@agentclientprotocol/claude-agent-acp 0.113.1-preview.8 → 0.114.0
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/claude-cli.d.ts +22 -16
- package/dist/claude-cli.d.ts.map +1 -1
- package/dist/claude-cli.js +40 -18
- 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/transcript-scan.d.ts +13 -3
- package/dist/session-index/transcript-scan.d.ts.map +1 -1
- package/dist/session-index/transcript-scan.js +21 -5
- 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 +4 -1
- package/dist/session-ultracode.d.ts.map +1 -1
- package/dist/session-ultracode.js +14 -25
- 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 +3 -1
- package/dist/startup-failure.d.ts.map +1 -1
- package/dist/startup-failure.js +7 -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 +6 -0
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +162 -76
- 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 +62 -27
- package/dist/v2/config.d.ts +9 -8
- package/dist/v2/config.d.ts.map +1 -1
- package/dist/v2/config.js +11 -8
- 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 +6 -0
- 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 +4 -4
package/dist/session-mode.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SessionConfigOption, type SessionModeState, type SessionNotification, type SetSessionModeRequest, type SetSessionModeResponse } from "@agentclientprotocol/sdk/unstable";
|
|
2
|
-
import type { ModelInfo, PermissionMode, PermissionResult, Query } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import type { ModelInfo, PermissionMode, PermissionResult, Query, Settings } from "@anthropic-ai/claude-agent-sdk";
|
|
3
3
|
export declare const MODE_CONFIG_ID = "mode";
|
|
4
4
|
export declare const AUTO_MODE_FALLBACK: PermissionMode;
|
|
5
5
|
export type SessionMode = {
|
|
@@ -45,9 +45,19 @@ type InitializeSessionModeParams = ModeAvailability & {
|
|
|
45
45
|
requestedMode: PermissionMode;
|
|
46
46
|
/** The mode is the built-in default: no request, transcript or setting chose it. */
|
|
47
47
|
builtInDefault?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* The mode the query was started in, when `requestedMode` was decided after
|
|
50
|
+
* that (see {@link startModeUnderPolicy}). Without it, `requestedMode`.
|
|
51
|
+
*/
|
|
52
|
+
startedIn?: PermissionMode;
|
|
48
53
|
currentModelInfo?: ModelInfo;
|
|
49
54
|
currentModelId: string;
|
|
50
55
|
};
|
|
56
|
+
/** The modes a session offers and the mode it starts in. */
|
|
57
|
+
export type StartMode = ModeAvailability & {
|
|
58
|
+
mode: PermissionMode;
|
|
59
|
+
builtInDefault: boolean;
|
|
60
|
+
};
|
|
51
61
|
/**
|
|
52
62
|
* The permission mode a new Claude query starts in.
|
|
53
63
|
*
|
|
@@ -72,11 +82,30 @@ export declare function resolveInitialPermissionMode(sources: {
|
|
|
72
82
|
mode: PermissionMode;
|
|
73
83
|
builtInDefault: boolean;
|
|
74
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* The start mode of a query that already runs in `started.mode`, decided
|
|
87
|
+
* again under settings that include the policy Claude Code reported after it
|
|
88
|
+
* started (see `SettingsManager.followCliPolicy`). That policy can turn off
|
|
89
|
+
* a mode that the query was started with, or name another
|
|
90
|
+
* `permissions.defaultMode`. A mode that was off at the start stays off: the
|
|
91
|
+
* SDK's bypass flag was set then. `started` itself when the policy changes
|
|
92
|
+
* none of these. `SessionModeManager.initialize` sets another mode on the
|
|
93
|
+
* query (`startedIn`).
|
|
94
|
+
*/
|
|
95
|
+
export declare function startModeUnderPolicy(started: StartMode, sources: {
|
|
96
|
+
explicit?: PermissionMode;
|
|
97
|
+
resumed?: string;
|
|
98
|
+
}, settings: {
|
|
99
|
+
atStart: Settings;
|
|
100
|
+
withPolicy: Settings;
|
|
101
|
+
}, logger: {
|
|
102
|
+
error: (...args: unknown[]) => void;
|
|
103
|
+
}): StartMode;
|
|
75
104
|
/** Owns session-mode policy and the ACP/SDK synchronization it requires. */
|
|
76
105
|
export declare class SessionModeManager<S extends SessionMode> {
|
|
77
106
|
private readonly options;
|
|
78
107
|
constructor(options: SessionModeManagerOptions<S>);
|
|
79
|
-
initialize({ query, requestedMode, builtInDefault, currentModelInfo, currentModelId, allowBypass, allowAuto, }: InitializeSessionModeParams): Promise<{
|
|
108
|
+
initialize({ query, requestedMode, builtInDefault, startedIn, currentModelInfo, currentModelId, allowBypass, allowAuto, }: InitializeSessionModeParams): Promise<{
|
|
80
109
|
modes: SessionModeState;
|
|
81
110
|
autoModeFallbackWarningPending: boolean;
|
|
82
111
|
}>;
|
|
@@ -92,13 +121,46 @@ export declare class SessionModeManager<S extends SessionMode> {
|
|
|
92
121
|
* before publishing the returned state change. */
|
|
93
122
|
reconcileForModel(session: SessionMode, model: ModelInfo | undefined): Promise<boolean>;
|
|
94
123
|
/**
|
|
95
|
-
* Sets the mode on the query
|
|
124
|
+
* Sets the mode on the query, and returns the mode that is then in effect
|
|
125
|
+
* (see {@link setQueryMode}). `auto` on a model without Auto runs as its
|
|
96
126
|
* fallback, with the warning. With `deferWarning`, the warning waits for
|
|
97
127
|
* the next prompt (see {@link deferFallbackWarning}).
|
|
98
128
|
*/
|
|
99
129
|
selectMode(sessionId: string, modeId: string, deferWarning?: boolean): Promise<PermissionMode>;
|
|
130
|
+
/**
|
|
131
|
+
* Sets `mode` on the session's query, and returns the mode that Claude Code
|
|
132
|
+
* names as in effect in its answer (SDK 0.3.332). That is not always the
|
|
133
|
+
* mode asked for, so the session records the answer.
|
|
134
|
+
*
|
|
135
|
+
* Returns `mode` where the answer names no mode, as from a Claude Code
|
|
136
|
+
* before 2.1.332, or names one that the session does not offer: the
|
|
137
|
+
* session's current mode is always one of its `availableModes`. Rejects
|
|
138
|
+
* where Claude Code refuses the mode, e.g. "Cannot set permission mode to
|
|
139
|
+
* auto: auto mode disabled by settings".
|
|
140
|
+
*/
|
|
141
|
+
setQueryMode(session: Pick<SessionMode, "query" | "modes">, mode: PermissionMode): Promise<PermissionMode>;
|
|
142
|
+
/** The mode of Claude Code's `answer` to a request for `asked` (see {@link setQueryMode}). */
|
|
143
|
+
private namedMode;
|
|
100
144
|
setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse>;
|
|
101
145
|
publishCurrent(sessionId: string, mode: string): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Records the mode that Claude Code reports for `session`, and tells the
|
|
148
|
+
* client. Claude Code reports the mode in the `init` frame at the start of
|
|
149
|
+
* each turn, and in a `status` frame after a change. That covers a change
|
|
150
|
+
* of its own: a session that starts in `auto` while settings disable Auto
|
|
151
|
+
* mode is in `default` a moment later, with a `status` frame or, when the
|
|
152
|
+
* change came before the answer to the initialize request, without one.
|
|
153
|
+
*
|
|
154
|
+
* Changes nothing for the mode already recorded, which is what a frame
|
|
155
|
+
* names after a change that the adapter asked for, and for a mode that the
|
|
156
|
+
* session does not offer, which is logged (see {@link setQueryMode}).
|
|
157
|
+
*
|
|
158
|
+
* Nothing ties a frame to the request that caused it. After two quick
|
|
159
|
+
* changes by the client, the first one's frame can arrive when the second
|
|
160
|
+
* mode is already recorded: the session then shows the first mode until
|
|
161
|
+
* the second frame arrives.
|
|
162
|
+
*/
|
|
163
|
+
modeReported(sessionId: string, session: S, mode: PermissionMode): Promise<void>;
|
|
102
164
|
publishFallbackWarning(sessionId: string, session: SessionMode): Promise<void>;
|
|
103
165
|
/**
|
|
104
166
|
* Leaves the Auto fallback's warning for the next prompt
|
|
@@ -112,6 +174,10 @@ export declare class SessionModeManager<S extends SessionMode> {
|
|
|
112
174
|
private isAutoUnavailable;
|
|
113
175
|
private isAvailable;
|
|
114
176
|
private parseMode;
|
|
177
|
+
/**
|
|
178
|
+
* Sets `mode` on the query, and returns the mode then in effect (see
|
|
179
|
+
* {@link setQueryMode}). A failure is logged, and `mode` is returned.
|
|
180
|
+
*/
|
|
115
181
|
private trySyncMode;
|
|
116
182
|
}
|
|
117
183
|
export declare function buildAvailableModes({ allowBypass, allowAuto }: ModeAvailability, air?: boolean): SessionModeState["availableModes"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-mode.d.ts","sourceRoot":"","sources":["../src/session-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,KAAK,
|
|
1
|
+
{"version":3,"file":"session-mode.d.ts","sourceRoot":"","sources":["../src/session-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,KAAK,EACL,QAAQ,EACT,MAAM,gCAAgC,CAAC;AAUxC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,kBAAkB,EAAE,cAA8B,CAAC;AAYhE,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,8EAA8E;IAC9E,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,gFAAgF;IAChF,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,yBAAyB,CAAC,CAAC,SAAS,WAAW,IAAI;IAC7D,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,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AO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,SAAS;IAcjB;;;OAGG;YACW,WAAW;CAa1B;AAED,wBAAgB,mBAAmB,CACjC,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,gBAAgB,EAC5C,GAAG,UAAQ,GACV,gBAAgB,CAAC,gBAAgB,CAAC,CA2CpC"}
|
package/dist/session-mode.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RequestError, } from "@agentclientprotocol/sdk/unstable";
|
|
2
2
|
import { AIR_KIND_KEY, airOnlyMeta } from "./air-extension.js";
|
|
3
|
-
import { resolvePermissionMode } from "./permissions/modes.js";
|
|
3
|
+
import { autoModeDisabled, resolvePermissionMode } from "./permissions/modes.js";
|
|
4
4
|
import { noticeOrTranscriptUpdate, noticeTranscriptText, sentenceCase, } from "./session-notices.js";
|
|
5
5
|
export const MODE_CONFIG_ID = "mode";
|
|
6
6
|
export const AUTO_MODE_FALLBACK = "acceptEdits";
|
|
@@ -54,13 +54,39 @@ export function resolveInitialPermissionMode(sources, logger, availability) {
|
|
|
54
54
|
}
|
|
55
55
|
return { mode: configuredMode, builtInDefault: false };
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The start mode of a query that already runs in `started.mode`, decided
|
|
59
|
+
* again under settings that include the policy Claude Code reported after it
|
|
60
|
+
* started (see `SettingsManager.followCliPolicy`). That policy can turn off
|
|
61
|
+
* a mode that the query was started with, or name another
|
|
62
|
+
* `permissions.defaultMode`. A mode that was off at the start stays off: the
|
|
63
|
+
* SDK's bypass flag was set then. `started` itself when the policy changes
|
|
64
|
+
* none of these. `SessionModeManager.initialize` sets another mode on the
|
|
65
|
+
* query (`startedIn`).
|
|
66
|
+
*/
|
|
67
|
+
export function startModeUnderPolicy(started, sources, settings, logger) {
|
|
68
|
+
const { atStart, withPolicy } = settings;
|
|
69
|
+
const availability = {
|
|
70
|
+
allowBypass: started.allowBypass && withPolicy.permissions?.disableBypassPermissionsMode !== "disable",
|
|
71
|
+
allowAuto: started.allowAuto && !autoModeDisabled(withPolicy),
|
|
72
|
+
};
|
|
73
|
+
if (availability.allowBypass === started.allowBypass &&
|
|
74
|
+
availability.allowAuto === started.allowAuto &&
|
|
75
|
+
withPolicy.permissions?.defaultMode === atStart.permissions?.defaultMode) {
|
|
76
|
+
return started;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
...availability,
|
|
80
|
+
...resolveInitialPermissionMode({ ...sources, defaultMode: withPolicy.permissions?.defaultMode }, logger, availability),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
57
83
|
/** Owns session-mode policy and the ACP/SDK synchronization it requires. */
|
|
58
84
|
export class SessionModeManager {
|
|
59
85
|
options;
|
|
60
86
|
constructor(options) {
|
|
61
87
|
this.options = options;
|
|
62
88
|
}
|
|
63
|
-
async initialize({ query, requestedMode, builtInDefault = false, currentModelInfo, currentModelId, allowBypass, allowAuto, }) {
|
|
89
|
+
async initialize({ query, requestedMode, builtInDefault = false, startedIn = requestedMode, currentModelInfo, currentModelId, allowBypass, allowAuto, }) {
|
|
64
90
|
const availableModes = buildAvailableModes({ allowBypass, allowAuto }, this.options.airClient?.() ?? false);
|
|
65
91
|
let effectiveMode = requestedMode;
|
|
66
92
|
let autoModeFallbackWarningPending = false;
|
|
@@ -71,21 +97,22 @@ export class SessionModeManager {
|
|
|
71
97
|
this.options.logError(`permissions.defaultMode "${effectiveMode}" is not available in ` +
|
|
72
98
|
`this session; falling back to "default".`);
|
|
73
99
|
effectiveMode = "default";
|
|
74
|
-
await this.trySyncMode(query, effectiveMode, "Failed to sync clamped permissionMode to SDK:");
|
|
75
100
|
}
|
|
76
101
|
else if (autoUnsupported && builtInDefault) {
|
|
77
102
|
// Like Claude Code: a built-in Auto default the model can't serve starts
|
|
78
103
|
// in Manual, without a warning. Nobody chose Auto, so don't escalate to
|
|
79
104
|
// acceptEdits.
|
|
80
105
|
effectiveMode = "default";
|
|
81
|
-
await this.trySyncMode(query, effectiveMode, "Failed to sync clamped permissionMode to SDK:");
|
|
82
106
|
}
|
|
83
107
|
else if (autoUnsupported) {
|
|
84
108
|
this.options.logError(`permissions.defaultMode "auto" is not available for model ` +
|
|
85
109
|
`"${currentModelId}"; falling back to "${AUTO_MODE_FALLBACK}".`);
|
|
86
|
-
effectiveMode = AUTO_MODE_FALLBACK;
|
|
87
110
|
autoModeFallbackWarningPending = true;
|
|
88
|
-
|
|
111
|
+
effectiveMode = AUTO_MODE_FALLBACK;
|
|
112
|
+
}
|
|
113
|
+
// The query runs in `startedIn`: another mode is set on it.
|
|
114
|
+
if (effectiveMode !== startedIn) {
|
|
115
|
+
effectiveMode = await this.trySyncMode(query, availableModes, effectiveMode, "Failed to sync permissionMode to SDK:");
|
|
89
116
|
}
|
|
90
117
|
return {
|
|
91
118
|
modes: { currentModeId: effectiveMode, availableModes },
|
|
@@ -156,13 +183,13 @@ export class SessionModeManager {
|
|
|
156
183
|
}
|
|
157
184
|
session.modes = {
|
|
158
185
|
availableModes: session.modes.availableModes,
|
|
159
|
-
currentModeId: AUTO_MODE_FALLBACK,
|
|
186
|
+
currentModeId: await this.trySyncMode(session.query, session.modes.availableModes, AUTO_MODE_FALLBACK, `Failed to sync permissionMode to "${AUTO_MODE_FALLBACK}" after model switch invalidated "auto":`),
|
|
160
187
|
};
|
|
161
|
-
await this.trySyncMode(session.query, AUTO_MODE_FALLBACK, `Failed to sync permissionMode to "${AUTO_MODE_FALLBACK}" after model switch invalidated "auto":`);
|
|
162
188
|
return true;
|
|
163
189
|
}
|
|
164
190
|
/**
|
|
165
|
-
* Sets the mode on the query
|
|
191
|
+
* Sets the mode on the query, and returns the mode that is then in effect
|
|
192
|
+
* (see {@link setQueryMode}). `auto` on a model without Auto runs as its
|
|
166
193
|
* fallback, with the warning. With `deferWarning`, the warning waits for
|
|
167
194
|
* the next prompt (see {@link deferFallbackWarning}).
|
|
168
195
|
*/
|
|
@@ -172,9 +199,10 @@ export class SessionModeManager {
|
|
|
172
199
|
if (!this.isAvailable(session.modes.availableModes, requestedMode)) {
|
|
173
200
|
throw RequestError.invalidParams(undefined, `Mode ${modeId} is not available in this session`);
|
|
174
201
|
}
|
|
175
|
-
const
|
|
202
|
+
const askedMode = this.effectiveMode(session, requestedMode);
|
|
203
|
+
let modeInEffect;
|
|
176
204
|
try {
|
|
177
|
-
await
|
|
205
|
+
modeInEffect = await this.setQueryMode(session, askedMode);
|
|
178
206
|
}
|
|
179
207
|
catch (error) {
|
|
180
208
|
if (error instanceof Error) {
|
|
@@ -185,13 +213,38 @@ export class SessionModeManager {
|
|
|
185
213
|
// eslint-disable-next-line preserve-caught-error
|
|
186
214
|
throw new Error("Invalid Mode");
|
|
187
215
|
}
|
|
188
|
-
if (
|
|
216
|
+
if (askedMode !== requestedMode) {
|
|
189
217
|
if (deferWarning)
|
|
190
218
|
this.deferFallbackWarning(session);
|
|
191
219
|
else
|
|
192
220
|
await this.publishFallbackWarning(sessionId, session);
|
|
193
221
|
}
|
|
194
|
-
return
|
|
222
|
+
return modeInEffect;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Sets `mode` on the session's query, and returns the mode that Claude Code
|
|
226
|
+
* names as in effect in its answer (SDK 0.3.332). That is not always the
|
|
227
|
+
* mode asked for, so the session records the answer.
|
|
228
|
+
*
|
|
229
|
+
* Returns `mode` where the answer names no mode, as from a Claude Code
|
|
230
|
+
* before 2.1.332, or names one that the session does not offer: the
|
|
231
|
+
* session's current mode is always one of its `availableModes`. Rejects
|
|
232
|
+
* where Claude Code refuses the mode, e.g. "Cannot set permission mode to
|
|
233
|
+
* auto: auto mode disabled by settings".
|
|
234
|
+
*/
|
|
235
|
+
async setQueryMode(session, mode) {
|
|
236
|
+
return this.namedMode(session.modes.availableModes, mode, await session.query.setPermissionMode(mode));
|
|
237
|
+
}
|
|
238
|
+
/** The mode of Claude Code's `answer` to a request for `asked` (see {@link setQueryMode}). */
|
|
239
|
+
namedMode(availableModes, asked, answer) {
|
|
240
|
+
const named = answer?.mode;
|
|
241
|
+
if (named === undefined || named === asked)
|
|
242
|
+
return asked;
|
|
243
|
+
if (!this.isAvailable(availableModes, named)) {
|
|
244
|
+
this.options.logError(`Claude Code is in permission mode "${named}" after a request for "${asked}", and the session does not offer "${named}"; keeping "${asked}".`);
|
|
245
|
+
return asked;
|
|
246
|
+
}
|
|
247
|
+
return named;
|
|
195
248
|
}
|
|
196
249
|
async setSessionMode(params) {
|
|
197
250
|
const effectiveMode = await this.selectMode(params.sessionId, params.modeId);
|
|
@@ -207,6 +260,36 @@ export class SessionModeManager {
|
|
|
207
260
|
update: { sessionUpdate: "current_mode_update", currentModeId: mode },
|
|
208
261
|
});
|
|
209
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Records the mode that Claude Code reports for `session`, and tells the
|
|
265
|
+
* client. Claude Code reports the mode in the `init` frame at the start of
|
|
266
|
+
* each turn, and in a `status` frame after a change. That covers a change
|
|
267
|
+
* of its own: a session that starts in `auto` while settings disable Auto
|
|
268
|
+
* mode is in `default` a moment later, with a `status` frame or, when the
|
|
269
|
+
* change came before the answer to the initialize request, without one.
|
|
270
|
+
*
|
|
271
|
+
* Changes nothing for the mode already recorded, which is what a frame
|
|
272
|
+
* names after a change that the adapter asked for, and for a mode that the
|
|
273
|
+
* session does not offer, which is logged (see {@link setQueryMode}).
|
|
274
|
+
*
|
|
275
|
+
* Nothing ties a frame to the request that caused it. After two quick
|
|
276
|
+
* changes by the client, the first one's frame can arrive when the second
|
|
277
|
+
* mode is already recorded: the session then shows the first mode until
|
|
278
|
+
* the second frame arrives.
|
|
279
|
+
*/
|
|
280
|
+
async modeReported(sessionId, session, mode) {
|
|
281
|
+
// A frame of a query that the session no longer runs on is not its mode.
|
|
282
|
+
if (this.options.getSession(sessionId) !== session)
|
|
283
|
+
return;
|
|
284
|
+
if (session.modes.currentModeId === mode)
|
|
285
|
+
return;
|
|
286
|
+
if (!this.isAvailable(session.modes.availableModes, mode)) {
|
|
287
|
+
this.options.logError(`Claude Code reports permission mode "${mode}", which the session does not offer; keeping "${session.modes.currentModeId}".`);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
await this.publishCurrent(sessionId, mode);
|
|
291
|
+
await this.options.updateConfigOption(sessionId, MODE_CONFIG_ID, mode);
|
|
292
|
+
}
|
|
210
293
|
async publishFallbackWarning(sessionId, session) {
|
|
211
294
|
session.autoModeFallbackWarningPending = false;
|
|
212
295
|
if (session.autoModeFallbackWarningShown)
|
|
@@ -270,12 +353,17 @@ export class SessionModeManager {
|
|
|
270
353
|
throw RequestError.invalidParams(undefined, `Invalid Mode: ${modeId}`);
|
|
271
354
|
}
|
|
272
355
|
}
|
|
273
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Sets `mode` on the query, and returns the mode then in effect (see
|
|
358
|
+
* {@link setQueryMode}). A failure is logged, and `mode` is returned.
|
|
359
|
+
*/
|
|
360
|
+
async trySyncMode(query, availableModes, mode, errorMessage) {
|
|
274
361
|
try {
|
|
275
|
-
await query.setPermissionMode(mode);
|
|
362
|
+
return this.namedMode(availableModes, mode, await query.setPermissionMode(mode));
|
|
276
363
|
}
|
|
277
364
|
catch (error) {
|
|
278
365
|
this.options.logError(errorMessage, error);
|
|
366
|
+
return mode;
|
|
279
367
|
}
|
|
280
368
|
}
|
|
281
369
|
}
|
package/dist/session-model.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SessionConfigOption } from "@agentclientprotocol/sdk/unstable";
|
|
2
2
|
import { type ModelInfo, type Query, type Settings } from "@anthropic-ai/claude-agent-sdk";
|
|
3
|
+
import type { QuerySettings } from "./query-settings.js";
|
|
3
4
|
export declare const MODEL_CONFIG_ID = "model";
|
|
4
5
|
export type SessionModelState = {
|
|
5
6
|
availableModels: Array<{
|
|
@@ -142,7 +143,9 @@ export declare function withCurrentModelInfo(allowedModels: ModelInfo[], sdkMode
|
|
|
142
143
|
currentModelInfo: ModelInfo | undefined;
|
|
143
144
|
modelInfos: ModelInfo[];
|
|
144
145
|
};
|
|
145
|
-
export declare function getAvailableModels(query: Query, models: ModelInfo[], sdkModels: ModelInfo[], settingsManager: ModelSettingsSource, logger: ModelLogger, isResumedSession: boolean, sessionId: string, resumedModelHint?: string, narrowedByGateway?: boolean
|
|
146
|
+
export declare function getAvailableModels(query: Query, models: ModelInfo[], sdkModels: ModelInfo[], settingsManager: ModelSettingsSource, logger: ModelLogger, isResumedSession: boolean, sessionId: string, resumedModelHint?: string, narrowedByGateway?: boolean,
|
|
147
|
+
/** Claude Code's `get_settings` answer for this query, read after `initialize`. */
|
|
148
|
+
cliSettings?: QuerySettings): Promise<SessionModelState>;
|
|
146
149
|
/** The display name of the model id `model` in `modelInfos`, if it is there. */
|
|
147
150
|
export declare function modelDisplayName(modelInfos: ModelInfo[], model: string): string | undefined;
|
|
148
151
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-model.d.ts","sourceRoot":"","sources":["../src/session-model.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,QAAQ,EACd,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"session-model.d.ts","sourceRoot":"","sources":["../src/session-model.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,QAAQ,EACd,MAAM,gCAAgC,CAAC;AAIxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;Q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,MAAM,CAAA;CAAE,GAAG,SAAS,CAW7C"}
|
package/dist/session-model.js
CHANGED
|
@@ -602,7 +602,9 @@ export function withCurrentModelInfo(allowedModels, sdkModels, currentModelId) {
|
|
|
602
602
|
function isPreModelSwitchHookBlock(error) {
|
|
603
603
|
return error instanceof Error && error.message.includes("blocked by a PreModelSwitch hook");
|
|
604
604
|
}
|
|
605
|
-
export async function getAvailableModels(query, models, sdkModels, settingsManager, logger, isResumedSession, sessionId, resumedModelHint, narrowedByGateway = false
|
|
605
|
+
export async function getAvailableModels(query, models, sdkModels, settingsManager, logger, isResumedSession, sessionId, resumedModelHint, narrowedByGateway = false,
|
|
606
|
+
/** Claude Code's `get_settings` answer for this query, read after `initialize`. */
|
|
607
|
+
cliSettings) {
|
|
606
608
|
// A gateway that lists none of the SDK's models leaves none to offer
|
|
607
609
|
// (`narrowToGatewayModels`). The session stays on the model the SDK runs,
|
|
608
610
|
// and the gateway refuses its requests.
|
|
@@ -612,7 +614,13 @@ export async function getAvailableModels(query, models, sdkModels, settingsManag
|
|
|
612
614
|
currentModelId: (isResumedSession && resumedModelHint) || sdkModels[0]?.value || "default",
|
|
613
615
|
};
|
|
614
616
|
}
|
|
615
|
-
|
|
617
|
+
// The `model` setting as the running CLI resolved it, which also counts the
|
|
618
|
+
// tiers that `settingsManager` does not read (the `settings` option of the
|
|
619
|
+
// query). Without the CLI's answer, the settings of this process.
|
|
620
|
+
const settings = cliSettings?.effective ?? settingsManager.getSettings();
|
|
621
|
+
const appliedModel = typeof cliSettings?.applied?.model === "string" && cliSettings.applied.model.trim()
|
|
622
|
+
? cliSettings.applied.model
|
|
623
|
+
: undefined;
|
|
616
624
|
let currentModel = models[0];
|
|
617
625
|
let resolvedFromInput;
|
|
618
626
|
// Model priority (highest to lowest):
|
|
@@ -644,7 +652,7 @@ export async function getAvailableModels(query, models, sdkModels, settingsManag
|
|
|
644
652
|
currentModel = resumedModelHint ? matchResumedModel(models, resumedModelHint) : currentModel;
|
|
645
653
|
}
|
|
646
654
|
// Skip the setModel round-trip when we can prove the SDK has already landed
|
|
647
|
-
// on the same model.
|
|
655
|
+
// on the same model. Three cases qualify:
|
|
648
656
|
// (a) No override applied — currentModel is the SDK's own default (or, on
|
|
649
657
|
// resume, the live model read back from the SDK above); nothing to sync.
|
|
650
658
|
// (b) The resolver returned the user's input verbatim AND that value exists
|
|
@@ -654,6 +662,8 @@ export async function getAvailableModels(query, models, sdkModels, settingsManag
|
|
|
654
662
|
// This only holds for fresh sessions: a resumed session lands on the
|
|
655
663
|
// transcript's model regardless of env/settings, so the override must
|
|
656
664
|
// be re-asserted to keep the reported model truthful.
|
|
665
|
+
// (c) The CLI reports that it runs the model that `currentModel` resolves
|
|
666
|
+
// to (`cliRunsSelectedModel` below), on a fresh or a resumed session.
|
|
657
667
|
// Anything else (fuzzy match, allowlist-synthesized value, alias) gets a
|
|
658
668
|
// setModel call so we don't drift from the user's intended pin.
|
|
659
669
|
// Case (a) does not hold when `narrowToGatewayModels` left the SDK on a
|
|
@@ -680,7 +690,19 @@ export async function getAvailableModels(query, models, sdkModels, settingsManag
|
|
|
680
690
|
}
|
|
681
691
|
// When the switch fails, the SDK stays on the model it ran before it.
|
|
682
692
|
const modelBeforeSwitch = () => switchToListed && sdkDefault !== undefined ? sdkDefault : models[0];
|
|
683
|
-
|
|
693
|
+
// `applied.model` is the model that the CLI runs: `claude-sonnet-5-5` for a
|
|
694
|
+
// `claude-sonnet-5-5[1m]` pin (it drops the hint of a model whose only
|
|
695
|
+
// window is 1M), `claude-sonnet-4-6[1m]` for the 1M lane of a model that
|
|
696
|
+
// also has a 200k one. The ids are compared with their hints, so a session
|
|
697
|
+
// on the 200k lane still gets a `[1m]` row set. On a resumed session the
|
|
698
|
+
// CLI has restored the transcript's model before it answers `get_settings`
|
|
699
|
+
// (seen on 2.1.333); nothing here enforces that order.
|
|
700
|
+
const cliRunsSelectedModel = appliedModel !== undefined &&
|
|
701
|
+
sdkSawSameValue &&
|
|
702
|
+
canonicalizeModelId(currentModel.resolvedModel ?? currentModel.value) ===
|
|
703
|
+
canonicalizeModelId(appliedModel);
|
|
704
|
+
const skipSetModel = cliRunsSelectedModel ||
|
|
705
|
+
(resolvedFromInput === undefined && !switchToListed) ||
|
|
684
706
|
(!isResumedSession && currentModel.value === resolvedFromInput && sdkSawSameValue);
|
|
685
707
|
if (!skipSetModel) {
|
|
686
708
|
const setModelStartedAt = performance.now();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const SESSION_READ_METHOD = "_session/read";
|
|
2
|
+
export declare const SESSION_READ_CAPABILITY: {
|
|
3
|
+
readonly supported: true;
|
|
4
|
+
};
|
|
5
|
+
export type SessionReadFrame = {
|
|
6
|
+
sessionId: string;
|
|
7
|
+
update: {
|
|
8
|
+
sessionUpdate: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
type ReadOptions = {
|
|
14
|
+
protocol: 1 | 2;
|
|
15
|
+
capabilities: unknown;
|
|
16
|
+
cursors: boolean;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
isOpen(sessionId: string): boolean;
|
|
19
|
+
replay(sessionId: string, cwd: string | undefined): Promise<{
|
|
20
|
+
frames: SessionReadFrame[];
|
|
21
|
+
cwd: string;
|
|
22
|
+
historyEnd?: number;
|
|
23
|
+
title?: string;
|
|
24
|
+
}>;
|
|
25
|
+
send(frame: SessionReadFrame): Promise<void> | void;
|
|
26
|
+
};
|
|
27
|
+
/** The SDK follows parent links in these records, including the branch selected by rewind.json. */
|
|
28
|
+
export declare function readSessionTranscript(sessionId: string, cwd?: string): Promise<{
|
|
29
|
+
messages: import("@anthropic-ai/claude-agent-sdk").SessionMessage[];
|
|
30
|
+
cwd: string;
|
|
31
|
+
transcript: string;
|
|
32
|
+
title: string | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
/** A read owns only a replay on this connection. Closing it invalidates the pending delivery. */
|
|
35
|
+
export declare class SessionReads {
|
|
36
|
+
private readonly active;
|
|
37
|
+
private readonly transitions;
|
|
38
|
+
/** Reserve a session before load, resume, close or delete can yield. */
|
|
39
|
+
transition<T>(sessionId: string | undefined, kind: "open" | "close", run: () => Promise<T>): Promise<T>;
|
|
40
|
+
read(params: unknown, options: ReadOptions): Promise<{
|
|
41
|
+
cursorId?: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=session-read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-read.d.ts","sourceRoot":"","sources":["../src/session-read.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,uBAAuB;;CAA+B,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC1D,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAcF,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GAAG,SAAS,GACtB,OAAO,CAAC;QAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7F,IAAI,CAAC,KAAK,EAAE,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