@agentclientprotocol/claude-agent-acp 0.81.3-preview.1 → 0.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +8 -5
  2. package/dist/acp-agent.d.ts +31 -37
  3. package/dist/acp-agent.d.ts.map +1 -1
  4. package/dist/acp-agent.js +546 -534
  5. package/dist/acp-subagents.d.ts +6 -0
  6. package/dist/acp-subagents.d.ts.map +1 -1
  7. package/dist/air-extension.d.ts +31 -1
  8. package/dist/air-extension.d.ts.map +1 -1
  9. package/dist/air-extension.js +35 -1
  10. package/dist/async-tasks.d.ts +39 -2
  11. package/dist/async-tasks.d.ts.map +1 -1
  12. package/dist/async-tasks.js +147 -44
  13. package/dist/context-compaction-meta.d.ts +6 -5
  14. package/dist/context-compaction-meta.d.ts.map +1 -1
  15. package/dist/context-compaction-meta.js +10 -10
  16. package/dist/context-compaction.d.ts +3 -0
  17. package/dist/context-compaction.d.ts.map +1 -1
  18. package/dist/context-compaction.js +23 -57
  19. package/dist/diff.d.ts +73 -5
  20. package/dist/diff.d.ts.map +1 -1
  21. package/dist/diff.js +435 -64
  22. package/dist/elicitation.d.ts +1 -1
  23. package/dist/elicitation.d.ts.map +1 -1
  24. package/dist/elicitation.js +12 -14
  25. package/dist/native-subagents.d.ts +58 -0
  26. package/dist/native-subagents.d.ts.map +1 -1
  27. package/dist/native-subagents.js +186 -34
  28. package/dist/paths.d.ts +3 -0
  29. package/dist/paths.d.ts.map +1 -0
  30. package/dist/paths.js +6 -0
  31. package/dist/permissions/presentation.d.ts +13 -2
  32. package/dist/permissions/presentation.d.ts.map +1 -1
  33. package/dist/permissions/presentation.js +49 -44
  34. package/dist/resumed-session.d.ts +11 -0
  35. package/dist/resumed-session.d.ts.map +1 -1
  36. package/dist/resumed-session.js +106 -4
  37. package/dist/session-mode.d.ts +2 -0
  38. package/dist/session-mode.d.ts.map +1 -1
  39. package/dist/session-mode.js +12 -5
  40. package/dist/settings.js +2 -2
  41. package/dist/subagent-history.d.ts +20 -0
  42. package/dist/subagent-history.d.ts.map +1 -0
  43. package/dist/subagent-history.js +46 -0
  44. package/dist/tool-calls/background.d.ts +20 -0
  45. package/dist/tool-calls/background.d.ts.map +1 -0
  46. package/dist/tool-calls/background.js +41 -0
  47. package/dist/tool-calls/changed-meta-filter.d.ts +27 -0
  48. package/dist/tool-calls/changed-meta-filter.d.ts.map +1 -0
  49. package/dist/tool-calls/changed-meta-filter.js +102 -0
  50. package/dist/tool-calls/client-capabilities.d.ts +51 -0
  51. package/dist/tool-calls/client-capabilities.d.ts.map +1 -0
  52. package/dist/tool-calls/client-capabilities.js +43 -0
  53. package/dist/tool-calls/content.d.ts +59 -0
  54. package/dist/tool-calls/content.d.ts.map +1 -0
  55. package/dist/tool-calls/content.js +194 -0
  56. package/dist/tool-calls/facts.d.ts +116 -0
  57. package/dist/tool-calls/facts.d.ts.map +1 -0
  58. package/dist/tool-calls/facts.js +1 -0
  59. package/dist/tool-calls/field-tracker.d.ts +58 -0
  60. package/dist/tool-calls/field-tracker.d.ts.map +1 -0
  61. package/dist/tool-calls/field-tracker.js +167 -0
  62. package/dist/tool-calls/renderer.d.ts +216 -0
  63. package/dist/tool-calls/renderer.d.ts.map +1 -0
  64. package/dist/tool-calls/renderer.js +487 -0
  65. package/dist/tool-calls/reporters/agent.d.ts +7 -0
  66. package/dist/tool-calls/reporters/agent.d.ts.map +1 -0
  67. package/dist/tool-calls/reporters/agent.js +190 -0
  68. package/dist/tool-calls/reporters/bash.d.ts +9 -0
  69. package/dist/tool-calls/reporters/bash.d.ts.map +1 -0
  70. package/dist/tool-calls/reporters/bash.js +83 -0
  71. package/dist/tool-calls/reporters/compaction.d.ts +24 -0
  72. package/dist/tool-calls/reporters/compaction.d.ts.map +1 -0
  73. package/dist/tool-calls/reporters/compaction.js +66 -0
  74. package/dist/tool-calls/reporters/file-edit.d.ts +46 -0
  75. package/dist/tool-calls/reporters/file-edit.d.ts.map +1 -0
  76. package/dist/tool-calls/reporters/file-edit.js +180 -0
  77. package/dist/tool-calls/reporters/index.d.ts +4 -0
  78. package/dist/tool-calls/reporters/index.d.ts.map +1 -0
  79. package/dist/tool-calls/reporters/index.js +40 -0
  80. package/dist/tool-calls/reporters/interaction.d.ts +71 -0
  81. package/dist/tool-calls/reporters/interaction.d.ts.map +1 -0
  82. package/dist/tool-calls/reporters/interaction.js +222 -0
  83. package/dist/tool-calls/reporters/read.d.ts +7 -0
  84. package/dist/tool-calls/reporters/read.d.ts.map +1 -0
  85. package/dist/tool-calls/reporters/read.js +64 -0
  86. package/dist/tool-calls/reporters/search.d.ts +10 -0
  87. package/dist/tool-calls/reporters/search.d.ts.map +1 -0
  88. package/dist/tool-calls/reporters/search.js +50 -0
  89. package/dist/tool-calls/reporters/web.d.ts +11 -0
  90. package/dist/tool-calls/reporters/web.d.ts.map +1 -0
  91. package/dist/tool-calls/reporters/web.js +42 -0
  92. package/dist/tools.d.ts +32 -37
  93. package/dist/tools.d.ts.map +1 -1
  94. package/dist/tools.js +48 -970
  95. package/package.json +4 -1
