negotium 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-helpers.js +259 -254
- package/dist/agent-helpers.js.map +6 -6
- package/dist/{chunk-cvxe25re.js → chunk-cxtngn3p.js} +120 -313
- package/dist/{chunk-cvxe25re.js.map → chunk-cxtngn3p.js.map} +7 -8
- package/dist/chunk-tfwbft4r.js +160 -0
- package/dist/chunk-tfwbft4r.js.map +12 -0
- package/dist/chunk-v7tj2vtq.js +205 -0
- package/dist/chunk-v7tj2vtq.js.map +10 -0
- package/dist/hosted-agent.js +2 -2
- package/dist/hosted-agent.js.map +2 -2
- package/dist/main.js +346 -273
- package/dist/main.js.map +9 -8
- package/dist/mcp-factories.js +278 -273
- package/dist/mcp-factories.js.map +6 -6
- package/dist/registry.js +24 -173
- package/dist/registry.js.map +4 -7
- package/dist/rollout.js +7 -5
- package/dist/rollout.js.map +2 -2
- package/dist/runtime/cron/mcp-server.ts +2 -2
- package/dist/runtime/src/agents/codex-registry.ts +4 -1
- package/dist/runtime/src/cron-mcp-host.ts +5 -0
- package/dist/runtime/src/runtime/inbox.ts +6 -0
- package/dist/runtime/src/version.ts +1 -1
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -510,289 +510,9 @@ ${toolBuffer.join(`
|
|
|
510
510
|
return pairs;
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
-
// ../../packages/core/src/agents/rollout/claude.ts
|
|
514
|
-
import { randomUUID } from "crypto";
|
|
515
|
-
import { existsSync as existsSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
516
|
-
import { homedir as homedir2 } from "os";
|
|
517
|
-
import { join as join2 } from "path";
|
|
518
|
-
|
|
519
|
-
// ../../packages/core/src/platform/jsonl.ts
|
|
520
|
-
import {
|
|
521
|
-
appendFileSync,
|
|
522
|
-
closeSync,
|
|
523
|
-
fsyncSync,
|
|
524
|
-
mkdirSync as mkdirSync3,
|
|
525
|
-
openSync,
|
|
526
|
-
readFileSync as readFileSync2,
|
|
527
|
-
renameSync,
|
|
528
|
-
statSync,
|
|
529
|
-
unlinkSync as unlinkSync2,
|
|
530
|
-
writeFileSync as writeFileSync2
|
|
531
|
-
} from "fs";
|
|
532
|
-
import { dirname as dirname2 } from "path";
|
|
533
|
-
|
|
534
|
-
// ../../packages/core/src/platform/file-utils.ts
|
|
535
|
-
import { unlinkSync } from "fs";
|
|
536
|
-
function createSafeUnlink(host) {
|
|
537
|
-
return (path, warnLabel) => {
|
|
538
|
-
try {
|
|
539
|
-
host.unlink(path);
|
|
540
|
-
} catch (e) {
|
|
541
|
-
if (e?.code === "ENOENT")
|
|
542
|
-
return;
|
|
543
|
-
if (warnLabel)
|
|
544
|
-
host.warn({ err: e, path }, warnLabel);
|
|
545
|
-
}
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
var defaultSafeUnlink = createSafeUnlink({
|
|
549
|
-
unlink: unlinkSync,
|
|
550
|
-
warn: (context, message) => logger.warn(context, message)
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
// ../../packages/core/src/platform/jsonl.ts
|
|
554
|
-
function parseJsonlText(raw) {
|
|
555
|
-
return raw.trim().split(`
|
|
556
|
-
`).filter(Boolean).map((line) => JSON.parse(line));
|
|
557
|
-
}
|
|
558
|
-
var LOCK_SLEEP = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
|
559
|
-
function writeJsonlFile(filePath, entries) {
|
|
560
|
-
const dir = dirname2(filePath);
|
|
561
|
-
mkdirSync3(dir, { recursive: true });
|
|
562
|
-
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
563
|
-
const payload = `${entries.map((e) => JSON.stringify(e)).join(`
|
|
564
|
-
`)}
|
|
565
|
-
`;
|
|
566
|
-
let fd = null;
|
|
567
|
-
try {
|
|
568
|
-
fd = openSync(tmpPath, "w");
|
|
569
|
-
writeFileSync2(fd, payload);
|
|
570
|
-
fsyncSync(fd);
|
|
571
|
-
closeSync(fd);
|
|
572
|
-
fd = null;
|
|
573
|
-
renameSync(tmpPath, filePath);
|
|
574
|
-
fsyncDirectoryBestEffort(dir);
|
|
575
|
-
} catch (err) {
|
|
576
|
-
if (fd !== null) {
|
|
577
|
-
try {
|
|
578
|
-
closeSync(fd);
|
|
579
|
-
} catch {}
|
|
580
|
-
}
|
|
581
|
-
try {
|
|
582
|
-
unlinkSync2(tmpPath);
|
|
583
|
-
} catch {}
|
|
584
|
-
throw err;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
function fsyncDirectoryBestEffort(dir) {
|
|
588
|
-
let fd = null;
|
|
589
|
-
try {
|
|
590
|
-
fd = openSync(dir, "r");
|
|
591
|
-
fsyncSync(fd);
|
|
592
|
-
} catch {} finally {
|
|
593
|
-
if (fd !== null) {
|
|
594
|
-
try {
|
|
595
|
-
closeSync(fd);
|
|
596
|
-
} catch {}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
// ../../packages/core/src/agents/rollout/claude.ts
|
|
602
|
-
var _attachmentsCache = null;
|
|
603
|
-
function loadClaudeAttachments() {
|
|
604
|
-
if (_attachmentsCache)
|
|
605
|
-
return _attachmentsCache;
|
|
606
|
-
const raw = readFileSync3(join2(FIXTURES_DIR, "claude-attachments.jsonl"), "utf8");
|
|
607
|
-
const lines = parseJsonlText(raw);
|
|
608
|
-
if (lines.length < 2) {
|
|
609
|
-
throw new Error(`loadClaudeAttachments: expected >=2 entries in claude-attachments.jsonl, got ${lines.length}`);
|
|
610
|
-
}
|
|
611
|
-
_attachmentsCache = {
|
|
612
|
-
deferredToolsDelta: lines[0],
|
|
613
|
-
skillListing: lines[1]
|
|
614
|
-
};
|
|
615
|
-
return _attachmentsCache;
|
|
616
|
-
}
|
|
617
|
-
var CLAUDE_SDK_VERSION = "2.1.126";
|
|
618
|
-
var CLAUDE_DEFAULT_MODEL = "claude-sonnet-5";
|
|
619
|
-
var CLAUDE_DEFAULT_GIT_BRANCH = "HEAD";
|
|
620
|
-
function encodeClaudeCwd(cwd) {
|
|
621
|
-
const realCwd = cwd.startsWith("/tmp/") ? cwd.replace(/^\/tmp\//, "/private/tmp/") : cwd;
|
|
622
|
-
return `-${realCwd.replaceAll(/[^a-zA-Z0-9]/g, "-").replace(/^-/, "")}`;
|
|
623
|
-
}
|
|
624
|
-
function writeClaudeRollout(opts) {
|
|
625
|
-
const sessionId = opts.sessionId ?? randomUUID();
|
|
626
|
-
assertUuidLike("sessionId", sessionId);
|
|
627
|
-
ensureCwdExists(opts.cwd);
|
|
628
|
-
const pairs = opts.pairs ?? extractChatPairs(opts.entries ?? []);
|
|
629
|
-
const cwdReal = opts.cwd.startsWith("/tmp/") ? opts.cwd.replace(/^\/tmp\//, "/private/tmp/") : opts.cwd;
|
|
630
|
-
const lines = [];
|
|
631
|
-
const ts = () => new Date().toISOString();
|
|
632
|
-
let lastUuid = null;
|
|
633
|
-
lines.push({ type: "queue-operation", operation: "enqueue", timestamp: ts(), sessionId });
|
|
634
|
-
lines.push({ type: "queue-operation", operation: "dequeue", timestamp: ts(), sessionId });
|
|
635
|
-
const attachments = loadClaudeAttachments();
|
|
636
|
-
for (const pair of pairs) {
|
|
637
|
-
const userUuid = randomUUID();
|
|
638
|
-
lines.push({
|
|
639
|
-
parentUuid: lastUuid,
|
|
640
|
-
isSidechain: false,
|
|
641
|
-
promptId: randomUUID(),
|
|
642
|
-
type: "user",
|
|
643
|
-
message: { role: "user", content: [{ type: "text", text: pair.userText }] },
|
|
644
|
-
uuid: userUuid,
|
|
645
|
-
timestamp: ts(),
|
|
646
|
-
permissionMode: "bypassPermissions",
|
|
647
|
-
userType: "external",
|
|
648
|
-
entrypoint: "sdk-ts",
|
|
649
|
-
cwd: cwdReal,
|
|
650
|
-
sessionId,
|
|
651
|
-
version: CLAUDE_SDK_VERSION,
|
|
652
|
-
gitBranch: CLAUDE_DEFAULT_GIT_BRANCH
|
|
653
|
-
});
|
|
654
|
-
const att1Uuid = randomUUID();
|
|
655
|
-
const att1 = clone(attachments.deferredToolsDelta);
|
|
656
|
-
att1.parentUuid = userUuid;
|
|
657
|
-
att1.uuid = att1Uuid;
|
|
658
|
-
att1.timestamp = ts();
|
|
659
|
-
att1.sessionId = sessionId;
|
|
660
|
-
att1.cwd = cwdReal;
|
|
661
|
-
lines.push(att1);
|
|
662
|
-
const att2Uuid = randomUUID();
|
|
663
|
-
const att2 = clone(attachments.skillListing);
|
|
664
|
-
att2.parentUuid = att1Uuid;
|
|
665
|
-
att2.uuid = att2Uuid;
|
|
666
|
-
att2.timestamp = ts();
|
|
667
|
-
att2.sessionId = sessionId;
|
|
668
|
-
att2.cwd = cwdReal;
|
|
669
|
-
lines.push(att2);
|
|
670
|
-
const assistantUuid = randomUUID();
|
|
671
|
-
lines.push({
|
|
672
|
-
parentUuid: att2Uuid,
|
|
673
|
-
isSidechain: false,
|
|
674
|
-
message: {
|
|
675
|
-
model: opts.model ?? CLAUDE_DEFAULT_MODEL,
|
|
676
|
-
id: `msg_${randomUUID().replace(/-/g, "").slice(0, 24)}`,
|
|
677
|
-
type: "message",
|
|
678
|
-
role: "assistant",
|
|
679
|
-
content: [{ type: "text", text: pair.assistantText }],
|
|
680
|
-
stop_reason: "end_turn",
|
|
681
|
-
stop_sequence: null,
|
|
682
|
-
stop_details: null,
|
|
683
|
-
usage: {
|
|
684
|
-
input_tokens: 0,
|
|
685
|
-
cache_creation_input_tokens: 0,
|
|
686
|
-
cache_read_input_tokens: 0,
|
|
687
|
-
output_tokens: 0,
|
|
688
|
-
server_tool_use: { web_search_requests: 0, web_fetch_requests: 0 },
|
|
689
|
-
service_tier: "standard",
|
|
690
|
-
cache_creation: { ephemeral_1h_input_tokens: 0, ephemeral_5m_input_tokens: 0 },
|
|
691
|
-
inference_geo: "",
|
|
692
|
-
iterations: [],
|
|
693
|
-
speed: "standard"
|
|
694
|
-
},
|
|
695
|
-
diagnostics: null
|
|
696
|
-
},
|
|
697
|
-
requestId: `req_${randomUUID().replace(/-/g, "").slice(0, 22)}`,
|
|
698
|
-
type: "assistant",
|
|
699
|
-
uuid: assistantUuid,
|
|
700
|
-
timestamp: ts(),
|
|
701
|
-
userType: "external",
|
|
702
|
-
entrypoint: "sdk-ts",
|
|
703
|
-
cwd: cwdReal,
|
|
704
|
-
sessionId,
|
|
705
|
-
version: CLAUDE_SDK_VERSION,
|
|
706
|
-
gitBranch: CLAUDE_DEFAULT_GIT_BRANCH
|
|
707
|
-
});
|
|
708
|
-
lastUuid = assistantUuid;
|
|
709
|
-
}
|
|
710
|
-
const projectsDir = join2(homedir2(), ".claude", "projects", encodeClaudeCwd(opts.cwd));
|
|
711
|
-
const path = join2(projectsDir, `${sessionId}.jsonl`);
|
|
712
|
-
writeJsonlFile(path, lines);
|
|
713
|
-
logger.info({ sessionId, path, pairs: pairs.length }, "writeClaudeRollout: synthetic rollout placed");
|
|
714
|
-
return { sessionId, rolloutPath: path };
|
|
715
|
-
}
|
|
716
|
-
function repairPoisonedRollout(sessionId, cwd) {
|
|
717
|
-
try {
|
|
718
|
-
const path = join2(homedir2(), ".claude", "projects", encodeClaudeCwd(cwd), `${sessionId}.jsonl`);
|
|
719
|
-
if (!existsSync2(path))
|
|
720
|
-
return false;
|
|
721
|
-
const lines = readFileSync3(path, "utf8").split(`
|
|
722
|
-
`).filter((l) => l.trim());
|
|
723
|
-
let poisonedAssistantIdx = -1;
|
|
724
|
-
for (let i = lines.length - 1;i >= 0; i--) {
|
|
725
|
-
const entry = parseClaudeRolloutLine(lines[i]);
|
|
726
|
-
if (entry && isPoisonedAssistantEntry(entry)) {
|
|
727
|
-
poisonedAssistantIdx = i;
|
|
728
|
-
break;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
if (poisonedAssistantIdx < 0) {
|
|
732
|
-
logger.warn({ sessionId, path }, "repairPoisonedRollout: no poisoned assistant entry found");
|
|
733
|
-
return false;
|
|
734
|
-
}
|
|
735
|
-
let turnStartIdx = -1;
|
|
736
|
-
for (let i = poisonedAssistantIdx - 1;i >= 0; i--) {
|
|
737
|
-
const entry = parseClaudeRolloutLine(lines[i]);
|
|
738
|
-
if (entry?.type === "user") {
|
|
739
|
-
turnStartIdx = i;
|
|
740
|
-
break;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
if (turnStartIdx < 0) {
|
|
744
|
-
logger.warn({ sessionId, path, poisonedAssistantIdx }, "repairPoisonedRollout: poisoned assistant has no preceding user entry");
|
|
745
|
-
return false;
|
|
746
|
-
}
|
|
747
|
-
const kept = lines.slice(0, turnStartIdx);
|
|
748
|
-
writeFileSync3(path, kept.length ? `${kept.join(`
|
|
749
|
-
`)}
|
|
750
|
-
` : "");
|
|
751
|
-
logger.warn({
|
|
752
|
-
sessionId,
|
|
753
|
-
path,
|
|
754
|
-
poisonedAssistantIdx,
|
|
755
|
-
turnStartIdx,
|
|
756
|
-
droppedEntries: lines.length - turnStartIdx,
|
|
757
|
-
keptEntries: kept.length
|
|
758
|
-
}, "repairPoisonedRollout: truncated turn removed from rollout JSONL");
|
|
759
|
-
return true;
|
|
760
|
-
} catch (err) {
|
|
761
|
-
logger.warn({ err, sessionId, cwd }, "repairPoisonedRollout: I/O error");
|
|
762
|
-
return false;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
function parseClaudeRolloutLine(line) {
|
|
766
|
-
try {
|
|
767
|
-
return JSON.parse(line);
|
|
768
|
-
} catch {
|
|
769
|
-
return null;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
function isPoisonedAssistantEntry(entry) {
|
|
773
|
-
if (entry.type !== "assistant")
|
|
774
|
-
return false;
|
|
775
|
-
if (entry.message?.stop_reason !== "max_tokens")
|
|
776
|
-
return false;
|
|
777
|
-
const content = entry.message.content;
|
|
778
|
-
if (!Array.isArray(content))
|
|
779
|
-
return false;
|
|
780
|
-
return content.some((block) => {
|
|
781
|
-
if (!block || typeof block !== "object")
|
|
782
|
-
return false;
|
|
783
|
-
const type = block.type;
|
|
784
|
-
return type === "thinking" || type === "redacted_thinking";
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
// ../../packages/core/src/agents/rollout/codex.ts
|
|
789
|
-
import { randomBytes as randomBytes4 } from "crypto";
|
|
790
|
-
import { existsSync as existsSync3, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync3 } from "fs";
|
|
791
|
-
import { basename, dirname as dirname5, join as join5, resolve as resolve5 } from "path";
|
|
792
|
-
|
|
793
513
|
// ../../packages/core/src/agents/execution-host.ts
|
|
794
514
|
import { AsyncLocalStorage } from "async_hooks";
|
|
795
|
-
import { dirname as
|
|
515
|
+
import { dirname as dirname3 } from "path";
|
|
796
516
|
|
|
797
517
|
// ../../packages/core/src/security/sensitive-path.ts
|
|
798
518
|
import { realpathSync } from "fs";
|
|
@@ -1787,8 +1507,8 @@ function getMcpServersForQuery(opts) {
|
|
|
1787
1507
|
}
|
|
1788
1508
|
|
|
1789
1509
|
// ../../packages/core/src/storage/vault.ts
|
|
1790
|
-
import { chmodSync as chmodSync2, mkdirSync as
|
|
1791
|
-
import { join as
|
|
1510
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync4 } from "fs";
|
|
1511
|
+
import { join as join3 } from "path";
|
|
1792
1512
|
|
|
1793
1513
|
// ../../packages/core/src/storage/sqlite.ts
|
|
1794
1514
|
var isBun = typeof process.versions.bun === "string";
|
|
@@ -1842,9 +1562,9 @@ if (isBun) {
|
|
|
1842
1562
|
}
|
|
1843
1563
|
|
|
1844
1564
|
// ../../packages/core/src/storage/storage-host.ts
|
|
1845
|
-
import { mkdirSync as
|
|
1846
|
-
import { homedir as
|
|
1847
|
-
import { dirname as
|
|
1565
|
+
import { mkdirSync as mkdirSync3 } from "fs";
|
|
1566
|
+
import { homedir as homedir2 } from "os";
|
|
1567
|
+
import { dirname as dirname2, join as join2, resolve as resolve4 } from "path";
|
|
1848
1568
|
var STORAGE_HOST_STATE = Symbol.for("negotium.storage-host.state.v1");
|
|
1849
1569
|
function storageState() {
|
|
1850
1570
|
const holder = globalThis;
|
|
@@ -1873,13 +1593,13 @@ function envPath(name, fallback) {
|
|
|
1873
1593
|
return resolve4(value || fallback);
|
|
1874
1594
|
}
|
|
1875
1595
|
function defaultStateDir() {
|
|
1876
|
-
return envPath("NEGOTIUM_STATE_DIR",
|
|
1596
|
+
return envPath("NEGOTIUM_STATE_DIR", join2(homedir2(), ".negotium"));
|
|
1877
1597
|
}
|
|
1878
1598
|
function defaultDataDir() {
|
|
1879
|
-
return envPath("NEGOTIUM_DATA_DIR",
|
|
1599
|
+
return envPath("NEGOTIUM_DATA_DIR", join2(defaultStateDir(), "data"));
|
|
1880
1600
|
}
|
|
1881
1601
|
function defaultSessionsDatabasePath() {
|
|
1882
|
-
return envPath("SESSIONS_DB_PATH",
|
|
1602
|
+
return envPath("SESSIONS_DB_PATH", join2(resolveStorageDataDir(), "sessions.db"));
|
|
1883
1603
|
}
|
|
1884
1604
|
var SQLITE_INIT_RETRY_MS = 25;
|
|
1885
1605
|
var SQLITE_INIT_TIMEOUT_MS = 5000;
|
|
@@ -1917,7 +1637,7 @@ function defaultDatabase() {
|
|
|
1917
1637
|
return state.fallbackDatabase;
|
|
1918
1638
|
if (state.fallbackDatabase)
|
|
1919
1639
|
state.fallbackDatabase.close();
|
|
1920
|
-
|
|
1640
|
+
mkdirSync3(dirname2(path), { recursive: true });
|
|
1921
1641
|
state.fallbackDatabase = new Database(path, { create: true });
|
|
1922
1642
|
state.fallbackDatabasePath = path;
|
|
1923
1643
|
initializeDatabase(state.fallbackDatabase);
|
|
@@ -2058,9 +1778,9 @@ function initializeVaultDatabase(database) {
|
|
|
2058
1778
|
}
|
|
2059
1779
|
}
|
|
2060
1780
|
function openVaultDatabase(dataDir) {
|
|
2061
|
-
const vaultDir =
|
|
2062
|
-
const path =
|
|
2063
|
-
|
|
1781
|
+
const vaultDir = join3(dataDir, "vault");
|
|
1782
|
+
const path = join3(vaultDir, "vault.db");
|
|
1783
|
+
mkdirSync4(vaultDir, { recursive: true, mode: 448 });
|
|
2064
1784
|
const database = new Database(path, { create: true });
|
|
2065
1785
|
chmodSync2(path, 384);
|
|
2066
1786
|
initializeVaultDatabase(database);
|
|
@@ -2181,18 +1901,105 @@ function hostedCodexAuthFilePath() {
|
|
|
2181
1901
|
return activeHost().codexAuthFilePath();
|
|
2182
1902
|
}
|
|
2183
1903
|
function hostedCodexHomePath() {
|
|
2184
|
-
return
|
|
1904
|
+
return dirname3(hostedCodexAuthFilePath());
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
// ../../packages/core/src/agents/rollout/codex.ts
|
|
1908
|
+
import { randomBytes as randomBytes4 } from "crypto";
|
|
1909
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync3 } from "fs";
|
|
1910
|
+
import { basename, dirname as dirname5, join as join4, resolve as resolve5 } from "path";
|
|
1911
|
+
|
|
1912
|
+
// ../../packages/core/src/platform/jsonl.ts
|
|
1913
|
+
import {
|
|
1914
|
+
appendFileSync,
|
|
1915
|
+
closeSync,
|
|
1916
|
+
fsyncSync,
|
|
1917
|
+
mkdirSync as mkdirSync5,
|
|
1918
|
+
openSync,
|
|
1919
|
+
readFileSync as readFileSync2,
|
|
1920
|
+
renameSync,
|
|
1921
|
+
statSync,
|
|
1922
|
+
unlinkSync as unlinkSync2,
|
|
1923
|
+
writeFileSync as writeFileSync2
|
|
1924
|
+
} from "fs";
|
|
1925
|
+
import { dirname as dirname4 } from "path";
|
|
1926
|
+
|
|
1927
|
+
// ../../packages/core/src/platform/file-utils.ts
|
|
1928
|
+
import { unlinkSync } from "fs";
|
|
1929
|
+
function createSafeUnlink(host) {
|
|
1930
|
+
return (path, warnLabel) => {
|
|
1931
|
+
try {
|
|
1932
|
+
host.unlink(path);
|
|
1933
|
+
} catch (e) {
|
|
1934
|
+
if (e?.code === "ENOENT")
|
|
1935
|
+
return;
|
|
1936
|
+
if (warnLabel)
|
|
1937
|
+
host.warn({ err: e, path }, warnLabel);
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
var defaultSafeUnlink = createSafeUnlink({
|
|
1942
|
+
unlink: unlinkSync,
|
|
1943
|
+
warn: (context, message) => logger.warn(context, message)
|
|
1944
|
+
});
|
|
1945
|
+
|
|
1946
|
+
// ../../packages/core/src/platform/jsonl.ts
|
|
1947
|
+
function parseJsonlText(raw) {
|
|
1948
|
+
return raw.trim().split(`
|
|
1949
|
+
`).filter(Boolean).map((line) => JSON.parse(line));
|
|
1950
|
+
}
|
|
1951
|
+
var LOCK_SLEEP = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
|
1952
|
+
function writeJsonlFile(filePath, entries) {
|
|
1953
|
+
const dir = dirname4(filePath);
|
|
1954
|
+
mkdirSync5(dir, { recursive: true });
|
|
1955
|
+
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
1956
|
+
const payload = `${entries.map((e) => JSON.stringify(e)).join(`
|
|
1957
|
+
`)}
|
|
1958
|
+
`;
|
|
1959
|
+
let fd = null;
|
|
1960
|
+
try {
|
|
1961
|
+
fd = openSync(tmpPath, "w");
|
|
1962
|
+
writeFileSync2(fd, payload);
|
|
1963
|
+
fsyncSync(fd);
|
|
1964
|
+
closeSync(fd);
|
|
1965
|
+
fd = null;
|
|
1966
|
+
renameSync(tmpPath, filePath);
|
|
1967
|
+
fsyncDirectoryBestEffort(dir);
|
|
1968
|
+
} catch (err) {
|
|
1969
|
+
if (fd !== null) {
|
|
1970
|
+
try {
|
|
1971
|
+
closeSync(fd);
|
|
1972
|
+
} catch {}
|
|
1973
|
+
}
|
|
1974
|
+
try {
|
|
1975
|
+
unlinkSync2(tmpPath);
|
|
1976
|
+
} catch {}
|
|
1977
|
+
throw err;
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
function fsyncDirectoryBestEffort(dir) {
|
|
1981
|
+
let fd = null;
|
|
1982
|
+
try {
|
|
1983
|
+
fd = openSync(dir, "r");
|
|
1984
|
+
fsyncSync(fd);
|
|
1985
|
+
} catch {} finally {
|
|
1986
|
+
if (fd !== null) {
|
|
1987
|
+
try {
|
|
1988
|
+
closeSync(fd);
|
|
1989
|
+
} catch {}
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
2185
1992
|
}
|
|
2186
1993
|
|
|
2187
1994
|
// ../../packages/core/src/agents/rollout/codex.ts
|
|
2188
1995
|
function codexSessionsDir() {
|
|
2189
|
-
return
|
|
1996
|
+
return join4(hostedCodexHomePath(), "sessions");
|
|
2190
1997
|
}
|
|
2191
1998
|
var _shellCache = null;
|
|
2192
1999
|
function loadCodexShell() {
|
|
2193
2000
|
if (_shellCache)
|
|
2194
2001
|
return _shellCache;
|
|
2195
|
-
const raw =
|
|
2002
|
+
const raw = readFileSync3(join4(FIXTURES_DIR, "codex-shell.jsonl"), "utf8");
|
|
2196
2003
|
const lines = parseJsonlText(raw);
|
|
2197
2004
|
if (lines.length < 5) {
|
|
2198
2005
|
throw new Error(`loadCodexShell: expected >=5 entries in codex-shell.jsonl, got ${lines.length}`);
|
|
@@ -2259,8 +2066,8 @@ function codexRolloutPath(threadId, fallback) {
|
|
|
2259
2066
|
const hh = String(createdAt.getHours()).padStart(2, "0");
|
|
2260
2067
|
const min = String(createdAt.getMinutes()).padStart(2, "0");
|
|
2261
2068
|
const ss = String(createdAt.getSeconds()).padStart(2, "0");
|
|
2262
|
-
const dir =
|
|
2263
|
-
return
|
|
2069
|
+
const dir = join4(codexSessionsDir(), yyyy, mm, dd);
|
|
2070
|
+
return join4(dir, `rollout-${yyyy}-${mm}-${dd}T${hh}-${min}-${ss}-${threadId}.jsonl`);
|
|
2264
2071
|
}
|
|
2265
2072
|
function canonicalFilePath(path) {
|
|
2266
2073
|
const absolute = resolve5(path);
|
|
@@ -2268,7 +2075,7 @@ function canonicalFilePath(path) {
|
|
|
2268
2075
|
return realpathSync2(absolute);
|
|
2269
2076
|
} catch {
|
|
2270
2077
|
try {
|
|
2271
|
-
return
|
|
2078
|
+
return join4(realpathSync2(dirname5(absolute)), basename(absolute));
|
|
2272
2079
|
} catch {
|
|
2273
2080
|
return absolute;
|
|
2274
2081
|
}
|
|
@@ -2378,7 +2185,7 @@ function readCodexPatchCallIds(threadId) {
|
|
|
2378
2185
|
if (!path)
|
|
2379
2186
|
return [];
|
|
2380
2187
|
try {
|
|
2381
|
-
return extractCodexPatchCallIds(
|
|
2188
|
+
return extractCodexPatchCallIds(readFileSync3(path, "utf8"));
|
|
2382
2189
|
} catch (error) {
|
|
2383
2190
|
logger.debug({ error, threadId }, "codex patch ids: rollout read failed");
|
|
2384
2191
|
return [];
|
|
@@ -2389,7 +2196,7 @@ function readLatestCodexPatchPreview(threadId, expectedPaths, consumedCallIds =
|
|
|
2389
2196
|
if (!path)
|
|
2390
2197
|
return;
|
|
2391
2198
|
try {
|
|
2392
|
-
return extractLatestCodexPatchPreview(
|
|
2199
|
+
return extractLatestCodexPatchPreview(readFileSync3(path, "utf8"), expectedPaths, consumedCallIds, expectedCallId);
|
|
2393
2200
|
} catch (error) {
|
|
2394
2201
|
logger.debug({ error, threadId }, "codex patch preview: rollout read failed");
|
|
2395
2202
|
return;
|
|
@@ -2417,7 +2224,7 @@ function readLatestCodexContextUsage(threadId) {
|
|
|
2417
2224
|
if (!path)
|
|
2418
2225
|
return;
|
|
2419
2226
|
try {
|
|
2420
|
-
return extractLatestCodexContextUsage(
|
|
2227
|
+
return extractLatestCodexContextUsage(readFileSync3(path, "utf8"));
|
|
2421
2228
|
} catch (error) {
|
|
2422
2229
|
logger.debug({ error, threadId }, "codex context usage: rollout read failed");
|
|
2423
2230
|
return;
|
|
@@ -2428,7 +2235,7 @@ function migrateCodexRolloutNativeMultiAgentMetadata(threadId) {
|
|
|
2428
2235
|
if (!path)
|
|
2429
2236
|
return false;
|
|
2430
2237
|
try {
|
|
2431
|
-
const entries = parseJsonlText(
|
|
2238
|
+
const entries = parseJsonlText(readFileSync3(path, "utf8"));
|
|
2432
2239
|
let changed = false;
|
|
2433
2240
|
for (const entry of entries) {
|
|
2434
2241
|
if (entry.type !== "session_meta" && entry.type !== "turn_context")
|
|
@@ -2457,19 +2264,19 @@ function latestCodexRolloutPath(threadId) {
|
|
|
2457
2264
|
try {
|
|
2458
2265
|
if (buckets) {
|
|
2459
2266
|
for (const bucket of buckets) {
|
|
2460
|
-
const dir =
|
|
2461
|
-
if (!
|
|
2267
|
+
const dir = join4(sessionsDir, bucket);
|
|
2268
|
+
if (!existsSync2(dir))
|
|
2462
2269
|
continue;
|
|
2463
2270
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
2464
2271
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
2465
|
-
candidates.push(
|
|
2272
|
+
candidates.push(join4(dir, rel));
|
|
2466
2273
|
}
|
|
2467
2274
|
}
|
|
2468
2275
|
}
|
|
2469
2276
|
if (candidates.length === 0) {
|
|
2470
2277
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
2471
2278
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
2472
|
-
candidates.push(
|
|
2279
|
+
candidates.push(join4(sessionsDir, rel));
|
|
2473
2280
|
}
|
|
2474
2281
|
}
|
|
2475
2282
|
return candidates.sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs)[0];
|
|
@@ -2590,13 +2397,13 @@ function sweepPriorRolloutsForThread(threadId) {
|
|
|
2590
2397
|
return;
|
|
2591
2398
|
}
|
|
2592
2399
|
for (const bucket of buckets) {
|
|
2593
|
-
const dir =
|
|
2594
|
-
if (!
|
|
2400
|
+
const dir = join4(sessionsDir, bucket);
|
|
2401
|
+
if (!existsSync2(dir))
|
|
2595
2402
|
continue;
|
|
2596
2403
|
try {
|
|
2597
2404
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
2598
2405
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
2599
|
-
const fullPath =
|
|
2406
|
+
const fullPath = join4(dir, rel);
|
|
2600
2407
|
try {
|
|
2601
2408
|
unlinkSync3(fullPath);
|
|
2602
2409
|
} catch (e) {
|
|
@@ -2614,7 +2421,7 @@ function sweepPriorRolloutsFullTree(threadId, sessionsDir) {
|
|
|
2614
2421
|
try {
|
|
2615
2422
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
2616
2423
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
2617
|
-
const fullPath =
|
|
2424
|
+
const fullPath = join4(sessionsDir, rel);
|
|
2618
2425
|
try {
|
|
2619
2426
|
unlinkSync3(fullPath);
|
|
2620
2427
|
} catch (e) {
|
|
@@ -2671,6 +2478,6 @@ function formatDateBucket(d) {
|
|
|
2671
2478
|
return `${yyyy}/${mm}/${dd}`;
|
|
2672
2479
|
}
|
|
2673
2480
|
|
|
2674
|
-
export { __toESM, __require, logger, CLAUDE_EFFORT_VALUES, CODEX_EFFORT_VALUES, MAESTRO_EFFORT_VALUES, MODEL_SONNET, MODEL_OPUS, MODEL_FABLE, configureRolloutHost, assertUuidLike, ensureCwdExists, extractChatPairs,
|
|
2481
|
+
export { __toESM, __require, logger, CLAUDE_EFFORT_VALUES, CODEX_EFFORT_VALUES, MAESTRO_EFFORT_VALUES, MODEL_SONNET, MODEL_OPUS, MODEL_FABLE, configureRolloutHost, FIXTURES_DIR, clone, assertUuidLike, ensureCwdExists, extractChatPairs, parseJsonlText, writeJsonlFile, hostedCodexHomePath, extractLatestCodexPatchPreview, extractCodexPatchCallIds, readCodexPatchCallIds, readLatestCodexPatchPreview, extractLatestCodexContextUsage, readLatestCodexContextUsage, migrateCodexRolloutNativeMultiAgentMetadata, latestCodexRolloutPath, writeCodexRollout, decodeUuidV7Timestamp };
|
|
2675
2482
|
|
|
2676
|
-
//# debugId=
|
|
2483
|
+
//# debugId=510EB5E3CE29EBDD64756E2164756E21
|