@agentclientprotocol/claude-agent-acp 0.106.1-preview.1 → 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-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 +54 -257
- 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";
|
|
@@ -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)
|
|
@@ -4621,21 +4440,6 @@ export class ClaudeAcpAgent {
|
|
|
4621
4440
|
// non-streaming fallback); its shared id keeps the per-block
|
|
4622
4441
|
// messages from moving the time.
|
|
4623
4442
|
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
4443
|
}
|
|
4640
4444
|
}
|
|
4641
4445
|
else {
|
|
@@ -5132,25 +4936,9 @@ export class ClaudeAcpAgent {
|
|
|
5132
4936
|
break;
|
|
5133
4937
|
}
|
|
5134
4938
|
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)) {
|
|
4939
|
+
const toolCallId = progressToolCallId(message, session.emittedToolCalls);
|
|
4940
|
+
if (toolCallId === undefined)
|
|
5152
4941
|
break;
|
|
5153
|
-
}
|
|
5154
4942
|
// The beat is in the subagent whose Agent call is
|
|
5155
4943
|
// `parent_tool_use_id`, unless it reports on that Agent call
|
|
5156
4944
|
// itself: the Agent call's own heartbeat falls back to its id, and
|
|
@@ -5204,7 +4992,9 @@ export class ClaudeAcpAgent {
|
|
|
5204
4992
|
// and task store are independent of the previous transcript.
|
|
5205
4993
|
// Clear both the in-memory snapshot and the client's visible plan
|
|
5206
4994
|
// before any follow-up prompt can republish stale tasks.
|
|
5207
|
-
await finishLifecycle("failed", "failed", "during conversation reset"
|
|
4995
|
+
await finishLifecycle("failed", "failed", "during conversation reset", {
|
|
4996
|
+
mayStillRun: true,
|
|
4997
|
+
});
|
|
5208
4998
|
subagents.clear();
|
|
5209
4999
|
asyncTasks.clear();
|
|
5210
5000
|
session.resolvedToolNames?.clear();
|
|
@@ -5967,7 +5757,8 @@ export class ClaudeAcpAgent {
|
|
|
5967
5757
|
// A subagent's text replays onto the root only for a client that gets it
|
|
5968
5758
|
// there live: one without native subagent sessions that asked for the
|
|
5969
5759
|
// flattened transcript. With native sessions the text goes to the child
|
|
5970
|
-
// 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.
|
|
5971
5762
|
const forwardSubagentText = !clientSupportsSubagents(this.clientCapabilities) &&
|
|
5972
5763
|
(session?.forwardSubagentText ?? supportsSubagentTranscript(this.clientCapabilities));
|
|
5973
5764
|
const supportsTypedFailures = supportsAirSessionFailures(this.clientCapabilities);
|
|
@@ -6307,7 +6098,10 @@ export class ClaudeAcpAgent {
|
|
|
6307
6098
|
}
|
|
6308
6099
|
if (rfdReplay && (await rfdReplay.toolCallUpdate(notification.update, child)))
|
|
6309
6100
|
continue;
|
|
6310
|
-
|
|
6101
|
+
const replayed = { ...notification, sessionId: replayTargetSessionId };
|
|
6102
|
+
await this.client.sessionUpdate(rfdReplay
|
|
6103
|
+
? asSdkSessionNotification(rfdReplay.withTarget(replayed, replayTargetSessionId))
|
|
6104
|
+
: replayed);
|
|
6311
6105
|
}
|
|
6312
6106
|
// The history of each subagent is in its own transcript. The replay
|
|
6313
6107
|
// sends it to the child session right after the launch, one message at
|
|
@@ -7052,6 +6846,17 @@ export class ClaudeAcpAgent {
|
|
|
7052
6846
|
* The work that follows a session setup response: the session's commands,
|
|
7053
6847
|
* the current states of the subagents a load replayed, and MCP server
|
|
7054
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.
|
|
7055
6860
|
*/
|
|
7056
6861
|
afterSetupResponse(sessionId, mcpServers) {
|
|
7057
6862
|
setTimeout(() => {
|
|
@@ -7128,12 +6933,11 @@ export class ClaudeAcpAgent {
|
|
|
7128
6933
|
});
|
|
7129
6934
|
}
|
|
7130
6935
|
/**
|
|
7131
|
-
*
|
|
7132
|
-
* (`readContextWindow`), without blocking the caller.
|
|
7133
|
-
*
|
|
7134
|
-
* `
|
|
7135
|
-
*
|
|
7136
|
-
* 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.
|
|
7137
6941
|
*/
|
|
7138
6942
|
refreshContextWindowInBackground(sessionId, session) {
|
|
7139
6943
|
if (session.contextWindowAuthoritative)
|
|
@@ -7166,21 +6970,18 @@ export class ClaudeAcpAgent {
|
|
|
7166
6970
|
}
|
|
7167
6971
|
else if (configId === MODEL_CONFIG_ID) {
|
|
7168
6972
|
// `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.
|
|
6973
|
+
// the Auto fallback below.
|
|
7172
6974
|
const newModelInfo = session.modelInfos.find((m) => m.value === value);
|
|
7173
6975
|
const modelChanged = session.models.currentModelId !== value;
|
|
7174
6976
|
if (modelChanged) {
|
|
7175
6977
|
session.idleCompaction?.disarm("model change");
|
|
7176
6978
|
// Seed the new model's context window WITHOUT awaited IPC on the
|
|
7177
6979
|
// 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`).
|
|
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`).
|
|
7184
6985
|
const seeded = immediateContextWindow(session.providerCacheKey, value, newModelInfo);
|
|
7185
6986
|
session.contextWindowSize = seeded.size;
|
|
7186
6987
|
session.contextWindowAuthoritative = seeded.authoritative;
|
|
@@ -7892,7 +7693,7 @@ export class ClaudeAcpAgent {
|
|
|
7892
7693
|
// session does (see `aliasResumedModelRow`).
|
|
7893
7694
|
const sdkModels = aliasResumedModelRow(initializationResult.models, creationOpts.resume !== undefined ? resumedModel : undefined);
|
|
7894
7695
|
const settingsAllowedModels = Array.isArray(settingsAvailableModels)
|
|
7895
|
-
? applyAvailableModelsAllowlist(sdkModels, settingsAvailableModels, settingsModelOverrides, settingsManager.getManagedDeniedModels())
|
|
7696
|
+
? await applyAvailableModelsAllowlist(sdkModels, settingsAvailableModels, settingsModelOverrides, settingsManager.getManagedDeniedModels())
|
|
7896
7697
|
: sdkModels;
|
|
7897
7698
|
// Then keep only the models the `providers/set` gateway listed.
|
|
7898
7699
|
const allowedModels = resolvedProvider?.listedModels
|
|
@@ -7934,7 +7735,8 @@ export class ClaudeAcpAgent {
|
|
|
7934
7735
|
// `fast_mode_disabled_reason` reflects the post-switch model since SDK
|
|
7935
7736
|
// 0.3.219 (the initialize response used to answer from the spawn-time
|
|
7936
7737
|
// model). A fresh SDK session reports `sdk_opt_in_required` — the toggle IS
|
|
7937
|
-
// the opt-in — which normalizes
|
|
7738
|
+
// the opt-in — which normalizes to `undefined`, as does `pending`; every
|
|
7739
|
+
// other reason is retained.
|
|
7938
7740
|
const fastModeDisabledReason = fastModeEnabled
|
|
7939
7741
|
? undefined
|
|
7940
7742
|
: normalizeFastModeDisabledReason(initializationResult.fast_mode_disabled_reason);
|
|
@@ -7975,21 +7777,16 @@ export class ClaudeAcpAgent {
|
|
|
7975
7777
|
}
|
|
7976
7778
|
// Seed the context window without awaited IPC. The cached authoritative
|
|
7977
7779
|
// 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
|
|
7982
|
-
//
|
|
7983
|
-
// Text inference alone misses aliases that resolve to extended-context
|
|
7984
|
-
// models with no "1m" token anywhere in their id or description (e.g.
|
|
7985
|
-
// `sonnet` → claude-sonnet-5, and `opus`/`default` since CLI 2.1.283,
|
|
7986
|
-
// 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.
|
|
7987
7785
|
//
|
|
7988
|
-
// The
|
|
7989
|
-
// fallback-resolved sibling's resolvedModel
|
|
7990
|
-
//
|
|
7991
|
-
//
|
|
7992
|
-
// 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.
|
|
7993
7790
|
const seededWindow = immediateContextWindow(providerCacheKey, models.currentModelId, allowlistedModelInfo);
|
|
7994
7791
|
if (creationOpts.replacingSession?.tornDown) {
|
|
7995
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"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** Normalize skills without changing their SDK semantics. Array order and
|
|
2
|
+
* duplicates do not affect the selected skill set, so neither should rebuild
|
|
3
|
+
* the underlying Query process. */
|
|
4
|
+
function normalizeSkills(skills) {
|
|
5
|
+
return Array.isArray(skills) ? [...new Set(skills)].sort() : skills;
|
|
6
|
+
}
|
|
7
|
+
/** Whether a changed `_meta.claudeCode.options` key on session/load or
|
|
8
|
+
* session/resume must rebuild the Query process. Almost every option is read
|
|
9
|
+
* only when the process starts, so the default is `true`. Every key of the
|
|
10
|
+
* SDK's `Options` must be classified: an SDK bump that adds or removes an
|
|
11
|
+
* option fails to compile until it is decided here. */
|
|
12
|
+
const OPTION_REBUILDS_SESSION = {
|
|
13
|
+
additionalDirectories: true,
|
|
14
|
+
agentProgressSummaries: true,
|
|
15
|
+
agents: true,
|
|
16
|
+
allowDangerouslySkipPermissions: true,
|
|
17
|
+
allowedTools: true,
|
|
18
|
+
betas: true,
|
|
19
|
+
debug: true,
|
|
20
|
+
debugFile: true,
|
|
21
|
+
disallowedTools: true,
|
|
22
|
+
effort: true,
|
|
23
|
+
enableFileCheckpointing: true,
|
|
24
|
+
env: true,
|
|
25
|
+
executableArgs: true,
|
|
26
|
+
extraArgs: true,
|
|
27
|
+
fallbackModel: true,
|
|
28
|
+
forwardSubagentText: true,
|
|
29
|
+
includeHookEvents: true,
|
|
30
|
+
managedSettings: true,
|
|
31
|
+
maxBudgetUsd: true,
|
|
32
|
+
maxThinkingTokens: true,
|
|
33
|
+
maxTurns: true,
|
|
34
|
+
mcpServers: true,
|
|
35
|
+
model: true,
|
|
36
|
+
outputFormat: true,
|
|
37
|
+
pathToClaudeCodeExecutable: true,
|
|
38
|
+
permissionPrompts: true,
|
|
39
|
+
permissionPromptToolName: true,
|
|
40
|
+
persistSession: true,
|
|
41
|
+
perTaskStopAffordance: true,
|
|
42
|
+
planModeInstructions: true,
|
|
43
|
+
pluginDelivery: true,
|
|
44
|
+
plugins: true,
|
|
45
|
+
projectConfigRoot: true,
|
|
46
|
+
promptSuggestions: true,
|
|
47
|
+
sandbox: true,
|
|
48
|
+
sessionStoreFlush: true,
|
|
49
|
+
settings: true,
|
|
50
|
+
settingSources: true,
|
|
51
|
+
skills: true,
|
|
52
|
+
strictMcpConfig: true,
|
|
53
|
+
supportedDialogKinds: true,
|
|
54
|
+
systemPrompt: true,
|
|
55
|
+
taskBudget: true,
|
|
56
|
+
thinking: true,
|
|
57
|
+
toolAliases: true,
|
|
58
|
+
toolConfig: true,
|
|
59
|
+
tools: true,
|
|
60
|
+
verbatimPrompts: true,
|
|
61
|
+
// Managed or ignored by the adapter.
|
|
62
|
+
agent: false,
|
|
63
|
+
cwd: false,
|
|
64
|
+
executable: false,
|
|
65
|
+
includePartialMessages: false,
|
|
66
|
+
permissionMode: false,
|
|
67
|
+
// Per-call controls for attaching to the stored conversation.
|
|
68
|
+
continue: false,
|
|
69
|
+
forkSession: false,
|
|
70
|
+
resume: false,
|
|
71
|
+
resumeDropsTurn: false,
|
|
72
|
+
resumeSessionAt: false,
|
|
73
|
+
sessionId: false,
|
|
74
|
+
// Callbacks and live objects: they cannot cross JSON-RPC and have no stable serialized form.
|
|
75
|
+
abortController: false,
|
|
76
|
+
canUseTool: false,
|
|
77
|
+
hooks: false,
|
|
78
|
+
onElicitation: false,
|
|
79
|
+
onUserDialog: false,
|
|
80
|
+
sessionStore: false,
|
|
81
|
+
spawnClaudeCodeProcess: false,
|
|
82
|
+
stderr: false,
|
|
83
|
+
// No effect on an already-created session.
|
|
84
|
+
loadTimeoutMs: false,
|
|
85
|
+
title: false,
|
|
86
|
+
};
|
|
87
|
+
/** A JSON value with object keys sorted, so key order never changes a
|
|
88
|
+
* fingerprint. Functions and class instances (hook callbacks, abort
|
|
89
|
+
* controllers, in-process MCP servers) cannot cross JSON-RPC and have no
|
|
90
|
+
* stable serialized form, so they are left out. */
|
|
91
|
+
function canonicalJson(value) {
|
|
92
|
+
if (typeof value === "function")
|
|
93
|
+
return undefined;
|
|
94
|
+
if (value === null || typeof value !== "object")
|
|
95
|
+
return value;
|
|
96
|
+
if (Array.isArray(value))
|
|
97
|
+
return value.map(canonicalJson);
|
|
98
|
+
const proto = Object.getPrototypeOf(value);
|
|
99
|
+
if (proto !== Object.prototype && proto !== null)
|
|
100
|
+
return undefined;
|
|
101
|
+
return Object.fromEntries(Object.keys(value)
|
|
102
|
+
.sort()
|
|
103
|
+
.map((key) => [key, canonicalJson(value[key])])
|
|
104
|
+
.filter(([, entry]) => entry !== undefined));
|
|
105
|
+
}
|
|
106
|
+
/** Compute a stable fingerprint of the session-defining params so we can
|
|
107
|
+
* detect when a loadSession/resumeSession call requires tearing down and
|
|
108
|
+
* recreating the underlying Query process. Every option classified in
|
|
109
|
+
* {@link OPTION_REBUILDS_SESSION} is covered, so a warm resume never silently
|
|
110
|
+
* keeps stale values. MCP servers are sorted by name, and skills are
|
|
111
|
+
* normalized as a set, so ordering differences don't trigger unnecessary
|
|
112
|
+
* recreations. */
|
|
113
|
+
export function computeSessionFingerprint(params) {
|
|
114
|
+
const servers = [...(params.mcpServers ?? [])].sort((a, b) => a.name.localeCompare(b.name));
|
|
115
|
+
const meta = params._meta;
|
|
116
|
+
const options = Object.fromEntries(Object.entries(meta?.claudeCode?.options ?? {}).filter(([key]) => OPTION_REBUILDS_SESSION[key] === true));
|
|
117
|
+
options.skills = normalizeSkills(options.skills);
|
|
118
|
+
return JSON.stringify(canonicalJson({
|
|
119
|
+
cwd: params.cwd,
|
|
120
|
+
mcpServers: servers,
|
|
121
|
+
additionalDirectories: params.additionalDirectories,
|
|
122
|
+
additionalRoots: meta?.additionalRoots,
|
|
123
|
+
systemPrompt: meta?.systemPrompt,
|
|
124
|
+
clientSystemPrompt: params.systemPrompt ?? undefined,
|
|
125
|
+
disableBuiltInTools: meta?.disableBuiltInTools,
|
|
126
|
+
emitRawSDKMessages: meta?.claudeCode?.emitRawSDKMessages,
|
|
127
|
+
options,
|
|
128
|
+
}));
|
|
129
|
+
}
|