@workit-dev/pi 2.27.6 → 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.
Files changed (2) hide show
  1. package/dist/workit.js +805 -202
  2. package/package.json +1 -1
package/dist/workit.js CHANGED
@@ -27384,7 +27384,7 @@ var splitDenial = (plan) => ({
27384
27384
  // packages/workit-core/src/hooks/write-gate.ts
27385
27385
  import {
27386
27386
  existsSync as existsSync16,
27387
- readdirSync as readdirSync5,
27387
+ readdirSync as readdirSync6,
27388
27388
  readFileSync as readFileSync12,
27389
27389
  readlinkSync as readlinkSync3,
27390
27390
  realpathSync as realpathSync11,
@@ -27392,7 +27392,7 @@ import {
27392
27392
  } from "node:fs";
27393
27393
  import { builtinModules } from "node:module";
27394
27394
  import os10 from "node:os";
27395
- import path42 from "node:path";
27395
+ import path43 from "node:path";
27396
27396
 
27397
27397
  // packages/workit-core/src/core/live-session.ts
27398
27398
  import { spawnSync as spawnSync23 } from "node:child_process";
@@ -27595,6 +27595,41 @@ var claimLiveSession = (target, owner, deps = {}) => {
27595
27595
  } catch {}
27596
27596
  };
27597
27597
 
27598
+ // packages/workit-core/src/hooks/path-glob.ts
27599
+ import { readdirSync as readdirSync5 } from "node:fs";
27600
+ import path42 from "node:path";
27601
+ var GLOB2 = /[*?[]/u;
27602
+ var globPattern = (glob, dots = false) => {
27603
+ try {
27604
+ return new RegExp(`^${dots || glob.startsWith(".") ? "" : "(?!\\.)"}${glob.replace(/[.+^$(){}|\\]/gu, "\\$&").replace(/\[!/gu, "[^").replaceAll("*", ".*").replaceAll("?", ".")}$`, "u");
27605
+ } catch {
27606
+ return null;
27607
+ }
27608
+ };
27609
+ var expandGlob = (file, limit = 64) => {
27610
+ if (!GLOB2.test(file))
27611
+ return [file];
27612
+ const { root } = path42.parse(file);
27613
+ let found = [root];
27614
+ for (const part of file.slice(root.length).split(/[\\/]/u).filter(Boolean)) {
27615
+ if (!GLOB2.test(part)) {
27616
+ found = found.map((dir) => path42.join(dir, part));
27617
+ continue;
27618
+ }
27619
+ const pattern = globPattern(part);
27620
+ if (pattern === null)
27621
+ return [file];
27622
+ found = found.flatMap((dir) => {
27623
+ try {
27624
+ return readdirSync5(dir).filter((name) => pattern.test(name)).map((name) => path42.join(dir, name));
27625
+ } catch {
27626
+ return [];
27627
+ }
27628
+ }).slice(0, limit);
27629
+ }
27630
+ return found.length > 0 ? found : [file];
27631
+ };
27632
+
27598
27633
  // packages/workit-core/src/hooks/windows-reads.ts
27599
27634
  var READ_CMDLETS = new Set([
27600
27635
  "foreach-object",
@@ -27912,44 +27947,44 @@ var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "wi
27912
27947
  var linkTarget = (file) => {
27913
27948
  try {
27914
27949
  const to = readlinkSync3(file);
27915
- let from = path42.dirname(file);
27950
+ let from = path43.dirname(file);
27916
27951
  try {
27917
27952
  from = realpathSync11.native(from);
27918
27953
  } catch {}
27919
- return path42.resolve(from, to);
27954
+ return path43.resolve(from, to);
27920
27955
  } catch {
27921
27956
  return null;
27922
27957
  }
27923
27958
  };
27924
27959
  var realPath = (file, dangling = true) => {
27925
- let dir = path42.resolve(file);
27960
+ let dir = path43.resolve(file);
27926
27961
  let rest = "";
27927
27962
  for (let hops = 0;; ) {
27928
27963
  try {
27929
- return path42.join(realpathSync11.native(dir), rest);
27964
+ return path43.join(realpathSync11.native(dir), rest);
27930
27965
  } catch {
27931
27966
  const link = dangling ? linkTarget(dir) : null;
27932
27967
  if (link !== null) {
27933
27968
  if (++hops > 40)
27934
27969
  return null;
27935
- dir = path42.join(link, rest);
27970
+ dir = path43.join(link, rest);
27936
27971
  rest = "";
27937
- } else if (path42.dirname(dir) === dir)
27938
- return path42.resolve(file);
27972
+ } else if (path43.dirname(dir) === dir)
27973
+ return path43.resolve(file);
27939
27974
  else {
27940
- rest = rest ? path42.join(path42.basename(dir), rest) : path42.basename(dir);
27941
- dir = path42.dirname(dir);
27975
+ rest = rest ? path43.join(path43.basename(dir), rest) : path43.basename(dir);
27976
+ dir = path43.dirname(dir);
27942
27977
  }
27943
27978
  }
27944
27979
  }
27945
27980
  };
27946
- var canonical5 = (file, dangling = true) => realPath(file, dangling) ?? path42.resolve(file);
27981
+ var canonical5 = (file, dangling = true) => realPath(file, dangling) ?? path43.resolve(file);
27947
27982
  var exempt = (cwd, root, file, plans) => {
27948
27983
  const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
27949
- const relative = path42.relative(fold(canonical5(root, false)), fold(canonical5(path42.resolve(cwd, file), false)));
27950
- if (relative.startsWith("..") || path42.isAbsolute(relative))
27984
+ const relative = path43.relative(fold(canonical5(root, false)), fold(canonical5(path43.resolve(cwd, file), false)));
27985
+ if (relative.startsWith("..") || path43.isAbsolute(relative))
27951
27986
  return true;
27952
- const posix = relative.split(path42.sep).join("/");
27987
+ const posix = relative.split(path43.sep).join("/");
27953
27988
  const segments = posix.split("/");
27954
27989
  return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
27955
27990
  };
@@ -28029,7 +28064,7 @@ var editsOf = (input) => {
28029
28064
  return [into];
28030
28065
  const files = operands(args);
28031
28066
  if (name === "ln" && files.length === 1)
28032
- return [path42.basename(files[0])];
28067
+ return [path43.basename(files[0])];
28033
28068
  return files.length ? [files.at(-1)] : null;
28034
28069
  }
28035
28070
  case "mklink": {
@@ -28091,6 +28126,35 @@ var editsOf = (input) => {
28091
28126
  return [];
28092
28127
  }
28093
28128
  };
28129
+ var removalsOf = (input) => {
28130
+ const [verb = "", ...args] = pastLead(input);
28131
+ const name = (verb.split(/[\\/]/).at(-1) ?? "").toLowerCase();
28132
+ const files = operands(args);
28133
+ if (/^(?:rm|rmdir|rd|unlink|shred|remove-item|ri|del|erase)$/.test(name))
28134
+ return { files };
28135
+ if (/^(?:mv|move-item|mi|move)$/.test(name)) {
28136
+ const into = valueOf(args, /^(?:-[a-zA-Z]*t|--target-directory=?)(.*)$/s);
28137
+ return {
28138
+ files: into === undefined ? files.slice(0, -1) : files.filter((file) => file !== into)
28139
+ };
28140
+ }
28141
+ if (name === "rsync" && args.some((arg) => /^--del(?:ete|$)/.test(arg)))
28142
+ return { files: files.slice(-1) };
28143
+ 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] ?? "")));
28144
+ if (name !== "find" || !removes)
28145
+ return { files: [] };
28146
+ const end = args.findIndex((arg) => /^[-(!]/.test(arg));
28147
+ const roots = end === 0 ? ["."] : args.slice(0, end);
28148
+ const tests = [];
28149
+ for (const [at, arg] of args.entries()) {
28150
+ const kind = /^-(i?)(?:name|path|wholename|regex)$/.exec(arg);
28151
+ const value = args[at + 1];
28152
+ if (kind && value !== undefined)
28153
+ tests.push([`${arg.replace(/^-i?/, "").replace("wholename", "path")}${kind[1]}`, value]);
28154
+ }
28155
+ const negated = args.some((arg) => arg === "!" || arg === "-not");
28156
+ return { files: roots, find: { roots, tests: negated ? [] : tests } };
28157
+ };
28094
28158
  var WRAPPERS3 = {
28095
28159
  sudo: "ugCDhpRrTtU",
28096
28160
  doas: "uC",
@@ -28114,7 +28178,7 @@ var WRAPPERS3 = {
28114
28178
  var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
28115
28179
  var INLINE_CODE = /^-[a-zA-Z]*[cep]$|^--(?:eval|print)(?:=|$)/;
28116
28180
  var isConfigDir = (file) => configDirs().some((dir) => canonical5(dir) === canonical5(file));
28117
- var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals|verdicts|agent-stamps)$/.test(path42.relative(canonical5(resolveStateDir()), canonical5(file)));
28181
+ var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals|verdicts|agent-stamps)$/.test(path43.relative(canonical5(resolveStateDir()), canonical5(file)));
28118
28182
  var READ_CALLS = /^(?:print|log|info|warn|error|debug|puts|readdir(?:Sync)?|listdir|scandir|iterdir|glob|l?stat(?:Sync)?|exists(?:Sync)?|isdir|isfile|is_dir|is_file|access(?:Sync)?|realpath(?:Sync)?|dirname|basename|relative|str|repr|len)$/;
28119
28183
  var MUTATING_CALLS = /^(?:renames?(?:Sync)?|move(?:_into)?|copy(?:2|file|tree|File|_into)?(?:Sync)?|cp(?:Sync)?|rm(?:tree|dir|Sync|dirSync)?|unlink(?:Sync)?|remove(?:dirs)?|mkdirs?(?:Sync)?|makedirs|mkdtemp(?:Sync)?|(?:sym|hard)?link(?:Sync|_to)?|write\w*|append\w*|f?truncate(?:Sync)?|ch(?:mod|own)(?:Sync)?|touch|open(?:Sync)?|dump|save|extractall|unpack_archive|put_contents|mv|FileUtils)$/;
28120
28184
  var SPAWNS = /getattr|Reflect|getOwnPropertyDescriptor|FileIO|\.copy\s*\((?!\s*\))|utime|ch(?:mod|own)|\.delete\s*\(\s*\)|(?:PYTHON|NODE_)\w*\+?=|-r\b|--(?:require|import|env-file|[\w-]*loader)|\b(?:exec\w*|eval|(?:unlink|rename|remove)\w*)\b|\]\s*\(/;
@@ -28639,10 +28703,10 @@ var linkSources = (args, at) => {
28639
28703
  const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
28640
28704
  const target = dest === undefined ? null : at(dest);
28641
28705
  const symbolic = args.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg));
28642
- const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync16(target) || /[\\/]$/.test(dest ?? "") ? target : path42.dirname(target);
28706
+ const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync16(target) || /[\\/]$/.test(dest ?? "") ? target : path43.dirname(target);
28643
28707
  return sources.flatMap((source) => {
28644
- if (symbolic && base !== null && !path42.isAbsolute(homeExpanded(source)))
28645
- return [path42.resolve(base, source)];
28708
+ if (symbolic && base !== null && !path43.isAbsolute(homeExpanded(source)))
28709
+ return [path43.resolve(base, source)];
28646
28710
  const resolved = at(source);
28647
28711
  return resolved ? [resolved] : [];
28648
28712
  });
@@ -28687,7 +28751,7 @@ var linkReach = (verb, args, at, atAll) => {
28687
28751
  const dir = match ? match[1] ?? args[index + 1] : undefined;
28688
28752
  if (!dir)
28689
28753
  return [];
28690
- return [...atAll(dir), ...dest && !path42.isAbsolute(dir) ? atAll(path42.join(dest, dir)) : []];
28754
+ return [...atAll(dir), ...dest && !path43.isAbsolute(dir) ? atAll(path43.join(dest, dir)) : []];
28691
28755
  });
28692
28756
  }
28693
28757
  if (verb === "mklink")
@@ -28723,7 +28787,7 @@ var shellWrites = (command, depth = 0) => {
28723
28787
  return { writes: true, targets: unknown ? null : targets };
28724
28788
  };
28725
28789
  var cache3 = new Map;
28726
- var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path42.resolve(root, file)) ?? "-").join("\x00");
28790
+ var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path43.resolve(root, file)) ?? "-").join("\x00");
28727
28791
  var gateFor = (cwd) => {
28728
28792
  const store = new TaskReader(cwd);
28729
28793
  const listed = store.listTaskIndex();
@@ -28786,7 +28850,7 @@ var DIR_TARGET = ".workit-live-target";
28786
28850
  var PLACEHOLDERS = new WeakMap;
28787
28851
  var collecting = null;
28788
28852
  var placeholderIn = (dir, name) => {
28789
- const target = path42.join(dir, name);
28853
+ const target = path43.join(dir, name);
28790
28854
  collecting?.add(target);
28791
28855
  return target;
28792
28856
  };
@@ -28814,6 +28878,7 @@ var inlineWhy = (targets) => REASONS.get(targets);
28814
28878
  var OPAQUE_TARGET = ".workit-runs-";
28815
28879
  var UNRESOLVED_TARGET = ".workit-unresolved-target";
28816
28880
  var LINK_SOURCE = ".workit-link-source";
28881
+ var REMOVED_SOURCE = ".workit-removed-source";
28817
28882
  var OVERRIDE = "WORKIT_LIVE_SESSION=override";
28818
28883
  var inert = (args, sub) => args.some((arg) => arg === "--help" || arg === "-h" || arg === "--dry-run" || DRY_N.has(sub) && /^-[a-zA-Z]*n[a-zA-Z]*$/.test(arg) && !arg.startsWith("--"));
28819
28884
  var gitMutationDirs = (cwd, command, dialect) => {
@@ -28833,13 +28898,13 @@ var gitMutationDirs = (cwd, command, dialect) => {
28833
28898
  return [];
28834
28899
  if (sub === "stash" && ["list", "show"].includes(rest[0] ?? ""))
28835
28900
  return [];
28836
- return [path42.resolve(cwd, invocation.dir ?? ".")];
28901
+ return [path43.resolve(cwd, invocation.dir ?? ".")];
28837
28902
  });
28838
28903
  };
