@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AsyncTaskRuntime } from "../async-tasks.js";
|
|
1
2
|
/** Stops one Claude background task without cancelling the parent prompt turn. */
|
|
2
3
|
export declare const ASYNC_TASK_STOP_METHOD = "_session/async_task/stop";
|
|
3
4
|
export type AsyncTaskStopRequest = {
|
|
@@ -8,4 +9,34 @@ export type AsyncTaskStopResponse = {
|
|
|
8
9
|
stopped: boolean;
|
|
9
10
|
};
|
|
10
11
|
export declare function parseAsyncTaskStopRequest(value: unknown): AsyncTaskStopRequest;
|
|
12
|
+
/** The part of a queued prompt turn that the stop of an autonomous turn reads. */
|
|
13
|
+
export type WaitingPrompt = {
|
|
14
|
+
promptUuid: string;
|
|
15
|
+
settled?: boolean;
|
|
16
|
+
commandStarted?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** The prompts in `turnQueue` that still await their turn. */
|
|
19
|
+
export declare function waitingPrompts<T extends WaitingPrompt>(turnQueue: readonly T[] | undefined): T[];
|
|
20
|
+
/**
|
|
21
|
+
* Whether an interrupt of the running autonomous turn leaves `waiting` to run
|
|
22
|
+
* next. A prompt still in Claude Code's queue survives it and is listed in the
|
|
23
|
+
* receipt's `still_queued`. A prompt that a `started` lifecycle frame says the
|
|
24
|
+
* CLI already dispatched into a turn may be part of the interrupted turn, and
|
|
25
|
+
* without lifecycle frames the adapter cannot tell which case a prompt is in.
|
|
26
|
+
*/
|
|
27
|
+
export declare function interruptKeepsWaitingPrompts(session: {
|
|
28
|
+
msgLifecycleV1?: boolean;
|
|
29
|
+
}, waiting: readonly WaitingPrompt[]): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Interrupts the running autonomous turn for a stop. The turn's aborted result
|
|
32
|
+
* is owed to the stop from before the interrupt, so a failed interrupt rolls
|
|
33
|
+
* the debt back.
|
|
34
|
+
*/
|
|
35
|
+
export declare function interruptAutonomousTurn(query: {
|
|
36
|
+
interrupt(): Promise<{
|
|
37
|
+
still_queued?: readonly string[];
|
|
38
|
+
} | undefined>;
|
|
39
|
+
}, asyncTasks: Pick<AsyncTaskRuntime, "autonomousTurnInterrupting" | "autonomousTurnInterruptFailed">, waiting: readonly WaitingPrompt[], logger: {
|
|
40
|
+
log(message: string): void;
|
|
41
|
+
}): Promise<void>;
|
|
11
42
|
//# sourceMappingURL=async-task-stop.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-task-stop.d.ts","sourceRoot":"","sources":["../../src/v1/async-task-stop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"async-task-stop.d.ts","sourceRoot":"","sources":["../../src/v1/async-task-stop.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,6BAA6B,CAAC;AAEjE,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAoB9E;AAED,kFAAkF;AAClF,MAAM,MAAM,aAAa,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEhG,8DAA8D;AAC9D,wBAAgB,cAAc,CAAC,CAAC,SAAS,aAAa,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,GAAG,SAAS,GAAG,CAAC,EAAE,CAEhG;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,EACrC,OAAO,EAAE,SAAS,aAAa,EAAE,GAChC,OAAO,CAKT;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE;IAAE,SAAS,IAAI,OAAO,CAAC;QAAE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,GAAG,SAAS,CAAC,CAAA;CAAE,EACjF,UAAU,EAAE,IAAI,CACd,gBAAgB,EAChB,4BAA4B,GAAG,+BAA+B,CAC/D,EACD,OAAO,EAAE,SAAS,aAAa,EAAE,EACjC,MAAM,EAAE;IAAE,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACrC,OAAO,CAAC,IAAI,CAAC,CAoBf"}
|
|
@@ -16,3 +16,44 @@ export function parseAsyncTaskStopRequest(value) {
|
|
|
16
16
|
}
|
|
17
17
|
return { sessionId, asyncTaskId };
|
|
18
18
|
}
|
|
19
|
+
/** The prompts in `turnQueue` that still await their turn. */
|
|
20
|
+
export function waitingPrompts(turnQueue) {
|
|
21
|
+
return (turnQueue ?? []).filter((turn) => !turn.settled);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether an interrupt of the running autonomous turn leaves `waiting` to run
|
|
25
|
+
* next. A prompt still in Claude Code's queue survives it and is listed in the
|
|
26
|
+
* receipt's `still_queued`. A prompt that a `started` lifecycle frame says the
|
|
27
|
+
* CLI already dispatched into a turn may be part of the interrupted turn, and
|
|
28
|
+
* without lifecycle frames the adapter cannot tell which case a prompt is in.
|
|
29
|
+
*/
|
|
30
|
+
export function interruptKeepsWaitingPrompts(session, waiting) {
|
|
31
|
+
return (waiting.length === 0 ||
|
|
32
|
+
(session.msgLifecycleV1 === true && waiting.every((turn) => !turn.commandStarted)));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Interrupts the running autonomous turn for a stop. The turn's aborted result
|
|
36
|
+
* is owed to the stop from before the interrupt, so a failed interrupt rolls
|
|
37
|
+
* the debt back.
|
|
38
|
+
*/
|
|
39
|
+
export async function interruptAutonomousTurn(query, asyncTasks, waiting, logger) {
|
|
40
|
+
asyncTasks.autonomousTurnInterrupting();
|
|
41
|
+
let receipt;
|
|
42
|
+
try {
|
|
43
|
+
receipt = await query.interrupt();
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
asyncTasks.autonomousTurnInterruptFailed();
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(receipt?.still_queued)) {
|
|
50
|
+
const stillQueued = new Set(receipt.still_queued);
|
|
51
|
+
for (const turn of waiting) {
|
|
52
|
+
if (stillQueued.has(turn.promptUuid))
|
|
53
|
+
continue;
|
|
54
|
+
// Not an error: the prompt may also be one the CLI has not read
|
|
55
|
+
// into its queue yet, and it then runs next as usual.
|
|
56
|
+
logger.log(`Prompt ${turn.promptUuid} is not in the interrupt receipt's still_queued: Claude Code may have taken it into the interrupted turn, which then ends with the interrupted result.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ClientCapabilities } from "@agentclientprotocol/sdk/unstable";
|
|
2
|
+
import type { SessionMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
3
|
+
import type { AcpClient } from "../acp-client.js";
|
|
4
|
+
/** A render whose updates are held until the read cursor is validated. */
|
|
5
|
+
export type DetachedReplay = {
|
|
6
|
+
messages: SessionMessage[];
|
|
7
|
+
transcript: string;
|
|
8
|
+
publish: AcpClient["sessionUpdate"];
|
|
9
|
+
endHistory: () => void;
|
|
10
|
+
signal: AbortSignal;
|
|
11
|
+
};
|
|
12
|
+
export declare class V1SessionReads {
|
|
13
|
+
private readonly client;
|
|
14
|
+
private readonly reads;
|
|
15
|
+
private readonly closed;
|
|
16
|
+
constructor(client: Pick<AcpClient, "sessionUpdate">);
|
|
17
|
+
dispose(): void;
|
|
18
|
+
readonly transition: <T>(sessionId: string | undefined, kind: "open" | "close", run: () => Promise<T>) => Promise<T>;
|
|
19
|
+
read(params: unknown, options: {
|
|
20
|
+
capabilities: ClientCapabilities | undefined;
|
|
21
|
+
airClient: boolean;
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
isOpen: (sessionId: string) => boolean;
|
|
24
|
+
assertRoot: (sessionId: string) => void;
|
|
25
|
+
clientTitle: (title: string) => string;
|
|
26
|
+
render: (sessionId: string, cwd: string, replay: DetachedReplay) => Promise<void>;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
cursorId?: string;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=session-read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-read.d.ts","sourceRoot":"","sources":["../../src/v1/session-read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAuB,MAAM,mCAAmC,CAAC;AACjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD,0EAA0E;AAC1E,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,SAAS,CAAC,eAAe,CAAC,CAAC;IACpC,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,qBAAa,cAAc;IAIb,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAsB;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;gBAEnB,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC;IAErE,OAAO,IAAI,IAAI;IAIf,QAAQ,CAAC,UAAU,kGAA0C;IAE7D,IAAI,CACF,MAAM,EAAE,OAAO,EACf,OAAO,EAAE;QACP,YAAY,EAAE,kBAAkB,GAAG,SAAS,CAAC;QAC7C,SAAS,EAAE,OAAO,CAAC;QACnB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;QACvC,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;QACxC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;QACvC,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KACnF,GACA,OAAO,CAAC;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAiDlC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { readSessionTranscript, SessionReads } from "../session-read.js";
|
|
2
|
+
import { ChangedMetaFilter } from "./tool-calls/changed-meta-filter.js";
|
|
3
|
+
export class V1SessionReads {
|
|
4
|
+
client;
|
|
5
|
+
reads = new SessionReads();
|
|
6
|
+
closed = new AbortController();
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
dispose() {
|
|
11
|
+
this.closed.abort();
|
|
12
|
+
}
|
|
13
|
+
transition = this.reads.transition.bind(this.reads);
|
|
14
|
+
read(params, options) {
|
|
15
|
+
const signal = options.signal
|
|
16
|
+
? AbortSignal.any([options.signal, this.closed.signal])
|
|
17
|
+
: this.closed.signal;
|
|
18
|
+
return this.reads.read(params, {
|
|
19
|
+
protocol: 1,
|
|
20
|
+
capabilities: options.capabilities,
|
|
21
|
+
cursors: options.capabilities?.session?.cursors != null,
|
|
22
|
+
isOpen: options.isOpen,
|
|
23
|
+
signal,
|
|
24
|
+
replay: async (sessionId, cwd) => {
|
|
25
|
+
options.assertRoot(sessionId);
|
|
26
|
+
const transcript = await readSessionTranscript(sessionId, cwd);
|
|
27
|
+
signal.throwIfAborted();
|
|
28
|
+
const frames = [];
|
|
29
|
+
let historyEnd;
|
|
30
|
+
const filter = options.airClient ? new ChangedMetaFilter() : undefined;
|
|
31
|
+
await options.render(sessionId, transcript.cwd, {
|
|
32
|
+
...transcript,
|
|
33
|
+
signal,
|
|
34
|
+
endHistory: () => {
|
|
35
|
+
historyEnd = frames.length;
|
|
36
|
+
},
|
|
37
|
+
publish: async (notification) => {
|
|
38
|
+
signal.throwIfAborted();
|
|
39
|
+
const update = filter
|
|
40
|
+
? filter.apply(notification.update)
|
|
41
|
+
: notification.update;
|
|
42
|
+
if (update) {
|
|
43
|
+
frames.push({
|
|
44
|
+
...notification,
|
|
45
|
+
update: update.sessionUpdate === "async_task_spawned"
|
|
46
|
+
? { ...update, canStop: false }
|
|
47
|
+
: update,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
frames,
|
|
54
|
+
cwd: transcript.cwd,
|
|
55
|
+
historyEnd,
|
|
56
|
+
title: transcript.title === undefined ? undefined : options.clientTitle(transcript.title),
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
send: (frame) => this.client.sessionUpdate(frame),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
package/dist/v2/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/v2/agent.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAcxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/v2/agent.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAcxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiF3C,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,CAoDb"}
|
package/dist/v2/agent.js
CHANGED
|
@@ -27,12 +27,14 @@ import { forkSession } from "../fork-session.js";
|
|
|
27
27
|
import { supportsMcpOAuth } from "../mcp-oauth.js";
|
|
28
28
|
import { McpOverAcp, mcpServerNames, refusedMcpServers, sdkMcpServers, startAroundRefusedMcpServers, } from "../mcp-servers.js";
|
|
29
29
|
import { ALLOW_BYPASS, autoModeDisabled } from "../permissions/modes.js";
|
|
30
|
+
import { followQueryPolicy } from "../query-settings.js";
|
|
30
31
|
import { clientTakesPromptSuggestions, promptSuggestionOptions, } from "../prompt-suggestions.js";
|
|
31
32
|
import { applyProviderRoute } from "../providers.js";
|
|
32
33
|
import { readHistoryAcrossCompactions, readResumedTail, resumedModelFromTranscript, } from "../resumed-session.js";
|
|
33
34
|
import { mergeEffortSettings } from "../session-effort.js";
|
|
34
35
|
import { configuredSettings, resolveThinkingConfig } from "../session-env.js";
|
|
35
|
-
import { resolveInitialPermissionMode } from "../session-mode.js";
|
|
36
|
+
import { resolveInitialPermissionMode, startModeUnderPolicy } from "../session-mode.js";
|
|
37
|
+
import { SESSION_READ_CAPABILITY, SESSION_READ_METHOD, SessionReads } from "../session-read.js";
|
|
36
38
|
import { cutAtRewindPoint, prepareRewoundResume } from "../session-rewind.js";
|
|
37
39
|
import { sanitizeTitle } from "../session-titles.js";
|
|
38
40
|
import { renameSession } from "../session-index/rename.js";
|
|
@@ -57,8 +59,10 @@ import { ReplayHolds } from "./replay-hold.js";
|
|
|
57
59
|
import { reportHooks } from "./reports.js";
|
|
58
60
|
import { savedSessionStatus } from "../session-status.js";
|
|
59
61
|
import { SessionRestarts } from "./restarts.js";
|
|
62
|
+
import { renderSessionRead } from "./session-read.js";
|
|
60
63
|
import { V2Session } from "./session.js";
|
|
61
|
-
import { afterSetupResponse, clientOptions,
|
|
64
|
+
import { afterSetupResponse, clientOptions, replayEndUpdate, sessionModels, withClientHooks, } from "./setup.js";
|
|
65
|
+
import { replaySessionHistory } from "./subagent-replay.js";
|
|
62
66
|
import { SubscriptionGuard } from "./subscription-guard.js";
|
|
63
67
|
/** The sessions per `session/list` page. */
|
|
64
68
|
const SESSION_LIST_PAGE_SIZE = 1000;
|
|
@@ -82,6 +86,7 @@ export function v2AgentApp(logger, onAgent) {
|
|
|
82
86
|
.onRequest(v2.methods.agent.providers.disable, ({ params }) => agent.auth.disableProvider(params))
|
|
83
87
|
.onRequest(v2.methods.agent.session.new, ({ params }) => agent.newSession(params))
|
|
84
88
|
.onRequest(v2.methods.agent.session.resume, ({ params }) => agent.resumeSession(params))
|
|
89
|
+
.onRequest(SESSION_READ_METHOD, (params) => params, ({ params, signal }) => agent.readSession(params, signal))
|
|
85
90
|
.onRequest(v2.methods.agent.session.fork, ({ params }) => agent.forkSession(params))
|
|
86
91
|
.onRequest(v2.methods.agent.session.list, ({ params }) => agent.listSessions(params))
|
|
87
92
|
.onRequest(v2.methods.agent.session.close, ({ params }) => agent.closeSession(params))
|
|
@@ -121,6 +126,7 @@ class V2Agent {
|
|
|
121
126
|
* response, and nothing of the session after it.
|
|
122
127
|
*/
|
|
123
128
|
resuming = new Map();
|
|
129
|
+
sessionReads = new SessionReads();
|
|
124
130
|
/** What the resumes that replay hold back until their `replay_complete` (see `replay-hold.ts`). */
|
|
125
131
|
replays = new ReplayHolds();
|
|
126
132
|
/**
|
|
@@ -281,7 +287,7 @@ class V2Agent {
|
|
|
281
287
|
const { authMethods, auth, _meta } = this.auth.initialize(request.capabilities);
|
|
282
288
|
const airMeta = airInitializeMeta(this.air);
|
|
283
289
|
return {
|
|
284
|
-
|
|
290
|
+
_meta: { ...airMeta, sessionRead: SESSION_READ_CAPABILITY },
|
|
285
291
|
protocolVersion: v2.PROTOCOL_VERSION,
|
|
286
292
|
info: { name: packageJson.name, title: "Claude Agent", version: packageJson.version },
|
|
287
293
|
capabilities: {
|
|
@@ -294,6 +300,22 @@ class V2Agent {
|
|
|
294
300
|
authMethods,
|
|
295
301
|
};
|
|
296
302
|
}
|
|
303
|
+
async readSession(params, signal) {
|
|
304
|
+
const sessionId = params?.sessionId;
|
|
305
|
+
if (typeof sessionId === "string" && this.children.has(sessionId)) {
|
|
306
|
+
throw restrictedChild(sessionId, "read");
|
|
307
|
+
}
|
|
308
|
+
const capabilities = this.clientCapabilities;
|
|
309
|
+
return this.sessionReads.read(params, {
|
|
310
|
+
protocol: 2,
|
|
311
|
+
capabilities,
|
|
312
|
+
cursors: true,
|
|
313
|
+
signal,
|
|
314
|
+
isOpen: (sessionId) => this.sessions.has(sessionId) || this.stopped.has(sessionId) || this.starting.has(sessionId),
|
|
315
|
+
replay: (sessionId, cwd) => renderSessionRead(sessionId, cwd, this.logger, capabilities),
|
|
316
|
+
send: (frame) => this.ctx.notify(v2.methods.client.session.update, frame),
|
|
317
|
+
});
|
|
318
|
+
}
|
|
297
319
|
/**
|
|
298
320
|
* `session/prompt`. Each prompt reads the auth identity again, as on v1. A
|
|
299
321
|
* restart of the session's query that is due runs first (see
|
|
@@ -368,7 +390,7 @@ class V2Agent {
|
|
|
368
390
|
*/
|
|
369
391
|
resumeSession(params) {
|
|
370
392
|
const { sessionId } = params;
|
|
371
|
-
const run = this.resume(params);
|
|
393
|
+
const run = this.sessionReads.transition(sessionId, "open", () => this.resume(params));
|
|
372
394
|
let runs = this.resuming.get(sessionId);
|
|
373
395
|
if (!runs)
|
|
374
396
|
this.resuming.set(sessionId, (runs = new Set()));
|
|
@@ -501,9 +523,10 @@ class V2Agent {
|
|
|
501
523
|
replay(session, messages, subagents) {
|
|
502
524
|
const { sessionId } = session;
|
|
503
525
|
this.replays.replay(() => {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
526
|
+
replaySessionHistory((notification) => this.send(notification), session.output, messages, subagents, {
|
|
527
|
+
background: session.tasks.backgroundWork(sessionId),
|
|
528
|
+
running: session.tasks.replayedBackground(sessionId),
|
|
529
|
+
});
|
|
507
530
|
const end = replayEndUpdate(this.clientCapabilities);
|
|
508
531
|
if (end)
|
|
509
532
|
this.send({ sessionId, update: end });
|
|
@@ -572,7 +595,9 @@ class V2Agent {
|
|
|
572
595
|
* hooks in it, as in every query.
|
|
573
596
|
*
|
|
574
597
|
* It sends no update, and it creates, resumes and changes no session. A
|
|
575
|
-
* `sessionId` without a stored conversation fails with `-32002`.
|
|
598
|
+
* `sessionId` without a stored conversation fails with `-32002`. A start
|
|
599
|
+
* that would fail fails it too, e.g. when Claude Code skipped an invalid
|
|
600
|
+
* settings file.
|
|
576
601
|
*/
|
|
577
602
|
async sessionOptions(params) {
|
|
578
603
|
const { sessionId } = params;
|
|
@@ -622,6 +647,9 @@ class V2Agent {
|
|
|
622
647
|
async closeSession({ sessionId }) {
|
|
623
648
|
if (this.children.has(sessionId))
|
|
624
649
|
throw restrictedChild(sessionId, "close");
|
|
650
|
+
return this.sessionReads.transition(sessionId, "close", () => this.close(sessionId));
|
|
651
|
+
}
|
|
652
|
+
async close(sessionId) {
|
|
625
653
|
// A restart that runs ends first, so the close ends the session it started.
|
|
626
654
|
await this.restarts.closing(sessionId);
|
|
627
655
|
// A resume that runs answers first: the close ends what it started, and
|
|
@@ -649,23 +677,25 @@ class V2Agent {
|
|
|
649
677
|
async deleteSession({ sessionId }) {
|
|
650
678
|
if (this.children.has(sessionId))
|
|
651
679
|
throw restrictedChild(sessionId, "delete");
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
680
|
+
return this.sessionReads.transition(sessionId, "close", async () => {
|
|
681
|
+
// A resume that runs, or its start, may make the session live.
|
|
682
|
+
await this.setupSettled(sessionId);
|
|
683
|
+
const live = this.sessions.get(sessionId);
|
|
684
|
+
if (live || this.stopped.has(sessionId))
|
|
685
|
+
await this.close(sessionId);
|
|
686
|
+
try {
|
|
687
|
+
// After a `session/set_title` of the session in flight.
|
|
688
|
+
const remove = () => deleteSession(sessionId, live ? { dir: live.cwd } : undefined);
|
|
689
|
+
await (this.transcripts ? this.transcripts.exclusive(sessionId, remove) : remove());
|
|
690
|
+
}
|
|
691
|
+
catch (error) {
|
|
692
|
+
// A session without a transcript, such as one never prompted, has nothing to delete.
|
|
693
|
+
if (error instanceof Error && /not found/i.test(error.message))
|
|
694
|
+
return {};
|
|
695
|
+
throw error;
|
|
696
|
+
}
|
|
697
|
+
return {};
|
|
698
|
+
});
|
|
669
699
|
}
|
|
670
700
|
/**
|
|
671
701
|
* `session/set_title`, as the v1 core does it (see `session-index/rename.ts`).
|
|
@@ -961,9 +991,10 @@ class V2Agent {
|
|
|
961
991
|
settings.getSettings().permissions?.disableBypassPermissionsMode !== "disable" &&
|
|
962
992
|
client?.allowDangerouslySkipPermissions !== false;
|
|
963
993
|
const allowAuto = !autoModeDisabled(settings.getSettings());
|
|
994
|
+
const spawnSettings = settings.getSettings();
|
|
964
995
|
const { mode, builtInDefault } = resolveInitialPermissionMode({
|
|
965
996
|
resumed: resumed?.permissionMode,
|
|
966
|
-
defaultMode:
|
|
997
|
+
defaultMode: spawnSettings.permissions?.defaultMode,
|
|
967
998
|
}, this.logger, { allowBypass, allowAuto });
|
|
968
999
|
// The settings stay live for the idle compaction (see `reports.ts`) until the session
|
|
969
1000
|
// ends. They keep the values they read: their cwd and key helper.
|
|
@@ -1127,6 +1158,12 @@ class V2Agent {
|
|
|
1127
1158
|
throw error;
|
|
1128
1159
|
}
|
|
1129
1160
|
}
|
|
1161
|
+
// From here on the settings include the policy Claude Code applies, which
|
|
1162
|
+
// the host resolver can miss (see `followCliPolicy`). The bypass flag stays
|
|
1163
|
+
// as it was decided before the query started. The mode is decided again:
|
|
1164
|
+
// `SessionConfig.start` sets it on the query below.
|
|
1165
|
+
const cliSettings = await followQueryPolicy(q, settings, this.logger);
|
|
1166
|
+
const startMode = startModeUnderPolicy({ allowBypass, allowAuto, mode, builtInDefault }, { resumed: resumed?.permissionMode }, { atStart: spawnSettings, withPolicy: settings.getSettings() }, this.logger);
|
|
1130
1167
|
authStarted(sessionId, initialization.account);
|
|
1131
1168
|
try {
|
|
1132
1169
|
this.guard.sessionStarted(sessionId, initialization.account, settings.getApiKeyHelper());
|
|
@@ -1143,7 +1180,7 @@ class V2Agent {
|
|
|
1143
1180
|
session.setRemoteControlAtStartup(startsWithRemoteControl(initialization));
|
|
1144
1181
|
let models;
|
|
1145
1182
|
try {
|
|
1146
|
-
models = await sessionModels(q, initialization.models, settings, routing.models, routing.narrowsModels, resumed, sessionId, this.logger, configured);
|
|
1183
|
+
models = await sessionModels(q, initialization.models, settings, routing.models, routing.narrowsModels, resumed, sessionId, this.logger, configured, cliSettings);
|
|
1147
1184
|
}
|
|
1148
1185
|
catch (error) {
|
|
1149
1186
|
// Claude Code refused a fresh session's model pin.
|
|
@@ -1153,10 +1190,11 @@ class V2Agent {
|
|
|
1153
1190
|
}
|
|
1154
1191
|
// A failed sync of the mode is logged (`SessionModeManager.initialize`),
|
|
1155
1192
|
// and a failed read of the agents or of ultracode leaves them out. Only
|
|
1156
|
-
// the effort that `recommendedValue` sets
|
|
1193
|
+
// the effort that `recommendedValue` sets, and settings files that Claude
|
|
1194
|
+
// Code skipped, can fail the start.
|
|
1157
1195
|
let config;
|
|
1158
1196
|
try {
|
|
1159
|
-
config = await SessionConfig.start(sessionId, q, {
|
|
1197
|
+
config = await SessionConfig.start(sessionId, q, { ...startMode, startedIn: mode }, models.models, models.modelInfos, models.currentModelInfo, {
|
|
1160
1198
|
fastMode: {
|
|
1161
1199
|
state: initialization.fast_mode_state,
|
|
1162
1200
|
disabledReason: initialization.fast_mode_disabled_reason,
|
|
@@ -1171,6 +1209,11 @@ class V2Agent {
|
|
|
1171
1209
|
catch (error) {
|
|
1172
1210
|
q.close();
|
|
1173
1211
|
settings.dispose();
|
|
1212
|
+
// A live session under this id keeps its entries.
|
|
1213
|
+
if (!this.sessions.has(sessionId)) {
|
|
1214
|
+
this.auth.sessionEnded(sessionId);
|
|
1215
|
+
this.guard.sessionEnded(sessionId);
|
|
1216
|
+
}
|
|
1174
1217
|
throw error;
|
|
1175
1218
|
}
|
|
1176
1219
|
return {
|
package/dist/v2/commands.d.ts
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
*
|
|
12
12
|
* `/mcp` is served as on v1 (`runMcpCommand`): Claude Code runs the command,
|
|
13
13
|
* and the adapter's server list replaces Claude Code's text in the turn's
|
|
14
|
-
* output.
|
|
14
|
+
* output. Once that text is sent, a reconnect starts OAuth for the servers
|
|
15
|
+
* that it tried and that need it.
|
|
15
16
|
*/
|
|
16
17
|
import type { ContentBlock } from "@agentclientprotocol/sdk/unstable";
|
|
17
18
|
import type * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
@@ -39,9 +40,13 @@ export declare class SessionCommands {
|
|
|
39
40
|
/**
|
|
40
41
|
* The text that replaces Claude Code's `output` of `command`, or `output`
|
|
41
42
|
* when the adapter cannot build it (a status read failed, or `signal`
|
|
42
|
-
* aborted).
|
|
43
|
+
* aborted). `reconnected` names the MCP servers that a reconnect tried, and is
|
|
44
|
+
* empty when `text` is `output`.
|
|
43
45
|
*/
|
|
44
|
-
replace(query: Parameters<typeof runMcpCommand>[0], command: McpCommand, output: string, signal: AbortSignal, logError: (message: string) => void): Promise<
|
|
46
|
+
replace(query: Parameters<typeof runMcpCommand>[0], command: McpCommand, output: string, signal: AbortSignal, logError: (message: string) => void): Promise<{
|
|
47
|
+
text: string;
|
|
48
|
+
reconnected: string[];
|
|
49
|
+
}>;
|
|
45
50
|
private render;
|
|
46
51
|
}
|
|
47
52
|
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/v2/commands.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/v2/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE5F,OAAO,EAAmB,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpF,qBAAa,eAAe;IAKxB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,aAAa;IALhC,4EAA4E;IAC5E,OAAO,CAAC,gBAAgB,CAAuB;gBAG5B,KAAK,EAAE,KAAK,EACZ,aAAa,UAAQ;IAGxC,0CAA0C;IACpC,IAAI,IAAI,OAAO,CAAC,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAI5C,gFAAgF;IAChF,OAAO,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,aAAa;IAInD;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;IASxC,sEAAsE;IACtE,QAAQ,IAAI,SAAS,MAAM,EAAE,GAAG,SAAS;IAIzC,yDAAyD;IACzD,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,GAAG,SAAS;IAM5D;;;;;OAKG;IACG,OAAO,CACX,KAAK,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,EAC1C,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAKnD,OAAO,CAAC,MAAM;CAaf"}
|
package/dist/v2/commands.js
CHANGED
|
@@ -44,11 +44,12 @@ export class SessionCommands {
|
|
|
44
44
|
/**
|
|
45
45
|
* The text that replaces Claude Code's `output` of `command`, or `output`
|
|
46
46
|
* when the adapter cannot build it (a status read failed, or `signal`
|
|
47
|
-
* aborted).
|
|
47
|
+
* aborted). `reconnected` names the MCP servers that a reconnect tried, and is
|
|
48
|
+
* empty when `text` is `output`.
|
|
48
49
|
*/
|
|
49
50
|
async replace(query, command, output, signal, logError) {
|
|
50
|
-
const { markdown } = await runMcpCommand(query, command, output, signal, logError);
|
|
51
|
-
return markdown
|
|
51
|
+
const { markdown, reconnected } = await runMcpCommand(query, command, output, signal, logError);
|
|
52
|
+
return markdown === null ? { text: output, reconnected: [] } : { text: markdown, reconnected };
|
|
52
53
|
}
|
|
53
54
|
render(commands) {
|
|
54
55
|
return v2AvailableCommands(getAvailableSlashCommands(commands, this.terminalCommands, undefined, undefined, this.query, undefined, this.remoteSession));
|
package/dist/v2/config.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ import type { Logger } from "../logger.js";
|
|
|
34
34
|
import type { SubagentModels } from "../native-subagents.js";
|
|
35
35
|
import { type FastModeReport } from "../session-fast-mode.js";
|
|
36
36
|
import { type SessionModelState } from "../session-model.js";
|
|
37
|
-
import { type
|
|
37
|
+
import { type StartMode } from "../session-mode.js";
|
|
38
38
|
type ConfigQuery = Pick<Query, "setPermissionMode" | "setModel" | "applyFlagSettings" | "supportedAgents">;
|
|
39
39
|
/** What a session starts with besides its mode and models (see {@link SessionConfig.start}). */
|
|
40
40
|
export interface ConfigSetup {
|
|
@@ -96,10 +96,11 @@ export declare class SessionConfig {
|
|
|
96
96
|
* without one. The client's `effort` pins the effort when the model offers
|
|
97
97
|
* it.
|
|
98
98
|
*/
|
|
99
|
-
static start(sessionId: string, query: ConfigQuery & Query,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
static start(sessionId: string, query: ConfigQuery & Query,
|
|
100
|
+
/** The start mode, and the mode that the query was started in. */
|
|
101
|
+
mode: StartMode & {
|
|
102
|
+
startedIn: PermissionMode;
|
|
103
|
+
}, models: SessionModelState, modelInfos: ModelInfo[], currentModelInfo: ModelInfo | undefined, setup: ConfigSetup, notify: (notification: SessionNotification) => void, logger: Logger): Promise<SessionConfig>;
|
|
103
104
|
/** The options, in v2 form. */
|
|
104
105
|
options(): v2.SessionConfigOption[];
|
|
105
106
|
/** The entries of the `model` option, for the `model` of a subagent's session. */
|
|
@@ -148,9 +149,9 @@ export declare class SessionConfig {
|
|
|
148
149
|
*/
|
|
149
150
|
private apply;
|
|
150
151
|
/**
|
|
151
|
-
* Sets the mode `requested` on the query, and records
|
|
152
|
-
*
|
|
153
|
-
* notice.
|
|
152
|
+
* Sets the mode `requested` on the query, and records the mode that Claude
|
|
153
|
+
* Code then names as in effect (see `SessionModeManager.setQueryMode`):
|
|
154
|
+
* `auto` that the model cannot serve runs as its fallback, with a notice.
|
|
154
155
|
*/
|
|
155
156
|
enterMode(requested: PermissionMode): Promise<void>;
|
|
156
157
|
/** The mode that `requested` runs as on the current model (see the module doc). */
|
package/dist/v2/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/v2/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACzB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,EAEV,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,KAAK,EACL,QAAQ,EACT,MAAM,gCAAgC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mFAAmF;IACnF,aAAa,CAAC,SAAS,EAAE,cAAc,GAAG,cAAc;YAI1C,SAAS;IAOvB,sFAAsF;YACxE,cAAc;IAK5B,gFAAgF;IAChF,WAAW,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO;IAQ1C;;;;OAIG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS9C;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO;IA0B1E;;;OAGG;IACG,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAS5E;;;;OAIG;YACW,WAAW;IASzB;;;OAGG;YACW,WAAW;IAMzB;;;;OAIG;YACW,YAAY;IAM1B,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,eAAe;IAQvB;;;;;;OAMG;YACW,WAAW;CA4D1B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,mBAAmB,CAmBtF"}
|
package/dist/v2/config.js
CHANGED
|
@@ -36,7 +36,8 @@ import { applyFastModeFlag, createFastModeConfigOption, FAST_MODE_CONFIG_ID, fas
|
|
|
36
36
|
import { MODEL_CONFIG_ID, modelDisplayName, modelEntryFor, resolveModelPreference, } from "../session-model.js";
|
|
37
37
|
import { MODE_CONFIG_ID, SessionModeManager, } from "../session-mode.js";
|
|
38
38
|
import { noticeUpdate } from "../session-notices.js";
|
|
39
|
-
import { createUltracodeConfigOption,
|
|
39
|
+
import { createUltracodeConfigOption, readSettingsReport, ultracodeSupported, ultracodeWorkflowsEnabled, } from "../session-ultracode.js";
|
|
40
|
+
import { rejectSkippedSettings } from "../startup-failure.js";
|
|
40
41
|
import { v1SetSessionConfigOptionRequest, v2ConfigOptions } from "./session-requests.js";
|
|
41
42
|
/** Every v2 client takes boolean config options. */
|
|
42
43
|
const BOOLEAN_OPTIONS = true;
|
|
@@ -116,7 +117,9 @@ export class SessionConfig {
|
|
|
116
117
|
* without one. The client's `effort` pins the effort when the model offers
|
|
117
118
|
* it.
|
|
118
119
|
*/
|
|
119
|
-
static async start(sessionId, query,
|
|
120
|
+
static async start(sessionId, query,
|
|
121
|
+
/** The start mode, and the mode that the query was started in. */
|
|
122
|
+
mode, models, modelInfos, currentModelInfo, setup, notify, logger) {
|
|
120
123
|
const rules = new SessionModeManager({
|
|
121
124
|
getSession: () => undefined,
|
|
122
125
|
sessionEndedMessage: "",
|
|
@@ -128,6 +131,7 @@ export class SessionConfig {
|
|
|
128
131
|
query,
|
|
129
132
|
requestedMode: mode.mode,
|
|
130
133
|
builtInDefault: mode.builtInDefault,
|
|
134
|
+
startedIn: mode.startedIn,
|
|
131
135
|
currentModelInfo,
|
|
132
136
|
currentModelId: models.currentModelId,
|
|
133
137
|
allowBypass: mode.allowBypass,
|
|
@@ -145,7 +149,8 @@ export class SessionConfig {
|
|
|
145
149
|
? undefined
|
|
146
150
|
: normalizeFastModeDisabledReason(setup.fastMode.disabledReason);
|
|
147
151
|
const settings = setup.effortSettings();
|
|
148
|
-
const ultracodeReport = await
|
|
152
|
+
const { ultracode: ultracodeReport, settingsErrors } = await readSettingsReport(query);
|
|
153
|
+
rejectSkippedSettings(settingsErrors);
|
|
149
154
|
const ultracodeEnabled = ultracodeReport?.requested ?? settings.ultracode === true;
|
|
150
155
|
const workflowsEnabled = ultracodeWorkflowsEnabled(ultracodeReport, currentModelInfo);
|
|
151
156
|
const clientEffort = setup.client?.effort;
|
|
@@ -340,9 +345,9 @@ export class SessionConfig {
|
|
|
340
345
|
}
|
|
341
346
|
}
|
|
342
347
|
/**
|
|
343
|
-
* Sets the mode `requested` on the query, and records
|
|
344
|
-
*
|
|
345
|
-
* notice.
|
|
348
|
+
* Sets the mode `requested` on the query, and records the mode that Claude
|
|
349
|
+
* Code then names as in effect (see `SessionModeManager.setQueryMode`):
|
|
350
|
+
* `auto` that the model cannot serve runs as its fallback, with a notice.
|
|
346
351
|
*/
|
|
347
352
|
enterMode(requested) {
|
|
348
353
|
return this.serialized(() => this.applyMode(requested));
|
|
@@ -352,10 +357,10 @@ export class SessionConfig {
|
|
|
352
357
|
return this.rules.effectiveMode(this.session, requested);
|
|
353
358
|
}
|
|
354
359
|
async applyMode(requested, duringSetup = false) {
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
this.rules.syncConfig(this.session,
|
|
358
|
-
if (
|
|
360
|
+
const asked = this.rules.effectiveMode(this.session, requested);
|
|
361
|
+
// The mode that Claude Code names in its answer, not always the one asked for.
|
|
362
|
+
this.rules.syncConfig(this.session, await this.rules.setQueryMode(this.session, asked));
|
|
363
|
+
if (asked !== requested)
|
|
359
364
|
await this.warnOfFallback(duringSetup);
|
|
360
365
|
}
|
|
361
366
|
/** The notice of an Auto mode fallback: now, or with the next prompt during setup. */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as v2 from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
2
|
+
import type { Logger } from "../logger.js";
|
|
3
|
+
import { type SessionReadFrame } from "../session-read.js";
|
|
4
|
+
/** Renders a stored history without the connection's live tool calls or child sessions. */
|
|
5
|
+
export declare function renderSessionRead(sessionId: string, dir: string | undefined, logger: Logger, capabilities: v2.ClientCapabilities | null | undefined): Promise<{
|
|
6
|
+
frames: SessionReadFrame[];
|
|
7
|
+
cwd: string;
|
|
8
|
+
historyEnd: number;
|
|
9
|
+
title?: string;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=session-read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-read.d.ts","sourceRoot":"","sources":["../../src/v2/session-read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAyB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAMlF,2FAA2F;AAC3F,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,EAAE,CAAC,kBAAkB,GAAG,IAAI,GAAG,SAAS,GACrD,OAAO,CAAC;IAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA+B1F"}
|