@workit-dev/codex 2.19.0 → 2.20.1
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.
|
@@ -12541,6 +12541,203 @@ function generatedByAttributes(files, paths) {
|
|
|
12541
12541
|
return out;
|
|
12542
12542
|
}
|
|
12543
12543
|
|
|
12544
|
+
// packages/workit-core/src/core/policy/dep-bump.ts
|
|
12545
|
+
var MANIFESTS = new Set(["package.json", "go.mod", "Cargo.toml", "pyproject.toml"]);
|
|
12546
|
+
var basename = (file) => file.slice(file.lastIndexOf("/") + 1);
|
|
12547
|
+
var isManifest = (file) => MANIFESTS.has(basename(file));
|
|
12548
|
+
var refused = (why) => ({ pins: false, bumped: 0, scripts: [], why });
|
|
12549
|
+
var pinned = (bumped, scripts = []) => ({
|
|
12550
|
+
pins: true,
|
|
12551
|
+
bumped,
|
|
12552
|
+
scripts,
|
|
12553
|
+
why: ""
|
|
12554
|
+
});
|
|
12555
|
+
var DEP_FIELDS = new Set([
|
|
12556
|
+
"dependencies",
|
|
12557
|
+
"devDependencies",
|
|
12558
|
+
"peerDependencies",
|
|
12559
|
+
"optionalDependencies"
|
|
12560
|
+
]);
|
|
12561
|
+
var NPM_COMPARATOR = /^(?:[~^]|[<>]=?|=)?v?\d+(?:\.(?:\d+|x|\*)){0,2}(?:-[\da-z.-]+)?(?:\+[\da-z.-]+)?$/iu;
|
|
12562
|
+
function npmVersion(spec) {
|
|
12563
|
+
if (spec.length > 256)
|
|
12564
|
+
return false;
|
|
12565
|
+
return spec.split("||").every((set) => {
|
|
12566
|
+
const tokens = set.trim().replace(/([<>]=?|=|[~^])\s+/gu, "$1").split(/\s+/u);
|
|
12567
|
+
if (tokens.length === 3 && tokens[1] === "-")
|
|
12568
|
+
return NPM_COMPARATOR.test(tokens[0] ?? "") && NPM_COMPARATOR.test(tokens[2] ?? "");
|
|
12569
|
+
return tokens.every((token) => NPM_COMPARATOR.test(token));
|
|
12570
|
+
});
|
|
12571
|
+
}
|
|
12572
|
+
var HOOK_SCRIPT = /^(?:pre|post)|^(?:install|uninstall|prepare|publish|pack|version|dependencies|start|stop|restart|test)$/u;
|
|
12573
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12574
|
+
var same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
12575
|
+
function packageJson(before, after) {
|
|
12576
|
+
let old;
|
|
12577
|
+
let now;
|
|
12578
|
+
try {
|
|
12579
|
+
old = JSON.parse(before);
|
|
12580
|
+
now = JSON.parse(after);
|
|
12581
|
+
} catch {
|
|
12582
|
+
return refused("does not parse");
|
|
12583
|
+
}
|
|
12584
|
+
if (!isRecord2(old) || !isRecord2(now))
|
|
12585
|
+
return refused("is no JSON object");
|
|
12586
|
+
let bumped = 0;
|
|
12587
|
+
const scripts = [];
|
|
12588
|
+
for (const field of new Set([...Object.keys(old), ...Object.keys(now)])) {
|
|
12589
|
+
const a = old[field];
|
|
12590
|
+
const b = now[field];
|
|
12591
|
+
if (same(a, b))
|
|
12592
|
+
continue;
|
|
12593
|
+
if (DEP_FIELDS.has(field)) {
|
|
12594
|
+
if (!isRecord2(a) || !isRecord2(b))
|
|
12595
|
+
return refused(`changes ${field}`);
|
|
12596
|
+
for (const name of new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
12597
|
+
if (a[name] === b[name])
|
|
12598
|
+
continue;
|
|
12599
|
+
if (!(name in a))
|
|
12600
|
+
return refused(`adds the dependency ${name}`);
|
|
12601
|
+
if (!(name in b))
|
|
12602
|
+
return refused(`removes the dependency ${name}`);
|
|
12603
|
+
const from = a[name];
|
|
12604
|
+
const to = b[name];
|
|
12605
|
+
if (typeof from !== "string" || typeof to !== "string")
|
|
12606
|
+
return refused(`changes ${field}.${name}`);
|
|
12607
|
+
if (!npmVersion(from.trim()) || !npmVersion(to.trim()))
|
|
12608
|
+
return refused(`changes the source of ${name}`);
|
|
12609
|
+
bumped += 1;
|
|
12610
|
+
}
|
|
12611
|
+
} else if (field === "scripts") {
|
|
12612
|
+
if (!isRecord2(a) || !isRecord2(b))
|
|
12613
|
+
return refused("changes scripts");
|
|
12614
|
+
for (const name of Object.keys(a))
|
|
12615
|
+
if (a[name] !== b[name])
|
|
12616
|
+
return refused(`changes the script ${name}`);
|
|
12617
|
+
for (const name of Object.keys(b)) {
|
|
12618
|
+
if (name in a)
|
|
12619
|
+
continue;
|
|
12620
|
+
if (HOOK_SCRIPT.test(name))
|
|
12621
|
+
return refused(`adds the lifecycle script ${name}`);
|
|
12622
|
+
if (name.startsWith("pnpm:"))
|
|
12623
|
+
return refused(`adds the pnpm: script ${name}`);
|
|
12624
|
+
const runner = Object.entries(a).find(([, command]) => typeof command === "string" && runsByGlob(command, name));
|
|
12625
|
+
if (runner)
|
|
12626
|
+
return refused(`adds the script ${name}, which the script ${runner[0]} runs by glob`);
|
|
12627
|
+
scripts.push(name);
|
|
12628
|
+
}
|
|
12629
|
+
} else
|
|
12630
|
+
return refused(`changes ${field}`);
|
|
12631
|
+
}
|
|
12632
|
+
return pinned(bumped, scripts);
|
|
12633
|
+
}
|
|
12634
|
+
function runsByGlob(command, name) {
|
|
12635
|
+
const tokens = command.split(/\s+/u).map((token) => token.replace(/^--filter=/u, "").replaceAll(/^["']|["']$/gu, "").replace(/^(?:npm|pnpm|yarn|bun):/u, ""));
|
|
12636
|
+
if (/\bpnpm\b/u.test(command) && tokens.some((token) => /^\/.+\/$/u.test(token)))
|
|
12637
|
+
return true;
|
|
12638
|
+
return tokens.filter((token) => token.includes("*")).some((glob) => new RegExp(`^${glob.split(/\*+/u).map((part) => part.replaceAll(/[.+?^${}()|[\]\\]/gu, "\\$&")).join(".*")}$`, "u").test(name));
|
|
12639
|
+
}
|
|
12640
|
+
function goDirectives(text) {
|
|
12641
|
+
const out = [];
|
|
12642
|
+
let block = null;
|
|
12643
|
+
for (const raw of text.split(`
|
|
12644
|
+
`)) {
|
|
12645
|
+
const indirect = /\/\/\s*indirect\s*$/u.test(raw);
|
|
12646
|
+
const line = raw.replace(/\/\/.*$/u, "").trim();
|
|
12647
|
+
if (!line)
|
|
12648
|
+
continue;
|
|
12649
|
+
if (block !== null) {
|
|
12650
|
+
if (line === ")")
|
|
12651
|
+
block = null;
|
|
12652
|
+
else
|
|
12653
|
+
out.push({ verb: block, args: line.replace(/\s+/gu, " "), indirect });
|
|
12654
|
+
continue;
|
|
12655
|
+
}
|
|
12656
|
+
const match = /^(\S+)\s*(.*)$/u.exec(line);
|
|
12657
|
+
if (!match)
|
|
12658
|
+
return null;
|
|
12659
|
+
const [, verb = "", rest = ""] = match;
|
|
12660
|
+
if (rest === "(")
|
|
12661
|
+
block = verb;
|
|
12662
|
+
else
|
|
12663
|
+
out.push({ verb, args: rest.replace(/\s+/gu, " "), indirect });
|
|
12664
|
+
}
|
|
12665
|
+
return block === null ? out : null;
|
|
12666
|
+
}
|
|
12667
|
+
var GO_VERSION = /^v\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+incompatible)?$/u;
|
|
12668
|
+
function goMod(before, after) {
|
|
12669
|
+
const old = goDirectives(before);
|
|
12670
|
+
const now = goDirectives(after);
|
|
12671
|
+
if (!old || !now)
|
|
12672
|
+
return refused("does not parse");
|
|
12673
|
+
if (old.length !== now.length)
|
|
12674
|
+
return refused("adds or removes a directive");
|
|
12675
|
+
let bumped = 0;
|
|
12676
|
+
for (const [index, a] of old.entries()) {
|
|
12677
|
+
const b = now[index];
|
|
12678
|
+
if (a.verb === b.verb && a.args === b.args && a.indirect === b.indirect)
|
|
12679
|
+
continue;
|
|
12680
|
+
if (a.verb !== "require" || b.verb !== "require" || a.indirect !== b.indirect)
|
|
12681
|
+
return refused(`changes ${a.verb}`);
|
|
12682
|
+
const [module, from, extra] = a.args.split(" ");
|
|
12683
|
+
const [moduleAfter, to, extraAfter] = b.args.split(" ");
|
|
12684
|
+
if (module !== moduleAfter || extra !== undefined || extraAfter !== undefined)
|
|
12685
|
+
return refused(`changes require ${module ?? ""}`);
|
|
12686
|
+
if (!GO_VERSION.test(from ?? "") || !GO_VERSION.test(to ?? ""))
|
|
12687
|
+
return refused(`changes the source of ${module ?? ""}`);
|
|
12688
|
+
bumped += 1;
|
|
12689
|
+
}
|
|
12690
|
+
return pinned(bumped);
|
|
12691
|
+
}
|
|
12692
|
+
var CARGO_TABLE = /^(?:workspace\.)?(?:target\..+\.)?(?:dev-|build-)?dependencies(?:\.[^.]+)?$/u;
|
|
12693
|
+
var PYPROJECT_TABLE = /^(?:project\.optional-dependencies|dependency-groups|tool\.poetry\.(?:dev-)?dependencies|tool\.poetry\.group\.[^.]+\.dependencies)$/u;
|
|
12694
|
+
var OTHER_SOURCE = /\b(?:git|rev|branch|tag|path|url|registry|package)\s*=|@|:\/\//u;
|
|
12695
|
+
var VERSION_TOKEN = /(?<=[\s"'=<>~^!,*v])\d+(?:\.\d+)*(?:[a-z]+\d*)?(?:\.(?:post|dev)\d+)?/giu;
|
|
12696
|
+
function tomlPins(before, after, cargo) {
|
|
12697
|
+
const old = before.split(`
|
|
12698
|
+
`);
|
|
12699
|
+
const now = after.split(`
|
|
12700
|
+
`);
|
|
12701
|
+
if (old.length !== now.length)
|
|
12702
|
+
return refused("adds or removes lines");
|
|
12703
|
+
let table = "";
|
|
12704
|
+
let inArray = false;
|
|
12705
|
+
let bumped = 0;
|
|
12706
|
+
for (const [index, a] of old.entries()) {
|
|
12707
|
+
const b = now[index] ?? "";
|
|
12708
|
+
const header = /^\s*\[\[?([^\]]+)\]\]?\s*(?:#.*)?$/u.exec(a);
|
|
12709
|
+
if (header) {
|
|
12710
|
+
table = (header[1] ?? "").replace(/\s+/gu, "");
|
|
12711
|
+
inArray = false;
|
|
12712
|
+
} else if (!cargo && table === "project" && /^\s*dependencies\s*=\s*\[\s*(?:#.*)?$/u.test(a))
|
|
12713
|
+
inArray = true;
|
|
12714
|
+
else if (inArray && /^\s*\]/u.test(a))
|
|
12715
|
+
inArray = false;
|
|
12716
|
+
if (a === b)
|
|
12717
|
+
continue;
|
|
12718
|
+
const listed = cargo ? CARGO_TABLE.test(table) : PYPROJECT_TABLE.test(table) || inArray || table === "project" && /^\s*dependencies\s*=/u.test(a);
|
|
12719
|
+
if (header || !listed)
|
|
12720
|
+
return refused(`changes line ${index + 1} outside a dependency table`);
|
|
12721
|
+
if (OTHER_SOURCE.test(a) || OTHER_SOURCE.test(b))
|
|
12722
|
+
return refused(`changes a dependency source on line ${index + 1}`);
|
|
12723
|
+
const key = (line) => /^\s*("?[\w.[\],-]+"?)/u.exec(line)?.[1] ?? "";
|
|
12724
|
+
const versionless = (line) => line.replace(VERSION_TOKEN, "V");
|
|
12725
|
+
const names = (line) => cargo ? "" : [...line.matchAll(/"([A-Za-z_][\w.-]*)/gu)].map((match) => match[1]).join(",");
|
|
12726
|
+
if (key(a) !== key(b) || names(a) !== names(b) || versionless(a) !== versionless(b))
|
|
12727
|
+
return refused(`changes more than a version on line ${index + 1}`);
|
|
12728
|
+
bumped += 1;
|
|
12729
|
+
}
|
|
12730
|
+
return pinned(bumped);
|
|
12731
|
+
}
|
|
12732
|
+
function manifestEdit(file, before, after) {
|
|
12733
|
+
const name = basename(file);
|
|
12734
|
+
if (name === "package.json")
|
|
12735
|
+
return packageJson(before, after);
|
|
12736
|
+
if (name === "go.mod")
|
|
12737
|
+
return goMod(before, after);
|
|
12738
|
+
return tomlPins(before, after, name === "Cargo.toml");
|
|
12739
|
+
}
|
|
12740
|
+
|
|
12544
12741
|
// packages/workit-core/src/core/policy/substance.ts
|
|
12545
12742
|
var SLASH_BLOCK = [["/*", "*/"]];
|
|
12546
12743
|
var C_LIKE = { line: ["//"], block: SLASH_BLOCK, quotes: `"'` };
|
|
@@ -12859,6 +13056,483 @@ function cosmeticChange(file, before, after) {
|
|
|
12859
13056
|
return a !== null && a === substanceOf(file, right);
|
|
12860
13057
|
}
|
|
12861
13058
|
|
|
13059
|
+
// packages/workit-core/src/core/policy/workflow-edit.ts
|
|
13060
|
+
class Unparsed extends Error {
|
|
13061
|
+
}
|
|
13062
|
+
var refuse = (why) => {
|
|
13063
|
+
throw new Unparsed(why);
|
|
13064
|
+
};
|
|
13065
|
+
var NON_STRING = /^(?:~|null|true|false|yes|no|on|off|y|n|[-+]?(?:\d[\d_]*(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?|0x[\da-f]+|0o[0-7]+|[-+]?\.inf|\.nan)$/iu;
|
|
13066
|
+
var HEX_DIGITS = { x: 2, u: 4, U: 8 };
|
|
13067
|
+
var ESCAPES = {
|
|
13068
|
+
n: `
|
|
13069
|
+
`,
|
|
13070
|
+
t: "\t",
|
|
13071
|
+
r: "\r",
|
|
13072
|
+
"0": "\x00",
|
|
13073
|
+
'"': '"',
|
|
13074
|
+
"\\": "\\",
|
|
13075
|
+
"/": "/",
|
|
13076
|
+
" ": " "
|
|
13077
|
+
};
|
|
13078
|
+
var scalar = (text, string, folded = false) => ({
|
|
13079
|
+
kind: "scalar",
|
|
13080
|
+
text,
|
|
13081
|
+
string,
|
|
13082
|
+
folded
|
|
13083
|
+
});
|
|
13084
|
+
function quoted(text, start) {
|
|
13085
|
+
const quote = text[start];
|
|
13086
|
+
let out = "";
|
|
13087
|
+
for (let index = start + 1;index < text.length; index += 1) {
|
|
13088
|
+
const char = text[index] ?? "";
|
|
13089
|
+
if (quote === "'" && char === "'") {
|
|
13090
|
+
if (text[index + 1] !== "'")
|
|
13091
|
+
return { value: out, end: index + 1 };
|
|
13092
|
+
out += "'";
|
|
13093
|
+
index += 1;
|
|
13094
|
+
} else if (quote === '"' && char === '"')
|
|
13095
|
+
return { value: out, end: index + 1 };
|
|
13096
|
+
else if (quote === '"' && char === "\\") {
|
|
13097
|
+
const next = text[index + 1] ?? "";
|
|
13098
|
+
const hex = HEX_DIGITS[next];
|
|
13099
|
+
if (hex) {
|
|
13100
|
+
const digits = text.slice(index + 2, index + 2 + hex);
|
|
13101
|
+
if (!/^[\da-f]+$/iu.test(digits) || digits.length !== hex)
|
|
13102
|
+
refuse("a bad escape");
|
|
13103
|
+
out += String.fromCodePoint(Number.parseInt(digits, 16));
|
|
13104
|
+
index += 1 + hex;
|
|
13105
|
+
} else {
|
|
13106
|
+
out += ESCAPES[next] ?? refuse("an unknown escape");
|
|
13107
|
+
index += 1;
|
|
13108
|
+
}
|
|
13109
|
+
} else
|
|
13110
|
+
out += char;
|
|
13111
|
+
}
|
|
13112
|
+
return refuse("a quoted scalar spans lines");
|
|
13113
|
+
}
|
|
13114
|
+
function trailing(text, end) {
|
|
13115
|
+
const rest = text.slice(end);
|
|
13116
|
+
if (rest.trim() && !/^\s+#/u.test(rest))
|
|
13117
|
+
refuse("text after a value");
|
|
13118
|
+
}
|
|
13119
|
+
var INDICATOR = /^[&*!%@`|>,[\]{}?:#-]/u;
|
|
13120
|
+
function plain(text) {
|
|
13121
|
+
const value = text.replace(/\s+#.*$/u, "").trimEnd();
|
|
13122
|
+
if (INDICATOR.test(value) && !/^-[^\s]/u.test(value))
|
|
13123
|
+
refuse("an indicator starts a scalar");
|
|
13124
|
+
if (/:\s|:$/u.test(value))
|
|
13125
|
+
refuse("a mapping inside a scalar");
|
|
13126
|
+
return scalar(value, !NON_STRING.test(value));
|
|
13127
|
+
}
|
|
13128
|
+
function flow(text, start) {
|
|
13129
|
+
const close = text[start] === "[" ? "]" : "}";
|
|
13130
|
+
const items = [];
|
|
13131
|
+
const entries = new Map;
|
|
13132
|
+
let index = start + 1;
|
|
13133
|
+
const skip = () => {
|
|
13134
|
+
while (text[index] === " ")
|
|
13135
|
+
index += 1;
|
|
13136
|
+
};
|
|
13137
|
+
const element = (stops) => {
|
|
13138
|
+
skip();
|
|
13139
|
+
const char = text[index];
|
|
13140
|
+
if (char === '"' || char === "'") {
|
|
13141
|
+
const read = quoted(text, index);
|
|
13142
|
+
index = read.end;
|
|
13143
|
+
return scalar(read.value, true);
|
|
13144
|
+
}
|
|
13145
|
+
if (char === "[" || char === "{") {
|
|
13146
|
+
const read = flow(text, index);
|
|
13147
|
+
index = read.end;
|
|
13148
|
+
return read.node;
|
|
13149
|
+
}
|
|
13150
|
+
let end = index;
|
|
13151
|
+
while (end < text.length && !stops.test(text[end] ?? ""))
|
|
13152
|
+
end += 1;
|
|
13153
|
+
const value = text.slice(index, end).trim();
|
|
13154
|
+
index = end;
|
|
13155
|
+
if (!value || value.includes("#"))
|
|
13156
|
+
refuse("an empty or commented flow element");
|
|
13157
|
+
return plain(value);
|
|
13158
|
+
};
|
|
13159
|
+
for (;; ) {
|
|
13160
|
+
skip();
|
|
13161
|
+
if (index >= text.length)
|
|
13162
|
+
refuse("a flow collection spans lines");
|
|
13163
|
+
if (text[index] === close)
|
|
13164
|
+
return {
|
|
13165
|
+
node: close === "]" ? { kind: "seq", items } : { kind: "map", entries },
|
|
13166
|
+
end: index + 1
|
|
13167
|
+
};
|
|
13168
|
+
if (close === "]")
|
|
13169
|
+
items.push(element(/[,\]]/u));
|
|
13170
|
+
else {
|
|
13171
|
+
const key = element(/[:,}]/u);
|
|
13172
|
+
skip();
|
|
13173
|
+
if (text[index] !== ":" || key.kind !== "scalar")
|
|
13174
|
+
refuse("a flow mapping without a value");
|
|
13175
|
+
index += 1;
|
|
13176
|
+
const value = element(/[,}]/u);
|
|
13177
|
+
const name = key.kind === "scalar" ? key.text : "";
|
|
13178
|
+
if (entries.has(name))
|
|
13179
|
+
refuse("a duplicate key");
|
|
13180
|
+
entries.set(name, value);
|
|
13181
|
+
}
|
|
13182
|
+
skip();
|
|
13183
|
+
if (text[index] === ",")
|
|
13184
|
+
index += 1;
|
|
13185
|
+
else if (text[index] !== close)
|
|
13186
|
+
refuse("a malformed flow collection");
|
|
13187
|
+
}
|
|
13188
|
+
}
|
|
13189
|
+
var isItem = (text) => text === "-" || text.startsWith("- ");
|
|
13190
|
+
function splitKey(text) {
|
|
13191
|
+
if (text[0] === '"' || text[0] === "'") {
|
|
13192
|
+
const read = quoted(text, 0);
|
|
13193
|
+
const after = text.slice(read.end);
|
|
13194
|
+
const match = /^\s*:(?:\s+|$)/u.exec(after);
|
|
13195
|
+
return match ? { key: read.value, rest: after.slice(match[0].length) } : null;
|
|
13196
|
+
}
|
|
13197
|
+
const match = /:(?:\s|$)/u.exec(text);
|
|
13198
|
+
if (!match || INDICATOR.test(text))
|
|
13199
|
+
return null;
|
|
13200
|
+
const key = text.slice(0, match.index).trimEnd();
|
|
13201
|
+
if (!key || key.includes(" #"))
|
|
13202
|
+
return null;
|
|
13203
|
+
return { key, rest: text.slice(match.index + 1).trimStart() };
|
|
13204
|
+
}
|
|
13205
|
+
|
|
13206
|
+
class Reader {
|
|
13207
|
+
lines;
|
|
13208
|
+
pos = 0;
|
|
13209
|
+
constructor(text) {
|
|
13210
|
+
const normal = text.replace(/\r\n/gu, `
|
|
13211
|
+
`);
|
|
13212
|
+
if (normal.includes("\r") || normal.charCodeAt(0) === 65279)
|
|
13213
|
+
refuse("an odd line break or BOM");
|
|
13214
|
+
this.lines = normal.split(`
|
|
13215
|
+
`);
|
|
13216
|
+
const first = this.lines.findIndex((line) => line.trim() && !line.trimStart().startsWith("#"));
|
|
13217
|
+
if (first >= 0 && /^---\s*(?:#.*)?$/u.test(this.lines[first] ?? ""))
|
|
13218
|
+
this.lines[first] = "";
|
|
13219
|
+
}
|
|
13220
|
+
next() {
|
|
13221
|
+
while (this.pos < this.lines.length) {
|
|
13222
|
+
const raw = this.lines[this.pos] ?? "";
|
|
13223
|
+
const text = raw.trimStart();
|
|
13224
|
+
if (text === "" || text.startsWith("#")) {
|
|
13225
|
+
this.pos += 1;
|
|
13226
|
+
continue;
|
|
13227
|
+
}
|
|
13228
|
+
const indent = raw.length - text.length;
|
|
13229
|
+
if (raw.slice(0, indent).includes("\t"))
|
|
13230
|
+
refuse("a tab indents a line");
|
|
13231
|
+
if (indent === 0 && /^(?:---|\.\.\.)(?:\s|$)|^%/u.test(text))
|
|
13232
|
+
refuse("several documents");
|
|
13233
|
+
return { indent, text: text.trimEnd() };
|
|
13234
|
+
}
|
|
13235
|
+
return null;
|
|
13236
|
+
}
|
|
13237
|
+
document() {
|
|
13238
|
+
const root = this.block(0);
|
|
13239
|
+
if (this.next())
|
|
13240
|
+
refuse("content after the document");
|
|
13241
|
+
return root;
|
|
13242
|
+
}
|
|
13243
|
+
block(min) {
|
|
13244
|
+
const line = this.next();
|
|
13245
|
+
if (!line || line.indent < min)
|
|
13246
|
+
return scalar("", false);
|
|
13247
|
+
return isItem(line.text) ? this.sequence(line.indent) : this.mapping(line.indent);
|
|
13248
|
+
}
|
|
13249
|
+
mapping(indent) {
|
|
13250
|
+
const entries = new Map;
|
|
13251
|
+
for (let line = this.next();line && line.indent >= indent; line = this.next()) {
|
|
13252
|
+
if (line.indent > indent || isItem(line.text))
|
|
13253
|
+
refuse("bad indentation");
|
|
13254
|
+
const split = splitKey(line.text) ?? refuse("a line that is no mapping entry");
|
|
13255
|
+
if (entries.has(split.key))
|
|
13256
|
+
refuse("a duplicate key");
|
|
13257
|
+
this.pos += 1;
|
|
13258
|
+
entries.set(split.key, this.value(split.rest, indent, true));
|
|
13259
|
+
}
|
|
13260
|
+
return { kind: "map", entries };
|
|
13261
|
+
}
|
|
13262
|
+
sequence(indent) {
|
|
13263
|
+
const items = [];
|
|
13264
|
+
for (let line = this.next();line && line.indent === indent && isItem(line.text); line = this.next()) {
|
|
13265
|
+
const rest = line.text.slice(1).trimStart();
|
|
13266
|
+
const offset = indent + line.text.length - rest.length;
|
|
13267
|
+
if (isItem(rest))
|
|
13268
|
+
refuse("a sequence inside a sequence item");
|
|
13269
|
+
if (rest && !/^[|>[{]/u.test(rest) && splitKey(rest)) {
|
|
13270
|
+
this.lines[this.pos] = " ".repeat(offset) + rest;
|
|
13271
|
+
items.push(this.mapping(offset));
|
|
13272
|
+
} else {
|
|
13273
|
+
this.pos += 1;
|
|
13274
|
+
items.push(this.value(rest, indent, false));
|
|
13275
|
+
}
|
|
13276
|
+
}
|
|
13277
|
+
const line = this.next();
|
|
13278
|
+
if (line && line.indent > indent)
|
|
13279
|
+
refuse("bad indentation");
|
|
13280
|
+
return { kind: "seq", items };
|
|
13281
|
+
}
|
|
13282
|
+
value(rest, indent, inMapping) {
|
|
13283
|
+
if (rest === "" || rest.startsWith("#")) {
|
|
13284
|
+
const line = this.next();
|
|
13285
|
+
if (line && line.indent > indent)
|
|
13286
|
+
return this.block(line.indent);
|
|
13287
|
+
if (inMapping && line?.indent === indent && isItem(line.text))
|
|
13288
|
+
return this.sequence(indent);
|
|
13289
|
+
return scalar("", false);
|
|
13290
|
+
}
|
|
13291
|
+
let node;
|
|
13292
|
+
if (rest[0] === "|" || rest[0] === ">")
|
|
13293
|
+
return this.blockScalar(rest, indent);
|
|
13294
|
+
if (rest[0] === '"' || rest[0] === "'") {
|
|
13295
|
+
const read = quoted(rest, 0);
|
|
13296
|
+
trailing(rest, read.end);
|
|
13297
|
+
node = scalar(read.value, true);
|
|
13298
|
+
} else if (rest[0] === "[" || rest[0] === "{") {
|
|
13299
|
+
const read = flow(rest, 0);
|
|
13300
|
+
trailing(rest, read.end);
|
|
13301
|
+
node = read.node;
|
|
13302
|
+
} else
|
|
13303
|
+
node = plain(rest);
|
|
13304
|
+
const line = this.next();
|
|
13305
|
+
if (line && line.indent > indent)
|
|
13306
|
+
refuse("a value continues on the next line");
|
|
13307
|
+
return node;
|
|
13308
|
+
}
|
|
13309
|
+
blockScalar(header, indent) {
|
|
13310
|
+
const match = /^([|>])(?:([-+])([1-9])?|([1-9])([-+])?)?\s*(?:#.*)?$/u.exec(header);
|
|
13311
|
+
if (!match)
|
|
13312
|
+
return refuse("a bad block scalar header");
|
|
13313
|
+
const chomp = match[2] ?? match[5] ?? "";
|
|
13314
|
+
const indicator = match[3] ?? match[4];
|
|
13315
|
+
let column = indicator ? indent + Number(indicator) : null;
|
|
13316
|
+
const body = [];
|
|
13317
|
+
while (this.pos < this.lines.length) {
|
|
13318
|
+
const raw = this.lines[this.pos] ?? "";
|
|
13319
|
+
if (raw.trim() === "") {
|
|
13320
|
+
body.push(column !== null && raw.length > column ? raw.slice(column) : "");
|
|
13321
|
+
this.pos += 1;
|
|
13322
|
+
continue;
|
|
13323
|
+
}
|
|
13324
|
+
const lead = raw.length - raw.trimStart().length;
|
|
13325
|
+
if (column === null) {
|
|
13326
|
+
if (lead <= indent)
|
|
13327
|
+
break;
|
|
13328
|
+
column = lead;
|
|
13329
|
+
}
|
|
13330
|
+
if (lead < column) {
|
|
13331
|
+
if (lead > indent)
|
|
13332
|
+
refuse("an under-indented block line");
|
|
13333
|
+
break;
|
|
13334
|
+
}
|
|
13335
|
+
if (raw.slice(0, column).includes("\t"))
|
|
13336
|
+
refuse("a tab indents a line");
|
|
13337
|
+
body.push(raw.slice(column));
|
|
13338
|
+
this.pos += 1;
|
|
13339
|
+
}
|
|
13340
|
+
let end = body.length;
|
|
13341
|
+
while (end > 0 && body[end - 1] === "")
|
|
13342
|
+
end -= 1;
|
|
13343
|
+
const content = body.slice(0, end).join(`
|
|
13344
|
+
`);
|
|
13345
|
+
const text = chomp === "+" ? `${body.join(`
|
|
13346
|
+
`)}
|
|
13347
|
+
` : chomp === "-" || !content ? content : `${content}
|
|
13348
|
+
`;
|
|
13349
|
+
return scalar(text, true, match[1] === ">");
|
|
13350
|
+
}
|
|
13351
|
+
}
|
|
13352
|
+
function parseWorkflowYaml(text) {
|
|
13353
|
+
try {
|
|
13354
|
+
return new Reader(text).document();
|
|
13355
|
+
} catch (error) {
|
|
13356
|
+
if (error instanceof Unparsed)
|
|
13357
|
+
return null;
|
|
13358
|
+
throw error;
|
|
13359
|
+
}
|
|
13360
|
+
}
|
|
13361
|
+
var isWorkflowFile = (file) => /^\.github\/workflows\/[^/]+\.ya?ml$/u.test(file);
|
|
13362
|
+
var GUARDED = new Set(["permissions", "secrets", "on", "uses", "environment", "if"]);
|
|
13363
|
+
var pathText = (keys) => keys.join(".").replaceAll(".[", "[");
|
|
13364
|
+
var WORD2 = /[\w./:@=+,-]+/uy;
|
|
13365
|
+
var QUOTED = /"[^"$`\\]*"/uy;
|
|
13366
|
+
var COMMAND = /^[\w.+][\w./+-]*$/u;
|
|
13367
|
+
var SHELL_STATE = new Set(". alias bg bind break builtin call caller case cd command compgen complete compopt continue coproc declare dirs disown do done elif else enable esac eval exec exit export fc fg fi for function getopts goto hash help history if in jobs kill let local logout mapfile popd pushd read readarray readonly return select set shift shopt source suspend then time times trap type typeset ulimit umask unalias unset until wait while".split(" "));
|
|
13368
|
+
var FALLBACK = new Set(["echo", "true"]);
|
|
13369
|
+
var FORM = 'more than && <command> or && (<command> || echo "<text>")';
|
|
13370
|
+
var OUTSIDE = '(outside plain words and "double-quoted text")';
|
|
13371
|
+
var COMMAND_INPUT = /(?:^|[-_])(?:commands?|cmd|script)$/iu;
|
|
13372
|
+
function tokens2(text) {
|
|
13373
|
+
const out = [];
|
|
13374
|
+
let index = 0;
|
|
13375
|
+
while (index < text.length) {
|
|
13376
|
+
const char = text[index] ?? "";
|
|
13377
|
+
if (char === " " || char === "\t")
|
|
13378
|
+
index += 1;
|
|
13379
|
+
else if (char === "(" || char === ")") {
|
|
13380
|
+
out.push({ op: char });
|
|
13381
|
+
index += 1;
|
|
13382
|
+
} else if ((char === "&" || char === "|") && text[index + 1] === char) {
|
|
13383
|
+
out.push({ op: char + char });
|
|
13384
|
+
index += 2;
|
|
13385
|
+
} else {
|
|
13386
|
+
const pattern = char === '"' ? QUOTED : WORD2;
|
|
13387
|
+
pattern.lastIndex = index;
|
|
13388
|
+
const match = pattern.exec(text);
|
|
13389
|
+
if (!match)
|
|
13390
|
+
return char === '"' ? 'a "quoted text" left open or holding $, a backtick or a backslash' : `the character ${char} ${OUTSIDE}`;
|
|
13391
|
+
index += match[0].length;
|
|
13392
|
+
const next = text[index] ?? " ";
|
|
13393
|
+
if (!" \t)&|".includes(next))
|
|
13394
|
+
return `the character ${next} ${OUTSIDE}`;
|
|
13395
|
+
out.push(char === '"' ? { quoted: match[0] } : { word: match[0] });
|
|
13396
|
+
}
|
|
13397
|
+
}
|
|
13398
|
+
return out;
|
|
13399
|
+
}
|
|
13400
|
+
function masking(before, appended) {
|
|
13401
|
+
if (appended.includes("${{"))
|
|
13402
|
+
return "an expression";
|
|
13403
|
+
if (/[\n\r]/u.test(appended))
|
|
13404
|
+
return "a new line";
|
|
13405
|
+
if (!before.trim())
|
|
13406
|
+
return "a command where none ran before";
|
|
13407
|
+
if (before.endsWith("\\"))
|
|
13408
|
+
return "a command after a trailing backslash";
|
|
13409
|
+
if (!appended.trimStart().startsWith("&&"))
|
|
13410
|
+
return "a command not chained with a leading &&";
|
|
13411
|
+
const list = tokens2(appended);
|
|
13412
|
+
if (typeof list === "string")
|
|
13413
|
+
return list;
|
|
13414
|
+
let index = 0;
|
|
13415
|
+
const op = (text) => {
|
|
13416
|
+
const token = list[index];
|
|
13417
|
+
if (!token || !("op" in token) || token.op !== text)
|
|
13418
|
+
return false;
|
|
13419
|
+
index += 1;
|
|
13420
|
+
return true;
|
|
13421
|
+
};
|
|
13422
|
+
const command = (names) => {
|
|
13423
|
+
const name = list[index];
|
|
13424
|
+
if (!name || !("word" in name) || !COMMAND.test(name.word))
|
|
13425
|
+
return FORM;
|
|
13426
|
+
if (names ? !names.has(name.word) : SHELL_STATE.has(name.word.toLowerCase()))
|
|
13427
|
+
return names ? FORM : `the shell command ${name.word}`;
|
|
13428
|
+
index += 1;
|
|
13429
|
+
for (let token = list[index];token && !("op" in token); token = list[index])
|
|
13430
|
+
index += 1;
|
|
13431
|
+
return null;
|
|
13432
|
+
};
|
|
13433
|
+
while (index < list.length) {
|
|
13434
|
+
if (!op("&&"))
|
|
13435
|
+
return FORM;
|
|
13436
|
+
const group = op("(");
|
|
13437
|
+
const bad = command() ?? (group && op("||") ? command(FALLBACK) : null);
|
|
13438
|
+
if (bad)
|
|
13439
|
+
return bad;
|
|
13440
|
+
if (group && !op(")"))
|
|
13441
|
+
return FORM;
|
|
13442
|
+
}
|
|
13443
|
+
return null;
|
|
13444
|
+
}
|
|
13445
|
+
function compare(before, after, at, room, out) {
|
|
13446
|
+
if (before.kind === "scalar" && after.kind === "scalar") {
|
|
13447
|
+
if (before.text === after.text && before.string === after.string)
|
|
13448
|
+
return;
|
|
13449
|
+
const grown = room !== null && before.string && after.string && before.folded === after.folded && after.text.length > before.text.length && after.text.startsWith(before.text);
|
|
13450
|
+
const masks = grown ? masking(before.text, after.text.slice(before.text.length)) : null;
|
|
13451
|
+
if (masks)
|
|
13452
|
+
out.refused.push({ path: at, what: `appends ${masks} to ${pathText(at)}` });
|
|
13453
|
+
else if (grown)
|
|
13454
|
+
out.allowed.push(`${pathText(at)} appended`);
|
|
13455
|
+
else
|
|
13456
|
+
out.refused.push({ path: at, what: `changes ${pathText(at)}` });
|
|
13457
|
+
return;
|
|
13458
|
+
}
|
|
13459
|
+
if (before.kind === "seq" && after.kind === "seq") {
|
|
13460
|
+
if (before.items.length !== after.items.length) {
|
|
13461
|
+
const fewer = after.items.length < before.items.length;
|
|
13462
|
+
const noun = at.at(-1) === "steps" ? "a step" : "an item";
|
|
13463
|
+
out.refused.push({
|
|
13464
|
+
path: at,
|
|
13465
|
+
what: `${fewer ? "removes" : "adds"} ${noun} ${fewer ? "from" : "to"} ${pathText(at)}`
|
|
13466
|
+
});
|
|
13467
|
+
return;
|
|
13468
|
+
}
|
|
13469
|
+
before.items.forEach((item, index) => compare(item, after.items[index], [...at, `[${index}]`], null, out));
|
|
13470
|
+
return;
|
|
13471
|
+
}
|
|
13472
|
+
if (before.kind === "map" && after.kind === "map") {
|
|
13473
|
+
const step = at.at(-2) === "steps";
|
|
13474
|
+
const job = at.length === 2 && at[0] === "jobs";
|
|
13475
|
+
const usesBoth = before.entries.has("uses") && after.entries.has("uses");
|
|
13476
|
+
for (const [key, value] of before.entries) {
|
|
13477
|
+
const next = after.entries.get(key);
|
|
13478
|
+
if (!next) {
|
|
13479
|
+
out.refused.push({
|
|
13480
|
+
path: [...at, key],
|
|
13481
|
+
what: at.length === 1 && at[0] === "jobs" ? `removes the job ${key}` : `removes ${pathText([...at, key])}`
|
|
13482
|
+
});
|
|
13483
|
+
continue;
|
|
13484
|
+
}
|
|
13485
|
+
if (key === "with" && job && usesBoth && value.kind === "map" && next.kind === "map")
|
|
13486
|
+
compareInputs(value, next, [...at, key], out);
|
|
13487
|
+
else
|
|
13488
|
+
compare(value, next, [...at, key], key === "run" && step ? "run" : null, out);
|
|
13489
|
+
}
|
|
13490
|
+
for (const [key] of after.entries)
|
|
13491
|
+
if (!before.entries.has(key))
|
|
13492
|
+
out.refused.push({ path: [...at, key], what: `adds ${pathText([...at, key])}` });
|
|
13493
|
+
return;
|
|
13494
|
+
}
|
|
13495
|
+
out.refused.push({ path: at, what: `changes the shape of ${pathText(at) || "the file"}` });
|
|
13496
|
+
}
|
|
13497
|
+
function compareInputs(before, after, at, out) {
|
|
13498
|
+
for (const [key, value] of before.entries) {
|
|
13499
|
+
const next = after.entries.get(key);
|
|
13500
|
+
if (next)
|
|
13501
|
+
compare(value, next, [...at, key], COMMAND_INPUT.test(key) ? "with" : null, out);
|
|
13502
|
+
else
|
|
13503
|
+
out.refused.push({ path: [...at, key], what: `removes ${pathText([...at, key])}` });
|
|
13504
|
+
}
|
|
13505
|
+
for (const [key] of after.entries)
|
|
13506
|
+
if (!before.entries.has(key))
|
|
13507
|
+
out.refused.push({ path: [...at, key], what: `adds the input ${pathText([...at, key])}` });
|
|
13508
|
+
}
|
|
13509
|
+
function decisive(refused) {
|
|
13510
|
+
for (const change of refused) {
|
|
13511
|
+
const key = change.path.find((part) => GUARDED.has(part));
|
|
13512
|
+
if (key === "uses")
|
|
13513
|
+
return `moves a uses: ref (${pathText(change.path)})`;
|
|
13514
|
+
if (key)
|
|
13515
|
+
return `changes ${key}: (${pathText(change.path)})`;
|
|
13516
|
+
}
|
|
13517
|
+
return (refused.find((change) => change.what.startsWith("removes")) ?? refused[0])?.what ?? "changes it";
|
|
13518
|
+
}
|
|
13519
|
+
function workflowEdit(before, after) {
|
|
13520
|
+
const old = parseWorkflowYaml(before);
|
|
13521
|
+
const now = parseWorkflowYaml(after);
|
|
13522
|
+
if (!old || !now)
|
|
13523
|
+
return { additive: false, detail: "does not parse as plain workflow YAML" };
|
|
13524
|
+
const out = { allowed: [], refused: [] };
|
|
13525
|
+
compare(old, now, [], null, out);
|
|
13526
|
+
if (out.refused.length)
|
|
13527
|
+
return { additive: false, detail: decisive(out.refused) };
|
|
13528
|
+
if (!out.allowed.length)
|
|
13529
|
+
return { additive: false, detail: "changes only comments or layout, read as code" };
|
|
13530
|
+
return {
|
|
13531
|
+
additive: true,
|
|
13532
|
+
detail: out.allowed.slice(0, 3).join(", ") + (out.allowed.length > 3 ? ", …" : "")
|
|
13533
|
+
};
|
|
13534
|
+
}
|
|
13535
|
+
|
|
12862
13536
|
// packages/workit-core/src/core/policy/lane.ts
|
|
12863
13537
|
var LANE_THRESHOLDS = {
|
|
12864
13538
|
selfMaxLines: 100,
|
|
@@ -12919,15 +13593,16 @@ var DOC_EXT = /\.(?:md|mdx|markdown|rst|adoc)$/iu;
|
|
|
12919
13593
|
var DOC_NAMES = /^(?:license|licence|notice|authors|changelog|changes|contributors)$/iu;
|
|
12920
13594
|
var INSTRUCTIONS = /(?:^|\/)(?:AGENTS|CLAUDE|GEMINI|SKILL)\.md$|(?:^|\/)(?:skills|agents|commands|rules|prompts)\/[^/]+/iu;
|
|
12921
13595
|
var TEST_PATH = /(?:^|\/)(?:test|tests|__tests__)\/|\.(?:test|spec)\.[^/]+$|_test\.[^/]+$/iu;
|
|
13596
|
+
var DEPENDENCY_BUMP_EVIDENCE = "green CI on the head";
|
|
12922
13597
|
var plural = (count, noun) => `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
12923
|
-
var
|
|
12924
|
-
var isDoc = (file) => !INSTRUCTIONS.test(file) && (DOC_EXT.test(file) || DOC_NAMES.test(
|
|
13598
|
+
var basename2 = (file) => file.slice(file.lastIndexOf("/") + 1);
|
|
13599
|
+
var isDoc = (file) => !INSTRUCTIONS.test(file) && (DOC_EXT.test(file) || DOC_NAMES.test(basename2(file)));
|
|
12925
13600
|
function kindOf(file) {
|
|
12926
13601
|
if (file.binary)
|
|
12927
13602
|
return "behavior";
|
|
12928
13603
|
if (file.generated)
|
|
12929
13604
|
return "generated";
|
|
12930
|
-
if (LOCKFILES.has(
|
|
13605
|
+
if (LOCKFILES.has(basename2(file.path)))
|
|
12931
13606
|
return "lockfile";
|
|
12932
13607
|
if (isDoc(file.path))
|
|
12933
13608
|
return "doc";
|
|
@@ -12960,7 +13635,7 @@ function globMatch(pattern, file) {
|
|
|
12960
13635
|
function isRiskPath(file, extra = []) {
|
|
12961
13636
|
if (extra.some((pattern) => globMatch(pattern, file)))
|
|
12962
13637
|
return true;
|
|
12963
|
-
if (RISK_FILES.has(file) || RISK_NAMES.has(
|
|
13638
|
+
if (RISK_FILES.has(file) || RISK_NAMES.has(basename2(file)))
|
|
12964
13639
|
return true;
|
|
12965
13640
|
if (TEST_PATH.test(file) || isDoc(file))
|
|
12966
13641
|
return false;
|
|
@@ -12968,8 +13643,41 @@ function isRiskPath(file, extra = []) {
|
|
|
12968
13643
|
}
|
|
12969
13644
|
var parseRiskPaths = (text) => text.split(`
|
|
12970
13645
|
`).map((line) => line.trim()).filter((line) => line && !line.startsWith("#")).map((line) => line.replace(/^\//u, ""));
|
|
13646
|
+
function additiveWorkflow(file, extra) {
|
|
13647
|
+
if (file.workflow?.additive !== true || file.binary || !isWorkflowFile(file.path))
|
|
13648
|
+
return false;
|
|
13649
|
+
if (extra.some((pattern) => globMatch(pattern, file.path)))
|
|
13650
|
+
return false;
|
|
13651
|
+
return !isRiskPath(file.path.replace(/^\.github\/workflows\//u, ".github/"), extra);
|
|
13652
|
+
}
|
|
13653
|
+
var ADDITIVE_CI_FLOOR = "an additive workflow edit needs a non-author verdict unless it rides a dependency bump";
|
|
13654
|
+
var CHANGELOG = /^(?:changelog|changes)(?:\.[^.]+)?$/iu;
|
|
13655
|
+
function dependencyBump(files, additive) {
|
|
13656
|
+
const manifests = files.filter((file) => file.manifest?.pins && !file.binary);
|
|
13657
|
+
if (!manifests.some((file) => (file.manifest?.bumped ?? 0) > 0))
|
|
13658
|
+
return null;
|
|
13659
|
+
const locks = [];
|
|
13660
|
+
for (const file of files) {
|
|
13661
|
+
if (additive.has(file.path) || manifests.includes(file))
|
|
13662
|
+
continue;
|
|
13663
|
+
if (LOCKFILES.has(basename2(file.path)))
|
|
13664
|
+
locks.push(file.path);
|
|
13665
|
+
else if (file.binary || !(isDoc(file.path) && CHANGELOG.test(basename2(file.path))))
|
|
13666
|
+
return null;
|
|
13667
|
+
}
|
|
13668
|
+
const bumped = manifests.reduce((sum, file) => sum + (file.manifest?.bumped ?? 0), 0);
|
|
13669
|
+
const scripts = manifests.flatMap((file) => file.manifest?.scripts ?? []);
|
|
13670
|
+
const list = (paths) => `${paths.slice(0, 3).join(", ")}${paths.length > 3 ? ", …" : ""}`;
|
|
13671
|
+
return `dependency-bump: ${plural(bumped, "version pin")} in ${list(manifests.map((file) => file.path))}${scripts.length ? `, ${plural(scripts.length, "new script")} (${list(scripts)})` : ""}${locks.length ? `, lockfile ${list(locks)}` : ""}; ${DEPENDENCY_BUMP_EVIDENCE} is its evidence`;
|
|
13672
|
+
}
|
|
12971
13673
|
function computeLane(input) {
|
|
12972
|
-
const
|
|
13674
|
+
const extra = input.riskPaths ?? [];
|
|
13675
|
+
const additive = input.files.filter((file) => additiveWorkflow(file, extra));
|
|
13676
|
+
const relaxed = new Set(additive.map((file) => file.path));
|
|
13677
|
+
const workflowNote = additive.length ? [
|
|
13678
|
+
`additive workflow edit: ${additive.slice(0, 3).map((file) => `${file.path} (${file.workflow?.detail ?? ""})`).join(", ")}${additive.length > 3 ? ", …" : ""}`
|
|
13679
|
+
] : [];
|
|
13680
|
+
const riskFiles = input.files.filter((file) => isRiskPath(file.path, extra) && !relaxed.has(file.path)).map((file) => file.path);
|
|
12973
13681
|
const risky = new Set(riskFiles);
|
|
12974
13682
|
const kinds = input.files.map((file) => ({
|
|
12975
13683
|
file,
|
|
@@ -12980,20 +13688,30 @@ function computeLane(input) {
|
|
|
12980
13688
|
const opaque = behavior.filter((entry) => entry.kind === "lockfile" || entry.file.binary);
|
|
12981
13689
|
const diffLines = input.files.reduce((sum, file) => sum + file.added + file.deleted, 0);
|
|
12982
13690
|
const counted = diffLines === lines && input.files.length === behavior.length ? "" : ` counted (the whole diff is ${plural(diffLines, "line")} in ${plural(input.files.length, "file")}; docs, comments, formatting, generated copies and lockfile lines are not counted)`;
|
|
12983
|
-
const result = (lane, reasons) =>
|
|
12984
|
-
lane
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
|
|
12989
|
-
|
|
13691
|
+
const result = (lane, reasons, classification) => {
|
|
13692
|
+
const floor = additive.length > 0 && !classification && (lane === "none" || lane === "self");
|
|
13693
|
+
return {
|
|
13694
|
+
lane: floor ? "focused" : lane,
|
|
13695
|
+
reasons: [...floor ? [ADDITIVE_CI_FLOOR] : [], ...reasons, ...workflowNote],
|
|
13696
|
+
lines,
|
|
13697
|
+
files: behavior.length,
|
|
13698
|
+
riskFiles,
|
|
13699
|
+
...classification ? { classification } : {}
|
|
13700
|
+
};
|
|
13701
|
+
};
|
|
12990
13702
|
const { selfMaxLines, selfMaxFiles, fullMinLines } = LANE_THRESHOLDS;
|
|
12991
13703
|
if (input.riskTier === "high")
|
|
12992
13704
|
return result("full", ["the task judgment records high risk"]);
|
|
12993
13705
|
if (riskFiles.length)
|
|
12994
13706
|
return result("full", [
|
|
12995
|
-
`touches a risk path: ${riskFiles.slice(0, 3).
|
|
13707
|
+
`touches a risk path: ${riskFiles.slice(0, 3).map((file) => {
|
|
13708
|
+
const refused = input.files.find((entry) => entry.path === file)?.workflow;
|
|
13709
|
+
return refused && !refused.additive ? `${file} (${refused.detail})` : file;
|
|
13710
|
+
}).join(", ")}${riskFiles.length > 3 ? ", …" : ""}`
|
|
12996
13711
|
]);
|
|
13712
|
+
const bump = dependencyBump(input.files, relaxed);
|
|
13713
|
+
if (bump && lines < fullMinLines)
|
|
13714
|
+
return result("self", [bump], "dependency-bump");
|
|
12997
13715
|
if (!behavior.length)
|
|
12998
13716
|
return result("none", [
|
|
12999
13717
|
input.files.length ? "only docs, comments, formatting or generated copies changed" : "no changes"
|
|
@@ -13040,6 +13758,7 @@ function cosmeticFiles(cwd, fork, head) {
|
|
|
13040
13758
|
return null;
|
|
13041
13759
|
const out = new Set;
|
|
13042
13760
|
const opaque = new Set;
|
|
13761
|
+
const facts = new Map;
|
|
13043
13762
|
for (const entry of candidates) {
|
|
13044
13763
|
const before = blobs.get(entry.oldBlob);
|
|
13045
13764
|
let after = blobs.get(entry.newBlob);
|
|
@@ -13049,12 +13768,20 @@ function cosmeticFiles(cwd, fork, head) {
|
|
|
13049
13768
|
} catch {
|
|
13050
13769
|
after = undefined;
|
|
13051
13770
|
}
|
|
13771
|
+
if (before && after && isWorkflowFile(entry.path))
|
|
13772
|
+
facts.set(entry.path, {
|
|
13773
|
+
workflow: workflowEdit(before.toString("utf8"), after.toString("utf8"))
|
|
13774
|
+
});
|
|
13775
|
+
else if (before && after && isManifest(entry.path))
|
|
13776
|
+
facts.set(entry.path, {
|
|
13777
|
+
manifest: manifestEdit(entry.path, before.toString("utf8"), after.toString("utf8"))
|
|
13778
|
+
});
|
|
13052
13779
|
if (before && after && cosmeticChange(entry.path, before, after))
|
|
13053
13780
|
out.add(entry.path);
|
|
13054
13781
|
else if ([before, after].some((bytes) => bytes && hasOpaqueLineBreak(bytes.toString("utf8"))))
|
|
13055
13782
|
opaque.add(entry.path);
|
|
13056
13783
|
}
|
|
13057
|
-
return { cosmetic: out, opaque };
|
|
13784
|
+
return { cosmetic: out, opaque, facts };
|
|
13058
13785
|
}
|
|
13059
13786
|
function generatedAt(cwd, fork, paths) {
|
|
13060
13787
|
const files = treeFilesNamed(cwd, fork, ".gitattributes");
|
|
@@ -13079,7 +13806,8 @@ function laneFiles(cwd, fork, head, attributesAt = fork) {
|
|
|
13079
13806
|
...stats.map((entry) => ({
|
|
13080
13807
|
...entry,
|
|
13081
13808
|
...cosmetic.opaque.has(entry.path) ? { binary: true } : {},
|
|
13082
|
-
cosmetic: !entry.binary && cosmetic.cosmetic.has(entry.path)
|
|
13809
|
+
cosmetic: !entry.binary && cosmetic.cosmetic.has(entry.path),
|
|
13810
|
+
...cosmetic.facts.get(entry.path)
|
|
13083
13811
|
})),
|
|
13084
13812
|
...head === null ? untrackedFiles(cwd).map((file) => untrackedStat(cwd, file)) : []
|
|
13085
13813
|
];
|
|
@@ -13662,10 +14390,10 @@ function appendRaw(cwd, row, options) {
|
|
|
13662
14390
|
function appendHookObserved(cwd, row) {
|
|
13663
14391
|
return appendRaw(cwd, { ...row, observer: "host_hook" }, {});
|
|
13664
14392
|
}
|
|
13665
|
-
var
|
|
14393
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13666
14394
|
var str = (value) => typeof value === "string" ? value : null;
|
|
13667
14395
|
var normalizeActor = (value) => {
|
|
13668
|
-
const actor =
|
|
14396
|
+
const actor = isRecord3(value) ? value : {};
|
|
13669
14397
|
return {
|
|
13670
14398
|
host: str(actor.host) ?? "unknown",
|
|
13671
14399
|
session: str(actor.session),
|
|
@@ -13729,7 +14457,7 @@ function readLedgerAt(cwd, file, options) {
|
|
|
13729
14457
|
skipped += 1;
|
|
13730
14458
|
continue;
|
|
13731
14459
|
}
|
|
13732
|
-
if (!
|
|
14460
|
+
if (!isRecord3(parsed) || !str(parsed.id) || !str(parsed.type) || !str(parsed.at)) {
|
|
13733
14461
|
skipped += 1;
|
|
13734
14462
|
continue;
|
|
13735
14463
|
}
|
|
@@ -16088,14 +16816,14 @@ var SCOPE_FIELDS = new Set([
|
|
|
16088
16816
|
|
|
16089
16817
|
// packages/workit-core/src/core/release-packages.ts
|
|
16090
16818
|
var KNOWN_FIELDS2 = new Set(["tagNamespace", "changelogPath"]);
|
|
16091
|
-
var
|
|
16819
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16092
16820
|
var NAMESPACE = /^[A-Za-z@][\w.@/+-]*$/u;
|
|
16093
16821
|
var validTagNamespace = (value) => NAMESPACE.test(value) && !value.includes("..") && !value.includes("@{") && !value.includes("//") && !value.endsWith(".lock") && !/\d$/u.test(value);
|
|
16094
16822
|
function readReleasePackages(raw) {
|
|
16095
16823
|
const out = { packages: [], issues: [] };
|
|
16096
16824
|
if (raw === undefined || raw === null)
|
|
16097
16825
|
return out;
|
|
16098
|
-
if (!
|
|
16826
|
+
if (!isRecord4(raw)) {
|
|
16099
16827
|
out.issues.push("releasePackages is not an object; ignored");
|
|
16100
16828
|
return out;
|
|
16101
16829
|
}
|
|
@@ -16106,7 +16834,7 @@ function readReleasePackages(raw) {
|
|
|
16106
16834
|
out.issues.push(`${label}: a blank or padded name; ignored`);
|
|
16107
16835
|
continue;
|
|
16108
16836
|
}
|
|
16109
|
-
if (!
|
|
16837
|
+
if (!isRecord4(entry)) {
|
|
16110
16838
|
out.issues.push(`${label} is not an object; ignored`);
|
|
16111
16839
|
continue;
|
|
16112
16840
|
}
|
|
@@ -18805,7 +19533,7 @@ var readText3 = (file) => {
|
|
|
18805
19533
|
throw error;
|
|
18806
19534
|
}
|
|
18807
19535
|
};
|
|
18808
|
-
var
|
|
19536
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18809
19537
|
function parseJsonc(text) {
|
|
18810
19538
|
let out = "";
|
|
18811
19539
|
for (let index = 0;index < text.length; index += 1) {
|
|
@@ -18879,12 +19607,12 @@ function claudeRules(cwd, env = process.env) {
|
|
|
18879
19607
|
if (text === null)
|
|
18880
19608
|
continue;
|
|
18881
19609
|
const value = JSON.parse(text);
|
|
18882
|
-
if (!
|
|
19610
|
+
if (!isRecord5(value))
|
|
18883
19611
|
return "unreadable";
|
|
18884
19612
|
const permissions = value.permissions;
|
|
18885
19613
|
if (permissions === undefined)
|
|
18886
19614
|
continue;
|
|
18887
|
-
if (!
|
|
19615
|
+
if (!isRecord5(permissions))
|
|
18888
19616
|
return "unreadable";
|
|
18889
19617
|
for (const [key, bucket] of [
|
|
18890
19618
|
["deny", rules.deny],
|
|
@@ -18918,7 +19646,7 @@ var opencodePermission = (permission, rules) => {
|
|
|
18918
19646
|
(permission === "allow" ? rules.allow : rules.deny).push("");
|
|
18919
19647
|
return ["allow", "ask", "deny"].includes(permission);
|
|
18920
19648
|
}
|
|
18921
|
-
if (!
|
|
19649
|
+
if (!isRecord5(permission))
|
|
18922
19650
|
return false;
|
|
18923
19651
|
for (const key of ["bash", "shell"]) {
|
|
18924
19652
|
const value = permission[key];
|
|
@@ -18930,7 +19658,7 @@ var opencodePermission = (permission, rules) => {
|
|
|
18930
19658
|
(value === "allow" ? rules.allow : rules.deny).push("");
|
|
18931
19659
|
continue;
|
|
18932
19660
|
}
|
|
18933
|
-
if (!
|
|
19661
|
+
if (!isRecord5(value))
|
|
18934
19662
|
return false;
|
|
18935
19663
|
for (const [pattern, action] of Object.entries(value)) {
|
|
18936
19664
|
if (action !== "allow" && action !== "ask" && action !== "deny")
|
|
@@ -18948,7 +19676,7 @@ var opencodeRuleset = (ruleset, rules) => {
|
|
|
18948
19676
|
if (!Array.isArray(ruleset))
|
|
18949
19677
|
return false;
|
|
18950
19678
|
for (const rule of ruleset) {
|
|
18951
|
-
if (!
|
|
19679
|
+
if (!isRecord5(rule))
|
|
18952
19680
|
return false;
|
|
18953
19681
|
const { action, resource, effect } = rule;
|
|
18954
19682
|
if (typeof action !== "string" || typeof resource !== "string")
|
|
@@ -18963,11 +19691,11 @@ var opencodeRuleset = (ruleset, rules) => {
|
|
|
18963
19691
|
var opencodeAgents = (agents, read) => {
|
|
18964
19692
|
if (agents === undefined)
|
|
18965
19693
|
return true;
|
|
18966
|
-
if (!
|
|
19694
|
+
if (!isRecord5(agents))
|
|
18967
19695
|
return false;
|
|
18968
|
-
return Object.values(agents).every((agent) =>
|
|
19696
|
+
return Object.values(agents).every((agent) => isRecord5(agent) && read(agent));
|
|
18969
19697
|
};
|
|
18970
|
-
var opencodeConfig = (value, rules) =>
|
|
19698
|
+
var opencodeConfig = (value, rules) => isRecord5(value) && opencodeRuleset(value.permissions, rules) && opencodePermission(value.permission, rules) && opencodeAgents(value.agents, (agent) => opencodeRuleset(agent.permissions, rules)) && opencodeAgents(value.agent, (agent) => opencodePermission(agent.permission, rules));
|
|
18971
19699
|
function opencodeRules(cwd, env = process.env) {
|
|
18972
19700
|
const rules = EMPTY2();
|
|
18973
19701
|
try {
|
|
@@ -19056,11 +19784,11 @@ function cursorRules(cwd, env = process.env) {
|
|
|
19056
19784
|
if (text === null)
|
|
19057
19785
|
continue;
|
|
19058
19786
|
const value = JSON.parse(text);
|
|
19059
|
-
if (!
|
|
19787
|
+
if (!isRecord5(value))
|
|
19060
19788
|
return "unreadable";
|
|
19061
19789
|
if (value.permissions === undefined)
|
|
19062
19790
|
continue;
|
|
19063
|
-
if (!
|
|
19791
|
+
if (!isRecord5(value.permissions))
|
|
19064
19792
|
return "unreadable";
|
|
19065
19793
|
for (const [key, bucket] of [
|
|
19066
19794
|
["deny", rules.deny],
|
|
@@ -19485,11 +20213,11 @@ var readJson = (file) => {
|
|
|
19485
20213
|
return;
|
|
19486
20214
|
}
|
|
19487
20215
|
};
|
|
19488
|
-
var
|
|
20216
|
+
var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19489
20217
|
var stringList = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
19490
20218
|
function machinePatterns(env) {
|
|
19491
20219
|
const value = readJson(heavyCommandsFile(env));
|
|
19492
|
-
return
|
|
20220
|
+
return isRecord6(value) ? stringList(value.patterns) : [];
|
|
19493
20221
|
}
|
|
19494
20222
|
function repoPatterns(cwd) {
|
|
19495
20223
|
return repoHeavyCommands(gitTop(cwd) ?? path27.resolve(cwd));
|
|
@@ -21735,11 +22463,11 @@ var workitSkillOf = (name) => {
|
|
|
21735
22463
|
const skill = bare.replace(/^workit:/, "workit-");
|
|
21736
22464
|
return WORKIT_METHOD_SKILLS.includes(skill) ? skill : null;
|
|
21737
22465
|
};
|
|
21738
|
-
var
|
|
22466
|
+
var QUOTED2 = /```[\s\S]*?```|["`“][^"`”\n]*["`”]|\B'[^'\n]*'\B/g;
|
|
21739
22467
|
var COMPLAINT = /\b(why \w+ you|you keep|stop \w+ing)\b.*?(?=\b(and|but)\b|[?.,;\n]|$)/gi;
|
|
21740
22468
|
var promptTrigger = (prompt) => {
|
|
21741
22469
|
let asking = false;
|
|
21742
|
-
const text = prompt.slice(0, 4000).replace(
|
|
22470
|
+
const text = prompt.slice(0, 4000).replace(QUOTED2, " ").replace(COMPLAINT, (clause) => (asking ||= /ask|quest/i.test(clause), " "));
|
|
21743
22471
|
for (const [skill, pattern] of PROMPT_INTENTS) {
|
|
21744
22472
|
const match = !(asking && skill === "workit-shape") && pattern.exec(text);
|
|
21745
22473
|
if (match)
|
|
@@ -21861,7 +22589,7 @@ ${line}` };
|
|
|
21861
22589
|
// packages/workit-core/src/hooks/hosts/fields.ts
|
|
21862
22590
|
import { existsSync as existsSync13, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
|
|
21863
22591
|
import path31 from "node:path";
|
|
21864
|
-
var
|
|
22592
|
+
var isRecord7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
21865
22593
|
var nonEmpty2 = (value) => typeof value === "string" && value.trim() !== "";
|
|
21866
22594
|
var optionalText = (value) => typeof value === "string" ? value : null;
|
|
21867
22595
|
var existingDirectory = (value) => {
|
|
@@ -21918,7 +22646,7 @@ var isWriteTool = (name) => typeof name === "string" && WRITE_TOOLS.has(name.toL
|
|
|
21918
22646
|
var PATH_KEYS = ["file_path", "filePath", "notebook_path", "path", "target_file", "file"];
|
|
21919
22647
|
var PATCH_HEADER = /^[ \t]*\*\*\* (?:(?:Add|Update|Delete) File|Move to): (.+)$/gm;
|
|
21920
22648
|
var writePaths = (input) => {
|
|
21921
|
-
if (!
|
|
22649
|
+
if (!isRecord7(input))
|
|
21922
22650
|
return [];
|
|
21923
22651
|
const paths = PATH_KEYS.map((key) => input[key]).filter(nonEmpty2);
|
|
21924
22652
|
for (const value of Object.values(input))
|
|
@@ -22228,7 +22956,7 @@ var SHELL_TOOLS2 = new Set(["bash", "unified-exec"]);
|
|
|
22228
22956
|
var isShellTool = (name) => SHELL_TOOLS2.has(String(name).toLowerCase());
|
|
22229
22957
|
var SOURCES2 = new Set(["startup", "resume", "clear", "compact", "fork"]);
|
|
22230
22958
|
var parseCodexHookInput = (value) => {
|
|
22231
|
-
if (!
|
|
22959
|
+
if (!isRecord7(value) || !Object.hasOwn(EVENTS, String(value.hook_event_name)))
|
|
22232
22960
|
return { ok: false, error: "hook_event_name is required" };
|
|
22233
22961
|
const event = value.hook_event_name;
|
|
22234
22962
|
const cwd = existingDirectory(value.cwd);
|
|
@@ -22237,7 +22965,7 @@ var parseCodexHookInput = (value) => {
|
|
|
22237
22965
|
const toolEvent = event === "PreToolUse" || event === "PostToolUse";
|
|
22238
22966
|
if (toolEvent && !nonEmpty2(value.tool_name))
|
|
22239
22967
|
return { ok: false, error: "tool_name is required" };
|
|
22240
|
-
const command =
|
|
22968
|
+
const command = isRecord7(value.tool_input) ? commandText(value.tool_input.command) : null;
|
|
22241
22969
|
if (toolEvent && isShellTool(value.tool_name) && !command)
|
|
22242
22970
|
return { ok: false, error: "tool_input.command is required for shell tools" };
|
|
22243
22971
|
if (event === "SubagentStart" && !nonEmpty2(value.agent_id))
|
|
@@ -22352,7 +23080,7 @@ var codexAdapter = {
|
|
|
22352
23080
|
const host = detectCodexSurface(env);
|
|
22353
23081
|
const parsed = parseCodexHookInput(raw);
|
|
22354
23082
|
if (!parsed.ok) {
|
|
22355
|
-
const native =
|
|
23083
|
+
const native = isRecord7(raw) && Object.hasOwn(EVENTS, String(raw.hook_event_name)) ? raw.hook_event_name : null;
|
|
22356
23084
|
return { ok: false, error: parsed.error, native, event: native ? EVENTS[native] : null };
|
|
22357
23085
|
}
|
|
22358
23086
|
const input = parsed.data;
|