@agentclientprotocol/claude-agent-acp 0.85.2-preview.9 → 0.86.1-preview.1

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 (59) hide show
  1. package/dist/acp-agent.d.ts +67 -21
  2. package/dist/acp-agent.d.ts.map +1 -1
  3. package/dist/acp-agent.js +264 -68
  4. package/dist/async-tasks.d.ts +52 -3
  5. package/dist/async-tasks.d.ts.map +1 -1
  6. package/dist/async-tasks.js +185 -42
  7. package/dist/clear-context-coordinator.d.ts +1 -0
  8. package/dist/clear-context-coordinator.d.ts.map +1 -1
  9. package/dist/clear-context-coordinator.js +2 -1
  10. package/dist/diff.d.ts +45 -8
  11. package/dist/diff.d.ts.map +1 -1
  12. package/dist/diff.js +111 -30
  13. package/dist/native-subagents.d.ts +7 -4
  14. package/dist/native-subagents.d.ts.map +1 -1
  15. package/dist/native-subagents.js +22 -5
  16. package/dist/permissions/presentation.d.ts +17 -2
  17. package/dist/permissions/presentation.d.ts.map +1 -1
  18. package/dist/permissions/presentation.js +4 -0
  19. package/dist/session-config-ids.d.ts +1 -0
  20. package/dist/session-config-ids.d.ts.map +1 -1
  21. package/dist/session-config-ids.js +1 -0
  22. package/dist/tool-calls/background.d.ts +5 -2
  23. package/dist/tool-calls/background.d.ts.map +1 -1
  24. package/dist/tool-calls/background.js +6 -11
  25. package/dist/tool-calls/client-capabilities.d.ts +20 -2
  26. package/dist/tool-calls/client-capabilities.d.ts.map +1 -1
  27. package/dist/tool-calls/client-capabilities.js +14 -4
  28. package/dist/tool-calls/facts.d.ts +8 -1
  29. package/dist/tool-calls/facts.d.ts.map +1 -1
  30. package/dist/tool-calls/renderer.d.ts +5 -1
  31. package/dist/tool-calls/renderer.d.ts.map +1 -1
  32. package/dist/tool-calls/renderer.js +14 -3
  33. package/dist/tool-calls/reporters/bash.d.ts.map +1 -1
  34. package/dist/tool-calls/reporters/bash.js +32 -5
  35. package/dist/tool-calls/reporters/file-edit.d.ts +1 -1
  36. package/dist/tool-calls/reporters/file-edit.d.ts.map +1 -1
  37. package/dist/tool-calls/reporters/file-edit.js +20 -14
  38. package/dist/v2/agent.d.ts +2 -0
  39. package/dist/v2/agent.d.ts.map +1 -1
  40. package/dist/v2/agent.js +109 -14
  41. package/dist/v2/initialize.d.ts +2 -5
  42. package/dist/v2/initialize.d.ts.map +1 -1
  43. package/dist/v2/initialize.js +42 -11
  44. package/dist/v2/permission.d.ts +25 -0
  45. package/dist/v2/permission.d.ts.map +1 -0
  46. package/dist/v2/permission.js +38 -0
  47. package/dist/v2/session-update.d.ts +6 -0
  48. package/dist/v2/session-update.d.ts.map +1 -1
  49. package/dist/v2/session-update.js +19 -0
  50. package/dist/v2/session.d.ts +29 -4
  51. package/dist/v2/session.d.ts.map +1 -1
  52. package/dist/v2/session.js +41 -6
  53. package/dist/v2/terminal.d.ts +42 -0
  54. package/dist/v2/terminal.d.ts.map +1 -0
  55. package/dist/v2/terminal.js +95 -0
  56. package/dist/v2/tool-call.d.ts +38 -0
  57. package/dist/v2/tool-call.d.ts.map +1 -0
  58. package/dist/v2/tool-call.js +49 -0
  59. package/package.json +1 -1
