@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.
Files changed (156) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +3 -0
  3. package/dist/core/agents/acp/acp-agent.js +91 -14
  4. package/dist/core/agents/acp/mappings.js +5 -1
  5. package/dist/core/agents/claude-code/approvals.js +2 -1
  6. package/dist/core/agents/claude-code/claude-agent.js +12 -2
  7. package/dist/core/agents/claude-code/mcp.js +9 -1
  8. package/dist/core/agents/claude-code/models.js +16 -10
  9. package/dist/core/agents/claude-code/options.js +23 -2
  10. package/dist/core/agents/claude-code/session.js +21 -1
  11. package/dist/core/agents/claude-code/tools.js +9 -4
  12. package/dist/core/agents/claude-code/turn.js +2 -0
  13. package/dist/core/agents/codex-app-server/adapter.js +2 -0
  14. package/dist/core/agents/codex-app-server/client.js +8 -5
  15. package/dist/core/agents/codex-app-server/codex-agent.js +35 -2
  16. package/dist/core/agents/codex-app-server/effort.js +13 -6
  17. package/dist/core/agents/codex-app-server/mcp.js +35 -18
  18. package/dist/core/agents/codex-app-server/models.js +10 -10
  19. package/dist/core/agents/codex-app-server/options.js +11 -2
  20. package/dist/core/agents/codex-app-server/session.js +11 -4
  21. package/dist/core/agents/codex-app-server/thread-settings.js +30 -11
  22. package/dist/core/agents/host-tools.js +493 -0
  23. package/dist/core/agents/mcp-config.js +6 -2
  24. package/dist/core/agents/scripted/scripted-agent.js +9 -3
  25. package/dist/core/agents/scripted/steps.js +5 -1
  26. package/dist/core/agents/session-agent.js +70 -2
  27. package/dist/core/agents/thinking-levels.js +8 -5
  28. package/dist/core/index.js +1 -0
  29. package/dist/core/presets.js +12 -2
  30. package/dist/core/processes/lifeline.js +9 -5
  31. package/dist/core/provision/pins.js +7 -16
  32. package/dist/core/provision/releases.js +25 -25
  33. package/dist/core/proxy/loopback.js +22 -4
  34. package/dist/protocol/config.js +21 -1
  35. package/dist/protocol/model-catalog.js +58 -18
  36. package/dist/protocol/models.js +6 -27
  37. package/dist/protocol/thinking.js +22 -9
  38. package/dist/protocol/wire-api.js +2 -2
  39. package/dist/server/bin.js +6 -4
  40. package/dist/types/core/agents/acp/acp-agent.d.ts +15 -0
  41. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  42. package/dist/types/core/agents/acp/mappings.d.ts +5 -1
  43. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  44. package/dist/types/core/agents/acp/requests.d.ts +2 -0
  45. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  46. package/dist/types/core/agents/claude-code/approvals.d.ts +2 -1
  47. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  48. package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -0
  49. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  50. package/dist/types/core/agents/claude-code/mcp.d.ts +8 -1
  51. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  52. package/dist/types/core/agents/claude-code/models.d.ts +9 -5
  53. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  54. package/dist/types/core/agents/claude-code/options.d.ts +10 -1
  55. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  56. package/dist/types/core/agents/claude-code/session.d.ts +2 -0
  57. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  58. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  59. package/dist/types/core/agents/claude-code/turn.d.ts +3 -0
  60. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
  61. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  62. package/dist/types/core/agents/codex-app-server/client.d.ts +2 -0
  63. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  64. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +11 -0
  65. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  66. package/dist/types/core/agents/codex-app-server/effort.d.ts +7 -7
  67. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  68. package/dist/types/core/agents/codex-app-server/mcp.d.ts +11 -3
  69. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  70. package/dist/types/core/agents/codex-app-server/models.d.ts +4 -1
  71. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  72. package/dist/types/core/agents/codex-app-server/options.d.ts +9 -2
  73. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  74. package/dist/types/core/agents/codex-app-server/requests.d.ts +2 -0
  75. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  76. package/dist/types/core/agents/codex-app-server/session.d.ts +6 -3
  77. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  78. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  79. package/dist/types/core/agents/host-tools.d.ts +162 -0
  80. package/dist/types/core/agents/host-tools.d.ts.map +1 -0
  81. package/dist/types/core/agents/mcp-config.d.ts +11 -2
  82. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  83. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  84. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -1
  85. package/dist/types/core/agents/session-agent.d.ts +2 -7
  86. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  87. package/dist/types/core/agents/thinking-levels.d.ts +7 -3
  88. package/dist/types/core/agents/thinking-levels.d.ts.map +1 -1
  89. package/dist/types/core/index.d.ts +1 -0
  90. package/dist/types/core/index.d.ts.map +1 -1
  91. package/dist/types/core/presets.d.ts +11 -1
  92. package/dist/types/core/presets.d.ts.map +1 -1
  93. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  94. package/dist/types/core/provision/pins.d.ts +5 -4
  95. package/dist/types/core/provision/pins.d.ts.map +1 -1
  96. package/dist/types/core/proxy/loopback.d.ts.map +1 -1
  97. package/dist/types/protocol/config.d.ts +12 -19
  98. package/dist/types/protocol/config.d.ts.map +1 -1
  99. package/dist/types/protocol/conversation.d.ts +4 -36
  100. package/dist/types/protocol/conversation.d.ts.map +1 -1
  101. package/dist/types/protocol/execution.d.ts +2 -18
  102. package/dist/types/protocol/execution.d.ts.map +1 -1
  103. package/dist/types/protocol/lifecycle.d.ts +8 -72
  104. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  105. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  106. package/dist/types/protocol/models.d.ts +4 -42
  107. package/dist/types/protocol/models.d.ts.map +1 -1
  108. package/dist/types/protocol/thinking.d.ts +19 -19
  109. package/dist/types/protocol/thinking.d.ts.map +1 -1
  110. package/dist/types/protocol/wire-api.d.ts +20 -105
  111. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  112. package/dist/types/protocol/wire.d.ts +16 -117
  113. package/dist/types/protocol/wire.d.ts.map +1 -1
  114. package/docs/consuming.md +68 -11
  115. package/docs/deploy.md +6 -5
  116. package/docs/harnesses.md +79 -31
  117. package/package.json +4 -4
  118. package/src/core/agents/acp/acp-agent.ts +123 -17
  119. package/src/core/agents/acp/mappings.ts +5 -1
  120. package/src/core/agents/acp/requests.ts +2 -0
  121. package/src/core/agents/claude-code/approvals.ts +2 -1
  122. package/src/core/agents/claude-code/claude-agent.ts +14 -2
  123. package/src/core/agents/claude-code/mcp.ts +11 -1
  124. package/src/core/agents/claude-code/models.ts +15 -10
  125. package/src/core/agents/claude-code/options.ts +33 -3
  126. package/src/core/agents/claude-code/session.ts +26 -1
  127. package/src/core/agents/claude-code/tools.ts +10 -4
  128. package/src/core/agents/claude-code/turn.ts +4 -0
  129. package/src/core/agents/codex-app-server/adapter.ts +2 -0
  130. package/src/core/agents/codex-app-server/client.ts +11 -5
  131. package/src/core/agents/codex-app-server/codex-agent.ts +45 -1
  132. package/src/core/agents/codex-app-server/effort.ts +15 -20
  133. package/src/core/agents/codex-app-server/mcp.ts +46 -23
  134. package/src/core/agents/codex-app-server/models.ts +10 -10
  135. package/src/core/agents/codex-app-server/options.ts +16 -2
  136. package/src/core/agents/codex-app-server/requests.ts +2 -0
  137. package/src/core/agents/codex-app-server/session.ts +19 -4
  138. package/src/core/agents/codex-app-server/thread-settings.ts +31 -11
  139. package/src/core/agents/host-tools.ts +649 -0
  140. package/src/core/agents/mcp-config.ts +15 -3
  141. package/src/core/agents/scripted/scripted-agent.ts +9 -2
  142. package/src/core/agents/scripted/steps.ts +5 -1
  143. package/src/core/agents/session-agent.ts +78 -2
  144. package/src/core/agents/thinking-levels.ts +9 -6
  145. package/src/core/index.ts +9 -0
  146. package/src/core/presets.ts +24 -3
  147. package/src/core/processes/lifeline.ts +9 -5
  148. package/src/core/provision/pins.ts +7 -16
  149. package/src/core/provision/releases.ts +25 -25
  150. package/src/core/proxy/loopback.ts +25 -4
  151. package/src/protocol/config.ts +22 -1
  152. package/src/protocol/model-catalog.ts +58 -18
  153. package/src/protocol/models.ts +6 -26
  154. package/src/protocol/thinking.ts +27 -14
  155. package/src/protocol/wire-api.ts +2 -2
  156. 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 mcp = this.sessions.mcpFor(options);
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 lacks becomes the
6
- * nearest one it has. Without `supported`, `off` becomes `low`: no model the
7
- * pinned CLI lists accepts `none` or `minimal`, and every one accepts `low`.
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
- const clamped = supported?.length ? clampThinkingLevel(level, supported) : undefined;
11
- const effective = clamped ?? (level === "off" ? "low" : level);
12
- return effective === "off" ? (offEffort ?? "minimal") : effective;
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
- server.type === "stdio"
18
- ? {
19
- command: server.command,
20
- ...(server.args && { args: server.args }),
21
- ...(server.env && { env: server.env }),
22
- }
23
- : { url: server.url, ...(server.headers && { http_headers: server.headers }) },
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
- /** The turn's servers, snapshotted before anything asynchronous can let the caller change them. */
181
- export function codexTurnMcp(options, homes) {
182
- const wire = snapshotMcpServers(options.mcpServers);
183
- const servers = codexMcpServers(wire);
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
- return Object.keys(servers).length ? { wire, thread: servers } : { wire };
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({ servers, thread, }) {
261
- // A home the turn names holds the turn's servers, written there.
262
- if (servers !== undefined || !thread)
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.thread
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 { knownThinkingLevels } from "../thinking-levels.js";
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
- /** The level a native Codex effort is: `none` and `minimal` are `off`. */
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" && isThinkingLevel(effort)
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 lists only efforts this build does not
33
- * know, or says nothing, is left out, so what it accepts stays unknown.
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 = knownThinkingLevels(native.map(codexThinkingLevel));
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 = knownThinkingLevels(efforts(model).map(codexThinkingLevel));
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
- env: env ? { ...process.env, ...env } : process.env,
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
- /** An effort fitted to what `model` accepts, so Codex is not asked for one it lacks. */
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
- return level && accepts?.levels.length
47
- ? codexReasoningEffort(level, accepts.levels, accepts.off)
48
- : effort;
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
- params.effort = effort;
116
- next = { ...next, effort, effortSet: true };
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
- else {
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 control.
145
- ...(noThinking && { notApplied: ["thinkingLevel"] }),
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,