negotium 0.18.2 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/bin/codex-sdk-window-hide.mjs +40 -0
  2. package/bin/negotium.mjs +4 -0
  3. package/dist/agent-helpers.js +522 -211
  4. package/dist/agent-helpers.js.map +9 -8
  5. package/dist/canonical-mcp-bridge.js +3 -2
  6. package/dist/canonical-mcp-bridge.js.map +1 -1
  7. package/dist/chunk-22mtr8np.js +200 -0
  8. package/dist/chunk-22mtr8np.js.map +9 -0
  9. package/dist/chunk-2mx7fq49.js +6 -0
  10. package/dist/chunk-2mx7fq49.js.map +9 -0
  11. package/dist/{chunk-r0xs3t81.js → chunk-f7p0h1gs.js} +2 -4
  12. package/dist/{chunk-r0xs3t81.js.map → chunk-f7p0h1gs.js.map} +2 -2
  13. package/dist/{chunk-44ajn328.js → chunk-m7qc729a.js} +2 -2
  14. package/dist/chunk-m7qc729a.js.map +12 -0
  15. package/dist/chunk-y8rtedjb.js +374 -0
  16. package/dist/chunk-y8rtedjb.js.map +13 -0
  17. package/dist/hosted-agent.js +355 -476
  18. package/dist/hosted-agent.js.map +7 -10
  19. package/dist/main.js +861 -537
  20. package/dist/main.js.map +11 -10
  21. package/dist/mcp-factories.js +546 -242
  22. package/dist/mcp-factories.js.map +9 -8
  23. package/dist/query-runtime.js +56 -6
  24. package/dist/query-runtime.js.map +6 -4
  25. package/dist/registry.js +1 -1
  26. package/dist/runtime/src/agents/codex-native-multi-agent.ts +45 -3
  27. package/dist/runtime/src/agents/codex-vault-hook-bridge.ts +36 -23
  28. package/dist/runtime/src/agents/codex-windows-wrapper.ts +174 -0
  29. package/dist/runtime/src/agents/mcp-tools/spawn-subagent.ts +24 -4
  30. package/dist/runtime/src/prompts/sessions/_shared-tools.md +19 -0
  31. package/dist/runtime/src/query/state.ts +19 -1
  32. package/dist/runtime/src/version.ts +1 -1
  33. package/dist/types/packages/core/src/agents/codex-windows-wrapper.d.ts +30 -0
  34. package/dist/types/packages/core/src/query/state.d.ts +8 -0
  35. package/dist/types/packages/core/src/version.d.ts +1 -1
  36. package/package.json +1 -1
  37. package/dist/chunk-44ajn328.js.map +0 -12
@@ -3,11 +3,12 @@ import {
3
3
  canonicalMcpBridgeEnv,
4
4
  registerCanonicalMcpBridgeEnvProvider,
5
5
  revokeCanonicalMcpBridgeTurn
6
- } from "./chunk-r0xs3t81.js";
6
+ } from "./chunk-f7p0h1gs.js";
7
+ import"./chunk-2mx7fq49.js";
7
8
  export {
8
9
  revokeCanonicalMcpBridgeTurn,
9
10
  registerCanonicalMcpBridgeEnvProvider,
10
11
  canonicalMcpBridgeEnv
11
12
  };
12
13
 
