negotium 0.2.2 → 0.2.3
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 +131 -133
- package/dist/agent-helpers.js.map +4 -4
- package/dist/{chunk-kc5kmr95.js → chunk-hsqgb2hw.js} +22 -24
- package/dist/{chunk-kc5kmr95.js.map → chunk-hsqgb2hw.js.map} +3 -3
- package/dist/hosted-agent.js +34 -36
- package/dist/hosted-agent.js.map +4 -4
- package/dist/main.js +291 -918
- package/dist/main.js.map +7 -9
- package/dist/mcp-factories.js +135 -137
- package/dist/mcp-factories.js.map +4 -4
- package/dist/registry.js +1 -1
- package/dist/rollout.js +1 -1
- package/dist/runtime/src/agents/rollout/shared.ts +3 -5
- package/dist/runtime/src/version.ts +1 -1
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/runtime/src/migration/single-user.ts +0 -805
package/dist/agent-helpers.js
CHANGED
|
@@ -373,8 +373,7 @@ function renderUserPromptBatch(prompts) {
|
|
|
373
373
|
|
|
374
374
|
// ../../packages/core/src/agents/rollout/shared.ts
|
|
375
375
|
import { mkdirSync as mkdirSync2 } from "fs";
|
|
376
|
-
import {
|
|
377
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
376
|
+
import { resolve as resolve2 } from "path";
|
|
378
377
|
function clone(obj) {
|
|
379
378
|
return structuredClone(obj);
|
|
380
379
|
}
|
|
@@ -505,18 +504,17 @@ ${toolBuffer.join(`
|
|
|
505
504
|
flushAssistant();
|
|
506
505
|
return pairs;
|
|
507
506
|
}
|
|
508
|
-
var
|
|
507
|
+
var trustedWorkspaceRoots, FIXTURES_DIR, UUID_RE;
|
|
509
508
|
var init_shared = __esm(() => {
|
|
510
509
|
init_config();
|
|
511
510
|
init_logger();
|
|
512
|
-
__dirname2 = dirname2(fileURLToPath2(import.meta.url));
|
|
513
511
|
trustedWorkspaceRoots = [
|
|
514
512
|
WORKSPACE_DIR,
|
|
515
513
|
DM_WORKSPACE_DIR,
|
|
516
514
|
SESSION_WORKSPACE_DIR,
|
|
517
515
|
TOPIC_WORKSPACE_DIR
|
|
518
516
|
].map((root) => resolve2(root));
|
|
519
|
-
FIXTURES_DIR =
|
|
517
|
+
FIXTURES_DIR = resolve2(PROJECT_ROOT, "src", "agents", "fixtures");
|
|
520
518
|
UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
521
519
|
});
|
|
522
520
|
|
|
@@ -559,7 +557,7 @@ import {
|
|
|
559
557
|
unlinkSync as unlinkSync2,
|
|
560
558
|
writeFileSync as writeFileSync2
|
|
561
559
|
} from "fs";
|
|
562
|
-
import { dirname as
|
|
560
|
+
import { dirname as dirname2 } from "path";
|
|
563
561
|
function parseJsonlText(raw) {
|
|
564
562
|
return raw.trim().split(`
|
|
565
563
|
`).filter(Boolean).map((line) => JSON.parse(line));
|
|
@@ -596,7 +594,7 @@ function appendJsonlEntry(filePath, entry) {
|
|
|
596
594
|
`);
|
|
597
595
|
}
|
|
598
596
|
function appendJsonlLine(filePath, line) {
|
|
599
|
-
mkdirSync3(
|
|
597
|
+
mkdirSync3(dirname2(filePath), { recursive: true });
|
|
600
598
|
const lockPath = `${filePath}${LOCK_SUFFIX}`;
|
|
601
599
|
const payload = line.endsWith(`
|
|
602
600
|
`) ? line : `${line}
|
|
@@ -627,7 +625,7 @@ function appendJsonlLine(filePath, line) {
|
|
|
627
625
|
}
|
|
628
626
|
}
|
|
629
627
|
function writeJsonlFile(filePath, entries) {
|
|
630
|
-
const dir =
|
|
628
|
+
const dir = dirname2(filePath);
|
|
631
629
|
mkdirSync3(dir, { recursive: true });
|
|
632
630
|
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
633
631
|
const payload = `${entries.map((e) => JSON.stringify(e)).join(`
|
|
@@ -687,11 +685,11 @@ var init_jsonl = __esm(() => {
|
|
|
687
685
|
import { randomUUID } from "crypto";
|
|
688
686
|
import { existsSync as existsSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
689
687
|
import { homedir as homedir2 } from "os";
|
|
690
|
-
import { join as
|
|
688
|
+
import { join as join2 } from "path";
|
|
691
689
|
function loadClaudeAttachments() {
|
|
692
690
|
if (_attachmentsCache)
|
|
693
691
|
return _attachmentsCache;
|
|
694
|
-
const raw = readFileSync3(
|
|
692
|
+
const raw = readFileSync3(join2(FIXTURES_DIR, "claude-attachments.jsonl"), "utf8");
|
|
695
693
|
const lines = parseJsonlText(raw);
|
|
696
694
|
if (lines.length < 2) {
|
|
697
695
|
throw new Error(`loadClaudeAttachments: expected >=2 entries in claude-attachments.jsonl, got ${lines.length}`);
|
|
@@ -792,8 +790,8 @@ function writeClaudeRollout(opts) {
|
|
|
792
790
|
});
|
|
793
791
|
lastUuid = assistantUuid;
|
|
794
792
|
}
|
|
795
|
-
const projectsDir =
|
|
796
|
-
const path =
|
|
793
|
+
const projectsDir = join2(homedir2(), ".claude", "projects", encodeClaudeCwd(opts.cwd));
|
|
794
|
+
const path = join2(projectsDir, `${sessionId}.jsonl`);
|
|
797
795
|
writeJsonlFile(path, lines);
|
|
798
796
|
logger.info({ sessionId, path, pairs: pairs.length }, "writeClaudeRollout: synthetic rollout placed");
|
|
799
797
|
return { sessionId, rolloutPath: path };
|
|
@@ -808,7 +806,7 @@ var init_claude = __esm(() => {
|
|
|
808
806
|
// ../../packages/core/src/agents/claude-registry.ts
|
|
809
807
|
import { existsSync as existsSync3, mkdirSync as mkdirSync4, readdirSync, renameSync as renameSync2, unlinkSync as unlinkSync3 } from "fs";
|
|
810
808
|
import { homedir as homedir3 } from "os";
|
|
811
|
-
import { join as
|
|
809
|
+
import { join as join3 } from "path";
|
|
812
810
|
var ALIAS_MAP, VALID_ALIASES, VALID_EFFORTS, claudeRegistry, claudeRegistryOperations;
|
|
813
811
|
var init_claude_registry = __esm(() => {
|
|
814
812
|
init_claude();
|
|
@@ -855,11 +853,11 @@ var init_claude_registry = __esm(() => {
|
|
|
855
853
|
const result = await forkSession(parentSessionId, {
|
|
856
854
|
...title ? { title } : {}
|
|
857
855
|
});
|
|
858
|
-
const projectsRoot =
|
|
859
|
-
const destDir =
|
|
860
|
-
const destPath =
|
|
856
|
+
const projectsRoot = join3(homedir3(), ".claude", "projects");
|
|
857
|
+
const destDir = join3(projectsRoot, encodeClaudeCwd(cwd));
|
|
858
|
+
const destPath = join3(destDir, `${result.sessionId}.jsonl`);
|
|
861
859
|
if (!existsSync3(destPath)) {
|
|
862
|
-
const sourcePath = readdirSync(projectsRoot).map((d) =>
|
|
860
|
+
const sourcePath = readdirSync(projectsRoot).map((d) => join3(projectsRoot, d, `${result.sessionId}.jsonl`)).find((p) => existsSync3(p));
|
|
863
861
|
if (!sourcePath) {
|
|
864
862
|
throw new Error(`claude forkSession: fork rollout ${result.sessionId}.jsonl not found under ${projectsRoot}`);
|
|
865
863
|
}
|
|
@@ -872,10 +870,10 @@ var init_claude_registry = __esm(() => {
|
|
|
872
870
|
};
|
|
873
871
|
},
|
|
874
872
|
async cleanupRollouts({ cwd, sessionIds }) {
|
|
875
|
-
const projectsDir =
|
|
873
|
+
const projectsDir = join3(homedir3(), ".claude", "projects", encodeClaudeCwd(cwd));
|
|
876
874
|
const failures = [];
|
|
877
875
|
for (const sid of sessionIds) {
|
|
878
|
-
const path =
|
|
876
|
+
const path = join3(projectsDir, `${sid}.jsonl`);
|
|
879
877
|
try {
|
|
880
878
|
unlinkSync3(path);
|
|
881
879
|
} catch (e) {
|
|
@@ -896,14 +894,14 @@ var init_claude_registry = __esm(() => {
|
|
|
896
894
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
897
895
|
import { existsSync as existsSync4, readFileSync as readFileSync4, realpathSync, statSync as statSync2, unlinkSync as unlinkSync4 } from "fs";
|
|
898
896
|
import { homedir as homedir4 } from "os";
|
|
899
|
-
import { basename, dirname as
|
|
897
|
+
import { basename, dirname as dirname3, join as join4, resolve as resolve3 } from "path";
|
|
900
898
|
function codexSessionsDir() {
|
|
901
|
-
return
|
|
899
|
+
return join4(process.env.CODEX_HOME || join4(homedir4(), ".codex"), "sessions");
|
|
902
900
|
}
|
|
903
901
|
function loadCodexShell() {
|
|
904
902
|
if (_shellCache)
|
|
905
903
|
return _shellCache;
|
|
906
|
-
const raw = readFileSync4(
|
|
904
|
+
const raw = readFileSync4(join4(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
|
|
907
905
|
const lines = parseJsonlText(raw);
|
|
908
906
|
if (lines.length < 5) {
|
|
909
907
|
throw new Error(`loadCodexShell: expected >=5 entries in codex-shell.jsonl, got ${lines.length}`);
|
|
@@ -967,7 +965,7 @@ function canonicalFilePath(path) {
|
|
|
967
965
|
return realpathSync(absolute);
|
|
968
966
|
} catch {
|
|
969
967
|
try {
|
|
970
|
-
return
|
|
968
|
+
return join4(realpathSync(dirname3(absolute)), basename(absolute));
|
|
971
969
|
} catch {
|
|
972
970
|
return absolute;
|
|
973
971
|
}
|
|
@@ -1156,19 +1154,19 @@ function latestCodexRolloutPath(threadId) {
|
|
|
1156
1154
|
try {
|
|
1157
1155
|
if (buckets) {
|
|
1158
1156
|
for (const bucket of buckets) {
|
|
1159
|
-
const dir =
|
|
1157
|
+
const dir = join4(sessionsDir, bucket);
|
|
1160
1158
|
if (!existsSync4(dir))
|
|
1161
1159
|
continue;
|
|
1162
1160
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
1163
1161
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
1164
|
-
candidates.push(
|
|
1162
|
+
candidates.push(join4(dir, rel));
|
|
1165
1163
|
}
|
|
1166
1164
|
}
|
|
1167
1165
|
}
|
|
1168
1166
|
if (candidates.length === 0) {
|
|
1169
1167
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
1170
1168
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
1171
|
-
candidates.push(
|
|
1169
|
+
candidates.push(join4(sessionsDir, rel));
|
|
1172
1170
|
}
|
|
1173
1171
|
}
|
|
1174
1172
|
return candidates.sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs)[0];
|
|
@@ -1277,8 +1275,8 @@ function writeCodexRollout(opts) {
|
|
|
1277
1275
|
const mm = String(now.getUTCMonth() + 1).padStart(2, "0");
|
|
1278
1276
|
const dd = String(now.getUTCDate()).padStart(2, "0");
|
|
1279
1277
|
const tsStr = tsIso.replace(/[:.]/g, "-").slice(0, 19);
|
|
1280
|
-
const dir =
|
|
1281
|
-
const path =
|
|
1278
|
+
const dir = join4(codexSessionsDir(), String(yyyy), mm, dd);
|
|
1279
|
+
const path = join4(dir, `rollout-${tsStr}-${threadId}.jsonl`);
|
|
1282
1280
|
if (opts.threadId) {
|
|
1283
1281
|
sweepPriorRolloutsForThread(opts.threadId);
|
|
1284
1282
|
}
|
|
@@ -1294,13 +1292,13 @@ function sweepPriorRolloutsForThread(threadId) {
|
|
|
1294
1292
|
return;
|
|
1295
1293
|
}
|
|
1296
1294
|
for (const bucket of buckets) {
|
|
1297
|
-
const dir =
|
|
1295
|
+
const dir = join4(sessionsDir, bucket);
|
|
1298
1296
|
if (!existsSync4(dir))
|
|
1299
1297
|
continue;
|
|
1300
1298
|
try {
|
|
1301
1299
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
1302
1300
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
1303
|
-
const fullPath =
|
|
1301
|
+
const fullPath = join4(dir, rel);
|
|
1304
1302
|
try {
|
|
1305
1303
|
unlinkSync4(fullPath);
|
|
1306
1304
|
} catch (e) {
|
|
@@ -1318,7 +1316,7 @@ function sweepPriorRolloutsFullTree(threadId, sessionsDir) {
|
|
|
1318
1316
|
try {
|
|
1319
1317
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
1320
1318
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
1321
|
-
const fullPath =
|
|
1319
|
+
const fullPath = join4(sessionsDir, rel);
|
|
1322
1320
|
try {
|
|
1323
1321
|
unlinkSync4(fullPath);
|
|
1324
1322
|
} catch (e) {
|
|
@@ -1449,29 +1447,29 @@ var init_sqlite = __esm(async () => {
|
|
|
1449
1447
|
// ../../packages/core/src/storage/storage-host.ts
|
|
1450
1448
|
import { mkdirSync as mkdirSync5 } from "fs";
|
|
1451
1449
|
import { homedir as homedir5 } from "os";
|
|
1452
|
-
import { dirname as
|
|
1450
|
+
import { dirname as dirname4, join as join5, resolve as resolve4 } from "path";
|
|
1453
1451
|
function envPath(name, fallback) {
|
|
1454
1452
|
const value = process.env[name]?.trim();
|
|
1455
1453
|
return resolve4(value || fallback);
|
|
1456
1454
|
}
|
|
1457
1455
|
function defaultStateDir() {
|
|
1458
|
-
return envPath("NEGOTIUM_STATE_DIR",
|
|
1456
|
+
return envPath("NEGOTIUM_STATE_DIR", join5(homedir5(), ".negotium"));
|
|
1459
1457
|
}
|
|
1460
1458
|
function defaultDataDir() {
|
|
1461
|
-
return envPath("NEGOTIUM_DATA_DIR",
|
|
1459
|
+
return envPath("NEGOTIUM_DATA_DIR", join5(defaultStateDir(), "data"));
|
|
1462
1460
|
}
|
|
1463
1461
|
function defaultLogDir() {
|
|
1464
|
-
return envPath("NEGOTIUM_LOG_DIR",
|
|
1462
|
+
return envPath("NEGOTIUM_LOG_DIR", join5(defaultStateDir(), "logs"));
|
|
1465
1463
|
}
|
|
1466
1464
|
function defaultWorkspaceDir() {
|
|
1467
|
-
return envPath("NEGOTIUM_WORKSPACE_DIR",
|
|
1465
|
+
return envPath("NEGOTIUM_WORKSPACE_DIR", join5(defaultStateDir(), "workspace"));
|
|
1468
1466
|
}
|
|
1469
1467
|
function defaultSessionAsksDir() {
|
|
1470
|
-
const runDir = envPath("NEGOTIUM_RUN_DIR",
|
|
1471
|
-
return
|
|
1468
|
+
const runDir = envPath("NEGOTIUM_RUN_DIR", join5(defaultStateDir(), "runtime"));
|
|
1469
|
+
return join5(runDir, "session-asks");
|
|
1472
1470
|
}
|
|
1473
1471
|
function defaultSessionsDatabasePath() {
|
|
1474
|
-
return envPath("SESSIONS_DB_PATH",
|
|
1472
|
+
return envPath("SESSIONS_DB_PATH", join5(resolveStorageDataDir(), "sessions.db"));
|
|
1475
1473
|
}
|
|
1476
1474
|
function initializeDatabase(database) {
|
|
1477
1475
|
database.exec("PRAGMA busy_timeout = 5000");
|
|
@@ -1488,7 +1486,7 @@ function defaultDatabase() {
|
|
|
1488
1486
|
return fallbackDatabase;
|
|
1489
1487
|
if (fallbackDatabase)
|
|
1490
1488
|
fallbackDatabase.close();
|
|
1491
|
-
mkdirSync5(
|
|
1489
|
+
mkdirSync5(dirname4(path), { recursive: true });
|
|
1492
1490
|
fallbackDatabase = new Database(path, { create: true });
|
|
1493
1491
|
fallbackDatabasePath = path;
|
|
1494
1492
|
initializeDatabase(fallbackDatabase);
|
|
@@ -1510,7 +1508,7 @@ function resolveStorageWorkspaceDir() {
|
|
|
1510
1508
|
return configuredHost.workspaceDir ?? defaultWorkspaceDir();
|
|
1511
1509
|
}
|
|
1512
1510
|
function resolveStorageSharedWikiDir() {
|
|
1513
|
-
return configuredHost.sharedWikiDir ??
|
|
1511
|
+
return configuredHost.sharedWikiDir ?? join5(resolveStorageWorkspaceDir(), "wiki");
|
|
1514
1512
|
}
|
|
1515
1513
|
function registerStorageSchemaInitializer(initialize, priority = 100) {
|
|
1516
1514
|
schemaInitializers.push({ initialize, priority });
|
|
@@ -1572,16 +1570,16 @@ import {
|
|
|
1572
1570
|
unlinkSync as unlinkSync5,
|
|
1573
1571
|
writeFileSync as writeFileSync4
|
|
1574
1572
|
} from "fs";
|
|
1575
|
-
import { dirname as
|
|
1573
|
+
import { dirname as dirname5, join as join6 } from "path";
|
|
1576
1574
|
function conversationDir(_userId) {
|
|
1577
|
-
return
|
|
1575
|
+
return join6(resolveStorageDataDir(), "conversations");
|
|
1578
1576
|
}
|
|
1579
1577
|
function topicFilename(topicName) {
|
|
1580
1578
|
const t = sanitizeTopicName(topicName, true);
|
|
1581
1579
|
return `${t}.jsonl`;
|
|
1582
1580
|
}
|
|
1583
1581
|
function getConversationPath(userId, topicName) {
|
|
1584
|
-
return
|
|
1582
|
+
return join6(conversationDir(userId), topicFilename(topicName));
|
|
1585
1583
|
}
|
|
1586
1584
|
function getActiveConversationPath(userId, topicName) {
|
|
1587
1585
|
const rawPath = getConversationPath(userId, topicName);
|
|
@@ -1607,7 +1605,7 @@ function appendConversationEventStrict(userId, topicName, agent, event) {
|
|
|
1607
1605
|
event
|
|
1608
1606
|
};
|
|
1609
1607
|
const line = JSON.stringify(entry);
|
|
1610
|
-
mkdirSync6(
|
|
1608
|
+
mkdirSync6(dirname5(path), { recursive: true });
|
|
1611
1609
|
appendJsonlLine(path, line);
|
|
1612
1610
|
const activePath = getActiveConversationPath(userId, topicName);
|
|
1613
1611
|
if (existsSync5(activePath)) {
|
|
@@ -1656,7 +1654,7 @@ function replaceRawConversationStrict(userId, topicName, entries) {
|
|
|
1656
1654
|
}
|
|
1657
1655
|
function replaceConversationPathStrict(path, entries) {
|
|
1658
1656
|
const tempPath = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
1659
|
-
mkdirSync6(
|
|
1657
|
+
mkdirSync6(dirname5(path), { recursive: true });
|
|
1660
1658
|
try {
|
|
1661
1659
|
writeFileSync4(tempPath, entries.length > 0 ? `${entries.map((entry) => JSON.stringify(entry)).join(`
|
|
1662
1660
|
`)}
|
|
@@ -1702,7 +1700,7 @@ var init_conversations = __esm(async () => {
|
|
|
1702
1700
|
// ../../packages/core/src/agents/codex-registry.ts
|
|
1703
1701
|
import { existsSync as existsSync6, unlinkSync as unlinkSync6 } from "fs";
|
|
1704
1702
|
import { homedir as homedir6 } from "os";
|
|
1705
|
-
import { join as
|
|
1703
|
+
import { join as join7 } from "path";
|
|
1706
1704
|
var VALID_EFFORTS2, codexRegistry, codexRegistryOperations;
|
|
1707
1705
|
var init_codex_registry = __esm(async () => {
|
|
1708
1706
|
init_codex();
|
|
@@ -1751,7 +1749,7 @@ var init_codex_registry = __esm(async () => {
|
|
|
1751
1749
|
async cleanupRollouts({ sessionIds }) {
|
|
1752
1750
|
if (sessionIds.length === 0)
|
|
1753
1751
|
return;
|
|
1754
|
-
const sessionsDir =
|
|
1752
|
+
const sessionsDir = join7(process.env.CODEX_HOME || join7(homedir6(), ".codex"), "sessions");
|
|
1755
1753
|
if (!existsSync6(sessionsDir))
|
|
1756
1754
|
return;
|
|
1757
1755
|
const failures = [];
|
|
@@ -1759,7 +1757,7 @@ var init_codex_registry = __esm(async () => {
|
|
|
1759
1757
|
try {
|
|
1760
1758
|
const glob = new Bun.Glob(`**/rollout-*-${tid}.jsonl`);
|
|
1761
1759
|
for await (const rel of glob.scan({ cwd: sessionsDir, onlyFiles: true })) {
|
|
1762
|
-
const path =
|
|
1760
|
+
const path = join7(sessionsDir, rel);
|
|
1763
1761
|
try {
|
|
1764
1762
|
unlinkSync6(path);
|
|
1765
1763
|
} catch (e) {
|
|
@@ -1785,15 +1783,15 @@ var init_codex_registry = __esm(async () => {
|
|
|
1785
1783
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
1786
1784
|
import { existsSync as existsSync7, mkdirSync as mkdirSync7, readFileSync as readFileSync6, writeFileSync as writeFileSync5 } from "fs";
|
|
1787
1785
|
import { homedir as homedir7 } from "os";
|
|
1788
|
-
import { join as
|
|
1786
|
+
import { join as join8, resolve as resolve5 } from "path";
|
|
1789
1787
|
function maestroSessionsDir() {
|
|
1790
|
-
return
|
|
1788
|
+
return join8(process.env.MAESTRO_DATA_DIR ? resolve5(process.env.MAESTRO_DATA_DIR) : join8(homedir7(), ".maestro"), "sessions");
|
|
1791
1789
|
}
|
|
1792
1790
|
function maestroSessionPath(sessionId) {
|
|
1793
|
-
return
|
|
1791
|
+
return join8(maestroSessionsDir(), `${sessionId}.jsonl`);
|
|
1794
1792
|
}
|
|
1795
1793
|
function maestroActiveSessionPath(sessionId) {
|
|
1796
|
-
return
|
|
1794
|
+
return join8(maestroSessionsDir(), `${sessionId}.active.jsonl`);
|
|
1797
1795
|
}
|
|
1798
1796
|
function existingCreatedAt(path) {
|
|
1799
1797
|
if (!existsSync7(path))
|
|
@@ -1938,7 +1936,7 @@ var init_registry = __esm(async () => {
|
|
|
1938
1936
|
|
|
1939
1937
|
// ../../packages/core/src/storage/tasks.ts
|
|
1940
1938
|
import { existsSync as existsSync8, mkdirSync as mkdirSync8, readFileSync as readFileSync7, renameSync as renameSync4, statSync as statSync3, writeFileSync as writeFileSync6 } from "fs";
|
|
1941
|
-
import { dirname as
|
|
1939
|
+
import { dirname as dirname6, join as join9 } from "path";
|
|
1942
1940
|
function safeTaskScopeKey(scopeKey) {
|
|
1943
1941
|
const safe = sanitizeFileName(scopeKey);
|
|
1944
1942
|
if (!safe || safe === "." || safe === "..") {
|
|
@@ -1950,7 +1948,7 @@ function taskScopeKey(opts) {
|
|
|
1950
1948
|
return opts.topicId?.trim() || opts.session || "default";
|
|
1951
1949
|
}
|
|
1952
1950
|
function getTaskFilePath(userId, scopeKey) {
|
|
1953
|
-
return
|
|
1951
|
+
return join9(resolveStorageDataDir(), "tasks", `${safeTaskScopeKey(scopeKey)}.json`);
|
|
1954
1952
|
}
|
|
1955
1953
|
function readTasks(userId, scopeKey) {
|
|
1956
1954
|
const path = getTaskFilePath(userId, scopeKey);
|
|
@@ -3029,7 +3027,7 @@ var init_vault_crypto = __esm(() => {
|
|
|
3029
3027
|
|
|
3030
3028
|
// ../../packages/core/src/storage/vault.ts
|
|
3031
3029
|
import { chmodSync as chmodSync2, mkdirSync as mkdirSync9 } from "fs";
|
|
3032
|
-
import { join as
|
|
3030
|
+
import { join as join10 } from "path";
|
|
3033
3031
|
function initializeVaultDatabase(database) {
|
|
3034
3032
|
database.exec("PRAGMA journal_mode = WAL");
|
|
3035
3033
|
database.exec("PRAGMA busy_timeout = 5000");
|
|
@@ -3064,8 +3062,8 @@ function initializeVaultDatabase(database) {
|
|
|
3064
3062
|
}
|
|
3065
3063
|
}
|
|
3066
3064
|
function openVaultDatabase(dataDir) {
|
|
3067
|
-
const vaultDir =
|
|
3068
|
-
const path =
|
|
3065
|
+
const vaultDir = join10(dataDir, "vault");
|
|
3066
|
+
const path = join10(vaultDir, "vault.db");
|
|
3069
3067
|
mkdirSync9(vaultDir, { recursive: true, mode: 448 });
|
|
3070
3068
|
const database = new Database(path, { create: true });
|
|
3071
3069
|
chmodSync2(path, 384);
|
|
@@ -3785,7 +3783,7 @@ var init_claude_provider = __esm(async () => {
|
|
|
3785
3783
|
});
|
|
3786
3784
|
|
|
3787
3785
|
// ../../packages/core/src/version.ts
|
|
3788
|
-
var NEGOTIUM_VERSION = "0.2.
|
|
3786
|
+
var NEGOTIUM_VERSION = "0.2.3";
|
|
3789
3787
|
|
|
3790
3788
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
3791
3789
|
import { spawn as spawn3 } from "child_process";
|
|
@@ -3803,7 +3801,7 @@ import {
|
|
|
3803
3801
|
} from "fs";
|
|
3804
3802
|
import { createRequire as createRequire2 } from "module";
|
|
3805
3803
|
import { tmpdir } from "os";
|
|
3806
|
-
import { dirname as
|
|
3804
|
+
import { dirname as dirname7, join as join11 } from "path";
|
|
3807
3805
|
function readPackageVersion(packageJsonPath) {
|
|
3808
3806
|
const parsed = JSON.parse(readFileSync9(packageJsonPath, "utf8"));
|
|
3809
3807
|
if (typeof parsed.version !== "string" || !parsed.version.trim()) {
|
|
@@ -3812,7 +3810,7 @@ function readPackageVersion(packageJsonPath) {
|
|
|
3812
3810
|
return parsed.version;
|
|
3813
3811
|
}
|
|
3814
3812
|
function codexCliScriptPath() {
|
|
3815
|
-
return
|
|
3813
|
+
return join11(dirname7(bundledCodexPackagePath), "bin", "codex.js");
|
|
3816
3814
|
}
|
|
3817
3815
|
function parseCodexModelCache(contents, sourcePath) {
|
|
3818
3816
|
let parsed;
|
|
@@ -3853,7 +3851,7 @@ function writePrivateFileAtomic(path, contents) {
|
|
|
3853
3851
|
}
|
|
3854
3852
|
}
|
|
3855
3853
|
function bundledCodexModelCachePath(authFilePath) {
|
|
3856
|
-
return
|
|
3854
|
+
return join11(dirname7(authFilePath), NEGOTIUM_MODEL_CACHE);
|
|
3857
3855
|
}
|
|
3858
3856
|
async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
3859
3857
|
const child = spawn3(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
|
|
@@ -3938,16 +3936,16 @@ async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
|
3938
3936
|
});
|
|
3939
3937
|
}
|
|
3940
3938
|
async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
|
|
3941
|
-
const sourceHome =
|
|
3942
|
-
const isolatedHome = mkdtempSync(
|
|
3943
|
-
const isolatedCachePath =
|
|
3939
|
+
const sourceHome = dirname7(authFilePath);
|
|
3940
|
+
const isolatedHome = mkdtempSync(join11(tmpdir(), "negotium-codex-models-"));
|
|
3941
|
+
const isolatedCachePath = join11(isolatedHome, "models_cache.json");
|
|
3944
3942
|
try {
|
|
3945
|
-
const isolatedAuthPath =
|
|
3943
|
+
const isolatedAuthPath = join11(isolatedHome, "auth.json");
|
|
3946
3944
|
copyFileSync(authFilePath, isolatedAuthPath);
|
|
3947
3945
|
chmodSync3(isolatedAuthPath, 384);
|
|
3948
|
-
const sourceConfigPath =
|
|
3946
|
+
const sourceConfigPath = join11(sourceHome, "config.toml");
|
|
3949
3947
|
if (existsSync10(sourceConfigPath)) {
|
|
3950
|
-
const isolatedConfigPath =
|
|
3948
|
+
const isolatedConfigPath = join11(isolatedHome, "config.toml");
|
|
3951
3949
|
copyFileSync(sourceConfigPath, isolatedConfigPath);
|
|
3952
3950
|
chmodSync3(isolatedConfigPath, 384);
|
|
3953
3951
|
}
|
|
@@ -3958,7 +3956,7 @@ async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
|
|
|
3958
3956
|
}
|
|
3959
3957
|
}
|
|
3960
3958
|
async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexModelCache) {
|
|
3961
|
-
const codexHome =
|
|
3959
|
+
const codexHome = dirname7(authFilePath);
|
|
3962
3960
|
const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
|
|
3963
3961
|
if (configuredCachePath) {
|
|
3964
3962
|
if (!existsSync10(configuredCachePath)) {
|
|
@@ -3968,7 +3966,7 @@ async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexMod
|
|
|
3968
3966
|
return configuredCachePath;
|
|
3969
3967
|
}
|
|
3970
3968
|
const bundledCachePath = bundledCodexModelCachePath(authFilePath);
|
|
3971
|
-
const sharedCachePath =
|
|
3969
|
+
const sharedCachePath = join11(codexHome, "models_cache.json");
|
|
3972
3970
|
if (existsSync10(sharedCachePath)) {
|
|
3973
3971
|
try {
|
|
3974
3972
|
const shared = readCompatibleCodexModelCache(sharedCachePath);
|
|
@@ -3987,8 +3985,8 @@ async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexMod
|
|
|
3987
3985
|
return bundledCachePath;
|
|
3988
3986
|
}
|
|
3989
3987
|
function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
|
|
3990
|
-
const codexHome =
|
|
3991
|
-
const outputPath =
|
|
3988
|
+
const codexHome = dirname7(authFilePath);
|
|
3989
|
+
const outputPath = join11(codexHome, NEGOTIUM_MODEL_CATALOG);
|
|
3992
3990
|
const parsed = readCodexModelCache(sourcePath).parsed;
|
|
3993
3991
|
const models = parsed.models.map((model, index) => {
|
|
3994
3992
|
if (!model || typeof model !== "object" || Array.isArray(model)) {
|
|
@@ -4758,7 +4756,7 @@ __export(exports_codex_provider, {
|
|
|
4758
4756
|
});
|
|
4759
4757
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
4760
4758
|
import { existsSync as existsSync11, readFileSync as readFileSync11, realpathSync as realpathSync3, statSync as statSync5 } from "fs";
|
|
4761
|
-
import { dirname as
|
|
4759
|
+
import { dirname as dirname8, isAbsolute as isAbsolute2, join as join12, relative, resolve as resolve8 } from "path";
|
|
4762
4760
|
import { Codex } from "@openai/codex-sdk";
|
|
4763
4761
|
function mapEffort(effort) {
|
|
4764
4762
|
if (!effort)
|
|
@@ -4772,7 +4770,7 @@ function codexMcpServerName(name) {
|
|
|
4772
4770
|
return CODEX_MCP_SERVER_NAME_OVERRIDES[name] ?? name;
|
|
4773
4771
|
}
|
|
4774
4772
|
function globalCodexMcpServerNames(authFilePath) {
|
|
4775
|
-
const configPath =
|
|
4773
|
+
const configPath = join12(dirname8(authFilePath), "config.toml");
|
|
4776
4774
|
if (!existsSync11(configPath))
|
|
4777
4775
|
return [];
|
|
4778
4776
|
try {
|
|
@@ -5568,7 +5566,7 @@ var init_maestro_provider = __esm(async () => {
|
|
|
5568
5566
|
// ../../packages/core/src/agents/index.ts
|
|
5569
5567
|
import { existsSync as existsSync12 } from "fs";
|
|
5570
5568
|
import { homedir as homedir8 } from "os";
|
|
5571
|
-
import { join as
|
|
5569
|
+
import { join as join13 } from "path";
|
|
5572
5570
|
async function* dispatchAgent(opts) {
|
|
5573
5571
|
switch (opts.agent) {
|
|
5574
5572
|
case "claude": {
|
|
@@ -5602,11 +5600,11 @@ async function resolveSessionFileMissing(agent, sessionId, cwd) {
|
|
|
5602
5600
|
switch (agent) {
|
|
5603
5601
|
case "claude": {
|
|
5604
5602
|
const encodedCwd = encodeClaudeCwd(cwd);
|
|
5605
|
-
const path =
|
|
5603
|
+
const path = join13(homedir8(), ".claude", "projects", encodedCwd, `${sessionId}.jsonl`);
|
|
5606
5604
|
return !existsSync12(path);
|
|
5607
5605
|
}
|
|
5608
5606
|
case "codex": {
|
|
5609
|
-
const sessionsDir =
|
|
5607
|
+
const sessionsDir = join13(process.env.CODEX_HOME || join13(homedir8(), ".codex"), "sessions");
|
|
5610
5608
|
const glob = new Bun.Glob(`**/rollout-*-${sessionId}.jsonl`);
|
|
5611
5609
|
for await (const _rel of glob.scan({ cwd: sessionsDir, onlyFiles: true })) {
|
|
5612
5610
|
return false;
|
|
@@ -6838,9 +6836,9 @@ var init_api_topic_brief = __esm(async () => {
|
|
|
6838
6836
|
});
|
|
6839
6837
|
|
|
6840
6838
|
// ../../packages/core/src/storage/wiki.ts
|
|
6841
|
-
import { basename as basename2, dirname as
|
|
6839
|
+
import { basename as basename2, dirname as dirname9, join as join14 } from "path";
|
|
6842
6840
|
function getSharedWikiDir(workspaceDir = resolveStorageWorkspaceDir()) {
|
|
6843
|
-
return workspaceDir === resolveStorageWorkspaceDir() ? resolveStorageSharedWikiDir() :
|
|
6841
|
+
return workspaceDir === resolveStorageWorkspaceDir() ? resolveStorageSharedWikiDir() : join14(workspaceDir, "wiki");
|
|
6844
6842
|
}
|
|
6845
6843
|
var init_wiki = __esm(async () => {
|
|
6846
6844
|
await init_storage_host();
|
|
@@ -7582,7 +7580,7 @@ var init_personal_general = __esm(async () => {
|
|
|
7582
7580
|
// ../../packages/core/src/agents/archiver.ts
|
|
7583
7581
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
7584
7582
|
import { existsSync as existsSync13, readdirSync as readdirSync2, readFileSync as readFileSync13, statSync as statSync6 } from "fs";
|
|
7585
|
-
import { join as
|
|
7583
|
+
import { join as join15 } from "path";
|
|
7586
7584
|
function resolveMemoryLanguage() {
|
|
7587
7585
|
const override = process.env.NEGOTIUM_MEMORY_LANG?.trim();
|
|
7588
7586
|
return override && override.length > 0 ? override : resolveOutputLanguage();
|
|
@@ -7833,10 +7831,10 @@ function distillOneLine(summaryMd) {
|
|
|
7833
7831
|
return "";
|
|
7834
7832
|
}
|
|
7835
7833
|
function findSummaryFile(storage, topicTitle, date, sinceMs, topicId) {
|
|
7836
|
-
const dir =
|
|
7834
|
+
const dir = join15(storage.getWikiDir(), "summaries");
|
|
7837
7835
|
if (!storage.fileExists(dir))
|
|
7838
7836
|
return null;
|
|
7839
|
-
const predicted =
|
|
7837
|
+
const predicted = join15(dir, wikiSummaryFilename(date, topicTitle, topicId));
|
|
7840
7838
|
if (storage.fileExists(predicted) && storage.fileModifiedAt(predicted) >= sinceMs)
|
|
7841
7839
|
return predicted;
|
|
7842
7840
|
let best = null;
|
|
@@ -7844,7 +7842,7 @@ function findSummaryFile(storage, topicTitle, date, sinceMs, topicId) {
|
|
|
7844
7842
|
if (!f.startsWith(`${date}-`) || !isTopicSummaryFile(f, topicId ?? "", topicTitle)) {
|
|
7845
7843
|
continue;
|
|
7846
7844
|
}
|
|
7847
|
-
const p =
|
|
7845
|
+
const p = join15(dir, f);
|
|
7848
7846
|
try {
|
|
7849
7847
|
const m = storage.fileModifiedAt(p);
|
|
7850
7848
|
if (m >= sinceMs && (!best || m > best.mtime))
|
|
@@ -7973,7 +7971,7 @@ __export(exports_auth_check, {
|
|
|
7973
7971
|
import { execFileSync as execFileSync5 } from "child_process";
|
|
7974
7972
|
import { existsSync as existsSync14 } from "fs";
|
|
7975
7973
|
import { homedir as homedir9, platform } from "os";
|
|
7976
|
-
import { join as
|
|
7974
|
+
import { join as join16 } from "path";
|
|
7977
7975
|
function hasMaestroCredential(host, key, userId) {
|
|
7978
7976
|
if (userId && host.getVaultValue(userId, key)?.trim())
|
|
7979
7977
|
return true;
|
|
@@ -8002,7 +8000,7 @@ function checkAgentAuth(agent, host = defaultAgentAuthHost, userId) {
|
|
|
8002
8000
|
error: "claude is not logged in (no macOS keychain entry 'Claude Code-credentials'). Run `claude` and complete login first"
|
|
8003
8001
|
};
|
|
8004
8002
|
}
|
|
8005
|
-
const path =
|
|
8003
|
+
const path = join16(host.homeDirectory(), ".claude", ".credentials.json");
|
|
8006
8004
|
if (host.exists(path))
|
|
8007
8005
|
return { ok: true };
|
|
8008
8006
|
return {
|
|
@@ -8749,13 +8747,13 @@ function formatTopicArchiveTranscriptRecord(row, topicTitle, index) {
|
|
|
8749
8747
|
|
|
8750
8748
|
// ../../packages/core/src/storage/topic-archive.ts
|
|
8751
8749
|
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync8 } from "fs";
|
|
8752
|
-
import { join as
|
|
8750
|
+
import { join as join17 } from "path";
|
|
8753
8751
|
function archiveTopicMessages(topicId, topicTitle, options = {}) {
|
|
8754
8752
|
const rows = options.afterRowid !== undefined ? getMessagesForTopicAfterRowid(topicId, options.afterRowid) : getAllMessagesForTopic(topicId);
|
|
8755
8753
|
if (rows.length === 0)
|
|
8756
8754
|
return null;
|
|
8757
8755
|
const safeTopic = sanitizeTopicName(topicTitle, true);
|
|
8758
|
-
const archiveDir =
|
|
8756
|
+
const archiveDir = join17(getSharedWikiDir(), "archive");
|
|
8759
8757
|
mkdirSync10(archiveDir, { recursive: true });
|
|
8760
8758
|
const date = new Date().toISOString().slice(0, 10);
|
|
8761
8759
|
const reasonSuffix = options.reason && options.reason !== "delete" ? `_${options.reason}` : "";
|
|
@@ -8768,7 +8766,7 @@ function archiveTopicMessages(topicId, topicTitle, options = {}) {
|
|
|
8768
8766
|
let path;
|
|
8769
8767
|
while (true) {
|
|
8770
8768
|
filename = `${safeTopic}_${date}${reasonSuffix}${counter === 1 ? "" : `_${counter}`}.jsonl`;
|
|
8771
|
-
path =
|
|
8769
|
+
path = join17(archiveDir, filename);
|
|
8772
8770
|
try {
|
|
8773
8771
|
writeFileSync8(path, body, { flag: "wx" });
|
|
8774
8772
|
break;
|
|
@@ -8813,7 +8811,7 @@ function archiveConversationEvents(topicId, topicTitle, userId, options = {}) {
|
|
|
8813
8811
|
const entries = readRawConversation(userId, topicTitle);
|
|
8814
8812
|
if (entries.length === 0)
|
|
8815
8813
|
return null;
|
|
8816
|
-
const archiveDir =
|
|
8814
|
+
const archiveDir = join17(getSharedWikiDir(), "archive");
|
|
8817
8815
|
mkdirSync10(archiveDir, { recursive: true });
|
|
8818
8816
|
const safeTopic = sanitizeTopicName(topicTitle, true);
|
|
8819
8817
|
const date = new Date().toISOString().slice(0, 10);
|
|
@@ -8841,7 +8839,7 @@ function archiveConversationEvents(topicId, topicTitle, userId, options = {}) {
|
|
|
8841
8839
|
let counter = 1;
|
|
8842
8840
|
while (true) {
|
|
8843
8841
|
const suffix = counter === 1 ? "" : `_${counter}`;
|
|
8844
|
-
const path =
|
|
8842
|
+
const path = join17(archiveDir, `${safeTopic}_${date}${reasonSuffix}_events${suffix}.jsonl`);
|
|
8845
8843
|
try {
|
|
8846
8844
|
writeFileSync8(path, body, { flag: "wx" });
|
|
8847
8845
|
logger.info({ topicId, topicTitle, archive: path, eventCount: entries.length }, "archiveConversationEvents: archived raw conversation events");
|
|
@@ -10289,7 +10287,7 @@ import { randomBytes as randomBytes5, timingSafeEqual as timingSafeEqual2 } from
|
|
|
10289
10287
|
import { chmodSync as chmodSync4 } from "fs";
|
|
10290
10288
|
import { createServer as createServer2 } from "net";
|
|
10291
10289
|
import { tmpdir as tmpdir2 } from "os";
|
|
10292
|
-
import { join as
|
|
10290
|
+
import { join as join18 } from "path";
|
|
10293
10291
|
function deepMapStrings2(value, transform) {
|
|
10294
10292
|
if (typeof value === "string")
|
|
10295
10293
|
return transform(value);
|
|
@@ -10376,7 +10374,7 @@ function authorized(actual, expected) {
|
|
|
10376
10374
|
}
|
|
10377
10375
|
async function createBrowserVaultBroker(userId) {
|
|
10378
10376
|
const token = randomBytes5(32).toString("hex");
|
|
10379
|
-
const socketPath =
|
|
10377
|
+
const socketPath = join18(process.platform === "win32" ? tmpdir2() : "/tmp", `negotium-browser-vault-${process.pid}-${randomBytes5(8).toString("hex")}.sock`);
|
|
10380
10378
|
const retainedForms = new Map;
|
|
10381
10379
|
const leases = new Map;
|
|
10382
10380
|
const sockets = new Set;
|
|
@@ -10580,7 +10578,7 @@ import {
|
|
|
10580
10578
|
unlinkSync as unlinkSync11,
|
|
10581
10579
|
writeFileSync as writeFileSync9
|
|
10582
10580
|
} from "fs";
|
|
10583
|
-
import { dirname as
|
|
10581
|
+
import { dirname as dirname10, join as join19, resolve as resolve13 } from "path";
|
|
10584
10582
|
function makeInstanceKey(userId, topic) {
|
|
10585
10583
|
return resolvePlaywrightTopicBinding(userId, topic).instanceKey;
|
|
10586
10584
|
}
|
|
@@ -10660,14 +10658,14 @@ function portFileName(instanceKey) {
|
|
|
10660
10658
|
function writePortFile(instanceKey, port) {
|
|
10661
10659
|
try {
|
|
10662
10660
|
mkdirSync11(managerHost.portsDir, { recursive: true });
|
|
10663
|
-
writeFileSync9(
|
|
10661
|
+
writeFileSync9(join19(managerHost.portsDir, portFileName(instanceKey)), String(port));
|
|
10664
10662
|
} catch (e) {
|
|
10665
10663
|
logger.warn({ err: e, instanceKey, port }, "Failed to save playwright port file");
|
|
10666
10664
|
}
|
|
10667
10665
|
}
|
|
10668
10666
|
function deletePortFile(instanceKey) {
|
|
10669
10667
|
try {
|
|
10670
|
-
unlinkSync11(
|
|
10668
|
+
unlinkSync11(join19(managerHost.portsDir, portFileName(instanceKey)));
|
|
10671
10669
|
} catch (e) {
|
|
10672
10670
|
logger.warn({ err: e, instanceKey }, "Failed to delete playwright port file");
|
|
10673
10671
|
}
|
|
@@ -11157,7 +11155,7 @@ async function cloneProfileForChild(opts) {
|
|
|
11157
11155
|
if (existsSync16(dstDir)) {
|
|
11158
11156
|
rmSync3(dstDir, { recursive: true, force: true });
|
|
11159
11157
|
}
|
|
11160
|
-
mkdirSync11(
|
|
11158
|
+
mkdirSync11(dirname10(dstDir), { recursive: true });
|
|
11161
11159
|
if (process.platform === "darwin") {
|
|
11162
11160
|
try {
|
|
11163
11161
|
execFileSync7("cp", ["-cR", srcDir, dstDir], { stdio: "pipe" });
|
|
@@ -11304,7 +11302,7 @@ RULES:
|
|
|
11304
11302
|
|
|
11305
11303
|
// ../../packages/core/src/agents/topic-cleanup.ts
|
|
11306
11304
|
import { mkdirSync as mkdirSync12, renameSync as renameSync6, unlinkSync as unlinkSync12, writeFileSync as writeFileSync10 } from "fs";
|
|
11307
|
-
import { dirname as
|
|
11305
|
+
import { dirname as dirname11 } from "path";
|
|
11308
11306
|
function collectSessionIdsByAgent(entries, extraSessions = []) {
|
|
11309
11307
|
const out = new Map;
|
|
11310
11308
|
for (const e of entries) {
|
|
@@ -11370,7 +11368,7 @@ function createTopicLogMaintenance(host) {
|
|
|
11370
11368
|
const path = runtimeHost.activeConversationPath(opts.userId, opts.topicName);
|
|
11371
11369
|
const tempPath = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
11372
11370
|
try {
|
|
11373
|
-
mkdirSync12(
|
|
11371
|
+
mkdirSync12(dirname11(path), { recursive: true });
|
|
11374
11372
|
writeFileSync10(tempPath, retained.length > 0 ? `${retained.map((entry) => JSON.stringify(entry)).join(`
|
|
11375
11373
|
`)}
|
|
11376
11374
|
` : "", { flag: "wx" });
|
|
@@ -11803,7 +11801,7 @@ var init_runtime_turn_requests = __esm(async () => {
|
|
|
11803
11801
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
11804
11802
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync4, writeFileSync as writeFileSync11 } from "fs";
|
|
11805
11803
|
import { tmpdir as tmpdir3 } from "os";
|
|
11806
|
-
import { join as
|
|
11804
|
+
import { join as join20 } from "path";
|
|
11807
11805
|
function previousCompactedSummary(entries) {
|
|
11808
11806
|
for (let index = entries.length - 2;index >= 0; index -= 1) {
|
|
11809
11807
|
const request = entries[index]?.event;
|
|
@@ -11933,7 +11931,7 @@ function formatCompactElapsed(startedAt) {
|
|
|
11933
11931
|
async function summarizeTopicContext(request) {
|
|
11934
11932
|
const startedAt = Date.now();
|
|
11935
11933
|
const sessionIds = [];
|
|
11936
|
-
const compactCwd = mkdtempSync2(
|
|
11934
|
+
const compactCwd = mkdtempSync2(join20(tmpdir3(), "negotium-compact-"));
|
|
11937
11935
|
const abortController = new AbortController;
|
|
11938
11936
|
const relayAbort = () => abortController.abort(request.signal?.reason);
|
|
11939
11937
|
if (request.signal?.aborted)
|
|
@@ -11960,7 +11958,7 @@ async function summarizeTopicContext(request) {
|
|
|
11960
11958
|
let error = "";
|
|
11961
11959
|
let toolViolation = false;
|
|
11962
11960
|
let compactionLogCalls = 0;
|
|
11963
|
-
const compactionLogPath =
|
|
11961
|
+
const compactionLogPath = join20(compactCwd, "conversation.log");
|
|
11964
11962
|
try {
|
|
11965
11963
|
const compactionMcp = useCompactionLog ? {
|
|
11966
11964
|
compact_log: {
|
|
@@ -12556,14 +12554,14 @@ var init_derive = __esm(async () => {
|
|
|
12556
12554
|
});
|
|
12557
12555
|
|
|
12558
12556
|
// ../../packages/core/src/query/session-inbox-path.ts
|
|
12559
|
-
import { join as
|
|
12557
|
+
import { join as join21 } from "path";
|
|
12560
12558
|
function sessionInboxPath(userId, topicId) {
|
|
12561
12559
|
const key = Buffer.from(topicId, "utf8").toString("base64url");
|
|
12562
|
-
return
|
|
12560
|
+
return join21(SESSION_INBOX_DIR, userId, `${TOPIC_ID_FILE_PREFIX}${key}${JSONL_SUFFIX}`);
|
|
12563
12561
|
}
|
|
12564
12562
|
function scheduledSessionInboxPath(userId, topicId) {
|
|
12565
12563
|
const key = Buffer.from(topicId, "utf8").toString("base64url");
|
|
12566
|
-
return
|
|
12564
|
+
return join21(SESSION_INBOX_DIR, userId, `${TOPIC_ID_FILE_PREFIX}${key}${SCHEDULE_SUFFIX}`);
|
|
12567
12565
|
}
|
|
12568
12566
|
var TOPIC_ID_FILE_PREFIX = "topic-id-", JSONL_SUFFIX = ".jsonl", SCHEDULE_SUFFIX = ".schedule";
|
|
12569
12567
|
var init_session_inbox_path = __esm(() => {
|
|
@@ -12572,13 +12570,13 @@ var init_session_inbox_path = __esm(() => {
|
|
|
12572
12570
|
|
|
12573
12571
|
// ../../packages/core/src/query/session-inbox-cleanup.ts
|
|
12574
12572
|
import { unlinkSync as unlinkSync14 } from "fs";
|
|
12575
|
-
import { basename as basename3, join as
|
|
12573
|
+
import { basename as basename3, join as join22 } from "path";
|
|
12576
12574
|
function cleanupSessionInboxFiles(userId, topicId, legacyTopicTitle) {
|
|
12577
12575
|
const live = sessionInboxPath(userId, topicId);
|
|
12578
12576
|
const scheduled = scheduledSessionInboxPath(userId, topicId);
|
|
12579
12577
|
const candidates = new Set([live, `${live}.processing`, scheduled, `${scheduled}.processing`]);
|
|
12580
12578
|
if (legacyTopicTitle && legacyTopicTitle !== "." && legacyTopicTitle !== ".." && basename3(legacyTopicTitle) === legacyTopicTitle) {
|
|
12581
|
-
const legacyBase =
|
|
12579
|
+
const legacyBase = join22(SESSION_INBOX_DIR, userId, legacyTopicTitle);
|
|
12582
12580
|
for (const suffix of [".jsonl", ".jsonl.processing", ".schedule", ".schedule.processing"]) {
|
|
12583
12581
|
candidates.add(`${legacyBase}${suffix}`);
|
|
12584
12582
|
}
|
|
@@ -12604,16 +12602,16 @@ var init_session_inbox_cleanup = __esm(() => {
|
|
|
12604
12602
|
|
|
12605
12603
|
// ../../packages/core/src/query/state.ts
|
|
12606
12604
|
import { mkdirSync as mkdirSync14, renameSync as renameSync7, unlinkSync as unlinkSync15, writeFileSync as writeFileSync12 } from "fs";
|
|
12607
|
-
import { basename as basename4, join as
|
|
12605
|
+
import { basename as basename4, join as join23 } from "path";
|
|
12608
12606
|
function createQueryStateStore(options) {
|
|
12609
12607
|
const sanitize = options.sanitizeTopicId ?? sanitizeId;
|
|
12610
|
-
const queryStateDirPath = (userId) =>
|
|
12611
|
-
const queryStateFile = (userId, topicId) =>
|
|
12608
|
+
const queryStateDirPath = (userId) => join23(options.usersLogDir, String(userId), "active-queries");
|
|
12609
|
+
const queryStateFile = (userId, topicId) => join23(queryStateDirPath(userId), `${sanitize(topicId)}.json`);
|
|
12612
12610
|
const legacyQueryStateFile = (userId, topicName) => {
|
|
12613
12611
|
if (!topicName || topicName === "." || topicName === ".." || basename4(topicName) !== topicName) {
|
|
12614
12612
|
return null;
|
|
12615
12613
|
}
|
|
12616
|
-
return
|
|
12614
|
+
return join23(queryStateDirPath(userId), `${topicName}.json`);
|
|
12617
12615
|
};
|
|
12618
12616
|
return {
|
|
12619
12617
|
write(userId, topicId, topicName, task) {
|
|
@@ -12773,30 +12771,30 @@ import {
|
|
|
12773
12771
|
unlinkSync as unlinkSync16,
|
|
12774
12772
|
writeFileSync as writeFileSync13
|
|
12775
12773
|
} from "fs";
|
|
12776
|
-
import { dirname as
|
|
12774
|
+
import { dirname as dirname12, join as join24 } from "path";
|
|
12777
12775
|
function pendingAskDir(userId) {
|
|
12778
12776
|
const rawUserId = String(userId);
|
|
12779
12777
|
const safeUserId = /^[A-Za-z0-9][A-Za-z0-9_.@-]{0,255}$/.test(rawUserId) && !rawUserId.includes("..") ? rawUserId : `sha256-${createHash5("sha256").update(rawUserId).digest("hex")}`;
|
|
12780
|
-
return
|
|
12778
|
+
return join24(resolveStorageSessionAsksDir(), safeUserId);
|
|
12781
12779
|
}
|
|
12782
12780
|
function encodeAskKey(key) {
|
|
12783
12781
|
return JSON.stringify([key.from, key.to]);
|
|
12784
12782
|
}
|
|
12785
12783
|
function pendingAskPath(key) {
|
|
12786
12784
|
const digest = createHash5("sha256").update(encodeAskKey(key)).digest("hex");
|
|
12787
|
-
return
|
|
12785
|
+
return join24(pendingAskDir(key.userId), `${ASK_FILENAME_PREFIX}${digest}.pending`);
|
|
12788
12786
|
}
|
|
12789
12787
|
function v2PendingAskPath(key) {
|
|
12790
12788
|
const encoded = Buffer.from(encodeAskKey(key), "utf8").toString("base64url");
|
|
12791
|
-
return
|
|
12789
|
+
return join24(pendingAskDir(key.userId), `${V2_ASK_FILENAME_PREFIX}${encoded}.pending`);
|
|
12792
12790
|
}
|
|
12793
12791
|
function legacyPendingAskPath(key) {
|
|
12794
12792
|
if (key.from.includes("/") || key.from.includes("\\") || key.to.includes("/") || key.to.includes("\\") || key.from.includes("\x00") || key.to.includes("\x00")) {
|
|
12795
12793
|
return null;
|
|
12796
12794
|
}
|
|
12797
12795
|
const dir = pendingAskDir(key.userId);
|
|
12798
|
-
const candidate =
|
|
12799
|
-
return
|
|
12796
|
+
const candidate = join24(dir, `${key.from}___${key.to}.pending`);
|
|
12797
|
+
return dirname12(candidate) === dir ? candidate : null;
|
|
12800
12798
|
}
|
|
12801
12799
|
function parsePendingAskFilename(fileName) {
|
|
12802
12800
|
if (!fileName.endsWith(".pending"))
|
|
@@ -13036,7 +13034,7 @@ function listPendingAsksForCaller(args) {
|
|
|
13036
13034
|
const parsed = isV3 ? { from: args.from, to: "" } : parsePendingAskFilename(fileName);
|
|
13037
13035
|
if (!parsed)
|
|
13038
13036
|
continue;
|
|
13039
|
-
const path =
|
|
13037
|
+
const path = join24(dir, fileName);
|
|
13040
13038
|
const record = readPendingAskFile(path, {
|
|
13041
13039
|
userId: args.userId,
|
|
13042
13040
|
from: parsed.from,
|
|
@@ -13078,7 +13076,7 @@ function deletePendingAsksForTopic(args) {
|
|
|
13078
13076
|
}
|
|
13079
13077
|
let deleted = 0;
|
|
13080
13078
|
for (const fileName of files) {
|
|
13081
|
-
const path =
|
|
13079
|
+
const path = join24(dir, fileName);
|
|
13082
13080
|
const parsed = parsePendingAskFilename(fileName);
|
|
13083
13081
|
const record = readPendingAskFile(path, {
|
|
13084
13082
|
userId: args.userId,
|
|
@@ -13710,7 +13708,7 @@ var init_lifecycle = __esm(async () => {
|
|
|
13710
13708
|
// ../../packages/core/src/runtime/attachments.ts
|
|
13711
13709
|
import { randomUUID as randomUUID14 } from "crypto";
|
|
13712
13710
|
import { copyFileSync as copyFileSync2, mkdirSync as mkdirSync16, writeFileSync as writeFileSync14 } from "fs";
|
|
13713
|
-
import { basename as basename5, join as
|
|
13711
|
+
import { basename as basename5, join as join25 } from "path";
|
|
13714
13712
|
function workspaceCwdFor(topicId) {
|
|
13715
13713
|
return resolveTopicWorkspaceDir(topicId);
|
|
13716
13714
|
}
|
|
@@ -13723,7 +13721,7 @@ function materializePromptAttachments(topicId, queryId, attachmentIds) {
|
|
|
13723
13721
|
if (!attachmentIds?.length)
|
|
13724
13722
|
return [];
|
|
13725
13723
|
const out = [];
|
|
13726
|
-
const destDir =
|
|
13724
|
+
const destDir = join25(workspaceCwdFor(topicId), "attachments", queryId);
|
|
13727
13725
|
for (const rawId of attachmentIds) {
|
|
13728
13726
|
if (typeof rawId !== "string")
|
|
13729
13727
|
continue;
|
|
@@ -13740,7 +13738,7 @@ function materializePromptAttachments(topicId, queryId, attachmentIds) {
|
|
|
13740
13738
|
mkdirSync16(destDir, { recursive: true });
|
|
13741
13739
|
const index = String(out.length + 1).padStart(2, "0");
|
|
13742
13740
|
const safeName = safeAttachmentFilename(attachment.filename, fileId);
|
|
13743
|
-
const destPath =
|
|
13741
|
+
const destPath = join25(destDir, `${index}-${fileId.slice(0, 8)}-${safeName}`);
|
|
13744
13742
|
copyFileSync2(sourcePath, destPath);
|
|
13745
13743
|
out.push({
|
|
13746
13744
|
id: attachment.id,
|
|
@@ -13770,10 +13768,10 @@ function promptWithAttachments(prompt, attachments) {
|
|
|
13770
13768
|
return composeAttachmentPrompt(prompt, attachments.map(({ filename, path }) => attachmentPromptLine(filename, path)));
|
|
13771
13769
|
}
|
|
13772
13770
|
function ingestAttachment(args) {
|
|
13773
|
-
const destDir =
|
|
13771
|
+
const destDir = join25(UPLOADS_DIR, args.topicId);
|
|
13774
13772
|
mkdirSync16(destDir, { recursive: true });
|
|
13775
13773
|
const safeName = safeAttachmentFilename(args.filename, "upload");
|
|
13776
|
-
const destPath =
|
|
13774
|
+
const destPath = join25(destDir, `${Date.now()}-${randomUUID14().slice(0, 8)}-${safeName}`);
|
|
13777
13775
|
if (args.sourcePath !== undefined) {
|
|
13778
13776
|
copyFileSync2(args.sourcePath, destPath);
|
|
13779
13777
|
} else if (args.bytes !== undefined) {
|
|
@@ -14364,7 +14362,7 @@ var init_visuals = __esm(async () => {
|
|
|
14364
14362
|
// ../../packages/core/src/storage/token-stats.ts
|
|
14365
14363
|
import { createHash as createHash6 } from "crypto";
|
|
14366
14364
|
import { mkdirSync as mkdirSync17 } from "fs";
|
|
14367
|
-
import { join as
|
|
14365
|
+
import { join as join26 } from "path";
|
|
14368
14366
|
function tokenStatsFileId(userId) {
|
|
14369
14367
|
const rawUserId = String(userId);
|
|
14370
14368
|
return /^[A-Za-z0-9][A-Za-z0-9_.@-]{0,255}$/.test(rawUserId) && !rawUserId.includes("..") ? rawUserId : `sha256-${createHash6("sha256").update(rawUserId).digest("hex")}`;
|
|
@@ -14373,7 +14371,7 @@ function queriesPath(userId) {
|
|
|
14373
14371
|
const fileId = tokenStatsFileId(userId);
|
|
14374
14372
|
const logDir = resolveStorageLogDir();
|
|
14375
14373
|
mkdirSync17(logDir, { recursive: true });
|
|
14376
|
-
return
|
|
14374
|
+
return join26(logDir, `token-queries-${fileId}.jsonl`);
|
|
14377
14375
|
}
|
|
14378
14376
|
function recordUsage(userId, session, usage) {
|
|
14379
14377
|
const record = {
|
|
@@ -14981,9 +14979,9 @@ var init_turn_session = __esm(async () => {
|
|
|
14981
14979
|
|
|
14982
14980
|
// ../../packages/core/src/storage/app-settings.ts
|
|
14983
14981
|
import { existsSync as existsSync17, mkdirSync as mkdirSync18, readFileSync as readFileSync16, writeFileSync as writeFileSync15 } from "fs";
|
|
14984
|
-
import { dirname as
|
|
14982
|
+
import { dirname as dirname13, join as join27 } from "path";
|
|
14985
14983
|
function settingsFile() {
|
|
14986
|
-
return
|
|
14984
|
+
return join27(resolveStorageDataDir(), "otium-settings.json");
|
|
14987
14985
|
}
|
|
14988
14986
|
function ensureSettingsLoaded() {
|
|
14989
14987
|
const path = settingsFile();
|
|
@@ -15083,7 +15081,7 @@ __export(exports_turn_runner, {
|
|
|
15083
15081
|
});
|
|
15084
15082
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
15085
15083
|
import { existsSync as existsSync18, mkdirSync as mkdirSync19, readdirSync as readdirSync5, statSync as statSync9 } from "fs";
|
|
15086
|
-
import { join as
|
|
15084
|
+
import { join as join28 } from "path";
|
|
15087
15085
|
function withDefaultPlaywright(configuredMcp, isManager) {
|
|
15088
15086
|
if (isManager)
|
|
15089
15087
|
return configuredMcp;
|
|
@@ -15126,7 +15124,7 @@ function appendAskReplyMessage(topicId, text2, agentType) {
|
|
|
15126
15124
|
return message;
|
|
15127
15125
|
}
|
|
15128
15126
|
function resolveWikiMirrorPath(directory, preferredFilename, matchesLegacyId, matchesTitle, preferExact = true) {
|
|
15129
|
-
const preferred =
|
|
15127
|
+
const preferred = join28(directory, preferredFilename);
|
|
15130
15128
|
if (preferExact && existsSync18(preferred))
|
|
15131
15129
|
return preferred;
|
|
15132
15130
|
let newestLegacyId = null;
|
|
@@ -15137,7 +15135,7 @@ function resolveWikiMirrorPath(directory, preferredFilename, matchesLegacyId, ma
|
|
|
15137
15135
|
const legacyIdMatch = !titleMatch && matchesLegacyId(filename);
|
|
15138
15136
|
if (!titleMatch && !legacyIdMatch)
|
|
15139
15137
|
continue;
|
|
15140
|
-
const path =
|
|
15138
|
+
const path = join28(directory, filename);
|
|
15141
15139
|
const mtimeMs = statSync9(path).mtimeMs;
|
|
15142
15140
|
if (titleMatch) {
|
|
15143
15141
|
if (!newestTitle || mtimeMs > newestTitle.mtimeMs) {
|
|
@@ -15151,9 +15149,9 @@ function resolveWikiMirrorPath(directory, preferredFilename, matchesLegacyId, ma
|
|
|
15151
15149
|
return newestTitle?.path ?? newestLegacyId?.path ?? preferred;
|
|
15152
15150
|
}
|
|
15153
15151
|
function resolveWikiMemoryMirror(wikiDir, topicId, topicTitle) {
|
|
15154
|
-
const briefFile = resolveWikiMirrorPath(
|
|
15152
|
+
const briefFile = resolveWikiMirrorPath(join28(wikiDir, "topic"), `${wikiBriefStorageKey(topicTitle, topicId)}.md`, (filename) => isTopicBriefFile(filename, topicId), (filename) => isTopicBriefFile(filename, topicId, topicTitle));
|
|
15155
15153
|
const hasBriefFile = existsSync18(briefFile) && statSync9(briefFile).isFile();
|
|
15156
|
-
const latestSummaryCandidate = resolveWikiMirrorPath(
|
|
15154
|
+
const latestSummaryCandidate = resolveWikiMirrorPath(join28(wikiDir, "summaries"), `__missing__-${wikiSummaryFilename("0000-00-00", topicTitle, topicId)}`, (filename) => isTopicSummaryFile(filename, topicId), (filename) => isTopicSummaryFile(filename, topicId, topicTitle), false);
|
|
15157
15155
|
const latestSummaryFile = existsSync18(latestSummaryCandidate) && statSync9(latestSummaryCandidate).isFile() ? latestSummaryCandidate : null;
|
|
15158
15156
|
return { briefFile, hasBriefFile, latestSummaryFile };
|
|
15159
15157
|
}
|
|
@@ -17977,4 +17975,4 @@ export {
|
|
|
17977
17975
|
DEFAULT_SELF_CONFIG_PRODUCT
|
|
17978
17976
|
};
|
|
17979
17977
|
|
|
17980
|
-
//# debugId=
|
|
17978
|
+
//# debugId=A76A8C7E7223693364756E2164756E21
|