@workit-dev/codex 2.27.7 → 2.27.8

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.
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ userHome2,
3
4
  configDir2,
4
5
  stateDir3,
5
6
  folderSlug2,
@@ -17517,7 +17518,7 @@ var splitDenial = (plan) => ({
17517
17518
  // packages/workit-core/src/hooks/write-gate.ts
17518
17519
  import {
17519
17520
  existsSync as existsSync12,
17520
- readdirSync as readdirSync3,
17521
+ readdirSync as readdirSync4,
17521
17522
  readFileSync as readFileSync10,
17522
17523
  readlinkSync as readlinkSync3,
17523
17524
  realpathSync as realpathSync8,
@@ -17525,7 +17526,7 @@ import {
17525
17526
  } from "node:fs";
17526
17527
  import { builtinModules } from "node:module";
17527
17528
  import os9 from "node:os";
17528
- import path30 from "node:path";
17529
+ import path31 from "node:path";
17529
17530
 
17530
17531
  // packages/workit-core/src/core/live-session.ts
17531
17532
  import { spawnSync as spawnSync15 } from "node:child_process";
@@ -17728,6 +17729,41 @@ var claimLiveSession = (target, owner, deps = {}) => {
17728
17729
  } catch {}
17729
17730
  };
17730
17731
 
17732
+ // packages/workit-core/src/hooks/path-glob.ts
17733
+ import { readdirSync as readdirSync3 } from "node:fs";
17734
+ import path30 from "node:path";
17735
+ var GLOB2 = /[*?[]/u;
17736
+ var globPattern = (glob, dots = false) => {
17737
+ try {
17738
+ return new RegExp(`^${dots || glob.startsWith(".") ? "" : "(?!\\.)"}${glob.replace(/[.+^$(){}|\\]/gu, "\\$&").replace(/\[!/gu, "[^").replaceAll("*", ".*").replaceAll("?", ".")}$`, "u");
17739
+ } catch {
17740
+ return null;
17741
+ }
17742
+ };
17743
+ var expandGlob = (file, limit = 64) => {
17744
+ if (!GLOB2.test(file))
17745
+ return [file];
17746
+ const { root } = path30.parse(file);
17747
+ let found = [root];
17748
+ for (const part of file.slice(root.length).split(/[\\/]/u).filter(Boolean)) {
17749
+ if (!GLOB2.test(part)) {
17750
+ found = found.map((dir) => path30.join(dir, part));
17751
+ continue;
17752
+ }
17753
+ const pattern = globPattern(part);
17754
+ if (pattern === null)
17755
+ return [file];
17756
+ found = found.flatMap((dir) => {
17757
+ try {
17758
+ return readdirSync3(dir).filter((name) => pattern.test(name)).map((name) => path30.join(dir, name));
17759
+ } catch {
17760
+ return [];
17761
+ }
17762
+ }).slice(0, limit);
17763
+ }
17764
+ return found.length > 0 ? found : [file];
17765
+ };
17766
+
17731
17767
  // packages/workit-core/src/hooks/windows-reads.ts
17732
17768
  var READ_CMDLETS = new Set([
17733
17769
  "foreach-object",
@@ -18045,44 +18081,44 @@ var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "wi
18045
18081
  var linkTarget = (file) => {
18046
18082
  try {
18047
18083
  const to = readlinkSync3(file);
18048
- let from = path30.dirname(file);
18084
+ let from = path31.dirname(file);
18049
18085
  try {
18050
18086
  from = realpathSync8.native(from);
18051
18087
  } catch {}
18052
- return path30.resolve(from, to);
18088
+ return path31.resolve(from, to);
18053
18089
  } catch {
18054
18090
  return null;
18055
18091
  }
18056
18092
  };
18057
18093
  var realPath = (file, dangling = true) => {
18058
- let dir = path30.resolve(file);
18094
+ let dir = path31.resolve(file);
18059
18095
  let rest = "";
18060
18096
  for (let hops = 0;; ) {
18061
18097
  try {
18062
- return path30.join(realpathSync8.native(dir), rest);
18098
+ return path31.join(realpathSync8.native(dir), rest);
18063
18099
  } catch {
18064
18100
  const link = dangling ? linkTarget(dir) : null;
18065
18101
  if (link !== null) {
18066
18102
  if (++hops > 40)
18067
18103
  return null;
18068
- dir = path30.join(link, rest);
18104
+ dir = path31.join(link, rest);
18069
18105
  rest = "";
18070
- } else if (path30.dirname(dir) === dir)
18071
- return path30.resolve(file);
18106
+ } else if (path31.dirname(dir) === dir)
18107
+ return path31.resolve(file);
18072
18108
  else {
18073
- rest = rest ? path30.join(path30.basename(dir), rest) : path30.basename(dir);
18074
- dir = path30.dirname(dir);
18109
+ rest = rest ? path31.join(path31.basename(dir), rest) : path31.basename(dir);
18110
+ dir = path31.dirname(dir);
18075
18111
  }
18076
18112
  }
18077
18113
  }
18078
18114
  };
18079
- var canonical5 = (file, dangling = true) => realPath(file, dangling) ?? path30.resolve(file);
18115
+ var canonical5 = (file, dangling = true) => realPath(file, dangling) ?? path31.resolve(file);
18080
18116
  var exempt = (cwd, root, file, plans) => {
18081
18117
  const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
18082
- const relative = path30.relative(fold(canonical5(root, false)), fold(canonical5(path30.resolve(cwd, file), false)));
18083
- if (relative.startsWith("..") || path30.isAbsolute(relative))
18118
+ const relative = path31.relative(fold(canonical5(root, false)), fold(canonical5(path31.resolve(cwd, file), false)));
18119
+ if (relative.startsWith("..") || path31.isAbsolute(relative))
18084
18120
  return true;
18085
- const posix = relative.split(path30.sep).join("/");
18121
+ const posix = relative.split(path31.sep).join("/");
18086
18122
  const segments = posix.split("/");
18087
18123
  return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
18088
18124
  };
@@ -18162,7 +18198,7 @@ var editsOf = (input) => {
18162
18198
  return [into];
18163
18199
  const files = operands(args);
18164
18200
  if (name === "ln" && files.length === 1)
18165
- return [path30.basename(files[0])];
18201
+ return [path31.basename(files[0])];
18166
18202
  return files.length ? [files.at(-1)] : null;
18167
18203
  }
18168
18204
  case "mklink": {
@@ -18224,6 +18260,35 @@ var editsOf = (input) => {
18224
18260
  return [];
18225
18261
  }
18226
18262
  };
18263
+ var removalsOf = (input) => {
18264
+ const [verb = "", ...args] = pastLead(input);
18265
+ const name = (verb.split(/[\\/]/).at(-1) ?? "").toLowerCase();
18266
+ const files = operands(args);
18267
+ if (/^(?:rm|rmdir|rd|unlink|shred|remove-item|ri|del|erase)$/.test(name))
18268
+ return { files };
18269
+ if (/^(?:mv|move-item|mi|move)$/.test(name)) {
18270
+ const into = valueOf(args, /^(?:-[a-zA-Z]*t|--target-directory=?)(.*)$/s);
18271
+ return {
18272
+ files: into === undefined ? files.slice(0, -1) : files.filter((file) => file !== into)
18273
+ };
18274
+ }
18275
+ if (name === "rsync" && args.some((arg) => /^--del(?:ete|$)/.test(arg)))
18276
+ return { files: files.slice(-1) };
18277
+ 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] ?? "")));
18278
+ if (name !== "find" || !removes)
18279
+ return { files: [] };
18280
+ const end = args.findIndex((arg) => /^[-(!]/.test(arg));
18281
+ const roots = end === 0 ? ["."] : args.slice(0, end);
18282
+ const tests = [];
18283
+ for (const [at, arg] of args.entries()) {
18284
+ const kind = /^-(i?)(?:name|path|wholename|regex)$/.exec(arg);
18285
+ const value = args[at + 1];
18286
+ if (kind && value !== undefined)
18287
+ tests.push([`${arg.replace(/^-i?/, "").replace("wholename", "path")}${kind[1]}`, value]);
18288
+ }
18289
+ const negated = args.some((arg) => arg === "!" || arg === "-not");
18290
+ return { files: roots, find: { roots, tests: negated ? [] : tests } };
18291
+ };
18227
18292
  var WRAPPERS3 = {
18228
18293
  sudo: "ugCDhpRrTtU",
18229
18294
  doas: "uC",
@@ -18247,7 +18312,7 @@ var WRAPPERS3 = {
18247
18312
  var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
18248
18313
  var INLINE_CODE = /^-[a-zA-Z]*[cep]$|^--(?:eval|print)(?:=|$)/;
18249
18314
  var isConfigDir = (file) => configDirs().some((dir) => canonical5(dir) === canonical5(file));
18250
- var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals|verdicts|agent-stamps)$/.test(path30.relative(canonical5(resolveStateDir()), canonical5(file)));
18315
+ var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals|verdicts|agent-stamps)$/.test(path31.relative(canonical5(resolveStateDir()), canonical5(file)));
18251
18316
  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)$/;
18252
18317
  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)$/;
18253
18318
  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*\(/;
@@ -18772,10 +18837,10 @@ var linkSources = (args, at) => {
18772
18837
  const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
18773
18838
  const target = dest === undefined ? null : at(dest);
18774
18839
  const symbolic = args.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg));
18775
- const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path30.dirname(target);
18840
+ const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path31.dirname(target);
18776
18841
  return sources.flatMap((source) => {
18777
- if (symbolic && base !== null && !path30.isAbsolute(homeExpanded(source)))
18778
- return [path30.resolve(base, source)];
18842
+ if (symbolic && base !== null && !path31.isAbsolute(homeExpanded(source)))
18843
+ return [path31.resolve(base, source)];
18779
18844
  const resolved = at(source);
18780
18845
  return resolved ? [resolved] : [];
18781
18846
  });
@@ -18820,7 +18885,7 @@ var linkReach = (verb, args, at, atAll) => {
18820
18885
  const dir = match ? match[1] ?? args[index + 1] : undefined;
18821
18886
  if (!dir)
18822
18887
  return [];
18823
- return [...atAll(dir), ...dest && !path30.isAbsolute(dir) ? atAll(path30.join(dest, dir)) : []];
18888
+ return [...atAll(dir), ...dest && !path31.isAbsolute(dir) ? atAll(path31.join(dest, dir)) : []];
18824
18889
  });
18825
18890
  }
18826
18891
  if (verb === "mklink")
@@ -18856,7 +18921,7 @@ var shellWrites = (command, depth = 0) => {
18856
18921
  return { writes: true, targets: unknown ? null : targets };
18857
18922
  };
18858
18923
  var cache2 = new Map;
18859
- var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path30.resolve(root, file)) ?? "-").join("\x00");
18924
+ var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path31.resolve(root, file)) ?? "-").join("\x00");
18860
18925
  var gateFor = (cwd) => {
18861
18926
  const store = new TaskReader(cwd);
18862
18927
  const listed = store.listTaskIndex();
@@ -18919,7 +18984,7 @@ var DIR_TARGET = ".workit-live-target";
18919
18984
  var PLACEHOLDERS = new WeakMap;
18920
18985
  var collecting = null;
18921
18986
  var placeholderIn = (dir, name) => {
18922
- const target = path30.join(dir, name);
18987
+ const target = path31.join(dir, name);
18923
18988
  collecting?.add(target);
18924
18989
  return target;
18925
18990
  };
@@ -18947,6 +19012,7 @@ var inlineWhy = (targets) => REASONS.get(targets);
18947
19012
  var OPAQUE_TARGET = ".workit-runs-";
18948
19013
  var UNRESOLVED_TARGET = ".workit-unresolved-target";
18949
19014
  var LINK_SOURCE = ".workit-link-source";
19015
+ var REMOVED_SOURCE = ".workit-removed-source";
18950
19016
  var OVERRIDE = "WORKIT_LIVE_SESSION=override";
18951
19017
  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("--"));