13
- //# debugId=80784E7A72C3AC2064756E2164756E21
14
+ //# debugId=C5FA8F0580D154DB64756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "80784E7A72C3AC2064756E2164756E21",
7
+ "debugId": "C5FA8F0580D154DB64756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -0,0 +1,200 @@
1
+ // @bun
2
+ import {
3
+ ACTIVE_QUERY_STALE_MS,
4
+ AGENTS_PROMPTS_DIR,
5
+ AGENT_HEALTH_SERVER,
6
+ BASHRS_SPILL_ROOT,
7
+ BASH_RS_BIN,
8
+ BASH_RS_VERSION,
9
+ BG_BASH_BASE_PORT,
10
+ BG_BASH_MAX_PORT,
11
+ BINARIES_DIR,
12
+ BINARY_EXTENSION,
13
+ BROWSER_DIR,
14
+ BROWSER_PROFILES_DIR,
15
+ BROWSER_RS_BIN,
16
+ BROWSER_RS_MIN_SECURE_VERSION,
17
+ BROWSER_RS_VERSION,
18
+ CANONICAL_MCP_PROXY_SERVER,
19
+ CLAUDE_EXECUTABLE,
20
+ COMPACTION_LOG_SERVER,
21
+ CRON_WORKSPACE_DIR,
22
+ DATA_DIR,
23
+ DEBUG_FILE,
24
+ DECISION_SERVER,
25
+ DEFAULT_OUTPUT_LANGUAGE,
26
+ DEFAULT_TOPIC_EFFORT,
27
+ DM_CMD_DIR,
28
+ DM_RESP_DIR,
29
+ DM_WORKSPACE_DIR,
30
+ FALLBACK_AGENT,
31
+ FALLBACK_MODEL,
32
+ FASTER_WHISPER_WRAPPER,
33
+ FFMPEG_BIN,
34
+ FFPROBE_BIN,
35
+ FILE_EXTENSIONS_REGEX,
36
+ FILE_TAG_REGEX,
37
+ LOG_DIR,
38
+ MAX_TELL_DEPTH,
39
+ MLX_WHISPER_BIN,
40
+ MODEL_DEEPSEEK_V4_FLASH,
41
+ MODEL_DEEPSEEK_V4_PRO,
42
+ MODEL_FABLE,
43
+ MODEL_HAIKU,
44
+ MODEL_OPUS,
45
+ MODEL_SONNET,
46
+ NEGOTIUM_PORT,
47
+ NODE_CONTROL_TOKEN,
48
+ NODE_ID,
49
+ PDFTOTEXT_BIN,
50
+ PLAYWRIGHT_BASE_PORT,
51
+ PLAYWRIGHT_MAX_PORT,
52
+ PLAYWRIGHT_MCP_BIN,
53
+ PLAYWRIGHT_PORTS_DIR,
54
+ PROGRESS_DIR,
55
+ PROJECT_ROOT,
56
+ PYTHON_BIN,
57
+ RESOURCES_DIR,
58
+ RUNTIME_DIR,
59
+ RUNTIME_MCP_SECRET,
60
+ RUN_DIR,
61
+ SECRETS_DIR,
62
+ SESSIONS_DB,
63
+ SESSION_ASKS_DIR,
64
+ SESSION_COMM_SERVER,
65
+ SESSION_INBOX_DIR,
66
+ SESSION_WORKSPACE_DIR,
67
+ SHARED_WIKI_DIR,
68
+ SNIPPETS_API_URL,
69
+ STATE_DIR,
70
+ SYSTEM_HEALTH_SERVER,
71
+ TASK_SERVER,
72
+ TESSERACT_BIN,
73
+ TOKEN_STATS_SERVER,
74
+ TOPIC_WORKSPACE_DIR,
75
+ TSCONFIG_PATH,
76
+ TSX_BIN,
77
+ TSX_LOADER,
78
+ UPLOADS_DIR,
79
+ USERS_LOG_DIR,
80
+ VAULT_DIR,
81
+ VAULT_MASTER_KEY,
82
+ VAULT_SERVER,
83
+ WHISPER_BACKEND,
84
+ WHISPER_MODEL,
85
+ WHISPER_MODEL_MLX,
86
+ WIKI_SERVER,
87
+ WORKSPACE_DIR,
88
+ codexAuthFilePath,
89
+ envText,
90
+ getCleanEnv,
91
+ hostname,
92
+ isProductionEnv,
93
+ resolveBashRsBin,
94
+ resolveBrowserMcpBin,
95
+ resolveBrowserProxy,
96
+ resolveBrowserRsBin,
97
+ resolveOutputLanguage,
98
+ resolveTopicWorkspaceDir
99
+ } from "./chunk-y8rtedjb.js";
100
+ import"./chunk-2mx7fq49.js";
101
+ export {
102
+ resolveTopicWorkspaceDir,
103
+ resolveOutputLanguage,
104
+ resolveBrowserRsBin,
105
+ resolveBrowserProxy,
106
+ resolveBrowserMcpBin,
107
+ resolveBashRsBin,
108
+ isProductionEnv,
109
+ hostname,
110
+ getCleanEnv,
111
+ envText,
112
+ codexAuthFilePath,
113
+ WORKSPACE_DIR,
114
+ WIKI_SERVER,
115
+ WHISPER_MODEL_MLX,
116
+ WHISPER_MODEL,
117
+ WHISPER_BACKEND,
118
+ VAULT_SERVER,
119
+ VAULT_MASTER_KEY,
120
+ VAULT_DIR,
121
+ USERS_LOG_DIR,
122
+ UPLOADS_DIR,
123
+ TSX_LOADER,
124
+ TSX_BIN,
125
+ TSCONFIG_PATH,
126
+ TOPIC_WORKSPACE_DIR,
127
+ TOKEN_STATS_SERVER,
128
+ TESSERACT_BIN,
129
+ TASK_SERVER,
130
+ SYSTEM_HEALTH_SERVER,
131
+ STATE_DIR,
132
+ SNIPPETS_API_URL,
133
+ SHARED_WIKI_DIR,
134
+ SESSION_WORKSPACE_DIR,
135
+ SESSION_INBOX_DIR,
136
+ SESSION_COMM_SERVER,
137
+ SESSION_ASKS_DIR,
138
+ SESSIONS_DB,
139
+ SECRETS_DIR,
140
+ RUN_DIR,
141
+ RUNTIME_MCP_SECRET,
142
+ RUNTIME_DIR,
143
+ RESOURCES_DIR,
144
+ PYTHON_BIN,
145
+ PROJECT_ROOT,
146
+ PROGRESS_DIR,
147
+ PLAYWRIGHT_PORTS_DIR,
148
+ PLAYWRIGHT_MCP_BIN,
149
+ PLAYWRIGHT_MAX_PORT,
150
+ PLAYWRIGHT_BASE_PORT,
151
+ PDFTOTEXT_BIN,
152
+ NODE_ID,
153
+ NODE_CONTROL_TOKEN,
154
+ NEGOTIUM_PORT,
155
+ MODEL_SONNET,
156
+ MODEL_OPUS,
157
+ MODEL_HAIKU,
158
+ MODEL_FABLE,
159
+ MODEL_DEEPSEEK_V4_PRO,
160
+ MODEL_DEEPSEEK_V4_FLASH,
161
+ MLX_WHISPER_BIN,
162
+ MAX_TELL_DEPTH,
163
+ LOG_DIR,
164
+ FILE_TAG_REGEX,
165
+ FILE_EXTENSIONS_REGEX,
166
+ FFPROBE_BIN,
167
+ FFMPEG_BIN,
168
+ FASTER_WHISPER_WRAPPER,
169
+ FALLBACK_MODEL,
170
+ FALLBACK_AGENT,
171
+ DM_WORKSPACE_DIR,
172
+ DM_RESP_DIR,
173
+ DM_CMD_DIR,
174
+ DEFAULT_TOPIC_EFFORT,
175
+ DEFAULT_OUTPUT_LANGUAGE,
176
+ DECISION_SERVER,
177
+ DEBUG_FILE,
178
+ DATA_DIR,
179
+ CRON_WORKSPACE_DIR,
180
+ COMPACTION_LOG_SERVER,
181
+ CLAUDE_EXECUTABLE,
182
+ CANONICAL_MCP_PROXY_SERVER,
183
+ BROWSER_RS_VERSION,
184
+ BROWSER_RS_MIN_SECURE_VERSION,
185
+ BROWSER_RS_BIN,
186
+ BROWSER_PROFILES_DIR,
187
+ BROWSER_DIR,
188
+ BINARY_EXTENSION,
189
+ BINARIES_DIR,
190
+ BG_BASH_MAX_PORT,
191
+ BG_BASH_BASE_PORT,
192
+ BASH_RS_VERSION,
193
+ BASH_RS_BIN,
194
+ BASHRS_SPILL_ROOT,
195
+ AGENT_HEALTH_SERVER,
196
+ AGENTS_PROMPTS_DIR,
197
+ ACTIVE_QUERY_STALE_MS
198
+ };
199
+
200
+ //# debugId=5CB107C13A2F117D64756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "5CB107C13A2F117D64756E2164756E21",
8
+ "names": []
9
+ }
@@ -0,0 +1,6 @@
1
+ // @bun
2
+ var __require = import.meta.require;
3
+
4
+ export { __require };
5
+
6
+ //# debugId=F2113E8A5115C63264756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "F2113E8A5115C63264756E2164756E21",
8
+ "names": []
9
+ }
@@ -1,6 +1,4 @@
1
1
  // @bun
