@hyperwindmill/caretaker-cli 0.19.0 → 0.21.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/mcp.js +5 -5
- package/dist/cli/web/mcp_bridge.d.ts +1 -1
- package/dist/cli/web/mcp_bridge.d.ts.map +1 -1
- package/dist/cli/web/mcp_bridge.js +23 -7
- package/dist/cli/web/scheduler/heartbeat.d.ts +2 -2
- package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -1
- package/dist/cli/web/scheduler/locks.d.ts +6 -0
- package/dist/cli/web/scheduler/locks.d.ts.map +1 -1
- package/dist/cli/web/scheduler/locks.js +6 -0
- package/dist/cli/web/scheduler/strategy.d.ts +3 -3
- package/dist/cli/web/scheduler/strategy.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_roles.d.ts +0 -4
- package/dist/cli/web/scheduler/task_roles.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_roles.js +12 -2
- package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_strategy.js +86 -4
- package/dist/cli/web/scheduler/telegram.d.ts.map +1 -1
- package/dist/cli/web/scheduler/telegram.js +4 -1
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +121 -10
- package/dist/harness/claude_code_runner.d.ts.map +1 -1
- package/dist/harness/claude_code_runner.js +5 -1
- package/dist/harness/tools/builtin/email_tools.d.ts +5 -0
- package/dist/harness/tools/builtin/email_tools.d.ts.map +1 -0
- package/dist/harness/tools/builtin/email_tools.js +182 -0
- package/dist/harness/tools/builtin/index.d.ts +2 -1
- package/dist/harness/tools/builtin/index.d.ts.map +1 -1
- package/dist/harness/tools/builtin/index.js +7 -1
- package/dist/harness/tools/builtin/task_tools.d.ts.map +1 -1
- package/dist/harness/tools/builtin/task_tools.js +48 -6
- package/dist/harness/tools/resolve.d.ts.map +1 -1
- package/dist/harness/tools/resolve.js +9 -4
- package/dist/lib/email.d.ts +132 -0
- package/dist/lib/email.d.ts.map +1 -0
- package/dist/lib/email.js +306 -0
- package/dist/lib/repo_url.d.ts +12 -0
- package/dist/lib/repo_url.d.ts.map +1 -0
- package/dist/lib/repo_url.js +36 -0
- package/dist/lib/task_git.d.ts +53 -1
- package/dist/lib/task_git.d.ts.map +1 -1
- package/dist/lib/task_git.js +197 -5
- package/dist/mcp/builtin_server.d.ts +13 -0
- package/dist/mcp/builtin_server.d.ts.map +1 -0
- package/dist/mcp/builtin_server.js +65 -0
- package/dist/store/json.d.ts +1 -0
- package/dist/store/json.d.ts.map +1 -1
- package/dist/store/json.js +15 -0
- package/dist/tui/agents.js +36 -14
- package/dist/webview/standalone.js +1511 -1068
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +8 -3
- package/dist/mcp/task_server.d.ts +0 -9
- package/dist/mcp/task_server.d.ts.map +0 -1
- package/dist/mcp/task_server.js +0 -48
package/dist/cli/mcp.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// `caretaker-cli mcp` — serve the built-in mcp__task__*
|
|
2
|
-
// external MCP client (e.g. Claude Code) can steer caretaker's
|
|
3
|
-
// system symmetrically. No auth: the trust boundary is local process access to
|
|
1
|
+
// `caretaker-cli mcp` — serve the built-in mcp__task__* / mcp__email__* tools
|
|
2
|
+
// over stdio so an external MCP client (e.g. Claude Code) can steer caretaker's
|
|
3
|
+
// task/project system symmetrically and send mail through a configured account. No auth: the trust boundary is local process access to
|
|
4
4
|
// CARETAKER_HOME (the caller could edit the folder DB directly). stdout carries
|
|
5
5
|
// the JSON-RPC wire — never write anything else to it here.
|
|
6
6
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
7
|
-
import {
|
|
7
|
+
import { buildBuiltinMcpServer } from '../mcp/builtin_server.js';
|
|
8
8
|
export async function startMcpStdioServer() {
|
|
9
|
-
const server =
|
|
9
|
+
const server = buildBuiltinMcpServer({ name: 'caretaker', version: '0.0.0' });
|
|
10
10
|
const transport = new StdioServerTransport();
|
|
11
11
|
await server.connect(transport);
|
|
12
12
|
// Stay alive until the client closes stdin. Resolve on transport close so
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
|
-
export declare function issueBridgeToken(): string;
|
|
2
|
+
export declare function issueBridgeToken(agentId?: string): string;
|
|
3
3
|
export declare function revokeBridgeToken(token: string): void;
|
|
4
4
|
export declare function setTaskBridgeUrl(url: string): void;
|
|
5
5
|
export declare function getTaskBridgeUrl(): string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp_bridge.d.ts","sourceRoot":"","sources":["../../../src/cli/web/mcp_bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp_bridge.d.ts","sourceRoot":"","sources":["../../../src/cli/web/mcp_bridge.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AASjC,wBAAgB,gBAAgB,CAAC,OAAO,SAAK,GAAG,MAAM,CAIrD;AACD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAErD;AAGD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAElD;AACD,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAEhD;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAuBlD"}
|
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
// Exposes the built-in mcp__task__* tools as a streamable-HTTP
|
|
2
|
-
// so claude-code agents can drive the task state machine
|
|
1
|
+
// Exposes the built-in mcp__task__* / mcp__email__* tools as a streamable-HTTP
|
|
2
|
+
// MCP endpoint so claude-code agents can drive the task state machine (and send
|
|
3
|
+
// mail through a configured account). Token-guarded:
|
|
3
4
|
// the task heartbeat issues a per-run bearer token and revokes it after.
|
|
4
5
|
// Stateless MCP (no session): a fresh Server per request. The task tools
|
|
5
6
|
// are context-free (they take task_id as an argument), so no per-run
|
|
6
7
|
// injection is needed.
|
|
8
|
+
//
|
|
9
|
+
// The token also carries WHO the run belongs to: the email tools scope which
|
|
10
|
+
// accounts an agent may see (ServiceConfig.allowedAgents), and a claude-code
|
|
11
|
+
// agent has no other way to identify itself — it speaks MCP over HTTP, not the
|
|
12
|
+
// in-process ToolContext. Without this the whole per-agent boundary would be
|
|
13
|
+
// bypassed on exactly the surface that matters most, the autonomous task run.
|
|
7
14
|
import { randomBytes } from 'node:crypto';
|
|
8
15
|
import { RESPONSE_ALREADY_SENT } from '@hono/node-server/utils/response';
|
|
9
16
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
import { buildBuiltinMcpServer } from '../../mcp/builtin_server.js';
|
|
18
|
+
import { loadAgents } from '../../store/json.js';
|
|
19
|
+
/** token → the agent id the run belongs to ('' when the caller didn't say). */
|
|
20
|
+
const activeTokens = new Map();
|
|
21
|
+
export function issueBridgeToken(agentId = '') {
|
|
13
22
|
const token = randomBytes(24).toString('hex');
|
|
14
|
-
activeTokens.
|
|
23
|
+
activeTokens.set(token, agentId);
|
|
15
24
|
return token;
|
|
16
25
|
}
|
|
17
26
|
export function revokeBridgeToken(token) {
|
|
@@ -31,7 +40,14 @@ export function registerTaskBridge(app) {
|
|
|
31
40
|
if (!token || !activeTokens.has(token))
|
|
32
41
|
return c.json({ error: 'unauthorized' }, 401);
|
|
33
42
|
const body = await c.req.json().catch(() => null);
|
|
34
|
-
|
|
43
|
+
// Resolve the run's agent so ctx.callerAgent is set for the tools that scope
|
|
44
|
+
// by it. A token issued without an agent id (or pointing at a since-deleted
|
|
45
|
+
// agent) leaves it unset, which the email tools treat as an unscoped caller.
|
|
46
|
+
const agentId = activeTokens.get(token) ?? '';
|
|
47
|
+
const callerAgent = agentId
|
|
48
|
+
? (await loadAgents().catch(() => [])).find((a) => a.id === agentId)
|
|
49
|
+
: undefined;
|
|
50
|
+
const server = buildBuiltinMcpServer(undefined, { callerAgent });
|
|
35
51
|
const transport = new StreamableHTTPServerTransport({
|
|
36
52
|
sessionIdGenerator: undefined, // stateless
|
|
37
53
|
enableJsonResponse: true, // plain JSON responses, no SSE needed
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ServiceConfig } from '../../../types.js';
|
|
2
2
|
import type { SchedulerStrategy } from './strategy.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parses and evaluates a cron expression string against a given Date.
|
|
@@ -11,6 +11,6 @@ export declare function matchesCron(cronStr: string, date: Date): boolean;
|
|
|
11
11
|
* Runs completely in background, automatically approving tool runs.
|
|
12
12
|
* Guards against concurrent execution: if the task is already running, skips.
|
|
13
13
|
*/
|
|
14
|
-
export declare function executeTaskRun(task:
|
|
14
|
+
export declare function executeTaskRun(task: ServiceConfig): Promise<void>;
|
|
15
15
|
export declare const HeartbeatStrategy: SchedulerStrategy;
|
|
16
16
|
//# sourceMappingURL=heartbeat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/heartbeat.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/heartbeat.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CA2DhE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAgHvE;AAID,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAC"}
|
|
@@ -14,4 +14,10 @@ export declare const runningTasks: Set<string>;
|
|
|
14
14
|
export declare const runningTaskControllers: Map<number, AbortController>;
|
|
15
15
|
/** Abort the in-flight run for a task, if one is registered. Returns whether it fired. */
|
|
16
16
|
export declare function abortRunningTask(taskId: number): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Project ids with a repository sync (clone/pull) in flight — shared between
|
|
19
|
+
* the heartbeat's pre-worktree sync and POST /api/projects/:id/sync so the
|
|
20
|
+
* two can never race a clone. Derived state only; never persisted.
|
|
21
|
+
*/
|
|
22
|
+
export declare const syncingProjects: Set<number>;
|
|
17
23
|
//# 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;AAE9C;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,8BAAqC,CAAC;AAEzE,0FAA0F;AAC1F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAKxD"}
|
|
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;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,aAAoB,CAAC"}
|
|
@@ -20,3 +20,9 @@ export function abortRunningTask(taskId) {
|
|
|
20
20
|
ctrl.abort();
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Project ids with a repository sync (clone/pull) in flight — shared between
|
|
25
|
+
* the heartbeat's pre-worktree sync and POST /api/projects/:id/sync so the
|
|
26
|
+
* two can never race a clone. Derived state only; never persisted.
|
|
27
|
+
*/
|
|
28
|
+
export const syncingProjects = new Set();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ServiceConfig } from '../../../types.js';
|
|
2
2
|
export interface SchedulerStrategy {
|
|
3
|
-
type:
|
|
4
|
-
tick(task:
|
|
3
|
+
type: ServiceConfig['type'];
|
|
4
|
+
tick(task: ServiceConfig, now: Date): Promise<void>;
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD"}
|
|
@@ -22,10 +22,6 @@ export declare function resolveSddEnabled(task: Pick<Task, 'sddEnabled'>, projec
|
|
|
22
22
|
* message stream, like review rounds — no stored phase counter.
|
|
23
23
|
*/
|
|
24
24
|
export declare function activationStatus(task: Task, project: ProjectConfig | undefined): Promise<'planning' | 'active'>;
|
|
25
|
-
/** Builtins the planner must not have: everything that mutates the workspace.
|
|
26
|
-
* bash is stripped too — it cannot be made read-only, and the planner keeps
|
|
27
|
-
* read_file/glob/grep for exploration. Same post-filter mechanism as the
|
|
28
|
-
* reviewer's mcp__task__* strip in task_review.ts. */
|
|
29
25
|
export declare const PLANNER_TOOL_DENYLIST: Set<string>;
|
|
30
26
|
export declare function filterPlannerTools(tools: Tool[], sdd?: boolean): Tool[];
|
|
31
27
|
//# sourceMappingURL=task_roles.d.ts.map
|
|
@@ -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,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG,IAAI,GAAG,SAAS,EAChE,YAAY,EAAE,OAAO,GACpB,MAAM,CAIR;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,EAC9B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,GAAG,IAAI,GAAG,SAAS,GAC7D,MAAM,GAAG,IAAI,CAGf;AAED,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,sBAA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|
58
58
|
* bash is stripped too — it cannot be made read-only, and the planner keeps
|
|
59
59
|
* read_file/glob/grep for exploration. Same post-filter mechanism as the
|
|
60
60
|
* reviewer's mcp__task__* strip in task_review.ts. */
|
|
61
|
-
|
|
61
|
+
/** Denied to the planner in every mode, SDD included: `bash` is the real
|
|
62
|
+
* implementation brake, and sending mail is an *external* side effect — worse
|
|
63
|
+
* than an unreviewed write, which is what the read-only planner exists to
|
|
64
|
+
* prevent. Listing the accounts stays allowed; a plan may name one. */
|
|
65
|
+
const PLANNER_ALWAYS_DENIED = new Set(['bash', 'mcp__email__email_send']);
|
|
66
|
+
export const PLANNER_TOOL_DENYLIST = new Set([
|
|
67
|
+
'write',
|
|
68
|
+
'edit',
|
|
69
|
+
'multiedit',
|
|
70
|
+
...PLANNER_ALWAYS_DENIED,
|
|
71
|
+
]);
|
|
62
72
|
/** Tools the SDD wrapper applies to: workspace writers that take a `path` arg. */
|
|
63
73
|
const SDD_WRAPPED_TOOLS = new Set(['write', 'edit', 'multiedit']);
|
|
64
74
|
/** Wrap a writing tool so it only accepts markdown targets. Everything else
|
|
@@ -83,6 +93,6 @@ export function filterPlannerTools(tools, sdd = false) {
|
|
|
83
93
|
// SDD mode: bash stays out (the actual implementation brake); the file
|
|
84
94
|
// writers survive but only for markdown targets.
|
|
85
95
|
return tools
|
|
86
|
-
.filter((t) => t.name
|
|
96
|
+
.filter((t) => !PLANNER_ALWAYS_DENIED.has(t.name))
|
|
87
97
|
.map((t) => (SDD_WRAPPED_TOOLS.has(t.name) ? markdownOnly(t) : t));
|
|
88
98
|
}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAodnE"}
|
|
@@ -2,8 +2,8 @@ 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, runningTaskControllers } from './locks.js';
|
|
6
|
-
import { isGitRepo, ensureWorktree, agentDirIn, commitWip, finalizeDone, runBootstrap, gitCommonDir } from '../../../lib/task_git.js';
|
|
5
|
+
import { runningTasks, runningTaskControllers, syncingProjects } from './locks.js';
|
|
6
|
+
import { isGitRepo, ensureWorktree, agentDirIn, commitWip, finalizeDone, runBootstrap, gitCommonDir, syncProjectRepo, projectWorkingDir, pushBranch } 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';
|
|
@@ -132,7 +132,39 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
132
132
|
if (!provider) {
|
|
133
133
|
throw new Error(`Provider "${agent.provider}" not found for agent "${agent.name}"`);
|
|
134
134
|
}
|
|
135
|
-
const baseWorkingDir = project
|
|
135
|
+
const baseWorkingDir = projectWorkingDir(project) || agent.workingDir || process.cwd();
|
|
136
|
+
// Remote-backed project: clone-or-pull the repository right before the
|
|
137
|
+
// first worktree is created. Failure blocks the task (bootstrap pattern).
|
|
138
|
+
if (!task.worktreePath && project.repositoryUrl?.trim()) {
|
|
139
|
+
if (syncingProjects.has(project.id)) {
|
|
140
|
+
console.log(`[task_heartbeat] Task #${task.id} repo sync already in flight; skipping tick.`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
syncingProjects.add(project.id);
|
|
144
|
+
try {
|
|
145
|
+
for await (const p of syncProjectRepo(project)) {
|
|
146
|
+
console.log(`[task_heartbeat] Task #${task.id} repo sync: ${p.step} — ${p.message}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (syncErr) {
|
|
150
|
+
const reason = syncErr instanceof Error ? syncErr.message : String(syncErr);
|
|
151
|
+
task.status = 'blocked';
|
|
152
|
+
task.blockedReason = reason;
|
|
153
|
+
task.updatedAt = new Date().toISOString();
|
|
154
|
+
await saveTask(task);
|
|
155
|
+
await addTaskMessage({
|
|
156
|
+
taskId: task.id,
|
|
157
|
+
role: 'assistant',
|
|
158
|
+
messageType: 'block',
|
|
159
|
+
content: `Repository sync failed — task blocked.\n\n${reason}`,
|
|
160
|
+
});
|
|
161
|
+
console.error(`[task_heartbeat] Task #${task.id} repo sync failed, blocked:`, reason);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
syncingProjects.delete(project.id);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
136
168
|
let workingDir = baseWorkingDir;
|
|
137
169
|
let mountRoot = baseWorkingDir;
|
|
138
170
|
let worktreeJustCreated = false;
|
|
@@ -336,7 +368,10 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
336
368
|
const runTimer = setTimeout(() => abortController.abort(), maxRunSeconds * 1000);
|
|
337
369
|
if (isClaudeCode) {
|
|
338
370
|
const bridgeUrl = getTaskBridgeUrl();
|
|
339
|
-
|
|
371
|
+
// The token carries the role-resolved agent's id: it is the only identity
|
|
372
|
+
// a claude-code run has on the bridge, and the email tools scope accounts
|
|
373
|
+
// by it (ServiceConfig.allowedAgents).
|
|
374
|
+
bridgeToken = bridgeUrl ? issueBridgeToken(effectiveAgent.id) : undefined;
|
|
340
375
|
claudeCode = claudeCodeTaskExtras({
|
|
341
376
|
planning,
|
|
342
377
|
sdd,
|
|
@@ -435,7 +470,20 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
435
470
|
if (await commitWip(gitTask.worktreePath, gitTask.title)) {
|
|
436
471
|
console.log(`[task_heartbeat] Task #${task.id} committed WIP to ${gitTask.branch}`);
|
|
437
472
|
}
|
|
473
|
+
const repoUrl = project.repositoryUrl?.trim();
|
|
474
|
+
if (repoUrl && gitTask.branch && gitTask.status !== 'done') {
|
|
475
|
+
// Per-cycle push is best-effort: the remote mirrors progress, but a
|
|
476
|
+
// flaky network must not fail the cycle. Finalize pushes are gated.
|
|
477
|
+
try {
|
|
478
|
+
await pushBranch(gitTask.worktreePath, gitTask.branch, { url: repoUrl, token: project.repositoryToken });
|
|
479
|
+
}
|
|
480
|
+
catch (pushErr) {
|
|
481
|
+
console.error(`[task_heartbeat] Task #${task.id} per-cycle push failed (best-effort):`, pushErr);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
438
484
|
if (gitTask.status === 'done') {
|
|
485
|
+
if (!(await pushOrBlock(gitTask, project)))
|
|
486
|
+
return;
|
|
439
487
|
if (gitTask.dockerContainer) {
|
|
440
488
|
await removeContainer(gitTask.dockerContainer);
|
|
441
489
|
gitTask.dockerContainer = null;
|
|
@@ -478,6 +526,36 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
478
526
|
console.log(`[task_heartbeat] Lock released for task #${task.id}`);
|
|
479
527
|
}
|
|
480
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* Push the task branch before finalizing. Returns true when pushed (or no push
|
|
531
|
+
* applies). On failure: blocks the task with the reason and returns false —
|
|
532
|
+
* the caller must NOT finalize (worktree stays; the user fixes the remote or
|
|
533
|
+
* token and unblocks to retry).
|
|
534
|
+
*/
|
|
535
|
+
async function pushOrBlock(task, project) {
|
|
536
|
+
const url = project?.repositoryUrl?.trim();
|
|
537
|
+
if (!url || !task.branch || !task.worktreePath)
|
|
538
|
+
return true;
|
|
539
|
+
try {
|
|
540
|
+
await pushBranch(task.worktreePath, task.branch, { url, token: project?.repositoryToken });
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
catch (err) {
|
|
544
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
545
|
+
task.status = 'blocked';
|
|
546
|
+
task.blockedReason = reason;
|
|
547
|
+
task.updatedAt = new Date().toISOString();
|
|
548
|
+
await saveTask(task);
|
|
549
|
+
await addTaskMessage({
|
|
550
|
+
taskId: task.id,
|
|
551
|
+
role: 'assistant',
|
|
552
|
+
messageType: 'block',
|
|
553
|
+
content: `Push to remote failed — task blocked. The worktree is kept; fix the remote or token and unblock to retry.\n\n${reason}`,
|
|
554
|
+
});
|
|
555
|
+
console.error(`[task_heartbeat] Task #${task.id} push failed, blocked:`, reason);
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
481
559
|
async function runReviewCycle(opts) {
|
|
482
560
|
const { task, project, agent, provider, tools, workingDir, signal, dockerContainer, dockerHasGit } = opts;
|
|
483
561
|
const maxRunSeconds = resolveMaxRunSeconds(task, project, provider.type === 'claude-code');
|
|
@@ -489,6 +567,8 @@ async function runReviewCycle(opts) {
|
|
|
489
567
|
const current = await getTaskById(task.id);
|
|
490
568
|
if (!current || current.status !== 'reviewing')
|
|
491
569
|
return;
|
|
570
|
+
if (!(await pushOrBlock(current, project)))
|
|
571
|
+
return;
|
|
492
572
|
if (current.dockerContainer) {
|
|
493
573
|
await removeContainer(current.dockerContainer);
|
|
494
574
|
current.dockerContainer = null;
|
|
@@ -565,6 +645,8 @@ async function runReviewCycle(opts) {
|
|
|
565
645
|
content: `Finished as done despite outstanding review findings after ${MAX_REVIEW_ROUNDS} rounds.`,
|
|
566
646
|
});
|
|
567
647
|
}
|
|
648
|
+
if (!(await pushOrBlock(current, project)))
|
|
649
|
+
return;
|
|
568
650
|
if (current.dockerContainer) {
|
|
569
651
|
await removeContainer(current.dockerContainer);
|
|
570
652
|
current.dockerContainer = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/telegram.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/telegram.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBxF;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAUpF;AAiED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAO,GAAG,MAAM,EAAE,CA8ClE;AAkSD,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAiB3D;AAED,eAAO,MAAM,gBAAgB,EAAE,iBAK9B,CAAC"}
|
|
@@ -6,9 +6,12 @@ import * as harness from '../../../harness/index.js';
|
|
|
6
6
|
import { loadAgents, loadConfig } from '../../../store/json.js';
|
|
7
7
|
import { __forTesting, readSession, createSession, appendMessage, userMessage, } from '../../../session/store.js';
|
|
8
8
|
import { decrypt, isEncrypted } from '../../../lib/encryption.js';
|
|
9
|
-
import { schedulerLogsDir } from './logs.js';
|
|
9
|
+
import { schedulerLogsDir, ensureSchedulerLogsDir } from './logs.js';
|
|
10
10
|
import { runningTasks } from './locks.js';
|
|
11
11
|
export async function saveTelegramOffset(taskId, updateId) {
|
|
12
|
+
// The offset is committed before any run is logged, so this can be the very
|
|
13
|
+
// first write into scheduler-logs/ — the dir may not exist yet.
|
|
14
|
+
await ensureSchedulerLogsDir();
|
|
12
15
|
const path = join(schedulerLogsDir(), `${taskId}.offset`);
|
|
13
16
|
const tmpPath = `${path}.tmp.${process.pid}.${Date.now()}`;
|
|
14
17
|
await writeFile(tmpPath, String(updateId), 'utf8');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAyClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAgBjF,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,EACtE,iBAAiB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,IAAI,CAAC;IAgFhB,KAAK,IAAI,IAAI;CAGd;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAomC3E"}
|
package/dist/cli/web/server.js
CHANGED
|
@@ -4,13 +4,15 @@ import fs from 'node:fs';
|
|
|
4
4
|
import { watch, existsSync, mkdirSync } from 'node:fs';
|
|
5
5
|
import { randomUUID } from 'node:crypto';
|
|
6
6
|
import { Hono } from 'hono';
|
|
7
|
+
import { stream } from 'hono/streaming';
|
|
7
8
|
import { serve } from '@hono/node-server';
|
|
8
9
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
9
10
|
import * as harness from '../../harness/index.js';
|
|
10
11
|
import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask, runQuery, tryNormalizeChecklistStatus } from '../../store/db.js';
|
|
11
|
-
import { discardWorktree } from '../../lib/task_git.js';
|
|
12
|
+
import { discardWorktree, syncProjectRepo, projectRepoStatus, managedRepoDir } from '../../lib/task_git.js';
|
|
12
13
|
import { removeContainer } from '../../lib/docker.js';
|
|
13
|
-
import {
|
|
14
|
+
import { validateRepositoryUrl } from '../../lib/repo_url.js';
|
|
15
|
+
import { runningTasks, abortRunningTask, syncingProjects } from './scheduler/locks.js';
|
|
14
16
|
import { registerTaskBridge, setTaskBridgeUrl } from './mcp_bridge.js';
|
|
15
17
|
import { loadAgents, loadConfig, dataDir, saveAgents, saveConfig, loadPlugins, loadMcpServers, } from '../../store/json.js';
|
|
16
18
|
import { createSource, deleteSource, patchSource, refreshSource, } from '../../plugins/source_manager.js';
|
|
@@ -227,7 +229,12 @@ export async function startServer(port, host) {
|
|
|
227
229
|
app.post('/api/projects', async (c) => {
|
|
228
230
|
try {
|
|
229
231
|
const body = await c.req.json();
|
|
230
|
-
const { name, description, workingDir, agentId, plannerAgentId, reviewerAgentId, planningEnabled, reviewEnabled, sddEnabled, bootstrapCommands, maxRunSeconds, dockerImage } = body;
|
|
232
|
+
const { name, description, workingDir, agentId, plannerAgentId, reviewerAgentId, planningEnabled, reviewEnabled, sddEnabled, bootstrapCommands, maxRunSeconds, dockerImage, repositoryUrl, repositoryToken } = body;
|
|
233
|
+
const repoUrl = typeof repositoryUrl === 'string' ? repositoryUrl.trim() : '';
|
|
234
|
+
const repoUrlError = validateRepositoryUrl(repoUrl);
|
|
235
|
+
if (repoUrlError) {
|
|
236
|
+
return c.json({ error: repoUrlError }, 400);
|
|
237
|
+
}
|
|
231
238
|
const config = await loadConfig();
|
|
232
239
|
if (!config.projects) {
|
|
233
240
|
config.projects = [];
|
|
@@ -250,6 +257,10 @@ export async function startServer(port, host) {
|
|
|
250
257
|
: null,
|
|
251
258
|
maxRunSeconds: typeof maxRunSeconds === 'number' && maxRunSeconds > 0 ? maxRunSeconds : null,
|
|
252
259
|
dockerImage: typeof dockerImage === 'string' && dockerImage.trim() ? dockerImage.trim() : null,
|
|
260
|
+
repositoryUrl: repoUrl || null,
|
|
261
|
+
repositoryToken: repoUrl && typeof repositoryToken === 'string' && repositoryToken.trim()
|
|
262
|
+
? repositoryToken.trim()
|
|
263
|
+
: null,
|
|
253
264
|
};
|
|
254
265
|
config.projects.push(project);
|
|
255
266
|
await saveConfig(config);
|
|
@@ -263,10 +274,18 @@ export async function startServer(port, host) {
|
|
|
263
274
|
try {
|
|
264
275
|
const id = Number(c.req.param('id'));
|
|
265
276
|
const config = await loadConfig();
|
|
277
|
+
const project = (config.projects || []).find((p) => p.id === id);
|
|
266
278
|
if (config.projects) {
|
|
267
279
|
config.projects = config.projects.filter((p) => p.id !== id);
|
|
268
280
|
await saveConfig(config);
|
|
269
281
|
}
|
|
282
|
+
// Ids are max+1, so deleting the highest one and creating a new project
|
|
283
|
+
// reuses the id — and with it ~/.caretaker/repos/<id>, which the new
|
|
284
|
+
// project would silently inherit (old code, old origin). Remove the
|
|
285
|
+
// managed clone; a user-chosen workingDir is never touched.
|
|
286
|
+
const managed = project ? managedRepoDir(project) : null;
|
|
287
|
+
if (managed)
|
|
288
|
+
await fs.promises.rm(managed, { recursive: true, force: true });
|
|
270
289
|
// Delete task messages first, then tasks — avoids orphaned message rows.
|
|
271
290
|
await runQuery(`DELETE FROM task_messages WHERE taskId IN (SELECT id FROM tasks WHERE projectId = ${id})`);
|
|
272
291
|
await runQuery(`DELETE FROM tasks WHERE projectId = ${id}`);
|
|
@@ -276,6 +295,49 @@ export async function startServer(port, host) {
|
|
|
276
295
|
return c.json({ error: String(err) }, 500);
|
|
277
296
|
}
|
|
278
297
|
});
|
|
298
|
+
// Clone-or-pull a remote-backed project's repository. Progress streams as
|
|
299
|
+
// ndjson (voice-backend pattern); failures travel in-band as an `error` line
|
|
300
|
+
// so URL/token problems are diagnosable from the UI.
|
|
301
|
+
app.post('/api/projects/:id/sync', async (c) => {
|
|
302
|
+
const id = Number(c.req.param('id'));
|
|
303
|
+
const config = await loadConfig();
|
|
304
|
+
const project = (config.projects || []).find((p) => p.id === id);
|
|
305
|
+
if (!project)
|
|
306
|
+
return c.json({ error: 'not found' }, 404);
|
|
307
|
+
if (!project.repositoryUrl?.trim())
|
|
308
|
+
return c.json({ error: 'project has no repository URL' }, 400);
|
|
309
|
+
if (syncingProjects.has(id))
|
|
310
|
+
return c.json({ error: 'sync already running' }, 409);
|
|
311
|
+
syncingProjects.add(id);
|
|
312
|
+
c.header('Content-Type', 'application/x-ndjson');
|
|
313
|
+
return stream(c, async (s) => {
|
|
314
|
+
try {
|
|
315
|
+
for await (const p of syncProjectRepo(project)) {
|
|
316
|
+
await s.writeln(JSON.stringify(p));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
321
|
+
await s.writeln(JSON.stringify({ step: 'error', message }));
|
|
322
|
+
}
|
|
323
|
+
finally {
|
|
324
|
+
syncingProjects.delete(id);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
// Derived repo state — disk + in-flight set at request time, nothing stored.
|
|
329
|
+
app.get('/api/projects/:id/repo-status', async (c) => {
|
|
330
|
+
const id = Number(c.req.param('id'));
|
|
331
|
+
const config = await loadConfig();
|
|
332
|
+
const project = (config.projects || []).find((p) => p.id === id);
|
|
333
|
+
if (!project)
|
|
334
|
+
return c.json({ error: 'not found' }, 404);
|
|
335
|
+
if (!project.repositoryUrl?.trim())
|
|
336
|
+
return c.json({ error: 'project has no repository URL' }, 400);
|
|
337
|
+
if (syncingProjects.has(id))
|
|
338
|
+
return c.json({ state: 'syncing' });
|
|
339
|
+
return c.json(await projectRepoStatus(project));
|
|
340
|
+
});
|
|
279
341
|
// Tasks REST endpoints
|
|
280
342
|
app.get('/api/projects/:id/tasks', async (c) => {
|
|
281
343
|
const id = Number(c.req.param('id'));
|
|
@@ -400,11 +462,30 @@ export async function startServer(port, host) {
|
|
|
400
462
|
return c.json({ ok: false, error: 'not found' }, 404);
|
|
401
463
|
if (!task.worktreePath)
|
|
402
464
|
return c.json({ ok: false, error: 'no worktree' }, 400);
|
|
465
|
+
// Same guard as delete: a manual discard racing a heartbeat cycle would rip
|
|
466
|
+
// the worktree out from under the running agent — and the critical section
|
|
467
|
+
// now includes a network push.
|
|
468
|
+
if (task.lockedAt || runningTasks.has(`task_db_${taskId}`)) {
|
|
469
|
+
return c.json({ ok: false, error: 'Task is currently running. Wait for it to finish or pause it first.' }, 409);
|
|
470
|
+
}
|
|
403
471
|
if (task.dockerContainer) {
|
|
404
472
|
await removeContainer(task.dockerContainer);
|
|
405
473
|
task.dockerContainer = null;
|
|
474
|
+
task.updatedAt = new Date().toISOString();
|
|
475
|
+
await saveTask(task);
|
|
476
|
+
}
|
|
477
|
+
const config = await loadConfig();
|
|
478
|
+
const project = (config.projects || []).find((p) => p.id === task.projectId);
|
|
479
|
+
const repoUrl = project?.repositoryUrl?.trim();
|
|
480
|
+
try {
|
|
481
|
+
await discardWorktree(task.worktreePath, task.title, repoUrl && task.branch
|
|
482
|
+
? { branch: task.branch, url: repoUrl, token: project?.repositoryToken }
|
|
483
|
+
: undefined);
|
|
484
|
+
}
|
|
485
|
+
catch (err) {
|
|
486
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
487
|
+
return c.json({ ok: false, error: `Discard aborted — worktree kept. ${message}` }, 500);
|
|
406
488
|
}
|
|
407
|
-
await discardWorktree(task.worktreePath, task.title);
|
|
408
489
|
task.worktreePath = null;
|
|
409
490
|
task.updatedAt = new Date().toISOString();
|
|
410
491
|
await saveTask(task);
|
|
@@ -467,11 +548,25 @@ export async function startServer(port, host) {
|
|
|
467
548
|
}
|
|
468
549
|
}
|
|
469
550
|
if (task.worktreePath) {
|
|
551
|
+
const config = await loadConfig();
|
|
552
|
+
const project = (config.projects || []).find((p) => p.id === task.projectId);
|
|
553
|
+
const repoUrl = project?.repositoryUrl?.trim();
|
|
554
|
+
const push = repoUrl && task.branch
|
|
555
|
+
? { branch: task.branch, url: repoUrl, token: project?.repositoryToken }
|
|
556
|
+
: undefined;
|
|
470
557
|
try {
|
|
471
|
-
await discardWorktree(task.worktreePath, task.title);
|
|
558
|
+
await discardWorktree(task.worktreePath, task.title, push);
|
|
472
559
|
}
|
|
473
560
|
catch {
|
|
474
|
-
//
|
|
561
|
+
// The user is deleting the task, so a failed push must not block it —
|
|
562
|
+
// but it must not leave the worktree on disk with no task row pointing
|
|
563
|
+
// at it either. Retry without the push; the branch survives locally.
|
|
564
|
+
try {
|
|
565
|
+
await discardWorktree(task.worktreePath, task.title);
|
|
566
|
+
}
|
|
567
|
+
catch {
|
|
568
|
+
// Best-effort: proceed with deletion even if cleanup fails.
|
|
569
|
+
}
|
|
475
570
|
}
|
|
476
571
|
}
|
|
477
572
|
await deleteTask(taskId);
|
|
@@ -750,10 +845,16 @@ export async function startServer(port, host) {
|
|
|
750
845
|
loadPlugins(),
|
|
751
846
|
loadMcpServers(),
|
|
752
847
|
]);
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
848
|
+
// Collapse every builtin `mcp__<ns>__` namespace (task, email, …) into a
|
|
849
|
+
// single wildcard entry: the picker offers the namespace, so a namespace
|
|
850
|
+
// gaining a tool needs no config change. resolveAgentTools expands it.
|
|
851
|
+
const toolNames = harness.tools.list().map((t) => t.name);
|
|
852
|
+
const namespaces = [
|
|
853
|
+
...new Set(toolNames.map((name) => /^mcp__[a-z]+__/.exec(name)?.[0]).filter((p) => !!p)),
|
|
854
|
+
];
|
|
855
|
+
const availableTools = toolNames
|
|
856
|
+
.filter((name) => !namespaces.some((p) => name.startsWith(p)))
|
|
857
|
+
.concat(namespaces.map((p) => `${p}*`));
|
|
757
858
|
const enrichedServers = mcpServersFile.servers.map((server) => {
|
|
758
859
|
let hasMcpTokens = false;
|
|
759
860
|
try {
|
|
@@ -909,6 +1010,16 @@ export async function startServer(port, host) {
|
|
|
909
1010
|
return;
|
|
910
1011
|
case 'saveConfig':
|
|
911
1012
|
try {
|
|
1013
|
+
// The settings form saves the whole config through here, so this
|
|
1014
|
+
// — not POST /api/projects — is the write path that actually
|
|
1015
|
+
// needs to enforce the repository-URL rules.
|
|
1016
|
+
for (const project of msg.config.projects || []) {
|
|
1017
|
+
const repoUrlError = validateRepositoryUrl(project.repositoryUrl || '');
|
|
1018
|
+
if (repoUrlError) {
|
|
1019
|
+
post({ type: 'error', message: `Project "${project.name}": ${repoUrlError}` });
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
912
1023
|
await saveConfig(msg.config);
|
|
913
1024
|
post({ type: 'voiceConfig', voice: voiceClientConfig(msg.config) });
|
|
914
1025
|
void loadAgentsAndSend();
|
|
@@ -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;AAiBrE,MAAM,MAAM,mBAAmB,GAAG;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;IAClG,MAAM,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,CAAC;AAQF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAA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AAA;KAAE,CAAC;CACzC,GAAG,mBAAmB,CAwBtB;AAsMD,wBAAsB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,GAAE,YAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CAuI/F"}
|
|
@@ -81,7 +81,11 @@ export function claudeCodeTaskExtras(p) {
|
|
|
81
81
|
const allowedTools = ['Read', 'Glob', 'Grep', 'mcp__task'];
|
|
82
82
|
if (p.sdd)
|
|
83
83
|
allowedTools.push('Write(**/*.md)', 'Edit(**/*.md)', 'MultiEdit(**/*.md)');
|
|
84
|
-
|
|
84
|
+
// The bridge serves the email tools on the same `task` server, so the prefix
|
|
85
|
+
// allowlist above would reach email_send too. Deny it explicitly: the mirror
|
|
86
|
+
// of PLANNER_ALWAYS_DENIED on the native path (see scheduler/task_roles.ts).
|
|
87
|
+
const disallowedTools = ['Bash', 'mcp__task__email_send'];
|
|
88
|
+
return { permissionMode: 'dontAsk', allowedTools, disallowedTools, extraMcpServers };
|
|
85
89
|
}
|
|
86
90
|
async function buildMcpConfigFile(serverIds, extra) {
|
|
87
91
|
const servers = {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/email_tools.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAkCpD,eAAO,MAAM,qBAAqB,EAAE,IAqBnC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAiE5B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAwE3B,CAAC"}
|