@@ -1,4 +1,5 @@
1
1
  import { createContextCompactionMeta, } from "./context-compaction-meta.js";
2
+ import { compactionToolCall } from "./tool-calls/reporters/compaction.js";
2
3
  export function clientSupportsCompactionUpdates(capabilities) {
3
4
  const compaction = capabilities?.session?.compaction;
4
5
  return typeof compaction === "object" && compaction !== null && !Array.isArray(compaction);
@@ -106,11 +107,13 @@ export class ContextCompactionLifecycle {
106
107
  sessionId;
107
108
  presentation;
108
109
  logError;
110
+ airClient;
109
111
  constructor(sendUpdate, options) {
110
112
  this.sendUpdate = sendUpdate;
111
113
  this.sessionId = options.sessionId;
112
114
  this.presentation = options.presentation ?? "tool_call";
113
115
  this.logError = options.logError ?? (() => { });
116
+ this.airClient = options.airClient ?? false;
114
117
  }
115
118
  get hasDeliveredOutput() {
116
119
  return this.outputDelivered;
@@ -182,18 +185,11 @@ export class ContextCompactionLifecycle {
182
185
  sessionUpdate: "compaction_update",
183
186
  compactionId,
184
187
  status: "in_progress",
185
- _meta: createContextCompactionMeta(),
188
+ ...(this.airClient ? { _meta: createContextCompactionMeta() } : {}),
186
189
  });
187
190
  return;
188
191
  }
189
- await this.send({
190
- sessionUpdate: "tool_call",
191
- toolCallId: compactionId,
192
- title: "Compact conversation",
193
- kind: "think",
194
- status: "in_progress",
195
- _meta: compactionToolMeta(),
196
- });
192
+ await this.send(compactionToolCall.started(compactionId, this.airClient));
197
193
  }
