@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.
@@ -6621,14 +6621,14 @@ var require_dist = __commonJS(function(exports, module) {
6621
6621
  });
6622
6622
 
6623
6623
  // packages/workit-codex/scripts/launch-mcp.ts
6624
- import { existsSync as existsSync18, realpathSync as realpathSync12, statSync as statSync6 } from "node:fs";
6625
- import path38 from "node:path";
6624
+ import { existsSync as existsSync19, realpathSync as realpathSync13, statSync as statSync6 } from "node:fs";
6625
+ import path39 from "node:path";
6626
6626
  import { fileURLToPath as fileURLToPath3 } from "node:url";
6627
6627
 
6628
6628
  // packages/workit-core/src/core.ts
6629
6629
  import { spawnSync as spawnSync20 } from "node:child_process";
6630
- import { existsSync as existsSync13, realpathSync as realpathSync9 } from "node:fs";
6631
- import path31 from "node:path";
6630
+ import { existsSync as existsSync14, realpathSync as realpathSync10 } from "node:fs";
6631
+ import path32 from "node:path";
6632
6632
 
6633
6633
  // packages/workit-core/src/core/task-contract.ts
6634
6634
  import { createHash, randomUUID } from "node:crypto";
@@ -14033,23 +14033,25 @@ function explainInvalidOperation(family, request) {
14033
14033
  return parsed.success ? null : invalidOperation(family, request, parsed.error);
14034
14034
  }
14035
14035
  // packages/workit-core/src/core/task-store.ts
14036
- import { createHash as createHash8 } from "node:crypto";
14037
- import * as fs13 from "node:fs";
14038
- import path16 from "node:path";
14036
+ import { createHash as createHash9 } from "node:crypto";
14037
+ import * as fs14 from "node:fs";
14038
+ import path17 from "node:path";
14039
14039
 
14040
14040
  // packages/workit-core/src/host-session.ts
14041
- import { createHash as createHash6, randomBytes, timingSafeEqual } from "node:crypto";
14042
- import fs6 from "node:fs";
14043
- import path10 from "node:path";
14041
+ import { createHash as createHash7, randomBytes, timingSafeEqual } from "node:crypto";
14042
+ import fs7 from "node:fs";
14043
+ import path11 from "node:path";
14044
14044
 
14045
14045
  // packages/workit-core/src/core/branch-policy.ts
14046
14046
  import { spawnSync } from "node:child_process";
14047
14047
 
14048
14048
  // packages/workit-core/src/core/config.ts
14049
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
14049
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, writeFileSync as writeFileSync2 } from "node:fs";
14050
14050
  import path2 from "node:path";
14051
14051
 
14052
14052
  // packages/workit-core/src/core/workit-paths.mjs
14053
+ import { createHash as createHash2 } from "node:crypto";
14054
+ import { existsSync, lstatSync, mkdirSync, realpathSync, renameSync, writeFileSync } from "node:fs";
14053
14055
  import os from "node:os";
14054
14056
  import path from "node:path";
