@agentclientprotocol/claude-agent-acp 0.109.0 → 0.109.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.
Files changed (72) hide show
  1. package/README.md +10 -5
  2. package/dist/acp-subagents.d.ts +39 -0
  3. package/dist/acp-subagents.d.ts.map +1 -1
  4. package/dist/acp-subagents.js +47 -0
  5. package/dist/auth-status-reporter.d.ts +2 -3
  6. package/dist/auth-status-reporter.d.ts.map +1 -1
  7. package/dist/auth-status-reporter.js +32 -29
  8. package/dist/auth-status.d.ts +6 -7
  9. package/dist/auth-status.d.ts.map +1 -1
  10. package/dist/auth-status.js +9 -8
  11. package/dist/client-system-prompt.d.ts +6 -4
  12. package/dist/client-system-prompt.d.ts.map +1 -1
  13. package/dist/client-system-prompt.js +7 -2
  14. package/dist/context-compaction.d.ts.map +1 -1
  15. package/dist/context-compaction.js +4 -3
  16. package/dist/native-subagents.d.ts +102 -7
  17. package/dist/native-subagents.d.ts.map +1 -1
  18. package/dist/native-subagents.js +208 -17
  19. package/dist/plans.d.ts +4 -4
  20. package/dist/providers.d.ts +34 -1
  21. package/dist/providers.d.ts.map +1 -1
  22. package/dist/providers.js +37 -1
  23. package/dist/serve.d.ts +1 -1
  24. package/dist/serve.js +1 -1
  25. package/dist/session-config-options.d.ts.map +1 -1
  26. package/dist/session-config-options.js +13 -0
  27. package/dist/subagent-replay.d.ts +49 -33
  28. package/dist/subagent-replay.d.ts.map +1 -1
  29. package/dist/subagent-replay.js +49 -52
  30. package/dist/tool-calls/renderer.d.ts +0 -9
  31. package/dist/tool-calls/renderer.d.ts.map +1 -1
  32. package/dist/tool-calls/renderer.js +1 -19
  33. package/dist/tool-calls/reporters/interaction.d.ts +9 -0
  34. package/dist/tool-calls/reporters/interaction.d.ts.map +1 -1
  35. package/dist/tool-calls/reporters/interaction.js +23 -1
  36. package/dist/tool-calls/reporters/search.d.ts +7 -3
  37. package/dist/tool-calls/reporters/search.d.ts.map +1 -1
  38. package/dist/tool-calls/reporters/search.js +9 -4
  39. package/dist/v1/acp-agent.d.ts +35 -19
  40. package/dist/v1/acp-agent.d.ts.map +1 -1
  41. package/dist/v1/acp-agent.js +123 -67
  42. package/dist/v1/client-connection.d.ts +4 -2
  43. package/dist/v1/client-connection.d.ts.map +1 -1
  44. package/dist/v1/client-connection.js +6 -2
  45. package/dist/v1/session-fingerprint.d.ts.map +1 -1
  46. package/dist/v1/session-fingerprint.js +1 -2
  47. package/dist/v2/agent.d.ts.map +1 -1
  48. package/dist/v2/agent.js +53 -19
  49. package/dist/v2/auth.d.ts +6 -5
  50. package/dist/v2/auth.d.ts.map +1 -1
  51. package/dist/v2/auth.js +2 -2
  52. package/dist/v2/permissions.d.ts +1 -1
  53. package/dist/v2/permissions.js +1 -1
  54. package/dist/v2/replay-hold.d.ts +15 -5
  55. package/dist/v2/replay-hold.d.ts.map +1 -1
  56. package/dist/v2/replay-hold.js +21 -7
  57. package/dist/v2/reports.d.ts +4 -0
  58. package/dist/v2/reports.d.ts.map +1 -1
  59. package/dist/v2/reports.js +10 -1
  60. package/dist/v2/session-requests.js +3 -1
  61. package/dist/v2/session-update.js +3 -3
  62. package/dist/v2/session.d.ts.map +1 -1
  63. package/dist/v2/session.js +2 -0
  64. package/dist/v2/subagent-replay.d.ts +20 -18
  65. package/dist/v2/subagent-replay.d.ts.map +1 -1
  66. package/dist/v2/subagent-replay.js +16 -31
  67. package/dist/v2/tasks.d.ts +55 -6
  68. package/dist/v2/tasks.d.ts.map +1 -1
  69. package/dist/v2/tasks.js +147 -19
  70. package/dist/v2/tool-call.d.ts.map +1 -1
  71. package/dist/v2/tool-call.js +23 -1
  72. package/package.json +4 -4
