@workit-dev/codex 2.22.1 → 2.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,10 @@
2
2
  import {
3
3
  configDir2,
4
4
  stateDir3,
5
+ folderSlug2,
6
+ folderStoreDir2,
5
7
  migrateLegacyDirs2
6
- } from "./workit-hook-7jv519ep.js";
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-x482fqpj.js";
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-btkg30rw.js";
31
+ } from "./workit-hook-mer435q8.js";
30
32
  import {
31
33
  locateWorkitCli2
32
- } from "./workit-hook-azjr1ew1.js";
34
+ } from "./workit-hook-agyvx03a.js";
33
35
  import {
34
36
  recordHookRun2
35
- } from "./workit-hook-xdv92sjp.js";
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 fs14 from "node:fs";
66
- import path19 from "node:path";
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,317 @@ ${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
+ judgedStale: () => {}
9392
+ };
9393
+ var tempSeq = 0;
9394
+ var tempBeside = (file) => path8.join(path8.dirname(file), `.${path8.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
9395
+ var copyInto = (from, to) => {
9396
+ const stat = fs4.lstatSync(from);
9397
+ if (stat.isDirectory()) {
9398
+ fs4.mkdirSync(to, { recursive: true });
9399
+ for (const name of fs4.readdirSync(from))
9400
+ copyInto(path8.join(from, name), path8.join(to, name));
9401
+ return;
9402
+ }
9403
+ if (exists(to))
9404
+ throw new Error(`${to} appeared during the move`);
9405
+ const temp = tempBeside(to);
9406
+ try {
9407
+ if (stat.isSymbolicLink())
9408
+ fs4.symlinkSync(fs4.readlinkSync(from), temp);
9409
+ else
9410
+ folderStoreIo.copyFile(from, temp);
9411
+ folderStoreIo.rename(temp, to);
9412
+ } catch (error) {
9413
+ fs4.rmSync(temp, { force: true });
9414
+ throw error;
9415
+ }
9416
+ };
9417
+ var sameFile = (left, right) => {
9418
+ try {
9419
+ const [a, b] = [fs4.lstatSync(left), fs4.lstatSync(right)];
9420
+ if (!a.isFile() || !b.isFile() || a.size !== b.size)
9421
+ return false;
9422
+ return fs4.readFileSync(left).equals(fs4.readFileSync(right));
9423
+ } catch {
9424
+ return false;
9425
+ }
9426
+ };
9427
+ var merge2 = (from, to, rel, moved) => {
9428
+ if (isV2TaskStub(rel))
9429
+ return [];
9430
+ if (!exists(to)) {
9431
+ try {
9432
+ folderStoreIo.rename(from, to);
9433
+ } catch {
9434
+ try {
9435
+ copyInto(from, to);
9436
+ fs4.rmSync(from, { recursive: true, force: true });
9437
+ } catch {
9438
+ return exists(from) ? [rel] : [];
9439
+ }
9440
+ }
9441
+ moved.push(rel);
9442
+ return [];
9443
+ }
9444
+ if (sameFile(from, to)) {
9445
+ fs4.rmSync(from, { force: true });
9446
+ moved.push(rel);
9447
+ return [];
9448
+ }
9449
+ if (!isDir(from) || !isDir(to))
9450
+ return [rel];
9451
+ const kept = fs4.readdirSync(from).flatMap((name) => merge2(path8.join(from, name), path8.join(to, name), `${rel}/${name}`, moved));
9452
+ try {
9453
+ if (fs4.readdirSync(from).length === 0)
9454
+ fs4.rmdirSync(from);
9455
+ } catch {}
9456
+ return kept;
9457
+ };
9458
+ var LOCK_STALE_MS = 1e4;
9459
+ var LOCK_WAIT_MS = 250;
9460
+ var pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
9461
+ var readLock = (lock) => fs4.readFileSync(lock, "utf8");
9462
+ var staleLock = (lock) => {
9463
+ try {
9464
+ const { mtimeMs } = fs4.statSync(lock);
9465
+ const text = readLock(lock);
9466
+ if (Date.now() - mtimeMs > LOCK_STALE_MS)
9467
+ return { text, mtimeMs };
9468
+ const pid = Number(text.trim().split(/\s+/u)[0]);
9469
+ if (!Number.isInteger(pid) || pid <= 0)
9470
+ return null;
9471
+ try {
9472
+ process.kill(pid, 0);
9473
+ return null;
9474
+ } catch (error) {
9475
+ return error.code === "ESRCH" ? { text, mtimeMs } : null;
9476
+ }
9477
+ } catch {
9478
+ return null;
9479
+ }
9480
+ };
9481
+ var removeStaleLock = (lock, judged) => {
9482
+ const aside = `${lock}.stale-${process.pid}-${crypto.randomUUID()}`;
9483
+ try {
9484
+ fs4.renameSync(lock, aside);
9485
+ } catch {
9486
+ return false;
9487
+ }
9488
+ let same = false;
9489
+ try {
9490
+ same = fs4.statSync(aside).mtimeMs === judged.mtimeMs && readLock(aside) === judged.text;
9491
+ } catch {}
9492
+ if (!same)
9493
+ try {
9494
+ fs4.linkSync(aside, lock);
9495
+ } catch {}
9496
+ fs4.rmSync(aside, { force: true });
9497
+ return same;
9498
+ };
9499
+ var takeMoveLock = (target) => {
9500
+ const lock = `${target}.lock`;
9501
+ const mine = `${process.pid} ${crypto.randomUUID()}
9502
+ `;
9503
+ const deadline = Date.now() + LOCK_WAIT_MS;
9504
+ for (;; ) {
9505
+ try {
9506
+ const fd = fs4.openSync(lock, "wx", 384);
9507
+ fs4.writeSync(fd, mine);
9508
+ fs4.closeSync(fd);
9509
+ return () => {
9510
+ try {
9511
+ if (readLock(lock) === mine)
9512
+ fs4.rmSync(lock, { force: true });
9513
+ } catch {}
9514
+ };
9515
+ } catch (error) {
9516
+ if (error.code !== "EEXIST")
9517
+ return null;
9518
+ }
9519
+ const stale = staleLock(lock);
9520
+ if (stale) {
9521
+ folderStoreIo.judgedStale();
9522
+ if (removeStaleLock(lock, stale))
9523
+ continue;
9524
+ }
9525
+ if (Date.now() >= deadline)
9526
+ return null;
9527
+ pause(25);
9528
+ }
9529
+ };
9530
+ var canonical2 = (dir) => {
9531
+ try {
9532
+ return fs4.realpathSync.native(dir);
9533
+ } catch {
9534
+ return path8.resolve(dir);
9535
+ }
9536
+ };
9537
+ var below = (parent, child) => {
9538
+ const rel = path8.relative(parent, child);
9539
+ return rel !== "" && !rel.startsWith("..") && !path8.isAbsolute(rel);
9540
+ };
9541
+ var TEST_RUN_REFUSALS = "folder-store-refusals.log";
9542
+ var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os4.tmpdir()) => {
9543
+ if (env.WORKIT_TEST_RUN === undefined || !hasStray)
9544
+ return null;
9545
+ const real = canonical2(folder);
9546
+ const tmp = canonical2(tempDir);
9547
+ if (below(tmp, real))
9548
+ return null;
9549
+ 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)`;
9550
+ };
9551
+ function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
9552
+ `)) {
9553
+ const workit = path8.join(folder, ".workit");
9554
+ const names = strayEntries(workit);
9555
+ const refusal = testRunFolderRefusal(folder, names.length > 0);
9556
+ if (refusal) {
9557
+ const run = process.env.WORKIT_TEST_RUN ?? "";
9558
+ if (path8.isAbsolute(run))
9559
+ try {
9560
+ fs4.appendFileSync(path8.join(run, TEST_RUN_REFUSALS), `${refusal}
9561
+ `);
9562
+ } catch {}
9563
+ throw new Error(refusal);
9564
+ }
9565
+ if (names.length === 0 || v2Workspace(workit) === true)
9566
+ return null;
9567
+ try {
9568
+ fs4.mkdirSync(path8.dirname(target), { recursive: true });
9569
+ } catch {
9570
+ return null;
9571
+ }
9572
+ const release = takeMoveLock(target);
9573
+ if (!release)
9574
+ return null;
9575
+ try {
9576
+ return moveLocked(workit, target, note);
9577
+ } finally {
9578
+ release();
9579
+ }
9580
+ }
9581
+ function moveLocked(workit, target, note) {
9582
+ const names = strayEntries(workit);
9583
+ if (names.length === 0 || v2Workspace(workit) === true)
9584
+ return null;
9585
+ try {
9586
+ fs4.mkdirSync(target, { recursive: true });
9587
+ } catch {
9588
+ return null;
9589
+ }
9590
+ const result = { from: workit, to: target, moved: [], kept: [] };
9591
+ for (const name of names) {
9592
+ result.kept.push(...merge2(path8.join(workit, name), path8.join(target, name), name, result.moved));
9593
+ }
9594
+ const left = (() => {
9595
+ try {
9596
+ return fs4.readdirSync(workit);
9597
+ } catch {
9598
+ return [];
9599
+ }
9600
+ })();
9601
+ const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path8.join(workit, name)));
9602
+ if (!v2Left && result.kept.length === 0) {
9603
+ fs4.rmSync(path8.join(workit, MARKER), { force: true });
9604
+ if (generatedIgnore(path8.join(workit, ".gitignore")))
9605
+ fs4.rmSync(path8.join(workit, ".gitignore"), { force: true });
9606
+ }
9607
+ const pointer = path8.join(workit, MOVED_POINTER);
9608
+ let wrote = false;
9609
+ if (result.kept.length > 0) {
9610
+ const text = `Workit keeps this folder's state in ${target}.
9611
+ Not moved, because the store there already has them or the move failed: ${result.kept.join(", ")}.
9612
+ Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
9613
+ `;
9614
+ try {
9615
+ if (!exists(pointer) || fs4.readFileSync(pointer, "utf8") !== text) {
9616
+ fs4.writeFileSync(pointer, text);
9617
+ wrote = true;
9618
+ }
9619
+ } catch {}
9620
+ } else {
9621
+ fs4.rmSync(pointer, { force: true });
9622
+ try {
9623
+ if (fs4.readdirSync(workit).length === 0)
9624
+ fs4.rmdirSync(workit);
9625
+ } catch {}
9626
+ }
9627
+ if (result.moved.length > 0 || wrote)
9628
+ 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)`);
9629
+ return result;
9630
+ }
9631
+
9632
+ // packages/workit-core/src/store/paths.ts
9322
9633
  var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