198
194
  /**
199
195
  * Streaming progress from the API's compaction content block.
@@ -211,6 +207,7 @@ export class ContextCompactionLifecycle {
211
207
  const state = this.activeCompaction;
212
208
  if (!state || state.terminalStatus || !summaryChunk)
213
209
  return;
210
+ state.streamedSummary = (state.streamedSummary ?? "") + summaryChunk;
214
211
  await this.send({
215
212
  sessionUpdate: "compaction_summary_chunk",
216
213
  compactionId: state.compactionId,
@@ -224,12 +221,7 @@ export class ContextCompactionLifecycle {
224
221
  if (!state || state.terminalStatus || state.heartbeatSent)
225
222
  return;
226
223
  state.heartbeatSent = true;
227
- await this.send({
228
- sessionUpdate: "tool_call_update",
229
- toolCallId: state.compactionId,
230
- status: "in_progress",
231
- _meta: compactionToolMeta(),
232
- });
224
+ await this.send(compactionToolCall.inProgress(state.compactionId, this.airClient));
233
225
  }
234
226
  /**
235
227
  * The PostCompact hook's summary. The CLI awaits the hook before emitting
@@ -280,7 +272,13 @@ export class ContextCompactionLifecycle {
280
272
  const terminalStatus = state.terminalStatus ?? status;
281
273
  const hasMetadata = Object.keys(metadata).length > 0;
282
274
  if (this.presentation === "compaction_update") {
283
- const summary = firstTerminal && terminalStatus === "completed" ? state.summary : undefined;
275
+ // A summary that went out as chunks is not sent again in full. The
276
+ // chunks are the raw API text and the summary is the cleaned hook text,
277
+ // so the summary is left out only when both hold the same text.
278
+ const summaryStreamed = state.streamedSummary === state.summary;
279
+ const summary = firstTerminal && terminalStatus === "completed" && !summaryStreamed
280
+ ? state.summary
281
+ : undefined;
284
282
  await this.send({
285
283
  sessionUpdate: "compaction_update",
286
284
  compactionId: state.compactionId,
@@ -290,35 +288,15 @@ export class ContextCompactionLifecycle {
290
288
  // `_meta` is a replace-patch: seed it with the first terminal, then
291
289
  // only re-send it when the boundary adds facts, so a status-only
292
290
  // duplicate can't wipe the token counts.
293
- ...(firstTerminal || hasMetadata ? { _meta: createContextCompactionMeta(metadata) } : {}),
291
+ // The standard `error` field carries the error, so `_meta` does not.
292
+ // Only AIR gets the compaction facts.
293
+ ...(this.airClient && (firstTerminal || hasMetadata)
294
+ ? { _meta: createContextCompactionMeta(withoutError(metadata)) }
295
+ : {}),
294
296
  });
295
297
  return;
296
298
  }
297
- const rawOutput = hasMetadata ? metadata : undefined;
298
- const errorContent = status === "failed" && metadata.error
299
- ? { content: [compactionErrorContent(metadata.error)] }
300
- : {};
301
- if (opened) {
302
- await this.send({
303
- sessionUpdate: "tool_call",
304
- toolCallId: state.compactionId,
305
- title: "Compact conversation",
306
- kind: "think",
307
- status,
308
- ...errorContent,
309
- ...(rawOutput ? { rawOutput } : {}),
310
- _meta: compactionToolMeta(metadata),
311
- });
312
- return;
313
- }
314
- await this.send({
315
- sessionUpdate: "tool_call_update",
316
- toolCallId: state.compactionId,
317
- ...(firstTerminal ? { status } : {}),
318
- ...errorContent,
319
- ...(rawOutput ? { rawOutput } : {}),
320
- _meta: compactionToolMeta(metadata),
321
- });
299
+ await this.send(compactionToolCall.finished(state.compactionId, opened || firstTerminal ? status : undefined, metadata, opened, this.airClient));
322
300
  }
323
301
  /** Make `compactionId` the active entity, moving a pending hook summary onto
324
302
  * it, and mark compaction output as delivered for the owning turn. */
@@ -346,6 +324,9 @@ export class ContextCompactionLifecycle {
346
324
  }
347
325
  }
348
326
  }
327
+ function withoutError({ error: _error, ...facts }) {
328
+ return facts;
329
+ }
349
330
  export function contextCompactionMetadataFromBoundary(compactMetadata) {
350
331
  return {
351
332
  trigger: compactMetadata.trigger === "auto" ? "automatic" : "manual",
@@ -358,18 +339,3 @@ export function contextCompactionMetadataFromBoundary(compactMetadata) {
358
339
  : {}),
359
340
  };
360
341
  }
361
- function compactionToolMeta(metadata = {}) {
362
- return {
363
- ...createContextCompactionMeta(metadata),
364
- claudeCode: { toolName: "compact" },
365
- };
366
- }
367
- function compactionErrorContent(error) {
368
- return {
369
- type: "content",
370
- content: {
371
- type: "text",
372
- text: `Compaction failed: ${error}`,
373
- },
374
- };
375
- }
package/dist/diff.d.ts CHANGED
@@ -1,13 +1,81 @@
1
1
  import { ToolCallContent, ToolCallLocation } from "@agentclientprotocol/sdk";
