@workit-dev/opencode 1.8.1 → 1.9.0
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/plugin.js +612 -42
- package/package.json +2 -2
package/dist/plugin.js
CHANGED
|
@@ -19267,7 +19267,9 @@ var tokenize = (command, dialect) => {
|
|
|
19267
19267
|
heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
|
|
19268
19268
|
else if (pending === "herestring")
|
|
19269
19269
|
(current.stdin ??= []).push(text);
|
|
19270
|
-
else if (pending
|
|
19270
|
+
else if (pending === "input")
|
|
19271
|
+
(current.inputs ??= []).push(text);
|
|
19272
|
+
else {
|
|
19271
19273
|
const at = current.words.length;
|
|
19272
19274
|
current.words.push(...MARKERS.test(word) ? expandBraces(word) : [word]);
|
|
19273
19275
|
if (expanding || !posix && word.startsWith("@"))
|
|
@@ -25554,7 +25556,7 @@ function heavyGate(cwd, command, options) {
|
|
|
25554
25556
|
}
|
|
25555
25557
|
}
|
|
25556
25558
|
// packages/workit-core/src/hooks/write-gate.ts
|
|
25557
|
-
import { existsSync as existsSync13, realpathSync as realpathSync9, statSync as statSync5 } from "node:fs";
|
|
25559
|
+
import { existsSync as existsSync13, readdirSync as readdirSync5, readFileSync as readFileSync11, realpathSync as realpathSync9, statSync as statSync5 } from "node:fs";
|
|
25558
25560
|
import os9 from "node:os";
|
|
25559
25561
|
import path40 from "node:path";
|
|
25560
25562
|
|
|
@@ -25820,9 +25822,9 @@ var editsOf = (input) => {
|
|
|
25820
25822
|
case "cp":
|
|
25821
25823
|
case "ln":
|
|
25822
25824
|
case "install": {
|
|
25823
|
-
const
|
|
25824
|
-
if (
|
|
25825
|
-
return
|
|
25825
|
+
const into = valueOf(args, /^(?:-t|--target-directory=?)(.*)$/s);
|
|
25826
|
+
if (into !== undefined)
|
|
25827
|
+
return [into];
|
|
25826
25828
|
const last = operands(args).at(-1);
|
|
25827
25829
|
return last ? [last] : null;
|
|
25828
25830
|
}
|
|
@@ -25876,6 +25878,84 @@ var editsOf = (input) => {
|
|
|
25876
25878
|
return [];
|
|
25877
25879
|
}
|
|
25878
25880
|
};
|
|
25881
|
+
var WRAPPERS2 = {
|
|
25882
|
+
sudo: "ugCDhpRrTtU",
|
|
25883
|
+
doas: "uC",
|
|
25884
|
+
env: "uCS",
|
|
25885
|
+
nice: "n",
|
|
25886
|
+
ionice: "cnp",
|
|
25887
|
+
timeout: "sk",
|
|
25888
|
+
stdbuf: "ioe",
|
|
25889
|
+
time: "fo",
|
|
25890
|
+
nohup: "",
|
|
25891
|
+
command: "",
|
|
25892
|
+
exec: "a",
|
|
25893
|
+
setsid: "",
|
|
25894
|
+
builtin: "",
|
|
25895
|
+
"!": "",
|
|
25896
|
+
npx: "p",
|
|
25897
|
+
bunx: "p"
|
|
25898
|
+
};
|
|
25899
|
+
var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
|
|
25900
|
+
var isConfigDir = (file) => configDirs().some((dir) => canonical3(dir) === canonical3(file));
|
|
25901
|
+
var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test(path40.relative(canonical3(resolveStateDir()), canonical3(file)));
|
|
25902
|
+
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)$/;
|
|
25903
|
+
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)$/;
|
|
25904
|
+
var PATH_CALLS = /^(?:join|resolve|normalize|abspath|expanduser|expandvars|Path|PurePath|fspath)$/;
|
|
25905
|
+
var readsRoot = (text, at) => {
|
|
25906
|
+
let call;
|
|
25907
|
+
for (let index = at, depth = 0;index > 0 && call === undefined; index--) {
|
|
25908
|
+
const char = text[index - 1];
|
|
25909
|
+
if (char === ")")
|
|
25910
|
+
depth++;
|
|
25911
|
+
else if (char === "(" && depth-- === 0)
|
|
25912
|
+
call = /([\w$]+)\s*$/.exec(text.slice(0, index - 1))?.[1] ?? "";
|
|
25913
|
+
else if (depth <= 0 && /[;\n]/.test(char))
|
|
25914
|
+
break;
|
|
25915
|
+
}
|
|
25916
|
+
if (call !== undefined && READ_CALLS.test(call))
|
|
25917
|
+
return true;
|
|
25918
|
+
if (call !== undefined && !PATH_CALLS.test(call))
|
|
25919
|
+
return false;
|
|
25920
|
+
return ![...text.matchAll(/([\w$]+)\s*\(/g)].some(([, name]) => MUTATING_CALLS.test(name));
|
|
25921
|
+
};
|
|
25922
|
+
var inertEdit = (command) => command.split("|").every((part) => /^:?(?:se(?:t)?|sy(?:ntax)?|colo(?:rscheme)?)(?:\s|$)|^[/?][^/?]*[/?]?$|^\d+$/.test(part.trim()));
|
|
25923
|
+
var SCRIPT_OPTIONS = [
|
|
25924
|
+
[/^(?:(?:ba|z|k|da)?sh|source|\.)$/, /^(?:[-+][oO]|--(?:rcfile|init-file))$/],
|
|
25925
|
+
[/^python/, /^-[WXQ]$/],
|
|
25926
|
+
[
|
|
25927
|
+
/./,
|
|
25928
|
+
/^(?:-[rCI]|--(?:require|import|(?:experimental-)?loader|preload|input-type|conditions|title|cwd|tsconfig|project|env-file|config))$/
|
|
25929
|
+
]
|
|
25930
|
+
];
|
|
25931
|
+
var PRELOAD = /^(?:-r|--(?:require|import|(?:experimental-)?loader|preload|rcfile|init-file))$/;
|
|
25932
|
+
var scriptArgs = (verb, args) => {
|
|
25933
|
+
const takes = SCRIPT_OPTIONS.find(([family]) => family.test(verb))?.[1] ?? /^$/;
|
|
25934
|
+
const preloads = [];
|
|
25935
|
+
for (let at = 0;at < args.length; at++) {
|
|
25936
|
+
const [option, value] = args[at].split(/=(.*)/s);
|
|
25937
|
+
if (value !== undefined && PRELOAD.test(option))
|
|
25938
|
+
preloads.push(value);
|
|
25939
|
+
else if (/^-[mce]$|^--(?:eval|print)$/.test(option))
|
|
25940
|
+
break;
|
|
25941
|
+
else if (takes.test(option)) {
|
|
25942
|
+
if (PRELOAD.test(option))
|
|
25943
|
+
preloads.push(args[at + 1] ?? "");
|
|
25944
|
+
at++;
|
|
25945
|
+
} else if (!/^[-+]/.test(option) && option !== "run")
|
|
25946
|
+
return { named: args[at], preloads };
|
|
25947
|
+
}
|
|
25948
|
+
return { preloads };
|
|
25949
|
+
};
|
|
25950
|
+
var unwrapped = (words) => {
|
|
25951
|
+
let at = 0;
|
|
25952
|
+
for (let takes;(takes = WRAPPERS2[words[at]?.split(/[\\/]/).at(-1) ?? ""]) !== undefined; ) {
|
|
25953
|
+
at++;
|
|
25954
|
+
while (at < words.length && /^-|^\w+=|^\d[\w.]*$/.test(words[at]))
|
|
25955
|
+
at += words[at].length === 2 && words[at][0] === "-" && takes.includes(words[at][1]) ? 2 : 1;
|
|
25956
|
+
}
|
|
25957
|
+
return at ? words.slice(at) : null;
|
|
25958
|
+
};
|
|
25879
25959
|
var shellScript2 = (words) => {
|
|
25880
25960
|
if (!SCRIPT_SHELLS.has((words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()))
|
|
25881
25961
|
return null;
|
|
@@ -26120,9 +26200,8 @@ var gitOutputs = (args) => {
|
|
|
26120
26200
|
const under = (file) => file === "." ? `${base}/${OPAQUE_TARGET}git` : /^[/~$]|^[A-Za-z]:[\\/]/.test(file) ? file : `${base}/${file}`;
|
|
26121
26201
|
return files.length ? files.map(under) : null;
|
|
26122
26202
|
};
|
|
26123
|
-
var
|
|
26124
|
-
|
|
26125
|
-
].map((match) => match[0]);
|
|
26203
|
+
var PATHS = /(?<![\w.~:/$-])(?:~\/|\/|[A-Za-z]:\/|\.\.(?:\/|$))[^\s'"`$),;:*?<>|\\[\]{}]*/g;
|
|
26204
|
+
var pathsIn = (text) => [...text.matchAll(PATHS)].map((match) => match[0]);
|
|
26126
26205
|
var linkSources = (args, at) => {
|
|
26127
26206
|
const names = operands([...args]);
|
|
26128
26207
|
const into = args.indexOf("-t");
|
|
@@ -26249,12 +26328,12 @@ var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
|
|
|
26249
26328
|
var PUSHD2 = new Set(["pushd", "push-location"]);
|
|
26250
26329
|
var POPD2 = new Set(["popd", "pop-location"]);
|
|
26251
26330
|
var UNKNOWN_DIR = path40.resolve(path40.parse(process.cwd()).root, ".workit-unknown-dir");
|
|
26252
|
-
var cdInto = (dir, words, strict = false, vars = new Map) => {
|
|
26331
|
+
var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
|
|
26253
26332
|
const lost = strict ? UNKNOWN_DIR : undefined;
|
|
26254
26333
|
const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
26255
26334
|
const named = found === undefined ? undefined : expandVars(found, vars);
|
|
26256
26335
|
const target = named === undefined ? undefined : homeExpanded(named);
|
|
26257
|
-
if (target === "-" || target && /^~|[$`*?]
|
|
26336
|
+
if (target === "-" || target && (globs ? /^~|[$`]/ : /^~|[$`*?]/).test(target))
|
|
26258
26337
|
return lost;
|
|
26259
26338
|
if (dir === undefined)
|
|
26260
26339
|
return lost;
|
|
@@ -26277,7 +26356,8 @@ var assignmentsOf = (words) => {
|
|
|
26277
26356
|
var commandWords = (words) => {
|
|
26278
26357
|
let start = 0;
|
|
26279
26358
|
while (start < words.length && COMPOUND.has(words[start]))
|
|
26280
|
-
start
|
|
26359
|
+
if (words[start++] === "function")
|
|
26360
|
+
start++;
|
|
26281
26361
|
return words.slice(start);
|
|
26282
26362
|
};
|
|
26283
26363
|
var REBINDS_ANY = new Set([
|
|
@@ -26429,7 +26509,8 @@ var expansions = (text, vars, loops) => {
|
|
|
26429
26509
|
last = match.index + match[0].length;
|
|
26430
26510
|
const value = vars.get(name);
|
|
26431
26511
|
const values = loops.get(name) ?? (value === undefined ? null : [value]);
|
|
26432
|
-
const
|
|
26512
|
+
const fallback = /^:?[-=](.*)$/s.exec(match[2] ?? "")?.[1];
|
|
26513
|
+
const applied = values?.flatMap((item) => fallback === undefined ? [applyOperator(item, match[2] ?? "")] : item === "" ? expansions(fallback, vars, loops) : [item]);
|
|
26433
26514
|
const fits = applied && results.length * applied.length <= MAX_EXPANSIONS2;
|
|
26434
26515
|
results = fits && applied.every((item) => item !== null) ? results.flatMap((prefix) => applied.map((item) => prefix + literal + item)) : results.map((prefix) => prefix + literal + match[0]);
|
|
26435
26516
|
}
|
|
@@ -26475,6 +26556,7 @@ var homeExpanded = (file) => {
|
|
|
26475
26556
|
};
|
|
26476
26557
|
var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherited = new Map) => {
|
|
26477
26558
|
const targets = [];
|
|
26559
|
+
const written = new Map;
|
|
26478
26560
|
let dir = cwd;
|
|
26479
26561
|
let stack = [];
|
|
26480
26562
|
const segments = segmentsOf(command, dialect);
|
|
@@ -26537,6 +26619,8 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26537
26619
|
continue;
|
|
26538
26620
|
}
|
|
26539
26621
|
const body = commandWords(segment.words);
|
|
26622
|
+
const before = segments[segments.indexOf(segment) - 1];
|
|
26623
|
+
const feeder = before?.pipe ? before : undefined;
|
|
26540
26624
|
const keywords = segment.words.length - body.length;
|
|
26541
26625
|
for (const keyword of segment.words.slice(0, keywords))
|
|
26542
26626
|
if (OPENS.has(keyword))
|
|
@@ -26590,7 +26674,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26590
26674
|
}
|
|
26591
26675
|
const plain = !segment.conditional;
|
|
26592
26676
|
if (CD2.has(name)) {
|
|
26593
|
-
dir = cdInto(dir, words, strict, vars);
|
|
26677
|
+
dir = cdInto(dir, words, Boolean(strict), vars, strict === "registry");
|
|
26594
26678
|
moved(plain);
|
|
26595
26679
|
continue;
|
|
26596
26680
|
}
|
|
@@ -26601,7 +26685,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26601
26685
|
}
|
|
26602
26686
|
if (PUSHD2.has(name)) {
|
|
26603
26687
|
stack.push(dir);
|
|
26604
|
-
dir = cdInto(dir, words, strict, vars);
|
|
26688
|
+
dir = cdInto(dir, words, Boolean(strict), vars, strict === "registry");
|
|
26605
26689
|
moved(plain);
|
|
26606
26690
|
continue;
|
|
26607
26691
|
}
|
|
@@ -26610,15 +26694,94 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26610
26694
|
moved(plain);
|
|
26611
26695
|
continue;
|
|
26612
26696
|
}
|
|
26613
|
-
const
|
|
26697
|
+
const literal = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
|
|
26698
|
+
const held = literal !== null && strict === "registry" ? expansions(literal, vars, loops) : [];
|
|
26699
|
+
const inner = held.length === 1 ? held[0] : literal;
|
|
26614
26700
|
const unPwd = () => new Map([...vars].filter(([key]) => key !== "PWD"));
|
|
26615
26701
|
if (inner !== null && dir !== undefined)
|
|
26616
26702
|
for (const runIn of workitRunDir(dir, words, atAll))
|
|
26617
26703
|
targets.push(...segmentTargets(runIn, inner, "posix", depth + 1, strict, runIn === dir ? vars : unPwd()));
|
|
26704
|
+
const bare = strict === "registry" && depth < 4 ? unwrapped(words) : null;
|
|
26705
|
+
if (bare?.length && dir !== undefined)
|
|
26706
|
+
targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
|
|
26707
|
+
if (strict === "registry" && dir !== undefined && depth < 4) {
|
|
26708
|
+
const run = words.slice(Math.max(0, words.findIndex((word) => !PREFIXES2.has(word))));
|
|
26709
|
+
const [verb = "", ...args] = run.map((word, index) => index ? word : (word.split(/[\\/]/).at(-1) ?? "").toLowerCase());
|
|
26710
|
+
const fed = segment.stdin?.join(`
|
|
26711
|
+
`);
|
|
26712
|
+
if (fed !== undefined)
|
|
26713
|
+
for (const file of segment.redirects)
|
|
26714
|
+
for (const into of atAll(file))
|
|
26715
|
+
written.set(into, fed);
|
|
26716
|
+
const read = (file) => atAll(file).flatMap((script) => {
|
|
26717
|
+
const made = written.get(script);
|
|
26718
|
+
if (made !== undefined)
|
|
26719
|
+
return [made];
|
|
26720
|
+
try {
|
|
26721
|
+
const stat = statSync5(script);
|
|
26722
|
+
const text = stat.isFile() && stat.size <= 262144 ? readFileSync11(script, "utf8") : "\x00";
|
|
26723
|
+
return text.includes("\x00") ? [] : [text];
|
|
26724
|
+
} catch {
|
|
26725
|
+
return [];
|
|
26726
|
+
}
|
|
26727
|
+
});
|
|
26728
|
+
const { named: operand, preloads } = scriptArgs(verb, args);
|
|
26729
|
+
const named = operand === "/dev/stdin" ? undefined : operand;
|
|
26730
|
+
const maker = feeder ? commandWords(feeder.words) : [];
|
|
26731
|
+
const [format = "", ...values] = maker.slice(1);
|
|
26732
|
+
let filled = 0;
|
|
26733
|
+
const printed = format.replace(/%[sbq]/g, () => values[filled++] ?? "");
|
|
26734
|
+
const piped = /^(?:echo|printf)$/.test(maker[0] ?? "") ? [[maker[0] === "printf" ? printed : format, ...values].join(`
|
|
26735
|
+
`).replaceAll("\\n", `
|
|
26736
|
+
`)] : maker[0] === "cat" ? [...feeder?.stdin ?? [], ...operands(maker.slice(1)).flatMap(read)] : [];
|
|
26737
|
+
const inputs = (segment.inputs ?? []).filter((file) => file !== "/dev/null");
|
|
26738
|
+
const shells = verb === "eval" ? [args.join(" ")] : verb === "trap" ? args.slice(0, 1) : verb === "alias" ? args.map((arg) => arg.replace(/^[^=]*=/, "")) : [];
|
|
26739
|
+
const others = [];
|
|
26740
|
+
if (SCRIPT_SHELLS.has(verb) || verb === "." || verb === "source") {
|
|
26741
|
+
if (named === undefined && shellScript2(run) === null)
|
|
26742
|
+
shells.push(...segment.stdin ?? [], ...inputs.flatMap(read), ...piped);
|
|
26743
|
+
else if (named !== undefined && shellScript2(run) === null)
|
|
26744
|
+
shells.push(...read(named));
|
|
26745
|
+
shells.push(...preloads.flatMap(read));
|
|
26746
|
+
} else if (INTERPRETERS.test(verb)) {
|
|
26747
|
+
const code = args.findIndex((arg) => /^-[a-zA-Z]*[ce]$|^--eval$/.test(arg));
|
|
26748
|
+
if (code >= 0)
|
|
26749
|
+
others.push(...expansions(args[code + 1] ?? "", vars, loops));
|
|
26750
|
+
others.push(...named === undefined ? [...segment.stdin ?? [], ...inputs.flatMap(read), ...piped] : read(named), ...preloads.flatMap(read));
|
|
26751
|
+
} else if (/[\\/]/.test(run[0] ?? ""))
|
|
26752
|
+
for (const text of read(run[0]))
|
|
26753
|
+
(/^#!.*\b(?:python|node|bun|deno|ruby|perl|php)/.test(text) ? others : shells).push(text);
|
|
26754
|
+
for (const script of shells)
|
|
26755
|
+
targets.push(...segmentTargets(dir, script, "posix", depth + 1, strict, vars));
|
|
26756
|
+
for (const raw of others) {
|
|
26757
|
+
const text = raw.replace(/^\s*(?:#(?!!)|\/\/|\/?\*).*$/gm, "");
|
|
26758
|
+
const joined = [
|
|
26759
|
+
...text.matchAll(/(?:["'][^"'\s,*?[]+["']\s*[,/+]\s*)+["'][^"'\s,*?[]+["']/g)
|
|
26760
|
+
].map(({ 0: literals, index }) => ({
|
|
26761
|
+
word: literals.replace(/["']\s*[,/+]\s*["']/g, "/").replace(/["']/g, ""),
|
|
26762
|
+
index
|
|
26763
|
+
}));
|
|
26764
|
+
const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
|
|
26765
|
+
const under = (word) => homes ? [path40.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
|
|
26766
|
+
const found = [
|
|
26767
|
+
...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
|
|
26768
|
+
...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
|
|
26769
|
+
];
|
|
26770
|
+
for (const { file, index } of found)
|
|
26771
|
+
if (!isRoot(file) || !readsRoot(text, index))
|
|
26772
|
+
targets.push(file);
|
|
26773
|
+
}
|
|
26774
|
+
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"))))
|
|
26775
|
+
for (const file of operands(args))
|
|
26776
|
+
targets.push(...atAll(file));
|
|
26777
|
+
if (verb === "cp" && args.some((arg) => /^-[a-zA-Z]*l|^--link$/.test(arg)))
|
|
26778
|
+
for (const file of operands(args).slice(0, -1))
|
|
26779
|
+
targets.push(...atAll(file));
|
|
26780
|
+
}
|
|
26618
26781
|
if (strict && dir !== undefined) {
|
|
26619
26782
|
const runIn = dir;
|
|
26620
26783
|
for (const sub of depth < 4 ? segment.subs ?? [] : [])
|
|
26621
|
-
targets.push(...segmentTargets(runIn, sub, dialect, depth + 1,
|
|
26784
|
+
targets.push(...segmentTargets(runIn, sub, dialect, depth + 1, strict, vars));
|
|
26622
26785
|
const expanding = new Set(segment.expands ?? []);
|
|
26623
26786
|
const scriptOf = (index) => {
|
|
26624
26787
|
const word = body[index];
|
|
@@ -26634,12 +26797,15 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26634
26797
|
if (runner !== undefined && expanding.has(keywords + lead + ran) && unresolvedRefs(homeExpanded(runner)).length > 0)
|
|
26635
26798
|
targets.push(unknownVarTarget(runner));
|
|
26636
26799
|
const here = segment.unanalyzable ? DIR_TARGET : `${OPAQUE_TARGET}${encodeURIComponent(runner?.split(/[\\/]/).at(-1) ?? "a command")}`;
|
|
26800
|
+
const quiet = strict === "registry" && INTERPRETERS.test(runner?.split(/[\\/]/).at(-1) ?? "");
|
|
26637
26801
|
for (const file of opaque ?? [])
|
|
26638
26802
|
for (const resolved of atAll(file))
|
|
26639
|
-
|
|
26803
|
+
if (!quiet || !isRoot(resolved))
|
|
26804
|
+
targets.push(file === "." ? path40.join(resolved, here) : resolved);
|
|
26640
26805
|
const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
|
|
26641
|
-
|
|
26642
|
-
|
|
26806
|
+
const lnArgs = words.slice(ln + 1);
|
|
26807
|
+
if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)) && (strict !== "registry" || !lnArgs.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg))))
|
|
26808
|
+
targets.push(...linkSources(lnArgs, at));
|
|
26643
26809
|
}
|
|
26644
26810
|
for (const file of segment.redirects)
|
|
26645
26811
|
if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file))
|
|
@@ -26674,11 +26840,14 @@ var workitCwd = (dir, args, resolve) => {
|
|
|
26674
26840
|
};
|
|
26675
26841
|
var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
|
|
26676
26842
|
try {
|
|
26843
|
+
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]] ?? ""]) : []);
|
|
26677
26844
|
return [
|
|
26678
|
-
...segmentTargets(cwd, command, dialect, 0, strict),
|
|
26845
|
+
...segmentTargets(cwd, command, dialect, 0, strict, env),
|
|
26679
26846
|
...gitMutationDirs(cwd, command, dialect).map((dir) => path40.join(dir, DIR_TARGET))
|
|
26680
26847
|
];
|
|
26681
|
-
} catch {
|
|
26848
|
+
} catch (error) {
|
|
26849
|
+
if (strict === "registry")
|
|
26850
|
+
throw error;
|
|
26682
26851
|
return [];
|
|
26683
26852
|
}
|
|
26684
26853
|
};
|
|
@@ -26736,12 +26905,79 @@ var claimAll = (owner, targets, deps) => {
|
|
|
26736
26905
|
};
|
|
26737
26906
|
var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path40.resolve(cwd, file)) : [path40.join(cwd, DIR_TARGET)];
|
|
26738
26907
|
var configDirs = () => [resolveConfigDir(), grantsDir()];
|
|
26908
|
+
var globbed = (cwd, target, state, configs) => {
|
|
26909
|
+
if (!/[*?[]/.test(target))
|
|
26910
|
+
return [];
|
|
26911
|
+
const raw = path40.resolve(cwd, target).split(path40.sep);
|
|
26912
|
+
const literal = raw.findIndex((part) => /[*?[]/.test(part));
|
|
26913
|
+
const pattern = [
|
|
26914
|
+
...canonical3(raw.slice(0, literal).join(path40.sep) || path40.sep).replace(/[\\/]+$/, "").split(path40.sep),
|
|
26915
|
+
...raw.slice(literal)
|
|
26916
|
+
];
|
|
26917
|
+
const segment = (glob, name) => {
|
|
26918
|
+
try {
|
|
26919
|
+
return new RegExp(`^${glob.startsWith(".") ? "" : "(?!\\.)"}${glob.replace(/[.+^$(){}|\\]/g, "\\$&").replace(/\[!/g, "[^").replaceAll("*", ".*").replaceAll("?", ".")}$`, CASE_INSENSITIVE ? "i" : "").test(name);
|
|
26920
|
+
} catch {
|
|
26921
|
+
return false;
|
|
26922
|
+
}
|
|
26923
|
+
};
|
|
26924
|
+
const hit = (file, below) => {
|
|
26925
|
+
const parts = canonical3(file).split(path40.sep);
|
|
26926
|
+
return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
|
|
26927
|
+
};
|
|
26928
|
+
let roots = [];
|
|
26929
|
+
try {
|
|
26930
|
+
roots = readdirSync5(state).filter((name) => /^(?:issued|approvals$)/.test(name));
|
|
26931
|
+
} catch {}
|
|
26932
|
+
return [
|
|
26933
|
+
...roots.map((name) => path40.join(state, name)).filter((root) => hit(root, true)),
|
|
26934
|
+
...configs.flatMap((dir) => [dir, path40.join(dir, "workspaces.json")]).filter((file) => hit(file, false))
|
|
26935
|
+
];
|
|
26936
|
+
};
|
|
26937
|
+
var guardedInodes = (state, configs) => {
|
|
26938
|
+
const seen = new Map;
|
|
26939
|
+
let budget = 2000;
|
|
26940
|
+
const add = (file, registry) => {
|
|
26941
|
+
if (budget-- <= 0)
|
|
26942
|
+
return;
|
|
26943
|
+
const stat = statSync5(file, { throwIfNoEntry: false });
|
|
26944
|
+
if (stat?.isFile())
|
|
26945
|
+
seen.set(`${stat.dev}:${stat.ino}`, registry);
|
|
26946
|
+
else if (stat?.isDirectory())
|
|
26947
|
+
for (const name of readdirSync5(file))
|
|
26948
|
+
add(path40.join(file, name), registry);
|
|
26949
|
+
};
|
|
26950
|
+
try {
|
|
26951
|
+
for (const dir of configs)
|
|
26952
|
+
add(path40.join(dir, "workspaces.json"), "grants");
|
|
26953
|
+
for (const name of readdirSync5(state))
|
|
26954
|
+
if (/^(?:issued|approvals$)/.test(name))
|
|
26955
|
+
add(path40.join(state, name), name === "approvals" ? "approvals" : "issued");
|
|
26956
|
+
} catch {}
|
|
26957
|
+
return seen;
|
|
26958
|
+
};
|
|
26959
|
+
var hardLinked = (file, state, configs, inodes) => {
|
|
26960
|
+
try {
|
|
26961
|
+
const stat = statSync5(file, { throwIfNoEntry: false });
|
|
26962
|
+
if (!stat?.isFile() || stat.nlink < 2 || !stat.ino)
|
|
26963
|
+
return;
|
|
26964
|
+
inodes.map ??= guardedInodes(state, configs);
|
|
26965
|
+
return inodes.map.get(`${stat.dev}:${stat.ino}`);
|
|
26966
|
+
} catch {
|
|
26967
|
+
return;
|
|
26968
|
+
}
|
|
26969
|
+
};
|
|
26739
26970
|
var registryTarget = (cwd, targets) => {
|
|
26740
26971
|
const state = resolveStateDir();
|
|
26741
26972
|
const configs = configDirs();
|
|
26973
|
+
const inodes = {};
|
|
26742
26974
|
for (const target of targets) {
|
|
26743
26975
|
const file = homeExpanded(target);
|
|
26744
|
-
const
|
|
26976
|
+
const glob = globbed(cwd, file, state, configs)[0];
|
|
26977
|
+
const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
|
|
26978
|
+
if (viaGlob)
|
|
26979
|
+
return { file: target, registry: viaGlob.registry };
|
|
26980
|
+
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);
|
|
26745
26981
|
if (registry)
|
|
26746
26982
|
return { file: target, registry };
|
|
26747
26983
|
}
|
|
@@ -26763,7 +26999,7 @@ var underRegistry = (state, cwd, target, platform = process.platform, real = (fi
|
|
|
26763
26999
|
};
|
|
26764
27000
|
var underConfig = (dir, cwd, target, platform = process.platform, real = (file) => file) => {
|
|
26765
27001
|
const parts = partsUnder(dir, cwd, target, platform, real);
|
|
26766
|
-
return parts?.length === 1 &&
|
|
27002
|
+
return parts?.length === 1 && ["", "workspaces.json", DIR_TARGET].includes(parts[0]);
|
|
26767
27003
|
};
|
|
26768
27004
|
var unquotedWindowsRegistry = (command, platform = process.platform) => {
|
|
26769
27005
|
if (platform !== "win32" || !command.includes("\\"))
|
|
@@ -26771,8 +27007,21 @@ var unquotedWindowsRegistry = (command, platform = process.platform) => {
|
|
|
26771
27007
|
const flat = (value) => value.replaceAll("\\", "/").toLowerCase();
|
|
26772
27008
|
const text = flat(command);
|
|
26773
27009
|
const state = flat(resolveStateDir());
|
|
26774
|
-
const
|
|
26775
|
-
|
|
27010
|
+
const configs = configDirs().map(flat);
|
|
27011
|
+
const registry = text.includes(`${state}/issued`) ? "issued" : text.includes(`${state}/approvals`) ? "approvals" : configs.some((dir) => text.includes(dir)) ? "grants" : null;
|
|
27012
|
+
if (!registry)
|
|
27013
|
+
return null;
|
|
27014
|
+
const spans = command.replace(/[^\s'"|;&<>()]*\\[^\s'"|;&<>()]*/g, (word) => word.replaceAll("\\", "/"));
|
|
27015
|
+
const writes = shellWrites(spans);
|
|
27016
|
+
const moved = [
|
|
27017
|
+
"",
|
|
27018
|
+
...[...spans.matchAll(/(?:^|[;&|(]\s*)(?:cd|pushd|chdir)\s+([^\s;&|)]+)/g)].map((match) => `${match[1]}/`)
|
|
27019
|
+
];
|
|
27020
|
+
const named = (target) => moved.some((dir) => {
|
|
27021
|
+
const at = flat(/^(?:[a-z]:)?\//i.test(target) ? target : dir + target).replace(/\/\.?\//g, "/");
|
|
27022
|
+
return registry === "grants" ? configs.some((cfg) => [cfg, `${cfg}/`, `${cfg}/workspaces.json`].includes(at)) : at.includes(`${state}/${registry}`);
|
|
27023
|
+
});
|
|
27024
|
+
return writes.writes && (writes.targets === null || writes.targets.some(named)) ? registry : null;
|
|
26776
27025
|
};
|
|
26777
27026
|
var REGISTRY_DENY = {
|
|
26778
27027
|
issued: {
|
|
@@ -26793,9 +27042,10 @@ var REGISTRY_DENY = {
|
|
|
26793
27042
|
};
|
|
26794
27043
|
var registryDeny = ({ file, registry }) => {
|
|
26795
27044
|
const { label, what, unblock } = REGISTRY_DENY[registry];
|
|
27045
|
+
const named = path40.basename(file).startsWith(".workit-") ? path40.dirname(file) : file;
|
|
26796
27046
|
return {
|
|
26797
27047
|
kind: "deny",
|
|
26798
|
-
reason: `workit ${label}: ${
|
|
27048
|
+
reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
|
|
26799
27049
|
unblock
|
|
26800
27050
|
};
|
|
26801
27051
|
};
|
|
@@ -26817,10 +27067,20 @@ function writeGate(cwd, paths, owner, deps) {
|
|
|
26817
27067
|
function shellGate(cwd, command, owner, dialect = "posix", deps) {
|
|
26818
27068
|
try {
|
|
26819
27069
|
const windows = unquotedWindowsRegistry(command);
|
|
26820
|
-
const forged = registryTarget(cwd,
|
|
27070
|
+
const forged = registryTarget(cwd, shellMutationTargets(cwd, command, dialect, "registry")) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
|
|
26821
27071
|
if (forged)
|
|
26822
27072
|
return registryDeny(forged);
|
|
26823
|
-
} catch {
|
|
27073
|
+
} catch {
|
|
27074
|
+
const text = command.replaceAll("\\", "/").replace(/['"]/g, "").toLowerCase();
|
|
27075
|
+
if (/issued|approvals|workspaces\.json|\.config\/workit|state\/workit/.test(text) || [resolveStateDir(), ...configDirs()].some((dir) => text.includes(dir.replaceAll("\\", "/").toLowerCase()))) {
|
|
27076
|
+
const { unblock } = REGISTRY_DENY.grants;
|
|
27077
|
+
return {
|
|
27078
|
+
kind: "deny",
|
|
27079
|
+
reason: `workit registry guard: Workit could not analyse this command, which names a guarded path; split it into plain commands. ${unblock}`,
|
|
27080
|
+
unblock
|
|
27081
|
+
};
|
|
27082
|
+
}
|
|
27083
|
+
}
|
|
26824
27084
|
const writes = shellWrites(command);
|
|
26825
27085
|
let targets = [];
|
|
26826
27086
|
if (owner)
|
|
@@ -28223,11 +28483,318 @@ var SCAN_MS = 30 * 60000;
|
|
|
28223
28483
|
// packages/workit-core/src/hooks/agent-model.ts
|
|
28224
28484
|
var UNLISTED = new Set(["description", "prompt"]);
|
|
28225
28485
|
|
|
28486
|
+
// packages/workit-core/src/hooks/ytrack-word.ts
|
|
28487
|
+
var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
|
|
28488
|
+
var namesYtrack = (text) => {
|
|
28489
|
+
const bare = text.replace(/['"\\]/g, "");
|
|
28490
|
+
return YTRACK_WORD.test(bare) || YTRACK_WORD.test(bare.replace(/`/g, ""));
|
|
28491
|
+
};
|
|
28492
|
+
|
|
28493
|
+
// packages/workit-core/src/hooks/ytrack-guard.ts
|
|
28494
|
+
var name2 = (word = "") => (word.split(/[\\/]/).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd)$|@.*$/g, "");
|
|
28495
|
+
var quote2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
|
|
28496
|
+
var minutesOf = (text = "") => {
|
|
28497
|
+
if (/^\d+$/.test(text.trim()))
|
|
28498
|
+
return Number(text) > 0 ? Number(text) : null;
|
|
28499
|
+
let total = 0;
|
|
28500
|
+
const rest = text.replace(/(\d+(?:\.\d+)?)\s*(h|hours?|m|mins?|minutes?)(?![a-z])/gi, (_, n, unit) => {
|
|
28501
|
+
total += Number(n) * (/^h/i.test(unit) ? 60 : 1);
|
|
28502
|
+
return "";
|
|
28503
|
+
});
|
|
28504
|
+
return rest.trim() || !Number.isInteger(total) || total <= 0 ? null : total;
|
|
28505
|
+
};
|
|
28506
|
+
var VALUE = new Set(("--host --body -b --body-file --text --date --duration --type --project -p --summary -s " + "--description --description-file --field --tag --add-tag --remove-tag --assignee --comment " + "--json --jq -X --method -f -F --raw-field --input --fields -q --query --author --since --limit").split(" "));
|
|
28507
|
+
var BARE = new Set("--debug --no-color --paginate --include --dry-run --silent --yes --meeting --help -h".split(" "));
|
|
28508
|
+
var standsAlone = (args, at) => {
|
|
28509
|
+
const before = args[at - 1] ?? "";
|
|
28510
|
+
const end = args.indexOf("--");
|
|
28511
|
+
return (end < 0 || at < end) && (!before.startsWith("-") || before.includes("=") || BARE.has(before));
|
|
28512
|
+
};
|
|
28513
|
+
var flagged = (args, flag) => args.some((arg, at) => flag.test(arg) && standsAlone(args, at));
|
|
28514
|
+
var asksHelp2 = (args) => flagged(args, /^(?:--help|-h)$/);
|
|
28515
|
+
var GROUPS = {
|
|
28516
|
+
issue: "issue",
|
|
28517
|
+
"work-item": "work-item",
|
|
28518
|
+
workitem: "work-item",
|
|
28519
|
+
api: "api"
|
|
28520
|
+
};
|
|
28521
|
+
var ASKS = /^(?:post|put|patch|delete)$/i;
|
|
28522
|
+
var BODY = /^(?:-[fF]|--(?:field|raw-field|input))(?:=|$)|^-[fF]./;
|
|
28523
|
+
var QUIET = /^--(?:debug|no-color|json|jq)$/;
|
|
28524
|
+
var CARRIES = {
|
|
28525
|
+
note: { "--body": "body", "-b": "body", "--body-file": "file" },
|
|
28526
|
+
time: { "--duration": "duration", "--text": "text", "--date": "date" },
|
|
28527
|
+
create: {
|
|
28528
|
+
"--project": "project",
|
|
28529
|
+
"-p": "project",
|
|
28530
|
+
"--summary": "summary",
|
|
28531
|
+
"-s": "summary",
|
|
28532
|
+
"--description": "description",
|
|
28533
|
+
"--description-file": "file"
|
|
28534
|
+
}
|
|
28535
|
+
};
|
|
28536
|
+
var gap = (part) => ({ workit: null, gap: part });
|
|
28537
|
+
var pair = (flag, value) => value.startsWith("-") ? `${flag}=${quote2(value)}` : `${flag} ${quote2(value)}`;
|
|
28538
|
+
var mapWrite = (verb, args) => {
|
|
28539
|
+
const values = {};
|
|
28540
|
+
const operands = [];
|
|
28541
|
+
for (let at = 0;at < args.length; at++) {
|
|
28542
|
+
const arg = args[at];
|
|
28543
|
+
if (!arg.startsWith("-") || arg === "-") {
|
|
28544
|
+
operands.push(arg);
|
|
28545
|
+
continue;
|
|
28546
|
+
}
|
|
28547
|
+
const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
|
|
28548
|
+
const flag = eq > 0 ? arg.slice(0, eq) : arg;
|
|
28549
|
+
const value = eq > 0 ? arg.slice(eq + 1) : VALUE.has(flag) ? args[++at] : undefined;
|
|
28550
|
+
if (QUIET.test(flag))
|
|
28551
|
+
continue;
|
|
28552
|
+
const key = CARRIES[verb][flag];
|
|
28553
|
+
if (!key || value === undefined || key in values)
|
|
28554
|
+
return gap(`\`${flag}\``);
|
|
28555
|
+
if (/[$`]|^~/.test(value))
|
|
28556
|
+
return gap(`the value of \`${flag}\`, which the shell expands when it runs`);
|
|
28557
|
+
values[key] = value;
|
|
28558
|
+
}
|
|
28559
|
+
const [issue, ...more] = operands.slice(2);
|
|
28560
|
+
const v = values;
|
|
28561
|
+
if (verb === "create") {
|
|
28562
|
+
if (issue !== undefined)
|
|
28563
|
+
return gap(`the operand \`${issue}\``);
|
|
28564
|
+
if (v.project === undefined || v.summary === undefined)
|
|
28565
|
+
return gap("a missing --project or --summary");
|
|
28566
|
+
if (v.description !== undefined && v.file !== undefined)
|
|
28567
|
+
return gap("both --description and --description-file");
|
|
28568
|
+
if (v.file === "-")
|
|
28569
|
+
return gap("text read from standard input");
|
|
28570
|
+
return {
|
|
28571
|
+
workit: [
|
|
28572
|
+
"workit youtrack create",
|
|
28573
|
+
pair("--project", v.project),
|
|
28574
|
+
pair("--summary", v.summary),
|
|
28575
|
+
v.description === undefined ? "" : pair("--description", v.description),
|
|
28576
|
+
v.file === undefined ? "" : pair("--file", v.file)
|
|
28577
|
+
].filter(Boolean).join(" ")
|
|
28578
|
+
};
|
|
28579
|
+
}
|
|
28580
|
+
if (issue === undefined || more.length || !/^[A-Z]+-\d+$/.test(issue))
|
|
28581
|
+
return gap("the issue, which must be one id like ABC-123");
|
|
28582
|
+
if (verb === "note") {
|
|
28583
|
+
if (v.body === undefined === (v.file === undefined))
|
|
28584
|
+
return gap("a comment that needs exactly one of --body or --body-file");
|
|
28585
|
+
if (v.file === "-")
|
|
28586
|
+
return gap("text read from standard input");
|
|
28587
|
+
if (v.body !== undefined && !v.body.trim())
|
|
28588
|
+
return gap("an empty --body");
|
|
28589
|
+
return {
|
|
28590
|
+
workit: `workit youtrack note ${issue} ${v.body === undefined ? pair("--file", v.file) : pair("--markdown", v.body)}`
|
|
28591
|
+
};
|
|
28592
|
+
}
|
|
28593
|
+
const minutes = minutesOf(v.duration);
|
|
28594
|
+
if (minutes === null)
|
|
28595
|
+
return gap(`\`--duration ${v.duration ?? ""}\`, which is no whole number of minutes`);
|
|
28596
|
+
if (v.date !== undefined && !/^(?:auto|\d{4}-\d{2}-\d{2})$/.test(v.date))
|
|
28597
|
+
return gap(`\`--date ${v.date}\``);
|
|
28598
|
+
return {
|
|
28599
|
+
workit: [
|
|
28600
|
+
`workit youtrack time ${issue} --minutes ${minutes}`,
|
|
28601
|
+
v.text === undefined ? "" : pair("--text", v.text),
|
|
28602
|
+
v.date === undefined ? "" : pair("--date", v.date)
|
|
28603
|
+
].filter(Boolean).join(" ")
|
|
28604
|
+
};
|
|
28605
|
+
};
|
|
28606
|
+
var UNCOVERED = { workit: null, gap: "" };
|
|
28607
|
+
var classify2 = (args) => {
|
|
28608
|
+
if (asksHelp2(args))
|
|
28609
|
+
return null;
|
|
28610
|
+
const lenient = args.filter((arg, at) => !arg.startsWith("-") && !VALUE.has(args[at - 1] ?? ""));
|
|
28611
|
+
const strict = args.filter((arg, at) => !arg.startsWith("-") && standsAlone(args, at));
|
|
28612
|
+
return judge(args, lenient) ?? judge(args, strict);
|
|
28613
|
+
};
|
|
28614
|
+
var judge = (args, words) => {
|
|
28615
|
+
const group = GROUPS[words[0] ?? ""];
|
|
28616
|
+
const verb = words[1] ?? "";
|
|
28617
|
+
if (group === "api") {
|
|
28618
|
+
const methods = args.flatMap((arg, at) => /^(?:-X|--method)$/.test(arg) ? [{ value: args[at + 1] ?? "", alone: standsAlone(args, at) }] : /^(?:-X.|--method=)/.test(arg) ? [{ value: arg.replace(/^(?:-X=?|--method=)/, ""), alone: standsAlone(args, at) }] : []);
|
|
28619
|
+
if (methods.some((method) => ASKS.test(method.value)))
|
|
28620
|
+
return UNCOVERED;
|
|
28621
|
+
if (methods.some((method) => method.alone))
|
|
28622
|
+
return null;
|
|
28623
|
+
return args.some((a) => BODY.test(a)) ? UNCOVERED : null;
|
|
28624
|
+
}
|
|
28625
|
+
if (group === "work-item" && /^(?:add|create)$/.test(verb))
|
|
28626
|
+
return mapWrite("time", args);
|
|
28627
|
+
if (group === "work-item")
|
|
28628
|
+
return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
|
|
28629
|
+
if (group !== "issue")
|
|
28630
|
+
return null;
|
|
28631
|
+
if (verb === "comment")
|
|
28632
|
+
return mapWrite("note", args);
|
|
28633
|
+
if (verb === "create")
|
|
28634
|
+
return mapWrite("create", args);
|
|
28635
|
+
if (verb === "command")
|
|
28636
|
+
return flagged(args, /^--dry-run$/) ? null : UNCOVERED;
|
|
28637
|
+
return /^(?:edit|update|delete|rm)$/.test(verb) ? UNCOVERED : null;
|
|
28638
|
+
};
|
|
28639
|
+
var SHELLS3 = /^(?:sh|bash|zsh|dash|ksh|ash|mksh|yash|fish)$/;
|
|
28640
|
+
var MAX_DEPTH2 = 4;
|
|
28641
|
+
var READ = new Map;
|
|
28642
|
+
var NOT_PLAIN = gap("a ytrack call that is not a plain command of its own (a wrapper, loop, substitution or script around it can change or repeat it)");
|
|
28643
|
+
var ungrant = (write) => write.workit ? { command: write.command, ...NOT_PLAIN } : write;
|
|
28644
|
+
var ytrackArgs = (line, found, depth, names, plain) => {
|
|
28645
|
+
const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
|
|
28646
|
+
const tail = workitCheckTail(line);
|
|
28647
|
+
if (tail) {
|
|
28648
|
+
inner("script" in tail ? tail.script : tail.argv.map(quote2).join(" "));
|
|
28649
|
+
return true;
|
|
28650
|
+
}
|
|
28651
|
+
const flag = SHELLS3.test(name2(line[0])) ? line.findIndex((word, index) => index > 0 && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(word)) : -1;
|
|
28652
|
+
const script = flag > 0 ? line[flag + 1] : name2(line[0]) === "eval" ? line.slice(1).join(" ") : undefined;
|
|
28653
|
+
if (script !== undefined) {
|
|
28654
|
+
inner(script);
|
|
28655
|
+
return true;
|
|
28656
|
+
}
|
|
28657
|
+
let at = 0;
|
|
28658
|
+
let called = false;
|
|
28659
|
+
const runner = name2(line[0]);
|
|
28660
|
+
if (/^(?:npx|bunx|pnpx)$/.test(runner) || /^(?:p?npm|yarn)$/.test(runner) && /^(?:dlx|exec|x)$/.test(line[1] ?? "")) {
|
|
28661
|
+
at = runner.endsWith("x") ? 1 : 2;
|
|
28662
|
+
for (;line[at]?.startsWith("-"); at++) {
|
|
28663
|
+
if (/^(?:-c|--call)$/.test(line[at])) {
|
|
28664
|
+
inner(line[at + 1] ?? "");
|
|
28665
|
+
called = true;
|
|
28666
|
+
}
|
|
28667
|
+
if (/^(?:-[pc]|--package|--call)$/.test(line[at]))
|
|
28668
|
+
at++;
|
|
28669
|
+
}
|
|
28670
|
+
}
|
|
28671
|
+
const resolved = /^(?:\$\(|`)\s*(?:which|command\s+-v|type\s+-[pP])\s+ytrack\s*[)`]$/.test(line[at] ?? "");
|
|
28672
|
+
const alias = names.get(line[at] ?? "");
|
|
28673
|
+
if (name2(line[at]) !== "ytrack" && !resolved && !alias)
|
|
28674
|
+
return called;
|
|
28675
|
+
const argv = [...alias ?? [], ...line.slice(at + 1)];
|
|
28676
|
+
const write = classify2(argv);
|
|
28677
|
+
if (write) {
|
|
28678
|
+
const one = { command: ["ytrack", ...argv].map(quote2).join(" "), ...write };
|
|
28679
|
+
found.push(plain ? one : ungrant(one));
|
|
28680
|
+
}
|
|
28681
|
+
return true;
|
|
28682
|
+
};
|
|
28683
|
+
var aliases = (command) => {
|
|
28684
|
+
const found = new Map;
|
|
28685
|
+
for (const [, alias, a, b, c] of command.matchAll(/\balias\s+([\w.-]+)=(?:'([^']*)'|"([^"]*)"|([^\s;&|)]+))/g)) {
|
|
28686
|
+
const value = a ?? b ?? c ?? "";
|
|
28687
|
+
if (/^(?:\S*\/)?ytrack(?:\s|$)/.test(value))
|
|
28688
|
+
found.set(alias, value.split(/\s+/).slice(1));
|
|
28689
|
+
}
|
|
28690
|
+
for (const [, a, b, body] of command.matchAll(/(?:\bfunction\s+([\w.-]+)(?:\s*\(\s*\))?|\b([\w.-]+)\s*\(\s*\))\s*\{([^}]*)\}/g))
|
|
28691
|
+
if (/(?:^|[\s;&|])(?:\S*\/)?ytrack\s/.test(body ?? ""))
|
|
28692
|
+
found.set(a ?? b ?? "", []);
|
|
28693
|
+
return found;
|
|
28694
|
+
};
|
|
28695
|
+
var PASS = /^(?:command|exec|nohup|setsid|time|nice|ionice|stdbuf|chronic|unbuffer|timeout)$/;
|
|
28696
|
+
var COMPOUND3 = /^(?:for|select|while|until|repeat|do|done|function|case|foreach|coproc)$/;
|
|
28697
|
+
var passed = (words) => {
|
|
28698
|
+
let at = 0;
|
|
28699
|
+
for (;at < words.length; at++) {
|
|
28700
|
+
const word = words[at];
|
|
28701
|
+
if (/^[A-Za-z_]\w*=/.test(word))
|
|
28702
|
+
return [];
|
|
28703
|
+
if (!PASS.test(word))
|
|
28704
|
+
break;
|
|
28705
|
+
if (/^(?:exec|command)$/.test(word) && words[at + 1]?.startsWith("-"))
|
|
28706
|
+
return [];
|
|
28707
|
+
while (/^(?:-|\d)/.test(words[at + 1] ?? ""))
|
|
28708
|
+
at++;
|
|
28709
|
+
}
|
|
28710
|
+
return words.slice(at);
|
|
28711
|
+
};
|
|
28712
|
+
var plainLines = (command, dialect) => {
|
|
28713
|
+
let first = null;
|
|
28714
|
+
const later = [];
|
|
28715
|
+
for (const segment of segmentsOf(command, dialect)) {
|
|
28716
|
+
if (segment.group || segment.unanalyzable || segment.subs?.length)
|
|
28717
|
+
return null;
|
|
28718
|
+
if (COMPOUND3.test(segment.words[0] ?? ""))
|
|
28719
|
+
return null;
|
|
28720
|
+
if (segment.words.some((word) => /^YTRACK_\w*=/.test(word)))
|
|
28721
|
+
return null;
|
|
28722
|
+
const names = namesYtrack([...segment.words, ...segment.stdin ?? []].join(" "));
|
|
28723
|
+
if (first === null) {
|
|
28724
|
+
if (!names || segment.expands?.length)
|
|
28725
|
+
return null;
|
|
28726
|
+
first = passed(segment.words);
|
|
28727
|
+
} else if (names)
|
|
28728
|
+
later.push(segment.words);
|
|
28729
|
+
}
|
|
28730
|
+
return first ? { first, later } : null;
|
|
28731
|
+
};
|
|
28732
|
+
var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
|
|
28733
|
+
if (!namesYtrack(command))
|
|
28734
|
+
return [];
|
|
28735
|
+
if (depth > MAX_DEPTH2)
|
|
28736
|
+
throw new Error("ytrack nested too deep");
|
|
28737
|
+
const key = `${plain}\x00${dialect}\x00${command}`;
|
|
28738
|
+
const known = READ.get(key);
|
|
28739
|
+
if (known)
|
|
28740
|
+
return known;
|
|
28741
|
+
let found = [];
|
|
28742
|
+
const lines = plain ? plainLines(command, dialect) : null;
|
|
28743
|
+
const none = new Map;
|
|
28744
|
+
if (!lines || !ytrackArgs(lines.first, found, depth, none, true) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false))) {
|
|
28745
|
+
found = [];
|
|
28746
|
+
for (const line of commandLines(command, dialect))
|
|
28747
|
+
ytrackArgs(line, found, depth, aliases(command), false);
|
|
28748
|
+
}
|
|
28749
|
+
READ.set(key, found);
|
|
28750
|
+
if (READ.size > 64)
|
|
28751
|
+
READ.delete(READ.keys().next().value);
|
|
28752
|
+
return found;
|
|
28753
|
+
};
|
|
28754
|
+
var writesMode = (cwd) => resolveRuntimeWorkspaceVcs(cwd)?.youtrack?.writes;
|
|
28755
|
+
var ytrackGate = (cwd, command, dialect, ask) => {
|
|
28756
|
+
let writes;
|
|
28757
|
+
try {
|
|
28758
|
+
const merged = new Map;
|
|
28759
|
+
for (const write of ytrackWrites(command, dialect)) {
|
|
28760
|
+
const seen = merged.get(write.command);
|
|
28761
|
+
merged.set(write.command, !seen || !write.workit ? write : !seen.workit ? seen : ungrant(write));
|
|
28762
|
+
}
|
|
28763
|
+
writes = [...merged.values()];
|
|
28764
|
+
} catch {
|
|
28765
|
+
if (writesMode(cwd) === "auto")
|
|
28766
|
+
return null;
|
|
28767
|
+
return {
|
|
28768
|
+
kind: "deny",
|
|
28769
|
+
reason: `Workit could not analyse this command, which names ytrack: run each ytrack call as its own plain command so a YouTrack write can ask the user first (#780).`,
|
|
28770
|
+
unblock: null
|
|
28771
|
+
};
|
|
28772
|
+
}
|
|
28773
|
+
if (!writes.length || writesMode(cwd) === "auto")
|
|
28774
|
+
return null;
|
|
28775
|
+
const calls = writes.flatMap((write) => write.workit ? [`\`${write.workit}\``] : []);
|
|
28776
|
+
const bare = writes.filter((write) => !write.workit).map((write) => `\`${write.command}\` (${write.gap ? `Workit cannot carry ${write.gap} into a workit youtrack call` : "no workit youtrack verb covers it"})`);
|
|
28777
|
+
if (!calls.length && ask)
|
|
28778
|
+
return {
|
|
28779
|
+
kind: "ask",
|
|
28780
|
+
reason: `${bare.join(", ")} writes to YouTrack: the user decides this call (#780).`
|
|
28781
|
+
};
|
|
28782
|
+
const why = `A raw ytrack write posts to YouTrack without the user's yes (#780).`;
|
|
28783
|
+
const run = calls.length ? ` Run ${calls.join(", then ")} instead: it asks the user first. When it answers approval_needed, run exactly the \`workit approve <id>\` it names, now, with nothing around it (no 2>&1, pipe or echo), so the host asks the user; then rerun the workit call once.` : "";
|
|
28784
|
+
const user = bare.length ? ` For ${bare.join(", ")}, the user decides: ask the user, and if they agree they run it in their own terminal.` : "";
|
|
28785
|
+
const rerun = writes.some((write) => write.gap === NOT_PLAIN.gap) ? " To get the named workit youtrack call instead, rerun the ytrack call as one plain command, with no wrapper, loop, substitution or script around it." : "";
|
|
28786
|
+
return {
|
|
28787
|
+
kind: "deny",
|
|
28788
|
+
reason: `${why}${run}${user}${rerun}`,
|
|
28789
|
+
unblock: writes[0]?.workit ?? null
|
|
28790
|
+
};
|
|
28791
|
+
};
|
|
28792
|
+
|
|
28226
28793
|
// packages/workit-core/src/hooks/handle.ts
|
|
28227
28794
|
var offered = new Set;
|
|
28228
28795
|
var PRE_TOOL = new Set(["shell.pre", "write.pre", "tool.pre"]);
|
|
28229
28796
|
// packages/workit-core/src/hooks/deadline.ts
|
|
28230
|
-
var
|
|
28797
|
+
var QUIET2 = new Set([
|
|
28231
28798
|
"stop",
|
|
28232
28799
|
"subagent.stop",
|
|
28233
28800
|
"shell.post",
|
|
@@ -28243,7 +28810,7 @@ if (false) {}
|
|
|
28243
28810
|
import path47 from "node:path";
|
|
28244
28811
|
|
|
28245
28812
|
// packages/workit-core/src/core/gitignore.ts
|
|
28246
|
-
import { existsSync as existsSync14, readFileSync as
|
|
28813
|
+
import { existsSync as existsSync14, readFileSync as readFileSync12, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28247
28814
|
import path43 from "node:path";
|
|
28248
28815
|
var GITIGNORE_ENTRIES = [
|
|
28249
28816
|
"# workit: SDD working state (never commit)",
|
|
@@ -28265,7 +28832,7 @@ var ensureProjectGitignore = (workspaceRoot, confirmed) => {
|
|
|
28265
28832
|
if (!confirmed)
|
|
28266
28833
|
return { ok: false, error: "confirmed: true required" };
|
|
28267
28834
|
const file = path43.join(workspaceRoot, ".gitignore");
|
|
28268
|
-
const existing = existsSync14(file) ?
|
|
28835
|
+
const existing = existsSync14(file) ? readFileSync12(file, "utf8") : "";
|
|
28269
28836
|
const existingLines = new Set(existing.split(`
|
|
28270
28837
|
`).map((l) => l.trim()).filter(Boolean));
|
|
28271
28838
|
const added = [];
|
|
@@ -28291,7 +28858,7 @@ var ensureProjectGitignore = (workspaceRoot, confirmed) => {
|
|
|
28291
28858
|
};
|
|
28292
28859
|
|
|
28293
28860
|
// packages/workit-core/src/core/hygiene.ts
|
|
28294
|
-
import { existsSync as existsSync15, readFileSync as
|
|
28861
|
+
import { existsSync as existsSync15, readFileSync as readFileSync13, readdirSync as readdirSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
28295
28862
|
import path44 from "node:path";
|
|
28296
28863
|
var repoRoot3 = assetRoot();
|
|
28297
28864
|
var templatesDir = () => path44.join(repoRoot3, "templates", "hygiene");
|
|
@@ -28299,7 +28866,7 @@ var packageJson = (root) => {
|
|
|
28299
28866
|
if (!existsSync15(path44.join(root, "package.json")))
|
|
28300
28867
|
return null;
|
|
28301
28868
|
try {
|
|
28302
|
-
return JSON.parse(
|
|
28869
|
+
return JSON.parse(readFileSync13(path44.join(root, "package.json"), "utf8"));
|
|
28303
28870
|
} catch {
|
|
28304
28871
|
return null;
|
|
28305
28872
|
}
|
|
@@ -28338,7 +28905,7 @@ var planHygieneFiles = (root, opts = {}) => {
|
|
|
28338
28905
|
const tpl = path44.join(templatesDir(), file);
|
|
28339
28906
|
if (!existsSync15(tpl))
|
|
28340
28907
|
continue;
|
|
28341
|
-
const content =
|
|
28908
|
+
const content = readFileSync13(tpl, "utf8").replace(/<PROJECT>/g, path44.basename(root)).replace(/<YEAR>/g, String(new Date().getFullYear())).replace(/<HOLDER>\s*/g, licenseHolder(root));
|
|
28342
28909
|
planned.push({ path: path44.join(root, file), content });
|
|
28343
28910
|
}
|
|
28344
28911
|
return planned;
|
|
@@ -28360,12 +28927,12 @@ import path46 from "node:path";
|
|
|
28360
28927
|
import { spawnSync as spawnSync25 } from "node:child_process";
|
|
28361
28928
|
|
|
28362
28929
|
// packages/workit-core/src/core/workspace-branch-policy.ts
|
|
28363
|
-
import { mkdirSync as mkdirSync5, readFileSync as
|
|
28930
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync14, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "node:fs";
|
|
28364
28931
|
import path45 from "node:path";
|
|
28365
28932
|
import { isDeepStrictEqual } from "node:util";
|
|
28366
28933
|
var readFileSafe = (p) => {
|
|
28367
28934
|
try {
|
|
28368
|
-
return
|
|
28935
|
+
return readFileSync14(p, "utf8");
|
|
28369
28936
|
} catch {
|
|
28370
28937
|
return null;
|
|
28371
28938
|
}
|
|
@@ -29081,7 +29648,7 @@ import path51 from "node:path";
|
|
|
29081
29648
|
|
|
29082
29649
|
// packages/workit-core/src/git/ops.ts
|
|
29083
29650
|
import { spawnSync as spawnSync27 } from "node:child_process";
|
|
29084
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync16, readdirSync as
|
|
29651
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync16, readdirSync as readdirSync7, readFileSync as readFileSync15, rmSync as rmSync4 } from "node:fs";
|
|
29085
29652
|
import path50 from "node:path";
|
|
29086
29653
|
var COMMIT_TIMEOUT_MS = 10 * 60000;
|
|
29087
29654
|
var git5 = (cwd, args, options = {}) => {
|
|
@@ -29126,7 +29693,7 @@ function operationInProgress(cwd) {
|
|
|
29126
29693
|
if (index === 0 && existsSync16(path50.join(marker, "amend")) && !conflicted()) {
|
|
29127
29694
|
let headName = "";
|
|
29128
29695
|
try {
|
|
29129
|
-
headName =
|
|
29696
|
+
headName = readFileSync15(path50.join(marker, "head-name"), "utf8").trim();
|
|
29130
29697
|
} catch {}
|
|
29131
29698
|
const branch = headName.startsWith("refs/heads/") ? headName.slice("refs/heads/".length) : null;
|
|
29132
29699
|
return { operation, commitAllowed: branch !== null, branch };
|
|
@@ -30370,6 +30937,9 @@ var evaluateShellPermission = (root, event, workdirs = new Map) => {
|
|
|
30370
30937
|
const decision = shellPolicy(cwd, resource, "posix");
|
|
30371
30938
|
if (decision.kind === "deny")
|
|
30372
30939
|
return deny(decision.reason);
|
|
30940
|
+
const ytrack = ytrackGate(cwd, resource, "posix", false);
|
|
30941
|
+
if (ytrack?.kind === "deny")
|
|
30942
|
+
return deny(ytrack.reason);
|
|
30373
30943
|
const raw = rawGitPre({
|
|
30374
30944
|
host: "opencode",
|
|
30375
30945
|
cwd,
|
|
@@ -30752,7 +31322,7 @@ var createStopControl = (root, port) => {
|
|
|
30752
31322
|
};
|
|
30753
31323
|
|
|
30754
31324
|
// packages/workit-opencode/src/v2/registry.ts
|
|
30755
|
-
import { existsSync as existsSync18, readFileSync as
|
|
31325
|
+
import { existsSync as existsSync18, readFileSync as readFileSync16 } from "node:fs";
|
|
30756
31326
|
import path55 from "node:path";
|
|
30757
31327
|
|
|
30758
31328
|
// packages/workit-opencode/src/shared/assets.ts
|
|
@@ -30823,7 +31393,7 @@ var registerSkills = async (ctx) => {
|
|
|
30823
31393
|
for (const [id, file] of packaged) {
|
|
30824
31394
|
if (existing.has(id))
|
|
30825
31395
|
continue;
|
|
30826
|
-
const parsed = parseFrontmatter(
|
|
31396
|
+
const parsed = parseFrontmatter(readFileSync16(file, "utf8"));
|
|
30827
31397
|
editor.add({
|
|
30828
31398
|
id,
|
|
30829
31399
|
name: parsed.name || id,
|
|
@@ -30861,13 +31431,13 @@ var registerCommands = async (ctx, registeredSkills) => {
|
|
|
30861
31431
|
};
|
|
30862
31432
|
|
|
30863
31433
|
// packages/workit-opencode/src/stale-sources.ts
|
|
30864
|
-
import { existsSync as existsSync19, readdirSync as
|
|
31434
|
+
import { existsSync as existsSync19, readdirSync as readdirSync8 } from "node:fs";
|
|
30865
31435
|
import path56 from "node:path";
|
|
30866
31436
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
30867
31437
|
var typescriptFiles = (directory) => {
|
|
30868
31438
|
if (!existsSync19(directory))
|
|
30869
31439
|
return [];
|
|
30870
|
-
return
|
|
31440
|
+
return readdirSync8(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
30871
31441
|
const file = path56.join(directory, entry.name);
|
|
30872
31442
|
return entry.isDirectory() ? typescriptFiles(file) : entry.isFile() && file.endsWith(".ts") ? [file] : [];
|
|
30873
31443
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workit-dev/opencode",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Workit OpenCode plugin — native tools, adaptive policy, and sixteen method skills",
|
|
6
6
|
"keywords": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@opencode/plugin": "2.0.18",
|
|
44
|
-
"@workit-dev/core": "^1.
|
|
44
|
+
"@workit-dev/core": "^1.9.0"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=24"
|