28839
28904
  var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
28840
28905
  var PUSHD2 = new Set(["pushd", "push-location"]);
28841
28906
  var POPD2 = new Set(["popd", "pop-location"]);
28842
- var UNKNOWN_DIR = path42.resolve(path42.parse(process.cwd()).root, ".workit-unknown-dir");
28907
+ var UNKNOWN_DIR = path43.resolve(path43.parse(process.cwd()).root, ".workit-unknown-dir");
28843
28908
  var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
28844
28909
  const lost = strict ? UNKNOWN_DIR : undefined;
28845
28910
  const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
@@ -28849,7 +28914,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
28849
28914
  return lost;
28850
28915
  if (dir === undefined)
28851
28916
  return lost;
28852
- return target === undefined ? os10.homedir() : path42.resolve(dir, target);
28917
+ return target === undefined ? os10.homedir() : path43.resolve(dir, target);
28853
28918
  };
28854
28919
  var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
28855
28920
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
@@ -28997,7 +29062,7 @@ var untrustedVars = (segments) => {
28997
29062
  }
28998
29063
  return { all, names };
28999
29064
  };
29000
- var UNKNOWN_VAR = path42.resolve(path42.parse(process.cwd()).root, ".workit-unknown-var");
29065
+ var UNKNOWN_VAR = path43.resolve(path43.parse(process.cwd()).root, ".workit-unknown-var");
29001
29066
  var REFERENCE = /\$\{(\w+)[^}]*\}|\$(\w+)|\$\([^)]*\)?|`[^`]*`?/g;
29002
29067
  var unresolvedRefs = (text) => [
29003
29068
  ...new Set([...text.matchAll(REFERENCE)].map((match) => {
@@ -29007,7 +29072,7 @@ var unresolvedRefs = (text) => [
29007
29072
  ];
29008
29073
  var unknownVarTarget = (text) => {
29009
29074
  const refs = unresolvedRefs(text);
29010
- return path42.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
29075
+ return path43.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
29011
29076
  };
29012
29077
  var applyOperator = (value, operator) => {
29013
29078
  if (operator === "")
@@ -29068,12 +29133,12 @@ var mktempPath = (value, dir) => {
29068
29133
  if (base === null && (temp || template === undefined))
29069
29134
  base = os10.tmpdir();
29070
29135
  const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
29071
- if (path42.isAbsolute(name))
29136
+ if (path43.isAbsolute(name))
29072
29137
  return name;
29073
29138
  const from = base === null ? dir : homeExpanded(base);
29074
- if (from === undefined || !path42.isAbsolute(from) && dir === undefined)
29139
+ if (from === undefined || !path43.isAbsolute(from) && dir === undefined)
29075
29140
  return null;
29076
- return path42.resolve(dir ?? from, from, name);
29141
+ return path43.resolve(dir ?? from, from, name);
29077
29142
  };
29078
29143
  var homeExpanded = (file) => {
29079
29144
  const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
@@ -29097,7 +29162,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29097
29162
  const home = homeExpanded(text);
29098
29163
  if (strict && unresolvedRefs(home).length > 0)
29099
29164
  return [unknownVarTarget(home)];
29100
- if (path42.isAbsolute(home))
29165
+ if (path43.isAbsolute(home))
29101
29166
  return [home];
29102
29167
  return base === undefined ? [] : [resolvedUnder(base, home)];
29103
29168
  });
@@ -29168,7 +29233,8 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29168
29233
  if (loop >= 0) {
29169
29234
  const [name = "", keyword, ...items] = segment.words.slice(loop + 1);
29170
29235
  const expanding = new Set(segment.expands ?? []);
29171
- const list = items.flatMap((item, index) => expanding.has(loop + 3 + index) ? listWords(item) : [listWord(homeExpanded(item))]);
29236
+ const globbedItem = (item) => strict === "registry" && dir !== undefined && /[*?[]/.test(item) ? expandGlob(path43.resolve(dir, homeExpanded(item))) : null;
29237
+ const list = items.flatMap((item, index) => globbedItem(item) ?? (expanding.has(loop + 3 + index) ? listWords(item) : [listWord(homeExpanded(item))]));
29172
29238
  vars.delete(name);
29173
29239
  if (keyword === "in" && list.length <= MAX_EXPANSIONS2 && !list.includes(null) && !untrusted.all && !untrusted.names.has(name))
29174
29240
  loops.set(name, list);
@@ -29307,7 +29373,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29307
29373
  index
29308
29374
  }));
29309
29375
  const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
29310
- const under = (word) => homes ? [path42.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
29376
+ const under = (word) => homes ? [path43.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
29311
29377
  const found = [
29312
29378
  ...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
29313
29379
  ...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
@@ -29315,7 +29381,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29315
29381
  for (const { file, index } of found) {
29316
29382
  const use = isRoot(file) ? rootUse(text, index) : "takes";
29317
29383
  if (use !== "reads")
29318
- targets.push(use === "builds" ? path42.join(file, UNRESOLVED_TARGET) : file);
29384
+ targets.push(use === "builds" ? path43.join(file, UNRESOLVED_TARGET) : file);
29319
29385
  }
29320
29386
  }
29321
29387
  if (/^(?:n?vim?|ex|ed|emacs)$/.test(verb) && (segment.stdin || inputs.length > 0 || feeder || args.some((arg, index) => /^(?:-[a-zA-Z]*[se]|--(?:batch|eval|script))$/.test(arg) || /^(?:-c|--cmd)$/.test(arg) && !inertEdit(args[index + 1] ?? "") || arg.startsWith("+") && !inertEdit(arg.slice(1) || "1"))))
@@ -29325,7 +29391,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29325
29391
  `);
29326
29392
  for (const [linker = "", ...rest] of fedRuns(words, feed))
29327
29393
  for (const source of linkReach(commandName2(linker), rest, at, atAll))
29328
- targets.push(path42.join(source, LINK_SOURCE));
29394
+ targets.push(path43.join(source, LINK_SOURCE));
29329
29395
  }
29330
29396
  if (strict && dir !== undefined) {
29331
29397
  const runIn = dir;
@@ -29352,7 +29418,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29352
29418
  for (const file of opaque ?? [])
29353
29419
  for (const resolved of atAll(file))
29354
29420
  if (!quiet || !isRoot(resolved))
29355
- targets.push(file === "." ? placeholderIn(resolved, here) : path42.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path42.dirname(resolved), path42.basename(resolved)) : resolved);
29421
+ targets.push(file === "." ? placeholderIn(resolved, here) : path43.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path43.dirname(resolved), path43.basename(resolved)) : resolved);
29356
29422
  const [shell = "", ...shellArgs] = pastLead(words);
29357
29423
  const verb = (shell.split(/[\\/]/).at(-1) ?? "").toLowerCase();
29358
29424
  const named = (SCRIPT_SHELLS.has(verb) || verb === "source" || verb === ".") && shellScript3([verb, ...shellArgs]) === null ? scriptArgs(verb, shellArgs).named ?? "" : null;
@@ -29373,6 +29439,12 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29373
29439
  if (dir !== undefined)
29374
29440
  targets.push(placeholderIn(dir, DIR_TARGET));
29375
29441
  }
29442
+ if (strict === "registry") {
29443
+ const { files: gone, find } = removalsOf(body);
29444
+ for (const root of gone)
29445
+ for (const file of atAll(root))
29446
+ targets.push(path43.join(file, find ? `${REMOVED_SOURCE}~${encodeURIComponent(JSON.stringify({ root, tests: find.tests }))}` : REMOVED_SOURCE));
29447
+ }
29376
29448
  for (const file of [...segment.redirects, ...edits ?? []])
29377
29449
  if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file) && !(dialect === "powershell" && /^(?:\$null|nul)$/i.test(file)))
29378
29450
  targets.push(...atAll(file));
@@ -29399,7 +29471,10 @@ var workitCwd = (dir, args, resolve) => {
29399
29471
  };
29400
29472
  var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
