negotium 0.2.19 → 0.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/agent-helpers.js +573 -593
  2. package/dist/agent-helpers.js.map +17 -17
  3. package/dist/background-bash.js +3 -2
  4. package/dist/background-bash.js.map +3 -3
  5. package/dist/browser-runtime.js +76 -36
  6. package/dist/browser-runtime.js.map +6 -6
  7. package/dist/canonical-mcp-bridge.js +1 -1
  8. package/dist/{chunk-fc58cqry.js → chunk-rhp26p2c.js} +171 -26
  9. package/dist/{chunk-fc58cqry.js.map → chunk-rhp26p2c.js.map} +6 -5
  10. package/dist/{chunk-r0xs3t81.js → chunk-s2gez3wg.js} +18 -3
  11. package/dist/{chunk-r0xs3t81.js.map → chunk-s2gez3wg.js.map} +2 -2
  12. package/dist/hosted-agent.js +185 -54
  13. package/dist/hosted-agent.js.map +7 -6
  14. package/dist/main.js +1209 -1114
  15. package/dist/main.js.map +25 -25
  16. package/dist/mcp-catalog.js.map +1 -1
  17. package/dist/mcp-factories.js +526 -540
  18. package/dist/mcp-factories.js.map +17 -17
  19. package/dist/outbox.js.map +1 -1
  20. package/dist/platform-runtime.js.map +1 -1
  21. package/dist/prompts.js +3 -2
  22. package/dist/prompts.js.map +3 -3
  23. package/dist/query-runtime.js +63 -26
  24. package/dist/query-runtime.js.map +4 -4
  25. package/dist/registry.js +4 -3
  26. package/dist/registry.js.map +3 -3
  27. package/dist/rollout.js +1 -1
  28. package/dist/runtime/src/agents/archiver.ts +3 -2
  29. package/dist/runtime/src/application/switch-topic-access-mode.ts +81 -8
  30. package/dist/runtime/src/bus.ts +19 -2
  31. package/dist/runtime/src/mcp/session-comm/runtime.ts +16 -0
  32. package/dist/runtime/src/platform/config.ts +13 -1
  33. package/dist/runtime/src/runtime/ask-callbacks.ts +19 -11
  34. package/dist/runtime/src/runtime/background-sessions.ts +9 -7
  35. package/dist/runtime/src/runtime/visual-store.ts +31 -23
  36. package/dist/runtime/src/storage/api-topics.ts +26 -0
  37. package/dist/runtime/src/storage/browser-profiles.ts +16 -8
  38. package/dist/runtime/src/storage/runtime-events.ts +30 -20
  39. package/dist/runtime/src/storage/runtime-gateway-submissions.ts +24 -16
  40. package/dist/runtime/src/storage/runtime-turn-requests.ts +9 -1
  41. package/dist/runtime/src/storage/self-schedules.ts +32 -24
  42. package/dist/runtime/src/storage/storage-host.ts +105 -43
  43. package/dist/runtime/src/storage/vault.ts +12 -3
  44. package/dist/runtime/src/version.ts +1 -1
  45. package/dist/runtime-helpers.js +63 -26
  46. package/dist/runtime-helpers.js.map +4 -4
  47. package/dist/sqlite.js +17 -1
  48. package/dist/sqlite.js.map +2 -2
  49. package/dist/storage.js +92 -46
  50. package/dist/storage.js.map +4 -4
  51. package/dist/types/packages/core/src/storage/api-topics.d.ts +15 -0
  52. package/dist/types/packages/core/src/storage/storage-host.d.ts +10 -0
  53. package/dist/types/packages/core/src/version.d.ts +1 -1
  54. package/dist/vault.js +156 -10
  55. package/dist/vault.js.map +6 -5
  56. package/package.json +1 -1
