@workit-dev/pi 2.27.7 → 2.27.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/workit.js CHANGED
@@ -10040,12 +10040,6 @@ var escapeRegExp2 = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10040
10040
  var resolveStateDir = () => stateDir(process.env);
10041
10041
  var homePattern = new RegExp(`${escapeRegExp2(os4.homedir())}(?=[/\\\\]|$)|\\$HOME(?=[/\\\\]|$)`, "g");
10042
10042
 
10043
- // packages/workit-core/src/store/paths.ts
10044
- import { spawnSync as spawnSync9 } from "node:child_process";
10045
- import { createHash as createHash7 } from "node:crypto";
10046
- import fs6 from "node:fs";
10047
- import path10 from "node:path";
10048
-
10049
10043
  // packages/workit-core/src/store/folder-store.ts
10050
10044
  import fs5 from "node:fs";
10051
10045
  import os5 from "node:os";
@@ -10262,13 +10256,14 @@ var below = (parent, child) => {
10262
10256
  const rel = path9.relative(parent, child);
10263
10257
  return rel !== "" && !rel.startsWith("..") && !path9.isAbsolute(rel);
10264
10258
  };
10259
+ var insideTempDir = (dir, tempDir = os5.tmpdir()) => below(canonical3(tempDir), canonical3(dir));
10265
10260
  var TEST_RUN_REFUSALS = "folder-store-refusals.log";
10266
10261
  var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os5.tmpdir()) => {
10267
10262
  if (env.WORKIT_TEST_RUN === undefined || !hasStray)
10268
10263
  return null;
10269
10264
  const real = canonical3(folder);
10270
10265
  const tmp = canonical3(tempDir);
10271
- if (below(tmp, real))
10266
+ if (insideTempDir(folder, tempDir))
10272
10267
  return null;
10273
10268
  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)`;
10274
10269
  };
@@ -10354,6 +10349,10 @@ Merge them by hand (cp -Rn ${workit}/. ${target}/), then delete them here.
10354
10349
  }
10355
10350
 
10356
10351
  // packages/workit-core/src/store/paths.ts
10352
+ import { spawnSync as spawnSync9 } from "node:child_process";
10353
+ import { createHash as createHash7 } from "node:crypto";
10354
+ import fs6 from "node:fs";
10355
+ import path10 from "node:path";
10357
10356
  var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
10358
10357
  var gitRun = (cwd, args) => {
10359
10358
  const run = spawnSync9("git", args, {
@@ -10666,8 +10665,58 @@ function hostSessionFromEnv(env) {
10666
10665
  var ISSUED_PER_LEAD = 64;
10667
10666
  var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/3";
10668
10667
  var hash = (value) => createHash8("sha256").update(value).digest("hex").slice(0, 32);
10669
- var userIssuedRoot = () => path11.join(resolveStateDir(), "issued");
10670
- var userTokenRoot = () => path11.join(resolveStateDir(), "issued-tokens");
10668
+ var PIN_FILE = "issued-registry";
10669
+ var pinFiles = new Map;
10670
+ var pinFile = (cwd) => {
10671
+ if (cwd === undefined)
10672
+ return null;
10673
+ const key = path11.resolve(cwd);
10674
+ const known = pinFiles.get(key);
10675
+ if (known !== undefined)
10676
+ return known;
10677
+ try {
10678
+ const location = resolveStore(key);
10679
+ if (location instanceof Error)
10680
+ return null;
10681
+ const file = location.shared ? path11.join(location.dir, "ledger", PIN_FILE) : null;
10682
+ pinFiles.set(key, file);
10683
+ return file;
10684
+ } catch {
10685
+ return null;
10686
+ }
10687
+ };
10688
+ var pinnedStateDir = (cwd) => {
10689
+ const file = pinFile(cwd);
10690
+ if (file === null)
10691
+ return null;
10692
+ try {
10693
+ const pinned = fs7.readFileSync(file, "utf8").trim();
10694
+ return path11.isAbsolute(pinned) ? pinned : null;
10695
+ } catch {
10696
+ return null;
10697
+ }
10698
+ };
10699
+ var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
10700
+ var testRunSkipsPin = (file) => process.env.WORKIT_TEST_RUN !== undefined && !insideTempDir(path11.dirname(path11.dirname(path11.dirname(file))));
10701
+ function pinIssuedRegistry(cwd) {
10702
+ const file = pinFile(cwd);
10703
+ if (file === null)
10704
+ return;
10705
+ const state = path11.resolve(resolveStateDir());
10706
+ if (pinnedStateDir(cwd) === state)
10707
+ return;
10708
+ if (testRunSkipsPin(file))
10709
+ return;
10710
+ try {
10711
+ fs7.mkdirSync(path11.dirname(file), { recursive: true });
10712
+ const temp = `${file}.${process.pid}.tmp`;
10713
+ fs7.writeFileSync(temp, `${state}
10714
+ `, { mode: 420 });
10715
+ fs7.renameSync(temp, file);
10716
+ } catch {}
10717
+ }
10718
+ var userIssuedRoot = (cwd) => path11.join(registryDir(cwd), "issued");
10719
+ var userTokenRoot = (cwd) => path11.join(registryDir(cwd), "issued-tokens");
10671
10720
  function migrateRepoIssued(cwd) {
10672
10721
  if (cwd === undefined)
10673
10722
  return;
@@ -10687,7 +10736,7 @@ function migrateRepoIssued(cwd) {
10687
10736
  const from = path11.join(old, lead);
10688
10737
  if (!fs7.statSync(from).isDirectory())
10689
10738
  continue;
10690
- const to = path11.join(userIssuedRoot(), lead);
10739
+ const to = path11.join(userIssuedRoot(cwd), lead);
10691
10740
  fs7.mkdirSync(to, { recursive: true, mode: 448 });
10692
10741
  for (const id of fs7.readdirSync(from)) {
10693
10742
  try {
@@ -10719,13 +10768,15 @@ var tokenHash = (token) => createHash8("sha256").update(token).digest("hex");
10719
10768
  function recordIssuedSession(cwd, lead, issued) {
10720
10769
  const token = randomBytes(18).toString("hex");
10721
10770
  try {
10771
+ pinIssuedRegistry(cwd);
10722
10772
  migrateRepoIssued(cwd);
10723
10773
  const own = hash(issued);
10724
- const tokens = path11.join(userTokenRoot(), hash(lead));
10774
+ const state = resolveStateDir();
10775
+ const tokens = path11.join(state, "issued-tokens", hash(lead));
10725
10776
  fs7.mkdirSync(tokens, { recursive: true, mode: 448 });
10726
10777
  fs7.writeFileSync(path11.join(tokens, own), `${tokenHash(token)}
10727
10778
  `, { mode: 384, flag: "wx" });
10728
- const dir = path11.join(userIssuedRoot(), hash(lead));
10779
+ const dir = path11.join(state, "issued", hash(lead));
10729
10780
  fs7.mkdirSync(dir, { recursive: true, mode: 448 });
10730
10781
  fs7.writeFileSync(path11.join(dir, own), `${ISSUED_SESSIONS_MARKER}
