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.
@@ -2445,246 +2445,17 @@ var init_claude_registry = __esm(() => {
2445
2445
  };
2446
2446
  });
2447
2447
 
2448
- // ../../packages/core/src/version.ts
2449
- var NEGOTIUM_VERSION = "0.6.1";
2450
-
2451
- // ../../packages/core/src/agents/codex-native-multi-agent.ts
2452
- import { spawn as spawn2 } from "child_process";
2453
- import { randomUUID as randomUUID2 } from "crypto";
2454
- import {
2455
- chmodSync as chmodSync3,
2456
- copyFileSync,
2457
- existsSync as existsSync4,
2458
- mkdtempSync,
2459
- readFileSync as readFileSync4,
2460
- renameSync as renameSync3,
2461
- rmSync,
2462
- unlinkSync as unlinkSync4,
2463
- writeFileSync as writeFileSync4
2464
- } from "fs";
2465
- import { createRequire as createRequire2 } from "module";
2466
- import { tmpdir } from "os";
2467
- import { dirname as dirname5, join as join6 } from "path";
2468
- function readPackageVersion(packageJsonPath) {
2469
- const parsed = JSON.parse(readFileSync4(packageJsonPath, "utf8"));
2470
- if (typeof parsed.version !== "string" || !parsed.version.trim()) {
2471
- throw new Error(`Codex package has no valid version: ${packageJsonPath}`);
2472
- }
2473
- return parsed.version;
2474
- }
2475
- function codexCliScriptPath() {
2476
- return join6(dirname5(bundledCodexPackagePath), "bin", "codex.js");
2477
- }
2478
- function parseCodexModelCache(contents, sourcePath) {
2479
- let parsed;
2480
- try {
2481
- parsed = JSON.parse(contents);
2482
- } catch (error) {
2483
- throw new Error(`Codex model cache is invalid JSON: ${sourcePath}`, { cause: error });
2484
- }
2485
- if (!Array.isArray(parsed.models) || parsed.models.length === 0) {
2486
- throw new Error(`Codex model cache has no models: ${sourcePath}`);
2487
- }
2488
- return parsed;
2489
- }
2490
- function readCodexModelCache(cachePath) {
2491
- const contents = readFileSync4(cachePath, "utf8");
2492
- return { contents, parsed: parseCodexModelCache(contents, cachePath) };
2493
- }
2494
- function readCompatibleCodexModelCache(cachePath) {
2495
- const cache = readCodexModelCache(cachePath);
2496
- if (cache.parsed.client_version !== BUNDLED_CODEX_VERSION) {
2497
- const found = typeof cache.parsed.client_version === "string" ? cache.parsed.client_version : "missing or invalid";
2498
- throw new Error(`Codex model cache version ${found} does not match Negotium's bundled Codex ${BUNDLED_CODEX_VERSION}: ${cachePath}`);
2499
- }
2500
- return cache;
2501
- }
2502
- function writePrivateFileAtomic(path, contents) {
2503
- if (existsSync4(path) && readFileSync4(path, "utf8") === contents)
2504
- return;
2505
- const tempPath = `${path}.${process.pid}.${randomUUID2()}.tmp`;
2506
- try {
2507
- writeFileSync4(tempPath, contents, { encoding: "utf8", mode: 384 });
2508
- renameSync3(tempPath, path);
2509
- chmodSync3(path, 384);
2510
- } finally {
2511
- try {
2512
- unlinkSync4(tempPath);
2513
- } catch {}
2514
- }
2515
- }
2516
- function bundledCodexModelCachePath(authFilePath) {
2517
- return join6(dirname5(authFilePath), NEGOTIUM_MODEL_CACHE);
2518
- }
2519
- async function bootstrapCodexModelCache(codexHome, cachePath) {
2520
- const child = spawn2(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
2521
- env: { ...process.env, CODEX_HOME: codexHome },
2522
- stdio: ["pipe", "pipe", "pipe"]
2523
- });
2524
- await new Promise((resolve5, reject) => {
2525
- let settled = false;
2526
- let stdoutBuffer = "";
2527
- let stderr = "";
2528
- const timer = setTimeout(() => finish(new Error("timed out while refreshing the Codex model catalog")), 15000);
2529
- const finish = (error) => {
2530
- if (settled)
2531
- return;
2532
- settled = true;
2533
- clearTimeout(timer);
2534
- try {
2535
- child.stdin.end();
2536
- child.kill();
2537
- } catch {}
2538
- if (error)
2539
- reject(error);
2540
- else if (!existsSync4(cachePath))
2541
- reject(new Error("Codex did not create its model cache"));
2542
- else
2543
- resolve5();
2544
- };
2545
- const send = (message) => {
2546
- child.stdin.write(`${JSON.stringify(message)}
2547
- `);
2548
- };
2549
- child.stderr.on("data", (chunk) => {
2550
- if (stderr.length < 4096)
2551
- stderr += String(chunk);
2552
- });
2553
- child.on("error", (error) => finish(error));
2554
- child.on("exit", (code, signal) => {
2555
- if (!settled) {
2556
- finish(new Error(`Codex model catalog refresh exited with ${signal ? `signal ${signal}` : `code ${code ?? 1}`}${stderr.trim() ? `: ${stderr.trim()}` : ""}`));
2557
- }
2558
- });
2559
- child.stdout.on("data", (chunk) => {
2560
- stdoutBuffer += String(chunk);
2561
- for (;; ) {
2562
- const newline = stdoutBuffer.indexOf(`
2563
- `);
2564
- if (newline < 0)
2565
- break;
2566
- const line = stdoutBuffer.slice(0, newline);
2567
- stdoutBuffer = stdoutBuffer.slice(newline + 1);
2568
- let message;
2569
- try {
2570
- message = JSON.parse(line);
2571
- } catch {
2572
- continue;
2573
- }
2574
- if (message.id === 1) {
2575
- if (message.error) {
2576
- finish(new Error(message.error.message || "Codex initialization failed"));
2577
- return;
2578
- }
2579
- send({ method: "initialized" });
2580
- send({ id: 2, method: "model/list", params: { includeHidden: true } });
2581
- } else if (message.id === 2) {
2582
- if (message.error) {
2583
- finish(new Error(message.error.message || "Codex model listing failed"));
2584
- } else {
2585
- finish();
2586
- }
2587
- return;
2588
- }
2589
- }
2590
- });
2591
- send({
2592
- id: 1,
2593
- method: "initialize",
2594
- params: {
2595
- clientInfo: { name: "negotium", version: NEGOTIUM_VERSION },
2596
- capabilities: { experimentalApi: true }
2597
- }
2598
- });
2599
- });
2600
- }
2601
- async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
2602
- const sourceHome = dirname5(authFilePath);
2603
- const isolatedHome = mkdtempSync(join6(tmpdir(), "negotium-codex-models-"));
2604
- const isolatedCachePath = join6(isolatedHome, "models_cache.json");
2605
- try {
2606
- const isolatedAuthPath = join6(isolatedHome, "auth.json");
2607
- copyFileSync(authFilePath, isolatedAuthPath);
2608
- chmodSync3(isolatedAuthPath, 384);
2609
- const sourceConfigPath = join6(sourceHome, "config.toml");
2610
- if (existsSync4(sourceConfigPath)) {
2611
- const isolatedConfigPath = join6(isolatedHome, "config.toml");
2612
- copyFileSync(sourceConfigPath, isolatedConfigPath);
2613
- chmodSync3(isolatedConfigPath, 384);
2614
- }
2615
- await bootstrap(isolatedHome, isolatedCachePath);
2616
- return readCompatibleCodexModelCache(isolatedCachePath).contents;
2617
- } finally {
2618
- rmSync(isolatedHome, { recursive: true, force: true });
2619
- }
2620
- }
2621
- async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
2622
- const codexHome = dirname5(authFilePath);
2623
- const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
2624
- if (configuredCachePath) {
2625
- if (!existsSync4(configuredCachePath)) {
2626
- throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);
2627
- }
2628
- readCompatibleCodexModelCache(configuredCachePath);
2629
- return configuredCachePath;
2630
- }
2631
- const bundledCachePath = bundledCodexModelCachePath(authFilePath);
2632
- const sharedCachePath = join6(codexHome, "models_cache.json");
2633
- if (existsSync4(sharedCachePath)) {
2634
- try {
2635
- const shared = readCompatibleCodexModelCache(sharedCachePath);
2636
- writePrivateFileAtomic(bundledCachePath, shared.contents);
2637
- return bundledCachePath;
2638
- } catch {}
2639
- }
2640
- if (existsSync4(bundledCachePath)) {
2641
- try {
2642
- readCompatibleCodexModelCache(bundledCachePath);
2643
- return bundledCachePath;
2644
- } catch {}
2645
- }
2646
- const refreshedContents = await bootstrapIsolatedCodexModelCache(authFilePath, bootstrap);
2647
- writePrivateFileAtomic(bundledCachePath, refreshedContents);
2648
- return bundledCachePath;
2649
- }
2650
- function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
2651
- const codexHome = dirname5(authFilePath);
2652
- const outputPath = join6(codexHome, NEGOTIUM_MODEL_CATALOG);
2653
- const parsed = readCodexModelCache(sourcePath).parsed;
2654
- const models = parsed.models.map((model, index) => {
2655
- if (!model || typeof model !== "object" || Array.isArray(model)) {
2656
- throw new Error(`Codex model cache entry ${index} is invalid: ${sourcePath}`);
2657
- }
2658
- return { ...model, multi_agent_version: "disabled" };
2659
- });
2660
- const contents = `${JSON.stringify({ models }, null, 2)}
2661
- `;
2662
- writePrivateFileAtomic(outputPath, contents);
2663
- return outputPath;
2664
- }
2665
- var moduleRequire, codexSdkPackagePath, codexSdkRequire, bundledCodexPackagePath, BUNDLED_CODEX_VERSION, SAFE_BUNDLED_CODEX_VERSION, NEGOTIUM_MODEL_CACHE, NEGOTIUM_MODEL_CATALOG;
2666
- var init_codex_native_multi_agent = __esm(() => {
2667
- moduleRequire = createRequire2(import.meta.url);
2668
- codexSdkPackagePath = moduleRequire.resolve("@openai/codex-sdk/package.json");
2669
- codexSdkRequire = createRequire2(codexSdkPackagePath);
2670
- bundledCodexPackagePath = codexSdkRequire.resolve("@openai/codex/package.json");
2671
- BUNDLED_CODEX_VERSION = readPackageVersion(bundledCodexPackagePath);
2672
- SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/g, "_");
2673
- NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
2674
- NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
2675
- });
2676
-
2677
2448
  // ../../packages/core/src/agents/rollout/codex.ts