29401
29473
  try {
29402
- const env = new Map(strict === "registry" ? [...command.matchAll(/\$\{?([A-Za-z_]\w*)/g)].filter((match) => !/^(?:OLD)?PWD$/.test(match[1])).map((match) => [match[1], process.env[match[1]] ?? ""]) : []);
29474
+ const env = new Map(strict === "registry" ? [
29475
+ ...[...command.matchAll(/\$\{?([A-Za-z_]\w*)/g)].filter((match) => !/^(?:OLD)?PWD$/.test(match[1])).map((match) => [match[1], process.env[match[1]] ?? ""]),
29476
+ ["PWD", cwd]
29477
+ ] : []);
29403
29478
  return recording(() => [
29404
29479
  ...segmentTargets(cwd, command, dialect, 0, strict, env),
29405
29480
  ...gitMutationDirs(cwd, command, dialect).map((dir) => placeholderIn(dir, DIR_TARGET))
@@ -29441,7 +29516,7 @@ var liveDeny = ({ marker, checkout, ageMs, file }) => {
29441
29516
  var guarded = (targets) => {
29442
29517
  const seen = new Set;
29443
29518
  return targets.filter((target) => {
29444
- const dir = path42.dirname(target);
29519
+ const dir = path43.dirname(target);
29445
29520
  if (seen.has(dir))
29446
29521
  return false;
29447
29522
  seen.add(dir);
@@ -29462,17 +29537,17 @@ var claimAll = (owner, targets, deps) => {
29462
29537
  for (const target of guarded(targets))
29463
29538
  claimLiveSession(target, owner, deps);
29464
29539
  };
29465
- var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path42.resolve(dir, file) : path42.isAbsolute(file) ? file : `${dir}${path42.sep}${file}`;
29540
+ var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path43.resolve(dir, file) : path43.isAbsolute(file) ? file : `${dir}${path43.sep}${file}`;
29466
29541
  var liveTargets = (cwd, paths) => recording(() => paths?.length ? paths.map((file) => resolvedUnder(cwd, file)) : [placeholderIn(cwd, DIR_TARGET)]);
29467
29542
  var CONFIG_FILES = ["workspaces.json", SEAL_FILE];
29468
29543
  var configDirs = () => [resolveConfigDir(), grantsDir()];
29469
29544
  var globbed = (cwd, target, state, configs) => {
29470
29545
  if (!/[*?[]/.test(target))
29471
29546
  return [];
29472
- const raw = path42.resolve(cwd, target).split(path42.sep);
29547
+ const raw = path43.resolve(cwd, target).split(path43.sep);
29473
29548
  const literal = raw.findIndex((part) => /[*?[]/.test(part));
29474
29549
  const pattern = [
29475
- ...canonical5(raw.slice(0, literal).join(path42.sep) || path42.sep).replace(/[\\/]+$/, "").split(path42.sep),
29550
+ ...canonical5(raw.slice(0, literal).join(path43.sep) || path43.sep).replace(/[\\/]+$/, "").split(path43.sep),
29476
29551
  ...raw.slice(literal)
29477
29552
  ];
29478
29553
  const segment = (glob, name) => {
@@ -29483,16 +29558,16 @@ var globbed = (cwd, target, state, configs) => {
29483
29558
  }
29484
29559
  };
29485
29560
  const hit = (file, below) => {
29486
- const parts = canonical5(file).split(path42.sep);
29561
+ const parts = canonical5(file).split(path43.sep);
29487
29562
  return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
29488
29563
  };
29489
29564
  let roots = [];
29490
29565
  try {
29491
- roots = readdirSync5(state).filter((name) => /^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name));
29566
+ roots = readdirSync6(state).filter((name) => /^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name));
29492
29567
  } catch {}
29493
29568
  return [
29494
- ...roots.map((name) => path42.join(state, name)).filter((root) => hit(root, true)),
29495
- ...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path42.join(dir, name))]).filter((file) => hit(file, false))
29569
+ ...roots.map((name) => path43.join(state, name)).filter((root) => hit(root, true)),
29570
+ ...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path43.join(dir, name))]).filter((file) => hit(file, false))
29496
29571
  ];
29497
29572
  };
29498
29573
  var guardedInodes = (state, configs) => {
@@ -29505,18 +29580,18 @@ var guardedInodes = (state, configs) => {
29505
29580
  if (stat?.isFile())
29506
29581
  seen.set(`${stat.dev}:${stat.ino}`, registry);
29507
29582
  else if (stat?.isDirectory())
29508
- for (const name of readdirSync5(file))
29509
- add(path42.join(file, name), registry);
29583
+ for (const name of readdirSync6(file))
29584
+ add(path43.join(file, name), registry);
29510
29585
  };
29511
29586
  try {
29512
29587
  for (const dir of configs)
29513
29588
  for (const name of CONFIG_FILES)
29514
- add(path42.join(dir, name), "grants");
29515
- for (const name of readdirSync5(state))
29589
+ add(path43.join(dir, name), "grants");
29590
+ for (const name of readdirSync6(state))
29516
29591
  if (/^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name))
29517
- add(path42.join(state, name), name === "approvals" ? "approvals" : name === "verdicts" || name === "agent-stamps" ? "ledger" : "issued");
29518
- for (const slug of readdirSync5(path42.join(state, "folders")))
29519
- add(path42.join(state, "folders", slug, "ledger"), "ledger");
29592
+ add(path43.join(state, name), name === "approvals" ? "approvals" : name === "verdicts" || name === "agent-stamps" ? "ledger" : "issued");
29593
+ for (const slug of readdirSync6(path43.join(state, "folders")))
29594
+ add(path43.join(state, "folders", slug, "ledger"), "ledger");
29520
29595
  } catch {}
29521
29596
  return seen;
29522
29597
  };
@@ -29533,19 +29608,87 @@ var hardLinked = (file, state, configs, inodes) => {
29533
29608
  };
29534
29609
  var inRepoLedger = (file) => [...file.matchAll(/[\\/]workit[\\/]ledger(?=[\\/]|$)/g)].some(({ index }) => {
29535
29610
  const gitDir = file.slice(0, index);
29536
- return /(?:^|[\\/])\.git$/.test(gitDir) || existsSync16(path42.join(gitDir, "HEAD")) && existsSync16(path42.join(gitDir, "objects"));
29611
+ return /(?:^|[\\/])\.git$/.test(gitDir) || existsSync16(path43.join(gitDir, "HEAD")) && existsSync16(path43.join(gitDir, "objects"));
29537
29612
  });
29538
29613
  var holdsGuarded = (cwd, source, state, configs) => {
29539
29614
  const real = canonical5(source);
29540
29615
  const below = (parent, child) => {
29541
- const rel = path42.relative(parent, child);
29542
- return rel === "" || !rel.startsWith("..") && !path42.isAbsolute(rel);
29616
+ const rel = path43.relative(parent, child);
29617
+ return rel === "" || !rel.startsWith("..") && !path43.isAbsolute(rel);
29543
29618
  };
29544
29619
  const holds = (file) => below(real, canonical5(file));
29545
- const inState = path42.relative(canonical5(state), real).split(path42.sep);
29546
- const ledgers = ["ledger", "workit/ledger", ".git/workit/ledger"].map((rel) => path42.join(real, rel)).filter((dir) => existsSync16(dir) && inRepoLedger(dir));
29620
+ const inState = path43.relative(canonical5(state), real).split(path43.sep);
29621
+ const ledgers = ["ledger", "workit/ledger", ".git/workit/ledger"].map((rel) => path43.join(real, rel)).filter((dir) => existsSync16(dir) && inRepoLedger(dir));
29622
+ const own = ledgerPath(cwd);
29623
+ return holds(state) || below(canonical5(state), real) && inState[0] === "folders" && inState.length <= 2 || configs.some(holds) || ledgers.length > 0 || own.ok && existsSync16(own.value) && holds(path43.dirname(own.value));
29624
+ };
29625
+ var removesLedger = (cwd, source, state, configs) => {
29626
+ const real = canonical5(source);
29627
+ if (/(?:^|[\\/])\.git(?:[\\/]workit)?$/i.test(real) || inRepoLedger(real))
29628
+ return true;
29547
29629
  const own = ledgerPath(cwd);
29548
- return holds(state) || below(canonical5(state), real) && inState[0] === "folders" && inState.length <= 2 || configs.some(holds) || ledgers.length > 0 || own.ok && existsSync16(own.value) && holds(path42.dirname(own.value));
29630
+ if (own.ok) {
29631
+ const rel = path43.relative(real, canonical5(path43.dirname(own.value)));
29632
+ if (rel === "" || !rel.startsWith("..") && !path43.isAbsolute(rel))
29633
+ return true;
29634
+ }
29635
+ return holdsGuarded(cwd, source, state, configs);
29636
+ };
29637
+ var findTests = (marker) => {
29638
+ try {
29639
+ return JSON.parse(decodeURIComponent(marker.slice(REMOVED_SOURCE.length + 1)));
29640
+ } catch {
29641
+ return null;
29642
+ }
29643
+ };
29644
+ var findReachesLedger = (cwd, root, find) => {
29645
+ if (find === null)
29646
+ return true;
29647
+ const real = canonical5(root);
29648
+ const own = ledgerPath(cwd);
29649
+ const ledgers = [
29650
+ ...own.ok ? [canonical5(path43.dirname(own.value))] : [],
29651
+ ...[".git/workit/ledger", "workit/ledger", "ledger"].map((rel) => path43.join(real, rel)).filter((dir) => existsSync16(dir) && inRepoLedger(dir))
29652
+ ];
29653
+ const under = (parent, child) => {
29654
+ const rel = path43.relative(parent, child);
29655
+ return rel === "" || !rel.startsWith("..") && !path43.isAbsolute(rel);
29656
+ };
29657
+ const patterns = find.tests.map(([kind, pattern]) => {
29658
+ const fold = kind.endsWith("i");
29659
+ const glob = globPattern(pattern, true);
29660
+ let test = /(?:)/;
29661
+ try {
29662
+ test = kind.startsWith("regex") ? new RegExp(`^${pattern}$`, fold ? "i" : "") : glob ? new RegExp(glob.source, fold ? "iu" : "u") : test;
29663
+ } catch {}
29664
+ return { kind, test };
29665
+ });
29666
+ const matches = (entry) => patterns.length === 0 || patterns.some(({ kind, test }) => test.test(kind.startsWith("name") ? path43.basename(entry) : path43.join(find.root, path43.relative(real, entry)).replaceAll("\\", "/")));
29667
+ for (const ledger of ledgers) {
29668
+ if (!existsSync16(ledger) || !under(real, ledger) && !under(ledger, real))
29669
+ continue;
29670
+ const entries = [];
29671
+ for (let dir = ledger;under(real, dir) && dir !== real; dir = path43.dirname(dir))
29672
+ entries.push(dir);
29673
+ const walk = (dir) => {
29674
+ for (const item of readdirSync6(dir, { withFileTypes: true })) {
29675
+ if (entries.length > 500)
29676
+ return;
29677
+ const file = path43.join(dir, item.name);
29678
+ entries.push(file);
29679
+ if (item.isDirectory())
29680
+ walk(file);
29681
+ }
29682
+ };
29683
+ try {
29684
+ walk(ledger);
29685
+ } catch {
29686
+ return true;
29687
+ }
29688
+ if (entries.some((entry) => under(real, entry) && matches(entry)))
29689
+ return true;
29690
+ }
29691
+ return false;
29549
29692
  };
29550
29693
  var registryTarget = (cwd, targets) => {
29551
29694
  const state = resolveStateDir();
@@ -29553,20 +29696,28 @@ var registryTarget = (cwd, targets) => {
29553
29696
  const inodes = {};
29554
29697
  for (const target of targets) {
29555
29698
  const file = homeExpanded(target);
29556
- if (path42.basename(file) === LINK_SOURCE) {
29557
- const source = path42.dirname(path42.resolve(cwd, file));
29699
+ if (path43.basename(file).startsWith(REMOVED_SOURCE)) {
29700
+ const marker = path43.basename(file);
29701
+ const source = path43.dirname(path43.resolve(cwd, file));
29702
+ const find = marker === REMOVED_SOURCE ? null : findTests(marker);
29703
+ if (expandGlob(source).some((gone) => find ? findReachesLedger(cwd, gone, find) : removesLedger(cwd, gone, state, configs)))
29704
+ return { file: path43.join(source, REMOVED_SOURCE), registry: "removes" };
29705
+ continue;
29706
+ }
29707
+ if (path43.basename(file) === LINK_SOURCE) {
29708
+ const source = path43.dirname(path43.resolve(cwd, file));
29558
29709
  const reached = registryTarget(cwd, [source])?.registry ?? (holdsGuarded(cwd, source, state, configs) ? "holds" : null);
29559
29710
  if (reached)
29560
29711
  return { file: target, registry: reached };
29561
29712
  continue;
29562
29713
  }
29563
- if (realPath(path42.resolve(cwd, file)) === null)
29714
+ if (realPath(path43.resolve(cwd, file)) === null)
29564
29715
  return { file: target, registry: "link" };
29565
29716
  const glob = globbed(cwd, file, state, configs)[0];
29566
29717
  const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
29567
29718
  if (viaGlob)
29568
29719
  return { file: target, registry: viaGlob.registry };
29569
- const registry = hardLinked(path42.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical5) ?? (inRepoLedger(canonical5(path42.resolve(cwd, file))) ? "ledger" : null) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical5)) ? "grants" : null);
29720
+ const registry = hardLinked(path43.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical5) ?? (inRepoLedger(canonical5(path43.resolve(cwd, file))) ? "ledger" : null) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical5)) ? "grants" : null);
29570
29721
  if (registry)
29571
29722
  return { file: target, registry };
29572
29723
  }
@@ -29574,7 +29725,7 @@ var registryTarget = (cwd, targets) => {
29574
29725
  };
