@hyperwindmill/caretaker-cli 0.23.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_extract.d.ts +55 -0
- package/dist/cli/web/scheduler/memory_extract.d.ts.map +1 -0
- package/dist/cli/web/scheduler/memory_extract.js +112 -0
- package/dist/cli/web/scheduler/memory_sweep.d.ts +68 -0
- package/dist/cli/web/scheduler/memory_sweep.d.ts.map +1 -0
- package/dist/cli/web/scheduler/memory_sweep.js +330 -0
- package/dist/cli/web/scheduler/task_review.d.ts +3 -0
- package/dist/cli/web/scheduler/task_review.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_review.js +26 -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 +27 -2
- package/dist/cli/web/scheduler.d.ts.map +1 -1
- package/dist/cli/web/scheduler.js +5 -0
- 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 +33 -6
- 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 +6 -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 +12 -0
- package/dist/harness/loop.d.ts.map +1 -1
- package/dist/harness/loop.js +16 -0
- package/dist/harness/memory_recall.d.ts +28 -0
- package/dist/harness/memory_recall.d.ts.map +1 -0
- package/dist/harness/memory_recall.js +74 -0
- package/dist/harness/title.js +1 -1
- 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 +4 -1
- package/dist/harness/tools/builtin/memory_tools.d.ts +3 -0
- package/dist/harness/tools/builtin/memory_tools.d.ts.map +1 -0
- package/dist/harness/tools/builtin/memory_tools.js +60 -0
- package/dist/harness/tools/resolve.d.ts.map +1 -1
- package/dist/harness/tools/resolve.js +15 -0
- package/dist/harness/tools/types.d.ts +6 -0
- package/dist/harness/tools/types.d.ts.map +1 -1
- package/dist/lib/project_resolve.d.ts +5 -0
- package/dist/lib/project_resolve.d.ts.map +1 -0
- package/dist/lib/project_resolve.js +23 -0
- package/dist/mcp/builtin_server.d.ts +2 -0
- package/dist/mcp/builtin_server.d.ts.map +1 -1
- package/dist/mcp/builtin_server.js +9 -7
- 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/store/db.d.ts +66 -0
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +68 -0
- package/dist/tui/agents.d.ts.map +1 -1
- package/dist/tui/agents.js +62 -25
- 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 +792 -440
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +8 -3
package/dist/cli/web/server.js
CHANGED
|
@@ -25,6 +25,7 @@ import { fsRouter } from './fs.js';
|
|
|
25
25
|
import { activationStatus, resolvePlanningEnabled } from './scheduler/task_roles.js';
|
|
26
26
|
import { registerVoiceProxy, voiceClientConfig, fetchVoiceCatalog } from './voice_proxy.js';
|
|
27
27
|
import { registerVoiceBackend, maybeAutoStartBackend } from './voice_backend.js';
|
|
28
|
+
import { fetchAcpRegistry, installAcpAgent } from '../../acp/index.js';
|
|
28
29
|
// Resolve Webview static files path.
|
|
29
30
|
// Published npm package ships the assets under dist/webview (see scripts/copy-webview.mjs);
|
|
30
31
|
// in the monorepo dev tree they live in the sibling webview-ui package.
|
|
@@ -37,11 +38,11 @@ export class WebSessionController {
|
|
|
37
38
|
metaRecord = null;
|
|
38
39
|
history = [];
|
|
39
40
|
inflight = null;
|
|
40
|
-
|
|
41
|
+
confirmGate;
|
|
41
42
|
sessionId;
|
|
42
43
|
constructor(opts) {
|
|
43
44
|
this.opts = opts;
|
|
44
|
-
this.
|
|
45
|
+
this.confirmGate = new harness.ConfirmGateState(opts.provider.type, opts.agent.confirmTools);
|
|
45
46
|
this.sessionId = opts.sessionId;
|
|
46
47
|
}
|
|
47
48
|
get isRunning() {
|
|
@@ -105,11 +106,10 @@ export class WebSessionController {
|
|
|
105
106
|
onToolCall: cb.onToolCall,
|
|
106
107
|
onToolResult: cb.onToolResult,
|
|
107
108
|
confirmTool: async (id, name, args) => {
|
|
108
|
-
if (!this.
|
|
109
|
+
if (!this.confirmGate.needsAsk(name))
|
|
109
110
|
return 'once';
|
|
110
111
|
const decision = await cb.askConfirm(id, name, args);
|
|
111
|
-
|
|
112
|
-
this.confirmSet.delete(name);
|
|
112
|
+
this.confirmGate.remember(name, decision);
|
|
113
113
|
return decision;
|
|
114
114
|
},
|
|
115
115
|
onMessage: async (msg) => {
|
|
@@ -864,7 +864,12 @@ export async function startServer(port, host) {
|
|
|
864
864
|
// Collapse every builtin `mcp__<ns>__` namespace (task, email, …) into a
|
|
865
865
|
// single wildcard entry: the picker offers the namespace, so a namespace
|
|
866
866
|
// gaining a tool needs no config change. resolveAgentTools expands it.
|
|
867
|
-
|
|
867
|
+
// Hidden tools (memory_read) are harness infrastructure, auto-included
|
|
868
|
+
// by resolveAgentTools behind their own gate — never a picker choice.
|
|
869
|
+
const toolNames = harness.tools
|
|
870
|
+
.list()
|
|
871
|
+
.filter((t) => !t.hidden)
|
|
872
|
+
.map((t) => t.name);
|
|
868
873
|
const namespaces = [
|
|
869
874
|
...new Set(toolNames.map((name) => /^mcp__[a-z]+__/.exec(name)?.[0]).filter((p) => !!p)),
|
|
870
875
|
];
|
|
@@ -1204,6 +1209,28 @@ export async function startServer(port, host) {
|
|
|
1204
1209
|
});
|
|
1205
1210
|
}
|
|
1206
1211
|
return;
|
|
1212
|
+
case 'fetchAcpRegistry':
|
|
1213
|
+
try {
|
|
1214
|
+
const agents = await fetchAcpRegistry();
|
|
1215
|
+
post({ type: 'acpRegistryFetched', result: { ok: true, agents } });
|
|
1216
|
+
}
|
|
1217
|
+
catch (err) {
|
|
1218
|
+
post({ type: 'acpRegistryFetched', result: { ok: false, error: String(err) } });
|
|
1219
|
+
}
|
|
1220
|
+
return;
|
|
1221
|
+
case 'installAcpAgent':
|
|
1222
|
+
try {
|
|
1223
|
+
const agents = await fetchAcpRegistry();
|
|
1224
|
+
const preset = agents.find((a) => a.id === msg.agentId);
|
|
1225
|
+
if (!preset)
|
|
1226
|
+
throw new Error(`unknown ACP agent "${msg.agentId}"`);
|
|
1227
|
+
const installed = await installAcpAgent(preset, (line) => post({ type: 'acpInstallProgress', agentId: msg.agentId, line }));
|
|
1228
|
+
post({ type: 'acpInstallResult', agentId: msg.agentId, ok: true, ...installed });
|
|
1229
|
+
}
|
|
1230
|
+
catch (err) {
|
|
1231
|
+
post({ type: 'acpInstallResult', agentId: msg.agentId, ok: false, error: String(err) });
|
|
1232
|
+
}
|
|
1233
|
+
return;
|
|
1207
1234
|
case 'fetchVoiceModels':
|
|
1208
1235
|
try {
|
|
1209
1236
|
const catalog = await fetchVoiceCatalog(msg.endpoint, msg.apiKey ?? null);
|
|
@@ -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"}
|