@workit-dev/pi 1.8.1 → 1.8.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.
- package/dist/workit.js +297 -37
- 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
|
|
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
|
|
25755
|
-
if (
|
|
25756
|
-
return
|
|
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
|
|
26055
|
-
|
|
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 && /^~|[$`*?]
|
|
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
|
|
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
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
26573
|
-
|
|
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
|
|
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 &&
|
|
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
|
|
26706
|
-
|
|
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}: ${
|
|
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,
|
|
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
|
|
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(
|
|
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
|
|
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 (
|
|
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
|
|
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
|
|
29215
|
+
return readdirSync7(dir).map((name) => path45.join(dir, name));
|
|
28956
29216
|
} catch {
|
|
28957
29217
|
return [];
|
|
28958
29218
|
}
|
|
@@ -29825,7 +30085,7 @@ var observeToolResult = (event, ctx) => {
|
|
|
29825
30085
|
var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? null : promptNudge(hookInput(ctx, { kind: "context.turn", prompt }), prompt);
|
|
29826
30086
|
|
|
29827
30087
|
// packages/workit-pi/src/launches.ts
|
|
29828
|
-
import { mkdirSync as mkdirSync7, readFileSync as
|
|
30088
|
+
import { mkdirSync as mkdirSync7, readFileSync as readFileSync13, readdirSync as readdirSync8, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
29829
30089
|
import os11 from "node:os";
|
|
29830
30090
|
import path47 from "node:path";
|
|
29831
30091
|
var launchDir = (root) => {
|
|
@@ -29871,14 +30131,14 @@ var abandonedLaunches = (root) => {
|
|
|
29871
30131
|
return [];
|
|
29872
30132
|
let names;
|
|
29873
30133
|
try {
|
|
29874
|
-
names =
|
|
30134
|
+
names = readdirSync8(dir);
|
|
29875
30135
|
} catch {
|
|
29876
30136
|
return [];
|
|
29877
30137
|
}
|
|
29878
30138
|
const found = [];
|
|
29879
30139
|
for (const name of names) {
|
|
29880
30140
|
try {
|
|
29881
|
-
const attempt = JSON.parse(
|
|
30141
|
+
const attempt = JSON.parse(readFileSync13(path47.join(dir, name), "utf8"));
|
|
29882
30142
|
if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
|
|
29883
30143
|
if (!alive(attempt))
|
|
29884
30144
|
found.push(attempt);
|