@workit-dev/pi 1.8.1 → 1.9.0

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 +608 -38
  2. package/package.json +1 -1
package/dist/workit.js CHANGED
@@ -19138,7 +19138,9 @@ var tokenize = (command, dialect) => {
19138
19138
  heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
19139
19139
  else if (pending === "herestring")
19140
19140
  (current.stdin ??= []).push(text);
19141
- else if (pending !== "input") {
19141
+ else if (pending === "input")
19142
+ (current.inputs ??= []).push(text);
19143
+ else {
19142
19144
  const at = current.words.length;
19143
19145
  current.words.push(...MARKERS.test(word) ? expandBraces(word) : [word]);
19144
19146
  if (expanding || !posix && word.startsWith("@"))
@@ -25485,7 +25487,7 @@ var splitDenial = (plan) => ({
25485
25487
  unblock: plan.unblock
25486
25488
  });
25487
25489
  // packages/workit-core/src/hooks/write-gate.ts
25488
- import { existsSync as existsSync13, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
25490
+ import { existsSync as existsSync13, readdirSync as readdirSync5, readFileSync as readFileSync11, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
25489
25491
  import os9 from "node:os";
25490
25492
  import path40 from "node:path";
25491
25493
 
@@ -25751,9 +25753,9 @@ var editsOf = (input) => {
25751
25753
  case "cp":
25752
25754
  case "ln":
25753
25755
  case "install": {
25754
- const target = args.indexOf("-t");
25755
- if (target >= 0)
25756
- return args[target + 1] ? [args[target + 1]] : null;
25756
+ const into = valueOf(args, /^(?:-t|--target-directory=?)(.*)$/s);
25757
+ if (into !== undefined)
25758
+ return [into];
25757
25759
  const last = operands(args).at(-1);
25758
25760
  return last ? [last] : null;
25759
25761
  }
@@ -25807,6 +25809,84 @@ var editsOf = (input) => {
25807
25809
  return [];
25808
25810
  }
25809
25811
  };
25812
+ var WRAPPERS2 = {
25813
+ sudo: "ugCDhpRrTtU",
25814
+ doas: "uC",
25815
+ env: "uCS",
25816
+ nice: "n",
25817
+ ionice: "cnp",
25818
+ timeout: "sk",
25819
+ stdbuf: "ioe",
25820
+ time: "fo",
25821
+ nohup: "",
25822
+ command: "",
25823
+ exec: "a",
25824
+ setsid: "",
25825
+ builtin: "",
25826
+ "!": "",
25827
+ npx: "p",
25828
+ bunx: "p"
25829
+ };
25830
+ var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
25831
+ var isConfigDir = (file) => configDirs().some((dir) => canonical3(dir) === canonical3(file));
25832
+ var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test(path40.relative(canonical3(resolveStateDir()), canonical3(file)));
25833
+ 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)$/;
25834
+ var MUTATING_CALLS = /^(?:renames?(?:Sync)?|move|copy(?:2|file|tree|File)?(?:Sync)?|cp(?:Sync)?|rm(?:tree|dir|Sync|dirSync)?|unlink(?:Sync)?|remove(?:dirs)?|mkdirs?(?:Sync)?|makedirs|mkdtemp(?:Sync)?|(?:sym|hard)?link(?:Sync|_to)?|write\w*|append\w*|truncate(?:Sync)?|ch(?:mod|own)(?:Sync)?|touch|open(?:Sync)?|dump|save|extractall|unpack_archive|put_contents|mv|FileUtils)$/;
25835
+ var PATH_CALLS = /^(?:join|resolve|normalize|abspath|expanduser|expandvars|Path|PurePath|fspath)$/;
25836
+ var readsRoot = (text, at) => {
25837
+ let call;
25838
+ for (let index = at, depth = 0;index > 0 && call === undefined; index--) {
25839
+ const char = text[index - 1];
25840
+ if (char === ")")
25841
+ depth++;
25842
+ else if (char === "(" && depth-- === 0)
25843
+ call = /([\w$]+)\s*$/.exec(text.slice(0, index - 1))?.[1] ?? "";
25844
+ else if (depth <= 0 && /[;\n]/.test(char))
25845
+ break;
25846
+ }
25847
+ if (call !== undefined && READ_CALLS.test(call))
25848
+ return true;
25849
+ if (call !== undefined && !PATH_CALLS.test(call))
25850
+ return false;
25851
+ return ![...text.matchAll(/([\w$]+)\s*\(/g)].some(([, name]) => MUTATING_CALLS.test(name));
25852
+ };
25853
+ var inertEdit = (command) => command.split("|").every((part) => /^:?(?:se(?:t)?|sy(?:ntax)?|colo(?:rscheme)?)(?:\s|$)|^[/?][^/?]*[/?]?$|^\d+$/.test(part.trim()));
25854
+ var SCRIPT_OPTIONS = [
25855
+ [/^(?:(?:ba|z|k|da)?sh|source|\.)$/, /^(?:[-+][oO]|--(?:rcfile|init-file))$/],
25856
+ [/^python/, /^-[WXQ]$/],
25857
+ [
25858
+ /./,
25859
+ /^(?:-[rCI]|--(?:require|import|(?:experimental-)?loader|preload|input-type|conditions|title|cwd|tsconfig|project|env-file|config))$/
25860
+ ]
25861
+ ];
25862
+ var PRELOAD = /^(?:-r|--(?:require|import|(?:experimental-)?loader|preload|rcfile|init-file))$/;
25863
+ var scriptArgs = (verb, args) => {
25864
+ const takes = SCRIPT_OPTIONS.find(([family]) => family.test(verb))?.[1] ?? /^$/;
25865
+ const preloads = [];
25866
+ for (let at = 0;at < args.length; at++) {
25867
+ const [option, value] = args[at].split(/=(.*)/s);
25868
+ if (value !== undefined && PRELOAD.test(option))
25869
+ preloads.push(value);
25870
+ else if (/^-[mce]$|^--(?:eval|print)$/.test(option))
25871
+ break;
25872
+ else if (takes.test(option)) {
25873
+ if (PRELOAD.test(option))
25874
+ preloads.push(args[at + 1] ?? "");
25875
+ at++;
25876
+ } else if (!/^[-+]/.test(option) && option !== "run")
25877
+ return { named: args[at], preloads };
25878
+ }
25879
+ return { preloads };
25880
+ };
25881
+ var unwrapped = (words) => {
25882
+ let at = 0;
25883
+ for (let takes;(takes = WRAPPERS2[words[at]?.split(/[\\/]/).at(-1) ?? ""]) !== undefined; ) {
25884
+ at++;
25885
+ while (at < words.length && /^-|^\w+=|^\d[\w.]*$/.test(words[at]))
25886
+ at += words[at].length === 2 && words[at][0] === "-" && takes.includes(words[at][1]) ? 2 : 1;
25887
+ }
25888
+ return at ? words.slice(at) : null;
25889
+ };
25810
25890
  var shellScript2 = (words) => {
25811
25891
  if (!SCRIPT_SHELLS.has((words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()))
25812
25892
  return null;
@@ -26051,9 +26131,8 @@ var gitOutputs = (args) => {
26051
26131
  const under = (file) => file === "." ? `${base}/${OPAQUE_TARGET}git` : /^[/~$]|^[A-Za-z]:[\\/]/.test(file) ? file : `${base}/${file}`;
26052
26132
  return files.length ? files.map(under) : null;
26053
26133
  };
26054
- var pathsIn = (text) => [
26055
- ...text.matchAll(/(?<![\w.~:/$-])(?:~\/|\/|[A-Za-z]:\/|\.\.(?:\/|$))[^\s'"`$),;:*?<>|\\[\]{}]*/g)
26056
- ].map((match) => match[0]);
26134
+ var PATHS = /(?<![\w.~:/$-])(?:~\/|\/|[A-Za-z]:\/|\.\.(?:\/|$))[^\s'"`$),;:*?<>|\\[\]{}]*/g;
26135
+ var pathsIn = (text) => [...text.matchAll(PATHS)].map((match) => match[0]);
26057
26136
  var linkSources = (args, at) => {
26058
26137
  const names = operands([...args]);
26059
26138
  const into = args.indexOf("-t");
@@ -26180,12 +26259,12 @@ var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
26180
26259
  var PUSHD2 = new Set(["pushd", "push-location"]);
26181
26260
  var POPD2 = new Set(["popd", "pop-location"]);
26182
26261
  var UNKNOWN_DIR = path40.resolve(path40.parse(process.cwd()).root, ".workit-unknown-dir");
26183
- var cdInto = (dir, words, strict = false, vars = new Map) => {
26262
+ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
26184
26263
  const lost = strict ? UNKNOWN_DIR : undefined;
26185
26264
  const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
26186
26265
  const named = found === undefined ? undefined : expandVars(found, vars);
26187
26266
  const target = named === undefined ? undefined : homeExpanded(named);
26188
- if (target === "-" || target && /^~|[$`*?]/.test(target))
26267
+ if (target === "-" || target && (globs ? /^~|[$`]/ : /^~|[$`*?]/).test(target))
26189
26268
  return lost;
26190
26269
  if (dir === undefined)
26191
26270
  return lost;
@@ -26208,7 +26287,8 @@ var assignmentsOf = (words) => {
26208
26287
  var commandWords = (words) => {
26209
26288
  let start = 0;
26210
26289
  while (start < words.length && COMPOUND.has(words[start]))
26211
- start++;
26290
+ if (words[start++] === "function")
26291
+ start++;
26212
26292
  return words.slice(start);
26213
26293
  };
26214
26294
  var REBINDS_ANY = new Set([
@@ -26360,7 +26440,8 @@ var expansions = (text, vars, loops) => {
26360
26440
  last = match.index + match[0].length;
26361
26441
  const value = vars.get(name);
26362
26442
  const values = loops.get(name) ?? (value === undefined ? null : [value]);
26363
- const applied = values?.map((item) => applyOperator(item, match[2] ?? ""));
26443
+ const fallback = /^:?[-=](.*)$/s.exec(match[2] ?? "")?.[1];
26444
+ const applied = values?.flatMap((item) => fallback === undefined ? [applyOperator(item, match[2] ?? "")] : item === "" ? expansions(fallback, vars, loops) : [item]);
26364
26445
  const fits = applied && results.length * applied.length <= MAX_EXPANSIONS2;
26365
26446
  results = fits && applied.every((item) => item !== null) ? results.flatMap((prefix) => applied.map((item) => prefix + literal + item)) : results.map((prefix) => prefix + literal + match[0]);
26366
26447
  }
@@ -26406,6 +26487,7 @@ var homeExpanded = (file) => {
26406
26487
  };
26407
26488
  var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherited = new Map) => {
26408
26489
  const targets = [];
26490
+ const written = new Map;
26409
26491
  let dir = cwd;
26410
26492
  let stack = [];
26411
26493
  const segments = segmentsOf(command, dialect);
@@ -26468,6 +26550,8 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26468
26550
  continue;
26469
26551
  }
26470
26552
  const body = commandWords(segment.words);
26553
+ const before = segments[segments.indexOf(segment) - 1];
26554
+ const feeder = before?.pipe ? before : undefined;
26471
26555
  const keywords = segment.words.length - body.length;
26472
26556
  for (const keyword of segment.words.slice(0, keywords))
26473
26557
  if (OPENS.has(keyword))
@@ -26521,7 +26605,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26521
26605
  }
26522
26606
  const plain = !segment.conditional;
26523
26607
  if (CD2.has(name)) {
26524
- dir = cdInto(dir, words, strict, vars);
26608
+ dir = cdInto(dir, words, Boolean(strict), vars, strict === "registry");
26525
26609
  moved(plain);
26526
26610
  continue;
26527
26611
  }
@@ -26532,7 +26616,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26532
26616
  }
26533
26617
  if (PUSHD2.has(name)) {
26534
26618
  stack.push(dir);
26535
- dir = cdInto(dir, words, strict, vars);
26619
+ dir = cdInto(dir, words, Boolean(strict), vars, strict === "registry");
26536
26620
  moved(plain);
26537
26621
  continue;
26538
26622
  }
@@ -26541,15 +26625,94 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26541
26625
  moved(plain);
26542
26626
  continue;
26543
26627
  }
26544
- const inner = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
26628
+ const literal = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
26629
+ const held = literal !== null && strict === "registry" ? expansions(literal, vars, loops) : [];
26630
+ const inner = held.length === 1 ? held[0] : literal;
26545
26631
  const unPwd = () => new Map([...vars].filter(([key]) => key !== "PWD"));
26546
26632
  if (inner !== null && dir !== undefined)
26547
26633
  for (const runIn of workitRunDir(dir, words, atAll))
26548
26634
  targets.push(...segmentTargets(runIn, inner, "posix", depth + 1, strict, runIn === dir ? vars : unPwd()));
26635
+ const bare = strict === "registry" && depth < 4 ? unwrapped(words) : null;
26636
+ if (bare?.length && dir !== undefined)
26637
+ targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
26638
+ if (strict === "registry" && dir !== undefined && depth < 4) {
26639
+ const run = words.slice(Math.max(0, words.findIndex((word) => !PREFIXES2.has(word))));
26640
+ const [verb = "", ...args] = run.map((word, index) => index ? word : (word.split(/[\\/]/).at(-1) ?? "").toLowerCase());
26641
+ const fed = segment.stdin?.join(`
26642
+ `);
26643
+ if (fed !== undefined)
26644
+ for (const file of segment.redirects)
26645
+ for (const into of atAll(file))
26646
+ written.set(into, fed);
26647
+ const read = (file) => atAll(file).flatMap((script) => {
26648
+ const made = written.get(script);
26649
+ if (made !== undefined)
26650
+ return [made];
26651
+ try {
26652
+ const stat = statSync4(script);
26653
+ const text = stat.isFile() && stat.size <= 262144 ? readFileSync11(script, "utf8") : "\x00";
26654
+ return text.includes("\x00") ? [] : [text];
26655
+ } catch {
26656
+ return [];
26657
+ }
26658
+ });
26659
+ const { named: operand, preloads } = scriptArgs(verb, args);
26660
+ const named = operand === "/dev/stdin" ? undefined : operand;
26661
+ const maker = feeder ? commandWords(feeder.words) : [];
26662
+ const [format = "", ...values] = maker.slice(1);
26663
+ let filled = 0;
26664
+ const printed = format.replace(/%[sbq]/g, () => values[filled++] ?? "");
26665
+ const piped = /^(?:echo|printf)$/.test(maker[0] ?? "") ? [[maker[0] === "printf" ? printed : format, ...values].join(`
26666
+ `).replaceAll("\\n", `
26667
+ `)] : maker[0] === "cat" ? [...feeder?.stdin ?? [], ...operands(maker.slice(1)).flatMap(read)] : [];
26668
+ const inputs = (segment.inputs ?? []).filter((file) => file !== "/dev/null");
26669
+ const shells = verb === "eval" ? [args.join(" ")] : verb === "trap" ? args.slice(0, 1) : verb === "alias" ? args.map((arg) => arg.replace(/^[^=]*=/, "")) : [];
26670
+ const others = [];
26671
+ if (SCRIPT_SHELLS.has(verb) || verb === "." || verb === "source") {
26672
+ if (named === undefined && shellScript2(run) === null)
26673
+ shells.push(...segment.stdin ?? [], ...inputs.flatMap(read), ...piped);
26674
+ else if (named !== undefined && shellScript2(run) === null)
26675
+ shells.push(...read(named));
26676
+ shells.push(...preloads.flatMap(read));
26677
+ } else if (INTERPRETERS.test(verb)) {
26678
+ const code = args.findIndex((arg) => /^-[a-zA-Z]*[ce]$|^--eval$/.test(arg));
26679
+ if (code >= 0)
26680
+ others.push(...expansions(args[code + 1] ?? "", vars, loops));
26681
+ others.push(...named === undefined ? [...segment.stdin ?? [], ...inputs.flatMap(read), ...piped] : read(named), ...preloads.flatMap(read));
26682
+ } else if (/[\\/]/.test(run[0] ?? ""))
26683
+ for (const text of read(run[0]))
26684
+ (/^#!.*\b(?:python|node|bun|deno|ruby|perl|php)/.test(text) ? others : shells).push(text);
26685
+ for (const script of shells)
26686
+ targets.push(...segmentTargets(dir, script, "posix", depth + 1, strict, vars));
26687
+ for (const raw of others) {
26688
+ const text = raw.replace(/^\s*(?:#(?!!)|\/\/|\/?\*).*$/gm, "");
26689
+ const joined = [
26690
+ ...text.matchAll(/(?:["'][^"'\s,*?[]+["']\s*[,/+]\s*)+["'][^"'\s,*?[]+["']/g)
26691
+ ].map(({ 0: literals, index }) => ({
26692
+ word: literals.replace(/["']\s*[,/+]\s*["']/g, "/").replace(/["']/g, ""),
26693
+ index
26694
+ }));
26695
+ const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
26696
+ const under = (word) => homes ? [path40.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
26697
+ const found = [
26698
+ ...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
26699
+ ...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
26700
+ ];
26701
+ for (const { file, index } of found)
26702
+ if (!isRoot(file) || !readsRoot(text, index))
26703
+ targets.push(file);
26704
+ }
26705
+ 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"))))
26706
+ for (const file of operands(args))
26707
+ targets.push(...atAll(file));
26708
+ if (verb === "cp" && args.some((arg) => /^-[a-zA-Z]*l|^--link$/.test(arg)))
26709
+ for (const file of operands(args).slice(0, -1))
26710
+ targets.push(...atAll(file));
26711
+ }
26549
26712
  if (strict && dir !== undefined) {
26550
26713
  const runIn = dir;
26551
26714
  for (const sub of depth < 4 ? segment.subs ?? [] : [])
26552
- targets.push(...segmentTargets(runIn, sub, dialect, depth + 1, true, vars));
26715
+ targets.push(...segmentTargets(runIn, sub, dialect, depth + 1, strict, vars));
26553
26716
  const expanding = new Set(segment.expands ?? []);
26554
26717
  const scriptOf = (index) => {
26555
26718
  const word = body[index];
@@ -26565,12 +26728,15 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26565
26728
  if (runner !== undefined && expanding.has(keywords + lead + ran) && unresolvedRefs(homeExpanded(runner)).length > 0)
26566
26729
  targets.push(unknownVarTarget(runner));
26567
26730
  const here = segment.unanalyzable ? DIR_TARGET : `${OPAQUE_TARGET}${encodeURIComponent(runner?.split(/[\\/]/).at(-1) ?? "a command")}`;
26731
+ const quiet = strict === "registry" && INTERPRETERS.test(runner?.split(/[\\/]/).at(-1) ?? "");
26568
26732
  for (const file of opaque ?? [])
26569
26733
  for (const resolved of atAll(file))
26570
- targets.push(file === "." ? path40.join(resolved, here) : resolved);
26734
+ if (!quiet || !isRoot(resolved))
26735
+ targets.push(file === "." ? path40.join(resolved, here) : resolved);
26571
26736
  const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
26572
- if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)))
26573
- targets.push(...linkSources(words.slice(ln + 1), at));
26737
+ const lnArgs = words.slice(ln + 1);
26738
+ if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)) && (strict !== "registry" || !lnArgs.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg))))
26739
+ targets.push(...linkSources(lnArgs, at));
26574
26740
  }
26575
26741
  for (const file of segment.redirects)
26576
26742
  if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file))
@@ -26605,11 +26771,14 @@ var workitCwd = (dir, args, resolve) => {
26605
26771
  };
26606
26772
  var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
26607
26773
  try {
26774
+ 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]] ?? ""]) : []);
26608
26775
  return [
26609
- ...segmentTargets(cwd, command, dialect, 0, strict),
26776
+ ...segmentTargets(cwd, command, dialect, 0, strict, env),
26610
26777
  ...gitMutationDirs(cwd, command, dialect).map((dir) => path40.join(dir, DIR_TARGET))
26611
26778
  ];
26612
- } catch {
26779
+ } catch (error) {
26780
+ if (strict === "registry")
26781
+ throw error;
26613
26782
  return [];
26614
26783
  }
26615
26784
  };
@@ -26667,12 +26836,79 @@ var claimAll = (owner, targets, deps) => {
26667
26836
  };
26668
26837
  var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path40.resolve(cwd, file)) : [path40.join(cwd, DIR_TARGET)];
26669
26838
  var configDirs = () => [resolveConfigDir(), grantsDir()];
26839
+ var globbed = (cwd, target, state, configs) => {
26840
+ if (!/[*?[]/.test(target))
26841
+ return [];
26842
+ const raw = path40.resolve(cwd, target).split(path40.sep);
26843
+ const literal = raw.findIndex((part) => /[*?[]/.test(part));
26844
+ const pattern = [
26845
+ ...canonical3(raw.slice(0, literal).join(path40.sep) || path40.sep).replace(/[\\/]+$/, "").split(path40.sep),
26846
+ ...raw.slice(literal)
26847
+ ];
26848
+ const segment = (glob, name) => {
26849
+ try {
26850
+ return new RegExp(`^${glob.startsWith(".") ? "" : "(?!\\.)"}${glob.replace(/[.+^$(){}|\\]/g, "\\$&").replace(/\[!/g, "[^").replaceAll("*", ".*").replaceAll("?", ".")}$`, CASE_INSENSITIVE ? "i" : "").test(name);
26851
+ } catch {
26852
+ return false;
26853
+ }
26854
+ };
26855
+ const hit = (file, below) => {
26856
+ const parts = canonical3(file).split(path40.sep);
26857
+ return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
26858
+ };
26859
+ let roots = [];
26860
+ try {
26861
+ roots = readdirSync5(state).filter((name) => /^(?:issued|approvals$)/.test(name));
26862
+ } catch {}
26863
+ return [
26864
+ ...roots.map((name) => path40.join(state, name)).filter((root) => hit(root, true)),
26865
+ ...configs.flatMap((dir) => [dir, path40.join(dir, "workspaces.json")]).filter((file) => hit(file, false))
26866
+ ];
26867
+ };
26868
+ var guardedInodes = (state, configs) => {
26869
+ const seen = new Map;
26870
+ let budget = 2000;
26871
+ const add = (file, registry) => {
26872
+ if (budget-- <= 0)
26873
+ return;
26874
+ const stat = statSync4(file, { throwIfNoEntry: false });
26875
+ if (stat?.isFile())
26876
+ seen.set(`${stat.dev}:${stat.ino}`, registry);
26877
+ else if (stat?.isDirectory())
26878
+ for (const name of readdirSync5(file))
26879
+ add(path40.join(file, name), registry);
26880
+ };
26881
+ try {
26882
+ for (const dir of configs)
26883
+ add(path40.join(dir, "workspaces.json"), "grants");
26884
+ for (const name of readdirSync5(state))
26885
+ if (/^(?:issued|approvals$)/.test(name))
26886
+ add(path40.join(state, name), name === "approvals" ? "approvals" : "issued");
26887
+ } catch {}
26888
+ return seen;
26889
+ };
26890
+ var hardLinked = (file, state, configs, inodes) => {
26891
+ try {
26892
+ const stat = statSync4(file, { throwIfNoEntry: false });
26893
+ if (!stat?.isFile() || stat.nlink < 2 || !stat.ino)
26894
+ return;
26895
+ inodes.map ??= guardedInodes(state, configs);
26896
+ return inodes.map.get(`${stat.dev}:${stat.ino}`);
26897
+ } catch {
26898
+ return;
26899
+ }
26900
+ };
26670
26901
  var registryTarget = (cwd, targets) => {
26671
26902
  const state = resolveStateDir();
26672
26903
  const configs = configDirs();
26904
+ const inodes = {};
26673
26905
  for (const target of targets) {
26674
26906
  const file = homeExpanded(target);
26675
- const registry = underRegistry(state, cwd, file, process.platform, canonical3) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical3)) ? "grants" : null);
26907
+ const glob = globbed(cwd, file, state, configs)[0];
26908
+ const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
26909
+ if (viaGlob)
26910
+ return { file: target, registry: viaGlob.registry };
26911
+ const registry = hardLinked(path40.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical3) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical3)) ? "grants" : null);
26676
26912
  if (registry)
26677
26913
  return { file: target, registry };
26678
26914
  }
@@ -26694,7 +26930,7 @@ var underRegistry = (state, cwd, target, platform = process.platform, real = (fi
26694
26930
  };
26695
26931
  var underConfig = (dir, cwd, target, platform = process.platform, real = (file) => file) => {
26696
26932
  const parts = partsUnder(dir, cwd, target, platform, real);
26697
- return parts?.length === 1 && (parts[0] === "" || parts[0] === "workspaces.json");
26933
+ return parts?.length === 1 && ["", "workspaces.json", DIR_TARGET].includes(parts[0]);
26698
26934
  };
26699
26935
  var unquotedWindowsRegistry = (command, platform = process.platform) => {
26700
26936
  if (platform !== "win32" || !command.includes("\\"))
@@ -26702,8 +26938,21 @@ var unquotedWindowsRegistry = (command, platform = process.platform) => {
26702
26938
  const flat = (value) => value.replaceAll("\\", "/").toLowerCase();
26703
26939
  const text = flat(command);
26704
26940
  const state = flat(resolveStateDir());
26705
- const registry = text.includes(`${state}/issued`) ? "issued" : text.includes(`${state}/approvals`) ? "approvals" : configDirs().some((dir) => text.includes(`${flat(dir)}/workspaces.json`)) ? "grants" : null;
26706
- return registry && shellWrites(command).writes ? registry : null;
26941
+ const configs = configDirs().map(flat);
26942
+ const registry = text.includes(`${state}/issued`) ? "issued" : text.includes(`${state}/approvals`) ? "approvals" : configs.some((dir) => text.includes(dir)) ? "grants" : null;
26943
+ if (!registry)
26944
+ return null;
26945
+ const spans = command.replace(/[^\s'"|;&<>()]*\\[^\s'"|;&<>()]*/g, (word) => word.replaceAll("\\", "/"));
26946
+ const writes = shellWrites(spans);
26947
+ const moved = [
26948
+ "",
26949
+ ...[...spans.matchAll(/(?:^|[;&|(]\s*)(?:cd|pushd|chdir)\s+([^\s;&|)]+)/g)].map((match) => `${match[1]}/`)
26950
+ ];
26951
+ const named = (target) => moved.some((dir) => {
26952
+ const at = flat(/^(?:[a-z]:)?\//i.test(target) ? target : dir + target).replace(/\/\.?\//g, "/");
26953
+ return registry === "grants" ? configs.some((cfg) => [cfg, `${cfg}/`, `${cfg}/workspaces.json`].includes(at)) : at.includes(`${state}/${registry}`);
26954
+ });
26955
+ return writes.writes && (writes.targets === null || writes.targets.some(named)) ? registry : null;
26707
26956
  };
26708
26957
  var REGISTRY_DENY = {
26709
26958
  issued: {
@@ -26724,9 +26973,10 @@ var REGISTRY_DENY = {
26724
26973
  };
26725
26974
  var registryDeny = ({ file, registry }) => {
26726
26975
  const { label, what, unblock } = REGISTRY_DENY[registry];
26976
+ const named = path40.basename(file).startsWith(".workit-") ? path40.dirname(file) : file;
26727
26977
  return {
26728
26978
  kind: "deny",
26729
- reason: `workit ${label}: ${file} is under ${what}. ${unblock}`,
26979
+ reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
26730
26980
  unblock
26731
26981
  };
26732
26982
  };
@@ -26748,10 +26998,20 @@ function writeGate(cwd, paths, owner, deps) {
26748
26998
  function shellGate(cwd, command, owner, dialect = "posix", deps) {
26749
26999
  try {
26750
27000
  const windows = unquotedWindowsRegistry(command);
26751
- const forged = registryTarget(cwd, segmentTargets(cwd, command, dialect)) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
27001
+ const forged = registryTarget(cwd, shellMutationTargets(cwd, command, dialect, "registry")) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
26752
27002
  if (forged)
26753
27003
  return registryDeny(forged);
26754
- } catch {}
27004
+ } catch {
27005
+ const text = command.replaceAll("\\", "/").replace(/['"]/g, "").toLowerCase();
27006
+ if (/issued|approvals|workspaces\.json|\.config\/workit|state\/workit/.test(text) || [resolveStateDir(), ...configDirs()].some((dir) => text.includes(dir.replaceAll("\\", "/").toLowerCase()))) {
27007
+ const { unblock } = REGISTRY_DENY.grants;
27008
+ return {
27009
+ kind: "deny",
27010
+ reason: `workit registry guard: Workit could not analyse this command, which names a guarded path; split it into plain commands. ${unblock}`,
27011
+ unblock
27012
+ };
27013
+ }
27014
+ }
26755
27015
  const writes = shellWrites(command);
26756
27016
  let targets = [];
26757
27017
  if (owner)
@@ -27349,7 +27609,7 @@ import path44 from "node:path";
27349
27609
 
27350
27610
  // packages/workit-core/src/approvals/store.ts
27351
27611
  import { createHash as createHash18, randomBytes as randomBytes4 } from "node:crypto";
27352
- import { mkdirSync as mkdirSync6, readdirSync as readdirSync5, readFileSync as readFileSync11 } from "node:fs";
27612
+ import { mkdirSync as mkdirSync6, readdirSync as readdirSync6, readFileSync as readFileSync12 } from "node:fs";
27353
27613
  import path42 from "node:path";
27354
27614
  var REQUEST_TTL_MS = 30 * 60000;
27355
27615
  var GRANT_TTL_MS = 15 * 60000;
@@ -27368,7 +27628,7 @@ var fileOf = (part, id) => path42.join(dirOf(part), `${id}.json`);
27368
27628
  var askedFile = (session, toolUseId) => path42.join(dirOf("asked"), `${createHash18("sha256").update(`${session}\x00${toolUseId}`).digest("hex").slice(0, 32)}.json`);
27369
27629
  var readJson3 = (file) => {
27370
27630
  try {
27371
- const value = JSON.parse(readFileSync11(file, "utf8"));
27631
+ const value = JSON.parse(readFileSync12(file, "utf8"));
27372
27632
  return value !== null && typeof value === "object" ? value : null;
27373
27633
  } catch {
27374
27634
  return null;
@@ -28283,7 +28543,7 @@ function confineImplementerShell(input, command, dialect = "posix") {
28283
28543
  }
28284
28544
  var SCRATCH = ".workit-scratch";
28285
28545
  var SHELL_NAMES = /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/;
28286
- var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php)$/;
28546
+ var INTERPRETERS2 = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php)$/;
28287
28547
  var FED = /^(?:-|\/dev\/stdin|\/dev\/fd\/0|\/proc\/self\/fd\/0)$|^<\(/;
28288
28548
  var LEADS = /^(?:sudo|doas|env|command|builtin|exec|nohup|time|nice|timeout|stdbuf|xargs|busybox|!|\{|if|then|else|elif|do|while|until|\w+=.*|[-\d].*)$/s;
28289
28549
  var RUNS = /^(?:sh|bash|zsh|dash|ksh|mksh|ash|python[\d.]*|node|bun|deno|ruby|perl|php|eval|source|\.|workit)$/;
@@ -28400,7 +28660,7 @@ var judgeRefusal = (command, fed, depth = 0) => {
28400
28660
  }
28401
28661
  }
28402
28662
  }
28403
- if (INTERPRETERS.test(name) && !args.some((arg) => INLINE.test(arg))) {
28663
+ if (INTERPRETERS2.test(name) && !args.some((arg) => INLINE.test(arg))) {
28404
28664
  const operand = args.find((arg, index) => (arg === "-" || !arg.startsWith("-")) && !VALUED.test(args[index - 1] ?? ""));
28405
28665
  if (FED.test(operand ?? "") || operand === undefined && !/^(?:bun|deno)$/.test(name))
28406
28666
  return unseen;
@@ -28752,7 +29012,7 @@ var cdWorkitSplit = (command) => {
28752
29012
  };
28753
29013
 
28754
29014
  // packages/workit-core/src/hooks/model-limit.ts
28755
- import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync6, readSync, statSync as statSync5 } from "node:fs";
29015
+ import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync7, readSync, statSync as statSync5 } from "node:fs";
28756
29016
  import os10 from "node:os";
28757
29017
  import path45 from "node:path";
28758
29018
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
@@ -28952,7 +29212,7 @@ var firstPrompt = (file) => {
28952
29212
  var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
28953
29213
  var listDir = (dir) => {
28954
29214
  try {
28955
- return readdirSync6(dir).map((name) => path45.join(dir, name));
29215
+ return readdirSync7(dir).map((name) => path45.join(dir, name));
28956
29216
  } catch {
28957
29217
  return [];
28958
29218
  }
@@ -29101,6 +29361,313 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
29101
29361
  return agentModelDecision(cwd, checked.input, { change: checked.change, permissionMode });
29102
29362
  };
29103
29363
 
29364
+ // packages/workit-core/src/hooks/ytrack-word.ts
29365
+ var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
29366
+ var namesYtrack = (text) => {
29367
+ const bare = text.replace(/['"\\]/g, "");
29368
+ return YTRACK_WORD.test(bare) || YTRACK_WORD.test(bare.replace(/`/g, ""));
29369
+ };
29370
+
29371
+ // packages/workit-core/src/hooks/ytrack-guard.ts
29372
+ var name2 = (word = "") => (word.split(/[\\/]/).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd)$|@.*$/g, "");
29373
+ var quote2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
29374
+ var minutesOf = (text = "") => {
29375
+ if (/^\d+$/.test(text.trim()))
29376
+ return Number(text) > 0 ? Number(text) : null;
29377
+ let total = 0;
29378
+ const rest = text.replace(/(\d+(?:\.\d+)?)\s*(h|hours?|m|mins?|minutes?)(?![a-z])/gi, (_, n, unit) => {
29379
+ total += Number(n) * (/^h/i.test(unit) ? 60 : 1);
29380
+ return "";
29381
+ });
29382
+ return rest.trim() || !Number.isInteger(total) || total <= 0 ? null : total;
29383
+ };
29384
+ var VALUE = new Set(("--host --body -b --body-file --text --date --duration --type --project -p --summary -s " + "--description --description-file --field --tag --add-tag --remove-tag --assignee --comment " + "--json --jq -X --method -f -F --raw-field --input --fields -q --query --author --since --limit").split(" "));
29385
+ var BARE = new Set("--debug --no-color --paginate --include --dry-run --silent --yes --meeting --help -h".split(" "));
29386
+ var standsAlone = (args, at) => {
29387
+ const before = args[at - 1] ?? "";
29388
+ const end = args.indexOf("--");
29389
+ return (end < 0 || at < end) && (!before.startsWith("-") || before.includes("=") || BARE.has(before));
29390
+ };
29391
+ var flagged = (args, flag) => args.some((arg, at) => flag.test(arg) && standsAlone(args, at));
29392
+ var asksHelp2 = (args) => flagged(args, /^(?:--help|-h)$/);
29393
+ var GROUPS = {
29394
+ issue: "issue",
29395
+ "work-item": "work-item",
29396
+ workitem: "work-item",
29397
+ api: "api"
29398
+ };
29399
+ var ASKS = /^(?:post|put|patch|delete)$/i;
29400
+ var BODY = /^(?:-[fF]|--(?:field|raw-field|input))(?:=|$)|^-[fF]./;
29401
+ var QUIET = /^--(?:debug|no-color|json|jq)$/;
29402
+ var CARRIES = {
29403
+ note: { "--body": "body", "-b": "body", "--body-file": "file" },
29404
+ time: { "--duration": "duration", "--text": "text", "--date": "date" },
29405
+ create: {
29406
+ "--project": "project",
29407
+ "-p": "project",
29408
+ "--summary": "summary",
29409
+ "-s": "summary",
29410
+ "--description": "description",
29411
+ "--description-file": "file"
29412
+ }
29413
+ };
29414
+ var gap = (part) => ({ workit: null, gap: part });
29415
+ var pair = (flag, value) => value.startsWith("-") ? `${flag}=${quote2(value)}` : `${flag} ${quote2(value)}`;
29416
+ var mapWrite = (verb, args) => {
29417
+ const values = {};
29418
+ const operands = [];
29419
+ for (let at = 0;at < args.length; at++) {
29420
+ const arg = args[at];
29421
+ if (!arg.startsWith("-") || arg === "-") {
29422
+ operands.push(arg);
29423
+ continue;
29424
+ }
29425
+ const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
29426
+ const flag = eq > 0 ? arg.slice(0, eq) : arg;
29427
+ const value = eq > 0 ? arg.slice(eq + 1) : VALUE.has(flag) ? args[++at] : undefined;
29428
+ if (QUIET.test(flag))
29429
+ continue;
29430
+ const key = CARRIES[verb][flag];
29431
+ if (!key || value === undefined || key in values)
29432
+ return gap(`\`${flag}\``);
29433
+ if (/[$`]|^~/.test(value))
29434
+ return gap(`the value of \`${flag}\`, which the shell expands when it runs`);
29435
+ values[key] = value;
29436
+ }
29437
+ const [issue, ...more] = operands.slice(2);
29438
+ const v = values;
29439
+ if (verb === "create") {
29440
+ if (issue !== undefined)
29441
+ return gap(`the operand \`${issue}\``);
29442
+ if (v.project === undefined || v.summary === undefined)
29443
+ return gap("a missing --project or --summary");
29444
+ if (v.description !== undefined && v.file !== undefined)
29445
+ return gap("both --description and --description-file");
29446
+ if (v.file === "-")
29447
+ return gap("text read from standard input");
29448
+ return {
29449
+ workit: [
29450
+ "workit youtrack create",
29451
+ pair("--project", v.project),
29452
+ pair("--summary", v.summary),
29453
+ v.description === undefined ? "" : pair("--description", v.description),
29454
+ v.file === undefined ? "" : pair("--file", v.file)
29455
+ ].filter(Boolean).join(" ")
29456
+ };
29457
+ }
29458
+ if (issue === undefined || more.length || !/^[A-Z]+-\d+$/.test(issue))
29459
+ return gap("the issue, which must be one id like ABC-123");
29460
+ if (verb === "note") {
29461
+ if (v.body === undefined === (v.file === undefined))
29462
+ return gap("a comment that needs exactly one of --body or --body-file");
29463
+ if (v.file === "-")
29464
+ return gap("text read from standard input");
29465
+ if (v.body !== undefined && !v.body.trim())
29466
+ return gap("an empty --body");
29467
+ return {
29468
+ workit: `workit youtrack note ${issue} ${v.body === undefined ? pair("--file", v.file) : pair("--markdown", v.body)}`
29469
+ };
29470
+ }
29471
+ const minutes = minutesOf(v.duration);
29472
+ if (minutes === null)
29473
+ return gap(`\`--duration ${v.duration ?? ""}\`, which is no whole number of minutes`);
29474
+ if (v.date !== undefined && !/^(?:auto|\d{4}-\d{2}-\d{2})$/.test(v.date))
29475
+ return gap(`\`--date ${v.date}\``);
29476
+ return {
29477
+ workit: [
29478
+ `workit youtrack time ${issue} --minutes ${minutes}`,
29479
+ v.text === undefined ? "" : pair("--text", v.text),
29480
+ v.date === undefined ? "" : pair("--date", v.date)
29481
+ ].filter(Boolean).join(" ")
29482
+ };
29483
+ };
29484
+ var UNCOVERED = { workit: null, gap: "" };
29485
+ var classify2 = (args) => {
29486
+ if (asksHelp2(args))
29487
+ return null;
29488
+ const lenient = args.filter((arg, at) => !arg.startsWith("-") && !VALUE.has(args[at - 1] ?? ""));
29489
+ const strict = args.filter((arg, at) => !arg.startsWith("-") && standsAlone(args, at));
29490
+ return judge(args, lenient) ?? judge(args, strict);
29491
+ };
29492
+ var judge = (args, words) => {
29493
+ const group = GROUPS[words[0] ?? ""];
29494
+ const verb = words[1] ?? "";
29495
+ if (group === "api") {
29496
+ const methods = args.flatMap((arg, at) => /^(?:-X|--method)$/.test(arg) ? [{ value: args[at + 1] ?? "", alone: standsAlone(args, at) }] : /^(?:-X.|--method=)/.test(arg) ? [{ value: arg.replace(/^(?:-X=?|--method=)/, ""), alone: standsAlone(args, at) }] : []);
29497
+ if (methods.some((method) => ASKS.test(method.value)))
29498
+ return UNCOVERED;
29499
+ if (methods.some((method) => method.alone))
29500
+ return null;
29501
+ return args.some((a) => BODY.test(a)) ? UNCOVERED : null;
29502
+ }
29503
+ if (group === "work-item" && /^(?:add|create)$/.test(verb))
29504
+ return mapWrite("time", args);
29505
+ if (group === "work-item")
29506
+ return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
29507
+ if (group !== "issue")
29508
+ return null;
29509
+ if (verb === "comment")
29510
+ return mapWrite("note", args);
29511
+ if (verb === "create")
29512
+ return mapWrite("create", args);
29513
+ if (verb === "command")
29514
+ return flagged(args, /^--dry-run$/) ? null : UNCOVERED;
29515
+ return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
29516
+ };
29517
+ var SHELLS3 = /^(?:sh|bash|zsh|dash|ksh|ash|mksh|yash|fish)$/;
29518
+ var MAX_DEPTH2 = 4;
29519
+ var READ = new Map;
29520
+ var NOT_PLAIN = gap("a ytrack call that is not a plain command of its own (a wrapper, loop, substitution or script around it can change or repeat it)");
29521
+ var ungrant = (write) => write.workit ? { command: write.command, ...NOT_PLAIN } : write;
29522
+ var ytrackArgs = (line, found, depth, names, plain) => {
29523
+ const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
29524
+ const tail = workitCheckTail(line);
29525
+ if (tail) {
29526
+ inner("script" in tail ? tail.script : tail.argv.map(quote2).join(" "));
29527
+ return true;
29528
+ }
29529
+ const flag = SHELLS3.test(name2(line[0])) ? line.findIndex((word, index) => index > 0 && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(word)) : -1;
29530
+ const script = flag > 0 ? line[flag + 1] : name2(line[0]) === "eval" ? line.slice(1).join(" ") : undefined;
29531
+ if (script !== undefined) {
29532
+ inner(script);
29533
+ return true;
29534
+ }
29535
+ let at = 0;
29536
+ let called = false;
29537
+ const runner = name2(line[0]);
29538
+ if (/^(?:npx|bunx|pnpx)$/.test(runner) || /^(?:p?npm|yarn)$/.test(runner) && /^(?:dlx|exec|x)$/.test(line[1] ?? "")) {
29539
+ at = runner.endsWith("x") ? 1 : 2;
29540
+ for (;line[at]?.startsWith("-"); at++) {
29541
+ if (/^(?:-c|--call)$/.test(line[at])) {
29542
+ inner(line[at + 1] ?? "");
29543
+ called = true;
29544
+ }
29545
+ if (/^(?:-[pc]|--package|--call)$/.test(line[at]))
29546
+ at++;
29547
+ }
29548
+ }
29549
+ const resolved = /^(?:\$\(|`)\s*(?:which|command\s+-v|type\s+-[pP])\s+ytrack\s*[)`]$/.test(line[at] ?? "");
29550
+ const alias = names.get(line[at] ?? "");
29551
+ if (name2(line[at]) !== "ytrack" && !resolved && !alias)
29552
+ return called;
29553
+ const argv = [...alias ?? [], ...line.slice(at + 1)];
29554
+ const write = classify2(argv);
29555
+ if (write) {
29556
+ const one = { command: ["ytrack", ...argv].map(quote2).join(" "), ...write };
29557
+ found.push(plain ? one : ungrant(one));
29558
+ }
29559
+ return true;
29560
+ };
29561
+ var aliases = (command) => {
29562
+ const found = new Map;
29563
+ for (const [, alias, a, b, c] of command.matchAll(/\balias\s+([\w.-]+)=(?:'([^']*)'|"([^"]*)"|([^\s;&|)]+))/g)) {
29564
+ const value = a ?? b ?? c ?? "";
29565
+ if (/^(?:\S*\/)?ytrack(?:\s|$)/.test(value))
29566
+ found.set(alias, value.split(/\s+/).slice(1));
29567
+ }
29568
+ for (const [, a, b, body] of command.matchAll(/(?:\bfunction\s+([\w.-]+)(?:\s*\(\s*\))?|\b([\w.-]+)\s*\(\s*\))\s*\{([^}]*)\}/g))
29569
+ if (/(?:^|[\s;&|])(?:\S*\/)?ytrack\s/.test(body ?? ""))
29570
+ found.set(a ?? b ?? "", []);
29571
+ return found;
29572
+ };
29573
+ var PASS = /^(?:command|exec|nohup|setsid|time|nice|ionice|stdbuf|chronic|unbuffer|timeout)$/;
29574
+ var COMPOUND3 = /^(?:for|select|while|until|repeat|do|done|function|case|foreach|coproc)$/;
29575
+ var passed = (words) => {
29576
+ let at = 0;
29577
+ for (;at < words.length; at++) {
29578
+ const word = words[at];
29579
+ if (/^[A-Za-z_]\w*=/.test(word))
29580
+ return [];
29581
+ if (!PASS.test(word))
29582
+ break;
29583
+ if (/^(?:exec|command)$/.test(word) && words[at + 1]?.startsWith("-"))
29584
+ return [];
29585
+ while (/^(?:-|\d)/.test(words[at + 1] ?? ""))
29586
+ at++;
29587
+ }
29588
+ return words.slice(at);
29589
+ };
29590
+ var plainLines = (command, dialect) => {
29591
+ let first = null;
29592
+ const later = [];
29593
+ for (const segment of segmentsOf(command, dialect)) {
29594
+ if (segment.group || segment.unanalyzable || segment.subs?.length)
29595
+ return null;
29596
+ if (COMPOUND3.test(segment.words[0] ?? ""))
29597
+ return null;
29598
+ if (segment.words.some((word) => /^YTRACK_\w*=/.test(word)))
29599
+ return null;
29600
+ const names = namesYtrack([...segment.words, ...segment.stdin ?? []].join(" "));
29601
+ if (first === null) {
29602
+ if (!names || segment.expands?.length)
29603
+ return null;
29604
+ first = passed(segment.words);
29605
+ } else if (names)
29606
+ later.push(segment.words);
29607
+ }
29608
+ return first ? { first, later } : null;
29609
+ };
29610
+ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
29611
+ if (!namesYtrack(command))
29612
+ return [];
29613
+ if (depth > MAX_DEPTH2)
29614
+ throw new Error("ytrack nested too deep");
29615
+ const key = `${plain}\x00${dialect}\x00${command}`;
29616
+ const known = READ.get(key);
29617
+ if (known)
29618
+ return known;
29619
+ let found = [];
29620
+ const lines = plain ? plainLines(command, dialect) : null;
29621
+ const none = new Map;
29622
+ if (!lines || !ytrackArgs(lines.first, found, depth, none, true) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false))) {
29623
+ found = [];
29624
+ for (const line of commandLines(command, dialect))
29625
+ ytrackArgs(line, found, depth, aliases(command), false);
29626
+ }
29627
+ READ.set(key, found);
29628
+ if (READ.size > 64)
29629
+ READ.delete(READ.keys().next().value);
29630
+ return found;
29631
+ };
29632
+ var writesMode = (cwd) => resolveRuntimeWorkspaceVcs(cwd)?.youtrack?.writes;
29633
+ var ytrackGate = (cwd, command, dialect, ask) => {
29634
+ let writes;
29635
+ try {
29636
+ const merged = new Map;
29637
+ for (const write of ytrackWrites(command, dialect)) {
29638
+ const seen = merged.get(write.command);
29639
+ merged.set(write.command, !seen || !write.workit ? write : !seen.workit ? seen : ungrant(write));
29640
+ }
29641
+ writes = [...merged.values()];
29642
+ } catch {
29643
+ if (writesMode(cwd) === "auto")
29644
+ return null;
29645
+ return {
29646
+ kind: "deny",
29647
+ reason: `Workit could not analyse this command, which names ytrack: run each ytrack call as its own plain command so a YouTrack write can ask the user first (#780).`,
29648
+ unblock: null
29649
+ };
29650
+ }
29651
+ if (!writes.length || writesMode(cwd) === "auto")
29652
+ return null;
29653
+ const calls = writes.flatMap((write) => write.workit ? [`\`${write.workit}\``] : []);
29654
+ const bare = writes.filter((write) => !write.workit).map((write) => `\`${write.command}\` (${write.gap ? `Workit cannot carry ${write.gap} into a workit youtrack call` : "no workit youtrack verb covers it"})`);
29655
+ if (!calls.length && ask)
29656
+ return {
29657
+ kind: "ask",
29658
+ reason: `${bare.join(", ")} writes to YouTrack: the user decides this call (#780).`
29659
+ };
29660
+ const why = `A raw ytrack write posts to YouTrack without the user's yes (#780).`;
29661
+ const run = calls.length ? ` Run ${calls.join(", then ")} instead: it asks the user first. When it answers approval_needed, run exactly the \`workit approve <id>\` it names, now, with nothing around it (no 2>&1, pipe or echo), so the host asks the user; then rerun the workit call once.` : "";
29662
+ const user = bare.length ? ` For ${bare.join(", ")}, the user decides: ask the user, and if they agree they run it in their own terminal.` : "";
29663
+ const rerun = writes.some((write) => write.gap === NOT_PLAIN.gap) ? " To get the named workit youtrack call instead, rerun the ytrack call as one plain command, with no wrapper, loop, substitution or script around it." : "";
29664
+ return {
29665
+ kind: "deny",
29666
+ reason: `${why}${run}${user}${rerun}`,
29667
+ unblock: writes[0]?.workit ?? null
29668
+ };
29669
+ };
29670
+
29104
29671
  // packages/workit-core/src/hooks/handle.ts
29105
29672
  var usable2 = (value) => value === "native" || value === "partial";
29106
29673
  var NONE6 = { kind: "none" };
@@ -29226,6 +29793,9 @@ function decide(input, deps) {
29226
29793
  const policy = canDeny ? shellPolicy(input.cwd, event.command, event.dialect) : NONE6;
29227
29794
  if (policy.kind !== "none")
29228
29795
  return policy;
29796
+ const ytrack = canDeny ? ytrackGate(input.cwd, event.command, event.dialect ?? "posix", input.host === "claude_code") : null;
29797
+ if (ytrack)
29798
+ return ytrack;
29229
29799
  const split = canDeny ? cdWorkitSplit(event.command) : null;
29230
29800
  if (split)
29231
29801
  return {
@@ -29361,7 +29931,7 @@ function decide(input, deps) {
29361
29931
  }
29362
29932
  }
29363
29933
  // packages/workit-core/src/hooks/deadline.ts
29364
- var QUIET = new Set([
29934
+ var QUIET2 = new Set([
29365
29935
  "stop",
29366
29936
  "subagent.stop",
29367
29937
  "shell.post",
@@ -29825,7 +30395,7 @@ var observeToolResult = (event, ctx) => {
29825
30395
  var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? null : promptNudge(hookInput(ctx, { kind: "context.turn", prompt }), prompt);
29826
30396
 
29827
30397
  // packages/workit-pi/src/launches.ts
29828
- import { mkdirSync as mkdirSync7, readFileSync as readFileSync12, readdirSync as readdirSync7, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
30398
+ import { mkdirSync as mkdirSync7, readFileSync as readFileSync13, readdirSync as readdirSync8, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
29829
30399
  import os11 from "node:os";
29830
30400
  import path47 from "node:path";
29831
30401
  var launchDir = (root) => {
@@ -29871,14 +30441,14 @@ var abandonedLaunches = (root) => {
29871
30441
  return [];
29872
30442
  let names;
29873
30443
  try {
29874
- names = readdirSync7(dir);
30444
+ names = readdirSync8(dir);
29875
30445
  } catch {
29876
30446
  return [];
29877
30447
  }
29878
30448
  const found = [];
29879
30449
  for (const name of names) {
29880
30450
  try {
29881
- const attempt = JSON.parse(readFileSync12(path47.join(dir, name), "utf8"));
30451
+ const attempt = JSON.parse(readFileSync13(path47.join(dir, name), "utf8"));
29882
30452
  if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
29883
30453
  if (!alive(attempt))
29884
30454
  found.push(attempt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",