@workit-dev/pi 2.4.3 → 2.4.4

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.
package/dist/worker.js CHANGED
@@ -9697,6 +9697,7 @@ var MUTATING_GIT = new Set([
9697
9697
  ]);
9698
9698
  var DRY_N = new Set(["add", "clean", "rm", "mv"]);
9699
9699
  var MUTATING_WORKIT_GIT = new Set(["commit", "branch", "stage", "unstage"]);
9700
+ var PLACEHOLDERS = new WeakMap;
9700
9701
  var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
9701
9702
  var PUSHD2 = new Set(["pushd", "push-location"]);
9702
9703
  var POPD2 = new Set(["popd", "pop-location"]);
@@ -9768,6 +9769,60 @@ var MUTATING_REMOTE = new Set([
9768
9769
  "set-branches",
9769
9770
  "prune"
9770
9771
  ]);
9772
+ var GIT_VERBS = {
9773
+ log: "@d@l|@d @l",
9774
+ show: "@d@l|@d @l",
9775
+ diff: "@d|@d cached staged merge-base no-index",
9776
+ "diff-tree": "@drtcm|@d root stdin no-commit-id",
9777
+ "diff-index": "@dm|@d cached merge-base",
9778
+ status: "sbu?zv|short branch porcelain? long untracked-files? ignored? ignore-submodules? show-stash ahead-behind no-ahead-behind renames no-renames find-renames? column? no-column null verbose",
9779
+ "rev-parse": "q|verify short? abbrev-ref? symbolic symbolic-full-name show-toplevel show-prefix git-dir git-common-dir absolute-git-dir is-inside-work-tree is-inside-git-dir is-bare-repository show-cdup quiet all branches? tags? remotes? since= until= default= path-format= sq-quote",
9780
+ "rev-list": "@l|@l count objects? left-only right-only",
9781
+ "ls-files": "cdmoiskuvtzfx:X:|cached deleted modified others ignored stage unmerged killed directory no-empty-directory exclude-standard exclude= exclude-from= full-name abbrev? error-unmatch with-tree= eol deduplicate format= recurse-submodules sparse",
9782
+ "ls-tree": "rdtlz|long name-only name-status object-only full-name full-tree abbrev? format=",
9783
+ "cat-file": "tsepz|batch? batch-check? batch-all-objects follow-symlinks unordered buffer allow-unknown-type mailmap use-mailmap",
9784
+ blame: "L:lstfnepwbcM?C?|porcelain line-porcelain incremental root show-stats show-name show-number show-email abbrev= reverse= first-parent date= ignore-rev= ignore-revs-file= minimal contents=",
9785
+ describe: "|tags all long abbrev= contains always dirty? broken? match= exclude= first-parent exact-match candidates= debug",
9786
+ "merge-base": "a|all octopus independent is-ancestor fork-point",
9787
+ "for-each-ref": "|count= sort= format= color? shell perl python tcl points-at= merged? no-merged? contains? no-contains? ignore-case omit-empty exclude=",
9788
+ shortlog: "@lsnec|@l summary numbered email committer group= format=",
9789
+ "show-ref": "dsq|head verify heads tags branches hash? abbrev? quiet dereference exists",
9790
+ "name-rev": "|tags refs= exclude= all annotate-stdin name-only no-undefined always",
9791
+ grep: "aiIvnhHcEGFPlLzoWqwe:A:B:C:m:f:|cached untracked no-index no-exclude-standard exclude-standard recurse-submodules text ignore-case word-regexp invert-match line-number column count full-name extended-regexp basic-regexp fixed-strings perl-regexp files-with-matches name-only files-without-match null only-matching heading break show-function function-context max-depth= threads= and or not all-match quiet after-context= before-context= context= max-count= color? no-color",
9792
+ "format-patch": "@do:nNks|@d stdout output-directory= numbered no-numbered start-number= subject-prefix= root cover-letter thread? signoff attach? inline? suffix= base=",
9793
+ reflog: "@l|@l all expire= expire-unreachable= rewrite updateref stale-fix dry-run verbose",
9794
+ "count-objects": "vH|verbose human-readable",
9795
+ "check-ignore": "qvnz|quiet verbose stdin non-matching no-index",
9796
+ var: "l|",
9797
+ version: "|build-options",
9798
+ "ls-remote": "htbq|heads tags branches refs quiet exit-code get-url symref sort=",
9799
+ remote: "v|verbose",
9800
+ config: "lz|get get-all get-regexp list local name-only null type= default=",
9801
+ worktree: "fdqvzb:B:|force detach lock reason= orphan no-checkout checkout quiet track no-track guess-remote porcelain expire= verbose",
9802
+ branch: "dDmMcCfvraliu:|delete move copy force list all remotes verbose contains? merged? no-merged? points-at= show-current set-upstream-to= unset-upstream track? no-track sort= format= color? column? ignore-case create-reflog",
9803
+ tag: "lam:dfF:n?|list annotate message= file= delete force sort= format= contains? merged? no-merged? points-at= column? create-reflog ignore-case",
9804
+ init: "+qb:|quiet bare initial-branch= object-format= ref-format= shared? separate-git-dir=",
9805
+ add: "+AunNvf|all update intent-to-add force dry-run verbose ignore-errors ignore-removal no-all renormalize chmod= sparse",
9806
+ commit: "+m:aqsnF:C:ouv|message= all amend no-edit allow-empty allow-empty-message author= date= signoff no-verify quiet file= reuse-message= fixup= squash= only include dry-run no-gpg-sign untracked-files? cleanup= reset-author verbose",
9807
+ checkout: "+b:B:fqm|detach force orphan= quiet track? no-track merge ours theirs",
9808
+ switch: "+c:C:dfqm|create= force-create= detach discard-changes force orphan= quiet track? no-track merge",
9809
+ restore: "+s:SWq|source= staged worktree ours theirs merge quiet overlay no-overlay",
9810
+ reset: "+qN|soft mixed hard merge keep quiet no-refresh",
9811
+ rm: "+rfnq|cached force dry-run quiet ignore-unmatch",
9812
+ mv: "+fnkv|force dry-run verbose",
9813
+ merge: "+m:qvnX:|no-ff ff ff-only squash no-squash commit no-commit message= no-edit abort continue quit allow-unrelated-histories stat no-stat quiet verbose no-verify signoff strategy-option=",
9814
+ stash: "+m:ukqa|message= include-untracked keep-index quiet all index staged",
9815
+ apply: "+p:C:R3qv|check stat numstat summary index cached 3way reverse reject allow-empty exclude= include= verbose quiet whitespace= recount",
9816
+ am: "+skq3|signoff keep 3way quiet abort continue skip quit whitespace= reject",
9817
+ fetch: "+fqvptn|all depth= deepen= shallow-since= unshallow tags no-tags prune force quiet verbose dry-run update-shallow refmap=",
9818
+ clone: "+nqlsb:o:|bare no-checkout depth= branch= origin= single-branch no-single-branch no-tags quiet shared local no-local filter= separate-git-dir=",
9819
+ "cherry-pick": "+nm:sxX:|no-commit mainline= signoff abort continue skip quit allow-empty keep-redundant-commits ff strategy-option=",
9820
+ revert: "+nm:sX:|no-commit mainline= signoff abort continue skip quit strategy-option= no-edit",
9821
+ rebase: "+qvfnX:|onto= root abort continue skip quit keep-base no-ff force-rebase autosquash no-autosquash autostash no-autostash update-refs signoff quiet verbose stat no-stat committer-date-is-author-date reset-author-date rebase-merges? no-rebase-merges empty= strategy-option= apply merge",
9822
+ clean: "+dfnqxXe:|dry-run force quiet exclude=",
9823
+ bisect: "+|term-old= term-new= no-checkout first-parent"
9824
+ };
9825
+ var JUDGE_GIT = `a judge runs git ${Object.keys(GIT_VERBS).join(" ")} with the options each documents (no abbreviations), writing only in a scratch repo; no -c, no wrapper but timeout, nice, time, command, no env but PAGER=cat, GIT_PAGER=cat, GIT_OPTIONAL_LOCKS=0, LC_*, LANG, TZ; status outside scratch needs --no-optional-locks`;
9771
9826
  var JUDGE_VERBS = {
9772
9827
  check: true,
9773
9828
  dir: true,
package/dist/workit.js CHANGED
@@ -26425,7 +26425,21 @@ var gitOutputs = (args) => {
26425
26425
  if (output !== undefined)
26426
26426
  files.push(output);
26427
26427
  if (sub === "init")
26428
- files.push(names[0] ?? ".");
26428
+ files.push(names[0] ?? "./");
26429
+ if (sub === "init" || sub === "clone") {
26430
+ const separate = valueOf(rest, /^--separate-git-dir=?(.*)$/s);
26431
+ if (separate !== undefined)
26432
+ files.push(separate);
26433
+ }
26434
+ if (sub === "worktree") {
26435
+ const end = rest.includes("--") ? rest.indexOf("--") : rest.length;
26436
+ const named = [
26437
+ ...rest.slice(1, end).filter((arg, index, words) => !arg.startsWith("-") && !/^(?:-[bB]|--reason)$/.test(words[index - 1] ?? "")),
26438
+ ...rest.slice(end + 1)
26439
+ ];
26440
+ const count = { add: 1, move: 2, remove: 1, repair: named.length || 1 }[rest[0] ?? ""] ?? 0;
26441
+ files.push(...(named.length ? named : ["."]).slice(0, count));
26442
+ }
26429
26443
  if (sub === "clone")
26430
26444
  files.push(names[1] ?? names[0]?.replace(/(?:\.git)?[\\/]*$/, "").split(/[\\/:]/).at(-1) ?? ".");
26431
26445
  if (sub === "format-patch" && !has(/^--stdout$/))
@@ -26543,6 +26557,28 @@ var MUTATING_GIT = new Set([
26543
26557
  var DRY_N = new Set(["add", "clean", "rm", "mv"]);
26544
26558
  var MUTATING_WORKIT_GIT = new Set(["commit", "branch", "stage", "unstage"]);
26545
26559
  var DIR_TARGET = ".workit-live-target";
26560
+ var PLACEHOLDERS = new WeakMap;
26561
+ var collecting = null;
26562
+ var placeholderIn = (dir, name) => {
26563
+ const target = path41.join(dir, name);
26564
+ collecting?.add(target);
26565
+ return target;
26566
+ };
26567
+ var recording = (make) => {
26568
+ const outer = collecting;
26569
+ const found = new Set;
26570
+ collecting = found;
26571
+ try {
26572
+ const targets = make();
26573
+ PLACEHOLDERS.set(targets, found);
26574
+ for (const target of found)
26575
+ outer?.add(target);
26576
+ return targets;
26577
+ } finally {
26578
+ collecting = outer;
26579
+ }
26580
+ };
26581
+ var placeholdersOf = (targets) => PLACEHOLDERS.get(targets) ?? new Set;
26546
26582
  var OPAQUE_TARGET = ".workit-runs-";
26547
26583
  var UNRESOLVED_TARGET = ".workit-unresolved-target";
26548
26584
  var OVERRIDE = "WORKIT_LIVE_SESSION=override";
@@ -26814,7 +26850,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26814
26850
  return [unknownVarTarget(home)];
26815
26851
  if (path41.isAbsolute(home))
26816
26852
  return [home];
26817
- return base === undefined ? [] : [path41.resolve(base, home)];
26853
+ return base === undefined ? [] : [resolvedUnder(base, home)];
26818
26854
  });
26819
26855
  const at = (file) => {
26820
26856
  const all = atAll(file);
@@ -27046,7 +27082,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
27046
27082
  for (const file of opaque ?? [])
27047
27083
  for (const resolved of atAll(file))
27048
27084
  if (!quiet || !isRoot(resolved))
27049
- targets.push(file === "." ? path41.join(resolved, here) : resolved);
27085
+ targets.push(file === "." ? placeholderIn(resolved, here) : path41.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path41.dirname(resolved), path41.basename(resolved)) : resolved);
27050
27086
  const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
27051
27087
  const lnArgs = words.slice(ln + 1);
27052
27088
  if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)) && (strict !== "registry" || !lnArgs.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg))))
