@mclawnet/agent 0.6.35 → 0.6.36
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/cli.js +6 -6
- package/dist/__tests__/collect-manifest.test.d.ts +2 -0
- package/dist/__tests__/collect-manifest.test.d.ts.map +1 -0
- package/dist/__tests__/hub-connection-on-activity.test.d.ts +2 -0
- package/dist/__tests__/hub-connection-on-activity.test.d.ts.map +1 -0
- package/dist/__tests__/hub-connection-wake-watch.test.d.ts +2 -0
- package/dist/__tests__/hub-connection-wake-watch.test.d.ts.map +1 -0
- package/dist/__tests__/ideas-rest-client.test.d.ts +2 -0
- package/dist/__tests__/ideas-rest-client.test.d.ts.map +1 -0
- package/dist/__tests__/legacy-claude-execute-compat.test.d.ts +2 -0
- package/dist/__tests__/legacy-claude-execute-compat.test.d.ts.map +1 -0
- package/dist/__tests__/no-adapter-cycle.test.d.ts +2 -0
- package/dist/__tests__/no-adapter-cycle.test.d.ts.map +1 -0
- package/dist/__tests__/session-manager-merge.test.d.ts +2 -0
- package/dist/__tests__/session-manager-merge.test.d.ts.map +1 -0
- package/dist/__tests__/session-manager-sticky.test.d.ts +2 -0
- package/dist/__tests__/session-manager-sticky.test.d.ts.map +1 -0
- package/dist/__tests__/session-protocol-dispatch.test.d.ts +2 -0
- package/dist/__tests__/session-protocol-dispatch.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-bridge.test.d.ts +2 -0
- package/dist/__tests__/worktree-bridge.test.d.ts.map +1 -0
- package/dist/backend-adapter.d.ts +6 -232
- package/dist/backend-adapter.d.ts.map +1 -1
- package/dist/backend-factory-AFF6I7YF.js +11 -0
- package/dist/backend-factory.d.ts +23 -1
- package/dist/backend-factory.d.ts.map +1 -1
- package/dist/bootstrap-deps.d.ts +22 -0
- package/dist/bootstrap-deps.d.ts.map +1 -1
- package/dist/bootstrap-deps.js +23 -4
- package/dist/bootstrap-deps.js.map +1 -1
- package/dist/{chunk-PJ5M6Q36.js → chunk-376QZ7JB.js} +2 -2
- package/dist/chunk-376QZ7JB.js.map +1 -0
- package/dist/{chunk-B733MQCA.js → chunk-GOCWMRBB.js} +1772 -284
- package/dist/chunk-GOCWMRBB.js.map +1 -0
- package/dist/{chunk-M2CDVPQF.js → chunk-JH6RGJBQ.js} +2 -2
- package/dist/{chunk-FYM7CXUI.js → chunk-VAEFJLPL.js} +25 -3
- package/dist/chunk-VAEFJLPL.js.map +1 -0
- package/dist/{dist-EGT2NQEW.js → dist-NWVHAP5R.js} +155 -13
- package/dist/dist-NWVHAP5R.js.map +1 -0
- package/dist/errors.d.ts +20 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/hub-connection.d.ts +25 -1
- package/dist/hub-connection.d.ts.map +1 -1
- package/dist/ideas-rest-client.d.ts +25 -0
- package/dist/ideas-rest-client.d.ts.map +1 -0
- package/dist/index.js +3 -3
- package/dist/{linux-IHA4O633.js → linux-MBU6ERXL.js} +3 -3
- package/dist/{macos-G4VK2253.js → macos-I2DUWFUH.js} +3 -3
- package/dist/projects-handler.d.ts +146 -1
- package/dist/projects-handler.d.ts.map +1 -1
- package/dist/service/index.js +5 -5
- package/dist/session-manager.d.ts +58 -0
- package/dist/session-manager.d.ts.map +1 -1
- package/dist/start.d.ts.map +1 -1
- package/dist/start.js +3 -2
- package/dist/{windows-P6U3JLUZ.js → windows-PEJ3KOLC.js} +3 -3
- package/dist/worktree-bridge.d.ts +51 -0
- package/dist/worktree-bridge.d.ts.map +1 -0
- package/package.json +9 -8
- package/dist/backend-factory-VRPU3534.js +0 -9
- package/dist/chunk-B733MQCA.js.map +0 -1
- package/dist/chunk-FYM7CXUI.js.map +0 -1
- package/dist/chunk-PJ5M6Q36.js.map +0 -1
- package/dist/dist-EGT2NQEW.js.map +0 -1
- /package/dist/{backend-factory-VRPU3534.js.map → backend-factory-AFF6I7YF.js.map} +0 -0
- /package/dist/{chunk-M2CDVPQF.js.map → chunk-JH6RGJBQ.js.map} +0 -0
- /package/dist/{linux-IHA4O633.js.map → linux-MBU6ERXL.js.map} +0 -0
- /package/dist/{macos-G4VK2253.js.map → macos-I2DUWFUH.js.map} +0 -0
- /package/dist/{windows-P6U3JLUZ.js.map → windows-PEJ3KOLC.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/backend-factory.ts"],"sourcesContent":["import type { BackendAdapter } from \"./backend-adapter.js\";\n\nexport type BackendKind = \"claude\" | \"codex\";\n\nconst cache = new Map<BackendKind, BackendAdapter>();\n\nexport function __resetBackendFactoryCache(): void {\n cache.clear();\n}\n\nexport interface BackendFactoryContext {\n /** Role instance / template name — surfaces in error messages so users know\n * which role is misconfigured when its backend package fails to load. */\n roleName?: string;\n}\n\n/**\n * Resolve a BackendAdapter for the given backend kind.\n *\n * - \"claude\" / undefined → @mclawnet/claude-adapter (back-compat default).\n * - \"codex\" → @mclawnet/codex-adapter via dynamic import so the codex bundle\n * isn't pulled into claude-only deployments.\n *\n * Results are cached per kind; subsequent calls return the same instance.\n */\nexport async function createBackendAdapter(\n kind: BackendKind | undefined,\n ctx: BackendFactoryContext = {},\n): Promise<BackendAdapter> {\n const resolved: BackendKind = kind ?? \"claude\";\n const cached = cache.get(resolved);\n if (cached) return cached;\n\n let adapter: BackendAdapter;\n if (resolved === \"claude\") {\n try {\n // Type-erased dynamic import: claude-adapter has a type-only ref back\n // to @mclawnet/agent, so resolving its types here would create a\n // tsc-time cycle. Both adapters are built AFTER agent, so the dist\n // files only exist at runtime.\n const mod = (await import(\"@mclawnet/claude-adapter\" as string)) as {\n ClaudeCodeAdapter: new () => BackendAdapter;\n };\n adapter = new mod.ClaudeCodeAdapter();\n } catch (err) {\n throw rethrowWithRole(\n err,\n ctx.roleName,\n \"failed to load @mclawnet/claude-adapter\",\n );\n }\n } else if (resolved === \"codex\") {\n try {\n const mod = (await import(\"@mclawnet/codex-adapter\" as string)) as {\n CodexAdapter: new () => BackendAdapter;\n };\n adapter = new mod.CodexAdapter();\n } catch (err) {\n throw rethrowWithRole(\n err,\n ctx.roleName,\n \"failed to load @mclawnet/codex-adapter (is codex CLI installed?)\",\n );\n }\n } else {\n throw new Error(`unknown backend kind: ${resolved}`);\n }\n\n cache.set(resolved, adapter);\n return adapter;\n}\n\nfunction rethrowWithRole(err: unknown, roleName: string | undefined, prefix: string): Error {\n const base = err instanceof Error ? err.message : String(err);\n const tag = roleName ? ` [role=${roleName}]` : \"\";\n return new Error(`${prefix}${tag}: ${base}`);\n}\n"],"mappings":";AAIA,IAAM,QAAQ,oBAAI,IAAiC;AAE5C,SAAS,6BAAmC;AACjD,QAAM,MAAM;AACd;AAiBA,eAAsB,qBACpB,MACA,MAA6B,CAAC,GACL;AACzB,QAAM,WAAwB,QAAQ;AACtC,QAAM,SAAS,MAAM,IAAI,QAAQ;AACjC,MAAI,OAAQ,QAAO;AAEnB,MAAI;AACJ,MAAI,aAAa,UAAU;AACzB,QAAI;AAKF,YAAM,MAAO,MAAM,OAAO,0BAAoC;AAG9D,gBAAU,IAAI,IAAI,kBAAkB;AAAA,IACtC,SAAS,KAAK;AACZ,YAAM;AAAA,QACJ;AAAA,QACA,IAAI;AAAA,QACJ;AAAA,MACF;AAAA,IACF;AAAA,EACF,WAAW,aAAa,SAAS;AAC/B,QAAI;AACF,YAAM,MAAO,MAAM,OAAO,oBAAmC;AAG7D,gBAAU,IAAI,IAAI,aAAa;AAAA,IACjC,SAAS,KAAK;AACZ,YAAM;AAAA,QACJ;AAAA,QACA,IAAI;AAAA,QACJ;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AACL,UAAM,IAAI,MAAM,yBAAyB,QAAQ,EAAE;AAAA,EACrD;AAEA,QAAM,IAAI,UAAU,OAAO;AAC3B,SAAO;AACT;AAEA,SAAS,gBAAgB,KAAc,UAA8B,QAAuB;AAC1F,QAAM,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC5D,QAAM,MAAM,WAAW,UAAU,QAAQ,MAAM;AAC/C,SAAO,IAAI,MAAM,GAAG,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;AAC7C;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["import { readFileSync, writeFileSync, mkdirSync, existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { homedir, hostname } from \"node:os\";\nimport type { BackendType } from \"@mclawnet/shared\";\nimport { createLogger } from \"@mclawnet/logger\";\n\nconst log = createLogger({ module: \"config\" });\n\nexport interface EmbeddingConfig {\n /** Embedding provider mode: auto / openai / ollama / hash */\n provider?: string;\n /** OpenAI-compatible API base URL (e.g. http://localhost:4141/v1 for copilot proxy) */\n openaiBaseUrl?: string;\n /** OpenAI API key (use \"dummy\" for copilot proxy) */\n openaiApiKey?: string;\n /** OpenAI embedding model name */\n openaiModel?: string;\n /** Ollama server URL */\n ollamaUrl?: string;\n /** Ollama embedding model name */\n ollamaModel?: string;\n}\n\nexport interface AgentConfig {\n hubUrl: string;\n token: string;\n name: string;\n backendType: BackendType;\n embedding?: EmbeddingConfig;\n}\n\nconst CONFIG_DIR = join(homedir(), \".clawnet\");\nconst SETTINGS_FILE = join(CONFIG_DIR, \"settings.json\");\n\nconst DEFAULT_HUB_URL = process.env.CLAWNET_DEFAULT_HUB_URL || \"wss://mclaw.work/ws/agent\";\n\nconst DEFAULTS: AgentConfig = {\n hubUrl: DEFAULT_HUB_URL,\n token: \"\",\n name: hostname(),\n backendType: \"claude-code\",\n};\n\n/** Ensure hubUrl uses ws(s):// protocol and ends with /ws/agent */\nfunction normalizeHubUrl(url: string): string {\n // Convert http(s):// to ws(s)://\n url = url.replace(/^https:\\/\\//, \"wss://\").replace(/^http:\\/\\//, \"ws://\");\n // Default to wss:// if no protocol\n if (!/^wss?:\\/\\//.test(url)) url = \"wss://\" + url;\n if (url.endsWith(\"/ws/agent\")) return url;\n return url.replace(/\\/+$/, \"\") + \"/ws/agent\";\n}\n\n/**\n * Map structured embedding config to CLAWNET_* env vars.\n * Only sets vars that are not already defined in process.env.\n */\nfunction applyEmbeddingConfig(embedding: EmbeddingConfig): void {\n const mapping: Array<[keyof EmbeddingConfig, string]> = [\n [\"provider\", \"CLAWNET_EMBEDDING_PROVIDER\"],\n [\"openaiBaseUrl\", \"CLAWNET_OPENAI_BASE_URL\"],\n [\"openaiApiKey\", \"CLAWNET_OPENAI_API_KEY\"],\n [\"openaiModel\", \"CLAWNET_OPENAI_EMBEDDING_MODEL\"],\n [\"ollamaUrl\", \"CLAWNET_OLLAMA_URL\"],\n [\"ollamaModel\", \"CLAWNET_OLLAMA_MODEL\"],\n ];\n\n for (const [configKey, envKey] of mapping) {\n const value = embedding[configKey];\n if (value !== undefined && process.env[envKey] === undefined) {\n process.env[envKey] = value;\n }\n }\n}\n\n/** Load config: CLI opts > env vars > settings file > defaults */\nexport function loadConfig(cliOpts: Partial<AgentConfig> = {}): AgentConfig {\n let fileConfig: Partial<AgentConfig> = {};\n\n log.info({ path: SETTINGS_FILE }, \"loading config\");\n\n if (existsSync(SETTINGS_FILE)) {\n try {\n fileConfig = JSON.parse(readFileSync(SETTINGS_FILE, \"utf-8\"));\n log.info(\n { hubUrl: fileConfig.hubUrl, hasToken: !!fileConfig.token, name: fileConfig.name },\n \"settings.json loaded\"\n );\n } catch (e) {\n log.warn({ err: e }, \"failed to parse settings.json\");\n }\n } else {\n log.warn(\"settings.json not found\");\n }\n\n // Apply structured embedding config to process.env\n if (fileConfig.embedding) {\n applyEmbeddingConfig(fileConfig.embedding);\n }\n\n const hubUrl =\n cliOpts.hubUrl ??\n process.env.CLAWNET_HUB_URL ??\n fileConfig.hubUrl ??\n DEFAULTS.hubUrl;\n\n const resolved = {\n hubUrl: normalizeHubUrl(hubUrl),\n token:\n cliOpts.token ??\n process.env.CLAWNET_TOKEN ??\n fileConfig.token ??\n DEFAULTS.token,\n name:\n cliOpts.name ??\n process.env.CLAWNET_NAME ??\n fileConfig.name ??\n DEFAULTS.name,\n backendType:\n (cliOpts.backendType as BackendType) ??\n (process.env.CLAWNET_BACKEND_TYPE as BackendType) ??\n (fileConfig.backendType as BackendType) ??\n DEFAULTS.backendType,\n embedding: fileConfig.embedding,\n };\n\n log.info(\n {\n hubUrl: resolved.hubUrl,\n hubUrlSource: cliOpts.hubUrl ? \"cli\" : process.env.CLAWNET_HUB_URL ? \"env\" : fileConfig.hubUrl ? \"file\" : \"default\",\n tokenSource: cliOpts.token ? \"cli\" : process.env.CLAWNET_TOKEN ? \"env\" : fileConfig.token ? \"file\" : \"default\",\n hasToken: !!resolved.token,\n },\n \"config resolved\"\n );\n\n return resolved;\n}\n\n/** Save config to ~/.clawnet/settings.json */\nexport function saveConfig(config: Partial<AgentConfig>): void {\n mkdirSync(CONFIG_DIR, { recursive: true });\n\n let existing: Partial<AgentConfig> = {};\n if (existsSync(SETTINGS_FILE)) {\n try {\n existing = JSON.parse(readFileSync(SETTINGS_FILE, \"utf-8\"));\n } catch {\n // ignore\n }\n }\n\n const merged = { ...existing, ...config };\n writeFileSync(SETTINGS_FILE, JSON.stringify(merged, null, 2) + \"\\n\");\n}\n"],"mappings":";AAAA,SAAS,cAAc,eAAe,WAAW,kBAAkB;AACnE,SAAS,YAAY;AACrB,SAAS,SAAS,gBAAgB;AAElC,SAAS,oBAAoB;AAE7B,IAAM,MAAM,aAAa,EAAE,QAAQ,SAAS,CAAC;AAyB7C,IAAM,aAAa,KAAK,QAAQ,GAAG,UAAU;AAC7C,IAAM,gBAAgB,KAAK,YAAY,eAAe;AAEtD,IAAM,kBAAkB,QAAQ,IAAI,2BAA2B;AAE/D,IAAM,WAAwB;AAAA,EAC5B,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM,SAAS;AAAA,EACf,aAAa;AACf;AAGA,SAAS,gBAAgB,KAAqB;AAE5C,QAAM,IAAI,QAAQ,eAAe,QAAQ,EAAE,QAAQ,cAAc,OAAO;AAExE,MAAI,CAAC,aAAa,KAAK,GAAG,EAAG,OAAM,WAAW;AAC9C,MAAI,IA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,SACX,SAAS;AAAA,IACX,MACE,QAAQ,QACR,QAAQ,IAAI,gBACZ,WAAW,QACX,SAAS;AAAA,IACX,aACG,QAAQ,eACR,QAAQ,IAAI,wBACZ,WAAW,eACZ,SAAS;AAAA,IACX,WAAW,WAAW;AAAA,EACxB;AAEA,MAAI;AAAA,IACF;AAAA,MACE,QAAQ,SAAS;AAAA,MACjB,cAAc,QAAQ,SAAS,QAAQ,QAAQ,IAAI,kBAAkB,QAAQ,WAAW,SAAS,SAAS;AAAA,MAC1G,aAAa,QAAQ,QAAQ,QAAQ,QAAQ,IAAI,gBAAgB,QAAQ,WAAW,QAAQ,SAAS;AAAA,MACrG,UAAU,CAAC,CAAC,SAAS;AAAA,IACvB;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AAGO,SAAS,WAAW,QAAoC;AAC7D,YAAU,YAAY,EAAE,WAAW,KAAK,CAAC;AAEzC,MAAI,WAAiC,CAAC;AACtC,MAAI,WAAW,aAAa,GAAG;AAC7B,QAAI;AACF,iBAAW,KAAK,MAAM,aAAa,eAAe,OAAO,CAAC;AAAA,IAC5D,QAAQ;AAAA,IAER;AAAA,EACF;AAEA,QAAM,SAAS,EAAE,GAAG,UAAU,GAAG,OAAO;AACxC,gBAAc,eAAe,KAAK,UAAU,QAAQ,MAAM,CAAC,IAAI,IAAI;AACrE;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../codex-adapter/src/codex-adapter.ts","../../codex-adapter/src/codex-spawn-args.ts","../../codex-adapter/src/json-rpc-client.ts","../../codex-adapter/src/permission-mapper.ts","../../codex-adapter/src/output-mapper.ts"],"sourcesContent":["import { execSync, spawn, type ChildProcess } from \"node:child_process\";\nimport { EventEmitter } from \"node:events\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { homedir, platform } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { buildCodexSpawnArgs, cleanupBriefingFile, type McpServerConfig } from \"./codex-spawn-args.js\";\nimport type {\n BackendAdapter,\n BackendProcess,\n BackendOutput,\n PermissionDecision,\n PermissionRequest,\n SpawnOptions,\n} from \"@mclawnet/agent\";\nimport { createLogger, preview } from \"@mclawnet/logger\";\nimport { JsonRpcClient } from \"./json-rpc-client.js\";\nimport {\n buildApprovalReply,\n parseApprovalRequest,\n type ApprovalWireFamily,\n} from \"./permission-mapper.js\";\nimport { mapCodexFrame } from \"./output-mapper.js\";\n\nconst log = createLogger({ module: \"codex-adapter\" });\n\nconst isWin = platform() === \"win32\";\n\n/**\n * Resolve the codex CLI binary the same way claude-adapter resolves claude:\n * use the OS lookup tool (where/which), fall back to known install paths.\n *\n * Without this, Windows users hit two failure modes:\n * 1. `spawn(\"codex\", ...)` fails because Windows `CreateProcess` does NOT\n * consult PATHEXT — only cmd.exe does — so a bare \"codex\" never finds\n * the npm-installed `codex.cmd` / `codex.exe` shim.\n * 2. Even if cmd.exe is on the way, post-CVE-2024-27980 Node refuses to\n * spawn `.cmd` / `.bat` without `shell: true`.\n */\nfunction resolveCodexBin(explicit?: string): string {\n if (explicit && explicit !== \"codex\") return explicit;\n\n const names = isWin ? [\"codex.exe\", \"codex.cmd\", \"codex.bat\"] : [\"codex\"];\n const whichCmd = isWin ? \"where\" : \"which\";\n for (const name of names) {\n try {\n const found = execSync(`${whichCmd} ${name}`, {\n encoding: \"utf-8\",\n // 1.5s is plenty for `where`/`which` on a healthy machine; the old\n // 5s × 3 worst-case (15s blocking event loop) showed up on slow\n // domain-joined Windows hosts / network-PATH setups.\n timeout: 1500,\n stdio: [\"ignore\", \"pipe\", \"ignore\"],\n }).trim().split(/\\r?\\n/)[0];\n if (found && existsSync(found)) return found;\n } catch {\n /* not in PATH */\n }\n }\n\n const home = homedir();\n const fallbacks = isWin\n ? [\n join(home, \"AppData\", \"Roaming\", \"npm\", \"codex.cmd\"),\n join(home, \"AppData\", \"Roaming\", \"npm\", \"codex.exe\"),\n join(home, \".cargo\", \"bin\", \"codex.exe\"),\n join(home, \".local\", \"bin\", \"codex.exe\"),\n ]\n : [\n join(home, \".cargo\", \"bin\", \"codex\"),\n join(home, \".local\", \"bin\", \"codex\"),\n \"/opt/homebrew/bin/codex\",\n \"/usr/local/bin/codex\",\n ];\n for (const p of fallbacks) {\n if (existsSync(p)) return p;\n }\n\n return isWin ? \"codex.cmd\" : \"codex\";\n}\n\n/**\n * Module-level cache for the resolved codex binary. Without this, every\n * CodexAdapter instance (created per-session by the agent's adapter factory)\n * pays the `where`/`which` cost again. On a Windows host where `where`\n * times out (slow PATH, network drive, AV scan), 3 lookups × 1.5s would\n * stall agent startup for every spawn.\n *\n * Cache is keyed on the override string so explicit per-instance overrides\n * (e.g. tests) bypass the shared cache.\n */\nconst resolvedCodexBinCache = new Map<string, string>();\nlet resolveCodexBinCallCount = 0;\nfunction getResolvedCodexBin(explicit?: string): string {\n const key = explicit ?? \"\";\n const hit = resolvedCodexBinCache.get(key);\n if (hit) return hit;\n resolveCodexBinCallCount++;\n const resolved = resolveCodexBin(explicit);\n resolvedCodexBinCache.set(key, resolved);\n return resolved;\n}\n\n/** Test-only: clear the resolved-bin cache between cases. */\nexport function __resetResolvedCodexBinCache(): void {\n resolvedCodexBinCache.clear();\n resolveCodexBinCallCount = 0;\n}\n\n/** Test-only: how many times resolveCodexBin actually ran (i.e. cache misses). */\nexport function __getResolveCodexBinCallCount(): number {\n return resolveCodexBinCallCount;\n}\n\n/**\n * Resolve how to spawn codex without invoking cmd.exe on Windows.\n *\n * codex.cmd is an npm shim that dispatches to the real Rust .exe (or in\n * some installs, a node-shimmed cli.js). Spawning the .cmd directly:\n * - requires `shell: true` post-CVE-2024-27980, which would also have to\n * deal with cmd.exe's 8191-char command-line cap.\n * - drops the child's stdio attachment in subtle ways through cmd.exe.\n *\n * So we parse the shim and spawn the underlying .exe (or `node cli.js`)\n * directly. Mirrors claude-adapter's resolveSpawnTarget pattern.\n */\nexport function resolveSpawnTarget(codexBin: string): {\n command: string;\n prefixArgs: string[];\n} {\n // Re-read platform per call (instead of using the module-level `isWin`\n // constant) so tests can flip `process.platform` to exercise Windows\n // paths from a macOS / Linux CI. Mirrors claude-adapter's pattern.\n const isWindows = platform() === \"win32\";\n if (!isWindows || !codexBin.toLowerCase().endsWith(\".cmd\")) {\n return { command: codexBin, prefixArgs: [] };\n }\n try {\n const cmdContent = readFileSync(codexBin, \"utf-8\");\n // codex shim typically points at a sibling .exe: e.g.\n // \"%~dp0\\node_modules\\@openai\\codex\\bin\\codex.exe\" %*\n const exeMatch = cmdContent.match(/(?:%~?dp0%?)[\\\\/](.+?\\.exe)/i);\n if (exeMatch) {\n const relParts = exeMatch[1].split(/[\\\\/]/);\n const exePath = join(dirname(codexBin), ...relParts);\n if (existsSync(exePath)) return { command: exePath, prefixArgs: [] };\n }\n // Fallback: npm-style `node cli.js` shim.\n const jsMatch = cmdContent.match(/(?:%~?dp0%?)[\\\\/](.+?\\.js)/i);\n if (jsMatch) {\n const relParts = jsMatch[1].split(/[\\\\/]/);\n const cliJsPath = join(dirname(codexBin), ...relParts);\n if (existsSync(cliJsPath)) {\n return { command: process.execPath, prefixArgs: [cliJsPath] };\n }\n }\n } catch {\n /* fall through */\n }\n // Last resort: invoke through cmd.exe. Loses the 8191-char cap protection\n // but at least the process gets spawned. Args are short for codex so this\n // is unlikely to bite.\n return { command: codexBin, prefixArgs: [] };\n}\n\nconst CLAWNET_CLIENT_INFO = {\n name: \"clawnet\",\n version: \"0.1.0\",\n title: \"ClawNet Agent\",\n};\n\n/**\n * Per-process state wrapper. Holds the JSON-RPC client + pending approval\n * resolvers so `respondToPermission` can find the right server-initiated\n * request id to reply to.\n */\nexport class CodexProcess extends EventEmitter implements BackendProcess {\n readonly id: string;\n readonly workDir: string;\n pid?: number;\n proc?: ChildProcess;\n private killed = false;\n /** callId → JSON-RPC server-request id we still owe a result to. */\n pendingApprovals = new Map<string, number>();\n /** callId → originating wire family (drives v2/legacy/mcp reply shape). */\n approvalMethods = new Map<string, ApprovalWireFamily>();\n /** Monotonic counter for approval resolver keys. */\n private nextResolverKey = 1;\n /** Resolver registered by the rpc client for each pending approval. */\n approvalResolvers = new Map<number, (reply: Record<string, string>) => void>();\n rpc?: JsonRpcClient;\n backendSessionId?: string;\n /**\n * Thread id to resume on agent restart. When set, handshake() sends\n * `thread/resume { threadId }` instead of `thread/start { cwd }`.\n * Set from SpawnOptions.resumeId in CodexAdapter.spawn(). Must NOT be\n * passed as `--resume` CLI flag — app-server rejects it.\n */\n resumeId?: string;\n /** True once `initialize` round-trip + `thread/start` (or `thread/resume`) have completed. */\n handshakeComplete = false;\n /** Inputs queued by send() while the handshake is still in flight. */\n pendingInputs: string[] = [];\n /** Temp file for briefing injection; cleaned up on kill(). */\n briefingFile?: string;\n /**\n * Set by CodexAdapter.spawn() so handshake() can surface real process-exit\n * info if the codex CLI died (e.g. arg parse error). Without this, a dead\n * process leads to a generic \"handshake timeout\" instead of the actual\n * \"error: unexpected argument …\" stderr message.\n *\n * Default returns (null, \"\") for tests that construct CodexProcess\n * directly without going through spawn() (e.g. attachRpc mock pipes).\n * spawn() overrides these with real getters wired to the child process.\n */\n getExitInfo: () => { code: number | null; signal: string | null } | null = () => null;\n getStderr: () => string = () => \"\";\n\n /** Allocate a resolver key. Monotonic; never reused. */\n allocResolverKey(): number {\n return this.nextResolverKey++;\n }\n\n constructor(sessionId: string, workDir: string, proc?: ChildProcess) {\n super();\n this.id = sessionId;\n this.workDir = workDir;\n this.proc = proc;\n this.pid = proc?.pid;\n }\n\n async kill(): Promise<void> {\n this.killed = true;\n // Drain any pending approval bookkeeping so long-running hubs don't leak\n // entries on aborted sessions. Resolve any outstanding RPC promise with a\n // \"cancel\"-equivalent so callers awaiting `respondToPermission` never hang.\n for (const [, resolver] of this.approvalResolvers) {\n try {\n resolver({ decision: \"abort\" });\n } catch {\n // ignore\n }\n }\n this.pendingApprovals.clear();\n this.approvalMethods.clear();\n this.approvalResolvers.clear();\n this.pendingInputs.length = 0;\n if (this.briefingFile) {\n cleanupBriefingFile(this.briefingFile);\n this.briefingFile = undefined;\n }\n if (this.proc && !this.proc.killed) {\n try {\n this.proc.kill(\"SIGTERM\");\n } catch {\n // ignore\n }\n }\n }\n\n isAlive(): boolean {\n if (this.killed) return false;\n if (!this.proc) return true;\n return !this.proc.killed && this.proc.exitCode === null;\n }\n}\n\nexport interface CodexAdapterOptions {\n /** Override path to the codex binary. Default: lookup in PATH. */\n codexBin?: string;\n /**\n * Max time to wait for codex handshake (initialize + thread/start|resume)\n * to complete before emitting an error. Default: 15s. Used to detect the\n * case where the codex process dies mid-handshake (CLI parse error,\n * crash) — without this, pendingInputs stack up forever and the swarm\n * silently stalls.\n */\n handshakeTimeoutMs?: number;\n}\n\n/**\n * CodexAdapter — BackendAdapter wrapping `codex app-server --listen stdio://`.\n *\n * M3.S3 scope: spawn/stop/send/onOutput plus the permission flow\n * (`onPermissionRequest` / `respondToPermission`). Resume + token-budget +\n * MCP plumbing land in follow-up slices.\n */\nexport class CodexAdapter implements BackendAdapter {\n readonly type = \"codex\";\n private codexBin: string;\n private handshakeTimeoutMs: number;\n\n constructor(options?: CodexAdapterOptions) {\n this.codexBin = getResolvedCodexBin(options?.codexBin);\n // Precedence: explicit constructor option > env var > 15s default. The\n // env var (CLAWNET_CODEX_HANDSHAKE_TIMEOUT_MS) is the escape hatch for\n // slow CI / cold-start machines where 15s isn't enough and the user\n // can't easily inject a CodexAdapterOptions override.\n const envTimeout = Number(process.env.CLAWNET_CODEX_HANDSHAKE_TIMEOUT_MS);\n this.handshakeTimeoutMs =\n options?.handshakeTimeoutMs ??\n (Number.isFinite(envTimeout) && envTimeout > 0 ? envTimeout : 15000);\n }\n\n async spawn(options: SpawnOptions): Promise<CodexProcess> {\n let cwd = options.workDir || process.cwd();\n if (!existsSync(cwd)) cwd = homedir();\n\n // Build args with MCP + briefing injection\n const mcpServer = this.buildMcpServerConfig(options);\n const { args, briefingFile } = buildCodexSpawnArgs({\n sessionId: options.sessionId,\n resumeId: options.resumeId,\n systemPrompt: options.systemPrompt,\n mcpServer,\n sandbox: options.sandbox,\n });\n\n log.info(\n { sessionId: options.sessionId, bin: this.codexBin, args, cwd, resumeId: options.resumeId },\n \"codex spawn: forking app-server\",\n );\n const { command, prefixArgs } = resolveSpawnTarget(this.codexBin);\n if (command !== this.codexBin) {\n log.info(\n { sessionId: options.sessionId, bin: this.codexBin, spawnCmd: command, prefixArgs },\n \"codex spawn: using resolved shim target (windows .cmd bypass)\",\n );\n }\n const proc = spawn(command, [...prefixArgs, ...args], {\n cwd,\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n env: process.env,\n windowsHide: true,\n });\n // Capture exit state into a closure so handshake() can surface it if\n // initialize / thread RPC times out. Without this guard a dead codex\n // (e.g. CLI arg parse error → ~600ms after spawn) would leave the\n // adapter waiting handshakeTimeoutMs (default 15s) with a generic\n // \"handshake timeout\" message. With it, we report exit code + stderr.\n const stderrChunks: string[] = [];\n proc.stderr?.on(\"data\", (chunk: Buffer) => {\n const text = chunk.toString(\"utf8\").trim();\n if (text) {\n stderrChunks.push(text);\n log.warn({ sessionId: options.sessionId, stderr: text }, \"codex stderr\");\n }\n });\n let exitInfo: { code: number | null; signal: string | null } | null = null;\n // cp is built AFTER this Promise resolves, so capture a thunk and resolve\n // it lazily. proc.on(\"exit\") needs to re-emit on cp so the BackendAdapter\n // contract's onExit/onError subscribers (session-manager) actually fire —\n // without this re-emit, codex crashes silently never reach the swarm\n // coordinator's handleRoleCrashed path and the queen stays unaware.\n let createdCp: CodexProcess | undefined;\n // Shared emit helper: invoked both from the proc.on(\"exit\") handler and\n // the late-fire safety branch below. Centralizes the \"emit exit + maybe\n // emit error with stderr\" contract so future changes can't drift.\n const emitProcessExit = (cp: CodexProcess, code: number | null, signal: string | null) => {\n try { cp.emit(\"exit\", code); } catch { /* listener threw */ }\n const isClean = code === 0 || signal === \"SIGTERM\";\n if (isClean) return;\n // Surface stderr via \"error\" so the agent's onSessionError handler\n // can include the real failure cause (e.g. \"error: unexpected\n // argument\", codex auth missing) instead of a bare \"exit code=1\".\n const stderr = stderrChunks.join(\"\\n\").trim().slice(0, 800);\n const detail = stderr ? ` — stderr: ${stderr}` : \"\";\n try {\n cp.emit(\n \"error\",\n new Error(`codex process exited (code=${code ?? \"null\"}, signal=${signal ?? \"null\"})${detail}`),\n );\n } catch { /* listener threw */ }\n };\n proc.on(\"exit\", (code, signal) => {\n const isClean = code === 0 || signal === \"SIGTERM\";\n const level = isClean ? \"debug\" : \"warn\";\n log[level]({ sessionId: options.sessionId, code, signal }, \"codex process exited\");\n if (!exitInfo) exitInfo = { code, signal };\n const cpRef = createdCp;\n if (!cpRef) return;\n emitProcessExit(cpRef, code, signal);\n });\n\n await new Promise<void>((resolve, reject) => {\n const t = setTimeout(() => resolve(), 2000);\n proc.on(\"error\", (err) => {\n clearTimeout(t);\n reject(new Error(`Failed to spawn codex CLI: ${err.message}`));\n });\n proc.on(\"spawn\", () => {\n clearTimeout(t);\n log.debug({ sessionId: options.sessionId, pid: proc.pid }, \"codex spawn: process started\");\n resolve();\n });\n });\n\n const cp = new CodexProcess(options.sessionId, cwd, proc);\n cp.briefingFile = briefingFile;\n cp.resumeId = options.resumeId;\n // Expose process-exit signal to handshake so a timeout can report the\n // real cause instead of a generic \"timeout\".\n cp.getExitInfo = () => exitInfo;\n cp.getStderr = () => stderrChunks.join(\"\\n\").slice(0, 800);\n createdCp = cp;\n // Late-fire safety: if the process exited BEFORE we got here (cp wasn't\n // assigned yet so the proc.on(\"exit\") path skipped the re-emit), surface\n // it now via the same channel. setImmediate defers until session-manager\n // has had a chance to subscribe (which happens synchronously after our\n // returned cp lands).\n if (exitInfo) {\n const { code, signal } = exitInfo;\n setImmediate(() => emitProcessExit(cp, code, signal));\n }\n this.wireRpc(cp);\n return cp;\n }\n\n private buildMcpServerConfig(options: SpawnOptions): McpServerConfig | undefined {\n // Resolve clawnet-mcp-server path. The package's \"exports\" map is a\n // closed whitelist (only \".\" and \"./package.json\" are exported, plus\n // \"./server\"). Resolving `@mclawnet/mcp-server/dist/server.js` directly\n // throws ERR_PACKAGE_PATH_NOT_EXPORTED on modern Node, which is why\n // packaged-release Windows hosts saw \"not resolvable\" while the dev\n // monorepo path silently worked.\n //\n // Strategy: try the supported subpath export first (\"./server\"), then\n // resolve via package.json + join, then fall back to the legacy direct\n // path (still useful when \"./server\" isn't published yet but a hub\n // installs an older mcp-server release), then dev-monorepo fallback.\n let serverPath: string | undefined;\n const require = createRequire(import.meta.url);\n const tryResolve = (specifier: string): string | undefined => {\n try {\n const p = require.resolve(specifier);\n return p && existsSync(p) ? p : undefined;\n } catch {\n return undefined;\n }\n };\n serverPath = tryResolve(\"@mclawnet/mcp-server/server\");\n if (!serverPath) {\n try {\n const pkgPath = require.resolve(\"@mclawnet/mcp-server/package.json\");\n const candidate = join(dirname(pkgPath), \"dist\", \"server.js\");\n if (existsSync(candidate)) serverPath = candidate;\n } catch {\n /* not installed */\n }\n }\n if (!serverPath) {\n serverPath = tryResolve(\"@mclawnet/mcp-server/dist/server.js\");\n }\n if (!serverPath) {\n const devPath = join(\n import.meta.dirname ?? __dirname,\n \"../../mcp-server/dist/server.js\",\n );\n if (existsSync(devPath)) serverPath = devPath;\n }\n if (!serverPath) {\n log.warn(\n { pkg: \"@mclawnet/mcp-server\" },\n \"codex: clawnet-mcp-server not resolvable, codex role will lack MCP tools\",\n );\n return undefined;\n }\n log.debug({ serverPath }, \"codex: resolved clawnet-mcp-server path\");\n const env: Record<string, string> = {};\n if (options.workDir) env.CLAWNET_WORK_DIR = options.workDir;\n // mcp-server's server.ts:28 explicitly documents: CLAWNET_HOME is the\n // user home (NO `.clawnet` suffix) — the server appends `.clawnet`\n // itself via projectRoot(). Passing `~/.clawnet` here would yield\n // `~/.clawnet/.clawnet/...` (double append) and break inbox/task layout.\n const home = process.env.CLAWNET_HOME ?? homedir();\n env.CLAWNET_HOME = home;\n return { command: \"node\", args: [serverPath], env };\n }\n\n /**\n * Bind a CodexProcess to a JSON-RPC duplex. Public so tests can inject a\n * mocked stdin/stdout pair without spawning a real subprocess.\n *\n * Drives the v2 handshake automatically: `initialize` → `thread/start`.\n * Once `thread/start` resolves, `cp.backendSessionId` is set and a\n * `session_started` event fires so the agent's hub bridge can persist it.\n */\n attachRpc(\n cp: CodexProcess,\n stdin: NodeJS.WritableStream,\n stdout: NodeJS.ReadableStream,\n ): void {\n const rpc = new JsonRpcClient({\n stdin: stdin as never,\n stdout: stdout as never,\n onRequest: (method, params) => this.handleServerRequest(cp, method, params),\n onNotification: (method, params) => this.handleNotification(cp, method, params),\n onMalformedLine: (line, err) =>\n log.warn(\n { sessionId: cp.id, err: err.message, linePreview: line.slice(0, 200) },\n \"codex stdout: non-JSON line ignored\",\n ),\n });\n cp.rpc = rpc;\n void this.handshake(cp);\n }\n\n private async handshake(cp: CodexProcess): Promise<void> {\n if (!cp.rpc) return;\n const rpc = cp.rpc;\n const resumeId = cp.resumeId;\n log.info(\n { sessionId: cp.id, workDir: cp.workDir, resumeId },\n \"codex handshake: start\",\n );\n\n // Wrap the whole handshake in a timeout so a dead codex process (e.g.\n // killed by `--resume` CLI parse error, segfault, etc.) doesn't leave\n // pendingInputs queued forever. Without this guard the swarm silently\n // stalls — the user sees no error, just nothing happens.\n //\n // raceSettled is declared up here (before the IIFE) so the handshake\n // success path can also check it. If timeout/death wins the race,\n // handshakeAttempt may still complete later — without this guard it\n // would mutate cp.backendSessionId, emit session_started, and flush\n // pendingInputs against a process the caller already considers dead.\n let raceSettled = false;\n const handshakeAttempt = (async () => {\n await rpc.request(\"initialize\", { clientInfo: CLAWNET_CLIENT_INFO });\n log.info({ sessionId: cp.id }, \"codex handshake: initialize ok\");\n\n // Branch on resumeId — `codex app-server` rejects `--resume` CLI flag,\n // so resume MUST happen at the JSON-RPC layer via `thread/resume`.\n // `thread/start` on a resumed codex returns a NEW threadId (losing\n // conversation continuity), which is why we have to branch here.\n let threadId: string | undefined;\n if (resumeId) {\n const resumed = (await rpc.request(\"thread/resume\", { threadId: resumeId })) as\n | { thread?: { id?: string }; threadId?: string }\n | undefined;\n // Don't silently fall back to the input resumeId — if codex ever\n // migrates the thread id (the protocol allows it) we'd persist a\n // stale id and break the next restart. Treat absent thread id as a\n // protocol error so the caller sees it and can re-spawn fresh.\n threadId = resumed?.thread?.id ?? resumed?.threadId;\n } else {\n // v2 `thread/start` returns { thread: { id, sessionId, ... }, ... }.\n // The resumable identifier is `thread.id` — `sessionId` here is the\n // tree-id shared by forked threads, not what `thread/resume` wants.\n const started = (await rpc.request(\"thread/start\", { cwd: cp.workDir })) as\n | { thread?: { id?: string }; threadId?: string }\n | undefined;\n threadId = started?.thread?.id ?? started?.threadId;\n }\n\n if (!threadId) {\n throw new Error(\n `codex handshake: ${resumeId ? \"thread/resume\" : \"thread/start\"} returned no threadId`,\n );\n }\n // Race lost (timeout/death already won) → don't mutate state, don't\n // emit session_started, don't flush queued inputs. The handshake\n // error has already been reported via cp.emit(\"error\") in the\n // catch-block below.\n if (raceSettled) {\n log.warn(\n { sessionId: cp.id, threadId },\n \"codex handshake resolved AFTER race already lost — discarding result\",\n );\n return;\n }\n cp.backendSessionId = threadId;\n cp.handshakeComplete = true;\n log.info(\n { sessionId: cp.id, threadId, queuedInputs: cp.pendingInputs.length },\n \"codex handshake: complete, flushing queued inputs\",\n );\n cp.emit(\"session_started\", { backendSessionId: threadId });\n // Flush any inputs that arrived while the handshake was in flight.\n const queued = cp.pendingInputs.splice(0);\n for (const input of queued) {\n this.dispatchTurn(cp, input);\n }\n })();\n // Attach a no-op catch so handshakeAttempt rejecting AFTER losing the\n // race (timeout or death already won) doesn't bubble as an unhandled\n // promise rejection — node --unhandled-rejections=strict would crash.\n // The real error already surfaced via cp.emit(\"error\") above.\n handshakeAttempt.catch(() => {});\n\n let timeoutHandle: NodeJS.Timeout | undefined;\n let exitPollHandle: NodeJS.Timeout | undefined;\n // raceSettled is checked by the death-poll loop and the handshake\n // success path. clearTimeout in finally{} alone is insufficient:\n // poll() may be mid-execution when finally runs, scheduling the next\n // setTimeout before clear; the success path could likewise resolve a\n // late RPC after the race has been decided.\n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutHandle = setTimeout(() => {\n reject(\n new Error(\n `codex handshake timeout after ${this.handshakeTimeoutMs}ms (process may have died)`,\n ),\n );\n }, this.handshakeTimeoutMs);\n });\n\n // Process-death detector: poll exitInfo every 100ms; if codex exits\n // mid-handshake (e.g. CLI parse error), reject early with the real\n // stderr instead of waiting handshakeTimeoutMs (15s default) for the\n // generic timeout message.\n const deathPromise = new Promise<never>((_, reject) => {\n const poll = () => {\n if (raceSettled) return; // race already over — stop recursing\n const exit = cp.getExitInfo();\n if (exit) {\n const stderr = cp.getStderr();\n reject(\n new Error(\n `codex process died during handshake ` +\n `(code=${exit.code}, signal=${exit.signal}). ` +\n `stderr: ${stderr || \"(empty)\"}`,\n ),\n );\n return;\n }\n exitPollHandle = setTimeout(poll, 100);\n };\n poll();\n });\n\n try {\n await Promise.race([handshakeAttempt, timeoutPromise, deathPromise]);\n } catch (err) {\n log.error({ err, sessionId: cp.id }, \"codex v2 handshake failed\");\n cp.emit(\"error\", err);\n } finally {\n raceSettled = true;\n if (timeoutHandle) clearTimeout(timeoutHandle);\n if (exitPollHandle) clearTimeout(exitPollHandle);\n }\n }\n\n private wireRpc(cp: CodexProcess) {\n const proc = cp.proc;\n if (proc?.stdin && proc?.stdout) {\n this.attachRpc(cp, proc.stdin, proc.stdout);\n }\n }\n\n private handleServerRequest(\n cp: CodexProcess,\n method: string,\n params: unknown,\n ): Promise<unknown> {\n const parsed = parseApprovalRequest(method, params);\n if (!parsed) {\n log.warn({ method }, \"codex server-request: unrecognized method\");\n return Promise.resolve({ decision: \"denied\" });\n }\n const { req, wireFamily } = parsed;\n return new Promise((resolve) => {\n const resolverKey = cp.allocResolverKey();\n cp.pendingApprovals.set(req.callId, resolverKey);\n cp.approvalMethods.set(req.callId, wireFamily);\n cp.approvalResolvers.set(resolverKey, (reply) => {\n resolve(reply);\n });\n cp.emit(\"permission_request\", req);\n });\n }\n\n private handleNotification(cp: CodexProcess, method: string, params: unknown) {\n // v2 thread lifecycle\n if (method === \"thread/started\") {\n // codex emits this as a *notification* during normal turns too; the\n // primary session_started signal comes from thread/start's RPC result\n // (see handshake()). Suppress the duplicate here so onSessionStarted\n // listeners only fire once.\n return;\n }\n if (method === \"error\") {\n // codex `error` notifications carry the real failure cause (e.g.\n // \"Missing environment variable: COPILOT_API_KEY\", upstream provider\n // failure). Before this branch existed they degraded to {kind:\"raw\"} →\n // normalize-backend-output dropped them silently → swarm coordinator\n // never learned the role had failed → queen kept nudging a dead\n // worker. Promote to cp.emit(\"error\") so session-manager.onError →\n // onSessionError fires.\n const p = (params ?? {}) as {\n error?: { message?: string; codexErrorInfo?: string };\n willRetry?: boolean;\n };\n const message = p.error?.message ?? \"codex emitted unspecified error\";\n log.warn({ sessionId: cp.id, params }, \"codex error notification\");\n cp.emit(\"error\", new Error(`codex: ${message}`));\n // willRetry:false is codex saying \"this turn is dead, no retry\". Kill\n // the process so proc.on(\"exit\") fires → session-manager.onSessionExit\n // → swarmCoordinator.handleRoleCrashed flips the role to crashed and\n // wakes the queen. Leaving it alive would burn an idle process and\n // continue queen nudge loops.\n if (p.willRetry === false) {\n void cp.kill().catch((err) => {\n log.warn({ err, sessionId: cp.id }, \"kill after fatal codex error failed\");\n });\n }\n return;\n }\n if (method === \"thread/status/changed\") {\n // Codex pairs systemError status with an `error` notification that\n // carries willRetry. We forward the status as onError so the swarm\n // sees the failure signal immediately, but defer the kill decision to\n // the paired `error` frame (it has the willRetry bit). Other status\n // transitions (active, idle, running, …) are benign lifecycle events\n // — silently consume them, otherwise mapCodexFrame would degrade them\n // to {kind:\"raw\"} and spam log.warn for every normal turn.\n const p = (params ?? {}) as { status?: { type?: string } };\n if (p.status?.type === \"systemError\") {\n log.warn({ sessionId: cp.id, params }, \"codex thread systemError\");\n cp.emit(\"error\", new Error(\"codex: thread entered systemError\"));\n }\n return;\n }\n if (method === \"turn/completed\" || method === \"thread/turnComplete\" || method === \"turn/complete\") {\n log.info({ sessionId: cp.id, method }, \"codex turn complete\");\n // Token usage is delivered via the separate\n // `thread/tokenUsageUpdated` notification — the `turn` payload here\n // does NOT carry a `usage` field per the v2 schema.\n cp.emit(\"turn_complete\", {\n backendSessionId: cp.backendSessionId,\n });\n return;\n }\n if (method === \"turn/started\") {\n log.info({ sessionId: cp.id }, \"codex turn started\");\n return;\n }\n const out: BackendOutput = mapCodexFrame({ method, params });\n this.logBackendOutput(cp.id, method, out);\n cp.emit(\"output\", out);\n }\n\n /**\n * Selective notification logging. The previous catch-all `log.debug(\"codex\n * notification\")` fired for every streaming `item/agentMessage/delta` chunk\n * (many per turn), drowning the actually useful events. Instead, log only\n * structural events at INFO and surface unrecognised methods as WARN so the\n * `{kind:\"raw\"}` degradation isn't silent.\n */\n private logBackendOutput(sessionId: string, method: string, out: BackendOutput): void {\n // Streaming text deltas — too high-frequency to log per-chunk.\n if (method === \"item/agentMessage/delta\") return;\n // Other token-usage / progress notifications without a structural meaning.\n if (method === \"thread/tokenUsageUpdated\") return;\n\n switch (out.kind) {\n case \"tool_use\":\n log.info(\n { sessionId, callId: out.callId, tool: out.toolName, input: preview(out.input, 120) },\n \"codex tool_use\",\n );\n return;\n case \"tool_result\":\n log.info(\n { sessionId, callId: out.callId, isError: out.isError, output: preview(out.output, 120) },\n \"codex tool_result\",\n );\n return;\n case \"assistant_text\":\n log.debug(\n { sessionId, len: out.text.length, text: preview(out.text, 120) },\n \"codex assistant_text\",\n );\n return;\n case \"raw\":\n log.warn({ sessionId, method, payload: preview(out.payload, 200) }, \"codex unhandled frame\");\n return;\n }\n }\n\n async stop(process: BackendProcess): Promise<void> {\n await process.kill();\n }\n\n send(process: BackendProcess, input: string): void {\n if (!(process instanceof CodexProcess)) {\n log.warn(\n { sessionId: (process as { id?: string })?.id, len: input.length },\n \"codex send: not a CodexProcess — input dropped\",\n );\n return;\n }\n if (!process.rpc) {\n log.warn({ sessionId: process.id, len: input.length }, \"codex send: no rpc — input dropped\");\n return;\n }\n if (!process.backendSessionId) {\n // Handshake still in flight: queue the input and let `handshake()`\n // flush it once `thread/start` resolves. This avoids silent drops when\n // a hub author moves from claude-adapter (no handshake) to codex.\n process.pendingInputs.push(input);\n log.info(\n { sessionId: process.id, queueDepth: process.pendingInputs.length, len: input.length },\n \"codex send: handshake pending, queued\",\n );\n return;\n }\n log.info(\n { sessionId: process.id, threadId: process.backendSessionId, len: input.length },\n \"codex send: dispatching turn/start\",\n );\n this.dispatchTurn(process, input);\n }\n\n private dispatchTurn(process: CodexProcess, input: string): void {\n if (!process.rpc || !process.backendSessionId) return;\n // codex v2: turn/start is a *request* (server returns a result when the\n // turn is queued). We fire-and-forget here because the agent loop reacts\n // to async `turn/completed` / `item/...` notifications, not to the\n // request's result envelope.\n void process.rpc\n .request(\"turn/start\", {\n threadId: process.backendSessionId,\n input: [{ type: \"text\", text: input }],\n })\n .then(() => {\n log.info(\n { sessionId: process.id, threadId: process.backendSessionId },\n \"codex turn/start: accepted by server\",\n );\n })\n .catch((err: Error) => {\n log.warn({ err, sessionId: process.id }, \"turn/start failed\");\n process.emit(\"error\", err);\n });\n }\n\n onOutput(process: BackendProcess, handler: (msg: unknown) => void): void {\n if (process instanceof CodexProcess) process.on(\"output\", handler);\n }\n\n onPermissionRequest(\n process: BackendProcess,\n handler: (req: PermissionRequest) => void,\n ): void {\n if (process instanceof CodexProcess) process.on(\"permission_request\", handler);\n }\n\n async respondToPermission(\n process: BackendProcess,\n decision: PermissionDecision,\n ): Promise<void> {\n if (!(process instanceof CodexProcess)) return;\n const key = process.pendingApprovals.get(decision.callId);\n if (key === undefined) {\n log.warn({ callId: decision.callId }, \"respondToPermission: no pending approval\");\n return;\n }\n const family = process.approvalMethods.get(decision.callId) ?? \"legacy\";\n const resolver = process.approvalResolvers.get(key);\n process.pendingApprovals.delete(decision.callId);\n process.approvalMethods.delete(decision.callId);\n process.approvalResolvers.delete(key);\n const reply = buildApprovalReply(family, decision.decision);\n resolver?.(reply);\n }\n\n onTurnComplete(\n process: BackendProcess,\n handler: (info: { backendSessionId?: string }) => void,\n ): void {\n if (process instanceof CodexProcess) process.on(\"turn_complete\", handler);\n }\n\n onSessionStarted(\n process: BackendProcess,\n handler: (info: { backendSessionId: string }) => void,\n ): void {\n if (process instanceof CodexProcess) process.on(\"session_started\", handler);\n }\n\n onError(process: BackendProcess, handler: (err: Error) => void): void {\n if (process instanceof CodexProcess) process.on(\"error\", handler);\n }\n\n onExit(process: BackendProcess, handler: (code: number | null) => void): void {\n if (process instanceof CodexProcess) process.on(\"exit\", handler);\n }\n}\n","/**\n * codex-spawn-args — construct CLI args for `codex app-server` with\n * per-spawn MCP server + briefing injection.\n *\n * Extracted from CodexAdapter.spawn() so it can be unit-tested without\n * spawning a real child process.\n */\nimport { writeFileSync, unlinkSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { tmpdir } from \"node:os\";\nimport { randomUUID } from \"node:crypto\";\nimport { DEFAULT_SANDBOX, type SandboxLevel } from \"@mclawnet/shared\";\n\nexport interface McpServerConfig {\n command: string;\n args?: string[];\n env?: Record<string, string>;\n}\n\nexport interface CodexSpawnArgsOptions {\n sessionId: string;\n resumeId?: string;\n systemPrompt?: string;\n mcpServer?: McpServerConfig;\n /**\n * Per-role sandbox level. Maps to codex's `sandbox_mode` config key:\n * - \"read-only\" → `read-only`\n * - \"workspace-write\" → `workspace-write` (default)\n * - \"full-access\" → `danger-full-access` (codex's internal name; we\n * expose the friendlier label upstream)\n * Undefined falls back to \"workspace-write\" so existing callers see no\n * behavior change.\n */\n sandbox?: SandboxLevel;\n}\n\nexport interface CodexSpawnArgsResult {\n args: string[];\n briefingFile?: string;\n}\n\nfunction escapeToml(value: string): string {\n return value.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\nexport function buildCodexSpawnArgs(options: CodexSpawnArgsOptions): CodexSpawnArgsResult {\n const args: string[] = [\"app-server\"];\n let briefingFile: string | undefined;\n\n // NOTE: `--resume <id>` is NOT a valid `codex app-server` flag. It only\n // exists on `codex` interactive / `codex exec`. Passing it to app-server\n // makes the CLI exit with \"error: unexpected argument '--resume' found\",\n // and the calling spawn() doesn't notice the immediate exit, so all\n // JSON-RPC traffic hangs. Resume is implemented at the protocol layer\n // by sending `thread/resume { threadId }` from CodexAdapter.handshake()\n // when CodexProcess.resumeId is set. `options.resumeId` is kept on the\n // CodexProcess for the handshake to read; we do NOT add it to args.\n void options.resumeId;\n\n // Non-interactive runtime policy: swarm roles run unattended, so MCP tool\n // calls must not be gated on a user-facing approval prompt. Without\n // `approval_policy=\"never\"`, codex defaults to `on-request` and rejects\n // every MCP tool call with \"user rejected MCP tool call\" because there's\n // no elicitation handler wired on the client side. `workspace-write`\n // matches the role's workDir as the writable root (analogous to claude-\n // adapter's `--permission-mode bypassPermissions` + workspace boundary).\n args.push(\"-c\", 'approval_policy=\"never\"');\n // Map ClawNet's abstract sandbox level to codex's mode name. We expose\n // \"full-access\" to users for readability; codex's internal mode is\n // named \"danger-full-access\". Default (undefined) → DEFAULT_SANDBOX\n // from @mclawnet/shared so existing swarms keep current behavior.\n const sandboxLevel: SandboxLevel = options.sandbox ?? DEFAULT_SANDBOX;\n const codexSandboxMode =\n sandboxLevel === \"read-only\"\n ? \"read-only\"\n : sandboxLevel === \"full-access\"\n ? \"danger-full-access\"\n : \"workspace-write\";\n args.push(\"-c\", `sandbox_mode=\"${codexSandboxMode}\"`);\n\n // Layer 1: MCP server injection via -c flags\n if (options.mcpServer) {\n const { command, args: serverArgs, env } = options.mcpServer;\n args.push(\"-c\", `mcp_servers.clawnet-mcp.command=\"${escapeToml(command)}\"`);\n if (serverArgs && serverArgs.length > 0) {\n const argsToml = \"[\" + serverArgs.map((a) => `\"${escapeToml(a)}\"`).join(\", \") + \"]\";\n args.push(\"-c\", `mcp_servers.clawnet-mcp.args=${argsToml}`);\n }\n if (env) {\n for (const [key, value] of Object.entries(env)) {\n args.push(\"-c\", `mcp_servers.clawnet-mcp.env.${key}=\"${escapeToml(value)}\"`);\n }\n }\n // CRITICAL: per-server tool approval mode. Without this codex still\n // elicits each MCP tool call (even with global approval_policy=\"never\"\n // which only covers shell exec). The elicitation has no client-side\n // handler, so every MCP tool call returns \"user rejected MCP tool call\"\n // in 0s. \"approve\" silently approves all tool calls — required for\n // unattended swarm-role execution. (Valid values are \"prompt\" and\n // \"approve\"; \"auto\" is NOT accepted by codex 0.134.)\n args.push(\"-c\", 'mcp_servers.clawnet-mcp.default_tools_approval_mode=\"approve\"');\n }\n\n // Layer 2: Briefing injection via temp file + model_instructions_file\n if (options.systemPrompt) {\n // Sanitize sessionId for use in a filename: swarm role sessionIds look like\n // \"<swarmId>::<instanceId>\" (e.g. \"abc123::dev-0\"). Windows forbids `:`\n // (and `\\\\/*?\"<>|`, control chars 0x00-0x1F, plus trailing `.`/space) in\n // filenames, so writeFileSync blows up with ENOENT and the entire codex\n // role fails to spawn. Replace all illegal chars with `_` — the file is\n // throwaway, only the .md suffix matters.\n const safeId = options.sessionId\n // eslint-disable-next-line no-control-regex\n .replace(/[\\\\/:*?\"<>|\\x00-\\x1F]/g, \"_\")\n .replace(/[. ]+$/g, \"_\");\n briefingFile = join(tmpdir(), `clawnet-briefing-${safeId}-${randomUUID().slice(0, 8)}.md`);\n writeFileSync(briefingFile, options.systemPrompt, { encoding: \"utf-8\", mode: 0o600 });\n args.push(\"-c\", `model_instructions_file=\"${escapeToml(briefingFile)}\"`);\n }\n\n return { args, briefingFile };\n}\n\nexport function cleanupBriefingFile(filePath: string): void {\n try {\n unlinkSync(filePath);\n } catch {\n // ignore — file may already be gone\n }\n}\n","import type { Writable, Readable } from \"node:stream\";\n\nexport interface JsonRpcClientOptions {\n stdin: Writable;\n stdout: Readable;\n onRequest?: (method: string, params: unknown) => Promise<unknown> | unknown;\n onNotification?: (method: string, params: unknown) => void;\n onMalformedLine?: (line: string, err: Error) => void;\n}\n\ninterface JsonRpcPending {\n resolve: (v: unknown) => void;\n reject: (e: Error) => void;\n}\n\n/**\n * Minimal JSON-RPC 2.0 client over NDJSON stdio.\n *\n * Half of the duplex: client-initiated `request()` returns a Promise tied to\n * the response by id. Server-initiated requests (codex approval callbacks)\n * are dispatched to `onRequest` and the resolved value is written back as a\n * `result` envelope.\n */\nexport class JsonRpcClient {\n private stdin: Writable;\n private buffer = \"\";\n private nextId = 1;\n private pending = new Map<number, JsonRpcPending>();\n private onRequest?: JsonRpcClientOptions[\"onRequest\"];\n private onNotification?: JsonRpcClientOptions[\"onNotification\"];\n private onMalformedLine?: JsonRpcClientOptions[\"onMalformedLine\"];\n\n constructor(opts: JsonRpcClientOptions) {\n this.stdin = opts.stdin;\n this.onRequest = opts.onRequest;\n this.onNotification = opts.onNotification;\n this.onMalformedLine = opts.onMalformedLine;\n opts.stdout.on(\"data\", (chunk: Buffer) => this.feed(chunk.toString(\"utf-8\")));\n // Without this listener, an EPIPE on stdin (codex dies mid-handshake,\n // user closes the pipe, OS sends SIGPIPE) bubbles as an unhandled\n // 'error' event and crashes the host process. We surface it as a\n // structured rejection on every in-flight request instead.\n this.stdin.on(\"error\", (err) => this.failAllPending(err));\n }\n\n /**\n * Reject every in-flight request with the given error. Called when stdin\n * dies so callers get a clean rejection instead of hanging until the\n * handshake death-poll catches up.\n */\n private failAllPending(err: Error): void {\n for (const [, p] of this.pending) {\n try { p.reject(err); } catch { /* ignore listener throw */ }\n }\n this.pending.clear();\n }\n\n request(method: string, params: unknown): Promise<unknown> {\n const id = this.nextId++;\n const frame = { jsonrpc: \"2.0\", id, method, params };\n return new Promise((resolve, reject) => {\n this.pending.set(id, { resolve, reject });\n // Pass an error callback so a write failure (EPIPE on dead child)\n // rejects this specific request instead of triggering an unhandled\n // 'error' on the stream. The stdin 'error' handler above is the\n // backstop for failures that arrive out-of-band of any write.\n this.stdin.write(JSON.stringify(frame) + \"\\n\", (err) => {\n if (err) {\n this.pending.delete(id);\n reject(err);\n }\n });\n });\n }\n\n notify(method: string, params: unknown): void {\n // Same swallow-rather-than-crash policy for notifications. There's no\n // pending promise to reject; the caller fired-and-forgot.\n this.stdin.write(JSON.stringify({ jsonrpc: \"2.0\", method, params }) + \"\\n\", () => {\n /* errors absorbed by the 'error' handler in the constructor */\n });\n }\n\n private feed(s: string) {\n this.buffer += s;\n let nl: number;\n while ((nl = this.buffer.indexOf(\"\\n\")) >= 0) {\n const line = this.buffer.slice(0, nl).trim();\n this.buffer = this.buffer.slice(nl + 1);\n if (!line) continue;\n this.dispatch(line);\n }\n }\n\n private dispatch(line: string) {\n let msg: {\n id?: number;\n method?: string;\n params?: unknown;\n result?: unknown;\n error?: { code: number; message: string };\n };\n try {\n msg = JSON.parse(line);\n } catch (err) {\n this.onMalformedLine?.(line, err as Error);\n return;\n }\n if (typeof msg.id === \"number\" && (msg.result !== undefined || msg.error !== undefined)) {\n const pending = this.pending.get(msg.id);\n if (!pending) return;\n this.pending.delete(msg.id);\n if (msg.error) pending.reject(new Error(msg.error.message));\n else pending.resolve(msg.result);\n return;\n }\n if (msg.method && typeof msg.id === \"number\") {\n // server-initiated request\n const id = msg.id;\n const method = msg.method;\n const params = msg.params;\n void Promise.resolve(this.onRequest?.(method, params))\n .then((result) => {\n this.stdin.write(JSON.stringify({ jsonrpc: \"2.0\", id, result }) + \"\\n\");\n })\n .catch((err: Error) => {\n this.stdin.write(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n error: { code: -32000, message: err.message },\n }) + \"\\n\",\n );\n });\n return;\n }\n if (msg.method) {\n this.onNotification?.(msg.method, msg.params);\n }\n }\n}\n","import type { PermissionDecision, PermissionRequest } from \"@mclawnet/agent\";\n\n/**\n * Three coexisting decision-wire families codex app-server speaks:\n * - \"legacy\" → ReviewDecision (approved/approved_for_session/denied/abort)\n * - \"v2\" → CommandExecutionApprovalDecision / FileChangeApprovalDecision\n * (accept/acceptForSession/decline/cancel)\n * - \"mcp\" → McpServerElicitationAction\n * ({ action: \"accept\" | \"decline\" | \"cancel\" })\n *\n * `parseApprovalRequest` returns the family so `respondToPermission` can pick\n * the right wire without re-deriving it from a brittle method-name prefix.\n */\nexport type ApprovalWireFamily = \"legacy\" | \"v2\" | \"mcp\";\n\nexport type ReviewDecisionWire =\n | \"approved\"\n | \"approved_for_session\"\n | \"denied\"\n | \"abort\";\n\nexport function decisionToWire(d: PermissionDecision[\"decision\"]): ReviewDecisionWire {\n switch (d) {\n case \"allow\":\n return \"approved\";\n case \"allow_session\":\n return \"approved_for_session\";\n case \"deny\":\n return \"denied\";\n case \"abort\":\n return \"abort\";\n default: {\n const _exhaustive: never = d;\n return _exhaustive;\n }\n }\n}\n\n/**\n * v2 CommandExecutionApprovalDecision / FileChangeApprovalDecision wire enum.\n * Used by codex app-server >= 0.134 for `item/.../requestApproval` flows.\n */\nexport type V2DecisionWire = \"accept\" | \"acceptForSession\" | \"decline\" | \"cancel\";\n\nexport function decisionToV2Wire(d: PermissionDecision[\"decision\"]): V2DecisionWire {\n switch (d) {\n case \"allow\":\n return \"accept\";\n case \"allow_session\":\n return \"acceptForSession\";\n case \"deny\":\n return \"decline\";\n case \"abort\":\n return \"cancel\";\n default: {\n const _exhaustive: never = d;\n return _exhaustive;\n }\n }\n}\n\n/**\n * MCP elicitation action enum (RMCP CreateElicitationResult). Note: \"session\"\n * scope isn't part of the MCP spec — `allow_session` degrades to \"accept\".\n */\nexport type McpElicitationAction = \"accept\" | \"decline\" | \"cancel\";\n\nexport function decisionToMcpAction(d: PermissionDecision[\"decision\"]): McpElicitationAction {\n switch (d) {\n case \"allow\":\n case \"allow_session\":\n return \"accept\";\n case \"deny\":\n return \"decline\";\n case \"abort\":\n return \"cancel\";\n default: {\n const _exhaustive: never = d;\n return _exhaustive;\n }\n }\n}\n\n/** @deprecated kept only for back-compat with M3.S5 test seam; prefer the\n * wire family returned by `parseApprovalRequest`. */\nexport function isV2ApprovalMethod(method: string): boolean {\n return method.startsWith(\"item/\");\n}\n\n/**\n * Build the wire-shaped reply body for a given decision + family.\n * - legacy → `{ decision: \"approved\" | ... }`\n * - v2 → `{ decision: \"accept\" | ... }`\n * - mcp → `{ action: \"accept\" | ... }`\n */\nexport function buildApprovalReply(\n family: ApprovalWireFamily,\n decision: PermissionDecision[\"decision\"],\n): Record<string, string> {\n switch (family) {\n case \"legacy\":\n return { decision: decisionToWire(decision) };\n case \"v2\":\n return { decision: decisionToV2Wire(decision) };\n case \"mcp\":\n return { action: decisionToMcpAction(decision) };\n default: {\n const _exhaustive: never = family;\n return _exhaustive;\n }\n }\n}\n\nexport interface ParsedApprovalRequest {\n req: PermissionRequest;\n wireFamily: ApprovalWireFamily;\n}\n\n/**\n * Map a codex JSON-RPC approval request to our backend-neutral\n * PermissionRequest. Covers both legacy (`execCommandApproval`,\n * `applyPatchApproval`) and v2 (`item/commandExecution/requestApproval`,\n * `item/fileChange/requestApproval`) shapes, plus MCP elicitation.\n *\n * Returns null when the method is not a recognized approval channel — the\n * adapter forwards such frames as raw output instead.\n */\nexport function parseApprovalRequest(\n method: string,\n params: unknown,\n): ParsedApprovalRequest | null {\n const p = (params ?? {}) as Record<string, unknown>;\n const callId = (p.callId as string | undefined) ?? (p.itemId as string | undefined);\n if (!callId) return null;\n const reason = p.reason as string | undefined;\n const cwd = p.cwd as string | undefined;\n\n if (method === \"execCommandApproval\") {\n return {\n req: {\n callId,\n toolName: \"shell\",\n input: { command: p.command, cwd },\n meta: { backend: \"codex\", reason, cwd },\n },\n wireFamily: \"legacy\",\n };\n }\n if (method === \"item/commandExecution/requestApproval\") {\n return {\n req: {\n callId,\n toolName: \"shell\",\n input: { command: p.command, cwd },\n meta: { backend: \"codex\", reason, cwd },\n },\n wireFamily: \"v2\",\n };\n }\n if (method === \"applyPatchApproval\") {\n return {\n req: {\n callId,\n toolName: \"apply_patch\",\n input: { fileChanges: p.fileChanges },\n meta: { backend: \"codex\", reason, cwd },\n },\n wireFamily: \"legacy\",\n };\n }\n if (method === \"item/fileChange/requestApproval\") {\n return {\n req: {\n callId,\n toolName: \"apply_patch\",\n input: { fileChanges: p.fileChanges },\n meta: { backend: \"codex\", reason, cwd },\n },\n wireFamily: \"v2\",\n };\n }\n if (method === \"mcpServer/elicitation/request\") {\n return {\n req: {\n callId,\n toolName: (p.serverName as string | undefined) ?? \"mcp\",\n input: { message: p.message, meta: p._meta },\n meta: { backend: \"codex\", reason },\n },\n wireFamily: \"mcp\",\n };\n }\n return null;\n}\n","import type { BackendOutput } from \"@mclawnet/agent\";\n\n/**\n * Map a single codex JSON-RPC notification frame to a backend-neutral\n * BackendOutput envelope. Unknown methods degrade to `{ kind: \"raw\" }` so\n * the agent main loop can still see them (e.g. for debug logging) without\n * the adapter pretending to understand every codex frame.\n *\n * Covers both v2 (`item/agentMessage/delta`, `item/started`, `item/completed`)\n * and legacy (`thread/message`, `thread/toolUse`) frame names.\n */\nexport function mapCodexFrame(frame: {\n method: string;\n params?: unknown;\n}): BackendOutput {\n const params = (frame.params ?? {}) as Record<string, unknown>;\n switch (frame.method) {\n // ── v2 frames (real codex app-server v2 protocol) ─────────────────\n case \"item/agentMessage/delta\": {\n const delta = params.delta;\n if (typeof delta === \"string\") {\n return { kind: \"assistant_text\", text: delta };\n }\n break;\n }\n case \"item/completed\": {\n const item = params.item as\n | {\n type?: string;\n text?: string;\n id?: string;\n // commandExecution\n command?: string;\n aggregatedOutput?: string | null;\n exitCode?: number | null;\n status?: string;\n // fileChange\n changes?: unknown;\n // mcpToolCall\n server?: string;\n tool?: string;\n arguments?: unknown;\n result?: unknown;\n error?: unknown;\n }\n | undefined;\n if (item?.type === \"agentMessage\" && typeof item.text === \"string\") {\n return { kind: \"assistant_text\", text: item.text };\n }\n if (item?.type === \"commandExecution\") {\n // CommandExecutionStatus = \"inProgress\" | \"completed\" | \"failed\" | \"declined\"\n const failed = item.status === \"failed\" || item.status === \"declined\";\n const badExit = typeof item.exitCode === \"number\" && item.exitCode !== 0;\n return {\n kind: \"tool_result\",\n callId: String(item.id ?? \"\"),\n output: item.aggregatedOutput ?? null,\n isError: failed || badExit,\n };\n }\n if (item?.type === \"fileChange\") {\n // PatchApplyStatus shares the CommandExecutionStatus enum shape.\n const failed = item.status === \"failed\" || item.status === \"declined\";\n return {\n kind: \"tool_result\",\n callId: String(item.id ?? \"\"),\n output: { changes: item.changes },\n isError: failed,\n };\n }\n if (item?.type === \"mcpToolCall\") {\n // McpToolCallStatus = \"inProgress\" | \"completed\" | \"failed\"\n const failed = item.status === \"failed\" || item.error != null;\n return {\n kind: \"tool_result\",\n callId: String(item.id ?? \"\"),\n output: failed ? item.error : item.result,\n isError: failed,\n };\n }\n break;\n }\n case \"item/started\": {\n const item = params.item as\n | { type?: string; id?: string; command?: string; name?: string; input?: unknown }\n | undefined;\n if (item?.type === \"commandExecution\") {\n return {\n kind: \"tool_use\",\n callId: String(item.id ?? \"\"),\n toolName: \"shell\",\n input: { command: item.command },\n };\n }\n if (item?.type === \"mcpToolCall\") {\n return {\n kind: \"tool_use\",\n callId: String(item.id ?? \"\"),\n toolName: String(item.name ?? \"mcp\"),\n input: item.input,\n };\n }\n break;\n }\n\n // ── legacy frame names (kept for back-compat with older codex / tests) ──\n case \"thread/message\": {\n const role = params.role as string | undefined;\n const content = params.content as Array<{ type: string; text?: string }> | undefined;\n if (role === \"assistant\" && content) {\n const text = content\n .filter((c) => c.type === \"text\" && typeof c.text === \"string\")\n .map((c) => c.text!)\n .join(\"\");\n return { kind: \"assistant_text\", text };\n }\n break;\n }\n case \"thread/toolUse\":\n return {\n kind: \"tool_use\",\n callId: String(params.callId ?? \"\"),\n toolName: String(params.name ?? \"\"),\n input: params.input,\n };\n case \"thread/toolResult\":\n return {\n kind: \"tool_result\",\n callId: String(params.callId ?? \"\"),\n output: params.output,\n isError: Boolean(params.isError),\n };\n }\n return { kind: \"raw\", backend: \"codex\", payload: frame };\n}\n"],"mappings":";AAAA,SAAS,UAAU,aAAgC;AACnD,SAAS,oBAAoB;AAC7B,SAAS,YAAY,oBAAoB;AACzC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,gBAAgB;AAClC,SAAS,SAAS,QAAAA,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AAS,MAAM;AAC9C,IAAAA,SAAQ,kBAAkB,OAAO,GAAG;AACpC,UAAM,QAAQ,mBAAmB,QAAQ,SAAS,QAAQ;AAC1D,eAAW,KAAK;EAClB;EAEA,eACEA,UACA,SAAsD;AAEtD,QAAIA,oBAAmB;AAAc,MAAAA,SAAQ,GAAG,iBAAiB,OAAO;EAC1E;EAEA,iBACEA,UACA,SAAqD;AAErD,QAAIA,oBAAmB;AAAc,MAAAA,SAAQ,GAAG,mBAAmB,OAAO;EAC5E;EAEA,QAAQA,UAAyB,SAA6B;AAC5D,QAAIA,oBAAmB;AAAc,MAAAA,SAAQ,GAAG,SAAS,OAAO;EAClE;EAEA,OAAOA,UAAyB,SAAsC;AACpE,QAAIA,oBAAmB;AAAc,MAAAA,SAAQ,GAAG,QAAQ,OAAO;EACjE;;","names":["join","join","join","cp","require","process"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|