@quantiya/codevibe-codex-plugin 2.0.116 → 2.0.117
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/native-launch.js +1 -1
- package/dist/server.js +1 -1
- package/node_modules/@quantiya/codevibe-core/dist/index.js +554 -551
- package/node_modules/@quantiya/codevibe-core/dist/orchestration-shell/cli.js +886 -608
- package/node_modules/@quantiya/codevibe-core/dist/substrate-launch/agy-auth-seed.d.ts +17 -7
- package/node_modules/@quantiya/codevibe-core/dist/substrate-launch/secret-service-client.d.ts +78 -0
- package/node_modules/@quantiya/codevibe-core/package.json +1 -1
- package/package.json +2 -2
|
@@ -9490,7 +9490,7 @@ function resolveSpawnSweepHelper(opts = {}) {
|
|
|
9490
9490
|
for (let dir of opts.nativeDirs ?? packageNativeDirs()) {
|
|
9491
9491
|
let manifestText;
|
|
9492
9492
|
try {
|
|
9493
|
-
manifestText =
|
|
9493
|
+
manifestText = fs62.readFileSync(path72.join(dir, SPAWN_SWEEP_MANIFEST), "utf8");
|
|
9494
9494
|
} catch {
|
|
9495
9495
|
continue;
|
|
9496
9496
|
}
|
|
@@ -9498,7 +9498,7 @@ function resolveSpawnSweepHelper(opts = {}) {
|
|
|
9498
9498
|
if (!manifest) return { ok: !1, reason: `the spawn-sweep manifest at ${dir} is malformed` };
|
|
9499
9499
|
let expected = manifest.targets[target2].sha256, bin = path72.join(dir, target2, SPAWN_SWEEP_BINARY), st;
|
|
9500
9500
|
try {
|
|
9501
|
-
st =
|
|
9501
|
+
st = fs62.lstatSync(bin), st.isFile() && st.uid === uid && (st.mode & 18) !== 0 && (fs62.chmodSync(bin, st.mode & 493), st = fs62.lstatSync(bin));
|
|
9502
9502
|
} catch {
|
|
9503
9503
|
return { ok: !1, reason: `the spawn-sweep helper is missing at ${bin}` };
|
|
9504
9504
|
}
|
|
@@ -9507,14 +9507,14 @@ function resolveSpawnSweepHelper(opts = {}) {
|
|
|
9507
9507
|
if ((st.mode & 18) !== 0) return { ok: !1, reason: `the spawn-sweep helper at ${bin} is writable by group or others` };
|
|
9508
9508
|
if (st.uid !== uid && st.uid !== 0) return { ok: !1, reason: `the spawn-sweep helper at ${bin} is owned by another user` };
|
|
9509
9509
|
let key = `${st.dev}:${st.ino}:${st.size}:${st.mtimeMs}:${st.ctimeMs}`, cached2 = verified.get(bin), sha2568;
|
|
9510
|
-
return cached2 && cached2.key === key ? sha2568 = cached2.sha256 : (sha2568 = (0, import_node_crypto44.createHash)("sha256").update(
|
|
9510
|
+
return cached2 && cached2.key === key ? sha2568 = cached2.sha256 : (sha2568 = (0, import_node_crypto44.createHash)("sha256").update(fs62.readFileSync(bin)).digest("hex"), verified.set(bin, { key, sha256: sha2568 })), sha2568 !== expected ? { ok: !1, reason: `the spawn-sweep helper at ${bin} does not match its pinned digest` } : { ok: !0, path: bin, sha256: sha2568, target: target2 };
|
|
9511
9511
|
}
|
|
9512
9512
|
return { ok: !1, reason: "the spawn-sweep helper is not installed with this package" };
|
|
9513
9513
|
}
|
|
9514
|
-
var import_node_crypto44,
|
|
9514
|
+
var import_node_crypto44, fs62, path72, SPAWN_SWEEP_MANIFEST, SPAWN_SWEEP_BINARY, verified, init_spawn_sweep_binary = __esm({
|
|
9515
9515
|
"src/local-executor/spawn-sweep-binary.ts"() {
|
|
9516
9516
|
"use strict";
|
|
9517
|
-
import_node_crypto44 = require("node:crypto"),
|
|
9517
|
+
import_node_crypto44 = require("node:crypto"), fs62 = __toESM(require("node:fs")), path72 = __toESM(require("node:path")), SPAWN_SWEEP_MANIFEST = "spawn-sweep.json", SPAWN_SWEEP_BINARY = "codevibe-spawn-sweep";
|
|
9518
9518
|
verified = /* @__PURE__ */ new Map();
|
|
9519
9519
|
}
|
|
9520
9520
|
});
|
|
@@ -9536,7 +9536,7 @@ function encodeSpawnRecord(rec) {
|
|
|
9536
9536
|
}
|
|
9537
9537
|
function defaultReadProcStat(pid) {
|
|
9538
9538
|
try {
|
|
9539
|
-
let content =
|
|
9539
|
+
let content = import_node_fs36.default.readFileSync(`/proc/${pid}/stat`, "utf8"), closeParen = content.lastIndexOf(")");
|
|
9540
9540
|
if (closeParen < 0) return { kind: "error", reason: "malformed comm parens" };
|
|
9541
9541
|
let rest = content.slice(closeParen + 2).trim().split(/\s+/), ppid = parseInt(rest[1], 10), starttime = rest[19];
|
|
9542
9542
|
return Number.isNaN(ppid) || !starttime ? { kind: "error", reason: "unparsable ppid or starttime" } : { kind: "ok", ppid, starttime };
|
|
@@ -9804,10 +9804,10 @@ async function executeSpawnSweep(opts) {
|
|
|
9804
9804
|
});
|
|
9805
9805
|
});
|
|
9806
9806
|
}
|
|
9807
|
-
var import_node_child_process15, import_node_crypto45,
|
|
9807
|
+
var import_node_child_process15, import_node_crypto45, import_node_fs36, import_node_path4, activeSpawnSweeps, init_spawn_sweep = __esm({
|
|
9808
9808
|
"src/local-executor/spawn-sweep.ts"() {
|
|
9809
9809
|
"use strict";
|
|
9810
|
-
import_node_child_process15 = __toESM(require("node:child_process")), import_node_crypto45 = __toESM(require("node:crypto")),
|
|
9810
|
+
import_node_child_process15 = __toESM(require("node:child_process")), import_node_crypto45 = __toESM(require("node:crypto")), import_node_fs36 = __toESM(require("node:fs")), import_node_path4 = __toESM(require("node:path"));
|
|
9811
9811
|
init_logger2();
|
|
9812
9812
|
init_spawn_sweep_binary();
|
|
9813
9813
|
activeSpawnSweeps = /* @__PURE__ */ new Map();
|
|
@@ -9838,15 +9838,15 @@ function spawnFilterPath(stateRoot, taskId, spawnId) {
|
|
|
9838
9838
|
}
|
|
9839
9839
|
async function writeDurable2(file, body2, exclusive) {
|
|
9840
9840
|
let dir = path74.dirname(file);
|
|
9841
|
-
await
|
|
9842
|
-
let target2 = exclusive ? file : `${file}.${process.pid}.${Date.now()}.tmp`, handle = await
|
|
9841
|
+
await fs64.mkdir(dir, { recursive: !0, mode: 448 });
|
|
9842
|
+
let target2 = exclusive ? file : `${file}.${process.pid}.${Date.now()}.tmp`, handle = await fs64.open(target2, "wx", 384);
|
|
9843
9843
|
try {
|
|
9844
9844
|
await handle.writeFile(body2, "utf8"), await handle.sync();
|
|
9845
9845
|
} finally {
|
|
9846
9846
|
await handle.close();
|
|
9847
9847
|
}
|
|
9848
|
-
exclusive || await
|
|
9849
|
-
let dirHandle = await
|
|
9848
|
+
exclusive || await fs64.rename(target2, file);
|
|
9849
|
+
let dirHandle = await fs64.open(dir, "r");
|
|
9850
9850
|
try {
|
|
9851
9851
|
await dirHandle.sync();
|
|
9852
9852
|
} finally {
|
|
@@ -9885,9 +9885,9 @@ async function readSpawnRecord(file) {
|
|
|
9885
9885
|
if (!match) return null;
|
|
9886
9886
|
let text2;
|
|
9887
9887
|
try {
|
|
9888
|
-
let st = await
|
|
9888
|
+
let st = await fs64.lstat(file);
|
|
9889
9889
|
if (!st.isFile() || st.size > MAX_RECORD_BYTES2) return null;
|
|
9890
|
-
text2 = await
|
|
9890
|
+
text2 = await fs64.readFile(file, "utf8");
|
|
9891
9891
|
} catch {
|
|
9892
9892
|
return null;
|
|
9893
9893
|
}
|
|
@@ -9934,13 +9934,13 @@ function sweepRecordOf(record2) {
|
|
|
9934
9934
|
async function removeExactDirectory(dir) {
|
|
9935
9935
|
let st;
|
|
9936
9936
|
try {
|
|
9937
|
-
st = await
|
|
9937
|
+
st = await fs64.lstat(dir);
|
|
9938
9938
|
} catch (err) {
|
|
9939
9939
|
if (err.code === "ENOENT") return;
|
|
9940
9940
|
throw err;
|
|
9941
9941
|
}
|
|
9942
9942
|
if (!st.isDirectory()) throw new Error(`spawn folder ${dir} is not a directory; left in place`);
|
|
9943
|
-
await
|
|
9943
|
+
await fs64.rm(dir, { recursive: !0, force: !0 });
|
|
9944
9944
|
}
|
|
9945
9945
|
async function removeRecordedSpawn(stateRoot, record2, opts) {
|
|
9946
9946
|
let recordFile = spawnRecordPath(stateRoot, record2.taskId, record2.spawnId);
|
|
@@ -9956,12 +9956,12 @@ async function removeRecordedSpawn(stateRoot, record2, opts) {
|
|
|
9956
9956
|
blockers: result.blockers.map((b) => b.reason)
|
|
9957
9957
|
}), !1;
|
|
9958
9958
|
}
|
|
9959
|
-
return await removeExactDirectory(record2.folder), await
|
|
9959
|
+
return await removeExactDirectory(record2.folder), await fs64.rm(spawnFilterPath(stateRoot, record2.taskId, record2.spawnId), { force: !0 }), await fs64.rm(recordFile, { force: !0 }), !0;
|
|
9960
9960
|
}
|
|
9961
9961
|
async function sweepOrphanSpawnRecords(stateRoot, deps = {}) {
|
|
9962
9962
|
let result = { removed: [], blockedTaskIds: /* @__PURE__ */ new Set(), retained: [] }, isOwnerAlive = deps.isOwnerAlive ?? isProcessIdentityAlive, dirs;
|
|
9963
9963
|
try {
|
|
9964
|
-
dirs = await
|
|
9964
|
+
dirs = await fs64.readdir(stateRoot, { withFileTypes: !0 });
|
|
9965
9965
|
} catch (err) {
|
|
9966
9966
|
if (err.code === "ENOENT") return result;
|
|
9967
9967
|
throw err;
|
|
@@ -9970,7 +9970,7 @@ async function sweepOrphanSpawnRecords(stateRoot, deps = {}) {
|
|
|
9970
9970
|
if (!dir.isDirectory() || dir.isSymbolicLink()) continue;
|
|
9971
9971
|
let stateDir = path74.join(stateRoot, dir.name), files;
|
|
9972
9972
|
try {
|
|
9973
|
-
files = await
|
|
9973
|
+
files = await fs64.readdir(stateDir);
|
|
9974
9974
|
} catch {
|
|
9975
9975
|
continue;
|
|
9976
9976
|
}
|
|
@@ -9996,10 +9996,10 @@ async function sweepOrphanSpawnRecords(stateRoot, deps = {}) {
|
|
|
9996
9996
|
}
|
|
9997
9997
|
return result;
|
|
9998
9998
|
}
|
|
9999
|
-
var fsSync6,
|
|
9999
|
+
var fsSync6, fs64, path74, SPAWN_ID_RE, SPAWN_RECORD_FILE_RE, ADVISORY_STATE_DIR, MAX_RECORD_BYTES2, defaultSweep, init_spawn_records = __esm({
|
|
10000
10000
|
"src/substrate/spawn-records.ts"() {
|
|
10001
10001
|
"use strict";
|
|
10002
|
-
fsSync6 = __toESM(require("node:fs")),
|
|
10002
|
+
fsSync6 = __toESM(require("node:fs")), fs64 = __toESM(require("node:fs/promises")), path74 = __toESM(require("node:path"));
|
|
10003
10003
|
init_logger2();
|
|
10004
10004
|
init_process_identity();
|
|
10005
10005
|
init_spawn_sweep();
|
|
@@ -10274,9 +10274,9 @@ function getPacketFilePath(taskId, homeDir = os46.homedir()) {
|
|
|
10274
10274
|
return path96.join(getTaskDirectoryPath(taskId, homeDir), "CONTINUATION.md");
|
|
10275
10275
|
}
|
|
10276
10276
|
async function atomicWritePacket(taskDir, finalPath, bytes, pid, ts, randHex) {
|
|
10277
|
-
if (await
|
|
10277
|
+
if (await import_node_fs44.promises.mkdir(taskDir, { recursive: !0, mode: 448 }), process.platform !== "win32")
|
|
10278
10278
|
try {
|
|
10279
|
-
await
|
|
10279
|
+
await import_node_fs44.promises.chmod(taskDir, 448);
|
|
10280
10280
|
} catch (err) {
|
|
10281
10281
|
throw new PacketIoError(
|
|
10282
10282
|
`chmod ${taskDir} 0o700 failed: ${err.message}`,
|
|
@@ -10288,11 +10288,11 @@ async function atomicWritePacket(taskDir, finalPath, bytes, pid, ts, randHex) {
|
|
|
10288
10288
|
`CONTINUATION.md.${pid}.${ts}.${randHex}.tmp`
|
|
10289
10289
|
), tmpHandle = null;
|
|
10290
10290
|
try {
|
|
10291
|
-
tmpHandle = await
|
|
10291
|
+
tmpHandle = await import_node_fs44.promises.open(
|
|
10292
10292
|
tmpPath,
|
|
10293
|
-
|
|
10293
|
+
import_node_fs44.constants.O_WRONLY | import_node_fs44.constants.O_CREAT | import_node_fs44.constants.O_TRUNC,
|
|
10294
10294
|
384
|
|
10295
|
-
), await tmpHandle.writeFile(bytes, { encoding: "utf8" }), await tmpHandle.sync(), await tmpHandle.close(), tmpHandle = null, process.platform !== "win32" && await
|
|
10295
|
+
), await tmpHandle.writeFile(bytes, { encoding: "utf8" }), await tmpHandle.sync(), await tmpHandle.close(), tmpHandle = null, process.platform !== "win32" && await import_node_fs44.promises.chmod(tmpPath, 384), await import_node_fs44.promises.rename(tmpPath, finalPath);
|
|
10296
10296
|
} catch (err) {
|
|
10297
10297
|
if (tmpHandle)
|
|
10298
10298
|
try {
|
|
@@ -10300,7 +10300,7 @@ async function atomicWritePacket(taskDir, finalPath, bytes, pid, ts, randHex) {
|
|
|
10300
10300
|
} catch {
|
|
10301
10301
|
}
|
|
10302
10302
|
try {
|
|
10303
|
-
await
|
|
10303
|
+
await import_node_fs44.promises.unlink(tmpPath);
|
|
10304
10304
|
} catch {
|
|
10305
10305
|
}
|
|
10306
10306
|
throw new PacketIoError(
|
|
@@ -10310,7 +10310,7 @@ async function atomicWritePacket(taskDir, finalPath, bytes, pid, ts, randHex) {
|
|
|
10310
10310
|
}
|
|
10311
10311
|
if (process.platform !== "win32")
|
|
10312
10312
|
try {
|
|
10313
|
-
let dirHandle = await
|
|
10313
|
+
let dirHandle = await import_node_fs44.promises.open(taskDir, import_node_fs44.constants.O_RDONLY);
|
|
10314
10314
|
try {
|
|
10315
10315
|
await dirHandle.sync();
|
|
10316
10316
|
} finally {
|
|
@@ -10365,7 +10365,7 @@ function createContinuationPacketWriter(deps) {
|
|
|
10365
10365
|
});
|
|
10366
10366
|
if (result.kind === "error") {
|
|
10367
10367
|
try {
|
|
10368
|
-
await
|
|
10368
|
+
await import_node_fs44.promises.unlink(finalPath);
|
|
10369
10369
|
} catch {
|
|
10370
10370
|
}
|
|
10371
10371
|
throw new PacketAuditEmitError(result.reason);
|
|
@@ -10389,10 +10389,10 @@ function createContinuationPacketWriter(deps) {
|
|
|
10389
10389
|
}
|
|
10390
10390
|
};
|
|
10391
10391
|
}
|
|
10392
|
-
var
|
|
10392
|
+
var import_node_fs44, path96, os46, crypto31, import_json_freeze15, import_yaml, Mutex, WORK_NOT_ENUMERATED_SENTINEL, VERIFICATION_NOT_RECORDED_SENTINEL, init_packet_writer = __esm({
|
|
10393
10393
|
"src/continuation/packet-writer.ts"() {
|
|
10394
10394
|
"use strict";
|
|
10395
|
-
|
|
10395
|
+
import_node_fs44 = require("node:fs"), path96 = __toESM(require("node:path")), os46 = __toESM(require("node:os")), crypto31 = __toESM(require("node:crypto")), import_json_freeze15 = require("json-freeze"), import_yaml = require("yaml");
|
|
10396
10396
|
init_types();
|
|
10397
10397
|
init_dirty_state_collector();
|
|
10398
10398
|
Mutex = class {
|
|
@@ -10591,7 +10591,7 @@ function resolveOnHostPath(cmd, hostPath = process.env.PATH ?? "") {
|
|
|
10591
10591
|
if (!dir.startsWith("/")) continue;
|
|
10592
10592
|
let candidate = path97.join(dir, cmd);
|
|
10593
10593
|
try {
|
|
10594
|
-
return
|
|
10594
|
+
return fs78.accessSync(candidate, fs78.constants.X_OK), candidate;
|
|
10595
10595
|
} catch {
|
|
10596
10596
|
}
|
|
10597
10597
|
}
|
|
@@ -10599,7 +10599,7 @@ function resolveOnHostPath(cmd, hostPath = process.env.PATH ?? "") {
|
|
|
10599
10599
|
}
|
|
10600
10600
|
function xdgUserDirs(homedir47) {
|
|
10601
10601
|
try {
|
|
10602
|
-
let text2 =
|
|
10602
|
+
let text2 = fs78.readFileSync(path97.join(homedir47, ".config", "user-dirs.dirs"), "utf8"), out = [];
|
|
10603
10603
|
for (let m of text2.matchAll(/^XDG_(DESKTOP|DOCUMENTS|DOWNLOAD|MUSIC|PICTURES|PUBLICSHARE|TEMPLATES|VIDEOS)_DIR="([^"]*)"/gm))
|
|
10604
10604
|
out.push(m[2].replace(/^\$HOME/, homedir47));
|
|
10605
10605
|
return out;
|
|
@@ -10709,7 +10709,7 @@ function scanGrantRoot(root, bounds = { maxEntries: 2e5, maxMs: 1e4 }, now = Dat
|
|
|
10709
10709
|
for (; stack.length > 0; ) {
|
|
10710
10710
|
let { dir, rel } = stack.pop(), list;
|
|
10711
10711
|
try {
|
|
10712
|
-
list =
|
|
10712
|
+
list = fs78.readdirSync(dir, { withFileTypes: !0 });
|
|
10713
10713
|
} catch {
|
|
10714
10714
|
continue;
|
|
10715
10715
|
}
|
|
@@ -10732,10 +10732,10 @@ function agentBinaryFolders(resolvedArgv0, realArgv0, input) {
|
|
|
10732
10732
|
}
|
|
10733
10733
|
return { folders };
|
|
10734
10734
|
}
|
|
10735
|
-
var
|
|
10735
|
+
var fs78, path97, inside, strictlyInside, CA_PEM, init_grant_rule = __esm({
|
|
10736
10736
|
"src/substrate/grant-rule.ts"() {
|
|
10737
10737
|
"use strict";
|
|
10738
|
-
|
|
10738
|
+
fs78 = __toESM(require("node:fs")), path97 = __toESM(require("node:path"));
|
|
10739
10739
|
inside = (p, root) => p === root || p.startsWith(root.endsWith("/") ? root : `${root}/`), strictlyInside = (p, root) => p !== root && inside(p, root);
|
|
10740
10740
|
CA_PEM = /^(cacert.*\.pem|ca-bundle.*\.pem|ca-certificates.*\.pem|ca\.pem|cert\.pem|.*chain.*\.pem)$/;
|
|
10741
10741
|
}
|
|
@@ -10949,7 +10949,7 @@ function defaultTierRelayPath() {
|
|
|
10949
10949
|
];
|
|
10950
10950
|
for (let candidate of candidates)
|
|
10951
10951
|
try {
|
|
10952
|
-
if (
|
|
10952
|
+
if (import_node_fs45.default.statSync(candidate).isFile()) return import_node_fs45.default.realpathSync(candidate);
|
|
10953
10953
|
} catch {
|
|
10954
10954
|
}
|
|
10955
10955
|
return null;
|
|
@@ -10959,7 +10959,7 @@ function buildExecArgv2(plan, argv) {
|
|
|
10959
10959
|
if (!resolved) throw new SubstrateUnavailableError("bubblewrap", `agent binary '${argv[0]}' not found on the host PATH`);
|
|
10960
10960
|
let real = resolved;
|
|
10961
10961
|
try {
|
|
10962
|
-
real =
|
|
10962
|
+
real = import_node_fs45.default.realpathSync(resolved);
|
|
10963
10963
|
} catch {
|
|
10964
10964
|
}
|
|
10965
10965
|
let folders = agentBinaryFolders(resolved, real, {
|
|
@@ -10969,7 +10969,7 @@ function buildExecArgv2(plan, argv) {
|
|
|
10969
10969
|
xdgRuntimeDir: process.env.XDG_RUNTIME_DIR,
|
|
10970
10970
|
realpath: (p) => {
|
|
10971
10971
|
try {
|
|
10972
|
-
return
|
|
10972
|
+
return import_node_fs45.default.realpathSync(p);
|
|
10973
10973
|
} catch {
|
|
10974
10974
|
return null;
|
|
10975
10975
|
}
|
|
@@ -10999,10 +10999,10 @@ function buildExecArgv2(plan, argv) {
|
|
|
10999
10999
|
hidden.some((root) => insideOrEqual(own2.host, root) || insideOrEqual(own2.target, root)) && segment.push(own2.mode === "ro" ? "--ro-bind" : "--bind", own2.host, own2.target);
|
|
11000
11000
|
return [...plan.chain, ...plan.pre, ...segment, ...plan.post, ...argv];
|
|
11001
11001
|
}
|
|
11002
|
-
var import_promises5,
|
|
11002
|
+
var import_promises5, import_node_fs45, import_node_os2, import_node_path5, import_node_crypto53, import_node_net, BPF_LD, BPF_W, BPF_ABS, BPF_ALU, BPF_AND, BPF_K, BPF_JMP, BPF_JEQ, BPF_RET, SECCOMP_RET_KILL_PROCESS, SECCOMP_RET_ALLOW, SECCOMP_RET_ERRNO, EAFNOSUPPORT, ENOSYS, AUDIT_ARCH_X86_64, AUDIT_ARCH_AARCH64, AUDIT_ARCH_I386, AUDIT_ARCH_ARM, insideOrEqual, BubblewrapHandle, BubblewrapSubstrate, init_bwrap = __esm({
|
|
11003
11003
|
"src/substrate/bwrap.ts"() {
|
|
11004
11004
|
"use strict";
|
|
11005
|
-
import_promises5 = __toESM(require("node:fs/promises")),
|
|
11005
|
+
import_promises5 = __toESM(require("node:fs/promises")), import_node_fs45 = __toESM(require("node:fs")), import_node_os2 = __toESM(require("node:os")), import_node_path5 = __toESM(require("node:path")), import_node_crypto53 = __toESM(require("node:crypto")), import_node_net = __toESM(require("node:net"));
|
|
11006
11006
|
init_errors();
|
|
11007
11007
|
init_relay_channel();
|
|
11008
11008
|
init_spawn_records();
|
|
@@ -11161,7 +11161,7 @@ var import_promises5, import_node_fs44, import_node_os2, import_node_path5, impo
|
|
|
11161
11161
|
}
|
|
11162
11162
|
}, BubblewrapSubstrate = class {
|
|
11163
11163
|
constructor(deps = {}) {
|
|
11164
|
-
this.runner = deps.runner ?? new ChildProcessCommandRunner(), this.platform = deps.platform ?? process.platform, this.homedir = deps.homedir ?? import_node_os2.default.homedir(), this.stateRoot = deps.stateRoot ?? import_node_path5.default.join(this.homedir, ".codevibe", "shadow-state-v2"), this.cacheRoot = deps.cacheRoot, this.desktopPid = deps.desktopPid ?? process.pid, this.uid = deps.uid ?? (typeof process.getuid == "function" ? process.getuid() : 1e3), this.gid = deps.gid ?? (typeof process.getgid == "function" ? process.getgid() : 1e3), this.fsShim = deps.fsShim, this.tierRelayPath = deps.tierRelayPath, this.nodePath = deps.nodePath ?? process.execPath, this.readBootId = deps.readBootId ?? (() =>
|
|
11164
|
+
this.runner = deps.runner ?? new ChildProcessCommandRunner(), this.platform = deps.platform ?? process.platform, this.homedir = deps.homedir ?? import_node_os2.default.homedir(), this.stateRoot = deps.stateRoot ?? import_node_path5.default.join(this.homedir, ".codevibe", "shadow-state-v2"), this.cacheRoot = deps.cacheRoot, this.desktopPid = deps.desktopPid ?? process.pid, this.uid = deps.uid ?? (typeof process.getuid == "function" ? process.getuid() : 1e3), this.gid = deps.gid ?? (typeof process.getgid == "function" ? process.getgid() : 1e3), this.fsShim = deps.fsShim, this.tierRelayPath = deps.tierRelayPath, this.nodePath = deps.nodePath ?? process.execPath, this.readBootId = deps.readBootId ?? (() => import_node_fs45.default.readFileSync("/proc/sys/kernel/random/boot_id", "utf8")), this.runSweep = deps.runSweep, this.readProcStat = deps.readProcStat;
|
|
11165
11165
|
}
|
|
11166
11166
|
async launch(spec) {
|
|
11167
11167
|
if (this.platform !== "linux")
|
|
@@ -11180,7 +11180,7 @@ var import_promises5, import_node_fs44, import_node_os2, import_node_path5, impo
|
|
|
11180
11180
|
host: "127.0.0.1",
|
|
11181
11181
|
port: Number(match[2]),
|
|
11182
11182
|
relayPath,
|
|
11183
|
-
nodePath: (this.fsShim?.realpathSync ??
|
|
11183
|
+
nodePath: (this.fsShim?.realpathSync ?? import_node_fs45.default.realpathSync)(this.nodePath)
|
|
11184
11184
|
};
|
|
11185
11185
|
}
|
|
11186
11186
|
let adopted = spec.spawnFolder, spawnId = adopted?.spawnId ?? import_node_crypto53.default.randomBytes(8).toString("hex"), taskSegment = spec.taskId || "advisory", taskStateDir = import_node_path5.default.join(this.stateRoot, taskSegment);
|
|
@@ -11225,7 +11225,7 @@ var import_promises5, import_node_fs44, import_node_os2, import_node_path5, impo
|
|
|
11225
11225
|
);
|
|
11226
11226
|
for (let d of ["/bin", "/sbin", "/lib", "/lib32", "/lib64", "/libx32"])
|
|
11227
11227
|
try {
|
|
11228
|
-
let lstat30 = this.fsShim?.lstatSync ??
|
|
11228
|
+
let lstat30 = this.fsShim?.lstatSync ?? import_node_fs45.default.lstatSync, readlink4 = this.fsShim?.readlinkSync ?? import_node_fs45.default.readlinkSync;
|
|
11229
11229
|
if (lstat30(d).isSymbolicLink()) {
|
|
11230
11230
|
let target2 = readlink4(d);
|
|
11231
11231
|
bwrapArgs.push("--symlink", target2, d);
|
|
@@ -11243,7 +11243,7 @@ var import_promises5, import_node_fs44, import_node_os2, import_node_path5, impo
|
|
|
11243
11243
|
), isOpenEgress) {
|
|
11244
11244
|
let resolvedResolv = null;
|
|
11245
11245
|
try {
|
|
11246
|
-
let exists = this.fsShim?.existsSync ??
|
|
11246
|
+
let exists = this.fsShim?.existsSync ?? import_node_fs45.default.existsSync, realpath19 = this.fsShim?.realpathSync ?? import_node_fs45.default.realpathSync;
|
|
11247
11247
|
if (!exists("/etc/resolv.conf"))
|
|
11248
11248
|
throw new Error("Host DNS configuration /etc/resolv.conf does not exist");
|
|
11249
11249
|
resolvedResolv = realpath19("/etc/resolv.conf");
|
|
@@ -11300,7 +11300,7 @@ var import_promises5, import_node_fs44, import_node_os2, import_node_path5, impo
|
|
|
11300
11300
|
xdgUserDirs: xdgUserDirs(homedir47),
|
|
11301
11301
|
isWsl: /microsoft/i.test((() => {
|
|
11302
11302
|
try {
|
|
11303
|
-
return
|
|
11303
|
+
return import_node_fs45.default.readFileSync("/proc/version", "utf8");
|
|
11304
11304
|
} catch {
|
|
11305
11305
|
return "";
|
|
11306
11306
|
}
|
|
@@ -11309,14 +11309,14 @@ var import_promises5, import_node_fs44, import_node_os2, import_node_path5, impo
|
|
|
11309
11309
|
defaultPath: ["/usr/local/bin", "/usr/bin", "/bin"],
|
|
11310
11310
|
realpath: (p) => {
|
|
11311
11311
|
try {
|
|
11312
|
-
return
|
|
11312
|
+
return import_node_fs45.default.realpathSync(p);
|
|
11313
11313
|
} catch {
|
|
11314
11314
|
return null;
|
|
11315
11315
|
}
|
|
11316
11316
|
},
|
|
11317
11317
|
isDirectory: (p) => {
|
|
11318
11318
|
try {
|
|
11319
|
-
return
|
|
11319
|
+
return import_node_fs45.default.statSync(p).isDirectory();
|
|
11320
11320
|
} catch {
|
|
11321
11321
|
return !1;
|
|
11322
11322
|
}
|
|
@@ -11492,7 +11492,7 @@ function companionPreferenceFilePath() {
|
|
|
11492
11492
|
async function readCompanionPreference() {
|
|
11493
11493
|
let filePath = companionPreferenceFilePath(), raw, st;
|
|
11494
11494
|
try {
|
|
11495
|
-
st = await
|
|
11495
|
+
st = await fs99.stat(filePath);
|
|
11496
11496
|
} catch (err) {
|
|
11497
11497
|
return err?.code !== "ENOENT" && logger.debug("[companion-preference] stat error \u2014 treating as missing", {
|
|
11498
11498
|
filePath,
|
|
@@ -11505,7 +11505,7 @@ async function readCompanionPreference() {
|
|
|
11505
11505
|
`
|
|
11506
11506
|
), null;
|
|
11507
11507
|
try {
|
|
11508
|
-
raw = await
|
|
11508
|
+
raw = await fs99.readFile(filePath, "utf8");
|
|
11509
11509
|
} catch (err) {
|
|
11510
11510
|
return logger.debug("[companion-preference] read error \u2014 treating as missing", {
|
|
11511
11511
|
filePath,
|
|
@@ -11523,19 +11523,19 @@ async function readCompanionPreference() {
|
|
|
11523
11523
|
}
|
|
11524
11524
|
async function persistCompanionPreference(pref) {
|
|
11525
11525
|
let filePath = companionPreferenceFilePath(), dir = path119.dirname(filePath);
|
|
11526
|
-
await
|
|
11526
|
+
await fs99.mkdir(dir, { recursive: !0 }), await fs99.writeFile(filePath, JSON.stringify(pref, null, 2), {
|
|
11527
11527
|
encoding: "utf8",
|
|
11528
11528
|
mode: 384
|
|
11529
11529
|
});
|
|
11530
11530
|
try {
|
|
11531
|
-
await
|
|
11531
|
+
await fs99.chmod(filePath, 384);
|
|
11532
11532
|
} catch {
|
|
11533
11533
|
}
|
|
11534
11534
|
}
|
|
11535
|
-
var
|
|
11535
|
+
var fs99, path119, os59, import_zod17, CompanionPreferenceSchema, init_persist_preference = __esm({
|
|
11536
11536
|
"src/companion-mode/persist-preference.ts"() {
|
|
11537
11537
|
"use strict";
|
|
11538
|
-
|
|
11538
|
+
fs99 = __toESM(require("fs/promises")), path119 = __toESM(require("path")), os59 = __toESM(require("os")), import_zod17 = require("zod");
|
|
11539
11539
|
init_logger2();
|
|
11540
11540
|
CompanionPreferenceSchema = import_zod17.z.object({
|
|
11541
11541
|
lastAgent: import_zod17.z.union([
|
|
@@ -11600,13 +11600,13 @@ function isContainedPath(parent, candidate) {
|
|
|
11600
11600
|
}
|
|
11601
11601
|
function resolveDeclaredCompanionLauncher(packageJsonPath) {
|
|
11602
11602
|
try {
|
|
11603
|
-
let packageRoot =
|
|
11604
|
-
|
|
11603
|
+
let packageRoot = fs100.realpathSync(path120.dirname(packageJsonPath)), declared = JSON.parse(
|
|
11604
|
+
fs100.readFileSync(packageJsonPath, "utf8")
|
|
11605
11605
|
).codevibe?.companionLauncher;
|
|
11606
11606
|
if (typeof declared != "string" || declared.trim().length === 0)
|
|
11607
11607
|
return null;
|
|
11608
|
-
let launcherPath =
|
|
11609
|
-
return !isContainedPath(packageRoot, launcherPath) || !
|
|
11608
|
+
let launcherPath = fs100.realpathSync(path120.resolve(packageRoot, declared));
|
|
11609
|
+
return !isContainedPath(packageRoot, launcherPath) || !fs100.statSync(launcherPath).isFile() ? null : (fs100.accessSync(launcherPath, fs100.constants.X_OK), launcherPath);
|
|
11610
11610
|
} catch {
|
|
11611
11611
|
return null;
|
|
11612
11612
|
}
|
|
@@ -11716,10 +11716,10 @@ async function runCompanionMode(args) {
|
|
|
11716
11716
|
process.kill(process.pid, signal);
|
|
11717
11717
|
}))(child.signal), 1) : child.status ?? 1;
|
|
11718
11718
|
}
|
|
11719
|
-
var import_child_process12, import_module, path120,
|
|
11719
|
+
var import_child_process12, import_module, path120, fs100, NoAgentInstalledError, COMPANION_PLUGIN, ACTIVE_COMPANION_AGENTS, ACTIVATION_AGENT, init_companion_mode = __esm({
|
|
11720
11720
|
"src/companion-mode/index.ts"() {
|
|
11721
11721
|
"use strict";
|
|
11722
|
-
import_child_process12 = require("child_process"), import_module = require("module"), path120 = __toESM(require("path")),
|
|
11722
|
+
import_child_process12 = require("child_process"), import_module = require("module"), path120 = __toESM(require("path")), fs100 = __toESM(require("fs"));
|
|
11723
11723
|
init_env_scrub();
|
|
11724
11724
|
init_logger2();
|
|
11725
11725
|
init_detect_agents();
|
|
@@ -32681,7 +32681,7 @@ async function clearRetiredPlannerCache(userId, cacheRoot = process.env.CODEVIBE
|
|
|
32681
32681
|
}
|
|
32682
32682
|
|
|
32683
32683
|
// src/orchestration-shell/index.ts
|
|
32684
|
-
var path113 = __toESM(require("path")), os55 = __toESM(require("os")), import_promises6 = require("node:fs/promises"),
|
|
32684
|
+
var path113 = __toESM(require("path")), os55 = __toESM(require("os")), import_promises6 = require("node:fs/promises"), fs93 = __toESM(require("node:fs")), import_node_fs54 = require("node:fs"), import_node_child_process19 = require("node:child_process"), import_node_util3 = require("node:util"), import_node_async_hooks = require("node:async_hooks");
|
|
32685
32685
|
|
|
32686
32686
|
// src/orchestration-shell/web/sanitize.ts
|
|
32687
32687
|
function sanitizeForTerminal(input) {
|
|
@@ -41990,7 +41990,7 @@ function formatBytes(bytes) {
|
|
|
41990
41990
|
}
|
|
41991
41991
|
|
|
41992
41992
|
// src/orchestration-shell/quorum-loop.ts
|
|
41993
|
-
var
|
|
41993
|
+
var import_node_fs49 = require("node:fs"), fsSync11 = __toESM(require("node:fs"));
|
|
41994
41994
|
|
|
41995
41995
|
// src/diagnostics/shape-only.ts
|
|
41996
41996
|
function outputShapeOnly(raw) {
|
|
@@ -42112,10 +42112,10 @@ function dedupKeyForBrokerCredentialLoaded(taskId, credentialIssuanceId) {
|
|
|
42112
42112
|
}
|
|
42113
42113
|
|
|
42114
42114
|
// src/orchestration-shell/reviewer-seat-self-test.ts
|
|
42115
|
-
var import_node_crypto32 = require("node:crypto"),
|
|
42115
|
+
var import_node_crypto32 = require("node:crypto"), fs44 = __toESM(require("node:fs/promises")), path49 = __toESM(require("node:path"));
|
|
42116
42116
|
|
|
42117
42117
|
// src/local-executor/tier-self-test.ts
|
|
42118
|
-
var import_node_child_process9 = require("node:child_process"), import_node_crypto31 = require("node:crypto"), fsSync3 = __toESM(require("node:fs")),
|
|
42118
|
+
var import_node_child_process9 = require("node:child_process"), import_node_crypto31 = require("node:crypto"), fsSync3 = __toESM(require("node:fs")), fs42 = __toESM(require("node:fs/promises")), path47 = __toESM(require("node:path"));
|
|
42119
42119
|
init_logger2();
|
|
42120
42120
|
|
|
42121
42121
|
// src/reviewer/providers/failure-classifier.ts
|
|
@@ -42148,7 +42148,7 @@ function classifyFailureFromStdout(stdout) {
|
|
|
42148
42148
|
}
|
|
42149
42149
|
|
|
42150
42150
|
// src/substrate-launch/agy-auth-seed.ts
|
|
42151
|
-
var import_node_child_process8 = require("node:child_process"), crypto15 = __toESM(require("node:crypto")), import_node_fs19 = require("node:fs"), path46 = __toESM(require("node:path"));
|
|
42151
|
+
var import_node_child_process8 = require("node:child_process"), crypto15 = __toESM(require("node:crypto")), import_node_fs19 = require("node:fs"), import_node_fs20 = require("node:fs"), path46 = __toESM(require("node:path"));
|
|
42152
42152
|
|
|
42153
42153
|
// src/local-executor/types.ts
|
|
42154
42154
|
var SpawnArgsInvalid = class extends Error {
|
|
@@ -42174,6 +42174,271 @@ var SpawnArgsInvalid = class extends Error {
|
|
|
42174
42174
|
MARKER_ENV_KEYS.QUORUM
|
|
42175
42175
|
]);
|
|
42176
42176
|
|
|
42177
|
+
// src/substrate-launch/secret-service-client.ts
|
|
42178
|
+
var fs40 = __toESM(require("node:fs")), net = __toESM(require("node:net")), DEADLINE_MS = 3e3, MAX_READ_BYTES = 131072, MAX_SECRET_BYTES = 65536, SECRETS = "org.freedesktop.secrets", SECRETS_PATH = "/org/freedesktop/secrets", SERVICE_IFACE = "org.freedesktop.Secret.Service";
|
|
42179
|
+
function sessionBusSocket(env, uid, isOwnSocket) {
|
|
42180
|
+
let addr = env.DBUS_SESSION_BUS_ADDRESS;
|
|
42181
|
+
if (addr) {
|
|
42182
|
+
for (let entry5 of addr.split(";")) {
|
|
42183
|
+
if (!entry5.startsWith("unix:")) continue;
|
|
42184
|
+
let kv = /* @__PURE__ */ new Map();
|
|
42185
|
+
for (let part of entry5.slice(5).split(",")) {
|
|
42186
|
+
let i = part.indexOf("=");
|
|
42187
|
+
if (i > 0)
|
|
42188
|
+
try {
|
|
42189
|
+
kv.set(part.slice(0, i), decodeURIComponent(part.slice(i + 1)));
|
|
42190
|
+
} catch {
|
|
42191
|
+
return null;
|
|
42192
|
+
}
|
|
42193
|
+
}
|
|
42194
|
+
if (kv.get("path")) return kv.get("path");
|
|
42195
|
+
if (kv.get("abstract")) return `\0${kv.get("abstract")}`;
|
|
42196
|
+
}
|
|
42197
|
+
return null;
|
|
42198
|
+
}
|
|
42199
|
+
let run2 = env.XDG_RUNTIME_DIR;
|
|
42200
|
+
if (run2 && run2.startsWith("/")) {
|
|
42201
|
+
let p = `${run2.replace(/\/+$/, "")}/bus`;
|
|
42202
|
+
if (isOwnSocket(p, uid)) return p;
|
|
42203
|
+
}
|
|
42204
|
+
return null;
|
|
42205
|
+
}
|
|
42206
|
+
function defaultIsOwnSocket(p, uid) {
|
|
42207
|
+
try {
|
|
42208
|
+
let st = fs40.lstatSync(p);
|
|
42209
|
+
return st.isSocket() && st.uid === uid;
|
|
42210
|
+
} catch {
|
|
42211
|
+
return !1;
|
|
42212
|
+
}
|
|
42213
|
+
}
|
|
42214
|
+
var DBusWriter = class {
|
|
42215
|
+
constructor() {
|
|
42216
|
+
this.buf = Buffer.alloc(256);
|
|
42217
|
+
this.len = 0;
|
|
42218
|
+
}
|
|
42219
|
+
ensure(n) {
|
|
42220
|
+
if (this.len + n <= this.buf.length) return;
|
|
42221
|
+
let b = Buffer.alloc(Math.max(this.buf.length * 2, this.len + n));
|
|
42222
|
+
this.buf.copy(b, 0, 0, this.len), this.buf = b;
|
|
42223
|
+
}
|
|
42224
|
+
align(n) {
|
|
42225
|
+
let pad2 = (n - this.len % n) % n;
|
|
42226
|
+
this.ensure(pad2), this.buf.fill(0, this.len, this.len + pad2), this.len += pad2;
|
|
42227
|
+
}
|
|
42228
|
+
y(v) {
|
|
42229
|
+
this.ensure(1), this.buf.writeUInt8(v, this.len), this.len += 1;
|
|
42230
|
+
}
|
|
42231
|
+
u(v) {
|
|
42232
|
+
this.align(4), this.ensure(4), this.buf.writeUInt32LE(v >>> 0, this.len), this.len += 4;
|
|
42233
|
+
}
|
|
42234
|
+
s(v) {
|
|
42235
|
+
let b = Buffer.from(v, "utf8");
|
|
42236
|
+
this.u(b.length), this.ensure(b.length + 1), b.copy(this.buf, this.len), this.len += b.length, this.y(0);
|
|
42237
|
+
}
|
|
42238
|
+
o(v) {
|
|
42239
|
+
this.s(v);
|
|
42240
|
+
}
|
|
42241
|
+
g(v) {
|
|
42242
|
+
let b = Buffer.from(v, "ascii");
|
|
42243
|
+
this.y(b.length), this.ensure(b.length + 1), b.copy(this.buf, this.len), this.len += b.length, this.y(0);
|
|
42244
|
+
}
|
|
42245
|
+
/** An array whose elements align to `elemAlign`; the length excludes the padding before the first element. */
|
|
42246
|
+
a(elemAlign, fill) {
|
|
42247
|
+
this.u(0);
|
|
42248
|
+
let at = this.len - 4;
|
|
42249
|
+
this.align(elemAlign);
|
|
42250
|
+
let start = this.len;
|
|
42251
|
+
fill(), this.buf.writeUInt32LE(this.len - start, at);
|
|
42252
|
+
}
|
|
42253
|
+
done() {
|
|
42254
|
+
return Buffer.from(this.buf.subarray(0, this.len));
|
|
42255
|
+
}
|
|
42256
|
+
}, BASIC = "ybnqiuxtdsogh";
|
|
42257
|
+
function splitSignature(sig) {
|
|
42258
|
+
let out = [], i = 0, one = (inArray) => {
|
|
42259
|
+
let c = sig[i];
|
|
42260
|
+
if (c === void 0) throw new Error("signature");
|
|
42261
|
+
if (c === "a")
|
|
42262
|
+
return i++, `a${one(!0)}`;
|
|
42263
|
+
if (c === "(" || c === "{") {
|
|
42264
|
+
if (c === "{" && !inArray) throw new Error("signature");
|
|
42265
|
+
let close = c === "(" ? ")" : "}", members = [];
|
|
42266
|
+
for (i++; sig[i] !== close; ) {
|
|
42267
|
+
if (i >= sig.length) throw new Error("signature");
|
|
42268
|
+
members.push(one(!1));
|
|
42269
|
+
}
|
|
42270
|
+
if (i++, members.length === 0) throw new Error("signature");
|
|
42271
|
+
if (c === "{" && (members.length !== 2 || !BASIC.includes(members[0]))) throw new Error("signature");
|
|
42272
|
+
return c + members.join("") + close;
|
|
42273
|
+
}
|
|
42274
|
+
if (!BASIC.includes(c) && c !== "v") throw new Error("signature");
|
|
42275
|
+
return i++, c;
|
|
42276
|
+
};
|
|
42277
|
+
for (; i < sig.length; ) out.push(one(!1));
|
|
42278
|
+
return out;
|
|
42279
|
+
}
|
|
42280
|
+
var ALIGN = { y: 1, b: 4, n: 2, q: 2, i: 4, u: 4, x: 8, t: 8, d: 8, s: 4, o: 4, g: 1, v: 1, h: 4, a: 4, "(": 8, "{": 8 }, DBusReader = class {
|
|
42281
|
+
constructor(b, off, le) {
|
|
42282
|
+
this.b = b;
|
|
42283
|
+
this.off = off;
|
|
42284
|
+
this.le = le;
|
|
42285
|
+
}
|
|
42286
|
+
align(n) {
|
|
42287
|
+
if (this.off += (n - this.off % n) % n, this.off > this.b.length) throw new Error("short");
|
|
42288
|
+
}
|
|
42289
|
+
need(n) {
|
|
42290
|
+
if (this.off + n > this.b.length) throw new Error("short");
|
|
42291
|
+
}
|
|
42292
|
+
u32() {
|
|
42293
|
+
this.align(4), this.need(4);
|
|
42294
|
+
let v = this.le ? this.b.readUInt32LE(this.off) : this.b.readUInt32BE(this.off);
|
|
42295
|
+
return this.off += 4, v;
|
|
42296
|
+
}
|
|
42297
|
+
str(len) {
|
|
42298
|
+
this.need(len + 1);
|
|
42299
|
+
let v = this.b.toString("utf8", this.off, this.off + len);
|
|
42300
|
+
return this.off += len + 1, v;
|
|
42301
|
+
}
|
|
42302
|
+
read(t) {
|
|
42303
|
+
switch (t[0]) {
|
|
42304
|
+
case "y":
|
|
42305
|
+
return this.need(1), this.b.readUInt8(this.off++);
|
|
42306
|
+
case "b":
|
|
42307
|
+
return this.u32() !== 0;
|
|
42308
|
+
case "u":
|
|
42309
|
+
case "h":
|
|
42310
|
+
return this.u32();
|
|
42311
|
+
case "i":
|
|
42312
|
+
return this.u32() | 0;
|
|
42313
|
+
case "s":
|
|
42314
|
+
case "o":
|
|
42315
|
+
return this.str(this.u32());
|
|
42316
|
+
case "g": {
|
|
42317
|
+
this.need(1);
|
|
42318
|
+
let n = this.b.readUInt8(this.off++);
|
|
42319
|
+
return this.str(n);
|
|
42320
|
+
}
|
|
42321
|
+
case "v": {
|
|
42322
|
+
let sig = this.read("g"), types = splitSignature(sig);
|
|
42323
|
+
if (types.length !== 1) throw new Error("variant");
|
|
42324
|
+
return this.align(ALIGN[types[0][0]]), { sig, value: this.read(types[0]) };
|
|
42325
|
+
}
|
|
42326
|
+
case "a": {
|
|
42327
|
+
let n = this.u32(), et = t.slice(1);
|
|
42328
|
+
this.align(ALIGN[et[0]]);
|
|
42329
|
+
let end = this.off + n;
|
|
42330
|
+
if (this.need(n), et === "y") {
|
|
42331
|
+
let v = Buffer.from(this.b.subarray(this.off, end));
|
|
42332
|
+
return this.off = end, v;
|
|
42333
|
+
}
|
|
42334
|
+
let out = [];
|
|
42335
|
+
for (; this.off < end; ) {
|
|
42336
|
+
let at = this.off;
|
|
42337
|
+
if (out.push(this.read(et)), this.off <= at) throw new Error("array");
|
|
42338
|
+
}
|
|
42339
|
+
if (this.off !== end) throw new Error("array");
|
|
42340
|
+
return out;
|
|
42341
|
+
}
|
|
42342
|
+
case "(":
|
|
42343
|
+
case "{":
|
|
42344
|
+
return this.align(8), splitSignature(t.slice(1, -1)).map((x) => this.read(x));
|
|
42345
|
+
default:
|
|
42346
|
+
throw new Error(`type ${t}`);
|
|
42347
|
+
}
|
|
42348
|
+
}
|
|
42349
|
+
};
|
|
42350
|
+
function methodCall(serial, dest, path122, iface, member, signature, fill) {
|
|
42351
|
+
let body2 = new DBusWriter();
|
|
42352
|
+
fill?.(body2);
|
|
42353
|
+
let bodyBuf = body2.done(), h = new DBusWriter();
|
|
42354
|
+
return h.y(108), h.y(1), h.y(0), h.y(1), h.u(bodyBuf.length), h.u(serial), h.a(8, () => {
|
|
42355
|
+
let field2 = (code, sig, write) => {
|
|
42356
|
+
h.align(8), h.y(code), h.g(sig), write();
|
|
42357
|
+
};
|
|
42358
|
+
field2(1, "o", () => h.o(path122)), field2(2, "s", () => h.s(iface)), field2(3, "s", () => h.s(member)), field2(6, "s", () => h.s(dest)), signature && field2(8, "g", () => h.g(signature));
|
|
42359
|
+
}), h.align(8), Buffer.concat([h.done(), bodyBuf]);
|
|
42360
|
+
}
|
|
42361
|
+
function parseMessage(b, wantBody = () => !0) {
|
|
42362
|
+
if (b.length < 16) return null;
|
|
42363
|
+
let le = b[0] === 108;
|
|
42364
|
+
if (!le && b[0] !== 66) throw new Error("endianness");
|
|
42365
|
+
let r = new DBusReader(b, 4, le), bodyLen = r.u32(), serial = r.u32(), fieldsLen = r.u32(), headerEnd = 16 + fieldsLen + (8 - (16 + fieldsLen) % 8) % 8, size2 = headerEnd + bodyLen;
|
|
42366
|
+
if (size2 > MAX_READ_BYTES) throw new Error("size");
|
|
42367
|
+
if (b.length < size2) return null;
|
|
42368
|
+
let fields = new DBusReader(b.subarray(0, 16 + fieldsLen), 12, le).read("a(yv)"), msg = { type: b[1], serial, signature: "", body: [] };
|
|
42369
|
+
for (let f of fields) {
|
|
42370
|
+
let [code, v] = f;
|
|
42371
|
+
code === 5 && (msg.replySerial = v.value), code === 3 && (msg.member = v.value), code === 4 && (msg.errorName = v.value), code === 8 && (msg.signature = v.value);
|
|
42372
|
+
}
|
|
42373
|
+
if (!wantBody(msg)) return { msg, size: size2 };
|
|
42374
|
+
let br = new DBusReader(b.subarray(0, size2), headerEnd, le);
|
|
42375
|
+
if (msg.body = splitSignature(msg.signature).map((t) => br.read(t)), br.off !== size2) throw new Error("body");
|
|
42376
|
+
return { msg, size: size2 };
|
|
42377
|
+
}
|
|
42378
|
+
function readSecretServiceItem(attributes, opts = {}) {
|
|
42379
|
+
let uid = opts.uid ?? (typeof process.getuid == "function" ? process.getuid() : -1), socketPath = uid < 0 ? null : sessionBusSocket(opts.env ?? process.env, uid, opts.isOwnSocket ?? defaultIsOwnSocket);
|
|
42380
|
+
return socketPath ? new Promise((resolve35) => {
|
|
42381
|
+
let phase = "auth", sock = (opts.connect ?? ((p) => net.createConnection({ path: p })))(socketPath), finish = (r) => {
|
|
42382
|
+
phase !== "done" && (phase = "done", clearTimeout(timer), sock.destroy(), resolve35(r));
|
|
42383
|
+
}, timer = setTimeout(() => finish({ kind: "error", why: "keychain-timeout" }), opts.timeoutMs ?? DEADLINE_MS), buf = Buffer.alloc(0), total = 0, serial = 0, waiting = /* @__PURE__ */ new Map(), call = (dest, path122, iface, member, sig, fill) => new Promise((res) => {
|
|
42384
|
+
serial += 1, waiting.set(serial, res), sock.write(methodCall(serial, dest, path122, iface, member, sig, fill));
|
|
42385
|
+
}), ok = (m, sig) => {
|
|
42386
|
+
if (m.type !== 2 || m.signature !== sig) throw new Error("reply");
|
|
42387
|
+
return m.body;
|
|
42388
|
+
}, run2 = async () => {
|
|
42389
|
+
ok(await call("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "Hello", ""), "s");
|
|
42390
|
+
let opened = await call(SECRETS, SECRETS_PATH, SERVICE_IFACE, "OpenSession", "sv", (w) => {
|
|
42391
|
+
w.s("plain"), w.g("s"), w.s("");
|
|
42392
|
+
});
|
|
42393
|
+
if (opened.type === 3) {
|
|
42394
|
+
let absent = /^org\.freedesktop\.DBus\.Error\.(ServiceUnknown|NameHasNoOwner|Spawn\.)/.test(opened.errorName ?? "");
|
|
42395
|
+
return finish(absent ? { kind: "none", why: "not-signed-in" } : { kind: "error", why: "keychain-error" });
|
|
42396
|
+
}
|
|
42397
|
+
let session2 = ok(opened, "vo")[1], search = ok(await call(SECRETS, SECRETS_PATH, SERVICE_IFACE, "SearchItems", "a{ss}", (w) => w.a(8, () => {
|
|
42398
|
+
for (let [k, v] of Object.entries(attributes))
|
|
42399
|
+
w.align(8), w.s(k), w.s(v);
|
|
42400
|
+
})), "aoao"), [unlocked, locked] = search;
|
|
42401
|
+
if (unlocked.length === 0) return finish({ kind: "none", why: locked.length > 0 ? "keychain-locked" : "not-signed-in" });
|
|
42402
|
+
let entry5 = ok(await call(SECRETS, SECRETS_PATH, SERVICE_IFACE, "GetSecrets", "aoo", (w) => {
|
|
42403
|
+
w.a(4, () => w.o(unlocked[0])), w.o(session2);
|
|
42404
|
+
}), "a{o(oayays)}")[0].find((e) => e[0] === unlocked[0]);
|
|
42405
|
+
if (!entry5) return finish({ kind: "error", why: "keychain-error" });
|
|
42406
|
+
let value = entry5[1][2];
|
|
42407
|
+
if (value.length > MAX_SECRET_BYTES) return finish({ kind: "error", why: "keychain-invalid" });
|
|
42408
|
+
finish({ kind: "secret", data: Buffer.from(value) });
|
|
42409
|
+
};
|
|
42410
|
+
sock.on("error", () => finish({ kind: "error", why: "keychain-error" })), sock.on("close", () => finish({ kind: "error", why: "keychain-error" })), sock.on("connect", () => {
|
|
42411
|
+
let uidHex = Buffer.from(String(uid), "ascii").toString("hex");
|
|
42412
|
+
sock.write(Buffer.concat([Buffer.from([0]), Buffer.from(`AUTH EXTERNAL ${uidHex}\r
|
|
42413
|
+
`, "ascii")]));
|
|
42414
|
+
}), sock.on("data", (chunk) => {
|
|
42415
|
+
if (total += chunk.length, total > MAX_READ_BYTES) return finish({ kind: "error", why: "keychain-invalid" });
|
|
42416
|
+
buf = Buffer.concat([buf, chunk]);
|
|
42417
|
+
try {
|
|
42418
|
+
if (phase === "auth") {
|
|
42419
|
+
let nl = buf.indexOf(`\r
|
|
42420
|
+
`);
|
|
42421
|
+
if (nl < 0) return;
|
|
42422
|
+
let line = buf.toString("ascii", 0, nl);
|
|
42423
|
+
if (buf = buf.subarray(nl + 2), !line.startsWith("OK ")) return finish({ kind: "error", why: "keychain-error" });
|
|
42424
|
+
phase = "messages", sock.write(`BEGIN\r
|
|
42425
|
+
`), run2().catch(() => finish({ kind: "error", why: "keychain-error" }));
|
|
42426
|
+
}
|
|
42427
|
+
for (; ; ) {
|
|
42428
|
+
if (phase !== "messages") return;
|
|
42429
|
+
let p = parseMessage(buf, (m) => (m.type === 2 || m.type === 3) && m.replySerial !== void 0 && waiting.has(m.replySerial));
|
|
42430
|
+
if (!p) return;
|
|
42431
|
+
buf = buf.subarray(p.size);
|
|
42432
|
+
let want = p.msg.replySerial !== void 0 ? waiting.get(p.msg.replySerial) : void 0;
|
|
42433
|
+
want && (p.msg.type === 2 || p.msg.type === 3) && (waiting.delete(p.msg.replySerial), want(p.msg));
|
|
42434
|
+
}
|
|
42435
|
+
} catch (e) {
|
|
42436
|
+
finish({ kind: "error", why: e.message === "size" ? "keychain-invalid" : "keychain-error" });
|
|
42437
|
+
}
|
|
42438
|
+
});
|
|
42439
|
+
}) : Promise.resolve({ kind: "none", why: "not-signed-in" });
|
|
42440
|
+
}
|
|
42441
|
+
|
|
42177
42442
|
// src/substrate-launch/agy-auth-seed.ts
|
|
42178
42443
|
var AGY_SIGN_IN_NOTICE = "No answer \u2014 Antigravity isn't signed in. Run `agy` once in a terminal to sign in.", AGY_SIGN_IN_REASON = "Antigravity isn't signed in. Run `agy` once in a terminal to sign in.", AGENT_SIGNED_OUT = "agent_signed_out", AGY_TOKEN_FILE = "antigravity-oauth-token", KEYCHAIN_SERVICE = "gemini", KEYCHAIN_ACCOUNT = "antigravity", KEYCHAIN_PREFIX = "go-keyring-base64:", SECURITY_BIN = "/usr/bin/security", KEYCHAIN_TIMEOUT_MS = 1e4, MAX_VALUE_BYTES = 65536, KEYCHAIN_SERVICE_TEST_ENV = "CODEVIBE_AGY_KEYCHAIN_SERVICE_FOR_TESTS", TEST_SERVICE_PREFIX = "codevibe-test-", TEST_SERVICE_FALLBACK = "codevibe-test-invalid-seam", AgentSignInUnavailable = class extends SpawnConfinementUnavailable {
|
|
42179
42444
|
constructor(why) {
|
|
@@ -42182,6 +42447,19 @@ var AGY_SIGN_IN_NOTICE = "No answer \u2014 Antigravity isn't signed in. Run `agy
|
|
|
42182
42447
|
this.name = "AgentSignInUnavailable";
|
|
42183
42448
|
}
|
|
42184
42449
|
};
|
|
42450
|
+
function nativeLinux(deps) {
|
|
42451
|
+
if ((deps.platform ?? process.platform) !== "linux") return !1;
|
|
42452
|
+
if (deps.isWsl !== void 0) return !deps.isWsl;
|
|
42453
|
+
try {
|
|
42454
|
+
return !/microsoft/i.test((deps.procVersion ?? (() => (0, import_node_fs20.readFileSync)("/proc/version", "utf8")))());
|
|
42455
|
+
} catch {
|
|
42456
|
+
return !0;
|
|
42457
|
+
}
|
|
42458
|
+
}
|
|
42459
|
+
async function readSecretService(deps) {
|
|
42460
|
+
let attributes = { service: keychainService(deps.env ?? process.env), username: KEYCHAIN_ACCOUNT }, r = await (deps.secretService ?? ((a) => readSecretServiceItem(a, { env: deps.env })))(attributes);
|
|
42461
|
+
return r.kind !== "secret" ? { source: "none", why: r.why } : validAgySignInJson(r.data) ? { source: "secret-service", data: r.data } : { source: "none", why: "keychain-invalid" };
|
|
42462
|
+
}
|
|
42185
42463
|
function validAgySignInJson(data) {
|
|
42186
42464
|
if (data.length < 2 || data.length > MAX_VALUE_BYTES) return !1;
|
|
42187
42465
|
let parsed;
|
|
@@ -42242,7 +42520,7 @@ function readKeychain(deps) {
|
|
|
42242
42520
|
}
|
|
42243
42521
|
async function readAgySignIn(hostAgyDir, deps = {}) {
|
|
42244
42522
|
let file = await readTokenFile(hostAgyDir);
|
|
42245
|
-
return file ? { source: "file", data: file } : (deps.platform ?? process.platform)
|
|
42523
|
+
return file ? { source: "file", data: file } : (deps.platform ?? process.platform) === "darwin" ? readKeychain(deps) : nativeLinux(deps) ? readSecretService(deps) : { source: "none", why: "not-signed-in" };
|
|
42246
42524
|
}
|
|
42247
42525
|
async function legacyCopy(hostAgyDir, destAgyDir) {
|
|
42248
42526
|
let dest = path46.join(destAgyDir, AGY_TOKEN_FILE);
|
|
@@ -42255,7 +42533,7 @@ async function legacyCopy(hostAgyDir, destAgyDir) {
|
|
|
42255
42533
|
}
|
|
42256
42534
|
}
|
|
42257
42535
|
async function seedAgySignIn(hostAgyDir, destAgyDir, deps = {}) {
|
|
42258
|
-
if ((deps.platform ?? process.platform) !== "darwin") return legacyCopy(hostAgyDir, destAgyDir);
|
|
42536
|
+
if ((deps.platform ?? process.platform) !== "darwin" && !nativeLinux(deps)) return legacyCopy(hostAgyDir, destAgyDir);
|
|
42259
42537
|
let signIn = await readAgySignIn(hostAgyDir, deps);
|
|
42260
42538
|
if (signIn.source === "none") throw new AgentSignInUnavailable(signIn.why);
|
|
42261
42539
|
let dest = path46.join(destAgyDir, AGY_TOKEN_FILE), handle = await import_node_fs19.promises.open(dest, import_node_fs19.constants.O_WRONLY | import_node_fs19.constants.O_CREAT | import_node_fs19.constants.O_EXCL | import_node_fs19.constants.O_NOFOLLOW, 384);
|
|
@@ -42327,7 +42605,7 @@ async function runOne(input, view, brief) {
|
|
|
42327
42605
|
if (handle.lastMessageCapturePath)
|
|
42328
42606
|
try {
|
|
42329
42607
|
output = `${output}
|
|
42330
|
-
${await
|
|
42608
|
+
${await fs42.readFile(handle.lastMessageCapturePath, "utf8")}`;
|
|
42331
42609
|
} catch {
|
|
42332
42610
|
}
|
|
42333
42611
|
return await input.removeTaskFolder?.(taskId).catch(() => {
|
|
@@ -42340,17 +42618,17 @@ function isTransientFailure(r) {
|
|
|
42340
42618
|
return label === "usage_limit" || label === "auth_failed" || label === "timeout";
|
|
42341
42619
|
}
|
|
42342
42620
|
async function runTierSelfTest(input) {
|
|
42343
|
-
let root = await
|
|
42621
|
+
let root = await fs42.realpath(await fs42.mkdtemp(path47.join(input.viewParent, "self-test-"))), view = path47.join(root, "view");
|
|
42344
42622
|
try {
|
|
42345
|
-
await
|
|
42623
|
+
await fs42.mkdir(view);
|
|
42346
42624
|
let firstLine = `codevibe self-test ${(0, import_node_crypto31.randomUUID)().slice(0, 8)}`;
|
|
42347
|
-
await
|
|
42625
|
+
await fs42.writeFile(path47.join(view, FILE), `${firstLine}
|
|
42348
42626
|
second line
|
|
42349
42627
|
`);
|
|
42350
|
-
let before = (0, import_node_crypto31.createHash)("sha256").update(await
|
|
42628
|
+
let before = (0, import_node_crypto31.createHash)("sha256").update(await fs42.readFile(path47.join(view, FILE))).digest("hex");
|
|
42351
42629
|
if (input.mode === "execute") {
|
|
42352
42630
|
let wanted = `ok-${(0, import_node_crypto31.randomUUID)().slice(0, 8)}`, r2 = await runOne(input, view, `Replace the first line of ${FILE} with exactly this text: ${wanted}
|
|
42353
|
-
Change nothing else and do not create any other file.`), after2 = await
|
|
42631
|
+
Change nothing else and do not create any other file.`), after2 = await fs42.readFile(path47.join(view, FILE), "utf8").catch(() => "");
|
|
42354
42632
|
if (r2.exitCode !== 0)
|
|
42355
42633
|
return { pass: !1, reason: `the agent exited ${r2.exitCode} on the edit task`, ...isTransientFailure(r2) ? { transient: !0 } : {} };
|
|
42356
42634
|
if (after2.split(`
|
|
@@ -42366,12 +42644,12 @@ Change nothing else and do not create any other file.`), after2 = await fs41.rea
|
|
|
42366
42644
|
}
|
|
42367
42645
|
return { pass: !0, ...agyCommandTool ? { agyCommandTool } : {} };
|
|
42368
42646
|
}
|
|
42369
|
-
let r = await runOne(input, view, `What is the first line of ${FILE}? Reply with that line only, exactly as written.`), after = (0, import_node_crypto31.createHash)("sha256").update(await
|
|
42647
|
+
let r = await runOne(input, view, `What is the first line of ${FILE}? Reply with that line only, exactly as written.`), after = (0, import_node_crypto31.createHash)("sha256").update(await fs42.readFile(path47.join(view, FILE)).catch(() => Buffer.alloc(0))).digest("hex");
|
|
42370
42648
|
return r.exitCode !== 0 ? { pass: !1, reason: `the agent exited ${r.exitCode} on the read-only question`, ...isTransientFailure(r) ? { transient: !0 } : {} } : r.output.includes(firstLine) ? after !== before ? { pass: !1, reason: "the read-only run changed the view" } : { pass: !0 } : { pass: !1, reason: "the agent exited 0 but its answer did not quote the first line" };
|
|
42371
42649
|
} catch (err) {
|
|
42372
42650
|
return err instanceof AgentSignInUnavailable ? { pass: !1, reason: err.reason, transient: !0, signInWhy: err.why } : { pass: !1, reason: `the self-test could not run (${err.message})`, transient: !0 };
|
|
42373
42651
|
} finally {
|
|
42374
|
-
await
|
|
42652
|
+
await fs42.rm(root, { recursive: !0, force: !0 }).catch((e) => {
|
|
42375
42653
|
logger.warn("[TierSelfTest] could not remove the throwaway view", { root, err: e.message });
|
|
42376
42654
|
});
|
|
42377
42655
|
}
|
|
@@ -43157,7 +43435,7 @@ async function buildVerdict2(spec, gateId, outcome2, classifyVerdict, onFinalTex
|
|
|
43157
43435
|
}
|
|
43158
43436
|
|
|
43159
43437
|
// src/reviewer/providers/codex.ts
|
|
43160
|
-
var
|
|
43438
|
+
var fs43 = __toESM(require("fs")), os28 = __toESM(require("os")), path48 = __toESM(require("path")), import_uuid10 = require("uuid");
|
|
43161
43439
|
init_env_scrub();
|
|
43162
43440
|
var CodexReviewerProvider = class {
|
|
43163
43441
|
constructor(opts = {}) {
|
|
@@ -43202,7 +43480,7 @@ var CodexReviewerProvider = class {
|
|
|
43202
43480
|
}
|
|
43203
43481
|
let lastMessage;
|
|
43204
43482
|
try {
|
|
43205
|
-
lastMessage =
|
|
43483
|
+
lastMessage = fs43.readFileSync(hostPath, "utf8");
|
|
43206
43484
|
} catch (ioErr) {
|
|
43207
43485
|
bestEffortUnlink(hostPath);
|
|
43208
43486
|
let reason = ioErr instanceof Error ? ioErr.message : String(ioErr);
|
|
@@ -43324,7 +43602,7 @@ function resolveLastMessagePaths(sandboxed, workdir) {
|
|
|
43324
43602
|
}
|
|
43325
43603
|
function bestEffortUnlink(p) {
|
|
43326
43604
|
try {
|
|
43327
|
-
|
|
43605
|
+
fs43.unlinkSync(p);
|
|
43328
43606
|
} catch {
|
|
43329
43607
|
}
|
|
43330
43608
|
}
|
|
@@ -43361,7 +43639,7 @@ function isTransient(err) {
|
|
|
43361
43639
|
return d.kind === "timeout" || d.kind === "cancelled" ? !0 : d.kind === "spawn_failed" && (d.failureReason === "usage_limit" || d.failureReason === "auth_failed" || d.failureReason === "timeout");
|
|
43362
43640
|
}
|
|
43363
43641
|
async function runOnce(input) {
|
|
43364
|
-
let root = await
|
|
43642
|
+
let root = await fs44.realpath(await fs44.mkdtemp(path49.join(await input.config.viewParent(), "self-test-"))), taskId = (0, import_node_crypto32.randomUUID)(), engaged = { seat: null }, result = await runInSeat(input, root, taskId, engaged);
|
|
43365
43643
|
if (engaged.cleanupUnresolved === !0)
|
|
43366
43644
|
return logger.warn("[ReviewerSeatSelfTest] the unconfined fallback could not be cleaned up \u2014 its folders are kept", { root, taskId }), { pass: !1, reason: "the seat's sandbox could not be cleaned up after its self-test", transient: !0 };
|
|
43367
43645
|
if (engaged.seat !== null)
|
|
@@ -43374,7 +43652,7 @@ async function runOnce(input) {
|
|
|
43374
43652
|
taskId
|
|
43375
43653
|
}), { pass: !1, reason: "the seat's sandbox could not be cleaned up after its self-test", transient: !0 };
|
|
43376
43654
|
}
|
|
43377
|
-
return await
|
|
43655
|
+
return await fs44.rm(root, { recursive: !0, force: !0 }).catch(() => {
|
|
43378
43656
|
}), await input.removeTaskFolder?.(taskId).catch(() => {
|
|
43379
43657
|
}), result;
|
|
43380
43658
|
}
|
|
@@ -43382,12 +43660,12 @@ async function runInSeat(input, root, taskId, engaged) {
|
|
|
43382
43660
|
let seat = null;
|
|
43383
43661
|
try {
|
|
43384
43662
|
let view = path49.join(root, "view"), scratch = path49.join(root, "seat");
|
|
43385
|
-
await
|
|
43663
|
+
await fs44.mkdir(view), await fs44.mkdir(scratch, { mode: 448 });
|
|
43386
43664
|
let firstLine = `codevibe self-test ${(0, import_node_crypto32.randomUUID)().slice(0, 8)}`;
|
|
43387
|
-
await
|
|
43665
|
+
await fs44.writeFile(path49.join(view, FILE2), `${firstLine}
|
|
43388
43666
|
second line
|
|
43389
43667
|
`);
|
|
43390
|
-
let before = (0, import_node_crypto32.createHash)("sha256").update(await
|
|
43668
|
+
let before = (0, import_node_crypto32.createHash)("sha256").update(await fs44.readFile(path49.join(view, FILE2))).digest("hex");
|
|
43391
43669
|
if (seat = await input.engage({ taskId, workdir: scratch, bundleDir: view }).catch((err) => {
|
|
43392
43670
|
throw logger.warn("[ReviewerSeatSelfTest] engage failed", { message: err.message }), err?.cleanupUnresolved === !0 && (engaged.cleanupUnresolved = !0), Object.assign(new Error("the seat could not be engaged for its self-test"), { transient: !0 });
|
|
43393
43671
|
}), engaged.seat = seat, seat === null) return { pass: !1, reason: "the seat could not be confined for its self-test", transient: !0 };
|
|
@@ -43416,7 +43694,7 @@ second line
|
|
|
43416
43694
|
}
|
|
43417
43695
|
if (failure2 !== void 0)
|
|
43418
43696
|
return { pass: !1, reason: `the agent failed on the read-only question (${failure2 instanceof ReviewerErrorClass ? failure2.detail.kind : "error"})`, ...isTransient(failure2) ? { transient: !0 } : {} };
|
|
43419
|
-
let after = (0, import_node_crypto32.createHash)("sha256").update(await
|
|
43697
|
+
let after = (0, import_node_crypto32.createHash)("sha256").update(await fs44.readFile(path49.join(view, FILE2)).catch(() => Buffer.alloc(0))).digest("hex");
|
|
43420
43698
|
return finalText?.includes(firstLine) ? after !== before ? { pass: !1, reason: "the read-only run changed the view" } : { pass: !0 } : { pass: !1, reason: "the agent exited 0 but its answer did not quote the first line" };
|
|
43421
43699
|
} catch (err) {
|
|
43422
43700
|
return { pass: !1, reason: `the self-test could not run (${err.message})`, transient: !0 };
|
|
@@ -43453,14 +43731,14 @@ async function ensureReviewerSeatSelfTest(input) {
|
|
|
43453
43731
|
}
|
|
43454
43732
|
|
|
43455
43733
|
// src/local-executor/authority.ts
|
|
43456
|
-
var
|
|
43734
|
+
var import_node_fs21 = require("node:fs"), fsSync4 = __toESM(require("node:fs")), os30 = __toESM(require("node:os")), path52 = __toESM(require("node:path"));
|
|
43457
43735
|
|
|
43458
43736
|
// src/orchestration-shell/web/agent-web-server.ts
|
|
43459
|
-
var crypto16 = __toESM(require("node:crypto")),
|
|
43737
|
+
var crypto16 = __toESM(require("node:crypto")), fs46 = __toESM(require("node:fs")), net3 = __toESM(require("node:net")), os29 = __toESM(require("node:os")), path51 = __toESM(require("node:path")), readline = __toESM(require("node:readline"));
|
|
43460
43738
|
init_logger2();
|
|
43461
43739
|
|
|
43462
43740
|
// src/orchestration-shell/web/extract.ts
|
|
43463
|
-
var
|
|
43741
|
+
var fs45 = __toESM(require("node:fs")), path50 = __toESM(require("node:path")), import_node_worker_threads = require("node:worker_threads");
|
|
43464
43742
|
init_logger2();
|
|
43465
43743
|
var WebExtractTimeoutError = class extends Error {
|
|
43466
43744
|
constructor(timeoutMs) {
|
|
@@ -43601,7 +43879,7 @@ function resolveExtractWorkerPath() {
|
|
|
43601
43879
|
path50.join(__dirname, "..", "src", "orchestration-shell", "web", "web-extract-worker.ts")
|
|
43602
43880
|
];
|
|
43603
43881
|
for (let c of candidates)
|
|
43604
|
-
if (
|
|
43882
|
+
if (fs45.existsSync(c)) return path50.resolve(c);
|
|
43605
43883
|
throw new Error("[extract] Durable web-extract-worker bundle not found");
|
|
43606
43884
|
}
|
|
43607
43885
|
async function htmlToTextWorker(html, options) {
|
|
@@ -44206,7 +44484,7 @@ function isPromptRelevantToRetainedPage(prompt, retainedPage) {
|
|
|
44206
44484
|
var http2 = __toESM(require("node:http")), https3 = __toESM(require("node:https")), dns2 = __toESM(require("node:dns")), zlib2 = __toESM(require("node:zlib")), import_node_string_decoder = require("node:string_decoder");
|
|
44207
44485
|
|
|
44208
44486
|
// src/orchestration-shell/web/ip.ts
|
|
44209
|
-
var
|
|
44487
|
+
var net2 = __toESM(require("node:net"));
|
|
44210
44488
|
function ipv4ToInt(ip) {
|
|
44211
44489
|
let m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(ip);
|
|
44212
44490
|
if (!m) return null;
|
|
@@ -44267,7 +44545,7 @@ function ipv6IsGlobalUnicast(g) {
|
|
|
44267
44545
|
return !((g0 & 65024) === 64512 || (g0 & 65472) === 65152 || (g0 & 65280) === 65280 || g0 === 8193 && g1 === 3512 || g0 === 8194 || g0 === 8193 && g1 === 0 || (g0 & 57344) !== 8192);
|
|
44268
44546
|
}
|
|
44269
44547
|
function isGlobalUnicastIp(addr) {
|
|
44270
|
-
let fam =
|
|
44548
|
+
let fam = net2.isIP(addr);
|
|
44271
44549
|
if (fam === 4) {
|
|
44272
44550
|
let v = ipv4ToInt(addr);
|
|
44273
44551
|
return v !== null && ipv4IsGlobalUnicast(v);
|
|
@@ -44281,7 +44559,7 @@ function isGlobalUnicastIp(addr) {
|
|
|
44281
44559
|
function classifyHost(rawHost) {
|
|
44282
44560
|
let host = rawHost.trim().toLowerCase();
|
|
44283
44561
|
if (host.startsWith("[") && host.endsWith("]") && (host = host.slice(1, -1)), host === "" || host === "localhost" || host.endsWith(".local")) return { kind: "reject" };
|
|
44284
|
-
if (
|
|
44562
|
+
if (net2.isIP(host) !== 0) return { kind: "ip", addr: host };
|
|
44285
44563
|
let dec = /^\d+$/.test(host) ? Number(host) : NaN;
|
|
44286
44564
|
if (Number.isInteger(dec) && dec >= 0 && dec <= 4294967295)
|
|
44287
44565
|
return { kind: "ip", addr: intToIpv4(dec >>> 0) };
|
|
@@ -44613,8 +44891,8 @@ function isPidAlive(pid) {
|
|
|
44613
44891
|
}
|
|
44614
44892
|
function sweepOrphanedFallbackDirs(tmpRoot = os29.tmpdir(), deps = {}) {
|
|
44615
44893
|
try {
|
|
44616
|
-
if (!
|
|
44617
|
-
let lstat30 = deps.lstat ??
|
|
44894
|
+
if (!fs46.existsSync(tmpRoot)) return;
|
|
44895
|
+
let lstat30 = deps.lstat ?? fs46.lstatSync, getuid = deps.getuid ?? (typeof process.getuid == "function" ? () => process.getuid() : null), currentUid = getuid ? getuid() : null, entries = fs46.readdirSync(tmpRoot);
|
|
44618
44896
|
for (let entry5 of entries) {
|
|
44619
44897
|
if (!entry5.startsWith("cv-ipc-")) continue;
|
|
44620
44898
|
let fullPath = path51.join(tmpRoot, entry5);
|
|
@@ -44622,25 +44900,25 @@ function sweepOrphanedFallbackDirs(tmpRoot = os29.tmpdir(), deps = {}) {
|
|
|
44622
44900
|
let stat25 = lstat30(fullPath);
|
|
44623
44901
|
if (stat25.isSymbolicLink() || !stat25.isDirectory() || currentUid !== null && stat25.uid !== currentUid) continue;
|
|
44624
44902
|
let ownerPath = path51.join(fullPath, "owner.json");
|
|
44625
|
-
if (
|
|
44903
|
+
if (fs46.existsSync(ownerPath))
|
|
44626
44904
|
try {
|
|
44627
|
-
let owner = JSON.parse(
|
|
44905
|
+
let owner = JSON.parse(fs46.readFileSync(ownerPath, "utf8"));
|
|
44628
44906
|
if (typeof owner?.pid == "number" && isPidAlive(owner.pid))
|
|
44629
44907
|
continue;
|
|
44630
44908
|
} catch {
|
|
44631
44909
|
}
|
|
44632
|
-
let files =
|
|
44910
|
+
let files = fs46.readdirSync(fullPath);
|
|
44633
44911
|
for (let file of files) {
|
|
44634
44912
|
if (!(file === "owner.json" || file.endsWith(".sock"))) continue;
|
|
44635
44913
|
let filePath = path51.join(fullPath, file);
|
|
44636
44914
|
try {
|
|
44637
44915
|
let fileStat = lstat30(filePath);
|
|
44638
44916
|
if (fileStat.isSymbolicLink()) continue;
|
|
44639
|
-
(fileStat.isFile() || fileStat.isSocket()) &&
|
|
44917
|
+
(fileStat.isFile() || fileStat.isSocket()) && fs46.unlinkSync(filePath);
|
|
44640
44918
|
} catch {
|
|
44641
44919
|
}
|
|
44642
44920
|
}
|
|
44643
|
-
|
|
44921
|
+
fs46.readdirSync(fullPath).length === 0 && fs46.rmdirSync(fullPath);
|
|
44644
44922
|
} catch {
|
|
44645
44923
|
}
|
|
44646
44924
|
}
|
|
@@ -44658,11 +44936,11 @@ function resolveBridgePath() {
|
|
|
44658
44936
|
];
|
|
44659
44937
|
for (let root of packageRoots) {
|
|
44660
44938
|
let pkgJsonPath = path51.join(root, "package.json");
|
|
44661
|
-
if (
|
|
44939
|
+
if (fs46.existsSync(pkgJsonPath))
|
|
44662
44940
|
try {
|
|
44663
|
-
if (JSON.parse(
|
|
44941
|
+
if (JSON.parse(fs46.readFileSync(pkgJsonPath, "utf8")).name === "@quantiya/codevibe-core") {
|
|
44664
44942
|
let candidate = path51.join(root, "bin", "codevibe-web-mcp-bridge.js");
|
|
44665
|
-
if (
|
|
44943
|
+
if (fs46.existsSync(candidate)) return candidate;
|
|
44666
44944
|
}
|
|
44667
44945
|
} catch {
|
|
44668
44946
|
}
|
|
@@ -44674,15 +44952,15 @@ function resolveBridgePath() {
|
|
|
44674
44952
|
path51.join(__dirname, "..", "..", "..", "bin", "codevibe-web-mcp-bridge.js")
|
|
44675
44953
|
];
|
|
44676
44954
|
for (let c of candidates)
|
|
44677
|
-
if (
|
|
44955
|
+
if (fs46.existsSync(c)) return path51.resolve(c);
|
|
44678
44956
|
throw new Error("[agent-web-server] Durable bridge binary codevibe-web-mcp-bridge.js not found");
|
|
44679
44957
|
}
|
|
44680
44958
|
function writeAuditEntry(sessionId, record2) {
|
|
44681
44959
|
try {
|
|
44682
44960
|
let auditDir = path51.join(os29.homedir(), ".codevibe", "sessions", sessionId);
|
|
44683
|
-
|
|
44961
|
+
fs46.mkdirSync(auditDir, { recursive: !0 });
|
|
44684
44962
|
let auditPath = path51.join(auditDir, "web-audit.jsonl");
|
|
44685
|
-
|
|
44963
|
+
fs46.appendFileSync(auditPath, JSON.stringify(record2) + `
|
|
44686
44964
|
`, "utf8");
|
|
44687
44965
|
} catch (err) {
|
|
44688
44966
|
logger.warn("[agent-web-server] Failed to write web audit log", {
|
|
@@ -44714,16 +44992,16 @@ async function startAgentWebTurn(options) {
|
|
|
44714
44992
|
let sessionId = options.sessionId, turnId = options.turnId ?? crypto16.randomBytes(6).toString("hex"), agent = options.agent ?? "CLAUDE", token4 = crypto16.randomBytes(32).toString("hex"), bridgePath = resolveBridgePath(), searchCount = 0, fetchCount = 0, closed4 = !1, turnAbortController = new AbortController();
|
|
44715
44993
|
options.signal && (options.signal.aborted ? turnAbortController.abort() : options.signal.addEventListener("abort", () => turnAbortController.abort(), { once: !0 }));
|
|
44716
44994
|
let primaryIpcDir = path51.join(os29.homedir(), ".codevibe", "ipc");
|
|
44717
|
-
|
|
44995
|
+
fs46.mkdirSync(primaryIpcDir, { recursive: !0, mode: 448 });
|
|
44718
44996
|
try {
|
|
44719
|
-
|
|
44997
|
+
fs46.chmodSync(primaryIpcDir, 448);
|
|
44720
44998
|
} catch {
|
|
44721
44999
|
}
|
|
44722
45000
|
let preferredSocketPath = path51.join(primaryIpcDir, `${turnId}.sock`), socketPath = preferredSocketPath, fallbackDir;
|
|
44723
45001
|
if (Buffer.byteLength(preferredSocketPath, "utf8") > 100) {
|
|
44724
|
-
fallbackDir =
|
|
45002
|
+
fallbackDir = fs46.mkdtempSync(path51.join(os29.tmpdir(), "cv-ipc-")), fs46.chmodSync(fallbackDir, 448);
|
|
44725
45003
|
let ownerFile = path51.join(fallbackDir, "owner.json");
|
|
44726
|
-
|
|
45004
|
+
fs46.writeFileSync(
|
|
44727
45005
|
ownerFile,
|
|
44728
45006
|
JSON.stringify({ pid: process.pid, createdAt: Date.now() }),
|
|
44729
45007
|
{ mode: 384 }
|
|
@@ -44731,15 +45009,15 @@ async function startAgentWebTurn(options) {
|
|
|
44731
45009
|
let safeTurnSuffix = turnId.length > 16 ? turnId.slice(0, 16) : turnId;
|
|
44732
45010
|
socketPath = path51.join(fallbackDir, `${safeTurnSuffix}.sock`);
|
|
44733
45011
|
}
|
|
44734
|
-
if (
|
|
45012
|
+
if (fs46.existsSync(socketPath))
|
|
44735
45013
|
try {
|
|
44736
|
-
|
|
45014
|
+
fs46.unlinkSync(socketPath);
|
|
44737
45015
|
} catch {
|
|
44738
45016
|
}
|
|
44739
45017
|
let sessionDir = path51.join(os29.homedir(), ".codevibe", "sessions", sessionId);
|
|
44740
|
-
|
|
45018
|
+
fs46.mkdirSync(sessionDir, { recursive: !0 });
|
|
44741
45019
|
let mcpConfigPath = path51.join(sessionDir, `mcp-web-${turnId}.json`);
|
|
44742
|
-
|
|
45020
|
+
fs46.writeFileSync(mcpConfigPath, JSON.stringify({
|
|
44743
45021
|
mcpServers: {
|
|
44744
45022
|
"codevibe-web": {
|
|
44745
45023
|
command: "node",
|
|
@@ -44747,7 +45025,7 @@ async function startAgentWebTurn(options) {
|
|
|
44747
45025
|
}
|
|
44748
45026
|
}
|
|
44749
45027
|
}, null, 2), { mode: 384 });
|
|
44750
|
-
let activeSockets = /* @__PURE__ */ new Set(), server =
|
|
45028
|
+
let activeSockets = /* @__PURE__ */ new Set(), server = net3.createServer((socket) => {
|
|
44751
45029
|
activeSockets.add(socket), socket.on("close", () => {
|
|
44752
45030
|
activeSockets.delete(socket);
|
|
44753
45031
|
}), readline.createInterface({
|
|
@@ -45087,7 +45365,7 @@ async function startAgentWebTurn(options) {
|
|
|
45087
45365
|
await new Promise((resolve35, reject) => {
|
|
45088
45366
|
server.listen(socketPath, () => {
|
|
45089
45367
|
try {
|
|
45090
|
-
|
|
45368
|
+
fs46.chmodSync(socketPath, 384), resolve35();
|
|
45091
45369
|
} catch (err) {
|
|
45092
45370
|
reject(err);
|
|
45093
45371
|
}
|
|
@@ -45095,23 +45373,23 @@ async function startAgentWebTurn(options) {
|
|
|
45095
45373
|
});
|
|
45096
45374
|
} catch (listenErr) {
|
|
45097
45375
|
try {
|
|
45098
|
-
|
|
45376
|
+
fs46.existsSync(socketPath) && fs46.unlinkSync(socketPath);
|
|
45099
45377
|
} catch {
|
|
45100
45378
|
}
|
|
45101
45379
|
try {
|
|
45102
|
-
|
|
45380
|
+
fs46.existsSync(mcpConfigPath) && fs46.unlinkSync(mcpConfigPath);
|
|
45103
45381
|
} catch {
|
|
45104
45382
|
}
|
|
45105
45383
|
if (fallbackDir)
|
|
45106
45384
|
try {
|
|
45107
|
-
if (
|
|
45108
|
-
let files =
|
|
45385
|
+
if (fs46.existsSync(fallbackDir)) {
|
|
45386
|
+
let files = fs46.readdirSync(fallbackDir);
|
|
45109
45387
|
for (let f of files)
|
|
45110
45388
|
try {
|
|
45111
|
-
|
|
45389
|
+
fs46.unlinkSync(path51.join(fallbackDir, f));
|
|
45112
45390
|
} catch {
|
|
45113
45391
|
}
|
|
45114
|
-
|
|
45392
|
+
fs46.rmdirSync(fallbackDir);
|
|
45115
45393
|
}
|
|
45116
45394
|
} catch {
|
|
45117
45395
|
}
|
|
@@ -45145,24 +45423,24 @@ async function startAgentWebTurn(options) {
|
|
|
45145
45423
|
})
|
|
45146
45424
|
]), timer && clearTimeout(timer);
|
|
45147
45425
|
try {
|
|
45148
|
-
|
|
45426
|
+
fs46.existsSync(socketPath) && fs46.unlinkSync(socketPath);
|
|
45149
45427
|
} catch {
|
|
45150
45428
|
}
|
|
45151
45429
|
if (fallbackDir)
|
|
45152
45430
|
try {
|
|
45153
|
-
if (
|
|
45154
|
-
let files =
|
|
45431
|
+
if (fs46.existsSync(fallbackDir)) {
|
|
45432
|
+
let files = fs46.readdirSync(fallbackDir);
|
|
45155
45433
|
for (let f of files)
|
|
45156
45434
|
try {
|
|
45157
|
-
|
|
45435
|
+
fs46.unlinkSync(path51.join(fallbackDir, f));
|
|
45158
45436
|
} catch {
|
|
45159
45437
|
}
|
|
45160
|
-
|
|
45438
|
+
fs46.rmdirSync(fallbackDir);
|
|
45161
45439
|
}
|
|
45162
45440
|
} catch {
|
|
45163
45441
|
}
|
|
45164
45442
|
try {
|
|
45165
|
-
|
|
45443
|
+
fs46.existsSync(mcpConfigPath) && fs46.unlinkSync(mcpConfigPath);
|
|
45166
45444
|
} catch {
|
|
45167
45445
|
}
|
|
45168
45446
|
}
|
|
@@ -45187,10 +45465,10 @@ function authorityExpired(scope) {
|
|
|
45187
45465
|
return new Date(scope.expiresAt) < /* @__PURE__ */ new Date();
|
|
45188
45466
|
}
|
|
45189
45467
|
async function enforceWrite(scope, p) {
|
|
45190
|
-
let canonical = await
|
|
45468
|
+
let canonical = await import_node_fs21.promises.realpath(p).catch((e) => {
|
|
45191
45469
|
if (e.code === "ENOENT") {
|
|
45192
45470
|
let parent = path52.dirname(p);
|
|
45193
|
-
return
|
|
45471
|
+
return import_node_fs21.promises.realpath(parent).then((realParent) => path52.join(realParent, path52.basename(p))).catch((parentErr) => {
|
|
45194
45472
|
throw new AuthorityError({
|
|
45195
45473
|
category: "authority_scope_conflict",
|
|
45196
45474
|
detail: `parent directory ${parent} for write target ${p} does not exist or is unresolvable: ${parentErr.message}`
|
|
@@ -45216,18 +45494,18 @@ async function enforceWrite(scope, p) {
|
|
|
45216
45494
|
}
|
|
45217
45495
|
async function safeWriteFile(scope, p, data, options) {
|
|
45218
45496
|
let canonical = await enforceWrite(scope, p);
|
|
45219
|
-
await
|
|
45497
|
+
await import_node_fs21.promises.writeFile(canonical, data, options);
|
|
45220
45498
|
}
|
|
45221
45499
|
async function enforceRead(scope, p) {
|
|
45222
45500
|
let canonical;
|
|
45223
45501
|
try {
|
|
45224
|
-
canonical = await
|
|
45502
|
+
canonical = await import_node_fs21.promises.realpath(p);
|
|
45225
45503
|
} catch (e) {
|
|
45226
45504
|
let err = e;
|
|
45227
45505
|
if (err.code === "ENOENT") {
|
|
45228
45506
|
let parent = path52.dirname(p), realParent;
|
|
45229
45507
|
try {
|
|
45230
|
-
realParent = await
|
|
45508
|
+
realParent = await import_node_fs21.promises.realpath(parent);
|
|
45231
45509
|
} catch (parentErr) {
|
|
45232
45510
|
let pe = parentErr;
|
|
45233
45511
|
throw new AuthorityError({
|
|
@@ -45264,7 +45542,7 @@ async function enforceRead(scope, p) {
|
|
|
45264
45542
|
}
|
|
45265
45543
|
async function safeReadFile(scope, p, options) {
|
|
45266
45544
|
let canonical = await enforceRead(scope, p);
|
|
45267
|
-
return
|
|
45545
|
+
return import_node_fs21.promises.readFile(canonical, options);
|
|
45268
45546
|
}
|
|
45269
45547
|
function mergeAuthorityScope(base2, incoming) {
|
|
45270
45548
|
let commandAllowlist = [
|
|
@@ -45732,7 +46010,7 @@ function enforceCommand(scope, argv) {
|
|
|
45732
46010
|
}
|
|
45733
46011
|
|
|
45734
46012
|
// src/local-executor/spawn.ts
|
|
45735
|
-
var
|
|
46013
|
+
var import_node_fs23 = require("node:fs");
|
|
45736
46014
|
init_bounded_output();
|
|
45737
46015
|
init_process_tree();
|
|
45738
46016
|
init_workspace_authority();
|
|
@@ -45740,7 +46018,7 @@ init_env_scrub();
|
|
|
45740
46018
|
init_logger2();
|
|
45741
46019
|
|
|
45742
46020
|
// src/local-executor/descendant-reaper.ts
|
|
45743
|
-
var import_node_child_process11 = require("node:child_process"),
|
|
46021
|
+
var import_node_child_process11 = require("node:child_process"), import_node_fs22 = require("node:fs"), PROCESS_TREE_MARKER_ENV = "CODEVIBE_PROCESS_TREE_ID", TREE_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
45744
46022
|
function processTreeMarkerToken(treeId) {
|
|
45745
46023
|
return `${PROCESS_TREE_MARKER_ENV}=${treeId}`;
|
|
45746
46024
|
}
|
|
@@ -45846,15 +46124,15 @@ async function listInWorkingDirDarwin(scope) {
|
|
|
45846
46124
|
async function listMarkedLinux(token4) {
|
|
45847
46125
|
let uid = process.getuid?.() ?? -1, marked = [], entries;
|
|
45848
46126
|
try {
|
|
45849
|
-
entries = await
|
|
46127
|
+
entries = await import_node_fs22.promises.readdir("/proc");
|
|
45850
46128
|
} catch {
|
|
45851
46129
|
return marked;
|
|
45852
46130
|
}
|
|
45853
46131
|
for (let entry5 of entries)
|
|
45854
46132
|
if (/^\d+$/.test(entry5))
|
|
45855
46133
|
try {
|
|
45856
|
-
if ((await
|
|
45857
|
-
let procStat = await
|
|
46134
|
+
if ((await import_node_fs22.promises.stat(`/proc/${entry5}`)).uid !== uid || !(await import_node_fs22.promises.readFile(`/proc/${entry5}/environ`, "utf8")).split("\0").includes(token4)) continue;
|
|
46135
|
+
let procStat = await import_node_fs22.promises.readFile(`/proc/${entry5}/stat`, "utf8"), fields = procStat.slice(procStat.lastIndexOf(")") + 2).split(" ");
|
|
45858
46136
|
marked.push({ pid: Number(entry5), startedAt: fields[19] ?? "" });
|
|
45859
46137
|
} catch {
|
|
45860
46138
|
}
|
|
@@ -45936,7 +46214,7 @@ async function spawnSubprocess(scope, args) {
|
|
|
45936
46214
|
if (args.argv.length === 0)
|
|
45937
46215
|
throw new SpawnArgsInvalid("argv must not be empty", "argv");
|
|
45938
46216
|
enforceCommand(scope, args.argv), ROLES_REQUIRING_NETWORK.has(args.role) && enforceNetwork(scope);
|
|
45939
|
-
let realWorkingDir = await
|
|
46217
|
+
let realWorkingDir = await import_node_fs23.promises.realpath(args.workingDir);
|
|
45940
46218
|
if (realWorkingDir !== args.workingDir)
|
|
45941
46219
|
throw new SpawnArgsInvalid(
|
|
45942
46220
|
`workingDir must be canonicalized before passing in: got ${args.workingDir}, realpath = ${realWorkingDir}`,
|
|
@@ -46191,7 +46469,7 @@ function wireLifecycle(internal, args) {
|
|
|
46191
46469
|
}
|
|
46192
46470
|
|
|
46193
46471
|
// src/local-executor/implementor-argv.ts
|
|
46194
|
-
var
|
|
46472
|
+
var import_node_fs24 = require("node:fs"), import_node_os = __toESM(require("node:os")), import_node_path3 = __toESM(require("node:path")), import_uuid11 = require("uuid");
|
|
46195
46473
|
function buildClaudeNoToolsPlanArgv(options) {
|
|
46196
46474
|
let model = options?.model ? assertValidModelIdentifier(options.model, "claude model") : null;
|
|
46197
46475
|
return {
|
|
@@ -46226,7 +46504,7 @@ function buildClaudeReadOnlyAdvisoryPlanArgv(workdir, attachments, options) {
|
|
|
46226
46504
|
addDirs.push(resolvedWorkdir);
|
|
46227
46505
|
let realWorkdir = null;
|
|
46228
46506
|
try {
|
|
46229
|
-
realWorkdir = (0,
|
|
46507
|
+
realWorkdir = (0, import_node_fs24.realpathSync)(resolvedWorkdir);
|
|
46230
46508
|
} catch {
|
|
46231
46509
|
}
|
|
46232
46510
|
let targetPatterns = /* @__PURE__ */ new Set(), escapedWorkdir = escapeClaudePathGlob(resolvedWorkdir);
|
|
@@ -46238,13 +46516,13 @@ function buildClaudeReadOnlyAdvisoryPlanArgv(workdir, attachments, options) {
|
|
|
46238
46516
|
for (let att of attachments) {
|
|
46239
46517
|
let resolvedAtt = import_node_path3.default.resolve(att), stat25 = null;
|
|
46240
46518
|
try {
|
|
46241
|
-
stat25 = (0,
|
|
46519
|
+
stat25 = (0, import_node_fs24.statSync)(resolvedAtt);
|
|
46242
46520
|
} catch {
|
|
46243
46521
|
}
|
|
46244
46522
|
let isDir = !!stat25?.isDirectory(), escapedAtt = escapeClaudePathGlob(resolvedAtt);
|
|
46245
46523
|
isDir ? (targetPatterns.add(formatClaudePermissionPath(`${escapedAtt}/**`)), addDirs.push(resolvedAtt)) : targetPatterns.add(formatClaudePermissionPath(escapedAtt));
|
|
46246
46524
|
try {
|
|
46247
|
-
let realAtt = (0,
|
|
46525
|
+
let realAtt = (0, import_node_fs24.realpathSync)(resolvedAtt);
|
|
46248
46526
|
if (realAtt !== resolvedAtt) {
|
|
46249
46527
|
let escapedRealAtt = escapeClaudePathGlob(realAtt);
|
|
46250
46528
|
isDir ? targetPatterns.add(formatClaudePermissionPath(`${escapedRealAtt}/**`)) : targetPatterns.add(formatClaudePermissionPath(escapedRealAtt));
|
|
@@ -46351,8 +46629,8 @@ function extractMcpServerConfig(mcpConfigPath) {
|
|
|
46351
46629
|
if (!mcpConfigPath)
|
|
46352
46630
|
return null;
|
|
46353
46631
|
try {
|
|
46354
|
-
if ((0,
|
|
46355
|
-
let raw = JSON.parse((0,
|
|
46632
|
+
if ((0, import_node_fs24.existsSync)(mcpConfigPath)) {
|
|
46633
|
+
let raw = JSON.parse((0, import_node_fs24.readFileSync)(mcpConfigPath, "utf8")), server = raw.mcpServers?.["codevibe-web"] || raw.mcpServers?.codevibe_web;
|
|
46356
46634
|
if (server && typeof server.command == "string" && server.command === "node" && Array.isArray(server.args) && server.args.length === 5 && typeof server.args[0] == "string" && server.args[1] === "--socket" && typeof server.args[2] == "string" && server.args[3] === "--token" && typeof server.args[4] == "string")
|
|
46357
46635
|
return { command: server.command, args: server.args };
|
|
46358
46636
|
}
|
|
@@ -46363,13 +46641,13 @@ function extractMcpServerConfig(mcpConfigPath) {
|
|
|
46363
46641
|
function setupAgyWebPlugin(workdir, server) {
|
|
46364
46642
|
try {
|
|
46365
46643
|
let pluginDir = import_node_path3.default.join(workdir, ".agents", "plugins", "codevibe-web");
|
|
46366
|
-
(0,
|
|
46644
|
+
(0, import_node_fs24.mkdirSync)(pluginDir, { recursive: !0, mode: 448 });
|
|
46367
46645
|
let pluginJsonPath = import_node_path3.default.join(pluginDir, "plugin.json");
|
|
46368
|
-
(0,
|
|
46646
|
+
(0, import_node_fs24.writeFileSync)(pluginJsonPath, JSON.stringify({ name: "codevibe-web" }, null, 2), {
|
|
46369
46647
|
mode: 384
|
|
46370
46648
|
});
|
|
46371
46649
|
let mcpConfigPath = import_node_path3.default.join(pluginDir, "mcp_config.json");
|
|
46372
|
-
(0,
|
|
46650
|
+
(0, import_node_fs24.writeFileSync)(
|
|
46373
46651
|
mcpConfigPath,
|
|
46374
46652
|
JSON.stringify(
|
|
46375
46653
|
{
|
|
@@ -46391,11 +46669,11 @@ function setupAgyWebPlugin(workdir, server) {
|
|
|
46391
46669
|
function stripAgyWebPlugin(workdir) {
|
|
46392
46670
|
try {
|
|
46393
46671
|
let pluginDir = import_node_path3.default.join(workdir, ".agents", "plugins", "codevibe-web");
|
|
46394
|
-
(0,
|
|
46672
|
+
(0, import_node_fs24.existsSync)(pluginDir) && (0, import_node_fs24.rmSync)(pluginDir, { recursive: !0, force: !0 });
|
|
46395
46673
|
let pluginsParent = import_node_path3.default.join(workdir, ".agents", "plugins");
|
|
46396
|
-
(0,
|
|
46674
|
+
(0, import_node_fs24.existsSync)(pluginsParent) && (0, import_node_fs24.readdirSync)(pluginsParent).length === 0 && (0, import_node_fs24.rmdirSync)(pluginsParent);
|
|
46397
46675
|
let agentsParent = import_node_path3.default.join(workdir, ".agents");
|
|
46398
|
-
(0,
|
|
46676
|
+
(0, import_node_fs24.existsSync)(agentsParent) && (0, import_node_fs24.readdirSync)(agentsParent).length === 0 && (0, import_node_fs24.rmdirSync)(agentsParent);
|
|
46399
46677
|
} catch {
|
|
46400
46678
|
}
|
|
46401
46679
|
}
|
|
@@ -46518,11 +46796,11 @@ function readImplementorLastMessage(capturePath, workdir, captureHostPath) {
|
|
|
46518
46796
|
} finally {
|
|
46519
46797
|
if (captureHostPath !== void 0) {
|
|
46520
46798
|
try {
|
|
46521
|
-
(0,
|
|
46799
|
+
(0, import_node_fs24.unlinkSync)(captureHostPath);
|
|
46522
46800
|
} catch {
|
|
46523
46801
|
}
|
|
46524
46802
|
try {
|
|
46525
|
-
(0,
|
|
46803
|
+
(0, import_node_fs24.rmdirSync)(import_node_path3.default.dirname(captureHostPath));
|
|
46526
46804
|
} catch {
|
|
46527
46805
|
}
|
|
46528
46806
|
}
|
|
@@ -46532,12 +46810,12 @@ function readFirstCandidate(candidates) {
|
|
|
46532
46810
|
for (let candidate of candidates) {
|
|
46533
46811
|
let text2;
|
|
46534
46812
|
try {
|
|
46535
|
-
text2 = (0,
|
|
46813
|
+
text2 = (0, import_node_fs24.readFileSync)(candidate, "utf8");
|
|
46536
46814
|
} catch {
|
|
46537
46815
|
continue;
|
|
46538
46816
|
}
|
|
46539
46817
|
try {
|
|
46540
|
-
(0,
|
|
46818
|
+
(0, import_node_fs24.unlinkSync)(candidate);
|
|
46541
46819
|
} catch {
|
|
46542
46820
|
}
|
|
46543
46821
|
return text2;
|
|
@@ -46546,12 +46824,12 @@ function readFirstCandidate(candidates) {
|
|
|
46546
46824
|
}
|
|
46547
46825
|
function isInsideContainer() {
|
|
46548
46826
|
try {
|
|
46549
|
-
if ((0,
|
|
46827
|
+
if ((0, import_node_fs24.existsSync)("/.dockerenv") || (0, import_node_fs24.existsSync)("/run/.containerenv"))
|
|
46550
46828
|
return !0;
|
|
46551
46829
|
} catch {
|
|
46552
46830
|
}
|
|
46553
46831
|
try {
|
|
46554
|
-
let cgroup = (0,
|
|
46832
|
+
let cgroup = (0, import_node_fs24.readFileSync)("/proc/1/cgroup", "utf8");
|
|
46555
46833
|
if (/\b(?:docker|containerd|kubepods|lxc|podman)\b/i.test(cgroup))
|
|
46556
46834
|
return !0;
|
|
46557
46835
|
} catch {
|
|
@@ -46914,15 +47192,15 @@ var HookBridge = class {
|
|
|
46914
47192
|
};
|
|
46915
47193
|
|
|
46916
47194
|
// src/local-executor/local-executor-impl.ts
|
|
46917
|
-
var import_node_crypto51 = require("node:crypto"),
|
|
47195
|
+
var import_node_crypto51 = require("node:crypto"), import_node_fs42 = require("node:fs"), syncFs = __toESM(require("node:fs")), os44 = __toESM(require("node:os")), path90 = __toESM(require("node:path"));
|
|
46918
47196
|
|
|
46919
47197
|
// src/substrate/docker.ts
|
|
46920
|
-
var
|
|
47198
|
+
var import_node_fs26 = require("node:fs"), os33 = __toESM(require("node:os")), path55 = __toESM(require("node:path"));
|
|
46921
47199
|
init_command_runner();
|
|
46922
47200
|
init_errors();
|
|
46923
47201
|
|
|
46924
47202
|
// src/substrate/forwarder.ts
|
|
46925
|
-
var
|
|
47203
|
+
var import_node_fs25 = require("node:fs"), net4 = __toESM(require("node:net"));
|
|
46926
47204
|
|
|
46927
47205
|
// src/substrate/types.ts
|
|
46928
47206
|
var NOOP_EGRESS_HOOK = () => {
|
|
@@ -46941,7 +47219,7 @@ function splitHostPort(addr) {
|
|
|
46941
47219
|
var denialCounter = 0, HostEgressForwarder = class {
|
|
46942
47220
|
constructor(spec) {
|
|
46943
47221
|
this.listening = !1;
|
|
46944
|
-
this.taskId = spec.taskId, this.upstream = splitHostPort(spec.hostBrokerAddr), this.onEgressDenied = spec.onEgressDenied ?? NOOP_EGRESS_HOOK, this.udsPath = spec.udsPath, this.server =
|
|
47222
|
+
this.taskId = spec.taskId, this.upstream = splitHostPort(spec.hostBrokerAddr), this.onEgressDenied = spec.onEgressDenied ?? NOOP_EGRESS_HOOK, this.udsPath = spec.udsPath, this.server = net4.createServer((client) => this.onConnection(client)), this.server.on("error", () => {
|
|
46945
47223
|
});
|
|
46946
47224
|
}
|
|
46947
47225
|
/**
|
|
@@ -46950,7 +47228,7 @@ var denialCounter = 0, HostEgressForwarder = class {
|
|
|
46950
47228
|
* Resolves with the UDS path the container dials.
|
|
46951
47229
|
*/
|
|
46952
47230
|
async start() {
|
|
46953
|
-
return await
|
|
47231
|
+
return await import_node_fs25.promises.rm(this.udsPath, { force: !0 }).catch(() => {
|
|
46954
47232
|
}), new Promise((resolve35, reject) => {
|
|
46955
47233
|
let onError = (err) => {
|
|
46956
47234
|
this.server.removeListener("error", onError), reject(err);
|
|
@@ -46970,20 +47248,20 @@ var denialCounter = 0, HostEgressForwarder = class {
|
|
|
46970
47248
|
*/
|
|
46971
47249
|
async stop() {
|
|
46972
47250
|
if (!this.listening) {
|
|
46973
|
-
await
|
|
47251
|
+
await import_node_fs25.promises.rm(this.udsPath, { force: !0 }).catch(() => {
|
|
46974
47252
|
});
|
|
46975
47253
|
return;
|
|
46976
47254
|
}
|
|
46977
47255
|
this.listening = !1, await new Promise((resolve35) => {
|
|
46978
47256
|
this.server.close(() => resolve35());
|
|
46979
|
-
}), await
|
|
47257
|
+
}), await import_node_fs25.promises.rm(this.udsPath, { force: !0 }).catch(() => {
|
|
46980
47258
|
});
|
|
46981
47259
|
}
|
|
46982
47260
|
// Relay one inbound (from the in-container relay) connection to the FIXED
|
|
46983
47261
|
// broker upstream. The agent-supplied target is never read — the upstream is
|
|
46984
47262
|
// hard-wired to `hostBrokerAddr`.
|
|
46985
47263
|
onConnection(client) {
|
|
46986
|
-
let upstream =
|
|
47264
|
+
let upstream = net4.connect(
|
|
46987
47265
|
{ host: this.upstream.host, port: this.upstream.port },
|
|
46988
47266
|
() => {
|
|
46989
47267
|
client.pipe(upstream), upstream.pipe(client);
|
|
@@ -47140,7 +47418,7 @@ var DockerHandle = class {
|
|
|
47140
47418
|
}), await this.runner.run(buildRmArgv(this.id)).catch(() => {
|
|
47141
47419
|
}), await this.forwarder.stop().catch(() => {
|
|
47142
47420
|
}), await this.workdirLease?.release().catch(() => {
|
|
47143
|
-
}), await
|
|
47421
|
+
}), await import_node_fs26.promises.rm(this.sessionDir, { recursive: !0, force: !0 }).catch(() => {
|
|
47144
47422
|
}));
|
|
47145
47423
|
}
|
|
47146
47424
|
}, DockerSubstrate = class {
|
|
@@ -47157,7 +47435,7 @@ var DockerHandle = class {
|
|
|
47157
47435
|
), workdirLease = await this.acquireWorkdirLease(spec.workdirAuthority));
|
|
47158
47436
|
let mountedWorkdir = workdirLease?.procfsPath ?? spec.workdir, sessionDir = path55.join(this.sessionRoot, `codevibe-substrate-${id5}`), udsDir = path55.join(sessionDir, "uds");
|
|
47159
47437
|
try {
|
|
47160
|
-
await
|
|
47438
|
+
await import_node_fs26.promises.mkdir(sessionDir, { recursive: !0, mode: 448 }), await import_node_fs26.promises.mkdir(udsDir, { recursive: !0, mode: 448 });
|
|
47161
47439
|
} catch (e) {
|
|
47162
47440
|
throw await this.rollback(sessionDir, null, workdirLease), new SubstrateLaunchError(
|
|
47163
47441
|
"docker",
|
|
@@ -47167,7 +47445,7 @@ var DockerHandle = class {
|
|
|
47167
47445
|
}
|
|
47168
47446
|
let udsPath = path55.join(udsDir, BROKER_SOCK_NAME), relayScriptPath = path55.join(sessionDir, "relay.js");
|
|
47169
47447
|
try {
|
|
47170
|
-
await
|
|
47448
|
+
await import_node_fs26.promises.writeFile(relayScriptPath, IN_CONTAINER_RELAY_SOURCE, {
|
|
47171
47449
|
encoding: "utf8",
|
|
47172
47450
|
mode: 384
|
|
47173
47451
|
});
|
|
@@ -47249,7 +47527,7 @@ var DockerHandle = class {
|
|
|
47249
47527
|
async rollback(sessionDir, forwarder, workdirLease = null) {
|
|
47250
47528
|
forwarder && await forwarder.stop().catch(() => {
|
|
47251
47529
|
}), await workdirLease?.release().catch(() => {
|
|
47252
|
-
}), await
|
|
47530
|
+
}), await import_node_fs26.promises.rm(sessionDir, { recursive: !0, force: !0 }).catch(() => {
|
|
47253
47531
|
});
|
|
47254
47532
|
}
|
|
47255
47533
|
// §6 Q2 — probe the Docker CLI/daemon. `docker version` exits non-zero (or
|
|
@@ -47279,13 +47557,13 @@ function randomId() {
|
|
|
47279
47557
|
}
|
|
47280
47558
|
|
|
47281
47559
|
// src/local-executor/class-a-emit.ts
|
|
47282
|
-
var
|
|
47560
|
+
var import_node_fs27 = require("node:fs"), import_ulid3 = require("ulid");
|
|
47283
47561
|
var LocalStubSink = class {
|
|
47284
47562
|
constructor(logPath) {
|
|
47285
47563
|
this.logPath = logPath;
|
|
47286
47564
|
}
|
|
47287
47565
|
async emit(envelope) {
|
|
47288
|
-
await
|
|
47566
|
+
await import_node_fs27.promises.appendFile(this.logPath, JSON.stringify(envelope) + `
|
|
47289
47567
|
`, { encoding: "utf8" });
|
|
47290
47568
|
}
|
|
47291
47569
|
}, DEFAULT_DEDUPE_CAP = 1e4;
|
|
@@ -48074,7 +48352,7 @@ var ClassBConsumer = class {
|
|
|
48074
48352
|
};
|
|
48075
48353
|
|
|
48076
48354
|
// src/substrate-launch/apikey-bootstrap.ts
|
|
48077
|
-
var
|
|
48355
|
+
var import_node_fs28 = require("node:fs"), os34 = __toESM(require("node:os")), path56 = __toESM(require("node:path"));
|
|
48078
48356
|
init_anchored_fs();
|
|
48079
48357
|
var HELPER_SCRIPT_NAME = "broker-apikey-helper.sh", TOKEN_FILE_NAME = "broker-token", CLAUDE_SETTINGS_NAME = "settings.json", CODEX_CONFIG_NAME = "config.toml", SANDBOX_BOOTSTRAP_DIR = "/codevibe/agent", SANDBOX_AGENT_CONFIG_DIR = "/codevibe/agent-config", CODEX_PROVIDER_ID = "codevibe_broker";
|
|
48080
48358
|
function helperScriptSource(tokenFileAbsPathInSandbox) {
|
|
@@ -48146,64 +48424,64 @@ var ApiKeyBootstrap = class _ApiKeyBootstrap {
|
|
|
48146
48424
|
* the live {@link ApiKeyBootstrap}.
|
|
48147
48425
|
*/
|
|
48148
48426
|
static async create(input) {
|
|
48149
|
-
let hostRoot = input.hostRoot ?? os34.tmpdir(), rawHostDir = await
|
|
48150
|
-
await
|
|
48427
|
+
let hostRoot = input.hostRoot ?? os34.tmpdir(), rawHostDir = await import_node_fs28.promises.mkdtemp(path56.join(hostRoot, "codevibe-agent-"));
|
|
48428
|
+
await import_node_fs28.promises.chmod(rawHostDir, 448).catch(() => {
|
|
48151
48429
|
});
|
|
48152
|
-
let rawConfigHostDir = await
|
|
48430
|
+
let rawConfigHostDir = await import_node_fs28.promises.mkdtemp(
|
|
48153
48431
|
path56.join(hostRoot, "codevibe-agent-config-")
|
|
48154
48432
|
);
|
|
48155
|
-
await
|
|
48433
|
+
await import_node_fs28.promises.chmod(rawConfigHostDir, 448).catch(() => {
|
|
48156
48434
|
});
|
|
48157
|
-
let hostDir = await
|
|
48435
|
+
let hostDir = await import_node_fs28.promises.realpath(rawHostDir), configHostDir = await import_node_fs28.promises.realpath(rawConfigHostDir), realWorkdir;
|
|
48158
48436
|
if (input.workdir !== void 0) {
|
|
48159
48437
|
try {
|
|
48160
|
-
realWorkdir = await
|
|
48438
|
+
realWorkdir = await import_node_fs28.promises.realpath(input.workdir);
|
|
48161
48439
|
} catch {
|
|
48162
|
-
throw await
|
|
48163
|
-
}), await
|
|
48440
|
+
throw await import_node_fs28.promises.rm(hostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48441
|
+
}), await import_node_fs28.promises.rm(configHostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48164
48442
|
}), new Error(
|
|
48165
48443
|
`ApiKeyBootstrap.create: cannot realpath workdir "${input.workdir}" (fail-closed)`
|
|
48166
48444
|
);
|
|
48167
48445
|
}
|
|
48168
48446
|
if (isInsideOrEqual(hostDir, realWorkdir))
|
|
48169
|
-
throw await
|
|
48170
|
-
}), await
|
|
48447
|
+
throw await import_node_fs28.promises.rm(hostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48448
|
+
}), await import_node_fs28.promises.rm(configHostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48171
48449
|
}), new Error(
|
|
48172
48450
|
`ApiKeyBootstrap.create: bootstrap dir "${hostDir}" is inside the agent workdir "${realWorkdir}" \u2014 the broker token would be reachable through the workdir mount (I1 fail-closed). Use a hostRoot outside the workdir.`
|
|
48173
48451
|
);
|
|
48174
48452
|
if (isInsideOrEqual(configHostDir, realWorkdir))
|
|
48175
|
-
throw await
|
|
48176
|
-
}), await
|
|
48453
|
+
throw await import_node_fs28.promises.rm(hostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48454
|
+
}), await import_node_fs28.promises.rm(configHostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48177
48455
|
}), new Error(
|
|
48178
48456
|
`ApiKeyBootstrap.create: config dir "${configHostDir}" is inside the agent workdir "${realWorkdir}" \u2014 CLI runtime state would be reachable through the workdir mount (I1 fail-closed). Use a hostRoot outside the workdir.`
|
|
48179
48457
|
);
|
|
48180
48458
|
}
|
|
48181
48459
|
let sandboxDir = input.sandboxDirEqualsHostDir ? hostDir : input.sandboxDir, sandboxConfigDir = input.configDirEqualsHostDir ?? input.sandboxDirEqualsHostDir ?? !1 ? configHostDir : input.sandboxConfigDir;
|
|
48182
48460
|
if (!sandboxDir)
|
|
48183
|
-
throw await
|
|
48184
|
-
}), await
|
|
48461
|
+
throw await import_node_fs28.promises.rm(hostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48462
|
+
}), await import_node_fs28.promises.rm(configHostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48185
48463
|
}), new Error(
|
|
48186
48464
|
"ApiKeyBootstrap.create: provide `sandboxDir` or `sandboxDirEqualsHostDir`"
|
|
48187
48465
|
);
|
|
48188
48466
|
if (!sandboxConfigDir)
|
|
48189
|
-
throw await
|
|
48190
|
-
}), await
|
|
48467
|
+
throw await import_node_fs28.promises.rm(hostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48468
|
+
}), await import_node_fs28.promises.rm(configHostDir, { recursive: !0, force: !0 }).catch(() => {
|
|
48191
48469
|
}), new Error(
|
|
48192
48470
|
"ApiKeyBootstrap.create: provide `sandboxConfigDir` or `configDirEqualsHostDir`"
|
|
48193
48471
|
);
|
|
48194
48472
|
let tokenInSandbox = path56.posix.join(sandboxDir, TOKEN_FILE_NAME), helperInSandbox = path56.posix.join(sandboxDir, HELPER_SCRIPT_NAME), tokenFileHostPath = path56.join(hostDir, TOKEN_FILE_NAME);
|
|
48195
|
-
await
|
|
48473
|
+
await import_node_fs28.promises.writeFile(tokenFileHostPath, input.initialToken, {
|
|
48196
48474
|
encoding: "utf8",
|
|
48197
48475
|
mode: 384
|
|
48198
|
-
}), await
|
|
48476
|
+
}), await import_node_fs28.promises.writeFile(
|
|
48199
48477
|
path56.join(hostDir, HELPER_SCRIPT_NAME),
|
|
48200
48478
|
helperScriptSource(tokenInSandbox),
|
|
48201
48479
|
{ encoding: "utf8", mode: 448 }
|
|
48202
|
-
), input.provider === "anthropic" ? await
|
|
48480
|
+
), input.provider === "anthropic" ? await import_node_fs28.promises.writeFile(
|
|
48203
48481
|
path56.join(configHostDir, CLAUDE_SETTINGS_NAME),
|
|
48204
48482
|
claudeSettings(helperInSandbox, input.claudeModelSettings),
|
|
48205
48483
|
{ encoding: "utf8", mode: 384 }
|
|
48206
|
-
) : await
|
|
48484
|
+
) : await import_node_fs28.promises.writeFile(
|
|
48207
48485
|
path56.join(configHostDir, CODEX_CONFIG_NAME),
|
|
48208
48486
|
codexConfig(input.sandboxBrokerUrl, helperInSandbox, input.codexModelConfig),
|
|
48209
48487
|
{ encoding: "utf8", mode: 384 }
|
|
@@ -48216,7 +48494,7 @@ var ApiKeyBootstrap = class _ApiKeyBootstrap {
|
|
|
48216
48494
|
), cleanupErrors = [];
|
|
48217
48495
|
for (let directory of [hostDir, configHostDir])
|
|
48218
48496
|
try {
|
|
48219
|
-
await
|
|
48497
|
+
await import_node_fs28.promises.rm(directory, { recursive: !0, force: !0 });
|
|
48220
48498
|
} catch (cleanupError) {
|
|
48221
48499
|
cleanupErrors.push(cleanupError);
|
|
48222
48500
|
}
|
|
@@ -48229,19 +48507,19 @@ var ApiKeyBootstrap = class _ApiKeyBootstrap {
|
|
|
48229
48507
|
}
|
|
48230
48508
|
let rawScratchDir = null;
|
|
48231
48509
|
try {
|
|
48232
|
-
let canonicalScratchRoot = await
|
|
48510
|
+
let canonicalScratchRoot = await import_node_fs28.promises.realpath(
|
|
48233
48511
|
input.claudeScratchHostRoot
|
|
48234
48512
|
);
|
|
48235
|
-
rawScratchDir = await
|
|
48236
|
-
let initial = await
|
|
48513
|
+
rawScratchDir = await import_node_fs28.promises.mkdtemp(path56.join(canonicalScratchRoot, "cv"));
|
|
48514
|
+
let initial = await import_node_fs28.promises.lstat(rawScratchDir, { bigint: !0 });
|
|
48237
48515
|
if (!initial.isDirectory() || initial.isSymbolicLink())
|
|
48238
48516
|
throw new Error(
|
|
48239
48517
|
"ApiKeyBootstrap.create: generated Claude scratch root is not a real directory"
|
|
48240
48518
|
);
|
|
48241
48519
|
await input.beforeClaudeScratchOpen?.(rawScratchDir);
|
|
48242
|
-
let scratchHandle = await
|
|
48520
|
+
let scratchHandle = await import_node_fs28.promises.open(
|
|
48243
48521
|
rawScratchDir,
|
|
48244
|
-
|
|
48522
|
+
import_node_fs28.constants.O_RDONLY | import_node_fs28.constants.O_NOFOLLOW | (typeof import_node_fs28.constants.O_DIRECTORY == "number" ? import_node_fs28.constants.O_DIRECTORY : 0)
|
|
48245
48523
|
);
|
|
48246
48524
|
try {
|
|
48247
48525
|
let opened = await scratchHandle.stat({ bigint: !0 });
|
|
@@ -48250,7 +48528,7 @@ var ApiKeyBootstrap = class _ApiKeyBootstrap {
|
|
|
48250
48528
|
"ApiKeyBootstrap.create: Claude scratch root changed while binding its directory handle"
|
|
48251
48529
|
);
|
|
48252
48530
|
await scratchHandle.chmod(448);
|
|
48253
|
-
let sealed = await scratchHandle.stat({ bigint: !0 }), live = await
|
|
48531
|
+
let sealed = await scratchHandle.stat({ bigint: !0 }), live = await import_node_fs28.promises.lstat(rawScratchDir, { bigint: !0 }), canonical = rawScratchDir, currentUid = process.getuid?.(), mode = sealed.mode & 0o777n;
|
|
48254
48532
|
if (!sealed.isDirectory() || !live.isDirectory() || live.isSymbolicLink() || live.dev !== sealed.dev || live.ino !== sealed.ino || live.birthtimeNs !== sealed.birthtimeNs || currentUid === void 0 || sealed.uid !== BigInt(currentUid) || mode !== 0o700n)
|
|
48255
48533
|
throw new Error(
|
|
48256
48534
|
"ApiKeyBootstrap.create: generated Claude scratch root failed its descriptor-bound private-directory identity check"
|
|
@@ -48286,7 +48564,7 @@ var ApiKeyBootstrap = class _ApiKeyBootstrap {
|
|
|
48286
48564
|
}
|
|
48287
48565
|
for (let directory of [hostDir, configHostDir])
|
|
48288
48566
|
try {
|
|
48289
|
-
await
|
|
48567
|
+
await import_node_fs28.promises.rm(directory, { recursive: !0, force: !0 });
|
|
48290
48568
|
} catch (cleanupError) {
|
|
48291
48569
|
cleanupErrors.push(cleanupError);
|
|
48292
48570
|
}
|
|
@@ -48334,7 +48612,7 @@ var ApiKeyBootstrap = class _ApiKeyBootstrap {
|
|
|
48334
48612
|
*/
|
|
48335
48613
|
async refresh(token4) {
|
|
48336
48614
|
let tmp = `${this.tokenFileHostPath}.tmp-${process.pid}-${Date.now()}`;
|
|
48337
|
-
await
|
|
48615
|
+
await import_node_fs28.promises.writeFile(tmp, token4, { encoding: "utf8", mode: 384 }), await import_node_fs28.promises.rename(tmp, this.tokenFileHostPath);
|
|
48338
48616
|
}
|
|
48339
48617
|
/**
|
|
48340
48618
|
* Remove the bootstrap, config, and unique Claude scratch dirs. Scratch
|
|
@@ -48361,7 +48639,7 @@ var ApiKeyBootstrap = class _ApiKeyBootstrap {
|
|
|
48361
48639
|
}
|
|
48362
48640
|
for (let directory of [this.hostDir, this.configHostDir])
|
|
48363
48641
|
try {
|
|
48364
|
-
await
|
|
48642
|
+
await import_node_fs28.promises.rm(directory, { recursive: !0, force: !0 });
|
|
48365
48643
|
} catch (error) {
|
|
48366
48644
|
cleanupErrors.push(error);
|
|
48367
48645
|
}
|
|
@@ -48375,7 +48653,7 @@ var ApiKeyBootstrap = class _ApiKeyBootstrap {
|
|
|
48375
48653
|
};
|
|
48376
48654
|
|
|
48377
48655
|
// src/local-executor/snapshot-merge.ts
|
|
48378
|
-
var crypto23 = __toESM(require("node:crypto")),
|
|
48656
|
+
var crypto23 = __toESM(require("node:crypto")), fs68 = __toESM(require("node:fs/promises")), path82 = __toESM(require("node:path"));
|
|
48379
48657
|
init_logger2();
|
|
48380
48658
|
|
|
48381
48659
|
// src/orchestration-shell/declared-test-runner.ts
|
|
@@ -49066,7 +49344,7 @@ init_anchored_fs();
|
|
|
49066
49344
|
init_bounded_directory();
|
|
49067
49345
|
|
|
49068
49346
|
// src/local-executor/workspace-shadow.ts
|
|
49069
|
-
var crypto22 = __toESM(require("node:crypto")), fsSync8 = __toESM(require("node:fs")),
|
|
49347
|
+
var crypto22 = __toESM(require("node:crypto")), fsSync8 = __toESM(require("node:fs")), fs66 = __toESM(require("node:fs/promises")), os38 = __toESM(require("node:os")), path77 = __toESM(require("node:path")), import_uuid12 = require("uuid");
|
|
49070
49348
|
init_logger2();
|
|
49071
49349
|
init_anchored_fs();
|
|
49072
49350
|
init_process_tree();
|
|
@@ -50044,7 +50322,7 @@ init_bounded_helper();
|
|
|
50044
50322
|
init_shadow_protocol();
|
|
50045
50323
|
|
|
50046
50324
|
// src/local-executor/shadow-roots.ts
|
|
50047
|
-
var import_node_crypto37 = require("node:crypto"),
|
|
50325
|
+
var import_node_crypto37 = require("node:crypto"), import_node_fs29 = require("node:fs"), fs52 = __toESM(require("node:fs/promises")), os35 = __toESM(require("node:os")), path60 = __toESM(require("node:path"));
|
|
50048
50326
|
init_shadow_fs_margins();
|
|
50049
50327
|
init_shadow_protocol();
|
|
50050
50328
|
var SHADOW_STATE_FORMAT_FILE = "FORMAT", SHADOW_STATE_FORMAT_VERSION = 2, SHADOW_STATE_FORMAT_BODY = `${JSON.stringify({ format: "codevibe-shadow-state", version: SHADOW_STATE_FORMAT_VERSION })}
|
|
@@ -50062,7 +50340,7 @@ async function nearestExistingAncestor(candidate) {
|
|
|
50062
50340
|
let current = path60.resolve(candidate);
|
|
50063
50341
|
for (; ; ) {
|
|
50064
50342
|
try {
|
|
50065
|
-
return await
|
|
50343
|
+
return await fs52.stat(current), current;
|
|
50066
50344
|
} catch (err) {
|
|
50067
50345
|
if (err.code !== "ENOENT") throw err;
|
|
50068
50346
|
}
|
|
@@ -50102,19 +50380,19 @@ async function mountPointOf(p, devOf = realDevOf) {
|
|
|
50102
50380
|
}
|
|
50103
50381
|
}
|
|
50104
50382
|
async function realDevOf(p) {
|
|
50105
|
-
return (await
|
|
50383
|
+
return (await fs52.stat(p)).dev;
|
|
50106
50384
|
}
|
|
50107
50385
|
function projectVolumeCopyRoot(volumeRoot, uid) {
|
|
50108
50386
|
return path60.join(volumeRoot, `.codevibe-shadows-${uid}`);
|
|
50109
50387
|
}
|
|
50110
50388
|
async function chooseCopyLocation(workingDir, probe = {}) {
|
|
50111
|
-
let platform2 = probe.platform ?? process.platform, statfsType = probe.statfsType ?? (async (p) => Number((await
|
|
50389
|
+
let platform2 = probe.platform ?? process.platform, statfsType = probe.statfsType ?? (async (p) => Number((await fs52.statfs(p)).type)), devOf = probe.devOf ?? realDevOf, homeLocation = await defaultCopyLocation(probe);
|
|
50112
50390
|
if (platform2 === "darwin") {
|
|
50113
50391
|
let home = probe.home ?? shadowHomeDir();
|
|
50114
50392
|
if (await devOf(workingDir) === await devOf(home)) return { copyRoot: homeLocation, basis: "home-volume" };
|
|
50115
50393
|
if (await statfsType(workingDir) !== DARWIN_APFS_FS_TYPE)
|
|
50116
50394
|
return { copyRoot: homeLocation, basis: "no-clone-volume" };
|
|
50117
|
-
let mountPoint = await mountPointOf(workingDir, devOf), real = (p) =>
|
|
50395
|
+
let mountPoint = await mountPointOf(workingDir, devOf), real = (p) => fs52.realpath(p).catch(() => path60.resolve(p)), volumesDir = await real(probe.volumesDir ?? "/Volumes");
|
|
50118
50396
|
return await real(path60.dirname(path60.resolve(mountPoint))) !== volumesDir ? { copyRoot: homeLocation, basis: "no-clone-volume" } : {
|
|
50119
50397
|
copyRoot: projectVolumeCopyRoot(mountPoint, probe.uid ?? process.getuid()),
|
|
50120
50398
|
basis: "project-volume"
|
|
@@ -50135,13 +50413,13 @@ async function v2CopyRoots(probe = {}) {
|
|
|
50135
50413
|
roots.push(await defaultCopyLocation(probe));
|
|
50136
50414
|
let volumesDir = probe.volumesDir ?? "/Volumes", uid = probe.uid ?? process.getuid(), volumes = [];
|
|
50137
50415
|
try {
|
|
50138
|
-
volumes = await
|
|
50416
|
+
volumes = await fs52.readdir(volumesDir);
|
|
50139
50417
|
} catch (err) {
|
|
50140
50418
|
if (err.code !== "ENOENT") throw err;
|
|
50141
50419
|
}
|
|
50142
50420
|
for (let volume of volumes) {
|
|
50143
50421
|
let candidate = projectVolumeCopyRoot(path60.join(volumesDir, volume), uid);
|
|
50144
|
-
(await
|
|
50422
|
+
(await fs52.lstat(candidate).catch(() => null))?.isDirectory() && roots.push(candidate);
|
|
50145
50423
|
}
|
|
50146
50424
|
} else platform2 === "linux" ? roots.push(...await linuxDiskCandidates(probe)) : roots.push(await defaultCopyLocation(probe));
|
|
50147
50425
|
return [...new Set(roots.map((root) => path60.resolve(root)))];
|
|
@@ -50170,10 +50448,10 @@ async function shadowRootPasses(env = {}, probe = env.copyRootProbe) {
|
|
|
50170
50448
|
async function readStateRootFormat(stateRootDir) {
|
|
50171
50449
|
let handle;
|
|
50172
50450
|
try {
|
|
50173
|
-
handle = await
|
|
50451
|
+
handle = await fs52.open(
|
|
50174
50452
|
path60.join(stateRootDir, SHADOW_STATE_FORMAT_FILE),
|
|
50175
50453
|
// Stage 2 R1-F8: O_NONBLOCK, so a FIFO named FORMAT is classified (not a regular file) instead of hanging.
|
|
50176
|
-
|
|
50454
|
+
import_node_fs29.constants.O_RDONLY | import_node_fs29.constants.O_NOFOLLOW | import_node_fs29.constants.O_NONBLOCK
|
|
50177
50455
|
);
|
|
50178
50456
|
} catch (err) {
|
|
50179
50457
|
return err.code === "ENOENT" ? { kind: "absent" } : { kind: "unknown", detail: `FORMAT unreadable: ${err.message}` };
|
|
@@ -50201,9 +50479,9 @@ async function ensureStateRootFormat(stateRootDir) {
|
|
|
50201
50479
|
new Error(`The task state folder ${stateRootDir} was created by a newer CodeVibe (${existing.detail}); this desktop will not add tasks to it. Update CodeVibe to continue.`),
|
|
50202
50480
|
{ code: "ESTATEFORMAT" }
|
|
50203
50481
|
);
|
|
50204
|
-
let formatFile = path60.join(stateRootDir, SHADOW_STATE_FORMAT_FILE), temporary = path60.join(stateRootDir, `${SHADOW_STATE_FORMAT_FILE}.${(0, import_node_crypto37.randomBytes)(8).toString("hex")}.tmp`), handle = await
|
|
50482
|
+
let formatFile = path60.join(stateRootDir, SHADOW_STATE_FORMAT_FILE), temporary = path60.join(stateRootDir, `${SHADOW_STATE_FORMAT_FILE}.${(0, import_node_crypto37.randomBytes)(8).toString("hex")}.tmp`), handle = await fs52.open(
|
|
50205
50483
|
temporary,
|
|
50206
|
-
|
|
50484
|
+
import_node_fs29.constants.O_WRONLY | import_node_fs29.constants.O_CREAT | import_node_fs29.constants.O_EXCL | import_node_fs29.constants.O_NOFOLLOW,
|
|
50207
50485
|
384
|
|
50208
50486
|
);
|
|
50209
50487
|
try {
|
|
@@ -50213,19 +50491,19 @@ async function ensureStateRootFormat(stateRootDir) {
|
|
|
50213
50491
|
}
|
|
50214
50492
|
try {
|
|
50215
50493
|
if (existing.kind === "empty")
|
|
50216
|
-
await
|
|
50494
|
+
await fs52.rename(temporary, formatFile);
|
|
50217
50495
|
else
|
|
50218
50496
|
try {
|
|
50219
|
-
await
|
|
50497
|
+
await fs52.link(temporary, formatFile);
|
|
50220
50498
|
} catch (err) {
|
|
50221
50499
|
if (err.code !== "EEXIST") throw err;
|
|
50222
50500
|
}
|
|
50223
50501
|
} finally {
|
|
50224
|
-
await
|
|
50502
|
+
await fs52.unlink(temporary).catch(() => {
|
|
50225
50503
|
});
|
|
50226
50504
|
}
|
|
50227
50505
|
if (process.platform !== "win32") {
|
|
50228
|
-
let dir = await
|
|
50506
|
+
let dir = await fs52.open(stateRootDir, import_node_fs29.constants.O_RDONLY | import_node_fs29.constants.O_NOFOLLOW);
|
|
50229
50507
|
try {
|
|
50230
50508
|
await dir.sync();
|
|
50231
50509
|
} finally {
|
|
@@ -50242,13 +50520,13 @@ async function passIsActionable(pass) {
|
|
|
50242
50520
|
init_shadow_start_record();
|
|
50243
50521
|
|
|
50244
50522
|
// src/local-executor/shadow-task-intent.ts
|
|
50245
|
-
var
|
|
50523
|
+
var fs57 = __toESM(require("node:fs/promises")), path65 = __toESM(require("node:path"));
|
|
50246
50524
|
|
|
50247
50525
|
// src/local-executor/shadow-apply-capabilities.ts
|
|
50248
|
-
var
|
|
50526
|
+
var import_node_fs33 = require("node:fs");
|
|
50249
50527
|
|
|
50250
50528
|
// src/local-executor/store-dir-anchor.ts
|
|
50251
|
-
var
|
|
50529
|
+
var import_node_fs30 = require("node:fs"), fs53 = __toESM(require("node:fs/promises")), path61 = __toESM(require("node:path"));
|
|
50252
50530
|
init_anchored_fs();
|
|
50253
50531
|
init_bounded_helper();
|
|
50254
50532
|
var O_NOFOLLOW_ANY_DARWIN = 536870912;
|
|
@@ -50261,11 +50539,11 @@ function safeName(name) {
|
|
|
50261
50539
|
}
|
|
50262
50540
|
var procFdUsable = null;
|
|
50263
50541
|
async function linuxProcFd() {
|
|
50264
|
-
return procFdUsable === null && (procFdUsable = process.platform === "linux" && await
|
|
50542
|
+
return procFdUsable === null && (procFdUsable = process.platform === "linux" && await fs53.stat("/proc/self/fd").then((s) => s.isDirectory(), () => !1)), procFdUsable;
|
|
50265
50543
|
}
|
|
50266
50544
|
async function openStoreAnchor(dir, opts) {
|
|
50267
50545
|
if (!path61.isAbsolute(dir)) throw refuse("store path is not absolute");
|
|
50268
|
-
let parent = await
|
|
50546
|
+
let parent = await fs53.realpath(path61.dirname(dir)), canonical = path61.join(parent, path61.basename(dir)), lstatDir = () => fs53.lstat(canonical).catch((err) => {
|
|
50269
50547
|
if (err.code === "ENOENT") return null;
|
|
50270
50548
|
throw err;
|
|
50271
50549
|
}), st = await lstatDir();
|
|
@@ -50273,13 +50551,13 @@ async function openStoreAnchor(dir, opts) {
|
|
|
50273
50551
|
if (!opts.create) return null;
|
|
50274
50552
|
let created = !1;
|
|
50275
50553
|
try {
|
|
50276
|
-
await
|
|
50554
|
+
await fs53.mkdir(canonical, { mode: 448 }), created = !0;
|
|
50277
50555
|
} catch (err) {
|
|
50278
50556
|
if (err.code !== "EEXIST") throw err;
|
|
50279
50557
|
}
|
|
50280
50558
|
if (st = await lstatDir(), st === null) throw refuse("store directory vanished while it was created");
|
|
50281
50559
|
if (created && process.platform !== "win32") {
|
|
50282
|
-
let p = await
|
|
50560
|
+
let p = await fs53.open(parent, import_node_fs30.constants.O_RDONLY);
|
|
50283
50561
|
try {
|
|
50284
50562
|
await p.sync();
|
|
50285
50563
|
} finally {
|
|
@@ -50288,7 +50566,7 @@ async function openStoreAnchor(dir, opts) {
|
|
|
50288
50566
|
}
|
|
50289
50567
|
}
|
|
50290
50568
|
if (st.isSymbolicLink() || !st.isDirectory()) throw refuse("store path is not a directory");
|
|
50291
|
-
let identity = { dev: st.dev, ino: st.ino }, noFollow = process.platform === "darwin" ? O_NOFOLLOW_ANY_DARWIN :
|
|
50569
|
+
let identity = { dev: st.dev, ino: st.ino }, noFollow = process.platform === "darwin" ? O_NOFOLLOW_ANY_DARWIN : import_node_fs30.constants.O_NOFOLLOW, dirFlags = import_node_fs30.constants.O_RDONLY | (import_node_fs30.constants.O_DIRECTORY ?? 0) | noFollow, held = await fs53.open(canonical, dirFlags).catch((err) => {
|
|
50292
50570
|
throw err.code === "ELOOP" || err.code === "ENOTDIR" ? refuse("store path is not a directory") : err;
|
|
50293
50571
|
});
|
|
50294
50572
|
try {
|
|
@@ -50318,7 +50596,7 @@ async function openStoreAnchor(dir, opts) {
|
|
|
50318
50596
|
process.platform !== "win32" && await held.sync();
|
|
50319
50597
|
},
|
|
50320
50598
|
async list() {
|
|
50321
|
-
return
|
|
50599
|
+
return fs53.readdir(pinned ? via : canonical);
|
|
50322
50600
|
},
|
|
50323
50601
|
async close() {
|
|
50324
50602
|
closed4 || (closed4 = !0, await held.close());
|
|
@@ -50347,7 +50625,7 @@ try { fs.fsyncSync(fd); } finally { fs.closeSync(fd); }
|
|
|
50347
50625
|
process.stdout.write(JSON.stringify({ ok: true, removed, kept }) + '\n');
|
|
50348
50626
|
`;
|
|
50349
50627
|
async function removeStoreEntriesAnchored(dir, prefixes, opts = {}) {
|
|
50350
|
-
let st = await
|
|
50628
|
+
let st = await fs53.lstat(dir, { bigint: !0 });
|
|
50351
50629
|
if (st.isSymbolicLink() || !st.isDirectory()) throw new Error("instance content store is not a directory");
|
|
50352
50630
|
let identity = { dev: st.dev.toString(), ino: st.ino.toString(), birthtimeNs: st.birthtimeNs.toString() };
|
|
50353
50631
|
await opts.beforeHelper?.();
|
|
@@ -50383,7 +50661,7 @@ async function removeStoreEntriesAnchored(dir, prefixes, opts = {}) {
|
|
|
50383
50661
|
let directoryRemoved = !1;
|
|
50384
50662
|
if ((result.kept ?? 0) === 0)
|
|
50385
50663
|
try {
|
|
50386
|
-
await anchoredRemoveEmptyDirectory(dir, identity, opts.helperTimeoutMs !== void 0 ? { helperTimeoutMs: opts.helperTimeoutMs } : {}), directoryRemoved = !await
|
|
50664
|
+
await anchoredRemoveEmptyDirectory(dir, identity, opts.helperTimeoutMs !== void 0 ? { helperTimeoutMs: opts.helperTimeoutMs } : {}), directoryRemoved = !await fs53.lstat(dir).then(() => !0, () => !1);
|
|
50387
50665
|
} catch (e) {
|
|
50388
50666
|
if (e.code !== "ENOENT") throw e;
|
|
50389
50667
|
}
|
|
@@ -50391,12 +50669,12 @@ async function removeStoreEntriesAnchored(dir, prefixes, opts = {}) {
|
|
|
50391
50669
|
}
|
|
50392
50670
|
|
|
50393
50671
|
// src/local-executor/shadow-apply-capabilities.ts
|
|
50394
|
-
var
|
|
50672
|
+
var fs56 = __toESM(require("node:fs/promises")), path64 = __toESM(require("node:path")), import_node_crypto40 = require("node:crypto");
|
|
50395
50673
|
init_nolink_apply();
|
|
50396
50674
|
init_shadow_protocol();
|
|
50397
50675
|
|
|
50398
50676
|
// src/local-executor/shadow-baseline-shards.ts
|
|
50399
|
-
var import_node_crypto38 = require("node:crypto"),
|
|
50677
|
+
var import_node_crypto38 = require("node:crypto"), import_node_fs31 = require("node:fs"), fs54 = __toESM(require("node:fs/promises")), path62 = __toESM(require("node:path"));
|
|
50400
50678
|
init_nolink_apply();
|
|
50401
50679
|
init_shadow_protocol();
|
|
50402
50680
|
var BASELINE_INLINE_MAX_BYTES = 8 * 1024 * 1024, BASELINE_SHARD_ENTRIES = 5e4, BASELINE_RECORD_VERSION = 1, BASELINE_SHARD_RE = /^baseline-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}-\d{5}\.jsonl$/i;
|
|
@@ -50413,7 +50691,7 @@ async function writeBaselineShards(stateDir, shadowDir, baseline, entriesPerShar
|
|
|
50413
50691
|
for (let start = 0, index = 0; start < baseline.length || index === 0; start += entriesPerShard, index += 1) {
|
|
50414
50692
|
let slice = baseline.slice(start, start + entriesPerShard), body2 = slice.map((entry5) => JSON.stringify(entry5)).join(`
|
|
50415
50693
|
`) + (slice.length ? `
|
|
50416
|
-
` : ""), name = baselineShardName(shadowDir, index), handle = await
|
|
50694
|
+
` : ""), name = baselineShardName(shadowDir, index), handle = await fs54.open(path62.join(stateDir, name), import_node_fs31.constants.O_WRONLY | import_node_fs31.constants.O_CREAT | import_node_fs31.constants.O_EXCL | import_node_fs31.constants.O_NOFOLLOW, 384);
|
|
50417
50695
|
try {
|
|
50418
50696
|
await handle.writeFile(body2), await handle.sync();
|
|
50419
50697
|
} finally {
|
|
@@ -50427,7 +50705,7 @@ async function writeBaselineShards(stateDir, shadowDir, baseline, entriesPerShar
|
|
|
50427
50705
|
}), slice.length === 0) break;
|
|
50428
50706
|
}
|
|
50429
50707
|
if (process.platform !== "win32") {
|
|
50430
|
-
let dir = await
|
|
50708
|
+
let dir = await fs54.open(stateDir, import_node_fs31.constants.O_RDONLY);
|
|
50431
50709
|
try {
|
|
50432
50710
|
await dir.sync();
|
|
50433
50711
|
} finally {
|
|
@@ -50480,16 +50758,16 @@ async function expandMarkerBaseline(stateDir, raw) {
|
|
|
50480
50758
|
}
|
|
50481
50759
|
async function listBaselineShards(stateDir, shadowDir) {
|
|
50482
50760
|
let suffix = path62.basename(shadowDir).match(SHADOW_UUID_SUFFIX_RE)?.[0];
|
|
50483
|
-
return suffix ? (await
|
|
50761
|
+
return suffix ? (await fs54.readdir(stateDir).catch(() => [])).filter((name) => BASELINE_SHARD_RE.test(name) && name.startsWith(`baseline${suffix}-`)) : [];
|
|
50484
50762
|
}
|
|
50485
50763
|
|
|
50486
50764
|
// src/local-executor/shadow-volume-probe.ts
|
|
50487
|
-
var import_node_child_process14 = require("node:child_process"), import_node_crypto39 = require("node:crypto"),
|
|
50765
|
+
var import_node_child_process14 = require("node:child_process"), import_node_crypto39 = require("node:crypto"), import_node_fs32 = require("node:fs"), fs55 = __toESM(require("node:fs/promises")), path63 = __toESM(require("node:path")), PROBE_ENTRY_RE = /^\.codevibe-probe-[0-9a-f]{32}(?:\.(?:renamed|link))?$/;
|
|
50488
50766
|
function newProbeEntryName() {
|
|
50489
50767
|
return `.codevibe-probe-${(0, import_node_crypto39.randomBytes)(16).toString("hex")}`;
|
|
50490
50768
|
}
|
|
50491
50769
|
async function bootIdentity(platform2 = process.platform) {
|
|
50492
|
-
if (platform2 === "linux") return (await
|
|
50770
|
+
if (platform2 === "linux") return (await fs55.readFile("/proc/sys/kernel/random/boot_id", "utf8")).trim();
|
|
50493
50771
|
if (platform2 === "darwin")
|
|
50494
50772
|
return new Promise((resolve35, reject) => {
|
|
50495
50773
|
(0, import_node_child_process14.execFile)("/usr/sbin/sysctl", ["-n", "kern.boottime"], (err, stdout) => {
|
|
@@ -50503,7 +50781,7 @@ async function probeVolumeCapabilities(projectRoot, journalProbeEntry, opts = {}
|
|
|
50503
50781
|
await journalProbeEntry(name);
|
|
50504
50782
|
let entry5 = path63.join(projectRoot, name), renamed = `${entry5}.renamed`, linked = `${entry5}.link`, steps = {}, modesTracked = !1, linkWorks = !1, inodeStable = !1;
|
|
50505
50783
|
try {
|
|
50506
|
-
let handle = await
|
|
50784
|
+
let handle = await fs55.open(entry5, import_node_fs32.constants.O_WRONLY | import_node_fs32.constants.O_CREAT | import_node_fs32.constants.O_EXCL | import_node_fs32.constants.O_NOFOLLOW, 384), inoCreate;
|
|
50507
50785
|
try {
|
|
50508
50786
|
await handle.writeFile(`codevibe probe
|
|
50509
50787
|
`), await handle.sync(), inoCreate = (await handle.stat({ bigint: !0 })).ino;
|
|
@@ -50511,27 +50789,27 @@ async function probeVolumeCapabilities(projectRoot, journalProbeEntry, opts = {}
|
|
|
50511
50789
|
await handle.close();
|
|
50512
50790
|
}
|
|
50513
50791
|
steps.exclusiveCreate = "ok";
|
|
50514
|
-
let inoClosed = (await
|
|
50792
|
+
let inoClosed = (await fs55.lstat(entry5, { bigint: !0 })).ino;
|
|
50515
50793
|
try {
|
|
50516
|
-
await
|
|
50517
|
-
let back = (await
|
|
50794
|
+
await fs55.chmod(entry5, 416);
|
|
50795
|
+
let back = (await fs55.lstat(entry5)).mode & 511;
|
|
50518
50796
|
modesTracked = back === 416, steps.chmod = modesTracked ? "ok" : `ignored (read back ${back.toString(8)})`;
|
|
50519
50797
|
} catch (err) {
|
|
50520
50798
|
steps.chmod = err.code ?? "error";
|
|
50521
50799
|
}
|
|
50522
50800
|
try {
|
|
50523
|
-
await
|
|
50801
|
+
await fs55.link(entry5, linked), linkWorks = !0, steps.link = "ok", await fs55.unlink(linked);
|
|
50524
50802
|
} catch (err) {
|
|
50525
50803
|
steps.link = err.code ?? "error";
|
|
50526
50804
|
}
|
|
50527
|
-
await
|
|
50528
|
-
let inoRenamed = (await
|
|
50529
|
-
await
|
|
50805
|
+
await fs55.rename(entry5, renamed), steps.rename = "ok";
|
|
50806
|
+
let inoRenamed = (await fs55.lstat(renamed, { bigint: !0 })).ino;
|
|
50807
|
+
await fs55.writeFile(renamed, `codevibe probe rewritten
|
|
50530
50808
|
`);
|
|
50531
|
-
let inoRewritten = (await
|
|
50809
|
+
let inoRewritten = (await fs55.lstat(renamed, { bigint: !0 })).ino, inos = [inoCreate, inoClosed, inoRenamed, inoRewritten];
|
|
50532
50810
|
inodeStable = inos.every((ino) => ino !== 0n && ino === inoCreate), steps.inodes = inos.map(String).join(",");
|
|
50533
50811
|
try {
|
|
50534
|
-
let dir = await
|
|
50812
|
+
let dir = await fs55.open(projectRoot, import_node_fs32.constants.O_RDONLY | import_node_fs32.constants.O_DIRECTORY);
|
|
50535
50813
|
try {
|
|
50536
50814
|
await dir.sync();
|
|
50537
50815
|
} finally {
|
|
@@ -50544,7 +50822,7 @@ async function probeVolumeCapabilities(projectRoot, journalProbeEntry, opts = {}
|
|
|
50544
50822
|
} finally {
|
|
50545
50823
|
await removeJournaledProbeEntry(projectRoot, name);
|
|
50546
50824
|
}
|
|
50547
|
-
let rootStat = await
|
|
50825
|
+
let rootStat = await fs55.stat(projectRoot, { bigint: !0 });
|
|
50548
50826
|
return {
|
|
50549
50827
|
version: 1,
|
|
50550
50828
|
mode: linkWorks ? "link" : "nolink",
|
|
@@ -50560,7 +50838,7 @@ async function removeJournaledProbeEntry(projectRoot, name) {
|
|
|
50560
50838
|
throw new Error(`not a probe entry name: ${JSON.stringify(name)}`);
|
|
50561
50839
|
for (let candidate of [name, `${name}.renamed`, `${name}.link`]) {
|
|
50562
50840
|
let full = path63.join(projectRoot, candidate);
|
|
50563
|
-
(await
|
|
50841
|
+
(await fs55.lstat(full).catch(() => null))?.isFile() && await fs55.unlink(full).catch(() => {
|
|
50564
50842
|
});
|
|
50565
50843
|
}
|
|
50566
50844
|
}
|
|
@@ -50568,7 +50846,7 @@ async function inodesTrustedNow(journaled, projectRoot, platform2) {
|
|
|
50568
50846
|
if (!journaled.inodeStable) return !1;
|
|
50569
50847
|
let [boot, stat25] = await Promise.all([
|
|
50570
50848
|
bootIdentity(platform2).catch(() => null),
|
|
50571
|
-
|
|
50849
|
+
fs55.stat(projectRoot, { bigint: !0 }).catch(() => null)
|
|
50572
50850
|
]);
|
|
50573
50851
|
return boot === journaled.bootId && stat25 !== null && stat25.dev.toString() === journaled.dev;
|
|
50574
50852
|
}
|
|
@@ -50601,10 +50879,10 @@ function manifestStoreFor(stateDir, shadowDir) {
|
|
|
50601
50879
|
return { dir: instanceStoreDir(stateDir, shadowDir), prefix: `manifest${instanceSuffix(shadowDir)}` };
|
|
50602
50880
|
}
|
|
50603
50881
|
async function removeInstanceStore(storeDir, suffix) {
|
|
50604
|
-
let prefixes = [`blob${suffix}-`, `manifest${suffix}-`], top = await
|
|
50882
|
+
let prefixes = [`blob${suffix}-`, `manifest${suffix}-`], top = await fs56.lstat(storeDir).catch(() => null);
|
|
50605
50883
|
if (top !== null) {
|
|
50606
50884
|
if (top.isSymbolicLink()) {
|
|
50607
|
-
await
|
|
50885
|
+
await fs56.unlink(storeDir).catch((err) => {
|
|
50608
50886
|
if (err.code !== "ENOENT") throw err;
|
|
50609
50887
|
});
|
|
50610
50888
|
return;
|
|
@@ -50614,14 +50892,14 @@ async function removeInstanceStore(storeDir, suffix) {
|
|
|
50614
50892
|
}
|
|
50615
50893
|
var testRetireSeam;
|
|
50616
50894
|
async function writeDurable(file, body2) {
|
|
50617
|
-
let temp = `${file}.${(0, import_node_crypto40.randomBytes)(8).toString("hex")}.tmp`, handle = await
|
|
50895
|
+
let temp = `${file}.${(0, import_node_crypto40.randomBytes)(8).toString("hex")}.tmp`, handle = await fs56.open(temp, import_node_fs33.constants.O_WRONLY | import_node_fs33.constants.O_CREAT | import_node_fs33.constants.O_EXCL | import_node_fs33.constants.O_NOFOLLOW, 384);
|
|
50618
50896
|
try {
|
|
50619
50897
|
await handle.writeFile(body2), await handle.sync();
|
|
50620
50898
|
} finally {
|
|
50621
50899
|
await handle.close();
|
|
50622
50900
|
}
|
|
50623
|
-
if (await
|
|
50624
|
-
let dir = await
|
|
50901
|
+
if (await fs56.rename(temp, file), process.platform !== "win32") {
|
|
50902
|
+
let dir = await fs56.open(path64.dirname(file), import_node_fs33.constants.O_RDONLY);
|
|
50625
50903
|
try {
|
|
50626
50904
|
await dir.sync();
|
|
50627
50905
|
} finally {
|
|
@@ -50659,7 +50937,7 @@ async function ensureApplyCapabilities(stateDir, shadowDir, workspaceRoot, force
|
|
|
50659
50937
|
linkVolume: probed.mode === "link"
|
|
50660
50938
|
};
|
|
50661
50939
|
return await writeDurable(names.capabilities, `${JSON.stringify(resolved)}
|
|
50662
|
-
`), await
|
|
50940
|
+
`), await fs56.unlink(names.probeJournal).catch(() => {
|
|
50663
50941
|
}), resolved;
|
|
50664
50942
|
}
|
|
50665
50943
|
var NoLinkPendingError = class extends Error {
|
|
@@ -50766,10 +51044,10 @@ async function retireApplyArtifacts(stateDir, shadowDir, workspaceRoot) {
|
|
|
50766
51044
|
let leftover = await readStateFile(names.probeJournal).catch(() => null);
|
|
50767
51045
|
if (leftover !== null) {
|
|
50768
51046
|
let { entry: entry5, projectRoot } = JSON.parse(leftover), root = workspaceRoot ?? projectRoot;
|
|
50769
|
-
root !== void 0 && (await removeJournaledProbeEntry(root, entry5), await
|
|
51047
|
+
root !== void 0 && (await removeJournaledProbeEntry(root, entry5), await fs56.unlink(names.probeJournal).catch(() => {
|
|
50770
51048
|
}));
|
|
50771
51049
|
}
|
|
50772
|
-
await
|
|
51050
|
+
await fs56.unlink(names.capabilities).catch((err) => {
|
|
50773
51051
|
if (err.code !== "ENOENT") throw err;
|
|
50774
51052
|
}), await removeInstanceStore(instanceStoreDir(stateDir, shadowDir), instanceSuffix(shadowDir));
|
|
50775
51053
|
let prefixes = [
|
|
@@ -50777,13 +51055,13 @@ async function retireApplyArtifacts(stateDir, shadowDir, workspaceRoot) {
|
|
|
50777
51055
|
startRecordPrefix(shadowDir) + "-",
|
|
50778
51056
|
startRecordPrefix(shadowDir) + "."
|
|
50779
51057
|
];
|
|
50780
|
-
for (let entry5 of await
|
|
51058
|
+
for (let entry5 of await fs56.readdir(stateDir).catch(() => [])) {
|
|
50781
51059
|
if (!prefixes.some((p) => entry5.startsWith(p))) continue;
|
|
50782
|
-
(await
|
|
51060
|
+
(await fs56.lstat(path64.join(stateDir, entry5)).catch(() => null))?.isFile() && await fs56.unlink(path64.join(stateDir, entry5)).catch(() => {
|
|
50783
51061
|
});
|
|
50784
51062
|
}
|
|
50785
51063
|
for (let shard of await listBaselineShards(stateDir, shadowDir))
|
|
50786
|
-
await
|
|
51064
|
+
await fs56.unlink(path64.join(stateDir, shard)).catch((err) => {
|
|
50787
51065
|
if (err.code !== "ENOENT") throw err;
|
|
50788
51066
|
});
|
|
50789
51067
|
}
|
|
@@ -50799,11 +51077,11 @@ async function retireInstanceRecordsForMarker(markerFile) {
|
|
|
50799
51077
|
}
|
|
50800
51078
|
var INSTANCE_ARTEFACT_RE = /^(?:apply-probe|apply-capabilities|baseline|nolink|start-record)(-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})(?:\.json|\.manifest\.json|\.intent\.json|-\d{5}\.jsonl|-[0-9a-f]{48}\.json(?:\.[0-9a-f]{16}\.tmp)?)$/i, INSTANCE_STORE_RE = /^store(-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})$/i, ORPHAN_ARTEFACT_MIN_AGE_MS = 3600 * 1e3;
|
|
50801
51079
|
async function reapOrphanedInstanceArtefacts(stateDir, now = Date.now()) {
|
|
50802
|
-
let names = await
|
|
51080
|
+
let names = await fs56.readdir(stateDir).catch(() => []), markers = new Set(names.filter((n) => /^shadow-state-.+\.json$/.test(n))), removed = [];
|
|
50803
51081
|
for (let name of names) {
|
|
50804
51082
|
let match = INSTANCE_ARTEFACT_RE.exec(name) ?? INSTANCE_STORE_RE.exec(name);
|
|
50805
51083
|
if (!match || markers.has(`shadow-state${match[1]}.json`)) continue;
|
|
50806
|
-
let full = path64.join(stateDir, name), stat25 = await
|
|
51084
|
+
let full = path64.join(stateDir, name), stat25 = await fs56.lstat(full).catch(() => null);
|
|
50807
51085
|
if (!(!stat25 || now - stat25.mtimeMs < ORPHAN_ARTEFACT_MIN_AGE_MS)) {
|
|
50808
51086
|
if (name.startsWith("apply-probe")) {
|
|
50809
51087
|
if (!stat25.isFile()) continue;
|
|
@@ -50814,7 +51092,7 @@ async function reapOrphanedInstanceArtefacts(stateDir, now = Date.now()) {
|
|
|
50814
51092
|
} catch {
|
|
50815
51093
|
continue;
|
|
50816
51094
|
}
|
|
50817
|
-
await
|
|
51095
|
+
await fs56.unlink(full).catch(() => {
|
|
50818
51096
|
});
|
|
50819
51097
|
} else if (name.startsWith("nolink") && name.endsWith(".json")) {
|
|
50820
51098
|
if (!stat25.isFile()) continue;
|
|
@@ -50827,13 +51105,13 @@ async function reapOrphanedInstanceArtefacts(stateDir, now = Date.now()) {
|
|
|
50827
51105
|
continue;
|
|
50828
51106
|
}
|
|
50829
51107
|
if (entry5.state !== "done") continue;
|
|
50830
|
-
await
|
|
51108
|
+
await fs56.unlink(full).catch(() => {
|
|
50831
51109
|
});
|
|
50832
51110
|
} else if (name.startsWith("store")) {
|
|
50833
|
-
if (!stat25.isDirectory() || stat25.isSymbolicLink() || (await removeInstanceStore(full, match[1]), await
|
|
51111
|
+
if (!stat25.isDirectory() || stat25.isSymbolicLink() || (await removeInstanceStore(full, match[1]), await fs56.lstat(full).then(() => !0, () => !1))) continue;
|
|
50834
51112
|
} else {
|
|
50835
51113
|
if (!stat25.isFile()) continue;
|
|
50836
|
-
await
|
|
51114
|
+
await fs56.unlink(full).catch(() => {
|
|
50837
51115
|
});
|
|
50838
51116
|
}
|
|
50839
51117
|
removed.push(name);
|
|
@@ -50854,7 +51132,7 @@ async function writeTaskIntent(stateDir, shadowDir, intent) {
|
|
|
50854
51132
|
async function readTaskIntent(stateDir, shadowDir) {
|
|
50855
51133
|
let text2;
|
|
50856
51134
|
try {
|
|
50857
|
-
text2 = await
|
|
51135
|
+
text2 = await fs57.readFile(intentFile(stateDir, shadowDir), "utf8");
|
|
50858
51136
|
} catch (err) {
|
|
50859
51137
|
if (err.code === "ENOENT") return { kind: "none" };
|
|
50860
51138
|
throw err;
|
|
@@ -50867,7 +51145,7 @@ async function readTaskIntent(stateDir, shadowDir) {
|
|
|
50867
51145
|
}
|
|
50868
51146
|
|
|
50869
51147
|
// src/local-executor/blob-store.ts
|
|
50870
|
-
var import_node_crypto41 = require("node:crypto"),
|
|
51148
|
+
var import_node_crypto41 = require("node:crypto"), import_node_fs34 = require("node:fs"), fs58 = __toESM(require("node:fs/promises")), path66 = __toESM(require("node:path"));
|
|
50871
51149
|
init_binary_classifier();
|
|
50872
51150
|
var BLOB_CHUNK_BYTES = 1024 * 1024, HEX64 = /^[0-9a-f]{64}$/, PREFIX_RE = /^blob-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
50873
51151
|
function assertStore(store) {
|
|
@@ -50897,35 +51175,35 @@ async function withStoreAnchor(dir, fn) {
|
|
|
50897
51175
|
}
|
|
50898
51176
|
async function createStoreTemp(anchor2, name, testBeforeOpen) {
|
|
50899
51177
|
await testBeforeOpen?.();
|
|
50900
|
-
let handle = await
|
|
51178
|
+
let handle = await fs58.open(anchor2.at(name), import_node_fs34.constants.O_WRONLY | import_node_fs34.constants.O_CREAT | import_node_fs34.constants.O_EXCL | anchor2.noFollow, 384).catch((err) => {
|
|
50901
51179
|
throw err.code === "ELOOP" || err.code === "ENOTDIR" || err.code === "ENOENT" ? refuse2("store directory changed while a file was created in it") : err;
|
|
50902
51180
|
});
|
|
50903
51181
|
try {
|
|
50904
|
-
let [own2, named] = await Promise.all([handle.stat(),
|
|
51182
|
+
let [own2, named] = await Promise.all([handle.stat(), fs58.lstat(anchor2.at(name))]);
|
|
50905
51183
|
if (own2.dev !== anchor2.identity.dev || named.dev !== own2.dev || named.ino !== own2.ino)
|
|
50906
51184
|
throw refuse2("store directory changed while a file was created in it");
|
|
50907
51185
|
await anchor2.assertStill("while a file was created in it");
|
|
50908
51186
|
} catch (err) {
|
|
50909
51187
|
throw await handle.close().catch(() => {
|
|
50910
|
-
}), anchor2.pinned && await
|
|
51188
|
+
}), anchor2.pinned && await fs58.unlink(anchor2.at(name)).catch(() => {
|
|
50911
51189
|
}), err;
|
|
50912
51190
|
}
|
|
50913
51191
|
return handle;
|
|
50914
51192
|
}
|
|
50915
51193
|
async function publishStoreTemp(anchor2, tmp, finalName) {
|
|
50916
51194
|
try {
|
|
50917
|
-
await anchor2.assertStill("before publishing"), await
|
|
51195
|
+
await anchor2.assertStill("before publishing"), await fs58.link(anchor2.at(tmp), anchor2.at(finalName));
|
|
50918
51196
|
} catch (err) {
|
|
50919
51197
|
if (err.code !== "EEXIST")
|
|
50920
|
-
throw await
|
|
51198
|
+
throw await fs58.unlink(anchor2.at(tmp)).catch(() => {
|
|
50921
51199
|
}), err;
|
|
50922
|
-
return await
|
|
51200
|
+
return await fs58.unlink(anchor2.at(tmp)).catch(() => {
|
|
50923
51201
|
}), "exists";
|
|
50924
51202
|
}
|
|
50925
|
-
return await
|
|
51203
|
+
return await fs58.unlink(anchor2.at(tmp)), "published";
|
|
50926
51204
|
}
|
|
50927
51205
|
async function dropStoreTemp(anchor2, tmp) {
|
|
50928
|
-
await
|
|
51206
|
+
await fs58.unlink(anchor2.at(tmp)).catch(() => {
|
|
50929
51207
|
});
|
|
50930
51208
|
}
|
|
50931
51209
|
async function putBlob(store, chunks, opts = {}) {
|
|
@@ -50983,7 +51261,7 @@ async function putBlobFromAnchoredCopy(store, copy) {
|
|
|
50983
51261
|
let ref = { blob: read.sha256, size: read.size };
|
|
50984
51262
|
try {
|
|
50985
51263
|
if (!HEX64.test(ref.blob) || !Number.isSafeInteger(ref.size) || ref.size < 0) throw refuse2("invalid anchored copy result");
|
|
50986
|
-
let hash3 = (0, import_node_crypto41.createHash)("sha256"), total = 0, check = await
|
|
51264
|
+
let hash3 = (0, import_node_crypto41.createHash)("sha256"), total = 0, check = await fs58.open(anchor2.at(tmp), import_node_fs34.constants.O_RDONLY | anchor2.noFollow);
|
|
50987
51265
|
try {
|
|
50988
51266
|
let buf = Buffer.alloc(BLOB_CHUNK_BYTES);
|
|
50989
51267
|
for (; ; ) {
|
|
@@ -51004,7 +51282,7 @@ async function putBlobFromAnchoredCopy(store, copy) {
|
|
|
51004
51282
|
async function copyBlob(src, dst, ref) {
|
|
51005
51283
|
if (src.dir === dst.dir && src.prefix === dst.prefix)
|
|
51006
51284
|
return await verifyBlob(src, ref), ref;
|
|
51007
|
-
let present = await
|
|
51285
|
+
let present = await fs58.lstat(blobPath(dst, ref.blob)).catch(() => null);
|
|
51008
51286
|
if (present?.isFile() && present.size === ref.size)
|
|
51009
51287
|
return await verifyBlob(dst, ref), ref;
|
|
51010
51288
|
let copied = await putBlob(dst, readBlobChunks(src, ref));
|
|
@@ -51013,7 +51291,7 @@ async function copyBlob(src, dst, ref) {
|
|
|
51013
51291
|
}
|
|
51014
51292
|
async function* readBlobChunks(store, ref) {
|
|
51015
51293
|
if (!Number.isSafeInteger(ref.size) || ref.size < 0) throw refuse2("invalid blob size");
|
|
51016
|
-
let handle = await
|
|
51294
|
+
let handle = await fs58.open(blobPath(store, ref.blob), import_node_fs34.constants.O_RDONLY | import_node_fs34.constants.O_NOFOLLOW | import_node_fs34.constants.O_NONBLOCK);
|
|
51017
51295
|
try {
|
|
51018
51296
|
let stat25 = await handle.stat();
|
|
51019
51297
|
if (!stat25.isFile() || stat25.size !== ref.size) throw refuse2(`blob ${ref.blob} is not a regular file of ${ref.size} bytes`);
|
|
@@ -51031,7 +51309,7 @@ async function* readBlobChunks(store, ref) {
|
|
|
51031
51309
|
}
|
|
51032
51310
|
}
|
|
51033
51311
|
async function openBlobForStreaming(store, ref) {
|
|
51034
|
-
let handle = await
|
|
51312
|
+
let handle = await fs58.open(blobPath(store, ref.blob), import_node_fs34.constants.O_RDONLY | import_node_fs34.constants.O_NOFOLLOW | import_node_fs34.constants.O_NONBLOCK);
|
|
51035
51313
|
try {
|
|
51036
51314
|
let stat25 = await handle.stat();
|
|
51037
51315
|
if (!stat25.isFile() || stat25.size !== ref.size) throw refuse2(`blob ${ref.blob} is not a regular file of ${ref.size} bytes`);
|
|
@@ -51074,7 +51352,7 @@ async function readBlobBytes(store, ref, maxBytes) {
|
|
|
51074
51352
|
return Buffer.concat(parts, ref.size);
|
|
51075
51353
|
}
|
|
51076
51354
|
async function readBlobHead(store, ref, maxBytes) {
|
|
51077
|
-
let handle = await
|
|
51355
|
+
let handle = await fs58.open(blobPath(store, ref.blob), import_node_fs34.constants.O_RDONLY | import_node_fs34.constants.O_NOFOLLOW | import_node_fs34.constants.O_NONBLOCK);
|
|
51078
51356
|
try {
|
|
51079
51357
|
let stat25 = await handle.stat();
|
|
51080
51358
|
if (!stat25.isFile() || stat25.size !== ref.size) throw refuse2(`blob ${ref.blob} is not a regular file of ${ref.size} bytes`);
|
|
@@ -51094,14 +51372,14 @@ async function readBlobHead(store, ref, maxBytes) {
|
|
|
51094
51372
|
init_binary_classifier();
|
|
51095
51373
|
|
|
51096
51374
|
// src/local-executor/shadow-slice3-cleanups.ts
|
|
51097
|
-
var
|
|
51375
|
+
var fs59 = __toESM(require("node:fs/promises")), path67 = __toESM(require("node:path"));
|
|
51098
51376
|
init_logger2();
|
|
51099
51377
|
init_shadow_protocol();
|
|
51100
51378
|
async function removeEmptyCreatedStateDir(createdStateDir, taskId) {
|
|
51101
51379
|
if (createdStateDir)
|
|
51102
51380
|
try {
|
|
51103
|
-
let st = await
|
|
51104
|
-
st.isDirectory() && !st.isSymbolicLink() && String(st.dev) === createdStateDir.dev && String(st.ino) === createdStateDir.ino && String(st.birthtimeNs) === createdStateDir.birthtimeNs && (await
|
|
51381
|
+
let st = await fs59.lstat(createdStateDir.canonicalPath, { bigint: !0 });
|
|
51382
|
+
st.isDirectory() && !st.isSymbolicLink() && String(st.dev) === createdStateDir.dev && String(st.ino) === createdStateDir.ino && String(st.birthtimeNs) === createdStateDir.birthtimeNs && (await fs59.readdir(createdStateDir.canonicalPath)).length === 0 && await fs59.rmdir(createdStateDir.canonicalPath);
|
|
51105
51383
|
} catch (stateDirErr) {
|
|
51106
51384
|
logger.warn("[WorkspaceShadow] failed-create state directory kept", {
|
|
51107
51385
|
taskId,
|
|
@@ -51118,17 +51396,17 @@ async function removeOrphanCaptureDirs(keepTaskIds, env = {}) {
|
|
|
51118
51396
|
async function removeOrphanCaptureDirsInPair(keepTaskIds, stateRoot, shadowRootDir) {
|
|
51119
51397
|
let removed = [], names;
|
|
51120
51398
|
try {
|
|
51121
|
-
names = await
|
|
51399
|
+
names = await fs59.readdir(shadowRootDir);
|
|
51122
51400
|
} catch (err) {
|
|
51123
51401
|
if (err.code === "ENOENT") return removed;
|
|
51124
51402
|
throw err;
|
|
51125
51403
|
}
|
|
51126
51404
|
for (let taskId of names) {
|
|
51127
51405
|
if (keepTaskIds.has(taskId) || taskId.startsWith(".") || isStateRootInfrastructureDirectory(taskId)) continue;
|
|
51128
|
-
let taskFolder = path67.join(shadowRootDir, taskId), capture = path67.join(taskFolder, "capture"), st = await
|
|
51406
|
+
let taskFolder = path67.join(shadowRootDir, taskId), capture = path67.join(taskFolder, "capture"), st = await fs59.lstat(capture).catch(() => null);
|
|
51129
51407
|
if (!st || !st.isDirectory() || st.isSymbolicLink()) continue;
|
|
51130
|
-
let folder = await
|
|
51131
|
-
!folder || !folder.isDirectory() || folder.isSymbolicLink() || await
|
|
51408
|
+
let folder = await fs59.lstat(taskFolder).catch(() => null);
|
|
51409
|
+
!folder || !folder.isDirectory() || folder.isSymbolicLink() || await fs59.lstat(path67.join(stateRoot, taskId)).then(() => "present", (err) => err.code === "ENOENT" ? "absent" : "unknown") !== "absent" || (await fs59.rm(capture, { recursive: !0, force: !0 }), removed.push(capture), await fs59.rmdir(taskFolder).catch(() => {
|
|
51132
51410
|
}));
|
|
51133
51411
|
}
|
|
51134
51412
|
return removed;
|
|
@@ -51140,7 +51418,7 @@ async function sweepOrphanCaptureDirs(keepTaskIds, skip, env = {}) {
|
|
|
51140
51418
|
}
|
|
51141
51419
|
|
|
51142
51420
|
// src/local-executor/withheld-media.ts
|
|
51143
|
-
var
|
|
51421
|
+
var fs60 = __toESM(require("node:fs/promises")), path69 = __toESM(require("node:path"));
|
|
51144
51422
|
|
|
51145
51423
|
// src/local-executor/office-extractor.ts
|
|
51146
51424
|
var crypto18 = __toESM(require("node:crypto")), path68 = __toESM(require("node:path"));
|
|
@@ -52561,7 +52839,7 @@ async function withheldMediaChanges(store, preTaskHashes, files, readLiveBase) {
|
|
|
52561
52839
|
var OTHER_BINARY = { kind: "other", format: "other_binary" };
|
|
52562
52840
|
async function storedBlob(store, hash3) {
|
|
52563
52841
|
if (!hash3) return null;
|
|
52564
|
-
let stat25 = await
|
|
52842
|
+
let stat25 = await fs60.stat(path69.join(store.dir, `${store.prefix}-${hash3}`)).catch(() => null);
|
|
52565
52843
|
return stat25?.isFile() ? { blob: hash3, size: stat25.size } : null;
|
|
52566
52844
|
}
|
|
52567
52845
|
async function unreadableOffice(store, file, baseRef) {
|
|
@@ -52657,7 +52935,7 @@ function parseChangeManifestShard(bytes, expected) {
|
|
|
52657
52935
|
}
|
|
52658
52936
|
|
|
52659
52937
|
// src/local-executor/change-manifest-store.ts
|
|
52660
|
-
var import_node_crypto43 = require("node:crypto"),
|
|
52938
|
+
var import_node_crypto43 = require("node:crypto"), import_node_fs35 = require("node:fs"), fs61 = __toESM(require("node:fs/promises")), path70 = __toESM(require("node:path"));
|
|
52661
52939
|
var PREFIX_RE2 = /^manifest-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, HEX643 = /^[0-9a-f]{64}$/, MAX_MANIFEST_SHARD_BYTES = 64 * 1024 * 1024;
|
|
52662
52940
|
function assertStore2(store) {
|
|
52663
52941
|
if (!PREFIX_RE2.test(store.prefix)) throw new Error("change manifest store: invalid prefix");
|
|
@@ -52667,7 +52945,7 @@ function manifestShardName(store, sha2568) {
|
|
|
52667
52945
|
return `${store.prefix}-${sha2568}`;
|
|
52668
52946
|
}
|
|
52669
52947
|
async function readShardFile(file, maxBytes) {
|
|
52670
|
-
let handle = await
|
|
52948
|
+
let handle = await fs61.open(file, import_node_fs35.constants.O_RDONLY | import_node_fs35.constants.O_NOFOLLOW | import_node_fs35.constants.O_NONBLOCK);
|
|
52671
52949
|
try {
|
|
52672
52950
|
let stat25 = await handle.stat();
|
|
52673
52951
|
if (!stat25.isFile() || stat25.size > maxBytes) throw new Error(`change manifest shard is not a bounded regular file: ${file}`);
|
|
@@ -54146,7 +54424,7 @@ init_task_folder();
|
|
|
54146
54424
|
init_shadow_protocol();
|
|
54147
54425
|
|
|
54148
54426
|
// src/local-executor/shadow-recovery.ts
|
|
54149
|
-
var crypto21 = __toESM(require("node:crypto")), fsSync7 = __toESM(require("node:fs")),
|
|
54427
|
+
var crypto21 = __toESM(require("node:crypto")), fsSync7 = __toESM(require("node:fs")), fs65 = __toESM(require("node:fs/promises")), import_node_fs37 = require("node:fs"), os37 = __toESM(require("node:os")), path76 = __toESM(require("node:path"));
|
|
54150
54428
|
init_logger2();
|
|
54151
54429
|
init_anchored_fs();
|
|
54152
54430
|
init_process_identity();
|
|
@@ -54240,7 +54518,7 @@ async function scanShadowMarkers(env = {}, ownedTaskIds) {
|
|
|
54240
54518
|
throw err;
|
|
54241
54519
|
});
|
|
54242
54520
|
if (env.signal?.aborted) return { recovered: [], exposureRetentions: [], displacedSnapshots: [], protectedDirNames: /* @__PURE__ */ new Set(), unresolved: [] };
|
|
54243
|
-
let shadowRoot = shadowRootAuthority?.canonicalPath ?? path76.resolve(requestedShadowRoot), siblingRoots = new Set(await Promise.all((env.siblingShadowRoots ?? []).map((root) =>
|
|
54521
|
+
let shadowRoot = shadowRootAuthority?.canonicalPath ?? path76.resolve(requestedShadowRoot), siblingRoots = new Set(await Promise.all((env.siblingShadowRoots ?? []).map((root) => fs65.realpath(root).catch(() => path76.resolve(root))))), belongsToSibling = (snapshotPath) => siblingRoots.size > 0 && typeof snapshotPath == "string" && siblingRoots.has(path76.dirname(path76.resolve(snapshotPath))), metadataBudget = createPathBudget(), entries;
|
|
54244
54522
|
try {
|
|
54245
54523
|
entries = await readDirectoryBounded(
|
|
54246
54524
|
stateRoot,
|
|
@@ -55080,7 +55358,7 @@ async function listShadowCleanupResidueInPair(taskIds, env) {
|
|
|
55080
55358
|
label: taskId
|
|
55081
55359
|
});
|
|
55082
55360
|
try {
|
|
55083
|
-
await
|
|
55361
|
+
await fs65.lstat(stateDir, { bigint: !0 }), add({ taskId, path: stateDir, kind: "state-directory" });
|
|
55084
55362
|
} catch (err) {
|
|
55085
55363
|
if (err.code !== "ENOENT") throw err;
|
|
55086
55364
|
}
|
|
@@ -55263,7 +55541,7 @@ async function sealSnapshotTreeDurably(snapshotRoot, snapshotRootAuthority, env)
|
|
|
55263
55541
|
{ absolute: snapshotRoot, relative: "", identity: snapshotRootAuthority }
|
|
55264
55542
|
], directories = [];
|
|
55265
55543
|
for (; pending2.length > 0; ) {
|
|
55266
|
-
let current = pending2.pop(), currentStat = await
|
|
55544
|
+
let current = pending2.pop(), currentStat = await fs65.lstat(current.absolute, { bigint: !0 });
|
|
55267
55545
|
if (!currentStat.isDirectory() || currentStat.isSymbolicLink() || currentStat.dev.toString() !== current.identity.dev || currentStat.ino.toString() !== current.identity.ino)
|
|
55268
55546
|
throw new Error("snapshot durability seal found an unsafe directory");
|
|
55269
55547
|
directories.push(current);
|
|
@@ -55280,7 +55558,7 @@ async function sealSnapshotTreeDurably(snapshotRoot, snapshotRootAuthority, env)
|
|
|
55280
55558
|
}
|
|
55281
55559
|
), files = [];
|
|
55282
55560
|
for (let entry5 of entries) {
|
|
55283
|
-
let relative26 = current.relative ? path76.join(current.relative, entry5.name) : entry5.name, absolute = path76.join(snapshotRoot, relative26), stat25 = await
|
|
55561
|
+
let relative26 = current.relative ? path76.join(current.relative, entry5.name) : entry5.name, absolute = path76.join(snapshotRoot, relative26), stat25 = await fs65.lstat(absolute, { bigint: !0 });
|
|
55284
55562
|
if (stat25.isDirectory() && !stat25.isSymbolicLink()) {
|
|
55285
55563
|
let enumerated = boundedDirectoryStat(entry5);
|
|
55286
55564
|
if (!enumerated || enumerated.dev !== stat25.dev.toString() || enumerated.ino !== stat25.ino.toString())
|
|
@@ -55295,7 +55573,7 @@ async function sealSnapshotTreeDurably(snapshotRoot, snapshotRootAuthority, env)
|
|
|
55295
55573
|
}
|
|
55296
55574
|
}
|
|
55297
55575
|
await forEachBounded(files, SEAL_FILE_CONCURRENCY, async ({ absolute, relative: relative26, stat: stat25 }) => {
|
|
55298
|
-
let handle = await
|
|
55576
|
+
let handle = await fs65.open(absolute, import_node_fs37.constants.O_RDONLY | import_node_fs37.constants.O_NOFOLLOW);
|
|
55299
55577
|
try {
|
|
55300
55578
|
let before = await handle.stat({ bigint: !0 });
|
|
55301
55579
|
if (!before.isFile() || before.dev !== stat25.dev || before.ino !== stat25.ino)
|
|
@@ -55303,7 +55581,7 @@ async function sealSnapshotTreeDurably(snapshotRoot, snapshotRootAuthority, env)
|
|
|
55303
55581
|
await env.beforeSnapshotDurabilitySync?.("file", absolute), await handle.sync();
|
|
55304
55582
|
let [after, live] = await Promise.all([
|
|
55305
55583
|
handle.stat({ bigint: !0 }),
|
|
55306
|
-
|
|
55584
|
+
fs65.lstat(absolute, { bigint: !0 })
|
|
55307
55585
|
]);
|
|
55308
55586
|
if (!after.isFile() || !live.isFile() || live.isSymbolicLink() || after.dev !== before.dev || after.ino !== before.ino || live.dev !== before.dev || live.ino !== before.ino || after.size !== before.size || after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) throw new Error(`snapshot file changed during durability sync: ${relative26}`);
|
|
55309
55587
|
} finally {
|
|
@@ -55320,7 +55598,7 @@ async function sealSnapshotTreeDurably(snapshotRoot, snapshotRootAuthority, env)
|
|
|
55320
55598
|
await env.beforeSnapshotDurabilitySync?.("directory", directory.absolute), process.platform !== "win32" && await handle.sync();
|
|
55321
55599
|
let [after, live] = await Promise.all([
|
|
55322
55600
|
handle.stat({ bigint: !0 }),
|
|
55323
|
-
|
|
55601
|
+
fs65.lstat(directory.absolute, { bigint: !0 })
|
|
55324
55602
|
]);
|
|
55325
55603
|
if (!after.isDirectory() || !live.isDirectory() || live.isSymbolicLink() || after.dev !== before.dev || after.ino !== before.ino || live.dev !== before.dev || live.ino !== before.ino || after.dev.toString() !== directory.identity.dev || after.ino.toString() !== directory.identity.ino) throw new Error(`snapshot directory changed during durability sync: ${directory.relative}`);
|
|
55326
55604
|
} finally {
|
|
@@ -55344,7 +55622,7 @@ async function createCopyShadow(workingDir, shadowDir, sourceRootAuthority, copy
|
|
|
55344
55622
|
(root) => !isWithinRoot(root, workingDir)
|
|
55345
55623
|
), excludedRootIdentities = /* @__PURE__ */ new Set();
|
|
55346
55624
|
for (let excludedRoot of reachableExcludedRoots) {
|
|
55347
|
-
let stats = await
|
|
55625
|
+
let stats = await fs65.stat(excludedRoot, { bigint: !0 }).catch(() => null);
|
|
55348
55626
|
stats !== null && excludedRootIdentities.add(`${stats.dev}:${stats.ino}`);
|
|
55349
55627
|
}
|
|
55350
55628
|
let walkStats = { entriesSeen: 0 }, copyLanes = lanes !== void 0 && lanes.length > 0 ? lanes : [{ copyFile: copyFile3, ...batchClones ? { batchClones } : {} }], scheduler = new CopyScheduler(copyLanes), slots = [];
|
|
@@ -55730,7 +56008,7 @@ async function removeExposureRetentionMarker(stateFile, expected, shadowRoot, ph
|
|
|
55730
56008
|
async function removeExposureRetentionMarkerIfPublicAbsent(stateFile, publicShadowDir, expected, shadowRoot, physicalCopyScope, expectedStateDir, expectedFileAuthority, opts) {
|
|
55731
56009
|
if (opts?.signal?.aborted) return !1;
|
|
55732
56010
|
try {
|
|
55733
|
-
return await
|
|
56011
|
+
return await fs65.lstat(publicShadowDir), !1;
|
|
55734
56012
|
} catch (err) {
|
|
55735
56013
|
if (err.code !== "ENOENT") throw err;
|
|
55736
56014
|
}
|
|
@@ -56398,7 +56676,7 @@ async function hasAnyOwnedAnchor(dir, name, opts) {
|
|
|
56398
56676
|
try {
|
|
56399
56677
|
let target2 = path76.join(dir, name);
|
|
56400
56678
|
return await withHelperDeadline(
|
|
56401
|
-
|
|
56679
|
+
fs65.lstat(target2),
|
|
56402
56680
|
resolveHelperTimeout(opts?.helperTimeoutMs),
|
|
56403
56681
|
"anchor lstat",
|
|
56404
56682
|
opts?.signal
|
|
@@ -56484,7 +56762,7 @@ async function readStableHandleWithLimit(handle, before, maxBytes, label, opts)
|
|
|
56484
56762
|
async function readSnapshotOwnerAnchor(shadowDir, opts) {
|
|
56485
56763
|
if (opts?.signal?.aborted)
|
|
56486
56764
|
throw new Error("anchored operation aborted by signal");
|
|
56487
|
-
let activeHandle, settled = !1, hasError = !1, timeout = resolveHelperTimeout(opts?.helperTimeoutMs), filePath = path76.join(shadowDir, SHADOW_OWNER_FILE), openPromise = (opts?.openFileHandle ??
|
|
56765
|
+
let activeHandle, settled = !1, hasError = !1, timeout = resolveHelperTimeout(opts?.helperTimeoutMs), filePath = path76.join(shadowDir, SHADOW_OWNER_FILE), openPromise = (opts?.openFileHandle ?? fs65.open)(filePath, import_node_fs37.constants.O_RDONLY | import_node_fs37.constants.O_NOFOLLOW);
|
|
56488
56766
|
openPromise.then(
|
|
56489
56767
|
(h) => {
|
|
56490
56768
|
settled ? h.close().catch(() => {
|
|
@@ -56549,7 +56827,7 @@ async function scanPersistedPhysicalCopyBytes(shadowRoots, physicalCopyScope, li
|
|
|
56549
56827
|
let shadowRoot = registeredRoot.path;
|
|
56550
56828
|
if (await isOnUnmountedVolume(shadowRoot, registeredRoot.dev) || registeredRoot.vanished === !0) continue;
|
|
56551
56829
|
let beforeRoot = await withHelperDeadline(
|
|
56552
|
-
|
|
56830
|
+
fs65.lstat(shadowRoot, { bigint: !0 }),
|
|
56553
56831
|
timeout,
|
|
56554
56832
|
"scanPersistedPhysicalCopyBytes root lstat",
|
|
56555
56833
|
opts?.signal
|
|
@@ -56577,7 +56855,7 @@ async function scanPersistedPhysicalCopyBytes(shadowRoots, physicalCopyScope, li
|
|
|
56577
56855
|
let shadowDir = path76.join(shadowRoot, entry5.name);
|
|
56578
56856
|
try {
|
|
56579
56857
|
let stat25 = await withHelperDeadline(
|
|
56580
|
-
|
|
56858
|
+
fs65.lstat(shadowDir),
|
|
56581
56859
|
timeout,
|
|
56582
56860
|
"scanPersistedPhysicalCopyBytes shadowDir lstat",
|
|
56583
56861
|
opts?.signal
|
|
@@ -56593,7 +56871,7 @@ async function scanPersistedPhysicalCopyBytes(shadowRoots, physicalCopyScope, li
|
|
|
56593
56871
|
}
|
|
56594
56872
|
}
|
|
56595
56873
|
let afterRoot = await withHelperDeadline(
|
|
56596
|
-
|
|
56874
|
+
fs65.lstat(shadowRoot, { bigint: !0 }),
|
|
56597
56875
|
timeout,
|
|
56598
56876
|
"scanPersistedPhysicalCopyBytes afterRoot lstat",
|
|
56599
56877
|
opts?.signal
|
|
@@ -56668,21 +56946,21 @@ async function hasUnreclaimedExposureRetention(stateRoot, opts) {
|
|
|
56668
56946
|
async function isOnUnmountedVolume(copyRoot, registeredDev) {
|
|
56669
56947
|
if (!/^\.codevibe-shadows-\d+$/.test(path76.basename(copyRoot))) return !1;
|
|
56670
56948
|
let volumeRoot = path76.dirname(copyRoot);
|
|
56671
|
-
if (volumeRoot === copyRoot || await
|
|
56949
|
+
if (volumeRoot === copyRoot || await fs65.lstat(copyRoot).then(() => !0, (err) => err.code !== "ENOENT")) return !1;
|
|
56672
56950
|
let volume;
|
|
56673
56951
|
try {
|
|
56674
|
-
volume = await
|
|
56952
|
+
volume = await fs65.lstat(volumeRoot, { bigint: !0 });
|
|
56675
56953
|
} catch (err) {
|
|
56676
56954
|
return err.code === "ENOENT";
|
|
56677
56955
|
}
|
|
56678
56956
|
if (!volume.isDirectory()) return !1;
|
|
56679
56957
|
if (registeredDev !== void 0 && /^-?\d+$/.test(registeredDev)) return volume.dev.toString() !== registeredDev;
|
|
56680
|
-
let holder = await
|
|
56958
|
+
let holder = await fs65.lstat(path76.dirname(volumeRoot), { bigint: !0 }).catch(() => null);
|
|
56681
56959
|
return holder !== null && holder.dev === volume.dev;
|
|
56682
56960
|
}
|
|
56683
56961
|
async function markerIsRecoveryAuthority(markerFile) {
|
|
56684
56962
|
try {
|
|
56685
|
-
let handle = await
|
|
56963
|
+
let handle = await fs65.open(markerFile, import_node_fs37.constants.O_RDONLY | import_node_fs37.constants.O_NOFOLLOW | import_node_fs37.constants.O_NONBLOCK), text2;
|
|
56686
56964
|
try {
|
|
56687
56965
|
let stat25 = await handle.stat();
|
|
56688
56966
|
if (!stat25.isFile() || stat25.size > MAX_STATE_MARKER_BYTES) return !0;
|
|
@@ -56698,7 +56976,7 @@ async function markerIsRecoveryAuthority(markerFile) {
|
|
|
56698
56976
|
if (!suffix) return !1;
|
|
56699
56977
|
let prefix = `nolink${suffix}-`, names;
|
|
56700
56978
|
try {
|
|
56701
|
-
names = await
|
|
56979
|
+
names = await fs65.readdir(path76.dirname(markerFile));
|
|
56702
56980
|
} catch (err) {
|
|
56703
56981
|
return err.code !== "ENOENT";
|
|
56704
56982
|
}
|
|
@@ -56718,7 +56996,7 @@ async function markerIsRecoveryAuthority(markerFile) {
|
|
|
56718
56996
|
return !1;
|
|
56719
56997
|
}
|
|
56720
56998
|
async function readMarkerClaimBounded(stateFile) {
|
|
56721
|
-
let handle = await
|
|
56999
|
+
let handle = await fs65.open(stateFile, import_node_fs37.constants.O_RDONLY | import_node_fs37.constants.O_NOFOLLOW | import_node_fs37.constants.O_NONBLOCK);
|
|
56722
57000
|
try {
|
|
56723
57001
|
let stat25 = await handle.stat();
|
|
56724
57002
|
if (!stat25.isFile() || stat25.size > MAX_STATE_MARKER_BYTES) throw new Error("marker claim is not a bounded regular file");
|
|
@@ -56936,7 +57214,7 @@ async function registerAndListQuotaShadowRoots(stateRoot, stateRootIdentity, cur
|
|
|
56936
57214
|
let parent = path76.dirname(candidate.path);
|
|
56937
57215
|
if (parent === candidate.path) return !0;
|
|
56938
57216
|
try {
|
|
56939
|
-
await
|
|
57217
|
+
await fs65.lstat(parent);
|
|
56940
57218
|
} catch (err) {
|
|
56941
57219
|
return err.code !== "ENOENT";
|
|
56942
57220
|
}
|
|
@@ -57080,7 +57358,7 @@ async function registerAndListQuotaShadowRoots(stateRoot, stateRootIdentity, cur
|
|
|
57080
57358
|
await canRetireReincarnatedRoot(candidate) || retained.push({ path: candidate.path, ...liveCandidate });
|
|
57081
57359
|
continue;
|
|
57082
57360
|
}
|
|
57083
|
-
let stat25 = await
|
|
57361
|
+
let stat25 = await fs65.lstat(candidate.path, { bigint: !0 });
|
|
57084
57362
|
if (!stat25.isDirectory() || stat25.isSymbolicLink() || stat25.dev.toString() !== candidate.dev || stat25.ino.toString() !== candidate.ino) {
|
|
57085
57363
|
if (!await canRetireReincarnatedRoot(candidate))
|
|
57086
57364
|
throw new Error("registered physical-copy root changed identity");
|
|
@@ -57377,9 +57655,9 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
57377
57655
|
*/
|
|
57378
57656
|
static async precheckCopySpace(workingDir, env = {}) {
|
|
57379
57657
|
try {
|
|
57380
|
-
let canonicalWorkingDir = await
|
|
57658
|
+
let canonicalWorkingDir = await fs66.realpath(workingDir), resolvedRoots = await resolveShadowRoots(env), stateRootIsV2Default = path77.resolve(resolvedRoots.stateRootDir) === path77.resolve(defaultStateRoot()), shadowRoot = resolvedRoots.shadowRootDir;
|
|
57381
57659
|
env.shadowRootDir === void 0 && stateRootIsV2Default && (shadowRoot = (await chooseCopyLocation(canonicalWorkingDir, env.copyRootProbe)).copyRoot);
|
|
57382
|
-
let copyLocation = await
|
|
57660
|
+
let copyLocation = await fs66.realpath(shadowRoot).catch(async (err) => {
|
|
57383
57661
|
if (err.code !== "ENOENT") throw err;
|
|
57384
57662
|
return (await ensureDurableDirectoryTree(shadowRoot, {
|
|
57385
57663
|
anchorPath: durableDirectoryAnchor(shadowRoot),
|
|
@@ -57410,7 +57688,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
57410
57688
|
}
|
|
57411
57689
|
stateRootIsV2Default && (await readStateRootFormat(requestedStateRoot)).kind === "unknown" && await ensureStateRootFormat(requestedStateRoot);
|
|
57412
57690
|
let resolvedWorkingDir = path77.resolve(workingDir), isWorkspacePath = (candidate) => candidate === resolvedWorkingDir || candidate === canonicalWorkingDir, sharesWorkspaceIdentity = async (candidate) => {
|
|
57413
|
-
let stats = await
|
|
57691
|
+
let stats = await fs66.stat(candidate, { bigint: !0 }).catch(() => null);
|
|
57414
57692
|
return stats !== null && stats.dev.toString() === workspaceRootAuthority.dev && stats.ino.toString() === workspaceRootAuthority.ino;
|
|
57415
57693
|
};
|
|
57416
57694
|
for (let requestedRoot of [requestedShadowRoot, requestedStateRoot]) {
|
|
@@ -57513,7 +57791,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
57513
57791
|
if (await withAnchoredExclusiveLock(
|
|
57514
57792
|
lifecycleLock,
|
|
57515
57793
|
async () => {
|
|
57516
|
-
await
|
|
57794
|
+
await fs66.mkdir(shadowDir, { recursive: !1, mode: 448 }), createdShadowAuthority = await captureWorkspaceRootAuthority(shadowDir), createdShadowIdentity = {
|
|
57517
57795
|
dev: createdShadowAuthority.dev,
|
|
57518
57796
|
ino: createdShadowAuthority.ino
|
|
57519
57797
|
}, exposureRetention = {
|
|
@@ -57631,7 +57909,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
57631
57909
|
currentOwner.snapshotRootAuthority,
|
|
57632
57910
|
creationSnapshotAuthority
|
|
57633
57911
|
) || !sameFsIdentity(currentOwner.shadowDirIdentity, createdShadowIdentity) || currentOwner.ownerProcessIdentity.pid !== ownerProcessIdentity.pid || currentOwner.ownerProcessIdentity.incarnationId !== ownerProcessIdentity.incarnationId) throw new Error("snapshot owner authority changed before exposure");
|
|
57634
|
-
await sealSnapshotTreeDurably(stagingDir, creationSnapshotAuthority, env), await
|
|
57912
|
+
await sealSnapshotTreeDurably(stagingDir, creationSnapshotAuthority, env), await fs66.rename(stagingDir, finalShadowDir), shadowDir = finalShadowDir, movePhysicalCopyReservation(physicalCopyScope, stagingDir, shadowDir), await env.beforeSnapshotDurabilitySync?.("parent", shadowRoot), await fsyncDirectory2(shadowRoot), await env.afterSnapshotExposeRename?.(finalShadowDir);
|
|
57635
57913
|
let observedExposedAuthority = await captureWorkspaceRootAuthority(
|
|
57636
57914
|
finalShadowDir,
|
|
57637
57915
|
workspaceAuthorityOptions(env, finalShadowDir, "snapshot exposure")
|
|
@@ -58171,7 +58449,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
58171
58449
|
return { content: "", mode: read.mode, blob: ref, ...fileClass2 ? { file_class: fileClass2 } : {} };
|
|
58172
58450
|
}
|
|
58173
58451
|
}
|
|
58174
|
-
await this.admitStoreCopy((await
|
|
58452
|
+
await this.admitStoreCopy((await fs66.lstat(path77.join(this.shadowDir, rel)).catch(() => null))?.size ?? 0);
|
|
58175
58453
|
let stored = await putBlobFromAnchoredCopy(store, (fd) => anchoredCopyFileWithinRoot(this.shadowDir, rel, {
|
|
58176
58454
|
maxBytes: MAX_CAPTURE_FILE_BYTES,
|
|
58177
58455
|
outFd: fd,
|
|
@@ -58214,7 +58492,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
58214
58492
|
*/
|
|
58215
58493
|
async realBaseClass(rel, required) {
|
|
58216
58494
|
let store = blobStoreFor(this.stateDir, this.shadowDir);
|
|
58217
|
-
await this.admitStoreCopy((await
|
|
58495
|
+
await this.admitStoreCopy((await fs66.lstat(path77.join(this.workingDir, rel)).catch(() => null))?.size ?? 0);
|
|
58218
58496
|
let copied = await putBlobFromAnchoredCopy(store, (fd) => anchoredCopyFileWithinRoot(this.workingDir, rel, {
|
|
58219
58497
|
maxBytes: MAX_CAPTURE_FILE_BYTES,
|
|
58220
58498
|
outFd: fd,
|
|
@@ -58288,7 +58566,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
58288
58566
|
*/
|
|
58289
58567
|
async ownPostImageBlob(store, file, sourceStore) {
|
|
58290
58568
|
if (file.blob) {
|
|
58291
|
-
let present = await
|
|
58569
|
+
let present = await fs66.stat(path77.join(store.dir, `${store.prefix}-${file.blob.blob}`)).catch(() => null);
|
|
58292
58570
|
if (present?.isFile() && present.size === file.blob.size) return file.blob;
|
|
58293
58571
|
}
|
|
58294
58572
|
if (isReferenceDiffFile(file)) {
|
|
@@ -58580,7 +58858,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
58580
58858
|
if (current.hash === null || current.mode === null)
|
|
58581
58859
|
preImages.set(rel, null);
|
|
58582
58860
|
else {
|
|
58583
|
-
let originalBytes = (await
|
|
58861
|
+
let originalBytes = (await fs66.lstat(path77.join(this.workingDir, rel))).size, space = await checkCopySpace({ copyLocation: this.stateDir, bytesToCopy: originalBytes });
|
|
58584
58862
|
if (!space.ok) throw new InsufficientCopySpaceError(space);
|
|
58585
58863
|
let smallOriginal = originalBytes <= READ_SESSION_CONTENT_MAX_BYTES ? await reads.hashFile(this.workingDir, rel, {
|
|
58586
58864
|
maxBytes: READ_SESSION_CONTENT_MAX_BYTES,
|
|
@@ -59095,7 +59373,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
59095
59373
|
async treeRemovalBudgetMs(signal) {
|
|
59096
59374
|
let countEntries = async (dir) => {
|
|
59097
59375
|
let n = 0;
|
|
59098
|
-
for await (let entry5 of await
|
|
59376
|
+
for await (let entry5 of await fs66.opendir(dir))
|
|
59099
59377
|
n++, entry5.isDirectory() && !entry5.isSymbolicLink() && (n += await countEntries(path77.join(dir, entry5.name)));
|
|
59100
59378
|
return n;
|
|
59101
59379
|
}, entries = await withHelperDeadline(
|
|
@@ -59366,7 +59644,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
59366
59644
|
shadowDirIdentity: this.shadowDirIdentity,
|
|
59367
59645
|
snapshotRootAuthority: this.snapshotRootAuthority
|
|
59368
59646
|
}, { helperTimeoutMs, signal }), stateSnapshot = await this.readStateMarkerSnapshot(!0, { helperTimeoutMs, signal });
|
|
59369
|
-
if (fallback.present && (fallback.fileIdentity || stateSnapshot?.marker.promoteState !== "disposing" || await
|
|
59647
|
+
if (fallback.present && (fallback.fileIdentity || stateSnapshot?.marker.promoteState !== "disposing" || await fs66.lstat(this.shadowDir).then(() => !0, (err) => err.code !== "ENOENT")))
|
|
59370
59648
|
throw new Error(
|
|
59371
59649
|
`WorkspaceShadow: refusing to discard ${this.taskId} while fallback cleanup authority exists`
|
|
59372
59650
|
);
|
|
@@ -59374,7 +59652,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
59374
59652
|
try {
|
|
59375
59653
|
let timeout = resolveHelperTimeout(helperTimeoutMs);
|
|
59376
59654
|
await withHelperDeadline(
|
|
59377
|
-
|
|
59655
|
+
fs66.lstat(this.shadowDir),
|
|
59378
59656
|
timeout,
|
|
59379
59657
|
"assertDiscardable shadowDir lstat",
|
|
59380
59658
|
signal
|
|
@@ -59414,7 +59692,7 @@ var ShadowCaptureCancelledError = class extends Error {
|
|
|
59414
59692
|
try {
|
|
59415
59693
|
let timeout = resolveHelperTimeout(opts.helperTimeoutMs);
|
|
59416
59694
|
await withHelperDeadline(
|
|
59417
|
-
|
|
59695
|
+
fs66.lstat(this.shadowDir),
|
|
59418
59696
|
timeout,
|
|
59419
59697
|
"beginDisposal shadowDir lstat",
|
|
59420
59698
|
opts.signal
|
|
@@ -60016,7 +60294,7 @@ async function reopenShadow(recovered, env = {}) {
|
|
|
60016
60294
|
async function removeEmptyTaskFolders(taskId, env = {}) {
|
|
60017
60295
|
let { shadowRootDir } = await resolveShadowRoots(env);
|
|
60018
60296
|
for (let root of [env.stateRootDir ?? defaultStateRoot(), shadowRootDir])
|
|
60019
|
-
await
|
|
60297
|
+
await fs66.rmdir(path77.join(root, taskId)).catch((err) => {
|
|
60020
60298
|
if (err.code !== "ENOENT" && err.code !== "ENOTEMPTY" && err.code !== "EEXIST") throw err;
|
|
60021
60299
|
});
|
|
60022
60300
|
}
|
|
@@ -60267,8 +60545,8 @@ async function reapOrphanShadowsInPair(keepTaskIdsIn, env, sweepProcessOwners, r
|
|
|
60267
60545
|
var PROJECT_VOLUME_COPY_ROOT_RE = /^\.codevibe-shadows-\d+$/;
|
|
60268
60546
|
async function removeEmptyProjectVolumeCopyRoot(shadowRoot) {
|
|
60269
60547
|
if (!PROJECT_VOLUME_COPY_ROOT_RE.test(path77.basename(shadowRoot))) return;
|
|
60270
|
-
let stat25 = await
|
|
60271
|
-
!stat25?.isDirectory() || stat25.uid !== process.getuid?.() || await
|
|
60548
|
+
let stat25 = await fs66.lstat(shadowRoot).catch(() => null);
|
|
60549
|
+
!stat25?.isDirectory() || stat25.uid !== process.getuid?.() || await fs66.rmdir(shadowRoot).catch((err) => {
|
|
60272
60550
|
if (!(err.code === "ENOTEMPTY" || err.code === "EEXIST" || err.code === "ENOENT"))
|
|
60273
60551
|
throw err;
|
|
60274
60552
|
});
|
|
@@ -60596,7 +60874,7 @@ init_anchored_fs();
|
|
|
60596
60874
|
init_shadow_protocol();
|
|
60597
60875
|
|
|
60598
60876
|
// src/local-executor/sharded-list.ts
|
|
60599
|
-
var import_node_crypto46 = require("node:crypto"),
|
|
60877
|
+
var import_node_crypto46 = require("node:crypto"), import_node_fs38 = require("node:fs"), fs67 = __toESM(require("node:fs/promises")), path81 = __toESM(require("node:path"));
|
|
60600
60878
|
var SHARDED_LIST_VERSION = 1, SHARDED_LIST_SHARD_ITEMS = 1e4, MAX_SHARDED_LIST_SHARD_BYTES = 64 * 1024 * 1024, PREFIX_RE3 = /^list-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, KIND_RE = /^[a-z][a-z0-9-]{0,63}$/, HEX644 = /^[0-9a-f]{64}$/;
|
|
60601
60879
|
function sha2564(data) {
|
|
60602
60880
|
return (0, import_node_crypto46.createHash)("sha256").update(data).digest("hex");
|
|
@@ -60618,7 +60896,7 @@ function canonicalJson2(value) {
|
|
|
60618
60896
|
return Array.isArray(value) ? `[${value.map((v) => canonicalJson2(v)).join(",")}]` : `{${Object.keys(value).filter((k) => value[k] !== void 0).sort().map((k) => `${JSON.stringify(k)}:${canonicalJson2(value[k])}`).join(",")}}`;
|
|
60619
60897
|
}
|
|
60620
60898
|
async function readShardFile2(file) {
|
|
60621
|
-
let handle = await
|
|
60899
|
+
let handle = await fs67.open(file, import_node_fs38.constants.O_RDONLY | import_node_fs38.constants.O_NOFOLLOW | import_node_fs38.constants.O_NONBLOCK);
|
|
60622
60900
|
try {
|
|
60623
60901
|
let stat25 = await handle.stat();
|
|
60624
60902
|
if (!stat25.isFile() || stat25.size > MAX_SHARDED_LIST_SHARD_BYTES)
|
|
@@ -61202,10 +61480,10 @@ async function runSnapshotMergeGate(args) {
|
|
|
61202
61480
|
deletedPaths: plan.files.filter((file) => file.change_kind === "deleted").map((file) => file.path),
|
|
61203
61481
|
trackIndex: -1,
|
|
61204
61482
|
runShell: runShellCommand,
|
|
61205
|
-
lstat:
|
|
61206
|
-
realpath:
|
|
61207
|
-
stat:
|
|
61208
|
-
readFile: (file) =>
|
|
61483
|
+
lstat: fs68.lstat,
|
|
61484
|
+
realpath: fs68.realpath,
|
|
61485
|
+
stat: fs68.stat,
|
|
61486
|
+
readFile: (file) => fs68.readFile(file, "utf8"),
|
|
61209
61487
|
timeoutMs,
|
|
61210
61488
|
signal: args.signal,
|
|
61211
61489
|
shadowRootAuthority: integrationAuthority
|
|
@@ -61737,7 +62015,7 @@ function assertExactSnapshotPromotionJournal(value) {
|
|
|
61737
62015
|
init_shadow_protocol();
|
|
61738
62016
|
|
|
61739
62017
|
// src/local-executor/team-media-approval.ts
|
|
61740
|
-
var
|
|
62018
|
+
var fs69 = __toESM(require("node:fs/promises")), path83 = __toESM(require("node:path"));
|
|
61741
62019
|
init_shadow_protocol();
|
|
61742
62020
|
var declined = /* @__PURE__ */ new WeakMap();
|
|
61743
62021
|
function takeTeamMediaDeclined(owner, taskGroupId) {
|
|
@@ -61769,7 +62047,7 @@ function recordPath(stateRoot, taskGroupId) {
|
|
|
61769
62047
|
return path83.join(teamMediaQuestionDir(stateRoot), `${taskGroupId}.json`);
|
|
61770
62048
|
}
|
|
61771
62049
|
async function syncDirectory(dir) {
|
|
61772
|
-
let fh = await
|
|
62050
|
+
let fh = await fs69.open(dir, "r");
|
|
61773
62051
|
try {
|
|
61774
62052
|
await fh.sync();
|
|
61775
62053
|
} finally {
|
|
@@ -61777,27 +62055,27 @@ async function syncDirectory(dir) {
|
|
|
61777
62055
|
}
|
|
61778
62056
|
}
|
|
61779
62057
|
async function writeOpenTeamMediaQuestion(stateRoot, q) {
|
|
61780
|
-
let dir = teamMediaQuestionDir(stateRoot), created = await
|
|
62058
|
+
let dir = teamMediaQuestionDir(stateRoot), created = await fs69.mkdir(dir, { recursive: !0, mode: 448 }), target2 = recordPath(stateRoot, q.taskGroupId), tmp = `${target2}.${process.pid}.tmp`, fh = await fs69.open(tmp, "w", 384);
|
|
61781
62059
|
try {
|
|
61782
62060
|
await fh.writeFile(JSON.stringify(q)), await fh.sync();
|
|
61783
62061
|
} finally {
|
|
61784
62062
|
await fh.close();
|
|
61785
62063
|
}
|
|
61786
|
-
await
|
|
62064
|
+
await fs69.rename(tmp, target2), await syncDirectory(dir), created !== void 0 && await syncDirectory(path83.dirname(dir));
|
|
61787
62065
|
}
|
|
61788
62066
|
async function removeOpenTeamMediaQuestion(stateRoot, taskGroupId) {
|
|
61789
|
-
await
|
|
62067
|
+
await fs69.rm(recordPath(stateRoot, taskGroupId), { force: !0 }), await syncDirectory(teamMediaQuestionDir(stateRoot)).catch((err) => {
|
|
61790
62068
|
if (err.code !== "ENOENT") throw err;
|
|
61791
62069
|
});
|
|
61792
62070
|
}
|
|
61793
62071
|
async function listOpenTeamMediaQuestions(stateRoot) {
|
|
61794
|
-
let dir = teamMediaQuestionDir(stateRoot), names = await
|
|
62072
|
+
let dir = teamMediaQuestionDir(stateRoot), names = await fs69.readdir(dir).catch((err) => {
|
|
61795
62073
|
if (err.code === "ENOENT") return [];
|
|
61796
62074
|
throw err;
|
|
61797
62075
|
}), out = [];
|
|
61798
62076
|
for (let name of names) {
|
|
61799
62077
|
if (!name.endsWith(".json")) continue;
|
|
61800
|
-
let q = JSON.parse(await
|
|
62078
|
+
let q = JSON.parse(await fs69.readFile(path83.join(dir, name), "utf8"));
|
|
61801
62079
|
q.version === 1 && typeof q.taskGroupId == "string" && typeof q.sessionId == "string" && `${q.taskGroupId}.json` === name && out.push(q);
|
|
61802
62080
|
}
|
|
61803
62081
|
return out;
|
|
@@ -61858,23 +62136,23 @@ async function recoverOpenTeamMediaQuestions(args) {
|
|
|
61858
62136
|
}
|
|
61859
62137
|
|
|
61860
62138
|
// src/local-executor/team-summary.ts
|
|
61861
|
-
var crypto24 = __toESM(require("node:crypto")),
|
|
62139
|
+
var crypto24 = __toESM(require("node:crypto")), fs70 = __toESM(require("node:fs")), path84 = __toESM(require("node:path"));
|
|
61862
62140
|
function atomicWriteJsonSync(targetPath, data, options = {}) {
|
|
61863
62141
|
let dir = path84.dirname(targetPath);
|
|
61864
|
-
|
|
62142
|
+
fs70.existsSync(dir) || fs70.mkdirSync(dir, { recursive: !0 });
|
|
61865
62143
|
let uniqueId = crypto24.randomUUID ? crypto24.randomUUID() : `${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}`, tmpPath = path84.join(dir, `.tmp.${path84.basename(targetPath)}.${uniqueId}`), serialized = typeof data == "string" ? data : JSON.stringify(data, null, 2), fd = null, renameSucceeded = !1;
|
|
61866
62144
|
try {
|
|
61867
|
-
if (fd =
|
|
62145
|
+
if (fd = fs70.openSync(tmpPath, "wx", 384), fs70.writeFileSync(fd, serialized, "utf8"), fs70.fsyncSync(fd), options.interruptBeforeRename)
|
|
61868
62146
|
throw new Error("Interrupted before atomic rename");
|
|
61869
|
-
|
|
62147
|
+
fs70.closeSync(fd), fd = null, fs70.renameSync(tmpPath, targetPath), renameSucceeded = !0;
|
|
61870
62148
|
try {
|
|
61871
62149
|
if (options.injectDirectorySyncError)
|
|
61872
62150
|
throw options.injectDirectorySyncError;
|
|
61873
|
-
let dirFd =
|
|
62151
|
+
let dirFd = fs70.openSync(dir, "r");
|
|
61874
62152
|
try {
|
|
61875
|
-
|
|
62153
|
+
fs70.fsyncSync(dirFd);
|
|
61876
62154
|
} finally {
|
|
61877
|
-
|
|
62155
|
+
fs70.closeSync(dirFd);
|
|
61878
62156
|
}
|
|
61879
62157
|
} catch (dirErr) {
|
|
61880
62158
|
let code = dirErr?.code;
|
|
@@ -61884,12 +62162,12 @@ function atomicWriteJsonSync(targetPath, data, options = {}) {
|
|
|
61884
62162
|
} finally {
|
|
61885
62163
|
if (fd !== null)
|
|
61886
62164
|
try {
|
|
61887
|
-
|
|
62165
|
+
fs70.closeSync(fd);
|
|
61888
62166
|
} catch {
|
|
61889
62167
|
}
|
|
61890
62168
|
if (!renameSucceeded && !options.interruptBeforeRename)
|
|
61891
62169
|
try {
|
|
61892
|
-
|
|
62170
|
+
fs70.existsSync(tmpPath) && fs70.unlinkSync(tmpPath);
|
|
61893
62171
|
} catch {
|
|
61894
62172
|
}
|
|
61895
62173
|
}
|
|
@@ -61947,7 +62225,7 @@ function validateDeliveryJournalEntry(item2, filePath, index) {
|
|
|
61947
62225
|
}
|
|
61948
62226
|
function shouldUnlinkAbandonedTmpLockFile(fullPath, fileName, tmpPrefix, nowMs) {
|
|
61949
62227
|
try {
|
|
61950
|
-
let stat25 =
|
|
62228
|
+
let stat25 = fs70.statSync(fullPath);
|
|
61951
62229
|
if (nowMs - stat25.mtimeMs < 50)
|
|
61952
62230
|
return !1;
|
|
61953
62231
|
let remainder = fileName.slice(tmpPrefix.length), [pidStr] = remainder.split(".");
|
|
@@ -61978,25 +62256,25 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
61978
62256
|
}
|
|
61979
62257
|
backupCorruptFile() {
|
|
61980
62258
|
try {
|
|
61981
|
-
if (
|
|
62259
|
+
if (fs70.existsSync(this.filePath)) {
|
|
61982
62260
|
let backupPath = `${this.filePath}.corrupt-${Date.now()}`;
|
|
61983
|
-
|
|
62261
|
+
fs70.copyFileSync(this.filePath, backupPath);
|
|
61984
62262
|
}
|
|
61985
62263
|
} catch {
|
|
61986
62264
|
}
|
|
61987
62265
|
}
|
|
61988
62266
|
withLock(action2) {
|
|
61989
62267
|
let lockPath = `${this.filePath}.lock`, dir = path84.dirname(this.filePath);
|
|
61990
|
-
|
|
62268
|
+
fs70.existsSync(dir) || fs70.mkdirSync(dir, { recursive: !0 });
|
|
61991
62269
|
let tmpPrefix = `${path84.basename(lockPath)}.tmp.`;
|
|
61992
62270
|
try {
|
|
61993
|
-
let files =
|
|
62271
|
+
let files = fs70.readdirSync(dir), now = Date.now();
|
|
61994
62272
|
for (let file of files)
|
|
61995
62273
|
if (file.startsWith(tmpPrefix)) {
|
|
61996
62274
|
let fullPath = path84.join(dir, file);
|
|
61997
62275
|
if (shouldUnlinkAbandonedTmpLockFile(fullPath, file, tmpPrefix, now))
|
|
61998
62276
|
try {
|
|
61999
|
-
|
|
62277
|
+
fs70.unlinkSync(fullPath);
|
|
62000
62278
|
} catch {
|
|
62001
62279
|
}
|
|
62002
62280
|
}
|
|
@@ -62007,11 +62285,11 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62007
62285
|
for (; !lockAcquired; ) {
|
|
62008
62286
|
let fd = null;
|
|
62009
62287
|
try {
|
|
62010
|
-
fd =
|
|
62288
|
+
fd = fs70.openSync(tmpLockPath, "wx", 384), fs70.writeFileSync(fd, lockPayload, "utf8"), fs70.fsyncSync(fd), fs70.closeSync(fd), fd = null, fs70.linkSync(tmpLockPath, lockPath), lockAcquired = !0;
|
|
62011
62289
|
} catch (err) {
|
|
62012
62290
|
if (err.code === "EEXIST") {
|
|
62013
62291
|
try {
|
|
62014
|
-
let stat25 =
|
|
62292
|
+
let stat25 = fs70.statSync(lockPath), existingLock = fs70.readFileSync(lockPath, "utf8"), trimmed = existingLock.trim(), ageMs = Date.now() - stat25.mtimeMs, shouldTakeover = !1;
|
|
62015
62293
|
if (trimmed.length === 0)
|
|
62016
62294
|
ageMs > 50 && (shouldTakeover = !0);
|
|
62017
62295
|
else {
|
|
@@ -62030,7 +62308,7 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62030
62308
|
}
|
|
62031
62309
|
if (shouldTakeover) {
|
|
62032
62310
|
try {
|
|
62033
|
-
|
|
62311
|
+
fs70.readFileSync(lockPath, "utf8") === existingLock && fs70.unlinkSync(lockPath);
|
|
62034
62312
|
} catch {
|
|
62035
62313
|
}
|
|
62036
62314
|
continue;
|
|
@@ -62048,13 +62326,13 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62048
62326
|
} finally {
|
|
62049
62327
|
if (fd !== null) {
|
|
62050
62328
|
try {
|
|
62051
|
-
|
|
62329
|
+
fs70.closeSync(fd);
|
|
62052
62330
|
} catch {
|
|
62053
62331
|
}
|
|
62054
62332
|
fd = null;
|
|
62055
62333
|
}
|
|
62056
62334
|
try {
|
|
62057
|
-
|
|
62335
|
+
fs70.existsSync(tmpLockPath) && fs70.unlinkSync(tmpLockPath);
|
|
62058
62336
|
} catch {
|
|
62059
62337
|
}
|
|
62060
62338
|
}
|
|
@@ -62064,7 +62342,7 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62064
62342
|
} finally {
|
|
62065
62343
|
if (lockAcquired)
|
|
62066
62344
|
try {
|
|
62067
|
-
|
|
62345
|
+
fs70.readFileSync(lockPath, "utf8") === lockPayload && fs70.unlinkSync(lockPath);
|
|
62068
62346
|
} catch {
|
|
62069
62347
|
}
|
|
62070
62348
|
}
|
|
@@ -62094,12 +62372,12 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62094
62372
|
atomicWriteJsonSync(this.filePath, serializedText, options), this.entries = validatedMap;
|
|
62095
62373
|
}
|
|
62096
62374
|
load() {
|
|
62097
|
-
if (!
|
|
62375
|
+
if (!fs70.existsSync(this.filePath)) {
|
|
62098
62376
|
this.entries.clear(), this.isCorrupted = !1, this.corruptionError = null;
|
|
62099
62377
|
return;
|
|
62100
62378
|
}
|
|
62101
62379
|
try {
|
|
62102
|
-
let raw =
|
|
62380
|
+
let raw = fs70.readFileSync(this.filePath, "utf8"), data;
|
|
62103
62381
|
try {
|
|
62104
62382
|
data = JSON.parse(raw);
|
|
62105
62383
|
} catch (parseErr) {
|
|
@@ -62144,7 +62422,7 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62144
62422
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
62145
62423
|
};
|
|
62146
62424
|
validateDeliveryJournalEntry(pendingEntry, this.filePath), this.withLock(() => {
|
|
62147
|
-
|
|
62425
|
+
fs70.existsSync(this.filePath) && this.load();
|
|
62148
62426
|
let existing = this.entries.get(deliveryId);
|
|
62149
62427
|
if (existing && existing.status === "SENT")
|
|
62150
62428
|
return;
|
|
@@ -62154,7 +62432,7 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62154
62432
|
}
|
|
62155
62433
|
claimDeliveryAdmission(deliveryId, summaryPayload, routing) {
|
|
62156
62434
|
return this.assertNotCorrupted(), this.withLock(() => {
|
|
62157
|
-
|
|
62435
|
+
fs70.existsSync(this.filePath) && this.load();
|
|
62158
62436
|
let existing = this.entries.get(deliveryId);
|
|
62159
62437
|
if (existing && existing.status === "SENT")
|
|
62160
62438
|
return { admitted: !1, alreadySent: !0, existingEntry: existing };
|
|
@@ -62180,7 +62458,7 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62180
62458
|
releaseDeliveryAdmission(deliveryId, claimToken) {
|
|
62181
62459
|
try {
|
|
62182
62460
|
this.withLock(() => {
|
|
62183
|
-
|
|
62461
|
+
fs70.existsSync(this.filePath) && this.load();
|
|
62184
62462
|
let existing = this.entries.get(deliveryId);
|
|
62185
62463
|
if (existing && existing.status !== "SENT") {
|
|
62186
62464
|
if (existing.claimToken && (!claimToken || typeof claimToken != "string" || claimToken.trim().length === 0 || existing.claimToken !== claimToken))
|
|
@@ -62199,7 +62477,7 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62199
62477
|
if (typeof claimTokenOrOptions == "string" ? (claimToken = claimTokenOrOptions, options = maybeOptions || {}) : claimTokenOrOptions && typeof claimTokenOrOptions == "object" && (options = claimTokenOrOptions), !receipt2 || typeof receipt2 != "object" || receipt2.emitted !== !0 || typeof receipt2.eventId != "string" || receipt2.eventId.trim().length === 0)
|
|
62200
62478
|
throw new Error("Invalid ShellEventEmitResult receipt: " + JSON.stringify(receipt2));
|
|
62201
62479
|
this.withLock(() => {
|
|
62202
|
-
|
|
62480
|
+
fs70.existsSync(this.filePath) && this.load();
|
|
62203
62481
|
let entry5 = this.entries.get(deliveryId);
|
|
62204
62482
|
if (!entry5)
|
|
62205
62483
|
throw new Error(`Delivery entry not found in journal: ${deliveryId}`);
|
|
@@ -62222,13 +62500,13 @@ var FileDurableTeamDeliveryJournal = class {
|
|
|
62222
62500
|
});
|
|
62223
62501
|
}
|
|
62224
62502
|
getEntry(deliveryId) {
|
|
62225
|
-
return
|
|
62503
|
+
return fs70.existsSync(this.filePath) && this.load(), this.entries.get(deliveryId) || null;
|
|
62226
62504
|
}
|
|
62227
62505
|
getPendingEntries() {
|
|
62228
|
-
return
|
|
62506
|
+
return fs70.existsSync(this.filePath) && this.load(), Array.from(this.entries.values()).filter((e) => e.status === "PENDING");
|
|
62229
62507
|
}
|
|
62230
62508
|
getAllEntries() {
|
|
62231
|
-
return
|
|
62509
|
+
return fs70.existsSync(this.filePath) && this.load(), Array.from(this.entries.values());
|
|
62232
62510
|
}
|
|
62233
62511
|
}, UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
62234
62512
|
function wireSnapshotMergeObserver(existingArgs = {}) {
|
|
@@ -62286,7 +62564,7 @@ async function emitTeamCompletionSummary(options) {
|
|
|
62286
62564
|
store,
|
|
62287
62565
|
leEmitFn
|
|
62288
62566
|
} = options;
|
|
62289
|
-
|
|
62567
|
+
fs70.existsSync(store.filePath) && store.load();
|
|
62290
62568
|
let existing = store.getEntry(deliveryId);
|
|
62291
62569
|
if (existing && existing.status === "SENT") {
|
|
62292
62570
|
if (leadTaskId && existing.leadTaskId && leadTaskId !== existing.leadTaskId)
|
|
@@ -62408,11 +62686,11 @@ init_workspace_authority();
|
|
|
62408
62686
|
init_anchored_fs();
|
|
62409
62687
|
|
|
62410
62688
|
// src/local-executor/merge-train.ts
|
|
62411
|
-
var crypto26 = __toESM(require("node:crypto")),
|
|
62689
|
+
var crypto26 = __toESM(require("node:crypto")), fs72 = __toESM(require("node:fs/promises")), os40 = __toESM(require("node:os")), path86 = __toESM(require("node:path"));
|
|
62412
62690
|
init_logger2();
|
|
62413
62691
|
|
|
62414
62692
|
// src/local-executor/worktree-merge.ts
|
|
62415
|
-
var import_node_child_process16 = require("node:child_process"), crypto25 = __toESM(require("node:crypto")),
|
|
62693
|
+
var import_node_child_process16 = require("node:child_process"), crypto25 = __toESM(require("node:crypto")), fs71 = __toESM(require("node:fs/promises")), os39 = __toESM(require("node:os")), path85 = __toESM(require("node:path")), import_node_util = require("node:util");
|
|
62416
62694
|
|
|
62417
62695
|
// src/local-executor/git-lock-retry.ts
|
|
62418
62696
|
var realSleep = (ms) => new Promise((resolve35) => setTimeout(resolve35, ms));
|
|
@@ -62853,7 +63131,7 @@ async function captureUntrackedTree(repoDir, taskGroupId, repoId) {
|
|
|
62853
63131
|
// #65 — race an in-flight revise's ref write
|
|
62854
63132
|
}), tree;
|
|
62855
63133
|
} finally {
|
|
62856
|
-
await
|
|
63134
|
+
await fs71.rm(tmpIndex, { force: !0 }).catch(() => {
|
|
62857
63135
|
});
|
|
62858
63136
|
}
|
|
62859
63137
|
}
|
|
@@ -62954,7 +63232,7 @@ async function snapshotWorktreeTreeSeeded(repoDir, seedRef) {
|
|
|
62954
63232
|
let { stdout } = await gitWithIndex(repoDir, tmpIndex, ["write-tree"]);
|
|
62955
63233
|
return stdout.trim();
|
|
62956
63234
|
} finally {
|
|
62957
|
-
await
|
|
63235
|
+
await fs71.rm(tmpIndex, { force: !0 }).catch(() => {
|
|
62958
63236
|
});
|
|
62959
63237
|
}
|
|
62960
63238
|
}
|
|
@@ -62995,7 +63273,7 @@ async function normalizingRawDigest(repoDir, paths) {
|
|
|
62995
63273
|
for (let p of normalizing) {
|
|
62996
63274
|
hash3.update(`${p.length}:${p}\0`);
|
|
62997
63275
|
try {
|
|
62998
|
-
let bytes = await
|
|
63276
|
+
let bytes = await fs71.readFile(path85.join(repoDir, p));
|
|
62999
63277
|
hash3.update(`${bytes.length}:`), hash3.update(bytes);
|
|
63000
63278
|
} catch {
|
|
63001
63279
|
hash3.update("ABSENT");
|
|
@@ -63057,7 +63335,7 @@ async function reconstructPostResetAnchor(repoDir, targetRef, entryWorktreeTree,
|
|
|
63057
63335
|
});
|
|
63058
63336
|
return;
|
|
63059
63337
|
} finally {
|
|
63060
|
-
await
|
|
63338
|
+
await fs71.rm(tmpIndex, { force: !0 }).catch(() => {
|
|
63061
63339
|
});
|
|
63062
63340
|
}
|
|
63063
63341
|
}
|
|
@@ -63089,7 +63367,7 @@ async function reconstructDirtyUncommittedPostPromoteTree(repoDir, integrationTr
|
|
|
63089
63367
|
});
|
|
63090
63368
|
return;
|
|
63091
63369
|
} finally {
|
|
63092
|
-
await
|
|
63370
|
+
await fs71.rm(tmpIndex, { force: !0 }).catch(() => {
|
|
63093
63371
|
});
|
|
63094
63372
|
}
|
|
63095
63373
|
}
|
|
@@ -63956,23 +64234,23 @@ async function catBlobRaw(repoDir, oid) {
|
|
|
63956
64234
|
}
|
|
63957
64235
|
async function hashObjectW(repoDir, bytes) {
|
|
63958
64236
|
let tmp = path85.join(os39.tmpdir(), `cp14-w3-blob-${crypto25.randomBytes(8).toString("hex")}`);
|
|
63959
|
-
await
|
|
64237
|
+
await fs71.writeFile(tmp, bytes);
|
|
63960
64238
|
try {
|
|
63961
64239
|
return (await git(repoDir, ["hash-object", "-w", "--no-filters", "--", tmp], { hermetic: !0 })).stdout.trim();
|
|
63962
64240
|
} finally {
|
|
63963
|
-
await
|
|
64241
|
+
await fs71.rm(tmp, { force: !0 });
|
|
63964
64242
|
}
|
|
63965
64243
|
}
|
|
63966
64244
|
async function diff3MergeBlobs(repoDir, oursOid, baseOid, theirsOid) {
|
|
63967
|
-
let dir = await
|
|
64245
|
+
let dir = await fs71.mkdtemp(path85.join(os39.tmpdir(), "cp14-w3-mf-"));
|
|
63968
64246
|
try {
|
|
63969
64247
|
let oursF = path85.join(dir, "ours"), baseF = path85.join(dir, "base"), theirsF = path85.join(dir, "theirs");
|
|
63970
|
-
return await
|
|
64248
|
+
return await fs71.writeFile(oursF, await catBlobRaw(repoDir, oursOid)), await fs71.writeFile(baseF, baseOid ? await catBlobRaw(repoDir, baseOid) : Buffer.alloc(0)), await fs71.writeFile(theirsF, await catBlobRaw(repoDir, theirsOid)), (await git(repoDir, ["merge-file", "-p", "--diff3", oursF, baseF, theirsF], {
|
|
63971
64249
|
allowFail: !0,
|
|
63972
64250
|
hermetic: !0
|
|
63973
64251
|
})).stdout;
|
|
63974
64252
|
} finally {
|
|
63975
|
-
await
|
|
64253
|
+
await fs71.rm(dir, { recursive: !0, force: !0 });
|
|
63976
64254
|
}
|
|
63977
64255
|
}
|
|
63978
64256
|
async function extractThreeWayConflict(repoDir, oursCommit, theirsCommit, p) {
|
|
@@ -64019,7 +64297,7 @@ async function assembleResolvedTree(repoDir, conflictedTree, resolved) {
|
|
|
64019
64297
|
}
|
|
64020
64298
|
return await runIdx(["write-tree"]);
|
|
64021
64299
|
} finally {
|
|
64022
|
-
await
|
|
64300
|
+
await fs71.rm(idx, { force: !0 });
|
|
64023
64301
|
}
|
|
64024
64302
|
}
|
|
64025
64303
|
async function commitTreeOffBranch(repoDir, tree, parents, message2, opts = {}) {
|
|
@@ -66306,7 +66584,7 @@ async function runTier1OnIntegrationWorktree(repoDir, integrationTip, tracks, co
|
|
|
66306
66584
|
repoDir,
|
|
66307
66585
|
attributePathCount: treeDanger.length
|
|
66308
66586
|
}), { status: "attribute_halt", attributePaths: treeDanger };
|
|
66309
|
-
let wtDir = await
|
|
66587
|
+
let wtDir = await fs72.mkdtemp(path86.join(os40.tmpdir(), "cv-tier1-")), worktreeAdded = !1;
|
|
66310
66588
|
try {
|
|
66311
66589
|
let add = await pinnedGit(
|
|
66312
66590
|
repoDir,
|
|
@@ -66345,10 +66623,10 @@ async function runTier1OnIntegrationWorktree(repoDir, integrationTip, tracks, co
|
|
|
66345
66623
|
trackIndex: -1,
|
|
66346
66624
|
// a union run — not a single track.
|
|
66347
66625
|
runShell: runShellCommand,
|
|
66348
|
-
lstat:
|
|
66349
|
-
realpath:
|
|
66350
|
-
stat:
|
|
66351
|
-
readFile: (p) =>
|
|
66626
|
+
lstat: fs72.lstat,
|
|
66627
|
+
realpath: fs72.realpath,
|
|
66628
|
+
stat: fs72.stat,
|
|
66629
|
+
readFile: (p) => fs72.readFile(p, "utf8"),
|
|
66352
66630
|
timeoutMs
|
|
66353
66631
|
});
|
|
66354
66632
|
if (declared.outcome === "fail")
|
|
@@ -66360,7 +66638,7 @@ async function runTier1OnIntegrationWorktree(repoDir, integrationTip, tracks, co
|
|
|
66360
66638
|
}
|
|
66361
66639
|
return { status: "pass" };
|
|
66362
66640
|
} finally {
|
|
66363
|
-
worktreeAdded && await pinnedGit(repoDir, ["worktree", "remove", "--force", wtDir], { allowFail: !0 }), await
|
|
66641
|
+
worktreeAdded && await pinnedGit(repoDir, ["worktree", "remove", "--force", wtDir], { allowFail: !0 }), await fs72.rm(wtDir, { recursive: !0, force: !0 }).catch(() => {
|
|
66364
66642
|
}), worktreeAdded && await pinnedGit(repoDir, ["worktree", "prune"], { allowFail: !0 });
|
|
66365
66643
|
}
|
|
66366
66644
|
}
|
|
@@ -66612,7 +66890,7 @@ async function detectGraftsHalt(repoDir, integrationTip) {
|
|
|
66612
66890
|
if (graftsPath.length === 0) return null;
|
|
66613
66891
|
let resolved = path86.isAbsolute(graftsPath) ? graftsPath : path86.join(repoDir, graftsPath), content;
|
|
66614
66892
|
try {
|
|
66615
|
-
content = await
|
|
66893
|
+
content = await fs72.readFile(resolved, "utf8");
|
|
66616
66894
|
} catch (err) {
|
|
66617
66895
|
return err?.code === "ENOENT" ? null : { status: "grafts_halt", graftsPath: resolved, integrationTip };
|
|
66618
66896
|
}
|
|
@@ -66632,7 +66910,7 @@ async function detectShallowHalt(repoDir, integrationTip) {
|
|
|
66632
66910
|
return isShallow.code === 0 && isShallow.stdout.trim() === "false" ? null : { status: "shallow_halt", shallowPath: resolved, integrationTip };
|
|
66633
66911
|
let present;
|
|
66634
66912
|
try {
|
|
66635
|
-
await
|
|
66913
|
+
await fs72.access(resolved), present = !0;
|
|
66636
66914
|
} catch (err) {
|
|
66637
66915
|
if (err?.code === "ENOENT") return null;
|
|
66638
66916
|
present = !0;
|
|
@@ -67152,7 +67430,7 @@ async function reconstructResolutionSetEntry(repoDir, commit, setHash, repoId, m
|
|
|
67152
67430
|
}
|
|
67153
67431
|
|
|
67154
67432
|
// src/local-executor/conflict-resolution-durable-store.ts
|
|
67155
|
-
var import_node_crypto50 = require("node:crypto"),
|
|
67433
|
+
var import_node_crypto50 = require("node:crypto"), import_node_fs39 = require("node:fs"), fs73 = __toESM(require("node:fs/promises")), os41 = __toESM(require("node:os")), path87 = __toESM(require("node:path")), DIR_MODE5 = 448, FILE_MODE7 = 384, RECORDS_FILE = "records.json", AGENTIC_RECORDS_FILE = "agentic-records.json", PENDING_FILE = "pending-attempts.json", INDEX_FILE = "resolution-sets.json";
|
|
67156
67434
|
function defaultRoot() {
|
|
67157
67435
|
return path87.join(os41.homedir(), ".codevibe", "conflict-resolutions");
|
|
67158
67436
|
}
|
|
@@ -67174,7 +67452,7 @@ var SafeGroupDir = class {
|
|
|
67174
67452
|
for (let i = -1; i < segments.length; i++) {
|
|
67175
67453
|
i >= 0 && (cur = path87.join(cur, segments[i]));
|
|
67176
67454
|
try {
|
|
67177
|
-
if ((await
|
|
67455
|
+
if ((await fs73.lstat(cur)).isSymbolicLink())
|
|
67178
67456
|
throw new Error("ConflictResolutionDurableStore: refusing a symlinked path component");
|
|
67179
67457
|
} catch (err) {
|
|
67180
67458
|
if (err.code === "ENOENT") return;
|
|
@@ -67186,7 +67464,7 @@ var SafeGroupDir = class {
|
|
|
67186
67464
|
let p = path87.join(this.dir(), file);
|
|
67187
67465
|
await this.assertNoSymlinkComponents(p);
|
|
67188
67466
|
try {
|
|
67189
|
-
let raw = await
|
|
67467
|
+
let raw = await fs73.readFile(p, "utf8");
|
|
67190
67468
|
return JSON.parse(raw);
|
|
67191
67469
|
} catch (err) {
|
|
67192
67470
|
if (err.code === "ENOENT") return null;
|
|
@@ -67195,19 +67473,19 @@ var SafeGroupDir = class {
|
|
|
67195
67473
|
}
|
|
67196
67474
|
async writeJsonAtomic(file, value) {
|
|
67197
67475
|
let dir = this.dir(), p = path87.join(dir, file);
|
|
67198
|
-
await this.assertNoSymlinkComponents(p), await
|
|
67476
|
+
await this.assertNoSymlinkComponents(p), await fs73.mkdir(dir, { recursive: !0, mode: DIR_MODE5 });
|
|
67199
67477
|
let data = JSON.stringify(value), tmp = `${p}.tmp.${process.pid}.${(0, import_node_crypto50.randomBytes)(6).toString("hex")}`, fh;
|
|
67200
67478
|
try {
|
|
67201
|
-
fh = await
|
|
67479
|
+
fh = await fs73.open(tmp, import_node_fs39.constants.O_WRONLY | import_node_fs39.constants.O_CREAT | import_node_fs39.constants.O_EXCL, FILE_MODE7), await fh.writeFile(data, "utf8"), await fh.sync();
|
|
67202
67480
|
} finally {
|
|
67203
67481
|
await fh?.close().catch(() => {
|
|
67204
67482
|
});
|
|
67205
67483
|
}
|
|
67206
|
-
await
|
|
67207
|
-
}), await
|
|
67484
|
+
await fs73.chmod(tmp, FILE_MODE7).catch(() => {
|
|
67485
|
+
}), await fs73.rename(tmp, p);
|
|
67208
67486
|
let dirFh;
|
|
67209
67487
|
try {
|
|
67210
|
-
dirFh = await
|
|
67488
|
+
dirFh = await fs73.open(dir, import_node_fs39.constants.O_RDONLY), await dirFh.sync();
|
|
67211
67489
|
} catch {
|
|
67212
67490
|
} finally {
|
|
67213
67491
|
await dirFh?.close().catch(() => {
|
|
@@ -67347,7 +67625,7 @@ function listShadowCleanupResidueWithRetry(taskIds, env = {}) {
|
|
|
67347
67625
|
init_process_identity();
|
|
67348
67626
|
|
|
67349
67627
|
// src/local-executor/merge-journal-store.ts
|
|
67350
|
-
var crypto27 = __toESM(require("node:crypto")),
|
|
67628
|
+
var crypto27 = __toESM(require("node:crypto")), fs74 = __toESM(require("node:fs/promises")), import_node_fs40 = require("node:fs"), os42 = __toESM(require("node:os")), path88 = __toESM(require("node:path"));
|
|
67351
67629
|
init_logger2();
|
|
67352
67630
|
var DIR_MODE6 = 448, FILE_MODE8 = 384, MERGE_JOURNAL_VERSION = 1, MERGE_JOURNAL_FILE = "merge.json";
|
|
67353
67631
|
function defaultRoot2() {
|
|
@@ -67381,7 +67659,7 @@ var MergeJournalStore = class {
|
|
|
67381
67659
|
return seg;
|
|
67382
67660
|
}
|
|
67383
67661
|
async mkdirSecure(dir) {
|
|
67384
|
-
await
|
|
67662
|
+
await fs74.mkdir(dir, { recursive: !0, mode: DIR_MODE6 });
|
|
67385
67663
|
}
|
|
67386
67664
|
/**
|
|
67387
67665
|
* Refuse to operate under a path whose any in-`rootDir` component is a symlink
|
|
@@ -67397,7 +67675,7 @@ var MergeJournalStore = class {
|
|
|
67397
67675
|
i >= 0 && (cur = path88.join(cur, segments[i]));
|
|
67398
67676
|
let st;
|
|
67399
67677
|
try {
|
|
67400
|
-
st = await
|
|
67678
|
+
st = await fs74.lstat(cur);
|
|
67401
67679
|
} catch (err) {
|
|
67402
67680
|
if (err.code === "ENOENT") return;
|
|
67403
67681
|
throw err;
|
|
@@ -67412,20 +67690,20 @@ var MergeJournalStore = class {
|
|
|
67412
67690
|
await this.assertNoSymlinkComponents(finalPath), await this.mkdirSecure(dir);
|
|
67413
67691
|
let tmp = `${finalPath}.tmp.${process.pid}.${crypto27.randomBytes(6).toString("hex")}`, fh;
|
|
67414
67692
|
try {
|
|
67415
|
-
fh = await
|
|
67693
|
+
fh = await fs74.open(
|
|
67416
67694
|
tmp,
|
|
67417
|
-
|
|
67695
|
+
import_node_fs40.constants.O_WRONLY | import_node_fs40.constants.O_CREAT | import_node_fs40.constants.O_EXCL,
|
|
67418
67696
|
FILE_MODE8
|
|
67419
67697
|
), await fh.writeFile(data, "utf8"), await fh.sync();
|
|
67420
67698
|
} finally {
|
|
67421
67699
|
await fh?.close().catch(() => {
|
|
67422
67700
|
});
|
|
67423
67701
|
}
|
|
67424
|
-
await
|
|
67425
|
-
}), await
|
|
67702
|
+
await fs74.chmod(tmp, FILE_MODE8).catch(() => {
|
|
67703
|
+
}), await fs74.rename(tmp, finalPath);
|
|
67426
67704
|
let dirFh;
|
|
67427
67705
|
try {
|
|
67428
|
-
dirFh = await
|
|
67706
|
+
dirFh = await fs74.open(dir, import_node_fs40.constants.O_RDONLY), await dirFh.sync();
|
|
67429
67707
|
} catch {
|
|
67430
67708
|
} finally {
|
|
67431
67709
|
await dirFh?.close().catch(() => {
|
|
@@ -67435,7 +67713,7 @@ var MergeJournalStore = class {
|
|
|
67435
67713
|
async readJson(p) {
|
|
67436
67714
|
await this.assertNoSymlinkComponents(p);
|
|
67437
67715
|
try {
|
|
67438
|
-
let raw = await
|
|
67716
|
+
let raw = await fs74.readFile(p, "utf8");
|
|
67439
67717
|
return JSON.parse(raw);
|
|
67440
67718
|
} catch (err) {
|
|
67441
67719
|
if (err.code === "ENOENT") return null;
|
|
@@ -67707,7 +67985,7 @@ var MergeJournalStore = class {
|
|
|
67707
67985
|
}
|
|
67708
67986
|
/** Delete the journal record for `(group, repo)` (terminal cleanup / GC). */
|
|
67709
67987
|
async deleteRecord(taskGroupId, repoId) {
|
|
67710
|
-
await
|
|
67988
|
+
await fs74.rm(this.repoDir(taskGroupId, repoId), { recursive: !0, force: !0 }).catch(() => {
|
|
67711
67989
|
});
|
|
67712
67990
|
}
|
|
67713
67991
|
};
|
|
@@ -67728,7 +68006,7 @@ function tracksEqual(a, b) {
|
|
|
67728
68006
|
}
|
|
67729
68007
|
|
|
67730
68008
|
// src/local-executor/promote-wal-store.ts
|
|
67731
|
-
var crypto28 = __toESM(require("node:crypto")),
|
|
68009
|
+
var crypto28 = __toESM(require("node:crypto")), fs75 = __toESM(require("node:fs/promises")), import_node_fs41 = require("node:fs"), os43 = __toESM(require("node:os")), path89 = __toESM(require("node:path"));
|
|
67732
68010
|
init_logger2();
|
|
67733
68011
|
var DIR_MODE7 = 448, FILE_MODE9 = 384, PROMOTE_WAL_VERSION = 1, PROMOTE_WAL_FILE = "promote.json";
|
|
67734
68012
|
function defaultRoot3() {
|
|
@@ -67763,7 +68041,7 @@ var PromoteWalStore = class {
|
|
|
67763
68041
|
return seg;
|
|
67764
68042
|
}
|
|
67765
68043
|
async mkdirSecure(dir) {
|
|
67766
|
-
await
|
|
68044
|
+
await fs75.mkdir(dir, { recursive: !0, mode: DIR_MODE7 });
|
|
67767
68045
|
}
|
|
67768
68046
|
/**
|
|
67769
68047
|
* Refuse to operate under a path whose any in-`rootDir` component is a symlink
|
|
@@ -67779,7 +68057,7 @@ var PromoteWalStore = class {
|
|
|
67779
68057
|
i >= 0 && (cur = path89.join(cur, segments[i]));
|
|
67780
68058
|
let st;
|
|
67781
68059
|
try {
|
|
67782
|
-
st = await
|
|
68060
|
+
st = await fs75.lstat(cur);
|
|
67783
68061
|
} catch (err) {
|
|
67784
68062
|
if (err.code === "ENOENT") return;
|
|
67785
68063
|
throw err;
|
|
@@ -67794,20 +68072,20 @@ var PromoteWalStore = class {
|
|
|
67794
68072
|
await this.assertNoSymlinkComponents(finalPath), await this.mkdirSecure(dir);
|
|
67795
68073
|
let tmp = `${finalPath}.tmp.${process.pid}.${crypto28.randomBytes(6).toString("hex")}`, fh;
|
|
67796
68074
|
try {
|
|
67797
|
-
fh = await
|
|
68075
|
+
fh = await fs75.open(
|
|
67798
68076
|
tmp,
|
|
67799
|
-
|
|
68077
|
+
import_node_fs41.constants.O_WRONLY | import_node_fs41.constants.O_CREAT | import_node_fs41.constants.O_EXCL,
|
|
67800
68078
|
FILE_MODE9
|
|
67801
68079
|
), await fh.writeFile(data, "utf8"), await fh.sync();
|
|
67802
68080
|
} finally {
|
|
67803
68081
|
await fh?.close().catch(() => {
|
|
67804
68082
|
});
|
|
67805
68083
|
}
|
|
67806
|
-
await
|
|
67807
|
-
}), await
|
|
68084
|
+
await fs75.chmod(tmp, FILE_MODE9).catch(() => {
|
|
68085
|
+
}), await fs75.rename(tmp, finalPath);
|
|
67808
68086
|
let dirFh;
|
|
67809
68087
|
try {
|
|
67810
|
-
dirFh = await
|
|
68088
|
+
dirFh = await fs75.open(dir, import_node_fs41.constants.O_RDONLY), await dirFh.sync();
|
|
67811
68089
|
} catch {
|
|
67812
68090
|
} finally {
|
|
67813
68091
|
await dirFh?.close().catch(() => {
|
|
@@ -67817,7 +68095,7 @@ var PromoteWalStore = class {
|
|
|
67817
68095
|
async readJson(p) {
|
|
67818
68096
|
await this.assertNoSymlinkComponents(p);
|
|
67819
68097
|
try {
|
|
67820
|
-
let raw = await
|
|
68098
|
+
let raw = await fs75.readFile(p, "utf8");
|
|
67821
68099
|
return JSON.parse(raw);
|
|
67822
68100
|
} catch (err) {
|
|
67823
68101
|
if (err.code === "ENOENT") return null;
|
|
@@ -67979,7 +68257,7 @@ var PromoteWalStore = class {
|
|
|
67979
68257
|
}
|
|
67980
68258
|
/** Delete the WAL record for `(group, repo)` (terminal cleanup / GC). */
|
|
67981
68259
|
async deleteRecord(taskGroupId, repoId) {
|
|
67982
|
-
await
|
|
68260
|
+
await fs75.rm(this.repoDir(taskGroupId, repoId), { recursive: !0, force: !0 }).catch(() => {
|
|
67983
68261
|
});
|
|
67984
68262
|
}
|
|
67985
68263
|
/**
|
|
@@ -67990,7 +68268,7 @@ var PromoteWalStore = class {
|
|
|
67990
68268
|
async listStartedNotCommitted() {
|
|
67991
68269
|
let out = [], groups;
|
|
67992
68270
|
try {
|
|
67993
|
-
groups = (await
|
|
68271
|
+
groups = (await fs75.readdir(this.rootDir, { withFileTypes: !0 })).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
67994
68272
|
} catch (err) {
|
|
67995
68273
|
if (err.code === "ENOENT") return out;
|
|
67996
68274
|
throw err;
|
|
@@ -67998,7 +68276,7 @@ var PromoteWalStore = class {
|
|
|
67998
68276
|
for (let gid of groups) {
|
|
67999
68277
|
let repos;
|
|
68000
68278
|
try {
|
|
68001
|
-
repos = (await
|
|
68279
|
+
repos = (await fs75.readdir(path89.join(this.rootDir, gid), { withFileTypes: !0 })).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
68002
68280
|
} catch {
|
|
68003
68281
|
continue;
|
|
68004
68282
|
}
|
|
@@ -68480,7 +68758,7 @@ var LocalExecutorImpl = class {
|
|
|
68480
68758
|
combinedOnExit
|
|
68481
68759
|
);
|
|
68482
68760
|
} catch (spawnErr) {
|
|
68483
|
-
throw capture !== void 0 && await
|
|
68761
|
+
throw capture !== void 0 && await import_node_fs42.promises.rm(path90.dirname(capture.hostPath), { recursive: !0, force: !0 }).catch(() => {
|
|
68484
68762
|
}), spawnErr;
|
|
68485
68763
|
}
|
|
68486
68764
|
return capture !== void 0 && (handle.lastMessageCapturePath = capture.hostPath), advisoryAdmission && this.bindAdvisorySpawn(advisoryAdmission, handle), handle;
|
|
@@ -68659,7 +68937,7 @@ var LocalExecutorImpl = class {
|
|
|
68659
68937
|
), { args, substrateEngaged: !1 };
|
|
68660
68938
|
}
|
|
68661
68939
|
let isWebActive = args.webTurnActive === !0, readOnlyView = args.implementorMode === "plan" || isPlanModeImplementorArgv(agentKind, args.argv), captureDir = readOnlyView && agentKind === "CODEX" && args.argv.includes("--output-last-message") ? await this.createCaptureDir(effectiveTaskId) : null, removeCaptureDir = async () => {
|
|
68662
|
-
captureDir !== null && await
|
|
68940
|
+
captureDir !== null && await import_node_fs42.promises.rm(captureDir, { recursive: !0, force: !0 }).catch(() => {
|
|
68663
68941
|
});
|
|
68664
68942
|
}, result;
|
|
68665
68943
|
try {
|
|
@@ -68774,7 +69052,7 @@ var LocalExecutorImpl = class {
|
|
|
68774
69052
|
viewParent: await config.viewParent(),
|
|
68775
69053
|
argvFor: (view) => buildImplementorArgv(agentKind, mode, view).argv,
|
|
68776
69054
|
spawn: (spawnArgs) => this.spawnImplementor(spawnArgs),
|
|
68777
|
-
...this.taskFolder ? { removeTaskFolder: (taskId) =>
|
|
69055
|
+
...this.taskFolder ? { removeTaskFolder: (taskId) => import_node_fs42.promises.rm(this.taskFolder(taskId), { recursive: !0, force: !0 }) } : {}
|
|
68778
69056
|
}), result = {
|
|
68779
69057
|
key,
|
|
68780
69058
|
agentKind,
|
|
@@ -68803,11 +69081,11 @@ var LocalExecutorImpl = class {
|
|
|
68803
69081
|
*/
|
|
68804
69082
|
async createCaptureDir(taskId) {
|
|
68805
69083
|
if (this.taskFolder === void 0)
|
|
68806
|
-
return
|
|
69084
|
+
return import_node_fs42.promises.realpath(await import_node_fs42.promises.mkdtemp(path90.join(os44.tmpdir(), "codevibe-capture-")));
|
|
68807
69085
|
let parent = path90.join(this.taskFolder(taskId), "capture");
|
|
68808
|
-
await
|
|
69086
|
+
await import_node_fs42.promises.mkdir(parent, { recursive: !0, mode: 448 });
|
|
68809
69087
|
let dir = path90.join(parent, (0, import_node_crypto51.randomUUID)());
|
|
68810
|
-
return await
|
|
69088
|
+
return await import_node_fs42.promises.mkdir(dir, { mode: 448 }), import_node_fs42.promises.realpath(dir);
|
|
68811
69089
|
}
|
|
68812
69090
|
/**
|
|
68813
69091
|
* CP-7 PART F — surface the PROMINENT reduced-trust badge (§6 Q2). The moat
|
|
@@ -70564,7 +70842,7 @@ var LocalExecutorImpl = class {
|
|
|
70564
70842
|
init_env_scrub();
|
|
70565
70843
|
|
|
70566
70844
|
// src/local-executor/cp7-audit-writer.ts
|
|
70567
|
-
var
|
|
70845
|
+
var import_node_fs43 = require("node:fs"), import_node_crypto52 = require("node:crypto"), import_uuid13 = require("uuid");
|
|
70568
70846
|
init_logger2();
|
|
70569
70847
|
var CANONICAL_FIELD_ORDER = [
|
|
70570
70848
|
"entry_id",
|
|
@@ -70721,19 +70999,19 @@ var Cp7AuditWriter = class {
|
|
|
70721
70999
|
prev_hash: this.lastHash,
|
|
70722
71000
|
event_dedup_key: eventDedupKey
|
|
70723
71001
|
}, line = canonicalEntryBytes(entry5) + `
|
|
70724
|
-
`, fd = (0,
|
|
71002
|
+
`, fd = (0, import_node_fs43.openSync)(
|
|
70725
71003
|
this.auditPath,
|
|
70726
|
-
|
|
71004
|
+
import_node_fs43.constants.O_CREAT | import_node_fs43.constants.O_APPEND | import_node_fs43.constants.O_WRONLY | import_node_fs43.constants.O_NOFOLLOW,
|
|
70727
71005
|
384
|
|
70728
71006
|
);
|
|
70729
71007
|
try {
|
|
70730
|
-
let st = (0,
|
|
71008
|
+
let st = (0, import_node_fs43.fstatSync)(fd);
|
|
70731
71009
|
if (!st.isFile())
|
|
70732
71010
|
throw new Error(
|
|
70733
71011
|
`Cp7AuditWriter: audit target "${this.auditPath}" is not a regular file (mode=0o${(st.mode & 61440).toString(8)}) \u2014 refusing to write`
|
|
70734
71012
|
);
|
|
70735
71013
|
} catch (statErr) {
|
|
70736
|
-
throw (0,
|
|
71014
|
+
throw (0, import_node_fs43.closeSync)(fd), statErr;
|
|
70737
71015
|
}
|
|
70738
71016
|
} catch (err) {
|
|
70739
71017
|
let reason = err instanceof Error ? err.message : String(err);
|
|
@@ -70747,18 +71025,18 @@ var Cp7AuditWriter = class {
|
|
|
70747
71025
|
try {
|
|
70748
71026
|
let off = 0;
|
|
70749
71027
|
for (; off < buf.length; ) {
|
|
70750
|
-
let n = (0,
|
|
71028
|
+
let n = (0, import_node_fs43.writeSync)(fd, buf, off, buf.length - off);
|
|
70751
71029
|
if (n === 0)
|
|
70752
71030
|
throw new Error(
|
|
70753
71031
|
`Cp7AuditWriter: writeSync made no progress (0 bytes) at offset ${off}/${buf.length} \u2014 refusing to spin on a stalled write`
|
|
70754
71032
|
);
|
|
70755
71033
|
off += n;
|
|
70756
71034
|
}
|
|
70757
|
-
(0,
|
|
71035
|
+
(0, import_node_fs43.fsyncSync)(fd), (0, import_node_fs43.closeSync)(fd);
|
|
70758
71036
|
} catch (err) {
|
|
70759
71037
|
let reason = err instanceof Error ? err.message : String(err);
|
|
70760
71038
|
try {
|
|
70761
|
-
(0,
|
|
71039
|
+
(0, import_node_fs43.closeSync)(fd);
|
|
70762
71040
|
} catch {
|
|
70763
71041
|
}
|
|
70764
71042
|
return this.poisoned = reason, logger.warn(
|
|
@@ -70779,7 +71057,7 @@ var Cp7AuditWriter = class {
|
|
|
70779
71057
|
readLastHashFromFile() {
|
|
70780
71058
|
let content;
|
|
70781
71059
|
try {
|
|
70782
|
-
content = (0,
|
|
71060
|
+
content = (0, import_node_fs43.readFileSync)(this.auditPath, "utf8");
|
|
70783
71061
|
} catch (e) {
|
|
70784
71062
|
if (e.code === "ENOENT") return null;
|
|
70785
71063
|
throw e;
|
|
@@ -74528,7 +74806,7 @@ function withImplementorCredentialPreflight(engage, store) {
|
|
|
74528
74806
|
init_bwrap();
|
|
74529
74807
|
|
|
74530
74808
|
// src/substrate/sandbox-exec.ts
|
|
74531
|
-
var
|
|
74809
|
+
var import_node_fs46 = require("node:fs"), fsSync10 = __toESM(require("node:fs")), os48 = __toESM(require("node:os")), path100 = __toESM(require("node:path"));
|
|
74532
74810
|
init_command_runner();
|
|
74533
74811
|
var import_node_path6 = require("node:path");
|
|
74534
74812
|
init_errors();
|
|
@@ -74536,7 +74814,7 @@ init_workspace_authority();
|
|
|
74536
74814
|
init_grant_rule();
|
|
74537
74815
|
|
|
74538
74816
|
// src/substrate/seatbelt-grants.ts
|
|
74539
|
-
var
|
|
74817
|
+
var fs80 = __toESM(require("node:fs")), path99 = __toESM(require("node:path"));
|
|
74540
74818
|
init_grant_rule();
|
|
74541
74819
|
var esc = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
74542
74820
|
function seatbeltRegexEscape(literal) {
|
|
@@ -74591,7 +74869,7 @@ function hideBlockLines(opts) {
|
|
|
74591
74869
|
for (let p of [...parents].sort()) lines.push(`(allow file-read-metadata (literal "${esc(p)}"))`);
|
|
74592
74870
|
return lines;
|
|
74593
74871
|
}
|
|
74594
|
-
function hasCaseVariantSibling(p, readdir21 = (d) =>
|
|
74872
|
+
function hasCaseVariantSibling(p, readdir21 = (d) => fs80.readdirSync(d)) {
|
|
74595
74873
|
let cur = path99.resolve(p);
|
|
74596
74874
|
for (; cur !== path99.dirname(cur); ) {
|
|
74597
74875
|
let parent = path99.dirname(cur), name = path99.basename(cur), siblings;
|
|
@@ -74605,7 +74883,7 @@ function hasCaseVariantSibling(p, readdir21 = (d) => fs79.readdirSync(d)) {
|
|
|
74605
74883
|
}
|
|
74606
74884
|
return !1;
|
|
74607
74885
|
}
|
|
74608
|
-
function ownFolderCaseRefusal(p, readdir21 = (d) =>
|
|
74886
|
+
function ownFolderCaseRefusal(p, readdir21 = (d) => fs80.readdirSync(d)) {
|
|
74609
74887
|
let cur = path99.resolve(p);
|
|
74610
74888
|
for (; cur !== path99.dirname(cur); ) {
|
|
74611
74889
|
let parent = path99.dirname(cur), name = path99.basename(cur), siblings;
|
|
@@ -74935,7 +75213,7 @@ async function resolveOnParentPath(cmd) {
|
|
|
74935
75213
|
if (!dir) continue;
|
|
74936
75214
|
let candidate = path100.join(dir, cmd);
|
|
74937
75215
|
try {
|
|
74938
|
-
return await
|
|
75216
|
+
return await import_node_fs46.promises.access(candidate, import_node_fs46.constants.X_OK), candidate;
|
|
74939
75217
|
} catch {
|
|
74940
75218
|
}
|
|
74941
75219
|
}
|
|
@@ -74965,7 +75243,7 @@ var SandboxExecHandle = class {
|
|
|
74965
75243
|
"sandbox_exec",
|
|
74966
75244
|
`agent binary '${argv[0]}' not found on the host PATH \u2014 cannot exec in the sandbox`
|
|
74967
75245
|
);
|
|
74968
|
-
let realArgv0 = await
|
|
75246
|
+
let realArgv0 = await import_node_fs46.promises.realpath(resolvedArgv0).catch(() => resolvedArgv0), deniedRoots = [
|
|
74969
75247
|
path100.join(os48.homedir(), ".codevibe"),
|
|
74970
75248
|
path100.join(this.workdir, ".git"),
|
|
74971
75249
|
...this.auditDir !== null ? [this.auditDir] : []
|
|
@@ -75014,7 +75292,7 @@ ${[
|
|
|
75014
75292
|
].join(`
|
|
75015
75293
|
`)}
|
|
75016
75294
|
` : "";
|
|
75017
|
-
await
|
|
75295
|
+
await import_node_fs46.promises.appendFile(
|
|
75018
75296
|
this.profilePath,
|
|
75019
75297
|
`
|
|
75020
75298
|
; exec-time agent-binary read allowance (argv0 resolution, 2026-07-03)
|
|
@@ -75046,7 +75324,7 @@ ${tail}`
|
|
|
75046
75324
|
}
|
|
75047
75325
|
this.proc = null;
|
|
75048
75326
|
}
|
|
75049
|
-
await
|
|
75327
|
+
await import_node_fs46.promises.rm(this.profilePath, { force: !0 }).catch(() => {
|
|
75050
75328
|
});
|
|
75051
75329
|
}
|
|
75052
75330
|
}
|
|
@@ -75069,14 +75347,14 @@ ${tail}`
|
|
|
75069
75347
|
), canonicalWorkdir = spec.workdirAuthority.canonicalPath;
|
|
75070
75348
|
else
|
|
75071
75349
|
try {
|
|
75072
|
-
canonicalWorkdir = await
|
|
75350
|
+
canonicalWorkdir = await import_node_fs46.promises.realpath(spec.workdir);
|
|
75073
75351
|
} catch {
|
|
75074
75352
|
}
|
|
75075
75353
|
let extraReadDirs = [];
|
|
75076
75354
|
if (spec.agentBootstrap) {
|
|
75077
75355
|
let bootstrapDir = spec.agentBootstrap.hostDir;
|
|
75078
75356
|
try {
|
|
75079
|
-
bootstrapDir = await
|
|
75357
|
+
bootstrapDir = await import_node_fs46.promises.realpath(bootstrapDir);
|
|
75080
75358
|
} catch {
|
|
75081
75359
|
}
|
|
75082
75360
|
let refusal = ownFolderCaseRefusal(bootstrapDir);
|
|
@@ -75087,12 +75365,12 @@ ${tail}`
|
|
|
75087
75365
|
if (spec.agentConfig) {
|
|
75088
75366
|
let configDir = spec.agentConfig.hostDir;
|
|
75089
75367
|
try {
|
|
75090
|
-
configDir = await
|
|
75368
|
+
configDir = await import_node_fs46.promises.realpath(configDir);
|
|
75091
75369
|
} catch {
|
|
75092
75370
|
}
|
|
75093
75371
|
extraWriteDirs.push(configDir);
|
|
75094
75372
|
}
|
|
75095
|
-
if (spec.captureDir && extraWriteDirs.push(await
|
|
75373
|
+
if (spec.captureDir && extraWriteDirs.push(await import_node_fs46.promises.realpath(spec.captureDir)), spec.agentScratch) {
|
|
75096
75374
|
try {
|
|
75097
75375
|
await assertWorkspaceRootAuthority(
|
|
75098
75376
|
spec.agentScratch.hostDir,
|
|
@@ -75112,14 +75390,14 @@ ${tail}`
|
|
|
75112
75390
|
if (spec.auditDir) {
|
|
75113
75391
|
resolvedAuditDir = spec.auditDir;
|
|
75114
75392
|
try {
|
|
75115
|
-
resolvedAuditDir = await
|
|
75393
|
+
resolvedAuditDir = await import_node_fs46.promises.realpath(spec.auditDir);
|
|
75116
75394
|
} catch {
|
|
75117
75395
|
}
|
|
75118
75396
|
}
|
|
75119
75397
|
let canonicalReview = spec.reviewGrants ? {
|
|
75120
|
-
bundleDir: await
|
|
75398
|
+
bundleDir: await import_node_fs46.promises.realpath(spec.reviewGrants.bundleDir),
|
|
75121
75399
|
...spec.reviewGrants.maskedOriginal ? { maskedOriginal: {
|
|
75122
|
-
dir: await
|
|
75400
|
+
dir: await import_node_fs46.promises.realpath(spec.reviewGrants.maskedOriginal.dir),
|
|
75123
75401
|
changedWithheld: spec.reviewGrants.maskedOriginal.changedWithheld
|
|
75124
75402
|
} } : {}
|
|
75125
75403
|
} : null, workspace = spec.workspaceRoots ? await this.seatbeltWorkspace(spec, canonicalWorkdir, extraWriteDirs, canonicalReview) : null, profile = buildSeatbeltProfile(
|
|
@@ -75138,7 +75416,7 @@ ${tail}`
|
|
|
75138
75416
|
workspace?.profile ?? null
|
|
75139
75417
|
), profilePath = path100.join(this.profileRoot, `codevibe-seatbelt-${id5}.sb`);
|
|
75140
75418
|
try {
|
|
75141
|
-
await
|
|
75419
|
+
await import_node_fs46.promises.writeFile(profilePath, profile, { encoding: "utf8", mode: 384 });
|
|
75142
75420
|
} catch (e) {
|
|
75143
75421
|
throw new SubstrateLaunchError(
|
|
75144
75422
|
"sandbox_exec",
|
|
@@ -75155,7 +75433,7 @@ ${tail}`
|
|
|
75155
75433
|
"sandbox-exec substrate handoff"
|
|
75156
75434
|
);
|
|
75157
75435
|
} catch (err) {
|
|
75158
|
-
throw await
|
|
75436
|
+
throw await import_node_fs46.promises.rm(profilePath, { force: !0 }).catch(() => {
|
|
75159
75437
|
}), err;
|
|
75160
75438
|
}
|
|
75161
75439
|
if (spec.agentScratch)
|
|
@@ -75166,7 +75444,7 @@ ${tail}`
|
|
|
75166
75444
|
"sandbox-exec Claude scratch profile handoff"
|
|
75167
75445
|
);
|
|
75168
75446
|
} catch (err) {
|
|
75169
|
-
throw await
|
|
75447
|
+
throw await import_node_fs46.promises.rm(profilePath, { force: !0 }).catch(() => {
|
|
75170
75448
|
}), err;
|
|
75171
75449
|
}
|
|
75172
75450
|
return new SandboxExecHandle(
|
|
@@ -75195,7 +75473,7 @@ ${tail}`
|
|
|
75195
75473
|
}
|
|
75196
75474
|
/** P63 §6.1 — the seat's own folders, the toolchain and interpreter grants (through the rule), and the PATH. */
|
|
75197
75475
|
async seatbeltWorkspace(spec, canonicalWorkdir, extraWriteDirs, review) {
|
|
75198
|
-
let real = async (p) =>
|
|
75476
|
+
let real = async (p) => import_node_fs46.promises.realpath(p).catch(() => p), homedir47 = os48.homedir(), project = await real(spec.workspaceRoots.project), copyRoots = await Promise.all(spec.workspaceRoots.copyRoots.map(real)), ownFolders = [
|
|
75199
75477
|
{ dir: canonicalWorkdir, mode: spec.writableWorkdir === !1 ? "read" : "read-write" },
|
|
75200
75478
|
...review ? [{ dir: review.bundleDir, mode: "read" }] : [],
|
|
75201
75479
|
...review?.maskedOriginal ? [{ dir: review.maskedOriginal.dir, mode: "read" }] : [],
|
|
@@ -75253,11 +75531,11 @@ function randomId2() {
|
|
|
75253
75531
|
|
|
75254
75532
|
// src/substrate-launch/fallback-ladder.ts
|
|
75255
75533
|
init_command_runner();
|
|
75256
|
-
var import_node_crypto55 = require("node:crypto"),
|
|
75534
|
+
var import_node_crypto55 = require("node:crypto"), import_node_fs47 = require("node:fs"), os49 = __toESM(require("node:os")), path102 = __toESM(require("node:path"));
|
|
75257
75535
|
init_spawn_sweep_binary();
|
|
75258
75536
|
|
|
75259
75537
|
// src/substrate/pasta-isolation-check.ts
|
|
75260
|
-
var import_node_child_process18 = require("node:child_process"), import_node_crypto54 = require("node:crypto"),
|
|
75538
|
+
var import_node_child_process18 = require("node:child_process"), import_node_crypto54 = require("node:crypto"), fs82 = __toESM(require("node:fs")), import_node_net2 = __toESM(require("node:net")), path101 = __toESM(require("node:path"));
|
|
75261
75539
|
init_logger2();
|
|
75262
75540
|
init_pasta();
|
|
75263
75541
|
function evaluateIsolation(e) {
|
|
@@ -75360,7 +75638,7 @@ async function runIsolationCheck(opts = {}) {
|
|
|
75360
75638
|
listeners.push(await listenOn("all-v6", "::"));
|
|
75361
75639
|
} catch {
|
|
75362
75640
|
}
|
|
75363
|
-
let ports = listeners.map((l) => ({ port: l.port, listener: l.name })), nodePath =
|
|
75641
|
+
let ports = listeners.map((l) => ({ port: l.port, listener: l.name })), nodePath = fs82.realpathSync(opts.nodePath ?? process.execPath), argv = [
|
|
75364
75642
|
...buildSetprivPrefix(opts.desktopPid ?? process.pid),
|
|
75365
75643
|
...(opts.mutatePastaArgv ?? ((x) => x))(
|
|
75366
75644
|
buildPastaArgv({ brokerPort: "none", ...opts.pastaPath ? { pastaBin: opts.pastaPath } : {} })
|
|
@@ -75393,17 +75671,17 @@ async function runIsolationCheck(opts = {}) {
|
|
|
75393
75671
|
}
|
|
75394
75672
|
function readIsolationCache(dir, key) {
|
|
75395
75673
|
try {
|
|
75396
|
-
let entry5 = JSON.parse(
|
|
75674
|
+
let entry5 = JSON.parse(fs82.readFileSync(path101.join(dir, `pasta-isolation-${key}.json`), "utf8"));
|
|
75397
75675
|
return entry5.key === key && typeof entry5.pass == "boolean" ? entry5 : null;
|
|
75398
75676
|
} catch {
|
|
75399
75677
|
return null;
|
|
75400
75678
|
}
|
|
75401
75679
|
}
|
|
75402
75680
|
function writeIsolationCache(dir, entry5) {
|
|
75403
|
-
|
|
75681
|
+
fs82.mkdirSync(dir, { recursive: !0, mode: 448 });
|
|
75404
75682
|
let file = path101.join(dir, `pasta-isolation-${entry5.key}.json`), tmp = `${file}.${process.pid}.tmp`;
|
|
75405
|
-
|
|
75406
|
-
`, { mode: 384, flag: "wx" }),
|
|
75683
|
+
fs82.writeFileSync(tmp, `${JSON.stringify(entry5)}
|
|
75684
|
+
`, { mode: 384, flag: "wx" }), fs82.renameSync(tmp, file), logger.info("[PastaIsolation] result cached", { pass: entry5.pass });
|
|
75407
75685
|
}
|
|
75408
75686
|
|
|
75409
75687
|
// src/substrate-launch/fallback-ladder.ts
|
|
@@ -75429,7 +75707,7 @@ async function cachedIsolationCheck(runner, cacheDir = path102.join(os49.homedir
|
|
|
75429
75707
|
if (!which.ok || !which.stdout.trim()) return { ok: !1, reason: "pasta is not on PATH" };
|
|
75430
75708
|
let pastaSha;
|
|
75431
75709
|
try {
|
|
75432
|
-
pastaSha = (0, import_node_crypto55.createHash)("sha256").update(await
|
|
75710
|
+
pastaSha = (0, import_node_crypto55.createHash)("sha256").update(await import_node_fs47.promises.readFile(await import_node_fs47.promises.realpath(which.stdout.trim()))).digest("hex");
|
|
75433
75711
|
} catch (err) {
|
|
75434
75712
|
return { ok: !1, reason: `pasta could not be read (${err.message})` };
|
|
75435
75713
|
}
|
|
@@ -75558,13 +75836,13 @@ async function confinementPreflight(input, deps = {}) {
|
|
|
75558
75836
|
async function linuxTierSelfTestKeyParts(open29, runner = new ChildProcessCommandRunner()) {
|
|
75559
75837
|
let resolve35 = async (name) => {
|
|
75560
75838
|
let p = (await exitsZero(runner, ["/bin/sh", "-c", `command -v ${name}`])).stdout.trim();
|
|
75561
|
-
return p ?
|
|
75562
|
-
}, sha = async (file) => file ? (0, import_node_crypto55.createHash)("sha256").update(await
|
|
75839
|
+
return p ? import_node_fs47.promises.realpath(p).catch(() => p) : "";
|
|
75840
|
+
}, sha = async (file) => file ? (0, import_node_crypto55.createHash)("sha256").update(await import_node_fs47.promises.readFile(file)).digest("hex") : "", { generateSeccompBpfFilter: generateSeccompBpfFilter2 } = await Promise.resolve().then(() => (init_bwrap(), bwrap_exports));
|
|
75563
75841
|
return {
|
|
75564
75842
|
filterSha256: (0, import_node_crypto55.createHash)("sha256").update(generateSeccompBpfFilter2()).digest("hex"),
|
|
75565
75843
|
bwrapVersion: (await exitsZero(runner, ["bwrap", "--version"])).stdout.trim(),
|
|
75566
75844
|
setprivPath: await resolve35("setpriv"),
|
|
75567
|
-
bashPath: await
|
|
75845
|
+
bashPath: await import_node_fs47.promises.realpath("/bin/bash").catch(() => "/bin/bash"),
|
|
75568
75846
|
...open29 ? { pastaSha256: await sha(await resolve35("pasta")) } : {}
|
|
75569
75847
|
};
|
|
75570
75848
|
}
|
|
@@ -75627,7 +75905,7 @@ var ConfinedModelCaller = class {
|
|
|
75627
75905
|
};
|
|
75628
75906
|
|
|
75629
75907
|
// src/local-executor/agentic-disposable-repo.ts
|
|
75630
|
-
var import_node_crypto56 = require("node:crypto"),
|
|
75908
|
+
var import_node_crypto56 = require("node:crypto"), fs84 = __toESM(require("node:fs/promises")), path103 = __toESM(require("node:path"));
|
|
75631
75909
|
init_anchored_fs();
|
|
75632
75910
|
init_workspace_authority();
|
|
75633
75911
|
var DisposableRepoError = class extends Error {
|
|
@@ -75664,10 +75942,10 @@ var DisposableRepoError = class extends Error {
|
|
|
75664
75942
|
];
|
|
75665
75943
|
async function materializeDisposableRepo(opts) {
|
|
75666
75944
|
let repoDir = path103.join(opts.parentDir, `cp14-wb2-resolve-${(0, import_node_crypto56.randomBytes)(8).toString("hex")}`);
|
|
75667
|
-
await
|
|
75945
|
+
await fs84.mkdir(repoDir, { recursive: !1, mode: 448 });
|
|
75668
75946
|
let repoAuthority = await captureWorkspaceRootAuthority(repoDir), cleanup = async () => {
|
|
75669
75947
|
try {
|
|
75670
|
-
await
|
|
75948
|
+
await fs84.lstat(repoDir);
|
|
75671
75949
|
} catch (err) {
|
|
75672
75950
|
if (err.code === "ENOENT") return;
|
|
75673
75951
|
throw err;
|
|
@@ -75728,7 +76006,7 @@ async function stageDirForRead(dir, expectedAuthority, seams = {}) {
|
|
|
75728
76006
|
if (!sameWorkspaceRootAuthority(before, expectedAuthority))
|
|
75729
76007
|
throw new Error("disposable repository changed before staging");
|
|
75730
76008
|
let staged = path103.join(parent, `.cp14-staged-${(0, import_node_crypto56.randomBytes)(12).toString("hex")}`);
|
|
75731
|
-
await
|
|
76009
|
+
await fs84.rename(dir, staged);
|
|
75732
76010
|
try {
|
|
75733
76011
|
await seams.afterRename?.(staged);
|
|
75734
76012
|
let [moved, parentAfter] = await Promise.all([
|
|
@@ -75875,11 +76153,11 @@ init_anchored_fs();
|
|
|
75875
76153
|
init_shadow_protocol();
|
|
75876
76154
|
|
|
75877
76155
|
// src/orchestration-shell/review-bundle.ts
|
|
75878
|
-
var import_node_crypto58 = require("node:crypto"),
|
|
76156
|
+
var import_node_crypto58 = require("node:crypto"), import_node_fs48 = require("node:fs"), fs86 = __toESM(require("node:fs/promises")), path105 = __toESM(require("node:path"));
|
|
75879
76157
|
init_shadow_protocol();
|
|
75880
76158
|
|
|
75881
76159
|
// src/orchestration-shell/review-receipts.ts
|
|
75882
|
-
var import_node_crypto57 = require("node:crypto"),
|
|
76160
|
+
var import_node_crypto57 = require("node:crypto"), fs85 = __toESM(require("node:fs/promises")), path104 = __toESM(require("node:path")), MAX_RECEIPTS_PER_SEAT = 12, RECEIPT_PRIORITY_CHANGE_BYTES = 16 * 1024, MAX_RECEIPT_LINE_BYTES = 512, CHUNK2 = 1024 * 1024, NL = 10, LARGE_VIEW_FILE_BYTES = 64 * 1024 * 1024;
|
|
75883
76161
|
function receiptEntryFields(entries, filePath) {
|
|
75884
76162
|
let entry5 = entries?.find((e) => e.path === filePath);
|
|
75885
76163
|
return entry5 ? { entryKind: entry5.kind, ...entry5.office ? { office: entry5.office } : {} } : {};
|
|
@@ -75888,7 +76166,7 @@ function normaliseReceiptValue(v) {
|
|
|
75888
76166
|
return v.replace(/\s+/g, " ").trim();
|
|
75889
76167
|
}
|
|
75890
76168
|
async function lineCount(file) {
|
|
75891
|
-
let fh = await
|
|
76169
|
+
let fh = await fs85.open(file, "r");
|
|
75892
76170
|
try {
|
|
75893
76171
|
let buf = Buffer.allocUnsafe(CHUNK2), total = 0, newlines = 0;
|
|
75894
76172
|
for (; ; ) {
|
|
@@ -75956,7 +76234,7 @@ async function readShortLine(fh, r) {
|
|
|
75956
76234
|
return length > 0 && await fh.read(buf, 0, length, r.start), buf.toString("utf8");
|
|
75957
76235
|
}
|
|
75958
76236
|
async function withFile(file, fn) {
|
|
75959
|
-
let fh = await
|
|
76237
|
+
let fh = await fs85.open(file, "r");
|
|
75960
76238
|
try {
|
|
75961
76239
|
return await fn(fh, (await fh.stat()).size);
|
|
75962
76240
|
} finally {
|
|
@@ -75968,7 +76246,7 @@ async function changedRegion(beforeFile, afterFile) {
|
|
|
75968
76246
|
afterFile && beforeFile && await withFile(afterFile, (fa, aSize) => withFile(beforeFile, async (fb, bSize) => {
|
|
75969
76247
|
prefix = await commonPrefixLines(fa, aSize, fb, bSize), suffix = Math.min(await commonSuffixLines(fa, aSize, fb, bSize), Math.min(aCount, bCount) - prefix);
|
|
75970
76248
|
}));
|
|
75971
|
-
let after = aCount - suffix > prefix ? [prefix + 1, aCount - suffix] : null, before = bCount - suffix > prefix ? [prefix + 1, bCount - suffix] : null, sizeOf = async (f) => f ? (await
|
|
76249
|
+
let after = aCount - suffix > prefix ? [prefix + 1, aCount - suffix] : null, before = bCount - suffix > prefix ? [prefix + 1, bCount - suffix] : null, sizeOf = async (f) => f ? (await fs85.stat(f)).size : 0, share = (r, count4) => r && count4 > 0 ? (r[1] - r[0] + 1) / count4 : 0, changedBytes = Math.max(
|
|
75972
76250
|
await sizeOf(afterFile) * share(after, aCount),
|
|
75973
76251
|
await sizeOf(beforeFile) * share(before, bCount)
|
|
75974
76252
|
);
|
|
@@ -75991,7 +76269,7 @@ async function pickNonBlank(file, range, rng) {
|
|
|
75991
76269
|
});
|
|
75992
76270
|
}
|
|
75993
76271
|
async function copyByteRange(fh, start, end, dest) {
|
|
75994
|
-
let out = await
|
|
76272
|
+
let out = await fs85.open(dest, "wx");
|
|
75995
76273
|
try {
|
|
75996
76274
|
let buf = Buffer.allocUnsafe(CHUNK2);
|
|
75997
76275
|
for (let pos = start; pos < end; ) {
|
|
@@ -76004,7 +76282,7 @@ async function copyByteRange(fh, start, end, dest) {
|
|
|
76004
76282
|
}
|
|
76005
76283
|
}
|
|
76006
76284
|
async function writeLargeViewParts(file, range, destDir, partBytes = LARGE_VIEW_FILE_BYTES) {
|
|
76007
|
-
await
|
|
76285
|
+
await fs85.mkdir(destDir, { recursive: !0 }), await withFile(file, async (fh, size2) => {
|
|
76008
76286
|
let [lo, hi] = range, emit = (start, end, first, last) => copyByteRange(fh, start, end, path104.join(destDir, `lines-${first}-${last}.txt`)), buf = Buffer.allocUnsafe(CHUNK2), line = 1, lineStart = 0, partStart = lo === 1 ? 0 : -1, partFirst = lo;
|
|
76009
76287
|
for (let pos = 0; pos < size2; ) {
|
|
76010
76288
|
let { bytesRead } = await fh.read(buf, 0, Math.min(CHUNK2, size2 - pos), pos);
|
|
@@ -76023,7 +76301,7 @@ async function writeLargeViewParts(file, range, destDir, partBytes = LARGE_VIEW_
|
|
|
76023
76301
|
});
|
|
76024
76302
|
}
|
|
76025
76303
|
async function largeViewLocation(bundleDir, file, line) {
|
|
76026
|
-
let dir = path104.join(bundleDir, "large", file), names = await
|
|
76304
|
+
let dir = path104.join(bundleDir, "large", file), names = await fs85.readdir(dir).catch(() => []);
|
|
76027
76305
|
for (let name of names) {
|
|
76028
76306
|
let m = /^lines-(\d+)-(\d+)\.txt$/.exec(name);
|
|
76029
76307
|
if (m && Number(m[1]) <= line && line <= Number(m[2]))
|
|
@@ -76036,7 +76314,7 @@ async function drawReceiptRequests(input) {
|
|
|
76036
76314
|
for (let f of input.files) {
|
|
76037
76315
|
let kind = f.entryKind ?? "text";
|
|
76038
76316
|
if (kind === "view" || kind === "withheld" || kind === "office" && !f.office?.textChanged) continue;
|
|
76039
|
-
let names = kind === "office" ? { after: `text/${f.path}.after.txt`, before: `text/${f.path}.before.txt` } : { after: `after/${f.path}`, before: `before/${f.path}` }, exists = async (rel) => await
|
|
76317
|
+
let names = kind === "office" ? { after: `text/${f.path}.after.txt`, before: `text/${f.path}.before.txt` } : { after: `after/${f.path}`, before: `before/${f.path}` }, exists = async (rel) => await fs85.stat(path104.join(input.bundleDir, rel)).catch(() => null) !== null, afterFile = (kind === "office" ? await exists(names.after) : f.hasAfter) ? path104.join(input.bundleDir, names.after) : null, beforeFile = (kind === "office" ? await exists(names.before) : f.hasBefore) ? path104.join(input.bundleDir, names.before) : null, region = await changedRegion(beforeFile, afterFile);
|
|
76040
76318
|
region.after === null && region.before === null || candidates.push({ file: f, changedBytes: region.changedBytes, afterRange: region.after, beforeRange: region.before, names });
|
|
76041
76319
|
}
|
|
76042
76320
|
let lineMaker = (c) => ({
|
|
@@ -76179,12 +76457,12 @@ function blobFile(source2) {
|
|
|
76179
76457
|
}
|
|
76180
76458
|
async function sha256File(file) {
|
|
76181
76459
|
let hash3 = (0, import_node_crypto58.createHash)("sha256"), size2 = 0;
|
|
76182
|
-
for await (let chunk of (0,
|
|
76460
|
+
for await (let chunk of (0, import_node_fs48.createReadStream)(file, { highWaterMark: 1024 * 1024 }))
|
|
76183
76461
|
hash3.update(chunk), size2 += chunk.length;
|
|
76184
76462
|
return { sha256: hash3.digest("hex"), size: size2 };
|
|
76185
76463
|
}
|
|
76186
76464
|
async function place(source2, dest) {
|
|
76187
|
-
await
|
|
76465
|
+
await fs86.mkdir(path105.dirname(dest), { recursive: !0 }), await fs86.copyFile(blobFile(source2), dest, import_node_fs48.constants.COPYFILE_EXCL | import_node_fs48.constants.COPYFILE_FICLONE);
|
|
76188
76466
|
let placed = await sha256File(dest);
|
|
76189
76467
|
if (placed.sha256 !== source2.ref.blob || placed.size !== source2.ref.size)
|
|
76190
76468
|
throw new Error(`review bundle: placed bytes do not match their blob: ${dest}`);
|
|
@@ -76211,7 +76489,7 @@ function contextSection(context) {
|
|
|
76211
76489
|
}
|
|
76212
76490
|
async function buildReviewBundle(input) {
|
|
76213
76491
|
for (let f of input.files) assertSafeRelativePath(f.path);
|
|
76214
|
-
await
|
|
76492
|
+
await fs86.mkdir(input.bundleDir);
|
|
76215
76493
|
let lines = [], entries = [], officeParts = [];
|
|
76216
76494
|
for (let f of [...input.files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0)) {
|
|
76217
76495
|
let binary = await presentBinary(input.bundleDir, f);
|
|
@@ -76223,13 +76501,13 @@ async function buildReviewBundle(input) {
|
|
|
76223
76501
|
let diffed = !1, small = (s) => !s || s.ref.size <= LARGE_TEXT_BYTES, baseUnknown = f.change_kind === "modified" && f.before === null;
|
|
76224
76502
|
if (f.change_kind !== "deleted" && !baseUnknown && small(f.after) && small(f.before)) {
|
|
76225
76503
|
let after = f.after ? (await readBlobBytes(f.after.store, f.after.ref, LARGE_TEXT_BYTES)).toString("utf8") : "", before = f.before ? (await readBlobBytes(f.before.store, f.before.ref, LARGE_TEXT_BYTES)).toString("utf8") : "", diffFile = path105.join(input.bundleDir, "diff", `${f.path}.diff`);
|
|
76226
|
-
await
|
|
76504
|
+
await fs86.mkdir(path105.dirname(diffFile), { recursive: !0 }), await fs86.writeFile(diffFile, excerptDiff(f.path, before, after, Number.MAX_SAFE_INTEGER), { flag: "wx" }), diffed = !0;
|
|
76227
76505
|
}
|
|
76228
76506
|
let largeNote = "";
|
|
76229
76507
|
if ((f.after?.ref.size ?? 0) > LARGE_VIEW_FILE_BYTES || (f.before?.ref.size ?? 0) > LARGE_VIEW_FILE_BYTES) {
|
|
76230
76508
|
let afterFile = f.after ? path105.join(input.bundleDir, "after", f.path) : null, beforeFile = f.before ? path105.join(input.bundleDir, "before", f.path) : null, region = await changedRegion(beforeFile, afterFile);
|
|
76231
76509
|
for (let [side, file, range] of [["after", afterFile, region.after], ["before", beforeFile, region.before]])
|
|
76232
|
-
file === null || range === null || (await
|
|
76510
|
+
file === null || range === null || (await fs86.stat(file)).size <= LARGE_VIEW_FILE_BYTES || (await writeLargeViewParts(file, range, path105.join(input.bundleDir, "large", side, f.path)), largeNote += `; changed lines of ${side}/${f.path} in large/${side}/${f.path}/`);
|
|
76233
76511
|
}
|
|
76234
76512
|
lines.push(indexLine(f, diffed).replace(/ \|$/, `${largeNote} |`));
|
|
76235
76513
|
}
|
|
@@ -76250,7 +76528,7 @@ async function buildReviewBundle(input) {
|
|
|
76250
76528
|
...contextSection(input.context)
|
|
76251
76529
|
].join(`
|
|
76252
76530
|
`);
|
|
76253
|
-
await
|
|
76531
|
+
await fs86.writeFile(path105.join(input.bundleDir, "INDEX.md"), index, { flag: "wx" });
|
|
76254
76532
|
let record2 = { version: 1, files: await hashTree(input.bundleDir), entries };
|
|
76255
76533
|
return await makeReadOnly(input.bundleDir), record2;
|
|
76256
76534
|
}
|
|
@@ -76258,7 +76536,7 @@ function partText(name) {
|
|
|
76258
76536
|
return name.replace(/[\r\n|`]/g, " ");
|
|
76259
76537
|
}
|
|
76260
76538
|
async function writeNew(file, text2) {
|
|
76261
|
-
await
|
|
76539
|
+
await fs86.mkdir(path105.dirname(file), { recursive: !0 }), await fs86.writeFile(file, text2, { flag: "wx" });
|
|
76262
76540
|
}
|
|
76263
76541
|
async function presentBinary(bundleDir, f) {
|
|
76264
76542
|
let afterCls = f.change_kind === "deleted" ? null : f.afterClass, beforeCls = f.change_kind === "created" ? null : f.beforeClass;
|
|
@@ -76311,7 +76589,7 @@ async function presentBinary(bundleDir, f) {
|
|
|
76311
76589
|
}
|
|
76312
76590
|
async function walkBundle(dir, onFile, onDir) {
|
|
76313
76591
|
let walk2 = async (current) => {
|
|
76314
|
-
for await (let entry5 of await
|
|
76592
|
+
for await (let entry5 of await fs86.opendir(current)) {
|
|
76315
76593
|
let full = path105.join(current, entry5.name);
|
|
76316
76594
|
if (entry5.isSymbolicLink()) throw new Error(`review bundle contains a link: ${full}`);
|
|
76317
76595
|
entry5.isDirectory() ? await walk2(full) : entry5.isFile() && await onFile(full, path105.relative(dir, full).split(path105.sep).join("/"));
|
|
@@ -76328,18 +76606,18 @@ async function hashTree(dir) {
|
|
|
76328
76606
|
}), out.sort(byName);
|
|
76329
76607
|
}
|
|
76330
76608
|
async function makeReadOnly(dir) {
|
|
76331
|
-
await walkBundle(dir, (full) =>
|
|
76609
|
+
await walkBundle(dir, (full) => fs86.chmod(full, 292), (folder) => fs86.chmod(folder, 365));
|
|
76332
76610
|
}
|
|
76333
76611
|
async function removeReviewRound(roundDir) {
|
|
76334
|
-
let top = await
|
|
76612
|
+
let top = await fs86.lstat(roundDir).catch(() => null);
|
|
76335
76613
|
if (!top) return;
|
|
76336
76614
|
if (!top.isDirectory() || top.isSymbolicLink()) throw new Error(`review round is not a directory: ${roundDir}`);
|
|
76337
76615
|
let walk2 = async (dir) => {
|
|
76338
|
-
await
|
|
76339
|
-
for (let e of await
|
|
76616
|
+
await fs86.chmod(dir, 448);
|
|
76617
|
+
for (let e of await fs86.readdir(dir, { withFileTypes: !0 }))
|
|
76340
76618
|
e.isDirectory() && await walk2(path105.join(dir, e.name));
|
|
76341
76619
|
};
|
|
76342
|
-
await walk2(roundDir), await
|
|
76620
|
+
await walk2(roundDir), await fs86.rm(roundDir, { recursive: !0, force: !0 });
|
|
76343
76621
|
}
|
|
76344
76622
|
async function verifyReviewBundle(bundleDir, record2) {
|
|
76345
76623
|
let want = [...record2.files].sort(byName), find = (name) => {
|
|
@@ -82255,10 +82533,10 @@ ${section}`);
|
|
|
82255
82533
|
return runDeclaredTestSurfaces({
|
|
82256
82534
|
...a,
|
|
82257
82535
|
runShell: this.deps.runShell ?? runShellCommand,
|
|
82258
|
-
lstat:
|
|
82259
|
-
realpath:
|
|
82260
|
-
stat:
|
|
82261
|
-
readFile: (p) =>
|
|
82536
|
+
lstat: import_node_fs49.promises.lstat,
|
|
82537
|
+
realpath: import_node_fs49.promises.realpath,
|
|
82538
|
+
stat: import_node_fs49.promises.stat,
|
|
82539
|
+
readFile: (p) => import_node_fs49.promises.readFile(p, "utf8")
|
|
82262
82540
|
// #609 — nearest-package.json framework detection.
|
|
82263
82541
|
});
|
|
82264
82542
|
}
|
|
@@ -82515,7 +82793,7 @@ ${section}`);
|
|
|
82515
82793
|
})
|
|
82516
82794
|
}, seatWorkdir = this.deps.workingDir, reviewGrants, round = null, receiptRequests = [];
|
|
82517
82795
|
try {
|
|
82518
|
-
round = await this.ensureReviewRound(args.gateId), round && (seatWorkdir = round.seatDir(args.seatId), await
|
|
82796
|
+
round = await this.ensureReviewRound(args.gateId), round && (seatWorkdir = round.seatDir(args.seatId), await import_node_fs49.promises.mkdir(seatWorkdir, { recursive: !0, mode: 448 }), reviewGrants = {
|
|
82519
82797
|
bundleDir: round.bundleDir,
|
|
82520
82798
|
...process.platform === "darwin" ? maskedOriginalGrant(round.record, this.deps.workingDir) : {}
|
|
82521
82799
|
}, receiptRequests = await drawReceiptRequests({ bundleDir: round.bundleDir, files: round.receiptFiles }));
|
|
@@ -82854,10 +83132,10 @@ ${section}`);
|
|
|
82854
83132
|
let next = (this.reviewStateRemovalByTask.get(taskId) ?? Promise.resolve()).then(async () => {
|
|
82855
83133
|
try {
|
|
82856
83134
|
let folder = folderFor(taskId);
|
|
82857
|
-
await removeReviewRound(path106.join(folder, "review")), await
|
|
82858
|
-
for (let sub of ["agy-home", "spawn"]) await
|
|
83135
|
+
await removeReviewRound(path106.join(folder, "review")), await import_node_fs49.promises.rm(path106.join(folder, "capture"), { recursive: !0, force: !0 });
|
|
83136
|
+
for (let sub of ["agy-home", "spawn"]) await import_node_fs49.promises.rmdir(path106.join(folder, sub)).catch(() => {
|
|
82859
83137
|
});
|
|
82860
|
-
await
|
|
83138
|
+
await import_node_fs49.promises.rmdir(folder).catch(() => {
|
|
82861
83139
|
});
|
|
82862
83140
|
} catch (err) {
|
|
82863
83141
|
logger.warn("[QuorumLoop] task review-state removal failed (left for the next start sweep)", {
|
|
@@ -82887,10 +83165,10 @@ ${section}`);
|
|
|
82887
83165
|
if (!reviewed) throw new Error("review round: the task has no captured change");
|
|
82888
83166
|
await this.reviewStateRemovalByTask.get(taskId);
|
|
82889
83167
|
let folders = reviewRoundFolders(this.deps.reviewTaskFolder(taskId), gateId);
|
|
82890
|
-
await
|
|
82891
|
-
for (let entry5 of await
|
|
83168
|
+
await import_node_fs49.promises.mkdir(path106.dirname(folders.round), { recursive: !0, mode: 448 });
|
|
83169
|
+
for (let entry5 of await import_node_fs49.promises.readdir(path106.dirname(folders.round)))
|
|
82892
83170
|
entry5 !== gateId && await removeReviewRound(path106.join(path106.dirname(folders.round), entry5));
|
|
82893
|
-
await removeReviewRound(folders.round), await
|
|
83171
|
+
await removeReviewRound(folders.round), await import_node_fs49.promises.mkdir(folders.round, { mode: 448 });
|
|
82894
83172
|
let brief = this.singleTaskContextByTask.get(taskId)?.brief ?? this.activeBriefByTask.get(taskId)?.brief ?? "", sources = await shadow.reviewBundleSources(reviewed), placedBytes = (size2) => size2 > LARGE_VIEW_FILE_BYTES ? 2 * size2 : size2, bundleBytes = sources.reduce((sum, f) => sum + placedBytes(f.after?.ref.size ?? 0) + placedBytes(f.before?.ref.size ?? 0), 0);
|
|
82895
83173
|
await assertCopySpace(folders.round, bundleBytes, "prepare the review files");
|
|
82896
83174
|
let context = shadow.reviewIndexContext(), record2 = await buildReviewBundle({ bundleDir: folders.bundle, taskBrief: brief, files: sources, context });
|
|
@@ -83105,7 +83383,7 @@ ${section}`);
|
|
|
83105
83383
|
}), null) : { handle: result.substrateHandle, tier: result.tier, teardown: () => result.teardown() };
|
|
83106
83384
|
},
|
|
83107
83385
|
evaluate: (testSpec, gateId, opts) => this.deps.reviewerRegistry.evaluate(testSpec, gateId, opts),
|
|
83108
|
-
...this.deps.reviewTaskFolder ? { removeTaskFolder: (taskId) =>
|
|
83386
|
+
...this.deps.reviewTaskFolder ? { removeTaskFolder: (taskId) => import_node_fs49.promises.rm(this.deps.reviewTaskFolder(taskId), { recursive: !0, force: !0 }) } : {}
|
|
83109
83387
|
});
|
|
83110
83388
|
return verdict.pass ? null : verdict.reason ?? "no reason";
|
|
83111
83389
|
}
|
|
@@ -83410,7 +83688,7 @@ ${section}`);
|
|
|
83410
83688
|
oursCommit,
|
|
83411
83689
|
theirsCommit,
|
|
83412
83690
|
baseSha
|
|
83413
|
-
}), parentDir = await
|
|
83691
|
+
}), parentDir = await import_node_fs49.promises.mkdtemp(path106.join(os50.tmpdir(), "codevibe-wb2-resolve-"));
|
|
83414
83692
|
return resolveAgenticSlot({
|
|
83415
83693
|
realRepoDir: this.deps.workingDir,
|
|
83416
83694
|
// canonical loop workdir == repo root
|
|
@@ -89751,7 +90029,7 @@ function destructiveConfirmationQuestion(text2) {
|
|
|
89751
90029
|
}
|
|
89752
90030
|
|
|
89753
90031
|
// src/orchestration-shell/advisory-attachment-journal.ts
|
|
89754
|
-
var import_node_crypto59 = require("node:crypto"), os51 = __toESM(require("node:os")), path107 = __toESM(require("node:path")),
|
|
90032
|
+
var import_node_crypto59 = require("node:crypto"), os51 = __toESM(require("node:os")), path107 = __toESM(require("node:path")), import_node_fs50 = require("node:fs");
|
|
89755
90033
|
init_anchored_fs();
|
|
89756
90034
|
init_bounded_directory();
|
|
89757
90035
|
init_durable_directory();
|
|
@@ -89960,7 +90238,7 @@ var AdvisoryAttachmentJournal = class {
|
|
|
89960
90238
|
), this.rootAuthority;
|
|
89961
90239
|
if (!create)
|
|
89962
90240
|
try {
|
|
89963
|
-
let stat25 = await
|
|
90241
|
+
let stat25 = await import_node_fs50.promises.lstat(this.rootPath);
|
|
89964
90242
|
if (!stat25.isDirectory() || stat25.isSymbolicLink())
|
|
89965
90243
|
throw new Error("advisory attachment journal root is not a private directory");
|
|
89966
90244
|
} catch (reason) {
|
|
@@ -90752,7 +91030,7 @@ function classifyDurableWorkspaceOutcome(event, displayedSessionId, decryptedMet
|
|
|
90752
91030
|
}
|
|
90753
91031
|
|
|
90754
91032
|
// src/orchestration-shell/workspace-terminal-coordinator.ts
|
|
90755
|
-
var crypto35 = __toESM(require("node:crypto")),
|
|
91033
|
+
var crypto35 = __toESM(require("node:crypto")), import_node_fs51 = require("node:fs"), os52 = __toESM(require("node:os")), path108 = __toESM(require("node:path"));
|
|
90756
91034
|
init_logger2();
|
|
90757
91035
|
|
|
90758
91036
|
// src/orchestration-shell/emit-shell-event.ts
|
|
@@ -91454,10 +91732,10 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91454
91732
|
}
|
|
91455
91733
|
async readJson(filePath, missing = null) {
|
|
91456
91734
|
try {
|
|
91457
|
-
let stat25 = await
|
|
91735
|
+
let stat25 = await import_node_fs51.promises.lstat(filePath);
|
|
91458
91736
|
if (!stat25.isFile() || stat25.isSymbolicLink() || stat25.size > MAX_RECORD_BYTES3)
|
|
91459
91737
|
throw new Error("WorkspaceTerminalCoordinator: unsafe or oversized record");
|
|
91460
|
-
return JSON.parse(await
|
|
91738
|
+
return JSON.parse(await import_node_fs51.promises.readFile(filePath, "utf8"));
|
|
91461
91739
|
} catch (error) {
|
|
91462
91740
|
if (error.code === "ENOENT") return missing;
|
|
91463
91741
|
throw error;
|
|
@@ -91466,7 +91744,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91466
91744
|
async listRecords(directory) {
|
|
91467
91745
|
let entries;
|
|
91468
91746
|
try {
|
|
91469
|
-
entries = await
|
|
91747
|
+
entries = await import_node_fs51.promises.readdir(directory, { withFileTypes: !0 });
|
|
91470
91748
|
} catch (error) {
|
|
91471
91749
|
if (error.code === "ENOENT") return [];
|
|
91472
91750
|
throw error;
|
|
@@ -91476,7 +91754,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91476
91754
|
async listGenerationDirectories(root) {
|
|
91477
91755
|
let entries;
|
|
91478
91756
|
try {
|
|
91479
|
-
entries = await
|
|
91757
|
+
entries = await import_node_fs51.promises.readdir(root, { withFileTypes: !0 });
|
|
91480
91758
|
} catch (error) {
|
|
91481
91759
|
if (error.code === "ENOENT") return [];
|
|
91482
91760
|
throw error;
|
|
@@ -91493,13 +91771,13 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91493
91771
|
async cleanTemporaryFiles(directory) {
|
|
91494
91772
|
let entries;
|
|
91495
91773
|
try {
|
|
91496
|
-
entries = await
|
|
91774
|
+
entries = await import_node_fs51.promises.readdir(directory, { withFileTypes: !0 });
|
|
91497
91775
|
} catch (error) {
|
|
91498
91776
|
if (error.code === "ENOENT") return;
|
|
91499
91777
|
throw error;
|
|
91500
91778
|
}
|
|
91501
91779
|
for (let entry5 of entries)
|
|
91502
|
-
entry5.isFile() && !entry5.isSymbolicLink() && entry5.name.includes(TEMP_INFIX) && await
|
|
91780
|
+
entry5.isFile() && !entry5.isSymbolicLink() && entry5.name.includes(TEMP_INFIX) && await import_node_fs51.promises.unlink(path108.join(directory, entry5.name));
|
|
91503
91781
|
await fsyncDir(directory);
|
|
91504
91782
|
}
|
|
91505
91783
|
async cleanTemporaryFilesAcrossGenerations(root) {
|
|
@@ -91512,7 +91790,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91512
91790
|
for (let record2 of await this.listRecordsAcrossGenerations(root)) {
|
|
91513
91791
|
let identity = `${record2.generation}/${path108.basename(record2.file, ".json")}`;
|
|
91514
91792
|
if (identity === excluded) continue;
|
|
91515
|
-
let stat25 = await
|
|
91793
|
+
let stat25 = await import_node_fs51.promises.stat(record2.file);
|
|
91516
91794
|
if (stat25.size > MAX_RECORD_BYTES3)
|
|
91517
91795
|
throw new Error("WorkspaceTerminalCoordinator: exact record exceeds size limit");
|
|
91518
91796
|
aggregateBytes += stat25.size, reserved.add(identity);
|
|
@@ -91696,7 +91974,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91696
91974
|
let intent = validateGroupIntent(raw);
|
|
91697
91975
|
if (intent.state !== "PENDING" || intent.operation !== operation || intent.groupGeneration !== groupGeneration || intent.operationHash !== authority.operationHash || intent.predecessor.anchorId !== authority.anchorId)
|
|
91698
91976
|
throw new Error("WorkspaceTerminalCoordinator: refused mismatched group reservation cancellation");
|
|
91699
|
-
await
|
|
91977
|
+
await import_node_fs51.promises.unlink(this.intentPath(nonce)), await fsyncDir(this.intentDir());
|
|
91700
91978
|
});
|
|
91701
91979
|
}
|
|
91702
91980
|
groupTerminal(outcome2, details) {
|
|
@@ -91841,12 +92119,12 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91841
92119
|
let outbox = validateOutboxForIntent(outboxValue, intent);
|
|
91842
92120
|
if (draftValue && canonicalJson4(validateOutboxForIntent(draftValue, intent)) !== canonicalJson4(outbox))
|
|
91843
92121
|
throw new Error("WorkspaceTerminalCoordinator: draft/outbox identity changed");
|
|
91844
|
-
draftValue && (await
|
|
92122
|
+
draftValue && (await import_node_fs51.promises.unlink(draftPath), await fsyncDir(this.draftDir(generation)));
|
|
91845
92123
|
return;
|
|
91846
92124
|
}
|
|
91847
92125
|
if (!draftValue)
|
|
91848
92126
|
throw new Error("WorkspaceTerminalCoordinator: committed group outcome has no exact draft");
|
|
91849
|
-
validateOutboxForIntent(draftValue, intent), await
|
|
92127
|
+
validateOutboxForIntent(draftValue, intent), await import_node_fs51.promises.mkdir(this.outboxDir(generation), { recursive: !0, mode: 448 }), await import_node_fs51.promises.rename(draftPath, outboxPath), await Promise.all([
|
|
91850
92128
|
fsyncDir(this.draftDir(generation)),
|
|
91851
92129
|
fsyncDir(this.outboxDir(generation))
|
|
91852
92130
|
]);
|
|
@@ -91863,7 +92141,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91863
92141
|
async syncSettlementDirectory(directory) {
|
|
91864
92142
|
let handle;
|
|
91865
92143
|
try {
|
|
91866
|
-
handle = await
|
|
92144
|
+
handle = await import_node_fs51.promises.open(directory, import_node_fs51.constants.O_RDONLY | import_node_fs51.constants.O_DIRECTORY | import_node_fs51.constants.O_NOFOLLOW);
|
|
91867
92145
|
} catch (error) {
|
|
91868
92146
|
if (error.code === "ENOENT") return;
|
|
91869
92147
|
throw error;
|
|
@@ -91877,7 +92155,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91877
92155
|
async persistSettlementMarker(file, record2) {
|
|
91878
92156
|
await atomicWriteFileSync2(file, this.serialize(record2), { requireDirectorySync: !0 });
|
|
91879
92157
|
for (let directory of [this.quarantineRoot(), path108.join(this.rootDir, "quarantine"), this.rootDir]) {
|
|
91880
|
-
let handle = await
|
|
92158
|
+
let handle = await import_node_fs51.promises.open(directory, import_node_fs51.constants.O_RDONLY | import_node_fs51.constants.O_DIRECTORY | import_node_fs51.constants.O_NOFOLLOW);
|
|
91881
92159
|
try {
|
|
91882
92160
|
await handle.sync();
|
|
91883
92161
|
} finally {
|
|
@@ -91887,11 +92165,11 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91887
92165
|
}
|
|
91888
92166
|
async acknowledge(nonce, generation = this.generation(), settlement = !1) {
|
|
91889
92167
|
let sync = (directory) => settlement ? this.syncSettlementDirectory(directory) : fsyncDir(directory);
|
|
91890
|
-
await
|
|
92168
|
+
await import_node_fs51.promises.unlink(this.outboxPath(nonce, generation)).catch((error) => {
|
|
91891
92169
|
if (error.code !== "ENOENT") throw error;
|
|
91892
|
-
}), await sync(this.outboxDir(generation)), await
|
|
92170
|
+
}), await sync(this.outboxDir(generation)), await import_node_fs51.promises.unlink(this.draftPath(nonce, generation)).catch((error) => {
|
|
91893
92171
|
if (error.code !== "ENOENT") throw error;
|
|
91894
|
-
}), await sync(this.draftDir(generation)), await
|
|
92172
|
+
}), await sync(this.draftDir(generation)), await import_node_fs51.promises.unlink(this.intentPath(nonce, generation)).catch((error) => {
|
|
91895
92173
|
if (error.code !== "ENOENT") throw error;
|
|
91896
92174
|
}), await sync(this.intentDir(generation));
|
|
91897
92175
|
}
|
|
@@ -91908,7 +92186,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91908
92186
|
pending2.add(`${record2.generation}/${sha2567(path108.basename(record2.file, ".json"))}`);
|
|
91909
92187
|
let disposable = files.filter((record2) => !pending2.has(`${record2.generation}/${path108.basename(record2.file, ".json")}`)), oldest = (await Promise.all(disposable.map(async (record2) => ({
|
|
91910
92188
|
...record2,
|
|
91911
|
-
mtimeMs: (await
|
|
92189
|
+
mtimeMs: (await import_node_fs51.promises.stat(record2.file)).mtimeMs
|
|
91912
92190
|
})))).sort((left, right) => left.mtimeMs - right.mtimeMs || left.file.localeCompare(right.file))[0];
|
|
91913
92191
|
if (!oldest) throw new Error("WorkspaceTerminalCoordinator: pending settlement capacity is full");
|
|
91914
92192
|
for (let directory2 of [this.intentDir(oldest.generation), this.outboxDir(oldest.generation), this.draftDir(oldest.generation)]) {
|
|
@@ -91917,7 +92195,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
91917
92195
|
if (sha2567(path108.basename(file, ".json")) === path108.basename(oldest.file, ".json"))
|
|
91918
92196
|
throw new Error("WorkspaceTerminalCoordinator: settlement cleanup is still pending");
|
|
91919
92197
|
}
|
|
91920
|
-
await
|
|
92198
|
+
await import_node_fs51.promises.unlink(oldest.file), await this.syncSettlementDirectory(path108.dirname(oldest.file));
|
|
91921
92199
|
}
|
|
91922
92200
|
let diagnostic = {
|
|
91923
92201
|
version: QUARANTINE_VERSION,
|
|
@@ -92016,7 +92294,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
92016
92294
|
intent.state === "TERMINAL" && (await this.flushTerminalIntent(intent), attempted.add(intent.nonce));
|
|
92017
92295
|
}
|
|
92018
92296
|
let outboxFiles = await this.listRecordsAcrossGenerations(this.outboxRoot()), bytes = 0;
|
|
92019
|
-
for (let record2 of outboxFiles) bytes += (await
|
|
92297
|
+
for (let record2 of outboxFiles) bytes += (await import_node_fs51.promises.stat(record2.file)).size;
|
|
92020
92298
|
if (outboxFiles.length > MAX_OUTBOX_RECORDS || bytes > MAX_OUTBOX_BYTES)
|
|
92021
92299
|
throw new Error("WorkspaceTerminalCoordinator: outbox capacity exceeded");
|
|
92022
92300
|
for (let record2 of outboxFiles) {
|
|
@@ -92037,7 +92315,7 @@ var WorkspaceTerminalCoordinator = class {
|
|
|
92037
92315
|
};
|
|
92038
92316
|
|
|
92039
92317
|
// src/orchestration-shell/decision-effect.ts
|
|
92040
|
-
var crypto36 = __toESM(require("node:crypto")),
|
|
92318
|
+
var crypto36 = __toESM(require("node:crypto")), fs90 = __toESM(require("node:fs/promises")), import_node_fs52 = require("node:fs"), os53 = __toESM(require("node:os")), path109 = __toESM(require("node:path"));
|
|
92041
92319
|
var RECEIPT_VERSION = 1, DIRECTORY_MODE2 = 448, FILE_MODE11 = 384, MAX_RECEIPT_BYTES2 = 64 * 1024, MAX_SESSION_RECEIPTS2 = 64, KNOWN_DECISIONS2 = /* @__PURE__ */ new Set([
|
|
92042
92320
|
"APPROVE",
|
|
92043
92321
|
"CANCEL",
|
|
@@ -92101,7 +92379,7 @@ var DecisionEffectReceiptStore = class {
|
|
|
92101
92379
|
for (let index = -1; index < components.length; index += 1) {
|
|
92102
92380
|
index >= 0 && (current = path109.join(current, components[index]));
|
|
92103
92381
|
try {
|
|
92104
|
-
if ((await
|
|
92382
|
+
if ((await fs90.lstat(current)).isSymbolicLink()) throw new Error("DecisionEffectReceiptStore: symlinked path");
|
|
92105
92383
|
} catch (error) {
|
|
92106
92384
|
if (error.code === "ENOENT") return;
|
|
92107
92385
|
throw error;
|
|
@@ -92111,16 +92389,16 @@ var DecisionEffectReceiptStore = class {
|
|
|
92111
92389
|
async atomicWrite(finalPath, receipt2) {
|
|
92112
92390
|
await this.assertNoSymlinkComponents(finalPath);
|
|
92113
92391
|
let directory = path109.dirname(finalPath);
|
|
92114
|
-
await
|
|
92392
|
+
await fs90.mkdir(directory, { recursive: !0, mode: DIRECTORY_MODE2 }), process.platform !== "win32" && await fs90.chmod(directory, DIRECTORY_MODE2);
|
|
92115
92393
|
let temporary = `${finalPath}.tmp.${process.pid}.${crypto36.randomBytes(6).toString("hex")}`, handle;
|
|
92116
92394
|
try {
|
|
92117
|
-
handle = await
|
|
92395
|
+
handle = await fs90.open(
|
|
92118
92396
|
temporary,
|
|
92119
|
-
|
|
92397
|
+
import_node_fs52.constants.O_WRONLY | import_node_fs52.constants.O_CREAT | import_node_fs52.constants.O_EXCL,
|
|
92120
92398
|
FILE_MODE11
|
|
92121
92399
|
), await handle.writeFile(`${JSON.stringify(validateReceipt2(receipt2))}
|
|
92122
|
-
`, "utf8"), await handle.sync(), await handle.close(), handle = void 0, await
|
|
92123
|
-
let directoryHandle = await
|
|
92400
|
+
`, "utf8"), await handle.sync(), await handle.close(), handle = void 0, await fs90.rename(temporary, finalPath);
|
|
92401
|
+
let directoryHandle = await fs90.open(directory, import_node_fs52.constants.O_RDONLY);
|
|
92124
92402
|
try {
|
|
92125
92403
|
await directoryHandle.sync();
|
|
92126
92404
|
} finally {
|
|
@@ -92128,7 +92406,7 @@ var DecisionEffectReceiptStore = class {
|
|
|
92128
92406
|
}
|
|
92129
92407
|
} catch (error) {
|
|
92130
92408
|
throw await handle?.close().catch(() => {
|
|
92131
|
-
}), await
|
|
92409
|
+
}), await fs90.unlink(temporary).catch(() => {
|
|
92132
92410
|
}), error;
|
|
92133
92411
|
}
|
|
92134
92412
|
}
|
|
@@ -92136,9 +92414,9 @@ var DecisionEffectReceiptStore = class {
|
|
|
92136
92414
|
let target2 = this.receiptPath(sessionId, decisionClaimId);
|
|
92137
92415
|
await this.assertNoSymlinkComponents(target2);
|
|
92138
92416
|
try {
|
|
92139
|
-
if ((await
|
|
92417
|
+
if ((await fs90.stat(target2)).size > MAX_RECEIPT_BYTES2)
|
|
92140
92418
|
throw new Error("DecisionEffectReceiptStore: receipt exceeds size limit");
|
|
92141
|
-
return validateReceipt2(JSON.parse(await
|
|
92419
|
+
return validateReceipt2(JSON.parse(await fs90.readFile(target2, "utf8")));
|
|
92142
92420
|
} catch (error) {
|
|
92143
92421
|
if (error.code === "ENOENT") return null;
|
|
92144
92422
|
throw error;
|
|
@@ -92180,7 +92458,7 @@ var DecisionEffectReceiptStore = class {
|
|
|
92180
92458
|
await this.assertNoSymlinkComponents(directory);
|
|
92181
92459
|
let entries;
|
|
92182
92460
|
try {
|
|
92183
|
-
entries = await
|
|
92461
|
+
entries = await fs90.readdir(directory, { withFileTypes: !0 });
|
|
92184
92462
|
} catch (error) {
|
|
92185
92463
|
if (error.code === "ENOENT") return [];
|
|
92186
92464
|
throw error;
|
|
@@ -92191,9 +92469,9 @@ var DecisionEffectReceiptStore = class {
|
|
|
92191
92469
|
let receipts = [];
|
|
92192
92470
|
for (let entry5 of files.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
92193
92471
|
let target2 = path109.join(directory, entry5.name);
|
|
92194
|
-
if ((await
|
|
92472
|
+
if ((await fs90.stat(target2)).size > MAX_RECEIPT_BYTES2)
|
|
92195
92473
|
throw new Error("DecisionEffectReceiptStore: receipt exceeds size limit");
|
|
92196
|
-
let receipt2 = validateReceipt2(JSON.parse(await
|
|
92474
|
+
let receipt2 = validateReceipt2(JSON.parse(await fs90.readFile(target2, "utf8")));
|
|
92197
92475
|
if (receipt2.sessionId !== sessionId)
|
|
92198
92476
|
throw new Error("DecisionEffectReceiptStore: receipt session mismatch");
|
|
92199
92477
|
receipts.push(receipt2);
|
|
@@ -94169,7 +94447,7 @@ ${notFoundMsg}`), fallbackSection && sections.push(fallbackSection);
|
|
|
94169
94447
|
}
|
|
94170
94448
|
|
|
94171
94449
|
// src/continuation/packet-reader.ts
|
|
94172
|
-
var
|
|
94450
|
+
var import_node_fs53 = require("node:fs"), path111 = __toESM(require("node:path")), os54 = __toESM(require("node:os")), import_yaml2 = require("yaml");
|
|
94173
94451
|
init_types();
|
|
94174
94452
|
init_packet_writer();
|
|
94175
94453
|
init_packet_writer();
|
|
@@ -94245,7 +94523,7 @@ function createContinuationPacketReader(deps) {
|
|
|
94245
94523
|
async read(taskId, expectedHash) {
|
|
94246
94524
|
let filePath = getPacketFilePath(taskId, homeDir), stat25;
|
|
94247
94525
|
try {
|
|
94248
|
-
stat25 = await
|
|
94526
|
+
stat25 = await import_node_fs53.promises.lstat(filePath);
|
|
94249
94527
|
} catch (err) {
|
|
94250
94528
|
throw err.code === "ENOENT" ? new PacketNotFound(filePath) : err;
|
|
94251
94529
|
}
|
|
@@ -94253,7 +94531,7 @@ function createContinuationPacketReader(deps) {
|
|
|
94253
94531
|
throw new PacketPermissionsLoose(filePath, stat25.mode);
|
|
94254
94532
|
let body2;
|
|
94255
94533
|
try {
|
|
94256
|
-
body2 = await
|
|
94534
|
+
body2 = await import_node_fs53.promises.readFile(filePath, "utf8");
|
|
94257
94535
|
} catch (err) {
|
|
94258
94536
|
throw err.code === "ENOENT" ? new PacketNotFound(filePath) : err;
|
|
94259
94537
|
}
|
|
@@ -94279,7 +94557,7 @@ function createContinuationPacketReader(deps) {
|
|
|
94279
94557
|
async list() {
|
|
94280
94558
|
let tasksDir = path111.join(homeDir, ".codevibe", "tasks"), entries;
|
|
94281
94559
|
try {
|
|
94282
|
-
entries = await
|
|
94560
|
+
entries = await import_node_fs53.promises.readdir(tasksDir, { withFileTypes: !0 });
|
|
94283
94561
|
} catch (err) {
|
|
94284
94562
|
if (err.code === "ENOENT")
|
|
94285
94563
|
return [];
|
|
@@ -94290,10 +94568,10 @@ function createContinuationPacketReader(deps) {
|
|
|
94290
94568
|
if (!dirent.isDirectory()) continue;
|
|
94291
94569
|
let taskId = dirent.name, packetPath = getPacketFilePath(taskId, homeDir), packetExists = !1, lastModified = null, packetHash;
|
|
94292
94570
|
try {
|
|
94293
|
-
let stat25 = await
|
|
94571
|
+
let stat25 = await import_node_fs53.promises.lstat(packetPath);
|
|
94294
94572
|
packetExists = !0, lastModified = stat25.mtime;
|
|
94295
94573
|
try {
|
|
94296
|
-
let body2 = await
|
|
94574
|
+
let body2 = await import_node_fs53.promises.readFile(packetPath, "utf8"), { yaml } = splitFrontmatter(body2);
|
|
94297
94575
|
if (yaml !== null) {
|
|
94298
94576
|
let parsed = (0, import_yaml2.parse)(yaml), validated = validatePacketSchema(parsed);
|
|
94299
94577
|
packetHash = computePacketHash(validated);
|
|
@@ -96032,7 +96310,7 @@ function validateAgentAvailability(workItems, detected, priorityOrder, inFlightA
|
|
|
96032
96310
|
var import_node_crypto60 = require("node:crypto");
|
|
96033
96311
|
|
|
96034
96312
|
// src/orchestration-shell/root-discovery.ts
|
|
96035
|
-
var
|
|
96313
|
+
var fs92 = __toESM(require("fs/promises")), path112 = __toESM(require("path")), DEFAULT_DISCOVERY_MAX_DEPTH = 2, DEFAULT_DISCOVERY_MAX_ROOTS = 25, PRUNED_DIRECTORY_NAMES = /* @__PURE__ */ new Set([
|
|
96036
96314
|
".git",
|
|
96037
96315
|
".codevibe",
|
|
96038
96316
|
".dart_tool",
|
|
@@ -96105,14 +96383,14 @@ async function discoverRepositoryRoots(deps = {}) {
|
|
|
96105
96383
|
async function canonicalizeDirectory(dir) {
|
|
96106
96384
|
let resolved = path112.resolve(dir);
|
|
96107
96385
|
try {
|
|
96108
|
-
return await
|
|
96386
|
+
return await fs92.realpath(resolved);
|
|
96109
96387
|
} catch {
|
|
96110
96388
|
return resolved;
|
|
96111
96389
|
}
|
|
96112
96390
|
}
|
|
96113
96391
|
async function readDirSafe(dir) {
|
|
96114
96392
|
try {
|
|
96115
|
-
return await
|
|
96393
|
+
return await fs92.readdir(dir, { withFileTypes: !0 });
|
|
96116
96394
|
} catch {
|
|
96117
96395
|
return null;
|
|
96118
96396
|
}
|
|
@@ -98997,9 +99275,9 @@ function sanitizeListingPath(relPath) {
|
|
|
98997
99275
|
}
|
|
98998
99276
|
function formatAgyWorkspaceListing(workdir, maxEntries = AGY_ADVISORY_LISTING_MAX_ENTRIES, maxBytes = AGY_ADVISORY_LISTING_MAX_BYTES) {
|
|
98999
99277
|
try {
|
|
99000
|
-
if (!
|
|
99278
|
+
if (!fs93.existsSync(workdir))
|
|
99001
99279
|
return "Folder listing unavailable (directory does not exist)";
|
|
99002
|
-
if (!
|
|
99280
|
+
if (!fs93.statSync(workdir).isDirectory())
|
|
99003
99281
|
return "Folder listing unavailable (not a directory)";
|
|
99004
99282
|
if (maxBytes <= 0 || maxEntries <= 0)
|
|
99005
99283
|
return "Folder listing (listing omitted \u2014 prompt budget exhausted)";
|
|
@@ -99007,7 +99285,7 @@ function formatAgyWorkspaceListing(workdir, maxEntries = AGY_ADVISORY_LISTING_MA
|
|
|
99007
99285
|
for (; queue.length > 0 && !truncated; ) {
|
|
99008
99286
|
let relDir = queue.shift(), absDir = relDir === "" ? workdir : path113.join(workdir, relDir), dir;
|
|
99009
99287
|
try {
|
|
99010
|
-
dir =
|
|
99288
|
+
dir = fs93.opendirSync(absDir);
|
|
99011
99289
|
} catch (err) {
|
|
99012
99290
|
if (relDir === "")
|
|
99013
99291
|
return `Folder listing unavailable (directory unreadable: ${err?.code || (err instanceof Error ? err.message : String(err))})`;
|
|
@@ -99037,7 +99315,7 @@ function formatAgyWorkspaceListing(workdir, maxEntries = AGY_ADVISORY_LISTING_MA
|
|
|
99037
99315
|
let isDir = entry5.isDirectory(), isSymlinkToDir = !1;
|
|
99038
99316
|
if (!isDir && entry5.isSymbolicLink())
|
|
99039
99317
|
try {
|
|
99040
|
-
|
|
99318
|
+
fs93.statSync(path113.join(absDir, entry5.name)).isDirectory() && (isSymlinkToDir = !0, isDir = !0);
|
|
99041
99319
|
} catch {
|
|
99042
99320
|
}
|
|
99043
99321
|
if (entry5.name === ".git") {
|
|
@@ -101825,7 +102103,7 @@ async function handleShellUserInput(deps) {
|
|
|
101825
102103
|
json ? "json" : "text",
|
|
101826
102104
|
{ taskId, sessionId: effectiveSessionId }
|
|
101827
102105
|
);
|
|
101828
|
-
(0,
|
|
102106
|
+
(0, import_node_fs54.writeFileSync)(exportPath, formatted, "utf8"), output.output = `Audit log exported to ${exportPath} (${result.model.entries.length} entries)`;
|
|
101829
102107
|
} catch (err) {
|
|
101830
102108
|
output.output = `Failed to export audit log to ${exportPath}: ${err.message ?? String(err)}`;
|
|
101831
102109
|
}
|
|
@@ -103714,14 +103992,14 @@ var OllamaGemmaRunner = class {
|
|
|
103714
103992
|
};
|
|
103715
103993
|
|
|
103716
103994
|
// src/orchestration-shell/cli.ts
|
|
103717
|
-
var import_uuid18 = require("uuid"),
|
|
103995
|
+
var import_uuid18 = require("uuid"), fs101 = __toESM(require("fs")), os60 = __toESM(require("os")), path121 = __toESM(require("path"));
|
|
103718
103996
|
|
|
103719
103997
|
// src/orchestration-shell/doctor-cli.ts
|
|
103720
|
-
var
|
|
103998
|
+
var fs95 = __toESM(require("fs")), path114 = __toESM(require("path")), crypto38 = __toESM(require("crypto")), import_child_process9 = require("child_process");
|
|
103721
103999
|
init_detect_agents();
|
|
103722
104000
|
|
|
103723
104001
|
// src/auth/auth-service.ts
|
|
103724
|
-
var crypto37 = __toESM(require("crypto")),
|
|
104002
|
+
var crypto37 = __toESM(require("crypto")), fs94 = __toESM(require("fs")), http3 = __toESM(require("http")), import_child_process8 = require("child_process");
|
|
103725
104003
|
init_env_scrub();
|
|
103726
104004
|
init_logger2();
|
|
103727
104005
|
init_auth_telemetry();
|
|
@@ -103803,7 +104081,7 @@ var AuthService = class _AuthService {
|
|
|
103803
104081
|
isRunningInWSL() {
|
|
103804
104082
|
if (process.platform !== "linux") return !1;
|
|
103805
104083
|
try {
|
|
103806
|
-
let osRelease =
|
|
104084
|
+
let osRelease = fs94.readFileSync("/proc/sys/kernel/osrelease", "utf8");
|
|
103807
104085
|
return /microsoft|wsl/i.test(osRelease);
|
|
103808
104086
|
} catch {
|
|
103809
104087
|
return !1;
|
|
@@ -104300,9 +104578,9 @@ var colors = {
|
|
|
104300
104578
|
function probeAgentClis(env = process.env) {
|
|
104301
104579
|
return AGENT_SPECS.map(({ agent, command, name }) => {
|
|
104302
104580
|
let binPath;
|
|
104303
|
-
if (agent === "ANTIGRAVITY" && env.AGY_PATH &&
|
|
104581
|
+
if (agent === "ANTIGRAVITY" && env.AGY_PATH && fs95.existsSync(env.AGY_PATH))
|
|
104304
104582
|
try {
|
|
104305
|
-
|
|
104583
|
+
fs95.statSync(env.AGY_PATH).isFile() && (binPath = env.AGY_PATH);
|
|
104306
104584
|
} catch {
|
|
104307
104585
|
binPath = void 0;
|
|
104308
104586
|
}
|
|
@@ -104430,19 +104708,19 @@ async function probeBackendConnectivity(appsyncUrl) {
|
|
|
104430
104708
|
function readBoundedUtf8File(filePath, maxBytes) {
|
|
104431
104709
|
let fd;
|
|
104432
104710
|
try {
|
|
104433
|
-
let stat25 =
|
|
104711
|
+
let stat25 = fs95.statSync(filePath);
|
|
104434
104712
|
if (!stat25.isFile()) return { ok: !1, error: "not a regular file" };
|
|
104435
104713
|
if (stat25.size > maxBytes) return { ok: !1, error: `file exceeds ${maxBytes} byte limit (${stat25.size} bytes)` };
|
|
104436
104714
|
if (stat25.size === 0) return { ok: !1, error: "empty file (0 bytes)" };
|
|
104437
|
-
fd =
|
|
104438
|
-
let buf = Buffer.alloc(stat25.size), bytesRead =
|
|
104715
|
+
fd = fs95.openSync(filePath, "r");
|
|
104716
|
+
let buf = Buffer.alloc(stat25.size), bytesRead = fs95.readSync(fd, buf, 0, stat25.size, 0);
|
|
104439
104717
|
return { ok: !0, content: buf.subarray(0, bytesRead).toString("utf8") };
|
|
104440
104718
|
} catch (err) {
|
|
104441
104719
|
return { ok: !1, error: err.message };
|
|
104442
104720
|
} finally {
|
|
104443
104721
|
if (fd !== void 0)
|
|
104444
104722
|
try {
|
|
104445
|
-
|
|
104723
|
+
fs95.closeSync(fd);
|
|
104446
104724
|
} catch {
|
|
104447
104725
|
}
|
|
104448
104726
|
}
|
|
@@ -104591,8 +104869,8 @@ async function probeOrphanStatusInPair(stateRoot, ownerRootOverride, shadowRootO
|
|
|
104591
104869
|
scanErrors.push(`Exposure retention ${record2.marker.taskId}: ${err.message}`);
|
|
104592
104870
|
}
|
|
104593
104871
|
let ownerRoot = ownerRootOverride ?? resolveOwnerRoot({}, stateRoot), deadProcessOwnersCount = 0;
|
|
104594
|
-
if (
|
|
104595
|
-
let entries =
|
|
104872
|
+
if (fs95.existsSync(ownerRoot)) {
|
|
104873
|
+
let entries = fs95.readdirSync(ownerRoot, { withFileTypes: !0 });
|
|
104596
104874
|
for (let entry5 of entries) {
|
|
104597
104875
|
if (!entry5.isFile() || !/^owner-[0-9a-f-]{36}\.json$/i.test(entry5.name)) continue;
|
|
104598
104876
|
let readResult = readBoundedUtf8File(path114.join(ownerRoot, entry5.name), 4096);
|
|
@@ -104650,7 +104928,7 @@ function shadowStateRoot() {
|
|
|
104650
104928
|
function readRegistry(stateRoot) {
|
|
104651
104929
|
let file = path114.join(stateRoot, SHADOW_ROOT_REGISTRY_FILE), raw;
|
|
104652
104930
|
try {
|
|
104653
|
-
raw =
|
|
104931
|
+
raw = fs95.readFileSync(file, "utf8");
|
|
104654
104932
|
} catch {
|
|
104655
104933
|
return null;
|
|
104656
104934
|
}
|
|
@@ -104662,7 +104940,7 @@ function readRegistry(stateRoot) {
|
|
|
104662
104940
|
function collectMarkers(stateRoot) {
|
|
104663
104941
|
let index = /* @__PURE__ */ new Map(), taskDirs;
|
|
104664
104942
|
try {
|
|
104665
|
-
taskDirs =
|
|
104943
|
+
taskDirs = fs95.readdirSync(stateRoot, { withFileTypes: !0 });
|
|
104666
104944
|
} catch {
|
|
104667
104945
|
return index;
|
|
104668
104946
|
}
|
|
@@ -104670,7 +104948,7 @@ function collectMarkers(stateRoot) {
|
|
|
104670
104948
|
if (!taskDir.isDirectory() || taskDir.name.startsWith(".")) continue;
|
|
104671
104949
|
let dir = path114.join(stateRoot, taskDir.name), files;
|
|
104672
104950
|
try {
|
|
104673
|
-
files =
|
|
104951
|
+
files = fs95.readdirSync(dir);
|
|
104674
104952
|
} catch {
|
|
104675
104953
|
continue;
|
|
104676
104954
|
}
|
|
@@ -104678,8 +104956,8 @@ function collectMarkers(stateRoot) {
|
|
|
104678
104956
|
if (!SHADOW_STATE_FILE_RE.test(name) && !SHADOW_EXPOSURE_RETENTION_FILE_RE.test(name)) continue;
|
|
104679
104957
|
let file = path114.join(dir, name), marker;
|
|
104680
104958
|
try {
|
|
104681
|
-
if (
|
|
104682
|
-
marker = JSON.parse(
|
|
104959
|
+
if (fs95.statSync(file).size > MAX_STATE_MARKER_BYTES) continue;
|
|
104960
|
+
marker = JSON.parse(fs95.readFileSync(file, "utf8"));
|
|
104683
104961
|
} catch {
|
|
104684
104962
|
continue;
|
|
104685
104963
|
}
|
|
@@ -104695,19 +104973,19 @@ function inodeSurvivesInParent(root) {
|
|
|
104695
104973
|
if (!root.ino) return;
|
|
104696
104974
|
let parent = path114.dirname(root.path);
|
|
104697
104975
|
try {
|
|
104698
|
-
|
|
104976
|
+
fs95.lstatSync(parent);
|
|
104699
104977
|
} catch (err) {
|
|
104700
104978
|
return err.code === "ENOENT" ? !1 : void 0;
|
|
104701
104979
|
}
|
|
104702
104980
|
let entries;
|
|
104703
104981
|
try {
|
|
104704
|
-
entries =
|
|
104982
|
+
entries = fs95.readdirSync(parent);
|
|
104705
104983
|
} catch {
|
|
104706
104984
|
return;
|
|
104707
104985
|
}
|
|
104708
104986
|
for (let name of entries)
|
|
104709
104987
|
try {
|
|
104710
|
-
if (
|
|
104988
|
+
if (fs95.lstatSync(path114.join(parent, name), { bigint: !0 }).ino.toString() === root.ino) return !0;
|
|
104711
104989
|
} catch {
|
|
104712
104990
|
continue;
|
|
104713
104991
|
}
|
|
@@ -104718,7 +104996,7 @@ function diagnose(stateRoot, roots) {
|
|
|
104718
104996
|
return roots.map((root) => {
|
|
104719
104997
|
let markers = markerIndex.get(root.path) ?? [], present = !1;
|
|
104720
104998
|
try {
|
|
104721
|
-
present =
|
|
104999
|
+
present = fs95.lstatSync(root.path).isDirectory();
|
|
104722
105000
|
} catch {
|
|
104723
105001
|
present = !1;
|
|
104724
105002
|
}
|
|
@@ -104876,29 +105154,29 @@ ${colors.red}\u2717${colors.reset} ${withheld.length} entr${withheld.length ===
|
|
|
104876
105154
|
Nothing was written. Re-run with ${colors.bold}--yes${colors.reset} to apply${withheld.length ? " the entries listed first" : ""}.`), 0;
|
|
104877
105155
|
let locks = path114.join(stateRoot, SHADOW_QUOTA_LOCK_DIR), held = [];
|
|
104878
105156
|
try {
|
|
104879
|
-
held =
|
|
105157
|
+
held = fs95.readdirSync(locks);
|
|
104880
105158
|
} catch {
|
|
104881
105159
|
held = [];
|
|
104882
105160
|
}
|
|
104883
105161
|
if (held.length)
|
|
104884
105162
|
return console.error(`${colors.red}\u2717${colors.reset} A CodeVibe session is registering a root right now. Try again once it is idle.`), 1;
|
|
104885
|
-
let file = path114.join(stateRoot, SHADOW_ROOT_REGISTRY_FILE), current =
|
|
105163
|
+
let file = path114.join(stateRoot, SHADOW_ROOT_REGISTRY_FILE), current = fs95.readFileSync(file, "utf8");
|
|
104886
105164
|
if (crypto38.createHash("sha256").update(current).digest("hex") !== crypto38.createHash("sha256").update(registry.raw).digest("hex"))
|
|
104887
105165
|
return console.error(`${colors.red}\u2717${colors.reset} The registry changed while this ran. Nothing was written; re-run.`), 1;
|
|
104888
105166
|
let stamp2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-"), backupDir = path114.join(path114.dirname(stateRoot), "shadow-root-backups", stamp2), backup = path114.join(backupDir, "shadow-roots.json");
|
|
104889
105167
|
try {
|
|
104890
|
-
|
|
105168
|
+
fs95.mkdirSync(backupDir, { recursive: !0, mode: 448 }), fs95.copyFileSync(file, backup);
|
|
104891
105169
|
} catch (err) {
|
|
104892
105170
|
return console.error(`${colors.red}\u2717${colors.reset} Could not write the backup at ${backupDir} (${err.code ?? "unknown error"}). Nothing was changed \u2014 this command will not clear an entry it cannot restore.`), 1;
|
|
104893
105171
|
}
|
|
104894
105172
|
let removed = new Set(clearable.map((d) => d.root.path)), kept = registry.roots.filter((r) => !removed.has(r.path)), tmp = path114.join(backupDir, `.registry.next.${process.pid}`);
|
|
104895
105173
|
try {
|
|
104896
|
-
|
|
105174
|
+
fs95.writeFileSync(tmp, JSON.stringify({ version: 2, roots: kept }), { mode: 384 }), fs95.renameSync(tmp, file);
|
|
104897
105175
|
} catch (err) {
|
|
104898
105176
|
return console.error(`${colors.red}\u2717${colors.reset} Could not replace the registry (${err.code ?? "unknown error"}). Nothing was changed; a copy of it is at ${backup}.`), 1;
|
|
104899
105177
|
} finally {
|
|
104900
105178
|
try {
|
|
104901
|
-
|
|
105179
|
+
fs95.unlinkSync(tmp);
|
|
104902
105180
|
} catch {
|
|
104903
105181
|
}
|
|
104904
105182
|
}
|
|
@@ -104907,7 +105185,7 @@ ${colors.red}\u2717${colors.reset} ${withheld.length} entr${withheld.length ===
|
|
|
104907
105185
|
for (let marker of d.markers) {
|
|
104908
105186
|
let copy = path114.join(backupDir, `marker-${savedMarkers.length}-${path114.basename(marker)}`);
|
|
104909
105187
|
try {
|
|
104910
|
-
|
|
105188
|
+
fs95.copyFileSync(marker, copy), savedMarkers.push({ copy: path114.basename(copy), original: marker });
|
|
104911
105189
|
} catch (err) {
|
|
104912
105190
|
if (err.code !== "ENOENT") {
|
|
104913
105191
|
unbackedMarkers.push(marker);
|
|
@@ -104915,16 +105193,16 @@ ${colors.red}\u2717${colors.reset} ${withheld.length} entr${withheld.length ===
|
|
|
104915
105193
|
}
|
|
104916
105194
|
}
|
|
104917
105195
|
try {
|
|
104918
|
-
|
|
105196
|
+
fs95.unlinkSync(marker);
|
|
104919
105197
|
} catch {
|
|
104920
105198
|
}
|
|
104921
105199
|
try {
|
|
104922
|
-
|
|
105200
|
+
fs95.rmdirSync(path114.dirname(marker));
|
|
104923
105201
|
} catch {
|
|
104924
105202
|
}
|
|
104925
105203
|
}
|
|
104926
105204
|
try {
|
|
104927
|
-
|
|
105205
|
+
fs95.writeFileSync(path114.join(backupDir, "manifest.json"), `${JSON.stringify({
|
|
104928
105206
|
clearedAtUtc: (/* @__PURE__ */ new Date()).toISOString(),
|
|
104929
105207
|
registry: file,
|
|
104930
105208
|
registryBackup: path114.basename(backup),
|
|
@@ -104944,7 +105222,7 @@ ${colors.green}\u2713${colors.reset} Cleared ${clearable.length} entr${clearable
|
|
|
104944
105222
|
}
|
|
104945
105223
|
|
|
104946
105224
|
// src/substrate-launch/engage-substrate.ts
|
|
104947
|
-
var
|
|
105225
|
+
var import_node_fs55 = require("node:fs"), os56 = __toESM(require("node:os")), path115 = __toESM(require("node:path")), crypto39 = __toESM(require("node:crypto"));
|
|
104948
105226
|
|
|
104949
105227
|
// src/credential-broker/types.ts
|
|
104950
105228
|
var BROKER_ROUTES = [
|
|
@@ -106947,17 +107225,17 @@ function deriveAuditPath(workdir) {
|
|
|
106947
107225
|
async function assertAuditOutsideWorkdir(auditPath, workdir) {
|
|
106948
107226
|
let realWorkdir;
|
|
106949
107227
|
try {
|
|
106950
|
-
realWorkdir = await
|
|
107228
|
+
realWorkdir = await import_node_fs55.promises.realpath(workdir);
|
|
106951
107229
|
} catch {
|
|
106952
107230
|
throw new Error(
|
|
106953
107231
|
`CP-7 W3: cannot realpath workdir "${workdir}" \u2014 refusing to launch (audit containment fail-closed)`
|
|
106954
107232
|
);
|
|
106955
107233
|
}
|
|
106956
107234
|
let auditDir = path115.dirname(auditPath);
|
|
106957
|
-
await
|
|
107235
|
+
await import_node_fs55.promises.mkdir(auditDir, { recursive: !0 });
|
|
106958
107236
|
let realAuditDir;
|
|
106959
107237
|
try {
|
|
106960
|
-
realAuditDir = await
|
|
107238
|
+
realAuditDir = await import_node_fs55.promises.realpath(auditDir);
|
|
106961
107239
|
} catch {
|
|
106962
107240
|
throw new Error(
|
|
106963
107241
|
`CP-7 W3: cannot realpath audit dir "${auditDir}" \u2014 refusing to launch (fail-closed)`
|
|
@@ -106965,14 +107243,14 @@ async function assertAuditOutsideWorkdir(auditPath, workdir) {
|
|
|
106965
107243
|
}
|
|
106966
107244
|
let resolvedAuditPath = path115.join(realAuditDir, path115.basename(auditPath)), leafStat;
|
|
106967
107245
|
try {
|
|
106968
|
-
leafStat = await
|
|
107246
|
+
leafStat = await import_node_fs55.promises.lstat(resolvedAuditPath);
|
|
106969
107247
|
} catch {
|
|
106970
107248
|
leafStat = void 0;
|
|
106971
107249
|
}
|
|
106972
107250
|
let resolvedLeafTarget = resolvedAuditPath;
|
|
106973
107251
|
if (leafStat?.isSymbolicLink())
|
|
106974
107252
|
try {
|
|
106975
|
-
resolvedLeafTarget = await
|
|
107253
|
+
resolvedLeafTarget = await import_node_fs55.promises.realpath(resolvedAuditPath);
|
|
106976
107254
|
} catch {
|
|
106977
107255
|
throw new Error(
|
|
106978
107256
|
`CP-7 W3: audit leaf "${resolvedAuditPath}" is a symlink that does not resolve (dangling) \u2014 refusing to launch (fail-closed). The audit file must be a regular file in the sibling .codevibe/audit/ tree.`
|
|
@@ -107250,7 +107528,7 @@ async function engageSubstrate(input) {
|
|
|
107250
107528
|
async function bubblewrapWorkspaceRoots(input) {
|
|
107251
107529
|
if (!input.projectRoot)
|
|
107252
107530
|
throw new Error("bubblewrap tier: the spawn names no project folder \u2014 refusing to launch without the \xA76.1 grant rule");
|
|
107253
|
-
return { project: await
|
|
107531
|
+
return { project: await import_node_fs55.promises.realpath(input.projectRoot), copyRoots: await v2CopyRoots() };
|
|
107254
107532
|
}
|
|
107255
107533
|
var RESOLVER_AGENT_STATE_DIR_SEGMENTS = {
|
|
107256
107534
|
GEMINI: [".gemini"]
|
|
@@ -107303,22 +107581,22 @@ async function engageWriteConfinedResolverSandbox(input) {
|
|
|
107303
107581
|
copyRoot
|
|
107304
107582
|
});
|
|
107305
107583
|
try {
|
|
107306
|
-
await
|
|
107584
|
+
await import_node_fs55.promises.mkdir(path115.dirname(spawnParentDir), { recursive: !0 }), await import_node_fs55.promises.mkdir(spawnParentDir);
|
|
107307
107585
|
} catch (mkdirErr) {
|
|
107308
|
-
throw await
|
|
107586
|
+
throw await import_node_fs55.promises.rm(spawnRecordFile, { force: !0 }), mkdirErr;
|
|
107309
107587
|
}
|
|
107310
107588
|
spawnParentDirCreated = !0;
|
|
107311
107589
|
try {
|
|
107312
107590
|
let agyCliDir = path115.join(privateHomeDir, ".gemini", "antigravity-cli");
|
|
107313
|
-
await
|
|
107591
|
+
await import_node_fs55.promises.mkdir(agyCliDir, { recursive: !0 });
|
|
107314
107592
|
let hostAgyDir = path115.join(homedir47, ".gemini", "antigravity-cli"), idFile = path115.join(hostAgyDir, "installation_id"), seeded = await seedAgySignIn(hostAgyDir, agyCliDir, input.agySignIn);
|
|
107315
107593
|
logger.info("[engageSubstrate] agy sign-in seeded for the spawn", seeded);
|
|
107316
107594
|
try {
|
|
107317
|
-
await
|
|
107595
|
+
await import_node_fs55.promises.copyFile(idFile, path115.join(agyCliDir, "installation_id")), await import_node_fs55.promises.chmod(path115.join(agyCliDir, "installation_id"), 384);
|
|
107318
107596
|
} catch {
|
|
107319
107597
|
}
|
|
107320
107598
|
let agyEnvForModel = input.homedir !== void 0 ? {} : process.env, safeAgySettings = readSafeAgyModelSettings(homedir47, agyEnvForModel);
|
|
107321
|
-
(safeAgySettings.model || safeAgySettings.effort) && await
|
|
107599
|
+
(safeAgySettings.model || safeAgySettings.effort) && await import_node_fs55.promises.writeFile(
|
|
107322
107600
|
path115.join(agyCliDir, "settings.json"),
|
|
107323
107601
|
JSON.stringify(safeAgySettings, null, 2) + `
|
|
107324
107602
|
`,
|
|
@@ -107357,7 +107635,7 @@ async function engageWriteConfinedResolverSandbox(input) {
|
|
|
107357
107635
|
let rollbackErrors = [];
|
|
107358
107636
|
if (spawnParentDirCreated && spawnParentDir !== null)
|
|
107359
107637
|
try {
|
|
107360
|
-
await
|
|
107638
|
+
await import_node_fs55.promises.rm(spawnParentDir, { recursive: !0, force: !0 }), spawnRecordFile !== null && await import_node_fs55.promises.rm(spawnRecordFile, { force: !0 });
|
|
107361
107639
|
} catch (rmErr) {
|
|
107362
107640
|
rollbackErrors.push(rmErr);
|
|
107363
107641
|
}
|
|
@@ -107373,7 +107651,7 @@ async function engageWriteConfinedResolverSandbox(input) {
|
|
|
107373
107651
|
stateDir = path115.join(
|
|
107374
107652
|
homedir47,
|
|
107375
107653
|
...RESOLVER_AGENT_STATE_DIR_SEGMENTS[agentKind]
|
|
107376
|
-
), await
|
|
107654
|
+
), await import_node_fs55.promises.mkdir(stateDir, { recursive: !0 }).catch(() => {
|
|
107377
107655
|
}), env.HOME = homedir47;
|
|
107378
107656
|
let nodeDir = process.execPath.slice(0, process.execPath.lastIndexOf("/"));
|
|
107379
107657
|
env.PATH = `${SANDBOX_DEFAULT_PATH}:${nodeDir}`;
|
|
@@ -107427,7 +107705,7 @@ async function engageWriteConfinedResolverSandbox(input) {
|
|
|
107427
107705
|
}
|
|
107428
107706
|
), err;
|
|
107429
107707
|
}
|
|
107430
|
-
spawnParentDirCreated && spawnParentDir !== null && (await
|
|
107708
|
+
spawnParentDirCreated && spawnParentDir !== null && (await import_node_fs55.promises.rm(spawnParentDir, { recursive: !0, force: !0 }), spawnRecordFile !== null && await import_node_fs55.promises.rm(spawnRecordFile, { force: !0 }));
|
|
107431
107709
|
}
|
|
107432
107710
|
};
|
|
107433
107711
|
}
|
|
@@ -109118,7 +109396,7 @@ Note: --export will overwrite any existing file at <path>.
|
|
|
109118
109396
|
offset: parsed.offset
|
|
109119
109397
|
});
|
|
109120
109398
|
if (result.kind === "ok" && parsed.exportPath) {
|
|
109121
|
-
let writeFile9 = deps?.writeFileFn ?? ((p, c) =>
|
|
109399
|
+
let writeFile9 = deps?.writeFileFn ?? ((p, c) => fs101.writeFileSync(p, c, "utf8"));
|
|
109122
109400
|
try {
|
|
109123
109401
|
let formatted = formatAuditExport(
|
|
109124
109402
|
result.model,
|
|
@@ -109267,7 +109545,7 @@ ${err.message}
|
|
|
109267
109545
|
`), 1;
|
|
109268
109546
|
}
|
|
109269
109547
|
try {
|
|
109270
|
-
setSessionCopyRoot((await chooseCopyLocation(await
|
|
109548
|
+
setSessionCopyRoot((await chooseCopyLocation(await fs101.promises.realpath(process.cwd()))).copyRoot);
|
|
109271
109549
|
} catch (err) {
|
|
109272
109550
|
let reason = err?.message ?? String(err);
|
|
109273
109551
|
markSessionCopyRootUnresolved(reason), logger.warn("[cli] copy location not resolved at start (each task resolves it again)", { error: reason });
|
|
@@ -109614,7 +109892,7 @@ function buildAndArmQuorumLoop(args) {
|
|
|
109614
109892
|
cacheDir: path121.join(os60.homedir(), ".codevibe", "substrate-checks"),
|
|
109615
109893
|
viewParent: async () => {
|
|
109616
109894
|
let dir = await defaultCopyLocation();
|
|
109617
|
-
return await
|
|
109895
|
+
return await fs101.promises.mkdir(dir, { recursive: !0, mode: 448 }), dir;
|
|
109618
109896
|
},
|
|
109619
109897
|
linuxKeyParts: (open29) => linuxTierSelfTestKeyParts(open29)
|
|
109620
109898
|
},
|
|
@@ -109710,7 +109988,7 @@ async function buildQuorumLoopExecutor(args) {
|
|
|
109710
109988
|
cacheDir: path121.join(os60.homedir(), ".codevibe", "substrate-checks"),
|
|
109711
109989
|
viewParent: async () => {
|
|
109712
109990
|
let dir = await defaultCopyLocation();
|
|
109713
|
-
return await
|
|
109991
|
+
return await fs101.promises.mkdir(dir, { recursive: !0, mode: 448 }), dir;
|
|
109714
109992
|
},
|
|
109715
109993
|
linuxKeyParts: (open29) => linuxTierSelfTestKeyParts(open29)
|
|
109716
109994
|
},
|
|
@@ -110193,7 +110471,7 @@ async function buildTeamLocalExecutor(args) {
|
|
|
110193
110471
|
cacheDir: path121.join(os60.homedir(), ".codevibe", "substrate-checks"),
|
|
110194
110472
|
viewParent: async () => {
|
|
110195
110473
|
let dir = await defaultCopyLocation();
|
|
110196
|
-
return await
|
|
110474
|
+
return await fs101.promises.mkdir(dir, { recursive: !0, mode: 448 }), dir;
|
|
110197
110475
|
},
|
|
110198
110476
|
linuxKeyParts: (open29) => linuxTierSelfTestKeyParts(open29)
|
|
110199
110477
|
},
|