@@ -27058,7 +27094,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
27058
27094
  const edits = editsOf(body);
27059
27095
  if (edits === null) {
27060
27096
  if (dir !== undefined)
27061
- targets.push(path41.join(dir, DIR_TARGET));
27097
+ targets.push(placeholderIn(dir, DIR_TARGET));
27062
27098
  } else
27063
27099
  for (const file of edits)
27064
27100
  targets.push(...atAll(file));
@@ -27066,7 +27102,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
27066
27102
  for (const invocation of workitInvocations(body.map(quoteWord2).join(" "), "posix")) {
27067
27103
  const { at: runsIn, args } = workitCwd(dir, invocation, atAll);
27068
27104
  if (args[0] === "git" && MUTATING_WORKIT_GIT.has(args[1] ?? "") && !inert(args.slice(2), ""))
27069
- targets.push(...runsIn.map((runs) => path41.join(runs, DIR_TARGET)));
27105
+ targets.push(...runsIn.map((runs) => placeholderIn(runs, DIR_TARGET)));
27070
27106
  }
27071
27107
  }
27072
27108
  return targets;
@@ -27086,10 +27122,10 @@ var workitCwd = (dir, args, resolve) => {
27086
27122
  var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
27087
27123
  try {
27088
27124
  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]] ?? ""]) : []);
