@ai-sdk/harness-codex 1.0.95 → 1.0.97

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ai-sdk/harness-codex
2
2
 
3
+ ## 1.0.97
4
+
5
+ ### Patch Changes
6
+
7
+ - 371e954: feat(harness): add `createBridgeToken()` and `withBridgeToken()` helpers for bridge backed harness adapters
8
+ - 62f481f: fix(harness): fix bridge resolution to no longer look for an alternative path which could cause Turbopack errors
9
+ - Updated dependencies [371e954]
10
+ - Updated dependencies [87b4858]
11
+ - @ai-sdk/harness@1.0.95
12
+
13
+ ## 1.0.96
14
+
15
+ ### Patch Changes
16
+
17
+ - 8961fde: feat(harness): allow changing `model` between turns via call options
18
+ - 29786f0: fix(harness-codex): support Codex `xhigh` and `max` reasoning levels
19
+ - Updated dependencies [8961fde]
20
+ - Updated dependencies [eb59f2a]
21
+ - @ai-sdk/harness@1.0.94
22
+ - @ai-sdk/provider-utils@5.0.34
23
+
3
24
  ## 1.0.95
4
25
 
5
26
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ type CodexHarnessSettings = {
33
33
  * Reasoning effort for reasoning-capable models. Leaving this unset
34
34
  * defers to the CLI's default.
35
35
  */
36
- readonly reasoningEffort?: 'low' | 'medium' | 'high';
36
+ readonly reasoningEffort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
37
37
  /**
38
38
  * When `true`, allow the underlying runtime to use live web search.
39
39
  */
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/codex-harness.ts
2
- import { createHash, randomBytes } from "crypto";
2
+ import { createHash } from "crypto";
3
3
  import path from "path";
4
4
  import {
5
5
  commonTool,
@@ -9,6 +9,7 @@ import {
9
9
  import {
10
10
  applyCredentialForwarding,
11
11
  classifyDiskLog,
12
+ createBridgeToken,
12
13
  createSandboxCredentialEnvironment,
13
14
  createBridgeErrorHandler,
14
15
  createBridgeStartupError,
@@ -22,6 +23,7 @@ import {
22
23
  shellQuote,
23
24
  warnCredentialBrokeringUnavailable,
24
25
  waitForBridgeReady,
26
+ withBridgeToken,
25
27
  writeSkills as writeHarnessSkills
26
28
  } from "@ai-sdk/harness/utils";
27
29
  import { WebSocket } from "ws";
@@ -56,21 +58,21 @@ async function getCodexBootstrap() {
56
58
  return cachedBootstrap;
57
59
  }
58
60
  async function readBridgeAsset(name) {
59
- const candidates = [
60
- new URL(`./bridge/${name}`, import.meta.url),
61
- new URL(`../bridge/${name}`, import.meta.url)
62
- ];
63
- let lastErr;
64
- for (const url of candidates) {
65
- try {
66
- return await readFile(fileURLToPath(url), "utf8");
67
- } catch (err) {
68
- const code = err.code;
69
- if (code !== "ENOENT") throw err;
70
- lastErr = err;
71
- }
72
- }
73
- throw lastErr ?? new Error(`bridge asset not found: ${name}`);
61
+ return readFile(
62
+ fileURLToPath(
63
+ resolveBridgeAssetUrl({
64
+ name,
65
+ moduleUrl: import.meta.url
66
+ })
67
+ ),
68
+ "utf8"
69
+ );
70
+ }
71
+ function resolveBridgeAssetUrl({
72
+ name,
73
+ moduleUrl
74
+ }) {
75
+ return new URL(`./bridge/${name}`, moduleUrl);
74
76
  }
75
77
 
76
78
  // src/codex-auth.ts
@@ -175,7 +177,7 @@ import { z } from "zod/v4";
175
177
  var outboundMessageSchema = harnessV1BridgeOutboundMessageSchema;
176
178
  var startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
177
179
  instructions: z.string().optional(),
178
- reasoningEffort: z.enum(["low", "medium", "high"]).optional(),
180
+ reasoningEffort: z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
179
181
  webSearch: z.boolean().optional(),
180
182
  codexConfig: z.record(z.string(), z.unknown()).optional(),
181
183
  mcpServers: z.record(z.string(), z.unknown()).optional(),
@@ -195,7 +197,7 @@ var inboundMessageSchema = z.discriminatedUnion("type", [
195
197
  var CLI_SHIM_FILENAME = "harness-tool.mjs";
196
198
 
197
199
  // src/version.ts
198
- var VERSION = true ? "1.0.95" : "0.0.0-test";
200
+ var VERSION = true ? "1.0.97" : "0.0.0-test";
199
201
 
200
202
  // src/codex-harness.ts
201
203
  var DEFAULT_CODEX_MODEL = "gpt-5.5";
@@ -235,7 +237,7 @@ function createCodex(settings = {}) {
235
237
  lifecycleStateSchema: codexResumeStateSchema,
236
238
  getBootstrap: getCodexBootstrap,
237
239
  doStart: async (startOpts) => {
238
- const model = startOpts.model ?? settings.model ?? DEFAULT_CODEX_MODEL;
240
+ const model = settings.model ?? DEFAULT_CODEX_MODEL;
239
241
  if (startOpts.builtinToolFiltering != null) {
240
242
  throw new HarnessCapabilityUnsupportedError({
241
243
  message: "Harness 'codex' does not support built-in tool filtering controls.",
@@ -394,7 +396,7 @@ function createCodex(settings = {}) {
394
396
  sandboxSession,
395
397
  override: settings.port
396
398
  });
397
- const token = settings.mintBridgeToken == null ? randomBytes(32).toString("hex") : settings.mintBridgeToken(sandboxId);
399
+ const token = settings.mintBridgeToken == null ? createBridgeToken() : settings.mintBridgeToken(sandboxId);
398
400
  const forwardedAuthEnvironment = credentialsBrokered ? sandboxAuthEnvironment : await applyCredentialForwarding({
399
401
  environment: sandboxAuthEnvironment,
400
402
  credentialEnvironmentVariables: CODEX_CREDENTIAL_ENVIRONMENT_VARIABLES,
@@ -582,14 +584,6 @@ function openWebSocket({
582
584
  ws.once("error", onError);
583
585
  });
584
586
  }
585
- function withBridgeToken({
586
- endpoint,
587
- token
588
- }) {
589
- const bridgeUrl = new URL(endpoint.url);
590
- bridgeUrl.searchParams.set("agent_bridge_token", token);
591
- return { ...endpoint, url: bridgeUrl.toString() };
592
- }
593
587
  function createSession({
594
588
  sessionId,
595
589
  channel,
@@ -773,7 +767,6 @@ function createSession({
773
767
  return {
774
768
  sessionId,
775
769
  isResume,
776
- modelId: model,
777
770
  doPromptTurn: async (promptOpts) => {
778
771
  if (promptOpts.responseFormat?.type === "json" && promptOpts.responseFormat.schema == null) {
779
772
  throw new HarnessCapabilityUnsupportedError({
@@ -813,7 +806,7 @@ function createSession({
813
806
  tools,
814
807
  ...promptOpts.responseFormat == null ? {} : { responseFormat: promptOpts.responseFormat },
815
808
  ...promptOpts.instructions ? { instructions: promptOpts.instructions } : {},
816
- model,
809
+ model: promptOpts.model ?? model,
817
810
  reasoningEffort,
818
811
  webSearch,
819
812
  ...codexConfig == null ? {} : { codexConfig },
@@ -866,7 +859,7 @@ function createSession({
866
859
  tools,
867
860
  ...continueOpts.responseFormat == null ? {} : { responseFormat: continueOpts.responseFormat },
868
861
  ...continueOpts.instructions ? { instructions: continueOpts.instructions } : {},
869
- model,
862
+ model: continueOpts.model ?? model,
870
863
  reasoningEffort,
871
864
  webSearch,
872
865
  ...codexConfig == null ? {} : { codexConfig },
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/codex-harness.ts","../src/codex-bootstrap.ts","../src/codex-auth.ts","../src/codex-bridge-protocol.ts","../src/bridge/cli-relay.ts","../src/version.ts","../src/index.ts"],"sourcesContent":["import { createHash, randomBytes } from 'node:crypto';\nimport path from 'node:path';\nimport {\n commonTool,\n HarnessCapabilityUnsupportedError,\n harnessV1DiagnosticFromBridgeFrame,\n type HarnessV1,\n type HarnessV1DebugConfig,\n type HarnessV1BuiltinTool,\n type HarnessV1ContinueTurnState,\n type HarnessV1CredentialForwarding,\n type HarnessV1Prompt,\n type HarnessV1PromptControl,\n type HarnessV1PortEndpoint,\n type HarnessV1ResumeSessionState,\n type HarnessV1NetworkSandboxSession,\n type HarnessV1PermissionMode,\n type HarnessV1Session,\n type HarnessV1Skill,\n type HarnessV1StreamPart,\n} from '@ai-sdk/harness';\nimport {\n applyCredentialForwarding,\n classifyDiskLog,\n createSandboxCredentialEnvironment,\n createBridgeErrorHandler,\n createBridgeStartupError,\n drainBridgeProcessStream,\n forwardBridgeProcessStream,\n getRestrictedSandboxSession,\n markBridgeStarting,\n resolveSandboxDefaultWorkingDirectory,\n resolveSandboxHomeDir,\n SandboxChannel,\n shellQuote,\n warnCredentialBrokeringUnavailable,\n waitForBridgeReady,\n writeSkills as writeHarnessSkills,\n type WriteSkillsResult,\n} from '@ai-sdk/harness/utils';\nimport {\n type Experimental_SandboxProcess,\n type Experimental_SandboxSession as SandboxSession,\n} from '@ai-sdk/provider-utils';\nimport { WebSocket } from 'ws';\nimport { z } from 'zod/v4';\nimport {\n CODEX_BOOTSTRAP_DIR as BOOTSTRAP_DIR,\n getCodexBootstrap,\n} from './codex-bootstrap';\nimport {\n CODEX_CREDENTIAL_ENVIRONMENT_VARIABLES,\n createCodexRequestTransformations,\n DEFAULT_OPENAI_BASE_URL,\n resolveCodexAuthenticationMode,\n resolveCodexEnv,\n type CodexAuthenticationMode,\n} from './codex-auth';\nimport {\n outboundMessageSchema,\n type InboundMessage,\n type OutboundMessage,\n} from './codex-bridge-protocol';\nimport { CLI_SHIM_FILENAME } from './bridge/cli-relay';\nimport { VERSION } from './version';\n\ntype CodexChannel = SandboxChannel<OutboundMessage, InboundMessage>;\ntype CodexRespawnStrategy = 'replay' | 'rerun';\n\n/*\n * This intentionally is not the latest Codex model. Newer GPT-5.6 models use\n * Responses Lite, which does not expose their code-mode tools as callable\n * through the custom model provider used by the harness. Keep GPT-5.5 as the\n * default until the upstream bug is resolved:\n * https://github.com/openai/codex/issues/31894\n *\n * Passing the model explicitly keeps the runtime behavior deterministic and\n * the telemetry (`gen_ai.request.model`) accurate.\n */\nconst DEFAULT_CODEX_MODEL = 'gpt-5.5';\n\n/**\n * Value to use in User-Agent and `x-client-app` headers.\n */\nconst CODEX_CLIENT_APP = `ai-sdk/harness-codex/${VERSION}`;\n\nexport type CodexHarnessSettings = {\n readonly auth?: CodexAuthenticationMode;\n /**\n * Customizes each credential value before it is forwarded into a sandbox\n * process. This does not restrict which credentials the harness adapter can\n * discover, read, or otherwise access in the host process.\n */\n readonly credentialForwarding?: HarnessV1CredentialForwarding;\n /**\n * Additional configuration passed through to Codex as-is. Codex config keys\n * typically use snake_case and must be provided in that form. Values managed\n * by this adapter take precedence over conflicting entries.\n */\n readonly codexConfig?: Record<string, unknown>;\n /**\n * MCP server definitions keyed by server name. Each definition uses the\n * underlying runtime's native MCP server configuration format.\n */\n readonly mcpServers?: Record<string, unknown>;\n /**\n * OpenAI model id the underlying `codex` CLI should use. Leaving this unset\n * pins the adapter default (`DEFAULT_CODEX_MODEL`).\n *\n * @deprecated Use `model` on `HarnessAgent` instead.\n */\n readonly model?: string;\n /**\n * Reasoning effort for reasoning-capable models. Leaving this unset\n * defers to the CLI's default.\n */\n readonly reasoningEffort?: 'low' | 'medium' | 'high';\n /**\n * When `true`, allow the underlying runtime to use live web search.\n */\n readonly webSearch?: boolean;\n /**\n * Override the port the bridge binds inside the sandbox. By default the\n * adapter uses the first port the sandbox declares via `sandbox.ports`.\n * Only set this if the sandbox declares multiple ports and the first one\n * is reserved for something else.\n */\n readonly port?: number;\n /**\n * Override the host endpoint used to connect to the sandbox bridge. Required\n * together with `port` when using a basic sandbox session.\n */\n readonly portEndpoint?: HarnessV1PortEndpoint;\n /** Maximum milliseconds to wait for the bridge to advertise its port. Defaults to 120000. */\n readonly startupTimeoutMs?: number;\n /**\n * Creates the authentication token used by the sandbox bridge. Defaults to\n * a random 32-byte hexadecimal token.\n */\n readonly mintBridgeToken?: (sandboxId: string) => string;\n};\n\n/*\n * Every native tool the Codex CLI can invoke as a model-callable tool,\n * declared as a `ToolSet` keyed by what the bridge emits as `toolName` on\n * the wire (`commonName ?? nativeName`). Schemas reflect the `ThreadItem`\n * union in `@openai/codex-sdk`'s `dist/index.d.ts`.\n *\n * Codex's other native operations (`apply_patch`, todo planning) surface\n * only as side-effect events (`file_change`, `todo_list`) and are not\n * model-callable tools — they don't appear here.\n */\nconst CODEX_BUILTIN_TOOLS = {\n bash: commonTool('bash', {\n nativeName: 'shell',\n toolUseKind: 'bash',\n description: 'Execute a shell command',\n inputSchema: z.object({ command: z.string() }),\n }),\n webSearch: commonTool('webSearch', {\n nativeName: 'web_search',\n toolUseKind: 'readonly',\n description: 'Search the web',\n inputSchema: z.object({ query: z.string() }),\n }),\n} as const satisfies Record<string, HarnessV1BuiltinTool<any, any>>;\n\n/**\n * Live bridge coordinates returned by `doDetach()` and `doSuspendTurn()`. A\n * future process uses them to reopen a socket to the still-running bridge\n * (`attach`) instead of re-spawning it. Absent on a `doStop()` payload.\n */\nconst codexBridgeCoordsSchema = z.object({\n port: z.number(),\n token: z.string(),\n lastSeenEventId: z.number(),\n sandboxId: z.string().optional(),\n});\n\n/**\n * Schema for the adapter-specific lifecycle `data` payload Codex produces.\n * `threadId` is what `codex.resumeThread(...)` requires for the replay/rerun\n * rungs; the sandbox lookup is handled separately via\n * `provider.resumeSession({ sessionId })`. `bridge` carries live coordinates\n * for cross-process `attach` (present on `doDetach()` and `doSuspendTurn()`\n * payloads).\n */\nconst codexResumeStateSchema = z.object({\n threadId: z.string().optional(),\n turnConfigurationFingerprint: z.string().optional(),\n bridge: codexBridgeCoordsSchema.optional(),\n sandboxCredentialEnvironment: z.record(z.string(), z.string()).optional(),\n});\n\ntype CodexBridgeCoords = z.infer<typeof codexBridgeCoordsSchema>;\n\nexport function createCodex(\n settings: CodexHarnessSettings = {},\n): HarnessV1<typeof CODEX_BUILTIN_TOOLS> {\n return {\n specificationVersion: 'harness-v1',\n harnessId: 'codex',\n builtinTools: CODEX_BUILTIN_TOOLS,\n supportsBuiltinToolApprovals: false,\n lifecycleStateSchema: codexResumeStateSchema,\n getBootstrap: getCodexBootstrap,\n doStart: async startOpts => {\n const model = startOpts.model ?? settings.model ?? DEFAULT_CODEX_MODEL;\n if (startOpts.builtinToolFiltering != null) {\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' does not support built-in tool filtering controls.\",\n harnessId: 'codex',\n });\n }\n if (\n startOpts.permissionMode != null &&\n startOpts.permissionMode !== 'allow-all'\n ) {\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' does not support built-in tool approval requests; use permissionMode: 'allow-all'.\",\n harnessId: 'codex',\n });\n }\n const sandboxSession = startOpts.sandboxSession;\n const toolSafeSandboxSession =\n getRestrictedSandboxSession(sandboxSession);\n const sandboxId = 'id' in sandboxSession ? sandboxSession.id : undefined;\n validateBasicSandboxSettings({\n sandboxSession,\n port: settings.port,\n portEndpoint: settings.portEndpoint,\n });\n if (settings.mintBridgeToken != null && sandboxId == null) {\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness cannot use `mintBridgeToken` with a sandbox session that does not expose an id.',\n });\n }\n const defaultWorkingDirectory =\n await resolveSandboxDefaultWorkingDirectory({\n sandboxSession,\n abortSignal: startOpts.abortSignal,\n });\n const lifecycleState = startOpts.continueFrom ?? startOpts.resumeFrom;\n const isResume = lifecycleState != null;\n const isContinue = startOpts.continueFrom != null;\n const resumeData =\n isResume && typeof lifecycleState?.data === 'object'\n ? (lifecycleState.data as {\n threadId?: unknown;\n turnConfigurationFingerprint?: unknown;\n bridge?: CodexBridgeCoords;\n sandboxCredentialEnvironment?: Record<string, string>;\n })\n : undefined;\n const resumeThreadId = resumeData?.threadId;\n const resumeThreadIdString =\n typeof resumeThreadId === 'string' && resumeThreadId.length > 0\n ? resumeThreadId\n : undefined;\n const turnConfigurationFingerprint =\n typeof resumeData?.turnConfigurationFingerprint === 'string'\n ? resumeData.turnConfigurationFingerprint\n : undefined;\n const coords = resumeData?.bridge;\n const authenticationMode = resolveCodexAuthenticationMode(settings.auth);\n const resolvedAuthEnvironment = resolveCodexEnv(settings.auth);\n let sandboxAuthEnvironment = resolvedAuthEnvironment;\n let sandboxCredentialEnvironment: Record<string, string> | undefined;\n let credentialsBrokered = false;\n if (\n 'addRequestTransformations' in sandboxSession &&\n sandboxSession.addRequestTransformations != null\n ) {\n sandboxCredentialEnvironment =\n resumeData?.sandboxCredentialEnvironment ??\n (await createSandboxCredentialEnvironment({\n environment: resolvedAuthEnvironment,\n credentialEnvironmentVariables:\n CODEX_CREDENTIAL_ENVIRONMENT_VARIABLES,\n credentialForwarding: settings.credentialForwarding,\n }));\n sandboxAuthEnvironment = {\n ...resolvedAuthEnvironment,\n ...sandboxCredentialEnvironment,\n };\n const requestTransformations = createCodexRequestTransformations({\n env: resolvedAuthEnvironment,\n sandboxEnv: sandboxAuthEnvironment,\n auth: authenticationMode,\n });\n if (requestTransformations.length > 0) {\n await sandboxSession.addRequestTransformations(\n requestTransformations,\n );\n }\n credentialsBrokered = true;\n if (\n requestTransformations.length > 0 &&\n authenticationMode === 'direct' &&\n resolvedAuthEnvironment.OPENAI_BASE_URL == null\n ) {\n /*\n * Vercel Sandbox request transformations apply only to HTTP traffic.\n * Materializing Codex's standard OpenAI URL makes the bridge select\n * its custom provider, where WebSockets are disabled, while keeping\n * the non-brokered path on Codex's built-in OpenAI provider.\n */\n sandboxAuthEnvironment.OPENAI_BASE_URL = DEFAULT_OPENAI_BASE_URL;\n }\n } else {\n warnCredentialBrokeringUnavailable();\n }\n const bootstrapDir = path.posix.resolve(\n defaultWorkingDirectory,\n BOOTSTRAP_DIR,\n );\n\n const workDir = startOpts.sessionWorkDir;\n const sandboxHomeDir = await resolveSandboxHomeDir({\n sandbox: toolSafeSandboxSession,\n abortSignal: startOpts.abortSignal,\n });\n const sessionDataDir = `${defaultWorkingDirectory}/.agent-runs/${startOpts.sessionId}`;\n const bridgeStateDir = `${sessionDataDir}/bridge`;\n const cliShimDir = `${sessionDataDir}/codex`;\n const cliShimPath = `${cliShimDir}/${CLI_SHIM_FILENAME}`;\n const timeoutMs = settings.startupTimeoutMs ?? 120_000;\n\n // Normalize each forwarded bridge diagnostics frame into the general\n // `HarnessV1Diagnostic` and report it. The adapter does no telemetry work\n // beyond this transport→emission mapping.\n const report = startOpts.observability?.report;\n const onDiagnostic = report\n ? (frame: Parameters<typeof harnessV1DiagnosticFromBridgeFrame>[0]) =>\n report(\n harnessV1DiagnosticFromBridgeFrame(frame, {\n sessionId: startOpts.sessionId,\n timestamp: Date.now(),\n }),\n )\n : undefined;\n const onBridgeError = createBridgeErrorHandler({\n harnessId: 'codex',\n sessionId: startOpts.sessionId,\n });\n\n /*\n * Rung 1 — ATTACH. With live coordinates, reopen a socket to the\n * still-running bridge. Parked between-turn sessions just attach and wait\n * for the next `start`; suspended in-flight turns request replay of\n * everything past the persisted cursor. No spawn, no fresh token. If the\n * bridge is gone the open throws and we fall through to a spawn-based\n * recovery.\n */\n if (coords) {\n try {\n const endpoint = await resolveBridgeEndpoint({\n sandboxSession,\n override: settings.portEndpoint,\n port: coords.port,\n });\n const attachEndpoint = withBridgeToken({\n endpoint,\n token: coords.token,\n });\n const attachChannel: CodexChannel = new SandboxChannel({\n connect: () => openWebSocket(attachEndpoint),\n outboundSchema: outboundMessageSchema,\n initialLastSeenEventId: coords.lastSeenEventId,\n onDiagnostic,\n onBridgeError,\n });\n await attachChannel.open(isContinue ? { resume: true } : undefined);\n return createSession({\n sessionId: startOpts.sessionId,\n channel: attachChannel,\n cliShimPath,\n // The live bridge was spawned by another process; no process handle.\n proc: undefined,\n model,\n reasoningEffort: settings.reasoningEffort,\n webSearch: settings.webSearch,\n codexConfig: settings.codexConfig,\n mcpServers: settings.mcpServers,\n resumeThreadId: resumeThreadIdString,\n isResume: true,\n seedResumeThreadOnFirstPrompt: false,\n rerunContinue: false,\n bridgePort: coords.port,\n bridgeToken: coords.token,\n sandboxId,\n sandboxCredentialEnvironment,\n debug: startOpts.observability?.debug,\n permissionMode: startOpts.permissionMode,\n sandbox: toolSafeSandboxSession,\n sandboxHomeDir,\n turnConfigurationFingerprint,\n });\n } catch {\n // Bridge no longer reachable — recover by respawning below.\n }\n }\n\n /*\n * Rungs 2/3 — REPLAY vs RERUN. Respawn the bridge. `replay` is only sound\n * for `continueFrom`: those coordinates include the cursor the on-disk\n * log is replayed *from*. `resumeFrom` is a between-turn resume; even when\n * it carries bridge coordinates, replaying the previous turn would\n * re-deliver stale events into the next turn. Those resumes always `rerun`\n * via `codex.resumeThread(threadId)` when attach is unavailable.\n */\n let respawnStrategy: CodexRespawnStrategy | undefined = isResume\n ? 'rerun'\n : undefined;\n if (coords && isContinue) {\n const logRaw = await Promise.resolve(\n toolSafeSandboxSession.readTextFile({\n path: `${bridgeStateDir}/event-log.ndjson`,\n abortSignal: startOpts.abortSignal,\n }),\n ).catch(() => null);\n if ((await classifyDiskLog(logRaw)) === 'replay') {\n respawnStrategy = 'replay';\n }\n }\n\n const port = resolveBridgePort({\n sandboxSession,\n override: settings.port,\n });\n const token =\n settings.mintBridgeToken == null\n ? randomBytes(32).toString('hex')\n : settings.mintBridgeToken(sandboxId!);\n const forwardedAuthEnvironment = credentialsBrokered\n ? sandboxAuthEnvironment\n : await applyCredentialForwarding({\n environment: sandboxAuthEnvironment,\n credentialEnvironmentVariables:\n CODEX_CREDENTIAL_ENVIRONMENT_VARIABLES,\n credentialForwarding: settings.credentialForwarding,\n });\n const env = {\n ...forwardedAuthEnvironment,\n AI_SDK_HARNESS_CLIENT_APP: CODEX_CLIENT_APP,\n BRIDGE_CHANNEL_TOKEN: token,\n BRIDGE_WS_PORT: String(port),\n ...(respawnStrategy === 'replay'\n ? { BRIDGE_REPLAY_FROM_DISK: '1' }\n : {}),\n };\n\n if (respawnStrategy === undefined) {\n await toolSafeSandboxSession.run({\n command: `mkdir -p ${shellQuote(workDir)} ${shellQuote(bridgeStateDir)}`,\n abortSignal: startOpts.abortSignal,\n });\n }\n\n await markBridgeStarting({\n sandbox: toolSafeSandboxSession,\n bridgeStateDir,\n bridgeType: 'codex',\n abortSignal: startOpts.abortSignal,\n });\n\n const proc = await toolSafeSandboxSession.spawn({\n command: `node ${shellQuote(`${bootstrapDir}/bridge.mjs`)} --workdir ${shellQuote(workDir)} --bridge-state-dir ${shellQuote(bridgeStateDir)} --cli-shim-dir ${shellQuote(cliShimDir)}`,\n env,\n abortSignal: startOpts.abortSignal,\n });\n const stderrTail: string[] = [];\n const bridgeStderrDone = forwardBridgeProcessStream({\n stream: proc.stderr,\n streamName: 'stderr',\n source: 'codex',\n collectTail: stderrTail,\n });\n\n const { port: boundPort } = await waitForBridgeReady({\n proc,\n sandbox: toolSafeSandboxSession,\n bridgeStateDir,\n bridgeType: 'codex',\n timeoutMs,\n abortSignal: startOpts.abortSignal,\n createTimeoutError: ({ proc, stdoutTail }) =>\n createBridgeStartupError({\n message: 'codex bridge did not become ready in time.',\n proc,\n stdoutTail,\n stderrTail,\n stderrDone: bridgeStderrDone,\n }),\n createExitError: ({ proc, stdoutTail }) =>\n createBridgeStartupError({\n message: 'codex bridge exited before becoming ready.',\n proc,\n stdoutTail,\n stderrTail,\n stderrDone: bridgeStderrDone,\n }),\n });\n void drainBridgeProcessStream(proc.stdout);\n\n const endpoint = await resolveBridgeEndpoint({\n sandboxSession,\n override: settings.portEndpoint,\n port: boundPort,\n });\n const bridgeEndpoint = withBridgeToken({ endpoint, token });\n\n const channel: CodexChannel = new SandboxChannel({\n connect: () => openWebSocket(bridgeEndpoint),\n outboundSchema: outboundMessageSchema,\n onDiagnostic,\n onBridgeError,\n // In replay mode the respawned bridge reloaded the finished turn from\n // disk; seed the cursor and resume so it streams the tail (incl.\n // `finish`).\n ...(respawnStrategy === 'replay'\n ? { initialLastSeenEventId: coords?.lastSeenEventId ?? 0 }\n : {}),\n });\n await channel.open(\n respawnStrategy === 'replay' ? { resume: true } : undefined,\n );\n\n return createSession({\n sessionId: startOpts.sessionId,\n channel,\n cliShimPath,\n proc,\n model,\n reasoningEffort: settings.reasoningEffort,\n webSearch: settings.webSearch,\n codexConfig: settings.codexConfig,\n mcpServers: settings.mcpServers,\n resumeThreadId: resumeThreadIdString,\n isResume: respawnStrategy !== undefined,\n seedResumeThreadOnFirstPrompt: respawnStrategy !== undefined,\n rerunContinue: respawnStrategy === 'rerun',\n bridgePort: boundPort,\n bridgeToken: token,\n sandboxId,\n sandboxCredentialEnvironment,\n debug: startOpts.observability?.debug,\n permissionMode: startOpts.permissionMode,\n sandbox: toolSafeSandboxSession,\n sandboxHomeDir,\n turnConfigurationFingerprint,\n });\n },\n };\n}\n\nfunction resolveBridgePort({\n sandboxSession,\n override,\n}: {\n sandboxSession: HarnessV1NetworkSandboxSession | SandboxSession;\n override: number | undefined;\n}): number {\n if (override !== undefined) return override;\n if ('ports' in sandboxSession && sandboxSession.ports.length > 0) {\n return sandboxSession.ports[0];\n }\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness needs a TCP port exposed by the sandbox. ' +\n 'Create the sandbox with `ports: [<port>]` or pass `createCodex({ port })`.',\n });\n}\n\nfunction validateBasicSandboxSettings({\n sandboxSession,\n port,\n portEndpoint,\n}: {\n sandboxSession: HarnessV1NetworkSandboxSession | SandboxSession;\n port: number | undefined;\n portEndpoint: HarnessV1PortEndpoint | undefined;\n}): void {\n if ('getPortEndpoint' in sandboxSession) return;\n if (port == null) {\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness requires an explicit `port` when using a basic sandbox session.',\n });\n }\n if (portEndpoint == null) {\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness requires an explicit `portEndpoint` when using a basic sandbox session.',\n });\n }\n}\n\nasync function resolveBridgeEndpoint({\n sandboxSession,\n override,\n port,\n}: {\n sandboxSession: HarnessV1NetworkSandboxSession | SandboxSession;\n override: HarnessV1PortEndpoint | undefined;\n port: number;\n}): Promise<HarnessV1PortEndpoint> {\n if (override != null) return override;\n if ('getPortEndpoint' in sandboxSession) {\n return sandboxSession.getPortEndpoint({ port, protocol: 'ws' });\n }\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness requires an explicit `portEndpoint` when using a basic sandbox session.',\n });\n}\n\nasync function writeCodexSkills({\n sandbox,\n sandboxHomeDir,\n skills,\n abortSignal,\n}: {\n sandbox: SandboxSession;\n sandboxHomeDir: string;\n skills: ReadonlyArray<HarnessV1Skill>;\n abortSignal?: AbortSignal;\n}): Promise<WriteSkillsResult> {\n const rootDir = path.posix.join(sandboxHomeDir, '.agents', 'skills');\n return writeHarnessSkills({\n sandbox,\n rootDir,\n skills,\n abortSignal,\n invalidSkillNameMessage: ({ name }) => `Invalid Codex skill name: ${name}`,\n invalidSkillFilePathMessage: ({ skillName, filePath }) =>\n `Invalid Codex skill file path for ${skillName}: ${filePath}`,\n });\n}\n\nfunction openWebSocket({\n url,\n headers,\n}: HarnessV1PortEndpoint): Promise<WebSocket> {\n return new Promise((resolve, reject) => {\n const ws = new WebSocket(url, {\n headers: headers == null ? undefined : { ...headers },\n });\n const onOpen = () => {\n ws.off('error', onError);\n resolve(ws);\n };\n const onError = (err: Error) => {\n ws.off('open', onOpen);\n reject(err);\n };\n ws.once('open', onOpen);\n ws.once('error', onError);\n });\n}\n\nfunction withBridgeToken({\n endpoint,\n token,\n}: {\n endpoint: HarnessV1PortEndpoint;\n token: string;\n}): HarnessV1PortEndpoint {\n const bridgeUrl = new URL(endpoint.url);\n bridgeUrl.searchParams.set('agent_bridge_token', token);\n return { ...endpoint, url: bridgeUrl.toString() };\n}\n\nfunction createSession({\n sessionId,\n channel,\n cliShimPath,\n proc,\n model,\n reasoningEffort,\n webSearch,\n codexConfig,\n mcpServers,\n resumeThreadId,\n isResume,\n seedResumeThreadOnFirstPrompt,\n rerunContinue,\n bridgePort,\n bridgeToken,\n sandboxId,\n sandboxCredentialEnvironment,\n debug,\n permissionMode,\n sandbox,\n sandboxHomeDir,\n turnConfigurationFingerprint,\n}: {\n sessionId: string;\n channel: CodexChannel;\n cliShimPath: string;\n /** Undefined on `attach` — the live bridge was spawned by another process. */\n proc: Experimental_SandboxProcess | undefined;\n model: string | undefined;\n reasoningEffort: 'low' | 'medium' | 'high' | undefined;\n webSearch: boolean | undefined;\n codexConfig: Record<string, unknown> | undefined;\n mcpServers: Record<string, unknown> | undefined;\n resumeThreadId: string | undefined;\n isResume: boolean;\n seedResumeThreadOnFirstPrompt: boolean;\n rerunContinue: boolean;\n bridgePort: number;\n bridgeToken: string;\n sandboxId: string | undefined;\n sandboxCredentialEnvironment: Record<string, string> | undefined;\n debug: HarnessV1DebugConfig | undefined;\n permissionMode: HarnessV1PermissionMode | undefined;\n sandbox: SandboxSession;\n sandboxHomeDir: string;\n turnConfigurationFingerprint: string | undefined;\n}): HarnessV1Session {\n let stopped = false;\n let stopPromise: Promise<void> | undefined;\n /*\n * Send the persisted threadId on the first prompt only when the bridge was\n * respawned (rerun/replay) so it takes the `codex.resumeThread(...)` branch.\n * An `attach`ed bridge already holds its threadState in memory and continues\n * on its own, so it needs no seed.\n */\n let pendingResumeThreadId = seedResumeThreadOnFirstPrompt\n ? resumeThreadId\n : undefined;\n /*\n * Host-tool relay guidance is prepended to the first user message of a fresh\n * session only. A resumed session (attach/replay/rerun) already carried it in\n * its original first message (preserved in the persisted thread), so it\n * starts \"applied\".\n */\n let initialPromptGuidanceApplied = isResume;\n\n /*\n * Latest codex thread id, cached from the bridge's `bridge-thread`\n * announcements. Seeded from lifecycle state so `doDetach()` and `doStop()`\n * can include a thread id even before this process has run a turn.\n */\n let latestThreadId = resumeThreadId;\n let latestTurnConfigurationFingerprint = turnConfigurationFingerprint;\n channel.on('bridge-thread', msg => {\n latestThreadId = msg.threadId;\n });\n\n const synchronizeTurnConfiguration = async ({\n skills,\n instructions,\n tools,\n abortSignal,\n }: {\n skills: ReadonlyArray<HarnessV1Skill>;\n instructions: string | undefined;\n tools: ReadonlyArray<{\n name: string;\n description?: string;\n inputSchema: unknown;\n }>;\n abortSignal?: AbortSignal;\n }): Promise<{ restartThread: boolean }> => {\n const skillsResult = await writeCodexSkills({\n sandbox,\n sandboxHomeDir,\n skills,\n abortSignal,\n });\n const nextFingerprint = fingerprintCodexTurnConfiguration({\n instructions,\n tools,\n });\n const restartThread =\n latestThreadId != null &&\n (skillsResult.changed ||\n (latestTurnConfigurationFingerprint != null &&\n latestTurnConfigurationFingerprint !== nextFingerprint));\n latestTurnConfigurationFingerprint = nextFingerprint;\n if (restartThread) {\n /*\n * `codex exec resume` retains the native thread's original developer\n * instructions and skill catalog. A fresh native thread is therefore\n * required for replacement semantics. Host-tool guidance is framed\n * again because that guidance also belongs to the new native thread.\n */\n initialPromptGuidanceApplied = false;\n pendingResumeThreadId = undefined;\n }\n return { restartThread };\n };\n\n /*\n * Wire the channel into one turn's worth of events and return the control\n * surface. Shared by `doPromptTurn` (which sends a `start` afterwards) and\n * `doContinueTurn` (which attaches to an already-running/replayed turn, or sends\n * a rerun `start`). The only difference between the two entry points is the\n * `start` message, not the listener/abort/settle plumbing.\n */\n const wireTurn = (turnOpts: {\n emit: (event: HarnessV1StreamPart) => void;\n abortSignal?: AbortSignal;\n }): {\n control: HarnessV1PromptControl;\n sendStart: (send: () => void) => void;\n } => {\n let pendingResolve: (() => void) | undefined;\n let pendingReject: ((err: unknown) => void) | undefined;\n const done = new Promise<void>((resolve, reject) => {\n pendingResolve = resolve;\n pendingReject = reject;\n });\n\n const unsubs: Array<() => void> = [];\n const forward = (event: HarnessV1StreamPart) => {\n try {\n turnOpts.emit(event);\n } catch {}\n };\n\n const eventTypes = [\n 'stream-start',\n 'text-start',\n 'text-delta',\n 'text-end',\n 'reasoning-start',\n 'reasoning-delta',\n 'reasoning-end',\n 'tool-call',\n 'tool-approval-request',\n 'tool-result',\n 'file-change',\n 'finish-step',\n 'raw',\n ] as const;\n let isSettled = false;\n const settleSuccess = () => {\n if (isSettled) return;\n isSettled = true;\n for (const u of unsubs) u();\n pendingResolve!();\n };\n const settleError = (err: unknown) => {\n if (isSettled) return;\n isSettled = true;\n for (const u of unsubs) u();\n pendingReject!(err);\n };\n\n for (const type of eventTypes) {\n unsubs.push(\n channel.on(type, msg => {\n forward(msg);\n }),\n );\n }\n unsubs.push(\n channel.on('finish', msg => {\n forward(msg);\n settleSuccess();\n }),\n );\n unsubs.push(\n channel.on('error', msg => {\n forward(msg);\n settleError(msg.error);\n }),\n );\n\n /*\n * A `'suspended'` close is a graceful slice-boundary freeze the host\n * initiated (`doSuspendTurn`): the turn keeps running in the bridge and its\n * tail is replayed to the next process, so wind this turn down cleanly\n * rather than failing it. Any other close mid-turn is an unexpected drop.\n */\n const onClose = (_code?: number, reason?: string) => {\n if (isSettled) return;\n if (reason === 'suspended') {\n settleSuccess();\n return;\n }\n settleError(new Error('codex bridge closed before the turn finished.'));\n };\n channel.onClose(onClose);\n\n const onAbort = () => {\n if (isSettled) return;\n try {\n channel.send({ type: 'abort' });\n } catch {}\n settleError(\n turnOpts.abortSignal?.reason ??\n new DOMException('Aborted', 'AbortError'),\n );\n };\n if (turnOpts.abortSignal) {\n if (turnOpts.abortSignal.aborted) {\n onAbort();\n } else {\n turnOpts.abortSignal.addEventListener('abort', onAbort, {\n once: true,\n });\n }\n }\n\n const control: HarnessV1PromptControl = {\n submitToolResult: async input => {\n channel.send({\n type: 'tool-result',\n toolCallId: input.toolCallId,\n output: input.output,\n isError: input.isError,\n });\n },\n submitToolApproval: async input => {\n channel.send({\n type: 'tool-approval-response',\n approvalId: input.approvalId,\n approved: input.approved,\n reason: input.reason,\n });\n },\n done,\n };\n\n return {\n control,\n sendStart: send => {\n /*\n * Codex can complete short turns without using tools. Deferring the\n * start frame gives the harness runner one event-loop turn to finish\n * wiring the prompt control and stream output before Codex can settle.\n */\n const timer = setTimeout(() => {\n if (isSettled) return;\n try {\n send();\n } catch (err) {\n settleError(err);\n }\n }, 0);\n timer.unref?.();\n },\n };\n };\n\n return {\n sessionId,\n isResume,\n modelId: model,\n doPromptTurn: async promptOpts => {\n if (\n promptOpts.responseFormat?.type === 'json' &&\n promptOpts.responseFormat.schema == null\n ) {\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' requires a JSON schema for structured output.\",\n harnessId: 'codex',\n });\n }\n const tools = (promptOpts.tools ?? []).map(t => ({\n name: t.name,\n description: t.description,\n inputSchema: t.inputSchema,\n }));\n const { restartThread } = await synchronizeTurnConfiguration({\n skills: promptOpts.skills,\n instructions: promptOpts.instructions,\n tools,\n abortSignal: promptOpts.abortSignal,\n });\n const turn = wireTurn({\n emit: promptOpts.emit,\n abortSignal: promptOpts.abortSignal,\n });\n\n let promptText = extractUserText(promptOpts.prompt);\n if (!initialPromptGuidanceApplied) {\n promptText = frameInitialPromptGuidance({\n toolUsageBlock:\n tools.length > 0\n ? composeToolUsageInstructions({\n tools,\n cliShimPath,\n })\n : undefined,\n userText: promptText,\n });\n }\n initialPromptGuidanceApplied = true;\n\n const startMessage = {\n type: 'start' as const,\n prompt: promptText,\n tools,\n ...(promptOpts.responseFormat == null\n ? {}\n : { responseFormat: promptOpts.responseFormat }),\n ...(promptOpts.instructions\n ? { instructions: promptOpts.instructions }\n : {}),\n model,\n reasoningEffort,\n webSearch,\n ...(codexConfig == null ? {} : { codexConfig }),\n ...(mcpServers == null ? {} : { mcpServers }),\n ...(permissionMode ? { permissionMode } : {}),\n ...(pendingResumeThreadId\n ? { resumeThreadId: pendingResumeThreadId }\n : {}),\n ...(restartThread ? { restartThread: true } : {}),\n ...(debug ? { debug } : {}),\n };\n pendingResumeThreadId = undefined;\n turn.sendStart(() => channel.send(startMessage));\n\n return turn.control;\n },\n doContinueTurn: async continueOpts => {\n if (\n continueOpts.responseFormat?.type === 'json' &&\n continueOpts.responseFormat.schema == null\n ) {\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' requires a JSON schema for structured output.\",\n harnessId: 'codex',\n });\n }\n const tools = (continueOpts.tools ?? []).map(t => ({\n name: t.name,\n description: t.description,\n inputSchema: t.inputSchema,\n }));\n const { restartThread } = await synchronizeTurnConfiguration({\n skills: continueOpts.skills,\n instructions: continueOpts.instructions,\n tools,\n abortSignal: continueOpts.abortSignal,\n });\n const turn = wireTurn({\n emit: continueOpts.emit,\n abortSignal: continueOpts.abortSignal,\n });\n\n /*\n * attach / replay: the still-running (or disk-replayed) turn streams into\n * the wired listeners — `doStart` opened the channel with `{ resume: true }`\n * so the bridge replays everything past the persisted cursor (including a\n * `finish` if the turn ended during the gap). No `start` is sent: issuing\n * one would clear the bridge's replay log and begin a new turn. Lossless.\n *\n * rerun: the bridge was respawned with no in-flight turn to attach to, so\n * re-drive codex's own thread via `resumeThreadId`. Lossy — work in flight\n * at the suspension is recomputed. This is the rare bridge-died\n * fallback; the common slice path is `attach`.\n */\n if (rerunContinue) {\n const threadId = pendingResumeThreadId ?? latestThreadId;\n pendingResumeThreadId = undefined;\n turn.sendStart(() =>\n channel.send({\n type: 'start' as const,\n /*\n * A continuation nudge rather than an empty prompt: `resumeThreadId`\n * rehydrates the prior thread, and this is the new user turn that\n * drives it forward. Keeping it non-empty avoids handing the runtime\n * an empty user message (and mirrors the claude-code adapter, where an\n * empty text block trips the Anthropic API's `cache_control` rule).\n */\n prompt: 'Continue.',\n tools,\n ...(continueOpts.responseFormat == null\n ? {}\n : { responseFormat: continueOpts.responseFormat }),\n ...(continueOpts.instructions\n ? { instructions: continueOpts.instructions }\n : {}),\n model,\n reasoningEffort,\n webSearch,\n ...(codexConfig == null ? {} : { codexConfig }),\n ...(mcpServers == null ? {} : { mcpServers }),\n ...(permissionMode ? { permissionMode } : {}),\n ...(threadId ? { resumeThreadId: threadId } : {}),\n ...(restartThread ? { restartThread: true } : {}),\n ...(debug ? { debug } : {}),\n }),\n );\n }\n\n return turn.control;\n },\n doCompact: async () => {\n /*\n * Codex compacts its context automatically inside the core turn loop\n * (~90% of the model context window), but the `codex exec` transport this\n * adapter drives exposes no manual compaction trigger and emits no\n * compaction event. Manual `compact()` is therefore unsupported; Codex's\n * own auto-compaction continues to run regardless.\n */\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' does not support manual compaction; Codex auto-compacts its context internally.\",\n harnessId: 'codex',\n });\n },\n doDetach: async () => {\n if (stopped) {\n throw new Error(\n `codex session ${sessionId} is already stopped; cannot detach.`,\n );\n }\n stopped = true;\n const lastSeenEventId = await channel.suspend();\n const payload: HarnessV1ResumeSessionState = {\n type: 'resume-session',\n harnessId: 'codex',\n specificationVersion: 'harness-v1',\n data: {\n ...(latestThreadId ? { threadId: latestThreadId } : {}),\n ...(latestTurnConfigurationFingerprint\n ? {\n turnConfigurationFingerprint:\n latestTurnConfigurationFingerprint,\n }\n : {}),\n ...(sandboxCredentialEnvironment == null\n ? {}\n : { sandboxCredentialEnvironment }),\n bridge: {\n port: bridgePort,\n token: bridgeToken,\n lastSeenEventId,\n ...(sandboxId == null ? {} : { sandboxId }),\n },\n },\n };\n return payload;\n },\n doDestroy: async () => {\n if (stopped) return stopPromise;\n stopped = true;\n stopPromise = (async () => {\n // Tell the channel we are tearing down so the bridge's post-shutdown\n // socket close finalises instead of triggering a reconnect.\n channel.beginClose();\n try {\n if (!channel.isClosed()) {\n channel.send({ type: 'destroy' });\n }\n } catch {}\n let stopTimer: ReturnType<typeof setTimeout> | undefined;\n try {\n if (proc) {\n await Promise.race([\n proc.wait(),\n new Promise<void>(resolve => {\n stopTimer = setTimeout(resolve, 5000);\n stopTimer.unref?.();\n }),\n ]);\n }\n } finally {\n if (stopTimer) clearTimeout(stopTimer);\n try {\n await proc?.kill();\n } catch {}\n channel.close();\n }\n })();\n return stopPromise;\n },\n doStop: async () => {\n if (stopped) {\n throw new Error(\n `codex session ${sessionId} is already stopped; cannot stop.`,\n );\n }\n stopped = true;\n /*\n * If the bridge's channel already closed (e.g. mid-turn WS drop)\n * there is no one to acknowledge a `stop` message. Synthesize an empty\n * payload — the workdir is still captured by the sandbox snapshot\n * during the subsequent `sandboxSession.stop()`, so the next turn can\n * resume the filesystem state. The trade-off: we lose\n * `threadId`, so the codex CLI starts a fresh thread on the\n * preserved workdir rather than resuming the prior conversation\n * inside Codex's runtime. Ability to continue beats throwing.\n */\n // Tell the channel we are tearing down so the bridge's post-stop\n // socket close finalises instead of triggering a reconnect.\n channel.beginClose();\n const data: unknown = channel.isClosed()\n ? {}\n : await new Promise<unknown>((resolve, reject) => {\n const timer = setTimeout(() => {\n unsub();\n reject(\n new Error(\n `codex session ${sessionId} did not reply to stop within 5s.`,\n ),\n );\n }, 5000);\n timer.unref?.();\n const unsub = channel.on('bridge-stop', msg => {\n clearTimeout(timer);\n unsub();\n resolve(msg.data);\n });\n try {\n channel.send({ type: 'stop' });\n } catch (err) {\n clearTimeout(timer);\n unsub();\n reject(err);\n }\n });\n\n let stopTimer: ReturnType<typeof setTimeout> | undefined;\n try {\n if (proc) {\n await Promise.race([\n proc.wait(),\n new Promise<void>(resolve => {\n stopTimer = setTimeout(resolve, 5000);\n stopTimer.unref?.();\n }),\n ]);\n }\n } finally {\n if (stopTimer) clearTimeout(stopTimer);\n try {\n await proc?.kill();\n } catch {}\n channel.close();\n }\n\n const lifecycleData =\n data != null && typeof data === 'object' && !Array.isArray(data)\n ? { ...(data as Record<string, unknown>) }\n : {};\n const payload: HarnessV1ResumeSessionState = {\n type: 'resume-session',\n harnessId: 'codex',\n specificationVersion: 'harness-v1',\n data: {\n ...lifecycleData,\n ...(latestTurnConfigurationFingerprint\n ? {\n turnConfigurationFingerprint:\n latestTurnConfigurationFingerprint,\n }\n : {}),\n ...(sandboxCredentialEnvironment == null\n ? {}\n : { sandboxCredentialEnvironment }),\n } as HarnessV1ResumeSessionState['data'],\n };\n return payload;\n },\n doSuspendTurn: async () => {\n if (stopped) {\n throw new Error(\n `codex session ${sessionId} is stopped; cannot suspend.`,\n );\n }\n stopped = true;\n /*\n * Freeze the host at a precise cursor without stopping the active model\n * turn. `channel.suspend` stops processing inbound frames, drains what\n * was already dispatched, then closes the host socket with reason\n * `'suspended'`. The bridge keeps the turn running and accumulates events\n * past the cursor for the next slice to replay. The sandbox process is\n * deliberately left alive.\n */\n const lastSeenEventId = await channel.suspend();\n const payload: HarnessV1ContinueTurnState = {\n type: 'continue-turn',\n harnessId: 'codex',\n specificationVersion: 'harness-v1',\n data: {\n ...(latestThreadId ? { threadId: latestThreadId } : {}),\n ...(latestTurnConfigurationFingerprint\n ? {\n turnConfigurationFingerprint:\n latestTurnConfigurationFingerprint,\n }\n : {}),\n ...(sandboxCredentialEnvironment == null\n ? {}\n : { sandboxCredentialEnvironment }),\n bridge: {\n port: bridgePort,\n token: bridgeToken,\n lastSeenEventId,\n ...(sandboxId == null ? {} : { sandboxId }),\n },\n },\n };\n return payload;\n },\n };\n}\n\nfunction fingerprintCodexTurnConfiguration({\n instructions,\n tools,\n}: {\n instructions: string | undefined;\n tools: ReadonlyArray<{\n name: string;\n description?: string;\n inputSchema: unknown;\n }>;\n}): string {\n return createHash('sha256')\n .update(JSON.stringify({ instructions: instructions ?? null, tools }))\n .digest('hex');\n}\n\n/*\n * Frame host-tool relay guidance and the user's text so Codex treats the\n * prepended block as operating guidance rather than user prose. Applied only\n * to the first user message of a fresh session.\n */\nfunction frameInitialPromptGuidance({\n toolUsageBlock,\n userText,\n}: {\n toolUsageBlock: string | undefined;\n userText: string;\n}): string {\n const blocks: string[] = [];\n if (toolUsageBlock) blocks.push(toolUsageBlock);\n if (blocks.length === 0) return userText;\n return `${blocks.join('\\n\\n')}\\n\\n<user-message>\\n${userText}\\n</user-message>`;\n}\n\nfunction composeToolUsageInstructions({\n tools,\n cliShimPath,\n}: {\n tools: ReadonlyArray<{\n name: string;\n description?: string;\n inputSchema?: unknown;\n }>;\n cliShimPath: string;\n}): string {\n const lines: string[] = [\n '<host-tool-instructions>',\n 'You have access to the following host-provided tools. To use one, run the following command via your built-in `bash` tool:',\n '',\n ` node ${cliShimPath} <toolName> '<jsonInput>'`,\n '',\n 'The script prints the JSON result to stdout. Do not invent another way to call these tools — only this CLI invocation will work. Pass the JSON input as a single-quoted argument.',\n 'For every user request that depends on a host-provided tool, run a separate CLI invocation for each needed tool call in the current turn before answering. Do not reuse previous tool results, and do not say you used a host tool unless the command has completed in the current turn.',\n '',\n ];\n for (const toolSpec of tools) {\n lines.push(\n `- **${toolSpec.name}**${toolSpec.description ? ': ' + toolSpec.description : ''}`,\n );\n lines.push(\n ` - Input schema: \\`${JSON.stringify(toolSpec.inputSchema ?? {})}\\``,\n );\n }\n lines.push('</host-tool-instructions>');\n return lines.join('\\n');\n}\n\n/*\n * Reduce a `HarnessV1Prompt` to the plain user text the bridge forwards\n * to the Codex SDK. File and image parts on the message are not yet\n * supported by the underlying runtime — throw rather than silently drop\n * them so callers learn about the gap instead of seeing mysteriously\n * truncated prompts.\n */\nfunction extractUserText(prompt: HarnessV1Prompt): string {\n if (typeof prompt === 'string') return prompt;\n const { content } = prompt;\n if (typeof content === 'string') return content;\n const parts: string[] = [];\n for (const part of content) {\n if (part.type !== 'text') {\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message: `The codex harness does not yet support user message parts of type '${part.type}'. Pass a string or a user message whose content contains only text parts.`,\n });\n }\n parts.push(part.text);\n }\n return parts.join('\\n\\n');\n}\n","import { readFile } from 'node:fs/promises';\nimport { fileURLToPath } from 'node:url';\nimport type { HarnessV1Bootstrap } from '@ai-sdk/harness';\n\n/*\n * Bootstrap is derived state stored under the sandbox's default working\n * directory so snapshot-capable providers can preserve the installed CLI,\n * bridge, and recipe marker without requiring root filesystem access.\n *\n * The session work dir (`startOpts.sessionWorkDir`) lives under the sandbox's\n * default working directory — the provider's persistent mount — so any files\n * the agent edits survive both detach -> attach and stop -> snapshot -> resume\n * cycles. Harness infra derived from `sandboxSession.defaultWorkingDirectory`\n * lives under `.agent-runs`, outside the agent workdir.\n */\nexport const CODEX_BOOTSTRAP_DIR = '.harness-bootstrap/codex';\n\nlet cachedBootstrap: HarnessV1Bootstrap | undefined;\n\nexport async function getCodexBootstrap(): Promise<HarnessV1Bootstrap> {\n if (cachedBootstrap != null) return cachedBootstrap;\n const [pkg, lock, bridge] = await Promise.all([\n readBridgeAsset('package.json'),\n readBridgeAsset('pnpm-lock.yaml'),\n readBridgeAsset('index.mjs'),\n ]);\n cachedBootstrap = {\n harnessId: 'codex',\n bootstrapDir: CODEX_BOOTSTRAP_DIR,\n files: [\n { path: `${CODEX_BOOTSTRAP_DIR}/package.json`, content: pkg },\n { path: `${CODEX_BOOTSTRAP_DIR}/pnpm-lock.yaml`, content: lock },\n { path: `${CODEX_BOOTSTRAP_DIR}/bridge.mjs`, content: bridge },\n ],\n commands: [\n {\n command: 'pnpm install --frozen-lockfile --store-dir .pnpm-store',\n },\n ],\n };\n return cachedBootstrap;\n}\n\nasync function readBridgeAsset(name: string): Promise<string> {\n const candidates = [\n new URL(`./bridge/${name}`, import.meta.url),\n new URL(`../bridge/${name}`, import.meta.url),\n ];\n let lastErr: unknown;\n for (const url of candidates) {\n try {\n return await readFile(fileURLToPath(url), 'utf8');\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code !== 'ENOENT') throw err;\n lastErr = err;\n }\n }\n throw lastErr ?? new Error(`bridge asset not found: ${name}`);\n}\n","import type {\n HarnessV1Authentication,\n HarnessV1RequestTransformation,\n HarnessV1RequestTransformationSources,\n} from '@ai-sdk/harness';\nimport {\n createCredentialRequestTransformation,\n getAiGatewayAuthFromEnv,\n isHarnessAuthenticationEnvironment,\n} from '@ai-sdk/harness/utils';\n\nconst DEFAULT_AI_GATEWAY_BASE_URL = 'https://ai-gateway.vercel.sh/v1';\nexport const DEFAULT_OPENAI_BASE_URL = 'https://api.openai.com/v1';\n\nexport const CODEX_CREDENTIAL_ENVIRONMENT_VARIABLES = [\n 'AI_GATEWAY_API_KEY',\n 'CODEX_API_KEY',\n] as const;\n\nexport function createCodexRequestTransformations({\n env: environment,\n sandboxEnv: sandboxEnvironment,\n auth: authenticationMode,\n}: HarnessV1RequestTransformationSources<CodexResolvedAuthenticationMode>): HarnessV1RequestTransformation[] {\n if (!environment.CODEX_API_KEY || !sandboxEnvironment.CODEX_API_KEY) {\n return [];\n }\n return [\n createCredentialRequestTransformation({\n matchUrl:\n environment.OPENAI_BASE_URL ??\n (authenticationMode === 'ai-gateway'\n ? DEFAULT_AI_GATEWAY_BASE_URL\n : DEFAULT_OPENAI_BASE_URL),\n matchHeaders: {\n Authorization: `Bearer ${sandboxEnvironment.CODEX_API_KEY}`,\n },\n transformHeaders: {\n Authorization: `Bearer ${environment.CODEX_API_KEY}`,\n },\n }),\n ];\n}\n\nexport type CodexResolvedAuthenticationMode = 'direct' | 'ai-gateway';\n\nexport type CodexAuthenticationMode = HarnessV1Authentication;\n\n/**\n * Resolve the environment-variable blob the codex bridge needs. Precedence:\n *\n * 1. An explicit authentication mode pins the selected route.\n * 2. Auto-detect from the host process env: gateway first\n * (`AI_GATEWAY_API_KEY` / `VERCEL_OIDC_TOKEN`), then `CODEX_API_KEY` /\n * `OPENAI_API_KEY`.\n */\nexport function resolveCodexEnv(\n auth: CodexAuthenticationMode | undefined,\n processEnv: Record<string, string | undefined> = process.env,\n): Record<string, string> {\n const suppliedEnvironment = isHarnessAuthenticationEnvironment(auth);\n const authenticationEnvironment = suppliedEnvironment ? auth : processEnv;\n if (auth === 'direct') {\n return pickOpenAI({ processEnv: authenticationEnvironment });\n }\n\n const gatewayAuthFromEnv = getAiGatewayAuthFromEnv({\n env: authenticationEnvironment,\n });\n if (auth === 'ai-gateway' || gatewayAuthFromEnv.apiKey) {\n return pickGateway({ gatewayAuthFromEnv });\n }\n return pickOpenAI({ processEnv: authenticationEnvironment });\n}\n\nexport function resolveCodexAuthenticationMode(\n auth: CodexAuthenticationMode | undefined,\n processEnv: Record<string, string | undefined> = process.env,\n): CodexResolvedAuthenticationMode {\n if (isHarnessAuthenticationEnvironment(auth)) {\n return getAiGatewayAuthFromEnv({ env: auth }).apiKey\n ? 'ai-gateway'\n : 'direct';\n }\n if (auth === 'direct') {\n return 'direct';\n }\n if (auth === 'ai-gateway') {\n return 'ai-gateway';\n }\n return getAiGatewayAuthFromEnv({ env: processEnv }).apiKey\n ? 'ai-gateway'\n : 'direct';\n}\n\nfunction pickOpenAI({\n processEnv,\n}: {\n processEnv: Record<string, string | undefined>;\n}): Record<string, string> {\n const env: Record<string, string> = {};\n const apiKey = processEnv.OPENAI_API_KEY ?? processEnv.CODEX_API_KEY;\n if (apiKey) env.CODEX_API_KEY = apiKey;\n const baseUrl = processEnv.OPENAI_BASE_URL;\n if (baseUrl) env.OPENAI_BASE_URL = baseUrl;\n const organization = processEnv.OPENAI_ORGANIZATION;\n if (organization) env.OPENAI_ORGANIZATION = organization;\n const project = processEnv.OPENAI_PROJECT;\n if (project) env.OPENAI_PROJECT = project;\n return env;\n}\n\nfunction pickGateway({\n gatewayAuthFromEnv,\n}: {\n gatewayAuthFromEnv: ReturnType<typeof getAiGatewayAuthFromEnv>;\n}): Record<string, string> {\n const apiKey = gatewayAuthFromEnv.apiKey;\n const baseUrl = toCodexGatewayBaseUrl(gatewayAuthFromEnv.baseUrl);\n const env: Record<string, string> = {};\n if (apiKey) {\n env.AI_GATEWAY_API_KEY = apiKey;\n env.CODEX_API_KEY = apiKey;\n }\n env.AI_GATEWAY_BASE_URL = baseUrl;\n env.OPENAI_BASE_URL = baseUrl;\n return env;\n}\n\nfunction toCodexGatewayBaseUrl(baseUrl: string): string {\n const trimmed = baseUrl.replace(/\\/+$/, '');\n return trimmed.endsWith('/v1') ? trimmed : `${trimmed}/v1`;\n}\n","import {\n harnessV1BridgeInboundCommandSchemas,\n harnessV1BridgeOutboundMessageSchema,\n harnessV1BridgeReadySchema,\n harnessV1BridgeStartBaseSchema,\n} from '@ai-sdk/harness';\nimport { z } from 'zod/v4';\n\n/*\n * Codex's bridge wire protocol. The outbound events (including `file-change`\n * and the `bridge-thread` resume coordinate), transport frames, shared inbound\n * commands, and `bridge-ready` line all come from the shared `@ai-sdk/harness`\n * protocol — the only Codex-specific piece is the `start` payload.\n */\n\nexport const outboundMessageSchema = harnessV1BridgeOutboundMessageSchema;\nexport type OutboundMessage = z.infer<typeof outboundMessageSchema>;\n\nexport const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({\n instructions: z.string().optional(),\n reasoningEffort: z.enum(['low', 'medium', 'high']).optional(),\n webSearch: z.boolean().optional(),\n codexConfig: z.record(z.string(), z.unknown()).optional(),\n mcpServers: z.record(z.string(), z.unknown()).optional(),\n // Resume signal. When supplied, the bridge calls\n // `codex.resumeThread(resumeThreadId, …)` instead of starting a fresh thread.\n // The host sources the id from lifecycle state `data` cached from a prior\n // `agent.detach`.\n resumeThreadId: z.string().optional(),\n restartThread: z.boolean().optional(),\n});\n\nexport type StartMessage = z.infer<typeof startMessageSchema>;\n\nexport const inboundMessageSchema = z.discriminatedUnion('type', [\n startMessageSchema,\n ...harnessV1BridgeInboundCommandSchemas,\n]);\nexport type InboundMessage = z.infer<typeof inboundMessageSchema>;\n\nexport const bridgeReadySchema = harnessV1BridgeReadySchema;\nexport type BridgeReady = z.infer<typeof bridgeReadySchema>;\n","/*\n * Temporary workaround for upstream codex CLI bug\n * https://github.com/openai/codex/issues/19425 — MCP tools registered via\n * `mcp_servers.*` are not exposed to the model in `codex exec --experimental-json`\n * mode (which is what `@openai/codex-sdk` uses). The MCP handshake completes\n * and `tools/list` succeeds, but codex never registers the tools as\n * model-callable functions.\n *\n * Until that's fixed upstream, this file implements a CLI-based relay:\n *\n * 1. A small Node script is written into harness-owned session state at turn\n * start (`buildCliShimScript`). It accepts `<toolName> <jsonInput>` as\n * argv, POSTs to the same HTTP relay the MCP shim uses, and prints the\n * result to stdout.\n *\n * 2. Tool descriptions and invocation instructions are injected into the\n * initial user prompt by the host adapter, telling the model to call host\n * tools by running `node <shim-path> <toolName> '<jsonInput>'` via its\n * built-in `bash` tool.\n *\n * 3. The bridge's event loop suppresses the matching `command_execution`\n * events (`isToolRelayCommand`) so callers receive clean `tool-call` /\n * `tool-result` events from the HTTP relay rather than seeing the\n * relay invocations as raw bash commands.\n *\n * Once #19425 is fixed and MCP tools are properly exposed in exec mode, the\n * three hookpoints in `bridge/index.ts` can be removed along with this file.\n */\nexport const CLI_SHIM_FILENAME = 'harness-tool.mjs';\n\nexport function buildCliShimScript({\n relayPort,\n}: {\n relayPort: number;\n}): string {\n return `#!/usr/bin/env node\nconst [toolName, inputJson = '{}'] = process.argv.slice(2);\nif (!toolName) {\n console.error('Usage: harness-tool <tool_name> <json_input>');\n process.exit(64);\n}\nlet input;\ntry {\n input = JSON.parse(inputJson);\n} catch (error) {\n console.error('Invalid JSON input: ' + (error instanceof Error ? error.message : String(error)));\n process.exit(64);\n}\nconst requestId = 'cli-' + Date.now() + '-' + Math.random().toString(16).slice(2);\nconst response = await fetch('http://127.0.0.1:${relayPort}', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ requestId, toolName, input }),\n});\nconst text = await response.text();\nlet payload;\ntry {\n payload = text ? JSON.parse(text) : {};\n} catch {\n payload = { error: text };\n}\nif (!response.ok || payload.error) {\n console.error(String(payload.error ?? ('tool relay failed with HTTP ' + response.status)));\n process.exit(1);\n}\nconsole.log(JSON.stringify(payload.result ?? payload, null, 2));\n`;\n}\n\nexport function isToolRelayCommand({\n command,\n cliShimPath,\n}: {\n command: string;\n cliShimPath: string;\n}): boolean {\n return parseToolRelayCommands({ command, cliShimPath }) !== undefined;\n}\n\nexport function parseToolRelayCommand({\n command,\n cliShimPath,\n}: {\n command: string;\n cliShimPath: string;\n}): { toolName: string; input: unknown } | undefined {\n const calls = parseToolRelayCommands({ command, cliShimPath });\n return calls?.length === 1 ? calls[0] : undefined;\n}\n\nexport function parseToolRelayCommands({\n command,\n cliShimPath,\n}: {\n command: string;\n cliShimPath: string;\n}): Array<{ toolName: string; input: unknown }> | undefined {\n return parseToolRelayCommandsInternal({ command, cliShimPath, depth: 0 });\n}\n\nfunction parseToolRelayCommandsInternal({\n command,\n cliShimPath,\n depth,\n}: {\n command: string;\n cliShimPath: string;\n depth: number;\n}): Array<{ toolName: string; input: unknown }> | undefined {\n const commands = splitShellAndCommands(command);\n if (!commands) return undefined;\n if (commands.length > 1) {\n const relayCalls: Array<{ toolName: string; input: unknown }> = [];\n for (const nestedCommand of commands) {\n const nestedCalls = parseToolRelayCommandsInternal({\n command: nestedCommand,\n cliShimPath,\n depth,\n });\n if (!nestedCalls) return undefined;\n relayCalls.push(...nestedCalls);\n }\n return relayCalls;\n }\n\n const argv = parseShellWords(command);\n if (!argv) return undefined;\n\n const relayCall = parseDirectToolRelayArgv({ argv, cliShimPath });\n if (relayCall) return [relayCall];\n\n const innerCommand = extractShellEvalCommand(argv);\n if (!innerCommand || depth >= 2) return undefined;\n return parseToolRelayCommandsInternal({\n command: innerCommand,\n cliShimPath,\n depth: depth + 1,\n });\n}\n\nfunction parseDirectToolRelayArgv({\n argv,\n cliShimPath,\n}: {\n argv: string[];\n cliShimPath: string;\n}): { toolName: string; input: unknown } | undefined {\n if (argv.length < 3 || argv.length > 4) return undefined;\n if (argv[0] !== 'node' || argv[1] !== cliShimPath) return undefined;\n const toolName = argv[2];\n if (!toolName) return undefined;\n try {\n return { toolName, input: JSON.parse(argv[3] ?? '{}') };\n } catch {\n return undefined;\n }\n}\n\nfunction extractShellEvalCommand(argv: string[]): string | undefined {\n if (argv.length !== 3) return undefined;\n const shellName = argv[0].split('/').at(-1);\n if (shellName !== 'bash' && shellName !== 'sh' && shellName !== 'zsh') {\n return undefined;\n }\n if (argv[1] !== '-c' && argv[1] !== '-lc') return undefined;\n return argv[2];\n}\n\nfunction splitShellAndCommands(command: string): string[] | undefined {\n const commands: string[] = [];\n let start = 0;\n let quote: '\"' | \"'\" | undefined;\n\n for (let i = 0; i < command.length; i++) {\n const char = command[i];\n if (quote === \"'\") {\n if (char === \"'\") quote = undefined;\n continue;\n }\n if (quote === '\"') {\n if (char === '\"') {\n quote = undefined;\n } else if (char === '\\\\') {\n i++;\n }\n continue;\n }\n if (char === '\"' || char === \"'\") {\n quote = char;\n continue;\n }\n if (char === '\\\\') {\n i++;\n continue;\n }\n if (char === '&' && command[i + 1] === '&') {\n const nestedCommand = command.slice(start, i).trim();\n if (!nestedCommand) return undefined;\n commands.push(nestedCommand);\n start = i + 2;\n i++;\n }\n }\n\n if (quote) return undefined;\n const nestedCommand = command.slice(start).trim();\n if (!nestedCommand) return undefined;\n commands.push(nestedCommand);\n return commands;\n}\n\nfunction parseShellWords(command: string): string[] | undefined {\n const words: string[] = [];\n let current = '';\n let quote: '\"' | \"'\" | undefined;\n let hasCurrent = false;\n\n const pushCurrent = () => {\n if (!hasCurrent) return;\n words.push(current);\n current = '';\n hasCurrent = false;\n };\n\n for (let i = 0; i < command.length; i++) {\n const char = command[i];\n if (quote === \"'\") {\n if (char === \"'\") {\n quote = undefined;\n } else {\n current += char;\n }\n hasCurrent = true;\n continue;\n }\n if (quote === '\"') {\n if (char === '\"') {\n quote = undefined;\n } else if (char === '\\\\' && i + 1 < command.length) {\n current += command[++i];\n } else {\n current += char;\n }\n hasCurrent = true;\n continue;\n }\n if (/\\s/.test(char)) {\n pushCurrent();\n continue;\n }\n if (char === '\"' || char === \"'\") {\n quote = char;\n hasCurrent = true;\n continue;\n }\n if (char === '\\\\' && i + 1 < command.length) {\n current += command[++i];\n hasCurrent = true;\n continue;\n }\n if (/[;&|<>()`$]/.test(char)) return undefined;\n current += char;\n hasCurrent = true;\n }\n if (quote) return undefined;\n pushCurrent();\n return words;\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import { createCodex } from './codex-harness';\n\n/**\n * Default `codex` harness instance with no overrides — suitable for the\n * common case where the underlying `codex` CLI's defaults are fine.\n * Equivalent to `createCodex()`.\n */\nexport const codex = createCodex();\n\nexport { createCodex } from './codex-harness';\nexport { VERSION } from './version';\nexport type { CodexHarnessSettings } from './codex-harness';\nexport type { CodexAuthenticationMode } from './codex-auth';\n"],"mappings":";AAAA,SAAS,YAAY,mBAAmB;AACxC,OAAO,UAAU;AACjB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAeK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,OAEV;AAKP,SAAS,iBAAiB;AAC1B,SAAS,KAAAA,UAAS;;;AC7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AAO,YAAY,SAAU,QAAO;AACxC,QAAM,QAAkB,CAAC;AACzB,aAAW,QAAQ,SAAS;AAC1B,QAAI,KAAK,SAAS,QAAQ;AACxB,YAAM,IAAI,kCAAkC;AAAA,QAC1C,WAAW;AAAA,QACX,SAAS,sEAAsE,KAAK,IAAI;AAAA,MAC1F,CAAC;AAAA,IACH;AACA,UAAM,KAAK,KAAK,IAAI;AAAA,EACtB;AACA,SAAO,MAAM,KAAK,MAAM;AAC1B;;;AMv3CO,IAAM,QAAQ,YAAY;","names":["z","z","endpoint","proc"]}
1
+ {"version":3,"sources":["../src/codex-harness.ts","../src/codex-bootstrap.ts","../src/codex-auth.ts","../src/codex-bridge-protocol.ts","../src/bridge/cli-relay.ts","../src/version.ts","../src/index.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport {\n commonTool,\n HarnessCapabilityUnsupportedError,\n harnessV1DiagnosticFromBridgeFrame,\n type HarnessV1,\n type HarnessV1DebugConfig,\n type HarnessV1BuiltinTool,\n type HarnessV1ContinueTurnState,\n type HarnessV1CredentialForwarding,\n type HarnessV1Prompt,\n type HarnessV1PromptControl,\n type HarnessV1PortEndpoint,\n type HarnessV1ResumeSessionState,\n type HarnessV1NetworkSandboxSession,\n type HarnessV1PermissionMode,\n type HarnessV1Session,\n type HarnessV1Skill,\n type HarnessV1StreamPart,\n} from '@ai-sdk/harness';\nimport {\n applyCredentialForwarding,\n classifyDiskLog,\n createBridgeToken,\n createSandboxCredentialEnvironment,\n createBridgeErrorHandler,\n createBridgeStartupError,\n drainBridgeProcessStream,\n forwardBridgeProcessStream,\n getRestrictedSandboxSession,\n markBridgeStarting,\n resolveSandboxDefaultWorkingDirectory,\n resolveSandboxHomeDir,\n SandboxChannel,\n shellQuote,\n warnCredentialBrokeringUnavailable,\n waitForBridgeReady,\n withBridgeToken,\n writeSkills as writeHarnessSkills,\n type WriteSkillsResult,\n} from '@ai-sdk/harness/utils';\nimport {\n type Experimental_SandboxProcess,\n type Experimental_SandboxSession as SandboxSession,\n} from '@ai-sdk/provider-utils';\nimport { WebSocket } from 'ws';\nimport { z } from 'zod/v4';\nimport {\n CODEX_BOOTSTRAP_DIR as BOOTSTRAP_DIR,\n getCodexBootstrap,\n} from './codex-bootstrap';\nimport {\n CODEX_CREDENTIAL_ENVIRONMENT_VARIABLES,\n createCodexRequestTransformations,\n DEFAULT_OPENAI_BASE_URL,\n resolveCodexAuthenticationMode,\n resolveCodexEnv,\n type CodexAuthenticationMode,\n} from './codex-auth';\nimport {\n outboundMessageSchema,\n type InboundMessage,\n type OutboundMessage,\n} from './codex-bridge-protocol';\nimport { CLI_SHIM_FILENAME } from './bridge/cli-relay';\nimport { VERSION } from './version';\n\ntype CodexChannel = SandboxChannel<OutboundMessage, InboundMessage>;\ntype CodexRespawnStrategy = 'replay' | 'rerun';\n\n/*\n * This intentionally is not the latest Codex model. Newer GPT-5.6 models use\n * Responses Lite, which does not expose their code-mode tools as callable\n * through the custom model provider used by the harness. Keep GPT-5.5 as the\n * default until the upstream bug is resolved:\n * https://github.com/openai/codex/issues/31894\n *\n * Passing the model explicitly keeps the runtime behavior deterministic and\n * the telemetry (`gen_ai.request.model`) accurate.\n */\nconst DEFAULT_CODEX_MODEL = 'gpt-5.5';\n\n/**\n * Value to use in User-Agent and `x-client-app` headers.\n */\nconst CODEX_CLIENT_APP = `ai-sdk/harness-codex/${VERSION}`;\n\nexport type CodexHarnessSettings = {\n readonly auth?: CodexAuthenticationMode;\n /**\n * Customizes each credential value before it is forwarded into a sandbox\n * process. This does not restrict which credentials the harness adapter can\n * discover, read, or otherwise access in the host process.\n */\n readonly credentialForwarding?: HarnessV1CredentialForwarding;\n /**\n * Additional configuration passed through to Codex as-is. Codex config keys\n * typically use snake_case and must be provided in that form. Values managed\n * by this adapter take precedence over conflicting entries.\n */\n readonly codexConfig?: Record<string, unknown>;\n /**\n * MCP server definitions keyed by server name. Each definition uses the\n * underlying runtime's native MCP server configuration format.\n */\n readonly mcpServers?: Record<string, unknown>;\n /**\n * OpenAI model id the underlying `codex` CLI should use. Leaving this unset\n * pins the adapter default (`DEFAULT_CODEX_MODEL`).\n *\n * @deprecated Use `model` on `HarnessAgent` instead.\n */\n readonly model?: string;\n /**\n * Reasoning effort for reasoning-capable models. Leaving this unset\n * defers to the CLI's default.\n */\n readonly reasoningEffort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max';\n /**\n * When `true`, allow the underlying runtime to use live web search.\n */\n readonly webSearch?: boolean;\n /**\n * Override the port the bridge binds inside the sandbox. By default the\n * adapter uses the first port the sandbox declares via `sandbox.ports`.\n * Only set this if the sandbox declares multiple ports and the first one\n * is reserved for something else.\n */\n readonly port?: number;\n /**\n * Override the host endpoint used to connect to the sandbox bridge. Required\n * together with `port` when using a basic sandbox session.\n */\n readonly portEndpoint?: HarnessV1PortEndpoint;\n /** Maximum milliseconds to wait for the bridge to advertise its port. Defaults to 120000. */\n readonly startupTimeoutMs?: number;\n /**\n * Creates the authentication token used by the sandbox bridge. Defaults to\n * a random 32-byte hexadecimal token.\n */\n readonly mintBridgeToken?: (sandboxId: string) => string;\n};\n\n/*\n * Every native tool the Codex CLI can invoke as a model-callable tool,\n * declared as a `ToolSet` keyed by what the bridge emits as `toolName` on\n * the wire (`commonName ?? nativeName`). Schemas reflect the `ThreadItem`\n * union in `@openai/codex-sdk`'s `dist/index.d.ts`.\n *\n * Codex's other native operations (`apply_patch`, todo planning) surface\n * only as side-effect events (`file_change`, `todo_list`) and are not\n * model-callable tools — they don't appear here.\n */\nconst CODEX_BUILTIN_TOOLS = {\n bash: commonTool('bash', {\n nativeName: 'shell',\n toolUseKind: 'bash',\n description: 'Execute a shell command',\n inputSchema: z.object({ command: z.string() }),\n }),\n webSearch: commonTool('webSearch', {\n nativeName: 'web_search',\n toolUseKind: 'readonly',\n description: 'Search the web',\n inputSchema: z.object({ query: z.string() }),\n }),\n} as const satisfies Record<string, HarnessV1BuiltinTool<any, any>>;\n\n/**\n * Live bridge coordinates returned by `doDetach()` and `doSuspendTurn()`. A\n * future process uses them to reopen a socket to the still-running bridge\n * (`attach`) instead of re-spawning it. Absent on a `doStop()` payload.\n */\nconst codexBridgeCoordsSchema = z.object({\n port: z.number(),\n token: z.string(),\n lastSeenEventId: z.number(),\n sandboxId: z.string().optional(),\n});\n\n/**\n * Schema for the adapter-specific lifecycle `data` payload Codex produces.\n * `threadId` is what `codex.resumeThread(...)` requires for the replay/rerun\n * rungs; the sandbox lookup is handled separately via\n * `provider.resumeSession({ sessionId })`. `bridge` carries live coordinates\n * for cross-process `attach` (present on `doDetach()` and `doSuspendTurn()`\n * payloads).\n */\nconst codexResumeStateSchema = z.object({\n threadId: z.string().optional(),\n turnConfigurationFingerprint: z.string().optional(),\n bridge: codexBridgeCoordsSchema.optional(),\n sandboxCredentialEnvironment: z.record(z.string(), z.string()).optional(),\n});\n\ntype CodexBridgeCoords = z.infer<typeof codexBridgeCoordsSchema>;\n\nexport function createCodex(\n settings: CodexHarnessSettings = {},\n): HarnessV1<typeof CODEX_BUILTIN_TOOLS> {\n return {\n specificationVersion: 'harness-v1',\n harnessId: 'codex',\n builtinTools: CODEX_BUILTIN_TOOLS,\n supportsBuiltinToolApprovals: false,\n lifecycleStateSchema: codexResumeStateSchema,\n getBootstrap: getCodexBootstrap,\n doStart: async startOpts => {\n const model = settings.model ?? DEFAULT_CODEX_MODEL;\n if (startOpts.builtinToolFiltering != null) {\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' does not support built-in tool filtering controls.\",\n harnessId: 'codex',\n });\n }\n if (\n startOpts.permissionMode != null &&\n startOpts.permissionMode !== 'allow-all'\n ) {\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' does not support built-in tool approval requests; use permissionMode: 'allow-all'.\",\n harnessId: 'codex',\n });\n }\n const sandboxSession = startOpts.sandboxSession;\n const toolSafeSandboxSession =\n getRestrictedSandboxSession(sandboxSession);\n const sandboxId = 'id' in sandboxSession ? sandboxSession.id : undefined;\n validateBasicSandboxSettings({\n sandboxSession,\n port: settings.port,\n portEndpoint: settings.portEndpoint,\n });\n if (settings.mintBridgeToken != null && sandboxId == null) {\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness cannot use `mintBridgeToken` with a sandbox session that does not expose an id.',\n });\n }\n const defaultWorkingDirectory =\n await resolveSandboxDefaultWorkingDirectory({\n sandboxSession,\n abortSignal: startOpts.abortSignal,\n });\n const lifecycleState = startOpts.continueFrom ?? startOpts.resumeFrom;\n const isResume = lifecycleState != null;\n const isContinue = startOpts.continueFrom != null;\n const resumeData =\n isResume && typeof lifecycleState?.data === 'object'\n ? (lifecycleState.data as {\n threadId?: unknown;\n turnConfigurationFingerprint?: unknown;\n bridge?: CodexBridgeCoords;\n sandboxCredentialEnvironment?: Record<string, string>;\n })\n : undefined;\n const resumeThreadId = resumeData?.threadId;\n const resumeThreadIdString =\n typeof resumeThreadId === 'string' && resumeThreadId.length > 0\n ? resumeThreadId\n : undefined;\n const turnConfigurationFingerprint =\n typeof resumeData?.turnConfigurationFingerprint === 'string'\n ? resumeData.turnConfigurationFingerprint\n : undefined;\n const coords = resumeData?.bridge;\n const authenticationMode = resolveCodexAuthenticationMode(settings.auth);\n const resolvedAuthEnvironment = resolveCodexEnv(settings.auth);\n let sandboxAuthEnvironment = resolvedAuthEnvironment;\n let sandboxCredentialEnvironment: Record<string, string> | undefined;\n let credentialsBrokered = false;\n if (\n 'addRequestTransformations' in sandboxSession &&\n sandboxSession.addRequestTransformations != null\n ) {\n sandboxCredentialEnvironment =\n resumeData?.sandboxCredentialEnvironment ??\n (await createSandboxCredentialEnvironment({\n environment: resolvedAuthEnvironment,\n credentialEnvironmentVariables:\n CODEX_CREDENTIAL_ENVIRONMENT_VARIABLES,\n credentialForwarding: settings.credentialForwarding,\n }));\n sandboxAuthEnvironment = {\n ...resolvedAuthEnvironment,\n ...sandboxCredentialEnvironment,\n };\n const requestTransformations = createCodexRequestTransformations({\n env: resolvedAuthEnvironment,\n sandboxEnv: sandboxAuthEnvironment,\n auth: authenticationMode,\n });\n if (requestTransformations.length > 0) {\n await sandboxSession.addRequestTransformations(\n requestTransformations,\n );\n }\n credentialsBrokered = true;\n if (\n requestTransformations.length > 0 &&\n authenticationMode === 'direct' &&\n resolvedAuthEnvironment.OPENAI_BASE_URL == null\n ) {\n /*\n * Vercel Sandbox request transformations apply only to HTTP traffic.\n * Materializing Codex's standard OpenAI URL makes the bridge select\n * its custom provider, where WebSockets are disabled, while keeping\n * the non-brokered path on Codex's built-in OpenAI provider.\n */\n sandboxAuthEnvironment.OPENAI_BASE_URL = DEFAULT_OPENAI_BASE_URL;\n }\n } else {\n warnCredentialBrokeringUnavailable();\n }\n const bootstrapDir = path.posix.resolve(\n defaultWorkingDirectory,\n BOOTSTRAP_DIR,\n );\n\n const workDir = startOpts.sessionWorkDir;\n const sandboxHomeDir = await resolveSandboxHomeDir({\n sandbox: toolSafeSandboxSession,\n abortSignal: startOpts.abortSignal,\n });\n const sessionDataDir = `${defaultWorkingDirectory}/.agent-runs/${startOpts.sessionId}`;\n const bridgeStateDir = `${sessionDataDir}/bridge`;\n const cliShimDir = `${sessionDataDir}/codex`;\n const cliShimPath = `${cliShimDir}/${CLI_SHIM_FILENAME}`;\n const timeoutMs = settings.startupTimeoutMs ?? 120_000;\n\n // Normalize each forwarded bridge diagnostics frame into the general\n // `HarnessV1Diagnostic` and report it. The adapter does no telemetry work\n // beyond this transport→emission mapping.\n const report = startOpts.observability?.report;\n const onDiagnostic = report\n ? (frame: Parameters<typeof harnessV1DiagnosticFromBridgeFrame>[0]) =>\n report(\n harnessV1DiagnosticFromBridgeFrame(frame, {\n sessionId: startOpts.sessionId,\n timestamp: Date.now(),\n }),\n )\n : undefined;\n const onBridgeError = createBridgeErrorHandler({\n harnessId: 'codex',\n sessionId: startOpts.sessionId,\n });\n\n /*\n * Rung 1 — ATTACH. With live coordinates, reopen a socket to the\n * still-running bridge. Parked between-turn sessions just attach and wait\n * for the next `start`; suspended in-flight turns request replay of\n * everything past the persisted cursor. No spawn, no fresh token. If the\n * bridge is gone the open throws and we fall through to a spawn-based\n * recovery.\n */\n if (coords) {\n try {\n const endpoint = await resolveBridgeEndpoint({\n sandboxSession,\n override: settings.portEndpoint,\n port: coords.port,\n });\n const attachEndpoint = withBridgeToken({\n endpoint,\n token: coords.token,\n });\n const attachChannel: CodexChannel = new SandboxChannel({\n connect: () => openWebSocket(attachEndpoint),\n outboundSchema: outboundMessageSchema,\n initialLastSeenEventId: coords.lastSeenEventId,\n onDiagnostic,\n onBridgeError,\n });\n await attachChannel.open(isContinue ? { resume: true } : undefined);\n return createSession({\n sessionId: startOpts.sessionId,\n channel: attachChannel,\n cliShimPath,\n // The live bridge was spawned by another process; no process handle.\n proc: undefined,\n model,\n reasoningEffort: settings.reasoningEffort,\n webSearch: settings.webSearch,\n codexConfig: settings.codexConfig,\n mcpServers: settings.mcpServers,\n resumeThreadId: resumeThreadIdString,\n isResume: true,\n seedResumeThreadOnFirstPrompt: false,\n rerunContinue: false,\n bridgePort: coords.port,\n bridgeToken: coords.token,\n sandboxId,\n sandboxCredentialEnvironment,\n debug: startOpts.observability?.debug,\n permissionMode: startOpts.permissionMode,\n sandbox: toolSafeSandboxSession,\n sandboxHomeDir,\n turnConfigurationFingerprint,\n });\n } catch {\n // Bridge no longer reachable — recover by respawning below.\n }\n }\n\n /*\n * Rungs 2/3 — REPLAY vs RERUN. Respawn the bridge. `replay` is only sound\n * for `continueFrom`: those coordinates include the cursor the on-disk\n * log is replayed *from*. `resumeFrom` is a between-turn resume; even when\n * it carries bridge coordinates, replaying the previous turn would\n * re-deliver stale events into the next turn. Those resumes always `rerun`\n * via `codex.resumeThread(threadId)` when attach is unavailable.\n */\n let respawnStrategy: CodexRespawnStrategy | undefined = isResume\n ? 'rerun'\n : undefined;\n if (coords && isContinue) {\n const logRaw = await Promise.resolve(\n toolSafeSandboxSession.readTextFile({\n path: `${bridgeStateDir}/event-log.ndjson`,\n abortSignal: startOpts.abortSignal,\n }),\n ).catch(() => null);\n if ((await classifyDiskLog(logRaw)) === 'replay') {\n respawnStrategy = 'replay';\n }\n }\n\n const port = resolveBridgePort({\n sandboxSession,\n override: settings.port,\n });\n const token =\n settings.mintBridgeToken == null\n ? createBridgeToken()\n : settings.mintBridgeToken(sandboxId!);\n const forwardedAuthEnvironment = credentialsBrokered\n ? sandboxAuthEnvironment\n : await applyCredentialForwarding({\n environment: sandboxAuthEnvironment,\n credentialEnvironmentVariables:\n CODEX_CREDENTIAL_ENVIRONMENT_VARIABLES,\n credentialForwarding: settings.credentialForwarding,\n });\n const env = {\n ...forwardedAuthEnvironment,\n AI_SDK_HARNESS_CLIENT_APP: CODEX_CLIENT_APP,\n BRIDGE_CHANNEL_TOKEN: token,\n BRIDGE_WS_PORT: String(port),\n ...(respawnStrategy === 'replay'\n ? { BRIDGE_REPLAY_FROM_DISK: '1' }\n : {}),\n };\n\n if (respawnStrategy === undefined) {\n await toolSafeSandboxSession.run({\n command: `mkdir -p ${shellQuote(workDir)} ${shellQuote(bridgeStateDir)}`,\n abortSignal: startOpts.abortSignal,\n });\n }\n\n await markBridgeStarting({\n sandbox: toolSafeSandboxSession,\n bridgeStateDir,\n bridgeType: 'codex',\n abortSignal: startOpts.abortSignal,\n });\n\n const proc = await toolSafeSandboxSession.spawn({\n command: `node ${shellQuote(`${bootstrapDir}/bridge.mjs`)} --workdir ${shellQuote(workDir)} --bridge-state-dir ${shellQuote(bridgeStateDir)} --cli-shim-dir ${shellQuote(cliShimDir)}`,\n env,\n abortSignal: startOpts.abortSignal,\n });\n const stderrTail: string[] = [];\n const bridgeStderrDone = forwardBridgeProcessStream({\n stream: proc.stderr,\n streamName: 'stderr',\n source: 'codex',\n collectTail: stderrTail,\n });\n\n const { port: boundPort } = await waitForBridgeReady({\n proc,\n sandbox: toolSafeSandboxSession,\n bridgeStateDir,\n bridgeType: 'codex',\n timeoutMs,\n abortSignal: startOpts.abortSignal,\n createTimeoutError: ({ proc, stdoutTail }) =>\n createBridgeStartupError({\n message: 'codex bridge did not become ready in time.',\n proc,\n stdoutTail,\n stderrTail,\n stderrDone: bridgeStderrDone,\n }),\n createExitError: ({ proc, stdoutTail }) =>\n createBridgeStartupError({\n message: 'codex bridge exited before becoming ready.',\n proc,\n stdoutTail,\n stderrTail,\n stderrDone: bridgeStderrDone,\n }),\n });\n void drainBridgeProcessStream(proc.stdout);\n\n const endpoint = await resolveBridgeEndpoint({\n sandboxSession,\n override: settings.portEndpoint,\n port: boundPort,\n });\n const bridgeEndpoint = withBridgeToken({ endpoint, token });\n\n const channel: CodexChannel = new SandboxChannel({\n connect: () => openWebSocket(bridgeEndpoint),\n outboundSchema: outboundMessageSchema,\n onDiagnostic,\n onBridgeError,\n // In replay mode the respawned bridge reloaded the finished turn from\n // disk; seed the cursor and resume so it streams the tail (incl.\n // `finish`).\n ...(respawnStrategy === 'replay'\n ? { initialLastSeenEventId: coords?.lastSeenEventId ?? 0 }\n : {}),\n });\n await channel.open(\n respawnStrategy === 'replay' ? { resume: true } : undefined,\n );\n\n return createSession({\n sessionId: startOpts.sessionId,\n channel,\n cliShimPath,\n proc,\n model,\n reasoningEffort: settings.reasoningEffort,\n webSearch: settings.webSearch,\n codexConfig: settings.codexConfig,\n mcpServers: settings.mcpServers,\n resumeThreadId: resumeThreadIdString,\n isResume: respawnStrategy !== undefined,\n seedResumeThreadOnFirstPrompt: respawnStrategy !== undefined,\n rerunContinue: respawnStrategy === 'rerun',\n bridgePort: boundPort,\n bridgeToken: token,\n sandboxId,\n sandboxCredentialEnvironment,\n debug: startOpts.observability?.debug,\n permissionMode: startOpts.permissionMode,\n sandbox: toolSafeSandboxSession,\n sandboxHomeDir,\n turnConfigurationFingerprint,\n });\n },\n };\n}\n\nfunction resolveBridgePort({\n sandboxSession,\n override,\n}: {\n sandboxSession: HarnessV1NetworkSandboxSession | SandboxSession;\n override: number | undefined;\n}): number {\n if (override !== undefined) return override;\n if ('ports' in sandboxSession && sandboxSession.ports.length > 0) {\n return sandboxSession.ports[0];\n }\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness needs a TCP port exposed by the sandbox. ' +\n 'Create the sandbox with `ports: [<port>]` or pass `createCodex({ port })`.',\n });\n}\n\nfunction validateBasicSandboxSettings({\n sandboxSession,\n port,\n portEndpoint,\n}: {\n sandboxSession: HarnessV1NetworkSandboxSession | SandboxSession;\n port: number | undefined;\n portEndpoint: HarnessV1PortEndpoint | undefined;\n}): void {\n if ('getPortEndpoint' in sandboxSession) return;\n if (port == null) {\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness requires an explicit `port` when using a basic sandbox session.',\n });\n }\n if (portEndpoint == null) {\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness requires an explicit `portEndpoint` when using a basic sandbox session.',\n });\n }\n}\n\nasync function resolveBridgeEndpoint({\n sandboxSession,\n override,\n port,\n}: {\n sandboxSession: HarnessV1NetworkSandboxSession | SandboxSession;\n override: HarnessV1PortEndpoint | undefined;\n port: number;\n}): Promise<HarnessV1PortEndpoint> {\n if (override != null) return override;\n if ('getPortEndpoint' in sandboxSession) {\n return sandboxSession.getPortEndpoint({ port, protocol: 'ws' });\n }\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message:\n 'The codex harness requires an explicit `portEndpoint` when using a basic sandbox session.',\n });\n}\n\nasync function writeCodexSkills({\n sandbox,\n sandboxHomeDir,\n skills,\n abortSignal,\n}: {\n sandbox: SandboxSession;\n sandboxHomeDir: string;\n skills: ReadonlyArray<HarnessV1Skill>;\n abortSignal?: AbortSignal;\n}): Promise<WriteSkillsResult> {\n const rootDir = path.posix.join(sandboxHomeDir, '.agents', 'skills');\n return writeHarnessSkills({\n sandbox,\n rootDir,\n skills,\n abortSignal,\n invalidSkillNameMessage: ({ name }) => `Invalid Codex skill name: ${name}`,\n invalidSkillFilePathMessage: ({ skillName, filePath }) =>\n `Invalid Codex skill file path for ${skillName}: ${filePath}`,\n });\n}\n\nfunction openWebSocket({\n url,\n headers,\n}: HarnessV1PortEndpoint): Promise<WebSocket> {\n return new Promise((resolve, reject) => {\n const ws = new WebSocket(url, {\n headers: headers == null ? undefined : { ...headers },\n });\n const onOpen = () => {\n ws.off('error', onError);\n resolve(ws);\n };\n const onError = (err: Error) => {\n ws.off('open', onOpen);\n reject(err);\n };\n ws.once('open', onOpen);\n ws.once('error', onError);\n });\n}\n\nfunction createSession({\n sessionId,\n channel,\n cliShimPath,\n proc,\n model,\n reasoningEffort,\n webSearch,\n codexConfig,\n mcpServers,\n resumeThreadId,\n isResume,\n seedResumeThreadOnFirstPrompt,\n rerunContinue,\n bridgePort,\n bridgeToken,\n sandboxId,\n sandboxCredentialEnvironment,\n debug,\n permissionMode,\n sandbox,\n sandboxHomeDir,\n turnConfigurationFingerprint,\n}: {\n sessionId: string;\n channel: CodexChannel;\n cliShimPath: string;\n /** Undefined on `attach` — the live bridge was spawned by another process. */\n proc: Experimental_SandboxProcess | undefined;\n model: string | undefined;\n reasoningEffort: 'low' | 'medium' | 'high' | 'xhigh' | 'max' | undefined;\n webSearch: boolean | undefined;\n codexConfig: Record<string, unknown> | undefined;\n mcpServers: Record<string, unknown> | undefined;\n resumeThreadId: string | undefined;\n isResume: boolean;\n seedResumeThreadOnFirstPrompt: boolean;\n rerunContinue: boolean;\n bridgePort: number;\n bridgeToken: string;\n sandboxId: string | undefined;\n sandboxCredentialEnvironment: Record<string, string> | undefined;\n debug: HarnessV1DebugConfig | undefined;\n permissionMode: HarnessV1PermissionMode | undefined;\n sandbox: SandboxSession;\n sandboxHomeDir: string;\n turnConfigurationFingerprint: string | undefined;\n}): HarnessV1Session {\n let stopped = false;\n let stopPromise: Promise<void> | undefined;\n /*\n * Send the persisted threadId on the first prompt only when the bridge was\n * respawned (rerun/replay) so it takes the `codex.resumeThread(...)` branch.\n * An `attach`ed bridge already holds its threadState in memory and continues\n * on its own, so it needs no seed.\n */\n let pendingResumeThreadId = seedResumeThreadOnFirstPrompt\n ? resumeThreadId\n : undefined;\n /*\n * Host-tool relay guidance is prepended to the first user message of a fresh\n * session only. A resumed session (attach/replay/rerun) already carried it in\n * its original first message (preserved in the persisted thread), so it\n * starts \"applied\".\n */\n let initialPromptGuidanceApplied = isResume;\n\n /*\n * Latest codex thread id, cached from the bridge's `bridge-thread`\n * announcements. Seeded from lifecycle state so `doDetach()` and `doStop()`\n * can include a thread id even before this process has run a turn.\n */\n let latestThreadId = resumeThreadId;\n let latestTurnConfigurationFingerprint = turnConfigurationFingerprint;\n channel.on('bridge-thread', msg => {\n latestThreadId = msg.threadId;\n });\n\n const synchronizeTurnConfiguration = async ({\n skills,\n instructions,\n tools,\n abortSignal,\n }: {\n skills: ReadonlyArray<HarnessV1Skill>;\n instructions: string | undefined;\n tools: ReadonlyArray<{\n name: string;\n description?: string;\n inputSchema: unknown;\n }>;\n abortSignal?: AbortSignal;\n }): Promise<{ restartThread: boolean }> => {\n const skillsResult = await writeCodexSkills({\n sandbox,\n sandboxHomeDir,\n skills,\n abortSignal,\n });\n const nextFingerprint = fingerprintCodexTurnConfiguration({\n instructions,\n tools,\n });\n const restartThread =\n latestThreadId != null &&\n (skillsResult.changed ||\n (latestTurnConfigurationFingerprint != null &&\n latestTurnConfigurationFingerprint !== nextFingerprint));\n latestTurnConfigurationFingerprint = nextFingerprint;\n if (restartThread) {\n /*\n * `codex exec resume` retains the native thread's original developer\n * instructions and skill catalog. A fresh native thread is therefore\n * required for replacement semantics. Host-tool guidance is framed\n * again because that guidance also belongs to the new native thread.\n */\n initialPromptGuidanceApplied = false;\n pendingResumeThreadId = undefined;\n }\n return { restartThread };\n };\n\n /*\n * Wire the channel into one turn's worth of events and return the control\n * surface. Shared by `doPromptTurn` (which sends a `start` afterwards) and\n * `doContinueTurn` (which attaches to an already-running/replayed turn, or sends\n * a rerun `start`). The only difference between the two entry points is the\n * `start` message, not the listener/abort/settle plumbing.\n */\n const wireTurn = (turnOpts: {\n emit: (event: HarnessV1StreamPart) => void;\n abortSignal?: AbortSignal;\n }): {\n control: HarnessV1PromptControl;\n sendStart: (send: () => void) => void;\n } => {\n let pendingResolve: (() => void) | undefined;\n let pendingReject: ((err: unknown) => void) | undefined;\n const done = new Promise<void>((resolve, reject) => {\n pendingResolve = resolve;\n pendingReject = reject;\n });\n\n const unsubs: Array<() => void> = [];\n const forward = (event: HarnessV1StreamPart) => {\n try {\n turnOpts.emit(event);\n } catch {}\n };\n\n const eventTypes = [\n 'stream-start',\n 'text-start',\n 'text-delta',\n 'text-end',\n 'reasoning-start',\n 'reasoning-delta',\n 'reasoning-end',\n 'tool-call',\n 'tool-approval-request',\n 'tool-result',\n 'file-change',\n 'finish-step',\n 'raw',\n ] as const;\n let isSettled = false;\n const settleSuccess = () => {\n if (isSettled) return;\n isSettled = true;\n for (const u of unsubs) u();\n pendingResolve!();\n };\n const settleError = (err: unknown) => {\n if (isSettled) return;\n isSettled = true;\n for (const u of unsubs) u();\n pendingReject!(err);\n };\n\n for (const type of eventTypes) {\n unsubs.push(\n channel.on(type, msg => {\n forward(msg);\n }),\n );\n }\n unsubs.push(\n channel.on('finish', msg => {\n forward(msg);\n settleSuccess();\n }),\n );\n unsubs.push(\n channel.on('error', msg => {\n forward(msg);\n settleError(msg.error);\n }),\n );\n\n /*\n * A `'suspended'` close is a graceful slice-boundary freeze the host\n * initiated (`doSuspendTurn`): the turn keeps running in the bridge and its\n * tail is replayed to the next process, so wind this turn down cleanly\n * rather than failing it. Any other close mid-turn is an unexpected drop.\n */\n const onClose = (_code?: number, reason?: string) => {\n if (isSettled) return;\n if (reason === 'suspended') {\n settleSuccess();\n return;\n }\n settleError(new Error('codex bridge closed before the turn finished.'));\n };\n channel.onClose(onClose);\n\n const onAbort = () => {\n if (isSettled) return;\n try {\n channel.send({ type: 'abort' });\n } catch {}\n settleError(\n turnOpts.abortSignal?.reason ??\n new DOMException('Aborted', 'AbortError'),\n );\n };\n if (turnOpts.abortSignal) {\n if (turnOpts.abortSignal.aborted) {\n onAbort();\n } else {\n turnOpts.abortSignal.addEventListener('abort', onAbort, {\n once: true,\n });\n }\n }\n\n const control: HarnessV1PromptControl = {\n submitToolResult: async input => {\n channel.send({\n type: 'tool-result',\n toolCallId: input.toolCallId,\n output: input.output,\n isError: input.isError,\n });\n },\n submitToolApproval: async input => {\n channel.send({\n type: 'tool-approval-response',\n approvalId: input.approvalId,\n approved: input.approved,\n reason: input.reason,\n });\n },\n done,\n };\n\n return {\n control,\n sendStart: send => {\n /*\n * Codex can complete short turns without using tools. Deferring the\n * start frame gives the harness runner one event-loop turn to finish\n * wiring the prompt control and stream output before Codex can settle.\n */\n const timer = setTimeout(() => {\n if (isSettled) return;\n try {\n send();\n } catch (err) {\n settleError(err);\n }\n }, 0);\n timer.unref?.();\n },\n };\n };\n\n return {\n sessionId,\n isResume,\n doPromptTurn: async promptOpts => {\n if (\n promptOpts.responseFormat?.type === 'json' &&\n promptOpts.responseFormat.schema == null\n ) {\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' requires a JSON schema for structured output.\",\n harnessId: 'codex',\n });\n }\n const tools = (promptOpts.tools ?? []).map(t => ({\n name: t.name,\n description: t.description,\n inputSchema: t.inputSchema,\n }));\n const { restartThread } = await synchronizeTurnConfiguration({\n skills: promptOpts.skills,\n instructions: promptOpts.instructions,\n tools,\n abortSignal: promptOpts.abortSignal,\n });\n const turn = wireTurn({\n emit: promptOpts.emit,\n abortSignal: promptOpts.abortSignal,\n });\n\n let promptText = extractUserText(promptOpts.prompt);\n if (!initialPromptGuidanceApplied) {\n promptText = frameInitialPromptGuidance({\n toolUsageBlock:\n tools.length > 0\n ? composeToolUsageInstructions({\n tools,\n cliShimPath,\n })\n : undefined,\n userText: promptText,\n });\n }\n initialPromptGuidanceApplied = true;\n\n const startMessage = {\n type: 'start' as const,\n prompt: promptText,\n tools,\n ...(promptOpts.responseFormat == null\n ? {}\n : { responseFormat: promptOpts.responseFormat }),\n ...(promptOpts.instructions\n ? { instructions: promptOpts.instructions }\n : {}),\n model: promptOpts.model ?? model,\n reasoningEffort,\n webSearch,\n ...(codexConfig == null ? {} : { codexConfig }),\n ...(mcpServers == null ? {} : { mcpServers }),\n ...(permissionMode ? { permissionMode } : {}),\n ...(pendingResumeThreadId\n ? { resumeThreadId: pendingResumeThreadId }\n : {}),\n ...(restartThread ? { restartThread: true } : {}),\n ...(debug ? { debug } : {}),\n };\n pendingResumeThreadId = undefined;\n turn.sendStart(() => channel.send(startMessage));\n\n return turn.control;\n },\n doContinueTurn: async continueOpts => {\n if (\n continueOpts.responseFormat?.type === 'json' &&\n continueOpts.responseFormat.schema == null\n ) {\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' requires a JSON schema for structured output.\",\n harnessId: 'codex',\n });\n }\n const tools = (continueOpts.tools ?? []).map(t => ({\n name: t.name,\n description: t.description,\n inputSchema: t.inputSchema,\n }));\n const { restartThread } = await synchronizeTurnConfiguration({\n skills: continueOpts.skills,\n instructions: continueOpts.instructions,\n tools,\n abortSignal: continueOpts.abortSignal,\n });\n const turn = wireTurn({\n emit: continueOpts.emit,\n abortSignal: continueOpts.abortSignal,\n });\n\n /*\n * attach / replay: the still-running (or disk-replayed) turn streams into\n * the wired listeners — `doStart` opened the channel with `{ resume: true }`\n * so the bridge replays everything past the persisted cursor (including a\n * `finish` if the turn ended during the gap). No `start` is sent: issuing\n * one would clear the bridge's replay log and begin a new turn. Lossless.\n *\n * rerun: the bridge was respawned with no in-flight turn to attach to, so\n * re-drive codex's own thread via `resumeThreadId`. Lossy — work in flight\n * at the suspension is recomputed. This is the rare bridge-died\n * fallback; the common slice path is `attach`.\n */\n if (rerunContinue) {\n const threadId = pendingResumeThreadId ?? latestThreadId;\n pendingResumeThreadId = undefined;\n turn.sendStart(() =>\n channel.send({\n type: 'start' as const,\n /*\n * A continuation nudge rather than an empty prompt: `resumeThreadId`\n * rehydrates the prior thread, and this is the new user turn that\n * drives it forward. Keeping it non-empty avoids handing the runtime\n * an empty user message (and mirrors the claude-code adapter, where an\n * empty text block trips the Anthropic API's `cache_control` rule).\n */\n prompt: 'Continue.',\n tools,\n ...(continueOpts.responseFormat == null\n ? {}\n : { responseFormat: continueOpts.responseFormat }),\n ...(continueOpts.instructions\n ? { instructions: continueOpts.instructions }\n : {}),\n model: continueOpts.model ?? model,\n reasoningEffort,\n webSearch,\n ...(codexConfig == null ? {} : { codexConfig }),\n ...(mcpServers == null ? {} : { mcpServers }),\n ...(permissionMode ? { permissionMode } : {}),\n ...(threadId ? { resumeThreadId: threadId } : {}),\n ...(restartThread ? { restartThread: true } : {}),\n ...(debug ? { debug } : {}),\n }),\n );\n }\n\n return turn.control;\n },\n doCompact: async () => {\n /*\n * Codex compacts its context automatically inside the core turn loop\n * (~90% of the model context window), but the `codex exec` transport this\n * adapter drives exposes no manual compaction trigger and emits no\n * compaction event. Manual `compact()` is therefore unsupported; Codex's\n * own auto-compaction continues to run regardless.\n */\n throw new HarnessCapabilityUnsupportedError({\n message:\n \"Harness 'codex' does not support manual compaction; Codex auto-compacts its context internally.\",\n harnessId: 'codex',\n });\n },\n doDetach: async () => {\n if (stopped) {\n throw new Error(\n `codex session ${sessionId} is already stopped; cannot detach.`,\n );\n }\n stopped = true;\n const lastSeenEventId = await channel.suspend();\n const payload: HarnessV1ResumeSessionState = {\n type: 'resume-session',\n harnessId: 'codex',\n specificationVersion: 'harness-v1',\n data: {\n ...(latestThreadId ? { threadId: latestThreadId } : {}),\n ...(latestTurnConfigurationFingerprint\n ? {\n turnConfigurationFingerprint:\n latestTurnConfigurationFingerprint,\n }\n : {}),\n ...(sandboxCredentialEnvironment == null\n ? {}\n : { sandboxCredentialEnvironment }),\n bridge: {\n port: bridgePort,\n token: bridgeToken,\n lastSeenEventId,\n ...(sandboxId == null ? {} : { sandboxId }),\n },\n },\n };\n return payload;\n },\n doDestroy: async () => {\n if (stopped) return stopPromise;\n stopped = true;\n stopPromise = (async () => {\n // Tell the channel we are tearing down so the bridge's post-shutdown\n // socket close finalises instead of triggering a reconnect.\n channel.beginClose();\n try {\n if (!channel.isClosed()) {\n channel.send({ type: 'destroy' });\n }\n } catch {}\n let stopTimer: ReturnType<typeof setTimeout> | undefined;\n try {\n if (proc) {\n await Promise.race([\n proc.wait(),\n new Promise<void>(resolve => {\n stopTimer = setTimeout(resolve, 5000);\n stopTimer.unref?.();\n }),\n ]);\n }\n } finally {\n if (stopTimer) clearTimeout(stopTimer);\n try {\n await proc?.kill();\n } catch {}\n channel.close();\n }\n })();\n return stopPromise;\n },\n doStop: async () => {\n if (stopped) {\n throw new Error(\n `codex session ${sessionId} is already stopped; cannot stop.`,\n );\n }\n stopped = true;\n /*\n * If the bridge's channel already closed (e.g. mid-turn WS drop)\n * there is no one to acknowledge a `stop` message. Synthesize an empty\n * payload — the workdir is still captured by the sandbox snapshot\n * during the subsequent `sandboxSession.stop()`, so the next turn can\n * resume the filesystem state. The trade-off: we lose\n * `threadId`, so the codex CLI starts a fresh thread on the\n * preserved workdir rather than resuming the prior conversation\n * inside Codex's runtime. Ability to continue beats throwing.\n */\n // Tell the channel we are tearing down so the bridge's post-stop\n // socket close finalises instead of triggering a reconnect.\n channel.beginClose();\n const data: unknown = channel.isClosed()\n ? {}\n : await new Promise<unknown>((resolve, reject) => {\n const timer = setTimeout(() => {\n unsub();\n reject(\n new Error(\n `codex session ${sessionId} did not reply to stop within 5s.`,\n ),\n );\n }, 5000);\n timer.unref?.();\n const unsub = channel.on('bridge-stop', msg => {\n clearTimeout(timer);\n unsub();\n resolve(msg.data);\n });\n try {\n channel.send({ type: 'stop' });\n } catch (err) {\n clearTimeout(timer);\n unsub();\n reject(err);\n }\n });\n\n let stopTimer: ReturnType<typeof setTimeout> | undefined;\n try {\n if (proc) {\n await Promise.race([\n proc.wait(),\n new Promise<void>(resolve => {\n stopTimer = setTimeout(resolve, 5000);\n stopTimer.unref?.();\n }),\n ]);\n }\n } finally {\n if (stopTimer) clearTimeout(stopTimer);\n try {\n await proc?.kill();\n } catch {}\n channel.close();\n }\n\n const lifecycleData =\n data != null && typeof data === 'object' && !Array.isArray(data)\n ? { ...(data as Record<string, unknown>) }\n : {};\n const payload: HarnessV1ResumeSessionState = {\n type: 'resume-session',\n harnessId: 'codex',\n specificationVersion: 'harness-v1',\n data: {\n ...lifecycleData,\n ...(latestTurnConfigurationFingerprint\n ? {\n turnConfigurationFingerprint:\n latestTurnConfigurationFingerprint,\n }\n : {}),\n ...(sandboxCredentialEnvironment == null\n ? {}\n : { sandboxCredentialEnvironment }),\n } as HarnessV1ResumeSessionState['data'],\n };\n return payload;\n },\n doSuspendTurn: async () => {\n if (stopped) {\n throw new Error(\n `codex session ${sessionId} is stopped; cannot suspend.`,\n );\n }\n stopped = true;\n /*\n * Freeze the host at a precise cursor without stopping the active model\n * turn. `channel.suspend` stops processing inbound frames, drains what\n * was already dispatched, then closes the host socket with reason\n * `'suspended'`. The bridge keeps the turn running and accumulates events\n * past the cursor for the next slice to replay. The sandbox process is\n * deliberately left alive.\n */\n const lastSeenEventId = await channel.suspend();\n const payload: HarnessV1ContinueTurnState = {\n type: 'continue-turn',\n harnessId: 'codex',\n specificationVersion: 'harness-v1',\n data: {\n ...(latestThreadId ? { threadId: latestThreadId } : {}),\n ...(latestTurnConfigurationFingerprint\n ? {\n turnConfigurationFingerprint:\n latestTurnConfigurationFingerprint,\n }\n : {}),\n ...(sandboxCredentialEnvironment == null\n ? {}\n : { sandboxCredentialEnvironment }),\n bridge: {\n port: bridgePort,\n token: bridgeToken,\n lastSeenEventId,\n ...(sandboxId == null ? {} : { sandboxId }),\n },\n },\n };\n return payload;\n },\n };\n}\n\nfunction fingerprintCodexTurnConfiguration({\n instructions,\n tools,\n}: {\n instructions: string | undefined;\n tools: ReadonlyArray<{\n name: string;\n description?: string;\n inputSchema: unknown;\n }>;\n}): string {\n return createHash('sha256')\n .update(JSON.stringify({ instructions: instructions ?? null, tools }))\n .digest('hex');\n}\n\n/*\n * Frame host-tool relay guidance and the user's text so Codex treats the\n * prepended block as operating guidance rather than user prose. Applied only\n * to the first user message of a fresh session.\n */\nfunction frameInitialPromptGuidance({\n toolUsageBlock,\n userText,\n}: {\n toolUsageBlock: string | undefined;\n userText: string;\n}): string {\n const blocks: string[] = [];\n if (toolUsageBlock) blocks.push(toolUsageBlock);\n if (blocks.length === 0) return userText;\n return `${blocks.join('\\n\\n')}\\n\\n<user-message>\\n${userText}\\n</user-message>`;\n}\n\nfunction composeToolUsageInstructions({\n tools,\n cliShimPath,\n}: {\n tools: ReadonlyArray<{\n name: string;\n description?: string;\n inputSchema?: unknown;\n }>;\n cliShimPath: string;\n}): string {\n const lines: string[] = [\n '<host-tool-instructions>',\n 'You have access to the following host-provided tools. To use one, run the following command via your built-in `bash` tool:',\n '',\n ` node ${cliShimPath} <toolName> '<jsonInput>'`,\n '',\n 'The script prints the JSON result to stdout. Do not invent another way to call these tools — only this CLI invocation will work. Pass the JSON input as a single-quoted argument.',\n 'For every user request that depends on a host-provided tool, run a separate CLI invocation for each needed tool call in the current turn before answering. Do not reuse previous tool results, and do not say you used a host tool unless the command has completed in the current turn.',\n '',\n ];\n for (const toolSpec of tools) {\n lines.push(\n `- **${toolSpec.name}**${toolSpec.description ? ': ' + toolSpec.description : ''}`,\n );\n lines.push(\n ` - Input schema: \\`${JSON.stringify(toolSpec.inputSchema ?? {})}\\``,\n );\n }\n lines.push('</host-tool-instructions>');\n return lines.join('\\n');\n}\n\n/*\n * Reduce a `HarnessV1Prompt` to the plain user text the bridge forwards\n * to the Codex SDK. File and image parts on the message are not yet\n * supported by the underlying runtime — throw rather than silently drop\n * them so callers learn about the gap instead of seeing mysteriously\n * truncated prompts.\n */\nfunction extractUserText(prompt: HarnessV1Prompt): string {\n if (typeof prompt === 'string') return prompt;\n const { content } = prompt;\n if (typeof content === 'string') return content;\n const parts: string[] = [];\n for (const part of content) {\n if (part.type !== 'text') {\n throw new HarnessCapabilityUnsupportedError({\n harnessId: 'codex',\n message: `The codex harness does not yet support user message parts of type '${part.type}'. Pass a string or a user message whose content contains only text parts.`,\n });\n }\n parts.push(part.text);\n }\n return parts.join('\\n\\n');\n}\n","import { readFile } from 'node:fs/promises';\nimport { fileURLToPath } from 'node:url';\nimport type { HarnessV1Bootstrap } from '@ai-sdk/harness';\n\n/*\n * Bootstrap is derived state stored under the sandbox's default working\n * directory so snapshot-capable providers can preserve the installed CLI,\n * bridge, and recipe marker without requiring root filesystem access.\n *\n * The session work dir (`startOpts.sessionWorkDir`) lives under the sandbox's\n * default working directory — the provider's persistent mount — so any files\n * the agent edits survive both detach -> attach and stop -> snapshot -> resume\n * cycles. Harness infra derived from `sandboxSession.defaultWorkingDirectory`\n * lives under `.agent-runs`, outside the agent workdir.\n */\nexport const CODEX_BOOTSTRAP_DIR = '.harness-bootstrap/codex';\n\nlet cachedBootstrap: HarnessV1Bootstrap | undefined;\n\nexport async function getCodexBootstrap(): Promise<HarnessV1Bootstrap> {\n if (cachedBootstrap != null) return cachedBootstrap;\n const [pkg, lock, bridge] = await Promise.all([\n readBridgeAsset('package.json'),\n readBridgeAsset('pnpm-lock.yaml'),\n readBridgeAsset('index.mjs'),\n ]);\n cachedBootstrap = {\n harnessId: 'codex',\n bootstrapDir: CODEX_BOOTSTRAP_DIR,\n files: [\n { path: `${CODEX_BOOTSTRAP_DIR}/package.json`, content: pkg },\n { path: `${CODEX_BOOTSTRAP_DIR}/pnpm-lock.yaml`, content: lock },\n { path: `${CODEX_BOOTSTRAP_DIR}/bridge.mjs`, content: bridge },\n ],\n commands: [\n {\n command: 'pnpm install --frozen-lockfile --store-dir .pnpm-store',\n },\n ],\n };\n return cachedBootstrap;\n}\n\nasync function readBridgeAsset(name: string): Promise<string> {\n return readFile(\n fileURLToPath(\n resolveBridgeAssetUrl({\n name,\n moduleUrl: import.meta.url,\n }),\n ),\n 'utf8',\n );\n}\n\nexport function resolveBridgeAssetUrl({\n name,\n moduleUrl,\n}: {\n name: string;\n moduleUrl: string | URL;\n}): URL {\n return new URL(`./bridge/${name}`, moduleUrl);\n}\n","import type {\n HarnessV1Authentication,\n HarnessV1RequestTransformation,\n HarnessV1RequestTransformationSources,\n} from '@ai-sdk/harness';\nimport {\n createCredentialRequestTransformation,\n getAiGatewayAuthFromEnv,\n isHarnessAuthenticationEnvironment,\n} from '@ai-sdk/harness/utils';\n\nconst DEFAULT_AI_GATEWAY_BASE_URL = 'https://ai-gateway.vercel.sh/v1';\nexport const DEFAULT_OPENAI_BASE_URL = 'https://api.openai.com/v1';\n\nexport const CODEX_CREDENTIAL_ENVIRONMENT_VARIABLES = [\n 'AI_GATEWAY_API_KEY',\n 'CODEX_API_KEY',\n] as const;\n\nexport function createCodexRequestTransformations({\n env: environment,\n sandboxEnv: sandboxEnvironment,\n auth: authenticationMode,\n}: HarnessV1RequestTransformationSources<CodexResolvedAuthenticationMode>): HarnessV1RequestTransformation[] {\n if (!environment.CODEX_API_KEY || !sandboxEnvironment.CODEX_API_KEY) {\n return [];\n }\n return [\n createCredentialRequestTransformation({\n matchUrl:\n environment.OPENAI_BASE_URL ??\n (authenticationMode === 'ai-gateway'\n ? DEFAULT_AI_GATEWAY_BASE_URL\n : DEFAULT_OPENAI_BASE_URL),\n matchHeaders: {\n Authorization: `Bearer ${sandboxEnvironment.CODEX_API_KEY}`,\n },\n transformHeaders: {\n Authorization: `Bearer ${environment.CODEX_API_KEY}`,\n },\n }),\n ];\n}\n\nexport type CodexResolvedAuthenticationMode = 'direct' | 'ai-gateway';\n\nexport type CodexAuthenticationMode = HarnessV1Authentication;\n\n/**\n * Resolve the environment-variable blob the codex bridge needs. Precedence:\n *\n * 1. An explicit authentication mode pins the selected route.\n * 2. Auto-detect from the host process env: gateway first\n * (`AI_GATEWAY_API_KEY` / `VERCEL_OIDC_TOKEN`), then `CODEX_API_KEY` /\n * `OPENAI_API_KEY`.\n */\nexport function resolveCodexEnv(\n auth: CodexAuthenticationMode | undefined,\n processEnv: Record<string, string | undefined> = process.env,\n): Record<string, string> {\n const suppliedEnvironment = isHarnessAuthenticationEnvironment(auth);\n const authenticationEnvironment = suppliedEnvironment ? auth : processEnv;\n if (auth === 'direct') {\n return pickOpenAI({ processEnv: authenticationEnvironment });\n }\n\n const gatewayAuthFromEnv = getAiGatewayAuthFromEnv({\n env: authenticationEnvironment,\n });\n if (auth === 'ai-gateway' || gatewayAuthFromEnv.apiKey) {\n return pickGateway({ gatewayAuthFromEnv });\n }\n return pickOpenAI({ processEnv: authenticationEnvironment });\n}\n\nexport function resolveCodexAuthenticationMode(\n auth: CodexAuthenticationMode | undefined,\n processEnv: Record<string, string | undefined> = process.env,\n): CodexResolvedAuthenticationMode {\n if (isHarnessAuthenticationEnvironment(auth)) {\n return getAiGatewayAuthFromEnv({ env: auth }).apiKey\n ? 'ai-gateway'\n : 'direct';\n }\n if (auth === 'direct') {\n return 'direct';\n }\n if (auth === 'ai-gateway') {\n return 'ai-gateway';\n }\n return getAiGatewayAuthFromEnv({ env: processEnv }).apiKey\n ? 'ai-gateway'\n : 'direct';\n}\n\nfunction pickOpenAI({\n processEnv,\n}: {\n processEnv: Record<string, string | undefined>;\n}): Record<string, string> {\n const env: Record<string, string> = {};\n const apiKey = processEnv.OPENAI_API_KEY ?? processEnv.CODEX_API_KEY;\n if (apiKey) env.CODEX_API_KEY = apiKey;\n const baseUrl = processEnv.OPENAI_BASE_URL;\n if (baseUrl) env.OPENAI_BASE_URL = baseUrl;\n const organization = processEnv.OPENAI_ORGANIZATION;\n if (organization) env.OPENAI_ORGANIZATION = organization;\n const project = processEnv.OPENAI_PROJECT;\n if (project) env.OPENAI_PROJECT = project;\n return env;\n}\n\nfunction pickGateway({\n gatewayAuthFromEnv,\n}: {\n gatewayAuthFromEnv: ReturnType<typeof getAiGatewayAuthFromEnv>;\n}): Record<string, string> {\n const apiKey = gatewayAuthFromEnv.apiKey;\n const baseUrl = toCodexGatewayBaseUrl(gatewayAuthFromEnv.baseUrl);\n const env: Record<string, string> = {};\n if (apiKey) {\n env.AI_GATEWAY_API_KEY = apiKey;\n env.CODEX_API_KEY = apiKey;\n }\n env.AI_GATEWAY_BASE_URL = baseUrl;\n env.OPENAI_BASE_URL = baseUrl;\n return env;\n}\n\nfunction toCodexGatewayBaseUrl(baseUrl: string): string {\n const trimmed = baseUrl.replace(/\\/+$/, '');\n return trimmed.endsWith('/v1') ? trimmed : `${trimmed}/v1`;\n}\n","import {\n harnessV1BridgeInboundCommandSchemas,\n harnessV1BridgeOutboundMessageSchema,\n harnessV1BridgeReadySchema,\n harnessV1BridgeStartBaseSchema,\n} from '@ai-sdk/harness';\nimport { z } from 'zod/v4';\n\n/*\n * Codex's bridge wire protocol. The outbound events (including `file-change`\n * and the `bridge-thread` resume coordinate), transport frames, shared inbound\n * commands, and `bridge-ready` line all come from the shared `@ai-sdk/harness`\n * protocol — the only Codex-specific piece is the `start` payload.\n */\n\nexport const outboundMessageSchema = harnessV1BridgeOutboundMessageSchema;\nexport type OutboundMessage = z.infer<typeof outboundMessageSchema>;\n\nexport const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({\n instructions: z.string().optional(),\n reasoningEffort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),\n webSearch: z.boolean().optional(),\n codexConfig: z.record(z.string(), z.unknown()).optional(),\n mcpServers: z.record(z.string(), z.unknown()).optional(),\n // Resume signal. When supplied, the bridge calls\n // `codex.resumeThread(resumeThreadId, …)` instead of starting a fresh thread.\n // The host sources the id from lifecycle state `data` cached from a prior\n // `agent.detach`.\n resumeThreadId: z.string().optional(),\n restartThread: z.boolean().optional(),\n});\n\nexport type StartMessage = z.infer<typeof startMessageSchema>;\n\nexport const inboundMessageSchema = z.discriminatedUnion('type', [\n startMessageSchema,\n ...harnessV1BridgeInboundCommandSchemas,\n]);\nexport type InboundMessage = z.infer<typeof inboundMessageSchema>;\n\nexport const bridgeReadySchema = harnessV1BridgeReadySchema;\nexport type BridgeReady = z.infer<typeof bridgeReadySchema>;\n","/*\n * Temporary workaround for upstream codex CLI bug\n * https://github.com/openai/codex/issues/19425 — MCP tools registered via\n * `mcp_servers.*` are not exposed to the model in `codex exec --experimental-json`\n * mode (which is what `@openai/codex-sdk` uses). The MCP handshake completes\n * and `tools/list` succeeds, but codex never registers the tools as\n * model-callable functions.\n *\n * Until that's fixed upstream, this file implements a CLI-based relay:\n *\n * 1. A small Node script is written into harness-owned session state at turn\n * start (`buildCliShimScript`). It accepts `<toolName> <jsonInput>` as\n * argv, POSTs to the same HTTP relay the MCP shim uses, and prints the\n * result to stdout.\n *\n * 2. Tool descriptions and invocation instructions are injected into the\n * initial user prompt by the host adapter, telling the model to call host\n * tools by running `node <shim-path> <toolName> '<jsonInput>'` via its\n * built-in `bash` tool.\n *\n * 3. The bridge's event loop suppresses the matching `command_execution`\n * events (`isToolRelayCommand`) so callers receive clean `tool-call` /\n * `tool-result` events from the HTTP relay rather than seeing the\n * relay invocations as raw bash commands.\n *\n * Once #19425 is fixed and MCP tools are properly exposed in exec mode, the\n * three hookpoints in `bridge/index.ts` can be removed along with this file.\n */\nexport const CLI_SHIM_FILENAME = 'harness-tool.mjs';\n\nexport function buildCliShimScript({\n relayPort,\n}: {\n relayPort: number;\n}): string {\n return `#!/usr/bin/env node\nconst [toolName, inputJson = '{}'] = process.argv.slice(2);\nif (!toolName) {\n console.error('Usage: harness-tool <tool_name> <json_input>');\n process.exit(64);\n}\nlet input;\ntry {\n input = JSON.parse(inputJson);\n} catch (error) {\n console.error('Invalid JSON input: ' + (error instanceof Error ? error.message : String(error)));\n process.exit(64);\n}\nconst requestId = 'cli-' + Date.now() + '-' + Math.random().toString(16).slice(2);\nconst response = await fetch('http://127.0.0.1:${relayPort}', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ requestId, toolName, input }),\n});\nconst text = await response.text();\nlet payload;\ntry {\n payload = text ? JSON.parse(text) : {};\n} catch {\n payload = { error: text };\n}\nif (!response.ok || payload.error) {\n console.error(String(payload.error ?? ('tool relay failed with HTTP ' + response.status)));\n process.exit(1);\n}\nconsole.log(JSON.stringify(payload.result ?? payload, null, 2));\n`;\n}\n\nexport function isToolRelayCommand({\n command,\n cliShimPath,\n}: {\n command: string;\n cliShimPath: string;\n}): boolean {\n return parseToolRelayCommands({ command, cliShimPath }) !== undefined;\n}\n\nexport function parseToolRelayCommand({\n command,\n cliShimPath,\n}: {\n command: string;\n cliShimPath: string;\n}): { toolName: string; input: unknown } | undefined {\n const calls = parseToolRelayCommands({ command, cliShimPath });\n return calls?.length === 1 ? calls[0] : undefined;\n}\n\nexport function parseToolRelayCommands({\n command,\n cliShimPath,\n}: {\n command: string;\n cliShimPath: string;\n}): Array<{ toolName: string; input: unknown }> | undefined {\n return parseToolRelayCommandsInternal({ command, cliShimPath, depth: 0 });\n}\n\nfunction parseToolRelayCommandsInternal({\n command,\n cliShimPath,\n depth,\n}: {\n command: string;\n cliShimPath: string;\n depth: number;\n}): Array<{ toolName: string; input: unknown }> | undefined {\n const commands = splitShellAndCommands(command);\n if (!commands) return undefined;\n if (commands.length > 1) {\n const relayCalls: Array<{ toolName: string; input: unknown }> = [];\n for (const nestedCommand of commands) {\n const nestedCalls = parseToolRelayCommandsInternal({\n command: nestedCommand,\n cliShimPath,\n depth,\n });\n if (!nestedCalls) return undefined;\n relayCalls.push(...nestedCalls);\n }\n return relayCalls;\n }\n\n const argv = parseShellWords(command);\n if (!argv) return undefined;\n\n const relayCall = parseDirectToolRelayArgv({ argv, cliShimPath });\n if (relayCall) return [relayCall];\n\n const innerCommand = extractShellEvalCommand(argv);\n if (!innerCommand || depth >= 2) return undefined;\n return parseToolRelayCommandsInternal({\n command: innerCommand,\n cliShimPath,\n depth: depth + 1,\n });\n}\n\nfunction parseDirectToolRelayArgv({\n argv,\n cliShimPath,\n}: {\n argv: string[];\n cliShimPath: string;\n}): { toolName: string; input: unknown } | undefined {\n if (argv.length < 3 || argv.length > 4) return undefined;\n if (argv[0] !== 'node' || argv[1] !== cliShimPath) return undefined;\n const toolName = argv[2];\n if (!toolName) return undefined;\n try {\n return { toolName, input: JSON.parse(argv[3] ?? '{}') };\n } catch {\n return undefined;\n }\n}\n\nfunction extractShellEvalCommand(argv: string[]): string | undefined {\n if (argv.length !== 3) return undefined;\n const shellName = argv[0].split('/').at(-1);\n if (shellName !== 'bash' && shellName !== 'sh' && shellName !== 'zsh') {\n return undefined;\n }\n if (argv[1] !== '-c' && argv[1] !== '-lc') return undefined;\n return argv[2];\n}\n\nfunction splitShellAndCommands(command: string): string[] | undefined {\n const commands: string[] = [];\n let start = 0;\n let quote: '\"' | \"'\" | undefined;\n\n for (let i = 0; i < command.length; i++) {\n const char = command[i];\n if (quote === \"'\") {\n if (char === \"'\") quote = undefined;\n continue;\n }\n if (quote === '\"') {\n if (char === '\"') {\n quote = undefined;\n } else if (char === '\\\\') {\n i++;\n }\n continue;\n }\n if (char === '\"' || char === \"'\") {\n quote = char;\n continue;\n }\n if (char === '\\\\') {\n i++;\n continue;\n }\n if (char === '&' && command[i + 1] === '&') {\n const nestedCommand = command.slice(start, i).trim();\n if (!nestedCommand) return undefined;\n commands.push(nestedCommand);\n start = i + 2;\n i++;\n }\n }\n\n if (quote) return undefined;\n const nestedCommand = command.slice(start).trim();\n if (!nestedCommand) return undefined;\n commands.push(nestedCommand);\n return commands;\n}\n\nfunction parseShellWords(command: string): string[] | undefined {\n const words: string[] = [];\n let current = '';\n let quote: '\"' | \"'\" | undefined;\n let hasCurrent = false;\n\n const pushCurrent = () => {\n if (!hasCurrent) return;\n words.push(current);\n current = '';\n hasCurrent = false;\n };\n\n for (let i = 0; i < command.length; i++) {\n const char = command[i];\n if (quote === \"'\") {\n if (char === \"'\") {\n quote = undefined;\n } else {\n current += char;\n }\n hasCurrent = true;\n continue;\n }\n if (quote === '\"') {\n if (char === '\"') {\n quote = undefined;\n } else if (char === '\\\\' && i + 1 < command.length) {\n current += command[++i];\n } else {\n current += char;\n }\n hasCurrent = true;\n continue;\n }\n if (/\\s/.test(char)) {\n pushCurrent();\n continue;\n }\n if (char === '\"' || char === \"'\") {\n quote = char;\n hasCurrent = true;\n continue;\n }\n if (char === '\\\\' && i + 1 < command.length) {\n current += command[++i];\n hasCurrent = true;\n continue;\n }\n if (/[;&|<>()`$]/.test(char)) return undefined;\n current += char;\n hasCurrent = true;\n }\n if (quote) return undefined;\n pushCurrent();\n return words;\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import { createCodex } from './codex-harness';\n\n/**\n * Default `codex` harness instance with no overrides — suitable for the\n * common case where the underlying `codex` CLI's defaults are fine.\n * Equivalent to `createCodex()`.\n */\nexport const codex = createCodex();\n\nexport { createCodex } from './codex-harness';\nexport { VERSION } from './version';\nexport type { CodexHarnessSettings } from './codex-harness';\nexport type { CodexAuthenticationMode } from './codex-auth';\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,OAAO,UAAU;AACjB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAeK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,OAEV;AAKP,SAAS,iBAAiB;AAC1B,SAAS,KAAAA,UAAS;;;AC/ClB,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAcvB,IAAM,sBAAsB;AAEnC,IAAI;AAEJ,eAAsB,oBAAiD;AACrE,MAAI,mBAAmB,KAAM,QAAO;AACpC,QAAM,CAAC,KAAK,MAAM,MAAM,IAAI,MAAM,QAAQ,IAAI;AAAA,IAC5C,gBAAgB,cAAc;AAAA,IAC9B,gBAAgB,gBAAgB;AAAA,IAChC,gBAAgB,WAAW;AAAA,EAC7B,CAAC;AACD,oBAAkB;AAAA,IAChB,WAAW;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EACpC;AAAA,EACA;AACF,GAOW;AACT,QAAM,QAAkB;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,WAAW;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,aAAW,YAAY,OAAO;AAC5B,UAAM;AAAA,MACJ,OAAO,SAAS,IAAI,KAAK,SAAS,cAAc,OAAO,SAAS,cAAc,EAAE;AAAA,IAClF;AACA,UAAM;AAAA,MACJ,uBAAuB,KAAK,UAAU,SAAS,eAAe,CAAC,CAAC,CAAC;AAAA,IACnE;AAAA,EACF;AACA,QAAM,KAAK,2BAA2B;AACtC,SAAO,MAAM,KAAK,IAAI;AACxB;AASA,SAAS,gBAAgB,QAAiC;AACxD,MAAI,OAAO,WAAW,SAAU,QAAO;AACvC,QAAM,EAAE,QAAQ,IAAI;AACpB,MAAI,OAAO,YAAY,SAAU,QAAO;AACxC,QAAM,QAAkB,CAAC;AACzB,aAAW,QAAQ,SAAS;AAC1B,QAAI,KAAK,SAAS,QAAQ;AACxB,YAAM,IAAI,kCAAkC;AAAA,QAC1C,WAAW;AAAA,QACX,SAAS,sEAAsE,KAAK,IAAI;AAAA,MAC1F,CAAC;AAAA,IACH;AACA,UAAM,KAAK,KAAK,IAAI;AAAA,EACtB;AACA,SAAO,MAAM,KAAK,MAAM;AAC1B;;;AM52CO,IAAM,QAAQ,YAAY;","names":["z","z","endpoint","proc"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/harness-codex",
3
- "version": "1.0.95",
3
+ "version": "1.0.97",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -26,8 +26,8 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@ai-sdk/harness": "1.0.93",
30
- "@ai-sdk/provider-utils": "5.0.33",
29
+ "@ai-sdk/harness": "1.0.95",
30
+ "@ai-sdk/provider-utils": "5.0.34",
31
31
  "ws": "^8.21.0"
32
32
  },
33
33
  "peerDependencies": {
@@ -42,19 +42,23 @@ export async function getCodexBootstrap(): Promise<HarnessV1Bootstrap> {
42
42
  }
43
43
 
44
44
  async function readBridgeAsset(name: string): Promise<string> {
45
- const candidates = [
46
- new URL(`./bridge/${name}`, import.meta.url),
47
- new URL(`../bridge/${name}`, import.meta.url),
48
- ];
49
- let lastErr: unknown;
50
- for (const url of candidates) {
51
- try {
52
- return await readFile(fileURLToPath(url), 'utf8');
53
- } catch (err) {
54
- const code = (err as NodeJS.ErrnoException).code;
55
- if (code !== 'ENOENT') throw err;
56
- lastErr = err;
57
- }
58
- }
59
- throw lastErr ?? new Error(`bridge asset not found: ${name}`);
45
+ return readFile(
46
+ fileURLToPath(
47
+ resolveBridgeAssetUrl({
48
+ name,
49
+ moduleUrl: import.meta.url,
50
+ }),
51
+ ),
52
+ 'utf8',
53
+ );
54
+ }
55
+
56
+ export function resolveBridgeAssetUrl({
57
+ name,
58
+ moduleUrl,
59
+ }: {
60
+ name: string;
61
+ moduleUrl: string | URL;
62
+ }): URL {
63
+ return new URL(`./bridge/${name}`, moduleUrl);
60
64
  }
@@ -18,7 +18,7 @@ export type OutboundMessage = z.infer<typeof outboundMessageSchema>;
18
18
 
19
19
  export const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
20
20
  instructions: z.string().optional(),
21
- reasoningEffort: z.enum(['low', 'medium', 'high']).optional(),
21
+ reasoningEffort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
22
22
  webSearch: z.boolean().optional(),
23
23
  codexConfig: z.record(z.string(), z.unknown()).optional(),
24
24
  mcpServers: z.record(z.string(), z.unknown()).optional(),
@@ -1,4 +1,4 @@
1
- import { createHash, randomBytes } from 'node:crypto';
1
+ import { createHash } from 'node:crypto';
2
2
  import path from 'node:path';
3
3
  import {
4
4
  commonTool,
@@ -22,6 +22,7 @@ import {
22
22
  import {
23
23
  applyCredentialForwarding,
24
24
  classifyDiskLog,
25
+ createBridgeToken,
25
26
  createSandboxCredentialEnvironment,
26
27
  createBridgeErrorHandler,
27
28
  createBridgeStartupError,
@@ -35,6 +36,7 @@ import {
35
36
  shellQuote,
36
37
  warnCredentialBrokeringUnavailable,
37
38
  waitForBridgeReady,
39
+ withBridgeToken,
38
40
  writeSkills as writeHarnessSkills,
39
41
  type WriteSkillsResult,
40
42
  } from '@ai-sdk/harness/utils';
@@ -114,7 +116,7 @@ export type CodexHarnessSettings = {
114
116
  * Reasoning effort for reasoning-capable models. Leaving this unset
115
117
  * defers to the CLI's default.
116
118
  */
117
- readonly reasoningEffort?: 'low' | 'medium' | 'high';
119
+ readonly reasoningEffort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
118
120
  /**
119
121
  * When `true`, allow the underlying runtime to use live web search.
120
122
  */
@@ -205,7 +207,7 @@ export function createCodex(
205
207
  lifecycleStateSchema: codexResumeStateSchema,
206
208
  getBootstrap: getCodexBootstrap,
207
209
  doStart: async startOpts => {
208
- const model = startOpts.model ?? settings.model ?? DEFAULT_CODEX_MODEL;
210
+ const model = settings.model ?? DEFAULT_CODEX_MODEL;
209
211
  if (startOpts.builtinToolFiltering != null) {
210
212
  throw new HarnessCapabilityUnsupportedError({
211
213
  message:
@@ -434,7 +436,7 @@ export function createCodex(
434
436
  });
435
437
  const token =
436
438
  settings.mintBridgeToken == null
437
- ? randomBytes(32).toString('hex')
439
+ ? createBridgeToken()
438
440
  : settings.mintBridgeToken(sandboxId!);
439
441
  const forwardedAuthEnvironment = credentialsBrokered
440
442
  ? sandboxAuthEnvironment
@@ -667,18 +669,6 @@ function openWebSocket({
667
669
  });
668
670
  }
669
671
 
670
- function withBridgeToken({
671
- endpoint,
672
- token,
673
- }: {
674
- endpoint: HarnessV1PortEndpoint;
675
- token: string;
676
- }): HarnessV1PortEndpoint {
677
- const bridgeUrl = new URL(endpoint.url);
678
- bridgeUrl.searchParams.set('agent_bridge_token', token);
679
- return { ...endpoint, url: bridgeUrl.toString() };
680
- }
681
-
682
672
  function createSession({
683
673
  sessionId,
684
674
  channel,
@@ -709,7 +699,7 @@ function createSession({
709
699
  /** Undefined on `attach` — the live bridge was spawned by another process. */
710
700
  proc: Experimental_SandboxProcess | undefined;
711
701
  model: string | undefined;
712
- reasoningEffort: 'low' | 'medium' | 'high' | undefined;
702
+ reasoningEffort: 'low' | 'medium' | 'high' | 'xhigh' | 'max' | undefined;
713
703
  webSearch: boolean | undefined;
714
704
  codexConfig: Record<string, unknown> | undefined;
715
705
  mcpServers: Record<string, unknown> | undefined;
@@ -958,7 +948,6 @@ function createSession({
958
948
  return {
959
949
  sessionId,
960
950
  isResume,
961
- modelId: model,
962
951
  doPromptTurn: async promptOpts => {
963
952
  if (
964
953
  promptOpts.responseFormat?.type === 'json' &&
@@ -1011,7 +1000,7 @@ function createSession({
1011
1000
  ...(promptOpts.instructions
1012
1001
  ? { instructions: promptOpts.instructions }
1013
1002
  : {}),
1014
- model,
1003
+ model: promptOpts.model ?? model,
1015
1004
  reasoningEffort,
1016
1005
  webSearch,
1017
1006
  ...(codexConfig == null ? {} : { codexConfig }),
@@ -1088,7 +1077,7 @@ function createSession({
1088
1077
  ...(continueOpts.instructions
1089
1078
  ? { instructions: continueOpts.instructions }
1090
1079
  : {}),
1091
- model,
1080
+ model: continueOpts.model ?? model,
1092
1081
  reasoningEffort,
1093
1082
  webSearch,
1094
1083
  ...(codexConfig == null ? {} : { codexConfig }),