@agentclientprotocol/claude-agent-acp 0.107.4-preview.2 → 0.107.4-preview.4
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/background-output.d.ts +90 -0
- package/dist/background-output.d.ts.map +1 -1
- package/dist/background-output.js +138 -0
- package/dist/permissions/options/shared.d.ts +3 -0
- package/dist/permissions/options/shared.d.ts.map +1 -1
- package/dist/permissions/options/tools.d.ts.map +1 -1
- package/dist/permissions/options/tools.js +3 -1
- package/dist/settings.d.ts +8 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +15 -0
- package/dist/tool-calls/background.d.ts +32 -0
- package/dist/tool-calls/background.d.ts.map +1 -1
- package/dist/tool-calls/background.js +53 -0
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +26 -4
- package/dist/v1/background-work.d.ts +87 -9
- package/dist/v1/background-work.d.ts.map +1 -1
- package/dist/v1/background-work.js +112 -3
- package/dist/v2/permissions.d.ts +1 -0
- package/dist/v2/permissions.d.ts.map +1 -1
- package/dist/v2/permissions.js +1 -0
- package/dist/v2/reports.d.ts +5 -1
- package/dist/v2/reports.d.ts.map +1 -1
- package/dist/v2/reports.js +7 -0
- package/dist/v2/session.d.ts +3 -1
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +10 -1
- package/dist/v2/tasks.d.ts +22 -0
- package/dist/v2/tasks.d.ts.map +1 -1
- package/dist/v2/tasks.js +57 -3
- package/package.json +1 -1
package/dist/v2/tasks.js
CHANGED
|
@@ -47,10 +47,10 @@ import * as fs from "node:fs";
|
|
|
47
47
|
import * as path from "node:path";
|
|
48
48
|
import { RequestError } from "@agentclientprotocol/sdk/unstable";
|
|
49
49
|
import { backgroundBashTaskFromToolResult, taskProgressFields } from "../async-tasks.js";
|
|
50
|
-
import { BackgroundOutputTail } from "../background-output.js";
|
|
50
|
+
import { BackgroundOutputTail, foregroundCommandToolCall, isCommandTool, TaskOutputPoll, } from "../background-output.js";
|
|
51
51
|
import { childModelOption, HANDBACK_TOOL, handbackMessage, isNativeSubagentControlTool, launchReply, linkedSessionMessages, mergeSubagentIdentity, responseModelEntry, resumedNativeSubagentId, rfdLabels, sendMessageResume, subagentIdentity, targetAgentId, unexposedControlFallback, withSessionReference, } from "../native-subagents.js";
|
|
52
52
|
import { subagentLineage } from "../subagent-history.js";
|
|
53
|
-
import { withRunningTerminal, withRunningToolCall } from "../tool-calls/background.js";
|
|
53
|
+
import { streamedTerminals, withRunningTerminal, withRunningToolCall, withStreamedTerminal, } from "../tool-calls/background.js";
|
|
54
54
|
import { ClientCapabilities } from "../tool-calls/client-capabilities.js";
|
|
55
55
|
import { AcpToolCallRenderer } from "../tool-calls/renderer.js";
|
|
56
56
|
import { workflowCard, workflowSnapshot } from "../workflow-progress.js";
|
|
@@ -99,6 +99,12 @@ export class SessionTasks {
|
|
|
99
99
|
level = new Map();
|
|
100
100
|
/** The terminals of the commands that went to the background, by task id. */
|
|
101
101
|
terminals = new Map();
|
|
102
|
+
/**
|
|
103
|
+
* The output polls of the commands that run in the foreground, by tool call
|
|
104
|
+
* id. A poll stays here after its task ended, stopped, until the command's
|
|
105
|
+
* tool result asks whether its terminal got output.
|
|
106
|
+
*/
|
|
107
|
+
foreground = new Map();
|
|
102
108
|
/**
|
|
103
109
|
* The tool calls whose tasks go on in the background, by task id. A call
|
|
104
110
|
* that the adapter started for its task (see {@link adoptTasks}) has the
|
|
@@ -236,6 +242,20 @@ export class SessionTasks {
|
|
|
236
242
|
const command = backgroundBashTaskFromToolResult(content, message.tool_use_result, toolUses, (toolUseId) => [...this.started].find(([, task]) => task.toolUseId === toolUseId && task.taskType === "local_bash")?.[0]);
|
|
237
243
|
// A fast command can end before its result: then its terminal exits with it.
|
|
238
244
|
const runningTerminal = command && this.started.has(command.taskId) ? command.toolCallId : undefined;
|
|
245
|
+
// The output that a foreground command's terminal showed as it ran is
|
|
246
|
+
// replaced by the result's, when the result carries the command's output
|
|
247
|
+
// (see `streamedTerminals`). The output file's tail goes on for a command
|
|
248
|
+
// that went to the background.
|
|
249
|
+
const shown = [];
|
|
250
|
+
for (const { tool_use_id: toolCallId } of results) {
|
|
251
|
+
const poll = this.foreground.get(toolCallId);
|
|
252
|
+
if (!poll)
|
|
253
|
+
continue;
|
|
254
|
+
this.foreground.delete(toolCallId);
|
|
255
|
+
if (poll.end())
|
|
256
|
+
shown.push(toolCallId);
|
|
257
|
+
}
|
|
258
|
+
const streamed = streamedTerminals(shown, command?.toolCallId, message.tool_result_meta);
|
|
239
259
|
if (command && runningTerminal) {
|
|
240
260
|
this.terminals.set(command.taskId, {
|
|
241
261
|
toolCallId: command.toolCallId,
|
|
@@ -275,7 +295,7 @@ export class SessionTasks {
|
|
|
275
295
|
});
|
|
276
296
|
runningToolCalls.add(toolCallId);
|
|
277
297
|
}
|
|
278
|
-
output.toolResults(message, (notification) => withRunningToolCall(withRunningTerminal(notification, runningTerminal), runningToolCalls));
|
|
298
|
+
output.toolResults(message, (notification) => withRunningToolCall(withRunningTerminal(withStreamedTerminal(notification, streamed), runningTerminal), runningToolCalls));
|
|
279
299
|
// A workflow can report progress before its launch call returns: it
|
|
280
300
|
// goes on the call after the result's own updates.
|
|
281
301
|
for (const [taskId, toolCall] of this.toolCalls) {
|
|
@@ -413,6 +433,7 @@ export class SessionTasks {
|
|
|
413
433
|
*/
|
|
414
434
|
withdrawAll() {
|
|
415
435
|
this.closed = true;
|
|
436
|
+
this.stopForeground();
|
|
416
437
|
for (const agentId of this.agentRequests.keys())
|
|
417
438
|
this.withdraw(agentId);
|
|
418
439
|
}
|
|
@@ -589,6 +610,7 @@ export class SessionTasks {
|
|
|
589
610
|
* `error`, as the root's work does.
|
|
590
611
|
*/
|
|
591
612
|
queryEnded(error) {
|
|
613
|
+
this.stopForeground();
|
|
592
614
|
for (const [taskId, terminal] of this.terminals) {
|
|
593
615
|
terminal.tail?.stop();
|
|
594
616
|
if (error)
|
|
@@ -671,6 +693,7 @@ export class SessionTasks {
|
|
|
671
693
|
taskStarted(message) {
|
|
672
694
|
const isAgent = message.task_type === "local_agent" || message.subagent_type !== undefined;
|
|
673
695
|
if (!isAgent) {
|
|
696
|
+
this.followForeground(message);
|
|
674
697
|
this.started.set(message.task_id, {
|
|
675
698
|
...(message.tool_use_id !== undefined ? { toolUseId: message.tool_use_id } : {}),
|
|
676
699
|
...(message.parent_task_id !== undefined ? { parentTaskId: message.parent_task_id } : {}),
|
|
@@ -840,6 +863,12 @@ export class SessionTasks {
|
|
|
840
863
|
: {}),
|
|
841
864
|
});
|
|
842
865
|
}
|
|
866
|
+
// A foreground command's output is read no more: a tool call that gets no
|
|
867
|
+
// result, such as one of a reply that Claude Code took back, would
|
|
868
|
+
// otherwise be read until the query ends.
|
|
869
|
+
const commandToolCall = this.started.get(taskId)?.toolUseId;
|
|
870
|
+
if (commandToolCall !== undefined)
|
|
871
|
+
this.foreground.get(commandToolCall)?.stop();
|
|
843
872
|
this.started.delete(taskId);
|
|
844
873
|
const terminal = this.terminals.get(taskId);
|
|
845
874
|
if (terminal && !terminal.ending) {
|
|
@@ -1682,6 +1711,31 @@ export class SessionTasks {
|
|
|
1682
1711
|
? [...this.toolCalls].find(([, t]) => t.toolCallId === target.toolCallId)?.[0]
|
|
1683
1712
|
: undefined;
|
|
1684
1713
|
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Starts reading the output of the foreground command that the task
|
|
1716
|
+
* `started` runs (see `foregroundCommandToolCall`) into its terminal, until
|
|
1717
|
+
* its tool result or the end of its task (see {@link TaskOutputPoll}). A
|
|
1718
|
+
* subagent's command goes to the subagent's session, and gets no poll
|
|
1719
|
+
* before that session is announced.
|
|
1720
|
+
*/
|
|
1721
|
+
followForeground(started) {
|
|
1722
|
+
const read = this.host.taskOutput();
|
|
1723
|
+
const toolCallId = foregroundCommandToolCall(started);
|
|
1724
|
+
if (!read || toolCallId === undefined || this.foreground.has(toolCallId))
|
|
1725
|
+
return;
|
|
1726
|
+
const parent = started.parent_task_id === undefined ? undefined : this.children.get(started.parent_task_id);
|
|
1727
|
+
const output = started.parent_task_id === undefined ? this.rootOutput : parent?.output;
|
|
1728
|
+
if (!output?.holds(toolCallId) || !isCommandTool(output.toolUses()[toolCallId]?.name))
|
|
1729
|
+
return;
|
|
1730
|
+
const taskId = started.task_id;
|
|
1731
|
+
this.foreground.set(toolCallId, new TaskOutputPoll(() => read(taskId), async (text) => output.emitV1([terminalOutput(output.sessionId, toolCallId, text)])));
|
|
1732
|
+
}
|
|
1733
|
+
/** Stops the output polls of the foreground commands: the query or the session ended. */
|
|
1734
|
+
stopForeground() {
|
|
1735
|
+
for (const poll of this.foreground.values())
|
|
1736
|
+
poll.stop();
|
|
1737
|
+
this.foreground.clear();
|
|
1738
|
+
}
|
|
1685
1739
|
followOutput(taskId, outputFilePath) {
|
|
1686
1740
|
const terminal = this.terminals.get(taskId);
|
|
1687
1741
|
if (!terminal || !outputFilePath || !this.host.reportsBackground)
|
package/package.json
CHANGED