14055
14057
  var WORKIT_DIR_OVERRIDES = {
@@ -14101,6 +14103,17 @@ var workitDir = (kind, env = process.env, platform = process.platform) => {
14101
14103
  var configDir = (env, platform) => workitDir("config", env, platform);
14102
14104
  var stateDir = (env, platform) => workitDir("state", env, platform);
14103
14105
  var dataDir = (env, platform) => workitDir("data", env, platform);
14106
+ var folderSlug = (dir, platform = process.platform) => {
14107
+ let canonical = dir;
14108
+ try {
14109
+ canonical = realpathSync.native(dir);
14110
+ } catch {}
14111
+ if (platform === "win32")
14112
+ canonical = canonical.toLowerCase();
14113
+ const base = path.basename(canonical).replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40) || "root";
14114
+ return `${base}-${createHash2("sha256").update(canonical).digest("hex").slice(0, 12)}`;
14115
+ };
14116
+ var folderStoreDir = (dir, env, platform) => path.join(stateDir(env, platform), "folders", folderSlug(dir, platform));
14104
14117
 
14105
14118
  // packages/workit-core/src/core/config.ts
14106
14119
  var UPDATES_MODES = ["prompt", "auto", "off"];
@@ -14362,18 +14375,18 @@ var gitContext = (workspaceRoot, paths = []) => {
14362
14375
 
14363
14376
  // packages/workit-core/src/core/workspaces.ts
14364
14377
  import { spawnSync as spawnSync6 } from "node:child_process";
14365
- import { createHash as createHash3 } from "node:crypto";
14366
- import { existsSync as existsSync3, lstatSync as lstatSync2, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
14378
+ import { createHash as createHash4 } from "node:crypto";
14379
+ import { existsSync as existsSync4, lstatSync as lstatSync3, readFileSync as readFileSync4, realpathSync as realpathSync4 } from "node:fs";
14367
14380
  import path7 from "node:path";
14368
14381
 
14369
14382
  // packages/workit-core/src/core/remotes.ts
14370
- import { lstatSync, readFileSync as readFileSync3, realpathSync as realpathSync2, statSync } from "node:fs";
14383
+ import { lstatSync as lstatSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync } from "node:fs";
14371
14384
  import { spawnSync as spawnSync5 } from "node:child_process";
14372
14385
  import path6 from "node:path";
14373
14386
 
14374
14387
  // packages/workit-core/src/git/rev.ts
14375
14388
  import { spawnSync as spawnSync3 } from "node:child_process";
14376
- import { createHash as createHash2 } from "node:crypto";
14389
+ import { createHash as createHash3 } from "node:crypto";
14377
14390
  import fs3 from "node:fs";
14378
14391
  import os2 from "node:os";
14379
14392
  import path5 from "node:path";
@@ -14829,7 +14842,7 @@ function worktreeTree(cwd, options = {}) {
14829
14842
  if (!tree)
14830
14843
  return null;
14831
14844
  const base = line(git(top, ["rev-parse", "--verify", "-q", "HEAD^{tree}"])) ?? emptyTree(top);
14832
- const key = skipped.length ? `sha256:${createHash2("sha256").update(JSON.stringify({ tree, skipped })).digest("hex")}` : tree;
14845
+ const key = skipped.length ? `sha256:${createHash3("sha256").update(JSON.stringify({ tree, skipped })).digest("hex")}` : tree;
14833
14846
  return { tree, key, dirty: tree !== base || skipped.length > 0, skipped };
14834
14847
  } finally {
14835
14848
  fs3.rmSync(scratch, { recursive: true, force: true });
@@ -14852,7 +14865,7 @@ function worktreeSignal(cwd, options = {}) {
14852
14865
  });
14853
14866
  if (!status.ok)
14854
14867
  return null;
14855
- const hash = createHash2("sha256");
14868
+ const hash = createHash3("sha256");
14856
14869
  hash.update(`${headSha(top) ?? "unborn"}\x00`);
14857
14870
  for (const entry of status.stdout.split("\x00")) {
14858
14871
  if (entry.length < 4)
@@ -15193,7 +15206,7 @@ function resolveSshHost(alias, sshConfig) {
15193
15206
 
15194
15207
  // packages/workit-core/src/core/account-home.ts
15195
15208
  import { spawnSync as spawnSync4 } from "node:child_process";
15196
- import { existsSync as existsSync2, readFileSync as readFileSync2, readlinkSync, realpathSync } from "node:fs";
15209
+ import { existsSync as existsSync3, readFileSync as readFileSync2, readlinkSync, realpathSync as realpathSync2 } from "node:fs";
15197
15210
  import os3 from "node:os";
15198
15211
  var WINDOWS = "C:\\Windows";
15199
15212
  var SYSTEM32 = `${WINDOWS}\\System32\\`;
@@ -15285,7 +15298,7 @@ var canonical2 = (real) => {
15285
15298
  };
15286
15299
  var isRepoDir = (dir) => ["HEAD", "objects", "refs"].every((name) => {
15287
15300
  try {
15288
- lstatSync(`${dir}/${name}`);
15301
+ lstatSync2(`${dir}/${name}`);
15289
15302
  return true;
15290
15303
  } catch {
15291
15304
  return false;
@@ -15294,7 +15307,7 @@ var isRepoDir = (dir) => ["HEAD", "objects", "refs"].every((name) => {
15294
15307
  var gitDirAt = (at, depth = 0) => {
15295
15308
  let real;
15296
15309
  try {
15297
- real = realpathSync2.native(at);
15310
+ real = realpathSync3.native(at);
15298
15311
  } catch {
15299
15312
  return null;
15300
15313
  }
@@ -15313,7 +15326,7 @@ var gitDirAt = (at, depth = 0) => {
15313
15326
  common = readFileSync3(`${real}/commondir`, "utf8").trim();
15314
15327
  } catch {}
15315
15328
  if (common !== undefined) {
15316
- lstatSync(`${real}/HEAD`);
15329
+ lstatSync2(`${real}/HEAD`);
15317
15330
  return gitDirAt(path6.isAbsolute(common) ? common : `${real}/${common}`, depth + 1);
15318
15331
  }
15319
15332
  if (!isRepoDir(real))
@@ -15322,11 +15335,11 @@ var gitDirAt = (at, depth = 0) => {
15322
15335
  for (const name of ["refs", "objects", "config", "packed-refs"]) {
15323
15336
  const item = `${real}/${name}`;
15324
15337
  try {
15325
- lstatSync(item);
15338
+ lstatSync2(item);
15326
15339
  } catch {
15327
15340
  continue;
15328
15341
  }
15329
- const resolved = realpathSync2.native(item);
15342
+ const resolved = realpathSync3.native(item);
15330
15343
  const rel = path6.relative(real, resolved);
15331
15344
  if (rel && !rel.startsWith("..") && !path6.isAbsolute(rel))
15332
15345
  continue;
@@ -15611,7 +15624,7 @@ var workspacesFileSchema = object({
15611
15624
  names.add(workspace.name);
15612
15625
  }
15613
15626
  });
15614
- var workspacesRevision = (contents) => createHash3("sha256").update(contents ?? "<missing>").digest("hex");
15627
+ var workspacesRevision = (contents) => createHash4("sha256").update(contents ?? "<missing>").digest("hex");
15615
15628
  var validateWorkspacesDocument = (parsed, file) => {
15616
15629
  if (!isConfigObject(parsed)) {
15617
15630
  return {
@@ -15762,8 +15775,8 @@ var probeCheckout = (cwd) => {
15762
15775
  if (cached !== undefined)
15763
15776
  return cached;
15764
15777
  let dir = path7.resolve(cwd);
15765
- while (!existsSync3(path7.join(dir, ".git"))) {
15766
- if (["HEAD", "objects", "refs"].every((name) => existsSync3(path7.join(dir, name)))) {
15778
+ while (!existsSync4(path7.join(dir, ".git"))) {
15779
+ if (["HEAD", "objects", "refs"].every((name) => existsSync4(path7.join(dir, name)))) {
15767
15780
  const real = realpathOf(dir);
15768
15781
  const owner = ownInternals(real) === true ? gitDirOwner(real) : null;
15769
15782
  if (owner === null)
@@ -15830,7 +15843,7 @@ var probeCheckout = (cwd) => {
15830
15843
  };
15831
15844
  var ownGitDir = (dotGit, real) => {
15832
15845
  try {
15833
- return lstatSync2(dotGit).isDirectory() && realpathOf(dotGit) === real;
15846
+ return lstatSync3(dotGit).isDirectory() && realpathOf(dotGit) === real;
15834
15847
  } catch {
15835
15848
  return false;
15836
15849
  }
@@ -15841,13 +15854,13 @@ var ownInternals = (real) => {
15841
15854
  for (const name of INTERNALS) {
15842
15855
  const at = path7.join(real, name);
15843
15856
  try {
15844
- lstatSync2(at);
15857
+ lstatSync3(at);
15845
15858
  } catch {
15846
15859
  continue;
15847
15860
  }
15848
15861
  let resolved;
15849
15862
  try {
15850
- resolved = (realpathSync3.native ?? realpathSync3)(at);
15863
+ resolved = (realpathSync4.native ?? realpathSync4)(at);
15851
15864
  } catch {
15852
15865
  return false;
15853
15866
  }
@@ -15905,7 +15918,7 @@ var matchingEntries = (cwd, entries) => {
15905
15918
  return main ? match(main) : direct;
15906
15919
  };
15907
15920
  var realpathOf = (p) => {
15908
- const real = realpathSync3.native ?? realpathSync3;
15921
+ const real = realpathSync4.native ?? realpathSync4;
15909
15922
  try {
15910
15923
  return real(p);
15911
15924
  } catch {
@@ -16098,7 +16111,7 @@ import path8 from "node:path";
16098
16111
  import { spawnSync as spawnSync8 } from "node:child_process";
16099
16112
 
16100
16113
  // packages/workit-core/src/core/release-tracks.ts
16101
- import { createHash as createHash4 } from "node:crypto";
16114
+ import { createHash as createHash5 } from "node:crypto";
16102
16115
  import { spawnSync as spawnSync7 } from "node:child_process";
16103
16116
  var KNOWN_FIELDS = new Set([
16104
16117
  "strategy",
@@ -16468,7 +16481,7 @@ function resolveTrackFor(cwd, options) {
16468
16481
  ]) ?? "",
16469
16482
  git2(cwd, ["config", "--get", recordedBaseKey(branch)]) ?? ""
16470
16483
  ] : [];
16471
- key = createHash4("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
16484
+ key = createHash5("sha256").update(JSON.stringify({ cwd, input, refs, head, own })).digest("hex");
16472
16485
  const hit = memo2.get(key);
16473
16486
  if (hit)
16474
16487
  return hit;
@@ -16862,9 +16875,318 @@ var redactSecrets = (value) => applyPatterns(value);
16862
16875
 
16863
16876
  // packages/workit-core/src/store/paths.ts
16864
16877
  import { spawnSync as spawnSync9 } from "node:child_process";
16865
- import { createHash as createHash5 } from "node:crypto";
16878
+ import { createHash as createHash6 } from "node:crypto";
16879
+ import fs6 from "node:fs";
16880
+ import path10 from "node:path";
16881
+
16882
+ // packages/workit-core/src/store/folder-store.ts
16866
16883
  import fs5 from "node:fs";
16884
+ import os5 from "node:os";
16867
16885
  import path9 from "node:path";
16886
+ var FOLDER_CONFIG = new Set(["checks.json", "risk-paths"]);
16887
+ var MOVED_POINTER = "MOVED-TO-STATE.txt";
16888
+ var V2_LEFTOVERS = new Set(["recovery", "index.json"]);
16889
+ var isV2TaskStub = (rel) => /^tasks[/\\][^/\\]+\.json$/u.test(rel);
16890
+ var MARKER = "workspace.json";
16891
+ var v2Workspace = (workit) => {
16892
+ let bytes;
16893
+ try {
16894
+ bytes = fs5.readFileSync(path9.join(workit, MARKER), "utf8");
16895
+ } catch {
16896
+ return null;
16897
+ }
16898
+ try {
16899
+ const value = JSON.parse(bytes);
16900
+ return value?.store?.format !== "workit-store";
16901
+ } catch {
16902
+ return true;
16903
+ }
16904
+ };
16905
+ var generatedIgnore = (file) => {
16906
+ try {
16907
+ return /^\*\n(!risk-paths\n)?$/u.test(fs5.readFileSync(file, "utf8"));
16908
+ } catch {
16909
+ return false;
16910
+ }
16911
+ };
16912
+ var exists = (file) => {
16913
+ try {
16914
+ fs5.lstatSync(file);
16915
+ return true;
16916
+ } catch {
16917
+ return false;
16918
+ }
16919
+ };
16920
+ var isDir = (file) => {
16921
+ try {
16922
+ return fs5.lstatSync(file).isDirectory();
16923
+ } catch {
16924
+ return false;
16925
+ }
16926
+ };
16927
+ var onlyStubs = (tasks) => {
16928
+ try {
16929
+ return fs5.readdirSync(tasks).every((entry) => isV2TaskStub(`tasks/${entry}`));
16930
+ } catch {
16931
+ return false;
16932
+ }
16933
+ };
16934
+ var strayEntries = (workit) => {
16935
+ if (!isDir(workit))
16936
+ return [];
16937
+ let names;
16938
+ try {
16939
+ names = fs5.readdirSync(workit);
16940
+ } catch {
16941
+ return [];
16942
+ }
16943
+ return names.filter((name) => !FOLDER_CONFIG.has(name) && !V2_LEFTOVERS.has(name) && name !== MOVED_POINTER && name !== MARKER && !(name === ".gitignore" && generatedIgnore(path9.join(workit, name))) && !(name === "tasks" && onlyStubs(path9.join(workit, name))));
16944
+ };
16945
+ var folderStoreIo = {
16946
+ rename: (from, to) => fs5.renameSync(from, to),
16947
+ copyFile: (from, to) => fs5.copyFileSync(from, to, fs5.constants.COPYFILE_EXCL),
16948
+ judgedStale: () => {}
16949
+ };
16950
+ var tempSeq = 0;
16951
+ var tempBeside = (file) => path9.join(path9.dirname(file), `.${path9.basename(file)}.workit-move-${process.pid}-${tempSeq += 1}`);
16952
+ var copyInto = (from, to) => {
16953
+ const stat = fs5.lstatSync(from);
16954
+ if (stat.isDirectory()) {
16955
+ fs5.mkdirSync(to, { recursive: true });
16956
+ for (const name of fs5.readdirSync(from))
16957
+ copyInto(path9.join(from, name), path9.join(to, name));
16958
+ return;
16959
+ }
16960
+ if (exists(to))
16961
+ throw new Error(`${to} appeared during the move`);
16962
+ const temp = tempBeside(to);
16963
+ try {
16964
+ if (stat.isSymbolicLink())
16965
+ fs5.symlinkSync(fs5.readlinkSync(from), temp);
16966
+ else
16967
+ folderStoreIo.copyFile(from, temp);
16968
+ folderStoreIo.rename(temp, to);
16969
+ } catch (error) {
16970
+ fs5.rmSync(temp, { force: true });
16971
+ throw error;
16972
+ }
16973
+ };
16974
+ var sameFile = (left, right) => {
16975
+ try {
16976
+ const [a, b] = [fs5.lstatSync(left), fs5.lstatSync(right)];
16977
+ if (!a.isFile() || !b.isFile() || a.size !== b.size)
16978
+ return false;
16979
+ return fs5.readFileSync(left).equals(fs5.readFileSync(right));
16980
+ } catch {
16981
+ return false;
16982
+ }
16983
+ };
16984
+ var merge2 = (from, to, rel, moved) => {
16985
+ if (isV2TaskStub(rel))
16986
+ return [];
16987
+ if (!exists(to)) {
16988
+ try {
16989
+ folderStoreIo.rename(from, to);
16990
+ } catch {
16991
+ try {
16992
+ copyInto(from, to);
16993
+ fs5.rmSync(from, { recursive: true, force: true });
16994
+ } catch {
16995
+ return exists(from) ? [rel] : [];
16996
+ }
16997
+ }
16998
+ moved.push(rel);
16999
+ return [];
17000
+ }
17001
+ if (sameFile(from, to)) {
17002
+ fs5.rmSync(from, { force: true });
17003
+ moved.push(rel);
17004
+ return [];
17005
+ }
17006
+ if (!isDir(from) || !isDir(to))
17007
+ return [rel];
17008
+ const kept = fs5.readdirSync(from).flatMap((name) => merge2(path9.join(from, name), path9.join(to, name), `${rel}/${name}`, moved));
17009
+ try {
17010
+ if (fs5.readdirSync(from).length === 0)
17011
+ fs5.rmdirSync(from);
17012
+ } catch {}
17013
+ return kept;
17014
+ };
17015
+ var LOCK_STALE_MS = 1e4;
17016
+ var LOCK_WAIT_MS = 250;
17017
+ var pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
17018
+ var readLock = (lock) => fs5.readFileSync(lock, "utf8");
17019
+ var staleLock = (lock) => {
17020
+ try {
17021
+ const { mtimeMs } = fs5.statSync(lock);
17022
+ const text = readLock(lock);
17023
+ if (Date.now() - mtimeMs > LOCK_STALE_MS)
17024
+ return { text, mtimeMs };
17025
+ const pid = Number(text.trim().split(/\s+/u)[0]);
17026
+ if (!Number.isInteger(pid) || pid <= 0)
17027
+ return null;
17028
+ try {
17029
+ process.kill(pid, 0);
17030
+ return null;
17031
+ } catch (error) {
17032
+ return error.code === "ESRCH" ? { text, mtimeMs } : null;
17033
+ }
17034
+ } catch {
17035
+ return null;
17036
+ }
17037
+ };
17038
+ var removeStaleLock = (lock, judged) => {
17039
+ const aside = `${lock}.stale-${process.pid}-${crypto.randomUUID()}`;
17040
+ try {
17041
+ fs5.renameSync(lock, aside);
17042
+ } catch {
17043
+ return false;
17044
+ }
17045
+ let same = false;
17046
+ try {
17047
+ same = fs5.statSync(aside).mtimeMs === judged.mtimeMs && readLock(aside) === judged.text;
17048
+ } catch {}
17049
+ if (!same)
17050
+ try {
17051
+ fs5.linkSync(aside, lock);
17052
+ } catch {}
17053
+ fs5.rmSync(aside, { force: true });
17054
+ return same;
17055
+ };
17056
+ var takeMoveLock = (target) => {
17057
+ const lock = `${target}.lock`;
17058
+ const mine = `${process.pid} ${crypto.randomUUID()}
17059
+ `;
17060
+ const deadline = Date.now() + LOCK_WAIT_MS;
17061
+ for (;; ) {
17062
+ try {
17063
+ const fd = fs5.openSync(lock, "wx", 384);
17064
+ fs5.writeSync(fd, mine);
17065
+ fs5.closeSync(fd);
17066
+ return () => {
17067
+ try {
17068
+ if (readLock(lock) === mine)
17069
+ fs5.rmSync(lock, { force: true });
17070
+ } catch {}
17071
+ };
17072
+ } catch (error) {
17073
+ if (error.code !== "EEXIST")
17074
+ return null;
17075
+ }
17076
+ const stale = staleLock(lock);
17077
+ if (stale) {
17078
+ folderStoreIo.judgedStale();
17079
+ if (removeStaleLock(lock, stale))
17080
+ continue;
17081
+ }
17082
+ if (Date.now() >= deadline)
17083
+ return null;
17084
+ pause(25);
17085
+ }
17086
+ };
17087
+ var canonical3 = (dir) => {
17088
+ try {
17089
+ return fs5.realpathSync.native(dir);
17090
+ } catch {
17091
+ return path9.resolve(dir);
17092
+ }
17093
+ };
17094
+ var below = (parent, child) => {
17095
+ const rel = path9.relative(parent, child);
17096
+ return rel !== "" && !rel.startsWith("..") && !path9.isAbsolute(rel);
17097
+ };
17098
+ var TEST_RUN_REFUSALS = "folder-store-refusals.log";
17099
+ var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os5.tmpdir()) => {
17100
+ if (env.WORKIT_TEST_RUN === undefined || !hasStray)
17101
+ return null;
17102
+ const real = canonical3(folder);
17103
+ const tmp = canonical3(tempDir);
17104
+ if (below(tmp, real))
17105
+ return null;
17106
+ return `workit test run (WORKIT_TEST_RUN): refusing to move ${path9.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)`;
17107
+ };
17108
+ function migrateFolderStore(folder, target, note = (line) => process.stderr.write(`${line}
17109
+ `)) {
17110
+ const workit = path9.join(folder, ".workit");
17111
+ const names = strayEntries(workit);
17112
+ const refusal = testRunFolderRefusal(folder, names.length > 0);
17113
+ if (refusal) {
17114
+ const run = process.env.WORKIT_TEST_RUN ?? "";
17115
+ if (path9.isAbsolute(run))
17116
+ try {
17117
+ fs5.appendFileSync(path9.join(run, TEST_RUN_REFUSALS), `${refusal}
17118
+ `);
17119
+ } catch {}
17120
+ throw new Error(refusal);
17121
+ }
17122
+ if (names.length === 0 || v2Workspace(workit) === true)
17123
+ return null;
17124
+ try {
17125
+ fs5.mkdirSync(path9.dirname(target), { recursive: true });
17126
+ } catch {
17127
+ return null;
17128
+ }
17129
+ const release = takeMoveLock(target);
17130
+ if (!release)
17131
+ return null;
17132
+ try {
17133
+ return moveLocked(workit, target, note);
17134
+ } finally {
17135
+ release();
17136
+ }
17137
+ }
17138
+ function moveLocked(workit, target, note) {
17139
+ const names = strayEntries(workit);
17140
+ if (names.length === 0 || v2Workspace(workit) === true)
17141
+ return null;
17142
+ try {
17143
+ fs5.mkdirSync(target, { recursive: true });
17144
+ } catch {
17145
+ return null;
17146
+ }
17147
+ const result = { from: workit, to: target, moved: [], kept: [] };
17148
+ for (const name of names) {
17149
+ result.kept.push(...merge2(path9.join(workit, name), path9.join(target, name), name, result.moved));
17150
+ }
17151
+ const left = (() => {
17152
+ try {
17153
+ return fs5.readdirSync(workit);
17154
+ } catch {
17155
+ return [];
17156
+ }
17157
+ })();
17158
+ const v2Left = left.some((name) => V2_LEFTOVERS.has(name) || name === "tasks" && isDir(path9.join(workit, name)));
17159
+ if (!v2Left && result.kept.length === 0) {
17160
+ fs5.rmSync(path9.join(workit, MARKER), { force: true });
17161
+ if (generatedIgnore(path9.join(workit, ".gitignore")))
17162
+ fs5.rmSync(path9.join(workit, ".gitignore"), { force: true });
17163
+ }
17164
+ const pointer = path9.join(workit, MOVED_POINTER);
17165
+ let wrote = false;
17166
+ if (result.kept.length > 0) {
17167
+ const text = `Workit keeps this folder's state in ${target}.
17168
+ Not moved, because the store there already has them or the move failed: ${result.kept.join(", ")}.
17169
+ Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
17170
+ `;
17171
+ try {
17172
+ if (!exists(pointer) || fs5.readFileSync(pointer, "utf8") !== text) {
17173
+ fs5.writeFileSync(pointer, text);
17174
+ wrote = true;
17175
+ }
17176
+ } catch {}
17177
+ } else {
17178
+ fs5.rmSync(pointer, { force: true });
17179
+ try {
17180
+ if (fs5.readdirSync(workit).length === 0)
17181
+ fs5.rmdirSync(workit);
17182
+ } catch {}
17183
+ }
17184
+ if (result.moved.length > 0 || wrote)
17185
+ 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)`);
17186
+ return result;
17187
+ }
17188
+
17189
+ // packages/workit-core/src/store/paths.ts
16868
17190
  var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
16869
17191
  var gitRun = (cwd, args) => {
16870
17192
  const run = spawnSync9("git", args, {
@@ -16889,10 +17211,10 @@ var gitRun = (cwd, args) => {
16889
17211
  missing: error?.code === "ENOENT"
16890
17212
  };
16891
17213
  };
16892
- var shortHash = (value) => createHash5("sha256").update(value).digest("hex").slice(0, 12);
17214
+ var shortHash = (value) => createHash6("sha256").update(value).digest("hex").slice(0, 12);
16893
17215
  var real = (file) => {
16894
17216
  try {
16895
- return fs5.realpathSync.native(file);
17217
+ return fs6.realpathSync.native(file);
16896
17218
  } catch {
16897
17219
  return file;
16898
17220
  }
@@ -16906,14 +17228,14 @@ var DISCOVERY_ENV = [
16906
17228
  ];
16907
17229
  var isGitDir = (dir) => {
16908
17230
  try {
16909
- return fs5.statSync(path9.join(dir, "HEAD")).isFile() && fs5.statSync(path9.join(dir, "objects")).isDirectory() && fs5.statSync(path9.join(dir, "refs")).isDirectory();
17231
+ return fs6.statSync(path10.join(dir, "HEAD")).isFile() && fs6.statSync(path10.join(dir, "objects")).isDirectory() && fs6.statSync(path10.join(dir, "refs")).isDirectory();
16910
17232
  } catch {
16911
17233
  return false;
16912
17234
  }
16913
17235
  };
16914
17236
  var reftableRefs = (common) => {
16915
17237
  try {
16916
- return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs5.readFileSync(path9.join(common, "config"), "utf8"));
17238
+ return /^\s*refstorage\s*=\s*reftable\s*$/imu.test(fs6.readFileSync(path10.join(common, "config"), "utf8"));
16917
17239
  } catch {
16918
17240
  return false;
16919
17241
  }
@@ -16926,17 +17248,17 @@ function fastGit(root) {
16926
17248
  for (;; ) {
16927
17249
  let stat;
16928
17250
  try {
16929
- stat = fs5.statSync(dir);
17251
+ stat = fs6.statSync(dir);
16930
17252
  } catch {
16931
17253
  return null;
16932
17254
  }
16933
17255
  if (device !== null && stat.dev !== device)
16934
17256
  return { kind: "none" };
16935
17257
  device = stat.dev;
16936
- const dotGit = path9.join(dir, ".git");
17258
+ const dotGit = path10.join(dir, ".git");
16937
17259
  let entry = null;
16938
17260
  try {
16939
- entry = fs5.statSync(dotGit);
17261
+ entry = fs6.statSync(dotGit);
16940
17262
  } catch {}
16941
17263
  let gitDir = null;
16942
17264
  let top = null;
@@ -16947,26 +17269,26 @@ function fastGit(root) {
16947
17269
  else if (entry.isFile()) {
16948
17270
  let text = "";
16949
17271
  try {
16950
- text = fs5.readFileSync(dotGit, "utf8");
17272
+ text = fs6.readFileSync(dotGit, "utf8");
16951
17273
  } catch {
16952
17274
  return null;
16953
17275
  }
16954
17276
  const match = /^gitdir: (.+)$/mu.exec(text);
16955
17277
  if (!match)
16956
17278
  return null;
16957
- gitDir = path9.resolve(dir, match[1].trim());
17279
+ gitDir = path10.resolve(dir, match[1].trim());
16958
17280
  } else
16959
17281
  return null;
16960
- if (!fs5.existsSync(path9.join(gitDir, "HEAD")))
17282
+ if (!fs6.existsSync(path10.join(gitDir, "HEAD")))
16961
17283
  return null;
16962
17284
  } else if (isGitDir(dir))
16963
17285
  gitDir = dir;
16964
17286
  if (gitDir) {
16965
17287
  let common = gitDir;
16966
17288
  try {
16967
- common = path9.resolve(gitDir, fs5.readFileSync(path9.join(gitDir, "commondir"), "utf8").trim());
17289
+ common = path10.resolve(gitDir, fs6.readFileSync(path10.join(gitDir, "commondir"), "utf8").trim());
16968
17290
  } catch {}
16969
- if (!fs5.existsSync(path9.join(common, "objects")))
17291
+ if (!fs6.existsSync(path10.join(common, "objects")))
16970
17292
  return null;
16971
17293
  return {
16972
17294
  kind: "repo",
@@ -16976,28 +17298,33 @@ function fastGit(root) {
16976
17298
  reftable: reftableRefs(common)
16977
17299
  };
16978
17300
  }
16979
- const parent = path9.dirname(dir);
17301
+ const parent = path10.dirname(dir);
16980
17302
  if (parent === dir)
16981
17303
  return { kind: "none" };
16982
17304
  dir = parent;
16983
17305
  }
16984
17306
  }
17307
+ var outsideGit = (root) => {
17308
+ const dir = folderStoreDir(root);
17309
+ migrateFolderStore(root, dir);
17310
+ return { dir, shared: false, top: null };
17311
+ };
16985
17312
  function resolveStore(root) {
16986
- root = path9.resolve(root);
17313
+ root = path10.resolve(root);
16987
17314
  let stat = null;
16988
17315
  try {
16989
- stat = fs5.statSync(root);
17316
+ stat = fs6.statSync(root);
16990
17317
  } catch {}
16991
17318
  if (!stat)
16992
17319
  return new Error(`cannot locate the workit store: ${root} does not exist (removed while workit ran?); nothing is recorded under a missing directory`);
16993
17320
  if (!stat.isDirectory())
16994
- return { dir: path9.join(root, ".workit"), shared: false, top: null };
17321
+ return { dir: path10.join(root, ".workit"), shared: false, top: null };
16995
17322
  const fast = fastGit(root);
16996
17323
  if (fast?.kind === "none")
16997
- return { dir: path9.join(root, ".workit"), shared: false, top: null };
17324
+ return outsideGit(root);
16998
17325
  if (fast?.kind === "repo")
16999
17326
  return {
17000
- dir: path9.join(fast.common, "workit"),
17327
+ dir: path10.join(fast.common, "workit"),
17001
17328
  shared: true,
17002
17329
  top: fast.top,
17003
17330
  git: { gitDir: fast.gitDir, top: fast.top, reftable: fast.reftable }
@@ -17007,20 +17334,20 @@ function resolveStore(root) {
17007
17334
  if (run.ok && common) {
17008
17335
  const top = gitRun(root, ["rev-parse", "--path-format=absolute", "--show-toplevel"]);
17009
17336
  return {
17010
- dir: path9.join(real(path9.resolve(root, common)), "workit"),
17337
+ dir: path10.join(real(path10.resolve(root, common)), "workit"),
17011
17338
  shared: true,
17012
17339
  top: top.ok && top.stdout.trim() ? real(top.stdout.trim()) : null
17013
17340
  };
17014
17341
  }
17015
17342
  if (run.missing || !run.ok && NOT_A_REPO.test(run.stderr))
17016
- return { dir: path9.join(root, ".workit"), shared: false, top: null };
17343
+ return outsideGit(root);
17017
17344
  return new Error(`cannot locate the workit store: git rev-parse failed (${run.stderr.trim().split(`
17018
17345
  `)[0] || "no output"}); fix the repository (git status should work here)`);
17019
17346
  }
17020
17347
  var rebasingBranch = (gitDir) => {
17021
17348
  for (const state of ["rebase-merge", "rebase-apply"]) {
17022
17349
  try {
17023
- const ref = fs5.readFileSync(path9.join(gitDir, state, "head-name"), "utf8").trim();
17350
+ const ref = fs6.readFileSync(path10.join(gitDir, state, "head-name"), "utf8").trim();
17024
17351
  const match = /^refs\/heads\/(.+)$/u.exec(ref);
17025
17352
  if (match)
17026
17353
  return match[1];
@@ -17035,7 +17362,7 @@ function resolveTaskKey(root, location) {
17035
17362
  if (location.git && !location.git.reftable) {
17036
17363
  let head = "";
17037
17364
  try {
17038
- head = fs5.readFileSync(path9.join(location.git.gitDir, "HEAD"), "utf8").trim();
17365
+ head = fs6.readFileSync(path10.join(location.git.gitDir, "HEAD"), "utf8").trim();
17039
17366
  } catch {}
17040
17367
  const ref = /^ref: refs\/heads\/(.+)$/u.exec(head);
17041
17368
  if (ref && ref[1] !== ".invalid")
@@ -17066,10 +17393,10 @@ function resolveTaskKey(root, location) {
17066
17393
  return { key: `detached-${shortHash(real(worktree))}`, kind: "detached", branch: null };
17067
17394
  }
17068
17395
  function checkoutRootOf(root, location) {
17069
- const resolved = path9.resolve(root);
17396
+ const resolved = path10.resolve(root);
17070
17397
  let canonical = resolved;
17071
17398
  try {
17072
- canonical = fs5.realpathSync(resolved);
17399
+ canonical = fs6.realpathSync(resolved);
17073
17400
  } catch {
17074
17401
  return resolved;
17075
17402
  }
@@ -17079,7 +17406,7 @@ function checkoutRootOf(root, location) {
17079
17406
  if (real(canonical) === found.top)
17080
17407
  return canonical;
17081
17408
  try {
17082
- return fs5.realpathSync(found.top);
17409
+ return fs6.realpathSync(found.top);
17083
17410
  } catch {
17084
17411
  return canonical;
17085
17412
  }
@@ -17091,25 +17418,25 @@ function branchRenames(location) {
17091
17418
  const walk = (dir) => {
17092
17419
  let entries;
17093
17420
  try {
17094
- entries = fs5.readdirSync(dir, { withFileTypes: true });
17421
+ entries = fs6.readdirSync(dir, { withFileTypes: true });
17095
17422
  } catch {
17096
17423
  return;
17097
17424
  }
17098
17425
  for (const entry of entries)
17099
17426
  if (entry.isDirectory())
17100
- walk(path9.join(dir, entry.name));
17427
+ walk(path10.join(dir, entry.name));
17101
17428
  else
17102
- files.push(path9.join(dir, entry.name));
17429
+ files.push(path10.join(dir, entry.name));
17103
17430
  };
17104
- walk(path9.join(path9.dirname(location.dir), "logs", "refs", "heads"));
17431
+ walk(path10.join(path10.dirname(location.dir), "logs", "refs", "heads"));
17105
17432
  if (location.git)
17106
- files.push(path9.join(location.git.gitDir, "logs", "HEAD"));
17433
+ files.push(path10.join(location.git.gitDir, "logs", "HEAD"));
17107
17434
  const seen = new Set;
17108
17435
  const renames = [];
17109
17436
  for (const file of files) {
17110
17437
  let text = "";
17111
17438
  try {
17112
- text = fs5.readFileSync(file, "utf8");
17439
+ text = fs6.readFileSync(file, "utf8");
17113
17440
  } catch {
17114
17441
  continue;
17115
17442
  }
@@ -17134,13 +17461,7 @@ function followRenames(key, boundAt, renames) {
17134
17461
  }
17135
17462
  return current;
17136
17463
  }
17137
- var checkoutSlug = (root) => {
17138
- let canonical = real(root);
17139
- if (process.platform === "win32")
17140
- canonical = canonical.toLowerCase();
17141
- const base = path9.basename(canonical).replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40) || "root";
17142
- return `${base}-${shortHash(canonical)}`;
17143
- };
17464
+ var checkoutSlug = (root) => folderSlug(root);
17144
17465
 
17145
17466
  // packages/workit-core/src/host-session.ts
17146
17467
  var HOST_SESSION_VARS = [
@@ -17170,9 +17491,9 @@ function hostSessionFromEnv(env) {
17170
17491
  }
17171
17492
  return inner ? { host: inner.host, session: inner.session } : { host: declared, session: null };
17172
17493
  }
17173
- var hash = (value) => createHash6("sha256").update(value).digest("hex").slice(0, 32);
17174
- var userIssuedRoot = () => path10.join(resolveStateDir(), "issued");
17175
- var userTokenRoot = () => path10.join(resolveStateDir(), "issued-tokens");
17494
+ var hash = (value) => createHash7("sha256").update(value).digest("hex").slice(0, 32);
17495
+ var userIssuedRoot = () => path11.join(resolveStateDir(), "issued");
17496
+ var userTokenRoot = () => path11.join(resolveStateDir(), "issued-tokens");
17176
17497
  function migrateRepoIssued(cwd) {
17177
17498
  if (cwd === undefined)
17178
17499
  return;
@@ -17181,27 +17502,27 @@ function migrateRepoIssued(cwd) {
17181
17502
  const location = resolveStore(cwd);
17182
17503
  if (location instanceof Error)
17183
17504
  return;
17184
- old = path10.join(location.dir, "hooks", "issued");
17185
- if (!fs6.existsSync(old))
17505
+ old = path11.join(location.dir, "hooks", "issued");
17506
+ if (!fs7.existsSync(old))
17186
17507
  return;
17187
17508
  } catch {
17188
17509
  return;
17189
17510
  }
17190
17511
  for (const lead of safeList(old)) {
17191
17512
  try {
17192
- const from = path10.join(old, lead);
17193
- if (!fs6.statSync(from).isDirectory())
17513
+ const from = path11.join(old, lead);
17514
+ if (!fs7.statSync(from).isDirectory())
17194
17515
  continue;
17195
- const to = path10.join(userIssuedRoot(), lead);
17196
- fs6.mkdirSync(to, { recursive: true, mode: 448 });
17197
- for (const id of fs6.readdirSync(from)) {
17516
+ const to = path11.join(userIssuedRoot(), lead);
17517
+ fs7.mkdirSync(to, { recursive: true, mode: 448 });
17518
+ for (const id of fs7.readdirSync(from)) {
17198
17519
  try {
17199
- fs6.copyFileSync(path10.join(from, id), path10.join(to, id), fs6.constants.COPYFILE_EXCL);
17520
+ fs7.copyFileSync(path11.join(from, id), path11.join(to, id), fs7.constants.COPYFILE_EXCL);
17200
17521
  } catch (error) {
17201
17522
  if (error.code !== "EEXIST")
17202
17523
  throw error;
17203
17524
  }
17204
- fs6.rmSync(path10.join(from, id), { force: true });
17525
+ fs7.rmSync(path11.join(from, id), { force: true });
17205
17526
  }
17206
17527
  removeIfEmpty(from);
17207
17528
  } catch {}
@@ -17210,14 +17531,14 @@ function migrateRepoIssued(cwd) {
17210
17531
  }
17211
17532
  var safeList = (dir) => {
17212
17533
  try {
17213
- return fs6.readdirSync(dir);
17534
+ return fs7.readdirSync(dir);
17214
17535
  } catch {
17215
17536
  return [];
17216
17537
  }
17217
17538
  };
17218
17539
  var removeIfEmpty = (dir) => {
17219
17540
  try {
17220
- fs6.rmdirSync(dir);
17541
+ fs7.rmdirSync(dir);
17221
17542
  } catch {}
17222
17543
  };
17223
17544
  var issuedRecord = (cwd, claimed) => {
@@ -17226,7 +17547,7 @@ var issuedRecord = (cwd, claimed) => {
17226
17547
  return null;
17227
17548
  migrateRepoIssued(cwd);
17228
17549
  try {
17229
- return fs6.readFileSync(path10.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
17550
+ return fs7.readFileSync(path11.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
17230
17551
  } catch {
17231
17552
  return null;
17232
17553
  }
@@ -17236,9 +17557,9 @@ var issuedToken = (claimed) => {
17236
17557
  const cut = claimed.lastIndexOf(":");
17237
17558
  if (cut <= 0)
17238
17559
  return { stored: null, leadBound: false };
17239
- const dir = path10.join(userTokenRoot(), hash(claimed.slice(0, cut)));
17560
+ const dir = path11.join(userTokenRoot(), hash(claimed.slice(0, cut)));
17240
17561
  try {
17241
- const text = fs6.readFileSync(path10.join(dir, hash(claimed)), "utf8");
17562
+ const text = fs7.readFileSync(path11.join(dir, hash(claimed)), "utf8");
17242
17563
  return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
17243
17564
  } catch {
17244
17565
  return { stored: null, leadBound: safeList(dir).length > 0 };
@@ -17257,8 +17578,8 @@ var OWN_CHILD_SHELL = new Set(["opencode", "pi"]);
17257
17578
 
17258
17579
  // packages/workit-core/src/store/event-log.ts
17259
17580
  import { randomUUID as randomUUID2 } from "node:crypto";
17260
- import fs7 from "node:fs";
17261
- import path11 from "node:path";
17581
+ import fs8 from "node:fs";
17582
+ import path12 from "node:path";
17262
17583
  var EVENT_VERSION = 1;
17263
17584
 
17264
17585
  class LogDamage extends Error {
@@ -17287,7 +17608,7 @@ var parseEvent = (line, file, offset) => {
17287
17608
  function readLog(file, from = 0, expectSeq = null) {
17288
17609
  let fd;
17289
17610
  try {
17290
- fd = fs7.openSync(file, "r");
17611
+ fd = fs8.openSync(file, "r");
17291
17612
  } catch (error) {
17292
17613
  if (error.code === "ENOENT")
17293
17614
  return null;
@@ -17296,13 +17617,13 @@ function readLog(file, from = 0, expectSeq = null) {
17296
17617
  let bytes;
17297
17618
  let size;
17298
17619
  try {
17299
- size = fs7.fstatSync(fd).size;
17620
+ size = fs8.fstatSync(fd).size;
17300
17621
  if (from > size)
17301
17622
  throw new LogDamage(`${file}: shorter than its snapshot`);
17302
17623
  bytes = Buffer.alloc(size - from);
17303
17624
  let read = 0;
17304
17625
  while (read < bytes.length) {
17305
- const got = fs7.readSync(fd, bytes, read, bytes.length - read, from + read);
17626
+ const got = fs8.readSync(fd, bytes, read, bytes.length - read, from + read);
17306
17627
  if (got === 0)
17307
17628
  break;
17308
17629
  read += got;
@@ -17310,7 +17631,7 @@ function readLog(file, from = 0, expectSeq = null) {
17310
17631
  bytes = bytes.subarray(0, read);
17311
17632
  size = from + read;
17312
17633
  } finally {
17313
- fs7.closeSync(fd);
17634
+ fs8.closeSync(fd);
17314
17635
  }
17315
17636
  const events = [];
17316
17637
  let start = 0;
@@ -17335,11 +17656,11 @@ function readLog(file, from = 0, expectSeq = null) {
17335
17656
  }
17336
17657
  var fsyncDirectory = (dir) => {
17337
17658
  try {
17338
- const fd = fs7.openSync(dir, "r");
17659
+ const fd = fs8.openSync(dir, "r");
17339
17660
  try {
17340
- fs7.fsyncSync(fd);
17661
+ fs8.fsyncSync(fd);
17341
17662
  } finally {
17342
- fs7.closeSync(fd);
17663
+ fs8.closeSync(fd);
17343
17664
  }
17344
17665
  } catch (error) {
17345
17666
  if (process.platform !== "win32")
@@ -17349,46 +17670,46 @@ var fsyncDirectory = (dir) => {
17349
17670
  function appendEvent(file, event, validEnd) {
17350
17671
  const line = Buffer.from(`${JSON.stringify(event)}
17351
17672
  `, "utf8");
17352
- const created = !fs7.existsSync(file);
17353
- if (!created && fs7.statSync(file).size !== validEnd) {
17354
- const cut = fs7.openSync(file, "r+");
17673
+ const created = !fs8.existsSync(file);
17674
+ if (!created && fs8.statSync(file).size !== validEnd) {
17675
+ const cut = fs8.openSync(file, "r+");
17355
17676
  try {
17356
- fs7.ftruncateSync(cut, validEnd);
17357
- fs7.fsyncSync(cut);
17677
+ fs8.ftruncateSync(cut, validEnd);
17678
+ fs8.fsyncSync(cut);
17358
17679
  } finally {
17359
- fs7.closeSync(cut);
17680
+ fs8.closeSync(cut);
17360
17681
  }
17361
17682
  }
17362
- const fd = fs7.openSync(file, "a", 384);
17683
+ const fd = fs8.openSync(file, "a", 384);
17363
17684
  try {
17364
17685
  let written = 0;
17365
17686
  while (written < line.length)
17366
- written += fs7.writeSync(fd, line, written, line.length - written);
17367
- fs7.fsyncSync(fd);
17687
+ written += fs8.writeSync(fd, line, written, line.length - written);
17688
+ fs8.fsyncSync(fd);
17368
17689
  } finally {
17369
- fs7.closeSync(fd);
17690
+ fs8.closeSync(fd);
17370
17691
  }
17371
17692
  if (created)
17372
- fsyncDirectory(path11.dirname(file));
17693
+ fsyncDirectory(path12.dirname(file));
17373
17694
  return validEnd;
17374
17695
  }
17375
17696
  function replaceFile(file, bytes, durable) {
17376
17697
  const temporary = `${file}.${process.pid}.${randomUUID2()}.tmp`;
17377
17698
  try {
17378
- const fd = fs7.openSync(temporary, "wx", 384);
17699
+ const fd = fs8.openSync(temporary, "wx", 384);
17379
17700
  try {
17380
- fs7.writeSync(fd, bytes);
17701
+ fs8.writeSync(fd, bytes);
17381
17702
  if (durable)
17382
- fs7.fsyncSync(fd);
17703
+ fs8.fsyncSync(fd);
17383
17704
  } finally {
17384
- fs7.closeSync(fd);
17705
+ fs8.closeSync(fd);
17385
17706
  }
17386
17707
  renameWithRetry(temporary, file);
17387
17708
  if (durable)
17388
- fsyncDirectory(path11.dirname(file));
17709
+ fsyncDirectory(path12.dirname(file));
17389
17710
  } catch (error) {
17390
17711
  try {
17391
- fs7.unlinkSync(temporary);
17712
+ fs8.unlinkSync(temporary);
17392
17713
  } catch {}
17393
17714
  throw error;
17394
17715
  }
@@ -17413,7 +17734,7 @@ var retryTransient = (run) => {
17413
17734
  }
17414
17735
  }
17415
17736
  };
17416
- var renameWithRetry = (from, to) => retryTransient(() => fs7.renameSync(from, to));
17737
+ var renameWithRetry = (from, to) => retryTransient(() => fs8.renameSync(from, to));
17417
17738
 
17418
17739
  // packages/workit-core/src/core/checkout-leftovers.ts
17419
17740
  var CHECKOUT_LEFTOVERS = [
@@ -17542,7 +17863,7 @@ var isPatch = (value) => Array.isArray(value) && value.every((op) => {
17542
17863
  });
17543
17864
 
17544
17865
  // packages/workit-core/src/store/reduce.ts
17545
- import { createHash as createHash7 } from "node:crypto";
17866
+ import { createHash as createHash8 } from "node:crypto";
17546
17867
  var OPENING_TYPES = new Set([
17547
17868
  "task.opened",
17548
17869
  "task.imported",
@@ -17571,7 +17892,7 @@ var isObject4 = (value) => typeof value === "object" && value !== null && !Array
17571
17892
  var isKey = (value) => isObject4(value) && typeof value.key === "string" && (value.kind === "branch" || value.kind === "detached" || value.kind === "dir") && (value.branch === null || typeof value.branch === "string");
17572
17893
  var BLOB_REF = "$blob";
17573
17894
  var blobRef = (value) => isObject4(value) && Object.keys(value).length === 1 && typeof value[BLOB_REF] === "string" && /^[0-9a-f]{64}$/.test(value[BLOB_REF]) ? value[BLOB_REF] : null;
17574
- var blobDigest = (value) => createHash7("sha256").update(JSON.stringify(value)).digest("hex");
17895
+ var blobDigest = (value) => createHash8("sha256").update(JSON.stringify(value)).digest("hex");
17575
17896
  var toBlob = (value, blobs) => {
17576
17897
  if (!isObject4(value))
17577
17898
  return value;
@@ -17685,8 +18006,8 @@ var migrationReporterInstalled = () => typeof globalThis[SLOT] === "function";
17685
18006
 
17686
18007
  // packages/workit-core/src/core/task-read.ts
17687
18008
  import { randomUUID as randomUUID3 } from "node:crypto";
17688
- import * as fs12 from "node:fs";
17689
- import path15 from "node:path";
18009
+ import * as fs13 from "node:fs";
18010
+ import path16 from "node:path";
17690
18011
 
17691
18012
  // node_modules/@openclaw/fs-safe/dist/errors.js
17692
18013
  var OPERATIONAL_CODES = new Set([
@@ -17737,10 +18058,10 @@ function sameFileIdentity(left, right, platform = process.platform) {
17737
18058
  // node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js
17738
18059
  import { randomBytes as randomBytes2 } from "node:crypto";
17739
18060
  import fsSync from "node:fs";
17740
- import path12 from "node:path";
18061
+ import path13 from "node:path";
17741
18062
 
17742
18063
  // node_modules/@openclaw/fs-safe/dist/bounded-read.js
17743
- import fs8 from "node:fs";
18064
+ import fs9 from "node:fs";
17744
18065
 
17745
18066
  // node_modules/@openclaw/fs-safe/dist/byte-budget.js
17746
18067
  function normalizeMaxBytes(value, options = {}) {
@@ -17777,7 +18098,7 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
17777
18098
  let total = 0;
17778
18099
  while (true) {
17779
18100
  const length = nextReadLength(total, maxBytes, scratch.length);
17780
- const bytesRead = fs8.readSync(fd, scratch, 0, length, null);
18101
+ const bytesRead = fs9.readSync(fd, scratch, 0, length, null);
17781
18102
  if (bytesRead === 0) {
17782
18103
  return Buffer.concat(chunks, total);
17783
18104
  }
@@ -17786,9 +18107,9 @@ function readFileDescriptorBoundedSync(fd, maxBytes) {
17786
18107
  }
17787
18108
 
17788
18109
  // node_modules/@openclaw/fs-safe/dist/read-open-flags.js
17789
- import fs9 from "node:fs";
18110
+ import fs10 from "node:fs";
17790
18111
  function resolveReadOpenFlags(options) {
17791
- const constants = options?.constants ?? fs9.constants;
18112
+ const constants = options?.constants ?? fs10.constants;
17792
18113
  const noFollow = process.platform !== "win32" && options?.followSymlinks !== true && typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
17793
18114
  const nonBlocking = process.platform !== "win32" && typeof constants.O_NONBLOCK === "number" ? constants.O_NONBLOCK : 0;
17794
18115
  return constants.O_RDONLY | noFollow | nonBlocking;
@@ -17827,13 +18148,13 @@ ${ownershipToken}
17827
18148
  return { raw, ownershipToken };
17828
18149
  }
17829
18150
  function relativeSidecarLockPath(lockRoot, lockPath) {
17830
- const resolved = path12.resolve(lockPath);
17831
- const lexicalRelative = path12.relative(lockRoot.rootDir, resolved);
17832
- const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path12.sep}`) && !path12.isAbsolute(lexicalRelative) ? lexicalRelative : path12.relative(lockRoot.rootReal, resolved);
17833
- if (!relative || relative === ".." || relative.startsWith(`..${path12.sep}`) || path12.isAbsolute(relative)) {
18151
+ const resolved = path13.resolve(lockPath);
18152
+ const lexicalRelative = path13.relative(lockRoot.rootDir, resolved);
18153
+ const relative = lexicalRelative !== ".." && !lexicalRelative.startsWith(`..${path13.sep}`) && !path13.isAbsolute(lexicalRelative) ? lexicalRelative : path13.relative(lockRoot.rootReal, resolved);
18154
+ if (!relative || relative === ".." || relative.startsWith(`..${path13.sep}`) || path13.isAbsolute(relative)) {
17834
18155
  throw new FsSafeError("outside-workspace", "sidecar lock path is outside lockRoot");
17835
18156
  }
17836
- return relative.split(path12.sep).join(path12.posix.sep);
18157
+ return relative.split(path13.sep).join(path13.posix.sep);
17837
18158
  }
17838
18159
  function parseSidecarLockPayload(raw, parser) {
17839
18160
  if (parser) {
@@ -17979,8 +18300,8 @@ function getFsSafeLockConfig() {
17979
18300
  }
17980
18301
 
17981
18302
  // node_modules/@openclaw/fs-safe/dist/file-lock-sync.js
17982
- import fs10 from "node:fs";
17983
- import path13 from "node:path";
18303
+ import fs11 from "node:fs";
18304
+ import path14 from "node:path";
17984
18305
 
17985
18306
  // node_modules/@openclaw/fs-safe/dist/timing.js
17986
18307
  function sleepSync(ms) {
@@ -18010,7 +18331,7 @@ function releaseAllSyncHeldLocks() {
18010
18331
  }
18011
18332
  try {
18012
18333
  if (held.fd !== undefined)
18013
- fs10.closeSync(held.fd);
18334
+ fs11.closeSync(held.fd);
18014
18335
  } catch {}
18015
18336
  try {
18016
18337
  removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
@@ -18045,7 +18366,7 @@ function releaseSyncHeldLock(held) {
18045
18366
  if (held.fd !== undefined) {
18046
18367
  const fd = held.fd;
18047
18368
  held.fd = undefined;
18048
- fs10.closeSync(fd);
18369
+ fs11.closeSync(fd);
18049
18370
  }
18050
18371
  removeSidecarLockIfUnchangedSync(held.lockPath, held.snapshot);
18051
18372
  heldLocks.delete(held.normalizedTargetPath);
@@ -18068,29 +18389,29 @@ function createSyncHeldLockHandle(held) {
18068
18389
  };
18069
18390
  }
18070
18391
  function canonicalLockParentSync(parent) {
18071
- return process.platform === "win32" ? fs10.realpathSync.native(parent) : fs10.realpathSync(parent);
18392
+ return process.platform === "win32" ? fs11.realpathSync.native(parent) : fs11.realpathSync(parent);
18072
18393
  }
18073
18394
  function normalizeTargetPath(targetPath) {
18074
- const resolved = path13.resolve(targetPath);
18075
- fs10.mkdirSync(path13.dirname(resolved), { recursive: true });
18395
+ const resolved = path14.resolve(targetPath);
18396
+ fs11.mkdirSync(path14.dirname(resolved), { recursive: true });
18076
18397
  try {
18077
- return path13.join(canonicalLockParentSync(path13.dirname(resolved)), path13.basename(resolved));
18398
+ return path14.join(canonicalLockParentSync(path14.dirname(resolved)), path14.basename(resolved));
18078
18399
  } catch {
18079
18400
  return resolved;
18080
18401
  }
18081
18402
  }
18082
18403
  function boundedLockPath(lockPath, lockRoot) {
18083
- const resolved = path13.resolve(lockPath);
18404
+ const resolved = path14.resolve(lockPath);
18084
18405
  if (!lockRoot)
18085
18406
  return resolved;
18086
18407
  relativeSidecarLockPath(lockRoot, resolved);
18087
- const parent = path13.dirname(resolved);
18408
+ const parent = path14.dirname(resolved);
18088
18409
  const parentReal = canonicalLockParentSync(parent);
18089
- const parentRelative = path13.relative(lockRoot.rootReal, parentReal);
18090
- if (parentRelative === ".." || parentRelative.startsWith(`..${path13.sep}`) || path13.isAbsolute(parentRelative)) {
18410
+ const parentRelative = path14.relative(lockRoot.rootReal, parentReal);
18411
+ if (parentRelative === ".." || parentRelative.startsWith(`..${path14.sep}`) || path14.isAbsolute(parentRelative)) {
18091
18412
  throw new FsSafeError("outside-workspace", "sidecar lock parent is outside lockRoot");
18092
18413
  }
18093
- return path13.join(parentReal, path13.basename(resolved));
18414
+ return path14.join(parentReal, path14.basename(resolved));
18094
18415
  }
18095
18416
  function defaultShouldReclaim(snapshot, staleMs, nowMs) {
18096
18417
  const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
@@ -18100,7 +18421,7 @@ function defaultShouldReclaim(snapshot, staleMs, nowMs) {
18100
18421
  }
18101
18422
  function reclaimGuardExists(reclaimGuardPath) {
18102
18423
  try {
18103
- fs10.lstatSync(reclaimGuardPath);
18424
+ fs11.lstatSync(reclaimGuardPath);
18104
18425
  return true;
18105
18426
  } catch (error) {
18106
18427
  if (error.code === "ENOENT")
@@ -18164,19 +18485,19 @@ function acquireFileLockSync(targetPath, options) {
18164
18485
  const { raw, ownershipToken } = serializeSidecarLockPayload(payload);
18165
18486
  let lockFileCreateDenied = false;
18166
18487
  try {
18167
- const noFollow = process.platform !== "win32" && typeof fs10.constants.O_NOFOLLOW === "number" ? fs10.constants.O_NOFOLLOW : 0;
18488
+ const noFollow = process.platform !== "win32" && typeof fs11.constants.O_NOFOLLOW === "number" ? fs11.constants.O_NOFOLLOW : 0;
18168
18489
  try {
18169
- fd = fs10.openSync(lockPath, fs10.constants.O_WRONLY | fs10.constants.O_CREAT | fs10.constants.O_EXCL | noFollow, 384);
18490
+ fd = fs11.openSync(lockPath, fs11.constants.O_WRONLY | fs11.constants.O_CREAT | fs11.constants.O_EXCL | noFollow, 384);
18170
18491
  } catch (error) {
18171
18492
  lockFileCreateDenied = isTransientLockFileDenial(error, lockPath);
18172
18493
  throw error;
18173
18494
  }
18174
- fs10.writeFileSync(fd, raw, "utf8");
18175
- fs10.fsyncSync(fd);
18495
+ fs11.writeFileSync(fd, raw, "utf8");
18496
+ fs11.fsyncSync(fd);
18176
18497
  const snapshot = {
18177
18498
  raw,
18178
18499
  payload,
18179
- stat: fs10.fstatSync(fd),
18500
+ stat: fs11.fstatSync(fd),
18180
18501
  ownershipToken
18181
18502
  };
18182
18503
  const createdHeld = {
@@ -18211,8 +18532,8 @@ function acquireFileLockSync(targetPath, options) {
18211
18532
  return returnedHandle;
18212
18533
  } catch (error) {
18213
18534
  if (fd !== undefined) {
18214
- const failed = { payload: null, stat: fs10.fstatSync(fd) };
18215
- fs10.closeSync(fd);
18535
+ const failed = { payload: null, stat: fs11.fstatSync(fd) };
18536
+ fs11.closeSync(fd);
18216
18537
  fd = undefined;
18217
18538
  removeSidecarLockIfUnchangedSync(lockPath, failed);
18218
18539
  }
@@ -18261,7 +18582,7 @@ function acquireFileLockSync(targetPath, options) {
18261
18582
  })) {
18262
18583
  let ownsReclaimGuard = false;
18263
18584
  try {
18264
- fs10.mkdirSync(reclaimGuardPath);
18585
+ fs11.mkdirSync(reclaimGuardPath);
18265
18586
  ownsReclaimGuard = true;
18266
18587
  if (removeSidecarLockIfUnchangedSync(lockPath, snapshot))
18267
18588
  continue;
@@ -18274,7 +18595,7 @@ function acquireFileLockSync(targetPath, options) {
18274
18595
  } finally {
18275
18596
  if (ownsReclaimGuard) {
18276
18597
  try {
18277
- fs10.rmdirSync(reclaimGuardPath);
18598
+ fs11.rmdirSync(reclaimGuardPath);
18278
18599
  } catch {}
18279
18600
  }
18280
18601
  }
@@ -18290,27 +18611,27 @@ function acquireFileLockSync(targetPath, options) {
18290
18611
  }
18291
18612
  }
18292
18613
  // packages/workit-core/src/core/package-root.ts
18293
- import { existsSync as existsSync4 } from "node:fs";
18294
- import path14 from "node:path";
18614
+ import { existsSync as existsSync5 } from "node:fs";
18615
+ import path15 from "node:path";
18295
18616
  import { fileURLToPath } from "node:url";
18296
18617
  var packageRoot = () => {
18297
- let dir = path14.dirname(fileURLToPath(import.meta.url));
18618
+ let dir = path15.dirname(fileURLToPath(import.meta.url));
18298
18619
  while (true) {
18299
- const parent = path14.dirname(dir);
18300
- if (existsSync4(path14.join(dir, "package.json")) || parent === dir)
18620
+ const parent = path15.dirname(dir);
18621
+ if (existsSync5(path15.join(dir, "package.json")) || parent === dir)
18301
18622
  return dir;
18302
18623
  dir = parent;
18303
18624
  }
18304
18625
  };
18305
18626
  var assetRoot = () => {
18306
18627
  const root = packageRoot();
18307
- const assets = path14.join(root, "assets");
18308
- return existsSync4(assets) ? assets : root;
18628
+ const assets = path15.join(root, "assets");
18629
+ return existsSync5(assets) ? assets : root;
18309
18630
  };
18310
18631
 
18311
18632
  // packages/workit-core/src/core/store-lock.ts
18312
18633
  import { spawnSync as spawnSync10 } from "node:child_process";
18313
- import fs11 from "node:fs";
18634
+ import fs12 from "node:fs";
18314
18635
  import { hostname } from "node:os";
18315
18636
  var metadataLockSchema = object({
18316
18637
  pid: number2().int().nonnegative().safe(),
@@ -18353,7 +18674,7 @@ var parseProcStatStart = (stat) => {
18353
18674
  };
18354
18675
  var readProcStat = (pid) => {
18355
18676
  try {
18356
- return fs11.readFileSync(`/proc/${pid}/stat`, "utf8");
18677
+ return fs12.readFileSync(`/proc/${pid}/stat`, "utf8");
18357
18678
  } catch {
18358
18679
  return null;
18359
18680
  }
@@ -18382,7 +18703,7 @@ var processStartOf = (pid, deps = {}) => {
18382
18703
  };
18383
18704
  var readTrimmed = (file) => {
18384
18705
  try {
18385
- return fs11.readFileSync(file, "utf8").trim() || null;
18706
+ return fs12.readFileSync(file, "utf8").trim() || null;
18386
18707
  } catch {
18387
18708
  return null;
18388
18709
  }
@@ -18393,7 +18714,7 @@ var localLockHost = () => {
18393
18714
  return cachedLockHost;
18394
18715
  let pidns = null;
18395
18716
  try {
18396
- pidns = /\[(\d+)\]/.exec(fs11.readlinkSync("/proc/self/ns/pid"))?.[1] ?? null;
18717
+ pidns = /\[(\d+)\]/.exec(fs12.readlinkSync("/proc/self/ns/pid"))?.[1] ?? null;
18397
18718
  } catch {}
18398
18719
  const boot = readTrimmed("/proc/sys/kernel/random/boot_id");
18399
18720
  cachedLockHost = pidns || boot ? `${hostname()}#${pidns ?? "?"}:${boot ?? "?"}` : hostname();
@@ -18439,7 +18760,7 @@ var classifyLockOwner = (payload, ageMs, localHost = localLockHost(), options =
18439
18760
  };
18440
18761
  var ageOf = (file, nowMs) => {
18441
18762
  try {
18442
- return nowMs - fs11.lstatSync(file).mtimeMs;
18763
+ return nowMs - fs12.lstatSync(file).mtimeMs;
18443
18764
  } catch {
18444
18765
  return null;
18445
18766
  }
@@ -18450,7 +18771,7 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
18450
18771
  if (age === null || age <= RECLAIM_GUARD_TTL_MS)
18451
18772
  return false;
18452
18773
  try {
18453
- fs11.rmdirSync(guard);
18774
+ fs12.rmdirSync(guard);
18454
18775
  return true;
18455
18776
  } catch {
18456
18777
  return false;
@@ -18495,7 +18816,7 @@ var indexEntry = (task, key, legacy, file) => {
18495
18816
  };
18496
18817
  var fileSignature = (file) => {
18497
18818
  try {
18498
- const stat = fs12.statSync(file, { bigint: true });
18819
+ const stat = fs13.statSync(file, { bigint: true });
18499
18820
  return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
18500
18821
  } catch {
18501
18822
  return null;
@@ -18512,7 +18833,7 @@ var cachedRuntimeVersion = null;
18512
18833
  var runtimeVersion = () => {
18513
18834
  if (cachedRuntimeVersion === null) {
18514
18835
  try {
18515
- const pkg = JSON.parse(fs12.readFileSync(path15.join(packageRoot(), "package.json"), "utf8"));
18836
+ const pkg = JSON.parse(fs13.readFileSync(path16.join(packageRoot(), "package.json"), "utf8"));
18516
18837
  cachedRuntimeVersion = typeof pkg.version === "string" && pkg.version ? pkg.version : "0.0.0";
18517
18838
  } catch {
18518
18839
  cachedRuntimeVersion = "0.0.0";
@@ -18534,14 +18855,14 @@ var isNewerVersion = (candidate, current) => {
18534
18855
  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);
18535
18856
  var readText2 = (file) => {
18536
18857
  try {
18537
- return fs12.readFileSync(file, "utf8");
18858
+ return fs13.readFileSync(file, "utf8");
18538
18859
  } catch {
18539
18860
  return "";
18540
18861
  }
18541
18862
  };
18542
18863
  var REFLOG_LINE = /^[0-9a-f]+ ([0-9a-f]+) .* (\d+) [+-]\d{4}\t(.*)$/u;
18543
18864
  var branchStart = (location, branch, aliases) => {
18544
- const first = readText2(path15.join(path15.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
18865
+ const first = readText2(path16.join(path16.dirname(location.dir), "logs", "refs", "heads", branch)).split(`
18545
18866
  `, 1)[0];
18546
18867
  const created = REFLOG_LINE.exec(first);
18547
18868
  const start = created && /^branch: Created from (\S+)$/u.exec(created[3])?.[1];
@@ -18551,7 +18872,7 @@ var branchStart = (location, branch, aliases) => {
18551
18872
  return start;
18552
18873
  if (!location.git)
18553
18874
  return null;
18554
- for (const line of readText2(path15.join(location.git.gitDir, "logs", "HEAD")).split(`
18875
+ for (const line of readText2(path16.join(location.git.gitDir, "logs", "HEAD")).split(`
18555
18876
  `)) {
18556
18877
  const entry = REFLOG_LINE.exec(line);
18557
18878
  const moved = entry && /^checkout: moving from (\S+) to (\S+)$/u.exec(entry[3]);
@@ -18561,23 +18882,23 @@ var branchStart = (location, branch, aliases) => {
18561
18882
  }
18562
18883
  return null;
18563
18884
  };
18564
- var refExists2 = (common, ref) => fs12.existsSync(path15.join(common, ref)) || readText2(path15.join(common, "packed-refs")).includes(` ${ref}
18885
+ var refExists2 = (common, ref) => fs13.existsSync(path16.join(common, ref)) || readText2(path16.join(common, "packed-refs")).includes(` ${ref}
18565
18886
  `);
18566
18887
  var origins = new Map;
18567
18888
  var sameDirectoryIdentity = (left, right) => {
18568
- if (!path15.isAbsolute(left) || !path15.isAbsolute(right))
18889
+ if (!path16.isAbsolute(left) || !path16.isAbsolute(right))
18569
18890
  return false;
18570
- const normalizedLeft = path15.resolve(left);
18571
- const normalizedRight = path15.resolve(right);
18891
+ const normalizedLeft = path16.resolve(left);
18892
+ const normalizedRight = path16.resolve(right);
18572
18893
  try {
18573
- const a = fs12.statSync(normalizedLeft, { bigint: true });
18574
- const b = fs12.statSync(normalizedRight, { bigint: true });
18894
+ const a = fs13.statSync(normalizedLeft, { bigint: true });
18895
+ const b = fs13.statSync(normalizedRight, { bigint: true });
18575
18896
  if (!a.isDirectory() || !b.isDirectory())
18576
18897
  return false;
18577
18898
  if (process.platform === "win32" ? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase() : normalizedLeft === normalizedRight)
18578
18899
  return true;
18579
- const canonicalLeft = fs12.realpathSync(normalizedLeft);
18580
- const canonicalRight = fs12.realpathSync(normalizedRight);
18900
+ const canonicalLeft = fs13.realpathSync(normalizedLeft);
18901
+ const canonicalRight = fs13.realpathSync(normalizedRight);
18581
18902
  if (process.platform === "win32" ? canonicalLeft.toLowerCase() === canonicalRight.toLowerCase() : canonicalLeft === canonicalRight)
18582
18903
  return true;
18583
18904
  return a.dev === b.dev && a.ino !== 0n && a.ino === b.ino;
@@ -18602,14 +18923,14 @@ class TaskReader {
18602
18923
  located;
18603
18924
  migrationChecked = false;
18604
18925
  constructor(root, options = {}) {
18605
- const resolved = path15.resolve(root);
18606
- this.origin = fs12.existsSync(resolved) ? fs12.realpathSync(resolved) : resolved;
18926
+ const resolved = path16.resolve(root);
18927
+ this.origin = fs13.existsSync(resolved) ? fs13.realpathSync(resolved) : resolved;
18607
18928
  this.located = resolveStore(this.origin);
18608
18929
  this.root = checkoutRootOf(this.origin, this.located);
18609
18930
  this.lockTimeoutMs = options.lockTimeoutMs ?? defaultLockTimeout();
18610
18931
  }
18611
18932
  location() {
18612
- if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs12.existsSync(path15.join(this.root, ".git"))) {
18933
+ if (this.located !== undefined && !(this.located instanceof Error) && !this.located.shared && fs13.existsSync(path16.join(this.root, ".git"))) {
18613
18934
  this.located = undefined;
18614
18935
  this.migrationChecked = false;
18615
18936
  }
@@ -18673,7 +18994,7 @@ class TaskReader {
18673
18994
  const tasksDir = this.paths().tasks;
18674
18995
  let names;
18675
18996
  try {
18676
- names = fs12.existsSync(tasksDir) ? fs12.readdirSync(tasksDir).filter((name) => validId(name)) : [];
18997
+ names = fs13.existsSync(tasksDir) ? fs13.readdirSync(tasksDir).filter((name) => validId(name)) : [];
18677
18998
  } catch (error) {
18678
18999
  return failure2("storage_error", `unable to list tasks: ${String(error)}`, {
18679
19000
  path: tasksDir
@@ -18714,7 +19035,7 @@ class TaskReader {
18714
19035
  const file = this.paths().workspace;
18715
19036
  let bytes;
18716
19037
  try {
18717
- bytes = retryTransient(() => fs12.readFileSync(file, "utf8"));
19038
+ bytes = retryTransient(() => fs13.readFileSync(file, "utf8"));
18718
19039
  } catch (error) {
18719
19040
  if (error.code === "ENOENT")
18720
19041
  return success(null, null, null);
@@ -18767,14 +19088,14 @@ class TaskReader {
18767
19088
  const branch = key.ok ? key.data.branch : null;
18768
19089
  if (!branch || !location.ok)
18769
19090
  return success(null, null, null);
18770
- const common = path15.dirname(location.data.dir);
18771
- const heads = path15.join(common, "logs", "refs", "heads");
18772
- const headLog = location.data.git ? path15.join(location.data.git.gitDir, "logs", "HEAD") : "";
19091
+ const common = path16.dirname(location.data.dir);
19092
+ const heads = path16.join(common, "logs", "refs", "heads");
19093
+ const headLog = location.data.git ? path16.join(location.data.git.gitDir, "logs", "HEAD") : "";
18773
19094
  const signatures = [
18774
- path15.join(heads, branch),
19095
+ path16.join(heads, branch),
18775
19096
  headLog,
18776
19097
  heads,
18777
- path15.join(common, "packed-refs")
19098
+ path16.join(common, "packed-refs")
18778
19099
  ].map((file) => fileSignature(file) ?? "-");
18779
19100
  const slot = `${location.data.dir}\x00${headLog}\x00${branch}`;
18780
19101
  let resolved = origins.get(slot);
@@ -18786,7 +19107,7 @@ class TaskReader {
18786
19107
  aliases.push(rename.from);
18787
19108
  const start = branchStart(location.data, branch, aliases);
18788
19109
  const slash = start?.indexOf("/") ?? -1;
18789
- const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path15.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
19110
+ const remote = slash > 0 && !refExists2(common, `refs/heads/${start}`) && (refExists2(common, `refs/remotes/${start}`) || readText2(path16.join(common, "config")).includes(`[remote "${start.slice(0, slash)}"]`));
18790
19111
  const name = start && (remote ? start.slice(slash + 1) : start);
18791
19112
  resolved = {
18792
19113
  signature: signatures.join("|"),
@@ -18806,27 +19127,27 @@ class TaskReader {
18806
19127
  }
18807
19128
  paths() {
18808
19129
  const location = this.location();
18809
- const dir = location.ok ? location.data.dir : path15.join(this.root, ".workit");
18810
- const checkout = path15.join(dir, "checkouts", checkoutSlug(this.root));
19130
+ const dir = location.ok ? location.data.dir : path16.join(this.root, ".workit");
19131
+ const checkout = path16.join(dir, "checkouts", checkoutSlug(this.root));
18811
19132
  return {
18812
19133
  dir,
18813
19134
  shared: location.ok ? location.data.shared : false,
18814
- marker: path15.join(dir, "store.json"),
19135
+ marker: path16.join(dir, "store.json"),
18815
19136
  checkout,
18816
- workspace: path15.join(checkout, "workspace.json"),
18817
- checkoutLock: path15.join(checkout, "metadata.lock"),
18818
- tasks: path15.join(dir, "tasks"),
18819
- index: path15.join(dir, "task-index.json"),
18820
- blobs: path15.join(dir, "blobs", "candidates"),
18821
- legacy: path15.join(dir, "legacy", checkoutSlug(this.root), "v2"),
18822
- v2: path15.join(this.root, ".workit")
19137
+ workspace: path16.join(checkout, "workspace.json"),
19138
+ checkoutLock: path16.join(checkout, "metadata.lock"),
19139
+ tasks: path16.join(dir, "tasks"),
19140
+ index: path16.join(dir, "task-index.json"),
19141
+ blobs: path16.join(dir, "blobs", "candidates"),
19142
+ legacy: path16.join(dir, "legacy", checkoutSlug(this.root), "v2"),
19143
+ v2: path16.join(this.root, ".workit")
18823
19144
  };
18824
19145
  }
18825
19146
  eventsPath(taskId) {
18826
- return path15.join(this.paths().tasks, taskId, "events.jsonl");
19147
+ return path16.join(this.paths().tasks, taskId, "events.jsonl");
18827
19148
  }
18828
19149
  snapshotPath(taskId) {
18829
- return path15.join(this.paths().tasks, taskId, "snapshot.json");
19150
+ return path16.join(this.paths().tasks, taskId, "snapshot.json");
18830
19151
  }
18831
19152
  ready(write = false) {
18832
19153
  const location = this.location();
@@ -18836,7 +19157,7 @@ class TaskReader {
18836
19157
  return success(null, null, null);
18837
19158
  const dirs = this.paths();
18838
19159
  try {
18839
- const marker = JSON.parse(fs12.readFileSync(dirs.marker, "utf8"));
19160
+ const marker = JSON.parse(fs13.readFileSync(dirs.marker, "utf8"));
18840
19161
  if (typeof marker.version === "number" && marker.version > STORE_FORMAT)
18841
19162
  return failure2("recovery_required", `the workit store at ${dirs.dir} has format ${marker.version}; upgrade Workit to use it`, { path: dirs.marker });
18842
19163
  } catch {}
@@ -18861,7 +19182,7 @@ class TaskReader {
18861
19182
  return {
18862
19183
  read: (digest) => {
18863
19184
  try {
18864
- return JSON.parse(fs12.readFileSync(path15.join(dir, `${digest}.json`), "utf8"));
19185
+ return JSON.parse(fs13.readFileSync(path16.join(dir, `${digest}.json`), "utf8"));
18865
19186
  } catch (error) {
18866
19187
  throw new LogDamage(`stored candidate ${digest} is missing or unreadable: ${String(error)}`);
18867
19188
  }
@@ -18948,7 +19269,7 @@ class TaskReader {
18948
19269
  }
18949
19270
  readSnapshot(taskId) {
18950
19271
  try {
18951
- const value = JSON.parse(fs12.readFileSync(this.snapshotPath(taskId), "utf8"));
19272
+ const value = JSON.parse(fs13.readFileSync(this.snapshotPath(taskId), "utf8"));
18952
19273
  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))
18953
19274
  return null;
18954
19275
  return value;
@@ -18975,7 +19296,7 @@ class TaskReader {
18975
19296
  }
18976
19297
  readIndex() {
18977
19298
  try {
18978
- const value = JSON.parse(fs12.readFileSync(this.paths().index, "utf8"));
19299
+ const value = JSON.parse(fs13.readFileSync(this.paths().index, "utf8"));
18979
19300
  if (!isObject5(value) || value.version !== INDEX_VERSION || !isObject5(value.tasks))
18980
19301
  return {};
18981
19302
  const tasks = {};
@@ -18989,7 +19310,7 @@ class TaskReader {
18989
19310
  }
18990
19311
  writeIndex(entries) {
18991
19312
  try {
18992
- fs12.mkdirSync(this.paths().tasks, { recursive: true });
19313
+ fs13.mkdirSync(this.paths().tasks, { recursive: true });
18993
19314
  replaceFile(this.paths().index, JSON.stringify({
18994
19315
  version: INDEX_VERSION,
18995
19316
  tasks: Object.fromEntries(entries.map((entry) => [entry.id, entry]))
@@ -19027,64 +19348,74 @@ class TaskReader {
19027
19348
  return failure2("recovery_required", `${label} record does not satisfy its schema`);
19028
19349
  }
19029
19350
  v2Dirs() {
19030
- return [...new Set([this.root, this.origin])].map((dir) => path15.join(dir, ".workit"));
19351
+ return [...new Set([this.root, this.origin])].map((dir) => path16.join(dir, ".workit"));
19031
19352
  }
19032
19353
  pendingMigrations() {
19033
19354
  return this.v2Dirs().filter((dir) => {
19034
- const raw = this.readV2Workspace(path15.join(dir, "workspace.json"));
19355
+ const raw = this.readV2Workspace(path16.join(dir, "workspace.json"));
19035
19356
  return raw !== null && raw !== TOMBSTONE;
19036
19357
  });
19037
19358
  }
19038
19359
  adoptLocalStore() {
19360
+ if (!this.paths().shared)
19361
+ return success(null, null, null);
19362
+ for (const local of [this.paths().v2, folderStoreDir(this.root)]) {
19363
+ const adopted = this.adoptStoreFrom(local);
19364
+ if (!adopted.ok)
19365
+ return adopted;
19366
+ }
19367
+ return success(null, null, null);
19368
+ }
19369
+ adoptStoreFrom(local) {
19039
19370
  const dirs = this.paths();
19040
- const marker = path15.join(dirs.v2, "store.json");
19041
- if (!dirs.shared || !fs12.existsSync(marker))
19371
+ const marker = path16.join(local, "store.json");
19372
+ if (!fs13.existsSync(marker))
19042
19373
  return success(null, null, null);
19043
19374
  return this.withLock(dirs.checkoutLock, () => {
19044
- if (!fs12.existsSync(marker))
19375
+ if (!fs13.existsSync(marker))
19045
19376
  return success(null, null, null);
19046
19377
  let tasks = 0;
19047
19378
  try {
19048
19379
  const merge = (from, to) => {
19049
- if (!fs12.existsSync(to)) {
19050
- fs12.mkdirSync(path15.dirname(to), { recursive: true });
19380
+ if (!fs13.existsSync(to)) {
19381
+ fs13.mkdirSync(path16.dirname(to), { recursive: true });
19051
19382
  try {
19052
- fs12.renameSync(from, to);
19383
+ fs13.renameSync(from, to);
19053
19384
  } catch {
19054
- fs12.cpSync(from, to, { recursive: true, errorOnExist: true, force: false });
19055
- fs12.rmSync(from, { recursive: true, force: true });
19385
+ fs13.cpSync(from, to, { recursive: true, errorOnExist: true, force: false });
19386
+ fs13.rmSync(from, { recursive: true, force: true });
19056
19387
  }
19057
19388
  return;
19058
19389
  }
19059
- if (fs12.lstatSync(from).isDirectory() && fs12.lstatSync(to).isDirectory())
19060
- for (const name of fs12.readdirSync(from))
19061
- merge(path15.join(from, name), path15.join(to, name));
19390
+ if (fs13.lstatSync(from).isDirectory() && fs13.lstatSync(to).isDirectory())
19391
+ for (const name of fs13.readdirSync(from))
19392
+ merge(path16.join(from, name), path16.join(to, name));
19062
19393
  };
19063
19394
  for (const sub of ["tasks", "checkouts", "blobs", "legacy"]) {
19064
- const from = path15.join(dirs.v2, sub);
19065
- if (!fs12.existsSync(from))
19395
+ const from = path16.join(local, sub);
19396
+ if (!fs13.existsSync(from))
19066
19397
  continue;
19067
19398
  if (sub === "tasks") {
19068
- for (const name of fs12.readdirSync(from))
19069
- if (validId(name) && !fs12.existsSync(path15.join(dirs.dir, sub, name)))
19399
+ for (const name of fs13.readdirSync(from))
19400
+ if (validId(name) && !fs13.existsSync(path16.join(dirs.dir, sub, name)))
19070
19401
  tasks += 1;
19071
19402
  }
19072
- merge(from, path15.join(dirs.dir, sub));
19403
+ merge(from, path16.join(dirs.dir, sub));
19073
19404
  }
19074
- const ledger = path15.join(dirs.v2, "ledger");
19075
- if (fs12.existsSync(ledger) && !fs12.existsSync(path15.join(dirs.dir, "ledger")))
19076
- merge(ledger, path15.join(dirs.dir, "ledger"));
19077
- fs12.rmSync(path15.join(dirs.v2, "task-index.json"), { force: true });
19078
- fs12.renameSync(marker, path15.join(dirs.v2, "store.moved.json"));
19405
+ const ledger = path16.join(local, "ledger");
19406
+ if (fs13.existsSync(ledger) && !fs13.existsSync(path16.join(dirs.dir, "ledger")))
19407
+ merge(ledger, path16.join(dirs.dir, "ledger"));
19408
+ fs13.rmSync(path16.join(local, "task-index.json"), { force: true });
19409
+ fs13.renameSync(marker, path16.join(local, "store.moved.json"));
19079
19410
  } catch (error) {
19080
- return failure2("storage_error", `cannot move ${dirs.v2} into ${dirs.dir}: ${String(error)}`, {
19081
- path: dirs.v2
19411
+ return failure2("storage_error", `cannot move ${local} into ${dirs.dir}: ${String(error)}`, {
19412
+ path: local
19082
19413
  });
19083
19414
  }
19084
19415
  reportMigration({
19085
- from: dirs.v2,
19416
+ from: local,
19086
19417
  to: dirs.dir,
19087
- backup: dirs.v2,
19418
+ backup: local,
19088
19419
  tasks,
19089
19420
  skipped: 0,
19090
19421
  workspace: false
@@ -19095,7 +19426,7 @@ class TaskReader {
19095
19426
  readV2Workspace(file) {
19096
19427
  let bytes;
19097
19428
  try {
19098
- bytes = fs12.readFileSync(file, "utf8");
19429
+ bytes = fs13.readFileSync(file, "utf8");
19099
19430
  } catch {
19100
19431
  return null;
19101
19432
  }
@@ -19113,7 +19444,7 @@ class TaskReader {
19113
19444
  schemaVersion: SCHEMA_VERSION,
19114
19445
  id: workspaceId ?? newId(),
19115
19446
  revision: newRevision(),
19116
- root: path15.dirname(v2),
19447
+ root: path16.dirname(v2),
19117
19448
  runtime: { createdWith: version, updatedWith: version },
19118
19449
  writer: null,
19119
19450
  store: {
@@ -19124,47 +19455,21 @@ class TaskReader {
19124
19455
  },
19125
19456
  critical: ["store"]
19126
19457
  };
19127
- fs12.mkdirSync(v2, { recursive: true });
19128
- const ignore = path15.join(v2, ".gitignore");
19129
- if (!fs12.existsSync(ignore))
19130
- fs12.writeFileSync(ignore, `*
19458
+ fs13.mkdirSync(v2, { recursive: true });
19459
+ const ignore = path16.join(v2, ".gitignore");
19460
+ if (!fs13.existsSync(ignore))
19461
+ fs13.writeFileSync(ignore, `*
19131
19462
  `);
19132
- replaceFile(path15.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
19463
+ replaceFile(path16.join(v2, "workspace.json"), `${JSON.stringify(marker, null, 2)}
19133
19464
  `, true);
19134
19465
  }
19135
- writeTombstoneIfMissing() {
19136
- try {
19137
- if (this.paths().shared)
19138
- return;
19139
- const v2 = path15.join(this.root, ".workit");
19140
- if (fs12.existsSync(path15.join(v2, "workspace.json")))
19141
- return;
19142
- let id = null;
19143
- try {
19144
- id = JSON.parse(fs12.readFileSync(this.paths().workspace, "utf8")).id ?? null;
19145
- } catch {}
19146
- this.writeTombstone(v2, id);
19147
- } catch {}
19148
- }
19149
19466
  initializeStorage() {
19150
19467
  const dirs = this.paths();
19151
- retryTransient(() => fs12.mkdirSync(dirs.checkout, { recursive: true }));
19152
- retryTransient(() => fs12.mkdirSync(dirs.tasks, { recursive: true }));
19153
- if (!fs12.existsSync(dirs.marker))
19468
+ retryTransient(() => fs13.mkdirSync(dirs.checkout, { recursive: true }));
19469
+ retryTransient(() => fs13.mkdirSync(dirs.tasks, { recursive: true }));
19470
+ if (!fs13.existsSync(dirs.marker))
19154
19471
  replaceFile(dirs.marker, `${JSON.stringify({ format: "workit-store", version: STORE_FORMAT, createdWith: runtimeVersion() })}
19155
19472
  `, false);
19156
- if (!dirs.shared) {
19157
- const ignore = path15.join(dirs.dir, ".gitignore");
19158
- let current = null;
19159
- try {
19160
- current = fs12.readFileSync(ignore, "utf8");
19161
- } catch {}
19162
- if (current !== `*
19163
- `)
19164
- retryTransient(() => fs12.writeFileSync(ignore, `*
19165
- `));
19166
- }
19167
- this.writeTombstoneIfMissing();
19168
19473
  }
19169
19474
  lockOptions(lockPath) {
19170
19475
  const inProcess = heldInProcess.has(lockPath);
@@ -19177,7 +19482,7 @@ class TaskReader {
19177
19482
  shouldReclaim: ({ payload, nowMs }) => {
19178
19483
  let ageMs = null;
19179
19484
  try {
19180
- ageMs = nowMs - fs12.lstatSync(lockPath).mtimeMs;
19485
+ ageMs = nowMs - fs13.lstatSync(lockPath).mtimeMs;
19181
19486
  } catch {}
19182
19487
  return classifyLockOwner(payload, ageMs, localLockHost(), TASK_STORE_LOCK).state === "stale";
19183
19488
  },
@@ -19214,7 +19519,7 @@ class TaskReader {
19214
19519
  withLock(lockPath, operation) {
19215
19520
  try {
19216
19521
  this.initializeStorage();
19217
- fs12.mkdirSync(path15.dirname(lockPath), { recursive: true });
19522
+ fs13.mkdirSync(path16.dirname(lockPath), { recursive: true });
19218
19523
  } catch (error) {
19219
19524
  return failure2("storage_error", `unable to initialize store: ${String(error)}`, {
19220
19525
  path: this.paths().dir
@@ -19254,18 +19559,18 @@ class TaskReader {
19254
19559
  lockDirWritable(lockPath) {
19255
19560
  const probe = `${lockPath}.${process.pid}.${randomUUID3()}.probe`;
19256
19561
  try {
19257
- fs12.closeSync(fs12.openSync(probe, "wx", 384));
19562
+ fs13.closeSync(fs13.openSync(probe, "wx", 384));
19258
19563
  } catch {
19259
19564
  return false;
19260
19565
  }
19261
19566
  try {
19262
- fs12.rmSync(probe, { force: true });
19567
+ fs13.rmSync(probe, { force: true });
19263
19568
  } catch {}
19264
19569
  return true;
19265
19570
  }
19266
19571
  lockHolderPresent(lockPath) {
19267
19572
  try {
19268
- fs12.lstatSync(lockPath);
19573
+ fs13.lstatSync(lockPath);
19269
19574
  return true;
19270
19575
  } catch (error) {
19271
19576
  return error?.code !== "ENOENT";
@@ -19277,12 +19582,12 @@ class TaskReader {
19277
19582
  if (isTransientWindowsError(error) && !this.lockHolderPresent(lockPath) && !this.lockDirWritable(lockPath))
19278
19583
  return failure2("storage_error", `cannot create the workit lock (${code}); no other Workit call holds it`, {
19279
19584
  path: lockPath,
19280
- guidance: `Check permissions and the read-only attribute on ${path15.dirname(lockPath)}.`
19585
+ guidance: `Check permissions and the read-only attribute on ${path16.dirname(lockPath)}.`
19281
19586
  });
19282
19587
  if (code === "EEXIST" || code === "file_lock_timeout" || code === "file_lock_stale" || isTransientWindowsError(error)) {
19283
19588
  let lock = null;
19284
19589
  try {
19285
- lock = parseMetadataLockOrNull(fs12.readFileSync(lockPath, "utf8"));
19590
+ lock = parseMetadataLockOrNull(fs13.readFileSync(lockPath, "utf8"));
19286
19591
  } catch {}
19287
19592
  return failure2("busy", `workit lock is held by another Workit call${lock ? ` (pid ${lock.pid} on ${lock.host})` : ""}; retry shortly`, {
19288
19593
  outcome: "not_started",
@@ -19312,7 +19617,7 @@ var MARKER_FIELDS = {
19312
19617
  };
19313
19618
  var isKnownMarker = (file, kind) => {
19314
19619
  try {
19315
- const value = JSON.parse(fs13.readFileSync(file, "utf8"));
19620
+ const value = JSON.parse(fs14.readFileSync(file, "utf8"));
19316
19621
  if (!isObject5(value))
19317
19622
  return false;
19318
19623
  const fields = MARKER_FIELDS[kind];
@@ -19326,35 +19631,35 @@ var isKnownMarker = (file, kind) => {
19326
19631
  }
19327
19632
  };
19328
19633
  var moveInto = (from, to) => {
19329
- if (fs13.lstatSync(from).isDirectory()) {
19634
+ if (fs14.lstatSync(from).isDirectory()) {
19330
19635
  let target = to;
19331
- if (fs13.existsSync(target) && !fs13.lstatSync(target).isDirectory())
19636
+ if (fs14.existsSync(target) && !fs14.lstatSync(target).isDirectory())
19332
19637
  target = `${to}.dir`;
19333
- fs13.mkdirSync(target, { recursive: true });
19334
- for (const name of fs13.readdirSync(from))
19335
- moveInto(path16.join(from, name), path16.join(target, name));
19336
- fs13.rmdirSync(from);
19638
+ fs14.mkdirSync(target, { recursive: true });
19639
+ for (const name of fs14.readdirSync(from))
19640
+ moveInto(path17.join(from, name), path17.join(target, name));
19641
+ fs14.rmdirSync(from);
19337
19642
  return;
19338
19643
  }
19339
19644
  let target = to;
19340
- if (fs13.existsSync(target)) {
19341
- const bytes = fs13.readFileSync(from);
19342
- if (fs13.lstatSync(target).isFile() && bytes.equals(fs13.readFileSync(target))) {
19343
- fs13.rmSync(from);
19645
+ if (fs14.existsSync(target)) {
19646
+ const bytes = fs14.readFileSync(from);
19647
+ if (fs14.lstatSync(target).isFile() && bytes.equals(fs14.readFileSync(target))) {
19648
+ fs14.rmSync(from);
19344
19649
  return;
19345
19650
  }
19346
- target = `${to}.${createHash8("sha256").update(bytes).digest("hex").slice(0, 12)}`;
19347
- if (fs13.existsSync(target)) {
19348
- fs13.rmSync(from);
19651
+ target = `${to}.${createHash9("sha256").update(bytes).digest("hex").slice(0, 12)}`;
19652
+ if (fs14.existsSync(target)) {
19653
+ fs14.rmSync(from);
19349
19654
  return;
19350
19655
  }
19351
19656
  }
19352
- fs13.mkdirSync(path16.dirname(target), { recursive: true });
19657
+ fs14.mkdirSync(path17.dirname(target), { recursive: true });
19353
19658
  try {
19354
- fs13.renameSync(from, target);
19659
+ fs14.renameSync(from, target);
19355
19660
  } catch {
19356
- fs13.copyFileSync(from, target);
19357
- fs13.rmSync(from);
19661
+ fs14.copyFileSync(from, target);
19662
+ fs14.rmSync(from);
19358
19663
  }
19359
19664
  };
19360
19665
  var now = () => new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
@@ -19417,7 +19722,7 @@ class TaskStore extends TaskReader {
19417
19722
  const moved = this.bindLocked(again.data.id, key, input.now);
19418
19723
  return moved.ok ? success(moved.data.revision, null, { task: moved.data, created: false, key }) : moved;
19419
19724
  }
19420
- const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path16.basename(this.root) || this.root;
19725
+ const label = key.kind === "branch" ? `branch ${key.branch}` : key.kind === "detached" ? "a detached HEAD" : path17.basename(this.root) || this.root;
19421
19726
  const intent = {
19422
19727
  objective: input.objective?.trim() || `Work on ${label}`,
19423
19728
  scope: { description: `the checkout (${label})`, paths: ["."], exclusions: [] },
@@ -19665,13 +19970,13 @@ class TaskStore extends TaskReader {
19665
19970
  if (!ready.ok)
19666
19971
  return ready;
19667
19972
  const dirs = this.paths();
19668
- const recovery = [path16.join(this.root, ".workit", "recovery"), path16.join(dirs.legacy, "recovery")].find((dir) => fs13.existsSync(dir)) ?? null;
19973
+ const recovery = [path17.join(this.root, ".workit", "recovery"), path17.join(dirs.legacy, "recovery")].find((dir) => fs14.existsSync(dir)) ?? null;
19669
19974
  if (recovery) {
19670
19975
  let files = 0;
19671
19976
  let bytes = 0;
19672
19977
  try {
19673
- for (const name of fs13.readdirSync(recovery)) {
19674
- const stat = fs13.lstatSync(path16.join(recovery, name));
19978
+ for (const name of fs14.readdirSync(recovery)) {
19979
+ const stat = fs14.lstatSync(path17.join(recovery, name));
19675
19980
  if (!stat.isFile())
19676
19981
  continue;
19677
19982
  files += 1;
@@ -19680,17 +19985,17 @@ class TaskStore extends TaskReader {
19680
19985
  } catch {}
19681
19986
  const remove = options.pruneRecovery === true && !dryRun;
19682
19987
  if (remove)
19683
- fs13.rmSync(recovery, { recursive: true, force: true });
19988
+ fs14.rmSync(recovery, { recursive: true, force: true });
19684
19989
  report.legacyRecovery = { path: recovery, files, bytes, removed: remove };
19685
19990
  }
19686
- if (!fs13.existsSync(dirs.tasks))
19991
+ if (!fs14.existsSync(dirs.tasks))
19687
19992
  return success(null, null, report);
19688
- const names = fs13.readdirSync(dirs.tasks).filter((name) => validId(name));
19993
+ const names = fs14.readdirSync(dirs.tasks).filter((name) => validId(name));
19689
19994
  for (const name of names) {
19690
19995
  const file = this.eventsPath(name);
19691
19996
  let size = 0;
19692
19997
  try {
19693
- size = fs13.statSync(file).size;
19998
+ size = fs14.statSync(file).size;
19694
19999
  } catch {
19695
20000
  continue;
19696
20001
  }
@@ -19718,16 +20023,16 @@ class TaskStore extends TaskReader {
19718
20023
  const references = new Set;
19719
20024
  for (const name of names)
19720
20025
  try {
19721
- for (const match of fs13.readFileSync(this.eventsPath(name), "utf8").matchAll(/"\$blob":"([0-9a-f]{64})"/g))
20026
+ for (const match of fs14.readFileSync(this.eventsPath(name), "utf8").matchAll(/"\$blob":"([0-9a-f]{64})"/g))
19722
20027
  references.add(match[1]);
19723
20028
  } catch {}
19724
- if (fs13.existsSync(dirs.blobs))
19725
- for (const name of fs13.readdirSync(dirs.blobs)) {
20029
+ if (fs14.existsSync(dirs.blobs))
20030
+ for (const name of fs14.readdirSync(dirs.blobs)) {
19726
20031
  const digest = name.replace(/\.json$/, "");
19727
- const file = path16.join(dirs.blobs, name);
20032
+ const file = path17.join(dirs.blobs, name);
19728
20033
  let stat;
19729
20034
  try {
19730
- stat = fs13.lstatSync(file);
20035
+ stat = fs14.lstatSync(file);
19731
20036
  } catch {
19732
20037
  continue;
19733
20038
  }
@@ -19738,11 +20043,11 @@ class TaskStore extends TaskReader {
19738
20043
  report.blobs.removed += 1;
19739
20044
  report.blobs.removedBytes += stat.size;
19740
20045
  if (!dryRun)
19741
- fs13.rmSync(file, { force: true });
20046
+ fs14.rmSync(file, { force: true });
19742
20047
  }
19743
20048
  return success(null, null, null);
19744
20049
  };
19745
- const swept = dryRun ? sweep() : this.withLock(path16.join(dirs.dir, "gc.lock"), sweep);
20050
+ const swept = dryRun ? sweep() : this.withLock(path17.join(dirs.dir, "gc.lock"), sweep);
19746
20051
  if (!swept.ok)
19747
20052
  return swept;
19748
20053
  const temporaryDirs = [
@@ -19750,17 +20055,17 @@ class TaskStore extends TaskReader {
19750
20055
  dirs.tasks,
19751
20056
  dirs.blobs,
19752
20057
  dirs.checkout,
19753
- ...names.map((name) => path16.join(dirs.tasks, name))
20058
+ ...names.map((name) => path17.join(dirs.tasks, name))
19754
20059
  ];
19755
20060
  for (const directory of temporaryDirs) {
19756
- if (!fs13.existsSync(directory))
20061
+ if (!fs14.existsSync(directory))
19757
20062
  continue;
19758
- for (const name of fs13.readdirSync(directory)) {
20063
+ for (const name of fs14.readdirSync(directory)) {
19759
20064
  if (!name.endsWith(".tmp") && !name.endsWith(".probe"))
19760
20065
  continue;
19761
- const file = path16.join(directory, name);
20066
+ const file = path17.join(directory, name);
19762
20067
  try {
19763
- const stat = fs13.lstatSync(file);
20068
+ const stat = fs14.lstatSync(file);
19764
20069
  if (!stat.isFile() || nowMs - stat.mtimeMs <= STALE_TEMPORARY_MS)
19765
20070
  continue;
19766
20071
  } catch {
@@ -19768,13 +20073,13 @@ class TaskStore extends TaskReader {
19768
20073
  }
19769
20074
  report.temporary.removed += 1;
19770
20075
  if (!dryRun)
19771
- fs13.rmSync(file, { force: true });
20076
+ fs14.rmSync(file, { force: true });
19772
20077
  }
19773
20078
  }
19774
20079
  return success(null, null, report);
19775
20080
  }
19776
20081
  taskLockPath(taskId) {
19777
- return path16.join(this.paths().tasks, taskId, "lock");
20082
+ return path17.join(this.paths().tasks, taskId, "lock");
19778
20083
  }
19779
20084
  settleMigrations(write) {
19780
20085
  const moved = this.adoptLocalStore();
@@ -19803,15 +20108,15 @@ class TaskStore extends TaskReader {
19803
20108
  return {
19804
20109
  read: (digest) => reader.read(digest),
19805
20110
  write: (digest, value) => {
19806
- const file = path16.join(dir, `${digest}.json`);
19807
- if (fs13.existsSync(file)) {
20111
+ const file = path17.join(dir, `${digest}.json`);
20112
+ if (fs14.existsSync(file)) {
19808
20113
  const stamp = new Date;
19809
20114
  try {
19810
- fs13.utimesSync(file, stamp, stamp);
20115
+ fs14.utimesSync(file, stamp, stamp);
19811
20116
  return;
19812
20117
  } catch {}
19813
20118
  }
19814
- fs13.mkdirSync(dir, { recursive: true });
20119
+ fs14.mkdirSync(dir, { recursive: true });
19815
20120
  replaceFile(file, JSON.stringify(value), true);
19816
20121
  }
19817
20122
  };
@@ -19905,8 +20210,8 @@ class TaskStore extends TaskReader {
19905
20210
  }
19906
20211
  }
19907
20212
  openTask(record, type, key, legacy = null) {
19908
- const dir = path16.join(this.paths().tasks, record.id);
19909
- fs13.mkdirSync(dir, { recursive: true });
20213
+ const dir = path17.join(this.paths().tasks, record.id);
20214
+ fs14.mkdirSync(dir, { recursive: true });
19910
20215
  const blobs = this.blobStore();
19911
20216
  const bound = key ? { ...key, boundAt: key.boundAt ?? new Date().toISOString() } : null;
19912
20217
  const event = this.event(record.id, 1, type, {
@@ -19958,11 +20263,11 @@ class TaskStore extends TaskReader {
19958
20263
  } catch {}
19959
20264
  if (!latest || latest.events[0]?.id !== last.id)
19960
20265
  return failure2("busy", "the task log changed during compaction; retry", { taskId });
19961
- const appended = fs13.readFileSync(file).subarray(log.end, latest.end);
20266
+ const appended = fs14.readFileSync(file).subarray(log.end, latest.end);
19962
20267
  const bytes = Buffer.concat([Buffer.from(prefix, "utf8"), appended]);
19963
20268
  replaceFile(file, bytes.toString("utf8"), true);
19964
20269
  try {
19965
- fs13.rmSync(this.snapshotPath(taskId), { force: true });
20270
+ fs14.rmSync(this.snapshotPath(taskId), { force: true });
19966
20271
  } catch {}
19967
20272
  const reloaded = this.load(taskId);
19968
20273
  if (reloaded.ok && reloaded.data)
@@ -19975,7 +20280,7 @@ class TaskStore extends TaskReader {
19975
20280
  }
19976
20281
  countEvents(file) {
19977
20282
  try {
19978
- const bytes = fs13.readFileSync(file);
20283
+ const bytes = fs14.readFileSync(file);
19979
20284
  let count = 0;
19980
20285
  for (let index = bytes.indexOf(10);index >= 0; index = bytes.indexOf(10, index + 1))
19981
20286
  count += 1;
@@ -19985,8 +20290,8 @@ class TaskStore extends TaskReader {
19985
20290
  }
19986
20291
  }
19987
20292
  withKeyLock(key, operation) {
19988
- const digest = createHash8("sha256").update(key).digest("hex").slice(0, 32);
19989
- return this.withLock(path16.join(this.paths().dir, "keys", `${digest}.lock`), operation);
20293
+ const digest = createHash9("sha256").update(key).digest("hex").slice(0, 32);
20294
+ return this.withLock(path17.join(this.paths().dir, "keys", `${digest}.lock`), operation);
19990
20295
  }
19991
20296
  bindLocked(taskId, key, timestamp) {
19992
20297
  const current = this.readWorkspace();
@@ -20127,7 +20432,7 @@ class TaskStore extends TaskReader {
20127
20432
  writeWorkspace(record) {
20128
20433
  const file = this.paths().workspace;
20129
20434
  try {
20130
- fs13.mkdirSync(path16.dirname(file), { recursive: true });
20435
+ fs14.mkdirSync(path17.dirname(file), { recursive: true });
20131
20436
  replaceFile(file, `${canonicalJson(record)}
20132
20437
  `, true);
20133
20438
  return success(null, null, null);
@@ -20153,13 +20458,13 @@ class TaskStore extends TaskReader {
20153
20458
  }
20154
20459
  migrateV2(v2) {
20155
20460
  const dirs = this.paths();
20156
- const v2Workspace = path16.join(v2, "workspace.json");
20157
- const v2Tasks = path16.join(v2, "tasks");
20158
- const legacy = path16.join(dirs.dir, "legacy", checkoutSlug(path16.dirname(v2)), "v2");
20461
+ const v2Workspace = path17.join(v2, "workspace.json");
20462
+ const v2Tasks = path17.join(v2, "tasks");
20463
+ const legacy = path17.join(dirs.dir, "legacy", checkoutSlug(path17.dirname(v2)), "v2");
20159
20464
  const raw = this.readV2Workspace(v2Workspace);
20160
20465
  if (raw === null || raw === TOMBSTONE)
20161
20466
  return success(null, null, null);
20162
- return this.withLock(dirs.checkoutLock, () => this.withLock(path16.join(v2, "metadata.lock"), () => {
20467
+ return this.withLock(dirs.checkoutLock, () => this.withLock(path17.join(v2, "metadata.lock"), () => {
20163
20468
  const workspace = this.readV2Workspace(v2Workspace);
20164
20469
  if (workspace === null || workspace === TOMBSTONE)
20165
20470
  return success(null, null, null);
@@ -20168,7 +20473,7 @@ class TaskStore extends TaskReader {
20168
20473
  return failure2("recovery_required", `cannot migrate the 2.x store at ${v2}: ${parsedWorkspace.error}; move it aside to start fresh`, { path: v2Workspace });
20169
20474
  let files = [];
20170
20475
  try {
20171
- files = fs13.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path16.join(v2Tasks, name)));
20476
+ files = fs14.readdirSync(v2Tasks).filter((name) => name.endsWith(".json") && validId(name.slice(0, -5))).filter((name) => !this.isStub(path17.join(v2Tasks, name)));
20172
20477
  } catch {}
20173
20478
  const current = this.readWorkspace();
20174
20479
  if (!current.ok)
@@ -20186,22 +20491,22 @@ class TaskStore extends TaskReader {
20186
20491
  let skipped = 0;
20187
20492
  const done = new Map;
20188
20493
  try {
20189
- fs13.mkdirSync(path16.join(legacy, "tasks"), { recursive: true });
20494
+ fs14.mkdirSync(path17.join(legacy, "tasks"), { recursive: true });
20190
20495
  for (const name of ["workspace.json", "index.json"])
20191
- if (fs13.existsSync(path16.join(v2, name)))
20192
- fs13.copyFileSync(path16.join(v2, name), path16.join(legacy, name));
20496
+ if (fs14.existsSync(path17.join(v2, name)))
20497
+ fs14.copyFileSync(path17.join(v2, name), path17.join(legacy, name));
20193
20498
  for (const name of files) {
20194
20499
  const id = name.slice(0, -5);
20195
- const file = path16.join(v2Tasks, name);
20196
- const bytes = fs13.readFileSync(file, "utf8");
20500
+ const file = path17.join(v2Tasks, name);
20501
+ const bytes = fs14.readFileSync(file, "utf8");
20197
20502
  const digest = sha256(bytes);
20198
- fs13.writeFileSync(path16.join(legacy, "tasks", name), bytes);
20503
+ fs14.writeFileSync(path17.join(legacy, "tasks", name), bytes);
20199
20504
  const parsed = this.parseRecord(bytes, taskRecordSchema, "2.x task");
20200
20505
  if (!parsed.ok || parsed.data.id !== id)
20201
20506
  return failure2("recovery_required", `cannot migrate 2.x task ${id}: ${parsed.ok ? "file name and record ID differ" : parsed.error}; move ${file} aside to continue`, { path: file });
20202
20507
  const record = { ...parsed.data, workspaceId: target.id };
20203
- const origin = { path: path16.join(legacy, "tasks", name), digest };
20204
- if (!fs13.existsSync(this.eventsPath(id))) {
20508
+ const origin = { path: path17.join(legacy, "tasks", name), digest };
20509
+ if (!fs14.existsSync(this.eventsPath(id))) {
20205
20510
  this.openTask(record, "migrated.from_v2", null, origin);
20206
20511
  migrated += 1;
20207
20512
  } else {
@@ -20236,13 +20541,13 @@ class TaskStore extends TaskReader {
20236
20541
  try {
20237
20542
  let complete = true;
20238
20543
  for (const [name, digest] of done) {
20239
- const file = path16.join(v2Tasks, name);
20240
- if (sha256(fs13.readFileSync(file, "utf8")) !== digest) {
20544
+ const file = path17.join(v2Tasks, name);
20545
+ if (sha256(fs14.readFileSync(file, "utf8")) !== digest) {
20241
20546
  complete = false;
20242
20547
  continue;
20243
20548
  }
20244
20549
  if (dirs.shared)
20245
- fs13.rmSync(file);
20550
+ fs14.rmSync(file);
20246
20551
  else
20247
20552
  replaceFile(file, this.stubFor(name.slice(0, -5)), false);
20248
20553
  }
@@ -20250,9 +20555,9 @@ class TaskStore extends TaskReader {
20250
20555
  return failure2("busy", `the 2.x store at ${v2} changed during migration; retry`, {
20251
20556
  path: v2
20252
20557
  });
20253
- fs13.rmSync(path16.join(v2, "index.json"), { force: true });
20558
+ fs14.rmSync(path17.join(v2, "index.json"), { force: true });
20254
20559
  if (dirs.shared)
20255
- fs13.rmSync(v2Workspace, { force: true });
20560
+ fs14.rmSync(v2Workspace, { force: true });
20256
20561
  else
20257
20562
  this.writeTombstone(v2, target.id);
20258
20563
  } catch (error) {
@@ -20275,49 +20580,49 @@ class TaskStore extends TaskReader {
20275
20580
  const dirs = this.paths();
20276
20581
  if (!dirs.shared)
20277
20582
  return success(null, null, null);
20278
- const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs13.existsSync(path16.join(v2, name)));
20279
- const ignore = path16.join(v2, ".gitignore");
20583
+ const present = () => CHECKOUT_LEFTOVERS.filter((name) => fs14.existsSync(path17.join(v2, name)));
20584
+ const ignore = path17.join(v2, ".gitignore");
20280
20585
  const onlyGeneratedIgnore = () => {
20281
20586
  try {
20282
- return fs13.readdirSync(v2).length === 1 && GENERATED_GITIGNORES.has(fs13.readFileSync(ignore, "utf8"));
20587
+ return fs14.readdirSync(v2).length === 1 && GENERATED_GITIGNORES.has(fs14.readFileSync(ignore, "utf8"));
20283
20588
  } catch {
20284
20589
  return false;
20285
20590
  }
20286
20591
  };
20287
20592
  if (present().length === 0 && !onlyGeneratedIgnore())
20288
20593
  return success(null, null, null);
20289
- const backup = path16.join(dirs.dir, "legacy", checkoutSlug(path16.dirname(v2)), "v2");
20594
+ const backup = path17.join(dirs.dir, "legacy", checkoutSlug(path17.dirname(v2)), "v2");
20290
20595
  return this.withLock(dirs.checkoutLock, () => {
20291
20596
  let moved = 0;
20292
20597
  try {
20293
20598
  for (const name of present()) {
20294
- const entry = path16.join(v2, name);
20599
+ const entry = path17.join(v2, name);
20295
20600
  const marker = name === "workspace.json" ? isKnownMarker(entry, "workspace") : name === "store.moved.json" && isKnownMarker(entry, "moved");
20296
- const empty = fs13.lstatSync(entry).isDirectory() && fs13.readdirSync(entry).length === 0;
20601
+ const empty = fs14.lstatSync(entry).isDirectory() && fs14.readdirSync(entry).length === 0;
20297
20602
  if (marker || empty) {
20298
- fs13.rmSync(entry, { recursive: true });
20603
+ fs14.rmSync(entry, { recursive: true });
20299
20604
  continue;
20300
20605
  }
20301
- if (name === "tasks" && fs13.lstatSync(entry).isDirectory()) {
20302
- for (const task of fs13.readdirSync(entry)) {
20303
- const file = path16.join(entry, task);
20304
- if (fs13.lstatSync(file).isFile() && isKnownMarker(file, "stub"))
20305
- fs13.rmSync(file);
20606
+ if (name === "tasks" && fs14.lstatSync(entry).isDirectory()) {
20607
+ for (const task of fs14.readdirSync(entry)) {
20608
+ const file = path17.join(entry, task);
20609
+ if (fs14.lstatSync(file).isFile() && isKnownMarker(file, "stub"))
20610
+ fs14.rmSync(file);
20306
20611
  else {
20307
- moveInto(file, path16.join(backup, "tasks", task));
20612
+ moveInto(file, path17.join(backup, "tasks", task));
20308
20613
  moved += 1;
20309
20614
  }
20310
20615
  }
20311
- fs13.rmdirSync(entry);
20616
+ fs14.rmdirSync(entry);
20312
20617
  continue;
20313
20618
  }
20314
- moveInto(entry, path16.join(backup, name));
20619
+ moveInto(entry, path17.join(backup, name));
20315
20620
  moved += 1;
20316
20621
  }
20317
20622
  if (onlyGeneratedIgnore())
20318
- fs13.rmSync(ignore);
20319
- if (fs13.readdirSync(v2).length === 0)
20320
- fs13.rmdirSync(v2);
20623
+ fs14.rmSync(ignore);
20624
+ if (fs14.readdirSync(v2).length === 0)
20625
+ fs14.rmdirSync(v2);
20321
20626
  } catch (error) {
20322
20627
  return failure2("storage_error", `cannot clear ${v2}: ${String(error)}`, { path: v2 });
20323
20628
  }
@@ -20339,7 +20644,7 @@ class TaskStore extends TaskReader {
20339
20644
  }
20340
20645
  isStub(file) {
20341
20646
  try {
20342
- const value = JSON.parse(fs13.readFileSync(file, "utf8"));
20647
+ const value = JSON.parse(fs14.readFileSync(file, "utf8"));
20343
20648
  return isObject5(value) && isObject5(value.store) && value.store.format === "workit-store";
20344
20649
  } catch {
20345
20650
  return false;
@@ -20352,23 +20657,23 @@ var isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state);
20352
20657
  var workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state);
20353
20658
 
20354
20659
  // packages/workit-core/src/core/task-evaluation.ts
20355
- import { createHash as createHash10 } from "node:crypto";
20356
- import * as fs17 from "node:fs";
20660
+ import { createHash as createHash11 } from "node:crypto";
20661
+ import * as fs18 from "node:fs";
20357
20662
  import { spawnSync as spawnSync15 } from "node:child_process";
20358
- import path22 from "node:path";
20663
+ import path23 from "node:path";
20359
20664
 
20360
20665
  // packages/workit-core/src/check-config.ts
20361
20666
  import { spawnSync as spawnSync11 } from "node:child_process";
20362
- import fs14 from "node:fs";
20363
- import path17 from "node:path";
20667
+ import fs15 from "node:fs";
20668
+ import path18 from "node:path";
20364
20669
  var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
20365
20670
  var SCRIPT_CHECK_ALIASES = { packaging: "test:packaging" };
20366
20671
  var CHECKS_FILE = ".workit/checks.json";
20367
20672
  var LEGACY_CHECKS_FILE = "workit.checks.json";
20368
20673
  function checksConfigFile(root) {
20369
- const current = path17.join(root, CHECKS_FILE);
20370
- const legacy = path17.join(root, LEGACY_CHECKS_FILE);
20371
- return !fs14.existsSync(current) && fs14.existsSync(legacy) ? legacy : current;
20674
+ const current = path18.join(root, CHECKS_FILE);
20675
+ const legacy = path18.join(root, LEGACY_CHECKS_FILE);
20676
+ return !fs15.existsSync(current) && fs15.existsSync(legacy) ? legacy : current;
20372
20677
  }
20373
20678
  var GENERATED_GITIGNORES2 = new Set([`*
20374
20679
  `, `*
@@ -20426,10 +20731,10 @@ var git3 = (cwd, args) => {
20426
20731
  return value || null;
20427
20732
  };
20428
20733
  function checkRoot(cwd) {
20429
- return path17.resolve(gitDirs(cwd)?.top ?? cwd);
20734
+ return path18.resolve(gitDirs(cwd)?.top ?? cwd);
20430
20735
  }
20431
20736
  var packageManager = (root) => {
20432
- const has = (file) => fs14.existsSync(path17.join(root, file));
20737
+ const has = (file) => fs15.existsSync(path18.join(root, file));
20433
20738
  if (has("bun.lock") || has("bun.lockb"))
20434
20739
  return "bun";
20435
20740
  if (has("pnpm-lock.yaml"))
@@ -20449,7 +20754,7 @@ var CHECK_NAME = /^[a-z0-9][a-z0-9:._-]{0,63}$/u;
20449
20754
  function detectedChecks(root) {
20450
20755
  const read = (file) => {
20451
20756
  try {
20452
- return fs14.readFileSync(path17.join(root, file), "utf8");
20757
+ return fs15.readFileSync(path18.join(root, file), "utf8");
20453
20758
  } catch {
20454
20759
  return null;
20455
20760
  }
@@ -20521,21 +20826,21 @@ function cleanupGlobs(value) {
20521
20826
  }
20522
20827
  function configFileFor(root) {
20523
20828
  const own = checksConfigFile(root);
20524
- if (fs14.existsSync(own))
20829
+ if (fs15.existsSync(own))
20525
20830
  return own;
20526
20831
  const common = git3(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
20527
- if (!common || path17.basename(common) !== ".git")
20832
+ if (!common || path18.basename(common) !== ".git")
20528
20833
  return own;
20529
- const main = path17.dirname(common);
20530
- if (path17.resolve(main) === path17.resolve(root))
20834
+ const main = path18.dirname(common);
20835
+ if (path18.resolve(main) === path18.resolve(root))
20531
20836
  return own;
20532
20837
  const shared = checksConfigFile(main);
20533
- return fs14.existsSync(shared) ? shared : own;
20838
+ return fs15.existsSync(shared) ? shared : own;
20534
20839
  }
20535
20840
  function loadCheckConfig(cwd) {
20536
20841
  const root = checkRoot(cwd);
20537
20842
  const file = configFileFor(root);
20538
- const legacy = path17.basename(file) === LEGACY_CHECKS_FILE;
20843
+ const legacy = path18.basename(file) === LEGACY_CHECKS_FILE;
20539
20844
  const label = legacy ? LEGACY_CHECKS_FILE : CHECKS_FILE;
20540
20845
  const note = legacy ? {
20541
20846
  note: `${LEGACY_CHECKS_FILE} is deprecated; move it to ${CHECKS_FILE} (workit doctor --fix)`
@@ -20551,7 +20856,7 @@ function loadCheckConfig(cwd) {
20551
20856
  });
20552
20857
  let text = null;
20553
20858
  try {
20554
- text = fs14.readFileSync(file, "utf8");
20859
+ text = fs15.readFileSync(file, "utf8");
20555
20860
  } catch (error) {
20556
20861
  if (error.code !== "ENOENT")
20557
20862
  return none(`cannot read ${label}: ${error.message}`);
@@ -20666,10 +20971,10 @@ function workitAvailable(env = process.env) {
20666
20971
  return workitOnPath;
20667
20972
  const windows = process.platform === "win32";
20668
20973
  const exts = windows ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
20669
- const dirs = (env.PATH ?? env.Path ?? "").split(path17.delimiter).filter(Boolean);
20974
+ const dirs = (env.PATH ?? env.Path ?? "").split(path18.delimiter).filter(Boolean);
20670
20975
  workitOnPath = dirs.some((dir) => exts.some((ext) => {
20671
20976
  try {
20672
- return fs14.statSync(path17.join(dir, `workit${ext}`)).isFile();
20977
+ return fs15.statSync(path18.join(dir, `workit${ext}`)).isFile();
20673
20978
  } catch {
20674
20979
  return false;
20675
20980
  }
@@ -20729,14 +21034,14 @@ var PM_RUN = new Set(["run", "run-script"]);
20729
21034
  var PYTHON_RUNNERS = new Set(["uv", "poetry", "pipenv", "pdm", "hatch", "rye"]);
20730
21035
 
20731
21036
  // packages/workit-core/src/core/policy/derive.ts
20732
- import { existsSync as existsSync8 } from "node:fs";
20733
- import path21 from "node:path";
21037
+ import { existsSync as existsSync9 } from "node:fs";
21038
+ import path22 from "node:path";
20734
21039
 
20735
21040
  // packages/workit-core/src/ledger.ts
20736
21041
  import { spawnSync as spawnSync14 } from "node:child_process";
20737
- import { createHash as createHash9, randomBytes as randomBytes3 } from "node:crypto";
20738
- import fs16 from "node:fs";
20739
- import path20 from "node:path";
21042
+ import { createHash as createHash10, randomBytes as randomBytes3 } from "node:crypto";
21043
+ import fs17 from "node:fs";
21044
+ import path21 from "node:path";
20740
21045
 
20741
21046
  // packages/workit-core/src/core/policy/bookkeeping.ts
20742
21047
  import { spawnSync as spawnSync12 } from "node:child_process";
@@ -20816,8 +21121,8 @@ function bookkeepingPaths(cwd, input) {
20816
21121
  }
20817
21122
 
20818
21123
  // packages/workit-core/src/core/policy/lane.ts
20819
- import { existsSync as existsSync7, readFileSync as readFileSync7 } from "node:fs";
20820
- import path18 from "node:path";
21124
+ import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
21125
+ import path19 from "node:path";
20821
21126
 
20822
21127
  // packages/workit-core/src/git/default-base.ts
20823
21128
  import { spawnSync as spawnSync13 } from "node:child_process";
@@ -22205,7 +22510,7 @@ function computeLane(input) {
22205
22510
  }
22206
22511
  function untrackedStat(cwd, file) {
22207
22512
  try {
22208
- const bytes = readFileSync7(path18.join(cwd, file));
22513
+ const bytes = readFileSync7(path19.join(cwd, file));
22209
22514
  if (bytes.includes(0))
22210
22515
  return { path: file, added: 0, deleted: 0, binary: true };
22211
22516
  const text = bytes.toString("utf8");
@@ -22237,7 +22542,7 @@ function cosmeticFiles(cwd, fork, head) {
22237
22542
  let after = blobs.get(entry.newBlob);
22238
22543
  if (!after && head === null && ABSENT.test(entry.newBlob))
22239
22544
  try {
22240
- after = readFileSync7(path18.join(cwd, entry.path));
22545
+ after = readFileSync7(path19.join(cwd, entry.path));
22241
22546
  } catch {
22242
22547
  after = undefined;
22243
22548
  }
@@ -22392,26 +22697,26 @@ function verdictDrift(cwd, input) {
22392
22697
  }
22393
22698
 
22394
22699
  // packages/workit-core/src/hooks/standing-signal.ts
22395
- import fs15 from "node:fs";
22396
- import path19 from "node:path";
22700
+ import fs16 from "node:fs";
22701
+ import path20 from "node:path";
22397
22702
  var gitStoreDir = (cwd) => {
22398
22703
  try {
22399
- for (let dir = path19.resolve(cwd);; dir = path19.dirname(dir)) {
22400
- const dotGit = path19.join(dir, ".git");
22401
- if (fs15.existsSync(dotGit)) {
22704
+ for (let dir = path20.resolve(cwd);; dir = path20.dirname(dir)) {
22705
+ const dotGit = path20.join(dir, ".git");
22706
+ if (fs16.existsSync(dotGit)) {
22402
22707
  let gitDir = dotGit;
22403
- if (fs15.statSync(dotGit).isFile()) {
22404
- const target = /^gitdir:\s*(.+)$/mu.exec(fs15.readFileSync(dotGit, "utf8"))?.[1]?.trim();
22708
+ if (fs16.statSync(dotGit).isFile()) {
22709
+ const target = /^gitdir:\s*(.+)$/mu.exec(fs16.readFileSync(dotGit, "utf8"))?.[1]?.trim();
22405
22710
  if (!target)
22406
22711
  return null;
22407
- gitDir = path19.resolve(dir, target);
22408
- const common = path19.join(gitDir, "commondir");
22409
- if (fs15.existsSync(common))
22410
- gitDir = path19.resolve(gitDir, fs15.readFileSync(common, "utf8").trim());
22712
+ gitDir = path20.resolve(dir, target);
22713
+ const common = path20.join(gitDir, "commondir");
22714
+ if (fs16.existsSync(common))
22715
+ gitDir = path20.resolve(gitDir, fs16.readFileSync(common, "utf8").trim());
22411
22716
  }
22412
- return path19.join(gitDir, "workit");
22717
+ return path20.join(gitDir, "workit");
22413
22718
  }
22414
- if (path19.dirname(dir) === dir)
22719
+ if (path20.dirname(dir) === dir)
22415
22720
  return null;
22416
22721
  }
22417
22722
  } catch {
@@ -22484,7 +22789,7 @@ var binaryRangeDiff = (cwd, base, head) => {
22484
22789
  return diff.ok && diff.stdout ? diff.stdout : null;
22485
22790
  };
22486
22791
  var hashOfDiff = (diff) => {
22487
- const hash = createHash9("sha256");
22792
+ const hash = createHash10("sha256");
22488
22793
  for (const line of diff.split(`
22489
22794
  `)) {
22490
22795
  if (line.startsWith("index "))
@@ -22517,14 +22822,14 @@ function cleanRebase(cwd, range) {
22517
22822
  return Boolean(tree) && tree === git4(cwd, ["rev-parse", "--verify", "-q", `${range.to}^{tree}`]);
22518
22823
  }
22519
22824
  function storeRoot(cwd) {
22520
- const location = resolveStore(path20.resolve(cwd));
22825
+ const location = resolveStore(path21.resolve(cwd));
22521
22826
  if (location instanceof Error)
22522
22827
  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");
22523
22828
  return { ok: true, value: { root: location.dir, shared: location.shared } };
22524
22829
  }
22525
22830
  function ledgerPath(cwd) {
22526
22831
  const root = storeRoot(cwd);
22527
- return root.ok ? { ok: true, value: path20.join(root.value.root, "ledger", "ledger.jsonl") } : root;
22832
+ return root.ok ? { ok: true, value: path21.join(root.value.root, "ledger", "ledger.jsonl") } : root;
22528
22833
  }
22529
22834
  var newId2 = () => `${Date.now().toString(36)}-${randomBytes3(6).toString("hex")}`;
22530
22835
  var NETWORK_FS_TYPES = new Set([
@@ -22544,25 +22849,25 @@ var onNetworkFs = (dir) => {
22544
22849
  if (process.platform !== "linux")
22545
22850
  return false;
22546
22851
  try {
22547
- return isNetworkFsType(fs16.statfsSync(dir).type);
22852
+ return isNetworkFsType(fs17.statfsSync(dir).type);
22548
22853
  } catch {
22549
22854
  return false;
22550
22855
  }
22551
22856
  };
22552
- var LOCK_WAIT_MS = 5000;
22553
- var LOCK_STALE_MS = 30000;
22857
+ var LOCK_WAIT_MS2 = 5000;
22858
+ var LOCK_STALE_MS2 = 30000;
22554
22859
  var LOCK_OWNER = "owner";
22555
22860
  var lockToken = (lock) => {
22556
22861
  try {
22557
- return fs16.readFileSync(path20.join(lock, LOCK_OWNER), "utf8");
22862
+ return fs17.readFileSync(path21.join(lock, LOCK_OWNER), "utf8");
22558
22863
  } catch {
22559
22864
  return null;
22560
22865
  }
22561
22866
  };
22562
22867
  var lockAgeMs = (lock) => {
22563
- for (const target of [path20.join(lock, LOCK_OWNER), lock]) {
22868
+ for (const target of [path21.join(lock, LOCK_OWNER), lock]) {
22564
22869
  try {
22565
- return Date.now() - fs16.statSync(target).mtimeMs;
22870
+ return Date.now() - fs17.statSync(target).mtimeMs;
22566
22871
  } catch {}
22567
22872
  }
22568
22873
  return null;
@@ -22570,14 +22875,14 @@ var lockAgeMs = (lock) => {
22570
22875
  var ledgerLock = {
22571
22876
  acquire(lock) {
22572
22877
  try {
22573
- fs16.mkdirSync(lock);
22878
+ fs17.mkdirSync(lock);
22574
22879
  } catch (error) {
22575
22880
  if (error.code === "EEXIST")
22576
22881
  return null;
22577
22882
  throw error;
22578
22883
  }
22579
22884
  const token = `${process.pid}-${randomBytes3(8).toString("hex")}`;
22580
- fs16.writeFileSync(path20.join(lock, LOCK_OWNER), token);
22885
+ fs17.writeFileSync(path21.join(lock, LOCK_OWNER), token);
22581
22886
  return token;
22582
22887
  },
22583
22888
  release(lock, token) {
@@ -22585,40 +22890,40 @@ var ledgerLock = {
22585
22890
  return false;
22586
22891
  const tomb = `${lock}.release-${randomBytes3(6).toString("hex")}`;
22587
22892
  try {
22588
- fs16.renameSync(lock, tomb);
22893
+ fs17.renameSync(lock, tomb);
22589
22894
  } catch {
22590
22895
  return false;
22591
22896
  }
22592
22897
  if (lockToken(tomb) !== token) {
22593
22898
  try {
22594
- fs16.renameSync(tomb, lock);
22899
+ fs17.renameSync(tomb, lock);
22595
22900
  } catch {}
22596
22901
  return false;
22597
22902
  }
22598
- fs16.rmSync(tomb, { recursive: true, force: true });
22903
+ fs17.rmSync(tomb, { recursive: true, force: true });
22599
22904
  return true;
22600
22905
  },
22601
22906
  token: lockToken,
22602
22907
  reap(lock, observed) {
22603
22908
  const tomb = `${lock}.reap-${randomBytes3(6).toString("hex")}`;
22604
22909
  try {
22605
- fs16.renameSync(lock, tomb);
22910
+ fs17.renameSync(lock, tomb);
22606
22911
  } catch {
22607
22912
  return false;
22608
22913
  }
22609
22914
  if (lockToken(tomb) === observed) {
22610
- fs16.rmSync(tomb, { recursive: true, force: true });
22915
+ fs17.rmSync(tomb, { recursive: true, force: true });
22611
22916
  return true;
22612
22917
  }
22613
22918
  try {
22614
- fs16.renameSync(tomb, lock);
22919
+ fs17.renameSync(tomb, lock);
22615
22920
  } catch {
22616
- fs16.rmSync(tomb, { recursive: true, force: true });
22921
+ fs17.rmSync(tomb, { recursive: true, force: true });
22617
22922
  }
22618
22923
  return false;
22619
22924
  }
22620
22925
  };
22621
- function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
22926
+ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS2)) {
22622
22927
  const lock = `${file}.lock`;
22623
22928
  const deadline = Date.now() + waitMs;
22624
22929
  let token = null;
@@ -22628,7 +22933,7 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
22628
22933
  break;
22629
22934
  const observed = lockToken(lock);
22630
22935
  const age = lockAgeMs(lock);
22631
- if (age !== null && age > LOCK_STALE_MS && ledgerLock.reap(lock, observed))
22936
+ if (age !== null && age > LOCK_STALE_MS2 && ledgerLock.reap(lock, observed))
22632
22937
  continue;
22633
22938
  if (Date.now() >= deadline)
22634
22939
  return null;
@@ -22640,14 +22945,14 @@ function withLedgerLock(file, fn, waitMs = hostAwareLockTimeout(LOCK_WAIT_MS)) {
22640
22945
  ledgerLock.release(lock, token);
22641
22946
  }
22642
22947
  }
22643
- var sha2562 = (text) => createHash9("sha256").update(text).digest("hex");
22948
+ var sha2562 = (text) => createHash10("sha256").update(text).digest("hex");
22644
22949
  var chainHash = (prevHash, body) => sha2562(`${prevHash ?? ""}
22645
22950
  ${body}`);
22646
22951
  var TAIL_BYTES = 64 * 1024;
22647
22952
  var lastLine = (fd, size) => {
22648
22953
  for (let span = Math.min(size, TAIL_BYTES);span > 0; span = Math.min(size, span * 2)) {
22649
22954
  const buffer = Buffer.alloc(span);
22650
- fs16.readSync(fd, buffer, 0, span, size - span);
22955
+ fs17.readSync(fd, buffer, 0, span, size - span);
22651
22956
  const end = buffer.lastIndexOf(10);
22652
22957
  if (end < 0) {
22653
22958
  if (span === size)
@@ -22678,32 +22983,32 @@ var lastLine = (fd, size) => {
22678
22983
  };
22679
22984
  var tighten = (fd) => {
22680
22985
  try {
22681
- if ((fs16.fstatSync(fd).mode & 63) !== 0)
22682
- fs16.fchmodSync(fd, 384);
22986
+ if ((fs17.fstatSync(fd).mode & 63) !== 0)
22987
+ fs17.fchmodSync(fd, 384);
22683
22988
  } catch {}
22684
22989
  };
22685
22990
  function appendLine(file, build, options) {
22686
22991
  const write = () => {
22687
- const fd = fs16.openSync(file, "a+", 384);
22992
+ const fd = fs17.openSync(file, "a+", 384);
22688
22993
  try {
22689
22994
  if (process.platform !== "win32")
22690
22995
  tighten(fd);
22691
- const line = build(lastLine(fd, fs16.fstatSync(fd).size));
22996
+ const line = build(lastLine(fd, fs17.fstatSync(fd).size));
22692
22997
  if (!line.ok)
22693
22998
  return line;
22694
22999
  const bytes = Buffer.from(`
22695
23000
  ${line.value}`);
22696
- const written = fs16.writeSync(fd, bytes);
23001
+ const written = fs17.writeSync(fd, bytes);
22697
23002
  if (written !== bytes.length)
22698
23003
  return err("unavailable", `short write to ${file}: ${written} of ${bytes.length} bytes; the row is torn and will be skipped`);
22699
23004
  return { ok: true, value: undefined };
22700
23005
  } finally {
22701
- fs16.closeSync(fd);
23006
+ fs17.closeSync(fd);
22702
23007
  }
22703
23008
  };
22704
23009
  try {
22705
- fs16.mkdirSync(path20.dirname(file), { recursive: true });
22706
- if (options.heldLock || !options.forceLock && !onNetworkFs(path20.dirname(file)))
23010
+ fs17.mkdirSync(path21.dirname(file), { recursive: true });
23011
+ if (options.heldLock || !options.forceLock && !onNetworkFs(path21.dirname(file)))
22707
23012
  return write();
22708
23013
  const locked = withLedgerLock(file, write);
22709
23014
  return locked ?? err("busy", `ledger lock ${file}.lock is held`, "retry; remove the .lock directory if no workit process is running");
@@ -22720,7 +23025,7 @@ var sealed = (row, id, at, previous) => {
22720
23025
  ` };
22721
23026
  };
22722
23027
  function appendRaw(cwd, row, options) {
22723
- const file = options.store ? { ok: true, value: path20.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
23028
+ const file = options.store ? { ok: true, value: path21.join(options.store.root, "ledger", "ledger.jsonl") } : ledgerPath(cwd);
22724
23029
  if (!file.ok)
22725
23030
  return file;
22726
23031
  const id = newId2();
@@ -22774,8 +23079,8 @@ function readLedgerAt(cwd, file, options) {
22774
23079
  let text = "";
22775
23080
  let stat = null;
22776
23081
  try {
22777
- stat = fs16.statSync(file);
22778
- text = fs16.readFileSync(file, "utf8");
23082
+ stat = fs17.statSync(file);
23083
+ text = fs17.readFileSync(file, "utf8");
22779
23084
  } catch (error) {
22780
23085
  if (error.code === "ENOENT")
22781
23086
  return {
@@ -22915,7 +23220,7 @@ function ledgerTampering(cwd) {
22915
23220
  if (!file.ok)
22916
23221
  return [];
22917
23222
  try {
22918
- const stat = fs16.statSync(file.value);
23223
+ const stat = fs17.statSync(file.value);
22919
23224
  const cached = tamperCache.get(file.value);
22920
23225
  if (cached && cached.size === stat.size && cached.stamp === fileStamp(stat))
22921
23226
  return cached.breaks;
@@ -23382,8 +23687,8 @@ function remoteIdentity(cwd, hop = 0) {
23382
23687
  return null;
23383
23688
  if (hop === 0 && !/^[\w+.-]+:\/\/|^[^/\\]+@[^/\\]+:/u.test(raw)) {
23384
23689
  const local = raw.replace(/^file:\/\//u, "");
23385
- const resolved = path20.isAbsolute(local) ? local : path20.resolve(cwd, local);
23386
- if (fs16.existsSync(resolved))
23690
+ const resolved = path21.isAbsolute(local) ? local : path21.resolve(cwd, local);
23691
+ if (fs17.existsSync(resolved))
23387
23692
  return remoteIdentity(resolved, 1);
23388
23693
  }
23389
23694
  const parsed = parseRemoteUrl(raw);
@@ -23403,8 +23708,8 @@ function verdictMirrorPath(cwd) {
23403
23708
  }
23404
23709
  if (!identity)
23405
23710
  return null;
23406
- const key = createHash9("sha256").update(identity).digest("hex").slice(0, 32);
23407
- return path20.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
23711
+ const key = createHash10("sha256").update(identity).digest("hex").slice(0, 32);
23712
+ return path21.join(resolveStateDir(), "verdicts", key, "ledger.jsonl");
23408
23713
  }
23409
23714
  var importedStamp = new Map;
23410
23715
  function importMirroredVerdicts(cwd, branch) {
@@ -23414,7 +23719,7 @@ function importMirroredVerdicts(cwd, branch) {
23414
23719
  return [];
23415
23720
  let stamp;
23416
23721
  try {
23417
- stamp = `${branch}\x00${fileStamp(fs16.statSync(file))}`;
23722
+ stamp = `${branch}\x00${fileStamp(fs17.statSync(file))}`;
23418
23723
  } catch {
23419
23724
  return [];
23420
23725
  }
@@ -23427,7 +23732,7 @@ function importMirroredVerdicts(cwd, branch) {
23427
23732
  const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
23428
23733
  const added = new Set;
23429
23734
  try {
23430
- fs16.mkdirSync(path20.dirname(local.value), { recursive: true });
23735
+ fs17.mkdirSync(path21.dirname(local.value), { recursive: true });
23431
23736
  } catch {
23432
23737
  return [];
23433
23738
  }
@@ -23631,7 +23936,7 @@ var productDecision = (task, ledger) => {
23631
23936
  };
23632
23937
  };
23633
23938
  var planRecorded = (task, root) => {
23634
- const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync8(path21.resolve(root, ref.path)));
23939
+ const cited = (latestJudgment(task)?.refs ?? []).find((ref) => ref.kind === "external" || ref.kind === "file" && existsSync9(path22.resolve(root, ref.path)));
23635
23940
  if (cited)
23636
23941
  return {
23637
23942
  met: true,
@@ -23697,15 +24002,15 @@ function derivedRuleStatus(task, requirement, root, ledger) {
23697
24002
  }
23698
24003
 
23699
24004
  // packages/workit-core/src/core/task-evaluation.ts
23700
- var digestBytes = (value) => createHash10("sha256").update(value).digest("hex");
23701
- var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path22.sep}`);
23702
- var relative = (root, candidate) => path22.relative(root, candidate).split(path22.sep).join("/") || ".";
24005
+ var digestBytes = (value) => createHash11("sha256").update(value).digest("hex");
24006
+ var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path23.sep}`);
24007
+ var relative = (root, candidate) => path23.relative(root, candidate).split(path23.sep).join("/") || ".";
23703
24008
  var canonicalPath = (value) => {
23704
24009
  if (typeof value !== "string" || !value)
23705
24010
  return null;
23706
24011
  if (value.includes("\\") || value.split("/").includes(".."))
23707
24012
  return null;
23708
- const normalized = path22.posix.normalize(value);
24013
+ const normalized = path23.posix.normalize(value);
23709
24014
  if (normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/"))
23710
24015
  return null;
23711
24016
  return normalized === "." ? "." : normalized.replace(/\/$/, "");
@@ -23753,21 +24058,21 @@ var gitPaths = (root) => {
23753
24058
  git: !/not a git repository/i.test(stderr)
23754
24059
  };
23755
24060
  }
23756
- const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path22.sep).join("/")) : [];
24061
+ const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path23.sep).join("/")) : [];
23757
24062
  const stagedDeleted = spawnSync15("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
23758
24063
  if (stagedDeleted.status !== 0) {
23759
24064
  const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
23760
24065
  if (!/not a git repository/i.test(stderr))
23761
24066
  return { paths, uncertain: true, git: true };
23762
24067
  } else if (stagedDeleted.stdout) {
23763
- paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path22.sep).join("/")));
24068
+ paths.push(...stagedDeleted.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path23.sep).join("/")));
23764
24069
  }
23765
24070
  return { paths: [...new Set(paths)], uncertain: false, git: true };
23766
24071
  };
23767
24072
  var walk = (root, directory, output) => {
23768
24073
  let names;
23769
24074
  try {
23770
- names = fs17.readdirSync(directory);
24075
+ names = fs18.readdirSync(directory);
23771
24076
  } catch {
23772
24077
  return true;
23773
24078
  }
@@ -23775,10 +24080,10 @@ var walk = (root, directory, output) => {
23775
24080
  for (const name of names) {
23776
24081
  if (name === ".git" || name === ".workit")
23777
24082
  continue;
23778
- const target = path22.join(directory, name);
24083
+ const target = path23.join(directory, name);
23779
24084
  let stat;
23780
24085
  try {
23781
- stat = fs17.lstatSync(target);
24086
+ stat = fs18.lstatSync(target);
23782
24087
  } catch {
23783
24088
  uncertain = true;
23784
24089
  continue;
@@ -23793,14 +24098,14 @@ var walk = (root, directory, output) => {
23793
24098
  var scopeRoots = (root, scope) => {
23794
24099
  const roots = [];
23795
24100
  for (const item of scope.paths.length ? scope.paths : ["."]) {
23796
- const target = path22.resolve(root, item);
24101
+ const target = path23.resolve(root, item);
23797
24102
  if (!inside(root, target))
23798
24103
  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` }] });
23799
24104
  let ancestor = target;
23800
- while (!fs17.existsSync(ancestor) && ancestor !== root)
23801
- ancestor = path22.dirname(ancestor);
24105
+ while (!fs18.existsSync(ancestor) && ancestor !== root)
24106
+ ancestor = path23.dirname(ancestor);
23802
24107
  try {
23803
- if (!inside(root, fs17.realpathSync(ancestor)))
24108
+ if (!inside(root, fs18.realpathSync(ancestor)))
23804
24109
  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` }] });
23805
24110
  } catch {
23806
24111
  return failure2("invalid_input", `candidate scope cannot be inspected: ${item}`);
@@ -23812,7 +24117,7 @@ var scopeRoots = (root, scope) => {
23812
24117
  function captureCandidate(root, scope, environment = []) {
23813
24118
  let checkout;
23814
24119
  try {
23815
- checkout = fs17.realpathSync(root);
24120
+ checkout = fs18.realpathSync(root);
23816
24121
  } catch {
23817
24122
  return failure2("invalid_input", "candidate root does not exist");
23818
24123
  }
@@ -23830,11 +24135,11 @@ function captureCandidate(root, scope, environment = []) {
23830
24135
  if (item === ".git" || item === ".workit")
23831
24136
  continue;
23832
24137
  names.add(item);
23833
- if (!fs17.existsSync(target))
24138
+ if (!fs18.existsSync(target))
23834
24139
  continue;
23835
24140
  let stat;
23836
24141
  try {
23837
- stat = fs17.lstatSync(target);
24142
+ stat = fs18.lstatSync(target);
23838
24143
  } catch {
23839
24144
  uncertain = true;
23840
24145
  continue;
@@ -23850,17 +24155,17 @@ function captureCandidate(root, scope, environment = []) {
23850
24155
  for (const item of [...names].toSorted()) {
23851
24156
  if (!scopeMatches(item, normalizedScope))
23852
24157
  continue;
23853
- const target = path22.join(checkout, item);
24158
+ const target = path23.join(checkout, item);
23854
24159
  try {
23855
- const stat = fs17.lstatSync(target);
24160
+ const stat = fs18.lstatSync(target);
23856
24161
  if (stat.isSymbolicLink()) {
23857
- const link = fs17.readlinkSync(target);
24162
+ const link = fs18.readlinkSync(target);
23858
24163
  files.push({ path: item, kind: "symlink", digest: digestBytes(link), executable: null });
23859
24164
  } else if (stat.isFile()) {
23860
24165
  files.push({
23861
24166
  path: item,
23862
24167
  kind: "file",
23863
- digest: digestBytes(fs17.readFileSync(target)),
24168
+ digest: digestBytes(fs18.readFileSync(target)),
23864
24169
  executable: (stat.mode & 73) !== 0
23865
24170
  });
23866
24171
  } else if (!stat.isDirectory()) {
@@ -24025,7 +24330,7 @@ var findingVerificationPasses = (findingCandidateId, evidence) => evidence.statu
24025
24330
  var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
24026
24331
  let root;
24027
24332
  try {
24028
- root = fs17.realpathSync(checkoutRoot);
24333
+ root = fs18.realpathSync(checkoutRoot);
24029
24334
  } catch {
24030
24335
  return failure2("permission_denied", "checkout root is unavailable");
24031
24336
  }
@@ -24034,23 +24339,23 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
24034
24339
  continue;
24035
24340
  if (!reference.digest)
24036
24341
  return failure2("invalid_input", "document references require a byte digest");
24037
- const target = path22.resolve(root, reference.path);
24038
- if (target !== root && !target.startsWith(`${root}${path22.sep}`))
24342
+ const target = path23.resolve(root, reference.path);
24343
+ if (target !== root && !target.startsWith(`${root}${path23.sep}`))
24039
24344
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
24040
24345
  fields: [
24041
24346
  { path: "contentRefs.path", reason: `${reference.path} is outside the checkout` }
24042
24347
  ]
24043
24348
  });
24044
24349
  try {
24045
- const below = path22.relative(root, target);
24350
+ const below = path23.relative(root, target);
24046
24351
  let current = root;
24047
- for (const segment of below.split(path22.sep)) {
24352
+ for (const segment of below.split(path23.sep)) {
24048
24353
  if (!segment)
24049
24354
  continue;
24050
- current = path22.join(current, segment);
24051
- const stat = fs17.lstatSync(current);
24052
- const real = fs17.realpathSync(current);
24053
- if (real !== root && !real.startsWith(`${root}${path22.sep}`))
24355
+ current = path23.join(current, segment);
24356
+ const stat = fs18.lstatSync(current);
24357
+ const real = fs18.realpathSync(current);
24358
+ if (real !== root && !real.startsWith(`${root}${path23.sep}`))
24054
24359
  return failure2("invalid_input", "document reference escapes checkout; cite it as an external file:// reference instead", {
24055
24360
  fields: [
24056
24361
  {
@@ -24066,7 +24371,7 @@ var verifyDecisionContentAtRoot = (checkoutRoot, binding) => {
24066
24371
  if (current !== target && !stat.isDirectory())
24067
24372
  return failure2("invalid_input", "document reference ancestor is not a directory");
24068
24373
  }
24069
- if (digestBytes(fs17.readFileSync(target)) !== reference.digest)
24374
+ if (digestBytes(fs18.readFileSync(target)) !== reference.digest)
24070
24375
  return failure2("permission_denied", "decision document bytes have changed");
24071
24376
  } catch {
24072
24377
  return failure2("invalid_input", "decision document is unavailable");
@@ -24415,8 +24720,8 @@ function briefInspectResult(request, result) {
24415
24720
  }
24416
24721
 
24417
24722
  // packages/workit-core/src/core/model-fallback.ts
24418
- import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
24419
- import path23 from "node:path";
24723
+ import { mkdirSync as mkdirSync5, readFileSync as readFileSync9, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "node:fs";
24724
+ import path24 from "node:path";
24420
24725
  var LIMITS_FILE = "model-limits.json";
24421
24726
  var DEFAULT_LIMIT_WINDOW_MS = 5 * 3600000;
24422
24727
  var KEEP_MS = 9 * 86400000;
@@ -24439,7 +24744,7 @@ var providerOf = (model, host) => {
24439
24744
  return null;
24440
24745
  };
24441
24746
  var empty = () => ({ exhausted: {}, seen: {}, redispatched: {} });
24442
- var storePath = (stateDir) => path23.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
24747
+ var storePath = (stateDir) => path24.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
24443
24748
  var readStore = (stateDir) => {
24444
24749
  try {
24445
24750
  const parsed = JSON.parse(readFileSync9(storePath(stateDir), "utf8"));
@@ -24856,26 +25161,26 @@ var exportDigest = (bundle) => sha256({
24856
25161
  task: bundle.task
24857
25162
  });
24858
25163
  // packages/workit-core/src/autonomy.ts
24859
- import { closeSync as closeSync2, copyFileSync as copyFileSync2, existsSync as existsSync11, openSync as openSync2 } from "node:fs";
24860
- import path27 from "node:path";
25164
+ import { closeSync as closeSync2, copyFileSync as copyFileSync2, existsSync as existsSync12, openSync as openSync2 } from "node:fs";
25165
+ import path28 from "node:path";
24861
25166
 
24862
25167
  // packages/workit-core/src/core/eval-world.ts
24863
- import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
24864
- import os5 from "node:os";
24865
- import path24 from "node:path";
25168
+ import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
25169
+ import os6 from "node:os";
25170
+ import path25 from "node:path";
24866
25171
  var EVAL_WORLD_ENV = "WORKIT_EVAL_WORLD";
24867
25172
  var EVAL_WORLD_MARKER = ".workit-eval-world";
24868
25173
  var inside2 = (dir, file) => {
24869
- const rel = path24.relative(dir, file);
24870
- return !rel.startsWith("..") && !path24.isAbsolute(rel);
25174
+ const rel = path25.relative(dir, file);
25175
+ return !rel.startsWith("..") && !path25.isAbsolute(rel);
24871
25176
  };
24872
25177
  var evalWorld = (cwd) => {
24873
25178
  const raw = process.env[EVAL_WORLD_ENV];
24874
- if (!raw || !path24.isAbsolute(raw))
25179
+ if (!raw || !path25.isAbsolute(raw))
24875
25180
  return null;
24876
25181
  try {
24877
- const world = realpathSync6(raw);
24878
- return inside2(realpathSync6(os5.tmpdir()), world) && inside2(world, realpathSync6(cwd)) && existsSync10(path24.join(world, EVAL_WORLD_MARKER)) ? world : null;
25182
+ const world = realpathSync7(raw);
25183
+ return inside2(realpathSync7(os6.tmpdir()), world) && inside2(world, realpathSync7(cwd)) && existsSync11(path25.join(world, EVAL_WORLD_MARKER)) ? world : null;
24879
25184
  } catch {
24880
25185
  return null;
24881
25186
  }
@@ -24883,16 +25188,16 @@ var evalWorld = (cwd) => {
24883
25188
  var evalWorldEntry = (cwd) => {
24884
25189
  const world = evalWorld(cwd);
24885
25190
  try {
24886
- return world ? loadWorkspacesFrom(path24.join(world, "config"))[0] ?? null : null;
25191
+ return world ? loadWorkspacesFrom(path25.join(world, "config"))[0] ?? null : null;
24887
25192
  } catch {
24888
25193
  return null;
24889
25194
  }
24890
25195
  };
24891
25196
 
24892
25197
  // packages/workit-core/src/core/grant-seal.ts
24893
- import { createHash as createHash11 } from "node:crypto";
25198
+ import { createHash as createHash12 } from "node:crypto";
24894
25199
  import { readFileSync as readFileSync10 } from "node:fs";
24895
- import path25 from "node:path";
25200
+ import path26 from "node:path";
24896
25201
  var SEAL_FILE = "workspaces.json.seal";
24897
25202
  var SEAL_VERSION = 1;
24898
25203
  var SEAL_COMMAND = "workit workspace seal";
@@ -24926,15 +25231,15 @@ var sealProjection = (entries) => entries.map((entry) => {
24926
25231
  youtrack: pick2(all.youtrack, ["writes", "autoHosts"])
24927
25232
  }, ENTRY_KEYS);
24928
25233
  });
24929
- 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);
24930
- var sealDigest = (projection) => createHash11("sha256").update(canonical3(projection)).digest("hex");
25234
+ 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);
25235
+ var sealDigest = (projection) => createHash12("sha256").update(canonical4(projection)).digest("hex");
24931
25236
  var broken = (reason, sealed = null) => ({
24932
25237
  state: "broken",
24933
25238
  reason,
24934
25239
  sealed
24935
25240
  });
24936
25241
  function checkSeal(dir) {
24937
- const file = path25.join(dir, SEAL_FILE);
25242
+ const file = path26.join(dir, SEAL_FILE);
24938
25243
  let seal;
24939
25244
  try {
24940
25245
  seal = JSON.parse(readFileSync10(file, "utf8"));
@@ -24957,8 +25262,8 @@ function checkSeal(dir) {
24957
25262
  import { spawnSync as spawnSync16 } from "node:child_process";
24958
25263
 
24959
25264
  // packages/workit-core/src/forge/exec.ts
24960
- import fs18 from "node:fs";
24961
- import path26 from "node:path";
25265
+ import fs19 from "node:fs";
25266
+ import path27 from "node:path";
24962
25267
 
24963
25268
  // packages/workit-core/src/forge/redact.ts
24964
25269
  var NAME = "[A-Za-z0-9_.-]";
@@ -24971,13 +25276,13 @@ var ANSI = new RegExp(String.raw`\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007\u0
24971
25276
  // packages/workit-core/src/forge/exec.ts
24972
25277
  var MAX_BUFFER2 = 64 * 1024 * 1024;
24973
25278
  function findExecutable(bin, env) {
24974
- const dirs = (env.PATH ?? env.Path ?? "").split(path26.delimiter).filter(Boolean);
25279
+ const dirs = (env.PATH ?? env.Path ?? "").split(path27.delimiter).filter(Boolean);
24975
25280
  const exts = process.platform === "win32" ? [".exe"] : [""];
24976
25281
  for (const dir of dirs)
24977
25282
  for (const ext of exts) {
24978
- const candidate = path26.join(dir, `${bin}${ext}`);
25283
+ const candidate = path27.join(dir, `${bin}${ext}`);
24979
25284
  try {
24980
- const stat = fs18.statSync(candidate);
25285
+ const stat = fs19.statSync(candidate);
24981
25286
  if (stat.isFile())
24982
25287
  return candidate;
24983
25288
  } catch {}
@@ -25032,7 +25337,7 @@ var accountHomeDir = () => {
25032
25337
  };
25033
25338
  var deniedFile = (dir) => {
25034
25339
  for (const name of ["workspaces.json", SEAL_FILE]) {
25035
- const file = path27.join(dir, name);
25340
+ const file = path28.join(dir, name);
25036
25341
  try {
25037
25342
  closeSync2(openSync2(file, "r"));
25038
25343
  } catch (error) {
@@ -25054,7 +25359,7 @@ var accountUnread = () => {
25054
25359
  if (dir === null)
25055
25360
  return NO_ACCOUNT;
25056
25361
  const file = deniedFile(dir);
25057
- return file === null ? null : `the account's ${path27.basename(file)} cannot be read (permission denied), so it reads as no workspace entries: no grants, no models, the D4 defaults apply`;
25362
+ return file === null ? null : `the account's ${path28.basename(file)} cannot be read (permission denied), so it reads as no workspace entries: no grants, no models, the D4 defaults apply`;
25058
25363
  };
25059
25364
  var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
25060
25365
  var fileSource = (dir = accountDir()) => ({
@@ -25075,7 +25380,7 @@ var NO_SEAL_NOTE = `workspaces.json has no seal yet (${SEAL_COMMAND} has never r
25075
25380
  var sealNote = (seal = sealOf()) => seal.state === "broken" ? `workspaces.json does not match its seal (${seal.reason}), so grants, endpoint, verification and youtrack.writes are the stricter of their current and last sealed values; ${SEAL_UNBLOCK}` : null;
25076
25381
  var shownGrantsDir = () => {
25077
25382
  const world = evalWorld(process.cwd());
25078
- return world ? path27.join(world, "config") : accountDir();
25383
+ return world ? path28.join(world, "config") : accountDir();
25079
25384
  };
25080
25385
  var benchWorld = (cwd) => {
25081
25386
  const entry = evalWorldEntry(cwd);
@@ -25099,10 +25404,10 @@ var grantsOverride = () => {
25099
25404
  const shown = shownGrantsDir();
25100
25405
  if (shown === null)
25101
25406
  return accountUnread() ?? NO_ACCOUNT;
25102
- const configured = path27.resolve(resolveConfigDir());
25103
- return configured === path27.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 ${path27.join(grantsDir(), "workspaces.json")}, and under a redirect they never exceed the D4 defaults`;
25407
+ const configured = path28.resolve(resolveConfigDir());
25408
+ return configured === path28.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 ${path28.join(grantsDir(), "workspaces.json")}, and under a redirect they never exceed the D4 defaults`;
25104
25409
  };
25105
- 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 ${path27.join(grantsDir(), "workspaces.json")}`;
25410
+ 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 ${path28.join(grantsDir(), "workspaces.json")}`;
25106
25411
  var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
25107
25412
  var DEFAULT_GRANTS = Object.freeze({
25108
25413
  push: true,
@@ -25503,7 +25808,7 @@ var BRANCH_RENAME = new Set(["-m", "-M", "--move", "-c", "-C", "--copy"]);
25503
25808
  var WORKTREE_VALUES = new Set(["--reason"]);
25504
25809
  var FETCH_VALUES = new Set(["--depth", "--deepen", "--shallow-since", "--shallow-exclude", "--refmap", "-j", "--jobs"].concat(["--upload-pack", "-o", "--server-option", "--negotiation-tip", "--filter"]).concat(["--recurse-submodules-default", "--submodule-prefix", "-s", "--strategy", "-X"]).concat(["--strategy-option"]));
25505
25810
  // packages/workit-core/src/core/task-engine.ts
25506
- import { realpathSync as realpathSync8 } from "node:fs";
25811
+ import { realpathSync as realpathSync9 } from "node:fs";
25507
25812
 
25508
25813
  // packages/workit-core/src/core/policy-resolver.ts
25509
25814
  function resolvePolicy(input) {
@@ -25752,12 +26057,12 @@ var judgeInputSummary = (raw) => {
25752
26057
  };
25753
26058
 
25754
26059
  // packages/workit-core/src/core/task-view.ts
25755
- import { realpathSync as realpathSync7 } from "node:fs";
26060
+ import { realpathSync as realpathSync8 } from "node:fs";
25756
26061
  var environment = () => [];
25757
26062
  var sameSession2 = (value, context) => typeof value === "object" && value !== null && value.kind === "host" && value.host === context.caller.host && value.handle === context.caller.actor;
25758
26063
  function contextRootError(store, context) {
25759
26064
  try {
25760
- realpathSync7(context.root);
26065
+ realpathSync8(context.root);
25761
26066
  const root = checkoutRootOf(context.root);
25762
26067
  if (root !== store.root && !sameDirectoryIdentity(root, store.root))
25763
26068
  return failure2("invalid_input", "operation context root does not match the task store root");
@@ -27227,7 +27532,7 @@ class WorkitCore {
27227
27532
  if (view.task.workspaceId !== view.workspace.id)
27228
27533
  return failure2("invalid_input", "task and workspace bindings are invalid");
27229
27534
  try {
27230
- if (realpathSync8(view.workspace.root) !== this.store.root)
27535
+ if (realpathSync9(view.workspace.root) !== this.store.root)
27231
27536
  return failure2("invalid_input", "task view root does not match the task store");
27232
27537
  } catch {
27233
27538
  return failure2("invalid_input", "task view root cannot be resolved");
@@ -27478,8 +27783,8 @@ class WorkitCore {
27478
27783
  }
27479
27784
  // packages/workit-core/src/core/repo-context.ts
27480
27785
  import { spawnSync as spawnSync17 } from "node:child_process";
27481
- import { existsSync as existsSync12, readFileSync as readFileSync11, readdirSync as readdirSync4 } from "node:fs";
27482
- import path28 from "node:path";
27786
+ import { existsSync as existsSync13, readFileSync as readFileSync11, readdirSync as readdirSync4 } from "node:fs";
27787
+ import path29 from "node:path";
27483
27788
  var isSafeContextRange = (value) => value.length <= 4096 && (() => {
27484
27789
  try {
27485
27790
  gitRevisionParts(value);
@@ -27623,13 +27928,13 @@ var findPrTemplate = (cwd) => {
27623
27928
  for (const rel of PR_TEMPLATE_FILES) {
27624
27929
  const parts = rel.split("/");
27625
27930
  const base = parts[parts.length - 1];
27626
- const dir = parts.length > 1 ? path28.join(cwd, ...parts.slice(0, -1)) : cwd;
27931
+ const dir = parts.length > 1 ? path29.join(cwd, ...parts.slice(0, -1)) : cwd;
27627
27932
  const actual = probeCaseInsensitive(dir, base);
27628
27933
  if (actual)
27629
27934
  return [...parts.slice(0, -1), actual].join("/");
27630
27935
  }
27631
27936
  for (const rel of PR_TEMPLATE_DIRS) {
27632
- const only = singleMarkdown(path28.join(cwd, ...rel.split("/")));
27937
+ const only = singleMarkdown(path29.join(cwd, ...rel.split("/")));
27633
27938
  if (only)
27634
27939
  return `${rel}/${only}`;
27635
27940
  }
@@ -27659,8 +27964,8 @@ var diffStatForRange = (cwd, range) => {
27659
27964
  return runGit(cwd, ["diff", "--stat", "--"]).stdout;
27660
27965
  };
27661
27966
  var packageScripts = (cwd, keys) => {
27662
- const pkgPath = path28.join(cwd, "package.json");
27663
- if (!existsSync12(pkgPath))
27967
+ const pkgPath = path29.join(cwd, "package.json");
27968
+ if (!existsSync13(pkgPath))
27664
27969
  return [];
27665
27970
  try {
27666
27971
  const pkg = JSON.parse(readFileSync11(pkgPath, "utf8"));
@@ -27685,9 +27990,9 @@ var documentationFiles = (cwd) => {
27685
27990
  if (entry.isDirectory()) {
27686
27991
  if (excluded.has(entry.name))
27687
27992
  continue;
27688
- walk(path28.join(dir, entry.name), depth + 1);
27993
+ walk(path29.join(dir, entry.name), depth + 1);
27689
27994
  } else if (entry.isFile() && (entry.name === "README.md" || entry.name.endsWith(".md"))) {
27690
- matches.push("./" + path28.relative(cwd, path28.join(dir, entry.name)).replaceAll("\\", "/"));
27995
+ matches.push("./" + path29.relative(cwd, path29.join(dir, entry.name)).replaceAll("\\", "/"));
27691
27996
  }
27692
27997
  }
27693
27998
  };
@@ -27695,7 +28000,7 @@ var documentationFiles = (cwd) => {
27695
28000
  return matches.toSorted().slice(0, 200);
27696
28001
  };
27697
28002
  var readTrimmed2 = (file, maxLines) => {
27698
- if (!existsSync12(file))
28003
+ if (!existsSync13(file))
27699
28004
  return "";
27700
28005
  const lines = readFileSync11(file, "utf8").split(`
27701
28006
  `);
@@ -27703,7 +28008,7 @@ var readTrimmed2 = (file, maxLines) => {
27703
28008
  `);
27704
28009
  };
27705
28010
  function prReadyContext(root, range) {
27706
- const cwd = path28.resolve(repoRoot(root));
28011
+ const cwd = path29.resolve(repoRoot(root));
27707
28012
  if (range !== undefined && !isResolvableContextRange(cwd, range))
27708
28013
  return invalidRange(cwd);
27709
28014
  let stdout = "";
@@ -27761,7 +28066,7 @@ ${status.stderr}` : "");
27761
28066
  stdout += `template_path: ${template}
27762
28067
 
27763
28068
  `;
27764
- stdout += readTrimmed2(path28.join(cwd, template), 220);
28069
+ stdout += readTrimmed2(path29.join(cwd, template), 220);
27765
28070
  } else {
27766
28071
  stdout += `template_path: none
27767
28072
 
@@ -27771,7 +28076,7 @@ ${status.stderr}` : "");
27771
28076
  stdout += `
27772
28077
  `;
27773
28078
  stdout += printSection("Recent Validation Signals");
27774
- if (existsSync12(path28.join(cwd, "package.json"))) {
28079
+ if (existsSync13(path29.join(cwd, "package.json"))) {
27775
28080
  stdout += `package.json detected. Common scripts:
27776
28081
  `;
27777
28082
  const found = packageScripts(cwd, ["lint", "format:check", "test", "build"]);
@@ -27780,7 +28085,7 @@ ${status.stderr}` : "");
27780
28085
  `) + `
27781
28086
  `;
27782
28087
  }
27783
- if (existsSync12(path28.join(cwd, "Cargo.toml")) || existsSync12(path28.join(cwd, "src-tauri/Cargo.toml"))) {
28088
+ if (existsSync13(path29.join(cwd, "Cargo.toml")) || existsSync13(path29.join(cwd, "src-tauri/Cargo.toml"))) {
27784
28089
  stdout += `Rust project detected.
27785
28090
  `;
27786
28091
  }
@@ -27813,7 +28118,7 @@ var CHANGELOG_RULES = `- Use an [Unreleased] section.
27813
28118
  - Apply with the host-native editor, preserving the repository changelog conventions.
27814
28119
  - If Unreleased already has duplicate category headings, normalize_only first.`;
27815
28120
  function changelogContext(root, range) {
27816
- const cwd = path28.resolve(repoRoot(root));
28121
+ const cwd = path29.resolve(repoRoot(root));
27817
28122
  if (range !== undefined && !isResolvableContextRange(cwd, range))
27818
28123
  return invalidRange(cwd);
27819
28124
  const resolvedRange = rangeArgOrDefault(range, cwd);
@@ -27831,8 +28136,8 @@ function changelogContext(root, range) {
27831
28136
  stdout += CHANGELOG_RULES + `
27832
28137
  `;
27833
28138
  stdout += printSection("Existing CHANGELOG.md");
27834
- const changelogPath = path28.join(cwd, "CHANGELOG.md");
27835
- if (existsSync12(changelogPath)) {
28139
+ const changelogPath = path29.join(cwd, "CHANGELOG.md");
28140
+ if (existsSync13(changelogPath)) {
27836
28141
  stdout += readTrimmed2(changelogPath, 260) + `
27837
28142
  `;
27838
28143
  } else {
@@ -27851,7 +28156,7 @@ function changelogContext(root, range) {
27851
28156
  return { stdout, stderr: "", exitCode: 0, cwd };
27852
28157
  }
27853
28158
  function docsRefreshContext(root, range) {
27854
- const cwd = path28.resolve(repoRoot(root));
28159
+ const cwd = path29.resolve(repoRoot(root));
27855
28160
  if (range !== undefined && !isResolvableContextRange(cwd, range))
27856
28161
  return invalidRange(cwd);
27857
28162
  const resolvedRange = rangeArgOrDefault(range, cwd);
@@ -27873,8 +28178,8 @@ function docsRefreshContext(root, range) {
27873
28178
  `) + `
27874
28179
  `;
27875
28180
  stdout += printSection("README Preview");
27876
- const readme = path28.join(cwd, "README.md");
27877
- if (existsSync12(readme)) {
28181
+ const readme = path29.join(cwd, "README.md");
28182
+ if (existsSync13(readme)) {
27878
28183
  stdout += readTrimmed2(readme, 220) + `
27879
28184
  `;
27880
28185
  } else {
@@ -27882,8 +28187,8 @@ function docsRefreshContext(root, range) {
27882
28187
  `;
27883
28188
  }
27884
28189
  stdout += printSection("Package Scripts");
27885
- const pkgPath = path28.join(cwd, "package.json");
27886
- if (existsSync12(pkgPath)) {
28190
+ const pkgPath = path29.join(cwd, "package.json");
28191
+ if (existsSync13(pkgPath)) {
27887
28192
  try {
27888
28193
  const pkg = JSON.parse(readFileSync11(pkgPath, "utf8"));
27889
28194
  stdout += JSON.stringify({ name: pkg.name, version: pkg.version, scripts: pkg.scripts }, null, 2) + `
@@ -27896,7 +28201,7 @@ function docsRefreshContext(root, range) {
27896
28201
  return { stdout, stderr: "", exitCode: 0, cwd };
27897
28202
  }
27898
28203
  function releaseNotesContext(root, rangeOrTag) {
27899
- const cwd = path28.resolve(repoRoot(root));
28204
+ const cwd = path29.resolve(repoRoot(root));
27900
28205
  if (!rangeOrTag) {
27901
28206
  return {
27902
28207
  stdout: "",
@@ -27939,7 +28244,7 @@ function releaseNotesContext(root, rangeOrTag) {
27939
28244
  `;
27940
28245
  stdout += printSection("Existing Release Files");
27941
28246
  for (const rel of ["CHANGELOG.md", "RELEASE_NOTES.md", ".github/releases.md"]) {
27942
- if (existsSync12(path28.join(cwd, rel)))
28247
+ if (existsSync13(path29.join(cwd, rel)))
27943
28248
  stdout += rel + `
27944
28249
  `;
27945
28250
  }
@@ -27970,8 +28275,8 @@ function releaseNotesContext(root, rangeOrTag) {
27970
28275
  import { spawnSync as spawnSync19 } from "node:child_process";
27971
28276
 
27972
28277
  // packages/workit-core/src/core/pr-create.ts
27973
- import fs19 from "node:fs";
27974
- import path29 from "node:path";
28278
+ import fs20 from "node:fs";
28279
+ import path30 from "node:path";
27975
28280
  import { spawnSync as spawnSync18 } from "node:child_process";
27976
28281
  // packages/workit-core/src/forge/pr-body.ts
27977
28282
  function parseGhIssue(value) {
@@ -27991,13 +28296,13 @@ var LOCAL = bounded(20000);
27991
28296
  var NETWORK = bounded(60000);
27992
28297
  function whichOnPath(tool) {
27993
28298
  const names = process.platform === "win32" ? [tool, `${tool}.exe`, `${tool}.cmd`] : [tool];
27994
- for (const dir of (process.env.PATH ?? "").split(path29.delimiter)) {
28299
+ for (const dir of (process.env.PATH ?? "").split(path30.delimiter)) {
27995
28300
  if (!dir)
27996
28301
  continue;
27997
28302
  for (const name of names) {
27998
- const candidate = path29.join(dir, name);
28303
+ const candidate = path30.join(dir, name);
27999
28304
  try {
28000
- fs19.accessSync(candidate, fs19.constants.X_OK);
28305
+ fs20.accessSync(candidate, fs20.constants.X_OK);
28001
28306
  return candidate;
28002
28307
  } catch {}
28003
28308
  }
@@ -28115,8 +28420,8 @@ var fetchGitLabIssueBody = async (ref, root, deps = {}) => {
28115
28420
  };
28116
28421
 
28117
28422
  // packages/workit-core/src/core/youtrack.ts
28118
- import fs20 from "node:fs";
28119
- import path30 from "node:path";
28423
+ import fs21 from "node:fs";
28424
+ import path31 from "node:path";
28120
28425
 
28121
28426
  // packages/workit-core/src/core/templates.ts
28122
28427
  var repoRoot2 = assetRoot();
@@ -28128,14 +28433,14 @@ var resolveWorkspaceRoot = (explicit) => explicit || process.cwd();
28128
28433
 
28129
28434
  // packages/workit-core/src/core/youtrack.ts
28130
28435
  var ISSUE_RE = /^[A-Z][A-Z0-9_]*-\d+$/;
28131
- var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path30.join(resolveConfigDir(), "youtrack.json");
28436
+ var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path31.join(resolveConfigDir(), "youtrack.json");
28132
28437
  var readYouTrackContextConfig = () => {
28133
28438
  const cfgPath = youTrackReadOnlyConfigPath();
28134
- if (!fs20.existsSync(cfgPath))
28439
+ if (!fs21.existsSync(cfgPath))
28135
28440
  return { data: {} };
28136
28441
  let parsed;
28137
28442
  try {
28138
- parsed = JSON.parse(fs20.readFileSync(cfgPath, "utf8"));
28443
+ parsed = JSON.parse(fs21.readFileSync(cfgPath, "utf8"));
28139
28444
  } catch {
28140
28445
  return { error: "YouTrack configuration is unavailable" };
28141
28446
  }
@@ -28206,9 +28511,9 @@ function resolveYouTrackFromPaths(spec_path, plan_path, workspace_root) {
28206
28511
  } catch {
28207
28512
  continue;
28208
28513
  }
28209
- if (!fs20.existsSync(full))
28514
+ if (!fs21.existsSync(full))
28210
28515
  continue;
28211
- const text = fs20.readFileSync(full, "utf8");
28516
+ const text = fs21.readFileSync(full, "utf8");
28212
28517
  const m = text.match(/^\*\*YouTrack:\*\*\s*`?([A-Z]+-\d+)`?/m);
28213
28518
  if (m)
28214
28519
  return m[1];
@@ -28480,22 +28785,22 @@ function resolveGitRevision(root, value) {
28480
28785
  }
28481
28786
  }
28482
28787
  function resolveInside(root, candidate) {
28483
- const base = realpathSync9(root);
28484
- const target = path31.resolve(base, candidate);
28485
- if (target !== base && !target.startsWith(base + path31.sep)) {
28788
+ const base = realpathSync10(root);
28789
+ const target = path32.resolve(base, candidate);
28790
+ if (target !== base && !target.startsWith(base + path32.sep)) {
28486
28791
  throw new Error("path must stay inside repository root");
28487
28792
  }
28488
28793
  let ancestor = target;
28489
- while (!existsSync13(ancestor))
28490
- ancestor = path31.dirname(ancestor);
28491
- const canonicalAncestor = realpathSync9(ancestor);
28492
- if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base + path31.sep)) {
28794
+ while (!existsSync14(ancestor))
28795
+ ancestor = path32.dirname(ancestor);
28796
+ const canonicalAncestor = realpathSync10(ancestor);
28797
+ if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base + path32.sep)) {
28493
28798
  throw new Error("path must stay inside repository root");
28494
28799
  }
28495
28800
  return target;
28496
28801
  }
28497
28802
  function run2(root, executable, args, env = {}) {
28498
- const cwd = realpathSync9(root);
28803
+ const cwd = realpathSync10(root);
28499
28804
  const result = spawnSync20(executable, args, {
28500
28805
  cwd,
28501
28806
  encoding: "utf8",
@@ -28510,18 +28815,18 @@ function run2(root, executable, args, env = {}) {
28510
28815
  }
28511
28816
 
28512
28817
  // packages/workit-core/src/core/cli-locate.ts
28513
- import { closeSync as closeSync3, existsSync as existsSync14, openSync as openSync3, readSync } from "node:fs";
28514
- import path32 from "node:path";
28818
+ import { closeSync as closeSync3, existsSync as existsSync15, openSync as openSync3, readSync } from "node:fs";
28819
+ import path33 from "node:path";
28515
28820
  var LAUNCHER_MARKER = "workit-owned-launcher";
28516
28821
  var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
28517
28822
  var installRoot = (env, platform = process.platform) => {
28518
28823
  if (env.WORKIT_INSTALL_ROOT)
28519
28824
  return env.WORKIT_INSTALL_ROOT;
28520
28825
  const data = dataDir(env, platform);
28521
- return platform === "win32" ? path32.join(data, "install") : data;
28826
+ return platform === "win32" ? path33.join(data, "install") : data;
28522
28827
  };
28523
- var ownedLauncherPath = (env, platform = process.platform) => path32.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
28524
- var ownedCurrentEntry = (env, platform = process.platform) => path32.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
28828
+ var ownedLauncherPath = (env, platform = process.platform) => path33.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
28829
+ var ownedCurrentEntry = (env, platform = process.platform) => path33.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
28525
28830
  var head = (file) => {
28526
28831
  let fd;
28527
28832
  try {
@@ -28539,7 +28844,7 @@ var head = (file) => {
28539
28844
  var locateWorkitCli = (options = {}) => {
28540
28845
  const env = options.env ?? process.env;
28541
28846
  const platform = options.platform ?? process.platform;
28542
- const exists = options.exists ?? existsSync14;
28847
+ const exists = options.exists ?? existsSync15;
28543
28848
  const read = options.read ?? head;
28544
28849
  const node = options.node ?? process.execPath;
28545
28850
  const launcher = ownedLauncherPath(env, platform);
@@ -28548,7 +28853,7 @@ var locateWorkitCli = (options = {}) => {
28548
28853
  source: "owned-launcher",
28549
28854
  command: launcher,
28550
28855
  args: [],
28551
- binDir: path32.dirname(launcher)
28856
+ binDir: path33.dirname(launcher)
28552
28857
  };
28553
28858
  const current = ownedCurrentEntry(env, platform);
28554
28859
  if (exists(current))
@@ -28577,7 +28882,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
28577
28882
  if (located.binDir) {
28578
28883
  const key = pathKey(env);
28579
28884
  const delimiter = platform === "win32" ? ";" : ":";
28580
- const same = (dir) => platform === "win32" ? path32.win32.normalize(dir).toLowerCase() === path32.win32.normalize(located.binDir).toLowerCase() : path32.posix.normalize(dir) === path32.posix.normalize(located.binDir);
28885
+ const same = (dir) => platform === "win32" ? path33.win32.normalize(dir).toLowerCase() === path33.win32.normalize(located.binDir).toLowerCase() : path33.posix.normalize(dir) === path33.posix.normalize(located.binDir);
28581
28886
  const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
28582
28887
  patch[key] = [located.binDir, ...rest].join(delimiter);
28583
28888
  }
@@ -28601,8 +28906,8 @@ var SUPPORT_MATRIX = {
28601
28906
  };
28602
28907
 
28603
28908
  // packages/workit-mcp/src/server.ts
28604
- import { existsSync as existsSync15, readFileSync as readFileSync12, realpathSync as realpathSync10 } from "node:fs";
28605
- import path33 from "node:path";
28909
+ import { existsSync as existsSync16, readFileSync as readFileSync12, realpathSync as realpathSync11 } from "node:fs";
28910
+ import path34 from "node:path";
28606
28911
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
28607
28912
  function isZ4Schema(s) {
28608
28913
  const schema = s;
@@ -30998,11 +31303,11 @@ var changedSourcesSinceLoad = (marker) => {
30998
31303
  };
30999
31304
 
31000
31305
  // packages/workit-core/src/hooks/repeat-failure.ts
31001
- import { createHash as createHash12 } from "node:crypto";
31306
+ import { createHash as createHash13 } from "node:crypto";
31002
31307
  var SAME_CALL_FAILED = "Same call failed twice:";
31003
31308
  var MAX_SESSIONS = 256;
31004
31309
  var stable = (value) => JSON.stringify(value, (_key, entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? Object.fromEntries(Object.entries(entry).toSorted(([a], [b]) => a.localeCompare(b))) : entry) ?? "null";
31005
- var hashOf = (call) => createHash12("sha256").update(call).digest("hex").slice(0, 32);
31310
+ var hashOf = (call) => createHash13("sha256").update(call).digest("hex").slice(0, 32);
31006
31311
  var record3 = (memo, sessionId, call, failed, next) => {
31007
31312
  const previous = memo.get(sessionId);
31008
31313
  memo.delete(sessionId);
@@ -31067,13 +31372,13 @@ var rootVariants = (workspaceRoot) => {
31067
31372
  if (!workspaceRoot)
31068
31373
  return [];
31069
31374
  const roots = new Set;
31070
- for (const candidate of [workspaceRoot, path33.resolve(workspaceRoot)]) {
31071
- if (path33.isAbsolute(candidate) && candidate !== path33.parse(candidate).root)
31375
+ for (const candidate of [workspaceRoot, path34.resolve(workspaceRoot)]) {
31376
+ if (path34.isAbsolute(candidate) && candidate !== path34.parse(candidate).root)
31072
31377
  roots.add(candidate);
31073
31378
  }
31074
31379
  try {
31075
- const canonical = realpathSync10(workspaceRoot);
31076
- if (canonical !== path33.parse(canonical).root)
31380
+ const canonical = realpathSync11(workspaceRoot);
31381
+ if (canonical !== path34.parse(canonical).root)
31077
31382
  roots.add(canonical);
31078
31383
  } catch {}
31079
31384
  return [...roots].toSorted((left, right) => right.length - left.length);
@@ -31155,12 +31460,12 @@ var thrownResult = (tool, error, workspaceRoot) => {
31155
31460
  };
31156
31461
  function createMcpServer(host, contextProvider) {
31157
31462
  assertMcpHost(host);
31158
- const here = path33.dirname(fileURLToPath2(import.meta.url));
31463
+ const here = path34.dirname(fileURLToPath2(import.meta.url));
31159
31464
  const sourceMarker = markSourcesLoaded([
31160
- path33.join(here, "server.ts"),
31161
- path33.join(here, "..", "..", "workit-core", "src", "core", "task-contract.ts"),
31162
- path33.join(here, "..", "..", "workit-core", "src", "core", "task-engine.ts")
31163
- ].filter((file) => existsSync15(file)));
31465
+ path34.join(here, "server.ts"),
31466
+ path34.join(here, "..", "..", "workit-core", "src", "core", "task-contract.ts"),
31467
+ path34.join(here, "..", "..", "workit-core", "src", "core", "task-engine.ts")
31468
+ ].filter((file) => existsSync16(file)));
31164
31469
  let staleWarned = false;
31165
31470
  const failures = new Map;
31166
31471
  const server = new Server({ name: "workit", version: VERSION }, { capabilities: { tools: {}, resources: {} } });
@@ -31542,7 +31847,7 @@ var COMPOSE_VALUES = new Set([
31542
31847
  // packages/workit-core/src/core/heavy-words.ts
31543
31848
  var HEAVY_WORDS = new Set(("npm npx pnpm pnpx yarn bun bunx deno corepack make gmake docker podman nerdctl " + "python python3 py uv poetry pdm pipenv hatch rye bundle rake nx " + "jest vitest mocha ava tap karma jasmine nyc c8 tsc vue-tsc svelte-check eslint stylelint " + "tslint webpack webpack-cli rollup parcel tsup vite next nuxt nuxi astro ng react-scripts " + "playwright cypress wdio testcafe turbo lerna sonar-scanner sonarless sonarless-mcp go " + "golangci-lint gotestsum staticcheck cargo mvn mvnw gradle gradlew ant sbt bazel bazelisk " + "buck2 dotnet msbuild pytest py.test tox nox mypy pyright pylint coverage maturin pip pip3 " + "rspec rails phpunit pest phpstan psalm composer mix swift xcodebuild flutter dart pod cmake " + "ninja meson ctest scons docker-compose buildah earthly").split(" "));
31544
31849
  // packages/workit-core/src/hooks/write-gate.ts
31545
- import path34 from "node:path";
31850
+ import path35 from "node:path";
31546
31851
 
31547
31852
  // packages/workit-core/src/core/live-session.ts
31548
31853
  import { spawnSync as spawnSync21 } from "node:child_process";
@@ -31584,7 +31889,7 @@ var PLACEHOLDERS = new WeakMap;
31584
31889
  var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
31585
31890
  var PUSHD2 = new Set(["pushd", "push-location"]);
31586
31891
  var POPD2 = new Set(["popd", "pop-location"]);
31587
- var UNKNOWN_DIR = path34.resolve(path34.parse(process.cwd()).root, ".workit-unknown-dir");
31892
+ var UNKNOWN_DIR = path35.resolve(path35.parse(process.cwd()).root, ".workit-unknown-dir");
31588
31893
  var DECLARERS = new Set(["export", "declare", "typeset", "local", "readonly"]);
31589
31894
  var REBINDS_ANY = new Set([
31590
31895
  "source",
@@ -31638,7 +31943,7 @@ var OPENS = new Set(["if", "for", "while", "until", "{"]);
31638
31943
  var CLOSES = new Set(["fi", "done", "}"]);
31639
31944
  var UNFOLLOWED = new Set(["case", "esac", "select", "function"]);
31640
31945
  var TRANSPARENT = new Set(["builtin", "command", "time", "!"]);
31641
- var UNKNOWN_VAR = path34.resolve(path34.parse(process.cwd()).root, ".workit-unknown-var");
31946
+ var UNKNOWN_VAR = path35.resolve(path35.parse(process.cwd()).root, ".workit-unknown-var");
31642
31947
  // packages/workit-core/src/core/skill-manifests.ts
31643
31948
  if (false) {}
31644
31949
 
@@ -31679,16 +31984,16 @@ var PROMPT_INTENTS = [
31679
31984
  ].map(([name, pattern]) => [`workit-${name}`, pattern]);
31680
31985
  var READERS = new Set("cat sed head tail less more bat nl get-content gc type".split(" "));
31681
31986
  // packages/workit-core/src/hooks/hosts/fields.ts
31682
- import { existsSync as existsSync16, realpathSync as realpathSync11, statSync as statSync5 } from "node:fs";
31683
- import path35 from "node:path";
31987
+ import { existsSync as existsSync17, realpathSync as realpathSync12, statSync as statSync5 } from "node:fs";
31988
+ import path36 from "node:path";
31684
31989
  var isRecord5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
31685
31990
  var nonEmpty2 = (value) => typeof value === "string" && value.trim() !== "";
31686
31991
  var optionalText = (value) => typeof value === "string" ? value : null;
31687
31992
  var existingDirectory = (value) => {
31688
- if (!nonEmpty2(value) || !path35.isAbsolute(value) || !existsSync16(value))
31993
+ if (!nonEmpty2(value) || !path36.isAbsolute(value) || !existsSync17(value))
31689
31994
  return null;
31690
31995
  try {
31691
- return statSync5(value).isDirectory() ? realpathSync11(value) : null;
31996
+ return statSync5(value).isDirectory() ? realpathSync12(value) : null;
31692
31997
  } catch {
31693
31998
  return null;
31694
31999
  }
@@ -32483,13 +32788,13 @@ var PROCESS_START = performance.timeOrigin;
32483
32788
  // packages/workit-core/src/hooks/run.ts
32484
32789
  if (false) {}
32485
32790
  // packages/workit-core/src/hooks/budget-signal.ts
32486
- import { createHash as createHash13 } from "node:crypto";
32487
- import fs21 from "node:fs";
32488
- import path36 from "node:path";
32489
- var hash2 = (text) => createHash13("sha256").update(text).digest("hex").slice(0, 32);
32490
- var budgetDir = (store) => path36.join(store, "budget");
32491
- var agentBase = (store, session, agentId) => path36.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
32492
- var spawnsFile = (store, session) => path36.join(budgetDir(store), `spawns-${hash2(session)}.jsonl`);
32791
+ import { createHash as createHash14 } from "node:crypto";
32792
+ import fs22 from "node:fs";
32793
+ import path37 from "node:path";
32794
+ var hash2 = (text) => createHash14("sha256").update(text).digest("hex").slice(0, 32);
32795
+ var budgetDir = (store) => path37.join(store, "budget");
32796
+ var agentBase = (store, session, agentId) => path37.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
32797
+ var spawnsFile = (store, session) => path37.join(budgetDir(store), `spawns-${hash2(session)}.jsonl`);
32493
32798
  var spawnBudget = (prompt) => {
32494
32799
  const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
32495
32800
  const n = found ? Number(found[1]) : NaN;
@@ -32500,14 +32805,14 @@ var noteSpawnBudget = (cwd, session, type, prompt) => {
32500
32805
  const store = session ? gitStoreDir(cwd) : null;
32501
32806
  if (!store)
32502
32807
  return;
32503
- fs21.mkdirSync(budgetDir(store), { recursive: true });
32504
- fs21.appendFileSync(spawnsFile(store, session), `${JSON.stringify({ type: type ?? "", n: spawnBudget(prompt) })}
32808
+ fs22.mkdirSync(budgetDir(store), { recursive: true });
32809
+ fs22.appendFileSync(spawnsFile(store, session), `${JSON.stringify({ type: type ?? "", n: spawnBudget(prompt) })}
32505
32810
  `);
32506
32811
  } catch {}
32507
32812
  };
32508
32813
  var readBudget = (file) => {
32509
32814
  try {
32510
- const { limit, told } = JSON.parse(fs21.readFileSync(file, "utf8"));
32815
+ const { limit, told } = JSON.parse(fs22.readFileSync(file, "utf8"));
32511
32816
  return typeof limit === "number" && limit > 0 ? { limit, told: Number(told) || 0 } : null;
32512
32817
  } catch {
32513
32818
  return null;
@@ -32519,13 +32824,13 @@ var claimSpawnBudget = (cwd, session, agentId, agentType) => {
32519
32824
  if (!store)
32520
32825
  return null;
32521
32826
  const file = spawnsFile(store, session);
32522
- const entries = fs21.readFileSync(file, "utf8").split(`
32827
+ const entries = fs22.readFileSync(file, "utf8").split(`
32523
32828
  `).filter(Boolean).map((line) => JSON.parse(line));
32524
32829
  const at = entries.findIndex((entry) => entry.type === (agentType ?? ""));
32525
32830
  if (at < 0)
32526
32831
  return null;
32527
32832
  const [{ n }] = entries.splice(at, 1);
32528
- fs21.writeFileSync(file, entries.map((entry) => `${JSON.stringify(entry)}
32833
+ fs22.writeFileSync(file, entries.map((entry) => `${JSON.stringify(entry)}
32529
32834
  `).join(""));
32530
32835
  if (typeof n !== "number" || n <= 0)
32531
32836
  return null;
@@ -32537,16 +32842,16 @@ var claimSpawnBudget = (cwd, session, agentId, agentType) => {
32537
32842
  };
32538
32843
  var startBudget = (store, session, agentId, n) => {
32539
32844
  const dir = budgetDir(store);
32540
- fs21.mkdirSync(dir, { recursive: true });
32845
+ fs22.mkdirSync(dir, { recursive: true });
32541
32846
  const cutoff = Date.now() - 604800000;
32542
- for (const name of fs21.readdirSync(dir))
32847
+ for (const name of fs22.readdirSync(dir))
32543
32848
  try {
32544
- if (fs21.statSync(path36.join(dir, name)).mtimeMs < cutoff)
32545
- fs21.rmSync(path36.join(dir, name));
32849
+ if (fs22.statSync(path37.join(dir, name)).mtimeMs < cutoff)
32850
+ fs22.rmSync(path37.join(dir, name));
32546
32851
  } catch {}
32547
32852
  const base = agentBase(store, session, agentId);
32548
- fs21.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
32549
- fs21.rmSync(`${base}.calls`, { force: true });
32853
+ fs22.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
32854
+ fs22.rmSync(`${base}.calls`, { force: true });
32550
32855
  };
32551
32856
  var lineFor = (calls) => `Tool-call budget reached (${calls}): commit your work, write your report, stop.`;
32552
32857
  var reachedOf = (cwd, session, agentId) => {
@@ -32555,20 +32860,20 @@ var reachedOf = (cwd, session, agentId) => {
32555
32860
  const budget = base && readBudget(`${base}.json`);
32556
32861
  if (!budget)
32557
32862
  return null;
32558
- return { base, budget, reached: Math.floor(fs21.statSync(`${base}.calls`).size / budget.limit) };
32863
+ return { base, budget, reached: Math.floor(fs22.statSync(`${base}.calls`).size / budget.limit) };
32559
32864
  };
32560
32865
  var dropBudget = (cwd, session, agentId) => {
32561
32866
  const store = session ? gitStoreDir(cwd) : null;
32562
32867
  if (store)
32563
32868
  for (const ext of [".json", ".calls"])
32564
- fs21.rmSync(agentBase(store, session, agentId) + ext, { force: true });
32869
+ fs22.rmSync(agentBase(store, session, agentId) + ext, { force: true });
32565
32870
  };
32566
32871
  var budgetLine = (cwd, session, agentId) => {
32567
32872
  try {
32568
32873
  const at = reachedOf(cwd, session, agentId);
32569
32874
  if (!at || at.reached <= at.budget.told)
32570
32875
  return null;
32571
- fs21.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
32876
+ fs22.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
32572
32877
  return lineFor(at.budget.limit * at.reached);
32573
32878
  } catch {
32574
32879
  return null;
@@ -32601,17 +32906,17 @@ if (false)
32601
32906
 
32602
32907
  // packages/workit-codex/scripts/agents.ts
32603
32908
  import {
32604
- existsSync as existsSync17,
32605
- lstatSync as lstatSync6,
32606
- mkdirSync as mkdirSync5,
32909
+ existsSync as existsSync18,
32910
+ lstatSync as lstatSync7,
32911
+ mkdirSync as mkdirSync6,
32607
32912
  readdirSync as readdirSync5,
32608
32913
  readFileSync as readFileSync13,
32609
- renameSync as renameSync4,
32914
+ renameSync as renameSync5,
32610
32915
  rmSync as rmSync3,
32611
- writeFileSync as writeFileSync5
32916
+ writeFileSync as writeFileSync6
32612
32917
  } from "node:fs";
32613
- import os6 from "node:os";
32614
- import path37 from "node:path";
32918
+ import os7 from "node:os";
32919
+ import path38 from "node:path";
32615
32920
  var CODEX_AGENT_ROLES = [
32616
32921
  "verifier",
32617
32922
  "reviewer",
@@ -32624,11 +32929,11 @@ var codexAgentName = (role) => `workit-${role}`;
32624
32929
  var codexAgentFile = (role) => `${codexAgentName(role)}.toml`;
32625
32930
  var tomlString = (value) => JSON.stringify(value);
32626
32931
  var codexHomeOfInstall = (pluginRoot) => {
32627
- const parts = path37.resolve(pluginRoot).split(path37.sep);
32932
+ const parts = path38.resolve(pluginRoot).split(path38.sep);
32628
32933
  const cache = parts.length - 4;
32629
- return cache >= 2 && parts[cache] === "cache" && parts[cache - 1] === "plugins" ? parts.slice(0, cache - 1).join(path37.sep) || path37.sep : null;
32934
+ return cache >= 2 && parts[cache] === "cache" && parts[cache - 1] === "plugins" ? parts.slice(0, cache - 1).join(path38.sep) || path38.sep : null;
32630
32935
  };
32631
- var codexHomeFor = (pluginRoot, env) => codexHomeOfInstall(pluginRoot) ?? (env.CODEX_HOME || path37.join(env.HOME || os6.homedir(), ".codex"));
32936
+ var codexHomeFor = (pluginRoot, env) => codexHomeOfInstall(pluginRoot) ?? (env.CODEX_HOME || path38.join(env.HOME || os7.homedir(), ".codex"));
32632
32937
  var withRoleModel = (content, file, models) => {
32633
32938
  const role = CODEX_AGENT_ROLES.find((candidate) => codexAgentFile(candidate) === file);
32634
32939
  const chosen = role ? models[role] : undefined;
@@ -32651,7 +32956,7 @@ var versionAtLeast = (version, min) => {
32651
32956
  };
32652
32957
  var pluginVersion = (pluginRoot) => {
32653
32958
  try {
32654
- const version = JSON.parse(readFileSync13(path37.join(pluginRoot, "package.json"), "utf8")).version;
32959
+ const version = JSON.parse(readFileSync13(path38.join(pluginRoot, "package.json"), "utf8")).version;
32655
32960
  return typeof version === "string" && /^\d+\.\d+\.\d+/.test(version) ? version.match(/^\d+\.\d+\.\d+/)[0] : null;
32656
32961
  } catch {
32657
32962
  return null;
@@ -32659,30 +32964,30 @@ var pluginVersion = (pluginRoot) => {
32659
32964
  };
32660
32965
  var lstatOrNull = (file) => {
32661
32966
  try {
32662
- return lstatSync6(file);
32967
+ return lstatSync7(file);
32663
32968
  } catch {
32664
32969
  return null;
32665
32970
  }
32666
32971
  };
32667
32972
  var installCodexAgents = (pluginRoot, codexHome, models = {}) => {
32668
- const source = path37.join(pluginRoot, "agents");
32669
- if (!existsSync17(source))
32973
+ const source = path38.join(pluginRoot, "agents");
32974
+ if (!existsSync18(source))
32670
32975
  return [];
32671
32976
  const version = pluginVersion(pluginRoot);
32672
- const target = path37.join(codexHome, "agents");
32977
+ const target = path38.join(codexHome, "agents");
32673
32978
  const results = [];
32674
32979
  for (const file of readdirSync5(source).filter((name) => name.endsWith(".toml")).toSorted()) {
32675
- const content = withRoleModel(stampCodexAgent(readFileSync13(path37.join(source, file), "utf8"), version), file, models);
32676
- const dest = path37.join(target, file);
32980
+ const content = withRoleModel(stampCodexAgent(readFileSync13(path38.join(source, file), "utf8"), version), file, models);
32981
+ const dest = path38.join(target, file);
32677
32982
  const stat = lstatOrNull(dest);
32678
32983
  if (stat?.isSymbolicLink()) {
32679
32984
  results.push({ file: dest, action: "skipped-symlink" });
32680
32985
  continue;
32681
32986
  }
32682
32987
  if (!stat) {
32683
- mkdirSync5(target, { recursive: true });
32988
+ mkdirSync6(target, { recursive: true });
32684
32989
  try {
32685
- writeFileSync5(dest, content, { flag: "wx" });
32990
+ writeFileSync6(dest, content, { flag: "wx" });
32686
32991
  results.push({ file: dest, action: "installed" });
32687
32992
  } catch (error) {
32688
32993
  if (error.code !== "EEXIST")
@@ -32709,10 +33014,10 @@ var installCodexAgents = (pluginRoot, codexHome, models = {}) => {
32709
33014
  results.push({ file: dest, action: "kept-newer-version" });
32710
33015
  continue;
32711
33016
  }
32712
- const temp = path37.join(target, `.${file}.${process.pid}.${Date.now()}.tmp`);
32713
- writeFileSync5(temp, content, { flag: "wx" });
33017
+ const temp = path38.join(target, `.${file}.${process.pid}.${Date.now()}.tmp`);
33018
+ writeFileSync6(temp, content, { flag: "wx" });
32714
33019
  try {
32715
- renameSync4(temp, dest);
33020
+ renameSync5(temp, dest);
32716
33021
  } catch (error) {
32717
33022
  rmSync3(temp, { force: true });
32718
33023
  throw error;
@@ -32731,14 +33036,14 @@ var codexQualification = (host) => host === "codex_cli" ? { surface: host, cli:
32731
33036
  var resolveCodexWorkspaceRoot = (pluginRoot, env) => {
32732
33037
  const explicit = env.WORKIT_WORKSPACE_ROOT;
32733
33038
  const inherited = env.PWD;
32734
- const candidate = explicit ?? (inherited && path38.resolve(inherited) !== path38.resolve(pluginRoot) ? inherited : undefined);
32735
- if (!candidate || !path38.isAbsolute(candidate) || !existsSync18(candidate))
33039
+ const candidate = explicit ?? (inherited && path39.resolve(inherited) !== path39.resolve(pluginRoot) ? inherited : undefined);
33040
+ if (!candidate || !path39.isAbsolute(candidate) || !existsSync19(candidate))
32736
33041
  return null;
32737
33042
  try {
32738
33043
  if (!statSync6(candidate).isDirectory())
32739
33044
  return null;
32740
- const canonical = realpathSync12(candidate);
32741
- if (canonical === realpathSync12(pluginRoot)) {
33045
+ const canonical = realpathSync13(candidate);
33046
+ if (canonical === realpathSync13(pluginRoot)) {
32742
33047
  if (!explicit)
32743
33048
  return null;
32744
33049
  const workspace = new TaskStore(canonical).readWorkspace();
@@ -32771,7 +33076,7 @@ var codexContextProvider = (host = detectCodexSurface(process.env), root) => ({
32771
33076
  };
32772
33077
  }
32773
33078
  });
32774
- var pluginRoot = () => path38.resolve(path38.dirname(fileURLToPath3(import.meta.url)), "..");
33079
+ var pluginRoot = () => path39.resolve(path39.dirname(fileURLToPath3(import.meta.url)), "..");
32775
33080
  var codexRoleModels = (cwd) => {
32776
33081
  const out = {};
32777
33082
  for (const [file, role] of [