@hyperwindmill/caretaker-cli 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/web/scheduler/task_review.d.ts +6 -0
- package/dist/cli/web/scheduler/task_review.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_review.js +22 -5
- package/dist/cli/web/scheduler/task_roles.d.ts +6 -0
- package/dist/cli/web/scheduler/task_roles.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_roles.js +9 -0
- package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_strategy.js +121 -11
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +15 -1
- package/dist/harness/claude_code_runner.d.ts +5 -0
- package/dist/harness/claude_code_runner.d.ts.map +1 -1
- package/dist/harness/claude_code_runner.js +17 -0
- package/dist/harness/loop.d.ts +2 -0
- package/dist/harness/loop.d.ts.map +1 -1
- package/dist/harness/loop.js +1 -0
- package/dist/harness/tools/builtin/bash.d.ts.map +1 -1
- package/dist/harness/tools/builtin/bash.js +18 -9
- package/dist/harness/tools/builtin/task_tools.d.ts.map +1 -1
- package/dist/harness/tools/builtin/task_tools.js +13 -0
- package/dist/harness/tools/types.d.ts +4 -0
- package/dist/harness/tools/types.d.ts.map +1 -1
- package/dist/lib/docker.d.ts +43 -0
- package/dist/lib/docker.d.ts.map +1 -0
- package/dist/lib/docker.js +160 -0
- package/dist/lib/task_git.d.ts +9 -1
- package/dist/lib/task_git.d.ts.map +1 -1
- package/dist/lib/task_git.js +24 -1
- package/dist/store/db.d.ts +6 -0
- package/dist/store/db.d.ts.map +1 -1
- package/dist/webview/standalone.css +6 -2
- package/dist/webview/standalone.css.map +2 -2
- package/dist/webview/standalone.js +521 -450
- package/dist/webview/standalone.js.map +2 -2
- package/package.json +3 -3
|
@@ -14,6 +14,12 @@ export declare function runDoneReview(opts: {
|
|
|
14
14
|
signal?: AbortSignal;
|
|
15
15
|
/** Wall-clock budget (seconds) for the review run. Defaults to the claude-code default. */
|
|
16
16
|
maxRunSeconds?: number;
|
|
17
|
+
/** When set, the review runs inside this docker container — aligned with the
|
|
18
|
+
* dev/planning cycles, so the reviewer can't execute the code under review on
|
|
19
|
+
* the host. best-effort git (see dockerHasGit). */
|
|
20
|
+
dockerContainer?: string;
|
|
21
|
+
/** Whether git is available inside the container; drives a prompt hint. */
|
|
22
|
+
dockerHasGit?: boolean;
|
|
17
23
|
}): Promise<{
|
|
18
24
|
verdict: 'pass' | 'changes';
|
|
19
25
|
text: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task_review.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_review.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"task_review.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_review.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAI5D,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CA2BrF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMnE;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,2FAA2F;IAC3F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;wDAEoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAqDzD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as harness from '../../../harness/index.js';
|
|
2
2
|
import { CLAUDE_CODE_DEFAULT_RUN_SECONDS } from './task_roles.js';
|
|
3
|
+
import { dockerDevAllowlist } from '../../../lib/docker.js';
|
|
3
4
|
export const MAX_REVIEW_ROUNDS = 3;
|
|
4
5
|
export function reviewPrompt(objective, branch, round) {
|
|
5
6
|
return `You are an INDEPENDENT code reviewer. You did not write this code, and your job is to find real problems — not to be agreeable. Do not rubber-stamp.
|
|
@@ -40,11 +41,19 @@ export function parseReviewVerdict(text) {
|
|
|
40
41
|
export async function runDoneReview(opts) {
|
|
41
42
|
// Strip task-state tools: the reviewer must not mutate the task; the harness decides.
|
|
42
43
|
const reviewTools = opts.tools.filter((t) => !t.name.startsWith('mcp__task__'));
|
|
43
|
-
// claude-code reviewer:
|
|
44
|
-
//
|
|
45
|
-
//
|
|
44
|
+
// claude-code reviewer: in a docker container it uses the same manual +
|
|
45
|
+
// workdir-scoped allowlist as the dev cycle (the Bash-rewrite hook is attached
|
|
46
|
+
// by the runner via `docker`); otherwise bypassPermissions, no task bridge.
|
|
46
47
|
const isClaudeCode = opts.provider.type === 'claude-code';
|
|
47
|
-
const claudeCode = isClaudeCode
|
|
48
|
+
const claudeCode = isClaudeCode
|
|
49
|
+
? opts.dockerContainer
|
|
50
|
+
? {
|
|
51
|
+
permissionMode: 'manual',
|
|
52
|
+
allowedTools: dockerDevAllowlist(opts.workingDir),
|
|
53
|
+
docker: { container: opts.dockerContainer, workdir: opts.workingDir },
|
|
54
|
+
}
|
|
55
|
+
: { permissionMode: 'bypassPermissions' }
|
|
56
|
+
: undefined;
|
|
48
57
|
// Wall-clock backstop for the review pass, enforced for every provider (the
|
|
49
58
|
// Claude Code CLI has no --max-turns equivalent). Combined with any external
|
|
50
59
|
// signal (a Pause landing mid-review) so either can abort the run.
|
|
@@ -54,15 +63,23 @@ export async function runDoneReview(opts) {
|
|
|
54
63
|
const signal = opts.signal
|
|
55
64
|
? AbortSignal.any([opts.signal, budgetController.signal])
|
|
56
65
|
: budgetController.signal;
|
|
66
|
+
let prompt = reviewPrompt(opts.objective, opts.branch, opts.round);
|
|
67
|
+
if (opts.dockerContainer) {
|
|
68
|
+
prompt += `\n\n**Execution environment:** your shell commands run inside a Docker container mounted at \`${opts.workingDir}\`.`;
|
|
69
|
+
if (opts.dockerHasGit === false) {
|
|
70
|
+
prompt += ` Note: \`git\` is NOT available in this container — inspect the changes by reading the files directly instead of running git commands.`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
57
73
|
try {
|
|
58
74
|
const result = await harness.run({
|
|
59
75
|
agent: { ...opts.agent, permissionMode: 'bypassPermissions' }, // unattended: mirror the auto-approve confirm gate
|
|
60
76
|
provider: opts.provider,
|
|
61
77
|
tools: reviewTools,
|
|
62
|
-
prompt
|
|
78
|
+
prompt,
|
|
63
79
|
history: [],
|
|
64
80
|
workingDir: opts.workingDir,
|
|
65
81
|
signal,
|
|
82
|
+
dockerContainer: opts.dockerContainer,
|
|
66
83
|
...(claudeCode ? { claudeCode } : {}),
|
|
67
84
|
}, {
|
|
68
85
|
confirmTool: async () => 'once', // unattended
|
|
@@ -6,6 +6,12 @@ export declare const DEFAULT_RUN_SECONDS = 120;
|
|
|
6
6
|
export declare const CLAUDE_CODE_DEFAULT_RUN_SECONDS: number;
|
|
7
7
|
/** Resolve the per-invocation budget (seconds): task → project → provider default. */
|
|
8
8
|
export declare function resolveMaxRunSeconds(task: Pick<Task, 'maxRunSeconds'>, project: Pick<ProjectConfig, 'maxRunSeconds'> | null | undefined, isClaudeCode: boolean): number;
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the docker image for a task's runs. Phase-1: project-level only, so
|
|
11
|
+
* the task arg is accepted (for a future per-task override tier) but unused.
|
|
12
|
+
* This is the single config chokepoint — a later agent-level tier is added here.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveDockerImage(_task: Pick<Task, 'projectId'>, project: Pick<ProjectConfig, 'dockerImage'> | null | undefined): string | null;
|
|
9
15
|
export declare function resolveRoleAgent(role: TaskRole, task: Task, project: ProjectConfig | undefined, agents: AgentConfig[]): AgentConfig | undefined;
|
|
10
16
|
export declare function resolvePlanningEnabled(task: Pick<Task, 'planningEnabled'>, project?: Pick<ProjectConfig, 'planningEnabled'> | null): boolean;
|
|
11
17
|
export declare function resolveReviewEnabled(task: Pick<Task, 'reviewEnabled'>, project?: Pick<ProjectConfig, 'reviewEnabled'> | null): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task_roles.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_roles.ts"],"names":[],"mappings":"AAGA,OAAO,EAAY,IAAI,EAAe,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAE5D,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;AAO5D,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,+BAA+B,QAAU,CAAC;AAEvD,sFAAsF;AACtF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,EACjC,OA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CAAC,IAAI,EAAE,YAAY,CAAC,EAC9B,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,GAAG,IAAI,GACjD,OAAO,CAET;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,aAAa,GAAG,SAAS,GACjC,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAC,CAIhC;AAED;;;uDAGuD;AACvD,eAAO,MAAM,qBAAqB,aAAkD,CAAC;AAsBrF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,UAAQ,GAAG,IAAI,EAAE,CAOrE"}
|
|
@@ -16,6 +16,15 @@ export function resolveMaxRunSeconds(task, project, isClaudeCode) {
|
|
|
16
16
|
return configured;
|
|
17
17
|
return isClaudeCode ? CLAUDE_CODE_DEFAULT_RUN_SECONDS : DEFAULT_RUN_SECONDS;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the docker image for a task's runs. Phase-1: project-level only, so
|
|
21
|
+
* the task arg is accepted (for a future per-task override tier) but unused.
|
|
22
|
+
* This is the single config chokepoint — a later agent-level tier is added here.
|
|
23
|
+
*/
|
|
24
|
+
export function resolveDockerImage(_task, project) {
|
|
25
|
+
const img = project?.dockerImage?.trim();
|
|
26
|
+
return img ? img : null;
|
|
27
|
+
}
|
|
19
28
|
export function resolveRoleAgent(role, task, project, agents) {
|
|
20
29
|
const pick = (id) => (id ? agents.find((a) => a.id === id) : undefined);
|
|
21
30
|
const developer = pick(task.agentId) || pick(project?.agentId) || agents[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task_strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"task_strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_strategy.ts"],"names":[],"mappings":"AAyHA,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAoanE"}
|
|
@@ -3,11 +3,13 @@ import * as harness from '../../../harness/index.js';
|
|
|
3
3
|
import { loadAgents, loadConfig } from '../../../store/json.js';
|
|
4
4
|
import { getTaskById, saveTask, addTaskMessage, updateTaskMessageContent, runQuery } from '../../../store/db.js';
|
|
5
5
|
import { runningTasks, runningTaskControllers } from './locks.js';
|
|
6
|
-
import { isGitRepo, ensureWorktree, agentDirIn, commitWip, finalizeDone, runBootstrap } from '../../../lib/task_git.js';
|
|
6
|
+
import { isGitRepo, ensureWorktree, agentDirIn, commitWip, finalizeDone, runBootstrap, gitCommonDir } from '../../../lib/task_git.js';
|
|
7
7
|
import { runDoneReview, MAX_REVIEW_ROUNDS } from './task_review.js';
|
|
8
8
|
import { claudeCodeTaskExtras } from '../../../harness/claude_code_runner.js';
|
|
9
9
|
import { issueBridgeToken, revokeBridgeToken, getTaskBridgeUrl } from '../mcp_bridge.js';
|
|
10
|
-
import { resolveRoleAgent, resolveReviewEnabled, resolveSddEnabled, resolveMaxRunSeconds, filterPlannerTools, } from './task_roles.js';
|
|
10
|
+
import { resolveRoleAgent, resolveReviewEnabled, resolveSddEnabled, resolveMaxRunSeconds, filterPlannerTools, resolveDockerImage, } from './task_roles.js';
|
|
11
|
+
import { resolve as resolvePath, dirname } from 'node:path';
|
|
12
|
+
import { ensureContainer, removeContainer, containerName, dockerDevAllowlist, containerHasGit, isDockerfilePath, buildImage, containerRunning } from '../../../lib/docker.js';
|
|
11
13
|
function buildPrompt(systemPrompt, taskId, taskTitle, maxRunSeconds, maxTurns, workingDir) {
|
|
12
14
|
const workspaceLine = workingDir
|
|
13
15
|
? `\n**Your workspace is: \`${workingDir}\`** — operate exclusively inside this directory. Do NOT reference or modify any other path on the filesystem.\n`
|
|
@@ -132,9 +134,11 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
132
134
|
}
|
|
133
135
|
const baseWorkingDir = project.workingDir || agent.workingDir || process.cwd();
|
|
134
136
|
let workingDir = baseWorkingDir;
|
|
135
|
-
|
|
137
|
+
let mountRoot = baseWorkingDir;
|
|
138
|
+
let worktreeJustCreated = false;
|
|
136
139
|
if (task.worktreePath) {
|
|
137
140
|
workingDir = await agentDirIn(task.worktreePath, baseWorkingDir);
|
|
141
|
+
mountRoot = task.worktreePath;
|
|
138
142
|
}
|
|
139
143
|
else if (await isGitRepo(baseWorkingDir)) {
|
|
140
144
|
const wt = await ensureWorktree(baseWorkingDir, task.projectId, task.id, task.title);
|
|
@@ -142,15 +146,77 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
142
146
|
task.worktreePath = wt.worktreePath;
|
|
143
147
|
await saveTask(task);
|
|
144
148
|
workingDir = wt.agentWorkingDir;
|
|
149
|
+
mountRoot = wt.worktreePath;
|
|
150
|
+
worktreeJustCreated = true;
|
|
145
151
|
console.log(`[task_heartbeat] Task #${task.id} worktree ${wt.worktreePath} (branch ${wt.branch})`);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
}
|
|
153
|
+
// Non-git projects fall through: workingDir/mountRoot stay baseWorkingDir (run in place).
|
|
154
|
+
// Docker isolation (project-level, phase 1): ensure the task's container is
|
|
155
|
+
// up (idempotent by name), before bootstrap. A failure blocks the task with
|
|
156
|
+
// the docker error — same policy as a failed bootstrap command.
|
|
157
|
+
const dockerImage = resolveDockerImage(task, project);
|
|
158
|
+
let dockerContainer;
|
|
159
|
+
let dockerHasGit = true;
|
|
160
|
+
if (dockerImage) {
|
|
161
|
+
const name = containerName(task.projectId, task.id);
|
|
162
|
+
// Also mount the git common dir so a linked worktree's gitdir resolves
|
|
163
|
+
// inside the container (identical-path). Only for git-worktree tasks.
|
|
164
|
+
const extraMounts = [];
|
|
165
|
+
if (task.worktreePath) {
|
|
166
|
+
const commonDir = await gitCommonDir(workingDir);
|
|
167
|
+
if (commonDir)
|
|
168
|
+
extraMounts.push(commonDir);
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
// dockerImage may be a Dockerfile path (starts with . / \) → build a
|
|
172
|
+
// per-project image from it (cached; only when we'll (re)create the
|
|
173
|
+
// container); otherwise it is a pullable image ref used as-is.
|
|
174
|
+
let imageRef = dockerImage;
|
|
175
|
+
if (isDockerfilePath(dockerImage)) {
|
|
176
|
+
imageRef = `caretaker-project-${task.projectId}:latest`;
|
|
177
|
+
if (!(await containerRunning(name))) {
|
|
178
|
+
const dockerfile = resolvePath(baseWorkingDir, dockerImage);
|
|
179
|
+
console.log(`[task_heartbeat] Task #${task.id} building image ${imageRef} from ${dockerfile}`);
|
|
180
|
+
await buildImage(dockerfile, dirname(dockerfile), imageRef);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
await ensureContainer(name, imageRef, mountRoot, workingDir, extraMounts);
|
|
184
|
+
dockerContainer = name;
|
|
185
|
+
if (task.dockerContainer !== name) {
|
|
186
|
+
task.dockerContainer = name;
|
|
187
|
+
await saveTask(task);
|
|
188
|
+
}
|
|
189
|
+
// In-container git is best-effort: warn the agent (via the prompt) when
|
|
190
|
+
// the image ships no git. The harness commits host-side regardless.
|
|
191
|
+
dockerHasGit = await containerHasGit(name);
|
|
192
|
+
if (!dockerHasGit) {
|
|
193
|
+
console.warn(`[task_heartbeat] Task #${task.id} container image "${dockerImage}" has no git — agent git commands will fail (commits are host-side).`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (dockErr) {
|
|
197
|
+
const reason = dockErr instanceof Error ? dockErr.message : String(dockErr);
|
|
198
|
+
task.status = 'blocked';
|
|
199
|
+
task.blockedReason = reason;
|
|
200
|
+
task.updatedAt = new Date().toISOString();
|
|
201
|
+
await saveTask(task);
|
|
202
|
+
await addTaskMessage({
|
|
203
|
+
taskId: task.id,
|
|
204
|
+
role: 'assistant',
|
|
205
|
+
messageType: 'block',
|
|
206
|
+
content: `Docker container setup failed — task blocked.\n\n${reason}`,
|
|
207
|
+
});
|
|
208
|
+
console.error(`[task_heartbeat] Task #${task.id} docker setup failed, blocked:`, reason);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Project bootstrap: run once in the fresh worktree (inside the container
|
|
213
|
+
// when docker is active) before the agent's first cycle. A failure blocks.
|
|
214
|
+
if (worktreeJustCreated) {
|
|
149
215
|
const bootstrap = (project.bootstrapCommands || []).filter((c) => c.trim());
|
|
150
216
|
if (bootstrap.length > 0) {
|
|
151
217
|
try {
|
|
152
218
|
console.log(`[task_heartbeat] Task #${task.id} running ${bootstrap.length} bootstrap command(s)`);
|
|
153
|
-
await runBootstrap(workingDir, bootstrap);
|
|
219
|
+
await runBootstrap(workingDir, bootstrap, dockerContainer);
|
|
154
220
|
}
|
|
155
221
|
catch (bootErr) {
|
|
156
222
|
const reason = bootErr instanceof Error ? bootErr.message : String(bootErr);
|
|
@@ -187,7 +253,7 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
187
253
|
// review gate flag is read at decision time: disabling it while a task sits
|
|
188
254
|
// in reviewing finalizes the task directly on the next tick.
|
|
189
255
|
if (task.status === 'reviewing') {
|
|
190
|
-
await runReviewCycle({ task, project, agent: effectiveAgent, provider, tools, workingDir, signal: abortController.signal });
|
|
256
|
+
await runReviewCycle({ task, project, agent: effectiveAgent, provider, tools, workingDir, signal: abortController.signal, dockerContainer, dockerHasGit });
|
|
191
257
|
return; // the finally{} block still runs and releases the lock
|
|
192
258
|
}
|
|
193
259
|
const planning = task.status === 'planning';
|
|
@@ -208,6 +274,16 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
208
274
|
const prompt = planning
|
|
209
275
|
? buildPlanningPrompt(agent.systemPrompt, task.id, task.title, maxRunSeconds, maxTurns, workingDir, sdd)
|
|
210
276
|
: buildPrompt(agent.systemPrompt, task.id, task.title, maxRunSeconds, maxTurns, workingDir);
|
|
277
|
+
// Tell the dev agent (either provider) it is containerized, and warn when
|
|
278
|
+
// git is unavailable in the image so it doesn't waste turns on failing git.
|
|
279
|
+
let effectivePrompt = prompt;
|
|
280
|
+
if (dockerContainer && !planning) {
|
|
281
|
+
let env = `\n\n**Execution environment:** your shell commands run inside a Docker container (image \`${dockerImage}\`) mounted at \`${workingDir}\`. File reads/writes are confined to this directory.`;
|
|
282
|
+
if (!dockerHasGit) {
|
|
283
|
+
env += ` Note: \`git\` is NOT available in this container — do not run git commands (commits are handled automatically for you).`;
|
|
284
|
+
}
|
|
285
|
+
effectivePrompt = `${prompt}${env}`;
|
|
286
|
+
}
|
|
211
287
|
const checklistBefore = (task.checklist || []).filter((item) => item.status !== 'pending').length;
|
|
212
288
|
// Create a live assistant message in DB
|
|
213
289
|
const liveMsg = await addTaskMessage({
|
|
@@ -215,6 +291,10 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
215
291
|
role: 'assistant',
|
|
216
292
|
messageType: 'heartbeat_live',
|
|
217
293
|
content: '',
|
|
294
|
+
// Capture the role-resolved agent behind this cycle, so the thread shows
|
|
295
|
+
// who actually ran (planner during planning, developer during active) —
|
|
296
|
+
// as text of the moment, not resolved live in the UI.
|
|
297
|
+
agentLabel: `${agent.name} · ${agent.model}`,
|
|
218
298
|
});
|
|
219
299
|
liveMsgId = liveMsg.id;
|
|
220
300
|
let buffer = '';
|
|
@@ -262,6 +342,18 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
262
342
|
sdd,
|
|
263
343
|
bridge: bridgeUrl && bridgeToken ? { url: bridgeUrl, token: bridgeToken } : undefined,
|
|
264
344
|
});
|
|
345
|
+
// Docker isolation for claude-code (non-planning): swap bypassPermissions
|
|
346
|
+
// for manual + a workdir-scoped allowlist and attach the Bash-rewrite hook.
|
|
347
|
+
// Planning stays as-is (read-only; no shell to contain).
|
|
348
|
+
if (dockerContainer && !planning) {
|
|
349
|
+
claudeCode = {
|
|
350
|
+
...claudeCode,
|
|
351
|
+
permissionMode: 'manual',
|
|
352
|
+
allowedTools: dockerDevAllowlist(workingDir),
|
|
353
|
+
disallowedTools: undefined,
|
|
354
|
+
docker: { container: dockerContainer, workdir: workingDir },
|
|
355
|
+
};
|
|
356
|
+
}
|
|
265
357
|
if (!bridgeUrl) {
|
|
266
358
|
console.warn('[tasks] claude-code agent without task bridge URL — task tools unavailable this run');
|
|
267
359
|
}
|
|
@@ -271,10 +363,11 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
271
363
|
agent: effectiveAgent,
|
|
272
364
|
provider,
|
|
273
365
|
tools,
|
|
274
|
-
prompt,
|
|
366
|
+
prompt: effectivePrompt,
|
|
275
367
|
history: historyRecords,
|
|
276
368
|
workingDir,
|
|
277
369
|
claudeCode,
|
|
370
|
+
dockerContainer,
|
|
278
371
|
signal,
|
|
279
372
|
}, {
|
|
280
373
|
onChunk: (chunk) => {
|
|
@@ -341,11 +434,15 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
341
434
|
console.log(`[task_heartbeat] Task #${task.id} committed WIP to ${gitTask.branch}`);
|
|
342
435
|
}
|
|
343
436
|
if (gitTask.status === 'done') {
|
|
437
|
+
if (gitTask.dockerContainer) {
|
|
438
|
+
await removeContainer(gitTask.dockerContainer);
|
|
439
|
+
gitTask.dockerContainer = null;
|
|
440
|
+
}
|
|
344
441
|
await finalizeDone(gitTask.worktreePath);
|
|
345
442
|
gitTask.worktreePath = null;
|
|
346
443
|
gitTask.updatedAt = new Date().toISOString();
|
|
347
444
|
await saveTask(gitTask);
|
|
348
|
-
console.log(`[task_heartbeat] Task #${
|
|
445
|
+
console.log(`[task_heartbeat] Task #${gitTask.id} done (review gate off): worktree removed, branch ${gitTask.branch} kept`);
|
|
349
446
|
}
|
|
350
447
|
}
|
|
351
448
|
catch (gitErr) {
|
|
@@ -380,7 +477,7 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
380
477
|
}
|
|
381
478
|
}
|
|
382
479
|
async function runReviewCycle(opts) {
|
|
383
|
-
const { task, project, agent, provider, tools, workingDir, signal } = opts;
|
|
480
|
+
const { task, project, agent, provider, tools, workingDir, signal, dockerContainer, dockerHasGit } = opts;
|
|
384
481
|
const maxRunSeconds = resolveMaxRunSeconds(task, project, provider.type === 'claude-code');
|
|
385
482
|
if (!task.worktreePath)
|
|
386
483
|
return; // reviewing implies a worktree; nothing to review otherwise
|
|
@@ -390,6 +487,10 @@ async function runReviewCycle(opts) {
|
|
|
390
487
|
const current = await getTaskById(task.id);
|
|
391
488
|
if (!current || current.status !== 'reviewing')
|
|
392
489
|
return;
|
|
490
|
+
if (current.dockerContainer) {
|
|
491
|
+
await removeContainer(current.dockerContainer);
|
|
492
|
+
current.dockerContainer = null;
|
|
493
|
+
}
|
|
393
494
|
await finalizeDone(current.worktreePath);
|
|
394
495
|
current.status = 'done';
|
|
395
496
|
current.worktreePath = null;
|
|
@@ -416,6 +517,8 @@ async function runReviewCycle(opts) {
|
|
|
416
517
|
round,
|
|
417
518
|
signal,
|
|
418
519
|
maxRunSeconds,
|
|
520
|
+
dockerContainer,
|
|
521
|
+
dockerHasGit,
|
|
419
522
|
});
|
|
420
523
|
verdict = review.verdict;
|
|
421
524
|
reviewText = review.text;
|
|
@@ -437,6 +540,9 @@ async function runReviewCycle(opts) {
|
|
|
437
540
|
role: 'user',
|
|
438
541
|
messageType: 'review',
|
|
439
542
|
content: `[CODE REVIEW round ${round}/${MAX_REVIEW_ROUNDS}] verdict=${verdict}\n\n${reviewText}`,
|
|
543
|
+
// role is 'user' so the verdict replays into the agent's history as feedback,
|
|
544
|
+
// but the reviewer agent produced it — capture that for the log display.
|
|
545
|
+
agentLabel: `${agent.name} · ${agent.model}`,
|
|
440
546
|
});
|
|
441
547
|
}
|
|
442
548
|
console.log(`[task_heartbeat] Task #${task.id} review round ${round}: ${verdict}`);
|
|
@@ -457,6 +563,10 @@ async function runReviewCycle(opts) {
|
|
|
457
563
|
content: `Finished as done despite outstanding review findings after ${MAX_REVIEW_ROUNDS} rounds.`,
|
|
458
564
|
});
|
|
459
565
|
}
|
|
566
|
+
if (current.dockerContainer) {
|
|
567
|
+
await removeContainer(current.dockerContainer);
|
|
568
|
+
current.dockerContainer = null;
|
|
569
|
+
}
|
|
460
570
|
await finalizeDone(current.worktreePath);
|
|
461
571
|
current.status = 'done';
|
|
462
572
|
current.worktreePath = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAwClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAajF,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9D,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;IACtF,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,qBAAa,oBAAoB;IAQ7B,OAAO,CAAC,QAAQ,CAAC,IAAI;IAPvB,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAc;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;gBAGjB,IAAI,EAAE;QACrB,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,cAAc,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAMH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,eAAe,IAAI,GAAG;IAIhB,KAAK,CACT,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,aAAa,EACjB,cAAc,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,GACrE,OAAO,CAAC,IAAI,CAAC;IA+EhB,KAAK,IAAI,IAAI;CAGd;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAw5B3E"}
|
package/dist/cli/web/server.js
CHANGED
|
@@ -9,6 +9,7 @@ import { WebSocketServer, WebSocket } from 'ws';
|
|
|
9
9
|
import * as harness from '../../harness/index.js';
|
|
10
10
|
import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask, runQuery, tryNormalizeChecklistStatus } from '../../store/db.js';
|
|
11
11
|
import { discardWorktree } from '../../lib/task_git.js';
|
|
12
|
+
import { removeContainer } from '../../lib/docker.js';
|
|
12
13
|
import { runningTasks, abortRunningTask } from './scheduler/locks.js';
|
|
13
14
|
import { registerTaskBridge, setTaskBridgeUrl } from './mcp_bridge.js';
|
|
14
15
|
import { loadAgents, loadConfig, dataDir, saveAgents, saveConfig, loadPlugins, loadMcpServers, } from '../../store/json.js';
|
|
@@ -204,7 +205,7 @@ export async function startServer(port, host) {
|
|
|
204
205
|
app.post('/api/projects', async (c) => {
|
|
205
206
|
try {
|
|
206
207
|
const body = await c.req.json();
|
|
207
|
-
const { name, description, workingDir, agentId, plannerAgentId, reviewerAgentId, planningEnabled, reviewEnabled, sddEnabled, bootstrapCommands, maxRunSeconds } = body;
|
|
208
|
+
const { name, description, workingDir, agentId, plannerAgentId, reviewerAgentId, planningEnabled, reviewEnabled, sddEnabled, bootstrapCommands, maxRunSeconds, dockerImage } = body;
|
|
208
209
|
const config = await loadConfig();
|
|
209
210
|
if (!config.projects) {
|
|
210
211
|
config.projects = [];
|
|
@@ -226,6 +227,7 @@ export async function startServer(port, host) {
|
|
|
226
227
|
? bootstrapCommands.map((c) => String(c).trim()).filter(Boolean)
|
|
227
228
|
: null,
|
|
228
229
|
maxRunSeconds: typeof maxRunSeconds === 'number' && maxRunSeconds > 0 ? maxRunSeconds : null,
|
|
230
|
+
dockerImage: typeof dockerImage === 'string' && dockerImage.trim() ? dockerImage.trim() : null,
|
|
229
231
|
};
|
|
230
232
|
config.projects.push(project);
|
|
231
233
|
await saveConfig(config);
|
|
@@ -376,6 +378,10 @@ export async function startServer(port, host) {
|
|
|
376
378
|
return c.json({ ok: false, error: 'not found' }, 404);
|
|
377
379
|
if (!task.worktreePath)
|
|
378
380
|
return c.json({ ok: false, error: 'no worktree' }, 400);
|
|
381
|
+
if (task.dockerContainer) {
|
|
382
|
+
await removeContainer(task.dockerContainer);
|
|
383
|
+
task.dockerContainer = null;
|
|
384
|
+
}
|
|
379
385
|
await discardWorktree(task.worktreePath, task.title);
|
|
380
386
|
task.worktreePath = null;
|
|
381
387
|
task.updatedAt = new Date().toISOString();
|
|
@@ -430,6 +436,14 @@ export async function startServer(port, host) {
|
|
|
430
436
|
return c.json({ ok: false, error: 'Task is currently running. Wait for it to finish or pause it first.' }, 409);
|
|
431
437
|
}
|
|
432
438
|
// Clean up any active worktree before deleting the task record.
|
|
439
|
+
if (task.dockerContainer) {
|
|
440
|
+
try {
|
|
441
|
+
await removeContainer(task.dockerContainer);
|
|
442
|
+
}
|
|
443
|
+
catch {
|
|
444
|
+
// Best-effort
|
|
445
|
+
}
|
|
446
|
+
}
|
|
433
447
|
if (task.worktreePath) {
|
|
434
448
|
try {
|
|
435
449
|
await discardWorktree(task.worktreePath, task.title);
|
|
@@ -9,6 +9,10 @@ export type ClaudeCodeRunExtras = {
|
|
|
9
9
|
url: string;
|
|
10
10
|
headers?: Record<string, string>;
|
|
11
11
|
}>;
|
|
12
|
+
docker?: {
|
|
13
|
+
container: string;
|
|
14
|
+
workdir: string;
|
|
15
|
+
};
|
|
12
16
|
};
|
|
13
17
|
export type ClaudeChildProcess = {
|
|
14
18
|
stdout: NodeJS.ReadableStream | null;
|
|
@@ -29,6 +33,7 @@ export interface ClaudeArgsInput {
|
|
|
29
33
|
allowedTools?: string[];
|
|
30
34
|
disallowedTools?: string[];
|
|
31
35
|
mcpConfigPath?: string;
|
|
36
|
+
settingsPath?: string;
|
|
32
37
|
resumeId?: string;
|
|
33
38
|
persistSession: boolean;
|
|
34
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude_code_runner.d.ts","sourceRoot":"","sources":["../../src/harness/claude_code_runner.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAM3E,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"claude_code_runner.d.ts","sourceRoot":"","sources":["../../src/harness/claude_code_runner.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAM3E,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAerE,MAAM,MAAM,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D,GACzE,MAAM,GAAG,IAAI,CAQf;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,eAAe,GAAG,MAAM,EAAE,CAY5D;AAED,uEAAuE;AACvE,wBAAgB,oBAAoB,CAAC,CAAC,EAAE;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC,GAAG,mBAAmB,CAiBtB;AA+LD,wBAAsB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,GAAE,YAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CAkI/F"}
|
|
@@ -14,6 +14,7 @@ import { loadContextFiles, formatContextBlock, resolveFileReferences } from './c
|
|
|
14
14
|
import { readSession, updateClaudeSessionId, assistantMessage, toolMessage, } from '../session/store.js';
|
|
15
15
|
import { loadMcpServers } from '../store/json.js';
|
|
16
16
|
import { resolvedServerRuntime } from '../mcp/client.js';
|
|
17
|
+
import { DOCKER_BASH_HOOK_SCRIPT, dockerClaudeSettings } from '../lib/docker.js';
|
|
17
18
|
let spawnImpl = nodeSpawn;
|
|
18
19
|
export function __setSpawn(fn) {
|
|
19
20
|
spawnImpl = fn;
|
|
@@ -45,6 +46,8 @@ export function buildClaudeArgs(i) {
|
|
|
45
46
|
args.push('--disallowedTools', ...i.disallowedTools);
|
|
46
47
|
if (i.mcpConfigPath)
|
|
47
48
|
args.push('--mcp-config', i.mcpConfigPath, '--strict-mcp-config');
|
|
49
|
+
if (i.settingsPath)
|
|
50
|
+
args.push('--settings', i.settingsPath);
|
|
48
51
|
if (i.resumeId)
|
|
49
52
|
args.push('--resume', i.resumeId);
|
|
50
53
|
else if (!i.persistSession)
|
|
@@ -254,6 +257,18 @@ export async function runClaudeCode(opts, cb = {}) {
|
|
|
254
257
|
.join('\n\n');
|
|
255
258
|
// 3. Per-run mcp-config temp file (agent's servers + injected bridge).
|
|
256
259
|
const mcp = await buildMcpConfigFile(agent.mcpServers ?? [], opts.claudeCode?.extraMcpServers);
|
|
260
|
+
// Per-run --settings temp file: registers the PreToolUse Bash-rewrite hook
|
|
261
|
+
// so claude-code shell commands run inside the task's docker container.
|
|
262
|
+
let settings = null;
|
|
263
|
+
if (opts.claudeCode?.docker) {
|
|
264
|
+
const dir = await mkdtemp(path.join(os.tmpdir(), 'caretaker-cc-settings-'));
|
|
265
|
+
const hookPath = path.join(dir, 'docker-hook.mjs');
|
|
266
|
+
await writeFile(hookPath, DOCKER_BASH_HOOK_SCRIPT, { mode: 0o700 });
|
|
267
|
+
const settingsPath = path.join(dir, 'settings.json');
|
|
268
|
+
const obj = dockerClaudeSettings(opts.claudeCode.docker.container, opts.claudeCode.docker.workdir, hookPath);
|
|
269
|
+
await writeFile(settingsPath, JSON.stringify(obj), { mode: 0o600 });
|
|
270
|
+
settings = { settingsPath, cleanup: () => rm(dir, { recursive: true, force: true }) };
|
|
271
|
+
}
|
|
257
272
|
const permissionMode = opts.claudeCode?.permissionMode ??
|
|
258
273
|
agent.permissionMode ??
|
|
259
274
|
detectClaudeDefaultPermissionMode() ??
|
|
@@ -267,6 +282,7 @@ export async function runClaudeCode(opts, cb = {}) {
|
|
|
267
282
|
allowedTools: opts.claudeCode?.allowedTools,
|
|
268
283
|
disallowedTools: opts.claudeCode?.disallowedTools,
|
|
269
284
|
mcpConfigPath: mcp?.configPath,
|
|
285
|
+
settingsPath: settings?.settingsPath,
|
|
270
286
|
resumeId: resume,
|
|
271
287
|
persistSession: Boolean(opts.sessionId),
|
|
272
288
|
});
|
|
@@ -321,5 +337,6 @@ export async function runClaudeCode(opts, cb = {}) {
|
|
|
321
337
|
}
|
|
322
338
|
finally {
|
|
323
339
|
await mcp?.cleanup().catch(() => { });
|
|
340
|
+
await settings?.cleanup().catch(() => { });
|
|
324
341
|
}
|
|
325
342
|
}
|
package/dist/harness/loop.d.ts
CHANGED
|
@@ -57,6 +57,8 @@ export interface RunOptions {
|
|
|
57
57
|
/** claude-code runner extras (ignored by the native loop): permission
|
|
58
58
|
* mode override, tool allow/deny rules, extra per-run MCP servers. */
|
|
59
59
|
claudeCode?: import('./claude_code_runner.js').ClaudeCodeRunExtras;
|
|
60
|
+
/** Native-loop only: run `bash` commands inside this docker container. */
|
|
61
|
+
dockerContainer?: string;
|
|
60
62
|
}
|
|
61
63
|
export interface RunResult {
|
|
62
64
|
/** Concatenated assistant text across all turns. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/harness/loop.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAiB,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAgC,KAAK,cAAc,EAAoB,MAAM,eAAe,CAAC;AAEpG,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,eAAe,IAAI,mBAAmB,EAC3C,KAAK,IAAI,EAGV,MAAM,kBAAkB,CAAC;AAK1B,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEzE,4DAA4D;AAC5D,wBAAgB,UAAU,CAAC,CAAC,E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th ?? 0,
|
|
54
54
|
confirmTool: cb.confirmTool,
|
|
55
55
|
sessionId: opts.sessionId,
|
|
56
|
+
dockerContainer: opts.dockerContainer,
|
|
56
57
|
};
|
|
57
58
|
// System prompt assembly, applied unconditionally (the prelude and
|
|
58
59
|
// context-files block are harness-level concerns, not tied to which tools
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/bash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/bash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAmBxC,eAAO,MAAM,QAAQ,EAAE,IAoHtB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { StringDecoder } from 'node:string_decoder';
|
|
3
3
|
import { commandEnv } from './shell-env.js';
|
|
4
|
+
import { containerExecArgs } from '../../../lib/docker.js';
|
|
4
5
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
5
6
|
/** Cap on stdout+stderr we echo back to the model. The harness applies a
|
|
6
7
|
* separate global cap on tool results; this keeps memory bounded inside
|
|
@@ -45,19 +46,27 @@ export const bashTool = {
|
|
|
45
46
|
// to capture PATH and version manager variables (NVM, volta, fnm, etc.).
|
|
46
47
|
// On Windows, fall back to cmd.exe via shell:true. On macOS, login
|
|
47
48
|
// shells source profiles correctly so we use the default env.
|
|
49
|
+
// Docker isolation (run-level): route the command through the task
|
|
50
|
+
// container instead of the host. Precedes the platform branch — when a
|
|
51
|
+
// container is set we always use `docker exec`.
|
|
48
52
|
const isWindows = process.platform === 'win32';
|
|
49
|
-
const child =
|
|
50
|
-
? spawn(a.command,
|
|
51
|
-
cwd: ctx.workingDir,
|
|
52
|
-
shell: true,
|
|
53
|
+
const child = ctx.dockerContainer
|
|
54
|
+
? spawn('docker', containerExecArgs(ctx.dockerContainer, ctx.workingDir, a.command), {
|
|
53
55
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
54
56
|
env: bashEnv(),
|
|
55
57
|
})
|
|
56
|
-
:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
: isWindows
|
|
59
|
+
? spawn(a.command, [], {
|
|
60
|
+
cwd: ctx.workingDir,
|
|
61
|
+
shell: true,
|
|
62
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
63
|
+
env: bashEnv(),
|
|
64
|
+
})
|
|
65
|
+
: spawn('bash', ['-c', a.command], {
|
|
66
|
+
cwd: ctx.workingDir,
|
|
67
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
68
|
+
env: bashEnv(),
|
|
69
|
+
});
|
|
61
70
|
const decoder = new StringDecoder('utf8');
|
|
62
71
|
let out = '';
|
|
63
72
|
let truncated = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/task_tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"task_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/task_tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAcpD,eAAO,MAAM,gBAAgB,EAAE,IAmD9B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IAqCrC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,IAoDjC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAiC5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAgD9B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAoC3B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAoC3B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAa7B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAgG5B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IA+B5B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAwC7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAoC9B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAwC7B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IA4BrC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAkC7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,IA8B/B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IA4C5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAgD9B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAuC5B,CAAC"}
|