27089
- return [
27125
+ return recording(() => [
27090
27126
  ...segmentTargets(cwd, command, dialect, 0, strict, env),
27091
- ...gitMutationDirs(cwd, command, dialect).map((dir) => path41.join(dir, DIR_TARGET))
27092
- ];
27127
+ ...gitMutationDirs(cwd, command, dialect).map((dir) => placeholderIn(dir, DIR_TARGET))
27128
+ ]);
27093
27129
  } catch (error) {
27094
27130
  if (strict === "registry")
27095
27131
  throw error;
@@ -27148,7 +27184,8 @@ var claimAll = (owner, targets, deps) => {
27148
27184
  for (const target of guarded(targets))
27149
27185
  claimLiveSession(target, owner, deps);
27150
27186
  };
27151
- var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path41.resolve(cwd, file)) : [path41.join(cwd, DIR_TARGET)];
27187
+ var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path41.resolve(dir, file) : path41.isAbsolute(file) ? file : `${dir}${path41.sep}${file}`;
27188
+ var liveTargets = (cwd, paths) => recording(() => paths?.length ? paths.map((file) => resolvedUnder(cwd, file)) : [placeholderIn(cwd, DIR_TARGET)]);
27152
27189
  var CONFIG_FILES = ["workspaces.json", SEAL_FILE];
27153
27190
  var configDirs = () => [resolveConfigDir(), grantsDir()];
