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.
package/dist/main.js CHANGED
@@ -1873,239 +1873,6 @@ var init_claude_registry = __esm(() => {
1873
1873
  };
1874
1874
  });
1875
1875
 
1876
- // ../../packages/core/src/version.ts
1877
- var exports_version = {};
1878
- __export(exports_version, {
1879
- NEGOTIUM_VERSION: () => NEGOTIUM_VERSION
1880
- });
1881
- var NEGOTIUM_VERSION = "0.6.1";
1882
-
1883
- // ../../packages/core/src/agents/codex-native-multi-agent.ts
1884
- import { spawn } from "child_process";
1885
- import { randomUUID as randomUUID2 } from "crypto";
1886
- import {
1887
- chmodSync as chmodSync3,
1888
- copyFileSync,
1889
- existsSync as existsSync5,
1890
- mkdtempSync,
1891
- readFileSync as readFileSync4,
1892
- renameSync as renameSync3,
1893
- rmSync,
1894
- unlinkSync as unlinkSync4,
1895
- writeFileSync as writeFileSync4
1896
- } from "fs";
1897
- import { createRequire as createRequire2 } from "module";
1898
- import { tmpdir } from "os";
1899
- import { dirname as dirname4, join as join7 } from "path";
1900
- function readPackageVersion(packageJsonPath) {
1901
- const parsed = JSON.parse(readFileSync4(packageJsonPath, "utf8"));
1902
- if (typeof parsed.version !== "string" || !parsed.version.trim()) {
1903
- throw new Error(`Codex package has no valid version: ${packageJsonPath}`);
1904
- }
1905
- return parsed.version;
1906
- }
1907
- function codexCliScriptPath() {
1908
- return join7(dirname4(bundledCodexPackagePath), "bin", "codex.js");
1909
- }
1910
- function parseCodexModelCache(contents, sourcePath) {
1911
- let parsed;
1912
- try {
1913
- parsed = JSON.parse(contents);
1914
- } catch (error) {
1915
- throw new Error(`Codex model cache is invalid JSON: ${sourcePath}`, { cause: error });
1916
- }
1917
- if (!Array.isArray(parsed.models) || parsed.models.length === 0) {
1918
- throw new Error(`Codex model cache has no models: ${sourcePath}`);
1919
- }
1920
- return parsed;
1921
- }
1922
- function readCodexModelCache(cachePath) {
1923
- const contents = readFileSync4(cachePath, "utf8");
1924
- return { contents, parsed: parseCodexModelCache(contents, cachePath) };
1925
- }
1926
- function readCompatibleCodexModelCache(cachePath) {
1927
- const cache = readCodexModelCache(cachePath);
1928
- if (cache.parsed.client_version !== BUNDLED_CODEX_VERSION) {
1929
- const found = typeof cache.parsed.client_version === "string" ? cache.parsed.client_version : "missing or invalid";
1930
- throw new Error(`Codex model cache version ${found} does not match Negotium's bundled Codex ${BUNDLED_CODEX_VERSION}: ${cachePath}`);
1931
- }
1932
- return cache;
1933
- }
1934
- function writePrivateFileAtomic(path, contents) {
1935
- if (existsSync5(path) && readFileSync4(path, "utf8") === contents)
1936
- return;
1937
- const tempPath = `${path}.${process.pid}.${randomUUID2()}.tmp`;
1938
- try {
1939
- writeFileSync4(tempPath, contents, { encoding: "utf8", mode: 384 });
1940
- renameSync3(tempPath, path);
1941
- chmodSync3(path, 384);
1942
- } finally {
1943
- try {
1944
- unlinkSync4(tempPath);
1945
- } catch {}
1946
- }
1947
- }
1948
- function bundledCodexModelCachePath(authFilePath) {
1949
- return join7(dirname4(authFilePath), NEGOTIUM_MODEL_CACHE);
1950
- }
1951
- async function bootstrapCodexModelCache(codexHome, cachePath) {
1952
- const child = spawn(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
1953
- env: { ...process.env, CODEX_HOME: codexHome },
1954
- stdio: ["pipe", "pipe", "pipe"]
1955
- });
1956
- await new Promise((resolve4, reject) => {
1957
- let settled = false;
1958
- let stdoutBuffer = "";
1959
- let stderr = "";
1960
- const timer = setTimeout(() => finish(new Error("timed out while refreshing the Codex model catalog")), 15000);
1961
- const finish = (error) => {
1962
- if (settled)
1963
- return;
1964
- settled = true;
1965
- clearTimeout(timer);
1966
- try {
1967
- child.stdin.end();
1968
- child.kill();
1969
- } catch {}
1970
- if (error)
1971
- reject(error);
1972
- else if (!existsSync5(cachePath))
1973
- reject(new Error("Codex did not create its model cache"));
1974
- else
1975
- resolve4();
1976
- };
1977
- const send = (message) => {
1978
- child.stdin.write(`${JSON.stringify(message)}
1979
- `);
1980
- };
1981
- child.stderr.on("data", (chunk) => {
1982
- if (stderr.length < 4096)
1983
- stderr += String(chunk);
1984
- });
1985
- child.on("error", (error) => finish(error));
1986
- child.on("exit", (code, signal) => {
1987
- if (!settled) {
1988
- finish(new Error(`Codex model catalog refresh exited with ${signal ? `signal ${signal}` : `code ${code ?? 1}`}${stderr.trim() ? `: ${stderr.trim()}` : ""}`));
1989
- }
1990
- });
1991
- child.stdout.on("data", (chunk) => {
1992
- stdoutBuffer += String(chunk);
1993
- for (;; ) {
1994
- const newline = stdoutBuffer.indexOf(`
1995
- `);
1996
- if (newline < 0)
1997
- break;
1998
- const line = stdoutBuffer.slice(0, newline);
1999
- stdoutBuffer = stdoutBuffer.slice(newline + 1);
2000
- let message;
2001
- try {
2002
- message = JSON.parse(line);
2003
- } catch {
2004
- continue;
2005
- }
2006
- if (message.id === 1) {
2007
- if (message.error) {
2008
- finish(new Error(message.error.message || "Codex initialization failed"));
2009
- return;
2010
- }
2011
- send({ method: "initialized" });
2012
- send({ id: 2, method: "model/list", params: { includeHidden: true } });
2013
- } else if (message.id === 2) {
2014
- if (message.error) {
2015
- finish(new Error(message.error.message || "Codex model listing failed"));
2016
- } else {
2017
- finish();
2018
- }
2019
- return;
2020
- }
2021
- }
2022
- });
2023
- send({
2024
- id: 1,
2025
- method: "initialize",
2026
- params: {
2027
- clientInfo: { name: "negotium", version: NEGOTIUM_VERSION },
2028
- capabilities: { experimentalApi: true }
2029
- }
2030
- });
2031
- });
2032
- }
2033
- async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
2034
- const sourceHome = dirname4(authFilePath);
2035
- const isolatedHome = mkdtempSync(join7(tmpdir(), "negotium-codex-models-"));
2036
- const isolatedCachePath = join7(isolatedHome, "models_cache.json");
2037
- try {
2038
- const isolatedAuthPath = join7(isolatedHome, "auth.json");
2039
- copyFileSync(authFilePath, isolatedAuthPath);
2040
- chmodSync3(isolatedAuthPath, 384);
2041
- const sourceConfigPath = join7(sourceHome, "config.toml");
2042
- if (existsSync5(sourceConfigPath)) {
2043
- const isolatedConfigPath = join7(isolatedHome, "config.toml");
2044
- copyFileSync(sourceConfigPath, isolatedConfigPath);
2045
- chmodSync3(isolatedConfigPath, 384);
2046
- }
2047
- await bootstrap(isolatedHome, isolatedCachePath);
2048
- return readCompatibleCodexModelCache(isolatedCachePath).contents;
2049
- } finally {
2050
- rmSync(isolatedHome, { recursive: true, force: true });
2051
- }
2052
- }
2053
- async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
2054
- const codexHome = dirname4(authFilePath);
2055
- const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
2056
- if (configuredCachePath) {
2057
- if (!existsSync5(configuredCachePath)) {
2058
- throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);
2059
- }
2060
- readCompatibleCodexModelCache(configuredCachePath);
2061
- return configuredCachePath;
2062
- }
2063
- const bundledCachePath = bundledCodexModelCachePath(authFilePath);
2064
- const sharedCachePath = join7(codexHome, "models_cache.json");
2065
- if (existsSync5(sharedCachePath)) {
2066
- try {
2067
- const shared = readCompatibleCodexModelCache(sharedCachePath);
2068
- writePrivateFileAtomic(bundledCachePath, shared.contents);
2069
- return bundledCachePath;
2070
- } catch {}
2071
- }
2072
- if (existsSync5(bundledCachePath)) {
2073
- try {
2074
- readCompatibleCodexModelCache(bundledCachePath);
2075
- return bundledCachePath;
2076
- } catch {}
2077
- }
2078
- const refreshedContents = await bootstrapIsolatedCodexModelCache(authFilePath, bootstrap);
2079
- writePrivateFileAtomic(bundledCachePath, refreshedContents);
2080
- return bundledCachePath;
2081
- }
2082
- function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
2083
- const codexHome = dirname4(authFilePath);
2084
- const outputPath = join7(codexHome, NEGOTIUM_MODEL_CATALOG);
2085
- const parsed = readCodexModelCache(sourcePath).parsed;
2086
- const models = parsed.models.map((model, index) => {
2087
- if (!model || typeof model !== "object" || Array.isArray(model)) {
2088
- throw new Error(`Codex model cache entry ${index} is invalid: ${sourcePath}`);
2089
- }
2090
- return { ...model, multi_agent_version: "disabled" };
2091
- });
2092
- const contents = `${JSON.stringify({ models }, null, 2)}
2093
- `;
2094
- writePrivateFileAtomic(outputPath, contents);
2095
- return outputPath;
2096
- }
2097
- var moduleRequire, codexSdkPackagePath, codexSdkRequire, bundledCodexPackagePath, BUNDLED_CODEX_VERSION, SAFE_BUNDLED_CODEX_VERSION, NEGOTIUM_MODEL_CACHE, NEGOTIUM_MODEL_CATALOG;
2098
- var init_codex_native_multi_agent = __esm(() => {
2099
- moduleRequire = createRequire2(import.meta.url);
2100
- codexSdkPackagePath = moduleRequire.resolve("@openai/codex-sdk/package.json");
2101
- codexSdkRequire = createRequire2(codexSdkPackagePath);
2102
- bundledCodexPackagePath = codexSdkRequire.resolve("@openai/codex/package.json");
2103
- BUNDLED_CODEX_VERSION = readPackageVersion(bundledCodexPackagePath);
2104
- SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/g, "_");
2105
- NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
2106
- NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
2107
- });
2108
-
2109
1876
  // ../../packages/core/src/security/sensitive-path.ts
