@agentclientprotocol/claude-agent-acp 0.94.1-preview.1 → 0.94.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.
- package/README.md +21 -9
- package/dist/acp-agent.d.ts +39 -3
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +145 -66
- package/dist/acp-subagents.d.ts +2 -1
- package/dist/acp-subagents.d.ts.map +1 -1
- package/dist/air-extension.d.ts +5 -0
- package/dist/air-extension.d.ts.map +1 -1
- package/dist/air-extension.js +5 -0
- 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 +1 -0
- package/dist/index.js +2 -3
- package/dist/native-subagents.d.ts +64 -0
- package/dist/native-subagents.d.ts.map +1 -1
- package/dist/native-subagents.js +224 -9
- package/dist/permissions/options/shared.d.ts +3 -0
- package/dist/permissions/options/shared.d.ts.map +1 -1
- package/dist/permissions/options/tools.js +1 -1
- package/dist/serve.d.ts +19 -11
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +26 -18
- package/dist/session-index/activity.d.ts +4 -0
- package/dist/session-index/activity.d.ts.map +1 -1
- package/dist/session-index/activity.js +16 -0
- package/dist/session-index/background-tasks.d.ts +69 -0
- package/dist/session-index/background-tasks.d.ts.map +1 -0
- package/dist/session-index/background-tasks.js +173 -0
- package/dist/session-index/service.d.ts +2 -0
- package/dist/session-index/service.d.ts.map +1 -1
- package/dist/session-index/service.js +6 -1
- package/dist/session-index/session-index.d.ts +14 -0
- package/dist/session-index/session-index.d.ts.map +1 -1
- package/dist/session-index/session-index.js +25 -2
- package/dist/session-index/transcript-scan.d.ts +8 -1
- package/dist/session-index/transcript-scan.d.ts.map +1 -1
- package/dist/session-index/transcript-scan.js +22 -1
- package/dist/session-titles.d.ts +44 -16
- package/dist/session-titles.d.ts.map +1 -1
- package/dist/session-titles.js +89 -27
- package/dist/subagent-replay.d.ts +21 -1
- package/dist/subagent-replay.d.ts.map +1 -1
- package/dist/subagent-replay.js +51 -3
- package/dist/task-notifications.d.ts +30 -0
- package/dist/task-notifications.d.ts.map +1 -0
- package/dist/task-notifications.js +62 -0
- package/package.json +1 -1
package/dist/acp-agent.js
CHANGED
|
@@ -5,7 +5,7 @@ import { promptSuggestionsMeta, promptSuggestionText } from "./prompt-suggestion
|
|
|
5
5
|
import { sanitizeTitle, SessionTitles } from "./session-titles.js";
|
|
6
6
|
import { AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY, asSdkSessionNotification, clientSupportsSubagents, subagentForm, } from "./acp-subagents.js";
|
|
7
7
|
import { isNativeSubagentControlTool, isNativeSubagentControlUpdate, NativeSubagentRuntime, nativeSubagentState, resumedNativeSubagentId, sendMessageResume, sendMessageResumePrompt, } from "./native-subagents.js";
|
|
8
|
-
import { AIR_ASYNC_TASKS_CAPABILITY, AIR_CUSTOM_INSTRUCTIONS_CAPABILITY, airCustomInstructions, AIR_DIFF_PATCH_CAPABILITY, AIR_PLAN_FILE_CAPABILITY, AIR_GOAL_KEY, AIR_KIND_KEY, AIR_LOAD_REPLAY_END_CAPABILITY, AIR_LOAD_REPLAY_END_KEY, AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY, AIR_SKILL_PATH_KEY, clientSupportsAirCapability, withAirMeta, } from "./air-extension.js";
|
|
8
|
+
import { AIR_ASYNC_TASKS_CAPABILITY, AIR_BACKGROUND_SUBAGENTS_CAPABILITY, AIR_CUSTOM_INSTRUCTIONS_CAPABILITY, airCustomInstructions, AIR_DIFF_PATCH_CAPABILITY, AIR_PLAN_FILE_CAPABILITY, AIR_GOAL_KEY, AIR_KIND_KEY, AIR_LOAD_REPLAY_END_CAPABILITY, AIR_LOAD_REPLAY_END_KEY, AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY, AIR_SKILL_PATH_KEY, clientSupportsAirCapability, withAirMeta, } from "./air-extension.js";
|
|
9
9
|
import * as sessionIndex from "./session-index/connection.js";
|
|
10
10
|
import { AsyncTaskRuntime, backgroundBashTaskFromToolResult, backgroundedBashToolCallIds, clientSupportsAsyncTasks, } from "./async-tasks.js";
|
|
11
11
|
import { AUTH_STATUS_PROBE_TIMEOUT_MS, AUTH_STATUS_UPDATE_METHOD, authStatusCapability, fromAccountInfo, fromCliStatus, gatewayAuthStatus, mergeAuthStatus, notLoggedInAuthStatus, sameAuthStatus, } from "./auth-status.js";
|
|
@@ -45,6 +45,7 @@ import { messageLoopYielder, nodeToWebReadable, nodeToWebWritable, Pushable, rac
|
|
|
45
45
|
import { acceptedPlanToolResult, approvedPlan, ExitPlanCoordinator, isExitPlanInterruptionResult, observeExitPlanToolResults, planModeUpdate, } from "./exit-plan.js";
|
|
46
46
|
import { DEFAULT_AGENT_ID } from "./session-config-ids.js";
|
|
47
47
|
import { parseToolResultMeta } from "./tool-result-meta.js";
|
|
48
|
+
import { markerTagText, TASK_NOTIFICATION_TAG, taskNotificationsOf, } from "./task-notifications.js";
|
|
48
49
|
import { formatUsageResponse, isUsageCommandText, parseUsageResponse } from "./usage-markdown.js";
|
|
49
50
|
export { DEFAULT_AGENT_ID } from "./session-config-ids.js";
|
|
50
51
|
import { MCP_AVAILABLE_COMMAND, parseMcpCommand, runMcpCommand } from "./mcp-command.js";
|
|
@@ -200,6 +201,16 @@ function parseRemoteControlCommand(prompt) {
|
|
|
200
201
|
return { action: "disconnect" };
|
|
201
202
|
return argument ? { action: "connect", name: argument } : { action: "connect" };
|
|
202
203
|
}
|
|
204
|
+
/** A top-level message a person typed in another client of the session, such
|
|
205
|
+
* as claude.ai or the Claude mobile app over Remote Control. Tool results and
|
|
206
|
+
* the CLI's own synthetic messages are user-role too, but carry no human
|
|
207
|
+
* origin. */
|
|
208
|
+
function isRemoteHumanMessage(message) {
|
|
209
|
+
return (message.type === "user" &&
|
|
210
|
+
message.origin?.kind === "human" &&
|
|
211
|
+
message.parent_tool_use_id === null &&
|
|
212
|
+
!message.isSynthetic);
|
|
213
|
+
}
|
|
203
214
|
/** Whether Claude Code offers a slash command of this name to an ACP client.
|
|
204
215
|
* This is the rule `getAvailableSlashCommands` applies when it lists the
|
|
205
216
|
* commands, so the adapter stands in for the command exactly when the client
|
|
@@ -332,7 +343,8 @@ const UNREPORTED_FOREGROUND = {
|
|
|
332
343
|
/** Whether this turn's terminal result arrived but its settlement is being
|
|
333
344
|
* held for background subagents it spawned (see Turn.deferredSettle). The
|
|
334
345
|
* single spelling of the hold predicate, shared by the consumer's settle
|
|
335
|
-
* lanes and cancel().
|
|
346
|
+
* lanes and cancel(). Always false for a client with `backgroundSubagents`,
|
|
347
|
+
* because no turn of that client is held. */
|
|
336
348
|
function isHeldOpen(turn) {
|
|
337
349
|
return turn != null && turn.deferredSettle !== undefined && !turn.settled;
|
|
338
350
|
}
|
|
@@ -739,7 +751,6 @@ const LOCAL_COMMAND_MARKERS = [
|
|
|
739
751
|
// model that a background task stopped; live, the SDK `task_notification`
|
|
740
752
|
// frame reports the same stop, so replay restores the task state from it (see
|
|
741
753
|
// taskNotificationsOf) instead of showing it.
|
|
742
|
-
const TASK_NOTIFICATION_TAG = "task-notification";
|
|
743
754
|
const INJECTED_CONTEXT_MARKERS = ["system-reminder", TASK_NOTIFICATION_TAG].map((tag) => ({
|
|
744
755
|
open: `<${tag}>`,
|
|
745
756
|
close: `</${tag}>`,
|
|
@@ -773,17 +784,6 @@ function stripMarkerTags(text) {
|
|
|
773
784
|
}
|
|
774
785
|
return result + text.slice(copiedUpTo);
|
|
775
786
|
}
|
|
776
|
-
function markerTagText(text, tag) {
|
|
777
|
-
const open = `<${tag}>`;
|
|
778
|
-
const close = `</${tag}>`;
|
|
779
|
-
const start = text.indexOf(open);
|
|
780
|
-
if (start === -1)
|
|
781
|
-
return undefined;
|
|
782
|
-
const end = text.indexOf(close, start + open.length);
|
|
783
|
-
if (end === -1)
|
|
784
|
-
return undefined;
|
|
785
|
-
return text.slice(start + open.length, end);
|
|
786
|
-
}
|
|
787
787
|
function hasMarkerTag(text, tag) {
|
|
788
788
|
return markerTagText(text, tag) !== undefined;
|
|
789
789
|
}
|
|
@@ -842,44 +842,6 @@ export function stripLocalCommandMetadata(content) {
|
|
|
842
842
|
export function isLocalCommandMetadata(content) {
|
|
843
843
|
return stripLocalCommandMetadata(content) === null;
|
|
844
844
|
}
|
|
845
|
-
/**
|
|
846
|
-
* Returns each `<task-notification>` in user-message content (a string or its
|
|
847
|
-
* text blocks). The `<result>` body is model context that the live frame does
|
|
848
|
-
* not carry, so the scan stops at it and a tag quoted in it cannot match.
|
|
849
|
-
*/
|
|
850
|
-
function taskNotificationsOf(content) {
|
|
851
|
-
const texts = typeof content === "string"
|
|
852
|
-
? [content]
|
|
853
|
-
: Array.isArray(content)
|
|
854
|
-
? content.flatMap((block) => block?.type === "text" && typeof block.text === "string" ? [block.text] : [])
|
|
855
|
-
: [];
|
|
856
|
-
const open = `<${TASK_NOTIFICATION_TAG}>`;
|
|
857
|
-
const close = `</${TASK_NOTIFICATION_TAG}>`;
|
|
858
|
-
const notifications = [];
|
|
859
|
-
for (const text of texts) {
|
|
860
|
-
let start = text.indexOf(open);
|
|
861
|
-
while (start !== -1) {
|
|
862
|
-
const end = text.indexOf(close, start + open.length);
|
|
863
|
-
if (end === -1)
|
|
864
|
-
break;
|
|
865
|
-
const body = text.slice(start + open.length, end).split("<result>", 1)[0];
|
|
866
|
-
const field = (tag) => markerTagText(body, tag)?.trim() || undefined;
|
|
867
|
-
const taskId = field("task-id");
|
|
868
|
-
const status = field("status");
|
|
869
|
-
if (taskId && status) {
|
|
870
|
-
notifications.push({
|
|
871
|
-
task_id: taskId,
|
|
872
|
-
status,
|
|
873
|
-
tool_use_id: field("tool-use-id"),
|
|
874
|
-
summary: field("summary"),
|
|
875
|
-
output_file: field("output-file"),
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
start = text.indexOf(open, end + close.length);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
return notifications;
|
|
882
|
-
}
|
|
883
845
|
/**
|
|
884
846
|
* True for a user record that the CLI wrote to tell the model that a
|
|
885
847
|
* background task stopped. A `subkind` marks the delivery of a prompt, for
|
|
@@ -1232,6 +1194,16 @@ export class ClaudeAcpAgent {
|
|
|
1232
1194
|
interruptSession: (sessionId) => this.cancelTurns({ sessionId }, { awaitInterrupt: false }),
|
|
1233
1195
|
teardownSession: (sessionId) => this.teardownSession(sessionId),
|
|
1234
1196
|
});
|
|
1197
|
+
/**
|
|
1198
|
+
* Whether a turn ends at its result while background subagents that it
|
|
1199
|
+
* spawned or resumed still run. Only an ACP v1 AIR client that declares
|
|
1200
|
+
* `backgroundSubagents` gets this. Every other client keeps the hold of
|
|
1201
|
+
* `Turn.deferredSettle`.
|
|
1202
|
+
*/
|
|
1203
|
+
endsTurnsWithLiveSubagents() {
|
|
1204
|
+
return (!this.v2 &&
|
|
1205
|
+
clientSupportsAirCapability(this.clientCapabilities, AIR_BACKGROUND_SUBAGENTS_CAPABILITY));
|
|
1206
|
+
}
|
|
1235
1207
|
constructor(client, logger, options = {}) {
|
|
1236
1208
|
this.v2 = options.v2 ?? false;
|
|
1237
1209
|
this.foregroundEvents = options.foreground;
|
|
@@ -1456,7 +1428,9 @@ export class ClaudeAcpAgent {
|
|
|
1456
1428
|
// `jetbrains.air`.
|
|
1457
1429
|
_meta: {
|
|
1458
1430
|
...(this.toolCallCapabilities.air.client
|
|
1459
|
-
? withAirMeta(airSessionFailureCapabilityMeta(AGENT_FILE_CHANGE_REPORT_CAPABILITY, AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY, AIR_ASYNC_TASKS_CAPABILITY, AIR_CUSTOM_INSTRUCTIONS_CAPABILITY, AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY, AIR_DIFF_PATCH_CAPABILITY, AIR_PLAN_FILE_CAPABILITY,
|
|
1431
|
+
? withAirMeta(airSessionFailureCapabilityMeta(AGENT_FILE_CHANGE_REPORT_CAPABILITY, AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY, AIR_ASYNC_TASKS_CAPABILITY, AIR_CUSTOM_INSTRUCTIONS_CAPABILITY, AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY, AIR_DIFF_PATCH_CAPABILITY, AIR_PLAN_FILE_CAPABILITY,
|
|
1432
|
+
// ACP v2 keeps the hold (see `src/v2/prompt.ts`).
|
|
1433
|
+
...(this.v2 ? [] : [AIR_BACKGROUND_SUBAGENTS_CAPABILITY]), ...this.sessionIndex.capabilities()), AIR_GOAL_KEY, {
|
|
1460
1434
|
version: GOAL_EXTENSION_VERSION,
|
|
1461
1435
|
controlMethod: GOAL_CONTROL_METHOD,
|
|
1462
1436
|
actions: [...GOAL_ACTIONS],
|
|
@@ -2175,6 +2149,11 @@ export class ClaudeAcpAgent {
|
|
|
2175
2149
|
if (session.remoteControlCommand) {
|
|
2176
2150
|
throw RequestError.invalidRequest(undefined, "Remote Control is already being changed. Try again in a moment.");
|
|
2177
2151
|
}
|
|
2152
|
+
// Once Remote Control is on, other clients can start turns or send
|
|
2153
|
+
// messages on their own. Something has to read the query stream for
|
|
2154
|
+
// those to reach this client, and a command that answers without a turn
|
|
2155
|
+
// would otherwise leave the stream unread until the next prompt.
|
|
2156
|
+
this.ensureConsumer(session, params.sessionId);
|
|
2178
2157
|
// Answered by the adapter without a model turn; v2 clients treat an
|
|
2179
2158
|
// `ended` without a prior `inserted` as a refused prompt.
|
|
2180
2159
|
events.inserted(randomUUID());
|
|
@@ -2271,8 +2250,10 @@ export class ClaudeAcpAgent {
|
|
|
2271
2250
|
};
|
|
2272
2251
|
session.turnQueue ??= [];
|
|
2273
2252
|
session.turnQueue.push(turn);
|
|
2253
|
+
(session.sentUserUuids ??= new Set()).add(promptUuid);
|
|
2274
2254
|
session.input.push(userMessage);
|
|
2275
2255
|
this.ensureConsumer(session, params.sessionId);
|
|
2256
|
+
session.titles.onPromptQueued(session, params.prompt);
|
|
2276
2257
|
// The prompt is queued, so its turn goes ahead even if the client misses
|
|
2277
2258
|
// the goal it sets; the turn's events report the outcome.
|
|
2278
2259
|
await this.publishGoalFromPrompt(params.sessionId, firstText, promptUuid).catch((error) => this.logger.error(`Session ${params.sessionId}: failed to publish the prompt's goal:`, error));
|
|
@@ -2660,6 +2641,7 @@ export class ClaudeAcpAgent {
|
|
|
2660
2641
|
// The held turn's work had ended at its result; the steer resumes it.
|
|
2661
2642
|
this.startForeground(sessionId, turnInFlight);
|
|
2662
2643
|
}
|
|
2644
|
+
(session.sentUserUuids ??= new Set()).add(steeredUuid);
|
|
2663
2645
|
session.input.push(userMessage);
|
|
2664
2646
|
const firstText = params.prompt[0]?.type === "text" ? params.prompt[0].text : "";
|
|
2665
2647
|
await this.publishGoalFromPrompt(sessionId, firstText, steeredUuid);
|
|
@@ -2776,10 +2758,29 @@ export class ClaudeAcpAgent {
|
|
|
2776
2758
|
// Tool-use blocks start streaming before their JSON input. Keep the
|
|
2777
2759
|
// partial input per parent message and block index so completed top-level
|
|
2778
2760
|
// fields can refine the pending tool call while it streams. Entries are
|
|
2779
|
-
// dropped at block/message boundaries; the
|
|
2761
|
+
// dropped at block/message boundaries; the map is swept when a turn
|
|
2780
2762
|
// settles, since an interrupted subagent stream (keyed by a
|
|
2781
2763
|
// parent_tool_use_id that never recurs) has no boundary event of its own.
|
|
2782
2764
|
const streamedToolInputs = new Map();
|
|
2765
|
+
/** Sweeps `streamedToolInputs` when a turn ends. A turn of a client with
|
|
2766
|
+
* `backgroundSubagents` can end while its subagents still stream tool
|
|
2767
|
+
* input, so the sweep keeps the lanes of live subagents, unless the turn
|
|
2768
|
+
* ends cancelled. Their own message boundaries drop them later. */
|
|
2769
|
+
const sweepStreamedToolInputs = (turnStopReason) => {
|
|
2770
|
+
if (turnStopReason === "cancelled" || !this.endsTurnsWithLiveSubagents()) {
|
|
2771
|
+
streamedToolInputs.clear();
|
|
2772
|
+
return;
|
|
2773
|
+
}
|
|
2774
|
+
const liveLanes = new Set();
|
|
2775
|
+
for (const task of session.liveBackgroundTasks.values()) {
|
|
2776
|
+
if (task.isSubagent && task.parentToolUseId)
|
|
2777
|
+
liveLanes.add(task.parentToolUseId);
|
|
2778
|
+
}
|
|
2779
|
+
for (const lane of streamedToolInputs.keys()) {
|
|
2780
|
+
if (!liveLanes.has(lane))
|
|
2781
|
+
streamedToolInputs.delete(lane);
|
|
2782
|
+
}
|
|
2783
|
+
};
|
|
2783
2784
|
// Stop reason accumulated for the active turn (result subtype, refusal,
|
|
2784
2785
|
// max_tokens, …). Reset per turn; read when the turn settles at idle.
|
|
2785
2786
|
let stopReason = "end_turn";
|
|
@@ -3271,9 +3272,10 @@ export class ClaudeAcpAgent {
|
|
|
3271
3272
|
};
|
|
3272
3273
|
/** Registers a live background task (see `liveBackgroundTasks`). A
|
|
3273
3274
|
* subagent is also recorded on the active turn, so that turn holds until
|
|
3274
|
-
* the subagent settles (see `Turn.spawnedTaskIds`).
|
|
3275
|
-
*
|
|
3276
|
-
*
|
|
3275
|
+
* the subagent settles (see `Turn.spawnedTaskIds`). A client with
|
|
3276
|
+
* `backgroundSubagents` gets no hold (see `turnAwaitingSubagents`).
|
|
3277
|
+
* Its requests may already be open, and where it runs decides
|
|
3278
|
+
* whether they block the foreground work, so that is checked again. */
|
|
3277
3279
|
const registerLiveTask = (taskId, parentToolUseId, isSubagent, placement = {}) => {
|
|
3278
3280
|
session.liveBackgroundTasks.set(taskId, {
|
|
3279
3281
|
parentToolUseId,
|
|
@@ -3321,8 +3323,9 @@ export class ClaudeAcpAgent {
|
|
|
3321
3323
|
};
|
|
3322
3324
|
/** Registers a settled subagent again when the SDK resumes it without a
|
|
3323
3325
|
* new `task_started`. The active turn is the one that resumed it, so it
|
|
3324
|
-
* holds until the subagent settles again
|
|
3325
|
-
*
|
|
3326
|
+
* holds until the subagent settles again, unless the client declared
|
|
3327
|
+
* `backgroundSubagents`. A repeated resume signal finds the subagent live
|
|
3328
|
+
* and changes nothing. */
|
|
3326
3329
|
const resumeLiveTask = (taskId) => {
|
|
3327
3330
|
if (session.liveBackgroundTasks.has(taskId))
|
|
3328
3331
|
return;
|
|
@@ -3334,9 +3337,12 @@ export class ClaudeAcpAgent {
|
|
|
3334
3337
|
/** Whether any background subagent this turn spawned is still live —
|
|
3335
3338
|
* while true, the turn's settlement stays deferred so the subagent's
|
|
3336
3339
|
* output and permission requests land inside it (see
|
|
3337
|
-
* Turn.deferredSettle).
|
|
3340
|
+
* Turn.deferredSettle). Always false for a client that declared
|
|
3341
|
+
* `backgroundSubagents`: its turns end at their result, and the subagent
|
|
3342
|
+
* traffic goes out after the prompt response. This is the single gate of
|
|
3343
|
+
* the hold, so no turn of such a client is ever held open. */
|
|
3338
3344
|
const turnAwaitingSubagents = (turn) => {
|
|
3339
|
-
if (!turn.spawnedTaskIds?.size) {
|
|
3345
|
+
if (this.endsTurnsWithLiveSubagents() || !turn.spawnedTaskIds?.size) {
|
|
3340
3346
|
return false;
|
|
3341
3347
|
}
|
|
3342
3348
|
for (const taskId of turn.spawnedTaskIds) {
|
|
@@ -3367,7 +3373,8 @@ export class ClaudeAcpAgent {
|
|
|
3367
3373
|
* turn open (see Turn.deferredSettle). Every result-time settle of a
|
|
3368
3374
|
* turn that can have spawned subagents must route through here: a site
|
|
3369
3375
|
* calling settleActive directly bypasses the hold and re-opens the
|
|
3370
|
-
* out-of-turn permission deadlock (issue #866) through its lane.
|
|
3376
|
+
* out-of-turn permission deadlock (issue #866) through its lane. For a
|
|
3377
|
+
* client with `backgroundSubagents` this always settles now. */
|
|
3371
3378
|
const settleOrDefer = async (outcome) => {
|
|
3372
3379
|
// No result ends a steered turn: the steer aborted the cycle this result
|
|
3373
3380
|
// may belong to, and the steered one is still to come. Record the outcome
|
|
@@ -3646,7 +3653,7 @@ export class ClaudeAcpAgent {
|
|
|
3646
3653
|
disarmForceCancel(session);
|
|
3647
3654
|
session.turnQueue = (session.turnQueue ?? []).filter((t) => t !== turn);
|
|
3648
3655
|
session.activeTurn = null;
|
|
3649
|
-
|
|
3656
|
+
sweepStreamedToolInputs(result.stopReason);
|
|
3650
3657
|
if (wasHeld) {
|
|
3651
3658
|
// Settling a held turn is its delivery-stretch boundary: the turn's
|
|
3652
3659
|
// answer finished long ago, so text streamed since the last boundary
|
|
@@ -3677,7 +3684,7 @@ export class ClaudeAcpAgent {
|
|
|
3677
3684
|
turn.settled = true;
|
|
3678
3685
|
session.turnQueue = (session.turnQueue ?? []).filter((t) => t !== turn);
|
|
3679
3686
|
session.activeTurn = null;
|
|
3680
|
-
|
|
3687
|
+
sweepStreamedToolInputs();
|
|
3681
3688
|
// A failed turn's stretch is over, and some failure lanes (the issue
|
|
3682
3689
|
// #825 idle-fail) never see the result whose `finally` would close it —
|
|
3683
3690
|
// start the next stretch clean, or its stale delivery record would
|
|
@@ -5153,6 +5160,33 @@ export class ClaudeAcpAgent {
|
|
|
5153
5160
|
await settleOrDefer({ ...heldTurn.deferredSettle, stopReason: "cancelled" });
|
|
5154
5161
|
break;
|
|
5155
5162
|
}
|
|
5163
|
+
// The same followup with no held turn: the client declared
|
|
5164
|
+
// `backgroundSubagents`, or the hold already ended. A user
|
|
5165
|
+
// turn that took the cycle over owns the request (see
|
|
5166
|
+
// `requestOwnerTurn`), so it continues the accepted plan in a
|
|
5167
|
+
// fresh context, as the user lane does. With no such turn
|
|
5168
|
+
// the user answered out of a turn, and the interrupt only
|
|
5169
|
+
// stops this autonomous cycle. Drop the markers, so that a
|
|
5170
|
+
// later user-turn result is not read as this interruption.
|
|
5171
|
+
// `canUseTool` offers no clear-context option to a request
|
|
5172
|
+
// without an owner turn, so a reset here is only a race with
|
|
5173
|
+
// the end of a turn.
|
|
5174
|
+
if (pendingExitPlanModeInterruption &&
|
|
5175
|
+
isExitPlanInterruptionResult(message, pendingExitPlanModeInterruption)) {
|
|
5176
|
+
session.pendingExitPlanModeInterruption = undefined;
|
|
5177
|
+
const ownerTurn = this.requestOwnerTurn(params.sessionId, session);
|
|
5178
|
+
if (pendingExitPlanContextReset?.toolUseId ===
|
|
5179
|
+
pendingExitPlanModeInterruption.toolUseId &&
|
|
5180
|
+
ownerTurn !== undefined &&
|
|
5181
|
+
ownerTurn === session.activeTurn) {
|
|
5182
|
+
await this.exitPlan.restart(params.sessionId, session, pendingExitPlanContextReset);
|
|
5183
|
+
return;
|
|
5184
|
+
}
|
|
5185
|
+
if (pendingExitPlanContextReset) {
|
|
5186
|
+
session.pendingExitPlanContextReset = undefined;
|
|
5187
|
+
this.logger.error(`Session ${params.sessionId}: no turn to continue the accepted plan in a fresh context`);
|
|
5188
|
+
}
|
|
5189
|
+
}
|
|
5156
5190
|
// CLI 2.1.274+ answers background-task completions that were
|
|
5157
5191
|
// already queued with ONE model call: every queued
|
|
5158
5192
|
// notification still gets its own result, but all except the
|
|
@@ -5406,7 +5440,9 @@ export class ClaudeAcpAgent {
|
|
|
5406
5440
|
// permission requests, and the model's promised summary all land
|
|
5407
5441
|
// inside the turn. `session/cancel` and the next prompt's echo
|
|
5408
5442
|
// hand-off still settle a deferred turn early, so a long-running
|
|
5409
|
-
// subagent never holds the prompt hostage.
|
|
5443
|
+
// subagent never holds the prompt hostage. A client with
|
|
5444
|
+
// `backgroundSubagents` gets no hold: the turn settles here, and
|
|
5445
|
+
// the subagent traffic goes out after the prompt response.
|
|
5410
5446
|
//
|
|
5411
5447
|
// is_error/auth already settled via failActive (activeTurn is null
|
|
5412
5448
|
// then, so both branches no-op); a cancelled turn settles at
|
|
@@ -5655,6 +5691,9 @@ export class ClaudeAcpAgent {
|
|
|
5655
5691
|
if (session.pendingGoalUpdate?.commandUuid === message.uuid) {
|
|
5656
5692
|
session.pendingGoalUpdate.started = true;
|
|
5657
5693
|
}
|
|
5694
|
+
// Taken out for every echo, not only in the branch below, so the
|
|
5695
|
+
// set does not grow with each prompt.
|
|
5696
|
+
const sentByAdapter = session.sentUserUuids?.delete(message.uuid) ?? false;
|
|
5658
5697
|
const queued = findUnsettledTurn(message.uuid);
|
|
5659
5698
|
if (queued) {
|
|
5660
5699
|
// Only (re)activate if this isn't already the active turn — a
|
|
@@ -5740,7 +5779,25 @@ export class ClaudeAcpAgent {
|
|
|
5740
5779
|
session.activeTurn.steeredEchoes.delete(message.uuid)) {
|
|
5741
5780
|
session.activeTurn.steeredAwaitingResult = true;
|
|
5742
5781
|
}
|
|
5743
|
-
//
|
|
5782
|
+
// A message typed in another client of the session (Remote
|
|
5783
|
+
// Control from claude.ai or the mobile app). The adapter's own
|
|
5784
|
+
// prompts and steers are stamped human too, so they are told
|
|
5785
|
+
// apart by uuid: a steer matches no turn, and a turn can settle
|
|
5786
|
+
// before its echo comes.
|
|
5787
|
+
const remoteContent = !sentByAdapter && isRemoteHumanMessage(message)
|
|
5788
|
+
? stripLocalCommandMetadata(message.message.content)
|
|
5789
|
+
: null;
|
|
5790
|
+
if (remoteContent !== null) {
|
|
5791
|
+
for (const notification of toAcpNotifications(remoteContent, "user", params.sessionId, session.toolUseCache, routedNotificationClient, this.logger, {
|
|
5792
|
+
clientCapabilities: this.clientCapabilities,
|
|
5793
|
+
toolCallCapabilities: this.toolCallCapabilities,
|
|
5794
|
+
cwd: session.cwd,
|
|
5795
|
+
messageId: messageIdForGrouping(message),
|
|
5796
|
+
})) {
|
|
5797
|
+
await sendUpdate(notification);
|
|
5798
|
+
}
|
|
5799
|
+
}
|
|
5800
|
+
// Otherwise an unrelated replay (e.g. the echo of an already-settled turn).
|
|
5744
5801
|
break;
|
|
5745
5802
|
}
|
|
5746
5803
|
}
|
|
@@ -7119,6 +7176,8 @@ export class ClaudeAcpAgent {
|
|
|
7119
7176
|
isNativeSubagentControlTool(toolName)) {
|
|
7120
7177
|
continue;
|
|
7121
7178
|
}
|
|
7179
|
+
if (rfdReplay && (await rfdReplay.toolCallUpdate(notification.update, child)))
|
|
7180
|
+
continue;
|
|
7122
7181
|
await this.client.sessionUpdate({ ...notification, sessionId: replayTargetSessionId });
|
|
7123
7182
|
}
|
|
7124
7183
|
// The history of each subagent is in its own transcript. The replay
|
|
@@ -7410,6 +7469,21 @@ export class ClaudeAcpAgent {
|
|
|
7410
7469
|
runsAutonomousCycle(sessionId) {
|
|
7411
7470
|
return this.foregroundWork.get(sessionId)?.owner === AUTONOMOUS_CYCLE;
|
|
7412
7471
|
}
|
|
7472
|
+
/** The ACP turn that owns a root request of the session now, if any. A
|
|
7473
|
+
* model cycle that Claude Code started on its own owns no turn. A turn that
|
|
7474
|
+
* took a cycle over owns it. A queued turn owns the request too, because
|
|
7475
|
+
* Claude Code can ask for a queued prompt before the consumer reaches its
|
|
7476
|
+
* echo (see `recordForegroundToolCall`). The ExitPlanMode request and the
|
|
7477
|
+
* result of its interruption use this one rule, so an offered
|
|
7478
|
+
* clear-context option always has a turn to continue. */
|
|
7479
|
+
requestOwnerTurn(sessionId, session) {
|
|
7480
|
+
if (this.runsAutonomousCycle(sessionId))
|
|
7481
|
+
return undefined;
|
|
7482
|
+
const active = session.activeTurn;
|
|
7483
|
+
if (active && !active.settled)
|
|
7484
|
+
return active;
|
|
7485
|
+
return session.turnQueue?.find((queued) => !queued.settled);
|
|
7486
|
+
}
|
|
7413
7487
|
/** Forward a permission request to the client, wiring the tool call's
|
|
7414
7488
|
* `signal` through as a `cancellationSignal`. When the turn is cancelled
|
|
7415
7489
|
* while the client's prompt is still open the signal aborts, the SDK sends
|
|
@@ -7694,6 +7768,11 @@ export class ClaudeAcpAgent {
|
|
|
7694
7768
|
defaultToNo,
|
|
7695
7769
|
availableModes: this.sessionModes.availableModeIds(session.modes),
|
|
7696
7770
|
prePlanMode: session.prePlanMode,
|
|
7771
|
+
// A fresh context continues the ACP turn that owns the request. With
|
|
7772
|
+
// `backgroundSubagents` a followup cycle can ask out of a turn, and
|
|
7773
|
+
// then there is no turn to continue.
|
|
7774
|
+
allowContextReset: !this.endsTurnsWithLiveSubagents() ||
|
|
7775
|
+
this.requestOwnerTurn(sessionId, session) !== undefined,
|
|
7697
7776
|
contextUsedPercent: session.contextUsedTokens === undefined || session.contextWindowSize <= 0
|
|
7698
7777
|
? undefined
|
|
7699
7778
|
: Math.max(0, Math.min(100, Math.round((session.contextUsedTokens / session.contextWindowSize) * 100))),
|
package/dist/acp-subagents.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export { AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY } from "./air-extension.js";
|
|
|
6
6
|
* - `rfd`: the subagents RFD (agentclientprotocol/agent-client-protocol#1992,
|
|
7
7
|
* as revised): `subagent_update` and `session_message`, which the SDK types.
|
|
8
8
|
* A client that declares `clientCapabilities.subagents` and is not AIR gets
|
|
9
|
-
* it. (ACP v2
|
|
9
|
+
* it. (An ACP v2 client gets it without declaring anything, since subagents
|
|
10
|
+
* are part of v2's baseline.)
|
|
10
11
|
* - `air`: the earlier draft of that RFD, which AIR implements:
|
|
11
12
|
* `subagent_spawned` and `subagent_state_update`, typed below. AIR gets it,
|
|
12
13
|
* whichever capability it declares (`docs/air-extensions.md`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acp-subagents.d.ts","sourceRoot":"","sources":["../src/acp-subagents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAO3C,OAAO,EAAE,uCAAuC,EAAE,MAAM,oBAAoB,CAAC;AAE7E
|
|
1
|
+
{"version":3,"file":"acp-subagents.d.ts","sourceRoot":"","sources":["../src/acp-subagents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAO3C,OAAO,EAAE,uCAAuC,EAAE,MAAM,oBAAoB,CAAC;AAE7E;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,CAAC;AAEzC,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,YAAY,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,YAAY,GAAG,SAAS,CAG/F;AAED;;;GAGG;AACH,MAAM,MAAM,2BA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M,gCAAgC,GAAG,mBAAmB,GAAG;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CACnC,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,YAAY,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,OAAO,CASzF;AAED,yEAAyE;AACzE,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,sBAAsB,GACnC,mBAAmB,CAErB"}
|
package/dist/air-extension.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export declare const AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY = "nativeSubagentSessions";
|
|
2
2
|
export declare const AIR_ASYNC_TASKS_CAPABILITY = "asyncTasks";
|
|
3
|
+
/**
|
|
4
|
+
* A prompt turn ends at its result also while its background subagents run.
|
|
5
|
+
* The subagent updates and requests then go out after the prompt response.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AIR_BACKGROUND_SUBAGENTS_CAPABILITY = "backgroundSubagents";
|
|
3
8
|
export declare const AIR_SESSION_FAILURE_CAPABILITY = "sessionFailure";
|
|
4
9
|
export declare const AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY = "recommendedValue";
|
|
5
10
|
export declare const AIR_CUSTOM_INSTRUCTIONS_CAPABILITY = "customInstructions";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"air-extension.d.ts","sourceRoot":"","sources":["../src/air-extension.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uCAAuC,2BAA2B,CAAC;AAChF,eAAO,MAAM,0BAA0B,eAAe,CAAC;AACvD,eAAO,MAAM,8BAA8B,mBAAmB,CAAC;AAC/D,eAAO,MAAM,uCAAuC,qBAAqB,CAAC;AAC1E,eAAO,MAAM,kCAAkC,uBAAuB,CAAC;AACvE,eAAO,MAAM,yBAAyB,cAAc,CAAC;AACrD,4EAA4E;AAC5E,eAAO,MAAM,kCAAkC,sBAAsB,CAAC;AACtE;;;GAGG;A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AE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GACpC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAErC;AAED,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAKnF;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAY9F;AAED,4DAA4D;AAC5D,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAIvE"}
|
package/dist/air-extension.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export const AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY = "nativeSubagentSessions";
|
|
2
2
|
export const AIR_ASYNC_TASKS_CAPABILITY = "asyncTasks";
|
|
3
|
+
/**
|
|
4
|
+
* A prompt turn ends at its result also while its background subagents run.
|
|
5
|
+
* The subagent updates and requests then go out after the prompt response.
|
|
6
|
+
*/
|
|
7
|
+
export const AIR_BACKGROUND_SUBAGENTS_CAPABILITY = "backgroundSubagents";
|
|
3
8
|
export const AIR_SESSION_FAILURE_CAPABILITY = "sessionFailure";
|
|
4
9
|
export const AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY = "recommendedValue";
|
|
5
10
|
export const AIR_CUSTOM_INSTRUCTIONS_CAPABILITY = "customInstructions";
|
|
@@ -36,6 +36,7 @@ export type ClearContextSession<Turn extends ClearContextTurn = ClearContextTurn
|
|
|
36
36
|
turnQueue?: Turn[];
|
|
37
37
|
pendingExitPlanContextReset?: ClearContextReset;
|
|
38
38
|
contextUsedTokens?: number;
|
|
39
|
+
sentUserUuids?: Set<string>;
|
|
39
40
|
input: {
|
|
40
41
|
push(message: SDKUserMessage): unknown;
|
|
41
42
|
};
|
|
@@ -1 +1 @@
|
|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,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,CAmDf"}
|
|
@@ -73,6 +73,7 @@ export async function continuePlanInFreshContext(sessionId, oldSession, reset, h
|
|
|
73
73
|
host.logError("Failed to publish clear-context session state:", error);
|
|
74
74
|
}
|
|
75
75
|
assertRestartActive(freshSession);
|
|
76
|
+
(freshSession.sentUserUuids ??= new Set()).add(turn.promptUuid);
|
|
76
77
|
freshSession.input.push(host.continuationMessage(sessionId, reset.plan, turn.promptUuid));
|
|
77
78
|
assertRestartActive(freshSession);
|
|
78
79
|
host.ensureConsumer(freshSession, sessionId);
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { claudeCliPath } from "./acp-agent.js";
|
|
3
3
|
import { applyManagedPolicyEnv } from "./managed-policy.js";
|
|
4
|
-
import { serveAcp } from "./serve.js";
|
|
4
|
+
import { acpProtocolsFromEnv, serveAcp } from "./serve.js";
|
|
5
5
|
import packageJson from "../package.json" with { type: "json" };
|
|
6
6
|
import { appendFileSync, mkdirSync } from "node:fs";
|
|
7
7
|
import { join } from "node:path";
|
|
@@ -78,9 +78,8 @@ else {
|
|
|
78
78
|
})()
|
|
79
79
|
: undefined;
|
|
80
80
|
logger?.log("Claude ACP started");
|
|
81
|
-
// The draft ACP v2 is opt-in while it is a draft.
|
|
82
81
|
const acp = serveAcp(logger, {
|
|
83
|
-
|
|
82
|
+
protocols: acpProtocolsFromEnv(process.env.CLAUDE_AGENT_ACP_PROTOCOL),
|
|
84
83
|
});
|
|
85
84
|
async function shutdown() {
|
|
86
85
|
await acp.dispose().catch((err) => {
|
|
@@ -41,6 +41,8 @@ export type NativeSubagent = {
|
|
|
41
41
|
promptIds?: Set<string>;
|
|
42
42
|
/** The RFD form: the calls that delegated to the child, whose runs ended. */
|
|
43
43
|
endedRuns?: Set<string>;
|
|
44
|
+
/** The RFD form: the calls that delegated to the child, whose runs handed back a report. */
|
|
45
|
+
handedBack?: Set<string>;
|
|
44
46
|
announced?: boolean;
|
|
45
47
|
terminalState?: SubagentState;
|
|
46
48
|
/** Connection-local single-flight state; never serialized on the wire. */
|
|
@@ -127,6 +129,18 @@ export declare class NativeSubagentRuntime {
|
|
|
127
129
|
private readonly taskFinishPromises;
|
|
128
130
|
/** The session that made each SendMessage call. */
|
|
129
131
|
private readonly senderByToolUse;
|
|
132
|
+
/**
|
|
133
|
+
* The RFD form: the Agent/Task calls that the client is not shown, until
|
|
134
|
+
* their final update. Kept by id because the adapter's own report that
|
|
135
|
+
* closes an unfinished call has no `toolName` to recognize it by.
|
|
136
|
+
*/
|
|
137
|
+
private readonly hiddenLaunches;
|
|
138
|
+
/**
|
|
139
|
+
* The RFD form: the SubagentHandback calls of announced children that the
|
|
140
|
+
* client is not shown yet, with their first report, the report from their
|
|
141
|
+
* input, and the call that delegated the run.
|
|
142
|
+
*/
|
|
143
|
+
private readonly handbacks;
|
|
130
144
|
private readonly generationByTaskId;
|
|
131
145
|
private readonly pending;
|
|
132
146
|
private pendingCount;
|
|
@@ -331,6 +345,25 @@ export declare class NativeSubagentRuntime {
|
|
|
331
345
|
* sender of the prompt when the call resumes a child.
|
|
332
346
|
*/
|
|
333
347
|
private rememberSendMessage;
|
|
348
|
+
/**
|
|
349
|
+
* The RFD form: an update of the Agent/Task call that launches `child`,
|
|
350
|
+
* which the parent's session messages replace. Only a launch whose child
|
|
351
|
+
* was never exposed stays a tool call of the parent, with its final status,
|
|
352
|
+
* since the RFD lets the Agent represent unexposed work through the parent.
|
|
353
|
+
* A background launch completes before its child starts, so its completion
|
|
354
|
+
* is not such a case.
|
|
355
|
+
*/
|
|
356
|
+
private routeRfdLaunch;
|
|
357
|
+
/**
|
|
358
|
+
* The RFD form: an update of a SubagentHandback call of the announced
|
|
359
|
+
* `child`, which its report replaces: the child's message to its parent,
|
|
360
|
+
* see {@link linkedSessionMessages}. A failed call delivered nothing, so the
|
|
361
|
+
* child is shown the call after all. `undefined` for any other update.
|
|
362
|
+
*/
|
|
363
|
+
private routeRfdHandback;
|
|
364
|
+
/** Whether `update` is of an Agent/Task call, by its tool name or, in the
|
|
365
|
+
* RFD form, by the id of a call the client is not shown. */
|
|
366
|
+
private isControlUpdate;
|
|
334
367
|
private rememberToolCallOwner;
|
|
335
368
|
/**
|
|
336
369
|
* The RFD form: how many cancels the client sent for `child`, its
|
|
@@ -384,6 +417,37 @@ export declare class NativeSubagentRuntime {
|
|
|
384
417
|
*/
|
|
385
418
|
export declare function announceNativeSubagent(child: NativeSubagent, publish: Publish, form: SubagentForm): Promise<void>;
|
|
386
419
|
export declare function finishNativeSubagent(session: NativeSubagentSession, taskId: string, state: SubagentState, publish: Publish): Promise<void>;
|
|
420
|
+
/**
|
|
421
|
+
* The RFD form: a message that a tool call sent, which the client is not
|
|
422
|
+
* shown, as two session messages: the sender's outgoing view, then the
|
|
423
|
+
* recipient's incoming one. That call is a launch's Agent/Task call, whose
|
|
424
|
+
* prompt goes from the parent to the child, or a child's SubagentHandback
|
|
425
|
+
* call, whose report goes from the child to the parent. Both views use the
|
|
426
|
+
* call's tool use id, and each names the other with the draft RFD's
|
|
427
|
+
* `recipientMessageId` and `senderMessageId`.
|
|
428
|
+
*/
|
|
429
|
+
export declare function linkedSessionMessages(toolUseId: string, senderSessionId: string, recipientSessionId: string, text: string): AcpSessionNotification[];
|
|
430
|
+
/**
|
|
431
|
+
* The tool with which a child hands its report to its parent, when Claude
|
|
432
|
+
* Code runs in hand-back mode. The Agent/Task result then only says that the
|
|
433
|
+
* report was delivered as a message, with `handback: "send"` in its
|
|
434
|
+
* structured result.
|
|
435
|
+
*/
|
|
436
|
+
export declare const HANDBACK_TOOL = "SubagentHandback";
|
|
437
|
+
/** The report of a SubagentHandback call, from its input. */
|
|
438
|
+
export declare function handbackMessage(input: unknown): string | undefined;
|
|
439
|
+
/**
|
|
440
|
+
* The RFD form: the answer of a foreground child, from the completed result
|
|
441
|
+
* of the Agent/Task call `launchId` that launched it, as the child's message
|
|
442
|
+
* in the parent's transcript (its incoming view). It replaces that call's
|
|
443
|
+
* result, which the parent is not shown. The child's transcript has its
|
|
444
|
+
* answer as its own agent message, not as a session message, so this view
|
|
445
|
+
* links to no other. `undefined` for a result without text. Not used for a
|
|
446
|
+
* run whose child handed back its report: the result has no report then.
|
|
447
|
+
*/
|
|
448
|
+
export declare function launchReply(launchId: string, childSessionId: string, parentSessionId: string, result: Extract<AcpSessionNotification["update"], {
|
|
449
|
+
sessionUpdate: "tool_call_update" | "tool_call";
|
|
450
|
+
}>): AcpSessionNotification | undefined;
|
|
387
451
|
/**
|
|
388
452
|
* The RFD form: the work state at the end of a child's work.
|
|
389
453
|
*
|