@agentclientprotocol/claude-agent-acp 0.109.0 → 0.109.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.
Files changed (72) hide show
  1. package/README.md +10 -5
  2. package/dist/acp-subagents.d.ts +39 -0
  3. package/dist/acp-subagents.d.ts.map +1 -1
  4. package/dist/acp-subagents.js +47 -0
  5. package/dist/auth-status-reporter.d.ts +2 -3
  6. package/dist/auth-status-reporter.d.ts.map +1 -1
  7. package/dist/auth-status-reporter.js +32 -29
  8. package/dist/auth-status.d.ts +6 -7
  9. package/dist/auth-status.d.ts.map +1 -1
  10. package/dist/auth-status.js +9 -8
  11. package/dist/client-system-prompt.d.ts +6 -4
  12. package/dist/client-system-prompt.d.ts.map +1 -1
  13. package/dist/client-system-prompt.js +7 -2
  14. package/dist/context-compaction.d.ts.map +1 -1
  15. package/dist/context-compaction.js +4 -3
  16. package/dist/native-subagents.d.ts +102 -7
  17. package/dist/native-subagents.d.ts.map +1 -1
  18. package/dist/native-subagents.js +208 -17
  19. package/dist/plans.d.ts +4 -4
  20. package/dist/providers.d.ts +34 -1
  21. package/dist/providers.d.ts.map +1 -1
  22. package/dist/providers.js +37 -1
  23. package/dist/serve.d.ts +1 -1
  24. package/dist/serve.js +1 -1
  25. package/dist/session-config-options.d.ts.map +1 -1
  26. package/dist/session-config-options.js +13 -0
  27. package/dist/subagent-replay.d.ts +49 -33
  28. package/dist/subagent-replay.d.ts.map +1 -1
  29. package/dist/subagent-replay.js +49 -52
  30. package/dist/tool-calls/renderer.d.ts +0 -9
  31. package/dist/tool-calls/renderer.d.ts.map +1 -1
  32. package/dist/tool-calls/renderer.js +1 -19
  33. package/dist/tool-calls/reporters/interaction.d.ts +9 -0
  34. package/dist/tool-calls/reporters/interaction.d.ts.map +1 -1
  35. package/dist/tool-calls/reporters/interaction.js +23 -1
  36. package/dist/tool-calls/reporters/search.d.ts +7 -3
  37. package/dist/tool-calls/reporters/search.d.ts.map +1 -1
  38. package/dist/tool-calls/reporters/search.js +9 -4
  39. package/dist/v1/acp-agent.d.ts +35 -19
  40. package/dist/v1/acp-agent.d.ts.map +1 -1
  41. package/dist/v1/acp-agent.js +123 -67
  42. package/dist/v1/client-connection.d.ts +4 -2
  43. package/dist/v1/client-connection.d.ts.map +1 -1
  44. package/dist/v1/client-connection.js +6 -2
  45. package/dist/v1/session-fingerprint.d.ts.map +1 -1
  46. package/dist/v1/session-fingerprint.js +1 -2
  47. package/dist/v2/agent.d.ts.map +1 -1
  48. package/dist/v2/agent.js +53 -19
  49. package/dist/v2/auth.d.ts +6 -5
  50. package/dist/v2/auth.d.ts.map +1 -1
  51. package/dist/v2/auth.js +2 -2
  52. package/dist/v2/permissions.d.ts +1 -1
  53. package/dist/v2/permissions.js +1 -1
  54. package/dist/v2/replay-hold.d.ts +15 -5
  55. package/dist/v2/replay-hold.d.ts.map +1 -1
  56. package/dist/v2/replay-hold.js +21 -7
  57. package/dist/v2/reports.d.ts +4 -0
  58. package/dist/v2/reports.d.ts.map +1 -1
  59. package/dist/v2/reports.js +10 -1
  60. package/dist/v2/session-requests.js +3 -1
  61. package/dist/v2/session-update.js +3 -3
  62. package/dist/v2/session.d.ts.map +1 -1
  63. package/dist/v2/session.js +2 -0
  64. package/dist/v2/subagent-replay.d.ts +20 -18
  65. package/dist/v2/subagent-replay.d.ts.map +1 -1
  66. package/dist/v2/subagent-replay.js +16 -31
  67. package/dist/v2/tasks.d.ts +55 -6
  68. package/dist/v2/tasks.d.ts.map +1 -1
  69. package/dist/v2/tasks.js +147 -19
  70. package/dist/v2/tool-call.d.ts.map +1 -1
  71. package/dist/v2/tool-call.js +23 -1
  72. package/package.json +4 -4
@@ -6,13 +6,12 @@
6
6
  * metadata file names the Agent or Task call that launched it (see
7
7
  * `subagentHistory`). The replay announces each child right after that call,
8
8
  * under its live session id (the agent id), with no capabilities: it cannot