@@ -3,7 +3,7 @@ import {
3
3
  canonicalMcpBridgeEnv,
4
4
  registerCanonicalMcpBridgeEnvProvider,
5
5
  revokeCanonicalMcpBridgeTurn
6
- } from "./chunk-r0xs3t81.js";
6
+ } from "./chunk-s2gez3wg.js";
7
7
  export {
8
8
  revokeCanonicalMcpBridgeTurn,
9
9
  registerCanonicalMcpBridgeEnvProvider,
@@ -1,4 +1,19 @@
1
- // @bun
1
+ var __create = Object.create;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __toESM = (mod, isNodeMode, target) => {
7
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
8
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
+ for (let key of __getOwnPropNames(mod))
10
+ if (!__hasOwnProp.call(to, key))
11
+ __defProp(to, key, {
12
+ get: () => mod[key],
13
+ enumerable: true
14
+ });
15
+ return to;
16
+ };
2
17
  var __require = import.meta.require;
3
18
 
4
19
  // ../../packages/core/src/agents/rollout/shared.ts
@@ -132,11 +147,12 @@ function versionAtLeast(actualVersion, minimumVersion) {
132
147
  }
133
148
  return true;
134
149
  }
150
+ var BROWSER_RS_VERSION_PROBE_TIMEOUT_MS = 15000;
135
151
  function browserRsMeetsMinimumVersion(candidate) {
136
152
  try {
137
153
  const output = execFileSync(candidate, ["--version"], {
138
154
  encoding: "utf8",
139
- timeout: 2000,
155
+ timeout: BROWSER_RS_VERSION_PROBE_TIMEOUT_MS,
140
156
  stdio: ["ignore", "pipe", "ignore"]
141
157
  }).trim();
142
158
  const match = output.match(/^browser-rs (\d+)\.(\d+)\.(\d+)$/);
@@ -761,11 +777,11 @@ function isPoisonedAssistantEntry(entry) {
761
777
  // ../../packages/core/src/agents/rollout/codex.ts
762
778
  import { randomBytes as randomBytes4 } from "crypto";
763
779
  import { existsSync as existsSync3, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync3 } from "fs";
764
- import { basename, dirname as dirname4, join as join4, resolve as resolve4 } from "path";
780
+ import { basename, dirname as dirname5, join as join5, resolve as resolve5 } from "path";
765
781
 
766
782
  // ../../packages/core/src/agents/execution-host.ts
767
783
  import { AsyncLocalStorage } from "async_hooks";
768
- import { dirname as dirname3 } from "path";
784
+ import { dirname as dirname4 } from "path";
769
785
 
770
786
  // ../../packages/core/src/security/sensitive-path.ts
771
787
  import { realpathSync } from "fs";
@@ -1725,8 +1741,8 @@ function getMcpServersForQuery(opts) {
1725
1741
  }
1726
1742
 
1727
1743
  // ../../packages/core/src/storage/vault.ts
1728
- import { chmodSync as chmodSync2, mkdirSync as mkdirSync4 } from "fs";
1729
- import { join as join3 } from "path";
1744
+ import { chmodSync as chmodSync2, mkdirSync as mkdirSync5 } from "fs";
1745
+ import { join as join4 } from "path";
1730
1746
 
1731
1747
  // ../../packages/core/src/storage/sqlite.ts
1732
1748
  var isBun = typeof process.versions.bun === "string";
@@ -1779,6 +1795,134 @@ if (isBun) {
1779
1795
  Database = NodeDatabase;
1780
1796
  }
1781
1797
 
1798
+ // ../../packages/core/src/storage/storage-host.ts
1799
+ import { mkdirSync as mkdirSync4 } from "fs";
1800
+ import { homedir as homedir3 } from "os";
1801
+ import { dirname as dirname3, join as join3, resolve as resolve4 } from "path";
1802
+ var STORAGE_HOST_STATE = Symbol.for("negotium.storage-host.state.v1");
1803
+ function storageState() {
1804
+ const holder = globalThis;
1805
+ const existing = holder[STORAGE_HOST_STATE];
1806
+ if (existing)
1807
+ return existing;
1808
+ const created = {
1809
+ configuredHost: {},
1810
+ fallbackDatabase: null,
1811
+ fallbackDatabasePath: null,
1812
+ frames: [],
1813
+ schemaInitializers: [],
1814
+ initializedSchemas: new WeakMap,
1815
+ initializingDatabases: new WeakSet
1816
+ };
1817
+ Object.defineProperty(holder, STORAGE_HOST_STATE, {
1818
+ value: created,
1819
+ enumerable: false,
1820
+ writable: false,
1821
+ configurable: false
1822
+ });
1823
+ return created;
1824
+ }
1825
+ function envPath(name, fallback) {
1826
+ const value = process.env[name]?.trim();
1827
+ return resolve4(value || fallback);
1828
+ }
1829
+ function defaultStateDir() {
1830
+ return envPath("NEGOTIUM_STATE_DIR", join3(homedir3(), ".negotium"));
1831
+ }
1832
+ function defaultDataDir() {
1833
+ return envPath("NEGOTIUM_DATA_DIR", join3(defaultStateDir(), "data"));
1834
+ }
1835
+ function defaultSessionsDatabasePath() {
1836
+ return envPath("SESSIONS_DB_PATH", join3(resolveStorageDataDir(), "sessions.db"));
1837
+ }
1838
+ var SQLITE_INIT_RETRY_MS = 25;
1839
+ var SQLITE_INIT_TIMEOUT_MS = 5000;
1840
+ var SQLITE_INIT_SLEEP = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
1841
+ function isSqliteBusy(error) {
1842
+ const message = error instanceof Error ? error.message : String(error);
1843
+ return /database is (?:locked|busy)|SQLITE_(?:BUSY|LOCKED)/i.test(message);
1844
+ }
1845
+ function execWithBusyRetry(database, sql, timeoutMs = SQLITE_INIT_TIMEOUT_MS) {
1846
+ const deadline = Date.now() + timeoutMs;
1847
+ while (true) {
1848
+ try {
1849
+ database.exec(sql);
1850
+ return;
1851
+ } catch (error) {
1852
+ if (!isSqliteBusy(error) || Date.now() >= deadline)
1853
+ throw error;
1854
+ Atomics.wait(SQLITE_INIT_SLEEP, 0, 0, Math.min(SQLITE_INIT_RETRY_MS, deadline - Date.now()));
1855
+ }
1856
+ }
1857
+ }
1858
+ function initializeDatabase(database) {
1859
+ database.exec("PRAGMA busy_timeout = 5000");
1860
+ execWithBusyRetry(database, "PRAGMA journal_mode = WAL");
1861
+ database.exec("PRAGMA foreign_keys = ON");
1862
+ database.exec("PRAGMA wal_autocheckpoint = 1000");
1863
+ try {
1864
+ database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
1865
+ } catch {}
1866
+ }
1867
+ function defaultDatabase() {
1868
+ const path = defaultSessionsDatabasePath();
1869
+ const state = storageState();
1870
+ if (state.fallbackDatabase && state.fallbackDatabasePath === path)
1871
+ return state.fallbackDatabase;
1872
+ if (state.fallbackDatabase)
1873
+ state.fallbackDatabase.close();
1874
+ mkdirSync4(dirname3(path), { recursive: true });
1875
+ state.fallbackDatabase = new Database(path, { create: true });
1876
+ state.fallbackDatabasePath = path;
1877
+ initializeDatabase(state.fallbackDatabase);
1878
+ return state.fallbackDatabase;
1879
+ }
1880
+ function resolveStorageDatabase() {
1881
+ return storageState().configuredHost.database ?? defaultDatabase();
1882
+ }
1883
+ function resolveStorageDataDir() {
1884
+ return storageState().configuredHost.dataDir ?? defaultDataDir();
1885
+ }
1886
+ function ensureStorageSchemas(database = resolveStorageDatabase()) {
1887
+ const state = storageState();
1888
+ if (state.initializingDatabases.has(database))
1889
+ return;
1890
+ let initialized = state.initializedSchemas.get(database);
1891
+ if (!initialized) {
1892
+ initialized = new Set;
1893
+ state.initializedSchemas.set(database, initialized);
1894
+ }
1895
+ state.initializingDatabases.add(database);
1896
+ try {
1897
+ for (const entry of state.schemaInitializers) {
1898
+ if (initialized.has(entry.initialize))
1899
+ continue;
1900
+ initialized.add(entry.initialize);
1901
+ try {
1902
+ entry.initialize(database);
1903
+ } catch (error) {
1904
+ initialized.delete(entry.initialize);
1905
+ throw error;
1906
+ }
1907
+ }
1908
+ } finally {
1909
+ state.initializingDatabases.delete(database);
1910
+ }
1911
+ }
1912
+ var internalStorageDatabase = new Proxy({}, {
1913
+ get(_target, property) {
1914
+ const database = resolveStorageDatabase();
1915
+ ensureStorageSchemas(database);
1916
+ const value = Reflect.get(database, property, database);
1917
+ return typeof value === "function" ? value.bind(database) : value;
1918
+ },
1919
+ set(_target, property, value) {
1920
+ const database = resolveStorageDatabase();
1921
+ ensureStorageSchemas(database);
1922
+ return Reflect.set(database, property, value, database);
1923
+ }
1924
+ });
1925
+
1782
1926
  // ../../packages/core/src/storage/vault-crypto-core.ts
1783
1927
  import { createCipheriv, createDecipheriv, createHash as createHash2, randomBytes as randomBytes3 } from "crypto";
1784
1928
  var ENVELOPE_PREFIX = "otium-vault:v1:";
@@ -1868,17 +2012,18 @@ function initializeVaultDatabase(database) {
1868
2012
  }
1869
2013
  }
1870
2014
  function openVaultDatabase(dataDir) {
1871
- const vaultDir = join3(dataDir, "vault");
1872
- const path = join3(vaultDir, "vault.db");
1873
- mkdirSync4(vaultDir, { recursive: true, mode: 448 });
2015
+ const vaultDir = join4(dataDir, "vault");
2016
+ const path = join4(vaultDir, "vault.db");
2017
+ mkdirSync5(vaultDir, { recursive: true, mode: 448 });
1874
2018
  const database = new Database(path, { create: true });
1875
2019
  chmodSync2(path, 384);
1876
2020
  initializeVaultDatabase(database);
1877
2021
  return database;
1878
2022
  }
1879
2023
  function activeVaultDatabase() {
1880
- if (!vaultDb)
1881
- vaultDb = openVaultDatabase(DATA_DIR);
2024
+ if (!vaultDb) {
2025
+ vaultDb = openVaultDatabase(resolveStorageDataDir());
2026
+ }
1882
2027
  return vaultDb;
1883
2028
  }
1884
2029
  var VAULT_VALUE_MAX_BYTES = 64 * 1024;
@@ -1991,18 +2136,18 @@ function hostedCodexAuthFilePath() {
1991
2136
  return activeHost().codexAuthFilePath();
1992
2137
  }
1993
2138
  function hostedCodexHomePath() {
1994
- return dirname3(hostedCodexAuthFilePath());
2139
+ return dirname4(hostedCodexAuthFilePath());
1995
2140
  }
1996
2141
 
1997
2142
  // ../../packages/core/src/agents/rollout/codex.ts
1998
2143
  function codexSessionsDir() {
1999
- return join4(hostedCodexHomePath(), "sessions");
2144
+ return join5(hostedCodexHomePath(), "sessions");
2000
2145
  }
2001
2146
  var _shellCache = null;
2002
2147
  function loadCodexShell() {
2003
2148
  if (_shellCache)
2004
2149
  return _shellCache;
2005
- const raw = readFileSync4(join4(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
2150
+ const raw = readFileSync4(join5(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
2006
2151
  const lines = parseJsonlText(raw);
2007
2152
  if (lines.length < 5) {
2008
2153
  throw new Error(`loadCodexShell: expected >=5 entries in codex-shell.jsonl, got ${lines.length}`);
@@ -2069,16 +2214,16 @@ function codexRolloutPath(threadId, fallback) {
2069
2214
  const hh = String(createdAt.getHours()).padStart(2, "0");
2070
2215
  const min = String(createdAt.getMinutes()).padStart(2, "0");
2071
2216
  const ss = String(createdAt.getSeconds()).padStart(2, "0");
2072
- const dir = join4(codexSessionsDir(), yyyy, mm, dd);
2073
- return join4(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
2217
+ const dir = join5(codexSessionsDir(), yyyy, mm, dd);
2218
+ return join5(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
2074
2219
  }
2075
2220
  function canonicalFilePath(path) {
2076
- const absolute = resolve4(path);
2221
+ const absolute = resolve5(path);
2077
2222
  try {
2078
2223
  return realpathSync2(absolute);
2079
2224
  } catch {
2080
2225
  try {
2081
- return join4(realpathSync2(dirname4(absolute)), basename(absolute));
2226
+ return join5(realpathSync2(dirname5(absolute)), basename(absolute));
2082
2227
  } catch {
2083
2228
  return absolute;
2084
2229
  }
@@ -2267,19 +2412,19 @@ function latestCodexRolloutPath(threadId) {
2267
2412
  try {
2268
2413
  if (buckets) {
2269
2414
  for (const bucket of buckets) {
2270
- const dir = join4(sessionsDir, bucket);
2415
+ const dir = join5(sessionsDir, bucket);
2271
2416
  if (!existsSync3(dir))
2272
2417
  continue;
2273
2418
  const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
2274
2419
  for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
2275
- candidates.push(join4(dir, rel));
2420
+ candidates.push(join5(dir, rel));
2276
2421
  }
2277
2422
  }
2278
2423
  }
2279
2424
  if (candidates.length === 0) {
2280
2425
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
2281
2426
  for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
2282
- candidates.push(join4(sessionsDir, rel));
2427
+ candidates.push(join5(sessionsDir, rel));
2283
2428
  }
2284
2429
  }
2285
2430
  return candidates.sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs)[0];
@@ -2400,13 +2545,13 @@ function sweepPriorRolloutsForThread(threadId) {
2400
2545
  return;
2401
2546
  }
2402
2547
  for (const bucket of buckets) {
2403
- const dir = join4(sessionsDir, bucket);
2548
+ const dir = join5(sessionsDir, bucket);
2404
2549
  if (!existsSync3(dir))
2405
2550
  continue;
2406
2551
  try {
2407
2552
  const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
2408
2553
  for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
2409
- const fullPath = join4(dir, rel);
2554
+ const fullPath = join5(dir, rel);
2410
2555
  try {
2411
2556
  unlinkSync3(fullPath);
2412
2557
  } catch (e) {
@@ -2424,7 +2569,7 @@ function sweepPriorRolloutsFullTree(threadId, sessionsDir) {
2424
2569
  try {
2425
2570
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
2426
2571
  for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
2427
- const fullPath = join4(sessionsDir, rel);
2572
+ const fullPath = join5(sessionsDir, rel);
2428
2573
  try {
2429
2574
  unlinkSync3(fullPath);
2430
2575
  } catch (e) {
@@ -2481,6 +2626,6 @@ function formatDateBucket(d) {
2481
2626
  return `${yyyy}/${mm}/${dd}`;
2482
2627
  }
2483
2628
 
2484
- export { __require, logger, CLAUDE_EFFORT_VALUES, CODEX_EFFORT_VALUES, MAESTRO_EFFORT_VALUES, MODEL_SONNET, MODEL_OPUS, MODEL_FABLE, configureRolloutHost, assertUuidLike, ensureCwdExists, extractChatPairs, encodeClaudeCwd, writeClaudeRollout, repairPoisonedRollout, hostedCodexHomePath, extractLatestCodexPatchPreview, extractCodexPatchCallIds, readCodexPatchCallIds, readLatestCodexPatchPreview, extractLatestCodexContextUsage, readLatestCodexContextUsage, migrateCodexRolloutNativeMultiAgentMetadata, latestCodexRolloutPath, writeCodexRollout, decodeUuidV7Timestamp };
2629
+ export { __toESM, __require, logger, CLAUDE_EFFORT_VALUES, CODEX_EFFORT_VALUES, MAESTRO_EFFORT_VALUES, MODEL_SONNET, MODEL_OPUS, MODEL_FABLE, configureRolloutHost, assertUuidLike, ensureCwdExists, extractChatPairs, encodeClaudeCwd, writeClaudeRollout, repairPoisonedRollout, hostedCodexHomePath, extractLatestCodexPatchPreview, extractCodexPatchCallIds, readCodexPatchCallIds, readLatestCodexPatchPreview, extractLatestCodexContextUsage, readLatestCodexContextUsage, migrateCodexRolloutNativeMultiAgentMetadata, latestCodexRolloutPath, writeCodexRollout, decodeUuidV7Timestamp };
2485
2630
 
2486
- //# debugId=3244605FC4A7370364756E2164756E21
2631
+ //# debugId=D69E031A952C1E0F64756E2164756E21