2
- var __require = import.meta.require;
3
-
4
2
  // ../../packages/core/src/mcp/canonical-bridge-config.ts
5
3
  var registrations = [];
6
4
  var turnLeases = new Map;
@@ -51,6 +49,6 @@ function revokeCanonicalMcpBridgeTurn(scope) {
51
49
  return leases.size;
52
50
  }
53
51
 
54
- export { __require, registerCanonicalMcpBridgeEnvProvider, canonicalMcpBridgeEnv, revokeCanonicalMcpBridgeTurn };
52
+ export { registerCanonicalMcpBridgeEnvProvider, canonicalMcpBridgeEnv, revokeCanonicalMcpBridgeTurn };
55
53
 
56
- //# debugId=FD5EF234163D263564756E2164756E21
54
+ //# debugId=7358D06F0893D4D064756E2164756E21
@@ -4,7 +4,7 @@
4
4
  "sourcesContent": [
5
5
  "import type { PeerRuntimeBridgeContext } from \"#types\";\n\nexport type CanonicalMcpSurface = \"task\" | \"decision\" | \"wiki\";\n\nexport interface CanonicalMcpBridgeScope {\n surface: CanonicalMcpSurface;\n userId: string;\n topicId: string;\n queryId: string;\n peerBridge: PeerRuntimeBridgeContext;\n}\n\nexport interface CanonicalMcpBridgeEnvLease {\n env: Record<string, string>;\n /** Revoke the capability immediately. Must be safe to call more than once. */\n revoke(): void;\n}\n\nexport type CanonicalMcpBridgeEnvProvider = (\n scope: CanonicalMcpBridgeScope,\n) => CanonicalMcpBridgeEnvLease | undefined;\n\nconst registrations: Array<{ id: symbol; provider: CanonicalMcpBridgeEnvProvider }> = [];\nconst turnLeases = new Map<string, Set<() => void>>();\n\nfunction turnKey(\n scope: Pick<CanonicalMcpBridgeScope, \"userId\" | \"topicId\" | \"queryId\" | \"peerBridge\">,\n): string {\n return JSON.stringify([\n scope.userId,\n scope.topicId,\n scope.queryId,\n scope.peerBridge.hubCellId,\n scope.peerBridge.hostTopicId,\n scope.peerBridge.hostQueryId,\n ]);\n}\n\n/** Placement adapters install a scoped capability issuer without exposing\n * their hub discovery or authentication model to generic core. */\nexport function registerCanonicalMcpBridgeEnvProvider(\n provider: CanonicalMcpBridgeEnvProvider,\n): () => void {\n const registration = { id: Symbol(\"canonical-mcp-bridge\"), provider };\n registrations.push(registration);\n let disposed = false;\n return () => {\n if (disposed) return;\n disposed = true;\n const index = registrations.findIndex((entry) => entry.id === registration.id);\n if (index >= 0) registrations.splice(index, 1);\n };\n}\n\nexport function canonicalMcpBridgeEnv(\n scope: CanonicalMcpBridgeScope,\n): Record<string, string> | undefined {\n const lease = registrations.at(-1)?.provider(scope);\n if (!lease) return undefined;\n const key = turnKey(scope);\n const leases = turnLeases.get(key) ?? new Set<() => void>();\n leases.add(lease.revoke);\n turnLeases.set(key, leases);\n return lease.env;\n}\n\n/** Revoke every canonical MCP capability issued while building one placed turn. */\nexport function revokeCanonicalMcpBridgeTurn(\n scope: Pick<CanonicalMcpBridgeScope, \"userId\" | \"topicId\" | \"queryId\" | \"peerBridge\">,\n): number {\n const key = turnKey(scope);\n const leases = turnLeases.get(key);\n if (!leases) return 0;\n turnLeases.delete(key);\n for (const revoke of leases) {\n try {\n revoke();\n } catch {\n // Revocation is best-effort across independently owned bridge adapters;\n // continue so one broken disposer cannot preserve sibling capabilities.\n }\n }\n return leases.size;\n}\n"
6
6
  ],
