@agentclientprotocol/claude-agent-acp 0.113.1-preview.1 → 0.113.1-preview.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/async-tasks.d.ts +27 -0
- package/dist/async-tasks.d.ts.map +1 -1
- package/dist/async-tasks.js +36 -0
- package/dist/claude-cli.d.ts +22 -16
- package/dist/claude-cli.d.ts.map +1 -1
- package/dist/claude-cli.js +40 -18
- package/dist/mcp-oauth.d.ts +3 -2
- package/dist/mcp-oauth.d.ts.map +1 -1
- package/dist/mcp-oauth.js +65 -27
- package/dist/query-settings.d.ts +42 -0
- package/dist/query-settings.d.ts.map +1 -0
- package/dist/query-settings.js +43 -0
- package/dist/resumed-session.d.ts +9 -2
- package/dist/resumed-session.d.ts.map +1 -1
- package/dist/resumed-session.js +51 -7
- package/dist/sdk-to-acp.js +4 -2
- package/dist/session-cursors.d.ts +1 -1
- package/dist/session-cursors.d.ts.map +1 -1
- package/dist/session-cursors.js +8 -2
- package/dist/session-index/service.d.ts.map +1 -1
- package/dist/session-index/service.js +9 -17
- package/dist/session-index/session-index.d.ts +1 -13
- package/dist/session-index/session-index.d.ts.map +1 -1
- package/dist/session-index/session-index.js +3 -29
- package/dist/session-index/transcript-scan.d.ts +17 -4
- package/dist/session-index/transcript-scan.d.ts.map +1 -1
- package/dist/session-index/transcript-scan.js +44 -3
- package/dist/session-mode.d.ts +69 -3
- package/dist/session-mode.d.ts.map +1 -1
- package/dist/session-mode.js +103 -15
- package/dist/session-model.d.ts +4 -1
- package/dist/session-model.d.ts.map +1 -1
- package/dist/session-model.js +26 -4
- package/dist/session-read.d.ts +45 -0
- package/dist/session-read.d.ts.map +1 -0
- package/dist/session-read.js +300 -0
- package/dist/session-rewind.d.ts +6 -2
- package/dist/session-rewind.d.ts.map +1 -1
- package/dist/session-rewind.js +13 -4
- package/dist/session-ultracode.d.ts +17 -5
- package/dist/session-ultracode.d.ts.map +1 -1
- package/dist/session-ultracode.js +16 -15
- package/dist/settings.d.ts +34 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +55 -4
- package/dist/startup-failure.d.ts +11 -1
- package/dist/startup-failure.d.ts.map +1 -1
- package/dist/startup-failure.js +33 -1
- package/dist/subagent-history.d.ts +9 -1
- package/dist/subagent-history.d.ts.map +1 -1
- package/dist/subagent-history.js +55 -13
- package/dist/v1/acp-agent.d.ts +8 -1
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +189 -94
- package/dist/v1/async-task-stop.d.ts +31 -0
- package/dist/v1/async-task-stop.d.ts.map +1 -1
- package/dist/v1/async-task-stop.js +41 -0
- package/dist/v1/session-read.d.ts +31 -0
- package/dist/v1/session-read.d.ts.map +1 -0
- package/dist/v1/session-read.js +62 -0
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +72 -29
- package/dist/v2/commands.d.ts +8 -3
- package/dist/v2/commands.d.ts.map +1 -1
- package/dist/v2/commands.js +4 -3
- package/dist/v2/config.d.ts +9 -8
- package/dist/v2/config.d.ts.map +1 -1
- package/dist/v2/config.js +15 -10
- package/dist/v2/session-read.d.ts +11 -0
- package/dist/v2/session-read.d.ts.map +1 -0
- package/dist/v2/session-read.js +28 -0
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +19 -2
- package/dist/v2/setup.d.ts +4 -1
- package/dist/v2/setup.d.ts.map +1 -1
- package/dist/v2/setup.js +4 -2
- package/dist/v2/stream.d.ts +9 -13
- package/dist/v2/stream.d.ts.map +1 -1
- package/dist/v2/stream.js +10 -9
- package/dist/v2/subagent-replay.d.ts +16 -4
- package/dist/v2/subagent-replay.d.ts.map +1 -1
- package/dist/v2/subagent-replay.js +22 -10
- package/dist/v2/tasks.d.ts.map +1 -1
- package/dist/v2/tasks.js +5 -3
- package/package.json +8 -8
package/dist/v1/acp-agent.js
CHANGED
|
@@ -12,7 +12,7 @@ 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";
|
|
15
|
+
import { ASYNC_TASK_STOP_METHOD, parseAsyncTaskStopRequest, interruptAutonomousTurn, interruptKeepsWaitingPrompts, waitingPrompts, } from "./async-task-stop.js";
|
|
16
16
|
import { STEER_METHOD, parseSteerRequest, } from "./steering.js";
|
|
17
17
|
import { AUTH_STATUS_UPDATE_METHOD, authStatusCapability, fromAccountInfo, gatewayAuthStatus, notLoggedInAuthStatus, } from "../auth-status.js";
|
|
18
18
|
import { AuthStatusReporter, cliLogout } from "../auth-status-reporter.js";
|
|
@@ -28,9 +28,10 @@ import { answerAskUserQuestion, answerMcpElicitation, answerUserDialog, elicitUn
|
|
|
28
28
|
import { startMcpServerAuthentication as startSharedMcpServerAuthentication, supportsMcpOAuth, } from "../mcp-oauth.js";
|
|
29
29
|
import { forkSession } from "../fork-session.js";
|
|
30
30
|
import { anchoredForkCursorUpdate, forkCursorUpdate, hasForkCursor, LastReportedEntity, promptGetsCursor, withRewindCapability, } from "../session-cursors.js";
|
|
31
|
+
import { SESSION_READ_CAPABILITY, SESSION_READ_METHOD } from "../session-read.js";
|
|
31
32
|
import { cutAtRewindPoint, loadRewindableHistory, parseSessionRewindRequest, prepareRewoundResume, rewindSession, SESSION_REWIND_METHOD, } from "../session-rewind.js";
|
|
32
33
|
import { clientSystemPrompt, sessionSystemPrompt, SYSTEM_PROMPT_CAPABILITY, } from "../client-system-prompt.js";
|
|
33
|
-
import { readSubagentMessages, subagentHistory, subagentLaunchIds, subagentLaunchedBy, subagentLineage, } from "../subagent-history.js";
|
|
34
|
+
import { readSubagentMessages, readSubagentMessagesOrFail, subagentHistory, subagentLaunchIds, subagentLaunchedBy, subagentLineage, } from "../subagent-history.js";
|
|
34
35
|
import { RfdSubagentReplay, ReplayTranscript, replaySubagentTerminalState, } from "../subagent-replay.js";
|
|
35
36
|
import { readHistoryAcrossCompactions, readResumedSession, readResumedTail, } from "../resumed-session.js";
|
|
36
37
|
import { SessionTiming } from "../session-timing.js";
|
|
@@ -55,6 +56,7 @@ import { addModelUsage, getMatchingModelUsage, modelUsageIncrement, normalizeMod
|
|
|
55
56
|
import { previewPatchContent } from "../diff.js";
|
|
56
57
|
import { backgroundedBashToolCall, withRunningTerminal, withStreamedTerminal, } from "../tool-calls/background.js";
|
|
57
58
|
import { ChangedMetaClient, ClientConnection } from "./client-connection.js";
|
|
59
|
+
import { V1SessionReads } from "./session-read.js";
|
|
58
60
|
import { ToolCallFieldTracker } from "../tool-calls/field-tracker.js";
|
|
59
61
|
import { RetractedToolCalls } from "../tool-calls/retracted.js";
|
|
60
62
|
import { ClientCapabilities as ToolCallClientCapabilities } from "../tool-calls/client-capabilities.js";
|
|
@@ -67,22 +69,23 @@ import { taskNotificationsOf } from "../task-notifications.js";
|
|
|
67
69
|
import { formatUsageResponse, isUsageCommandText, parseUsageResponse } from "../usage-markdown.js";
|
|
68
70
|
import { parseMcpCommand, runMcpCommand } from "../mcp-command.js";
|
|
69
71
|
import { configuredSettings, resolveThinkingConfig } from "../session-env.js";
|
|
70
|
-
import { MODE_CONFIG_ID, resolveInitialPermissionMode, SessionModeManager, } from "../session-mode.js";
|
|
72
|
+
import { MODE_CONFIG_ID, resolveInitialPermissionMode, SessionModeManager, startModeUnderPolicy, } from "../session-mode.js";
|
|
71
73
|
import { aliasResumedModelRow, applyAvailableModelsAllowlist, getAvailableModels, MODEL_CONFIG_ID, modelDisplayName, modelEntryFor, narrowToGatewayModels, resolveModelPreference, withCurrentModelInfo, } from "../session-model.js";
|
|
72
74
|
import { applyProviderRoute, createEnvForProvider, defaultProviderConfig, gatewayRequestToProviderConfig, isGatewayAuthMethod, listProvidersResponse, loggableBaseUrl, PROVIDER_ID, providerConfigFromSetRequest, providerRouteSettings, validatedGatewayAuthRequest, withListedModels, } from "../providers.js";
|
|
73
75
|
import { EFFORT_CONFIG_ID, effortFlagSettings, effortForModelSwitch, mergeEffortSettings, settleEffortAfterModelSwitch, settingsEffortForModel, withoutEffort, } from "../session-effort.js";
|
|
74
|
-
import { createUltracodeConfigOption,
|
|
76
|
+
import { createUltracodeConfigOption, readSettingsReport, ULTRACODE_CONFIG_ID, ultracodeSupported, ultracodeWorkflowsEnabled, } from "../session-ultracode.js";
|
|
77
|
+
import { followQueryPolicy } from "../query-settings.js";
|
|
75
78
|
import { buildConfigOptions, clientSupportsBooleanConfigOptions, clientSupportsRecommendedConfigValue, configOptionValue, setSelectedModel, discoverCustomAgents, } from "../session-config-options.js";
|
|
76
79
|
import { applyFastModeFlag, createFastModeConfigOption, FAST_MODE_CONFIG_ID, fastModeResultIsNews, fastModeStateChange, fastModeStateEnabled, normalizeFastModeDisabledReason, } from "../session-fast-mode.js";
|
|
77
80
|
import { cacheResultContextWindow, clearContextWindowCache, immediateContextWindow, providerCacheKeyFor, readContextWindow, } from "../context-window.js";
|
|
78
81
|
import { isLoginRequiredText, resultEnd, turnErrorData } from "../result-end.js";
|
|
79
|
-
import { STARTUP_FAILURE_RESULTS_ENV, startupFailureError } from "../startup-failure.js";
|
|
82
|
+
import { STARTUP_FAILURE_RESULTS_ENV, rejectSkippedSettings, startupFailureError, } from "../startup-failure.js";
|
|
80
83
|
import { recordStreamedDelta, unstreamedRemainder } from "../streamed-text.js";
|
|
81
84
|
import { subagentHookOptions } from "../subagent-configuration.js";
|
|
82
85
|
import { isReplayHiddenMetaMessage, isSyntheticLoginMessage, LOCAL_ONLY_COMMANDS, stripLocalCommandMetadata, } from "../message-filters.js";
|
|
83
86
|
import { computeSessionFingerprint } from "./session-fingerprint.js";
|
|
84
87
|
import { promptToClaude, SUPPORTED_PROMPT_CONTENT_TYPES } from "../prompt-to-claude.js";
|
|
85
|
-
import {
|
|
88
|
+
import { isAbortedResult } from "../result-end.js";
|
|
86
89
|
import { messageIdForGrouping, stampParentToolUseId, streamEventToAcpNotifications, toAcpNotifications, } from "../sdk-to-acp.js";
|
|
87
90
|
import { getAvailableSlashCommands } from "../slash-commands.js";
|
|
88
91
|
/** Claude CLI emits this synthetic result when an interrupted cycle ends on
|
|
@@ -409,6 +412,7 @@ export class ClaudeAcpAgent {
|
|
|
409
412
|
announcedChildren = new AnnouncedChildren();
|
|
410
413
|
/** What anchors a live cursor: the last entity that the client holds per session. */
|
|
411
414
|
lastEntities = new LastReportedEntity();
|
|
415
|
+
sessionReads;
|
|
412
416
|
/**
|
|
413
417
|
* AIR's draft: the model that the last load of each session replayed to each
|
|
414
418
|
* child session, as the model id and the entry that went out. See
|
|
@@ -457,6 +461,7 @@ export class ClaudeAcpAgent {
|
|
|
457
461
|
mcp = new McpOverAcp()) {
|
|
458
462
|
this.mcp = mcp;
|
|
459
463
|
this.sessions = {};
|
|
464
|
+
this.sessionReads = new V1SessionReads(client);
|
|
460
465
|
this.client = new ChangedMetaClient(client, () => this.toolCallCapabilities.air.client, (update) => {
|
|
461
466
|
// Before the client can name the child that a `subagent_update` announces.
|
|
462
467
|
this.announcedChildren.sending(update);
|
|
@@ -635,6 +640,7 @@ export class ClaudeAcpAgent {
|
|
|
635
640
|
// Only AIR gets the AIR capabilities and the goal capability, under
|
|
636
641
|
// `jetbrains.air`.
|
|
637
642
|
_meta: {
|
|
643
|
+
sessionRead: SESSION_READ_CAPABILITY,
|
|
638
644
|
...(this.toolCallCapabilities.air.client
|
|
639
645
|
? withAirMeta(airSessionFailureCapabilityMeta(AGENT_FILE_CHANGE_REPORT_CAPABILITY, AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY, AIR_ASYNC_TASKS_CAPABILITY, AIR_CUSTOM_INSTRUCTIONS_CAPABILITY, AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY, AIR_DIFF_PATCH_CAPABILITY, AIR_PLAN_FILE_CAPABILITY, AIR_BACKGROUND_SUBAGENTS_CAPABILITY, ...this.sessionIndex.capabilities(), ...(clientSupportsAirCapability(request.clientCapabilities, AIR_SESSION_REWIND_CAPABILITY)
|
|
640
646
|
? [AIR_SESSION_REWIND_CAPABILITY]
|
|
@@ -654,15 +660,15 @@ export class ClaudeAcpAgent {
|
|
|
654
660
|
// Without `configOptions`: a restart of the query restores the session's choices itself.
|
|
655
661
|
const { configOptions, ...request } = params;
|
|
656
662
|
const initial = initialConfigOptions(configOptions);
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
663
|
+
const resume = params._meta?.claudeCode?.options?.resume;
|
|
664
|
+
return this.sessionReads.transition(resume, "open", async () => {
|
|
665
|
+
while (this.providerUpdate)
|
|
666
|
+
await this.providerUpdate;
|
|
667
|
+
const created = await this.createSession(request, { resume });
|
|
668
|
+
const response = await this.withInitialConfigOptions(created, initial);
|
|
669
|
+
this.afterSetupResponse(response.sessionId, params.mcpServers);
|
|
670
|
+
return response;
|
|
662
671
|
});
|
|
663
|
-
const response = await this.withInitialConfigOptions(created, initial);
|
|
664
|
-
this.afterSetupResponse(response.sessionId, params.mcpServers);
|
|
665
|
-
return response;
|
|
666
672
|
}
|
|
667
673
|
/**
|
|
668
674
|
* `session/options`: the modes and config options that `session/new` with
|
|
@@ -677,7 +683,8 @@ export class ClaudeAcpAgent {
|
|
|
677
683
|
* hooks in it, as in every query.
|
|
678
684
|
*
|
|
679
685
|
* It sends no update, and it creates, loads and changes no session. A
|
|
680
|
-
* `sessionId` that is neither held nor stored fails with `-32002`.
|
|
686
|
+
* `sessionId` that is neither held nor stored fails with `-32002`. It fails
|
|
687
|
+
* as the start would when Claude Code skipped an invalid settings file.
|
|
681
688
|
*/
|
|
682
689
|
async sessionOptions(params) {
|
|
683
690
|
while (this.providerUpdate)
|
|
@@ -718,17 +725,7 @@ export class ClaudeAcpAgent {
|
|
|
718
725
|
async createSessionWhileReplaying(params, timing) {
|
|
719
726
|
await this.validateCwd(params.cwd, params.additionalDirectories);
|
|
720
727
|
clientSystemPrompt(params.systemPrompt);
|
|
721
|
-
const pending =
|
|
722
|
-
state: {
|
|
723
|
-
cwd: params.cwd,
|
|
724
|
-
taskState: new Map(),
|
|
725
|
-
subagentChecklists: new Set(),
|
|
726
|
-
forwardSubagentText: this.forwardsSubagentText(params._meta),
|
|
727
|
-
messageIdToUuid: new Map(),
|
|
728
|
-
sessionFailureState: createSessionFailureState(),
|
|
729
|
-
},
|
|
730
|
-
stopped: false,
|
|
731
|
-
};
|
|
728
|
+
const pending = this.pendingReplay(params.cwd, params._meta);
|
|
732
729
|
const transcript = readResumedSession(params.sessionId, this.logger);
|
|
733
730
|
const replay = transcript
|
|
734
731
|
.then(({ messages }) => this.replaySessionHistory(params.sessionId, messages, pending))
|
|
@@ -789,16 +786,18 @@ export class ClaudeAcpAgent {
|
|
|
789
786
|
// The fork row can lack `forkedFrom`: the scan reads it from the first
|
|
790
787
|
// 64 KB of the transcript only. So the fork is held back by its id too.
|
|
791
788
|
this.sessionIndex.onForkCreated(params.sessionId, sessionId);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
789
|
+
return this.sessionReads.transition(sessionId, "open", async () => {
|
|
790
|
+
const { modes, configOptions } = await this.withInitialConfigOptions(await this.getOrCreateSession({
|
|
791
|
+
sessionId,
|
|
792
|
+
cwd: params.cwd,
|
|
793
|
+
mcpServers: params.mcpServers,
|
|
794
|
+
additionalDirectories: params.additionalDirectories,
|
|
795
|
+
systemPrompt: params.systemPrompt,
|
|
796
|
+
_meta: params._meta,
|
|
797
|
+
}), initial);
|
|
798
|
+
this.afterSetupResponse(sessionId, params.mcpServers ?? []);
|
|
799
|
+
return { sessionId, modes, configOptions };
|
|
800
|
+
});
|
|
802
801
|
}
|
|
803
802
|
/** Runs `fork`, the handler of a `session/fork` request of `sourceId`,
|
|
804
803
|
* with its forks held back from the session list (see
|
|
@@ -884,14 +883,19 @@ export class ClaudeAcpAgent {
|
|
|
884
883
|
});
|
|
885
884
|
}
|
|
886
885
|
async resumeSession(params) {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
886
|
+
return this.sessionReads.transition(params.sessionId, "open", async () => {
|
|
887
|
+
const initial = initialConfigOptions(params.configOptions);
|
|
888
|
+
while (this.providerUpdate)
|
|
889
|
+
await this.providerUpdate;
|
|
890
|
+
const result = await this.withInitialConfigOptions(await this.getOrCreateSession(params), initial);
|
|
891
|
+
this.afterSetupResponse(params.sessionId, params.mcpServers ?? []);
|
|
892
|
+
return result;
|
|
893
|
+
});
|
|
893
894
|
}
|
|
894
|
-
|
|
895
|
+
loadSession(params) {
|
|
896
|
+
return this.sessionReads.transition(params.sessionId, "open", () => this.loadAndReplay(params));
|
|
897
|
+
}
|
|
898
|
+
async loadAndReplay(params) {
|
|
895
899
|
const timing = new SessionTiming(this.logger, "load", params.sessionId);
|
|
896
900
|
const initial = initialConfigOptions(params.configOptions);
|
|
897
901
|
while (this.providerUpdate)
|
|
@@ -912,6 +916,17 @@ export class ClaudeAcpAgent {
|
|
|
912
916
|
this.afterSetupResponse(params.sessionId, params.mcpServers ?? []);
|
|
913
917
|
return result;
|
|
914
918
|
}
|
|
919
|
+
readSession(params, signal) {
|
|
920
|
+
return this.sessionReads.read(params, {
|
|
921
|
+
capabilities: this.clientCapabilities,
|
|
922
|
+
airClient: this.toolCallCapabilities.air.client,
|
|
923
|
+
signal,
|
|
924
|
+
isOpen: (sessionId) => Object.hasOwn(this.sessions, sessionId),
|
|
925
|
+
assertRoot: (sessionId) => this.assertNoChildSession(sessionId, "read"),
|
|
926
|
+
clientTitle: (title) => this.sessionIndex.clientTitle(title),
|
|
927
|
+
render: (sessionId, cwd, replay) => this.replaySessionHistory(sessionId, undefined, this.pendingReplay(cwd), replay),
|
|
928
|
+
});
|
|
929
|
+
}
|
|
915
930
|
/**
|
|
916
931
|
* One page of the sessions, newest first. The cursor is the offset of the
|
|
917
932
|
* page. The SDK then orders the transcripts by their modification time and
|
|
@@ -1136,16 +1151,17 @@ export class ClaudeAcpAgent {
|
|
|
1136
1151
|
reconnected = outcome.reconnected;
|
|
1137
1152
|
return outcome.markdown;
|
|
1138
1153
|
},
|
|
1139
|
-
// A reconnect starts OAuth for
|
|
1140
|
-
//
|
|
1154
|
+
// A reconnect starts OAuth for each server that it tried and that needs
|
|
1155
|
+
// it, also for one from Claude Code's settings or the project's
|
|
1156
|
+
// `.mcp.json`: the client has no terminal to sign in from. A plain
|
|
1157
|
+
// `/mcp` and a cancelled turn start none.
|
|
1141
1158
|
afterDelivery: () => {
|
|
1142
1159
|
const session = this.sessions[params.sessionId];
|
|
1143
1160
|
if (!session || session.cancelled)
|
|
1144
1161
|
return;
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
startMcpServerAuthentication(this, params.sessionId, servers);
|
|
1162
|
+
if (reconnected.length > 0) {
|
|
1163
|
+
startMcpServerAuthentication(this, params.sessionId, new Set(reconnected));
|
|
1164
|
+
}
|
|
1149
1165
|
},
|
|
1150
1166
|
};
|
|
1151
1167
|
}
|
|
@@ -1909,13 +1925,16 @@ export class ClaudeAcpAgent {
|
|
|
1909
1925
|
try {
|
|
1910
1926
|
if (asyncTasks.isAutonomousTurn(params.asyncTaskId)) {
|
|
1911
1927
|
// The task stands for a turn that Claude Code started on its own, so
|
|
1912
|
-
// stopping it interrupts that turn. A prompt that
|
|
1913
|
-
//
|
|
1914
|
-
|
|
1928
|
+
// stopping it interrupts that turn. A waiting prompt that is still in
|
|
1929
|
+
// Claude Code's queue survives the interrupt and runs next. One that
|
|
1930
|
+
// Claude Code already dispatched into a turn, or any prompt on a CLI
|
|
1931
|
+
// that sends no lifecycle frames, may be part of the interrupted turn.
|
|
1932
|
+
const waiting = waitingPrompts(session.turnQueue);
|
|
1933
|
+
if (!interruptKeepsWaitingPrompts(session, waiting)) {
|
|
1915
1934
|
asyncTasks.releaseStop(params.asyncTaskId);
|
|
1916
1935
|
return { stopped: false };
|
|
1917
1936
|
}
|
|
1918
|
-
await session.query.
|
|
1937
|
+
await interruptAutonomousTurn(session.query, asyncTasks, waiting, this.logger);
|
|
1919
1938
|
}
|
|
1920
1939
|
else {
|
|
1921
1940
|
await session.query.stopTask(params.asyncTaskId);
|
|
@@ -3390,6 +3409,10 @@ export class ClaudeAcpAgent {
|
|
|
3390
3409
|
case "system":
|
|
3391
3410
|
switch (message.subtype) {
|
|
3392
3411
|
case "init":
|
|
3412
|
+
// The mode at the start of the turn (see `modeReported`).
|
|
3413
|
+
if (message.permissionMode) {
|
|
3414
|
+
await this.sessionModes.modeReported(params.sessionId, session, message.permissionMode);
|
|
3415
|
+
}
|
|
3393
3416
|
// Latch the lifecycle capability so cancel() routes orphan
|
|
3394
3417
|
// accounting through `orphanCommands` (per-uuid, exact)
|
|
3395
3418
|
// instead of the coalescing-blind count. Never unlatch: init
|
|
@@ -3449,6 +3472,10 @@ export class ClaudeAcpAgent {
|
|
|
3449
3472
|
await this.reportMcpServerStartupFailures(session, message.mcp_servers, supportsNotices, sendUpdate, params.sessionId);
|
|
3450
3473
|
break;
|
|
3451
3474
|
case "status": {
|
|
3475
|
+
// The mode after a change (see `modeReported`).
|
|
3476
|
+
if (message.permissionMode) {
|
|
3477
|
+
await this.sessionModes.modeReported(params.sessionId, session, message.permissionMode);
|
|
3478
|
+
}
|
|
3452
3479
|
// A model request that serves none of the prompts a cancel
|
|
3453
3480
|
// stopped is new work, such as Claude Code's follow-up after a
|
|
3454
3481
|
// background command finished. It comes after the stopped
|
|
@@ -4191,8 +4218,11 @@ export class ClaudeAcpAgent {
|
|
|
4191
4218
|
// slash-command output forwarding), though their cost is real.
|
|
4192
4219
|
// The exception: the user's prompt was added to that turn while it
|
|
4193
4220
|
// ran, so its result answers the prompt (see answersPendingPrompt).
|
|
4194
|
-
|
|
4195
|
-
|
|
4221
|
+
// A stop that interrupted an autonomous turn owes that turn's
|
|
4222
|
+
// aborted result, which has no origin after a scheduler fire.
|
|
4223
|
+
const answersPrompt = answersPendingPrompt(message);
|
|
4224
|
+
const startedByClaudeCode = asyncTasks.startedByClaudeCode(message, answersPrompt);
|
|
4225
|
+
const isAutonomousResult = startedByClaudeCode && !answersPrompt;
|
|
4196
4226
|
// A result with no turn to claim it also ends the cycle that
|
|
4197
4227
|
// Claude Code started on its own, whatever its origin says. A
|
|
4198
4228
|
// scheduler fire (a ScheduleWakeup or cron prompt) is one: its
|
|
@@ -5290,8 +5320,9 @@ export class ClaudeAcpAgent {
|
|
|
5290
5320
|
else if (message.parent_tool_use_id !== null &&
|
|
5291
5321
|
Array.isArray(message.message.content)) {
|
|
5292
5322
|
// A foreground fork inherits a placeholder result for its own
|
|
5293
|
-
// launch
|
|
5294
|
-
//
|
|
5323
|
+
// launch, and Claude Code before 2.1.332 streams it ("Fork
|
|
5324
|
+
// started — that fork is you."). Only the launching side can
|
|
5325
|
+
// complete that Agent call with the fork's actual report.
|
|
5295
5326
|
const launchId = message.parent_tool_use_id;
|
|
5296
5327
|
content = message.message.content.filter((block) => block.type !== "tool_result" || block.tool_use_id !== launchId);
|
|
5297
5328
|
// The message-level sidecar cannot describe a remaining result
|
|
@@ -6127,6 +6158,7 @@ export class ClaudeAcpAgent {
|
|
|
6127
6158
|
}
|
|
6128
6159
|
/** Tear down all active sessions. Called when the ACP connection closes. */
|
|
6129
6160
|
async dispose() {
|
|
6161
|
+
this.sessionReads.dispose();
|
|
6130
6162
|
this.sessionIndex.dispose();
|
|
6131
6163
|
await Promise.all(Object.keys(this.sessions).map((id) => this.teardownSession(id)));
|
|
6132
6164
|
}
|
|
@@ -6145,8 +6177,10 @@ export class ClaudeAcpAgent {
|
|
|
6145
6177
|
}
|
|
6146
6178
|
/** Idempotent: a session that is not loaded here is already closed. */
|
|
6147
6179
|
async closeSession(params) {
|
|
6148
|
-
|
|
6149
|
-
|
|
6180
|
+
return this.sessionReads.transition(params.sessionId, "close", async () => {
|
|
6181
|
+
await this.endSession(params.sessionId);
|
|
6182
|
+
return {};
|
|
6183
|
+
});
|
|
6150
6184
|
}
|
|
6151
6185
|
/**
|
|
6152
6186
|
* `session/status`: `open` for a session that this connection holds. A held
|
|
@@ -6168,7 +6202,7 @@ export class ClaudeAcpAgent {
|
|
|
6168
6202
|
}
|
|
6169
6203
|
/** Per client: see {@link sessionIndex.SessionIndexConnection.deleteSession}. */
|
|
6170
6204
|
async deleteSession(params) {
|
|
6171
|
-
return this.sessionIndex.deleteSession(params);
|
|
6205
|
+
return this.sessionReads.transition(params.sessionId, "close", () => this.sessionIndex.deleteSession(params));
|
|
6172
6206
|
}
|
|
6173
6207
|
setSessionMode(params) {
|
|
6174
6208
|
return this.serializeConfigurationChange(params.sessionId, () => this.sessionModes.setSessionMode(params));
|
|
@@ -6225,15 +6259,34 @@ export class ClaudeAcpAgent {
|
|
|
6225
6259
|
await this.applyConfigOptionValue(params.sessionId, session, params.configId, effectiveValue, duringSetup);
|
|
6226
6260
|
return { configOptions: session.configOptions };
|
|
6227
6261
|
}
|
|
6228
|
-
|
|
6262
|
+
pendingReplay(cwd, meta) {
|
|
6263
|
+
return {
|
|
6264
|
+
state: {
|
|
6265
|
+
cwd,
|
|
6266
|
+
taskState: new Map(),
|
|
6267
|
+
subagentChecklists: new Set(),
|
|
6268
|
+
forwardSubagentText: this.forwardsSubagentText(meta),
|
|
6269
|
+
messageIdToUuid: new Map(),
|
|
6270
|
+
sessionFailureState: createSessionFailureState(),
|
|
6271
|
+
},
|
|
6272
|
+
stopped: false,
|
|
6273
|
+
};
|
|
6274
|
+
}
|
|
6275
|
+
async replaySessionHistory(sessionId, resumedMessages, pending, detached) {
|
|
6229
6276
|
const replayStartedAt = performance.now();
|
|
6230
6277
|
const toolUseCache = {};
|
|
6278
|
+
const publish = detached?.publish ??
|
|
6279
|
+
((notification) => this.client.sessionUpdate(notification));
|
|
6231
6280
|
// A replay rebuilds the client's entities, and its cursors anchor to those.
|
|
6232
|
-
|
|
6281
|
+
if (!detached)
|
|
6282
|
+
this.lastEntities.forget(sessionId);
|
|
6233
6283
|
// A load replays the messages before each compaction too, unless reading them fails.
|
|
6234
6284
|
// The rewind cut comes first: the dropped turns get no replay and no cursor.
|
|
6235
|
-
const current =
|
|
6236
|
-
|
|
6285
|
+
const current = detached?.messages ??
|
|
6286
|
+
(await cutAtRewindPoint(sessionId, resumedMessages ?? (await getSessionMessages(sessionId)), this.logger));
|
|
6287
|
+
const messages = detached
|
|
6288
|
+
? current
|
|
6289
|
+
: await readHistoryAcrossCompactions(sessionId, current, this.logger);
|
|
6237
6290
|
// A cursor whose resume point a compaction left out cannot be rewound to.
|
|
6238
6291
|
const currentUuids = new Set(current.map((message) => message.uuid));
|
|
6239
6292
|
const historyLoadedAt = performance.now();
|
|
@@ -6259,12 +6312,14 @@ export class ClaudeAcpAgent {
|
|
|
6259
6312
|
state: session.sessionFailureState,
|
|
6260
6313
|
capabilities: this.clientCapabilities,
|
|
6261
6314
|
isCurrent: () => {
|
|
6315
|
+
if (detached)
|
|
6316
|
+
return !detached.signal.aborted;
|
|
6262
6317
|
const live = this.sessions[sessionId];
|
|
6263
6318
|
if (!live)
|
|
6264
6319
|
return pending !== undefined && !pending.stopped;
|
|
6265
6320
|
return live.sessionFailureState === session.sessionFailureState;
|
|
6266
6321
|
},
|
|
6267
|
-
sendUpdate:
|
|
6322
|
+
sendUpdate: publish,
|
|
6268
6323
|
logger: this.logger,
|
|
6269
6324
|
})
|
|
6270
6325
|
: undefined;
|
|
@@ -6282,6 +6337,12 @@ export class ClaudeAcpAgent {
|
|
|
6282
6337
|
// no model to the list, and each child's model is its id until the load
|
|
6283
6338
|
// response refines it (see `publishCurrentSubagentStates`).
|
|
6284
6339
|
const replayModels = pending ? undefined : this.subagentModels(sessionId);
|
|
6340
|
+
const readSubagentHistory = () => detached
|
|
6341
|
+
? subagentHistory(sessionId, { strict: true, transcript: detached.transcript })
|
|
6342
|
+
: subagentHistory(sessionId);
|
|
6343
|
+
const readChildMessages = (agentId, history, launchId) => detached
|
|
6344
|
+
? readSubagentMessagesOrFail(sessionId, agentId, history, launchId)
|
|
6345
|
+
: readSubagentMessages(sessionId, agentId, history, this.logger);
|
|
6285
6346
|
// Registers the Agent and Task launches of `list`, and the terminal state
|
|
6286
6347
|
// of each launch from its tool_result.
|
|
6287
6348
|
const registerLaunches = (list) => {
|
|
@@ -6364,7 +6425,7 @@ export class ClaudeAcpAgent {
|
|
|
6364
6425
|
const parentSessionId = child.parentToolUseId
|
|
6365
6426
|
? (replayChildren.get(child.parentToolUseId)?.sessionId ?? sessionId)
|
|
6366
6427
|
: sessionId;
|
|
6367
|
-
await
|
|
6428
|
+
await publish(asSdkSessionNotification({
|
|
6368
6429
|
sessionId: parentSessionId,
|
|
6369
6430
|
update: {
|
|
6370
6431
|
sessionUpdate: "subagent_spawned",
|
|
@@ -6380,7 +6441,7 @@ export class ClaudeAcpAgent {
|
|
|
6380
6441
|
};
|
|
6381
6442
|
// Only a history with an Agent or Task launch has subagent transcripts to read.
|
|
6382
6443
|
const subagents = nativeReplayEnabled && replayChildren.size > 0
|
|
6383
|
-
? await
|
|
6444
|
+
? await readSubagentHistory()
|
|
6384
6445
|
: { agents: new Map() };
|
|
6385
6446
|
const airReplay = nativeReplayEnabled ? new ReplayTranscript(subagents) : undefined;
|
|
6386
6447
|
airReplay?.scan(messages, sessionId);
|
|
@@ -6388,10 +6449,10 @@ export class ClaudeAcpAgent {
|
|
|
6388
6449
|
const rfdHistory = form === "rfd" &&
|
|
6389
6450
|
messages.some((message) => subagentLaunchIds(message.message?.content)
|
|
6390
6451
|
.length > 0)
|
|
6391
|
-
? await
|
|
6452
|
+
? await readSubagentHistory()
|
|
6392
6453
|
: { agents: new Map() };
|
|
6393
6454
|
const rfdReplay = form === "rfd"
|
|
6394
|
-
? new RfdSubagentReplay(rfdHistory,
|
|
6455
|
+
? new RfdSubagentReplay(rfdHistory, publish, detached ? undefined : this.subagentModels(sessionId), session?.cwd)
|
|
6395
6456
|
: undefined;
|
|
6396
6457
|
rfdReplay?.scan(messages, sessionId);
|
|
6397
6458
|
// History persists no task_started frame, so a background task gets its
|
|
@@ -6401,7 +6462,7 @@ export class ClaudeAcpAgent {
|
|
|
6401
6462
|
// The tool cache forgets a tool use at its result, but a notification
|
|
6402
6463
|
// comes later and needs the tool use that started the task.
|
|
6403
6464
|
const replayToolUses = new Map();
|
|
6404
|
-
const replayAsyncTasks = new AsyncTaskRuntime(clientSupportsAsyncTasks(this.clientCapabilities), sessionId,
|
|
6465
|
+
const replayAsyncTasks = new AsyncTaskRuntime(clientSupportsAsyncTasks(this.clientCapabilities), sessionId, publish, {
|
|
6405
6466
|
routeOf: (toolCallId) => {
|
|
6406
6467
|
const target = replayToolUses.get(toolCallId)?.sessionId;
|
|
6407
6468
|
return target && target !== sessionId
|
|
@@ -6447,6 +6508,7 @@ export class ClaudeAcpAgent {
|
|
|
6447
6508
|
const pause = messageLoopYielder.maybeYield();
|
|
6448
6509
|
if (pause)
|
|
6449
6510
|
await pause;
|
|
6511
|
+
detached?.signal.throwIfAborted();
|
|
6450
6512
|
if (pending?.stopped || isReplayHiddenMetaMessage(message)) {
|
|
6451
6513
|
return;
|
|
6452
6514
|
}
|
|
@@ -6512,7 +6574,7 @@ export class ClaudeAcpAgent {
|
|
|
6512
6574
|
if (replayChild?.announced && entry && !sameModelEntry(replayChild.model, entry)) {
|
|
6513
6575
|
replayChild.responseModel = model;
|
|
6514
6576
|
replayChild.model = entry;
|
|
6515
|
-
await
|
|
6577
|
+
await publish({
|
|
6516
6578
|
sessionId: replayChild.sessionId,
|
|
6517
6579
|
update: {
|
|
6518
6580
|
sessionUpdate: "config_option_update",
|
|
@@ -6563,7 +6625,10 @@ export class ClaudeAcpAgent {
|
|
|
6563
6625
|
// A subagent's own compaction summary is not the root session's.
|
|
6564
6626
|
if (replayCompactionUpdates &&
|
|
6565
6627
|
parentToolUseId === null &&
|
|
6566
|
-
(await replayCompactSummary(message,
|
|
6628
|
+
(await replayCompactSummary(message, publish, {
|
|
6629
|
+
sessionId,
|
|
6630
|
+
airClient: this.toolCallCapabilities.air.client,
|
|
6631
|
+
}))) {
|
|
6567
6632
|
return;
|
|
6568
6633
|
}
|
|
6569
6634
|
for (const notification of toAcpNotifications(
|
|
@@ -6595,7 +6660,7 @@ export class ClaudeAcpAgent {
|
|
|
6595
6660
|
: undefined;
|
|
6596
6661
|
if (handback !== undefined) {
|
|
6597
6662
|
if (handback !== null) {
|
|
6598
|
-
await
|
|
6663
|
+
await publish({
|
|
6599
6664
|
sessionId: replayTargetSessionId,
|
|
6600
6665
|
update: {
|
|
6601
6666
|
sessionUpdate: "agent_message_chunk",
|
|
@@ -6607,7 +6672,7 @@ export class ClaudeAcpAgent {
|
|
|
6607
6672
|
continue;
|
|
6608
6673
|
}
|
|
6609
6674
|
const replayed = { ...notification, sessionId: replayTargetSessionId };
|
|
6610
|
-
await
|
|
6675
|
+
await publish(rfdReplay
|
|
6611
6676
|
? asSdkSessionNotification(rfdReplay.withTarget(replayed, replayTargetSessionId))
|
|
6612
6677
|
: replayed);
|
|
6613
6678
|
}
|
|
@@ -6621,7 +6686,7 @@ export class ClaudeAcpAgent {
|
|
|
6621
6686
|
if (!agentId || replayedSubagents.has(agentId))
|
|
6622
6687
|
continue;
|
|
6623
6688
|
replayedSubagents.add(agentId);
|
|
6624
|
-
const childMessages = await
|
|
6689
|
+
const childMessages = await readChildMessages(agentId, subagents, toolUseId);
|
|
6625
6690
|
registerLaunches(childMessages);
|
|
6626
6691
|
airReplay?.scan(childMessages, agentId);
|
|
6627
6692
|
for (const childMessage of childMessages)
|
|
@@ -6635,7 +6700,7 @@ export class ClaudeAcpAgent {
|
|
|
6635
6700
|
const launched = rfdReplay.childOfLaunch(toolUseId);
|
|
6636
6701
|
if (!launched || launched.announced)
|
|
6637
6702
|
continue;
|
|
6638
|
-
const childMessages = await
|
|
6703
|
+
const childMessages = await readChildMessages(launched.sessionId, rfdHistory, toolUseId);
|
|
6639
6704
|
await rfdReplay.announce(launched);
|
|
6640
6705
|
rfdReplay.scan(childMessages, launched.sessionId);
|
|
6641
6706
|
for (const childMessage of childMessages)
|
|
@@ -6646,20 +6711,30 @@ export class ClaudeAcpAgent {
|
|
|
6646
6711
|
};
|
|
6647
6712
|
for (const [index, message] of messages.entries()) {
|
|
6648
6713
|
// Before the message's own chunk: the cursor lies before the message.
|
|
6649
|
-
const before = this.lastEntities.last(sessionId);
|
|
6714
|
+
const before = detached ? undefined : this.lastEntities.last(sessionId);
|
|
6650
6715
|
await replayMessage(message);
|
|
6651
6716
|
// A task notification record is no user message to the client (see `replayMessage`).
|
|
6652
6717
|
if (!pending?.stopped &&
|
|
6653
6718
|
hasForkCursor(messages, index) &&
|
|
6654
6719
|
!isTaskNotificationRecord(message)) {
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6720
|
+
const update = forkCursorUpdate(message.uuid);
|
|
6721
|
+
if (detached) {
|
|
6722
|
+
if (this.clientCapabilities?.session?.cursors != null) {
|
|
6723
|
+
await publish({ sessionId, update });
|
|
6724
|
+
}
|
|
6725
|
+
}
|
|
6726
|
+
else {
|
|
6727
|
+
this.announceCursor(sessionId, update, before, {
|
|
6728
|
+
rewindable: currentUuids.has(messages[index - 1].uuid),
|
|
6729
|
+
});
|
|
6730
|
+
}
|
|
6658
6731
|
}
|
|
6659
6732
|
}
|
|
6733
|
+
detached?.endHistory();
|
|
6660
6734
|
if (rfdReplay && !pending?.stopped) {
|
|
6661
6735
|
await rfdReplay.finish(clientSupportsNotices(this.clientCapabilities), sessionId);
|
|
6662
|
-
|
|
6736
|
+
if (!detached)
|
|
6737
|
+
this.replayedSubagents.set(sessionId, rfdReplay);
|
|
6663
6738
|
}
|
|
6664
6739
|
if (nativeReplayEnabled && !pending?.stopped) {
|
|
6665
6740
|
const childModels = new Map();
|
|
@@ -6668,7 +6743,7 @@ export class ClaudeAcpAgent {
|
|
|
6668
6743
|
childModels.set(child.sessionId, { model: child.responseModel, sent: child.model });
|
|
6669
6744
|
}
|
|
6670
6745
|
}
|
|
6671
|
-
if (childModels.size > 0)
|
|
6746
|
+
if (!detached && childModels.size > 0)
|
|
6672
6747
|
this.replayedChildModels.set(sessionId, childModels);
|
|
6673
6748
|
// Claude history persists sidechain messages and Agent/Task tool uses,
|
|
6674
6749
|
// but not task_started/task_updated lifecycle frames. Recover terminal
|
|
@@ -6680,7 +6755,7 @@ export class ClaudeAcpAgent {
|
|
|
6680
6755
|
const parentSessionId = child.parentToolUseId
|
|
6681
6756
|
? (replayChildren.get(child.parentToolUseId)?.sessionId ?? sessionId)
|
|
6682
6757
|
: sessionId;
|
|
6683
|
-
await
|
|
6758
|
+
await publish(asSdkSessionNotification({
|
|
6684
6759
|
sessionId: parentSessionId,
|
|
6685
6760
|
update: {
|
|
6686
6761
|
sessionUpdate: "subagent_state_update",
|
|
@@ -6697,9 +6772,10 @@ export class ClaudeAcpAgent {
|
|
|
6697
6772
|
// A client with `loadReplayEnd` gets one more update after the whole
|
|
6698
6773
|
// replay, the subagent history included. A stopped replay (the CLI start
|
|
6699
6774
|
// failed) does not get it, and a failed replay throws before this line.
|
|
6700
|
-
if (!
|
|
6775
|
+
if (!detached &&
|
|
6776
|
+
!pending?.stopped &&
|
|
6701
6777
|
clientSupportsAirCapability(this.clientCapabilities, AIR_LOAD_REPLAY_END_CAPABILITY)) {
|
|
6702
|
-
await
|
|
6778
|
+
await publish({
|
|
6703
6779
|
sessionId,
|
|
6704
6780
|
// No `title` and no `updatedAt`: `null` would clear them.
|
|
6705
6781
|
update: {
|
|
@@ -7965,10 +8041,11 @@ export class ClaudeAcpAgent {
|
|
|
7965
8041
|
settingsManager.getSettings().permissions?.disableBypassPermissionsMode !== "disable" &&
|
|
7966
8042
|
sessionMeta?.claudeCode?.options?.allowDangerouslySkipPermissions !== false;
|
|
7967
8043
|
const allowAuto = !autoModeDisabled(settingsManager.getSettings());
|
|
8044
|
+
const spawnSettings = settingsManager.getSettings();
|
|
7968
8045
|
const { mode: initialPermissionMode, builtInDefault: builtInPermissionMode } = resolveInitialPermissionMode({
|
|
7969
8046
|
explicit: creationOpts.permissionMode,
|
|
7970
8047
|
resumed: resumedPermissionMode,
|
|
7971
|
-
defaultMode:
|
|
8048
|
+
defaultMode: spawnSettings.permissions?.defaultMode,
|
|
7972
8049
|
}, this.logger, { allowBypass, allowAuto });
|
|
7973
8050
|
const userProvidedOptions = sessionMeta?.claudeCode?.options;
|
|
7974
8051
|
const forwardSubagentText = this.forwardsSubagentText(params._meta);
|
|
@@ -8187,9 +8264,12 @@ export class ClaudeAcpAgent {
|
|
|
8187
8264
|
hooks: [
|
|
8188
8265
|
...(subagentConfigHook ? [subagentConfigHook] : []),
|
|
8189
8266
|
createPostToolUseHook({
|
|
8267
|
+
// Claude Code reports the mode in a `status` frame too: the
|
|
8268
|
+
// first of the two is recorded.
|
|
8190
8269
|
onEnterPlanMode: async () => {
|
|
8191
|
-
|
|
8192
|
-
|
|
8270
|
+
const entered = this.sessions[sessionId];
|
|
8271
|
+
if (entered)
|
|
8272
|
+
await this.sessionModes.modeReported(sessionId, entered, "plan");
|
|
8193
8273
|
},
|
|
8194
8274
|
}),
|
|
8195
8275
|
],
|
|
@@ -8348,6 +8428,18 @@ export class ClaudeAcpAgent {
|
|
|
8348
8428
|
if (route)
|
|
8349
8429
|
await applyProviderRoute(q, route);
|
|
8350
8430
|
timing.phase("sdk-initialize");
|
|
8431
|
+
// From here on the settings include the policy the CLI applies, which
|
|
8432
|
+
// the host resolver can miss (see `followCliPolicy`). The SDK's bypass
|
|
8433
|
+
// flag stays as it was decided before the CLI started. The mode is
|
|
8434
|
+
// decided again: `sessionModes.initialize` sets it on the query below.
|
|
8435
|
+
const cliSettings = await followQueryPolicy(q, settingsManager, this.logger);
|
|
8436
|
+
const startMode = startModeUnderPolicy({
|
|
8437
|
+
allowBypass,
|
|
8438
|
+
allowAuto,
|
|
8439
|
+
mode: initialPermissionMode,
|
|
8440
|
+
builtInDefault: builtInPermissionMode,
|
|
8441
|
+
}, { explicit: creationOpts.permissionMode, resumed: resumedPermissionMode }, { atStart: spawnSettings, withPolicy: settingsManager.getSettings() }, this.logger);
|
|
8442
|
+
timing.phase("cli-settings");
|
|
8351
8443
|
// Publish the identity BEFORE the guard can refuse this session. A
|
|
8352
8444
|
// refusal is exactly when the client most needs to know which account it
|
|
8353
8445
|
// was refused for.
|
|
@@ -8395,7 +8487,7 @@ export class ClaudeAcpAgent {
|
|
|
8395
8487
|
const allowedModels = resolvedProvider?.listedModels
|
|
8396
8488
|
? narrowToGatewayModels(settingsAllowedModels, resolvedProvider.listedModels, resolvedProvider.bedrockRegionPrefix)
|
|
8397
8489
|
: settingsAllowedModels;
|
|
8398
|
-
const models = await getAvailableModels(q, allowedModels, initializationResult.models, settingsManager, this.logger, creationOpts.resume !== undefined, sessionId, resumedModel, resolvedProvider?.listedModels !== undefined);
|
|
8490
|
+
const models = await getAvailableModels(q, allowedModels, initializationResult.models, settingsManager, this.logger, creationOpts.resume !== undefined, sessionId, resumedModel, resolvedProvider?.listedModels !== undefined, cliSettings);
|
|
8399
8491
|
timing.phase("models");
|
|
8400
8492
|
// Resolve the current model's capabilities separately from the stable
|
|
8401
8493
|
// permission-mode catalog advertised to ACP clients (see
|
|
@@ -8403,12 +8495,13 @@ export class ClaudeAcpAgent {
|
|
|
8403
8495
|
const { allowlistedModelInfo, currentModelInfo, modelInfos } = withCurrentModelInfo(allowedModels, sdkModels, models.currentModelId);
|
|
8404
8496
|
const { modes, autoModeFallbackWarningPending } = await this.sessionModes.initialize({
|
|
8405
8497
|
query: q,
|
|
8406
|
-
requestedMode:
|
|
8407
|
-
builtInDefault:
|
|
8498
|
+
requestedMode: startMode.mode,
|
|
8499
|
+
builtInDefault: startMode.builtInDefault,
|
|
8500
|
+
startedIn: initialPermissionMode,
|
|
8408
8501
|
currentModelInfo,
|
|
8409
8502
|
currentModelId: models.currentModelId,
|
|
8410
|
-
allowBypass,
|
|
8411
|
-
allowAuto,
|
|
8503
|
+
allowBypass: startMode.allowBypass,
|
|
8504
|
+
allowAuto: startMode.allowAuto,
|
|
8412
8505
|
});
|
|
8413
8506
|
timing.phase("modes");
|
|
8414
8507
|
const agents = await discoverCustomAgents(q);
|
|
@@ -8451,7 +8544,7 @@ export class ClaudeAcpAgent {
|
|
|
8451
8544
|
// The CLI reports whether ultracode can run (workflows enabled and a
|
|
8452
8545
|
// supporting model) and whether the session already requests it (an
|
|
8453
8546
|
// `ultracode: true` setting). Without a report, fall back to settings.
|
|
8454
|
-
const ultracodeReport = await
|
|
8547
|
+
const { ultracode: ultracodeReport, settingsErrors } = await readSettingsReport(q);
|
|
8455
8548
|
timing.phase("ultracode");
|
|
8456
8549
|
const ultracodeEnabled = ultracodeReport?.requested ?? effortSettings.ultracode === true;
|
|
8457
8550
|
const workflowsEnabled = ultracodeWorkflowsEnabled(ultracodeReport, currentModelInfo);
|
|
@@ -8464,6 +8557,7 @@ export class ClaudeAcpAgent {
|
|
|
8464
8557
|
useRecommendedValue,
|
|
8465
8558
|
airClient: this.toolCallCapabilities.air.client,
|
|
8466
8559
|
}, ultracode);
|
|
8560
|
+
rejectSkippedSettings(settingsErrors);
|
|
8467
8561
|
if (creationOpts.optionsOnly) {
|
|
8468
8562
|
this.discardUnregisteredQuery(q, input, settingsManager);
|
|
8469
8563
|
return { sessionId, modes, configOptions };
|
|
@@ -9105,6 +9199,7 @@ export function v1AgentApp(logger, onAgent) {
|
|
|
9105
9199
|
.onRequest(methods.agent.initialize, (ctx) => agent.initialize(ctx.params))
|
|
9106
9200
|
.onRequest(methods.agent.session.new, (ctx) => agent.newSession(ctx.params))
|
|
9107
9201
|
.onRequest(methods.agent.session.load, ofRootSession("load", (ctx) => agent.loadSession(ctx.params)))
|
|
9202
|
+
.onRequest(SESSION_READ_METHOD, { parse: (params) => params }, (ctx) => agent.readSession(ctx.params, ctx.signal))
|
|
9108
9203
|
.onRequest(methods.agent.session.fork, ofRootSession("fork", (ctx) => agent.forking(ctx.params.sessionId, () => agent.unstable_forkSession(ctx.params))))
|
|
9109
9204
|
.onRequest(methods.agent.session.list, (ctx) => agent.listSessions(ctx.params))
|
|
9110
9205
|
.onRequest(methods.agent.session.delete, ofRootSession("delete", (ctx) => agent.deleteSession(ctx.params)))
|