@zvada/agent-server 0.3.25 → 0.3.26
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 +80 -0
- package/README.md +3 -0
- 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 +2 -1
- 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/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 +9 -3
- 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 +12 -2
- 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/protocol/config.js +21 -1
- package/dist/protocol/model-catalog.js +58 -18
- package/dist/protocol/models.js +6 -27
- package/dist/protocol/thinking.js +22 -9
- package/dist/protocol/wire-api.js +2 -2
- package/dist/server/bin.js +6 -4
- 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/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.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/protocol/config.d.ts +12 -19
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +4 -36
- 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/lifecycle.d.ts +8 -72
- 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/thinking.d.ts +19 -19
- package/dist/types/protocol/thinking.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +20 -105
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +16 -117
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/docs/consuming.md +68 -11
- package/docs/deploy.md +6 -5
- package/docs/harnesses.md +79 -31
- package/package.json +4 -4
- 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/claude-code/approvals.ts +2 -1
- 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/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 +9 -2
- 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 +24 -3
- 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/protocol/config.ts +22 -1
- package/src/protocol/model-catalog.ts +58 -18
- package/src/protocol/models.ts +6 -26
- package/src/protocol/thinking.ts +27 -14
- package/src/protocol/wire-api.ts +2 -2
- package/src/server/bin.ts +6 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { sharedNativeProcesses } from "../../processes/native-processes.js";
|
|
2
2
|
import { onAbort, untilAborted } from "../../utils/deadline.js";
|
|
3
|
+
import { McpUnavailableError } from "../../utils/errors.js";
|
|
3
4
|
import { configFingerprint } from "../config-fingerprint.js";
|
|
5
|
+
import { hostToolSessions, refuseHostName, } from "../host-tools.js";
|
|
4
6
|
import { IDLE_TIMEOUT_MS } from "../process-pool.js";
|
|
5
7
|
import { SessionAgent } from "../session-agent.js";
|
|
6
8
|
import { CodexAppServerClient, } from "./client.js";
|
|
@@ -55,6 +57,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
55
57
|
processes;
|
|
56
58
|
timing;
|
|
57
59
|
sessions;
|
|
60
|
+
host;
|
|
58
61
|
login = new CodexCliLogin({
|
|
59
62
|
connect: (env) => this.connect({ cwd: process.cwd(), ...(env && { env }) }, { experimentalApi: false }),
|
|
60
63
|
cliPath: async () => (await this.cliPath()) ?? "codex",
|
|
@@ -87,6 +90,9 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
87
90
|
inheritConfig: agentOptions.inheritConfig,
|
|
88
91
|
builtInTools: agentOptions.builtInTools,
|
|
89
92
|
});
|
|
93
|
+
this.host = hostToolSessions(agentOptions.hostTools, this.harness, {
|
|
94
|
+
live: (sessionId) => this.sessions.live(sessionId),
|
|
95
|
+
});
|
|
90
96
|
}
|
|
91
97
|
/** On a product's credentials, each session may list as a different account. */
|
|
92
98
|
get modelsPerSession() {
|
|
@@ -100,6 +106,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
100
106
|
signal,
|
|
101
107
|
items: new TurnItems(),
|
|
102
108
|
mode: options.permissionMode ?? "default",
|
|
109
|
+
turnId: options.turnId,
|
|
103
110
|
};
|
|
104
111
|
let session;
|
|
105
112
|
let stop;
|
|
@@ -129,7 +136,8 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
129
136
|
const predecessor = this.sessions.stopUnsettled(options.sessionId);
|
|
130
137
|
if (predecessor && !(await predecessor))
|
|
131
138
|
throw new Error("Previous Codex execution has not stopped");
|
|
132
|
-
const
|
|
139
|
+
const host = await untilAborted(this.hostServer(options), signal);
|
|
140
|
+
const mcp = this.sessions.mcpFor(options, host);
|
|
133
141
|
scope.auth = await authFor({
|
|
134
142
|
credentials: this.agentOptions.credentials,
|
|
135
143
|
sessionId: options.sessionId,
|
|
@@ -188,6 +196,29 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
188
196
|
this.sessions.leave(options.sessionId, session, scope);
|
|
189
197
|
}
|
|
190
198
|
}
|
|
199
|
+
hostSecret(sessionId) {
|
|
200
|
+
return this.host?.secretOf(sessionId);
|
|
201
|
+
}
|
|
202
|
+
/** The host's server for the session, by the name its source gives, when it has one. */
|
|
203
|
+
async hostServer(options) {
|
|
204
|
+
const lease = await this.host?.lease(options.sessionId, options.cwd);
|
|
205
|
+
if (!lease)
|
|
206
|
+
return undefined;
|
|
207
|
+
refuseHostName(options.mcpServers, lease.source.name);
|
|
208
|
+
try {
|
|
209
|
+
return { [lease.source.name]: await lease.http() };
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
// @ref LLP 0018#codex — a loopback that cannot start: the turn goes on without the host's tools, and says so
|
|
213
|
+
if (!(error instanceof McpUnavailableError))
|
|
214
|
+
throw error;
|
|
215
|
+
await options.onWarning?.({
|
|
216
|
+
category: "mcp_unavailable",
|
|
217
|
+
message: `${error.message.split(";")[0]}; the turn goes on without the host's tools`,
|
|
218
|
+
});
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
191
222
|
/**
|
|
192
223
|
* The user's own login, for a turn (or a model list) whose `env` names a
|
|
193
224
|
* home, when the operator set `userLogin`: read again for each, so a login
|
|
@@ -261,10 +292,12 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
261
292
|
await super.release(sessionId);
|
|
262
293
|
// @ref LLP 0001#d10--built-in-turns-own-their-logical-session-through-cleanup — released once its process has exited, as a Claude session is
|
|
263
294
|
await this.sessions.release(sessionId);
|
|
295
|
+
this.host?.release(sessionId);
|
|
264
296
|
}
|
|
265
297
|
async terminateAll() {
|
|
266
298
|
await super.terminateAll();
|
|
267
299
|
await this.sessions.terminateAll();
|
|
300
|
+
await this.host?.close();
|
|
268
301
|
}
|
|
269
302
|
/**
|
|
270
303
|
* The CLI to run: the provisioner's, else `$CODEX_CLI_PATH`; PATH's `codex`
|
|
@@ -285,7 +318,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
285
318
|
const codexPath = (await this.cliPath(signal)) ?? "codex";
|
|
286
319
|
signal?.throwIfAborted();
|
|
287
320
|
const clientOptions = {
|
|
288
|
-
...clientOptionsFor(codexPath, options, auth, experimentalApi, this.agentOptions.inheritConfig),
|
|
321
|
+
...clientOptionsFor(codexPath, options, auth, experimentalApi, this.agentOptions.inheritConfig, this.host !== undefined),
|
|
289
322
|
processes: this.processes,
|
|
290
323
|
...(sessionId !== undefined && { sessionId }),
|
|
291
324
|
};
|
|
@@ -2,12 +2,19 @@ import { clampThinkingLevel } from "../../../protocol/index.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* The effort Codex runs for `level`. `supported` is what the model accepts, in
|
|
4
4
|
* this vocabulary, where `off` stands for its least effort: `offEffort`, the
|
|
5
|
-
* native `none` or `minimal` the model advertises. A level it
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* native `none` or `minimal` the model advertises. A level it lists is sent as
|
|
6
|
+
* it is, and one it lacks is fitted to the nearest level this build can order;
|
|
7
|
+
* when there is none (a level this build does not know, or a model listing
|
|
8
|
+
* none it knows), the level is not applied: `undefined`. Without `supported`,
|
|
9
|
+
* the level is sent as asked, and `off` becomes `low`: no model the pinned CLI
|
|
10
|
+
* lists accepts `none` or `minimal`, and every one accepts `low`.
|
|
8
11
|
*/
|
|
9
12
|
export function codexReasoningEffort(level, supported, offEffort) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
if (supported?.length) {
|
|
14
|
+
const clamped = clampThinkingLevel(level, supported);
|
|
15
|
+
if (clamped === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
return clamped === "off" ? (offEffort ?? "minimal") : clamped;
|
|
18
|
+
}
|
|
19
|
+
return level === "off" ? "low" : level;
|
|
13
20
|
}
|
|
@@ -5,7 +5,7 @@ import { configFingerprint } from "../config-fingerprint.js";
|
|
|
5
5
|
import { UnavailableMcpServers, mcpConnectionErrors, settleMcpFailures, snapshotMcpServers, } from "../mcp-config.js";
|
|
6
6
|
import { pages } from "./client.js";
|
|
7
7
|
/** Codex supports stdio and Streamable HTTP, not the legacy SSE transport. */
|
|
8
|
-
function codexMcpServers(servers) {
|
|
8
|
+
export function codexMcpServers(servers) {
|
|
9
9
|
return Object.fromEntries(Object.entries(servers).map(([name, server]) => {
|
|
10
10
|
if (name === "codex_apps")
|
|
11
11
|
throw new Error("MCP server name codex_apps is reserved by Codex");
|
|
@@ -14,13 +14,22 @@ function codexMcpServers(servers) {
|
|
|
14
14
|
}
|
|
15
15
|
return [
|
|
16
16
|
name,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
{
|
|
18
|
+
...(server.type === "stdio"
|
|
19
|
+
? {
|
|
20
|
+
command: server.command,
|
|
21
|
+
...(server.args && { args: server.args }),
|
|
22
|
+
...(server.env && { env: server.env }),
|
|
23
|
+
}
|
|
24
|
+
: { url: server.url, ...(server.headers && { http_headers: server.headers }) }),
|
|
25
|
+
// Whole seconds, rounded up (1118 ms becomes 2 s): Codex reads a fraction
|
|
26
|
+
// back as a float (1.118 as 1.1179999999999999, Codex 0.160.0), which a
|
|
27
|
+
// home's read-back takes for an override; an integer reads back unchanged.
|
|
28
|
+
// The thread's config and its fingerprint take this same value.
|
|
29
|
+
...(server.timeoutMs !== undefined && {
|
|
30
|
+
tool_timeout_sec: Math.ceil(server.timeoutMs / 1000),
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
24
33
|
];
|
|
25
34
|
}));
|
|
26
35
|
}
|
|
@@ -177,13 +186,21 @@ async function settleCodexMcp(client, threadId, servers, causes) {
|
|
|
177
186
|
updates.end();
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
189
|
+
// @ref LLP 0018#codex — the host's server rides the thread, never a home's config file
|
|
190
|
+
/**
|
|
191
|
+
* The turn's servers, snapshotted before anything asynchronous can let the
|
|
192
|
+
* caller change them. The host's server goes in the thread's own config
|
|
193
|
+
* whether or not the turn names a home: its secret is never written to disk.
|
|
194
|
+
*/
|
|
195
|
+
export function codexTurnMcp(options, homes, host = {}) {
|
|
196
|
+
const turn = snapshotMcpServers(options.mcpServers);
|
|
197
|
+
const wire = { ...turn, ...host };
|
|
198
|
+
const servers = codexMcpServers(turn);
|
|
199
|
+
const own = codexMcpServers(host);
|
|
184
200
|
if (homes.claim(options))
|
|
185
|
-
return { wire, servers };
|
|
186
|
-
|
|
201
|
+
return Object.keys(own).length ? { wire, servers, thread: own } : { wire, servers };
|
|
202
|
+
const thread = { ...servers, ...own };
|
|
203
|
+
return Object.keys(thread).length ? { wire, thread } : { wire };
|
|
187
204
|
}
|
|
188
205
|
// @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
|
|
189
206
|
/**
|
|
@@ -257,9 +274,9 @@ export class CodexMcpState {
|
|
|
257
274
|
* Read before the thread opens, so no connection is made first, and
|
|
258
275
|
* before each turn.
|
|
259
276
|
*/
|
|
260
|
-
async threadServers({
|
|
261
|
-
// A home the turn names holds the turn's servers, written there.
|
|
262
|
-
if (
|
|
277
|
+
async threadServers({ thread }) {
|
|
278
|
+
// A home the turn names holds the turn's servers, written there; the thread only the host's.
|
|
279
|
+
if (!thread)
|
|
263
280
|
return undefined;
|
|
264
281
|
const result = (await this.client.request("config/read", { cwd: this.cwd }));
|
|
265
282
|
assertCodexThreadMcp(result.config?.mcp_servers ?? {}, thread);
|
|
@@ -276,7 +293,7 @@ export class CodexMcpState {
|
|
|
276
293
|
// down), or at once when this turn requires it: its old failure must
|
|
277
294
|
// not decide. So is every server after a turn whose servers did not settle.
|
|
278
295
|
const again = this.unavailable.retryNow(mcp.wire).length > 0 || this.unsettled;
|
|
279
|
-
const started = mcp.
|
|
296
|
+
const started = mcp.servers === undefined
|
|
280
297
|
? await this.startThreadServers(again)
|
|
281
298
|
: await this.startHomeServers(mcp, again);
|
|
282
299
|
let unavailable;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { isThinkingLevel } from "../../../protocol/index.js";
|
|
2
1
|
import { onAbort } from "../../utils/deadline.js";
|
|
3
|
-
import {
|
|
2
|
+
import { listedThinkingLevels } from "../thinking-levels.js";
|
|
4
3
|
import { pages } from "./client.js";
|
|
5
4
|
const MODEL_LIST_TIMEOUT_MS = 5_000;
|
|
6
5
|
/** How many pages of `model/list` are read; Codex lists a dozen models in one. */
|
|
7
6
|
const MODEL_LIST_PAGES = 10;
|
|
8
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The level a native Codex effort is: `none` and `minimal` are `off`, and any
|
|
9
|
+
* other effort is a level of its own name, known to this build or not.
|
|
10
|
+
*/
|
|
9
11
|
export function codexThinkingLevel(effort) {
|
|
10
12
|
if (effort === "none" || effort === "minimal")
|
|
11
13
|
return "off";
|
|
12
|
-
return typeof effort === "string" && effort !== "off" &&
|
|
13
|
-
? effort
|
|
14
|
-
: undefined;
|
|
14
|
+
return typeof effort === "string" && effort !== "off" && /\S/.test(effort) ? effort : undefined;
|
|
15
15
|
}
|
|
16
16
|
function efforts(model) {
|
|
17
17
|
return Array.isArray(model.supportedReasoningEfforts)
|
|
@@ -29,8 +29,8 @@ async function readCodexModels(client) {
|
|
|
29
29
|
* What each model accepts, by its `model` and `id`. Codex's `none` or
|
|
30
30
|
* `minimal` is `off`, remembered so `off` sends the value the model
|
|
31
31
|
* advertised (`none` when it offers both). A model that lists no efforts at
|
|
32
|
-
* all has none (`levels: []`); one that
|
|
33
|
-
*
|
|
32
|
+
* all has none (`levels: []`); one that says nothing is left out, so what it
|
|
33
|
+
* accepts stays unknown.
|
|
34
34
|
*/
|
|
35
35
|
function codexModelThinking(models) {
|
|
36
36
|
const thinking = new Map();
|
|
@@ -41,7 +41,7 @@ function codexModelThinking(models) {
|
|
|
41
41
|
: native.includes("minimal")
|
|
42
42
|
? "minimal"
|
|
43
43
|
: undefined;
|
|
44
|
-
const levels =
|
|
44
|
+
const levels = listedThinkingLevels(native.map(codexThinkingLevel));
|
|
45
45
|
const none = Array.isArray(model.supportedReasoningEfforts) && native.length === 0;
|
|
46
46
|
if (!levels.length && !none)
|
|
47
47
|
continue;
|
|
@@ -110,7 +110,7 @@ export function codexModelDescriptors(models, harness, configuredModel) {
|
|
|
110
110
|
const id = typeof model.model === "string" ? model.model : model.id;
|
|
111
111
|
if (typeof id !== "string" || model.hidden === true)
|
|
112
112
|
return [];
|
|
113
|
-
const levels =
|
|
113
|
+
const levels = listedThinkingLevels(efforts(model).map(codexThinkingLevel));
|
|
114
114
|
const fallback = codexThinkingLevel(model.defaultReasoningEffort);
|
|
115
115
|
return [
|
|
116
116
|
{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { configFingerprint, directoriesFingerprint } from "../config-fingerprint.js";
|
|
2
|
+
import { withLoopbackDirect } from "../host-tools.js";
|
|
2
3
|
/**
|
|
3
4
|
* Why a turn without tools (`disableTools`) fails on Codex. With every
|
|
4
5
|
* feature that offers one turned off, Codex 0.160 still gives a code-mode
|
|
@@ -67,11 +68,15 @@ export function codexSessionCompatible(existing, options) {
|
|
|
67
68
|
* How the harness starts `codex app-server` for a folder, its `env` and a
|
|
68
69
|
* login, at the operator's `inheritConfig`.
|
|
69
70
|
*/
|
|
70
|
-
export function clientOptionsFor(codexPath, { cwd, env }, auth, experimentalApi, inheritConfig = "all"
|
|
71
|
+
export function clientOptionsFor(codexPath, { cwd, env }, auth, experimentalApi, inheritConfig = "all",
|
|
72
|
+
/** The engine serves host tools on loopback: reach it directly, past any proxy. */
|
|
73
|
+
loopback = false) {
|
|
74
|
+
const base = env ? { ...process.env, ...env } : process.env;
|
|
71
75
|
return {
|
|
72
76
|
codexPath,
|
|
73
77
|
cwd,
|
|
74
|
-
|
|
78
|
+
// @ref LLP 0018#codex — the bearer never travels through a proxy
|
|
79
|
+
env: loopback ? withLoopbackDirect(base) : base,
|
|
75
80
|
...(experimentalApi && { experimentalApi: true }),
|
|
76
81
|
...(auth && { ephemeralCredentials: true }),
|
|
77
82
|
// @ref LLP 0001#d17--a-turn-inherits-what-the-operator-chooses-all-the-projects-or-none — a session's home loads no plugins
|
|
@@ -110,6 +115,10 @@ export function threadParams(options, policy = {}, mcpServers) {
|
|
|
110
115
|
if (tools.local === false) {
|
|
111
116
|
features.shell_tool = false;
|
|
112
117
|
features.unified_exec = false;
|
|
118
|
+
// @ref LLP 0017#each-turn-names-its-environments — view_image has a switch, apply_patch none
|
|
119
|
+
// Since 0.164 Codex lists `view_image` and `apply_patch` whatever a turn's environments:
|
|
120
|
+
// this takes the first away, and `environments: []` refuses a call to the second.
|
|
121
|
+
features.view_image = false;
|
|
113
122
|
}
|
|
114
123
|
if (tools.imageGeneration === false)
|
|
115
124
|
features.image_generation = false;
|
|
@@ -4,7 +4,7 @@ import { ProcessPool } from "../process-pool.js";
|
|
|
4
4
|
import { authFingerprint, logIn } from "./credentials.js";
|
|
5
5
|
import { CodexHomes, holdHome, homeIdentity } from "./homes.js";
|
|
6
6
|
import { codexLoginMark, codexLoginStore } from "./login.js";
|
|
7
|
-
import { CodexMcpState, codexTurnMcp, threadServersFingerprint } from "./mcp.js";
|
|
7
|
+
import { CodexMcpState, codexTurnMcp, threadServersFingerprint, } from "./mcp.js";
|
|
8
8
|
import { codexSessionCompatible, processIdentity, threadParams, } from "./options.js";
|
|
9
9
|
import { bindServerRequests } from "./requests.js";
|
|
10
10
|
import { CodexThread } from "./thread-settings.js";
|
|
@@ -76,9 +76,16 @@ export class CodexSessions {
|
|
|
76
76
|
get(sessionId) {
|
|
77
77
|
return this.pool.get(sessionId);
|
|
78
78
|
}
|
|
79
|
-
/** The turn's MCP servers, in the `CODEX_HOME` the session claims when the turn names one. */
|
|
80
|
-
mcpFor(options) {
|
|
81
|
-
return codexTurnMcp(options, this.homes);
|
|
79
|
+
/** The turn's MCP servers, in the `CODEX_HOME` the session claims when the turn names one, and the host's. */
|
|
80
|
+
mcpFor(options, host) {
|
|
81
|
+
return codexTurnMcp(options, this.homes, host);
|
|
82
|
+
}
|
|
83
|
+
/** The turn the session runs now, and its mode, for a host tool's caller. */
|
|
84
|
+
live(sessionId) {
|
|
85
|
+
const turn = this.pool.get(sessionId)?.turn;
|
|
86
|
+
return turn?.turnId
|
|
87
|
+
? { turnId: turn.turnId, permissionMode: turn.mode, signal: turn.signal }
|
|
88
|
+
: undefined;
|
|
82
89
|
}
|
|
83
90
|
/**
|
|
84
91
|
* The session's process for the turn, which takes it (the pool's rule):
|
|
@@ -39,13 +39,24 @@ async function modelThinking(session, model, known) {
|
|
|
39
39
|
const levels = known ?? modelThinkingLevels("codex-app-server", model);
|
|
40
40
|
return levels && { levels };
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* An effort fitted to what `model` accepts, so Codex is not asked for one it
|
|
44
|
+
* lacks. When the model's levels are known, the answer is always an effort it
|
|
45
|
+
* lists: the fit; else the model's own default effort; else the first level
|
|
46
|
+
* it lists, as Codex names it (its `none` or `minimal` for `off`). The effort
|
|
47
|
+
* as it was only when the model's levels are unknown or it lists none.
|
|
48
|
+
*/
|
|
43
49
|
async function fitEffort(session, model, effort, known) {
|
|
44
|
-
const level = codexThinkingLevel(effort);
|
|
45
50
|
const accepts = await modelThinking(session, model, known);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
const first = accepts?.levels[0];
|
|
52
|
+
if (!accepts || first === undefined)
|
|
53
|
+
return effort;
|
|
54
|
+
const level = codexThinkingLevel(effort);
|
|
55
|
+
return ((level && codexReasoningEffort(level, accepts.levels, accepts.off)) ??
|
|
56
|
+
accepts.defaultEffort ??
|
|
57
|
+
// A level the model lists always fits; `off` becomes its native effort.
|
|
58
|
+
codexReasoningEffort(first, accepts.levels, accepts.off) ??
|
|
59
|
+
first);
|
|
49
60
|
}
|
|
50
61
|
/** One logical session's thread settings, which outlive its processes. */
|
|
51
62
|
export class CodexThread {
|
|
@@ -106,17 +117,24 @@ export class CodexThread {
|
|
|
106
117
|
// A model known to have no reasoning control is sent no effort, and the
|
|
107
118
|
// turn reports no level: the thread's effort does not apply to it.
|
|
108
119
|
let noThinking = false;
|
|
120
|
+
// A level with no fit among the levels the model lists is not sent: the
|
|
121
|
+
// turn runs as one that names no level.
|
|
122
|
+
let unlisted = false;
|
|
109
123
|
if (options.thinkingLevel) {
|
|
110
124
|
const accepts = await modelThinking(session, next.model, known);
|
|
111
125
|
if (accepts && !accepts.levels.length)
|
|
112
126
|
noThinking = true;
|
|
113
127
|
else {
|
|
114
128
|
const effort = codexReasoningEffort(options.thinkingLevel, accepts?.levels, accepts?.off);
|
|
115
|
-
|
|
116
|
-
|
|
129
|
+
if (effort === undefined)
|
|
130
|
+
unlisted = true;
|
|
131
|
+
else {
|
|
132
|
+
params.effort = effort;
|
|
133
|
+
next = { ...next, effort, effortSet: true };
|
|
134
|
+
}
|
|
117
135
|
}
|
|
118
136
|
}
|
|
119
|
-
|
|
137
|
+
if (!options.thinkingLevel || unlisted) {
|
|
120
138
|
// Once a turn set the thread's effort, the default is worked out for
|
|
121
139
|
// this turn's model. Otherwise, and when Codex cannot say what the
|
|
122
140
|
// default is, the thread keeps its own effort, fitted to a model the
|
|
@@ -137,12 +155,13 @@ export class CodexThread {
|
|
|
137
155
|
const collaboration = inCollaborationMode(next, mode);
|
|
138
156
|
return {
|
|
139
157
|
params: { ...params, ...collaboration.params },
|
|
140
|
-
...((level || next.reportedModel || noThinking) && {
|
|
158
|
+
...((level || next.reportedModel || noThinking || unlisted) && {
|
|
141
159
|
applied: {
|
|
142
160
|
...(level && { thinkingLevel: level }),
|
|
143
161
|
...(next.reportedModel && { model: next.reportedModel }),
|
|
144
|
-
// The turn's level was not sent: its model has no reasoning
|
|
145
|
-
|
|
162
|
+
// The turn's level was not sent: its model has no reasoning
|
|
163
|
+
// control, or does not list that level.
|
|
164
|
+
...((noThinking || unlisted) && { notApplied: ["thinkingLevel"] }),
|
|
146
165
|
},
|
|
147
166
|
}),
|
|
148
167
|
next: collaboration.next,
|