2678
2449
  import { randomBytes as randomBytes4 } from "crypto";
2679
- import { existsSync as existsSync5, readFileSync as readFileSync5, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync5 } from "fs";
2680
- import { basename, dirname as dirname6, join as join7, resolve as resolve5 } from "path";
2450
+ import { existsSync as existsSync4, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync4 } from "fs";
2451
+ import { basename, dirname as dirname5, join as join6, resolve as resolve5 } from "path";
2681
2452
  function codexSessionsDir() {
2682
- return join7(hostedCodexHomePath(), "sessions");
2453
+ return join6(hostedCodexHomePath(), "sessions");
2683
2454
  }
2684
2455
  function loadCodexShell() {
2685
2456
  if (_shellCache)
2686
2457
  return _shellCache;
2687
- const raw = readFileSync5(join7(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
2458
+ const raw = readFileSync4(join6(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
2688
2459
  const lines = parseJsonlText(raw);
2689
2460
  if (lines.length < 5) {
2690
2461
  throw new Error(`loadCodexShell: expected >=5 entries in codex-shell.jsonl, got ${lines.length}`);
@@ -2751,8 +2522,8 @@ function codexRolloutPath(threadId, fallback) {
2751
2522
  const hh = String(createdAt.getHours()).padStart(2, "0");
2752
2523
  const min = String(createdAt.getMinutes()).padStart(2, "0");
2753
2524
  const ss = String(createdAt.getSeconds()).padStart(2, "0");
2754
- const dir = join7(codexSessionsDir(), yyyy, mm, dd);
2755
- return join7(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
2525
+ const dir = join6(codexSessionsDir(), yyyy, mm, dd);
2526
+ return join6(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
2756
2527
  }
2757
2528
  function canonicalFilePath(path) {
2758
2529
  const absolute = resolve5(path);
@@ -2760,7 +2531,7 @@ function canonicalFilePath(path) {
2760
2531
  return realpathSync2(absolute);
2761
2532
  } catch {
2762
2533
  try {
2763
- return join7(realpathSync2(dirname6(absolute)), basename(absolute));
2534
+ return join6(realpathSync2(dirname5(absolute)), basename(absolute));
2764
2535
  } catch {
2765
2536
  return absolute;
2766
2537
  }
@@ -2870,7 +2641,7 @@ function readCodexPatchCallIds(threadId) {
2870
2641
  if (!path)
2871
2642
  return [];
2872
2643
  try {
2873
- return extractCodexPatchCallIds(readFileSync5(path, "utf8"));
2644
+ return extractCodexPatchCallIds(readFileSync4(path, "utf8"));
2874
2645
  } catch (error) {
2875
2646
  logger.debug({ error, threadId }, "codex patch ids: rollout read failed");
2876
2647
  return [];
@@ -2881,7 +2652,7 @@ function readLatestCodexPatchPreview(threadId, expectedPaths, consumedCallIds =
2881
2652
  if (!path)
2882
2653
  return;
2883
2654
  try {
2884
- return extractLatestCodexPatchPreview(readFileSync5(path, "utf8"), expectedPaths, consumedCallIds, expectedCallId);
2655
+ return extractLatestCodexPatchPreview(readFileSync4(path, "utf8"), expectedPaths, consumedCallIds, expectedCallId);
2885
2656
  } catch (error) {
2886
2657
  logger.debug({ error, threadId }, "codex patch preview: rollout read failed");
2887
2658
  return;
@@ -2939,7 +2710,7 @@ function readLatestCodexContextUsage(threadId) {
2939
2710
  if (!path)
2940
2711
  return;
2941
2712
  try {
2942
- return extractLatestCodexContextUsage(readFileSync5(path, "utf8"));
2713
+ return extractLatestCodexContextUsage(readFileSync4(path, "utf8"));
2943
2714
  } catch (error) {
2944
2715
  logger.debug({ error, threadId }, "codex context usage: rollout read failed");
2945
2716
  return;
@@ -2950,7 +2721,7 @@ function readLatestCodexTokenTotals(threadId) {
2950
2721
  if (!path)
2951
2722
  return;
2952
2723
  try {
2953
- return extractLatestCodexTokenTotals(readFileSync5(path, "utf8"));
2724
+ return extractLatestCodexTokenTotals(readFileSync4(path, "utf8"));
2954
2725
  } catch (error) {
2955
2726
  logger.debug({ error, threadId }, "codex token totals: rollout read failed");
2956
2727
  return;
@@ -2961,7 +2732,7 @@ function migrateCodexRolloutNativeMultiAgentMetadata(threadId) {
2961
2732
  if (!path)
2962
2733
  return false;
2963
2734
  try {
2964
- const entries = parseJsonlText(readFileSync5(path, "utf8"));
2735
+ const entries = parseJsonlText(readFileSync4(path, "utf8"));
2965
2736
  let changed = false;
2966
2737
  for (const entry of entries) {
2967
2738
  if (entry.type !== "session_meta" && entry.type !== "turn_context")
@@ -2990,19 +2761,19 @@ function latestCodexRolloutPath(threadId) {
2990
2761
  try {
2991
2762
  if (buckets) {
2992
2763
  for (const bucket of buckets) {
2993
- const dir = join7(sessionsDir, bucket);
2994
- if (!existsSync5(dir))
2764
+ const dir = join6(sessionsDir, bucket);
2765
+ if (!existsSync4(dir))
2995
2766
  continue;
2996
2767
  const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
2997
2768
  for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
2998
- candidates.push(join7(dir, rel));
2769
+ candidates.push(join6(dir, rel));
2999
2770
  }
3000
2771
  }
3001
2772
  }
3002
2773
  if (candidates.length === 0) {
3003
2774
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
3004
2775
  for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
3005
- candidates.push(join7(sessionsDir, rel));
2776
+ candidates.push(join6(sessionsDir, rel));
3006
2777
  }
3007
2778
  }
3008
2779
  return candidates.sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs)[0];
@@ -3123,15 +2894,15 @@ function sweepPriorRolloutsForThread(threadId) {
3123
2894
  return;
3124
2895
  }
3125
2896
  for (const bucket of buckets) {
3126
- const dir = join7(sessionsDir, bucket);
3127
- if (!existsSync5(dir))
2897
+ const dir = join6(sessionsDir, bucket);
2898
+ if (!existsSync4(dir))
3128
2899
  continue;
3129
2900
  try {
3130
2901
  const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
3131
2902
  for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
3132
- const fullPath = join7(dir, rel);
2903
+ const fullPath = join6(dir, rel);
3133
2904
  try {
3134
- unlinkSync5(fullPath);
2905
+ unlinkSync4(fullPath);
3135
2906
  } catch (e) {
3136
2907
  if (e?.code !== "ENOENT") {
3137
2908
  logger.warn({ err: e, path: fullPath }, "writeCodexRollout: prior-rollout unlink failed (continuing)");
@@ -3147,9 +2918,9 @@ function sweepPriorRolloutsFullTree(threadId, sessionsDir) {
3147
2918
  try {
3148
2919
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
3149
2920
  for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
3150
- const fullPath = join7(sessionsDir, rel);
2921
+ const fullPath = join6(sessionsDir, rel);
3151
2922
  try {
3152
- unlinkSync5(fullPath);
2923
+ unlinkSync4(fullPath);
3153
2924
  } catch (e) {
3154
2925
  if (e?.code !== "ENOENT") {
3155
2926
  logger.warn({ err: e, path: fullPath }, "writeCodexRollout: prior-rollout unlink failed (continuing)");
@@ -3208,7 +2979,241 @@ var init_codex = __esm(async () => {
3208
2979
  init_logger();
3209
2980
  });
3210
2981
 
2982
+ // ../../packages/core/src/version.ts
2983
+ var NEGOTIUM_VERSION = "0.6.4";
2984
+
2985
+ // ../../packages/core/src/agents/codex-native-multi-agent.ts
2986
+ import { spawn as spawn2 } from "child_process";
2987
+ import { randomUUID as randomUUID2 } from "crypto";
2988
+ import {
2989
+ chmodSync as chmodSync3,
2990
+ copyFileSync,
2991
+ existsSync as existsSync5,
2992
+ mkdtempSync,
2993
+ readFileSync as readFileSync5,
2994
+ renameSync as renameSync3,
2995
+ rmSync,
2996
+ unlinkSync as unlinkSync5,
2997
+ writeFileSync as writeFileSync4
2998
+ } from "fs";
2999
+ import { createRequire as createRequire2 } from "module";
3000
+ import { tmpdir } from "os";
3001
+ import { dirname as dirname6, join as join7 } from "path";
3002
+ function readPackageVersion(packageJsonPath) {
3003
+ const parsed = JSON.parse(readFileSync5(packageJsonPath, "utf8"));
3004
+ if (typeof parsed.version !== "string" || !parsed.version.trim()) {
3005
+ throw new Error(`Codex package has no valid version: ${packageJsonPath}`);
3006
+ }
3007
+ return parsed.version;
3008
+ }
3009
+ function codexCliScriptPath() {
3010
+ return join7(dirname6(bundledCodexPackagePath), "bin", "codex.js");
3011
+ }
3012
+ function parseCodexModelCache(contents, sourcePath) {
3013
+ let parsed;
3014
+ try {
3015
+ parsed = JSON.parse(contents);
3016
+ } catch (error) {
3017
+ throw new Error(`Codex model cache is invalid JSON: ${sourcePath}`, { cause: error });
3018
+ }
3019
+ if (!Array.isArray(parsed.models) || parsed.models.length === 0) {
3020
+ throw new Error(`Codex model cache has no models: ${sourcePath}`);
3021
+ }
3022
+ return parsed;
3023
+ }
3024
+ function readCodexModelCache(cachePath) {
3025
+ const contents = readFileSync5(cachePath, "utf8");
3026
+ return { contents, parsed: parseCodexModelCache(contents, cachePath) };
3027
+ }
3028
+ function readCompatibleCodexModelCache(cachePath) {
3029
+ const cache = readCodexModelCache(cachePath);
3030
+ if (cache.parsed.client_version !== BUNDLED_CODEX_VERSION) {
3031
+ const found = typeof cache.parsed.client_version === "string" ? cache.parsed.client_version : "missing or invalid";
3032
+ throw new Error(`Codex model cache version ${found} does not match Negotium's bundled Codex ${BUNDLED_CODEX_VERSION}: ${cachePath}`);
3033
+ }
3034
+ return cache;
3035
+ }
3036
+ function writePrivateFileAtomic(path, contents) {
3037
+ if (existsSync5(path) && readFileSync5(path, "utf8") === contents)
3038
+ return;
3039
+ const tempPath = `${path}.${process.pid}.${randomUUID2()}.tmp`;
3040
+ try {
3041
+ writeFileSync4(tempPath, contents, { encoding: "utf8", mode: 384 });
3042
+ renameSync3(tempPath, path);
3043
+ chmodSync3(path, 384);
3044
+ } finally {
3045
+ try {
3046
+ unlinkSync5(tempPath);
3047
+ } catch {}
3048
+ }
3049
+ }
3050
+ function bundledCodexModelCachePath(authFilePath) {
3051
+ return join7(dirname6(authFilePath), NEGOTIUM_MODEL_CACHE);
3052
+ }
3053
+ async function bootstrapCodexModelCache(codexHome, cachePath) {
3054
+ const child = spawn2(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
3055
+ env: { ...process.env, CODEX_HOME: codexHome },
3056
+ stdio: ["pipe", "pipe", "pipe"]
3057
+ });
3058
+ await new Promise((resolve6, reject) => {
3059
+ let settled = false;
3060
+ let stdoutBuffer = "";
3061
+ let stderr = "";
3062
+ const timer = setTimeout(() => finish(new Error("timed out while refreshing the Codex model catalog")), 15000);
3063
+ const finish = (error) => {
3064
+ if (settled)
3065
+ return;
3066
+ settled = true;
3067
+ clearTimeout(timer);
3068
+ try {
3069
+ child.stdin.end();
3070
+ child.kill();
3071
+ } catch {}
3072
+ if (error)
3073
+ reject(error);
3074
+ else if (!existsSync5(cachePath))
3075
+ reject(new Error("Codex did not create its model cache"));
3076
+ else
3077
+ resolve6();
3078
+ };
3079
+ const send = (message) => {
3080
+ child.stdin.write(`${JSON.stringify(message)}
3081
+ `);
3082
+ };
3083
+ child.stderr.on("data", (chunk) => {
3084
+ if (stderr.length < 4096)
3085
+ stderr += String(chunk);
3086
+ });
3087
+ child.on("error", (error) => finish(error));
3088
+ child.on("exit", (code, signal) => {
3089
+ if (!settled) {
3090
+ finish(new Error(`Codex model catalog refresh exited with ${signal ? `signal ${signal}` : `code ${code ?? 1}`}${stderr.trim() ? `: ${stderr.trim()}` : ""}`));
3091
+ }
3092
+ });
3093
+ child.stdout.on("data", (chunk) => {
3094
+ stdoutBuffer += String(chunk);
3095
+ for (;; ) {
3096
+ const newline = stdoutBuffer.indexOf(`
3097
+ `);
3098
+ if (newline < 0)
3099
+ break;
3100
+ const line = stdoutBuffer.slice(0, newline);
3101
+ stdoutBuffer = stdoutBuffer.slice(newline + 1);
3102
+ let message;
3103
+ try {
3104
+ message = JSON.parse(line);
3105
+ } catch {
3106
+ continue;
3107
+ }
3108
+ if (message.id === 1) {
3109
+ if (message.error) {
3110
+ finish(new Error(message.error.message || "Codex initialization failed"));
3111
+ return;
3112
+ }
3113
+ send({ method: "initialized" });
3114
+ send({ id: 2, method: "model/list", params: { includeHidden: true } });
3115
+ } else if (message.id === 2) {
3116
+ if (message.error) {
3117
+ finish(new Error(message.error.message || "Codex model listing failed"));
3118
+ } else {
3119
+ finish();
3120
+ }
3121
+ return;
3122
+ }
3123
+ }
3124
+ });
3125
+ send({
3126
+ id: 1,
3127
+ method: "initialize",
3128
+ params: {
3129
+ clientInfo: { name: "negotium", version: NEGOTIUM_VERSION },
3130
+ capabilities: { experimentalApi: true }
3131
+ }
3132
+ });
3133
+ });
3134
+ }
3135
+ async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
3136
+ const sourceHome = dirname6(authFilePath);
3137
+ const isolatedHome = mkdtempSync(join7(tmpdir(), "negotium-codex-models-"));
3138
+ const isolatedCachePath = join7(isolatedHome, "models_cache.json");
3139
+ try {
3140
+ const isolatedAuthPath = join7(isolatedHome, "auth.json");
3141
+ copyFileSync(authFilePath, isolatedAuthPath);
3142
+ chmodSync3(isolatedAuthPath, 384);
3143
+ const sourceConfigPath = join7(sourceHome, "config.toml");
3144
+ if (existsSync5(sourceConfigPath)) {
3145
+ const isolatedConfigPath = join7(isolatedHome, "config.toml");
3146
+ copyFileSync(sourceConfigPath, isolatedConfigPath);
3147
+ chmodSync3(isolatedConfigPath, 384);
3148
+ }
3149
+ await bootstrap(isolatedHome, isolatedCachePath);
3150
+ return readCompatibleCodexModelCache(isolatedCachePath).contents;
3151
+ } finally {
3152
+ rmSync(isolatedHome, { recursive: true, force: true });
3153
+ }
3154
+ }
3155
+ async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
3156
+ const codexHome = dirname6(authFilePath);
3157
+ const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
3158
+ if (configuredCachePath) {
3159
+ if (!existsSync5(configuredCachePath)) {
3160
+ throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);
3161
+ }
3162
+ readCompatibleCodexModelCache(configuredCachePath);
3163
+ return configuredCachePath;
3164
+ }
3165
+ const bundledCachePath = bundledCodexModelCachePath(authFilePath);
3166
+ const sharedCachePath = join7(codexHome, "models_cache.json");
3167
+ if (existsSync5(sharedCachePath)) {
3168
+ try {
3169
+ const shared = readCompatibleCodexModelCache(sharedCachePath);
3170
+ writePrivateFileAtomic(bundledCachePath, shared.contents);
3171
+ return bundledCachePath;
3172
+ } catch {}
3173
+ }
3174
+ if (existsSync5(bundledCachePath)) {
3175
+ try {
3176
+ readCompatibleCodexModelCache(bundledCachePath);
3177
+ return bundledCachePath;
3178
+ } catch {}
3179
+ }
3180
+ const refreshedContents = await bootstrapIsolatedCodexModelCache(authFilePath, bootstrap);
3181
+ writePrivateFileAtomic(bundledCachePath, refreshedContents);
3182
+ return bundledCachePath;
3183
+ }
3184
+ function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
3185
+ const codexHome = dirname6(authFilePath);
3186
+ const outputPath = join7(codexHome, NEGOTIUM_MODEL_CATALOG);
3187
+ const parsed = readCodexModelCache(sourcePath).parsed;
3188
+ const models = parsed.models.map((model, index) => {
3189
+ if (!model || typeof model !== "object" || Array.isArray(model)) {
3190
+ throw new Error(`Codex model cache entry ${index} is invalid: ${sourcePath}`);
3191
+ }
3192
+ return { ...model, multi_agent_version: "disabled" };
3193
+ });
3194
+ const contents = `${JSON.stringify({ models }, null, 2)}
3195
+ `;
3196
+ writePrivateFileAtomic(outputPath, contents);
3197
+ return outputPath;
3198
+ }
3199
+ var moduleRequire, codexSdkPackagePath, codexSdkRequire, bundledCodexPackagePath, BUNDLED_CODEX_VERSION, SAFE_BUNDLED_CODEX_VERSION, NEGOTIUM_MODEL_CACHE, NEGOTIUM_MODEL_CATALOG;
3200
+ var init_codex_native_multi_agent = __esm(() => {
3201
+ moduleRequire = createRequire2(import.meta.url);
3202
+ codexSdkPackagePath = moduleRequire.resolve("@openai/codex-sdk/package.json");
3203
+ codexSdkRequire = createRequire2(codexSdkPackagePath);
3204
+ bundledCodexPackagePath = codexSdkRequire.resolve("@openai/codex/package.json");
3205
+ BUNDLED_CODEX_VERSION = readPackageVersion(bundledCodexPackagePath);
3206
+ SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/g, "_");
3207
+ NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
3208
+ NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
3209
+ });
3210
+
3211
3211
  // ../../packages/core/src/agents/codex-app-server.ts
3212
+ var exports_codex_app_server = {};
3213
+ __export(exports_codex_app_server, {
3214
+ forkCodexSession: () => forkCodexSession,
3215
+ createCodexAppServerForker: () => createCodexAppServerForker
3216
+ });
3212
3217
  import { spawn as spawn3 } from "child_process";
3213
3218
  function createCodexAppServerForker(host) {
3214
3219
  return async (parentThreadId) => {
@@ -3328,7 +3333,6 @@ import { existsSync as existsSync6, unlinkSync as unlinkSync6 } from "fs";
3328
3333
  import { join as join8 } from "path";
3329
3334
  var VALID_EFFORTS2, codexRegistry, codexRegistryOperations;
3330
3335
  var init_codex_registry = __esm(async () => {
3331
- await init_codex_app_server();
3332
3336
  await init_execution_host();
3333
3337
  await init_codex();
3334
3338
  init_logger();
@@ -3363,7 +3367,8 @@ var init_codex_registry = __esm(async () => {
3363
3367
  return { sessionId: threadId, rolloutPath };
3364
3368
  },
3365
3369
  async forkSession({ parentSessionId }) {
3366
- return await forkCodexSession(parentSessionId);
3370
+ const { forkCodexSession: forkCodexSession2 } = await init_codex_app_server().then(() => exports_codex_app_server);
3371
+ return await forkCodexSession2(parentSessionId);
3367
3372
  },
3368
3373
  async cleanupRollouts({ sessionIds }) {
3369
3374
  if (sessionIds.length === 0)
@@ -19289,4 +19294,4 @@ export {
19289
19294
  DEFAULT_SELF_CONFIG_PRODUCT
19290
19295
  };
19291
19296
 
19292
- //# debugId=03CA2F824FB8358C64756E2164756E21
19297
+ //# debugId=6BFDBF463059259E64756E2164756E21