@workit-dev/pi 1.1.6 → 1.1.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 +160 -21
  2. package/package.json +1 -1
package/dist/workit.js CHANGED
@@ -25123,7 +25123,7 @@ var splitDenial = (plan) => ({
25123
25123
  unblock: plan.unblock
25124
25124
  });
25125
25125
  // packages/workit-core/src/hooks/write-gate.ts
25126
- import { existsSync as existsSync11, realpathSync as realpathSync8 } from "node:fs";
25126
+ import { existsSync as existsSync11, realpathSync as realpathSync8, statSync as statSync3 } from "node:fs";
25127
25127
  import os9 from "node:os";
25128
25128
  import path37 from "node:path";
25129
25129
 
@@ -25527,12 +25527,81 @@ var opaqueWrites = (input, scriptOf = (index) => input[index]) => {
25527
25527
  })
25528
25528
  ];
25529
25529
  };
25530
+ if (name === "curl")
25531
+ return curlOutputs(args);
25530
25532
  if (name === "perl")
25531
25533
  return inline(/^-[a-zA-Z]*[eE]$/);
25532
25534
  if (/^(?:python[\d.]*|node|bun|deno|ruby|php)$/.test(name))
25533
25535
  return inline(/^-[a-zA-Z]*[ce]$|^--eval$|^-p$/);
25534
25536
  return shellScript2(words) === null ? null : ["."];
25535
25537
  };
