negotium 0.2.18 → 0.2.20
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 +367 -313
- package/dist/agent-helpers.js.map +18 -18
- package/dist/background-bash.js +3 -2
- package/dist/background-bash.js.map +3 -3
- package/dist/browser-runtime.js +60 -36
- package/dist/browser-runtime.js.map +6 -6
- package/dist/{chunk-fc58cqry.js → chunk-g2kqfdwm.js} +154 -24
- package/dist/{chunk-fc58cqry.js.map → chunk-g2kqfdwm.js.map} +7 -6
- package/dist/hosted-agent.js +183 -53
- package/dist/hosted-agent.js.map +8 -7
- package/dist/main.js +1395 -626
- package/dist/main.js.map +27 -26
- package/dist/mcp-factories.js +1204 -624
- package/dist/mcp-factories.js.map +21 -20
- package/dist/prompts.js +3 -2
- package/dist/prompts.js.map +3 -3
- package/dist/query-runtime.js +47 -26
- package/dist/query-runtime.js.map +4 -4
- package/dist/registry.js +3 -3
- package/dist/registry.js.map +2 -2
- package/dist/rollout.js +1 -1
- package/dist/runtime/src/agents/archiver.ts +4 -3
- 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/canonical-proxy-server.ts +13 -14
- package/dist/runtime/src/mcp/session-comm/runtime.ts +16 -0
- package/dist/runtime/src/mcp/wiki-search-index.ts +359 -0
- package/dist/runtime/src/mcp/wiki-server.ts +559 -98
- package/dist/runtime/src/platform/config.ts +13 -1
- package/dist/runtime/src/platform/mcp-config.ts +1 -1
- package/dist/runtime/src/prompts/agents/wiki-archiver.md +62 -47
- 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 +47 -26
- package/dist/runtime-helpers.js.map +4 -4
- package/dist/storage.js +76 -41
- package/dist/storage.js.map +4 -4
- package/dist/types/packages/core/src/agents/archiver.d.ts +1 -1
- package/dist/types/packages/core/src/mcp/wiki-search-index.d.ts +59 -0
- 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 +140 -10
- package/dist/vault.js.map +6 -5
- package/package.json +1 -1
|
@@ -132,11 +132,12 @@ function versionAtLeast(actualVersion, minimumVersion) {
|
|
|
132
132
|
}
|
|
133
133
|
return true;
|
|
134
134
|
}
|
|
135
|
+
var BROWSER_RS_VERSION_PROBE_TIMEOUT_MS = 15000;
|
|
135
136
|
function browserRsMeetsMinimumVersion(candidate) {
|
|
136
137
|
try {
|
|
137
138
|
const output = execFileSync(candidate, ["--version"], {
|
|
138
139
|
encoding: "utf8",
|
|
139
|
-
timeout:
|
|
140
|
+
timeout: BROWSER_RS_VERSION_PROBE_TIMEOUT_MS,
|
|
140
141
|
stdio: ["ignore", "pipe", "ignore"]
|
|
141
142
|
}).trim();
|
|
142
143
|
const match = output.match(/^browser-rs (\d+)\.(\d+)\.(\d+)$/);
|
|
@@ -761,11 +762,11 @@ function isPoisonedAssistantEntry(entry) {
|
|
|
761
762
|
// ../../packages/core/src/agents/rollout/codex.ts
|
|
762
763
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
763
764
|
import { existsSync as existsSync3, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync3 } from "fs";
|
|
764
|
-
import { basename, dirname as
|
|
765
|
+
import { basename, dirname as dirname5, join as join5, resolve as resolve5 } from "path";
|
|
765
766
|
|
|
766
767
|
// ../../packages/core/src/agents/execution-host.ts
|
|
767
768
|
import { AsyncLocalStorage } from "async_hooks";
|
|
768
|
-
import { dirname as
|
|
769
|
+
import { dirname as dirname4 } from "path";
|
|
769
770
|
|
|
770
771
|
// ../../packages/core/src/security/sensitive-path.ts
|
|
771
772
|
import { realpathSync } from "fs";
|
|
@@ -1725,8 +1726,8 @@ function getMcpServersForQuery(opts) {
|
|
|
1725
1726
|
}
|
|
1726
1727
|
|
|
1727
1728
|
// ../../packages/core/src/storage/vault.ts
|
|
1728
|
-
import { chmodSync as chmodSync2, mkdirSync as
|
|
1729
|
-
import { join as
|
|
1729
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync5 } from "fs";
|
|
1730
|
+
import { join as join4 } from "path";
|
|
1730
1731
|
|
|
1731
1732
|
// ../../packages/core/src/storage/sqlite.ts
|
|
1732
1733
|
var isBun = typeof process.versions.bun === "string";
|
|
@@ -1779,6 +1780,134 @@ if (isBun) {
|
|
|
1779
1780
|
Database = NodeDatabase;
|
|
1780
1781
|
}
|
|
1781
1782
|
|
|
1783
|
+
// ../../packages/core/src/storage/storage-host.ts
|
|
1784
|
+
import { mkdirSync as mkdirSync4 } from "fs";
|
|
1785
|
+
import { homedir as homedir3 } from "os";
|
|
1786
|
+
import { dirname as dirname3, join as join3, resolve as resolve4 } from "path";
|
|
1787
|
+
var STORAGE_HOST_STATE = Symbol.for("negotium.storage-host.state.v1");
|
|
1788
|
+
function storageState() {
|
|
1789
|
+
const holder = globalThis;
|
|
1790
|
+
const existing = holder[STORAGE_HOST_STATE];
|
|
1791
|
+
if (existing)
|
|
1792
|
+
return existing;
|
|
1793
|
+
const created = {
|
|
1794
|
+
configuredHost: {},
|
|
1795
|
+
fallbackDatabase: null,
|
|
1796
|
+
fallbackDatabasePath: null,
|
|
1797
|
+
frames: [],
|
|
1798
|
+
schemaInitializers: [],
|
|
1799
|
+
initializedSchemas: new WeakMap,
|
|
1800
|
+
initializingDatabases: new WeakSet
|
|
1801
|
+
};
|
|
1802
|
+
Object.defineProperty(holder, STORAGE_HOST_STATE, {
|
|
1803
|
+
value: created,
|
|
1804
|
+
enumerable: false,
|
|
1805
|
+
writable: false,
|
|
1806
|
+
configurable: false
|
|
1807
|
+
});
|
|
1808
|
+
return created;
|
|
1809
|
+
}
|
|
1810
|
+
function envPath(name, fallback) {
|
|
1811
|
+
const value = process.env[name]?.trim();
|
|
1812
|
+
return resolve4(value || fallback);
|
|
1813
|
+
}
|
|
1814
|
+
function defaultStateDir() {
|
|
1815
|
+
return envPath("NEGOTIUM_STATE_DIR", join3(homedir3(), ".negotium"));
|
|
1816
|
+
}
|
|
1817
|
+
function defaultDataDir() {
|
|
1818
|
+
return envPath("NEGOTIUM_DATA_DIR", join3(defaultStateDir(), "data"));
|
|
1819
|
+
}
|
|
1820
|
+
function defaultSessionsDatabasePath() {
|
|
1821
|
+
return envPath("SESSIONS_DB_PATH", join3(resolveStorageDataDir(), "sessions.db"));
|
|
1822
|
+
}
|
|
1823
|
+
var SQLITE_INIT_RETRY_MS = 25;
|
|
1824
|
+
var SQLITE_INIT_TIMEOUT_MS = 5000;
|
|
1825
|
+
var SQLITE_INIT_SLEEP = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
|
1826
|
+
function isSqliteBusy(error) {
|
|
1827
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1828
|
+
return /database is (?:locked|busy)|SQLITE_(?:BUSY|LOCKED)/i.test(message);
|
|
1829
|
+
}
|
|
1830
|
+
function execWithBusyRetry(database, sql, timeoutMs = SQLITE_INIT_TIMEOUT_MS) {
|
|
1831
|
+
const deadline = Date.now() + timeoutMs;
|
|
1832
|
+
while (true) {
|
|
1833
|
+
try {
|
|
1834
|
+
database.exec(sql);
|
|
1835
|
+
return;
|
|
1836
|
+
} catch (error) {
|
|
1837
|
+
if (!isSqliteBusy(error) || Date.now() >= deadline)
|
|
1838
|
+
throw error;
|
|
1839
|
+
Atomics.wait(SQLITE_INIT_SLEEP, 0, 0, Math.min(SQLITE_INIT_RETRY_MS, deadline - Date.now()));
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
function initializeDatabase(database) {
|
|
1844
|
+
database.exec("PRAGMA busy_timeout = 5000");
|
|
1845
|
+
execWithBusyRetry(database, "PRAGMA journal_mode = WAL");
|
|
1846
|
+
database.exec("PRAGMA foreign_keys = ON");
|
|
1847
|
+
database.exec("PRAGMA wal_autocheckpoint = 1000");
|
|
1848
|
+
try {
|
|
1849
|
+
database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
1850
|
+
} catch {}
|
|
1851
|
+
}
|
|
1852
|
+
function defaultDatabase() {
|
|
1853
|
+
const path = defaultSessionsDatabasePath();
|
|
1854
|
+
const state = storageState();
|
|
1855
|
+
if (state.fallbackDatabase && state.fallbackDatabasePath === path)
|
|
1856
|
+
return state.fallbackDatabase;
|
|
1857
|
+
if (state.fallbackDatabase)
|
|
1858
|
+
state.fallbackDatabase.close();
|
|
1859
|
+
mkdirSync4(dirname3(path), { recursive: true });
|
|
1860
|
+
state.fallbackDatabase = new Database(path, { create: true });
|
|
1861
|
+
state.fallbackDatabasePath = path;
|
|
1862
|
+
initializeDatabase(state.fallbackDatabase);
|
|
1863
|
+
return state.fallbackDatabase;
|
|
1864
|
+
}
|
|
1865
|
+
function resolveStorageDatabase() {
|
|
1866
|
+
return storageState().configuredHost.database ?? defaultDatabase();
|
|
1867
|
+
}
|
|
1868
|
+
function resolveStorageDataDir() {
|
|
1869
|
+
return storageState().configuredHost.dataDir ?? defaultDataDir();
|
|
1870
|
+
}
|
|
1871
|
+
function ensureStorageSchemas(database = resolveStorageDatabase()) {
|
|
1872
|
+
const state = storageState();
|
|
1873
|
+
if (state.initializingDatabases.has(database))
|
|
1874
|
+
return;
|
|
1875
|
+
let initialized = state.initializedSchemas.get(database);
|
|
1876
|
+
if (!initialized) {
|
|
1877
|
+
initialized = new Set;
|
|
1878
|
+
state.initializedSchemas.set(database, initialized);
|
|
1879
|
+
}
|
|
1880
|
+
state.initializingDatabases.add(database);
|
|
1881
|
+
try {
|
|
1882
|
+
for (const entry of state.schemaInitializers) {
|
|
1883
|
+
if (initialized.has(entry.initialize))
|
|
1884
|
+
continue;
|
|
1885
|
+
initialized.add(entry.initialize);
|
|
1886
|
+
try {
|
|
1887
|
+
entry.initialize(database);
|
|
1888
|
+
} catch (error) {
|
|
1889
|
+
initialized.delete(entry.initialize);
|
|
1890
|
+
throw error;
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
} finally {
|
|
1894
|
+
state.initializingDatabases.delete(database);
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
var internalStorageDatabase = new Proxy({}, {
|
|
1898
|
+
get(_target, property) {
|
|
1899
|
+
const database = resolveStorageDatabase();
|
|
1900
|
+
ensureStorageSchemas(database);
|
|
1901
|
+
const value = Reflect.get(database, property, database);
|
|
1902
|
+
return typeof value === "function" ? value.bind(database) : value;
|
|
1903
|
+
},
|
|
1904
|
+
set(_target, property, value) {
|
|
1905
|
+
const database = resolveStorageDatabase();
|
|
1906
|
+
ensureStorageSchemas(database);
|
|
1907
|
+
return Reflect.set(database, property, value, database);
|
|
1908
|
+
}
|
|
1909
|
+
});
|
|
1910
|
+
|
|
1782
1911
|
// ../../packages/core/src/storage/vault-crypto-core.ts
|
|
1783
1912
|
import { createCipheriv, createDecipheriv, createHash as createHash2, randomBytes as randomBytes3 } from "crypto";
|
|
1784
1913
|
var ENVELOPE_PREFIX = "otium-vault:v1:";
|
|
@@ -1868,17 +1997,18 @@ function initializeVaultDatabase(database) {
|
|
|
1868
1997
|
}
|
|
1869
1998
|
}
|
|
1870
1999
|
function openVaultDatabase(dataDir) {
|
|
1871
|
-
const vaultDir =
|
|
1872
|
-
const path =
|
|
1873
|
-
|
|
2000
|
+
const vaultDir = join4(dataDir, "vault");
|
|
2001
|
+
const path = join4(vaultDir, "vault.db");
|
|
2002
|
+
mkdirSync5(vaultDir, { recursive: true, mode: 448 });
|
|
1874
2003
|
const database = new Database(path, { create: true });
|
|
1875
2004
|
chmodSync2(path, 384);
|
|
1876
2005
|
initializeVaultDatabase(database);
|
|
1877
2006
|
return database;
|
|
1878
2007
|
}
|
|
1879
2008
|
function activeVaultDatabase() {
|
|
1880
|
-
if (!vaultDb)
|
|
1881
|
-
vaultDb = openVaultDatabase(
|
|
2009
|
+
if (!vaultDb) {
|
|
2010
|
+
vaultDb = openVaultDatabase(resolveStorageDataDir());
|
|
2011
|
+
}
|
|
1882
2012
|
return vaultDb;
|
|
1883
2013
|
}
|
|
1884
2014
|
var VAULT_VALUE_MAX_BYTES = 64 * 1024;
|
|
@@ -1991,18 +2121,18 @@ function hostedCodexAuthFilePath() {
|
|
|
1991
2121
|
return activeHost().codexAuthFilePath();
|
|
1992
2122
|
}
|
|
1993
2123
|
function hostedCodexHomePath() {
|
|
1994
|
-
return
|
|
2124
|
+
return dirname4(hostedCodexAuthFilePath());
|
|
1995
2125
|
}
|
|
1996
2126
|
|
|
1997
2127
|
// ../../packages/core/src/agents/rollout/codex.ts
|
|
1998
2128
|
function codexSessionsDir() {
|
|
1999
|
-
return
|
|
2129
|
+
return join5(hostedCodexHomePath(), "sessions");
|
|
2000
2130
|
}
|
|
2001
2131
|
var _shellCache = null;
|
|
2002
2132
|
function loadCodexShell() {
|
|
2003
2133
|
if (_shellCache)
|
|
2004
2134
|
return _shellCache;
|
|
2005
|
-
const raw = readFileSync4(
|
|
2135
|
+
const raw = readFileSync4(join5(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
|
|
2006
2136
|
const lines = parseJsonlText(raw);
|
|
2007
2137
|
if (lines.length < 5) {
|
|
2008
2138
|
throw new Error(`loadCodexShell: expected >=5 entries in codex-shell.jsonl, got ${lines.length}`);
|
|
@@ -2069,16 +2199,16 @@ function codexRolloutPath(threadId, fallback) {
|
|
|
2069
2199
|
const hh = String(createdAt.getHours()).padStart(2, "0");
|
|
2070
2200
|
const min = String(createdAt.getMinutes()).padStart(2, "0");
|
|
2071
2201
|
const ss = String(createdAt.getSeconds()).padStart(2, "0");
|
|
2072
|
-
const dir =
|
|
2073
|
-
return
|
|
2202
|
+
const dir = join5(codexSessionsDir(), yyyy, mm, dd);
|
|
2203
|
+
return join5(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
|
|
2074
2204
|
}
|
|
2075
2205
|
function canonicalFilePath(path) {
|
|
2076
|
-
const absolute =
|
|
2206
|
+
const absolute = resolve5(path);
|
|
2077
2207
|
try {
|
|
2078
2208
|
return realpathSync2(absolute);
|
|
2079
2209
|
} catch {
|
|
2080
2210
|
try {
|
|
2081
|
-
return
|
|
2211
|
+
return join5(realpathSync2(dirname5(absolute)), basename(absolute));
|
|
2082
2212
|
} catch {
|
|
2083
2213
|
return absolute;
|
|
2084
2214
|
}
|
|
@@ -2267,19 +2397,19 @@ function latestCodexRolloutPath(threadId) {
|
|
|
2267
2397
|
try {
|
|
2268
2398
|
if (buckets) {
|
|
2269
2399
|
for (const bucket of buckets) {
|
|
2270
|
-
const dir =
|
|
2400
|
+
const dir = join5(sessionsDir, bucket);
|
|
2271
2401
|
if (!existsSync3(dir))
|
|
2272
2402
|
continue;
|
|
2273
2403
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
2274
2404
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
2275
|
-
candidates.push(
|
|
2405
|
+
candidates.push(join5(dir, rel));
|
|
2276
2406
|
}
|
|
2277
2407
|
}
|
|
2278
2408
|
}
|
|
2279
2409
|
if (candidates.length === 0) {
|
|
2280
2410
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
2281
2411
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
2282
|
-
candidates.push(
|
|
2412
|
+
candidates.push(join5(sessionsDir, rel));
|
|
2283
2413
|
}
|
|
2284
2414
|
}
|
|
2285
2415
|
return candidates.sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs)[0];
|
|
@@ -2400,13 +2530,13 @@ function sweepPriorRolloutsForThread(threadId) {
|
|
|
2400
2530
|
return;
|
|
2401
2531
|
}
|
|
2402
2532
|
for (const bucket of buckets) {
|
|
2403
|
-
const dir =
|
|
2533
|
+
const dir = join5(sessionsDir, bucket);
|
|
2404
2534
|
if (!existsSync3(dir))
|
|
2405
2535
|
continue;
|
|
2406
2536
|
try {
|
|
2407
2537
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
2408
2538
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
2409
|
-
const fullPath =
|
|
2539
|
+
const fullPath = join5(dir, rel);
|
|
2410
2540
|
try {
|
|
2411
2541
|
unlinkSync3(fullPath);
|
|
2412
2542
|
} catch (e) {
|
|
@@ -2424,7 +2554,7 @@ function sweepPriorRolloutsFullTree(threadId, sessionsDir) {
|
|
|
2424
2554
|
try {
|
|
2425
2555
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
2426
2556
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
2427
|
-
const fullPath =
|
|
2557
|
+
const fullPath = join5(sessionsDir, rel);
|
|
2428
2558
|
try {
|
|
2429
2559
|
unlinkSync3(fullPath);
|
|
2430
2560
|
} catch (e) {
|
|
@@ -2483,4 +2613,4 @@ function formatDateBucket(d) {
|
|
|
2483
2613
|
|
|
2484
2614
|
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 };
|
|
2485
2615
|
|
|
2486
|
-
//# debugId=
|
|
2616
|
+
//# debugId=3BC854CFD07F1E6C64756E2164756E21
|