2
2
  /**
3
- * Builds diff ToolUpdate content from the structured toolResponse provided by
4
- * the PostToolUse hook for diff-producing tools (Edit, Write). Unlike parsing
5
- * the plain unified diff string, this uses the pre-parsed structuredPatch
6
- * which supports multiple replacement sites (replaceAll) and always includes
7
- * context lines for better readability.
3
+ * The largest file, in bytes, that the adapter turns into a git patch.
4
+ *
5
+ * A larger file, a larger new text, or an Edit whose result can be larger
6
+ * gets no patch. The tool call then keeps its standard ACP content. The limit
7
+ * bounds the file read, the replacement, and the line diff that run while
8
+ * Claude waits for an approval.
9
+ */
10
+ export declare const MAX_PATCH_FILE_BYTES: number;
11
+ /**
12
+ * One unified-diff hunk in the `diff` package convention.
13
+ *
14
+ * A side with zero lines stores the number of the line after the change as its
15
+ * start. {@link hunkHeader} converts that start to the git convention.
16
+ */
17
+ interface PatchHunk {
18
+ oldStart: number;
19
+ oldLines: number;
20
+ newStart: number;
21
+ newLines: number;
22
+ lines: string[];
23
+ }
24
+ /** The kind of file change that a git patch describes. */
25
+ type FileChange = "create" | "update";
26
+ /**
27
+ * Builds the exact patch shown before Claude runs an Edit or Write tool.
28
+ *
29
+ * Returns undefined when the adapter cannot predict the file change exactly.
30
+ * The caller then keeps the standard tool-call content. The adapter declines
31
+ * a file that is missing for an Edit, too large, binary, or that has CR line
32
+ * endings. Claude converts the line endings of an edited file, so an in-memory
33
+ * replacement would not match the bytes that Claude writes. It also declines
34
+ * an `old_string` that does not match exactly once, because Claude then
35
+ * normalizes quotes or fails.
36
+ *
37
+ * 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.
40
+ *
41
+ * The preview uses the tool input as it is. Claude can still remove the
42
+ * trailing whitespace of a line before it writes. The PostToolUse hook then
43
+ * sends the patch of the written file.
44
+ */
45
+ export declare function previewPatchContent(toolName: string, input: Record<string, unknown>, cwd?: string): Promise<ToolCallContent[] | undefined>;
46
+ /**
47
+ * Builds the git patch for a finished Edit or Write from the file on disk.
48
+ *
49
+ * The Claude SDK `structuredPatch` is display data: Claude converts leading
50
+ * tabs to spaces and CRLF line endings to LF before it computes the hunks. A
51
+ * patch built from those hunks does not match the file. This function diffs
52
+ * `originalFile` against the written file instead. It returns undefined when
53
+ * it cannot build an exact patch, and the caller then sends the standard diff.
54
+ * A written file that contains a CR or a byte order mark is declined, because
55
+ * Claude removed those bytes from `originalFile`.
56
+ */
57
+ export declare function patchUpdateFromDiffToolResponse(toolResponse: unknown): Promise<{
58
+ content: ToolCallContent[];
59
+ locations: ToolCallLocation[];
60
+ } | undefined>;
61
+ /**
62
+ * Builds standard ACP diff content from the structured toolResponse provided
63
+ * by the PostToolUse hook for diff-producing tools (Edit, Write). Unlike
64
+ * parsing the plain unified diff string, this uses the pre-parsed
65
+ * structuredPatch which supports multiple replacement sites (replaceAll) and
66
+ * always includes context lines for better readability.
8
67
  */
9
68
  export declare function toolUpdateFromDiffToolResponse(toolResponse: unknown): {
10
69
  content?: ToolCallContent[];
11
70
  locations?: ToolCallLocation[];
12
71
  };
72
+ /**
73
+ * The text of one git patch for `filePath`.
74
+ *
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.
78
+ */
79
+ export declare function gitPatchText(filePath: string, change: FileChange, hunks: PatchHunk[]): string;
80
+ export {};
13
81
  //# 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;AAwB7E;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAAC,YAAY,EAAE,OAAO,GAAG;IACrE,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAChC,CA2HA"}
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;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAAC,YAAY,EAAE,OAAO,GAAG;IACrE,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAChC,CAoEA;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,CAM7F"}