@agentclientprotocol/claude-agent-acp 0.106.0 → 0.106.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 +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-failure-extension.d.ts +15 -1
- package/dist/session-failure-extension.d.ts.map +1 -1
- package/dist/session-failure-extension.js +63 -0
- 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 +26 -0
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +30 -0
- package/dist/v1/acp-agent.d.ts +31 -68
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +71 -271
- 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 +18 -4
- package/dist/v2/setup.js +1 -1
- package/dist/v2/stream.d.ts +2 -4
- package/dist/v2/stream.d.ts.map +1 -1
- package/dist/v2/stream.js +5 -9
- 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";
|
|
@@ -35,7 +37,7 @@ import { buildClaudePermissionOptions } from "../permissions/options.js";
|
|
|
35
37
|
import { buildClaudePermissionPresentation, permissionToolCallMeta, } from "../permissions/presentation.js";
|
|
36
38
|
import { decodeClaudePermissionResponse } from "../permissions/response.js";
|
|
37
39
|
import { SettingsManager } from "../settings.js";
|
|
38
|
-
import { activeUsageLimitMessage, airSessionFailureCapabilityMeta, assistantMessageText, createSessionFailureState, isSyntheticUsageLimitMessage, providerFailureCategory, SessionFailureController, sessionFailureMeta, supportsAirSessionFailures, } from "../session-failure-extension.js";
|
|
40
|
+
import { activeUsageLimitMessage, apiRetryWarning, airSessionFailureCapabilityMeta, assistantMessageText, createSessionFailureState, isSyntheticUsageLimitMessage, providerFailureCategory, SessionFailureController, sessionFailureMeta, supportsAirSessionFailures, } from "../session-failure-extension.js";
|
|
39
41
|
import { billsClaudeSubscription, claudeLoginRequiredError, claudeSubscriptionNotSupportedError, holdsNonSubscriptionCredential, refuseClaudeSubscriptionTurn, shouldHideClaudeAuth, warnClaudeSubscriptionGuardDegraded, } from "../hide-claude-auth.js";
|
|
40
42
|
import { adapterRemoteControlCommand, isRemoteHumanMessage, parseRemoteControlCommand, runRemoteControlCommand, } from "../remote-control.js";
|
|
41
43
|
import { AGENT_FILE_CHANGE_REPORT_CAPABILITY, agentFileChangeReportMeta, createNativeFileChangeReporter, recordSubagentFileEdits, supportsAgentFileChangeReport, } from "../file-change-audit.js";
|
|
@@ -43,13 +45,13 @@ 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";
|
|
51
53
|
import { ClientCapabilities as ToolCallClientCapabilities } from "../tool-calls/client-capabilities.js";
|
|
52
|
-
import { AcpToolCallRenderer, isFinalToolCallStatus, } from "../tool-calls/renderer.js";
|
|
54
|
+
import { AcpToolCallRenderer, isFinalToolCallStatus, progressToolCallId, } from "../tool-calls/renderer.js";
|
|
53
55
|
import { messageLoopYielder, Pushable, raceTimeoutAndAbort, unreachable } from "../utils.js";
|
|
54
56
|
import { acceptedPlanToolResult, ExitPlanCoordinator, isExitPlanInterruptionResult, observeExitPlanToolResults, } from "../exit-plan.js";
|
|
55
57
|
import { AGENT_CONFIG_ID, DEFAULT_AGENT_ID } from "../session-config-ids.js";
|
|
@@ -70,6 +72,7 @@ import { STARTUP_FAILURE_RESULTS_ENV, startupFailureError } from "../startup-fai
|
|
|
70
72
|
import { recordStreamedDelta, unstreamedRemainder } from "../streamed-text.js";
|
|
71
73
|
import { subagentHookOptions } from "../subagent-configuration.js";
|
|
72
74
|
import { isReplayHiddenMetaMessage, isSyntheticLoginMessage, LOCAL_ONLY_COMMANDS, stripLocalCommandMetadata, } from "../message-filters.js";
|
|
75
|
+
import { computeSessionFingerprint } from "./session-fingerprint.js";
|
|
73
76
|
import { promptToClaude, SUPPORTED_PROMPT_CONTENT_TYPES } from "../prompt-to-claude.js";
|
|
74
77
|
import { AUTONOMOUS_RESULT_ORIGINS, isAbortedResult } from "../result-end.js";
|
|
75
78
|
import { messageIdForGrouping, stampParentToolUseId, streamEventToAcpNotifications, toAcpNotifications, } from "../sdk-to-acp.js";
|
|
@@ -190,63 +193,6 @@ async function structuredUsageMarkdown(query, signal, logger) {
|
|
|
190
193
|
* completed/stalled without the host turn resolving (issue #825). */
|
|
191
194
|
const TURN_NO_RESULT_MESSAGE = "The turn ended without a result: the agent went idle while this prompt was still in flight " +
|
|
192
195
|
"(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
196
|
/** The foreground work of a session: a prompt's turn, from its insertion
|
|
251
197
|
* until its result, or a model cycle that Claude Code started on its own
|
|
252
198
|
* (see `startAutonomousCycle`). At most one cycle runs at a time, so a
|
|
@@ -294,135 +240,6 @@ function disarmForceCancel(session) {
|
|
|
294
240
|
session.forceCancelTimer = undefined;
|
|
295
241
|
}
|
|
296
242
|
}
|
|
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
243
|
/** The JSON-RPC code ACP assigns to `authRequired`. Read from the SDK so it
|
|
427
244
|
* cannot drift from the errors this agent throws. */
|
|
428
245
|
const AUTH_REQUIRED_CODE = RequestError.authRequired().code;
|
|
@@ -2021,11 +1838,13 @@ export class ClaudeAcpAgent {
|
|
|
2021
1838
|
// routing path as the immediate notifications.
|
|
2022
1839
|
const routedNotificationClient = { sessionUpdate: sendUpdate };
|
|
2023
1840
|
session.nativeSubagentDeliver = sendUpdate;
|
|
2024
|
-
const finishLifecycle = async (nativeState, asyncState, context
|
|
1841
|
+
const finishLifecycle = async (nativeState, asyncState, context,
|
|
1842
|
+
// Whether Claude Code can keep the subagents running (see `finishAll`).
|
|
1843
|
+
{ mayStillRun = false } = {}) => {
|
|
2025
1844
|
await compaction.interrupt();
|
|
2026
1845
|
await Promise.all([
|
|
2027
1846
|
subagents
|
|
2028
|
-
.finishAll(nativeState, sendUpdate)
|
|
1847
|
+
.finishAll(nativeState, sendUpdate, { mayStillRun })
|
|
2029
1848
|
.catch((error) => this.logger.error(`Session ${params.sessionId}: failed to publish terminal subagent state ${context}`, error)),
|
|
2030
1849
|
asyncTasks
|
|
2031
1850
|
.finishAll(asyncState)
|
|
@@ -2053,7 +1872,9 @@ export class ClaudeAcpAgent {
|
|
|
2053
1872
|
});
|
|
2054
1873
|
};
|
|
2055
1874
|
const publishSessionFailure = async (kind, options = {}) => {
|
|
2056
|
-
const turnId = options.turnScoped === false
|
|
1875
|
+
const turnId = options.turnScoped === false
|
|
1876
|
+
? undefined
|
|
1877
|
+
: (options.turnId ?? session.activeTurn?.promptUuid);
|
|
2057
1878
|
await sessionFailures.publish(kind, {
|
|
2058
1879
|
turnId,
|
|
2059
1880
|
sessionScoped: options.turnScoped === false,
|
|
@@ -3844,18 +3665,19 @@ export class ClaudeAcpAgent {
|
|
|
3844
3665
|
// action to clear it (issue #1072).
|
|
3845
3666
|
if (kind === "auth_required")
|
|
3846
3667
|
break;
|
|
3847
|
-
//
|
|
3848
|
-
//
|
|
3849
|
-
//
|
|
3850
|
-
//
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
:
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3668
|
+
// The CLI holds the echo of a prompt back until the first
|
|
3669
|
+
// assistant frame or stream event of the turn, so the retries
|
|
3670
|
+
// of a request that gets no response come before the echo
|
|
3671
|
+
// activates the turn. Give them the queue head, the prompt
|
|
3672
|
+
// being sent: all retries and the terminal failure of one turn
|
|
3673
|
+
// then share its `${turnId}:error` row.
|
|
3674
|
+
const retryTurn = session.activeTurn ??
|
|
3675
|
+
(asyncTasks.autonomousTurnOpen ? undefined : firstUnsettledQueuedTurn());
|
|
3676
|
+
await publishSessionFailure(kind, {
|
|
3677
|
+
turnId: retryTurn?.promptUuid,
|
|
3678
|
+
...apiRetryWarning(message),
|
|
3679
|
+
severity: "warning",
|
|
3680
|
+
});
|
|
3859
3681
|
break;
|
|
3860
3682
|
}
|
|
3861
3683
|
case "model_refusal_fallback": {
|
|
@@ -4618,21 +4440,6 @@ export class ClaudeAcpAgent {
|
|
|
4618
4440
|
// non-streaming fallback); its shared id keeps the per-block
|
|
4619
4441
|
// messages from moving the time.
|
|
4620
4442
|
session.idleCompaction?.noteRequest(message.event.message.usage, message.event.message.id || undefined);
|
|
4621
|
-
// Only upgrade from the heuristic default — once we have an
|
|
4622
|
-
// authoritative window (cache-seeded at session creation or
|
|
4623
|
-
// on a model switch, read from the resumed session on
|
|
4624
|
-
// session/load, confirmed by each `result`), trust it over
|
|
4625
|
-
// the heuristic. The flag, not the value, is the sentinel: an
|
|
4626
|
-
// authoritative window can legitimately equal
|
|
4627
|
-
// DEFAULT_CONTEXT_WINDOW (e.g. a backend serving a 200k lane
|
|
4628
|
-
// under a "[1m]"-spelled id) and must not be clobbered.
|
|
4629
|
-
if (!session.contextWindowAuthoritative &&
|
|
4630
|
-
session.contextWindowSize === DEFAULT_CONTEXT_WINDOW) {
|
|
4631
|
-
const inferred = inferContextWindowFromModel(model);
|
|
4632
|
-
if (inferred !== null) {
|
|
4633
|
-
session.contextWindowSize = inferred;
|
|
4634
|
-
}
|
|
4635
|
-
}
|
|
4636
4443
|
}
|
|
4637
4444
|
}
|
|
4638
4445
|
else {
|
|
@@ -5129,25 +4936,9 @@ export class ClaudeAcpAgent {
|
|
|
5129
4936
|
break;
|
|
5130
4937
|
}
|
|
5131
4938
|
case "tool_progress": {
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
// `agent_api_retry` beats behind `subagentRetry` report under
|
|
5135
|
-
// `agent_<assistant_message_id>`. Forwarding those verbatim leaves the
|
|
5136
|
-
// client resolving an id it has never been told about (the same trap
|
|
5137
|
-
// `ensureToolCallEmitted` documents for #851). The SDK stamps
|
|
5138
|
-
// `parent_tool_use_id` with the executing tool's real id whenever the
|
|
5139
|
-
// beat doesn't carry one of its own, so fall back to it rather than
|
|
5140
|
-
// pattern-matching each synthetic id shape. Beats that do report a real
|
|
5141
|
-
// id (a subagent's `bash_progress`, whose parent is the spawning Agent
|
|
5142
|
-
// call) keep resolving to that id.
|
|
5143
|
-
const toolCallId = session.emittedToolCalls.has(message.tool_use_id)
|
|
5144
|
-
? message.tool_use_id
|
|
5145
|
-
: message.parent_tool_use_id;
|
|
5146
|
-
// Ids leave `emittedToolCalls` at `tool_result`, so this also stops a
|
|
5147
|
-
// beat that races past completion from reopening a finished call.
|
|
5148
|
-
if (toolCallId === null || !session.emittedToolCalls.has(toolCallId)) {
|
|
4939
|
+
const toolCallId = progressToolCallId(message, session.emittedToolCalls);
|
|
4940
|
+
if (toolCallId === undefined)
|
|
5149
4941
|
break;
|
|
5150
|
-
}
|
|
5151
4942
|
// The beat is in the subagent whose Agent call is
|
|
5152
4943
|
// `parent_tool_use_id`, unless it reports on that Agent call
|
|
5153
4944
|
// itself: the Agent call's own heartbeat falls back to its id, and
|
|
@@ -5201,7 +4992,9 @@ export class ClaudeAcpAgent {
|
|
|
5201
4992
|
// and task store are independent of the previous transcript.
|
|
5202
4993
|
// Clear both the in-memory snapshot and the client's visible plan
|
|
5203
4994
|
// before any follow-up prompt can republish stale tasks.
|
|
5204
|
-
await finishLifecycle("failed", "failed", "during conversation reset"
|
|
4995
|
+
await finishLifecycle("failed", "failed", "during conversation reset", {
|
|
4996
|
+
mayStillRun: true,
|
|
4997
|
+
});
|
|
5205
4998
|
subagents.clear();
|
|
5206
4999
|
asyncTasks.clear();
|
|
5207
5000
|
session.resolvedToolNames?.clear();
|
|
@@ -5964,7 +5757,8 @@ export class ClaudeAcpAgent {
|
|
|
5964
5757
|
// A subagent's text replays onto the root only for a client that gets it
|
|
5965
5758
|
// there live: one without native subagent sessions that asked for the
|
|
5966
5759
|
// flattened transcript. With native sessions the text goes to the child
|
|
5967
|
-
// session, which
|
|
5760
|
+
// session, which the replay restores in both forms: AIR's draft under a
|
|
5761
|
+
// replay id, the RFD form under the session id the child had live.
|
|
5968
5762
|
const forwardSubagentText = !clientSupportsSubagents(this.clientCapabilities) &&
|
|
5969
5763
|
(session?.forwardSubagentText ?? supportsSubagentTranscript(this.clientCapabilities));
|
|
5970
5764
|
const supportsTypedFailures = supportsAirSessionFailures(this.clientCapabilities);
|
|
@@ -6304,7 +6098,10 @@ export class ClaudeAcpAgent {
|
|
|
6304
6098
|
}
|
|
6305
6099
|
if (rfdReplay && (await rfdReplay.toolCallUpdate(notification.update, child)))
|
|
6306
6100
|
continue;
|
|
6307
|
-
|
|
6101
|
+
const replayed = { ...notification, sessionId: replayTargetSessionId };
|
|
6102
|
+
await this.client.sessionUpdate(rfdReplay
|
|
6103
|
+
? asSdkSessionNotification(rfdReplay.withTarget(replayed, replayTargetSessionId))
|
|
6104
|
+
: replayed);
|
|
6308
6105
|
}
|
|
6309
6106
|
// The history of each subagent is in its own transcript. The replay
|
|
6310
6107
|
// sends it to the child session right after the launch, one message at
|
|
@@ -7049,6 +6846,17 @@ export class ClaudeAcpAgent {
|
|
|
7049
6846
|
* The work that follows a session setup response: the session's commands,
|
|
7050
6847
|
* the current states of the subagents a load replayed, and MCP server
|
|
7051
6848
|
* authentication.
|
|
6849
|
+
*
|
|
6850
|
+
* Call it in the same synchronous step as the handler's `return`: an
|
|
6851
|
+
* `await` between them would let the timer run before the response. The ACP
|
|
6852
|
+
* SDK (2.6.0) gives a request handler no responder and no after-response
|
|
6853
|
+
* hook, so the order rests on two things that its source shows and its API
|
|
6854
|
+
* does not promise. `registerAppRequest` queues the response in the
|
|
6855
|
+
* microtask that follows the handler's return, with no macrotask in
|
|
6856
|
+
* between, so the timer runs after it. And `Connection.sendMessage` writes
|
|
6857
|
+
* in call order, so what the timer sends is written after the response. A
|
|
6858
|
+
* caller that does not serve the agent through the SDK's `AgentApp` (see
|
|
6859
|
+
* `v1AgentApp`) has no such order.
|
|
7052
6860
|
*/
|
|
7053
6861
|
afterSetupResponse(sessionId, mcpServers) {
|
|
7054
6862
|
setTimeout(() => {
|
|
@@ -7125,12 +6933,11 @@ export class ClaudeAcpAgent {
|
|
|
7125
6933
|
});
|
|
7126
6934
|
}
|
|
7127
6935
|
/**
|
|
7128
|
-
*
|
|
7129
|
-
* (`readContextWindow`), without blocking the caller.
|
|
7130
|
-
*
|
|
7131
|
-
* `
|
|
7132
|
-
*
|
|
7133
|
-
* result still overwrites this.
|
|
6936
|
+
* Replace the default context window with `getContextUsage().rawMaxTokens`
|
|
6937
|
+
* (`readContextWindow`), without blocking the caller. Without it, a model
|
|
6938
|
+
* with a 200K window (`claude-sonnet-4-5`, or any model under
|
|
6939
|
+
* `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`) would show the 1M default until the
|
|
6940
|
+
* first result's modelUsage arrives. A later result still overwrites this.
|
|
7134
6941
|
*/
|
|
7135
6942
|
refreshContextWindowInBackground(sessionId, session) {
|
|
7136
6943
|
if (session.contextWindowAuthoritative)
|
|
@@ -7163,21 +6970,18 @@ export class ClaudeAcpAgent {
|
|
|
7163
6970
|
}
|
|
7164
6971
|
else if (configId === MODEL_CONFIG_ID) {
|
|
7165
6972
|
// `ModelInfo.supportsAutoMode` is the canonical SDK signal for applying
|
|
7166
|
-
// the Auto fallback below
|
|
7167
|
-
// context window for semantic aliases (e.g. `default`) whose ID alone
|
|
7168
|
-
// carries no "1m" token.
|
|
6973
|
+
// the Auto fallback below.
|
|
7169
6974
|
const newModelInfo = session.modelInfos.find((m) => m.value === value);
|
|
7170
6975
|
const modelChanged = session.models.currentModelId !== value;
|
|
7171
6976
|
if (modelChanged) {
|
|
7172
6977
|
session.idleCompaction?.disarm("model change");
|
|
7173
6978
|
// Seed the new model's context window WITHOUT awaited IPC on the
|
|
7174
6979
|
// switch path: cached authoritative value if we've already learned it
|
|
7175
|
-
// (from a prior turn's `result.modelUsage`), else the
|
|
7176
|
-
//
|
|
7177
|
-
//
|
|
7178
|
-
//
|
|
7179
|
-
//
|
|
7180
|
-
// (`refreshContextWindowInBackground`).
|
|
6980
|
+
// (from a prior turn's `result.modelUsage`), else the default. SDK
|
|
6981
|
+
// control requests are serialized over one channel, so an awaited
|
|
6982
|
+
// `getContextUsage` here would delay the rest of the switch (issues
|
|
6983
|
+
// #886/#880); the default is instead replaced in the background once
|
|
6984
|
+
// the switch is done (`refreshContextWindowInBackground`).
|
|
7181
6985
|
const seeded = immediateContextWindow(session.providerCacheKey, value, newModelInfo);
|
|
7182
6986
|
session.contextWindowSize = seeded.size;
|
|
7183
6987
|
session.contextWindowAuthoritative = seeded.authoritative;
|
|
@@ -7889,7 +7693,7 @@ export class ClaudeAcpAgent {
|
|
|
7889
7693
|
// session does (see `aliasResumedModelRow`).
|
|
7890
7694
|
const sdkModels = aliasResumedModelRow(initializationResult.models, creationOpts.resume !== undefined ? resumedModel : undefined);
|
|
7891
7695
|
const settingsAllowedModels = Array.isArray(settingsAvailableModels)
|
|
7892
|
-
? applyAvailableModelsAllowlist(sdkModels, settingsAvailableModels, settingsModelOverrides, settingsManager.getManagedDeniedModels())
|
|
7696
|
+
? await applyAvailableModelsAllowlist(sdkModels, settingsAvailableModels, settingsModelOverrides, settingsManager.getManagedDeniedModels())
|
|
7893
7697
|
: sdkModels;
|
|
7894
7698
|
// Then keep only the models the `providers/set` gateway listed.
|
|
7895
7699
|
const allowedModels = resolvedProvider?.listedModels
|
|
@@ -7931,7 +7735,8 @@ export class ClaudeAcpAgent {
|
|
|
7931
7735
|
// `fast_mode_disabled_reason` reflects the post-switch model since SDK
|
|
7932
7736
|
// 0.3.219 (the initialize response used to answer from the spawn-time
|
|
7933
7737
|
// model). A fresh SDK session reports `sdk_opt_in_required` — the toggle IS
|
|
7934
|
-
// the opt-in — which normalizes
|
|
7738
|
+
// the opt-in — which normalizes to `undefined`, as does `pending`; every
|
|
7739
|
+
// other reason is retained.
|
|
7935
7740
|
const fastModeDisabledReason = fastModeEnabled
|
|
7936
7741
|
? undefined
|
|
7937
7742
|
: normalizeFastModeDisabledReason(initializationResult.fast_mode_disabled_reason);
|
|
@@ -7972,21 +7777,16 @@ export class ClaudeAcpAgent {
|
|
|
7972
7777
|
}
|
|
7973
7778
|
// Seed the context window without awaited IPC. The cached authoritative
|
|
7974
7779
|
// window from a prior turn wins (`result.modelUsage`, cross-session),
|
|
7975
|
-
// then the
|
|
7976
|
-
//
|
|
7977
|
-
// (`refreshContextWindowInBackground
|
|
7978
|
-
// arrives on the first `result.modelUsage` and is cached
|
|
7979
|
-
//
|
|
7980
|
-
// Text inference alone misses aliases that resolve to extended-context
|
|
7981
|
-
// models with no "1m" token anywhere in their id or description (e.g.
|
|
7982
|
-
// `sonnet` → claude-sonnet-5, and `opus`/`default` since CLI 2.1.283,
|
|
7983
|
-
// all natively ~1M) — the background refresh covers those (issue #596).
|
|
7780
|
+
// then the default. The default is replaced by a background
|
|
7781
|
+
// getContextUsage once the session is registered
|
|
7782
|
+
// (`refreshContextWindowInBackground`, issue #596); the authoritative
|
|
7783
|
+
// window then arrives on the first `result.modelUsage` and is cached
|
|
7784
|
+
// from there.
|
|
7984
7785
|
//
|
|
7985
|
-
// The
|
|
7986
|
-
// fallback-resolved sibling's resolvedModel
|
|
7987
|
-
//
|
|
7988
|
-
//
|
|
7989
|
-
// the id itself is a trustworthy window signal.
|
|
7786
|
+
// The cache lookup is deliberately keyed to the allowlisted entry: a
|
|
7787
|
+
// fallback-resolved sibling's resolvedModel can name a different context
|
|
7788
|
+
// lane than the verbatim live id (e.g. an "opus[1m]" row matched for a
|
|
7789
|
+
// bare 200k id), so on the fallback path the lookup uses the id itself.
|
|
7990
7790
|
const seededWindow = immediateContextWindow(providerCacheKey, models.currentModelId, allowlistedModelInfo);
|
|
7991
7791
|
if (creationOpts.replacingSession?.tornDown) {
|
|
7992
7792
|
throw RequestError.internalError(undefined, SESSION_ENDED_MESSAGE);
|
|
@@ -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"}
|