negotium 0.6.2 → 0.6.4

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.
@@ -1025,235 +1025,6 @@ var init_claude_registry = __esm(() => {
1025
1025
  };
1026
1026
  });
1027
1027
 
1028
- // ../../packages/core/src/version.ts
1029
- var NEGOTIUM_VERSION = "0.6.1";
1030
-
1031
- // ../../packages/core/src/agents/codex-native-multi-agent.ts
1032
- import { spawn } from "child_process";
1033
- import { randomUUID as randomUUID3 } from "crypto";
1034
- import {
1035
- chmodSync as chmodSync3,
1036
- copyFileSync,
1037
- existsSync as existsSync6,
1038
- mkdtempSync,
1039
- readFileSync as readFileSync6,
1040
- renameSync as renameSync4,
1041
- rmSync,
1042
- unlinkSync as unlinkSync6,
1043
- writeFileSync as writeFileSync5
1044
- } from "fs";
1045
- import { createRequire as createRequire2 } from "module";
1046
- import { tmpdir } from "os";
1047
- import { dirname as dirname4, join as join5 } from "path";
1048
- function readPackageVersion(packageJsonPath) {
1049
- const parsed = JSON.parse(readFileSync6(packageJsonPath, "utf8"));
1050
- if (typeof parsed.version !== "string" || !parsed.version.trim()) {
1051
- throw new Error(`Codex package has no valid version: ${packageJsonPath}`);
1052
- }
1053
- return parsed.version;
1054
- }
1055
- function codexCliScriptPath() {
1056
- return join5(dirname4(bundledCodexPackagePath), "bin", "codex.js");
1057
- }
1058
- function parseCodexModelCache(contents, sourcePath) {
1059
- let parsed;
1060
- try {
1061
- parsed = JSON.parse(contents);
1062
- } catch (error) {
1063
- throw new Error(`Codex model cache is invalid JSON: ${sourcePath}`, { cause: error });
1064
- }
1065
- if (!Array.isArray(parsed.models) || parsed.models.length === 0) {
1066
- throw new Error(`Codex model cache has no models: ${sourcePath}`);
1067
- }
1068
- return parsed;
1069
- }
1070
- function readCodexModelCache(cachePath) {
1071
- const contents = readFileSync6(cachePath, "utf8");
1072
- return { contents, parsed: parseCodexModelCache(contents, cachePath) };
1073
- }
1074
- function readCompatibleCodexModelCache(cachePath) {
1075
- const cache = readCodexModelCache(cachePath);
1076
- if (cache.parsed.client_version !== BUNDLED_CODEX_VERSION) {
1077
- const found = typeof cache.parsed.client_version === "string" ? cache.parsed.client_version : "missing or invalid";
1078
- throw new Error(`Codex model cache version ${found} does not match Negotium's bundled Codex ${BUNDLED_CODEX_VERSION}: ${cachePath}`);
1079
- }
1080
- return cache;
1081
- }
1082
- function writePrivateFileAtomic(path, contents) {
1083
- if (existsSync6(path) && readFileSync6(path, "utf8") === contents)
1084
- return;
1085
- const tempPath = `${path}.${process.pid}.${randomUUID3()}.tmp`;
1086
- try {
1087
- writeFileSync5(tempPath, contents, { encoding: "utf8", mode: 384 });
1088
- renameSync4(tempPath, path);
1089
- chmodSync3(path, 384);
1090
- } finally {
1091
- try {
1092
- unlinkSync6(tempPath);
1093
- } catch {}
1094
- }
1095
- }
1096
- function bundledCodexModelCachePath(authFilePath) {
1097
- return join5(dirname4(authFilePath), NEGOTIUM_MODEL_CACHE);
1098
- }
1099
- async function bootstrapCodexModelCache(codexHome, cachePath) {
1100
- const child = spawn(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
1101
- env: { ...process.env, CODEX_HOME: codexHome },
1102
- stdio: ["pipe", "pipe", "pipe"]
1103
- });
1104
- await new Promise((resolve4, reject) => {
1105
- let settled = false;
1106
- let stdoutBuffer = "";
1107
- let stderr = "";
1108
- const timer = setTimeout(() => finish(new Error("timed out while refreshing the Codex model catalog")), 15000);
1109
- const finish = (error) => {
1110
- if (settled)
1111
- return;
1112
- settled = true;
1113
- clearTimeout(timer);
1114
- try {
1115
- child.stdin.end();
1116
- child.kill();
1117
- } catch {}
1118
- if (error)
1119
- reject(error);
1120
- else if (!existsSync6(cachePath))
1121
- reject(new Error("Codex did not create its model cache"));
1122
- else
1123
- resolve4();
1124
- };
1125
- const send = (message) => {
1126
- child.stdin.write(`${JSON.stringify(message)}
1127
- `);
1128
- };
1129
- child.stderr.on("data", (chunk) => {
1130
- if (stderr.length < 4096)
1131
- stderr += String(chunk);
1132
- });
1133
- child.on("error", (error) => finish(error));
1134
- child.on("exit", (code, signal) => {
1135
- if (!settled) {
1136
- finish(new Error(`Codex model catalog refresh exited with ${signal ? `signal ${signal}` : `code ${code ?? 1}`}${stderr.trim() ? `: ${stderr.trim()}` : ""}`));
1137
- }
1138
- });
1139
- child.stdout.on("data", (chunk) => {
1140
- stdoutBuffer += String(chunk);
1141
- for (;; ) {
1142
- const newline = stdoutBuffer.indexOf(`
1143
- `);
1144
- if (newline < 0)
1145
- break;
1146
- const line = stdoutBuffer.slice(0, newline);
1147
- stdoutBuffer = stdoutBuffer.slice(newline + 1);
1148
- let message;
1149
- try {
1150
- message = JSON.parse(line);
1151
- } catch {
1152
- continue;
1153
- }
1154
- if (message.id === 1) {
1155
- if (message.error) {
1156
- finish(new Error(message.error.message || "Codex initialization failed"));
1157
- return;
1158
- }
1159
- send({ method: "initialized" });
1160
- send({ id: 2, method: "model/list", params: { includeHidden: true } });
1161
- } else if (message.id === 2) {
1162
- if (message.error) {
1163
- finish(new Error(message.error.message || "Codex model listing failed"));
1164
- } else {
1165
- finish();
1166
- }
1167
- return;
1168
- }
1169
- }
1170
- });
1171
- send({
1172
- id: 1,
1173
- method: "initialize",
1174
- params: {
1175
- clientInfo: { name: "negotium", version: NEGOTIUM_VERSION },
1176
- capabilities: { experimentalApi: true }
1177
- }
1178
- });
1179
- });
1180
- }
1181
- async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
1182
- const sourceHome = dirname4(authFilePath);
1183
- const isolatedHome = mkdtempSync(join5(tmpdir(), "negotium-codex-models-"));
1184
- const isolatedCachePath = join5(isolatedHome, "models_cache.json");
1185
- try {
1186
- const isolatedAuthPath = join5(isolatedHome, "auth.json");
1187
- copyFileSync(authFilePath, isolatedAuthPath);
1188
- chmodSync3(isolatedAuthPath, 384);
1189
- const sourceConfigPath = join5(sourceHome, "config.toml");
1190
- if (existsSync6(sourceConfigPath)) {
1191
- const isolatedConfigPath = join5(isolatedHome, "config.toml");
1192
- copyFileSync(sourceConfigPath, isolatedConfigPath);
1193
- chmodSync3(isolatedConfigPath, 384);
1194
- }
1195
- await bootstrap(isolatedHome, isolatedCachePath);
1196
- return readCompatibleCodexModelCache(isolatedCachePath).contents;
1197
- } finally {
1198
- rmSync(isolatedHome, { recursive: true, force: true });
1199
- }
1200
- }
1201
- async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
1202
- const codexHome = dirname4(authFilePath);
1203
- const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
1204
- if (configuredCachePath) {
1205
- if (!existsSync6(configuredCachePath)) {
1206
- throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);
1207
- }
1208
- readCompatibleCodexModelCache(configuredCachePath);
1209
- return configuredCachePath;
1210
- }
1211
- const bundledCachePath = bundledCodexModelCachePath(authFilePath);
1212
- const sharedCachePath = join5(codexHome, "models_cache.json");
1213
- if (existsSync6(sharedCachePath)) {
1214
- try {
1215
- const shared = readCompatibleCodexModelCache(sharedCachePath);
1216
- writePrivateFileAtomic(bundledCachePath, shared.contents);
1217
- return bundledCachePath;
1218
- } catch {}
1219
- }
1220
- if (existsSync6(bundledCachePath)) {
1221
- try {
1222
- readCompatibleCodexModelCache(bundledCachePath);
1223
- return bundledCachePath;
1224
- } catch {}
1225
- }
1226
- const refreshedContents = await bootstrapIsolatedCodexModelCache(authFilePath, bootstrap);
1227
- writePrivateFileAtomic(bundledCachePath, refreshedContents);
1228
- return bundledCachePath;
1229
- }
1230
- function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
1231
- const codexHome = dirname4(authFilePath);
1232
- const outputPath = join5(codexHome, NEGOTIUM_MODEL_CATALOG);
1233
- const parsed = readCodexModelCache(sourcePath).parsed;
1234
- const models = parsed.models.map((model, index) => {
1235
- if (!model || typeof model !== "object" || Array.isArray(model)) {
1236
- throw new Error(`Codex model cache entry ${index} is invalid: ${sourcePath}`);
1237
- }
1238
- return { ...model, multi_agent_version: "disabled" };
1239
- });
1240
- const contents = `${JSON.stringify({ models }, null, 2)}
1241
- `;
1242
- writePrivateFileAtomic(outputPath, contents);
1243
- return outputPath;
1244
- }
1245
- var moduleRequire, codexSdkPackagePath, codexSdkRequire, bundledCodexPackagePath, BUNDLED_CODEX_VERSION, SAFE_BUNDLED_CODEX_VERSION, NEGOTIUM_MODEL_CACHE, NEGOTIUM_MODEL_CATALOG;
1246
- var init_codex_native_multi_agent = __esm(() => {
1247
- moduleRequire = createRequire2(import.meta.url);
1248
- codexSdkPackagePath = moduleRequire.resolve("@openai/codex-sdk/package.json");
1249
- codexSdkRequire = createRequire2(codexSdkPackagePath);
1250
- bundledCodexPackagePath = codexSdkRequire.resolve("@openai/codex/package.json");
1251
- BUNDLED_CODEX_VERSION = readPackageVersion(bundledCodexPackagePath);
1252
- SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/g, "_");
1253
- NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
1254
- NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
1255
- });
1256
-
1257
1028
  // ../../packages/core/src/security/sensitive-path.ts