7
- "mappings": ";;;;AAsBA,IAAM,gBAAgF,CAA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AI;AAAA,MACF,OAAO;AAAA,MACP,MAAM;AAAA,EAIV;AAAA,EACA,OAAO,OAAO;AAAA;",
8
+ "debugId": "7358D06F0893D4D064756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -23,7 +23,7 @@ import { createRequire } from "module";
23
23
  import { dirname, join } from "path";
24
24
 
25
25
  // ../../packages/core/src/version.ts
26
- var NEGOTIUM_VERSION = "0.18.2";
26
+ var NEGOTIUM_VERSION = "0.19.1";
27
27
 
28
28
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
29
29
  var moduleRequire = createRequire(import.meta.url);
@@ -158,4 +158,4 @@ export {
158
158
  createCodexAppServerForker
159
159
  };
160
160
 
161
- //# debugId=BEFB3E8C582938DC64756E2164756E21
161
+ //# debugId=BBE91265DAC3F7C064756E2164756E21
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../packages/core/src/agents/codex-app-server.ts", "../../../packages/core/src/agents/codex-native-multi-agent.ts", "../../../packages/core/src/version.ts"],
4
+ "sourcesContent": [
5
+ "import { type ChildProcessWithoutNullStreams, spawn } from \"node:child_process\";\nimport { codexCliScriptPath } from \"#agents/codex-native-multi-agent\";\nimport { hostedCodexHomePath } from \"#agents/execution-host\";\nimport { latestCodexRolloutPath } from \"#agents/rollout/codex\";\nimport { NEGOTIUM_VERSION } from \"#version\";\n\ninterface CodexAppServerForkResult {\n forkId: string;\n rolloutPath: string;\n}\n\ninterface CodexAppServerForkHost {\n spawnServer(): ChildProcessWithoutNullStreams;\n findRolloutPath(threadId: string): string | undefined;\n timeoutMs: number;\n}\n\ntype JsonRpcResponse = {\n id?: number;\n result?: { thread?: { id?: unknown } };\n error?: { message?: unknown };\n};\n\nexport function createCodexAppServerForker(host: CodexAppServerForkHost) {\n return async (parentThreadId: string): Promise<CodexAppServerForkResult> => {\n const child = host.spawnServer();\n\n return await new Promise<CodexAppServerForkResult>((resolve, reject) => {\n let settled = false;\n let stdoutBuffer = \"\";\n let stderr = \"\";\n const timer = setTimeout(\n () => finish(new Error(\"Codex thread fork timed out\")),\n host.timeoutMs,\n );\n\n const finish = (error?: Error, result?: CodexAppServerForkResult) => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n try {\n child.stdin.end();\n child.kill();\n } catch {\n // The app server may already have exited after stdin closed.\n }\n if (error) reject(error);\n else if (result) resolve(result);\n else reject(new Error(\"Codex thread fork returned no result\"));\n };\n\n const send = (message: Record<string, unknown>) => {\n child.stdin.write(`${JSON.stringify(message)}\\n`);\n };\n\n child.stderr.on(\"data\", (chunk) => {\n if (stderr.length < 8_192) stderr += String(chunk);\n });\n child.on(\"error\", (error) => finish(error));\n child.on(\"exit\", (code, signal) => {\n if (settled) return;\n const detail = signal ? `signal ${signal}` : `code ${code ?? 1}`;\n finish(\n new Error(\n `Codex app server exited with ${detail}${stderr.trim() ? `: ${stderr.trim()}` : \"\"}`,\n ),\n );\n });\n child.stdout.on(\"data\", (chunk) => {\n stdoutBuffer += String(chunk);\n for (;;) {\n const newline = stdoutBuffer.indexOf(\"\\n\");\n if (newline < 0) break;\n const line = stdoutBuffer.slice(0, newline);\n stdoutBuffer = stdoutBuffer.slice(newline + 1);\n let message: JsonRpcResponse;\n try {\n message = JSON.parse(line) as JsonRpcResponse;\n } catch {\n continue;\n }\n\n if (message.id === 1) {\n if (message.error) {\n finish(new Error(String(message.error.message || \"Codex initialization failed\")));\n return;\n }\n send({ method: \"initialized\" });\n send({ id: 2, method: \"thread/fork\", params: { threadId: parentThreadId } });\n continue;\n }\n if (message.id !== 2) continue;\n if (message.error) {\n finish(new Error(String(message.error.message || \"Codex thread fork failed\")));\n return;\n }\n const forkId = message.result?.thread?.id;\n if (typeof forkId !== \"string\" || !forkId) {\n finish(new Error(\"Codex thread fork returned no thread id\"));\n return;\n }\n const rolloutPath = host.findRolloutPath(forkId);\n if (!rolloutPath) {\n finish(new Error(`Codex thread fork rollout was not found for ${forkId}`));\n return;\n }\n finish(undefined, { forkId, rolloutPath });\n return;\n }\n });\n\n send({\n id: 1,\n method: \"initialize\",\n params: {\n clientInfo: { name: \"negotium\", version: NEGOTIUM_VERSION },\n },\n });\n });\n };\n}\n\nconst forkCodexThread = createCodexAppServerForker({\n spawnServer() {\n return spawn(process.execPath, [codexCliScriptPath(), \"app-server\", \"--stdio\"], {\n env: { ...process.env, CODEX_HOME: hostedCodexHomePath() },\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n // Background stdio server — no console window on Windows. Ignored on POSIX.\n windowsHide: true,\n });\n },\n findRolloutPath: latestCodexRolloutPath,\n timeoutMs: 15_000,\n});\n\nexport async function forkCodexSession(parentThreadId: string): Promise<CodexAppServerForkResult> {\n return await forkCodexThread(parentThreadId);\n}\n",
6
+ "import { type ChildProcess, spawn } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport {\n chmodSync,\n copyFileSync,\n existsSync,\n mkdtempSync,\n readFileSync,\n renameSync,\n rmSync,\n unlinkSync,\n writeFileSync,\n} from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { NEGOTIUM_VERSION } from \"#version\";\n\ntype CodexModel = Record<string, unknown>;\ntype CodexModelCache = {\n client_version?: unknown;\n models?: unknown;\n};\n\nconst moduleRequire = createRequire(import.meta.url);\nconst codexSdkPackagePath = moduleRequire.resolve(\"@openai/codex-sdk/package.json\");\nconst codexSdkRequire = createRequire(codexSdkPackagePath);\nconst bundledCodexPackagePath = codexSdkRequire.resolve(\"@openai/codex/package.json\");\n\nfunction readPackageVersion(packageJsonPath: string): string {\n const parsed = JSON.parse(readFileSync(packageJsonPath, \"utf8\")) as { version?: unknown };\n if (typeof parsed.version !== \"string\" || !parsed.version.trim()) {\n throw new Error(`Codex package has no valid version: ${packageJsonPath}`);\n }\n return parsed.version;\n}\n\nexport const BUNDLED_CODEX_VERSION = readPackageVersion(bundledCodexPackagePath);\nconst SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/g, \"_\");\nconst NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;\nconst NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;\n\nexport function codexCliScriptPath(): string {\n return join(dirname(bundledCodexPackagePath), \"bin\", \"codex.js\");\n}\n\nfunction parseCodexModelCache(contents: string, sourcePath: string): CodexModelCache {\n let parsed: CodexModelCache;\n try {\n parsed = JSON.parse(contents) as CodexModelCache;\n } catch (error) {\n throw new Error(`Codex model cache is invalid JSON: ${sourcePath}`, { cause: error });\n }\n if (!Array.isArray(parsed.models) || parsed.models.length === 0) {\n throw new Error(`Codex model cache has no models: ${sourcePath}`);\n }\n return parsed;\n}\n\nfunction readCodexModelCache(cachePath: string): {\n contents: string;\n parsed: CodexModelCache;\n} {\n const contents = readFileSync(cachePath, \"utf8\");\n return { contents, parsed: parseCodexModelCache(contents, cachePath) };\n}\n\nfunction readCompatibleCodexModelCache(cachePath: string): {\n contents: string;\n parsed: CodexModelCache;\n} {\n const cache = readCodexModelCache(cachePath);\n if (cache.parsed.client_version !== BUNDLED_CODEX_VERSION) {\n const found =\n typeof cache.parsed.client_version === \"string\"\n ? cache.parsed.client_version\n : \"missing or invalid\";\n throw new Error(\n `Codex model cache version ${found} does not match Negotium's bundled Codex ${BUNDLED_CODEX_VERSION}: ${cachePath}`,\n );\n }\n return cache;\n}\n\nfunction writePrivateFileAtomic(path: string, contents: string): void {\n if (existsSync(path) && readFileSync(path, \"utf8\") === contents) return;\n\n const tempPath = `${path}.${process.pid}.${randomUUID()}.tmp`;\n try {\n writeFileSync(tempPath, contents, { encoding: \"utf8\", mode: 0o600 });\n renameSync(tempPath, path);\n chmodSync(path, 0o600);\n } finally {\n try {\n unlinkSync(tempPath);\n } catch {\n // renameSync normally consumed the temporary file.\n }\n }\n}\n\nexport function bundledCodexModelCachePath(authFilePath: string): string {\n return join(dirname(authFilePath), NEGOTIUM_MODEL_CACHE);\n}\n\nasync function bootstrapCodexModelCache(codexHome: string, cachePath: string): Promise<void> {\n const child = spawn(process.execPath, [codexCliScriptPath(), \"app-server\", \"--stdio\"], {\n env: { ...process.env, CODEX_HOME: codexHome },\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n // Background stdio server — no console window on Windows. Ignored on POSIX.\n windowsHide: true,\n });\n\n const refreshed = new Promise<void>((resolve, reject) => {\n let settled = false;\n let stdoutBuffer = \"\";\n let stderr = \"\";\n const timer = setTimeout(\n () => finish(new Error(\"timed out while refreshing the Codex model catalog\")),\n 15_000,\n );\n\n const finish = (error?: Error) => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n try {\n child.stdin.end();\n child.kill();\n } catch {\n // The app server may already have exited after stdin closed.\n }\n if (error) reject(error);\n else if (!existsSync(cachePath)) reject(new Error(\"Codex did not create its model cache\"));\n else resolve();\n };\n\n const send = (message: Record<string, unknown>) => {\n child.stdin.write(`${JSON.stringify(message)}\\n`);\n };\n\n child.stderr.on(\"data\", (chunk) => {\n if (stderr.length < 4_096) stderr += String(chunk);\n });\n child.on(\"error\", (error) => finish(error));\n child.on(\"exit\", (code, signal) => {\n if (!settled) {\n finish(\n new Error(\n `Codex model catalog refresh exited with ${signal ? `signal ${signal}` : `code ${code ?? 1}`}${stderr.trim() ? `: ${stderr.trim()}` : \"\"}`,\n ),\n );\n }\n });\n child.stdout.on(\"data\", (chunk) => {\n stdoutBuffer += String(chunk);\n for (;;) {\n const newline = stdoutBuffer.indexOf(\"\\n\");\n if (newline < 0) break;\n const line = stdoutBuffer.slice(0, newline);\n stdoutBuffer = stdoutBuffer.slice(newline + 1);\n let message: { id?: number; error?: { message?: string } };\n try {\n message = JSON.parse(line) as typeof message;\n } catch {\n continue;\n }\n if (message.id === 1) {\n if (message.error) {\n finish(new Error(message.error.message || \"Codex initialization failed\"));\n return;\n }\n send({ method: \"initialized\" });\n send({ id: 2, method: \"model/list\", params: { includeHidden: true } });\n } else if (message.id === 2) {\n if (message.error) {\n finish(new Error(message.error.message || \"Codex model listing failed\"));\n } else {\n finish();\n }\n return;\n }\n }\n });\n\n send({\n id: 1,\n method: \"initialize\",\n params: {\n clientInfo: { name: \"negotium\", version: NEGOTIUM_VERSION },\n capabilities: { experimentalApi: true },\n },\n });\n });\n\n try {\n await refreshed;\n } finally {\n // `child.kill()` only signals. The caller deletes CODEX_HOME right after we\n // return, and Windows cannot delete a directory the child still holds open\n // (EBUSY), so wait for the process to actually exit first.\n await waitForChildExit(child, CODEX_BOOTSTRAP_EXIT_WAIT_MS);\n }\n}\n\nconst CODEX_BOOTSTRAP_EXIT_WAIT_MS = 3_000;\n\nfunction waitForChildExit(child: ChildProcess, timeoutMs: number): Promise<void> {\n if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve();\n return new Promise((resolve) => {\n const timer = setTimeout(resolve, timeoutMs);\n timer.unref?.();\n child.once(\"exit\", () => {\n clearTimeout(timer);\n resolve();\n });\n });\n}\n\n/**\n * Remove the temporary CODEX_HOME. On Windows a just-exited child (or an\n * antivirus scan of the files it wrote) can keep the directory busy for a\n * moment, so retry, and never let cleanup of a throwaway directory fail a turn\n * whose result was already read. POSIX keeps the original behaviour: unlinking\n * open files works there, and a genuine failure still surfaces.\n */\nfunction removeIsolatedCodexHome(dir: string): void {\n if (process.platform !== \"win32\") {\n rmSync(dir, { recursive: true, force: true });\n return;\n }\n try {\n rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });\n } catch {\n // Best effort: the OS temp cleaner will reclaim it.\n }\n}\n\nasync function bootstrapIsolatedCodexModelCache(\n authFilePath: string,\n bootstrap: (codexHome: string, cachePath: string) => Promise<void>,\n): Promise<string> {\n const sourceHome = dirname(authFilePath);\n const isolatedHome = mkdtempSync(join(tmpdir(), \"negotium-codex-models-\"));\n const isolatedCachePath = join(isolatedHome, \"models_cache.json\");\n\n try {\n const isolatedAuthPath = join(isolatedHome, \"auth.json\");\n copyFileSync(authFilePath, isolatedAuthPath);\n chmodSync(isolatedAuthPath, 0o600);\n\n // Preserve custom provider configuration while keeping the bundled CLI's\n // cache write completely outside the user's shared CODEX_HOME.\n const sourceConfigPath = join(sourceHome, \"config.toml\");\n if (existsSync(sourceConfigPath)) {\n const isolatedConfigPath = join(isolatedHome, \"config.toml\");\n copyFileSync(sourceConfigPath, isolatedConfigPath);\n chmodSync(isolatedConfigPath, 0o600);\n }\n\n await bootstrap(isolatedHome, isolatedCachePath);\n return readCompatibleCodexModelCache(isolatedCachePath).contents;\n } finally {\n removeIsolatedCodexHome(isolatedHome);\n }\n}\n\nexport async function ensureCodexModelCache(\n authFilePath: string,\n bootstrap: (codexHome: string, cachePath: string) => Promise<void> = bootstrapCodexModelCache,\n): Promise<string> {\n const codexHome = dirname(authFilePath);\n const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;\n if (configuredCachePath) {\n if (!existsSync(configuredCachePath)) {\n throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);\n }\n readCompatibleCodexModelCache(configuredCachePath);\n return configuredCachePath;\n }\n\n // The global Codex CLI owns models_cache.json and may update it to a schema\n // newer than the SDK bundled by Negotium. Snapshot a cache generated for our\n // exact bundled version so later global CLI updates cannot break turns.\n const bundledCachePath = bundledCodexModelCachePath(authFilePath);\n const sharedCachePath = join(codexHome, \"models_cache.json\");\n if (existsSync(sharedCachePath)) {\n try {\n const shared = readCompatibleCodexModelCache(sharedCachePath);\n // Keep model metadata fresh while the global CLI remains compatible.\n writePrivateFileAtomic(bundledCachePath, shared.contents);\n return bundledCachePath;\n } catch {\n // A compatible private snapshot is safer than failing because another\n // process briefly exposed an incomplete shared-cache write.\n }\n }\n\n if (existsSync(bundledCachePath)) {\n try {\n readCompatibleCodexModelCache(bundledCachePath);\n return bundledCachePath;\n } catch {\n // Re-bootstrap below instead of passing a corrupt or version-mismatched\n // private snapshot into this SDK version.\n }\n }\n\n const refreshedContents = await bootstrapIsolatedCodexModelCache(authFilePath, bootstrap);\n writePrivateFileAtomic(bundledCachePath, refreshedContents);\n return bundledCachePath;\n}\n\n/**\n * Codex can resolve model metadata before `features.multi_agent=false`, so a\n * model-advertised v1/v2 value may still register native collaboration tools.\n * Feed Codex an authoritative copy of its own catalog with only that field\n * disabled. Runtime MCP delegation remains available independently.\n */\nexport function writeCodexCatalogWithNativeMultiAgentDisabled(\n authFilePath: string,\n sourcePath: string,\n): string {\n const codexHome = dirname(authFilePath);\n const outputPath = join(codexHome, NEGOTIUM_MODEL_CATALOG);\n\n const parsed = readCodexModelCache(sourcePath).parsed;\n\n const models = (parsed.models as unknown[]).map((model, index): CodexModel => {\n if (!model || typeof model !== \"object\" || Array.isArray(model)) {\n throw new Error(`Codex model cache entry ${index} is invalid: ${sourcePath}`);\n }\n return { ...(model as CodexModel), multi_agent_version: \"disabled\" };\n });\n const contents = `${JSON.stringify({ models }, null, 2)}\\n`;\n writePrivateFileAtomic(outputPath, contents);\n return outputPath;\n}\n",
7
+ "export const NEGOTIUM_VERSION = \"0.19.1\";\n"
8
+ ],
9
+ "mappings": ";;;;;;;AAAA;;;ACEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA;AAEA;;;ACfO,IAAM,mBAAmB;;;ADwBhC,IAAM,gBAAgB,cAAc,YAAY,GAAG;AACnD,IAAM,sBAAsB,cAAc,QAAQ,gCAAgC;AAClF,IAAM,kBAAkB,cAAc,mBAAmB;AACzD,IAAM,0BAA0B,gBAAgB,QAAQ,4BAA4B;AAEpF,SAAS,kBAAkB,CAAC,iBAAiC;AAAA,EAC3D,MAAM,SAAS,KAAK,MAAM,aAAa,iBAAiB,MAAM,CAAC;AAAA,EAC/D,IAAI,OAAO,OAAO,YAAY,YAAY,CAAC,OAAO,QAAQ,KAAK,GAAG;AAAA,IAChE,MAAM,IAAI,MAAM,uCAAuC,iBAAiB;AAAA,EAC1E;AAAA,EACA,OAAO,OAAO;AAAA;AAGT,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