@workit-dev/codex 2.22.0 → 2.22.2
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/.codex-plugin/plugin.json +1 -1
- package/bin/workit-paths.mjs +33 -1
- package/dist/launch-mcp.js +907 -631
- package/dist/{workit-hook-z09frbdk.js → workit-hook-0qpa9aa6.js} +5 -1
- package/dist/{workit-hook-52cm7mqd.js → workit-hook-2j7nwxvz.js} +3 -3
- package/dist/{workit-hook-sdmcdyrk.js → workit-hook-a7qmf2t8.js} +3 -3
- package/dist/{workit-hook-azjr1ew1.js → workit-hook-agyvx03a.js} +1 -1
- package/dist/{workit-hook-8nhm9sqf.js → workit-hook-at93rw3g.js} +933 -662
- package/dist/{workit-hook-ta5skes6.js → workit-hook-c490e5mm.js} +2 -2
- package/dist/{workit-hook-vmvv43m0.js → workit-hook-dv9s0sjq.js} +2 -2
- package/dist/{workit-hook-btkg30rw.js → workit-hook-mer435q8.js} +1 -1
- package/dist/{workit-hook-xdv92sjp.js → workit-hook-p972vv1e.js} +1 -1
- package/dist/{workit-hook-7jv519ep.js → workit-hook-sxyjantk.js} +14 -2
- package/dist/{workit-hook-x482fqpj.js → workit-hook-v0nvtq6s.js} +1 -1
- package/dist/{workit-hook-7dwf87hc.js → workit-hook-v7vytjn0.js} +4 -3
- package/dist/{workit-hook-dzfxvq92.js → workit-hook-yqe1kfrp.js} +2 -2
- package/dist/workit-hook.js +9 -9
- package/package.json +3 -3
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
configDir2,
|
|
4
4
|
stateDir3,
|
|
5
|
+
folderSlug2,
|
|
6
|
+
folderStoreDir2,
|
|
5
7
|
migrateLegacyDirs2
|
|
6
|
-
} from "./workit-hook-
|
|
8
|
+
} from "./workit-hook-sxyjantk.js";
|
|
7
9
|
import {
|
|
8
10
|
gitDirs,
|
|
9
11
|
withinCall,
|
|
@@ -16,7 +18,7 @@ import {
|
|
|
16
18
|
checkCommand,
|
|
17
19
|
lightCommand,
|
|
18
20
|
maybeHeavy2
|
|
19
|
-
} from "./workit-hook-
|
|
21
|
+
} from "./workit-hook-v0nvtq6s.js";
|
|
20
22
|
import {
|
|
21
23
|
gitStoreDir2,
|
|
22
24
|
standingSeenFile2,
|
|
@@ -26,13 +28,13 @@ import {
|
|
|
26
28
|
} from "./workit-hook-jy7y0gdx.js";
|
|
27
29
|
import {
|
|
28
30
|
takeProcNotice2
|
|
29
|
-
} from "./workit-hook-
|
|
31
|
+
} from "./workit-hook-mer435q8.js";
|
|
30
32
|
import {
|
|
31
33
|
locateWorkitCli2
|
|
32
|
-
} from "./workit-hook-
|
|
34
|
+
} from "./workit-hook-agyvx03a.js";
|
|
33
35
|
import {
|
|
34
36
|
recordHookRun2
|
|
35
|
-
} from "./workit-hook-
|
|
37
|
+
} from "./workit-hook-p972vv1e.js";
|
|
36
38
|
import {
|
|
37
39
|
budgetHooks2
|
|
38
40
|
} from "./workit-hook-b8nrcfzr.js";
|
|
@@ -62,8 +64,8 @@ var capabilitiesFor = (descriptor, observed = {}) => descriptor.capabilities.map
|
|
|
62
64
|
});
|
|
63
65
|
// packages/workit-core/src/hooks/context.ts
|
|
64
66
|
import { createHash as createHash11 } from "node:crypto";
|
|
65
|
-
import
|
|
66
|
-
import
|
|
67
|
+
import fs15 from "node:fs";
|
|
68
|
+
import path20 from "node:path";
|
|
67
69
|
|
|
68
70
|
// packages/workit-core/src/core/branch.ts
|
|
69
71
|
import { createHash as createHash4 } from "node:crypto";
|
|
@@ -9317,8 +9319,288 @@ ${table}` : bootstrap;
|
|
|
9317
9319
|
// packages/workit-core/src/store/paths.ts
|
|
9318
9320
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
9319
9321
|
import { createHash as createHash6 } from "node:crypto";
|
|
9322
|
+
import fs5 from "node:fs";
|
|
9323
|
+
import path9 from "node:path";
|
|
9324
|
+
|
|
9325
|
+
// packages/workit-core/src/store/folder-store.ts
|
|
9320
9326
|
import fs4 from "node:fs";
|
|
9327
|
+
import os4 from "node:os";
|
|
9321
9328
|
import path8 from "node:path";
|
|
9329
|
+
var FOLDER_CONFIG = new Set(["checks.json", "risk-paths"]);
|
|
9330
|
+
var MOVED_POINTER = "MOVED-TO-STATE.txt";
|
|
9331
|
+
var V2_LEFTOVERS = new Set(["recovery", "index.json"]);
|
|
9332
|
+
var isV2TaskStub = (rel) => /^tasks[/\\][^/\\]+\.json$/u.test(rel);
|
|
9333
|
+
var MARKER = "workspace.json";
|
|
9334
|
+
var v2Workspace = (workit) => {
|
|
9335
|
+
let bytes;
|
|
9336
|
+
try {
|
|
9337
|
+
bytes = fs4.readFileSync(path8.join(workit, MARKER), "utf8");
|
|
9338
|
+
} catch {
|
|
9339
|
+
return null;
|
|
9340
|
+
}
|
|
9341
|
+
try {
|
|
9342
|
+
const value = JSON.parse(bytes);
|
|
9343
|
+
return value?.store?.format !== "workit-store";
|
|
9344
|
+
} catch {
|
|
9345
|
+
return true;
|
|
9346
|
+
}
|
|
9347
|
+
};
|
|
9348
|
+
var generatedIgnore = (file) => {
|
|
9349
|
+
try {
|
|
9350
|
+
return /^\*\n(!risk-paths\n)?$/u.test(fs4.readFileSync(file, "utf8"));
|
|
9351
|
+
} catch {
|
|
9352
|
+
return false;
|
|
9353
|
+
}
|
|
9354
|
+
};
|
|
9355
|
+
var exists = (file) => {
|
|
9356
|
+
try {
|
|
9357
|
+
fs4.lstatSync(file);
|
|
9358
|
+
return true;
|
|
9359
|
+
} catch {
|
|
9360
|
+
return false;
|
|
9361
|
+
}
|
|
9362
|
+
};
|
|
9363
|
+
var isDir = (file) => {
|
|
9364
|
+
try {
|
|
9365
|
+
return fs4.lstatSync(file).isDirectory();
|
|
9366
|
+
} catch {
|
|
9367
|
+
return false;
|
|
9368
|
+
}
|
|
9369
|
+
};
|
|
9370
|
+
var onlyStubs = (tasks) => {
|
|
9371
|
+
try {
|
|
9372
|
+
return fs4.readdirSync(tasks).every((entry) => isV2TaskStub(`tasks/${entry}`));
|
|
9373
|
+
} catch {
|
|
9374
|
+
return false;
|
|
9375
|
+
}
|
|
9376
|
+
};
|
|
9377
|
+
var strayEntries = (workit) => {
|
|
9378
|
+
if (!isDir(workit))
|
|
9379
|
+
return [];
|
|
9380
|
+
let names;
|
|
9381
|
+
try {
|
|
9382
|
+
names = fs4.readdirSync(workit);
|
|
9383
|
+
} catch {
|
|
9384
|
+
return [];
|
|
9385
|
+
}
|
|
9386
|
+
return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path8.join(workit, name))) && !(name === "tasks" && onlyStubs(path8.join(workit, name))));
|
|
9387
|
+
};
|
|
9388
|
+
var folderStoreIo = {
|
|
9389
|
+
rename: (from, to) => fs4.renameSync(from, to),
|
|
9390
|
+
copyFile: (from, to) => fs4.copyFileSync(from, to, fs4.constants.COPYFILE_EXCL)
|
|
9391
|
+
};
|
|
9392
|
+
var tempSeq = 0;
|
|
9393
|
+
var tempBeside = (file) => path8.join(path8.dirname(file), `.${path8.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
|
|
9394
|
+
var copyInto = (from, to) => {
|
|
9395
|
+
const stat = fs4.lstatSync(from);
|
|
9396
|
+
if (stat.isDirectory()) {
|
|
9397
|
+
fs4.mkdirSync(to, { recursive: true });
|
|
9398
|
+
for (const name of fs4.readdirSync(from))
|
|
9399
|
+
copyInto(path8.join(from, name), path8.join(to, name));
|
|
9400
|
+
return;
|
|
9401
|
+
}
|
|
9402
|
+
if (exists(to))
|
|
9403
|
+
throw new Error(`${to} appeared during the move`);
|
|
9404
|
+
const temp = tempBeside(to);
|
|
9405
|
+
try {
|
|
9406
|
+
if (stat.isSymbolicLink())
|
|
9407
|
+
fs4.symlinkSync(fs4.readlinkSync(from), temp);
|
|
9408
|
+
else
|
|
9409
|
+
folderStoreIo.copyFile(from, temp);
|
|
9410
|
+
folderStoreIo.rename(temp, to);
|
|
9411
|
+
} catch (error) {
|
|
9412
|
+
fs4.rmSync(temp, { force: true });
|
|
9413
|
+
throw error;
|
|
9414
|
+
}
|
|
9415
|
+
};
|
|
9416
|
+
var sameFile = (left, right) => {
|
|
9417
|
+
try {
|
|
9418
|
+
const [a, b] = [fs4.lstatSync(left), fs4.lstatSync(right)];
|
|
9419
|
+
if (!a.isFile() || !b.isFile() || a.size !== b.size)
|
|
9420
|
+
return false;
|
|
9421
|
+
return fs4.readFileSync(left).equals(fs4.readFileSync(right));
|
|
9422
|
+
} catch {
|
|
9423
|
+
return false;
|
|
9424
|
+
}
|
|
9425
|
+
};
|
|
9426
|
+
var merge2 = (from, to, rel, moved) => {
|
|
9427
|
+
if (isV2TaskStub(rel))
|
|
9428
|
+
return [];
|
|
9429
|
+
if (!exists(to)) {
|
|
9430
|
+
try {
|
|
9431
|
+
folderStoreIo.rename(from, to);
|
|
9432
|
+
} catch {
|
|
9433
|
+
try {
|
|
9434
|
+
copyInto(from, to);
|
|
9435
|
+
fs4.rmSync(from, { recursive: true, force: true });
|
|
9436
|
+
} catch {
|
|
9437
|
+
return exists(from) ? [rel] : [];
|
|
9438
|
+
}
|
|
9439
|
+
}
|
|
9440
|
+
moved.push(rel);
|
|
9441
|
+
return [];
|
|
9442
|
+
}
|
|
9443
|
+
if (sameFile(from, to)) {
|
|
9444
|
+
fs4.rmSync(from, { force: true });
|
|
9445
|
+
moved.push(rel);
|
|
9446
|
+
return [];
|
|
9447
|
+
}
|
|
9448
|
+
if (!isDir(from) || !isDir(to))
|
|
9449
|
+
return [rel];
|
|
9450
|
+
const kept = fs4.readdirSync(from).flatMap((name) => merge2(path8.join(from, name), path8.join(to, name), `${rel}/${name}`, moved));
|
|
9451
|
+
try {
|
|
9452
|
+
if (fs4.readdirSync(from).length === 0)
|
|
9453
|
+
fs4.rmdirSync(from);
|
|
9454
|
+
} catch {}
|
|
9455
|
+
return kept;
|
|
9456
|
+
};
|
|
9457
|
+
var LOCK_STALE_MS = 1e4;
|
|
9458
|
+
var LOCK_WAIT_MS = 250;
|
|
9459
|
+
var pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
9460
|
+
var staleLock = (lock) => {
|
|
9461
|
+
try {
|
|
9462
|
+
const stat = fs4.statSync(lock);
|
|
9463
|
+
if (Date.now() - stat.mtimeMs > LOCK_STALE_MS)
|
|
9464
|
+
return true;
|
|
9465
|
+
const pid = Number(fs4.readFileSync(lock, "utf8").trim());
|
|
9466
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
9467
|
+
return false;
|
|
9468
|
+
try {
|
|
9469
|
+
process.kill(pid, 0);
|
|
9470
|
+
return false;
|
|
9471
|
+
} catch (error) {
|
|
9472
|
+
return error.code === "ESRCH";
|
|
9473
|
+
}
|
|
9474
|
+
} catch {
|
|
9475
|
+
return false;
|
|
9476
|
+
}
|
|
9477
|
+
};
|
|
9478
|
+
var takeMoveLock = (target) => {
|
|
9479
|
+
const lock = `${target}.lock`;
|
|
9480
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
9481
|
+
for (;; ) {
|
|
9482
|
+
try {
|
|
9483
|
+
const fd = fs4.openSync(lock, "wx", 384);
|
|
9484
|
+
fs4.writeSync(fd, `${process.pid}
|
|
9485
|
+
`);
|
|
9486
|
+
fs4.closeSync(fd);
|
|
9487
|
+
return () => fs4.rmSync(lock, { force: true });
|
|
9488
|
+
} catch (error) {
|
|
9489
|
+
if (error.code !== "EEXIST")
|
|
9490
|
+
return null;
|
|
9491
|
+
}
|
|
9492
|
+
if (staleLock(lock)) {
|
|
9493
|
+
fs4.rmSync(lock, { force: true });
|
|
9494
|
+
continue;
|
|
9495
|
+
}
|
|
9496
|
+
if (Date.now() >= deadline)
|
|
9497
|
+
return null;
|
|
9498
|
+
pause(25);
|
|
9499
|
+
}
|
|
9500
|
+
};
|
|
9501
|
+
var canonical2 = (dir) => {
|
|
9502
|
+
try {
|
|
9503
|
+
return fs4.realpathSync.native(dir);
|
|
9504
|
+
} catch {
|
|
9505
|
+
return path8.resolve(dir);
|
|
9506
|
+
}
|
|
9507
|
+
};
|
|
9508
|
+
var below = (parent, child) => {
|
|
9509
|
+
const rel = path8.relative(parent, child);
|
|
9510
|
+
return rel !== "" && !rel.startsWith("..") && !path8.isAbsolute(rel);
|
|
9511
|
+
};
|
|
9512
|
+
var TEST_RUN_REFUSALS = "folder-store-refusals.log";
|
|
9513
|
+
var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os4.tmpdir()) => {
|
|
9514
|
+
if (env.WORKIT_TEST_RUN === undefined || !hasStray)
|
|
9515
|
+
return null;
|
|
9516
|
+
const real = canonical2(folder);
|
|
9517
|
+
const tmp = canonical2(tempDir);
|
|
9518
|
+
if (below(tmp, real))
|
|
9519
|
+
return null;
|
|
9520
|
+
return `workit test run (WORKIT_TEST_RUN): refusing to move ${path8.join(real, ".workit")} into the run's throwaway state dir; a test must work in a fresh dir inside ${tmp}, never the temp dir itself, a parent of it or a folder outside it (#892)`;
|
|
9521
|
+
};
|
|
9522
|
+
function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
|
|
9523
|
+
`)) {
|
|
9524
|
+
const workit = path8.join(folder, ".workit");
|
|
9525
|
+
const names = strayEntries(workit);
|
|
9526
|
+
const refusal = testRunFolderRefusal(folder, names.length > 0);
|
|
9527
|
+
if (refusal) {
|
|
9528
|
+
const run = process.env.WORKIT_TEST_RUN ?? "";
|
|
9529
|
+
if (path8.isAbsolute(run))
|
|
9530
|
+
try {
|
|
9531
|
+
fs4.appendFileSync(path8.join(run, TEST_RUN_REFUSALS), `${refusal}
|
|
9532
|
+
`);
|
|
9533
|
+
} catch {}
|
|
9534
|
+
throw new Error(refusal);
|
|
9535
|
+
}
|
|
9536
|
+
if (names.length === 0 || v2Workspace(workit) === true)
|
|
9537
|
+
return null;
|
|
9538
|
+
try {
|
|
9539
|
+
fs4.mkdirSync(path8.dirname(target), { recursive: true });
|
|
9540
|
+
} catch {
|
|
9541
|
+
return null;
|
|
9542
|
+
}
|
|
9543
|
+
const release = takeMoveLock(target);
|
|
9544
|
+
if (!release)
|
|
9545
|
+
return null;
|
|
9546
|
+
try {
|
|
9547
|
+
return moveLocked(workit, target, note);
|
|
9548
|
+
} finally {
|
|
9549
|
+
release();
|
|
9550
|
+
}
|
|
9551
|
+
}
|
|
9552
|
+
function moveLocked(workit, target, note) {
|
|
9553
|
+
const names = strayEntries(workit);
|
|
9554
|
+
if (names.length === 0 || v2Workspace(workit) === true)
|
|
9555
|
+
return null;
|
|
9556
|
+
try {
|
|
9557
|
+
fs4.mkdirSync(target, { recursive: true });
|
|
9558
|
+
} catch {
|
|
9559
|
+
return null;
|
|
9560
|
+
}
|
|
9561
|
+
const result = { from: workit, to: target, moved: [], kept: [] };
|
|
9562
|
+
for (const name of names) {
|
|
9563
|
+
result.kept.push(...merge2(path8.join(workit, name), path8.join(target, name), name, result.moved));
|
|
9564
|
+
}
|
|
9565
|
+
const left = (() => {
|
|
9566
|
+
try {
|
|
9567
|
+
return fs4.readdirSync(workit);
|
|
9568
|
+
} catch {
|
|
9569
|
+
return [];
|
|
9570
|
+
}
|
|
9571
|
+
})();
|
|
9572
|
+
const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path8.join(workit, name)));
|
|
9573
|
+
if (!v2Left && result.kept.length === 0) {
|
|
9574
|
+
fs4.rmSync(path8.join(workit, MARKER), { force: true });
|
|
9575
|
+
if (generatedIgnore(path8.join(workit, ".gitignore")))
|
|
9576
|
+
fs4.rmSync(path8.join(workit, ".gitignore"), { force: true });
|
|
9577
|
+
}
|
|
9578
|
+
const pointer = path8.join(workit, MOVED_POINTER);
|
|
9579
|
+
let wrote = false;
|
|
9580
|
+
if (result.kept.length > 0) {
|
|
9581
|
+
const text = `Workit keeps this folder's state in ${target}.
|
|
9582
|
+
Not moved, because the store there already has them or the move failed: ${result.kept.join(", ")}.
|
|
9583
|
+
Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
|
|
9584
|
+
`;
|
|
9585
|
+
try {
|
|
9586
|
+
if (!exists(pointer) || fs4.readFileSync(pointer, "utf8") !== text) {
|
|
9587
|
+
fs4.writeFileSync(pointer, text);
|
|
9588
|
+
wrote = true;
|
|
9589
|
+
}
|
|
9590
|
+
} catch {}
|
|
9591
|
+
} else {
|
|
9592
|
+
fs4.rmSync(pointer, { force: true });
|
|
9593
|
+
try {
|
|
9594
|
+
if (fs4.readdirSync(workit).length === 0)
|
|
9595
|
+
fs4.rmdirSync(workit);
|
|
9596
|
+
} catch {}
|
|
9597
|
+
}
|
|
9598
|
+
if (result.moved.length > 0 || wrote)
|
|
9599
|
+
note(result.kept.length > 0 ? `workit: moved ${workit} to ${target}; ${result.kept.length} path${result.kept.length === 1 ? "" : "s"} left in place, see ${pointer}` : `workit: moved ${workit} to ${target} (outside a git repository Workit keeps its state there)`);
|
|
9600
|
+
return result;
|
|
9601
|
+
}
|
|
9602
|
+
|
|
9603
|
+
// packages/workit-core/src/store/paths.ts
|
|
9322
9604
|
var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
|
|
9323
9605
|
var gitRun = (cwd, args) => {
|
|
9324
9606
|
const run = spawnSync7("git", args, {
|
|
@@ -9346,7 +9628,7 @@ var gitRun = (cwd, args) => {
|
|
|
9346
9628
|
var shortHash = (value) => createHash6("sha256").update(value).digest("hex").slice(0, 12);
|
|
9347
9629
|
var real = (file) => {
|
|
9348
9630
|
try {
|
|
9349
|
-
return
|
|
9631
|
+
return fs5.realpathSync.native(file);
|
|
9350
9632
|
} catch {
|
|
9351
9633
|
return file;
|
|
9352
9634
|
}
|
|
@@ -9360,14 +9642,14 @@ var DISCOVERY_ENV = [
|
|
|
9360
9642
|
];
|
|
9361
9643
|
var isGitDir = (dir) => {
|
|
9362
9644
|
try {
|
|
9363
|
-
return
|
|
9645
|
+
return fs5.statSync(path9.join(dir, "HEAD")).isFile() && fs5.statSync(path9.join(dir, "objects")).isDirectory() && fs5.statSync(path9.join(dir, "refs")).isDirectory();
|
|
9364
9646
|
} catch {
|
|
9365
9647
|
return false;
|
|
9366
9648
|
}
|
|
9367
9649
|
};
|
|
9368
9650
|
var reftableRefs = (common) => {
|
|
9369
9651
|
try {
|
|
9370
|
-
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(
|
|
9652
|
+
return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs5.readFileSync(path9.join(common, "config"), "utf8"));
|
|
9371
9653
|
} catch {
|
|
9372
9654
|
return false;
|
|
9373
9655
|
}
|
|
@@ -9380,17 +9662,17 @@ function fastGit(root) {
|
|
|
9380
9662
|
for (;; ) {
|
|
9381
9663
|
let stat;
|
|
9382
9664
|
try {
|
|
9383
|
-
stat =
|
|
9665
|
+
stat = fs5.statSync(dir);
|
|
9384
9666
|
} catch {
|
|
9385
9667
|
return null;
|
|
9386
9668
|
}
|
|
9387
9669
|
if (device !== null && stat.dev !== device)
|
|
9388
9670
|
return { kind: "none" };
|
|
9389
9671
|
device = stat.dev;
|
|
9390
|
-
const dotGit =
|
|
9672
|
+
const dotGit = path9.join(dir, ".git");
|
|
9391
9673
|
let entry = null;
|
|
9392
9674
|
try {
|
|
9393
|
-
entry =
|
|
9675
|
+
entry = fs5.statSync(dotGit);
|
|
9394
9676
|
} catch {}
|
|
9395
9677
|
let gitDir = null;
|
|
9396
9678
|
let top = null;
|
|
@@ -9401,26 +9683,26 @@ function fastGit(root) {
|
|
|
9401
9683
|
else if (entry.isFile()) {
|
|
9402
9684
|
let text = "";
|
|
9403
9685
|
try {
|
|
9404
|
-
text =
|
|
9686
|
+
text = fs5.readFileSync(dotGit, "utf8");
|
|
9405
9687
|
} catch {
|
|
9406
9688
|
return null;
|
|
9407
9689
|
}
|
|
9408
9690
|
const match = /^gitdir: (.+)$/mu.exec(text);
|
|
9409
9691
|
if (!match)
|
|
9410
9692
|
return null;
|
|
9411
|
-
gitDir =
|
|
9693
|
+
gitDir = path9.resolve(dir, match[1].trim());
|
|
9412
9694
|
} else
|
|
9413
9695
|
return null;
|
|
9414
|
-
if (!
|
|
9696
|
+
if (!fs5.existsSync(path9.join(gitDir, "HEAD")))
|
|
9415
9697
|
return null;
|
|
9416
9698
|
} else if (isGitDir(dir))
|
|
9417
9699
|
gitDir = dir;
|
|
9418
9700
|
if (gitDir) {
|
|
9419
9701
|
let common = gitDir;
|
|
9420
9702
|
try {
|
|
9421
|
-
common =
|
|
9703
|
+
common = path9.resolve(gitDir, fs5.readFileSync(path9.join(gitDir, "commondir"), "utf8").trim());
|
|
9422
9704
|
} catch {}
|
|
9423
|
-
if (!
|
|
9705
|
+
if (!fs5.existsSync(path9.join(common, "objects")))
|
|
9424
9706
|
return null;
|
|
9425
9707
|
return {
|
|
9426
9708
|
kind: "repo",
|
|
@@ -9430,28 +9712,33 @@ function fastGit(root) {
|
|
|
9430
9712
|
reftable: reftableRefs(common)
|
|
9431
9713
|
};
|
|
9432
9714
|
}
|
|
9433
|
-
const parent =
|
|
9715
|
+
const parent = path9.dirname(dir);
|
|
9434
9716
|
if (parent === dir)
|
|
9435
9717
|
return { kind: "none" };
|
|
9436
9718
|
dir = parent;
|
|
9437
9719
|
}
|
|
9438
9720
|
}
|
|
9721
|
+
var outsideGit = (root) => {
|
|
9722
|
+
const dir = folderStoreDir2(root);
|
|
9723
|
+
migrateFolderStore(root, dir);
|
|
9724
|
+
return { dir, shared: false, top: null };
|
|
9725
|
+
};
|
|
9439
9726
|
function resolveStore(root) {
|
|
9440
|
-
root =
|
|
9727
|
+
root = path9.resolve(root);
|
|
9441
9728
|
let stat = null;
|
|
9442
9729
|
try {
|
|
9443
|
-
stat =
|
|
9730
|
+
stat = fs5.statSync(root);
|
|
9444
9731
|
} catch {}
|
|
9445
9732
|
if (!stat)
|
|
9446
9733
|
return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
|
|
9447
9734
|
if (!stat.isDirectory())
|
|
9448
|
-
return { dir:
|
|
9735
|
+
return { dir: path9.join(root, ".workit"), shared: false, top: null };
|
|
9449
9736
|
const fast = fastGit(root);
|
|
9450
9737
|
if (fast?.kind === "none")
|
|
9451
|
-
return
|
|
9738
|
+
return outsideGit(root);
|
|
9452
9739
|
if (fast?.kind === "repo")
|
|
9453
9740
|
return {
|
|
9454
|
-
dir:
|
|
9741
|
+
dir: path9.join(fast.common, "workit"),
|
|
9455
9742
|
shared: true,
|
|
9456
9743
|
top: fast.top,
|
|
9457
9744
|
git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
|
|
@@ -9461,20 +9748,20 @@ function resolveStore(root) {
|
|
|
9461
9748
|
if (run.ok && common) {
|
|
9462
9749
|
const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
|
|
9463
9750
|
return {
|
|
9464
|
-
dir:
|
|
9751
|
+
dir: path9.join(real(path9.resolve(root, common)), "workit"),
|
|
9465
9752
|
shared: true,
|
|
9466
9753
|
top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
|
|
9467
9754
|
};
|
|
9468
9755
|
}
|
|
9469
9756
|
if (run.missing || !run.ok && NOT_A_REPO.test(run.stderr))
|
|
9470
|
-
return
|
|
9757
|
+
return outsideGit(root);
|
|
9471
9758
|
return new Error(`cannot locate the workit store: git rev-parse failed (${run.stderr.trim().split(`
|
|
9472
9759
|
`)[0] || "no output"}); fix the repository (git status should work here)`);
|
|
9473
9760
|
}
|
|
9474
9761
|
var rebasingBranch = (gitDir) => {
|
|
9475
9762
|
for (const state of ["rebase-merge", "rebase-apply"]) {
|
|
9476
9763
|
try {
|
|
9477
|
-
const ref =
|
|
9764
|
+
const ref = fs5.readFileSync(path9.join(gitDir, state, "head-name"), "utf8").trim();
|
|
9478
9765
|
const match = /^refs\/heads\/(.+)$/u.exec(ref);
|
|
9479
9766
|
if (match)
|
|
9480
9767
|
return match[1];
|
|
@@ -9489,7 +9776,7 @@ function resolveTaskKey(root, location) {
|
|
|
9489
9776
|
if (location.git && !location.git.reftable) {
|
|
9490
9777
|
let head = "";
|
|
9491
9778
|
try {
|
|
9492
|
-
head =
|
|
9779
|
+
head = fs5.readFileSync(path9.join(location.git.gitDir, "HEAD"), "utf8").trim();
|
|
9493
9780
|
} catch {}
|
|
9494
9781
|
const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
|
|
9495
9782
|
if (ref && ref[1] !== ".invalid")
|
|
@@ -9520,10 +9807,10 @@ function resolveTaskKey(root, location) {
|
|
|
9520
9807
|
return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
|
|
9521
9808
|
}
|
|
9522
9809
|
function checkoutRootOf(root, location) {
|
|
9523
|
-
const resolved =
|
|
9810
|
+
const resolved = path9.resolve(root);
|
|
9524
9811
|
let canonical = resolved;
|
|
9525
9812
|
try {
|
|
9526
|
-
canonical =
|
|
9813
|
+
canonical = fs5.realpathSync(resolved);
|
|
9527
9814
|
} catch {
|
|
9528
9815
|
return resolved;
|
|
9529
9816
|
}
|
|
@@ -9533,7 +9820,7 @@ function checkoutRootOf(root, location) {
|
|
|
9533
9820
|
if (real(canonical) === found.top)
|
|
9534
9821
|
return canonical;
|
|
9535
9822
|
try {
|
|
9536
|
-
return
|
|
9823
|
+
return fs5.realpathSync(found.top);
|
|
9537
9824
|
} catch {
|
|
9538
9825
|
return canonical;
|
|
9539
9826
|
}
|
|
@@ -9545,25 +9832,25 @@ function branchRenames(location) {
|
|
|
9545
9832
|
const walk = (dir) => {
|
|
9546
9833
|
let entries;
|
|
9547
9834
|
try {
|
|
9548
|
-
entries =
|
|
9835
|
+
entries = fs5.readdirSync(dir, { withFileTypes: true });
|
|
9549
9836
|
} catch {
|
|
9550
9837
|
return;
|
|
9551
9838
|
}
|
|
9552
9839
|
for (const entry of entries)
|
|
9553
9840
|
if (entry.isDirectory())
|
|
9554
|
-
walk(
|
|
9841
|
+
walk(path9.join(dir, entry.name));
|
|
9555
9842
|
else
|
|
9556
|
-
files.push(
|
|
9843
|
+
files.push(path9.join(dir, entry.name));
|
|
9557
9844
|
};
|
|
9558
|
-
walk(
|
|
9845
|
+
walk(path9.join(path9.dirname(location.dir), "logs", "refs", "heads"));
|
|
9559
9846
|
if (location.git)
|
|
9560
|
-
files.push(
|
|
9847
|
+
files.push(path9.join(location.git.gitDir, "logs", "HEAD"));
|
|
9561
9848
|
const seen = new Set;
|
|
9562
9849
|
const renames = [];
|
|
9563
9850
|
for (const file of files) {
|
|
9564
9851
|
let text = "";
|
|
9565
9852
|
try {
|
|
9566
|
-
text =
|
|
9853
|
+
text = fs5.readFileSync(file, "utf8");
|
|
9567
9854
|
} catch {
|
|
9568
9855
|
continue;
|
|
9569
9856
|
}
|
|
@@ -9588,13 +9875,7 @@ function followRenames(key, boundAt, renames) {
|
|
|
9588
9875
|
}
|
|
9589
9876
|
return current;
|
|
9590
9877
|
}
|
|
9591
|
-
var checkoutSlug = (root) =>
|
|
9592
|
-
let canonical = real(root);
|
|
9593
|
-
if (process.platform === "win32")
|
|
9594
|
-
canonical = canonical.toLowerCase();
|
|
9595
|
-
const base = path8.basename(canonical).replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40) || "root";
|
|
9596
|
-
return `${base}-${shortHash(canonical)}`;
|
|
9597
|
-
};
|
|
9878
|
+
var checkoutSlug = (root) => folderSlug2(root);
|
|
9598
9879
|
|
|
9599
9880
|
// packages/workit-core/src/core/task-contract.ts
|
|
9600
9881
|
import { createHash as createHash7, randomUUID } from "node:crypto";
|
|
@@ -10337,7 +10618,7 @@ function resolveIdRef(kind, ref, ids) {
|
|
|
10337
10618
|
return failure2("not_found", `${kind} not found`);
|
|
10338
10619
|
return failure2("invalid_input", `${kind} prefix ${ref} is ambiguous; candidates: ${matches.join(", ")}`);
|
|
10339
10620
|
}
|
|
10340
|
-
function
|
|
10621
|
+
function canonical3(value, seen) {
|
|
10341
10622
|
if (value === null || typeof value === "boolean" || typeof value === "string") {
|
|
10342
10623
|
if (typeof value === "string" && invalidUnicode(value))
|
|
10343
10624
|
throw new TypeError("invalid Unicode");
|
|
@@ -10359,7 +10640,7 @@ function canonical2(value, seen) {
|
|
|
10359
10640
|
if (!(index in value))
|
|
10360
10641
|
throw new TypeError("sparse array");
|
|
10361
10642
|
}
|
|
10362
|
-
result = value.map((item) =>
|
|
10643
|
+
result = value.map((item) => canonical3(item, seen));
|
|
10363
10644
|
} else {
|
|
10364
10645
|
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
10365
10646
|
throw new TypeError("value is not a JSON object");
|
|
@@ -10367,13 +10648,13 @@ function canonical2(value, seen) {
|
|
|
10367
10648
|
throw new TypeError("symbol key is not JSON");
|
|
10368
10649
|
if (Object.keys(value).some((key) => invalidUnicode(key)))
|
|
10369
10650
|
throw new TypeError("invalid Unicode");
|
|
10370
|
-
result = Object.fromEntries(Object.keys(value).toSorted().map((key) => [key,
|
|
10651
|
+
result = Object.fromEntries(Object.keys(value).toSorted().map((key) => [key, canonical3(value[key], seen)]));
|
|
10371
10652
|
}
|
|
10372
10653
|
seen.delete(value);
|
|
10373
10654
|
return result;
|
|
10374
10655
|
}
|
|
10375
10656
|
function canonicalJson(value) {
|
|
10376
|
-
return JSON.stringify(
|
|
10657
|
+
return JSON.stringify(canonical3(value, new Set));
|
|
10377
10658
|
}
|
|
10378
10659
|
function sha256(value) {
|
|
10379
10660
|
if (typeof value === "string" && invalidUnicode(value))
|
|
@@ -10414,14 +10695,14 @@ function candidateDigest(input) {
|
|
|
10414
10695
|
|
|
10415
10696
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
10416
10697
|
import { createHash as createHash10 } from "node:crypto";
|
|
10417
|
-
import * as
|
|
10698
|
+
import * as fs14 from "node:fs";
|
|
10418
10699
|
import { spawnSync as spawnSync12 } from "node:child_process";
|
|
10419
|
-
import
|
|
10700
|
+
import path19 from "node:path";
|
|
10420
10701
|
|
|
10421
10702
|
// packages/workit-core/src/core/task-read.ts
|
|
10422
10703
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
10423
|
-
import * as
|
|
10424
|
-
import
|
|
10704
|
+
import * as fs11 from "node:fs";
|
|
10705
|
+
import path14 from "node:path";
|
|
10425
10706
|
|
|
10426
10707
|
// node_modules/@openclaw/fs-safe/dist/errors.js
|
|
10427
10708
|
var OPERATIONAL_CODES = new Set([
|
|
@@ -10472,10 +10753,10 @@ function sameFileIdentity(left, right, platform = process.platform) {
|
|
|
10472
10753
|
// node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
|
|
10473
10754
|
import { randomBytes } from "node:crypto";
|
|
10474
10755
|
import fsSync from "node:fs";
|
|
10475
|
-
import
|
|
10756
|
+
import path10 from "node:path";
|
|
10476
10757
|
|
|
10477
10758
|
// node_modules/@openclaw/fs-safe/dist/bounded-read.js
|
|
10478
|
-
import
|
|
10759
|
+
import fs6 from "node:fs";
|
|
10479
10760
|
|
|
10480
10761
|
// node_modules/@openclaw/fs-safe/dist/byte-budget.js
|
|
10481
10762
|
function normalizeMaxBytes(value, options = {}) {
|
|
@@ -10512,7 +10793,7 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
|
|
|
10512
10793
|
let total = 0;
|
|
10513
10794
|
while (true) {
|
|
10514
10795
|
const length = nextReadLength(total, maxBytes, scratch.length);
|
|
10515
|
-
const bytesRead =
|
|
10796
|
+
const bytesRead = fs6.readSync(fd, scratch, 0, length, null);
|
|
10516
10797
|
if (bytesRead === 0) {
|
|
10517
10798
|
return Buffer.concat(chunks, total);
|
|
10518
10799
|
}
|
|
@@ -10521,9 +10802,9 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
|
|
|
10521
10802
|
}
|
|
10522
10803
|
|
|
10523
10804
|
// node_modules/@openclaw/fs-safe/dist/read-open-flags.js
|
|
10524
|
-
import
|
|
10805
|
+
import fs7 from "node:fs";
|
|
10525
10806
|
function resolveReadOpenFlags(options) {
|
|
10526
|
-
const constants = options?.constants ??
|
|
10807
|
+
const constants = options?.constants ?? fs7.constants;
|
|
10527
10808
|
const noFollow = process.platform !== "win32" && options?.followSymlinks !== true && typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
10528
10809
|
const nonBlocking = process.platform !== "win32" && typeof constants.O_NONBLOCK === "number" ? constants.O_NONBLOCK : 0;
|
|
10529
10810
|
return constants.O_RDONLY | noFollow | nonBlocking;
|
|
@@ -10562,13 +10843,13 @@ ${ownershipToken}
|
|
|
10562
10843
|
return { raw, ownershipToken };
|
|
10563
10844
|
}
|
|
10564
10845
|
function relativeSidecarLockPath(lockRoot, lockPath) {
|
|
10565
|
-
const resolved =
|
|
10566
|
-
const lexicalRelative =
|
|
10567
|
-
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${
|
|
10568
|
-
if (!relative || relative === ".." || relative.startsWith(`..${
|
|
10846
|
+
const resolved = path10.resolve(lockPath);
|
|
10847
|
+
const lexicalRelative = path10.relative(lockRoot.rootDir, resolved);
|
|
10848
|
+
const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path10.sep}`) && !path10.isAbsolute(lexicalRelative) ? lexicalRelative : path10.relative(lockRoot.rootReal, resolved);
|
|
10849
|
+
if (!relative || relative === ".." || relative.startsWith(`..${path10.sep}`) || path10.isAbsolute(relative)) {
|
|
10569
10850
|
throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
|
|
10570
10851
|
}
|
|
10571
|
-
return relative.split(
|
|
10852
|
+
return relative.split(path10.sep).join(path10.posix.sep);
|
|
10572
10853
|
}
|
|
10573
10854
|
function parseSidecarLockPayload(raw, parser) {
|
|
10574
10855
|
if (parser) {
|
|
@@ -10714,8 +10995,8 @@ function getFsSafeLockConfig() {
|
|
|
10714
10995
|
}
|
|
10715
10996
|
|
|
10716
10997
|
// node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
|
|
10717
|
-
import
|
|
10718
|
-
import
|
|
10998
|
+
import fs8 from "node:fs";
|
|
10999
|
+
import path11 from "node:path";
|
|
10719
11000
|
|
|
10720
11001
|
// node_modules/@openclaw/fs-safe/dist/timing.js
|
|
10721
11002
|
function sleepSync(ms) {
|
|
@@ -10745,7 +11026,7 @@ function releaseAllSyncHeldLocks() {
|
|
|
10745
11026
|
}
|
|
10746
11027
|
try {
|
|
10747
11028
|
if (held.fd !== undefined)
|
|
10748
|
-
|
|
11029
|
+
fs8.closeSync(held.fd);
|
|
10749
11030
|
} catch {}
|
|
10750
11031
|
try {
|
|
10751
11032
|
removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
|
|
@@ -10780,7 +11061,7 @@ function releaseSyncHeldLock(held) {
|
|
|
10780
11061
|
if (held.fd !== undefined) {
|
|
10781
11062
|
const fd = held.fd;
|
|
10782
11063
|
held.fd = undefined;
|
|
10783
|
-
|
|
11064
|
+
fs8.closeSync(fd);
|
|
10784
11065
|
}
|
|
10785
11066
|
removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
|
|
10786
11067
|
heldLocks.delete(held.normalizedTargetPath);
|
|
@@ -10803,29 +11084,29 @@ function createSyncHeldLockHandle(held) {
|
|
|
10803
11084
|
};
|
|
10804
11085
|
}
|
|
10805
11086
|
function canonicalLockParentSync(parent) {
|
|
10806
|
-
return process.platform === "win32" ?
|
|
11087
|
+
return process.platform === "win32" ? fs8.realpathSync.native(parent) : fs8.realpathSync(parent);
|
|
10807
11088
|
}
|
|
10808
11089
|
function normalizeTargetPath(targetPath) {
|
|
10809
|
-
const resolved =
|
|
10810
|
-
|
|
11090
|
+
const resolved = path11.resolve(targetPath);
|
|
11091
|
+
fs8.mkdirSync(path11.dirname(resolved), { recursive: true });
|
|
10811
11092
|
try {
|
|
10812
|
-
return
|
|
11093
|
+
return path11.join(canonicalLockParentSync(path11.dirname(resolved)), path11.basename(resolved));
|
|
10813
11094
|
} catch {
|
|
10814
11095
|
return resolved;
|
|
10815
11096
|
}
|
|
10816
11097
|
}
|
|
10817
11098
|
function boundedLockPath(lockPath, lockRoot) {
|
|
10818
|
-
const resolved =
|
|
11099
|
+
const resolved = path11.resolve(lockPath);
|
|
10819
11100
|
if (!lockRoot)
|
|
10820
11101
|
return resolved;
|
|
10821
11102
|
relativeSidecarLockPath(lockRoot, resolved);
|
|
10822
|
-
const parent =
|
|
11103
|
+
const parent = path11.dirname(resolved);
|
|
10823
11104
|
const parentReal = canonicalLockParentSync(parent);
|
|
10824
|
-
const parentRelative =
|
|
10825
|
-
if (parentRelative === ".." || parentRelative.startsWith(`..${
|
|
11105
|
+
const parentRelative = path11.relative(lockRoot.rootReal, parentReal);
|
|
11106
|
+
if (parentRelative === ".." || parentRelative.startsWith(`..${path11.sep}`) || path11.isAbsolute(parentRelative)) {
|
|
10826
11107
|
throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
|
|
10827
11108
|
}
|
|
10828
|
-
return
|
|
11109
|
+
return path11.join(parentReal, path11.basename(resolved));
|
|
10829
11110
|
}
|
|
10830
11111
|
function defaultShouldReclaim(snapshot, staleMs, nowMs) {
|
|
10831
11112
|
const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
|
|
@@ -10835,7 +11116,7 @@ function defaultShouldReclaim(snapshot, staleMs, nowMs) {
|
|
|
10835
11116
|
}
|
|
10836
11117
|
function reclaimGuardExists(reclaimGuardPath) {
|
|
10837
11118
|
try {
|
|
10838
|
-
|
|
11119
|
+
fs8.lstatSync(reclaimGuardPath);
|
|
10839
11120
|
return true;
|
|
10840
11121
|
} catch (error) {
|
|
10841
11122
|
if (error.code === "ENOENT")
|
|
@@ -10899,19 +11180,19 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
10899
11180
|
const { raw, ownershipToken } = serializeSidecarLockPayload(payload);
|
|
10900
11181
|
let lockFileCreateDenied = false;
|
|
10901
11182
|
try {
|
|
10902
|
-
const noFollow = process.platform !== "win32" && typeof
|
|
11183
|
+
const noFollow = process.platform !== "win32" && typeof fs8.constants.O_NOFOLLOW === "number" ? fs8.constants.O_NOFOLLOW : 0;
|
|
10903
11184
|
try {
|
|
10904
|
-
fd =
|
|
11185
|
+
fd = fs8.openSync(lockPath, fs8.constants.O_WRONLY | fs8.constants.O_CREAT | fs8.constants.O_EXCL | noFollow, 384);
|
|
10905
11186
|
} catch (error) {
|
|
10906
11187
|
lockFileCreateDenied = isTransientLockFileDenial(error, lockPath);
|
|
10907
11188
|
throw error;
|
|
10908
11189
|
}
|
|
10909
|
-
|
|
10910
|
-
|
|
11190
|
+
fs8.writeFileSync(fd, raw, "utf8");
|
|
11191
|
+
fs8.fsyncSync(fd);
|
|
10911
11192
|
const snapshot = {
|
|
10912
11193
|
raw,
|
|
10913
11194
|
payload,
|
|
10914
|
-
stat:
|
|
11195
|
+
stat: fs8.fstatSync(fd),
|
|
10915
11196
|
ownershipToken
|
|
10916
11197
|
};
|
|
10917
11198
|
const createdHeld = {
|
|
@@ -10946,8 +11227,8 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
10946
11227
|
return returnedHandle;
|
|
10947
11228
|
} catch (error) {
|
|
10948
11229
|
if (fd !== undefined) {
|
|
10949
|
-
const failed = { payload: null, stat:
|
|
10950
|
-
|
|
11230
|
+
const failed = { payload: null, stat: fs8.fstatSync(fd) };
|
|
11231
|
+
fs8.closeSync(fd);
|
|
10951
11232
|
fd = undefined;
|
|
10952
11233
|
removeSidecarLockIfUnchangedSync(lockPath, failed);
|
|
10953
11234
|
}
|
|
@@ -10996,7 +11277,7 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
10996
11277
|
})) {
|
|
10997
11278
|
let ownsReclaimGuard = false;
|
|
10998
11279
|
try {
|
|
10999
|
-
|
|
11280
|
+
fs8.mkdirSync(reclaimGuardPath);
|
|
11000
11281
|
ownsReclaimGuard = true;
|
|
11001
11282
|
if (removeSidecarLockIfUnchangedSync(lockPath, snapshot))
|
|
11002
11283
|
continue;
|
|
@@ -11009,7 +11290,7 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
11009
11290
|
} finally {
|
|
11010
11291
|
if (ownsReclaimGuard) {
|
|
11011
11292
|
try {
|
|
11012
|
-
|
|
11293
|
+
fs8.rmdirSync(reclaimGuardPath);
|
|
11013
11294
|
} catch {}
|
|
11014
11295
|
}
|
|
11015
11296
|
}
|
|
@@ -11026,13 +11307,13 @@ function acquireFileLockSync(targetPath, options) {
|
|
|
11026
11307
|
}
|
|
11027
11308
|
// packages/workit-core/src/core/package-root.ts
|
|
11028
11309
|
import { existsSync as existsSync4 } from "node:fs";
|
|
11029
|
-
import
|
|
11310
|
+
import path12 from "node:path";
|
|
11030
11311
|
import { fileURLToPath } from "node:url";
|
|
11031
11312
|
var packageRoot = () => {
|
|
11032
|
-
let dir =
|
|
11313
|
+
let dir = path12.dirname(fileURLToPath(import.meta.url));
|
|
11033
11314
|
while (true) {
|
|
11034
|
-
const parent =
|
|
11035
|
-
if (existsSync4(
|
|
11315
|
+
const parent = path12.dirname(dir);
|
|
11316
|
+
if (existsSync4(path12.join(dir, "package.json")) || parent === dir)
|
|
11036
11317
|
return dir;
|
|
11037
11318
|
dir = parent;
|
|
11038
11319
|
}
|
|
@@ -11040,7 +11321,7 @@ var packageRoot = () => {
|
|
|
11040
11321
|
|
|
11041
11322
|
// packages/workit-core/src/core/store-lock.ts
|
|
11042
11323
|
import { spawnSync as spawnSync8 } from "node:child_process";
|
|
11043
|
-
import
|
|
11324
|
+
import fs9 from "node:fs";
|
|
11044
11325
|
import { hostname } from "node:os";
|
|
11045
11326
|
var metadataLockSchema = object({
|
|
11046
11327
|
pid: number2().int().nonnegative().safe(),
|
|
@@ -11083,7 +11364,7 @@ var parseProcStatStart = (stat) => {
|
|
|
11083
11364
|
};
|
|
11084
11365
|
var readProcStat = (pid) => {
|
|
11085
11366
|
try {
|
|
11086
|
-
return
|
|
11367
|
+
return fs9.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
11087
11368
|
} catch {
|
|
11088
11369
|
return null;
|
|
11089
11370
|
}
|
|
@@ -11112,7 +11393,7 @@ var processStartOf = (pid, deps = {}) => {
|
|
|
11112
11393
|
};
|
|
11113
11394
|
var readTrimmed = (file) => {
|
|
11114
11395
|
try {
|
|
11115
|
-
return
|
|
11396
|
+
return fs9.readFileSync(file, "utf8").trim() || null;
|
|
11116
11397
|
} catch {
|
|
11117
11398
|
return null;
|
|
11118
11399
|
}
|
|
@@ -11123,7 +11404,7 @@ var localLockHost = () => {
|
|
|
11123
11404
|
return cachedLockHost;
|
|
11124
11405
|
let pidns = null;
|
|
11125
11406
|
try {
|
|
11126
|
-
pidns = /\[(\d+)\]/.exec(
|
|
11407
|
+
pidns = /\[(\d+)\]/.exec(fs9.readlinkSync("/proc/self/ns/pid"))?.[1] ?? null;
|
|
11127
11408
|
} catch {}
|
|
11128
11409
|
const boot = readTrimmed("/proc/sys/kernel/random/boot_id");
|
|
11129
11410
|
cachedLockHost = pidns || boot ? `${hostname()}#${pidns ?? "?"}:${boot ?? "?"}` : hostname();
|
|
@@ -11169,7 +11450,7 @@ var classifyLockOwner = (payload, ageMs, localHost = localLockHost(), options =
|
|
|
11169
11450
|
};
|
|
11170
11451
|
var ageOf = (file, nowMs) => {
|
|
11171
11452
|
try {
|
|
11172
|
-
return nowMs -
|
|
11453
|
+
return nowMs - fs9.lstatSync(file).mtimeMs;
|
|
11173
11454
|
} catch {
|
|
11174
11455
|
return null;
|
|
11175
11456
|
}
|
|
@@ -11180,7 +11461,7 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
|
|
|
11180
11461
|
if (age === null || age <= RECLAIM_GUARD_TTL_MS)
|
|
11181
11462
|
return false;
|
|
11182
11463
|
try {
|
|
11183
|
-
|
|
11464
|
+
fs9.rmdirSync(guard);
|
|
11184
11465
|
return true;
|
|
11185
11466
|
} catch {
|
|
11186
11467
|
return false;
|
|
@@ -11189,8 +11470,8 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
|
|
|
11189
11470
|
|
|
11190
11471
|
// packages/workit-core/src/store/event-log.ts
|
|
11191
11472
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
11192
|
-
import
|
|
11193
|
-
import
|
|
11473
|
+
import fs10 from "node:fs";
|
|
11474
|
+
import path13 from "node:path";
|
|
11194
11475
|
var EVENT_VERSION = 1;
|
|
11195
11476
|
|
|
11196
11477
|
class LogDamage extends Error {
|
|
@@ -11219,7 +11500,7 @@ var parseEvent = (line, file, offset) => {
|
|
|
11219
11500
|
function readLog(file, from = 0, expectSeq = null) {
|
|
11220
11501
|
let fd;
|
|
11221
11502
|
try {
|
|
11222
|
-
fd =
|
|
11503
|
+
fd = fs10.openSync(file, "r");
|
|
11223
11504
|
} catch (error) {
|
|
11224
11505
|
if (error.code === "ENOENT")
|
|
11225
11506
|
return null;
|
|
@@ -11228,13 +11509,13 @@ function readLog(file, from = 0, expectSeq = null) {
|
|
|
11228
11509
|
let bytes;
|
|
11229
11510
|
let size;
|
|
11230
11511
|
try {
|
|
11231
|
-
size =
|
|
11512
|
+
size = fs10.fstatSync(fd).size;
|
|
11232
11513
|
if (from > size)
|
|
11233
11514
|
throw new LogDamage(`${file}: shorter than its snapshot`);
|
|
11234
11515
|
bytes = Buffer.alloc(size - from);
|
|
11235
11516
|
let read = 0;
|
|
11236
11517
|
while (read < bytes.length) {
|
|
11237
|
-
const got =
|
|
11518
|
+
const got = fs10.readSync(fd, bytes, read, bytes.length - read, from + read);
|
|
11238
11519
|
if (got === 0)
|
|
11239
11520
|
break;
|
|
11240
11521
|
read += got;
|
|
@@ -11242,7 +11523,7 @@ function readLog(file, from = 0, expectSeq = null) {
|
|
|
11242
11523
|
bytes = bytes.subarray(0, read);
|
|
11243
11524
|
size = from + read;
|
|
11244
11525
|
} finally {
|
|
11245
|
-
|
|
11526
|
+
fs10.closeSync(fd);
|
|
11246
11527
|
}
|
|
11247
11528
|
const events = [];
|
|
11248
11529
|
let start = 0;
|
|
@@ -11267,11 +11548,11 @@ function readLog(file, from = 0, expectSeq = null) {
|
|
|
11267
11548
|
}
|
|
11268
11549
|
var fsyncDirectory = (dir) => {
|
|
11269
11550
|
try {
|
|
11270
|
-
const fd =
|
|
11551
|
+
const fd = fs10.openSync(dir, "r");
|
|
11271
11552
|
try {
|
|
11272
|
-
|
|
11553
|
+
fs10.fsyncSync(fd);
|
|
11273
11554
|
} finally {
|
|
11274
|
-
|
|
11555
|
+
fs10.closeSync(fd);
|
|
11275
11556
|
}
|
|
11276
11557
|
} catch (error) {
|
|
11277
11558
|
if (process.platform !== "win32")
|
|
@@ -11281,20 +11562,20 @@ var fsyncDirectory = (dir) => {
|
|
|
11281
11562
|
function replaceFile(file, bytes, durable) {
|
|
11282
11563
|
const temporary = `${file}.${process.pid}.${randomUUID2()}.tmp`;
|
|
11283
11564
|
try {
|
|
11284
|
-
const fd =
|
|
11565
|
+
const fd = fs10.openSync(temporary, "wx", 384);
|
|
11285
11566
|
try {
|
|
11286
|
-
|
|
11567
|
+
fs10.writeSync(fd, bytes);
|
|
11287
11568
|
if (durable)
|
|
11288
|
-
|
|
11569
|
+
fs10.fsyncSync(fd);
|
|
11289
11570
|
} finally {
|
|
11290
|
-
|
|
11571
|
+
fs10.closeSync(fd);
|
|
11291
11572
|
}
|
|
11292
11573
|
renameWithRetry(temporary, file);
|
|
11293
11574
|
if (durable)
|
|
11294
|
-
fsyncDirectory(
|
|
11575
|
+
fsyncDirectory(path13.dirname(file));
|
|
11295
11576
|
} catch (error) {
|
|
11296
11577
|
try {
|
|
11297
|
-
|
|
11578
|
+
fs10.unlinkSync(temporary);
|
|
11298
11579
|
} catch {}
|
|
11299
11580
|
throw error;
|
|
11300
11581
|
}
|
|
@@ -11319,7 +11600,7 @@ var retryTransient = (run) => {
|
|
|
11319
11600
|
}
|
|
11320
11601
|
}
|
|
11321
11602
|
};
|
|
11322
|
-
var renameWithRetry = (from, to) => retryTransient(() =>
|
|
11603
|
+
var renameWithRetry = (from, to) => retryTransient(() => fs10.renameSync(from, to));
|
|
11323
11604
|
|
|
11324
11605
|
// packages/workit-core/src/store/patch.ts
|
|
11325
11606
|
var isPlainObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -11511,7 +11792,7 @@ var indexEntry = (task, key, legacy, file) => {
|
|
|
11511
11792
|
};
|
|
11512
11793
|
var fileSignature = (file) => {
|
|
11513
11794
|
try {
|
|
11514
|
-
const stat =
|
|
11795
|
+
const stat = fs11.statSync(file, { bigint: true });
|
|
11515
11796
|
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
|
|
11516
11797
|
} catch {
|
|
11517
11798
|
return null;
|
|
@@ -11528,7 +11809,7 @@ var cachedRuntimeVersion = null;
|
|
|
11528
11809
|
var runtimeVersion = () => {
|
|
11529
11810
|
if (cachedRuntimeVersion === null) {
|
|
11530
11811
|
try {
|
|
11531
|
-
const pkg = JSON.parse(
|
|
11812
|
+
const pkg = JSON.parse(fs11.readFileSync(path14.join(packageRoot(), "package.json"), "utf8"));
|
|
11532
11813
|
cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
|
|
11533
11814
|
} catch {
|
|
11534
11815
|
cachedRuntimeVersion = "0.0.0";
|
|
@@ -11550,14 +11831,14 @@ var isNewerVersion = (candidate, current) => {
|
|
|
11550
11831
|
var validId = (value) => /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(value);
|
|
11551
11832
|
var readText2 = (file) => {
|
|
11552
11833
|
try {
|
|
11553
|
-
return
|
|
11834
|
+
return fs11.readFileSync(file, "utf8");
|
|
11554
11835
|
} catch {
|
|
11555
11836
|
return "";
|
|
11556
11837
|
}
|
|
11557
11838
|
};
|
|
11558
11839
|
var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
|
|
11559
11840
|
var branchStart = (location, branch, aliases) => {
|
|
11560
|
-
const first = readText2(
|
|
11841
|
+
const first = readText2(path14.join(path14.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
|
|
11561
11842
|
`, 1)[0];
|
|
11562
11843
|
const created = REFLOG_LINE.exec(first);
|
|
11563
11844
|
const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
|
|
@@ -11567,7 +11848,7 @@ var branchStart = (location, branch, aliases) => {
|
|
|
11567
11848
|
return start;
|
|
11568
11849
|
if (!location.git)
|
|
11569
11850
|
return null;
|
|
11570
|
-
for (const line of readText2(
|
|
11851
|
+
for (const line of readText2(path14.join(location.git.gitDir, "logs", "HEAD")).split(`
|
|
11571
11852
|
`)) {
|
|
11572
11853
|
const entry = REFLOG_LINE.exec(line);
|
|
11573
11854
|
const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
|
|
@@ -11577,23 +11858,23 @@ var branchStart = (location, branch, aliases) => {
|
|
|
11577
11858
|
}
|
|
11578
11859
|
return null;
|
|
11579
11860
|
};
|
|
11580
|
-
var refExists2 = (common, ref) =>
|
|
11861
|
+
var refExists2 = (common, ref) => fs11.existsSync(path14.join(common, ref)) || readText2(path14.join(common, "packed-refs")).includes(` ${ref}
|
|
11581
11862
|
`);
|
|
11582
11863
|
var origins = new Map;
|
|
11583
11864
|
var sameDirectoryIdentity = (left, right) => {
|
|
11584
|
-
if (!
|
|
11865
|
+
if (!path14.isAbsolute(left) || !path14.isAbsolute(right))
|
|
11585
11866
|
return false;
|
|
11586
|
-
const normalizedLeft =
|
|
11587
|
-
const normalizedRight =
|
|
11867
|
+
const normalizedLeft = path14.resolve(left);
|
|
11868
|
+
const normalizedRight = path14.resolve(right);
|
|
11588
11869
|
try {
|
|
11589
|
-
const a =
|
|
11590
|
-
const b =
|
|
11870
|
+
const a = fs11.statSync(normalizedLeft, { bigint: true });
|
|
11871
|
+
const b = fs11.statSync(normalizedRight, { bigint: true });
|
|
11591
11872
|
if (!a.isDirectory() || !b.isDirectory())
|
|
11592
11873
|
return false;
|
|
11593
11874
|
if (process.platform === "win32" ? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase() : normalizedLeft === normalizedRight)
|
|
11594
11875
|
return true;
|
|
11595
|
-
const canonicalLeft =
|
|
11596
|
-
const canonicalRight =
|
|
11876
|
+
const canonicalLeft = fs11.realpathSync(normalizedLeft);
|
|
11877
|
+
const canonicalRight = fs11.realpathSync(normalizedRight);
|
|
11597
11878
|
if (process.platform === "win32" ? canonicalLeft.toLowerCase() === canonicalRight.toLowerCase() : canonicalLeft === canonicalRight)
|
|
11598
11879
|
return true;
|
|
11599
11880
|
return a.dev === b.dev && a.ino !== 0n && a.ino === b.ino;
|
|
@@ -11618,14 +11899,14 @@ class TaskReader {
|
|
|
11618
11899
|
located;
|
|
11619
11900
|
migrationChecked = false;
|
|
11620
11901
|
constructor(root, options = {}) {
|
|
11621
|
-
const resolved =
|
|
11622
|
-
this.origin =
|
|
11902
|
+
const resolved = path14.resolve(root);
|
|
11903
|
+
this.origin = fs11.existsSync(resolved) ? fs11.realpathSync(resolved) : resolved;
|
|
11623
11904
|
this.located = resolveStore(this.origin);
|
|
11624
11905
|
this.root = checkoutRootOf(this.origin, this.located);
|
|
11625
11906
|
this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
|
|
11626
11907
|
}
|
|
11627
11908
|
location() {
|
|
11628
|
-
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared &&
|
|
11909
|
+
if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs11.existsSync(path14.join(this.root, ".git"))) {
|
|
11629
11910
|
this.located = undefined;
|
|
11630
11911
|
this.migrationChecked = false;
|
|
11631
11912
|
}
|
|
@@ -11689,7 +11970,7 @@ class TaskReader {
|
|
|
11689
11970
|
const tasksDir = this.paths().tasks;
|
|
11690
11971
|
let names;
|
|
11691
11972
|
try {
|
|
11692
|
-
names =
|
|
11973
|
+
names = fs11.existsSync(tasksDir) ? fs11.readdirSync(tasksDir).filter((name) => validId(name)) : [];
|
|
11693
11974
|
} catch (error) {
|
|
11694
11975
|
return failure2("storage_error", `unable to list tasks: ${String(error)}`, {
|
|
11695
11976
|
path: tasksDir
|
|
@@ -11730,7 +12011,7 @@ class TaskReader {
|
|
|
11730
12011
|
const file = this.paths().workspace;
|
|
11731
12012
|
let bytes;
|
|
11732
12013
|
try {
|
|
11733
|
-
bytes = retryTransient(() =>
|
|
12014
|
+
bytes = retryTransient(() => fs11.readFileSync(file, "utf8"));
|
|
11734
12015
|
} catch (error) {
|
|
11735
12016
|
if (error.code === "ENOENT")
|
|
11736
12017
|
return success(null, null, null);
|
|
@@ -11783,14 +12064,14 @@ class TaskReader {
|
|
|
11783
12064
|
const branch = key.ok ? key.data.branch : null;
|
|
11784
12065
|
if (!branch || !location.ok)
|
|
11785
12066
|
return success(null, null, null);
|
|
11786
|
-
const common =
|
|
11787
|
-
const heads =
|
|
11788
|
-
const headLog = location.data.git ?
|
|
12067
|
+
const common = path14.dirname(location.data.dir);
|
|
12068
|
+
const heads = path14.join(common, "logs", "refs", "heads");
|
|
12069
|
+
const headLog = location.data.git ? path14.join(location.data.git.gitDir, "logs", "HEAD") : "";
|
|
11789
12070
|
const signatures = [
|
|
11790
|
-
|
|
12071
|
+
path14.join(heads, branch),
|
|
11791
12072
|
headLog,
|
|
11792
12073
|
heads,
|
|
11793
|
-
|
|
12074
|
+
path14.join(common, "packed-refs")
|
|
11794
12075
|
].map((file) => fileSignature(file) ?? "-");
|
|
11795
12076
|
const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
|
|
11796
12077
|
let resolved = origins.get(slot);
|
|
@@ -11802,7 +12083,7 @@ class TaskReader {
|
|
|
11802
12083
|
aliases.push(rename.from);
|
|
11803
12084
|
const start = branchStart(location.data, branch, aliases);
|
|
11804
12085
|
const slash = start?.indexOf("/") ?? -1;
|
|
11805
|
-
const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(
|
|
12086
|
+
const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path14.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
|
|
11806
12087
|
const name = start && (remote ? start.slice(slash + 1) : start);
|
|
11807
12088
|
resolved = {
|
|
11808
12089
|
signature: signatures.join("|"),
|
|
@@ -11822,27 +12103,27 @@ class TaskReader {
|
|
|
11822
12103
|
}
|
|
11823
12104
|
paths() {
|
|
11824
12105
|
const location = this.location();
|
|
11825
|
-
const dir = location.ok ? location.data.dir :
|
|
11826
|
-
const checkout =
|
|
12106
|
+
const dir = location.ok ? location.data.dir : path14.join(this.root, ".workit");
|
|
12107
|
+
const checkout = path14.join(dir, "checkouts", checkoutSlug(this.root));
|
|
11827
12108
|
return {
|
|
11828
12109
|
dir,
|
|
11829
12110
|
shared: location.ok ? location.data.shared : false,
|
|
11830
|
-
marker:
|
|
12111
|
+
marker: path14.join(dir, "store.json"),
|
|
11831
12112
|
checkout,
|
|
11832
|
-
workspace:
|
|
11833
|
-
checkoutLock:
|
|
11834
|
-
tasks:
|
|
11835
|
-
index:
|
|
11836
|
-
blobs:
|
|
11837
|
-
legacy:
|
|
11838
|
-
v2:
|
|
12113
|
+
workspace: path14.join(checkout, "workspace.json"),
|
|
12114
|
+
checkoutLock: path14.join(checkout, "metadata.lock"),
|
|
12115
|
+
tasks: path14.join(dir, "tasks"),
|
|
12116
|
+
index: path14.join(dir, "task-index.json"),
|
|
12117
|
+
blobs: path14.join(dir, "blobs", "candidates"),
|
|
12118
|
+
legacy: path14.join(dir, "legacy", checkoutSlug(this.root), "v2"),
|
|
12119
|
+
v2: path14.join(this.root, ".workit")
|
|
11839
12120
|
};
|
|
11840
12121
|
}
|
|
11841
12122
|
eventsPath(taskId) {
|
|
11842
|
-
return
|
|
12123
|
+
return path14.join(this.paths().tasks, taskId, "events.jsonl");
|
|
11843
12124
|
}
|
|
11844
12125
|
snapshotPath(taskId) {
|
|
11845
|
-
return
|
|
12126
|
+
return path14.join(this.paths().tasks, taskId, "snapshot.json");
|
|
11846
12127
|
}
|
|
11847
12128
|
ready(write = false) {
|
|
11848
12129
|
const location = this.location();
|
|
@@ -11852,7 +12133,7 @@ class TaskReader {
|
|
|
11852
12133
|
return success(null, null, null);
|
|
11853
12134
|
const dirs = this.paths();
|
|
11854
12135
|
try {
|
|
11855
|
-
const marker = JSON.parse(
|
|
12136
|
+
const marker = JSON.parse(fs11.readFileSync(dirs.marker, "utf8"));
|
|
11856
12137
|
if (typeof marker.version === "number" && marker.version > STORE_FORMAT)
|
|
11857
12138
|
return failure2("recovery_required", `the workit store at ${dirs.dir} has format ${marker.version}; upgrade Workit to use it`, { path: dirs.marker });
|
|
11858
12139
|
} catch {}
|
|
@@ -11877,7 +12158,7 @@ class TaskReader {
|
|
|
11877
12158
|
return {
|
|
11878
12159
|
read: (digest) => {
|
|
11879
12160
|
try {
|
|
11880
|
-
return JSON.parse(
|
|
12161
|
+
return JSON.parse(fs11.readFileSync(path14.join(dir, `${digest}.json`), "utf8"));
|
|
11881
12162
|
} catch (error) {
|
|
11882
12163
|
throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
|
|
11883
12164
|
}
|
|
@@ -11964,7 +12245,7 @@ class TaskReader {
|
|
|
11964
12245
|
}
|
|
11965
12246
|
readSnapshot(taskId) {
|
|
11966
12247
|
try {
|
|
11967
|
-
const value = JSON.parse(
|
|
12248
|
+
const value = JSON.parse(fs11.readFileSync(this.snapshotPath(taskId), "utf8"));
|
|
11968
12249
|
if (!isObject5(value) || value.v !== 1 || value.task !== taskId || typeof value.seq !== "number" || typeof value.lastId !== "string" || typeof value.lastStart !== "number" || typeof value.end !== "number" || !isObject5(value.record))
|
|
11969
12250
|
return null;
|
|
11970
12251
|
return value;
|
|
@@ -11991,7 +12272,7 @@ class TaskReader {
|
|
|
11991
12272
|
}
|
|
11992
12273
|
readIndex() {
|
|
11993
12274
|
try {
|
|
11994
|
-
const value = JSON.parse(
|
|
12275
|
+
const value = JSON.parse(fs11.readFileSync(this.paths().index, "utf8"));
|
|
11995
12276
|
if (!isObject5(value) || value.version !== INDEX_VERSION || !isObject5(value.tasks))
|
|
11996
12277
|
return {};
|
|
11997
12278
|
const tasks = {};
|
|
@@ -12005,7 +12286,7 @@ class TaskReader {
|
|
|
12005
12286
|
}
|
|
12006
12287
|
writeIndex(entries) {
|
|
12007
12288
|
try {
|
|
12008
|
-
|
|
12289
|
+
fs11.mkdirSync(this.paths().tasks, { recursive: true });
|
|
12009
12290
|
replaceFile(this.paths().index, JSON.stringify({
|
|
12010
12291
|
version: INDEX_VERSION,
|
|
12011
12292
|
tasks: Object.fromEntries(entries.map((entry) => [entry.id, entry]))
|
|
@@ -12043,64 +12324,74 @@ class TaskReader {
|
|
|
12043
12324
|
return failure2("recovery_required", `${label} record does not satisfy its schema`);
|
|
12044
12325
|
}
|
|
12045
12326
|
v2Dirs() {
|
|
12046
|
-
return [...new Set([this.root, this.origin])].map((dir) =>
|
|
12327
|
+
return [...new Set([this.root, this.origin])].map((dir) => path14.join(dir, ".workit"));
|
|
12047
12328
|
}
|
|
12048
12329
|
pendingMigrations() {
|
|
12049
12330
|
return this.v2Dirs().filter((dir) => {
|
|
12050
|
-
const raw = this.readV2Workspace(
|
|
12331
|
+
const raw = this.readV2Workspace(path14.join(dir, "workspace.json"));
|
|
12051
12332
|
return raw !== null && raw !== TOMBSTONE;
|
|
12052
12333
|
});
|
|
12053
12334
|
}
|
|
12054
12335
|
adoptLocalStore() {
|
|
12336
|
+
if (!this.paths().shared)
|
|
12337
|
+
return success(null, null, null);
|
|
12338
|
+
for (const local of [this.paths().v2, folderStoreDir2(this.root)]) {
|
|
12339
|
+
const adopted = this.adoptStoreFrom(local);
|
|
12340
|
+
if (!adopted.ok)
|
|
12341
|
+
return adopted;
|
|
12342
|
+
}
|
|
12343
|
+
return success(null, null, null);
|
|
12344
|
+
}
|
|
12345
|
+
adoptStoreFrom(local) {
|
|
12055
12346
|
const dirs = this.paths();
|
|
12056
|
-
const marker =
|
|
12057
|
-
if (!
|
|
12347
|
+
const marker = path14.join(local, "store.json");
|
|
12348
|
+
if (!fs11.existsSync(marker))
|
|
12058
12349
|
return success(null, null, null);
|
|
12059
12350
|
return this.withLock(dirs.checkoutLock, () => {
|
|
12060
|
-
if (!
|
|
12351
|
+
if (!fs11.existsSync(marker))
|
|
12061
12352
|
return success(null, null, null);
|
|
12062
12353
|
let tasks = 0;
|
|
12063
12354
|
try {
|
|
12064
12355
|
const merge = (from, to) => {
|
|
12065
|
-
if (!
|
|
12066
|
-
|
|
12356
|
+
if (!fs11.existsSync(to)) {
|
|
12357
|
+
fs11.mkdirSync(path14.dirname(to), { recursive: true });
|
|
12067
12358
|
try {
|
|
12068
|
-
|
|
12359
|
+
fs11.renameSync(from, to);
|
|
12069
12360
|
} catch {
|
|
12070
|
-
|
|
12071
|
-
|
|
12361
|
+
fs11.cpSync(from, to, { recursive: true, errorOnExist: true, force: false });
|
|
12362
|
+
fs11.rmSync(from, { recursive: true, force: true });
|
|
12072
12363
|
}
|
|
12073
12364
|
return;
|
|
12074
12365
|
}
|
|
12075
|
-
if (
|
|
12076
|
-
for (const name of
|
|
12077
|
-
merge(
|
|
12366
|
+
if (fs11.lstatSync(from).isDirectory() && fs11.lstatSync(to).isDirectory())
|
|
12367
|
+
for (const name of fs11.readdirSync(from))
|
|
12368
|
+
merge(path14.join(from, name), path14.join(to, name));
|
|
12078
12369
|
};
|
|
12079
12370
|
for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
|
|
12080
|
-
const from =
|
|
12081
|
-
if (!
|
|
12371
|
+
const from = path14.join(local, sub);
|
|
12372
|
+
if (!fs11.existsSync(from))
|
|
12082
12373
|
continue;
|
|
12083
12374
|
if (sub === "tasks") {
|
|
12084
|
-
for (const name of
|
|
12085
|
-
if (validId(name) && !
|
|
12375
|
+
for (const name of fs11.readdirSync(from))
|
|
12376
|
+
if (validId(name) && !fs11.existsSync(path14.join(dirs.dir, sub, name)))
|
|
12086
12377
|
tasks += 1;
|
|
12087
12378
|
}
|
|
12088
|
-
merge(from,
|
|
12379
|
+
merge(from, path14.join(dirs.dir, sub));
|
|
12089
12380
|
}
|
|
12090
|
-
const ledger =
|
|
12091
|
-
if (
|
|
12092
|
-
merge(ledger,
|
|
12093
|
-
|
|
12094
|
-
|
|
12381
|
+
const ledger = path14.join(local, "ledger");
|
|
12382
|
+
if (fs11.existsSync(ledger) && !fs11.existsSync(path14.join(dirs.dir, "ledger")))
|
|
12383
|
+
merge(ledger, path14.join(dirs.dir, "ledger"));
|
|
12384
|
+
fs11.rmSync(path14.join(local, "task-index.json"), { force: true });
|
|
12385
|
+
fs11.renameSync(marker, path14.join(local, "store.moved.json"));
|
|
12095
12386
|
} catch (error) {
|
|
12096
|
-
return failure2("storage_error", `cannot move ${
|
|
12097
|
-
path:
|
|
12387
|
+
return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
|
|
12388
|
+
path: local
|
|
12098
12389
|
});
|
|
12099
12390
|
}
|
|
12100
12391
|
reportMigration({
|
|
12101
|
-
from:
|
|
12392
|
+
from: local,
|
|
12102
12393
|
to: dirs.dir,
|
|
12103
|
-
backup:
|
|
12394
|
+
backup: local,
|
|
12104
12395
|
tasks,
|
|
12105
12396
|
skipped: 0,
|
|
12106
12397
|
workspace: false
|
|
@@ -12111,7 +12402,7 @@ class TaskReader {
|
|
|
12111
12402
|
readV2Workspace(file) {
|
|
12112
12403
|
let bytes;
|
|
12113
12404
|
try {
|
|
12114
|
-
bytes =
|
|
12405
|
+
bytes = fs11.readFileSync(file, "utf8");
|
|
12115
12406
|
} catch {
|
|
12116
12407
|
return null;
|
|
12117
12408
|
}
|
|
@@ -12129,7 +12420,7 @@ class TaskReader {
|
|
|
12129
12420
|
schemaVersion: SCHEMA_VERSION,
|
|
12130
12421
|
id: workspaceId ?? newId(),
|
|
12131
12422
|
revision: newRevision(),
|
|
12132
|
-
root:
|
|
12423
|
+
root: path14.dirname(v2),
|
|
12133
12424
|
runtime: { createdWith: version, updatedWith: version },
|
|
12134
12425
|
writer: null,
|
|
12135
12426
|
store: {
|
|
@@ -12140,47 +12431,21 @@ class TaskReader {
|
|
|
12140
12431
|
},
|
|
12141
12432
|
critical: ["store"]
|
|
12142
12433
|
};
|
|
12143
|
-
|
|
12144
|
-
const ignore =
|
|
12145
|
-
if (!
|
|
12146
|
-
|
|
12434
|
+
fs11.mkdirSync(v2, { recursive: true });
|
|
12435
|
+
const ignore = path14.join(v2, ".gitignore");
|
|
12436
|
+
if (!fs11.existsSync(ignore))
|
|
12437
|
+
fs11.writeFileSync(ignore, `*
|
|
12147
12438
|
`);
|
|
12148
|
-
replaceFile(
|
|
12439
|
+
replaceFile(path14.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
|
|
12149
12440
|
`, true);
|
|
12150
12441
|
}
|
|
12151
|
-
writeTombstoneIfMissing() {
|
|
12152
|
-
try {
|
|
12153
|
-
if (this.paths().shared)
|
|
12154
|
-
return;
|
|
12155
|
-
const v2 = path13.join(this.root, ".workit");
|
|
12156
|
-
if (fs10.existsSync(path13.join(v2, "workspace.json")))
|
|
12157
|
-
return;
|
|
12158
|
-
let id = null;
|
|
12159
|
-
try {
|
|
12160
|
-
id = JSON.parse(fs10.readFileSync(this.paths().workspace, "utf8")).id ?? null;
|
|
12161
|
-
} catch {}
|
|
12162
|
-
this.writeTombstone(v2, id);
|
|
12163
|
-
} catch {}
|
|
12164
|
-
}
|
|
12165
12442
|
initializeStorage() {
|
|
12166
12443
|
const dirs = this.paths();
|
|
12167
|
-
retryTransient(() =>
|
|
12168
|
-
retryTransient(() =>
|
|
12169
|
-
if (!
|
|
12444
|
+
retryTransient(() => fs11.mkdirSync(dirs.checkout, { recursive: true }));
|
|
12445
|
+
retryTransient(() => fs11.mkdirSync(dirs.tasks, { recursive: true }));
|
|
12446
|
+
if (!fs11.existsSync(dirs.marker))
|
|
12170
12447
|
replaceFile(dirs.marker, `${JSON.stringify({ format: "workit-store", version: STORE_FORMAT, createdWith: runtimeVersion() })}
|
|
12171
12448
|
`, false);
|
|
12172
|
-
if (!dirs.shared) {
|
|
12173
|
-
const ignore = path13.join(dirs.dir, ".gitignore");
|
|
12174
|
-
let current = null;
|
|
12175
|
-
try {
|
|
12176
|
-
current = fs10.readFileSync(ignore, "utf8");
|
|
12177
|
-
} catch {}
|
|
12178
|
-
if (current !== `*
|
|
12179
|
-
`)
|
|
12180
|
-
retryTransient(() => fs10.writeFileSync(ignore, `*
|
|
12181
|
-
`));
|
|
12182
|
-
}
|
|
12183
|
-
this.writeTombstoneIfMissing();
|
|
12184
12449
|
}
|
|
12185
12450
|
lockOptions(lockPath) {
|
|
12186
12451
|
const inProcess = heldInProcess.has(lockPath);
|
|
@@ -12193,7 +12458,7 @@ class TaskReader {
|
|
|
12193
12458
|
shouldReclaim: ({ payload, nowMs }) => {
|
|
12194
12459
|
let ageMs = null;
|
|
12195
12460
|
try {
|
|
12196
|
-
ageMs = nowMs -
|
|
12461
|
+
ageMs = nowMs - fs11.lstatSync(lockPath).mtimeMs;
|
|
12197
12462
|
} catch {}
|
|
12198
12463
|
return classifyLockOwner(payload, ageMs, localLockHost(), TASK_STORE_LOCK).state === "stale";
|
|
12199
12464
|
},
|
|
@@ -12230,7 +12495,7 @@ class TaskReader {
|
|
|
12230
12495
|
withLock(lockPath, operation) {
|
|
12231
12496
|
try {
|
|
12232
12497
|
this.initializeStorage();
|
|
12233
|
-
|
|
12498
|
+
fs11.mkdirSync(path14.dirname(lockPath), { recursive: true });
|
|
12234
12499
|
} catch (error) {
|
|
12235
12500
|
return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
|
|
12236
12501
|
path: this.paths().dir
|
|
@@ -12270,18 +12535,18 @@ class TaskReader {
|
|
|
12270
12535
|
lockDirWritable(lockPath) {
|
|
12271
12536
|
const probe = `${lockPath}.${process.pid}.${randomUUID3()}.probe`;
|
|
12272
12537
|
try {
|
|
12273
|
-
|
|
12538
|
+
fs11.closeSync(fs11.openSync(probe, "wx", 384));
|
|
12274
12539
|
} catch {
|
|
12275
12540
|
return false;
|
|
12276
12541
|
}
|
|
12277
12542
|
try {
|
|
12278
|
-
|
|
12543
|
+
fs11.rmSync(probe, { force: true });
|
|
12279
12544
|
} catch {}
|
|
12280
12545
|
return true;
|
|
12281
12546
|
}
|
|
12282
12547
|
lockHolderPresent(lockPath) {
|
|
12283
12548
|
try {
|
|
12284
|
-
|
|
12549
|
+
fs11.lstatSync(lockPath);
|
|
12285
12550
|
return true;
|
|
12286
12551
|
} catch (error) {
|
|
12287
12552
|
return error?.code !== "ENOENT";
|
|
@@ -12293,12 +12558,12 @@ class TaskReader {
|
|
|
12293
12558
|
if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
|
|
12294
12559
|
return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
|
|
12295
12560
|
path: lockPath,
|
|
12296
|
-
guidance: `Check permissions and the read-only attribute on ${
|
|
12561
|
+
guidance: `Check permissions and the read-only attribute on ${path14.dirname(lockPath)}.`
|
|
12297
12562
|
});
|
|
12298
12563
|
if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
|
|
12299
12564
|
let lock = null;
|
|
12300
12565
|
try {
|
|
12301
|
-
lock = parseMetadataLockOrNull(
|
|
12566
|
+
lock = parseMetadataLockOrNull(fs11.readFileSync(lockPath, "utf8"));
|
|
12302
12567
|
} catch {}
|
|
12303
12568
|
return failure2("busy", `workit lock is held by another Workit call${lock ? ` (pid ${lock.pid} on ${lock.host})` : ""}; retry shortly`, {
|
|
12304
12569
|
outcome: "not_started",
|
|
@@ -12313,13 +12578,13 @@ class TaskReader {
|
|
|
12313
12578
|
|
|
12314
12579
|
// packages/workit-core/src/core/policy/derive.ts
|
|
12315
12580
|
import { existsSync as existsSync7 } from "node:fs";
|
|
12316
|
-
import
|
|
12581
|
+
import path18 from "node:path";
|
|
12317
12582
|
|
|
12318
12583
|
// packages/workit-core/src/ledger.ts
|
|
12319
12584
|
import { spawnSync as spawnSync11 } from "node:child_process";
|
|
12320
12585
|
import { createHash as createHash9, randomBytes as randomBytes3 } from "node:crypto";
|
|
12321
|
-
import
|
|
12322
|
-
import
|
|
12586
|
+
import fs13 from "node:fs";
|
|
12587
|
+
import path17 from "node:path";
|
|
12323
12588
|
|
|
12324
12589
|
// packages/workit-core/src/core/policy/bookkeeping.ts
|
|
12325
12590
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
@@ -12400,7 +12665,7 @@ function bookkeepingPaths(cwd, input) {
|
|
|
12400
12665
|
|
|
12401
12666
|
// packages/workit-core/src/core/policy/lane.ts
|
|
12402
12667
|
import { existsSync as existsSync6, readFileSync as readFileSync7 } from "node:fs";
|
|
12403
|
-
import
|
|
12668
|
+
import path15 from "node:path";
|
|
12404
12669
|
|
|
12405
12670
|
// packages/workit-core/src/git/default-base.ts
|
|
12406
12671
|
import { spawnSync as spawnSync10 } from "node:child_process";
|
|
@@ -13788,7 +14053,7 @@ function computeLane(input) {
|
|
|
13788
14053
|
}
|
|
13789
14054
|
function untrackedStat(cwd, file) {
|
|
13790
14055
|
try {
|
|
13791
|
-
const bytes = readFileSync7(
|
|
14056
|
+
const bytes = readFileSync7(path15.join(cwd, file));
|
|
13792
14057
|
if (bytes.includes(0))
|
|
13793
14058
|
return { path: file, added: 0, deleted: 0, binary: true };
|
|
13794
14059
|
const text = bytes.toString("utf8");
|
|
@@ -13820,7 +14085,7 @@ function cosmeticFiles(cwd, fork, head) {
|
|
|
13820
14085
|
let after = blobs.get(entry.newBlob);
|
|
13821
14086
|
if (!after && head === null && ABSENT.test(entry.newBlob))
|
|
13822
14087
|
try {
|
|
13823
|
-
after = readFileSync7(
|
|
14088
|
+
after = readFileSync7(path15.join(cwd, entry.path));
|
|
13824
14089
|
} catch {
|
|
13825
14090
|
after = undefined;
|
|
13826
14091
|
}
|
|
@@ -13976,13 +14241,13 @@ function verdictDrift(cwd, input) {
|
|
|
13976
14241
|
|
|
13977
14242
|
// packages/workit-core/src/host-session.ts
|
|
13978
14243
|
import { createHash as createHash8, randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
|
|
13979
|
-
import
|
|
13980
|
-
import
|
|
14244
|
+
import fs12 from "node:fs";
|
|
14245
|
+
import path16 from "node:path";
|
|
13981
14246
|
var ISSUED_PER_LEAD = 64;
|
|
13982
14247
|
var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/3";
|
|
13983
14248
|
var hash = (value) => createHash8("sha256").update(value).digest("hex").slice(0, 32);
|
|
13984
|
-
var userIssuedRoot = () =>
|
|
13985
|
-
var userTokenRoot = () =>
|
|
14249
|
+
var userIssuedRoot = () => path16.join(resolveStateDir(), "issued");
|
|
14250
|
+
var userTokenRoot = () => path16.join(resolveStateDir(), "issued-tokens");
|
|
13986
14251
|
function migrateRepoIssued(cwd) {
|
|
13987
14252
|
if (cwd === undefined)
|
|
13988
14253
|
return;
|
|
@@ -13991,27 +14256,27 @@ function migrateRepoIssued(cwd) {
|
|
|
13991
14256
|
const location = resolveStore(cwd);
|
|
13992
14257
|
if (location instanceof Error)
|
|
13993
14258
|
return;
|
|
13994
|
-
old =
|
|
13995
|
-
if (!
|
|
14259
|
+
old = path16.join(location.dir, "hooks", "issued");
|
|
14260
|
+
if (!fs12.existsSync(old))
|
|
13996
14261
|
return;
|
|
13997
14262
|
} catch {
|
|
13998
14263
|
return;
|
|
13999
14264
|
}
|
|
14000
14265
|
for (const lead of safeList(old)) {
|
|
14001
14266
|
try {
|
|
14002
|
-
const from =
|
|
14003
|
-
if (!
|
|
14267
|
+
const from = path16.join(old, lead);
|
|
14268
|
+
if (!fs12.statSync(from).isDirectory())
|
|
14004
14269
|
continue;
|
|
14005
|
-
const to =
|
|
14006
|
-
|
|
14007
|
-
for (const id of
|
|
14270
|
+
const to = path16.join(userIssuedRoot(), lead);
|
|
14271
|
+
fs12.mkdirSync(to, { recursive: true, mode: 448 });
|
|
14272
|
+
for (const id of fs12.readdirSync(from)) {
|
|
14008
14273
|
try {
|
|
14009
|
-
|
|
14274
|
+
fs12.copyFileSync(path16.join(from, id), path16.join(to, id), fs12.constants.COPYFILE_EXCL);
|
|
14010
14275
|
} catch (error) {
|
|
14011
14276
|
if (error.code !== "EEXIST")
|
|
14012
14277
|
throw error;
|
|
14013
14278
|
}
|
|
14014
|
-
|
|
14279
|
+
fs12.rmSync(path16.join(from, id), { force: true });
|
|
14015
14280
|
}
|
|
14016
14281
|
removeIfEmpty(from);
|
|
14017
14282
|
} catch {}
|
|
@@ -14020,14 +14285,14 @@ function migrateRepoIssued(cwd) {
|
|
|
14020
14285
|
}
|
|
14021
14286
|
var safeList = (dir) => {
|
|
14022
14287
|
try {
|
|
14023
|
-
return
|
|
14288
|
+
return fs12.readdirSync(dir);
|
|
14024
14289
|
} catch {
|
|
14025
14290
|
return [];
|
|
14026
14291
|
}
|
|
14027
14292
|
};
|
|
14028
14293
|
var removeIfEmpty = (dir) => {
|
|
14029
14294
|
try {
|
|
14030
|
-
|
|
14295
|
+
fs12.rmdirSync(dir);
|
|
14031
14296
|
} catch {}
|
|
14032
14297
|
};
|
|
14033
14298
|
var tokenHash = (token) => createHash8("sha256").update(token).digest("hex");
|
|
@@ -14036,13 +14301,13 @@ function recordIssuedSession(cwd, lead, issued) {
|
|
|
14036
14301
|
try {
|
|
14037
14302
|
migrateRepoIssued(cwd);
|
|
14038
14303
|
const own = hash(issued);
|
|
14039
|
-
const tokens =
|
|
14040
|
-
|
|
14041
|
-
|
|
14304
|
+
const tokens = path16.join(userTokenRoot(), hash(lead));
|
|
14305
|
+
fs12.mkdirSync(tokens, { recursive: true, mode: 448 });
|
|
14306
|
+
fs12.writeFileSync(path16.join(tokens, own), `${tokenHash(token)}
|
|
14042
14307
|
`, { mode: 384, flag: "wx" });
|
|
14043
|
-
const dir =
|
|
14044
|
-
|
|
14045
|
-
|
|
14308
|
+
const dir = path16.join(userIssuedRoot(), hash(lead));
|
|
14309
|
+
fs12.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
14310
|
+
fs12.writeFileSync(path16.join(dir, own), `${ISSUED_SESSIONS_MARKER}
|
|
14046
14311
|
`, { mode: 384 });
|
|
14047
14312
|
pruneIssued(dir, own, tokens);
|
|
14048
14313
|
return token;
|
|
@@ -14069,13 +14334,13 @@ function verdictCommand(options) {
|
|
|
14069
14334
|
}
|
|
14070
14335
|
function pruneIssued(dir, own, tokens) {
|
|
14071
14336
|
try {
|
|
14072
|
-
const entries =
|
|
14337
|
+
const entries = fs12.readdirSync(dir);
|
|
14073
14338
|
if (entries.length <= ISSUED_PER_LEAD)
|
|
14074
14339
|
return;
|
|
14075
|
-
const byAge = entries.filter((name) => name !== own).map((name) => ({ name, at:
|
|
14340
|
+
const byAge = entries.filter((name) => name !== own).map((name) => ({ name, at: fs12.statSync(path16.join(dir, name)).mtimeMs })).toSorted((a, b) => a.at - b.at);
|
|
14076
14341
|
for (const { name } of byAge.slice(0, entries.length - ISSUED_PER_LEAD)) {
|
|
14077
|
-
|
|
14078
|
-
|
|
14342
|
+
fs12.rmSync(path16.join(dir, name), { force: true });
|
|
14343
|
+
fs12.rmSync(path16.join(tokens, name), { force: true });
|
|
14079
14344
|
}
|
|
14080
14345
|
} catch {}
|
|
14081
14346
|
}
|
|
@@ -14085,7 +14350,7 @@ var issuedRecord = (cwd, claimed) => {
|
|
|
14085
14350
|
return null;
|
|
14086
14351
|
migrateRepoIssued(cwd);
|
|
14087
14352
|
try {
|
|
14088
|
-
return
|
|
14353
|
+
return fs12.readFileSync(path16.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
|
|
14089
14354
|
} catch {
|
|
14090
14355
|
return null;
|
|
14091
14356
|
}
|
|
@@ -14095,9 +14360,9 @@ var issuedToken = (claimed) => {
|
|
|
14095
14360
|
const cut = claimed.lastIndexOf(":");
|
|
14096
14361
|
if (cut <= 0)
|
|
14097
14362
|
return { stored: null, leadBound: false };
|
|
14098
|
-
const dir =
|
|
14363
|
+
const dir = path16.join(userTokenRoot(), hash(claimed.slice(0, cut)));
|
|
14099
14364
|
try {
|
|
14100
|
-
const text =
|
|
14365
|
+
const text = fs12.readFileSync(path16.join(dir, hash(claimed)), "utf8");
|
|
14101
14366
|
return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
|
|
14102
14367
|
} catch {
|
|
14103
14368
|
return { stored: null, leadBound: safeList(dir).length > 0 };
|
|
@@ -14224,14 +14489,14 @@ function cleanRebase(cwd, range) {
|
|
|
14224
14489
|
return Boolean(tree) && tree === git3(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
|
|
14225
14490
|
}
|
|
14226
14491
|
function storeRoot(cwd) {
|
|
14227
|
-
const location = resolveStore(
|
|
14492
|
+
const location = resolveStore(path17.resolve(cwd));
|
|
14228
14493
|
if (location instanceof Error)
|
|
14229
14494
|
return err("unavailable", location.message.replace(/; fix the repository.*$/u, ""), / does not exist /u.test(location.message) ? "run workit from a directory that exists" : "fix the repository (git status should work here) or run from a non-git directory");
|
|
14230
14495
|
return { ok: true, value: { root: location.dir, shared: location.shared } };
|
|
14231
14496
|
}
|
|
14232
14497
|
function ledgerPath(cwd) {
|
|
14233
14498
|
const root = storeRoot(cwd);
|
|
14234
|
-
return root.ok ? { ok: true, value:
|
|
14499
|
+
return root.ok ? { ok: true, value: path17.join(root.value.root, "ledger", "ledger.jsonl") } : root;
|
|
14235
14500
|
}
|
|
14236
14501
|
var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
|
|
14237
14502
|
var NETWORK_FS_TYPES = new Set([
|
|
@@ -14251,25 +14516,25 @@ var onNetworkFs = (dir) => {
|
|
|
14251
14516
|
if (process.platform !== "linux")
|
|
14252
14517
|
return false;
|
|
14253
14518
|
try {
|
|
14254
|
-
return isNetworkFsType(
|
|
14519
|
+
return isNetworkFsType(fs13.statfsSync(dir).type);
|
|
14255
14520
|
} catch {
|
|
14256
14521
|
return false;
|
|
14257
14522
|
}
|
|
14258
14523
|
};
|
|
14259
|
-
var
|
|
14260
|
-
var
|
|
14524
|
+
var LOCK_WAIT_MS2 = 5000;
|
|
14525
|
+
var LOCK_STALE_MS2 = 30000;
|
|
14261
14526
|
var LOCK_OWNER = "owner";
|
|
14262
14527
|
var lockToken = (lock) => {
|
|
14263
14528
|
try {
|
|
14264
|
-
return
|
|
14529
|
+
return fs13.readFileSync(path17.join(lock, LOCK_OWNER), "utf8");
|
|
14265
14530
|
} catch {
|
|
14266
14531
|
return null;
|
|
14267
14532
|
}
|
|
14268
14533
|
};
|
|
14269
14534
|
var lockAgeMs = (lock) => {
|
|
14270
|
-
for (const target of [
|
|
14535
|
+
for (const target of [path17.join(lock, LOCK_OWNER), lock]) {
|
|
14271
14536
|
try {
|
|
14272
|
-
return Date.now() -
|
|
14537
|
+
return Date.now() - fs13.statSync(target).mtimeMs;
|
|
14273
14538
|
} catch {}
|
|
14274
14539
|
}
|
|
14275
14540
|
return null;
|
|
@@ -14277,14 +14542,14 @@ var lockAgeMs = (lock) => {
|
|
|
14277
14542
|
var ledgerLock = {
|
|
14278
14543
|
acquire(lock) {
|
|
14279
14544
|
try {
|
|
14280
|
-
|
|
14545
|
+
fs13.mkdirSync(lock);
|
|
14281
14546
|
} catch (error) {
|
|
14282
14547
|
if (error.code === "EEXIST")
|
|
14283
14548
|
return null;
|
|
14284
14549
|
throw error;
|
|
14285
14550
|
}
|
|
14286
14551
|
const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
|
|
14287
|
-
|
|
14552
|
+
fs13.writeFileSync(path17.join(lock, LOCK_OWNER), token);
|
|
14288
14553
|
return token;
|
|
14289
14554
|
},
|
|
14290
14555
|
release(lock, token) {
|
|
@@ -14292,40 +14557,40 @@ var ledgerLock = {
|
|
|
14292
14557
|
return false;
|
|
14293
14558
|
const tomb = `${lock}.release-${randomBytes3(6).toString("hex")}`;
|
|
14294
14559
|
try {
|
|
14295
|
-
|
|
14560
|
+
fs13.renameSync(lock, tomb);
|
|
14296
14561
|
} catch {
|
|
14297
14562
|
return false;
|
|
14298
14563
|
}
|
|
14299
14564
|
if (lockToken(tomb) !== token) {
|
|
14300
14565
|
try {
|
|
14301
|
-
|
|
14566
|
+
fs13.renameSync(tomb, lock);
|
|
14302
14567
|
} catch {}
|
|
14303
14568
|
return false;
|
|
14304
14569
|
}
|
|
14305
|
-
|
|
14570
|
+
fs13.rmSync(tomb, { recursive: true, force: true });
|
|
14306
14571
|
return true;
|
|
14307
14572
|
},
|
|
14308
14573
|
token: lockToken,
|
|
14309
14574
|
reap(lock, observed) {
|
|
14310
14575
|
const tomb = `${lock}.reap-${randomBytes3(6).toString("hex")}`;
|
|
14311
14576
|
try {
|
|
14312
|
-
|
|
14577
|
+
fs13.renameSync(lock, tomb);
|
|
14313
14578
|
} catch {
|
|
14314
14579
|
return false;
|
|
14315
14580
|
}
|
|
14316
14581
|
if (lockToken(tomb) === observed) {
|
|
14317
|
-
|
|
14582
|
+
fs13.rmSync(tomb, { recursive: true, force: true });
|
|
14318
14583
|
return true;
|
|
14319
14584
|
}
|
|
14320
14585
|
try {
|
|
14321
|
-
|
|
14586
|
+
fs13.renameSync(tomb, lock);
|
|
14322
14587
|
} catch {
|
|
14323
|
-
|
|
14588
|
+
fs13.rmSync(tomb, { recursive: true, force: true });
|
|
14324
14589
|
}
|
|
14325
14590
|
return false;
|
|
14326
14591
|
}
|
|
14327
14592
|
};
|
|
14328
|
-
function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(
|
|
14593
|
+
function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2)) {
|
|
14329
14594
|
const lock = `${file}.lock`;
|
|
14330
14595
|
const deadline = Date.now() + waitMs;
|
|
14331
14596
|
let token = null;
|
|
@@ -14335,7 +14600,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
|
|
|
14335
14600
|
break;
|
|
14336
14601
|
const observed = lockToken(lock);
|
|
14337
14602
|
const age = lockAgeMs(lock);
|
|
14338
|
-
if (age !== null && age >
|
|
14603
|
+
if (age !== null && age > LOCK_STALE_MS2 && ledgerLock.reap(lock, observed))
|
|
14339
14604
|
continue;
|
|
14340
14605
|
if (Date.now() >= deadline)
|
|
14341
14606
|
return null;
|
|
@@ -14354,7 +14619,7 @@ var TAIL_BYTES = 64 * 1024;
|
|
|
14354
14619
|
var lastLine = (fd, size) => {
|
|
14355
14620
|
for (let span = Math.min(size, TAIL_BYTES);span > 0; span = Math.min(size, span * 2)) {
|
|
14356
14621
|
const buffer = Buffer.alloc(span);
|
|
14357
|
-
|
|
14622
|
+
fs13.readSync(fd, buffer, 0, span, size - span);
|
|
14358
14623
|
const end = buffer.lastIndexOf(10);
|
|
14359
14624
|
if (end < 0) {
|
|
14360
14625
|
if (span === size)
|
|
@@ -14385,32 +14650,32 @@ var lastLine = (fd, size) => {
|
|
|
14385
14650
|
};
|
|
14386
14651
|
var tighten = (fd) => {
|
|
14387
14652
|
try {
|
|
14388
|
-
if ((
|
|
14389
|
-
|
|
14653
|
+
if ((fs13.fstatSync(fd).mode & 63) !== 0)
|
|
14654
|
+
fs13.fchmodSync(fd, 384);
|
|
14390
14655
|
} catch {}
|
|
14391
14656
|
};
|
|
14392
14657
|
function appendLine(file, build, options) {
|
|
14393
14658
|
const write = () => {
|
|
14394
|
-
const fd =
|
|
14659
|
+
const fd = fs13.openSync(file, "a+", 384);
|
|
14395
14660
|
try {
|
|
14396
14661
|
if (process.platform !== "win32")
|
|
14397
14662
|
tighten(fd);
|
|
14398
|
-
const line = build(lastLine(fd,
|
|
14663
|
+
const line = build(lastLine(fd, fs13.fstatSync(fd).size));
|
|
14399
14664
|
if (!line.ok)
|
|
14400
14665
|
return line;
|
|
14401
14666
|
const bytes = Buffer.from(`
|
|
14402
14667
|
${line.value}`);
|
|
14403
|
-
const written =
|
|
14668
|
+
const written = fs13.writeSync(fd, bytes);
|
|
14404
14669
|
if (written !== bytes.length)
|
|
14405
14670
|
return err("unavailable", `short write to ${file}: ${written} of ${bytes.length} bytes; the row is torn and will be skipped`);
|
|
14406
14671
|
return { ok: true, value: undefined };
|
|
14407
14672
|
} finally {
|
|
14408
|
-
|
|
14673
|
+
fs13.closeSync(fd);
|
|
14409
14674
|
}
|
|
14410
14675
|
};
|
|
14411
14676
|
try {
|
|
14412
|
-
|
|
14413
|
-
if (options.heldLock || !options.forceLock && !onNetworkFs(
|
|
14677
|
+
fs13.mkdirSync(path17.dirname(file), { recursive: true });
|
|
14678
|
+
if (options.heldLock || !options.forceLock && !onNetworkFs(path17.dirname(file)))
|
|
14414
14679
|
return write();
|
|
14415
14680
|
const locked = withLedgerLock(file, write);
|
|
14416
14681
|
return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
|
|
@@ -14427,7 +14692,7 @@ var sealed = (row, id, at, previous) => {
|
|
|
14427
14692
|
` };
|
|
14428
14693
|
};
|
|
14429
14694
|
function appendRaw(cwd, row, options) {
|
|
14430
|
-
const file = options.store ? { ok: true, value:
|
|
14695
|
+
const file = options.store ? { ok: true, value: path17.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
|
|
14431
14696
|
if (!file.ok)
|
|
14432
14697
|
return file;
|
|
14433
14698
|
const id = newId2();
|
|
@@ -14477,8 +14742,8 @@ function readLedgerAt(cwd, file, options) {
|
|
|
14477
14742
|
let text = "";
|
|
14478
14743
|
let stat = null;
|
|
14479
14744
|
try {
|
|
14480
|
-
stat =
|
|
14481
|
-
text =
|
|
14745
|
+
stat = fs13.statSync(file);
|
|
14746
|
+
text = fs13.readFileSync(file, "utf8");
|
|
14482
14747
|
} catch (error) {
|
|
14483
14748
|
if (error.code === "ENOENT")
|
|
14484
14749
|
return {
|
|
@@ -14618,7 +14883,7 @@ function ledgerTampering(cwd) {
|
|
|
14618
14883
|
if (!file.ok)
|
|
14619
14884
|
return [];
|
|
14620
14885
|
try {
|
|
14621
|
-
const stat =
|
|
14886
|
+
const stat = fs13.statSync(file.value);
|
|
14622
14887
|
const cached = tamperCache.get(file.value);
|
|
14623
14888
|
if (cached && cached.size === stat.size && cached.stamp === fileStamp(stat))
|
|
14624
14889
|
return cached.breaks;
|
|
@@ -15085,8 +15350,8 @@ function remoteIdentity(cwd, hop = 0) {
|
|
|
15085
15350
|
return null;
|
|
15086
15351
|
if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
|
|
15087
15352
|
const local = raw.replace(/^file:\/\//u, "");
|
|
15088
|
-
const resolved =
|
|
15089
|
-
if (
|
|
15353
|
+
const resolved = path17.isAbsolute(local) ? local : path17.resolve(cwd, local);
|
|
15354
|
+
if (fs13.existsSync(resolved))
|
|
15090
15355
|
return remoteIdentity(resolved, 1);
|
|
15091
15356
|
}
|
|
15092
15357
|
const parsed = parseRemoteUrl(raw);
|
|
@@ -15107,7 +15372,7 @@ function verdictMirrorPath(cwd) {
|
|
|
15107
15372
|
if (!identity)
|
|
15108
15373
|
return null;
|
|
15109
15374
|
const key = createHash9("sha256").update(identity).digest("hex").slice(0, 32);
|
|
15110
|
-
return
|
|
15375
|
+
return path17.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
|
|
15111
15376
|
}
|
|
15112
15377
|
var importedStamp = new Map;
|
|
15113
15378
|
function importMirroredVerdicts(cwd, branch) {
|
|
@@ -15117,7 +15382,7 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
15117
15382
|
return [];
|
|
15118
15383
|
let stamp;
|
|
15119
15384
|
try {
|
|
15120
|
-
stamp = `${branch}\x00${fileStamp(
|
|
15385
|
+
stamp = `${branch}\x00${fileStamp(fs13.statSync(file))}`;
|
|
15121
15386
|
} catch {
|
|
15122
15387
|
return [];
|
|
15123
15388
|
}
|
|
@@ -15130,7 +15395,7 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
15130
15395
|
const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
|
|
15131
15396
|
const added = new Set;
|
|
15132
15397
|
try {
|
|
15133
|
-
|
|
15398
|
+
fs13.mkdirSync(path17.dirname(local.value), { recursive: true });
|
|
15134
15399
|
} catch {
|
|
15135
15400
|
return [];
|
|
15136
15401
|
}
|
|
@@ -15246,7 +15511,7 @@ var productDecision = (task, ledger) => {
|
|
|
15246
15511
|
};
|
|
15247
15512
|
};
|
|
15248
15513
|
var planRecorded = (task, root) => {
|
|
15249
|
-
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync7(
|
|
15514
|
+
const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync7(path18.resolve(root, ref.path)));
|
|
15250
15515
|
if (cited)
|
|
15251
15516
|
return {
|
|
15252
15517
|
met: true,
|
|
@@ -15324,14 +15589,14 @@ function writeBlockers(task, root) {
|
|
|
15324
15589
|
|
|
15325
15590
|
// packages/workit-core/src/core/task-evaluation.ts
|
|
15326
15591
|
var digestBytes = (value) => createHash10("sha256").update(value).digest("hex");
|
|
15327
|
-
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${
|
|
15328
|
-
var relative = (root, candidate) =>
|
|
15592
|
+
var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path19.sep}`);
|
|
15593
|
+
var relative = (root, candidate) => path19.relative(root, candidate).split(path19.sep).join("/") || ".";
|
|
15329
15594
|
var canonicalPath = (value) => {
|
|
15330
15595
|
if (typeof value !== "string" || !value)
|
|
15331
15596
|
return null;
|
|
15332
15597
|
if (value.includes("\\") || value.split("/").includes(".."))
|
|
15333
15598
|
return null;
|
|
15334
|
-
const normalized =
|
|
15599
|
+
const normalized = path19.posix.normalize(value);
|
|
15335
15600
|
if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
|
|
15336
15601
|
return null;
|
|
15337
15602
|
return normalized === "." ? "." : normalized.replace(/\/$/, "");
|
|
@@ -15379,21 +15644,21 @@ var gitPaths = (root) => {
|
|
|
15379
15644
|
git: !/not a git repository/i.test(stderr)
|
|
15380
15645
|
};
|
|
15381
15646
|
}
|
|
15382
|
-
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
15647
|
+
const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path19.sep).join("/")) : [];
|
|
15383
15648
|
const stagedDeleted = spawnSync12("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
|
|
15384
15649
|
if (stagedDeleted.status !== 0) {
|
|
15385
15650
|
const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
|
|
15386
15651
|
if (!/not a git repository/i.test(stderr))
|
|
15387
15652
|
return { paths, uncertain: true, git: true };
|
|
15388
15653
|
} else if (stagedDeleted.stdout) {
|
|
15389
|
-
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(
|
|
15654
|
+
paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path19.sep).join("/")));
|
|
15390
15655
|
}
|
|
15391
15656
|
return { paths: [...new Set(paths)], uncertain: false, git: true };
|
|
15392
15657
|
};
|
|
15393
15658
|
var walk = (root, directory, output) => {
|
|
15394
15659
|
let names;
|
|
15395
15660
|
try {
|
|
15396
|
-
names =
|
|
15661
|
+
names = fs14.readdirSync(directory);
|
|
15397
15662
|
} catch {
|
|
15398
15663
|
return true;
|
|
15399
15664
|
}
|
|
@@ -15401,10 +15666,10 @@ var walk = (root, directory, output) => {
|
|
|
15401
15666
|
for (const name of names) {
|
|
15402
15667
|
if (name === ".git" || name === ".workit")
|
|
15403
15668
|
continue;
|
|
15404
|
-
const target =
|
|
15669
|
+
const target = path19.join(directory, name);
|
|
15405
15670
|
let stat;
|
|
15406
15671
|
try {
|
|
15407
|
-
stat =
|
|
15672
|
+
stat = fs14.lstatSync(target);
|
|
15408
15673
|
} catch {
|
|
15409
15674
|
uncertain = true;
|
|
15410
15675
|
continue;
|
|
@@ -15419,14 +15684,14 @@ var walk = (root, directory, output) => {
|
|
|
15419
15684
|
var scopeRoots = (root, scope) => {
|
|
15420
15685
|
const roots = [];
|
|
15421
15686
|
for (const item of scope.paths.length ? scope.paths : ["."]) {
|
|
15422
|
-
const target =
|
|
15687
|
+
const target = path19.resolve(root, item);
|
|
15423
15688
|
if (!inside(root, target))
|
|
15424
15689
|
return failure2("invalid_input", `candidate scope escapes checkout: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`, { fields: [{ path: "scope.paths", reason: `${item} is outside the checkout` }] });
|
|
15425
15690
|
let ancestor = target;
|
|
15426
|
-
while (!
|
|
15427
|
-
ancestor =
|
|
15691
|
+
while (!fs14.existsSync(ancestor) && ancestor !== root)
|
|
15692
|
+
ancestor = path19.dirname(ancestor);
|
|
15428
15693
|
try {
|
|
15429
|
-
if (!inside(root,
|
|
15694
|
+
if (!inside(root, fs14.realpathSync(ancestor)))
|
|
15430
15695
|
return failure2("invalid_input", `candidate scope escapes checkout through a symlink: ${item} — keep one task per repository and coordinate a separate linked task in the other checkout`, { fields: [{ path: "scope.paths", reason: `${item} resolves outside the checkout` }] });
|
|
15431
15696
|
} catch {
|
|
15432
15697
|
return failure2("invalid_input", `candidate scope cannot be inspected: ${item}`);
|
|
@@ -15438,7 +15703,7 @@ var scopeRoots = (root, scope) => {
|
|
|
15438
15703
|
function captureCandidate(root, scope, environment = []) {
|
|
15439
15704
|
let checkout;
|
|
15440
15705
|
try {
|
|
15441
|
-
checkout =
|
|
15706
|
+
checkout = fs14.realpathSync(root);
|
|
15442
15707
|
} catch {
|
|
15443
15708
|
return failure2("invalid_input", "candidate root does not exist");
|
|
15444
15709
|
}
|
|
@@ -15456,11 +15721,11 @@ function captureCandidate(root, scope, environment = []) {
|
|
|
15456
15721
|
if (item === ".git" || item === ".workit")
|
|
15457
15722
|
continue;
|
|
15458
15723
|
names.add(item);
|
|
15459
|
-
if (!
|
|
15724
|
+
if (!fs14.existsSync(target))
|
|
15460
15725
|
continue;
|
|
15461
15726
|
let stat;
|
|
15462
15727
|
try {
|
|
15463
|
-
stat =
|
|
15728
|
+
stat = fs14.lstatSync(target);
|
|
15464
15729
|
} catch {
|
|
15465
15730
|
uncertain = true;
|
|
15466
15731
|
continue;
|
|
@@ -15476,17 +15741,17 @@ function captureCandidate(root, scope, environment = []) {
|
|
|
15476
15741
|
for (const item of [...names].toSorted()) {
|
|
15477
15742
|
if (!scopeMatches(item, normalizedScope))
|
|
15478
15743
|
continue;
|
|
15479
|
-
const target =
|
|
15744
|
+
const target = path19.join(checkout, item);
|
|
15480
15745
|
try {
|
|
15481
|
-
const stat =
|
|
15746
|
+
const stat = fs14.lstatSync(target);
|
|
15482
15747
|
if (stat.isSymbolicLink()) {
|
|
15483
|
-
const link =
|
|
15748
|
+
const link = fs14.readlinkSync(target);
|
|
15484
15749
|
files.push({ path: item, kind: "symlink", digest: digestBytes(link), executable: null });
|
|
15485
15750
|
} else if (stat.isFile()) {
|
|
15486
15751
|
files.push({
|
|
15487
15752
|
path: item,
|
|
15488
15753
|
kind: "file",
|
|
15489
|
-
digest: digestBytes(
|
|
15754
|
+
digest: digestBytes(fs14.readFileSync(target)),
|
|
15490
15755
|
executable: (stat.mode & 73) !== 0
|
|
15491
15756
|
});
|
|
15492
15757
|
} else if (!stat.isDirectory()) {
|
|
@@ -15636,7 +15901,7 @@ var scopeCovers2 = scopeCovers;
|
|
|
15636
15901
|
var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
15637
15902
|
let root;
|
|
15638
15903
|
try {
|
|
15639
|
-
root =
|
|
15904
|
+
root = fs14.realpathSync(checkoutRoot);
|
|
15640
15905
|
} catch {
|
|
15641
15906
|
return failure2("permission_denied", "checkout root is unavailable");
|
|
15642
15907
|
}
|
|
@@ -15645,23 +15910,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
|
15645
15910
|
continue;
|
|
15646
15911
|
if (!reference.digest)
|
|
15647
15912
|
return failure2("invalid_input", "document references require a byte digest");
|
|
15648
|
-
const target =
|
|
15649
|
-
if (target !== root && !target.startsWith(`${root}${
|
|
15913
|
+
const target = path19.resolve(root, reference.path);
|
|
15914
|
+
if (target !== root && !target.startsWith(`${root}${path19.sep}`))
|
|
15650
15915
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
15651
15916
|
fields: [
|
|
15652
15917
|
{ path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
|
|
15653
15918
|
]
|
|
15654
15919
|
});
|
|
15655
15920
|
try {
|
|
15656
|
-
const below =
|
|
15921
|
+
const below = path19.relative(root, target);
|
|
15657
15922
|
let current = root;
|
|
15658
|
-
for (const segment of below.split(
|
|
15923
|
+
for (const segment of below.split(path19.sep)) {
|
|
15659
15924
|
if (!segment)
|
|
15660
15925
|
continue;
|
|
15661
|
-
current =
|
|
15662
|
-
const stat =
|
|
15663
|
-
const real =
|
|
15664
|
-
if (real !== root && !real.startsWith(`${root}${
|
|
15926
|
+
current = path19.join(current, segment);
|
|
15927
|
+
const stat = fs14.lstatSync(current);
|
|
15928
|
+
const real = fs14.realpathSync(current);
|
|
15929
|
+
if (real !== root && !real.startsWith(`${root}${path19.sep}`))
|
|
15665
15930
|
return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
|
|
15666
15931
|
fields: [
|
|
15667
15932
|
{
|
|
@@ -15677,7 +15942,7 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
|
|
|
15677
15942
|
if (current !== target && !stat.isDirectory())
|
|
15678
15943
|
return failure2("invalid_input", "document reference ancestor is not a directory");
|
|
15679
15944
|
}
|
|
15680
|
-
if (digestBytes(
|
|
15945
|
+
if (digestBytes(fs14.readFileSync(target)) !== reference.digest)
|
|
15681
15946
|
return failure2("permission_denied", "decision document bytes have changed");
|
|
15682
15947
|
} catch {
|
|
15683
15948
|
return failure2("invalid_input", "decision document is unavailable");
|
|
@@ -16159,7 +16424,7 @@ function entryCompactContext(store, entry, session, context) {
|
|
|
16159
16424
|
current: () => recentSignal(store.root)
|
|
16160
16425
|
};
|
|
16161
16426
|
const observed = task?.data.evidence.some(isObservedCheck) ?? false;
|
|
16162
|
-
const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [
|
|
16427
|
+
const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [path20.resolve(store.root, ref.path)] : []));
|
|
16163
16428
|
const observedFiles = filesKey(files);
|
|
16164
16429
|
const compact = compactContext(store, context, entry?.id ?? null, freshness, origin && { origin: origin.origin, taskId: origin.entry.id });
|
|
16165
16430
|
if (!compact.ok || !compact.data)
|
|
@@ -16218,17 +16483,17 @@ ${options.addendum}` : ""}
|
|
|
16218
16483
|
</workit-contract>`;
|
|
16219
16484
|
};
|
|
16220
16485
|
var checkoutAt = (cwd) => {
|
|
16221
|
-
for (let dir =
|
|
16222
|
-
const dotGit =
|
|
16223
|
-
if (
|
|
16224
|
-
const admin =
|
|
16225
|
-
const head =
|
|
16486
|
+
for (let dir = path20.resolve(cwd);; dir = path20.dirname(dir)) {
|
|
16487
|
+
const dotGit = path20.join(dir, ".git");
|
|
16488
|
+
if (fs15.existsSync(dotGit)) {
|
|
16489
|
+
const admin = fs15.statSync(dotGit).isFile() ? path20.resolve(dir, /^gitdir:\s*(.+)$/mu.exec(fs15.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "") : dotGit;
|
|
16490
|
+
const head = fs15.readFileSync(path20.join(admin, "HEAD"), "utf8").trim();
|
|
16226
16491
|
return {
|
|
16227
16492
|
root: dir,
|
|
16228
16493
|
branch: /^ref: refs\/heads\/(.+)$/u.exec(head)?.[1] ?? null
|
|
16229
16494
|
};
|
|
16230
16495
|
}
|
|
16231
|
-
if (
|
|
16496
|
+
if (path20.dirname(dir) === dir)
|
|
16232
16497
|
return null;
|
|
16233
16498
|
}
|
|
16234
16499
|
};
|
|
@@ -16239,7 +16504,7 @@ var whereLine = (cwd) => {
|
|
|
16239
16504
|
return null;
|
|
16240
16505
|
const allowed = branchPolicySnapshotFor(cwd).namePolicy.allowed;
|
|
16241
16506
|
const kinds = allowed.some((pattern) => pattern.source === "^.*$") ? "any" : allowedKinds(allowed).join(", ") || "see `workit help git`";
|
|
16242
|
-
const place = checkout.root ===
|
|
16507
|
+
const place = checkout.root === path20.resolve(cwd) ? "" : ` in ${checkout.root}`;
|
|
16243
16508
|
return `cwd ${cwd}${place} on ${checkout.branch ?? "detached HEAD"}; branch kinds: ${kinds}`;
|
|
16244
16509
|
} catch {
|
|
16245
16510
|
return null;
|
|
@@ -16266,32 +16531,32 @@ var turnMarker = (input) => {
|
|
|
16266
16531
|
if (location instanceof Error)
|
|
16267
16532
|
return null;
|
|
16268
16533
|
const session = [input.host, input.session.id, input.session.agentId ?? ""].join("\x00");
|
|
16269
|
-
return
|
|
16534
|
+
return path20.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
|
|
16270
16535
|
} catch {
|
|
16271
16536
|
return null;
|
|
16272
16537
|
}
|
|
16273
16538
|
};
|
|
16274
16539
|
var writeTurnDigest = (file, digest) => {
|
|
16275
16540
|
try {
|
|
16276
|
-
|
|
16277
|
-
|
|
16541
|
+
fs15.mkdirSync(path20.dirname(file), { recursive: true });
|
|
16542
|
+
fs15.writeFileSync(file, `${JSON.stringify({ digest })}
|
|
16278
16543
|
`);
|
|
16279
16544
|
} catch {}
|
|
16280
16545
|
};
|
|
16281
16546
|
var clearTurnDigest = (file) => {
|
|
16282
16547
|
try {
|
|
16283
|
-
|
|
16548
|
+
fs15.rmSync(file, { force: true });
|
|
16284
16549
|
} catch {}
|
|
16285
16550
|
};
|
|
16286
16551
|
var pruneTurnDigests = (dir, now) => {
|
|
16287
16552
|
try {
|
|
16288
|
-
for (const name of
|
|
16553
|
+
for (const name of fs15.readdirSync(dir)) {
|
|
16289
16554
|
if (!name.startsWith("turn-"))
|
|
16290
16555
|
continue;
|
|
16291
|
-
const file =
|
|
16556
|
+
const file = path20.join(dir, name);
|
|
16292
16557
|
try {
|
|
16293
|
-
if (now -
|
|
16294
|
-
|
|
16558
|
+
if (now - fs15.statSync(file).mtimeMs > TURN_TTL_MS)
|
|
16559
|
+
fs15.rmSync(file, { force: true });
|
|
16295
16560
|
} catch {}
|
|
16296
16561
|
}
|
|
16297
16562
|
} catch {}
|
|
@@ -16307,7 +16572,7 @@ var changedTurnContext = (input, text) => {
|
|
|
16307
16572
|
return text;
|
|
16308
16573
|
const digest = digestOf(text);
|
|
16309
16574
|
try {
|
|
16310
|
-
const previous = JSON.parse(
|
|
16575
|
+
const previous = JSON.parse(fs15.readFileSync(file, "utf8"));
|
|
16311
16576
|
if (previous.digest === digest)
|
|
16312
16577
|
return null;
|
|
16313
16578
|
} catch {}
|
|
@@ -16318,7 +16583,7 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
|
|
|
16318
16583
|
const file = turnMarker(input);
|
|
16319
16584
|
if (!file)
|
|
16320
16585
|
return;
|
|
16321
|
-
pruneTurnDigests(
|
|
16586
|
+
pruneTurnDigests(path20.dirname(file), Date.now());
|
|
16322
16587
|
if (text)
|
|
16323
16588
|
writeTurnDigest(file, digestOf(text));
|
|
16324
16589
|
else
|
|
@@ -16327,36 +16592,36 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
|
|
|
16327
16592
|
// packages/workit-core/src/core/route-intent.ts
|
|
16328
16593
|
import { spawnSync as spawnSync14 } from "node:child_process";
|
|
16329
16594
|
import { existsSync as existsSync11 } from "node:fs";
|
|
16330
|
-
import
|
|
16595
|
+
import path26 from "node:path";
|
|
16331
16596
|
|
|
16332
16597
|
// packages/workit-core/src/hooks/raw-git.ts
|
|
16333
16598
|
import { spawnSync as spawnSync13 } from "node:child_process";
|
|
16334
16599
|
import { createHash as createHash14 } from "node:crypto";
|
|
16335
|
-
import
|
|
16336
|
-
import
|
|
16337
|
-
import
|
|
16600
|
+
import fs17 from "node:fs";
|
|
16601
|
+
import os6 from "node:os";
|
|
16602
|
+
import path25 from "node:path";
|
|
16338
16603
|
|
|
16339
16604
|
// packages/workit-core/src/autonomy.ts
|
|
16340
16605
|
import { closeSync as closeSync2, copyFileSync, existsSync as existsSync10, openSync as openSync2 } from "node:fs";
|
|
16341
|
-
import
|
|
16606
|
+
import path23 from "node:path";
|
|
16342
16607
|
|
|
16343
16608
|
// packages/workit-core/src/core/eval-world.ts
|
|
16344
16609
|
import { existsSync as existsSync9, realpathSync as realpathSync7 } from "node:fs";
|
|
16345
|
-
import
|
|
16346
|
-
import
|
|
16610
|
+
import os5 from "node:os";
|
|
16611
|
+
import path21 from "node:path";
|
|
16347
16612
|
var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
|
|
16348
16613
|
var EVAL_WORLD_MARKER = ".workit-eval-world";
|
|
16349
16614
|
var inside2 = (dir, file) => {
|
|
16350
|
-
const rel =
|
|
16351
|
-
return !rel.startsWith("..") && !
|
|
16615
|
+
const rel = path21.relative(dir, file);
|
|
16616
|
+
return !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
16352
16617
|
};
|
|
16353
16618
|
var evalWorld = (cwd) => {
|
|
16354
16619
|
const raw = process.env[EVAL_WORLD_ENV];
|
|
16355
|
-
if (!raw || !
|
|
16620
|
+
if (!raw || !path21.isAbsolute(raw))
|
|
16356
16621
|
return null;
|
|
16357
16622
|
try {
|
|
16358
16623
|
const world = realpathSync7(raw);
|
|
16359
|
-
return inside2(realpathSync7(
|
|
16624
|
+
return inside2(realpathSync7(os5.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync9(path21.join(world, EVAL_WORLD_MARKER)) ? world : null;
|
|
16360
16625
|
} catch {
|
|
16361
16626
|
return null;
|
|
16362
16627
|
}
|
|
@@ -16364,7 +16629,7 @@ var evalWorld = (cwd) => {
|
|
|
16364
16629
|
var evalWorldEntry = (cwd) => {
|
|
16365
16630
|
const world = evalWorld(cwd);
|
|
16366
16631
|
try {
|
|
16367
|
-
return world ? loadWorkspacesFrom(
|
|
16632
|
+
return world ? loadWorkspacesFrom(path21.join(world, "config"))[0] ?? null : null;
|
|
16368
16633
|
} catch {
|
|
16369
16634
|
return null;
|
|
16370
16635
|
}
|
|
@@ -16373,7 +16638,7 @@ var evalWorldEntry = (cwd) => {
|
|
|
16373
16638
|
// packages/workit-core/src/core/grant-seal.ts
|
|
16374
16639
|
import { createHash as createHash12 } from "node:crypto";
|
|
16375
16640
|
import { readFileSync as readFileSync9 } from "node:fs";
|
|
16376
|
-
import
|
|
16641
|
+
import path22 from "node:path";
|
|
16377
16642
|
var SEAL_FILE = "workspaces.json.seal";
|
|
16378
16643
|
var SEAL_VERSION = 1;
|
|
16379
16644
|
var SEAL_COMMAND = "workit workspace seal";
|
|
@@ -16407,15 +16672,15 @@ var sealProjection = (entries) => entries.map((entry) => {
|
|
|
16407
16672
|
youtrack: pick2(all.youtrack, ["writes", "autoHosts"])
|
|
16408
16673
|
}, ENTRY_KEYS);
|
|
16409
16674
|
});
|
|
16410
|
-
var
|
|
16411
|
-
var sealDigest = (projection) => createHash12("sha256").update(
|
|
16675
|
+
var canonical4 = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : item);
|
|
16676
|
+
var sealDigest = (projection) => createHash12("sha256").update(canonical4(projection)).digest("hex");
|
|
16412
16677
|
var broken = (reason, sealed = null) => ({
|
|
16413
16678
|
state: "broken",
|
|
16414
16679
|
reason,
|
|
16415
16680
|
sealed
|
|
16416
16681
|
});
|
|
16417
16682
|
function checkSeal(dir) {
|
|
16418
|
-
const file =
|
|
16683
|
+
const file = path22.join(dir, SEAL_FILE);
|
|
16419
16684
|
let seal;
|
|
16420
16685
|
try {
|
|
16421
16686
|
seal = JSON.parse(readFileSync9(file, "utf8"));
|
|
@@ -16473,7 +16738,7 @@ var accountHomeDir = () => {
|
|
|
16473
16738
|
};
|
|
16474
16739
|
var deniedFile = (dir) => {
|
|
16475
16740
|
for (const name of ["workspaces.json", SEAL_FILE]) {
|
|
16476
|
-
const file =
|
|
16741
|
+
const file = path23.join(dir, name);
|
|
16477
16742
|
try {
|
|
16478
16743
|
closeSync2(openSync2(file, "r"));
|
|
16479
16744
|
} catch (error) {
|
|
@@ -16495,7 +16760,7 @@ var accountUnread = () => {
|
|
|
16495
16760
|
if (dir === null)
|
|
16496
16761
|
return NO_ACCOUNT;
|
|
16497
16762
|
const file = deniedFile(dir);
|
|
16498
|
-
return file === null ? null : `the account's ${
|
|
16763
|
+
return file === null ? null : `the account's ${path23.basename(file)} cannot be read (permission denied), so it reads as no workspace entries: no grants, no models, the D4 defaults apply`;
|
|
16499
16764
|
};
|
|
16500
16765
|
var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
|
|
16501
16766
|
var fileSource = (dir = accountDir()) => ({
|
|
@@ -16544,10 +16809,10 @@ var youTrackWritesPolicy = (cwd) => {
|
|
|
16544
16809
|
return ASK;
|
|
16545
16810
|
}
|
|
16546
16811
|
};
|
|
16547
|
-
var redirected = (dir) =>
|
|
16812
|
+
var redirected = (dir) => path23.resolve(resolveConfigDir()) !== path23.resolve(dir);
|
|
16548
16813
|
var shownGrantsDir = () => {
|
|
16549
16814
|
const world = evalWorld(process.cwd());
|
|
16550
|
-
return world ?
|
|
16815
|
+
return world ? path23.join(world, "config") : accountDir();
|
|
16551
16816
|
};
|
|
16552
16817
|
var benchWorld = (cwd) => {
|
|
16553
16818
|
const entry = evalWorldEntry(cwd);
|
|
@@ -16571,10 +16836,10 @@ var grantsOverride = () => {
|
|
|
16571
16836
|
const shown = shownGrantsDir();
|
|
16572
16837
|
if (shown === null)
|
|
16573
16838
|
return accountUnread() ?? NO_ACCOUNT;
|
|
16574
|
-
const configured =
|
|
16575
|
-
return configured ===
|
|
16839
|
+
const configured = path23.resolve(resolveConfigDir());
|
|
16840
|
+
return configured === path23.resolve(shown) ? null : `the config directory is redirected to ${configured} (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), but that override does not apply to grants: grants are read only from ${path23.join(grantsDir(), "workspaces.json")}, and under a redirect they never exceed the D4 defaults`;
|
|
16576
16841
|
};
|
|
16577
|
-
var redirectUnblock = () => `ask the user: grants above the D4 defaults apply only without a config redirect (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), and are read from ${
|
|
16842
|
+
var redirectUnblock = () => `ask the user: grants above the D4 defaults apply only without a config redirect (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), and are read from ${path23.join(grantsDir(), "workspaces.json")}`;
|
|
16578
16843
|
var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
|
|
16579
16844
|
var DEFAULT_GRANTS = Object.freeze({
|
|
16580
16845
|
push: true,
|
|
@@ -16982,8 +17247,8 @@ var packageTagShapes = (packages) => packages.map((entry) => `${entry.tagNamespa
|
|
|
16982
17247
|
|
|
16983
17248
|
// packages/workit-core/src/hooks/session-marker.ts
|
|
16984
17249
|
import { createHash as createHash13 } from "node:crypto";
|
|
16985
|
-
import
|
|
16986
|
-
import
|
|
17250
|
+
import fs16 from "node:fs";
|
|
17251
|
+
import path24 from "node:path";
|
|
16987
17252
|
var sessionMarkerFile = (input, session, store) => {
|
|
16988
17253
|
let dir = store;
|
|
16989
17254
|
if (dir === undefined) {
|
|
@@ -16993,7 +17258,7 @@ var sessionMarkerFile = (input, session, store) => {
|
|
|
16993
17258
|
dir = location.dir;
|
|
16994
17259
|
}
|
|
16995
17260
|
const name = createHash13("sha256").update(`${input.host}\x00${session}`).digest("hex").slice(0, 32);
|
|
16996
|
-
return
|
|
17261
|
+
return path24.join(dir, "hooks", `skills-${name}.json`);
|
|
16997
17262
|
};
|
|
16998
17263
|
var list = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
16999
17264
|
var EMPTY = {
|
|
@@ -17006,7 +17271,7 @@ var EMPTY = {
|
|
|
17006
17271
|
};
|
|
17007
17272
|
var readRaw = (file) => {
|
|
17008
17273
|
try {
|
|
17009
|
-
return
|
|
17274
|
+
return fs16.readFileSync(file, "utf8");
|
|
17010
17275
|
} catch {
|
|
17011
17276
|
return "";
|
|
17012
17277
|
}
|
|
@@ -17028,13 +17293,13 @@ var parseMarker = (text) => {
|
|
|
17028
17293
|
};
|
|
17029
17294
|
var readSessionMarker = (file) => parseMarker(readRaw(file));
|
|
17030
17295
|
var writeAtomic = (file, marker) => {
|
|
17031
|
-
|
|
17296
|
+
fs16.mkdirSync(path24.dirname(file), { recursive: true });
|
|
17032
17297
|
const temp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
17033
17298
|
try {
|
|
17034
|
-
|
|
17035
|
-
|
|
17299
|
+
fs16.writeFileSync(temp, JSON.stringify(marker));
|
|
17300
|
+
fs16.renameSync(temp, file);
|
|
17036
17301
|
} catch (error) {
|
|
17037
|
-
|
|
17302
|
+
fs16.rmSync(temp, { force: true });
|
|
17038
17303
|
throw error;
|
|
17039
17304
|
}
|
|
17040
17305
|
};
|
|
@@ -17616,14 +17881,14 @@ var GIT_CONFIG_ENV = /^(?:GIT_(?:CONFIG\w*|DIR|COMMON_DIR|WORK_TREE|SSH|SSH_COMM
|
|
|
17616
17881
|
var ASSIGNMENT2 = /^([A-Za-z_]\w*)=([\s\S]*)$/;
|
|
17617
17882
|
var MAX_DEPTH = 4;
|
|
17618
17883
|
var MAX_EXPANSIONS = 16;
|
|
17619
|
-
var isAbsolute = (value) =>
|
|
17884
|
+
var isAbsolute = (value) => path25.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
|
|
17620
17885
|
var HERE = /^(?:\$PWD|\$\{PWD\}|\$\(\s*pwd\s*\)|`pwd`|\$\(\s*git\s+rev-parse\s+--show-toplevel\s*\))(?=$|[\\/])/;
|
|
17621
17886
|
var joinDir = (base, raw) => {
|
|
17622
17887
|
const next = raw.replace(HERE, ".");
|
|
17623
17888
|
if (base === undefined || /[$`*?]/.test(next) || next === "-")
|
|
17624
17889
|
return;
|
|
17625
|
-
const expanded = next === "~" || next.startsWith("~/") ?
|
|
17626
|
-
return base === null || isAbsolute(expanded) ? expanded :
|
|
17890
|
+
const expanded = next === "~" || next.startsWith("~/") ? path25.join(os6.homedir(), next.slice(1)) : next;
|
|
17891
|
+
return base === null || isAbsolute(expanded) ? expanded : path25.join(base, expanded);
|
|
17627
17892
|
};
|
|
17628
17893
|
var rebase = (base, inner) => inner === null ? base : inner === undefined ? undefined : joinDir(base, inner);
|
|
17629
17894
|
var cdTarget = (words) => {
|
|
@@ -18024,7 +18289,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
|
|
|
18024
18289
|
}
|
|
18025
18290
|
if (CD.has(name)) {
|
|
18026
18291
|
const target = cdTarget(words);
|
|
18027
|
-
dir = target === null ?
|
|
18292
|
+
dir = target === null ? os6.homedir() : joinDir(dir, target);
|
|
18028
18293
|
} else if (PUSHD.has(name)) {
|
|
18029
18294
|
const target = cdTarget(words);
|
|
18030
18295
|
stack.push(dir);
|
|
@@ -18524,7 +18789,7 @@ var repoAt = (dir) => {
|
|
|
18524
18789
|
return { location, dir, branch: resolveTaskKey(dir, location).branch };
|
|
18525
18790
|
};
|
|
18526
18791
|
var isWorkitWorkspace = (repo) => {
|
|
18527
|
-
if (
|
|
18792
|
+
if (fs17.existsSync(repo.location.dir))
|
|
18528
18793
|
return true;
|
|
18529
18794
|
try {
|
|
18530
18795
|
return resolveRuntimeWorkspaceVcs(repo.location.top ?? repo.dir) !== null;
|
|
@@ -18545,17 +18810,17 @@ var headSha2 = (repo) => {
|
|
|
18545
18810
|
if (!git || git.reftable)
|
|
18546
18811
|
return null;
|
|
18547
18812
|
try {
|
|
18548
|
-
const head =
|
|
18813
|
+
const head = fs17.readFileSync(path25.join(git.gitDir, "HEAD"), "utf8").trim();
|
|
18549
18814
|
if (/^[0-9a-f]{40,64}$/.test(head))
|
|
18550
18815
|
return head;
|
|
18551
18816
|
const ref = /^ref: (refs\/.+)$/.exec(head)?.[1];
|
|
18552
18817
|
if (!ref)
|
|
18553
18818
|
return null;
|
|
18554
|
-
const common =
|
|
18819
|
+
const common = path25.dirname(repo.location.dir);
|
|
18555
18820
|
try {
|
|
18556
|
-
return
|
|
18821
|
+
return fs17.readFileSync(path25.join(common, ref), "utf8").trim() || null;
|
|
18557
18822
|
} catch {}
|
|
18558
|
-
const packed =
|
|
18823
|
+
const packed = fs17.readFileSync(path25.join(common, "packed-refs"), "utf8");
|
|
18559
18824
|
return new RegExp(`^([0-9a-f]{40,64}) ${ref.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`, "m").exec(packed)?.[1] ?? null;
|
|
18560
18825
|
} catch {
|
|
18561
18826
|
return null;
|
|
@@ -18648,8 +18913,8 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
|
|
|
18648
18913
|
const sub = invocation.args[0];
|
|
18649
18914
|
if (invocation.tool !== "git" || invocation.dir === undefined || !sub || sub.startsWith("-") || GIT_COMMANDS.has(sub) || depth >= MAX_DEPTH)
|
|
18650
18915
|
return [invocation];
|
|
18651
|
-
const dir =
|
|
18652
|
-
if (!
|
|
18916
|
+
const dir = path25.resolve(root, invocation.dir ?? ".");
|
|
18917
|
+
if (!fs17.existsSync(dir))
|
|
18653
18918
|
return [invocation];
|
|
18654
18919
|
const config = gitConfig(dir, invocation, cache);
|
|
18655
18920
|
const alias = configValue(config, `alias.${sub.toLowerCase()}`);
|
|
@@ -18671,34 +18936,42 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
|
|
|
18671
18936
|
var normalizedUrl = (url, dir) => {
|
|
18672
18937
|
const trimmed = url.trim();
|
|
18673
18938
|
if (/^file:\/\//i.test(trimmed))
|
|
18674
|
-
return
|
|
18939
|
+
return path25.resolve(dir, trimmed.slice(7)).replace(/\/+$/, "").replace(/\.git$/, "");
|
|
18675
18940
|
const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(trimmed);
|
|
18676
18941
|
const scp = !scheme && /^(?:[^@/\\]+@)?[^/\\:]{2,}:/.test(trimmed);
|
|
18677
18942
|
if (!scheme && !scp)
|
|
18678
|
-
return
|
|
18943
|
+
return path25.resolve(dir, trimmed).replace(/\/+$/, "").replace(/\.git$/, "");
|
|
18679
18944
|
const value = scheme ? trimmed.slice(scheme[0].length).replace(/^[^@/]*@/, "").replace(/^([^/:]+):\d+(?=\/)/, "$1") : trimmed.replace(/^[^@/]*@/, "").replace(":", "/");
|
|
18680
18945
|
return value.toLowerCase().replace(/\/{2,}/g, "/").replace(/^www\./, "").replace(/\/+$/, "").replace(/\.git$/, "");
|
|
18681
18946
|
};
|
|
18682
|
-
var
|
|
18683
|
-
|
|
18684
|
-
|
|
18685
|
-
|
|
18686
|
-
|
|
18687
|
-
|
|
18688
|
-
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
best = { base, prefix };
|
|
18692
|
-
}
|
|
18693
|
-
if (best)
|
|
18694
|
-
return best.base + url.slice(best.prefix.length);
|
|
18947
|
+
var rewrite = (url, config, kind) => {
|
|
18948
|
+
let best = null;
|
|
18949
|
+
for (const [key, prefixes] of config) {
|
|
18950
|
+
if (!key.startsWith("url.") || !key.endsWith(`.${kind}`))
|
|
18951
|
+
continue;
|
|
18952
|
+
const base = key.slice(4, -(kind.length + 1));
|
|
18953
|
+
for (const prefix of prefixes)
|
|
18954
|
+
if (url.startsWith(prefix) && prefix.length > (best?.prefix.length ?? -1))
|
|
18955
|
+
best = { base, prefix };
|
|
18695
18956
|
}
|
|
18696
|
-
return url;
|
|
18957
|
+
return best ? best.base + url.slice(best.prefix.length) : null;
|
|
18697
18958
|
};
|
|
18698
|
-
var
|
|
18699
|
-
|
|
18700
|
-
|
|
18959
|
+
var rewrittenUrl = (url, config) => rewrite(url, config, "pushinsteadof") ?? rewrite(url, config, "insteadof") ?? url;
|
|
18960
|
+
var pushUrlsOf = (config, remote) => {
|
|
18961
|
+
const pushurls = config.get(`remote.${remote}.pushurl`) ?? [];
|
|
18962
|
+
if (pushurls.length)
|
|
18963
|
+
return pushurls.map((url) => rewrite(url, config, "insteadof") ?? url);
|
|
18964
|
+
const urls = config.get(`remote.${remote}.url`) ?? [remote];
|
|
18965
|
+
const aliased = urls.flatMap((url) => rewrite(url, config, "pushinsteadof") ?? []);
|
|
18966
|
+
return aliased.length ? aliased : urls.map((url) => rewrite(url, config, "insteadof") ?? url);
|
|
18701
18967
|
};
|
|
18968
|
+
var singlePushUrl = (config, remote) => {
|
|
18969
|
+
if (!config.has(`remote.${remote}.url`) && !config.has(`remote.${remote}.pushurl`))
|
|
18970
|
+
return null;
|
|
18971
|
+
const urls = pushUrlsOf(config, remote);
|
|
18972
|
+
return urls.length === 1 ? urls[0] : null;
|
|
18973
|
+
};
|
|
18974
|
+
var pushUrl = (config, remote, dir) => normalizedUrl(pushUrlsOf(config, remote).at(-1) ?? remote, dir);
|
|
18702
18975
|
var pushRemoteOf = (config, branch) => {
|
|
18703
18976
|
const remotes = new Set;
|
|
18704
18977
|
for (const key of config.keys()) {
|
|
@@ -18908,7 +19181,7 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
|
|
|
18908
19181
|
const out = [];
|
|
18909
19182
|
const repos = new Map;
|
|
18910
19183
|
const repoFor = (relative) => {
|
|
18911
|
-
const dir =
|
|
19184
|
+
const dir = path25.resolve(cwd, relative ?? ".");
|
|
18912
19185
|
if (!repos.has(dir)) {
|
|
18913
19186
|
const repo = repoAt(dir);
|
|
18914
19187
|
const workit = repo !== null && isWorkitWorkspace(repo);
|
|
@@ -18929,7 +19202,7 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
|
|
|
18929
19202
|
const action = rawAction(invocation);
|
|
18930
19203
|
const at = !action ? null : repoFor(invocation.dir) ?? (all && invocation.tool !== "git" && explicitRepo(invocation.tool === "gh", "repo" in action && action.repo || "", invocation.env ?? {}) ? {
|
|
18931
19204
|
repo: {
|
|
18932
|
-
dir:
|
|
19205
|
+
dir: path25.resolve(cwd, invocation.dir ?? "."),
|
|
18933
19206
|
branch: null
|
|
18934
19207
|
},
|
|
18935
19208
|
workit: false
|
|
@@ -19002,13 +19275,13 @@ var messageOf = (segment, index) => {
|
|
|
19002
19275
|
};
|
|
19003
19276
|
var sameGitDir = (a, b, platform = process.platform) => {
|
|
19004
19277
|
if (platform !== "win32")
|
|
19005
|
-
return
|
|
19006
|
-
const fold = (value) =>
|
|
19278
|
+
return path25.posix.resolve(a) === path25.posix.resolve(b);
|
|
19279
|
+
const fold = (value) => path25.win32.resolve(value).toLowerCase();
|
|
19007
19280
|
return fold(a) === fold(b);
|
|
19008
19281
|
};
|
|
19009
19282
|
var cdCommitCall = (input, command, target, repo) => {
|
|
19010
19283
|
const { top, git, dir: store } = repo.location;
|
|
19011
|
-
if (!top || !git || sameGitDir(git.gitDir,
|
|
19284
|
+
if (!top || !git || sameGitDir(git.gitDir, path25.dirname(store)) || repoAt(input.cwd)?.location.top === top)
|
|
19012
19285
|
return null;
|
|
19013
19286
|
const bare = command.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"/gu, "").replaceAll("&&", "");
|
|
19014
19287
|
if (/[;|&<>`$()\n\\]/u.test(bare))
|
|
@@ -19017,7 +19290,7 @@ var cdCommitCall = (input, command, target, repo) => {
|
|
|
19017
19290
|
const commit = rest.at(-1);
|
|
19018
19291
|
if (cd?.words[0] !== "cd" || cd.words.length !== 2 || cd.expands?.length || !commit)
|
|
19019
19292
|
return null;
|
|
19020
|
-
if (
|
|
19293
|
+
if (path25.resolve(input.cwd, cd.words[1]) !== target)
|
|
19021
19294
|
return null;
|
|
19022
19295
|
if (rest.some((each) => each.redirects.length || each.stdin?.length || each.group))
|
|
19023
19296
|
return null;
|
|
@@ -19084,7 +19357,7 @@ var commitRefusal = (input, command, dialect, { action, repo, invocation, workit
|
|
|
19084
19357
|
} catch {}
|
|
19085
19358
|
if (guarded && !switches)
|
|
19086
19359
|
return `workit: raw ${quote("git commit")} on ${repo.branch}, a protected branch. Branch first: ${quote("workit git branch --kind feature --slug <slug>")} (uncommitted changes come along), then ${quote("workit git commit -m '<msg>' -- <paths>")}.`;
|
|
19087
|
-
const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command,
|
|
19360
|
+
const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path25.resolve(input.cwd, invocation.dir), repo);
|
|
19088
19361
|
return call && `workit: no ${quote("cd … &&")} chain; run ${quote(call)}.`;
|
|
19089
19362
|
};
|
|
19090
19363
|
function rawGitPre(input, command, options = {}) {
|
|
@@ -19143,20 +19416,18 @@ var forgeRepo = (gh, named, env, config, branch, dir) => {
|
|
|
19143
19416
|
const hosted = gh ? parts.length > 2 : parts.length > 2 && parts[0].includes(".");
|
|
19144
19417
|
let url = /:\/\/|@/.test(repo) ? repo : parts.length > 1 ? `https://${hosted ? "" : `${host}/`}${repo}` : "";
|
|
19145
19418
|
if (!repo) {
|
|
19146
|
-
const
|
|
19147
|
-
|
|
19419
|
+
const pushHost = pushHostOf(config, pushRemoteOf(config, branch) ?? "origin");
|
|
19420
|
+
const remote = (gh ? ghDefaultOf(config, pushHost, dir, env) : null) ?? ["upstream", "origin"].find((name) => config.has(`remote.${name}.url`) && (name === "origin" || pushHost === null || pushHostOf(config, name) === pushHost));
|
|
19421
|
+
url = remote ? pushUrlsOf(config, remote).at(-1) ?? "" : "";
|
|
19148
19422
|
}
|
|
19149
19423
|
const key = remoteKey(url);
|
|
19150
19424
|
return key ? { remotes: [{ name: "forge", url, key }] } : Error("its repository is unknown");
|
|
19151
19425
|
};
|
|
19152
19426
|
var pushHostOf = (config, remote) => {
|
|
19153
|
-
const
|
|
19154
|
-
|
|
19155
|
-
return null;
|
|
19156
|
-
return remoteKey(rewrittenUrl(urls[0], config))?.split("/")[0] ?? null;
|
|
19427
|
+
const url = singlePushUrl(config, remote);
|
|
19428
|
+
return url === null ? null : remoteKey(url)?.split("/")[0] ?? null;
|
|
19157
19429
|
};
|
|
19158
|
-
var ghDefaultOf = (config,
|
|
19159
|
-
const pushHost = pushHostOf(config, pushRemoteOf(config, branch) ?? "origin");
|
|
19430
|
+
var ghDefaultOf = (config, pushHost, dir, env) => {
|
|
19160
19431
|
for (const [key, value] of localGhResolved(dir, env)) {
|
|
19161
19432
|
const name = key.slice(7, -12);
|
|
19162
19433
|
if (!name || value !== "base")
|
|
@@ -19215,9 +19486,9 @@ var grantRefusal = (action, repo, invocation, cache) => {
|
|
|
19215
19486
|
return null;
|
|
19216
19487
|
};
|
|
19217
19488
|
var localTag = (repo, name) => {
|
|
19218
|
-
const common =
|
|
19489
|
+
const common = path25.dirname(repo.location.dir);
|
|
19219
19490
|
try {
|
|
19220
|
-
return
|
|
19491
|
+
return fs17.existsSync(path25.join(common, "refs/tags", name)) || fs17.readFileSync(path25.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
|
|
19221
19492
|
`);
|
|
19222
19493
|
} catch {
|
|
19223
19494
|
return false;
|
|
@@ -19237,7 +19508,7 @@ var analysisDenial = (error) => ({
|
|
|
19237
19508
|
});
|
|
19238
19509
|
var NEXT_COMMAND = "next";
|
|
19239
19510
|
var MARKER_TTL_SECONDS = 3600;
|
|
19240
|
-
var markerFile = (repo, session, key) =>
|
|
19511
|
+
var markerFile = (repo, session, key) => path25.join(repo.location.dir, "hooks", `commit-${createHash14("sha256").update(`${session}\x00${key}`).digest("hex").slice(0, 32)}.json`);
|
|
19241
19512
|
var callKey = (toolUseId, command) => toolUseId ?? `cmd:${createHash14("sha256").update(command).digest("hex")}`;
|
|
19242
19513
|
function noteRawCommit(input, command, key) {
|
|
19243
19514
|
try {
|
|
@@ -19248,8 +19519,8 @@ function noteRawCommit(input, command, key) {
|
|
|
19248
19519
|
if (action.kind !== "commit")
|
|
19249
19520
|
continue;
|
|
19250
19521
|
const file = markerFile(repo, input.session.id, key);
|
|
19251
|
-
|
|
19252
|
-
|
|
19522
|
+
fs17.mkdirSync(path25.dirname(file), { recursive: true });
|
|
19523
|
+
fs17.writeFileSync(file, `${JSON.stringify({ head: headSha2(repo), at })}
|
|
19253
19524
|
`);
|
|
19254
19525
|
}
|
|
19255
19526
|
} catch {}
|
|
@@ -19282,11 +19553,11 @@ var headCommit = (dir) => {
|
|
|
19282
19553
|
var settle2 = (input, repo, file) => {
|
|
19283
19554
|
let marker;
|
|
19284
19555
|
try {
|
|
19285
|
-
marker = JSON.parse(
|
|
19556
|
+
marker = JSON.parse(fs17.readFileSync(file, "utf8"));
|
|
19286
19557
|
} catch {
|
|
19287
19558
|
return;
|
|
19288
19559
|
}
|
|
19289
|
-
|
|
19560
|
+
fs17.rmSync(file, { force: true });
|
|
19290
19561
|
const session = input.session.id;
|
|
19291
19562
|
const now = Date.now() / 1000;
|
|
19292
19563
|
if (typeof marker.at !== "number" || now - marker.at > MARKER_TTL_SECONDS)
|
|
@@ -19335,7 +19606,7 @@ function settlePendingCommit(input) {
|
|
|
19335
19606
|
if (!repo)
|
|
19336
19607
|
return;
|
|
19337
19608
|
const file = markerFile(repo, input.session.id, NEXT_COMMAND);
|
|
19338
|
-
if (
|
|
19609
|
+
if (fs17.existsSync(file))
|
|
19339
19610
|
settle2(input, repo, file);
|
|
19340
19611
|
} catch {}
|
|
19341
19612
|
}
|
|
@@ -19489,7 +19760,7 @@ var judgedDir = (root, dir) => {
|
|
|
19489
19760
|
return null;
|
|
19490
19761
|
if (dir === null)
|
|
19491
19762
|
return root;
|
|
19492
|
-
const resolved =
|
|
19763
|
+
const resolved = path26.resolve(root, dir);
|
|
19493
19764
|
return existsSync11(resolved) && inWorkitWorkspace(resolved) ? resolved : null;
|
|
19494
19765
|
};
|
|
19495
19766
|
var shellBranchPolicyViolation = (root, command, dialect = "posix") => {
|
|
@@ -19686,13 +19957,13 @@ var askedWorkitCall = (command, dialect = "posix", depth = 0) => {
|
|
|
19686
19957
|
return null;
|
|
19687
19958
|
};
|
|
19688
19959
|
// packages/workit-core/src/core/heavy-rules.ts
|
|
19689
|
-
import
|
|
19690
|
-
import
|
|
19691
|
-
import
|
|
19960
|
+
import fs18 from "node:fs";
|
|
19961
|
+
import os7 from "node:os";
|
|
19962
|
+
import path27 from "node:path";
|
|
19692
19963
|
var EMPTY2 = () => ({ deny: [], allow: [] });
|
|
19693
19964
|
var readText3 = (file) => {
|
|
19694
19965
|
try {
|
|
19695
|
-
return
|
|
19966
|
+
return fs18.readFileSync(file, "utf8");
|
|
19696
19967
|
} catch (error) {
|
|
19697
19968
|
if (error.code === "ENOENT")
|
|
19698
19969
|
return null;
|
|
@@ -19729,23 +20000,23 @@ function parseJsonc(text) {
|
|
|
19729
20000
|
return JSON.parse(out.replace(/,(\s*[}\]])/gu, "$1"));
|
|
19730
20001
|
}
|
|
19731
20002
|
function gitTop(cwd) {
|
|
19732
|
-
for (let dir =
|
|
19733
|
-
if (
|
|
20003
|
+
for (let dir = path27.resolve(cwd);; dir = path27.dirname(dir)) {
|
|
20004
|
+
if (fs18.existsSync(path27.join(dir, ".git")))
|
|
19734
20005
|
return dir;
|
|
19735
|
-
if (
|
|
20006
|
+
if (path27.dirname(dir) === dir)
|
|
19736
20007
|
return null;
|
|
19737
20008
|
}
|
|
19738
20009
|
}
|
|
19739
20010
|
var projectDirs = (cwd) => {
|
|
19740
20011
|
const top = gitTop(cwd);
|
|
19741
20012
|
const dirs = [];
|
|
19742
|
-
for (let dir =
|
|
20013
|
+
for (let dir = path27.resolve(cwd);; dir = path27.dirname(dir)) {
|
|
19743
20014
|
dirs.push(dir);
|
|
19744
|
-
if (!top || dir === top ||
|
|
20015
|
+
if (!top || dir === top || path27.dirname(dir) === dir)
|
|
19745
20016
|
return dirs;
|
|
19746
20017
|
}
|
|
19747
20018
|
};
|
|
19748
|
-
var homeOf = (env) => env.HOME ||
|
|
20019
|
+
var homeOf = (env) => env.HOME || os7.homedir();
|
|
19749
20020
|
var CLAUDE_MANAGED = {
|
|
19750
20021
|
linux: "/etc/claude-code/managed-settings.json",
|
|
19751
20022
|
darwin: "/Library/Application Support/ClaudeCode/managed-settings.json",
|
|
@@ -19753,12 +20024,12 @@ var CLAUDE_MANAGED = {
|
|
|
19753
20024
|
};
|
|
19754
20025
|
function claudeSettingsFiles(cwd, env, platform = process.platform) {
|
|
19755
20026
|
const project = env.CLAUDE_PROJECT_DIR || gitTop(cwd) || cwd;
|
|
19756
|
-
const user = env.CLAUDE_CONFIG_DIR ||
|
|
20027
|
+
const user = env.CLAUDE_CONFIG_DIR || path27.join(homeOf(env), ".claude");
|
|
19757
20028
|
return [
|
|
19758
20029
|
...CLAUDE_MANAGED[platform] ? [CLAUDE_MANAGED[platform]] : [],
|
|
19759
|
-
|
|
19760
|
-
|
|
19761
|
-
|
|
20030
|
+
path27.join(user, "settings.json"),
|
|
20031
|
+
path27.join(project, ".claude", "settings.json"),
|
|
20032
|
+
path27.join(project, ".claude", "settings.local.json")
|
|
19762
20033
|
];
|
|
19763
20034
|
}
|
|
19764
20035
|
var bashPattern = (entry) => {
|
|
@@ -19865,10 +20136,10 @@ var opencodeConfig = (value, rules) => isRecord5(value) && opencodeRuleset(value
|
|
|
19865
20136
|
function opencodeRules(cwd, env = process.env) {
|
|
19866
20137
|
const rules = EMPTY2();
|
|
19867
20138
|
try {
|
|
19868
|
-
const config = env.XDG_CONFIG_HOME ||
|
|
20139
|
+
const config = env.XDG_CONFIG_HOME || path27.join(homeOf(env), ".config");
|
|
19869
20140
|
const files = [
|
|
19870
|
-
...OPENCODE_NAMES.map((name) =>
|
|
19871
|
-
...projectDirs(cwd).flatMap((dir) => OPENCODE_NAMES.flatMap((name) => [
|
|
20141
|
+
...OPENCODE_NAMES.map((name) => path27.join(config, "opencode", name)),
|
|
20142
|
+
...projectDirs(cwd).flatMap((dir) => OPENCODE_NAMES.flatMap((name) => [path27.join(dir, name), path27.join(dir, ".opencode", name)])),
|
|
19872
20143
|
...env.OPENCODE_CONFIG ? [env.OPENCODE_CONFIG] : []
|
|
19873
20144
|
];
|
|
19874
20145
|
for (const file of files) {
|
|
@@ -19912,19 +20183,19 @@ var codexRule = (body) => {
|
|
|
19912
20183
|
function codexRules(cwd, env = process.env) {
|
|
19913
20184
|
const rules = EMPTY2();
|
|
19914
20185
|
try {
|
|
19915
|
-
const home = env.CODEX_HOME ||
|
|
20186
|
+
const home = env.CODEX_HOME || path27.join(homeOf(env), ".codex");
|
|
19916
20187
|
const top = gitTop(cwd) ?? cwd;
|
|
19917
|
-
for (const dir of [
|
|
20188
|
+
for (const dir of [path27.join(home, "rules"), path27.join(top, ".codex", "rules")]) {
|
|
19918
20189
|
let files;
|
|
19919
20190
|
try {
|
|
19920
|
-
files =
|
|
20191
|
+
files = fs18.readdirSync(dir).filter((name) => name.endsWith(".rules"));
|
|
19921
20192
|
} catch (error) {
|
|
19922
20193
|
if (error.code === "ENOENT")
|
|
19923
20194
|
continue;
|
|
19924
20195
|
return "unreadable";
|
|
19925
20196
|
}
|
|
19926
20197
|
for (const name of files) {
|
|
19927
|
-
const text = readText3(
|
|
20198
|
+
const text = readText3(path27.join(dir, name)) ?? "";
|
|
19928
20199
|
for (const part of text.split(/\bprefix_rule\s*\(/u).slice(1)) {
|
|
19929
20200
|
const rule = codexRule(part);
|
|
19930
20201
|
if (!rule)
|
|
@@ -19943,8 +20214,8 @@ function cursorRules(cwd, env = process.env) {
|
|
|
19943
20214
|
try {
|
|
19944
20215
|
const top = gitTop(cwd) ?? cwd;
|
|
19945
20216
|
for (const file of [
|
|
19946
|
-
|
|
19947
|
-
|
|
20217
|
+
path27.join(homeOf(env), ".cursor", "cli-config.json"),
|
|
20218
|
+
path27.join(top, ".cursor", "cli.json")
|
|
19948
20219
|
]) {
|
|
19949
20220
|
const text = readText3(file);
|
|
19950
20221
|
if (text === null)
|
|
@@ -20018,11 +20289,11 @@ function wrapAllowed(read, words, command, options = {}) {
|
|
|
20018
20289
|
}
|
|
20019
20290
|
|
|
20020
20291
|
// packages/workit-core/src/core/heavy.ts
|
|
20021
|
-
import
|
|
20022
|
-
import
|
|
20292
|
+
import fs19 from "node:fs";
|
|
20293
|
+
import path28 from "node:path";
|
|
20023
20294
|
var stateDir = (env, platform = process.platform) => stateDir3(env, platform);
|
|
20024
20295
|
var HEAVY_COMMANDS_FILE = "heavy-commands.json";
|
|
20025
|
-
var heavyCommandsFile = (env) =>
|
|
20296
|
+
var heavyCommandsFile = (env) => path28.join(stateDir(env), HEAVY_COMMANDS_FILE);
|
|
20026
20297
|
var HEAVY_SCRIPT = /^(?:test|tests|t|tst|unit|integration|e2e|coverage|cov|lint|eslint|typecheck|type-check|types|tsc|check|verify|validate|build|compile|bundle|ci|sonar|cypress|playwright|jest|vitest|mocha|bench|benchmark|all)(?:$|[:_.-])/iu;
|
|
20027
20298
|
var INFO_FLAGS = new Set(["--version", "-v", "-V", "--help", "-h", "help", "version"]);
|
|
20028
20299
|
var WATCH_FLAG = /^(?:--watch(?:All)?(?:=.*)?|-w|--serve)$/u;
|
|
@@ -20374,7 +20645,7 @@ function parsePattern(pattern) {
|
|
|
20374
20645
|
var matches = (matchers, words) => matchers.length <= words.length && matchers.every((matcher, index) => index === 0 ? matcher.test(words[0]) || matcher.test(baseName2(words[0])) : matcher.test(words[index]));
|
|
20375
20646
|
var readJson = (file) => {
|
|
20376
20647
|
try {
|
|
20377
|
-
return JSON.parse(
|
|
20648
|
+
return JSON.parse(fs19.readFileSync(file, "utf8"));
|
|
20378
20649
|
} catch {
|
|
20379
20650
|
return;
|
|
20380
20651
|
}
|
|
@@ -20386,7 +20657,7 @@ function machinePatterns(env) {
|
|
|
20386
20657
|
return isRecord6(value) ? stringList(value.patterns) : [];
|
|
20387
20658
|
}
|
|
20388
20659
|
function repoPatterns(cwd) {
|
|
20389
|
-
return repoHeavyCommands(gitTop(cwd) ??
|
|
20660
|
+
return repoHeavyCommands(gitTop(cwd) ?? path28.resolve(cwd));
|
|
20390
20661
|
}
|
|
20391
20662
|
function heavyLines(lines, options) {
|
|
20392
20663
|
const found = [];
|
|
@@ -20489,12 +20760,12 @@ function serverPlan(command, options) {
|
|
|
20489
20760
|
}
|
|
20490
20761
|
function workitOnPath(env = process.env) {
|
|
20491
20762
|
const names = process.platform === "win32" ? ["workit.exe", "workit.cmd", "workit"] : ["workit"];
|
|
20492
|
-
for (const dir of (env.PATH ?? "").split(
|
|
20763
|
+
for (const dir of (env.PATH ?? "").split(path28.delimiter))
|
|
20493
20764
|
for (const name of names) {
|
|
20494
20765
|
if (!dir)
|
|
20495
20766
|
continue;
|
|
20496
20767
|
try {
|
|
20497
|
-
|
|
20768
|
+
fs19.accessSync(path28.join(dir, name), fs19.constants.X_OK);
|
|
20498
20769
|
return true;
|
|
20499
20770
|
} catch {}
|
|
20500
20771
|
}
|
|
@@ -20580,15 +20851,15 @@ import {
|
|
|
20580
20851
|
realpathSync as realpathSync8,
|
|
20581
20852
|
statSync as statSync3
|
|
20582
20853
|
} from "node:fs";
|
|
20583
|
-
import
|
|
20584
|
-
import
|
|
20854
|
+
import os9 from "node:os";
|
|
20855
|
+
import path30 from "node:path";
|
|
20585
20856
|
|
|
20586
20857
|
// packages/workit-core/src/core/live-session.ts
|
|
20587
20858
|
import { spawnSync as spawnSync15 } from "node:child_process";
|
|
20588
20859
|
import { createHash as createHash15 } from "node:crypto";
|
|
20589
|
-
import
|
|
20590
|
-
import
|
|
20591
|
-
import
|
|
20860
|
+
import fs20 from "node:fs";
|
|
20861
|
+
import os8 from "node:os";
|
|
20862
|
+
import path29 from "node:path";
|
|
20592
20863
|
var LIVE_SESSION_TTL_MS = 15 * 60000;
|
|
20593
20864
|
var HEARTBEAT_EVERY_MS = 30000;
|
|
20594
20865
|
var liveProbe = {
|
|
@@ -20609,9 +20880,9 @@ var processAlive = (pid) => {
|
|
|
20609
20880
|
var processInfo = (pid) => {
|
|
20610
20881
|
try {
|
|
20611
20882
|
if (liveProbe.platform === "linux") {
|
|
20612
|
-
const stat =
|
|
20883
|
+
const stat = fs20.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
20613
20884
|
const ppid = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
20614
|
-
const command =
|
|
20885
|
+
const command = fs20.readFileSync(`/proc/${pid}/cmdline`, "utf8").replaceAll("\x00", " ");
|
|
20615
20886
|
return Number.isInteger(ppid) ? { ppid, command: command.trim() } : null;
|
|
20616
20887
|
}
|
|
20617
20888
|
if (liveProbe.platform === "win32")
|
|
@@ -20662,35 +20933,35 @@ var liveOwner = (input, transport, env = process.env) => {
|
|
|
20662
20933
|
};
|
|
20663
20934
|
};
|
|
20664
20935
|
var checkoutOf = (target) => {
|
|
20665
|
-
let dir =
|
|
20666
|
-
while (!
|
|
20667
|
-
dir =
|
|
20668
|
-
if (
|
|
20669
|
-
dir =
|
|
20670
|
-
const parts = dir.split(
|
|
20936
|
+
let dir = path29.resolve(target);
|
|
20937
|
+
while (!fs20.existsSync(dir) && path29.dirname(dir) !== dir)
|
|
20938
|
+
dir = path29.dirname(dir);
|
|
20939
|
+
if (fs20.existsSync(dir) && !fs20.statSync(dir).isDirectory())
|
|
20940
|
+
dir = path29.dirname(dir);
|
|
20941
|
+
const parts = dir.split(path29.sep);
|
|
20671
20942
|
const dotGit = parts.lastIndexOf(".git");
|
|
20672
20943
|
if (dotGit > 0)
|
|
20673
|
-
dir = parts.slice(0, dotGit).join(
|
|
20944
|
+
dir = parts.slice(0, dotGit).join(path29.sep) || path29.sep;
|
|
20674
20945
|
const location = resolveStore(dir);
|
|
20675
20946
|
if (location instanceof Error || !location.shared || !location.top)
|
|
20676
20947
|
return null;
|
|
20677
20948
|
let top = location.top;
|
|
20678
20949
|
try {
|
|
20679
|
-
top =
|
|
20950
|
+
top = fs20.realpathSync.native(top);
|
|
20680
20951
|
} catch {}
|
|
20681
20952
|
return top;
|
|
20682
20953
|
};
|
|
20683
|
-
var markerFile2 = (top) =>
|
|
20954
|
+
var markerFile2 = (top) => path29.join(resolveStateDir(), "live-sessions", `${createHash15("sha256").update(checkoutKey(top)).digest("hex").slice(0, 32)}.json`);
|
|
20684
20955
|
var checkoutKey = (top, platform = process.platform) => {
|
|
20685
|
-
let key =
|
|
20956
|
+
let key = path29.resolve(top);
|
|
20686
20957
|
try {
|
|
20687
|
-
key =
|
|
20958
|
+
key = fs20.realpathSync.native(key);
|
|
20688
20959
|
} catch {}
|
|
20689
20960
|
return platform === "win32" ? key.replaceAll("/", "\\").toLowerCase() : key;
|
|
20690
20961
|
};
|
|
20691
20962
|
var readMarker = (file) => {
|
|
20692
20963
|
try {
|
|
20693
|
-
const value = JSON.parse(
|
|
20964
|
+
const value = JSON.parse(fs20.readFileSync(file, "utf8"));
|
|
20694
20965
|
if (value?.version !== 1 || typeof value.session !== "string" || typeof value.host !== "string" || typeof value.heartbeatAt !== "string" || Number.isNaN(Date.parse(value.heartbeatAt)))
|
|
20695
20966
|
return null;
|
|
20696
20967
|
return {
|
|
@@ -20713,7 +20984,7 @@ var isLive = (marker, deps) => {
|
|
|
20713
20984
|
const age = ageOf2(marker, deps.now ?? new Date);
|
|
20714
20985
|
if (age > (deps.ttlMs ?? LIVE_SESSION_TTL_MS))
|
|
20715
20986
|
return false;
|
|
20716
|
-
if (marker.machine !== (deps.machine ??
|
|
20987
|
+
if (marker.machine !== (deps.machine ?? os8.hostname()) || marker.pid === null)
|
|
20717
20988
|
return true;
|
|
20718
20989
|
if (!(deps.alive ?? processAlive)(marker.pid))
|
|
20719
20990
|
return false;
|
|
@@ -20742,7 +21013,7 @@ var liveConflict = (target, owner, deps = {}) => {
|
|
|
20742
21013
|
const marker = readMarker(file);
|
|
20743
21014
|
if (!marker || sameLead(marker, owner) || !isLive(marker, deps))
|
|
20744
21015
|
return null;
|
|
20745
|
-
if (sameOwner(marker, owner, deps.machine ??
|
|
21016
|
+
if (sameOwner(marker, owner, deps.machine ?? os8.hostname()))
|
|
20746
21017
|
return null;
|
|
20747
21018
|
return { marker, file, ageMs: ageOf2(marker, deps.now ?? new Date), checkout };
|
|
20748
21019
|
} catch {
|
|
@@ -20756,7 +21027,7 @@ var claimLiveSession = (target, owner, deps = {}) => {
|
|
|
20756
21027
|
return;
|
|
20757
21028
|
const file = markerFile2(checkout);
|
|
20758
21029
|
const now = deps.now ?? new Date;
|
|
20759
|
-
const machine = deps.machine ??
|
|
21030
|
+
const machine = deps.machine ?? os8.hostname();
|
|
20760
21031
|
const current = readMarker(file);
|
|
20761
21032
|
if (current) {
|
|
20762
21033
|
const age = ageOf2(current, now);
|
|
@@ -20777,10 +21048,10 @@ var claimLiveSession = (target, owner, deps = {}) => {
|
|
|
20777
21048
|
checkout,
|
|
20778
21049
|
heartbeatAt: now.toISOString()
|
|
20779
21050
|
};
|
|
20780
|
-
|
|
21051
|
+
fs20.mkdirSync(path29.dirname(file), { recursive: true });
|
|
20781
21052
|
const temp = `${file}.${process.pid}.tmp`;
|
|
20782
|
-
|
|
20783
|
-
|
|
21053
|
+
fs20.writeFileSync(temp, JSON.stringify(marker));
|
|
21054
|
+
fs20.renameSync(temp, file);
|
|
20784
21055
|
} catch {}
|
|
20785
21056
|
};
|
|
20786
21057
|
|
|
@@ -20790,44 +21061,44 @@ var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "wi
|
|
|
20790
21061
|
var linkTarget = (file) => {
|
|
20791
21062
|
try {
|
|
20792
21063
|
const to = readlinkSync3(file);
|
|
20793
|
-
let from =
|
|
21064
|
+
let from = path30.dirname(file);
|
|
20794
21065
|
try {
|
|
20795
21066
|
from = realpathSync8.native(from);
|
|
20796
21067
|
} catch {}
|
|
20797
|
-
return
|
|
21068
|
+
return path30.resolve(from, to);
|
|
20798
21069
|
} catch {
|
|
20799
21070
|
return null;
|
|
20800
21071
|
}
|
|
20801
21072
|
};
|
|
20802
21073
|
var realPath = (file, dangling = true) => {
|
|
20803
|
-
let dir =
|
|
21074
|
+
let dir = path30.resolve(file);
|
|
20804
21075
|
let rest = "";
|
|
20805
21076
|
for (let hops = 0;; ) {
|
|
20806
21077
|
try {
|
|
20807
|
-
return
|
|
21078
|
+
return path30.join(realpathSync8.native(dir), rest);
|
|
20808
21079
|
} catch {
|
|
20809
21080
|
const link = dangling ? linkTarget(dir) : null;
|
|
20810
21081
|
if (link !== null) {
|
|
20811
21082
|
if (++hops > 40)
|
|
20812
21083
|
return null;
|
|
20813
|
-
dir =
|
|
21084
|
+
dir = path30.join(link, rest);
|
|
20814
21085
|
rest = "";
|
|
20815
|
-
} else if (
|
|
20816
|
-
return
|
|
21086
|
+
} else if (path30.dirname(dir) === dir)
|
|
21087
|
+
return path30.resolve(file);
|
|
20817
21088
|
else {
|
|
20818
|
-
rest = rest ?
|
|
20819
|
-
dir =
|
|
21089
|
+
rest = rest ? path30.join(path30.basename(dir), rest) : path30.basename(dir);
|
|
21090
|
+
dir = path30.dirname(dir);
|
|
20820
21091
|
}
|
|
20821
21092
|
}
|
|
20822
21093
|
}
|
|
20823
21094
|
};
|
|
20824
|
-
var
|
|
21095
|
+
var canonical5 = (file, dangling = true) => realPath(file, dangling) ?? path30.resolve(file);
|
|
20825
21096
|
var exempt = (cwd, root, file, plans) => {
|
|
20826
21097
|
const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
|
|
20827
|
-
const relative =
|
|
20828
|
-
if (relative.startsWith("..") ||
|
|
21098
|
+
const relative = path30.relative(fold(canonical5(root, false)), fold(canonical5(path30.resolve(cwd, file), false)));
|
|
21099
|
+
if (relative.startsWith("..") || path30.isAbsolute(relative))
|
|
20829
21100
|
return true;
|
|
20830
|
-
const posix = relative.split(
|
|
21101
|
+
const posix = relative.split(path30.sep).join("/");
|
|
20831
21102
|
const segments = posix.split("/");
|
|
20832
21103
|
return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
|
|
20833
21104
|
};
|
|
@@ -20944,8 +21215,8 @@ var WRAPPERS3 = {
|
|
|
20944
21215
|
bunx: "p"
|
|
20945
21216
|
};
|
|
20946
21217
|
var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
|
|
20947
|
-
var isConfigDir = (file) => configDirs().some((dir) =>
|
|
20948
|
-
var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test(
|
|
21218
|
+
var isConfigDir = (file) => configDirs().some((dir) => canonical5(dir) === canonical5(file));
|
|
21219
|
+
var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test(path30.relative(canonical5(resolveStateDir()), canonical5(file)));
|
|
20949
21220
|
var READ_CALLS = /^(?:print|log|info|warn|error|debug|puts|readdir(?:Sync)?|listdir|scandir|iterdir|glob|l?stat(?:Sync)?|exists(?:Sync)?|isdir|isfile|is_dir|is_file|access(?:Sync)?|realpath(?:Sync)?|dirname|basename|relative|str|repr|len)$/;
|
|
20950
21221
|
var MUTATING_CALLS = /^(?:renames?(?:Sync)?|move|copy(?:2|file|tree|File)?(?:Sync)?|cp(?:Sync)?|rm(?:tree|dir|Sync|dirSync)?|unlink(?:Sync)?|remove(?:dirs)?|mkdirs?(?:Sync)?|makedirs|mkdtemp(?:Sync)?|(?:sym|hard)?link(?:Sync|_to)?|write\w*|append\w*|truncate(?:Sync)?|ch(?:mod|own)(?:Sync)?|touch|open(?:Sync)?|dump|save|extractall|unpack_archive|put_contents|mv|FileUtils)$/;
|
|
20951
21222
|
var SPAWNS = /subprocess|child_process|WriteStream|tempfile|sqlite|inplace|getattr|spawn|\bvm\b|Function\s*\(|FileIO|ZipFile|tarfile|shelve|FileHandler|filename\s*=|savefig|utime|ch(?:mod|own)|mkfifo|mknod|\.(?:delete|to_\w+)\s*\(|Path\b.*\.replace\(|Bun\.\$|O_(?:WR|RDW|CR|AP|TR)|(?:PYTHON|NODE_)\w*=|-r\b|--(?:require|import|[\w-]*loader)|\bos\.replace|\b(?:system|popen|exec\w*|fork|eval|shutil|(?:unlink|rename|remove)\w*)\b|\]\s*\(|\brequire\s*\(\s*(?!(['"])(?:(?![a-zA-Z]:)[\w@][^'"]*|[^'"]*\.json)\1)/;
|
|
@@ -21285,10 +21556,10 @@ var linkSources = (args, at) => {
|
|
|
21285
21556
|
const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
|
|
21286
21557
|
const target = dest === undefined ? null : at(dest);
|
|
21287
21558
|
const symbolic = args.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg));
|
|
21288
|
-
const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target :
|
|
21559
|
+
const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path30.dirname(target);
|
|
21289
21560
|
return sources.flatMap((source) => {
|
|
21290
|
-
if (symbolic && base !== null && !
|
|
21291
|
-
return [
|
|
21561
|
+
if (symbolic && base !== null && !path30.isAbsolute(homeExpanded(source)))
|
|
21562
|
+
return [path30.resolve(base, source)];
|
|
21292
21563
|
const resolved = at(source);
|
|
21293
21564
|
return resolved ? [resolved] : [];
|
|
21294
21565
|
});
|
|
@@ -21317,7 +21588,7 @@ var shellWrites = (command, depth = 0) => {
|
|
|
21317
21588
|
return { writes: true, targets: unknown ? null : targets };
|
|
21318
21589
|
};
|
|
21319
21590
|
var cache2 = new Map;
|
|
21320
|
-
var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(
|
|
21591
|
+
var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path30.resolve(root, file)) ?? "-").join("\x00");
|
|
21321
21592
|
var gateFor = (cwd) => {
|
|
21322
21593
|
const store = new TaskReader(cwd);
|
|
21323
21594
|
const listed = store.listTaskIndex();
|
|
@@ -21380,7 +21651,7 @@ var DIR_TARGET = ".workit-live-target";
|
|
|
21380
21651
|
var PLACEHOLDERS = new WeakMap;
|
|
21381
21652
|
var collecting = null;
|
|
21382
21653
|
var placeholderIn = (dir, name) => {
|
|
21383
|
-
const target =
|
|
21654
|
+
const target = path30.join(dir, name);
|
|
21384
21655
|
collecting?.add(target);
|
|
21385
21656
|
return target;
|
|
21386
21657
|
};
|
|
@@ -21420,13 +21691,13 @@ var gitMutationDirs = (cwd, command, dialect) => {
|
|
|
21420
21691
|
return [];
|
|
21421
21692
|
if (sub === "stash" && ["list", "show"].includes(rest[0] ?? ""))
|
|
21422
21693
|
return [];
|
|
21423
|
-
return [
|
|
21694
|
+
return [path30.resolve(cwd, invocation.dir ?? ".")];
|
|
21424
21695
|
});
|
|
21425
21696
|
};
|
|
21426
21697
|
var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
|
|
21427
21698
|
var PUSHD2 = new Set(["pushd", "push-location"]);
|
|
21428
21699
|
var POPD2 = new Set(["popd", "pop-location"]);
|
|
21429
|
-
var UNKNOWN_DIR =
|
|
21700
|
+
var UNKNOWN_DIR = path30.resolve(path30.parse(process.cwd()).root, ".workit-unknown-dir");
|
|
21430
21701
|
var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
|
|
21431
21702
|
const lost = strict ? UNKNOWN_DIR : undefined;
|
|
21432
21703
|
const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
@@ -21436,7 +21707,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
|
|
|
21436
21707
|
return lost;
|
|
21437
21708
|
if (dir === undefined)
|
|
21438
21709
|
return lost;
|
|
21439
|
-
return target === undefined ?
|
|
21710
|
+
return target === undefined ? os9.homedir() : path30.resolve(dir, target);
|
|
21440
21711
|
};
|
|
21441
21712
|
var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
21442
21713
|
var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
|
|
@@ -21571,7 +21842,7 @@ var untrustedVars = (segments) => {
|
|
|
21571
21842
|
}
|
|
21572
21843
|
return { all, names };
|
|
21573
21844
|
};
|
|
21574
|
-
var UNKNOWN_VAR =
|
|
21845
|
+
var UNKNOWN_VAR = path30.resolve(path30.parse(process.cwd()).root, ".workit-unknown-var");
|
|
21575
21846
|
var REFERENCE = /\$\{(\w+)[^}]*\}|\$(\w+)|\$\([^)]*\)?|`[^`]*`?/g;
|
|
21576
21847
|
var unresolvedRefs = (text) => [
|
|
21577
21848
|
...new Set([...text.matchAll(REFERENCE)].map((match) => {
|
|
@@ -21581,7 +21852,7 @@ var unresolvedRefs = (text) => [
|
|
|
21581
21852
|
];
|
|
21582
21853
|
var unknownVarTarget = (text) => {
|
|
21583
21854
|
const refs = unresolvedRefs(text);
|
|
21584
|
-
return
|
|
21855
|
+
return path30.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
|
|
21585
21856
|
};
|
|
21586
21857
|
var applyOperator = (value, operator) => {
|
|
21587
21858
|
if (operator === "")
|
|
@@ -21640,18 +21911,18 @@ var mktempPath = (value, dir) => {
|
|
|
21640
21911
|
template = arg;
|
|
21641
21912
|
}
|
|
21642
21913
|
if (base === null && (temp || template === undefined))
|
|
21643
|
-
base =
|
|
21914
|
+
base = os9.tmpdir();
|
|
21644
21915
|
const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
|
|
21645
|
-
if (
|
|
21916
|
+
if (path30.isAbsolute(name))
|
|
21646
21917
|
return name;
|
|
21647
21918
|
const from = base === null ? dir : homeExpanded(base);
|
|
21648
|
-
if (from === undefined || !
|
|
21919
|
+
if (from === undefined || !path30.isAbsolute(from) && dir === undefined)
|
|
21649
21920
|
return null;
|
|
21650
|
-
return
|
|
21921
|
+
return path30.resolve(dir ?? from, from, name);
|
|
21651
21922
|
};
|
|
21652
21923
|
var homeExpanded = (file) => {
|
|
21653
21924
|
const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
|
|
21654
|
-
return match ? (process.env.HOME ||
|
|
21925
|
+
return match ? (process.env.HOME || os9.homedir()) + file.slice(match[0].length) : file;
|
|
21655
21926
|
};
|
|
21656
21927
|
var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherited = new Map) => {
|
|
21657
21928
|
const targets = [];
|
|
@@ -21668,7 +21939,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
21668
21939
|
const home = homeExpanded(text);
|
|
21669
21940
|
if (strict && unresolvedRefs(home).length > 0)
|
|
21670
21941
|
return [unknownVarTarget(home)];
|
|
21671
|
-
if (
|
|
21942
|
+
if (path30.isAbsolute(home))
|
|
21672
21943
|
return [home];
|
|
21673
21944
|
return base === undefined ? [] : [resolvedUnder(base, home)];
|
|
21674
21945
|
});
|
|
@@ -21863,7 +22134,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
21863
22134
|
index
|
|
21864
22135
|
}));
|
|
21865
22136
|
const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
|
|
21866
|
-
const under = (word) => homes ? [
|
|
22137
|
+
const under = (word) => homes ? [path30.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
|
|
21867
22138
|
const found = [
|
|
21868
22139
|
...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
|
|
21869
22140
|
...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
|
|
@@ -21871,7 +22142,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
21871
22142
|
for (const { file, index } of found) {
|
|
21872
22143
|
const use = isRoot(file) ? rootUse(text, index) : "takes";
|
|
21873
22144
|
if (use !== "reads")
|
|
21874
|
-
targets.push(use === "builds" ?
|
|
22145
|
+
targets.push(use === "builds" ? path30.join(file, UNRESOLVED_TARGET) : file);
|
|
21875
22146
|
}
|
|
21876
22147
|
}
|
|
21877
22148
|
if (/^(?:n?vim?|ex|ed|emacs)$/.test(verb) && (segment.stdin || inputs.length > 0 || feeder || args.some((arg, index) => /^(?:-[a-zA-Z]*[se]|--(?:batch|eval|script))$/.test(arg) || /^(?:-c|--cmd)$/.test(arg) && !inertEdit(args[index + 1] ?? "") || arg.startsWith("+") && !inertEdit(arg.slice(1) || "1"))))
|
|
@@ -21906,7 +22177,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
21906
22177
|
for (const file of opaque ?? [])
|
|
21907
22178
|
for (const resolved of atAll(file))
|
|
21908
22179
|
if (!quiet || !isRoot(resolved))
|
|
21909
|
-
targets.push(file === "." ? placeholderIn(resolved, here) :
|
|
22180
|
+
targets.push(file === "." ? placeholderIn(resolved, here) : path30.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path30.dirname(resolved), path30.basename(resolved)) : resolved);
|
|
21910
22181
|
const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
|
|
21911
22182
|
const lnArgs = words.slice(ln + 1);
|
|
21912
22183
|
if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)) && (strict !== "registry" || !lnArgs.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg))))
|
|
@@ -21985,7 +22256,7 @@ var liveDeny = ({ marker, checkout, ageMs, file }) => {
|
|
|
21985
22256
|
var guarded = (targets) => {
|
|
21986
22257
|
const seen = new Set;
|
|
21987
22258
|
return targets.filter((target) => {
|
|
21988
|
-
const dir =
|
|
22259
|
+
const dir = path30.dirname(target);
|
|
21989
22260
|
if (seen.has(dir))
|
|
21990
22261
|
return false;
|
|
21991
22262
|
seen.add(dir);
|
|
@@ -22006,17 +22277,17 @@ var claimAll = (owner, targets, deps) => {
|
|
|
22006
22277
|
for (const target of guarded(targets))
|
|
22007
22278
|
claimLiveSession(target, owner, deps);
|
|
22008
22279
|
};
|
|
22009
|
-
var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ?
|
|
22280
|
+
var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path30.resolve(dir, file) : path30.isAbsolute(file) ? file : `${dir}${path30.sep}${file}`;
|
|
22010
22281
|
var liveTargets = (cwd, paths) => recording(() => paths?.length ? paths.map((file) => resolvedUnder(cwd, file)) : [placeholderIn(cwd, DIR_TARGET)]);
|
|
22011
22282
|
var CONFIG_FILES = ["workspaces.json", SEAL_FILE];
|
|
22012
22283
|
var configDirs = () => [resolveConfigDir(), grantsDir()];
|
|
22013
22284
|
var globbed = (cwd, target, state, configs) => {
|
|
22014
22285
|
if (!/[*?[]/.test(target))
|
|
22015
22286
|
return [];
|
|
22016
|
-
const raw =
|
|
22287
|
+
const raw = path30.resolve(cwd, target).split(path30.sep);
|
|
22017
22288
|
const literal = raw.findIndex((part) => /[*?[]/.test(part));
|
|
22018
22289
|
const pattern = [
|
|
22019
|
-
...
|
|
22290
|
+
...canonical5(raw.slice(0, literal).join(path30.sep) || path30.sep).replace(/[\\/]+$/, "").split(path30.sep),
|
|
22020
22291
|
...raw.slice(literal)
|
|
22021
22292
|
];
|
|
22022
22293
|
const segment = (glob, name) => {
|
|
@@ -22027,7 +22298,7 @@ var globbed = (cwd, target, state, configs) => {
|
|
|
22027
22298
|
}
|
|
22028
22299
|
};
|
|
22029
22300
|
const hit = (file, below) => {
|
|
22030
|
-
const parts =
|
|
22301
|
+
const parts = canonical5(file).split(path30.sep);
|
|
22031
22302
|
return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
|
|
22032
22303
|
};
|
|
22033
22304
|
let roots = [];
|
|
@@ -22035,8 +22306,8 @@ var globbed = (cwd, target, state, configs) => {
|
|
|
22035
22306
|
roots = readdirSync3(state).filter((name) => /^(?:issued|approvals$)/.test(name));
|
|
22036
22307
|
} catch {}
|
|
22037
22308
|
return [
|
|
22038
|
-
...roots.map((name) =>
|
|
22039
|
-
...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) =>
|
|
22309
|
+
...roots.map((name) => path30.join(state, name)).filter((root) => hit(root, true)),
|
|
22310
|
+
...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path30.join(dir, name))]).filter((file) => hit(file, false))
|
|
22040
22311
|
];
|
|
22041
22312
|
};
|
|
22042
22313
|
var guardedInodes = (state, configs) => {
|
|
@@ -22050,15 +22321,15 @@ var guardedInodes = (state, configs) => {
|
|
|
22050
22321
|
seen.set(`${stat.dev}:${stat.ino}`, registry);
|
|
22051
22322
|
else if (stat?.isDirectory())
|
|
22052
22323
|
for (const name of readdirSync3(file))
|
|
22053
|
-
add(
|
|
22324
|
+
add(path30.join(file, name), registry);
|
|
22054
22325
|
};
|
|
22055
22326
|
try {
|
|
22056
22327
|
for (const dir of configs)
|
|
22057
22328
|
for (const name of CONFIG_FILES)
|
|
22058
|
-
add(
|
|
22329
|
+
add(path30.join(dir, name), "grants");
|
|
22059
22330
|
for (const name of readdirSync3(state))
|
|
22060
22331
|
if (/^(?:issued|approvals$)/.test(name))
|
|
22061
|
-
add(
|
|
22332
|
+
add(path30.join(state, name), name === "approvals" ? "approvals" : "issued");
|
|
22062
22333
|
} catch {}
|
|
22063
22334
|
return seen;
|
|
22064
22335
|
};
|
|
@@ -22079,13 +22350,13 @@ var registryTarget = (cwd, targets) => {
|
|
|
22079
22350
|
const inodes = {};
|
|
22080
22351
|
for (const target of targets) {
|
|
22081
22352
|
const file = homeExpanded(target);
|
|
22082
|
-
if (realPath(
|
|
22353
|
+
if (realPath(path30.resolve(cwd, file)) === null)
|
|
22083
22354
|
return { file: target, registry: "link" };
|
|
22084
22355
|
const glob = globbed(cwd, file, state, configs)[0];
|
|
22085
22356
|
const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
|
|
22086
22357
|
if (viaGlob)
|
|
22087
22358
|
return { file: target, registry: viaGlob.registry };
|
|
22088
|
-
const registry = hardLinked(
|
|
22359
|
+
const registry = hardLinked(path30.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical5) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical5)) ? "grants" : null);
|
|
22089
22360
|
if (registry)
|
|
22090
22361
|
return { file: target, registry };
|
|
22091
22362
|
}
|
|
@@ -22093,7 +22364,7 @@ var registryTarget = (cwd, targets) => {
|
|
|
22093
22364
|
};
|
|
22094
22365
|
var partsUnder = (dir, cwd, target, platform, real) => {
|
|
22095
22366
|
const win = platform === "win32";
|
|
22096
|
-
const p = win ?
|
|
22367
|
+
const p = win ? path30.win32 : path30.posix;
|
|
22097
22368
|
const fold = (value) => win || platform === "darwin" ? value.toLowerCase() : value;
|
|
22098
22369
|
const named = win ? target.replace(/^\/([a-zA-Z])(?=\/|$)/, "$1:") : target;
|
|
22099
22370
|
const relative = p.relative(fold(real(p.resolve(dir))), fold(real(p.resolve(cwd, named))));
|
|
@@ -22155,13 +22426,13 @@ var REGISTRY_DENY = {
|
|
|
22155
22426
|
};
|
|
22156
22427
|
var registryDeny = ({ file, registry }) => {
|
|
22157
22428
|
const { label, what, unblock } = REGISTRY_DENY[registry];
|
|
22158
|
-
if (
|
|
22429
|
+
if (path30.basename(file) === UNRESOLVED_TARGET)
|
|
22159
22430
|
return {
|
|
22160
22431
|
kind: "deny",
|
|
22161
22432
|
reason: `workit ${label}: Workit could not resolve the file this command's script writes, which it builds from a path under ${what}. ${unblock}`,
|
|
22162
22433
|
unblock
|
|
22163
22434
|
};
|
|
22164
|
-
const named =
|
|
22435
|
+
const named = path30.basename(file).startsWith(".workit-") ? path30.dirname(file) : file;
|
|
22165
22436
|
return {
|
|
22166
22437
|
kind: "deny",
|
|
22167
22438
|
reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
|
|
@@ -22250,11 +22521,11 @@ function beforeWriteGate(cwd, paths) {
|
|
|
22250
22521
|
import { spawnSync as spawnSync16 } from "node:child_process";
|
|
22251
22522
|
|
|
22252
22523
|
// packages/workit-core/src/ci-waiter.ts
|
|
22253
|
-
import
|
|
22254
|
-
import
|
|
22524
|
+
import fs21 from "node:fs";
|
|
22525
|
+
import path31 from "node:path";
|
|
22255
22526
|
var waiterFile = (cwd, pr) => {
|
|
22256
22527
|
const common = gitCommonDir(cwd);
|
|
22257
|
-
return common ?
|
|
22528
|
+
return common ? path31.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
|
|
22258
22529
|
};
|
|
22259
22530
|
var pidAlive2 = (pid) => {
|
|
22260
22531
|
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
@@ -22297,7 +22568,7 @@ var liveCiWaiter = (cwd, pr, head = null, nowMs = Date.now()) => {
|
|
|
22297
22568
|
const file = waiterFile(cwd, pr);
|
|
22298
22569
|
if (!file)
|
|
22299
22570
|
return null;
|
|
22300
|
-
const waiter = parse3(
|
|
22571
|
+
const waiter = parse3(fs21.readFileSync(file, "utf8"));
|
|
22301
22572
|
if (!waiter || waiter.pr !== pr || waiter.pid === process.pid)
|
|
22302
22573
|
return null;
|
|
22303
22574
|
if (head && waiter.head && !sameSha(waiter.head, head))
|
|
@@ -22757,12 +23028,12 @@ ${line}` };
|
|
|
22757
23028
|
};
|
|
22758
23029
|
// packages/workit-core/src/hooks/hosts/fields.ts
|
|
22759
23030
|
import { existsSync as existsSync13, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
|
|
22760
|
-
import
|
|
23031
|
+
import path32 from "node:path";
|
|
22761
23032
|
var isRecord7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
22762
23033
|
var nonEmpty2 = (value) => typeof value === "string" && value.trim() !== "";
|
|
22763
23034
|
var optionalText = (value) => typeof value === "string" ? value : null;
|
|
22764
23035
|
var existingDirectory = (value) => {
|
|
22765
|
-
if (!nonEmpty2(value) || !
|
|
23036
|
+
if (!nonEmpty2(value) || !path32.isAbsolute(value) || !existsSync13(value))
|
|
22766
23037
|
return null;
|
|
22767
23038
|
try {
|
|
22768
23039
|
return statSync4(value).isDirectory() ? realpathSync9(value) : null;
|
|
@@ -22829,8 +23100,8 @@ var writeTargets = (input) => {
|
|
|
22829
23100
|
return paths.length > 0 ? paths : null;
|
|
22830
23101
|
};
|
|
22831
23102
|
// packages/workit-core/src/hooks/standing.ts
|
|
22832
|
-
import
|
|
22833
|
-
import
|
|
23103
|
+
import fs23 from "node:fs";
|
|
23104
|
+
import path34 from "node:path";
|
|
22834
23105
|
|
|
22835
23106
|
// packages/workit-core/src/approvals/store.ts
|
|
22836
23107
|
var REQUEST_TTL_MS = 30 * 60000;
|
|
@@ -23536,41 +23807,41 @@ function neededChecks(lane, configured) {
|
|
|
23536
23807
|
|
|
23537
23808
|
// packages/workit-core/src/hooks/worktree-confine.ts
|
|
23538
23809
|
import { createHash as createHash16 } from "node:crypto";
|
|
23539
|
-
import
|
|
23540
|
-
import
|
|
23541
|
-
import
|
|
23810
|
+
import fs22 from "node:fs";
|
|
23811
|
+
import os10 from "node:os";
|
|
23812
|
+
import path33 from "node:path";
|
|
23542
23813
|
var FANOUT_TOKEN_FILE = "workit-fanout-token";
|
|
23543
23814
|
var NONE5 = { kind: "none" };
|
|
23544
23815
|
var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
|
|
23545
23816
|
var realOf = (file) => {
|
|
23546
23817
|
let rest = "";
|
|
23547
|
-
for (let dir = file;; dir =
|
|
23818
|
+
for (let dir = file;; dir = path33.dirname(dir)) {
|
|
23548
23819
|
try {
|
|
23549
|
-
return
|
|
23820
|
+
return path33.join(fs22.realpathSync.native(dir), rest);
|
|
23550
23821
|
} catch {
|
|
23551
|
-
if (
|
|
23822
|
+
if (path33.dirname(dir) === dir)
|
|
23552
23823
|
return file;
|
|
23553
|
-
rest = rest ?
|
|
23824
|
+
rest = rest ? path33.join(path33.basename(dir), rest) : path33.basename(dir);
|
|
23554
23825
|
}
|
|
23555
23826
|
}
|
|
23556
23827
|
};
|
|
23557
|
-
var
|
|
23558
|
-
const start =
|
|
23559
|
-
const { root } =
|
|
23828
|
+
var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
|
|
23829
|
+
const start = path33.isAbsolute(file) ? file : `${process.cwd()}${path33.sep}${file}`;
|
|
23830
|
+
const { root } = path33.parse(start);
|
|
23560
23831
|
let at = root;
|
|
23561
23832
|
let missing = false;
|
|
23562
23833
|
for (const part of start.slice(root.length).split(/[\\/]+/)) {
|
|
23563
23834
|
if (part === "" || part === ".")
|
|
23564
23835
|
continue;
|
|
23565
23836
|
if (part === "..") {
|
|
23566
|
-
at =
|
|
23837
|
+
at = path33.dirname(at);
|
|
23567
23838
|
continue;
|
|
23568
23839
|
}
|
|
23569
|
-
const next =
|
|
23840
|
+
const next = path33.join(at, part);
|
|
23570
23841
|
let link = null;
|
|
23571
23842
|
if (!missing)
|
|
23572
23843
|
try {
|
|
23573
|
-
link =
|
|
23844
|
+
link = fs22.readlinkSync(next);
|
|
23574
23845
|
} catch (error) {
|
|
23575
23846
|
missing = error.code !== "EINVAL";
|
|
23576
23847
|
}
|
|
@@ -23578,25 +23849,25 @@ var canonical5 = (file, hops = { chain: 40, total: 1000 }) => {
|
|
|
23578
23849
|
at = next;
|
|
23579
23850
|
hops.chain = 40;
|
|
23580
23851
|
} else if (hops.chain-- > 0 && hops.total-- > 0)
|
|
23581
|
-
at =
|
|
23852
|
+
at = canonical6(path33.isAbsolute(link) ? link : `${at}${path33.sep}${link}`, hops);
|
|
23582
23853
|
else
|
|
23583
|
-
return
|
|
23854
|
+
return path33.resolve(file);
|
|
23584
23855
|
}
|
|
23585
23856
|
return realOf(at);
|
|
23586
23857
|
};
|
|
23587
23858
|
var within = (child, parent) => {
|
|
23588
23859
|
const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
|
|
23589
|
-
const relative =
|
|
23590
|
-
return relative === "" || !relative.startsWith("..") && !
|
|
23860
|
+
const relative = path33.relative(fold(parent), fold(child));
|
|
23861
|
+
return relative === "" || !relative.startsWith("..") && !path33.isAbsolute(relative);
|
|
23591
23862
|
};
|
|
23592
23863
|
var checkoutOf2 = (file) => {
|
|
23593
|
-
for (let dir =
|
|
23594
|
-
const dotGit =
|
|
23595
|
-
if (
|
|
23596
|
-
const admin =
|
|
23597
|
-
return { root: dir, workit: !!admin &&
|
|
23864
|
+
for (let dir = canonical6(file);; dir = path33.dirname(dir)) {
|
|
23865
|
+
const dotGit = path33.join(dir, ".git");
|
|
23866
|
+
if (fs22.existsSync(dotGit)) {
|
|
23867
|
+
const admin = fs22.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
|
|
23868
|
+
return { root: dir, workit: !!admin && fs22.existsSync(path33.join(admin, FANOUT_TOKEN_FILE)) };
|
|
23598
23869
|
}
|
|
23599
|
-
if (
|
|
23870
|
+
if (path33.dirname(dir) === dir)
|
|
23600
23871
|
return null;
|
|
23601
23872
|
}
|
|
23602
23873
|
};
|
|
@@ -23608,11 +23879,11 @@ var workitWorktreeOf = (file) => {
|
|
|
23608
23879
|
return null;
|
|
23609
23880
|
}
|
|
23610
23881
|
};
|
|
23611
|
-
var bindingDir = () =>
|
|
23612
|
-
var bindingFile = (session, agentId) =>
|
|
23882
|
+
var bindingDir = () => path33.join(resolveStateDir(), "worktree-bind");
|
|
23883
|
+
var bindingFile = (session, agentId) => path33.join(bindingDir(), `${createHash16("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
|
|
23613
23884
|
var readBinding = (file) => {
|
|
23614
23885
|
try {
|
|
23615
|
-
const value = JSON.parse(
|
|
23886
|
+
const value = JSON.parse(fs22.readFileSync(file, "utf8"));
|
|
23616
23887
|
return typeof value.worktree === "string" ? value : null;
|
|
23617
23888
|
} catch {
|
|
23618
23889
|
return null;
|
|
@@ -23634,8 +23905,8 @@ var bind = (input, worktree) => {
|
|
|
23634
23905
|
agentId,
|
|
23635
23906
|
at: new Date().toISOString()
|
|
23636
23907
|
};
|
|
23637
|
-
|
|
23638
|
-
|
|
23908
|
+
fs22.mkdirSync(path33.dirname(file), { recursive: true });
|
|
23909
|
+
fs22.writeFileSync(file, JSON.stringify(binding));
|
|
23639
23910
|
try {
|
|
23640
23911
|
if (inWorkitWorkspace(input.cwd))
|
|
23641
23912
|
appendHookObserved(input.cwd, {
|
|
@@ -23653,26 +23924,26 @@ var hostIsolated = (cwd, agentId) => {
|
|
|
23653
23924
|
const checkout = checkoutOf2(cwd);
|
|
23654
23925
|
if (!checkout)
|
|
23655
23926
|
return false;
|
|
23656
|
-
const dotGit =
|
|
23657
|
-
if (!
|
|
23927
|
+
const dotGit = path33.join(checkout.root, ".git");
|
|
23928
|
+
if (!fs22.statSync(dotGit).isFile())
|
|
23658
23929
|
return false;
|
|
23659
23930
|
const [adminDir, gitDir] = gitDirsAt(checkout.root, null, false) ?? [];
|
|
23660
|
-
const back =
|
|
23661
|
-
if (
|
|
23931
|
+
const back = fs22.readFileSync(path33.join(adminDir, "gitdir"), "utf8").trim();
|
|
23932
|
+
if (path33.relative(canonical6(path33.resolve(adminDir, back)), canonical6(dotGit)) !== "")
|
|
23662
23933
|
return false;
|
|
23663
|
-
const expected =
|
|
23664
|
-
return
|
|
23934
|
+
const expected = path33.join(path33.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
|
|
23935
|
+
return path33.relative(canonical6(expected), checkout.root) === "";
|
|
23665
23936
|
} catch {
|
|
23666
23937
|
return false;
|
|
23667
23938
|
}
|
|
23668
23939
|
};
|
|
23669
23940
|
var runnerAt = (target) => {
|
|
23670
|
-
const base =
|
|
23941
|
+
const base = path33.basename(target);
|
|
23671
23942
|
return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
|
|
23672
23943
|
};
|
|
23673
23944
|
var shown = (target) => {
|
|
23674
|
-
const named = /^\.workit-(?:live-target$|runs-)/.test(
|
|
23675
|
-
return
|
|
23945
|
+
const named = /^\.workit-(?:live-target$|runs-)/.test(path33.basename(target)) ? path33.dirname(target) : target;
|
|
23946
|
+
return path33.sep === "\\" ? named.replaceAll("/", "\\") : named;
|
|
23676
23947
|
};
|
|
23677
23948
|
var runFrom = (dir, command) => `cd ${dir} && ${command.replace(/^\s*cd\s+\S+\s*(?:&&|;)\s*/, "")}`;
|
|
23678
23949
|
var deny2 = (what, unblock) => ({
|
|
@@ -23688,7 +23959,7 @@ var outsideDeny = (input, worktree, target, command) => {
|
|
|
23688
23959
|
};
|
|
23689
23960
|
var unknownDirDeny = (input, worktree) => deny2(`workit worktree confinement: implementer ${input.session.agentId} writes after a directory change Workit cannot resolve (\`cd -\`, \`cd "$X"\`, \`popd\`)`, `Why: write by absolute path, \`git -C ${worktree ?? "<worktree>"}\` or \`workit <verb> --cwd\`.`);
|
|
23690
23961
|
var refsOf = (targets) => [
|
|
23691
|
-
...new Set(targets.flatMap((target) =>
|
|
23962
|
+
...new Set(targets.flatMap((target) => path33.relative(UNKNOWN_VAR, path33.resolve(target)).split(path33.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
|
|
23692
23963
|
];
|
|
23693
23964
|
var literalForm = (command, refs) => {
|
|
23694
23965
|
let text = command;
|
|
@@ -23721,13 +23992,13 @@ function confineImplementer(input, targets, command) {
|
|
|
23721
23992
|
try {
|
|
23722
23993
|
if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
|
|
23723
23994
|
return NONE5;
|
|
23724
|
-
const unresolved = targets.filter((target) => within(
|
|
23995
|
+
const unresolved = targets.filter((target) => within(path33.resolve(target), UNKNOWN_VAR));
|
|
23725
23996
|
if (unresolved.length > 0)
|
|
23726
23997
|
return unknownVarDeny(input, unresolved, command);
|
|
23727
|
-
if (targets.some((target) => within(
|
|
23998
|
+
if (targets.some((target) => within(path33.resolve(target), UNKNOWN_DIR)))
|
|
23728
23999
|
return unknownDirDeny(input, boundWorktree(input));
|
|
23729
|
-
const bindings =
|
|
23730
|
-
const judged = targets.map((named) => ({ named, real:
|
|
24000
|
+
const bindings = canonical6(bindingDir());
|
|
24001
|
+
const judged = targets.map((named) => ({ named, real: canonical6(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
|
|
23731
24002
|
if (judged.length === 0)
|
|
23732
24003
|
return NONE5;
|
|
23733
24004
|
let worktree = boundWorktree(input);
|
|
@@ -23741,7 +24012,7 @@ function confineImplementer(input, targets, command) {
|
|
|
23741
24012
|
return unboundDeny(input, judged[0].named);
|
|
23742
24013
|
bind(input, worktree);
|
|
23743
24014
|
}
|
|
23744
|
-
const root =
|
|
24015
|
+
const root = canonical6(worktree);
|
|
23745
24016
|
const outside = judged.find(({ real }) => !within(real, root) || within(real, bindings));
|
|
23746
24017
|
return outside ? outsideDeny(input, worktree, outside.named, command) : NONE5;
|
|
23747
24018
|
} catch {
|
|
@@ -23831,10 +24102,10 @@ var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print|test|version|help)$|^-[hvV]$/
|
|
|
23831
24102
|
var VALUED2 = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
|
|
23832
24103
|
var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
|
|
23833
24104
|
var inScratch = (real, repo) => {
|
|
23834
|
-
for (let dir = real;
|
|
23835
|
-
if (
|
|
24105
|
+
for (let dir = real;path33.dirname(dir) !== dir; dir = path33.dirname(dir)) {
|
|
24106
|
+
if (path33.basename(dir) !== SCRATCH)
|
|
23836
24107
|
continue;
|
|
23837
|
-
const root =
|
|
24108
|
+
const root = path33.dirname(dir);
|
|
23838
24109
|
const checkout = checkoutOf2(root);
|
|
23839
24110
|
if (checkout?.root === root && (repo === null || checkout.workit || commonDir(root) === repo))
|
|
23840
24111
|
return true;
|
|
@@ -23844,9 +24115,9 @@ var inScratch = (real, repo) => {
|
|
|
23844
24115
|
var inGitDir = (real) => real.split(/[\\/]/).includes(".git");
|
|
23845
24116
|
var SAFE_KEY = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|ignorecase|precomposeunicode|symlinks)|user\..*|init\.defaultbranch|commit\.gpgsign|extensions\.(?:objectformat|refstorage)|branch\..*\.(?:remote|merge)|remote\..*\.fetch)$/;
|
|
23846
24117
|
var literalIn = (value, repo, checkout = false) => {
|
|
23847
|
-
if (/[$`]/.test(value) || !
|
|
24118
|
+
if (/[$`]/.test(value) || !path33.isAbsolute(value))
|
|
23848
24119
|
return false;
|
|
23849
|
-
const real =
|
|
24120
|
+
const real = canonical6(value);
|
|
23850
24121
|
const root = checkout ? checkoutOf2(real)?.root : undefined;
|
|
23851
24122
|
return inScratch(real, repo) || root !== undefined && (repo === null || commonDir(root) === repo);
|
|
23852
24123
|
};
|
|
@@ -23865,45 +24136,45 @@ var configEntries = (text) => {
|
|
|
23865
24136
|
return entries;
|
|
23866
24137
|
};
|
|
23867
24138
|
function gitDirsAt(dir, repo, scan = true) {
|
|
23868
|
-
for (let at = dir;; at =
|
|
23869
|
-
const dotGit =
|
|
24139
|
+
for (let at = dir;; at = path33.dirname(at)) {
|
|
24140
|
+
const dotGit = path33.join(at, ".git");
|
|
23870
24141
|
let gitDir = null;
|
|
23871
24142
|
try {
|
|
23872
|
-
if (
|
|
23873
|
-
gitDir =
|
|
24143
|
+
if (fs22.statSync(dotGit).isDirectory())
|
|
24144
|
+
gitDir = canonical6(dotGit);
|
|
23874
24145
|
else {
|
|
23875
|
-
const named = /^gitdir:\s*(.+?)\s*$/mu.exec(
|
|
24146
|
+
const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs22.readFileSync(dotGit, "utf8"))?.[1];
|
|
23876
24147
|
if (!named)
|
|
23877
24148
|
return null;
|
|
23878
|
-
gitDir =
|
|
24149
|
+
gitDir = canonical6(path33.resolve(at, named));
|
|
23879
24150
|
}
|
|
23880
24151
|
} catch (error) {
|
|
23881
24152
|
if (error.code !== "ENOENT")
|
|
23882
24153
|
return null;
|
|
23883
|
-
if (["HEAD", "objects", "refs"].every((name) =>
|
|
23884
|
-
gitDir =
|
|
24154
|
+
if (["HEAD", "objects", "refs"].every((name) => fs22.existsSync(path33.join(at, name))))
|
|
24155
|
+
gitDir = canonical6(at);
|
|
23885
24156
|
}
|
|
23886
24157
|
if (gitDir !== null) {
|
|
23887
|
-
const common =
|
|
23888
|
-
const shared =
|
|
24158
|
+
const common = path33.join(gitDir, "commondir");
|
|
24159
|
+
const shared = fs22.existsSync(common) ? canonical6(path33.resolve(gitDir, fs22.readFileSync(common, "utf8").trim())) : gitDir;
|
|
23889
24160
|
const dirs = [gitDir, shared];
|
|
23890
|
-
for (const config of scan ? new Set([
|
|
24161
|
+
for (const config of scan ? new Set([path33.join(gitDir, "config"), path33.join(shared, "config")]) : []) {
|
|
23891
24162
|
let text = "";
|
|
23892
24163
|
try {
|
|
23893
|
-
text =
|
|
24164
|
+
text = fs22.readFileSync(config, "utf8");
|
|
23894
24165
|
} catch {
|
|
23895
24166
|
continue;
|
|
23896
24167
|
}
|
|
23897
24168
|
for (const [key, value] of configEntries(text)) {
|
|
23898
24169
|
if (key === "core.worktree")
|
|
23899
|
-
dirs.push(
|
|
24170
|
+
dirs.push(canonical6(path33.resolve(gitDir, value)));
|
|
23900
24171
|
else if (/^remote\..*\.url$/.test(key) ? !literalIn(value, repo, true) : !SAFE_KEY.test(key))
|
|
23901
24172
|
return null;
|
|
23902
24173
|
}
|
|
23903
24174
|
}
|
|
23904
24175
|
return dirs;
|
|
23905
24176
|
}
|
|
23906
|
-
if (
|
|
24177
|
+
if (path33.dirname(at) === at)
|
|
23907
24178
|
return [];
|
|
23908
24179
|
}
|
|
23909
24180
|
}
|
|
@@ -24043,10 +24314,10 @@ var gitKind = (args, local = () => true) => {
|
|
|
24043
24314
|
return GIT_VERBS[verb].startsWith("+") ? "write" : "read";
|
|
24044
24315
|
};
|
|
24045
24316
|
var remoteIn = (dir, name, repo) => {
|
|
24046
|
-
const shared =
|
|
24317
|
+
const shared = path33.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
|
|
24047
24318
|
if (!shared)
|
|
24048
24319
|
return false;
|
|
24049
|
-
const url = configEntries(
|
|
24320
|
+
const url = configEntries(fs22.readFileSync(path33.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
|
|
24050
24321
|
return url !== undefined && literalIn(url, repo, true);
|
|
24051
24322
|
};
|
|
24052
24323
|
var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
@@ -24060,7 +24331,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
24060
24331
|
const lead = [];
|
|
24061
24332
|
while (/^\w+\+?=/.test(words[at] ?? ""))
|
|
24062
24333
|
lead.push(words[at++]);
|
|
24063
|
-
const name =
|
|
24334
|
+
const name = path33.basename(words[at] ?? "");
|
|
24064
24335
|
let start = words.findIndex((word) => /(?:^|[\\/])git(?:\.exe)?(?:=|$)/.test(word));
|
|
24065
24336
|
if (start > at) {
|
|
24066
24337
|
if (/^(?:grep|egrep|rg|echo|printf|ls|wc|head|tail|cat|which|type|test|\[|cd|mkdir)$/.test(name) || name === "command" && /^-[vV]$/.test(words[at + 1] ?? ""))
|
|
@@ -24071,7 +24342,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
24071
24342
|
if (start >= 0 && words[start].includes("="))
|
|
24072
24343
|
why = "git is redefined";
|
|
24073
24344
|
const run = words[start] ?? "";
|
|
24074
|
-
if (run.includes("/") && (!
|
|
24345
|
+
if (run.includes("/") && (!path33.isAbsolute(run) || literalIn(run, repo, true)))
|
|
24075
24346
|
why ??= `\`${run}\` is not the system git`;
|
|
24076
24347
|
if (segment.expands?.includes(at) && name !== "[" || /\{[^}]*,/.test(words[at] ?? ""))
|
|
24077
24348
|
why = "the command's name is expanded by the shell";
|
|
@@ -24096,13 +24367,13 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
24096
24367
|
const args = words[index] === "--version" ? ["version"] : words.slice(index);
|
|
24097
24368
|
if (!why && start >= 0) {
|
|
24098
24369
|
const local = (source, remote) => remote && /^[\w-][\w.-]*$/.test(source) ? remoteIn(dir, source, repo) : literalIn(source, repo, true);
|
|
24099
|
-
const runsIn =
|
|
24370
|
+
const runsIn = path33.isAbsolute(dir) ? dir : cwd && path33.resolve(cwd, dir);
|
|
24100
24371
|
const home = runsIn && checkoutOf2(runsIn);
|
|
24101
24372
|
const fetches = args[0] === "fetch" && plainFetch(args.slice(1)) && home && (home.workit || commonDir(home.root) === repo) && !words.some((word) => /^--[gw]/.test(word));
|
|
24102
24373
|
if (!fetches && !gitKind(args, local))
|
|
24103
24374
|
why = `\`git ${args.slice(0, 2).join(" ")}\` is not allowed`;
|
|
24104
24375
|
}
|
|
24105
|
-
const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(
|
|
24376
|
+
const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path33.basename(word)));
|
|
24106
24377
|
const scripts = [
|
|
24107
24378
|
...words.filter((_, after) => shell >= 0 && after > shell && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(words[after - 1])),
|
|
24108
24379
|
...shell < 0 ? [] : segment.stdin ?? []
|
|
@@ -24147,7 +24418,7 @@ var judgeVerbRefused = (args) => {
|
|
|
24147
24418
|
var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
|
|
24148
24419
|
var CLI_ENTRY = /(?:^|[=\\/])(?:workit(?:\.(?:exe|cmd|[cm]?js))?|@workit-dev\/cli(?:@\S*)?)$|(?:workit-cli|@workit-dev[\\/]cli)[\\/](?:src[\\/](?:index|main)|dist[\\/]index)\.[cm]?[jt]sx?$/;
|
|
24149
24420
|
var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
|
|
24150
|
-
const name =
|
|
24421
|
+
const name = path33.basename(words[0] ?? "").toLowerCase();
|
|
24151
24422
|
if (name === "alias")
|
|
24152
24423
|
return words.flatMap((word) => {
|
|
24153
24424
|
const set = /^([\w-]+)=(.*)$/s.exec(word);
|
|
@@ -24176,11 +24447,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
|
|
|
24176
24447
|
return why;
|
|
24177
24448
|
}
|
|
24178
24449
|
const { words } = segment;
|
|
24179
|
-
const runs = (word = "") => RUNS.test(
|
|
24450
|
+
const runs = (word = "") => RUNS.test(path33.basename(word).toLowerCase());
|
|
24180
24451
|
let at = 0;
|
|
24181
24452
|
while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
|
|
24182
24453
|
at++;
|
|
24183
|
-
const name =
|
|
24454
|
+
const name = path33.basename(words[at] ?? "").toLowerCase();
|
|
24184
24455
|
const args = words.slice(at + 1);
|
|
24185
24456
|
const unseen = `\`${words.join(" ").slice(0, 80)}\` runs a script Workit cannot read (piped, on stdin, a process substitution or eval): write the case to a file in ${SCRATCH} and dispatch it from a test instead`;
|
|
24186
24457
|
if (/^(?:cd|chdir|pushd|popd)$/.test(name))
|
|
@@ -24262,9 +24533,9 @@ var judgeDeny = (input, what, target, retry) => {
|
|
|
24262
24533
|
const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
|
|
24263
24534
|
const root = checkoutOf2(input.cwd)?.root;
|
|
24264
24535
|
const candidate = target ? checkoutOf2(target)?.root : undefined;
|
|
24265
|
-
const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ?
|
|
24266
|
-
const scratch = root ? `${
|
|
24267
|
-
const call = root ? retry?.((other ??
|
|
24536
|
+
const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path33.join(candidate, SCRATCH) : undefined;
|
|
24537
|
+
const scratch = root ? `${path33.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
|
|
24538
|
+
const call = root ? retry?.((other ?? path33.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
|
|
24268
24539
|
const unblock = call ? `Retry as: ${call}` : "Why: write only there (mkdir -p it); a fix the candidate needs is a finding (`workit finding record`).";
|
|
24269
24540
|
return {
|
|
24270
24541
|
kind: "deny",
|
|
@@ -24275,9 +24546,9 @@ ${unblock}`,
|
|
|
24275
24546
|
};
|
|
24276
24547
|
var movedInto = (command, cwd, target, dir) => {
|
|
24277
24548
|
for (const { words, redirects } of segmentsOf(command))
|
|
24278
|
-
for (const word of [...redirects, ...
|
|
24279
|
-
if (
|
|
24280
|
-
const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${
|
|
24549
|
+
for (const word of [...redirects, ...path33.basename(words[0] ?? "") === "tee" ? words : []])
|
|
24550
|
+
if (path33.resolve(cwd, word) === path33.resolve(cwd, target)) {
|
|
24551
|
+
const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path33.basename(word)}`);
|
|
24281
24552
|
return moved === command ? null : moved;
|
|
24282
24553
|
}
|
|
24283
24554
|
return null;
|
|
@@ -24288,20 +24559,20 @@ function confineJudge(input, targets, placeholders = placeholdersOf(targets), co
|
|
|
24288
24559
|
return NONE5;
|
|
24289
24560
|
const judged = checkoutOf2(input.cwd);
|
|
24290
24561
|
const repo = judged ? commonDir(judged.root) : null;
|
|
24291
|
-
const scratch = (real) => inScratch(real, repo) || [
|
|
24292
|
-
const [host, , session] =
|
|
24562
|
+
const scratch = (real) => inScratch(real, repo) || [os10.tmpdir(), "/tmp"].some((dir) => {
|
|
24563
|
+
const [host, , session] = path33.relative(canonical6(dir), real).split(path33.sep);
|
|
24293
24564
|
return /^claude-\d+$/.test(host) && session === input.session.id;
|
|
24294
24565
|
});
|
|
24295
24566
|
for (const target of targets) {
|
|
24296
|
-
const resolved =
|
|
24567
|
+
const resolved = path33.resolve(target);
|
|
24297
24568
|
if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
|
|
24298
24569
|
return judgeDeny(input, "it writes to a path Workit cannot resolve", undefined, () => {
|
|
24299
24570
|
const literal = command && literalForm(command, refsOf([target]));
|
|
24300
24571
|
return literal === command ? null : literal;
|
|
24301
24572
|
});
|
|
24302
|
-
const real =
|
|
24303
|
-
const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(
|
|
24304
|
-
const gitDirs = runsGit ? gitDirsAt(
|
|
24573
|
+
const real = canonical6(target);
|
|
24574
|
+
const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path33.basename(target));
|
|
24575
|
+
const gitDirs = runsGit ? gitDirsAt(path33.dirname(real), repo) : [];
|
|
24305
24576
|
if (gitDirs === null)
|
|
24306
24577
|
return judgeDeny(input, `git in ${shown(target)} uses a git dir or config Workit cannot check`);
|
|
24307
24578
|
if (runsGit ? gitDirs.length > 0 ? gitDirs.every(scratch) : scratch(real) : scratch(real) && !inGitDir(real))
|
|
@@ -24367,7 +24638,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
|
|
|
24367
24638
|
let git = [];
|
|
24368
24639
|
try {
|
|
24369
24640
|
git = rawInvocations(command, dialect).flatMap(({ tool, dir, args }) => tool === "git" && (args[0] === "push" || leadOwnedGit(args) || gitKind(args) === "write" && !/^(?:init|clone)$/.test(args[0]) && !(args[0] === "fetch" && plainFetch(args.slice(1)))) ? [
|
|
24370
|
-
|
|
24641
|
+
path33.join(dir === undefined ? UNKNOWN_DIR : path33.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
|
|
24371
24642
|
] : []);
|
|
24372
24643
|
} catch {}
|
|
24373
24644
|
const lists = [
|
|
@@ -24412,17 +24683,17 @@ var judgeChecksLine = (cwd) => {
|
|
|
24412
24683
|
|
|
24413
24684
|
// packages/workit-core/src/hooks/standing.ts
|
|
24414
24685
|
var readPlans = (store) => {
|
|
24415
|
-
const dir =
|
|
24686
|
+
const dir = path34.join(store, "fanouts");
|
|
24416
24687
|
let names;
|
|
24417
24688
|
try {
|
|
24418
|
-
names =
|
|
24689
|
+
names = fs23.readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
24419
24690
|
} catch {
|
|
24420
24691
|
return [];
|
|
24421
24692
|
}
|
|
24422
24693
|
const plans = [];
|
|
24423
24694
|
for (const name of names) {
|
|
24424
24695
|
try {
|
|
24425
|
-
const raw = JSON.parse(
|
|
24696
|
+
const raw = JSON.parse(fs23.readFileSync(path34.join(dir, name), "utf8"));
|
|
24426
24697
|
if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
|
|
24427
24698
|
continue;
|
|
24428
24699
|
const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
|
|
@@ -24631,13 +24902,13 @@ var cdWorkitSplit = (command) => {
|
|
|
24631
24902
|
};
|
|
24632
24903
|
|
|
24633
24904
|
// packages/workit-core/src/hooks/spawn-gate.ts
|
|
24634
|
-
import
|
|
24635
|
-
import
|
|
24905
|
+
import fs24 from "node:fs";
|
|
24906
|
+
import path36 from "node:path";
|
|
24636
24907
|
|
|
24637
24908
|
// packages/workit-core/src/hooks/model-limit.ts
|
|
24638
24909
|
import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync4, readSync, statSync as statSync5 } from "node:fs";
|
|
24639
|
-
import
|
|
24640
|
-
import
|
|
24910
|
+
import os11 from "node:os";
|
|
24911
|
+
import path35 from "node:path";
|
|
24641
24912
|
var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
24642
24913
|
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
24643
24914
|
var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
|
|
@@ -24835,17 +25106,17 @@ var firstPrompt = (file) => {
|
|
|
24835
25106
|
var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
|
|
24836
25107
|
var listDir = (dir) => {
|
|
24837
25108
|
try {
|
|
24838
|
-
return readdirSync4(dir).map((name) =>
|
|
25109
|
+
return readdirSync4(dir).map((name) => path35.join(dir, name));
|
|
24839
25110
|
} catch {
|
|
24840
25111
|
return [];
|
|
24841
25112
|
}
|
|
24842
25113
|
};
|
|
24843
25114
|
var SCAN_MS = 30 * 60000;
|
|
24844
25115
|
var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
24845
|
-
const projects =
|
|
24846
|
-
const project =
|
|
25116
|
+
const projects = path35.join(env.CLAUDE_CONFIG_DIR || path35.join(env.HOME || os11.homedir(), ".claude"), "projects");
|
|
25117
|
+
const project = path35.join(projects, claudeProjectSlug(cwd));
|
|
24847
25118
|
const notes = [];
|
|
24848
|
-
const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(
|
|
25119
|
+
const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path35.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
|
|
24849
25120
|
for (const { file, worker } of files)
|
|
24850
25121
|
try {
|
|
24851
25122
|
const stat = statSync5(file);
|
|
@@ -24860,7 +25131,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
|
24860
25131
|
if (!seen)
|
|
24861
25132
|
continue;
|
|
24862
25133
|
notes.push(worker ? redispatchNote(seen, {
|
|
24863
|
-
label: `worker ${
|
|
25134
|
+
label: `worker ${path35.basename(file, ".jsonl")}`,
|
|
24864
25135
|
prompt: firstPrompt(file)
|
|
24865
25136
|
}, now) : `Workit: this session hit a usage limit (${seen.reason}); ${seen.key} is marked exhausted until ${shortTime(seen.until)}. Claude Code runs only Anthropic models: Workit cannot switch this session, so continue on another host or after the reset.`);
|
|
24866
25137
|
} catch {}
|
|
@@ -24959,13 +25230,13 @@ var agentModelDecision = (cwd, tool, options = {}) => {
|
|
|
24959
25230
|
var MADE_WORKTREE = /^WORKTREE:[ \t]*(?!not made yet)\S(?![^\n]*not made yet)/mu;
|
|
24960
25231
|
var namesMade = (word) => {
|
|
24961
25232
|
try {
|
|
24962
|
-
const stat =
|
|
25233
|
+
const stat = fs24.statSync(word);
|
|
24963
25234
|
if (stat.isFile())
|
|
24964
|
-
return stat.size < 1e6 && MADE_WORKTREE.test(
|
|
24965
|
-
const dotGit =
|
|
24966
|
-
const link =
|
|
24967
|
-
const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(
|
|
24968
|
-
return !!admin &&
|
|
25235
|
+
return stat.size < 1e6 && MADE_WORKTREE.test(fs24.readFileSync(word, "utf8"));
|
|
25236
|
+
const dotGit = path36.join(word, ".git");
|
|
25237
|
+
const link = fs24.statSync(dotGit);
|
|
25238
|
+
const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs24.readFileSync(dotGit, "utf8"));
|
|
25239
|
+
return !!admin && fs24.existsSync(path36.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
|
|
24969
25240
|
} catch {
|
|
24970
25241
|
return false;
|
|
24971
25242
|
}
|
|
@@ -25011,8 +25282,8 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
|
|
|
25011
25282
|
|
|
25012
25283
|
// packages/workit-core/src/hooks/teardown.ts
|
|
25013
25284
|
import { spawn } from "node:child_process";
|
|
25014
|
-
import
|
|
25015
|
-
import
|
|
25285
|
+
import fs25 from "node:fs";
|
|
25286
|
+
import path37 from "node:path";
|
|
25016
25287
|
var REAP_INTERVAL_MS = 10 * 60000;
|
|
25017
25288
|
var LOG_MAX_BYTES = 1 << 20;
|
|
25018
25289
|
var ENDS = {
|
|
@@ -25023,9 +25294,9 @@ var ENDS = {
|
|
|
25023
25294
|
};
|
|
25024
25295
|
var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
|
|
25025
25296
|
var HOST_SESSION_VARS = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
|
|
25026
|
-
var teardownDir = (env) =>
|
|
25027
|
-
var teardownLog = (env) =>
|
|
25028
|
-
var reapStamp = (env) =>
|
|
25297
|
+
var teardownDir = (env) => path37.join(stateDir3(env), "procs");
|
|
25298
|
+
var teardownLog = (env) => path37.join(teardownDir(env), "teardown.log");
|
|
25299
|
+
var reapStamp = (env) => path37.join(teardownDir(env), "reap-at-start.stamp");
|
|
25029
25300
|
function spawnDetached(request) {
|
|
25030
25301
|
try {
|
|
25031
25302
|
const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
|
|
@@ -25052,13 +25323,13 @@ var teardownDeps = {
|
|
|
25052
25323
|
var openLog = (env, args) => {
|
|
25053
25324
|
try {
|
|
25054
25325
|
const file = teardownLog(env);
|
|
25055
|
-
|
|
25326
|
+
fs25.mkdirSync(path37.dirname(file), { recursive: true });
|
|
25056
25327
|
let size = 0;
|
|
25057
25328
|
try {
|
|
25058
|
-
size =
|
|
25329
|
+
size = fs25.statSync(file).size;
|
|
25059
25330
|
} catch {}
|
|
25060
|
-
const fd =
|
|
25061
|
-
|
|
25331
|
+
const fd = fs25.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
|
|
25332
|
+
fs25.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
|
|
25062
25333
|
`);
|
|
25063
25334
|
return fd;
|
|
25064
25335
|
} catch {
|
|
@@ -25070,7 +25341,7 @@ function runCli(args, env) {
|
|
|
25070
25341
|
try {
|
|
25071
25342
|
const cli = locateWorkitCli2({ env });
|
|
25072
25343
|
const cwd = teardownDir(env);
|
|
25073
|
-
|
|
25344
|
+
fs25.mkdirSync(cwd, { recursive: true });
|
|
25074
25345
|
log = openLog(env, args);
|
|
25075
25346
|
const started = teardownDeps.spawn({
|
|
25076
25347
|
command: cli.command,
|
|
@@ -25080,7 +25351,7 @@ function runCli(args, env) {
|
|
|
25080
25351
|
log
|
|
25081
25352
|
});
|
|
25082
25353
|
if (!started && log !== null)
|
|
25083
|
-
|
|
25354
|
+
fs25.writeSync(log, ` not started
|
|
25084
25355
|
`);
|
|
25085
25356
|
return started;
|
|
25086
25357
|
} catch {
|
|
@@ -25088,7 +25359,7 @@ function runCli(args, env) {
|
|
|
25088
25359
|
} finally {
|
|
25089
25360
|
if (log !== null)
|
|
25090
25361
|
try {
|
|
25091
|
-
|
|
25362
|
+
fs25.closeSync(log);
|
|
25092
25363
|
} catch {}
|
|
25093
25364
|
}
|
|
25094
25365
|
}
|
|
@@ -25107,24 +25378,24 @@ function endSession(end, env = process.env) {
|
|
|
25107
25378
|
var claim2 = (file, now) => {
|
|
25108
25379
|
for (let attempt = 0;attempt < 2; attempt += 1)
|
|
25109
25380
|
try {
|
|
25110
|
-
|
|
25381
|
+
fs25.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
|
|
25111
25382
|
return true;
|
|
25112
25383
|
} catch (error) {
|
|
25113
25384
|
if (error.code !== "EEXIST")
|
|
25114
25385
|
return false;
|
|
25115
25386
|
let held = Number.NaN;
|
|
25116
25387
|
try {
|
|
25117
|
-
held = Number(
|
|
25388
|
+
held = Number(fs25.readFileSync(file, "utf8"));
|
|
25118
25389
|
} catch {}
|
|
25119
25390
|
if (now - held < REAP_INTERVAL_MS)
|
|
25120
25391
|
return false;
|
|
25121
|
-
|
|
25392
|
+
fs25.rmSync(file, { force: true });
|
|
25122
25393
|
}
|
|
25123
25394
|
return false;
|
|
25124
25395
|
};
|
|
25125
25396
|
var fresh = (stamp, now) => {
|
|
25126
25397
|
try {
|
|
25127
|
-
const last = Number(
|
|
25398
|
+
const last = Number(fs25.readFileSync(stamp, "utf8"));
|
|
25128
25399
|
return now - last < REAP_INTERVAL_MS && last <= now;
|
|
25129
25400
|
} catch {
|
|
25130
25401
|
return false;
|
|
@@ -25137,7 +25408,7 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
25137
25408
|
try {
|
|
25138
25409
|
if (fresh(stamp, now))
|
|
25139
25410
|
return false;
|
|
25140
|
-
|
|
25411
|
+
fs25.mkdirSync(path37.dirname(stamp), { recursive: true });
|
|
25141
25412
|
if (!claim2(lock, now))
|
|
25142
25413
|
return false;
|
|
25143
25414
|
} catch {
|
|
@@ -25150,12 +25421,12 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
25150
25421
|
started = runCli(["stop", "--orphans", "--reason", "session-start"], env);
|
|
25151
25422
|
if (started) {
|
|
25152
25423
|
const temp = `${stamp}.${process.pid}`;
|
|
25153
|
-
|
|
25154
|
-
|
|
25424
|
+
fs25.writeFileSync(temp, String(now), { mode: 384 });
|
|
25425
|
+
fs25.renameSync(temp, stamp);
|
|
25155
25426
|
}
|
|
25156
25427
|
} catch {} finally {
|
|
25157
25428
|
try {
|
|
25158
|
-
|
|
25429
|
+
fs25.rmSync(lock, { force: true });
|
|
25159
25430
|
} catch {}
|
|
25160
25431
|
}
|
|
25161
25432
|
return started;
|
|
@@ -26157,7 +26428,7 @@ var dispatchHook = (adapter, raw, env = process.env) => {
|
|
|
26157
26428
|
};
|
|
26158
26429
|
// packages/workit-core/src/hooks/deadline.ts
|
|
26159
26430
|
import { appendFileSync, mkdirSync as mkdirSync4 } from "node:fs";
|
|
26160
|
-
import
|
|
26431
|
+
import path38 from "node:path";
|
|
26161
26432
|
var HOOK_SKIP_TEXT = "workit context skipped: host under load";
|
|
26162
26433
|
var HOOK_DEADLINE_MS = 8000;
|
|
26163
26434
|
var HOST_DEADLINES = {
|
|
@@ -26175,7 +26446,7 @@ var hookDeadlineMs = (env, host = "", native) => {
|
|
|
26175
26446
|
const row = HOST_DEADLINES[host];
|
|
26176
26447
|
return override(env) ?? (row ? native === undefined ? Math.min(...Object.values(row)) : row[native] ?? row[""] : HOOK_DEADLINE_MS);
|
|
26177
26448
|
};
|
|
26178
|
-
var skipsFile = (stateDir) =>
|
|
26449
|
+
var skipsFile = (stateDir) => path38.join(stateDir, HOOK_SKIPS_FILE);
|
|
26179
26450
|
var recordHookSkip = (skip, stateDir = resolveStateDir()) => {
|
|
26180
26451
|
try {
|
|
26181
26452
|
mkdirSync4(stateDir, { recursive: true });
|