18952
19018
  var gitMutationDirs = (cwd, command, dialect) => {
@@ -18966,13 +19032,13 @@ var gitMutationDirs = (cwd, command, dialect) => {
18966
19032
  return [];
18967
19033
  if (sub === "stash" && ["list", "show"].includes(rest[0] ?? ""))
18968
19034
  return [];
18969
- return [path30.resolve(cwd, invocation.dir ?? ".")];
19035
+ return [path31.resolve(cwd, invocation.dir ?? ".")];
18970
19036
  });
18971
19037
  };
18972
19038
  var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
18973
19039
  var PUSHD2 = new Set(["pushd", "push-location"]);
18974
19040
  var POPD2 = new Set(["popd", "pop-location"]);
18975
- var UNKNOWN_DIR = path30.resolve(path30.parse(process.cwd()).root, ".workit-unknown-dir");
19041
+ var UNKNOWN_DIR = path31.resolve(path31.parse(process.cwd()).root, ".workit-unknown-dir");
18976
19042
  var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
18977
19043
  const lost = strict ? UNKNOWN_DIR : undefined;
18978
19044
  const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
@@ -18982,7 +19048,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
18982
19048
  return lost;
18983
19049
  if (dir === undefined)
18984
19050
  return lost;
18985
- return target === undefined ? os9.homedir() : path30.resolve(dir, target);
19051
+ return target === undefined ? os9.homedir() : path31.resolve(dir, target);
18986
19052
  };
18987
19053
  var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
18988
19054
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
@@ -19130,7 +19196,7 @@ var untrustedVars = (segments) => {
19130
19196
  }
19131
19197
  return { all, names };
19132
19198
  };
19133
- var UNKNOWN_VAR = path30.resolve(path30.parse(process.cwd()).root, ".workit-unknown-var");
19199
+ var UNKNOWN_VAR = path31.resolve(path31.parse(process.cwd()).root, ".workit-unknown-var");
19134
19200
  var REFERENCE = /\$\{(\w+)[^}]*\}|\$(\w+)|\$\([^)]*\)?|`[^`]*`?/g;
19135
19201
  var unresolvedRefs = (text) => [
19136
19202
  ...new Set([...text.matchAll(REFERENCE)].map((match) => {
@@ -19140,7 +19206,7 @@ var unresolvedRefs = (text) => [
19140
19206
  ];
19141
19207
  var unknownVarTarget = (text) => {
19142
19208
  const refs = unresolvedRefs(text);
19143
- return path30.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
19209
+ return path31.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
19144
19210
  };
19145
19211
  var applyOperator = (value, operator) => {
19146
19212
  if (operator === "")
@@ -19201,12 +19267,12 @@ var mktempPath = (value, dir) => {
19201
19267
  if (base === null && (temp || template === undefined))
19202
19268
  base = os9.tmpdir();
19203
19269
  const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
19204
- if (path30.isAbsolute(name))
19270
+ if (path31.isAbsolute(name))
19205
19271
  return name;
19206
19272
  const from = base === null ? dir : homeExpanded(base);
19207
- if (from === undefined || !path30.isAbsolute(from) && dir === undefined)
19273
+ if (from === undefined || !path31.isAbsolute(from) && dir === undefined)
19208
19274
  return null;
19209
- return path30.resolve(dir ?? from, from, name);
19275
+ return path31.resolve(dir ?? from, from, name);
19210
19276
  };
19211
19277
  var homeExpanded = (file) => {
19212
19278
  const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
@@ -19230,7 +19296,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19230
19296
  const home = homeExpanded(text);
19231
19297
  if (strict && unresolvedRefs(home).length > 0)
19232
19298
  return [unknownVarTarget(home)];
19233
- if (path30.isAbsolute(home))
19299
+ if (path31.isAbsolute(home))
19234
19300
  return [home];
19235
19301
  return base === undefined ? [] : [resolvedUnder(base, home)];
19236
19302
  });
@@ -19301,7 +19367,8 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19301
19367
  if (loop >= 0) {
19302
19368
  const [name = "", keyword, ...items] = segment.words.slice(loop + 1);
19303
19369
  const expanding = new Set(segment.expands ?? []);
19304
- const list = items.flatMap((item, index) => expanding.has(loop + 3 + index) ? listWords(item) : [listWord(homeExpanded(item))]);
19370
+ const globbedItem = (item) => strict === "registry" && dir !== undefined && /[*?[]/.test(item) ? expandGlob(path31.resolve(dir, homeExpanded(item))) : null;
19371
+ const list = items.flatMap((item, index) => globbedItem(item) ?? (expanding.has(loop + 3 + index) ? listWords(item) : [listWord(homeExpanded(item))]));
19305
19372
  vars.delete(name);
19306
19373
  if (keyword === "in" && list.length <= MAX_EXPANSIONS2 && !list.includes(null) && !untrusted.all && !untrusted.names.has(name))
19307
19374
  loops.set(name, list);
@@ -19440,7 +19507,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19440
19507
  index
19441
19508
  }));
19442
19509
  const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
19443
- const under = (word) => homes ? [path30.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
19510
+ const under = (word) => homes ? [path31.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
19444
19511
  const found = [
19445
19512
  ...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
19446
19513
  ...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
@@ -19448,7 +19515,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19448
19515
  for (const { file, index } of found) {
19449
19516
  const use = isRoot(file) ? rootUse(text, index) : "takes";
19450
19517
  if (use !== "reads")
19451
- targets.push(use === "builds" ? path30.join(file, UNRESOLVED_TARGET) : file);
19518
+ targets.push(use === "builds" ? path31.join(file, UNRESOLVED_TARGET) : file);
19452
19519
  }
19453
19520
  }
19454
19521
  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"))))
@@ -19458,7 +19525,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19458
19525
  `);
19459
19526
  for (const [linker = "", ...rest] of fedRuns(words, feed))
19460
19527
  for (const source of linkReach(commandName2(linker), rest, at, atAll))
19461
- targets.push(path30.join(source, LINK_SOURCE));
19528
+ targets.push(path31.join(source, LINK_SOURCE));
19462
19529
  }
19463
19530
  if (strict && dir !== undefined) {
19464
19531
  const runIn = dir;
@@ -19485,7 +19552,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19485
19552
  for (const file of opaque ?? [])
19486
19553
  for (const resolved of atAll(file))
19487
19554
  if (!quiet || !isRoot(resolved))
19488
- targets.push(file === "." ? placeholderIn(resolved, here) : path30.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path30.dirname(resolved), path30.basename(resolved)) : resolved);
19555
+ targets.push(file === "." ? placeholderIn(resolved, here) : path31.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path31.dirname(resolved), path31.basename(resolved)) : resolved);
19489
19556
  const [shell = "", ...shellArgs] = pastLead(words);
19490
19557
  const verb = (shell.split(/[\\/]/).at(-1) ?? "").toLowerCase();
19491
19558
  const named = (SCRIPT_SHELLS.has(verb) || verb === "source" || verb === ".") && shellScript3([verb, ...shellArgs]) === null ? scriptArgs(verb, shellArgs).named ?? "" : null;
@@ -19506,6 +19573,12 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
19506
19573
  if (dir !== undefined)
19507
19574
  targets.push(placeholderIn(dir, DIR_TARGET));
19508
19575
  }
19576
+ if (strict === "registry") {
19577
+ const { files: gone, find } = removalsOf(body);
19578
+ for (const root of gone)
19579
+ for (const file of atAll(root))
19580
+ targets.push(path31.join(file, find ? `${REMOVED_SOURCE}~${encodeURIComponent(JSON.stringify({ root, tests: find.tests }))}` : REMOVED_SOURCE));
19581
+ }
19509
19582
  for (const file of [...segment.redirects, ...edits ?? []])
19510
19583
  if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file) && !(dialect === "powershell" && /^(?:\$null|nul)$/i.test(file)))
19511
19584
  targets.push(...atAll(file));
@@ -19532,7 +19605,10 @@ var workitCwd = (dir, args, resolve) => {
19532
19605
  };
19533
19606
  var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
19534
19607
  try {
19535
- 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]] ?? ""]) : []);
19608
+ const env = new Map(strict === "registry" ? [
19609
+ ...[...command.matchAll(/\$\{?([A-Za-z_]\w*)/g)].filter((match) => !/^(?:OLD)?PWD$/.test(match[1])).map((match) => [match[1], process.env[match[1]] ?? ""]),
19610
+ ["PWD", cwd]
19611
+ ] : []);
19536
19612
  return recording(() => [
19537
19613
  ...segmentTargets(cwd, command, dialect, 0, strict, env),
19538
19614
  ...gitMutationDirs(cwd, command, dialect).map((dir) => placeholderIn(dir, DIR_TARGET))
@@ -19574,7 +19650,7 @@ var liveDeny = ({ marker, checkout, ageMs, file }) => {
19574
19650
  var guarded = (targets) => {
19575
19651
  const seen = new Set;
19576
19652
  return targets.filter((target) => {
19577
- const dir = path30.dirname(target);
19653
+ const dir = path31.dirname(target);
19578
19654
  if (seen.has(dir))
19579
19655
  return false;
19580
19656
  seen.add(dir);
@@ -19595,17 +19671,17 @@ var claimAll = (owner, targets, deps) => {
19595
19671
  for (const target of guarded(targets))
19596
19672
  claimLiveSession(target, owner, deps);
19597
19673
  };
19598
- var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path30.resolve(dir, file) : path30.isAbsolute(file) ? file : `${dir}${path30.sep}${file}`;
19674
+ var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path31.resolve(dir, file) : path31.isAbsolute(file) ? file : `${dir}${path31.sep}${file}`;
19599
19675
  var liveTargets = (cwd, paths) => recording(() => paths?.length ? paths.map((file) => resolvedUnder(cwd, file)) : [placeholderIn(cwd, DIR_TARGET)]);
19600
19676
  var CONFIG_FILES = ["workspaces.json", SEAL_FILE];
19601
19677
  var configDirs = () => [resolveConfigDir(), grantsDir()];
19602
19678
  var globbed = (cwd, target, state, configs) => {
19603
19679
  if (!/[*?[]/.test(target))
19604
19680
  return [];
19605
- const raw = path30.resolve(cwd, target).split(path30.sep);
19681
+ const raw = path31.resolve(cwd, target).split(path31.sep);
19606
19682
  const literal = raw.findIndex((part) => /[*?[]/.test(part));
19607
19683
  const pattern = [
19608
- ...canonical5(raw.slice(0, literal).join(path30.sep) || path30.sep).replace(/[\\/]+$/, "").split(path30.sep),
19684
+ ...canonical5(raw.slice(0, literal).join(path31.sep) || path31.sep).replace(/[\\/]+$/, "").split(path31.sep),
19609
19685
  ...raw.slice(literal)
19610
19686
  ];
19611
19687
  const segment = (glob, name) => {
@@ -19616,16 +19692,16 @@ var globbed = (cwd, target, state, configs) => {
19616
19692
  }
19617
19693
  };
19618
19694
  const hit = (file, below) => {
19619
- const parts = canonical5(file).split(path30.sep);
19695
+ const parts = canonical5(file).split(path31.sep);
19620
19696
  return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
19621
19697
  };
19622
19698
  let roots = [];
19623
19699
  try {
19624
- roots = readdirSync3(state).filter((name) => /^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name));
19700
+ roots = readdirSync4(state).filter((name) => /^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name));
19625
19701
  } catch {}
19626
19702
  return [
19627
- ...roots.map((name) => path30.join(state, name)).filter((root) => hit(root, true)),
19628
- ...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path30.join(dir, name))]).filter((file) => hit(file, false))
19703
+ ...roots.map((name) => path31.join(state, name)).filter((root) => hit(root, true)),
19704
+ ...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path31.join(dir, name))]).filter((file) => hit(file, false))
19629
19705
  ];
19630
19706
  };
19631
19707
  var guardedInodes = (state, configs) => {
@@ -19638,18 +19714,18 @@ var guardedInodes = (state, configs) => {
19638
19714
  if (stat?.isFile())
19639
19715
  seen.set(`${stat.dev}:${stat.ino}`, registry);
19640
19716
  else if (stat?.isDirectory())
19641
- for (const name of readdirSync3(file))
19642
- add(path30.join(file, name), registry);
19717
+ for (const name of readdirSync4(file))
19718
+ add(path31.join(file, name), registry);
19643
19719
  };
19644
19720
  try {
19645
19721
  for (const dir of configs)
19646
19722
  for (const name of CONFIG_FILES)
19647
- add(path30.join(dir, name), "grants");
19648
- for (const name of readdirSync3(state))
19723
+ add(path31.join(dir, name), "grants");
19724
+ for (const name of readdirSync4(state))
19649
19725
  if (/^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name))
19650
- add(path30.join(state, name), name === "approvals" ? "approvals" : name === "verdicts" || name === "agent-stamps" ? "ledger" : "issued");
19651
- for (const slug of readdirSync3(path30.join(state, "folders")))
19652
- add(path30.join(state, "folders", slug, "ledger"), "ledger");
19726
+ add(path31.join(state, name), name === "approvals" ? "approvals" : name === "verdicts" || name === "agent-stamps" ? "ledger" : "issued");
19727
+ for (const slug of readdirSync4(path31.join(state, "folders")))
19728
+ add(path31.join(state, "folders", slug, "ledger"), "ledger");
19653
19729
  } catch {}
19654
19730
  return seen;
19655
19731
  };
