@hyperwindmill/caretaker-cli 0.24.0 → 0.25.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/acp/index.d.ts +3 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +2 -0
- package/dist/acp/install.d.ts +12 -0
- package/dist/acp/install.d.ts.map +1 -0
- package/dist/acp/install.js +110 -0
- package/dist/acp/registry.d.ts +10 -0
- package/dist/acp/registry.d.ts.map +1 -0
- package/dist/acp/registry.js +116 -0
- package/dist/cli/web/mcp_bridge.d.ts +7 -1
- package/dist/cli/web/mcp_bridge.d.ts.map +1 -1
- package/dist/cli/web/mcp_bridge.js +10 -6
- package/dist/cli/web/scheduler/memory_sweep.d.ts.map +1 -1
- package/dist/cli/web/scheduler/memory_sweep.js +1 -0
- package/dist/cli/web/scheduler/task_review.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_review.js +25 -0
- package/dist/cli/web/scheduler/task_roles.d.ts +1 -1
- package/dist/cli/web/scheduler/task_roles.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_roles.js +6 -6
- package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_strategy.js +23 -2
- package/dist/cli/web/server.d.ts +1 -1
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +27 -5
- package/dist/harness/acp_policy.d.ts +41 -0
- package/dist/harness/acp_policy.d.ts.map +1 -0
- package/dist/harness/acp_policy.js +59 -0
- package/dist/harness/acp_pool.d.ts +33 -0
- package/dist/harness/acp_pool.d.ts.map +1 -0
- package/dist/harness/acp_pool.js +148 -0
- package/dist/harness/acp_runner.d.ts +4 -0
- package/dist/harness/acp_runner.d.ts.map +1 -0
- package/dist/harness/acp_runner.js +347 -0
- package/dist/harness/claude_code_runner.d.ts +2 -0
- package/dist/harness/claude_code_runner.d.ts.map +1 -1
- package/dist/harness/claude_code_runner.js +1 -1
- package/dist/harness/confirm_gate.d.ts +12 -0
- package/dist/harness/confirm_gate.d.ts.map +1 -0
- package/dist/harness/confirm_gate.js +33 -0
- package/dist/harness/index.d.ts +1 -0
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +1 -0
- package/dist/harness/loop.d.ts +3 -0
- package/dist/harness/loop.d.ts.map +1 -1
- package/dist/harness/loop.js +6 -0
- package/dist/harness/memory_recall.d.ts +8 -3
- package/dist/harness/memory_recall.d.ts.map +1 -1
- package/dist/harness/memory_recall.js +11 -7
- package/dist/harness/title.js +1 -1
- package/dist/mcp/builtin_server.d.ts +1 -0
- package/dist/mcp/builtin_server.d.ts.map +1 -1
- package/dist/mcp/builtin_server.js +3 -2
- package/dist/mcp/run_command_tool.d.ts +13 -0
- package/dist/mcp/run_command_tool.d.ts.map +1 -0
- package/dist/mcp/run_command_tool.js +51 -0
- package/dist/session/store.d.ts +1 -0
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +6 -0
- package/dist/session/types.d.ts +3 -0
- package/dist/session/types.d.ts.map +1 -1
- package/dist/tui/agents.d.ts.map +1 -1
- package/dist/tui/agents.js +57 -23
- package/dist/tui/chat.d.ts.map +1 -1
- package/dist/tui/chat.js +7 -8
- package/dist/tui/providers.d.ts.map +1 -1
- package/dist/tui/providers.js +116 -17
- package/dist/webview/standalone.css +18 -0
- package/dist/webview/standalone.css.map +2 -2
- package/dist/webview/standalone.js +235 -25
- package/dist/webview/standalone.js.map +2 -2
- package/package.json +8 -3
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PermissionOption, RequestPermissionRequest, RequestPermissionResponse } from '@agentclientprotocol/sdk';
|
|
2
|
+
import type { ConfirmDecision } from './tools/index.js';
|
|
3
|
+
export type AcpPolicyMode = 'interactive' | 'unattended' | 'planner' | 'deny-all';
|
|
4
|
+
export type AcpRunExtras = {
|
|
5
|
+
/** Permission policy. Default 'interactive' (route to the confirm gate). */
|
|
6
|
+
mode?: AcpPolicyMode;
|
|
7
|
+
/** Planner SDD mode: edits allowed on markdown-only locations. */
|
|
8
|
+
sdd?: boolean;
|
|
9
|
+
/** Extra per-run MCP servers (the task bridge), same shape as claude-code's. */
|
|
10
|
+
extraMcpServers?: Record<string, {
|
|
11
|
+
type: 'http';
|
|
12
|
+
url: string;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
}>;
|
|
15
|
+
/** Docker confinement: 'execute' tool calls are denied (the bridge-injected
|
|
16
|
+
* run_command tool is the only shell path). */
|
|
17
|
+
docker?: {
|
|
18
|
+
container: string;
|
|
19
|
+
workdir: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type PermissionDecision = 'allow' | 'deny' | 'ask';
|
|
23
|
+
export declare function decidePermission(req: RequestPermissionRequest, extras: AcpRunExtras): PermissionDecision;
|
|
24
|
+
/** Map a gate decision onto the agent-provided options. Fail-safe: when no
|
|
25
|
+
* matching option exists, respond 'cancelled' (never invent an optionId). */
|
|
26
|
+
export declare function buildPermissionResponse(options: PermissionOption[], decision: ConfirmDecision | 'deny'): RequestPermissionResponse;
|
|
27
|
+
/** Role restrictions + task-bridge wiring for autonomous task runs — the ACP
|
|
28
|
+
* mirror of claudeCodeTaskExtras. */
|
|
29
|
+
export declare function acpTaskExtras(p: {
|
|
30
|
+
planning: boolean;
|
|
31
|
+
sdd: boolean;
|
|
32
|
+
bridge?: {
|
|
33
|
+
url: string;
|
|
34
|
+
token: string;
|
|
35
|
+
};
|
|
36
|
+
docker?: {
|
|
37
|
+
container: string;
|
|
38
|
+
workdir: string;
|
|
39
|
+
};
|
|
40
|
+
}): AcpRunExtras;
|
|
41
|
+
//# sourceMappingURL=acp_policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp_policy.d.ts","sourceRoot":"","sources":["../../src/harness/acp_policy.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,YAAY,GAAG,SAAS,GAAG,UAAU,CAAC;AAElF,MAAM,MAAM,YAAY,GAAG;IACzB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,kEAAkE;IAClE,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,gFAAgF;IAChF,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;oDACgD;IAChD,MAAM,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAM1D,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,YAAY,GACnB,kBAAkB,CAqBpB;AAED;8EAC8E;AAC9E,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,gBAAgB,EAAE,EAC3B,QAAQ,EAAE,eAAe,GAAG,MAAM,GACjC,yBAAyB,CAY3B;AAED;sCACsC;AACtC,wBAAgB,aAAa,CAAC,CAAC,EAAE;IAC/B,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;IACxC,MAAM,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,GAAG,YAAY,CAWf"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Permission policy for ACP runs: one pure function replaces the per-runner
|
|
2
|
+
// tangle (claude-code CLI flags, native tool filtering). Every ACP
|
|
3
|
+
// session/request_permission goes through decidePermission; 'ask' is resolved
|
|
4
|
+
// by the caller via the ordinary confirm gate.
|
|
5
|
+
/** Kinds a planner must never perform. 'other' stays allowed on purpose:
|
|
6
|
+
* MCP tool calls (task_submit_plan, task_get_state) surface as 'other'. */
|
|
7
|
+
const PLANNER_DENIED_KINDS = new Set(['edit', 'delete', 'move', 'execute']);
|
|
8
|
+
export function decidePermission(req, extras) {
|
|
9
|
+
const mode = extras.mode ?? 'interactive';
|
|
10
|
+
const kind = req.toolCall.kind ?? 'other';
|
|
11
|
+
// Docker confinement outranks every mode: shell goes through run_command or dies.
|
|
12
|
+
if (extras.docker && kind === 'execute')
|
|
13
|
+
return 'deny';
|
|
14
|
+
switch (mode) {
|
|
15
|
+
case 'deny-all':
|
|
16
|
+
return 'deny';
|
|
17
|
+
case 'unattended':
|
|
18
|
+
return 'allow';
|
|
19
|
+
case 'planner': {
|
|
20
|
+
if (!PLANNER_DENIED_KINDS.has(kind))
|
|
21
|
+
return 'allow';
|
|
22
|
+
if (extras.sdd && kind === 'edit') {
|
|
23
|
+
const locations = req.toolCall.locations ?? [];
|
|
24
|
+
if (locations.length > 0 && locations.every((l) => l.path.endsWith('.md')))
|
|
25
|
+
return 'allow';
|
|
26
|
+
}
|
|
27
|
+
return 'deny';
|
|
28
|
+
}
|
|
29
|
+
case 'interactive':
|
|
30
|
+
return 'ask';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Map a gate decision onto the agent-provided options. Fail-safe: when no
|
|
34
|
+
* matching option exists, respond 'cancelled' (never invent an optionId). */
|
|
35
|
+
export function buildPermissionResponse(options, decision) {
|
|
36
|
+
const pick = (kinds) => kinds.map((k) => options.find((o) => o.kind === k)).find(Boolean);
|
|
37
|
+
const opt = decision === 'reject' || decision === 'deny'
|
|
38
|
+
? pick(['reject_once', 'reject_always'])
|
|
39
|
+
: decision === 'always'
|
|
40
|
+
? pick(['allow_always', 'allow_once'])
|
|
41
|
+
: pick(['allow_once', 'allow_always']);
|
|
42
|
+
return opt
|
|
43
|
+
? { outcome: { outcome: 'selected', optionId: opt.optionId } }
|
|
44
|
+
: { outcome: { outcome: 'cancelled' } };
|
|
45
|
+
}
|
|
46
|
+
/** Role restrictions + task-bridge wiring for autonomous task runs — the ACP
|
|
47
|
+
* mirror of claudeCodeTaskExtras. */
|
|
48
|
+
export function acpTaskExtras(p) {
|
|
49
|
+
const extraMcpServers = p.bridge
|
|
50
|
+
? {
|
|
51
|
+
task: {
|
|
52
|
+
type: 'http',
|
|
53
|
+
url: p.bridge.url,
|
|
54
|
+
headers: { Authorization: `Bearer ${p.bridge.token}` },
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
: undefined;
|
|
58
|
+
return { mode: p.planning ? 'planner' : 'unattended', sdd: p.sdd, extraMcpServers, docker: p.docker };
|
|
59
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ClientApp, type ClientConnection, type InitializeResponse, type RequestPermissionRequest, type RequestPermissionResponse, type SessionNotification, type Usage } from '@agentclientprotocol/sdk';
|
|
2
|
+
import type { ProviderConfig } from '../types.js';
|
|
3
|
+
export type TurnBinding = {
|
|
4
|
+
/** null until session/new returns (drop nothing: the first updates can only
|
|
5
|
+
* belong to our session — one child, one session). */
|
|
6
|
+
acpSessionId: string | null;
|
|
7
|
+
onUpdate: (n: SessionNotification) => void | Promise<void>;
|
|
8
|
+
onPermission: (r: RequestPermissionRequest) => Promise<RequestPermissionResponse>;
|
|
9
|
+
};
|
|
10
|
+
export type AcpAgentHandle = {
|
|
11
|
+
conn: ClientConnection;
|
|
12
|
+
init: InitializeResponse;
|
|
13
|
+
binding: {
|
|
14
|
+
current: TurnBinding | null;
|
|
15
|
+
};
|
|
16
|
+
/** ACP session id once created/loaded — reused across turns of this handle. */
|
|
17
|
+
acpSessionId?: string;
|
|
18
|
+
/** Last session-cumulative usage snapshot (per-turn usage is the diff). */
|
|
19
|
+
lastUsage?: Usage;
|
|
20
|
+
kill: () => void;
|
|
21
|
+
lastUsed: number;
|
|
22
|
+
};
|
|
23
|
+
type Connector = (provider: ProviderConfig, app: ClientApp) => {
|
|
24
|
+
conn: ClientConnection;
|
|
25
|
+
kill: () => void;
|
|
26
|
+
};
|
|
27
|
+
export declare function __setConnector(fn: Connector): void;
|
|
28
|
+
export declare function __resetConnector(): void;
|
|
29
|
+
export declare function acquireAcpAgent(provider: ProviderConfig, poolKey: string | null): Promise<AcpAgentHandle>;
|
|
30
|
+
export declare function releaseAcpAgent(poolKey: string | null, handle: AcpAgentHandle): void;
|
|
31
|
+
export declare function __shutdownAcpPool(): void;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=acp_pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp_pool.d.ts","sourceRoot":"","sources":["../../src/harness/acp_pool.ts"],"names":[],"mappings":"AAYA,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACxB,KAAK,KAAK,EACX,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,MAAM,WAAW,GAAG;IACxB;2DACuD;IACvD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,YAAY,EAAE,CAAC,CAAC,EAAE,wBAAwB,KAAK,OAAO,CAAC,yBAAyB,CAAC,CAAC;CACnF,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE;QAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAAA;KAAE,CAAC;IACzC,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAGF,KAAK,SAAS,GAAG,CACf,QAAQ,EAAE,cAAc,EACxB,GAAG,EAAE,SAAS,KACX;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC;AAmClD,wBAAgB,cAAc,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI,CAElD;AACD,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AA6DD,wBAAsB,eAAe,CACnC,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC,cAAc,CAAC,CAqBzB;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAMpF;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAUxC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// ACP agent process pool. Unlike claude -p (one process per turn + --resume),
|
|
2
|
+
// an ACP child is long-lived: spawn → initialize → session/new, then N
|
|
3
|
+
// session/prompt calls on the same child. One child per caretaker session
|
|
4
|
+
// (poolKey = `${agentId}:${sessionId}`); sessionId-less runs (tasks, sweep,
|
|
5
|
+
// headless one-shots) get an ephemeral child killed at end of run.
|
|
6
|
+
//
|
|
7
|
+
// Handlers are registered once per child at client() construction and route
|
|
8
|
+
// through a mutable `binding` the runner sets at turn start — turns on one
|
|
9
|
+
// session are serialized by the surfaces, so there is no race.
|
|
10
|
+
import { spawn as nodeSpawn } from 'node:child_process';
|
|
11
|
+
import { Readable, Writable } from 'node:stream';
|
|
12
|
+
import { client, ndJsonStream, PROTOCOL_VERSION, } from '@agentclientprotocol/sdk';
|
|
13
|
+
import { mergeShellEnv } from './tools/builtin/shell-env.js';
|
|
14
|
+
const defaultConnector = (provider, app) => {
|
|
15
|
+
if (!provider.command) {
|
|
16
|
+
throw new Error(`acp runner: provider "${provider.name}" has no command — set the ACP agent server executable (e.g. npx) in the provider settings`);
|
|
17
|
+
}
|
|
18
|
+
const child = nodeSpawn(provider.command, provider.args ?? [], {
|
|
19
|
+
// Same env policy as the claude-code runner: probed interactive-shell PATH
|
|
20
|
+
// merged WITHOUT scrubbing secrets, so env-based auth survives; provider.env on top.
|
|
21
|
+
env: { ...mergeShellEnv(process.env), ...provider.env },
|
|
22
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
23
|
+
});
|
|
24
|
+
let stderrTail = '';
|
|
25
|
+
child.stderr?.on('data', (d) => {
|
|
26
|
+
stderrTail = (stderrTail + String(d)).slice(-4096);
|
|
27
|
+
});
|
|
28
|
+
child.on('error', (err) => {
|
|
29
|
+
console.warn(`[acp] failed to start "${provider.command}": ${err.message}`);
|
|
30
|
+
});
|
|
31
|
+
child.on('close', (code) => {
|
|
32
|
+
if (code !== 0 && code !== null && stderrTail) {
|
|
33
|
+
console.warn(`[acp] "${provider.command}" exited ${code}: ${stderrTail.trim()}`);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const stream = ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
|
|
37
|
+
const conn = app.connect(stream);
|
|
38
|
+
return { conn, kill: () => child.kill('SIGTERM') };
|
|
39
|
+
};
|
|
40
|
+
let connector = defaultConnector;
|
|
41
|
+
export function __setConnector(fn) {
|
|
42
|
+
connector = fn;
|
|
43
|
+
}
|
|
44
|
+
export function __resetConnector() {
|
|
45
|
+
connector = defaultConnector;
|
|
46
|
+
}
|
|
47
|
+
// ─── pool ───────────────────────────────────────────────────────────────
|
|
48
|
+
const pool = new Map();
|
|
49
|
+
const IDLE_TTL_MS = 10 * 60_000;
|
|
50
|
+
let reaper = null;
|
|
51
|
+
function ensureReaper() {
|
|
52
|
+
if (reaper)
|
|
53
|
+
return;
|
|
54
|
+
reaper = setInterval(() => {
|
|
55
|
+
const now = Date.now();
|
|
56
|
+
for (const [key, h] of pool) {
|
|
57
|
+
if (h.binding.current === null && now - h.lastUsed > IDLE_TTL_MS) {
|
|
58
|
+
pool.delete(key);
|
|
59
|
+
h.kill();
|
|
60
|
+
h.conn.close();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, 60_000);
|
|
64
|
+
reaper.unref?.();
|
|
65
|
+
}
|
|
66
|
+
async function createHandle(provider) {
|
|
67
|
+
const binding = { current: null };
|
|
68
|
+
const app = client({ name: 'caretaker' })
|
|
69
|
+
.onNotification('session/update', async (ctx) => {
|
|
70
|
+
const b = binding.current;
|
|
71
|
+
if (!b)
|
|
72
|
+
return;
|
|
73
|
+
if (b.acpSessionId !== null && ctx.params.sessionId !== b.acpSessionId)
|
|
74
|
+
return;
|
|
75
|
+
await b.onUpdate(ctx.params);
|
|
76
|
+
})
|
|
77
|
+
.onRequest('session/request_permission', async (ctx) => {
|
|
78
|
+
const b = binding.current;
|
|
79
|
+
// No turn in flight: fail-safe cancel (never allow unattended).
|
|
80
|
+
if (!b)
|
|
81
|
+
return { outcome: { outcome: 'cancelled' } };
|
|
82
|
+
return b.onPermission(ctx.params);
|
|
83
|
+
});
|
|
84
|
+
const { conn, kill } = connector(provider, app);
|
|
85
|
+
let init;
|
|
86
|
+
try {
|
|
87
|
+
init = await conn.agent.request('initialize', {
|
|
88
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
89
|
+
clientCapabilities: {
|
|
90
|
+
// v1 deliberately advertises neither fs nor terminal (see spec):
|
|
91
|
+
// agent-side fs writes the same bind-mounted files; shell confinement
|
|
92
|
+
// under docker is deny-execute + the bridge run_command tool.
|
|
93
|
+
fs: { readTextFile: false, writeTextFile: false },
|
|
94
|
+
terminal: false,
|
|
95
|
+
},
|
|
96
|
+
clientInfo: { name: 'caretaker', version: '1' },
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
// A child that fails the handshake (not an ACP binary, crash at boot,
|
|
101
|
+
// protocol mismatch) must not be leaked as a zombie process.
|
|
102
|
+
kill();
|
|
103
|
+
conn.close();
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
106
|
+
return { conn, init, binding, kill, lastUsed: Date.now() };
|
|
107
|
+
}
|
|
108
|
+
export async function acquireAcpAgent(provider, poolKey) {
|
|
109
|
+
if (poolKey) {
|
|
110
|
+
const existing = pool.get(poolKey);
|
|
111
|
+
if (existing) {
|
|
112
|
+
if (!existing.conn.signal.aborted) {
|
|
113
|
+
existing.lastUsed = Date.now();
|
|
114
|
+
return existing;
|
|
115
|
+
}
|
|
116
|
+
pool.delete(poolKey); // dead child: recreate below
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const handle = await createHandle(provider);
|
|
120
|
+
if (poolKey) {
|
|
121
|
+
pool.set(poolKey, handle);
|
|
122
|
+
ensureReaper();
|
|
123
|
+
// Self-cleanup when the child dies on its own.
|
|
124
|
+
void handle.conn.closed.then(() => {
|
|
125
|
+
if (pool.get(poolKey) === handle)
|
|
126
|
+
pool.delete(poolKey);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return handle;
|
|
130
|
+
}
|
|
131
|
+
export function releaseAcpAgent(poolKey, handle) {
|
|
132
|
+
handle.lastUsed = Date.now();
|
|
133
|
+
if (!poolKey) {
|
|
134
|
+
handle.kill();
|
|
135
|
+
handle.conn.close();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export function __shutdownAcpPool() {
|
|
139
|
+
for (const [key, h] of pool) {
|
|
140
|
+
pool.delete(key);
|
|
141
|
+
h.kill();
|
|
142
|
+
h.conn.close();
|
|
143
|
+
}
|
|
144
|
+
if (reaper) {
|
|
145
|
+
clearInterval(reaper);
|
|
146
|
+
reaper = null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RunOptions, RunCallbacks, RunResult } from './loop.js';
|
|
2
|
+
export declare function isAdapterNotice(text: string, meta?: unknown): boolean;
|
|
3
|
+
export declare function runAcp(opts: RunOptions, cb?: RunCallbacks): Promise<RunResult>;
|
|
4
|
+
//# sourceMappingURL=acp_runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp_runner.d.ts","sourceRoot":"","sources":["../../src/harness/acp_runner.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAuFrE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAIrE;AAYD,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,GAAE,YAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CA+OxF"}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
// ACP runner: implements the same run() contract as loop.ts by driving an
|
|
2
|
+
// Agent Client Protocol agent (claude-agent-acp, codex-acp, agy_acp_server, …)
|
|
3
|
+
// over JSON-RPC/stdio. The agent owns the loop and its tools; caretaker owns
|
|
4
|
+
// the permission policy (acp_policy.ts), display persistence (cb.onMessage),
|
|
5
|
+
// and session continuity (acpSessionId + session/load when supported).
|
|
6
|
+
//
|
|
7
|
+
// System prompt is fabricated client-side (ACP has no system-prompt field):
|
|
8
|
+
// the stable context block (agent systemPrompt + context files minus the
|
|
9
|
+
// runner's self-loaded ones — the mirror of claude-code's
|
|
10
|
+
// --append-system-prompt) rides the FIRST turn of each ACP session; volatile
|
|
11
|
+
// parts (<memories>, voice block) ride every turn. Under ACP the prompt enters
|
|
12
|
+
// history and accumulates, hence the split.
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { loadContextFiles, formatContextBlock, resolveFileReferences } from './context_files.js';
|
|
15
|
+
import { buildMemoriesBlock } from './memory_recall.js';
|
|
16
|
+
import { VOICE_CONVERSATION_PRELUDE } from './prelude.js';
|
|
17
|
+
import { foldHistory } from './claude_code_runner.js';
|
|
18
|
+
import { decidePermission, buildPermissionResponse } from './acp_policy.js';
|
|
19
|
+
import { acquireAcpAgent, releaseAcpAgent } from './acp_pool.js';
|
|
20
|
+
import { readSession, updateAcpSessionId, assistantMessage, toolMessage } from '../session/store.js';
|
|
21
|
+
import { loadMcpServers } from '../store/json.js';
|
|
22
|
+
import { resolvedServerRuntime } from '../mcp/client.js';
|
|
23
|
+
const CANCEL_GRACE_MS = 5_000;
|
|
24
|
+
/** Agent's configured MCP servers + per-run extras (task bridge) as ACP shapes. */
|
|
25
|
+
async function resolveAcpMcpServers(serverIds, extra) {
|
|
26
|
+
const out = [];
|
|
27
|
+
if (serverIds.length > 0) {
|
|
28
|
+
const file = await loadMcpServers();
|
|
29
|
+
for (const id of serverIds) {
|
|
30
|
+
const cfg = file.servers.find((s) => s.id === id);
|
|
31
|
+
if (!cfg)
|
|
32
|
+
continue;
|
|
33
|
+
const r = await resolvedServerRuntime(cfg).catch(() => null);
|
|
34
|
+
if (!r) {
|
|
35
|
+
console.warn(`[acp] skipping MCP server "${id}" (disabled or no usable credentials)`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (r.type === 'stdio') {
|
|
39
|
+
out.push({
|
|
40
|
+
name: id,
|
|
41
|
+
command: r.command,
|
|
42
|
+
args: r.args ?? [],
|
|
43
|
+
env: Object.entries(r.env ?? {}).map(([name, value]) => ({ name, value })),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
out.push({
|
|
48
|
+
type: 'http',
|
|
49
|
+
name: id,
|
|
50
|
+
url: r.url,
|
|
51
|
+
headers: Object.entries(r.headers ?? {}).map(([name, value]) => ({ name, value })),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const [name, def] of Object.entries(extra ?? {})) {
|
|
57
|
+
out.push({
|
|
58
|
+
type: 'http',
|
|
59
|
+
name,
|
|
60
|
+
url: def.url,
|
|
61
|
+
headers: Object.entries(def.headers ?? {}).map(([n, v]) => ({ name: n, value: v })),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/** Session-cumulative → per-turn usage (clamped; unknown baseline = full total). */
|
|
67
|
+
function diffUsage(prev, cur) {
|
|
68
|
+
const d = (a, b) => Math.max(0, a - (b ?? 0));
|
|
69
|
+
const usage = {
|
|
70
|
+
input: d(cur.inputTokens, prev?.inputTokens),
|
|
71
|
+
output: d(cur.outputTokens, prev?.outputTokens),
|
|
72
|
+
};
|
|
73
|
+
if (cur.cachedReadTokens != null)
|
|
74
|
+
usage.cacheRead = d(cur.cachedReadTokens, prev?.cachedReadTokens ?? undefined);
|
|
75
|
+
if (cur.cachedWriteTokens != null)
|
|
76
|
+
usage.cacheWrite = d(cur.cachedWriteTokens, prev?.cachedWriteTokens ?? undefined);
|
|
77
|
+
return usage;
|
|
78
|
+
}
|
|
79
|
+
/** claude-agent-acp harness notices (hook output, warnings) are demoted to
|
|
80
|
+
* the thinking channel: visible but collapsed, out of the persisted reply
|
|
81
|
+
* text and out of TTS. Two signals, in order:
|
|
82
|
+
* 1. `_meta.claudeCode.kind === 'informational'` on the chunk — the marker
|
|
83
|
+
* https://github.com/agentclientprotocol/claude-agent-acp/issues/1042
|
|
84
|
+
* landed (PR #1055, 2026-09-23). Covers every level, including 'info'
|
|
85
|
+
* chunks that carry no visible prefix.
|
|
86
|
+
* 2. Fallback for pre-#1055 adapters (pinned npx versions): the folded
|
|
87
|
+
* `**Notice:** …` / `**Warning:** …` / `**Error:** …` text prefix. A
|
|
88
|
+
* notice arrives as ONE complete chunk, so only a whole-chunk prefix
|
|
89
|
+
* match counts — model deltas that merely contain a bold label
|
|
90
|
+
* mid-stream stay untouched. Drop this arm when pre-fix adapters are no
|
|
91
|
+
* longer a concern. */
|
|
92
|
+
const ADAPTER_NOTICE_RE = /^\*\*(Notice|Warning|Error):\*\* /;
|
|
93
|
+
export function isAdapterNotice(text, meta) {
|
|
94
|
+
const kind = meta?.claudeCode?.kind;
|
|
95
|
+
if (kind === 'informational')
|
|
96
|
+
return true;
|
|
97
|
+
return ADAPTER_NOTICE_RE.test(text);
|
|
98
|
+
}
|
|
99
|
+
function extractToolResultText(content) {
|
|
100
|
+
if (!Array.isArray(content))
|
|
101
|
+
return '';
|
|
102
|
+
return content
|
|
103
|
+
.map((c) => c?.type === 'content' && c.content?.type === 'text' ? String(c.content.text) : '')
|
|
104
|
+
.filter(Boolean)
|
|
105
|
+
.join('\n');
|
|
106
|
+
}
|
|
107
|
+
export async function runAcp(opts, cb = {}) {
|
|
108
|
+
const { agent, provider } = opts;
|
|
109
|
+
const extras = opts.acp ?? {};
|
|
110
|
+
const workingDir = opts.workingDir ?? process.cwd();
|
|
111
|
+
const safeEmit = async (fn) => {
|
|
112
|
+
try {
|
|
113
|
+
await fn?.();
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
console.warn('[acp] callback error:', err);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
// 1. Stable context block (mirror of claude-code's --append-system-prompt,
|
|
120
|
+
// minus files this runner self-loads).
|
|
121
|
+
const selfLoaded = new Set(provider.selfLoadedContextFiles ?? []);
|
|
122
|
+
const sys = await resolveFileReferences(agent.systemPrompt ?? '', workingDir);
|
|
123
|
+
const ctxEntries = (await loadContextFiles(workingDir)).filter((e) => !selfLoaded.has(path.basename(e.path)));
|
|
124
|
+
const stableBlock = [sys, ctxEntries.length ? formatContextBlock(ctxEntries) : '']
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
.join('\n\n');
|
|
127
|
+
// 2. Volatile per-turn block.
|
|
128
|
+
const memoriesBlock = opts.skipMemoryRecall
|
|
129
|
+
? ''
|
|
130
|
+
: await buildMemoriesBlock(opts.prompt, workingDir, opts.memoryProjectId);
|
|
131
|
+
const volatileBlock = [memoriesBlock, opts.voiceConversation ? VOICE_CONVERSATION_PRELUDE : '']
|
|
132
|
+
.filter(Boolean)
|
|
133
|
+
.join('\n\n');
|
|
134
|
+
const mcpServers = await resolveAcpMcpServers(agent.mcpServers ?? [], extras.extraMcpServers);
|
|
135
|
+
// 3. Acquire child (pooled per caretaker session; ephemeral otherwise).
|
|
136
|
+
const poolKey = opts.sessionId ? `${agent.id}:${opts.sessionId}` : null;
|
|
137
|
+
let handle;
|
|
138
|
+
try {
|
|
139
|
+
handle = await acquireAcpAgent(provider, poolKey);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
throw new Error(`acp runner failed to start the agent for provider "${provider.name}": ${err?.message ?? err} ` +
|
|
143
|
+
`(is it installed and authenticated? Log in with the agent's own CLI first.)`);
|
|
144
|
+
}
|
|
145
|
+
// 4. Turn accumulation state.
|
|
146
|
+
const parts = [];
|
|
147
|
+
let text = '';
|
|
148
|
+
let toolCalls = 0;
|
|
149
|
+
const pushText = (t) => {
|
|
150
|
+
text += t;
|
|
151
|
+
const last = parts[parts.length - 1];
|
|
152
|
+
if (last && last.type === 'text')
|
|
153
|
+
last.text += t;
|
|
154
|
+
else
|
|
155
|
+
parts.push({ type: 'text', text: t });
|
|
156
|
+
};
|
|
157
|
+
const onUpdate = async (n) => {
|
|
158
|
+
const u = n.update;
|
|
159
|
+
switch (u.sessionUpdate) {
|
|
160
|
+
case 'agent_message_chunk':
|
|
161
|
+
if (u.content.type === 'text') {
|
|
162
|
+
if (isAdapterNotice(u.content.text, u._meta)) {
|
|
163
|
+
// Adapter harness notice (see isAdapterNotice / issue #1042):
|
|
164
|
+
// demote to thinking instead of polluting the reply.
|
|
165
|
+
await safeEmit(() => cb.onThinking?.(u.content.text));
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
pushText(u.content.text);
|
|
169
|
+
await safeEmit(() => cb.onChunk?.(u.content.text));
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
case 'agent_thought_chunk':
|
|
173
|
+
if (u.content.type === 'text')
|
|
174
|
+
await safeEmit(() => cb.onThinking?.(u.content.text));
|
|
175
|
+
break;
|
|
176
|
+
case 'tool_call': {
|
|
177
|
+
toolCalls += 1;
|
|
178
|
+
const name = u.name ?? u.title;
|
|
179
|
+
parts.push({ type: 'tool_use', id: u.toolCallId, name, args: u.rawInput ?? {} });
|
|
180
|
+
await safeEmit(() => cb.onToolCall?.(u.toolCallId, name, u.rawInput ?? {}));
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case 'tool_call_update': {
|
|
184
|
+
if (u.status === 'completed' || u.status === 'failed') {
|
|
185
|
+
const resultText = extractToolResultText(u.content);
|
|
186
|
+
await safeEmit(() => cb.onToolResult?.(u.toolCallId, resultText));
|
|
187
|
+
await safeEmit(() => cb.onMessage?.(toolMessage(u.toolCallId, resultText)));
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
default:
|
|
192
|
+
break; // plan / usage_update / mode updates: not rendered in v1
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const onPermission = async (req) => {
|
|
196
|
+
const decision = decidePermission(req, extras);
|
|
197
|
+
if (decision === 'allow')
|
|
198
|
+
return buildPermissionResponse(req.options, 'once');
|
|
199
|
+
if (decision === 'deny')
|
|
200
|
+
return buildPermissionResponse(req.options, 'deny');
|
|
201
|
+
// 'ask' → the ordinary confirm gate; no gate wired means allow (the caller
|
|
202
|
+
// decides which surfaces gate, same contract as the native loop).
|
|
203
|
+
if (!cb.confirmTool)
|
|
204
|
+
return buildPermissionResponse(req.options, 'once');
|
|
205
|
+
const name = req.toolCall.name ?? req.toolCall.title ?? 'tool';
|
|
206
|
+
const answer = await cb.confirmTool(req.toolCall.toolCallId, String(name), req.toolCall.rawInput ?? {});
|
|
207
|
+
return buildPermissionResponse(req.options, answer);
|
|
208
|
+
};
|
|
209
|
+
let stopReason = 'error';
|
|
210
|
+
let usage = { input: 0, output: 0 };
|
|
211
|
+
let aborted = false;
|
|
212
|
+
let graceTimer;
|
|
213
|
+
try {
|
|
214
|
+
// 5. Resolve the ACP session: pooled live id → persisted id via
|
|
215
|
+
// session/load (capability-gated) → session/new (+ folded history).
|
|
216
|
+
let acpSessionId = handle.acpSessionId;
|
|
217
|
+
let isNewSession = false;
|
|
218
|
+
if (!acpSessionId) {
|
|
219
|
+
let persisted;
|
|
220
|
+
let modes;
|
|
221
|
+
if (opts.sessionId) {
|
|
222
|
+
try {
|
|
223
|
+
persisted = (await readSession(agent.id, opts.sessionId)).meta.acpSessionId;
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
/* new session */
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (persisted && handle.init.agentCapabilities?.loadSession) {
|
|
230
|
+
// Load BEFORE arming the binding: the replayed history streams as
|
|
231
|
+
// session/update notifications we deliberately drop (our own store
|
|
232
|
+
// already has the conversation).
|
|
233
|
+
try {
|
|
234
|
+
const loadRes = await handle.conn.agent.request('session/load', {
|
|
235
|
+
sessionId: persisted,
|
|
236
|
+
cwd: workingDir,
|
|
237
|
+
mcpServers,
|
|
238
|
+
});
|
|
239
|
+
modes = loadRes.modes;
|
|
240
|
+
acpSessionId = persisted;
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
console.warn(`[acp] session/load "${persisted}" failed; starting fresh:`, err);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (!acpSessionId) {
|
|
247
|
+
const res = await handle.conn.agent.request('session/new', { cwd: workingDir, mcpServers });
|
|
248
|
+
acpSessionId = res.sessionId;
|
|
249
|
+
modes = res.modes;
|
|
250
|
+
isNewSession = true;
|
|
251
|
+
}
|
|
252
|
+
handle.acpSessionId = acpSessionId;
|
|
253
|
+
// Agent-level session mode (AgentConfig.acpMode): pin the agent to one
|
|
254
|
+
// of its OWN permission modes so it stops asking at the source. Only for
|
|
255
|
+
// interactive-policy runs — task runs' policy (unattended/planner/
|
|
256
|
+
// deny-all) stays authoritative. Unknown/unadvertised modes warn and
|
|
257
|
+
// continue: a wrong mode id must never brick the chat.
|
|
258
|
+
const wantMode = agent.acpMode?.trim();
|
|
259
|
+
if (wantMode && (extras.mode ?? 'interactive') === 'interactive') {
|
|
260
|
+
const available = modes?.availableModes.some((m) => m.id === wantMode);
|
|
261
|
+
if (!available) {
|
|
262
|
+
console.warn(`[acp] agent "${agent.name}": acpMode "${wantMode}" is not among the agent's advertised modes — ignored`);
|
|
263
|
+
}
|
|
264
|
+
else if (modes.currentModeId !== wantMode) {
|
|
265
|
+
try {
|
|
266
|
+
await handle.conn.agent.request('session/set_mode', {
|
|
267
|
+
sessionId: acpSessionId,
|
|
268
|
+
modeId: wantMode,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
console.warn(`[acp] session/set_mode "${wantMode}" failed:`, err);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (opts.sessionId && acpSessionId !== persisted) {
|
|
277
|
+
try {
|
|
278
|
+
await updateAcpSessionId({ agentId: agent.id, id: opts.sessionId }, acpSessionId);
|
|
279
|
+
}
|
|
280
|
+
catch (err) {
|
|
281
|
+
console.warn('[acp] failed to persist session id:', err);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// 6. Prompt blocks: stable context on the session's first turn; volatile
|
|
286
|
+
// every turn; history folded only into a brand-new session.
|
|
287
|
+
const blocks = [];
|
|
288
|
+
if (isNewSession && stableBlock) {
|
|
289
|
+
blocks.push({ type: 'text', text: `<caretaker-context>\n${stableBlock}\n</caretaker-context>` });
|
|
290
|
+
}
|
|
291
|
+
if (volatileBlock)
|
|
292
|
+
blocks.push({ type: 'text', text: volatileBlock });
|
|
293
|
+
blocks.push({
|
|
294
|
+
type: 'text',
|
|
295
|
+
text: isNewSession ? foldHistory(opts.history, opts.prompt) : opts.prompt,
|
|
296
|
+
});
|
|
297
|
+
// 7. Arm the binding, wire abort, send the prompt.
|
|
298
|
+
handle.binding.current = { acpSessionId, onUpdate, onPermission };
|
|
299
|
+
const onAbort = () => {
|
|
300
|
+
aborted = true;
|
|
301
|
+
void handle.conn.agent.notify('session/cancel', { sessionId: acpSessionId }).catch(() => { });
|
|
302
|
+
graceTimer = setTimeout(() => handle.kill(), CANCEL_GRACE_MS);
|
|
303
|
+
};
|
|
304
|
+
opts.signal?.addEventListener('abort', onAbort, { once: true });
|
|
305
|
+
try {
|
|
306
|
+
if (opts.signal?.aborted) {
|
|
307
|
+
// addEventListener never fires for a signal aborted BEFORE registration
|
|
308
|
+
// (e.g. a Pause or wall-clock budget landing during session setup) —
|
|
309
|
+
// without this check the prompt would run un-cancellable, and a wedged
|
|
310
|
+
// agent would hang the turn forever.
|
|
311
|
+
aborted = true;
|
|
312
|
+
return { text, toolCalls, usage, stop: 'aborted' };
|
|
313
|
+
}
|
|
314
|
+
const res = await handle.conn.agent.request('session/prompt', {
|
|
315
|
+
sessionId: acpSessionId,
|
|
316
|
+
prompt: blocks,
|
|
317
|
+
});
|
|
318
|
+
stopReason = res.stopReason;
|
|
319
|
+
if (res.usage) {
|
|
320
|
+
usage = diffUsage(handle.lastUsage, res.usage);
|
|
321
|
+
handle.lastUsage = res.usage;
|
|
322
|
+
await safeEmit(() => cb.onUsage?.(usage));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
finally {
|
|
326
|
+
opts.signal?.removeEventListener('abort', onAbort);
|
|
327
|
+
if (graceTimer)
|
|
328
|
+
clearTimeout(graceTimer);
|
|
329
|
+
handle.binding.current = null;
|
|
330
|
+
}
|
|
331
|
+
if (parts.length > 0)
|
|
332
|
+
await safeEmit(() => cb.onMessage?.(assistantMessage(parts, usage)));
|
|
333
|
+
if (aborted || stopReason === 'cancelled')
|
|
334
|
+
return { text, toolCalls, usage, stop: 'aborted' };
|
|
335
|
+
if (stopReason === 'max_turn_requests')
|
|
336
|
+
return { text, toolCalls, usage, stop: 'max_turns' };
|
|
337
|
+
return { text, toolCalls, usage, stop: 'done' };
|
|
338
|
+
}
|
|
339
|
+
catch (err) {
|
|
340
|
+
if (aborted)
|
|
341
|
+
return { text, toolCalls, usage, stop: 'aborted' };
|
|
342
|
+
throw new Error(`acp runner: ${err?.message ?? String(err)}`);
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
releaseAcpAgent(poolKey, handle);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type SpawnOptions } from 'node:child_process';
|
|
2
2
|
import type { RunOptions, RunCallbacks, RunResult } from './loop.js';
|
|
3
|
+
import type { MessageRecord } from '../session/types.js';
|
|
3
4
|
export type ClaudeCodeRunExtras = {
|
|
4
5
|
permissionMode?: string;
|
|
5
6
|
allowedTools?: string[];
|
|
@@ -50,6 +51,7 @@ export declare function claudeCodeTaskExtras(p: {
|
|
|
50
51
|
token: string;
|
|
51
52
|
};
|
|
52
53
|
}): ClaudeCodeRunExtras;
|
|
54
|
+
export declare function foldHistory(history: MessageRecord[] | undefined, prompt: string): string;
|
|
53
55
|
export declare function runClaudeCode(opts: RunOptions, cb?: RunCallbacks): Promise<RunResult>;
|
|
54
56
|
export {};
|
|
55
57
|
//# sourceMappingURL=claude_code_runner.d.ts.map
|