9323
9634
  var gitRun = (cwd, args) => {
9324
9635
  const run = spawnSync7("git", args, {
@@ -9346,7 +9657,7 @@ var gitRun = (cwd, args) => {
9346
9657
  var shortHash = (value) => createHash6("sha256").update(value).digest("hex").slice(0, 12);
9347
9658
  var real = (file) => {
9348
9659
  try {
9349
- return fs4.realpathSync.native(file);
9660
+ return fs5.realpathSync.native(file);
9350
9661
  } catch {
9351
9662
  return file;
9352
9663
  }
@@ -9360,14 +9671,14 @@ var DISCOVERY_ENV = [
9360
9671
  ];
9361
9672
  var isGitDir = (dir) => {
9362
9673
  try {
9363
- return fs4.statSync(path8.join(dir, "HEAD")).isFile() && fs4.statSync(path8.join(dir, "objects")).isDirectory() && fs4.statSync(path8.join(dir, "refs")).isDirectory();
9674
+ return fs5.statSync(path9.join(dir, "HEAD")).isFile() && fs5.statSync(path9.join(dir, "objects")).isDirectory() && fs5.statSync(path9.join(dir, "refs")).isDirectory();
9364
9675
  } catch {
9365
9676
  return false;
9366
9677
  }
9367
9678
  };
9368
9679
  var reftableRefs = (common) => {
9369
9680
  try {
9370
- return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs4.readFileSync(path8.join(common, "config"), "utf8"));
9681
+ return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs5.readFileSync(path9.join(common, "config"), "utf8"));
9371
9682
  } catch {
9372
9683
  return false;
9373
9684
  }
@@ -9380,17 +9691,17 @@ function fastGit(root) {
9380
9691
  for (;; ) {
9381
9692
  let stat;
9382
9693
  try {
9383
- stat = fs4.statSync(dir);
9694
+ stat = fs5.statSync(dir);
9384
9695
  } catch {
9385
9696
  return null;
9386
9697
  }
9387
9698
  if (device !== null && stat.dev !== device)
9388
9699
  return { kind: "none" };
9389
9700
  device = stat.dev;
9390
- const dotGit = path8.join(dir, ".git");
9701
+ const dotGit = path9.join(dir, ".git");
9391
9702
  let entry = null;
9392
9703
  try {
9393
- entry = fs4.statSync(dotGit);
9704
+ entry = fs5.statSync(dotGit);
9394
9705
  } catch {}
9395
9706
  let gitDir = null;
9396
9707
  let top = null;
@@ -9401,26 +9712,26 @@ function fastGit(root) {
9401
9712
  else if (entry.isFile()) {
9402
9713
  let text = "";
9403
9714
  try {
9404
- text = fs4.readFileSync(dotGit, "utf8");
9715
+ text = fs5.readFileSync(dotGit, "utf8");
9405
9716
  } catch {
9406
9717
  return null;
9407
9718
  }
9408
9719
  const match = /^gitdir: (.+)$/mu.exec(text);
9409
9720
  if (!match)
9410
9721
  return null;
9411
- gitDir = path8.resolve(dir, match[1].trim());
9722
+ gitDir = path9.resolve(dir, match[1].trim());
9412
9723
  } else
9413
9724
  return null;
9414
- if (!fs4.existsSync(path8.join(gitDir, "HEAD")))
9725
+ if (!fs5.existsSync(path9.join(gitDir, "HEAD")))
9415
9726
  return null;
9416
9727
  } else if (isGitDir(dir))
9417
9728
  gitDir = dir;
9418
9729
  if (gitDir) {
9419
9730
  let common = gitDir;
9420
9731
  try {
9421
- common = path8.resolve(gitDir, fs4.readFileSync(path8.join(gitDir, "commondir"), "utf8").trim());
9732
+ common = path9.resolve(gitDir, fs5.readFileSync(path9.join(gitDir, "commondir"), "utf8").trim());
9422
9733
  } catch {}
9423
- if (!fs4.existsSync(path8.join(common, "objects")))
9734
+ if (!fs5.existsSync(path9.join(common, "objects")))
9424
9735
  return null;
9425
9736
  return {
9426
9737
  kind: "repo",
@@ -9430,28 +9741,33 @@ function fastGit(root) {
9430
9741
  reftable: reftableRefs(common)
9431
9742
  };
9432
9743
  }
9433
- const parent = path8.dirname(dir);
9744
+ const parent = path9.dirname(dir);
9434
9745
  if (parent === dir)
9435
9746
  return { kind: "none" };
9436
9747
  dir = parent;
9437
9748
  }
9438
9749
  }
9750
+ var outsideGit = (root) => {
9751
+ const dir = folderStoreDir2(root);
9752
+ migrateFolderStore(root, dir);
9753
+ return { dir, shared: false, top: null };
9754
+ };
9439
9755
  function resolveStore(root) {
9440
- root = path8.resolve(root);
9756
+ root = path9.resolve(root);
9441
9757
  let stat = null;
9442
9758
  try {
9443
- stat = fs4.statSync(root);
9759
+ stat = fs5.statSync(root);
9444
9760
  } catch {}
9445
9761
  if (!stat)
9446
9762
  return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
9447
9763
  if (!stat.isDirectory())
9448
- return { dir: path8.join(root, ".workit"), shared: false, top: null };
9764
+ return { dir: path9.join(root, ".workit"), shared: false, top: null };
9449
9765
  const fast = fastGit(root);
9450
9766
  if (fast?.kind === "none")
9451
- return { dir: path8.join(root, ".workit"), shared: false, top: null };
9767
+ return outsideGit(root);
9452
9768
  if (fast?.kind === "repo")
9453
9769
  return {
9454
- dir: path8.join(fast.common, "workit"),
9770
+ dir: path9.join(fast.common, "workit"),
9455
9771
  shared: true,
9456
9772
  top: fast.top,
9457
9773
  git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
@@ -9461,20 +9777,20 @@ function resolveStore(root) {
9461
9777
  if (run.ok && common) {
9462
9778
  const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
9463
9779
  return {
9464
- dir: path8.join(real(path8.resolve(root, common)), "workit"),
9780
+ dir: path9.join(real(path9.resolve(root, common)), "workit"),
9465
9781
  shared: true,
9466
9782
  top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
9467
9783
  };
9468
9784
  }
9469
9785
  if (run.missing || !run.ok && NOT_A_REPO.test(run.stderr))
9470
- return { dir: path8.join(root, ".workit"), shared: false, top: null };
9786
+ return outsideGit(root);
9471
9787
  return new Error(`cannot locate the workit store: git rev-parse failed (${run.stderr.trim().split(`
9472
9788
  `)[0] || "no output"}); fix the repository (git status should work here)`);
9473
9789
  }
9474
9790
  var rebasingBranch = (gitDir) => {
9475
9791
  for (const state of ["rebase-merge", "rebase-apply"]) {
9476
9792
  try {
9477
- const ref = fs4.readFileSync(path8.join(gitDir, state, "head-name"), "utf8").trim();
9793
+ const ref = fs5.readFileSync(path9.join(gitDir, state, "head-name"), "utf8").trim();
9478
9794
  const match = /^refs\/heads\/(.+)$/u.exec(ref);
9479
9795
  if (match)
9480
9796
  return match[1];
@@ -9489,7 +9805,7 @@ function resolveTaskKey(root, location) {
9489
9805
  if (location.git && !location.git.reftable) {
9490
9806
  let head = "";
9491
9807
  try {
9492
- head = fs4.readFileSync(path8.join(location.git.gitDir, "HEAD"), "utf8").trim();
9808
+ head = fs5.readFileSync(path9.join(location.git.gitDir, "HEAD"), "utf8").trim();
9493
9809
  } catch {}
9494
9810
  const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
9495
9811
  if (ref && ref[1] !== ".invalid")
@@ -9520,10 +9836,10 @@ function resolveTaskKey(root, location) {
9520
9836
  return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
9521
9837
  }
9522
9838
  function checkoutRootOf(root, location) {
9523
- const resolved = path8.resolve(root);
9839
+ const resolved = path9.resolve(root);
9524
9840
  let canonical = resolved;
9525
9841
  try {
9526
- canonical = fs4.realpathSync(resolved);
9842
+ canonical = fs5.realpathSync(resolved);
9527
9843
  } catch {
9528
9844
  return resolved;
9529
9845
  }
@@ -9533,7 +9849,7 @@ function checkoutRootOf(root, location) {
9533
9849
  if (real(canonical) === found.top)
9534
9850
  return canonical;
9535
9851
  try {
9536
- return fs4.realpathSync(found.top);
9852
+ return fs5.realpathSync(found.top);
9537
9853
  } catch {
9538
9854
  return canonical;
9539
9855
  }
@@ -9545,25 +9861,25 @@ function branchRenames(location) {
9545
9861
  const walk = (dir) => {
9546
9862
  let entries;
9547
9863
  try {
9548
- entries = fs4.readdirSync(dir, { withFileTypes: true });
9864
+ entries = fs5.readdirSync(dir, { withFileTypes: true });
9549
9865
  } catch {
9550
9866
  return;
9551
9867
  }
9552
9868
  for (const entry of entries)
9553
9869
  if (entry.isDirectory())
9554
- walk(path8.join(dir, entry.name));
9870
+ walk(path9.join(dir, entry.name));
9555
9871
  else
9556
- files.push(path8.join(dir, entry.name));
9872
+ files.push(path9.join(dir, entry.name));
9557
9873
  };
9558
- walk(path8.join(path8.dirname(location.dir), "logs", "refs", "heads"));
9874
+ walk(path9.join(path9.dirname(location.dir), "logs", "refs", "heads"));
9559
9875
  if (location.git)
9560
- files.push(path8.join(location.git.gitDir, "logs", "HEAD"));
9876
+ files.push(path9.join(location.git.gitDir, "logs", "HEAD"));
9561
9877
  const seen = new Set;
9562
9878
  const renames = [];
9563
9879
  for (const file of files) {
9564
9880
  let text = "";
9565
9881
  try {
9566
- text = fs4.readFileSync(file, "utf8");
9882
+ text = fs5.readFileSync(file, "utf8");
9567
9883
  } catch {
9568
9884
  continue;
9569
9885
  }
@@ -9588,13 +9904,7 @@ function followRenames(key, boundAt, renames) {
9588
9904
  }
9589
9905
  return current;
9590
9906
  }
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
- };
9907
+ var checkoutSlug = (root) => folderSlug2(root);
9598
9908
 
9599
9909
  // packages/workit-core/src/core/task-contract.ts
9600
9910
  import { createHash as createHash7, randomUUID } from "node:crypto";
@@ -10337,7 +10647,7 @@ function resolveIdRef(kind, ref, ids) {
10337
10647
  return failure2("not_found", `${kind} not found`);
10338
10648
  return failure2("invalid_input", `${kind} prefix ${ref} is ambiguous; candidates: ${matches.join(", ")}`);
10339
10649
  }
10340
- function canonical2(value, seen) {
10650
+ function canonical3(value, seen) {
10341
10651
  if (value === null || typeof value === "boolean" || typeof value === "string") {
10342
10652
  if (typeof value === "string" && invalidUnicode(value))
10343
10653
  throw new TypeError("invalid Unicode");
@@ -10359,7 +10669,7 @@ function canonical2(value, seen) {
10359
10669
  if (!(index in value))
10360
10670
  throw new TypeError("sparse array");
10361
10671
  }
10362
- result = value.map((item) => canonical2(item, seen));
10672
+ result = value.map((item) => canonical3(item, seen));
10363
10673
  } else {
10364
10674
  if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
10365
10675
  throw new TypeError("value is not a JSON object");
@@ -10367,13 +10677,13 @@ function canonical2(value, seen) {
10367
10677
  throw new TypeError("symbol key is not JSON");
10368
10678
  if (Object.keys(value).some((key) => invalidUnicode(key)))
10369
10679
  throw new TypeError("invalid Unicode");
10370
- result = Object.fromEntries(Object.keys(value).toSorted().map((key) => [key, canonical2(value[key], seen)]));
10680
+ result = Object.fromEntries(Object.keys(value).toSorted().map((key) => [key, canonical3(value[key], seen)]));
10371
10681
  }
10372
10682
  seen.delete(value);
10373
10683
  return result;
10374
10684
  }
10375
10685
  function canonicalJson(value) {
10376
- return JSON.stringify(canonical2(value, new Set));
10686
+ return JSON.stringify(canonical3(value, new Set));
10377
10687
  }
10378
10688
  function sha256(value) {
10379
10689
  if (typeof value === "string" && invalidUnicode(value))
@@ -10414,14 +10724,14 @@ function candidateDigest(input) {
10414
10724
 
10415
10725
  // packages/workit-core/src/core/task-evaluation.ts
10416
10726
  import { createHash as createHash10 } from "node:crypto";
10417
- import * as fs13 from "node:fs";
10727
+ import * as fs14 from "node:fs";
10418
10728
  import { spawnSync as spawnSync12 } from "node:child_process";
10419
- import path18 from "node:path";
10729
+ import path19 from "node:path";
10420
10730
 
10421
10731
  // packages/workit-core/src/core/task-read.ts
10422
10732
  import { randomUUID as randomUUID3 } from "node:crypto";
10423
- import * as fs10 from "node:fs";
10424
- import path13 from "node:path";
10733
+ import * as fs11 from "node:fs";
10734
+ import path14 from "node:path";
10425
10735
 
10426
10736
  // node_modules/@openclaw/fs-safe/dist/errors.js
10427
10737
  var OPERATIONAL_CODES = new Set([
@@ -10472,10 +10782,10 @@ function sameFileIdentity(left, right, platform = process.platform) {
10472
10782
  // node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
10473
10783
  import { randomBytes } from "node:crypto";
10474
10784
  import fsSync from "node:fs";
10475
- import path9 from "node:path";
10785
+ import path10 from "node:path";
10476
10786
 
10477
10787
  // node_modules/@openclaw/fs-safe/dist/bounded-read.js
10478
- import fs5 from "node:fs";
10788
+ import fs6 from "node:fs";
10479
10789
 
10480
10790
  // node_modules/@openclaw/fs-safe/dist/byte-budget.js
10481
10791
  function normalizeMaxBytes(value, options = {}) {
@@ -10512,7 +10822,7 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
10512
10822
  let total = 0;
10513
10823
  while (true) {
10514
10824
  const length = nextReadLength(total, maxBytes, scratch.length);
10515
- const bytesRead = fs5.readSync(fd, scratch, 0, length, null);
10825
+ const bytesRead = fs6.readSync(fd, scratch, 0, length, null);
10516
10826
  if (bytesRead === 0) {
10517
10827
  return Buffer.concat(chunks, total);
10518
10828
  }
@@ -10521,9 +10831,9 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
10521
10831
  }
10522
10832
 
10523
10833
  // node_modules/@openclaw/fs-safe/dist/read-open-flags.js
10524
- import fs6 from "node:fs";
10834
+ import fs7 from "node:fs";
10525
10835
  function resolveReadOpenFlags(options) {
10526
- const constants = options?.constants ?? fs6.constants;
10836
+ const constants = options?.constants ?? fs7.constants;
10527
10837
  const noFollow = process.platform !== "win32" && options?.followSymlinks !== true && typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
10528
10838
  const nonBlocking = process.platform !== "win32" && typeof constants.O_NONBLOCK === "number" ? constants.O_NONBLOCK : 0;
10529
10839
  return constants.O_RDONLY | noFollow | nonBlocking;
@@ -10562,13 +10872,13 @@ ${ownershipToken}
10562
10872
  return { raw, ownershipToken };
10563
10873
  }
10564
10874
  function relativeSidecarLockPath(lockRoot, lockPath) {
10565
- const resolved = path9.resolve(lockPath);
10566
- const lexicalRelative = path9.relative(lockRoot.rootDir, resolved);
10567
- const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path9.sep}`) && !path9.isAbsolute(lexicalRelative) ? lexicalRelative : path9.relative(lockRoot.rootReal, resolved);
10568
- if (!relative || relative === ".." || relative.startsWith(`..${path9.sep}`) || path9.isAbsolute(relative)) {
10875
+ const resolved = path10.resolve(lockPath);
10876
+ const lexicalRelative = path10.relative(lockRoot.rootDir, resolved);
10877
+ const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path10.sep}`) && !path10.isAbsolute(lexicalRelative) ? lexicalRelative : path10.relative(lockRoot.rootReal, resolved);
10878
+ if (!relative || relative === ".." || relative.startsWith(`..${path10.sep}`) || path10.isAbsolute(relative)) {
10569
10879
  throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
10570
10880
  }
10571
- return relative.split(path9.sep).join(path9.posix.sep);
10881
+ return relative.split(path10.sep).join(path10.posix.sep);
10572
10882
  }
10573
10883
  function parseSidecarLockPayload(raw, parser) {
10574
10884
  if (parser) {
@@ -10714,8 +11024,8 @@ function getFsSafeLockConfig() {
10714
11024
  }
10715
11025
 
10716
11026
  // node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
10717
- import fs7 from "node:fs";
10718
- import path10 from "node:path";
11027
+ import fs8 from "node:fs";
11028
+ import path11 from "node:path";
10719
11029
 
10720
11030
  // node_modules/@openclaw/fs-safe/dist/timing.js
10721
11031
  function sleepSync(ms) {
@@ -10745,7 +11055,7 @@ function releaseAllSyncHeldLocks() {
10745
11055
  }
10746
11056
  try {
10747
11057
  if (held.fd !== undefined)
10748
- fs7.closeSync(held.fd);
11058
+ fs8.closeSync(held.fd);
10749
11059
  } catch {}
10750
11060
  try {
10751
11061
  removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
@@ -10780,7 +11090,7 @@ function releaseSyncHeldLock(held) {
10780
11090
  if (held.fd !== undefined) {
10781
11091
  const fd = held.fd;
10782
11092
  held.fd = undefined;
10783
- fs7.closeSync(fd);
11093
+ fs8.closeSync(fd);
10784
11094
  }
10785
11095
  removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
10786
11096
  heldLocks.delete(held.normalizedTargetPath);
@@ -10803,29 +11113,29 @@ function createSyncHeldLockHandle(held) {
10803
11113
  };
10804
11114
  }
10805
11115
  function canonicalLockParentSync(parent) {
10806
- return process.platform === "win32" ? fs7.realpathSync.native(parent) : fs7.realpathSync(parent);
11116
+ return process.platform === "win32" ? fs8.realpathSync.native(parent) : fs8.realpathSync(parent);
10807
11117
  }
10808
11118
  function normalizeTargetPath(targetPath) {
10809
- const resolved = path10.resolve(targetPath);
10810
- fs7.mkdirSync(path10.dirname(resolved), { recursive: true });
11119
+ const resolved = path11.resolve(targetPath);
11120
+ fs8.mkdirSync(path11.dirname(resolved), { recursive: true });
10811
11121
  try {
10812
- return path10.join(canonicalLockParentSync(path10.dirname(resolved)), path10.basename(resolved));
11122
+ return path11.join(canonicalLockParentSync(path11.dirname(resolved)), path11.basename(resolved));
10813
11123
  } catch {
10814
11124
  return resolved;
10815
11125
  }
10816
11126
  }
10817
11127
  function boundedLockPath(lockPath, lockRoot) {
10818
- const resolved = path10.resolve(lockPath);
11128
+ const resolved = path11.resolve(lockPath);
10819
11129
  if (!lockRoot)
10820
11130
  return resolved;
10821
11131
  relativeSidecarLockPath(lockRoot, resolved);
10822
- const parent = path10.dirname(resolved);
11132
+ const parent = path11.dirname(resolved);
10823
11133
  const parentReal = canonicalLockParentSync(parent);
10824
- const parentRelative = path10.relative(lockRoot.rootReal, parentReal);
10825
- if (parentRelative === ".." || parentRelative.startsWith(`..${path10.sep}`) || path10.isAbsolute(parentRelative)) {
11134
+ const parentRelative = path11.relative(lockRoot.rootReal, parentReal);
11135
+ if (parentRelative === ".." || parentRelative.startsWith(`..${path11.sep}`) || path11.isAbsolute(parentRelative)) {
10826
11136
  throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
10827
11137
  }
10828
- return path10.join(parentReal, path10.basename(resolved));
11138
+ return path11.join(parentReal, path11.basename(resolved));
10829
11139
  }
10830
11140
  function defaultShouldReclaim(snapshot, staleMs, nowMs) {
10831
11141
  const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
@@ -10835,7 +11145,7 @@ function defaultShouldReclaim(snapshot, staleMs, nowMs) {
10835
11145
  }
10836
11146
  function reclaimGuardExists(reclaimGuardPath) {
10837
11147
  try {
10838
- fs7.lstatSync(reclaimGuardPath);
11148
+ fs8.lstatSync(reclaimGuardPath);
10839
11149
  return true;
10840
11150
  } catch (error) {
10841
11151
  if (error.code === "ENOENT")
@@ -10899,19 +11209,19 @@ function acquireFileLockSync(targetPath, options) {
10899
11209
  const { raw, ownershipToken } = serializeSidecarLockPayload(payload);
10900
11210
  let lockFileCreateDenied = false;
10901
11211
  try {
10902
- const noFollow = process.platform !== "win32" && typeof fs7.constants.O_NOFOLLOW === "number" ? fs7.constants.O_NOFOLLOW : 0;
11212
+ const noFollow = process.platform !== "win32" && typeof fs8.constants.O_NOFOLLOW === "number" ? fs8.constants.O_NOFOLLOW : 0;
10903
11213
  try {
10904
- fd = fs7.openSync(lockPath, fs7.constants.O_WRONLY | fs7.constants.O_CREAT | fs7.constants.O_EXCL | noFollow, 384);
11214
+ fd = fs8.openSync(lockPath, fs8.constants.O_WRONLY | fs8.constants.O_CREAT | fs8.constants.O_EXCL | noFollow, 384);
10905
11215
  } catch (error) {
10906
11216
  lockFileCreateDenied = isTransientLockFileDenial(error, lockPath);
10907
11217
  throw error;
10908
11218
  }
10909
- fs7.writeFileSync(fd, raw, "utf8");
10910
- fs7.fsyncSync(fd);
11219
+ fs8.writeFileSync(fd, raw, "utf8");
11220
+ fs8.fsyncSync(fd);
10911
11221
  const snapshot = {
10912
11222
  raw,
10913
11223
  payload,
10914
- stat: fs7.fstatSync(fd),
11224
+ stat: fs8.fstatSync(fd),
10915
11225
  ownershipToken
10916
11226
  };
10917
11227
  const createdHeld = {
@@ -10946,8 +11256,8 @@ function acquireFileLockSync(targetPath, options) {
10946
11256
  return returnedHandle;
10947
11257
  } catch (error) {
10948
11258
  if (fd !== undefined) {
10949
- const failed = { payload: null, stat: fs7.fstatSync(fd) };
10950
- fs7.closeSync(fd);
11259
+ const failed = { payload: null, stat: fs8.fstatSync(fd) };
11260
+ fs8.closeSync(fd);
10951
11261
  fd = undefined;
10952
11262
  removeSidecarLockIfUnchangedSync(lockPath, failed);
10953
11263
  }
@@ -10996,7 +11306,7 @@ function acquireFileLockSync(targetPath, options) {
10996
11306
  })) {
10997
11307
  let ownsReclaimGuard = false;
10998
11308
  try {
10999
- fs7.mkdirSync(reclaimGuardPath);
11309
+ fs8.mkdirSync(reclaimGuardPath);
11000
11310
  ownsReclaimGuard = true;
11001
11311
  if (removeSidecarLockIfUnchangedSync(lockPath, snapshot))
11002
11312
  continue;
@@ -11009,7 +11319,7 @@ function acquireFileLockSync(targetPath, options) {
11009
11319
  } finally {
11010
11320
  if (ownsReclaimGuard) {
11011
11321
  try {
11012
- fs7.rmdirSync(reclaimGuardPath);
11322
+ fs8.rmdirSync(reclaimGuardPath);
11013
11323
  } catch {}
11014
11324
  }
11015
11325
  }
@@ -11026,13 +11336,13 @@ function acquireFileLockSync(targetPath, options) {
11026
11336
  }
11027
11337
  // packages/workit-core/src/core/package-root.ts
11028
11338
  import { existsSync as existsSync4 } from "node:fs";
11029
- import path11 from "node:path";
11339
+ import path12 from "node:path";
11030
11340
  import { fileURLToPath } from "node:url";
11031
11341
  var packageRoot = () => {
11032
- let dir = path11.dirname(fileURLToPath(import.meta.url));
11342
+ let dir = path12.dirname(fileURLToPath(import.meta.url));
11033
11343
  while (true) {
11034
- const parent = path11.dirname(dir);
11035
- if (existsSync4(path11.join(dir, "package.json")) || parent === dir)
11344
+ const parent = path12.dirname(dir);
11345
+ if (existsSync4(path12.join(dir, "package.json")) || parent === dir)
11036
11346
  return dir;
11037
11347
  dir = parent;
11038
11348
  }
@@ -11040,7 +11350,7 @@ var packageRoot = () => {
11040
11350
 
11041
11351
  // packages/workit-core/src/core/store-lock.ts
11042
11352
  import { spawnSync as spawnSync8 } from "node:child_process";
11043
- import fs8 from "node:fs";
11353
+ import fs9 from "node:fs";
11044
11354
  import { hostname } from "node:os";
11045
11355
  var metadataLockSchema = object({
11046
11356
  pid: number2().int().nonnegative().safe(),
@@ -11083,7 +11393,7 @@ var parseProcStatStart = (stat) => {
11083
11393
  };
11084
11394
  var readProcStat = (pid) => {
11085
11395
  try {
11086
- return fs8.readFileSync(`/proc/${pid}/stat`, "utf8");
11396
+ return fs9.readFileSync(`/proc/${pid}/stat`, "utf8");
11087
11397
  } catch {
11088
11398
  return null;
11089
11399
  }
@@ -11112,7 +11422,7 @@ var processStartOf = (pid, deps = {}) => {
11112
11422
  };
11113
11423
  var readTrimmed = (file) => {
11114
11424
  try {
11115
- return fs8.readFileSync(file, "utf8").trim() || null;
11425
+ return fs9.readFileSync(file, "utf8").trim() || null;
11116
11426
  } catch {
11117
11427
  return null;
11118
11428
  }
@@ -11123,7 +11433,7 @@ var localLockHost = () => {
11123
11433
  return cachedLockHost;
11124
11434
  let pidns = null;
11125
11435
  try {
11126
- pidns = /\[(\d+)\]/.exec(fs8.readlinkSync("/proc/self/ns/pid"))?.[1] ?? null;
11436
+ pidns = /\[(\d+)\]/.exec(fs9.readlinkSync("/proc/self/ns/pid"))?.[1] ?? null;
11127
11437
  } catch {}
11128
11438
  const boot = readTrimmed("/proc/sys/kernel/random/boot_id");
11129
11439
  cachedLockHost = pidns || boot ? `${hostname()}#${pidns ?? "?"}:${boot ?? "?"}` : hostname();
@@ -11169,7 +11479,7 @@ var classifyLockOwner = (payload, ageMs, localHost = localLockHost(), options =
11169
11479
  };
11170
11480
  var ageOf = (file, nowMs) => {
11171
11481
  try {
11172
- return nowMs - fs8.lstatSync(file).mtimeMs;
11482
+ return nowMs - fs9.lstatSync(file).mtimeMs;
11173
11483
  } catch {
11174
11484
  return null;
11175
11485
  }
@@ -11180,7 +11490,7 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
11180
11490
  if (age === null || age <= RECLAIM_GUARD_TTL_MS)
11181
11491
  return false;
11182
11492
  try {
11183
- fs8.rmdirSync(guard);
11493
+ fs9.rmdirSync(guard);
11184
11494
  return true;
11185
11495
  } catch {
11186
11496
  return false;
@@ -11189,8 +11499,8 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
11189
11499
 
11190
11500
  // packages/workit-core/src/store/event-log.ts
11191
11501
  import { randomUUID as randomUUID2 } from "node:crypto";
11192
- import fs9 from "node:fs";
11193
- import path12 from "node:path";
11502
+ import fs10 from "node:fs";
11503
+ import path13 from "node:path";
11194
11504
  var EVENT_VERSION = 1;
11195
11505
 
11196
11506
  class LogDamage extends Error {
@@ -11219,7 +11529,7 @@ var parseEvent = (line, file, offset) => {
11219
11529
  function readLog(file, from = 0, expectSeq = null) {
11220
11530
  let fd;
11221
11531
  try {
11222
- fd = fs9.openSync(file, "r");
11532
+ fd = fs10.openSync(file, "r");
11223
11533
  } catch (error) {
11224
11534
  if (error.code === "ENOENT")
11225
11535
  return null;
@@ -11228,13 +11538,13 @@ function readLog(file, from = 0, expectSeq = null) {
11228
11538
  let bytes;
11229
11539
  let size;
11230
11540
  try {
11231
- size = fs9.fstatSync(fd).size;
11541
+ size = fs10.fstatSync(fd).size;
11232
11542
  if (from > size)
11233
11543
  throw new LogDamage(`${file}: shorter than its snapshot`);
11234
11544
  bytes = Buffer.alloc(size - from);
11235
11545
  let read = 0;
11236
11546
  while (read < bytes.length) {
11237
- const got = fs9.readSync(fd, bytes, read, bytes.length - read, from + read);
11547
+ const got = fs10.readSync(fd, bytes, read, bytes.length - read, from + read);
11238
11548
  if (got === 0)
11239
11549
  break;
11240
11550
  read += got;
@@ -11242,7 +11552,7 @@ function readLog(file, from = 0, expectSeq = null) {
11242
11552
  bytes = bytes.subarray(0, read);
11243
11553
  size = from + read;
11244
11554
  } finally {
11245
- fs9.closeSync(fd);
11555
+ fs10.closeSync(fd);
11246
11556
  }
11247
11557
  const events = [];
11248
11558
  let start = 0;
@@ -11267,11 +11577,11 @@ function readLog(file, from = 0, expectSeq = null) {
11267
11577
  }
11268
11578
  var fsyncDirectory = (dir) => {
11269
11579
  try {
11270
- const fd = fs9.openSync(dir, "r");
11580
+ const fd = fs10.openSync(dir, "r");
11271
11581
  try {
11272
- fs9.fsyncSync(fd);
11582
+ fs10.fsyncSync(fd);
11273
11583
  } finally {
11274
- fs9.closeSync(fd);
11584
+ fs10.closeSync(fd);
11275
11585
  }
11276
11586
  } catch (error) {
11277
11587
  if (process.platform !== "win32")
@@ -11281,20 +11591,20 @@ var fsyncDirectory = (dir) => {
11281
11591
  function replaceFile(file, bytes, durable) {
11282
11592
  const temporary = `${file}.${process.pid}.${randomUUID2()}.tmp`;
11283
11593
  try {
11284
- const fd = fs9.openSync(temporary, "wx", 384);
11594
+ const fd = fs10.openSync(temporary, "wx", 384);
11285
11595
  try {
11286
- fs9.writeSync(fd, bytes);
11596
+ fs10.writeSync(fd, bytes);
11287
11597
  if (durable)
11288
- fs9.fsyncSync(fd);
11598
+ fs10.fsyncSync(fd);
11289
11599
  } finally {
11290
- fs9.closeSync(fd);
11600
+ fs10.closeSync(fd);
11291
11601
  }
11292
11602
  renameWithRetry(temporary, file);
11293
11603
  if (durable)
11294
- fsyncDirectory(path12.dirname(file));
11604
+ fsyncDirectory(path13.dirname(file));
11295
11605
  } catch (error) {
11296
11606
  try {
11297
- fs9.unlinkSync(temporary);
11607
+ fs10.unlinkSync(temporary);
11298
11608
  } catch {}
11299
11609
  throw error;
11300
11610
  }
@@ -11319,7 +11629,7 @@ var retryTransient = (run) => {
11319
11629
  }
11320
11630
  }
11321
11631
  };
11322
- var renameWithRetry = (from, to) => retryTransient(() => fs9.renameSync(from, to));
11632
+ var renameWithRetry = (from, to) => retryTransient(() => fs10.renameSync(from, to));
11323
11633
 
11324
11634
  // packages/workit-core/src/store/patch.ts
11325
11635
  var isPlainObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -11511,7 +11821,7 @@ var indexEntry = (task, key, legacy, file) => {
11511
11821
  };
11512
11822
  var fileSignature = (file) => {
11513
11823
  try {
11514
- const stat = fs10.statSync(file, { bigint: true });
11824
+ const stat = fs11.statSync(file, { bigint: true });
11515
11825
  return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
11516
11826
  } catch {
11517
11827
  return null;
@@ -11528,7 +11838,7 @@ var cachedRuntimeVersion = null;
11528
11838
  var runtimeVersion = () => {
11529
11839
  if (cachedRuntimeVersion === null) {
11530
11840
  try {
11531
- const pkg = JSON.parse(fs10.readFileSync(path13.join(packageRoot(), "package.json"), "utf8"));
11841
+ const pkg = JSON.parse(fs11.readFileSync(path14.join(packageRoot(), "package.json"), "utf8"));
11532
11842
  cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
11533
11843
  } catch {
11534
11844
  cachedRuntimeVersion = "0.0.0";
@@ -11550,14 +11860,14 @@ var isNewerVersion = (candidate, current) => {
11550
11860
  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
11861
  var readText2 = (file) => {
11552
11862
  try {
11553
- return fs10.readFileSync(file, "utf8");
11863
+ return fs11.readFileSync(file, "utf8");
11554
11864
  } catch {
11555
11865
  return "";
11556
11866
  }
11557
11867
  };
11558
11868
  var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
11559
11869
  var branchStart = (location, branch, aliases) => {
11560
- const first = readText2(path13.join(path13.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
11870
+ const first = readText2(path14.join(path14.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
11561
11871
  `, 1)[0];
11562
11872
  const created = REFLOG_LINE.exec(first);
11563
11873
  const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
@@ -11567,7 +11877,7 @@ var branchStart = (location, branch, aliases) => {
11567
11877
  return start;
11568
11878
  if (!location.git)
11569
11879
  return null;
11570
- for (const line of readText2(path13.join(location.git.gitDir, "logs", "HEAD")).split(`
11880
+ for (const line of readText2(path14.join(location.git.gitDir, "logs", "HEAD")).split(`
11571
11881
  `)) {
11572
11882
  const entry = REFLOG_LINE.exec(line);
11573
11883
  const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
@@ -11577,23 +11887,23 @@ var branchStart = (location, branch, aliases) => {
11577
11887
  }
11578
11888
  return null;
11579
11889
  };
11580
- var refExists2 = (common, ref) => fs10.existsSync(path13.join(common, ref)) || readText2(path13.join(common, "packed-refs")).includes(` ${ref}
11890
+ var refExists2 = (common, ref) => fs11.existsSync(path14.join(common, ref)) || readText2(path14.join(common, "packed-refs")).includes(` ${ref}
11581
11891
  `);
11582
11892
  var origins = new Map;
11583
11893
  var sameDirectoryIdentity = (left, right) => {
11584
- if (!path13.isAbsolute(left) || !path13.isAbsolute(right))
11894
+ if (!path14.isAbsolute(left) || !path14.isAbsolute(right))
11585
11895
  return false;
11586
- const normalizedLeft = path13.resolve(left);
11587
- const normalizedRight = path13.resolve(right);
11896
+ const normalizedLeft = path14.resolve(left);
11897
+ const normalizedRight = path14.resolve(right);
11588
11898
  try {
11589
- const a = fs10.statSync(normalizedLeft, { bigint: true });
11590
- const b = fs10.statSync(normalizedRight, { bigint: true });
11899
+ const a = fs11.statSync(normalizedLeft, { bigint: true });
11900
+ const b = fs11.statSync(normalizedRight, { bigint: true });
11591
11901
  if (!a.isDirectory() || !b.isDirectory())
11592
11902
  return false;
11593
11903
  if (process.platform === "win32" ? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase() : normalizedLeft === normalizedRight)
11594
11904
  return true;
11595
- const canonicalLeft = fs10.realpathSync(normalizedLeft);
11596
- const canonicalRight = fs10.realpathSync(normalizedRight);
11905
+ const canonicalLeft = fs11.realpathSync(normalizedLeft);
11906
+ const canonicalRight = fs11.realpathSync(normalizedRight);
11597
11907
  if (process.platform === "win32" ? canonicalLeft.toLowerCase() === canonicalRight.toLowerCase() : canonicalLeft === canonicalRight)
11598
11908
  return true;
11599
11909
  return a.dev === b.dev && a.ino !== 0n && a.ino === b.ino;
@@ -11618,14 +11928,14 @@ class TaskReader {
11618
11928
  located;
11619
11929
  migrationChecked = false;
11620
11930
  constructor(root, options = {}) {
11621
- const resolved = path13.resolve(root);
11622
- this.origin = fs10.existsSync(resolved) ? fs10.realpathSync(resolved) : resolved;
11931
+ const resolved = path14.resolve(root);
11932
+ this.origin = fs11.existsSync(resolved) ? fs11.realpathSync(resolved) : resolved;
11623
11933
  this.located = resolveStore(this.origin);
11624
11934
  this.root = checkoutRootOf(this.origin, this.located);
11625
11935
  this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
11626
11936
  }
11627
11937
  location() {
11628
- if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs10.existsSync(path13.join(this.root, ".git"))) {
11938
+ if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs11.existsSync(path14.join(this.root, ".git"))) {
11629
11939
  this.located = undefined;
11630
11940
  this.migrationChecked = false;
11631
11941
  }
@@ -11689,7 +11999,7 @@ class TaskReader {
11689
11999
  const tasksDir = this.paths().tasks;
11690
12000
  let names;
11691
12001
  try {
11692
- names = fs10.existsSync(tasksDir) ? fs10.readdirSync(tasksDir).filter((name) => validId(name)) : [];
12002
+ names = fs11.existsSync(tasksDir) ? fs11.readdirSync(tasksDir).filter((name) => validId(name)) : [];
11693
12003
  } catch (error) {
11694
12004
  return failure2("storage_error", `unable to list tasks: ${String(error)}`, {
11695
12005
  path: tasksDir
@@ -11730,7 +12040,7 @@ class TaskReader {
11730
12040
  const file = this.paths().workspace;
11731
12041
  let bytes;
11732
12042
  try {
11733
- bytes = retryTransient(() => fs10.readFileSync(file, "utf8"));
12043
+ bytes = retryTransient(() => fs11.readFileSync(file, "utf8"));
11734
12044
  } catch (error) {
11735
12045
  if (error.code === "ENOENT")
11736
12046
  return success(null, null, null);
@@ -11783,14 +12093,14 @@ class TaskReader {
11783
12093
  const branch = key.ok ? key.data.branch : null;
11784
12094
  if (!branch || !location.ok)
11785
12095
  return success(null, null, null);
11786
- const common = path13.dirname(location.data.dir);
11787
- const heads = path13.join(common, "logs", "refs", "heads");
11788
- const headLog = location.data.git ? path13.join(location.data.git.gitDir, "logs", "HEAD") : "";
12096
+ const common = path14.dirname(location.data.dir);
12097
+ const heads = path14.join(common, "logs", "refs", "heads");
12098
+ const headLog = location.data.git ? path14.join(location.data.git.gitDir, "logs", "HEAD") : "";
11789
12099
  const signatures = [
11790
- path13.join(heads, branch),
12100
+ path14.join(heads, branch),
11791
12101
  headLog,
11792
12102
  heads,
11793
- path13.join(common, "packed-refs")
12103
+ path14.join(common, "packed-refs")
11794
12104
  ].map((file) => fileSignature(file) ?? "-");
11795
12105
  const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
11796
12106
  let resolved = origins.get(slot);
@@ -11802,7 +12112,7 @@ class TaskReader {
11802
12112
  aliases.push(rename.from);
11803
12113
  const start = branchStart(location.data, branch, aliases);
11804
12114
  const slash = start?.indexOf("/") ?? -1;
11805
- const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path13.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
12115
+ 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
12116
  const name = start && (remote ? start.slice(slash + 1) : start);
11807
12117
  resolved = {
11808
12118
  signature: signatures.join("|"),
@@ -11822,27 +12132,27 @@ class TaskReader {
11822
12132
  }
11823
12133
  paths() {
11824
12134
  const location = this.location();
11825
- const dir = location.ok ? location.data.dir : path13.join(this.root, ".workit");
11826
- const checkout = path13.join(dir, "checkouts", checkoutSlug(this.root));
12135
+ const dir = location.ok ? location.data.dir : path14.join(this.root, ".workit");
12136
+ const checkout = path14.join(dir, "checkouts", checkoutSlug(this.root));
11827
12137
  return {
11828
12138
  dir,
11829
12139
  shared: location.ok ? location.data.shared : false,
11830
- marker: path13.join(dir, "store.json"),
12140
+ marker: path14.join(dir, "store.json"),
11831
12141
  checkout,
11832
- workspace: path13.join(checkout, "workspace.json"),
11833
- checkoutLock: path13.join(checkout, "metadata.lock"),
11834
- tasks: path13.join(dir, "tasks"),
11835
- index: path13.join(dir, "task-index.json"),
11836
- blobs: path13.join(dir, "blobs", "candidates"),
11837
- legacy: path13.join(dir, "legacy", checkoutSlug(this.root), "v2"),
11838
- v2: path13.join(this.root, ".workit")
12142
+ workspace: path14.join(checkout, "workspace.json"),
12143
+ checkoutLock: path14.join(checkout, "metadata.lock"),
12144
+ tasks: path14.join(dir, "tasks"),
12145
+ index: path14.join(dir, "task-index.json"),
12146
+ blobs: path14.join(dir, "blobs", "candidates"),
12147
+ legacy: path14.join(dir, "legacy", checkoutSlug(this.root), "v2"),
12148
+ v2: path14.join(this.root, ".workit")
11839
12149
  };
11840
12150
  }
11841
12151
  eventsPath(taskId) {
11842
- return path13.join(this.paths().tasks, taskId, "events.jsonl");
12152
+ return path14.join(this.paths().tasks, taskId, "events.jsonl");
11843
12153
  }
11844
12154
  snapshotPath(taskId) {
11845
- return path13.join(this.paths().tasks, taskId, "snapshot.json");
12155
+ return path14.join(this.paths().tasks, taskId, "snapshot.json");
11846
12156
  }
11847
12157
  ready(write = false) {
11848
12158
  const location = this.location();
@@ -11852,7 +12162,7 @@ class TaskReader {
11852
12162
  return success(null, null, null);
11853
12163
  const dirs = this.paths();
11854
12164
  try {
11855
- const marker = JSON.parse(fs10.readFileSync(dirs.marker, "utf8"));
12165
+ const marker = JSON.parse(fs11.readFileSync(dirs.marker, "utf8"));
11856
12166
  if (typeof marker.version === "number" && marker.version > STORE_FORMAT)
11857
12167
  return failure2("recovery_required", `the workit store at ${dirs.dir} has format ${marker.version}; upgrade Workit to use it`, { path: dirs.marker });
11858
12168
  } catch {}
@@ -11877,7 +12187,7 @@ class TaskReader {
11877
12187
  return {
11878
12188
  read: (digest) => {
11879
12189
  try {
11880
- return JSON.parse(fs10.readFileSync(path13.join(dir, `${digest}.json`), "utf8"));
12190
+ return JSON.parse(fs11.readFileSync(path14.join(dir, `${digest}.json`), "utf8"));
11881
12191
  } catch (error) {
11882
12192
  throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
11883
12193
  }
@@ -11964,7 +12274,7 @@ class TaskReader {
11964
12274
  }
11965
12275
  readSnapshot(taskId) {
11966
12276
  try {
11967
- const value = JSON.parse(fs10.readFileSync(this.snapshotPath(taskId), "utf8"));
12277
+ const value = JSON.parse(fs11.readFileSync(this.snapshotPath(taskId), "utf8"));
11968
12278
  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
12279
  return null;
11970
12280
  return value;
@@ -11991,7 +12301,7 @@ class TaskReader {
11991
12301
  }
11992
12302
  readIndex() {
11993
12303
  try {
11994
- const value = JSON.parse(fs10.readFileSync(this.paths().index, "utf8"));
12304
+ const value = JSON.parse(fs11.readFileSync(this.paths().index, "utf8"));
11995
12305
  if (!isObject5(value) || value.version !== INDEX_VERSION || !isObject5(value.tasks))
11996
12306
  return {};
11997
12307
  const tasks = {};
@@ -12005,7 +12315,7 @@ class TaskReader {
12005
12315
  }
12006
12316
  writeIndex(entries) {
12007
12317
  try {
12008
- fs10.mkdirSync(this.paths().tasks, { recursive: true });
12318
+ fs11.mkdirSync(this.paths().tasks, { recursive: true });
12009
12319
  replaceFile(this.paths().index, JSON.stringify({
12010
12320
  version: INDEX_VERSION,
12011
12321
  tasks: Object.fromEntries(entries.map((entry) => [entry.id, entry]))
@@ -12043,64 +12353,74 @@ class TaskReader {
12043
12353
  return failure2("recovery_required", `${label} record does not satisfy its schema`);
12044
12354
  }
12045
12355
  v2Dirs() {
12046
- return [...new Set([this.root, this.origin])].map((dir) => path13.join(dir, ".workit"));
12356
+ return [...new Set([this.root, this.origin])].map((dir) => path14.join(dir, ".workit"));
12047
12357
  }
12048
12358
  pendingMigrations() {
12049
12359
  return this.v2Dirs().filter((dir) => {
12050
- const raw = this.readV2Workspace(path13.join(dir, "workspace.json"));
12360
+ const raw = this.readV2Workspace(path14.join(dir, "workspace.json"));
12051
12361
  return raw !== null && raw !== TOMBSTONE;
12052
12362
  });
12053
12363
  }
12054
12364
  adoptLocalStore() {
12365
+ if (!this.paths().shared)
12366
+ return success(null, null, null);
12367
+ for (const local of [this.paths().v2, folderStoreDir2(this.root)]) {
12368
+ const adopted = this.adoptStoreFrom(local);
12369
+ if (!adopted.ok)
12370
+ return adopted;
12371
+ }
12372
+ return success(null, null, null);
12373
+ }
12374
+ adoptStoreFrom(local) {
12055
12375
  const dirs = this.paths();
12056
- const marker = path13.join(dirs.v2, "store.json");
12057
- if (!dirs.shared || !fs10.existsSync(marker))
12376
+ const marker = path14.join(local, "store.json");
12377
+ if (!fs11.existsSync(marker))
12058
12378
  return success(null, null, null);
12059
12379
  return this.withLock(dirs.checkoutLock, () => {
12060
- if (!fs10.existsSync(marker))
12380
+ if (!fs11.existsSync(marker))
12061
12381
  return success(null, null, null);
12062
12382
  let tasks = 0;
12063
12383
  try {
12064
12384
  const merge = (from, to) => {
12065
- if (!fs10.existsSync(to)) {
12066
- fs10.mkdirSync(path13.dirname(to), { recursive: true });
12385
+ if (!fs11.existsSync(to)) {
12386
+ fs11.mkdirSync(path14.dirname(to), { recursive: true });
12067
12387
  try {
12068
- fs10.renameSync(from, to);
12388
+ fs11.renameSync(from, to);
12069
12389
  } catch {
12070
- fs10.cpSync(from, to, { recursive: true, errorOnExist: true, force: false });
12071
- fs10.rmSync(from, { recursive: true, force: true });
12390
+ fs11.cpSync(from, to, { recursive: true, errorOnExist: true, force: false });
12391
+ fs11.rmSync(from, { recursive: true, force: true });
12072
12392
  }
12073
12393
  return;
12074
12394
  }
12075
- if (fs10.lstatSync(from).isDirectory() && fs10.lstatSync(to).isDirectory())
12076
- for (const name of fs10.readdirSync(from))
12077
- merge(path13.join(from, name), path13.join(to, name));
12395
+ if (fs11.lstatSync(from).isDirectory() && fs11.lstatSync(to).isDirectory())
12396
+ for (const name of fs11.readdirSync(from))
12397
+ merge(path14.join(from, name), path14.join(to, name));
12078
12398
  };
12079
12399
  for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
12080
- const from = path13.join(dirs.v2, sub);
12081
- if (!fs10.existsSync(from))
12400
+ const from = path14.join(local, sub);
12401
+ if (!fs11.existsSync(from))
12082
12402
  continue;
12083
12403
  if (sub === "tasks") {
12084
- for (const name of fs10.readdirSync(from))
12085
- if (validId(name) && !fs10.existsSync(path13.join(dirs.dir, sub, name)))
12404
+ for (const name of fs11.readdirSync(from))
12405
+ if (validId(name) && !fs11.existsSync(path14.join(dirs.dir, sub, name)))
12086
12406
  tasks += 1;
12087
12407
  }
12088
- merge(from, path13.join(dirs.dir, sub));
12408
+ merge(from, path14.join(dirs.dir, sub));
12089
12409
  }
12090
- const ledger = path13.join(dirs.v2, "ledger");
12091
- if (fs10.existsSync(ledger) && !fs10.existsSync(path13.join(dirs.dir, "ledger")))
12092
- merge(ledger, path13.join(dirs.dir, "ledger"));
12093
- fs10.rmSync(path13.join(dirs.v2, "task-index.json"), { force: true });
12094
- fs10.renameSync(marker, path13.join(dirs.v2, "store.moved.json"));
12410
+ const ledger = path14.join(local, "ledger");
12411
+ if (fs11.existsSync(ledger) && !fs11.existsSync(path14.join(dirs.dir, "ledger")))
12412
+ merge(ledger, path14.join(dirs.dir, "ledger"));
12413
+ fs11.rmSync(path14.join(local, "task-index.json"), { force: true });
12414
+ fs11.renameSync(marker, path14.join(local, "store.moved.json"));
12095
12415
  } catch (error) {
12096
- return failure2("storage_error", `cannot move ${dirs.v2} into ${dirs.dir}: ${String(error)}`, {
12097
- path: dirs.v2
12416
+ return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
12417
+ path: local
12098
12418
  });
12099
12419
  }
12100
12420
  reportMigration({
12101
- from: dirs.v2,
12421
+ from: local,
12102
12422
  to: dirs.dir,
12103
- backup: dirs.v2,
12423
+ backup: local,
12104
12424
  tasks,
12105
12425
  skipped: 0,
12106
12426
  workspace: false
@@ -12111,7 +12431,7 @@ class TaskReader {
12111
12431
  readV2Workspace(file) {
12112
12432
  let bytes;
12113
12433
  try {
12114
- bytes = fs10.readFileSync(file, "utf8");
12434
+ bytes = fs11.readFileSync(file, "utf8");
12115
12435
  } catch {
12116
12436
  return null;
12117
12437
  }
@@ -12129,7 +12449,7 @@ class TaskReader {
12129
12449
  schemaVersion: SCHEMA_VERSION,
12130
12450
  id: workspaceId ?? newId(),
12131
12451
  revision: newRevision(),
12132
- root: path13.dirname(v2),
12452
+ root: path14.dirname(v2),
12133
12453
  runtime: { createdWith: version, updatedWith: version },
12134
12454
  writer: null,
12135
12455
  store: {
@@ -12140,47 +12460,21 @@ class TaskReader {
12140
12460
  },
12141
12461
  critical: ["store"]
12142
12462
  };
12143
- fs10.mkdirSync(v2, { recursive: true });
12144
- const ignore = path13.join(v2, ".gitignore");
12145
- if (!fs10.existsSync(ignore))
12146
- fs10.writeFileSync(ignore, `*
12463
+ fs11.mkdirSync(v2, { recursive: true });
12464
+ const ignore = path14.join(v2, ".gitignore");
12465
+ if (!fs11.existsSync(ignore))
12466
+ fs11.writeFileSync(ignore, `*
12147
12467
  `);
12148
- replaceFile(path13.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
12468
+ replaceFile(path14.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
12149
12469
  `, true);
12150
12470
  }
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
12471
  initializeStorage() {
12166
12472
  const dirs = this.paths();
12167
- retryTransient(() => fs10.mkdirSync(dirs.checkout, { recursive: true }));
12168
- retryTransient(() => fs10.mkdirSync(dirs.tasks, { recursive: true }));
12169
- if (!fs10.existsSync(dirs.marker))
12473
+ retryTransient(() => fs11.mkdirSync(dirs.checkout, { recursive: true }));
12474
+ retryTransient(() => fs11.mkdirSync(dirs.tasks, { recursive: true }));
12475
+ if (!fs11.existsSync(dirs.marker))
12170
12476
  replaceFile(dirs.marker, `${JSON.stringify({ format: "workit-store", version: STORE_FORMAT, createdWith: runtimeVersion() })}
12171
12477
  `, 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
12478
  }
12185
12479
  lockOptions(lockPath) {
12186
12480
  const inProcess = heldInProcess.has(lockPath);
@@ -12193,7 +12487,7 @@ class TaskReader {
12193
12487
  shouldReclaim: ({ payload, nowMs }) => {
12194
12488
  let ageMs = null;
12195
12489
  try {
12196
- ageMs = nowMs - fs10.lstatSync(lockPath).mtimeMs;
12490
+ ageMs = nowMs - fs11.lstatSync(lockPath).mtimeMs;
12197
12491
  } catch {}
12198
12492
  return classifyLockOwner(payload, ageMs, localLockHost(), TASK_STORE_LOCK).state === "stale";
12199
12493
  },
@@ -12230,7 +12524,7 @@ class TaskReader {
12230
12524
  withLock(lockPath, operation) {
12231
12525
  try {
12232
12526
  this.initializeStorage();
12233
- fs10.mkdirSync(path13.dirname(lockPath), { recursive: true });
12527
+ fs11.mkdirSync(path14.dirname(lockPath), { recursive: true });
12234
12528
  } catch (error) {
12235
12529
  return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
12236
12530
  path: this.paths().dir
@@ -12270,18 +12564,18 @@ class TaskReader {
12270
12564
  lockDirWritable(lockPath) {
12271
12565
  const probe = `${lockPath}.${process.pid}.${randomUUID3()}.probe`;
12272
12566
  try {
12273
- fs10.closeSync(fs10.openSync(probe, "wx", 384));
12567
+ fs11.closeSync(fs11.openSync(probe, "wx", 384));
12274
12568
  } catch {
12275
12569
  return false;
12276
12570
  }
12277
12571
  try {
12278
- fs10.rmSync(probe, { force: true });
12572
+ fs11.rmSync(probe, { force: true });
12279
12573
  } catch {}
12280
12574
  return true;
12281
12575
  }
12282
12576
  lockHolderPresent(lockPath) {
12283
12577
  try {
12284
- fs10.lstatSync(lockPath);
12578
+ fs11.lstatSync(lockPath);
12285
12579
  return true;
12286
12580
  } catch (error) {
12287
12581
  return error?.code !== "ENOENT";
@@ -12293,12 +12587,12 @@ class TaskReader {
12293
12587
  if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
12294
12588
  return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
12295
12589
  path: lockPath,
12296
- guidance: `Check permissions and the read-only attribute on ${path13.dirname(lockPath)}.`
12590
+ guidance: `Check permissions and the read-only attribute on ${path14.dirname(lockPath)}.`
12297
12591
  });
12298
12592
  if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
12299
12593
  let lock = null;
12300
12594
  try {
12301
- lock = parseMetadataLockOrNull(fs10.readFileSync(lockPath, "utf8"));
12595
+ lock = parseMetadataLockOrNull(fs11.readFileSync(lockPath, "utf8"));
12302
12596
  } catch {}
12303
12597
  return failure2("busy", `workit lock is held by another Workit call${lock ? ` (pid ${lock.pid} on ${lock.host})` : ""}; retry shortly`, {
12304
12598
  outcome: "not_started",
@@ -12313,13 +12607,13 @@ class TaskReader {
12313
12607
 
12314
12608
  // packages/workit-core/src/core/policy/derive.ts
12315
12609
  import { existsSync as existsSync7 } from "node:fs";
12316
- import path17 from "node:path";
12610
+ import path18 from "node:path";
12317
12611
 
12318
12612
  // packages/workit-core/src/ledger.ts
12319
12613
  import { spawnSync as spawnSync11 } from "node:child_process";
12320
12614
  import { createHash as createHash9, randomBytes as randomBytes3 } from "node:crypto";
12321
- import fs12 from "node:fs";
12322
- import path16 from "node:path";
12615
+ import fs13 from "node:fs";
12616
+ import path17 from "node:path";
12323
12617
 
12324
12618
  // packages/workit-core/src/core/policy/bookkeeping.ts
12325
12619
  import { spawnSync as spawnSync9 } from "node:child_process";
@@ -12400,7 +12694,7 @@ function bookkeepingPaths(cwd, input) {
12400
12694
 
12401
12695
  // packages/workit-core/src/core/policy/lane.ts
12402
12696
  import { existsSync as existsSync6, readFileSync as readFileSync7 } from "node:fs";
12403
- import path14 from "node:path";
12697
+ import path15 from "node:path";
12404
12698
 
12405
12699
  // packages/workit-core/src/git/default-base.ts
12406
12700
  import { spawnSync as spawnSync10 } from "node:child_process";
@@ -13788,7 +14082,7 @@ function computeLane(input) {
13788
14082
  }
13789
14083
  function untrackedStat(cwd, file) {
13790
14084
  try {
13791
- const bytes = readFileSync7(path14.join(cwd, file));
14085
+ const bytes = readFileSync7(path15.join(cwd, file));
13792
14086
  if (bytes.includes(0))
13793
14087
  return { path: file, added: 0, deleted: 0, binary: true };
13794
14088
  const text = bytes.toString("utf8");
@@ -13820,7 +14114,7 @@ function cosmeticFiles(cwd, fork, head) {
13820
14114
  let after = blobs.get(entry.newBlob);
13821
14115
  if (!after && head === null && ABSENT.test(entry.newBlob))
13822
14116
  try {
13823
- after = readFileSync7(path14.join(cwd, entry.path));
14117
+ after = readFileSync7(path15.join(cwd, entry.path));
13824
14118
  } catch {
13825
14119
  after = undefined;
13826
14120
  }
@@ -13976,13 +14270,13 @@ function verdictDrift(cwd, input) {
13976
14270
 
13977
14271
  // packages/workit-core/src/host-session.ts
13978
14272
  import { createHash as createHash8, randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
13979
- import fs11 from "node:fs";
13980
- import path15 from "node:path";
14273
+ import fs12 from "node:fs";
14274
+ import path16 from "node:path";
13981
14275
  var ISSUED_PER_LEAD = 64;
13982
14276
  var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/3";
13983
14277
  var hash = (value) => createHash8("sha256").update(value).digest("hex").slice(0, 32);
13984
- var userIssuedRoot = () => path15.join(resolveStateDir(), "issued");
13985
- var userTokenRoot = () => path15.join(resolveStateDir(), "issued-tokens");
14278
+ var userIssuedRoot = () => path16.join(resolveStateDir(), "issued");
14279
+ var userTokenRoot = () => path16.join(resolveStateDir(), "issued-tokens");
13986
14280
  function migrateRepoIssued(cwd) {
13987
14281
  if (cwd === undefined)
13988
14282
  return;
@@ -13991,27 +14285,27 @@ function migrateRepoIssued(cwd) {
13991
14285
  const location = resolveStore(cwd);
13992
14286
  if (location instanceof Error)
13993
14287
  return;
13994
- old = path15.join(location.dir, "hooks", "issued");
13995
- if (!fs11.existsSync(old))
14288
+ old = path16.join(location.dir, "hooks", "issued");
14289
+ if (!fs12.existsSync(old))
13996
14290
  return;
13997
14291
  } catch {
13998
14292
  return;
13999
14293
  }
14000
14294
  for (const lead of safeList(old)) {
14001
14295
  try {
14002
- const from = path15.join(old, lead);
14003
- if (!fs11.statSync(from).isDirectory())
14296
+ const from = path16.join(old, lead);
14297
+ if (!fs12.statSync(from).isDirectory())
14004
14298
  continue;
14005
- const to = path15.join(userIssuedRoot(), lead);
14006
- fs11.mkdirSync(to, { recursive: true, mode: 448 });
14007
- for (const id of fs11.readdirSync(from)) {
14299
+ const to = path16.join(userIssuedRoot(), lead);
14300
+ fs12.mkdirSync(to, { recursive: true, mode: 448 });
14301
+ for (const id of fs12.readdirSync(from)) {
14008
14302
  try {
14009
- fs11.copyFileSync(path15.join(from, id), path15.join(to, id), fs11.constants.COPYFILE_EXCL);
14303
+ fs12.copyFileSync(path16.join(from, id), path16.join(to, id), fs12.constants.COPYFILE_EXCL);
14010
14304
  } catch (error) {
14011
14305
  if (error.code !== "EEXIST")
14012
14306
  throw error;
14013
14307
  }
14014
- fs11.rmSync(path15.join(from, id), { force: true });
14308
+ fs12.rmSync(path16.join(from, id), { force: true });
14015
14309
  }
14016
14310
  removeIfEmpty(from);
14017
14311
  } catch {}
@@ -14020,14 +14314,14 @@ function migrateRepoIssued(cwd) {
14020
14314
  }
14021
14315
  var safeList = (dir) => {
14022
14316
  try {
14023
- return fs11.readdirSync(dir);
14317
+ return fs12.readdirSync(dir);
14024
14318
  } catch {
14025
14319
  return [];
14026
14320
  }
14027
14321
  };
14028
14322
  var removeIfEmpty = (dir) => {
14029
14323
  try {
14030
- fs11.rmdirSync(dir);
14324
+ fs12.rmdirSync(dir);
14031
14325
  } catch {}
14032
14326
  };
14033
14327
  var tokenHash = (token) => createHash8("sha256").update(token).digest("hex");
@@ -14036,13 +14330,13 @@ function recordIssuedSession(cwd, lead, issued) {
14036
14330
  try {
14037
14331
  migrateRepoIssued(cwd);
14038
14332
  const own = hash(issued);
14039
- const tokens = path15.join(userTokenRoot(), hash(lead));
14040
- fs11.mkdirSync(tokens, { recursive: true, mode: 448 });
14041
- fs11.writeFileSync(path15.join(tokens, own), `${tokenHash(token)}
14333
+ const tokens = path16.join(userTokenRoot(), hash(lead));
14334
+ fs12.mkdirSync(tokens, { recursive: true, mode: 448 });
14335
+ fs12.writeFileSync(path16.join(tokens, own), `${tokenHash(token)}
14042
14336
  `, { mode: 384, flag: "wx" });
14043
- const dir = path15.join(userIssuedRoot(), hash(lead));
14044
- fs11.mkdirSync(dir, { recursive: true, mode: 448 });
14045
- fs11.writeFileSync(path15.join(dir, own), `${ISSUED_SESSIONS_MARKER}
14337
+ const dir = path16.join(userIssuedRoot(), hash(lead));
14338
+ fs12.mkdirSync(dir, { recursive: true, mode: 448 });
14339
+ fs12.writeFileSync(path16.join(dir, own), `${ISSUED_SESSIONS_MARKER}
14046
14340
  `, { mode: 384 });
14047
14341
  pruneIssued(dir, own, tokens);
14048
14342
  return token;
@@ -14069,13 +14363,13 @@ function verdictCommand(options) {
14069
14363
  }
14070
14364
  function pruneIssued(dir, own, tokens) {
14071
14365
  try {
14072
- const entries = fs11.readdirSync(dir);
14366
+ const entries = fs12.readdirSync(dir);
14073
14367
  if (entries.length <= ISSUED_PER_LEAD)
14074
14368
  return;
14075
- const byAge = entries.filter((name) => name !== own).map((name) => ({ name, at: fs11.statSync(path15.join(dir, name)).mtimeMs })).toSorted((a, b) => a.at - b.at);
14369
+ 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
14370
  for (const { name } of byAge.slice(0, entries.length - ISSUED_PER_LEAD)) {
14077
- fs11.rmSync(path15.join(dir, name), { force: true });
14078
- fs11.rmSync(path15.join(tokens, name), { force: true });
14371
+ fs12.rmSync(path16.join(dir, name), { force: true });
14372
+ fs12.rmSync(path16.join(tokens, name), { force: true });
14079
14373
  }
14080
14374
  } catch {}
14081
14375
  }
@@ -14085,7 +14379,7 @@ var issuedRecord = (cwd, claimed) => {
14085
14379
  return null;
14086
14380
  migrateRepoIssued(cwd);
14087
14381
  try {
14088
- return fs11.readFileSync(path15.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
14382
+ return fs12.readFileSync(path16.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
14089
14383
  } catch {
14090
14384
  return null;
14091
14385
  }
@@ -14095,9 +14389,9 @@ var issuedToken = (claimed) => {
14095
14389
  const cut = claimed.lastIndexOf(":");
14096
14390
  if (cut <= 0)
14097
14391
  return { stored: null, leadBound: false };
14098
- const dir = path15.join(userTokenRoot(), hash(claimed.slice(0, cut)));
14392
+ const dir = path16.join(userTokenRoot(), hash(claimed.slice(0, cut)));
14099
14393
  try {
14100
- const text = fs11.readFileSync(path15.join(dir, hash(claimed)), "utf8");
14394
+ const text = fs12.readFileSync(path16.join(dir, hash(claimed)), "utf8");
14101
14395
  return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
14102
14396
  } catch {
14103
14397
  return { stored: null, leadBound: safeList(dir).length > 0 };
@@ -14224,14 +14518,14 @@ function cleanRebase(cwd, range) {
14224
14518
  return Boolean(tree) && tree === git3(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
14225
14519
  }
14226
14520
  function storeRoot(cwd) {
14227
- const location = resolveStore(path16.resolve(cwd));
14521
+ const location = resolveStore(path17.resolve(cwd));
14228
14522
  if (location instanceof Error)
14229
14523
  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
14524
  return { ok: true, value: { root: location.dir, shared: location.shared } };
14231
14525
  }
14232
14526
  function ledgerPath(cwd) {
14233
14527
  const root = storeRoot(cwd);
14234
- return root.ok ? { ok: true, value: path16.join(root.value.root, "ledger", "ledger.jsonl") } : root;
14528
+ return root.ok ? { ok: true, value: path17.join(root.value.root, "ledger", "ledger.jsonl") } : root;
14235
14529
  }
14236
14530
  var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
14237
14531
  var NETWORK_FS_TYPES = new Set([
@@ -14251,25 +14545,25 @@ var onNetworkFs = (dir) => {
14251
14545
  if (process.platform !== "linux")
14252
14546
  return false;
14253
14547
  try {
14254
- return isNetworkFsType(fs12.statfsSync(dir).type);
14548
+ return isNetworkFsType(fs13.statfsSync(dir).type);
14255
14549
  } catch {
14256
14550
  return false;
14257
14551
  }
14258
14552
  };
14259
- var LOCK_WAIT_MS = 5000;
14260
- var LOCK_STALE_MS = 30000;
14553
+ var LOCK_WAIT_MS2 = 5000;
14554
+ var LOCK_STALE_MS2 = 30000;
14261
14555
  var LOCK_OWNER = "owner";
14262
14556
  var lockToken = (lock) => {
14263
14557
  try {
14264
- return fs12.readFileSync(path16.join(lock, LOCK_OWNER), "utf8");
14558
+ return fs13.readFileSync(path17.join(lock, LOCK_OWNER), "utf8");
14265
14559
  } catch {
14266
14560
  return null;
14267
14561
  }
14268
14562
  };
14269
14563
  var lockAgeMs = (lock) => {
14270
- for (const target of [path16.join(lock, LOCK_OWNER), lock]) {
14564
+ for (const target of [path17.join(lock, LOCK_OWNER), lock]) {
14271
14565
  try {
14272
- return Date.now() - fs12.statSync(target).mtimeMs;
14566
+ return Date.now() - fs13.statSync(target).mtimeMs;
14273
14567
  } catch {}
14274
14568
  }
14275
14569
  return null;
@@ -14277,14 +14571,14 @@ var lockAgeMs = (lock) => {
14277
14571
  var ledgerLock = {
14278
14572
  acquire(lock) {
14279
14573
  try {
14280
- fs12.mkdirSync(lock);
14574
+ fs13.mkdirSync(lock);
14281
14575
  } catch (error) {
14282
14576
  if (error.code === "EEXIST")
14283
14577
  return null;
14284
14578
  throw error;
14285
14579
  }
14286
14580
  const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
14287
- fs12.writeFileSync(path16.join(lock, LOCK_OWNER), token);
14581
+ fs13.writeFileSync(path17.join(lock, LOCK_OWNER), token);
14288
14582
  return token;
14289
14583
  },
14290
14584
  release(lock, token) {
@@ -14292,40 +14586,40 @@ var ledgerLock = {
14292
14586
  return false;
14293
14587
  const tomb = `${lock}.release-${randomBytes3(6).toString("hex")}`;
14294
14588
  try {
14295
- fs12.renameSync(lock, tomb);
14589
+ fs13.renameSync(lock, tomb);
14296
14590
  } catch {
14297
14591
  return false;
14298
14592
  }
14299
14593
  if (lockToken(tomb) !== token) {
14300
14594
  try {
14301
- fs12.renameSync(tomb, lock);
14595
+ fs13.renameSync(tomb, lock);
14302
14596
  } catch {}
14303
14597
  return false;
14304
14598
  }
14305
- fs12.rmSync(tomb, { recursive: true, force: true });
14599
+ fs13.rmSync(tomb, { recursive: true, force: true });
14306
14600
  return true;
14307
14601
  },
14308
14602
  token: lockToken,
14309
14603
  reap(lock, observed) {
14310
14604
  const tomb = `${lock}.reap-${randomBytes3(6).toString("hex")}`;
14311
14605
  try {
14312
- fs12.renameSync(lock, tomb);
14606
+ fs13.renameSync(lock, tomb);
14313
14607
  } catch {
14314
14608
  return false;
14315
14609
  }
14316
14610
  if (lockToken(tomb) === observed) {
14317
- fs12.rmSync(tomb, { recursive: true, force: true });
14611
+ fs13.rmSync(tomb, { recursive: true, force: true });
14318
14612
  return true;
14319
14613
  }
14320
14614
  try {
14321
- fs12.renameSync(tomb, lock);
14615
+ fs13.renameSync(tomb, lock);
14322
14616
  } catch {
14323
- fs12.rmSync(tomb, { recursive: true, force: true });
14617
+ fs13.rmSync(tomb, { recursive: true, force: true });
14324
14618
  }
14325
14619
  return false;
14326
14620
  }
14327
14621
  };
14328
- function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
14622
+ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2)) {
14329
14623
  const lock = `${file}.lock`;
14330
14624
  const deadline = Date.now() + waitMs;
14331
14625
  let token = null;
@@ -14335,7 +14629,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
14335
14629
  break;
14336
14630
  const observed = lockToken(lock);
14337
14631
  const age = lockAgeMs(lock);
14338
- if (age !== null && age > LOCK_STALE_MS && ledgerLock.reap(lock, observed))
14632
+ if (age !== null && age > LOCK_STALE_MS2 && ledgerLock.reap(lock, observed))
14339
14633
  continue;
14340
14634
  if (Date.now() >= deadline)
14341
14635
  return null;
@@ -14354,7 +14648,7 @@ var TAIL_BYTES = 64 * 1024;
14354
14648
  var lastLine = (fd, size) => {
14355
14649
  for (let span = Math.min(size, TAIL_BYTES);span > 0; span = Math.min(size, span * 2)) {
14356
14650
  const buffer = Buffer.alloc(span);
14357
- fs12.readSync(fd, buffer, 0, span, size - span);
14651
+ fs13.readSync(fd, buffer, 0, span, size - span);
14358
14652
  const end = buffer.lastIndexOf(10);
14359
14653
  if (end < 0) {
14360
14654
  if (span === size)
@@ -14385,32 +14679,32 @@ var lastLine = (fd, size) => {
14385
14679
  };
14386
14680
  var tighten = (fd) => {
14387
14681
  try {
14388
- if ((fs12.fstatSync(fd).mode & 63) !== 0)
14389
- fs12.fchmodSync(fd, 384);
14682
+ if ((fs13.fstatSync(fd).mode & 63) !== 0)
14683
+ fs13.fchmodSync(fd, 384);
14390
14684
  } catch {}
14391
14685
  };
14392
14686
  function appendLine(file, build, options) {
14393
14687
  const write = () => {
14394
- const fd = fs12.openSync(file, "a+", 384);
14688
+ const fd = fs13.openSync(file, "a+", 384);
14395
14689
  try {
14396
14690
  if (process.platform !== "win32")
14397
14691
  tighten(fd);
14398
- const line = build(lastLine(fd, fs12.fstatSync(fd).size));
14692
+ const line = build(lastLine(fd, fs13.fstatSync(fd).size));
14399
14693
  if (!line.ok)
14400
14694
  return line;
14401
14695
  const bytes = Buffer.from(`
14402
14696
  ${line.value}`);
14403
- const written = fs12.writeSync(fd, bytes);
14697
+ const written = fs13.writeSync(fd, bytes);
14404
14698
  if (written !== bytes.length)
14405
14699
  return err("unavailable", `short write to ${file}: ${written} of ${bytes.length} bytes; the row is torn and will be skipped`);
14406
14700
  return { ok: true, value: undefined };
14407
14701
  } finally {
14408
- fs12.closeSync(fd);
14702
+ fs13.closeSync(fd);
14409
14703
  }
14410
14704
  };
14411
14705
  try {
14412
- fs12.mkdirSync(path16.dirname(file), { recursive: true });
14413
- if (options.heldLock || !options.forceLock && !onNetworkFs(path16.dirname(file)))
14706
+ fs13.mkdirSync(path17.dirname(file), { recursive: true });
14707
+ if (options.heldLock || !options.forceLock && !onNetworkFs(path17.dirname(file)))
14414
14708
  return write();
14415
14709
  const locked = withLedgerLock(file, write);
14416
14710
  return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
@@ -14427,7 +14721,7 @@ var sealed = (row, id, at, previous) => {
14427
14721
  ` };
14428
14722
  };
14429
14723
  function appendRaw(cwd, row, options) {
14430
- const file = options.store ? { ok: true, value: path16.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
14724
+ const file = options.store ? { ok: true, value: path17.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
14431
14725
  if (!file.ok)
14432
14726
  return file;
14433
14727
  const id = newId2();
@@ -14477,8 +14771,8 @@ function readLedgerAt(cwd, file, options) {
14477
14771
  let text = "";
14478
14772
  let stat = null;
14479
14773
  try {
14480
- stat = fs12.statSync(file);
14481
- text = fs12.readFileSync(file, "utf8");
14774
+ stat = fs13.statSync(file);
14775
+ text = fs13.readFileSync(file, "utf8");
14482
14776
  } catch (error) {
14483
14777
  if (error.code === "ENOENT")
14484
14778
  return {
@@ -14618,7 +14912,7 @@ function ledgerTampering(cwd) {
14618
14912
  if (!file.ok)
14619
14913
  return [];
14620
14914
  try {
14621
- const stat = fs12.statSync(file.value);
14915
+ const stat = fs13.statSync(file.value);
14622
14916
  const cached = tamperCache.get(file.value);
14623
14917
  if (cached && cached.size === stat.size && cached.stamp === fileStamp(stat))
14624
14918
  return cached.breaks;
@@ -15085,8 +15379,8 @@ function remoteIdentity(cwd, hop = 0) {
15085
15379
  return null;
15086
15380
  if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
15087
15381
  const local = raw.replace(/^file:\/\//u, "");
15088
- const resolved = path16.isAbsolute(local) ? local : path16.resolve(cwd, local);
15089
- if (fs12.existsSync(resolved))
15382
+ const resolved = path17.isAbsolute(local) ? local : path17.resolve(cwd, local);
15383
+ if (fs13.existsSync(resolved))
15090
15384
  return remoteIdentity(resolved, 1);
15091
15385
  }
15092
15386
  const parsed = parseRemoteUrl(raw);
@@ -15107,7 +15401,7 @@ function verdictMirrorPath(cwd) {
15107
15401
  if (!identity)
15108
15402
  return null;
15109
15403
  const key = createHash9("sha256").update(identity).digest("hex").slice(0, 32);
15110
- return path16.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
15404
+ return path17.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
15111
15405
  }
15112
15406
  var importedStamp = new Map;
15113
15407
  function importMirroredVerdicts(cwd, branch) {
@@ -15117,7 +15411,7 @@ function importMirroredVerdicts(cwd, branch) {
15117
15411
  return [];
15118
15412
  let stamp;
15119
15413
  try {
15120
- stamp = `${branch}\x00${fileStamp(fs12.statSync(file))}`;
15414
+ stamp = `${branch}\x00${fileStamp(fs13.statSync(file))}`;
15121
15415
  } catch {
15122
15416
  return [];
15123
15417
  }
@@ -15130,7 +15424,7 @@ function importMirroredVerdicts(cwd, branch) {
15130
15424
  const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
15131
15425
  const added = new Set;
15132
15426
  try {
15133
- fs12.mkdirSync(path16.dirname(local.value), { recursive: true });
15427
+ fs13.mkdirSync(path17.dirname(local.value), { recursive: true });
15134
15428
  } catch {
15135
15429
  return [];
15136
15430
  }
@@ -15246,7 +15540,7 @@ var productDecision = (task, ledger) => {
15246
15540
  };
15247
15541
  };
15248
15542
  var planRecorded = (task, root) => {
15249
- const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync7(path17.resolve(root, ref.path)));
15543
+ const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync7(path18.resolve(root, ref.path)));
15250
15544
  if (cited)
15251
15545
  return {
15252
15546
  met: true,
@@ -15324,14 +15618,14 @@ function writeBlockers(task, root) {
15324
15618
 
15325
15619
  // packages/workit-core/src/core/task-evaluation.ts
15326
15620
  var digestBytes = (value) => createHash10("sha256").update(value).digest("hex");
15327
- var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path18.sep}`);
15328
- var relative = (root, candidate) => path18.relative(root, candidate).split(path18.sep).join("/") || ".";
15621
+ var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path19.sep}`);
15622
+ var relative = (root, candidate) => path19.relative(root, candidate).split(path19.sep).join("/") || ".";
15329
15623
  var canonicalPath = (value) => {
15330
15624
  if (typeof value !== "string" || !value)
15331
15625
  return null;
15332
15626
  if (value.includes("\\") || value.split("/").includes(".."))
15333
15627
  return null;
15334
- const normalized = path18.posix.normalize(value);
15628
+ const normalized = path19.posix.normalize(value);
15335
15629
  if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
15336
15630
  return null;
15337
15631
  return normalized === "." ? "." : normalized.replace(/\/$/, "");
@@ -15379,21 +15673,21 @@ var gitPaths = (root) => {
15379
15673
  git: !/not a git repository/i.test(stderr)
15380
15674
  };
15381
15675
  }
15382
- const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path18.sep).join("/")) : [];
15676
+ const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path19.sep).join("/")) : [];
15383
15677
  const stagedDeleted = spawnSync12("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
15384
15678
  if (stagedDeleted.status !== 0) {
15385
15679
  const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
15386
15680
  if (!/not a git repository/i.test(stderr))
15387
15681
  return { paths, uncertain: true, git: true };
15388
15682
  } else if (stagedDeleted.stdout) {
15389
- paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path18.sep).join("/")));
15683
+ paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path19.sep).join("/")));
15390
15684
  }
15391
15685
  return { paths: [...new Set(paths)], uncertain: false, git: true };
15392
15686
  };
15393
15687
  var walk = (root, directory, output) => {
15394
15688
  let names;
15395
15689
  try {
15396
- names = fs13.readdirSync(directory);
15690
+ names = fs14.readdirSync(directory);
15397
15691
  } catch {
15398
15692
  return true;
15399
15693
  }
@@ -15401,10 +15695,10 @@ var walk = (root, directory, output) => {
15401
15695
  for (const name of names) {
15402
15696
  if (name === ".git" || name === ".workit")
15403
15697
  continue;
15404
- const target = path18.join(directory, name);
15698
+ const target = path19.join(directory, name);
15405
15699
  let stat;
15406
15700
  try {
15407
- stat = fs13.lstatSync(target);
15701
+ stat = fs14.lstatSync(target);
15408
15702
  } catch {
15409
15703
  uncertain = true;
15410
15704
  continue;
@@ -15419,14 +15713,14 @@ var walk = (root, directory, output) => {
15419
15713
  var scopeRoots = (root, scope) => {
15420
15714
  const roots = [];
15421
15715
  for (const item of scope.paths.length ? scope.paths : ["."]) {
15422
- const target = path18.resolve(root, item);
15716
+ const target = path19.resolve(root, item);
15423
15717
  if (!inside(root, target))
15424
15718
  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
15719
  let ancestor = target;
15426
- while (!fs13.existsSync(ancestor) && ancestor !== root)
15427
- ancestor = path18.dirname(ancestor);
15720
+ while (!fs14.existsSync(ancestor) && ancestor !== root)
15721
+ ancestor = path19.dirname(ancestor);
15428
15722
  try {
15429
- if (!inside(root, fs13.realpathSync(ancestor)))
15723
+ if (!inside(root, fs14.realpathSync(ancestor)))
15430
15724
  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
15725
  } catch {
15432
15726
  return failure2("invalid_input", `candidate scope cannot be inspected: ${item}`);
@@ -15438,7 +15732,7 @@ var scopeRoots = (root, scope) => {
15438
15732
  function captureCandidate(root, scope, environment = []) {
15439
15733
  let checkout;
15440
15734
  try {
15441
- checkout = fs13.realpathSync(root);
15735
+ checkout = fs14.realpathSync(root);
15442
15736
  } catch {
15443
15737
  return failure2("invalid_input", "candidate root does not exist");
15444
15738
  }
@@ -15456,11 +15750,11 @@ function captureCandidate(root, scope, environment = []) {
15456
15750
  if (item === ".git" || item === ".workit")
15457
15751
  continue;
15458
15752
  names.add(item);
15459
- if (!fs13.existsSync(target))
15753
+ if (!fs14.existsSync(target))
15460
15754
  continue;
15461
15755
  let stat;
15462
15756
  try {
15463
- stat = fs13.lstatSync(target);
15757
+ stat = fs14.lstatSync(target);
15464
15758
  } catch {
15465
15759
  uncertain = true;
15466
15760
  continue;
@@ -15476,17 +15770,17 @@ function captureCandidate(root, scope, environment = []) {
15476
15770
  for (const item of [...names].toSorted()) {
15477
15771
  if (!scopeMatches(item, normalizedScope))
15478
15772
  continue;
15479
- const target = path18.join(checkout, item);
15773
+ const target = path19.join(checkout, item);
15480
15774
  try {
15481
- const stat = fs13.lstatSync(target);
15775
+ const stat = fs14.lstatSync(target);
15482
15776
  if (stat.isSymbolicLink()) {
15483
- const link = fs13.readlinkSync(target);
15777
+ const link = fs14.readlinkSync(target);
15484
15778
  files.push({ path: item, kind: "symlink", digest: digestBytes(link), executable: null });
15485
15779
  } else if (stat.isFile()) {
15486
15780
  files.push({
15487
15781
  path: item,
15488
15782
  kind: "file",
15489
- digest: digestBytes(fs13.readFileSync(target)),
15783
+ digest: digestBytes(fs14.readFileSync(target)),
15490
15784
  executable: (stat.mode & 73) !== 0
15491
15785
  });
15492
15786
  } else if (!stat.isDirectory()) {
@@ -15636,7 +15930,7 @@ var scopeCovers2 = scopeCovers;
15636
15930
  var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
15637
15931
  let root;
15638
15932
  try {
15639
- root = fs13.realpathSync(checkoutRoot);
15933
+ root = fs14.realpathSync(checkoutRoot);
15640
15934
  } catch {
15641
15935
  return failure2("permission_denied", "checkout root is unavailable");
15642
15936
  }
@@ -15645,23 +15939,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
15645
15939
  continue;
15646
15940
  if (!reference.digest)
15647
15941
  return failure2("invalid_input", "document references require a byte digest");
15648
- const target = path18.resolve(root, reference.path);
15649
- if (target !== root && !target.startsWith(`${root}${path18.sep}`))
15942
+ const target = path19.resolve(root, reference.path);
15943
+ if (target !== root && !target.startsWith(`${root}${path19.sep}`))
15650
15944
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
15651
15945
  fields: [
15652
15946
  { path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
15653
15947
  ]
15654
15948
  });
15655
15949
  try {
15656
- const below = path18.relative(root, target);
15950
+ const below = path19.relative(root, target);
15657
15951
  let current = root;
15658
- for (const segment of below.split(path18.sep)) {
15952
+ for (const segment of below.split(path19.sep)) {
15659
15953
  if (!segment)
15660
15954
  continue;
15661
- current = path18.join(current, segment);
15662
- const stat = fs13.lstatSync(current);
15663
- const real = fs13.realpathSync(current);
15664
- if (real !== root && !real.startsWith(`${root}${path18.sep}`))
15955
+ current = path19.join(current, segment);
15956
+ const stat = fs14.lstatSync(current);
15957
+ const real = fs14.realpathSync(current);
15958
+ if (real !== root && !real.startsWith(`${root}${path19.sep}`))
15665
15959
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
15666
15960
  fields: [
15667
15961
  {
@@ -15677,7 +15971,7 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
15677
15971
  if (current !== target && !stat.isDirectory())
15678
15972
  return failure2("invalid_input", "document reference ancestor is not a directory");
15679
15973
  }
15680
- if (digestBytes(fs13.readFileSync(target)) !== reference.digest)
15974
+ if (digestBytes(fs14.readFileSync(target)) !== reference.digest)
15681
15975
  return failure2("permission_denied", "decision document bytes have changed");
15682
15976
  } catch {
15683
15977
  return failure2("invalid_input", "decision document is unavailable");
@@ -16159,7 +16453,7 @@ function entryCompactContext(store, entry, session, context) {
16159
16453
  current: () => recentSignal(store.root)
16160
16454
  };
16161
16455
  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" ? [path19.resolve(store.root, ref.path)] : []));
16456
+ const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [path20.resolve(store.root, ref.path)] : []));
16163
16457
  const observedFiles = filesKey(files);
16164
16458
  const compact = compactContext(store, context, entry?.id ?? null, freshness, origin && { origin: origin.origin, taskId: origin.entry.id });
16165
16459
  if (!compact.ok || !compact.data)
@@ -16218,17 +16512,17 @@ ${options.addendum}` : ""}
16218
16512
  </workit-contract>`;
16219
16513
  };
16220
16514
  var checkoutAt = (cwd) => {
16221
- for (let dir = path19.resolve(cwd);; dir = path19.dirname(dir)) {
16222
- const dotGit = path19.join(dir, ".git");
16223
- if (fs14.existsSync(dotGit)) {
16224
- const admin = fs14.statSync(dotGit).isFile() ? path19.resolve(dir, /^gitdir:\s*(.+)$/mu.exec(fs14.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "") : dotGit;
16225
- const head = fs14.readFileSync(path19.join(admin, "HEAD"), "utf8").trim();
16515
+ for (let dir = path20.resolve(cwd);; dir = path20.dirname(dir)) {
16516
+ const dotGit = path20.join(dir, ".git");
16517
+ if (fs15.existsSync(dotGit)) {
16518
+ const admin = fs15.statSync(dotGit).isFile() ? path20.resolve(dir, /^gitdir:\s*(.+)$/mu.exec(fs15.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "") : dotGit;
16519
+ const head = fs15.readFileSync(path20.join(admin, "HEAD"), "utf8").trim();
16226
16520
  return {
16227
16521
  root: dir,
16228
16522
  branch: /^ref: refs\/heads\/(.+)$/u.exec(head)?.[1] ?? null
16229
16523
  };
16230
16524
  }
16231
- if (path19.dirname(dir) === dir)
16525
+ if (path20.dirname(dir) === dir)
16232
16526
  return null;
16233
16527
  }
16234
16528
  };
@@ -16239,7 +16533,7 @@ var whereLine = (cwd) => {
16239
16533
  return null;
16240
16534
  const allowed = branchPolicySnapshotFor(cwd).namePolicy.allowed;
16241
16535
  const kinds = allowed.some((pattern) => pattern.source === "^.*$") ? "any" : allowedKinds(allowed).join(", ") || "see `workit help git`";
16242
- const place = checkout.root === path19.resolve(cwd) ? "" : ` in ${checkout.root}`;
16536
+ const place = checkout.root === path20.resolve(cwd) ? "" : ` in ${checkout.root}`;
16243
16537
  return `cwd ${cwd}${place} on ${checkout.branch ?? "detached HEAD"}; branch kinds: ${kinds}`;
16244
16538
  } catch {
16245
16539
  return null;
@@ -16266,32 +16560,32 @@ var turnMarker = (input) => {
16266
16560
  if (location instanceof Error)
16267
16561
  return null;
16268
16562
  const session = [input.host, input.session.id, input.session.agentId ?? ""].join("\x00");
16269
- return path19.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
16563
+ return path20.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
16270
16564
  } catch {
16271
16565
  return null;
16272
16566
  }
16273
16567
  };
16274
16568
  var writeTurnDigest = (file, digest) => {
16275
16569
  try {
16276
- fs14.mkdirSync(path19.dirname(file), { recursive: true });
16277
- fs14.writeFileSync(file, `${JSON.stringify({ digest })}
16570
+ fs15.mkdirSync(path20.dirname(file), { recursive: true });
16571
+ fs15.writeFileSync(file, `${JSON.stringify({ digest })}
16278
16572
  `);
16279
16573
  } catch {}
16280
16574
  };
16281
16575
  var clearTurnDigest = (file) => {
16282
16576
  try {
16283
- fs14.rmSync(file, { force: true });
16577
+ fs15.rmSync(file, { force: true });
16284
16578
  } catch {}
16285
16579
  };
16286
16580
  var pruneTurnDigests = (dir, now) => {
16287
16581
  try {
16288
- for (const name of fs14.readdirSync(dir)) {
16582
+ for (const name of fs15.readdirSync(dir)) {
16289
16583
  if (!name.startsWith("turn-"))
16290
16584
  continue;
16291
- const file = path19.join(dir, name);
16585
+ const file = path20.join(dir, name);
16292
16586
  try {
16293
- if (now - fs14.statSync(file).mtimeMs > TURN_TTL_MS)
16294
- fs14.rmSync(file, { force: true });
16587
+ if (now - fs15.statSync(file).mtimeMs > TURN_TTL_MS)
16588
+ fs15.rmSync(file, { force: true });
16295
16589
  } catch {}
16296
16590
  }
16297
16591
  } catch {}
@@ -16307,7 +16601,7 @@ var changedTurnContext = (input, text) => {
16307
16601
  return text;
16308
16602
  const digest = digestOf(text);
16309
16603
  try {
16310
- const previous = JSON.parse(fs14.readFileSync(file, "utf8"));
16604
+ const previous = JSON.parse(fs15.readFileSync(file, "utf8"));
16311
16605
  if (previous.digest === digest)
16312
16606
  return null;
16313
16607
  } catch {}
@@ -16318,7 +16612,7 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
16318
16612
  const file = turnMarker(input);
16319
16613
  if (!file)
16320
16614
  return;
16321
- pruneTurnDigests(path19.dirname(file), Date.now());
16615
+ pruneTurnDigests(path20.dirname(file), Date.now());
16322
16616
  if (text)
16323
16617
  writeTurnDigest(file, digestOf(text));
16324
16618
  else
@@ -16327,36 +16621,36 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
16327
16621
  // packages/workit-core/src/core/route-intent.ts
16328
16622
  import { spawnSync as spawnSync14 } from "node:child_process";
16329
16623
  import { existsSync as existsSync11 } from "node:fs";
16330
- import path25 from "node:path";
16624
+ import path26 from "node:path";
16331
16625
 
16332
16626
  // packages/workit-core/src/hooks/raw-git.ts
16333
16627
  import { spawnSync as spawnSync13 } from "node:child_process";
16334
16628
  import { createHash as createHash14 } from "node:crypto";
16335
- import fs16 from "node:fs";
16336
- import os5 from "node:os";
16337
- import path24 from "node:path";
16629
+ import fs17 from "node:fs";
16630
+ import os6 from "node:os";
16631
+ import path25 from "node:path";
16338
16632
 
16339
16633
  // packages/workit-core/src/autonomy.ts
16340
16634
  import { closeSync as closeSync2, copyFileSync, existsSync as existsSync10, openSync as openSync2 } from "node:fs";
16341
- import path22 from "node:path";
16635
+ import path23 from "node:path";
16342
16636
 
16343
16637
  // packages/workit-core/src/core/eval-world.ts
16344
16638
  import { existsSync as existsSync9, realpathSync as realpathSync7 } from "node:fs";
16345
- import os4 from "node:os";
16346
- import path20 from "node:path";
16639
+ import os5 from "node:os";
16640
+ import path21 from "node:path";
16347
16641
  var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
16348
16642
  var EVAL_WORLD_MARKER = ".workit-eval-world";
16349
16643
  var inside2 = (dir, file) => {
16350
- const rel = path20.relative(dir, file);
16351
- return !rel.startsWith("..") && !path20.isAbsolute(rel);
16644
+ const rel = path21.relative(dir, file);
16645
+ return !rel.startsWith("..") && !path21.isAbsolute(rel);
16352
16646
  };
16353
16647
  var evalWorld = (cwd) => {
16354
16648
  const raw = process.env[EVAL_WORLD_ENV];
16355
- if (!raw || !path20.isAbsolute(raw))
16649
+ if (!raw || !path21.isAbsolute(raw))
16356
16650
  return null;
16357
16651
  try {
16358
16652
  const world = realpathSync7(raw);
16359
- return inside2(realpathSync7(os4.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync9(path20.join(world, EVAL_WORLD_MARKER)) ? world : null;
16653
+ return inside2(realpathSync7(os5.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync9(path21.join(world, EVAL_WORLD_MARKER)) ? world : null;
16360
16654
  } catch {
16361
16655
  return null;
16362
16656
  }
@@ -16364,7 +16658,7 @@ var evalWorld = (cwd) => {
16364
16658
  var evalWorldEntry = (cwd) => {
16365
16659
  const world = evalWorld(cwd);
16366
16660
  try {
16367
- return world ? loadWorkspacesFrom(path20.join(world, "config"))[0] ?? null : null;
16661
+ return world ? loadWorkspacesFrom(path21.join(world, "config"))[0] ?? null : null;
16368
16662
  } catch {
16369
16663
  return null;
16370
16664
  }
@@ -16373,7 +16667,7 @@ var evalWorldEntry = (cwd) => {
16373
16667
  // packages/workit-core/src/core/grant-seal.ts
16374
16668
  import { createHash as createHash12 } from "node:crypto";
16375
16669
  import { readFileSync as readFileSync9 } from "node:fs";
16376
- import path21 from "node:path";
16670
+ import path22 from "node:path";
16377
16671
  var SEAL_FILE = "workspaces.json.seal";
16378
16672
  var SEAL_VERSION = 1;
16379
16673
  var SEAL_COMMAND = "workit workspace seal";
@@ -16407,15 +16701,15 @@ var sealProjection = (entries) => entries.map((entry) => {
16407
16701
  youtrack: pick2(all.youtrack, ["writes", "autoHosts"])
16408
16702
  }, ENTRY_KEYS);
16409
16703
  });
16410
- var canonical3 = (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);
16411
- var sealDigest = (projection) => createHash12("sha256").update(canonical3(projection)).digest("hex");
16704
+ 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);
16705
+ var sealDigest = (projection) => createHash12("sha256").update(canonical4(projection)).digest("hex");
16412
16706
  var broken = (reason, sealed = null) => ({
16413
16707
  state: "broken",
16414
16708
  reason,
16415
16709
  sealed
16416
16710
  });
16417
16711
  function checkSeal(dir) {
16418
- const file = path21.join(dir, SEAL_FILE);
16712
+ const file = path22.join(dir, SEAL_FILE);
16419
16713
  let seal;
16420
16714
  try {
16421
16715
  seal = JSON.parse(readFileSync9(file, "utf8"));
@@ -16473,7 +16767,7 @@ var accountHomeDir = () => {
16473
16767
  };
16474
16768
  var deniedFile = (dir) => {
16475
16769
  for (const name of ["workspaces.json", SEAL_FILE]) {
16476
- const file = path22.join(dir, name);
16770
+ const file = path23.join(dir, name);
16477
16771
  try {
16478
16772
  closeSync2(openSync2(file, "r"));
16479
16773
  } catch (error) {
@@ -16495,7 +16789,7 @@ var accountUnread = () => {
16495
16789
  if (dir === null)
16496
16790
  return NO_ACCOUNT;
16497
16791
  const file = deniedFile(dir);
16498
- return file === null ? null : `the account's ${path22.basename(file)} cannot be read (permission denied), so it reads as no workspace entries: no grants, no models, the D4 defaults apply`;
16792
+ 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
16793
  };
16500
16794
  var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
16501
16795
  var fileSource = (dir = accountDir()) => ({
@@ -16544,10 +16838,10 @@ var youTrackWritesPolicy = (cwd) => {
16544
16838
  return ASK;
16545
16839
  }
16546
16840
  };
16547
- var redirected = (dir) => path22.resolve(resolveConfigDir()) !== path22.resolve(dir);
16841
+ var redirected = (dir) => path23.resolve(resolveConfigDir()) !== path23.resolve(dir);
16548
16842
  var shownGrantsDir = () => {
16549
16843
  const world = evalWorld(process.cwd());
16550
- return world ? path22.join(world, "config") : accountDir();
16844
+ return world ? path23.join(world, "config") : accountDir();
16551
16845
  };
16552
16846
  var benchWorld = (cwd) => {
16553
16847
  const entry = evalWorldEntry(cwd);
@@ -16571,10 +16865,10 @@ var grantsOverride = () => {
16571
16865
  const shown = shownGrantsDir();
16572
16866
  if (shown === null)
16573
16867
  return accountUnread() ?? NO_ACCOUNT;
16574
- const configured = path22.resolve(resolveConfigDir());
16575
- return configured === path22.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 ${path22.join(grantsDir(), "workspaces.json")}, and under a redirect they never exceed the D4 defaults`;
16868
+ const configured = path23.resolve(resolveConfigDir());
16869
+ 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
16870
  };
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 ${path22.join(grantsDir(), "workspaces.json")}`;
16871
+ 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
16872
  var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
16579
16873
  var DEFAULT_GRANTS = Object.freeze({
16580
16874
  push: true,
@@ -16982,8 +17276,8 @@ var packageTagShapes = (packages) => packages.map((entry) => `${entry.tagNamespa
16982
17276
 
16983
17277
  // packages/workit-core/src/hooks/session-marker.ts
16984
17278
  import { createHash as createHash13 } from "node:crypto";
16985
- import fs15 from "node:fs";
16986
- import path23 from "node:path";
17279
+ import fs16 from "node:fs";
17280
+ import path24 from "node:path";
16987
17281
  var sessionMarkerFile = (input, session, store) => {
16988
17282
  let dir = store;
16989
17283
  if (dir === undefined) {
@@ -16993,7 +17287,7 @@ var sessionMarkerFile = (input, session, store) => {
16993
17287
  dir = location.dir;
16994
17288
  }
16995
17289
  const name = createHash13("sha256").update(`${input.host}\x00${session}`).digest("hex").slice(0, 32);
16996
- return path23.join(dir, "hooks", `skills-${name}.json`);
17290
+ return path24.join(dir, "hooks", `skills-${name}.json`);
16997
17291
  };
16998
17292
  var list = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
16999
17293
  var EMPTY = {
@@ -17006,7 +17300,7 @@ var EMPTY = {
17006
17300
  };
17007
17301
  var readRaw = (file) => {
17008
17302
  try {
17009
- return fs15.readFileSync(file, "utf8");
17303
+ return fs16.readFileSync(file, "utf8");
17010
17304
  } catch {
17011
17305
  return "";
17012
17306
  }
@@ -17028,13 +17322,13 @@ var parseMarker = (text) => {
17028
17322
  };
17029
17323
  var readSessionMarker = (file) => parseMarker(readRaw(file));
17030
17324
  var writeAtomic = (file, marker) => {
17031
- fs15.mkdirSync(path23.dirname(file), { recursive: true });
17325
+ fs16.mkdirSync(path24.dirname(file), { recursive: true });
17032
17326
  const temp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
17033
17327
  try {
17034
- fs15.writeFileSync(temp, JSON.stringify(marker));
17035
- fs15.renameSync(temp, file);
17328
+ fs16.writeFileSync(temp, JSON.stringify(marker));
17329
+ fs16.renameSync(temp, file);
17036
17330
  } catch (error) {
17037
- fs15.rmSync(temp, { force: true });
17331
+ fs16.rmSync(temp, { force: true });
17038
17332
  throw error;
17039
17333
  }
17040
17334
  };
@@ -17616,14 +17910,14 @@ var GIT_CONFIG_ENV = /^(?:GIT_(?:CONFIG\w*|DIR|COMMON_DIR|WORK_TREE|SSH|SSH_COMM
17616
17910
  var ASSIGNMENT2 = /^([A-Za-z_]\w*)=([\s\S]*)$/;
17617
17911
  var MAX_DEPTH = 4;
17618
17912
  var MAX_EXPANSIONS = 16;
17619
- var isAbsolute = (value) => path24.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
17913
+ var isAbsolute = (value) => path25.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
17620
17914
  var HERE = /^(?:\$PWD|\$\{PWD\}|\$\(\s*pwd\s*\)|`pwd`|\$\(\s*git\s+rev-parse\s+--show-toplevel\s*\))(?=$|[\\/])/;
17621
17915
  var joinDir = (base, raw) => {
17622
17916
  const next = raw.replace(HERE, ".");
17623
17917
  if (base === undefined || /[$`*?]/.test(next) || next === "-")
17624
17918
  return;
17625
- const expanded = next === "~" || next.startsWith("~/") ? path24.join(os5.homedir(), next.slice(1)) : next;
17626
- return base === null || isAbsolute(expanded) ? expanded : path24.join(base, expanded);
17919
+ const expanded = next === "~" || next.startsWith("~/") ? path25.join(os6.homedir(), next.slice(1)) : next;
17920
+ return base === null || isAbsolute(expanded) ? expanded : path25.join(base, expanded);
17627
17921
  };
17628
17922
  var rebase = (base, inner) => inner === null ? base : inner === undefined ? undefined : joinDir(base, inner);
17629
17923
  var cdTarget = (words) => {
@@ -18024,7 +18318,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
18024
18318
  }
18025
18319
  if (CD.has(name)) {
18026
18320
  const target = cdTarget(words);
18027
- dir = target === null ? os5.homedir() : joinDir(dir, target);
18321
+ dir = target === null ? os6.homedir() : joinDir(dir, target);
18028
18322
  } else if (PUSHD.has(name)) {
18029
18323
  const target = cdTarget(words);
18030
18324
  stack.push(dir);
@@ -18524,7 +18818,7 @@ var repoAt = (dir) => {
18524
18818
  return { location, dir, branch: resolveTaskKey(dir, location).branch };
18525
18819
  };
18526
18820
  var isWorkitWorkspace = (repo) => {
18527
- if (fs16.existsSync(repo.location.dir))
18821
+ if (fs17.existsSync(repo.location.dir))
18528
18822
  return true;
18529
18823
  try {
18530
18824
  return resolveRuntimeWorkspaceVcs(repo.location.top ?? repo.dir) !== null;
@@ -18545,17 +18839,17 @@ var headSha2 = (repo) => {
18545
18839
  if (!git || git.reftable)
18546
18840
  return null;
18547
18841
  try {
18548
- const head = fs16.readFileSync(path24.join(git.gitDir, "HEAD"), "utf8").trim();
18842
+ const head = fs17.readFileSync(path25.join(git.gitDir, "HEAD"), "utf8").trim();
18549
18843
  if (/^[0-9a-f]{40,64}$/.test(head))
18550
18844
  return head;
18551
18845
  const ref = /^ref: (refs\/.+)$/.exec(head)?.[1];
18552
18846
  if (!ref)
18553
18847
  return null;
18554
- const common = path24.dirname(repo.location.dir);
18848
+ const common = path25.dirname(repo.location.dir);
18555
18849
  try {
18556
- return fs16.readFileSync(path24.join(common, ref), "utf8").trim() || null;
18850
+ return fs17.readFileSync(path25.join(common, ref), "utf8").trim() || null;
18557
18851
  } catch {}
18558
- const packed = fs16.readFileSync(path24.join(common, "packed-refs"), "utf8");
18852
+ const packed = fs17.readFileSync(path25.join(common, "packed-refs"), "utf8");
18559
18853
  return new RegExp(`^([0-9a-f]{40,64}) ${ref.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`, "m").exec(packed)?.[1] ?? null;
18560
18854
  } catch {
18561
18855
  return null;
@@ -18648,8 +18942,8 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
18648
18942
  const sub = invocation.args[0];
18649
18943
  if (invocation.tool !== "git" || invocation.dir === undefined || !sub || sub.startsWith("-") || GIT_COMMANDS.has(sub) || depth >= MAX_DEPTH)
18650
18944
  return [invocation];
18651
- const dir = path24.resolve(root, invocation.dir ?? ".");
18652
- if (!fs16.existsSync(dir))
18945
+ const dir = path25.resolve(root, invocation.dir ?? ".");
18946
+ if (!fs17.existsSync(dir))
18653
18947
  return [invocation];
18654
18948
  const config = gitConfig(dir, invocation, cache);
18655
18949
  const alias = configValue(config, `alias.${sub.toLowerCase()}`);
@@ -18671,11 +18965,11 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
18671
18965
  var normalizedUrl = (url, dir) => {
18672
18966
  const trimmed = url.trim();
18673
18967
  if (/^file:\/\//i.test(trimmed))
18674
- return path24.resolve(dir, trimmed.slice(7)).replace(/\/+$/, "").replace(/\.git$/, "");
18968
+ return path25.resolve(dir, trimmed.slice(7)).replace(/\/+$/, "").replace(/\.git$/, "");
18675
18969
  const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(trimmed);
18676
18970
  const scp = !scheme && /^(?:[^@/\\]+@)?[^/\\:]{2,}:/.test(trimmed);
18677
18971
  if (!scheme && !scp)
18678
- return path24.resolve(dir, trimmed).replace(/\/+$/, "").replace(/\.git$/, "");
18972
+ return path25.resolve(dir, trimmed).replace(/\/+$/, "").replace(/\.git$/, "");
18679
18973
  const value = scheme ? trimmed.slice(scheme[0].length).replace(/^[^@/]*@/, "").replace(/^([^/:]+):\d+(?=\/)/, "$1") : trimmed.replace(/^[^@/]*@/, "").replace(":", "/");
18680
18974
  return value.toLowerCase().replace(/\/{2,}/g, "/").replace(/^www\./, "").replace(/\/+$/, "").replace(/\.git$/, "");
18681
18975
  };
@@ -18916,7 +19210,7 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
18916
19210
  const out = [];
18917
19211
  const repos = new Map;
18918
19212
  const repoFor = (relative) => {
18919
- const dir = path24.resolve(cwd, relative ?? ".");
19213
+ const dir = path25.resolve(cwd, relative ?? ".");
18920
19214
  if (!repos.has(dir)) {
18921
19215
  const repo = repoAt(dir);
18922
19216
  const workit = repo !== null && isWorkitWorkspace(repo);
@@ -18937,7 +19231,7 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
18937
19231
  const action = rawAction(invocation);
18938
19232
  const at = !action ? null : repoFor(invocation.dir) ?? (all && invocation.tool !== "git" && explicitRepo(invocation.tool === "gh", "repo" in action && action.repo || "", invocation.env ?? {}) ? {
18939
19233
  repo: {
18940
- dir: path24.resolve(cwd, invocation.dir ?? "."),
19234
+ dir: path25.resolve(cwd, invocation.dir ?? "."),
18941
19235
  branch: null
18942
19236
  },
18943
19237
  workit: false
@@ -19010,13 +19304,13 @@ var messageOf = (segment, index) => {
19010
19304
  };
19011
19305
  var sameGitDir = (a, b, platform = process.platform) => {
19012
19306
  if (platform !== "win32")
19013
- return path24.posix.resolve(a) === path24.posix.resolve(b);
19014
- const fold = (value) => path24.win32.resolve(value).toLowerCase();
19307
+ return path25.posix.resolve(a) === path25.posix.resolve(b);
19308
+ const fold = (value) => path25.win32.resolve(value).toLowerCase();
19015
19309
  return fold(a) === fold(b);
19016
19310
  };
19017
19311
  var cdCommitCall = (input, command, target, repo) => {
19018
19312
  const { top, git, dir: store } = repo.location;
19019
- if (!top || !git || sameGitDir(git.gitDir, path24.dirname(store)) || repoAt(input.cwd)?.location.top === top)
19313
+ if (!top || !git || sameGitDir(git.gitDir, path25.dirname(store)) || repoAt(input.cwd)?.location.top === top)
19020
19314
  return null;
19021
19315
  const bare = command.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"/gu, "").replaceAll("&&", "");
19022
19316
  if (/[;|&<>`$()\n\\]/u.test(bare))
@@ -19025,7 +19319,7 @@ var cdCommitCall = (input, command, target, repo) => {
19025
19319
  const commit = rest.at(-1);
19026
19320
  if (cd?.words[0] !== "cd" || cd.words.length !== 2 || cd.expands?.length || !commit)
19027
19321
  return null;
19028
- if (path24.resolve(input.cwd, cd.words[1]) !== target)
19322
+ if (path25.resolve(input.cwd, cd.words[1]) !== target)
19029
19323
  return null;
19030
19324
  if (rest.some((each) => each.redirects.length || each.stdin?.length || each.group))
19031
19325
  return null;
@@ -19092,7 +19386,7 @@ var commitRefusal = (input, command, dialect, { action, repo, invocation, workit
19092
19386
  } catch {}
19093
19387
  if (guarded && !switches)
19094
19388
  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>")}.`;
19095
- const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path24.resolve(input.cwd, invocation.dir), repo);
19389
+ const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path25.resolve(input.cwd, invocation.dir), repo);
19096
19390
  return call && `workit: no ${quote("cd … &&")} chain; run ${quote(call)}.`;
19097
19391
  };
19098
19392
  function rawGitPre(input, command, options = {}) {
@@ -19221,9 +19515,9 @@ var grantRefusal = (action, repo, invocation, cache) => {
19221
19515
  return null;
19222
19516
  };
19223
19517
  var localTag = (repo, name) => {
19224
- const common = path24.dirname(repo.location.dir);
19518
+ const common = path25.dirname(repo.location.dir);
19225
19519
  try {
19226
- return fs16.existsSync(path24.join(common, "refs/tags", name)) || fs16.readFileSync(path24.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
19520
+ return fs17.existsSync(path25.join(common, "refs/tags", name)) || fs17.readFileSync(path25.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
19227
19521
  `);
19228
19522
  } catch {
19229
19523
  return false;
@@ -19243,7 +19537,7 @@ var analysisDenial = (error) => ({
19243
19537
  });
19244
19538
  var NEXT_COMMAND = "next";
19245
19539
  var MARKER_TTL_SECONDS = 3600;
19246
- var markerFile = (repo, session, key) => path24.join(repo.location.dir, "hooks", `commit-${createHash14("sha256").update(`${session}\x00${key}`).digest("hex").slice(0, 32)}.json`);
19540
+ var markerFile = (repo, session, key) => path25.join(repo.location.dir, "hooks", `commit-${createHash14("sha256").update(`${session}\x00${key}`).digest("hex").slice(0, 32)}.json`);
19247
19541
  var callKey = (toolUseId, command) => toolUseId ?? `cmd:${createHash14("sha256").update(command).digest("hex")}`;
19248
19542
  function noteRawCommit(input, command, key) {
19249
19543
  try {
@@ -19254,8 +19548,8 @@ function noteRawCommit(input, command, key) {
19254
19548
  if (action.kind !== "commit")
19255
19549
  continue;
19256
19550
  const file = markerFile(repo, input.session.id, key);
19257
- fs16.mkdirSync(path24.dirname(file), { recursive: true });
19258
- fs16.writeFileSync(file, `${JSON.stringify({ head: headSha2(repo), at })}
19551
+ fs17.mkdirSync(path25.dirname(file), { recursive: true });
19552
+ fs17.writeFileSync(file, `${JSON.stringify({ head: headSha2(repo), at })}
19259
19553
  `);
19260
19554
  }
19261
19555
  } catch {}
@@ -19288,11 +19582,11 @@ var headCommit = (dir) => {
19288
19582
  var settle2 = (input, repo, file) => {
19289
19583
  let marker;
19290
19584
  try {
19291
- marker = JSON.parse(fs16.readFileSync(file, "utf8"));
19585
+ marker = JSON.parse(fs17.readFileSync(file, "utf8"));
19292
19586
  } catch {
19293
19587
  return;
19294
19588
  }
19295
- fs16.rmSync(file, { force: true });
19589
+ fs17.rmSync(file, { force: true });
19296
19590
  const session = input.session.id;
19297
19591
  const now = Date.now() / 1000;
19298
19592
  if (typeof marker.at !== "number" || now - marker.at > MARKER_TTL_SECONDS)
@@ -19341,7 +19635,7 @@ function settlePendingCommit(input) {
19341
19635
  if (!repo)
19342
19636
  return;
19343
19637
  const file = markerFile(repo, input.session.id, NEXT_COMMAND);
19344
- if (fs16.existsSync(file))
19638
+ if (fs17.existsSync(file))
19345
19639
  settle2(input, repo, file);
19346
19640
  } catch {}
19347
19641
  }
@@ -19495,7 +19789,7 @@ var judgedDir = (root, dir) => {
19495
19789
  return null;
19496
19790
  if (dir === null)
19497
19791
  return root;
19498
- const resolved = path25.resolve(root, dir);
19792
+ const resolved = path26.resolve(root, dir);
19499
19793
  return existsSync11(resolved) && inWorkitWorkspace(resolved) ? resolved : null;
19500
19794
  };
19501
19795
  var shellBranchPolicyViolation = (root, command, dialect = "posix") => {
@@ -19692,13 +19986,13 @@ var askedWorkitCall = (command, dialect = "posix", depth = 0) => {
19692
19986
  return null;
19693
19987
  };
19694
19988
  // packages/workit-core/src/core/heavy-rules.ts
19695
- import fs17 from "node:fs";
19696
- import os6 from "node:os";
19697
- import path26 from "node:path";
19989
+ import fs18 from "node:fs";
19990
+ import os7 from "node:os";
19991
+ import path27 from "node:path";
19698
19992
  var EMPTY2 = () => ({ deny: [], allow: [] });
19699
19993
  var readText3 = (file) => {
19700
19994
  try {
19701
- return fs17.readFileSync(file, "utf8");
19995
+ return fs18.readFileSync(file, "utf8");
19702
19996
  } catch (error) {
19703
19997
  if (error.code === "ENOENT")
19704
19998
  return null;
@@ -19735,23 +20029,23 @@ function parseJsonc(text) {
19735
20029
  return JSON.parse(out.replace(/,(\s*[}\]])/gu, "$1"));
19736
20030
  }
19737
20031
  function gitTop(cwd) {
19738
- for (let dir = path26.resolve(cwd);; dir = path26.dirname(dir)) {
19739
- if (fs17.existsSync(path26.join(dir, ".git")))
20032
+ for (let dir = path27.resolve(cwd);; dir = path27.dirname(dir)) {
20033
+ if (fs18.existsSync(path27.join(dir, ".git")))
19740
20034
  return dir;
19741
- if (path26.dirname(dir) === dir)
20035
+ if (path27.dirname(dir) === dir)
19742
20036
  return null;
19743
20037
  }
19744
20038
  }
19745
20039
  var projectDirs = (cwd) => {
19746
20040
  const top = gitTop(cwd);
19747
20041
  const dirs = [];
19748
- for (let dir = path26.resolve(cwd);; dir = path26.dirname(dir)) {
20042
+ for (let dir = path27.resolve(cwd);; dir = path27.dirname(dir)) {
19749
20043
  dirs.push(dir);
19750
- if (!top || dir === top || path26.dirname(dir) === dir)
20044
+ if (!top || dir === top || path27.dirname(dir) === dir)
19751
20045
  return dirs;
19752
20046
  }
19753
20047
  };
19754
- var homeOf = (env) => env.HOME || os6.homedir();
20048
+ var homeOf = (env) => env.HOME || os7.homedir();
19755
20049
  var CLAUDE_MANAGED = {
19756
20050
  linux: "/etc/claude-code/managed-settings.json",
19757
20051
  darwin: "/Library/Application Support/ClaudeCode/managed-settings.json",
@@ -19759,12 +20053,12 @@ var CLAUDE_MANAGED = {
19759
20053
  };
19760
20054
  function claudeSettingsFiles(cwd, env, platform = process.platform) {
19761
20055
  const project = env.CLAUDE_PROJECT_DIR || gitTop(cwd) || cwd;
19762
- const user = env.CLAUDE_CONFIG_DIR || path26.join(homeOf(env), ".claude");
20056
+ const user = env.CLAUDE_CONFIG_DIR || path27.join(homeOf(env), ".claude");
19763
20057
  return [
19764
20058
  ...CLAUDE_MANAGED[platform] ? [CLAUDE_MANAGED[platform]] : [],
19765
- path26.join(user, "settings.json"),
19766
- path26.join(project, ".claude", "settings.json"),
19767
- path26.join(project, ".claude", "settings.local.json")
20059
+ path27.join(user, "settings.json"),
20060
+ path27.join(project, ".claude", "settings.json"),
20061
+ path27.join(project, ".claude", "settings.local.json")
19768
20062
  ];
19769
20063
  }
19770
20064
  var bashPattern = (entry) => {
@@ -19871,10 +20165,10 @@ var opencodeConfig = (value, rules) => isRecord5(value) && opencodeRuleset(value
19871
20165
  function opencodeRules(cwd, env = process.env) {
19872
20166
  const rules = EMPTY2();
19873
20167
  try {
19874
- const config = env.XDG_CONFIG_HOME || path26.join(homeOf(env), ".config");
20168
+ const config = env.XDG_CONFIG_HOME || path27.join(homeOf(env), ".config");
19875
20169
  const files = [
19876
- ...OPENCODE_NAMES.map((name) => path26.join(config, "opencode", name)),
19877
- ...projectDirs(cwd).flatMap((dir) => OPENCODE_NAMES.flatMap((name) => [path26.join(dir, name), path26.join(dir, ".opencode", name)])),
20170
+ ...OPENCODE_NAMES.map((name) => path27.join(config, "opencode", name)),
20171
+ ...projectDirs(cwd).flatMap((dir) => OPENCODE_NAMES.flatMap((name) => [path27.join(dir, name), path27.join(dir, ".opencode", name)])),
19878
20172
  ...env.OPENCODE_CONFIG ? [env.OPENCODE_CONFIG] : []
19879
20173
  ];
19880
20174
  for (const file of files) {
@@ -19918,19 +20212,19 @@ var codexRule = (body) => {
19918
20212
  function codexRules(cwd, env = process.env) {
19919
20213
  const rules = EMPTY2();
19920
20214
  try {
19921
- const home = env.CODEX_HOME || path26.join(homeOf(env), ".codex");
20215
+ const home = env.CODEX_HOME || path27.join(homeOf(env), ".codex");
19922
20216
  const top = gitTop(cwd) ?? cwd;
19923
- for (const dir of [path26.join(home, "rules"), path26.join(top, ".codex", "rules")]) {
20217
+ for (const dir of [path27.join(home, "rules"), path27.join(top, ".codex", "rules")]) {
19924
20218
  let files;
19925
20219
  try {
19926
- files = fs17.readdirSync(dir).filter((name) => name.endsWith(".rules"));
20220
+ files = fs18.readdirSync(dir).filter((name) => name.endsWith(".rules"));
19927
20221
  } catch (error) {
19928
20222
  if (error.code === "ENOENT")
19929
20223
  continue;
19930
20224
  return "unreadable";
19931
20225
  }
19932
20226
  for (const name of files) {
19933
- const text = readText3(path26.join(dir, name)) ?? "";
20227
+ const text = readText3(path27.join(dir, name)) ?? "";
19934
20228
  for (const part of text.split(/\bprefix_rule\s*\(/u).slice(1)) {
19935
20229
  const rule = codexRule(part);
19936
20230
  if (!rule)
@@ -19949,8 +20243,8 @@ function cursorRules(cwd, env = process.env) {
19949
20243
  try {
19950
20244
  const top = gitTop(cwd) ?? cwd;
19951
20245
  for (const file of [
19952
- path26.join(homeOf(env), ".cursor", "cli-config.json"),
19953
- path26.join(top, ".cursor", "cli.json")
20246
+ path27.join(homeOf(env), ".cursor", "cli-config.json"),
20247
+ path27.join(top, ".cursor", "cli.json")
19954
20248
  ]) {
19955
20249
  const text = readText3(file);
19956
20250
  if (text === null)
@@ -20024,11 +20318,11 @@ function wrapAllowed(read, words, command, options = {}) {
20024
20318
  }
20025
20319
 
20026
20320
  // packages/workit-core/src/core/heavy.ts
20027
- import fs18 from "node:fs";
20028
- import path27 from "node:path";
20321
+ import fs19 from "node:fs";
20322
+ import path28 from "node:path";
20029
20323
  var stateDir = (env, platform = process.platform) => stateDir3(env, platform);
20030
20324
  var HEAVY_COMMANDS_FILE = "heavy-commands.json";
20031
- var heavyCommandsFile = (env) => path27.join(stateDir(env), HEAVY_COMMANDS_FILE);
20325
+ var heavyCommandsFile = (env) => path28.join(stateDir(env), HEAVY_COMMANDS_FILE);
20032
20326
  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;
20033
20327
  var INFO_FLAGS = new Set(["--version", "-v", "-V", "--help", "-h", "help", "version"]);
20034
20328
  var WATCH_FLAG = /^(?:--watch(?:All)?(?:=.*)?|-w|--serve)$/u;
@@ -20380,7 +20674,7 @@ function parsePattern(pattern) {
20380
20674
  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]));
20381
20675
  var readJson = (file) => {
20382
20676
  try {
20383
- return JSON.parse(fs18.readFileSync(file, "utf8"));
20677
+ return JSON.parse(fs19.readFileSync(file, "utf8"));
20384
20678
  } catch {
20385
20679
  return;
20386
20680
  }
@@ -20392,7 +20686,7 @@ function machinePatterns(env) {
20392
20686
  return isRecord6(value) ? stringList(value.patterns) : [];
20393
20687
  }
20394
20688
  function repoPatterns(cwd) {
20395
- return repoHeavyCommands(gitTop(cwd) ?? path27.resolve(cwd));
20689
+ return repoHeavyCommands(gitTop(cwd) ?? path28.resolve(cwd));
20396
20690
  }
20397
20691
  function heavyLines(lines, options) {
20398
20692
  const found = [];
@@ -20495,12 +20789,12 @@ function serverPlan(command, options) {
20495
20789
  }
20496
20790
  function workitOnPath(env = process.env) {
20497
20791
  const names = process.platform === "win32" ? ["workit.exe", "workit.cmd", "workit"] : ["workit"];
20498
- for (const dir of (env.PATH ?? "").split(path27.delimiter))
20792
+ for (const dir of (env.PATH ?? "").split(path28.delimiter))
20499
20793
  for (const name of names) {
20500
20794
  if (!dir)
20501
20795
  continue;
20502
20796
  try {
20503
- fs18.accessSync(path27.join(dir, name), fs18.constants.X_OK);
20797
+ fs19.accessSync(path28.join(dir, name), fs19.constants.X_OK);
20504
20798
  return true;
20505
20799
  } catch {}
20506
20800
  }
@@ -20586,15 +20880,15 @@ import {
20586
20880
  realpathSync as realpathSync8,
20587
20881
  statSync as statSync3
20588
20882
  } from "node:fs";
20589
- import os8 from "node:os";
20590
- import path29 from "node:path";
20883
+ import os9 from "node:os";
20884
+ import path30 from "node:path";
20591
20885
 
20592
20886
  // packages/workit-core/src/core/live-session.ts
20593
20887
  import { spawnSync as spawnSync15 } from "node:child_process";
20594
20888
  import { createHash as createHash15 } from "node:crypto";
20595
- import fs19 from "node:fs";
20596
- import os7 from "node:os";
20597
- import path28 from "node:path";
20889
+ import fs20 from "node:fs";
20890
+ import os8 from "node:os";
20891
+ import path29 from "node:path";
20598
20892
  var LIVE_SESSION_TTL_MS = 15 * 60000;
20599
20893
  var HEARTBEAT_EVERY_MS = 30000;
20600
20894
  var liveProbe = {
@@ -20615,9 +20909,9 @@ var processAlive = (pid) => {
20615
20909
  var processInfo = (pid) => {
20616
20910
  try {
20617
20911
  if (liveProbe.platform === "linux") {
20618
- const stat = fs19.readFileSync(`/proc/${pid}/stat`, "utf8");
20912
+ const stat = fs20.readFileSync(`/proc/${pid}/stat`, "utf8");
20619
20913
  const ppid = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
20620
- const command = fs19.readFileSync(`/proc/${pid}/cmdline`, "utf8").replaceAll("\x00", " ");
20914
+ const command = fs20.readFileSync(`/proc/${pid}/cmdline`, "utf8").replaceAll("\x00", " ");
20621
20915
  return Number.isInteger(ppid) ? { ppid, command: command.trim() } : null;
20622
20916
  }
20623
20917
  if (liveProbe.platform === "win32")
@@ -20668,35 +20962,35 @@ var liveOwner = (input, transport, env = process.env) => {
20668
20962
  };
20669
20963
  };
20670
20964
  var checkoutOf = (target) => {
20671
- let dir = path28.resolve(target);
20672
- while (!fs19.existsSync(dir) && path28.dirname(dir) !== dir)
20673
- dir = path28.dirname(dir);
20674
- if (fs19.existsSync(dir) && !fs19.statSync(dir).isDirectory())
20675
- dir = path28.dirname(dir);
20676
- const parts = dir.split(path28.sep);
20965
+ let dir = path29.resolve(target);
20966
+ while (!fs20.existsSync(dir) && path29.dirname(dir) !== dir)
20967
+ dir = path29.dirname(dir);
20968
+ if (fs20.existsSync(dir) && !fs20.statSync(dir).isDirectory())
20969
+ dir = path29.dirname(dir);
20970
+ const parts = dir.split(path29.sep);
20677
20971
  const dotGit = parts.lastIndexOf(".git");
20678
20972
  if (dotGit > 0)
20679
- dir = parts.slice(0, dotGit).join(path28.sep) || path28.sep;
20973
+ dir = parts.slice(0, dotGit).join(path29.sep) || path29.sep;
20680
20974
  const location = resolveStore(dir);
20681
20975
  if (location instanceof Error || !location.shared || !location.top)
20682
20976
  return null;
20683
20977
  let top = location.top;
20684
20978
  try {
20685
- top = fs19.realpathSync.native(top);
20979
+ top = fs20.realpathSync.native(top);
20686
20980
  } catch {}
20687
20981
  return top;
20688
20982
  };
20689
- var markerFile2 = (top) => path28.join(resolveStateDir(), "live-sessions", `${createHash15("sha256").update(checkoutKey(top)).digest("hex").slice(0, 32)}.json`);
20983
+ var markerFile2 = (top) => path29.join(resolveStateDir(), "live-sessions", `${createHash15("sha256").update(checkoutKey(top)).digest("hex").slice(0, 32)}.json`);
20690
20984
  var checkoutKey = (top, platform = process.platform) => {
20691
- let key = path28.resolve(top);
20985
+ let key = path29.resolve(top);
20692
20986
  try {
20693
- key = fs19.realpathSync.native(key);
20987
+ key = fs20.realpathSync.native(key);
20694
20988
  } catch {}
20695
20989
  return platform === "win32" ? key.replaceAll("/", "\\").toLowerCase() : key;
20696
20990
  };
20697
20991
  var readMarker = (file) => {
20698
20992
  try {
20699
- const value = JSON.parse(fs19.readFileSync(file, "utf8"));
20993
+ const value = JSON.parse(fs20.readFileSync(file, "utf8"));
20700
20994
  if (value?.version !== 1 || typeof value.session !== "string" || typeof value.host !== "string" || typeof value.heartbeatAt !== "string" || Number.isNaN(Date.parse(value.heartbeatAt)))
20701
20995
  return null;
20702
20996
  return {
@@ -20719,7 +21013,7 @@ var isLive = (marker, deps) => {
20719
21013
  const age = ageOf2(marker, deps.now ?? new Date);
20720
21014
  if (age > (deps.ttlMs ?? LIVE_SESSION_TTL_MS))
20721
21015
  return false;
20722
- if (marker.machine !== (deps.machine ?? os7.hostname()) || marker.pid === null)
21016
+ if (marker.machine !== (deps.machine ?? os8.hostname()) || marker.pid === null)
20723
21017
  return true;
20724
21018
  if (!(deps.alive ?? processAlive)(marker.pid))
20725
21019
  return false;
@@ -20748,7 +21042,7 @@ var liveConflict = (target, owner, deps = {}) => {
20748
21042
  const marker = readMarker(file);
20749
21043
  if (!marker || sameLead(marker, owner) || !isLive(marker, deps))
20750
21044
  return null;
20751
- if (sameOwner(marker, owner, deps.machine ?? os7.hostname()))
21045
+ if (sameOwner(marker, owner, deps.machine ?? os8.hostname()))
20752
21046
  return null;
20753
21047
  return { marker, file, ageMs: ageOf2(marker, deps.now ?? new Date), checkout };
20754
21048
  } catch {
@@ -20762,7 +21056,7 @@ var claimLiveSession = (target, owner, deps = {}) => {
20762
21056
  return;
20763
21057
  const file = markerFile2(checkout);
20764
21058
  const now = deps.now ?? new Date;
20765
- const machine = deps.machine ?? os7.hostname();
21059
+ const machine = deps.machine ?? os8.hostname();
20766
21060
  const current = readMarker(file);
20767
21061
  if (current) {
20768
21062
  const age = ageOf2(current, now);
@@ -20783,10 +21077,10 @@ var claimLiveSession = (target, owner, deps = {}) => {
20783
21077
  checkout,
20784
21078
  heartbeatAt: now.toISOString()
20785
21079
  };
20786
- fs19.mkdirSync(path28.dirname(file), { recursive: true });
21080
+ fs20.mkdirSync(path29.dirname(file), { recursive: true });
20787
21081
  const temp = `${file}.${process.pid}.tmp`;
20788
- fs19.writeFileSync(temp, JSON.stringify(marker));
20789
- fs19.renameSync(temp, file);
21082
+ fs20.writeFileSync(temp, JSON.stringify(marker));
21083
+ fs20.renameSync(temp, file);
20790
21084
  } catch {}
20791
21085
  };
20792
21086
 
@@ -20796,44 +21090,44 @@ var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "wi
20796
21090
  var linkTarget = (file) => {
20797
21091
  try {
20798
21092
  const to = readlinkSync3(file);
20799
- let from = path29.dirname(file);
21093
+ let from = path30.dirname(file);
20800
21094
  try {
20801
21095
  from = realpathSync8.native(from);
20802
21096
  } catch {}
20803
- return path29.resolve(from, to);
21097
+ return path30.resolve(from, to);
20804
21098
  } catch {
20805
21099
  return null;
20806
21100
  }
20807
21101
  };
20808
21102
  var realPath = (file, dangling = true) => {
20809
- let dir = path29.resolve(file);
21103
+ let dir = path30.resolve(file);
20810
21104
  let rest = "";
20811
21105
  for (let hops = 0;; ) {
20812
21106
  try {
20813
- return path29.join(realpathSync8.native(dir), rest);
21107
+ return path30.join(realpathSync8.native(dir), rest);
20814
21108
  } catch {
20815
21109
  const link = dangling ? linkTarget(dir) : null;
20816
21110
  if (link !== null) {
20817
21111
  if (++hops > 40)
20818
21112
  return null;
20819
- dir = path29.join(link, rest);
21113
+ dir = path30.join(link, rest);
20820
21114
  rest = "";
20821
- } else if (path29.dirname(dir) === dir)
20822
- return path29.resolve(file);
21115
+ } else if (path30.dirname(dir) === dir)
21116
+ return path30.resolve(file);
20823
21117
  else {
20824
- rest = rest ? path29.join(path29.basename(dir), rest) : path29.basename(dir);
20825
- dir = path29.dirname(dir);
21118
+ rest = rest ? path30.join(path30.basename(dir), rest) : path30.basename(dir);
21119
+ dir = path30.dirname(dir);
20826
21120
  }
20827
21121
  }
20828
21122
  }
20829
21123
  };
20830
- var canonical4 = (file, dangling = true) => realPath(file, dangling) ?? path29.resolve(file);
21124
+ var canonical5 = (file, dangling = true) => realPath(file, dangling) ?? path30.resolve(file);
20831
21125
  var exempt = (cwd, root, file, plans) => {
20832
21126
  const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
20833
- const relative = path29.relative(fold(canonical4(root, false)), fold(canonical4(path29.resolve(cwd, file), false)));
20834
- if (relative.startsWith("..") || path29.isAbsolute(relative))
21127
+ const relative = path30.relative(fold(canonical5(root, false)), fold(canonical5(path30.resolve(cwd, file), false)));
21128
+ if (relative.startsWith("..") || path30.isAbsolute(relative))
20835
21129
  return true;
20836
- const posix = relative.split(path29.sep).join("/");
21130
+ const posix = relative.split(path30.sep).join("/");
20837
21131
  const segments = posix.split("/");
20838
21132
  return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
20839
21133
  };
@@ -20950,8 +21244,8 @@ var WRAPPERS3 = {
20950
21244
  bunx: "p"
20951
21245
  };
20952
21246
  var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
20953
- var isConfigDir = (file) => configDirs().some((dir) => canonical4(dir) === canonical4(file));
20954
- var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test(path29.relative(canonical4(resolveStateDir()), canonical4(file)));
21247
+ var isConfigDir = (file) => configDirs().some((dir) => canonical5(dir) === canonical5(file));
21248
+ var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test(path30.relative(canonical5(resolveStateDir()), canonical5(file)));
20955
21249
  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)$/;
20956
21250
  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)$/;
20957
21251
  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)/;
@@ -21291,10 +21585,10 @@ var linkSources = (args, at) => {
21291
21585
  const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
21292
21586
  const target = dest === undefined ? null : at(dest);
21293
21587
  const symbolic = args.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg));
21294
- const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path29.dirname(target);
21588
+ const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path30.dirname(target);
21295
21589
  return sources.flatMap((source) => {
21296
- if (symbolic && base !== null && !path29.isAbsolute(homeExpanded(source)))
21297
- return [path29.resolve(base, source)];
21590
+ if (symbolic && base !== null && !path30.isAbsolute(homeExpanded(source)))
21591
+ return [path30.resolve(base, source)];
21298
21592
  const resolved = at(source);
21299
21593
  return resolved ? [resolved] : [];
21300
21594
  });
@@ -21323,7 +21617,7 @@ var shellWrites = (command, depth = 0) => {
21323
21617
  return { writes: true, targets: unknown ? null : targets };
21324
21618
  };
21325
21619
  var cache2 = new Map;
21326
- var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path29.resolve(root, file)) ?? "-").join("\x00");
21620
+ var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path30.resolve(root, file)) ?? "-").join("\x00");
21327
21621
  var gateFor = (cwd) => {
21328
21622
  const store = new TaskReader(cwd);
21329
21623
  const listed = store.listTaskIndex();
@@ -21386,7 +21680,7 @@ var DIR_TARGET = ".workit-live-target";
21386
21680
  var PLACEHOLDERS = new WeakMap;
21387
21681
  var collecting = null;
21388
21682
  var placeholderIn = (dir, name) => {
21389
- const target = path29.join(dir, name);
21683
+ const target = path30.join(dir, name);
21390
21684
  collecting?.add(target);
21391
21685
  return target;
21392
21686
  };
@@ -21426,13 +21720,13 @@ var gitMutationDirs = (cwd, command, dialect) => {
21426
21720
  return [];
21427
21721
  if (sub === "stash" && ["list", "show"].includes(rest[0] ?? ""))
21428
21722
  return [];
21429
- return [path29.resolve(cwd, invocation.dir ?? ".")];
21723
+ return [path30.resolve(cwd, invocation.dir ?? ".")];
21430
21724
  });
21431
21725
  };
21432
21726
  var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
21433
21727
  var PUSHD2 = new Set(["pushd", "push-location"]);
21434
21728
  var POPD2 = new Set(["popd", "pop-location"]);
21435
- var UNKNOWN_DIR = path29.resolve(path29.parse(process.cwd()).root, ".workit-unknown-dir");
21729
+ var UNKNOWN_DIR = path30.resolve(path30.parse(process.cwd()).root, ".workit-unknown-dir");
21436
21730
  var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
21437
21731
  const lost = strict ? UNKNOWN_DIR : undefined;
21438
21732
  const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
@@ -21442,7 +21736,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
21442
21736
  return lost;
21443
21737
  if (dir === undefined)
21444
21738
  return lost;
21445
- return target === undefined ? os8.homedir() : path29.resolve(dir, target);
21739
+ return target === undefined ? os9.homedir() : path30.resolve(dir, target);
21446
21740
  };
21447
21741
  var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
21448
21742
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
@@ -21577,7 +21871,7 @@ var untrustedVars = (segments) => {
21577
21871
  }
21578
21872
  return { all, names };
21579
21873
  };
21580
- var UNKNOWN_VAR = path29.resolve(path29.parse(process.cwd()).root, ".workit-unknown-var");
21874
+ var UNKNOWN_VAR = path30.resolve(path30.parse(process.cwd()).root, ".workit-unknown-var");
21581
21875
  var REFERENCE = /\$\{(\w+)[^}]*\}|\$(\w+)|\$\([^)]*\)?|`[^`]*`?/g;
21582
21876
  var unresolvedRefs = (text) => [
21583
21877
  ...new Set([...text.matchAll(REFERENCE)].map((match) => {
@@ -21587,7 +21881,7 @@ var unresolvedRefs = (text) => [
21587
21881
  ];
21588
21882
  var unknownVarTarget = (text) => {
21589
21883
  const refs = unresolvedRefs(text);
21590
- return path29.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
21884
+ return path30.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
21591
21885
  };
21592
21886
  var applyOperator = (value, operator) => {
21593
21887
  if (operator === "")
@@ -21646,18 +21940,18 @@ var mktempPath = (value, dir) => {
21646
21940
  template = arg;
21647
21941
  }
21648
21942
  if (base === null && (temp || template === undefined))
21649
- base = os8.tmpdir();
21943
+ base = os9.tmpdir();
21650
21944
  const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
21651
- if (path29.isAbsolute(name))
21945
+ if (path30.isAbsolute(name))
21652
21946
  return name;
21653
21947
  const from = base === null ? dir : homeExpanded(base);
21654
- if (from === undefined || !path29.isAbsolute(from) && dir === undefined)
21948
+ if (from === undefined || !path30.isAbsolute(from) && dir === undefined)
21655
21949
  return null;
21656
- return path29.resolve(dir ?? from, from, name);
21950
+ return path30.resolve(dir ?? from, from, name);
21657
21951
  };
21658
21952
  var homeExpanded = (file) => {
21659
21953
  const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
21660
- return match ? (process.env.HOME || os8.homedir()) + file.slice(match[0].length) : file;
21954
+ return match ? (process.env.HOME || os9.homedir()) + file.slice(match[0].length) : file;
21661
21955
  };
21662
21956
  var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherited = new Map) => {
21663
21957
  const targets = [];
@@ -21674,7 +21968,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
21674
21968
  const home = homeExpanded(text);
21675
21969
  if (strict && unresolvedRefs(home).length > 0)
21676
21970
  return [unknownVarTarget(home)];
21677
- if (path29.isAbsolute(home))
21971
+ if (path30.isAbsolute(home))
21678
21972
  return [home];
21679
21973
  return base === undefined ? [] : [resolvedUnder(base, home)];
21680
21974
  });
@@ -21869,7 +22163,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
21869
22163
  index
21870
22164
  }));
21871
22165
  const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
21872
- const under = (word) => homes ? [path29.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
22166
+ const under = (word) => homes ? [path30.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
21873
22167
  const found = [
21874
22168
  ...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
21875
22169
  ...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
@@ -21877,7 +22171,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
21877
22171
  for (const { file, index } of found) {
21878
22172
  const use = isRoot(file) ? rootUse(text, index) : "takes";
21879
22173
  if (use !== "reads")
21880
- targets.push(use === "builds" ? path29.join(file, UNRESOLVED_TARGET) : file);
22174
+ targets.push(use === "builds" ? path30.join(file, UNRESOLVED_TARGET) : file);
21881
22175
  }
21882
22176
  }
21883
22177
  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"))))
@@ -21912,7 +22206,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
21912
22206
  for (const file of opaque ?? [])
21913
22207
  for (const resolved of atAll(file))
21914
22208
  if (!quiet || !isRoot(resolved))
21915
- targets.push(file === "." ? placeholderIn(resolved, here) : path29.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path29.dirname(resolved), path29.basename(resolved)) : resolved);
22209
+ targets.push(file === "." ? placeholderIn(resolved, here) : path30.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path30.dirname(resolved), path30.basename(resolved)) : resolved);
21916
22210
  const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
21917
22211
  const lnArgs = words.slice(ln + 1);
21918
22212
  if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)) && (strict !== "registry" || !lnArgs.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg))))
@@ -21991,7 +22285,7 @@ var liveDeny = ({ marker, checkout, ageMs, file }) => {
21991
22285
  var guarded = (targets) => {
21992
22286
  const seen = new Set;
21993
22287
  return targets.filter((target) => {
21994
- const dir = path29.dirname(target);
22288
+ const dir = path30.dirname(target);
21995
22289
  if (seen.has(dir))
21996
22290
  return false;
21997
22291
  seen.add(dir);
@@ -22012,17 +22306,17 @@ var claimAll = (owner, targets, deps) => {
22012
22306
  for (const target of guarded(targets))
22013
22307
  claimLiveSession(target, owner, deps);
22014
22308
  };
22015
- var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path29.resolve(dir, file) : path29.isAbsolute(file) ? file : `${dir}${path29.sep}${file}`;
22309
+ var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path30.resolve(dir, file) : path30.isAbsolute(file) ? file : `${dir}${path30.sep}${file}`;
22016
22310
  var liveTargets = (cwd, paths) => recording(() => paths?.length ? paths.map((file) => resolvedUnder(cwd, file)) : [placeholderIn(cwd, DIR_TARGET)]);
22017
22311
  var CONFIG_FILES = ["workspaces.json", SEAL_FILE];
22018
22312
  var configDirs = () => [resolveConfigDir(), grantsDir()];
22019
22313
  var globbed = (cwd, target, state, configs) => {
22020
22314
  if (!/[*?[]/.test(target))
22021
22315
  return [];
22022
- const raw = path29.resolve(cwd, target).split(path29.sep);
22316
+ const raw = path30.resolve(cwd, target).split(path30.sep);
22023
22317
  const literal = raw.findIndex((part) => /[*?[]/.test(part));
22024
22318
  const pattern = [
22025
- ...canonical4(raw.slice(0, literal).join(path29.sep) || path29.sep).replace(/[\\/]+$/, "").split(path29.sep),
22319
+ ...canonical5(raw.slice(0, literal).join(path30.sep) || path30.sep).replace(/[\\/]+$/, "").split(path30.sep),
22026
22320
  ...raw.slice(literal)
22027
22321
  ];
22028
22322
  const segment = (glob, name) => {
@@ -22033,7 +22327,7 @@ var globbed = (cwd, target, state, configs) => {
22033
22327
  }
22034
22328
  };
22035
22329
  const hit = (file, below) => {
22036
- const parts = canonical4(file).split(path29.sep);
22330
+ const parts = canonical5(file).split(path30.sep);
22037
22331
  return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
22038
22332
  };
22039
22333
  let roots = [];
@@ -22041,8 +22335,8 @@ var globbed = (cwd, target, state, configs) => {
22041
22335
  roots = readdirSync3(state).filter((name) => /^(?:issued|approvals$)/.test(name));
22042
22336
  } catch {}
22043
22337
  return [
22044
- ...roots.map((name) => path29.join(state, name)).filter((root) => hit(root, true)),
22045
- ...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path29.join(dir, name))]).filter((file) => hit(file, false))
22338
+ ...roots.map((name) => path30.join(state, name)).filter((root) => hit(root, true)),
22339
+ ...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path30.join(dir, name))]).filter((file) => hit(file, false))
22046
22340
  ];
22047
22341
  };
22048
22342
  var guardedInodes = (state, configs) => {
@@ -22056,15 +22350,15 @@ var guardedInodes = (state, configs) => {
22056
22350
  seen.set(`${stat.dev}:${stat.ino}`, registry);
22057
22351
  else if (stat?.isDirectory())
22058
22352
  for (const name of readdirSync3(file))
22059
- add(path29.join(file, name), registry);
22353
+ add(path30.join(file, name), registry);
22060
22354
  };
22061
22355
  try {
22062
22356
  for (const dir of configs)
22063
22357
  for (const name of CONFIG_FILES)
22064
- add(path29.join(dir, name), "grants");
22358
+ add(path30.join(dir, name), "grants");
22065
22359
  for (const name of readdirSync3(state))
22066
22360
  if (/^(?:issued|approvals$)/.test(name))
22067
- add(path29.join(state, name), name === "approvals" ? "approvals" : "issued");
22361
+ add(path30.join(state, name), name === "approvals" ? "approvals" : "issued");
22068
22362
  } catch {}
22069
22363
  return seen;
22070
22364
  };
@@ -22085,13 +22379,13 @@ var registryTarget = (cwd, targets) => {
22085
22379
  const inodes = {};
22086
22380
  for (const target of targets) {
22087
22381
  const file = homeExpanded(target);
22088
- if (realPath(path29.resolve(cwd, file)) === null)
22382
+ if (realPath(path30.resolve(cwd, file)) === null)
22089
22383
  return { file: target, registry: "link" };
22090
22384
  const glob = globbed(cwd, file, state, configs)[0];
22091
22385
  const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
22092
22386
  if (viaGlob)
22093
22387
  return { file: target, registry: viaGlob.registry };
22094
- const registry = hardLinked(path29.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical4) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical4)) ? "grants" : null);
22388
+ 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);
22095
22389
  if (registry)
22096
22390
  return { file: target, registry };
22097
22391
  }
@@ -22099,7 +22393,7 @@ var registryTarget = (cwd, targets) => {
22099
22393
  };
22100
22394
  var partsUnder = (dir, cwd, target, platform, real) => {
22101
22395
  const win = platform === "win32";
22102
- const p = win ? path29.win32 : path29.posix;
22396
+ const p = win ? path30.win32 : path30.posix;
22103
22397
  const fold = (value) => win || platform === "darwin" ? value.toLowerCase() : value;
22104
22398
  const named = win ? target.replace(/^\/([a-zA-Z])(?=\/|$)/, "$1:") : target;
22105
22399
  const relative = p.relative(fold(real(p.resolve(dir))), fold(real(p.resolve(cwd, named))));
@@ -22161,13 +22455,13 @@ var REGISTRY_DENY = {
22161
22455
  };
22162
22456
  var registryDeny = ({ file, registry }) => {
22163
22457
  const { label, what, unblock } = REGISTRY_DENY[registry];
22164
- if (path29.basename(file) === UNRESOLVED_TARGET)
22458
+ if (path30.basename(file) === UNRESOLVED_TARGET)
22165
22459
  return {
22166
22460
  kind: "deny",
22167
22461
  reason: `workit ${label}: Workit could not resolve the file this command's script writes, which it builds from a path under ${what}. ${unblock}`,
22168
22462
  unblock
22169
22463
  };
22170
- const named = path29.basename(file).startsWith(".workit-") ? path29.dirname(file) : file;
22464
+ const named = path30.basename(file).startsWith(".workit-") ? path30.dirname(file) : file;
22171
22465
  return {
22172
22466
  kind: "deny",
22173
22467
  reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
@@ -22256,11 +22550,11 @@ function beforeWriteGate(cwd, paths) {
22256
22550
  import { spawnSync as spawnSync16 } from "node:child_process";
22257
22551
 
22258
22552
  // packages/workit-core/src/ci-waiter.ts
22259
- import fs20 from "node:fs";
22260
- import path30 from "node:path";
22553
+ import fs21 from "node:fs";
22554
+ import path31 from "node:path";
22261
22555
  var waiterFile = (cwd, pr) => {
22262
22556
  const common = gitCommonDir(cwd);
22263
- return common ? path30.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
22557
+ return common ? path31.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
22264
22558
  };
22265
22559
  var pidAlive2 = (pid) => {
22266
22560
  if (!Number.isSafeInteger(pid) || pid <= 0)
@@ -22303,7 +22597,7 @@ var liveCiWaiter = (cwd, pr, head = null, nowMs = Date.now()) => {
22303
22597
  const file = waiterFile(cwd, pr);
22304
22598
  if (!file)
22305
22599
  return null;
22306
- const waiter = parse3(fs20.readFileSync(file, "utf8"));
22600
+ const waiter = parse3(fs21.readFileSync(file, "utf8"));
22307
22601
  if (!waiter || waiter.pr !== pr || waiter.pid === process.pid)
22308
22602
  return null;
22309
22603
  if (head && waiter.head && !sameSha(waiter.head, head))
@@ -22763,12 +23057,12 @@ ${line}` };
22763
23057
  };
22764
23058
  // packages/workit-core/src/hooks/hosts/fields.ts
22765
23059
  import { existsSync as existsSync13, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
22766
- import path31 from "node:path";
23060
+ import path32 from "node:path";
22767
23061
  var isRecord7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
22768
23062
  var nonEmpty2 = (value) => typeof value === "string" && value.trim() !== "";
22769
23063
  var optionalText = (value) => typeof value === "string" ? value : null;
22770
23064
  var existingDirectory = (value) => {
22771
- if (!nonEmpty2(value) || !path31.isAbsolute(value) || !existsSync13(value))
23065
+ if (!nonEmpty2(value) || !path32.isAbsolute(value) || !existsSync13(value))
22772
23066
  return null;
22773
23067
  try {
22774
23068
  return statSync4(value).isDirectory() ? realpathSync9(value) : null;
@@ -22835,8 +23129,8 @@ var writeTargets = (input) => {
22835
23129
  return paths.length > 0 ? paths : null;
22836
23130
  };
22837
23131
  // packages/workit-core/src/hooks/standing.ts
22838
- import fs22 from "node:fs";
22839
- import path33 from "node:path";
23132
+ import fs23 from "node:fs";
23133
+ import path34 from "node:path";
22840
23134
 
22841
23135
  // packages/workit-core/src/approvals/store.ts
22842
23136
  var REQUEST_TTL_MS = 30 * 60000;
@@ -23542,41 +23836,41 @@ function neededChecks(lane, configured) {
23542
23836
 
23543
23837
  // packages/workit-core/src/hooks/worktree-confine.ts
23544
23838
  import { createHash as createHash16 } from "node:crypto";
23545
- import fs21 from "node:fs";
23546
- import os9 from "node:os";
23547
- import path32 from "node:path";
23839
+ import fs22 from "node:fs";
23840
+ import os10 from "node:os";
23841
+ import path33 from "node:path";
23548
23842
  var FANOUT_TOKEN_FILE = "workit-fanout-token";
23549
23843
  var NONE5 = { kind: "none" };
23550
23844
  var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
23551
23845
  var realOf = (file) => {
23552
23846
  let rest = "";
23553
- for (let dir = file;; dir = path32.dirname(dir)) {
23847
+ for (let dir = file;; dir = path33.dirname(dir)) {
23554
23848
  try {
23555
- return path32.join(fs21.realpathSync.native(dir), rest);
23849
+ return path33.join(fs22.realpathSync.native(dir), rest);
23556
23850
  } catch {
23557
- if (path32.dirname(dir) === dir)
23851
+ if (path33.dirname(dir) === dir)
23558
23852
  return file;
23559
- rest = rest ? path32.join(path32.basename(dir), rest) : path32.basename(dir);
23853
+ rest = rest ? path33.join(path33.basename(dir), rest) : path33.basename(dir);
23560
23854
  }
23561
23855
  }
23562
23856
  };
23563
- var canonical5 = (file, hops = { chain: 40, total: 1000 }) => {
23564
- const start = path32.isAbsolute(file) ? file : `${process.cwd()}${path32.sep}${file}`;
23565
- const { root } = path32.parse(start);
23857
+ var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
23858
+ const start = path33.isAbsolute(file) ? file : `${process.cwd()}${path33.sep}${file}`;
23859
+ const { root } = path33.parse(start);
23566
23860
  let at = root;
23567
23861
  let missing = false;
23568
23862
  for (const part of start.slice(root.length).split(/[\\/]+/)) {
23569
23863
  if (part === "" || part === ".")
23570
23864
  continue;
23571
23865
  if (part === "..") {
23572
- at = path32.dirname(at);
23866
+ at = path33.dirname(at);
23573
23867
  continue;
23574
23868
  }
23575
- const next = path32.join(at, part);
23869
+ const next = path33.join(at, part);
23576
23870
  let link = null;
23577
23871
  if (!missing)
23578
23872
  try {
23579
- link = fs21.readlinkSync(next);
23873
+ link = fs22.readlinkSync(next);
23580
23874
  } catch (error) {
23581
23875
  missing = error.code !== "EINVAL";
23582
23876
  }
@@ -23584,25 +23878,25 @@ var canonical5 = (file, hops = { chain: 40, total: 1000 }) => {
23584
23878
  at = next;
23585
23879
  hops.chain = 40;
23586
23880
  } else if (hops.chain-- > 0 && hops.total-- > 0)
23587
- at = canonical5(path32.isAbsolute(link) ? link : `${at}${path32.sep}${link}`, hops);
23881
+ at = canonical6(path33.isAbsolute(link) ? link : `${at}${path33.sep}${link}`, hops);
23588
23882
  else
23589
- return path32.resolve(file);
23883
+ return path33.resolve(file);
23590
23884
  }
23591
23885
  return realOf(at);
23592
23886
  };
23593
23887
  var within = (child, parent) => {
23594
23888
  const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
23595
- const relative = path32.relative(fold(parent), fold(child));
23596
- return relative === "" || !relative.startsWith("..") && !path32.isAbsolute(relative);
23889
+ const relative = path33.relative(fold(parent), fold(child));
23890
+ return relative === "" || !relative.startsWith("..") && !path33.isAbsolute(relative);
23597
23891
  };
23598
23892
  var checkoutOf2 = (file) => {
23599
- for (let dir = canonical5(file);; dir = path32.dirname(dir)) {
23600
- const dotGit = path32.join(dir, ".git");
23601
- if (fs21.existsSync(dotGit)) {
23602
- const admin = fs21.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
23603
- return { root: dir, workit: !!admin && fs21.existsSync(path32.join(admin, FANOUT_TOKEN_FILE)) };
23893
+ for (let dir = canonical6(file);; dir = path33.dirname(dir)) {
23894
+ const dotGit = path33.join(dir, ".git");
23895
+ if (fs22.existsSync(dotGit)) {
23896
+ const admin = fs22.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
23897
+ return { root: dir, workit: !!admin && fs22.existsSync(path33.join(admin, FANOUT_TOKEN_FILE)) };
23604
23898
  }
23605
- if (path32.dirname(dir) === dir)
23899
+ if (path33.dirname(dir) === dir)
23606
23900
  return null;
23607
23901
  }
23608
23902
  };
@@ -23614,11 +23908,11 @@ var workitWorktreeOf = (file) => {
23614
23908
  return null;
23615
23909
  }
23616
23910
  };
23617
- var bindingDir = () => path32.join(resolveStateDir(), "worktree-bind");
23618
- var bindingFile = (session, agentId) => path32.join(bindingDir(), `${createHash16("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
23911
+ var bindingDir = () => path33.join(resolveStateDir(), "worktree-bind");
23912
+ var bindingFile = (session, agentId) => path33.join(bindingDir(), `${createHash16("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
23619
23913
  var readBinding = (file) => {
23620
23914
  try {
23621
- const value = JSON.parse(fs21.readFileSync(file, "utf8"));
23915
+ const value = JSON.parse(fs22.readFileSync(file, "utf8"));
23622
23916
  return typeof value.worktree === "string" ? value : null;
23623
23917
  } catch {
23624
23918
  return null;
@@ -23640,8 +23934,8 @@ var bind = (input, worktree) => {
23640
23934
  agentId,
23641
23935
  at: new Date().toISOString()
23642
23936
  };
23643
- fs21.mkdirSync(path32.dirname(file), { recursive: true });
23644
- fs21.writeFileSync(file, JSON.stringify(binding));
23937
+ fs22.mkdirSync(path33.dirname(file), { recursive: true });
23938
+ fs22.writeFileSync(file, JSON.stringify(binding));
23645
23939
  try {
23646
23940
  if (inWorkitWorkspace(input.cwd))
23647
23941
  appendHookObserved(input.cwd, {
@@ -23659,26 +23953,26 @@ var hostIsolated = (cwd, agentId) => {
23659
23953
  const checkout = checkoutOf2(cwd);
23660
23954
  if (!checkout)
23661
23955
  return false;
23662
- const dotGit = path32.join(checkout.root, ".git");
23663
- if (!fs21.statSync(dotGit).isFile())
23956
+ const dotGit = path33.join(checkout.root, ".git");
23957
+ if (!fs22.statSync(dotGit).isFile())
23664
23958
  return false;
23665
23959
  const [adminDir, gitDir] = gitDirsAt(checkout.root, null, false) ?? [];
23666
- const back = fs21.readFileSync(path32.join(adminDir, "gitdir"), "utf8").trim();
23667
- if (path32.relative(canonical5(path32.resolve(adminDir, back)), canonical5(dotGit)) !== "")
23960
+ const back = fs22.readFileSync(path33.join(adminDir, "gitdir"), "utf8").trim();
23961
+ if (path33.relative(canonical6(path33.resolve(adminDir, back)), canonical6(dotGit)) !== "")
23668
23962
  return false;
23669
- const expected = path32.join(path32.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
23670
- return path32.relative(canonical5(expected), checkout.root) === "";
23963
+ const expected = path33.join(path33.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
23964
+ return path33.relative(canonical6(expected), checkout.root) === "";
23671
23965
  } catch {
23672
23966
  return false;
23673
23967
  }
23674
23968
  };
23675
23969
  var runnerAt = (target) => {
23676
- const base = path32.basename(target);
23970
+ const base = path33.basename(target);
23677
23971
  return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
23678
23972
  };
23679
23973
  var shown = (target) => {
23680
- const named = /^\.workit-(?:live-target$|runs-)/.test(path32.basename(target)) ? path32.dirname(target) : target;
23681
- return path32.sep === "\\" ? named.replaceAll("/", "\\") : named;
23974
+ const named = /^\.workit-(?:live-target$|runs-)/.test(path33.basename(target)) ? path33.dirname(target) : target;
23975
+ return path33.sep === "\\" ? named.replaceAll("/", "\\") : named;
23682
23976
  };
23683
23977
  var runFrom = (dir, command) => `cd ${dir} && ${command.replace(/^\s*cd\s+\S+\s*(?:&&|;)\s*/, "")}`;
23684
23978
  var deny2 = (what, unblock) => ({
@@ -23694,7 +23988,7 @@ var outsideDeny = (input, worktree, target, command) => {
23694
23988
  };
23695
23989
  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\`.`);
23696
23990
  var refsOf = (targets) => [
23697
- ...new Set(targets.flatMap((target) => path32.relative(UNKNOWN_VAR, path32.resolve(target)).split(path32.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
23991
+ ...new Set(targets.flatMap((target) => path33.relative(UNKNOWN_VAR, path33.resolve(target)).split(path33.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
23698
23992
  ];
23699
23993
  var literalForm = (command, refs) => {
23700
23994
  let text = command;
@@ -23727,13 +24021,13 @@ function confineImplementer(input, targets, command) {
23727
24021
  try {
23728
24022
  if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
23729
24023
  return NONE5;
23730
- const unresolved = targets.filter((target) => within(path32.resolve(target), UNKNOWN_VAR));
24024
+ const unresolved = targets.filter((target) => within(path33.resolve(target), UNKNOWN_VAR));
23731
24025
  if (unresolved.length > 0)
23732
24026
  return unknownVarDeny(input, unresolved, command);
23733
- if (targets.some((target) => within(path32.resolve(target), UNKNOWN_DIR)))
24027
+ if (targets.some((target) => within(path33.resolve(target), UNKNOWN_DIR)))
23734
24028
  return unknownDirDeny(input, boundWorktree(input));
23735
- const bindings = canonical5(bindingDir());
23736
- const judged = targets.map((named) => ({ named, real: canonical5(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
24029
+ const bindings = canonical6(bindingDir());
24030
+ const judged = targets.map((named) => ({ named, real: canonical6(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
23737
24031
  if (judged.length === 0)
23738
24032
  return NONE5;
23739
24033
  let worktree = boundWorktree(input);
@@ -23747,7 +24041,7 @@ function confineImplementer(input, targets, command) {
23747
24041
  return unboundDeny(input, judged[0].named);
23748
24042
  bind(input, worktree);
23749
24043
  }
23750
- const root = canonical5(worktree);
24044
+ const root = canonical6(worktree);
23751
24045
  const outside = judged.find(({ real }) => !within(real, root) || within(real, bindings));
23752
24046
  return outside ? outsideDeny(input, worktree, outside.named, command) : NONE5;
23753
24047
  } catch {
@@ -23837,10 +24131,10 @@ var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print|test|version|help)$|^-[hvV]$/
23837
24131
  var VALUED2 = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
23838
24132
  var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
23839
24133
  var inScratch = (real, repo) => {
23840
- for (let dir = real;path32.dirname(dir) !== dir; dir = path32.dirname(dir)) {
23841
- if (path32.basename(dir) !== SCRATCH)
24134
+ for (let dir = real;path33.dirname(dir) !== dir; dir = path33.dirname(dir)) {
24135
+ if (path33.basename(dir) !== SCRATCH)
23842
24136
  continue;
23843
- const root = path32.dirname(dir);
24137
+ const root = path33.dirname(dir);
23844
24138
  const checkout = checkoutOf2(root);
23845
24139
  if (checkout?.root === root && (repo === null || checkout.workit || commonDir(root) === repo))
23846
24140
  return true;
@@ -23850,9 +24144,9 @@ var inScratch = (real, repo) => {
23850
24144
  var inGitDir = (real) => real.split(/[\\/]/).includes(".git");
23851
24145
  var SAFE_KEY = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|ignorecase|precomposeunicode|symlinks)|user\..*|init\.defaultbranch|commit\.gpgsign|extensions\.(?:objectformat|refstorage)|branch\..*\.(?:remote|merge)|remote\..*\.fetch)$/;
23852
24146
  var literalIn = (value, repo, checkout = false) => {
23853
- if (/[$`]/.test(value) || !path32.isAbsolute(value))
24147
+ if (/[$`]/.test(value) || !path33.isAbsolute(value))
23854
24148
  return false;
23855
- const real = canonical5(value);
24149
+ const real = canonical6(value);
23856
24150
  const root = checkout ? checkoutOf2(real)?.root : undefined;
23857
24151
  return inScratch(real, repo) || root !== undefined && (repo === null || commonDir(root) === repo);
23858
24152
  };
@@ -23871,45 +24165,45 @@ var configEntries = (text) => {
23871
24165
  return entries;
23872
24166
  };
23873
24167
  function gitDirsAt(dir, repo, scan = true) {
23874
- for (let at = dir;; at = path32.dirname(at)) {
23875
- const dotGit = path32.join(at, ".git");
24168
+ for (let at = dir;; at = path33.dirname(at)) {
24169
+ const dotGit = path33.join(at, ".git");
23876
24170
  let gitDir = null;
23877
24171
  try {
23878
- if (fs21.statSync(dotGit).isDirectory())
23879
- gitDir = canonical5(dotGit);
24172
+ if (fs22.statSync(dotGit).isDirectory())
24173
+ gitDir = canonical6(dotGit);
23880
24174
  else {
23881
- const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs21.readFileSync(dotGit, "utf8"))?.[1];
24175
+ const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs22.readFileSync(dotGit, "utf8"))?.[1];
23882
24176
  if (!named)
23883
24177
  return null;
23884
- gitDir = canonical5(path32.resolve(at, named));
24178
+ gitDir = canonical6(path33.resolve(at, named));
23885
24179
  }
23886
24180
  } catch (error) {
23887
24181
  if (error.code !== "ENOENT")
23888
24182
  return null;
23889
- if (["HEAD", "objects", "refs"].every((name) => fs21.existsSync(path32.join(at, name))))
23890
- gitDir = canonical5(at);
24183
+ if (["HEAD", "objects", "refs"].every((name) => fs22.existsSync(path33.join(at, name))))
24184
+ gitDir = canonical6(at);
23891
24185
  }
23892
24186
  if (gitDir !== null) {
23893
- const common = path32.join(gitDir, "commondir");
23894
- const shared = fs21.existsSync(common) ? canonical5(path32.resolve(gitDir, fs21.readFileSync(common, "utf8").trim())) : gitDir;
24187
+ const common = path33.join(gitDir, "commondir");
24188
+ const shared = fs22.existsSync(common) ? canonical6(path33.resolve(gitDir, fs22.readFileSync(common, "utf8").trim())) : gitDir;
23895
24189
  const dirs = [gitDir, shared];
23896
- for (const config of scan ? new Set([path32.join(gitDir, "config"), path32.join(shared, "config")]) : []) {
24190
+ for (const config of scan ? new Set([path33.join(gitDir, "config"), path33.join(shared, "config")]) : []) {
23897
24191
  let text = "";
23898
24192
  try {
23899
- text = fs21.readFileSync(config, "utf8");
24193
+ text = fs22.readFileSync(config, "utf8");
23900
24194
  } catch {
23901
24195
  continue;
23902
24196
  }
23903
24197
  for (const [key, value] of configEntries(text)) {
23904
24198
  if (key === "core.worktree")
23905
- dirs.push(canonical5(path32.resolve(gitDir, value)));
24199
+ dirs.push(canonical6(path33.resolve(gitDir, value)));
23906
24200
  else if (/^remote\..*\.url$/.test(key) ? !literalIn(value, repo, true) : !SAFE_KEY.test(key))
23907
24201
  return null;
23908
24202
  }
23909
24203
  }
23910
24204
  return dirs;
23911
24205
  }
23912
- if (path32.dirname(at) === at)
24206
+ if (path33.dirname(at) === at)
23913
24207
  return [];
23914
24208
  }
23915
24209
  }
@@ -24049,10 +24343,10 @@ var gitKind = (args, local = () => true) => {
24049
24343
  return GIT_VERBS[verb].startsWith("+") ? "write" : "read";
24050
24344
  };
24051
24345
  var remoteIn = (dir, name, repo) => {
24052
- const shared = path32.isAbsolute(dir) ? gitDirsAt(canonical5(dir), repo, false)?.[1] : undefined;
24346
+ const shared = path33.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
24053
24347
  if (!shared)
24054
24348
  return false;
24055
- const url = configEntries(fs21.readFileSync(path32.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
24349
+ const url = configEntries(fs22.readFileSync(path33.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
24056
24350
  return url !== undefined && literalIn(url, repo, true);
24057
24351
  };
24058
24352
  var judgeGit = (command, repo, cwd, depth = 0) => {
@@ -24066,7 +24360,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
24066
24360
  const lead = [];
24067
24361
  while (/^\w+\+?=/.test(words[at] ?? ""))
24068
24362
  lead.push(words[at++]);
24069
- const name = path32.basename(words[at] ?? "");
24363
+ const name = path33.basename(words[at] ?? "");
24070
24364
  let start = words.findIndex((word) => /(?:^|[\\/])git(?:\.exe)?(?:=|$)/.test(word));
24071
24365
  if (start > at) {
24072
24366
  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] ?? ""))
@@ -24077,7 +24371,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
24077
24371
  if (start >= 0 && words[start].includes("="))
24078
24372
  why = "git is redefined";
24079
24373
  const run = words[start] ?? "";
24080
- if (run.includes("/") && (!path32.isAbsolute(run) || literalIn(run, repo, true)))
24374
+ if (run.includes("/") && (!path33.isAbsolute(run) || literalIn(run, repo, true)))
24081
24375
  why ??= `\`${run}\` is not the system git`;
24082
24376
  if (segment.expands?.includes(at) && name !== "[" || /\{[^}]*,/.test(words[at] ?? ""))
24083
24377
  why = "the command's name is expanded by the shell";
@@ -24102,13 +24396,13 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
24102
24396
  const args = words[index] === "--version" ? ["version"] : words.slice(index);
24103
24397
  if (!why && start >= 0) {
24104
24398
  const local = (source, remote) => remote && /^[\w-][\w.-]*$/.test(source) ? remoteIn(dir, source, repo) : literalIn(source, repo, true);
24105
- const runsIn = path32.isAbsolute(dir) ? dir : cwd && path32.resolve(cwd, dir);
24399
+ const runsIn = path33.isAbsolute(dir) ? dir : cwd && path33.resolve(cwd, dir);
24106
24400
  const home = runsIn && checkoutOf2(runsIn);
24107
24401
  const fetches = args[0] === "fetch" && plainFetch(args.slice(1)) && home && (home.workit || commonDir(home.root) === repo) && !words.some((word) => /^--[gw]/.test(word));
24108
24402
  if (!fetches && !gitKind(args, local))
24109
24403
  why = `\`git ${args.slice(0, 2).join(" ")}\` is not allowed`;
24110
24404
  }
24111
- const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path32.basename(word)));
24405
+ 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)));
24112
24406
  const scripts = [
24113
24407
  ...words.filter((_, after) => shell >= 0 && after > shell && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(words[after - 1])),
24114
24408
  ...shell < 0 ? [] : segment.stdin ?? []
@@ -24153,7 +24447,7 @@ var judgeVerbRefused = (args) => {
24153
24447
  var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
24154
24448
  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?$/;
24155
24449
  var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
24156
- const name = path32.basename(words[0] ?? "").toLowerCase();
24450
+ const name = path33.basename(words[0] ?? "").toLowerCase();
24157
24451
  if (name === "alias")
24158
24452
  return words.flatMap((word) => {
24159
24453
  const set = /^([\w-]+)=(.*)$/s.exec(word);
@@ -24182,11 +24476,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
24182
24476
  return why;
24183
24477
  }
24184
24478
  const { words } = segment;
24185
- const runs = (word = "") => RUNS.test(path32.basename(word).toLowerCase());
24479
+ const runs = (word = "") => RUNS.test(path33.basename(word).toLowerCase());
24186
24480
  let at = 0;
24187
24481
  while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
24188
24482
  at++;
24189
- const name = path32.basename(words[at] ?? "").toLowerCase();
24483
+ const name = path33.basename(words[at] ?? "").toLowerCase();
24190
24484
  const args = words.slice(at + 1);
24191
24485
  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`;
24192
24486
  if (/^(?:cd|chdir|pushd|popd)$/.test(name))
@@ -24268,9 +24562,9 @@ var judgeDeny = (input, what, target, retry) => {
24268
24562
  const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
24269
24563
  const root = checkoutOf2(input.cwd)?.root;
24270
24564
  const candidate = target ? checkoutOf2(target)?.root : undefined;
24271
- const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path32.join(candidate, SCRATCH) : undefined;
24272
- const scratch = root ? `${path32.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
24273
- const call = root ? retry?.((other ?? path32.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
24565
+ const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path33.join(candidate, SCRATCH) : undefined;
24566
+ const scratch = root ? `${path33.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
24567
+ const call = root ? retry?.((other ?? path33.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
24274
24568
  const unblock = call ? `Retry as: ${call}` : "Why: write only there (mkdir -p it); a fix the candidate needs is a finding (`workit finding record`).";
24275
24569
  return {
24276
24570
  kind: "deny",
@@ -24281,9 +24575,9 @@ ${unblock}`,
24281
24575
  };
24282
24576
  var movedInto = (command, cwd, target, dir) => {
24283
24577
  for (const { words, redirects } of segmentsOf(command))
24284
- for (const word of [...redirects, ...path32.basename(words[0] ?? "") === "tee" ? words : []])
24285
- if (path32.resolve(cwd, word) === path32.resolve(cwd, target)) {
24286
- const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path32.basename(word)}`);
24578
+ for (const word of [...redirects, ...path33.basename(words[0] ?? "") === "tee" ? words : []])
24579
+ if (path33.resolve(cwd, word) === path33.resolve(cwd, target)) {
24580
+ const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path33.basename(word)}`);
24287
24581
  return moved === command ? null : moved;
24288
24582
  }
24289
24583
  return null;
@@ -24294,20 +24588,20 @@ function confineJudge(input, targets, placeholders = placeholdersOf(targets), co
24294
24588
  return NONE5;
24295
24589
  const judged = checkoutOf2(input.cwd);
24296
24590
  const repo = judged ? commonDir(judged.root) : null;
24297
- const scratch = (real) => inScratch(real, repo) || [os9.tmpdir(), "/tmp"].some((dir) => {
24298
- const [host, , session] = path32.relative(canonical5(dir), real).split(path32.sep);
24591
+ const scratch = (real) => inScratch(real, repo) || [os10.tmpdir(), "/tmp"].some((dir) => {
24592
+ const [host, , session] = path33.relative(canonical6(dir), real).split(path33.sep);
24299
24593
  return /^claude-\d+$/.test(host) && session === input.session.id;
24300
24594
  });
24301
24595
  for (const target of targets) {
24302
- const resolved = path32.resolve(target);
24596
+ const resolved = path33.resolve(target);
24303
24597
  if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
24304
24598
  return judgeDeny(input, "it writes to a path Workit cannot resolve", undefined, () => {
24305
24599
  const literal = command && literalForm(command, refsOf([target]));
24306
24600
  return literal === command ? null : literal;
24307
24601
  });
24308
- const real = canonical5(target);
24309
- const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path32.basename(target));
24310
- const gitDirs = runsGit ? gitDirsAt(path32.dirname(real), repo) : [];
24602
+ const real = canonical6(target);
24603
+ const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path33.basename(target));
24604
+ const gitDirs = runsGit ? gitDirsAt(path33.dirname(real), repo) : [];
24311
24605
  if (gitDirs === null)
24312
24606
  return judgeDeny(input, `git in ${shown(target)} uses a git dir or config Workit cannot check`);
24313
24607
  if (runsGit ? gitDirs.length > 0 ? gitDirs.every(scratch) : scratch(real) : scratch(real) && !inGitDir(real))
@@ -24373,7 +24667,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
24373
24667
  let git = [];
24374
24668
  try {
24375
24669
  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)))) ? [
24376
- path32.join(dir === undefined ? UNKNOWN_DIR : path32.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
24670
+ path33.join(dir === undefined ? UNKNOWN_DIR : path33.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
24377
24671
  ] : []);
24378
24672
  } catch {}
24379
24673
  const lists = [
@@ -24418,17 +24712,17 @@ var judgeChecksLine = (cwd) => {
24418
24712
 
24419
24713
  // packages/workit-core/src/hooks/standing.ts
24420
24714
  var readPlans = (store) => {
24421
- const dir = path33.join(store, "fanouts");
24715
+ const dir = path34.join(store, "fanouts");
24422
24716
  let names;
24423
24717
  try {
24424
- names = fs22.readdirSync(dir).filter((name) => name.endsWith(".json"));
24718
+ names = fs23.readdirSync(dir).filter((name) => name.endsWith(".json"));
24425
24719
  } catch {
24426
24720
  return [];
24427
24721
  }
24428
24722
  const plans = [];
24429
24723
  for (const name of names) {
24430
24724
  try {
24431
- const raw = JSON.parse(fs22.readFileSync(path33.join(dir, name), "utf8"));
24725
+ const raw = JSON.parse(fs23.readFileSync(path34.join(dir, name), "utf8"));
24432
24726
  if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
24433
24727
  continue;
24434
24728
  const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
@@ -24637,13 +24931,13 @@ var cdWorkitSplit = (command) => {
24637
24931
  };
24638
24932
 
24639
24933
  // packages/workit-core/src/hooks/spawn-gate.ts
24640
- import fs23 from "node:fs";
24641
- import path35 from "node:path";
24934
+ import fs24 from "node:fs";
24935
+ import path36 from "node:path";
24642
24936
 
24643
24937
  // packages/workit-core/src/hooks/model-limit.ts
24644
24938
  import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync4, readSync, statSync as statSync5 } from "node:fs";
24645
- import os10 from "node:os";
24646
- import path34 from "node:path";
24939
+ import os11 from "node:os";
24940
+ import path35 from "node:path";
24647
24941
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
24648
24942
  var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
24649
24943
  var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
@@ -24841,17 +25135,17 @@ var firstPrompt = (file) => {
24841
25135
  var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
24842
25136
  var listDir = (dir) => {
24843
25137
  try {
24844
- return readdirSync4(dir).map((name) => path34.join(dir, name));
25138
+ return readdirSync4(dir).map((name) => path35.join(dir, name));
24845
25139
  } catch {
24846
25140
  return [];
24847
25141
  }
24848
25142
  };
24849
25143
  var SCAN_MS = 30 * 60000;
24850
25144
  var scanClaudeTranscripts = (cwd, env, now = new Date) => {
24851
- const projects = path34.join(env.CLAUDE_CONFIG_DIR || path34.join(env.HOME || os10.homedir(), ".claude"), "projects");
24852
- const project = path34.join(projects, claudeProjectSlug(cwd));
25145
+ const projects = path35.join(env.CLAUDE_CONFIG_DIR || path35.join(env.HOME || os11.homedir(), ".claude"), "projects");
25146
+ const project = path35.join(projects, claudeProjectSlug(cwd));
24853
25147
  const notes = [];
24854
- const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path34.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
25148
+ 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 })));
24855
25149
  for (const { file, worker } of files)
24856
25150
  try {
24857
25151
  const stat = statSync5(file);
@@ -24866,7 +25160,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
24866
25160
  if (!seen)
24867
25161
  continue;
24868
25162
  notes.push(worker ? redispatchNote(seen, {
24869
- label: `worker ${path34.basename(file, ".jsonl")}`,
25163
+ label: `worker ${path35.basename(file, ".jsonl")}`,
24870
25164
  prompt: firstPrompt(file)
24871
25165
  }, 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.`);
24872
25166
  } catch {}
@@ -24965,13 +25259,13 @@ var agentModelDecision = (cwd, tool, options = {}) => {
24965
25259
  var MADE_WORKTREE = /^WORKTREE:[ \t]*(?!not made yet)\S(?![^\n]*not made yet)/mu;
24966
25260
  var namesMade = (word) => {
24967
25261
  try {
24968
- const stat = fs23.statSync(word);
25262
+ const stat = fs24.statSync(word);
24969
25263
  if (stat.isFile())
24970
- return stat.size < 1e6 && MADE_WORKTREE.test(fs23.readFileSync(word, "utf8"));
24971
- const dotGit = path35.join(word, ".git");
24972
- const link = fs23.statSync(dotGit);
24973
- const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs23.readFileSync(dotGit, "utf8"));
24974
- return !!admin && fs23.existsSync(path35.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
25264
+ return stat.size < 1e6 && MADE_WORKTREE.test(fs24.readFileSync(word, "utf8"));
25265
+ const dotGit = path36.join(word, ".git");
25266
+ const link = fs24.statSync(dotGit);
25267
+ const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs24.readFileSync(dotGit, "utf8"));
25268
+ return !!admin && fs24.existsSync(path36.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
24975
25269
  } catch {
24976
25270
  return false;
24977
25271
  }
@@ -25017,8 +25311,8 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
25017
25311
 
25018
25312
  // packages/workit-core/src/hooks/teardown.ts
25019
25313
  import { spawn } from "node:child_process";
25020
- import fs24 from "node:fs";
25021
- import path36 from "node:path";
25314
+ import fs25 from "node:fs";
25315
+ import path37 from "node:path";
25022
25316
  var REAP_INTERVAL_MS = 10 * 60000;
25023
25317
  var LOG_MAX_BYTES = 1 << 20;
25024
25318
  var ENDS = {
@@ -25029,9 +25323,9 @@ var ENDS = {
25029
25323
  };
25030
25324
  var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
25031
25325
  var HOST_SESSION_VARS = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
25032
- var teardownDir = (env) => path36.join(stateDir3(env), "procs");
25033
- var teardownLog = (env) => path36.join(teardownDir(env), "teardown.log");
25034
- var reapStamp = (env) => path36.join(teardownDir(env), "reap-at-start.stamp");
25326
+ var teardownDir = (env) => path37.join(stateDir3(env), "procs");
25327
+ var teardownLog = (env) => path37.join(teardownDir(env), "teardown.log");
25328
+ var reapStamp = (env) => path37.join(teardownDir(env), "reap-at-start.stamp");
25035
25329
  function spawnDetached(request) {
25036
25330
  try {
25037
25331
  const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
@@ -25058,13 +25352,13 @@ var teardownDeps = {
25058
25352
  var openLog = (env, args) => {
25059
25353
  try {
25060
25354
  const file = teardownLog(env);
25061
- fs24.mkdirSync(path36.dirname(file), { recursive: true });
25355
+ fs25.mkdirSync(path37.dirname(file), { recursive: true });
25062
25356
  let size = 0;
25063
25357
  try {
25064
- size = fs24.statSync(file).size;
25358
+ size = fs25.statSync(file).size;
25065
25359
  } catch {}
25066
- const fd = fs24.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
25067
- fs24.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
25360
+ const fd = fs25.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
25361
+ fs25.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
25068
25362
  `);
25069
25363
  return fd;
25070
25364
  } catch {
@@ -25076,7 +25370,7 @@ function runCli(args, env) {
25076
25370
  try {
25077
25371
  const cli = locateWorkitCli2({ env });
25078
25372
  const cwd = teardownDir(env);
25079
- fs24.mkdirSync(cwd, { recursive: true });
25373
+ fs25.mkdirSync(cwd, { recursive: true });
25080
25374
  log = openLog(env, args);
25081
25375
  const started = teardownDeps.spawn({
25082
25376
  command: cli.command,
@@ -25086,7 +25380,7 @@ function runCli(args, env) {
25086
25380
  log
25087
25381
  });
25088
25382
  if (!started && log !== null)
25089
- fs24.writeSync(log, ` not started
25383
+ fs25.writeSync(log, ` not started
25090
25384
  `);
25091
25385
  return started;
25092
25386
  } catch {
@@ -25094,7 +25388,7 @@ function runCli(args, env) {
25094
25388
  } finally {
25095
25389
  if (log !== null)
25096
25390
  try {
25097
- fs24.closeSync(log);
25391
+ fs25.closeSync(log);
25098
25392
  } catch {}
25099
25393
  }
25100
25394
  }
@@ -25113,24 +25407,24 @@ function endSession(end, env = process.env) {
25113
25407
  var claim2 = (file, now) => {
25114
25408
  for (let attempt = 0;attempt < 2; attempt += 1)
25115
25409
  try {
25116
- fs24.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
25410
+ fs25.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
25117
25411
  return true;
25118
25412
  } catch (error) {
25119
25413
  if (error.code !== "EEXIST")
25120
25414
  return false;
25121
25415
  let held = Number.NaN;
25122
25416
  try {
25123
- held = Number(fs24.readFileSync(file, "utf8"));
25417
+ held = Number(fs25.readFileSync(file, "utf8"));
25124
25418
  } catch {}
25125
25419
  if (now - held < REAP_INTERVAL_MS)
25126
25420
  return false;
25127
- fs24.rmSync(file, { force: true });
25421
+ fs25.rmSync(file, { force: true });
25128
25422
  }
25129
25423
  return false;
25130
25424
  };
25131
25425
  var fresh = (stamp, now) => {
25132
25426
  try {
25133
- const last = Number(fs24.readFileSync(stamp, "utf8"));
25427
+ const last = Number(fs25.readFileSync(stamp, "utf8"));
25134
25428
  return now - last < REAP_INTERVAL_MS && last <= now;
25135
25429
  } catch {
25136
25430
  return false;
@@ -25143,7 +25437,7 @@ function reapAtStart(_cwd, env = process.env) {
25143
25437
  try {
25144
25438
  if (fresh(stamp, now))
25145
25439
  return false;
25146
- fs24.mkdirSync(path36.dirname(stamp), { recursive: true });
25440
+ fs25.mkdirSync(path37.dirname(stamp), { recursive: true });
25147
25441
  if (!claim2(lock, now))
25148
25442
  return false;
25149
25443
  } catch {
@@ -25156,12 +25450,12 @@ function reapAtStart(_cwd, env = process.env) {
25156
25450
  started = runCli(["stop", "--orphans", "--reason", "session-start"], env);
25157
25451
  if (started) {
25158
25452
  const temp = `${stamp}.${process.pid}`;
25159
- fs24.writeFileSync(temp, String(now), { mode: 384 });
25160
- fs24.renameSync(temp, stamp);
25453
+ fs25.writeFileSync(temp, String(now), { mode: 384 });
25454
+ fs25.renameSync(temp, stamp);
25161
25455
  }
25162
25456
  } catch {} finally {
25163
25457
  try {
25164
- fs24.rmSync(lock, { force: true });
25458
+ fs25.rmSync(lock, { force: true });
25165
25459
  } catch {}
25166
25460
  }
25167
25461
  return started;
@@ -26163,7 +26457,7 @@ var dispatchHook = (adapter, raw, env = process.env) => {
26163
26457
  };
26164
26458
  // packages/workit-core/src/hooks/deadline.ts
26165
26459
  import { appendFileSync, mkdirSync as mkdirSync4 } from "node:fs";
26166
- import path37 from "node:path";
26460
+ import path38 from "node:path";
26167
26461
  var HOOK_SKIP_TEXT = "workit context skipped: host under load";
26168
26462
  var HOOK_DEADLINE_MS = 8000;
26169
26463
  var HOST_DEADLINES = {
@@ -26181,7 +26475,7 @@ var hookDeadlineMs = (env, host = "", native) => {
26181
26475
  const row = HOST_DEADLINES[host];
26182
26476
  return override(env) ?? (row ? native === undefined ? Math.min(...Object.values(row)) : row[native] ?? row[""] : HOOK_DEADLINE_MS);
26183
26477
  };
26184
- var skipsFile = (stateDir) => path37.join(stateDir, HOOK_SKIPS_FILE);
26478
+ var skipsFile = (stateDir) => path38.join(stateDir, HOOK_SKIPS_FILE);
26185
26479
  var recordHookSkip = (skip, stateDir = resolveStateDir()) => {
26186
26480
  try {
26187
26481
  mkdirSync4(stateDir, { recursive: true });