10731
10782
  `, { mode: 384 });
@@ -10770,17 +10821,17 @@ var issuedRecord = (cwd, claimed) => {
10770
10821
  return null;
10771
10822
  migrateRepoIssued(cwd);
10772
10823
  try {
10773
- return fs7.readFileSync(path11.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
10824
+ return fs7.readFileSync(path11.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
10774
10825
  } catch {
10775
10826
  return null;
10776
10827
  }
10777
10828
  };
10778
10829
  var TOKEN_HASH = /^([0-9a-f]{64})$/mu;
10779
- var issuedToken = (claimed) => {
10830
+ var issuedToken = (cwd, claimed) => {
10780
10831
  const cut = claimed.lastIndexOf(":");
10781
10832
  if (cut <= 0)
10782
10833
  return { stored: null, leadBound: false };
10783
- const dir = path11.join(userTokenRoot(), hash(claimed.slice(0, cut)));
10834
+ const dir = path11.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
10784
10835
  try {
10785
10836
  const text = fs7.readFileSync(path11.join(dir, hash(claimed)), "utf8");
10786
10837
  return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
@@ -10790,7 +10841,7 @@ var issuedToken = (claimed) => {
10790
10841
  };
10791
10842
  function issuedBinding(cwd, claimed) {
10792
10843
  const record = issuedRecord(cwd, claimed);
10793
- const { stored, leadBound } = issuedToken(claimed);
10844
+ const { stored, leadBound } = issuedToken(cwd, claimed);
10794
10845
  if (stored)
10795
10846
  return "token";
10796
10847
  if (record === null)
@@ -27384,7 +27435,7 @@ var splitDenial = (plan) => ({
27384
27435
  // packages/workit-core/src/hooks/write-gate.ts
27385
27436
  import {
27386
27437
  existsSync as existsSync16,
27387
- readdirSync as readdirSync5,
27438
+ readdirSync as readdirSync6,
27388
27439
  readFileSync as readFileSync12,
27389
27440
  readlinkSync as readlinkSync3,
27390
27441
  realpathSync as realpathSync11,
@@ -27392,7 +27443,7 @@ import {
27392
27443
  } from "node:fs";
27393
27444
  import { builtinModules } from "node:module";
27394
27445
  import os10 from "node:os";
27395
- import path42 from "node:path";
27446
+ import path43 from "node:path";
27396
27447
 
27397
27448
  // packages/workit-core/src/core/live-session.ts
27398
27449
  import { spawnSync as spawnSync23 } from "node:child_process";
@@ -27595,6 +27646,41 @@ var claimLiveSession = (target, owner, deps = {}) => {
27595
27646
  } catch {}
27596
27647
  };
27597
27648
 
27649
+ // packages/workit-core/src/hooks/path-glob.ts
27650
+ import { readdirSync as readdirSync5 } from "node:fs";
27651
+ import path42 from "node:path";
27652
+ var GLOB2 = /[*?[]/u;
27653
+ var globPattern = (glob, dots = false) => {
27654
+ try {
27655
+ return new RegExp(`^${dots || glob.startsWith(".") ? "" : "(?!\\.)"}${glob.replace(/[.+^$(){}|\\]/gu, "\\$&").replace(/\[!/gu, "[^").replaceAll("*", ".*").replaceAll("?", ".")}$`, "u");
27656
+ } catch {
27657
+ return null;
27658
+ }
27659
+ };
27660
+ var expandGlob = (file, limit = 64) => {
27661
+ if (!GLOB2.test(file))
27662
+ return [file];
27663
+ const { root } = path42.parse(file);
27664
+ let found = [root];
27665
+ for (const part of file.slice(root.length).split(/[\\/]/u).filter(Boolean)) {
27666
+ if (!GLOB2.test(part)) {
27667
+ found = found.map((dir) => path42.join(dir, part));
27668
+ continue;
27669
+ }
27670
+ const pattern = globPattern(part);
27671
+ if (pattern === null)
27672
+ return [file];
27673
+ found = found.flatMap((dir) => {
27674
+ try {
27675
+ return readdirSync5(dir).filter((name) => pattern.test(name)).map((name) => path42.join(dir, name));
27676
+ } catch {
27677
+ return [];
27678
+ }
27679
+ }).slice(0, limit);
27680
+ }
27681
+ return found.length > 0 ? found : [file];
27682
+ };
27683
+
27598
27684
  // packages/workit-core/src/hooks/windows-reads.ts
27599
27685
  var READ_CMDLETS = new Set([
27600
27686
  "foreach-object",
@@ -27912,44 +27998,44 @@ var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "wi
27912
27998
  var linkTarget = (file) => {
27913
27999
  try {
27914
28000
  const to = readlinkSync3(file);
27915
- let from = path42.dirname(file);
28001
+ let from = path43.dirname(file);
27916
28002
  try {
27917
28003
  from = realpathSync11.native(from);
27918
28004
  } catch {}
27919
- return path42.resolve(from, to);
28005
+ return path43.resolve(from, to);
27920
28006
  } catch {
27921
28007
  return null;
27922
28008
  }
27923
28009
  };
27924
28010
  var realPath = (file, dangling = true) => {
27925
- let dir = path42.resolve(file);
28011
+ let dir = path43.resolve(file);
27926
28012
  let rest = "";
27927
28013
  for (let hops = 0;; ) {
27928
28014
  try {
27929
- return path42.join(realpathSync11.native(dir), rest);
28015
+ return path43.join(realpathSync11.native(dir), rest);
27930
28016
  } catch {
27931
28017
  const link = dangling ? linkTarget(dir) : null;
27932
28018
  if (link !== null) {
27933
28019
  if (++hops > 40)
27934
28020
  return null;
27935
- dir = path42.join(link, rest);
28021
+ dir = path43.join(link, rest);
27936
28022
  rest = "";
27937
- } else if (path42.dirname(dir) === dir)
27938
- return path42.resolve(file);
28023
+ } else if (path43.dirname(dir) === dir)
28024
+ return path43.resolve(file);
27939
28025
  else {
27940
- rest = rest ? path42.join(path42.basename(dir), rest) : path42.basename(dir);
27941
- dir = path42.dirname(dir);
28026
+ rest = rest ? path43.join(path43.basename(dir), rest) : path43.basename(dir);
28027
+ dir = path43.dirname(dir);
27942
28028
  }
27943
28029
  }
27944
28030
  }
27945
28031
  };
27946
- var canonical5 = (file, dangling = true) => realPath(file, dangling) ?? path42.resolve(file);
28032
+ var canonical5 = (file, dangling = true) => realPath(file, dangling) ?? path43.resolve(file);
27947
28033
  var exempt = (cwd, root, file, plans) => {
27948
28034
  const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
27949
- const relative = path42.relative(fold(canonical5(root, false)), fold(canonical5(path42.resolve(cwd, file), false)));
27950
- if (relative.startsWith("..") || path42.isAbsolute(relative))
28035
+ const relative = path43.relative(fold(canonical5(root, false)), fold(canonical5(path43.resolve(cwd, file), false)));
28036
+ if (relative.startsWith("..") || path43.isAbsolute(relative))
27951
28037
  return true;
27952
- const posix = relative.split(path42.sep).join("/");
28038
+ const posix = relative.split(path43.sep).join("/");
27953
28039
  const segments = posix.split("/");
27954
28040
  return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
27955
28041
  };
@@ -28029,7 +28115,7 @@ var editsOf = (input) => {
28029
28115
  return [into];
28030
28116
  const files = operands(args);
28031
28117
  if (name === "ln" && files.length === 1)
28032
- return [path42.basename(files[0])];
28118
+ return [path43.basename(files[0])];
28033
28119
  return files.length ? [files.at(-1)] : null;
28034
28120
  }
28035
28121
  case "mklink": {
@@ -28091,6 +28177,35 @@ var editsOf = (input) => {
28091
28177
  return [];
28092
28178
  }
28093
28179
  };
28180
+ var removalsOf = (input) => {
28181
+ const [verb = "", ...args] = pastLead(input);
28182
+ const name = (verb.split(/[\\/]/).at(-1) ?? "").toLowerCase();
28183
+ const files = operands(args);
28184
+ if (/^(?:rm|rmdir|rd|unlink|shred|remove-item|ri|del|erase)$/.test(name))
28185
+ return { files };
28186
+ if (/^(?:mv|move-item|mi|move)$/.test(name)) {
28187
+ const into = valueOf(args, /^(?:-[a-zA-Z]*t|--target-directory=?)(.*)$/s);
28188
+ return {
28189
+ files: into === undefined ? files.slice(0, -1) : files.filter((file) => file !== into)
28190
+ };
28191
+ }
28192
+ if (name === "rsync" && args.some((arg) => /^--del(?:ete|$)/.test(arg)))
28193
+ return { files: files.slice(-1) };
28194
+ const removes = args.some((arg, at) => arg === "-delete" || /^-(?:exec|execdir|ok|okdir)$/.test(arg) && /^(?:rm|rmdir|unlink|shred|mv|truncate|cp|dd|tee|sh|bash|dash|zsh)$/.test(commandName2(args[at + 1] ?? "")));
28195
+ if (name !== "find" || !removes)
28196
+ return { files: [] };
28197
+ const end = args.findIndex((arg) => /^[-(!]/.test(arg));
28198
+ const roots = end === 0 ? ["."] : args.slice(0, end);
28199
+ const tests = [];
28200
+ for (const [at, arg] of args.entries()) {
28201
+ const kind = /^-(i?)(?:name|path|wholename|regex)$/.exec(arg);
28202
+ const value = args[at + 1];
28203
+ if (kind && value !== undefined)
28204
+ tests.push([`${arg.replace(/^-i?/, "").replace("wholename", "path")}${kind[1]}`, value]);
28205
+ }
28206
+ const negated = args.some((arg) => arg === "!" || arg === "-not");
28207
+ return { files: roots, find: { roots, tests: negated ? [] : tests } };
28208
+ };
28094
28209
  var WRAPPERS3 = {
28095
28210
  sudo: "ugCDhpRrTtU",
28096
28211
  doas: "uC",
@@ -28114,7 +28229,7 @@ var WRAPPERS3 = {
28114
28229
  var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
28115
28230
  var INLINE_CODE = /^-[a-zA-Z]*[cep]$|^--(?:eval|print)(?:=|$)/;
28116
28231
  var isConfigDir = (file) => configDirs().some((dir) => canonical5(dir) === canonical5(file));
28117
- var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals|verdicts|agent-stamps)$/.test(path42.relative(canonical5(resolveStateDir()), canonical5(file)));
28232
+ var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals|verdicts|agent-stamps)$/.test(path43.relative(canonical5(resolveStateDir()), canonical5(file)));
28118
28233
  var READ_CALLS = /^(?:print|log|info|warn|error|debug|puts|readdir(?:Sync)?|listdir|scandir|iterdir|glob|l?stat(?:Sync)?|exists(?:Sync)?|isdir|isfile|is_dir|is_file|access(?:Sync)?|realpath(?:Sync)?|dirname|basename|relative|str|repr|len)$/;
28119
28234
  var MUTATING_CALLS = /^(?:renames?(?:Sync)?|move(?:_into)?|copy(?:2|file|tree|File|_into)?(?:Sync)?|cp(?:Sync)?|rm(?:tree|dir|Sync|dirSync)?|unlink(?:Sync)?|remove(?:dirs)?|mkdirs?(?:Sync)?|makedirs|mkdtemp(?:Sync)?|(?:sym|hard)?link(?:Sync|_to)?|write\w*|append\w*|f?truncate(?:Sync)?|ch(?:mod|own)(?:Sync)?|touch|open(?:Sync)?|dump|save|extractall|unpack_archive|put_contents|mv|FileUtils)$/;
28120
28235
  var SPAWNS = /getattr|Reflect|getOwnPropertyDescriptor|FileIO|\.copy\s*\((?!\s*\))|utime|ch(?:mod|own)|\.delete\s*\(\s*\)|(?:PYTHON|NODE_)\w*\+?=|-r\b|--(?:require|import|env-file|[\w-]*loader)|\b(?:exec\w*|eval|(?:unlink|rename|remove)\w*)\b|\]\s*\(/;
@@ -28639,10 +28754,10 @@ var linkSources = (args, at) => {
28639
28754
  const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
28640
28755
  const target = dest === undefined ? null : at(dest);
28641
28756
  const symbolic = args.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg));
28642
- const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync16(target) || /[\\/]$/.test(dest ?? "") ? target : path42.dirname(target);
28757
+ const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync16(target) || /[\\/]$/.test(dest ?? "") ? target : path43.dirname(target);
28643
28758
  return sources.flatMap((source) => {
28644
- if (symbolic && base !== null && !path42.isAbsolute(homeExpanded(source)))
28645
- return [path42.resolve(base, source)];
28759
+ if (symbolic && base !== null && !path43.isAbsolute(homeExpanded(source)))
28760
+ return [path43.resolve(base, source)];
28646
28761
  const resolved = at(source);
28647
28762
  return resolved ? [resolved] : [];
28648
28763
  });
@@ -28687,7 +28802,7 @@ var linkReach = (verb, args, at, atAll) => {
28687
28802
  const dir = match ? match[1] ?? args[index + 1] : undefined;
28688
28803
  if (!dir)
28689
28804
  return [];
28690
- return [...atAll(dir), ...dest && !path42.isAbsolute(dir) ? atAll(path42.join(dest, dir)) : []];
28805
+ return [...atAll(dir), ...dest && !path43.isAbsolute(dir) ? atAll(path43.join(dest, dir)) : []];
28691
28806
  });
28692
28807
  }
28693
28808
  if (verb === "mklink")
@@ -28723,7 +28838,7 @@ var shellWrites = (command, depth = 0) => {
28723
28838
  return { writes: true, targets: unknown ? null : targets };
28724
28839
  };
28725
28840
  var cache3 = new Map;
28726
- var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path42.resolve(root, file)) ?? "-").join("\x00");
28841
+ var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path43.resolve(root, file)) ?? "-").join("\x00");
28727
28842
  var gateFor = (cwd) => {
28728
28843
  const store = new TaskReader(cwd);
28729
28844
  const listed = store.listTaskIndex();
@@ -28786,7 +28901,7 @@ var DIR_TARGET = ".workit-live-target";
28786
28901
  var PLACEHOLDERS = new WeakMap;
28787
28902
  var collecting = null;
28788
28903
  var placeholderIn = (dir, name) => {
28789
- const target = path42.join(dir, name);
28904
+ const target = path43.join(dir, name);
28790
28905
  collecting?.add(target);
28791
28906
  return target;
28792
28907
  };
@@ -28814,6 +28929,7 @@ var inlineWhy = (targets) => REASONS.get(targets);
28814
28929
  var OPAQUE_TARGET = ".workit-runs-";
28815
28930
  var UNRESOLVED_TARGET = ".workit-unresolved-target";
28816
28931
  var LINK_SOURCE = ".workit-link-source";
28932
+ var REMOVED_SOURCE = ".workit-removed-source";
28817
28933
  var OVERRIDE = "WORKIT_LIVE_SESSION=override";
28818
28934
  var inert = (args, sub) => args.some((arg) => arg === "--help" || arg === "-h" || arg === "--dry-run" || DRY_N.has(sub) && /^-[a-zA-Z]*n[a-zA-Z]*$/.test(arg) && !arg.startsWith("--"));
28819
28935
  var gitMutationDirs = (cwd, command, dialect) => {
@@ -28833,13 +28949,13 @@ var gitMutationDirs = (cwd, command, dialect) => {
28833
28949
  return [];
28834
28950
  if (sub === "stash" && ["list", "show"].includes(rest[0] ?? ""))
28835
28951
  return [];
28836
- return [path42.resolve(cwd, invocation.dir ?? ".")];
28952
+ return [path43.resolve(cwd, invocation.dir ?? ".")];
28837
28953
  });
28838
28954
  };
28839
28955
  var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
28840
28956
  var PUSHD2 = new Set(["pushd", "push-location"]);
28841
28957
  var POPD2 = new Set(["popd", "pop-location"]);
28842
- var UNKNOWN_DIR = path42.resolve(path42.parse(process.cwd()).root, ".workit-unknown-dir");
28958
+ var UNKNOWN_DIR = path43.resolve(path43.parse(process.cwd()).root, ".workit-unknown-dir");
28843
28959
  var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
28844
28960
  const lost = strict ? UNKNOWN_DIR : undefined;
28845
28961
  const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
@@ -28849,7 +28965,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
28849
28965
  return lost;
28850
28966
  if (dir === undefined)
28851
28967
  return lost;
28852
- return target === undefined ? os10.homedir() : path42.resolve(dir, target);
28968
+ return target === undefined ? os10.homedir() : path43.resolve(dir, target);
28853
28969
  };
28854
28970
  var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
28855
28971
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
@@ -28997,7 +29113,7 @@ var untrustedVars = (segments) => {
28997
29113
  }
28998
29114
  return { all, names };
28999
29115
  };
29000
- var UNKNOWN_VAR = path42.resolve(path42.parse(process.cwd()).root, ".workit-unknown-var");
29116
+ var UNKNOWN_VAR = path43.resolve(path43.parse(process.cwd()).root, ".workit-unknown-var");
29001
29117
  var REFERENCE = /\$\{(\w+)[^}]*\}|\$(\w+)|\$\([^)]*\)?|`[^`]*`?/g;
29002
29118
  var unresolvedRefs = (text) => [
29003
29119
  ...new Set([...text.matchAll(REFERENCE)].map((match) => {
@@ -29007,7 +29123,7 @@ var unresolvedRefs = (text) => [
29007
29123
  ];
29008
29124
  var unknownVarTarget = (text) => {
29009
29125
  const refs = unresolvedRefs(text);
29010
- return path42.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
29126
+ return path43.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
29011
29127
  };
29012
29128
  var applyOperator = (value, operator) => {
29013
29129
  if (operator === "")
@@ -29068,12 +29184,12 @@ var mktempPath = (value, dir) => {
29068
29184
  if (base === null && (temp || template === undefined))
29069
29185
  base = os10.tmpdir();
29070
29186
  const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
29071
- if (path42.isAbsolute(name))
29187
+ if (path43.isAbsolute(name))
29072
29188
  return name;
29073
29189
  const from = base === null ? dir : homeExpanded(base);
29074
- if (from === undefined || !path42.isAbsolute(from) && dir === undefined)
29190
+ if (from === undefined || !path43.isAbsolute(from) && dir === undefined)
29075
29191
  return null;
29076
- return path42.resolve(dir ?? from, from, name);
29192
+ return path43.resolve(dir ?? from, from, name);
29077
29193
  };
29078
29194
  var homeExpanded = (file) => {
29079
29195
  const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
@@ -29097,7 +29213,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29097
29213
  const home = homeExpanded(text);
29098
29214
  if (strict && unresolvedRefs(home).length > 0)
29099
29215
  return [unknownVarTarget(home)];
29100
- if (path42.isAbsolute(home))
29216
+ if (path43.isAbsolute(home))
29101
29217
  return [home];
29102
29218
  return base === undefined ? [] : [resolvedUnder(base, home)];
29103
29219
  });
@@ -29168,7 +29284,8 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29168
29284
  if (loop >= 0) {
29169
29285
  const [name = "", keyword, ...items] = segment.words.slice(loop + 1);
29170
29286
  const expanding = new Set(segment.expands ?? []);
29171
- const list = items.flatMap((item, index) => expanding.has(loop + 3 + index) ? listWords(item) : [listWord(homeExpanded(item))]);
29287
+ const globbedItem = (item) => strict === "registry" && dir !== undefined && /[*?[]/.test(item) ? expandGlob(path43.resolve(dir, homeExpanded(item))) : null;
29288
+ const list = items.flatMap((item, index) => globbedItem(item) ?? (expanding.has(loop + 3 + index) ? listWords(item) : [listWord(homeExpanded(item))]));
29172
29289
  vars.delete(name);
29173
29290
  if (keyword === "in" && list.length <= MAX_EXPANSIONS2 && !list.includes(null) && !untrusted.all && !untrusted.names.has(name))
29174
29291
  loops.set(name, list);
@@ -29307,7 +29424,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29307
29424
  index
29308
29425
  }));
29309
29426
  const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
29310
- const under = (word) => homes ? [path42.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
29427
+ const under = (word) => homes ? [path43.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
29311
29428
  const found = [
29312
29429
  ...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
29313
29430
  ...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
@@ -29315,7 +29432,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29315
29432
  for (const { file, index } of found) {
29316
29433
  const use = isRoot(file) ? rootUse(text, index) : "takes";
29317
29434
  if (use !== "reads")
29318
- targets.push(use === "builds" ? path42.join(file, UNRESOLVED_TARGET) : file);
29435
+ targets.push(use === "builds" ? path43.join(file, UNRESOLVED_TARGET) : file);
29319
29436
  }
29320
29437
  }
29321
29438
  if (/^(?:n?vim?|ex|ed|emacs)$/.test(verb) && (segment.stdin || inputs.length > 0 || feeder || args.some((arg, index) => /^(?:-[a-zA-Z]*[se]|--(?:batch|eval|script))$/.test(arg) || /^(?:-c|--cmd)$/.test(arg) && !inertEdit(args[index + 1] ?? "") || arg.startsWith("+") && !inertEdit(arg.slice(1) || "1"))))
@@ -29325,7 +29442,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29325
29442
  `);
29326
29443
  for (const [linker = "", ...rest] of fedRuns(words, feed))
29327
29444
  for (const source of linkReach(commandName2(linker), rest, at, atAll))
29328
- targets.push(path42.join(source, LINK_SOURCE));
29445
+ targets.push(path43.join(source, LINK_SOURCE));
29329
29446
  }
29330
29447
  if (strict && dir !== undefined) {
29331
29448
  const runIn = dir;
@@ -29352,7 +29469,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29352
29469
  for (const file of opaque ?? [])
29353
29470
  for (const resolved of atAll(file))
29354
29471
  if (!quiet || !isRoot(resolved))
29355
- targets.push(file === "." ? placeholderIn(resolved, here) : path42.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path42.dirname(resolved), path42.basename(resolved)) : resolved);
29472
+ targets.push(file === "." ? placeholderIn(resolved, here) : path43.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path43.dirname(resolved), path43.basename(resolved)) : resolved);
29356
29473
  const [shell = "", ...shellArgs] = pastLead(words);
29357
29474
  const verb = (shell.split(/[\\/]/).at(-1) ?? "").toLowerCase();
29358
29475
  const named = (SCRIPT_SHELLS.has(verb) || verb === "source" || verb === ".") && shellScript3([verb, ...shellArgs]) === null ? scriptArgs(verb, shellArgs).named ?? "" : null;
@@ -29373,6 +29490,12 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29373
29490
  if (dir !== undefined)
29374
29491
  targets.push(placeholderIn(dir, DIR_TARGET));
29375
29492
  }
29493
+ if (strict === "registry") {
29494
+ const { files: gone, find } = removalsOf(body);
29495
+ for (const root of gone)
29496
+ for (const file of atAll(root))
29497
+ targets.push(path43.join(file, find ? `${REMOVED_SOURCE}~${encodeURIComponent(JSON.stringify({ root, tests: find.tests }))}` : REMOVED_SOURCE));
29498
+ }
29376
29499
  for (const file of [...segment.redirects, ...edits ?? []])
29377
29500
  if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file) && !(dialect === "powershell" && /^(?:\$null|nul)$/i.test(file)))
29378
29501
  targets.push(...atAll(file));
@@ -29399,7 +29522,10 @@ var workitCwd = (dir, args, resolve) => {
29399
29522
  };
29400
29523
  var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
29401
29524
  try {
29402
- const env = new Map(strict === "registry" ? [...command.matchAll(/\$\{?([A-Za-z_]\w*)/g)].filter((match) => !/^(?:OLD)?PWD$/.test(match[1])).map((match) => [match[1], process.env[match[1]] ?? ""]) : []);
29525
+ const env = new Map(strict === "registry" ? [
29526
+ ...[...command.matchAll(/\$\{?([A-Za-z_]\w*)/g)].filter((match) => !/^(?:OLD)?PWD$/.test(match[1])).map((match) => [match[1], process.env[match[1]] ?? ""]),
29527
+ ["PWD", cwd]
29528
+ ] : []);
29403
29529
  return recording(() => [
29404
29530
  ...segmentTargets(cwd, command, dialect, 0, strict, env),
29405
29531
  ...gitMutationDirs(cwd, command, dialect).map((dir) => placeholderIn(dir, DIR_TARGET))
@@ -29441,7 +29567,7 @@ var liveDeny = ({ marker, checkout, ageMs, file }) => {
29441
29567
  var guarded = (targets) => {
29442
29568
  const seen = new Set;
29443
29569
  return targets.filter((target) => {
29444
- const dir = path42.dirname(target);
29570
+ const dir = path43.dirname(target);
29445
29571
  if (seen.has(dir))
29446
29572
  return false;
29447
29573
  seen.add(dir);
@@ -29462,17 +29588,17 @@ var claimAll = (owner, targets, deps) => {
29462
29588
  for (const target of guarded(targets))
29463
29589
  claimLiveSession(target, owner, deps);
29464
29590
  };
29465
- var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path42.resolve(dir, file) : path42.isAbsolute(file) ? file : `${dir}${path42.sep}${file}`;
29591
+ var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path43.resolve(dir, file) : path43.isAbsolute(file) ? file : `${dir}${path43.sep}${file}`;
29466
29592
  var liveTargets = (cwd, paths) => recording(() => paths?.length ? paths.map((file) => resolvedUnder(cwd, file)) : [placeholderIn(cwd, DIR_TARGET)]);
29467
29593
  var CONFIG_FILES = ["workspaces.json", SEAL_FILE];
29468
29594
  var configDirs = () => [resolveConfigDir(), grantsDir()];
29469
29595
  var globbed = (cwd, target, state, configs) => {
29470
29596
  if (!/[*?[]/.test(target))
29471
29597
  return [];
29472
- const raw = path42.resolve(cwd, target).split(path42.sep);
29598
+ const raw = path43.resolve(cwd, target).split(path43.sep);
29473
29599
  const literal = raw.findIndex((part) => /[*?[]/.test(part));
29474
29600
  const pattern = [
29475
- ...canonical5(raw.slice(0, literal).join(path42.sep) || path42.sep).replace(/[\\/]+$/, "").split(path42.sep),
29601
+ ...canonical5(raw.slice(0, literal).join(path43.sep) || path43.sep).replace(/[\\/]+$/, "").split(path43.sep),
29476
29602
  ...raw.slice(literal)
29477
29603
  ];
29478
29604
  const segment = (glob, name) => {
@@ -29483,16 +29609,16 @@ var globbed = (cwd, target, state, configs) => {
29483
29609
  }
29484
29610
  };
29485
29611
  const hit = (file, below) => {
29486
- const parts = canonical5(file).split(path42.sep);
29612
+ const parts = canonical5(file).split(path43.sep);
29487
29613
  return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
29488
29614
  };
29489
29615
  let roots = [];
29490
29616
  try {
29491
- roots = readdirSync5(state).filter((name) => /^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name));
29617
+ roots = readdirSync6(state).filter((name) => /^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name));
29492
29618
  } catch {}
29493
29619
  return [
29494
- ...roots.map((name) => path42.join(state, name)).filter((root) => hit(root, true)),
29495
- ...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path42.join(dir, name))]).filter((file) => hit(file, false))
29620
+ ...roots.map((name) => path43.join(state, name)).filter((root) => hit(root, true)),
29621
+ ...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path43.join(dir, name))]).filter((file) => hit(file, false))
29496
29622
  ];
29497
29623
  };
29498
29624
  var guardedInodes = (state, configs) => {
@@ -29505,18 +29631,18 @@ var guardedInodes = (state, configs) => {
29505
29631
  if (stat?.isFile())
29506
29632
  seen.set(`${stat.dev}:${stat.ino}`, registry);
29507
29633
  else if (stat?.isDirectory())
29508
- for (const name of readdirSync5(file))
29509
- add(path42.join(file, name), registry);
29634
+ for (const name of readdirSync6(file))
29635
+ add(path43.join(file, name), registry);
29510
29636
  };
29511
29637
  try {
29512
29638
  for (const dir of configs)
29513
29639
  for (const name of CONFIG_FILES)
29514
- add(path42.join(dir, name), "grants");
29515
- for (const name of readdirSync5(state))
29640
+ add(path43.join(dir, name), "grants");
29641
+ for (const name of readdirSync6(state))
29516
29642
  if (/^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name))
29517
- add(path42.join(state, name), name === "approvals" ? "approvals" : name === "verdicts" || name === "agent-stamps" ? "ledger" : "issued");
29518
- for (const slug of readdirSync5(path42.join(state, "folders")))
29519
- add(path42.join(state, "folders", slug, "ledger"), "ledger");
29643
+ add(path43.join(state, name), name === "approvals" ? "approvals" : name === "verdicts" || name === "agent-stamps" ? "ledger" : "issued");
29644
+ for (const slug of readdirSync6(path43.join(state, "folders")))
29645
+ add(path43.join(state, "folders", slug, "ledger"), "ledger");
29520
29646
  } catch {}
29521
29647
  return seen;
29522
29648
  };
@@ -29533,19 +29659,87 @@ var hardLinked = (file, state, configs, inodes) => {
29533
29659
  };
29534
29660
  var inRepoLedger = (file) => [...file.matchAll(/[\\/]workit[\\/]ledger(?=[\\/]|$)/g)].some(({ index }) => {
29535
29661
  const gitDir = file.slice(0, index);
29536
- return /(?:^|[\\/])\.git$/.test(gitDir) || existsSync16(path42.join(gitDir, "HEAD")) && existsSync16(path42.join(gitDir, "objects"));
29662
+ return /(?:^|[\\/])\.git$/.test(gitDir) || existsSync16(path43.join(gitDir, "HEAD")) && existsSync16(path43.join(gitDir, "objects"));
29537
29663
  });
29538
29664
  var holdsGuarded = (cwd, source, state, configs) => {
29539
29665
  const real = canonical5(source);
29540
29666
  const below = (parent, child) => {
29541
- const rel = path42.relative(parent, child);
29542
- return rel === "" || !rel.startsWith("..") && !path42.isAbsolute(rel);
29667
+ const rel = path43.relative(parent, child);
29668
+ return rel === "" || !rel.startsWith("..") && !path43.isAbsolute(rel);
29543
29669
  };
29544
29670
  const holds = (file) => below(real, canonical5(file));
29545
- const inState = path42.relative(canonical5(state), real).split(path42.sep);
29546
- const ledgers = ["ledger", "workit/ledger", ".git/workit/ledger"].map((rel) => path42.join(real, rel)).filter((dir) => existsSync16(dir) && inRepoLedger(dir));
29671
+ const inState = path43.relative(canonical5(state), real).split(path43.sep);
29672
+ const ledgers = ["ledger", "workit/ledger", ".git/workit/ledger"].map((rel) => path43.join(real, rel)).filter((dir) => existsSync16(dir) && inRepoLedger(dir));
29547
29673
  const own = ledgerPath(cwd);
29548
- return holds(state) || below(canonical5(state), real) && inState[0] === "folders" && inState.length <= 2 || configs.some(holds) || ledgers.length > 0 || own.ok && existsSync16(own.value) && holds(path42.dirname(own.value));
29674
+ return holds(state) || below(canonical5(state), real) && inState[0] === "folders" && inState.length <= 2 || configs.some(holds) || ledgers.length > 0 || own.ok && existsSync16(own.value) && holds(path43.dirname(own.value));
29675
+ };
29676
+ var removesLedger = (cwd, source, state, configs) => {
29677
+ const real = canonical5(source);
29678
+ if (/(?:^|[\\/])\.git(?:[\\/]workit)?$/i.test(real) || inRepoLedger(real))
29679
+ return true;
29680
+ const own = ledgerPath(cwd);
29681
+ if (own.ok) {
29682
+ const rel = path43.relative(real, canonical5(path43.dirname(own.value)));
29683
+ if (rel === "" || !rel.startsWith("..") && !path43.isAbsolute(rel))
29684
+ return true;
29685
+ }
29686
+ return holdsGuarded(cwd, source, state, configs);
29687
+ };
29688
+ var findTests = (marker) => {
29689
+ try {
29690
+ return JSON.parse(decodeURIComponent(marker.slice(REMOVED_SOURCE.length + 1)));
29691
+ } catch {
29692
+ return null;
29693
+ }
29694
+ };
29695
+ var findReachesLedger = (cwd, root, find) => {
29696
+ if (find === null)
29697
+ return true;
29698
+ const real = canonical5(root);
29699
+ const own = ledgerPath(cwd);
29700
+ const ledgers = [
29701
+ ...own.ok ? [canonical5(path43.dirname(own.value))] : [],
29702
+ ...[".git/workit/ledger", "workit/ledger", "ledger"].map((rel) => path43.join(real, rel)).filter((dir) => existsSync16(dir) && inRepoLedger(dir))
29703
+ ];
29704
+ const under = (parent, child) => {
29705
+ const rel = path43.relative(parent, child);
29706
+ return rel === "" || !rel.startsWith("..") && !path43.isAbsolute(rel);
29707
+ };
29708
+ const patterns = find.tests.map(([kind, pattern]) => {
29709
+ const fold = kind.endsWith("i");
29710
+ const glob = globPattern(pattern, true);
29711
+ let test = /(?:)/;
29712
+ try {
29713
+ test = kind.startsWith("regex") ? new RegExp(`^${pattern}$`, fold ? "i" : "") : glob ? new RegExp(glob.source, fold ? "iu" : "u") : test;
29714
+ } catch {}
29715
+ return { kind, test };
29716
+ });
29717
+ const matches = (entry) => patterns.length === 0 || patterns.some(({ kind, test }) => test.test(kind.startsWith("name") ? path43.basename(entry) : path43.join(find.root, path43.relative(real, entry)).replaceAll("\\", "/")));
29718
+ for (const ledger of ledgers) {
29719
+ if (!existsSync16(ledger) || !under(real, ledger) && !under(ledger, real))
29720
+ continue;
29721
+ const entries = [];
29722
+ for (let dir = ledger;under(real, dir) && dir !== real; dir = path43.dirname(dir))
29723
+ entries.push(dir);
29724
+ const walk = (dir) => {
29725
+ for (const item of readdirSync6(dir, { withFileTypes: true })) {
29726
+ if (entries.length > 500)
29727
+ return;
29728
+ const file = path43.join(dir, item.name);
29729
+ entries.push(file);
29730
+ if (item.isDirectory())
29731
+ walk(file);
29732
+ }
29733
+ };
29734
+ try {
29735
+ walk(ledger);
29736
+ } catch {
29737
+ return true;
29738
+ }
29739
+ if (entries.some((entry) => under(real, entry) && matches(entry)))
29740
+ return true;
29741
+ }
29742
+ return false;
29549
29743
  };
29550
29744
  var registryTarget = (cwd, targets) => {
29551
29745
  const state = resolveStateDir();
@@ -29553,20 +29747,28 @@ var registryTarget = (cwd, targets) => {
29553
29747
  const inodes = {};
29554
29748
  for (const target of targets) {
29555
29749
  const file = homeExpanded(target);
29556
- if (path42.basename(file) === LINK_SOURCE) {
29557
- const source = path42.dirname(path42.resolve(cwd, file));
29750
+ if (path43.basename(file).startsWith(REMOVED_SOURCE)) {
29751
+ const marker = path43.basename(file);
29752
+ const source = path43.dirname(path43.resolve(cwd, file));
29753
+ const find = marker === REMOVED_SOURCE ? null : findTests(marker);
29754
+ if (expandGlob(source).some((gone) => find ? findReachesLedger(cwd, gone, find) : removesLedger(cwd, gone, state, configs)))
29755
+ return { file: path43.join(source, REMOVED_SOURCE), registry: "removes" };
29756
+ continue;
29757
+ }
29758
+ if (path43.basename(file) === LINK_SOURCE) {
29759
+ const source = path43.dirname(path43.resolve(cwd, file));
29558
29760
  const reached = registryTarget(cwd, [source])?.registry ?? (holdsGuarded(cwd, source, state, configs) ? "holds" : null);
29559
29761
  if (reached)
29560
29762
  return { file: target, registry: reached };
29561
29763
  continue;
29562
29764
  }
29563
- if (realPath(path42.resolve(cwd, file)) === null)
29765
+ if (realPath(path43.resolve(cwd, file)) === null)
29564
29766
  return { file: target, registry: "link" };
29565
29767
  const glob = globbed(cwd, file, state, configs)[0];
29566
29768
  const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
29567
29769
  if (viaGlob)
29568
29770
  return { file: target, registry: viaGlob.registry };
29569
- const registry = hardLinked(path42.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical5) ?? (inRepoLedger(canonical5(path42.resolve(cwd, file))) ? "ledger" : null) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical5)) ? "grants" : null);
29771
+ const registry = hardLinked(path43.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical5) ?? (inRepoLedger(canonical5(path43.resolve(cwd, file))) ? "ledger" : null) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical5)) ? "grants" : null);
29570
29772
  if (registry)
29571
29773
  return { file: target, registry };
29572
29774
  }
@@ -29574,7 +29776,7 @@ var registryTarget = (cwd, targets) => {
29574
29776
  };
29575
29777
  var partsUnder = (dir, cwd, target, platform, real) => {
29576
29778
  const win = platform === "win32";
29577
- const p = win ? path42.win32 : path42.posix;
29779
+ const p = win ? path43.win32 : path43.posix;
29578
29780
  const fold = (value) => win || platform === "darwin" ? value.toLowerCase() : value;
29579
29781
  const named = win ? target.replace(/^\/([a-zA-Z])(?=\/|$)/, "$1:") : target;
29580
29782
  const relative = p.relative(fold(real(p.resolve(dir))), fold(real(p.resolve(cwd, named))));
@@ -29627,6 +29829,11 @@ var REGISTRY_DENY = {
29627
29829
  what: "a symlink chain Workit could not resolve (over 40 links), which may reach a guarded path",
29628
29830
  unblock: "Write to the file's real path."
29629
29831
  },
29832
+ removes: {
29833
+ label: "ledger guard",
29834
+ what: "a Workit ledger, the git dir that holds one or Workit's state",
29835
+ unblock: "Never remove or move `.git`, `.git/workit` or a dir that holds a Workit ledger: the ledger keeps the session's verdicts and pins. Remove the files you made by name."
29836
+ },
29630
29837
  holds: {
29631
29838
  label: "registry guard",
29632
29839
  what: "Workit's state, its config or a repository ledger",
@@ -29655,19 +29862,25 @@ var REGISTRY_DENY = {
29655
29862
  };
29656
29863
  var registryDeny = ({ file, registry }) => {
29657
29864
  const { label, what, unblock } = REGISTRY_DENY[registry];
29658
- if (path42.basename(file) === LINK_SOURCE)
29865
+ if (path43.basename(file) === LINK_SOURCE)
29659
29866
  return {
29660
29867
  kind: "deny",
29661
- reason: `workit ${label}: this command links or mounts ${path42.dirname(file)}, which is or holds ${what}. ${LINK_UNBLOCK}`,
29868
+ reason: `workit ${label}: this command links or mounts ${path43.dirname(file)}, which is or holds ${what}. ${LINK_UNBLOCK}`,
29662
29869
  unblock: LINK_UNBLOCK
29663
29870
  };
29664
- if (path42.basename(file) === UNRESOLVED_TARGET)
29871
+ if (path43.basename(file) === REMOVED_SOURCE)
29872
+ return {
29873
+ kind: "deny",
29874
+ reason: `workit ${label}: this command removes or moves ${path43.dirname(file)}, which is or holds ${what}. ${unblock}`,
29875
+ unblock
29876
+ };
29877
+ if (path43.basename(file) === UNRESOLVED_TARGET)
29665
29878
  return {
29666
29879
  kind: "deny",
29667
29880
  reason: `workit ${label}: Workit could not resolve the file this command's script writes, which it builds from a path under ${what}. ${unblock}`,
29668
29881
  unblock
29669
29882
  };
29670
- const named = path42.basename(file).startsWith(".workit-") ? path42.dirname(file) : file;
29883
+ const named = path43.basename(file).startsWith(".workit-") ? path43.dirname(file) : file;
29671
29884
  return {
29672
29885
  kind: "deny",
29673
29886
  reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
@@ -29758,10 +29971,10 @@ import { spawnSync as spawnSync24 } from "node:child_process";
29758
29971
 
29759
29972
  // packages/workit-core/src/ci-waiter.ts
29760
29973
  import fs29 from "node:fs";
29761
- import path43 from "node:path";
29974
+ import path44 from "node:path";
29762
29975
  var waiterFile = (cwd, pr) => {
29763
29976
  const common = gitCommonDir(cwd);
29764
- return common ? path43.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
29977
+ return common ? path44.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
29765
29978
  };
29766
29979
  var pidAlive2 = (pid) => {
29767
29980
  if (!Number.isSafeInteger(pid) || pid <= 0)
@@ -29833,11 +30046,11 @@ function currentJudgment(cwd) {
29833
30046
  }
29834
30047
 
29835
30048
  // packages/workit-core/src/core/verdict-set.ts
29836
- import path44 from "node:path";
30049
+ import path45 from "node:path";
29837
30050
  var SET_TTL_MS = 7 * 86400000;
29838
30051
  var SET_ROW = "verdict.set";
29839
30052
  var SET_VOID = "verdict.set.voided";
29840
- var setStorePath = () => path44.join(resolveStateDir(), "verdicts", "sets", "ledger.jsonl");
30053
+ var setStorePath = () => path45.join(resolveStateDir(), "verdicts", "sets", "ledger.jsonl");
29841
30054
  var distrusted = (cwd, id, rows, type) => rows.some((row) => row.type === type && row.id === id && trustReasons(cwd, row).length > 0);
29842
30055
  function gateStands(cwd, gate, rows, now = Date.now()) {
29843
30056
  const id = typeof gate.verdictId === "string" ? gate.verdictId : null;
@@ -30324,12 +30537,12 @@ var writePaths = (input) => {
30324
30537
  };
30325
30538
  // packages/workit-core/src/hooks/standing.ts
30326
30539
  import fs31 from "node:fs";
30327
- import path50 from "node:path";
30540
+ import path51 from "node:path";
30328
30541
 
30329
30542
  // packages/workit-core/src/approvals/store.ts
30330
30543
  import { createHash as createHash20, randomBytes as randomBytes4 } from "node:crypto";
30331
- import { mkdirSync as mkdirSync7, readdirSync as readdirSync6, readFileSync as readFileSync13, rmSync as rmSync3 } from "node:fs";
30332
- import path45 from "node:path";
30544
+ import { mkdirSync as mkdirSync7, readdirSync as readdirSync7, readFileSync as readFileSync13, rmSync as rmSync3 } from "node:fs";
30545
+ import path46 from "node:path";
30333
30546
  var REQUEST_TTL_MS = 30 * 60000;
30334
30547
  var GRANT_TTL_MS = 15 * 60000;
30335
30548
  var ID_PATTERN = /^ap_[a-z2-7]{8}$/u;
@@ -30341,10 +30554,10 @@ var approvalHash = (fields) => createHash20("sha256").update(canonicalJson({
30341
30554
  effect: fields.effect,
30342
30555
  subject: fields.subject
30343
30556
  })).digest("hex");
30344
- var approvalsDir = () => path45.join(resolveStateDir(), "approvals");
30345
- var dirOf = (part) => path45.join(approvalsDir(), part);
30346
- var fileOf = (part, id) => path45.join(dirOf(part), `${id}.json`);
30347
- var askedFile = (session, toolUseId) => path45.join(dirOf("asked"), `${createHash20("sha256").update(`${session}\x00${toolUseId}`).digest("hex").slice(0, 32)}.json`);
30557
+ var approvalsDir = () => path46.join(resolveStateDir(), "approvals");
30558
+ var dirOf = (part) => path46.join(approvalsDir(), part);
30559
+ var fileOf = (part, id) => path46.join(dirOf(part), `${id}.json`);
30560
+ var askedFile = (session, toolUseId) => path46.join(dirOf("asked"), `${createHash20("sha256").update(`${session}\x00${toolUseId}`).digest("hex").slice(0, 32)}.json`);
30348
30561
  var readJson3 = (file) => {
30349
30562
  try {
30350
30563
  const value = JSON.parse(readFileSync13(file, "utf8"));
@@ -30354,14 +30567,14 @@ var readJson3 = (file) => {
30354
30567
  }
30355
30568
  };
30356
30569
  var write = (file, value) => {
30357
- mkdirSync7(path45.dirname(file), { recursive: true });
30570
+ mkdirSync7(path46.dirname(file), { recursive: true });
30358
30571
  writeFileAtomic(file, `${JSON.stringify(value, null, 2)}
30359
30572
  `);
30360
30573
  };
30361
30574
  var live = (expires, now) => Date.parse(expires) > now.getTime();
30362
30575
  var names2 = (part) => {
30363
30576
  try {
30364
- return readdirSync6(dirOf(part)).filter((name) => name.endsWith(".json"));
30577
+ return readdirSync7(dirOf(part)).filter((name) => name.endsWith(".json"));
30365
30578
  } catch {
30366
30579
  return [];
30367
30580
  }
@@ -30479,7 +30692,7 @@ var namesTicket = (text) => /WORKIT_APPROVAL_(?:TICKET|UNASKED)/u.test(text.repl
30479
30692
  var TICKET_DENY = "Only the host's prompt adds an approval ticket.";
30480
30693
  var dropInline = (drop) => {
30481
30694
  for (const name of names2("inline")) {
30482
- const file = path45.join(dirOf("inline"), name);
30695
+ const file = path46.join(dirOf("inline"), name);
30483
30696
  const row = readJson3(file);
30484
30697
  if (!row || drop(row))
30485
30698
  rmSync3(file, { force: true });
@@ -30541,12 +30754,12 @@ var approveCallIn = (command, dialect = "posix") => {
30541
30754
  var approveCallDeny = (fix) => `Run \`${fix}\` as its own call: no chain, pipe, substitution, leading cd, env prefix or redirect around it, so the host can show the request and record the user's answer.`;
30542
30755
 
30543
30756
  // packages/workit-core/src/approvals/inline.ts
30544
- import path48 from "node:path";
30757
+ import path49 from "node:path";
30545
30758
 
30546
30759
  // packages/workit-core/src/approvals/release-notes-ask.ts
30547
30760
  import { createHash as createHash21 } from "node:crypto";
30548
30761
  import { existsSync as existsSync17, readFileSync as readFileSync14 } from "node:fs";
30549
- import path46 from "node:path";
30762
+ import path47 from "node:path";
30550
30763
  var sha2563 = (data) => createHash21("sha256").update(data).digest("hex");
30551
30764
  var isReleaseNotesApprove = (words) => words[0] === "notes" && words[1] === "approve";
30552
30765
  var versionOf = (args) => {
@@ -30586,10 +30799,10 @@ var releaseNotesAskAt = (args, cwd) => {
30586
30799
  const common = version ? gitCommonDir(cwd) : null;
30587
30800
  if (!version || !common)
30588
30801
  return null;
30589
- const dir = path46.join(common, "workit", "release-notes");
30802
+ const dir = path47.join(common, "workit", "release-notes");
30590
30803
  for (const file of [
30591
- path46.join(dir, "packages", `${version.replaceAll("/", "%2F")}.md`),
30592
- path46.join(dir, `${version}.md`)
30804
+ path47.join(dir, "packages", `${version.replaceAll("/", "%2F")}.md`),
30805
+ path47.join(dir, `${version}.md`)
30593
30806
  ])
30594
30807
  if (existsSync17(file))
30595
30808
  try {
@@ -30603,7 +30816,7 @@ var releaseNotesAskAt = (args, cwd) => {
30603
30816
  // packages/workit-core/src/approvals/youtrack-ask.ts
30604
30817
  import { createHash as createHash22 } from "node:crypto";
30605
30818
  import { readFileSync as readFileSync15, realpathSync as realpathSync12 } from "node:fs";
30606
- import path47 from "node:path";
30819
+ import path48 from "node:path";
30607
30820
  var TIME = "markdown file minutes text date";
30608
30821
  var FLAGS = {
30609
30822
  note: TIME,
@@ -30647,7 +30860,7 @@ var youTrackAsk = (args, cwd, load = readFileSync15) => {
30647
30860
  const files = [];
30648
30861
  const read = (file) => {
30649
30862
  try {
30650
- const named = path47.resolve(cwd, file);
30863
+ const named = path48.resolve(cwd, file);
30651
30864
  const content = load(named);
30652
30865
  files.push([realpathSync12(named), sha2564(content)]);
30653
30866
  return content;
@@ -30685,7 +30898,7 @@ var youTrackAsk = (args, cwd, load = readFileSync15) => {
30685
30898
  const content = read(file);
30686
30899
  if (!content)
30687
30900
  return null;
30688
- lines.push(`attach: ${path47.basename(file)} (${content.length} bytes)`);
30901
+ lines.push(`attach: ${path48.basename(file)} (${content.length} bytes)`);
30689
30902
  }
30690
30903
  if (!lines.length)
30691
30904
  return null;
@@ -30722,7 +30935,7 @@ var cwdOf = (globals) => {
30722
30935
  }
30723
30936
  return cwd;
30724
30937
  };
30725
- var inlineCallCwd = (call, base) => call.cwd ? path48.resolve(base, call.cwd) : base;
30938
+ var inlineCallCwd = (call, base) => call.cwd ? path49.resolve(base, call.cwd) : base;
30726
30939
  var isReadFilter = (segment) => (segment.words[0] === "tail" || segment.words[0] === "head") && segment.words.slice(1).every((word) => /^(?:-[nc]|-[nc]?\d+|\+?\d+)$/u.test(word)) && !segment.redirects.length && !segment.subs?.length && !segment.stdin?.length && !segment.inputs?.length && !segment.expands?.length && !segment.group && !segment.unanalyzable;
30727
30940
  var onlyFiltersAfter = (segments) => segments[0]?.pipe === true && segments.slice(1).every((segment, index, rest) => isReadFilter(segment) && (index === rest.length - 1 ? !segment.pipe : segment.pipe));
30728
30941
  var inlineCallIn = (command, dialect = "posix") => {
@@ -31245,35 +31458,35 @@ function neededChecks(lane, configured) {
31245
31458
  import { createHash as createHash23 } from "node:crypto";
31246
31459
  import fs30 from "node:fs";
31247
31460
  import os11 from "node:os";
31248
- import path49 from "node:path";
31461
+ import path50 from "node:path";
31249
31462
  var FANOUT_TOKEN_FILE = "workit-fanout-token";
31250
31463
  var NONE5 = { kind: "none" };
31251
31464
  var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
31252
31465
  var realOf = (file) => {
31253
31466
  let rest = "";
31254
- for (let dir = file;; dir = path49.dirname(dir)) {
31467
+ for (let dir = file;; dir = path50.dirname(dir)) {
31255
31468
  try {
31256
- return path49.join(fs30.realpathSync.native(dir), rest);
31469
+ return path50.join(fs30.realpathSync.native(dir), rest);
31257
31470
  } catch {
31258
- if (path49.dirname(dir) === dir)
31471
+ if (path50.dirname(dir) === dir)
31259
31472
  return file;
31260
- rest = rest ? path49.join(path49.basename(dir), rest) : path49.basename(dir);
31473
+ rest = rest ? path50.join(path50.basename(dir), rest) : path50.basename(dir);
31261
31474
  }
31262
31475
  }
31263
31476
  };
31264
31477
  var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
31265
- const start = path49.isAbsolute(file) ? file : `${process.cwd()}${path49.sep}${file}`;
31266
- const { root } = path49.parse(start);
31478
+ const start = path50.isAbsolute(file) ? file : `${process.cwd()}${path50.sep}${file}`;
31479
+ const { root } = path50.parse(start);
31267
31480
  let at = root;
31268
31481
  let missing = false;
31269
31482
  for (const part of start.slice(root.length).split(/[\\/]+/)) {
31270
31483
  if (part === "" || part === ".")
31271
31484
  continue;
31272
31485
  if (part === "..") {
31273
- at = path49.dirname(at);
31486
+ at = path50.dirname(at);
31274
31487
  continue;
31275
31488
  }
31276
- const next = path49.join(at, part);
31489
+ const next = path50.join(at, part);
31277
31490
  let link = null;
31278
31491
  if (!missing)
31279
31492
  try {
@@ -31285,25 +31498,25 @@ var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
31285
31498
  at = next;
31286
31499
  hops.chain = 40;
31287
31500
  } else if (hops.chain-- > 0 && hops.total-- > 0)
31288
- at = canonical6(path49.isAbsolute(link) ? link : `${at}${path49.sep}${link}`, hops);
31501
+ at = canonical6(path50.isAbsolute(link) ? link : `${at}${path50.sep}${link}`, hops);
31289
31502
  else
31290
- return path49.resolve(file);
31503
+ return path50.resolve(file);
31291
31504
  }
31292
31505
  return realOf(at);
31293
31506
  };
31294
31507
  var within = (child, parent) => {
31295
31508
  const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
31296
- const relative = path49.relative(fold(parent), fold(child));
31297
- return relative === "" || !relative.startsWith("..") && !path49.isAbsolute(relative);
31509
+ const relative = path50.relative(fold(parent), fold(child));
31510
+ return relative === "" || !relative.startsWith("..") && !path50.isAbsolute(relative);
31298
31511
  };
31299
31512
  var checkoutOf2 = (file) => {
31300
- for (let dir = canonical6(file);; dir = path49.dirname(dir)) {
31301
- const dotGit = path49.join(dir, ".git");
31513
+ for (let dir = canonical6(file);; dir = path50.dirname(dir)) {
31514
+ const dotGit = path50.join(dir, ".git");
31302
31515
  if (fs30.existsSync(dotGit)) {
31303
31516
  const admin = fs30.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
31304
- return { root: dir, workit: !!admin && fs30.existsSync(path49.join(admin, FANOUT_TOKEN_FILE)) };
31517
+ return { root: dir, workit: !!admin && fs30.existsSync(path50.join(admin, FANOUT_TOKEN_FILE)) };
31305
31518
  }
31306
- if (path49.dirname(dir) === dir)
31519
+ if (path50.dirname(dir) === dir)
31307
31520
  return null;
31308
31521
  }
31309
31522
  };
@@ -31315,8 +31528,8 @@ var workitWorktreeOf = (file) => {
31315
31528
  return null;
31316
31529
  }
31317
31530
  };
31318
- var bindingDir = () => path49.join(resolveStateDir(), "worktree-bind");
31319
- var bindingFile = (session, agentId) => path49.join(bindingDir(), `${createHash23("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
31531
+ var bindingDir = () => path50.join(resolveStateDir(), "worktree-bind");
31532
+ var bindingFile = (session, agentId) => path50.join(bindingDir(), `${createHash23("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
31320
31533
  var readBinding = (file) => {
31321
31534
  try {
31322
31535
  const value = JSON.parse(fs30.readFileSync(file, "utf8"));
@@ -31341,7 +31554,7 @@ var bind = (input, worktree) => {
31341
31554
  agentId,
31342
31555
  at: new Date().toISOString()
31343
31556
  };
31344
- fs30.mkdirSync(path49.dirname(file), { recursive: true });
31557
+ fs30.mkdirSync(path50.dirname(file), { recursive: true });
31345
31558
  fs30.writeFileSync(file, JSON.stringify(binding));
31346
31559
  try {
31347
31560
  if (inWorkitWorkspace(input.cwd))
@@ -31360,26 +31573,26 @@ var hostIsolated = (cwd, agentId) => {
31360
31573
  const checkout = checkoutOf2(cwd);
31361
31574
  if (!checkout)
31362
31575
  return false;
31363
- const dotGit = path49.join(checkout.root, ".git");
31576
+ const dotGit = path50.join(checkout.root, ".git");
31364
31577
  if (!fs30.statSync(dotGit).isFile())
31365
31578
  return false;
31366
31579
  const [adminDir, gitDir] = gitDirsAt(checkout.root, null, false) ?? [];
31367
- const back = fs30.readFileSync(path49.join(adminDir, "gitdir"), "utf8").trim();
31368
- if (path49.relative(canonical6(path49.resolve(adminDir, back)), canonical6(dotGit)) !== "")
31580
+ const back = fs30.readFileSync(path50.join(adminDir, "gitdir"), "utf8").trim();
31581
+ if (path50.relative(canonical6(path50.resolve(adminDir, back)), canonical6(dotGit)) !== "")
31369
31582
  return false;
31370
- const expected = path49.join(path49.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
31371
- return path49.relative(canonical6(expected), checkout.root) === "";
31583
+ const expected = path50.join(path50.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
31584
+ return path50.relative(canonical6(expected), checkout.root) === "";
31372
31585
  } catch {
31373
31586
  return false;
31374
31587
  }
31375
31588
  };
31376
31589
  var runnerAt = (target) => {
31377
- const base = path49.basename(target);
31590
+ const base = path50.basename(target);
31378
31591
  return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
31379
31592
  };
31380
31593
  var shown = (target) => {
31381
- const named = /^\.workit-(?:live-target$|runs-)/.test(path49.basename(target)) ? path49.dirname(target) : target;
31382
- return path49.sep === "\\" ? named.replaceAll("/", "\\") : named;
31594
+ const named = /^\.workit-(?:live-target$|runs-)/.test(path50.basename(target)) ? path50.dirname(target) : target;
31595
+ return path50.sep === "\\" ? named.replaceAll("/", "\\") : named;
31383
31596
  };
31384
31597
  var runFrom = (dir, command) => `cd ${dir} && ${command.replace(/^\s*cd\s+\S+\s*(?:&&|;)\s*/, "")}`;
31385
31598
  var deny2 = (what, unblock) => ({
@@ -31395,7 +31608,7 @@ var outsideDeny = (input, worktree, target, command) => {
31395
31608
  };
31396
31609
  var unknownDirDeny = (input, worktree) => deny2(`workit worktree confinement: implementer ${input.session.agentId} writes after a directory change Workit cannot resolve (\`cd -\`, \`cd "$X"\`, \`popd\`)`, `Why: write by absolute path, \`git -C ${worktree ?? "<worktree>"}\` or \`workit <verb> --cwd\`.`);
31397
31610
  var refsOf = (targets) => [
31398
- ...new Set(targets.flatMap((target) => path49.relative(UNKNOWN_VAR, path49.resolve(target)).split(path49.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
31611
+ ...new Set(targets.flatMap((target) => path50.relative(UNKNOWN_VAR, path50.resolve(target)).split(path50.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
31399
31612
  ];
31400
31613
  var literalForm = (command, refs) => {
31401
31614
  let text = command;
@@ -31428,10 +31641,10 @@ function confineImplementer(input, targets, command) {
31428
31641
  try {
31429
31642
  if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
31430
31643
  return NONE5;
31431
- const unresolved = targets.filter((target) => within(path49.resolve(target), UNKNOWN_VAR));
31644
+ const unresolved = targets.filter((target) => within(path50.resolve(target), UNKNOWN_VAR));
31432
31645
  if (unresolved.length > 0)
31433
31646
  return unknownVarDeny(input, unresolved, command);
31434
- if (targets.some((target) => within(path49.resolve(target), UNKNOWN_DIR)))
31647
+ if (targets.some((target) => within(path50.resolve(target), UNKNOWN_DIR)))
31435
31648
  return unknownDirDeny(input, boundWorktree(input));
31436
31649
  const bindings = canonical6(bindingDir());
31437
31650
  const judged = targets.map((named) => ({ named, real: canonical6(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
@@ -31538,10 +31751,10 @@ var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print)(?:=|$)|^--(?:test|version|he
31538
31751
  var VALUED2 = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
31539
31752
  var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
31540
31753
  var inScratch = (real, repo) => {
31541
- for (let dir = real;path49.dirname(dir) !== dir; dir = path49.dirname(dir)) {
31542
- if (path49.basename(dir) !== SCRATCH)
31754
+ for (let dir = real;path50.dirname(dir) !== dir; dir = path50.dirname(dir)) {
31755
+ if (path50.basename(dir) !== SCRATCH)
31543
31756
  continue;
31544
- const root = path49.dirname(dir);
31757
+ const root = path50.dirname(dir);
31545
31758
  const checkout = checkoutOf2(root);
31546
31759
  if (checkout?.root === root && (repo === null || checkout.workit || commonDir(root) === repo))
31547
31760
  return true;
@@ -31551,7 +31764,7 @@ var inScratch = (real, repo) => {
31551
31764
  var inGitDir = (real) => real.split(/[\\/]/).includes(".git");
31552
31765
  var SAFE_KEY = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|ignorecase|precomposeunicode|symlinks)|user\..*|init\.defaultbranch|commit\.gpgsign|extensions\.(?:objectformat|refstorage)|branch\..*\.(?:remote|merge)|remote\..*\.fetch)$/;
31553
31766
  var literalIn = (value, repo, checkout = false) => {
31554
- if (/[$`]/.test(value) || !path49.isAbsolute(value))
31767
+ if (/[$`]/.test(value) || !path50.isAbsolute(value))
31555
31768
  return false;
31556
31769
  const real = canonical6(value);
31557
31770
  const root = checkout ? checkoutOf2(real)?.root : undefined;
@@ -31572,8 +31785,8 @@ var configEntries = (text) => {
31572
31785
  return entries;
31573
31786
  };
31574
31787
  function gitDirsAt(dir, repo, scan = true) {
31575
- for (let at = dir;; at = path49.dirname(at)) {
31576
- const dotGit = path49.join(at, ".git");
31788
+ for (let at = dir;; at = path50.dirname(at)) {
31789
+ const dotGit = path50.join(at, ".git");
31577
31790
  let gitDir = null;
31578
31791
  try {
31579
31792
  if (fs30.statSync(dotGit).isDirectory())
@@ -31582,19 +31795,19 @@ function gitDirsAt(dir, repo, scan = true) {
31582
31795
  const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs30.readFileSync(dotGit, "utf8"))?.[1];
31583
31796
  if (!named)
31584
31797
  return null;
31585
- gitDir = canonical6(path49.resolve(at, named));
31798
+ gitDir = canonical6(path50.resolve(at, named));
31586
31799
  }
31587
31800
  } catch (error) {
31588
31801
  if (error.code !== "ENOENT")
31589
31802
  return null;
31590
- if (["HEAD", "objects", "refs"].every((name) => fs30.existsSync(path49.join(at, name))))
31803
+ if (["HEAD", "objects", "refs"].every((name) => fs30.existsSync(path50.join(at, name))))
31591
31804
  gitDir = canonical6(at);
31592
31805
  }
31593
31806
  if (gitDir !== null) {
31594
- const common = path49.join(gitDir, "commondir");
31595
- const shared = fs30.existsSync(common) ? canonical6(path49.resolve(gitDir, fs30.readFileSync(common, "utf8").trim())) : gitDir;
31807
+ const common = path50.join(gitDir, "commondir");
31808
+ const shared = fs30.existsSync(common) ? canonical6(path50.resolve(gitDir, fs30.readFileSync(common, "utf8").trim())) : gitDir;
31596
31809
  const dirs = [gitDir, shared];
31597
- for (const config of scan ? new Set([path49.join(gitDir, "config"), path49.join(shared, "config")]) : []) {
31810
+ for (const config of scan ? new Set([path50.join(gitDir, "config"), path50.join(shared, "config")]) : []) {
31598
31811
  let text = "";
31599
31812
  try {
31600
31813
  text = fs30.readFileSync(config, "utf8");
@@ -31603,14 +31816,14 @@ function gitDirsAt(dir, repo, scan = true) {
31603
31816
  }
31604
31817
  for (const [key, value] of configEntries(text)) {
31605
31818
  if (key === "core.worktree")
31606
- dirs.push(canonical6(path49.resolve(gitDir, value)));
31819
+ dirs.push(canonical6(path50.resolve(gitDir, value)));
31607
31820
  else if (/^remote\..*\.url$/.test(key) ? !literalIn(value, repo, true) : !SAFE_KEY.test(key))
31608
31821
  return null;
31609
31822
  }
31610
31823
  }
31611
31824
  return dirs;
31612
31825
  }
31613
- if (path49.dirname(at) === at)
31826
+ if (path50.dirname(at) === at)
31614
31827
  return [];
31615
31828
  }
31616
31829
  }
@@ -31750,10 +31963,10 @@ var gitKind = (args, local = () => true) => {
31750
31963
  return GIT_VERBS[verb].startsWith("+") ? "write" : "read";
31751
31964
  };
31752
31965
  var remoteIn = (dir, name, repo) => {
31753
- const shared = path49.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
31966
+ const shared = path50.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
31754
31967
  if (!shared)
31755
31968
  return false;
31756
- const url = configEntries(fs30.readFileSync(path49.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
31969
+ const url = configEntries(fs30.readFileSync(path50.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
31757
31970
  return url !== undefined && literalIn(url, repo, true);
31758
31971
  };
31759
31972
  var judgeEnvAllowed = (word) => {
@@ -31782,7 +31995,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
31782
31995
  at = after;
31783
31996
  }
31784
31997
  }
31785
- const name = path49.basename(words[at] ?? "");
31998
+ const name = path50.basename(words[at] ?? "");
31786
31999
  let start = words.findIndex((word) => /(?:^|[\\/])git(?:\.exe)?(?:=|$)/.test(word));
31787
32000
  if (start > at) {
31788
32001
  if (/^(?:grep|egrep|rg|echo|printf|ls|wc|head|tail|cat|which|type|test|\[|cd|mkdir)$/.test(name) || name === "command" && /^-[vV]$/.test(words[at + 1] ?? ""))
@@ -31793,7 +32006,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
31793
32006
  if (start >= 0 && words[start].includes("="))
31794
32007
  why = "git is redefined";
31795
32008
  const run = words[start] ?? "";
31796
- if (run.includes("/") && (!path49.isAbsolute(run) || literalIn(run, repo, true)))
32009
+ if (run.includes("/") && (!path50.isAbsolute(run) || literalIn(run, repo, true)))
31797
32010
  why ??= `\`${run}\` is not the system git`;
31798
32011
  if (segment.expands?.includes(at) && name !== "[" || /\{[^}]*,/.test(words[at] ?? ""))
31799
32012
  why = "the command's name is expanded by the shell";
@@ -31818,13 +32031,13 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
31818
32031
  const args = words[index] === "--version" ? ["version"] : words.slice(index);
31819
32032
  if (!why && start >= 0) {
31820
32033
  const local = (source, remote) => remote && /^[\w-][\w.-]*$/.test(source) ? remoteIn(dir, source, repo) : literalIn(source, repo, true);
31821
- const runsIn = path49.isAbsolute(dir) ? dir : cwd && path49.resolve(cwd, dir);
32034
+ const runsIn = path50.isAbsolute(dir) ? dir : cwd && path50.resolve(cwd, dir);
31822
32035
  const home = runsIn && checkoutOf2(runsIn);
31823
32036
  const fetches = args[0] === "fetch" && plainFetch(args.slice(1)) && home && (home.workit || commonDir(home.root) === repo) && !words.some((word) => /^--[gw]/.test(word));
31824
32037
  if (!fetches && !gitKind(args, local))
31825
32038
  why = `\`git ${args.slice(0, 2).join(" ")}\` is not allowed`;
31826
32039
  }
31827
- const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path49.basename(word)));
32040
+ const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path50.basename(word)));
31828
32041
  const scripts = [
31829
32042
  ...words.filter((_, after) => shell >= 0 && after > shell && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(words[after - 1])),
31830
32043
  ...shell < 0 ? [] : segment.stdin ?? []
@@ -31869,7 +32082,7 @@ var judgeVerbRefused = (args) => {
31869
32082
  var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
31870
32083
  var CLI_ENTRY = /(?:^|[=\\/])(?:workit(?:\.(?:exe|cmd|[cm]?js))?|@workit-dev\/cli(?:@\S*)?)$|(?:workit-cli|@workit-dev[\\/]cli)[\\/](?:src[\\/](?:index|main)|dist[\\/]index)\.[cm]?[jt]sx?$/;
31871
32084
  var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
31872
- const name = path49.basename(words[0] ?? "").toLowerCase();
32085
+ const name = path50.basename(words[0] ?? "").toLowerCase();
31873
32086
  if (name === "alias")
31874
32087
  return words.flatMap((word) => {
31875
32088
  const set = /^([\w-]+)=(.*)$/s.exec(word);
@@ -31898,11 +32111,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
31898
32111
  return why;
31899
32112
  }
31900
32113
  const { words } = segment;
31901
- const runs = (word = "") => RUNS.test(path49.basename(word).toLowerCase());
32114
+ const runs = (word = "") => RUNS.test(path50.basename(word).toLowerCase());
31902
32115
  let at = 0;
31903
32116
  while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
31904
32117
  at++;
31905
- const name = path49.basename(words[at] ?? "").toLowerCase();
32118
+ const name = path50.basename(words[at] ?? "").toLowerCase();
31906
32119
  const args = words.slice(at + 1);
31907
32120
  const unseen = `\`${words.join(" ").slice(0, 80)}\` runs a script Workit cannot read (piped, on stdin, a process substitution or eval): write the case to a file in ${SCRATCH} and dispatch it from a test instead`;
31908
32121
  if (/^(?:cd|chdir|pushd|popd)$/.test(name))
@@ -31984,10 +32197,10 @@ var judgeDeny = (input, what, target, retry, why = "write only there (mkdir -p i
31984
32197
  const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
31985
32198
  const root = checkoutOf2(input.cwd)?.root;
31986
32199
  const candidate = target ? checkoutOf2(target)?.root : undefined;
31987
- const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path49.join(candidate, SCRATCH) : undefined;
31988
- const scratch = root ? `${path49.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
31989
- const call = root ? retry?.((other ?? path49.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
31990
- const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ? path49.join(root, SCRATCH) : SCRATCH))}`;
32200
+ const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path50.join(candidate, SCRATCH) : undefined;
32201
+ const scratch = root ? `${path50.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
32202
+ const call = root ? retry?.((other ?? path50.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
32203
+ const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ? path50.join(root, SCRATCH) : SCRATCH))}`;
31991
32204
  return {
31992
32205
  kind: "deny",
31993
32206
  reason: `workit scratch confinement: ${role} ${input.session.agentId} may write only in its scratch dir ${scratch}, and ${what}.
@@ -31997,9 +32210,9 @@ ${unblock}`,
31997
32210
  };
31998
32211
  var movedInto = (command, cwd, target, dir) => {
31999
32212
  for (const { words, redirects } of segmentsOf(command))
32000
- for (const word of [...redirects, ...path49.basename(words[0] ?? "") === "tee" ? words : []])
32001
- if (path49.resolve(cwd, word) === path49.resolve(cwd, target)) {
32002
- const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path49.basename(word)}`);
32213
+ for (const word of [...redirects, ...path50.basename(words[0] ?? "") === "tee" ? words : []])
32214
+ if (path50.resolve(cwd, word) === path50.resolve(cwd, target)) {
32215
+ const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path50.basename(word)}`);
32003
32216
  return moved === command ? null : moved;
32004
32217
  }
32005
32218
  return null;
@@ -32011,19 +32224,19 @@ function confineJudge(input, targets, placeholders = placeholdersOf(targets), co
32011
32224
  const judged = checkoutOf2(input.cwd);
32012
32225
  const repo = judged ? commonDir(judged.root) : null;
32013
32226
  const scratch = (real) => inScratch(real, repo) || [os11.tmpdir(), "/tmp"].some((dir) => {
32014
- const [host, , session] = path49.relative(canonical6(dir), real).split(path49.sep);
32227
+ const [host, , session] = path50.relative(canonical6(dir), real).split(path50.sep);
32015
32228
  return /^claude-\d+$/.test(host) && session === input.session.id;
32016
32229
  });
32017
32230
  for (const target of targets) {
32018
- const resolved = path49.resolve(target);
32231
+ const resolved = path50.resolve(target);
32019
32232
  if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
32020
32233
  return judgeDeny(input, "it writes to a path Workit cannot resolve", undefined, () => {
32021
32234
  const literal = command && literalForm(command, refsOf([target]));
32022
32235
  return literal === command ? null : literal;
32023
32236
  });
32024
32237
  const real = canonical6(target);
32025
- const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path49.basename(target));
32026
- const gitDirs = runsGit ? gitDirsAt(path49.dirname(real), repo) : [];
32238
+ const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path50.basename(target));
32239
+ const gitDirs = runsGit ? gitDirsAt(path50.dirname(real), repo) : [];
32027
32240
  if (gitDirs === null)
32028
32241
  return judgeDeny(input, `git in ${shown(target)} uses a git dir or config Workit cannot check`);
32029
32242
  if (runsGit ? gitDirs.length > 0 ? gitDirs.every(scratch) : scratch(real) : scratch(real) && !inGitDir(real))
@@ -32091,7 +32304,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
32091
32304
  let git = [];
32092
32305
  try {
32093
32306
  git = rawInvocations(command, dialect).flatMap(({ tool, dir, args }) => tool === "git" && (args[0] === "push" || leadOwnedGit(args) || gitKind(args) === "write" && !/^(?:init|clone)$/.test(args[0]) && !(args[0] === "fetch" && plainFetch(args.slice(1)))) ? [
32094
- path49.join(dir === undefined ? UNKNOWN_DIR : path49.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
32307
+ path50.join(dir === undefined ? UNKNOWN_DIR : path50.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
32095
32308
  ] : []);
32096
32309
  } catch {}
32097
32310
  const lists = [
@@ -32136,7 +32349,7 @@ var judgeChecksLine = (cwd) => {
32136
32349
 
32137
32350
  // packages/workit-core/src/hooks/standing.ts
32138
32351
  var readPlans = (store) => {
32139
- const dir = path50.join(store, "fanouts");
32352
+ const dir = path51.join(store, "fanouts");
32140
32353
  let names;
32141
32354
  try {
32142
32355
  names = fs31.readdirSync(dir).filter((name) => name.endsWith(".json"));
@@ -32146,7 +32359,7 @@ var readPlans = (store) => {
32146
32359
  const plans = [];
32147
32360
  for (const name of names) {
32148
32361
  try {
32149
- const raw = JSON.parse(fs31.readFileSync(path50.join(dir, name), "utf8"));
32362
+ const raw = JSON.parse(fs31.readFileSync(path51.join(dir, name), "utf8"));
32150
32363
  if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
32151
32364
  continue;
32152
32365
  const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
@@ -32356,12 +32569,12 @@ var cdWorkitSplit = (command) => {
32356
32569
 
32357
32570
  // packages/workit-core/src/hooks/spawn-gate.ts
32358
32571
  import fs32 from "node:fs";
32359
- import path52 from "node:path";
32572
+ import path53 from "node:path";
32360
32573
 
32361
32574
  // packages/workit-core/src/hooks/model-limit.ts
32362
- import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync7, readSync, statSync as statSync5 } from "node:fs";
32575
+ import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync8, readSync, statSync as statSync5 } from "node:fs";
32363
32576
  import os12 from "node:os";
32364
- import path51 from "node:path";
32577
+ import path52 from "node:path";
32365
32578
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
32366
32579
  var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
32367
32580
  var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
@@ -32559,17 +32772,17 @@ var firstPrompt = (file) => {
32559
32772
  var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
32560
32773
  var listDir = (dir) => {
32561
32774
  try {
32562
- return readdirSync7(dir).map((name) => path51.join(dir, name));
32775
+ return readdirSync8(dir).map((name) => path52.join(dir, name));
32563
32776
  } catch {
32564
32777
  return [];
32565
32778
  }
32566
32779
  };
32567
32780
  var SCAN_MS = 30 * 60000;
32568
32781
  var scanClaudeTranscripts = (cwd, env, now = new Date) => {
32569
- const projects = path51.join(env.CLAUDE_CONFIG_DIR || path51.join(env.HOME || os12.homedir(), ".claude"), "projects");
32570
- const project = path51.join(projects, claudeProjectSlug(cwd));
32782
+ const projects = path52.join(env.CLAUDE_CONFIG_DIR || path52.join(env.HOME || os12.homedir(), ".claude"), "projects");
32783
+ const project = path52.join(projects, claudeProjectSlug(cwd));
32571
32784
  const notes = [];
32572
- const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path51.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
32785
+ const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path52.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
32573
32786
  for (const { file, worker } of files)
32574
32787
  try {
32575
32788
  const stat = statSync5(file);
@@ -32584,7 +32797,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
32584
32797
  if (!seen)
32585
32798
  continue;
32586
32799
  notes.push(worker ? redispatchNote(seen, {
32587
- label: `worker ${path51.basename(file, ".jsonl")}`,
32800
+ label: `worker ${path52.basename(file, ".jsonl")}`,
32588
32801
  prompt: firstPrompt(file)
32589
32802
  }, now) : `Workit: this session hit a usage limit (${seen.reason}); ${seen.key} is marked exhausted until ${shortTime(seen.until)}. Claude Code runs only Anthropic models: Workit cannot switch this session, so continue on another host or after the reset.`);
32590
32803
  } catch {}
@@ -32686,10 +32899,10 @@ var namesMade = (word) => {
32686
32899
  const stat = fs32.statSync(word);
32687
32900
  if (stat.isFile())
32688
32901
  return stat.size < 1e6 && MADE_WORKTREE.test(fs32.readFileSync(word, "utf8"));
32689
- const dotGit = path52.join(word, ".git");
32902
+ const dotGit = path53.join(word, ".git");
32690
32903
  const link = fs32.statSync(dotGit);
32691
32904
  const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs32.readFileSync(dotGit, "utf8"));
32692
- return !!admin && fs32.existsSync(path52.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
32905
+ return !!admin && fs32.existsSync(path53.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
32693
32906
  } catch {
32694
32907
  return false;
32695
32908
  }
@@ -32735,8 +32948,8 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
32735
32948
 
32736
32949
  // packages/workit-core/src/hooks/server-gate.ts
32737
32950
  import fs33 from "node:fs";
32738
- import path53 from "node:path";
32739
- var procNoticeFile = (env, session) => path53.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
32951
+ import path54 from "node:path";
32952
+ var procNoticeFile = (env, session) => path54.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
32740
32953
  var mb = (bytes) => `${Math.round(Number(bytes) / 1048576)} MB`;
32741
32954
  function takeProcNotice(session, env = process.env) {
32742
32955
  if (!session)
@@ -32774,21 +32987,21 @@ function takeProcNotice(session, env = process.env) {
32774
32987
  // packages/workit-core/src/hooks/teardown.ts
32775
32988
  import { spawn } from "node:child_process";
32776
32989
  import fs34 from "node:fs";
32777
- import path55 from "node:path";
32990
+ import path56 from "node:path";
32778
32991
 
32779
32992
  // packages/workit-core/src/core/cli-locate.ts
32780
32993
  import { closeSync as closeSync5, existsSync as existsSync18, openSync as openSync5, readSync as readSync2 } from "node:fs";
32781
- import path54 from "node:path";
32994
+ import path55 from "node:path";
32782
32995
  var LAUNCHER_MARKER = "workit-owned-launcher";
32783
32996
  var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
32784
32997
  var installRoot = (env, platform = process.platform) => {
32785
32998
  if (env.WORKIT_INSTALL_ROOT)
32786
32999
  return env.WORKIT_INSTALL_ROOT;
32787
33000
  const data = dataDir(env, platform);
32788
- return platform === "win32" ? path54.join(data, "install") : data;
33001
+ return platform === "win32" ? path55.join(data, "install") : data;
32789
33002
  };
32790
- var ownedLauncherPath = (env, platform = process.platform) => path54.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
32791
- var ownedCurrentEntry = (env, platform = process.platform) => path54.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
33003
+ var ownedLauncherPath = (env, platform = process.platform) => path55.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
33004
+ var ownedCurrentEntry = (env, platform = process.platform) => path55.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
32792
33005
  var head = (file) => {
32793
33006
  let fd;
32794
33007
  try {
@@ -32815,7 +33028,7 @@ var locateWorkitCli = (options = {}) => {
32815
33028
  source: "owned-launcher",
32816
33029
  command: launcher,
32817
33030
  args: [],
32818
- binDir: path54.dirname(launcher)
33031
+ binDir: path55.dirname(launcher)
32819
33032
  };
32820
33033
  const current = ownedCurrentEntry(env, platform);
32821
33034
  if (exists(current))
@@ -32844,7 +33057,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
32844
33057
  if (located.binDir) {
32845
33058
  const key = pathKey(env);
32846
33059
  const delimiter = platform === "win32" ? ";" : ":";
32847
- const same = (dir) => platform === "win32" ? path54.win32.normalize(dir).toLowerCase() === path54.win32.normalize(located.binDir).toLowerCase() : path54.posix.normalize(dir) === path54.posix.normalize(located.binDir);
33060
+ const same = (dir) => platform === "win32" ? path55.win32.normalize(dir).toLowerCase() === path55.win32.normalize(located.binDir).toLowerCase() : path55.posix.normalize(dir) === path55.posix.normalize(located.binDir);
32848
33061
  const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
32849
33062
  patch[key] = [located.binDir, ...rest].join(delimiter);
32850
33063
  }
@@ -32868,9 +33081,9 @@ var ENDS = {
32868
33081
  };
32869
33082
  var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
32870
33083
  var HOST_SESSION_VARS2 = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
32871
- var teardownDir = (env) => path55.join(stateDir(env), "procs");
32872
- var teardownLog = (env) => path55.join(teardownDir(env), "teardown.log");
32873
- var reapStamp = (env) => path55.join(teardownDir(env), "reap-at-start.stamp");
33084
+ var teardownDir = (env) => path56.join(stateDir(env), "procs");
33085
+ var teardownLog = (env) => path56.join(teardownDir(env), "teardown.log");
33086
+ var reapStamp = (env) => path56.join(teardownDir(env), "reap-at-start.stamp");
32874
33087
  function spawnDetached(request) {
32875
33088
  try {
32876
33089
  const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
@@ -32897,7 +33110,7 @@ var teardownDeps = {
32897
33110
  var openLog = (env, args) => {
32898
33111
  try {
32899
33112
  const file = teardownLog(env);
32900
- fs34.mkdirSync(path55.dirname(file), { recursive: true });
33113
+ fs34.mkdirSync(path56.dirname(file), { recursive: true });
32901
33114
  let size = 0;
32902
33115
  try {
32903
33116
  size = fs34.statSync(file).size;
@@ -32982,7 +33195,7 @@ function reapAtStart(_cwd, env = process.env) {
32982
33195
  try {
32983
33196
  if (fresh(stamp, now))
32984
33197
  return false;
32985
- fs34.mkdirSync(path55.dirname(stamp), { recursive: true });
33198
+ fs34.mkdirSync(path56.dirname(stamp), { recursive: true });
32986
33199
  if (!claim2(lock, now))
32987
33200
  return false;
32988
33201
  } catch {
@@ -33674,11 +33887,11 @@ Retry as: ${retry}`,
33674
33887
  // packages/workit-core/src/agent-stamp.ts
33675
33888
  import { createHash as createHash24, randomBytes as randomBytes5 } from "node:crypto";
33676
33889
  import fs35 from "node:fs";
33677
- import path56 from "node:path";
33890
+ import path57 from "node:path";
33678
33891
  var STAMP_TTL_MS = 120000;
33679
33892
  var AGENT_ID = /^[\w-]{1,64}$/u;
33680
33893
  var hash2 = (text) => createHash24("sha256").update(text).digest("hex").slice(0, 32);
33681
- var stampDir = (env, session) => path56.join(stateDir(env), "agent-stamps", hash2(session));
33894
+ var stampDir = (env, session) => path57.join(stateDir(env), "agent-stamps", hash2(session));
33682
33895
  var workitCalls2 = (command, dialect = "posix") => {
33683
33896
  const calls = [];
33684
33897
  try {
@@ -33703,9 +33916,9 @@ var noteAgentStamps = (env, session, agentId, command, options = {}) => {
33703
33916
  fs35.mkdirSync(dir, { recursive: true, mode: 448 });
33704
33917
  const now = Date.now();
33705
33918
  for (const name of fs35.readdirSync(dir))
33706
- if (now - fs35.statSync(path56.join(dir, name)).mtimeMs > STAMP_TTL_MS)
33707
- fs35.rmSync(path56.join(dir, name), { force: true });
33708
- calls.forEach((argv, index) => fs35.writeFileSync(path56.join(dir, `${hash2(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
33919
+ if (now - fs35.statSync(path57.join(dir, name)).mtimeMs > STAMP_TTL_MS)
33920
+ fs35.rmSync(path57.join(dir, name), { force: true });
33921
+ calls.forEach((argv, index) => fs35.writeFileSync(path57.join(dir, `${hash2(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
33709
33922
  } catch {}
33710
33923
  };
33711
33924
  var callTag = (toolUseId) => hash2(toolUseId).slice(0, 8);
@@ -33717,18 +33930,479 @@ var dropAgentStamps = (env, session, toolUseId, command) => {
33717
33930
  const tag = `.${callTag(toolUseId)}-`;
33718
33931
  for (const name of fs35.readdirSync(dir))
33719
33932
  if (name.includes(tag))
33720
- fs35.rmSync(path56.join(dir, name), { force: true });
33933
+ fs35.rmSync(path57.join(dir, name), { force: true });
33721
33934
  } catch {}
33722
33935
  };
33723
33936
 
33937
+ // packages/workit-core/src/hooks/hook-entry.ts
33938
+ import { existsSync as existsSync19, readFileSync as readFileSync16, realpathSync as realpathSync13 } from "node:fs";
33939
+ import path58 from "node:path";
33940
+ var ENTRY_NAMES = /^(?:workit-hook(?:-[\w-]+)?\.(?:m?js|ts)|cursor-session-start\.js|workit-(?:codex|cursor)-hook|workit-cursor-session-start)(?:\.(?:cmd|ps1|exe))?$/iu;
33941
+ var PACKAGE_ENTRIES = {
33942
+ "claude-code": /^(?:bin\/workit-hook\.mjs|src\/(?:run|hook)\.ts|dist\/workit-hook\.js)$/u,
33943
+ codex: /^(?:hooks\/(?:launcher|workit-hook)\.ts|dist\/workit-hook(?:-[\w-]+)?\.js)$/u,
33944
+ cursor: /^(?:hooks\/(?:launch|launch-runtime)\.mjs|hooks\/(?:workit-hook|session-start|subagent-start)\.ts|dist\/(?:workit-hook|cursor-session-start)\.js)$/u,
33945
+ core: /^src\/hooks\/run\.ts$/u
33946
+ };
33947
+ var RUNNERS2 = new Set([
33948
+ "node",
33949
+ "nodejs",
33950
+ "bun",
33951
+ "deno",
33952
+ "tsx",
33953
+ "ts-node",
33954
+ "sh",
33955
+ "bash",
33956
+ "zsh",
33957
+ "dash",
33958
+ "ksh",
33959
+ "fish",
33960
+ "source",
33961
+ "."
33962
+ ]);
33963
+ var PACKAGE_RUNNERS2 = new Set(["npx", "bunx", "pnpx"]);
33964
+ var NO_RUN = new Set([
33965
+ "build",
33966
+ "test",
33967
+ "fmt",
33968
+ "lint",
33969
+ "check",
33970
+ "doc",
33971
+ "info",
33972
+ "install",
33973
+ "add",
33974
+ "pm"
33975
+ ]);
33976
+ var MORE_WRAPPERS = new Set(["strace", "ltrace", "watch", "unshare", "firejail", "xargs", "&"]);
33977
+ var baseName3 = (word) => (word.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "").toLowerCase();
33978
+ var packageAt = (dir) => {
33979
+ try {
33980
+ const name = JSON.parse(readFileSync16(path58.join(dir, "package.json"), "utf8")).name;
33981
+ const short = /^@workit-dev\/(claude-code|codex|cursor|core)$/u.exec(String(name))?.[1];
33982
+ if (short)
33983
+ return short;
33984
+ } catch {}
33985
+ for (const [manifest, short] of [
33986
+ [".claude-plugin", "claude-code"],
33987
+ [".codex-plugin", "codex"],
33988
+ [".cursor-plugin", "cursor"]
33989
+ ]) {
33990
+ try {
33991
+ const name = JSON.parse(readFileSync16(path58.join(dir, manifest, "plugin.json"), "utf8")).name;
33992
+ if (name === "workit")
33993
+ return short;
33994
+ } catch {}
33995
+ }
33996
+ return null;
33997
+ };
33998
+ var entryByPath = (file) => {
33999
+ let dir = path58.dirname(file);
34000
+ for (let depth = 0;depth < 4; depth += 1, dir = path58.dirname(dir)) {
34001
+ const short = packageAt(dir);
34002
+ if (short)
34003
+ return PACKAGE_ENTRIES[short]?.test(path58.relative(dir, file).split(path58.sep).join("/")) ?? false;
34004
+ if (existsSync19(path58.join(dir, "package.json")))
34005
+ return false;
34006
+ }
34007
+ return false;
34008
+ };
34009
+ var literalSub = (match, inner) => {
34010
+ try {
34011
+ const [only, ...rest] = segmentsOf(inner);
34012
+ const [verb = "", ...args] = only?.words ?? [];
34013
+ const last = args.findLast((arg) => !arg.startsWith("-"));
34014
+ return rest.length === 0 && /^(?:echo|printf|ls|realpath|readlink)$/u.test(baseName3(verb)) && last ? last : match;
34015
+ } catch {
34016
+ return match;
34017
+ }
34018
+ };
34019
+ var expand = (word, vars) => word.replace(/\$\(([^()]*)\)|`([^`]*)`/gu, (match, sub, tick) => literalSub(match, sub ?? tick ?? "")).replace(/\$\{(\w+)\}|\$(\w+)/gu, (match, braced, bare) => {
34020
+ const name = braced ?? bare ?? "";
34021
+ return vars.get(name) ?? process.env[name] ?? match;
34022
+ }).replace(/^~(?=[\\/]|$)/u, userHome(process.env));
34023
+ var entryNamed = (word, scan) => {
34024
+ if (!word)
34025
+ return null;
34026
+ const text = expand(word, scan.vars);
34027
+ if (ENTRY_NAMES.test(baseName3(text)))
34028
+ return text;
34029
+ const fd = /^\/(?:dev|proc\/self)\/fd\/(\d+)$/u.exec(text)?.[1];
34030
+ if (fd !== undefined && scan.fds.has(fd))
34031
+ return text;
34032
+ if (scan.dir === null && !path58.isAbsolute(text))
34033
+ return null;
34034
+ for (const file of expandGlob(path58.resolve(scan.dir ?? "/", text))) {
34035
+ if (scan.links.has(file) || entryByPath(file))
34036
+ return text;
34037
+ let real;
34038
+ try {
34039
+ real = realpathSync13(file);
34040
+ } catch {
34041
+ continue;
34042
+ }
34043
+ if (ENTRY_NAMES.test(baseName3(real)) || entryByPath(real))
34044
+ return text;
34045
+ }
34046
+ return null;
34047
+ };
34048
+ var noteLink = (words, scan) => {
34049
+ if (!/^(?:ln|cp|install)$/u.test(baseName3(words[0] ?? "")) || scan.dir === null)
34050
+ return;
34051
+ const names = words.slice(1).filter((word) => !word.startsWith("-"));
34052
+ const dest = names.at(-1);
34053
+ if (dest === undefined || names.length < 2)
34054
+ return;
34055
+ for (const source of names.slice(0, -1).filter((name) => entryNamed(name, scan))) {
34056
+ const to = path58.resolve(scan.dir, expand(dest, scan.vars));
34057
+ scan.links.add(to);
34058
+ scan.links.add(path58.join(to, path58.basename(source)));
34059
+ }
34060
+ };
34061
+ var runsEntry = (words, inputs, scan) => {
34062
+ const named = (word) => entryNamed(word, scan);
34063
+ let at = 0;
34064
+ while (at < words.length) {
34065
+ while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
34066
+ at += 1;
34067
+ const word = words[at];
34068
+ if (word === undefined)
34069
+ return null;
34070
+ const entry = named(word);
34071
+ if (entry)
34072
+ return entry;
34073
+ const name = baseName3(word);
34074
+ const split = name === "env" ? words.findIndex((w) => /^(?:-\w*S|--split-string)/u.test(w)) : -1;
34075
+ if (split > at) {
34076
+ const line = /^(?:-\w*S|--split-string=?)(.*)$/su.exec(words[split] ?? "")?.[1] || words[split + 1];
34077
+ const rest = words.slice(split + (line === words[split + 1] ? 2 : 1));
34078
+ return runsEntry([...(line ?? "").split(/\s+/u).filter(Boolean), ...rest], inputs, scan);
34079
+ }
34080
+ if (MORE_WRAPPERS.has(name)) {
34081
+ at = pastOptions(words, at + 1, "");
34082
+ continue;
34083
+ }
34084
+ const takes = WRAPPERS3[name];
34085
+ if (takes !== undefined && !PACKAGE_RUNNERS2.has(name)) {
34086
+ at = pastOptions(words, at + 1, takes, name === "env" || name === "sudo");
34087
+ continue;
34088
+ }
34089
+ if (name === "busybox" || name === "toybox") {
34090
+ at += 1;
34091
+ continue;
34092
+ }
34093
+ const runner = PACKAGE_RUNNERS2.has(name) || name === "bun" && words[at + 1] === "x" || /^(?:pnpm|yarn|npm)$/u.test(name) && /^(?:dlx|exec|x)$/u.test(words[at + 1] ?? "");
34094
+ if (runner) {
34095
+ at += PACKAGE_RUNNERS2.has(name) ? 1 : 2;
34096
+ while (words[at]?.startsWith("-"))
34097
+ at += /^(?:-p|--package|-c|--call)$/u.test(words[at] ?? "") ? 2 : 1;
34098
+ if (/^@workit-dev\/(?:claude-code|codex|cursor)(?:@|$)/u.test(words[at] ?? ""))
34099
+ return words[at] ?? null;
34100
+ continue;
34101
+ }
34102
+ if (!RUNNERS2.has(name))
34103
+ return null;
34104
+ if ((name === "bun" || name === "deno") && NO_RUN.has(words[at + 1] ?? ""))
34105
+ return null;
34106
+ for (const arg of [...words.slice(at + 1), ...inputs]) {
34107
+ const hit = named(arg);
34108
+ if (hit)
34109
+ return hit;
34110
+ }
34111
+ return null;
34112
+ }
34113
+ return null;
34114
+ };
34115
+ var KEYWORDS3 = new Set([
34116
+ "{",
34117
+ "}",
34118
+ "if",
34119
+ "then",
34120
+ "elif",
34121
+ "else",
34122
+ "fi",
34123
+ "while",
34124
+ "until",
34125
+ "do",
34126
+ "done",
34127
+ "esac",
34128
+ "!"
34129
+ ]);
34130
+ var pastKeywords = (words) => {
34131
+ let at = 0;
34132
+ for (;; ) {
34133
+ if (words[at] === "function")
34134
+ at += 2;
34135
+ else if (KEYWORDS3.has(words[at] ?? ""))
34136
+ at += 1;
34137
+ else
34138
+ break;
34139
+ }
34140
+ return /^(?:for|case|select)$/u.test(words[at] ?? "") ? [] : words.slice(at);
34141
+ };
34142
+ var READERS2 = new Set(("cat less more head tail ls dir stat file wc grep egrep fgrep rg ag diff cmp sha256sum md5sum " + "shasum du bat echo printf cp mv rm chmod touch mkdir realpath readlink dirname basename tee " + "oxfmt oxlint prettier eslint tsc gh jq sort uniq cut tr nl od xxd hexdump strings code vim " + "nano sed get-content gc type select-string get-childitem test-path").split(" "));
34143
+ var TOKENS2 = /[\s'"`(),[\]{};|&<>=!]+/u;
34144
+ var ENTRY_SAMPLES = [
34145
+ "workit-hook.mjs",
34146
+ "workit-hook.js",
34147
+ "workit-hook.ts",
34148
+ "cursor-session-start.js"
34149
+ ];
34150
+ var tokenEntry = (token, scan) => {
34151
+ if (!/[\\/]/u.test(token) && !existsSync19(path58.resolve(scan.dir ?? "/", token)))
34152
+ return null;
34153
+ return entryNamed(token, scan);
34154
+ };
34155
+ var opaqueEntry = (words, inputs, scan) => {
34156
+ let at = 0;
34157
+ while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
34158
+ at += 1;
34159
+ const head = baseName3(words[at] ?? "");
34160
+ if (READERS2.has(head))
34161
+ return null;
34162
+ if ((head === "bun" || head === "deno") && NO_RUN.has(words[at + 1] ?? ""))
34163
+ return null;
34164
+ if (head === "git" && !words.some((word) => word.includes("alias.")))
34165
+ return null;
34166
+ if (head === "workit" || head === "workit-cli")
34167
+ return null;
34168
+ const tokens = words.flatMap((word) => word.split(TOKENS2)).filter(Boolean);
34169
+ const runner = (token) => RUNNERS2.has(baseName3(token)) && !/^(?:\.|source)$/u.test(token) || PACKAGE_RUNNERS2.has(baseName3(token));
34170
+ if (!tokens.some(runner))
34171
+ return null;
34172
+ if (scan.fed)
34173
+ return scan.fed;
34174
+ for (const token of tokens) {
34175
+ const hit = tokenEntry(token, scan);
34176
+ if (hit)
34177
+ return hit;
34178
+ }
34179
+ if (head === "find")
34180
+ for (const [index, word] of words.entries()) {
34181
+ const named = /^-i?name$/u.test(words[index - 1] ?? "") && /^[^*?[]/u.test(word);
34182
+ const pattern = named ? globPattern(word) : null;
34183
+ if (pattern && ENTRY_SAMPLES.some((sample) => pattern.test(sample)))
34184
+ return word;
34185
+ }
34186
+ if (/^(?:xargs|parallel)$/u.test(head) || tokens.includes("xargs"))
34187
+ for (const input of inputs) {
34188
+ try {
34189
+ const file = path58.resolve(scan.dir ?? "/", expand(input, scan.vars));
34190
+ const text = readFileSync16(file, "utf8").slice(0, 65536);
34191
+ for (const token of text.split(/\s+/u).filter(Boolean)) {
34192
+ const hit = tokenEntry(token, scan);
34193
+ if (hit)
34194
+ return hit;
34195
+ }
34196
+ } catch {}
34197
+ }
34198
+ return null;
34199
+ };
34200
+ var expandedCommand = (words, scan) => {
34201
+ let at = 0;
34202
+ while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
34203
+ at += 1;
34204
+ if (!/[$`]/u.test(words[at] ?? ""))
34205
+ return null;
34206
+ for (const word of words.slice(at + 1)) {
34207
+ const hit = entryNamed(word, scan);
34208
+ if (hit)
34209
+ return hit;
34210
+ }
34211
+ return null;
34212
+ };
34213
+ var optionsEntry = (words, scan) => {
34214
+ for (const word of words) {
34215
+ const value = /^(?:NODE_OPTIONS|BUN_OPTIONS)=(.*)$/su.exec(word)?.[1];
34216
+ if (value === undefined)
34217
+ continue;
34218
+ for (const token of value.split(TOKENS2).filter(Boolean)) {
34219
+ const hit = tokenEntry(token, scan);
34220
+ if (hit)
34221
+ return hit;
34222
+ }
34223
+ }
34224
+ return null;
34225
+ };
34226
+ var scanCommand = (command, dialect, scan) => {
34227
+ let segments;
34228
+ try {
34229
+ segments = segmentsOf(command, dialect);
34230
+ } catch {
34231
+ return null;
34232
+ }
34233
+ for (const [index, segment] of segments.entries()) {
34234
+ if (segment.unanalyzable)
34235
+ continue;
34236
+ bindLoop(segment.words, segments.slice(index + 1), scan);
34237
+ const words = pastKeywords(segment.words);
34238
+ const fed = scan.fed;
34239
+ scan.fed = null;
34240
+ const hit = segmentEntry(segment, words, dialect, scan, fed);
34241
+ if (hit)
34242
+ return hit;
34243
+ }
34244
+ return null;
34245
+ };
34246
+ var bindLoop = (raw, after, scan) => {
34247
+ const at = raw.findIndex((word) => !KEYWORDS3.has(word));
34248
+ const verb = raw[at];
34249
+ if ((verb === "for" || verb === "select") && raw[at + 2] === "in") {
34250
+ const name = raw[at + 1] ?? "";
34251
+ const items = raw.slice(at + 3);
34252
+ const item = items.find((word) => entryNamed(word, scan)) ?? items[0];
34253
+ if (/^[A-Za-z_]\w*$/u.test(name) && item !== undefined)
34254
+ scan.vars.set(name, expand(item, scan.vars));
34255
+ return;
34256
+ }
34257
+ const read = raw.indexOf("read");
34258
+ if (read < 0 || !raw.slice(0, read).some((word) => word === "while" || word === "until"))
34259
+ return;
34260
+ const fed = after.find((segment) => segment.words[0] === "done")?.stdin?.[0];
34261
+ const line = fed?.split(`
34262
+ `)[0]?.trim();
34263
+ const name = raw.slice(read + 1).find((word) => /^[A-Za-z_]\w*$/u.test(word));
34264
+ if (name && line)
34265
+ scan.vars.set(name, line);
34266
+ };
34267
+ var segmentEntry = (segment, words, dialect, scan, fed) => {
34268
+ const verb = baseName3(words[0] ?? "");
34269
+ if (["cd", "pushd", "chdir", "set-location", "sl"].includes(verb)) {
34270
+ const target = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
34271
+ const moved = target === undefined ? userHome(process.env) : expand(target, scan.vars);
34272
+ scan.dir = moved === "-" || /[$`]/u.test(moved) ? null : path58.isAbsolute(moved) ? moved : scan.dir && path58.resolve(scan.dir, moved);
34273
+ if (scan.dir === null)
34274
+ scan.vars.delete("PWD");
34275
+ else
34276
+ scan.vars.set("PWD", scan.dir);
34277
+ return null;
34278
+ }
34279
+ if (verb === "popd") {
34280
+ scan.dir = null;
34281
+ return null;
34282
+ }
34283
+ const declares = ["export", "declare", "typeset", "local", "readonly"].includes(verb);
34284
+ const assigns = declares ? words.slice(1) : words.every((word) => /^[A-Za-z_]\w*=/u.test(word)) ? words : [];
34285
+ for (const word of assigns) {
34286
+ const [name = "", value] = word.split(/=(.*)/su);
34287
+ if (value !== undefined && /^[A-Za-z_]\w*$/u.test(name))
34288
+ scan.vars.set(name, expand(value.replace(/^(['"])(.*)\1$/su, "$2"), scan.vars));
34289
+ }
34290
+ const options = optionsEntry(declares ? words.slice(1) : words, scan);
34291
+ if (options)
34292
+ return options;
34293
+ if (verb === "exec" && words.slice(1).every((word) => /^\d+$/u.test(word))) {
34294
+ for (const input of segment.inputs ?? [])
34295
+ if (entryNamed(input, scan))
34296
+ for (const fd of words.slice(1))
34297
+ scan.fds.add(fd);
34298
+ }
34299
+ const inputs = segment.inputs ?? [];
34300
+ const entry = runsEntry(words, inputs, scan) ?? expandedCommand(words, scan) ?? opaqueEntry(words, inputs, { ...scan, fed });
34301
+ if (entry)
34302
+ return entry;
34303
+ if (segment.pipe)
34304
+ scan.fed = words.slice(1).flatMap((word) => word.split(TOKENS2)).map((token) => token ? tokenEntry(token, scan) : null).find(Boolean) ?? null;
34305
+ noteLink(words, scan);
34306
+ if (scan.depth >= 4)
34307
+ return null;
34308
+ const nested = (script) => scanCommand(script, dialect, {
34309
+ ...scan,
34310
+ vars: new Map(scan.vars),
34311
+ fed: null,
34312
+ depth: scan.depth + 1
34313
+ });
34314
+ const scripts = [...segment.subs ?? []];
34315
+ const script = shellScript2(words) ?? cmdScript2(words) ?? workitScript(words);
34316
+ if (script)
34317
+ scripts.push(script);
34318
+ if (!script && /^(?:ba|z|da|k)?sh$/u.test(verb) && words.slice(1).every((word) => word.startsWith("-")) || verb === "at" || verb === "batch")
34319
+ scripts.push(...segment.stdin ?? []);
34320
+ for (const text of scripts) {
34321
+ const hit = nested(text);
34322
+ if (hit)
34323
+ return hit;
34324
+ }
34325
+ return null;
34326
+ };
34327
+ var cmdScript2 = (words) => {
34328
+ const name = baseName3(words[0] ?? "");
34329
+ if (!/^(?:cmd|pwsh|powershell)$/u.test(name))
34330
+ return null;
34331
+ const flag = words.findIndex((word, at) => at > 0 && /^[/-](?:c|k|command)$/iu.test(word));
34332
+ return flag < 0 ? null : words.slice(flag + 1).join(" ").replaceAll("\\", "/") || null;
34333
+ };
34334
+ var workitScript = (words) => {
34335
+ if (!/^workit(?:-cli)?$/u.test(baseName3(words[0] ?? "")))
34336
+ return null;
34337
+ const dash = words.indexOf("--");
34338
+ return dash < 0 ? null : words.slice(dash + 1).join(" ") || null;
34339
+ };
34340
+ var substitutions2 = (command) => {
34341
+ const found = [];
34342
+ for (let at = command.indexOf("$(");at >= 0 && found.length < 32; at = command.indexOf("$(", at + 1)) {
34343
+ if (command[at + 2] === "(")
34344
+ continue;
34345
+ let depth = 1;
34346
+ let end = at + 2;
34347
+ for (;end < command.length && depth > 0; end += 1)
34348
+ if (command[end] === "(")
34349
+ depth += 1;
34350
+ else if (command[end] === ")")
34351
+ depth -= 1;
34352
+ found.push(command.slice(at + 2, end - 1));
34353
+ }
34354
+ return found;
34355
+ };
34356
+ var hookEntryRun = (cwd, command, dialect = "posix") => {
34357
+ const scan = (text) => scanCommand(text, dialect, {
34358
+ dir: cwd,
34359
+ vars: new Map([["PWD", cwd]]),
34360
+ links: new Set,
34361
+ fds: new Set,
34362
+ fed: null,
34363
+ depth: 0
34364
+ });
34365
+ const texts = dialect === "posix" && /[A-Za-z]:\\/u.test(command) ? [command, command.replaceAll("\\", "/")] : [command];
34366
+ for (const text of texts) {
34367
+ const hit = scan(text) ?? substitutions2(text).map(scan).find(Boolean);
34368
+ if (hit)
34369
+ return hit;
34370
+ }
34371
+ return null;
34372
+ };
34373
+ var hookEntryDeny = (entry) => `workit hook guard: this command runs Workit's hook entry ${entry}. Only the host runs Workit's hooks, with the payload it builds; a payload written in a shell would act as a session, subagent or agent that never existed. Use the workit CLI for what you need (\`workit doctor\` probes the installed hooks).`;
34374
+
33724
34375
  // packages/workit-core/src/hooks/identity-env.ts
34376
+ import fs36 from "node:fs";
34377
+ import path59 from "node:path";
33725
34378
  var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
33726
- var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
33727
34379
  var IDENTITY = new RegExp(`^${NAMES}$`, "u");
34380
+ var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
33728
34381
  var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
33729
- var powershell = (names) => new RegExp(`\\$env:${names}\\b|env:[\\\\/]?${names}\\b|EnvironmentVariable\\(\\s*['"]${names}\\b`, "iu");
34382
+ var IDENTITY_ANY = new RegExp(NAMES, "iu");
34383
+ var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
34384
+ var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
34385
+ var STATE_ANY = new RegExp(STATE_NAMES, "iu");
34386
+ var powershell = (names) => new RegExp([
34387
+ `\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
34388
+ `${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
34389
+ `SetEnvironmentVariable\\(\\s*['"]${names}\\b`
34390
+ ].join("|"), "iu");
34391
+ var PS_ITEM = "\\b(?:(?:Set|New|Remove|Clear|Rename|Move|Copy)-Item(?:Property)?|(?:Set|Add|Clear)-Content|si|ni|ri|rm|del|erase|rd|rmdir|cli|sc|ac|clc|rni|mi|move|mv|cpi|copy|cp|ren)\\b";
33730
34392
  var POWERSHELL = powershell(NAMES);
34393
+ var POWERSHELL_STATE = powershell(STATE_NAMES);
33731
34394
  var POWERSHELL_HOST = powershell(HOST_NAMES);
34395
+ var POWERSHELL_OPAQUE = new RegExp([
34396
+ `SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
34397
+ `${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
34398
+ `(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
34399
+ `\\b(?:iex|Invoke-Expression)\\b`
34400
+ ].join("|"), "iu");
34401
+ var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
34402
+ var CMD_IDENTITY = cmdSet(NAMES);
34403
+ var CMD_STATE = cmdSet(STATE_NAMES);
34404
+ var CMD_HOST = cmdSet(HOST_NAMES);
34405
+ var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
33732
34406
  var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
33733
34407
  var OPAQUE = new Set([
33734
34408
  "watch",
@@ -33746,22 +34420,41 @@ var ENV_FLAGS = new Set(["i", "0", "v"]);
33746
34420
  var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
33747
34421
  var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
33748
34422
  var base3 = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
33749
- var nameOf = (word) => word?.split("=")[0] ?? "";
33750
- var named = (word) => IDENTITY.test(nameOf(word)) || HOST_VARIABLE.test(nameOf(word));
33751
- var isWorkit = (word) => /^workit(?:-cli)?$/u.test(base3(word));
34423
+ var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
34424
+ var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
34425
+ var named = (word) => IDENTITY.test(nameOf(word));
34426
+ var stateNamed = (word) => STATE2.test(nameOf(word));
34427
+ var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base3(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
34428
+ var linksToWorkit = (word, cwd) => {
34429
+ const places = /[\\/]/u.test(word) ? [path59.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path59.delimiter).map((dir) => path59.join(dir, word));
34430
+ for (const place of places) {
34431
+ try {
34432
+ const real = fs36.realpathSync(place);
34433
+ return isWorkit(real);
34434
+ } catch {}
34435
+ }
34436
+ return false;
34437
+ };
34438
+ var newSeg = () => ({ identity: null, scoped: null, runs: false, words: [] });
33752
34439
  var UNREADABLE = "env/unset arguments Workit cannot read";
33753
- var mark = (scan, word) => {
33754
- const name = nameOf(word);
33755
- if (IDENTITY.test(name))
33756
- scan.hit ??= name;
33757
- else if (HOST_VARIABLE.test(name))
33758
- scan.hostHit ??= name;
33759
- };
33760
- var scanEnv = (words, at, expands, scan, depth) => {
34440
+ var note = (scan, seg, word) => {
34441
+ if (scan.identity && named(word)) {
34442
+ if (seg)
34443
+ seg.identity ??= nameOf(word);
34444
+ else
34445
+ scan.hit ??= nameOf(word);
34446
+ }
34447
+ if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
34448
+ return;
34449
+ if (seg)
34450
+ seg.scoped ??= nameOf(word);
34451
+ else
34452
+ scan.shell ??= nameOf(word);
34453
+ };
34454
+ var mayBeWorkit = (words, cwd) => words.some(({ word, built }) => built || linksToWorkit(word, cwd));
34455
+ var scanEnv = (words, at, expands, scan, seg, depth) => {
33761
34456
  const risky = (what) => void (scan.risky ??= what);
33762
- const unset = (name) => {
33763
- mark(scan, name);
33764
- };
34457
+ const unset = (name) => note(scan, seg, name);
33765
34458
  const split = (line, rest, built) => {
33766
34459
  if (line === undefined || depth >= 4)
33767
34460
  return risky(UNREADABLE);
@@ -33778,7 +34471,7 @@ var scanEnv = (words, at, expands, scan, depth) => {
33778
34471
  } catch {
33779
34472
  return risky(UNREADABLE);
33780
34473
  }
33781
- scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, depth + 1);
34474
+ scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
33782
34475
  };
33783
34476
  let options = true;
33784
34477
  for (let index = at;index < words.length; index += 1) {
@@ -33836,25 +34529,25 @@ var scanEnv = (words, at, expands, scan, depth) => {
33836
34529
  }
33837
34530
  continue;
33838
34531
  }
33839
- if (/^[A-Za-z_]\w*=/u.test(word)) {
34532
+ if (ASSIGN.test(word)) {
33840
34533
  unset(word);
33841
34534
  continue;
33842
34535
  }
33843
- return commandAt(words.slice(index), scan);
34536
+ return commandAt(words.slice(index), scan, seg, new Set([...expands].filter((at2) => at2 >= index).map((at2) => at2 - index)));
33844
34537
  }
33845
34538
  };
33846
- var commandAt = (words, scan, expands = new Set, from = 0) => {
34539
+ var commandAt = (words, scan, seg, expands = new Set, from = 0) => {
33847
34540
  let index = from;
33848
34541
  while (index < words.length) {
33849
- while (/^[A-Za-z_]\w*=/u.test(words[index] ?? "")) {
33850
- mark(scan, words[index]);
34542
+ while (ASSIGN.test(words[index] ?? "")) {
34543
+ note(scan, seg, words[index]);
33851
34544
  index += 1;
33852
34545
  }
33853
34546
  const name = base3(words[index]).toLowerCase();
33854
34547
  if (name === "env")
33855
- return scanEnv(words, index + 1, expands, scan, 0);
34548
+ return scanEnv(words, index + 1, expands, scan, seg, 0);
33856
34549
  if (OPAQUE.has(name))
33857
- return opaque(words.slice(index + 1), scan, true);
34550
+ return opaque(words.slice(index + 1), scan, seg, true);
33858
34551
  if (name === "busybox" || name === "toybox") {
33859
34552
  index += 1;
33860
34553
  continue;
@@ -33864,21 +34557,37 @@ var commandAt = (words, scan, expands = new Set, from = 0) => {
33864
34557
  break;
33865
34558
  index = pastOptions(words, index + 1, takes);
33866
34559
  }
33867
- if (isWorkit(words[index]))
33868
- scan.runs = true;
33869
- else if (words.slice(index + 1).some((word) => base3(word).toLowerCase() === "env"))
33870
- opaque(words.slice(index + 1), scan, false);
33871
- };
33872
- var opaque = (rest, scan, assigns) => {
34560
+ const word = words[index];
34561
+ if (word === undefined)
34562
+ return;
34563
+ seg.words.push({ word, built: expands.has(index) });
34564
+ const rest = words.slice(index + 1);
34565
+ if (isWorkit(word) || rest.some(isWorkit))
34566
+ seg.runs = true;
34567
+ if (!isWorkit(word) && rest.some((next) => base3(next).toLowerCase() === "env"))
34568
+ opaque(rest, scan, seg, false);
34569
+ const program = base3(word).toLowerCase();
34570
+ const shell = program === "pwsh" || program === "powershell";
34571
+ if (program === "cmd" || shell) {
34572
+ const at = rest.findIndex((next) => shell ? /^-(?:c|command)$/iu.test(next) : /^\/[ck]$/iu.test(next));
34573
+ if (at >= 0) {
34574
+ const script = rest.slice(at + 1).join(" ");
34575
+ const change = shell ? powershellChange(script, scan.identity) : cmdChange(script, scan);
34576
+ if (change)
34577
+ scan.hit ??= change;
34578
+ }
34579
+ }
34580
+ };
34581
+ var opaque = (rest, scan, seg, assigns) => {
33873
34582
  if (!rest.some(isWorkit))
33874
34583
  return;
33875
- scan.runs = true;
33876
- const changes = (word) => base3(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && /^[A-Za-z_]\w*=/u.test(word);
34584
+ seg.runs = true;
34585
+ const changes = (word) => base3(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
33877
34586
  if (rest.some(changes))
33878
34587
  scan.risky ??= UNREADABLE;
33879
- const hit = rest.find(named);
33880
- if (hit && rest.some((word) => base3(word).toLowerCase() === "env"))
33881
- mark(scan, hit);
34588
+ if (rest.some((word) => base3(word).toLowerCase() === "env"))
34589
+ for (const word of rest)
34590
+ note(scan, seg, word);
33882
34591
  };
33883
34592
  var LOGIN_VALUED = {
33884
34593
  su: /[sgGwc]/u,
@@ -33904,7 +34613,7 @@ var loginScript = (words) => {
33904
34613
  }
33905
34614
  return null;
33906
34615
  };
33907
- var scanCommand = (command, dialect, depth, scan) => {
34616
+ var scanCommand2 = (command, dialect, depth, scan) => {
33908
34617
  let segments;
33909
34618
  try {
33910
34619
  segments = segmentsOf(command, dialect);
@@ -33913,38 +34622,83 @@ var scanCommand = (command, dialect, depth, scan) => {
33913
34622
  }
33914
34623
  for (const { words, expands = [] } of segments) {
33915
34624
  const expanded = new Set(expands);
34625
+ const seg = newSeg();
33916
34626
  let at = 0;
33917
- while (/^[A-Za-z_]\w*=/u.test(words[at] ?? "")) {
33918
- mark(scan, words[at]);
34627
+ while (ASSIGN.test(words[at] ?? ""))
33919
34628
  at += 1;
33920
- }
34629
+ for (const word of words.slice(0, at))
34630
+ note(scan, at === words.length ? null : seg, word);
33921
34631
  let declare = at;
33922
34632
  if (["builtin", "command"].includes(words[declare] ?? ""))
33923
34633
  declare += 1;
33924
34634
  if (DECLARES.has(words[declare] ?? "")) {
33925
34635
  for (let index = declare + 1;index < words.length; index += 1) {
33926
- mark(scan, words[index]);
34636
+ note(scan, null, words[index]);
33927
34637
  if (expanded.has(index))
33928
34638
  scan.risky ??= UNREADABLE;
33929
34639
  }
33930
34640
  continue;
33931
34641
  }
33932
- commandAt(words, scan, expanded, at);
34642
+ commandAt(words, scan, seg, expanded, at);
33933
34643
  const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
33934
- if (script)
33935
- scanCommand(script, dialect, depth + 1, scan);
33936
- }
33937
- };
33938
- var identityEnvChange = (command, dialect = "posix") => {
33939
- if (!/WORKIT_|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDE|\b(?:env|unset|export|declare|typeset|local|readonly)\b/u.test(command))
34644
+ if (script) {
34645
+ const before = scan.runs;
34646
+ scan.runs = false;
34647
+ scanCommand2(script, dialect, depth + 1, scan);
34648
+ seg.runs ||= scan.runs;
34649
+ scan.runs ||= before;
34650
+ }
34651
+ scan.words.push(...seg.words);
34652
+ const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
34653
+ if (seg.identity && reaches())
34654
+ scan.hit ??= seg.identity;
34655
+ if (seg.scoped && reaches())
34656
+ scan.state ??= seg.scoped;
34657
+ scan.runs ||= seg.runs;
34658
+ }
34659
+ };
34660
+ var cmdChange = (script, scan) => (scan.identity ? CMD_IDENTITY.exec(script)?.[1] : null) ?? (RUNS_TEXT.test(script) ? CMD_STATE.exec(script)?.[1] ?? (scan.identity ? CMD_HOST.exec(script)?.[1] : null) ?? null : null);
34661
+ var powershellChange = (command, identity) => {
34662
+ const hit = identity ? POWERSHELL.exec(command)?.[0] : null;
34663
+ if (hit)
34664
+ return hit;
34665
+ if (!RUNS_TEXT.test(command) && !/&\s*[$(]/u.test(command))
33940
34666
  return null;
34667
+ const state = POWERSHELL_STATE.exec(command)?.[0] ?? (identity ? POWERSHELL_HOST.exec(command)?.[0] : null) ?? cmdChange(command, { identity });
34668
+ if (state)
34669
+ return state;
34670
+ return POWERSHELL_OPAQUE.test(command) ? UNREADABLE : null;
34671
+ };
34672
+ var identityEnvChange = (command, dialect = "posix", options = {}) => {
34673
+ const identity = options.identity ?? true;
33941
34674
  if (dialect === "powershell")
33942
- return POWERSHELL.exec(command)?.[0] ?? (/\bworkit\b/iu.test(command) ? POWERSHELL_HOST.exec(command)?.[0] ?? null : null);
33943
- const scan = { hit: null, hostHit: null, risky: null, runs: false };
33944
- scanCommand(command, dialect, 0, scan);
33945
- return scan.hit ?? (scan.runs ? scan.hostHit ?? scan.risky : null);
34675
+ return powershellChange(command, identity);
34676
+ if (!/WORKIT_|XDG_|HOME|USERPROFILE|APPDATA|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDE|EnvironmentVariable|\b(?:env|unset|export|declare|typeset|local|readonly)\b/iu.test(command))
34677
+ return null;
34678
+ const scan = {
34679
+ identity,
34680
+ cwd: options.cwd,
34681
+ hit: null,
34682
+ state: null,
34683
+ shell: null,
34684
+ risky: null,
34685
+ runs: false,
34686
+ words: []
34687
+ };
34688
+ scanCommand2(command, dialect, 0, scan);
34689
+ if (scan.hit)
34690
+ return scan.hit;
34691
+ if (scan.state)
34692
+ return scan.state;
34693
+ if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
34694
+ return scan.shell;
34695
+ return scan.runs ? scan.risky : null;
34696
+ };
34697
+ var identityEnvDeny = (change) => {
34698
+ if (change === UNREADABLE || IDENTITY_ANY.test(change) || !STATE_ANY.test(change))
34699
+ return `workit identity: ${change === UNREADABLE ? `this command runs workit with ${UNREADABLE}` : `this command changes ${change}`}. The host sets WORKIT_HOST, WORKIT_SESSION_ID, WORKIT_AGENT_ID and its own session variables, and Workit acts as who they name; run it without changing them (a verifier or reviewer passes the --session and --token its start text names).`;
34700
+ return `workit identity: this command runs workit with ${change} changed. Workit reads issued sessions, grants and its ledger trust from the state and config dirs the host's environment names, so a workit call may not move them (#980); run it without setting, unsetting or emptying ${change}.`;
33946
34701
  };
33947
- var identityEnvDeny = (change) => `workit identity: ${change === UNREADABLE ? `this command runs workit with ${UNREADABLE}` : `this command changes ${change}`}. The host sets WORKIT_HOST, WORKIT_SESSION_ID, WORKIT_AGENT_ID and its own session variables, and Workit acts as who they name; run it without changing them (a verifier or reviewer passes the --session and --token its start text names).`;
33948
34702
 
33949
34703
  // packages/workit-core/src/hooks/handle.ts
33950
34704
  var usable2 = (value) => value === "native" || value === "partial";
@@ -34021,6 +34775,7 @@ function decide(input, deps) {
34021
34775
  switch (event.kind) {
34022
34776
  case "session.start": {
34023
34777
  reapAtStart(input.cwd);
34778
+ pinIssuedRegistry(input.cwd);
34024
34779
  if (!usable2(descriptor.context.sessionStart))
34025
34780
  return NONE6;
34026
34781
  const key = input.session.id ? `${input.host}\x00${input.session.id}` : null;
@@ -34137,11 +34892,17 @@ function decide(input, deps) {
34137
34892
  const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) : NONE6;
34138
34893
  if (raw.kind === "deny")
34139
34894
  return raw;
34895
+ const entry = canDeny ? hookEntryRun(input.cwd, event.command, event.dialect) : null;
34896
+ if (entry)
34897
+ return { kind: "deny", reason: hookEntryDeny(entry), unblock: null };
34140
34898
  const owner = role === "judge" ? null : liveOwner(input, descriptor.transport);
34141
34899
  const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, owner, event.dialect) : NONE6;
34142
34900
  if (gate.kind === "deny")
34143
34901
  return gate;
34144
- const identity = canDeny && stampsAgents(descriptor) ? identityEnvChange(event.command, event.dialect) : null;
34902
+ const identity = canDeny ? identityEnvChange(event.command, event.dialect, {
34903
+ identity: stampsAgents(descriptor),
34904
+ cwd: input.cwd
34905
+ }) : null;
34145
34906
  if (identity)
34146
34907
  return { kind: "deny", reason: identityEnvDeny(identity), unblock: null };
34147
34908
  const plan = heavyGate(input.cwd, event.command, {
@@ -34278,11 +35039,11 @@ var modelKey = (model) => {
34278
35039
 
34279
35040
  // packages/workit-core/src/hooks/budget-signal.ts
34280
35041
  import { createHash as createHash25 } from "node:crypto";
34281
- import fs36 from "node:fs";
34282
- import path57 from "node:path";
35042
+ import fs37 from "node:fs";
35043
+ import path60 from "node:path";
34283
35044
  var hash3 = (text) => createHash25("sha256").update(text).digest("hex").slice(0, 32);
34284
- var budgetDir = (store) => path57.join(store, "budget");
34285
- var agentBase = (store, session, agentId) => path57.join(budgetDir(store), hash3(`${session}\x00${agentId ?? ""}`));
35045
+ var budgetDir = (store) => path60.join(store, "budget");
35046
+ var agentBase = (store, session, agentId) => path60.join(budgetDir(store), hash3(`${session}\x00${agentId ?? ""}`));
34286
35047
  var spawnBudget = (prompt) => {
34287
35048
  const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
34288
35049
  const n = found ? Number(found[1]) : NaN;
@@ -34290,7 +35051,7 @@ var spawnBudget = (prompt) => {
34290
35051
  };
34291
35052
  var readBudget = (file) => {
34292
35053
  try {
34293
- const { limit, told } = JSON.parse(fs36.readFileSync(file, "utf8"));
35054
+ const { limit, told } = JSON.parse(fs37.readFileSync(file, "utf8"));
34294
35055
  return typeof limit === "number" && limit > 0 ? { limit, told: Number(told) || 0 } : null;
34295
35056
  } catch {
34296
35057
  return null;
@@ -34298,16 +35059,16 @@ var readBudget = (file) => {
34298
35059
  };
34299
35060
  var startBudget = (store, session, agentId, n) => {
34300
35061
  const dir = budgetDir(store);
34301
- fs36.mkdirSync(dir, { recursive: true });
35062
+ fs37.mkdirSync(dir, { recursive: true });
34302
35063
  const cutoff = Date.now() - 604800000;
34303
- for (const name of fs36.readdirSync(dir))
35064
+ for (const name of fs37.readdirSync(dir))
34304
35065
  try {
34305
- if (fs36.statSync(path57.join(dir, name)).mtimeMs < cutoff)
34306
- fs36.rmSync(path57.join(dir, name));
35066
+ if (fs37.statSync(path60.join(dir, name)).mtimeMs < cutoff)
35067
+ fs37.rmSync(path60.join(dir, name));
34307
35068
  } catch {}
34308
35069
  const base = agentBase(store, session, agentId);
34309
- fs36.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
34310
- fs36.rmSync(`${base}.calls`, { force: true });
35070
+ fs37.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
35071
+ fs37.rmSync(`${base}.calls`, { force: true });
34311
35072
  };
34312
35073
  var bindBudget = (cwd, session, agentId, prompt) => {
34313
35074
  try {
@@ -34330,8 +35091,8 @@ var tickBudget = (cwd, session, agentId) => {
34330
35091
  const budget = readBudget(`${base}.json`);
34331
35092
  if (!budget)
34332
35093
  return false;
34333
- fs36.appendFileSync(`${base}.calls`, ".");
34334
- return fs36.statSync(`${base}.calls`).size >= budget.limit * (budget.told + 1);
35094
+ fs37.appendFileSync(`${base}.calls`, ".");
35095
+ return fs37.statSync(`${base}.calls`).size >= budget.limit * (budget.told + 1);
34335
35096
  } catch {
34336
35097
  return false;
34337
35098
  }
@@ -34343,14 +35104,14 @@ var reachedOf = (cwd, session, agentId) => {
34343
35104
  const budget = base && readBudget(`${base}.json`);
34344
35105
  if (!budget)
34345
35106
  return null;
34346
- return { base, budget, reached: Math.floor(fs36.statSync(`${base}.calls`).size / budget.limit) };
35107
+ return { base, budget, reached: Math.floor(fs37.statSync(`${base}.calls`).size / budget.limit) };
34347
35108
  };
34348
35109
  var budgetLine = (cwd, session, agentId) => {
34349
35110
  try {
34350
35111
  const at = reachedOf(cwd, session, agentId);
34351
35112
  if (!at || at.reached <= at.budget.told)
34352
35113
  return null;
34353
- fs36.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
35114
+ fs37.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
34354
35115
  return lineFor(at.budget.limit * at.reached);
34355
35116
  } catch {
34356
35117
  return null;
@@ -34756,14 +35517,14 @@ var observeToolResult = (event, ctx) => {
34756
35517
  var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? null : promptNudge(hookInput(ctx, { kind: "context.turn", prompt }), prompt);
34757
35518
 
34758
35519
  // packages/workit-pi/src/launches.ts
34759
- import { mkdirSync as mkdirSync8, readFileSync as readFileSync16, readdirSync as readdirSync8, rmSync as rmSync4, writeFileSync as writeFileSync7 } from "node:fs";
35520
+ import { mkdirSync as mkdirSync8, readFileSync as readFileSync17, readdirSync as readdirSync9, rmSync as rmSync4, writeFileSync as writeFileSync7 } from "node:fs";
34760
35521
  import os13 from "node:os";
34761
- import path58 from "node:path";
35522
+ import path61 from "node:path";
34762
35523
  var launchDir = (root) => {
34763
35524
  const location = resolveStore(root);
34764
- return location instanceof Error ? null : path58.join(location.dir, "pi-launches");
35525
+ return location instanceof Error ? null : path61.join(location.dir, "pi-launches");
34765
35526
  };
34766
- var fileFor = (dir, workerId) => path58.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
35527
+ var fileFor = (dir, workerId) => path61.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
34767
35528
  var recordLaunch = (root, attempt) => {
34768
35529
  const dir = launchDir(root);
34769
35530
  if (!dir)
@@ -34802,14 +35563,14 @@ var abandonedLaunches = (root) => {
34802
35563
  return [];
34803
35564
  let names;
34804
35565
  try {
34805
- names = readdirSync8(dir);
35566
+ names = readdirSync9(dir);
34806
35567
  } catch {
34807
35568
  return [];
34808
35569
  }
34809
35570
  const found = [];
34810
35571
  for (const name of names) {
34811
35572
  try {
34812
- const attempt = JSON.parse(readFileSync16(path58.join(dir, name), "utf8"));
35573
+ const attempt = JSON.parse(readFileSync17(path61.join(dir, name), "utf8"));
34813
35574
  if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
34814
35575
  if (!alive(attempt))
34815
35576
  found.push(attempt);