@@ -19666,19 +19742,87 @@ var hardLinked = (file, state, configs, inodes) => {
19666
19742
  };
19667
19743
  var inRepoLedger = (file) => [...file.matchAll(/[\\/]workit[\\/]ledger(?=[\\/]|$)/g)].some(({ index }) => {
19668
19744
  const gitDir = file.slice(0, index);
19669
- return /(?:^|[\\/])\.git$/.test(gitDir) || existsSync12(path30.join(gitDir, "HEAD")) && existsSync12(path30.join(gitDir, "objects"));
19745
+ return /(?:^|[\\/])\.git$/.test(gitDir) || existsSync12(path31.join(gitDir, "HEAD")) && existsSync12(path31.join(gitDir, "objects"));
19670
19746
  });
19671
19747
  var holdsGuarded = (cwd, source, state, configs) => {
19672
19748
  const real = canonical5(source);
19673
19749
  const below = (parent, child) => {
19674
- const rel = path30.relative(parent, child);
19675
- return rel === "" || !rel.startsWith("..") && !path30.isAbsolute(rel);
19750
+ const rel = path31.relative(parent, child);
19751
+ return rel === "" || !rel.startsWith("..") && !path31.isAbsolute(rel);
19676
19752
  };
19677
19753
  const holds = (file) => below(real, canonical5(file));
19678
- const inState = path30.relative(canonical5(state), real).split(path30.sep);
19679
- const ledgers = ["ledger", "workit/ledger", ".git/workit/ledger"].map((rel) => path30.join(real, rel)).filter((dir) => existsSync12(dir) && inRepoLedger(dir));
19754
+ const inState = path31.relative(canonical5(state), real).split(path31.sep);
19755
+ const ledgers = ["ledger", "workit/ledger", ".git/workit/ledger"].map((rel) => path31.join(real, rel)).filter((dir) => existsSync12(dir) && inRepoLedger(dir));
19756
+ const own = ledgerPath(cwd);
19757
+ return holds(state) || below(canonical5(state), real) && inState[0] === "folders" && inState.length <= 2 || configs.some(holds) || ledgers.length > 0 || own.ok && existsSync12(own.value) && holds(path31.dirname(own.value));
19758
+ };
19759
+ var removesLedger = (cwd, source, state, configs) => {
19760
+ const real = canonical5(source);
19761
+ if (/(?:^|[\\/])\.git(?:[\\/]workit)?$/i.test(real) || inRepoLedger(real))
19762
+ return true;
19763
+ const own = ledgerPath(cwd);
19764
+ if (own.ok) {
19765
+ const rel = path31.relative(real, canonical5(path31.dirname(own.value)));
19766
+ if (rel === "" || !rel.startsWith("..") && !path31.isAbsolute(rel))
19767
+ return true;
19768
+ }
19769
+ return holdsGuarded(cwd, source, state, configs);
19770
+ };
19771
+ var findTests = (marker) => {
19772
+ try {
19773
+ return JSON.parse(decodeURIComponent(marker.slice(REMOVED_SOURCE.length + 1)));
19774
+ } catch {
19775
+ return null;
19776
+ }
19777
+ };
19778
+ var findReachesLedger = (cwd, root, find) => {
19779
+ if (find === null)
19780
+ return true;
19781
+ const real = canonical5(root);
19680
19782
  const own = ledgerPath(cwd);
19681
- return holds(state) || below(canonical5(state), real) && inState[0] === "folders" && inState.length <= 2 || configs.some(holds) || ledgers.length > 0 || own.ok && existsSync12(own.value) && holds(path30.dirname(own.value));
19783
+ const ledgers = [
19784
+ ...own.ok ? [canonical5(path31.dirname(own.value))] : [],
19785
+ ...[".git/workit/ledger", "workit/ledger", "ledger"].map((rel) => path31.join(real, rel)).filter((dir) => existsSync12(dir) && inRepoLedger(dir))
19786
+ ];
19787
+ const under = (parent, child) => {
19788
+ const rel = path31.relative(parent, child);
19789
+ return rel === "" || !rel.startsWith("..") && !path31.isAbsolute(rel);
19790
+ };
19791
+ const patterns = find.tests.map(([kind, pattern]) => {
19792
+ const fold = kind.endsWith("i");
19793
+ const glob = globPattern(pattern, true);
19794
+ let test = /(?:)/;
19795
+ try {
19796
+ test = kind.startsWith("regex") ? new RegExp(`^${pattern}$`, fold ? "i" : "") : glob ? new RegExp(glob.source, fold ? "iu" : "u") : test;
19797
+ } catch {}
19798
+ return { kind, test };
19799
+ });
19800
+ const matches = (entry) => patterns.length === 0 || patterns.some(({ kind, test }) => test.test(kind.startsWith("name") ? path31.basename(entry) : path31.join(find.root, path31.relative(real, entry)).replaceAll("\\", "/")));
19801
+ for (const ledger of ledgers) {
19802
+ if (!existsSync12(ledger) || !under(real, ledger) && !under(ledger, real))
19803
+ continue;
19804
+ const entries = [];
19805
+ for (let dir = ledger;under(real, dir) && dir !== real; dir = path31.dirname(dir))
19806
+ entries.push(dir);
19807
+ const walk = (dir) => {
19808
+ for (const item of readdirSync4(dir, { withFileTypes: true })) {
19809
+ if (entries.length > 500)
19810
+ return;
19811
+ const file = path31.join(dir, item.name);
19812
+ entries.push(file);
19813
+ if (item.isDirectory())
19814
+ walk(file);
19815
+ }
19816
+ };
19817
+ try {
19818
+ walk(ledger);
19819
+ } catch {
19820
+ return true;
19821
+ }
19822
+ if (entries.some((entry) => under(real, entry) && matches(entry)))
19823
+ return true;
19824
+ }
19825
+ return false;
19682
19826
  };
19683
19827
  var registryTarget = (cwd, targets) => {
19684
19828
  const state = resolveStateDir();
@@ -19686,20 +19830,28 @@ var registryTarget = (cwd, targets) => {
19686
19830
  const inodes = {};
19687
19831
  for (const target of targets) {
19688
19832
  const file = homeExpanded(target);
19689
- if (path30.basename(file) === LINK_SOURCE) {
19690
- const source = path30.dirname(path30.resolve(cwd, file));
19833
+ if (path31.basename(file).startsWith(REMOVED_SOURCE)) {
19834
+ const marker = path31.basename(file);
19835
+ const source = path31.dirname(path31.resolve(cwd, file));
19836
+ const find = marker === REMOVED_SOURCE ? null : findTests(marker);
19837
+ if (expandGlob(source).some((gone) => find ? findReachesLedger(cwd, gone, find) : removesLedger(cwd, gone, state, configs)))
19838
+ return { file: path31.join(source, REMOVED_SOURCE), registry: "removes" };
19839
+ continue;
19840
+ }
19841
+ if (path31.basename(file) === LINK_SOURCE) {
19842
+ const source = path31.dirname(path31.resolve(cwd, file));
19691
19843
  const reached = registryTarget(cwd, [source])?.registry ?? (holdsGuarded(cwd, source, state, configs) ? "holds" : null);
19692
19844
  if (reached)
19693
19845
  return { file: target, registry: reached };
19694
19846
  continue;
19695
19847
  }
19696
- if (realPath(path30.resolve(cwd, file)) === null)
19848
+ if (realPath(path31.resolve(cwd, file)) === null)
19697
19849
  return { file: target, registry: "link" };
19698
19850
  const glob = globbed(cwd, file, state, configs)[0];
19699
19851
  const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
19700
19852
  if (viaGlob)
19701
19853
  return { file: target, registry: viaGlob.registry };
19702
- const registry = hardLinked(path30.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical5) ?? (inRepoLedger(canonical5(path30.resolve(cwd, file))) ? "ledger" : null) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical5)) ? "grants" : null);
19854
+ const registry = hardLinked(path31.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical5) ?? (inRepoLedger(canonical5(path31.resolve(cwd, file))) ? "ledger" : null) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical5)) ? "grants" : null);
19703
19855
  if (registry)
19704
19856
  return { file: target, registry };
19705
19857
  }
@@ -19707,7 +19859,7 @@ var registryTarget = (cwd, targets) => {
19707
19859
  };
