@workit-dev/pi 2.0.2 → 2.1.1

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 +70 -20
  2. package/package.json +1 -1
package/dist/workit.js CHANGED
@@ -19309,6 +19309,7 @@ var tokenize = (command, dialect) => {
19309
19309
  let expanding = false;
19310
19310
  let afterOperator = false;
19311
19311
  let pending = null;
19312
+ let duplicate = false;
19312
19313
  const heredocs = [];
19313
19314
  const escape = posix ? "\\" : "`";
19314
19315
  const flushWord = () => {
@@ -19316,7 +19317,7 @@ var tokenize = (command, dialect) => {
19316
19317
  return;
19317
19318
  const text = MARKERS.test(word) ? literal2(word) : word;
19318
19319
  if (pending === "redirect") {
19319
- if (!text.startsWith("&"))
19320
+ if (!duplicate || !/^(?:\d+-?|-)$/.test(text))
19320
19321
  current.redirects.push(text);
19321
19322
  } else if (pending === "heredoc")
19322
19323
  heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
@@ -19331,6 +19332,7 @@ var tokenize = (command, dialect) => {
19331
19332
  (current.expands ??= []).push(...current.words.slice(at).map((_, i) => at + i));
19332
19333
  }
19333
19334
  pending = null;
19335
+ duplicate = false;
19334
19336
  word = "";
19335
19337
  inWord = false;
19336
19338
  expanding = false;
@@ -19479,11 +19481,9 @@ var tokenize = (command, dialect) => {
19479
19481
  flushWord();
19480
19482
  if (command[index + 1] === ">")
19481
19483
  index++;
19482
- if (command[index + 1] === "&") {
19484
+ duplicate = command[index + 1] === "&";
19485
+ if (duplicate)
19483
19486
  index++;
19484
- word = "&";
19485
- inWord = true;
19486
- }
19487
19487
  pending = "redirect";
19488
19488
  } else if (char === "<" && posix) {
19489
19489
  flushWord();
@@ -25683,7 +25683,14 @@ var splitDenial = (plan) => ({
25683
25683
  unblock: plan.unblock
25684
25684
  });
25685
25685
  // packages/workit-core/src/hooks/write-gate.ts
25686
- import { existsSync as existsSync13, readdirSync as readdirSync5, readFileSync as readFileSync12, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
25686
+ import {
25687
+ existsSync as existsSync13,
25688
+ readdirSync as readdirSync5,
25689
+ readFileSync as readFileSync12,
25690
+ readlinkSync as readlinkSync2,
25691
+ realpathSync as realpathSync9,
25692
+ statSync as statSync4
25693
+ } from "node:fs";
25687
25694
  import os9 from "node:os";
25688
25695
  import path41 from "node:path";
25689
25696
 
@@ -25891,21 +25898,44 @@ var claimLiveSession = (target, owner, deps = {}) => {
25891
25898
  // packages/workit-core/src/hooks/write-gate.ts
25892
25899
  var NONE3 = { kind: "none" };
25893
25900
  var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "win32";
25894
- var canonical4 = (file) => {
25901
+ var linkTarget = (file) => {
25902
+ try {
25903
+ const to = readlinkSync2(file);
25904
+ let from = path41.dirname(file);
25905
+ try {
25906
+ from = realpathSync9.native(from);
25907
+ } catch {}
25908
+ return path41.resolve(from, to);
25909
+ } catch {
25910
+ return null;
25911
+ }
25912
+ };
25913
+ var realPath = (file, dangling = true) => {
25914
+ let dir = path41.resolve(file);
25895
25915
  let rest = "";
25896
- for (let dir = path41.resolve(file);; dir = path41.dirname(dir)) {
25916
+ for (let hops = 0;; ) {
25897
25917
  try {
25898
25918
  return path41.join(realpathSync9.native(dir), rest);
25899
25919
  } catch {
25900
- if (path41.dirname(dir) === dir)
25920
+ const link = dangling ? linkTarget(dir) : null;
25921
+ if (link !== null) {
25922
+ if (++hops > 40)
25923
+ return null;
25924
+ dir = path41.join(link, rest);
25925
+ rest = "";
25926
+ } else if (path41.dirname(dir) === dir)
25901
25927
  return path41.resolve(file);
25902
- rest = rest ? path41.join(path41.basename(dir), rest) : path41.basename(dir);
25928
+ else {
25929
+ rest = rest ? path41.join(path41.basename(dir), rest) : path41.basename(dir);
25930
+ dir = path41.dirname(dir);
25931
+ }
25903
25932
  }
25904
25933
  }
25905
25934
  };
25935
+ var canonical4 = (file, dangling = true) => realPath(file, dangling) ?? path41.resolve(file);
25906
25936
  var exempt = (cwd, root, file, plans) => {
25907
25937
  const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
25908
- const relative = path41.relative(fold(canonical4(root)), fold(canonical4(path41.resolve(cwd, file))));
25938
+ const relative = path41.relative(fold(canonical4(root, false)), fold(canonical4(path41.resolve(cwd, file), false)));
25909
25939
  if (relative.startsWith("..") || path41.isAbsolute(relative))
25910
25940
  return true;
25911
25941
  const posix = relative.split(path41.sep).join("/");
@@ -25943,6 +25973,7 @@ var editsOf = (input) => {
25943
25973
  case "rm":
25944
25974
  case "rmdir":
25945
25975
  case "tee":
25976
+ case "sponge":
25946
25977
  case "mv":
25947
25978
  case "truncate":
25948
25979
  return operands(args);
@@ -26029,7 +26060,7 @@ var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test
26029
26060
  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)$/;
26030
26061
  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)$/;
26031
26062
  var PATH_CALLS = /^(?:join|resolve|normalize|abspath|expanduser|expandvars|Path|PurePath|fspath)$/;
26032
- var readsRoot = (text, at) => {
26063
+ var rootUse = (text, at) => {
26033
26064
  let call;
26034
26065
  for (let index = at, depth = 0;index > 0 && call === undefined; index--) {
26035
26066
  const char = text[index - 1];
@@ -26041,10 +26072,10 @@ var readsRoot = (text, at) => {
26041
26072
  break;
26042
26073
  }
26043
26074
  if (call !== undefined && READ_CALLS.test(call))
26044
- return true;
26075
+ return "reads";
26045
26076
  if (call !== undefined && !PATH_CALLS.test(call))
26046
- return false;
26047
- return ![...text.matchAll(/([\w$]+)\s*\(/g)].some(([, name]) => MUTATING_CALLS.test(name));
26077
+ return "takes";
26078
+ return [...text.matchAll(/([\w$]+)\s*\(/g)].some(([, name]) => MUTATING_CALLS.test(name)) ? "builds" : "reads";
26048
26079
  };
26049
26080
  var inertEdit = (command) => command.split("|").every((part) => /^:?(?:se(?:t)?|sy(?:ntax)?|colo(?:rscheme)?)(?:\s|$)|^[/?][^/?]*[/?]?$|^\d+$/.test(part.trim()));
26050
26081
  var SCRIPT_OPTIONS = [
@@ -26058,12 +26089,15 @@ var SCRIPT_OPTIONS = [
26058
26089
  var PRELOAD = /^(?:-r|--(?:require|import|(?:experimental-)?loader|preload|rcfile|init-file))$/;
26059
26090
  var scriptArgs = (verb, args) => {
26060
26091
  const takes = SCRIPT_OPTIONS.find(([family]) => family.test(verb))?.[1] ?? /^$/;
26092
+ const shell = SCRIPT_OPTIONS[0][0].test(verb);
26061
26093
  const preloads = [];
26062
26094
  for (let at = 0;at < args.length; at++) {
26063
26095
  const [option, value] = args[at].split(/=(.*)/s);
26064
26096
  if (value !== undefined && PRELOAD.test(option))
26065
26097
  preloads.push(value);
26066
- else if (/^-[mce]$|^--(?:eval|print)$/.test(option))
26098
+ else if (/^-[mce]$|^--(?:eval|print)$|^-$/.test(option))
26099
+ break;
26100
+ else if (shell && /^-[a-zA-Z]*s[a-zA-Z]*$/.test(option))
26067
26101
  break;
26068
26102
  else if (takes.test(option)) {
26069
26103
  if (PRELOAD.test(option))
@@ -26429,6 +26463,7 @@ var DRY_N = new Set(["add", "clean", "rm", "mv"]);
26429
26463
  var MUTATING_WORKIT_GIT = new Set(["commit", "branch", "stage", "unstage"]);
26430
26464
  var DIR_TARGET = ".workit-live-target";
26431
26465
  var OPAQUE_TARGET = ".workit-runs-";
26466
+ var UNRESOLVED_TARGET = ".workit-unresolved-target";
26432
26467
  var OVERRIDE = "WORKIT_LIVE_SESSION=override";
26433
26468
  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("--"));
26434
26469
  var gitMutationDirs = (cwd, command, dialect) => {
@@ -26894,9 +26929,11 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26894
26929
  ...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
26895
26930
  ...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
26896
26931
  ];
26897
- for (const { file, index } of found)
26898
- if (!isRoot(file) || !readsRoot(text, index))
26899
- targets.push(file);
26932
+ for (const { file, index } of found) {
26933
+ const use = isRoot(file) ? rootUse(text, index) : "takes";
26934
+ if (use !== "reads")
26935
+ targets.push(use === "builds" ? path41.join(file, UNRESOLVED_TARGET) : file);
26936
+ }
26900
26937
  }
26901
26938
  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"))))
26902
26939
  for (const file of operands(args))
@@ -27102,6 +27139,8 @@ var registryTarget = (cwd, targets) => {
27102
27139
  const inodes = {};
27103
27140
  for (const target of targets) {
27104
27141
  const file = homeExpanded(target);
27142
+ if (realPath(path41.resolve(cwd, file)) === null)
27143
+ return { file: target, registry: "link" };
27105
27144
  const glob = globbed(cwd, file, state, configs)[0];
27106
27145
  const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
27107
27146
  if (viaGlob)
@@ -27128,7 +27167,7 @@ var underRegistry = (state, cwd, target, platform = process.platform, real = (fi
27128
27167
  };
27129
27168
  var underConfig = (dir, cwd, target, platform = process.platform, real = (file) => file) => {
27130
27169
  const parts = partsUnder(dir, cwd, target, platform, real);
27131
- return parts?.length === 1 && ["", ...CONFIG_FILES, DIR_TARGET].includes(parts[0]);
27170
+ return parts?.length === 1 && ["", ...CONFIG_FILES, DIR_TARGET, UNRESOLVED_TARGET].includes(parts[0]);
27132
27171
  };
27133
27172
  var unquotedWindowsRegistry = (command, platform = process.platform) => {
27134
27173
  if (platform !== "win32" || !command.includes("\\"))
@@ -27153,6 +27192,11 @@ var unquotedWindowsRegistry = (command, platform = process.platform) => {
27153
27192
  return writes.writes && (writes.targets === null || writes.targets.some(named)) ? registry : null;
27154
27193
  };
27155
27194
  var REGISTRY_DENY = {
27195
+ link: {
27196
+ label: "registry guard",
27197
+ what: "a symlink chain Workit could not resolve (over 40 links), which may reach a guarded path",
27198
+ unblock: "Write to the file's real path."
27199
+ },
27156
27200
  issued: {
27157
27201
  label: "issued-registry guard",
27158
27202
  what: "Workit's issued-session state",
@@ -27171,6 +27215,12 @@ var REGISTRY_DENY = {
27171
27215
  };
27172
27216
  var registryDeny = ({ file, registry }) => {
27173
27217
  const { label, what, unblock } = REGISTRY_DENY[registry];
27218
+ if (path41.basename(file) === UNRESOLVED_TARGET)
27219
+ return {
27220
+ kind: "deny",
27221
+ reason: `workit ${label}: Workit could not resolve the file this command's script writes, which it builds from a path under ${what}. ${unblock}`,
27222
+ unblock
27223
+ };
27174
27224
  const named = path41.basename(file).startsWith(".workit-") ? path41.dirname(file) : file;
27175
27225
  return {
27176
27226
  kind: "deny",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "2.0.2",
3
+ "version": "2.1.1",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",