@workit-dev/pi 1.2.0 → 1.2.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/worker.js +14 -0
- package/dist/workit.js +342 -28
- package/package.json +1 -1
package/dist/worker.js
CHANGED
|
@@ -8589,6 +8589,7 @@ var OBSERVED_ONLY = new Set([
|
|
|
8589
8589
|
"check",
|
|
8590
8590
|
"merge.unverified",
|
|
8591
8591
|
"policy.judged",
|
|
8592
|
+
"verdict.voided",
|
|
8592
8593
|
...PR_ROW_TYPES
|
|
8593
8594
|
]);
|
|
8594
8595
|
|
|
@@ -9689,6 +9690,19 @@ var MUTATING_REMOTE = new Set([
|
|
|
9689
9690
|
"set-branches",
|
|
9690
9691
|
"prune"
|
|
9691
9692
|
]);
|
|
9693
|
+
var JUDGE_VERBS = {
|
|
9694
|
+
check: true,
|
|
9695
|
+
dir: true,
|
|
9696
|
+
help: true,
|
|
9697
|
+
"test-audit": true,
|
|
9698
|
+
ledger: ["verdict", "finding", "list", "check", "ruling"],
|
|
9699
|
+
pr: ["status"],
|
|
9700
|
+
ci: ["wait", "logs"],
|
|
9701
|
+
fanout: ["status", "brief"],
|
|
9702
|
+
models: ["show"],
|
|
9703
|
+
lock: ["status"]
|
|
9704
|
+
};
|
|
9705
|
+
var JUDGE_JOB = Object.entries(JUDGE_VERBS).map(([verb, subs]) => `workit ${verb}${subs === true ? "" : ` ${subs.join("|")}`}`).join(", ");
|
|
9692
9706
|
|
|
9693
9707
|
// packages/workit-core/src/hooks/steering.ts
|
|
9694
9708
|
var ROLES = {
|
package/dist/workit.js
CHANGED
|
@@ -16114,6 +16114,19 @@ function verdictBasis(verdict, current) {
|
|
|
16114
16114
|
return "stale";
|
|
16115
16115
|
}
|
|
16116
16116
|
var isLiveVerdict = (row, retired) => row.type === "verdict" && typeof row.result === "string" && !retired.has(row.id);
|
|
16117
|
+
var VOID_TYPE = "verdict.voided";
|
|
16118
|
+
function verdictVoids(rows, options = {}) {
|
|
16119
|
+
const voids = new Map;
|
|
16120
|
+
for (const row of rows)
|
|
16121
|
+
if (row.type === VOID_TYPE && row.observer === "workit_cli" && typeof row.target === "string" && (options.chained ? row.integrity === "verified" : row.integrity !== "unverified") && !voids.has(row.target))
|
|
16122
|
+
voids.set(row.target, {
|
|
16123
|
+
id: row.id,
|
|
16124
|
+
at: row.at,
|
|
16125
|
+
reason: str2(row.reason) ?? "",
|
|
16126
|
+
by: row.actor.session
|
|
16127
|
+
});
|
|
16128
|
+
return voids;
|
|
16129
|
+
}
|
|
16117
16130
|
function trailerSessions(cwd, base, head) {
|
|
16118
16131
|
if (!base || !head || !safeRef2(base) || !safeRef2(head))
|
|
16119
16132
|
return [];
|
|
@@ -16452,6 +16465,8 @@ function checkVerdictsOnce(cwd, branch, ledgerRows) {
|
|
|
16452
16465
|
for (const row of rows)
|
|
16453
16466
|
if (row.type === "verdict" && row.supersedes && !row.supersedeIgnored && trustReasons(cwd, row).length === 0)
|
|
16454
16467
|
retired.add(row.supersedes);
|
|
16468
|
+
for (const id of verdictVoids(rows, { chained: true }).keys())
|
|
16469
|
+
retired.add(id);
|
|
16455
16470
|
const byKind = new Map;
|
|
16456
16471
|
for (const row of rows.toSorted(byRank))
|
|
16457
16472
|
if (isLiveVerdict(row, retired) && scope(row)) {
|
|
@@ -16585,7 +16600,7 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
16585
16600
|
const mirror = readLedgerAt(cwd, file, { integrity: true });
|
|
16586
16601
|
if (!mirror.ok)
|
|
16587
16602
|
return [];
|
|
16588
|
-
const candidates = mirror.value.rows.filter((row) => row.type === "verdict" && row.branch === branch && row.integrity === "verified");
|
|
16603
|
+
const candidates = mirror.value.rows.filter((row) => (row.type === "verdict" || row.type === VOID_TYPE) && row.branch === branch && row.integrity === "verified");
|
|
16589
16604
|
const added = new Set;
|
|
16590
16605
|
try {
|
|
16591
16606
|
fs15.mkdirSync(path19.dirname(local.value), { recursive: true });
|
|
@@ -16611,7 +16626,10 @@ function importMirroredVerdicts(cwd, branch) {
|
|
|
16611
16626
|
integrityReason: _reason,
|
|
16612
16627
|
...fields
|
|
16613
16628
|
} = row;
|
|
16614
|
-
const written = appendLine(local.value, (previous) => ({
|
|
16629
|
+
const written = appendLine(local.value, (previous) => ({
|
|
16630
|
+
ok: true,
|
|
16631
|
+
value: sealed(fields, id, at, previous).line
|
|
16632
|
+
}), { heldLock: true });
|
|
16615
16633
|
if (!written.ok)
|
|
16616
16634
|
return false;
|
|
16617
16635
|
ids.add(id);
|
|
@@ -16652,6 +16670,7 @@ var OBSERVED_ONLY = new Set([
|
|
|
16652
16670
|
"check",
|
|
16653
16671
|
"merge.unverified",
|
|
16654
16672
|
"policy.judged",
|
|
16673
|
+
"verdict.voided",
|
|
16655
16674
|
...PR_ROW_TYPES
|
|
16656
16675
|
]);
|
|
16657
16676
|
|
|
@@ -24270,7 +24289,8 @@ var WORKIT_BYPASS_FLAGS = ["--unverified", "--overwrite-unintegrated"];
|
|
|
24270
24289
|
var WORKIT_USER_ONLY = [
|
|
24271
24290
|
["release", "notes", "approve"],
|
|
24272
24291
|
["grant", "set"],
|
|
24273
|
-
["grant", "raise"]
|
|
24292
|
+
["grant", "raise"],
|
|
24293
|
+
["ledger", "void"]
|
|
24274
24294
|
];
|
|
24275
24295
|
var ALLOWED = new Set(WORKIT_ALLOWED_VERBS);
|
|
24276
24296
|
var hasWordsInOrder = (words, needle) => {
|
|
@@ -25450,7 +25470,7 @@ var shellScript2 = (words) => {
|
|
|
25450
25470
|
return null;
|
|
25451
25471
|
for (let index = 1;index < words.length; index++) {
|
|
25452
25472
|
const word = words[index];
|
|
25453
|
-
if (/^-[a-z]*c
|
|
25473
|
+
if (/^-[a-z]*c[a-z]*$/.test(word))
|
|
25454
25474
|
return words[index + 1] ?? null;
|
|
25455
25475
|
if (/^[-+][oO]$/.test(word))
|
|
25456
25476
|
index++;
|
|
@@ -25481,8 +25501,16 @@ var opaqueWrites = (input, scriptOf = (index) => input[index]) => {
|
|
|
25481
25501
|
const files = operands(args);
|
|
25482
25502
|
const has = (pattern) => args.some((arg) => pattern.test(arg));
|
|
25483
25503
|
const listed = (named) => named.length ? named : ["."];
|
|
25484
|
-
if (name === "unlink" || name === "shred")
|
|
25504
|
+
if (name === "unlink" || name === "shred" || name === "mkfifo")
|
|
25485
25505
|
return listed(files);
|
|
25506
|
+
if (name === "wget")
|
|
25507
|
+
return wgetOutputs(args);
|
|
25508
|
+
if (name === "tar")
|
|
25509
|
+
return tarOutputs(args);
|
|
25510
|
+
if (name === "unzip")
|
|
25511
|
+
return has(/^-[a-zA-Z]*[lptvzZ]/) ? null : listed(args.flatMap((arg, at) => arg.startsWith("-d") ? [arg.slice(2) || args[at + 1] || "."] : []));
|
|
25512
|
+
if (name === "git")
|
|
25513
|
+
return gitOutputs(args);
|
|
25486
25514
|
if (/^(?:chmod|chown|chgrp|chattr)$/.test(name))
|
|
25487
25515
|
return listed(has(/^--reference/) ? files : files.slice(1));
|
|
25488
25516
|
if (name === "rsync") {
|
|
@@ -25602,6 +25630,85 @@ var curlOutputs = (args) => {
|
|
|
25602
25630
|
files.push(...dirs.length ? dirs : ["."]);
|
|
25603
25631
|
return files.length > 0 ? files : null;
|
|
25604
25632
|
};
|
|
25633
|
+
var valueOf = (args, option) => {
|
|
25634
|
+
const at = args.findIndex((arg) => option.test(arg));
|
|
25635
|
+
return at < 0 ? undefined : option.exec(args[at])?.[1] || args[at + 1];
|
|
25636
|
+
};
|
|
25637
|
+
var wgetOutputs = (args) => {
|
|
25638
|
+
const named = valueOf(args, /^(?:-[a-zA-Z]*O|--output-document=?)(.*)$/s);
|
|
25639
|
+
const logs = [/^-[a-zA-Z]*[oa](.*)$/s, /^--(?:output-file|append-output)=?(.*)$/s].flatMap((option) => valueOf(args, option) ?? []);
|
|
25640
|
+
if (named === undefined)
|
|
25641
|
+
return [...logs, valueOf(args, /^(?:-[a-zA-Z]*P|--directory-prefix=?)(.*)$/s) ?? "."];
|
|
25642
|
+
return named === "-" ? logs : [...logs, named];
|
|
25643
|
+
};
|
|
25644
|
+
var tarOutputs = (args) => {
|
|
25645
|
+
const letters = args.filter((arg, at) => at === 0 && !arg.startsWith("-") || /^-[a-zA-Z]+$/.test(arg)).join("").replaceAll("C", "");
|
|
25646
|
+
const long = (pattern) => args.some((arg) => pattern.test(arg));
|
|
25647
|
+
const extract = /x/.test(letters) || long(/^--(?:extract|get)$/);
|
|
25648
|
+
const creates = /[cruA]/.test(letters) || long(/^--(?:create|append|update|concatenate|delete)$/);
|
|
25649
|
+
if (!extract && !creates)
|
|
25650
|
+
return null;
|
|
25651
|
+
const files = [];
|
|
25652
|
+
if (extract) {
|
|
25653
|
+
const dirs = args.flatMap((arg, at) => /^-C|^--directory(?:=|$)/.test(arg) ? [arg.replace(/^-C|^--directory=?/, "") || args[at + 1] || "."] : []);
|
|
25654
|
+
files.push(...dirs.length ? dirs : ["."]);
|
|
25655
|
+
}
|
|
25656
|
+
const old = args[0] !== undefined && !args[0].startsWith("-") && args[0].includes("f");
|
|
25657
|
+
const archive = old ? args[1] : valueOf(args, /^(?:-[a-zA-Z]*f|--file=?)(.*)$/s);
|
|
25658
|
+
if (creates && archive !== undefined && archive !== "-")
|
|
25659
|
+
files.push(archive);
|
|
25660
|
+
return files;
|
|
25661
|
+
};
|
|
25662
|
+
var CONFIG_READ = /^(?:--get(?:-all|-regexp|-urlmatch)?|--list|-l|get|list)$/;
|
|
25663
|
+
var CONFIG_WRITE = /^(?:--(?:unset(?:-all)?|add|replace-all|rename-section|remove-section|edit)|-e|set|unset|rename-section|remove-section|edit)$/;
|
|
25664
|
+
var CONFIG_VALUE = /^(?:--file|-f|--blob|--type|--default|--comment)$/;
|
|
25665
|
+
var configWrites = (rest) => {
|
|
25666
|
+
if (rest.some((arg) => CONFIG_READ.test(arg)))
|
|
25667
|
+
return false;
|
|
25668
|
+
if (rest.some((arg) => CONFIG_WRITE.test(arg)))
|
|
25669
|
+
return true;
|
|
25670
|
+
let named = 0;
|
|
25671
|
+
for (let index = 0;index < rest.length; index++)
|
|
25672
|
+
if (CONFIG_VALUE.test(rest[index]))
|
|
25673
|
+
index++;
|
|
25674
|
+
else if (!rest[index].startsWith("-"))
|
|
25675
|
+
named++;
|
|
25676
|
+
return named > 1;
|
|
25677
|
+
};
|
|
25678
|
+
var GIT_VALUE = /^(?:-[Ccbouj]|--(?:git-dir|work-tree|namespace|config-env|branch|origin|config|depth|reference(?:-if-able)?|template|separate-git-dir|upload-pack|jobs|filter|initial-branch|object-format))$/;
|
|
25679
|
+
var gitOutputs = (args) => {
|
|
25680
|
+
let at = 0;
|
|
25681
|
+
let base;
|
|
25682
|
+
for (;args[at]?.startsWith("-"); at += GIT_VALUE.test(args[at]) ? 2 : 1)
|
|
25683
|
+
if (args[at] === "-C")
|
|
25684
|
+
base = args[at + 1];
|
|
25685
|
+
const [sub = "", ...rest] = args.slice(at);
|
|
25686
|
+
if (rest.some((arg) => arg === "--help" || arg === "-h"))
|
|
25687
|
+
return null;
|
|
25688
|
+
const names = rest.filter((arg, index) => !arg.startsWith("-") && !GIT_VALUE.test(rest[index - 1] ?? ""));
|
|
25689
|
+
const has = (pattern) => rest.some((arg) => pattern.test(arg));
|
|
25690
|
+
const files = [];
|
|
25691
|
+
const output = valueOf(rest, sub === "archive" ? /^(?:-o|--output=?)(.*)$/s : /^--output=?(.*)$/s);
|
|
25692
|
+
if (output !== undefined)
|
|
25693
|
+
files.push(output);
|
|
25694
|
+
if (sub === "init")
|
|
25695
|
+
files.push(names[0] ?? ".");
|
|
25696
|
+
if (sub === "clone")
|
|
25697
|
+
files.push(names[1] ?? names[0]?.replace(/(?:\.git)?[\\/]*$/, "").split(/[\\/:]/).at(-1) ?? ".");
|
|
25698
|
+
if (sub === "format-patch" && !has(/^--stdout$/))
|
|
25699
|
+
files.push(valueOf(rest, /^(?:-o|--output-directory=?)(.*)$/s) ?? ".");
|
|
25700
|
+
if (sub === "bundle" && names[0] === "create" && names[1])
|
|
25701
|
+
files.push(names[1]);
|
|
25702
|
+
if (sub === "config" && configWrites(rest))
|
|
25703
|
+
files.push(has(/^--global$/) ? "~/.gitconfig" : has(/^--system$/) ? "/etc/gitconfig" : valueOf(rest, /^(?:-f|--file=?)(.*)$/s) ?? ".");
|
|
25704
|
+
const branchWrite = has(/^-[a-zA-Z]*[dDfmMcCu]|^--(?:delete|force|move|copy|set-upstream|unset-upstream|edit)/) || names.length > 0 && !has(/^-[a-zA-Z]*[lavr]|^--(?:list|all|remotes|verbose|show|contains|no-contains|merged|no-merged|points-at|format|sort)/);
|
|
25705
|
+
if (sub === "fetch" || sub === "gc" || sub === "branch" && branchWrite)
|
|
25706
|
+
files.push(".");
|
|
25707
|
+
if (base === undefined)
|
|
25708
|
+
return files.length ? files : null;
|
|
25709
|
+
const under = (file) => file === "." ? `${base}/${OPAQUE_TARGET}git` : /^[/~$]|^[A-Za-z]:[\\/]/.test(file) ? file : `${base}/${file}`;
|
|
25710
|
+
return files.length ? files.map(under) : null;
|
|
25711
|
+
};
|
|
25605
25712
|
var pathsIn = (text) => [
|
|
25606
25713
|
...text.matchAll(/(?<![\w.~:/$-])(?:~\/|\/|[A-Za-z]:\/|\.\.(?:\/|$))[^\s'"`$),;:*?<>|\\[\]{}]*/g)
|
|
25607
25714
|
].map((match) => match[0]);
|
|
@@ -27558,9 +27665,6 @@ var MUTATING_REMOTE = new Set([
|
|
|
27558
27665
|
"set-branches",
|
|
27559
27666
|
"prune"
|
|
27560
27667
|
]);
|
|
27561
|
-
var CONFIG_READ = /^(?:--get(?:-all|-regexp|-urlmatch)?|--list|-l|get|list)$/;
|
|
27562
|
-
var CONFIG_WRITE = /^(?:--(?:unset(?:-all)?|add|replace-all|rename-section|remove-section|edit)|-e|set|unset|rename-section|remove-section|edit)$/;
|
|
27563
|
-
var CONFIG_VALUE = /^(?:--file|-f|--blob|--type|--default|--comment)$/;
|
|
27564
27668
|
var leadOwnedGit = (args) => {
|
|
27565
27669
|
const [sub = "", ...rest] = args;
|
|
27566
27670
|
if (rest.some((arg) => arg === "--help" || arg === "-h"))
|
|
@@ -27599,19 +27703,8 @@ var leadOwnedGit = (args) => {
|
|
|
27599
27703
|
return names[0] === "drop" || names[0] === "clear";
|
|
27600
27704
|
case "remote":
|
|
27601
27705
|
return MUTATING_REMOTE.has(names[0] ?? "");
|
|
27602
|
-
case "config":
|
|
27603
|
-
|
|
27604
|
-
return false;
|
|
27605
|
-
if (rest.some((arg) => CONFIG_WRITE.test(arg)))
|
|
27606
|
-
return true;
|
|
27607
|
-
let operands = 0;
|
|
27608
|
-
for (let index = 0;index < rest.length; index++)
|
|
27609
|
-
if (CONFIG_VALUE.test(rest[index]))
|
|
27610
|
-
index++;
|
|
27611
|
-
else if (!rest[index].startsWith("-"))
|
|
27612
|
-
operands++;
|
|
27613
|
-
return operands > 1;
|
|
27614
|
-
}
|
|
27706
|
+
case "config":
|
|
27707
|
+
return configWrites(rest);
|
|
27615
27708
|
default:
|
|
27616
27709
|
return false;
|
|
27617
27710
|
}
|
|
@@ -27639,6 +27732,223 @@ function confineImplementerShell(input, command, dialect = "posix") {
|
|
|
27639
27732
|
} catch {}
|
|
27640
27733
|
return confineImplementer(input, shellMutationTargets(input.cwd, command, dialect, true), command);
|
|
27641
27734
|
}
|
|
27735
|
+
var SCRATCH = ".workit-scratch";
|
|
27736
|
+
var SHELL_NAMES = /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/;
|
|
27737
|
+
var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php)$/;
|
|
27738
|
+
var FED = /^(?:-|\/dev\/stdin|\/dev\/fd\/0|\/proc\/self\/fd\/0)$|^<\(/;
|
|
27739
|
+
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;
|
|
27740
|
+
var RUNS = /^(?:sh|bash|zsh|dash|ksh|mksh|ash|python[\d.]*|node|bun|deno|ruby|perl|php|eval|source|\.|workit)$/;
|
|
27741
|
+
var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print|test|version|help)$|^-[hvV]$/;
|
|
27742
|
+
var VALUED = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
|
|
27743
|
+
var commonDir = (root) => {
|
|
27744
|
+
const dotGit = path39.join(root, ".git");
|
|
27745
|
+
if (!fs28.statSync(dotGit).isFile())
|
|
27746
|
+
return canonical4(dotGit);
|
|
27747
|
+
const admin = path39.resolve(root, /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "");
|
|
27748
|
+
const common = path39.join(admin, "commondir");
|
|
27749
|
+
return canonical4(fs28.existsSync(common) ? path39.resolve(admin, fs28.readFileSync(common, "utf8").trim()) : admin);
|
|
27750
|
+
};
|
|
27751
|
+
var inScratch = (real, repo) => {
|
|
27752
|
+
const checkout = checkoutOf2(real);
|
|
27753
|
+
return checkout !== null && within(real, path39.join(checkout.root, SCRATCH)) && (repo === null || commonDir(checkout.root) === repo);
|
|
27754
|
+
};
|
|
27755
|
+
var JUDGE_VERBS = {
|
|
27756
|
+
check: true,
|
|
27757
|
+
dir: true,
|
|
27758
|
+
help: true,
|
|
27759
|
+
"test-audit": true,
|
|
27760
|
+
ledger: ["verdict", "finding", "list", "check", "ruling"],
|
|
27761
|
+
pr: ["status"],
|
|
27762
|
+
ci: ["wait", "logs"],
|
|
27763
|
+
fanout: ["status", "brief"],
|
|
27764
|
+
models: ["show"],
|
|
27765
|
+
lock: ["status"]
|
|
27766
|
+
};
|
|
27767
|
+
var HELP = /^(?:--help|-h)$/;
|
|
27768
|
+
var judgeVerbRefused = (args) => {
|
|
27769
|
+
const { rest } = skipWorkitGlobals(args);
|
|
27770
|
+
const end = rest.indexOf("--");
|
|
27771
|
+
const call = end < 0 ? rest : rest.slice(0, end);
|
|
27772
|
+
const [verb, sub = ""] = call;
|
|
27773
|
+
if (verb === undefined || verb === "--version" || HELP.test(verb) || HELP.test(sub))
|
|
27774
|
+
return null;
|
|
27775
|
+
const allowed = Object.hasOwn(JUDGE_VERBS, verb) ? JUDGE_VERBS[verb] : [];
|
|
27776
|
+
const ok = allowed === true ? !(verb === "test-audit" && call.some((arg) => /^--mutate(?:=|$)/.test(arg))) : allowed.includes(sub);
|
|
27777
|
+
return ok ? null : `workit ${call.join(" ")}`;
|
|
27778
|
+
};
|
|
27779
|
+
var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
|
|
27780
|
+
var CLI_ENTRY = /(?:^|[=\\/])(?:workit(?:\.(?:exe|cmd|[cm]?js))?|@workit-dev\/cli(?:@\S*)?)$|(?:workit-cli|@workit-dev[\\/]cli)[\\/](?:src[\\/](?:index|main)|dist[\\/]index)\.[cm]?[jt]sx?$/;
|
|
27781
|
+
var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
|
|
27782
|
+
const name = path39.basename(words[0] ?? "").toLowerCase();
|
|
27783
|
+
if (name === "alias")
|
|
27784
|
+
return words.flatMap((word) => {
|
|
27785
|
+
const set = /^([\w-]+)=(.*)$/s.exec(word);
|
|
27786
|
+
if (!set)
|
|
27787
|
+
return [];
|
|
27788
|
+
aliases.set(set[1], set[2]);
|
|
27789
|
+
return workitCalls(set[2], depth + 1, aliases);
|
|
27790
|
+
});
|
|
27791
|
+
const body = aliases.get(words[0] ?? "");
|
|
27792
|
+
if (body !== undefined)
|
|
27793
|
+
return workitCalls([body, ...words.slice(1).map((word) => `'${word.replaceAll("'", `'\\''`)}'`)].join(" "), depth + 1, aliases);
|
|
27794
|
+
let at = /^workit(?:\.exe|\.cmd)?$/.test(name) ? 0 : CLI_RUNNERS.test(name) ? words.findIndex((word, index) => index > 0 && CLI_ENTRY.test(word)) : -1;
|
|
27795
|
+
if (at < 0)
|
|
27796
|
+
return [];
|
|
27797
|
+
while (words[at + 1] === "--" || CLI_ENTRY.test(words[at + 1] ?? ""))
|
|
27798
|
+
at++;
|
|
27799
|
+
return [words.slice(at + 1)];
|
|
27800
|
+
});
|
|
27801
|
+
var JUDGE_JOB = Object.entries(JUDGE_VERBS).map(([verb, subs]) => `workit ${verb}${subs === true ? "" : ` ${subs.join("|")}`}`).join(", ");
|
|
27802
|
+
var judgeRefusal = (command, fed, depth = 0) => {
|
|
27803
|
+
let moved = false;
|
|
27804
|
+
for (const segment of segmentsOf(command)) {
|
|
27805
|
+
const nested = (script) => script !== undefined && depth < 4 ? judgeRefusal(script, fed, depth + 1) : null;
|
|
27806
|
+
for (const sub of segment.subs ?? []) {
|
|
27807
|
+
const why = nested(sub);
|
|
27808
|
+
if (why)
|
|
27809
|
+
return why;
|
|
27810
|
+
}
|
|
27811
|
+
const { words } = segment;
|
|
27812
|
+
const runs = (word = "") => RUNS.test(path39.basename(word).toLowerCase());
|
|
27813
|
+
let at = 0;
|
|
27814
|
+
while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
|
|
27815
|
+
at++;
|
|
27816
|
+
const name = path39.basename(words[at] ?? "").toLowerCase();
|
|
27817
|
+
const args = words.slice(at + 1);
|
|
27818
|
+
const unseen = `\`${words.join(" ").slice(0, 80)}\` runs a script Workit cannot read (piped, on stdin, a process substitution or eval): write the case to a file in ${SCRATCH} and dispatch it from a test instead`;
|
|
27819
|
+
if (/^(?:cd|chdir|pushd|popd)$/.test(name))
|
|
27820
|
+
moved = true;
|
|
27821
|
+
if (name === "eval" || (name === "source" || name === ".") && FED.test(args[0] ?? ""))
|
|
27822
|
+
return unseen;
|
|
27823
|
+
if (SHELL_NAMES.test(name)) {
|
|
27824
|
+
let operand;
|
|
27825
|
+
let stdin = false;
|
|
27826
|
+
let inline;
|
|
27827
|
+
for (let index = 0;index < args.length && inline === undefined; index++) {
|
|
27828
|
+
const arg = args[index];
|
|
27829
|
+
if (/^-[a-zA-Z]*c[a-zA-Z]*$/.test(arg))
|
|
27830
|
+
inline = index + 1;
|
|
27831
|
+
else if (/^[-+][oO]$/.test(arg))
|
|
27832
|
+
index++;
|
|
27833
|
+
else if (arg === "--" || !/^[-+]/.test(arg)) {
|
|
27834
|
+
operand = arg === "--" ? args[index + 1] : arg;
|
|
27835
|
+
break;
|
|
27836
|
+
} else if (/^-[a-zA-Z]*s/.test(arg))
|
|
27837
|
+
stdin = true;
|
|
27838
|
+
}
|
|
27839
|
+
if (inline !== undefined) {
|
|
27840
|
+
const why = nested(args[inline]);
|
|
27841
|
+
if (why)
|
|
27842
|
+
return why;
|
|
27843
|
+
} else if (operand === undefined || stdin || FED.test(operand)) {
|
|
27844
|
+
if (!segment.stdin?.length || moved || operand !== undefined && !stdin)
|
|
27845
|
+
return unseen;
|
|
27846
|
+
fed.push(...segment.stdin);
|
|
27847
|
+
for (const body of segment.stdin) {
|
|
27848
|
+
const why = nested(body);
|
|
27849
|
+
if (why)
|
|
27850
|
+
return why;
|
|
27851
|
+
}
|
|
27852
|
+
}
|
|
27853
|
+
}
|
|
27854
|
+
if (INTERPRETERS.test(name) && !args.some((arg) => INLINE.test(arg))) {
|
|
27855
|
+
const operand = args.find((arg, index) => (arg === "-" || !arg.startsWith("-")) && !VALUED.test(args[index - 1] ?? ""));
|
|
27856
|
+
if (FED.test(operand ?? "") || operand === undefined && !/^(?:bun|deno)$/.test(name))
|
|
27857
|
+
return unseen;
|
|
27858
|
+
}
|
|
27859
|
+
const tail = workitCheckTail(words.slice(at));
|
|
27860
|
+
if (tail) {
|
|
27861
|
+
const why = nested("script" in tail ? tail.script : tail.argv.map((word) => `'${word.replaceAll("'", `'\\''`)}'`).join(" "));
|
|
27862
|
+
if (why)
|
|
27863
|
+
return why;
|
|
27864
|
+
}
|
|
27865
|
+
}
|
|
27866
|
+
for (const args of workitCalls(command)) {
|
|
27867
|
+
const call = judgeVerbRefused(args);
|
|
27868
|
+
if (call)
|
|
27869
|
+
return `\`${call}\` is not a judge's job: a judge runs only ${JUDGE_JOB}`;
|
|
27870
|
+
}
|
|
27871
|
+
return null;
|
|
27872
|
+
};
|
|
27873
|
+
var substitutingHeredoc = (command) => {
|
|
27874
|
+
for (const match of command.matchAll(/(?<!<)<<-?[ \t]*([^\s<>;&|()]+)/g)) {
|
|
27875
|
+
const delimiter = match[1];
|
|
27876
|
+
if (/['"\\]/.test(delimiter))
|
|
27877
|
+
continue;
|
|
27878
|
+
const newline = command.indexOf(`
|
|
27879
|
+
`, match.index + match[0].length);
|
|
27880
|
+
if (newline < 0)
|
|
27881
|
+
continue;
|
|
27882
|
+
const lines = command.slice(newline + 1).split(`
|
|
27883
|
+
`);
|
|
27884
|
+
const end = lines.findIndex((line) => line.trim() === delimiter);
|
|
27885
|
+
if (/\$\((?!\()|`/.test((end < 0 ? lines : lines.slice(0, end)).join(`
|
|
27886
|
+
`)))
|
|
27887
|
+
return true;
|
|
27888
|
+
}
|
|
27889
|
+
return false;
|
|
27890
|
+
};
|
|
27891
|
+
var judgeDeny = (input, what) => {
|
|
27892
|
+
const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
|
|
27893
|
+
const root = checkoutOf2(input.cwd)?.root;
|
|
27894
|
+
const scratch = root ? path39.join(root, SCRATCH) : `${SCRATCH}/ at the root of the checkout you judge`;
|
|
27895
|
+
const unblock = `Write only under ${scratch} (mkdir -p it): put a generated case in a file there with a quoted heredoc (<<'EOF') and never run it in the shell. Reads, \`workit check\` and \`workit ledger verdict|finding\` stay allowed; a change the candidate needs is a finding, not an edit.`;
|
|
27896
|
+
return {
|
|
27897
|
+
kind: "deny",
|
|
27898
|
+
reason: `workit scratch confinement: ${role} ${input.session.agentId} may write only in its scratch dir ${scratch}, and ${what}. ${unblock}`,
|
|
27899
|
+
unblock
|
|
27900
|
+
};
|
|
27901
|
+
};
|
|
27902
|
+
function confineJudge(input, targets) {
|
|
27903
|
+
try {
|
|
27904
|
+
if (!input.session.agentId)
|
|
27905
|
+
return NONE5;
|
|
27906
|
+
const judged = checkoutOf2(input.cwd);
|
|
27907
|
+
const repo = judged ? commonDir(judged.root) : null;
|
|
27908
|
+
for (const target of targets) {
|
|
27909
|
+
const resolved = path39.resolve(target);
|
|
27910
|
+
if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
|
|
27911
|
+
return judgeDeny(input, "it writes to a path Workit cannot resolve (a variable, a command substitution or `cd -`): spell the path out");
|
|
27912
|
+
if (inScratch(canonical4(target), repo))
|
|
27913
|
+
continue;
|
|
27914
|
+
const runner = runnerAt(target);
|
|
27915
|
+
return judgeDeny(input, runner === null ? `${shown(target)} is outside it` : `\`${runner}\` runs in ${shown(target)}, outside it`);
|
|
27916
|
+
}
|
|
27917
|
+
return NONE5;
|
|
27918
|
+
} catch {
|
|
27919
|
+
return NONE5;
|
|
27920
|
+
}
|
|
27921
|
+
}
|
|
27922
|
+
function confineJudgeShell(input, command, dialect = "posix") {
|
|
27923
|
+
try {
|
|
27924
|
+
if (!input.session.agentId)
|
|
27925
|
+
return NONE5;
|
|
27926
|
+
const fed = [];
|
|
27927
|
+
let refused;
|
|
27928
|
+
try {
|
|
27929
|
+
refused = dialect === "posix" ? judgeRefusal(command, fed) : null;
|
|
27930
|
+
} catch {
|
|
27931
|
+
refused = "Workit cannot read this command: split it into simpler ones";
|
|
27932
|
+
}
|
|
27933
|
+
if (refused)
|
|
27934
|
+
return judgeDeny(input, refused);
|
|
27935
|
+
if (dialect === "posix" && substitutingHeredoc(command))
|
|
27936
|
+
return judgeDeny(input, "an unquoted heredoc runs the `$(…)` or backtick command in its body: quote the delimiter (<<'EOF')");
|
|
27937
|
+
let git = [];
|
|
27938
|
+
try {
|
|
27939
|
+
git = rawInvocations(command, dialect).flatMap(({ tool, dir, args }) => tool === "git" && (args[0] === "push" || leadOwnedGit(args)) ? [
|
|
27940
|
+
path39.join(dir === undefined ? UNKNOWN_DIR : path39.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
|
|
27941
|
+
] : []);
|
|
27942
|
+
} catch {}
|
|
27943
|
+
return confineJudge(input, [
|
|
27944
|
+
...shellMutationTargets(input.cwd, command, dialect, true),
|
|
27945
|
+
...fed.flatMap((body) => shellMutationTargets(input.cwd, body, "posix", true)),
|
|
27946
|
+
...git
|
|
27947
|
+
]);
|
|
27948
|
+
} catch {
|
|
27949
|
+
return NONE5;
|
|
27950
|
+
}
|
|
27951
|
+
}
|
|
27642
27952
|
|
|
27643
27953
|
// packages/workit-core/src/hooks/steering.ts
|
|
27644
27954
|
var ROLES = {
|
|
@@ -28212,7 +28522,7 @@ var usable2 = (value) => value === "native" || value === "partial";
|
|
|
28212
28522
|
var NONE6 = { kind: "none" };
|
|
28213
28523
|
var resendsOnChange = (descriptor) => descriptor.context.turnResend === "on-change" && usable2(descriptor.context.perTurn);
|
|
28214
28524
|
var offered = new Set;
|
|
28215
|
-
var
|
|
28525
|
+
var agentRole = (input, descriptor) => input.session.agentId && input.session.agentType !== null ? workitRole(descriptor, input.session.agentType) : null;
|
|
28216
28526
|
var LIMIT_TEXT_MAX = 1000;
|
|
28217
28527
|
var usageLimitOnStop = (input, agentId, text) => {
|
|
28218
28528
|
try {
|
|
@@ -28326,12 +28636,14 @@ function decide(input, deps) {
|
|
|
28326
28636
|
unblock: null
|
|
28327
28637
|
};
|
|
28328
28638
|
}
|
|
28329
|
-
|
|
28330
|
-
|
|
28639
|
+
const role = canDeny ? agentRole(input, descriptor) : null;
|
|
28640
|
+
if (role) {
|
|
28641
|
+
const confined = (role === "implementer" ? confineImplementerShell : confineJudgeShell)(input, event.command, event.dialect);
|
|
28331
28642
|
if (confined.kind === "deny")
|
|
28332
28643
|
return confined;
|
|
28333
28644
|
}
|
|
28334
|
-
const
|
|
28645
|
+
const owner = role === "judge" ? null : liveOwner(input, descriptor.transport);
|
|
28646
|
+
const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, owner, event.dialect) : NONE6;
|
|
28335
28647
|
if (gate.kind === "deny")
|
|
28336
28648
|
return gate;
|
|
28337
28649
|
const plan = heavyGate(input.cwd, event.command, {
|
|
@@ -28378,12 +28690,14 @@ function decide(input, deps) {
|
|
|
28378
28690
|
case "write.pre": {
|
|
28379
28691
|
if (!usable2(descriptor.events["write.pre"].support))
|
|
28380
28692
|
return NONE6;
|
|
28381
|
-
|
|
28382
|
-
|
|
28693
|
+
const role = agentRole(input, descriptor);
|
|
28694
|
+
if (role) {
|
|
28695
|
+
const targets = liveTargets(input.cwd, event.paths);
|
|
28696
|
+
const confined = role === "implementer" ? confineImplementer(input, targets) : confineJudge(input, targets);
|
|
28383
28697
|
if (confined.kind === "deny")
|
|
28384
28698
|
return confined;
|
|
28385
28699
|
}
|
|
28386
|
-
return writeGate(input.cwd, event.paths, liveOwner(input, descriptor.transport));
|
|
28700
|
+
return writeGate(input.cwd, event.paths, role === "judge" ? null : liveOwner(input, descriptor.transport));
|
|
28387
28701
|
}
|
|
28388
28702
|
case "subagent.start":
|
|
28389
28703
|
if (workitRole(descriptor, event.agentType) === "judge")
|