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.
- package/dist/agent-helpers.js +573 -593
- package/dist/agent-helpers.js.map +17 -17
- package/dist/background-bash.js +3 -2
- package/dist/background-bash.js.map +3 -3
- package/dist/browser-runtime.js +76 -36
- package/dist/browser-runtime.js.map +6 -6
- package/dist/canonical-mcp-bridge.js +1 -1
- package/dist/{chunk-fc58cqry.js → chunk-rhp26p2c.js} +171 -26
- package/dist/{chunk-fc58cqry.js.map → chunk-rhp26p2c.js.map} +6 -5
- package/dist/{chunk-r0xs3t81.js → chunk-s2gez3wg.js} +18 -3
- package/dist/{chunk-r0xs3t81.js.map → chunk-s2gez3wg.js.map} +2 -2
- package/dist/hosted-agent.js +185 -54
- package/dist/hosted-agent.js.map +7 -6
- package/dist/main.js +1209 -1114
- package/dist/main.js.map +25 -25
- package/dist/mcp-catalog.js.map +1 -1
- package/dist/mcp-factories.js +526 -540
- package/dist/mcp-factories.js.map +17 -17
- package/dist/outbox.js.map +1 -1
- package/dist/platform-runtime.js.map +1 -1
- package/dist/prompts.js +3 -2
- package/dist/prompts.js.map +3 -3
- package/dist/query-runtime.js +63 -26
- package/dist/query-runtime.js.map +4 -4
- package/dist/registry.js +4 -3
- package/dist/registry.js.map +3 -3
- package/dist/rollout.js +1 -1
- package/dist/runtime/src/agents/archiver.ts +3 -2
- package/dist/runtime/src/application/switch-topic-access-mode.ts +81 -8
- package/dist/runtime/src/bus.ts +19 -2
- package/dist/runtime/src/mcp/session-comm/runtime.ts +16 -0
- package/dist/runtime/src/platform/config.ts +13 -1
- package/dist/runtime/src/runtime/ask-callbacks.ts +19 -11
- package/dist/runtime/src/runtime/background-sessions.ts +9 -7
- package/dist/runtime/src/runtime/visual-store.ts +31 -23
- package/dist/runtime/src/storage/api-topics.ts +26 -0
- package/dist/runtime/src/storage/browser-profiles.ts +16 -8
- package/dist/runtime/src/storage/runtime-events.ts +30 -20
- package/dist/runtime/src/storage/runtime-gateway-submissions.ts +24 -16
- package/dist/runtime/src/storage/runtime-turn-requests.ts +9 -1
- package/dist/runtime/src/storage/self-schedules.ts +32 -24
- package/dist/runtime/src/storage/storage-host.ts +105 -43
- package/dist/runtime/src/storage/vault.ts +12 -3
- package/dist/runtime/src/version.ts +1 -1
- package/dist/runtime-helpers.js +63 -26
- package/dist/runtime-helpers.js.map +4 -4
- package/dist/sqlite.js +17 -1
- package/dist/sqlite.js.map +2 -2
- package/dist/storage.js +92 -46
- package/dist/storage.js.map +4 -4
- package/dist/types/packages/core/src/storage/api-topics.d.ts +15 -0
- package/dist/types/packages/core/src/storage/storage-host.d.ts +10 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/dist/vault.js +156 -10
- package/dist/vault.js.map +6 -5
- package/package.json +1 -1
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
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/mcp/canonical-bridge-config.ts
|
|
@@ -51,6 +66,6 @@ function revokeCanonicalMcpBridgeTurn(scope) {
|
|
|
51
66
|
return leases.size;
|
|
52
67
|
}
|
|
53
68
|
|
|
54
|
-
export { __require, registerCanonicalMcpBridgeEnvProvider, canonicalMcpBridgeEnv, revokeCanonicalMcpBridgeTurn };
|
|
69
|
+
export { __toESM, __require, registerCanonicalMcpBridgeEnvProvider, canonicalMcpBridgeEnv, revokeCanonicalMcpBridgeTurn };
|
|
55
70
|
|
|
56
|
-
//# debugId=
|
|
71
|
+
//# debugId=FF9F7F9A872D7FA764756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import type { PeerRuntimeBridgeContext } from \"#types\";\n\nexport type CanonicalMcpSurface = \"task\" | \"wiki\";\n\nexport interface CanonicalMcpBridgeScope {\n surface: CanonicalMcpSurface;\n userId: string;\n topicId: string;\n queryId: string;\n peerBridge: PeerRuntimeBridgeContext;\n}\n\nexport interface CanonicalMcpBridgeEnvLease {\n env: Record<string, string>;\n /** Revoke the capability immediately. Must be safe to call more than once. */\n revoke(): void;\n}\n\nexport type CanonicalMcpBridgeEnvProvider = (\n scope: CanonicalMcpBridgeScope,\n) => CanonicalMcpBridgeEnvLease | undefined;\n\nconst registrations: Array<{ id: symbol; provider: CanonicalMcpBridgeEnvProvider }> = [];\nconst turnLeases = new Map<string, Set<() => void>>();\n\nfunction turnKey(\n scope: Pick<CanonicalMcpBridgeScope, \"userId\" | \"topicId\" | \"queryId\" | \"peerBridge\">,\n): string {\n return JSON.stringify([\n scope.userId,\n scope.topicId,\n scope.queryId,\n scope.peerBridge.hubCellId,\n scope.peerBridge.hostTopicId,\n scope.peerBridge.hostQueryId,\n ]);\n}\n\n/** Placement adapters install a scoped capability issuer without exposing\n * their hub discovery or authentication model to generic core. */\nexport function registerCanonicalMcpBridgeEnvProvider(\n provider: CanonicalMcpBridgeEnvProvider,\n): () => void {\n const registration = { id: Symbol(\"canonical-mcp-bridge\"), provider };\n registrations.push(registration);\n let disposed = false;\n return () => {\n if (disposed) return;\n disposed = true;\n const index = registrations.findIndex((entry) => entry.id === registration.id);\n if (index >= 0) registrations.splice(index, 1);\n };\n}\n\nexport function canonicalMcpBridgeEnv(\n scope: CanonicalMcpBridgeScope,\n): Record<string, string> | undefined {\n const lease = registrations.at(-1)?.provider(scope);\n if (!lease) return undefined;\n const key = turnKey(scope);\n const leases = turnLeases.get(key) ?? new Set<() => void>();\n leases.add(lease.revoke);\n turnLeases.set(key, leases);\n return lease.env;\n}\n\n/** Revoke every canonical MCP capability issued while building one placed turn. */\nexport function revokeCanonicalMcpBridgeTurn(\n scope: Pick<CanonicalMcpBridgeScope, \"userId\" | \"topicId\" | \"queryId\" | \"peerBridge\">,\n): number {\n const key = turnKey(scope);\n const leases = turnLeases.get(key);\n if (!leases) return 0;\n turnLeases.delete(key);\n for (const revoke of leases) {\n try {\n revoke();\n } catch {\n // Revocation is best-effort across independently owned bridge adapters;\n // continue so one broken disposer cannot preserve sibling capabilities.\n }\n }\n return leases.size;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAsBA,IAAM,gBAAgF,CAAC;AACvF,IAAM,aAAa,IAAI;AAEvB,SAAS,OAAO,CACd,OACQ;AAAA,EACR,OAAO,KAAK,UAAU;AAAA,IACpB,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM,WAAW;AAAA,IACjB,MAAM,WAAW;AAAA,IACjB,MAAM,WAAW;AAAA,EACnB,CAAC;AAAA;AAKI,SAAS,qCAAqC,CACnD,UACY;AAAA,EACZ,MAAM,eAAe,EAAE,IAAI,OAAO,sBAAsB,GAAG,SAAS;AAAA,EACpE,cAAc,KAAK,YAAY;AAAA,EAC/B,IAAI,WAAW;AAAA,EACf,OAAO,MAAM;AAAA,IACX,IAAI;AAAA,MAAU;AAAA,IACd,WAAW;AAAA,IACX,MAAM,QAAQ,cAAc,UAAU,CAAC,UAAU,MAAM,OAAO,aAAa,EAAE;AAAA,IAC7E,IAAI,SAAS;AAAA,MAAG,cAAc,OAAO,OAAO,CAAC;AAAA;AAAA;AAI1C,SAAS,qBAAqB,CACnC,OACoC;AAAA,EACpC,MAAM,QAAQ,cAAc,GAAG,EAAE,GAAG,SAAS,KAAK;AAAA,EAClD,KAAK;AAAA,IAAO;AAAA,EACZ,MAAM,MAAM,QAAQ,KAAK;AAAA,EACzB,MAAM,SAAS,WAAW,IAAI,GAAG,KAAK,IAAI;AAAA,EAC1C,OAAO,IAAI,MAAM,MAAM;AAAA,EACvB,WAAW,IAAI,KAAK,MAAM;AAAA,EAC1B,OAAO,MAAM;AAAA;AAIR,SAAS,4BAA4B,CAC1C,OACQ;AAAA,EACR,MAAM,MAAM,QAAQ,KAAK;AAAA,EACzB,MAAM,SAAS,WAAW,IAAI,GAAG;AAAA,EACjC,KAAK;AAAA,IAAQ,OAAO;AAAA,EACpB,WAAW,OAAO,GAAG;AAAA,EACrB,WAAW,UAAU,QAAQ;AAAA,IAC3B,IAAI;AAAA,MACF,OAAO;AAAA,MACP,MAAM;AAAA,EAIV;AAAA,EACA,OAAO,OAAO;AAAA;",
|
|
8
|
+
"debugId": "FF9F7F9A872D7FA764756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/hosted-agent.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
__require,
|
|
4
|
+
__toESM,
|
|
4
5
|
canonicalMcpBridgeEnv,
|
|
5
6
|
revokeCanonicalMcpBridgeTurn
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-s2gez3wg.js";
|
|
7
8
|
|
|
8
9
|
// ../../packages/core/src/agents/claude-provider.ts
|
|
9
10
|
import { spawn as spawn2 } from "child_process";
|
|
@@ -138,11 +139,12 @@ function versionAtLeast(actualVersion, minimumVersion) {
|
|
|
138
139
|
}
|
|
139
140
|
return true;
|
|
140
141
|
}
|
|
142
|
+
var BROWSER_RS_VERSION_PROBE_TIMEOUT_MS = 15000;
|
|
141
143
|
function browserRsMeetsMinimumVersion(candidate) {
|
|
142
144
|
try {
|
|
143
145
|
const output = execFileSync(candidate, ["--version"], {
|
|
144
146
|
encoding: "utf8",
|
|
145
|
-
timeout:
|
|
147
|
+
timeout: BROWSER_RS_VERSION_PROBE_TIMEOUT_MS,
|
|
146
148
|
stdio: ["ignore", "pipe", "ignore"]
|
|
147
149
|
}).trim();
|
|
148
150
|
const match = output.match(/^browser-rs (\d+)\.(\d+)\.(\d+)$/);
|
|
@@ -451,7 +453,7 @@ function deepMapStrings(value, fn) {
|
|
|
451
453
|
|
|
452
454
|
// ../../packages/core/src/agents/execution-host.ts
|
|
453
455
|
import { AsyncLocalStorage } from "async_hooks";
|
|
454
|
-
import { dirname as
|
|
456
|
+
import { dirname as dirname4 } from "path";
|
|
455
457
|
|
|
456
458
|
// ../../packages/core/src/security/sensitive-path.ts
|
|
457
459
|
import { realpathSync } from "fs";
|
|
@@ -1395,8 +1397,8 @@ function getMcpServersForQuery(opts) {
|
|
|
1395
1397
|
}
|
|
1396
1398
|
|
|
1397
1399
|
// ../../packages/core/src/storage/vault.ts
|
|
1398
|
-
import { chmodSync as chmodSync2, mkdirSync as
|
|
1399
|
-
import { join as
|
|
1400
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync4 } from "fs";
|
|
1401
|
+
import { join as join3 } from "path";
|
|
1400
1402
|
|
|
1401
1403
|
// ../../packages/core/src/storage/sqlite.ts
|
|
1402
1404
|
var isBun = typeof process.versions.bun === "string";
|
|
@@ -1449,6 +1451,134 @@ if (isBun) {
|
|
|
1449
1451
|
Database = NodeDatabase;
|
|
1450
1452
|
}
|
|
1451
1453
|
|
|
1454
|
+
// ../../packages/core/src/storage/storage-host.ts
|
|
1455
|
+
import { mkdirSync as mkdirSync3 } from "fs";
|
|
1456
|
+
import { homedir as homedir2 } from "os";
|
|
1457
|
+
import { dirname as dirname3, join as join2, resolve as resolve4 } from "path";
|
|
1458
|
+
var STORAGE_HOST_STATE = Symbol.for("negotium.storage-host.state.v1");
|
|
1459
|
+
function storageState() {
|
|
1460
|
+
const holder = globalThis;
|
|
1461
|
+
const existing = holder[STORAGE_HOST_STATE];
|
|
1462
|
+
if (existing)
|
|
1463
|
+
return existing;
|
|
1464
|
+
const created = {
|
|
1465
|
+
configuredHost: {},
|
|
1466
|
+
fallbackDatabase: null,
|
|
1467
|
+
fallbackDatabasePath: null,
|
|
1468
|
+
frames: [],
|
|
1469
|
+
schemaInitializers: [],
|
|
1470
|
+
initializedSchemas: new WeakMap,
|
|
1471
|
+
initializingDatabases: new WeakSet
|
|
1472
|
+
};
|
|
1473
|
+
Object.defineProperty(holder, STORAGE_HOST_STATE, {
|
|
1474
|
+
value: created,
|
|
1475
|
+
enumerable: false,
|
|
1476
|
+
writable: false,
|
|
1477
|
+
configurable: false
|
|
1478
|
+
});
|
|
1479
|
+
return created;
|
|
1480
|
+
}
|
|
1481
|
+
function envPath(name, fallback) {
|
|
1482
|
+
const value = process.env[name]?.trim();
|
|
1483
|
+
return resolve4(value || fallback);
|
|
1484
|
+
}
|
|
1485
|
+
function defaultStateDir() {
|
|
1486
|
+
return envPath("NEGOTIUM_STATE_DIR", join2(homedir2(), ".negotium"));
|
|
1487
|
+
}
|
|
1488
|
+
function defaultDataDir() {
|
|
1489
|
+
return envPath("NEGOTIUM_DATA_DIR", join2(defaultStateDir(), "data"));
|
|
1490
|
+
}
|
|
1491
|
+
function defaultSessionsDatabasePath() {
|
|
1492
|
+
return envPath("SESSIONS_DB_PATH", join2(resolveStorageDataDir(), "sessions.db"));
|
|
1493
|
+
}
|
|
1494
|
+
var SQLITE_INIT_RETRY_MS = 25;
|
|
1495
|
+
var SQLITE_INIT_TIMEOUT_MS = 5000;
|
|
1496
|
+
var SQLITE_INIT_SLEEP = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
|
1497
|
+
function isSqliteBusy(error) {
|
|
1498
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1499
|
+
return /database is (?:locked|busy)|SQLITE_(?:BUSY|LOCKED)/i.test(message);
|
|
1500
|
+
}
|
|
1501
|
+
function execWithBusyRetry(database, sql, timeoutMs = SQLITE_INIT_TIMEOUT_MS) {
|
|
1502
|
+
const deadline = Date.now() + timeoutMs;
|
|
1503
|
+
while (true) {
|
|
1504
|
+
try {
|
|
1505
|
+
database.exec(sql);
|
|
1506
|
+
return;
|
|
1507
|
+
} catch (error) {
|
|
1508
|
+
if (!isSqliteBusy(error) || Date.now() >= deadline)
|
|
1509
|
+
throw error;
|
|
1510
|
+
Atomics.wait(SQLITE_INIT_SLEEP, 0, 0, Math.min(SQLITE_INIT_RETRY_MS, deadline - Date.now()));
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
function initializeDatabase(database) {
|
|
1515
|
+
database.exec("PRAGMA busy_timeout = 5000");
|
|
1516
|
+
execWithBusyRetry(database, "PRAGMA journal_mode = WAL");
|
|
1517
|
+
database.exec("PRAGMA foreign_keys = ON");
|
|
1518
|
+
database.exec("PRAGMA wal_autocheckpoint = 1000");
|
|
1519
|
+
try {
|
|
1520
|
+
database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
1521
|
+
} catch {}
|
|
1522
|
+
}
|
|
1523
|
+
function defaultDatabase() {
|
|
1524
|
+
const path = defaultSessionsDatabasePath();
|
|
1525
|
+
const state = storageState();
|
|
1526
|
+
if (state.fallbackDatabase && state.fallbackDatabasePath === path)
|
|
1527
|
+
return state.fallbackDatabase;
|
|
1528
|
+
if (state.fallbackDatabase)
|
|
1529
|
+
state.fallbackDatabase.close();
|
|
1530
|
+
mkdirSync3(dirname3(path), { recursive: true });
|
|
1531
|
+
state.fallbackDatabase = new Database(path, { create: true });
|
|
1532
|
+
state.fallbackDatabasePath = path;
|
|
1533
|
+
initializeDatabase(state.fallbackDatabase);
|
|
1534
|
+
return state.fallbackDatabase;
|
|
1535
|
+
}
|
|
1536
|
+
function resolveStorageDatabase() {
|
|
1537
|
+
return storageState().configuredHost.database ?? defaultDatabase();
|
|
1538
|
+
}
|
|
1539
|
+
function resolveStorageDataDir() {
|
|
1540
|
+
return storageState().configuredHost.dataDir ?? defaultDataDir();
|
|
1541
|
+
}
|
|
1542
|
+
function ensureStorageSchemas(database = resolveStorageDatabase()) {
|
|
1543
|
+
const state = storageState();
|
|
1544
|
+
if (state.initializingDatabases.has(database))
|
|
1545
|
+
return;
|
|
1546
|
+
let initialized = state.initializedSchemas.get(database);
|
|
1547
|
+
if (!initialized) {
|
|
1548
|
+
initialized = new Set;
|
|
1549
|
+
state.initializedSchemas.set(database, initialized);
|
|
1550
|
+
}
|
|
1551
|
+
state.initializingDatabases.add(database);
|
|
1552
|
+
try {
|
|
1553
|
+
for (const entry of state.schemaInitializers) {
|
|
1554
|
+
if (initialized.has(entry.initialize))
|
|
1555
|
+
continue;
|
|
1556
|
+
initialized.add(entry.initialize);
|
|
1557
|
+
try {
|
|
1558
|
+
entry.initialize(database);
|
|
1559
|
+
} catch (error) {
|
|
1560
|
+
initialized.delete(entry.initialize);
|
|
1561
|
+
throw error;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
} finally {
|
|
1565
|
+
state.initializingDatabases.delete(database);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
var internalStorageDatabase = new Proxy({}, {
|
|
1569
|
+
get(_target, property) {
|
|
1570
|
+
const database = resolveStorageDatabase();
|
|
1571
|
+
ensureStorageSchemas(database);
|
|
1572
|
+
const value = Reflect.get(database, property, database);
|
|
1573
|
+
return typeof value === "function" ? value.bind(database) : value;
|
|
1574
|
+
},
|
|
1575
|
+
set(_target, property, value) {
|
|
1576
|
+
const database = resolveStorageDatabase();
|
|
1577
|
+
ensureStorageSchemas(database);
|
|
1578
|
+
return Reflect.set(database, property, value, database);
|
|
1579
|
+
}
|
|
1580
|
+
});
|
|
1581
|
+
|
|
1452
1582
|
// ../../packages/core/src/storage/vault-crypto-core.ts
|
|
1453
1583
|
import { createCipheriv, createDecipheriv, createHash as createHash2, randomBytes as randomBytes3 } from "crypto";
|
|
1454
1584
|
var ENVELOPE_PREFIX = "otium-vault:v1:";
|
|
@@ -1538,17 +1668,18 @@ function initializeVaultDatabase(database) {
|
|
|
1538
1668
|
}
|
|
1539
1669
|
}
|
|
1540
1670
|
function openVaultDatabase(dataDir) {
|
|
1541
|
-
const vaultDir =
|
|
1542
|
-
const path =
|
|
1543
|
-
|
|
1671
|
+
const vaultDir = join3(dataDir, "vault");
|
|
1672
|
+
const path = join3(vaultDir, "vault.db");
|
|
1673
|
+
mkdirSync4(vaultDir, { recursive: true, mode: 448 });
|
|
1544
1674
|
const database = new Database(path, { create: true });
|
|
1545
1675
|
chmodSync2(path, 384);
|
|
1546
1676
|
initializeVaultDatabase(database);
|
|
1547
1677
|
return database;
|
|
1548
1678
|
}
|
|
1549
1679
|
function activeVaultDatabase() {
|
|
1550
|
-
if (!vaultDb)
|
|
1551
|
-
vaultDb = openVaultDatabase(
|
|
1680
|
+
if (!vaultDb) {
|
|
1681
|
+
vaultDb = openVaultDatabase(resolveStorageDataDir());
|
|
1682
|
+
}
|
|
1552
1683
|
return vaultDb;
|
|
1553
1684
|
}
|
|
1554
1685
|
var VAULT_VALUE_MAX_BYTES = 64 * 1024;
|
|
@@ -1704,7 +1835,7 @@ function hostedCodexAuthFilePath() {
|
|
|
1704
1835
|
return activeHost().codexAuthFilePath();
|
|
1705
1836
|
}
|
|
1706
1837
|
function hostedCodexHomePath() {
|
|
1707
|
-
return
|
|
1838
|
+
return dirname4(hostedCodexAuthFilePath());
|
|
1708
1839
|
}
|
|
1709
1840
|
|
|
1710
1841
|
// ../../packages/core/src/media/file-events.ts
|
|
@@ -2214,8 +2345,8 @@ async function* claudeProvider(opts) {
|
|
|
2214
2345
|
// ../../packages/core/src/agents/codex-provider.ts
|
|
2215
2346
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
2216
2347
|
import { existsSync as existsSync5, readFileSync as readFileSync6, realpathSync as realpathSync3, statSync as statSync3 } from "fs";
|
|
2217
|
-
import { homedir as
|
|
2218
|
-
import { dirname as
|
|
2348
|
+
import { homedir as homedir3 } from "os";
|
|
2349
|
+
import { dirname as dirname7, isAbsolute, join as join6, relative, resolve as resolve6 } from "path";
|
|
2219
2350
|
import { Codex } from "@openai/codex-sdk";
|
|
2220
2351
|
|
|
2221
2352
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
@@ -2234,10 +2365,10 @@ import {
|
|
|
2234
2365
|
} from "fs";
|
|
2235
2366
|
import { createRequire as createRequire2 } from "module";
|
|
2236
2367
|
import { tmpdir } from "os";
|
|
2237
|
-
import { dirname as
|
|
2368
|
+
import { dirname as dirname5, join as join4 } from "path";
|
|
2238
2369
|
|
|
2239
2370
|
// ../../packages/core/src/version.ts
|
|
2240
|
-
var NEGOTIUM_VERSION = "0.2.
|
|
2371
|
+
var NEGOTIUM_VERSION = "0.2.21";
|
|
2241
2372
|
|
|
2242
2373
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
2243
2374
|
var moduleRequire = createRequire2(import.meta.url);
|
|
@@ -2256,7 +2387,7 @@ var SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/
|
|
|
2256
2387
|
var NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
|
|
2257
2388
|
var NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
|
|
2258
2389
|
function codexCliScriptPath() {
|
|
2259
|
-
return
|
|
2390
|
+
return join4(dirname5(bundledCodexPackagePath), "bin", "codex.js");
|
|
2260
2391
|
}
|
|
2261
2392
|
function parseCodexModelCache(contents, sourcePath) {
|
|
2262
2393
|
let parsed;
|
|
@@ -2297,14 +2428,14 @@ function writePrivateFileAtomic(path, contents) {
|
|
|
2297
2428
|
}
|
|
2298
2429
|
}
|
|
2299
2430
|
function bundledCodexModelCachePath(authFilePath) {
|
|
2300
|
-
return
|
|
2431
|
+
return join4(dirname5(authFilePath), NEGOTIUM_MODEL_CACHE);
|
|
2301
2432
|
}
|
|
2302
2433
|
async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
2303
2434
|
const child = spawn3(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
|
|
2304
2435
|
env: { ...process.env, CODEX_HOME: codexHome },
|
|
2305
2436
|
stdio: ["pipe", "pipe", "pipe"]
|
|
2306
2437
|
});
|
|
2307
|
-
await new Promise((
|
|
2438
|
+
await new Promise((resolve5, reject) => {
|
|
2308
2439
|
let settled = false;
|
|
2309
2440
|
let stdoutBuffer = "";
|
|
2310
2441
|
let stderr = "";
|
|
@@ -2323,7 +2454,7 @@ async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
|
2323
2454
|
else if (!existsSync3(cachePath))
|
|
2324
2455
|
reject(new Error("Codex did not create its model cache"));
|
|
2325
2456
|
else
|
|
2326
|
-
|
|
2457
|
+
resolve5();
|
|
2327
2458
|
};
|
|
2328
2459
|
const send = (message) => {
|
|
2329
2460
|
child.stdin.write(`${JSON.stringify(message)}
|
|
@@ -2382,16 +2513,16 @@ async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
|
2382
2513
|
});
|
|
2383
2514
|
}
|
|
2384
2515
|
async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
|
|
2385
|
-
const sourceHome =
|
|
2386
|
-
const isolatedHome = mkdtempSync(
|
|
2387
|
-
const isolatedCachePath =
|
|
2516
|
+
const sourceHome = dirname5(authFilePath);
|
|
2517
|
+
const isolatedHome = mkdtempSync(join4(tmpdir(), "negotium-codex-models-"));
|
|
2518
|
+
const isolatedCachePath = join4(isolatedHome, "models_cache.json");
|
|
2388
2519
|
try {
|
|
2389
|
-
const isolatedAuthPath =
|
|
2520
|
+
const isolatedAuthPath = join4(isolatedHome, "auth.json");
|
|
2390
2521
|
copyFileSync(authFilePath, isolatedAuthPath);
|
|
2391
2522
|
chmodSync3(isolatedAuthPath, 384);
|
|
2392
|
-
const sourceConfigPath =
|
|
2523
|
+
const sourceConfigPath = join4(sourceHome, "config.toml");
|
|
2393
2524
|
if (existsSync3(sourceConfigPath)) {
|
|
2394
|
-
const isolatedConfigPath =
|
|
2525
|
+
const isolatedConfigPath = join4(isolatedHome, "config.toml");
|
|
2395
2526
|
copyFileSync(sourceConfigPath, isolatedConfigPath);
|
|
2396
2527
|
chmodSync3(isolatedConfigPath, 384);
|
|
2397
2528
|
}
|
|
@@ -2402,7 +2533,7 @@ async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
|
|
|
2402
2533
|
}
|
|
2403
2534
|
}
|
|
2404
2535
|
async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
|
|
2405
|
-
const codexHome =
|
|
2536
|
+
const codexHome = dirname5(authFilePath);
|
|
2406
2537
|
const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
|
|
2407
2538
|
if (configuredCachePath) {
|
|
2408
2539
|
if (!existsSync3(configuredCachePath)) {
|
|
@@ -2412,7 +2543,7 @@ async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexMod
|
|
|
2412
2543
|
return configuredCachePath;
|
|
2413
2544
|
}
|
|
2414
2545
|
const bundledCachePath = bundledCodexModelCachePath(authFilePath);
|
|
2415
|
-
const sharedCachePath =
|
|
2546
|
+
const sharedCachePath = join4(codexHome, "models_cache.json");
|
|
2416
2547
|
if (existsSync3(sharedCachePath)) {
|
|
2417
2548
|
try {
|
|
2418
2549
|
const shared = readCompatibleCodexModelCache(sharedCachePath);
|
|
@@ -2431,8 +2562,8 @@ async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexMod
|
|
|
2431
2562
|
return bundledCachePath;
|
|
2432
2563
|
}
|
|
2433
2564
|
function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
|
|
2434
|
-
const codexHome =
|
|
2435
|
-
const outputPath =
|
|
2565
|
+
const codexHome = dirname5(authFilePath);
|
|
2566
|
+
const outputPath = join4(codexHome, NEGOTIUM_MODEL_CATALOG);
|
|
2436
2567
|
const parsed = readCodexModelCache(sourcePath).parsed;
|
|
2437
2568
|
const models = parsed.models.map((model, index) => {
|
|
2438
2569
|
if (!model || typeof model !== "object" || Array.isArray(model)) {
|
|
@@ -2502,12 +2633,12 @@ function createCodexTreeManager(host, options = {}) {
|
|
|
2502
2633
|
const previous = spawnChain;
|
|
2503
2634
|
let release;
|
|
2504
2635
|
let released = false;
|
|
2505
|
-
spawnChain = new Promise((
|
|
2636
|
+
spawnChain = new Promise((resolve5) => {
|
|
2506
2637
|
release = () => {
|
|
2507
2638
|
if (released)
|
|
2508
2639
|
return;
|
|
2509
2640
|
released = true;
|
|
2510
|
-
|
|
2641
|
+
resolve5();
|
|
2511
2642
|
};
|
|
2512
2643
|
});
|
|
2513
2644
|
await previous;
|
|
@@ -2614,7 +2745,7 @@ function createCodexTreeManager(host, options = {}) {
|
|
|
2614
2745
|
return;
|
|
2615
2746
|
const deadline = Date.now() + Math.max(0, graceMs);
|
|
2616
2747
|
while (Date.now() < deadline && hasSurvivors(plan.targets)) {
|
|
2617
|
-
await new Promise((
|
|
2748
|
+
await new Promise((resolve5) => setTimeout(resolve5, Math.min(100, Math.max(1, deadline - Date.now()))));
|
|
2618
2749
|
}
|
|
2619
2750
|
killStragglers(plan);
|
|
2620
2751
|
}
|
|
@@ -2667,17 +2798,17 @@ var killOwnedCodexTreesForShutdown = manager.killOwnedTreesForShutdown;
|
|
|
2667
2798
|
|
|
2668
2799
|
// ../../packages/core/src/agents/rollout/codex.ts
|
|
2669
2800
|
import { existsSync as existsSync4, readFileSync as readFileSync5, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync4 } from "fs";
|
|
2670
|
-
import { basename, dirname as
|
|
2801
|
+
import { basename, dirname as dirname6, join as join5, resolve as resolve5 } from "path";
|
|
2671
2802
|
function codexSessionsDir() {
|
|
2672
|
-
return
|
|
2803
|
+
return join5(hostedCodexHomePath(), "sessions");
|
|
2673
2804
|
}
|
|
2674
2805
|
function canonicalFilePath(path) {
|
|
2675
|
-
const absolute =
|
|
2806
|
+
const absolute = resolve5(path);
|
|
2676
2807
|
try {
|
|
2677
2808
|
return realpathSync2(absolute);
|
|
2678
2809
|
} catch {
|
|
2679
2810
|
try {
|
|
2680
|
-
return
|
|
2811
|
+
return join5(realpathSync2(dirname6(absolute)), basename(absolute));
|
|
2681
2812
|
} catch {
|
|
2682
2813
|
return absolute;
|
|
2683
2814
|
}
|
|
@@ -2907,19 +3038,19 @@ function latestCodexRolloutPath(threadId) {
|
|
|
2907
3038
|
try {
|
|
2908
3039
|
if (buckets) {
|
|
2909
3040
|
for (const bucket of buckets) {
|
|
2910
|
-
const dir =
|
|
3041
|
+
const dir = join5(sessionsDir, bucket);
|
|
2911
3042
|
if (!existsSync4(dir))
|
|
2912
3043
|
continue;
|
|
2913
3044
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
2914
3045
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
2915
|
-
candidates.push(
|
|
3046
|
+
candidates.push(join5(dir, rel));
|
|
2916
3047
|
}
|
|
2917
3048
|
}
|
|
2918
3049
|
}
|
|
2919
3050
|
if (candidates.length === 0) {
|
|
2920
3051
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
2921
3052
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
2922
|
-
candidates.push(
|
|
3053
|
+
candidates.push(join5(sessionsDir, rel));
|
|
2923
3054
|
}
|
|
2924
3055
|
}
|
|
2925
3056
|
return candidates.sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs)[0];
|
|
@@ -3071,7 +3202,7 @@ function codexMcpServerName(name) {
|
|
|
3071
3202
|
return CODEX_MCP_SERVER_NAME_OVERRIDES[name] ?? name;
|
|
3072
3203
|
}
|
|
3073
3204
|
function globalCodexMcpServerNames(authFilePath) {
|
|
3074
|
-
const configPath =
|
|
3205
|
+
const configPath = join6(dirname7(authFilePath), "config.toml");
|
|
3075
3206
|
if (!existsSync5(configPath))
|
|
3076
3207
|
return [];
|
|
3077
3208
|
try {
|
|
@@ -3170,9 +3301,9 @@ var CODEX_DIFF_BASELINE_FILE_LIMIT = 200;
|
|
|
3170
3301
|
var CODEX_DIFF_BASELINE_BYTE_LIMIT = 16 * 1024 * 1024;
|
|
3171
3302
|
function canonicalPath(path) {
|
|
3172
3303
|
try {
|
|
3173
|
-
return realpathSync3(
|
|
3304
|
+
return realpathSync3(resolve6(path));
|
|
3174
3305
|
} catch {
|
|
3175
|
-
return
|
|
3306
|
+
return resolve6(path);
|
|
3176
3307
|
}
|
|
3177
3308
|
}
|
|
3178
3309
|
function textFile(path, maxBytes = CODEX_DIFF_FILE_LIMIT) {
|
|
@@ -3216,7 +3347,7 @@ class CodexFilePreviewTracker {
|
|
|
3216
3347
|
const code = record.slice(0, 2);
|
|
3217
3348
|
const path = record.slice(3);
|
|
3218
3349
|
const remainingBytes = CODEX_DIFF_BASELINE_BYTE_LIMIT - loadedBytes;
|
|
3219
|
-
const content = loadedFiles < CODEX_DIFF_BASELINE_FILE_LIMIT && remainingBytes > 0 ? textFile(
|
|
3350
|
+
const content = loadedFiles < CODEX_DIFF_BASELINE_FILE_LIMIT && remainingBytes > 0 ? textFile(resolve6(this.#root, path), remainingBytes) : undefined;
|
|
3220
3351
|
this.#baseline.set(path, content);
|
|
3221
3352
|
if (typeof content === "string") {
|
|
3222
3353
|
loadedFiles += 1;
|
|
@@ -3229,7 +3360,7 @@ class CodexFilePreviewTracker {
|
|
|
3229
3360
|
preview(path, succeeded) {
|
|
3230
3361
|
if (!this.#root || !this.#baselineAvailable || !succeeded)
|
|
3231
3362
|
return {};
|
|
3232
|
-
const absolute = canonicalPath(isAbsolute(path) ? path :
|
|
3363
|
+
const absolute = canonicalPath(isAbsolute(path) ? path : resolve6(this.#cwd, path));
|
|
3233
3364
|
const relativePath = relative(this.#root, absolute);
|
|
3234
3365
|
if (!relativePath || relativePath.startsWith("..") || isAbsolute(relativePath))
|
|
3235
3366
|
return {};
|
|
@@ -3264,7 +3395,7 @@ class CodexFilePreviewTracker {
|
|
|
3264
3395
|
}
|
|
3265
3396
|
}
|
|
3266
3397
|
async function fileChangeEvents(item, previews, cwd, threadId, consumedPatchCallIds) {
|
|
3267
|
-
const expectedPaths = item.changes.map((change) => isAbsolute(change.path) ? change.path :
|
|
3398
|
+
const expectedPaths = item.changes.map((change) => isAbsolute(change.path) ? change.path : resolve6(cwd, change.path));
|
|
3268
3399
|
let nativePreview;
|
|
3269
3400
|
if (threadId && item.status === "completed") {
|
|
3270
3401
|
await new Promise((resolveDelay) => setTimeout(resolveDelay, 20));
|
|
@@ -3433,8 +3564,8 @@ async function* codexProvider(opts) {
|
|
|
3433
3564
|
mcpServerCount: Object.keys(codexMcpServers).length
|
|
3434
3565
|
}, "codexProvider: starting turn");
|
|
3435
3566
|
const hostedCodexHome = hostedCodexHomePath();
|
|
3436
|
-
const inheritedCodexHome = process.env.CODEX_HOME ||
|
|
3437
|
-
const codexEnvironment = scopedBrowserCapability ||
|
|
3567
|
+
const inheritedCodexHome = process.env.CODEX_HOME || join6(homedir3(), ".codex");
|
|
3568
|
+
const codexEnvironment = scopedBrowserCapability || resolve6(hostedCodexHome) !== resolve6(inheritedCodexHome) ? {
|
|
3438
3569
|
...Object.fromEntries(Object.entries(process.env).filter((entry) => typeof entry[1] === "string")),
|
|
3439
3570
|
CODEX_HOME: hostedCodexHome,
|
|
3440
3571
|
...scopedBrowserCapability ? { [CODEX_BROWSER_CAPABILITY_ENV]: scopedBrowserCapability } : {}
|
|
@@ -3712,7 +3843,7 @@ async function* codexProvider(opts) {
|
|
|
3712
3843
|
process.env.MAESTRO_SDK_SILENT_BOOTSTRAP ??= "1";
|
|
3713
3844
|
|
|
3714
3845
|
// ../../packages/core/src/agents/maestro-provider.ts
|
|
3715
|
-
import { resolve as
|
|
3846
|
+
import { resolve as resolve7 } from "path";
|
|
3716
3847
|
import { maestroProvider as sdkMaestroProvider, setMcpResolver } from "maestro-agent-sdk";
|
|
3717
3848
|
var MAESTRO_DEFAULT_MAX_TOKENS = 32768;
|
|
3718
3849
|
var PROVIDER_ASK_USER_TOOL = "AskUserQuestion";
|
|
@@ -3811,7 +3942,7 @@ function buildProviderOwnedToolBlockHook() {
|
|
|
3811
3942
|
}
|
|
3812
3943
|
};
|
|
3813
3944
|
}
|
|
3814
|
-
var MAESTRO_TOOL_OUTPUT_DIR =
|
|
3945
|
+
var MAESTRO_TOOL_OUTPUT_DIR = resolve7(RUN_DIR, "maestro-tool-outputs");
|
|
3815
3946
|
function buildMaestroToolResultTruncation(opts) {
|
|
3816
3947
|
if (opts.toolResultTruncation)
|
|
3817
3948
|
return opts.toolResultTruncation;
|
|
@@ -3846,16 +3977,16 @@ function maestroProvider(opts) {
|
|
|
3846
3977
|
// ../../packages/core/src/agents/claude-runtime-inspection.ts
|
|
3847
3978
|
import { readFileSync as readFileSync7 } from "fs";
|
|
3848
3979
|
import { createRequire as createRequire3 } from "module";
|
|
3849
|
-
import { dirname as
|
|
3980
|
+
import { dirname as dirname8, join as join7 } from "path";
|
|
3850
3981
|
var cached;
|
|
3851
3982
|
function inspectBundledClaudeRuntime() {
|
|
3852
3983
|
if (cached)
|
|
3853
3984
|
return cached;
|
|
3854
3985
|
try {
|
|
3855
3986
|
const require2 = createRequire3(import.meta.url);
|
|
3856
|
-
const sdkDir =
|
|
3857
|
-
const sdkPackage = JSON.parse(readFileSync7(
|
|
3858
|
-
const manifest = JSON.parse(readFileSync7(
|
|
3987
|
+
const sdkDir = dirname8(require2.resolve("@anthropic-ai/claude-agent-sdk"));
|
|
3988
|
+
const sdkPackage = JSON.parse(readFileSync7(join7(sdkDir, "package.json"), "utf8"));
|
|
3989
|
+
const manifest = JSON.parse(readFileSync7(join7(sdkDir, "manifest.json"), "utf8"));
|
|
3859
3990
|
const sdkVersion = typeof sdkPackage.version === "string" ? sdkPackage.version : "";
|
|
3860
3991
|
const claudeCodeVersion = typeof manifest.version === "string" ? manifest.version : "";
|
|
3861
3992
|
if (!sdkVersion || !claudeCodeVersion) {
|
|
@@ -3928,4 +4059,4 @@ export {
|
|
|
3928
4059
|
buildClaudeDisallowedTools
|
|
3929
4060
|
};
|
|
3930
4061
|
|
|
3931
|
-
//# debugId=
|
|
4062
|
+
//# debugId=8986D026DD1A3D4964756E2164756E21
|