@agentclientprotocol/claude-agent-acp 0.99.2-preview.11 → 0.99.2-preview.13
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-agent.d.ts +48 -1
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +107 -30
- package/dist/background-work.d.ts +188 -0
- package/dist/background-work.d.ts.map +1 -0
- package/dist/background-work.js +384 -0
- package/dist/native-subagents.d.ts +7 -0
- package/dist/native-subagents.d.ts.map +1 -1
- package/dist/native-subagents.js +25 -0
- package/dist/tool-calls/background.d.ts +10 -0
- package/dist/tool-calls/background.d.ts.map +1 -1
- package/dist/tool-calls/background.js +18 -0
- package/dist/tool-calls/renderer.d.ts +8 -0
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +6 -5
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +38 -16
- package/dist/v2/background.d.ts +72 -0
- package/dist/v2/background.d.ts.map +1 -0
- package/dist/v2/background.js +166 -0
- package/dist/v2/terminal.d.ts +8 -0
- package/dist/v2/terminal.d.ts.map +1 -1
- package/dist/v2/terminal.js +22 -0
- package/package.json +1 -1
package/dist/native-subagents.js
CHANGED
|
@@ -123,6 +123,31 @@ export class NativeSubagentRuntime {
|
|
|
123
123
|
const child = this.children.get(sessionId);
|
|
124
124
|
return child?.announced ? child.workState : undefined;
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* The RFD form: the `subagent_update` that tells a client that holds nothing
|
|
128
|
+
* of the announced child `sessionId` of this live session what it is now:
|
|
129
|
+
* its labels, its directory, its `cancel` capability, and its work state.
|
|
130
|
+
* Undefined when no such child runs here.
|
|
131
|
+
*/
|
|
132
|
+
currentUpdate(sessionId) {
|
|
133
|
+
if (this.form !== "rfd")
|
|
134
|
+
return undefined;
|
|
135
|
+
const child = this.childOfSession(sessionId);
|
|
136
|
+
if (!child?.announced || !child.workState)
|
|
137
|
+
return undefined;
|
|
138
|
+
return {
|
|
139
|
+
sessionId: child.parentSessionId,
|
|
140
|
+
update: {
|
|
141
|
+
sessionUpdate: "subagent_update",
|
|
142
|
+
sessionId: child.sessionId,
|
|
143
|
+
...(child.title ? { title: child.title } : {}),
|
|
144
|
+
...(child.description ? { description: child.description } : {}),
|
|
145
|
+
...(child.reportedCwd ? { cwd: child.reportedCwd } : {}),
|
|
146
|
+
capabilities: { cancel: {} },
|
|
147
|
+
state: { state: child.workState },
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
126
151
|
/**
|
|
127
152
|
* Reports the model of a child response, an exact model id, as the entry of
|
|
128
153
|
* the root session's `model` option that matches it, else as the id (see
|
|
@@ -29,4 +29,14 @@ export declare function backgroundedBashToolCall(notification: SessionNotificati
|
|
|
29
29
|
* the exit when the command's task ends (see `Session.backgroundTerminals`).
|
|
30
30
|
*/
|
|
31
31
|
export declare function withRunningTerminal(notification: SessionNotification, toolCallId: string | undefined): SessionNotification;
|
|
32
|
+
/**
|
|
33
|
+
* Keeps the tool call of a task that went on in the background running: the
|
|
34
|
+
* tool result update of a tool call in `toolCallIds` reports `in_progress`
|
|
35
|
+
* instead of `completed`.
|
|
36
|
+
*
|
|
37
|
+
* A Monitor or Workflow call returns as soon as its task starts. The consumer
|
|
38
|
+
* reports the task's end, or its pause, on the tool call (see
|
|
39
|
+
* `Session.backgroundToolCalls`).
|
|
40
|
+
*/
|
|
41
|
+
export declare function withRunningToolCall(notification: SessionNotification, toolCallIds: ReadonlySet<string>): SessionNotification;
|
|
32
42
|
//# sourceMappingURL=background.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../src/tool-calls/background.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAG7E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,mBAAmB,EACjC,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAAC,EAC5C,mBAAmB,EAAE,OAAO,GAC3B,mBAAmB,CAgBrB;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,mBAAmB,EACjC,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,mBAAmB,CAiBrB"}
|
|
1
|
+
{"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../src/tool-calls/background.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAG7E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,mBAAmB,EACjC,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAAC,EAC5C,mBAAmB,EAAE,OAAO,GAC3B,mBAAmB,CAgBrB;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,mBAAmB,EACjC,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,mBAAmB,CAiBrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,mBAAmB,EACjC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B,mBAAmB,CAUrB"}
|
|
@@ -59,3 +59,21 @@ export function withRunningTerminal(notification, toolCallId) {
|
|
|
59
59
|
delete next._meta;
|
|
60
60
|
return { ...notification, update: next };
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Keeps the tool call of a task that went on in the background running: the
|
|
64
|
+
* tool result update of a tool call in `toolCallIds` reports `in_progress`
|
|
65
|
+
* instead of `completed`.
|
|
66
|
+
*
|
|
67
|
+
* A Monitor or Workflow call returns as soon as its task starts. The consumer
|
|
68
|
+
* reports the task's end, or its pause, on the tool call (see
|
|
69
|
+
* `Session.backgroundToolCalls`).
|
|
70
|
+
*/
|
|
71
|
+
export function withRunningToolCall(notification, toolCallIds) {
|
|
72
|
+
const update = notification.update;
|
|
73
|
+
if (update.sessionUpdate !== "tool_call_update" ||
|
|
74
|
+
!toolCallIds.has(update.toolCallId) ||
|
|
75
|
+
update.status !== "completed") {
|
|
76
|
+
return notification;
|
|
77
|
+
}
|
|
78
|
+
return { ...notification, update: { ...update, status: "in_progress" } };
|
|
79
|
+
}
|
|
@@ -3,6 +3,14 @@ import { type ToolResultMeta } from "../tool-result-meta.js";
|
|
|
3
3
|
import { ClientCapabilities } from "./client-capabilities.js";
|
|
4
4
|
import type { ToolResultContext, ToolResultFacts, ToolUse, ToolUseFacts } from "./facts.js";
|
|
5
5
|
export type ToolCallUpdate = SessionNotification["update"];
|
|
6
|
+
/**
|
|
7
|
+
* ACP v2's `cancelled` and `paused` tool call statuses. v1's statuses have no
|
|
8
|
+
* such values, and the agent builds its reports in v1 types, so they travel as
|
|
9
|
+
* v1 statuses. Only a v2 client gets them, and the v2 surface sends them as
|
|
10
|
+
* they are (`src/v2/tool-call.ts`).
|
|
11
|
+
*/
|
|
12
|
+
export declare const V2_CANCELLED: ToolCallStatus;
|
|
13
|
+
export declare const V2_PAUSED: ToolCallStatus;
|
|
6
14
|
/** Whether `status` ends a tool call: `completed`, `failed`, or, on v2, `cancelled`. */
|
|
7
15
|
export declare function isFinalToolCallStatus(status: ToolCallStatus | null | undefined): boolean;
|
|
8
16
|
/** The `_meta` of a tool call report. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/tool-calls/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,IAAI,qBAAqB,EAC3C,wBAAwB,EACxB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACf,MAAM,mCAAmC,CAAC;AAS3C,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B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CAAC,EAAE,OAAO,CAAC;KACzB,GAAG,cAAc;IAsBlB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO;IAgBzD;;;;OAIG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,eAAe,EAAE;IAS1E;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,cAAc;CA2BtF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAStF"}
|
|
@@ -10,12 +10,13 @@ import { grepPath } from "./reporters/search.js";
|
|
|
10
10
|
/** The id suffix of the call that clears the plan file of an approved plan for AIR. */
|
|
11
11
|
const PLAN_FILE_CLEAR_SUFFIX = ":plan-file-clear";
|
|
12
12
|
/**
|
|
13
|
-
* ACP v2's `cancelled` tool call
|
|
14
|
-
* the agent builds its reports in v1 types, so
|
|
15
|
-
* a v2 client gets
|
|
16
|
-
* (`src/v2/tool-call.ts`).
|
|
13
|
+
* ACP v2's `cancelled` and `paused` tool call statuses. v1's statuses have no
|
|
14
|
+
* such values, and the agent builds its reports in v1 types, so they travel as
|
|
15
|
+
* v1 statuses. Only a v2 client gets them, and the v2 surface sends them as
|
|
16
|
+
* they are (`src/v2/tool-call.ts`).
|
|
17
17
|
*/
|
|
18
|
-
const V2_CANCELLED = "cancelled";
|
|
18
|
+
export const V2_CANCELLED = "cancelled";
|
|
19
|
+
export const V2_PAUSED = "paused";
|
|
19
20
|
/** Whether `status` ends a tool call: `completed`, `failed`, or, on v2, `cancelled`. */
|
|
20
21
|
export function isFinalToolCallStatus(status) {
|
|
21
22
|
return status === "completed" || status === "failed" || status === V2_CANCELLED;
|
package/dist/v2/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/v2/agent.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AACxE,OAAO,EAAE,cAAc,EAAkB,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/v2/agent.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AACxE,OAAO,EAAE,cAAc,EAAkB,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAsB9E;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GACvC,EAAE,CAAC,QAAQ,CAyIb"}
|
package/dist/v2/agent.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
2
2
|
import { ClaudeAcpAgent } from "../acp-agent.js";
|
|
3
|
+
import { stateUpdate, V2Background } from "./background.js";
|
|
3
4
|
import { v1InitializeRequest, v2InitializeResponse } from "./initialize.js";
|
|
4
5
|
import { v1PermissionResponse, v2PermissionRequest } from "./permission.js";
|
|
5
6
|
import { v2Foreground, v2Prompt } from "./prompt.js";
|
|
@@ -29,6 +30,14 @@ export function v2AgentApp(logger, onAgent) {
|
|
|
29
30
|
foreground: (sessionId) => v2Foreground((update) => {
|
|
30
31
|
void client.send({ sessionId, update });
|
|
31
32
|
}),
|
|
33
|
+
background: {
|
|
34
|
+
changed: (report) => {
|
|
35
|
+
for (const notification of client.background.changed(report)) {
|
|
36
|
+
void client.send(notification);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
forget: (sessionId) => client.background.forget(sessionId),
|
|
40
|
+
},
|
|
32
41
|
});
|
|
33
42
|
onAgent(agent);
|
|
34
43
|
})
|
|
@@ -57,10 +66,17 @@ export function v2AgentApp(logger, onAgent) {
|
|
|
57
66
|
await agent.publishCurrentSessionInfo(params.sessionId);
|
|
58
67
|
// v2 requires a snapshot of the foreground state after the replay and
|
|
59
68
|
// before the response, also without a replay: a resumed live session can
|
|
60
|
-
// be running a turn, or waiting on a permission request.
|
|
69
|
+
// be running a turn, or waiting on a permission request. The current
|
|
70
|
+
// state of each subagent, terminal and tool call it lists comes first,
|
|
71
|
+
// as v2 requires. The subagents' go again after the response (see below).
|
|
72
|
+
await agent.publishLiveSubagents(params.sessionId, client.background.listedSubagents(params.sessionId));
|
|
73
|
+
await agent.publishBackgroundToolCalls(params.sessionId, client.background.listedToolCalls(params.sessionId));
|
|
74
|
+
for (const notification of client.background.currentItems(params.sessionId)) {
|
|
75
|
+
void client.send(notification);
|
|
76
|
+
}
|
|
61
77
|
void client.send({
|
|
62
78
|
sessionId: params.sessionId,
|
|
63
|
-
update:
|
|
79
|
+
update: stateUpdate(agent.foregroundState(params.sessionId)),
|
|
64
80
|
});
|
|
65
81
|
const commands = await setupCommands(agent, params.sessionId, logger);
|
|
66
82
|
// The response ends a replay. The subagents RFD treats the replayed
|
|
@@ -103,16 +119,16 @@ export function v2AgentApp(logger, onAgent) {
|
|
|
103
119
|
.onRequest(v2.methods.agent.session.prompt, ({ params }) => v2Prompt(agent, params, (update) => {
|
|
104
120
|
void client.send({ sessionId: params.sessionId, update });
|
|
105
121
|
}))
|
|
122
|
+
.onRequest(v2.methods.agent.terminal.cancel, async ({ params }) => {
|
|
123
|
+
await agent.cancelBackgroundTerminal(params);
|
|
124
|
+
return {};
|
|
125
|
+
})
|
|
126
|
+
.onRequest(v2.methods.agent.toolCall.cancel, async ({ params }) => {
|
|
127
|
+
await agent.cancelBackgroundToolCall(params);
|
|
128
|
+
return {};
|
|
129
|
+
})
|
|
106
130
|
.onNotification(v2.methods.agent.session.cancel, ({ params }) => agent.cancel(params));
|
|
107
131
|
}
|
|
108
|
-
/** The `state_update` that reports `state` as the current foreground state. */
|
|
109
|
-
function stateSnapshot(state) {
|
|
110
|
-
if (state === "idle")
|
|
111
|
-
return { sessionUpdate: "state_update", state: "idle" };
|
|
112
|
-
if (state === "running")
|
|
113
|
-
return { sessionUpdate: "state_update", state: "running" };
|
|
114
|
-
return { sessionUpdate: "state_update", state: "requires_action" };
|
|
115
|
-
}
|
|
116
132
|
/**
|
|
117
133
|
* The `availableCommands` of a setup response, which v2 requires when the
|
|
118
134
|
* session has commands. The agent sends a v1 client the same list as an
|
|
@@ -179,6 +195,8 @@ class V2ClientConnection {
|
|
|
179
195
|
terminals = new V2Terminals();
|
|
180
196
|
/** The `_meta` that the client stores for each tool call. */
|
|
181
197
|
toolCallMeta = new V2ToolCallMeta();
|
|
198
|
+
/** The `background` list of each session's `state_update`s. */
|
|
199
|
+
background = new V2Background(this.terminals);
|
|
182
200
|
constructor(ctx, logger) {
|
|
183
201
|
this.ctx = ctx;
|
|
184
202
|
this.logger = logger;
|
|
@@ -225,7 +243,9 @@ class V2ClientConnection {
|
|
|
225
243
|
* request opening.)
|
|
226
244
|
*/
|
|
227
245
|
send(notification) {
|
|
228
|
-
return this.ctx
|
|
246
|
+
return this.ctx
|
|
247
|
+
.notify(v2.methods.client.session.update, this.background.stamp(notification))
|
|
248
|
+
.catch((error) => {
|
|
229
249
|
this.logger.error(`Failed to send a ${notification.update.sessionUpdate} update:`, error);
|
|
230
250
|
});
|
|
231
251
|
}
|
|
@@ -257,11 +277,13 @@ class V2ClientConnection {
|
|
|
257
277
|
childState = undefined;
|
|
258
278
|
}
|
|
259
279
|
// Every update goes to the connection before any is awaited, so an update
|
|
260
|
-
// that another call sends meanwhile cannot come between them.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
...(
|
|
264
|
-
|
|
280
|
+
// that another call sends meanwhile cannot come between them. The parent's
|
|
281
|
+
// copy is stamped first: a child's announcement starts its list.
|
|
282
|
+
const stamped = [
|
|
283
|
+
...updates.map((v2Update) => this.background.stamp({ ...notification, update: v2Update })),
|
|
284
|
+
...(childState ? [this.background.stamp(childState)] : []),
|
|
285
|
+
];
|
|
286
|
+
await Promise.all(stamped.map((v2Notification) => this.ctx.notify(v2.methods.client.session.update, v2Notification)));
|
|
265
287
|
}
|
|
266
288
|
/**
|
|
267
289
|
* The v2 updates of a v1 update: for a tool call report, the updates of its
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `background` lists of the v2 sessions of a connection (see
|
|
3
|
+
* `background-work.ts`, which builds them).
|
|
4
|
+
*
|
|
5
|
+
* A session that reports its background work gets its list on every
|
|
6
|
+
* `state_update` of its own stream, as v2 requires, from the list the agent
|
|
7
|
+
* reports when the session starts. A subagent session of such a session
|
|
8
|
+
* reports its own list from its announcement on, also in the parent's mirror
|
|
9
|
+
* of its state (`subagent_update.state`).
|
|
10
|
+
*/
|
|
11
|
+
import type * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
12
|
+
import type { BackgroundReport, WorkStateName } from "../background-work.js";
|
|
13
|
+
import type { V2Terminals } from "./terminal.js";
|
|
14
|
+
/** The `state_update` that reports `state` as the session's current work state. */
|
|
15
|
+
export declare function stateUpdate(state: WorkStateName): v2.SessionUpdate;
|
|
16
|
+
export declare class V2Background {
|
|
17
|
+
private readonly terminals;
|
|
18
|
+
/**
|
|
19
|
+
* The latest list of each session that reports one, whether a state of the
|
|
20
|
+
* session carried it, and the parent of a subagent session.
|
|
21
|
+
*/
|
|
22
|
+
private readonly sessions;
|
|
23
|
+
/**
|
|
24
|
+
* The tool calls that advertise `cancel`, by session and tool call. Like a
|
|
25
|
+
* terminal's (see `V2Terminals.advertiseCancel`), the capability goes with
|
|
26
|
+
* the final status.
|
|
27
|
+
*/
|
|
28
|
+
private readonly cancellableToolCalls;
|
|
29
|
+
constructor(terminals: V2Terminals);
|
|
30
|
+
/**
|
|
31
|
+
* `notification` with the session's list, when it is a `state_update` of a
|
|
32
|
+
* session that reports one, or a `subagent_update` that mirrors the state of
|
|
33
|
+
* such a child. A child of a session that reports its list reports its own
|
|
34
|
+
* from its announcement on: empty, until the agent reports it.
|
|
35
|
+
*/
|
|
36
|
+
stamp(notification: v2.UpdateSessionNotification): v2.UpdateSessionNotification;
|
|
37
|
+
/**
|
|
38
|
+
* Records the new list of a session, and returns the updates that report it:
|
|
39
|
+
*
|
|
40
|
+
* - For each terminal or tool call that the list adds, a `terminal_update`
|
|
41
|
+
* or `tool_call_update` that lets the client cancel it. It comes before
|
|
42
|
+
* the first list that names it, as v2 requires of an announcement: its
|
|
43
|
+
* own updates came earlier.
|
|
44
|
+
* - Once a state of the session carried a list, the state again with the
|
|
45
|
+
* new list, without a stop reason: a repeated `idle` is no new
|
|
46
|
+
* completion. A subagent's goes to its parent's mirror first, as its
|
|
47
|
+
* other states do.
|
|
48
|
+
*/
|
|
49
|
+
changed(report: BackgroundReport): v2.UpdateSessionNotification[];
|
|
50
|
+
/**
|
|
51
|
+
* The current `terminal_update` of each terminal that the session
|
|
52
|
+
* `sessionId` lists, and the `cancel` capability of each tool call that it
|
|
53
|
+
* lists, whose other fields the agent sends (see
|
|
54
|
+
* `ClaudeAcpAgent.publishBackgroundToolCalls`). v2 requires them before the
|
|
55
|
+
* state snapshot of `session/resume`, as a replay may not have delivered
|
|
56
|
+
* them.
|
|
57
|
+
*/
|
|
58
|
+
currentItems(sessionId: string): v2.UpdateSessionNotification[];
|
|
59
|
+
/** The tool calls that the session `sessionId` lists. */
|
|
60
|
+
listedToolCalls(sessionId: string): string[];
|
|
61
|
+
/**
|
|
62
|
+
* The update that lets the client cancel the listed terminal or tool call
|
|
63
|
+
* `item`, unless it advertises that already. `again` sends it anyway, as
|
|
64
|
+
* the item's current state.
|
|
65
|
+
*/
|
|
66
|
+
private advertiseCancel;
|
|
67
|
+
/** The subagent sessions that the session `sessionId` lists. */
|
|
68
|
+
listedSubagents(sessionId: string): string[];
|
|
69
|
+
/** Forgets the list of a session, and those of its subagent sessions. */
|
|
70
|
+
forget(sessionId: string): void;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=background.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../src/v2/background.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,EAAkB,gBAAgB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAUjD,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,EAAE,CAAC,aAAa,CAElE;AAUD,qBAAa,YAAY;IAiBX,OAAO,CAAC,QAAQ,CAAC,SAAS;IAhBtC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAGrB;IAEJ;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAqB;gBAE7B,SAAS,EAAE,WAAW;IAEnD;;;;;OAKG;IACH,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC,yBAAyB,GAAG,EAAE,CAAC,yBAAyB;IAiC/E;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,EAAE,gBAAgB,GAAG,EAAE,CAAC,yBAAyB,EAAE;IAyBjE;;;;;;;OAOG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC,yBAAyB,EAAE;IAM/D,yDAAyD;IACzD,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAM5C;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAyBvB,gEAAgE;IAChE,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAM5C,yEAAyE;IACzE,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAShC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/** `state` as the current work state of a session, with no stop reason. */
|
|
2
|
+
function currentState(state) {
|
|
3
|
+
if (state === "idle")
|
|
4
|
+
return { state: "idle" };
|
|
5
|
+
if (state === "running")
|
|
6
|
+
return { state: "running" };
|
|
7
|
+
if (state === "requires_action")
|
|
8
|
+
return { state: "requires_action" };
|
|
9
|
+
return { state: "unknown" };
|
|
10
|
+
}
|
|
11
|
+
/** The `state_update` that reports `state` as the session's current work state. */
|
|
12
|
+
export function stateUpdate(state) {
|
|
13
|
+
return { sessionUpdate: "state_update", ...currentState(state) };
|
|
14
|
+
}
|
|
15
|
+
/** `state` with the list `background`. */
|
|
16
|
+
function withBackground(state, background) {
|
|
17
|
+
return { ...state, background };
|
|
18
|
+
}
|
|
19
|
+
/** The final tool call statuses. */
|
|
20
|
+
const FINAL_STATUSES = new Set(["completed", "failed", "cancelled"]);
|
|
21
|
+
export class V2Background {
|
|
22
|
+
terminals;
|
|
23
|
+
/**
|
|
24
|
+
* The latest list of each session that reports one, whether a state of the
|
|
25
|
+
* session carried it, and the parent of a subagent session.
|
|
26
|
+
*/
|
|
27
|
+
sessions = new Map();
|
|
28
|
+
/**
|
|
29
|
+
* The tool calls that advertise `cancel`, by session and tool call. Like a
|
|
30
|
+
* terminal's (see `V2Terminals.advertiseCancel`), the capability goes with
|
|
31
|
+
* the final status.
|
|
32
|
+
*/
|
|
33
|
+
cancellableToolCalls = new Set();
|
|
34
|
+
constructor(terminals) {
|
|
35
|
+
this.terminals = terminals;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* `notification` with the session's list, when it is a `state_update` of a
|
|
39
|
+
* session that reports one, or a `subagent_update` that mirrors the state of
|
|
40
|
+
* such a child. A child of a session that reports its list reports its own
|
|
41
|
+
* from its announcement on: empty, until the agent reports it.
|
|
42
|
+
*/
|
|
43
|
+
stamp(notification) {
|
|
44
|
+
const { sessionId, update } = notification;
|
|
45
|
+
if (update.sessionUpdate === "tool_call_update" &&
|
|
46
|
+
FINAL_STATUSES.has(String(update.status)) &&
|
|
47
|
+
this.cancellableToolCalls.delete(`${sessionId} ${update.toolCallId}`)) {
|
|
48
|
+
// A tool call that reached its final status can no longer be cancelled.
|
|
49
|
+
return { ...notification, update: { ...update, capabilities: null } };
|
|
50
|
+
}
|
|
51
|
+
if (update.sessionUpdate === "state_update") {
|
|
52
|
+
const session = this.sessions.get(sessionId);
|
|
53
|
+
if (!session)
|
|
54
|
+
return notification;
|
|
55
|
+
session.reported = true;
|
|
56
|
+
return { ...notification, update: { ...update, background: session.items } };
|
|
57
|
+
}
|
|
58
|
+
if (update.sessionUpdate === "subagent_update" && this.sessions.has(sessionId)) {
|
|
59
|
+
const subagent = update;
|
|
60
|
+
let child = this.sessions.get(subagent.sessionId);
|
|
61
|
+
if (!child) {
|
|
62
|
+
child = { items: [], reported: false, parent: sessionId };
|
|
63
|
+
this.sessions.set(subagent.sessionId, child);
|
|
64
|
+
}
|
|
65
|
+
if (subagent.state) {
|
|
66
|
+
return {
|
|
67
|
+
...notification,
|
|
68
|
+
update: { ...subagent, state: withBackground(subagent.state, child.items) },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return notification;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Records the new list of a session, and returns the updates that report it:
|
|
76
|
+
*
|
|
77
|
+
* - For each terminal or tool call that the list adds, a `terminal_update`
|
|
78
|
+
* or `tool_call_update` that lets the client cancel it. It comes before
|
|
79
|
+
* the first list that names it, as v2 requires of an announcement: its
|
|
80
|
+
* own updates came earlier.
|
|
81
|
+
* - Once a state of the session carried a list, the state again with the
|
|
82
|
+
* new list, without a stop reason: a repeated `idle` is no new
|
|
83
|
+
* completion. A subagent's goes to its parent's mirror first, as its
|
|
84
|
+
* other states do.
|
|
85
|
+
*/
|
|
86
|
+
changed(report) {
|
|
87
|
+
const { sessionId, items, state, parentSessionId } = report;
|
|
88
|
+
const session = this.sessions.get(sessionId);
|
|
89
|
+
const unchanged = session && JSON.stringify(session.items) === JSON.stringify(items);
|
|
90
|
+
this.sessions.set(sessionId, {
|
|
91
|
+
items,
|
|
92
|
+
reported: session?.reported ?? false,
|
|
93
|
+
parent: parentSessionId ?? session?.parent,
|
|
94
|
+
});
|
|
95
|
+
const known = new Set((session?.items ?? []).map((item) => JSON.stringify(item)));
|
|
96
|
+
const updates = items.flatMap((item) => known.has(JSON.stringify(item)) ? [] : this.advertiseCancel(sessionId, item, false));
|
|
97
|
+
if (session?.reported && state && !unchanged) {
|
|
98
|
+
if (parentSessionId) {
|
|
99
|
+
updates.push({
|
|
100
|
+
sessionId: parentSessionId,
|
|
101
|
+
update: { sessionUpdate: "subagent_update", sessionId, state: currentState(state) },
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
updates.push({ sessionId, update: stateUpdate(state) });
|
|
105
|
+
}
|
|
106
|
+
return updates;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The current `terminal_update` of each terminal that the session
|
|
110
|
+
* `sessionId` lists, and the `cancel` capability of each tool call that it
|
|
111
|
+
* lists, whose other fields the agent sends (see
|
|
112
|
+
* `ClaudeAcpAgent.publishBackgroundToolCalls`). v2 requires them before the
|
|
113
|
+
* state snapshot of `session/resume`, as a replay may not have delivered
|
|
114
|
+
* them.
|
|
115
|
+
*/
|
|
116
|
+
currentItems(sessionId) {
|
|
117
|
+
return (this.sessions.get(sessionId)?.items ?? []).flatMap((item) => this.advertiseCancel(sessionId, item, true));
|
|
118
|
+
}
|
|
119
|
+
/** The tool calls that the session `sessionId` lists. */
|
|
120
|
+
listedToolCalls(sessionId) {
|
|
121
|
+
return (this.sessions.get(sessionId)?.items ?? []).flatMap((item) => item.type === "tool_call" ? [item.toolCallId] : []);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The update that lets the client cancel the listed terminal or tool call
|
|
125
|
+
* `item`, unless it advertises that already. `again` sends it anyway, as
|
|
126
|
+
* the item's current state.
|
|
127
|
+
*/
|
|
128
|
+
advertiseCancel(sessionId, item, again) {
|
|
129
|
+
if (item.type === "terminal") {
|
|
130
|
+
const update = this.terminals.advertiseCancel(sessionId, item.terminalId, again);
|
|
131
|
+
return update ? [{ sessionId, update }] : [];
|
|
132
|
+
}
|
|
133
|
+
if (item.type !== "tool_call")
|
|
134
|
+
return [];
|
|
135
|
+
const key = `${sessionId} ${item.toolCallId}`;
|
|
136
|
+
if (this.cancellableToolCalls.has(key) && !again)
|
|
137
|
+
return [];
|
|
138
|
+
this.cancellableToolCalls.add(key);
|
|
139
|
+
return [
|
|
140
|
+
{
|
|
141
|
+
sessionId,
|
|
142
|
+
update: {
|
|
143
|
+
sessionUpdate: "tool_call_update",
|
|
144
|
+
toolCallId: item.toolCallId,
|
|
145
|
+
capabilities: { cancel: {} },
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
/** The subagent sessions that the session `sessionId` lists. */
|
|
151
|
+
listedSubagents(sessionId) {
|
|
152
|
+
return (this.sessions.get(sessionId)?.items ?? []).flatMap((item) => item.type === "subagent" ? [item.sessionId] : []);
|
|
153
|
+
}
|
|
154
|
+
/** Forgets the list of a session, and those of its subagent sessions. */
|
|
155
|
+
forget(sessionId) {
|
|
156
|
+
this.sessions.delete(sessionId);
|
|
157
|
+
for (const key of this.cancellableToolCalls) {
|
|
158
|
+
if (key.startsWith(`${sessionId} `))
|
|
159
|
+
this.cancellableToolCalls.delete(key);
|
|
160
|
+
}
|
|
161
|
+
for (const [child, { parent }] of this.sessions) {
|
|
162
|
+
if (parent === sessionId)
|
|
163
|
+
this.forget(child);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
package/dist/v2/terminal.d.ts
CHANGED
|
@@ -35,6 +35,14 @@ export declare class V2Terminals {
|
|
|
35
35
|
terminal: v2.SessionUpdate[];
|
|
36
36
|
report: V1ToolCallReport | undefined;
|
|
37
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* The `terminal_update` that lets the client cancel the running terminal
|
|
40
|
+
* `terminalId` of the session `sessionId` with `terminal/cancel`, with its
|
|
41
|
+
* command, or undefined when the terminal is not running. `again` sends it
|
|
42
|
+
* also when the terminal advertises the capability already, as the current
|
|
43
|
+
* state of the terminal.
|
|
44
|
+
*/
|
|
45
|
+
advertiseCancel(sessionId: string, terminalId: string, again?: boolean): v2.SessionUpdate | undefined;
|
|
38
46
|
/** Forgets the terminals of a session. */
|
|
39
47
|
forget(sessionId: string): void;
|
|
40
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../src/v2/terminal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAE7E,KAAK,gBAAgB,GACjB,CAAC,QAAQ,GAAG;IAAE,aAAa,EAAE,WAAW,CAAA;CAAE,CAAC,GAC3C,CAAC,cAAc,GAAG;IAAE,aAAa,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAAC;AAiB7D,0EAA0E;AAC1E,qBAAa,WAAW;IACtB,oGAAoG;IACpG,OAAO,CAAC,QAAQ,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../src/v2/terminal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAE7E,KAAK,gBAAgB,GACjB,CAAC,QAAQ,GAAG;IAAE,aAAa,EAAE,WAAW,CAAA;CAAE,CAAC,GAC3C,CAAC,cAAc,GAAG;IAAE,aAAa,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAAC;AAiB7D,0EAA0E;AAC1E,qBAAa,WAAW;IACtB,oGAAoG;IACpG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAGpB;IAEJ;;;;;;;;OAQG;IACH,KAAK,CACH,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,gBAAgB,GACvB;QAAE,QAAQ,EAAE,EAAE,CAAC,aAAa,EAAE,CAAC;QAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAA;KAAE;IAyCzE;;;;;;OAMG;IACH,eAAe,CACb,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,UAAQ,GACZ,EAAE,CAAC,aAAa,GAAG,SAAS;IAa/B,0CAA0C;IAC1C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAKhC"}
|
package/dist/v2/terminal.js
CHANGED
|
@@ -42,6 +42,8 @@ export class V2Terminals {
|
|
|
42
42
|
...(exit.exit_code != null ? { exitCode: exit.exit_code } : {}),
|
|
43
43
|
...(exit.signal != null ? { signal: exit.signal } : {}),
|
|
44
44
|
},
|
|
45
|
+
// An exited terminal can no longer be cancelled.
|
|
46
|
+
...(running.cancellable ? { capabilities: null } : {}),
|
|
45
47
|
}
|
|
46
48
|
: {}),
|
|
47
49
|
});
|
|
@@ -58,6 +60,26 @@ export class V2Terminals {
|
|
|
58
60
|
}
|
|
59
61
|
return { terminal, report: withoutTerminalKeys(report) };
|
|
60
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* The `terminal_update` that lets the client cancel the running terminal
|
|
65
|
+
* `terminalId` of the session `sessionId` with `terminal/cancel`, with its
|
|
66
|
+
* command, or undefined when the terminal is not running. `again` sends it
|
|
67
|
+
* also when the terminal advertises the capability already, as the current
|
|
68
|
+
* state of the terminal.
|
|
69
|
+
*/
|
|
70
|
+
advertiseCancel(sessionId, terminalId, again = false) {
|
|
71
|
+
// The agent names a command's terminal after its tool call.
|
|
72
|
+
const running = this.running.get(`${sessionId} ${terminalId}`);
|
|
73
|
+
if (!running || (running.cancellable && !again))
|
|
74
|
+
return undefined;
|
|
75
|
+
running.cancellable = true;
|
|
76
|
+
return {
|
|
77
|
+
sessionUpdate: "terminal_update",
|
|
78
|
+
terminalId,
|
|
79
|
+
...(running.command !== undefined ? { command: running.command } : {}),
|
|
80
|
+
capabilities: { cancel: {} },
|
|
81
|
+
};
|
|
82
|
+
}
|
|
61
83
|
/** Forgets the terminals of a session. */
|
|
62
84
|
forget(sessionId) {
|
|
63
85
|
for (const key of this.running.keys()) {
|
package/package.json
CHANGED