@agentclientprotocol/claude-agent-acp 0.106.1-preview.1 → 0.106.1-preview.11
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 +1 -76
- package/dist/async-tasks.d.ts +1 -1
- package/dist/async-tasks.js +1 -1
- package/dist/context-window.d.ts +11 -9
- package/dist/context-window.d.ts.map +1 -1
- package/dist/context-window.js +12 -13
- package/dist/managed-policy.d.ts +9 -0
- package/dist/managed-policy.d.ts.map +1 -1
- package/dist/managed-policy.js +25 -0
- package/dist/native-subagents.d.ts +72 -9
- package/dist/native-subagents.d.ts.map +1 -1
- package/dist/native-subagents.js +130 -12
- package/dist/session-fast-mode.d.ts +16 -10
- package/dist/session-fast-mode.d.ts.map +1 -1
- package/dist/session-fast-mode.js +36 -25
- package/dist/session-index/transcript-scan.d.ts +4 -2
- package/dist/session-index/transcript-scan.d.ts.map +1 -1
- package/dist/session-index/transcript-scan.js +67 -12
- package/dist/session-model.d.ts +22 -16
- package/dist/session-model.d.ts.map +1 -1
- package/dist/session-model.js +66 -38
- package/dist/session-usage.d.ts +8 -17
- package/dist/session-usage.d.ts.map +1 -1
- package/dist/session-usage.js +8 -21
- package/dist/settings.d.ts +2 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +12 -0
- package/dist/subagent-replay.d.ts +16 -1
- package/dist/subagent-replay.d.ts.map +1 -1
- package/dist/subagent-replay.js +28 -1
- package/dist/tool-calls/renderer.d.ts +31 -1
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +42 -7
- package/dist/tool-calls/retracted.d.ts +29 -0
- package/dist/tool-calls/retracted.d.ts.map +1 -0
- package/dist/tool-calls/retracted.js +66 -0
- package/dist/v1/acp-agent.d.ts +36 -68
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +78 -262
- package/dist/v1/async-task-stop.d.ts +11 -0
- package/dist/v1/async-task-stop.d.ts.map +1 -0
- package/dist/v1/async-task-stop.js +18 -0
- package/dist/v1/session-fingerprint.d.ts +16 -0
- package/dist/v1/session-fingerprint.d.ts.map +1 -0
- package/dist/v1/session-fingerprint.js +129 -0
- package/dist/v1/steering.d.ts +48 -0
- package/dist/v1/steering.d.ts.map +1 -0
- package/dist/v1/steering.js +41 -0
- package/dist/v2/agent.js +10 -4
- package/dist/v2/outcome.d.ts +3 -2
- package/dist/v2/outcome.d.ts.map +1 -1
- package/dist/v2/outcome.js +8 -3
- package/dist/v2/reports.d.ts +2 -2
- package/dist/v2/reports.d.ts.map +1 -1
- package/dist/v2/reports.js +3 -6
- package/dist/v2/session.d.ts +11 -4
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +19 -4
- package/dist/v2/setup.js +1 -1
- package/dist/v2/stream.d.ts +17 -5
- package/dist/v2/stream.d.ts.map +1 -1
- package/dist/v2/stream.js +40 -19
- package/dist/v2/subagent-replay.js +2 -2
- package/dist/v2/tasks.d.ts +29 -11
- package/dist/v2/tasks.d.ts.map +1 -1
- package/dist/v2/tasks.js +69 -19
- package/dist/v2/tool-call.js +3 -0
- package/package.json +5 -5
package/dist/v1/acp-agent.js
CHANGED
|
@@ -12,6 +12,8 @@ import { AIR_ASYNC_TASKS_CAPABILITY, AIR_BACKGROUND_SUBAGENTS_CAPABILITY, AIR_CU
|
|
|
12
12
|
import * as sessionIndex from "./session-index.js";
|
|
13
13
|
import { AsyncTaskRuntime, backgroundBashTaskFromToolResult, backgroundedBashToolCallIds, clientSupportsAsyncTasks, } from "../async-tasks.js";
|
|
14
14
|
import { SessionBackgroundWork } from "./background-work.js";
|
|
15
|
+
import { ASYNC_TASK_STOP_METHOD, parseAsyncTaskStopRequest, } from "./async-task-stop.js";
|
|
16
|
+
import { STEER_METHOD, STEER_PRIORITY_LATER, STEER_PRIORITY_NOW, parseSteerRequest, } from "./steering.js";
|
|
15
17
|
import { AUTH_STATUS_UPDATE_METHOD, authStatusCapability, fromAccountInfo, gatewayAuthStatus, notLoggedInAuthStatus, } from "../auth-status.js";
|
|
16
18
|
import { AuthStatusReporter, cliLogout } from "../auth-status-reporter.js";
|
|
17
19
|
import { terminalAuthMethods as authMethodsForTerminal } from "../auth-methods.js";
|
|
@@ -43,13 +45,14 @@ import { ContextCompactionLifecycle, clientSupportsCompactionUpdates, contextCom
|
|
|
43
45
|
import { IdleCompaction } from "../idle-compaction.js";
|
|
44
46
|
import { clientSupportsNotices, collapseHookSpeaker, informationalNotice, MAX_NOTICE_TITLE_LENGTH, mcpServerStartupNotice, modelRefusalFallback, normalizeNoticeText, noticeOrTranscriptUpdate, sentenceCase, } from "../session-notices.js";
|
|
45
47
|
import { clearHookCallbacks, createPostToolUseHook, createTaskHook, changedTaskPlanEntries, forgetPublishedTaskPlan, unregisterHookCallback, } from "../tools.js";
|
|
46
|
-
import { addModelUsage,
|
|
48
|
+
import { addModelUsage, getMatchingModelUsage, modelUsageIncrement, normalizeModelUsage, quotaMeta, resumedFirstResultModelUsage, snapshotFromUsage, tallyTotal, totalTokens, ZERO_USAGE, } from "../session-usage.js";
|
|
47
49
|
import { previewPatchContent } from "../diff.js";
|
|
48
50
|
import { backgroundedBashToolCall, withRunningTerminal } from "../tool-calls/background.js";
|
|
49
51
|
import { ChangedMetaClient, ClientConnection } from "./client-connection.js";
|
|
50
52
|
import { ToolCallFieldTracker } from "../tool-calls/field-tracker.js";
|
|
53
|
+
import { RetractedToolCalls } from "../tool-calls/retracted.js";
|
|
51
54
|
import { ClientCapabilities as ToolCallClientCapabilities } from "../tool-calls/client-capabilities.js";
|
|
52
|
-
import { AcpToolCallRenderer, isFinalToolCallStatus, } from "../tool-calls/renderer.js";
|
|
55
|
+
import { AcpToolCallRenderer, isFinalToolCallStatus, progressToolCallId, } from "../tool-calls/renderer.js";
|
|
53
56
|
import { messageLoopYielder, Pushable, raceTimeoutAndAbort, unreachable } from "../utils.js";
|
|
54
57
|
import { acceptedPlanToolResult, ExitPlanCoordinator, isExitPlanInterruptionResult, observeExitPlanToolResults, } from "../exit-plan.js";
|
|
55
58
|
import { AGENT_CONFIG_ID, DEFAULT_AGENT_ID } from "../session-config-ids.js";
|
|
@@ -70,6 +73,7 @@ import { STARTUP_FAILURE_RESULTS_ENV, startupFailureError } from "../startup-fai
|
|
|
70
73
|
import { recordStreamedDelta, unstreamedRemainder } from "../streamed-text.js";
|
|
71
74
|
import { subagentHookOptions } from "../subagent-configuration.js";
|
|
72
75
|
import { isReplayHiddenMetaMessage, isSyntheticLoginMessage, LOCAL_ONLY_COMMANDS, stripLocalCommandMetadata, } from "../message-filters.js";
|
|
76
|
+
import { computeSessionFingerprint } from "./session-fingerprint.js";
|
|
73
77
|
import { promptToClaude, SUPPORTED_PROMPT_CONTENT_TYPES } from "../prompt-to-claude.js";
|
|
74
78
|
import { AUTONOMOUS_RESULT_ORIGINS, isAbortedResult } from "../result-end.js";
|
|
75
79
|
import { messageIdForGrouping, stampParentToolUseId, streamEventToAcpNotifications, toAcpNotifications, } from "../sdk-to-acp.js";
|
|
@@ -190,63 +194,6 @@ async function structuredUsageMarkdown(query, signal, logger) {
|
|
|
190
194
|
* completed/stalled without the host turn resolving (issue #825). */
|
|
191
195
|
const TURN_NO_RESULT_MESSAGE = "The turn ended without a result: the agent went idle while this prompt was still in flight " +
|
|
192
196
|
"(e.g. the model stream dropped mid-turn). Any partial output may be incomplete; please retry.";
|
|
193
|
-
/** Custom (extension) request method a client uses to steer the turn that is
|
|
194
|
-
* currently running: the message is injected into the in-flight turn rather
|
|
195
|
-
* than queued as a separate `session/prompt`. Named `_session/steering` per the
|
|
196
|
-
* agreed ACP steering wire protocol; advertised to clients via the top-level
|
|
197
|
-
* `InitializeResponse._meta.steering.supported`. */
|
|
198
|
-
const STEER_METHOD = "_session/steering";
|
|
199
|
-
/** Stops one Claude background task without cancelling the parent prompt turn. */
|
|
200
|
-
const ASYNC_TASK_STOP_METHOD = "_session/async_task/stop";
|
|
201
|
-
function parseAsyncTaskStopRequest(value) {
|
|
202
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
203
|
-
throw RequestError.invalidParams(undefined, "async task stop params must be an object");
|
|
204
|
-
}
|
|
205
|
-
const params = value;
|
|
206
|
-
const sessionId = typeof params.sessionId === "string" ? params.sessionId.trim() : "";
|
|
207
|
-
const asyncTaskId = typeof params.asyncTaskId === "string" ? params.asyncTaskId.trim() : "";
|
|
208
|
-
if (!sessionId) {
|
|
209
|
-
throw RequestError.invalidParams(undefined, "async task stop params require a non-empty sessionId");
|
|
210
|
-
}
|
|
211
|
-
if (!asyncTaskId) {
|
|
212
|
-
throw RequestError.invalidParams(undefined, "async task stop params require a non-empty asyncTaskId");
|
|
213
|
-
}
|
|
214
|
-
return { sessionId, asyncTaskId };
|
|
215
|
-
}
|
|
216
|
-
/** How urgently the SDK delivers a steered message relative to the running
|
|
217
|
-
* turn — an internal Claude implementation detail, not part of the wire
|
|
218
|
-
* contract. `now` pre-empts the current generation, while `later` waits for a
|
|
219
|
-
* pending permission/elicitation callback to settle instead of cancelling its
|
|
220
|
-
* ACP request and hiding the client's user-input card (IJAI-1191). */
|
|
221
|
-
const STEER_PRIORITY_NOW = "now";
|
|
222
|
-
const STEER_PRIORITY_LATER = "later";
|
|
223
|
-
/** Validate raw JSON-RPC params into a {@link SteerRequest}. Kept minimal — the
|
|
224
|
-
* content blocks are handed to `promptToClaude`, which tolerates unknown block
|
|
225
|
-
* types — but `sessionId` and a non-empty `prompt` array are required. */
|
|
226
|
-
function parseSteerRequest(params) {
|
|
227
|
-
if (!params || typeof params !== "object") {
|
|
228
|
-
throw RequestError.invalidParams(undefined, "steer params must be an object");
|
|
229
|
-
}
|
|
230
|
-
const { sessionId, prompt, _meta } = params;
|
|
231
|
-
if (typeof sessionId !== "string" || sessionId.length === 0) {
|
|
232
|
-
throw RequestError.invalidParams(undefined, "steer params require a non-empty sessionId");
|
|
233
|
-
}
|
|
234
|
-
if (!Array.isArray(prompt) || prompt.length === 0) {
|
|
235
|
-
throw RequestError.invalidParams(undefined, "steer params require a non-empty prompt array");
|
|
236
|
-
}
|
|
237
|
-
const steering = _meta && typeof _meta === "object" ? _meta.steering : undefined;
|
|
238
|
-
const idleBehavior = steering && typeof steering === "object"
|
|
239
|
-
? steering.idleBehavior
|
|
240
|
-
: undefined;
|
|
241
|
-
if (idleBehavior !== undefined && idleBehavior !== "promptRequired") {
|
|
242
|
-
throw RequestError.invalidParams(undefined, "unsupported steering idleBehavior");
|
|
243
|
-
}
|
|
244
|
-
return {
|
|
245
|
-
sessionId,
|
|
246
|
-
prompt: prompt,
|
|
247
|
-
_meta: _meta,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
197
|
/** The foreground work of a session: a prompt's turn, from its insertion
|
|
251
198
|
* until its result, or a model cycle that Claude Code started on its own
|
|
252
199
|
* (see `startAutonomousCycle`). At most one cycle runs at a time, so a
|
|
@@ -294,135 +241,6 @@ function disarmForceCancel(session) {
|
|
|
294
241
|
session.forceCancelTimer = undefined;
|
|
295
242
|
}
|
|
296
243
|
}
|
|
297
|
-
/** Normalize skills without changing their SDK semantics. Array order and
|
|
298
|
-
* duplicates do not affect the selected skill set, so neither should rebuild
|
|
299
|
-
* the underlying Query process. */
|
|
300
|
-
function normalizeSkills(skills) {
|
|
301
|
-
return Array.isArray(skills) ? [...new Set(skills)].sort() : skills;
|
|
302
|
-
}
|
|
303
|
-
/** Whether a changed `_meta.claudeCode.options` key on session/load or
|
|
304
|
-
* session/resume must rebuild the Query process. Almost every option is read
|
|
305
|
-
* only when the process starts, so the default is `true`. Every key of the
|
|
306
|
-
* SDK's `Options` must be classified: an SDK bump that adds or removes an
|
|
307
|
-
* option fails to compile until it is decided here. */
|
|
308
|
-
const OPTION_REBUILDS_SESSION = {
|
|
309
|
-
additionalDirectories: true,
|
|
310
|
-
agentProgressSummaries: true,
|
|
311
|
-
agents: true,
|
|
312
|
-
allowDangerouslySkipPermissions: true,
|
|
313
|
-
allowedTools: true,
|
|
314
|
-
betas: true,
|
|
315
|
-
debug: true,
|
|
316
|
-
debugFile: true,
|
|
317
|
-
disallowedTools: true,
|
|
318
|
-
effort: true,
|
|
319
|
-
enableFileCheckpointing: true,
|
|
320
|
-
env: true,
|
|
321
|
-
executableArgs: true,
|
|
322
|
-
extraArgs: true,
|
|
323
|
-
fallbackModel: true,
|
|
324
|
-
forwardSubagentText: true,
|
|
325
|
-
includeHookEvents: true,
|
|
326
|
-
managedSettings: true,
|
|
327
|
-
maxBudgetUsd: true,
|
|
328
|
-
maxThinkingTokens: true,
|
|
329
|
-
maxTurns: true,
|
|
330
|
-
mcpServers: true,
|
|
331
|
-
model: true,
|
|
332
|
-
outputFormat: true,
|
|
333
|
-
pathToClaudeCodeExecutable: true,
|
|
334
|
-
permissionPrompts: true,
|
|
335
|
-
permissionPromptToolName: true,
|
|
336
|
-
persistSession: true,
|
|
337
|
-
perTaskStopAffordance: true,
|
|
338
|
-
planModeInstructions: true,
|
|
339
|
-
pluginDelivery: true,
|
|
340
|
-
plugins: true,
|
|
341
|
-
projectConfigRoot: true,
|
|
342
|
-
promptSuggestions: true,
|
|
343
|
-
sandbox: true,
|
|
344
|
-
sessionStoreFlush: true,
|
|
345
|
-
settings: true,
|
|
346
|
-
settingSources: true,
|
|
347
|
-
skills: true,
|
|
348
|
-
strictMcpConfig: true,
|
|
349
|
-
supportedDialogKinds: true,
|
|
350
|
-
systemPrompt: true,
|
|
351
|
-
taskBudget: true,
|
|
352
|
-
thinking: true,
|
|
353
|
-
toolAliases: true,
|
|
354
|
-
toolConfig: true,
|
|
355
|
-
tools: true,
|
|
356
|
-
verbatimPrompts: true,
|
|
357
|
-
// Managed or ignored by the adapter.
|
|
358
|
-
agent: false,
|
|
359
|
-
cwd: false,
|
|
360
|
-
executable: false,
|
|
361
|
-
includePartialMessages: false,
|
|
362
|
-
permissionMode: false,
|
|
363
|
-
// Per-call controls for attaching to the stored conversation.
|
|
364
|
-
continue: false,
|
|
365
|
-
forkSession: false,
|
|
366
|
-
resume: false,
|
|
367
|
-
resumeDropsTurn: false,
|
|
368
|
-
resumeSessionAt: false,
|
|
369
|
-
sessionId: false,
|
|
370
|
-
// Callbacks and live objects: they cannot cross JSON-RPC and have no stable serialized form.
|
|
371
|
-
abortController: false,
|
|
372
|
-
canUseTool: false,
|
|
373
|
-
hooks: false,
|
|
374
|
-
onElicitation: false,
|
|
375
|
-
onUserDialog: false,
|
|
376
|
-
sessionStore: false,
|
|
377
|
-
spawnClaudeCodeProcess: false,
|
|
378
|
-
stderr: false,
|
|
379
|
-
// No effect on an already-created session.
|
|
380
|
-
loadTimeoutMs: false,
|
|
381
|
-
title: false,
|
|
382
|
-
};
|
|
383
|
-
/** A JSON value with object keys sorted, so key order never changes a
|
|
384
|
-
* fingerprint. Functions and class instances (hook callbacks, abort
|
|
385
|
-
* controllers, in-process MCP servers) cannot cross JSON-RPC and have no
|
|
386
|
-
* stable serialized form, so they are left out. */
|
|
387
|
-
function canonicalJson(value) {
|
|
388
|
-
if (typeof value === "function")
|
|
389
|
-
return undefined;
|
|
390
|
-
if (value === null || typeof value !== "object")
|
|
391
|
-
return value;
|
|
392
|
-
if (Array.isArray(value))
|
|
393
|
-
return value.map(canonicalJson);
|
|
394
|
-
const proto = Object.getPrototypeOf(value);
|
|
395
|
-
if (proto !== Object.prototype && proto !== null)
|
|
396
|
-
return undefined;
|
|
397
|
-
return Object.fromEntries(Object.keys(value)
|
|
398
|
-
.sort()
|
|
399
|
-
.map((key) => [key, canonicalJson(value[key])])
|
|
400
|
-
.filter(([, entry]) => entry !== undefined));
|
|
401
|
-
}
|
|
402
|
-
/** Compute a stable fingerprint of the session-defining params so we can
|
|
403
|
-
* detect when a loadSession/resumeSession call requires tearing down and
|
|
404
|
-
* recreating the underlying Query process. Every option classified in
|
|
405
|
-
* {@link OPTION_REBUILDS_SESSION} is covered, so a warm resume never silently
|
|
406
|
-
* keeps stale values. MCP servers are sorted by name, and skills are
|
|
407
|
-
* normalized as a set, so ordering differences don't trigger unnecessary
|
|
408
|
-
* recreations. */
|
|
409
|
-
export function computeSessionFingerprint(params) {
|
|
410
|
-
const servers = [...(params.mcpServers ?? [])].sort((a, b) => a.name.localeCompare(b.name));
|
|
411
|
-
const meta = params._meta;
|
|
412
|
-
const options = Object.fromEntries(Object.entries(meta?.claudeCode?.options ?? {}).filter(([key]) => OPTION_REBUILDS_SESSION[key] === true));
|
|
413
|
-
options.skills = normalizeSkills(options.skills);
|
|
414
|
-
return JSON.stringify(canonicalJson({
|
|
415
|
-
cwd: params.cwd,
|
|
416
|
-
mcpServers: servers,
|
|
417
|
-
additionalDirectories: params.additionalDirectories,
|
|
418
|
-
additionalRoots: meta?.additionalRoots,
|
|
419
|
-
systemPrompt: meta?.systemPrompt,
|
|
420
|
-
clientSystemPrompt: params.systemPrompt ?? undefined,
|
|
421
|
-
disableBuiltInTools: meta?.disableBuiltInTools,
|
|
422
|
-
emitRawSDKMessages: meta?.claudeCode?.emitRawSDKMessages,
|
|
423
|
-
options,
|
|
424
|
-
}));
|
|
425
|
-
}
|
|
426
244
|
/** The JSON-RPC code ACP assigns to `authRequired`. Read from the SDK so it
|
|
427
245
|
* cannot drift from the errors this agent throws. */
|
|
428
246
|
const AUTH_REQUIRED_CODE = RequestError.authRequired().code;
|
|
@@ -2021,11 +1839,13 @@ export class ClaudeAcpAgent {
|
|
|
2021
1839
|
// routing path as the immediate notifications.
|
|
2022
1840
|
const routedNotificationClient = { sessionUpdate: sendUpdate };
|
|
2023
1841
|
session.nativeSubagentDeliver = sendUpdate;
|
|
2024
|
-
const finishLifecycle = async (nativeState, asyncState, context
|
|
1842
|
+
const finishLifecycle = async (nativeState, asyncState, context,
|
|
1843
|
+
// Whether Claude Code can keep the subagents running (see `finishAll`).
|
|
1844
|
+
{ mayStillRun = false } = {}) => {
|
|
2025
1845
|
await compaction.interrupt();
|
|
2026
1846
|
await Promise.all([
|
|
2027
1847
|
subagents
|
|
2028
|
-
.finishAll(nativeState, sendUpdate)
|
|
1848
|
+
.finishAll(nativeState, sendUpdate, { mayStillRun })
|
|
2029
1849
|
.catch((error) => this.logger.error(`Session ${params.sessionId}: failed to publish terminal subagent state ${context}`, error)),
|
|
2030
1850
|
asyncTasks
|
|
2031
1851
|
.finishAll(asyncState)
|
|
@@ -2556,18 +2376,21 @@ export class ClaudeAcpAgent {
|
|
|
2556
2376
|
* SDK reports a subagent's end. */
|
|
2557
2377
|
const isRunningBackgroundSubagentOutput = (parentToolUseId) => parentToolUseId !== null && runsInBackground(parentToolUseId);
|
|
2558
2378
|
/** Ends the open tool calls that `include` accepts, with the report of a call
|
|
2559
|
-
* that
|
|
2560
|
-
*
|
|
2561
|
-
|
|
2379
|
+
* that was stopped and sent no result: by a cancel, or (`stoppedBy`
|
|
2380
|
+
* `retracted`) by Claude Code when it took back the message that made the
|
|
2381
|
+
* call. `include` gets the Agent/Task call of the subagent that made the
|
|
2382
|
+
* tool call, if a subagent did, and the tool call. */
|
|
2383
|
+
const closeOpenToolCalls = async (include, stoppedBy = "cancelled") => {
|
|
2562
2384
|
const renderer = new AcpToolCallRenderer(this.toolCallCapabilities);
|
|
2563
2385
|
for (const toolCallId of [...session.emittedToolCalls]) {
|
|
2564
2386
|
const parentToolUseId = session.toolCallParents?.get(toolCallId);
|
|
2565
|
-
if (!include(parentToolUseId))
|
|
2387
|
+
if (!include(parentToolUseId, toolCallId))
|
|
2566
2388
|
continue;
|
|
2567
2389
|
const report = renderer.unfinished({
|
|
2568
2390
|
toolCallId,
|
|
2569
2391
|
ran: session.dispatchedToolCalls?.has(toolCallId) === true,
|
|
2570
|
-
cancelled:
|
|
2392
|
+
cancelled: stoppedBy === "cancelled",
|
|
2393
|
+
retracted: stoppedBy === "retracted",
|
|
2571
2394
|
});
|
|
2572
2395
|
// Named as the call's other updates are: the subagent runtime routes the
|
|
2573
2396
|
// report with them, to the child session, or to none that has ended.
|
|
@@ -2576,6 +2399,14 @@ export class ClaudeAcpAgent {
|
|
|
2576
2399
|
await closeToolCall(toolCallId, report);
|
|
2577
2400
|
}
|
|
2578
2401
|
};
|
|
2402
|
+
/** Ends the open tool calls of the messages that `message` says Claude
|
|
2403
|
+
* Code took back (see `RetractedToolCalls`). No result comes for them. */
|
|
2404
|
+
const closeRetractedToolCalls = async (message) => {
|
|
2405
|
+
const retracted = new Set(retractedToolCallsOf(session).retractedBy(message));
|
|
2406
|
+
if (retracted.size === 0)
|
|
2407
|
+
return;
|
|
2408
|
+
await closeOpenToolCalls((_parent, toolCallId) => retracted.has(toolCallId), "retracted");
|
|
2409
|
+
};
|
|
2579
2410
|
/** Whether the closing at the end of the work a cancel stopped takes a tool
|
|
2580
2411
|
* call that the subagent started by the Agent call `parentToolUseId` made
|
|
2581
2412
|
* (undefined for a call of the main conversation): not one of a running
|
|
@@ -3867,6 +3698,7 @@ export class ClaudeAcpAgent {
|
|
|
3867
3698
|
// state sync the client's model picker (and the model-dependent
|
|
3868
3699
|
// options rebuilt from it) keeps advertising a model the
|
|
3869
3700
|
// session is no longer running (see `modelRefusalFallback`).
|
|
3701
|
+
await closeRetractedToolCalls(message);
|
|
3870
3702
|
const fallback = modelRefusalFallback(message);
|
|
3871
3703
|
const { summary: fallbackSummary, explanation } = fallback;
|
|
3872
3704
|
// A silent model swap is a session-level advisory, not something the model said.
|
|
@@ -4621,21 +4453,6 @@ export class ClaudeAcpAgent {
|
|
|
4621
4453
|
// non-streaming fallback); its shared id keeps the per-block
|
|
4622
4454
|
// messages from moving the time.
|
|
4623
4455
|
session.idleCompaction?.noteRequest(message.event.message.usage, message.event.message.id || undefined);
|
|
4624
|
-
// Only upgrade from the heuristic default — once we have an
|
|
4625
|
-
// authoritative window (cache-seeded at session creation or
|
|
4626
|
-
// on a model switch, read from the resumed session on
|
|
4627
|
-
// session/load, confirmed by each `result`), trust it over
|
|
4628
|
-
// the heuristic. The flag, not the value, is the sentinel: an
|
|
4629
|
-
// authoritative window can legitimately equal
|
|
4630
|
-
// DEFAULT_CONTEXT_WINDOW (e.g. a backend serving a 200k lane
|
|
4631
|
-
// under a "[1m]"-spelled id) and must not be clobbered.
|
|
4632
|
-
if (!session.contextWindowAuthoritative &&
|
|
4633
|
-
session.contextWindowSize === DEFAULT_CONTEXT_WINDOW) {
|
|
4634
|
-
const inferred = inferContextWindowFromModel(model);
|
|
4635
|
-
if (inferred !== null) {
|
|
4636
|
-
session.contextWindowSize = inferred;
|
|
4637
|
-
}
|
|
4638
|
-
}
|
|
4639
4456
|
}
|
|
4640
4457
|
}
|
|
4641
4458
|
else {
|
|
@@ -4741,6 +4558,8 @@ export class ClaudeAcpAgent {
|
|
|
4741
4558
|
case "user":
|
|
4742
4559
|
case "assistant": {
|
|
4743
4560
|
if (message.type === "assistant") {
|
|
4561
|
+
await closeRetractedToolCalls(message);
|
|
4562
|
+
retractedToolCallsOf(session).sent(message);
|
|
4744
4563
|
recordDispatchedToolUses(session, message.message.content);
|
|
4745
4564
|
// A tool use that did not stream is reached here first.
|
|
4746
4565
|
const content = message.message.content;
|
|
@@ -5132,25 +4951,9 @@ export class ClaudeAcpAgent {
|
|
|
5132
4951
|
break;
|
|
5133
4952
|
}
|
|
5134
4953
|
case "tool_progress": {
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
// `agent_api_retry` beats behind `subagentRetry` report under
|
|
5138
|
-
// `agent_<assistant_message_id>`. Forwarding those verbatim leaves the
|
|
5139
|
-
// client resolving an id it has never been told about (the same trap
|
|
5140
|
-
// `ensureToolCallEmitted` documents for #851). The SDK stamps
|
|
5141
|
-
// `parent_tool_use_id` with the executing tool's real id whenever the
|
|
5142
|
-
// beat doesn't carry one of its own, so fall back to it rather than
|
|
5143
|
-
// pattern-matching each synthetic id shape. Beats that do report a real
|
|
5144
|
-
// id (a subagent's `bash_progress`, whose parent is the spawning Agent
|
|
5145
|
-
// call) keep resolving to that id.
|
|
5146
|
-
const toolCallId = session.emittedToolCalls.has(message.tool_use_id)
|
|
5147
|
-
? message.tool_use_id
|
|
5148
|
-
: message.parent_tool_use_id;
|
|
5149
|
-
// Ids leave `emittedToolCalls` at `tool_result`, so this also stops a
|
|
5150
|
-
// beat that races past completion from reopening a finished call.
|
|
5151
|
-
if (toolCallId === null || !session.emittedToolCalls.has(toolCallId)) {
|
|
4954
|
+
const toolCallId = progressToolCallId(message, session.emittedToolCalls);
|
|
4955
|
+
if (toolCallId === undefined)
|
|
5152
4956
|
break;
|
|
5153
|
-
}
|
|
5154
4957
|
// The beat is in the subagent whose Agent call is
|
|
5155
4958
|
// `parent_tool_use_id`, unless it reports on that Agent call
|
|
5156
4959
|
// itself: the Agent call's own heartbeat falls back to its id, and
|
|
@@ -5204,7 +5007,9 @@ export class ClaudeAcpAgent {
|
|
|
5204
5007
|
// and task store are independent of the previous transcript.
|
|
5205
5008
|
// Clear both the in-memory snapshot and the client's visible plan
|
|
5206
5009
|
// before any follow-up prompt can republish stale tasks.
|
|
5207
|
-
await finishLifecycle("failed", "failed", "during conversation reset"
|
|
5010
|
+
await finishLifecycle("failed", "failed", "during conversation reset", {
|
|
5011
|
+
mayStillRun: true,
|
|
5012
|
+
});
|
|
5208
5013
|
subagents.clear();
|
|
5209
5014
|
asyncTasks.clear();
|
|
5210
5015
|
session.resolvedToolNames?.clear();
|
|
@@ -5967,7 +5772,8 @@ export class ClaudeAcpAgent {
|
|
|
5967
5772
|
// A subagent's text replays onto the root only for a client that gets it
|
|
5968
5773
|
// there live: one without native subagent sessions that asked for the
|
|
5969
5774
|
// flattened transcript. With native sessions the text goes to the child
|
|
5970
|
-
// session, which
|
|
5775
|
+
// session, which the replay restores in both forms: AIR's draft under a
|
|
5776
|
+
// replay id, the RFD form under the session id the child had live.
|
|
5971
5777
|
const forwardSubagentText = !clientSupportsSubagents(this.clientCapabilities) &&
|
|
5972
5778
|
(session?.forwardSubagentText ?? supportsSubagentTranscript(this.clientCapabilities));
|
|
5973
5779
|
const supportsTypedFailures = supportsAirSessionFailures(this.clientCapabilities);
|
|
@@ -6307,7 +6113,10 @@ export class ClaudeAcpAgent {
|
|
|
6307
6113
|
}
|
|
6308
6114
|
if (rfdReplay && (await rfdReplay.toolCallUpdate(notification.update, child)))
|
|
6309
6115
|
continue;
|
|
6310
|
-
|
|
6116
|
+
const replayed = { ...notification, sessionId: replayTargetSessionId };
|
|
6117
|
+
await this.client.sessionUpdate(rfdReplay
|
|
6118
|
+
? asSdkSessionNotification(rfdReplay.withTarget(replayed, replayTargetSessionId))
|
|
6119
|
+
: replayed);
|
|
6311
6120
|
}
|
|
6312
6121
|
// The history of each subagent is in its own transcript. The replay
|
|
6313
6122
|
// sends it to the child session right after the launch, one message at
|
|
@@ -7052,6 +6861,17 @@ export class ClaudeAcpAgent {
|
|
|
7052
6861
|
* The work that follows a session setup response: the session's commands,
|
|
7053
6862
|
* the current states of the subagents a load replayed, and MCP server
|
|
7054
6863
|
* authentication.
|
|
6864
|
+
*
|
|
6865
|
+
* Call it in the same synchronous step as the handler's `return`: an
|
|
6866
|
+
* `await` between them would let the timer run before the response. The ACP
|
|
6867
|
+
* SDK (2.6.0) gives a request handler no responder and no after-response
|
|
6868
|
+
* hook, so the order rests on two things that its source shows and its API
|
|
6869
|
+
* does not promise. `registerAppRequest` queues the response in the
|
|
6870
|
+
* microtask that follows the handler's return, with no macrotask in
|
|
6871
|
+
* between, so the timer runs after it. And `Connection.sendMessage` writes
|
|
6872
|
+
* in call order, so what the timer sends is written after the response. A
|
|
6873
|
+
* caller that does not serve the agent through the SDK's `AgentApp` (see
|
|
6874
|
+
* `v1AgentApp`) has no such order.
|
|
7055
6875
|
*/
|
|
7056
6876
|
afterSetupResponse(sessionId, mcpServers) {
|
|
7057
6877
|
setTimeout(() => {
|
|
@@ -7128,12 +6948,11 @@ export class ClaudeAcpAgent {
|
|
|
7128
6948
|
});
|
|
7129
6949
|
}
|
|
7130
6950
|
/**
|
|
7131
|
-
*
|
|
7132
|
-
* (`readContextWindow`), without blocking the caller.
|
|
7133
|
-
*
|
|
7134
|
-
* `
|
|
7135
|
-
*
|
|
7136
|
-
* result still overwrites this.
|
|
6951
|
+
* Replace the default context window with `getContextUsage().rawMaxTokens`
|
|
6952
|
+
* (`readContextWindow`), without blocking the caller. Without it, a model
|
|
6953
|
+
* with a 200K window (`claude-sonnet-4-5`, or any model under
|
|
6954
|
+
* `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`) would show the 1M default until the
|
|
6955
|
+
* first result's modelUsage arrives. A later result still overwrites this.
|
|
7137
6956
|
*/
|
|
7138
6957
|
refreshContextWindowInBackground(sessionId, session) {
|
|
7139
6958
|
if (session.contextWindowAuthoritative)
|
|
@@ -7166,21 +6985,18 @@ export class ClaudeAcpAgent {
|
|
|
7166
6985
|
}
|
|
7167
6986
|
else if (configId === MODEL_CONFIG_ID) {
|
|
7168
6987
|
// `ModelInfo.supportsAutoMode` is the canonical SDK signal for applying
|
|
7169
|
-
// the Auto fallback below
|
|
7170
|
-
// context window for semantic aliases (e.g. `default`) whose ID alone
|
|
7171
|
-
// carries no "1m" token.
|
|
6988
|
+
// the Auto fallback below.
|
|
7172
6989
|
const newModelInfo = session.modelInfos.find((m) => m.value === value);
|
|
7173
6990
|
const modelChanged = session.models.currentModelId !== value;
|
|
7174
6991
|
if (modelChanged) {
|
|
7175
6992
|
session.idleCompaction?.disarm("model change");
|
|
7176
6993
|
// Seed the new model's context window WITHOUT awaited IPC on the
|
|
7177
6994
|
// switch path: cached authoritative value if we've already learned it
|
|
7178
|
-
// (from a prior turn's `result.modelUsage`), else the
|
|
7179
|
-
//
|
|
7180
|
-
//
|
|
7181
|
-
//
|
|
7182
|
-
//
|
|
7183
|
-
// (`refreshContextWindowInBackground`).
|
|
6995
|
+
// (from a prior turn's `result.modelUsage`), else the default. SDK
|
|
6996
|
+
// control requests are serialized over one channel, so an awaited
|
|
6997
|
+
// `getContextUsage` here would delay the rest of the switch (issues
|
|
6998
|
+
// #886/#880); the default is instead replaced in the background once
|
|
6999
|
+
// the switch is done (`refreshContextWindowInBackground`).
|
|
7184
7000
|
const seeded = immediateContextWindow(session.providerCacheKey, value, newModelInfo);
|
|
7185
7001
|
session.contextWindowSize = seeded.size;
|
|
7186
7002
|
session.contextWindowAuthoritative = seeded.authoritative;
|
|
@@ -7892,7 +7708,7 @@ export class ClaudeAcpAgent {
|
|
|
7892
7708
|
// session does (see `aliasResumedModelRow`).
|
|
7893
7709
|
const sdkModels = aliasResumedModelRow(initializationResult.models, creationOpts.resume !== undefined ? resumedModel : undefined);
|
|
7894
7710
|
const settingsAllowedModels = Array.isArray(settingsAvailableModels)
|
|
7895
|
-
? applyAvailableModelsAllowlist(sdkModels, settingsAvailableModels, settingsModelOverrides, settingsManager.getManagedDeniedModels())
|
|
7711
|
+
? await applyAvailableModelsAllowlist(sdkModels, settingsAvailableModels, settingsModelOverrides, settingsManager.getManagedDeniedModels())
|
|
7896
7712
|
: sdkModels;
|
|
7897
7713
|
// Then keep only the models the `providers/set` gateway listed.
|
|
7898
7714
|
const allowedModels = resolvedProvider?.listedModels
|
|
@@ -7934,7 +7750,8 @@ export class ClaudeAcpAgent {
|
|
|
7934
7750
|
// `fast_mode_disabled_reason` reflects the post-switch model since SDK
|
|
7935
7751
|
// 0.3.219 (the initialize response used to answer from the spawn-time
|
|
7936
7752
|
// model). A fresh SDK session reports `sdk_opt_in_required` — the toggle IS
|
|
7937
|
-
// the opt-in — which normalizes
|
|
7753
|
+
// the opt-in — which normalizes to `undefined`, as does `pending`; every
|
|
7754
|
+
// other reason is retained.
|
|
7938
7755
|
const fastModeDisabledReason = fastModeEnabled
|
|
7939
7756
|
? undefined
|
|
7940
7757
|
: normalizeFastModeDisabledReason(initializationResult.fast_mode_disabled_reason);
|
|
@@ -7975,21 +7792,16 @@ export class ClaudeAcpAgent {
|
|
|
7975
7792
|
}
|
|
7976
7793
|
// Seed the context window without awaited IPC. The cached authoritative
|
|
7977
7794
|
// window from a prior turn wins (`result.modelUsage`, cross-session),
|
|
7978
|
-
// then the
|
|
7979
|
-
//
|
|
7980
|
-
// (`refreshContextWindowInBackground
|
|
7981
|
-
// arrives on the first `result.modelUsage` and is cached
|
|
7795
|
+
// then the default. The default is replaced by a background
|
|
7796
|
+
// getContextUsage once the session is registered
|
|
7797
|
+
// (`refreshContextWindowInBackground`, issue #596); the authoritative
|
|
7798
|
+
// window then arrives on the first `result.modelUsage` and is cached
|
|
7799
|
+
// from there.
|
|
7982
7800
|
//
|
|
7983
|
-
//
|
|
7984
|
-
//
|
|
7985
|
-
//
|
|
7986
|
-
//
|
|
7987
|
-
//
|
|
7988
|
-
// The inference fallback is deliberately keyed to the allowlisted entry: a
|
|
7989
|
-
// fallback-resolved sibling's resolvedModel/displayName/description can
|
|
7990
|
-
// describe a different context lane than the verbatim live id (e.g. an
|
|
7991
|
-
// "opus[1m]" row matched for a bare 200k id), so on the fallback path only
|
|
7992
|
-
// the id itself is a trustworthy window signal.
|
|
7801
|
+
// The cache lookup is deliberately keyed to the allowlisted entry: a
|
|
7802
|
+
// fallback-resolved sibling's resolvedModel can name a different context
|
|
7803
|
+
// lane than the verbatim live id (e.g. an "opus[1m]" row matched for a
|
|
7804
|
+
// bare 200k id), so on the fallback path the lookup uses the id itself.
|
|
7993
7805
|
const seededWindow = immediateContextWindow(providerCacheKey, models.currentModelId, allowlistedModelInfo);
|
|
7994
7806
|
if (creationOpts.replacingSession?.tornDown) {
|
|
7995
7807
|
throw RequestError.internalError(undefined, SESSION_ENDED_MESSAGE);
|
|
@@ -8494,6 +8306,10 @@ function forgetForegroundToolCall(session, toolCallId) {
|
|
|
8494
8306
|
function toolCallFieldsOf(session) {
|
|
8495
8307
|
return (session.toolCallFields ??= new ToolCallFieldTracker());
|
|
8496
8308
|
}
|
|
8309
|
+
/** The record of a session's assistant tool uses, created on first use. */
|
|
8310
|
+
function retractedToolCallsOf(session) {
|
|
8311
|
+
return (session.retractedToolCalls ??= new RetractedToolCalls());
|
|
8312
|
+
}
|
|
8497
8313
|
const MAX_RESOLVED_TOOL_NAMES = 1000;
|
|
8498
8314
|
/** Keeps the tool names of the tool results in `content` before the tool use cache drops them. */
|
|
8499
8315
|
function rememberResolvedToolNames(session, content) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Stops one Claude background task without cancelling the parent prompt turn. */
|
|
2
|
+
export declare const ASYNC_TASK_STOP_METHOD = "_session/async_task/stop";
|
|
3
|
+
export type AsyncTaskStopRequest = {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
asyncTaskId: string;
|
|
6
|
+
};
|
|
7
|
+
export type AsyncTaskStopResponse = {
|
|
8
|
+
stopped: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function parseAsyncTaskStopRequest(value: unknown): AsyncTaskStopRequest;
|
|
11
|
+
//# sourceMappingURL=async-task-stop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-task-stop.d.ts","sourceRoot":"","sources":["../../src/v1/async-task-stop.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,6BAA6B,CAAC;AAEjE,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAoB9E"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RequestError } from "@agentclientprotocol/sdk/unstable";
|
|
2
|
+
/** Stops one Claude background task without cancelling the parent prompt turn. */
|
|
3
|
+
export const ASYNC_TASK_STOP_METHOD = "_session/async_task/stop";
|
|
4
|
+
export function parseAsyncTaskStopRequest(value) {
|
|
5
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
6
|
+
throw RequestError.invalidParams(undefined, "async task stop params must be an object");
|
|
7
|
+
}
|
|
8
|
+
const params = value;
|
|
9
|
+
const sessionId = typeof params.sessionId === "string" ? params.sessionId.trim() : "";
|
|
10
|
+
const asyncTaskId = typeof params.asyncTaskId === "string" ? params.asyncTaskId.trim() : "";
|
|
11
|
+
if (!sessionId) {
|
|
12
|
+
throw RequestError.invalidParams(undefined, "async task stop params require a non-empty sessionId");
|
|
13
|
+
}
|
|
14
|
+
if (!asyncTaskId) {
|
|
15
|
+
throw RequestError.invalidParams(undefined, "async task stop params require a non-empty asyncTaskId");
|
|
16
|
+
}
|
|
17
|
+
return { sessionId, asyncTaskId };
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NewSessionRequest } from "@agentclientprotocol/sdk/unstable";
|
|
2
|
+
/** Compute a stable fingerprint of the session-defining params so we can
|
|
3
|
+
* detect when a loadSession/resumeSession call requires tearing down and
|
|
4
|
+
* recreating the underlying Query process. Every option classified in
|
|
5
|
+
* {@link OPTION_REBUILDS_SESSION} is covered, so a warm resume never silently
|
|
6
|
+
* keeps stale values. MCP servers are sorted by name, and skills are
|
|
7
|
+
* normalized as a set, so ordering differences don't trigger unnecessary
|
|
8
|
+
* recreations. */
|
|
9
|
+
export declare function computeSessionFingerprint(params: {
|
|
10
|
+
cwd: string;
|
|
11
|
+
mcpServers?: NewSessionRequest["mcpServers"];
|
|
12
|
+
additionalDirectories?: NewSessionRequest["additionalDirectories"];
|
|
13
|
+
systemPrompt?: NewSessionRequest["systemPrompt"];
|
|
14
|
+
_meta?: NewSessionRequest["_meta"];
|
|
15
|
+
}): string;
|
|
16
|
+
//# sourceMappingURL=session-fingerprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-fingerprint.d.ts","sourceRoot":"","sources":["../../src/v1/session-fingerprint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AA8G3E;;;;;;mBAMmB;AACnB,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC7C,qBAAqB,CAAC,EAAE,iBAAiB,CAAC,uBAAuB,CAAC,CAAC;IACnE,YAAY,CAAC,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC;IACjD,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;CACpC,GAAG,MAAM,CAsBT"}
|