25538
+ var CURL_LONG = [
25539
+ "output",
25540
+ "output-dir",
25541
+ "cookie-jar",
25542
+ "dump-header",
25543
+ "trace",
25544
+ "trace-ascii",
25545
+ "stderr",
25546
+ "libcurl",
25547
+ "hsts",
25548
+ "alt-svc",
25549
+ "etag-save",
25550
+ "config",
25551
+ "write-out",
25552
+ "remote-name",
25553
+ "remote-name-all"
25554
+ ];
25555
+ var CURL_SHORT_LONG = {
25556
+ o: "output",
25557
+ c: "cookie-jar",
25558
+ D: "dump-header",
25559
+ K: "config",
25560
+ w: "write-out"
25561
+ };
25562
+ var CURL_SHORT = /^-([^-AbcCdDeEFHKmoPQrtTuUwxXyYz]*)(?:([AbcCdDeEFHKmoPQrtTuUwxXyYz])(.*))?$/s;
25563
+ var curlOutputs = (args) => {
25564
+ const files = [];
25565
+ const named = [];
25566
+ const dirs = [];
25567
+ let remote = false;
25568
+ for (let index = 0;index < args.length; index++) {
25569
+ const long = /^--([\w.-]+)(?:=(.*))?$/s.exec(args[index]);
25570
+ const short = long ? null : CURL_SHORT.exec(args[index]);
25571
+ if (short?.[1].includes("O"))
25572
+ remote = true;
25573
+ const option = long ? long[1] === "cookie" ? undefined : CURL_LONG.find((name) => name === long[1]) ?? CURL_LONG.find((name) => name.startsWith(long[1])) : CURL_SHORT_LONG[short?.[2] ?? ""];
25574
+ if (option?.startsWith("remote-name"))
25575
+ remote = true;
25576
+ if (option === undefined || option.startsWith("remote-name")) {
25577
+ if (short?.[2] && !short[3])
25578
+ index++;
25579
+ continue;
25580
+ }
25581
+ const value = (long ? long[2] : short?.[3]) || args[++index];
25582
+ if (option === "config" || option === "write-out" && value?.startsWith("@"))
25583
+ files.push(unknownVarTarget(`curl ${option === "config" ? "-K <config>" : "-w @<format>"}`));
25584
+ else if (value === undefined || value === "-")
25585
+ continue;
25586
+ else if (option === "output")
25587
+ named.push(value);
25588
+ else if (option === "output-dir")
25589
+ dirs.push(value);
25590
+ else if (option === "write-out")
25591
+ for (const match of value.matchAll(/%output\{(?:>>)?([^}]*)\}/g))
25592
+ files.push(match[1]);
25593
+ else
25594
+ files.push(value);
25595
+ }
25596
+ for (const name of named) {
25597
+ if (dirs.length === 0 || /^[/~$]|^[A-Za-z]:[\\/]/.test(name))
25598
+ files.push(name);
25599
+ files.push(...dirs.map((dir) => `${dir}/${name}`));
25600
+ }
25601
+ if (remote)
25602
+ files.push(...dirs.length ? dirs : ["."]);
25603
+ return files.length > 0 ? files : null;
25604
+ };
25536
25605
  var pathsIn = (text) => [
25537
25606
  ...text.matchAll(/(?<![\w.~:/$-])(?:~\/|\/|[A-Za-z]:\/|\.\.(?:\/|$))[^\s'"`$),;:*?<>|\\[\]{}]*/g)
25538
25607
  ].map((match) => match[0]);
@@ -25635,6 +25704,7 @@ var MUTATING_GIT = new Set([
25635
25704
  var DRY_N = new Set(["add", "clean", "rm", "mv"]);
25636
25705
  var MUTATING_WORKIT_GIT = new Set(["commit", "branch", "stage", "unstage"]);
25637
25706
  var DIR_TARGET = ".workit-live-target";
25707
+ var OPAQUE_TARGET = ".workit-runs-";
25638
25708
  var OVERRIDE = "WORKIT_LIVE_SESSION=override";
25639
25709
  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("--"));
25640
25710
  var gitMutationDirs = (cwd, command, dialect) => {
@@ -25764,6 +25834,10 @@ var untrustedVars = (segments) => {
25764
25834
  depth = Math.max(0, depth - 1);
25765
25835
  }
25766
25836
  const words = segment.words.slice(start);
25837
+ const at = words.findIndex((word) => !/^\w+=/.test(word));
25838
+ const ifs = (word) => /\bIFS\b/.test(word);
25839
+ if (segment.subs?.some(ifs) || words.some((w, i) => ifs(w) && !(i < at && words[at] === "read")))
25840
+ all = true;
25767
25841
  if (depth > 0)
25768
25842
  for (const [key] of assignmentsOf(words))
25769
25843
  names.add(key);
@@ -25808,7 +25882,10 @@ var unresolvedRefs = (text) => [
25808
25882
  return name === undefined ? match[0] : `$${name}`;
25809
25883
  }))
25810
25884
  ];
25811
- var unknownVarTarget = (text) => path37.join(UNKNOWN_VAR, encodeURIComponent(unresolvedRefs(text).join(" ") || text));
25885
+ var unknownVarTarget = (text) => {
25886
+ const refs = unresolvedRefs(text);
25887
+ return path37.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
25888
+ };
25812
25889
  var applyOperator = (value, operator) => {
25813
25890
  if (operator === "")
25814
25891
  return value;
@@ -25904,6 +25981,20 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
25904
25981
  const name = /^\$(\w+)$/.exec(ref)?.[1];
25905
25982
  return name === undefined || new RegExp(`(?<!\\\\)\\$(?:${name}(?!\\w)|\\{${name}\\b)`).test(command);
25906
25983
  };
25984
+ const listWord = (word) => unresolvedRefs(word).length > 0 || /[\s*?[]/.test(word) ? null : word;
25985
+ const listWords = (item) => expansions(item, vars, loops).map((text) => listWord(homeExpanded(text)));
25986
+ const redefined = untrusted.all || Boolean(process.env.CDPATH) || /\bCDPATH\b/.test(command) || segments.some((s, i) => s.words.length > 0 && segments[i + 1]?.group === "open" && segments[i + 2]?.group === "close");
25987
+ const moved = (plain) => {
25988
+ if (plain && !redefined && !untrusted.names.has("PWD") && dir !== undefined && dir !== UNKNOWN_DIR && statSync3(dir, { throwIfNoEntry: false })?.isDirectory())
25989
+ vars.set("PWD", dir);
25990
+ else
25991
+ vars.delete("PWD");
25992
+ };
25993
+ const lost = () => {
25994
+ dir = strict ? UNKNOWN_DIR : undefined;
25995
+ stack = [];
25996
+ moved(false);
25997
+ };
25907
25998
  const assigned = (value) => {
25908
25999
  const made = mktempPath(value, dir);
25909
26000
  if (made !== null)
@@ -25933,10 +26024,10 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
25933
26024
  if (loop >= 0) {
25934
26025
  const [name = "", keyword, ...items] = segment.words.slice(loop + 1);
25935
26026
  const expanding = new Set(segment.expands ?? []);
25936
- const literal = keyword === "in" && items.every((_, index) => !expanding.has(loop + 3 + index));
26027
+ const list = items.flatMap((item, index) => expanding.has(loop + 3 + index) ? listWords(item) : [listWord(homeExpanded(item))]);
25937
26028
  vars.delete(name);
25938
- if (literal && !untrusted.all && !untrusted.names.has(name))
25939
- loops.set(name, items.map(homeExpanded));
26029
+ if (keyword === "in" && list.length <= MAX_EXPANSIONS2 && !list.includes(null) && !untrusted.all && !untrusted.names.has(name))
26030
+ loops.set(name, list);
25940
26031
  else
25941
26032
  loops.delete(name);
25942
26033
  continue;
@@ -25954,31 +26045,53 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
25954
26045
  vars.set(key, resolved);
25955
26046
  }
25956
26047
  }
26048
+ const moving = (word = "") => {
26049
+ const verb = (word.split(/[\\/]/).at(-1) ?? "").toLowerCase();
26050
+ return CD2.has(verb) || PUSHD2.has(verb) || POPD2.has(verb);
26051
+ };
25957
26052
  const name = (words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase();
25958
- const moves = CD2.has(name) || PUSHD2.has(name) || POPD2.has(name);
26053
+ const moves = moving(name);
25959
26054
  if (moves && strict && nesting > 0) {
25960
26055
  dir = UNKNOWN_DIR;
26056
+ moved(false);
25961
26057
  continue;
25962
26058
  }
25963
- if (moves && keywords > 0)
26059
+ if (moves && keywords > 0) {
26060
+ moved(false);
25964
26061
  continue;
26062
+ }
26063
+ const wrapper = words.findIndex((word) => !TRANSPARENT.has(word) && !PREFIXES2.has(word));
26064
+ if (wrapper > 0 && moving(words[wrapper])) {
26065
+ lost();
26066
+ continue;
26067
+ }
26068
+ const plain = !segment.conditional;
25965
26069
  if (CD2.has(name)) {
25966
26070
  dir = cdInto(dir, words, strict, vars);
26071
+ moved(plain);
26072
+ continue;
26073
+ }
26074
+ const rotates = words.length < 2 || words.slice(1).some((word) => /^[-+]/.test(word));
26075
+ if (dialect === "posix" && (PUSHD2.has(name) ? rotates : POPD2.has(name) && words.length > 1)) {
26076
+ lost();
25967
26077
  continue;
25968
26078
  }
25969
26079
  if (PUSHD2.has(name)) {
25970
26080
  stack.push(dir);
25971
26081
  dir = cdInto(dir, words, strict, vars);
26082
+ moved(plain);
25972
26083
  continue;
25973
26084
  }
25974
26085
  if (POPD2.has(name)) {
25975
26086
  dir = stack.length ? stack.pop() : strict ? UNKNOWN_DIR : undefined;
26087
+ moved(plain);
25976
26088
  continue;
25977
26089
  }
25978
26090
  const inner = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
26091
+ const unPwd = () => new Map([...vars].filter(([key]) => key !== "PWD"));
25979
26092
  if (inner !== null && dir !== undefined)
25980
26093
  for (const runIn of workitRunDir(dir, words, atAll))
25981
- targets.push(...segmentTargets(runIn, inner, "posix", depth + 1, strict, vars));
26094
+ targets.push(...segmentTargets(runIn, inner, "posix", depth + 1, strict, runIn === dir ? vars : unPwd()));
25982
26095
  if (strict && dir !== undefined) {
25983
26096
  const runIn = dir;
25984
26097
  for (const sub of depth < 4 ? segment.subs ?? [] : [])
@@ -25989,13 +26102,18 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
25989
26102
  if (word === undefined || !expanding.has(keywords + index))
25990
26103
  return word;
25991
26104
  const all = expansions(word, vars, loops);
25992
- const open = all.length === 1 ? unresolvedRefs(all[0]).filter(unescaped) : [];
25993
- return all.length === 1 && open.length === 0 ? all[0] : undefined;
26105
+ return all.some((text) => unresolvedRefs(text).some(unescaped)) ? undefined : all.join(`
26106
+ `);
25994
26107
  };
25995
26108
  const opaque = segment.unanalyzable ? ["."] : inner === null ? opaqueWrites(body, scriptOf) : null;
26109
+ const ran = words.findIndex((word) => word === "xargs" || !PREFIXES2.has(word));
26110
+ const runner = words[ran];
26111
+ if (runner !== undefined && expanding.has(keywords + lead + ran) && unresolvedRefs(homeExpanded(runner)).length > 0)
26112
+ targets.push(unknownVarTarget(runner));
26113
+ const here = segment.unanalyzable ? DIR_TARGET : `${OPAQUE_TARGET}${encodeURIComponent(runner?.split(/[\\/]/).at(-1) ?? "a command")}`;
25996
26114
  for (const file of opaque ?? [])
25997
26115
  for (const resolved of atAll(file))
25998
- targets.push(file === "." ? path37.join(resolved, DIR_TARGET) : resolved);
26116
+ targets.push(file === "." ? path37.join(resolved, here) : resolved);
25999
26117
  const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
26000
26118
  if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)))
