@zvada/agent-server 0.3.25 → 0.3.27
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/CHANGELOG.md +113 -0
- package/README.md +4 -1
- package/dist/client/client.js +27 -11
- package/dist/client/connection.js +35 -3
- package/dist/core/agents/acp/acp-agent.js +91 -14
- package/dist/core/agents/acp/mappings.js +5 -1
- package/dist/core/agents/claude-code/approvals.js +3 -2
- package/dist/core/agents/claude-code/claude-agent.js +12 -2
- package/dist/core/agents/claude-code/mcp.js +9 -1
- package/dist/core/agents/claude-code/models.js +16 -10
- package/dist/core/agents/claude-code/options.js +23 -2
- package/dist/core/agents/claude-code/session.js +21 -1
- package/dist/core/agents/claude-code/tools.js +9 -4
- package/dist/core/agents/claude-code/turn.js +2 -0
- package/dist/core/agents/codex-app-server/adapter.js +2 -0
- package/dist/core/agents/codex-app-server/client.js +8 -5
- package/dist/core/agents/codex-app-server/codex-agent.js +35 -2
- package/dist/core/agents/codex-app-server/effort.js +13 -6
- package/dist/core/agents/codex-app-server/mcp.js +35 -18
- package/dist/core/agents/codex-app-server/models.js +10 -10
- package/dist/core/agents/codex-app-server/options.js +11 -2
- package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
- package/dist/core/agents/codex-app-server/session.js +11 -4
- package/dist/core/agents/codex-app-server/thread-settings.js +30 -11
- package/dist/core/agents/host-tools.js +493 -0
- package/dist/core/agents/mcp-config.js +6 -2
- package/dist/core/agents/scripted/scripted-agent.js +39 -6
- package/dist/core/agents/scripted/steps.js +5 -1
- package/dist/core/agents/session-agent.js +70 -2
- package/dist/core/agents/thinking-levels.js +8 -5
- package/dist/core/index.js +1 -0
- package/dist/core/presets.js +16 -3
- package/dist/core/processes/lifeline.js +9 -5
- package/dist/core/provision/pins.js +7 -16
- package/dist/core/provision/releases.js +25 -25
- package/dist/core/proxy/loopback.js +22 -4
- package/dist/core/runtime/agent-runtime.js +15 -5
- package/dist/core/runtime/event-processor.js +13 -8
- package/dist/core/runtime/origin-line.js +42 -0
- package/dist/core/runtime/request-broker.js +2 -1
- package/dist/core/runtime/steering.js +4 -3
- package/dist/core/runtime/turn.js +6 -4
- package/dist/operator/errors.js +97 -0
- package/dist/operator/index.js +10 -5
- package/dist/operator/mcp.js +7 -12
- package/dist/operator/operator.js +1336 -380
- package/dist/operator/refs.js +59 -0
- package/dist/operator/render.js +171 -74
- package/dist/operator/session-tools.js +87 -0
- package/dist/operator/types.js +30 -0
- package/dist/operator/view.js +82 -27
- package/dist/protocol/config.js +33 -6
- package/dist/protocol/conversation.js +3 -0
- package/dist/protocol/history.js +2 -1
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/lifecycle.js +19 -0
- package/dist/protocol/model-catalog.js +58 -18
- package/dist/protocol/models.js +6 -27
- package/dist/protocol/origin.js +39 -0
- package/dist/protocol/reduce.js +2 -0
- package/dist/protocol/thinking.js +22 -9
- package/dist/protocol/wire-api.js +2 -2
- package/dist/protocol/wire.js +17 -0
- package/dist/server/bin.js +6 -4
- package/dist/server/routes.js +15 -5
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/connection.d.ts +14 -2
- package/dist/types/client/connection.d.ts.map +1 -1
- package/dist/types/client/turns.d.ts +2 -2
- package/dist/types/client/turns.d.ts.map +1 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts +15 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/mappings.d.ts +5 -1
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
- package/dist/types/core/agents/acp/requests.d.ts +2 -0
- package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
- package/dist/types/core/agents/base.d.ts +2 -0
- package/dist/types/core/agents/base.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts +2 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/mcp.d.ts +8 -1
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/models.d.ts +9 -5
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/options.d.ts +10 -1
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/session.d.ts +2 -0
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/turn.d.ts +3 -0
- package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/client.d.ts +2 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +11 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts +7 -7
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +11 -3
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/models.d.ts +4 -1
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/options.d.ts +9 -2
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/requests.d.ts +2 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/session.d.ts +6 -3
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
- package/dist/types/core/agents/host-tools.d.ts +162 -0
- package/dist/types/core/agents/host-tools.d.ts.map +1 -0
- package/dist/types/core/agents/mcp-config.d.ts +11 -2
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
- package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
- package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
- package/dist/types/core/agents/scripted/steps.d.ts.map +1 -1
- package/dist/types/core/agents/session-agent.d.ts +2 -7
- package/dist/types/core/agents/session-agent.d.ts.map +1 -1
- package/dist/types/core/agents/thinking-levels.d.ts +7 -3
- package/dist/types/core/agents/thinking-levels.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/presets.d.ts +11 -1
- package/dist/types/core/presets.d.ts.map +1 -1
- package/dist/types/core/processes/lifeline.d.ts.map +1 -1
- package/dist/types/core/provision/pins.d.ts +5 -4
- package/dist/types/core/provision/pins.d.ts.map +1 -1
- package/dist/types/core/proxy/loopback.d.ts.map +1 -1
- package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/types/core/runtime/event-processor.d.ts +2 -2
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/core/runtime/origin-line.d.ts +15 -0
- package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
- package/dist/types/core/runtime/request-broker.d.ts +1 -1
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
- package/dist/types/core/runtime/steering.d.ts +7 -4
- package/dist/types/core/runtime/steering.d.ts.map +1 -1
- package/dist/types/core/runtime/turn.d.ts.map +1 -1
- package/dist/types/operator/errors.d.ts +83 -0
- package/dist/types/operator/errors.d.ts.map +1 -0
- package/dist/types/operator/index.d.ts +10 -5
- package/dist/types/operator/index.d.ts.map +1 -1
- package/dist/types/operator/mcp.d.ts +1 -1
- package/dist/types/operator/mcp.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts +15 -197
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/refs.d.ts +25 -0
- package/dist/types/operator/refs.d.ts.map +1 -0
- package/dist/types/operator/render.d.ts +59 -19
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/operator/session-tools.d.ts +61 -0
- package/dist/types/operator/session-tools.d.ts.map +1 -0
- package/dist/types/operator/types.d.ts +441 -0
- package/dist/types/operator/types.d.ts.map +1 -0
- package/dist/types/operator/view.d.ts +19 -29
- package/dist/types/operator/view.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +32 -24
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +48 -39
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/execution.d.ts +2 -18
- package/dist/types/protocol/execution.d.ts.map +1 -1
- package/dist/types/protocol/history.d.ts +1 -1
- package/dist/types/protocol/history.d.ts.map +1 -1
- package/dist/types/protocol/index.d.ts +1 -0
- package/dist/types/protocol/index.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +48 -74
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/model-catalog.d.ts.map +1 -1
- package/dist/types/protocol/models.d.ts +4 -42
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/origin.d.ts +49 -0
- package/dist/types/protocol/origin.d.ts.map +1 -0
- package/dist/types/protocol/reduce.d.ts.map +1 -1
- package/dist/types/protocol/thinking.d.ts +19 -19
- package/dist/types/protocol/thinking.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +59 -106
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +81 -119
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/dist/types/server/routes.d.ts.map +1 -1
- package/docs/consuming.md +124 -132
- package/docs/deploy.md +6 -5
- package/docs/harnesses.md +79 -31
- package/docs/sync-history.md +2 -1
- package/package.json +4 -4
- package/src/client/client.ts +36 -9
- package/src/client/connection.ts +31 -1
- package/src/client/turns.ts +2 -1
- package/src/core/agents/acp/acp-agent.ts +123 -17
- package/src/core/agents/acp/mappings.ts +5 -1
- package/src/core/agents/acp/requests.ts +2 -0
- package/src/core/agents/base.ts +2 -0
- package/src/core/agents/claude-code/approvals.ts +4 -3
- package/src/core/agents/claude-code/claude-agent.ts +14 -2
- package/src/core/agents/claude-code/mcp.ts +11 -1
- package/src/core/agents/claude-code/models.ts +15 -10
- package/src/core/agents/claude-code/options.ts +33 -3
- package/src/core/agents/claude-code/session.ts +26 -1
- package/src/core/agents/claude-code/tools.ts +10 -4
- package/src/core/agents/claude-code/turn.ts +4 -0
- package/src/core/agents/codex-app-server/adapter.ts +2 -0
- package/src/core/agents/codex-app-server/client.ts +11 -5
- package/src/core/agents/codex-app-server/codex-agent.ts +45 -1
- package/src/core/agents/codex-app-server/effort.ts +15 -20
- package/src/core/agents/codex-app-server/mcp.ts +46 -23
- package/src/core/agents/codex-app-server/models.ts +10 -10
- package/src/core/agents/codex-app-server/options.ts +16 -2
- package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
- package/src/core/agents/codex-app-server/requests.ts +2 -0
- package/src/core/agents/codex-app-server/session.ts +19 -4
- package/src/core/agents/codex-app-server/thread-settings.ts +31 -11
- package/src/core/agents/host-tools.ts +649 -0
- package/src/core/agents/mcp-config.ts +15 -3
- package/src/core/agents/scripted/scripted-agent.ts +51 -5
- package/src/core/agents/scripted/steps.ts +5 -1
- package/src/core/agents/session-agent.ts +78 -2
- package/src/core/agents/thinking-levels.ts +9 -6
- package/src/core/index.ts +9 -0
- package/src/core/presets.ts +28 -4
- package/src/core/processes/lifeline.ts +9 -5
- package/src/core/provision/pins.ts +7 -16
- package/src/core/provision/releases.ts +25 -25
- package/src/core/proxy/loopback.ts +25 -4
- package/src/core/runtime/agent-runtime.ts +31 -7
- package/src/core/runtime/event-processor.ts +13 -6
- package/src/core/runtime/origin-line.ts +43 -0
- package/src/core/runtime/request-broker.ts +2 -0
- package/src/core/runtime/steering.ts +8 -4
- package/src/core/runtime/turn.ts +11 -4
- package/src/operator/errors.ts +218 -0
- package/src/operator/index.ts +18 -23
- package/src/operator/mcp.ts +7 -16
- package/src/operator/operator.ts +1583 -613
- package/src/operator/refs.ts +75 -0
- package/src/operator/render.ts +208 -98
- package/src/operator/session-tools.ts +126 -0
- package/src/operator/types.ts +505 -0
- package/src/operator/view.ts +93 -42
- package/src/protocol/config.ts +36 -7
- package/src/protocol/conversation.ts +3 -0
- package/src/protocol/history.ts +2 -1
- package/src/protocol/index.ts +1 -0
- package/src/protocol/lifecycle.ts +21 -0
- package/src/protocol/model-catalog.ts +58 -18
- package/src/protocol/models.ts +6 -26
- package/src/protocol/origin.ts +47 -0
- package/src/protocol/reduce.ts +4 -0
- package/src/protocol/thinking.ts +27 -14
- package/src/protocol/wire-api.ts +2 -2
- package/src/protocol/wire.ts +18 -0
- package/src/server/bin.ts +6 -4
- package/src/server/routes.ts +16 -5
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "../../../protocol/index.ts";
|
|
8
8
|
import type { NativeProcesses } from "../../processes/native-processes.ts";
|
|
9
9
|
import { onAbort } from "../../utils/deadline.ts";
|
|
10
|
-
import {
|
|
10
|
+
import { listedThinkingLevels } from "../thinking-levels.ts";
|
|
11
11
|
import { type ClaudeSessionConfig, buildClaudeOptions } from "./options.ts";
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -26,7 +26,7 @@ export function claudeModelDescriptors(models: readonly ClaudeModelInfo[]): Mode
|
|
|
26
26
|
...(model.resolvedModel &&
|
|
27
27
|
model.resolvedModel !== model.value && { resolvedId: model.resolvedModel }),
|
|
28
28
|
...(model.value === "default" && { isDefault: true }),
|
|
29
|
-
thinking: { levels:
|
|
29
|
+
thinking: { levels: listedThinkingLevels(model.supportedEffortLevels ?? []) },
|
|
30
30
|
}));
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -35,20 +35,25 @@ export function claudeModelDescriptors(models: readonly ClaudeModelInfo[]): Mode
|
|
|
35
35
|
* lowers a level its model lacks on its own and does not say so (`max` and
|
|
36
36
|
* `xhigh` become `high`), so the level is fitted here, where the model's levels
|
|
37
37
|
* are known. `off` is sent as it is: some models do not let thinking be
|
|
38
|
-
* disabled
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
38
|
+
* disabled (Haiku 5.5 at `off` still spends thinking tokens, with an empty
|
|
39
|
+
* reasoning part, on Claude Code 2.1.327); Haiku 4.5, which Claude Code
|
|
40
|
+
* otherwise starts thinking, does not think with it. A model known to have no
|
|
41
|
+
* effort levels (`levels: []`, Haiku 4.5) is sent no other level, so it is not
|
|
42
|
+
* started on adaptive thinking at an effort it has no control for: it thinks
|
|
43
|
+
* at its own default, as Claude Code starts it. Neither is a model sent a
|
|
44
|
+
* level that has no fit among the levels it lists. A model whose levels are
|
|
45
|
+
* unknown (`undefined`) is sent the level as asked, but `ultra` as `max`,
|
|
46
|
+
* Claude's ceiling; a model that lists `ultra` is sent it.
|
|
43
47
|
*/
|
|
44
48
|
export function fitClaudeThinking(
|
|
45
49
|
level: ThinkingLevel | undefined,
|
|
46
50
|
levels: readonly ThinkingLevel[] | undefined,
|
|
47
51
|
): { send?: ThinkingLevel; applied?: ThinkingLevel } {
|
|
48
52
|
if (level === undefined) return {};
|
|
49
|
-
if (level === "off"
|
|
50
|
-
if (
|
|
51
|
-
const fitted = clampThinkingLevel(level, levels)
|
|
53
|
+
if (level === "off") return { send: level };
|
|
54
|
+
if (levels === undefined) return { send: level === "ultra" ? "max" : level };
|
|
55
|
+
const fitted = clampThinkingLevel(level, levels);
|
|
56
|
+
if (fitted === undefined) return {};
|
|
52
57
|
return { send: fitted, applied: fitted };
|
|
53
58
|
}
|
|
54
59
|
|
|
@@ -11,6 +11,7 @@ import type { NativeProcesses } from "../../processes/native-processes.ts";
|
|
|
11
11
|
import type { AgentExecuteOptions } from "../base.ts";
|
|
12
12
|
import { configFingerprint, directoriesFingerprint } from "../config-fingerprint.ts";
|
|
13
13
|
import type { CredentialSource } from "../credentials.ts";
|
|
14
|
+
import type { HostToolSessions, HostTools } from "../host-tools.ts";
|
|
14
15
|
import type { InheritConfig } from "../inherit-config.ts";
|
|
15
16
|
import { type ClaudeSpawn, claudeSpawner } from "./spawn.ts";
|
|
16
17
|
|
|
@@ -52,7 +53,8 @@ export type ClaudeSdkOptionOverrides = Partial<
|
|
|
52
53
|
* asks about, questions (AskUserQuestion) and plan approvals (ExitPlanMode)
|
|
53
54
|
* included, BEFORE the interactive permission broker and elicitation. Claude
|
|
54
55
|
* asks about a call its mode and rules do not approve by themselves: under
|
|
55
|
-
* `bypass_permissions`,
|
|
56
|
+
* `bypass_permissions`, questions, plans and, since Claude Code 2.1.326, the
|
|
57
|
+
* few calls it holds back as dangerous. Returns the SDK's own
|
|
56
58
|
* `PermissionResult` (so hosts keep full native power: `updatedInput`,
|
|
57
59
|
* `updatedPermissions`) or undefined to fall through to the broker.
|
|
58
60
|
* Operator embed-tier only — never wire-sourced.
|
|
@@ -137,6 +139,11 @@ export interface ClaudeCodeAgentOptions {
|
|
|
137
139
|
* wire-configured servers.
|
|
138
140
|
*/
|
|
139
141
|
sdkMcpServers?: (ctx: SessionSpawn) => SdkMcpServers | Promise<SdkMcpServers>;
|
|
142
|
+
/**
|
|
143
|
+
* The host's tools for each session (LLP 0018), run in process: no secret,
|
|
144
|
+
* no HTTP. A turn's own server may not take their name. Operator-level only.
|
|
145
|
+
*/
|
|
146
|
+
hostTools?: HostTools;
|
|
140
147
|
/**
|
|
141
148
|
* Pre-broker tool policy (SDK PermissionResult or undefined = fall through
|
|
142
149
|
* to the interactive broker). Operator embed-tier only.
|
|
@@ -200,6 +207,8 @@ export type ClaudeSessionSettings = ClaudeSessionExtras &
|
|
|
200
207
|
Pick<ClaudeCodeAgentOptions, "idleTimeoutMs" | "cancelConfirmMs"> & {
|
|
201
208
|
/** The agent's: where its sessions' `claude` processes start. */
|
|
202
209
|
processes: NativeProcesses;
|
|
210
|
+
/** The agent's: its sessions' host tools. */
|
|
211
|
+
host?: HostToolSessions;
|
|
203
212
|
};
|
|
204
213
|
|
|
205
214
|
/** What a turn asks of the Claude session it runs on. */
|
|
@@ -396,6 +405,11 @@ function buildEnv(
|
|
|
396
405
|
};
|
|
397
406
|
}
|
|
398
407
|
|
|
408
|
+
/** Whether Claude Code reads a flag as on: `1`, `true`, `yes` or `on`, in any case (2.1.327). */
|
|
409
|
+
function envFlagOn(value: string | undefined): boolean {
|
|
410
|
+
return ["1", "true", "yes", "on"].includes((value ?? "").trim().toLowerCase());
|
|
411
|
+
}
|
|
412
|
+
|
|
399
413
|
/** The environment Claude Code runs a turn with this `env` in, which decides whose login it runs on. */
|
|
400
414
|
export function claudeEnv(
|
|
401
415
|
config: Pick<ClaudeSessionConfig, "env" | "inheritConfig">,
|
|
@@ -444,8 +458,10 @@ export function buildClaudeOptions(
|
|
|
444
458
|
options.thinking = { type: "disabled" };
|
|
445
459
|
} else {
|
|
446
460
|
options.thinking = { type: "adaptive" };
|
|
447
|
-
//
|
|
448
|
-
|
|
461
|
+
// The level as `fitClaudeThinking` gave it. The SDK types `effort` as
|
|
462
|
+
// the levels it knows; one beyond them (a level the model lists, or
|
|
463
|
+
// any when its levels are unknown) goes to the CLI as it is named.
|
|
464
|
+
options.effort = config.thinkingLevel as CCOptions["effort"];
|
|
449
465
|
}
|
|
450
466
|
}
|
|
451
467
|
if (config.resumeSessionId) {
|
|
@@ -466,7 +482,21 @@ export function buildClaudeOptions(
|
|
|
466
482
|
// this function returns, so those can never be clobbered (and the
|
|
467
483
|
// ClaudeSdkOptionOverrides type excludes them anyway).
|
|
468
484
|
if (overrides) Object.assign(options, overrides);
|
|
485
|
+
// @ref LLP 0001#d4--permission-requests-are-first-class-protocol — plan mode asks through the broker
|
|
486
|
+
// On a model with auto mode, plan mode takes auto mode's semantics: calls run that the broker
|
|
487
|
+
// never sees. Off beneath the operator's own settings object; a path, or `extraArgs.settings`, stays theirs.
|
|
488
|
+
if (typeof options.settings !== "string" && options.extraArgs?.settings === undefined)
|
|
489
|
+
options.settings = { useAutoModeDuringPlan: false, ...options.settings };
|
|
469
490
|
if (config.subagentMode === "turn") options.forwardSubagentText = true;
|
|
491
|
+
// @ref LLP 0001#d14--nothing-the-agent-does-is-off-the-stream — a watch outlives its turn
|
|
492
|
+
// Claude Code 2.1.327 offers `Monitor` with background tasks off: its watch
|
|
493
|
+
// runs past the turn and Claude answers each line with a query of its own,
|
|
494
|
+
// which no turn shows. With background tasks off it is off too, beside the
|
|
495
|
+
// operator's own denials; an env that turns them on leaves it alone.
|
|
496
|
+
if (envFlagOn(options.env?.CLAUDE_CODE_DISABLE_BACKGROUND_TASKS)) {
|
|
497
|
+
const denied = options.disallowedTools ?? [];
|
|
498
|
+
if (!denied.includes("Monitor")) options.disallowedTools = [...denied, "Monitor"];
|
|
499
|
+
}
|
|
470
500
|
// Engine wiring over the operator's: their spawner still runs, as theirs.
|
|
471
501
|
if (spawn)
|
|
472
502
|
options.spawnClaudeCodeProcess = claudeSpawner(
|
|
@@ -14,6 +14,7 @@ import type { NativeProcess } from "../../processes/native-processes.ts";
|
|
|
14
14
|
import { onAbort, untilAborted, withTimeout } from "../../utils/deadline.ts";
|
|
15
15
|
import { SessionResumeError } from "../../utils/errors.ts";
|
|
16
16
|
import { CANCEL_CONFIRM_MS } from "../base.ts";
|
|
17
|
+
import type { LiveTurn } from "../host-tools.ts";
|
|
17
18
|
import {
|
|
18
19
|
IDLE_TIMEOUT_MS,
|
|
19
20
|
type PooledClient,
|
|
@@ -30,6 +31,7 @@ import {
|
|
|
30
31
|
type ClaudeSessionConfig,
|
|
31
32
|
type ClaudeSessionEndReason,
|
|
32
33
|
type ClaudeSessionSettings,
|
|
34
|
+
type SdkMcpServers,
|
|
33
35
|
buildClaudeOptions,
|
|
34
36
|
claudeSpawnKey,
|
|
35
37
|
fromSdkPermissionMode,
|
|
@@ -217,11 +219,27 @@ export class ClaudeSession implements PooledProcess, PooledClient {
|
|
|
217
219
|
return true;
|
|
218
220
|
}
|
|
219
221
|
|
|
222
|
+
/** The turn running now and the mode the process runs in, for a host tool's caller. */
|
|
223
|
+
private liveTurn(): ReturnType<LiveTurn> {
|
|
224
|
+
return this.turn
|
|
225
|
+
? {
|
|
226
|
+
turnId: this.turn.id,
|
|
227
|
+
permissionMode: this.config.permissionMode ?? "default",
|
|
228
|
+
signal: this.turn.signal,
|
|
229
|
+
}
|
|
230
|
+
: undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
220
233
|
async start(): Promise<void> {
|
|
221
234
|
if (this.state !== "starting") throw new Error(`Cannot start in state: ${this.state}`);
|
|
222
235
|
const sdk = await import("@anthropic-ai/claude-agent-sdk");
|
|
223
236
|
const spawn = { sessionId: this.id, cwd: this.config.cwd };
|
|
224
|
-
const
|
|
237
|
+
const source = await this.settings.host?.source(this.id, this.config.cwd);
|
|
238
|
+
const hostServers: SdkMcpServers = { ...(await this.settings.sdkMcpServers?.(spawn)) };
|
|
239
|
+
if (source && this.settings.host)
|
|
240
|
+
hostServers[source.name] = this.settings.host.inProcess(this.id, source, () =>
|
|
241
|
+
this.liveTurn(),
|
|
242
|
+
) as unknown as SdkMcpServers[string];
|
|
225
243
|
this.mcp.useHostServers(hostServers);
|
|
226
244
|
const overrides = await this.settings.sdkOptions?.(spawn);
|
|
227
245
|
this.thinkingOverridden = Boolean(
|
|
@@ -234,6 +252,13 @@ export class ClaudeSession implements PooledProcess, PooledClient {
|
|
|
234
252
|
this.native = native;
|
|
235
253
|
},
|
|
236
254
|
});
|
|
255
|
+
// @ref LLP 0018#permissions — a read-only host tool runs unasked, as on Codex; any other asks
|
|
256
|
+
const readOnly = (source?.tools ?? []).filter((tool) => tool.annotations?.readOnly);
|
|
257
|
+
if (source && readOnly.length)
|
|
258
|
+
options.allowedTools = [
|
|
259
|
+
...(options.allowedTools ?? []),
|
|
260
|
+
...readOnly.map((tool) => `mcp__${source.name}__${tool.name}`),
|
|
261
|
+
];
|
|
237
262
|
if (this.settings.hooks) {
|
|
238
263
|
options.hooks = this.settings.hooks({
|
|
239
264
|
sessionId: this.id,
|
|
@@ -14,12 +14,14 @@ import type { McpTool, ToolKind, ToolLocation, ToolMeta } from "../../../protoco
|
|
|
14
14
|
* CLI offers that is not here, so a pin bump decides it.
|
|
15
15
|
*/
|
|
16
16
|
export const CLAUDE_TOOL_KINDS: ReadonlyMap<string, ToolKind> = new Map<string, ToolKind>([
|
|
17
|
-
// What the pinned CLI
|
|
17
|
+
// What the pinned CLI offers, with the engine's options or a product's.
|
|
18
18
|
["Read", "read"],
|
|
19
19
|
["Edit", "edit"],
|
|
20
20
|
["Write", "edit"],
|
|
21
21
|
["NotebookEdit", "edit"],
|
|
22
22
|
["Bash", "execute"],
|
|
23
|
+
// Runs a shell command and reports its output as it comes.
|
|
24
|
+
["Monitor", "execute"],
|
|
23
25
|
// Stops a background shell or sub-agent the agent started.
|
|
24
26
|
["TaskStop", "execute"],
|
|
25
27
|
// Runs a script the agent wrote, which starts sub-agents of its own.
|
|
@@ -28,6 +30,8 @@ export const CLAUDE_TOOL_KINDS: ReadonlyMap<string, ToolKind> = new Map<string,
|
|
|
28
30
|
["WebSearch", "fetch"],
|
|
29
31
|
// Loads a skill's instructions into the conversation.
|
|
30
32
|
["Skill", "read"],
|
|
33
|
+
// Loads the definition of a tool the CLI held back: nothing of the person's.
|
|
34
|
+
["ToolSearch", "other"],
|
|
31
35
|
// The sub-agent tool: `init` names it `Task`, the model `Agent`. A spawn is `task` by its subagent.
|
|
32
36
|
["Task", "think"],
|
|
33
37
|
["Agent", "think"],
|
|
@@ -77,8 +81,8 @@ function toolLocationsFromInput(input: Record<string, unknown>): ToolLocation[]
|
|
|
77
81
|
const MCP_PREFIX = "mcp__";
|
|
78
82
|
|
|
79
83
|
/**
|
|
80
|
-
* A server's name as Claude Code spells it in a tool name (the pinned CLI
|
|
81
|
-
* 2.1.288
|
|
84
|
+
* A server's name as Claude Code spells it in a tool name (the pinned CLI;
|
|
85
|
+
* 2.1.288 and 2.1.325 spell it alike, observed 2026-11-16):
|
|
82
86
|
* other than letters, digits, `_` and `-` become `_`, and a claude.ai
|
|
83
87
|
* connector's runs of `_` collapse.
|
|
84
88
|
*/
|
|
@@ -131,7 +135,9 @@ export function claudeToolMeta(
|
|
|
131
135
|
servers?: Iterable<string>,
|
|
132
136
|
): ToolMeta {
|
|
133
137
|
const mcp = claudeMcpTool(toolName, servers);
|
|
134
|
-
|
|
138
|
+
// A `Monitor` on a WebSocket has no command.
|
|
139
|
+
const command =
|
|
140
|
+
toolName === "Bash" || toolName === "Monitor" ? textOf(input, "command") : undefined;
|
|
135
141
|
const url = toolName === "WebFetch" ? textOf(input, "url") : undefined;
|
|
136
142
|
return {
|
|
137
143
|
kind: CLAUDE_TOOL_KINDS.get(toolName) ?? "other",
|
|
@@ -14,6 +14,8 @@ const STEER_QUERY_TIMEOUT_MS = 60_000;
|
|
|
14
14
|
/** What a turn starts with: its id, and the brokers its requests go to. */
|
|
15
15
|
export interface ClaudeTurnStart {
|
|
16
16
|
turnId: string;
|
|
17
|
+
/** The turn's cancel: a host tool's call under way ends with it. */
|
|
18
|
+
signal?: AbortSignal;
|
|
17
19
|
/**
|
|
18
20
|
* The engine's permission broker for this turn. Absent (a turn driven
|
|
19
21
|
* outside the runtime), Claude's permission mode alone decides.
|
|
@@ -35,6 +37,7 @@ export interface ClaudeTurnStart {
|
|
|
35
37
|
*/
|
|
36
38
|
export class ClaudeTurn {
|
|
37
39
|
readonly id: string;
|
|
40
|
+
readonly signal?: AbortSignal;
|
|
38
41
|
readonly permissions?: PermissionRequestHandler;
|
|
39
42
|
readonly elicitation?: ElicitationRequestHandler;
|
|
40
43
|
/** What the turn yields, until its result or its failure. */
|
|
@@ -71,6 +74,7 @@ export class ClaudeTurn {
|
|
|
71
74
|
|
|
72
75
|
constructor(start: ClaudeTurnStart, prompt: string) {
|
|
73
76
|
this.id = start.turnId;
|
|
77
|
+
this.signal = start.signal;
|
|
74
78
|
this.permissions = start.permissions;
|
|
75
79
|
this.elicitation = start.elicitation;
|
|
76
80
|
this.prompt = prompt;
|
|
@@ -493,6 +493,8 @@ export function codexErrorCategory(info: unknown): ErrorCategory | undefined {
|
|
|
493
493
|
case "unauthorized":
|
|
494
494
|
return "auth";
|
|
495
495
|
case "badRequest":
|
|
496
|
+
// A model the provider does not have, or the account cannot run.
|
|
497
|
+
case "modelNotFound":
|
|
496
498
|
return "invalid_request";
|
|
497
499
|
case "internalServerError":
|
|
498
500
|
return "internal";
|
|
@@ -123,6 +123,16 @@ export class CodexRpcError extends Error {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/** The `-c key=value` overrides the app-server starts with, for these options. */
|
|
127
|
+
export function configArgs(
|
|
128
|
+
opts: Pick<CodexAppServerClientOptions, "ephemeralCredentials" | "pluginsOff">,
|
|
129
|
+
): string[] {
|
|
130
|
+
return [
|
|
131
|
+
...(opts.ephemeralCredentials ? ["-c", 'cli_auth_credentials_store="ephemeral"'] : []),
|
|
132
|
+
...(opts.pluginsOff ? ["-c", "features.plugins=false"] : []),
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
|
|
126
136
|
export interface CodexAppServerClientOptions {
|
|
127
137
|
codexPath?: string;
|
|
128
138
|
cwd?: string;
|
|
@@ -324,11 +334,7 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
324
334
|
this.nativeShutdownFailed = false;
|
|
325
335
|
const native = this.opts.processes.spawn({
|
|
326
336
|
command: this.opts.codexPath ?? "codex",
|
|
327
|
-
args: [
|
|
328
|
-
"app-server",
|
|
329
|
-
...(this.opts.ephemeralCredentials ? ["-c", 'cli_auth_credentials_store="ephemeral"'] : []),
|
|
330
|
-
...(this.opts.pluginsOff ? ["-c", "features.plugins=false"] : []),
|
|
331
|
-
],
|
|
337
|
+
args: ["app-server", ...configArgs(this.opts)],
|
|
332
338
|
cwd: this.opts.cwd,
|
|
333
339
|
env: this.opts.env ?? process.env,
|
|
334
340
|
harness: "codex-app-server",
|
|
@@ -6,9 +6,16 @@ import type {
|
|
|
6
6
|
} from "../../../protocol/index.ts";
|
|
7
7
|
import { type NativeProcesses, sharedNativeProcesses } from "../../processes/native-processes.ts";
|
|
8
8
|
import { onAbort, untilAborted } from "../../utils/deadline.ts";
|
|
9
|
+
import { McpUnavailableError } from "../../utils/errors.ts";
|
|
9
10
|
import type { AgentExecuteOptions, ListModelsOptions, RawAgentEvent } from "../base.ts";
|
|
10
11
|
import { configFingerprint } from "../config-fingerprint.ts";
|
|
11
12
|
import type { CredentialSource } from "../credentials.ts";
|
|
13
|
+
import {
|
|
14
|
+
type HostToolSessions,
|
|
15
|
+
type HostTools,
|
|
16
|
+
hostToolSessions,
|
|
17
|
+
refuseHostName,
|
|
18
|
+
} from "../host-tools.ts";
|
|
12
19
|
import type { InheritConfig } from "../inherit-config.ts";
|
|
13
20
|
import { IDLE_TIMEOUT_MS } from "../process-pool.ts";
|
|
14
21
|
import { type DeliverSteer, SessionAgent } from "../session-agent.ts";
|
|
@@ -136,6 +143,12 @@ export interface CodexAppServerAgentOptions {
|
|
|
136
143
|
* default. Operator-level only.
|
|
137
144
|
*/
|
|
138
145
|
userLogin?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* The host's tools for each session (LLP 0018): Codex reaches them at the
|
|
148
|
+
* engine's loopback, by a secret of the session's own in its thread's
|
|
149
|
+
* config. Operator-level only.
|
|
150
|
+
*/
|
|
151
|
+
hostTools?: HostTools;
|
|
139
152
|
}
|
|
140
153
|
|
|
141
154
|
/**
|
|
@@ -151,6 +164,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
151
164
|
readonly processes: NativeProcesses;
|
|
152
165
|
private readonly timing: CodexTurnTiming;
|
|
153
166
|
private readonly sessions: CodexSessions;
|
|
167
|
+
private readonly host?: HostToolSessions;
|
|
154
168
|
readonly login = new CodexCliLogin({
|
|
155
169
|
connect: (env) =>
|
|
156
170
|
this.connect({ cwd: process.cwd(), ...(env && { env }) }, { experimentalApi: false }),
|
|
@@ -190,6 +204,9 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
190
204
|
builtInTools: agentOptions.builtInTools,
|
|
191
205
|
},
|
|
192
206
|
);
|
|
207
|
+
this.host = hostToolSessions(agentOptions.hostTools, this.harness, {
|
|
208
|
+
live: (sessionId) => this.sessions.live(sessionId),
|
|
209
|
+
});
|
|
193
210
|
}
|
|
194
211
|
|
|
195
212
|
/** On a product's credentials, each session may list as a different account. */
|
|
@@ -209,6 +226,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
209
226
|
signal,
|
|
210
227
|
items: new TurnItems(),
|
|
211
228
|
mode: options.permissionMode ?? "default",
|
|
229
|
+
turnId: options.turnId,
|
|
212
230
|
};
|
|
213
231
|
let session: CodexSession | undefined;
|
|
214
232
|
let stop: TurnStop | undefined;
|
|
@@ -236,7 +254,8 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
236
254
|
const predecessor = this.sessions.stopUnsettled(options.sessionId);
|
|
237
255
|
if (predecessor && !(await predecessor))
|
|
238
256
|
throw new Error("Previous Codex execution has not stopped");
|
|
239
|
-
const
|
|
257
|
+
const host = await untilAborted(this.hostServer(options), signal);
|
|
258
|
+
const mcp = this.sessions.mcpFor(options, host);
|
|
240
259
|
scope.auth = await authFor({
|
|
241
260
|
credentials: this.agentOptions.credentials,
|
|
242
261
|
sessionId: options.sessionId,
|
|
@@ -288,6 +307,28 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
288
307
|
}
|
|
289
308
|
}
|
|
290
309
|
|
|
310
|
+
protected override hostSecret(sessionId: string): string | undefined {
|
|
311
|
+
return this.host?.secretOf(sessionId);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** The host's server for the session, by the name its source gives, when it has one. */
|
|
315
|
+
private async hostServer(options: AgentExecuteOptions) {
|
|
316
|
+
const lease = await this.host?.lease(options.sessionId, options.cwd);
|
|
317
|
+
if (!lease) return undefined;
|
|
318
|
+
refuseHostName(options.mcpServers, lease.source.name);
|
|
319
|
+
try {
|
|
320
|
+
return { [lease.source.name]: await lease.http() };
|
|
321
|
+
} catch (error) {
|
|
322
|
+
// @ref LLP 0018#codex — a loopback that cannot start: the turn goes on without the host's tools, and says so
|
|
323
|
+
if (!(error instanceof McpUnavailableError)) throw error;
|
|
324
|
+
await options.onWarning?.({
|
|
325
|
+
category: "mcp_unavailable",
|
|
326
|
+
message: `${error.message.split(";")[0]}; the turn goes on without the host's tools`,
|
|
327
|
+
});
|
|
328
|
+
return undefined;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
291
332
|
/**
|
|
292
333
|
* The user's own login, for a turn (or a model list) whose `env` names a
|
|
293
334
|
* home, when the operator set `userLogin`: read again for each, so a login
|
|
@@ -376,11 +417,13 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
376
417
|
await super.release(sessionId);
|
|
377
418
|
// @ref LLP 0001#d10--built-in-turns-own-their-logical-session-through-cleanup — released once its process has exited, as a Claude session is
|
|
378
419
|
await this.sessions.release(sessionId);
|
|
420
|
+
this.host?.release(sessionId);
|
|
379
421
|
}
|
|
380
422
|
|
|
381
423
|
override async terminateAll(): Promise<void> {
|
|
382
424
|
await super.terminateAll();
|
|
383
425
|
await this.sessions.terminateAll();
|
|
426
|
+
await this.host?.close();
|
|
384
427
|
}
|
|
385
428
|
|
|
386
429
|
/**
|
|
@@ -418,6 +461,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
418
461
|
auth,
|
|
419
462
|
experimentalApi,
|
|
420
463
|
this.agentOptions.inheritConfig,
|
|
464
|
+
this.host !== undefined,
|
|
421
465
|
),
|
|
422
466
|
processes: this.processes,
|
|
423
467
|
...(sessionId !== undefined && { sessionId }),
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import { type ThinkingLevel, clampThinkingLevel } from "../../../protocol/index.ts";
|
|
2
2
|
|
|
3
|
-
/** Codex reasoning-effort string for a level (matches the `ReasoningEffort` enum). */
|
|
4
|
-
type CodexReasoningEffort =
|
|
5
|
-
| "none"
|
|
6
|
-
| "minimal"
|
|
7
|
-
| "low"
|
|
8
|
-
| "medium"
|
|
9
|
-
| "high"
|
|
10
|
-
| "xhigh"
|
|
11
|
-
| "max"
|
|
12
|
-
| "ultra";
|
|
13
|
-
|
|
14
3
|
/**
|
|
15
4
|
* The effort Codex runs for `level`. `supported` is what the model accepts, in
|
|
16
5
|
* this vocabulary, where `off` stands for its least effort: `offEffort`, the
|
|
17
|
-
* native `none` or `minimal` the model advertises. A level it
|
|
18
|
-
*
|
|
19
|
-
*
|
|
6
|
+
* native `none` or `minimal` the model advertises. A level it lists is sent as
|
|
7
|
+
* it is, and one it lacks is fitted to the nearest level this build can order;
|
|
8
|
+
* when there is none (a level this build does not know, or a model listing
|
|
9
|
+
* none it knows), the level is not applied: `undefined`. Without `supported`,
|
|
10
|
+
* the level is sent as asked, and `off` becomes `low`: no model the pinned CLI
|
|
11
|
+
* lists accepts `none` or `minimal`, and every one accepts `low`.
|
|
20
12
|
*/
|
|
21
|
-
export function codexReasoningEffort
|
|
13
|
+
export function codexReasoningEffort(
|
|
22
14
|
level: ThinkingLevel,
|
|
23
15
|
supported?: readonly ThinkingLevel[],
|
|
24
|
-
offEffort?:
|
|
25
|
-
):
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
offEffort?: "none" | "minimal",
|
|
17
|
+
): string | undefined {
|
|
18
|
+
if (supported?.length) {
|
|
19
|
+
const clamped = clampThinkingLevel(level, supported);
|
|
20
|
+
if (clamped === undefined) return undefined;
|
|
21
|
+
return clamped === "off" ? (offEffort ?? "minimal") : clamped;
|
|
22
|
+
}
|
|
23
|
+
return level === "off" ? "low" : level;
|
|
29
24
|
}
|
|
@@ -14,7 +14,7 @@ import type { CodexHomes } from "./homes.ts";
|
|
|
14
14
|
import type { CodexNotification } from "./protocol.ts";
|
|
15
15
|
|
|
16
16
|
/** Codex supports stdio and Streamable HTTP, not the legacy SSE transport. */
|
|
17
|
-
function codexMcpServers(servers: Record<string, McpServerConfig>): Record<string, unknown> {
|
|
17
|
+
export function codexMcpServers(servers: Record<string, McpServerConfig>): Record<string, unknown> {
|
|
18
18
|
return Object.fromEntries(
|
|
19
19
|
Object.entries(servers).map(([name, server]) => {
|
|
20
20
|
if (name === "codex_apps") throw new Error("MCP server name codex_apps is reserved by Codex");
|
|
@@ -23,13 +23,22 @@ function codexMcpServers(servers: Record<string, McpServerConfig>): Record<strin
|
|
|
23
23
|
}
|
|
24
24
|
return [
|
|
25
25
|
name,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
{
|
|
27
|
+
...(server.type === "stdio"
|
|
28
|
+
? {
|
|
29
|
+
command: server.command,
|
|
30
|
+
...(server.args && { args: server.args }),
|
|
31
|
+
...(server.env && { env: server.env }),
|
|
32
|
+
}
|
|
33
|
+
: { url: server.url, ...(server.headers && { http_headers: server.headers }) }),
|
|
34
|
+
// Whole seconds, rounded up (1118 ms becomes 2 s): Codex reads a fraction
|
|
35
|
+
// back as a float (1.118 as 1.1179999999999999, Codex 0.160.0), which a
|
|
36
|
+
// home's read-back takes for an override; an integer reads back unchanged.
|
|
37
|
+
// The thread's config and its fingerprint take this same value.
|
|
38
|
+
...(server.timeoutMs !== undefined && {
|
|
39
|
+
tool_timeout_sec: Math.ceil(server.timeoutMs / 1000),
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
33
42
|
];
|
|
34
43
|
}),
|
|
35
44
|
);
|
|
@@ -248,12 +257,28 @@ export interface CodexTurnMcp {
|
|
|
248
257
|
thread?: Record<string, unknown>;
|
|
249
258
|
}
|
|
250
259
|
|
|
251
|
-
/** The
|
|
252
|
-
export
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
260
|
+
/** The host's tools, as the session's turns name them (`HostToolSessions.http`). */
|
|
261
|
+
export type CodexHostServer = Record<string, McpServerConfig>;
|
|
262
|
+
|
|
263
|
+
// @ref LLP 0018#codex — the host's server rides the thread, never a home's config file
|
|
264
|
+
/**
|
|
265
|
+
* The turn's servers, snapshotted before anything asynchronous can let the
|
|
266
|
+
* caller change them. The host's server goes in the thread's own config
|
|
267
|
+
* whether or not the turn names a home: its secret is never written to disk.
|
|
268
|
+
*/
|
|
269
|
+
export function codexTurnMcp(
|
|
270
|
+
options: AgentExecuteOptions,
|
|
271
|
+
homes: CodexHomes,
|
|
272
|
+
host: CodexHostServer = {},
|
|
273
|
+
): CodexTurnMcp {
|
|
274
|
+
const turn = snapshotMcpServers(options.mcpServers);
|
|
275
|
+
const wire = { ...turn, ...host };
|
|
276
|
+
const servers = codexMcpServers(turn);
|
|
277
|
+
const own = codexMcpServers(host);
|
|
278
|
+
if (homes.claim(options))
|
|
279
|
+
return Object.keys(own).length ? { wire, servers, thread: own } : { wire, servers };
|
|
280
|
+
const thread = { ...servers, ...own };
|
|
281
|
+
return Object.keys(thread).length ? { wire, thread } : { wire };
|
|
257
282
|
}
|
|
258
283
|
|
|
259
284
|
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — a thread's config is fixed once it is open
|
|
@@ -325,12 +350,9 @@ export class CodexMcpState {
|
|
|
325
350
|
* Read before the thread opens, so no connection is made first, and
|
|
326
351
|
* before each turn.
|
|
327
352
|
*/
|
|
328
|
-
async threadServers({
|
|
329
|
-
servers,
|
|
330
|
-
thread
|
|
331
|
-
}: CodexTurnMcp): Promise<Record<string, unknown> | undefined> {
|
|
332
|
-
// A home the turn names holds the turn's servers, written there.
|
|
333
|
-
if (servers !== undefined || !thread) return undefined;
|
|
353
|
+
async threadServers({ thread }: CodexTurnMcp): Promise<Record<string, unknown> | undefined> {
|
|
354
|
+
// A home the turn names holds the turn's servers, written there; the thread only the host's.
|
|
355
|
+
if (!thread) return undefined;
|
|
334
356
|
const result = (await this.client.request("config/read", { cwd: this.cwd })) as {
|
|
335
357
|
config?: { mcp_servers?: Record<string, unknown> };
|
|
336
358
|
};
|
|
@@ -353,9 +375,10 @@ export class CodexMcpState {
|
|
|
353
375
|
// down), or at once when this turn requires it: its old failure must
|
|
354
376
|
// not decide. So is every server after a turn whose servers did not settle.
|
|
355
377
|
const again = this.unavailable.retryNow(mcp.wire).length > 0 || this.unsettled;
|
|
356
|
-
const started =
|
|
357
|
-
|
|
358
|
-
|
|
378
|
+
const started =
|
|
379
|
+
mcp.servers === undefined
|
|
380
|
+
? await this.startThreadServers(again)
|
|
381
|
+
: await this.startHomeServers(mcp, again);
|
|
359
382
|
let unavailable: Record<string, string>;
|
|
360
383
|
try {
|
|
361
384
|
unavailable = await settleCodexMcp(this.client, threadId, mcp.wire, this.causes);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AgentHarness, ModelDescriptor, ThinkingLevel } from "../../../protocol/index.ts";
|
|
2
|
-
import { isThinkingLevel } from "../../../protocol/index.ts";
|
|
3
2
|
import { onAbort } from "../../utils/deadline.ts";
|
|
4
|
-
import {
|
|
3
|
+
import { listedThinkingLevels } from "../thinking-levels.ts";
|
|
5
4
|
import { type CodexConnection, pages } from "./client.ts";
|
|
6
5
|
|
|
7
6
|
const MODEL_LIST_TIMEOUT_MS = 5_000;
|
|
@@ -20,12 +19,13 @@ export interface CodexModelThinking {
|
|
|
20
19
|
defaultEffort?: string;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* The level a native Codex effort is: `none` and `minimal` are `off`, and any
|
|
24
|
+
* other effort is a level of its own name, known to this build or not.
|
|
25
|
+
*/
|
|
24
26
|
export function codexThinkingLevel(effort: unknown): ThinkingLevel | undefined {
|
|
25
27
|
if (effort === "none" || effort === "minimal") return "off";
|
|
26
|
-
return typeof effort === "string" && effort !== "off" &&
|
|
27
|
-
? effort
|
|
28
|
-
: undefined;
|
|
28
|
+
return typeof effort === "string" && effort !== "off" && /\S/.test(effort) ? effort : undefined;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function efforts(model: CodexModel): unknown[] {
|
|
@@ -53,8 +53,8 @@ async function readCodexModels(client: Pick<CodexConnection, "request">): Promis
|
|
|
53
53
|
* What each model accepts, by its `model` and `id`. Codex's `none` or
|
|
54
54
|
* `minimal` is `off`, remembered so `off` sends the value the model
|
|
55
55
|
* advertised (`none` when it offers both). A model that lists no efforts at
|
|
56
|
-
* all has none (`levels: []`); one that
|
|
57
|
-
*
|
|
56
|
+
* all has none (`levels: []`); one that says nothing is left out, so what it
|
|
57
|
+
* accepts stays unknown.
|
|
58
58
|
*/
|
|
59
59
|
function codexModelThinking(models: readonly CodexModel[]): Map<string, CodexModelThinking> {
|
|
60
60
|
const thinking = new Map<string, CodexModelThinking>();
|
|
@@ -65,7 +65,7 @@ function codexModelThinking(models: readonly CodexModel[]): Map<string, CodexMod
|
|
|
65
65
|
: native.includes("minimal")
|
|
66
66
|
? "minimal"
|
|
67
67
|
: undefined;
|
|
68
|
-
const levels =
|
|
68
|
+
const levels = listedThinkingLevels(native.map(codexThinkingLevel));
|
|
69
69
|
const none = Array.isArray(model.supportedReasoningEfforts) && native.length === 0;
|
|
70
70
|
if (!levels.length && !none) continue;
|
|
71
71
|
const defaultEffort =
|
|
@@ -156,7 +156,7 @@ export function codexModelDescriptors(
|
|
|
156
156
|
return models.flatMap((model) => {
|
|
157
157
|
const id = typeof model.model === "string" ? model.model : model.id;
|
|
158
158
|
if (typeof id !== "string" || model.hidden === true) return [];
|
|
159
|
-
const levels =
|
|
159
|
+
const levels = listedThinkingLevels(efforts(model).map(codexThinkingLevel));
|
|
160
160
|
const fallback = codexThinkingLevel(model.defaultReasoningEffort);
|
|
161
161
|
return [
|
|
162
162
|
{
|