2110
1877
  import { realpathSync } from "fs";
2111
1878
  import { resolve as resolve4 } from "path";
@@ -2437,7 +2204,7 @@ function deriveBgBashContextCapability(runtimeCapability, userId, topic) {
2437
2204
  var init_context = () => {};
2438
2205
 
2439
2206
  // ../../packages/core/src/platform/background-bash/manager.ts
2440
- import { execFileSync as execFileSync4, spawn as spawn2 } from "child_process";
2207
+ import { execFileSync as execFileSync4, spawn } from "child_process";
2441
2208
  import { randomBytes as randomBytes3 } from "crypto";
2442
2209
  function makeBgBashKey(_userId, _topic) {
2443
2210
  return "runtime";
@@ -2464,7 +2231,7 @@ function createBackgroundBashManager(options = {}) {
2464
2231
  const now = options.now ?? Date.now;
2465
2232
  const wait = options.delay ?? delay;
2466
2233
  const portPids = options.portPids ?? defaultPortPids;
2467
- const spawnImpl = options.spawn ?? ((command, args, spawnOptions) => spawn2(command, [...args], spawnOptions));
2234
+ const spawnImpl = options.spawn ?? ((command, args, spawnOptions) => spawn(command, [...args], spawnOptions));
2468
2235
  function contextKey(userId, topic) {
2469
2236
  return `${userId}\x00${topic}`;
2470
2237
  }
@@ -2706,7 +2473,7 @@ var init_mcp_transport = __esm(() => {
2706
2473
  // ../../packages/core/src/platform/mcp-config.ts
2707
2474
  import { accessSync as accessSync2, constants as fsConstants } from "fs";
2708
2475
  import { homedir as homedir6 } from "os";
2709
- import { join as join8 } from "path";
2476
+ import { join as join7 } from "path";
2710
2477
  function buildStdioMcpServer(agent, serverFile, serverArgs, env) {
2711
2478
  if (agent === "codex") {
2712
2479
  return {
@@ -2820,7 +2587,7 @@ function resolveCuaRsBinary(platform2 = process.platform) {
2820
2587
  return null;
2821
2588
  const candidates = [
2822
2589
  envText("NEGOTIUM_CUA_RS_BIN"),
2823
- join8(homedir6(), ".local", "bin", "cua-rs"),
2590
+ join7(homedir6(), ".local", "bin", "cua-rs"),
2824
2591
  "/usr/local/bin/cua-rs"
2825
2592
  ].filter((p) => Boolean(p));
2826
2593
  for (const candidate of candidates) {
@@ -3313,7 +3080,7 @@ var init_mcp_config = __esm(() => {
3313
3080
 
3314
3081
  // ../../packages/core/src/agents/execution-host.ts
3315
3082
  import { AsyncLocalStorage } from "async_hooks";
3316
- import { dirname as dirname5 } from "path";
3083
+ import { dirname as dirname4 } from "path";
3317
3084
  function activeHost() {
3318
3085
  const scoped = scopedHost.getStore();
3319
3086
  if (scoped)
@@ -3348,7 +3115,7 @@ function hostedCodexAuthFilePath() {
3348
3115
  return activeHost().codexAuthFilePath();
3349
3116
  }
3350
3117
  function hostedCodexHomePath() {
3351
- return dirname5(hostedCodexAuthFilePath());
3118
+ return dirname4(hostedCodexAuthFilePath());
3352
3119
  }
3353
3120
  var defaultHost, hostRegistrations, scopedHost;
3354
3121
  var init_execution_host = __esm(async () => {
@@ -3370,15 +3137,15 @@ var init_execution_host = __esm(async () => {
3370
3137
 
3371
3138
  // ../../packages/core/src/agents/rollout/codex.ts
3372
3139
  import { randomBytes as randomBytes4 } from "crypto";
3373
- import { existsSync as existsSync6, readFileSync as readFileSync5, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync5 } from "fs";
3374
- import { basename, dirname as dirname6, join as join9, resolve as resolve5 } from "path";
3140
+ import { existsSync as existsSync5, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync4 } from "fs";
3141
+ import { basename, dirname as dirname5, join as join8, resolve as resolve5 } from "path";
3375
3142
  function codexSessionsDir() {
3376
- return join9(hostedCodexHomePath(), "sessions");
3143
+ return join8(hostedCodexHomePath(), "sessions");
3377
3144
  }
3378
3145
  function loadCodexShell() {
3379
3146
  if (_shellCache)
3380
3147
  return _shellCache;
3381
- const raw = readFileSync5(join9(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
3148
+ const raw = readFileSync4(join8(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
3382
3149
  const lines = parseJsonlText(raw);
3383
3150
  if (lines.length < 5) {
3384
3151
  throw new Error(`loadCodexShell: expected >=5 entries in codex-shell.jsonl, got ${lines.length}`);
@@ -3445,8 +3212,8 @@ function codexRolloutPath(threadId, fallback) {
3445
3212
  const hh = String(createdAt.getHours()).padStart(2, "0");
3446
3213
  const min = String(createdAt.getMinutes()).padStart(2, "0");
3447
3214
  const ss = String(createdAt.getSeconds()).padStart(2, "0");
3448
- const dir = join9(codexSessionsDir(), yyyy, mm, dd);
3449
- return join9(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
3215
+ const dir = join8(codexSessionsDir(), yyyy, mm, dd);
3216
+ return join8(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
3450
3217
  }
3451
3218
  function canonicalFilePath(path) {
3452
3219
  const absolute = resolve5(path);
@@ -3454,7 +3221,7 @@ function canonicalFilePath(path) {
3454
3221
  return realpathSync2(absolute);
3455
3222
  } catch {
3456
3223
  try {
3457
- return join9(realpathSync2(dirname6(absolute)), basename(absolute));
3224
+ return join8(realpathSync2(dirname5(absolute)), basename(absolute));
3458
3225
  } catch {
3459
3226
  return absolute;
3460
3227
  }
@@ -3564,7 +3331,7 @@ function readCodexPatchCallIds(threadId) {
3564
3331
  if (!path)
3565
3332
  return [];
3566
3333
  try {
3567
- return extractCodexPatchCallIds(readFileSync5(path, "utf8"));
3334
+ return extractCodexPatchCallIds(readFileSync4(path, "utf8"));
3568
3335
  } catch (error) {
3569
3336
  logger.debug({ error, threadId }, "codex patch ids: rollout read failed");
3570
3337
  return [];
@@ -3575,7 +3342,7 @@ function readLatestCodexPatchPreview(threadId, expectedPaths, consumedCallIds =
3575
3342
  if (!path)
3576
3343
  return;
3577
3344
  try {
3578
- return extractLatestCodexPatchPreview(readFileSync5(path, "utf8"), expectedPaths, consumedCallIds, expectedCallId);
3345
+ return extractLatestCodexPatchPreview(readFileSync4(path, "utf8"), expectedPaths, consumedCallIds, expectedCallId);
3579
3346
  } catch (error) {
3580
3347
  logger.debug({ error, threadId }, "codex patch preview: rollout read failed");
3581
3348
  return;
@@ -3633,7 +3400,7 @@ function readLatestCodexContextUsage(threadId) {
3633
3400
  if (!path)
3634
3401
  return;
3635
3402
  try {
3636
- return extractLatestCodexContextUsage(readFileSync5(path, "utf8"));
3403
+ return extractLatestCodexContextUsage(readFileSync4(path, "utf8"));
3637
3404
  } catch (error) {
3638
3405
  logger.debug({ error, threadId }, "codex context usage: rollout read failed");
3639
3406
  return;
@@ -3644,7 +3411,7 @@ function readLatestCodexTokenTotals(threadId) {
3644
3411
  if (!path)
3645
3412
  return;
3646
3413
  try {
3647
- return extractLatestCodexTokenTotals(readFileSync5(path, "utf8"));
3414
+ return extractLatestCodexTokenTotals(readFileSync4(path, "utf8"));
3648
3415
  } catch (error) {
3649
3416
  logger.debug({ error, threadId }, "codex token totals: rollout read failed");
3650
3417
  return;
@@ -3655,7 +3422,7 @@ function migrateCodexRolloutNativeMultiAgentMetadata(threadId) {
3655
3422
  if (!path)
3656
3423
  return false;
3657
3424
  try {
3658
- const entries = parseJsonlText(readFileSync5(path, "utf8"));
3425
+ const entries = parseJsonlText(readFileSync4(path, "utf8"));
3659
3426
  let changed = false;
3660
3427
  for (const entry of entries) {
3661
3428
  if (entry.type !== "session_meta" && entry.type !== "turn_context")
@@ -3684,19 +3451,19 @@ function latestCodexRolloutPath(threadId) {
3684
3451
  try {
3685
3452
  if (buckets) {
3686
3453
  for (const bucket of buckets) {
3687
- const dir = join9(sessionsDir, bucket);
3688
- if (!existsSync6(dir))
3454
+ const dir = join8(sessionsDir, bucket);
3455
+ if (!existsSync5(dir))
3689
3456
  continue;
3690
3457
  const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
3691
3458
  for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
3692
- candidates.push(join9(dir, rel));
3459
+ candidates.push(join8(dir, rel));
3693
3460
  }
3694
3461
  }
3695
3462
  }
3696
3463
  if (candidates.length === 0) {
3697
3464
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
3698
3465
  for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
3699
- candidates.push(join9(sessionsDir, rel));
3466
+ candidates.push(join8(sessionsDir, rel));
3700
3467
  }
3701
3468
  }
3702
3469
  return candidates.sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs)[0];
@@ -3817,15 +3584,15 @@ function sweepPriorRolloutsForThread(threadId) {
3817
3584
  return;
3818
3585
  }
3819
3586
  for (const bucket of buckets) {
3820
- const dir = join9(sessionsDir, bucket);
3821
- if (!existsSync6(dir))
3587
+ const dir = join8(sessionsDir, bucket);
3588
+ if (!existsSync5(dir))
3822
3589
  continue;
3823
3590
  try {
3824
3591
  const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
3825
3592
  for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
3826
- const fullPath = join9(dir, rel);
3593
+ const fullPath = join8(dir, rel);
3827
3594
  try {
3828
- unlinkSync5(fullPath);
3595
+ unlinkSync4(fullPath);
3829
3596
  } catch (e) {
3830
3597
  if (e?.code !== "ENOENT") {
3831
3598
  logger.warn({ err: e, path: fullPath }, "writeCodexRollout: prior-rollout unlink failed (continuing)");
@@ -3841,9 +3608,9 @@ function sweepPriorRolloutsFullTree(threadId, sessionsDir) {
3841
3608
  try {
3842
3609
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
3843
3610
  for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
3844
- const fullPath = join9(sessionsDir, rel);
3611
+ const fullPath = join8(sessionsDir, rel);
3845
3612
  try {
3846
- unlinkSync5(fullPath);
3613
+ unlinkSync4(fullPath);
3847
3614
  } catch (e) {
3848
3615
  if (e?.code !== "ENOENT") {
3849
3616
  logger.warn({ err: e, path: fullPath }, "writeCodexRollout: prior-rollout unlink failed (continuing)");
@@ -3902,7 +3669,245 @@ var init_codex = __esm(async () => {
3902
3669
  init_logger();
3903
3670
  });
3904
3671
 
3672
+ // ../../packages/core/src/version.ts
3673
+ var exports_version = {};
3674
+ __export(exports_version, {
3675
+ NEGOTIUM_VERSION: () => NEGOTIUM_VERSION
3676
+ });
3677
+ var NEGOTIUM_VERSION = "0.6.4";
3678
+
3679
+ // ../../packages/core/src/agents/codex-native-multi-agent.ts
3680
+ import { spawn as spawn2 } from "child_process";
3681
+ import { randomUUID as randomUUID2 } from "crypto";
3682
+ import {
3683
+ chmodSync as chmodSync3,
3684
+ copyFileSync,
3685
+ existsSync as existsSync6,
3686
+ mkdtempSync,
3687
+ readFileSync as readFileSync5,
3688
+ renameSync as renameSync3,
3689
+ rmSync,
3690
+ unlinkSync as unlinkSync5,
3691
+ writeFileSync as writeFileSync4
3692
+ } from "fs";
3693
+ import { createRequire as createRequire2 } from "module";
3694
+ import { tmpdir } from "os";
3695
+ import { dirname as dirname6, join as join9 } from "path";
3696
+ function readPackageVersion(packageJsonPath) {
3697
+ const parsed = JSON.parse(readFileSync5(packageJsonPath, "utf8"));
3698
+ if (typeof parsed.version !== "string" || !parsed.version.trim()) {
3699
+ throw new Error(`Codex package has no valid version: ${packageJsonPath}`);
3700
+ }
3701
+ return parsed.version;
3702
+ }
3703
+ function codexCliScriptPath() {
3704
+ return join9(dirname6(bundledCodexPackagePath), "bin", "codex.js");
3705
+ }
3706
+ function parseCodexModelCache(contents, sourcePath) {
3707
+ let parsed;
3708
+ try {
3709
+ parsed = JSON.parse(contents);
3710
+ } catch (error) {
3711
+ throw new Error(`Codex model cache is invalid JSON: ${sourcePath}`, { cause: error });
3712
+ }
3713
+ if (!Array.isArray(parsed.models) || parsed.models.length === 0) {
3714
+ throw new Error(`Codex model cache has no models: ${sourcePath}`);
3715
+ }
3716
+ return parsed;
3717
+ }
3718
+ function readCodexModelCache(cachePath) {
3719
+ const contents = readFileSync5(cachePath, "utf8");
3720
+ return { contents, parsed: parseCodexModelCache(contents, cachePath) };
3721
+ }
3722
+ function readCompatibleCodexModelCache(cachePath) {
3723
+ const cache = readCodexModelCache(cachePath);
3724
+ if (cache.parsed.client_version !== BUNDLED_CODEX_VERSION) {
3725
+ const found = typeof cache.parsed.client_version === "string" ? cache.parsed.client_version : "missing or invalid";
3726
+ throw new Error(`Codex model cache version ${found} does not match Negotium's bundled Codex ${BUNDLED_CODEX_VERSION}: ${cachePath}`);
3727
+ }
3728
+ return cache;
3729
+ }
3730
+ function writePrivateFileAtomic(path, contents) {
3731
+ if (existsSync6(path) && readFileSync5(path, "utf8") === contents)
3732
+ return;
3733
+ const tempPath = `${path}.${process.pid}.${randomUUID2()}.tmp`;
3734
+ try {
3735
+ writeFileSync4(tempPath, contents, { encoding: "utf8", mode: 384 });
3736
+ renameSync3(tempPath, path);
3737
+ chmodSync3(path, 384);
3738
+ } finally {
3739
+ try {
3740
+ unlinkSync5(tempPath);
3741
+ } catch {}
3742
+ }
3743
+ }
3744
+ function bundledCodexModelCachePath(authFilePath) {
3745
+ return join9(dirname6(authFilePath), NEGOTIUM_MODEL_CACHE);
3746
+ }
3747
+ async function bootstrapCodexModelCache(codexHome, cachePath) {
3748
+ const child = spawn2(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
3749
+ env: { ...process.env, CODEX_HOME: codexHome },
3750
+ stdio: ["pipe", "pipe", "pipe"]
3751
+ });
3752
+ await new Promise((resolve6, reject) => {
3753
+ let settled = false;
3754
+ let stdoutBuffer = "";
3755
+ let stderr = "";
3756
+ const timer = setTimeout(() => finish(new Error("timed out while refreshing the Codex model catalog")), 15000);
3757
+ const finish = (error) => {
3758
+ if (settled)
3759
+ return;
3760
+ settled = true;
3761
+ clearTimeout(timer);
3762
+ try {
3763
+ child.stdin.end();
3764
+ child.kill();
3765
+ } catch {}
3766
+ if (error)
3767
+ reject(error);
3768
+ else if (!existsSync6(cachePath))
3769
+ reject(new Error("Codex did not create its model cache"));
3770
+ else
3771
+ resolve6();
3772
+ };
3773
+ const send = (message) => {
3774
+ child.stdin.write(`${JSON.stringify(message)}
3775
+ `);
3776
+ };
3777
+ child.stderr.on("data", (chunk) => {
3778
+ if (stderr.length < 4096)
3779
+ stderr += String(chunk);
3780
+ });
3781
+ child.on("error", (error) => finish(error));
3782
+ child.on("exit", (code, signal) => {
3783
+ if (!settled) {
3784
+ finish(new Error(`Codex model catalog refresh exited with ${signal ? `signal ${signal}` : `code ${code ?? 1}`}${stderr.trim() ? `: ${stderr.trim()}` : ""}`));
3785
+ }
3786
+ });
3787
+ child.stdout.on("data", (chunk) => {
3788
+ stdoutBuffer += String(chunk);
3789
+ for (;; ) {
3790
+ const newline = stdoutBuffer.indexOf(`
3791
+ `);
3792
+ if (newline < 0)
3793
+ break;
3794
+ const line = stdoutBuffer.slice(0, newline);
3795
+ stdoutBuffer = stdoutBuffer.slice(newline + 1);
3796
+ let message;
3797
+ try {
3798
+ message = JSON.parse(line);
3799
+ } catch {
3800
+ continue;
3801
+ }
3802
+ if (message.id === 1) {
3803
+ if (message.error) {
3804
+ finish(new Error(message.error.message || "Codex initialization failed"));
3805
+ return;
3806
+ }
3807
+ send({ method: "initialized" });
3808
+ send({ id: 2, method: "model/list", params: { includeHidden: true } });
3809
+ } else if (message.id === 2) {
3810
+ if (message.error) {
3811
+ finish(new Error(message.error.message || "Codex model listing failed"));
3812
+ } else {
3813
+ finish();
3814
+ }
3815
+ return;
3816
+ }
3817
+ }
3818
+ });
3819
+ send({
3820
+ id: 1,
3821
+ method: "initialize",
3822
+ params: {
3823
+ clientInfo: { name: "negotium", version: NEGOTIUM_VERSION },
3824
+ capabilities: { experimentalApi: true }
3825
+ }
3826
+ });
3827
+ });
3828
+ }
3829
+ async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
3830
+ const sourceHome = dirname6(authFilePath);
3831
+ const isolatedHome = mkdtempSync(join9(tmpdir(), "negotium-codex-models-"));
3832
+ const isolatedCachePath = join9(isolatedHome, "models_cache.json");
3833
+ try {
3834
+ const isolatedAuthPath = join9(isolatedHome, "auth.json");
3835
+ copyFileSync(authFilePath, isolatedAuthPath);
3836
+ chmodSync3(isolatedAuthPath, 384);
3837
+ const sourceConfigPath = join9(sourceHome, "config.toml");
3838
+ if (existsSync6(sourceConfigPath)) {
3839
+ const isolatedConfigPath = join9(isolatedHome, "config.toml");
3840
+ copyFileSync(sourceConfigPath, isolatedConfigPath);
3841
+ chmodSync3(isolatedConfigPath, 384);
3842
+ }
3843
+ await bootstrap(isolatedHome, isolatedCachePath);
3844
+ return readCompatibleCodexModelCache(isolatedCachePath).contents;
3845
+ } finally {
3846
+ rmSync(isolatedHome, { recursive: true, force: true });
3847
+ }
3848
+ }
3849
+ async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
3850
+ const codexHome = dirname6(authFilePath);
3851
+ const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
3852
+ if (configuredCachePath) {
3853
+ if (!existsSync6(configuredCachePath)) {
3854
+ throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);
3855
+ }
3856
+ readCompatibleCodexModelCache(configuredCachePath);
3857
+ return configuredCachePath;
3858
+ }
3859
+ const bundledCachePath = bundledCodexModelCachePath(authFilePath);
3860
+ const sharedCachePath = join9(codexHome, "models_cache.json");
3861
+ if (existsSync6(sharedCachePath)) {
3862
+ try {
3863
+ const shared = readCompatibleCodexModelCache(sharedCachePath);
3864
+ writePrivateFileAtomic(bundledCachePath, shared.contents);
3865
+ return bundledCachePath;
3866
+ } catch {}
3867
+ }
3868
+ if (existsSync6(bundledCachePath)) {
3869
+ try {
3870
+ readCompatibleCodexModelCache(bundledCachePath);
3871
+ return bundledCachePath;
3872
+ } catch {}
3873
+ }
3874
+ const refreshedContents = await bootstrapIsolatedCodexModelCache(authFilePath, bootstrap);
3875
+ writePrivateFileAtomic(bundledCachePath, refreshedContents);
3876
+ return bundledCachePath;
3877
+ }
3878
+ function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
3879
+ const codexHome = dirname6(authFilePath);
3880
+ const outputPath = join9(codexHome, NEGOTIUM_MODEL_CATALOG);
3881
+ const parsed = readCodexModelCache(sourcePath).parsed;
3882
+ const models = parsed.models.map((model, index) => {
3883
+ if (!model || typeof model !== "object" || Array.isArray(model)) {
3884
+ throw new Error(`Codex model cache entry ${index} is invalid: ${sourcePath}`);
3885
+ }
3886
+ return { ...model, multi_agent_version: "disabled" };
3887
+ });
3888
+ const contents = `${JSON.stringify({ models }, null, 2)}
3889
+ `;
3890
+ writePrivateFileAtomic(outputPath, contents);
3891
+ return outputPath;
3892
+ }
3893
+ var moduleRequire, codexSdkPackagePath, codexSdkRequire, bundledCodexPackagePath, BUNDLED_CODEX_VERSION, SAFE_BUNDLED_CODEX_VERSION, NEGOTIUM_MODEL_CACHE, NEGOTIUM_MODEL_CATALOG;
3894
+ var init_codex_native_multi_agent = __esm(() => {
3895
+ moduleRequire = createRequire2(import.meta.url);
3896
+ codexSdkPackagePath = moduleRequire.resolve("@openai/codex-sdk/package.json");
3897
+ codexSdkRequire = createRequire2(codexSdkPackagePath);
3898
+ bundledCodexPackagePath = codexSdkRequire.resolve("@openai/codex/package.json");
3899
+ BUNDLED_CODEX_VERSION = readPackageVersion(bundledCodexPackagePath);
3900
+ SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/g, "_");
3901
+ NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
3902
+ NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
3903
+ });
3904
+
3905
3905
  // ../../packages/core/src/agents/codex-app-server.ts
3906
+ var exports_codex_app_server = {};
3907
+ __export(exports_codex_app_server, {
3908
+ forkCodexSession: () => forkCodexSession,
3909
+ createCodexAppServerForker: () => createCodexAppServerForker
3910
+ });
3906
3911
  import { spawn as spawn3 } from "child_process";
3907
3912
  function createCodexAppServerForker(host) {
3908
3913
  return async (parentThreadId) => {
@@ -4022,7 +4027,6 @@ import { existsSync as existsSync7, unlinkSync as unlinkSync6 } from "fs";
4022
4027
  import { join as join10 } from "path";
4023
4028
  var VALID_EFFORTS2, codexRegistry, codexRegistryOperations;
4024
4029
  var init_codex_registry = __esm(async () => {
4025
- await init_codex_app_server();
4026
4030
  await init_execution_host();
4027
4031
  await init_codex();
4028
4032
  init_logger();
@@ -4057,7 +4061,8 @@ var init_codex_registry = __esm(async () => {
4057
4061
  return { sessionId: threadId, rolloutPath };
4058
4062
  },
4059
4063
  async forkSession({ parentSessionId }) {
4060
- return await forkCodexSession(parentSessionId);
4064
+ const { forkCodexSession: forkCodexSession2 } = await init_codex_app_server().then(() => exports_codex_app_server);
4065
+ return await forkCodexSession2(parentSessionId);
4061
4066
  },
4062
4067
  async cleanupRollouts({ sessionIds }) {
4063
4068
  if (sessionIds.length === 0)
@@ -22796,6 +22801,12 @@ ${schedule.message}`, topic.agent, {
22796
22801
  depth: 0,
22797
22802
  from: fromLabel,
22798
22803
  injectAuthorId: "system",
22804
+ injectSourceAdapter: "self-schedule",
22805
+ injectKind: "tell",
22806
+ injectTellCard: {
22807
+ fromLabel,
22808
+ message: schedule.message
22809
+ },
22799
22810
  onSettled: (result) => {
22800
22811
  settled = true;
22801
22812
  stopClaimHeartbeat();
@@ -35326,6 +35337,56 @@ var init_terminal_width = __esm(() => {
35326
35337
  widthCache = new Map;
35327
35338
  });
35328
35339
 
35340
+ // ../../adapters/terminal/src/visualization.ts
35341
+ import { basename as basename12, extname as extname5, isAbsolute as isAbsolute7 } from "path";
35342
+ function hasControlCharacter(value) {
35343
+ for (const character of value) {
35344
+ const code = character.codePointAt(0) ?? 0;
35345
+ if (code <= 31 || code === 127)
35346
+ return true;
35347
+ }
35348
+ return false;
35349
+ }
35350
+ function isSupportedVisualizationPath(value) {
35351
+ if (value.length === 0 || value.length > MAX_VISUALIZATION_PATH_LENGTH || !isAbsolute7(value) || hasControlCharacter(value)) {
35352
+ return false;
35353
+ }
35354
+ const extension = extname5(value).toLowerCase();
35355
+ return extension === ".html" || extension === ".htm";
35356
+ }
35357
+ function parseVisualizationReference(value) {
35358
+ const trimmed = value.trim();
35359
+ if (trimmed.length > MAX_VISUALIZATION_REFERENCE_LENGTH || !trimmed.startsWith(VISUALIZE_PREFIX) || !trimmed.endsWith(VISUALIZE_SUFFIX)) {
35360
+ return null;
35361
+ }
35362
+ const encoded = trimmed.slice(VISUALIZE_PREFIX.length, -VISUALIZE_SUFFIX.length);
35363
+ let parsed;
35364
+ try {
35365
+ parsed = JSON.parse(encoded);
35366
+ } catch {
35367
+ return null;
35368
+ }
35369
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
35370
+ return null;
35371
+ const keys = Object.keys(parsed);
35372
+ if (keys.length < 1 || keys.length > 2 || keys.some((key) => key !== "path" && key !== "mode")) {
35373
+ return null;
35374
+ }
35375
+ const candidate = parsed;
35376
+ if (typeof candidate.path !== "string" || !isSupportedVisualizationPath(candidate.path)) {
35377
+ return null;
35378
+ }
35379
+ if (candidate.mode !== undefined && candidate.mode !== "wide")
35380
+ return null;
35381
+ return {
35382
+ path: candidate.path,
35383
+ name: basename12(candidate.path) || candidate.path,
35384
+ ...candidate.mode === "wide" ? { mode: "wide" } : {}
35385
+ };
35386
+ }
35387
+ var VISUALIZE_PREFIX = "\uE200visualize\uE202", VISUALIZE_SUFFIX = "\uE201", MAX_VISUALIZATION_REFERENCE_LENGTH = 8192, MAX_VISUALIZATION_PATH_LENGTH = 4096;
35388
+ var init_visualization = () => {};
35389
+
35329
35390
  // ../../adapters/terminal/src/render.ts
35330
35391
  function workingFrame(frame) {
35331
35392
  const index = Math.abs(Math.trunc(frame)) % WORKING_FRAMES.length;
@@ -35770,6 +35831,17 @@ function renderMarkdown(value, width) {
35770
35831
  `);
35771
35832
  for (let lineIndex = 0;lineIndex < rawLines.length; lineIndex += 1) {
35772
35833
  const rawLine = rawLines[lineIndex] ?? "";
35834
+ const visualization = parseVisualizationReference(rawLine);
35835
+ if (visualization) {
35836
+ flushTable();
35837
+ const mode = visualization.mode ? ` \xB7 ${visualization.mode}` : "";
35838
+ result.push(line(` \u25C7 visualization${mode} \xB7 ${visualization.name}`, {
35839
+ fg: theme.cyan,
35840
+ bg: theme.surfaceRaised,
35841
+ bold: true
35842
+ }));
35843
+ continue;
35844
+ }
35773
35845
  const fence = rawLine.match(/^\s*```([^`]*)$/);
35774
35846
  if (fence) {
35775
35847
  flushTable();
@@ -37064,6 +37136,7 @@ var init_render = __esm(async () => {
37064
37136
  init_path_suggest();
37065
37137
  await init_state2();
37066
37138
  init_terminal_width();
37139
+ init_visualization();
37067
37140
  init_terminal_width();
37068
37141
  theme = {
37069
37142
  canvas: [10, 11, 15],
@@ -42199,7 +42272,7 @@ function renderOutbound(text2, maxLen = 4096) {
42199
42272
 
42200
42273
  // ../../adapters/telegram/src/adapter.ts
42201
42274
  import { existsSync as existsSync37 } from "fs";
42202
- import { basename as basename12, extname as extname5 } from "path";
42275
+ import { basename as basename13, extname as extname6 } from "path";
42203
42276
  function startTelegramAdapter(opts) {
42204
42277
  const { client, forumChatId } = opts;
42205
42278
  const userId = opts.userId ?? "local";
@@ -42705,9 +42778,9 @@ function startTelegramAdapter(opts) {
42705
42778
  error: "file not found on disk"
42706
42779
  };
42707
42780
  }
42708
- const ext = extname5(path).slice(1).toLowerCase();
42781
+ const ext = extname6(path).slice(1).toLowerCase();
42709
42782
  const fileOptions = {
42710
- filename: basename12(file.filename) || basename12(path),
42783
+ filename: basename13(file.filename) || basename13(path),
42711
42784
  ...file.mimeType ? { contentType: file.mimeType } : {}
42712
42785
  };
42713
42786
  try {
@@ -43442,14 +43515,14 @@ Warning: enable the bot administrator permission "Manage Topics" before creating
43442
43515
  timer.unref?.();
43443
43516
  }
43444
43517
  }
43445
- const tagFiles = msg.text ? extractFileTagPaths(msg.text).map((path) => ({ path, filename: basename12(path) })) : [];
43518
+ const tagFiles = msg.text ? extractFileTagPaths(msg.text).map((path) => ({ path, filename: basename13(path) })) : [];
43446
43519
  const attachmentFiles = hasAttachments ? (msg.attachments ?? []).map((attachment) => {
43447
43520
  const path = resolveUploadedFilePathByFileId(attachment.id);
43448
43521
  if (!path)
43449
43522
  return null;
43450
43523
  return {
43451
43524
  path,
43452
- filename: basename12(attachment.filename) || basename12(path),
43525
+ filename: basename13(attachment.filename) || basename13(path),
43453
43526
  ...attachment.mimeType ? { mimeType: attachment.mimeType } : {}
43454
43527
  };
43455
43528
  }).filter((file) => file !== null) : [];
@@ -44579,7 +44652,7 @@ var init_join = __esm(async () => {
44579
44652
  // ../../adapters/otium/src/peer-files.ts
44580
44653
  import { randomUUID as randomUUID30 } from "crypto";
44581
44654
  import { copyFileSync as copyFileSync5, mkdirSync as mkdirSync35, rmSync as rmSync12, statSync as statSync21 } from "fs";
44582
- import { basename as basename13, extname as extname6, join as join47 } from "path";
44655
+ import { basename as basename14, extname as extname7, join as join47 } from "path";
44583
44656
  function fileType(mimeType) {
44584
44657
  if (mimeType.startsWith("image/"))
44585
44658
  return "image";
@@ -44601,11 +44674,11 @@ function rowFor(fileId) {
44601
44674
  return db.query("SELECT * FROM otium_peer_files WHERE id = ?").get(fileId) ?? null;
44602
44675
  }
44603
44676
  function safeFilename(filename) {
44604
- const value = basename13(filename).replace(/[^A-Za-z0-9._ -]/g, "_").slice(0, 120);
44677
+ const value = basename14(filename).replace(/[^A-Za-z0-9._ -]/g, "_").slice(0, 120);
44605
44678
  return value || "upload";
44606
44679
  }
44607
44680
  function mimeFromPath(path) {
44608
- const extension = extname6(path).toLowerCase();
44681
+ const extension = extname7(path).toLowerCase();
44609
44682
  const known = {
44610
44683
  ".png": "image/png",
44611
44684
  ".jpg": "image/jpeg",
@@ -44671,7 +44744,7 @@ function installPeerFileHooks() {
44671
44744
  return existing;
44672
44745
  return insertLocalFile({
44673
44746
  sourcePath: path,
44674
- filename: basename13(path),
44747
+ filename: basename14(path),
44675
44748
  mimeType: mimeFromPath(path),
44676
44749
  topicId: access?.topicId,
44677
44750
  ownerUserId: access?.ownerUserId
@@ -48559,4 +48632,4 @@ switch (command) {
48559
48632
  }
48560
48633
  }
48561
48634
 
48562
- //# debugId=51C96532F0CBBD5E64756E2164756E21
48635
+ //# debugId=FFCB7D41CEEC0A6064756E2164756E21