@workit-dev/pi 2.20.0 → 2.20.2

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 +97 -46
  2. package/package.json +1 -1
package/dist/workit.js CHANGED
@@ -15097,7 +15097,23 @@ function runsByGlob(command, name) {
15097
15097
  const tokens = command.split(/\s+/u).map((token) => token.replace(/^--filter=/u, "").replaceAll(/^["']|["']$/gu, "").replace(/^(?:npm|pnpm|yarn|bun):/u, ""));
15098
15098
  if (/\bpnpm\b/u.test(command) && tokens.some((token) => /^\/.+\/$/u.test(token)))
15099
15099
  return true;
15100
- return tokens.filter((token) => token.includes("*")).some((glob) => new RegExp(`^${glob.split(/\*+/u).map((part) => part.replaceAll(/[.+?^${}()|[\]\\]/gu, "\\$&")).join(".*")}$`, "u").test(name));
15100
+ return tokens.filter((token) => token.includes("*")).some((glob) => globMatches(glob, name));
15101
+ }
15102
+ function globMatches(glob, name) {
15103
+ const parts = glob.split("*");
15104
+ const first = parts[0];
15105
+ const last = parts.at(-1) ?? "";
15106
+ const end = name.length - last.length;
15107
+ if (end < first.length || !name.startsWith(first) || !name.endsWith(last))
15108
+ return false;
15109
+ let at = first.length;
15110
+ for (const part of parts.slice(1, -1)) {
15111
+ const found = name.indexOf(part, at);
15112
+ if (found < 0 || found + part.length > end)
15113
+ return false;
15114
+ at = found + part.length;
15115
+ }
15116
+ return true;
15101
15117
  }
15102
15118
  function goDirectives(text) {
15103
15119
  const out = [];
@@ -20322,7 +20338,8 @@ var tokenize = (command, dialect) => {
20322
20338
  if (current.words.length) {
20323
20339
  current.pipe = true;
20324
20340
  current.conditional = true;
20325
- }
20341
+ } else if (segments.at(-1)?.group === "close")
20342
+ segments.at(-1).pipe = true;
20326
20343
  if (next === "&")
20327
20344
  index++;
20328
20345
  }
@@ -25711,7 +25728,53 @@ var hasWordsInOrder = (words, needle) => {
25711
25728
  return false;
25712
25729
  };
25713
25730
  var isBypass = (word) => WORKIT_BYPASS_FLAGS.some((flag) => word === flag || word.startsWith(`${flag}=`));
25714
- var isWorkitWord = (word) => /^(?:.*[\\/])?workit(?:-cli)?$/u.test(word);
25731
+ var isWorkitWord = (word) => /^(?:(?:.*[\\/])?workit(?:-cli)?|@workit-dev\/cli(?:@[\w.-]+)?)$/u.test(word);
25732
+ var verbAt = (words) => {
25733
+ let at = 0;
25734
+ for (;; ) {
25735
+ const word = words[at];
25736
+ if (word === "--json")
25737
+ at += 1;
25738
+ else if (word === "--cwd" || word === "--session")
25739
+ at += 2;
25740
+ else if (word?.startsWith("--cwd=") || word?.startsWith("--session="))
25741
+ at += 1;
25742
+ else
25743
+ return at;
25744
+ }
25745
+ };
25746
+ var WRAPPERS2 = new Set(["env", "sudo", "nohup", "command", "timeout", "nice", "exec"]);
25747
+ var VALUED = /^-(?:[ugnskCpD]|-user|-group|-signal|-kill-after|-unset|-chdir)$/u;
25748
+ var unwrapped = (words) => {
25749
+ let at = 0;
25750
+ for (;; ) {
25751
+ const word = words[at] ?? "";
25752
+ const name = word.split("/").at(-1) ?? "";
25753
+ if (/^[A-Za-z_]\w*=/u.test(word))
25754
+ at += 1;
25755
+ else if (WRAPPERS2.has(name)) {
25756
+ at += 1;
25757
+ while (words[at]?.startsWith("-"))
25758
+ at += VALUED.test(words[at] ?? "") ? 2 : 1;
25759
+ if (name === "timeout" && words[at] !== undefined)
25760
+ at += 1;
25761
+ } else
25762
+ return words.slice(at);
25763
+ }
25764
+ };
25765
+ var shellScript2 = (all) => {
25766
+ const words = unwrapped(all);
25767
+ const name = words[0]?.split("/").at(-1) ?? "";
25768
+ if (name === "eval")
25769
+ return words.slice(1).join(" ") || null;
25770
+ if (!/^(?:ba|z|da|k)?sh$/u.test(name))
25771
+ return null;
25772
+ const flag = words.findIndex((word, at) => at > 0 && /^-[a-z]*c[a-z]*$/u.test(word));
25773
+ if (flag < 0)
25774
+ return null;
25775
+ return words[words[flag + 1] === "--" ? flag + 2 : flag + 1] ?? null;
25776
+ };
25777
+ var SCRIPT_DEPTH = 4;
25715
25778
  var bypassReason = (flag) => `Workit: \`${flag}\` overrides a Workit gate, so the user decides this call (no allow rule covers it).`;
25716
25779
  var workitBypassFlag = (command, dialect = "posix") => {
25717
25780
  for (const segment of segmentsOf(command, dialect)) {
@@ -25746,47 +25809,30 @@ var userOnlyWorkitCall = (command, dialect = "posix") => {
25746
25809
  const words = segment.words.slice(start + 1);
25747
25810
  const end = words.indexOf("--");
25748
25811
  const args = end < 0 ? words : words.slice(0, end);
25749
- let at = 0;
25750
- for (;; ) {
25751
- const word = args[at];
25752
- if (word === "--json")
25753
- at += 1;
25754
- else if (word === "--cwd" || word === "--session")
25755
- at += 2;
25756
- else if (word?.startsWith("--cwd="))
25757
- at += 1;
25758
- else
25759
- break;
25760
- }
25761
- const call = args.slice(at);
25812
+ const call = args.slice(verbAt(args));
25762
25813
  const found = WORKIT_USER_ONLY.find((needle) => call[0] === needle[0] && hasWordsInOrder(call, needle));
25763
25814
  if (found && !helpOnly(call, found))
25764
25815
  return [...found];
25765
25816
  }
25766
25817
  return null;
25767
25818
  };
25768
- var askedWorkitCall = (command, dialect = "posix") => {
25819
+ var askedWorkitCall = (command, dialect = "posix", depth = 0) => {
25769
25820
  if (!mayRunUserOnly(command))
25770
25821
  return null;
25771
25822
  for (const segment of segmentsOf(command, dialect)) {
25772
25823
  if (segment.unanalyzable)
25773
25824
  continue;
25825
+ const script = shellScript2(segment.words);
25826
+ for (const inner of depth < SCRIPT_DEPTH ? [...script ? [script] : [], ...segment.subs ?? []] : []) {
25827
+ const found = askedWorkitCall(inner, "posix", depth + 1);
25828
+ if (found)
25829
+ return { ...found, plain: false };
25830
+ }
25774
25831
  const start = segment.words.findIndex(isWorkitWord);
25775
25832
  if (start < 0)
25776
25833
  continue;
25777
25834
  const words = segment.words.slice(start + 1);
25778
- let at = 0;
25779
- for (;; ) {
25780
- const word = words[at];
25781
- if (word === "--json")
25782
- at += 1;
25783
- else if (word === "--cwd" || word === "--session")
25784
- at += 2;
25785
- else if (word?.startsWith("--cwd="))
25786
- at += 1;
25787
- else
25788
- break;
25789
- }
25835
+ const at = verbAt(words);
25790
25836
  const verb = WORKIT_ASKED_VERBS.find((name) => words[at] === name);
25791
25837
  if (verb && !helpOnly(words.slice(at), [verb]))
25792
25838
  return {
@@ -26563,7 +26609,10 @@ function heavyPlan(command, options) {
26563
26609
  };
26564
26610
  }
26565
26611
  if (single) {
26566
- const rewrite = leaseRewrite(command.trim().replace(TAIL_FILTER, ""));
26612
+ const rewrite = leaseRewrite(command.trim().replace(TAIL_FILTER, (_, merged = "", redirects = "") => {
26613
+ const out = [...redirects.matchAll(/(\d*)(>>?)\s*(\S+)/gu)].findLast(([, fd]) => fd === "" || fd === "1");
26614
+ return out ? ` ${out[2]} ${out[3]}${merged}` : "";
26615
+ }));
26567
26616
  return rewrite ? { kind: "rewrite", command: rewrite, reason: single.reason } : { kind: "none" };
26568
26617
  }
26569
26618
  const parts = heavy.map((match) => leaseCommand(match.line));
@@ -26608,7 +26657,7 @@ function workitOnPath2(env = process.env) {
26608
26657
  }
26609
26658
  return false;
26610
26659
  }
26611
- var TAIL_FILTER = /(?:\s+2>&1)?\s*\|\s*(?:tail|head)(?:\s+[\w=.+-]+)*\s*$/u;
26660
+ var TAIL_FILTER = /(\s+2>&1)?\s*\|\s*(?:tail|head)(?:\s+(?!\d*>)[\w=.+-]+)*((?:\s*\d*>>?\s*[\w./~-]+)*)\s*$/u;
26612
26661
  var ASSIGNMENTS = /^\s*((?:[A-Za-z_]\w*=(?:'[^']*'|"(?:[^"\\]|\\.)*"|[^\s'"])*\s+)*)/u;
26613
26662
  function leaseRewrite(command) {
26614
26663
  const text = command.trim();
@@ -27000,7 +27049,7 @@ var wrappedScript = (input) => {
27000
27049
  return null;
27001
27050
  if ("script" in tail)
27002
27051
  return tail.script;
27003
- const script = shellScript2(tail.argv);
27052
+ const script = shellScript3(tail.argv);
27004
27053
  if (SCRIPT_SHELLS.has((tail.argv[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()) && script)
27005
27054
  return script;
27006
27055
  return tail.argv.map(quoteWord2).join(" ");
@@ -27082,7 +27131,7 @@ var editsOf = (input) => {
27082
27131
  return [];
27083
27132
  }
27084
27133
  };
27085
- var WRAPPERS2 = {
27134
+ var WRAPPERS3 = {
27086
27135
  sudo: "ugCDhpRrTtU",
27087
27136
  doas: "uC",
27088
27137
  env: "uCS",
@@ -27160,16 +27209,16 @@ var scriptArgs = (verb, args) => {
27160
27209
  }
27161
27210
  return { preloads };
27162
27211
  };
27163
- var unwrapped = (words) => {
27212
+ var unwrapped2 = (words) => {
27164
27213
  let at = 0;
27165
- for (let takes;(takes = WRAPPERS2[words[at]?.split(/[\\/]/).at(-1) ?? ""]) !== undefined; ) {
27214
+ for (let takes;(takes = WRAPPERS3[words[at]?.split(/[\\/]/).at(-1) ?? ""]) !== undefined; ) {
27166
27215
  at++;
27167
27216
  while (at < words.length && /^-|^\w+=|^\d[\w.]*$/.test(words[at]))
27168
27217
  at += words[at].length === 2 && words[at][0] === "-" && takes.includes(words[at][1]) ? 2 : 1;
27169
27218
  }
27170
27219
  return at ? words.slice(at) : null;
27171
27220
  };
27172
- var shellScript2 = (words) => {
27221
+ var shellScript3 = (words) => {
27173
27222
  if (!SCRIPT_SHELLS.has((words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()))
27174
27223
  return null;
27175
27224
  for (let index = 1;index < words.length; index++) {
@@ -27270,7 +27319,7 @@ var opaqueWrites = (input, scriptOf = (index) => input[index], fed) => {
27270
27319
  return [".", ...args.flatMap(pathsIn)];
27271
27320
  if (/^(?:python[\d.]*|node|bun|deno|ruby|php)$/.test(name))
27272
27321
  return inline(/^-[a-zA-Z]*[cep]$|^--(?:eval|print)$/);
27273
- return shellScript2(words) === null ? null : ["."];
27322
+ return shellScript3(words) === null ? null : ["."];
27274
27323
  };
27275
27324
  var CURL_LONG = [
27276
27325
  "output",
@@ -27952,14 +28001,14 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
27952
28001
  moved(plain);
27953
28002
  continue;
27954
28003
  }
27955
- const literal = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
28004
+ const literal = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript3(words) : null) : null;
27956
28005
  const held = literal !== null && strict === "registry" ? expansions(literal, vars, loops) : [];
27957
28006
  const inner = held.length === 1 ? held[0] : literal;
27958
28007
  const unPwd = () => new Map([...vars].filter(([key]) => key !== "PWD"));
27959
28008
  if (inner !== null && dir !== undefined)
27960
28009
  for (const runIn of workitRunDir(dir, words, atAll))
27961
28010
  targets.push(...segmentTargets(runIn, inner, "posix", depth + 1, strict, runIn === dir ? vars : unPwd()));
27962
- const bare = strict === "registry" && depth < 4 ? unwrapped(words) : null;
28011
+ const bare = strict === "registry" && depth < 4 ? unwrapped2(words) : null;
27963
28012
  if (bare?.length && dir !== undefined)
27964
28013
  targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
27965
28014
  if (strict === "registry" && dir !== undefined && depth < 4) {
@@ -27996,9 +28045,9 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
27996
28045
  const shells = verb === "eval" ? [args.join(" ")] : verb === "trap" ? args.slice(0, 1) : verb === "alias" ? args.map((arg) => arg.replace(/^[^=]*=/, "")) : [];
27997
28046
  const others = [];
27998
28047
  if (SCRIPT_SHELLS.has(verb) || verb === "." || verb === "source") {
27999
- if (named === undefined && shellScript2(run) === null)
28048
+ if (named === undefined && shellScript3(run) === null)
28000
28049
  shells.push(...segment.stdin ?? [], ...inputs.flatMap(read), ...piped);
28001
- else if (named !== undefined && shellScript2(run) === null)
28050
+ else if (named !== undefined && shellScript3(run) === null)
28002
28051
  shells.push(...read(named));
28003
28052
  shells.push(...preloads.flatMap(read));
28004
28053
  } else if (INTERPRETERS.test(verb)) {
@@ -30161,7 +30210,7 @@ var FED = /^(?:-|\/dev\/stdin|\/dev\/fd\/0|\/proc\/self\/fd\/0)$|^<\(/;
30161
30210
  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;
30162
30211
  var RUNS = /^(?:sh|bash|zsh|dash|ksh|mksh|ash|python[\d.]*|node|bun|deno|ruby|perl|php|eval|source|\.|workit)$/;
30163
30212
  var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print|test|version|help)$|^-[hvV]$/;
30164
- var VALUED = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
30213
+ var VALUED2 = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
30165
30214
  var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
30166
30215
  var inScratch = (real, repo) => {
30167
30216
  for (let dir = real;path47.dirname(dir) !== dir; dir = path47.dirname(dir)) {
@@ -30555,7 +30604,7 @@ var judgeRefusal = (command, fed, depth = 0) => {
30555
30604
  }
30556
30605
  }
30557
30606
  if (INTERPRETERS2.test(name) && !args.some((arg) => INLINE.test(arg))) {
30558
- const operand = args.find((arg, index) => (arg === "-" || !arg.startsWith("-")) && !VALUED.test(args[index - 1] ?? ""));
30607
+ const operand = args.find((arg, index) => (arg === "-" || !arg.startsWith("-")) && !VALUED2.test(args[index - 1] ?? ""));
30559
30608
  if ((FED.test(operand ?? "") || operand === undefined && !/^(?:bun|deno)$/.test(name)) && !(segment.stdin?.length && /^(?:-|\/dev\/stdin)?$/.test(operand ?? "")))
30560
30609
  return unseen;
30561
30610
  }
@@ -32145,7 +32194,6 @@ var retryOf = ({ call, dir }) => {
32145
32194
  function exitPipeGate(command, dialect = "posix") {
32146
32195
  if (!/\bworkit/u.test(command) || !/\b(?:tail|head)\b/u.test(command))
32147
32196
  return null;
32148
- const subshellPiped = /\)\s*(?:\d*>&?\d*\s*)*\|(?!\|)/u.test(command);
32149
32197
  const groups = [];
32150
32198
  let carry = null;
32151
32199
  let pipefail = false;
@@ -32168,10 +32216,13 @@ function exitPipeGate(command, dialect = "posix") {
32168
32216
  }
32169
32217
  if (closes) {
32170
32218
  const inner = groups.pop() ?? null;
32171
- const piped = segment.pipe === true || segment.group === "close" && subshellPiped;
32172
- carry = piped ? inner ?? carry : null;
32219
+ if (inner && groups.length)
32220
+ groups[groups.length - 1] = inner;
32221
+ carry = segment.pipe ? inner ?? carry : null;
32173
32222
  continue;
32174
32223
  }
32224
+ if (!words.length && !segment.stdin && !segment.subs)
32225
+ continue;
32175
32226
  if (setsPipefail(words))
32176
32227
  pipefail = true;
32177
32228
  const filter = base2(words[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "2.20.0",
3
+ "version": "2.20.2",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",