@hyperwindmill/caretaker-cli 0.11.2 → 0.12.1

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.
@@ -5,4 +5,13 @@
5
5
  * keys so concurrent chats can progress while serialising per-chat.
6
6
  */
7
7
  export declare const runningTasks: Set<string>;
8
+ /**
9
+ * AbortControllers for in-flight task heartbeat runs, keyed by task id. Lets a
10
+ * Pause (or block) action abort the running agent mid-cycle instead of waiting
11
+ * for the current cycle to burn through its turns — the whole point of Pause
12
+ * when an agent has gone off the rails.
13
+ */
14
+ export declare const runningTaskControllers: Map<number, AbortController>;
15
+ /** Abort the in-flight run for a task, if one is registered. Returns whether it fired. */
16
+ export declare function abortRunningTask(taskId: number): boolean;
8
17
  //# sourceMappingURL=locks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/locks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,YAAY,aAAoB,CAAC"}
1
+ {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/locks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,YAAY,aAAoB,CAAC;AAE9C;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,8BAAqC,CAAC;AAEzE,0FAA0F;AAC1F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAKxD"}
@@ -5,3 +5,18 @@
5
5
  * keys so concurrent chats can progress while serialising per-chat.
6
6
  */
7
7
  export const runningTasks = new Set();
8
+ /**
9
+ * AbortControllers for in-flight task heartbeat runs, keyed by task id. Lets a
10
+ * Pause (or block) action abort the running agent mid-cycle instead of waiting
11
+ * for the current cycle to burn through its turns — the whole point of Pause
12
+ * when an agent has gone off the rails.
13
+ */
14
+ export const runningTaskControllers = new Map();
15
+ /** Abort the in-flight run for a task, if one is registered. Returns whether it fired. */
16
+ export function abortRunningTask(taskId) {
17
+ const ctrl = runningTaskControllers.get(taskId);
18
+ if (!ctrl)
19
+ return false;
20
+ ctrl.abort();
21
+ return true;
22
+ }
@@ -11,6 +11,9 @@ export declare function runDoneReview(opts: {
11
11
  branch: string;
12
12
  workingDir: string;
13
13
  round: number;
14
+ signal?: AbortSignal;
15
+ /** Wall-clock budget (seconds) for the review run. Defaults to the claude-code default. */
16
+ maxRunSeconds?: number;
14
17
  }): Promise<{
15
18
  verdict: 'pass' | 'changes';
16
19
  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;AAG5D,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;CACf,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAsCzD"}
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;AAG5D,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;CACxB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAqCzD"}
@@ -1,5 +1,5 @@
1
1
  import * as harness from '../../../harness/index.js';
2
- import { CLAUDE_CODE_MAX_RUN_MS } from './task_roles.js';
2
+ import { CLAUDE_CODE_DEFAULT_RUN_SECONDS } from './task_roles.js';
3
3
  export const MAX_REVIEW_ROUNDS = 3;
4
4
  export function reviewPrompt(objective, branch, round) {
5
5
  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.
@@ -45,16 +45,15 @@ export async function runDoneReview(opts) {
45
45
  // mcpServers still pass through inside the runner).
46
46
  const isClaudeCode = opts.provider.type === 'claude-code';
47
47
  const claudeCode = isClaudeCode ? { permissionMode: 'bypassPermissions' } : undefined;
48
- // Same wall-clock backstop as the task heartbeat: the Claude Code CLI has
49
- // no --max-turns equivalent, so a runaway review pass would otherwise stall
50
- // the reviewing gate indefinitely.
51
- let ccTimer;
52
- let signal;
53
- if (isClaudeCode) {
54
- const ccController = new AbortController();
55
- ccTimer = setTimeout(() => ccController.abort(), CLAUDE_CODE_MAX_RUN_MS);
56
- signal = ccController.signal;
57
- }
48
+ // Wall-clock backstop for the review pass, enforced for every provider (the
49
+ // Claude Code CLI has no --max-turns equivalent). Combined with any external
50
+ // signal (a Pause landing mid-review) so either can abort the run.
51
+ const budgetMs = (opts.maxRunSeconds ?? CLAUDE_CODE_DEFAULT_RUN_SECONDS) * 1000;
52
+ const budgetController = new AbortController();
53
+ const runTimer = setTimeout(() => budgetController.abort(), budgetMs);
54
+ const signal = opts.signal
55
+ ? AbortSignal.any([opts.signal, budgetController.signal])
56
+ : budgetController.signal;
58
57
  try {
59
58
  const result = await harness.run({
60
59
  agent: { ...opts.agent, permissionMode: 'bypassPermissions' }, // unattended: mirror the auto-approve confirm gate
@@ -71,7 +70,6 @@ export async function runDoneReview(opts) {
71
70
  return { verdict: parseReviewVerdict(result.text), text: result.text };
72
71
  }
73
72
  finally {
74
- if (ccTimer)
75
- clearTimeout(ccTimer);
73
+ clearTimeout(runTimer);
76
74
  }
77
75
  }
@@ -2,7 +2,10 @@ import { Task } from '../../../store/db.js';
2
2
  import type { AgentConfig, ProjectConfig } from '../../../types.js';
3
3
  import type { Tool } from '../../../harness/tools/types.js';
4
4
  export type TaskRole = 'planner' | 'developer' | 'reviewer';
5
- export declare const CLAUDE_CODE_MAX_RUN_MS: number;
5
+ export declare const DEFAULT_RUN_SECONDS = 120;
6
+ export declare const CLAUDE_CODE_DEFAULT_RUN_SECONDS: number;
7
+ /** Resolve the per-invocation budget (seconds): task → project → provider default. */
8
+ export declare function resolveMaxRunSeconds(task: Pick<Task, 'maxRunSeconds'>, project: Pick<ProjectConfig, 'maxRunSeconds'> | null | undefined, isClaudeCode: boolean): number;
6
9
  export declare function resolveRoleAgent(role: TaskRole, task: Task, project: ProjectConfig | undefined, agents: AgentConfig[]): AgentConfig | undefined;
7
10
  export declare function resolvePlanningEnabled(task: Pick<Task, 'planningEnabled'>, project?: Pick<ProjectConfig, 'planningEnabled'> | null): boolean;
8
11
  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;AAM5D,eAAO,MAAM,sBAAsB,QAAc,CAAC;AAElD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,aAAa,GAAG,SAAS,EAClC,MAAM,EAAE,WAAW,EAAE,GACpB,WAAW,GAAG,SAAS,CAOzB;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,iBAAiB,CAAC,EACnC,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,iBAAiB,CAAC,GAAG,IAAI,GACtD,OAAO,CAET;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,EACjC,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG,IAAI,GACpD,OAAO,CAET;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,IAAI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AsB,CACpC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,iBAAiB,CAAC,EACnC,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,iBAAiB,CAAC,GAAG,IAAI,GACtD,OAAO,CAET;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,EACjC,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG,IAAI,GACpD,OAAO,CAET;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,IAAI,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"}
@@ -2,11 +2,20 @@
2
2
  // The existing task.agentId -> project.agentId -> agents[0] chain IS the
3
3
  // developer role; planner/reviewer optionally override and degrade onto it.
4
4
  import { runQuery } from '../../../store/db.js';
5
- // ponytail: hard wall-clock cap; make configurable if real runs need more
6
- // The Claude Code CLI has no --max-turns equivalent, so a claude-code run has
7
- // no native turn cap. Without a wall-clock backstop a runaway run would stall
8
- // the whole heartbeat (and, for reviews, the review gate) indefinitely.
9
- export const CLAUDE_CODE_MAX_RUN_MS = 15 * 60_000;
5
+ // Per-invocation wall-clock budget defaults, in seconds. A run is aborted when
6
+ // it exceeds the resolved budget — for every provider. claude-code gets a larger
7
+ // default because the CLI has no --max-turns equivalent (native runs are also
8
+ // turn-bounded by agent.maxTurns), so without a generous backstop a claude-code
9
+ // run would stall the heartbeat (and, for reviews, the review gate).
10
+ export const DEFAULT_RUN_SECONDS = 120;
11
+ export const CLAUDE_CODE_DEFAULT_RUN_SECONDS = 15 * 60;
12
+ /** Resolve the per-invocation budget (seconds): task → project → provider default. */
13
+ export function resolveMaxRunSeconds(task, project, isClaudeCode) {
14
+ const configured = task.maxRunSeconds ?? project?.maxRunSeconds;
15
+ if (typeof configured === 'number' && configured > 0)
16
+ return configured;
17
+ return isClaudeCode ? CLAUDE_CODE_DEFAULT_RUN_SECONDS : DEFAULT_RUN_SECONDS;
18
+ }
10
19
  export function resolveRoleAgent(role, task, project, agents) {
11
20
  const pick = (id) => (id ? agents.find((a) => a.id === id) : undefined);
12
21
  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":"AAsHA,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAySnE"}
1
+ {"version":3,"file":"task_strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_strategy.ts"],"names":[],"mappings":"AAsHA,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAqUnE"}
@@ -2,12 +2,12 @@ import { randomUUID } from 'node:crypto';
2
2
  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
- import { runningTasks } from './locks.js';
6
- import { isGitRepo, ensureWorktree, agentDirIn, commitWip, finalizeDone } from '../../../lib/task_git.js';
5
+ import { runningTasks, runningTaskControllers } from './locks.js';
6
+ import { isGitRepo, ensureWorktree, agentDirIn, commitWip, finalizeDone, runBootstrap } 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, filterPlannerTools, CLAUDE_CODE_MAX_RUN_MS, } from './task_roles.js';
10
+ import { resolveRoleAgent, resolveReviewEnabled, resolveSddEnabled, resolveMaxRunSeconds, filterPlannerTools, } from './task_roles.js';
11
11
  function buildPrompt(systemPrompt, taskId, taskTitle, maxRunSeconds, maxTurns, workingDir) {
12
12
  const workspaceLine = workingDir
13
13
  ? `\n**Your workspace is: \`${workingDir}\`** — operate exclusively inside this directory. Do NOT reference or modify any other path on the filesystem.\n`
@@ -100,6 +100,9 @@ export async function runTaskHeartbeatTick(now) {
100
100
  return;
101
101
  }
102
102
  runningTasks.add(lockKey);
103
+ // Register an abort handle so Pause/block can kill this run mid-cycle.
104
+ const abortController = new AbortController();
105
+ runningTaskControllers.set(task.id, abortController);
103
106
  console.log(`[task_heartbeat] Claimed task #${task.id}: "${task.title}"`);
104
107
  // Update lockedAt in DB
105
108
  task.lockedAt = new Date().toISOString();
@@ -140,6 +143,31 @@ export async function runTaskHeartbeatTick(now) {
140
143
  await saveTask(task);
141
144
  workingDir = wt.agentWorkingDir;
142
145
  console.log(`[task_heartbeat] Task #${task.id} worktree ${wt.worktreePath} (branch ${wt.branch})`);
146
+ // Project bootstrap: run once in the fresh worktree before the agent's first
147
+ // cycle (e.g. `pnpm install`). A failing command blocks the task so the user
148
+ // sees why setup broke instead of the agent flailing in an unbuilt tree.
149
+ const bootstrap = (project.bootstrapCommands || []).filter((c) => c.trim());
150
+ if (bootstrap.length > 0) {
151
+ try {
152
+ console.log(`[task_heartbeat] Task #${task.id} running ${bootstrap.length} bootstrap command(s)`);
153
+ await runBootstrap(workingDir, bootstrap);
154
+ }
155
+ catch (bootErr) {
156
+ const reason = bootErr instanceof Error ? bootErr.message : String(bootErr);
157
+ task.status = 'blocked';
158
+ task.blockedReason = reason;
159
+ task.updatedAt = new Date().toISOString();
160
+ await saveTask(task);
161
+ await addTaskMessage({
162
+ taskId: task.id,
163
+ role: 'assistant',
164
+ messageType: 'block',
165
+ content: `Bootstrap failed — task blocked.\n\n${reason}`,
166
+ });
167
+ console.error(`[task_heartbeat] Task #${task.id} bootstrap failed, blocked:`, reason);
168
+ return;
169
+ }
170
+ }
143
171
  }
144
172
  // Non-git projects fall through: workingDir stays baseWorkingDir (run in place).
145
173
  // Ensure mcp__task__* is in agent.allowedTools
@@ -159,7 +187,7 @@ export async function runTaskHeartbeatTick(now) {
159
187
  // review gate flag is read at decision time: disabling it while a task sits
160
188
  // in reviewing finalizes the task directly on the next tick.
161
189
  if (task.status === 'reviewing') {
162
- await runReviewCycle({ task, project, agent: effectiveAgent, provider, tools, workingDir });
190
+ await runReviewCycle({ task, project, agent: effectiveAgent, provider, tools, workingDir, signal: abortController.signal });
163
191
  return; // the finally{} block still runs and releases the lock
164
192
  }
165
193
  const planning = task.status === 'planning';
@@ -172,7 +200,10 @@ export async function runTaskHeartbeatTick(now) {
172
200
  }
173
201
  // Max turns: standard sonnet settings or maxTurns
174
202
  const maxTurns = agent.maxTurns || 30;
175
- const maxRunSeconds = 120; // 2 minutes
203
+ const isClaudeCode = provider.type === 'claude-code';
204
+ // Per-invocation wall-clock budget (task → project → provider default),
205
+ // enforced below via the abort timer for every provider.
206
+ const maxRunSeconds = resolveMaxRunSeconds(task, project, isClaudeCode);
176
207
  // 5. Construct prompt
177
208
  const prompt = planning
178
209
  ? buildPlanningPrompt(agent.systemPrompt, task.id, task.title, maxRunSeconds, maxTurns, workingDir, sdd)
@@ -216,14 +247,13 @@ export async function runTaskHeartbeatTick(now) {
216
247
  // claude-code agents get role-scoped permission/tool extras and, when a
217
248
  // task bridge is running, an injected mcp__task server so the CLI can
218
249
  // still call task_get_state/task_submit_plan/etc despite --strict-mcp-config.
219
- const isClaudeCode = provider?.type === 'claude-code';
220
250
  let bridgeToken;
221
251
  let claudeCode;
222
- // Claude Code runs have no native turn cap (the CLI has no --max-turns),
223
- // so bound them with a wall-clock timeout instead; native runs stay
224
- // governed by maxTurns as usual.
225
- let ccTimer;
226
- let signal;
252
+ // Same handle Pause aborts; the wall-clock budget (resolved above) also
253
+ // aborts it. Enforced for every provider — native runs stay additionally
254
+ // turn-bounded by maxTurns.
255
+ const signal = abortController.signal;
256
+ const runTimer = setTimeout(() => abortController.abort(), maxRunSeconds * 1000);
227
257
  if (isClaudeCode) {
228
258
  const bridgeUrl = getTaskBridgeUrl();
229
259
  bridgeToken = bridgeUrl ? issueBridgeToken() : undefined;
@@ -235,9 +265,6 @@ export async function runTaskHeartbeatTick(now) {
235
265
  if (!bridgeUrl) {
236
266
  console.warn('[tasks] claude-code agent without task bridge URL — task tools unavailable this run');
237
267
  }
238
- const ccController = new AbortController();
239
- ccTimer = setTimeout(() => ccController.abort(), CLAUDE_CODE_MAX_RUN_MS);
240
- signal = ccController.signal;
241
268
  }
242
269
  try {
243
270
  await harness.run({
@@ -269,8 +296,7 @@ export async function runTaskHeartbeatTick(now) {
269
296
  finally {
270
297
  if (bridgeToken)
271
298
  revokeBridgeToken(bridgeToken);
272
- if (ccTimer)
273
- clearTimeout(ccTimer);
299
+ clearTimeout(runTimer);
274
300
  }
275
301
  // Finalize live message
276
302
  if (liveMsgId !== null) {
@@ -349,11 +375,13 @@ export async function runTaskHeartbeatTick(now) {
349
375
  await saveTask(finalCheck);
350
376
  }
351
377
  runningTasks.delete(lockKey);
378
+ runningTaskControllers.delete(task.id);
352
379
  console.log(`[task_heartbeat] Lock released for task #${task.id}`);
353
380
  }
354
381
  }
355
382
  async function runReviewCycle(opts) {
356
- const { task, project, agent, provider, tools, workingDir } = opts;
383
+ const { task, project, agent, provider, tools, workingDir, signal } = opts;
384
+ const maxRunSeconds = resolveMaxRunSeconds(task, project, provider.type === 'claude-code');
357
385
  if (!task.worktreePath)
358
386
  return; // reviewing implies a worktree; nothing to review otherwise
359
387
  // Review gate disabled (task or project level): finalize directly, no review.
@@ -386,6 +414,8 @@ async function runReviewCycle(opts) {
386
414
  branch: task.branch || '(unknown)',
387
415
  workingDir,
388
416
  round,
417
+ signal,
418
+ maxRunSeconds,
389
419
  });
390
420
  verdict = review.verdict;
391
421
  reviewText = review.text;
@@ -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;AAuClD,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,UA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B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA44B3E"}
@@ -9,7 +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 { runningTasks } from './scheduler/locks.js';
12
+ import { runningTasks, abortRunningTask } from './scheduler/locks.js';
13
13
  import { registerTaskBridge, setTaskBridgeUrl } from './mcp_bridge.js';
14
14
  import { loadAgents, loadConfig, dataDir, saveAgents, saveConfig, loadPlugins, loadMcpServers, } from '../../store/json.js';
15
15
  import { createSource, deleteSource, patchSource, refreshSource, } from '../../plugins/source_manager.js';
@@ -204,7 +204,7 @@ export async function startServer(port, host) {
204
204
  app.post('/api/projects', async (c) => {
205
205
  try {
206
206
  const body = await c.req.json();
207
- const { name, description, workingDir, agentId, plannerAgentId, reviewerAgentId, planningEnabled, reviewEnabled, sddEnabled } = body;
207
+ const { name, description, workingDir, agentId, plannerAgentId, reviewerAgentId, planningEnabled, reviewEnabled, sddEnabled, bootstrapCommands, maxRunSeconds } = body;
208
208
  const config = await loadConfig();
209
209
  if (!config.projects) {
210
210
  config.projects = [];
@@ -222,6 +222,10 @@ export async function startServer(port, host) {
222
222
  planningEnabled: typeof planningEnabled === 'boolean' ? planningEnabled : null,
223
223
  reviewEnabled: typeof reviewEnabled === 'boolean' ? reviewEnabled : null,
224
224
  sddEnabled: typeof sddEnabled === 'boolean' ? sddEnabled : null,
225
+ bootstrapCommands: Array.isArray(bootstrapCommands)
226
+ ? bootstrapCommands.map((c) => String(c).trim()).filter(Boolean)
227
+ : null,
228
+ maxRunSeconds: typeof maxRunSeconds === 'number' && maxRunSeconds > 0 ? maxRunSeconds : null,
225
229
  };
226
230
  config.projects.push(project);
227
231
  await saveConfig(config);
@@ -264,7 +268,7 @@ export async function startServer(port, host) {
264
268
  app.post('/api/projects/:id/tasks', async (c) => {
265
269
  const projectId = Number(c.req.param('id'));
266
270
  const body = await c.req.json();
267
- const { title, objective, checklist, startActive, agentId, plannerAgentId, reviewerAgentId, planningEnabled, reviewEnabled, sddEnabled } = body;
271
+ const { title, objective, checklist, startActive, agentId, plannerAgentId, reviewerAgentId, planningEnabled, reviewEnabled, sddEnabled, maxRunSeconds } = body;
268
272
  // Validate that the specified agents exist (if provided).
269
273
  const idsToValidate = [agentId, plannerAgentId, reviewerAgentId].filter(Boolean);
270
274
  if (idsToValidate.length > 0) {
@@ -303,6 +307,7 @@ export async function startServer(port, host) {
303
307
  planningEnabled: taskPlanning,
304
308
  reviewEnabled: typeof reviewEnabled === 'boolean' ? reviewEnabled : null,
305
309
  sddEnabled: typeof sddEnabled === 'boolean' ? sddEnabled : null,
310
+ maxRunSeconds: typeof maxRunSeconds === 'number' && maxRunSeconds > 0 ? maxRunSeconds : null,
306
311
  });
307
312
  return c.json({ ok: true });
308
313
  });
@@ -355,6 +360,9 @@ export async function startServer(port, host) {
355
360
  }
356
361
  else {
357
362
  task.status = status;
363
+ // Pausing/blocking must abort the in-flight run, not just skip the next
364
+ // tick — an off-the-rails agent has to stop now.
365
+ abortRunningTask(taskId);
358
366
  }
359
367
  task.updatedAt = new Date().toISOString();
360
368
  await saveTask(task);
@@ -494,6 +502,9 @@ export async function startServer(port, host) {
494
502
  if ('sddEnabled' in body) {
495
503
  task.sddEnabled = typeof body.sddEnabled === 'boolean' ? body.sddEnabled : null;
496
504
  }
505
+ if ('maxRunSeconds' in body) {
506
+ task.maxRunSeconds = typeof body.maxRunSeconds === 'number' && body.maxRunSeconds > 0 ? body.maxRunSeconds : null;
507
+ }
497
508
  task.updatedAt = new Date().toISOString();
498
509
  await saveTask(task);
499
510
  return c.json({
@@ -501,6 +512,7 @@ export async function startServer(port, host) {
501
512
  planningEnabled: task.planningEnabled ?? null,
502
513
  reviewEnabled: task.reviewEnabled ?? null,
503
514
  sddEnabled: task.sddEnabled ?? null,
515
+ maxRunSeconds: task.maxRunSeconds ?? null,
504
516
  });
505
517
  });
506
518
  const nodeServer = serve({
@@ -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;AAqCxC,eAAO,MAAM,QAAQ,EAAE,IA4GtB,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;AAkBxC,eAAO,MAAM,QAAQ,EAAE,IA4GtB,CAAC"}
@@ -1,36 +1,18 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { StringDecoder } from 'node:string_decoder';
3
- import { mergeShellEnv } from './shell-env.js';
3
+ import { commandEnv } from './shell-env.js';
4
4
  const DEFAULT_TIMEOUT_MS = 30_000;
5
5
  /** Cap on stdout+stderr we echo back to the model. The harness applies a
6
6
  * separate global cap on tool results; this keeps memory bounded inside
7
7
  * the bash tool itself for very chatty commands. */
8
8
  const MAX_OUTPUT_BYTES = 50_000;
9
- // Env var patterns scrubbed from the spawned child env. Mirrors caretaker
10
- // server's policy in src/mcp/shell.ts: keep tokens/keys/secrets out of
11
- // command-line tools the agent runs.
12
- const SECRET_ENV_PATTERNS = [/^OPENCODE_/, /^CLAUDE_/, /_TOKEN$/, /_KEY$/, /_SECRET$/];
13
- function scrubbedEnv() {
14
- const out = {};
15
- for (const [k, v] of Object.entries(process.env)) {
16
- if (SECRET_ENV_PATTERNS.some((re) => re.test(k)))
17
- continue;
18
- out[k] = v;
19
- }
20
- return out;
21
- }
22
9
  /**
23
- * Build the environment for bash subprocesses.
24
- * On Linux, merges the probed interactive shell environment to capture
25
- * PATH and version manager variables (NVM, volta, fnm, etc.) that
26
- * .bashrc sets but which are missing in non-interactive shells.
10
+ * Build the environment for bash subprocesses. Delegates to the shared
11
+ * `commandEnv()` so the bash tool and the task bootstrap/git helpers use
12
+ * one scrub + probe-merge policy.
27
13
  */
28
14
  function bashEnv() {
29
- const base = scrubbedEnv();
30
- if (process.platform === 'linux') {
31
- return mergeShellEnv(base);
32
- }
33
- return base;
15
+ return commandEnv();
34
16
  }
35
17
  export const bashTool = {
36
18
  name: 'bash',
@@ -52,4 +52,29 @@ export declare function getShellEnv(): Record<string, string>;
52
52
  * variables are set only if not already present in the env.
53
53
  */
54
54
  export declare function mergeShellEnv(existingEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
55
+ /**
56
+ * Env var patterns scrubbed from spawned command envs. Shared by the bash
57
+ * tool and by bootstrap/git spawns so unattended runs don't leak tokens.
58
+ * Mirrors the caretaker server's policy in src/mcp/shell.ts.
59
+ */
60
+ export declare const SECRET_ENV_PATTERNS: RegExp[];
61
+ /**
62
+ * Base env for spawned shells: process.env with secret vars scrubbed.
63
+ * Used by both the bash tool and the task bootstrap/git helpers so the
64
+ * same scrub policy applies everywhere a command is spawned.
65
+ */
66
+ export declare function scrubbedEnv(): NodeJS.ProcessEnv;
67
+ /**
68
+ * Build the env for a spawned shell command: scrubbed process.env, with the
69
+ * probed interactive-shell PATH and version-manager vars merged in on Linux.
70
+ * macOS/Windows return the scrubbed env unchanged (login shells there already
71
+ * source profiles correctly). Mirrors what the `bash` tool uses.
72
+ */
73
+ export declare function commandEnv(): NodeJS.ProcessEnv;
74
+ /**
75
+ * @internal Test-only: set the cached probe result directly so tests can
76
+ * exercise the env-merge path without running a real interactive shell probe.
77
+ * Production code never calls this.
78
+ */
79
+ export declare function setShellEnvForTest(env: Record<string, string>): void;
55
80
  //# sourceMappingURL=shell-env.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell-env.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/shell-env.ts"],"names":[],"mappings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;GAIG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAAC,UAAU,CAO/C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAAC,UAAU,CAM9C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAEpE"}
@@ -179,3 +179,50 @@ export function mergeShellEnv(existingEnv) {
179
179
  }
180
180
  return merged;
181
181
  }
182
+ /**
183
+ * Env var patterns scrubbed from spawned command envs. Shared by the bash
184
+ * tool and by bootstrap/git spawns so unattended runs don't leak tokens.
185
+ * Mirrors the caretaker server's policy in src/mcp/shell.ts.
186
+ */
187
+ export const SECRET_ENV_PATTERNS = [
188
+ /^OPENCODE_/,
189
+ /^CLAUDE_/,
190
+ /_TOKEN$/,
191
+ /_KEY$/,
192
+ /_SECRET$/,
193
+ ];
194
+ /**
195
+ * Base env for spawned shells: process.env with secret vars scrubbed.
196
+ * Used by both the bash tool and the task bootstrap/git helpers so the
197
+ * same scrub policy applies everywhere a command is spawned.
198
+ */
199
+ export function scrubbedEnv() {
200
+ const out = {};
201
+ for (const [k, v] of Object.entries(process.env)) {
202
+ if (SECRET_ENV_PATTERNS.some((re) => re.test(k)))
203
+ continue;
204
+ out[k] = v;
205
+ }
206
+ return out;
207
+ }
208
+ /**
209
+ * Build the env for a spawned shell command: scrubbed process.env, with the
210
+ * probed interactive-shell PATH and version-manager vars merged in on Linux.
211
+ * macOS/Windows return the scrubbed env unchanged (login shells there already
212
+ * source profiles correctly). Mirrors what the `bash` tool uses.
213
+ */
214
+ export function commandEnv() {
215
+ const base = scrubbedEnv();
216
+ if (process.platform === "linux") {
217
+ return mergeShellEnv(base);
218
+ }
219
+ return base;
220
+ }
221
+ /**
222
+ * @internal Test-only: set the cached probe result directly so tests can
223
+ * exercise the env-merge path without running a real interactive shell probe.
224
+ * Production code never calls this.
225
+ */
226
+ export function setShellEnvForTest(env) {
227
+ cachedResult = { env, success: true };
228
+ }
@@ -5,6 +5,14 @@ export declare function ensureWorktree(projectWorkingDir: string, projectId: num
5
5
  worktreePath: string;
6
6
  agentWorkingDir: string;
7
7
  }>;
8
+ /**
9
+ * Run project bootstrap commands once in a freshly created worktree, in order.
10
+ * Stops at the first non-zero exit and throws with the failed command + its
11
+ * output, so the caller can surface why setup failed. Each command gets a
12
+ * generous timeout so a hung install can't wedge the scheduler tick.
13
+ * ponytail: 10-min per-command timeout; make it configurable if a real project needs longer.
14
+ */
15
+ export declare function runBootstrap(cwd: string, commands: string[]): Promise<void>;
8
16
  export declare function commitWip(worktreePath: string, title: string): Promise<boolean>;
9
17
  export declare function finalizeDone(worktreePath: string): Promise<void>;
10
18
  export declare function discardWorktree(worktreePath: string, title: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"task_git.d.ts","sourceRoot":"","sources":["../../src/lib/task_git.ts"],"names":[],"mappings":"AAaA,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAM7D;AAgBD,wBAAsB,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKjG;AAED,wBAAsB,cAAc,CAClC,iBAAiB,EAAE,MAAM,EACzB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC,CAe5E;AAcD,wBAAsB,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAcrF;AAED,wBAAsB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBtE;AAED,wBAAsB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGxF"}
1
+ {"version":3,"file":"task_git.d.ts","sourceRoot":"","sources":["../../src/lib/task_git.ts"],"names":[],"mappings":"AAmBA,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAM7D;AAgBD,wBAAsB,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKjG;AAED,wBAAsB,cAAc,CAClC,iBAAiB,EAAE,MAAM,EACzB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC,CAe5E;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBjF;AAcD,wBAAsB,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAcrF;AAED,wBAAsB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBtE;AAED,wBAAsB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGxF"}
@@ -1,11 +1,17 @@
1
- import { execFile } from 'node:child_process';
1
+ import { execFile, exec as execCb } from 'node:child_process';
2
2
  import { promisify } from 'node:util';
3
3
  import { rm } from 'node:fs/promises';
4
4
  import { join, relative, dirname } from 'node:path';
5
5
  import { dataDir } from '../store/db.js';
6
+ import { commandEnv } from '../harness/tools/builtin/shell-env.js';
6
7
  const exec = promisify(execFile);
8
+ const execShell = promisify(execCb);
7
9
  async function git(cwd, args) {
8
- const { stdout } = await exec('git', args, { cwd, maxBuffer: 32 * 1024 * 1024 });
10
+ const { stdout } = await exec('git', args, {
11
+ cwd,
12
+ env: commandEnv(),
13
+ maxBuffer: 32 * 1024 * 1024,
14
+ });
9
15
  return stdout.trim();
10
16
  }
11
17
  export async function isGitRepo(dir) {
@@ -47,6 +53,33 @@ export async function ensureWorktree(projectWorkingDir, projectId, taskId, title
47
53
  const agentWorkingDir = rel ? join(worktreePath, rel) : worktreePath;
48
54
  return { branch, worktreePath, agentWorkingDir };
49
55
  }
56
+ /**
57
+ * Run project bootstrap commands once in a freshly created worktree, in order.
58
+ * Stops at the first non-zero exit and throws with the failed command + its
59
+ * output, so the caller can surface why setup failed. Each command gets a
60
+ * generous timeout so a hung install can't wedge the scheduler tick.
61
+ * ponytail: 10-min per-command timeout; make it configurable if a real project needs longer.
62
+ */
63
+ export async function runBootstrap(cwd, commands) {
64
+ for (const command of commands) {
65
+ const cmd = command.trim();
66
+ if (!cmd)
67
+ continue;
68
+ try {
69
+ await execShell(cmd, {
70
+ cwd,
71
+ env: commandEnv(),
72
+ timeout: 10 * 60 * 1000,
73
+ maxBuffer: 32 * 1024 * 1024,
74
+ });
75
+ }
76
+ catch (err) {
77
+ const e = err;
78
+ const detail = (e.stderr || e.stdout || e.message || '').toString().trim();
79
+ throw new Error(`Bootstrap command failed: \`${cmd}\`\n${detail}`);
80
+ }
81
+ }
82
+ }
50
83
  async function hasGitIdentity(cwd) {
51
84
  try {
52
85
  const [name, email] = await Promise.all([
@@ -38,6 +38,8 @@ export interface Task {
38
38
  planningEnabled?: boolean | null;
39
39
  reviewEnabled?: boolean | null;
40
40
  sddEnabled?: boolean | null;
41
+ /** Per-invocation wall-clock budget (seconds). Inherits from the project; unset = default. */
42
+ maxRunSeconds?: number | null;
41
43
  createdAt: string;
42
44
  updatedAt: string;
43
45
  }
@@ -1 +1 @@
1
- {"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