29575
29726
  var partsUnder = (dir, cwd, target, platform, real) => {
29576
29727
  const win = platform === "win32";
29577
- const p = win ? path42.win32 : path42.posix;
29728
+ const p = win ? path43.win32 : path43.posix;
29578
29729
  const fold = (value) => win || platform === "darwin" ? value.toLowerCase() : value;
29579
29730
  const named = win ? target.replace(/^\/([a-zA-Z])(?=\/|$)/, "$1:") : target;
29580
29731
  const relative = p.relative(fold(real(p.resolve(dir))), fold(real(p.resolve(cwd, named))));
@@ -29627,6 +29778,11 @@ var REGISTRY_DENY = {
29627
29778
  what: "a symlink chain Workit could not resolve (over 40 links), which may reach a guarded path",
29628
29779
  unblock: "Write to the file's real path."
29629
29780
  },
29781
+ removes: {
29782
+ label: "ledger guard",
29783
+ what: "a Workit ledger, the git dir that holds one or Workit's state",
29784
+ 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."
29785
+ },
29630
29786
  holds: {
29631
29787
  label: "registry guard",
29632
29788
  what: "Workit's state, its config or a repository ledger",
@@ -29655,19 +29811,25 @@ var REGISTRY_DENY = {
29655
29811
  };
29656
29812
  var registryDeny = ({ file, registry }) => {
29657
29813
  const { label, what, unblock } = REGISTRY_DENY[registry];
29658
- if (path42.basename(file) === LINK_SOURCE)
29814
+ if (path43.basename(file) === LINK_SOURCE)
29659
29815
  return {
29660
29816
  kind: "deny",
29661
- reason: `workit ${label}: this command links or mounts ${path42.dirname(file)}, which is or holds ${what}. ${LINK_UNBLOCK}`,
29817
+ reason: `workit ${label}: this command links or mounts ${path43.dirname(file)}, which is or holds ${what}. ${LINK_UNBLOCK}`,
29662
29818
  unblock: LINK_UNBLOCK
29663
29819
  };
29664
- if (path42.basename(file) === UNRESOLVED_TARGET)
29820
+ if (path43.basename(file) === REMOVED_SOURCE)
29821
+ return {
29822
+ kind: "deny",
29823
+ reason: `workit ${label}: this command removes or moves ${path43.dirname(file)}, which is or holds ${what}. ${unblock}`,
29824
+ unblock
29825
+ };
29826
+ if (path43.basename(file) === UNRESOLVED_TARGET)
29665
29827
  return {
29666
29828
  kind: "deny",
29667
29829
  reason: `workit ${label}: Workit could not resolve the file this command's script writes, which it builds from a path under ${what}. ${unblock}`,
29668
29830
  unblock
29669
29831
  };
29670
- const named = path42.basename(file).startsWith(".workit-") ? path42.dirname(file) : file;
29832
+ const named = path43.basename(file).startsWith(".workit-") ? path43.dirname(file) : file;
29671
29833
  return {
29672
29834
  kind: "deny",
29673
29835
  reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
@@ -29758,10 +29920,10 @@ import { spawnSync as spawnSync24 } from "node:child_process";
29758
29920
 
29759
29921
  // packages/workit-core/src/ci-waiter.ts
29760
29922
  import fs29 from "node:fs";
29761
- import path43 from "node:path";
29923
+ import path44 from "node:path";
29762
29924
  var waiterFile = (cwd, pr) => {
29763
29925
  const common = gitCommonDir(cwd);
29764
- return common ? path43.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
29926
+ return common ? path44.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
29765
29927
  };
29766
29928
  var pidAlive2 = (pid) => {
29767
29929
  if (!Number.isSafeInteger(pid) || pid <= 0)
@@ -29833,11 +29995,11 @@ function currentJudgment(cwd) {
29833
29995
  }
29834
29996
 
29835
29997
  // packages/workit-core/src/core/verdict-set.ts
29836
- import path44 from "node:path";
29998
+ import path45 from "node:path";
29837
29999
  var SET_TTL_MS = 7 * 86400000;
29838
30000
  var SET_ROW = "verdict.set";
29839
30001
  var SET_VOID = "verdict.set.voided";
29840
- var setStorePath = () => path44.join(resolveStateDir(), "verdicts", "sets", "ledger.jsonl");
30002
+ var setStorePath = () => path45.join(resolveStateDir(), "verdicts", "sets", "ledger.jsonl");
29841
30003
  var distrusted = (cwd, id, rows, type) => rows.some((row) => row.type === type && row.id === id && trustReasons(cwd, row).length > 0);
29842
30004
  function gateStands(cwd, gate, rows, now = Date.now()) {
29843
30005
  const id = typeof gate.verdictId === "string" ? gate.verdictId : null;
@@ -30324,12 +30486,12 @@ var writePaths = (input) => {
30324
30486
  };
30325
30487
  // packages/workit-core/src/hooks/standing.ts
30326
30488
  import fs31 from "node:fs";
30327
- import path50 from "node:path";
30489
+ import path51 from "node:path";
30328
30490
 
30329
30491
  // packages/workit-core/src/approvals/store.ts
30330
30492
  import { createHash as createHash20, randomBytes as randomBytes4 } from "node:crypto";
30331
- import { mkdirSync as mkdirSync7, readdirSync as readdirSync6, readFileSync as readFileSync13, rmSync as rmSync3 } from "node:fs";
30332
- import path45 from "node:path";
30493
+ import { mkdirSync as mkdirSync7, readdirSync as readdirSync7, readFileSync as readFileSync13, rmSync as rmSync3 } from "node:fs";
30494
+ import path46 from "node:path";
30333
30495
  var REQUEST_TTL_MS = 30 * 60000;
30334
30496
  var GRANT_TTL_MS = 15 * 60000;
30335
30497
  var ID_PATTERN = /^ap_[a-z2-7]{8}$/u;
@@ -30341,10 +30503,10 @@ var approvalHash = (fields) => createHash20("sha256").update(canonicalJson({
30341
30503
  effect: fields.effect,
30342
30504
  subject: fields.subject
30343
30505
  })).digest("hex");
30344
- var approvalsDir = () => path45.join(resolveStateDir(), "approvals");
30345
- var dirOf = (part) => path45.join(approvalsDir(), part);
30346
- var fileOf = (part, id) => path45.join(dirOf(part), `${id}.json`);
30347
- var askedFile = (session, toolUseId) => path45.join(dirOf("asked"), `${createHash20("sha256").update(`${session}\x00${toolUseId}`).digest("hex").slice(0, 32)}.json`);
30506
+ var approvalsDir = () => path46.join(resolveStateDir(), "approvals");
30507
+ var dirOf = (part) => path46.join(approvalsDir(), part);
30508
+ var fileOf = (part, id) => path46.join(dirOf(part), `${id}.json`);
30509
+ var askedFile = (session, toolUseId) => path46.join(dirOf("asked"), `${createHash20("sha256").update(`${session}\x00${toolUseId}`).digest("hex").slice(0, 32)}.json`);
30348
30510
  var readJson3 = (file) => {
30349
30511
  try {
30350
30512
  const value = JSON.parse(readFileSync13(file, "utf8"));
@@ -30354,14 +30516,14 @@ var readJson3 = (file) => {
30354
30516
  }
30355
30517
  };
30356
30518
  var write = (file, value) => {
30357
- mkdirSync7(path45.dirname(file), { recursive: true });
30519
+ mkdirSync7(path46.dirname(file), { recursive: true });
30358
30520
  writeFileAtomic(file, `${JSON.stringify(value, null, 2)}
30359
30521
  `);
30360
30522
  };
30361
30523
  var live = (expires, now) => Date.parse(expires) > now.getTime();
30362
30524
  var names2 = (part) => {
30363
30525
  try {
30364
- return readdirSync6(dirOf(part)).filter((name) => name.endsWith(".json"));
30526
+ return readdirSync7(dirOf(part)).filter((name) => name.endsWith(".json"));
30365
30527
  } catch {
30366
30528
  return [];
30367
30529
  }
@@ -30479,7 +30641,7 @@ var namesTicket = (text) => /WORKIT_APPROVAL_(?:TICKET|UNASKED)/u.test(text.repl
30479
30641
  var TICKET_DENY = "Only the host's prompt adds an approval ticket.";
30480
30642
  var dropInline = (drop) => {
30481
30643
  for (const name of names2("inline")) {
30482
- const file = path45.join(dirOf("inline"), name);
30644
+ const file = path46.join(dirOf("inline"), name);
30483
30645
  const row = readJson3(file);
30484
30646
  if (!row || drop(row))
30485
30647
  rmSync3(file, { force: true });
@@ -30541,12 +30703,12 @@ var approveCallIn = (command, dialect = "posix") => {
30541
30703
  var approveCallDeny = (fix) => `Run \`${fix}\` as its own call: no chain, pipe, substitution, leading cd, env prefix or redirect around it, so the host can show the request and record the user's answer.`;
30542
30704
 
30543
30705
  // packages/workit-core/src/approvals/inline.ts
30544
- import path48 from "node:path";
30706
+ import path49 from "node:path";
30545
30707
 
30546
30708
  // packages/workit-core/src/approvals/release-notes-ask.ts
30547
30709
  import { createHash as createHash21 } from "node:crypto";
30548
30710
  import { existsSync as existsSync17, readFileSync as readFileSync14 } from "node:fs";
30549
- import path46 from "node:path";
30711
+ import path47 from "node:path";
30550
30712
  var sha2563 = (data) => createHash21("sha256").update(data).digest("hex");
30551
30713
  var isReleaseNotesApprove = (words) => words[0] === "notes" && words[1] === "approve";
30552
30714
  var versionOf = (args) => {
@@ -30586,10 +30748,10 @@ var releaseNotesAskAt = (args, cwd) => {
30586
30748
  const common = version ? gitCommonDir(cwd) : null;
30587
30749
  if (!version || !common)
30588
30750
  return null;
30589
- const dir = path46.join(common, "workit", "release-notes");
30751
+ const dir = path47.join(common, "workit", "release-notes");
30590
30752
  for (const file of [
30591
- path46.join(dir, "packages", `${version.replaceAll("/", "%2F")}.md`),
30592
- path46.join(dir, `${version}.md`)
30753
+ path47.join(dir, "packages", `${version.replaceAll("/", "%2F")}.md`),
30754
+ path47.join(dir, `${version}.md`)
30593
30755
  ])
30594
30756
  if (existsSync17(file))
30595
30757
  try {
@@ -30603,7 +30765,7 @@ var releaseNotesAskAt = (args, cwd) => {
30603
30765
  // packages/workit-core/src/approvals/youtrack-ask.ts
30604
30766
  import { createHash as createHash22 } from "node:crypto";
30605
30767
  import { readFileSync as readFileSync15, realpathSync as realpathSync12 } from "node:fs";
30606
- import path47 from "node:path";
30768
+ import path48 from "node:path";
30607
30769
  var TIME = "markdown file minutes text date";
30608
30770
  var FLAGS = {
30609
30771
  note: TIME,
@@ -30647,7 +30809,7 @@ var youTrackAsk = (args, cwd, load = readFileSync15) => {
30647
30809
  const files = [];
30648
30810
  const read = (file) => {
30649
30811
  try {
30650
- const named = path47.resolve(cwd, file);
30812
+ const named = path48.resolve(cwd, file);
30651
30813
  const content = load(named);
30652
30814
  files.push([realpathSync12(named), sha2564(content)]);
30653
30815
  return content;
@@ -30685,7 +30847,7 @@ var youTrackAsk = (args, cwd, load = readFileSync15) => {
30685
30847
  const content = read(file);
30686
30848
  if (!content)
30687
30849
  return null;
30688
- lines.push(`attach: ${path47.basename(file)} (${content.length} bytes)`);
30850
+ lines.push(`attach: ${path48.basename(file)} (${content.length} bytes)`);
30689
30851
  }
30690
30852
  if (!lines.length)
30691
30853
  return null;
@@ -30722,7 +30884,7 @@ var cwdOf = (globals) => {
30722
30884
  }
30723
30885
  return cwd;
30724
30886
  };
30725
- var inlineCallCwd = (call, base) => call.cwd ? path48.resolve(base, call.cwd) : base;
30887
+ var inlineCallCwd = (call, base) => call.cwd ? path49.resolve(base, call.cwd) : base;
30726
30888
  var isReadFilter = (segment) => (segment.words[0] === "tail" || segment.words[0] === "head") && segment.words.slice(1).every((word) => /^(?:-[nc]|-[nc]?\d+|\+?\d+)$/u.test(word)) && !segment.redirects.length && !segment.subs?.length && !segment.stdin?.length && !segment.inputs?.length && !segment.expands?.length && !segment.group && !segment.unanalyzable;
30727
30889
  var onlyFiltersAfter = (segments) => segments[0]?.pipe === true && segments.slice(1).every((segment, index, rest) => isReadFilter(segment) && (index === rest.length - 1 ? !segment.pipe : segment.pipe));
30728
30890
  var inlineCallIn = (command, dialect = "posix") => {
@@ -31245,35 +31407,35 @@ function neededChecks(lane, configured) {
31245
31407
  import { createHash as createHash23 } from "node:crypto";
31246
31408
  import fs30 from "node:fs";
31247
31409
  import os11 from "node:os";
31248
- import path49 from "node:path";
31410
+ import path50 from "node:path";
31249
31411
  var FANOUT_TOKEN_FILE = "workit-fanout-token";
31250
31412
  var NONE5 = { kind: "none" };
31251
31413
  var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
31252
31414
  var realOf = (file) => {
31253
31415
  let rest = "";
31254
- for (let dir = file;; dir = path49.dirname(dir)) {
31416
+ for (let dir = file;; dir = path50.dirname(dir)) {
31255
31417
  try {
31256
- return path49.join(fs30.realpathSync.native(dir), rest);
31418
+ return path50.join(fs30.realpathSync.native(dir), rest);
31257
31419
  } catch {
31258
- if (path49.dirname(dir) === dir)
31420
+ if (path50.dirname(dir) === dir)
31259
31421
  return file;
31260
- rest = rest ? path49.join(path49.basename(dir), rest) : path49.basename(dir);
31422
+ rest = rest ? path50.join(path50.basename(dir), rest) : path50.basename(dir);
31261
31423
  }
31262
31424
  }
31263
31425
  };
31264
31426
  var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
31265
- const start = path49.isAbsolute(file) ? file : `${process.cwd()}${path49.sep}${file}`;
31266
- const { root } = path49.parse(start);
31427
+ const start = path50.isAbsolute(file) ? file : `${process.cwd()}${path50.sep}${file}`;
31428
+ const { root } = path50.parse(start);
31267
31429
  let at = root;
31268
31430
  let missing = false;
31269
31431
  for (const part of start.slice(root.length).split(/[\\/]+/)) {
31270
31432
  if (part === "" || part === ".")
31271
31433
  continue;
31272
31434
  if (part === "..") {
31273
- at = path49.dirname(at);
31435
+ at = path50.dirname(at);
31274
31436
  continue;
31275
31437
  }
31276
- const next = path49.join(at, part);
31438
+ const next = path50.join(at, part);
31277
31439
  let link = null;
31278
31440
  if (!missing)
31279
31441
  try {
@@ -31285,25 +31447,25 @@ var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
31285
31447
  at = next;
31286
31448
  hops.chain = 40;
31287
31449
  } else if (hops.chain-- > 0 && hops.total-- > 0)
31288
- at = canonical6(path49.isAbsolute(link) ? link : `${at}${path49.sep}${link}`, hops);
31450
+ at = canonical6(path50.isAbsolute(link) ? link : `${at}${path50.sep}${link}`, hops);
31289
31451
  else
31290
- return path49.resolve(file);
31452
+ return path50.resolve(file);
31291
31453
  }
31292
31454
  return realOf(at);
31293
31455
  };
31294
31456
  var within = (child, parent) => {
31295
31457
  const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
31296
- const relative = path49.relative(fold(parent), fold(child));
31297
- return relative === "" || !relative.startsWith("..") && !path49.isAbsolute(relative);
31458
+ const relative = path50.relative(fold(parent), fold(child));
31459
+ return relative === "" || !relative.startsWith("..") && !path50.isAbsolute(relative);
31298
31460
  };
31299
31461
  var checkoutOf2 = (file) => {
31300
- for (let dir = canonical6(file);; dir = path49.dirname(dir)) {
31301
- const dotGit = path49.join(dir, ".git");
31462
+ for (let dir = canonical6(file);; dir = path50.dirname(dir)) {
31463
+ const dotGit = path50.join(dir, ".git");
31302
31464
  if (fs30.existsSync(dotGit)) {
31303
31465
  const admin = fs30.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
31304
- return { root: dir, workit: !!admin && fs30.existsSync(path49.join(admin, FANOUT_TOKEN_FILE)) };
31466
+ return { root: dir, workit: !!admin && fs30.existsSync(path50.join(admin, FANOUT_TOKEN_FILE)) };
31305
31467
  }
31306
- if (path49.dirname(dir) === dir)
31468
+ if (path50.dirname(dir) === dir)
31307
31469
  return null;
31308
31470
  }
31309
31471
  };
@@ -31315,8 +31477,8 @@ var workitWorktreeOf = (file) => {
31315
31477
  return null;
31316
31478
  }
31317
31479
  };
31318
- var bindingDir = () => path49.join(resolveStateDir(), "worktree-bind");
31319
- var bindingFile = (session, agentId) => path49.join(bindingDir(), `${createHash23("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
31480
+ var bindingDir = () => path50.join(resolveStateDir(), "worktree-bind");
31481
+ var bindingFile = (session, agentId) => path50.join(bindingDir(), `${createHash23("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
31320
31482
  var readBinding = (file) => {
31321
31483
  try {
31322
31484
  const value = JSON.parse(fs30.readFileSync(file, "utf8"));
@@ -31341,7 +31503,7 @@ var bind = (input, worktree) => {
31341
31503
  agentId,
31342
31504
  at: new Date().toISOString()
31343
31505
  };
31344
- fs30.mkdirSync(path49.dirname(file), { recursive: true });
31506
+ fs30.mkdirSync(path50.dirname(file), { recursive: true });
31345
31507
  fs30.writeFileSync(file, JSON.stringify(binding));
31346
31508
  try {
31347
31509
  if (inWorkitWorkspace(input.cwd))
@@ -31360,26 +31522,26 @@ var hostIsolated = (cwd, agentId) => {
31360
31522
  const checkout = checkoutOf2(cwd);
31361
31523
  if (!checkout)
31362
31524
  return false;
31363
- const dotGit = path49.join(checkout.root, ".git");
31525
+ const dotGit = path50.join(checkout.root, ".git");
31364
31526
  if (!fs30.statSync(dotGit).isFile())
31365
31527
  return false;
31366
31528
  const [adminDir, gitDir] = gitDirsAt(checkout.root, null, false) ?? [];
31367
- const back = fs30.readFileSync(path49.join(adminDir, "gitdir"), "utf8").trim();
31368
- if (path49.relative(canonical6(path49.resolve(adminDir, back)), canonical6(dotGit)) !== "")
31529
+ const back = fs30.readFileSync(path50.join(adminDir, "gitdir"), "utf8").trim();
31530
+ if (path50.relative(canonical6(path50.resolve(adminDir, back)), canonical6(dotGit)) !== "")
31369
31531
  return false;
31370
- const expected = path49.join(path49.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
31371
- return path49.relative(canonical6(expected), checkout.root) === "";
31532
+ const expected = path50.join(path50.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
31533
+ return path50.relative(canonical6(expected), checkout.root) === "";
31372
31534
  } catch {
31373
31535
  return false;
31374
31536
  }
31375
31537
  };
31376
31538
  var runnerAt = (target) => {
31377
- const base = path49.basename(target);
31539
+ const base = path50.basename(target);
31378
31540
  return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
31379
31541
  };
31380
31542
  var shown = (target) => {
31381
- const named = /^\.workit-(?:live-target$|runs-)/.test(path49.basename(target)) ? path49.dirname(target) : target;
31382
- return path49.sep === "\\" ? named.replaceAll("/", "\\") : named;
31543
+ const named = /^\.workit-(?:live-target$|runs-)/.test(path50.basename(target)) ? path50.dirname(target) : target;
31544
+ return path50.sep === "\\" ? named.replaceAll("/", "\\") : named;
31383
31545
  };
31384
31546
  var runFrom = (dir, command) => `cd ${dir} && ${command.replace(/^\s*cd\s+\S+\s*(?:&&|;)\s*/, "")}`;
31385
31547
  var deny2 = (what, unblock) => ({
@@ -31395,7 +31557,7 @@ var outsideDeny = (input, worktree, target, command) => {
31395
31557
  };
31396
31558
  var unknownDirDeny = (input, worktree) => deny2(`workit worktree confinement: implementer ${input.session.agentId} writes after a directory change Workit cannot resolve (\`cd -\`, \`cd "$X"\`, \`popd\`)`, `Why: write by absolute path, \`git -C ${worktree ?? "<worktree>"}\` or \`workit <verb> --cwd\`.`);
31397
31559
  var refsOf = (targets) => [
31398
- ...new Set(targets.flatMap((target) => path49.relative(UNKNOWN_VAR, path49.resolve(target)).split(path49.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
31560
+ ...new Set(targets.flatMap((target) => path50.relative(UNKNOWN_VAR, path50.resolve(target)).split(path50.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
31399
31561
  ];
31400
31562
  var literalForm = (command, refs) => {
31401
31563
  let text = command;
@@ -31428,10 +31590,10 @@ function confineImplementer(input, targets, command) {
31428
31590
  try {
31429
31591
  if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
31430
31592
  return NONE5;
31431
- const unresolved = targets.filter((target) => within(path49.resolve(target), UNKNOWN_VAR));
31593
+ const unresolved = targets.filter((target) => within(path50.resolve(target), UNKNOWN_VAR));
31432
31594
  if (unresolved.length > 0)
31433
31595
  return unknownVarDeny(input, unresolved, command);
31434
- if (targets.some((target) => within(path49.resolve(target), UNKNOWN_DIR)))
31596
+ if (targets.some((target) => within(path50.resolve(target), UNKNOWN_DIR)))
31435
31597
  return unknownDirDeny(input, boundWorktree(input));
31436
31598
  const bindings = canonical6(bindingDir());
31437
31599
  const judged = targets.map((named) => ({ named, real: canonical6(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
@@ -31538,10 +31700,10 @@ var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print)(?:=|$)|^--(?:test|version|he
31538
31700
  var VALUED2 = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
31539
31701
  var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
31540
31702
  var inScratch = (real, repo) => {
31541
- for (let dir = real;path49.dirname(dir) !== dir; dir = path49.dirname(dir)) {
31542
- if (path49.basename(dir) !== SCRATCH)
31703
+ for (let dir = real;path50.dirname(dir) !== dir; dir = path50.dirname(dir)) {
31704
+ if (path50.basename(dir) !== SCRATCH)
31543
31705
  continue;
31544
- const root = path49.dirname(dir);
31706
+ const root = path50.dirname(dir);
31545
31707
  const checkout = checkoutOf2(root);
31546
31708
  if (checkout?.root === root && (repo === null || checkout.workit || commonDir(root) === repo))
31547
31709
  return true;
@@ -31551,7 +31713,7 @@ var inScratch = (real, repo) => {
31551
31713
  var inGitDir = (real) => real.split(/[\\/]/).includes(".git");
31552
31714
  var SAFE_KEY = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|ignorecase|precomposeunicode|symlinks)|user\..*|init\.defaultbranch|commit\.gpgsign|extensions\.(?:objectformat|refstorage)|branch\..*\.(?:remote|merge)|remote\..*\.fetch)$/;
31553
31715
  var literalIn = (value, repo, checkout = false) => {
31554
- if (/[$`]/.test(value) || !path49.isAbsolute(value))
31716
+ if (/[$`]/.test(value) || !path50.isAbsolute(value))
31555
31717
  return false;
31556
31718
  const real = canonical6(value);
31557
31719
  const root = checkout ? checkoutOf2(real)?.root : undefined;
@@ -31572,8 +31734,8 @@ var configEntries = (text) => {
31572
31734
  return entries;
31573
31735
  };
31574
31736
  function gitDirsAt(dir, repo, scan = true) {
31575
- for (let at = dir;; at = path49.dirname(at)) {
31576
- const dotGit = path49.join(at, ".git");
31737
+ for (let at = dir;; at = path50.dirname(at)) {
31738
+ const dotGit = path50.join(at, ".git");
31577
31739
  let gitDir = null;
31578
31740
  try {
31579
31741
  if (fs30.statSync(dotGit).isDirectory())
@@ -31582,19 +31744,19 @@ function gitDirsAt(dir, repo, scan = true) {
31582
31744
  const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs30.readFileSync(dotGit, "utf8"))?.[1];
31583
31745
  if (!named)
31584
31746
  return null;
31585
- gitDir = canonical6(path49.resolve(at, named));
31747
+ gitDir = canonical6(path50.resolve(at, named));
31586
31748
  }
31587
31749
  } catch (error) {
31588
31750
  if (error.code !== "ENOENT")
31589
31751
  return null;
31590
- if (["HEAD", "objects", "refs"].every((name) => fs30.existsSync(path49.join(at, name))))
31752
+ if (["HEAD", "objects", "refs"].every((name) => fs30.existsSync(path50.join(at, name))))
31591
31753
  gitDir = canonical6(at);
31592
31754
  }
31593
31755
  if (gitDir !== null) {
31594
- const common = path49.join(gitDir, "commondir");
31595
- const shared = fs30.existsSync(common) ? canonical6(path49.resolve(gitDir, fs30.readFileSync(common, "utf8").trim())) : gitDir;
31756
+ const common = path50.join(gitDir, "commondir");
31757
+ const shared = fs30.existsSync(common) ? canonical6(path50.resolve(gitDir, fs30.readFileSync(common, "utf8").trim())) : gitDir;
31596
31758
  const dirs = [gitDir, shared];
31597
- for (const config of scan ? new Set([path49.join(gitDir, "config"), path49.join(shared, "config")]) : []) {
31759
+ for (const config of scan ? new Set([path50.join(gitDir, "config"), path50.join(shared, "config")]) : []) {
31598
31760
  let text = "";
31599
31761
  try {
31600
31762
  text = fs30.readFileSync(config, "utf8");
@@ -31603,14 +31765,14 @@ function gitDirsAt(dir, repo, scan = true) {
31603
31765
  }
31604
31766
  for (const [key, value] of configEntries(text)) {
31605
31767
  if (key === "core.worktree")
31606
- dirs.push(canonical6(path49.resolve(gitDir, value)));
31768
+ dirs.push(canonical6(path50.resolve(gitDir, value)));
31607
31769
  else if (/^remote\..*\.url$/.test(key) ? !literalIn(value, repo, true) : !SAFE_KEY.test(key))
31608
31770
  return null;
31609
31771
  }
31610
31772
  }
31611
31773
  return dirs;
31612
31774
  }
31613
- if (path49.dirname(at) === at)
31775
+ if (path50.dirname(at) === at)
31614
31776
  return [];
31615
31777
  }
31616
31778
  }
@@ -31750,10 +31912,10 @@ var gitKind = (args, local = () => true) => {
31750
31912
  return GIT_VERBS[verb].startsWith("+") ? "write" : "read";
31751
31913
  };
31752
31914
  var remoteIn = (dir, name, repo) => {
31753
- const shared = path49.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
31915
+ const shared = path50.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
31754
31916
  if (!shared)
31755
31917
  return false;
31756
- const url = configEntries(fs30.readFileSync(path49.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
31918
+ const url = configEntries(fs30.readFileSync(path50.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
31757
31919
  return url !== undefined && literalIn(url, repo, true);
31758
31920
  };
31759
31921
  var judgeEnvAllowed = (word) => {
@@ -31782,7 +31944,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
31782
31944
  at = after;
31783
31945
  }
31784
31946
  }
31785
- const name = path49.basename(words[at] ?? "");
31947
+ const name = path50.basename(words[at] ?? "");
31786
31948
  let start = words.findIndex((word) => /(?:^|[\\/])git(?:\.exe)?(?:=|$)/.test(word));
31787
31949
  if (start > at) {
31788
31950
  if (/^(?:grep|egrep|rg|echo|printf|ls|wc|head|tail|cat|which|type|test|\[|cd|mkdir)$/.test(name) || name === "command" && /^-[vV]$/.test(words[at + 1] ?? ""))
@@ -31793,7 +31955,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
31793
31955
  if (start >= 0 && words[start].includes("="))
31794
31956
  why = "git is redefined";
31795
31957
  const run = words[start] ?? "";
31796
- if (run.includes("/") && (!path49.isAbsolute(run) || literalIn(run, repo, true)))
31958
+ if (run.includes("/") && (!path50.isAbsolute(run) || literalIn(run, repo, true)))
31797
31959
  why ??= `\`${run}\` is not the system git`;
31798
31960
  if (segment.expands?.includes(at) && name !== "[" || /\{[^}]*,/.test(words[at] ?? ""))
31799
31961
  why = "the command's name is expanded by the shell";
@@ -31818,13 +31980,13 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
31818
31980
  const args = words[index] === "--version" ? ["version"] : words.slice(index);
31819
31981
  if (!why && start >= 0) {
31820
31982
  const local = (source, remote) => remote && /^[\w-][\w.-]*$/.test(source) ? remoteIn(dir, source, repo) : literalIn(source, repo, true);
31821
- const runsIn = path49.isAbsolute(dir) ? dir : cwd && path49.resolve(cwd, dir);
31983
+ const runsIn = path50.isAbsolute(dir) ? dir : cwd && path50.resolve(cwd, dir);
31822
31984
  const home = runsIn && checkoutOf2(runsIn);
31823
31985
  const fetches = args[0] === "fetch" && plainFetch(args.slice(1)) && home && (home.workit || commonDir(home.root) === repo) && !words.some((word) => /^--[gw]/.test(word));
31824
31986
  if (!fetches && !gitKind(args, local))
31825
31987
  why = `\`git ${args.slice(0, 2).join(" ")}\` is not allowed`;
31826
31988
  }
31827
- const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path49.basename(word)));
31989
+ const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path50.basename(word)));
31828
31990
  const scripts = [
31829
31991
  ...words.filter((_, after) => shell >= 0 && after > shell && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(words[after - 1])),
31830
31992
  ...shell < 0 ? [] : segment.stdin ?? []
@@ -31869,7 +32031,7 @@ var judgeVerbRefused = (args) => {
31869
32031
  var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
31870
32032
  var CLI_ENTRY = /(?:^|[=\\/])(?:workit(?:\.(?:exe|cmd|[cm]?js))?|@workit-dev\/cli(?:@\S*)?)$|(?:workit-cli|@workit-dev[\\/]cli)[\\/](?:src[\\/](?:index|main)|dist[\\/]index)\.[cm]?[jt]sx?$/;
31871
32033
  var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
31872
- const name = path49.basename(words[0] ?? "").toLowerCase();
32034
+ const name = path50.basename(words[0] ?? "").toLowerCase();
31873
32035
  if (name === "alias")
31874
32036
  return words.flatMap((word) => {
31875
32037
  const set = /^([\w-]+)=(.*)$/s.exec(word);
@@ -31898,11 +32060,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
31898
32060
  return why;
31899
32061
  }
31900
32062
  const { words } = segment;
31901
- const runs = (word = "") => RUNS.test(path49.basename(word).toLowerCase());
32063
+ const runs = (word = "") => RUNS.test(path50.basename(word).toLowerCase());
31902
32064
  let at = 0;
31903
32065
  while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
31904
32066
  at++;
31905
- const name = path49.basename(words[at] ?? "").toLowerCase();
32067
+ const name = path50.basename(words[at] ?? "").toLowerCase();
31906
32068
  const args = words.slice(at + 1);
31907
32069
  const unseen = `\`${words.join(" ").slice(0, 80)}\` runs a script Workit cannot read (piped, on stdin, a process substitution or eval): write the case to a file in ${SCRATCH} and dispatch it from a test instead`;
31908
32070
  if (/^(?:cd|chdir|pushd|popd)$/.test(name))
@@ -31984,10 +32146,10 @@ var judgeDeny = (input, what, target, retry, why = "write only there (mkdir -p i
31984
32146
  const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
31985
32147
  const root = checkoutOf2(input.cwd)?.root;
31986
32148
  const candidate = target ? checkoutOf2(target)?.root : undefined;
31987
- const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path49.join(candidate, SCRATCH) : undefined;
31988
- const scratch = root ? `${path49.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
31989
- const call = root ? retry?.((other ?? path49.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
31990
- const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ? path49.join(root, SCRATCH) : SCRATCH))}`;
32149
+ const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path50.join(candidate, SCRATCH) : undefined;
32150
+ const scratch = root ? `${path50.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
32151
+ const call = root ? retry?.((other ?? path50.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
32152
+ const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ? path50.join(root, SCRATCH) : SCRATCH))}`;
31991
32153
  return {
31992
32154
  kind: "deny",
31993
32155
  reason: `workit scratch confinement: ${role} ${input.session.agentId} may write only in its scratch dir ${scratch}, and ${what}.
@@ -31997,9 +32159,9 @@ ${unblock}`,
31997
32159
  };
31998
32160
  var movedInto = (command, cwd, target, dir) => {
31999
32161
  for (const { words, redirects } of segmentsOf(command))
32000
- for (const word of [...redirects, ...path49.basename(words[0] ?? "") === "tee" ? words : []])
32001
- if (path49.resolve(cwd, word) === path49.resolve(cwd, target)) {
32002
- const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path49.basename(word)}`);
32162
+ for (const word of [...redirects, ...path50.basename(words[0] ?? "") === "tee" ? words : []])
32163
+ if (path50.resolve(cwd, word) === path50.resolve(cwd, target)) {
32164
+ const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path50.basename(word)}`);
32003
32165
  return moved === command ? null : moved;
32004
32166
  }
32005
32167
  return null;
@@ -32011,19 +32173,19 @@ function confineJudge(input, targets, placeholders = placeholdersOf(targets), co
32011
32173
  const judged = checkoutOf2(input.cwd);
32012
32174
  const repo = judged ? commonDir(judged.root) : null;
32013
32175
  const scratch = (real) => inScratch(real, repo) || [os11.tmpdir(), "/tmp"].some((dir) => {
32014
- const [host, , session] = path49.relative(canonical6(dir), real).split(path49.sep);
32176
+ const [host, , session] = path50.relative(canonical6(dir), real).split(path50.sep);
32015
32177
  return /^claude-\d+$/.test(host) && session === input.session.id;
32016
32178
  });
32017
32179
  for (const target of targets) {
32018
- const resolved = path49.resolve(target);
32180
+ const resolved = path50.resolve(target);
32019
32181
  if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
32020
32182
  return judgeDeny(input, "it writes to a path Workit cannot resolve", undefined, () => {
32021
32183
  const literal = command && literalForm(command, refsOf([target]));
32022
32184
  return literal === command ? null : literal;
32023
32185
  });
32024
32186
  const real = canonical6(target);
32025
- const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path49.basename(target));
32026
- const gitDirs = runsGit ? gitDirsAt(path49.dirname(real), repo) : [];
32187
+ const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path50.basename(target));
32188
+ const gitDirs = runsGit ? gitDirsAt(path50.dirname(real), repo) : [];
32027
32189
  if (gitDirs === null)
32028
32190
  return judgeDeny(input, `git in ${shown(target)} uses a git dir or config Workit cannot check`);
32029
32191
  if (runsGit ? gitDirs.length > 0 ? gitDirs.every(scratch) : scratch(real) : scratch(real) && !inGitDir(real))
@@ -32091,7 +32253,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
32091
32253
  let git = [];
32092
32254
  try {
32093
32255
  git = rawInvocations(command, dialect).flatMap(({ tool, dir, args }) => tool === "git" && (args[0] === "push" || leadOwnedGit(args) || gitKind(args) === "write" && !/^(?:init|clone)$/.test(args[0]) && !(args[0] === "fetch" && plainFetch(args.slice(1)))) ? [
32094
- path49.join(dir === undefined ? UNKNOWN_DIR : path49.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
32256
+ path50.join(dir === undefined ? UNKNOWN_DIR : path50.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
32095
32257
  ] : []);
32096
32258
  } catch {}
32097
32259
  const lists = [
@@ -32136,7 +32298,7 @@ var judgeChecksLine = (cwd) => {
32136
32298
 
32137
32299
  // packages/workit-core/src/hooks/standing.ts
32138
32300
  var readPlans = (store) => {
32139
- const dir = path50.join(store, "fanouts");
32301
+ const dir = path51.join(store, "fanouts");
32140
32302
  let names;
32141
32303
  try {
32142
32304
  names = fs31.readdirSync(dir).filter((name) => name.endsWith(".json"));
@@ -32146,7 +32308,7 @@ var readPlans = (store) => {
32146
32308
  const plans = [];
32147
32309
  for (const name of names) {
32148
32310
  try {
32149
- const raw = JSON.parse(fs31.readFileSync(path50.join(dir, name), "utf8"));
32311
+ const raw = JSON.parse(fs31.readFileSync(path51.join(dir, name), "utf8"));
32150
32312
  if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
32151
32313
  continue;
32152
32314
  const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
@@ -32356,12 +32518,12 @@ var cdWorkitSplit = (command) => {
32356
32518
 
32357
32519
  // packages/workit-core/src/hooks/spawn-gate.ts
32358
32520
  import fs32 from "node:fs";
32359
- import path52 from "node:path";
32521
+ import path53 from "node:path";
32360
32522
 
32361
32523
  // packages/workit-core/src/hooks/model-limit.ts
32362
- import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync7, readSync, statSync as statSync5 } from "node:fs";
32524
+ import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync8, readSync, statSync as statSync5 } from "node:fs";
32363
32525
  import os12 from "node:os";
32364
- import path51 from "node:path";
32526
+ import path52 from "node:path";
32365
32527
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
32366
32528
  var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
32367
32529
  var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
@@ -32559,17 +32721,17 @@ var firstPrompt = (file) => {
32559
32721
  var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
32560
32722
  var listDir = (dir) => {
32561
32723
  try {
32562
- return readdirSync7(dir).map((name) => path51.join(dir, name));
32724
+ return readdirSync8(dir).map((name) => path52.join(dir, name));
32563
32725
  } catch {
32564
32726
  return [];
32565
32727
  }
32566
32728
  };
32567
32729
  var SCAN_MS = 30 * 60000;
32568
32730
  var scanClaudeTranscripts = (cwd, env, now = new Date) => {
32569
- const projects = path51.join(env.CLAUDE_CONFIG_DIR || path51.join(env.HOME || os12.homedir(), ".claude"), "projects");
32570
- const project = path51.join(projects, claudeProjectSlug(cwd));
32731
+ const projects = path52.join(env.CLAUDE_CONFIG_DIR || path52.join(env.HOME || os12.homedir(), ".claude"), "projects");
32732
+ const project = path52.join(projects, claudeProjectSlug(cwd));
32571
32733
  const notes = [];
32572
- const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path51.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
32734
+ const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path52.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
32573
32735
  for (const { file, worker } of files)
32574
32736
  try {
32575
32737
  const stat = statSync5(file);
@@ -32584,7 +32746,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
32584
32746
  if (!seen)
32585
32747
  continue;
32586
32748
  notes.push(worker ? redispatchNote(seen, {
32587
- label: `worker ${path51.basename(file, ".jsonl")}`,
32749
+ label: `worker ${path52.basename(file, ".jsonl")}`,
32588
32750
  prompt: firstPrompt(file)
32589
32751
  }, now) : `Workit: this session hit a usage limit (${seen.reason}); ${seen.key} is marked exhausted until ${shortTime(seen.until)}. Claude Code runs only Anthropic models: Workit cannot switch this session, so continue on another host or after the reset.`);
32590
32752
  } catch {}
@@ -32686,10 +32848,10 @@ var namesMade = (word) => {
32686
32848
  const stat = fs32.statSync(word);
32687
32849
  if (stat.isFile())
32688
32850
  return stat.size < 1e6 && MADE_WORKTREE.test(fs32.readFileSync(word, "utf8"));
32689
- const dotGit = path52.join(word, ".git");
32851
+ const dotGit = path53.join(word, ".git");
32690
32852
  const link = fs32.statSync(dotGit);
32691
32853
  const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs32.readFileSync(dotGit, "utf8"));
32692
- return !!admin && fs32.existsSync(path52.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
32854
+ return !!admin && fs32.existsSync(path53.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
32693
32855
  } catch {
32694
32856
  return false;
32695
32857
  }
@@ -32735,8 +32897,8 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
32735
32897
 
32736
32898
  // packages/workit-core/src/hooks/server-gate.ts
32737
32899
  import fs33 from "node:fs";
32738
- import path53 from "node:path";
32739
- var procNoticeFile = (env, session) => path53.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
32900
+ import path54 from "node:path";
32901
+ var procNoticeFile = (env, session) => path54.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
32740
32902
  var mb = (bytes) => `${Math.round(Number(bytes) / 1048576)} MB`;
32741
32903
  function takeProcNotice(session, env = process.env) {
32742
32904
  if (!session)
@@ -32774,21 +32936,21 @@ function takeProcNotice(session, env = process.env) {
32774
32936
  // packages/workit-core/src/hooks/teardown.ts
32775
32937
  import { spawn } from "node:child_process";
32776
32938
  import fs34 from "node:fs";
32777
- import path55 from "node:path";
32939
+ import path56 from "node:path";
32778
32940
 
32779
32941
  // packages/workit-core/src/core/cli-locate.ts
32780
32942
  import { closeSync as closeSync5, existsSync as existsSync18, openSync as openSync5, readSync as readSync2 } from "node:fs";
32781
- import path54 from "node:path";
32943
+ import path55 from "node:path";
32782
32944
  var LAUNCHER_MARKER = "workit-owned-launcher";
32783
32945
  var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
32784
32946
  var installRoot = (env, platform = process.platform) => {
32785
32947
  if (env.WORKIT_INSTALL_ROOT)
32786
32948
  return env.WORKIT_INSTALL_ROOT;
32787
32949
  const data = dataDir(env, platform);
32788
- return platform === "win32" ? path54.join(data, "install") : data;
32950
+ return platform === "win32" ? path55.join(data, "install") : data;
32789
32951
  };
32790
- var ownedLauncherPath = (env, platform = process.platform) => path54.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
32791
- var ownedCurrentEntry = (env, platform = process.platform) => path54.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
32952
+ var ownedLauncherPath = (env, platform = process.platform) => path55.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
32953
+ var ownedCurrentEntry = (env, platform = process.platform) => path55.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
32792
32954
  var head = (file) => {
32793
32955
  let fd;
32794
32956
  try {
@@ -32815,7 +32977,7 @@ var locateWorkitCli = (options = {}) => {
32815
32977
  source: "owned-launcher",
32816
32978
  command: launcher,
32817
32979
  args: [],
32818
- binDir: path54.dirname(launcher)
32980
+ binDir: path55.dirname(launcher)
32819
32981
  };
32820
32982
  const current = ownedCurrentEntry(env, platform);
32821
32983
  if (exists(current))
@@ -32844,7 +33006,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
32844
33006
  if (located.binDir) {
32845
33007
  const key = pathKey(env);
32846
33008
  const delimiter = platform === "win32" ? ";" : ":";
32847
- const same = (dir) => platform === "win32" ? path54.win32.normalize(dir).toLowerCase() === path54.win32.normalize(located.binDir).toLowerCase() : path54.posix.normalize(dir) === path54.posix.normalize(located.binDir);
33009
+ const same = (dir) => platform === "win32" ? path55.win32.normalize(dir).toLowerCase() === path55.win32.normalize(located.binDir).toLowerCase() : path55.posix.normalize(dir) === path55.posix.normalize(located.binDir);
32848
33010
  const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
32849
33011
  patch[key] = [located.binDir, ...rest].join(delimiter);
32850
33012
  }
@@ -32868,9 +33030,9 @@ var ENDS = {
32868
33030
  };
32869
33031
  var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
32870
33032
  var HOST_SESSION_VARS2 = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
32871
- var teardownDir = (env) => path55.join(stateDir(env), "procs");
32872
- var teardownLog = (env) => path55.join(teardownDir(env), "teardown.log");
32873
- var reapStamp = (env) => path55.join(teardownDir(env), "reap-at-start.stamp");
33033
+ var teardownDir = (env) => path56.join(stateDir(env), "procs");
33034
+ var teardownLog = (env) => path56.join(teardownDir(env), "teardown.log");
33035
+ var reapStamp = (env) => path56.join(teardownDir(env), "reap-at-start.stamp");
32874
33036
  function spawnDetached(request) {
32875
33037
  try {
32876
33038
  const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
@@ -32897,7 +33059,7 @@ var teardownDeps = {
32897
33059
  var openLog = (env, args) => {
32898
33060
  try {
32899
33061
  const file = teardownLog(env);
32900
- fs34.mkdirSync(path55.dirname(file), { recursive: true });
33062
+ fs34.mkdirSync(path56.dirname(file), { recursive: true });
32901
33063
  let size = 0;
32902
33064
  try {
32903
33065
  size = fs34.statSync(file).size;
@@ -32982,7 +33144,7 @@ function reapAtStart(_cwd, env = process.env) {
32982
33144
  try {
32983
33145
  if (fresh(stamp, now))
32984
33146
  return false;
32985
- fs34.mkdirSync(path55.dirname(stamp), { recursive: true });
33147
+ fs34.mkdirSync(path56.dirname(stamp), { recursive: true });
32986
33148
  if (!claim2(lock, now))
32987
33149
  return false;
32988
33150
  } catch {
@@ -33674,11 +33836,11 @@ Retry as: ${retry}`,
33674
33836
  // packages/workit-core/src/agent-stamp.ts
33675
33837
  import { createHash as createHash24, randomBytes as randomBytes5 } from "node:crypto";
33676
33838
  import fs35 from "node:fs";
33677
- import path56 from "node:path";
33839
+ import path57 from "node:path";
33678
33840
  var STAMP_TTL_MS = 120000;
33679
33841
  var AGENT_ID = /^[\w-]{1,64}$/u;
33680
33842
  var hash2 = (text) => createHash24("sha256").update(text).digest("hex").slice(0, 32);
33681
- var stampDir = (env, session) => path56.join(stateDir(env), "agent-stamps", hash2(session));
33843
+ var stampDir = (env, session) => path57.join(stateDir(env), "agent-stamps", hash2(session));
33682
33844
  var workitCalls2 = (command, dialect = "posix") => {
33683
33845
  const calls = [];
33684
33846
  try {
@@ -33703,9 +33865,9 @@ var noteAgentStamps = (env, session, agentId, command, options = {}) => {
33703
33865
  fs35.mkdirSync(dir, { recursive: true, mode: 448 });
33704
33866
  const now = Date.now();
33705
33867
  for (const name of fs35.readdirSync(dir))
33706
- if (now - fs35.statSync(path56.join(dir, name)).mtimeMs > STAMP_TTL_MS)
33707
- fs35.rmSync(path56.join(dir, name), { force: true });
33708
- calls.forEach((argv, index) => fs35.writeFileSync(path56.join(dir, `${hash2(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
33868
+ if (now - fs35.statSync(path57.join(dir, name)).mtimeMs > STAMP_TTL_MS)
33869
+ fs35.rmSync(path57.join(dir, name), { force: true });
33870
+ calls.forEach((argv, index) => fs35.writeFileSync(path57.join(dir, `${hash2(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
33709
33871
  } catch {}
33710
33872
  };
33711
33873
  var callTag = (toolUseId) => hash2(toolUseId).slice(0, 8);
@@ -33717,9 +33879,447 @@ var dropAgentStamps = (env, session, toolUseId, command) => {
33717
33879
  const tag = `.${callTag(toolUseId)}-`;
33718
33880
  for (const name of fs35.readdirSync(dir))
33719
33881
  if (name.includes(tag))
33720
- fs35.rmSync(path56.join(dir, name), { force: true });
33882
+ fs35.rmSync(path57.join(dir, name), { force: true });
33883
+ } catch {}
33884
+ };
33885
+
33886
+ // packages/workit-core/src/hooks/hook-entry.ts
33887
+ import { existsSync as existsSync19, readFileSync as readFileSync16, realpathSync as realpathSync13 } from "node:fs";
33888
+ import path58 from "node:path";
33889
+ 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;
33890
+ var PACKAGE_ENTRIES = {
33891
+ "claude-code": /^(?:bin\/workit-hook\.mjs|src\/(?:run|hook)\.ts|dist\/workit-hook\.js)$/u,
33892
+ codex: /^(?:hooks\/(?:launcher|workit-hook)\.ts|dist\/workit-hook(?:-[\w-]+)?\.js)$/u,
33893
+ cursor: /^(?:hooks\/(?:launch|launch-runtime)\.mjs|hooks\/(?:workit-hook|session-start|subagent-start)\.ts|dist\/(?:workit-hook|cursor-session-start)\.js)$/u,
33894
+ core: /^src\/hooks\/run\.ts$/u
33895
+ };
33896
+ var RUNNERS2 = new Set([
33897
+ "node",
33898
+ "nodejs",
33899
+ "bun",
33900
+ "deno",
33901
+ "tsx",
33902
+ "ts-node",
33903
+ "sh",
33904
+ "bash",
33905
+ "zsh",
33906
+ "dash",
33907
+ "ksh",
33908
+ "fish",
33909
+ "source",
33910
+ "."
33911
+ ]);
33912
+ var PACKAGE_RUNNERS2 = new Set(["npx", "bunx", "pnpx"]);
33913
+ var NO_RUN = new Set([
33914
+ "build",
33915
+ "test",
33916
+ "fmt",
33917
+ "lint",
33918
+ "check",
33919
+ "doc",
33920
+ "info",
33921
+ "install",
33922
+ "add",
33923
+ "pm"
33924
+ ]);
33925
+ var MORE_WRAPPERS = new Set(["strace", "ltrace", "watch", "unshare", "firejail", "xargs", "&"]);
33926
+ var baseName3 = (word) => (word.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "").toLowerCase();
33927
+ var packageAt = (dir) => {
33928
+ try {
33929
+ const name = JSON.parse(readFileSync16(path58.join(dir, "package.json"), "utf8")).name;
33930
+ const short = /^@workit-dev\/(claude-code|codex|cursor|core)$/u.exec(String(name))?.[1];
33931
+ if (short)
33932
+ return short;
33721
33933
  } catch {}
33934
+ for (const [manifest, short] of [
33935
+ [".claude-plugin", "claude-code"],
33936
+ [".codex-plugin", "codex"],
33937
+ [".cursor-plugin", "cursor"]
33938
+ ]) {
33939
+ try {
33940
+ const name = JSON.parse(readFileSync16(path58.join(dir, manifest, "plugin.json"), "utf8")).name;
33941
+ if (name === "workit")
33942
+ return short;
33943
+ } catch {}
33944
+ }
33945
+ return null;
33946
+ };
33947
+ var entryByPath = (file) => {
33948
+ let dir = path58.dirname(file);
33949
+ for (let depth = 0;depth < 4; depth += 1, dir = path58.dirname(dir)) {
33950
+ const short = packageAt(dir);
33951
+ if (short)
33952
+ return PACKAGE_ENTRIES[short]?.test(path58.relative(dir, file).split(path58.sep).join("/")) ?? false;
33953
+ if (existsSync19(path58.join(dir, "package.json")))
33954
+ return false;
33955
+ }
33956
+ return false;
33957
+ };
33958
+ var literalSub = (match, inner) => {
33959
+ try {
33960
+ const [only, ...rest] = segmentsOf(inner);
33961
+ const [verb = "", ...args] = only?.words ?? [];
33962
+ const last = args.findLast((arg) => !arg.startsWith("-"));
33963
+ return rest.length === 0 && /^(?:echo|printf|ls|realpath|readlink)$/u.test(baseName3(verb)) && last ? last : match;
33964
+ } catch {
33965
+ return match;
33966
+ }
33967
+ };
33968
+ var expand = (word, vars) => word.replace(/\$\(([^()]*)\)|`([^`]*)`/gu, (match, sub, tick) => literalSub(match, sub ?? tick ?? "")).replace(/\$\{(\w+)\}|\$(\w+)/gu, (match, braced, bare) => {
33969
+ const name = braced ?? bare ?? "";
33970
+ return vars.get(name) ?? process.env[name] ?? match;
33971
+ }).replace(/^~(?=[\\/]|$)/u, userHome(process.env));
33972
+ var entryNamed = (word, scan) => {
33973
+ if (!word)
33974
+ return null;
33975
+ const text = expand(word, scan.vars);
33976
+ if (ENTRY_NAMES.test(baseName3(text)))
33977
+ return text;
33978
+ const fd = /^\/(?:dev|proc\/self)\/fd\/(\d+)$/u.exec(text)?.[1];
33979
+ if (fd !== undefined && scan.fds.has(fd))
33980
+ return text;
33981
+ if (scan.dir === null && !path58.isAbsolute(text))
33982
+ return null;
33983
+ for (const file of expandGlob(path58.resolve(scan.dir ?? "/", text))) {
33984
+ if (scan.links.has(file) || entryByPath(file))
33985
+ return text;
33986
+ let real;
33987
+ try {
33988
+ real = realpathSync13(file);
33989
+ } catch {
33990
+ continue;
33991
+ }
33992
+ if (ENTRY_NAMES.test(baseName3(real)) || entryByPath(real))
33993
+ return text;
33994
+ }
33995
+ return null;
33996
+ };
33997
+ var noteLink = (words, scan) => {
33998
+ if (!/^(?:ln|cp|install)$/u.test(baseName3(words[0] ?? "")) || scan.dir === null)
33999
+ return;
34000
+ const names = words.slice(1).filter((word) => !word.startsWith("-"));
34001
+ const dest = names.at(-1);
34002
+ if (dest === undefined || names.length < 2)
34003
+ return;
34004
+ for (const source of names.slice(0, -1).filter((name) => entryNamed(name, scan))) {
34005
+ const to = path58.resolve(scan.dir, expand(dest, scan.vars));
34006
+ scan.links.add(to);
34007
+ scan.links.add(path58.join(to, path58.basename(source)));
34008
+ }
34009
+ };
34010
+ var runsEntry = (words, inputs, scan) => {
34011
+ const named = (word) => entryNamed(word, scan);
34012
+ let at = 0;
34013
+ while (at < words.length) {
34014
+ while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
34015
+ at += 1;
34016
+ const word = words[at];
34017
+ if (word === undefined)
34018
+ return null;
34019
+ const entry = named(word);
34020
+ if (entry)
34021
+ return entry;
34022
+ const name = baseName3(word);
34023
+ const split = name === "env" ? words.findIndex((w) => /^(?:-\w*S|--split-string)/u.test(w)) : -1;
34024
+ if (split > at) {
34025
+ const line = /^(?:-\w*S|--split-string=?)(.*)$/su.exec(words[split] ?? "")?.[1] || words[split + 1];
34026
+ const rest = words.slice(split + (line === words[split + 1] ? 2 : 1));
34027
+ return runsEntry([...(line ?? "").split(/\s+/u).filter(Boolean), ...rest], inputs, scan);
34028
+ }
34029
+ if (MORE_WRAPPERS.has(name)) {
34030
+ at = pastOptions(words, at + 1, "");
34031
+ continue;
34032
+ }
34033
+ const takes = WRAPPERS3[name];
34034
+ if (takes !== undefined && !PACKAGE_RUNNERS2.has(name)) {
34035
+ at = pastOptions(words, at + 1, takes, name === "env" || name === "sudo");
34036
+ continue;
34037
+ }
34038
+ if (name === "busybox" || name === "toybox") {
34039
+ at += 1;
34040
+ continue;
34041
+ }
34042
+ 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] ?? "");
34043
+ if (runner) {
34044
+ at += PACKAGE_RUNNERS2.has(name) ? 1 : 2;
34045
+ while (words[at]?.startsWith("-"))
34046
+ at += /^(?:-p|--package|-c|--call)$/u.test(words[at] ?? "") ? 2 : 1;
34047
+ if (/^@workit-dev\/(?:claude-code|codex|cursor)(?:@|$)/u.test(words[at] ?? ""))
34048
+ return words[at] ?? null;
34049
+ continue;
34050
+ }
34051
+ if (!RUNNERS2.has(name))
34052
+ return null;
34053
+ if ((name === "bun" || name === "deno") && NO_RUN.has(words[at + 1] ?? ""))
34054
+ return null;
34055
+ for (const arg of [...words.slice(at + 1), ...inputs]) {
34056
+ const hit = named(arg);
34057
+ if (hit)
34058
+ return hit;
34059
+ }
34060
+ return null;
34061
+ }
34062
+ return null;
33722
34063
  };
34064
+ var KEYWORDS3 = new Set([
34065
+ "{",
34066
+ "}",
34067
+ "if",
34068
+ "then",
34069
+ "elif",
34070
+ "else",
34071
+ "fi",
34072
+ "while",
34073
+ "until",
34074
+ "do",
34075
+ "done",
34076
+ "esac",
34077
+ "!"
34078
+ ]);
34079
+ var pastKeywords = (words) => {
34080
+ let at = 0;
34081
+ for (;; ) {
34082
+ if (words[at] === "function")
34083
+ at += 2;
34084
+ else if (KEYWORDS3.has(words[at] ?? ""))
34085
+ at += 1;
34086
+ else
34087
+ break;
34088
+ }
34089
+ return /^(?:for|case|select)$/u.test(words[at] ?? "") ? [] : words.slice(at);
34090
+ };
34091
+ 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(" "));
34092
+ var TOKENS2 = /[\s'"`(),[\]{};|&<>=!]+/u;
34093
+ var ENTRY_SAMPLES = [
34094
+ "workit-hook.mjs",
34095
+ "workit-hook.js",
34096
+ "workit-hook.ts",
34097
+ "cursor-session-start.js"
34098
+ ];
34099
+ var tokenEntry = (token, scan) => {
34100
+ if (!/[\\/]/u.test(token) && !existsSync19(path58.resolve(scan.dir ?? "/", token)))
34101
+ return null;
34102
+ return entryNamed(token, scan);
34103
+ };
34104
+ var opaqueEntry = (words, inputs, scan) => {
34105
+ let at = 0;
34106
+ while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
34107
+ at += 1;
34108
+ const head = baseName3(words[at] ?? "");
34109
+ if (READERS2.has(head))
34110
+ return null;
34111
+ if ((head === "bun" || head === "deno") && NO_RUN.has(words[at + 1] ?? ""))
34112
+ return null;
34113
+ if (head === "git" && !words.some((word) => word.includes("alias.")))
34114
+ return null;
34115
+ if (head === "workit" || head === "workit-cli")
34116
+ return null;
34117
+ const tokens = words.flatMap((word) => word.split(TOKENS2)).filter(Boolean);
34118
+ const runner = (token) => RUNNERS2.has(baseName3(token)) && !/^(?:\.|source)$/u.test(token) || PACKAGE_RUNNERS2.has(baseName3(token));
34119
+ if (!tokens.some(runner))
34120
+ return null;
34121
+ if (scan.fed)
34122
+ return scan.fed;
34123
+ for (const token of tokens) {
34124
+ const hit = tokenEntry(token, scan);
34125
+ if (hit)
34126
+ return hit;
34127
+ }
34128
+ if (head === "find")
34129
+ for (const [index, word] of words.entries()) {
34130
+ const named = /^-i?name$/u.test(words[index - 1] ?? "") && /^[^*?[]/u.test(word);
34131
+ const pattern = named ? globPattern(word) : null;
34132
+ if (pattern && ENTRY_SAMPLES.some((sample) => pattern.test(sample)))
34133
+ return word;
34134
+ }
34135
+ if (/^(?:xargs|parallel)$/u.test(head) || tokens.includes("xargs"))
34136
+ for (const input of inputs) {
34137
+ try {
34138
+ const file = path58.resolve(scan.dir ?? "/", expand(input, scan.vars));
34139
+ const text = readFileSync16(file, "utf8").slice(0, 65536);
34140
+ for (const token of text.split(/\s+/u).filter(Boolean)) {
34141
+ const hit = tokenEntry(token, scan);
34142
+ if (hit)
34143
+ return hit;
34144
+ }
34145
+ } catch {}
34146
+ }
34147
+ return null;
34148
+ };
34149
+ var expandedCommand = (words, scan) => {
34150
+ let at = 0;
34151
+ while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
34152
+ at += 1;
34153
+ if (!/[$`]/u.test(words[at] ?? ""))
34154
+ return null;
34155
+ for (const word of words.slice(at + 1)) {
34156
+ const hit = entryNamed(word, scan);
34157
+ if (hit)
34158
+ return hit;
34159
+ }
34160
+ return null;
34161
+ };
34162
+ var optionsEntry = (words, scan) => {
34163
+ for (const word of words) {
34164
+ const value = /^(?:NODE_OPTIONS|BUN_OPTIONS)=(.*)$/su.exec(word)?.[1];
34165
+ if (value === undefined)
34166
+ continue;
34167
+ for (const token of value.split(TOKENS2).filter(Boolean)) {
34168
+ const hit = tokenEntry(token, scan);
34169
+ if (hit)
34170
+ return hit;
34171
+ }
34172
+ }
34173
+ return null;
34174
+ };
34175
+ var scanCommand = (command, dialect, scan) => {
34176
+ let segments;
34177
+ try {
34178
+ segments = segmentsOf(command, dialect);
34179
+ } catch {
34180
+ return null;
34181
+ }
34182
+ for (const [index, segment] of segments.entries()) {
34183
+ if (segment.unanalyzable)
34184
+ continue;
34185
+ bindLoop(segment.words, segments.slice(index + 1), scan);
34186
+ const words = pastKeywords(segment.words);
34187
+ const fed = scan.fed;
34188
+ scan.fed = null;
34189
+ const hit = segmentEntry(segment, words, dialect, scan, fed);
34190
+ if (hit)
34191
+ return hit;
34192
+ }
34193
+ return null;
34194
+ };
34195
+ var bindLoop = (raw, after, scan) => {
34196
+ const at = raw.findIndex((word) => !KEYWORDS3.has(word));
34197
+ const verb = raw[at];
34198
+ if ((verb === "for" || verb === "select") && raw[at + 2] === "in") {
34199
+ const name = raw[at + 1] ?? "";
34200
+ const items = raw.slice(at + 3);
34201
+ const item = items.find((word) => entryNamed(word, scan)) ?? items[0];
34202
+ if (/^[A-Za-z_]\w*$/u.test(name) && item !== undefined)
34203
+ scan.vars.set(name, expand(item, scan.vars));
34204
+ return;
34205
+ }
34206
+ const read = raw.indexOf("read");
34207
+ if (read < 0 || !raw.slice(0, read).some((word) => word === "while" || word === "until"))
34208
+ return;
34209
+ const fed = after.find((segment) => segment.words[0] === "done")?.stdin?.[0];
34210
+ const line = fed?.split(`
34211
+ `)[0]?.trim();
34212
+ const name = raw.slice(read + 1).find((word) => /^[A-Za-z_]\w*$/u.test(word));
34213
+ if (name && line)
34214
+ scan.vars.set(name, line);
34215
+ };
34216
+ var segmentEntry = (segment, words, dialect, scan, fed) => {
34217
+ const verb = baseName3(words[0] ?? "");
34218
+ if (["cd", "pushd", "chdir", "set-location", "sl"].includes(verb)) {
34219
+ const target = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
34220
+ const moved = target === undefined ? userHome(process.env) : expand(target, scan.vars);
34221
+ scan.dir = moved === "-" || /[$`]/u.test(moved) ? null : path58.isAbsolute(moved) ? moved : scan.dir && path58.resolve(scan.dir, moved);
34222
+ if (scan.dir === null)
34223
+ scan.vars.delete("PWD");
34224
+ else
34225
+ scan.vars.set("PWD", scan.dir);
34226
+ return null;
34227
+ }
34228
+ if (verb === "popd") {
34229
+ scan.dir = null;
34230
+ return null;
34231
+ }
34232
+ const declares = ["export", "declare", "typeset", "local", "readonly"].includes(verb);
34233
+ const assigns = declares ? words.slice(1) : words.every((word) => /^[A-Za-z_]\w*=/u.test(word)) ? words : [];
34234
+ for (const word of assigns) {
34235
+ const [name = "", value] = word.split(/=(.*)/su);
34236
+ if (value !== undefined && /^[A-Za-z_]\w*$/u.test(name))
34237
+ scan.vars.set(name, expand(value.replace(/^(['"])(.*)\1$/su, "$2"), scan.vars));
34238
+ }
34239
+ const options = optionsEntry(declares ? words.slice(1) : words, scan);
34240
+ if (options)
34241
+ return options;
34242
+ if (verb === "exec" && words.slice(1).every((word) => /^\d+$/u.test(word))) {
34243
+ for (const input of segment.inputs ?? [])
34244
+ if (entryNamed(input, scan))
34245
+ for (const fd of words.slice(1))
34246
+ scan.fds.add(fd);
34247
+ }
34248
+ const inputs = segment.inputs ?? [];
34249
+ const entry = runsEntry(words, inputs, scan) ?? expandedCommand(words, scan) ?? opaqueEntry(words, inputs, { ...scan, fed });
34250
+ if (entry)
34251
+ return entry;
34252
+ if (segment.pipe)
34253
+ scan.fed = words.slice(1).flatMap((word) => word.split(TOKENS2)).map((token) => token ? tokenEntry(token, scan) : null).find(Boolean) ?? null;
34254
+ noteLink(words, scan);
34255
+ if (scan.depth >= 4)
34256
+ return null;
34257
+ const nested = (script) => scanCommand(script, dialect, {
34258
+ ...scan,
34259
+ vars: new Map(scan.vars),
34260
+ fed: null,
34261
+ depth: scan.depth + 1
34262
+ });
34263
+ const scripts = [...segment.subs ?? []];
34264
+ const script = shellScript2(words) ?? cmdScript2(words) ?? workitScript(words);
34265
+ if (script)
34266
+ scripts.push(script);
34267
+ if (!script && /^(?:ba|z|da|k)?sh$/u.test(verb) && words.slice(1).every((word) => word.startsWith("-")) || verb === "at" || verb === "batch")
34268
+ scripts.push(...segment.stdin ?? []);
34269
+ for (const text of scripts) {
34270
+ const hit = nested(text);
34271
+ if (hit)
34272
+ return hit;
34273
+ }
34274
+ return null;
34275
+ };
34276
+ var cmdScript2 = (words) => {
34277
+ const name = baseName3(words[0] ?? "");
34278
+ if (!/^(?:cmd|pwsh|powershell)$/u.test(name))
34279
+ return null;
34280
+ const flag = words.findIndex((word, at) => at > 0 && /^[/-](?:c|k|command)$/iu.test(word));
34281
+ return flag < 0 ? null : words.slice(flag + 1).join(" ").replaceAll("\\", "/") || null;
34282
+ };
34283
+ var workitScript = (words) => {
34284
+ if (!/^workit(?:-cli)?$/u.test(baseName3(words[0] ?? "")))
34285
+ return null;
34286
+ const dash = words.indexOf("--");
34287
+ return dash < 0 ? null : words.slice(dash + 1).join(" ") || null;
34288
+ };
34289
+ var substitutions2 = (command) => {
34290
+ const found = [];
34291
+ for (let at = command.indexOf("$(");at >= 0 && found.length < 32; at = command.indexOf("$(", at + 1)) {
34292
+ if (command[at + 2] === "(")
34293
+ continue;
34294
+ let depth = 1;
34295
+ let end = at + 2;
34296
+ for (;end < command.length && depth > 0; end += 1)
34297
+ if (command[end] === "(")
34298
+ depth += 1;
34299
+ else if (command[end] === ")")
34300
+ depth -= 1;
34301
+ found.push(command.slice(at + 2, end - 1));
34302
+ }
34303
+ return found;
34304
+ };
34305
+ var hookEntryRun = (cwd, command, dialect = "posix") => {
34306
+ const scan = (text) => scanCommand(text, dialect, {
34307
+ dir: cwd,
34308
+ vars: new Map([["PWD", cwd]]),
34309
+ links: new Set,
34310
+ fds: new Set,
34311
+ fed: null,
34312
+ depth: 0
34313
+ });
34314
+ const texts = dialect === "posix" && /[A-Za-z]:\\/u.test(command) ? [command, command.replaceAll("\\", "/")] : [command];
34315
+ for (const text of texts) {
34316
+ const hit = scan(text) ?? substitutions2(text).map(scan).find(Boolean);
34317
+ if (hit)
34318
+ return hit;
34319
+ }
34320
+ return null;
34321
+ };
34322
+ 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).`;
33723
34323
 
33724
34324
  // packages/workit-core/src/hooks/identity-env.ts
33725
34325
  var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
@@ -33904,7 +34504,7 @@ var loginScript = (words) => {
33904
34504
  }
33905
34505
  return null;
33906
34506
  };
33907
- var scanCommand = (command, dialect, depth, scan) => {
34507
+ var scanCommand2 = (command, dialect, depth, scan) => {
33908
34508
  let segments;
33909
34509
  try {
33910
34510
  segments = segmentsOf(command, dialect);
@@ -33932,7 +34532,7 @@ var scanCommand = (command, dialect, depth, scan) => {
33932
34532
  commandAt(words, scan, expanded, at);
33933
34533
  const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
33934
34534
  if (script)
33935
- scanCommand(script, dialect, depth + 1, scan);
34535
+ scanCommand2(script, dialect, depth + 1, scan);
33936
34536
  }
33937
34537
  };
33938
34538
  var identityEnvChange = (command, dialect = "posix") => {
@@ -33941,7 +34541,7 @@ var identityEnvChange = (command, dialect = "posix") => {
33941
34541
  if (dialect === "powershell")
33942
34542
  return POWERSHELL.exec(command)?.[0] ?? (/\bworkit\b/iu.test(command) ? POWERSHELL_HOST.exec(command)?.[0] ?? null : null);
33943
34543
  const scan = { hit: null, hostHit: null, risky: null, runs: false };
33944
- scanCommand(command, dialect, 0, scan);
34544
+ scanCommand2(command, dialect, 0, scan);
33945
34545
  return scan.hit ?? (scan.runs ? scan.hostHit ?? scan.risky : null);
33946
34546
  };
33947
34547
  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).`;
@@ -34137,6 +34737,9 @@ function decide(input, deps) {
34137
34737
  const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) : NONE6;
34138
34738
  if (raw.kind === "deny")
34139
34739
  return raw;
34740
+ const entry = canDeny ? hookEntryRun(input.cwd, event.command, event.dialect) : null;
34741
+ if (entry)
34742
+ return { kind: "deny", reason: hookEntryDeny(entry), unblock: null };
34140
34743
  const owner = role === "judge" ? null : liveOwner(input, descriptor.transport);
34141
34744
  const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, owner, event.dialect) : NONE6;
34142
34745
  if (gate.kind === "deny")
@@ -34279,10 +34882,10 @@ var modelKey = (model) => {
34279
34882
  // packages/workit-core/src/hooks/budget-signal.ts
34280
34883
  import { createHash as createHash25 } from "node:crypto";
34281
34884
  import fs36 from "node:fs";
34282
- import path57 from "node:path";
34885
+ import path59 from "node:path";
34283
34886
  var hash3 = (text) => createHash25("sha256").update(text).digest("hex").slice(0, 32);
34284
- var budgetDir = (store) => path57.join(store, "budget");
34285
- var agentBase = (store, session, agentId) => path57.join(budgetDir(store), hash3(`${session}\x00${agentId ?? ""}`));
34887
+ var budgetDir = (store) => path59.join(store, "budget");
34888
+ var agentBase = (store, session, agentId) => path59.join(budgetDir(store), hash3(`${session}\x00${agentId ?? ""}`));
34286
34889
  var spawnBudget = (prompt) => {
34287
34890
  const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
34288
34891
  const n = found ? Number(found[1]) : NaN;
@@ -34302,8 +34905,8 @@ var startBudget = (store, session, agentId, n) => {
34302
34905
  const cutoff = Date.now() - 604800000;
34303
34906
  for (const name of fs36.readdirSync(dir))
34304
34907
  try {
34305
- if (fs36.statSync(path57.join(dir, name)).mtimeMs < cutoff)
34306
- fs36.rmSync(path57.join(dir, name));
34908
+ if (fs36.statSync(path59.join(dir, name)).mtimeMs < cutoff)
34909
+ fs36.rmSync(path59.join(dir, name));
34307
34910
  } catch {}
34308
34911
  const base = agentBase(store, session, agentId);
34309
34912
  fs36.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
@@ -34756,14 +35359,14 @@ var observeToolResult = (event, ctx) => {
34756
35359
  var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? null : promptNudge(hookInput(ctx, { kind: "context.turn", prompt }), prompt);
34757
35360
 
34758
35361
  // packages/workit-pi/src/launches.ts
34759
- import { mkdirSync as mkdirSync8, readFileSync as readFileSync16, readdirSync as readdirSync8, rmSync as rmSync4, writeFileSync as writeFileSync7 } from "node:fs";
35362
+ import { mkdirSync as mkdirSync8, readFileSync as readFileSync17, readdirSync as readdirSync9, rmSync as rmSync4, writeFileSync as writeFileSync7 } from "node:fs";
34760
35363
  import os13 from "node:os";
34761
- import path58 from "node:path";
35364
+ import path60 from "node:path";
34762
35365
  var launchDir = (root) => {
34763
35366
  const location = resolveStore(root);
34764
- return location instanceof Error ? null : path58.join(location.dir, "pi-launches");
35367
+ return location instanceof Error ? null : path60.join(location.dir, "pi-launches");
34765
35368
  };
34766
- var fileFor = (dir, workerId) => path58.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
35369
+ var fileFor = (dir, workerId) => path60.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
34767
35370
  var recordLaunch = (root, attempt) => {
34768
35371
  const dir = launchDir(root);
34769
35372
  if (!dir)
@@ -34802,14 +35405,14 @@ var abandonedLaunches = (root) => {
34802
35405
  return [];
34803
35406
  let names;
34804
35407
  try {
34805
- names = readdirSync8(dir);
35408
+ names = readdirSync9(dir);
34806
35409
  } catch {
34807
35410
  return [];
34808
35411
  }
34809
35412
  const found = [];
34810
35413
  for (const name of names) {
34811
35414
  try {
34812
- const attempt = JSON.parse(readFileSync16(path58.join(dir, name), "utf8"));
35415
+ const attempt = JSON.parse(readFileSync17(path60.join(dir, name), "utf8"));
34813
35416
  if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
34814
35417
  if (!alive(attempt))
34815
35418
  found.push(attempt);