27154
27191
  var globbed = (cwd, target, state, configs) => {
@@ -28588,18 +28625,48 @@ import path44 from "node:path";
28588
28625
  var FANOUT_TOKEN_FILE = "workit-fanout-token";
28589
28626
  var NONE5 = { kind: "none" };
28590
28627
  var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
28591
- var canonical5 = (file) => {
28628
+ var realOf = (file) => {
28592
28629
  let rest = "";
28593
- for (let dir = path44.resolve(file);; dir = path44.dirname(dir)) {
28630
+ for (let dir = file;; dir = path44.dirname(dir)) {
28594
28631
  try {
28595
28632
  return path44.join(fs29.realpathSync.native(dir), rest);
28596
28633
  } catch {
28597
28634
  if (path44.dirname(dir) === dir)
28598
- return path44.resolve(file);
28635
+ return file;
28599
28636
  rest = rest ? path44.join(path44.basename(dir), rest) : path44.basename(dir);
28600
28637
  }
28601
28638
  }
28602
28639
  };
28640
+ var canonical5 = (file, hops = { chain: 40, total: 1000 }) => {
28641
+ const start = path44.isAbsolute(file) ? file : `${process.cwd()}${path44.sep}${file}`;
28642
+ const { root } = path44.parse(start);
28643
+ let at = root;
28644
+ let missing = false;
28645
+ for (const part of start.slice(root.length).split(/[\\/]+/)) {
28646
+ if (part === "" || part === ".")
28647
+ continue;
28648
+ if (part === "..") {
28649
+ at = path44.dirname(at);
28650
+ continue;
28651
+ }
28652
+ const next = path44.join(at, part);
28653
+ let link = null;
28654
+ if (!missing)
28655
+ try {
28656
+ link = fs29.readlinkSync(next);
28657
+ } catch (error) {
28658
+ missing = error.code !== "EINVAL";
28659
+ }
28660
+ if (link === null) {
28661
+ at = next;
28662
+ hops.chain = 40;
28663
+ } else if (hops.chain-- > 0 && hops.total-- > 0)
28664
+ at = canonical5(path44.isAbsolute(link) ? link : `${at}${path44.sep}${link}`, hops);
28665
+ else
28666
+ return path44.resolve(file);
28667
+ }
28668
+ return realOf(at);
28669
+ };
28603
28670
  var within = (child, parent) => {
28604
28671
  const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
28605
28672
  const relative = path44.relative(fold(parent), fold(child));
@@ -28609,13 +28676,8 @@ var checkoutOf2 = (file) => {
28609
28676
  for (let dir = canonical5(file);; dir = path44.dirname(dir)) {
28610
28677
  const dotGit = path44.join(dir, ".git");
28611
28678
  if (fs29.existsSync(dotGit)) {
28612
- if (!fs29.statSync(dotGit).isFile())
28613
- return { root: dir, workit: false };
28614
- const admin = /^gitdir:\s*(.+)$/mu.exec(fs29.readFileSync(dotGit, "utf8"))?.[1]?.trim();
28615
- return {
28616
- root: dir,
28617
- workit: Boolean(admin) && fs29.existsSync(path44.join(path44.resolve(dir, admin), FANOUT_TOKEN_FILE))
28618
- };
28679
+ const admin = fs29.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
28680
+ return { root: dir, workit: !!admin && fs29.existsSync(path44.join(admin, FANOUT_TOKEN_FILE)) };
28619
28681
  }
28620
28682
  if (path44.dirname(dir) === dir)
28621
28683
  return null;
@@ -28677,16 +28739,11 @@ var hostIsolated = (cwd, agentId) => {
28677
28739
  const dotGit = path44.join(checkout.root, ".git");
28678
28740
  if (!fs29.statSync(dotGit).isFile())
28679
28741
  return false;
28680
- const admin = /^gitdir:\s*(.+)$/mu.exec(fs29.readFileSync(dotGit, "utf8"))?.[1]?.trim();
28681
- if (!admin)
28682
- return false;
28683
- const adminDir = path44.resolve(checkout.root, admin);
28742
+ const [adminDir, gitDir] = gitDirsAt(checkout.root, null, false) ?? [];
28684
28743
  const back = fs29.readFileSync(path44.join(adminDir, "gitdir"), "utf8").trim();
28685
28744
  if (path44.relative(canonical5(path44.resolve(adminDir, back)), canonical5(dotGit)) !== "")
28686
28745
  return false;
28687
- const common = path44.join(adminDir, "commondir");
28688
- const gitDir = fs29.existsSync(common) ? path44.resolve(adminDir, fs29.readFileSync(common, "utf8").trim()) : adminDir;
28689
- const expected = path44.join(path44.dirname(canonical5(gitDir)), ".claude", "worktrees", `agent-${agentId}`);
28746
+ const expected = path44.join(path44.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
28690
28747
  return path44.relative(canonical5(expected), checkout.root) === "";
28691
28748
  } catch {
28692
28749
  return false;
@@ -28878,17 +28935,295 @@ var LEADS = /^(?:sudo|doas|env|command|builtin|exec|nohup|time|nice|timeout|stdb
28878
28935
  var RUNS = /^(?:sh|bash|zsh|dash|ksh|mksh|ash|python[\d.]*|node|bun|deno|ruby|perl|php|eval|source|\.|workit)$/;
28879
28936
  var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print|test|version|help)$|^-[hvV]$/;
28880
28937
  var VALUED = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
28881
- var commonDir = (root) => {
28882
- const dotGit = path44.join(root, ".git");
28883
- if (!fs29.statSync(dotGit).isFile())
28884
- return canonical5(dotGit);
28885
- const admin = path44.resolve(root, /^gitdir:\s*(.+)$/mu.exec(fs29.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "");
28886
- const common = path44.join(admin, "commondir");
28887
- return canonical5(fs29.existsSync(common) ? path44.resolve(admin, fs29.readFileSync(common, "utf8").trim()) : admin);
28888
- };
28938
+ var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
28889
28939
  var inScratch = (real, repo) => {
28890
- const checkout = checkoutOf2(real);
28891
- return checkout !== null && within(real, path44.join(checkout.root, SCRATCH)) && (repo === null || commonDir(checkout.root) === repo);
28940
+ for (let dir = real;path44.dirname(dir) !== dir; dir = path44.dirname(dir)) {
28941
+ if (path44.basename(dir) !== SCRATCH)
28942
+ continue;
28943
+ const root = path44.dirname(dir);
28944
+ if (checkoutOf2(root)?.root === root && (repo === null || commonDir(root) === repo))
28945
+ return true;
28946
+ }
28947
+ return false;
28948
+ };
28949
+ var inGitDir = (real) => real.split(/[\\/]/).includes(".git");
28950
+ var SAFE_KEY = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|ignorecase|precomposeunicode|symlinks)|user\..*|init\.defaultbranch|commit\.gpgsign|extensions\.(?:objectformat|refstorage)|branch\..*\.(?:remote|merge)|remote\..*\.fetch)$/;
28951
+ var literalIn = (value, repo, checkout = false) => {
28952
+ if (/[$`]/.test(value) || !path44.isAbsolute(value))
28953
+ return false;
28954
+ const real = canonical5(value);
28955
+ const root = checkout ? checkoutOf2(real)?.root : undefined;
28956
+ return inScratch(real, repo) || root !== undefined && (repo === null || commonDir(root) === repo);
28957
+ };
28958
+ var configEntries = (text) => {
28959
+ const entries = [];
28960
+ let section = "";
28961
+ for (const line of text.split(`
28962
+ `)) {
28963
+ const header = /^\s*\[\s*([\w.-]+)(?:\s+"([^"]*))?/.exec(line);
28964
+ const entry = /^\s*([\w-]+)\s*(?:=\s*"?(.*?)"?)?\s*$/.exec(line);
28965
+ if (header)
28966
+ section = header[2] === undefined ? header[1] : `${header[1]}.${header[2]}`;
28967
+ else if (entry)
28968
+ entries.push([`${section}.${entry[1]}`.toLowerCase(), entry[2] ?? "true"]);
28969
+ }
28970
+ return entries;
28971
+ };
28972
+ function gitDirsAt(dir, repo, scan = true) {
28973
+ for (let at = dir;; at = path44.dirname(at)) {
28974
+ const dotGit = path44.join(at, ".git");
28975
+ let gitDir = null;
28976
+ try {
28977
+ if (fs29.statSync(dotGit).isDirectory())
28978
+ gitDir = canonical5(dotGit);
28979
+ else {
28980
+ const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs29.readFileSync(dotGit, "utf8"))?.[1];
28981
+ if (!named)
28982
+ return null;
28983
+ gitDir = canonical5(path44.resolve(at, named));
28984
+ }
28985
+ } catch (error) {
28986
+ if (error.code !== "ENOENT")
28987
+ return null;
28988
+ if (["HEAD", "objects", "refs"].every((name) => fs29.existsSync(path44.join(at, name))))
28989
+ gitDir = canonical5(at);
28990
+ }
28991
+ if (gitDir !== null) {
28992
+ const common = path44.join(gitDir, "commondir");
28993
+ const shared = fs29.existsSync(common) ? canonical5(path44.resolve(gitDir, fs29.readFileSync(common, "utf8").trim())) : gitDir;
28994
+ const dirs = [gitDir, shared];
28995
+ for (const config of scan ? new Set([path44.join(gitDir, "config"), path44.join(shared, "config")]) : []) {
28996
+ let text = "";
28997
+ try {
28998
+ text = fs29.readFileSync(config, "utf8");
28999
+ } catch {
29000
+ continue;
29001
+ }
29002
+ for (const [key, value] of configEntries(text)) {
29003
+ if (key === "core.worktree")
29004
+ dirs.push(canonical5(path44.resolve(gitDir, value)));
29005
+ else if (/^remote\..*\.url$/.test(key) ? !literalIn(value, repo, true) : !SAFE_KEY.test(key))
29006
+ return null;
29007
+ }
29008
+ }
29009
+ return dirs;
29010
+ }
29011
+ if (path44.dirname(at) === at)
29012
+ return [];
29013
+ }
29014
+ }
29015
+ var DIFF_S = "psuRaWwbzU:S:G:l:M?C?B?D";
29016
+ var DIFF_L = "stat? numstat shortstat name-only name-status summary patch no-patch raw color? no-color word-diff? color-words? unified= ignore-all-space ignore-space-change ignore-blank-lines ignore-cr-at-eol diff-filter= find-renames? find-copies? no-renames relative? abbrev? diff-algorithm= ignore-space-at-eol word-diff-regex= full-index binary exit-code quiet minimal patience histogram src-prefix= dst-prefix= no-prefix dirstat? text check function-context no-ext-diff no-textconv output=";
29017
+ var LOG_S = "n:iEFPgL:";
29018
+ var LOG_L = "oneline format= pretty? graph decorate? no-decorate all branches? tags? remotes? since= until= after= before= author= committer= grep= all-match invert-grep regexp-ignore-case extended-regexp fixed-strings perl-regexp max-count= skip= first-parent no-merges merges reverse follow date= abbrev-commit no-abbrev-commit left-right cherry-pick cherry-mark boundary not topo-order date-order source simplify-by-decoration ancestry-path full-history notes? no-notes walk-reflogs mailmap use-mailmap";
29019
+ var GIT_VERBS = {
29020
+ log: "@d@l|@d @l",
29021
+ show: "@d@l|@d @l",
29022
+ diff: "@d|@d cached staged merge-base no-index",
29023
+ "diff-tree": "@drtcm|@d root stdin no-commit-id",
29024
+ "diff-index": "@dm|@d cached merge-base",
29025
+ status: "sbu?zv|short branch porcelain? long untracked-files? ignored? ignore-submodules? show-stash ahead-behind no-ahead-behind renames no-renames find-renames? column? no-column null verbose",
29026
+ "rev-parse": "q|verify short? abbrev-ref? symbolic symbolic-full-name show-toplevel show-prefix git-dir git-common-dir absolute-git-dir is-inside-work-tree is-inside-git-dir is-bare-repository show-cdup quiet all branches? tags? remotes? since= until= default= path-format= sq-quote",
29027
+ "rev-list": "@l|@l count objects? left-only right-only",
29028
+ "ls-files": "cdmoiskuvtzfx:X:|cached deleted modified others ignored stage unmerged killed directory no-empty-directory exclude-standard exclude= exclude-from= full-name abbrev? error-unmatch with-tree= eol deduplicate format= recurse-submodules sparse",
29029
+ "ls-tree": "rdtlz|long name-only name-status object-only full-name full-tree abbrev? format=",
29030
+ "cat-file": "tsepz|batch? batch-check? batch-all-objects follow-symlinks unordered buffer allow-unknown-type mailmap use-mailmap",
29031
+ blame: "L:lstfnepwbcM?C?|porcelain line-porcelain incremental root show-stats show-name show-number show-email abbrev= reverse= first-parent date= ignore-rev= ignore-revs-file= minimal contents=",
29032
+ describe: "|tags all long abbrev= contains always dirty? broken? match= exclude= first-parent exact-match candidates= debug",
29033
+ "merge-base": "a|all octopus independent is-ancestor fork-point",
29034
+ "for-each-ref": "|count= sort= format= color? shell perl python tcl points-at= merged? no-merged? contains? no-contains? ignore-case omit-empty exclude=",
29035
+ shortlog: "@lsnec|@l summary numbered email committer group= format=",
29036
+ "show-ref": "dsq|head verify heads tags branches hash? abbrev? quiet dereference exists",
29037
+ "name-rev": "|tags refs= exclude= all annotate-stdin name-only no-undefined always",
29038
+ grep: "aiIvnhHcEGFPlLzoWqwe:A:B:C:m:f:|cached untracked no-index no-exclude-standard exclude-standard recurse-submodules text ignore-case word-regexp invert-match line-number column count full-name extended-regexp basic-regexp fixed-strings perl-regexp files-with-matches name-only files-without-match null only-matching heading break show-function function-context max-depth= threads= and or not all-match quiet after-context= before-context= context= max-count= color? no-color",
29039
+ "format-patch": "@do:nNks|@d stdout output-directory= numbered no-numbered start-number= subject-prefix= root cover-letter thread? signoff attach? inline? suffix= base=",
29040
+ reflog: "@l|@l all expire= expire-unreachable= rewrite updateref stale-fix dry-run verbose",
29041
+ "count-objects": "vH|verbose human-readable",
29042
+ "check-ignore": "qvnz|quiet verbose stdin non-matching no-index",
29043
+ var: "l|",
29044
+ version: "|build-options",
29045
+ "ls-remote": "htbq|heads tags branches refs quiet exit-code get-url symref sort=",
29046
+ remote: "v|verbose",
29047
+ config: "lz|get get-all get-regexp list local name-only null type= default=",
29048
+ worktree: "fdqvzb:B:|force detach lock reason= orphan no-checkout checkout quiet track no-track guess-remote porcelain expire= verbose",
29049
+ branch: "dDmMcCfvraliu:|delete move copy force list all remotes verbose contains? merged? no-merged? points-at= show-current set-upstream-to= unset-upstream track? no-track sort= format= color? column? ignore-case create-reflog",
29050
+ tag: "lam:dfF:n?|list annotate message= file= delete force sort= format= contains? merged? no-merged? points-at= column? create-reflog ignore-case",
29051
+ init: "+qb:|quiet bare initial-branch= object-format= ref-format= shared? separate-git-dir=",
29052
+ add: "+AunNvf|all update intent-to-add force dry-run verbose ignore-errors ignore-removal no-all renormalize chmod= sparse",
29053
+ commit: "+m:aqsnF:C:ouv|message= all amend no-edit allow-empty allow-empty-message author= date= signoff no-verify quiet file= reuse-message= fixup= squash= only include dry-run no-gpg-sign untracked-files? cleanup= reset-author verbose",
29054
+ checkout: "+b:B:fqm|detach force orphan= quiet track? no-track merge ours theirs",
29055
+ switch: "+c:C:dfqm|create= force-create= detach discard-changes force orphan= quiet track? no-track merge",
29056
+ restore: "+s:SWq|source= staged worktree ours theirs merge quiet overlay no-overlay",
29057
+ reset: "+qN|soft mixed hard merge keep quiet no-refresh",
29058
+ rm: "+rfnq|cached force dry-run quiet ignore-unmatch",
29059
+ mv: "+fnkv|force dry-run verbose",
29060
+ merge: "+m:qvnX:|no-ff ff ff-only squash no-squash commit no-commit message= no-edit abort continue quit allow-unrelated-histories stat no-stat quiet verbose no-verify signoff strategy-option=",
29061
+ stash: "+m:ukqa|message= include-untracked keep-index quiet all index staged",
29062
+ apply: "+p:C:R3qv|check stat numstat summary index cached 3way reverse reject allow-empty exclude= include= verbose quiet whitespace= recount",
29063
+ am: "+skq3|signoff keep 3way quiet abort continue skip quit whitespace= reject",
29064
+ fetch: "+fqvptn|all depth= deepen= shallow-since= unshallow tags no-tags prune force quiet verbose dry-run update-shallow refmap=",
29065
+ clone: "+nqlsb:o:|bare no-checkout depth= branch= origin= single-branch no-single-branch no-tags quiet shared local no-local filter= separate-git-dir=",
29066
+ "cherry-pick": "+nm:sxX:|no-commit mainline= signoff abort continue skip quit allow-empty keep-redundant-commits ff strategy-option=",
29067
+ revert: "+nm:sX:|no-commit mainline= signoff abort continue skip quit strategy-option= no-edit",
29068
+ rebase: "+qvfnX:|onto= root abort continue skip quit keep-base no-ff force-rebase autosquash no-autosquash autostash no-autostash update-refs signoff quiet verbose stat no-stat committer-date-is-author-date reset-author-date rebase-merges? no-rebase-merges empty= strategy-option= apply merge",
29069
+ clean: "+dfnqxXe:|dry-run force quiet exclude=",
29070
+ bisect: "+|term-old= term-new= no-checkout first-parent"
29071
+ };
29072
+ var gitOperands = (args) => {
29073
+ const [verb = "", ...rest] = args;
29074
+ const spec = Object.hasOwn(GIT_VERBS, verb) ? GIT_VERBS[verb] : null;
29075
+ if (spec === null)
29076
+ return null;
29077
+ const [shorts, longs] = spec.split("|");
29078
+ const short = shorts.replace("@d", DIFF_S).replace("@l", LOG_S);
29079
+ const long = longs.replace("@d", DIFF_L).replace("@l", LOG_L).split(" ");
29080
+ const operands = [];
29081
+ for (let at = 0;at < rest.length; at++) {
29082
+ const arg = rest[at];
29083
+ if (arg === "--")
29084
+ return [...operands, ...rest.slice(at + 1)];
29085
+ if (!arg.startsWith("-") || arg === "-")
29086
+ operands.push(arg);
29087
+ else if (arg.startsWith("--")) {
29088
+ const [name] = arg.slice(2).split("=");
29089
+ const valued = arg.includes("=");
29090
+ if (long.includes(`${name}=`))
29091
+ at += valued ? 0 : 1;
29092
+ else if (!long.includes(`${name}?`) && (valued || !long.includes(name)))
29093
+ return null;
29094
+ } else if (!/^-\d+$/.test(arg))
29095
+ for (let index = 1;index < arg.length; index++) {
29096
+ const found = /[:?+]/.test(arg[index]) ? -1 : short.indexOf(arg[index]);
29097
+ if (found < 0)
29098
+ return null;
29099
+ const takes = short[found + 1];
29100
+ if (takes === ":" && index === arg.length - 1)
29101
+ at++;
29102
+ if (takes === ":" || takes === "?")
29103
+ break;
29104
+ }
29105
+ }
29106
+ return operands;
29107
+ };
29108
+ var gitKind = (args, local = () => true) => {
29109
+ const named = gitOperands(args);
29110
+ if (!named)
29111
+ return null;
29112
+ const [verb] = args;
29113
+ const [first = "", second] = named;
29114
+ const has = (pattern) => args.some((arg) => pattern.test(arg));
29115
+ switch (verb) {
29116
+ case "reflog":
29117
+ return /^(?:expire|delete)$/.test(first) ? "write" : "read";
29118
+ case "branch":
29119
+ case "tag":
29120
+ return leadOwnedGit(args) || named.length > 0 && !has(/^(?:-l|--list|--contains|--(?:no-)?merged|--points-at)$/) ? "write" : "read";
29121
+ case "config": {
29122
+ if (has(/^(?:-l|--list|--get-regexp)$/) || first === "list")
29123
+ return has(/^--local$/) ? "write" : null;
29124
+ if (has(/^--get/) || first === "get" || named.length === 1)
29125
+ return "read";
29126
+ const [key = "", value] = first === "set" ? named.slice(1) : named;
29127
+ return /^(?:user\.(?:name|email)|init\.defaultbranch)$/i.test(key) || /^commit\.gpgsign$/i.test(key) && value === "false" ? "write" : null;
29128
+ }
29129
+ case "worktree":
29130
+ return first === "list" ? "read" : /^(?:add|remove)$/.test(first) ? "write" : null;
29131
+ case "remote":
29132
+ return !first || first === "show" && named.length === 2 && local(second, true) ? "read" : null;
29133
+ case "ls-remote":
29134
+ return local(first || "origin", true) ? "read" : null;
29135
+ case "bisect":
29136
+ return /^(?:log|terms)$/.test(first) ? "read" : /^(?:start|good|bad|new|old|skip|reset)$/.test(first) ? "write" : null;
29137
+ case "blame": {
29138
+ const contents = args.findIndex((arg) => arg.startsWith("--contents"));
29139
+ const file = args[contents]?.slice(11) || args[contents + 1];
29140
+ return contents < 0 || local(file) ? "read" : null;
29141
+ }
29142
+ case "fetch":
29143
+ return !first || local(first, true) ? "write" : null;
29144
+ case "clone":
29145
+ return local(first) ? "write" : null;
29146
+ }
29147
+ return GIT_VERBS[verb].startsWith("+") ? "write" : "read";
29148
+ };
29149
+ var JUDGE_GIT = `a judge runs git ${Object.keys(GIT_VERBS).join(" ")} with the options each documents (no abbreviations), writing only in a scratch repo; no -c, no wrapper but timeout, nice, time, command, no env but PAGER=cat, GIT_PAGER=cat, GIT_OPTIONAL_LOCKS=0, LC_*, LANG, TZ; status outside scratch needs --no-optional-locks`;
29150
+ var remoteIn = (dir, name, repo) => {
29151
+ const shared = path44.isAbsolute(dir) ? gitDirsAt(canonical5(dir), repo, false)?.[1] : undefined;
29152
+ if (!shared)
29153
+ return false;
29154
+ const url = configEntries(fs29.readFileSync(path44.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
29155
+ return url !== undefined && literalIn(url, repo, true);
29156
+ };
29157
+ var judgeGit = (command, repo, depth = 0) => {
29158
+ const runsGit = /\bgit\b/.test(command);
29159
+ for (const segment of segmentsOf(command)) {
29160
+ const words = segment.words;
29161
+ let why = null;
29162
+ let at = 0;
29163
+ while (/^(?:if|then|elif|else|do|while|until|!|\{|\()$/.test(words[at] ?? ""))
29164
+ at++;
29165
+ const lead = [];
29166
+ while (/^\w+\+?=/.test(words[at] ?? ""))
29167
+ lead.push(words[at++]);
29168
+ const name = path44.basename(words[at] ?? "");
29169
+ let start = words.findIndex((word) => /(?:^|[\\/])git(?:\.exe)?(?:=|$)/.test(word));
29170
+ if (start > at) {
29171
+ if (/^(?:grep|egrep|rg|echo|printf|ls|wc|head|tail|cat|which|type|test|\[|cd|mkdir)$/.test(name) || name === "command" && /^-[vV]$/.test(words[at + 1] ?? ""))
29172
+ start = -1;
29173
+ else if (!/^(?:timeout|nice|time|command)$/.test(name) || words.slice(at + 1, start).some((word) => !/^(?:-[\w-]+|\d[\w.]*)$/.test(word)))
29174
+ why = `\`${name}\` runs git`;
29175
+ }
29176
+ if (start >= 0 && words[start].includes("="))
29177
+ why = "git is redefined";
29178
+ const run = words[start] ?? "";
29179
+ if (run.includes("/") && (!path44.isAbsolute(run) || literalIn(run, repo, true)))
29180
+ why ??= `\`${run}\` is not the system git`;
29181
+ if (segment.expands?.includes(at) && name !== "[" || /\{[^}]*,/.test(words[at] ?? ""))
29182
+ why = "the command's name is expanded by the shell";
29183
+ if (start >= 0 && (segment.expands?.length || words.some((word) => /\{[^}]*(?:,|\.\.)[^}]*\}|^~/.test(word))))
29184
+ why ??= "a word in this git command is expanded by the shell: spell it as a literal";
29185
+ if (/^(?:export|declare|local|readonly|typeset)$/.test(name))
29186
+ lead.push(...words.slice(at + 1).filter((word) => /^\w+\+?=/.test(word)));
29187
+ for (const word of runsGit ? lead : lead.filter((set) => /^(?:BASH_)?ENV=/.test(set)))
29188
+ if (!/^(?:(?:GIT_)?PAGER=cat|GIT_OPTIONAL_LOCKS=0|(?:LC_\w+|LANG|TZ)=[^$`]*)$/.test(word))
29189
+ why ??= `\`${word}\` is not allowed`;
29190
+ let index = start < 0 ? words.length : start + 1;
29191
+ let dir = "";
29192
+ let unlocked = lead.includes("GIT_OPTIONAL_LOCKS=0");
29193
+ for (;!why && words[index]?.startsWith("-") && words[index] !== "--version"; index++) {
29194
+ const word = words[index];
29195
+ const flag = /^--(git-dir|work-tree)(?:=([\s\S]*))?$/.exec(word);
29196
+ const value = flag?.[2] ?? (/^(?:-C|--git-dir|--work-tree)$/.test(word) ? words[++index] : "");
29197
+ if (word === "-C")
29198
+ dir = value;
29199
+ unlocked ||= word === "--no-optional-locks";
29200
+ if (flag ? !literalIn(value, repo) : !/^(?:-C|-P|--no-pager|--no-optional-locks)$/.test(word))
29201
+ why = `\`${word}\` is not allowed`;
29202
+ }
29203
+ const args = words[index] === "--version" ? ["version"] : words.slice(index);
29204
+ if (!why && start >= 0) {
29205
+ const local = (source, remote) => remote && /^[\w-][\w.-]*$/.test(source) ? remoteIn(dir, source, repo) : literalIn(source, repo, true);
29206
+ if (!gitKind(args, local))
29207
+ why = `\`git ${args.slice(0, 2).join(" ")}\` is not allowed`;
29208
+ else if (args[0] === "status" && !unlocked) {
29209
+ const dirs = path44.isAbsolute(dir) ? gitDirsAt(canonical5(dir), repo) : null;
29210
+ if (!dirs?.length || !dirs.every((gitDir) => inScratch(gitDir, repo)))
29211
+ why = "`git status` refreshes the index outside scratch: add --no-optional-locks";
29212
+ }
29213
+ }
29214
+ const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path44.basename(word)));
29215
+ const scripts = [
29216
+ ...words.filter((_, after) => shell >= 0 && after > shell && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(words[after - 1])),
29217
+ ...shell < 0 ? [] : segment.stdin ?? []
29218
+ ];
29219
+ if (shell > at && scripts.some((script) => /git/.test(script)) && (!/^(?:timeout|nice|time|command)$/.test(name) || words.slice(at + 1, shell).some((word) => !/^(?:-[\w-]+|\d[\w.]*)$/.test(word))))
29220
+ why ??= `\`${name}\` runs git`;
29221
+ for (const script of [...segment.subs ?? [], ...scripts])
29222
+ why ??= depth < 4 ? judgeGit(script, repo, depth + 1) : "scripts nest too deep for Workit to read";
29223
+ if (why)
29224
+ return why;
29225
+ }
29226
+ return null;
28892
29227
  };
28893
29228
  var JUDGE_VERBS = {
28894
29229
  check: true,
@@ -29039,7 +29374,7 @@ var judgeDeny = (input, what, target) => {
29039
29374
  unblock
29040
29375
  };
29041
29376
  };
29042
- function confineJudge(input, targets) {
29377
+ function confineJudge(input, targets, placeholders = placeholdersOf(targets)) {
29043
29378
  try {
29044
29379
  if (!input.session.agentId)
29045
29380
  return NONE5;
@@ -29049,7 +29384,12 @@ function confineJudge(input, targets) {
29049
29384
  const resolved = path44.resolve(target);
29050
29385
  if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
29051
29386
  return judgeDeny(input, "it writes to a path Workit cannot resolve (a variable, a command substitution or `cd -`): spell the path out");
29052
- if (inScratch(canonical5(target), repo))
29387
+ const real = canonical5(target);
29388
+ const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path44.basename(target));
29389
+ const gitDirs = runsGit ? gitDirsAt(path44.dirname(real), repo) : [];
29390
+ if (gitDirs === null)
29391
+ return judgeDeny(input, `git in ${shown(target)} uses a git dir or config Workit cannot check`);
29392
+ if (runsGit ? gitDirs.length > 0 ? gitDirs.every((dir) => inScratch(dir, repo)) : inScratch(real, repo) : inScratch(real, repo) && !inGitDir(real))
29053
29393
  continue;
29054
29394
  const runner = runnerAt(target);
29055
29395
  return judgeDeny(input, runner === null ? `${shown(target)} is outside it` : `\`${runner}\` runs in ${shown(target)}, outside it`, target);
@@ -29070,21 +29410,31 @@ function confineJudgeShell(input, command, dialect = "posix") {
29070
29410
  } catch {
29071
29411
  refused = "Workit cannot read this command: split it into simpler ones";
29072
29412
  }
29413
+ if (!refused && dialect === "posix") {
29414
+ const judged = checkoutOf2(input.cwd);
29415
+ try {
29416
+ const why = judgeGit(command, judged ? commonDir(judged.root) : null);
29417
+ if (why)
29418
+ refused = `${why}: ${JUDGE_GIT}`;
29419
+ } catch {
29420
+ refused = "Workit cannot read this command: split it into simpler ones";
29421
+ }
29422
+ }
29073
29423
  if (refused)
29074
29424
  return judgeDeny(input, refused);
29075
29425
  if (dialect === "posix" && substitutingHeredoc(command))
29076
29426
  return judgeDeny(input, "an unquoted heredoc runs the `$(…)` or backtick command in its body: quote the delimiter (<<'EOF')");
29077
29427
  let git = [];
29078
29428
  try {
29079
- git = rawInvocations(command, dialect).flatMap(({ tool, dir, args }) => tool === "git" && (args[0] === "push" || leadOwnedGit(args)) ? [
29429
+ git = rawInvocations(command, dialect).flatMap(({ tool, dir, args }) => tool === "git" && (args[0] === "push" || leadOwnedGit(args) || gitKind(args) === "write" && !/^(?:init|clone)$/.test(args[0])) ? [
29080
29430
  path44.join(dir === undefined ? UNKNOWN_DIR : path44.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
29081
29431
  ] : []);
29082
29432
  } catch {}
29083
- return confineJudge(input, [
29084
- ...shellMutationTargets(input.cwd, command, dialect, true),
29085
- ...fed.flatMap((body) => shellMutationTargets(input.cwd, body, "posix", true)),
29086
- ...git
29087
- ]);
29433
+ const lists = [
29434
+ shellMutationTargets(input.cwd, command, dialect, true),
29435
+ ...fed.map((body) => shellMutationTargets(input.cwd, body, "posix", true))
29436
+ ];
29437
+ return confineJudge(input, [...lists.flat(), ...git], new Set([...git, ...lists.flatMap((list) => [...placeholdersOf(list)])]));
29088
29438
  } catch {
29089
29439
  return NONE5;
29090
29440
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "2.4.3",
3
+ "version": "2.4.4",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",