@agentclientprotocol/claude-agent-acp 0.90.0 → 0.90.1-preview.10

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.
@@ -73,6 +73,23 @@ type TaskStarted = {
73
73
  description?: unknown;
74
74
  prompt?: unknown;
75
75
  };
76
+ /** An agent of the session's subagent history, as the runtime restores it. */
77
+ export type HistoricalSubagent = {
78
+ agentId: string;
79
+ /** The Agent or Task call that launched it. */
80
+ launchId: string;
81
+ /** The agent that made that call. None means the root session. */
82
+ parentAgentId?: string;
83
+ name?: string;
84
+ agentType?: string;
85
+ description?: string;
86
+ };
87
+ /**
88
+ * The agent `agentId` and its ancestors, root first, from the session's
89
+ * subagent history; empty when the history cannot place it (see
90
+ * `subagentLineage`).
91
+ */
92
+ export type SubagentLineage = (agentId: string) => Promise<readonly HistoricalSubagent[]>;
76
93
  /**
77
94
  * Owns the connection-local native subagent registry and all ACP lifecycle
78
95
  * ordering. The main agent only supplies SDK facts and delivers routed output.
@@ -82,6 +99,7 @@ export declare class NativeSubagentRuntime {
82
99
  private readonly session;
83
100
  private readonly publish;
84
101
  private readonly logger;
102
+ private readonly lineage?;
85
103
  readonly enabled: boolean;
86
104
  /** The form of the child sessions; see {@link SubagentForm}. */
87
105
  readonly form: SubagentForm | undefined;