9
- * run again in this process. Then it sends the child's `model` (of its first
10
- * response) and its history to the child session; a later response with
11
- * another model sends it again. As live, the parent is not shown the launch
12
- * call: its prompt is the parent's outgoing message, and a foreground child's
13
- * answer its reply. A child's successful SubagentHandback call is its message
14
- * to the parent instead. Unlike live, the replay does not tell runs apart, so
15
- * a child that handed back any report gets no reply from its launch's result.
9
+ * run again in this process. Then it sends the child's history to the child
10
+ * session. As live, the parent is not shown the launch call: its prompt is
11
+ * the parent's outgoing message, and a foreground child's answer its reply. A
12
+ * child's successful SubagentHandback call is its message to the parent
13
+ * instead. Unlike live, the replay does not tell runs apart, so a child that
14
+ * handed back any report gets no reply from its launch's result.
16
15
  *
17
16
  * A SendMessage call whose message the replay delivered to a child before it
18
17
  * reached the call is that message too: the sender's outgoing view, at the
@@ -32,9 +31,12 @@
32
31
  * ({@link currentStates}): on its parent and on its own stream. A child that
33
32
  * works in the live session, on a resume of the active session, gets its
34
33
  * current state from the resume snapshot instead
35
- * (`SessionTasks.currentState`). A child whose configuration is not the
36
- * `model` that the replay sent, such as a live child whose hooks reported its
37
- * mode, gets it again then too.
34
+ * (`SessionTasks.currentState`).
35
+ *
36
+ * The replay sends no `config_option_update` of a child: v2 asks an agent not
37
+ * to replay a past one. Each child's configuration goes out after the root's
38
+ * `replay_complete` too, following the child's current state (see
39
+ * `currentChildConfiguration`).
38
40
  *
39
41
  * A launch without metadata has no known id, so it is not announced: the RFD
40
42
  * forbids inventing one. Its Agent call stays an ordinary tool call of the
