mirror of
https://github.com/textcortex/claude-code-sandbox.git
synced 2025-08-04 19:08:21 +00:00
Checkpoint
This commit is contained in:
parent
040662602d
commit
24c2a98caf
7 changed files with 204 additions and 1160 deletions
1320
package-lock.json
generated
1320
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -23,13 +23,14 @@
|
|||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"chalk": "^5.3.0",
|
||||
"chalk": "^4.1.2",
|
||||
"chokidar": "^3.6.0",
|
||||
"commander": "^12.0.0",
|
||||
"dockerode": "^4.0.2",
|
||||
"inquirer": "^9.2.15",
|
||||
"ora": "^8.0.1",
|
||||
"simple-git": "^3.22.0"
|
||||
"inquirer": "^8.2.6",
|
||||
"ora": "^5.4.1",
|
||||
"simple-git": "^3.22.0",
|
||||
"tar-stream": "^3.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/dockerode": "^3.3.23",
|
||||
|
|
|
@ -3,7 +3,6 @@ import { Command } from 'commander';
|
|||
import chalk from 'chalk';
|
||||
import { ClaudeSandbox } from './index';
|
||||
import { loadConfig } from './config';
|
||||
import path from 'path';
|
||||
|
||||
const program = new Command();
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import Docker from 'dockerode';
|
||||
import path from 'path';
|
||||
import fs from 'fs/promises';
|
||||
import { Readable, Writable } from 'stream';
|
||||
import { SandboxConfig, Credentials } from './types';
|
||||
|
||||
export class ContainerManager {
|
||||
|
@ -84,21 +82,22 @@ fi\\n\\
|
|||
ENTRYPOINT ["/bin/bash", "-c"]
|
||||
`;
|
||||
|
||||
// Build image
|
||||
const buildStream = await this.docker.buildImage({
|
||||
context: undefined,
|
||||
src: ['Dockerfile'],
|
||||
}, {
|
||||
// Build image from string
|
||||
const tarStream = require('tar-stream');
|
||||
const pack = tarStream.pack();
|
||||
|
||||
// Add Dockerfile to tar
|
||||
pack.entry({ name: 'Dockerfile' }, dockerfile);
|
||||
pack.finalize();
|
||||
|
||||
const buildStream = await this.docker.buildImage(pack, {
|
||||
dockerfile: 'Dockerfile',
|
||||
t: imageName,
|
||||
buildargs: {
|
||||
'DOCKER_CONTENT': Buffer.from(dockerfile).toString('base64'),
|
||||
},
|
||||
});
|
||||
|
||||
// Wait for build to complete
|
||||
await new Promise((resolve, reject) => {
|
||||
this.docker.modem.followProgress(buildStream, (err: any, res: any) => {
|
||||
this.docker.modem.followProgress(buildStream as any, (err: any, res: any) => {
|
||||
if (err) reject(err);
|
||||
else resolve(res);
|
||||
});
|
||||
|
@ -106,7 +105,6 @@ ENTRYPOINT ["/bin/bash", "-c"]
|
|||
}
|
||||
|
||||
private async buildImage(dockerfilePath: string, imageName: string): Promise<void> {
|
||||
const dockerfile = await fs.readFile(dockerfilePath, 'utf-8');
|
||||
const buildContext = path.dirname(dockerfilePath);
|
||||
|
||||
const buildStream = await this.docker.buildImage({
|
||||
|
@ -118,7 +116,7 @@ ENTRYPOINT ["/bin/bash", "-c"]
|
|||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
this.docker.modem.followProgress(buildStream, (err: any, res: any) => {
|
||||
this.docker.modem.followProgress(buildStream as any, (err: any, res: any) => {
|
||||
if (err) reject(err);
|
||||
else resolve(res);
|
||||
});
|
||||
|
@ -126,7 +124,7 @@ ENTRYPOINT ["/bin/bash", "-c"]
|
|||
}
|
||||
|
||||
private async createContainer(containerConfig: any): Promise<Docker.Container> {
|
||||
const { branchName, credentials, workDir, repoName } = containerConfig;
|
||||
const { branchName, credentials, workDir } = containerConfig;
|
||||
|
||||
// Prepare environment variables
|
||||
const env = this.prepareEnvironment(credentials);
|
||||
|
@ -269,7 +267,7 @@ ENTRYPOINT ["/bin/bash", "-c"]
|
|||
}
|
||||
|
||||
async cleanup(): Promise<void> {
|
||||
for (const [id, container] of this.containers) {
|
||||
for (const [, container] of this.containers) {
|
||||
try {
|
||||
await container.stop();
|
||||
await container.remove();
|
||||
|
|
|
@ -15,7 +15,7 @@ export class GitMonitor extends EventEmitter {
|
|||
this.git = git;
|
||||
}
|
||||
|
||||
async start(branchName: string): Promise<void> {
|
||||
async start(_branchName: string): Promise<void> {
|
||||
this.monitoring = true;
|
||||
|
||||
// Get initial commit hash
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
import Docker from 'dockerode';
|
||||
import { simpleGit, SimpleGit } from 'simple-git';
|
||||
import chalk from 'chalk';
|
||||
import inquirer from 'inquirer';
|
||||
import { CredentialManager } from './credentials';
|
||||
import { GitMonitor } from './git-monitor';
|
||||
import { ContainerManager } from './container';
|
||||
import { UIManager } from './ui';
|
||||
import { SandboxConfig } from './types';
|
||||
import path from 'path';
|
||||
import fs from 'fs/promises';
|
||||
|
||||
export class ClaudeSandbox {
|
||||
private docker: Docker;
|
||||
|
|
|
@ -60,7 +60,7 @@ export class UIManager {
|
|||
return action;
|
||||
}
|
||||
|
||||
showSpinner(message: string): ora.Ora {
|
||||
showSpinner(message: string): any {
|
||||
return ora(message).start();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue