@agentclientprotocol/claude-agent-acp 0.85.2-preview.9 → 0.86.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.
- package/dist/acp-agent.d.ts +56 -21
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +161 -34
- package/dist/clear-context-coordinator.d.ts +1 -0
- package/dist/clear-context-coordinator.d.ts.map +1 -1
- package/dist/clear-context-coordinator.js +2 -1
- package/dist/diff.d.ts +45 -8
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +111 -30
- package/dist/permissions/presentation.d.ts +17 -2
- package/dist/permissions/presentation.d.ts.map +1 -1
- package/dist/permissions/presentation.js +4 -0
- package/dist/session-config-ids.d.ts +1 -0
- package/dist/session-config-ids.d.ts.map +1 -1
- package/dist/session-config-ids.js +1 -0
- package/dist/tool-calls/client-capabilities.d.ts +20 -2
- package/dist/tool-calls/client-capabilities.d.ts.map +1 -1
- package/dist/tool-calls/client-capabilities.js +14 -4
- package/dist/tool-calls/facts.d.ts +8 -1
- package/dist/tool-calls/facts.d.ts.map +1 -1
- package/dist/tool-calls/renderer.d.ts +5 -1
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +14 -3
- package/dist/tool-calls/reporters/bash.d.ts.map +1 -1
- package/dist/tool-calls/reporters/bash.js +32 -5
- package/dist/tool-calls/reporters/file-edit.d.ts +1 -1
- package/dist/tool-calls/reporters/file-edit.d.ts.map +1 -1
- package/dist/tool-calls/reporters/file-edit.js +20 -14
- package/dist/v2/agent.d.ts +2 -0
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +109 -14
- package/dist/v2/initialize.d.ts +2 -5
- package/dist/v2/initialize.d.ts.map +1 -1
- package/dist/v2/initialize.js +42 -11
- package/dist/v2/permission.d.ts +25 -0
- package/dist/v2/permission.d.ts.map +1 -0
- package/dist/v2/permission.js +38 -0
- package/dist/v2/session-update.d.ts +6 -0
- package/dist/v2/session-update.d.ts.map +1 -1
- package/dist/v2/session-update.js +19 -0
- package/dist/v2/session.d.ts +29 -4
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +41 -6
- package/dist/v2/terminal.d.ts +42 -0
- package/dist/v2/terminal.d.ts.map +1 -0
- package/dist/v2/terminal.js +95 -0
- package/dist/v2/tool-call.d.ts +38 -0
- package/dist/v2/tool-call.d.ts.map +1 -0
- package/dist/v2/tool-call.js +49 -0
- package/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-owned display terminals for the commands that the agent runs.
|
|
3
|
+
*
|
|
4
|
+
* The agent reports a command through the terminal extension of ACP v1
|
|
5
|
+
* clients, as codex-acp does: `_meta.terminal_info` names the terminal of a
|
|
6
|
+
* tool call, whose content references it; `terminal_output` (a snapshot) or
|
|
7
|
+
* `terminal_output_delta` (a chunk) carries the output, and `terminal_exit` the
|
|
8
|
+
* exit. ACP v2 standardizes this as display-only terminals: the same content
|
|
9
|
+
* reference, and `terminal_update` and `terminal_output_chunk` for the
|
|
10
|
+
* terminal's state. The agent reports to a v2 client as to a client of the
|
|
11
|
+
* extension (`ToolCallClientCapabilities.from`), and {@link V2Terminals} turns
|
|
12
|
+
* the extension's keys into those updates.
|
|
13
|
+
*/
|
|
14
|
+
import type { ToolCall, ToolCallUpdate } from "@agentclientprotocol/sdk";
|
|
15
|
+
import type * as v2 from "@agentclientprotocol/sdk/experimental/v2";
|
|
16
|
+
type V1ToolCallReport = (ToolCall & {
|
|
17
|
+
sessionUpdate: "tool_call";
|
|
18
|
+
}) | (ToolCallUpdate & {
|
|
19
|
+
sessionUpdate: "tool_call_update";
|
|
20
|
+
});
|
|
21
|
+
/** The terminal updates of the tool call reports of one v2 connection. */
|
|
22
|
+
export declare class V2Terminals {
|
|
23
|
+
/** The terminal and the last reported command of each running command, by session and tool call. */
|
|
24
|
+
private readonly running;
|
|
25
|
+
/**
|
|
26
|
+
* The terminal updates that a tool call report carries in the extension's
|
|
27
|
+
* keys, and the report without them, or undefined when nothing else is left
|
|
28
|
+
* in it.
|
|
29
|
+
*
|
|
30
|
+
* The extension names no command, so the terminal gets the command of the
|
|
31
|
+
* tool call's `rawInput` once a report carries it: the first report of a
|
|
32
|
+
* streamed tool use has no input yet.
|
|
33
|
+
*/
|
|
34
|
+
split(sessionId: string, report: V1ToolCallReport): {
|
|
35
|
+
terminal: v2.SessionUpdate[];
|
|
36
|
+
report: V1ToolCallReport | undefined;
|
|
37
|
+
};
|
|
38
|
+
/** Forgets the terminals of a session. */
|
|
39
|
+
forget(sessionId: string): void;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=terminal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../src/v2/terminal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAEpE,KAAK,gBAAgB,GACjB,CAAC,QAAQ,GAAG;IAAE,aAAa,EAAE,WAAW,CAAA;CAAE,CAAC,GAC3C,CAAC,cAAc,GAAG;IAAE,aAAa,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAAC;AAiB7D,0EAA0E;AAC1E,qBAAa,WAAW;IACtB,oGAAoG;IACpG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+D;IAEvF;;;;;;;;OAQG;IACH,KAAK,CACH,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,gBAAgB,GACvB;QAAE,QAAQ,EAAE,EAAE,CAAC,aAAa,EAAE,CAAC;QAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAA;KAAE;IAuCzE,0CAA0C;IAC1C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAKhC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const TERMINAL_KEYS = [
|
|
2
|
+
"terminal_info",
|
|
3
|
+
"terminal_output",
|
|
4
|
+
"terminal_output_delta",
|
|
5
|
+
"terminal_exit",
|
|
6
|
+
];
|
|
7
|
+
/** The terminal updates of the tool call reports of one v2 connection. */
|
|
8
|
+
export class V2Terminals {
|
|
9
|
+
/** The terminal and the last reported command of each running command, by session and tool call. */
|
|
10
|
+
running = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* The terminal updates that a tool call report carries in the extension's
|
|
13
|
+
* keys, and the report without them, or undefined when nothing else is left
|
|
14
|
+
* in it.
|
|
15
|
+
*
|
|
16
|
+
* The extension names no command, so the terminal gets the command of the
|
|
17
|
+
* tool call's `rawInput` once a report carries it: the first report of a
|
|
18
|
+
* streamed tool use has no input yet.
|
|
19
|
+
*/
|
|
20
|
+
split(sessionId, report) {
|
|
21
|
+
const meta = (report._meta ?? {});
|
|
22
|
+
const key = `${sessionId} ${report.toolCallId}`;
|
|
23
|
+
if (meta.terminal_info)
|
|
24
|
+
this.running.set(key, { terminalId: meta.terminal_info.terminal_id });
|
|
25
|
+
const terminal = [];
|
|
26
|
+
const running = this.running.get(key);
|
|
27
|
+
if (running) {
|
|
28
|
+
const command = commandOf(report.rawInput);
|
|
29
|
+
const newCommand = command !== undefined && command !== running.command;
|
|
30
|
+
if (newCommand)
|
|
31
|
+
running.command = command;
|
|
32
|
+
const { terminal_output: output, terminal_output_delta: delta, terminal_exit: exit } = meta;
|
|
33
|
+
if (meta.terminal_info || newCommand || output || exit) {
|
|
34
|
+
terminal.push({
|
|
35
|
+
sessionUpdate: "terminal_update",
|
|
36
|
+
terminalId: running.terminalId,
|
|
37
|
+
...(newCommand ? { command } : {}),
|
|
38
|
+
...(output ? { output: { data: base64(output.data) } } : {}),
|
|
39
|
+
...(exit
|
|
40
|
+
? {
|
|
41
|
+
exitStatus: {
|
|
42
|
+
...(exit.exit_code != null ? { exitCode: exit.exit_code } : {}),
|
|
43
|
+
...(exit.signal != null ? { signal: exit.signal } : {}),
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
: {}),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (delta) {
|
|
50
|
+
terminal.push({
|
|
51
|
+
sessionUpdate: "terminal_output_chunk",
|
|
52
|
+
terminalId: running.terminalId,
|
|
53
|
+
data: base64(delta.data),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (exit)
|
|
57
|
+
this.running.delete(key);
|
|
58
|
+
}
|
|
59
|
+
return { terminal, report: withoutTerminalKeys(report) };
|
|
60
|
+
}
|
|
61
|
+
/** Forgets the terminals of a session. */
|
|
62
|
+
forget(sessionId) {
|
|
63
|
+
for (const key of this.running.keys()) {
|
|
64
|
+
if (key.startsWith(`${sessionId} `))
|
|
65
|
+
this.running.delete(key);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The report without the extension's keys, or undefined when it carried
|
|
71
|
+
* nothing else but `_meta`: the output report of a command carries the output
|
|
72
|
+
* alone, and only the stamps that every report of the tool call repeats. In v2
|
|
73
|
+
* a concrete `_meta` replaces the stored one, so sending them would drop the
|
|
74
|
+
* other keys that the tool call holds.
|
|
75
|
+
*/
|
|
76
|
+
function withoutTerminalKeys(report) {
|
|
77
|
+
if (!report._meta || !TERMINAL_KEYS.some((key) => key in report._meta))
|
|
78
|
+
return report;
|
|
79
|
+
const meta = Object.fromEntries(Object.entries(report._meta).filter(([key]) => !TERMINAL_KEYS.includes(key)));
|
|
80
|
+
const stripped = { ...report };
|
|
81
|
+
if (Object.keys(meta).length > 0)
|
|
82
|
+
stripped._meta = meta;
|
|
83
|
+
else
|
|
84
|
+
delete stripped._meta;
|
|
85
|
+
const fields = Object.keys(stripped).filter((key) => key !== "sessionUpdate" && key !== "toolCallId" && key !== "_meta");
|
|
86
|
+
return fields.length > 0 || report.sessionUpdate === "tool_call" ? stripped : undefined;
|
|
87
|
+
}
|
|
88
|
+
function commandOf(rawInput) {
|
|
89
|
+
const command = rawInput?.command;
|
|
90
|
+
return typeof command === "string" && command.length > 0 ? command : undefined;
|
|
91
|
+
}
|
|
92
|
+
/** The output bytes, base64-encoded as a v2 terminal carries them. */
|
|
93
|
+
function base64(text) {
|
|
94
|
+
return Buffer.from(text, "utf8").toString("base64");
|
|
95
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v2 form of the tool call reports that `ClaudeAcpAgent` sends as v1
|
|
3
|
+
* `tool_call` and `tool_call_update` updates, and in permission requests.
|
|
4
|
+
*/
|
|
5
|
+
import type { ToolCall, ToolCallUpdate } from "@agentclientprotocol/sdk";
|
|
6
|
+
import type * as v2 from "@agentclientprotocol/sdk/experimental/v2";
|
|
7
|
+
type V1ToolCallReport = (ToolCall & {
|
|
8
|
+
sessionUpdate: "tool_call";
|
|
9
|
+
}) | (ToolCallUpdate & {
|
|
10
|
+
sessionUpdate: "tool_call_update";
|
|
11
|
+
});
|
|
12
|
+
type V2ToolCallUpdate = v2.ToolCallUpdate & {
|
|
13
|
+
sessionUpdate: "tool_call_update";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The v2 form of a v1 tool call report.
|
|
17
|
+
*
|
|
18
|
+
* v1 reports a new tool call with `tool_call` and changes it with
|
|
19
|
+
* `tool_call_update`; v2 has one `tool_call_update` that upserts by
|
|
20
|
+
* `toolCallId`. Both leave a field that a report omits unchanged, and both
|
|
21
|
+
* replace `content` and `locations` as whole arrays. They differ on `null`:
|
|
22
|
+
* in v1 it leaves the field unchanged too, in v2 it clears the field, so `null`
|
|
23
|
+
* fields are left out.
|
|
24
|
+
*
|
|
25
|
+
* Diffs need what a v1 diff does not say, so the agent builds them in v2 form
|
|
26
|
+
* for a v2 client (`v2DiffContent`), and they pass as they are. Terminal
|
|
27
|
+
* content references a display terminal, as in v2: a v2 client has no client
|
|
28
|
+
* terminals, so the agent's only terminals are those of its terminal extension
|
|
29
|
+
* (see `terminal.ts`).
|
|
30
|
+
*/
|
|
31
|
+
export declare function v2ToolCallUpdate(report: V1ToolCallReport): V2ToolCallUpdate;
|
|
32
|
+
/**
|
|
33
|
+
* The v2 form of the fields of a v1 tool call report, which a session update
|
|
34
|
+
* and the subject of a permission request carry. See {@link v2ToolCallUpdate}.
|
|
35
|
+
*/
|
|
36
|
+
export declare function v2ToolCallPatch(toolCall: ToolCall | ToolCallUpdate): v2.ToolCallUpdate;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=tool-call.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call.d.ts","sourceRoot":"","sources":["../../src/v2/tool-call.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAmB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1F,OAAO,KAAK,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAEpE,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;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,GAAG,EAAE,CAAC,cAAc,CAUtF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v2 form of a v1 tool call report.
|
|
3
|
+
*
|
|
4
|
+
* v1 reports a new tool call with `tool_call` and changes it with
|
|
5
|
+
* `tool_call_update`; v2 has one `tool_call_update` that upserts by
|
|
6
|
+
* `toolCallId`. Both leave a field that a report omits unchanged, and both
|
|
7
|
+
* replace `content` and `locations` as whole arrays. They differ on `null`:
|
|
8
|
+
* in v1 it leaves the field unchanged too, in v2 it clears the field, so `null`
|
|
9
|
+
* fields are left out.
|
|
10
|
+
*
|
|
11
|
+
* Diffs need what a v1 diff does not say, so the agent builds them in v2 form
|
|
12
|
+
* for a v2 client (`v2DiffContent`), and they pass as they are. Terminal
|
|
13
|
+
* content references a display terminal, as in v2: a v2 client has no client
|
|
14
|
+
* terminals, so the agent's only terminals are those of its terminal extension
|
|
15
|
+
* (see `terminal.ts`).
|
|
16
|
+
*/
|
|
17
|
+
export function v2ToolCallUpdate(report) {
|
|
18
|
+
return { ...v2ToolCallPatch(report), sessionUpdate: "tool_call_update" };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The v2 form of the fields of a v1 tool call report, which a session update
|
|
22
|
+
* and the subject of a permission request carry. See {@link v2ToolCallUpdate}.
|
|
23
|
+
*/
|
|
24
|
+
export function v2ToolCallPatch(toolCall) {
|
|
25
|
+
const patch = Object.fromEntries(Object.entries(toolCall).filter(([key, value]) => value !== null && key !== "sessionUpdate" && key !== "content"));
|
|
26
|
+
return {
|
|
27
|
+
...patch,
|
|
28
|
+
...(toolCall.content != null ? { content: toolCall.content.map(v2ToolCallContent) } : {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function v2ToolCallContent(item) {
|
|
32
|
+
switch (item.type) {
|
|
33
|
+
case "content":
|
|
34
|
+
// v2 content blocks are a superset of the v1 blocks.
|
|
35
|
+
return item;
|
|
36
|
+
case "terminal":
|
|
37
|
+
return item;
|
|
38
|
+
default:
|
|
39
|
+
if (isV2Diff(item))
|
|
40
|
+
return item;
|
|
41
|
+
// A v1 diff names one path, with old and new texts that can be a
|
|
42
|
+
// snippet: v2 cannot say which operation it is, nor give its patch.
|
|
43
|
+
throw new Error("An ACP v2 client cannot take a v1 diff");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** A diff that the agent built in v2 form, which travels as v1 content. */
|
|
47
|
+
function isV2Diff(item) {
|
|
48
|
+
return "changes" in item;
|
|
49
|
+
}
|
package/package.json
CHANGED