26001
26119
  targets.push(...linkSources(words.slice(ln + 1), at));
@@ -27329,7 +27447,14 @@ var hostIsolated = (cwd, agentId) => {
27329
27447
  return false;
27330
27448
  }
27331
27449
  };
27332
- var shown = (target) => path39.basename(target) === ".workit-live-target" ? path39.dirname(target) : target;
27450
+ var runnerAt = (target) => {
27451
+ const base = path39.basename(target);
27452
+ return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
27453
+ };
27454
+ var shown = (target) => {
27455
+ const named = /^\.workit-(?:live-target$|runs-)/.test(path39.basename(target)) ? path39.dirname(target) : target;
27456
+ return path39.sep === "\\" ? named.replaceAll("/", "\\") : named;
27457
+ };
27333
27458
  var unboundDeny = (input, target) => {
27334
27459
  const unblock = "Work only in the worktree your brief names, which the lead made with `workit fanout worktree create <slice>`: edit files under it and run one verb per call against it (`workit git --cwd <worktree> commit -m … -- <paths>`, `workit check --cwd <worktree> <name>`). If your brief names no worktree, stop and report that to the lead.";
27335
27460
  return {
@@ -27339,10 +27464,11 @@ var unboundDeny = (input, target) => {
27339
27464
  };
27340
27465
  };
27341
27466
  var outsideDeny = (input, worktree, target) => {
27342
- const unblock = `Edit only under ${worktree} and run git there, one verb per call: \`workit git --cwd ${worktree} commit -m … -- <paths>\`, \`workit check --cwd ${worktree} <name>\` (or \`git -C ${worktree} …\`); a command whose writes Workit cannot see is judged by the directory it runs in. Anything outside it is a follow-up for your report.`;
27467
+ const runner = runnerAt(target);
27468
+ const unblock = `${runner === null ? "" : `Run \`${runner}\` from your worktree: \`cd ${worktree} && …\`. `}Edit only under ${worktree} and run git there, one verb per call: \`workit git --cwd ${worktree} commit -m … -- <paths>\`, \`workit check --cwd ${worktree} <name>\` (or \`git -C ${worktree} …\`); a command whose writes Workit cannot see is judged by the directory it runs in. Anything outside it is a follow-up for your report.`;
27343
27469
  return {
27344
27470
  kind: "deny",
27345
- reason: `workit worktree confinement: implementer ${input.session.agentId} is bound to the worktree ${worktree}, and ${shown(target)} is outside it. ${unblock}`,
27471
+ reason: `workit worktree confinement: implementer ${input.session.agentId} is bound to the worktree ${worktree}, and ${runner === null ? `${shown(target)} is` : `\`${runner}\` runs in ${shown(target)},`} outside it. ${unblock}`,
27346
27472
  unblock
27347
27473
  };
27348
27474
  };
@@ -27366,15 +27492,28 @@ var literalForm = (command, refs) => {
27366
27492
  };
27367
27493
  var unknownVarDeny = (input, worktree, targets, command) => {
27368
27494
  const refs = [
27369
- ...new Set(targets.flatMap((target) => decodeURIComponent(path39.relative(UNKNOWN_VAR, path39.resolve(target)).split(path39.sep)[0]).split(" ").filter(Boolean)))
27495
+ ...new Set(targets.flatMap((target) => path39.relative(UNKNOWN_VAR, path39.resolve(target)).split(path39.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
27370
27496
  ];
27497
+ let text = command ?? "";
27498
+ const first = [];
27499
+ const named = refs.map((ref) => {
27500
+ const name = /^\$(\w+)$/.exec(ref)?.[1];
27501
+ const set = name ? new RegExp(`(^|[\\s;&|(])${name}=("?)(\\$\\([^()]*\\)|\`[^\`]*\`)\\2[ \\t]*(?:&&|;|\\n)?[ \\t]*`).exec(text) : null;
27502
+ const sub = set?.[3] ?? (/^(?:\$\(|`)/.test(ref) ? ref : null);
27503
+ if (sub === null)
27504
+ return ref;
27505
+ if (set)
27506
+ text = text.replace(set[0], set[1]);
27507
+ first.push(`Run \`${sub.slice(sub.startsWith("`") ? 1 : 2, -1).trim()}\` first, then`);
27508
+ return sub === ref ? ref : `${ref} (set by \`${sub}\`)`;
27509
+ });
27371
27510
  const wt = worktree ?? "<worktree>";
27372
- const named = refs.join(", ");
27373
- const retry = command === undefined ? "" : ` Retry as: \`${literalForm(command, refs)}\`.`;
27374
- const unblock = `Spell the path out instead of ${named}: Workit follows only a plain \`NAME=<literal>\` set earlier in the same command, \`$(mktemp …)\` and a \`for\` over literal words.${retry} Write under ${wt} (\`workit git --cwd ${wt} …\`, \`workit check --cwd ${wt} …\`) or a temp dir.`;
27511
+ const literal = literalForm(text, refs.filter((ref) => /^[$`]/.test(ref)));
27512
+ const retry = command === undefined || literal === command ? "" : ` ${first.length ? `${first.join(" ")} retry` : "Retry"} as: \`${literal}\`.`;
27513
+ const unblock = `Spell the path out instead of ${refs.join(", ")}: Workit follows only a plain \`NAME=<literal>\` set earlier in the same command, \`$(mktemp …)\`, \`$PWD\` after a literal \`cd\` and a \`for\` over literal words.${retry} Write under ${wt} (\`workit git --cwd ${wt} …\`, \`workit check --cwd ${wt} …\`) or a temp dir.`;
27375
27514
  return {
27376
27515
  kind: "deny",
27377
- reason: `workit worktree confinement: implementer ${input.session.agentId} writes to a path built from ${named}, which Workit cannot resolve (a command substitution, a loop over unknown words, a conditional or a binder such as read or eval sets it), so it cannot tell whether the write stays in its worktree. ${unblock}`,
27516
+ reason: `workit worktree confinement: implementer ${input.session.agentId} writes to a path built from ${named.join(", ")}, which Workit cannot resolve (a command substitution, a loop over unknown or split words, a conditional, a binder such as read or eval, or an options file sets it), so it cannot tell whether the write stays in its worktree. ${unblock}`,
27378
27517
  unblock
27379
27518
  };
27380
27519
  };
@@ -27719,7 +27858,7 @@ var verbFirst = (command) => {
27719
27858
  };
27720
27859
 
27721
27860
  // packages/workit-core/src/hooks/model-limit.ts
27722
- import { closeSync as closeSync2, openSync as openSync2, readdirSync as readdirSync4, readSync, statSync as statSync3 } from "node:fs";
27861
+ import { closeSync as closeSync2, openSync as openSync2, readdirSync as readdirSync4, readSync, statSync as statSync4 } from "node:fs";
27723
27862
  import os10 from "node:os";
27724
27863
  import path41 from "node:path";
27725
27864
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
@@ -27932,7 +28071,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
27932
28071
  const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path41.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
27933
28072
  for (const { file, worker } of files)
27934
28073
  try {
27935
- const stat = statSync3(file);
28074
+ const stat = statSync4(file);
27936
28075
  if (now.getTime() - stat.mtimeMs > SCAN_MS)
27937
28076
  continue;
27938
28077
  const last = lastApiError(tail(file, stat.size));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",