@@ -6,7 +6,7 @@ import { clientTakesPromptSuggestions, promptSuggestionOptions, PromptSuggestion
6
6
  import { savedSessionStatus, SESSION_STATUS_CAPABILITY } from "../session-status.js";
7
7
  import { applyInitialConfigOptions, initialConfigOptions, SESSION_OPTIONS_CAPABILITY, } from "../initial-config-options.js";
8
8
  import { sanitizeTitle, SessionTitles } from "../session-titles.js";
9
- import { AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY, asSdkSessionNotification, clientSupportsSubagents, restrictedChild, subagentForm, } from "../acp-subagents.js";
9
+ import { AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY, AnnouncedChildren, asSdkSessionNotification, clientSupportsSubagents, restrictedChild, subagentForm, } from "../acp-subagents.js";
10
10
  import { childModelOption, isNativeSubagentControlTool, isNativeSubagentControlUpdate, NativeSubagentRuntime, nativeSubagentState, responseModelEntry, resumedNativeSubagentId, sameModelEntry, sendMessageResume, sendMessageResumePrompt, } from "../native-subagents.js";
11
11
  import { AIR_ASYNC_TASKS_CAPABILITY, AIR_BACKGROUND_SUBAGENTS_CAPABILITY, AIR_CUSTOM_INSTRUCTIONS_CAPABILITY, airCustomInstructions, AIR_DIFF_PATCH_CAPABILITY, AIR_PLAN_FILE_CAPABILITY, AIR_GOAL_KEY, AIR_LOAD_REPLAY_END_CAPABILITY, AIR_LOAD_REPLAY_END_KEY, AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY, clientSupportsAirCapability, withAirMeta, } from "../air-extension.js";
12
12
  import * as sessionIndex from "./session-index.js";
@@ -28,7 +28,7 @@ import { startMcpServerAuthentication as startSharedMcpServerAuthentication, sup
28
28
  import { forkSession } from "../fork-session.js";
29
29
  import { clientSystemPrompt, sessionSystemPrompt, SYSTEM_PROMPT_CAPABILITY, } from "../client-system-prompt.js";
30
30
  import { readSubagentMessages, subagentHistory, subagentLaunchIds, subagentLaunchedBy, subagentLineage, } from "../subagent-history.js";
31
- import { RfdSubagentReplay, firstResponseModel, replaySubagentTerminalState, } from "../subagent-replay.js";
31
+ import { RfdSubagentReplay, replaySubagentTerminalState, } from "../subagent-replay.js";
32
32
  import { readHistoryAcrossCompactions, readResumedSession, readResumedTail, } from "../resumed-session.js";
33
33
  import { SessionTiming } from "../session-timing.js";
34
34
  import { ALLOW_BYPASS, autoModeDisabled } from "../permissions/modes.js";
@@ -63,7 +63,7 @@ import { parseMcpCommand, runMcpCommand } from "../mcp-command.js";
63
63
  import { configuredSettings, resolveThinkingConfig } from "../session-env.js";
64
64
  import { MODE_CONFIG_ID, resolveInitialPermissionMode, SessionModeManager, } from "../session-mode.js";
65
65
  import { aliasResumedModelRow, applyAvailableModelsAllowlist, getAvailableModels, MODEL_CONFIG_ID, modelDisplayName, modelEntryFor, narrowToGatewayModels, resolveModelPreference, withCurrentModelInfo, } from "../session-model.js";
66
- import { createEnvForProvider, defaultProviderConfig, gatewayRequestToProviderConfig, isGatewayAuthMethod, listProvidersResponse, loggableBaseUrl, PROVIDER_ID, providerConfigFromSetRequest, validatedGatewayAuthRequest, withListedModels, } from "../providers.js";
66
+ import { applyProviderRoute, createEnvForProvider, defaultProviderConfig, gatewayRequestToProviderConfig, isGatewayAuthMethod, listProvidersResponse, loggableBaseUrl, PROVIDER_ID, providerConfigFromSetRequest, providerRouteSettings, validatedGatewayAuthRequest, withListedModels, } from "../providers.js";
67
67
  import { EFFORT_CONFIG_ID, effortFlagSettings, effortForModelSwitch, mergeEffortSettings, settleEffortAfterModelSwitch, settingsEffortForModel, withoutEffort, } from "../session-effort.js";
68
68
  import { createUltracodeConfigOption, readUltracodeSettings, ULTRACODE_CONFIG_ID, ultracodeSupported, ultracodeWorkflowsEnabled, } from "../session-ultracode.js";
69
69
  import { buildConfigOptions, clientSupportsBooleanConfigOptions, clientSupportsRecommendedConfigValue, configOptionValue, setSelectedModel, discoverCustomAgents, } from "../session-config-options.js";
@@ -386,9 +386,16 @@ export class ClaudeAcpAgent {
386
386
  toolUseWaitMs = TOOL_USE_WAIT_MS;
387
387
  /**
388
388
  * The subagent replay of each session's last load, until
389
- * {@link publishCurrentSubagentStates} sends its children's current states.
389
+ * {@link publishCurrentSubagentStates} sends its children's current states
390
+ * and configurations.
390
391
  */
391
392
  replayedSubagents = new Map();
393
+ /**
394
+ * The subagents RFD form: the child sessions that the sessions announced,
395
+ * from each one's `subagent_update` until the client ends its root session
396
+ * (see {@link endSession}) or the connection ends (see `AnnouncedChildren`).
397
+ */
398
+ announcedChildren = new AnnouncedChildren();
392
399
  /**
393
400
  * AIR's draft: the model that the last load of each session replayed to each
394
401
  * child session, as the model id and the entry that went out. See
@@ -414,7 +421,7 @@ export class ClaudeAcpAgent {
414
421
  agent: this,
415
422
  isAirClient: () => this.toolCallCapabilities.air.client,
416
423
  interruptSession: (sessionId) => this.cancelTurns({ sessionId }, { awaitInterrupt: false }),
417
- teardownSession: (sessionId) => this.teardownSession(sessionId),
424
+ teardownSession: (sessionId) => this.endSession(sessionId),
418
425
  });
419
426
  /**
420
427
  * Whether a turn ends at its result while background subagents that it
@@ -430,7 +437,9 @@ export class ClaudeAcpAgent {
430
437
  }
431
438
  constructor(client, logger) {
432
439
  this.sessions = {};
433
- this.client = new ChangedMetaClient(client, () => this.toolCallCapabilities.air.client);
440
+ this.client = new ChangedMetaClient(client, () => this.toolCallCapabilities.air.client,
441
+ // Before the client can name the child that a `subagent_update` announces.
442
+ (update) => this.announcedChildren.sending(update));
434
443
  this.logger = logger ?? console;
435
444
  this.exitPlan = new ExitPlanCoordinator({
436
445
  currentSession: (id) => this.sessions[id],
@@ -623,7 +632,7 @@ export class ClaudeAcpAgent {
623
632
  * the same `cwd`, additional directories and `_meta` would answer with, or
624
633
  * `session/load` and `session/resume` of `sessionId`.
625
634
  *
626
- * A session that this connection holds answers with what it has now.
635
+ * A held session answers from memory if load/resume would reuse its query.
627
636
  * Otherwise a query starts as the session's would, without MCP servers, and
628
637
  * closes once its options are read (`optionsOnly` in `createSession`). The
629
638
  * query does not persist: it stores no session, and it does not write to
@@ -631,22 +640,20 @@ export class ClaudeAcpAgent {
631
640
  * hooks in it, as in every query.
632
641
  *
633
642
  * It sends no update, and it creates, loads and changes no session. A
634
- * `sessionId` without a stored conversation fails with `-32002`.
643
+ * `sessionId` that is neither held nor stored fails with `-32002`.
635
644
  */
636
645
  async sessionOptions(params) {
637
646
  while (this.providerUpdate)
638
647
  await this.providerUpdate;
639
- const held = params.sessionId != null ? this.sessions[params.sessionId] : undefined;
640
- if (held) {
641
- await this.validateCwd(params.cwd, params.additionalDirectories);
642
- return { modes: held.modes, configOptions: held.configOptions };
643
- }
644
- const { modes, configOptions } = await this.createSession({
648
+ const setup = {
645
649
  cwd: params.cwd,
646
650
  mcpServers: [],
647
651
  additionalDirectories: params.additionalDirectories,
648
652
  _meta: params._meta,
649
- }, { resume: params.sessionId ?? undefined, optionsOnly: true });
653
+ };
654
+ const { modes, configOptions } = params.sessionId == null
655
+ ? await this.createSession(setup, { optionsOnly: true })
656
+ : await this.getOrCreateSession({ ...setup, sessionId: params.sessionId }, { optionsOnly: true });
650
657
  return { modes, configOptions };
651
658
  }
652
659
  /**
@@ -778,7 +785,7 @@ export class ClaudeAcpAgent {
778
785
  let result;
779
786
  if (this.sessions[params.sessionId]) {
780
787
  const resumedSession = await readResumedSession(params.sessionId, this.logger);
781
- result = await this.getOrCreateSession(params, resumedSession);
788
+ result = await this.getOrCreateSession(params, { resumedSession });
782
789
  timing.phase("session-ready");
783
790
  await this.replaySessionHistory(params.sessionId, resumedSession.messages);
784
791
  }
@@ -1379,14 +1386,10 @@ export class ClaudeAcpAgent {
1379
1386
  });
1380
1387
  }
1381
1388
  /**
1382
- * Starts a new query for the session `sessionId`, which ran on this
1383
- * connection and whose query is gone: it resumes the stored conversation.
1384
- * `resume` names the Claude session, which shares the ACP session id, so the
1385
- * new query continues the same conversation under the same id. Claude Code
1386
- * writes the conversation at the first prompt, so resuming a session that was
1387
- * never prompted fails with `sessionNotFound`, and keeps failing. Such a
1388
- * session starts a fresh query under the same id instead: it has no history
1389
- * to lose, and the client keeps a session it can use.
1389
+ * Starts the query that a held session would resume with. Claude Code writes
1390
+ * the conversation at the first prompt. If there's nothing to resume, start
1391
+ * fresh: a replacement keeps the session's id; an options probe keeps neither
1392
+ * query nor id.
1390
1393
  */
1391
1394
  async recreateLiveSession(params, sessionId, options) {
1392
1395
  try {
@@ -1396,9 +1399,10 @@ export class ClaudeAcpAgent {
1396
1399
  if (!(error instanceof RequestError && error.code === RequestError.sessionNotFound(sessionId).code)) {
1397
1400
  throw error;
1398
1401
  }
1399
- this.logger.log(`session ${sessionId} was never persisted; starting a fresh query under the same id`);
1402
+ this.logger.log(`session ${sessionId} has no stored conversation; starting a fresh query`);
1400
1403
  return await this.createSession(params, {
1401
- reuseSessionId: sessionId,
1404
+ // A probe doesn't claim the id of the session it is describing.
1405
+ ...(options.optionsOnly ? { optionsOnly: true } : { reuseSessionId: sessionId }),
1402
1406
  permissionMode: options.permissionMode,
1403
1407
  replacingSession: options.replacingSession,
1404
1408
  });
@@ -3079,6 +3083,14 @@ export class ClaudeAcpAgent {
3079
3083
  noTurnOwnsCycle()) {
3080
3084
  await asyncTasks.autonomousTurnStarted();
3081
3085
  }
3086
+ // Before the message's updates are routed: a subagent's message names
3087
+ // its child session, and an end that waited for such messages is
3088
+ // reported (see `NativeSubagentRuntime.messageCame`). Awaited only
3089
+ // when an end is reported, so that no cancel runs between any other
3090
+ // message and its handling.
3091
+ const reported = subagents.messageCame(message, sendUpdate);
3092
+ if (reported)
3093
+ await reported;
3082
3094
  switch (message.type) {
3083
3095
  case "system":
3084
3096
  switch (message.subtype) {
@@ -3596,6 +3608,10 @@ export class ClaudeAcpAgent {
3596
3608
  subagentType: message.subagent_type,
3597
3609
  description: message.description,
3598
3610
  prompt: message.prompt,
3611
+ launchTool: message.tool_use_id
3612
+ ? session.toolUseCache[message.tool_use_id]?.name
3613
+ : undefined,
3614
+ parentTaskId: message.parent_task_id,
3599
3615
  }, sendUpdate);
3600
3616
  await asyncTasks.taskStarted({
3601
3617
  task_id: message.task_id,
@@ -3627,7 +3643,10 @@ export class ClaudeAcpAgent {
3627
3643
  break;
3628
3644
  // The task settled — no further tool calls can originate
3629
3645
  // from it, so its registry entry can be dropped.
3630
- await subagents.finishTask(message.task_id, message.status, sendUpdate, message.tool_use_id, { reason: message.reason });
3646
+ await subagents.finishTask(message.task_id, message.status, sendUpdate, message.tool_use_id, {
3647
+ reason: message.reason,
3648
+ foreground: session.liveBackgroundTasks.get(message.task_id)?.backgrounded === false,
3649
+ });
3631
3650
  await asyncTasks.taskNotification({
3632
3651
  task_id: message.task_id,
3633
3652
  status: message.status,
@@ -3669,7 +3688,10 @@ export class ClaudeAcpAgent {
3669
3688
  if (message.patch.status === "completed" ||
3670
3689
  message.patch.status === "failed" ||
3671
3690
  message.patch.status === "killed") {
3672
- await subagents.finishTask(message.task_id, message.patch.status, sendUpdate, undefined, { error: message.patch.status === "failed" ? message.patch.error : undefined });
3691
+ await subagents.finishTask(message.task_id, message.patch.status, sendUpdate, undefined, {
3692
+ error: message.patch.status === "failed" ? message.patch.error : undefined,
3693
+ foreground: session.liveBackgroundTasks.get(message.task_id)?.backgrounded === false,
3694
+ });
3673
3695
  const parentToolUseId = session.liveBackgroundTasks.get(message.task_id)?.parentToolUseId;
3674
3696
  if (parentToolUseId) {
3675
3697
  streamedBlocksByParent.delete(parentToolUseId);
@@ -5293,16 +5315,14 @@ export class ClaudeAcpAgent {
5293
5315
  }
5294
5316
  /**
5295
5317
  * Throws invalid params (-32602) when `sessionId` is a child session that a
5296
- * session of this connection announced on the subagents RFD form (see
5297
- * `NativeSubagentRuntime.hasChild`): the client can cancel a child, and
5298
- * nothing else. `method` completes "the client cannot … it".
5318
+ * session of this connection announced on the subagents RFD form, while it
5319
+ * ran or in a load's replay, and that session is not closed (see
5320
+ * `AnnouncedChildren`): the client can cancel a child, and nothing else.
5321
+ * `method` completes "the client cannot … it".
5299
5322
  */
5300
5323
  assertNoChildSession(sessionId, method) {
5301
- for (const session of Object.values(this.sessions)) {
5302
- if (session.nativeSubagentRuntime?.hasChild(sessionId)) {
5303
- throw restrictedChild(sessionId, method);
5304
- }
5305
- }
5324
+ if (this.announcedChildren.has(sessionId))
5325
+ throw restrictedChild(sessionId, method);
5306
5326
  }
5307
5327
  /**
5308
5328
  * Cancels the current work of the subagent child session `sessionId`, which
@@ -5797,12 +5817,20 @@ export class ClaudeAcpAgent {
5797
5817
  this.sessionIndex.dispose();
5798
5818
  await Promise.all(Object.keys(this.sessions).map((id) => this.teardownSession(id)));
5799
5819
  }
5820
+ /**
5821
+ * {@link teardownSession}, for a session that the client ends: with
5822
+ * `session/close`, `session/delete`, or an archive. The client can no
5823
+ * longer name the session's children then (see `AnnouncedChildren`). A load
5824
+ * or resume that replaces the session's query keeps them.
5825
+ */
5826
+ async endSession(sessionId) {
5827
+ await this.teardownSession(sessionId);
5828
+ // After the teardown's last updates, which name the children.
5829
+ this.announcedChildren.rootClosed(sessionId);
5830
+ }
5800
5831
  /** Idempotent: a session that is not loaded here is already closed. */
5801
5832
  async closeSession(params) {
5802
- if (!this.sessions[params.sessionId]) {
5803
- return {};
5804
- }
5805
- await this.teardownSession(params.sessionId);
5833
+ await this.endSession(params.sessionId);
5806
5834
  return {};
5807
5835
  }
5808
5836
  /**
@@ -6040,7 +6068,7 @@ export class ClaudeAcpAgent {
6040
6068
  ? await subagentHistory(sessionId)
6041
6069
  : { agents: new Map() };
6042
6070
  const rfdReplay = form === "rfd"
6043
- ? new RfdSubagentReplay(rfdHistory, (notification) => this.client.sessionUpdate(asSdkSessionNotification(notification)), this.subagentModels(sessionId), !pending, session?.cwd)
6071
+ ? new RfdSubagentReplay(rfdHistory, (notification) => this.client.sessionUpdate(asSdkSessionNotification(notification)), this.subagentModels(sessionId), session?.cwd)
6044
6072
  : undefined;
6045
6073
  rfdReplay?.scan(messages, sessionId);
6046
6074
  // History persists no task_started frame, so a background task gets its
@@ -6150,7 +6178,7 @@ export class ClaudeAcpAgent {
6150
6178
  if (message.type === "assistant") {
6151
6179
  const model = message.message.model;
6152
6180
  if (rfdReplay && child) {
6153
- await rfdReplay.responseModel(child, model);
6181
+ rfdReplay.responseModel(child, model);
6154
6182
  }
6155
6183
  else if (nativeReplayEnabled && parentToolUseId) {
6156
6184
  // AIR's draft: the entry of the model list that is known now. A load
@@ -6268,7 +6296,7 @@ export class ClaudeAcpAgent {
6268
6296
  if (!launched || launched.announced)
6269
6297
  continue;
6270
6298
  const childMessages = await readSubagentMessages(sessionId, launched.sessionId, rfdHistory, this.logger);
6271
- await rfdReplay.announce(launched, firstResponseModel(childMessages));
6299
+ await rfdReplay.announce(launched);
6272
6300
  rfdReplay.scan(childMessages, launched.sessionId);
6273
6301
  for (const childMessage of childMessages)
6274
6302
  await replayMessage(childMessage, launched);
@@ -7025,7 +7053,7 @@ export class ClaudeAcpAgent {
7025
7053
  *
7026
7054
  * Call it in the same synchronous step as the handler's `return`: an
7027
7055
  * `await` between them would let the timer run before the response. The ACP
7028
- * SDK (2.8.0) gives a request handler no responder and no after-response
7056
+ * SDK (2.9.1) gives a request handler no responder and no after-response
7029
7057
  * hook, so the order rests on two things that its source shows and its API
7030
7058
  * does not promise. `registerAppRequest` queues the response in the
7031
7059
  * microtask that follows the handler's return, with no macrotask in
@@ -7051,20 +7079,27 @@ export class ClaudeAcpAgent {
7051
7079
  }, 0);
7052
7080
  }
7053
7081
  /**
7054
- * Sends the current state of each subagent that the last load of
7055
- * `sessionId` replayed (see {@link RfdSubagentReplay.currentStates}). Run it
7056
- * only after the load response: before it, the client treats subagent states
7057
- * as history.
7082
+ * Sends what is current of the subagents of `sessionId` after a session
7083
+ * setup response: the state and configuration of each one that the last
7084
+ * load replayed (see {@link RfdSubagentReplay.currentStates}), then each
7085
+ * one that works in the session and that no replay announced, with its
7086
+ * announcement again (see `NativeSubagentRuntime.currentChildren`). The
7087
+ * second kind is a child of a session that was resumed, which replays
7088
+ * nothing, or one whose launch the loaded history does not have, such as a
7089
+ * forked skill's. Run it only after the response: before a load's response,
7090
+ * the client treats a subagent's state and configuration as history.
7058
7091
  */
7059
7092
  async publishCurrentSubagentStates(sessionId) {
7060
7093
  await this.publishReplayedChildModels(sessionId);
7061
7094
  const replay = this.replayedSubagents.get(sessionId);
7062
- if (!replay)
7063
- return;
7064
7095
  this.replayedSubagents.delete(sessionId);
7065
7096
  const runtime = this.sessions[sessionId]?.nativeSubagentRuntime;
7066
7097
  try {
7067
- for (const notification of replay.currentStates((child) => runtime?.liveWorkState(child), (child) => runtime?.configurationOf?.(child))) {
7098
+ const current = [
7099
+ ...(replay?.currentStates((child) => runtime?.liveWorkState(child), (child) => runtime?.configurationOf?.(child)) ?? []),
7100
+ ...(runtime?.currentChildren((child) => replay?.announced(child) === true) ?? []),
7101
+ ];
7102
+ for (const notification of current) {
7068
7103
  await this.client.sessionUpdate(asSdkSessionNotification(notification));
7069
7104
  }
7070
7105
  }
@@ -7362,7 +7397,7 @@ export class ClaudeAcpAgent {
7362
7397
  },
7363
7398
  });
7364
7399
  }
7365
- async getOrCreateSession(params, resumedSession) {
7400
+ async getOrCreateSession(params, { resumedSession, optionsOnly, } = {}) {
7366
7401
  // Reject a bad `cwd` or prompt before reusing or tearing down a live session.
7367
7402
  await this.validateCwd(params.cwd, params.additionalDirectories);
7368
7403
  clientSystemPrompt(params.systemPrompt);
@@ -7370,7 +7405,15 @@ export class ClaudeAcpAgent {
7370
7405
  // A recreated live session keeps its mode, not the mode of the transcript.
7371
7406
  const livePermissionMode = existingSession?.modes.currentModeId;
7372
7407
  if (existingSession) {
7373
- const fingerprint = computeSessionFingerprint(params);
7408
+ // `session/options` cannot supply MCP servers or a system prompt. Their
7409
+ // absence in a probe is not a request to replace the held session's.
7410
+ const fingerprint = computeSessionFingerprint(optionsOnly
7411
+ ? {
7412
+ ...params,
7413
+ mcpServers: existingSession.creationParams?.mcpServers,
7414
+ systemPrompt: existingSession.creationParams?.systemPrompt,
7415
+ }
7416
+ : params);
7374
7417
  if (fingerprint === existingSession.sessionFingerprint) {
7375
7418
  return {
7376
7419
  sessionId: params.sessionId,
@@ -7378,11 +7421,9 @@ export class ClaudeAcpAgent {
7378
7421
  configOptions: existingSession.configOptions,
7379
7422
  };
7380
7423
  }
7381
- // Session-defining params changed (e.g. cwd pointed at a git worktree,
7382
- // MCP servers reconfigured, or the skill set changed). Tear down the
7383
- // existing session and recreate it so the underlying Query process picks
7384
- // up the new values.
7385
- await this.teardownSession(params.sessionId);
7424
+ // Load/resume replaces the query. An options probe leaves it running.
7425
+ if (!optionsOnly)
7426
+ await this.teardownSession(params.sessionId);
7386
7427
  }
7387
7428
  const sessionParams = {
7388
7429
  cwd: params.cwd,
@@ -7393,6 +7434,7 @@ export class ClaudeAcpAgent {
7393
7434
  };
7394
7435
  const creation = {
7395
7436
  permissionMode: livePermissionMode,
7437
+ optionsOnly,
7396
7438
  ...(resumedSession ? { resumedModelHint: resumedSession.model } : {}),
7397
7439
  };
7398
7440
  // A live session may never have been prompted, so it may have no stored
@@ -7454,7 +7496,11 @@ export class ClaudeAcpAgent {
7454
7496
  // We want to create a new session id unless it is resume,
7455
7497
  // but not resume + forkSession.
7456
7498
  let sessionId;
7457
- if (creationOpts.publicSessionId) {
7499
+ if (creationOpts.optionsOnly) {
7500
+ // The transcript to read is `resume`. No callback from this query owns that session.
7501
+ sessionId = randomUUID();
7502
+ }
7503
+ else if (creationOpts.publicSessionId) {
7458
7504
  sessionId = creationOpts.publicSessionId;
7459
7505
  }
7460
7506
  else if (creationOpts.forkSession) {
@@ -7578,14 +7624,14 @@ export class ClaudeAcpAgent {
7578
7624
  const providerEnv = createEnvForProvider(resolvedProvider);
7579
7625
  // With the model configuration of the environment (e.g. Bedrock model overrides).
7580
7626
  const configuredSettingsObject = await configuredSettings(userProvidedOptions?.settings, params.cwd);
7581
- // Claude Code applies env from settings.json after the subprocess env. Put
7582
- // an active ACP route in the programmatic settings tier too so user/project
7583
- // settings cannot silently restore a different ANTHROPIC_BASE_URL.
7584
- const settings = resolvedProvider
7627
+ // An active ACP route goes into the programmatic settings tier too (see
7628
+ // `providerRouteSettings`).
7629
+ const route = resolvedProvider ? providerRouteSettings(providerEnv) : undefined;
7630
+ const settings = route
7585
7631
  ? {
7586
7632
  ...configuredSettingsObject,
7587
- apiKeyHelper: "",
7588
- env: { ...configuredSettingsObject?.env, ...providerEnv },
7633
+ ...route,
7634
+ env: { ...configuredSettingsObject?.env, ...route.env },
7589
7635
  }
7590
7636
  : configuredSettingsObject;
7591
7637
  const env = {
@@ -7810,7 +7856,14 @@ export class ClaudeAcpAgent {
7810
7856
  },
7811
7857
  ...(creationOpts.resume !== undefined && { resume: creationOpts.resume }),
7812
7858
  ...(creationOpts.forkSession !== undefined && { forkSession: creationOpts.forkSession }),
7813
- ...(creationOpts.optionsOnly ? { persistSession: false } : {}),
7859
+ // The probe neither reports session updates through our hooks nor
7860
+ // starts the MCP servers in the client's options or workspace settings.
7861
+ ...(creationOpts.optionsOnly && {
7862
+ persistSession: false,
7863
+ hooks: userProvidedOptions?.hooks,
7864
+ strictMcpConfig: true,
7865
+ mcpServers: {},
7866
+ }),
7814
7867
  abortController,
7815
7868
  };
7816
7869
  // Prefer the official ACP `additionalDirectories` field. Fall back to the
@@ -7856,10 +7909,13 @@ export class ClaudeAcpAgent {
7856
7909
  error instanceof Error &&
7857
7910
  (error.message === "Query closed before response received" ||
7858
7911
  error.message.includes("No conversation found with session ID"))) {
7859
- throw RequestError.sessionNotFound(sessionId);
7912
+ throw RequestError.sessionNotFound(creationOpts.optionsOnly ? creationOpts.resume : sessionId);
7860
7913
  }
7861
7914
  throw startupFailureError(error) ?? error;
7862
7915
  }
7916
+ // Before a request of the session reaches the provider.
7917
+ if (route)
7918
+ await applyProviderRoute(q, route);
7863
7919
  timing.phase("sdk-initialize");
7864
7920
  // Publish the identity BEFORE the guard can refuse this session. A
7865
7921
  // refusal is exactly when the client most needs to know which account it
@@ -25,7 +25,8 @@ export declare class ClientConnection implements AcpClient {
25
25
  mcpServerOverAcp(server: McpServerAcp): Promise<McpHttpServerConfig>;
26
26
  }
27
27
  /**
28
- * The client that the agent talks to. For an AIR client, every session update
28
+ * The client that the agent talks to. `sending` takes every session update
29
+ * first, before it goes to the client. For an AIR client, every session update
29
30
  * passes the {@link ChangedMetaFilter} last, after the native subagent routing,
30
31
  * so a `tool_call_update` carries only the `_meta` keys that changed. ACP
31
32
  * merges only the top-level tool call fields, not the `_meta` keys. So another
@@ -34,8 +35,9 @@ export declare class ClientConnection implements AcpClient {
34
35
  export declare class ChangedMetaClient implements AcpClient {
35
36
  private readonly inner;
36
37
  private readonly airClient;
38
+ private readonly sending;
37
39
  private readonly filter;
38
- constructor(inner: AcpClient, airClient: () => boolean);
40
+ constructor(inner: AcpClient, airClient: () => boolean, sending?: (update: AcpSessionNotification) => void);
39
41
  sessionUpdate(params: AcpSessionNotification): Promise<void>;
40
42
  requestPermission(params: AcpPermissionRequest, signal?: AbortSignal): Promise<RequestPermissionResponse>;
41
43
  readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"client-connection.d.ts","sourceRoot":"","sources":["../../src/v1/client-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,YAAY,EAEZ,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EAEzB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAA4B,MAAM,qBAAqB,CAAC;AACvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAE3E;;;;;GAKG;AACH,qBAAa,gBAAiB,YAAW,SAAS;IAE9C,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBADH,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,UAAU;IAGlC,aAAa,CAAC,MAAM,EAAE,sBA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AAC,EAAE,WAAW,GACnB,OAAO,CAAC,yBAAyB,CAAC;IAIrC,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAIxE,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAI3E,iBAAiB,CACf,MAAM,EAAE,wBAAwB,EAChC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,yBAAyB,CAAC;IAIrC,mBAAmB,CAAC,MAAM,EAAE,+BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3E,gBAAgB,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrE,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/E,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAGrE"}
@@ -49,7 +49,8 @@ export class ClientConnection {
49
49
  }
50
50
  }
51
51
  /**
52
- * The client that the agent talks to. For an AIR client, every session update
52
+ * The client that the agent talks to. `sending` takes every session update
53
+ * first, before it goes to the client. For an AIR client, every session update
53
54
  * passes the {@link ChangedMetaFilter} last, after the native subagent routing,
54
55
  * so a `tool_call_update` carries only the `_meta` keys that changed. ACP
55
56
  * merges only the top-level tool call fields, not the `_meta` keys. So another
@@ -58,12 +59,15 @@ export class ClientConnection {
58
59
  export class ChangedMetaClient {
59
60
  inner;
60
61
  airClient;
62
+ sending;
61
63
  filter = new ChangedMetaFilter();
62
- constructor(inner, airClient) {
64
+ constructor(inner, airClient, sending = () => { }) {
63
65
  this.inner = inner;
64
66
  this.airClient = airClient;
67
+ this.sending = sending;
65
68
  }
66
69
  async sessionUpdate(params) {
70
+ this.sending(params);
67
71
  if (!this.airClient())
68
72
  return this.inner.sessionUpdate(params);
69
73
  const update = this.filter.apply(params.update);
@@ -1 +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;AA+G3E;;;;;;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"}
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;AA+G3E;;;;;;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,CAqBT"}
@@ -119,8 +119,7 @@ export function computeSessionFingerprint(params) {
119
119
  return JSON.stringify(canonicalJson({
120
120
  cwd: params.cwd,
121
121
  mcpServers: servers,
122
- additionalDirectories: params.additionalDirectories,
123
- additionalRoots: meta?.additionalRoots,
122
+ additionalDirectories: params.additionalDirectories ?? meta?.additionalRoots ?? [],
124
123
  systemPrompt: meta?.systemPrompt,
125
124
  clientSystemPrompt: params.systemPrompt ?? undefined,
126
125
  disableBuiltInTools: meta?.disableBuiltInTools,
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/v2/agent.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAaxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAqE3C,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC1B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,8CAA8C;AAC9C,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GACpC,EAAE,CAAC,QAAQ,CA6Cb"}
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/v2/agent.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAaxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAsE3C,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC1B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,8CAA8C;AAC9C,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GACpC,EAAE,CAAC,QAAQ,CA6Cb"}