1258
1029
  import { realpathSync } from "fs";
1259
1030
  import { resolve as resolve4 } from "path";
@@ -1482,7 +1253,7 @@ function deriveBgBashContextCapability(runtimeCapability, userId, topic) {
1482
1253
  var init_context = () => {};
1483
1254
 
1484
1255
  // ../../packages/core/src/platform/background-bash/manager.ts
1485
- import { execFileSync as execFileSync2, spawn as spawn2 } from "child_process";
1256
+ import { execFileSync as execFileSync2, spawn } from "child_process";
1486
1257
  import { randomBytes as randomBytes2 } from "crypto";
1487
1258
  function makeBgBashKey(_userId, _topic) {
1488
1259
  return "runtime";
@@ -1509,7 +1280,7 @@ function createBackgroundBashManager(options = {}) {
1509
1280
  const now = options.now ?? Date.now;
1510
1281
  const wait = options.delay ?? delay;
1511
1282
  const portPids = options.portPids ?? defaultPortPids;
1512
- const spawnImpl = options.spawn ?? ((command, args, spawnOptions) => spawn2(command, [...args], spawnOptions));
1283
+ const spawnImpl = options.spawn ?? ((command, args, spawnOptions) => spawn(command, [...args], spawnOptions));
1513
1284
  function contextKey(userId, topic) {
1514
1285
  return `${userId}\x00${topic}`;
1515
1286
  }
@@ -2303,7 +2074,7 @@ var init_mcp_config = __esm(() => {
2303
2074
  // ../../packages/core/src/storage/storage-host.ts
2304
2075
  import { mkdirSync as mkdirSync6 } from "fs";
2305
2076
  import { homedir as homedir4 } from "os";
2306
- import { dirname as dirname5, join as join6, resolve as resolve5 } from "path";
2077
+ import { dirname as dirname4, join as join5, resolve as resolve5 } from "path";
2307
2078
  function storageState() {
2308
2079
  const holder = globalThis;
2309
2080
  const existing = holder[STORAGE_HOST_STATE];
@@ -2331,23 +2102,23 @@ function envPath(name, fallback) {
2331
2102
  return resolve5(value2 || fallback);
2332
2103
  }
2333
2104
  function defaultStateDir() {
2334
- return envPath("NEGOTIUM_STATE_DIR", join6(homedir4(), ".negotium"));
2105
+ return envPath("NEGOTIUM_STATE_DIR", join5(homedir4(), ".negotium"));
2335
2106
  }
2336
2107
  function defaultDataDir() {
2337
- return envPath("NEGOTIUM_DATA_DIR", join6(defaultStateDir(), "data"));
2108
+ return envPath("NEGOTIUM_DATA_DIR", join5(defaultStateDir(), "data"));
2338
2109
  }
2339
2110
  function defaultLogDir() {
2340
- return envPath("NEGOTIUM_LOG_DIR", join6(defaultStateDir(), "logs"));
2111
+ return envPath("NEGOTIUM_LOG_DIR", join5(defaultStateDir(), "logs"));
2341
2112
  }
2342
2113
  function defaultWorkspaceDir() {
2343
- return envPath("NEGOTIUM_WORKSPACE_DIR", join6(defaultStateDir(), "workspace"));
2114
+ return envPath("NEGOTIUM_WORKSPACE_DIR", join5(defaultStateDir(), "workspace"));
2344
2115
  }
2345
2116
  function defaultSessionAsksDir() {
2346
- const runDir = envPath("NEGOTIUM_RUN_DIR", join6(defaultStateDir(), "runtime"));
2347
- return join6(runDir, "session-asks");
2117
+ const runDir = envPath("NEGOTIUM_RUN_DIR", join5(defaultStateDir(), "runtime"));
2118
+ return join5(runDir, "session-asks");
2348
2119
  }
2349
2120
  function defaultSessionsDatabasePath() {
2350
- return envPath("SESSIONS_DB_PATH", join6(resolveStorageDataDir(), "sessions.db"));
2121
+ return envPath("SESSIONS_DB_PATH", join5(resolveStorageDataDir(), "sessions.db"));
2351
2122
  }
2352
2123
  function isSqliteBusy(error) {
2353
2124
  const message = error instanceof Error ? error.message : String(error);
@@ -2382,7 +2153,7 @@ function defaultDatabase() {
2382
2153
  return state.fallbackDatabase;
2383
2154
  if (state.fallbackDatabase)
2384
2155
  state.fallbackDatabase.close();
2385
- mkdirSync6(dirname5(path), { recursive: true });
2156
+ mkdirSync6(dirname4(path), { recursive: true });
2386
2157
  state.fallbackDatabase = new Database(path, { create: true });
2387
2158
  state.fallbackDatabasePath = path;
2388
2159
  initializeDatabase(state.fallbackDatabase);
@@ -2404,7 +2175,7 @@ function resolveStorageWorkspaceDir() {
2404
2175
  return storageState().configuredHost.workspaceDir ?? defaultWorkspaceDir();
2405
2176
  }
2406
2177
  function resolveStorageSharedWikiDir() {
2407
- return storageState().configuredHost.sharedWikiDir ?? join6(resolveStorageWorkspaceDir(), "wiki");
2178
+ return storageState().configuredHost.sharedWikiDir ?? join5(resolveStorageWorkspaceDir(), "wiki");
2408
2179
  }
2409
2180
  function registerStorageSchemaInitializer(initialize, priority = 100) {
2410
2181
  const initializers = storageState().schemaInitializers;
@@ -2513,8 +2284,8 @@ var init_vault_crypto = __esm(() => {
2513
2284
  });
2514
2285
 
2515
2286
  // ../../packages/core/src/storage/vault.ts
2516
- import { chmodSync as chmodSync4, mkdirSync as mkdirSync7 } from "fs";
2517
- import { join as join7 } from "path";
2287
+ import { chmodSync as chmodSync3, mkdirSync as mkdirSync7 } from "fs";
2288
+ import { join as join6 } from "path";
2518
2289
  function initializeVaultDatabase(database) {
2519
2290
  database.exec("PRAGMA journal_mode = WAL");
2520
2291
  database.exec("PRAGMA busy_timeout = 5000");
@@ -2549,11 +2320,11 @@ function initializeVaultDatabase(database) {
2549
2320
  }
2550
2321
  }
2551
2322
  function openVaultDatabase(dataDir) {
2552
- const vaultDir = join7(dataDir, "vault");
2553
- const path = join7(vaultDir, "vault.db");
2323
+ const vaultDir = join6(dataDir, "vault");
2324
+ const path = join6(vaultDir, "vault.db");
2554
2325
  mkdirSync7(vaultDir, { recursive: true, mode: 448 });
2555
2326
  const database = new Database(path, { create: true });
2556
- chmodSync4(path, 384);
2327
+ chmodSync3(path, 384);
2557
2328
  initializeVaultDatabase(database);
2558
2329
  return database;
2559
2330
  }
@@ -2658,7 +2429,7 @@ var init_vault = __esm(async () => {
2658
2429
 
2659
2430
  // ../../packages/core/src/agents/execution-host.ts
2660
2431
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2661
- import { dirname as dirname6 } from "path";
2432
+ import { dirname as dirname5 } from "path";
2662
2433
  function activeHost() {
2663
2434
  const scoped = scopedHost.getStore();
2664
2435
  if (scoped)
@@ -2693,7 +2464,7 @@ function hostedCodexAuthFilePath() {
2693
2464
  return activeHost().codexAuthFilePath();
2694
2465
  }
2695
2466
  function hostedCodexHomePath() {
2696
- return dirname6(hostedCodexAuthFilePath());
2467
+ return dirname5(hostedCodexAuthFilePath());
2697
2468
  }
2698
2469
  var defaultHost, hostRegistrations, scopedHost;
2699
2470
  var init_execution_host = __esm(async () => {
@@ -2715,15 +2486,15 @@ var init_execution_host = __esm(async () => {
2715
2486
 
2716
2487
  // ../../packages/core/src/agents/rollout/codex.ts
2717
2488
  import { randomBytes as randomBytes4 } from "crypto";
2718
- import { existsSync as existsSync7, readFileSync as readFileSync7, realpathSync as realpathSync2, statSync as statSync3, unlinkSync as unlinkSync7 } from "fs";
2719
- import { basename as basename2, dirname as dirname7, join as join8, resolve as resolve6 } from "path";
2489
+ import { existsSync as existsSync6, readFileSync as readFileSync6, realpathSync as realpathSync2, statSync as statSync3, unlinkSync as unlinkSync6 } from "fs";
2490
+ import { basename as basename2, dirname as dirname6, join as join7, resolve as resolve6 } from "path";
2720
2491
  function codexSessionsDir() {
2721
- return join8(hostedCodexHomePath(), "sessions");
2492
+ return join7(hostedCodexHomePath(), "sessions");
2722
2493
  }
2723
2494
  function loadCodexShell() {
2724
2495
  if (_shellCache)
2725
2496
  return _shellCache;
2726
- const raw = readFileSync7(join8(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
2497
+ const raw = readFileSync6(join7(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
2727
2498
  const lines = parseJsonlText(raw);
2728
2499
  if (lines.length < 5) {
2729
2500
  throw new Error(`loadCodexShell: expected >=5 entries in codex-shell.jsonl, got ${lines.length}`);
@@ -2790,8 +2561,8 @@ function codexRolloutPath(threadId, fallback) {
2790
2561
  const hh = String(createdAt.getHours()).padStart(2, "0");
2791
2562
  const min = String(createdAt.getMinutes()).padStart(2, "0");
2792
2563
  const ss = String(createdAt.getSeconds()).padStart(2, "0");
2793
- const dir = join8(codexSessionsDir(), yyyy, mm, dd);
2794
- return join8(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
2564
+ const dir = join7(codexSessionsDir(), yyyy, mm, dd);
2565
+ return join7(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
2795
2566
  }
2796
2567
  function canonicalFilePath(path) {
2797
2568
  const absolute = resolve6(path);
@@ -2799,7 +2570,7 @@ function canonicalFilePath(path) {
2799
2570
  return realpathSync2(absolute);
2800
2571
  } catch {
2801
2572
  try {
2802
- return join8(realpathSync2(dirname7(absolute)), basename2(absolute));
2573
+ return join7(realpathSync2(dirname6(absolute)), basename2(absolute));
2803
2574
  } catch {
2804
2575
  return absolute;
2805
2576
  }
@@ -2909,7 +2680,7 @@ function readCodexPatchCallIds(threadId) {
2909
2680
  if (!path)
2910
2681
  return [];
2911
2682
  try {
2912
- return extractCodexPatchCallIds(readFileSync7(path, "utf8"));
2683
+ return extractCodexPatchCallIds(readFileSync6(path, "utf8"));
2913
2684
  } catch (error) {
2914
2685
  logger.debug({ error, threadId }, "codex patch ids: rollout read failed");
2915
2686
  return [];
@@ -2920,7 +2691,7 @@ function readLatestCodexPatchPreview(threadId, expectedPaths, consumedCallIds =
2920
2691
  if (!path)
2921
2692
  return;
2922
2693
  try {
2923
- return extractLatestCodexPatchPreview(readFileSync7(path, "utf8"), expectedPaths, consumedCallIds, expectedCallId);
2694
+ return extractLatestCodexPatchPreview(readFileSync6(path, "utf8"), expectedPaths, consumedCallIds, expectedCallId);
2924
2695
  } catch (error) {
2925
2696
  logger.debug({ error, threadId }, "codex patch preview: rollout read failed");
2926
2697
  return;
@@ -2978,7 +2749,7 @@ function readLatestCodexContextUsage(threadId) {
2978
2749
  if (!path)
2979
2750
  return;
2980
2751
  try {
2981
- return extractLatestCodexContextUsage(readFileSync7(path, "utf8"));
2752
+ return extractLatestCodexContextUsage(readFileSync6(path, "utf8"));
2982
2753
  } catch (error) {
2983
2754
  logger.debug({ error, threadId }, "codex context usage: rollout read failed");
2984
2755
  return;
@@ -2989,7 +2760,7 @@ function readLatestCodexTokenTotals(threadId) {
2989
2760
  if (!path)
2990
2761
  return;
2991
2762
  try {
2992
- return extractLatestCodexTokenTotals(readFileSync7(path, "utf8"));
2763
+ return extractLatestCodexTokenTotals(readFileSync6(path, "utf8"));
2993
2764
  } catch (error) {
2994
2765
  logger.debug({ error, threadId }, "codex token totals: rollout read failed");
2995
2766
  return;
@@ -3000,7 +2771,7 @@ function migrateCodexRolloutNativeMultiAgentMetadata(threadId) {
3000
2771
  if (!path)
3001
2772
  return false;
3002
2773
  try {
3003
- const entries = parseJsonlText(readFileSync7(path, "utf8"));
2774
+ const entries = parseJsonlText(readFileSync6(path, "utf8"));
3004
2775
  let changed = false;
3005
2776
  for (const entry of entries) {
3006
2777
  if (entry.type !== "session_meta" && entry.type !== "turn_context")
@@ -3029,19 +2800,19 @@ function latestCodexRolloutPath(threadId) {
3029
2800
  try {
3030
2801
  if (buckets) {
3031
2802
  for (const bucket of buckets) {
3032
- const dir = join8(sessionsDir, bucket);
3033
- if (!existsSync7(dir))
2803
+ const dir = join7(sessionsDir, bucket);
2804
+ if (!existsSync6(dir))
3034
2805
  continue;
3035
2806
  const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
3036
2807
  for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
3037
- candidates.push(join8(dir, rel));
2808
+ candidates.push(join7(dir, rel));
3038
2809
  }
3039
2810
  }
3040
2811
  }
3041
2812
  if (candidates.length === 0) {
3042
2813
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
3043
2814
  for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
3044
- candidates.push(join8(sessionsDir, rel));
2815
+ candidates.push(join7(sessionsDir, rel));
3045
2816
  }
3046
2817
  }
3047
2818
  return candidates.sort((a, b) => statSync3(b).mtimeMs - statSync3(a).mtimeMs)[0];
@@ -3162,15 +2933,15 @@ function sweepPriorRolloutsForThread(threadId) {
3162
2933
  return;
3163
2934
  }
3164
2935
  for (const bucket of buckets) {
3165
- const dir = join8(sessionsDir, bucket);
3166
- if (!existsSync7(dir))
2936
+ const dir = join7(sessionsDir, bucket);
2937
+ if (!existsSync6(dir))
3167
2938
  continue;
3168
2939
  try {
3169
2940
  const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
3170
2941
  for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
3171
- const fullPath = join8(dir, rel);
2942
+ const fullPath = join7(dir, rel);
3172
2943
  try {
3173
- unlinkSync7(fullPath);
2944
+ unlinkSync6(fullPath);
3174
2945
  } catch (e) {
3175
2946
  if (e?.code !== "ENOENT") {
3176
2947
  logger.warn({ err: e, path: fullPath }, "writeCodexRollout: prior-rollout unlink failed (continuing)");
@@ -3186,9 +2957,9 @@ function sweepPriorRolloutsFullTree(threadId, sessionsDir) {
3186
2957
  try {
3187
2958
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
3188
2959
  for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
3189
- const fullPath = join8(sessionsDir, rel);
2960
+ const fullPath = join7(sessionsDir, rel);
3190
2961
  try {
3191
- unlinkSync7(fullPath);
2962
+ unlinkSync6(fullPath);
3192
2963
  } catch (e) {
3193
2964
  if (e?.code !== "ENOENT") {
3194
2965
  logger.warn({ err: e, path: fullPath }, "writeCodexRollout: prior-rollout unlink failed (continuing)");
@@ -3247,7 +3018,241 @@ var init_codex = __esm(async () => {
3247
3018
  init_logger();
3248
3019
  });
3249
3020
 
3021
+ // ../../packages/core/src/version.ts
3022
+ var NEGOTIUM_VERSION = "0.6.4";
3023
+
3024
+ // ../../packages/core/src/agents/codex-native-multi-agent.ts
3025
+ import { spawn as spawn2 } from "child_process";
3026
+ import { randomUUID as randomUUID3 } from "crypto";
3027
+ import {
3028
+ chmodSync as chmodSync4,
3029
+ copyFileSync,
3030
+ existsSync as existsSync7,
3031
+ mkdtempSync,
3032
+ readFileSync as readFileSync7,
3033
+ renameSync as renameSync4,
3034
+ rmSync,
3035
+ unlinkSync as unlinkSync7,
3036
+ writeFileSync as writeFileSync5
3037
+ } from "fs";
3038
+ import { createRequire as createRequire2 } from "module";
3039
+ import { tmpdir } from "os";
3040
+ import { dirname as dirname7, join as join8 } from "path";
3041
+ function readPackageVersion(packageJsonPath) {
3042
+ const parsed = JSON.parse(readFileSync7(packageJsonPath, "utf8"));
3043
+ if (typeof parsed.version !== "string" || !parsed.version.trim()) {
3044
+ throw new Error(`Codex package has no valid version: ${packageJsonPath}`);
3045
+ }
3046
+ return parsed.version;
3047
+ }
3048
+ function codexCliScriptPath() {
3049
+ return join8(dirname7(bundledCodexPackagePath), "bin", "codex.js");
3050
+ }
3051
+ function parseCodexModelCache(contents, sourcePath) {
3052
+ let parsed;
3053
+ try {
3054
+ parsed = JSON.parse(contents);
3055
+ } catch (error) {
3056
+ throw new Error(`Codex model cache is invalid JSON: ${sourcePath}`, { cause: error });
3057
+ }
3058
+ if (!Array.isArray(parsed.models) || parsed.models.length === 0) {
3059
+ throw new Error(`Codex model cache has no models: ${sourcePath}`);
3060
+ }
3061
+ return parsed;
3062
+ }
3063
+ function readCodexModelCache(cachePath) {
3064
+ const contents = readFileSync7(cachePath, "utf8");
3065
+ return { contents, parsed: parseCodexModelCache(contents, cachePath) };
3066
+ }
3067
+ function readCompatibleCodexModelCache(cachePath) {
3068
+ const cache = readCodexModelCache(cachePath);
3069
+ if (cache.parsed.client_version !== BUNDLED_CODEX_VERSION) {
3070
+ const found = typeof cache.parsed.client_version === "string" ? cache.parsed.client_version : "missing or invalid";
3071
+ throw new Error(`Codex model cache version ${found} does not match Negotium's bundled Codex ${BUNDLED_CODEX_VERSION}: ${cachePath}`);
3072
+ }
3073
+ return cache;
3074
+ }
3075
+ function writePrivateFileAtomic(path, contents) {
3076
+ if (existsSync7(path) && readFileSync7(path, "utf8") === contents)
3077
+ return;
3078
+ const tempPath = `${path}.${process.pid}.${randomUUID3()}.tmp`;
3079
+ try {
3080
+ writeFileSync5(tempPath, contents, { encoding: "utf8", mode: 384 });
3081
+ renameSync4(tempPath, path);
3082
+ chmodSync4(path, 384);
3083
+ } finally {
3084
+ try {
3085
+ unlinkSync7(tempPath);
3086
+ } catch {}
3087
+ }
3088
+ }
3089
+ function bundledCodexModelCachePath(authFilePath) {
3090
+ return join8(dirname7(authFilePath), NEGOTIUM_MODEL_CACHE);
3091
+ }
3092
+ async function bootstrapCodexModelCache(codexHome, cachePath) {
3093
+ const child = spawn2(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
3094
+ env: { ...process.env, CODEX_HOME: codexHome },
3095
+ stdio: ["pipe", "pipe", "pipe"]
3096
+ });
3097
+ await new Promise((resolve7, reject) => {
3098
+ let settled = false;
3099
+ let stdoutBuffer = "";
3100
+ let stderr = "";
3101
+ const timer = setTimeout(() => finish(new Error("timed out while refreshing the Codex model catalog")), 15000);
3102
+ const finish = (error) => {
3103
+ if (settled)
3104
+ return;
3105
+ settled = true;
3106
+ clearTimeout(timer);
3107
+ try {
3108
+ child.stdin.end();
3109
+ child.kill();
3110
+ } catch {}
3111
+ if (error)
3112
+ reject(error);
3113
+ else if (!existsSync7(cachePath))
3114
+ reject(new Error("Codex did not create its model cache"));
3115
+ else
3116
+ resolve7();
3117
+ };
3118
+ const send = (message) => {
3119
+ child.stdin.write(`${JSON.stringify(message)}
3120
+ `);
3121
+ };
3122
+ child.stderr.on("data", (chunk) => {
3123
+ if (stderr.length < 4096)
3124
+ stderr += String(chunk);
3125
+ });
3126
+ child.on("error", (error) => finish(error));
3127
+ child.on("exit", (code, signal) => {
3128
+ if (!settled) {
3129
+ finish(new Error(`Codex model catalog refresh exited with ${signal ? `signal ${signal}` : `code ${code ?? 1}`}${stderr.trim() ? `: ${stderr.trim()}` : ""}`));
3130
+ }
3131
+ });
3132
+ child.stdout.on("data", (chunk) => {
3133
+ stdoutBuffer += String(chunk);
3134
+ for (;; ) {
3135
+ const newline = stdoutBuffer.indexOf(`
3136
+ `);
3137
+ if (newline < 0)
3138
+ break;
3139
+ const line = stdoutBuffer.slice(0, newline);
3140
+ stdoutBuffer = stdoutBuffer.slice(newline + 1);
3141
+ let message;
3142
+ try {
3143
+ message = JSON.parse(line);
3144
+ } catch {
3145
+ continue;
3146
+ }
3147
+ if (message.id === 1) {
3148
+ if (message.error) {
3149
+ finish(new Error(message.error.message || "Codex initialization failed"));
3150
+ return;
3151
+ }
3152
+ send({ method: "initialized" });
3153
+ send({ id: 2, method: "model/list", params: { includeHidden: true } });
3154
+ } else if (message.id === 2) {
3155
+ if (message.error) {
3156
+ finish(new Error(message.error.message || "Codex model listing failed"));
3157
+ } else {
3158
+ finish();
3159
+ }
3160
+ return;
3161
+ }
3162
+ }
3163
+ });
3164
+ send({
3165
+ id: 1,
3166
+ method: "initialize",
3167
+ params: {
3168
+ clientInfo: { name: "negotium", version: NEGOTIUM_VERSION },
3169
+ capabilities: { experimentalApi: true }
3170
+ }
3171
+ });
3172
+ });
3173
+ }
3174
+ async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
3175
+ const sourceHome = dirname7(authFilePath);
3176
+ const isolatedHome = mkdtempSync(join8(tmpdir(), "negotium-codex-models-"));
3177
+ const isolatedCachePath = join8(isolatedHome, "models_cache.json");
3178
+ try {
3179
+ const isolatedAuthPath = join8(isolatedHome, "auth.json");
3180
+ copyFileSync(authFilePath, isolatedAuthPath);
3181
+ chmodSync4(isolatedAuthPath, 384);
3182
+ const sourceConfigPath = join8(sourceHome, "config.toml");
3183
+ if (existsSync7(sourceConfigPath)) {
3184
+ const isolatedConfigPath = join8(isolatedHome, "config.toml");
3185
+ copyFileSync(sourceConfigPath, isolatedConfigPath);
3186
+ chmodSync4(isolatedConfigPath, 384);
3187
+ }
3188
+ await bootstrap(isolatedHome, isolatedCachePath);
3189
+ return readCompatibleCodexModelCache(isolatedCachePath).contents;
3190
+ } finally {
3191
+ rmSync(isolatedHome, { recursive: true, force: true });
3192
+ }
3193
+ }
3194
+ async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
3195
+ const codexHome = dirname7(authFilePath);
3196
+ const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
3197
+ if (configuredCachePath) {
3198
+ if (!existsSync7(configuredCachePath)) {
3199
+ throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);
3200
+ }
3201
+ readCompatibleCodexModelCache(configuredCachePath);
3202
+ return configuredCachePath;
3203
+ }
3204
+ const bundledCachePath = bundledCodexModelCachePath(authFilePath);
3205
+ const sharedCachePath = join8(codexHome, "models_cache.json");
3206
+ if (existsSync7(sharedCachePath)) {
3207
+ try {
3208
+ const shared = readCompatibleCodexModelCache(sharedCachePath);
3209
+ writePrivateFileAtomic(bundledCachePath, shared.contents);
3210
+ return bundledCachePath;
3211
+ } catch {}
3212
+ }
3213
+ if (existsSync7(bundledCachePath)) {
3214
+ try {
3215
+ readCompatibleCodexModelCache(bundledCachePath);
3216
+ return bundledCachePath;
3217
+ } catch {}
3218
+ }
3219
+ const refreshedContents = await bootstrapIsolatedCodexModelCache(authFilePath, bootstrap);
3220
+ writePrivateFileAtomic(bundledCachePath, refreshedContents);
3221
+ return bundledCachePath;
3222
+ }
3223
+ function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
3224
+ const codexHome = dirname7(authFilePath);
3225
+ const outputPath = join8(codexHome, NEGOTIUM_MODEL_CATALOG);
3226
+ const parsed = readCodexModelCache(sourcePath).parsed;
3227
+ const models = parsed.models.map((model, index) => {
3228
+ if (!model || typeof model !== "object" || Array.isArray(model)) {
3229
+ throw new Error(`Codex model cache entry ${index} is invalid: ${sourcePath}`);
3230
+ }
3231
+ return { ...model, multi_agent_version: "disabled" };
3232
+ });
3233
+ const contents = `${JSON.stringify({ models }, null, 2)}
3234
+ `;
3235
+ writePrivateFileAtomic(outputPath, contents);
3236
+ return outputPath;
3237
+ }
3238
+ var moduleRequire, codexSdkPackagePath, codexSdkRequire, bundledCodexPackagePath, BUNDLED_CODEX_VERSION, SAFE_BUNDLED_CODEX_VERSION, NEGOTIUM_MODEL_CACHE, NEGOTIUM_MODEL_CATALOG;
3239
+ var init_codex_native_multi_agent = __esm(() => {
3240
+ moduleRequire = createRequire2(import.meta.url);
3241
+ codexSdkPackagePath = moduleRequire.resolve("@openai/codex-sdk/package.json");
3242
+ codexSdkRequire = createRequire2(codexSdkPackagePath);
3243
+ bundledCodexPackagePath = codexSdkRequire.resolve("@openai/codex/package.json");
3244
+ BUNDLED_CODEX_VERSION = readPackageVersion(bundledCodexPackagePath);
3245
+ SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/g, "_");
3246
+ NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
3247
+ NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
3248
+ });
3249
+
3250
3250
  // ../../packages/core/src/agents/codex-app-server.ts
3251
+ var exports_codex_app_server = {};
3252
+ __export(exports_codex_app_server, {
3253
+ forkCodexSession: () => forkCodexSession,
3254
+ createCodexAppServerForker: () => createCodexAppServerForker
3255
+ });
3251
3256
  import { spawn as spawn3 } from "child_process";
3252
3257
  function createCodexAppServerForker(host) {
3253
3258
  return async (parentThreadId) => {
@@ -3367,7 +3372,6 @@ import { existsSync as existsSync8, unlinkSync as unlinkSync8 } from "fs";
3367
3372
  import { join as join9 } from "path";
3368
3373
  var VALID_EFFORTS2, codexRegistry, codexRegistryOperations;
3369
3374
  var init_codex_registry = __esm(async () => {
3370
- await init_codex_app_server();
3371
3375
  await init_execution_host();
3372
3376
  await init_codex();
3373
3377
  init_logger();
@@ -3402,7 +3406,8 @@ var init_codex_registry = __esm(async () => {
3402
3406
  return { sessionId: threadId, rolloutPath };
3403
3407
  },
3404
3408
  async forkSession({ parentSessionId }) {
3405
- return await forkCodexSession(parentSessionId);
3409
+ const { forkCodexSession: forkCodexSession2 } = await init_codex_app_server().then(() => exports_codex_app_server);
3410
+ return await forkCodexSession2(parentSessionId);
3406
3411
  },
3407
3412
  async cleanupRollouts({ sessionIds }) {
3408
3413
  if (sessionIds.length === 0)
@@ -21542,4 +21547,4 @@ export {
21542
21547
  createAgentHealthMcpServer
21543
21548
  };
21544
21549
 
21545
- //# debugId=DA8078449BC2B6E364756E2164756E21
21550
+ //# debugId=17A2FD732002839B64756E2164756E21