@@ -69,7 +69,9 @@ export declare class AsyncTaskRuntime {
69
69
  /** `notices`: the client can present `notice` updates, so the stop
70
70
  * acknowledgement need not be a transcript line. `routeOf`: the route of
71
71
  * the tasks that a tool call in another session started, for example in
72
- * a native subagent session. */
72
+ * a native subagent session. `toolNameOf`: the name of the tool of a tool
73
+ * call, or `undefined` when the tool call is unknown. A task that a
74
+ * `Monitor` tool call started is ignored. */
73
75
  private readonly options;
74
76
  /**
75
77
  * One registry owns both active tasks and terminal tombstones. Keeping an
@@ -77,14 +79,24 @@ export declare class AsyncTaskRuntime {
77
79
  * a command was backgrounded can arrive after its terminal SDK edge.
78
80
  */
79
81
  private readonly tasks;
82
+ /**
83
+ * The task output paths in the text of each tool result, by tool call
84
+ * id. A task whose id and tool call are known takes its output path from
85
+ * here. The tool result can come before or after the SDK names the task.
86
+ * The oldest entries are dropped.
87
+ */
88
+ private readonly outputPathsByToolCall;
80
89
  constructor(enabled: boolean, sessionId: string, publish: Publish,
81
90
  /** `notices`: the client can present `notice` updates, so the stop
82
91
  * acknowledgement need not be a transcript line. `routeOf`: the route of
83
92
  * the tasks that a tool call in another session started, for example in
84
- * a native subagent session. */
93
+ * a native subagent session. `toolNameOf`: the name of the tool of a tool
94
+ * call, or `undefined` when the tool call is unknown. A task that a
95
+ * `Monitor` tool call started is ignored. */
85
96
  options?: {
86
97
  notices?: boolean;
87
98
  routeOf?: (toolCallId: string) => Route | undefined;
99
+ toolNameOf?: (toolCallId: string) => string | undefined;
88
100
  });
89
101
  taskStarted(message: AsyncTaskStarted): Promise<void>;
90
102
  taskBackgrounded(message: AsyncTaskStarted): Promise<void>;
@@ -107,6 +119,14 @@ export declare class AsyncTaskRuntime {
107
119
  claimStop(taskId: string): boolean;
108
120
  releaseStop(taskId: string): void;
109
121
  taskStopped(taskId: string): Promise<void>;
122
+ /** Whether a task of the tool call went to the background, so the client gets it. */
123
+ isBackgroundedToolCall(toolCallId: string): boolean;
124
+ /**
125
+ * Reads the tool results in `content` for the output path of a known task.
126
+ * Only a path that ends with `tasks/<task id>.output` in the result of
127
+ * the task's own tool call counts. A tool result never creates a task.
128
+ */
129
+ toolResults(content: unknown): Promise<void>;
110
130
  /**
111
131
  * Sends the spawn of each held task without a tool call id. The prompt
112
132
  * result ends the model turn, and the result of the tool call that started a
@@ -114,10 +134,20 @@ export declare class AsyncTaskRuntime {
114
134
  */
115
135
  releaseHeld(): Promise<void>;
116
136
  clear(): void;
137
+ /**
138
+ * Marks a task that the client never sees. Only a task that is not announced
139
+ * can become ignored, so the client never holds a task without its end.
140
+ */
141
+ private ignore;
117
142
  private task;
118
143
  private mergeStarted;
119
144
  /** Keeps the first tool call id that a later SDK message brings. */
120
145
  private mergeToolCallId;
146
+ /**
147
+ * Takes the output path from the result of the task's tool call when no
148
+ * structured source gave one. A structured path later replaces it.
149
+ */
150
+ private mergeToolResultPath;
121
151
  /** Sends an update of an announced task. A held task sends it after its spawn. */
122
152
  private whenAnnounced;
123
153
  private mergePatch;
@@ -131,6 +161,11 @@ export declare class AsyncTaskRuntime {
131
161
  * backgrounded command. A held task gets its spawn without the id when it
132
162
  * ends first, or when the prompt result ends the model turn
133
163
  * ({@link releaseHeld}). No guess by the command text binds a task.
164
+ *
165
+ * A task that a `Monitor` tool call started is ignored: Monitor streams its
166
+ * output to the model only, so the task has nothing for the client. The
167
+ * tool_use streams before the tool runs, so the tool name is known when the
168
+ * spawn has the tool call id.
134
169
  */
135
170
  private announce;
136
171
  private finish;
@@ -145,10 +180,24 @@ export declare class AsyncTaskRuntime {
145
180
  /** Publishes an update of the task in the session that owns the task. */
146
181
  private send;
147
182
  }
148
- /** Recovers background Bash lifecycle data exposed only on its tool result. */
183
+ /**
184
+ * Recovers a background Bash task from the structured `backgroundTaskId` of
185
+ * its tool result. The text of a tool result never gives a task id: a
186
+ * foreground command can print any text.
187
+ */
149
188
  export declare function backgroundBashTaskFromToolResult(content: unknown, toolUseResult: unknown, toolUses: Record<string, {
150
189
  name: string;
151
190
  input: unknown;
152
191
  }>): AsyncTaskStarted | undefined;
192
+ /**
193
+ * The Bash tool calls in `content` whose command went to the background. Only
194
+ * structured data counts: the task from the structured tool result, a task
195
+ * that the runtime knows for the tool call, or a `run_in_background` input of
196
+ * a call that did not fail.
197
+ */
198
+ export declare function backgroundedBashToolCallIds(content: unknown, toolUses: Record<string, {
199
+ name: string;
200
+ input: unknown;
201
+ }>, runtime: AsyncTaskRuntime, structuredTask?: AsyncTaskStarted): Set<string>;
153
202
  export {};
154
203
  //# sourceMappingURL=async-tasks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"async-tasks.d.ts","sourceRoot":"","sources":["../src/async-tasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,E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;IACG,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBlD;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAOlC,KAAK,IAAI,IAAI;IAKb;;;OAGG;IACH,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,IAAI;IAwBZ,OAAO,CAAC,YAAY;IAwBpB,oEAAoE;IACpE,OAAO,CAAC,eAAe;IAQvB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAM3B,kFAAkF;YACpE,aAAa;IAK3B,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,mBAAmB;IAQ3B;;;;;;;;;;;;;OAaG;YACW,QAAQ;YAuCR,MAAM;YAiCN,eAAe;IAa7B;;;OAGG;YACW,eAAe;IAqB7B,wFAAwF;YAC1E,YAAY;IAmB1B,yEAAyE;YAC3D,IAAI;CAKnB;AAyBD;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,OAAO,EACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,GACzD,gBAAgB,GAAG,SAAS,CAuC9B;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,EAC1D,OAAO,EAAE,gBAAgB,EACzB,cAAc,CAAC,EAAE,gBAAgB,GAChC,GAAG,CAAC,MAAM,CAAC,CAmBb"}
@@ -1,5 +1,6 @@
1
1
  import { AIR_ASYNC_TASKS_CAPABILITY, clientSupportsAirCapability } from "./air-extension.js";
2
2
  import { noticeOrTranscriptUpdate } from "./session-notices.js";
3
+ const MAX_TOOL_RESULT_PATHS = 500;
3
4
  export function clientSupportsAsyncTasks(capabilities) {
4
5
  return clientSupportsAirCapability(capabilities, AIR_ASYNC_TASKS_CAPABILITY);
5
6
  }
@@ -15,11 +16,20 @@ export class AsyncTaskRuntime {
15
16
  * a command was backgrounded can arrive after its terminal SDK edge.
16
17
  */
17
18
  tasks = new Map();
19
+ /**
20
+ * The task output paths in the text of each tool result, by tool call
21
+ * id. A task whose id and tool call are known takes its output path from
22
+ * here. The tool result can come before or after the SDK names the task.
23
+ * The oldest entries are dropped.
24
+ */
25
+ outputPathsByToolCall = new Map();
18
26
  constructor(enabled, sessionId, publish,
19
27
  /** `notices`: the client can present `notice` updates, so the stop
20
28
  * acknowledgement need not be a transcript line. `routeOf`: the route of
21
29
  * the tasks that a tool call in another session started, for example in
22
- * a native subagent session. */
30
+ * a native subagent session. `toolNameOf`: the name of the tool of a tool
31
+ * call, or `undefined` when the tool call is unknown. A task that a
32
+ * `Monitor` tool call started is ignored. */
23
33
  options = {}) {
24
34
  this.enabled = enabled;
25
35
  this.sessionId = sessionId;
@@ -33,8 +43,8 @@ export class AsyncTaskRuntime {
33
43
  if (!taskId)
34
44
  return;
35
45
  const task = this.task(taskId);
36
- if (isSubagentTask(message)) {
37
- task.ignored = true;
46
+ if (isSubagentTask(message) || isMonitorTask(message)) {
47
+ this.ignore(task);
38
48
  return;
39
49
  }
40
50
  const previousOutputFilePath = task.outputFilePath;
@@ -57,8 +67,8 @@ export class AsyncTaskRuntime {
57
67
  if (!taskId)
58
68
  return;
59
69
  const task = this.task(taskId);
60
- if (isSubagentTask(message)) {
61
- task.ignored = true;
70
+ if (isSubagentTask(message) || isMonitorTask(message)) {
71
+ this.ignore(task);
62
72
  return;
63
73
  }
64
74
  const previousOutputFilePath = task.outputFilePath;
@@ -205,8 +215,9 @@ export class AsyncTaskRuntime {
205
215
  const task = this.task(taskId);
206
216
  if (task.ignored || isTerminal(task.state))
207
217
  continue;
208
- if (field(item, "taskType", "task_type") === "local_agent") {
209
- task.ignored = true;
218
+ const levelTaskType = field(item, "taskType", "task_type");
219
+ if (levelTaskType === "local_agent" || levelTaskType === "local_monitor") {
220
+ this.ignore(task);
210
221
  continue;
211
222
  }
212
223
  if (!task.startedObserved) {
@@ -289,6 +300,44 @@ export class AsyncTaskRuntime {
289
300
  // its tool call), not whether the agent may answer a direct user action.
290
301
  await this.send(task, noticeOrTranscriptUpdate({ severity: "info", title: "Task stopped by user", description: `${task.name}.` }, this.options.notices ?? false));
291
302
  }
303
+ /** Whether a task of the tool call went to the background, so the client gets it. */
304
+ isBackgroundedToolCall(toolCallId) {
305
+ for (const task of this.tasks.values()) {
306
+ if (task.toolCallId === toolCallId && !task.ignored && (task.announced || task.held)) {
307
+ return true;
308
+ }
309
+ }
310
+ return false;
311
+ }
312
+ /**
313
+ * Reads the tool results in `content` for the output path of a known task.
314
+ * Only a path that ends with `tasks/<task id>.output` in the result of
315
+ * the task's own tool call counts. A tool result never creates a task.
316
+ */
317
+ async toolResults(content) {
318
+ if (!this.enabled || !Array.isArray(content))
319
+ return;
320
+ for (const result of content.flatMap(toolResultBlock)) {
321
+ const text = textContent(result.content);
322
+ const paths = text ? taskOutputPaths(text) : [];
323
+ if (paths.length === 0)
324
+ continue;
325
+ this.outputPathsByToolCall.delete(result.toolUseId);
326
+ this.outputPathsByToolCall.set(result.toolUseId, paths);
327
+ if (this.outputPathsByToolCall.size > MAX_TOOL_RESULT_PATHS) {
328
+ const oldest = this.outputPathsByToolCall.keys().next().value;
329
+ if (oldest !== undefined)
330
+ this.outputPathsByToolCall.delete(oldest);
331
+ }
332
+ for (const task of this.tasks.values()) {
333
+ if (task.toolCallId !== result.toolUseId || task.ignored || task.outputFilePath)
334
+ continue;
335
+ this.mergeToolResultPath(task);
336
+ if (task.outputFilePath && task.announced)
337
+ await this.publishMetadata(task);
338
+ }
339
+ }
340
+ }
292
341
  /**
293
342
  * Sends the spawn of each held task without a tool call id. The prompt
294
343
  * result ends the model turn, and the result of the tool call that started a
@@ -304,6 +353,18 @@ export class AsyncTaskRuntime {
304
353
  }
305
354
  clear() {
306
355
  this.tasks.clear();
356
+ this.outputPathsByToolCall.clear();
357
+ }
358
+ /**
359
+ * Marks a task that the client never sees. Only a task that is not announced
360
+ * can become ignored, so the client never holds a task without its end.
361
+ */
362
+ ignore(task) {
363
+ if (task.announced)
364
+ return;
365
+ task.ignored = true;
366
+ task.held = false;
367
+ task.deferred = [];
307
368
  }
308
369
  task(taskId) {
309
370
  let task = this.tasks.get(taskId);
@@ -354,10 +415,23 @@ export class AsyncTaskRuntime {
354
415
  const toolCallId = nonBlankString(field(message, "toolCallId", "tool_use_id"));
355
416
  if (toolCallId)
356
417
  task.toolCallId = toolCallId;
418
+ this.mergeToolResultPath(task);
357
419
  }
358
420
  /** Keeps the first tool call id that a later SDK message brings. */
359
421
  mergeToolCallId(task, value) {
360
422
  task.toolCallId ??= nonBlankString(field(value, "toolCallId", "tool_use_id"));
423
+ this.mergeToolResultPath(task);
424
+ }
425
+ /**
426
+ * Takes the output path from the result of the task's tool call when no
427
+ * structured source gave one. A structured path later replaces it.
428
+ */
429
+ mergeToolResultPath(task) {
430
+ if (task.outputFilePath || !task.toolCallId)
431
+ return;
432
+ const paths = this.outputPathsByToolCall.get(task.toolCallId);
433
+ if (paths)
434
+ task.outputFilePath = outputFilePathOf(paths, task.id);
361
435
  }
362
436
  /** Sends an update of an announced task. A held task sends it after its spawn. */
363
437
  async whenAnnounced(task, send) {
@@ -397,10 +471,20 @@ export class AsyncTaskRuntime {
397
471
  * backgrounded command. A held task gets its spawn without the id when it
398
472
  * ends first, or when the prompt result ends the model turn
399
473
  * ({@link releaseHeld}). No guess by the command text binds a task.
474
+ *
475
+ * A task that a `Monitor` tool call started is ignored: Monitor streams its
476
+ * output to the model only, so the task has nothing for the client. The
477
+ * tool_use streams before the tool runs, so the tool name is known when the
478
+ * spawn has the tool call id.
400
479
  */
401
480
  async announce(task, options = {}) {
402
481
  if (task.announced || task.ignored)
403
482
  return;
483
+ const toolName = task.toolCallId ? this.options.toolNameOf?.(task.toolCallId) : undefined;
484
+ if (toolName !== undefined && HIDDEN_TASK_TOOLS.has(toolName)) {
485
+ this.ignore(task);
486
+ return;
487
+ }
404
488
  if (!task.toolCallId && !options.withoutToolCall && !isTerminal(task.state)) {
405
489
  task.held = true;
406
490
  return;
@@ -538,7 +622,11 @@ function recordPublished(task, fields) {
538
622
  task.published.set(key, JSON.stringify(value));
539
623
  }
540
624
  }
541
- /** Recovers background Bash lifecycle data exposed only on its tool result. */
625
+ /**
626
+ * Recovers a background Bash task from the structured `backgroundTaskId` of
627
+ * its tool result. The text of a tool result never gives a task id: a
628
+ * foreground command can print any text.
629
+ */
542
630
  export function backgroundBashTaskFromToolResult(content, toolUseResult, toolUses) {
543
631
  if (!Array.isArray(content))
544
632
  return undefined;
@@ -547,12 +635,7 @@ export function backgroundBashTaskFromToolResult(content, toolUseResult, toolUse
547
635
  if (bashResults.length === 0)
548
636
  return undefined;
549
637
  const backgroundResults = structuredBackgroundResults(toolUseResult, toolUses);
550
- const distinctTaskIds = new Set([
551
- ...backgroundResults.map((result) => result.taskId),
552
- ...bashResults
553
- .map((result) => backgroundTaskIdFromText(result.content))
554
- .filter((taskId) => taskId !== undefined),
555
- ]);
638
+ const distinctTaskIds = new Set(backgroundResults.map((result) => result.taskId));
556
639
  if (distinctTaskIds.size !== 1)
557
640
  return undefined;
558
641
  const taskId = [...distinctTaskIds][0];
@@ -583,17 +666,31 @@ export function backgroundBashTaskFromToolResult(content, toolUseResult, toolUse
583
666
  toolCallId: match.toolUseId,
584
667
  };
585
668
  }
586
- function backgroundTaskIdFromText(content) {
587
- const text = textContent(content);
588
- if (!text)
589
- return undefined;
590
- const marker = "Command running in background with ID: ";
591
- const start = text.indexOf(marker);
592
- if (start < 0)
593
- return undefined;
594
- const valueStart = start + marker.length;
595
- const valueEnd = text.indexOf(".", valueStart);
596
- return valueEnd < 0 ? undefined : nonBlankString(text.slice(valueStart, valueEnd));
669
+ /**
670
+ * The Bash tool calls in `content` whose command went to the background. Only
671
+ * structured data counts: the task from the structured tool result, a task
672
+ * that the runtime knows for the tool call, or a `run_in_background` input of
673
+ * a call that did not fail.
674
+ */
675
+ export function backgroundedBashToolCallIds(content, toolUses, runtime, structuredTask) {
676
+ const ids = new Set();
677
+ if (!runtime.enabled || !Array.isArray(content))
678
+ return ids;
679
+ const structuredToolCallId = structuredTask
680
+ ? nonBlankString(field(structuredTask, "toolCallId", "tool_use_id"))
681
+ : undefined;
682
+ for (const result of content.flatMap(toolResultBlock)) {
683
+ const toolUse = toolUses[result.toolUseId];
684
+ if (toolUse?.name !== "Bash")
685
+ continue;
686
+ const input = isRecord(toolUse.input) ? toolUse.input : undefined;
687
+ if (result.toolUseId === structuredToolCallId ||
688
+ runtime.isBackgroundedToolCall(result.toolUseId) ||
689
+ (input?.run_in_background === true && !result.isError)) {
690
+ ids.add(result.toolUseId);
691
+ }
692
+ }
693
+ return ids;
597
694
  }
598
695
  function structuredBackgroundResults(value, toolUses, hintedToolUseId, seen = new Set()) {
599
696
  if (typeof value !== "object" || value === null || seen.has(value))
@@ -618,26 +715,67 @@ function toolResultBlock(value) {
618
715
  if (!isRecord(value) || value.type !== "tool_result")
619
716
  return [];
620
717
  const toolUseId = nonBlankString(field(value, "toolUseId", "tool_use_id"));
621
- return toolUseId ? [{ toolUseId, content: value.content }] : [];
718
+ return toolUseId
719
+ ? [
720
+ {
721
+ toolUseId,
722
+ content: value.content,
723
+ isError: field(value, "isError", "is_error") === true,
724
+ },
725
+ ]
726
+ : [];
622
727
  }
623
728
  function asyncTaskOutputFilePath(content, taskId) {
624
729
  const text = textContent(content);
625
- if (!text)
626
- return undefined;
627
- const marker = "Output is being written to: ";
628
- const start = text.indexOf(marker);
629
- if (start < 0)
630
- return undefined;
631
- const valueStart = start + marker.length;
632
- const valueEnd = text.indexOf(". You will be notified", valueStart);
633
- if (valueEnd < 0)
634
- return undefined;
635
- const path = text.slice(valueStart, valueEnd).trim();
636
- const expectedPosixSuffix = `/tasks/${taskId}.output`;
637
- const expectedWindowsSuffix = `\\tasks\\${taskId}.output`;
638
- return path.endsWith(expectedPosixSuffix) || path.endsWith(expectedWindowsSuffix)
639
- ? path
640
- : undefined;
730
+ return text ? outputFilePathOf(taskOutputPaths(text), taskId) : undefined;
731
+ }
732
+ /**
733
+ * The end of a task output path: `tasks/<id>.output`, followed by a sentence
734
+ * period, whitespace or the end of the text. Claude Code writes the output of
735
+ * a background task there.
736
+ */
737
+ const TASK_OUTPUT_SUFFIX = /[/\\]tasks[/\\][^\s/\\]+?\.output(?=\.(?!\w)|\s|$)/g;
738
+ /** An absolute POSIX, Windows drive or UNC path. */
739
+ const ABSOLUTE_PATH = /^(?:\/|[A-Za-z]:[\\/]|\\\\)/;
740
+ /**
741
+ * The task output paths in a tool result text. Each text of Claude Code puts
742
+ * the path after "Output is being written to: ", so a path starts after the
743
+ * nearest `": "` before its end. A drive colon has no space after it, so a
744
+ * path can hold spaces and a drive. The search for the start stops at a line
745
+ * break and at the end of the previous path end, so a path never crosses a
746
+ * line or holds another path. Each character is read at most once, so the
747
+ * parse is linear in the text length. A path that is not absolute does not
748
+ * count.
749
+ */
750
+ function taskOutputPaths(text) {
751
+ const paths = [];
752
+ let previousEnd = 0;
753
+ for (const match of text.matchAll(TASK_OUTPUT_SUFFIX)) {
754
+ const end = match.index + match[0].length;
755
+ let start = -1;
756
+ for (let i = match.index - 1; i >= previousEnd; i--) {
757
+ const char = text[i];
758
+ if (char === "\n" || char === "\r")
759
+ break;
760
+ if (char === ":" && text[i + 1] === " ") {
761
+ start = i + 2;
762
+ break;
763
+ }
764
+ }
765
+ previousEnd = end;
766
+ if (start < 0)
767
+ continue;
768
+ const path = text.slice(start, end);
769
+ if (ABSOLUTE_PATH.test(path))
770
+ paths.push(path);
771
+ }
772
+ return paths;
773
+ }
774
+ /** The output path of the task `taskId` among the paths, if one names it. */
775
+ function outputFilePathOf(paths, taskId) {
776
+ const posix = `/tasks/${taskId}.output`;
777
+ const windows = `\\tasks\\${taskId}.output`;
778
+ return paths.find((path) => path.endsWith(posix) || path.endsWith(windows));
641
779
  }
642
780
  function textContent(value) {
643
781
  if (typeof value === "string")
@@ -671,6 +809,11 @@ function isBackgroundTask(isBackgrounded, taskType) {
671
809
  return false;
672
810
  return taskType !== "local_bash" && taskType !== "local_agent";
673
811
  }
812
+ /** The tools whose async tasks the client never sees. */
813
+ const HIDDEN_TASK_TOOLS = new Set(["Monitor"]);
814
+ function isMonitorTask(message) {
815
+ return field(message, "taskType", "task_type") === "local_monitor";
816
+ }
674
817
  function isSubagentTask(message) {
675
818
  return (field(message, "subagentType", "subagent_type") !== undefined ||
676
819
  field(message, "taskType", "task_type") === "local_agent");
@@ -29,6 +29,7 @@ export type ClearContextSession<Turn extends ClearContextTurn = ClearContextTurn
29
29
  currentModelId: string;
30
30
  };
31
31
  configOptions: SessionConfigOption[];
32
+ currentAgent: string;
32
33
  fastModeEnabled: boolean;
33
34
  effortPinnedLevel?: string;
34
35
  activeTurn?: Turn | null;
@@ -1 +1 @@
1
- {"version":3,"file":"clear-context-coordinator.d.ts","sourceRoot":"","sources":["../src/clear-context-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACvF,OAAO,KAAK,EAGV,cAAc,EACd,cAAc,EACf,MAAM,gCAAgC,CAAC;AAGxC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;CACtB,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAA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gB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACzC,cAAc,CACZ,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,cAAc,CAAA;KAAE,GACnE,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,mBAAmB,CACjB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,cAAc,EACpB,aAAa,EAAE,mBAAmB,EAAE,GACnC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,CAAC;IACzF,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1D,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CACjD,CAAC;AAiCF;;kEAEkE;AAClE,wBAAsB,0BAA0B,CAC9C,IAAI,SAAS,gBAAgB,EAC7B,OAAO,SAAS,mBAAmB,CAAC,IAAI,CAAC,EAEzC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,OAAO,EACnB,KAAK,EAAE,iBAAiB,EACxB,IAAI,EAAE,2BAA2B,CAAC,OAAO,EAAE,IAAI,CAAC,EAChD,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAkDf"}
@@ -1,4 +1,4 @@
1
- import { DEFAULT_MODEL_ID } from "./session-config-ids.js";
1
+ import { DEFAULT_AGENT_ID, DEFAULT_MODEL_ID } from "./session-config-ids.js";
2
2
  function restartParams(session) {
3
3
  const originalParams = session.creationParams ?? { cwd: session.cwd, mcpServers: [] };
4
4
  const originalMeta = originalParams._meta;
@@ -18,6 +18,7 @@ function restartParams(session) {
18
18
  ...(session.models.currentModelId !== DEFAULT_MODEL_ID
19
19
  ? { model: session.models.currentModelId }
20
20
  : {}),
21
+ ...(session.currentAgent !== DEFAULT_AGENT_ID ? { agent: session.currentAgent } : {}),
21
22
  ...(session.effortPinnedLevel !== undefined
22
23
  ? { effort: session.effortPinnedLevel }
23
24
  : {}),
package/dist/diff.d.ts CHANGED
@@ -23,6 +23,17 @@ interface PatchHunk {
23
23
  }
24
24
  /** The kind of file change that a git patch describes. */
25
25
  type FileChange = "create" | "update";
26
+ /**
27
+ * The diff that carries an exact patch: AIR's `diffPatch` extension of a v1
28
+ * diff, or an ACP v2 diff.
29
+ */
30
+ export type PatchForm = "air" | "v2";
31
+ /**
32
+ * How a git patch names its file. `git` is git's own form: the leading slash
33
+ * dropped and the `a/` and `b/` prefixes added. `absolute` is the form of an
34
+ * ACP v2 `git_patch`, whose paths must be absolute: the path itself.
35
+ */
36
+ type GitPatchPaths = "git" | "absolute";
26
37
  /**
27
38
  * Builds the exact patch shown before Claude runs an Edit or Write tool.
28
39
  *
@@ -35,14 +46,14 @@ type FileChange = "create" | "update";
35
46
  * normalizes quotes or fails.
36
47
  *
37
48
  * A Write always gets content that shows the change: the patch, the standard
38
- * diff of a text that cannot have an exact patch, or a notice that the Write
39
- * overwrites a file that the adapter cannot show.
49
+ * diff (in v2, the change alone) of a text that cannot have an exact patch, or
50
+ * a notice that the Write overwrites a file that the adapter cannot show.
40
51
  *
41
52
  * The preview uses the tool input as it is. Claude can still remove the
42
53
  * trailing whitespace of a line before it writes. The PostToolUse hook then
43
54
  * sends the patch of the written file.
44
55
  */
45
- export declare function previewPatchContent(toolName: string, input: Record<string, unknown>, cwd?: string): Promise<ToolCallContent[] | undefined>;
56
+ export declare function previewPatchContent(toolName: string, input: Record<string, unknown>, cwd?: string, form?: PatchForm): Promise<ToolCallContent[] | undefined>;
46
57
  /**
47
58
  * Builds the git patch for a finished Edit or Write from the file on disk.
48
59
  *
@@ -54,7 +65,7 @@ export declare function previewPatchContent(toolName: string, input: Record<stri
54
65
  * A written file that contains a CR or a byte order mark is declined, because
55
66
  * Claude removed those bytes from `originalFile`.
56
67
  */
57
- export declare function patchUpdateFromDiffToolResponse(toolResponse: unknown): Promise<{
68
+ export declare function patchUpdateFromDiffToolResponse(toolResponse: unknown, form?: PatchForm): Promise<{
58
69
  content: ToolCallContent[];
59
70
  locations: ToolCallLocation[];
60
71
  } | undefined>;
@@ -69,13 +80,39 @@ export declare function toolUpdateFromDiffToolResponse(toolResponse: unknown): {
69
80
  content?: ToolCallContent[];
70
81
  locations?: ToolCallLocation[];
71
82
  };
83
+ /**
84
+ * The ACP v2 diff of a finished Edit or Write: the exact patch of
85
+ * {@link patchUpdateFromDiffToolResponse} when it can be built, else the
86
+ * change with a patch from what the toolResponse holds.
87
+ *
88
+ * The fallback patch of an update comes from the `structuredPatch`, which is
89
+ * display data (see {@link patchUpdateFromDiffToolResponse}). That is enough
90
+ * for a v2 patch, which is renderable text, not a patch to apply. An update
91
+ * without hunks, such as one whose previous content was too large to diff,
92
+ * gets the change alone. An Edit with an empty `old_string` reports the same
93
+ * response for a created file and a filled empty one, so it gets no diff.
94
+ */
95
+ export declare function v2UpdateFromDiffToolResponse(toolResponse: unknown): Promise<{
96
+ content?: ToolCallContent[];
97
+ locations?: ToolCallLocation[];
98
+ }>;
72
99
  /**
73
100
  * The text of one git patch for `filePath`.
74
101
  *
75
- * The headers follow `git diff`: the path loses its leading slash, gets the
76
- * `a/` and `b/` prefixes, and is quoted when git would quote it. A created
77
- * file gets its mode line and a `/dev/null` side.
102
+ * The headers follow `git diff`: the path is quoted when git would quote it,
103
+ * and a created file gets its mode line and a `/dev/null` side. With `git`
104
+ * paths, the path loses its leading slash and gets the `a/` and `b/` prefixes.
105
+ */
106
+ export declare function gitPatchText(filePath: string, change: FileChange, hunks: PatchHunk[], paths?: GitPatchPaths): string;
107
+ /**
108
+ * The ACP v2 diff of a change to the text file `filePath`: the change and,
109
+ * given hunks, its git patch.
110
+ *
111
+ * The agent builds tool call content in v1 types, and v1 cannot express a v2
112
+ * diff, so the diff travels as v1 content. Nothing in the agent reads inside a
113
+ * diff, and only a v2 client gets one: the v2 surface sends it as it is
114
+ * (`src/v2/tool-call.ts`).
78
115
  */
79
- export declare function gitPatchText(filePath: string, change: FileChange, hunks: PatchHunk[]): string;
116
+ export declare function v2DiffContent(filePath: string, change: FileChange, hunks?: PatchHunk[]): ToolCallContent;
80
117
  export {};
81
118
  //# sourceMappingURL=diff.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAQ7E;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,QAAc,CAAC;AAkBhD;;;;;GAKG;AACH,UAAU,SAAS;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AA0BD,0DAA0D;AAC1D,KAAK,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,eAAe,EAAE,GAAG,SAAS,CAAC,CAkExC;AA0CD;;;;;;;;;;GAUG;AACH,wBAAsB,+BAA+B,CACnD,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,eAAe,EAAE,CAAC;IAAC,SAAS,EAAE,gBAAgB,EAAE,CAAA;CAAE,GAAG,SAAS,CAAC,CA0CpF;A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