@ordewell/core 0.12.3 → 0.12.5
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/{eventStore-BcoMsZtU.d.mts → eventStore-BbMmQDBw.d.mts} +49 -1
- package/dist/{eventStore-CSFKy48Y.d.ts → eventStore-br1Tvuh6.d.ts} +49 -1
- package/dist/index.d.mts +28 -160
- package/dist/index.d.ts +28 -160
- package/dist/index.js +925 -541
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +875 -491
- package/dist/index.mjs.map +1 -1
- package/dist/plan-utils.d.mts +2 -2
- package/dist/plan-utils.d.ts +2 -2
- package/dist/{runSettingsText-C6eto6Uv.d.ts → runSettingsText-CmPkgAuJ.d.ts} +143 -3
- package/dist/{runSettingsText-DnzSrB0c.d.mts → runSettingsText-DywaLmlZ.d.mts} +143 -3
- package/dist/testing.d.mts +47 -2
- package/dist/testing.d.ts +47 -2
- package/dist/testing.js +72 -4
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +55 -3
- package/dist/testing.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1115,14 +1115,14 @@ var VerdictEngine = class {
|
|
|
1115
1115
|
if (this.toolCheckpoints.has(taskId)) {
|
|
1116
1116
|
return Promise.resolve({ kind: "withdrawn", why: "another checkpoint is still waiting for an answer. Wait for it before asking again." });
|
|
1117
1117
|
}
|
|
1118
|
-
return new Promise((
|
|
1118
|
+
return new Promise((resolve18) => {
|
|
1119
1119
|
const settle = (answer2) => {
|
|
1120
1120
|
signal.removeEventListener("abort", onAbort);
|
|
1121
1121
|
if (this.toolCheckpoints.get(taskId) === settle) {
|
|
1122
1122
|
this.toolCheckpoints.delete(taskId);
|
|
1123
1123
|
this.checkpointQuestions.delete(taskId);
|
|
1124
1124
|
}
|
|
1125
|
-
|
|
1125
|
+
resolve18(answer2);
|
|
1126
1126
|
};
|
|
1127
1127
|
const onAbort = () => {
|
|
1128
1128
|
settle({ kind: "withdrawn", why: "the call was cancelled." });
|
|
@@ -5813,6 +5813,10 @@ function exclusionWord(pattern) {
|
|
|
5813
5813
|
function isScopePattern(entry) {
|
|
5814
5814
|
return /^(\/|~|https?:\/\/|web_search:|mcp__|mcp-server:|[A-Za-z]:[\\/])/.test(entry);
|
|
5815
5815
|
}
|
|
5816
|
+
var backslashed = (scope) => scope.replace(/\//g, "\\");
|
|
5817
|
+
function scopeExclusion(entry) {
|
|
5818
|
+
return /^[A-Za-z]:[\\/]/.test(entry) ? globRegExp(backslashed(entry), "i") : globRegExp(entry);
|
|
5819
|
+
}
|
|
5816
5820
|
function parseAllowlist(entries) {
|
|
5817
5821
|
const list2 = { commands: [], commandExclusions: [], tools: [], toolExclusions: [], scopes: [], scopeExclusions: [] };
|
|
5818
5822
|
for (const raw of entries) {
|
|
@@ -5822,7 +5826,8 @@ function parseAllowlist(entries) {
|
|
|
5822
5826
|
if (entry.startsWith("mcp:")) {
|
|
5823
5827
|
(exclude ? list2.toolExclusions : list2.tools).push(globRegExp(entry.slice(4).trim(), "i"));
|
|
5824
5828
|
} else if (isScopePattern(entry)) {
|
|
5825
|
-
(exclude
|
|
5829
|
+
if (exclude) list2.scopeExclusions.push(scopeExclusion(entry));
|
|
5830
|
+
else list2.scopes.push(globRegExp(entry));
|
|
5826
5831
|
} else {
|
|
5827
5832
|
const [binary, ...words] = entry.split(/\s+/);
|
|
5828
5833
|
(exclude ? list2.commandExclusions : list2.commands).push({ text: raw.trim(), binary, words: words.map(exclude ? exclusionWord : ruleWord) });
|
|
@@ -5870,7 +5875,7 @@ function toolAllowed(list2, tool2) {
|
|
|
5870
5875
|
}
|
|
5871
5876
|
function scopeExcluded(list2, scope) {
|
|
5872
5877
|
const origin = /^(?:curl|wget) (https?:\/\/\S+\/\*)$/.exec(scope)?.[1];
|
|
5873
|
-
return list2.scopeExclusions.some((re) => re.test(scope) || origin !== void 0 && re.test(origin));
|
|
5878
|
+
return list2.scopeExclusions.some((re) => re.test(scope) || re.test(backslashed(scope)) || origin !== void 0 && re.test(origin));
|
|
5874
5879
|
}
|
|
5875
5880
|
function scopeAllowed(list2, scope) {
|
|
5876
5881
|
if (scopeExcluded(list2, scope)) return false;
|
|
@@ -6244,13 +6249,13 @@ function vetHostUnresolved(host) {
|
|
|
6244
6249
|
if (LOCAL_NAMES.has(bare.toLowerCase())) return { ok: false, reason: `local host name ${bare}` };
|
|
6245
6250
|
return void 0;
|
|
6246
6251
|
}
|
|
6247
|
-
async function vetHost(host,
|
|
6252
|
+
async function vetHost(host, resolve18) {
|
|
6248
6253
|
const settled = vetHostUnresolved(host);
|
|
6249
6254
|
if (settled) return settled;
|
|
6250
6255
|
const bare = stripBrackets(host);
|
|
6251
6256
|
let addresses;
|
|
6252
6257
|
try {
|
|
6253
|
-
addresses = await
|
|
6258
|
+
addresses = await resolve18(bare);
|
|
6254
6259
|
} catch {
|
|
6255
6260
|
return { ok: false, reason: `${bare} did not resolve` };
|
|
6256
6261
|
}
|
|
@@ -6261,16 +6266,16 @@ async function vetHost(host, resolve17) {
|
|
|
6261
6266
|
}
|
|
6262
6267
|
return { ok: true, addresses };
|
|
6263
6268
|
}
|
|
6264
|
-
async function vetEgress(host, port,
|
|
6265
|
-
return vetEgressUnresolved(host, port) ?? vetHost(host,
|
|
6269
|
+
async function vetEgress(host, port, resolve18 = resolveAll) {
|
|
6270
|
+
return vetEgressUnresolved(host, port) ?? vetHost(host, resolve18);
|
|
6266
6271
|
}
|
|
6267
6272
|
function vetEgressUnresolved(host, port) {
|
|
6268
6273
|
if (!ALLOWED_PORTS.has(port)) return { ok: false, reason: `port ${port} is not 80 or 443` };
|
|
6269
6274
|
return vetHostUnresolved(host);
|
|
6270
6275
|
}
|
|
6271
|
-
function guardedLookup(
|
|
6276
|
+
function guardedLookup(resolve18 = resolveAll) {
|
|
6272
6277
|
return (hostname, options, callback) => {
|
|
6273
|
-
void vetHost(hostname,
|
|
6278
|
+
void vetHost(hostname, resolve18).then((check2) => {
|
|
6274
6279
|
if (!check2.ok) {
|
|
6275
6280
|
callback(Object.assign(new Error(`blocked host: ${check2.reason}`), { code: "EBLOCKEDHOST" }), []);
|
|
6276
6281
|
return;
|
|
@@ -7377,10 +7382,139 @@ function allowlistRule(parts, allow, trustedResolves) {
|
|
|
7377
7382
|
}
|
|
7378
7383
|
|
|
7379
7384
|
// src/services/researchShell.ts
|
|
7385
|
+
var import_child_process = require("child_process");
|
|
7380
7386
|
var fsSync = __toESM(require("fs"));
|
|
7387
|
+
var path3 = __toESM(require("path"));
|
|
7388
|
+
|
|
7389
|
+
// src/services/pathScope.ts
|
|
7390
|
+
var os = __toESM(require("os"));
|
|
7381
7391
|
var path2 = __toESM(require("path"));
|
|
7392
|
+
function expandHome(target) {
|
|
7393
|
+
if (!target.startsWith("~")) return target;
|
|
7394
|
+
const home = os.homedir();
|
|
7395
|
+
if (target === "~" || target.startsWith("~/")) return path2.join(home, target.slice(1));
|
|
7396
|
+
return path2.join(path2.dirname(home), target.slice(1));
|
|
7397
|
+
}
|
|
7398
|
+
function resolveWithin(root, target, from = root, hostPath2) {
|
|
7399
|
+
const spelled = hostPath2 ? hostPath2(target, from) : target;
|
|
7400
|
+
if (spelled === void 0) return { abs: target, inside: false, unfollowable: true };
|
|
7401
|
+
if (hostPath2 && isInertDevice(spelled)) return { abs: spelled, inside: false, device: true };
|
|
7402
|
+
const abs = path2.resolve(from, expandHome(spelled));
|
|
7403
|
+
const rel = path2.relative(root, abs);
|
|
7404
|
+
return { abs, inside: rel === "" || !rel.startsWith("..") && !path2.isAbsolute(rel), ...isInertDevice(abs) ? { device: true } : {} };
|
|
7405
|
+
}
|
|
7406
|
+
function resolveRef(root, ref2, hostPath2) {
|
|
7407
|
+
let from = root;
|
|
7408
|
+
for (const target of ref2.cwd) {
|
|
7409
|
+
const dir = resolveWithin(root, target, from, hostPath2);
|
|
7410
|
+
if (dir.unfollowable) return { abs: ref2.path, inside: false, unfollowable: true };
|
|
7411
|
+
from = dir.abs;
|
|
7412
|
+
}
|
|
7413
|
+
return resolveWithin(root, ref2.path, from, hostPath2);
|
|
7414
|
+
}
|
|
7415
|
+
function grantScopeFor(abs, kind) {
|
|
7416
|
+
if (kind === "directory") return path2.join(abs, "*");
|
|
7417
|
+
const parent = path2.dirname(abs);
|
|
7418
|
+
if (parent === path2.parse(abs).root) return path2.join(abs, "*");
|
|
7419
|
+
return path2.join(parent, "*");
|
|
7420
|
+
}
|
|
7421
|
+
var INERT_DEVICES = ["/dev/null", "/dev/stdin", "/dev/stdout", "/dev/stderr"];
|
|
7422
|
+
function isInertDevice(abs) {
|
|
7423
|
+
return INERT_DEVICES.includes(abs);
|
|
7424
|
+
}
|
|
7425
|
+
|
|
7426
|
+
// src/services/researchShell.ts
|
|
7382
7427
|
var POSIX_SHELL = { file: null, args: [], dialect: "posix", utilsDir: null };
|
|
7383
7428
|
var CMD_SHELL = { file: null, args: [], dialect: "cmd", utilsDir: null };
|
|
7429
|
+
function defaultReadMounts(root) {
|
|
7430
|
+
const mount = path3.win32.join(root, "usr", "bin", "mount.exe");
|
|
7431
|
+
try {
|
|
7432
|
+
const read2 = (args) => (0, import_child_process.execFileSync)(mount, args, { encoding: "utf8", timeout: 5e3, windowsHide: true });
|
|
7433
|
+
return [read2([]), read2(["-p"])];
|
|
7434
|
+
} catch {
|
|
7435
|
+
return void 0;
|
|
7436
|
+
}
|
|
7437
|
+
}
|
|
7438
|
+
function parseMounts(mounts, prefix) {
|
|
7439
|
+
const points = [];
|
|
7440
|
+
for (const line of mounts.split(/\r?\n/)) {
|
|
7441
|
+
const m = /^(.+?) on (\/.*?) type \S+ \(([^)]*)\)/.exec(line);
|
|
7442
|
+
if (!m) continue;
|
|
7443
|
+
const host = m[1].replace(/\//g, "\\");
|
|
7444
|
+
points.push({ point: m[2], host: /^[A-Za-z]:$/.test(host) ? `${host}\\` : host, caseless: m[3].split(",").includes("posix=0") });
|
|
7445
|
+
}
|
|
7446
|
+
if (!points.some((p) => p.point === "/")) return void 0;
|
|
7447
|
+
const cygdrive = /^\s*(\/\S*)\s+\S+\s+\S+/m.exec(prefix.split(/\r?\n/).slice(1).join("\n"))?.[1] ?? "/";
|
|
7448
|
+
return { points, cygdrive };
|
|
7449
|
+
}
|
|
7450
|
+
function defaultMounts(root, env) {
|
|
7451
|
+
const temp = env.TEMP || env.TMP;
|
|
7452
|
+
return {
|
|
7453
|
+
points: [
|
|
7454
|
+
{ point: "/", host: root, caseless: false },
|
|
7455
|
+
{ point: "/bin", host: path3.win32.join(root, "usr", "bin"), caseless: false },
|
|
7456
|
+
...temp ? [{ point: "/tmp", host: temp, caseless: true }] : []
|
|
7457
|
+
],
|
|
7458
|
+
cygdrive: "/"
|
|
7459
|
+
};
|
|
7460
|
+
}
|
|
7461
|
+
function mountedHostPath(table, spelled, from, home) {
|
|
7462
|
+
if (isInertDevice(spelled)) return spelled;
|
|
7463
|
+
if (spelled.startsWith("/")) return mountedAbsolute(table, spelled.replace(/\\/g, "/"));
|
|
7464
|
+
if (home && (spelled === "~" || /^~[\\/]/.test(spelled))) {
|
|
7465
|
+
const base = home.startsWith("/") ? mountedAbsolute(table, home) : home;
|
|
7466
|
+
return base === void 0 ? void 0 : path3.win32.join(base, spelled.slice(1));
|
|
7467
|
+
}
|
|
7468
|
+
if (from === void 0 || /^[A-Za-z]:/.test(spelled) || spelled.startsWith("\\") || spelled.startsWith("~")) return spelled;
|
|
7469
|
+
return staysOnDrive(table, spelled.replace(/\\/g, "/"), from) ? spelled : void 0;
|
|
7470
|
+
}
|
|
7471
|
+
function mountedAbsolute(table, posix17) {
|
|
7472
|
+
if (/^\/\/[^/]/.test(posix17)) return posix17.replace(/\//g, "\\");
|
|
7473
|
+
const segments = posix17.split("/").filter((s) => s !== "" && s !== ".");
|
|
7474
|
+
if (segments.includes("..")) return void 0;
|
|
7475
|
+
const prefix = table.cygdrive.endsWith("/") ? table.cygdrive : `${table.cygdrive}/`;
|
|
7476
|
+
const top = segments[0]?.toLowerCase();
|
|
7477
|
+
if (top === "proc" && segments[1]?.toLowerCase() === "cygdrive") return mountedAbsolute(table, prefix + segments.slice(2).join("/"));
|
|
7478
|
+
if (top === "proc" || top === "dev") return void 0;
|
|
7479
|
+
const normal = `/${segments.join("/")}`;
|
|
7480
|
+
const under = ({ point, caseless }) => {
|
|
7481
|
+
if (point === "/") return true;
|
|
7482
|
+
const [at, here] = caseless ? [point.toLowerCase(), normal.toLowerCase()] : [point, normal];
|
|
7483
|
+
return here === at || here.startsWith(`${at}/`);
|
|
7484
|
+
};
|
|
7485
|
+
let best = table.points.filter(under).sort((a, b) => b.point.length - a.point.length)[0];
|
|
7486
|
+
const drive = normal.toLowerCase().startsWith(prefix.toLowerCase()) ? /^([a-z])(?:\/|$)/i.exec(normal.slice(prefix.length)) : null;
|
|
7487
|
+
if (drive && (!best || prefix.length + 1 > best.point.length)) {
|
|
7488
|
+
best = { point: normal.slice(0, prefix.length + 1), host: `${drive[1].toUpperCase()}:\\` };
|
|
7489
|
+
}
|
|
7490
|
+
if (!best) return void 0;
|
|
7491
|
+
const rest = normal.slice(best.point.length).split("/").filter(Boolean);
|
|
7492
|
+
return rest.length ? path3.win32.join(best.host, ...rest) : best.host;
|
|
7493
|
+
}
|
|
7494
|
+
function staysOnDrive(table, relative20, from) {
|
|
7495
|
+
if (!relative20.split("/").includes("..")) return true;
|
|
7496
|
+
const drive = /^([A-Za-z]):(?:[\\/]|$)/.exec(from);
|
|
7497
|
+
const underMount = table.points.some((p) => {
|
|
7498
|
+
if (/^[A-Za-z]:\\$/.test(p.host)) return false;
|
|
7499
|
+
const rel = path3.win32.relative(p.host, from);
|
|
7500
|
+
return !rel.startsWith("..") && !path3.win32.isAbsolute(rel);
|
|
7501
|
+
});
|
|
7502
|
+
if (!drive || underMount) return false;
|
|
7503
|
+
const top = `/${drive[1].toLowerCase()}`;
|
|
7504
|
+
const climbed = path3.posix.join(`${top}/${from.slice(drive[0].length).replace(/\\/g, "/")}`, relative20);
|
|
7505
|
+
return climbed === top || climbed.startsWith(`${top}/`);
|
|
7506
|
+
}
|
|
7507
|
+
function gitBashHostPath(root, env, readMounts) {
|
|
7508
|
+
let table;
|
|
7509
|
+
return (spelled, from) => {
|
|
7510
|
+
if (!spelled.startsWith("/") && !spelled.startsWith("~") && !/(^|[\\/])\.\.([\\/]|$)/.test(spelled)) return spelled;
|
|
7511
|
+
if (!table) {
|
|
7512
|
+
const read2 = readMounts(root);
|
|
7513
|
+
table = (read2 && parseMounts(...read2)) ?? defaultMounts(root, env);
|
|
7514
|
+
}
|
|
7515
|
+
return mountedHostPath(table, spelled, from, env.HOME);
|
|
7516
|
+
};
|
|
7517
|
+
}
|
|
7384
7518
|
function defaultExists(candidate) {
|
|
7385
7519
|
try {
|
|
7386
7520
|
return fsSync.statSync(candidate).isFile();
|
|
@@ -7390,9 +7524,9 @@ function defaultExists(candidate) {
|
|
|
7390
7524
|
}
|
|
7391
7525
|
function gitBashRoots(env) {
|
|
7392
7526
|
const roots = [
|
|
7393
|
-
env.ProgramFiles &&
|
|
7394
|
-
env["ProgramFiles(x86)"] &&
|
|
7395
|
-
env.LOCALAPPDATA &&
|
|
7527
|
+
env.ProgramFiles && path3.win32.join(env.ProgramFiles, "Git"),
|
|
7528
|
+
env["ProgramFiles(x86)"] && path3.win32.join(env["ProgramFiles(x86)"], "Git"),
|
|
7529
|
+
env.LOCALAPPDATA && path3.win32.join(env.LOCALAPPDATA, "Programs", "Git"),
|
|
7396
7530
|
"C:\\Program Files\\Git",
|
|
7397
7531
|
"C:\\Program Files (x86)\\Git"
|
|
7398
7532
|
].filter((r) => !!r);
|
|
@@ -7400,32 +7534,34 @@ function gitBashRoots(env) {
|
|
|
7400
7534
|
}
|
|
7401
7535
|
var cached = null;
|
|
7402
7536
|
function resolveResearchShell(deps = {}) {
|
|
7403
|
-
|
|
7537
|
+
const probe = !!(deps.platform || deps.exists || deps.env || deps.readMounts);
|
|
7538
|
+
if (cached && !probe) return cached;
|
|
7404
7539
|
const platform = deps.platform ?? process.platform;
|
|
7405
7540
|
if (platform !== "win32") {
|
|
7406
|
-
if (!
|
|
7541
|
+
if (!probe) cached = POSIX_SHELL;
|
|
7407
7542
|
return POSIX_SHELL;
|
|
7408
7543
|
}
|
|
7409
7544
|
const exists = deps.exists ?? defaultExists;
|
|
7410
7545
|
const env = deps.env ?? process.env;
|
|
7411
7546
|
for (const root of gitBashRoots(env)) {
|
|
7412
7547
|
for (const rel of [["bin", "bash.exe"], ["usr", "bin", "bash.exe"]]) {
|
|
7413
|
-
const file =
|
|
7548
|
+
const file = path3.win32.join(root, ...rel);
|
|
7414
7549
|
if (!exists(file)) continue;
|
|
7415
|
-
const utilsDir =
|
|
7550
|
+
const utilsDir = path3.win32.join(root, "usr", "bin");
|
|
7416
7551
|
const resolved2 = {
|
|
7417
7552
|
file,
|
|
7418
7553
|
// `-c`, not `-lc`: a login shell sources the user's profile, which can
|
|
7419
7554
|
// change directory out from under a command whose cwd is the workspace.
|
|
7420
7555
|
args: ["-c"],
|
|
7421
7556
|
dialect: "posix",
|
|
7422
|
-
utilsDir: exists(
|
|
7557
|
+
utilsDir: exists(path3.win32.join(utilsDir, "grep.exe")) ? utilsDir : null,
|
|
7558
|
+
hostPath: gitBashHostPath(root, env, deps.readMounts ?? defaultReadMounts)
|
|
7423
7559
|
};
|
|
7424
|
-
if (!
|
|
7560
|
+
if (!probe) cached = resolved2;
|
|
7425
7561
|
return resolved2;
|
|
7426
7562
|
}
|
|
7427
7563
|
}
|
|
7428
|
-
if (!
|
|
7564
|
+
if (!probe) cached = CMD_SHELL;
|
|
7429
7565
|
return CMD_SHELL;
|
|
7430
7566
|
}
|
|
7431
7567
|
function clearResearchShellCache() {
|
|
@@ -7433,8 +7569,8 @@ function clearResearchShellCache() {
|
|
|
7433
7569
|
}
|
|
7434
7570
|
function researchToolsPath(shell, basePath) {
|
|
7435
7571
|
if (!shell.utilsDir) return basePath ?? "";
|
|
7436
|
-
const segments = [shell.utilsDir, ...(basePath ?? "").split(
|
|
7437
|
-
return [...new Set(segments)].join(
|
|
7572
|
+
const segments = [shell.utilsDir, ...(basePath ?? "").split(path3.win32.delimiter)].filter(Boolean);
|
|
7573
|
+
return [...new Set(segments)].join(path3.win32.delimiter);
|
|
7438
7574
|
}
|
|
7439
7575
|
function researchShellWarning(shell) {
|
|
7440
7576
|
if (shell.dialect !== "cmd") return null;
|
|
@@ -7446,8 +7582,8 @@ function researchPolicyOptions(shell) {
|
|
|
7446
7582
|
|
|
7447
7583
|
// src/services/sandbox/plannerSandbox.ts
|
|
7448
7584
|
var fsSync3 = __toESM(require("fs"));
|
|
7449
|
-
var
|
|
7450
|
-
var
|
|
7585
|
+
var os2 = __toESM(require("os"));
|
|
7586
|
+
var path7 = __toESM(require("path"));
|
|
7451
7587
|
|
|
7452
7588
|
// src/services/researchStepSummary.ts
|
|
7453
7589
|
function ellipsize(text6, max) {
|
|
@@ -7529,11 +7665,11 @@ function classifyOutcome(success, output) {
|
|
|
7529
7665
|
|
|
7530
7666
|
// src/services/sandbox/bubblewrap.ts
|
|
7531
7667
|
var fsSync2 = __toESM(require("fs"));
|
|
7532
|
-
var
|
|
7668
|
+
var path5 = __toESM(require("path"));
|
|
7533
7669
|
|
|
7534
7670
|
// src/services/sandbox/SandboxBackend.ts
|
|
7535
|
-
var
|
|
7536
|
-
var
|
|
7671
|
+
var import_child_process2 = require("child_process");
|
|
7672
|
+
var path4 = __toESM(require("path"));
|
|
7537
7673
|
var MEMORY_LIMIT_SIGNAL = "SIGUSR2";
|
|
7538
7674
|
var SandboxUnsupportedError = class extends Error {
|
|
7539
7675
|
constructor(backend, what) {
|
|
@@ -7544,7 +7680,7 @@ var SandboxUnsupportedError = class extends Error {
|
|
|
7544
7680
|
function assertProfilePaths(backend, profile) {
|
|
7545
7681
|
const paths = [...profile.write, ...profile.linkless ?? [], ...profile.gitWorktrees ?? [], ...(profile.gitEntries ?? []).map((entry) => entry.path), ...profile.gitless ?? [], ...profile.read === "host" ? [] : profile.read, ...profile.throwaway ?? [], ...profile.masked ?? []];
|
|
7546
7682
|
for (const p of paths) {
|
|
7547
|
-
if (!
|
|
7683
|
+
if (!path4.posix.isAbsolute(p) || p.includes("\0")) throw new SandboxUnsupportedError(backend, `the path ${JSON.stringify(p)}`);
|
|
7548
7684
|
}
|
|
7549
7685
|
}
|
|
7550
7686
|
function assertLimits(backend, limits) {
|
|
@@ -7556,14 +7692,14 @@ function keptEnv(invocation, profile) {
|
|
|
7556
7692
|
return profile.inheritEnv === void 0 ? invocation.env : Object.fromEntries(profile.inheritEnv.flatMap((name) => invocation.env[name] === void 0 ? [] : [[name, invocation.env[name]]]));
|
|
7557
7693
|
}
|
|
7558
7694
|
var PROBE_TIMEOUT_MS = 1e4;
|
|
7559
|
-
var execProbe = (file, args, env) => new Promise((
|
|
7695
|
+
var execProbe = (file, args, env) => new Promise((resolve18) => {
|
|
7560
7696
|
try {
|
|
7561
|
-
(0,
|
|
7697
|
+
(0, import_child_process2.execFile)(file, args, { env, timeout: PROBE_TIMEOUT_MS, encoding: "utf8" }, (err, stdout, stderr) => {
|
|
7562
7698
|
const code = !err ? 0 : typeof err.code === "number" ? err.code : null;
|
|
7563
|
-
|
|
7699
|
+
resolve18({ code, output: `${stdout ?? ""}${stderr ?? ""}`.trim() || (err?.message ?? "") });
|
|
7564
7700
|
});
|
|
7565
7701
|
} catch (err) {
|
|
7566
|
-
|
|
7702
|
+
resolve18({ code: null, output: err instanceof Error ? err.message : String(err) });
|
|
7567
7703
|
}
|
|
7568
7704
|
});
|
|
7569
7705
|
async function probeByRunning(backend, profile, exec5) {
|
|
@@ -7580,7 +7716,7 @@ async function probeByRunning(backend, profile, exec5) {
|
|
|
7580
7716
|
// src/services/sandbox/bubblewrap.ts
|
|
7581
7717
|
var SYSTEM_BWRAP = ["/usr/bin/bwrap", "/bin/bwrap", "/usr/local/bin/bwrap", "/run/current-system/sw/bin/bwrap"];
|
|
7582
7718
|
function findBubblewrap(env, exists) {
|
|
7583
|
-
const onPath = (env.PATH ?? "").split(
|
|
7719
|
+
const onPath = (env.PATH ?? "").split(path5.posix.delimiter).filter((dir) => path5.posix.isAbsolute(dir)).map((dir) => path5.posix.join(dir, "bwrap"));
|
|
7584
7720
|
return [.../* @__PURE__ */ new Set([...SYSTEM_BWRAP, ...onPath])].find(exists) ?? null;
|
|
7585
7721
|
}
|
|
7586
7722
|
function defaultIsDirectory(p) {
|
|
@@ -7675,7 +7811,7 @@ var BubblewrapBackend = class {
|
|
|
7675
7811
|
for (const p of shallowFirst(profile.masked ?? [])) args.push(...this.isDirectory(p) ? ["--tmpfs", p] : ["--ro-bind", "/dev/null", p]);
|
|
7676
7812
|
for (const p of shallowFirst(profile.write)) args.push("--bind", p, p);
|
|
7677
7813
|
const readOnlyGit = /* @__PURE__ */ new Set([
|
|
7678
|
-
...(profile.gitWorktrees ?? []).map((worktree) =>
|
|
7814
|
+
...(profile.gitWorktrees ?? []).map((worktree) => path5.posix.join(worktree, ".git")),
|
|
7679
7815
|
...(profile.gitEntries ?? []).map((entry) => entry.path)
|
|
7680
7816
|
]);
|
|
7681
7817
|
for (const gitPath of readOnlyGit) args.push("--ro-bind", gitPath, gitPath);
|
|
@@ -7688,7 +7824,7 @@ var BubblewrapBackend = class {
|
|
|
7688
7824
|
};
|
|
7689
7825
|
|
|
7690
7826
|
// src/services/sandbox/seatbelt.ts
|
|
7691
|
-
var
|
|
7827
|
+
var path6 = __toESM(require("path"));
|
|
7692
7828
|
var SANDBOX_EXEC = "/usr/bin/sandbox-exec";
|
|
7693
7829
|
var BASE_PROFILE = `(version 1)
|
|
7694
7830
|
(deny default)
|
|
@@ -7847,7 +7983,7 @@ var SeatbeltBackend = class {
|
|
|
7847
7983
|
if (profile.write.length) rules.push(`(allow file-read* file-test-existence file-map-executable file-write* ${filters("WRITABLE", "subpath", profile.write)})`);
|
|
7848
7984
|
if (profile.linkless?.length) rules.push(`(deny file-write-create (require-all (vnode-type SYMLINK) (require-any ${filters("LINKLESS", "subpath", profile.linkless)})))`);
|
|
7849
7985
|
if (profile.gitWorktrees?.length) {
|
|
7850
|
-
const gitDirs = profile.gitWorktrees.map((worktree) =>
|
|
7986
|
+
const gitDirs = profile.gitWorktrees.map((worktree) => path6.posix.join(worktree, ".git"));
|
|
7851
7987
|
rules.push(`(deny file-write* ${filters("GIT", "literal", gitDirs)})`);
|
|
7852
7988
|
rules.push(`(deny file-write* ${filters("WORKTREE", "literal", profile.gitWorktrees)})`);
|
|
7853
7989
|
}
|
|
@@ -7876,13 +8012,13 @@ var SeatbeltBackend = class {
|
|
|
7876
8012
|
function directoriesAbove(paths) {
|
|
7877
8013
|
const above = /* @__PURE__ */ new Set();
|
|
7878
8014
|
for (const p of paths) {
|
|
7879
|
-
for (let dir =
|
|
8015
|
+
for (let dir = path6.posix.dirname(p); dir !== "/" && !above.has(dir); dir = path6.posix.dirname(dir)) above.add(dir);
|
|
7880
8016
|
}
|
|
7881
8017
|
return [...above];
|
|
7882
8018
|
}
|
|
7883
8019
|
|
|
7884
8020
|
// src/utils/processTree.ts
|
|
7885
|
-
var
|
|
8021
|
+
var import_child_process3 = require("child_process");
|
|
7886
8022
|
var HARD_KILL_DELAY_MS = 5e3;
|
|
7887
8023
|
function isNoSuchProcess(err) {
|
|
7888
8024
|
return typeof err === "object" && err !== null && "code" in err && err.code === "ESRCH";
|
|
@@ -7904,7 +8040,7 @@ function spawnInOwnGroup(spawn3, platform = process.platform) {
|
|
|
7904
8040
|
if (typeof pgid !== "number") return proc;
|
|
7905
8041
|
groupLeaders.add(proc);
|
|
7906
8042
|
ownGroups.set(pgid, proc);
|
|
7907
|
-
if (proc instanceof
|
|
8043
|
+
if (proc instanceof import_child_process3.ChildProcess) watchForHostDeath(pgid);
|
|
7908
8044
|
proc.once("exit", () => {
|
|
7909
8045
|
if (!groupHasMembers(pgid)) forgetGroup(proc, pgid);
|
|
7910
8046
|
});
|
|
@@ -7916,7 +8052,7 @@ function watchForHostDeath(pgid) {
|
|
|
7916
8052
|
const group = `-- -${pgid}`;
|
|
7917
8053
|
const seconds = HARD_KILL_DELAY_MS / 1e3;
|
|
7918
8054
|
const stop2 = `read _ || kill -s TERM ${group} 2>/dev/null; i=0; while [ "$i" -lt ${seconds} ] && kill -s 0 ${group} 2>/dev/null; do sleep 1; i=$((i + 1)); done; kill -s 0 ${group} 2>/dev/null && kill -s KILL ${group} 2>/dev/null`;
|
|
7919
|
-
const watch2 = (0,
|
|
8055
|
+
const watch2 = (0, import_child_process3.spawn)("/bin/sh", ["-c", stop2], { detached: true, cwd: "/", stdio: ["pipe", "ignore", "ignore"] });
|
|
7920
8056
|
watch2.on("error", () => {
|
|
7921
8057
|
hostWatches.delete(pgid);
|
|
7922
8058
|
});
|
|
@@ -8009,7 +8145,7 @@ function hookHostTeardown() {
|
|
|
8009
8145
|
}
|
|
8010
8146
|
}
|
|
8011
8147
|
function defaultExecFile(file, args, cb) {
|
|
8012
|
-
(0,
|
|
8148
|
+
(0, import_child_process3.execFile)(file, args, (err) => cb(err ?? null));
|
|
8013
8149
|
}
|
|
8014
8150
|
function killTree(proc, deps = {}) {
|
|
8015
8151
|
if (!proc) return;
|
|
@@ -8021,12 +8157,12 @@ function killTree(proc, deps = {}) {
|
|
|
8021
8157
|
if (typeof proc.pid !== "number") return;
|
|
8022
8158
|
const pid = proc.pid;
|
|
8023
8159
|
const run = deps.execFileImpl ?? defaultExecFile;
|
|
8024
|
-
run("taskkill", ["/pid", String(pid), "/T"], () => {
|
|
8160
|
+
const force = () => run("taskkill", ["/pid", String(pid), "/T", "/F"], () => {
|
|
8025
8161
|
});
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8162
|
+
run("taskkill", ["/pid", String(pid), "/T"], (err) => {
|
|
8163
|
+
if (err && !hasExited(proc)) force();
|
|
8164
|
+
});
|
|
8165
|
+
const hardKill = setTimeoutImpl(force, HARD_KILL_DELAY_MS);
|
|
8030
8166
|
hardKill.unref?.();
|
|
8031
8167
|
proc.once("exit", () => clearTimeoutImpl(hardKill));
|
|
8032
8168
|
return;
|
|
@@ -8105,22 +8241,22 @@ function scratchEnv(scratch, platform) {
|
|
|
8105
8241
|
GIT_OPTIONAL_LOCKS: "0",
|
|
8106
8242
|
// npm writes a debug log under its cache for every command, `npm ls` too,
|
|
8107
8243
|
// and records its update check there.
|
|
8108
|
-
npm_config_cache:
|
|
8244
|
+
npm_config_cache: path7.join(scratch, "npm"),
|
|
8109
8245
|
npm_config_update_notifier: "false",
|
|
8110
8246
|
// `go list` opens the build cache.
|
|
8111
|
-
GOCACHE:
|
|
8247
|
+
GOCACHE: path7.join(scratch, "go-build"),
|
|
8112
8248
|
// Where Linux tools that follow the XDG layout (pip among them) keep caches.
|
|
8113
|
-
XDG_CACHE_HOME:
|
|
8249
|
+
XDG_CACHE_HOME: path7.join(scratch, "cache"),
|
|
8114
8250
|
// Python otherwise writes bytecode beside the sources, in the workspace.
|
|
8115
|
-
PYTHONPYCACHEPREFIX:
|
|
8251
|
+
PYTHONPYCACHEPREFIX: path7.join(scratch, "pycache"),
|
|
8116
8252
|
// The `/usr/bin` shims of Apple's command-line tools (`git` among them)
|
|
8117
8253
|
// cache lookups in the user's temporary directory, ignoring TMPDIR, and
|
|
8118
8254
|
// print an error on every call when they cannot.
|
|
8119
|
-
...platform === "darwin" ? { xcrun_db:
|
|
8255
|
+
...platform === "darwin" ? { xcrun_db: path7.join(scratch, "xcrun_db") } : {}
|
|
8120
8256
|
};
|
|
8121
8257
|
}
|
|
8122
8258
|
function localServices(env, stat, uid) {
|
|
8123
|
-
const runtimeDir = env.XDG_RUNTIME_DIR &&
|
|
8259
|
+
const runtimeDir = env.XDG_RUNTIME_DIR && path7.posix.isAbsolute(env.XDG_RUNTIME_DIR) ? env.XDG_RUNTIME_DIR : void 0;
|
|
8124
8260
|
const candidates = [runtimeDir, uid === void 0 ? void 0 : `/run/user/${uid}`, "/run/dbus", "/tmp/.X11-unix", "/run/docker.sock"];
|
|
8125
8261
|
const found = candidates.flatMap((p) => p ? [stat(p)?.canonical] : []).filter((p) => !!p && p !== "/");
|
|
8126
8262
|
return [...new Set(found)];
|
|
@@ -8225,8 +8361,8 @@ function sealedShellProfile(host, opts) {
|
|
|
8225
8361
|
};
|
|
8226
8362
|
}
|
|
8227
8363
|
function strictlyWithin(child, parent) {
|
|
8228
|
-
const rel =
|
|
8229
|
-
return rel !== "" && !rel.startsWith("..") && !
|
|
8364
|
+
const rel = path7.relative(parent, child);
|
|
8365
|
+
return rel !== "" && !rel.startsWith("..") && !path7.isAbsolute(rel);
|
|
8230
8366
|
}
|
|
8231
8367
|
function canonicalGitEntries(entries) {
|
|
8232
8368
|
return entries.flatMap((entry) => {
|
|
@@ -8279,9 +8415,9 @@ async function detect(deps) {
|
|
|
8279
8415
|
}
|
|
8280
8416
|
return unavailable(`${backend.name} could not start (${detail})`);
|
|
8281
8417
|
}
|
|
8282
|
-
async function detectSealed(backend, platform, stat, probeWorkspace =
|
|
8418
|
+
async function detectSealed(backend, platform, stat, probeWorkspace = os2.tmpdir()) {
|
|
8283
8419
|
const existing = (paths) => (paths ?? []).filter((p) => stat(p) !== null);
|
|
8284
|
-
const named3 = (paths) => platform === "darwin" ? paths.map((p) =>
|
|
8420
|
+
const named3 = (paths) => platform === "darwin" ? paths.map((p) => path7.posix.join(stat(path7.posix.dirname(p))?.canonical ?? path7.posix.dirname(p), path7.posix.basename(p))) : paths;
|
|
8285
8421
|
const developerDir = platform === "darwin" ? stat("/private/var/select/developer_dir")?.canonical : void 0;
|
|
8286
8422
|
const reads = [.../* @__PURE__ */ new Set([...named3(existing(SEALED_READS[platform])), ...developerDir ? [developerDir] : []])];
|
|
8287
8423
|
const masked = named3(existing(SEALED_MASKS[platform]));
|
|
@@ -8329,7 +8465,7 @@ function sweepOrphanScratch(root) {
|
|
|
8329
8465
|
for (const name of names2) {
|
|
8330
8466
|
const pid = Number(/^ordewell-planner-(\d+)-/.exec(name)?.[1]);
|
|
8331
8467
|
if (!pid || pid === process.pid || processAlive(pid)) continue;
|
|
8332
|
-
const dir =
|
|
8468
|
+
const dir = path7.join(root, name);
|
|
8333
8469
|
try {
|
|
8334
8470
|
const stat = fsSync3.lstatSync(dir);
|
|
8335
8471
|
if (stat.isDirectory() && stat.uid === process.getuid?.()) fsSync3.rmSync(dir, { recursive: true, force: true });
|
|
@@ -8343,15 +8479,15 @@ function createScratch() {
|
|
|
8343
8479
|
process.once("exit", () => {
|
|
8344
8480
|
for (const dir2 of [...liveScratch]) removeScratch(dir2);
|
|
8345
8481
|
});
|
|
8346
|
-
sweepOrphanScratch(
|
|
8482
|
+
sweepOrphanScratch(os2.tmpdir());
|
|
8347
8483
|
}
|
|
8348
|
-
const dir = fsSync3.realpathSync(fsSync3.mkdtempSync(
|
|
8484
|
+
const dir = fsSync3.realpathSync(fsSync3.mkdtempSync(path7.join(os2.tmpdir(), `ordewell-planner-${process.pid}-`)));
|
|
8349
8485
|
liveScratch.add(dir);
|
|
8350
8486
|
return dir;
|
|
8351
8487
|
}
|
|
8352
8488
|
var PlannerShellSandbox = class _PlannerShellSandbox {
|
|
8353
|
-
constructor(
|
|
8354
|
-
this.resolve =
|
|
8489
|
+
constructor(resolve18 = () => resolvePlannerSandbox()) {
|
|
8490
|
+
this.resolve = resolve18;
|
|
8355
8491
|
}
|
|
8356
8492
|
resolve;
|
|
8357
8493
|
scratch = /* @__PURE__ */ new Map();
|
|
@@ -8500,35 +8636,6 @@ function sealedMemoryLimitNote(outcome, memoryBytes, forTask) {
|
|
|
8500
8636
|
}
|
|
8501
8637
|
var SEALED_FAILURE_NOTE = "A sealed run cannot reach the network, the user's credentials or their files outside the workspace, and cannot change the workspace, so running it sealed again fails the same way. To read something it could not, run each command on its own, without a loop or inline code, so Ordewell's command rules can judge it; a change belongs in the plan as a task.";
|
|
8502
8638
|
|
|
8503
|
-
// src/services/pathScope.ts
|
|
8504
|
-
var os2 = __toESM(require("os"));
|
|
8505
|
-
var path7 = __toESM(require("path"));
|
|
8506
|
-
function expandHome(target) {
|
|
8507
|
-
if (!target.startsWith("~")) return target;
|
|
8508
|
-
const home = os2.homedir();
|
|
8509
|
-
if (target === "~" || target.startsWith("~/")) return path7.join(home, target.slice(1));
|
|
8510
|
-
return path7.join(path7.dirname(home), target.slice(1));
|
|
8511
|
-
}
|
|
8512
|
-
function resolveWithin(root, target, from = root) {
|
|
8513
|
-
const abs = path7.resolve(from, expandHome(target));
|
|
8514
|
-
const rel = path7.relative(root, abs);
|
|
8515
|
-
return { abs, inside: rel === "" || !rel.startsWith("..") && !path7.isAbsolute(rel) };
|
|
8516
|
-
}
|
|
8517
|
-
function resolveRef(root, ref2) {
|
|
8518
|
-
const from = ref2.cwd.reduce((dir, target) => resolveWithin(root, target, dir).abs, root);
|
|
8519
|
-
return resolveWithin(root, ref2.path, from);
|
|
8520
|
-
}
|
|
8521
|
-
function grantScopeFor(abs, kind) {
|
|
8522
|
-
if (kind === "directory") return path7.join(abs, "*");
|
|
8523
|
-
const parent = path7.dirname(abs);
|
|
8524
|
-
if (parent === path7.parse(abs).root) return path7.join(abs, "*");
|
|
8525
|
-
return path7.join(parent, "*");
|
|
8526
|
-
}
|
|
8527
|
-
var INERT_DEVICES = ["/dev/null", "/dev/stdin", "/dev/stdout", "/dev/stderr"];
|
|
8528
|
-
function isInertDevice(abs) {
|
|
8529
|
-
return INERT_DEVICES.includes(abs);
|
|
8530
|
-
}
|
|
8531
|
-
|
|
8532
8639
|
// src/services/symbolPatterns.ts
|
|
8533
8640
|
var SYMBOL_LANGUAGES = [
|
|
8534
8641
|
{
|
|
@@ -8868,6 +8975,9 @@ var CD_HINT = ' A "cd" is followed only on a line joined by "&&" alone, so after
|
|
|
8868
8975
|
function refusal(output) {
|
|
8869
8976
|
return { success: false, output, truncated: false };
|
|
8870
8977
|
}
|
|
8978
|
+
function unfollowableReason(spelled) {
|
|
8979
|
+
return `Git Bash reads "${spelled}" by rules this check cannot follow, so it cannot tell which folder the command would reach: a ".." past one of its mounts, or its own /proc or /dev. Name the path from its drive (/c/Users/...) or as a Windows path (C:\\Users\\...), with no "..".`;
|
|
8980
|
+
}
|
|
8871
8981
|
var TASK_UNSEALED = "A read-only task asks nobody, so this command could only run sealed, and this machine has no sandbox to seal it in.";
|
|
8872
8982
|
var OWN_UNSEALED = "this machine has no sandbox to seal it in, and Ordewell runs nothing in a read-only task's worktree outside one.";
|
|
8873
8983
|
var TASK_CONTINUE = "Continue without it, and say in your report if what it would have shown matters.";
|
|
@@ -9040,12 +9150,13 @@ ${refs.output.trim()}`);
|
|
|
9040
9150
|
outsidePaths(command, root) {
|
|
9041
9151
|
const found = /* @__PURE__ */ new Map();
|
|
9042
9152
|
for (const ref2 of pathRefs(command, this.policyOptions())) {
|
|
9043
|
-
const { abs, inside: inside2 } = resolveRef(root, ref2);
|
|
9044
|
-
if (
|
|
9153
|
+
const { abs, inside: inside2, device, unfollowable } = resolveRef(root, ref2, this.researchShell.hostPath);
|
|
9154
|
+
if (unfollowable) return { outside: [], unfollowable: ref2.path };
|
|
9155
|
+
if (inside2 || device) continue;
|
|
9045
9156
|
const scope = grantScopeFor(abs, "file");
|
|
9046
9157
|
if (!found.has(scope)) found.set(scope, abs);
|
|
9047
9158
|
}
|
|
9048
|
-
return [...found].map(([scope, abs]) => ({ abs, scope }));
|
|
9159
|
+
return { outside: [...found].map(([scope, abs]) => ({ abs, scope })) };
|
|
9049
9160
|
}
|
|
9050
9161
|
policyOptions() {
|
|
9051
9162
|
return researchPolicyOptions(this.researchShell);
|
|
@@ -9136,7 +9247,7 @@ ${TASK_CONTINUE}`);
|
|
|
9136
9247
|
...approval.commandPolicy?.(),
|
|
9137
9248
|
...allow ? { allow } : {}
|
|
9138
9249
|
});
|
|
9139
|
-
const outside = this.outsidePaths(command, root);
|
|
9250
|
+
const { outside, unfollowable } = this.outsidePaths(command, root);
|
|
9140
9251
|
const asks = tier === "ask";
|
|
9141
9252
|
const scopes = [...asks ? commandScopes ?? [scope] : [], ...outside.map((o) => o.scope)];
|
|
9142
9253
|
const touched = outside.map((o) => o.abs).join(", ");
|
|
@@ -9155,6 +9266,8 @@ ${TASK_CONTINUE}`);
|
|
|
9155
9266
|
}
|
|
9156
9267
|
if (site.task?.sealed) return this.runSealed(site, command, request, "after", signal);
|
|
9157
9268
|
if (tier === "refuse") return this.sealedInstead(site, command, request, refusal(`Command refused: ${reason}${site.task ? `
|
|
9269
|
+
${TASK_UNSEALED} ${TASK_CONTINUE}` : ""}`), signal);
|
|
9270
|
+
if (unfollowable !== void 0) return this.sealedInstead(site, command, request, refusal(`Command refused: ${unfollowableReason(unfollowable)}${site.task ? `
|
|
9158
9271
|
${TASK_UNSEALED} ${TASK_CONTINUE}` : ""}`), signal);
|
|
9159
9272
|
const outbound = [...outboundTexts ?? [], ...(webUrls ?? []).map((url) => url.href)];
|
|
9160
9273
|
if (outbound.length && carriesSecret(outbound, [...this.outboundSecrets(), ...sensitiveEnvValues(process.env)])) {
|
|
@@ -9504,33 +9617,33 @@ function grepOptions(args) {
|
|
|
9504
9617
|
};
|
|
9505
9618
|
}
|
|
9506
9619
|
var STOPPED_TOOL_RESULT = "Stopped by the user \u2014 this call was not executed, and no further tool calls will run this turn.";
|
|
9507
|
-
async function executeTool(name, args,
|
|
9508
|
-
const outcome = await runTool(name, args,
|
|
9620
|
+
async function executeTool(name, args, fs29, fetcher, signal) {
|
|
9621
|
+
const outcome = await runTool(name, args, fs29, fetcher, signal);
|
|
9509
9622
|
return { ...outcome, output: redactSecrets(outcome.output) };
|
|
9510
9623
|
}
|
|
9511
|
-
async function runTool(name, args,
|
|
9624
|
+
async function runTool(name, args, fs29, fetcher, signal) {
|
|
9512
9625
|
if (signal?.aborted) return { success: false, output: STOPPED_TOOL_RESULT, truncated: false };
|
|
9513
9626
|
switch (name) {
|
|
9514
9627
|
case "read_file": {
|
|
9515
9628
|
const offset = num(args.offset);
|
|
9516
9629
|
const limit = num(args.limit);
|
|
9517
9630
|
const maxBytes = num(args.maxBytes);
|
|
9518
|
-
return
|
|
9631
|
+
return fs29.readFile(String(args.path ?? ""), { offset, limit, maxBytes });
|
|
9519
9632
|
}
|
|
9520
9633
|
case "read_files": {
|
|
9521
9634
|
const paths = Array.isArray(args.paths) ? args.paths.map(String) : [];
|
|
9522
|
-
return
|
|
9635
|
+
return fs29.readFiles(paths);
|
|
9523
9636
|
}
|
|
9524
9637
|
case "glob":
|
|
9525
|
-
return
|
|
9638
|
+
return fs29.glob(String(args.pattern ?? ""), { path: str(args.path), headLimit: num(args.head_limit ?? args.headLimit) });
|
|
9526
9639
|
case "grep":
|
|
9527
|
-
return
|
|
9640
|
+
return fs29.grep(String(args.pattern ?? ""), grepOptions(args));
|
|
9528
9641
|
case "find_symbol":
|
|
9529
|
-
return
|
|
9642
|
+
return fs29.findSymbol(String(args.symbol ?? ""), { language: str(args.language), path: str(args.path) });
|
|
9530
9643
|
case "list_dir":
|
|
9531
|
-
return
|
|
9644
|
+
return fs29.listDir(String(args.path ?? ""), num(args.depth));
|
|
9532
9645
|
case "bash":
|
|
9533
|
-
return args.sealed === true ?
|
|
9646
|
+
return args.sealed === true ? fs29.bash(String(args.command ?? ""), signal, { sealed: true }) : fs29.bash(String(args.command ?? ""), signal);
|
|
9534
9647
|
case "fetch": {
|
|
9535
9648
|
if (!fetcher) return { success: false, output: "Web fetching is not available in this environment.", truncated: false };
|
|
9536
9649
|
return fetcher.fetch(String(args.url ?? ""));
|
|
@@ -10302,7 +10415,7 @@ function decodedBody(res) {
|
|
|
10302
10415
|
return decoder;
|
|
10303
10416
|
}
|
|
10304
10417
|
function pinnedTransport(lookup2) {
|
|
10305
|
-
return (url, init) => new Promise((
|
|
10418
|
+
return (url, init) => new Promise((resolve18, reject) => {
|
|
10306
10419
|
const target = new URL(url);
|
|
10307
10420
|
const client = target.protocol === "https:" ? https : http;
|
|
10308
10421
|
const req = client.request(
|
|
@@ -10323,7 +10436,7 @@ function pinnedTransport(lookup2) {
|
|
|
10323
10436
|
(res) => {
|
|
10324
10437
|
res.on("error", () => void 0);
|
|
10325
10438
|
const body = decodedBody(res);
|
|
10326
|
-
|
|
10439
|
+
resolve18({
|
|
10327
10440
|
ok: res.statusCode !== void 0 && res.statusCode >= 200 && res.statusCode < 300,
|
|
10328
10441
|
status: res.statusCode ?? 0,
|
|
10329
10442
|
headers: headerGetter(res),
|
|
@@ -10666,7 +10779,7 @@ var PendingApprovals = class {
|
|
|
10666
10779
|
return Promise.resolve(refused5);
|
|
10667
10780
|
}
|
|
10668
10781
|
const pending = { id: id2, request, createdAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
10669
|
-
return new Promise((
|
|
10782
|
+
return new Promise((resolve18) => {
|
|
10670
10783
|
const settle = (decision) => {
|
|
10671
10784
|
const entry = this.entries.get(id2);
|
|
10672
10785
|
if (!entry) return;
|
|
@@ -10674,7 +10787,7 @@ var PendingApprovals = class {
|
|
|
10674
10787
|
this.entries.delete(id2);
|
|
10675
10788
|
options.onDecision?.(decision);
|
|
10676
10789
|
this.opts.onSettled?.(id2, isGranted(decision), { request, decision });
|
|
10677
|
-
|
|
10790
|
+
resolve18(decision);
|
|
10678
10791
|
};
|
|
10679
10792
|
let timer = null;
|
|
10680
10793
|
if (!options.noTimeout) {
|
|
@@ -11587,16 +11700,35 @@ function grepRegexFromProbe(exitCode) {
|
|
|
11587
11700
|
return exitCode === 0 || exitCode === 1 ? "pcre" : "ere";
|
|
11588
11701
|
}
|
|
11589
11702
|
function toPosixClasses(pattern) {
|
|
11703
|
+
const converted = convertForEre(pattern, true);
|
|
11704
|
+
return converted ?? convertForEre(pattern, false);
|
|
11705
|
+
}
|
|
11706
|
+
var BACKREFERENCE = /\0([1-9])\0/g;
|
|
11707
|
+
function convertForEre(pattern, plainGroups) {
|
|
11590
11708
|
const CLASS_ESCAPES = { s: "[:space:]", w: "[:alnum:]_", d: "[:digit:]", t: " " };
|
|
11709
|
+
const groupOf = [];
|
|
11710
|
+
let groups = 0;
|
|
11711
|
+
let captures = 0;
|
|
11591
11712
|
let out = "";
|
|
11592
11713
|
let i = 0;
|
|
11593
11714
|
while (i < pattern.length) {
|
|
11594
11715
|
const c = pattern[i];
|
|
11595
11716
|
if (c === "\\") {
|
|
11596
|
-
|
|
11717
|
+
const next = pattern[i + 1] ?? "";
|
|
11718
|
+
out += /[1-9]/.test(next) ? `\0${next}\0` : pattern.slice(i, i + 2);
|
|
11597
11719
|
i += 2;
|
|
11598
11720
|
continue;
|
|
11599
11721
|
}
|
|
11722
|
+
if (c === "(") {
|
|
11723
|
+
groups++;
|
|
11724
|
+
if (plainGroups && pattern.startsWith("(?:", i)) {
|
|
11725
|
+
out += "(";
|
|
11726
|
+
i += 3;
|
|
11727
|
+
continue;
|
|
11728
|
+
}
|
|
11729
|
+
const named3 = /^\(\?(?:P?<(?![=!])|')/.test(pattern.slice(i, i + 4));
|
|
11730
|
+
if (pattern[i + 1] !== "?" || named3) groupOf[++captures] = groups;
|
|
11731
|
+
}
|
|
11600
11732
|
if (c !== "[") {
|
|
11601
11733
|
out += c;
|
|
11602
11734
|
i++;
|
|
@@ -11613,7 +11745,12 @@ function toPosixClasses(pattern) {
|
|
|
11613
11745
|
let closeBracket = false;
|
|
11614
11746
|
let openBracket = false;
|
|
11615
11747
|
let dash = false;
|
|
11748
|
+
let caret = false;
|
|
11616
11749
|
let closed = false;
|
|
11750
|
+
if (pattern[i] === "]") {
|
|
11751
|
+
closeBracket = true;
|
|
11752
|
+
i++;
|
|
11753
|
+
}
|
|
11617
11754
|
while (i < pattern.length) {
|
|
11618
11755
|
const ch = pattern[i];
|
|
11619
11756
|
if (ch === "]") {
|
|
@@ -11636,6 +11773,7 @@ function toPosixClasses(pattern) {
|
|
|
11636
11773
|
else if (e === "]") closeBracket = true;
|
|
11637
11774
|
else if (e === "[") openBracket = true;
|
|
11638
11775
|
else if (e === "-") dash = true;
|
|
11776
|
+
else if (e === "^") caret = true;
|
|
11639
11777
|
else body += e;
|
|
11640
11778
|
continue;
|
|
11641
11779
|
}
|
|
@@ -11646,9 +11784,17 @@ function toPosixClasses(pattern) {
|
|
|
11646
11784
|
out += pattern.slice(start);
|
|
11647
11785
|
break;
|
|
11648
11786
|
}
|
|
11649
|
-
|
|
11787
|
+
const members = `${closeBracket ? "]" : ""}${body}`;
|
|
11788
|
+
if (caret && !negate && members === "") out += openBracket || dash ? `[${dash ? "-" : ""}${openBracket ? "[" : ""}^]` : "\\^";
|
|
11789
|
+
else out += `[${negate ? "^" : ""}${members}${caret ? "^" : ""}${openBracket ? "[" : ""}${dash ? "-" : ""}]`;
|
|
11650
11790
|
}
|
|
11651
|
-
|
|
11791
|
+
let representable = true;
|
|
11792
|
+
const renumbered2 = out.replace(BACKREFERENCE, (_, n) => {
|
|
11793
|
+
const group = plainGroups ? groupOf[Number(n)] ?? Number(n) : Number(n);
|
|
11794
|
+
if (group > 9) representable = false;
|
|
11795
|
+
return `\\${group}`;
|
|
11796
|
+
});
|
|
11797
|
+
return representable ? renumbered2 : null;
|
|
11652
11798
|
}
|
|
11653
11799
|
function buildFallbackGrepArgs(pattern, opts, root, regex = "pcre") {
|
|
11654
11800
|
const args = ["-r", "-n"];
|
|
@@ -11684,7 +11830,7 @@ function filterFallbackByAnchoredInclude(stdout, include, anchor, outputMode) {
|
|
|
11684
11830
|
if (!line) return false;
|
|
11685
11831
|
const reportedPath = extractFallbackGrepPath(line, outputMode);
|
|
11686
11832
|
const relPath = import_node_path.default.isAbsolute(reportedPath) ? import_node_path.default.relative(anchor, reportedPath) : reportedPath;
|
|
11687
|
-
return matchesAnchoredGlob(relPath, include);
|
|
11833
|
+
return matchesAnchoredGlob(relPath.split(import_node_path.default.sep).join("/"), include);
|
|
11688
11834
|
}).join("\n");
|
|
11689
11835
|
}
|
|
11690
11836
|
function applyHeadLimit(stdout, headLimit) {
|
|
@@ -11693,9 +11839,14 @@ function applyHeadLimit(stdout, headLimit) {
|
|
|
11693
11839
|
}
|
|
11694
11840
|
function formatSearchOutput(capped, root, opts) {
|
|
11695
11841
|
if (capped.rows.length === 0) return opts.emptyMessage;
|
|
11696
|
-
const
|
|
11697
|
-
const prefix = root ===
|
|
11698
|
-
const
|
|
11842
|
+
const sep13 = opts.sep ?? import_node_path.default.sep;
|
|
11843
|
+
const prefix = root === sep13 || root.endsWith(sep13) ? root : `${root}${sep13}`;
|
|
11844
|
+
const prefixes = sep13 === "\\" ? [prefix, `${prefix.slice(0, -1)}/`] : [prefix];
|
|
11845
|
+
const strip = (row) => {
|
|
11846
|
+
const found = prefixes.find((p) => row.startsWith(p));
|
|
11847
|
+
return found ? row.slice(found.length) : row;
|
|
11848
|
+
};
|
|
11849
|
+
const body = prefix === sep13 ? capped.rows.join("\n") : capped.rows.map(strip).join("\n");
|
|
11699
11850
|
if (!capped.truncated) return body;
|
|
11700
11851
|
const hint = opts.hint ? ` ${opts.hint}` : "";
|
|
11701
11852
|
return `${body}
|
|
@@ -11813,9 +11964,9 @@ function claudeManagedSettingsDir(platform = process.platform) {
|
|
|
11813
11964
|
}
|
|
11814
11965
|
function readClaudeSettingsModels(files, platform = process.platform) {
|
|
11815
11966
|
const managed = claudeManagedSettingsDir(platform);
|
|
11816
|
-
const
|
|
11817
|
-
const dropIns = files.list(
|
|
11818
|
-
const ranked = [...dropIns.reverse(),
|
|
11967
|
+
const join51 = platform === "win32" ? path13.win32.join : path13.posix.join;
|
|
11968
|
+
const dropIns = files.list(join51(managed, "managed-settings.d")).filter((name) => name.endsWith(".json") && !name.startsWith(".")).sort().map((name) => join51(managed, "managed-settings.d", name));
|
|
11969
|
+
const ranked = [...dropIns.reverse(), join51(managed, "managed-settings.json"), join51(claudeConfigDir(files.env), "settings.json")];
|
|
11819
11970
|
for (const file of ranked) {
|
|
11820
11971
|
const content = files.read(file);
|
|
11821
11972
|
const lineup = content === null ? null : parseClaudeSettingsModels(content);
|
|
@@ -13565,7 +13716,7 @@ var OrdewellMcpServer = class {
|
|
|
13565
13716
|
this.boundHost = void 0;
|
|
13566
13717
|
if (!http2) return;
|
|
13567
13718
|
http2.closeAllConnections();
|
|
13568
|
-
await new Promise((
|
|
13719
|
+
await new Promise((resolve18) => http2.close(() => resolve18()));
|
|
13569
13720
|
}
|
|
13570
13721
|
async issue(grant) {
|
|
13571
13722
|
const url = await this.start();
|
|
@@ -13574,7 +13725,7 @@ var OrdewellMcpServer = class {
|
|
|
13574
13725
|
return { url, token };
|
|
13575
13726
|
}
|
|
13576
13727
|
start() {
|
|
13577
|
-
this.listening ??= new Promise((
|
|
13728
|
+
this.listening ??= new Promise((resolve18, reject) => {
|
|
13578
13729
|
const http2 = (0, import_http.createServer)((req, res) => {
|
|
13579
13730
|
this.handle(req, res).catch(() => {
|
|
13580
13731
|
if (!res.headersSent) reply(res, 500, "Internal error");
|
|
@@ -13593,7 +13744,7 @@ var OrdewellMcpServer = class {
|
|
|
13593
13744
|
}
|
|
13594
13745
|
this.boundHost = `127.0.0.1:${address.port}`;
|
|
13595
13746
|
this.boundUrl = `http://${this.boundHost}${ORDEWELL_MCP_PATH}`;
|
|
13596
|
-
|
|
13747
|
+
resolve18(this.boundUrl);
|
|
13597
13748
|
});
|
|
13598
13749
|
http2.unref();
|
|
13599
13750
|
this.http = http2;
|
|
@@ -14390,11 +14541,11 @@ var import_net = require("net");
|
|
|
14390
14541
|
var import_string_decoder = require("string_decoder");
|
|
14391
14542
|
|
|
14392
14543
|
// src/utils/shellPath.ts
|
|
14393
|
-
var
|
|
14544
|
+
var import_child_process4 = require("child_process");
|
|
14394
14545
|
var import_util = require("util");
|
|
14395
14546
|
var os6 = __toESM(require("os"));
|
|
14396
14547
|
var path15 = __toESM(require("path"));
|
|
14397
|
-
var execAsync = (0, import_util.promisify)(
|
|
14548
|
+
var execAsync = (0, import_util.promisify)(import_child_process4.exec);
|
|
14398
14549
|
var LOGIN_SHELL_TIMEOUT_MS = 5e3;
|
|
14399
14550
|
var PATH_MARKER = "__ORDEWELL_PATH__";
|
|
14400
14551
|
var defaultExec = async (command, options) => {
|
|
@@ -14416,28 +14567,28 @@ function posixBinDirs() {
|
|
|
14416
14567
|
];
|
|
14417
14568
|
}
|
|
14418
14569
|
function windowsBinDirs(env, home) {
|
|
14419
|
-
const
|
|
14420
|
-
const under = (base, ...parts) => base ? [
|
|
14570
|
+
const join51 = (...parts) => path15.win32.join(...parts);
|
|
14571
|
+
const under = (base, ...parts) => base ? [join51(base, ...parts)] : [];
|
|
14421
14572
|
const appData = env.APPDATA;
|
|
14422
14573
|
const localAppData = env.LOCALAPPDATA;
|
|
14423
14574
|
const programData = env.ProgramData;
|
|
14424
14575
|
return [
|
|
14425
14576
|
// Native per-user installers, PowerShell-driven and otherwise.
|
|
14426
|
-
|
|
14427
|
-
|
|
14428
|
-
|
|
14429
|
-
|
|
14577
|
+
join51(home, ".local", "bin"),
|
|
14578
|
+
join51(home, ".opencode", "bin"),
|
|
14579
|
+
join51(home, ".claude", "bin"),
|
|
14580
|
+
join51(home, ".codex", "bin"),
|
|
14430
14581
|
...under(localAppData, "Programs", "claude"),
|
|
14431
14582
|
// Node package managers. npm's global prefix is `%APPDATA%\npm`; the
|
|
14432
14583
|
// literal spelling is kept as a fallback for a host that does not export
|
|
14433
14584
|
// APPDATA (a service account, a stripped CI container).
|
|
14434
14585
|
...under(appData, "npm"),
|
|
14435
|
-
|
|
14586
|
+
join51(home, "AppData", "Roaming", "npm"),
|
|
14436
14587
|
...under(localAppData, "pnpm"),
|
|
14437
14588
|
...under(localAppData, "Yarn", "bin"),
|
|
14438
|
-
|
|
14589
|
+
join51(home, ".bun", "bin"),
|
|
14439
14590
|
// Windows package managers.
|
|
14440
|
-
|
|
14591
|
+
join51(home, "scoop", "shims"),
|
|
14441
14592
|
...under(env.SCOOP, "shims"),
|
|
14442
14593
|
...under(env.SCOOP_GLOBAL ?? programData, "scoop", "shims"),
|
|
14443
14594
|
...under(programData, "chocolatey", "bin"),
|
|
@@ -14447,7 +14598,7 @@ function windowsBinDirs(env, home) {
|
|
|
14447
14598
|
...under(localAppData, "Microsoft", "WindowsApps"),
|
|
14448
14599
|
// Version managers. Volta's Windows home is not the POSIX `~/.volta`.
|
|
14449
14600
|
...under(localAppData, "Volta", "bin"),
|
|
14450
|
-
|
|
14601
|
+
join51(home, ".volta", "bin")
|
|
14451
14602
|
];
|
|
14452
14603
|
}
|
|
14453
14604
|
function wellKnownBinDirs(deps = {}) {
|
|
@@ -14558,7 +14709,7 @@ var BatchQuoteError = class extends Error {
|
|
|
14558
14709
|
|
|
14559
14710
|
cmd.exe has no way to carry a quote inside a quoted argument, so the text after it would run as commands of their own.
|
|
14560
14711
|
|
|
14561
|
-
Install the native executable from the coding agent's own Windows installer or release binary. Ordewell will launch it directly, with no interpreter in the way
|
|
14712
|
+
Install the native executable from the coding agent's own Windows installer or release binary. Ordewell will launch it directly, with no interpreter in the way.`
|
|
14562
14713
|
);
|
|
14563
14714
|
this.command = command;
|
|
14564
14715
|
this.name = "BatchQuoteError";
|
|
@@ -14579,12 +14730,17 @@ Searched: ${searchedPath || "(empty PATH)"}`);
|
|
|
14579
14730
|
};
|
|
14580
14731
|
function isResolvableOnPosixPath(command, PATH, exists) {
|
|
14581
14732
|
if (command.includes("/")) return exists(command);
|
|
14582
|
-
return PATH.split(path16.delimiter).map((d) => d.trim()).filter(Boolean).some((dir) => exists(path16.join(dir, command)));
|
|
14733
|
+
return PATH.split(path16.posix.delimiter).map((d) => d.trim()).filter(Boolean).some((dir) => exists(path16.posix.join(dir, command)));
|
|
14583
14734
|
}
|
|
14584
14735
|
function isExecutableResolved(command, plan, PATH, deps = {}) {
|
|
14585
|
-
if ((deps.platform ?? process.platform) === "win32") return plan.file !== command;
|
|
14736
|
+
if ((deps.platform ?? process.platform) === "win32") return plan.file !== command || namesDirectFile(command, deps);
|
|
14586
14737
|
return isResolvableOnPosixPath(command, PATH, deps.exists ?? defaultExists3);
|
|
14587
14738
|
}
|
|
14739
|
+
function namesDirectFile(command, deps) {
|
|
14740
|
+
if (path16.win32.basename(command) === command) return false;
|
|
14741
|
+
const pathExt = (deps.pathExt ?? (() => process.env.PATHEXT ?? ""))();
|
|
14742
|
+
return candidateExtensions(command, pathExt).direct.includes("") && (deps.exists ?? defaultExists3)(command);
|
|
14743
|
+
}
|
|
14588
14744
|
function defaultExists3(candidate) {
|
|
14589
14745
|
try {
|
|
14590
14746
|
return fsSync4.statSync(candidate).isFile();
|
|
@@ -14592,6 +14748,65 @@ function defaultExists3(candidate) {
|
|
|
14592
14748
|
return false;
|
|
14593
14749
|
}
|
|
14594
14750
|
}
|
|
14751
|
+
var MAX_SHIM_BYTES = 4096;
|
|
14752
|
+
function defaultReadShim(file) {
|
|
14753
|
+
try {
|
|
14754
|
+
return fsSync4.statSync(file).size > MAX_SHIM_BYTES ? void 0 : fsSync4.readFileSync(file, "utf8");
|
|
14755
|
+
} catch {
|
|
14756
|
+
return void 0;
|
|
14757
|
+
}
|
|
14758
|
+
}
|
|
14759
|
+
var NPM_SHIM_HEAD = "@ECHO off\nGOTO start\n:find_dp0\nSET dp0=%~dp0\nEXIT /b\n:start\nSETLOCAL\nCALL :find_dp0\n";
|
|
14760
|
+
var NPM_SHIMS = {
|
|
14761
|
+
node: `${NPM_SHIM_HEAD}
|
|
14762
|
+
IF EXIST "%dp0%\\node.exe" (
|
|
14763
|
+
SET "_prog=%dp0%\\node.exe"
|
|
14764
|
+
) ELSE (
|
|
14765
|
+
SET "_prog=node"
|
|
14766
|
+
SET PATHEXT=%PATHEXT:;.JS;=;%
|
|
14767
|
+
)
|
|
14768
|
+
|
|
14769
|
+
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\TARGET" %*
|
|
14770
|
+
`,
|
|
14771
|
+
program: `${NPM_SHIM_HEAD}"%dp0%\\TARGET" %*
|
|
14772
|
+
`
|
|
14773
|
+
};
|
|
14774
|
+
function shimPattern(template) {
|
|
14775
|
+
const [before, after] = template.split("TARGET").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
14776
|
+
return new RegExp(`^${before}([^"%\\n]+)${after}$`);
|
|
14777
|
+
}
|
|
14778
|
+
var NPM_SHIM_PATTERNS = { node: shimPattern(NPM_SHIMS.node), program: shimPattern(NPM_SHIMS.program) };
|
|
14779
|
+
function npmShimTarget(shim, pathDirs, deps) {
|
|
14780
|
+
const raw = (deps.readShim ?? defaultReadShim)(shim);
|
|
14781
|
+
if (raw === void 0) return void 0;
|
|
14782
|
+
const text6 = raw.replace(/\r\n/g, "\n").replace(/\n?$/, "\n");
|
|
14783
|
+
const exists = deps.exists ?? defaultExists3;
|
|
14784
|
+
const folder = path16.win32.dirname(shim);
|
|
14785
|
+
const program = NPM_SHIM_PATTERNS.program.exec(text6)?.[1];
|
|
14786
|
+
if (program !== void 0) {
|
|
14787
|
+
const file2 = path16.win32.join(folder, program);
|
|
14788
|
+
return DIRECT_EXTENSIONS.includes(path16.win32.extname(file2).toLowerCase()) && exists(file2) ? { file: file2, leading: [] } : void 0;
|
|
14789
|
+
}
|
|
14790
|
+
const script = NPM_SHIM_PATTERNS.node.exec(text6)?.[1];
|
|
14791
|
+
if (script === void 0) return void 0;
|
|
14792
|
+
const file = path16.win32.join(folder, script);
|
|
14793
|
+
if (!exists(file)) return void 0;
|
|
14794
|
+
const beside = path16.win32.join(folder, "node.exe");
|
|
14795
|
+
const node = exists(beside) ? beside : shimNode(pathDirs, deps);
|
|
14796
|
+
return node ? { file: node, leading: [file] } : void 0;
|
|
14797
|
+
}
|
|
14798
|
+
function shimNode(pathDirs, deps) {
|
|
14799
|
+
const exists = deps.exists ?? defaultExists3;
|
|
14800
|
+
const declared = (deps.pathExt ?? (() => process.env.PATHEXT ?? ""))().split(path16.win32.delimiter).map((e) => e.trim().toLowerCase()).filter(Boolean);
|
|
14801
|
+
const extensions = (declared.length > 0 ? declared : [".com", ".exe", ".bat", ".cmd"]).filter((e) => e !== ".js");
|
|
14802
|
+
for (const dir of pathDirs) {
|
|
14803
|
+
for (const ext of extensions) {
|
|
14804
|
+
const candidate = path16.win32.join(dir, `node${ext}`);
|
|
14805
|
+
if (exists(candidate)) return DIRECT_EXTENSIONS.includes(ext) ? candidate : void 0;
|
|
14806
|
+
}
|
|
14807
|
+
}
|
|
14808
|
+
return void 0;
|
|
14809
|
+
}
|
|
14595
14810
|
function quoteForCmd(arg) {
|
|
14596
14811
|
if (arg === "") return '""';
|
|
14597
14812
|
if (!/[\s"^&|<>()]/.test(arg)) return arg;
|
|
@@ -14642,7 +14857,8 @@ async function findWindowsExecutables(command, deps) {
|
|
|
14642
14857
|
const exists = deps.exists ?? defaultExists3;
|
|
14643
14858
|
const pathExt = (deps.pathExt ?? (() => process.env.PATHEXT ?? ""))();
|
|
14644
14859
|
const byRoute = candidateExtensions(command, pathExt);
|
|
14645
|
-
const
|
|
14860
|
+
const pathDirs = (await (deps.resolvePath ?? augmentedPath)() || "").split(path16.win32.delimiter).map((d) => d.trim().replace(/^"|"$/g, "")).filter(Boolean);
|
|
14861
|
+
const dirs = path16.win32.basename(command) !== command ? [path16.win32.dirname(path16.win32.resolve(command))] : pathDirs;
|
|
14646
14862
|
const base = path16.win32.basename(command);
|
|
14647
14863
|
const found = [];
|
|
14648
14864
|
for (const route of ROUTES) {
|
|
@@ -14650,7 +14866,8 @@ async function findWindowsExecutables(command, deps) {
|
|
|
14650
14866
|
for (const dir of dirs) {
|
|
14651
14867
|
const candidate = path16.win32.join(dir, `${base}${ext}`);
|
|
14652
14868
|
if (exists(candidate)) {
|
|
14653
|
-
|
|
14869
|
+
const target = route === "cmd" ? npmShimTarget(candidate, pathDirs, deps) : void 0;
|
|
14870
|
+
found.push(target ? { ...target, route: "direct" } : { file: candidate, route });
|
|
14654
14871
|
break outer;
|
|
14655
14872
|
}
|
|
14656
14873
|
}
|
|
@@ -14660,8 +14877,9 @@ async function findWindowsExecutables(command, deps) {
|
|
|
14660
14877
|
}
|
|
14661
14878
|
function planFor(found, args, deps) {
|
|
14662
14879
|
if (found.route === "direct") {
|
|
14663
|
-
const
|
|
14664
|
-
|
|
14880
|
+
const all = [...found.leading ?? [], ...args];
|
|
14881
|
+
const length2 = windowsCommandLine(found.file, all).length;
|
|
14882
|
+
return length2 > WINDOWS_MAX_COMMAND_LINE ? { tooLong: length2, limit: WINDOWS_MAX_COMMAND_LINE } : { file: found.file, args: all };
|
|
14665
14883
|
}
|
|
14666
14884
|
if (found.route === "cmd") {
|
|
14667
14885
|
if (hasLineBreak([found.file, ...args])) return { lineBreak: true };
|
|
@@ -14758,7 +14976,7 @@ function assertWorkspaceIsProject(workspace, deps = {}) {
|
|
|
14758
14976
|
}
|
|
14759
14977
|
|
|
14760
14978
|
// src/services/workspaceEnv.ts
|
|
14761
|
-
var
|
|
14979
|
+
var import_child_process5 = require("child_process");
|
|
14762
14980
|
var fs5 = __toESM(require("fs"));
|
|
14763
14981
|
var os7 = __toESM(require("os"));
|
|
14764
14982
|
var path19 = __toESM(require("path"));
|
|
@@ -15313,10 +15531,10 @@ var DIRENV_TIMEOUT_MS = 5e3;
|
|
|
15313
15531
|
var KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
15314
15532
|
function defaultDeps() {
|
|
15315
15533
|
return {
|
|
15316
|
-
run: (command, args, opts) => new Promise((
|
|
15317
|
-
(0,
|
|
15534
|
+
run: (command, args, opts) => new Promise((resolve18) => {
|
|
15535
|
+
(0, import_child_process5.execFile)(command, args, { ...opts, timeout: DIRENV_TIMEOUT_MS, encoding: "utf8" }, (err, stdout, stderr) => {
|
|
15318
15536
|
const code = err ? typeof err.code === "number" ? Number(err.code) : -1 : 0;
|
|
15319
|
-
|
|
15537
|
+
resolve18({ code, stdout: String(stdout ?? ""), stderr: String(stderr ?? "") });
|
|
15320
15538
|
});
|
|
15321
15539
|
}),
|
|
15322
15540
|
readFile: (file) => {
|
|
@@ -15405,10 +15623,10 @@ async function fromDirenv(cwd, deps) {
|
|
|
15405
15623
|
}
|
|
15406
15624
|
return { env, blocked: null };
|
|
15407
15625
|
}
|
|
15408
|
-
function findUp(start,
|
|
15626
|
+
function findUp(start, relative20, deps) {
|
|
15409
15627
|
let dir = path19.resolve(start);
|
|
15410
15628
|
for (; ; ) {
|
|
15411
|
-
const candidate = path19.join(dir,
|
|
15629
|
+
const candidate = path19.join(dir, relative20);
|
|
15412
15630
|
if (deps.readFile(candidate) !== null) return candidate;
|
|
15413
15631
|
const parent = path19.dirname(dir);
|
|
15414
15632
|
if (parent === dir) return null;
|
|
@@ -15453,14 +15671,14 @@ function parseEnvFile(content, context, home) {
|
|
|
15453
15671
|
|
|
15454
15672
|
// src/services/harness/settleWithin.ts
|
|
15455
15673
|
function settleWithin(promise, wait) {
|
|
15456
|
-
return new Promise((
|
|
15674
|
+
return new Promise((resolve18, reject) => {
|
|
15457
15675
|
let settled = false;
|
|
15458
15676
|
const settle = (outcome) => {
|
|
15459
15677
|
if (settled) return;
|
|
15460
15678
|
settled = true;
|
|
15461
15679
|
clearTimeout(timer);
|
|
15462
15680
|
try {
|
|
15463
|
-
|
|
15681
|
+
resolve18(outcome());
|
|
15464
15682
|
} catch (err) {
|
|
15465
15683
|
reject(err);
|
|
15466
15684
|
}
|
|
@@ -15523,14 +15741,14 @@ function unlessCancelled(work, signal) {
|
|
|
15523
15741
|
if (!signal) return work;
|
|
15524
15742
|
work.catch(() => {
|
|
15525
15743
|
});
|
|
15526
|
-
return new Promise((
|
|
15744
|
+
return new Promise((resolve18, reject) => {
|
|
15527
15745
|
if (signal.aborted) {
|
|
15528
|
-
|
|
15746
|
+
resolve18(CANCELLED2);
|
|
15529
15747
|
return;
|
|
15530
15748
|
}
|
|
15531
|
-
const onAbort = () =>
|
|
15749
|
+
const onAbort = () => resolve18(CANCELLED2);
|
|
15532
15750
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
15533
|
-
work.then(
|
|
15751
|
+
work.then(resolve18, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
15534
15752
|
});
|
|
15535
15753
|
}
|
|
15536
15754
|
async function spawnAttached(steps) {
|
|
@@ -15629,8 +15847,8 @@ async function awaitAttach(probe, timeoutMs, pollMs, ended2) {
|
|
|
15629
15847
|
const state = await settleWithin(probe(left), ended2 ? { timeoutMs: left, onTimeout, ended: ended2, onEnded: () => "failed" } : { timeoutMs: left, onTimeout });
|
|
15630
15848
|
if (state !== "pending") return state;
|
|
15631
15849
|
if (pollMs > 0) {
|
|
15632
|
-
await new Promise((
|
|
15633
|
-
const timer = setTimeout(
|
|
15850
|
+
await new Promise((resolve18) => {
|
|
15851
|
+
const timer = setTimeout(resolve18, pollMs);
|
|
15634
15852
|
timer.unref?.();
|
|
15635
15853
|
});
|
|
15636
15854
|
}
|
|
@@ -15847,8 +16065,8 @@ function releasePipes(child) {
|
|
|
15847
16065
|
var RunnerProcess = class {
|
|
15848
16066
|
constructor(deps) {
|
|
15849
16067
|
this.deps = deps;
|
|
15850
|
-
this.ended = new Promise((
|
|
15851
|
-
this.markEnded =
|
|
16068
|
+
this.ended = new Promise((resolve18) => {
|
|
16069
|
+
this.markEnded = resolve18;
|
|
15852
16070
|
});
|
|
15853
16071
|
}
|
|
15854
16072
|
deps;
|
|
@@ -15897,7 +16115,8 @@ var RunnerProcess = class {
|
|
|
15897
16115
|
const PATH = await resolvePath();
|
|
15898
16116
|
const launch = await planDirectLaunch(command.command, command.args, {
|
|
15899
16117
|
platform: this.deps.platform,
|
|
15900
|
-
resolvePath
|
|
16118
|
+
resolvePath,
|
|
16119
|
+
exists: this.deps.exists
|
|
15901
16120
|
});
|
|
15902
16121
|
if (!isExecutableResolved(command.command, launch, PATH, { platform: this.deps.platform, exists: this.deps.exists })) {
|
|
15903
16122
|
throw new ExecutableNotFoundError(command.command, PATH);
|
|
@@ -16000,8 +16219,8 @@ ${tail}` : ""}`;
|
|
|
16000
16219
|
}
|
|
16001
16220
|
/**
|
|
16002
16221
|
* Tree-wide, because the direct child may be a CLI whose shells, MCP servers
|
|
16003
|
-
* and test runs would outlive it — or, on Windows, the cmd.exe
|
|
16004
|
-
* than the runner. The forced follow-up is scheduled and unref'd, so a
|
|
16222
|
+
* and test runs would outlive it — or, on Windows, the cmd.exe or PowerShell
|
|
16223
|
+
* that runs a shim rather than the runner. The forced follow-up is scheduled and unref'd, so a
|
|
16005
16224
|
* disposed runner is never the reason the host refuses to exit.
|
|
16006
16225
|
*/
|
|
16007
16226
|
dispose() {
|
|
@@ -16314,7 +16533,7 @@ var StdioAgentAdapter = class extends ProcessLifecycle {
|
|
|
16314
16533
|
onEvent({ type: "error", message: this.exitMessage() });
|
|
16315
16534
|
return;
|
|
16316
16535
|
}
|
|
16317
|
-
await new Promise((
|
|
16536
|
+
await new Promise((resolve18, reject) => {
|
|
16318
16537
|
let settled = false;
|
|
16319
16538
|
const release2 = () => {
|
|
16320
16539
|
settled = true;
|
|
@@ -16326,7 +16545,7 @@ var StdioAgentAdapter = class extends ProcessLifecycle {
|
|
|
16326
16545
|
const finish2 = () => {
|
|
16327
16546
|
if (settled) return;
|
|
16328
16547
|
release2();
|
|
16329
|
-
|
|
16548
|
+
resolve18();
|
|
16330
16549
|
};
|
|
16331
16550
|
const fail = (err) => {
|
|
16332
16551
|
if (settled) return;
|
|
@@ -16540,7 +16759,7 @@ var PermissionLedger = class {
|
|
|
16540
16759
|
const open = this.open.get(id2);
|
|
16541
16760
|
if (!open || this.answering.has(id2)) return false;
|
|
16542
16761
|
this.answering.add(id2);
|
|
16543
|
-
const sent = new Promise((
|
|
16762
|
+
const sent = new Promise((resolve18) => resolve18(this.reply(open.handle, decision)));
|
|
16544
16763
|
return this.awaitReply(id2, open, sent);
|
|
16545
16764
|
}
|
|
16546
16765
|
async awaitReply(id2, open, sent) {
|
|
@@ -17394,8 +17613,8 @@ var ClaudeCodeAdapter = class extends StdioAgentAdapter {
|
|
|
17394
17613
|
if (!this.process) return Promise.resolve(null);
|
|
17395
17614
|
this.controlCount += 1;
|
|
17396
17615
|
const requestId = `ordewell-${request.subtype}-${this.controlCount}`;
|
|
17397
|
-
const answered3 = new Promise((
|
|
17398
|
-
this.pendingControl.set(requestId,
|
|
17616
|
+
const answered3 = new Promise((resolve18) => {
|
|
17617
|
+
this.pendingControl.set(requestId, resolve18);
|
|
17399
17618
|
});
|
|
17400
17619
|
this.writeLine({ type: "control_request", request_id: requestId, request });
|
|
17401
17620
|
return settleWithin(answered3, { timeoutMs, ended: this.processEnded, onTimeout: () => null, onEnded: () => null }).finally(() => {
|
|
@@ -17900,7 +18119,7 @@ var ClaudeCodeAdapter = class extends StdioAgentAdapter {
|
|
|
17900
18119
|
|
|
17901
18120
|
// src/services/harness/CodexAdapter.ts
|
|
17902
18121
|
var import_crypto7 = require("crypto");
|
|
17903
|
-
var
|
|
18122
|
+
var hostPath = __toESM(require("path"));
|
|
17904
18123
|
|
|
17905
18124
|
// src/services/harness/codexSandbox.ts
|
|
17906
18125
|
var CODEX_RUNNER = "codex";
|
|
@@ -17914,6 +18133,17 @@ async function probeCodexSandbox(deps, cwd, env) {
|
|
|
17914
18133
|
const landlock = await runProbe(deps, cwd, env, ["--enable", "use_legacy_landlock"]);
|
|
17915
18134
|
return landlock.code === 0 ? "legacy-landlock" : "unavailable";
|
|
17916
18135
|
}
|
|
18136
|
+
var CODEX_WINDOWS_DOCS = "https://developers.openai.com/codex/windows";
|
|
18137
|
+
function codexWindowsReadOnlyNote(readiness) {
|
|
18138
|
+
const state = readiness === "updateRequired" ? "needs its setup run again" : "is not set up";
|
|
18139
|
+
return [
|
|
18140
|
+
`Codex's Windows sandbox ${state} on this machine, so Codex runs this task read-only with no sandbox: each edit, and each command it does not judge safe, goes to Codex's reviewer, and what the reviewer approves runs unconfined.`,
|
|
18141
|
+
"",
|
|
18142
|
+
`To give Codex its sandbox, run \`codex\` in a terminal and choose "Set up default sandbox" (it asks for Administrator once), or run /setup-default-sandbox there. Not the non-admin sandbox: under it Codex refuses every command of a task like this one. ${CODEX_WINDOWS_DOCS}`
|
|
18143
|
+
].join("\n");
|
|
18144
|
+
}
|
|
18145
|
+
var CODEX_WINDOWS_READ_ONLY_ADVICE = "Codex's Windows sandbox is not ready on this machine, so your sandbox may be read-only. That does not stop this task: make edits with apply_patch, and run a command that must write (a build, an install, tests that write files) with escalated permissions. A reviewer decides each such request. Do not end the task because the sandbox is read-only.";
|
|
18146
|
+
var CODEX_WINDOWS_SHELL_ADVICE = "Your shell on this Windows machine is PowerShell. Where its execution policy refuses an npm-installed tool's .ps1 script (npm, npx, pnpm), call the .cmd beside it instead, as in npm.cmd test. Report a test run as passed only when you saw it pass.";
|
|
17917
18147
|
var NAMESPACE_CAUSE = "Its Linux sandbox needs unprivileged user namespaces, which this kernel restricts (Ubuntu 24.04's AppArmor default), and the legacy Landlock backend did not work either.";
|
|
17918
18148
|
var SYSCTL_FIX = " sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0";
|
|
17919
18149
|
function codexSandboxUnavailableMessage(role = "planner") {
|
|
@@ -18010,7 +18240,7 @@ var CodexSandboxAvailability = class {
|
|
|
18010
18240
|
async function runProbe(deps, cwd, env, flags) {
|
|
18011
18241
|
const args = ["sandbox", ...flags, "--", "/bin/true"];
|
|
18012
18242
|
const placed = await deps.placement?.place({ command: "codex", args, env: {}, files: [] });
|
|
18013
|
-
return new Promise((
|
|
18243
|
+
return new Promise((resolve18) => {
|
|
18014
18244
|
let output = "";
|
|
18015
18245
|
let settled = false;
|
|
18016
18246
|
let proc = null;
|
|
@@ -18019,7 +18249,7 @@ async function runProbe(deps, cwd, env, flags) {
|
|
|
18019
18249
|
settled = true;
|
|
18020
18250
|
clearTimeout(timer);
|
|
18021
18251
|
placed?.ended();
|
|
18022
|
-
|
|
18252
|
+
resolve18({ code, output });
|
|
18023
18253
|
};
|
|
18024
18254
|
const timer = setTimeout(() => {
|
|
18025
18255
|
placed?.stop();
|
|
@@ -18177,13 +18407,14 @@ ${taskCompletionContract(commits ? { commits } : {})}`;
|
|
|
18177
18407
|
*/
|
|
18178
18408
|
plannerInstructions(nativeSearch, hidden, ownShell = true, extra) {
|
|
18179
18409
|
const tools = ordewellToolNames("planner", hidden, extra);
|
|
18410
|
+
const runCommand = !hidden?.includes("run_command");
|
|
18180
18411
|
return [
|
|
18181
18412
|
`You have ${countOf(tools)} tools from the \`${ORDEWELL_MCP_SERVER_NAME}\` MCP server: ${quoted3(tools)}.`,
|
|
18182
18413
|
`They are not in your tool list up front. Find them with the tool discovery you have (the \`exec\` tool's \`ALL_TOOLS\` list) and call them by their full names, ${quoted3(this.toolNames("planner", hidden, extra))}.`,
|
|
18183
|
-
ownShell ? `Run shell commands with \`${this.toolName("run_command")}\`, not your own shell: yours is sandboxed without network, so git remotes, gh and cloud CLIs fail there.` : `You have no shell of your own on this machine: run every command, reads included, with \`${this.toolName("run_command")}\`.`,
|
|
18414
|
+
!runCommand ? "" : ownShell ? `Run shell commands with \`${this.toolName("run_command")}\`, not your own shell: yours is sandboxed without network, so git remotes, gh and cloud CLIs fail there.` : `You have no shell of your own on this machine: run every command, reads included, with \`${this.toolName("run_command")}\`.`,
|
|
18184
18415
|
`Fetch web pages with \`${this.toolName("fetch")}\`, not curl or your shell.`,
|
|
18185
18416
|
nativeSearch ? "Search the web with your built-in web search." : `Your built-in web search is off for this session; search with \`${this.toolName("web_search")}\`.`
|
|
18186
|
-
].join(" ");
|
|
18417
|
+
].filter(Boolean).join(" ");
|
|
18187
18418
|
},
|
|
18188
18419
|
plannerWebSearch: (nativeSearch) => nativeSearch ? "cached" : "disabled"
|
|
18189
18420
|
};
|
|
@@ -18205,7 +18436,7 @@ var CodexRpc = class {
|
|
|
18205
18436
|
}
|
|
18206
18437
|
/** The request as the awaited form of {@link send}, for steps that wait on one answer and nothing else. */
|
|
18207
18438
|
call(method, params) {
|
|
18208
|
-
return new Promise((
|
|
18439
|
+
return new Promise((resolve18) => this.send(method, params, (response) => resolve18(response)));
|
|
18209
18440
|
}
|
|
18210
18441
|
/**
|
|
18211
18442
|
* A request framed as the line to write, left to the caller to write — for
|
|
@@ -18527,7 +18758,9 @@ var CodexAdapter = class extends StdioAgentAdapter {
|
|
|
18527
18758
|
/** The row each announced file of an in-flight `fileChange` item is shown under, by the file's shown path. */
|
|
18528
18759
|
fileChangeRows = /* @__PURE__ */ new Map();
|
|
18529
18760
|
sandbox = "default";
|
|
18530
|
-
/**
|
|
18761
|
+
/** Whether the user set up Codex's Windows sandbox, asked for a change task on a Windows host; null where nothing asked or Codex did not say. */
|
|
18762
|
+
windowsSandbox = null;
|
|
18763
|
+
/** Codex's own shell is off, and `run_command` is the only one: a read-only task's, and a planner's on a host where no sandbox starts (ADR-0033) or on Windows (ADR-0010). */
|
|
18531
18764
|
ownShellOff = false;
|
|
18532
18765
|
/** A read-only task's: every MCP server Codex would start beside Ordewell's, each switched off for its thread (ADR-0046). */
|
|
18533
18766
|
withheldServers = [];
|
|
@@ -18563,9 +18796,11 @@ var CodexAdapter = class extends StdioAgentAdapter {
|
|
|
18563
18796
|
const needsSandbox = opts.kind === "planner" || opts.flags.permissionMode !== "danger-full-access";
|
|
18564
18797
|
const nothingToAsk = readOnly || this.deps.placement !== void 0 && !needsSandbox;
|
|
18565
18798
|
this.sandbox = nothingToAsk ? "default" : await probeCodexSandbox(this.deps, opts.cwd, this.spawnEnv);
|
|
18566
|
-
|
|
18799
|
+
const unsandboxedPlanner = this.sandbox === "unavailable" && opts.kind === "planner" && !!opts.mcp;
|
|
18800
|
+
const readsThroughOrdewell = !!opts.mcp && !opts.mcp.hidden?.includes("run_command");
|
|
18801
|
+
this.ownShellOff = readOnly || unsandboxedPlanner || opts.kind === "planner" && readsThroughOrdewell && this.onWindowsHost();
|
|
18567
18802
|
if (this.sandbox === "unavailable" && needsSandbox && !this.ownShellOff) throw new Error(codexSandboxUnavailableMessage(this.deps.placement ? "container" : opts.kind));
|
|
18568
|
-
if (
|
|
18803
|
+
if (unsandboxedPlanner) this.announce({ type: "thinking", text: codexShellOffNote() });
|
|
18569
18804
|
const incomplete = () => {
|
|
18570
18805
|
throw this.handshakeIncomplete();
|
|
18571
18806
|
};
|
|
@@ -18591,6 +18826,7 @@ ${this.exitMessage()}`);
|
|
|
18591
18826
|
throw initialized.closed ? this.handshakeIncomplete() : new Error(`The Codex app-server rejected initialize: ${initialized.message ?? "unknown error"}`);
|
|
18592
18827
|
}
|
|
18593
18828
|
if (readOnlyTask(opts)) this.withheldServers = await this.configuredServers(opts.cwd);
|
|
18829
|
+
if (this.runsWindowsSandbox(opts)) this.windowsSandbox = await this.windowsSandboxReadiness();
|
|
18594
18830
|
const resumeId = opts.resumeSessionId;
|
|
18595
18831
|
let opened2 = await this.requestThread(resumeId);
|
|
18596
18832
|
if ("reason" in opened2 && resumeId) {
|
|
@@ -18601,8 +18837,34 @@ ${this.exitMessage()}`);
|
|
|
18601
18837
|
this.threadId = opened2.id;
|
|
18602
18838
|
this.sessionId = opened2.id;
|
|
18603
18839
|
this.threadModel = opened2.model;
|
|
18840
|
+
if (opts.kind === "task" && this.windowsSandbox !== null && this.windowsSandbox !== "ready" && opened2.sandbox === "readOnly") {
|
|
18841
|
+
this.announce({ type: "thinking", text: codexWindowsReadOnlyNote(this.windowsSandbox) });
|
|
18842
|
+
}
|
|
18604
18843
|
if (opts.kind === "task") await this.loadCommands(this.runnerCwd(opts));
|
|
18605
18844
|
}
|
|
18845
|
+
/**
|
|
18846
|
+
* Codex runs on this Windows host, not placed on another machine. Its
|
|
18847
|
+
* sandboxes here cannot keep a planner's command off the network: with none
|
|
18848
|
+
* set up there is none, and under the non-admin one Node reaches the network
|
|
18849
|
+
* (measured, ADR-0010). So a planner's own shell is off here, and every
|
|
18850
|
+
* command goes through Ordewell's `run_command`, as every other planner's
|
|
18851
|
+
* does on Windows (ADR-0026). A one-shot plan, which runs no command, keeps
|
|
18852
|
+
* Codex's shell with its approvals declined: it has no other way to read.
|
|
18853
|
+
*/
|
|
18854
|
+
onWindowsHost() {
|
|
18855
|
+
return !this.deps.placement && (this.deps.platform ?? process.platform) === "win32";
|
|
18856
|
+
}
|
|
18857
|
+
/** A change task whose commands Codex runs in its own Windows sandbox, which the user may not have set up. */
|
|
18858
|
+
runsWindowsSandbox(opts) {
|
|
18859
|
+
return opts.kind === "task" && this.onWindowsHost() && !this.ownShellOff && opts.flags.permissionMode === "workspace-write";
|
|
18860
|
+
}
|
|
18861
|
+
/** Codex's answer, or null from a Codex that has no such question: that one is left as it configures itself. */
|
|
18862
|
+
async windowsSandboxReadiness() {
|
|
18863
|
+
const response = await this.rpc.call("windowsSandbox/readiness", {});
|
|
18864
|
+
if (!response.ok && response.closed) throw this.handshakeIncomplete();
|
|
18865
|
+
const status = response.ok ? response.result.status : void 0;
|
|
18866
|
+
return status === "ready" || status === "notConfigured" || status === "updateRequired" ? status : null;
|
|
18867
|
+
}
|
|
18606
18868
|
commands() {
|
|
18607
18869
|
return this.nativeCommands.map((command) => ({ ...command }));
|
|
18608
18870
|
}
|
|
@@ -18670,6 +18932,7 @@ ${this.exitMessage()}`);
|
|
|
18670
18932
|
}
|
|
18671
18933
|
return Object.keys(servers).filter((name) => name !== ORDEWELL_MCP_SERVER_NAME);
|
|
18672
18934
|
}
|
|
18935
|
+
/** The thread, the model it runs, and the sandbox Codex granted it, which need not be the one asked for. */
|
|
18673
18936
|
async requestThread(resumeSessionId) {
|
|
18674
18937
|
const response = await this.rpc.call(resumeSessionId ? "thread/resume" : "thread/start", {
|
|
18675
18938
|
...resumeSessionId ? { threadId: resumeSessionId } : {},
|
|
@@ -18679,7 +18942,8 @@ ${this.exitMessage()}`);
|
|
|
18679
18942
|
const thread = response.ok ? response.result.thread : void 0;
|
|
18680
18943
|
if (!thread?.id) return { reason: !response.ok && response.message || "no thread id returned" };
|
|
18681
18944
|
const model = response.ok ? response.result.model : void 0;
|
|
18682
|
-
|
|
18945
|
+
const sandbox = response.ok ? response.result.sandbox?.type : void 0;
|
|
18946
|
+
return { id: thread.id, model: typeof model === "string" ? model : null, sandbox: typeof sandbox === "string" ? sandbox : null };
|
|
18683
18947
|
}
|
|
18684
18948
|
threadParams() {
|
|
18685
18949
|
const opts = this.startOpts;
|
|
@@ -18697,14 +18961,20 @@ ${this.exitMessage()}`);
|
|
|
18697
18961
|
...opts?.mcp ? { mcp_servers: CODEX_ORDEWELL.threadServers(opts.mcp) } : {}
|
|
18698
18962
|
};
|
|
18699
18963
|
const threadConfig = Object.keys(config).length ? { config } : {};
|
|
18964
|
+
const noWindowsSandbox = this.windowsSandbox !== null && this.windowsSandbox !== "ready";
|
|
18700
18965
|
if (opts?.kind === "task") {
|
|
18701
18966
|
const { approvalPolicy, approvalsReviewer } = opts.flags.modeSettings;
|
|
18967
|
+
const developerInstructions = [
|
|
18968
|
+
opts.mcp ? CODEX_ORDEWELL.taskInstructions({ readOnly: readOnlyTask(opts), ...opts.commits ? { commits: true } : {}, ...opts.mcp.extraTools ? { extra: opts.mcp.extraTools } : {} }) : "",
|
|
18969
|
+
this.onWindowsHost() && !this.ownShellOff ? CODEX_WINDOWS_SHELL_ADVICE : "",
|
|
18970
|
+
noWindowsSandbox ? CODEX_WINDOWS_READ_ONLY_ADVICE : ""
|
|
18971
|
+
].filter(Boolean).join("\n\n");
|
|
18702
18972
|
return {
|
|
18703
18973
|
...common,
|
|
18704
18974
|
sandbox: opts.flags.permissionMode,
|
|
18705
18975
|
...approvalPolicy ? { approvalPolicy } : {},
|
|
18706
18976
|
...approvalsReviewer ? { approvalsReviewer } : {},
|
|
18707
|
-
...
|
|
18977
|
+
...developerInstructions ? { developerInstructions } : {},
|
|
18708
18978
|
...threadConfig,
|
|
18709
18979
|
...readOnlyTask(opts) ? { config: { ...config, mcp_servers: { ...withheld(this.withheldServers), ...config.mcp_servers }, projects: untrustedProjects(opts.cwd), web_search: "disabled" } } : {}
|
|
18710
18980
|
};
|
|
@@ -18747,8 +19017,8 @@ ${this.exitMessage()}`);
|
|
|
18747
19017
|
return awaitAttach(async (left) => {
|
|
18748
19018
|
const known = CODEX_ORDEWELL.attachState(this.mcpStartup);
|
|
18749
19019
|
if (known !== "pending") return known;
|
|
18750
|
-
const reported2 = new Promise((
|
|
18751
|
-
this.mcpStartupSettled = () =>
|
|
19020
|
+
const reported2 = new Promise((resolve18) => {
|
|
19021
|
+
this.mcpStartupSettled = () => resolve18(CODEX_ORDEWELL.attachState(this.mcpStartup));
|
|
18752
19022
|
});
|
|
18753
19023
|
const state = await settleWithin(reported2, {
|
|
18754
19024
|
timeoutMs: left,
|
|
@@ -18773,10 +19043,10 @@ ${this.exitMessage()}`);
|
|
|
18773
19043
|
const turn = this.turn;
|
|
18774
19044
|
if (!this.process || !turn) return Promise.resolve(false);
|
|
18775
19045
|
this.interruptRequested = true;
|
|
18776
|
-
const acknowledged = new Promise((
|
|
19046
|
+
const acknowledged = new Promise((resolve18) => {
|
|
18777
19047
|
this.whenNamed(turn, () => this.rpc.send("turn/interrupt", { threadId: this.threadId, turnId: turn.id }, (response) => {
|
|
18778
19048
|
if (!response.ok) this.interruptRequested = false;
|
|
18779
|
-
|
|
19049
|
+
resolve18(response.ok);
|
|
18780
19050
|
}));
|
|
18781
19051
|
});
|
|
18782
19052
|
return settleWithin(acknowledged, { timeoutMs, ended: this.processEnded, onTimeout: () => false, onEnded: () => false });
|
|
@@ -18798,7 +19068,7 @@ ${this.exitMessage()}`);
|
|
|
18798
19068
|
const turn = this.turn;
|
|
18799
19069
|
if (!this.process || !turn) return Promise.resolve(false);
|
|
18800
19070
|
const clientId = (0, import_crypto7.randomUUID)();
|
|
18801
|
-
return new Promise((
|
|
19071
|
+
return new Promise((resolve18) => {
|
|
18802
19072
|
let settled = false;
|
|
18803
19073
|
const steer = {
|
|
18804
19074
|
id: id2,
|
|
@@ -18807,7 +19077,7 @@ ${this.exitMessage()}`);
|
|
|
18807
19077
|
if (settled) return;
|
|
18808
19078
|
settled = true;
|
|
18809
19079
|
if (!accepted) turn.steers.delete(clientId);
|
|
18810
|
-
|
|
19080
|
+
resolve18(accepted);
|
|
18811
19081
|
}
|
|
18812
19082
|
};
|
|
18813
19083
|
turn.steers.set(clientId, steer);
|
|
@@ -19356,10 +19626,11 @@ ${this.exitMessage()}`);
|
|
|
19356
19626
|
}
|
|
19357
19627
|
/** Relative to the task's worktree, where every path but a stray one lies; a move names both ends. */
|
|
19358
19628
|
shownChangePath(change) {
|
|
19629
|
+
const { isAbsolute: isAbsolute13, relative: relative20, sep: sep13 } = this.deps.placement ? hostPath.posix : hostPath;
|
|
19359
19630
|
const shown = (path53) => {
|
|
19360
19631
|
const cwd = this.startOpts && this.runnerCwd(this.startOpts);
|
|
19361
|
-
const rel = cwd ? (
|
|
19362
|
-
return rel && rel !== ".." && !rel.startsWith(`..${
|
|
19632
|
+
const rel = cwd ? relative20(cwd, path53) : path53;
|
|
19633
|
+
return rel && rel !== ".." && !rel.startsWith(`..${sep13}`) && !isAbsolute13(rel) ? rel : path53;
|
|
19363
19634
|
};
|
|
19364
19635
|
const from = shown(change.path ?? "");
|
|
19365
19636
|
return change.kind?.move_path ? `${from} \u2192 ${shown(change.kind.move_path)}` : from;
|
|
@@ -19566,14 +19837,14 @@ function splitModelId(id2) {
|
|
|
19566
19837
|
return { providerID: id2.slice(0, slash), modelID: id2.slice(slash + 1) };
|
|
19567
19838
|
}
|
|
19568
19839
|
function delay(ms, signal) {
|
|
19569
|
-
return new Promise((
|
|
19840
|
+
return new Promise((resolve18) => {
|
|
19570
19841
|
const onAbort = () => {
|
|
19571
19842
|
clearTimeout(timer);
|
|
19572
|
-
|
|
19843
|
+
resolve18();
|
|
19573
19844
|
};
|
|
19574
19845
|
const timer = setTimeout(() => {
|
|
19575
19846
|
signal?.removeEventListener("abort", onAbort);
|
|
19576
|
-
|
|
19847
|
+
resolve18();
|
|
19577
19848
|
}, ms);
|
|
19578
19849
|
timer.unref?.();
|
|
19579
19850
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -19695,8 +19966,8 @@ function streamTurn() {
|
|
|
19695
19966
|
}
|
|
19696
19967
|
function turnLatch() {
|
|
19697
19968
|
let markDone;
|
|
19698
|
-
const ended2 = new Promise((
|
|
19699
|
-
markDone =
|
|
19969
|
+
const ended2 = new Promise((resolve18) => {
|
|
19970
|
+
markDone = resolve18;
|
|
19700
19971
|
});
|
|
19701
19972
|
const turn = { live: false, done: false, ended: ended2, finish: () => {
|
|
19702
19973
|
turn.done = true;
|
|
@@ -19708,9 +19979,9 @@ async function settleTurn(turn, how, onEvent) {
|
|
|
19708
19979
|
const { signal } = how;
|
|
19709
19980
|
let onAbort = () => {
|
|
19710
19981
|
};
|
|
19711
|
-
const aborted = new Promise((
|
|
19712
|
-
onAbort =
|
|
19713
|
-
if (signal?.aborted)
|
|
19982
|
+
const aborted = new Promise((resolve18) => {
|
|
19983
|
+
onAbort = resolve18;
|
|
19984
|
+
if (signal?.aborted) resolve18();
|
|
19714
19985
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
19715
19986
|
});
|
|
19716
19987
|
try {
|
|
@@ -19737,8 +20008,8 @@ async function interruptAcknowledged(turn, processEnded, timeoutMs) {
|
|
|
19737
20008
|
async function openEventStream(connect2, onFrame, onActivity) {
|
|
19738
20009
|
const streamAbort = new AbortController();
|
|
19739
20010
|
let connected;
|
|
19740
|
-
const ready = new Promise((
|
|
19741
|
-
connected =
|
|
20011
|
+
const ready = new Promise((resolve18) => {
|
|
20012
|
+
connected = resolve18;
|
|
19742
20013
|
});
|
|
19743
20014
|
let fail;
|
|
19744
20015
|
const failed2 = new Promise((_resolve, reject) => {
|
|
@@ -19752,7 +20023,7 @@ async function openEventStream(connect2, onFrame, onActivity) {
|
|
|
19752
20023
|
const attemptAbort = new AbortController();
|
|
19753
20024
|
const abortAttempt = () => attemptAbort.abort();
|
|
19754
20025
|
streamAbort.signal.addEventListener("abort", abortAttempt, { once: true });
|
|
19755
|
-
const stopped2 = new Promise((
|
|
20026
|
+
const stopped2 = new Promise((resolve18) => attemptAbort.signal.addEventListener("abort", () => resolve18(), { once: true }));
|
|
19756
20027
|
try {
|
|
19757
20028
|
await streamEvents((signal) => settleWithin(connect2(signal), {
|
|
19758
20029
|
timeoutMs: STREAM_CONNECT_TIMEOUT_MS,
|
|
@@ -20553,7 +20824,7 @@ var OpenCodeAdapter = class extends ProcessLifecycle {
|
|
|
20553
20824
|
* only until the address is known.
|
|
20554
20825
|
*/
|
|
20555
20826
|
serverAddress() {
|
|
20556
|
-
return new Promise((
|
|
20827
|
+
return new Promise((resolve18) => {
|
|
20557
20828
|
let partial = "";
|
|
20558
20829
|
const stopReading = this.runner.readStdout((text6) => {
|
|
20559
20830
|
const lines2 = (partial + text6).split("\n");
|
|
@@ -20568,7 +20839,7 @@ var OpenCodeAdapter = class extends ProcessLifecycle {
|
|
|
20568
20839
|
const settle = (url) => {
|
|
20569
20840
|
stopReading();
|
|
20570
20841
|
clearTimeout(timer);
|
|
20571
|
-
|
|
20842
|
+
resolve18(url);
|
|
20572
20843
|
};
|
|
20573
20844
|
void this.processEnded.then(() => settle(null));
|
|
20574
20845
|
});
|
|
@@ -21268,7 +21539,7 @@ var OpenCodeAdapter = class extends ProcessLifecycle {
|
|
|
21268
21539
|
if (servers) this.mcpServers = Object.keys(servers).filter((name) => name !== ordewell.name);
|
|
21269
21540
|
return OPENCODE_ORDEWELL.attachState(servers?.[ordewell.name]?.status);
|
|
21270
21541
|
}, MCP_ATTACH_TIMEOUT_MS, MCP_STATUS_POLL_MS2, this.processEnded);
|
|
21271
|
-
if (state === "connected" && this.v2) await new Promise((
|
|
21542
|
+
if (state === "connected" && this.v2) await new Promise((resolve18) => setTimeout(resolve18, V2_TOOLS_OFFERED_MS));
|
|
21272
21543
|
return state;
|
|
21273
21544
|
}
|
|
21274
21545
|
/** 2.x lists its servers as `{ name, status: { status } }`, and only once it has started connecting them. */
|
|
@@ -21606,12 +21877,12 @@ var ModelCatalog = class {
|
|
|
21606
21877
|
|
|
21607
21878
|
// src/services/ModelDiscovery.ts
|
|
21608
21879
|
var path28 = __toESM(require("path"));
|
|
21609
|
-
var
|
|
21880
|
+
var import_child_process7 = require("child_process");
|
|
21610
21881
|
var import_util2 = require("util");
|
|
21611
21882
|
var fsSync5 = __toESM(require("fs"));
|
|
21612
21883
|
|
|
21613
21884
|
// src/services/harness/appServerModels.ts
|
|
21614
|
-
var
|
|
21885
|
+
var import_child_process6 = require("child_process");
|
|
21615
21886
|
var DEFAULT_TIMEOUT_MS3 = 2e4;
|
|
21616
21887
|
function definedOnly(env) {
|
|
21617
21888
|
return Object.fromEntries(Object.entries(env).filter((entry) => entry[1] !== void 0));
|
|
@@ -21626,7 +21897,7 @@ function parseRpcLine(line) {
|
|
|
21626
21897
|
}
|
|
21627
21898
|
async function openAppServer(command, args, launch) {
|
|
21628
21899
|
const runner = new RunnerProcess({
|
|
21629
|
-
spawn:
|
|
21900
|
+
spawn: import_child_process6.spawn,
|
|
21630
21901
|
fetch: globalThis.fetch,
|
|
21631
21902
|
// The cwd is no workspace, so it pays no direnv round trip before a spawn
|
|
21632
21903
|
// with a deadline. Discovery and the account monitor pass the workspace's
|
|
@@ -21650,8 +21921,8 @@ async function openAppServer(command, args, launch) {
|
|
|
21650
21921
|
})) launch.onMessage?.(message);
|
|
21651
21922
|
};
|
|
21652
21923
|
let inputBroken;
|
|
21653
|
-
const broken = new Promise((
|
|
21654
|
-
inputBroken =
|
|
21924
|
+
const broken = new Promise((resolve18) => {
|
|
21925
|
+
inputBroken = resolve18;
|
|
21655
21926
|
});
|
|
21656
21927
|
try {
|
|
21657
21928
|
await runner.start(launch.cwd, () => ({ command, args }), (started) => {
|
|
@@ -21711,7 +21982,7 @@ async function discoverAppServerModels(command, args, options = {}) {
|
|
|
21711
21982
|
}
|
|
21712
21983
|
|
|
21713
21984
|
// src/services/ModelDiscovery.ts
|
|
21714
|
-
var execAsync2 = (0, import_util2.promisify)(
|
|
21985
|
+
var execAsync2 = (0, import_util2.promisify)(import_child_process7.exec);
|
|
21715
21986
|
var defaultExec2 = async (command, options) => {
|
|
21716
21987
|
const PATH = await augmentedPath();
|
|
21717
21988
|
const { stdout } = await execAsync2(command, { timeout: options?.timeout, maxBuffer: 32 * 1024 * 1024, env: withPath(options?.env ?? process.env, PATH) });
|
|
@@ -24869,15 +25140,15 @@ var fs10 = __toESM(require("fs"));
|
|
|
24869
25140
|
var path32 = __toESM(require("path"));
|
|
24870
25141
|
|
|
24871
25142
|
// src/services/worktreeBootstrap.ts
|
|
24872
|
-
var
|
|
25143
|
+
var import_child_process9 = require("child_process");
|
|
24873
25144
|
var import_util4 = require("util");
|
|
24874
25145
|
var fs9 = __toESM(require("fs"));
|
|
24875
25146
|
var path31 = __toESM(require("path"));
|
|
24876
25147
|
|
|
24877
25148
|
// src/services/gitExec.ts
|
|
24878
|
-
var
|
|
25149
|
+
var import_child_process8 = require("child_process");
|
|
24879
25150
|
var import_util3 = require("util");
|
|
24880
|
-
var execFileAsync = (0, import_util3.promisify)(
|
|
25151
|
+
var execFileAsync = (0, import_util3.promisify)(import_child_process8.execFile);
|
|
24881
25152
|
var MAX_BUFFER = 64 * 1024 * 1024;
|
|
24882
25153
|
var GIT_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
24883
25154
|
function execFileWithTimeout(timeoutMs) {
|
|
@@ -25038,7 +25309,7 @@ function rebased(pointee, opts) {
|
|
|
25038
25309
|
}
|
|
25039
25310
|
|
|
25040
25311
|
// src/services/worktreeBootstrap.ts
|
|
25041
|
-
var execAsync3 = (0, import_util4.promisify)(
|
|
25312
|
+
var execAsync3 = (0, import_util4.promisify)(import_child_process9.exec);
|
|
25042
25313
|
var SETUP_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
25043
25314
|
var LINKED_ARTIFACTS = /* @__PURE__ */ new Set(["node_modules", "vendor", ".venv", ".claude", ".opencode", ".codegraph", ".envrc"]);
|
|
25044
25315
|
var isEnvFile = (name) => name.startsWith(".env");
|
|
@@ -25564,11 +25835,11 @@ async function committedInHead(files) {
|
|
|
25564
25835
|
}
|
|
25565
25836
|
const result = /* @__PURE__ */ new Map();
|
|
25566
25837
|
await Promise.all([...byDir].map(async ([dir, inDir]) => {
|
|
25567
|
-
const
|
|
25838
|
+
const relative20 = (file) => path34.relative(dir, file).split(path34.sep).join("/");
|
|
25568
25839
|
try {
|
|
25569
|
-
const { stdout } = await runGit("git", ["ls-tree", "--name-only", "HEAD", "--", ...inDir.map(
|
|
25840
|
+
const { stdout } = await runGit("git", ["ls-tree", "--name-only", "HEAD", "--", ...inDir.map(relative20)], { cwd: dir, env: cleanEnv() });
|
|
25570
25841
|
const listed5 = new Set(stdout.split("\n").map((line) => line.trim()).filter(Boolean));
|
|
25571
|
-
for (const file of inDir) result.set(file, listed5.has(
|
|
25842
|
+
for (const file of inDir) result.set(file, listed5.has(relative20(file)));
|
|
25572
25843
|
} catch {
|
|
25573
25844
|
}
|
|
25574
25845
|
}));
|
|
@@ -26300,7 +26571,7 @@ function researchTasksGuide(tools) {
|
|
|
26300
26571
|
function sealedGuide(tool2) {
|
|
26301
26572
|
return `${tool2} with "sealed": true runs a command without asking anyone, for local computation over the workspace: a loop over files, a script, a pipe into an interpreter. A sealed run has no network, the workspace read-only, and no home directory or credentials; $TMPDIR is a scratch directory kept for the session's sealed runs, so read what one left there with another sealed run. A command that would be refused for being a loop, a here-document or a pipe into an interpreter runs sealed on its own where this machine has a sandbox, and you can ask for it yourself when you know a command is local computation. Never seal a command that needs the network or the user's accounts: it fails there. An allowlist exclusion and a command the user denied are refused either way, and without a sandbox a command that would run sealed is refused.`;
|
|
26302
26573
|
}
|
|
26303
|
-
function researchPhaseBlock(harnessMode, agents) {
|
|
26574
|
+
function researchPhaseBlock(harnessMode, agents, researchShell) {
|
|
26304
26575
|
const shared2 = [
|
|
26305
26576
|
"RESEARCH PHASE:",
|
|
26306
26577
|
"- Start by reading README.md and any agent config files (AGENTS.md, CLAUDE.md)"
|
|
@@ -26309,6 +26580,7 @@ function researchPhaseBlock(harnessMode, agents) {
|
|
|
26309
26580
|
"- Explore the repository with your own tools until you understand its architecture",
|
|
26310
26581
|
"- You are planning, not implementing: do NOT edit, create, or delete any file, and do not run commands that change the workspace",
|
|
26311
26582
|
"- Run commands \u2014 git, gh, cloud CLIs, the project's own tooling \u2014 with the run_command tool, not a shell of your own. MCP tools the user configured (issue trackers, todo lists) are yours to read from too. Reads run at once; anything else is approved or refused by the user's settings. When something the plan needs to change is refused, add it to the plan instead: a script task when you can state the exact commands, an ops task when it needs judgment",
|
|
26583
|
+
...researchShellLine(researchShell),
|
|
26312
26584
|
`- ${sealedGuide("run_command")}`,
|
|
26313
26585
|
...agents === null ? [] : ["- When you delegate orientation to your own agents (WHO EXPLORES below), WAIT for their results inside this reply. Do NOT launch them in the background or async and end your turn saying you will report back later: your turn ending is what hands the conversation back to the user, and anything you say after it never reaches them."]
|
|
26314
26586
|
] : [
|
|
@@ -26356,6 +26628,11 @@ var NATIVE_SHELL_GUIDE = [
|
|
|
26356
26628
|
].join("\n");
|
|
26357
26629
|
var AUTORUN_ON = "AUTORUN is on: a plan you submit starts when your reply ends, without the user's review. When you are ready to plan, write the outline in your reply as the plan's summary and submit the plan in the same reply; do not wait for the user to confirm it, and do not start its tasks yourself. Still ask clarifying questions first when the goal is vague or a decision would materially change the outcome.";
|
|
26358
26630
|
var AUTORUN_OFF = "AUTORUN is off now: show the outline and wait for the user to confirm it before you submit a plan.";
|
|
26631
|
+
function researchShellLine(shell) {
|
|
26632
|
+
if (shell === "git-bash") return ["- On this Windows machine run_command runs Git Bash, a POSIX shell: read with cat, ls, grep and find, not PowerShell cmdlets such as Get-Content."];
|
|
26633
|
+
if (shell === "cmd") return ["- On this Windows machine run_command runs cmd.exe: read with type, dir and findstr, not PowerShell cmdlets such as Get-Content."];
|
|
26634
|
+
return [];
|
|
26635
|
+
}
|
|
26359
26636
|
var EXECUTION_TOOLS_SECTION = [
|
|
26360
26637
|
"RUNNING THE PLAN:",
|
|
26361
26638
|
"When the user asks you to start, stop or retry work, do it with these tools rather than telling them which button to press. Ordewell checks every call, may ask the user first, and a refusal says why and what would be accepted.",
|
|
@@ -26551,7 +26828,7 @@ function buildConversationBody(goal, context, modelsJson, runners, modeGuide, va
|
|
|
26551
26828
|
"4. When the strategy calls for a plan and you have enough context, produce a prose outline \u2014 a short list describing each task in order.",
|
|
26552
26829
|
autorun ? `5. Write the outline in your reply, then ${submit} in the same reply.` : `5. After the user confirms the outline, ${submit}.`,
|
|
26553
26830
|
"",
|
|
26554
|
-
researchPhaseBlock(tools, agents),
|
|
26831
|
+
researchPhaseBlock(tools, agents, variant.researchShell),
|
|
26555
26832
|
"",
|
|
26556
26833
|
...whoExploresSection(agents),
|
|
26557
26834
|
"",
|
|
@@ -26904,12 +27181,12 @@ function buildConflictRepairPrompt(task2, conflict, integrationBranch, plan) {
|
|
|
26904
27181
|
const merge = `git merge --no-edit ${quotedMessageArgs(conflict.message)} ${integrationBranch}`;
|
|
26905
27182
|
const asked = `What the task was asked to do:
|
|
26906
27183
|
${task2.prompt ?? task2.description}`;
|
|
26907
|
-
const
|
|
27184
|
+
const resolve18 = "resolve every conflict so that both sides' intent survives: keep the work already integrated and add what the task contributed.";
|
|
26908
27185
|
const repos = conflict.repos.filter((repo) => repo !== SELF_REPO);
|
|
26909
27186
|
if (repos.length === 0) {
|
|
26910
27187
|
return [
|
|
26911
27188
|
`Task ${ref2} "${task2.title}" passed, but merging its branch \`${branch}\` into \`${integrationBranch}\` conflicted${files.length > 0 ? ` in ${files.join(", ")}` : ""}. None of its work has landed yet.`,
|
|
26912
|
-
`This is the task's own worktree, on \`${branch}\`, with its work committed. Run \`${merge}\` here and ${
|
|
27189
|
+
`This is the task's own worktree, on \`${branch}\`, with its work committed. Run \`${merge}\` here and ${resolve18} Never drop either side wholesale, and never abort the merge or reset it away.`,
|
|
26913
27190
|
`Build and test the result the way this project does, commit the merge with \`${COMMIT_MERGE}\`, and only then call \`task_complete\`.`,
|
|
26914
27191
|
"",
|
|
26915
27192
|
asked
|
|
@@ -26918,7 +27195,7 @@ ${task2.prompt ?? task2.description}`;
|
|
|
26918
27195
|
const stoppedIn = conflict.conflictRepo ?? repos[0];
|
|
26919
27196
|
return [
|
|
26920
27197
|
`Task ${ref2} "${task2.title}" passed, but landing its branch \`${branch}\` on \`${integrationBranch}\` conflicted in ${stoppedIn}${files.length > 0 ? ` (${files.join(", ")})` : ""}. A task lands in every repository it changed or in none, so none of its work has landed yet.`,
|
|
26921
|
-
`This is the task's own workspace, with each repository at its usual path on \`${branch}\` and the task's work committed. In each repository the task changed \u2014 ${repos.join(", ")} \u2014 run \`${merge}\` inside that repository's directory, and ${
|
|
27198
|
+
`This is the task's own workspace, with each repository at its usual path on \`${branch}\` and the task's work committed. In each repository the task changed \u2014 ${repos.join(", ")} \u2014 run \`${merge}\` inside that repository's directory, and ${resolve18} Never drop either side wholesale, and never abort a merge or reset it away.`,
|
|
26922
27199
|
`Build and test the result the way this project does, commit the merge in each repository with \`${COMMIT_MERGE}\`, and only then call \`task_complete\`.`,
|
|
26923
27200
|
"",
|
|
26924
27201
|
asked
|
|
@@ -28270,12 +28547,12 @@ var PlannerConversation = class {
|
|
|
28270
28547
|
}
|
|
28271
28548
|
/** Resolves once no turn holds the conversation: what a subtree's stop waits on (ADR-0055 D16). */
|
|
28272
28549
|
idle() {
|
|
28273
|
-
return this.live ? new Promise((
|
|
28274
|
-
this.idling.push(
|
|
28550
|
+
return this.live ? new Promise((resolve18) => {
|
|
28551
|
+
this.idling.push(resolve18);
|
|
28275
28552
|
}) : Promise.resolve();
|
|
28276
28553
|
}
|
|
28277
28554
|
settleIdle() {
|
|
28278
|
-
for (const
|
|
28555
|
+
for (const resolve18 of this.idling.splice(0)) resolve18();
|
|
28279
28556
|
}
|
|
28280
28557
|
/** Stop the planner turn in flight; it settles as stopped. False when none is. */
|
|
28281
28558
|
stopTurn(by) {
|
|
@@ -30003,13 +30280,13 @@ function delegationSwitchedOn({ env, moduleDir, exists }) {
|
|
|
30003
30280
|
return exists(`${root}/.git`) && exists(`${root}/packages/core/package.json`);
|
|
30004
30281
|
}
|
|
30005
30282
|
function placeHere(variable) {
|
|
30006
|
-
const
|
|
30007
|
-
if (!
|
|
30283
|
+
const fs29 = typeof process === "undefined" ? void 0 : process.getBuiltinModule?.("fs");
|
|
30284
|
+
if (!fs29) return { env: void 0, moduleDir: null, exists: () => false };
|
|
30008
30285
|
const file = typeof __filename !== "undefined" ? __filename : new URL(
|
|
30009
30286
|
// @ts-expect-error - import.meta is only valid under an ESM module setting; see builtinSkills.ts
|
|
30010
30287
|
__filename
|
|
30011
30288
|
).pathname;
|
|
30012
|
-
return { env: process.env[variable], moduleDir: file.replace(/[\\/][^\\/]*$/, ""), exists: (path53) =>
|
|
30289
|
+
return { env: process.env[variable], moduleDir: file.replace(/[\\/][^\\/]*$/, ""), exists: (path53) => fs29.existsSync(path53) };
|
|
30013
30290
|
}
|
|
30014
30291
|
var DELEGATION_OFFERED = delegationSwitchedOn(placeHere(DELEGATION_ENV));
|
|
30015
30292
|
var CONTAINERS_ENV = "ORDEWELL_CONTAINERS";
|
|
@@ -30456,7 +30733,7 @@ var SettingsService = class {
|
|
|
30456
30733
|
};
|
|
30457
30734
|
|
|
30458
30735
|
// src/services/escalationNotifier.ts
|
|
30459
|
-
var
|
|
30736
|
+
var import_child_process10 = require("child_process");
|
|
30460
30737
|
var os10 = __toESM(require("os"));
|
|
30461
30738
|
var NOTIFY_TIME_LIMIT_MS = 1e4;
|
|
30462
30739
|
var NOTIFY_CONCURRENCY = 2;
|
|
@@ -30579,7 +30856,7 @@ function stop(proc) {
|
|
|
30579
30856
|
}
|
|
30580
30857
|
async function runNotifyCommand(command, env, { timeLimitMs = NOTIFY_TIME_LIMIT_MS } = {}) {
|
|
30581
30858
|
const [file, ...args] = command;
|
|
30582
|
-
const proc = (0,
|
|
30859
|
+
const proc = (0, import_child_process10.spawn)(file, args, {
|
|
30583
30860
|
cwd: os10.homedir(),
|
|
30584
30861
|
env: runnerEnv(await augmentedPath(), {}, env),
|
|
30585
30862
|
stdio: "ignore",
|
|
@@ -30588,7 +30865,7 @@ async function runNotifyCommand(command, env, { timeLimitMs = NOTIFY_TIME_LIMIT_
|
|
|
30588
30865
|
});
|
|
30589
30866
|
proc.unref();
|
|
30590
30867
|
const leaveTeardown = onHostTeardown(() => stop(proc));
|
|
30591
|
-
await new Promise((
|
|
30868
|
+
await new Promise((resolve18, reject) => {
|
|
30592
30869
|
const settle = () => {
|
|
30593
30870
|
clearTimeout(limit);
|
|
30594
30871
|
leaveTeardown();
|
|
@@ -30605,7 +30882,7 @@ async function runNotifyCommand(command, env, { timeLimitMs = NOTIFY_TIME_LIMIT_
|
|
|
30605
30882
|
});
|
|
30606
30883
|
proc.once("exit", (code, signal) => {
|
|
30607
30884
|
settle();
|
|
30608
|
-
if (code === 0)
|
|
30885
|
+
if (code === 0) resolve18();
|
|
30609
30886
|
else reject(new Error(code === null ? `ended on ${signal}` : `exited with code ${code}`));
|
|
30610
30887
|
});
|
|
30611
30888
|
});
|
|
@@ -30653,8 +30930,8 @@ function detectInstalledPlanner(installation) {
|
|
|
30653
30930
|
return probe;
|
|
30654
30931
|
}
|
|
30655
30932
|
async function installedPlannerDetected() {
|
|
30656
|
-
while (!answered2) await new Promise((
|
|
30657
|
-
waiters.push(
|
|
30933
|
+
while (!answered2) await new Promise((resolve18) => {
|
|
30934
|
+
waiters.push(resolve18);
|
|
30658
30935
|
});
|
|
30659
30936
|
}
|
|
30660
30937
|
function installedPlannerAnswered() {
|
|
@@ -31195,9 +31472,8 @@ function mergeOutcome(result, branch, group, repaired = []) {
|
|
|
31195
31472
|
|
|
31196
31473
|
// src/services/taskDiffRead.ts
|
|
31197
31474
|
var import_crypto13 = require("crypto");
|
|
31198
|
-
var
|
|
31475
|
+
var fs15 = __toESM(require("fs"));
|
|
31199
31476
|
var path37 = __toESM(require("path"));
|
|
31200
|
-
var import_os3 = require("os");
|
|
31201
31477
|
|
|
31202
31478
|
// src/services/stateRoot.ts
|
|
31203
31479
|
var fs13 = __toESM(require("fs"));
|
|
@@ -31225,6 +31501,16 @@ function refuseUsersCheckout(codeRoot, stateRoot) {
|
|
|
31225
31501
|
}
|
|
31226
31502
|
}
|
|
31227
31503
|
|
|
31504
|
+
// src/utils/realPath.ts
|
|
31505
|
+
var fs14 = __toESM(require("fs"));
|
|
31506
|
+
function realPathOf(p) {
|
|
31507
|
+
try {
|
|
31508
|
+
return fs14.realpathSync.native(p);
|
|
31509
|
+
} catch {
|
|
31510
|
+
return fs14.realpathSync(p);
|
|
31511
|
+
}
|
|
31512
|
+
}
|
|
31513
|
+
|
|
31228
31514
|
// src/services/taskDiffRead.ts
|
|
31229
31515
|
var TASK_DIFF_UNAVAILABLE = "Task diff is not available for this run: no task-specific changes were recorded (shared runs cannot attribute workspace changes to one task).";
|
|
31230
31516
|
function allowedPath(file) {
|
|
@@ -31332,18 +31618,18 @@ async function readTaskDiff(invoker, run, taskId, options) {
|
|
|
31332
31618
|
};
|
|
31333
31619
|
try {
|
|
31334
31620
|
const files = [];
|
|
31335
|
-
const workspaceRoot =
|
|
31621
|
+
const workspaceRoot = fs15.realpathSync(stateRootOf(run));
|
|
31336
31622
|
for (const repo of run.repos) {
|
|
31337
31623
|
if (options.repo !== void 0 && repo.path !== options.repo) continue;
|
|
31338
31624
|
const entry = record.repos[repo.path];
|
|
31339
31625
|
if (!entry?.baseRef) return { available: false, reason: `Task diff is not available for repository ${repo.path}: this older run did not record the task's starting commit.` };
|
|
31340
31626
|
if (!/^[a-f0-9]{40,64}$/.test(entry.baseRef)) throw new Error("Invalid recorded starting commit.");
|
|
31341
|
-
const live3 = record.status !== "merged" &&
|
|
31627
|
+
const live3 = record.status !== "merged" && fs15.existsSync(entry.worktree);
|
|
31342
31628
|
const cwd = live3 ? entry.worktree : repo.root;
|
|
31343
|
-
if (!inside(workspaceRoot,
|
|
31629
|
+
if (!inside(workspaceRoot, fs15.realpathSync(cwd))) throw new Error("The recorded task repository moved outside the workspace.");
|
|
31344
31630
|
if (live3) {
|
|
31345
31631
|
const toplevel = (await git(reader, cwd, ["rev-parse", "--show-toplevel"])).trim();
|
|
31346
|
-
if (
|
|
31632
|
+
if (realPathOf(toplevel) !== realPathOf(entry.worktree)) throw new Error("The recorded task worktree is no longer a repository.");
|
|
31347
31633
|
}
|
|
31348
31634
|
const prefix = (await git(reader, repo.root, ["rev-parse", "--show-prefix"])).trim();
|
|
31349
31635
|
const common = ["--no-pager", "-c", "core.fsmonitor=false"];
|
|
@@ -31378,9 +31664,9 @@ async function readTaskDiff(invoker, run, taskId, options) {
|
|
|
31378
31664
|
const others = await git(reader, workspace, [...common, "ls-files", "--others", "--exclude-standard", "-z", "--", "."]);
|
|
31379
31665
|
for (const file of others.split("\0").filter((f) => f && allowed(f))) {
|
|
31380
31666
|
const full = path37.join(workspace, file);
|
|
31381
|
-
if (!inside(
|
|
31667
|
+
if (!inside(fs15.realpathSync(workspace), fs15.realpathSync(path37.dirname(full)))) continue;
|
|
31382
31668
|
const untracked = async (numstat) => {
|
|
31383
|
-
const result = await tryGit(reader, workspace, [...common, "diff", "--no-index", "--no-renames", "--no-ext-diff", "--no-textconv", ...numstat ? ["--numstat", "-z"] : [], "--",
|
|
31669
|
+
const result = await tryGit(reader, workspace, [...common, "diff", "--no-index", "--no-renames", "--no-ext-diff", "--no-textconv", ...numstat ? ["--numstat", "-z"] : [], "--", "/dev/null", file]);
|
|
31384
31670
|
if (!result.ok && result.code !== 1) throw new Error(result.stderr.trim() || "Could not read an untracked file diff.");
|
|
31385
31671
|
return result.stdout;
|
|
31386
31672
|
};
|
|
@@ -31407,8 +31693,8 @@ ${await file.patch()}`);
|
|
|
31407
31693
|
|
|
31408
31694
|
// src/services/GitWorktreeIsolation.ts
|
|
31409
31695
|
var import_crypto14 = require("crypto");
|
|
31410
|
-
var
|
|
31411
|
-
var
|
|
31696
|
+
var import_child_process11 = require("child_process");
|
|
31697
|
+
var fs17 = __toESM(require("fs"));
|
|
31412
31698
|
var path39 = __toESM(require("path"));
|
|
31413
31699
|
|
|
31414
31700
|
// src/utils/shell.ts
|
|
@@ -31421,7 +31707,7 @@ function shellQuoted(text6) {
|
|
|
31421
31707
|
}
|
|
31422
31708
|
|
|
31423
31709
|
// src/utils/prdStore.ts
|
|
31424
|
-
var
|
|
31710
|
+
var fs16 = __toESM(require("fs"));
|
|
31425
31711
|
var path38 = __toESM(require("path"));
|
|
31426
31712
|
var PRD_BLOCK_RE = /<!--\s*ORDEWELL_PRD_START\s+slug="([^"]+)"\s*-->\s*([\s\S]*?)\s*<!--\s*ORDEWELL_PRD_END\s*-->/;
|
|
31427
31713
|
function extractPrdBlock(text6) {
|
|
@@ -31437,9 +31723,9 @@ function sanitizeSlug(raw) {
|
|
|
31437
31723
|
}
|
|
31438
31724
|
function savePrdMarkdown(workspace, slug, markdown) {
|
|
31439
31725
|
const dir = path38.join(workspace, ".scratch", sanitizeSlug(slug));
|
|
31440
|
-
|
|
31726
|
+
fs16.mkdirSync(dir, { recursive: true });
|
|
31441
31727
|
const file = path38.join(dir, "PRD.md");
|
|
31442
|
-
|
|
31728
|
+
fs16.writeFileSync(file, markdown.endsWith("\n") ? markdown : markdown + "\n", "utf8");
|
|
31443
31729
|
return file;
|
|
31444
31730
|
}
|
|
31445
31731
|
|
|
@@ -31599,7 +31885,7 @@ function isInside(parent, child) {
|
|
|
31599
31885
|
}
|
|
31600
31886
|
function resolvesAsNamed(base, p) {
|
|
31601
31887
|
try {
|
|
31602
|
-
return
|
|
31888
|
+
return fs17.realpathSync(p) === path39.join(fs17.realpathSync(base), path39.relative(base, p));
|
|
31603
31889
|
} catch {
|
|
31604
31890
|
return false;
|
|
31605
31891
|
}
|
|
@@ -31693,7 +31979,7 @@ function settleStatus(record, status) {
|
|
|
31693
31979
|
}
|
|
31694
31980
|
function realDir(p) {
|
|
31695
31981
|
try {
|
|
31696
|
-
return
|
|
31982
|
+
return fs17.realpathSync.native(p);
|
|
31697
31983
|
} catch {
|
|
31698
31984
|
return path39.resolve(p);
|
|
31699
31985
|
}
|
|
@@ -31703,7 +31989,7 @@ function sameDir(a, b) {
|
|
|
31703
31989
|
}
|
|
31704
31990
|
function resolves(target) {
|
|
31705
31991
|
try {
|
|
31706
|
-
|
|
31992
|
+
fs17.statSync(target);
|
|
31707
31993
|
return true;
|
|
31708
31994
|
} catch {
|
|
31709
31995
|
return false;
|
|
@@ -31715,7 +32001,7 @@ function inactive(reason, repos) {
|
|
|
31715
32001
|
}
|
|
31716
32002
|
function clearImmutableFlags(platform, dir) {
|
|
31717
32003
|
if (platform !== "darwin") return;
|
|
31718
|
-
(0,
|
|
32004
|
+
(0, import_child_process11.spawnSync)("/usr/bin/chflags", ["-R", "nouchg", dir], { stdio: "ignore" });
|
|
31719
32005
|
}
|
|
31720
32006
|
function leftoverLinks(dir) {
|
|
31721
32007
|
const named3 = listDir2(dir).filter((name) => LINKED_ARTIFACTS.has(name) || isEnvFile(name) || isLink(path39.join(dir, name)));
|
|
@@ -31723,7 +32009,7 @@ function leftoverLinks(dir) {
|
|
|
31723
32009
|
}
|
|
31724
32010
|
function isLink(target) {
|
|
31725
32011
|
try {
|
|
31726
|
-
return
|
|
32012
|
+
return fs17.lstatSync(target).isSymbolicLink();
|
|
31727
32013
|
} catch {
|
|
31728
32014
|
return false;
|
|
31729
32015
|
}
|
|
@@ -31935,7 +32221,7 @@ var GitWorktreeIsolation = class {
|
|
|
31935
32221
|
async acceptsWorktree(run, repo) {
|
|
31936
32222
|
const dir = this.integrationDir(run, repo);
|
|
31937
32223
|
ensureStateDirIgnored(stateRootOf(run));
|
|
31938
|
-
|
|
32224
|
+
fs17.mkdirSync(path39.dirname(dir), { recursive: true });
|
|
31939
32225
|
const added = await this.tryGit(repo.root, ["worktree", "add", "-q", "--no-checkout", dir, repo.integrationBranch]);
|
|
31940
32226
|
await this.removeWorktreeDir(run, repo, dir, []);
|
|
31941
32227
|
return added.ok;
|
|
@@ -32003,7 +32289,7 @@ var GitWorktreeIsolation = class {
|
|
|
32003
32289
|
for (const repo of run.repos) {
|
|
32004
32290
|
const worktree = path39.join(dir, repo.path);
|
|
32005
32291
|
const tip = (await this.git(repo.root, ["rev-parse", repo.integrationBranch])).trim();
|
|
32006
|
-
|
|
32292
|
+
fs17.mkdirSync(path39.dirname(worktree), { recursive: true });
|
|
32007
32293
|
await this.git(repo.root, ["worktree", "add", "-q", "-B", branch, worktree, tip]);
|
|
32008
32294
|
record.repos[repo.path] = { worktree, linked: [], baseRef: tip };
|
|
32009
32295
|
}
|
|
@@ -32035,7 +32321,7 @@ var GitWorktreeIsolation = class {
|
|
|
32035
32321
|
const source = path39.join(run.workspaceRoot, rel);
|
|
32036
32322
|
const target = path39.join(cwd, rel);
|
|
32037
32323
|
if (!resolves(source) || lexists(target)) continue;
|
|
32038
|
-
|
|
32324
|
+
fs17.mkdirSync(path39.dirname(target), { recursive: true });
|
|
32039
32325
|
if (linkPath(source, target, this.platform) === "copy") copied.push(rel);
|
|
32040
32326
|
const entry = self ? record.repos[SELF_REPO] : void 0;
|
|
32041
32327
|
if (entry) entry.linked.push(rel);
|
|
@@ -32088,7 +32374,7 @@ var GitWorktreeIsolation = class {
|
|
|
32088
32374
|
}
|
|
32089
32375
|
const base = { branch: names2.branch, name: path39.basename(names2.dir), title: task2.title };
|
|
32090
32376
|
for (const worktree of at) {
|
|
32091
|
-
if (!
|
|
32377
|
+
if (!fs17.existsSync(worktree)) continue;
|
|
32092
32378
|
const linked = leftoverLinks(path39.join(worktree, await this.prefixOf(repo)));
|
|
32093
32379
|
found.push({ repo, worktree, target: { ...base, worktree, linked } });
|
|
32094
32380
|
}
|
|
@@ -32107,7 +32393,7 @@ var GitWorktreeIsolation = class {
|
|
|
32107
32393
|
if (target.worktree) await this.removeWorktreeDir(run, repo, worktree, target.linked);
|
|
32108
32394
|
}
|
|
32109
32395
|
for (const repo of run.repos) await this.tryGit(repo.root, ["branch", "-D", names2.branch]);
|
|
32110
|
-
this.removeTaskWorkspace(run, names2.dir);
|
|
32396
|
+
await this.removeTaskWorkspace(run, names2.dir);
|
|
32111
32397
|
return removal;
|
|
32112
32398
|
}
|
|
32113
32399
|
async restorePrevious(record, preserved) {
|
|
@@ -32137,7 +32423,7 @@ var GitWorktreeIsolation = class {
|
|
|
32137
32423
|
for (const repo of run.repos) {
|
|
32138
32424
|
const entry = record.repos[repo.path];
|
|
32139
32425
|
if (!entry) continue;
|
|
32140
|
-
if (!
|
|
32426
|
+
if (!fs17.existsSync(entry.worktree)) throw new Error(`The worktree of task ${task2.order} is gone: ${entry.worktree}`);
|
|
32141
32427
|
if (repo.path === SELF_REPO) cwd = await this.inWorkspacePlace(repo, entry.worktree);
|
|
32142
32428
|
if (entry.changed || repo.path === record.conflictRepo) {
|
|
32143
32429
|
repairBase[repo.path] = (await this.git(repo.root, ["rev-parse", "--verify", repo.integrationBranch])).trim();
|
|
@@ -32286,7 +32572,7 @@ var GitWorktreeIsolation = class {
|
|
|
32286
32572
|
* out of sync, and deleting it is the one action that cannot be undone.
|
|
32287
32573
|
*/
|
|
32288
32574
|
async worktreeHasChanges(entry, prefix) {
|
|
32289
|
-
if (!
|
|
32575
|
+
if (!fs17.existsSync(entry.worktree)) return false;
|
|
32290
32576
|
const status = await this.tryGit(entry.worktree, ["status", "--porcelain", "-z", "--untracked-files=normal"]);
|
|
32291
32577
|
if (!status.ok) return true;
|
|
32292
32578
|
const linked = new Set(entry.linked);
|
|
@@ -32692,7 +32978,7 @@ var GitWorktreeIsolation = class {
|
|
|
32692
32978
|
for (const repo of run.repos) {
|
|
32693
32979
|
const entry = record.repos[repo.path];
|
|
32694
32980
|
if (!entry) continue;
|
|
32695
|
-
if (!
|
|
32981
|
+
if (!fs17.existsSync(entry.worktree)) {
|
|
32696
32982
|
return this.stopLanding(record, "failed", repo, void 0, `its worktree is gone (${entry.worktree})`);
|
|
32697
32983
|
}
|
|
32698
32984
|
try {
|
|
@@ -32942,7 +33228,7 @@ var GitWorktreeIsolation = class {
|
|
|
32942
33228
|
const ref2 = `refs/heads/${repo.integrationBranch}`;
|
|
32943
33229
|
if (!(await this.tryGit(repo.root, ["update-ref", ref2, made, onto])).ok) return { strayed: true };
|
|
32944
33230
|
const dir = this.integrationDir(run, repo);
|
|
32945
|
-
if (!
|
|
33231
|
+
if (!fs17.existsSync(path39.join(dir, ".git"))) return { onto: made };
|
|
32946
33232
|
const read2 = await this.readAcross(dir, onto, made);
|
|
32947
33233
|
if (read2.ok) return { onto: made };
|
|
32948
33234
|
if (!(await this.tryGit(repo.root, ["update-ref", ref2, onto, made])).ok) return { strayed: true };
|
|
@@ -33047,7 +33333,7 @@ var GitWorktreeIsolation = class {
|
|
|
33047
33333
|
if (!await (reverts ? this.isRevertsOn(repo, head, tip, reverts) : this.isOneMergeOn(repo, head, tip))) return false;
|
|
33048
33334
|
const dir = this.integrationDir(run, repo);
|
|
33049
33335
|
const held2 = await this.worktreeHolding(repo, repo.integrationBranch);
|
|
33050
|
-
if (!held2 && (!
|
|
33336
|
+
if (!held2 && (!fs17.existsSync(path39.join(dir, ".git")) || await this.integrationOffBranch(run, repo))) return false;
|
|
33051
33337
|
const holder = held2 ? held2.worktree : dir;
|
|
33052
33338
|
if (holder === null) return (await this.tryGit(repo.root, ["update-ref", `refs/heads/${repo.integrationBranch}`, tip, head])).ok;
|
|
33053
33339
|
if (!sameDir(holder, dir)) return false;
|
|
@@ -33102,7 +33388,7 @@ var GitWorktreeIsolation = class {
|
|
|
33102
33388
|
*/
|
|
33103
33389
|
async integrationOffBranch(run, repo) {
|
|
33104
33390
|
const dir = this.integrationDir(run, repo);
|
|
33105
|
-
if (!
|
|
33391
|
+
if (!fs17.existsSync(path39.join(dir, ".git"))) return null;
|
|
33106
33392
|
const head = (await this.tryGit(dir, ["symbolic-ref", "-q", "HEAD"])).stdout.trim();
|
|
33107
33393
|
if (head === `refs/heads/${repo.integrationBranch}`) return null;
|
|
33108
33394
|
return `${head ? `on ${head.replace(/^refs\/heads\//, "")}` : "detached"}, not on ${repo.integrationBranch}`;
|
|
@@ -33113,7 +33399,7 @@ var GitWorktreeIsolation = class {
|
|
|
33113
33399
|
if (!listed5.ok) return null;
|
|
33114
33400
|
let worktree = null;
|
|
33115
33401
|
for (const line of listed5.stdout.split(/\r?\n/)) {
|
|
33116
|
-
if (line.startsWith("worktree ")) worktree = line.slice("worktree ".length);
|
|
33402
|
+
if (line.startsWith("worktree ")) worktree = path39.normalize(line.slice("worktree ".length));
|
|
33117
33403
|
else if (line === `branch refs/heads/${branch}`) return { worktree };
|
|
33118
33404
|
}
|
|
33119
33405
|
return { worktree: null };
|
|
@@ -33130,12 +33416,58 @@ var GitWorktreeIsolation = class {
|
|
|
33130
33416
|
if ((await this.tryGit(entry.worktree, ["check-ignore", "-q", "--", prefix + name])).ok) continue;
|
|
33131
33417
|
excludes.push(`:(exclude,literal)${(prefix + name).replace(/\\/g, "/")}`);
|
|
33132
33418
|
}
|
|
33419
|
+
if (this.platform === "win32") {
|
|
33420
|
+
const made = entry.linked.map((name) => (prefix + name).replace(/\\/g, "/"));
|
|
33421
|
+
const under = (link) => made.some((dir) => link === dir || link.startsWith(`${dir}/`));
|
|
33422
|
+
for (const link of await this.linksGitWalksInto(entry.worktree)) {
|
|
33423
|
+
if (!under(link)) excludes.push(`:(exclude,literal)${link}`);
|
|
33424
|
+
}
|
|
33425
|
+
}
|
|
33133
33426
|
await this.git(entry.worktree, ["add", "-A", "--", ".", ...excludes]);
|
|
33134
33427
|
const staged = await this.tryGit(entry.worktree, ["diff", "--cached", "--quiet"]);
|
|
33135
33428
|
if (staged.ok) return;
|
|
33136
33429
|
const commit = opts.rescue ? ["-c", "commit.gpgsign=false", "commit", "--no-verify"] : ["commit"];
|
|
33137
33430
|
await this.git(entry.worktree, [...VERBATIM, ...commit, "-q", ...messageArgs(message)]);
|
|
33138
33431
|
}
|
|
33432
|
+
/**
|
|
33433
|
+
* The links git would walk into when it stages `worktree`: on Windows a
|
|
33434
|
+
* junction reads to git as the directory it leads to, so staging one a task
|
|
33435
|
+
* left commits what it holds, a folder of the user's as readily as anything.
|
|
33436
|
+
* A symbolic link git stages as a link, as it does elsewhere, and keeps. Read
|
|
33437
|
+
* from git's own listing, one call, so what git ignores, a mirrored install
|
|
33438
|
+
* among it, is never walked; and a link is told by lstat, as Windows reports
|
|
33439
|
+
* every reparse point, a OneDrive placeholder too, as a link in a directory
|
|
33440
|
+
* listing.
|
|
33441
|
+
*/
|
|
33442
|
+
async linksGitWalksInto(worktree) {
|
|
33443
|
+
const listed5 = await this.tryGit(worktree, ["status", "--porcelain=v1", "-z", "--no-renames", "--untracked-files=all"]);
|
|
33444
|
+
if (!listed5.ok) throw new Error(`git could not list what the worktree holds: ${firstLine3(listed5.stderr.trim() || `exit ${listed5.code}`)}`);
|
|
33445
|
+
const isLink2 = /* @__PURE__ */ new Map();
|
|
33446
|
+
const linkAt = (rel) => {
|
|
33447
|
+
let link = isLink2.get(rel);
|
|
33448
|
+
if (link === void 0) {
|
|
33449
|
+
try {
|
|
33450
|
+
link = fs17.lstatSync(path39.join(worktree, rel)).isSymbolicLink();
|
|
33451
|
+
} catch {
|
|
33452
|
+
link = false;
|
|
33453
|
+
}
|
|
33454
|
+
isLink2.set(rel, link);
|
|
33455
|
+
}
|
|
33456
|
+
return link;
|
|
33457
|
+
};
|
|
33458
|
+
const found = /* @__PURE__ */ new Set();
|
|
33459
|
+
for (const entry of listed5.stdout.split("\0")) {
|
|
33460
|
+
const parts = entry.slice(3).split("/");
|
|
33461
|
+
for (let depth = 1; depth < parts.length; depth++) {
|
|
33462
|
+
const dir = parts.slice(0, depth).join("/");
|
|
33463
|
+
if (linkAt(dir)) {
|
|
33464
|
+
found.add(dir);
|
|
33465
|
+
break;
|
|
33466
|
+
}
|
|
33467
|
+
}
|
|
33468
|
+
}
|
|
33469
|
+
return [...found];
|
|
33470
|
+
}
|
|
33139
33471
|
/** A message Ordewell writes, with the trailer if the user's setting says so right now. */
|
|
33140
33472
|
message(kind, from) {
|
|
33141
33473
|
return landingMessage(kind, from, this.deps.plannedWith?.() ?? false);
|
|
@@ -33146,10 +33478,10 @@ var GitWorktreeIsolation = class {
|
|
|
33146
33478
|
async ensureIntegrationWorktree(run, repo) {
|
|
33147
33479
|
return this.admin(stateRootOf(run), async () => {
|
|
33148
33480
|
const dir = this.integrationDir(run, repo);
|
|
33149
|
-
if (
|
|
33481
|
+
if (fs17.existsSync(path39.join(dir, ".git"))) return dir;
|
|
33150
33482
|
await this.tryGit(repo.root, ["worktree", "prune"]);
|
|
33151
33483
|
ensureStateDirIgnored(stateRootOf(run));
|
|
33152
|
-
|
|
33484
|
+
fs17.mkdirSync(path39.dirname(dir), { recursive: true });
|
|
33153
33485
|
await this.git(repo.root, ["worktree", "add", "-q", dir, repo.integrationBranch]);
|
|
33154
33486
|
return dir;
|
|
33155
33487
|
});
|
|
@@ -33186,7 +33518,7 @@ var GitWorktreeIsolation = class {
|
|
|
33186
33518
|
if (entry) await this.removeWorktreeDir(run, repo, entry.worktree, entry.linked);
|
|
33187
33519
|
await this.tryGit(repo.root, ["branch", "-D", record.branch]);
|
|
33188
33520
|
}
|
|
33189
|
-
this.removeTaskWorkspace(run, record.workspace);
|
|
33521
|
+
await this.removeTaskWorkspace(run, record.workspace);
|
|
33190
33522
|
if (opts.dropRecord) delete run.tasks[record.taskId];
|
|
33191
33523
|
return removal;
|
|
33192
33524
|
}
|
|
@@ -33210,7 +33542,7 @@ var GitWorktreeIsolation = class {
|
|
|
33210
33542
|
}
|
|
33211
33543
|
async tipToKeep(repo, target) {
|
|
33212
33544
|
const { worktree } = target;
|
|
33213
|
-
if (worktree &&
|
|
33545
|
+
if (worktree && fs17.existsSync(worktree)) {
|
|
33214
33546
|
if (!hasGitEntry(worktree)) throw new Error("it is not a git worktree any more");
|
|
33215
33547
|
if (await this.worktreeHasChanges({ worktree, linked: target.linked }, await this.prefixOf(repo))) {
|
|
33216
33548
|
await this.commitWorktree(repo, { worktree, linked: target.linked }, this.message("rescue", target), { rescue: true });
|
|
@@ -33240,23 +33572,40 @@ var GitWorktreeIsolation = class {
|
|
|
33240
33572
|
* links and the directories that held deeper repos. Links are unlinked
|
|
33241
33573
|
* first, so removing the rest can never walk into the real workspace.
|
|
33242
33574
|
*/
|
|
33243
|
-
removeTaskWorkspace(run, dir) {
|
|
33244
|
-
if (!isInside(this.runRoot(run), dir) || !
|
|
33575
|
+
async removeTaskWorkspace(run, dir) {
|
|
33576
|
+
if (!isInside(this.runRoot(run), dir) || !fs17.existsSync(dir)) return;
|
|
33245
33577
|
this.unlinkLinksUnder(dir);
|
|
33246
33578
|
clearImmutableFlags(this.platform, dir);
|
|
33247
|
-
|
|
33579
|
+
await this.removeDir(dir);
|
|
33580
|
+
}
|
|
33581
|
+
/**
|
|
33582
|
+
* Windows removes no directory a process works in, and a runner stopped
|
|
33583
|
+
* there a moment ago may still be going: taskkill ends it from another
|
|
33584
|
+
* process. So there the removal waits for it, a while, before it gives up.
|
|
33585
|
+
*/
|
|
33586
|
+
async removeDir(dir) {
|
|
33587
|
+
if (this.platform === "win32") await fs17.promises.rm(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
|
|
33588
|
+
else fs17.rmSync(dir, { recursive: true, force: true });
|
|
33248
33589
|
}
|
|
33249
33590
|
unlinkLinksUnder(dir) {
|
|
33250
33591
|
let entries;
|
|
33251
33592
|
try {
|
|
33252
|
-
entries =
|
|
33593
|
+
entries = fs17.readdirSync(dir, { withFileTypes: true });
|
|
33253
33594
|
} catch {
|
|
33254
33595
|
return;
|
|
33255
33596
|
}
|
|
33256
33597
|
for (const entry of entries) {
|
|
33257
33598
|
const target = path39.join(dir, entry.name);
|
|
33258
|
-
if (entry.
|
|
33259
|
-
else if (entry.
|
|
33599
|
+
if (entry.isDirectory()) this.unlinkLinksUnder(target);
|
|
33600
|
+
else if (entry.isSymbolicLink()) {
|
|
33601
|
+
let stat;
|
|
33602
|
+
try {
|
|
33603
|
+
stat = fs17.lstatSync(target);
|
|
33604
|
+
} catch {
|
|
33605
|
+
}
|
|
33606
|
+
if (stat?.isSymbolicLink()) this.unlinkIfLink(target);
|
|
33607
|
+
else if (stat?.isDirectory()) this.unlinkLinksUnder(target);
|
|
33608
|
+
}
|
|
33260
33609
|
}
|
|
33261
33610
|
}
|
|
33262
33611
|
/**
|
|
@@ -33278,8 +33627,8 @@ var GitWorktreeIsolation = class {
|
|
|
33278
33627
|
};
|
|
33279
33628
|
const owned = new Set(Object.values(run.tasks).map((r) => path39.resolve(r.workspace)));
|
|
33280
33629
|
const root = this.runRoot(run);
|
|
33281
|
-
if (
|
|
33282
|
-
for (const entry of
|
|
33630
|
+
if (fs17.existsSync(root)) {
|
|
33631
|
+
for (const entry of fs17.readdirSync(root)) {
|
|
33283
33632
|
const dir = path39.join(root, entry);
|
|
33284
33633
|
if (entry === INTEGRATION_DIR || owned.has(path39.resolve(dir))) continue;
|
|
33285
33634
|
let kept = true;
|
|
@@ -33290,7 +33639,7 @@ var GitWorktreeIsolation = class {
|
|
|
33290
33639
|
}
|
|
33291
33640
|
if (!kept) continue;
|
|
33292
33641
|
for (const repo of run.repos) await this.removeWorktreeDir(run, repo, path39.join(dir, repo.path), []);
|
|
33293
|
-
this.removeTaskWorkspace(run, dir);
|
|
33642
|
+
await this.removeTaskWorkspace(run, dir);
|
|
33294
33643
|
}
|
|
33295
33644
|
}
|
|
33296
33645
|
const taskBranches = Object.values(run.tasks).map((r) => r.branch);
|
|
@@ -33306,32 +33655,36 @@ var GitWorktreeIsolation = class {
|
|
|
33306
33655
|
return removal;
|
|
33307
33656
|
}
|
|
33308
33657
|
async removeWorktreeDir(run, repo, dir, linked) {
|
|
33309
|
-
|
|
33310
|
-
|
|
33311
|
-
|
|
33312
|
-
|
|
33313
|
-
|
|
33314
|
-
|
|
33315
|
-
|
|
33316
|
-
|
|
33658
|
+
const prefix = (await this.tryGit(repo.root, ["rev-parse", "--show-prefix"])).stdout.trim();
|
|
33659
|
+
for (const base of /* @__PURE__ */ new Set([dir, path39.join(dir, prefix)])) {
|
|
33660
|
+
for (const name of /* @__PURE__ */ new Set([...linked, ...installDirs(base)])) {
|
|
33661
|
+
const target = path39.join(base, name);
|
|
33662
|
+
if (!resolvesAsNamed(this.runRoot(run), path39.dirname(target))) continue;
|
|
33663
|
+
this.unlinkIfLink(target);
|
|
33664
|
+
this.unlinkLinksUnder(target);
|
|
33665
|
+
}
|
|
33666
|
+
for (const name of resolvesAsNamed(this.runRoot(run), base) ? fs17.readdirSync(base) : []) {
|
|
33667
|
+
if (LINKED_ARTIFACTS.has(name) || isEnvFile(name)) this.unlinkIfLink(path39.join(base, name));
|
|
33668
|
+
}
|
|
33317
33669
|
}
|
|
33670
|
+
if (this.platform === "win32" && resolvesAsNamed(this.runRoot(run), dir)) this.unlinkLinksUnder(dir);
|
|
33318
33671
|
await this.tryGit(repo.root, ["worktree", "remove", "--force", dir]);
|
|
33319
|
-
if (
|
|
33672
|
+
if (fs17.existsSync(dir) && isInside(this.runRoot(run), dir)) {
|
|
33320
33673
|
clearImmutableFlags(this.platform, dir);
|
|
33321
|
-
|
|
33674
|
+
await this.removeDir(dir);
|
|
33322
33675
|
}
|
|
33323
33676
|
await this.tryGit(repo.root, ["worktree", "prune"]);
|
|
33324
33677
|
for (let parent = path39.dirname(dir); isInside(this.runRoot(run), parent); parent = path39.dirname(parent)) this.removeIfEmpty(parent);
|
|
33325
33678
|
}
|
|
33326
33679
|
unlinkIfLink(target) {
|
|
33327
33680
|
try {
|
|
33328
|
-
if (
|
|
33681
|
+
if (fs17.lstatSync(target).isSymbolicLink()) fs17.rmSync(target, { force: true });
|
|
33329
33682
|
} catch {
|
|
33330
33683
|
}
|
|
33331
33684
|
}
|
|
33332
33685
|
removeIfEmpty(dir) {
|
|
33333
33686
|
try {
|
|
33334
|
-
|
|
33687
|
+
fs17.rmdirSync(dir);
|
|
33335
33688
|
} catch {
|
|
33336
33689
|
}
|
|
33337
33690
|
}
|
|
@@ -33358,7 +33711,7 @@ var GitWorktreeIsolation = class {
|
|
|
33358
33711
|
async rebaseInProgress(cwd) {
|
|
33359
33712
|
for (const dir of ["rebase-merge", "rebase-apply"]) {
|
|
33360
33713
|
const found = await this.tryGit(cwd, ["rev-parse", "--git-path", dir]);
|
|
33361
|
-
if (found.ok &&
|
|
33714
|
+
if (found.ok && fs17.existsSync(path39.resolve(cwd, found.stdout.trim()))) return true;
|
|
33362
33715
|
}
|
|
33363
33716
|
return false;
|
|
33364
33717
|
}
|
|
@@ -33389,7 +33742,7 @@ function createWorktreeIsolation(deps) {
|
|
|
33389
33742
|
}
|
|
33390
33743
|
|
|
33391
33744
|
// src/utils/sessionStore.ts
|
|
33392
|
-
var
|
|
33745
|
+
var fs18 = __toESM(require("fs"));
|
|
33393
33746
|
var path40 = __toESM(require("path"));
|
|
33394
33747
|
|
|
33395
33748
|
// src/interfaces/ILogger.ts
|
|
@@ -33443,7 +33796,7 @@ var NO_RESEARCH_LOG = [];
|
|
|
33443
33796
|
var writtenLogs = /* @__PURE__ */ new Map();
|
|
33444
33797
|
function saveResearchLog(log, file) {
|
|
33445
33798
|
const written = writtenLogs.get(file);
|
|
33446
|
-
const unchanged =
|
|
33799
|
+
const unchanged = fs18.existsSync(file) ? written?.log.deref() === log && written.length === log.length : log.length === 0;
|
|
33447
33800
|
if (unchanged) return;
|
|
33448
33801
|
writeFileAtomic(file, JSON.stringify(log));
|
|
33449
33802
|
writtenLogs.set(file, { log: new WeakRef(log), length: log.length });
|
|
@@ -33451,7 +33804,7 @@ function saveResearchLog(log, file) {
|
|
|
33451
33804
|
function restoreResearchLog(plan, sessionId, file, logger) {
|
|
33452
33805
|
if (plan.researchLog) return;
|
|
33453
33806
|
try {
|
|
33454
|
-
plan.researchLog = JSON.parse(
|
|
33807
|
+
plan.researchLog = JSON.parse(fs18.readFileSync(file, "utf-8"));
|
|
33455
33808
|
} catch (err) {
|
|
33456
33809
|
if (err.code !== "ENOENT") logger.warn("sessionStore", `failed to read the research log of ${sessionId}; going on without it`, err);
|
|
33457
33810
|
}
|
|
@@ -33482,10 +33835,10 @@ function legacySessionFilename(session) {
|
|
|
33482
33835
|
}
|
|
33483
33836
|
function dropLegacyFile(sessionsDir, meta) {
|
|
33484
33837
|
const legacy = path40.join(sessionsDir, legacySessionFilename(meta));
|
|
33485
|
-
if (legacy === path40.join(sessionsDir, sessionFilename(meta)) || !
|
|
33838
|
+
if (legacy === path40.join(sessionsDir, sessionFilename(meta)) || !fs18.existsSync(legacy)) return;
|
|
33486
33839
|
try {
|
|
33487
|
-
const held2 = JSON.parse(
|
|
33488
|
-
if (held2 === meta.id)
|
|
33840
|
+
const held2 = JSON.parse(fs18.readFileSync(legacy, "utf-8")).meta?.id;
|
|
33841
|
+
if (held2 === meta.id) fs18.unlinkSync(legacy);
|
|
33489
33842
|
} catch {
|
|
33490
33843
|
}
|
|
33491
33844
|
}
|
|
@@ -33527,7 +33880,7 @@ function listChildSessions(rootSessionId, baseDir) {
|
|
|
33527
33880
|
const dir = childSessionsDir(rootSessionId, baseDir);
|
|
33528
33881
|
const named3 = (entry) => {
|
|
33529
33882
|
try {
|
|
33530
|
-
const session = JSON.parse(
|
|
33883
|
+
const session = JSON.parse(fs18.readFileSync(path40.join(dir, entry, CHILD_SESSION_FILE), "utf-8"));
|
|
33531
33884
|
return isSessionMeta(session.meta) ? session.meta.id : null;
|
|
33532
33885
|
} catch {
|
|
33533
33886
|
return null;
|
|
@@ -33535,7 +33888,7 @@ function listChildSessions(rootSessionId, baseDir) {
|
|
|
33535
33888
|
};
|
|
33536
33889
|
let entries;
|
|
33537
33890
|
try {
|
|
33538
|
-
entries =
|
|
33891
|
+
entries = fs18.readdirSync(dir);
|
|
33539
33892
|
} catch {
|
|
33540
33893
|
return [];
|
|
33541
33894
|
}
|
|
@@ -33543,12 +33896,12 @@ function listChildSessions(rootSessionId, baseDir) {
|
|
|
33543
33896
|
}
|
|
33544
33897
|
function listSessions(baseDir, logger = defaultLogger) {
|
|
33545
33898
|
const sessionsDir = getSessionsDir(baseDir);
|
|
33546
|
-
if (!
|
|
33547
|
-
const files =
|
|
33899
|
+
if (!fs18.existsSync(sessionsDir)) return [];
|
|
33900
|
+
const files = fs18.readdirSync(sessionsDir).filter((f) => f.endsWith(".json"));
|
|
33548
33901
|
return files.map((f) => {
|
|
33549
33902
|
let parsed;
|
|
33550
33903
|
try {
|
|
33551
|
-
parsed = JSON.parse(
|
|
33904
|
+
parsed = JSON.parse(fs18.readFileSync(path40.join(sessionsDir, f), "utf-8"));
|
|
33552
33905
|
} catch (err) {
|
|
33553
33906
|
if (err instanceof SyntaxError) return moveAside(sessionsDir, f, "is not valid JSON", logger);
|
|
33554
33907
|
logger.warn("sessionStore", `failed to read session file ${f}; skipping`, err);
|
|
@@ -33569,7 +33922,7 @@ function listSessions(baseDir, logger = defaultLogger) {
|
|
|
33569
33922
|
function moveAside(sessionsDir, file, reason, logger) {
|
|
33570
33923
|
const aside = `${file}.${Date.now()}.corrupt`;
|
|
33571
33924
|
try {
|
|
33572
|
-
|
|
33925
|
+
fs18.renameSync(path40.join(sessionsDir, file), path40.join(sessionsDir, aside));
|
|
33573
33926
|
logger.warn("sessionStore", `session file ${file} ${reason}; moved aside to ${aside} rather than overwritten`);
|
|
33574
33927
|
} catch {
|
|
33575
33928
|
logger.warn("sessionStore", `failed to read session file ${file}; skipping`);
|
|
@@ -33578,12 +33931,12 @@ function moveAside(sessionsDir, file, reason, logger) {
|
|
|
33578
33931
|
}
|
|
33579
33932
|
var filenameEndings = (sessionId) => [sessionId.replace(/^session-/, ""), sessionId].map((id2) => `_${id2.slice(0, 8)}.json`);
|
|
33580
33933
|
function findSessionFile(sessionsDir, sessionId, logger) {
|
|
33581
|
-
const files =
|
|
33934
|
+
const files = fs18.readdirSync(sessionsDir).filter((f) => f.endsWith(".json"));
|
|
33582
33935
|
const endings = filenameEndings(sessionId);
|
|
33583
33936
|
const named3 = files.filter((f) => endings.some((ending) => f.endsWith(ending)));
|
|
33584
33937
|
for (const file of /* @__PURE__ */ new Set([...named3, ...files])) {
|
|
33585
33938
|
try {
|
|
33586
|
-
const session = JSON.parse(
|
|
33939
|
+
const session = JSON.parse(fs18.readFileSync(path40.join(sessionsDir, file), "utf-8"));
|
|
33587
33940
|
if (session.meta.id === sessionId) return { file, session };
|
|
33588
33941
|
} catch (err) {
|
|
33589
33942
|
logger.warn("sessionStore", `failed to read session file ${file}; skipping`, err);
|
|
@@ -33605,7 +33958,7 @@ function settledOnLoad(session, researchLog, logger) {
|
|
|
33605
33958
|
function loadChildSession(place, logger = defaultLogger) {
|
|
33606
33959
|
let parsed;
|
|
33607
33960
|
try {
|
|
33608
|
-
parsed = JSON.parse(
|
|
33961
|
+
parsed = JSON.parse(fs18.readFileSync(childSessionPath(place), "utf-8"));
|
|
33609
33962
|
} catch (err) {
|
|
33610
33963
|
if (err.code !== "ENOENT") logger.warn("sessionStore", `failed to read child session ${place.sessionId}`, err);
|
|
33611
33964
|
return null;
|
|
@@ -33615,7 +33968,7 @@ function loadChildSession(place, logger = defaultLogger) {
|
|
|
33615
33968
|
}
|
|
33616
33969
|
function loadSession(sessionId, baseDir, logger = defaultLogger) {
|
|
33617
33970
|
const sessionsDir = getSessionsDir(baseDir);
|
|
33618
|
-
if (!
|
|
33971
|
+
if (!fs18.existsSync(sessionsDir)) return null;
|
|
33619
33972
|
try {
|
|
33620
33973
|
const found = findSessionFile(sessionsDir, sessionId, logger);
|
|
33621
33974
|
if (found) {
|
|
@@ -33642,16 +33995,16 @@ function getLatestSession(baseDir, logger = defaultLogger) {
|
|
|
33642
33995
|
}
|
|
33643
33996
|
function deleteSession(sessionId, baseDir, logger = defaultLogger) {
|
|
33644
33997
|
const sessionsDir = getSessionsDir(baseDir);
|
|
33645
|
-
if (!
|
|
33998
|
+
if (!fs18.existsSync(sessionsDir)) return false;
|
|
33646
33999
|
try {
|
|
33647
|
-
|
|
34000
|
+
fs18.rmSync(sessionDataDir(sessionId, baseDir), { recursive: true, force: true });
|
|
33648
34001
|
} catch (err) {
|
|
33649
34002
|
logger.warn("sessionStore", `failed to remove the task logs of ${sessionId}`, err);
|
|
33650
34003
|
}
|
|
33651
34004
|
try {
|
|
33652
34005
|
const found = findSessionFile(sessionsDir, sessionId, logger);
|
|
33653
34006
|
if (found) {
|
|
33654
|
-
|
|
34007
|
+
fs18.unlinkSync(path40.join(sessionsDir, found.file));
|
|
33655
34008
|
return true;
|
|
33656
34009
|
}
|
|
33657
34010
|
} catch (err) {
|
|
@@ -33798,8 +34151,8 @@ var import_uuid6 = require("uuid");
|
|
|
33798
34151
|
|
|
33799
34152
|
// src/services/ContextCollector.ts
|
|
33800
34153
|
var ORDEWELL_CONTEXT_MAX = 8e3;
|
|
33801
|
-
async function collectResearchContext(
|
|
33802
|
-
const collector = new ContextCollector(
|
|
34154
|
+
async function collectResearchContext(fs29, runners) {
|
|
34155
|
+
const collector = new ContextCollector(fs29);
|
|
33803
34156
|
let contextStr = "";
|
|
33804
34157
|
let firstContext = null;
|
|
33805
34158
|
for (const r of runners) {
|
|
@@ -33826,8 +34179,8 @@ ${firstContext.dirStructure}
|
|
|
33826
34179
|
return contextStr;
|
|
33827
34180
|
}
|
|
33828
34181
|
var ContextCollector = class {
|
|
33829
|
-
constructor(
|
|
33830
|
-
this.fs =
|
|
34182
|
+
constructor(fs29, registry) {
|
|
34183
|
+
this.fs = fs29;
|
|
33831
34184
|
this.registry = registry;
|
|
33832
34185
|
}
|
|
33833
34186
|
fs;
|
|
@@ -33875,28 +34228,29 @@ var ALLOWED_TOOL_NAMES = new Set(subagentToolSpecs().map((t) => t.name));
|
|
|
33875
34228
|
function refused3(output) {
|
|
33876
34229
|
return { success: false, output, truncated: false };
|
|
33877
34230
|
}
|
|
33878
|
-
function nonPromptingFs(
|
|
33879
|
-
const withinWorkspace = (p) => resolveWithin(
|
|
34231
|
+
function nonPromptingFs(fs29) {
|
|
34232
|
+
const withinWorkspace = (p) => resolveWithin(fs29.getWorkspaceRoot(), p ?? ".").inside;
|
|
33880
34233
|
const outsideRefusal = (p) => refused3(
|
|
33881
34234
|
`Path "${p}" is outside the workspace. Research agents are confined to the workspace root \u2014 note the gap in your digest and let the planner request it directly.`
|
|
33882
34235
|
);
|
|
33883
34236
|
return {
|
|
33884
|
-
getWorkspaceRoot: () =>
|
|
33885
|
-
readFile: (p, opts) => withinWorkspace(p) ?
|
|
34237
|
+
getWorkspaceRoot: () => fs29.getWorkspaceRoot(),
|
|
34238
|
+
readFile: (p, opts) => withinWorkspace(p) ? fs29.readFile(p, opts) : Promise.resolve(outsideRefusal(p)),
|
|
33886
34239
|
readFiles: (paths) => {
|
|
33887
34240
|
const escaping = paths.find((p) => !withinWorkspace(p));
|
|
33888
|
-
return escaping ? Promise.resolve(outsideRefusal(escaping)) :
|
|
34241
|
+
return escaping ? Promise.resolve(outsideRefusal(escaping)) : fs29.readFiles(paths);
|
|
33889
34242
|
},
|
|
33890
|
-
glob: (pattern, opts) => withinWorkspace(opts?.path) ?
|
|
33891
|
-
grep: (pattern, opts) => withinWorkspace(opts?.path) ?
|
|
33892
|
-
findSymbol: (symbol, opts) => withinWorkspace(opts?.path) ?
|
|
33893
|
-
listDir: (p, depth) => withinWorkspace(p) ?
|
|
34243
|
+
glob: (pattern, opts) => withinWorkspace(opts?.path) ? fs29.glob(pattern, opts) : Promise.resolve(outsideRefusal(opts.path)),
|
|
34244
|
+
grep: (pattern, opts) => withinWorkspace(opts?.path) ? fs29.grep(pattern, opts) : Promise.resolve(outsideRefusal(opts.path)),
|
|
34245
|
+
findSymbol: (symbol, opts) => withinWorkspace(opts?.path) ? fs29.findSymbol(symbol, opts) : Promise.resolve(outsideRefusal(opts.path)),
|
|
34246
|
+
listDir: (p, depth) => withinWorkspace(p) ? fs29.listDir(p, depth) : Promise.resolve(outsideRefusal(p)),
|
|
33894
34247
|
bash: async (command, signal, opts) => {
|
|
33895
|
-
const
|
|
34248
|
+
const shell = resolveResearchShell();
|
|
34249
|
+
const policy = researchPolicyOptions(shell);
|
|
33896
34250
|
const { tier, reason } = classifyCommand(command, policy);
|
|
33897
|
-
const escaping = pathRefs(command, policy).map((ref2) => resolveRef(
|
|
33898
|
-
if (tier === "auto" && !escaping && !opts?.sealed) return
|
|
33899
|
-
if (opts?.sealed || await
|
|
34251
|
+
const escaping = pathRefs(command, policy).map((ref2) => resolveRef(fs29.getWorkspaceRoot(), ref2, shell.hostPath)).find((r) => !r.inside);
|
|
34252
|
+
if (tier === "auto" && !escaping && !opts?.sealed) return fs29.bash(command, signal);
|
|
34253
|
+
if (opts?.sealed || await fs29.canSeal?.()) return fs29.bash(command, signal, { sealed: true });
|
|
33900
34254
|
if (tier === "refuse") return refused3(`Command refused: ${reason}`);
|
|
33901
34255
|
if (tier === "auto" && escaping) return outsideRefusal(escaping.abs);
|
|
33902
34256
|
return refused3(`"${command}" needs user approval, and research agents run in the background where nothing can be approved. Use the read-only research tools, and note in your digest that this command would answer the question.`);
|
|
@@ -33908,7 +34262,7 @@ function withoutContext({ contextTokens: _context, ...record }) {
|
|
|
33908
34262
|
}
|
|
33909
34263
|
async function runLoop(prompt, deps) {
|
|
33910
34264
|
if (deps.signal?.aborted) return "[research agent aborted before starting]";
|
|
33911
|
-
const
|
|
34265
|
+
const fs29 = nonPromptingFs(deps.fs);
|
|
33912
34266
|
const chat = deps.createChat(
|
|
33913
34267
|
(delta) => deps.onProgress?.({ type: "thinking", text: delta, subagentId: deps.subagentId }),
|
|
33914
34268
|
// The record says who made the call: unstamped, the ledger would read the
|
|
@@ -33931,7 +34285,7 @@ ${turn.text}`;
|
|
|
33931
34285
|
if (tc.name === "read_file" && !("maxBytes" in args) && !("limit" in args)) args.limit = 2e3;
|
|
33932
34286
|
const toolArgs = JSON.stringify(tc.args);
|
|
33933
34287
|
deps.onProgress?.({ type: "tool_call", tool: tc.name, toolArgs, toolCallId: tc.id, subagentId: deps.subagentId });
|
|
33934
|
-
const res = await executeTool(tc.name, args,
|
|
34288
|
+
const res = await executeTool(tc.name, args, fs29, deps.fetcher, deps.signal);
|
|
33935
34289
|
const output = res.output.length > SUBAGENT_LIMITS.toolOutputMaxChars ? res.output.slice(0, SUBAGENT_LIMITS.toolOutputMaxChars) + `
|
|
33936
34290
|
[... truncated to ${SUBAGENT_LIMITS.toolOutputMaxChars} chars, total ${res.output.length}]` : res.output;
|
|
33937
34291
|
const stepEntry = {
|
|
@@ -34139,7 +34493,7 @@ var BaseAiService = class _BaseAiService {
|
|
|
34139
34493
|
* steering/failed result and the loop continues sequentially: a subagent can
|
|
34140
34494
|
* never fail a plan or a turn.
|
|
34141
34495
|
*/
|
|
34142
|
-
async executeSpawnAgent(args,
|
|
34496
|
+
async executeSpawnAgent(args, fs29, onProgress, signal, subagentId, fetcher) {
|
|
34143
34497
|
const prompt = typeof args.prompt === "string" ? args.prompt.trim() : "";
|
|
34144
34498
|
if (!prompt) {
|
|
34145
34499
|
return { success: false, output: 'spawn_research_agent requires a non-empty "prompt" string: a self-contained task for the agent, including what its digest must report back.', truncated: false };
|
|
@@ -34151,7 +34505,7 @@ var BaseAiService = class _BaseAiService {
|
|
|
34151
34505
|
if (!chat) throw new Error("subagent chats are not available for this provider");
|
|
34152
34506
|
return chat;
|
|
34153
34507
|
},
|
|
34154
|
-
fs:
|
|
34508
|
+
fs: fs29,
|
|
34155
34509
|
signal,
|
|
34156
34510
|
subagentId,
|
|
34157
34511
|
// The subagent gets web tools only behind a non-prompting gate: no
|
|
@@ -34167,14 +34521,14 @@ var BaseAiService = class _BaseAiService {
|
|
|
34167
34521
|
});
|
|
34168
34522
|
}
|
|
34169
34523
|
/** Collect project context for the planning phase. Shared with the harness backend. */
|
|
34170
|
-
static async collectResearchContext(
|
|
34171
|
-
return collectResearchContext(
|
|
34524
|
+
static async collectResearchContext(fs29, runners) {
|
|
34525
|
+
return collectResearchContext(fs29, runners);
|
|
34172
34526
|
}
|
|
34173
34527
|
/**
|
|
34174
34528
|
* Execute one round of tool calls and report each through onProgress.
|
|
34175
34529
|
* Returns the results to feed back plus the log entries produced.
|
|
34176
34530
|
*/
|
|
34177
|
-
async executeToolCalls(toolCalls,
|
|
34531
|
+
async executeToolCalls(toolCalls, fs29, onProgress, fetcher, stepIndex, thinking, signal, plannerTools) {
|
|
34178
34532
|
const toolResults = [];
|
|
34179
34533
|
const logEntries = [];
|
|
34180
34534
|
let resultsText = "";
|
|
@@ -34195,12 +34549,12 @@ var BaseAiService = class _BaseAiService {
|
|
|
34195
34549
|
spawnSubagentIds.set(i, subagentId);
|
|
34196
34550
|
announcedAt.set(i, (/* @__PURE__ */ new Date()).toISOString());
|
|
34197
34551
|
onProgress({ type: "tool_call", tool: toolCalls[i].name, toolArgs: JSON.stringify(toolCalls[i].args), subagentId, toolCallId: toolCalls[i].id });
|
|
34198
|
-
precomputed.set(i, await this.executeSpawnAgent({ ...toolCalls[i].args },
|
|
34552
|
+
precomputed.set(i, await this.executeSpawnAgent({ ...toolCalls[i].args }, fs29, onProgress, signal, subagentId, fetcher));
|
|
34199
34553
|
}) : Promise.resolve(),
|
|
34200
34554
|
parallelIndexes.length > 1 ? mapWithConcurrency(parallelIndexes, TOOL_ROUND_CONCURRENCY, async (i) => {
|
|
34201
34555
|
announcedAt.set(i, (/* @__PURE__ */ new Date()).toISOString());
|
|
34202
34556
|
onProgress({ type: "tool_call", tool: toolCalls[i].name, toolArgs: JSON.stringify(toolCalls[i].args), toolCallId: toolCalls[i].id });
|
|
34203
|
-
precomputed.set(i, await executeTool(toolCalls[i].name, normalizedArgs[i],
|
|
34557
|
+
precomputed.set(i, await executeTool(toolCalls[i].name, normalizedArgs[i], fs29, fetcher, signal));
|
|
34204
34558
|
}) : Promise.resolve()
|
|
34205
34559
|
]);
|
|
34206
34560
|
for (const [index, tc] of toolCalls.entries()) {
|
|
@@ -34211,7 +34565,7 @@ var BaseAiService = class _BaseAiService {
|
|
|
34211
34565
|
announcedAt.set(index, (/* @__PURE__ */ new Date()).toISOString());
|
|
34212
34566
|
onProgress({ type: "tool_call", ...named3, toolArgs: JSON.stringify(tc.args), toolCallId: tc.id });
|
|
34213
34567
|
}
|
|
34214
|
-
const toolResult = preResult ?? await callPlannerTool(plannerTools, tc.name, toolArgs, signal) ?? await executeTool(tc.name, toolArgs,
|
|
34568
|
+
const toolResult = preResult ?? await callPlannerTool(plannerTools, tc.name, toolArgs, signal) ?? await executeTool(tc.name, toolArgs, fs29, fetcher, signal);
|
|
34215
34569
|
const MAX_RESPONSE_CHARS = 5e4;
|
|
34216
34570
|
const truncatedResponse = toolResult.success && (toolResult.truncated || toolResult.output.length > MAX_RESPONSE_CHARS);
|
|
34217
34571
|
const llmOutput = toolResult.output.length > MAX_RESPONSE_CHARS ? toolResult.output.slice(0, MAX_RESPONSE_CHARS) + `
|
|
@@ -34384,7 +34738,7 @@ ${llmOutput}
|
|
|
34384
34738
|
* parsed tasks if a plan was emitted mid-loop, or null if the loop
|
|
34385
34739
|
* exhausted without a valid plan.
|
|
34386
34740
|
*/
|
|
34387
|
-
async runResearchLoop(chat, firstMessage,
|
|
34741
|
+
async runResearchLoop(chat, firstMessage, fs29, onProgress, runners, initialLog, fetcher, userGoal, runnerModes, autonomousDefault, signal) {
|
|
34388
34742
|
const researchLog = initialLog ? [...initialLog] : [];
|
|
34389
34743
|
if (!initialLog && userGoal) {
|
|
34390
34744
|
researchLog.push({
|
|
@@ -34410,7 +34764,7 @@ ${llmOutput}
|
|
|
34410
34764
|
if (!turn.hasToolCalls) break;
|
|
34411
34765
|
const { toolResults, logEntries, resultsText } = await this.executeToolCalls(
|
|
34412
34766
|
turn.toolCalls,
|
|
34413
|
-
|
|
34767
|
+
fs29,
|
|
34414
34768
|
onProgress,
|
|
34415
34769
|
fetcher,
|
|
34416
34770
|
step,
|
|
@@ -34454,18 +34808,18 @@ var import_uuid8 = require("uuid");
|
|
|
34454
34808
|
var import_generative_ai2 = require("@google/generative-ai");
|
|
34455
34809
|
|
|
34456
34810
|
// src/services/runnerAuth.ts
|
|
34457
|
-
var
|
|
34458
|
-
var
|
|
34811
|
+
var import_child_process12 = require("child_process");
|
|
34812
|
+
var import_path6 = require("path");
|
|
34459
34813
|
var AUTH_TIMEOUT_MS = 8e3;
|
|
34460
|
-
var defaultExec3 = (command, args, options) => new Promise((
|
|
34814
|
+
var defaultExec3 = (command, args, options) => new Promise((resolve18) => {
|
|
34461
34815
|
let settled = false;
|
|
34462
34816
|
const settle = (result) => {
|
|
34463
34817
|
if (settled) return;
|
|
34464
34818
|
settled = true;
|
|
34465
34819
|
clearTimeout(timer);
|
|
34466
|
-
|
|
34820
|
+
resolve18(result);
|
|
34467
34821
|
};
|
|
34468
|
-
const child = (0,
|
|
34822
|
+
const child = (0, import_child_process12.execFile)(command, args, { timeout: options.timeout, env: options.env, encoding: "utf8", windowsVerbatimArguments: options.verbatim }, (err, stdout, stderr) => {
|
|
34469
34823
|
const raw = err?.code;
|
|
34470
34824
|
const code = err ? typeof raw === "number" ? raw : -1 : 0;
|
|
34471
34825
|
settle({ code, stdout: String(stdout ?? ""), stderr: String(stderr ?? "") });
|
|
@@ -34490,9 +34844,11 @@ async function readRunnerAuth(manifest, options = {}) {
|
|
|
34490
34844
|
let env;
|
|
34491
34845
|
try {
|
|
34492
34846
|
env = withPath(process.env, await augmentedPath(), options.env ?? {});
|
|
34493
|
-
|
|
34847
|
+
const launch = await planDirectLaunch(command, spec.statusArgs, options.launch);
|
|
34848
|
+
answer2 = await (options.exec ?? defaultExec3)(launch.file, launch.args, {
|
|
34494
34849
|
timeout: options.timeoutMs ?? AUTH_TIMEOUT_MS,
|
|
34495
|
-
env
|
|
34850
|
+
env,
|
|
34851
|
+
...launch.verbatim ? { verbatim: true } : {}
|
|
34496
34852
|
});
|
|
34497
34853
|
} catch {
|
|
34498
34854
|
return { state: "unknown", loginCommand };
|
|
@@ -34543,7 +34899,7 @@ function verdictFromExit(spec, output, code) {
|
|
|
34543
34899
|
}
|
|
34544
34900
|
var recorded2 = /* @__PURE__ */ new Map();
|
|
34545
34901
|
function recordKey(runner, workspace) {
|
|
34546
|
-
return workspace ? `${(0,
|
|
34902
|
+
return workspace ? `${(0, import_path6.resolve)(workspace)}\0${runner}` : runner;
|
|
34547
34903
|
}
|
|
34548
34904
|
function recordRunnerAuth(runner, auth, workspace) {
|
|
34549
34905
|
recorded2.set(recordKey(runner, workspace), auth);
|
|
@@ -35575,10 +35931,10 @@ ${repairHint}` }] : parts;
|
|
|
35575
35931
|
}, { signal });
|
|
35576
35932
|
}
|
|
35577
35933
|
// --- IAiService implementation ---
|
|
35578
|
-
async researchAndPlan(userDescription, runners, modelsByRunner,
|
|
35934
|
+
async researchAndPlan(userDescription, runners, modelsByRunner, fs29, onProgress, fetcher, runnerModes, modes = DEFAULT_PLANNER_MODES, signal) {
|
|
35579
35935
|
this.ensureInit();
|
|
35580
35936
|
const { autonomousDefault } = modes;
|
|
35581
|
-
const contextStr = await BaseAiService.collectResearchContext(
|
|
35937
|
+
const contextStr = await BaseAiService.collectResearchContext(fs29, runners);
|
|
35582
35938
|
const systemPrompt = buildResearchPrompt(userDescription, contextStr, modelsByRunner, runners, runnerModes, modes);
|
|
35583
35939
|
const firstMessage = `${buildResearchToolsPrompt(false)}
|
|
35584
35940
|
|
|
@@ -35586,17 +35942,17 @@ Explore the workspace to understand the codebase, then generate the plan.`;
|
|
|
35586
35942
|
const researchChat = this.chat([{ role: "user", content: systemPrompt }], [{ functionDeclarations: TOOL_DEFINITIONS }], {
|
|
35587
35943
|
onUsage: (record) => onProgress({ type: "usage", record })
|
|
35588
35944
|
});
|
|
35589
|
-
const result = await this.runResearchLoop(researchChat, firstMessage,
|
|
35945
|
+
const result = await this.runResearchLoop(researchChat, firstMessage, fs29, onProgress, runners, void 0, fetcher, userDescription, runnerModes, autonomousDefault, signal);
|
|
35590
35946
|
if (result.tasks) return { tasks: result.tasks, researchLog: result.researchLog, researchResults: result.researchResults };
|
|
35591
35947
|
const fallback = await this.generatePlanFallback(userDescription, contextStr, result.researchResults, modelsByRunner, runners, onProgress, result.researchLog, runnerModes, autonomousDefault, signal, modes);
|
|
35592
35948
|
return { tasks: fallback.tasks, researchLog: fallback.researchLog, researchResults: result.researchResults };
|
|
35593
35949
|
}
|
|
35594
|
-
async generatePlanDirect(userDescription, runners = [...DEFAULT_RUNNERS], modelsByRunner = {}, onToken,
|
|
35950
|
+
async generatePlanDirect(userDescription, runners = [...DEFAULT_RUNNERS], modelsByRunner = {}, onToken, fs29, _fetcher, runnerModes, modes = DEFAULT_PLANNER_MODES, signal) {
|
|
35595
35951
|
this.ensureInit();
|
|
35596
35952
|
const { autonomousDefault } = modes;
|
|
35597
35953
|
let ctx = "";
|
|
35598
|
-
if (
|
|
35599
|
-
const collected = await new ContextCollector(
|
|
35954
|
+
if (fs29) {
|
|
35955
|
+
const collected = await new ContextCollector(fs29).collect(runners[0] ?? DEFAULT_RUNNERS[0]);
|
|
35600
35956
|
if (collected.aiflowContext) ctx = `
|
|
35601
35957
|
<aiflow_context>
|
|
35602
35958
|
${collected.aiflowContext}
|
|
@@ -35963,10 +36319,10 @@ ${buildResearchToolsPrompt()}` }
|
|
|
35963
36319
|
}
|
|
35964
36320
|
}
|
|
35965
36321
|
// --- IAiService implementation ---
|
|
35966
|
-
async researchAndPlan(userDescription, runners, modelsByRunner,
|
|
36322
|
+
async researchAndPlan(userDescription, runners, modelsByRunner, fs29, onProgress, fetcher, runnerModes, modes = DEFAULT_PLANNER_MODES, signal) {
|
|
35967
36323
|
this.ensureInit();
|
|
35968
36324
|
const { autonomousDefault } = modes;
|
|
35969
|
-
const contextStr = await BaseAiService.collectResearchContext(
|
|
36325
|
+
const contextStr = await BaseAiService.collectResearchContext(fs29, runners);
|
|
35970
36326
|
const systemPrompt = buildResearchPrompt(userDescription, contextStr, modelsByRunner, runners, runnerModes, modes);
|
|
35971
36327
|
const userText = `User goal: ${userDescription}`;
|
|
35972
36328
|
const firstMessage = `${buildResearchToolsPrompt()}
|
|
@@ -35986,17 +36342,17 @@ ${userText}`;
|
|
|
35986
36342
|
onUsage: (record) => onProgress({ type: "usage", record }),
|
|
35987
36343
|
budget: this.plannerBudget()
|
|
35988
36344
|
});
|
|
35989
|
-
const result = await this.runResearchLoop(researchChat, firstMessage,
|
|
36345
|
+
const result = await this.runResearchLoop(researchChat, firstMessage, fs29, onProgress, runners, void 0, fetcher, userDescription, runnerModes, autonomousDefault, signal);
|
|
35990
36346
|
if (result.tasks) return { tasks: result.tasks, researchLog: result.researchLog, researchResults: result.researchResults };
|
|
35991
36347
|
const fallback = await this.generatePlanFallback(userDescription, contextStr, result.researchResults, modelsByRunner, runners, onProgress, result.researchLog, runnerModes, autonomousDefault, signal, modes);
|
|
35992
36348
|
return { tasks: fallback.tasks, researchLog: fallback.researchLog, researchResults: result.researchResults };
|
|
35993
36349
|
}
|
|
35994
|
-
async generatePlanDirect(userDescription, runners = [...DEFAULT_RUNNERS], modelsByRunner = {}, onToken,
|
|
36350
|
+
async generatePlanDirect(userDescription, runners = [...DEFAULT_RUNNERS], modelsByRunner = {}, onToken, fs29, _fetcher, runnerModes, modes = DEFAULT_PLANNER_MODES, signal) {
|
|
35995
36351
|
this.ensureInit();
|
|
35996
36352
|
const { autonomousDefault } = modes;
|
|
35997
36353
|
let ctx = "";
|
|
35998
|
-
if (
|
|
35999
|
-
const collected = await new ContextCollector(
|
|
36354
|
+
if (fs29) {
|
|
36355
|
+
const collected = await new ContextCollector(fs29).collect(runners[0] ?? DEFAULT_RUNNERS[0]);
|
|
36000
36356
|
if (collected.aiflowContext) ctx = `
|
|
36001
36357
|
<aiflow_context>
|
|
36002
36358
|
${collected.aiflowContext}
|
|
@@ -36874,7 +37230,7 @@ var PlanEditError = class extends Error {
|
|
|
36874
37230
|
};
|
|
36875
37231
|
|
|
36876
37232
|
// src/services/sessionLease.ts
|
|
36877
|
-
var
|
|
37233
|
+
var fs19 = __toESM(require("fs"));
|
|
36878
37234
|
var path41 = __toESM(require("path"));
|
|
36879
37235
|
var import_crypto16 = require("crypto");
|
|
36880
37236
|
var LEASE_HEARTBEAT_MS = 1e4;
|
|
@@ -36943,7 +37299,7 @@ function isRecord9(value) {
|
|
|
36943
37299
|
function readRecord(file) {
|
|
36944
37300
|
let raw;
|
|
36945
37301
|
try {
|
|
36946
|
-
raw =
|
|
37302
|
+
raw = fs19.readFileSync(file, "utf8");
|
|
36947
37303
|
} catch (err) {
|
|
36948
37304
|
if (err.code === "ENOENT") return null;
|
|
36949
37305
|
throw err;
|
|
@@ -37075,9 +37431,9 @@ var LeaseHost = class {
|
|
|
37075
37431
|
if (this.held.size === 0) this.stopHeartbeat();
|
|
37076
37432
|
try {
|
|
37077
37433
|
withFileLock(file, () => {
|
|
37078
|
-
if (readRecord(file)?.hostId === this.id)
|
|
37434
|
+
if (readRecord(file)?.hostId === this.id) fs19.rmSync(file, { force: true });
|
|
37079
37435
|
}, "release a session lease");
|
|
37080
|
-
|
|
37436
|
+
fs19.rmdirSync(path41.dirname(file));
|
|
37081
37437
|
} catch {
|
|
37082
37438
|
}
|
|
37083
37439
|
}
|
|
@@ -37213,8 +37569,9 @@ function preservedNotice(kept) {
|
|
|
37213
37569
|
const owner = first.task ? `Task "${first.task.title}"` : "A leftover task workspace no record accounted for";
|
|
37214
37570
|
return `${owner} had work that never landed, so before its worktree was removed it was kept on branch ${first.branch}${where}. \`git log ${first.branch}\` shows it; merge or cherry-pick it to bring it back, and delete the branch once you no longer need it.`;
|
|
37215
37571
|
}
|
|
37216
|
-
function refusedNotice(worktree, reason, task2) {
|
|
37217
|
-
|
|
37572
|
+
function refusedNotice(worktree, reason, task2, platform = process.platform) {
|
|
37573
|
+
const remove = platform === "win32" ? `remove it with \`rmdir /s /q "${worktree}"\` in a Command Prompt, then \`git worktree prune\`` : `remove it with \`git worktree remove --force ${worktree}\``;
|
|
37574
|
+
return `Left ${task2 ? `the worktree of task "${task2.title}"` : "a leftover worktree"} in place at ${worktree}: it holds work Ordewell could not keep (${reason}). Save what you need from it, then ${remove}.`;
|
|
37218
37575
|
}
|
|
37219
37576
|
function sharedPathsNotice(run) {
|
|
37220
37577
|
if (run.repos.some((r) => r.path === SELF_REPO)) {
|
|
@@ -38594,16 +38951,27 @@ function liveConfig(dir) {
|
|
|
38594
38951
|
const selected = new Set(repositoryRunnerConfigPaths([...found.keys()]));
|
|
38595
38952
|
return new Map([...found].filter(([name]) => selected.has(name)));
|
|
38596
38953
|
}
|
|
38597
|
-
function linkedRoots(dir) {
|
|
38954
|
+
function linkedRoots(dir, checkout) {
|
|
38598
38955
|
const linked = /* @__PURE__ */ new Set();
|
|
38599
38956
|
for (const root of RUNNER_CONFIG_ROOTS) {
|
|
38600
38957
|
try {
|
|
38601
|
-
|
|
38958
|
+
const here = (0, import_fs13.lstatSync)(path42.join(dir, root), { bigint: true });
|
|
38959
|
+
if (here.isSymbolicLink() || here.isFile() && here.nlink > 1n && sameFile(here, (0, import_fs13.statSync)(path42.join(checkout, root), { bigint: true }))) linked.add(root);
|
|
38602
38960
|
} catch {
|
|
38603
38961
|
}
|
|
38604
38962
|
}
|
|
38605
38963
|
return linked;
|
|
38606
38964
|
}
|
|
38965
|
+
function sameFile(a, b) {
|
|
38966
|
+
return a.dev === b.dev && a.ino === b.ino;
|
|
38967
|
+
}
|
|
38968
|
+
function linksTo(link, target) {
|
|
38969
|
+
try {
|
|
38970
|
+
return (0, import_fs13.lstatSync)(link).isSymbolicLink() && realPathOf(link) === realPathOf(target);
|
|
38971
|
+
} catch {
|
|
38972
|
+
return false;
|
|
38973
|
+
}
|
|
38974
|
+
}
|
|
38607
38975
|
function readDirs(root) {
|
|
38608
38976
|
const dirs = [{ dir: root, prefix: "" }];
|
|
38609
38977
|
for (let dir = root, prefix = ""; !(0, import_fs13.existsSync)(path42.join(dir, ".git")); ) {
|
|
@@ -38648,7 +39016,7 @@ var TaskStartConfig = class {
|
|
|
38648
39016
|
*/
|
|
38649
39017
|
worktreeDifferences(id2, dir, root) {
|
|
38650
39018
|
const now = liveConfig(dir);
|
|
38651
|
-
const linked = linkedRoots(dir);
|
|
39019
|
+
const linked = linkedRoots(dir, root);
|
|
38652
39020
|
const fromCheckout2 = (name) => linked.has(name.split("/")[0]);
|
|
38653
39021
|
const key = `${id2}:worktree:${dir}`;
|
|
38654
39022
|
let local = this.live.get(key);
|
|
@@ -38677,10 +39045,14 @@ var TaskStartConfig = class {
|
|
|
38677
39045
|
if (!cwd || !repo.baseRef || !(0, import_fs13.existsSync)(cwd)) continue;
|
|
38678
39046
|
const prefix = repo.path === "." ? (await tryGit(invoker, repo.root, ["rev-parse", "--show-prefix"])).stdout.trim() : "";
|
|
38679
39047
|
const roots = [...RUNNER_CONFIG_ROOTS, ...prefix ? RUNNER_CONFIG_ROOTS.map((r) => `${prefix}${r}`) : []];
|
|
39048
|
+
const top = path42.resolve(repo.root, ...prefix.split("/").filter(Boolean).map(() => ".."));
|
|
39049
|
+
const runnerRoots = prefix ? roots.filter((root) => root.startsWith(prefix)) : roots;
|
|
39050
|
+
const linked = runnerRoots.filter((root) => linksTo(path42.join(cwd, root), path42.join(top, root))).map((root) => `${root}/`);
|
|
38680
39051
|
const diff = await tryGit(invoker, cwd, ["diff", "--no-ext-diff", "--no-textconv", "--no-renames", "--name-only", "--diff-filter=ACMRTU", "-z", repo.baseRef, "--"]);
|
|
38681
39052
|
const untracked = await tryGit(invoker, cwd, ["ls-files", "--others", "-z", "--", ...roots]);
|
|
38682
39053
|
if (!diff.ok || !untracked.ok) continue;
|
|
38683
39054
|
for (const name of [...diff.stdout.split("\0"), ...untracked.stdout.split("\0")]) {
|
|
39055
|
+
if (linked.some((root) => name.startsWith(root))) continue;
|
|
38684
39056
|
const here = prefix && name.startsWith(prefix) ? name.slice(prefix.length) : void 0;
|
|
38685
39057
|
if (repositoryRunnerConfigPaths([name]).length || here !== void 0 && repositoryRunnerConfigPaths([here]).length) {
|
|
38686
39058
|
found.push(repo.path === "." ? name : path42.posix.join(repo.path, name));
|
|
@@ -38692,8 +39064,8 @@ var TaskStartConfig = class {
|
|
|
38692
39064
|
};
|
|
38693
39065
|
|
|
38694
39066
|
// src/services/ScriptRunner.ts
|
|
38695
|
-
var
|
|
38696
|
-
var
|
|
39067
|
+
var import_child_process13 = require("child_process");
|
|
39068
|
+
var fs20 = __toESM(require("fs"));
|
|
38697
39069
|
var path43 = __toESM(require("path"));
|
|
38698
39070
|
var import_events2 = require("events");
|
|
38699
39071
|
var import_string_decoder2 = require("string_decoder");
|
|
@@ -38779,8 +39151,8 @@ var ScriptSession = class extends AbstractRunnerSession {
|
|
|
38779
39151
|
/** Aborted to end a sealed step, which has no process of its own here to signal. */
|
|
38780
39152
|
sealedEnd = new AbortController();
|
|
38781
39153
|
markGone;
|
|
38782
|
-
gone = new Promise((
|
|
38783
|
-
this.markGone =
|
|
39154
|
+
gone = new Promise((resolve18) => {
|
|
39155
|
+
this.markGone = resolve18;
|
|
38784
39156
|
});
|
|
38785
39157
|
/** Whoever spawned it attaches its listeners when the spawn resolves, so the body starts a macrotask later. */
|
|
38786
39158
|
begin() {
|
|
@@ -38882,7 +39254,7 @@ var ScriptSession = class extends AbstractRunnerSession {
|
|
|
38882
39254
|
return shell.file === null ? { file: step.script, args: [], shell: true } : { file: shell.file, args: [...shell.args, step.script], shell: false };
|
|
38883
39255
|
}
|
|
38884
39256
|
spawnStep(launch) {
|
|
38885
|
-
return new Promise((
|
|
39257
|
+
return new Promise((resolve18) => {
|
|
38886
39258
|
let settled = false;
|
|
38887
39259
|
const stdout = new import_string_decoder2.StringDecoder("utf8");
|
|
38888
39260
|
const stderr = new import_string_decoder2.StringDecoder("utf8");
|
|
@@ -38894,7 +39266,7 @@ var ScriptSession = class extends AbstractRunnerSession {
|
|
|
38894
39266
|
this.child = null;
|
|
38895
39267
|
this.placed = null;
|
|
38896
39268
|
launch.placed?.ended();
|
|
38897
|
-
|
|
39269
|
+
resolve18(status);
|
|
38898
39270
|
};
|
|
38899
39271
|
this.placed = launch.placed ?? null;
|
|
38900
39272
|
const child = spawnInOwnGroup((detached) => this.setup.spawn(launch.file, launch.args, {
|
|
@@ -38945,7 +39317,7 @@ var ScriptSession = class extends AbstractRunnerSession {
|
|
|
38945
39317
|
openFullOutput() {
|
|
38946
39318
|
const target = this.setup.fullOutput;
|
|
38947
39319
|
if (!target) return;
|
|
38948
|
-
const stream =
|
|
39320
|
+
const stream = fs20.createWriteStream(target.file);
|
|
38949
39321
|
const full = { file: target.file, stream, written: 0, dropped: 0, failed: false };
|
|
38950
39322
|
stream.on("error", (err) => {
|
|
38951
39323
|
if (!full.failed) console.error(`[ScriptSession] could not save the output of ${this.id} to ${target.file}:`, err);
|
|
@@ -38970,12 +39342,12 @@ var ScriptSession = class extends AbstractRunnerSession {
|
|
|
38970
39342
|
if (!full.failed && full.dropped > 0) full.stream.write(`
|
|
38971
39343
|
[Ordewell stopped saving output here: ${full.dropped} more characters were not saved]
|
|
38972
39344
|
`);
|
|
38973
|
-
await new Promise((
|
|
39345
|
+
await new Promise((resolve18) => {
|
|
38974
39346
|
if (full.stream.closed) {
|
|
38975
|
-
|
|
39347
|
+
resolve18();
|
|
38976
39348
|
return;
|
|
38977
39349
|
}
|
|
38978
|
-
full.stream.once("close", () =>
|
|
39350
|
+
full.stream.once("close", () => resolve18());
|
|
38979
39351
|
full.stream.end();
|
|
38980
39352
|
});
|
|
38981
39353
|
return full.failed ? void 0 : { file: full.file, droppedChars: full.dropped };
|
|
@@ -39090,7 +39462,7 @@ var ScriptRunner = class extends AbstractRunner {
|
|
|
39090
39462
|
body,
|
|
39091
39463
|
cwd: opts.cwd,
|
|
39092
39464
|
env: runnerEnv(PATH, opts.env),
|
|
39093
|
-
spawn: this.deps.spawn ?? ((file, args, options) => (0,
|
|
39465
|
+
spawn: this.deps.spawn ?? ((file, args, options) => (0, import_child_process13.spawn)(file, args, options)),
|
|
39094
39466
|
platform,
|
|
39095
39467
|
launch: { ...this.deps.launch, platform, resolvePath },
|
|
39096
39468
|
shell: this.deps.shell ?? (() => resolveResearchShell()),
|
|
@@ -39127,7 +39499,7 @@ function passed(status) {
|
|
|
39127
39499
|
|
|
39128
39500
|
// src/services/PatchCapture.ts
|
|
39129
39501
|
var import_crypto18 = require("crypto");
|
|
39130
|
-
var
|
|
39502
|
+
var fs21 = __toESM(require("fs"));
|
|
39131
39503
|
var os11 = __toESM(require("os"));
|
|
39132
39504
|
var path44 = __toESM(require("path"));
|
|
39133
39505
|
|
|
@@ -39207,9 +39579,9 @@ var Subtree = class _Subtree {
|
|
|
39207
39579
|
at(path53) {
|
|
39208
39580
|
const { here } = this.source;
|
|
39209
39581
|
const absolute = `${ROOT_NODE2}/${path53}`;
|
|
39210
|
-
const
|
|
39582
|
+
const relative20 = `${here}/${path53}`;
|
|
39211
39583
|
const nodes = this.nodes();
|
|
39212
|
-
const found = (absolute !== here && isWithin(absolute, here) ? nodes.find((node) => node.path === absolute) : void 0) ?? nodes.find((node) => node.path ===
|
|
39584
|
+
const found = (absolute !== here && isWithin(absolute, here) ? nodes.find((node) => node.path === absolute) : void 0) ?? nodes.find((node) => node.path === relative20);
|
|
39213
39585
|
return found && this.planOf(found);
|
|
39214
39586
|
}
|
|
39215
39587
|
/** The same as a reference is pinned against it. */
|
|
@@ -39627,17 +39999,17 @@ function linkInPatch(patch) {
|
|
|
39627
39999
|
function readOwn(scratch, name, max) {
|
|
39628
40000
|
let fd;
|
|
39629
40001
|
try {
|
|
39630
|
-
fd =
|
|
40002
|
+
fd = fs21.openSync(path44.join(scratch, name), fs21.constants.O_RDONLY | (fs21.constants.O_NOFOLLOW ?? 0));
|
|
39631
40003
|
} catch (err) {
|
|
39632
40004
|
throw new Refusal(`the capture left no ${name.split(".").pop()} Ordewell could read (${err.code ?? String(err)})`);
|
|
39633
40005
|
}
|
|
39634
40006
|
try {
|
|
39635
|
-
if (!
|
|
40007
|
+
if (!fs21.fstatSync(fd).isFile()) throw new Refusal(`the capture's ${name.split(".").pop()} is not a file`);
|
|
39636
40008
|
const chunks = [];
|
|
39637
40009
|
let total = 0;
|
|
39638
40010
|
for (; ; ) {
|
|
39639
40011
|
const chunk = Buffer.alloc(Math.min(1024 * 1024, max + 1 - total));
|
|
39640
|
-
const read2 =
|
|
40012
|
+
const read2 = fs21.readSync(fd, chunk, 0, chunk.length, null);
|
|
39641
40013
|
if (read2 === 0) break;
|
|
39642
40014
|
total += read2;
|
|
39643
40015
|
chunks.push(chunk.subarray(0, read2));
|
|
@@ -39645,7 +40017,7 @@ function readOwn(scratch, name, max) {
|
|
|
39645
40017
|
}
|
|
39646
40018
|
return Buffer.concat(chunks);
|
|
39647
40019
|
} finally {
|
|
39648
|
-
|
|
40020
|
+
fs21.closeSync(fd);
|
|
39649
40021
|
}
|
|
39650
40022
|
}
|
|
39651
40023
|
function failure(step, outcome) {
|
|
@@ -39683,7 +40055,7 @@ async function captureHeld(runs, opts, signal) {
|
|
|
39683
40055
|
if (clash) return { kind: "refused", reason: clash };
|
|
39684
40056
|
const flags = [...flag("excluded", excluded.map((c) => c.name)), ...flag("dropped", dropped.map((p) => `${p.name} (${byteSize(p.size)})`))];
|
|
39685
40057
|
if (kept.length === 0) return { kind: "empty", reason: "none of the worktree's changes is one a patch carries.", flags };
|
|
39686
|
-
|
|
40058
|
+
fs21.writeFileSync(`${stem}.revert`, revertRecords([...excluded, ...dropped.flatMap((p) => p.changes)]), { flag: "wx", mode: 384 });
|
|
39687
40059
|
const exported = await runs.run(exportScript(stem), worktree);
|
|
39688
40060
|
if (signal?.aborted) return { kind: "refused", reason: "the attempt ended while its changes were being captured." };
|
|
39689
40061
|
if (!exported.success) return { kind: "refused", reason: failure("git could not write or replay the patch", exported) };
|
|
@@ -39709,8 +40081,8 @@ async function captureHeld(runs, opts, signal) {
|
|
|
39709
40081
|
if (err instanceof Refusal) return { kind: "refused", reason: `${err.message}.` };
|
|
39710
40082
|
throw err;
|
|
39711
40083
|
} finally {
|
|
39712
|
-
|
|
39713
|
-
for (const suffix of ["base", "raw", "files", "sizes", "renames", "revert", "kept", "hashes", "patch", "tree", "replayed"])
|
|
40084
|
+
fs21.rmSync(`${stem}.d`, { recursive: true, force: true });
|
|
40085
|
+
for (const suffix of ["base", "raw", "files", "sizes", "renames", "revert", "kept", "hashes", "patch", "tree", "replayed"]) fs21.rmSync(`${stem}.${suffix}`, { force: true });
|
|
39714
40086
|
}
|
|
39715
40087
|
}
|
|
39716
40088
|
async function capturePatch(shell, opts = {}, signal) {
|
|
@@ -39759,7 +40131,7 @@ async function indexEntries(invoker, worktree) {
|
|
|
39759
40131
|
async function trialApply(invoker, worktree, patchFile, scratch) {
|
|
39760
40132
|
const index = path44.resolve(worktree, (await git(invoker, worktree, [...APPLY_GIT, "rev-parse", "--git-path", "index"])).trim());
|
|
39761
40133
|
const copy = path44.join(scratch, "index");
|
|
39762
|
-
|
|
40134
|
+
fs21.copyFileSync(index, copy);
|
|
39763
40135
|
const trial = { ...invoker, exec: (file, args, opts) => invoker.exec(file, args, { ...opts, env: { ...opts.env, GIT_INDEX_FILE: copy } }) };
|
|
39764
40136
|
const tried = await tryGit(trial, worktree, [...APPLY_GIT, "apply", "--cached", "--3way", "--whitespace=nowarn", patchFile]);
|
|
39765
40137
|
return { left: await indexEntries(trial, worktree), ...tried.ok ? {} : { failed: tried.stderr } };
|
|
@@ -39778,7 +40150,7 @@ function gitRefused(lead, stderr) {
|
|
|
39778
40150
|
function onDisk3(worktree, names2) {
|
|
39779
40151
|
return names2.map((name) => {
|
|
39780
40152
|
try {
|
|
39781
|
-
const stat =
|
|
40153
|
+
const stat = fs21.lstatSync(path44.join(worktree, name), { bigint: true, throwIfNoEntry: false });
|
|
39782
40154
|
return stat ? `${stat.mode} ${stat.ino} ${stat.size} ${stat.mtimeNs} ${stat.ctimeNs}` : "none";
|
|
39783
40155
|
} catch (err) {
|
|
39784
40156
|
return err.code ?? "unreadable";
|
|
@@ -39819,12 +40191,12 @@ function leavesWorktree(worktree, names2, linked, held2, left) {
|
|
|
39819
40191
|
return `the patch writes ${name}, under ${at}, a submodule, whose files are another repository's.`;
|
|
39820
40192
|
}
|
|
39821
40193
|
const full = path44.join(worktree, ...parts.slice(0, i));
|
|
39822
|
-
const stat =
|
|
40194
|
+
const stat = fs21.lstatSync(full, { throwIfNoEntry: false });
|
|
39823
40195
|
if (!stat) break;
|
|
39824
40196
|
const last = i === parts.length;
|
|
39825
40197
|
if (stat.isSymbolicLink()) {
|
|
39826
40198
|
if (last && held2.get(at)?.some((entry) => entry.mode === LINK)) break;
|
|
39827
|
-
const target =
|
|
40199
|
+
const target = fs21.readlinkSync(full);
|
|
39828
40200
|
return `the patch writes ${name}, ${last ? `a link to ${target}` : `under ${at}, a link to ${target}`}, so git would write through it, outside your worktree.`;
|
|
39829
40201
|
}
|
|
39830
40202
|
if (last || stat.isDirectory()) continue;
|
|
@@ -39846,10 +40218,10 @@ async function applyPatch(invoker, worktree, patch, saved, opts = {}) {
|
|
|
39846
40218
|
if (link !== void 0) {
|
|
39847
40219
|
return refused5(`the patch holds a link or a submodule (${JSON.stringify(link.slice(0, 80))}), which a saved patch never does, so it is not one that was saved.`);
|
|
39848
40220
|
}
|
|
39849
|
-
const dir =
|
|
40221
|
+
const dir = fs21.mkdtempSync(path44.join(os11.tmpdir(), "ordewell-apply-"));
|
|
39850
40222
|
try {
|
|
39851
40223
|
const toplevel = (await git(invoker, worktree, [...APPLY_GIT, "rev-parse", "--show-toplevel"])).trim();
|
|
39852
|
-
if (
|
|
40224
|
+
if (realPathOf(toplevel) !== realPathOf(worktree)) return refused5(`${worktree} is not the root of a worktree of its own.`);
|
|
39853
40225
|
const head = (await git(invoker, worktree, [...APPLY_GIT, "rev-parse", "--verify", "HEAD^{commit}"])).trim();
|
|
39854
40226
|
if (!(await tryGit(invoker, worktree, [...APPLY_GIT, "cat-file", "-e", `${saved.base}^{commit}`])).ok) {
|
|
39855
40227
|
return refused5(`the commit the patch was taken against (${saved.base.slice(0, 12)}) is not in this repository, so there is nothing to merge it from.`);
|
|
@@ -39857,7 +40229,7 @@ async function applyPatch(invoker, worktree, patch, saved, opts = {}) {
|
|
|
39857
40229
|
const before = await unmergedPaths(invoker, worktree);
|
|
39858
40230
|
if (before.length > 0) return refused5(`your worktree still has unresolved conflicts (${listed(before.slice(0, 10))}${before.length > 10 ? `, +${before.length - 10} more` : ""}). Resolve them and git add them, or undo them, then apply the patch.`);
|
|
39859
40231
|
const file = path44.join(dir, "saved.patch");
|
|
39860
|
-
|
|
40232
|
+
fs21.writeFileSync(file, patch, { flag: "wx", mode: 384 });
|
|
39861
40233
|
const held2 = await indexEntries(invoker, worktree);
|
|
39862
40234
|
const named3 = await pathsNamed(invoker, worktree, file);
|
|
39863
40235
|
const { left, failed: failed2 } = await trialApply(invoker, worktree, file, dir);
|
|
@@ -39889,7 +40261,7 @@ async function applyPatch(invoker, worktree, patch, saved, opts = {}) {
|
|
|
39889
40261
|
} catch (err) {
|
|
39890
40262
|
return refused5(`git could not apply the patch (${err instanceof Error ? err.message : String(err)}).`);
|
|
39891
40263
|
} finally {
|
|
39892
|
-
|
|
40264
|
+
fs21.rmSync(dir, { recursive: true, force: true });
|
|
39893
40265
|
}
|
|
39894
40266
|
}
|
|
39895
40267
|
function resolution(c) {
|
|
@@ -39956,17 +40328,17 @@ async function applySavedPatch(args, site) {
|
|
|
39956
40328
|
|
|
39957
40329
|
// src/services/Board.ts
|
|
39958
40330
|
var import_crypto19 = require("crypto");
|
|
39959
|
-
var
|
|
40331
|
+
var fs22 = __toESM(require("fs"));
|
|
39960
40332
|
var path45 = __toESM(require("path"));
|
|
39961
40333
|
var BLOB_READ_MAX = 16 * 1024 * 1024;
|
|
39962
40334
|
async function workBlob(cwd, file) {
|
|
39963
40335
|
try {
|
|
39964
|
-
const root = await
|
|
39965
|
-
const full = await
|
|
40336
|
+
const root = await fs22.promises.realpath(cwd);
|
|
40337
|
+
const full = await fs22.promises.realpath(path45.join(root, file));
|
|
39966
40338
|
if (!full.startsWith(`${root}${path45.sep}`)) return void 0;
|
|
39967
|
-
const stat = await
|
|
40339
|
+
const stat = await fs22.promises.stat(full);
|
|
39968
40340
|
if (!stat.isFile() || stat.size > BLOB_READ_MAX) return void 0;
|
|
39969
|
-
const bytes = await
|
|
40341
|
+
const bytes = await fs22.promises.readFile(full);
|
|
39970
40342
|
return (0, import_crypto19.createHash)("sha1").update(`blob ${bytes.length}\0`).update(bytes).digest("hex");
|
|
39971
40343
|
} catch {
|
|
39972
40344
|
return void 0;
|
|
@@ -41435,7 +41807,7 @@ function leasedIsolation(isolation, held2) {
|
|
|
41435
41807
|
closeChanges: async () => {
|
|
41436
41808
|
do {
|
|
41437
41809
|
await Promise.all(underWay);
|
|
41438
|
-
await new Promise((
|
|
41810
|
+
await new Promise((resolve18) => setImmediate(resolve18));
|
|
41439
41811
|
} while (underWay.size > 0);
|
|
41440
41812
|
closed = true;
|
|
41441
41813
|
}
|
|
@@ -41676,9 +42048,9 @@ var SlotPool = class {
|
|
|
41676
42048
|
try {
|
|
41677
42049
|
while (this.keptStarts.length > 0 && !this.full) {
|
|
41678
42050
|
const node = this.keptStarts.shift();
|
|
41679
|
-
await new Promise((
|
|
41680
|
-
this.taken =
|
|
41681
|
-
void node.tick().catch(() => void 0).finally(
|
|
42051
|
+
await new Promise((resolve18) => {
|
|
42052
|
+
this.taken = resolve18;
|
|
42053
|
+
void node.tick().catch(() => void 0).finally(resolve18);
|
|
41682
42054
|
});
|
|
41683
42055
|
this.taken = null;
|
|
41684
42056
|
}
|
|
@@ -44577,9 +44949,9 @@ function candidatesOf(models) {
|
|
|
44577
44949
|
}
|
|
44578
44950
|
|
|
44579
44951
|
// src/services/RunnerInstallation.ts
|
|
44580
|
-
var
|
|
44952
|
+
var import_child_process14 = require("child_process");
|
|
44581
44953
|
var import_util5 = require("util");
|
|
44582
|
-
var execAsync4 = (0, import_util5.promisify)(
|
|
44954
|
+
var execAsync4 = (0, import_util5.promisify)(import_child_process14.exec);
|
|
44583
44955
|
var defaultExec4 = async (command, options) => {
|
|
44584
44956
|
const PATH = await augmentedPath();
|
|
44585
44957
|
const { stdout } = await execAsync4(command, { ...options, env: withPath(process.env, PATH) });
|
|
@@ -44599,6 +44971,7 @@ var RunnerInstallation = class {
|
|
|
44599
44971
|
env;
|
|
44600
44972
|
workspace;
|
|
44601
44973
|
authExec;
|
|
44974
|
+
launch;
|
|
44602
44975
|
constructor(registry, execImpl = defaultExec4, now = Date.now, options = {}) {
|
|
44603
44976
|
this.registry = registry;
|
|
44604
44977
|
this.execImpl = execImpl;
|
|
@@ -44606,6 +44979,7 @@ var RunnerInstallation = class {
|
|
|
44606
44979
|
this.env = options.env ?? (async () => ({}));
|
|
44607
44980
|
this.workspace = options.workspace ?? (() => void 0);
|
|
44608
44981
|
this.authExec = options.authExec;
|
|
44982
|
+
this.launch = options.launch ?? {};
|
|
44609
44983
|
}
|
|
44610
44984
|
/** True if the runner's CLI responds to `--version`. Cached per process. */
|
|
44611
44985
|
async isInstalled(runner) {
|
|
@@ -44689,7 +45063,8 @@ var RunnerInstallation = class {
|
|
|
44689
45063
|
try {
|
|
44690
45064
|
return await readRunnerAuth(manifest, {
|
|
44691
45065
|
...this.authExec ? { exec: this.authExec } : {},
|
|
44692
|
-
env: await this.env(workspace)
|
|
45066
|
+
env: await this.env(workspace),
|
|
45067
|
+
launch: this.launch
|
|
44693
45068
|
});
|
|
44694
45069
|
} catch {
|
|
44695
45070
|
return { state: "unknown" };
|
|
@@ -44716,10 +45091,10 @@ var RunnerInstallation = class {
|
|
|
44716
45091
|
* with `isInstalled` there.
|
|
44717
45092
|
*/
|
|
44718
45093
|
async isSpawnable(command) {
|
|
44719
|
-
if (process.platform !== "win32") return true;
|
|
45094
|
+
if ((this.launch.platform ?? process.platform) !== "win32") return true;
|
|
44720
45095
|
try {
|
|
44721
|
-
const plan = await planDirectLaunch(command, []);
|
|
44722
|
-
return plan
|
|
45096
|
+
const plan = await planDirectLaunch(command, [], this.launch);
|
|
45097
|
+
return isExecutableResolved(command, plan, "", this.launch);
|
|
44723
45098
|
} catch {
|
|
44724
45099
|
return false;
|
|
44725
45100
|
}
|
|
@@ -44909,10 +45284,10 @@ var AccountLimitMonitor = class {
|
|
|
44909
45284
|
entry.inFlight = controller;
|
|
44910
45285
|
entry.lastStartedAt = this.now();
|
|
44911
45286
|
let deadline;
|
|
44912
|
-
const abandoned = new Promise((
|
|
45287
|
+
const abandoned = new Promise((resolve18) => {
|
|
44913
45288
|
deadline = setTimeout(() => {
|
|
44914
45289
|
controller.abort();
|
|
44915
|
-
|
|
45290
|
+
resolve18({ kind: "failed" });
|
|
44916
45291
|
}, DEADLINE_MS);
|
|
44917
45292
|
deadline.unref?.();
|
|
44918
45293
|
});
|
|
@@ -45048,7 +45423,7 @@ function freeze(snapshot) {
|
|
|
45048
45423
|
}
|
|
45049
45424
|
|
|
45050
45425
|
// src/services/harness/codexAccountLimits.ts
|
|
45051
|
-
var
|
|
45426
|
+
var import_os3 = require("os");
|
|
45052
45427
|
var DEFAULT_TIMEOUT_MS4 = 2e4;
|
|
45053
45428
|
var METHOD_NOT_FOUND = -32601;
|
|
45054
45429
|
var INVALID_REQUEST = -32600;
|
|
@@ -45076,7 +45451,7 @@ async function readCodexAccountLimits(command, args, options, signal) {
|
|
|
45076
45451
|
let owner;
|
|
45077
45452
|
const root = options.workspaceRoot?.();
|
|
45078
45453
|
const server4 = await openAppServer(command, args, {
|
|
45079
|
-
cwd: (0,
|
|
45454
|
+
cwd: (0, import_os3.tmpdir)(),
|
|
45080
45455
|
deps: { ...root ? { workspaceEnv: () => workspaceEnvOf(root) } : {}, ...options.deps },
|
|
45081
45456
|
onMessage: (message) => {
|
|
45082
45457
|
if (message.method === "account/updated") accountChanged ||= accountRead;
|
|
@@ -45091,9 +45466,9 @@ async function readCodexAccountLimits(command, args, options, signal) {
|
|
|
45091
45466
|
const initialized = await rpc.call("initialize", { clientInfo: APP_SERVER_CLIENT_INFO });
|
|
45092
45467
|
if (!initialized.ok) return failed2();
|
|
45093
45468
|
server4.notify("initialized", {});
|
|
45094
|
-
const account = await new Promise((
|
|
45469
|
+
const account = await new Promise((resolve18) => rpc.send("account/read", { refreshToken: false }, (response) => {
|
|
45095
45470
|
accountRead = true;
|
|
45096
|
-
|
|
45471
|
+
resolve18(response);
|
|
45097
45472
|
}));
|
|
45098
45473
|
if (!account.ok) return account.code === METHOD_NOT_FOUND ? { kind: "unsupported" } : failed2();
|
|
45099
45474
|
const who = codexAccountOwner(account.result);
|
|
@@ -45111,7 +45486,7 @@ async function readCodexAccountLimits(command, args, options, signal) {
|
|
|
45111
45486
|
...followUp ? { followUp: true } : {}
|
|
45112
45487
|
};
|
|
45113
45488
|
})();
|
|
45114
|
-
const cancelled2 = signal.aborted ? Promise.resolve() : new Promise((
|
|
45489
|
+
const cancelled2 = signal.aborted ? Promise.resolve() : new Promise((resolve18) => signal.addEventListener("abort", () => resolve18(), { once: true }));
|
|
45115
45490
|
try {
|
|
45116
45491
|
return await settleWithin(asked, {
|
|
45117
45492
|
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS4,
|
|
@@ -45164,11 +45539,11 @@ function codexWindow(slot, raw) {
|
|
|
45164
45539
|
}
|
|
45165
45540
|
|
|
45166
45541
|
// src/services/harness/claudeAccountLimits.ts
|
|
45167
|
-
var
|
|
45542
|
+
var import_child_process15 = require("child_process");
|
|
45168
45543
|
var import_crypto20 = require("crypto");
|
|
45169
45544
|
var import_fs14 = require("fs");
|
|
45170
|
-
var
|
|
45171
|
-
var
|
|
45545
|
+
var import_os4 = require("os");
|
|
45546
|
+
var import_path7 = require("path");
|
|
45172
45547
|
var DEFAULT_TIMEOUT_MS5 = 2e4;
|
|
45173
45548
|
var INITIALIZE_TIMEOUT_MS2 = 1e4;
|
|
45174
45549
|
var USAGE_TIMEOUT_MS = 1e4;
|
|
@@ -45200,7 +45575,7 @@ function claudeAccountLimitCollector(options) {
|
|
|
45200
45575
|
};
|
|
45201
45576
|
}
|
|
45202
45577
|
async function readClaudeAccountLimits(options, signal) {
|
|
45203
|
-
const cwd = (0, import_fs14.mkdtempSync)((0,
|
|
45578
|
+
const cwd = (0, import_fs14.mkdtempSync)((0, import_path7.join)((0, import_os4.tmpdir)(), "ordewell-claude-limits-"));
|
|
45204
45579
|
const removeCwd = () => {
|
|
45205
45580
|
try {
|
|
45206
45581
|
(0, import_fs14.rmSync)(cwd, { recursive: true, force: true });
|
|
@@ -45209,7 +45584,7 @@ async function readClaudeAccountLimits(options, signal) {
|
|
|
45209
45584
|
};
|
|
45210
45585
|
const root = options.workspaceRoot?.();
|
|
45211
45586
|
const adapter = new ClaudeCodeAdapter({
|
|
45212
|
-
spawn:
|
|
45587
|
+
spawn: import_child_process15.spawn,
|
|
45213
45588
|
fetch: globalThis.fetch,
|
|
45214
45589
|
// Resolved from the workspace, not the probe's empty cwd, which has no environment of its own.
|
|
45215
45590
|
workspaceEnv: root ? () => workspaceEnvOf(root) : async () => ({}),
|
|
@@ -45229,7 +45604,7 @@ async function readClaudeAccountLimits(options, signal) {
|
|
|
45229
45604
|
if (usage.kind === "refused" && UNSUPPORTED_REQUEST.test(usage.error)) return { kind: "unsupported" };
|
|
45230
45605
|
return claudeLimitReading(usage, owner, isRecord11(account) ? text5(account.subscriptionType) : void 0) ?? failed2();
|
|
45231
45606
|
})().catch(failed2);
|
|
45232
|
-
const cancelled2 = signal.aborted ? Promise.resolve() : new Promise((
|
|
45607
|
+
const cancelled2 = signal.aborted ? Promise.resolve() : new Promise((resolve18) => signal.addEventListener("abort", () => resolve18(), { once: true }));
|
|
45233
45608
|
try {
|
|
45234
45609
|
return await settleWithin(asked, {
|
|
45235
45610
|
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS5,
|
|
@@ -45284,13 +45659,13 @@ function isoInstant(value) {
|
|
|
45284
45659
|
}
|
|
45285
45660
|
|
|
45286
45661
|
// src/services/harness/openCodeGoLimits.ts
|
|
45287
|
-
var
|
|
45662
|
+
var import_os6 = require("os");
|
|
45288
45663
|
|
|
45289
45664
|
// src/services/harness/openCodeCredentials.ts
|
|
45290
45665
|
var import_crypto21 = require("crypto");
|
|
45291
45666
|
var import_fs15 = require("fs");
|
|
45292
|
-
var
|
|
45293
|
-
var
|
|
45667
|
+
var import_os5 = require("os");
|
|
45668
|
+
var import_path8 = require("path");
|
|
45294
45669
|
var import_worker_threads = require("worker_threads");
|
|
45295
45670
|
var DEFAULT_TIMEOUT_MS6 = 5e3;
|
|
45296
45671
|
var BUSY_MS = 250;
|
|
@@ -45347,12 +45722,12 @@ parentPort.postMessage(select());
|
|
|
45347
45722
|
var isRecord12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45348
45723
|
var digest = (...parts) => (0, import_crypto21.createHash)("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
|
|
45349
45724
|
function openCodeStorePaths(env, home) {
|
|
45350
|
-
const data = (0,
|
|
45725
|
+
const data = (0, import_path8.join)(env.XDG_DATA_HOME || (0, import_path8.join)(home, ".local", "share"), "opencode");
|
|
45351
45726
|
const file = env.OPENCODE_DB || "opencode.db";
|
|
45352
|
-
return { db: file === ":memory:" ? null : (0,
|
|
45727
|
+
return { db: file === ":memory:" ? null : (0, import_path8.resolve)(data, file), auth: (0, import_path8.join)(data, "auth.json") };
|
|
45353
45728
|
}
|
|
45354
45729
|
function openCodeGoLoginReader(deps = {}) {
|
|
45355
|
-
const homedir11 = deps.homedir ??
|
|
45730
|
+
const homedir11 = deps.homedir ?? import_os5.homedir;
|
|
45356
45731
|
let last;
|
|
45357
45732
|
return {
|
|
45358
45733
|
async read(env, signal) {
|
|
@@ -45501,7 +45876,7 @@ function openCodeGoAccountLimitCollector(options) {
|
|
|
45501
45876
|
label: "OpenCode Go",
|
|
45502
45877
|
provider: "opencode-go",
|
|
45503
45878
|
scope: () => {
|
|
45504
|
-
const paths = openCodeStorePaths(env(), (deps.reader?.homedir ??
|
|
45879
|
+
const paths = openCodeStorePaths(env(), (deps.reader?.homedir ?? import_os6.homedir)());
|
|
45505
45880
|
return ["opencode", paths.db ?? ":memory:", paths.auth].join("\0");
|
|
45506
45881
|
},
|
|
45507
45882
|
acquire: async (signal) => {
|
|
@@ -45657,7 +46032,7 @@ function parseJson2(text6) {
|
|
|
45657
46032
|
}
|
|
45658
46033
|
|
|
45659
46034
|
// src/services/harness/CliAgentAiService.ts
|
|
45660
|
-
var
|
|
46035
|
+
var import_child_process16 = require("child_process");
|
|
45661
46036
|
var import_uuid11 = require("uuid");
|
|
45662
46037
|
|
|
45663
46038
|
// src/services/harness/turnReply.ts
|
|
@@ -45765,7 +46140,7 @@ function nativeShellOffer(input) {
|
|
|
45765
46140
|
if (input.runner === "codex") {
|
|
45766
46141
|
return {
|
|
45767
46142
|
offered: false,
|
|
45768
|
-
reason: "Codex already runs its own shell, read-only and without the network (ADR-0026), so this setting changes nothing for it."
|
|
46143
|
+
reason: platform === "win32" ? "On Windows Codex plans with its own shell off, since its sandbox there cannot keep a command off the network, and runs every command through Ordewell's (ADR-0010)." : "Codex already runs its own shell, read-only and without the network (ADR-0026), so this setting changes nothing for it."
|
|
45769
46144
|
};
|
|
45770
46145
|
}
|
|
45771
46146
|
const checked = CHECKED[input.runner];
|
|
@@ -45886,7 +46261,7 @@ var CliAgentAiService = class {
|
|
|
45886
46261
|
const runner = runnerForProvider(config.aiProvider);
|
|
45887
46262
|
if (!runner) throw new Error(`${config.aiProvider} is not a coding-agent planner.`);
|
|
45888
46263
|
this.runner = runner;
|
|
45889
|
-
const spawn3 = deps.spawn ??
|
|
46264
|
+
const spawn3 = deps.spawn ?? import_child_process16.spawn;
|
|
45890
46265
|
this.processDeps = {
|
|
45891
46266
|
spawn: (command, args, options) => {
|
|
45892
46267
|
const child = spawn3(command, args, options);
|
|
@@ -45925,6 +46300,11 @@ var CliAgentAiService = class {
|
|
|
45925
46300
|
hasActiveConversation() {
|
|
45926
46301
|
return this.session?.start != null;
|
|
45927
46302
|
}
|
|
46303
|
+
/** On Windows, the shell `run_command` runs, which a coding agent there would take for PowerShell (ADR-0010). */
|
|
46304
|
+
researchShell() {
|
|
46305
|
+
if ((this.processDeps.platform ?? process.platform) !== "win32") return void 0;
|
|
46306
|
+
return resolveResearchShell().dialect === "cmd" ? "cmd" : "git-bash";
|
|
46307
|
+
}
|
|
45928
46308
|
/**
|
|
45929
46309
|
* False when the running agent process was spawned under a model/effort the
|
|
45930
46310
|
* user has since changed in the picker. Unlike a vendor backend, the model
|
|
@@ -45986,13 +46366,14 @@ var CliAgentAiService = class {
|
|
|
45986
46366
|
this.session = session;
|
|
45987
46367
|
session.notice = req.notice;
|
|
45988
46368
|
const contextStr = await collectResearchContext(req.fs, req.runners);
|
|
46369
|
+
const researchShell = this.researchShell();
|
|
45989
46370
|
const systemPrompt = buildConversationSystemPrompt(
|
|
45990
46371
|
req.goal,
|
|
45991
46372
|
contextStr,
|
|
45992
46373
|
req.modelsByRunner,
|
|
45993
46374
|
req.runners,
|
|
45994
46375
|
req.runnerModes,
|
|
45995
|
-
{ harness: true, runner: this.runner, isolatedExecution: req.isolatedExecution, skills: req.skills, execution: req.plannerTools !== void 0, autorun: req.autorun, delegation: req.delegation, subplanner: req.subplanner, ...req.plannerTools.noSubagents ? { subagents: false } : {} }
|
|
46376
|
+
{ harness: true, runner: this.runner, isolatedExecution: req.isolatedExecution, skills: req.skills, execution: req.plannerTools !== void 0, autorun: req.autorun, delegation: req.delegation, subplanner: req.subplanner, ...req.plannerTools.noSubagents ? { subagents: false } : {}, ...researchShell ? { researchShell } : {} }
|
|
45996
46377
|
);
|
|
45997
46378
|
const fetcher = req.fetcher;
|
|
45998
46379
|
const cwd = this.workspaceRoot();
|
|
@@ -46579,6 +46960,9 @@ ${corrective}`, catalog, onProgress, signal),
|
|
|
46579
46960
|
};
|
|
46580
46961
|
const tools = {
|
|
46581
46962
|
sessionId: (0, import_uuid11.v4)(),
|
|
46963
|
+
// No session here runs a command, so the planner is not offered one: it
|
|
46964
|
+
// reads with its harness's own tools, and Codex keeps its shell for it.
|
|
46965
|
+
withheld: ["run_command"],
|
|
46582
46966
|
handler: {
|
|
46583
46967
|
listRunners: async () => ({ text: JSON.stringify({ runners: catalog.runners.map((id2) => ({ id: id2, readOnly: readOnlyMode(catalog.runnerModes?.[id2]) !== void 0 })) }) }),
|
|
46584
46968
|
listModels: async ({ runner }) => ({ text: JSON.stringify({ runner, models: catalog.modelsByRunner?.[runner] ?? [] }) }),
|
|
@@ -46633,8 +47017,8 @@ Before submitting, call list_runners and list_models to check the available assi
|
|
|
46633
47017
|
session.discard();
|
|
46634
47018
|
}
|
|
46635
47019
|
}
|
|
46636
|
-
async researchAndPlan(userDescription, runners, modelsByRunner,
|
|
46637
|
-
const contextStr = await collectResearchContext(
|
|
47020
|
+
async researchAndPlan(userDescription, runners, modelsByRunner, fs29, onProgress, _fetcher, runnerModes, modes = DEFAULT_PLANNER_MODES, signal) {
|
|
47021
|
+
const contextStr = await collectResearchContext(fs29, runners);
|
|
46638
47022
|
const prompt = buildPlanWithResults(userDescription, contextStr, "", modelsByRunner, runners, runnerModes, modes, true);
|
|
46639
47023
|
const plan = await this.submittedPlan(prompt, oneShotCatalog(runners, modelsByRunner, runnerModes, modes), onProgress, signal);
|
|
46640
47024
|
return {
|
|
@@ -46675,22 +47059,22 @@ function createAiService(config, deps) {
|
|
|
46675
47059
|
var path50 = __toESM(require("path"));
|
|
46676
47060
|
|
|
46677
47061
|
// src/services/handoffReferences.ts
|
|
46678
|
-
var
|
|
47062
|
+
var fs24 = __toESM(require("fs"));
|
|
46679
47063
|
var path47 = __toESM(require("path"));
|
|
46680
|
-
var
|
|
47064
|
+
var import_child_process17 = require("child_process");
|
|
46681
47065
|
function resolveHandoffReferences(handoff, workspace) {
|
|
46682
47066
|
const checked = /* @__PURE__ */ new Map();
|
|
46683
47067
|
const contained = (candidate) => {
|
|
46684
47068
|
try {
|
|
46685
|
-
const root =
|
|
46686
|
-
const resolved2 =
|
|
46687
|
-
const
|
|
46688
|
-
return
|
|
47069
|
+
const root = fs24.realpathSync(workspace);
|
|
47070
|
+
const resolved2 = fs24.realpathSync(path47.resolve(root, candidate));
|
|
47071
|
+
const relative20 = path47.relative(root, resolved2);
|
|
47072
|
+
return relative20 !== ".." && !relative20.startsWith(`..${path47.sep}`) && !path47.isAbsolute(relative20) ? resolved2 : void 0;
|
|
46689
47073
|
} catch {
|
|
46690
47074
|
return void 0;
|
|
46691
47075
|
}
|
|
46692
47076
|
};
|
|
46693
|
-
const
|
|
47077
|
+
const resolve18 = (ref2) => {
|
|
46694
47078
|
if (ref2.kind !== "file" && ref2.kind !== "commit") return ref2;
|
|
46695
47079
|
const key = JSON.stringify(ref2);
|
|
46696
47080
|
const known = checked.get(key);
|
|
@@ -46700,14 +47084,14 @@ function resolveHandoffReferences(handoff, workspace) {
|
|
|
46700
47084
|
const file = contained(ref2.path);
|
|
46701
47085
|
if (file) {
|
|
46702
47086
|
try {
|
|
46703
|
-
resolved2 =
|
|
47087
|
+
resolved2 = fs24.statSync(file).isFile();
|
|
46704
47088
|
} catch {
|
|
46705
47089
|
}
|
|
46706
47090
|
}
|
|
46707
47091
|
} else if (/^[0-9a-fA-F]{4,64}$/.test(ref2.sha)) {
|
|
46708
47092
|
const repo = contained(ref2.repo ?? ".");
|
|
46709
|
-
if (repo &&
|
|
46710
|
-
const result2 = (0,
|
|
47093
|
+
if (repo && fs24.existsSync(path47.join(repo, ".git"))) {
|
|
47094
|
+
const result2 = (0, import_child_process17.spawnSync)("git", ["--no-optional-locks", "--no-replace-objects", "cat-file", "-t", ref2.sha], {
|
|
46711
47095
|
cwd: repo,
|
|
46712
47096
|
encoding: "utf8",
|
|
46713
47097
|
timeout: 1e3,
|
|
@@ -46723,9 +47107,9 @@ function resolveHandoffReferences(handoff, workspace) {
|
|
|
46723
47107
|
};
|
|
46724
47108
|
return {
|
|
46725
47109
|
...handoff,
|
|
46726
|
-
findings: handoff.findings.map((f) => ({ ...f, ...f.evidence ? { evidence: f.evidence.map(
|
|
47110
|
+
findings: handoff.findings.map((f) => ({ ...f, ...f.evidence ? { evidence: f.evidence.map(resolve18) } : {} })),
|
|
46727
47111
|
// A saved patch is Ordewell's own record, not a claim about a tree (ADR-0050).
|
|
46728
|
-
...handoff.artifacts ? { artifacts: handoff.artifacts.map((a) => a.kind === "patch" ? a :
|
|
47112
|
+
...handoff.artifacts ? { artifacts: handoff.artifacts.map((a) => a.kind === "patch" ? a : resolve18(a)) } : {}
|
|
46729
47113
|
};
|
|
46730
47114
|
}
|
|
46731
47115
|
|
|
@@ -47391,8 +47775,8 @@ var PlanTurns = class {
|
|
|
47391
47775
|
this.pump();
|
|
47392
47776
|
return Promise.resolve(plan);
|
|
47393
47777
|
}
|
|
47394
|
-
const settled = new Promise((
|
|
47395
|
-
this.waiters.set(entry.id, { resolve:
|
|
47778
|
+
const settled = new Promise((resolve18, reject) => {
|
|
47779
|
+
this.waiters.set(entry.id, { resolve: resolve18, reject, signal: input.signal });
|
|
47396
47780
|
});
|
|
47397
47781
|
this.pump();
|
|
47398
47782
|
return settled;
|
|
@@ -48582,8 +48966,8 @@ var ChildPlanSession = class extends AbstractRunnerSession {
|
|
|
48582
48966
|
counts;
|
|
48583
48967
|
stopping = null;
|
|
48584
48968
|
markGone;
|
|
48585
|
-
gone = new Promise((
|
|
48586
|
-
this.markGone =
|
|
48969
|
+
gone = new Promise((resolve18) => {
|
|
48970
|
+
this.markGone = resolve18;
|
|
48587
48971
|
});
|
|
48588
48972
|
/** Whoever spawned it attaches its listeners when the spawn resolves, so the child starts a macrotask later. */
|
|
48589
48973
|
begin() {
|
|
@@ -49525,7 +49909,7 @@ var TreeLedger = class _TreeLedger {
|
|
|
49525
49909
|
};
|
|
49526
49910
|
|
|
49527
49911
|
// src/utils/treeEventLog.ts
|
|
49528
|
-
var
|
|
49912
|
+
var fs25 = __toESM(require("fs"));
|
|
49529
49913
|
var path48 = __toESM(require("path"));
|
|
49530
49914
|
|
|
49531
49915
|
// src/services/eventStore.ts
|
|
@@ -49546,7 +49930,7 @@ function treeEventLogFile(rootSessionId, baseDir) {
|
|
|
49546
49930
|
return path48.join(sessionDataDir(rootSessionId, baseDir), LOG_FILE);
|
|
49547
49931
|
}
|
|
49548
49932
|
function hasTreeEventLog(rootSessionId, baseDir) {
|
|
49549
|
-
return
|
|
49933
|
+
return fs25.existsSync(treeEventLogFile(rootSessionId, baseDir));
|
|
49550
49934
|
}
|
|
49551
49935
|
function batchOf(line) {
|
|
49552
49936
|
try {
|
|
@@ -49559,8 +49943,8 @@ function batchOf(line) {
|
|
|
49559
49943
|
async function* landed2(file) {
|
|
49560
49944
|
let stream;
|
|
49561
49945
|
try {
|
|
49562
|
-
await
|
|
49563
|
-
stream =
|
|
49946
|
+
await fs25.promises.access(file);
|
|
49947
|
+
stream = fs25.createReadStream(file);
|
|
49564
49948
|
} catch (err) {
|
|
49565
49949
|
if (err.code === "ENOENT") return;
|
|
49566
49950
|
throw err;
|
|
@@ -49595,15 +49979,15 @@ function jsonlEventStore(file) {
|
|
|
49595
49979
|
let walked = null;
|
|
49596
49980
|
let doubted = null;
|
|
49597
49981
|
async function open() {
|
|
49598
|
-
await
|
|
49599
|
-
const size = await
|
|
49982
|
+
await fs25.promises.mkdir(path48.dirname(file), { recursive: true });
|
|
49983
|
+
const size = await fs25.promises.stat(file).then(({ size: size2 }) => size2, () => 0);
|
|
49600
49984
|
let found = walked?.end === size ? walked : null;
|
|
49601
49985
|
if (!found) {
|
|
49602
49986
|
found = { end: 0, next: 1 };
|
|
49603
49987
|
for await (const batch of landed2(file)) found = pastBatch(found, batch);
|
|
49604
49988
|
}
|
|
49605
|
-
if (size > found.end) await
|
|
49606
|
-
return { handle: await
|
|
49989
|
+
if (size > found.end) await fs25.promises.truncate(file, found.end);
|
|
49990
|
+
return { handle: await fs25.promises.open(file, "a"), next: found.next };
|
|
49607
49991
|
}
|
|
49608
49992
|
async function write(events) {
|
|
49609
49993
|
writer ??= await open();
|
|
@@ -49999,7 +50383,7 @@ var SessionEventRelay = class {
|
|
|
49999
50383
|
};
|
|
50000
50384
|
|
|
50001
50385
|
// src/utils/taskLogStore.ts
|
|
50002
|
-
var
|
|
50386
|
+
var fs26 = __toESM(require("fs"));
|
|
50003
50387
|
var path49 = __toESM(require("path"));
|
|
50004
50388
|
var EXTENSION = ".jsonl";
|
|
50005
50389
|
function taskDir({ baseDir, sessionId, rootSessionId }, taskId) {
|
|
@@ -50008,7 +50392,7 @@ function taskDir({ baseDir, sessionId, rootSessionId }, taskId) {
|
|
|
50008
50392
|
function listTaskLogAttempts(location, taskId) {
|
|
50009
50393
|
let names2;
|
|
50010
50394
|
try {
|
|
50011
|
-
names2 =
|
|
50395
|
+
names2 = fs26.readdirSync(taskDir(location, taskId));
|
|
50012
50396
|
} catch {
|
|
50013
50397
|
return [];
|
|
50014
50398
|
}
|
|
@@ -50017,13 +50401,13 @@ function listTaskLogAttempts(location, taskId) {
|
|
|
50017
50401
|
function openTaskLog(location, taskId, attempt) {
|
|
50018
50402
|
ensureStateDirIgnored(location.baseDir);
|
|
50019
50403
|
const dir = taskDir(location, taskId);
|
|
50020
|
-
|
|
50404
|
+
fs26.mkdirSync(dir, { recursive: true });
|
|
50021
50405
|
const next = (listTaskLogAttempts(location, taskId).pop() ?? 0) + 1;
|
|
50022
50406
|
let number = attempt !== void 0 && Number.isInteger(attempt) && attempt >= 1 ? attempt : next;
|
|
50023
50407
|
for (; ; ) {
|
|
50024
50408
|
const file = path49.join(dir, `${number}${EXTENSION}`);
|
|
50025
50409
|
try {
|
|
50026
|
-
|
|
50410
|
+
fs26.writeFileSync(file, "", { flag: "wx" });
|
|
50027
50411
|
} catch (err) {
|
|
50028
50412
|
if (err.code === "EEXIST") {
|
|
50029
50413
|
number = Math.max(number + 1, next);
|
|
@@ -50035,7 +50419,7 @@ function openTaskLog(location, taskId, attempt) {
|
|
|
50035
50419
|
attempt: number,
|
|
50036
50420
|
append(events) {
|
|
50037
50421
|
if (events.length === 0) return;
|
|
50038
|
-
|
|
50422
|
+
fs26.appendFileSync(file, events.map((e) => `${JSON.stringify(e)}
|
|
50039
50423
|
`).join(""));
|
|
50040
50424
|
}
|
|
50041
50425
|
};
|
|
@@ -50044,7 +50428,7 @@ function openTaskLog(location, taskId, attempt) {
|
|
|
50044
50428
|
function prepareTaskOutputFile(location, taskId, attempt) {
|
|
50045
50429
|
ensureStateDirIgnored(location.baseDir);
|
|
50046
50430
|
const dir = taskDir(location, taskId);
|
|
50047
|
-
|
|
50431
|
+
fs26.mkdirSync(dir, { recursive: true });
|
|
50048
50432
|
return path49.join(dir, `${attempt}.output.txt`);
|
|
50049
50433
|
}
|
|
50050
50434
|
function taskPatchFile(location, taskId, attempt) {
|
|
@@ -50053,16 +50437,16 @@ function taskPatchFile(location, taskId, attempt) {
|
|
|
50053
50437
|
function saveTaskPatch(location, taskId, attempt, patch) {
|
|
50054
50438
|
ensureStateDirIgnored(location.baseDir);
|
|
50055
50439
|
const file = taskPatchFile(location, taskId, attempt);
|
|
50056
|
-
|
|
50440
|
+
fs26.mkdirSync(path49.dirname(file), { recursive: true });
|
|
50057
50441
|
const partial = `${file}.${process.pid}-${Date.now()}.partial`;
|
|
50058
|
-
|
|
50059
|
-
|
|
50442
|
+
fs26.writeFileSync(partial, patch, { flag: "wx" });
|
|
50443
|
+
fs26.renameSync(partial, file);
|
|
50060
50444
|
return file;
|
|
50061
50445
|
}
|
|
50062
50446
|
function readTaskPatch(location, taskId, attempt) {
|
|
50063
50447
|
if (!Number.isInteger(attempt) || attempt < 1) return void 0;
|
|
50064
50448
|
try {
|
|
50065
|
-
return
|
|
50449
|
+
return fs26.readFileSync(taskPatchFile(location, taskId, attempt));
|
|
50066
50450
|
} catch {
|
|
50067
50451
|
return void 0;
|
|
50068
50452
|
}
|
|
@@ -50074,7 +50458,7 @@ function readTaskLog(location, taskId, attempt) {
|
|
|
50074
50458
|
if (!Number.isInteger(attempt) || attempt < 1) return [];
|
|
50075
50459
|
let raw;
|
|
50076
50460
|
try {
|
|
50077
|
-
raw =
|
|
50461
|
+
raw = fs26.readFileSync(path49.join(taskDir(location, taskId), `${attempt}${EXTENSION}`), "utf-8");
|
|
50078
50462
|
} catch {
|
|
50079
50463
|
return [];
|
|
50080
50464
|
}
|
|
@@ -50299,8 +50683,8 @@ function withTaskRunnerConfig(runner, setting) {
|
|
|
50299
50683
|
// src/services/container/dockerLease.ts
|
|
50300
50684
|
var import_crypto26 = require("crypto");
|
|
50301
50685
|
var import_fs19 = require("fs");
|
|
50302
|
-
var
|
|
50303
|
-
var
|
|
50686
|
+
var import_os9 = require("os");
|
|
50687
|
+
var import_path13 = require("path");
|
|
50304
50688
|
|
|
50305
50689
|
// src/services/container/modelGateway.ts
|
|
50306
50690
|
var import_crypto22 = require("crypto");
|
|
@@ -50351,19 +50735,19 @@ var ModelGateway = class {
|
|
|
50351
50735
|
api;
|
|
50352
50736
|
/** The port it took on this host's loopback. */
|
|
50353
50737
|
listen() {
|
|
50354
|
-
return new Promise((
|
|
50738
|
+
return new Promise((resolve18, reject) => {
|
|
50355
50739
|
this.server.once("error", reject);
|
|
50356
50740
|
this.server.listen(0, "127.0.0.1", () => {
|
|
50357
50741
|
const { port } = this.server.address();
|
|
50358
50742
|
this.host = `127.0.0.1:${port}`;
|
|
50359
|
-
|
|
50743
|
+
resolve18(port);
|
|
50360
50744
|
});
|
|
50361
50745
|
});
|
|
50362
50746
|
}
|
|
50363
50747
|
async close() {
|
|
50364
50748
|
this.server.closeAllConnections();
|
|
50365
|
-
await new Promise((
|
|
50366
|
-
this.server.close(() =>
|
|
50749
|
+
await new Promise((resolve18) => {
|
|
50750
|
+
this.server.close(() => resolve18());
|
|
50367
50751
|
});
|
|
50368
50752
|
}
|
|
50369
50753
|
carries({ headers }) {
|
|
@@ -50473,7 +50857,7 @@ var CredentialBroker = class {
|
|
|
50473
50857
|
|
|
50474
50858
|
// src/services/container/taskWorkspace.ts
|
|
50475
50859
|
var import_crypto23 = require("crypto");
|
|
50476
|
-
var
|
|
50860
|
+
var import_path9 = require("path");
|
|
50477
50861
|
var MIRROR_ROOT = "/mirror";
|
|
50478
50862
|
var TASK_ROOT = "/task";
|
|
50479
50863
|
var WORK_ROOT = `${TASK_ROOT}/work`;
|
|
@@ -50490,8 +50874,8 @@ printf %s "$kept" > ${mark}
|
|
|
50490
50874
|
`;
|
|
50491
50875
|
var SIGN_IN_COPY = `${TASK_ROOT}/login/claude`;
|
|
50492
50876
|
var SIGN_IN_MARK = `${TASK_ROOT}/login/handed`;
|
|
50493
|
-
var repoDir = (repo) => repo.path === SELF_REPO ? WORK_ROOT :
|
|
50494
|
-
var mirrorDir2 = (repo) =>
|
|
50877
|
+
var repoDir = (repo) => repo.path === SELF_REPO ? WORK_ROOT : import_path9.posix.join(WORK_ROOT, repo.path);
|
|
50878
|
+
var mirrorDir2 = (repo) => import_path9.posix.join(MIRROR_ROOT, `${repo.path === SELF_REPO ? "self" : (0, import_crypto23.createHash)("sha256").update(repo.path).digest("hex").slice(0, 16)}.git`);
|
|
50495
50879
|
var exportRef = (attempt) => `refs/ordewell/export/${attempt}`;
|
|
50496
50880
|
var receiveScript = (mirror) => `set -e; [ -d ${mirror} ] || git init -q --bare ${mirror}; cd ${mirror}; git config gc.auto 0; git config gc.pruneExpire never; git config receive.autogc false; exec git receive-pack .`;
|
|
50497
50881
|
var extArgument = (arg) => arg.replace(/%/g, "%%").replace(/ /g, "% ");
|
|
@@ -50636,7 +51020,7 @@ function parseContainerSettings(raw) {
|
|
|
50636
51020
|
}
|
|
50637
51021
|
|
|
50638
51022
|
// src/services/container/containerRunners.ts
|
|
50639
|
-
var
|
|
51023
|
+
var import_path10 = require("path");
|
|
50640
51024
|
var LOGIN_VOLUME = "ordewell-login-claude-code";
|
|
50641
51025
|
var CODEX_LOGIN_VOLUME = "ordewell-login-codex";
|
|
50642
51026
|
var OPENCODE_LOGIN_VOLUME = "ordewell-login-opencode";
|
|
@@ -50689,7 +51073,7 @@ var CONTAINER_RUNNERS = [
|
|
|
50689
51073
|
api: ANTHROPIC_API,
|
|
50690
51074
|
unbrokered: { openai: OPENAI_API },
|
|
50691
51075
|
// The copy is the runner's data directory, which `XDG_DATA_HOME` names the parent of.
|
|
50692
|
-
signIn: { volume: OPENCODE_LOGIN_VOLUME, hosts: OPENCODE_HOSTS, copy: ["sh", "-c", COPY_OPENCODE_SIGN_IN], path: OPENCODE_SIGN_IN_COPY, env: { XDG_DATA_HOME:
|
|
51076
|
+
signIn: { volume: OPENCODE_LOGIN_VOLUME, hosts: OPENCODE_HOSTS, copy: ["sh", "-c", COPY_OPENCODE_SIGN_IN], path: OPENCODE_SIGN_IN_COPY, env: { XDG_DATA_HOME: import_path10.posix.join(TASK_ROOT, "login") } },
|
|
50693
51077
|
args: (launch) => launch.args
|
|
50694
51078
|
}
|
|
50695
51079
|
];
|
|
@@ -50851,8 +51235,8 @@ var describeProblems = (problems) => problems.map(({ message, remedy }) => [mess
|
|
|
50851
51235
|
var import_crypto24 = require("crypto");
|
|
50852
51236
|
var import_fs16 = require("fs");
|
|
50853
51237
|
var import_net2 = require("net");
|
|
50854
|
-
var
|
|
50855
|
-
var
|
|
51238
|
+
var import_os7 = require("os");
|
|
51239
|
+
var import_path11 = require("path");
|
|
50856
51240
|
|
|
50857
51241
|
// src/services/container/guaranteeProbe.ts
|
|
50858
51242
|
var METADATA = "169.254.169.254:80";
|
|
@@ -50990,8 +51374,8 @@ var OUTSIDE = "1.1.1.1:443";
|
|
|
50990
51374
|
var OUTSIDE_NAME = "example.com";
|
|
50991
51375
|
var PROBE_MS = 12e4;
|
|
50992
51376
|
function plantFile() {
|
|
50993
|
-
const dir = (0, import_fs16.mkdtempSync)((0,
|
|
50994
|
-
const file = (0,
|
|
51377
|
+
const dir = (0, import_fs16.mkdtempSync)((0, import_path11.join)((0, import_fs16.realpathSync)((0, import_os7.tmpdir)()), "ordewell-canary-"));
|
|
51378
|
+
const file = (0, import_path11.join)(dir, "canary");
|
|
50995
51379
|
(0, import_fs16.writeFileSync)(file, (0, import_crypto24.randomBytes)(16).toString("hex"));
|
|
50996
51380
|
return { file, remove: () => (0, import_fs16.rmSync)(dir, { recursive: true, force: true }) };
|
|
50997
51381
|
}
|
|
@@ -51001,9 +51385,9 @@ function listenOnLoopback() {
|
|
|
51001
51385
|
hits += 1;
|
|
51002
51386
|
socket.destroy();
|
|
51003
51387
|
});
|
|
51004
|
-
return new Promise((
|
|
51388
|
+
return new Promise((resolve18, reject) => {
|
|
51005
51389
|
server4.once("error", reject);
|
|
51006
|
-
server4.listen(0, "127.0.0.1", () =>
|
|
51390
|
+
server4.listen(0, "127.0.0.1", () => resolve18({ port: server4.address().port, hits: () => hits, close: () => server4.close() }));
|
|
51007
51391
|
});
|
|
51008
51392
|
}
|
|
51009
51393
|
async function withCanaries(use) {
|
|
@@ -51024,7 +51408,7 @@ function networkAsked(route, port) {
|
|
|
51024
51408
|
return { outside, name: OUTSIDE_NAME, proxy: route.proxied ? { refused: [...outside, METADATA] } : null };
|
|
51025
51409
|
}
|
|
51026
51410
|
function probeExpected(settings, mounts) {
|
|
51027
|
-
return { mounts, memoryBytes: settings.memoryBytes, pids: PIDS_LIMIT, hostKernel: `${(0,
|
|
51411
|
+
return { mounts, memoryBytes: settings.memoryBytes, pids: PIDS_LIMIT, hostKernel: `${(0, import_os7.type)()} ${(0, import_os7.release)()}` };
|
|
51028
51412
|
}
|
|
51029
51413
|
function probeFindings(stdout, stderr) {
|
|
51030
51414
|
try {
|
|
@@ -51053,7 +51437,7 @@ async function proveEngine(settings, { cli, egress, labels }) {
|
|
|
51053
51437
|
}
|
|
51054
51438
|
|
|
51055
51439
|
// src/services/container/dockerCli.ts
|
|
51056
|
-
var
|
|
51440
|
+
var import_child_process18 = require("child_process");
|
|
51057
51441
|
var import_fs17 = require("fs");
|
|
51058
51442
|
var CALL_TIMEOUT_MS = 12e4;
|
|
51059
51443
|
var KILLED = 137;
|
|
@@ -51066,8 +51450,8 @@ var SpawnedDockerCli = class {
|
|
|
51066
51450
|
return { ...withPath(cleanEnv(), await this.resolvePath()), ...env };
|
|
51067
51451
|
}
|
|
51068
51452
|
async call(args, { input, env, timeoutMs = CALL_TIMEOUT_MS, stdoutTo } = {}) {
|
|
51069
|
-
const child = (0,
|
|
51070
|
-
return new Promise((
|
|
51453
|
+
const child = (0, import_child_process18.spawn)("docker", [...args], { env: await this.environment(env), stdio: ["pipe", "pipe", "pipe"] });
|
|
51454
|
+
return new Promise((resolve18) => {
|
|
51071
51455
|
let stdout = "";
|
|
51072
51456
|
let stderr = "";
|
|
51073
51457
|
let written = 0;
|
|
@@ -51093,7 +51477,7 @@ var SpawnedDockerCli = class {
|
|
|
51093
51477
|
child.stdin.end(input);
|
|
51094
51478
|
const finish2 = (code) => {
|
|
51095
51479
|
clearTimeout(timer);
|
|
51096
|
-
const done = () =>
|
|
51480
|
+
const done = () => resolve18({ code, stdout, stderr, ...overflowed ? { overflowed: true } : {} });
|
|
51097
51481
|
if (sink) sink.end(done);
|
|
51098
51482
|
else done();
|
|
51099
51483
|
};
|
|
@@ -51105,7 +51489,7 @@ var SpawnedDockerCli = class {
|
|
|
51105
51489
|
});
|
|
51106
51490
|
}
|
|
51107
51491
|
async entry(args) {
|
|
51108
|
-
return (0,
|
|
51492
|
+
return (0, import_child_process18.spawn)("docker", [...args], { env: await this.environment(), stdio: ["pipe", "pipe", "pipe"] });
|
|
51109
51493
|
}
|
|
51110
51494
|
};
|
|
51111
51495
|
|
|
@@ -51198,8 +51582,8 @@ function listening(entry) {
|
|
|
51198
51582
|
entry.stderr?.on("data", (chunk) => {
|
|
51199
51583
|
said2 = (said2 + chunk.toString()).slice(-STDERR_TAIL_CHARS2);
|
|
51200
51584
|
});
|
|
51201
|
-
return new Promise((
|
|
51202
|
-
entry.stdout?.once("data", () =>
|
|
51585
|
+
return new Promise((resolve18, reject) => {
|
|
51586
|
+
entry.stdout?.once("data", () => resolve18());
|
|
51203
51587
|
entry.once("error", reject);
|
|
51204
51588
|
entry.once("close", () => reject(new Error(`The egress sidecar ended before it listened${said2.trim() ? `: ${said2.trim()}` : "."}`)));
|
|
51205
51589
|
});
|
|
@@ -51333,20 +51717,20 @@ send(READY, 0);
|
|
|
51333
51717
|
var LeaseRelay = class {
|
|
51334
51718
|
constructor(entry) {
|
|
51335
51719
|
this.entry = entry;
|
|
51336
|
-
this.ready = new Promise((
|
|
51337
|
-
this.markReady =
|
|
51720
|
+
this.ready = new Promise((resolve18, reject) => {
|
|
51721
|
+
this.markReady = resolve18;
|
|
51338
51722
|
this.failReady = reject;
|
|
51339
51723
|
});
|
|
51340
51724
|
this.ready.catch(() => void 0);
|
|
51341
|
-
this.ended = new Promise((
|
|
51725
|
+
this.ended = new Promise((resolve18) => {
|
|
51342
51726
|
entry.once("close", () => {
|
|
51343
51727
|
this.gone();
|
|
51344
|
-
|
|
51728
|
+
resolve18();
|
|
51345
51729
|
});
|
|
51346
51730
|
entry.once("error", (err) => {
|
|
51347
51731
|
this.stderrTail += err.message;
|
|
51348
51732
|
this.gone();
|
|
51349
|
-
|
|
51733
|
+
resolve18();
|
|
51350
51734
|
});
|
|
51351
51735
|
});
|
|
51352
51736
|
entry.stdin?.on("error", () => void 0);
|
|
@@ -51383,8 +51767,8 @@ var LeaseRelay = class {
|
|
|
51383
51767
|
if (known) return known.listening;
|
|
51384
51768
|
let heard;
|
|
51385
51769
|
let failed2;
|
|
51386
|
-
const listening2 = new Promise((
|
|
51387
|
-
heard =
|
|
51770
|
+
const listening2 = new Promise((resolve18, reject) => {
|
|
51771
|
+
heard = resolve18;
|
|
51388
51772
|
failed2 = reject;
|
|
51389
51773
|
});
|
|
51390
51774
|
this.forwards.set(containerPort, { hostPort, listening: listening2, heard, failed: failed2 });
|
|
@@ -51419,9 +51803,9 @@ var LeaseRelay = class {
|
|
|
51419
51803
|
this.send(CONNECT, conn, port);
|
|
51420
51804
|
});
|
|
51421
51805
|
this.exposed.add(server4);
|
|
51422
|
-
await new Promise((
|
|
51806
|
+
await new Promise((resolve18, reject) => {
|
|
51423
51807
|
server4.once("error", reject);
|
|
51424
|
-
server4.listen(0, "127.0.0.1", () =>
|
|
51808
|
+
server4.listen(0, "127.0.0.1", () => resolve18());
|
|
51425
51809
|
});
|
|
51426
51810
|
return server4.address().port;
|
|
51427
51811
|
}
|
|
@@ -51516,8 +51900,8 @@ async function tryVolume(cli, volume) {
|
|
|
51516
51900
|
const removed = await cli.call(["volume", "rm", "-f", volume]);
|
|
51517
51901
|
if (removed.code === 0) return null;
|
|
51518
51902
|
if (tried === VOLUME_TRIES) return removed.stderr.trim();
|
|
51519
|
-
await new Promise((
|
|
51520
|
-
setTimeout(
|
|
51903
|
+
await new Promise((resolve18) => {
|
|
51904
|
+
setTimeout(resolve18, VOLUME_WAIT_MS);
|
|
51521
51905
|
});
|
|
51522
51906
|
}
|
|
51523
51907
|
}
|
|
@@ -51583,8 +51967,8 @@ async function reclaimContainers(tree, raw, { cli = new SpawnedDockerCli(), tell
|
|
|
51583
51967
|
|
|
51584
51968
|
// src/services/container/pushGate.ts
|
|
51585
51969
|
var import_fs18 = require("fs");
|
|
51586
|
-
var
|
|
51587
|
-
var
|
|
51970
|
+
var import_os8 = require("os");
|
|
51971
|
+
var import_path12 = require("path");
|
|
51588
51972
|
var FSCK = ["-c", "transfer.fsckObjects=true", "-c", "fetch.fsckObjects=true"];
|
|
51589
51973
|
var LANDING_HOOKS = ["pre-commit", "prepare-commit-msg", "commit-msg", "post-commit", "pre-merge-commit", "post-merge", "post-checkout", "post-rewrite", "reference-transaction", "post-index-change"];
|
|
51590
51974
|
var PushRefused = class extends Error {
|
|
@@ -51616,8 +52000,8 @@ async function takeThroughGate(invoker, repo, bundle, { ref: ref2, base }) {
|
|
|
51616
52000
|
async function hooksWritten(invoker, repo, base, snapshot) {
|
|
51617
52001
|
const top = (await git(invoker, repo, ["rev-parse", "--show-toplevel"])).trim();
|
|
51618
52002
|
const path53 = (await git(invoker, repo, ["rev-parse", "--git-path", "hooks"])).trim();
|
|
51619
|
-
const given = (0,
|
|
51620
|
-
const folders = [.../* @__PURE__ */ new Set([given, realOf(given)])].map((dir) => (0,
|
|
52003
|
+
const given = (0, import_path12.resolve)(top, path53);
|
|
52004
|
+
const folders = [.../* @__PURE__ */ new Set([given, realOf(given)])].map((dir) => (0, import_path12.relative)(top, dir).split(import_path12.sep).join("/").toLowerCase()).filter((dir) => dir !== ".." && !dir.startsWith("../") && !(0, import_path12.isAbsolute)(dir));
|
|
51621
52005
|
if (folders.length === 0) return [];
|
|
51622
52006
|
const changed = (await git(invoker, repo, ["diff-tree", "-r", "-z", "--name-only", "--no-renames", base, snapshot])).split("\0").filter(Boolean);
|
|
51623
52007
|
return changed.filter((file) => {
|
|
@@ -51627,20 +52011,20 @@ async function hooksWritten(invoker, repo, base, snapshot) {
|
|
|
51627
52011
|
}
|
|
51628
52012
|
function realOf(path53) {
|
|
51629
52013
|
try {
|
|
51630
|
-
return (
|
|
52014
|
+
return realPathOf(path53);
|
|
51631
52015
|
} catch {
|
|
51632
52016
|
return path53;
|
|
51633
52017
|
}
|
|
51634
52018
|
}
|
|
51635
52019
|
async function checkObjects(invoker, repo, snapshot, base) {
|
|
51636
|
-
const scratch = (0, import_fs18.mkdtempSync)((0,
|
|
52020
|
+
const scratch = (0, import_fs18.mkdtempSync)((0, import_path12.join)((0, import_os8.tmpdir)(), "ordewell-gate-"));
|
|
51637
52021
|
try {
|
|
51638
|
-
const prefix = (0,
|
|
52022
|
+
const prefix = (0, import_path12.join)(scratch, "taken");
|
|
51639
52023
|
const packed = await tryGit(invoker, repo, ["pack-objects", "--revs", "-q", prefix], `${snapshot}
|
|
51640
52024
|
^${base}
|
|
51641
52025
|
`);
|
|
51642
52026
|
if (!packed.ok) throw new PushRefused(`git could not read what it holds (${packed.stderr.trim()})`);
|
|
51643
|
-
const checked = await tryGit(invoker, repo, ["index-pack", "--strict", "-o", (0,
|
|
52027
|
+
const checked = await tryGit(invoker, repo, ["index-pack", "--strict", "-o", (0, import_path12.join)(scratch, "checked.idx"), `${prefix}-${packed.stdout.trim()}.pack`]);
|
|
51644
52028
|
if (!checked.ok) throw new PushRefused(`git would not take it (${checked.stderr.trim()})`);
|
|
51645
52029
|
} finally {
|
|
51646
52030
|
(0, import_fs18.rmSync)(scratch, { recursive: true, force: true });
|
|
@@ -51655,10 +52039,10 @@ async function restoreSnapshot(invoker, worktree, snapshot, linked) {
|
|
|
51655
52039
|
await run("reset", "-q");
|
|
51656
52040
|
}
|
|
51657
52041
|
async function hooksLandingWouldRun(invoker, worktree) {
|
|
51658
|
-
const dir = (0,
|
|
52042
|
+
const dir = (0, import_path12.resolve)(worktree, (await git(invoker, worktree, ["rev-parse", "--git-path", "hooks"])).trim());
|
|
51659
52043
|
return LANDING_HOOKS.filter((hook) => {
|
|
51660
52044
|
try {
|
|
51661
|
-
(0, import_fs18.accessSync)((0,
|
|
52045
|
+
(0, import_fs18.accessSync)((0, import_path12.resolve)(dir, hook), import_fs18.constants.X_OK);
|
|
51662
52046
|
return true;
|
|
51663
52047
|
} catch {
|
|
51664
52048
|
return false;
|
|
@@ -51766,7 +52150,7 @@ var DockerExecutionBackend = class {
|
|
|
51766
52150
|
*/
|
|
51767
52151
|
async preflight(runner, model) {
|
|
51768
52152
|
const setupCommand = this.options.setupCommand?.();
|
|
51769
|
-
const { problems, settings } = await inspectReadiness(this.options.settings, { cli: this.cli, broker: this.broker, agent: runner !== null, ...runner ? { runner } : {}, ...setupCommand ? { setupCommand } : {} });
|
|
52153
|
+
const { problems, settings } = await inspectReadiness(this.options.settings, { cli: this.cli, broker: this.broker, ...this.options.platform ? { platform: this.options.platform } : {}, agent: runner !== null, ...runner ? { runner } : {}, ...setupCommand ? { setupCommand } : {} });
|
|
51770
52154
|
if (!settings) throw new Error(`This session runs tasks in containers, and this task cannot start in one. ${describeProblems(problems)}`);
|
|
51771
52155
|
const refusal4 = runner && settings.login.kind === "broker" ? brokerRefusal(runner, model) : null;
|
|
51772
52156
|
if (refusal4) throw new Error(`This session runs tasks in containers, and this task cannot start in one. ${refusal4}`);
|
|
@@ -51793,7 +52177,7 @@ var DockerExecutionBackend = class {
|
|
|
51793
52177
|
}
|
|
51794
52178
|
async workingDirectory(opened2) {
|
|
51795
52179
|
const { worktree, writable, cwd } = opened2.workspace;
|
|
51796
|
-
return
|
|
52180
|
+
return import_path13.posix.join(WORK_ROOT, worktree ? (0, import_path13.relative)(writable ?? cwd, cwd).split(import_path13.sep).join("/") : await this.checkoutFolder(cwd));
|
|
51797
52181
|
}
|
|
51798
52182
|
async start({ runner, settings, spec, opened: opened2, repos }, signal) {
|
|
51799
52183
|
const taskId = spec.task.id;
|
|
@@ -52030,7 +52414,7 @@ var DockerExecutionBackend = class {
|
|
|
52030
52414
|
const launchNumber = ++box.launches;
|
|
52031
52415
|
const moved = /* @__PURE__ */ new Map();
|
|
52032
52416
|
for (const file of launch.files) {
|
|
52033
|
-
const inside2 = `/tmp/ordewell/${launchNumber}-${(0,
|
|
52417
|
+
const inside2 = `/tmp/ordewell/${launchNumber}-${(0, import_path13.basename)(file)}`;
|
|
52034
52418
|
const wrote = await this.cli.call(["exec", "-i", box.name, "sh", "-c", 'umask 077; mkdir -p /tmp/ordewell; cat > "$0"', inside2], { input: (0, import_fs19.readFileSync)(file) });
|
|
52035
52419
|
if (wrote.code !== 0) throw new Error(`Could not hand the runner its configuration: ${wrote.stderr.trim()}`);
|
|
52036
52420
|
moved.set(file, inside2);
|
|
@@ -52153,10 +52537,10 @@ var DockerExecutionBackend = class {
|
|
|
52153
52537
|
*/
|
|
52154
52538
|
bringBack(box) {
|
|
52155
52539
|
box.bringing ??= (async () => {
|
|
52156
|
-
const dir = (0, import_fs19.mkdtempSync)((0,
|
|
52540
|
+
const dir = (0, import_fs19.mkdtempSync)((0, import_path13.join)((0, import_os9.tmpdir)(), "ordewell-export-"));
|
|
52157
52541
|
try {
|
|
52158
52542
|
const taken = [];
|
|
52159
|
-
for (const repo of box.repos) taken.push({ repo, snapshot: await this.take(box, repo, (0,
|
|
52543
|
+
for (const repo of box.repos) taken.push({ repo, snapshot: await this.take(box, repo, (0, import_path13.join)(dir, `${taken.length}.bundle`)) });
|
|
52160
52544
|
for (const { repo, snapshot } of taken) await restoreSnapshot(this.git, repo.worktree, snapshot, repo.linked);
|
|
52161
52545
|
} catch (err) {
|
|
52162
52546
|
await this.cli.call(["volume", "create", ...this.labels(box.taskId), this.heldVolume(box.taskId)]);
|
|
@@ -55557,12 +55941,12 @@ var Session = class {
|
|
|
55557
55941
|
return !task2 || reportEnded(task2) || task2.status !== "in_progress" && !this.orchestrator.getAttempt(taskId);
|
|
55558
55942
|
};
|
|
55559
55943
|
if (over() || signal?.aborted) return Promise.resolve();
|
|
55560
|
-
return new Promise((
|
|
55944
|
+
return new Promise((resolve18) => {
|
|
55561
55945
|
const done = () => {
|
|
55562
55946
|
clearTimeout(timer);
|
|
55563
55947
|
unsubscribe();
|
|
55564
55948
|
signal?.removeEventListener("abort", done);
|
|
55565
|
-
|
|
55949
|
+
resolve18();
|
|
55566
55950
|
};
|
|
55567
55951
|
const timer = setTimeout(done, ms);
|
|
55568
55952
|
const check2 = () => {
|
|
@@ -56758,7 +57142,7 @@ ${pins.join("\n")}` : goal;
|
|
|
56758
57142
|
slotForTurn(signal) {
|
|
56759
57143
|
if (this.turnRoom()) return null;
|
|
56760
57144
|
if (signal?.aborted) return Promise.reject(new PlannerTurnStoppedError());
|
|
56761
|
-
return new Promise((
|
|
57145
|
+
return new Promise((resolve18, reject) => {
|
|
56762
57146
|
const onAbort = () => {
|
|
56763
57147
|
if (this.openingsWaiting.delete(end)) end(new PlannerTurnStoppedError());
|
|
56764
57148
|
};
|
|
@@ -56774,7 +57158,7 @@ ${pins.join("\n")}` : goal;
|
|
|
56774
57158
|
this.roomWaiter = null;
|
|
56775
57159
|
this.openingsWaiting.delete(end);
|
|
56776
57160
|
signal?.removeEventListener("abort", onAbort);
|
|
56777
|
-
|
|
57161
|
+
resolve18();
|
|
56778
57162
|
return true;
|
|
56779
57163
|
};
|
|
56780
57164
|
});
|
|
@@ -56785,7 +57169,7 @@ ${pins.join("\n")}` : goal;
|
|
|
56785
57169
|
return null;
|
|
56786
57170
|
}
|
|
56787
57171
|
if (signal?.aborted) return Promise.reject(new PlannerTurnStoppedError());
|
|
56788
|
-
return new Promise((
|
|
57172
|
+
return new Promise((resolve18, reject) => {
|
|
56789
57173
|
const onAbort = () => {
|
|
56790
57174
|
if (this.openingsWaiting.delete(end)) end(new PlannerTurnStoppedError());
|
|
56791
57175
|
};
|
|
@@ -56799,7 +57183,7 @@ ${pins.join("\n")}` : goal;
|
|
|
56799
57183
|
if (!this.openingsWaiting.delete(end)) return;
|
|
56800
57184
|
signal?.removeEventListener("abort", onAbort);
|
|
56801
57185
|
this.assertPlannerReady();
|
|
56802
|
-
}).then(
|
|
57186
|
+
}).then(resolve18, reject);
|
|
56803
57187
|
});
|
|
56804
57188
|
}
|
|
56805
57189
|
/**
|
|
@@ -56979,8 +57363,8 @@ ${pins.join("\n")}` : goal;
|
|
|
56979
57363
|
if (!pending) return null;
|
|
56980
57364
|
const held2 = pending.held;
|
|
56981
57365
|
if (!held2) return this.turns.follow(input, forced);
|
|
56982
|
-
return new Promise((
|
|
56983
|
-
held2.push({ input, forced, resolve:
|
|
57366
|
+
return new Promise((resolve18, reject) => {
|
|
57367
|
+
held2.push({ input, forced, resolve: resolve18, reject });
|
|
56984
57368
|
});
|
|
56985
57369
|
}
|
|
56986
57370
|
/**
|
|
@@ -59131,7 +59515,7 @@ function taskLogHeaderView(task2, follow, approvals, attempt) {
|
|
|
59131
59515
|
|
|
59132
59516
|
// src/services/StructuredRunner.ts
|
|
59133
59517
|
var import_events4 = require("events");
|
|
59134
|
-
var
|
|
59518
|
+
var import_child_process19 = require("child_process");
|
|
59135
59519
|
var DEFAULT_INTERRUPT_GRACE_MS = 5e3;
|
|
59136
59520
|
var TOOL_ARG_MAX_CHARS = 120;
|
|
59137
59521
|
var TURN_OPENING_EVENTS = /* @__PURE__ */ new Set(["assistant_text", "assistant_text_delta", "thinking", "thinking_delta", "tool_call"]);
|
|
@@ -59417,8 +59801,8 @@ var StructuredSession = class extends AbstractRunnerSession {
|
|
|
59417
59801
|
if (this.stopping) return this.stopping;
|
|
59418
59802
|
if (this.exited) return Promise.resolve();
|
|
59419
59803
|
let woundDown;
|
|
59420
|
-
this.stopping = new Promise((
|
|
59421
|
-
woundDown =
|
|
59804
|
+
this.stopping = new Promise((resolve18) => {
|
|
59805
|
+
woundDown = resolve18;
|
|
59422
59806
|
});
|
|
59423
59807
|
void this.windDown().catch(() => this.kill()).then(woundDown);
|
|
59424
59808
|
return this.stopping;
|
|
@@ -59447,7 +59831,7 @@ var StructuredSession = class extends AbstractRunnerSession {
|
|
|
59447
59831
|
}
|
|
59448
59832
|
/** Whether `turn` closed within the deadline once interrupted. */
|
|
59449
59833
|
async turnClosed(turn, adapter, deadline) {
|
|
59450
|
-
const closed = new Promise((
|
|
59834
|
+
const closed = new Promise((resolve18) => this.structuredEmitter.once("turnEnd", () => resolve18()));
|
|
59451
59835
|
adapter.interrupt(Math.max(0, deadline - Date.now())).catch(() => false);
|
|
59452
59836
|
return await this.within(closed, deadline) && turn.ended;
|
|
59453
59837
|
}
|
|
@@ -59458,7 +59842,7 @@ var StructuredSession = class extends AbstractRunnerSession {
|
|
|
59458
59842
|
gone() {
|
|
59459
59843
|
const { signal } = this.ended;
|
|
59460
59844
|
if (signal.aborted) return Promise.resolve();
|
|
59461
|
-
return new Promise((
|
|
59845
|
+
return new Promise((resolve18) => signal.addEventListener("abort", () => resolve18(), { once: true }));
|
|
59462
59846
|
}
|
|
59463
59847
|
turnState() {
|
|
59464
59848
|
return this.state;
|
|
@@ -59610,7 +59994,7 @@ var StructuredSession = class extends AbstractRunnerSession {
|
|
|
59610
59994
|
}
|
|
59611
59995
|
async interruptTurn(turn, adapter) {
|
|
59612
59996
|
const grace = this.launch.interruptGraceMs;
|
|
59613
|
-
const ended2 = new Promise((
|
|
59997
|
+
const ended2 = new Promise((resolve18) => this.structuredEmitter.once("turnEnd", () => resolve18()));
|
|
59614
59998
|
const acknowledged = await settleWithin(adapter.interrupt(grace).catch(() => false), { timeoutMs: grace, onTimeout: () => false });
|
|
59615
59999
|
if (acknowledged) {
|
|
59616
60000
|
const settled = await settleWithin(ended2.then(() => true), { timeoutMs: grace, onTimeout: () => false });
|
|
@@ -59927,7 +60311,7 @@ var StructuredRunner = class extends AbstractRunner {
|
|
|
59927
60311
|
const session = new StructuredSession(id2, opts.taskId, {
|
|
59928
60312
|
runner: opts.runner,
|
|
59929
60313
|
deps: {
|
|
59930
|
-
spawn:
|
|
60314
|
+
spawn: import_child_process19.spawn,
|
|
59931
60315
|
fetch: globalThis.fetch,
|
|
59932
60316
|
...this.processDeps,
|
|
59933
60317
|
// Already resolved by the caller (ADR-0016); resolving it again here
|
|
@@ -59982,10 +60366,10 @@ var StructuredRunner = class extends AbstractRunner {
|
|
|
59982
60366
|
};
|
|
59983
60367
|
|
|
59984
60368
|
// src/utils/clipboard.ts
|
|
59985
|
-
var
|
|
60369
|
+
var import_child_process20 = require("child_process");
|
|
59986
60370
|
var defaultHasBin = (bin) => {
|
|
59987
60371
|
try {
|
|
59988
|
-
(0,
|
|
60372
|
+
(0, import_child_process20.execSync)(`${process.platform === "win32" ? "where" : "which"} ${bin}`, { stdio: "ignore" });
|
|
59989
60373
|
return true;
|
|
59990
60374
|
} catch {
|
|
59991
60375
|
return false;
|
|
@@ -60042,11 +60426,11 @@ var RunnerRegistry = class {
|
|
|
60042
60426
|
};
|
|
60043
60427
|
|
|
60044
60428
|
// src/plugins/removedPluginNotice.ts
|
|
60045
|
-
var
|
|
60429
|
+
var fs27 = __toESM(require("fs"));
|
|
60046
60430
|
var path51 = __toESM(require("path"));
|
|
60047
60431
|
function isManifestFile(file) {
|
|
60048
60432
|
try {
|
|
60049
|
-
return
|
|
60433
|
+
return fs27.statSync(file).isFile();
|
|
60050
60434
|
} catch {
|
|
60051
60435
|
return false;
|
|
60052
60436
|
}
|
|
@@ -60054,7 +60438,7 @@ function isManifestFile(file) {
|
|
|
60054
60438
|
function removedPluginNotice(dataDir = globalDataDir()) {
|
|
60055
60439
|
const directory = path51.join(dataDir, "plugins");
|
|
60056
60440
|
try {
|
|
60057
|
-
const hasManifest = isManifestFile(path51.join(directory, "manifest.json")) ||
|
|
60441
|
+
const hasManifest = isManifestFile(path51.join(directory, "manifest.json")) || fs27.readdirSync(directory, { withFileTypes: true }).some(
|
|
60058
60442
|
(entry) => (entry.isDirectory() || entry.isSymbolicLink()) && isManifestFile(path51.join(directory, entry.name, "manifest.json"))
|
|
60059
60443
|
);
|
|
60060
60444
|
if (hasManifest) return "Plugin runners were removed; manifests in ~/.ordewell/plugins/ are ignored. See the CHANGELOG.";
|
|
@@ -60065,7 +60449,7 @@ function removedPluginNotice(dataDir = globalDataDir()) {
|
|
|
60065
60449
|
}
|
|
60066
60450
|
|
|
60067
60451
|
// src/utils/stateStore.ts
|
|
60068
|
-
var
|
|
60452
|
+
var fs28 = __toESM(require("fs"));
|
|
60069
60453
|
var path52 = __toESM(require("path"));
|
|
60070
60454
|
var STATE_FILE2 = "state.json";
|
|
60071
60455
|
function getStatePath(baseDir) {
|
|
@@ -60083,9 +60467,9 @@ function saveState(plan, baseDir, sessionId) {
|
|
|
60083
60467
|
function loadState(baseDir, logger = defaultLogger) {
|
|
60084
60468
|
const dir = baseDir ?? process.cwd();
|
|
60085
60469
|
const statePath = getStatePath(dir);
|
|
60086
|
-
if (!
|
|
60470
|
+
if (!fs28.existsSync(statePath)) return null;
|
|
60087
60471
|
try {
|
|
60088
|
-
const raw =
|
|
60472
|
+
const raw = fs28.readFileSync(statePath, "utf-8");
|
|
60089
60473
|
const parsed = JSON.parse(raw);
|
|
60090
60474
|
if (!Array.isArray(parsed.runners)) {
|
|
60091
60475
|
logger.warn("stateStore", `rejecting state from ${statePath}: old format (scalar "runner" instead of "runners" array). Please re-plan.`);
|
|
@@ -60109,11 +60493,11 @@ function loadState(baseDir, logger = defaultLogger) {
|
|
|
60109
60493
|
function clearState(baseDir) {
|
|
60110
60494
|
const dir = baseDir ?? process.cwd();
|
|
60111
60495
|
const statePath = getStatePath(dir);
|
|
60112
|
-
if (
|
|
60496
|
+
if (fs28.existsSync(statePath)) fs28.unlinkSync(statePath);
|
|
60113
60497
|
}
|
|
60114
60498
|
function stateExists(baseDir) {
|
|
60115
60499
|
const dir = baseDir ?? process.cwd();
|
|
60116
|
-
return
|
|
60500
|
+
return fs28.existsSync(getStatePath(dir));
|
|
60117
60501
|
}
|
|
60118
60502
|
|
|
60119
60503
|
// src/services/selectPlanner.ts
|