19708
19860
  var partsUnder = (dir, cwd, target, platform, real) => {
19709
19861
  const win = platform === "win32";
19710
- const p = win ? path30.win32 : path30.posix;
19862
+ const p = win ? path31.win32 : path31.posix;
19711
19863
  const fold = (value) => win || platform === "darwin" ? value.toLowerCase() : value;
19712
19864
  const named = win ? target.replace(/^\/([a-zA-Z])(?=\/|$)/, "$1:") : target;
19713
19865
  const relative = p.relative(fold(real(p.resolve(dir))), fold(real(p.resolve(cwd, named))));
@@ -19760,6 +19912,11 @@ var REGISTRY_DENY = {
19760
19912
  what: "a symlink chain Workit could not resolve (over 40 links), which may reach a guarded path",
19761
19913
  unblock: "Write to the file's real path."
19762
19914
  },
19915
+ removes: {
19916
+ label: "ledger guard",
19917
+ what: "a Workit ledger, the git dir that holds one or Workit's state",
19918
+ 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."
19919
+ },
19763
19920
  holds: {
19764
19921
  label: "registry guard",
19765
19922
  what: "Workit's state, its config or a repository ledger",
@@ -19788,19 +19945,25 @@ var REGISTRY_DENY = {
19788
19945
  };
19789
19946
  var registryDeny = ({ file, registry }) => {
19790
19947
  const { label, what, unblock } = REGISTRY_DENY[registry];
19791
- if (path30.basename(file) === LINK_SOURCE)
19948
+ if (path31.basename(file) === LINK_SOURCE)
19792
19949
  return {
19793
19950
  kind: "deny",
19794
- reason: `workit ${label}: this command links or mounts ${path30.dirname(file)}, which is or holds ${what}. ${LINK_UNBLOCK}`,
19951
+ reason: `workit ${label}: this command links or mounts ${path31.dirname(file)}, which is or holds ${what}. ${LINK_UNBLOCK}`,
19795
19952
  unblock: LINK_UNBLOCK
19796
19953
  };
19797
- if (path30.basename(file) === UNRESOLVED_TARGET)
19954
+ if (path31.basename(file) === REMOVED_SOURCE)
19955
+ return {
19956
+ kind: "deny",
19957
+ reason: `workit ${label}: this command removes or moves ${path31.dirname(file)}, which is or holds ${what}. ${unblock}`,
19958
+ unblock
19959
+ };
19960
+ if (path31.basename(file) === UNRESOLVED_TARGET)
19798
19961
  return {
19799
19962
  kind: "deny",
19800
19963
  reason: `workit ${label}: Workit could not resolve the file this command's script writes, which it builds from a path under ${what}. ${unblock}`,
19801
19964
  unblock
19802
19965
  };
19803
- const named = path30.basename(file).startsWith(".workit-") ? path30.dirname(file) : file;
19966
+ const named = path31.basename(file).startsWith(".workit-") ? path31.dirname(file) : file;
19804
19967
  return {
19805
19968
  kind: "deny",
19806
19969
  reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
@@ -19891,10 +20054,10 @@ import { spawnSync as spawnSync16 } from "node:child_process";
19891
20054
 
19892
20055
  // packages/workit-core/src/ci-waiter.ts
19893
20056
  import fs21 from "node:fs";
19894
- import path31 from "node:path";
20057
+ import path32 from "node:path";
19895
20058
  var waiterFile = (cwd, pr) => {
19896
20059
  const common = gitCommonDir(cwd);
19897
- return common ? path31.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
20060
+ return common ? path32.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
19898
20061
  };
19899
20062
  var pidAlive2 = (pid) => {
19900
20063
  if (!Number.isSafeInteger(pid) || pid <= 0)
@@ -19966,11 +20129,11 @@ function currentJudgment(cwd) {
19966
20129
  }
19967
20130
 
19968
20131
  // packages/workit-core/src/core/verdict-set.ts
19969
- import path32 from "node:path";
20132
+ import path33 from "node:path";
19970
20133
  var SET_TTL_MS = 7 * 86400000;
19971
20134
  var SET_ROW = "verdict.set";
19972
20135
  var SET_VOID = "verdict.set.voided";
19973
- var setStorePath = () => path32.join(resolveStateDir(), "verdicts", "sets", "ledger.jsonl");
20136
+ var setStorePath = () => path33.join(resolveStateDir(), "verdicts", "sets", "ledger.jsonl");
19974
20137
  var distrusted = (cwd, id, rows, type) => rows.some((row) => row.type === type && row.id === id && trustReasons(cwd, row).length > 0);
19975
20138
  function gateStands(cwd, gate, rows, now = Date.now()) {
19976
20139
  const id = typeof gate.verdictId === "string" ? gate.verdictId : null;
@@ -20421,12 +20584,12 @@ ${line}` };
20421
20584
  };
20422
20585
  // packages/workit-core/src/hooks/hosts/fields.ts
20423
20586
  import { existsSync as existsSync13, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
20424
- import path33 from "node:path";
20587
+ import path34 from "node:path";
20425
20588
  var isRecord7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
20426
20589
  var nonEmpty2 = (value) => typeof value === "string" && value.trim() !== "";
20427
20590
  var optionalText = (value) => typeof value === "string" ? value : null;
20428
20591
  var existingDirectory = (value) => {
20429
- if (!nonEmpty2(value) || !path33.isAbsolute(value) || !existsSync13(value))
20592
+ if (!nonEmpty2(value) || !path34.isAbsolute(value) || !existsSync13(value))
20430
20593
  return null;
20431
20594
  try {
20432
20595
  return statSync4(value).isDirectory() ? realpathSync9(value) : null;
@@ -20494,7 +20657,7 @@ var writeTargets = (input) => {
20494
20657
  };
20495
20658
  // packages/workit-core/src/hooks/standing.ts
20496
20659
  import fs23 from "node:fs";
20497
- import path35 from "node:path";
20660
+ import path36 from "node:path";
20498
20661
 
20499
20662
  // packages/workit-core/src/approvals/store.ts
20500
20663
  var REQUEST_TTL_MS = 30 * 60000;
@@ -21202,35 +21365,35 @@ function neededChecks(lane, configured) {
21202
21365
  import { createHash as createHash16 } from "node:crypto";
21203
21366
  import fs22 from "node:fs";
21204
21367
  import os10 from "node:os";
21205
- import path34 from "node:path";
21368
+ import path35 from "node:path";
21206
21369
  var FANOUT_TOKEN_FILE = "workit-fanout-token";
21207
21370
  var NONE5 = { kind: "none" };
21208
21371
  var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
21209
21372
  var realOf = (file) => {
21210
21373
  let rest = "";
21211
- for (let dir = file;; dir = path34.dirname(dir)) {
21374
+ for (let dir = file;; dir = path35.dirname(dir)) {
21212
21375
  try {
21213
- return path34.join(fs22.realpathSync.native(dir), rest);
21376
+ return path35.join(fs22.realpathSync.native(dir), rest);
21214
21377
  } catch {
21215
- if (path34.dirname(dir) === dir)
21378
+ if (path35.dirname(dir) === dir)
21216
21379
  return file;
21217
- rest = rest ? path34.join(path34.basename(dir), rest) : path34.basename(dir);
21380
+ rest = rest ? path35.join(path35.basename(dir), rest) : path35.basename(dir);
21218
21381
  }
21219
21382
  }
21220
21383
  };
21221
21384
  var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
21222
- const start = path34.isAbsolute(file) ? file : `${process.cwd()}${path34.sep}${file}`;
21223
- const { root } = path34.parse(start);
21385
+ const start = path35.isAbsolute(file) ? file : `${process.cwd()}${path35.sep}${file}`;
21386
+ const { root } = path35.parse(start);
21224
21387
  let at = root;
21225
21388
  let missing = false;
21226
21389
  for (const part of start.slice(root.length).split(/[\\/]+/)) {
21227
21390
  if (part === "" || part === ".")
21228
21391
  continue;
21229
21392
  if (part === "..") {
21230
- at = path34.dirname(at);
21393
+ at = path35.dirname(at);
21231
21394
  continue;
21232
21395
  }
21233
- const next = path34.join(at, part);
21396
+ const next = path35.join(at, part);
21234
21397
  let link = null;
21235
21398
  if (!missing)
21236
21399
  try {
@@ -21242,25 +21405,25 @@ var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
21242
21405
  at = next;
21243
21406
  hops.chain = 40;
21244
21407
  } else if (hops.chain-- > 0 && hops.total-- > 0)
21245
- at = canonical6(path34.isAbsolute(link) ? link : `${at}${path34.sep}${link}`, hops);
21408
+ at = canonical6(path35.isAbsolute(link) ? link : `${at}${path35.sep}${link}`, hops);
21246
21409
  else
21247
- return path34.resolve(file);
21410
+ return path35.resolve(file);
21248
21411
  }
21249
21412
  return realOf(at);
21250
21413
  };
21251
21414
  var within = (child, parent) => {
21252
21415
  const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
21253
- const relative = path34.relative(fold(parent), fold(child));
21254
- return relative === "" || !relative.startsWith("..") && !path34.isAbsolute(relative);
21416
+ const relative = path35.relative(fold(parent), fold(child));
21417
+ return relative === "" || !relative.startsWith("..") && !path35.isAbsolute(relative);
21255
21418
  };
21256
21419
  var checkoutOf2 = (file) => {
21257
- for (let dir = canonical6(file);; dir = path34.dirname(dir)) {
21258
- const dotGit = path34.join(dir, ".git");
21420
+ for (let dir = canonical6(file);; dir = path35.dirname(dir)) {
21421
+ const dotGit = path35.join(dir, ".git");
21259
21422
  if (fs22.existsSync(dotGit)) {
21260
21423
  const admin = fs22.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
21261
- return { root: dir, workit: !!admin && fs22.existsSync(path34.join(admin, FANOUT_TOKEN_FILE)) };
21424
+ return { root: dir, workit: !!admin && fs22.existsSync(path35.join(admin, FANOUT_TOKEN_FILE)) };
21262
21425
  }
21263
- if (path34.dirname(dir) === dir)
21426
+ if (path35.dirname(dir) === dir)
21264
21427
  return null;
21265
21428
  }
21266
21429
  };
@@ -21272,8 +21435,8 @@ var workitWorktreeOf = (file) => {
21272
21435
  return null;
21273
21436
  }
21274
21437
  };
21275
- var bindingDir = () => path34.join(resolveStateDir(), "worktree-bind");
21276
- var bindingFile = (session, agentId) => path34.join(bindingDir(), `${createHash16("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
21438
+ var bindingDir = () => path35.join(resolveStateDir(), "worktree-bind");
21439
+ var bindingFile = (session, agentId) => path35.join(bindingDir(), `${createHash16("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
21277
21440
  var readBinding = (file) => {
21278
21441
  try {
21279
21442
  const value = JSON.parse(fs22.readFileSync(file, "utf8"));
@@ -21298,7 +21461,7 @@ var bind = (input, worktree) => {
21298
21461
  agentId,
21299
21462
  at: new Date().toISOString()
21300
21463
  };
21301
- fs22.mkdirSync(path34.dirname(file), { recursive: true });
21464
+ fs22.mkdirSync(path35.dirname(file), { recursive: true });
21302
21465
  fs22.writeFileSync(file, JSON.stringify(binding));
21303
21466
  try {
21304
21467
  if (inWorkitWorkspace(input.cwd))
@@ -21317,26 +21480,26 @@ var hostIsolated = (cwd, agentId) => {
21317
21480
  const checkout = checkoutOf2(cwd);
21318
21481
  if (!checkout)
21319
21482
  return false;
21320
- const dotGit = path34.join(checkout.root, ".git");
21483
+ const dotGit = path35.join(checkout.root, ".git");
21321
21484
  if (!fs22.statSync(dotGit).isFile())
21322
21485
  return false;
21323
21486
  const [adminDir, gitDir] = gitDirsAt(checkout.root, null, false) ?? [];
21324
- const back = fs22.readFileSync(path34.join(adminDir, "gitdir"), "utf8").trim();
21325
- if (path34.relative(canonical6(path34.resolve(adminDir, back)), canonical6(dotGit)) !== "")
21487
+ const back = fs22.readFileSync(path35.join(adminDir, "gitdir"), "utf8").trim();
21488
+ if (path35.relative(canonical6(path35.resolve(adminDir, back)), canonical6(dotGit)) !== "")
21326
21489
  return false;
21327
- const expected = path34.join(path34.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
21328
- return path34.relative(canonical6(expected), checkout.root) === "";
21490
+ const expected = path35.join(path35.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
21491
+ return path35.relative(canonical6(expected), checkout.root) === "";
21329
21492
  } catch {
21330
21493
  return false;
21331
21494
  }
21332
21495
  };
21333
21496
  var runnerAt = (target) => {
21334
- const base = path34.basename(target);
21497
+ const base = path35.basename(target);
21335
21498
  return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
21336
21499
  };
21337
21500
  var shown = (target) => {
21338
- const named = /^\.workit-(?:live-target$|runs-)/.test(path34.basename(target)) ? path34.dirname(target) : target;
21339
- return path34.sep === "\\" ? named.replaceAll("/", "\\") : named;
21501
+ const named = /^\.workit-(?:live-target$|runs-)/.test(path35.basename(target)) ? path35.dirname(target) : target;
21502
+ return path35.sep === "\\" ? named.replaceAll("/", "\\") : named;
21340
21503
  };
21341
21504
  var runFrom = (dir, command) => `cd ${dir} && ${command.replace(/^\s*cd\s+\S+\s*(?:&&|;)\s*/, "")}`;
21342
21505
  var deny2 = (what, unblock) => ({
@@ -21352,7 +21515,7 @@ var outsideDeny = (input, worktree, target, command) => {
21352
21515
  };
21353
21516
  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\`.`);
21354
21517
  var refsOf = (targets) => [
21355
- ...new Set(targets.flatMap((target) => path34.relative(UNKNOWN_VAR, path34.resolve(target)).split(path34.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
21518
+ ...new Set(targets.flatMap((target) => path35.relative(UNKNOWN_VAR, path35.resolve(target)).split(path35.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
21356
21519
  ];
21357
21520
  var literalForm = (command, refs) => {
21358
21521
  let text = command;
@@ -21385,10 +21548,10 @@ function confineImplementer(input, targets, command) {
21385
21548
  try {
21386
21549
  if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
21387
21550
  return NONE5;
21388
- const unresolved = targets.filter((target) => within(path34.resolve(target), UNKNOWN_VAR));
21551
+ const unresolved = targets.filter((target) => within(path35.resolve(target), UNKNOWN_VAR));
21389
21552
  if (unresolved.length > 0)
21390
21553
  return unknownVarDeny(input, unresolved, command);
21391
- if (targets.some((target) => within(path34.resolve(target), UNKNOWN_DIR)))
21554
+ if (targets.some((target) => within(path35.resolve(target), UNKNOWN_DIR)))
21392
21555
  return unknownDirDeny(input, boundWorktree(input));
21393
21556
  const bindings = canonical6(bindingDir());
21394
21557
  const judged = targets.map((named) => ({ named, real: canonical6(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
@@ -21495,10 +21658,10 @@ var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print)(?:=|$)|^--(?:test|version|he
21495
21658
  var VALUED2 = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
21496
21659
  var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
21497
21660
  var inScratch = (real, repo) => {
21498
- for (let dir = real;path34.dirname(dir) !== dir; dir = path34.dirname(dir)) {
21499
- if (path34.basename(dir) !== SCRATCH)
21661
+ for (let dir = real;path35.dirname(dir) !== dir; dir = path35.dirname(dir)) {
21662
+ if (path35.basename(dir) !== SCRATCH)
21500
21663
  continue;
21501
- const root = path34.dirname(dir);
21664
+ const root = path35.dirname(dir);
21502
21665
  const checkout = checkoutOf2(root);
21503
21666
  if (checkout?.root === root && (repo === null || checkout.workit || commonDir(root) === repo))
21504
21667
  return true;
@@ -21508,7 +21671,7 @@ var inScratch = (real, repo) => {
21508
21671
  var inGitDir = (real) => real.split(/[\\/]/).includes(".git");
21509
21672
  var SAFE_KEY = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|ignorecase|precomposeunicode|symlinks)|user\..*|init\.defaultbranch|commit\.gpgsign|extensions\.(?:objectformat|refstorage)|branch\..*\.(?:remote|merge)|remote\..*\.fetch)$/;
21510
21673
  var literalIn = (value, repo, checkout = false) => {
21511
- if (/[$`]/.test(value) || !path34.isAbsolute(value))
21674
+ if (/[$`]/.test(value) || !path35.isAbsolute(value))
21512
21675
  return false;
21513
21676
  const real = canonical6(value);
21514
21677
  const root = checkout ? checkoutOf2(real)?.root : undefined;
@@ -21529,8 +21692,8 @@ var configEntries = (text) => {
21529
21692
  return entries;
21530
21693
  };
21531
21694
  function gitDirsAt(dir, repo, scan = true) {
21532
- for (let at = dir;; at = path34.dirname(at)) {
21533
- const dotGit = path34.join(at, ".git");
21695
+ for (let at = dir;; at = path35.dirname(at)) {
21696
+ const dotGit = path35.join(at, ".git");
21534
21697
  let gitDir = null;
21535
21698
  try {
21536
21699
  if (fs22.statSync(dotGit).isDirectory())
@@ -21539,19 +21702,19 @@ function gitDirsAt(dir, repo, scan = true) {
21539
21702
  const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs22.readFileSync(dotGit, "utf8"))?.[1];
21540
21703
  if (!named)
21541
21704
  return null;
21542
- gitDir = canonical6(path34.resolve(at, named));
21705
+ gitDir = canonical6(path35.resolve(at, named));
21543
21706
  }
21544
21707
  } catch (error) {
21545
21708
  if (error.code !== "ENOENT")
21546
21709
  return null;
21547
- if (["HEAD", "objects", "refs"].every((name) => fs22.existsSync(path34.join(at, name))))
21710
+ if (["HEAD", "objects", "refs"].every((name) => fs22.existsSync(path35.join(at, name))))
21548
21711
  gitDir = canonical6(at);
21549
21712
  }
21550
21713
  if (gitDir !== null) {
21551
- const common = path34.join(gitDir, "commondir");
21552
- const shared = fs22.existsSync(common) ? canonical6(path34.resolve(gitDir, fs22.readFileSync(common, "utf8").trim())) : gitDir;
21714
+ const common = path35.join(gitDir, "commondir");
21715
+ const shared = fs22.existsSync(common) ? canonical6(path35.resolve(gitDir, fs22.readFileSync(common, "utf8").trim())) : gitDir;
21553
21716
  const dirs = [gitDir, shared];
21554
- for (const config of scan ? new Set([path34.join(gitDir, "config"), path34.join(shared, "config")]) : []) {
21717
+ for (const config of scan ? new Set([path35.join(gitDir, "config"), path35.join(shared, "config")]) : []) {
21555
21718
  let text = "";
21556
21719
  try {
21557
21720
  text = fs22.readFileSync(config, "utf8");
@@ -21560,14 +21723,14 @@ function gitDirsAt(dir, repo, scan = true) {
21560
21723
  }
21561
21724
  for (const [key, value] of configEntries(text)) {
21562
21725
  if (key === "core.worktree")
21563
- dirs.push(canonical6(path34.resolve(gitDir, value)));
21726
+ dirs.push(canonical6(path35.resolve(gitDir, value)));
21564
21727
  else if (/^remote\..*\.url$/.test(key) ? !literalIn(value, repo, true) : !SAFE_KEY.test(key))
21565
21728
  return null;
21566
21729
  }
21567
21730
  }
21568
21731
  return dirs;
21569
21732
  }
21570
- if (path34.dirname(at) === at)
21733
+ if (path35.dirname(at) === at)
21571
21734
  return [];
21572
21735
  }
21573
21736
  }
@@ -21707,10 +21870,10 @@ var gitKind = (args, local = () => true) => {
21707
21870
  return GIT_VERBS[verb].startsWith("+") ? "write" : "read";
21708
21871
  };
21709
21872
  var remoteIn = (dir, name, repo) => {
21710
- const shared = path34.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
21873
+ const shared = path35.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
21711
21874
  if (!shared)
21712
21875
  return false;
21713
- const url = configEntries(fs22.readFileSync(path34.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
21876
+ const url = configEntries(fs22.readFileSync(path35.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
21714
21877
  return url !== undefined && literalIn(url, repo, true);
21715
21878
  };
21716
21879
  var judgeEnvAllowed = (word) => {
@@ -21739,7 +21902,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
21739
21902
  at = after;
21740
21903
  }
21741
21904
  }
21742
- const name = path34.basename(words[at] ?? "");
21905
+ const name = path35.basename(words[at] ?? "");
21743
21906
  let start = words.findIndex((word) => /(?:^|[\\/])git(?:\.exe)?(?:=|$)/.test(word));
21744
21907
  if (start > at) {
21745
21908
  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] ?? ""))
@@ -21750,7 +21913,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
21750
21913
  if (start >= 0 && words[start].includes("="))
21751
21914
  why = "git is redefined";
21752
21915
  const run = words[start] ?? "";
21753
- if (run.includes("/") && (!path34.isAbsolute(run) || literalIn(run, repo, true)))
21916
+ if (run.includes("/") && (!path35.isAbsolute(run) || literalIn(run, repo, true)))
21754
21917
  why ??= `\`${run}\` is not the system git`;
21755
21918
  if (segment.expands?.includes(at) && name !== "[" || /\{[^}]*,/.test(words[at] ?? ""))
21756
21919
  why = "the command's name is expanded by the shell";
@@ -21775,13 +21938,13 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
21775
21938
  const args = words[index] === "--version" ? ["version"] : words.slice(index);
21776
21939
  if (!why && start >= 0) {
21777
21940
  const local = (source, remote) => remote && /^[\w-][\w.-]*$/.test(source) ? remoteIn(dir, source, repo) : literalIn(source, repo, true);
21778
- const runsIn = path34.isAbsolute(dir) ? dir : cwd && path34.resolve(cwd, dir);
21941
+ const runsIn = path35.isAbsolute(dir) ? dir : cwd && path35.resolve(cwd, dir);
21779
21942
  const home = runsIn && checkoutOf2(runsIn);
21780
21943
  const fetches = args[0] === "fetch" && plainFetch(args.slice(1)) && home && (home.workit || commonDir(home.root) === repo) && !words.some((word) => /^--[gw]/.test(word));
21781
21944
  if (!fetches && !gitKind(args, local))
21782
21945
  why = `\`git ${args.slice(0, 2).join(" ")}\` is not allowed`;
21783
21946
  }
21784
- const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path34.basename(word)));
21947
+ const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path35.basename(word)));
21785
21948
  const scripts = [
21786
21949
  ...words.filter((_, after) => shell >= 0 && after > shell && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(words[after - 1])),
21787
21950
  ...shell < 0 ? [] : segment.stdin ?? []
@@ -21826,7 +21989,7 @@ var judgeVerbRefused = (args) => {
21826
21989
  var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
21827
21990
  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?$/;
21828
21991
  var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
21829
- const name = path34.basename(words[0] ?? "").toLowerCase();
21992
+ const name = path35.basename(words[0] ?? "").toLowerCase();
21830
21993
  if (name === "alias")
21831
21994
  return words.flatMap((word) => {
21832
21995
  const set = /^([\w-]+)=(.*)$/s.exec(word);
@@ -21855,11 +22018,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
21855
22018
  return why;
21856
22019
  }
21857
22020
  const { words } = segment;
21858
- const runs = (word = "") => RUNS.test(path34.basename(word).toLowerCase());
22021
+ const runs = (word = "") => RUNS.test(path35.basename(word).toLowerCase());
21859
22022
  let at = 0;
21860
22023
  while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
21861
22024
  at++;
21862
- const name = path34.basename(words[at] ?? "").toLowerCase();
22025
+ const name = path35.basename(words[at] ?? "").toLowerCase();
21863
22026
  const args = words.slice(at + 1);
21864
22027
  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`;
21865
22028
  if (/^(?:cd|chdir|pushd|popd)$/.test(name))
@@ -21941,10 +22104,10 @@ var judgeDeny = (input, what, target, retry, why = "write only there (mkdir -p i
21941
22104
  const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
21942
22105
  const root = checkoutOf2(input.cwd)?.root;
21943
22106
  const candidate = target ? checkoutOf2(target)?.root : undefined;
21944
- const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path34.join(candidate, SCRATCH) : undefined;
21945
- const scratch = root ? `${path34.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
21946
- const call = root ? retry?.((other ?? path34.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
21947
- const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ? path34.join(root, SCRATCH) : SCRATCH))}`;
22107
+ const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path35.join(candidate, SCRATCH) : undefined;
22108
+ const scratch = root ? `${path35.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
22109
+ const call = root ? retry?.((other ?? path35.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
22110
+ const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ? path35.join(root, SCRATCH) : SCRATCH))}`;
21948
22111
  return {
21949
22112
  kind: "deny",
21950
22113
  reason: `workit scratch confinement: ${role} ${input.session.agentId} may write only in its scratch dir ${scratch}, and ${what}.
@@ -21954,9 +22117,9 @@ ${unblock}`,
21954
22117
  };
21955
22118
  var movedInto = (command, cwd, target, dir) => {
21956
22119
  for (const { words, redirects } of segmentsOf(command))
21957
- for (const word of [...redirects, ...path34.basename(words[0] ?? "") === "tee" ? words : []])
21958
- if (path34.resolve(cwd, word) === path34.resolve(cwd, target)) {
21959
- const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path34.basename(word)}`);
22120
+ for (const word of [...redirects, ...path35.basename(words[0] ?? "") === "tee" ? words : []])
22121
+ if (path35.resolve(cwd, word) === path35.resolve(cwd, target)) {
22122
+ const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path35.basename(word)}`);
21960
22123
  return moved === command ? null : moved;
21961
22124
  }
21962
22125
  return null;
@@ -21968,19 +22131,19 @@ function confineJudge(input, targets, placeholders = placeholdersOf(targets), co
21968
22131
  const judged = checkoutOf2(input.cwd);
21969
22132
  const repo = judged ? commonDir(judged.root) : null;
21970
22133
  const scratch = (real) => inScratch(real, repo) || [os10.tmpdir(), "/tmp"].some((dir) => {
21971
- const [host, , session] = path34.relative(canonical6(dir), real).split(path34.sep);
22134
+ const [host, , session] = path35.relative(canonical6(dir), real).split(path35.sep);
21972
22135
  return /^claude-\d+$/.test(host) && session === input.session.id;
21973
22136
  });
21974
22137
  for (const target of targets) {
21975
- const resolved = path34.resolve(target);
22138
+ const resolved = path35.resolve(target);
21976
22139
  if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
21977
22140
  return judgeDeny(input, "it writes to a path Workit cannot resolve", undefined, () => {
21978
22141
  const literal = command && literalForm(command, refsOf([target]));
21979
22142
  return literal === command ? null : literal;
21980
22143
  });
21981
22144
  const real = canonical6(target);
21982
- const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path34.basename(target));
21983
- const gitDirs = runsGit ? gitDirsAt(path34.dirname(real), repo) : [];
22145
+ const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path35.basename(target));
22146
+ const gitDirs = runsGit ? gitDirsAt(path35.dirname(real), repo) : [];
21984
22147
  if (gitDirs === null)
21985
22148
  return judgeDeny(input, `git in ${shown(target)} uses a git dir or config Workit cannot check`);
21986
22149
  if (runsGit ? gitDirs.length > 0 ? gitDirs.every(scratch) : scratch(real) : scratch(real) && !inGitDir(real))
@@ -22048,7 +22211,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
22048
22211
  let git = [];
22049
22212
  try {
22050
22213
  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)))) ? [
22051
- path34.join(dir === undefined ? UNKNOWN_DIR : path34.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
22214
+ path35.join(dir === undefined ? UNKNOWN_DIR : path35.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
22052
22215
  ] : []);
22053
22216
  } catch {}
22054
22217
  const lists = [
@@ -22093,7 +22256,7 @@ var judgeChecksLine = (cwd) => {
22093
22256
 
22094
22257
  // packages/workit-core/src/hooks/standing.ts
22095
22258
  var readPlans = (store) => {
22096
- const dir = path35.join(store, "fanouts");
22259
+ const dir = path36.join(store, "fanouts");
22097
22260
  let names;
22098
22261
  try {
22099
22262
  names = fs23.readdirSync(dir).filter((name) => name.endsWith(".json"));
@@ -22103,7 +22266,7 @@ var readPlans = (store) => {
22103
22266
  const plans = [];
22104
22267
  for (const name of names) {
22105
22268
  try {
22106
- const raw = JSON.parse(fs23.readFileSync(path35.join(dir, name), "utf8"));
22269
+ const raw = JSON.parse(fs23.readFileSync(path36.join(dir, name), "utf8"));
22107
22270
  if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
22108
22271
  continue;
22109
22272
  const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
@@ -22313,12 +22476,12 @@ var cdWorkitSplit = (command) => {
22313
22476
 
22314
22477
  // packages/workit-core/src/hooks/spawn-gate.ts
22315
22478
  import fs24 from "node:fs";
22316
- import path37 from "node:path";
22479
+ import path38 from "node:path";
22317
22480
 
22318
22481
  // packages/workit-core/src/hooks/model-limit.ts
22319
- import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync4, readSync, statSync as statSync5 } from "node:fs";
22482
+ import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync5, readSync, statSync as statSync5 } from "node:fs";
22320
22483
  import os11 from "node:os";
22321
- import path36 from "node:path";
22484
+ import path37 from "node:path";
22322
22485
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
22323
22486
  var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
22324
22487
  var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
@@ -22516,17 +22679,17 @@ var firstPrompt = (file) => {
22516
22679
  var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
22517
22680
  var listDir = (dir) => {
22518
22681
  try {
22519
- return readdirSync4(dir).map((name) => path36.join(dir, name));
22682
+ return readdirSync5(dir).map((name) => path37.join(dir, name));
22520
22683
  } catch {
22521
22684
  return [];
22522
22685
  }
22523
22686
  };
22524
22687
  var SCAN_MS = 30 * 60000;
22525
22688
  var scanClaudeTranscripts = (cwd, env, now = new Date) => {
22526
- const projects = path36.join(env.CLAUDE_CONFIG_DIR || path36.join(env.HOME || os11.homedir(), ".claude"), "projects");
22527
- const project = path36.join(projects, claudeProjectSlug(cwd));
22689
+ const projects = path37.join(env.CLAUDE_CONFIG_DIR || path37.join(env.HOME || os11.homedir(), ".claude"), "projects");
22690
+ const project = path37.join(projects, claudeProjectSlug(cwd));
22528
22691
  const notes = [];
22529
- const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path36.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
22692
+ const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path37.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
22530
22693
  for (const { file, worker } of files)
22531
22694
  try {
22532
22695
  const stat = statSync5(file);
@@ -22541,7 +22704,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
22541
22704
  if (!seen)
22542
22705
  continue;
22543
22706
  notes.push(worker ? redispatchNote(seen, {
22544
- label: `worker ${path36.basename(file, ".jsonl")}`,
22707
+ label: `worker ${path37.basename(file, ".jsonl")}`,
22545
22708
  prompt: firstPrompt(file)
22546
22709
  }, 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.`);
22547
22710
  } catch {}
@@ -22643,10 +22806,10 @@ var namesMade = (word) => {
22643
22806
  const stat = fs24.statSync(word);
22644
22807
  if (stat.isFile())
22645
22808
  return stat.size < 1e6 && MADE_WORKTREE.test(fs24.readFileSync(word, "utf8"));
22646
- const dotGit = path37.join(word, ".git");
22809
+ const dotGit = path38.join(word, ".git");
22647
22810
  const link = fs24.statSync(dotGit);
22648
22811
  const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs24.readFileSync(dotGit, "utf8"));
22649
- return !!admin && fs24.existsSync(path37.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
22812
+ return !!admin && fs24.existsSync(path38.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
22650
22813
  } catch {
22651
22814
  return false;
22652
22815
  }
@@ -22693,7 +22856,7 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
22693
22856
  // packages/workit-core/src/hooks/teardown.ts
22694
22857
  import { spawn } from "node:child_process";
22695
22858
  import fs25 from "node:fs";
22696
- import path38 from "node:path";
22859
+ import path39 from "node:path";
22697
22860
  var REAP_INTERVAL_MS = 10 * 60000;
22698
22861
  var LOG_MAX_BYTES = 1 << 20;
22699
22862
  var ENDS = {
@@ -22704,9 +22867,9 @@ var ENDS = {
22704
22867
  };
22705
22868
  var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
22706
22869
  var HOST_SESSION_VARS = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
22707
- var teardownDir = (env) => path38.join(stateDir3(env), "procs");
22708
- var teardownLog = (env) => path38.join(teardownDir(env), "teardown.log");
22709
- var reapStamp = (env) => path38.join(teardownDir(env), "reap-at-start.stamp");
22870
+ var teardownDir = (env) => path39.join(stateDir3(env), "procs");
22871
+ var teardownLog = (env) => path39.join(teardownDir(env), "teardown.log");
22872
+ var reapStamp = (env) => path39.join(teardownDir(env), "reap-at-start.stamp");
22710
22873
  function spawnDetached(request) {
22711
22874
  try {
22712
22875
  const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
@@ -22733,7 +22896,7 @@ var teardownDeps = {
22733
22896
  var openLog = (env, args) => {
22734
22897
  try {
22735
22898
  const file = teardownLog(env);
22736
- fs25.mkdirSync(path38.dirname(file), { recursive: true });
22899
+ fs25.mkdirSync(path39.dirname(file), { recursive: true });
22737
22900
  let size = 0;
22738
22901
  try {
22739
22902
  size = fs25.statSync(file).size;
@@ -22818,7 +22981,7 @@ function reapAtStart(_cwd, env = process.env) {
22818
22981
  try {
22819
22982
  if (fresh(stamp, now))
22820
22983
  return false;
22821
- fs25.mkdirSync(path38.dirname(stamp), { recursive: true });
22984
+ fs25.mkdirSync(path39.dirname(stamp), { recursive: true });
22822
22985
  if (!claim2(lock, now))
22823
22986
  return false;
22824
22987
  } catch {
@@ -23510,11 +23673,11 @@ Retry as: ${retry}`,
23510
23673
  // packages/workit-core/src/agent-stamp.ts
23511
23674
  import { createHash as createHash17, randomBytes as randomBytes4 } from "node:crypto";
23512
23675
  import fs26 from "node:fs";
23513
- import path39 from "node:path";
23676
+ import path40 from "node:path";
23514
23677
  var STAMP_TTL_MS = 120000;
23515
23678
  var AGENT_ID = /^[\w-]{1,64}$/u;
23516
23679
  var hash2 = (text) => createHash17("sha256").update(text).digest("hex").slice(0, 32);
23517
- var stampDir = (env, session) => path39.join(stateDir3(env), "agent-stamps", hash2(session));
23680
+ var stampDir = (env, session) => path40.join(stateDir3(env), "agent-stamps", hash2(session));
23518
23681
  var workitCalls2 = (command, dialect = "posix") => {
23519
23682
  const calls = [];
23520
23683
  try {
@@ -23539,9 +23702,9 @@ var noteAgentStamps = (env, session, agentId, command, options = {}) => {
23539
23702
  fs26.mkdirSync(dir, { recursive: true, mode: 448 });
23540
23703
  const now = Date.now();
23541
23704
  for (const name of fs26.readdirSync(dir))
23542
- if (now - fs26.statSync(path39.join(dir, name)).mtimeMs > STAMP_TTL_MS)
23543
- fs26.rmSync(path39.join(dir, name), { force: true });
23544
- calls.forEach((argv, index) => fs26.writeFileSync(path39.join(dir, `${hash2(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
23705
+ if (now - fs26.statSync(path40.join(dir, name)).mtimeMs > STAMP_TTL_MS)
23706
+ fs26.rmSync(path40.join(dir, name), { force: true });
23707
+ calls.forEach((argv, index) => fs26.writeFileSync(path40.join(dir, `${hash2(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
23545
23708
  } catch {}
23546
23709
  };
23547
23710
  var callTag = (toolUseId) => hash2(toolUseId).slice(0, 8);
@@ -23553,10 +23716,448 @@ var dropAgentStamps = (env, session, toolUseId, command) => {
23553
23716
  const tag = `.${callTag(toolUseId)}-`;
23554
23717
  for (const name of fs26.readdirSync(dir))
23555
23718
  if (name.includes(tag))
23556
- fs26.rmSync(path39.join(dir, name), { force: true });
23719
+ fs26.rmSync(path40.join(dir, name), { force: true });
23557
23720
  } catch {}
23558
23721
  };
23559
23722
 
23723
+ // packages/workit-core/src/hooks/hook-entry.ts
23724
+ import { existsSync as existsSync14, readFileSync as readFileSync11, realpathSync as realpathSync10 } from "node:fs";
23725
+ import path41 from "node:path";
23726
+ 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;
23727
+ var PACKAGE_ENTRIES = {
23728
+ "claude-code": /^(?:bin\/workit-hook\.mjs|src\/(?:run|hook)\.ts|dist\/workit-hook\.js)$/u,
23729
+ codex: /^(?:hooks\/(?:launcher|workit-hook)\.ts|dist\/workit-hook(?:-[\w-]+)?\.js)$/u,
23730
+ cursor: /^(?:hooks\/(?:launch|launch-runtime)\.mjs|hooks\/(?:workit-hook|session-start|subagent-start)\.ts|dist\/(?:workit-hook|cursor-session-start)\.js)$/u,
23731
+ core: /^src\/hooks\/run\.ts$/u
23732
+ };
23733
+ var RUNNERS = new Set([
23734
+ "node",
23735
+ "nodejs",
23736
+ "bun",
23737
+ "deno",
23738
+ "tsx",
23739
+ "ts-node",
23740
+ "sh",
23741
+ "bash",
23742
+ "zsh",
23743
+ "dash",
23744
+ "ksh",
23745
+ "fish",
23746
+ "source",
23747
+ "."
23748
+ ]);
23749
+ var PACKAGE_RUNNERS2 = new Set(["npx", "bunx", "pnpx"]);
23750
+ var NO_RUN = new Set([
23751
+ "build",
23752
+ "test",
23753
+ "fmt",
23754
+ "lint",
23755
+ "check",
23756
+ "doc",
23757
+ "info",
23758
+ "install",
23759
+ "add",
23760
+ "pm"
23761
+ ]);
23762
+ var MORE_WRAPPERS = new Set(["strace", "ltrace", "watch", "unshare", "firejail", "xargs", "&"]);
23763
+ var baseName3 = (word) => (word.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "").toLowerCase();
23764
+ var packageAt = (dir) => {
23765
+ try {
23766
+ const name = JSON.parse(readFileSync11(path41.join(dir, "package.json"), "utf8")).name;
23767
+ const short = /^@workit-dev\/(claude-code|codex|cursor|core)$/u.exec(String(name))?.[1];
23768
+ if (short)
23769
+ return short;
23770
+ } catch {}
23771
+ for (const [manifest, short] of [
23772
+ [".claude-plugin", "claude-code"],
23773
+ [".codex-plugin", "codex"],
23774
+ [".cursor-plugin", "cursor"]
23775
+ ]) {
23776
+ try {
23777
+ const name = JSON.parse(readFileSync11(path41.join(dir, manifest, "plugin.json"), "utf8")).name;
23778
+ if (name === "workit")
23779
+ return short;
23780
+ } catch {}
23781
+ }
23782
+ return null;
23783
+ };
23784
+ var entryByPath = (file) => {
23785
+ let dir = path41.dirname(file);
23786
+ for (let depth = 0;depth < 4; depth += 1, dir = path41.dirname(dir)) {
23787
+ const short = packageAt(dir);
23788
+ if (short)
23789
+ return PACKAGE_ENTRIES[short]?.test(path41.relative(dir, file).split(path41.sep).join("/")) ?? false;
23790
+ if (existsSync14(path41.join(dir, "package.json")))
23791
+ return false;
23792
+ }
23793
+ return false;
23794
+ };
23795
+ var literalSub = (match, inner) => {
23796
+ try {
23797
+ const [only, ...rest] = segmentsOf(inner);
23798
+ const [verb = "", ...args] = only?.words ?? [];
23799
+ const last = args.findLast((arg) => !arg.startsWith("-"));
23800
+ return rest.length === 0 && /^(?:echo|printf|ls|realpath|readlink)$/u.test(baseName3(verb)) && last ? last : match;
23801
+ } catch {
23802
+ return match;
23803
+ }
23804
+ };
23805
+ var expand = (word, vars) => word.replace(/\$\(([^()]*)\)|`([^`]*)`/gu, (match, sub, tick) => literalSub(match, sub ?? tick ?? "")).replace(/\$\{(\w+)\}|\$(\w+)/gu, (match, braced, bare) => {
23806
+ const name = braced ?? bare ?? "";
23807
+ return vars.get(name) ?? process.env[name] ?? match;
23808
+ }).replace(/^~(?=[\\/]|$)/u, userHome2(process.env));
23809
+ var entryNamed = (word, scan) => {
23810
+ if (!word)
23811
+ return null;
23812
+ const text = expand(word, scan.vars);
23813
+ if (ENTRY_NAMES.test(baseName3(text)))
23814
+ return text;
23815
+ const fd = /^\/(?:dev|proc\/self)\/fd\/(\d+)$/u.exec(text)?.[1];
23816
+ if (fd !== undefined && scan.fds.has(fd))
23817
+ return text;
23818
+ if (scan.dir === null && !path41.isAbsolute(text))
23819
+ return null;
23820
+ for (const file of expandGlob(path41.resolve(scan.dir ?? "/", text))) {
23821
+ if (scan.links.has(file) || entryByPath(file))
23822
+ return text;
23823
+ let real;
23824
+ try {
23825
+ real = realpathSync10(file);
23826
+ } catch {
23827
+ continue;
23828
+ }
23829
+ if (ENTRY_NAMES.test(baseName3(real)) || entryByPath(real))
23830
+ return text;
23831
+ }
23832
+ return null;
23833
+ };
23834
+ var noteLink = (words, scan) => {
23835
+ if (!/^(?:ln|cp|install)$/u.test(baseName3(words[0] ?? "")) || scan.dir === null)
23836
+ return;
23837
+ const names = words.slice(1).filter((word) => !word.startsWith("-"));
23838
+ const dest = names.at(-1);
23839
+ if (dest === undefined || names.length < 2)
23840
+ return;
23841
+ for (const source of names.slice(0, -1).filter((name) => entryNamed(name, scan))) {
23842
+ const to = path41.resolve(scan.dir, expand(dest, scan.vars));
23843
+ scan.links.add(to);
23844
+ scan.links.add(path41.join(to, path41.basename(source)));
23845
+ }
23846
+ };
23847
+ var runsEntry = (words, inputs, scan) => {
23848
+ const named = (word) => entryNamed(word, scan);
23849
+ let at = 0;
23850
+ while (at < words.length) {
23851
+ while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
23852
+ at += 1;
23853
+ const word = words[at];
23854
+ if (word === undefined)
23855
+ return null;
23856
+ const entry = named(word);
23857
+ if (entry)
23858
+ return entry;
23859
+ const name = baseName3(word);
23860
+ const split = name === "env" ? words.findIndex((w) => /^(?:-\w*S|--split-string)/u.test(w)) : -1;
23861
+ if (split > at) {
23862
+ const line = /^(?:-\w*S|--split-string=?)(.*)$/su.exec(words[split] ?? "")?.[1] || words[split + 1];
23863
+ const rest = words.slice(split + (line === words[split + 1] ? 2 : 1));
23864
+ return runsEntry([...(line ?? "").split(/\s+/u).filter(Boolean), ...rest], inputs, scan);
23865
+ }
23866
+ if (MORE_WRAPPERS.has(name)) {
23867
+ at = pastOptions(words, at + 1, "");
23868
+ continue;
23869
+ }
23870
+ const takes = WRAPPERS3[name];
23871
+ if (takes !== undefined && !PACKAGE_RUNNERS2.has(name)) {
23872
+ at = pastOptions(words, at + 1, takes, name === "env" || name === "sudo");
23873
+ continue;
23874
+ }
23875
+ if (name === "busybox" || name === "toybox") {
23876
+ at += 1;
23877
+ continue;
23878
+ }
23879
+ 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] ?? "");
23880
+ if (runner) {
23881
+ at += PACKAGE_RUNNERS2.has(name) ? 1 : 2;
23882
+ while (words[at]?.startsWith("-"))
23883
+ at += /^(?:-p|--package|-c|--call)$/u.test(words[at] ?? "") ? 2 : 1;
23884
+ if (/^@workit-dev\/(?:claude-code|codex|cursor)(?:@|$)/u.test(words[at] ?? ""))
23885
+ return words[at] ?? null;
23886
+ continue;
23887
+ }
23888
+ if (!RUNNERS.has(name))
23889
+ return null;
23890
+ if ((name === "bun" || name === "deno") && NO_RUN.has(words[at + 1] ?? ""))
23891
+ return null;
23892
+ for (const arg of [...words.slice(at + 1), ...inputs]) {
23893
+ const hit = named(arg);
23894
+ if (hit)
23895
+ return hit;
23896
+ }
23897
+ return null;
23898
+ }
23899
+ return null;
23900
+ };
23901
+ var KEYWORDS3 = new Set([
23902
+ "{",
23903
+ "}",
23904
+ "if",
23905
+ "then",
23906
+ "elif",
23907
+ "else",
23908
+ "fi",
23909
+ "while",
23910
+ "until",
23911
+ "do",
23912
+ "done",
23913
+ "esac",
23914
+ "!"
23915
+ ]);
23916
+ var pastKeywords = (words) => {
23917
+ let at = 0;
23918
+ for (;; ) {
23919
+ if (words[at] === "function")
23920
+ at += 2;
23921
+ else if (KEYWORDS3.has(words[at] ?? ""))
23922
+ at += 1;
23923
+ else
23924
+ break;
23925
+ }
23926
+ return /^(?:for|case|select)$/u.test(words[at] ?? "") ? [] : words.slice(at);
23927
+ };
23928
+ 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(" "));
23929
+ var TOKENS2 = /[\s'"`(),[\]{};|&<>=!]+/u;
23930
+ var ENTRY_SAMPLES = [
23931
+ "workit-hook.mjs",
23932
+ "workit-hook.js",
23933
+ "workit-hook.ts",
23934
+ "cursor-session-start.js"
23935
+ ];
23936
+ var tokenEntry = (token, scan) => {
23937
+ if (!/[\\/]/u.test(token) && !existsSync14(path41.resolve(scan.dir ?? "/", token)))
23938
+ return null;
23939
+ return entryNamed(token, scan);
23940
+ };
23941
+ var opaqueEntry = (words, inputs, scan) => {
23942
+ let at = 0;
23943
+ while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
23944
+ at += 1;
23945
+ const head = baseName3(words[at] ?? "");
23946
+ if (READERS2.has(head))
23947
+ return null;
23948
+ if ((head === "bun" || head === "deno") && NO_RUN.has(words[at + 1] ?? ""))
23949
+ return null;
23950
+ if (head === "git" && !words.some((word) => word.includes("alias.")))
23951
+ return null;
23952
+ if (head === "workit" || head === "workit-cli")
23953
+ return null;
23954
+ const tokens = words.flatMap((word) => word.split(TOKENS2)).filter(Boolean);
23955
+ const runner = (token) => RUNNERS.has(baseName3(token)) && !/^(?:\.|source)$/u.test(token) || PACKAGE_RUNNERS2.has(baseName3(token));
23956
+ if (!tokens.some(runner))
23957
+ return null;
23958
+ if (scan.fed)
23959
+ return scan.fed;
23960
+ for (const token of tokens) {
23961
+ const hit = tokenEntry(token, scan);
23962
+ if (hit)
23963
+ return hit;
23964
+ }
23965
+ if (head === "find")
23966
+ for (const [index, word] of words.entries()) {
23967
+ const named = /^-i?name$/u.test(words[index - 1] ?? "") && /^[^*?[]/u.test(word);
23968
+ const pattern = named ? globPattern(word) : null;
23969
+ if (pattern && ENTRY_SAMPLES.some((sample) => pattern.test(sample)))
23970
+ return word;
23971
+ }
23972
+ if (/^(?:xargs|parallel)$/u.test(head) || tokens.includes("xargs"))
23973
+ for (const input of inputs) {
23974
+ try {
23975
+ const file = path41.resolve(scan.dir ?? "/", expand(input, scan.vars));
23976
+ const text = readFileSync11(file, "utf8").slice(0, 65536);
23977
+ for (const token of text.split(/\s+/u).filter(Boolean)) {
23978
+ const hit = tokenEntry(token, scan);
23979
+ if (hit)
23980
+ return hit;
23981
+ }
23982
+ } catch {}
23983
+ }
23984
+ return null;
23985
+ };
23986
+ var expandedCommand = (words, scan) => {
23987
+ let at = 0;
23988
+ while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
23989
+ at += 1;
23990
+ if (!/[$`]/u.test(words[at] ?? ""))
23991
+ return null;
23992
+ for (const word of words.slice(at + 1)) {
23993
+ const hit = entryNamed(word, scan);
23994
+ if (hit)
23995
+ return hit;
23996
+ }
23997
+ return null;
23998
+ };
23999
+ var optionsEntry = (words, scan) => {
24000
+ for (const word of words) {
24001
+ const value = /^(?:NODE_OPTIONS|BUN_OPTIONS)=(.*)$/su.exec(word)?.[1];
24002
+ if (value === undefined)
24003
+ continue;
24004
+ for (const token of value.split(TOKENS2).filter(Boolean)) {
24005
+ const hit = tokenEntry(token, scan);
24006
+ if (hit)
24007
+ return hit;
24008
+ }
24009
+ }
24010
+ return null;
24011
+ };
24012
+ var scanCommand = (command, dialect, scan) => {
24013
+ let segments;
24014
+ try {
24015
+ segments = segmentsOf(command, dialect);
24016
+ } catch {
24017
+ return null;
24018
+ }
24019
+ for (const [index, segment] of segments.entries()) {
24020
+ if (segment.unanalyzable)
24021
+ continue;
24022
+ bindLoop(segment.words, segments.slice(index + 1), scan);
24023
+ const words = pastKeywords(segment.words);
24024
+ const fed = scan.fed;
24025
+ scan.fed = null;
24026
+ const hit = segmentEntry(segment, words, dialect, scan, fed);
24027
+ if (hit)
24028
+ return hit;
24029
+ }
24030
+ return null;
24031
+ };
24032
+ var bindLoop = (raw, after, scan) => {
24033
+ const at = raw.findIndex((word) => !KEYWORDS3.has(word));
24034
+ const verb = raw[at];
24035
+ if ((verb === "for" || verb === "select") && raw[at + 2] === "in") {
24036
+ const name = raw[at + 1] ?? "";
24037
+ const items = raw.slice(at + 3);
24038
+ const item = items.find((word) => entryNamed(word, scan)) ?? items[0];
24039
+ if (/^[A-Za-z_]\w*$/u.test(name) && item !== undefined)
24040
+ scan.vars.set(name, expand(item, scan.vars));
24041
+ return;
24042
+ }
24043
+ const read = raw.indexOf("read");
24044
+ if (read < 0 || !raw.slice(0, read).some((word) => word === "while" || word === "until"))
24045
+ return;
24046
+ const fed = after.find((segment) => segment.words[0] === "done")?.stdin?.[0];
24047
+ const line = fed?.split(`
24048
+ `)[0]?.trim();
24049
+ const name = raw.slice(read + 1).find((word) => /^[A-Za-z_]\w*$/u.test(word));
24050
+ if (name && line)
24051
+ scan.vars.set(name, line);
24052
+ };
24053
+ var segmentEntry = (segment, words, dialect, scan, fed) => {
24054
+ const verb = baseName3(words[0] ?? "");
24055
+ if (["cd", "pushd", "chdir", "set-location", "sl"].includes(verb)) {
24056
+ const target = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
24057
+ const moved = target === undefined ? userHome2(process.env) : expand(target, scan.vars);
24058
+ scan.dir = moved === "-" || /[$`]/u.test(moved) ? null : path41.isAbsolute(moved) ? moved : scan.dir && path41.resolve(scan.dir, moved);
24059
+ if (scan.dir === null)
24060
+ scan.vars.delete("PWD");
24061
+ else
24062
+ scan.vars.set("PWD", scan.dir);
24063
+ return null;
24064
+ }
24065
+ if (verb === "popd") {
24066
+ scan.dir = null;
24067
+ return null;
24068
+ }
24069
+ const declares = ["export", "declare", "typeset", "local", "readonly"].includes(verb);
24070
+ const assigns = declares ? words.slice(1) : words.every((word) => /^[A-Za-z_]\w*=/u.test(word)) ? words : [];
24071
+ for (const word of assigns) {
24072
+ const [name = "", value] = word.split(/=(.*)/su);
24073
+ if (value !== undefined && /^[A-Za-z_]\w*$/u.test(name))
24074
+ scan.vars.set(name, expand(value.replace(/^(['"])(.*)\1$/su, "$2"), scan.vars));
24075
+ }
24076
+ const options = optionsEntry(declares ? words.slice(1) : words, scan);
24077
+ if (options)
24078
+ return options;
24079
+ if (verb === "exec" && words.slice(1).every((word) => /^\d+$/u.test(word))) {
24080
+ for (const input of segment.inputs ?? [])
24081
+ if (entryNamed(input, scan))
24082
+ for (const fd of words.slice(1))
24083
+ scan.fds.add(fd);
24084
+ }
24085
+ const inputs = segment.inputs ?? [];
24086
+ const entry = runsEntry(words, inputs, scan) ?? expandedCommand(words, scan) ?? opaqueEntry(words, inputs, { ...scan, fed });
24087
+ if (entry)
24088
+ return entry;
24089
+ if (segment.pipe)
24090
+ scan.fed = words.slice(1).flatMap((word) => word.split(TOKENS2)).map((token) => token ? tokenEntry(token, scan) : null).find(Boolean) ?? null;
24091
+ noteLink(words, scan);
24092
+ if (scan.depth >= 4)
24093
+ return null;
24094
+ const nested = (script) => scanCommand(script, dialect, {
24095
+ ...scan,
24096
+ vars: new Map(scan.vars),
24097
+ fed: null,
24098
+ depth: scan.depth + 1
24099
+ });
24100
+ const scripts = [...segment.subs ?? []];
24101
+ const script = shellScript2(words) ?? cmdScript2(words) ?? workitScript(words);
24102
+ if (script)
24103
+ scripts.push(script);
24104
+ if (!script && /^(?:ba|z|da|k)?sh$/u.test(verb) && words.slice(1).every((word) => word.startsWith("-")) || verb === "at" || verb === "batch")
24105
+ scripts.push(...segment.stdin ?? []);
24106
+ for (const text of scripts) {
24107
+ const hit = nested(text);
24108
+ if (hit)
24109
+ return hit;
24110
+ }
24111
+ return null;
24112
+ };
24113
+ var cmdScript2 = (words) => {
24114
+ const name = baseName3(words[0] ?? "");
24115
+ if (!/^(?:cmd|pwsh|powershell)$/u.test(name))
24116
+ return null;
24117
+ const flag = words.findIndex((word, at) => at > 0 && /^[/-](?:c|k|command)$/iu.test(word));
24118
+ return flag < 0 ? null : words.slice(flag + 1).join(" ").replaceAll("\\", "/") || null;
24119
+ };
24120
+ var workitScript = (words) => {
24121
+ if (!/^workit(?:-cli)?$/u.test(baseName3(words[0] ?? "")))
24122
+ return null;
24123
+ const dash = words.indexOf("--");
24124
+ return dash < 0 ? null : words.slice(dash + 1).join(" ") || null;
24125
+ };
24126
+ var substitutions2 = (command) => {
24127
+ const found = [];
24128
+ for (let at = command.indexOf("$(");at >= 0 && found.length < 32; at = command.indexOf("$(", at + 1)) {
24129
+ if (command[at + 2] === "(")
24130
+ continue;
24131
+ let depth = 1;
24132
+ let end = at + 2;
24133
+ for (;end < command.length && depth > 0; end += 1)
24134
+ if (command[end] === "(")
24135
+ depth += 1;
24136
+ else if (command[end] === ")")
24137
+ depth -= 1;
24138
+ found.push(command.slice(at + 2, end - 1));
24139
+ }
24140
+ return found;
24141
+ };
24142
+ var hookEntryRun = (cwd, command, dialect = "posix") => {
24143
+ const scan = (text) => scanCommand(text, dialect, {
24144
+ dir: cwd,
24145
+ vars: new Map([["PWD", cwd]]),
24146
+ links: new Set,
24147
+ fds: new Set,
24148
+ fed: null,
24149
+ depth: 0
24150
+ });
24151
+ const texts = dialect === "posix" && /[A-Za-z]:\\/u.test(command) ? [command, command.replaceAll("\\", "/")] : [command];
24152
+ for (const text of texts) {
24153
+ const hit = scan(text) ?? substitutions2(text).map(scan).find(Boolean);
24154
+ if (hit)
24155
+ return hit;
24156
+ }
24157
+ return null;
24158
+ };
24159
+ 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).`;
24160
+
23560
24161
  // packages/workit-core/src/hooks/identity-env.ts
23561
24162
  var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
23562
24163
  var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
@@ -23740,7 +24341,7 @@ var loginScript = (words) => {
23740
24341
  }
23741
24342
  return null;
23742
24343
  };
23743
- var scanCommand = (command, dialect, depth, scan) => {
24344
+ var scanCommand2 = (command, dialect, depth, scan) => {
23744
24345
  let segments;
23745
24346
  try {
23746
24347
  segments = segmentsOf(command, dialect);
@@ -23768,7 +24369,7 @@ var scanCommand = (command, dialect, depth, scan) => {
23768
24369
  commandAt(words, scan, expanded, at);
23769
24370
  const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
23770
24371
  if (script)
23771
- scanCommand(script, dialect, depth + 1, scan);
24372
+ scanCommand2(script, dialect, depth + 1, scan);
23772
24373
  }
23773
24374
  };
23774
24375
  var identityEnvChange = (command, dialect = "posix") => {
@@ -23777,7 +24378,7 @@ var identityEnvChange = (command, dialect = "posix") => {
23777
24378
  if (dialect === "powershell")
23778
24379
  return POWERSHELL.exec(command)?.[0] ?? (/\bworkit\b/iu.test(command) ? POWERSHELL_HOST.exec(command)?.[0] ?? null : null);
23779
24380
  const scan = { hit: null, hostHit: null, risky: null, runs: false };
23780
- scanCommand(command, dialect, 0, scan);
24381
+ scanCommand2(command, dialect, 0, scan);
23781
24382
  return scan.hit ?? (scan.runs ? scan.hostHit ?? scan.risky : null);
23782
24383
  };
23783
24384
  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).`;
@@ -23973,6 +24574,9 @@ function decide(input, deps) {
23973
24574
  const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) : NONE6;
23974
24575
  if (raw.kind === "deny")
23975
24576
  return raw;
24577
+ const entry = canDeny ? hookEntryRun(input.cwd, event.command, event.dialect) : null;
24578
+ if (entry)
24579
+ return { kind: "deny", reason: hookEntryDeny(entry), unblock: null };
23976
24580
  const owner = role === "judge" ? null : liveOwner(input, descriptor.transport);
23977
24581
  const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, owner, event.dialect) : NONE6;
23978
24582
  if (gate.kind === "deny")
@@ -24120,7 +24724,7 @@ var dispatchHook = (adapter, raw, env = process.env) => {
24120
24724
  };
24121
24725
  // packages/workit-core/src/hooks/deadline.ts
24122
24726
  import { appendFileSync, mkdirSync as mkdirSync4 } from "node:fs";
24123
- import path40 from "node:path";
24727
+ import path42 from "node:path";
24124
24728
  var HOOK_SKIP_TEXT = "workit context skipped: host under load";
24125
24729
  var HOOK_DEADLINE_MS = 8000;
24126
24730
  var HOST_DEADLINES = {
@@ -24138,7 +24742,7 @@ var hookDeadlineMs = (env, host = "", native) => {
24138
24742
  const row = HOST_DEADLINES[host];
24139
24743
  return override(env) ?? (row ? native === undefined ? Math.min(...Object.values(row)) : row[native] ?? row[""] : HOOK_DEADLINE_MS);
24140
24744
  };
24141
- var skipsFile = (stateDir) => path40.join(stateDir, HOOK_SKIPS_FILE);
24745
+ var skipsFile = (stateDir) => path42.join(stateDir, HOOK_SKIPS_FILE);
24142
24746
  var recordHookSkip = (skip, stateDir = resolveStateDir()) => {
24143
24747
  try {
24144
24748
  mkdirSync4(stateDir, { recursive: true });