@@ -83,6 +85,8 @@ export declare class SubagentReplay {
83
85
  static load(host: ReplayHost, messages: SessionMessage[], live?: LiveChildren): Promise<SubagentReplay | undefined>;
84
86
  /** The hooks of the replay of the root session's history (`messages`). */
85
87
  hooks(output: SessionOutput, messages: SessionMessage[]): ReplayHooks;
88
+ /** Whether the replay announced the child session `sessionId`. */
89
+ announced(sessionId: string): boolean;
86
90
  /**
87
91
  * Ends the replay of the children. Every child's end goes out on its
88
92
  * parent, whose history it is. Then each announced child gets its
@@ -104,9 +108,8 @@ export declare class SubagentReplay {
104
108
  * session: its work ended, or its process is gone, so its replayed end, on
105
109
  * its parent and on its own stream. A `cwd` that is gone, such as a
106
110
  * worktree that Claude Code removed, is cleared. Then each replayed child's
107
- * configuration, when it is not the `model` that the replay sent: the live
108
- * child's, else the model of its latest response, by the session's model
109
- * list.
111
+ * configuration (see `currentChildConfiguration`): the live child's, else
112
+ * the model of its latest response, by the session's model list.
110
113
  *
111
114
  * The v1 core sends the same after the response (`currentStates`): on v1
112
115
  * the response is what separates a replayed child state from a current one.
@@ -129,16 +132,15 @@ export declare class SubagentReplay {
129
132
  */
130
133
  private route;
131
134
  /**
132
- * Before a message of `owner`'s history (the root's when undefined): a
133
- * child's response with another model sends its `model` again, and a
134
- * persisted task notification of a child is the state its work ended in.
135
+ * Before a message of `owner`'s history (the root's when undefined): the
136
+ * model of a child's response is its latest one (see `trackResponseModel`),
137
+ * and a persisted task notification of a child is the state its work ended
138
+ * in.
135
139
  */
136
140
  private replaying;
137
141
  /** After a message that launched children: each is announced, and its history replays. */
138
142
  private replayed;
139
143
  private announce;
140
- /** The `model` of a response of `child`, when it is not the one the client holds. */
141
- private sendModel;
142
144
  /**
143
145
  * The rest of a child's user message to replay, or `null` when nothing is
144
146
  * left, after its text went out as the child's incoming `session_message`.
@@ -1 +1 @@
1
- {"version":3,"file":"subagent-replay.d.ts","sourceRoot":"","sources":["../../src/v2/subagent-replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAOL,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAC;AAmBhC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,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;IAiBpB,OAAO,CAAC,UAAU;IAWlB;;;OAGG;IACH;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK;IAyDb;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAcjB,0FAA0F;IAC1F,OAAO,CAAC,QAAQ;IAgBhB,OAAO,CAAC,QAAQ;IAiChB;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAgBpB;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,KAAK;CAKd"}
@@ -1,6 +1,6 @@
1
- import { childModelOption, launchReply, linkedSessionMessages, nativeSubagentState, responseModelEntry, rfdLabels, } from "../native-subagents.js";
1
+ import { launchReply, linkedSessionMessages, nativeSubagentState, rfdLabels, } from "../native-subagents.js";
2
2
  import { readSubagentMessages, subagentHistory, subagentLaunchIds, } from "../subagent-history.js";
3
- import { deliveredCall, firstResponseModel, isDelivery, isDirectory, missingHistoryNotice, ReplayTranscript, replayEndState, textOf, } from "../subagent-replay.js";
3
+ import { currentChildConfiguration, deliveredCall, isDelivery, isDirectory, missingHistoryNotice, ReplayTranscript, replayEndState, textOf, trackResponseModel, } from "../subagent-replay.js";
4
4
  import { taskNotificationsOf } from "../task-notifications.js";
5
5
  import { REPLAY_COMPLETE } from "./setup.js";
6
6
  import { SessionOutput } from "./stream.js";
@@ -50,6 +50,10 @@ export class SubagentReplay {
50
50
  this.transcript.scan(messages, output.sessionId);
51
51
  return this.ownerHooks(output, undefined);
52
52
  }
53
+ /** Whether the replay announced the child session `sessionId`. */
54
+ announced(sessionId) {
55
+ return this.transcript.byAgentId.get(sessionId)?.announced === true;
56
+ }
53
57
  /**
54
58
  * Ends the replay of the children. Every child's end goes out on its
55
59
  * parent, whose history it is. Then each announced child gets its
@@ -93,9 +97,8 @@ export class SubagentReplay {
93
97
  * session: its work ended, or its process is gone, so its replayed end, on
94
98
  * its parent and on its own stream. A `cwd` that is gone, such as a
95
99
  * worktree that Claude Code removed, is cleared. Then each replayed child's
96
- * configuration, when it is not the `model` that the replay sent: the live
97
- * child's, else the model of its latest response, by the session's model
98
- * list.
100
+ * configuration (see `currentChildConfiguration`): the live child's, else
101
+ * the model of its latest response, by the session's model list.
99
102
  *
100
103
  * The v1 core sends the same after the response (`currentStates`): on v1
101
104
  * the response is what separates a replayed child state from a current one.
@@ -110,15 +113,13 @@ export class SubagentReplay {
110
113
  }
111
114
  }
112
115
  sendConfiguration(child) {
113
- const entry = responseModelEntry(child.responseModel, this.host.models());
114
- const current = this.live.configuration(child.sessionId) ?? (entry ? [childModelOption(entry)] : undefined);
115
- const replayed = child.model ? JSON.stringify([childModelOption(child.model)]) : undefined;
116
- if (!current || JSON.stringify(current) === replayed)
116
+ const configOptions = currentChildConfiguration(child, this.live.configuration(child.sessionId), this.host.models());
117
+ if (!configOptions)
117
118
  return;
118
119
  child.output.emitV1([
119
120
  {
120
121
  sessionId: child.sessionId,
121
- update: { sessionUpdate: "config_option_update", configOptions: current },
122
+ update: { sessionUpdate: "config_option_update", configOptions },
122
123
  },
123
124
  ]);
124
125
  }
@@ -203,15 +204,16 @@ export class SubagentReplay {
203
204
  return [];
204
205
  }
205
206
  /**
206
- * Before a message of `owner`'s history (the root's when undefined): a
207
- * child's response with another model sends its `model` again, and a
208
- * persisted task notification of a child is the state its work ended in.
207
+ * Before a message of `owner`'s history (the root's when undefined): the
208
+ * model of a child's response is its latest one (see `trackResponseModel`),
209
+ * and a persisted task notification of a child is the state its work ended
210
+ * in.
209
211
  */
210
212
  replaying(message, owner) {
211
213
  const inner = message.message;
212
214
  if (message.type === "assistant") {
213
215
  if (owner)
214
- this.sendModel(owner, typeof inner?.model === "string" ? inner.model : undefined);
216
+ trackResponseModel(owner, inner?.model);
215
217
  return;
216
218
  }
217
219
  for (const notification of taskNotificationsOf(inner?.content)) {
@@ -232,7 +234,6 @@ export class SubagentReplay {
232
234
  if (messages.length === 0)
233
235
  this.withoutHistory++;
234
236
  this.announce(child);
235
- this.sendModel(child, firstResponseModel(messages));
236
237
  this.transcript.scan(messages, child.sessionId);
237
238
  child.output.replay(messages, this.ownerHooks(child.output, child));
238
239
  if (!child.promptSent && typeof child.input.prompt === "string") {
@@ -261,22 +262,6 @@ export class SubagentReplay {
261
262
  });
262
263
  child.output = new SessionOutput(child.sessionId, child.cwd ?? parentCwd, this.host.translator, (update) => this.host.send({ sessionId: child.sessionId, update }), this.host.logger, true);
263
264
  }
264
- /** The `model` of a response of `child`, when it is not the one the client holds. */
265
- sendModel(child, model) {
266
- const entry = responseModelEntry(model, this.host.models());
267
- if (!entry || !child.output)
268
- return;
269
- child.responseModel = model;
270
- if (child.model?.value === entry.value && child.model.name === entry.name)
271
- return;
272
- child.model = entry;
273
- child.output.emitV1([
274
- {
275
- sessionId: child.sessionId,
276
- update: { sessionUpdate: "config_option_update", configOptions: [childModelOption(entry)] },
277
- },
278
- ]);
279
- }
280
265
  /**
281
266
  * The rest of a child's user message to replay, or `null` when nothing is
282
267
  * left, after its text went out as the child's incoming `session_message`.
@@ -71,6 +71,11 @@ export declare class SessionTasks {
71
71
  private readonly pendingByLaunch;
72
72
  /** The live subagent tasks, by agent id, announced or not. */
73
73
  private readonly agents;
74
+ /**
75
+ * The ends of the runs that wait for their messages (see {@link taskEnded}),
76
+ * by agent id.
77
+ */
78
+ private readonly heldEnds;
74
79
  /** The open permission requests of each subagent, by agent id. */
75
80
  private readonly agentRequests;
76
81
  /** The subagents whose runs a cancel stops, by agent id, until their runs end. */
@@ -168,8 +173,13 @@ export declare class SessionTasks {
168
173
  loadReplay(messages: SessionMessage[]): Promise<SubagentReplay | undefined>;
169
174
  /** Whether a subagent task runs, announced or not, in the foreground or the background. */
170
175
  hasLiveSubagents(): boolean;
171
- /** Whether `sessionId` is an announced child session of this root. */
172
- hasChild(sessionId: string): boolean;
176
+ /**
177
+ * Whether `sessionId` is a child session that this root announced in its
178
+ * current conversation. A child that only a replay announced, or one from
179
+ * before a conversation reset, is not: the client still knows those (see
180
+ * `AnnouncedChildren`).
181
+ */
182
+ private hasChild;
173
183
  /**
174
184
  * The session that a permission request of the agent `agentId` goes to:
175
185
  * its child session once it is announced, else the root. A request can
@@ -260,6 +270,26 @@ export declare class SessionTasks {
260
270
  } | {
261
271
  toolCallId: string;
262
272
  }): Promise<boolean>;
273
+ /**
274
+ * For a resume of the active session that replays: the announcement and
275
+ * the `replay_complete` of each current child that the replay did not
276
+ * announce (`replayed`), parents first. The stored history has no launch of
277
+ * such a child: a forked skill's, whose metadata names no call, or a
278
+ * subagent that Claude launched after the history was written. Its replay
279
+ * is empty, so its `replay_complete` follows its announcement at once.
280
+ *
281
+ * A child is current when it works, when its parent lists it, or when the
282
+ * replay holds something its session sent (`held`), such as the end of a
283
+ * run that ended while the history was read. v2 asks for a child's
284
+ * announcement again on every resume, before any other update of its
285
+ * session, and for a `replay_complete` on every child that is announced
286
+ * before the response. The caller sends these after the root's
287
+ * `replay_complete`, where an announcement is current, and before what the
288
+ * replay held.
289
+ */
290
+ unreplayedChildren(replayed: (sessionId: string) => boolean, held: ReadonlySet<string>): v2.UpdateSessionNotification[];
291
+ /** Whether `child` works, or its parent's `background` list (of `lists`) names it. */
292
+ private worksOrListed;
263
293
  /**
264
294
  * The current state of the session's work, for a resume of the active
265
295
  * session: each subagent that a session lists, or that works in its
@@ -272,6 +302,12 @@ export declare class SessionTasks {
272
302
  currentState(): v2.UpdateSessionNotification[];
273
303
  /** The tool calls of `sessionId` whose tasks go on in the background: a cancel leaves them. */
274
304
  backgroundCalls(sessionId: string): Set<string>;
305
+ /**
306
+ * The root's turn ends: a run whose end still waited for its messages ends
307
+ * before the root's idle, since the turn waited on it. Such a turn ended
308
+ * without a result, as one that a cancel stopped can.
309
+ */
310
+ turnClosed(): void;
275
311
  /**
276
312
  * Claude Code's query ended: its tasks ended with its process. Terminals
277
313
  * exit and background tool calls are cancelled; a child that worked ends
@@ -340,10 +376,21 @@ export declare class SessionTasks {
340
376
  * stays unexposed, its traffic the root's.
341
377
  */
342
378
  private restore;
379
+ /** The session whose stream mapped the tool call `toolCallId`, if one did. */
380
+ private callerOf;
381
+ /**
382
+ * Ends the runs whose ends waited for their messages (see {@link taskEnded}),
383
+ * when `message` ends their wait (see `endsMessageWait`). Without a
384
+ * message, all of them: the root's turn or the query ended, or the
385
+ * conversation was reset.
386
+ */
387
+ private releaseHeldEnds;
343
388
  /**
344
389
  * A message of a subagent, by its `parent_tool_use_id`: it goes to the
345
- * child's stream, or waits for the child's announcement. A message of an
346
- * agent that no known call launched is the root's.
390
+ * child's stream, or waits for the child's announcement. One whose
391
+ * `parent_tool_use_id` is no Agent or Task call goes by its `agent_id`: a
392
+ * forked skill that the user typed sends `forked-command-<skill>` for every
393
+ * run of the skill. A message of an agent that neither names is the root's.
347
394
  */
348
395
  private childMessage;
349
396
  /** Sends a message of the announced `child` to its stream. */
@@ -377,9 +424,11 @@ export declare class SessionTasks {
377
424
  /**
378
425
  * `notification`, an update that the client is shown on the session
379
426
  * `shownOn`, with a `session` reference when it is of a TaskStop or
380
- * SendMessage call that names an announced child by its agent id, or of a
427
+ * SendMessage call that names an announced child by its agent id, of a
381
428
  * SendMessage call that resumed one and stays shown (see
382
- * {@link requestShows}), as on v1 (`NativeSubagentRuntime.withTarget`).
429
+ * {@link requestShows}), or of the call that launched one and is no Agent
430
+ * or Task call, such as the Skill call of a forked skill, as on v1
431
+ * (`NativeSubagentRuntime.withTarget`).
383
432
  */
384
433
  private withTarget;
385
434
  private routed;
@@ -1 +1 @@
1
- {"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../src/v2/tasks.ts"],"names":[],"mappings":"AA+CA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,cAAc,EACd,cAAc,EACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAA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O,CAAC,cAAc;IAsBtB;;;;;;;OAOG;YACW,YAAY;IA8B1B,oEAAoE;IACpE,WAAW,EAAG,CACZ,OAAO,EAAE,EAAE,CAAC,wBAAwB,EACpC,MAAM,EAAE,WAAW,KAChB,OAAO,CAAC,EAAE,CAAC,yBAAyB,CAAC,CAAC;IAE3C;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAQ1B,oFAAoF;IACpF,OAAO,CAAC,QAAQ;IAKhB;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAYf;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAWnB,0FAA0F;IAC1F,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,SAAS;IAWjB,kEAAkE;IAClE,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,QAAQ;IAKhB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAepB,qDAAqD;IACrD,OAAO,CAAC,YAAY;IAepB;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK;IA4Cb;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,UAAU;IAmBlB,6EAA6E;IAC7E,OAAO,CAAC,UAAU;IAelB;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAkBxB,yFAAyF;IACzF,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,OAAO;CAGhB;AAoBD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CASlE"}
package/dist/v2/tasks.js CHANGED
@@ -18,6 +18,14 @@
18
18
  * wait for it. A child that ends before it is announced stays unexposed.
19
19
  * Each run of it is the child's foreground work: `running` from its start
20
20
  * to its end, on its stream and mirrored on the parent's `subagent_update`.
21
+ * - A forked skill (`context: fork`, such as `/code-review`) runs as a
22
+ * subagent that no Agent or Task call launched. One that Claude called
23
+ * with the Skill tool is announced on the session that made the call, which
24
+ * stays shown. One that the user typed has no call: it is announced on the
25
+ * root, and its messages name it by `agent_id` only, under an id that no
26
+ * call has (`forked-command-code-review`). Claude Code (2.1.328) holds
27
+ * those until after the task's end, so the child's end waits for them (see
28
+ * {@link SessionTasks.taskEnded}).
21
29
  * - The parent is not shown the Agent call of an announced child: the call's
22
30
  * prompt is the parent's outgoing `session_message` and the child's
23
31
  * incoming one, and a foreground child's answer is its reply to the parent.
@@ -48,7 +56,7 @@ import * as path from "node:path";
48
56
  import { RequestError } from "@agentclientprotocol/sdk/unstable";
49
57
  import { backgroundBashTaskFromToolResult, taskProgressFields } from "../async-tasks.js";
50
58
  import { BackgroundOutputTail, foregroundCommandToolCall, isCommandTool, TaskOutputPoll, } from "../background-output.js";
51
- import { childModelOption, HANDBACK_TOOL, handbackMessage, isNativeSubagentControlTool, launchReply, linkedSessionMessages, mergeSubagentIdentity, responseModelEntry, resumedNativeSubagentId, rfdLabels, sendMessageResume, subagentIdentity, targetAgentId, unexposedControlFallback, withSessionReference, } from "../native-subagents.js";
59
+ import { childModelOption, endsMessageWait, endWaitsForMessages, HANDBACK_TOOL, handbackMessage, isNativeSubagentControlTool, launchReply, linkedSessionMessages, mergeSubagentIdentity, responseModelEntry, resumedNativeSubagentId, rfdLabels, sendMessageResume, subagentIdentity, targetAgentId, unexposedControlFallback, withSessionReference, } from "../native-subagents.js";
52
60
  import { subagentLineage } from "../subagent-history.js";
53
61
  import { streamedTerminals, withRunningTerminal, withRunningToolCall, withStreamedTerminal, } from "../tool-calls/background.js";
54
62
  import { ClientCapabilities } from "../tool-calls/client-capabilities.js";
@@ -56,6 +64,7 @@ import { AcpToolCallRenderer } from "../tool-calls/renderer.js";
56
64
  import { workflowCard, workflowSnapshot } from "../workflow-progress.js";
57
65
  import { ChildConfigurations } from "./child-config.js";
58
66
  import { SessionOutput } from "./stream.js";
67
+ import { REPLAY_COMPLETE } from "./setup.js";
59
68
  import { SubagentReplay } from "./subagent-replay.js";
60
69
  /** The tools whose structured result names the task that the call started. */
61
70
  const TASK_TOOLS = new Set(["Monitor", "Workflow"]);
@@ -78,6 +87,11 @@ export class SessionTasks {
78
87
  pendingByLaunch = new Map();
79
88
  /** The live subagent tasks, by agent id, announced or not. */
80
89
  agents = new Map();
90
+ /**
91
+ * The ends of the runs that wait for their messages (see {@link taskEnded}),
92
+ * by agent id.
93
+ */
94
+ heldEnds = new Map();
81
95
  /** The open permission requests of each subagent, by agent id. */
82
96
  agentRequests = new Map();
83
97
  /** The subagents whose runs a cancel stops, by agent id, until their runs end. */
@@ -164,6 +178,7 @@ export class SessionTasks {
164
178
  * was a child's, which then goes to the child's stream only.
165
179
  */
166
180
  handle(message) {
181
+ this.releaseHeldEnds(message);
167
182
  switch (message.type) {
168
183
  case "system":
169
184
  switch (message.subtype) {
@@ -323,7 +338,12 @@ export class SessionTasks {
323
338
  hasLiveSubagents() {
324
339
  return this.agents.size > 0;
325
340
  }
326
- /** Whether `sessionId` is an announced child session of this root. */
341
+ /**
342
+ * Whether `sessionId` is a child session that this root announced in its
343
+ * current conversation. A child that only a replay announced, or one from
344
+ * before a conversation reset, is not: the client still knows those (see
345
+ * `AnnouncedChildren`).
346
+ */
327
347
  hasChild(sessionId) {
328
348
  return this.children.get(sessionId)?.announced === true;
329
349
  }
@@ -536,6 +556,38 @@ export class SessionTasks {
536
556
  }
537
557
  return true;
538
558
  }
559
+ /**
560
+ * For a resume of the active session that replays: the announcement and
561
+ * the `replay_complete` of each current child that the replay did not
562
+ * announce (`replayed`), parents first. The stored history has no launch of
563
+ * such a child: a forked skill's, whose metadata names no call, or a
564
+ * subagent that Claude launched after the history was written. Its replay
565
+ * is empty, so its `replay_complete` follows its announcement at once.
566
+ *
567
+ * A child is current when it works, when its parent lists it, or when the
568
+ * replay holds something its session sent (`held`), such as the end of a
569
+ * run that ended while the history was read. v2 asks for a child's
570
+ * announcement again on every resume, before any other update of its
571
+ * session, and for a `replay_complete` on every child that is announced
572
+ * before the response. The caller sends these after the root's
573
+ * `replay_complete`, where an announcement is current, and before what the
574
+ * replay held.
575
+ */
576
+ unreplayedChildren(replayed, held) {
577
+ const lists = this.lists();
578
+ return this.parentsFirst()
579
+ .filter((child) => !replayed(child.sessionId) &&
580
+ (held.has(child.sessionId) || this.worksOrListed(child, lists)))
581
+ .flatMap((child) => [
582
+ { sessionId: child.parentSessionId, update: this.announcement(child) },
583
+ { sessionId: child.sessionId, update: REPLAY_COMPLETE },
584
+ ]);
585
+ }
586
+ /** Whether `child` works, or its parent's `background` list (of `lists`) names it. */
587
+ worksOrListed(child, lists) {
588
+ return (child.working ||
589
+ (lists.get(child.parentSessionId) ?? []).some((item) => item.type === "subagent" && item.sessionId === child.sessionId));
590
+ }
539
591
  /**
540
592
  * The current state of the session's work, for a resume of the active
541
593
  * session: each subagent that a session lists, or that works in its
@@ -550,9 +602,7 @@ export class SessionTasks {
550
602
  const lists = this.lists();
551
603
  const visit = (sessionId) => {
552
604
  const listed = lists.get(sessionId) ?? [];
553
- const children = this.parentsFirst().filter((child) => child.parentSessionId === sessionId &&
554
- (child.working ||
555
- listed.some((item) => item.type === "subagent" && item.sessionId === child.sessionId)));
605
+ const children = this.parentsFirst().filter((child) => child.parentSessionId === sessionId && this.worksOrListed(child, lists));
556
606
  for (const child of children) {
557
607
  const state = stateObject(this.childState(child), undefined);
558
608
  if ((lists.get(child.sessionId) ?? []).length === 0) {
@@ -604,6 +654,14 @@ export class SessionTasks {
604
654
  .filter((toolCall) => toolCall.output.sessionId === sessionId)
605
655
  .map((toolCall) => toolCall.toolCallId));
606
656
  }
657
+ /**
658
+ * The root's turn ends: a run whose end still waited for its messages ends
659
+ * before the root's idle, since the turn waited on it. Such a turn ended
660
+ * without a result, as one that a cancel stopped can.
661
+ */
662
+ turnClosed() {
663
+ this.releaseHeldEnds();
664
+ }
607
665
  /**
608
666
  * Claude Code's query ended: its tasks ended with its process. Terminals
609
667
  * exit and background tool calls are cancelled; a child that worked ends
@@ -611,6 +669,7 @@ export class SessionTasks {
611
669
  */
612
670
  queryEnded(error) {
613
671
  this.stopForeground();
672
+ this.releaseHeldEnds();
614
673
  for (const [taskId, terminal] of this.terminals) {
615
674
  terminal.tail?.stop();
616
675
  if (error)
@@ -641,6 +700,7 @@ export class SessionTasks {
641
700
  * its state.
642
701
  */
643
702
  conversationReset() {
703
+ this.releaseHeldEnds();
644
704
  for (const child of [...this.parentsFirst()].reverse()) {
645
705
  if (!child.working)
646
706
  continue;
@@ -742,10 +802,12 @@ export class SessionTasks {
742
802
  if (toolUseId !== undefined) {
743
803
  this.pendingByLaunch.delete(toolUseId);
744
804
  this.childByToolUse.set(toolUseId, child);
745
- // The launch call names the parent. Without one, it is the parent task.
746
- const launch = this.launches.get(toolUseId);
747
- if (launch)
748
- this.announce(child, launch.output.sessionId);
805
+ // The call that launched it names the parent: an Agent or Task call,
806
+ // else a call that a session's stream mapped, such as the Skill call
807
+ // of a forked skill. Without a call, it is the parent task.
808
+ const parent = this.launches.get(toolUseId)?.output.sessionId ?? this.callerOf(toolUseId);
809
+ if (parent !== undefined)
810
+ this.announce(child, parent);
749
811
  }
750
812
  else {
751
813
  // No session update may carry a session id before its announcement.
@@ -846,13 +908,14 @@ export class SessionTasks {
846
908
  */
847
909
  taskEnded(taskId, status, error) {
848
910
  const child = this.children.get(taskId);
911
+ const foreground = this.agents.get(taskId)?.background === false;
849
912
  if (this.agents.delete(taskId))
850
913
  this.host.foregroundRequestsChanged();
851
914
  if (child && !child.announced) {
852
915
  this.withdrawChild(child);
853
916
  }
854
917
  else if (child) {
855
- this.endRun(child, status === "completed"
918
+ const outcome = status === "completed"
856
919
  ? { stopReason: "end_turn" }
857
920
  : status === "stopped"
858
921
  ? { stopReason: "cancelled" }
@@ -861,7 +924,26 @@ export class SessionTasks {
861
924
  ...(error
862
925
  ? { error: { code: RequestError.internalError().code, message: error } }
863
926
  : {}),
864
- });
927
+ };
928
+ const held = this.heldEnds.get(taskId);
929
+ if (held) {
930
+ // A second report of an end that waits can give the text of its failure.
931
+ if (held.stopReason === "error" &&
932
+ !held.error &&
933
+ outcome.stopReason === "error" &&
934
+ outcome.error) {
935
+ this.heldEnds.set(taskId, outcome);
936
+ }
937
+ }
938
+ else if (child.working &&
939
+ endWaitsForMessages({ launched: child.launchToolUseId !== undefined, foreground })) {
940
+ // The run of a child whose messages Claude Code holds until after
941
+ // its end ends once they came (see `releaseHeldEnds`).
942
+ this.heldEnds.set(taskId, outcome);
943
+ }
944
+ else {
945
+ this.endRun(child, outcome);
946
+ }
865
947
  }
866
948
  // A foreground command's output is read no more: a tool call that gets no
867
949
  // result, such as one of a reply that Claude Code took back, would
@@ -912,6 +994,7 @@ export class SessionTasks {
912
994
  // --- Children ---------------------------------------------------------------------
913
995
  /** A new child, not announced, which runs; the messages of its launch that came wait for it. */
914
996
  newChild(sessionId, launchToolUseId, task) {
997
+ const pending = launchToolUseId !== undefined ? (this.pendingByLaunch.get(launchToolUseId) ?? []) : [];
915
998
  const child = {
916
999
  sessionId,
917
1000
  parentSessionId: this.host.sessionId,
@@ -919,7 +1002,8 @@ export class SessionTasks {
919
1002
  task,
920
1003
  announced: false,
921
1004
  awaitedParent: undefined,
922
- pending: launchToolUseId !== undefined ? (this.pendingByLaunch.get(launchToolUseId) ?? []) : [],
1005
+ pending,
1006
+ heard: pending.length > 0,
923
1007
  title: undefined,
924
1008
  description: undefined,
925
1009
  working: true,
@@ -992,16 +1076,53 @@ export class SessionTasks {
992
1076
  this.startRun(child, prompt, toolUseId);
993
1077
  this.host.foregroundRequestsChanged();
994
1078
  }
1079
+ /** The session whose stream mapped the tool call `toolCallId`, if one did. */
1080
+ callerOf(toolCallId) {
1081
+ if (this.rootOutput.holds(toolCallId))
1082
+ return this.host.sessionId;
1083
+ for (const child of this.children.values()) {
1084
+ if (child.output?.holds(toolCallId))
1085
+ return child.sessionId;
1086
+ }
1087
+ return undefined;
1088
+ }
1089
+ /**
1090
+ * Ends the runs whose ends waited for their messages (see {@link taskEnded}),
1091
+ * when `message` ends their wait (see `endsMessageWait`). Without a
1092
+ * message, all of them: the root's turn or the query ended, or the
1093
+ * conversation was reset.
1094
+ */
1095
+ releaseHeldEnds(message) {
1096
+ if (this.heldEnds.size === 0)
1097
+ return;
1098
+ for (const [agentId, outcome] of [...this.heldEnds]) {
1099
+ const child = this.children.get(agentId);
1100
+ if (!endsMessageWait(message, child?.heard === true))
1101
+ continue;
1102
+ this.heldEnds.delete(agentId);
1103
+ if (child)
1104
+ this.endRun(child, outcome);
1105
+ this.publish();
1106
+ }
1107
+ }
995
1108
  /**
996
1109
  * A message of a subagent, by its `parent_tool_use_id`: it goes to the
997
- * child's stream, or waits for the child's announcement. A message of an
998
- * agent that no known call launched is the root's.
1110
+ * child's stream, or waits for the child's announcement. One whose
1111
+ * `parent_tool_use_id` is no Agent or Task call goes by its `agent_id`: a
1112
+ * forked skill that the user typed sends `forked-command-<skill>` for every
1113
+ * run of the skill. A message of an agent that neither names is the root's.
999
1114
  */
1000
1115
  childMessage(message) {
1001
1116
  const launchId = message.parent_tool_use_id;
1002
1117
  if (launchId === null)
1003
1118
  return false;
1004
- const child = this.childByToolUse.get(launchId);
1119
+ const agentId = message.agent_id;
1120
+ const child = this.childByToolUse.get(launchId) ??
1121
+ (typeof agentId === "string" && !this.launches.has(launchId)
1122
+ ? this.children.get(agentId)
1123
+ : undefined);
1124
+ if (child)
1125
+ child.heard = true;
1005
1126
  if (child?.announced) {
1006
1127
  this.deliver(child, message);
1007
1128
  return true;
@@ -1068,8 +1189,13 @@ export class SessionTasks {
1068
1189
  update: { sessionUpdate: "state_update", ...state },
1069
1190
  });
1070
1191
  const prompt = child.task.prompt ?? identity?.prompt;
1071
- if (prompt)
1072
- this.sendPrompt(child, prompt, child.launchToolUseId, parentSessionId, true);
1192
+ // The prompt replaces an Agent or Task call in the parent's transcript.
1193
+ // Another call that launched the child, such as a Skill call, stays
1194
+ // shown there, so the prompt is the child's incoming message only.
1195
+ const replacesCall = child.launchToolUseId !== undefined && this.launches.has(child.launchToolUseId);
1196
+ if (prompt) {
1197
+ this.sendPrompt(child, prompt, child.launchToolUseId, parentSessionId, replacesCall);
1198
+ }
1073
1199
  // What its hooks reported before, after the prompt.
1074
1200
  this.publishConfiguration(child, undefined);
1075
1201
  const pending = child.pending;
@@ -1149,9 +1275,11 @@ export class SessionTasks {
1149
1275
  /**
1150
1276
  * `notification`, an update that the client is shown on the session
1151
1277
  * `shownOn`, with a `session` reference when it is of a TaskStop or
1152
- * SendMessage call that names an announced child by its agent id, or of a
1278
+ * SendMessage call that names an announced child by its agent id, of a
1153
1279
  * SendMessage call that resumed one and stays shown (see
1154
- * {@link requestShows}), as on v1 (`NativeSubagentRuntime.withTarget`).
1280
+ * {@link requestShows}), or of the call that launched one and is no Agent
1281
+ * or Task call, such as the Skill call of a forked skill, as on v1
1282
+ * (`NativeSubagentRuntime.withTarget`).
1155
1283
  */
1156
1284
  withTarget(notification, shownOn) {
1157
1285
  const { update } = notification;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-call.d.ts","sourceRoot":"","sources":["../../src/v2/tool-call.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAmB,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnG,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;AAE7D,KAAK,gBAAgB,GAAG,EAAE,CAAC,cAAc,GAAG;IAAE,aAAa,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAElF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAE3E;AAcD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,g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