@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.
Files changed (256) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +4 -1
  3. package/dist/client/client.js +27 -11
  4. package/dist/client/connection.js +35 -3
  5. package/dist/core/agents/acp/acp-agent.js +91 -14
  6. package/dist/core/agents/acp/mappings.js +5 -1
  7. package/dist/core/agents/claude-code/approvals.js +3 -2
  8. package/dist/core/agents/claude-code/claude-agent.js +12 -2
  9. package/dist/core/agents/claude-code/mcp.js +9 -1
  10. package/dist/core/agents/claude-code/models.js +16 -10
  11. package/dist/core/agents/claude-code/options.js +23 -2
  12. package/dist/core/agents/claude-code/session.js +21 -1
  13. package/dist/core/agents/claude-code/tools.js +9 -4
  14. package/dist/core/agents/claude-code/turn.js +2 -0
  15. package/dist/core/agents/codex-app-server/adapter.js +2 -0
  16. package/dist/core/agents/codex-app-server/client.js +8 -5
  17. package/dist/core/agents/codex-app-server/codex-agent.js +35 -2
  18. package/dist/core/agents/codex-app-server/effort.js +13 -6
  19. package/dist/core/agents/codex-app-server/mcp.js +35 -18
  20. package/dist/core/agents/codex-app-server/models.js +10 -10
  21. package/dist/core/agents/codex-app-server/options.js +11 -2
  22. package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
  23. package/dist/core/agents/codex-app-server/session.js +11 -4
  24. package/dist/core/agents/codex-app-server/thread-settings.js +30 -11
  25. package/dist/core/agents/host-tools.js +493 -0
  26. package/dist/core/agents/mcp-config.js +6 -2
  27. package/dist/core/agents/scripted/scripted-agent.js +39 -6
  28. package/dist/core/agents/scripted/steps.js +5 -1
  29. package/dist/core/agents/session-agent.js +70 -2
  30. package/dist/core/agents/thinking-levels.js +8 -5
  31. package/dist/core/index.js +1 -0
  32. package/dist/core/presets.js +16 -3
  33. package/dist/core/processes/lifeline.js +9 -5
  34. package/dist/core/provision/pins.js +7 -16
  35. package/dist/core/provision/releases.js +25 -25
  36. package/dist/core/proxy/loopback.js +22 -4
  37. package/dist/core/runtime/agent-runtime.js +15 -5
  38. package/dist/core/runtime/event-processor.js +13 -8
  39. package/dist/core/runtime/origin-line.js +42 -0
  40. package/dist/core/runtime/request-broker.js +2 -1
  41. package/dist/core/runtime/steering.js +4 -3
  42. package/dist/core/runtime/turn.js +6 -4
  43. package/dist/operator/errors.js +97 -0
  44. package/dist/operator/index.js +10 -5
  45. package/dist/operator/mcp.js +7 -12
  46. package/dist/operator/operator.js +1336 -380
  47. package/dist/operator/refs.js +59 -0
  48. package/dist/operator/render.js +171 -74
  49. package/dist/operator/session-tools.js +87 -0
  50. package/dist/operator/types.js +30 -0
  51. package/dist/operator/view.js +82 -27
  52. package/dist/protocol/config.js +33 -6
  53. package/dist/protocol/conversation.js +3 -0
  54. package/dist/protocol/history.js +2 -1
  55. package/dist/protocol/index.js +1 -0
  56. package/dist/protocol/lifecycle.js +19 -0
  57. package/dist/protocol/model-catalog.js +58 -18
  58. package/dist/protocol/models.js +6 -27
  59. package/dist/protocol/origin.js +39 -0
  60. package/dist/protocol/reduce.js +2 -0
  61. package/dist/protocol/thinking.js +22 -9
  62. package/dist/protocol/wire-api.js +2 -2
  63. package/dist/protocol/wire.js +17 -0
  64. package/dist/server/bin.js +6 -4
  65. package/dist/server/routes.js +15 -5
  66. package/dist/types/client/client.d.ts.map +1 -1
  67. package/dist/types/client/connection.d.ts +14 -2
  68. package/dist/types/client/connection.d.ts.map +1 -1
  69. package/dist/types/client/turns.d.ts +2 -2
  70. package/dist/types/client/turns.d.ts.map +1 -1
  71. package/dist/types/core/agents/acp/acp-agent.d.ts +15 -0
  72. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  73. package/dist/types/core/agents/acp/mappings.d.ts +5 -1
  74. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  75. package/dist/types/core/agents/acp/requests.d.ts +2 -0
  76. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  77. package/dist/types/core/agents/base.d.ts +2 -0
  78. package/dist/types/core/agents/base.d.ts.map +1 -1
  79. package/dist/types/core/agents/claude-code/approvals.d.ts +2 -1
  80. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  81. package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -0
  82. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  83. package/dist/types/core/agents/claude-code/mcp.d.ts +8 -1
  84. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  85. package/dist/types/core/agents/claude-code/models.d.ts +9 -5
  86. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  87. package/dist/types/core/agents/claude-code/options.d.ts +10 -1
  88. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  89. package/dist/types/core/agents/claude-code/session.d.ts +2 -0
  90. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  91. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  92. package/dist/types/core/agents/claude-code/turn.d.ts +3 -0
  93. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
  94. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  95. package/dist/types/core/agents/codex-app-server/client.d.ts +2 -0
  96. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  97. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +11 -0
  98. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  99. package/dist/types/core/agents/codex-app-server/effort.d.ts +7 -7
  100. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  101. package/dist/types/core/agents/codex-app-server/mcp.d.ts +11 -3
  102. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  103. package/dist/types/core/agents/codex-app-server/models.d.ts +4 -1
  104. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  105. package/dist/types/core/agents/codex-app-server/options.d.ts +9 -2
  106. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  107. package/dist/types/core/agents/codex-app-server/requests.d.ts +2 -0
  108. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  109. package/dist/types/core/agents/codex-app-server/session.d.ts +6 -3
  110. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  111. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  112. package/dist/types/core/agents/host-tools.d.ts +162 -0
  113. package/dist/types/core/agents/host-tools.d.ts.map +1 -0
  114. package/dist/types/core/agents/mcp-config.d.ts +11 -2
  115. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  116. package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
  117. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  118. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -1
  119. package/dist/types/core/agents/session-agent.d.ts +2 -7
  120. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  121. package/dist/types/core/agents/thinking-levels.d.ts +7 -3
  122. package/dist/types/core/agents/thinking-levels.d.ts.map +1 -1
  123. package/dist/types/core/index.d.ts +1 -0
  124. package/dist/types/core/index.d.ts.map +1 -1
  125. package/dist/types/core/presets.d.ts +11 -1
  126. package/dist/types/core/presets.d.ts.map +1 -1
  127. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  128. package/dist/types/core/provision/pins.d.ts +5 -4
  129. package/dist/types/core/provision/pins.d.ts.map +1 -1
  130. package/dist/types/core/proxy/loopback.d.ts.map +1 -1
  131. package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
  132. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  133. package/dist/types/core/runtime/event-processor.d.ts +2 -2
  134. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  135. package/dist/types/core/runtime/origin-line.d.ts +15 -0
  136. package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
  137. package/dist/types/core/runtime/request-broker.d.ts +1 -1
  138. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  139. package/dist/types/core/runtime/steering.d.ts +7 -4
  140. package/dist/types/core/runtime/steering.d.ts.map +1 -1
  141. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  142. package/dist/types/operator/errors.d.ts +83 -0
  143. package/dist/types/operator/errors.d.ts.map +1 -0
  144. package/dist/types/operator/index.d.ts +10 -5
  145. package/dist/types/operator/index.d.ts.map +1 -1
  146. package/dist/types/operator/mcp.d.ts +1 -1
  147. package/dist/types/operator/mcp.d.ts.map +1 -1
  148. package/dist/types/operator/operator.d.ts +15 -197
  149. package/dist/types/operator/operator.d.ts.map +1 -1
  150. package/dist/types/operator/refs.d.ts +25 -0
  151. package/dist/types/operator/refs.d.ts.map +1 -0
  152. package/dist/types/operator/render.d.ts +59 -19
  153. package/dist/types/operator/render.d.ts.map +1 -1
  154. package/dist/types/operator/session-tools.d.ts +61 -0
  155. package/dist/types/operator/session-tools.d.ts.map +1 -0
  156. package/dist/types/operator/types.d.ts +441 -0
  157. package/dist/types/operator/types.d.ts.map +1 -0
  158. package/dist/types/operator/view.d.ts +19 -29
  159. package/dist/types/operator/view.d.ts.map +1 -1
  160. package/dist/types/protocol/config.d.ts +32 -24
  161. package/dist/types/protocol/config.d.ts.map +1 -1
  162. package/dist/types/protocol/conversation.d.ts +48 -39
  163. package/dist/types/protocol/conversation.d.ts.map +1 -1
  164. package/dist/types/protocol/execution.d.ts +2 -18
  165. package/dist/types/protocol/execution.d.ts.map +1 -1
  166. package/dist/types/protocol/history.d.ts +1 -1
  167. package/dist/types/protocol/history.d.ts.map +1 -1
  168. package/dist/types/protocol/index.d.ts +1 -0
  169. package/dist/types/protocol/index.d.ts.map +1 -1
  170. package/dist/types/protocol/lifecycle.d.ts +48 -74
  171. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  172. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  173. package/dist/types/protocol/models.d.ts +4 -42
  174. package/dist/types/protocol/models.d.ts.map +1 -1
  175. package/dist/types/protocol/origin.d.ts +49 -0
  176. package/dist/types/protocol/origin.d.ts.map +1 -0
  177. package/dist/types/protocol/reduce.d.ts.map +1 -1
  178. package/dist/types/protocol/thinking.d.ts +19 -19
  179. package/dist/types/protocol/thinking.d.ts.map +1 -1
  180. package/dist/types/protocol/wire-api.d.ts +59 -106
  181. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  182. package/dist/types/protocol/wire.d.ts +81 -119
  183. package/dist/types/protocol/wire.d.ts.map +1 -1
  184. package/dist/types/server/routes.d.ts.map +1 -1
  185. package/docs/consuming.md +124 -132
  186. package/docs/deploy.md +6 -5
  187. package/docs/harnesses.md +79 -31
  188. package/docs/sync-history.md +2 -1
  189. package/package.json +4 -4
  190. package/src/client/client.ts +36 -9
  191. package/src/client/connection.ts +31 -1
  192. package/src/client/turns.ts +2 -1
  193. package/src/core/agents/acp/acp-agent.ts +123 -17
  194. package/src/core/agents/acp/mappings.ts +5 -1
  195. package/src/core/agents/acp/requests.ts +2 -0
  196. package/src/core/agents/base.ts +2 -0
  197. package/src/core/agents/claude-code/approvals.ts +4 -3
  198. package/src/core/agents/claude-code/claude-agent.ts +14 -2
  199. package/src/core/agents/claude-code/mcp.ts +11 -1
  200. package/src/core/agents/claude-code/models.ts +15 -10
  201. package/src/core/agents/claude-code/options.ts +33 -3
  202. package/src/core/agents/claude-code/session.ts +26 -1
  203. package/src/core/agents/claude-code/tools.ts +10 -4
  204. package/src/core/agents/claude-code/turn.ts +4 -0
  205. package/src/core/agents/codex-app-server/adapter.ts +2 -0
  206. package/src/core/agents/codex-app-server/client.ts +11 -5
  207. package/src/core/agents/codex-app-server/codex-agent.ts +45 -1
  208. package/src/core/agents/codex-app-server/effort.ts +15 -20
  209. package/src/core/agents/codex-app-server/mcp.ts +46 -23
  210. package/src/core/agents/codex-app-server/models.ts +10 -10
  211. package/src/core/agents/codex-app-server/options.ts +16 -2
  212. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  213. package/src/core/agents/codex-app-server/requests.ts +2 -0
  214. package/src/core/agents/codex-app-server/session.ts +19 -4
  215. package/src/core/agents/codex-app-server/thread-settings.ts +31 -11
  216. package/src/core/agents/host-tools.ts +649 -0
  217. package/src/core/agents/mcp-config.ts +15 -3
  218. package/src/core/agents/scripted/scripted-agent.ts +51 -5
  219. package/src/core/agents/scripted/steps.ts +5 -1
  220. package/src/core/agents/session-agent.ts +78 -2
  221. package/src/core/agents/thinking-levels.ts +9 -6
  222. package/src/core/index.ts +9 -0
  223. package/src/core/presets.ts +28 -4
  224. package/src/core/processes/lifeline.ts +9 -5
  225. package/src/core/provision/pins.ts +7 -16
  226. package/src/core/provision/releases.ts +25 -25
  227. package/src/core/proxy/loopback.ts +25 -4
  228. package/src/core/runtime/agent-runtime.ts +31 -7
  229. package/src/core/runtime/event-processor.ts +13 -6
  230. package/src/core/runtime/origin-line.ts +43 -0
  231. package/src/core/runtime/request-broker.ts +2 -0
  232. package/src/core/runtime/steering.ts +8 -4
  233. package/src/core/runtime/turn.ts +11 -4
  234. package/src/operator/errors.ts +218 -0
  235. package/src/operator/index.ts +18 -23
  236. package/src/operator/mcp.ts +7 -16
  237. package/src/operator/operator.ts +1583 -613
  238. package/src/operator/refs.ts +75 -0
  239. package/src/operator/render.ts +208 -98
  240. package/src/operator/session-tools.ts +126 -0
  241. package/src/operator/types.ts +505 -0
  242. package/src/operator/view.ts +93 -42
  243. package/src/protocol/config.ts +36 -7
  244. package/src/protocol/conversation.ts +3 -0
  245. package/src/protocol/history.ts +2 -1
  246. package/src/protocol/index.ts +1 -0
  247. package/src/protocol/lifecycle.ts +21 -0
  248. package/src/protocol/model-catalog.ts +58 -18
  249. package/src/protocol/models.ts +6 -26
  250. package/src/protocol/origin.ts +47 -0
  251. package/src/protocol/reduce.ts +4 -0
  252. package/src/protocol/thinking.ts +27 -14
  253. package/src/protocol/wire-api.ts +2 -2
  254. package/src/protocol/wire.ts +18 -0
  255. package/src/server/bin.ts +6 -4
  256. 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 { knownThinkingLevels } from "../thinking-levels.ts";
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: knownThinkingLevels(model.supportedEffortLevels ?? []) },
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, and Claude Code then thinks at its default effort; Haiku, which
39
- * Claude Code otherwise starts thinking, does not think with it. A model known
40
- * to have no effort levels (`levels: []`, Haiku) is sent no other level, so it
41
- * is not started on adaptive thinking at an effort it has no control for; a
42
- * model whose levels are unknown (`undefined`) is sent the level as asked.
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" || levels === undefined) return { send: level };
50
- if (!levels.length) return {};
51
- const fitted = clampThinkingLevel(level, levels) ?? level;
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`, only questions and plans. Returns the SDK's own
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
- // Claude's ceiling is `max`.
448
- options.effort = config.thinkingLevel === "ultra" ? "max" : config.thinkingLevel;
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 hostServers = await this.settings.sdkMcpServers?.(spawn);
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 (2.1.288) offers, with the engine's options or a product's.
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, SDK 0.3.288, and 2.1.325 alike):
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
- const command = toolName === "Bash" ? textOf(input, "command") : undefined;
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 mcp = this.sessions.mcpFor(options);
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 lacks becomes the
18
- * nearest one it has. Without `supported`, `off` becomes `low`: no model the
19
- * pinned CLI lists accepts `none` or `minimal`, and every one accepts `low`.
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<Off extends "none" | "minimal" = "minimal">(
13
+ export function codexReasoningEffort(
22
14
  level: ThinkingLevel,
23
15
  supported?: readonly ThinkingLevel[],
24
- offEffort?: Off,
25
- ): Exclude<CodexReasoningEffort, "none" | "minimal"> | Off {
26
- const clamped = supported?.length ? clampThinkingLevel(level, supported) : undefined;
27
- const effective = clamped ?? (level === "off" ? "low" : level);
28
- return effective === "off" ? (offEffort ?? ("minimal" as Off)) : effective;
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
- server.type === "stdio"
27
- ? {
28
- command: server.command,
29
- ...(server.args && { args: server.args }),
30
- ...(server.env && { env: server.env }),
31
- }
32
- : { url: server.url, ...(server.headers && { http_headers: server.headers }) },
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 turn's servers, snapshotted before anything asynchronous can let the caller change them. */
252
- export function codexTurnMcp(options: AgentExecuteOptions, homes: CodexHomes): CodexTurnMcp {
253
- const wire = snapshotMcpServers(options.mcpServers);
254
- const servers = codexMcpServers(wire);
255
- if (homes.claim(options)) return { wire, servers };
256
- return Object.keys(servers).length ? { wire, thread: servers } : { wire };
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 = mcp.thread
357
- ? await this.startThreadServers(again)
358
- : await this.startHomeServers(mcp, again);
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 { knownThinkingLevels } from "../thinking-levels.ts";
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
- /** The level a native Codex effort is: `none` and `minimal` are `off`. */
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" && isThinkingLevel(effort)
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 lists only efforts this build does not
57
- * know, or says nothing, is left out, so what it accepts stays unknown.
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 = knownThinkingLevels(native.map(codexThinkingLevel));
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 = knownThinkingLevels(efforts(model).map(codexThinkingLevel));
159
+ const levels = listedThinkingLevels(efforts(model).map(codexThinkingLevel));
160
160
  const fallback = codexThinkingLevel(model.defaultReasoningEffort);
161
161
  return [
162
162
  {