@@ -103,8 +121,13 @@ export declare class NativeSubagentRuntime {
103
121
  private readonly generationByTaskId;
104
122
  private readonly pending;
105
123
  private pendingCount;
106
- /** `form` is undefined for a client without native subagent sessions. */
107
- constructor(form: SubagentForm | undefined, rootSessionId: string, session: NativeSubagentSession, publish: Publish, logger: Logger);
124
+ /** The RFD form: how many times the parent was cancelled (see {@link awaitingUser}). */
125
+ private parentCancels;
126
+ /**
127
+ * `form` is undefined for a client without native subagent sessions. The RFD
128
+ * form restores an agent from before a load or resume with `lineage`.
129
+ */
130
+ constructor(form: SubagentForm | undefined, rootSessionId: string, session: NativeSubagentSession, publish: Publish, logger: Logger, lineage?: SubagentLineage | undefined);
108
131
  route(notification: AcpSessionNotification, deliver: Publish, forcedSessionId?: string): Promise<AcpSessionNotification | null>;
109
132
  private routeUpdate;
110
133
  taskStarted(task: TaskStarted, deliver: Publish): Promise<void>;
@@ -158,16 +181,43 @@ export declare class NativeSubagentRuntime {
158
181
  * foreground children that the turn waits on and, currently, background
159
182
  * children too, and the SDK's task events report each as cancelled. A child
160
183
  * that keeps running keeps its open requests
161
- * (agentclientprotocol/agent-client-protocol#2308).
184
+ * (agentclientprotocol/agent-client-protocol#2308). The RFD form only counts
185
+ * the cancel, for {@link awaitingUser}.
162
186
  */
163
187
  parentCancelled(deliver: Publish): Promise<void>;
164
188
  /**
165
189
  * Runs `request`, a permission or question request of the session
166
190
  * `sessionId`. In the RFD form, a child waiting on it is `requires_action`
167
- * until its last open request ends.
191
+ * until its last open request ends, and then `running` again.
192
+ *
193
+ * `signal` aborts when Claude Code withdraws the request, which is not an
194
+ * answer. If the parent was cancelled while the request was open, Claude
195
+ * Code's interrupt withdrew it as it stopped the child, and the SDK's events
196
+ * report the child `idle` next. The end of the request then reports no
197
+ * `running`, which would show a child that is being stopped as working.
198
+ * Without a cancel, something else answered the request in the user's place,
199
+ * such as a `PermissionRequest` hook, and the child runs on, so the end
200
+ * reports `running`.
168
201
  */
169
- awaitingUser<T>(sessionId: string, request: () => Promise<T>): Promise<T>;
202
+ awaitingUser<T>(sessionId: string, request: () => Promise<T>, signal?: AbortSignal): Promise<T>;
170
203
  discardPending(parentToolUseId: string): void;
204
+ /**
205
+ * The RFD form: restores the agent `agentId` when the SendMessage call
206
+ * `toolUseId` resumes it and the runtime does not know it, because it ran
207
+ * before the session was loaded or resumed. A new launch is no resume: its
208
+ * call is an Agent or Task call.
209
+ *
210
+ * The agent keeps its session id from before, its agent id. The session's
211
+ * subagent history (see {@link SubagentLineage}) gives the call that
212
+ * launched it and its ancestors. The launch call is its delegation again:
213
+ * Claude Code sends the resumed run's messages under that call's id. Before the agent's traffic, the RFD requires its complete
214
+ * ancestor chain, parent before child. So each ancestor that the client was
215
+ * not told about in this connection is announced, with no work state since
216
+ * nothing says that it runs; then the agent, as running. The RFD forbids
217
+ * guessing a parent, so an agent that the history cannot place stays
218
+ * unexposed, as before.
219
+ */
220
+ private restore;
171
221
  /**
172
222
  * The RFD form: the child runs again, and keeps its session. `toolUseId` is
173
223
  * the call that delegated, usually a SendMessage: the SDK runs the resumed
@@ -1 +1 @@
1
- {"version":3,"file":"native-subagents.d.ts","sourceRoot":"","sources":["../src/native-subagents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAClF,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAG9F,kFAAkF;AAClF,MAAM,MAAM,SAAS,GAAG,WAAW,CACjC,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE;IAAE,aAAa,EAAE,iBAAiB,CAAA;CAAE,CAAC,CAAC,OAAO,CAAC,CACtF,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC/B;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E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,CAEtE"}
@@ -14,6 +14,7 @@ export class NativeSubagentRuntime {
14
14
  session;
15
15
  publish;
16
16
  logger;
17
+ lineage;
17
18
  enabled;
18
19
  /** The form of the child sessions; see {@link SubagentForm}. */
19
20
  form;
@@ -35,12 +36,18 @@ export class NativeSubagentRuntime {
35
36
  generationByTaskId = new Map();
36
37
  pending = new Map();
37
38
  pendingCount = 0;
38
- /** `form` is undefined for a client without native subagent sessions. */
39
- constructor(form, rootSessionId, session, publish, logger) {
39
+ /** The RFD form: how many times the parent was cancelled (see {@link awaitingUser}). */
40
+ parentCancels = 0;
41
+ /**
42
+ * `form` is undefined for a client without native subagent sessions. The RFD
43
+ * form restores an agent from before a load or resume with `lineage`.
44
+ */
45
+ constructor(form, rootSessionId, session, publish, logger, lineage) {
40
46
  this.rootSessionId = rootSessionId;
41
47
  this.session = session;
42
48
  this.publish = publish;
43
49
  this.logger = logger;
50
+ this.lineage = lineage;
44
51
  this.form = form;
45
52
  this.enabled = form !== undefined;
46
53
  this.children = session.nativeSubagentsByTaskId ??= new Map();
@@ -140,7 +147,10 @@ export class NativeSubagentRuntime {
140
147
  async taskStarted(task, deliver) {
141
148
  if (!this.enabled)
142
149
  return;
143
- const known = this.form === "rfd" ? this.children.get(task.taskId) : undefined;
150
+ const known = this.form === "rfd"
151
+ ? (this.children.get(task.taskId) ??
152
+ (await this.restore(task.taskId, task.toolUseId ?? undefined, deliver)))
153
+ : undefined;
144
154
  if (known) {
145
155
  // A child keeps its session for every delegation to it. The SDK starts
146
156
  // a resumed agent again under the id of the call that resumed it.
@@ -216,7 +226,7 @@ export class NativeSubagentRuntime {
216
226
  async sendMessageResumed(taskId, deliver, prompt, toolUseId) {
217
227
  if (this.form !== "rfd")
218
228
  return this.taskResumed(taskId, deliver, prompt);
219
- const child = this.children.get(taskId);
229
+ const child = this.children.get(taskId) ?? (await this.restore(taskId, toolUseId, deliver));
220
230
  if (!child)
221
231
  return;
222
232
  const finishing = this.taskFinishPromises.get(taskId);
@@ -353,21 +363,34 @@ export class NativeSubagentRuntime {
353
363
  * foreground children that the turn waits on and, currently, background
354
364
  * children too, and the SDK's task events report each as cancelled. A child
355
365
  * that keeps running keeps its open requests
356
- * (agentclientprotocol/agent-client-protocol#2308).
366
+ * (agentclientprotocol/agent-client-protocol#2308). The RFD form only counts
367
+ * the cancel, for {@link awaitingUser}.
357
368
  */
358
369
  async parentCancelled(deliver) {
359
370
  if (this.form === "air")
360
371
  await this.finishAll("cancelled", deliver);
372
+ else
373
+ this.parentCancels++;
361
374
  }
362
375
  /**
363
376
  * Runs `request`, a permission or question request of the session
364
377
  * `sessionId`. In the RFD form, a child waiting on it is `requires_action`
365
- * until its last open request ends.
378
+ * until its last open request ends, and then `running` again.
379
+ *
380
+ * `signal` aborts when Claude Code withdraws the request, which is not an
381
+ * answer. If the parent was cancelled while the request was open, Claude
382
+ * Code's interrupt withdrew it as it stopped the child, and the SDK's events
383
+ * report the child `idle` next. The end of the request then reports no
384
+ * `running`, which would show a child that is being stopped as working.
385
+ * Without a cancel, something else answered the request in the user's place,
386
+ * such as a `PermissionRequest` hook, and the child runs on, so the end
387
+ * reports `running`.
366
388
  */
367
- async awaitingUser(sessionId, request) {
389
+ async awaitingUser(sessionId, request, signal) {
368
390
  const child = this.form === "rfd" ? this.childOfSession(sessionId) : undefined;
369
391
  if (!child?.announced)
370
392
  return request();
393
+ const cancelsAtOpen = this.parentCancels;
371
394
  child.openRequests = (child.openRequests ?? 0) + 1;
372
395
  if (child.openRequests === 1 && child.workState === "running") {
373
396
  await this.reportState(child, { state: "requires_action" }).catch((error) => this.logger.log(`Failed to report that subagent ${child.sessionId} waits: ${error}`));
@@ -377,7 +400,9 @@ export class NativeSubagentRuntime {
377
400
  }
378
401
  finally {
379
402
  child.openRequests = (child.openRequests ?? 1) - 1;
380
- if (child.openRequests === 0 && child.workState === "requires_action") {
403
+ // Withdrawn after a cancel that came while the request was open.
404
+ const stopped = signal?.aborted === true && this.parentCancels !== cancelsAtOpen;
405
+ if (child.openRequests === 0 && child.workState === "requires_action" && !stopped) {
381
406
  await this.reportState(child, { state: "running" }).catch((error) => this.logger.log(`Failed to report that subagent ${child.sessionId} runs: ${error}`));
382
407
  }
383
408
  }
@@ -385,6 +410,68 @@ export class NativeSubagentRuntime {
385
410
  discardPending(parentToolUseId) {
386
411
  this.takePending(parentToolUseId);
387
412
  }
413
+ /**
414
+ * The RFD form: restores the agent `agentId` when the SendMessage call
415
+ * `toolUseId` resumes it and the runtime does not know it, because it ran
416
+ * before the session was loaded or resumed. A new launch is no resume: its
417
+ * call is an Agent or Task call.
418
+ *
419
+ * The agent keeps its session id from before, its agent id. The session's
420
+ * subagent history (see {@link SubagentLineage}) gives the call that
421
+ * launched it and its ancestors. The launch call is its delegation again:
422
+ * Claude Code sends the resumed run's messages under that call's id. Before the agent's traffic, the RFD requires its complete
423
+ * ancestor chain, parent before child. So each ancestor that the client was
424
+ * not told about in this connection is announced, with no work state since
425
+ * nothing says that it runs; then the agent, as running. The RFD forbids
426
+ * guessing a parent, so an agent that the history cannot place stays
427
+ * unexposed, as before.
428
+ */
429
+ async restore(agentId, toolUseId, deliver) {
430
+ if (!this.lineage || !toolUseId || !this.senderByToolUse.has(toolUseId))
431
+ return undefined;
432
+ const lineage = await this.lineage(agentId).catch((error) => {
433
+ this.logger.log(`Session ${this.rootSessionId}: failed to read the history of subagent ${agentId}: ${error}`);
434
+ return [];
435
+ });
436
+ for (const entry of lineage) {
437
+ let child = this.children.get(entry.agentId);
438
+ if (!child) {
439
+ child = {
440
+ sessionId: entry.agentId,
441
+ parentSessionId: entry.parentAgentId
442
+ ? (this.children.get(entry.parentAgentId)?.sessionId ?? entry.parentAgentId)
443
+ : this.rootSessionId,
444
+ parentToolUseId: entry.launchId,
445
+ name: subagentDisplayName(entry.name, entry.description, entry.agentType, entry.agentId),
446
+ task: subagentDescription(undefined, entry.description),
447
+ ...rfdLabels(entry.name, entry.agentType, entry.description),
448
+ };
449
+ this.children.set(entry.agentId, child);
450
+ this.taskByToolUse.set(entry.launchId, entry.agentId);
451
+ this.childByParentToolUse.set(entry.launchId, child);
452
+ }
453
+ if (child.announced)
454
+ continue;
455
+ if (entry.agentId === agentId) {
456
+ await this.announce(child);
457
+ }
458
+ else {
459
+ await this.publish({
460
+ sessionId: child.parentSessionId,
461
+ update: {
462
+ sessionUpdate: "subagent_update",
463
+ sessionId: child.sessionId,
464
+ ...(child.title ? { title: child.title } : {}),
465
+ ...(child.description ? { description: child.description } : {}),
466
+ },
467
+ });
468
+ child.announced = true;
469
+ }
470
+ for (const pending of this.takePending(entry.launchId))
471
+ await deliver(pending);
472
+ }
473
+ return this.children.get(agentId);
474
+ }
388
475
  /**
389
476
  * The RFD form: the child runs again, and keeps its session. `toolUseId` is
390
477
  * the call that delegated, usually a SendMessage: the SDK runs the resumed
@@ -1,4 +1,5 @@
1
1
  import { type SessionMessage } from "@anthropic-ai/claude-agent-sdk";
2
+ import { type HistoricalSubagent } from "./native-subagents.js";
2
3
  /** What the metadata file of a subagent says about it. */
3
4
  export interface SubagentRecord {
4
5
  /** The SDK agent id, the name of its transcript. */
@@ -33,6 +34,22 @@ export interface SubagentHistory {
33
34
  * The ids are empty for a session without a local transcript.
34
35
  */
35
36
  export declare function subagentHistory(sessionId: string): Promise<SubagentHistory>;
37
+ /**
38
+ * The agent `agentId` and its ancestors, root first, from the subagent history
39
+ * of the session `sessionId`. The runtime restores an agent from it when Claude
40
+ * Code resumes one that ran before the session was loaded or resumed.
41
+ *
42
+ * The metadata file of an agent names the call that launched it, but not the
43
+ * agent that made the call. So the parent of a launch is the session whose
44
+ * transcript has the call, as in the replay: the session's own transcript, or
45
+ * an agent's. The list is empty when the agent or one of its ancestors has no
46
+ * metadata, or no transcript has its launch.
47
+ */
48
+ export declare function subagentLineage(sessionId: string, agentId: string, logger: {
49
+ error(...args: unknown[]): void;
50
+ }): Promise<HistoricalSubagent[]>;
51
+ /** The ids of the Agent and Task calls that launched subagents in `content`. */
52
+ export declare function subagentLaunchIds(content: unknown): string[];
36
53
  /**
37
54
  * The transcript of the subagent `agentId` of a session, or an empty list
38
55
  * when it cannot be read. With the project directory, the SDK skips its
@@ -1 +1 @@
1
- {"version":3,"file":"subagent-history.d.ts","sourceRoot":"","sources":["../src/subagent-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,gCAAgC,CAAC;AAKxC,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uDAAuD;IACvD,UAAU,EAAE,OAAO,CAAC;IACpB,mCAAmC;IACnC,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACpC;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAwCjF;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE;IAAE,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;CAAE,GAC1C,OAAO,CAAC,cAAc,EAAE,CAAC,CAW3B"}
1
+ {"version":3,"file":"subagent-history.d.ts","sourceRoot":"","sources":["../src/subagent-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAA+B,KA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getSubagentMessages, } from "@anthropic-ai/claude-agent-sdk";
1
+ import { getSessionInfo, getSessionMessages, getSubagentMessages, } from "@anthropic-ai/claude-agent-sdk";
2
2
  import { readdir, readFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
+ import { isNativeSubagentControlTool } from "./native-subagents.js";
4
5
  import { findTranscript } from "./resumed-session.js";
5
6
  /**
6
7
  * Finds the subagent transcripts of a session.
@@ -52,6 +53,83 @@ export async function subagentHistory(sessionId) {
52
53
  const dir = (await getSessionInfo(sessionId).catch(() => undefined))?.cwd;
53
54
  return dir ? { agents, dir } : { agents };
54
55
  }
56
+ /**
57
+ * The agent `agentId` and its ancestors, root first, from the subagent history
58
+ * of the session `sessionId`. The runtime restores an agent from it when Claude
59
+ * Code resumes one that ran before the session was loaded or resumed.
60
+ *
61
+ * The metadata file of an agent names the call that launched it, but not the
62
+ * agent that made the call. So the parent of a launch is the session whose
63
+ * transcript has the call, as in the replay: the session's own transcript, or
64
+ * an agent's. The list is empty when the agent or one of its ancestors has no
65
+ * metadata, or no transcript has its launch.
66
+ */
67
+ export async function subagentLineage(sessionId, agentId, logger) {
68
+ const history = await subagentHistory(sessionId);
69
+ const launchOf = new Map();
70
+ for (const [launchId, record] of history.agents) {
71
+ launchOf.set(record.agentId, { launchId, record });
72
+ }
73
+ if (!launchOf.has(agentId))
74
+ return [];
75
+ // Without the project directory, as the replay reads it (`readResumedSession`).
76
+ const rootLaunches = new Set(launchIdsIn(await getSessionMessages(sessionId).catch((error) => {
77
+ logger.error(`Failed to read the transcript of session ${sessionId}:`, error);
78
+ return [];
79
+ })));
80
+ const agentLaunches = new Map();
81
+ /** The agent whose transcript has the launch `launchId`, `null` for the root's. */
82
+ const launcherOf = async (launchId) => {
83
+ if (rootLaunches.has(launchId))
84
+ return null;
85
+ for (const candidate of launchOf.keys()) {
86
+ let launches = agentLaunches.get(candidate);
87
+ if (!launches) {
88
+ launches = new Set(launchIdsIn(await readSubagentMessages(sessionId, candidate, history, logger)));
89
+ agentLaunches.set(candidate, launches);
90
+ }
91
+ if (launches.has(launchId))
92
+ return candidate;
93
+ }
94
+ return undefined;
95
+ };
96
+ const lineage = [];
97
+ let current = agentId;
98
+ while (current !== null) {
99
+ const launch = launchOf.get(current);
100
+ // A cycle, or an ancestor without metadata.
101
+ if (!launch || lineage.some((entry) => entry.agentId === current))
102
+ return [];
103
+ const launcher = await launcherOf(launch.launchId);
104
+ if (launcher === undefined)
105
+ return [];
106
+ lineage.unshift({
107
+ agentId: current,
108
+ launchId: launch.launchId,
109
+ ...(launcher !== null ? { parentAgentId: launcher } : {}),
110
+ ...(launch.record.name ? { name: launch.record.name } : {}),
111
+ ...(launch.record.agentType ? { agentType: launch.record.agentType } : {}),
112
+ ...(launch.record.description ? { description: launch.record.description } : {}),
113
+ });
114
+ current = launcher;
115
+ }
116
+ return lineage;
117
+ }
118
+ /** The ids of the Agent and Task calls that launched subagents in `content`. */
119
+ export function subagentLaunchIds(content) {
120
+ if (!Array.isArray(content))
121
+ return [];
122
+ return content.flatMap((block) => typeof block === "object" &&
123
+ block !== null &&
124
+ block.type === "tool_use" &&
125
+ typeof block.id === "string" &&
126
+ isNativeSubagentControlTool(block.name)
127
+ ? [block.id]
128
+ : []);
129
+ }
130
+ function launchIdsIn(messages) {
131
+ return messages.flatMap((message) => subagentLaunchIds(message.message?.content));
132
+ }
55
133
  /**
56
134
  * The transcript of the subagent `agentId` of a session, or an empty list
57
135
  * when it cannot be read. With the project directory, the SDK skips its
@@ -90,6 +90,11 @@ export declare class AcpToolCallRenderer {
90
90
  * the tool call's content already shows, which it would otherwise keep.
91
91
  */
92
92
  private get keepsMeta();
93
+ /**
94
+ * Whether a tool call with these facts gets a display terminal: a command, for a client
95
+ * that renders terminals.
96
+ */
97
+ private hasTerminal;
93
98
  /**
94
99
  * The status of a tool result. Claude Code reports a run that it aborted in
95
100
  * one of three ways:
@@ -223,13 +228,21 @@ export declare class AcpToolCallRenderer {
223
228
  * client `failed`, since v1 has no `cancelled`. If Claude Code ran it but
224
229
  * returned no result, it failed, unless a `session/cancel` ended the turn
225
230
  * (`cancelled`): the cancel stopped the run, so a v2 client gets `cancelled`
226
- * for it too.
231
+ * for it too. The report does not end the call's terminal: see {@link terminalExit}.
227
232
  */
228
233
  unfinished(call: {
229
234
  toolCallId: string;
230
235
  ran: boolean;
231
236
  cancelled?: boolean;
232
237
  }): ToolCallUpdate;
238
+ /**
239
+ * The `_meta` that ends the display terminal of a command whose tool call gets no result, to
240
+ * add to the report from {@link unfinished}. Undefined when the tool call has no terminal
241
+ * (see {@link toolCall}). The exit code is unknown, since the command ended without a result:
242
+ * null, or 1 for AIR, which always gets a number and reads 1 for a command that did not
243
+ * succeed.
244
+ */
245
+ terminalExit(toolUse: ToolUse): Pick<ToolUpdateMeta, "terminal_exit"> | undefined;
233
246
  /**
234
247
  * The report of a tool progress beat. The field tracker sends the
235
248
  * `in_progress` status once, so a later beat carries only the progress.
@@ -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,0BAA0B,CAAC;AAQlC,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM5F,MAAM,MAAM,cAAc,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAa3D,wFAAwF;AACxF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAExF;AAED,yCAAyC;AACzC,MAAM,MAAM,cAAc,GAAG;IAC3B,UA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AC;QACzB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,aAAa,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;CAyBtF"}
@@ -49,6 +49,13 @@ export class AcpToolCallRenderer {
49
49
  get keepsMeta() {
50
50
  return this.capabilities.air.client || this.capabilities.v2;
51
51
  }
52
+ /**
53
+ * Whether a tool call with these facts gets a display terminal: a command, for a client
54
+ * that renders terminals.
55
+ */
56
+ hasTerminal(facts) {
57
+ return facts.command === true && this.capabilities.terminalOutput;
58
+ }
52
59
  /**
53
60
  * The status of a tool result. Claude Code reports a run that it aborted in
54
61
  * one of three ways:
@@ -100,9 +107,7 @@ export class AcpToolCallRenderer {
100
107
  return {
101
108
  _meta: {
102
109
  ...this.toolUseMeta(toolUse, options.cwd),
103
- ...(facts.command && this.capabilities.terminalOutput
104
- ? { terminal_info: { terminal_id: toolUse.id } }
105
- : {}),
110
+ ...(this.hasTerminal(facts) ? { terminal_info: { terminal_id: toolUse.id } } : {}),
106
111
  // Only AIR gets the MCP flag. The upstream adapter does not send it.
107
112
  ...(isMcp && this.capabilities.air.client ? { is_mcp_tool_call: true } : {}),
108
113
  },
@@ -462,7 +467,7 @@ export class AcpToolCallRenderer {
462
467
  * client `failed`, since v1 has no `cancelled`. If Claude Code ran it but
463
468
  * returned no result, it failed, unless a `session/cancel` ended the turn
464
469
  * (`cancelled`): the cancel stopped the run, so a v2 client gets `cancelled`
465
- * for it too.
470
+ * for it too. The report does not end the call's terminal: see {@link terminalExit}.
466
471
  */
467
472
  unfinished(call) {
468
473
  const stopped = !call.ran || call.cancelled === true;
@@ -479,6 +484,24 @@ export class AcpToolCallRenderer {
479
484
  ],
480
485
  };
481
486
  }
487
+ /**
488
+ * The `_meta` that ends the display terminal of a command whose tool call gets no result, to
489
+ * add to the report from {@link unfinished}. Undefined when the tool call has no terminal
490
+ * (see {@link toolCall}). The exit code is unknown, since the command ended without a result:
491
+ * null, or 1 for AIR, which always gets a number and reads 1 for a command that did not
492
+ * succeed.
493
+ */
494
+ terminalExit(toolUse) {
495
+ if (!this.hasTerminal(this.facts(toolUse)))
496
+ return undefined;
497
+ return {
498
+ terminal_exit: {
499
+ terminal_id: toolUse.id,
500
+ exit_code: this.capabilities.air.client ? 1 : null,
501
+ signal: null,
502
+ },
503
+ };
504
+ }
482
505
  /**
483
506
  * The report of a tool progress beat. The field tracker sends the
484
507
  * `in_progress` status once, so a later beat carries only the progress.
@@ -529,7 +552,7 @@ export class AcpToolCallRenderer {
529
552
  * does not render `rawInput` itself, and never next to a terminal.
530
553
  */
531
554
  toolUseContent(toolCallId, facts) {
532
- const terminal = facts.command === true && this.capabilities.terminalOutput;
555
+ const terminal = this.hasTerminal(facts);
533
556
  return [
534
557
  ...(terminal ? [{ type: "terminal", terminalId: toolCallId }] : []),
535
558
  ...(facts.change ?? []),
@@ -53,7 +53,11 @@ export interface TurnEvents {
53
53
  * the cycle reports nothing more, and the turn reports from there.
54
54
  */
55
55
  export interface ForegroundEvents {
56
- /** The work started, or works again after it waited for the user. */
56
+ /**
57
+ * The work started, or works again after it waited for the user. Not after
58
+ * a wait that a cancel ended: Claude Code's interrupt withdrew the last
59
+ * request, so the work is being stopped, and {@link ended} follows at once.
60
+ */
57
61
  running(): void;
58
62
  /**
59
63
  * The work waits for the user: a permission request or a question is open in
@@ -1 +1 @@
1
- {"version":3,"file":"turn-events.d.ts","sourceRoot":"","sources":["../src/turn-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,OAAO,IAAI,IAAI,CAAC;IAChB;;;;OAIG;IACH,YAAY,IAAI,IAAI,CAAC;IACrB,sBAAsB;IACtB,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B;AAED,6DAA6D;AAC7D,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,mBAAmB,GAAG,SAAS,GAAG,WAAW,CAAC;AAEnG,wBAAwB;AACxB,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,UAAU,CAAC;IACvB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC"}
1
+ {"version":3,"file":"turn-events.d.ts","sourceRoot":"","sources":["../src/turn-events.ts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`running`. For a prompt's turn, right after its `user_message`.
30
30
  * - Waiting on a permission request or a question: `requires_action`, and
31
- * `running` once none is open.
31
+ * `running` once none is open, unless a cancel withdrew the last one: the
32
+ * work is being stopped then, and its `idle` follows.
32
33
  * - Ended: `idle` with the stop reason, usage, and `_meta` of the work.
33
34
  * - Failed: `idle` with the `error` stop reason and the JSON-RPC error that v1
34
35
  * answers the prompt with, so a client can show its message and handle its
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/v2/prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAuC,MAAM,mBAAmB,CAAC;AAE/F;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,EAAE,CAAC,aAAa,EACxB,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,GACvC,OAAO,CAAC,EAAE,CAAC,cAAc,CAAC,CAiC5B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,GAAG,gBAAgB,CAoBvF;AAgCD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,aAAa,GAAG,aAAa,CAEvF"}
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/v2/prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAuC,MAAM,mBAAmB,CAAC;AAE/F;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,EAAE,CAAC,aAAa,EACxB,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,GACvC,OAAO,CAAC,EAAE,CAAC,cAAc,CAAC,CAiC5B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,GAAG,gBAAgB,CAoBvF;AAgCD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,aAAa,GAAG,aAAa,CAEvF"}
package/dist/v2/prompt.js CHANGED
@@ -57,7 +57,8 @@ export function v2Prompt(agent, params, send) {
57
57
  *
58
58
  * - Started: `running`. For a prompt's turn, right after its `user_message`.
59
59
  * - Waiting on a permission request or a question: `requires_action`, and
60
- * `running` once none is open.
60
+ * `running` once none is open, unless a cancel withdrew the last one: the
61
+ * work is being stopped then, and its `idle` follows.
61
62
  * - Ended: `idle` with the stop reason, usage, and `_meta` of the work.
62
63
  * - Failed: `idle` with the `error` stop reason and the JSON-RPC error that v1
63
64
  * answers the prompt with, so a client can show its message and handle its
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.90.0",
6
+ "version": "0.90.1-preview.10",
7
7
  "description": "An ACP-compatible coding agent powered by the Claude Agent SDK (TypeScript)",
8
8
  "main": "dist/lib.js",
9
9
  "types": "dist/lib.d.ts",