@kirill.konshin/lint 0.5.5 → 0.6.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.
Files changed (111) hide show
  1. package/README.md +38 -3
  2. package/commands/spec-author.md +39 -0
  3. package/dist/configs/base.d.ts +4 -3
  4. package/dist/configs/base.js +61 -74
  5. package/dist/configs/imports.d.ts +3 -2
  6. package/dist/configs/imports.js +95 -146
  7. package/dist/configs/nx.d.ts +4 -3
  8. package/dist/configs/nx.js +31 -41
  9. package/dist/configs/prettier.d.ts +3 -2
  10. package/dist/configs/prettier.js +19 -16
  11. package/dist/configs/promise.d.ts +3 -2
  12. package/dist/configs/promise.js +16 -16
  13. package/dist/configs/react.d.ts +4 -3
  14. package/dist/configs/react.js +178 -217
  15. package/dist/configs/storybook.d.ts +4 -3
  16. package/dist/configs/storybook.js +22 -22
  17. package/dist/configs/tailwind.d.ts +4 -3
  18. package/dist/configs/tailwind.js +67 -91
  19. package/dist/configs/testing.d.ts +7 -6
  20. package/dist/configs/testing.js +112 -146
  21. package/dist/configs/turbo.d.ts +4 -3
  22. package/dist/configs/turbo.js +19 -27
  23. package/dist/configs/typescriptTypeAware.d.ts +4 -3
  24. package/dist/configs/typescriptTypeAware.js +99 -95
  25. package/dist/configs/unicorn.d.ts +3 -2
  26. package/dist/configs/unicorn.js +34 -41
  27. package/dist/exts.d.ts +2 -1
  28. package/dist/exts.js +10 -11
  29. package/dist/index.d.ts +44 -42
  30. package/dist/index.js +53 -85
  31. package/dist/lib.d.ts +21 -21
  32. package/dist/lib.js +261 -301
  33. package/dist/lintPrepare.d.ts +20 -17
  34. package/dist/lintPrepare.js +341 -371
  35. package/dist/lintStaged.d.ts +4 -3
  36. package/dist/lintStaged.js +25 -22
  37. package/dist/prettier.d.ts +4 -3
  38. package/dist/prettier.js +16 -17
  39. package/dist/restrictions.d.ts +11 -10
  40. package/dist/restrictions.js +18 -22
  41. package/dist/yarn.cjs +79 -98
  42. package/dist/yarn.d.cts +3 -2
  43. package/package.json +24 -8
  44. package/rules/agent.md +2 -0
  45. package/rules/openspec.md +1 -1
  46. package/skills/spec-steward/SKILL.md +3 -11
  47. package/skills/spec-steward/references/audit.md +18 -43
  48. package/skills/spec-steward/references/contract.md +4 -4
  49. package/skills/spec-steward/references/criteria.md +4 -4
  50. package/skills/spec-steward/references/review-format.md +6 -6
  51. package/skills/spec-steward/references/wiring.md +2 -2
  52. package/skills/spec-steward/references/worker.md +67 -0
  53. package/skills/spec-steward/scripts/lib/corpus.mjs +1 -1
  54. package/skills/spec-steward/scripts/lib/evidence.mjs +2 -147
  55. package/skills/spec-steward/scripts/lib/wire.mjs +6 -4
  56. package/skills/spec-steward/scripts/steward.mjs +30 -91
  57. package/skills/spec-steward/sweeps.json +49 -0
  58. package/skills/spec-tools/SKILL.md +46 -0
  59. package/skills/spec-tools/references/contract.md +111 -0
  60. package/skills/spec-tools/references/gitlab.md +122 -0
  61. package/skills/spec-verify/SKILL.md +153 -0
  62. package/spec-tools/dist/audit-DkZZulq6.mjs +130 -0
  63. package/spec-tools/dist/auditChanged-CNGjlake.mjs +1 -0
  64. package/spec-tools/dist/auditChanged-CZCvMgyZ.mjs +618 -0
  65. package/spec-tools/dist/auditReport-xgq4wK2i.mjs +458 -0
  66. package/spec-tools/dist/auditScope-CBuBtfPG.mjs +104 -0
  67. package/spec-tools/dist/changeGates-DdeQKfle.mjs +333 -0
  68. package/spec-tools/dist/changeGates-uy4Ti8rK.mjs +1 -0
  69. package/spec-tools/dist/ci-BUewHJS3.mjs +143 -0
  70. package/spec-tools/dist/ci-CFBzn8Of.mjs +1 -0
  71. package/spec-tools/dist/cli.mjs +93 -0
  72. package/spec-tools/dist/comment-szasMMg2.mjs +57 -0
  73. package/spec-tools/dist/files-Bppsb34B.mjs +1 -0
  74. package/spec-tools/dist/files-QlzY687_.mjs +38 -0
  75. package/spec-tools/dist/html-BMTkpbUN.mjs +1766 -0
  76. package/spec-tools/dist/jsonrepair-Dlm5dEen.mjs +742 -0
  77. package/spec-tools/dist/repo-CjIoUPYl.mjs +16 -0
  78. package/spec-tools/dist/repo-DUcnJw3c.mjs +1 -0
  79. package/spec-tools/dist/run-BElA9du3.mjs +67 -0
  80. package/spec-tools/dist/specDiff-8G56jMYn.mjs +123 -0
  81. package/spec-tools/dist/steward-DeieyOcj.mjs +34 -0
  82. package/spec-tools/dist/stewardAudit-BRMM0lrD.mjs +1 -0
  83. package/spec-tools/dist/stewardAudit-v0vOMfLN.mjs +271 -0
  84. package/spec-tools/dist/tier-Cn0P7juM.mjs +1 -0
  85. package/spec-tools/dist/tier-c3s_mA_I.mjs +65 -0
  86. package/spec-tools/dist/util-wnxhsnWO.mjs +49 -0
  87. package/spec-tools/dist/verdict-BFfN9PO8.mjs +58 -0
  88. package/spec-tools/dist/workers-BcIgckeq.mjs +417 -0
  89. package/spec-tools/dist/workflowEvidence-DyBj8EdG.mjs +1 -0
  90. package/spec-tools/dist/workflowEvidence-oui6ghPI.mjs +78 -0
  91. package/dist/configs/base.d.ts.map +0 -1
  92. package/dist/configs/imports.d.ts.map +0 -1
  93. package/dist/configs/nx.d.ts.map +0 -1
  94. package/dist/configs/prettier.d.ts.map +0 -1
  95. package/dist/configs/promise.d.ts.map +0 -1
  96. package/dist/configs/react.d.ts.map +0 -1
  97. package/dist/configs/storybook.d.ts.map +0 -1
  98. package/dist/configs/tailwind.d.ts.map +0 -1
  99. package/dist/configs/testing.d.ts.map +0 -1
  100. package/dist/configs/turbo.d.ts.map +0 -1
  101. package/dist/configs/typescriptTypeAware.d.ts.map +0 -1
  102. package/dist/configs/unicorn.d.ts.map +0 -1
  103. package/dist/exts.d.ts.map +0 -1
  104. package/dist/index.d.ts.map +0 -1
  105. package/dist/lib.d.ts.map +0 -1
  106. package/dist/lintPrepare.d.ts.map +0 -1
  107. package/dist/lintStaged.d.ts.map +0 -1
  108. package/dist/prettier.d.ts.map +0 -1
  109. package/dist/restrictions.d.ts.map +0 -1
  110. package/dist/yarn.d.cts.map +0 -1
  111. package/skills/spec-steward/workflows/audit.js +0 -539
@@ -0,0 +1,333 @@
1
+ import { n as root, t as git } from "./repo-CjIoUPYl.mjs";
2
+ import { n as slugify } from "./util-wnxhsnWO.mjs";
3
+ import { n as gateBase } from "./ci-BUewHJS3.mjs";
4
+ import * as fs from "node:fs";
5
+ import * as path from "node:path";
6
+ //#region spec-tools/src/changeGates.ts
7
+ /**
8
+ * The change gates — the corpus checks spec-steward does not own, because they are about OpenSpec's change
9
+ * folders rather than the specifications: every archived change is well-formed, no `skip_specs` change carries a
10
+ * delta, and every delta a branch touches names standing requirements. `spec-tools gates` runs them after
11
+ * spec-steward's check; statements about repository state, never a unit test. Whether the branch's WORKFLOW is
12
+ * finished is `workflowEvidence`'s question, kept out of here so a change mid-workflow reads green.
13
+ *
14
+ * The module also holds the change and specification parsing the other commands share — `spec-diff`,
15
+ * `workflowEvidence` and the audit's affected set. Anchors are spec-steward's `slugify`, so a heading cited by a test
16
+ * and a heading the diff renders are the same slug.
17
+ */
18
+ /** Every capability specification in the working tree, with its requirement and scenario headings. */
19
+ function capabilitySpecs() {
20
+ const base = path.join(root(), "openspec/specs");
21
+ const walk = (dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
22
+ const full = path.join(dir, entry.name);
23
+ return entry.isDirectory() ? walk(full) : entry.name === "spec.md" ? [full] : [];
24
+ });
25
+ return walk(base).map((file) => {
26
+ const lines = fs.readFileSync(file, "utf8").split("\n");
27
+ const headingsAt = (depth, kind) => lines.flatMap((line, i) => {
28
+ const m = new RegExp(`^#{${depth}} (${kind}: .+)$`).exec(line);
29
+ return m ? [{
30
+ heading: m[1],
31
+ name: m[1].slice(kind.length + 2),
32
+ line: i + 1,
33
+ slug: slugify(m[1])
34
+ }] : [];
35
+ });
36
+ const requirements = headingsAt(3, "Requirement");
37
+ const scenarios = headingsAt(4, "Scenario");
38
+ return {
39
+ capability: path.relative(base, path.dirname(file)),
40
+ file: path.relative(root(), file),
41
+ requirements,
42
+ scenarios
43
+ };
44
+ });
45
+ }
46
+ /**
47
+ * The requirement blocks of one specification text — heading to the line before the next requirement, trailing
48
+ * blank lines trimmed — so a block read at a git ref compares equal to the same block read from disk.
49
+ */
50
+ function requirementBlocks(file, text) {
51
+ const lines = text.split("\n");
52
+ const starts = lines.flatMap((line, i) => /^### Requirement: .+$/.test(line) ? [i] : []);
53
+ const capability = path.dirname(file).replace(/^openspec\/specs\//, "");
54
+ return starts.map((start, n) => {
55
+ const body = lines.slice(start, starts[n + 1] ?? lines.length);
56
+ while (body.length && body[body.length - 1].trim() === "") body.pop();
57
+ const heading = lines[start].slice(4);
58
+ return {
59
+ file,
60
+ capability,
61
+ name: heading.slice(13),
62
+ slug: slugify(heading),
63
+ line: start + 1,
64
+ block: body.join("\n")
65
+ };
66
+ });
67
+ }
68
+ /** A requirement block with its whitespace collapsed, so two spellings of the same text compare equal. */
69
+ const normalizeBlock = (text) => text.replace(/\s+/g, " ").trim();
70
+ /**
71
+ * The specification files git sees renamed between a ref and the working tree, base path to head path. A capability
72
+ * that moved is the same capability under a new path, so every comparison against a base reads it there.
73
+ */
74
+ function specMovesSince(ref, rootDir = root()) {
75
+ const moves = /* @__PURE__ */ new Map();
76
+ for (const line of git([
77
+ "diff",
78
+ "-M",
79
+ "--name-status",
80
+ ref,
81
+ "--",
82
+ "openspec/specs"
83
+ ], rootDir).split("\n")) {
84
+ const [kind, from, to] = line.split(" ");
85
+ if (kind?.startsWith("R") && from?.endsWith("/spec.md") && to) moves.set(from, to);
86
+ }
87
+ return moves;
88
+ }
89
+ /** The specification files at a git ref, each with its text there, addressed by its path in the working tree. */
90
+ function specsAt(ref, rootDir = root()) {
91
+ const moves = specMovesSince(ref, rootDir);
92
+ return git([
93
+ "ls-tree",
94
+ "-r",
95
+ "--name-only",
96
+ ref,
97
+ "--",
98
+ "openspec/specs"
99
+ ], rootDir).split("\n").filter((file) => file.endsWith("/spec.md")).map((file) => ({
100
+ file: moves.get(file) ?? file,
101
+ text: git(["show", `${ref}:${file}`], rootDir)
102
+ }));
103
+ }
104
+ /** Every requirement in the specifications as they stand at a git ref — the base `spec-diff` renders against. */
105
+ function requirementsAt(ref) {
106
+ return specsAt(ref).flatMap(({ file, text }) => requirementBlocks(file, text));
107
+ }
108
+ /**
109
+ * Archived changes that are not evidence the workflow ran. Read from the FILESYSTEM, not the git index: git cannot
110
+ * track an empty directory, so a change folder emptied on disk is invisible to every gate built on `git diff` —
111
+ * which is how two of them survived unnoticed for five days.
112
+ */
113
+ function malformedArchivedChanges(rootDir = root()) {
114
+ const base = path.join(rootDir, "openspec/changes/archive");
115
+ if (!fs.existsSync(base)) return [];
116
+ return fs.readdirSync(base, { withFileTypes: true }).filter((entry) => entry.isDirectory()).flatMap((entry) => {
117
+ const dir = path.join(base, entry.name);
118
+ const missing = [".openspec.yaml", "proposal.md"].filter((file) => !fs.existsSync(path.join(dir, file)));
119
+ if (missing.length) return [`${entry.name} — missing ${missing.join(" and ")}`];
120
+ const specs = path.join(dir, "specs");
121
+ if (fs.existsSync(specs)) {
122
+ const walk = (current) => fs.readdirSync(current, { withFileTypes: true }).flatMap((child) => {
123
+ const full = path.join(current, child.name);
124
+ return child.isDirectory() ? walk(full) : child.name.endsWith(".md") ? [full] : [];
125
+ });
126
+ if (walk(specs).length === 0) return [`${entry.name} — carries a specs/ tree with no delta file`];
127
+ }
128
+ return [];
129
+ });
130
+ }
131
+ /**
132
+ * Unarchived changes whose deltas are already live in the standing specs — synced but not archived. A MODIFIED
133
+ * header is always present in main (it modifies an existing requirement), so only ADDED and REMOVED are decidable
134
+ * by heading: an ADDED requirement found in main, or a REMOVED one gone from it, means the sync ran. That state is
135
+ * legitimate on a branch (sync, push, watch CI go green) and unfinished on a merge request, which is why
136
+ * `workflowEvidence` — the merge-request gate — reads it and the change gates do not.
137
+ */
138
+ function syncedUnarchivedChanges(rootDir = root()) {
139
+ const changes = path.join(rootDir, "openspec/changes");
140
+ if (!fs.existsSync(changes)) return [];
141
+ const walk = (dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
142
+ const full = path.join(dir, entry.name);
143
+ return entry.isDirectory() ? walk(full) : entry.name === "spec.md" ? [full] : [];
144
+ });
145
+ const section = (text, op) => {
146
+ const start = text.indexOf(`## ${op} Requirements`);
147
+ if (start < 0) return "";
148
+ const rest = text.slice(start + 1);
149
+ const end = rest.search(/^## (ADDED|MODIFIED|REMOVED|RENAMED) Requirements/m);
150
+ return end < 0 ? rest : rest.slice(0, end);
151
+ };
152
+ const headers = (text) => [...text.matchAll(/^### Requirement: (.+)$/gm)].map((m) => m[1].trim());
153
+ /** A requirement's block by heading, whitespace-normalized, so a synced MODIFIED delta compares equal to main. */
154
+ const block = (text, h) => {
155
+ const start = text.indexOf(`### Requirement: ${h}`);
156
+ if (start < 0) return void 0;
157
+ const rest = text.slice(start);
158
+ const end = rest.search(/\n#{2,3} /);
159
+ return normalizeBlock(end < 0 ? rest : rest.slice(0, end));
160
+ };
161
+ return fs.readdirSync(changes, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "archive").flatMap((entry) => {
162
+ const specs = path.join(changes, entry.name, "specs");
163
+ if (!fs.existsSync(specs)) return [];
164
+ return walk(specs).flatMap((delta) => {
165
+ const capability = path.relative(specs, path.dirname(delta));
166
+ const main = path.join(rootDir, "openspec/specs", capability, "spec.md");
167
+ if (!fs.existsSync(main)) return [];
168
+ const text = fs.readFileSync(delta, "utf8");
169
+ const live = fs.readFileSync(main, "utf8");
170
+ const present = (h) => live.includes(`### Requirement: ${h}`);
171
+ return [
172
+ ...headers(section(text, "ADDED")).filter(present).map((h) => `${entry.name} — ADDED "${h}" is already in ${capability}`),
173
+ ...headers(section(text, "REMOVED")).filter((h) => !present(h)).map((h) => `${entry.name} — REMOVED "${h}" is already gone from ${capability}`),
174
+ ...headers(section(text, "MODIFIED")).filter((h) => present(h) && block(text, h) === block(live, h)).map((h) => `${entry.name} — MODIFIED "${h}" already reads as ${capability} does`)
175
+ ];
176
+ });
177
+ });
178
+ }
179
+ /** Every open change — a directory under `openspec/changes/` other than the archive. */
180
+ function openChanges(rootDir = root()) {
181
+ const changes = path.join(rootDir, "openspec/changes");
182
+ if (!fs.existsSync(changes)) return [];
183
+ return fs.readdirSync(changes, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "archive").map((entry) => entry.name).sort();
184
+ }
185
+ /**
186
+ * Open changes still carrying delta files. A change that takes the delta flow is finished inside its merge request —
187
+ * archived, its deltas folded — and never merges half-done: deltas left open drift from the standing specifications
188
+ * the longer they sit. Read from the filesystem so an unstaged delta counts too; a parked proposal is `skip_specs`
189
+ * and carries none.
190
+ */
191
+ function deltaFilesInOpenChanges(rootDir = root()) {
192
+ const changes = path.join(rootDir, "openspec/changes");
193
+ const walk = (dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
194
+ const full = path.join(dir, entry.name);
195
+ return entry.isDirectory() ? walk(full) : entry.name.endsWith(".md") ? [full] : [];
196
+ });
197
+ return openChanges(rootDir).flatMap((change) => {
198
+ const specs = path.join(changes, change, "specs");
199
+ if (!fs.existsSync(specs)) return [];
200
+ const deltas = walk(specs).map((f) => path.relative(path.join(changes, change), f));
201
+ return deltas.length ? [`${change} — carries ${deltas.length} delta file(s): ${deltas.join(", ")}`] : [];
202
+ });
203
+ }
204
+ /**
205
+ * The open changes this tree touches against a base — files changed or untracked under their directories. On the
206
+ * default branch itself nothing is touched, which keeps a stale change failing its own pipeline and no one else's.
207
+ */
208
+ function touchedOpenChanges(base, rootDir = root()) {
209
+ const files = [...git([
210
+ "diff",
211
+ "--name-only",
212
+ base,
213
+ "--",
214
+ "openspec/changes"
215
+ ], rootDir).split("\n"), ...git([
216
+ "ls-files",
217
+ "--others",
218
+ "--exclude-standard",
219
+ "--",
220
+ "openspec/changes"
221
+ ], rootDir).split("\n")];
222
+ const names = /* @__PURE__ */ new Set();
223
+ for (const file of files) {
224
+ const m = /^openspec\/changes\/([^/]+)\//.exec(file);
225
+ if (m && m[1] !== "archive") names.add(m[1]);
226
+ }
227
+ return [...names].filter((name) => fs.existsSync(path.join(rootDir, "openspec/changes", name))).sort();
228
+ }
229
+ /**
230
+ * Delta headings that name no standing requirement: a `MODIFIED` or `REMOVED` heading, or a `RENAMED` FROM, that the
231
+ * standing specification does not carry — the change was written against a requirement another change has since
232
+ * renamed or removed, and OpenSpec's own validation lets it through. Judged over the changes named only: a synced
233
+ * change's REMOVED and RENAMED headings are legitimately gone, so callers leave synced changes out.
234
+ */
235
+ function staleDeltaTargets(changes, rootDir = root()) {
236
+ const walk = (dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
237
+ const full = path.join(dir, entry.name);
238
+ return entry.isDirectory() ? walk(full) : entry.name === "spec.md" ? [full] : [];
239
+ });
240
+ const hits = [];
241
+ for (const change of changes) {
242
+ const specs = path.join(rootDir, "openspec/changes", change, "specs");
243
+ if (!fs.existsSync(specs)) continue;
244
+ for (const delta of walk(specs)) {
245
+ const capability = path.relative(specs, path.dirname(delta));
246
+ const standing = path.join(rootDir, "openspec/specs", capability, "spec.md");
247
+ const headings = new Set(fs.existsSync(standing) ? [...fs.readFileSync(standing, "utf8").matchAll(/^### Requirement: (.+)$/gm)].map((m) => m[1].trim()) : []);
248
+ let section = "";
249
+ for (const line of fs.readFileSync(delta, "utf8").split("\n")) {
250
+ const s = /^## (ADDED|MODIFIED|REMOVED|RENAMED) Requirements/.exec(line);
251
+ if (s) {
252
+ section = s[1];
253
+ continue;
254
+ }
255
+ let name;
256
+ if (section === "MODIFIED" || section === "REMOVED") name = /^### Requirement: (.+)$/.exec(line)?.[1]?.trim();
257
+ else if (section === "RENAMED") name = /^- FROM: `### Requirement: (.+)`\s*$/.exec(line)?.[1]?.trim();
258
+ if (name !== void 0 && !headings.has(name)) hits.push(`${change}: ${capability} ${section}${section === "RENAMED" ? " FROM" : ""} "${name}" names no standing requirement`);
259
+ }
260
+ }
261
+ }
262
+ return hits;
263
+ }
264
+ /**
265
+ * A change that declares `skip_specs: true` while carrying delta files. `skip_specs` tells archive to skip the spec
266
+ * merge; on a change that HAS deltas that is silent data loss — the folder moves to the archive and the standing
267
+ * specs never receive them. OpenSpec has no guard for it, so it is one here, read from the filesystem so an unstaged
268
+ * delta counts too. It guards after sync as much as at archive: a change that carries deltas never sets `skip_specs`,
269
+ * whatever state its workflow is in.
270
+ */
271
+ function skipSpecsWithDeltas(rootDir = root()) {
272
+ const changes = path.join(rootDir, "openspec/changes");
273
+ if (!fs.existsSync(changes)) return [];
274
+ const walk = (dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
275
+ const full = path.join(dir, entry.name);
276
+ return entry.isDirectory() ? walk(full) : entry.name.endsWith(".md") ? [full] : [];
277
+ });
278
+ const dirs = (dir) => fs.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory());
279
+ return dirs(changes).flatMap((e) => e.name === "archive" ? dirs(path.join(changes, "archive")).map((a) => path.join(changes, "archive", a.name)) : [path.join(changes, e.name)]).flatMap((dir) => {
280
+ const cfg = path.join(dir, ".openspec.yaml");
281
+ if (!fs.existsSync(cfg) || !/^\s*skip_specs:\s*true/m.test(fs.readFileSync(cfg, "utf8"))) return [];
282
+ const specs = path.join(dir, "specs");
283
+ if (!fs.existsSync(specs) || walk(specs).length === 0) return [];
284
+ return [`${path.relative(changes, dir)} sets skip_specs: true but carries delta files — archive would discard them`];
285
+ });
286
+ }
287
+ /** The change gates over this tree, and the warnings that fail nothing. */
288
+ function main(env = process.env) {
289
+ const synced = new Set(syncedUnarchivedChanges().map((s) => s.split(" — ")[0]));
290
+ const touched = (() => {
291
+ try {
292
+ const base = gateBase(env);
293
+ return base === null ? [] : touchedOpenChanges(base).filter((change) => !synced.has(change));
294
+ } catch (error) {
295
+ return `no base to judge the touched changes against: ${error.message.split("\n")[0]}`;
296
+ }
297
+ })();
298
+ const gates = [
299
+ {
300
+ name: "every archived change carries its schema marker, its proposal, and any delta it claims",
301
+ run: malformedArchivedChanges
302
+ },
303
+ {
304
+ name: "no change sets skip_specs while carrying delta files",
305
+ run: skipSpecsWithDeltas,
306
+ hint: "remove skip_specs, or delete the deltas if the change really specifies nothing"
307
+ },
308
+ {
309
+ name: "every delta this branch touches names standing requirements (MODIFIED, REMOVED, RENAMED FROM)",
310
+ run: () => typeof touched === "string" ? [touched] : staleDeltaTargets(touched),
311
+ hint: "another change renamed or removed the requirement — rebase the delta onto its successors; that change's design names them"
312
+ }
313
+ ];
314
+ let failed = 0;
315
+ for (const gate of gates) {
316
+ const violations = gate.run();
317
+ if (violations.length === 0) {
318
+ console.log(` ok ${gate.name}`);
319
+ continue;
320
+ }
321
+ failed += 1;
322
+ console.log(` FAIL ${gate.name}`);
323
+ for (const v of violations) console.log(` ${v}`);
324
+ if (gate.hint) console.log(` → ${gate.hint}`);
325
+ }
326
+ const untouched = typeof touched === "string" ? [] : staleDeltaTargets(openChanges().filter((change) => !synced.has(change) && !touched.includes(change)));
327
+ console.log(`\n WARN ${untouched.length} — stale deltas in untouched changes`);
328
+ for (const w of untouched) console.log(` ${w}`);
329
+ console.log(`\n${failed === 0 ? "PASS" : "FAIL"} — ${gates.length - failed}/${gates.length} change gates hold`);
330
+ return failed === 0 ? 0 : 1;
331
+ }
332
+ //#endregion
333
+ export { normalizeBlock as a, requirementsAt as c, staleDeltaTargets as d, syncedUnarchivedChanges as f, malformedArchivedChanges as i, skipSpecsWithDeltas as l, deltaFilesInOpenChanges as n, openChanges as o, touchedOpenChanges as p, main as r, requirementBlocks as s, capabilitySpecs as t, specMovesSince as u };
@@ -0,0 +1 @@
1
+ export { r as main } from "./changeGates-DdeQKfle.mjs";
@@ -0,0 +1,143 @@
1
+ import { n as root, t as git$1 } from "./repo-CjIoUPYl.mjs";
2
+ import { execFileSync } from "node:child_process";
3
+ //#region skills/spec-steward/scripts/lib/git.mjs
4
+ /** The few git reads steward needs; every one degrades to "nothing" outside a repository. */
5
+ /**
6
+ * @param {string} cwd
7
+ * @param {string[]} args
8
+ * @returns {string | null} stdout, or null when git fails
9
+ */
10
+ function git(cwd, args) {
11
+ try {
12
+ return execFileSync("git", args, {
13
+ cwd,
14
+ encoding: "utf8",
15
+ maxBuffer: 268435456,
16
+ stdio: [
17
+ "ignore",
18
+ "pipe",
19
+ "ignore"
20
+ ]
21
+ });
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+ /** The commit a ref names, or null when the repository has no such object. @param {string} root @param {string} ref */
27
+ const commitOf = (root, ref) => git(root, [
28
+ "rev-parse",
29
+ "--verify",
30
+ "--quiet",
31
+ `${ref}^{commit}`
32
+ ])?.trim() || null;
33
+ /** The merge base of `ref` and HEAD — what a branch is compared against — or `ref` itself when there is none. */
34
+ const mergeBase = (root, ref) => git(root, [
35
+ "merge-base",
36
+ ref,
37
+ "HEAD"
38
+ ])?.trim() || ref;
39
+ /**
40
+ * The base `--base` names (R-004): a merge request's diff base in CI, nothing in another CI pipeline, the merge base
41
+ * with `origin/HEAD` (or `origin/main`) locally; an explicit ref is compared through its merge base with HEAD.
42
+ * @param {string} root
43
+ * @param {string | true} given `auto`, a ref, or true when the flag had no value
44
+ * @param {Record<string, string | undefined>} env
45
+ * @returns {{ ref: string | null, how: string } | { error: string }}
46
+ */
47
+ function resolveBase(root, given, env = process.env) {
48
+ if (given !== "auto") {
49
+ if (given === true || !given) return { error: "--base needs a ref, or auto" };
50
+ if (!commitOf(root, given)) return { error: `base ref ${given} not found — git fetch origin` };
51
+ return {
52
+ ref: mergeBase(root, given),
53
+ how: `merge base of ${given}`
54
+ };
55
+ }
56
+ const sha = env.CI_MERGE_REQUEST_DIFF_BASE_SHA;
57
+ if (sha) {
58
+ if (!commitOf(root, sha)) return { error: `CI_MERGE_REQUEST_DIFF_BASE_SHA ${sha} is not in this clone` };
59
+ return {
60
+ ref: sha,
61
+ how: "the merge request diff base"
62
+ };
63
+ }
64
+ if (env.CI) return {
65
+ ref: null,
66
+ how: "none — a CI pipeline outside a merge request"
67
+ };
68
+ for (const upstream of ["origin/HEAD", "origin/main"]) {
69
+ if (!commitOf(root, upstream)) continue;
70
+ const ref = git(root, [
71
+ "merge-base",
72
+ upstream,
73
+ "HEAD"
74
+ ])?.trim();
75
+ if (ref) return {
76
+ ref,
77
+ how: `merge base of ${upstream}`
78
+ };
79
+ }
80
+ return { error: "no origin/HEAD or origin/main to compare against — git fetch origin" };
81
+ }
82
+ //#endregion
83
+ //#region spec-tools/src/ci.ts
84
+ /**
85
+ * Every pipeline variable the tools read, in one place: where a run's bases, its merge request and its shard come
86
+ * from. GitLab CI's variables today; another CI is one more branch here, never a read anywhere else. The gate base is
87
+ * spec-steward's own resolver, so the corpus gate and the change gates always judge against the same commit.
88
+ */
89
+ /**
90
+ * The base a branch's own changes are judged against: a merge request's diff base, which is already the merge base;
91
+ * none in any other pipeline — a default-branch push or the nightly has no branch of its own; locally, the merge base
92
+ * with the default branch.
93
+ */
94
+ function gateBase(env = process.env, rootDir = root()) {
95
+ const base = resolveBase(rootDir, "auto", env);
96
+ if ("error" in base) throw new Error(base.error);
97
+ return base.ref;
98
+ }
99
+ /**
100
+ * What a run diffs against: the merge request's diff base, the merge base with its target branch, a push's own
101
+ * before-commit (the previous tip, or the parent of a pushed branch's first commit), or `HEAD` — the working tree's own
102
+ * edits, which is what an author previews before handing back.
103
+ */
104
+ function diffBase(env = process.env) {
105
+ if (env.CI_MERGE_REQUEST_DIFF_BASE_SHA) return env.CI_MERGE_REQUEST_DIFF_BASE_SHA;
106
+ if (env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME) return git$1([
107
+ "merge-base",
108
+ `origin/${env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME}`,
109
+ "HEAD"
110
+ ]).trim();
111
+ if (env.CI_COMMIT_SHA) return /^0*$/.test(env.CI_COMMIT_BEFORE_SHA ?? "") ? "HEAD^" : env.CI_COMMIT_BEFORE_SHA;
112
+ return "HEAD";
113
+ }
114
+ /** The scheduled run that audits the whole corpus: the pipeline's `SPEC_AUDIT_NIGHTLY`. */
115
+ const isNightly = (env = process.env) => env.SPEC_AUDIT_NIGHTLY === "true";
116
+ /** The merge request this pipeline runs for, or null outside one. */
117
+ function mergeRequest(env = process.env) {
118
+ if (!env.CI_MERGE_REQUEST_IID && !env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME) return null;
119
+ return {
120
+ draft: env.CI_MERGE_REQUEST_DRAFT === "true",
121
+ target: env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME
122
+ };
123
+ }
124
+ /** Where a headless audit's streamed result is kept for the job log and the verdict gate: one file per job. */
125
+ const jobLog = (env = process.env) => `job-log-${env.CI_JOB_NAME ?? "local"}.md`;
126
+ /** What a merge-request comment links to: this job's artifacts and this pipeline, or nothing outside CI. */
127
+ function pipeline(env = process.env) {
128
+ return {
129
+ artifacts: env.CI_JOB_URL && `${env.CI_JOB_URL}/artifacts/file`,
130
+ id: env.CI_PIPELINE_IID,
131
+ url: env.CI_PIPELINE_URL
132
+ };
133
+ }
134
+ /** This job's share of a parallel audit: job `index` of `total`, both 1-based; one job outside a parallel matrix. */
135
+ function shard(env = process.env) {
136
+ const total = Number(env.CI_NODE_TOTAL ?? 1) || 1;
137
+ return {
138
+ index: Number(env.CI_NODE_INDEX ?? 1) || 1,
139
+ total
140
+ };
141
+ }
142
+ //#endregion
143
+ export { mergeRequest as a, jobLog as i, gateBase as n, pipeline as o, isNightly as r, shard as s, diffBase as t };
@@ -0,0 +1 @@
1
+ export { i as jobLog } from "./ci-BUewHJS3.mjs";
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+ //#region spec-tools/src/cli.ts
3
+ const [command, ...argv] = process.argv.slice(2);
4
+ /** The value after a flag, or undefined. */
5
+ const flag = (name) => {
6
+ const i = argv.indexOf(name);
7
+ return i >= 0 ? argv[i + 1] : void 0;
8
+ };
9
+ /** The audit `--audit` names; spec-verify when none is named. */
10
+ async function auditOf() {
11
+ const name = flag("--audit") ?? "spec-verify";
12
+ const { AUDIT_NAMES } = await import("./files-Bppsb34B.mjs");
13
+ if (!AUDIT_NAMES.includes(name)) throw new Error(`--audit ${name}: expected one of ${AUDIT_NAMES.join(", ")}`);
14
+ return name;
15
+ }
16
+ async function main() {
17
+ switch (command) {
18
+ case "gates": {
19
+ const { root } = await import("./repo-DUcnJw3c.mjs");
20
+ const checked = (await import("./steward-DeieyOcj.mjs")).steward([
21
+ "check",
22
+ "--base",
23
+ "auto"
24
+ ], root());
25
+ const gates = (await import("./changeGates-uy4Ti8rK.mjs")).main();
26
+ return Math.max(checked, gates);
27
+ }
28
+ case "evidence": return (await import("./workflowEvidence-DyBj8EdG.mjs")).cli(argv);
29
+ case "diff":
30
+ console.log((await import("./specDiff-8G56jMYn.mjs")).main(argv));
31
+ return 0;
32
+ case "changed": {
33
+ const { root } = await import("./repo-DUcnJw3c.mjs");
34
+ (await import("./steward-DeieyOcj.mjs")).writeEvidence(root());
35
+ process.stdout.write((await import("./auditChanged-CNGjlake.mjs")).main());
36
+ return 0;
37
+ }
38
+ case "tier": {
39
+ const { dotenv, tier } = await import("./tier-Cn0P7juM.mjs");
40
+ process.stdout.write(dotenv(tier()));
41
+ return 0;
42
+ }
43
+ case "scope": {
44
+ const { root } = await import("./repo-DUcnJw3c.mjs");
45
+ (await import("./steward-DeieyOcj.mjs")).writeEvidence(root());
46
+ process.stdout.write((await import("./auditScope-CBuBtfPG.mjs")).main(process.env, await auditOf()));
47
+ return 0;
48
+ }
49
+ case "workers": {
50
+ const pass = argv.includes("--verify") ? "verify" : argv.includes("--complete") ? "complete" : "read";
51
+ const file = flag("--context");
52
+ const context = file ? (await import("node:fs")).readFileSync(file, "utf8") : void 0;
53
+ return (await import("./workers-BcIgckeq.mjs")).workers(pass, {
54
+ audit: await auditOf(),
55
+ context
56
+ });
57
+ }
58
+ case "report": {
59
+ if (await auditOf() === "spec-verify") return (await import("./auditReport-xgq4wK2i.mjs")).cli(argv);
60
+ const { commitReader, worktreeReader } = await import("./auditReport-xgq4wK2i.mjs");
61
+ console.log((await import("./stewardAudit-BRMM0lrD.mjs")).merge(argv.includes("--worktree") ? worktreeReader : commitReader));
62
+ return 0;
63
+ }
64
+ case "audit": return (await import("./audit-DkZZulq6.mjs")).audit(argv, await auditOf());
65
+ case "run": {
66
+ const skill = argv[0];
67
+ if (!skill || skill.startsWith("-")) break;
68
+ const { jobLog } = await import("./ci-CFBzn8Of.mjs");
69
+ const log = jobLog();
70
+ const code = await (await import("./run-BElA9du3.mjs")).run(skill, log);
71
+ const report = flag("--verdict");
72
+ if (code !== 0 || !report) return code;
73
+ const advisory = argv.includes("--advisory") || process.env.AUDIT_GATING === "advisory";
74
+ return (await import("./verdict-BFfN9PO8.mjs")).gate(report, log, advisory);
75
+ }
76
+ case "verdict": {
77
+ const report = argv[0];
78
+ if (!report || report.startsWith("-")) break;
79
+ const { jobLog } = await import("./ci-CFBzn8Of.mjs");
80
+ const advisory = argv.includes("--advisory") || process.env.AUDIT_GATING === "advisory";
81
+ return (await import("./verdict-BFfN9PO8.mjs")).gate(report, flag("--log") ?? jobLog(), advisory);
82
+ }
83
+ case "comment":
84
+ process.stdout.write((await import("./comment-szasMMg2.mjs")).comment(argv));
85
+ return 0;
86
+ case "html": return (await import("./html-BMTkpbUN.mjs")).html(argv);
87
+ }
88
+ console.error(`spec-tools: unknown or incomplete command ${[command, ...argv].join(" ") || "(none)"}`);
89
+ return 2;
90
+ }
91
+ process.exitCode = await main();
92
+ //#endregion
93
+ export {};
@@ -0,0 +1,57 @@
1
+ import { o as pipeline } from "./ci-BUewHJS3.mjs";
2
+ import * as fs from "node:fs";
3
+ //#region spec-tools/src/comment.ts
4
+ /**
5
+ * `spec-tools comment <name>=<report.md>...`: the merge-request comment of a pipeline's AI reviews — one row per review
6
+ * with its verdict and counts, read from the fixed first line every report carries (`PASS|FAIL|INCOMPLETE (<n> errors,
7
+ * <m> warnings)`), linked to the reports in this job's artifacts, with the coverage report and the specification diff
8
+ * beneath when the pipeline produced them. Written to `mr-comment.md` and printed; posting it is the pipeline's.
9
+ */
10
+ const COMMENT_FILE = "mr-comment.md";
11
+ /** A report's verdict line: state and counts, or NOT RUN when the review produced no report. */
12
+ function verdictRow(text) {
13
+ if (text === void 0) return {
14
+ state: "NOT RUN",
15
+ errors: 0,
16
+ warnings: 0
17
+ };
18
+ const line = text.split("\n")[0] ?? "";
19
+ return {
20
+ state: /^([A-Z]+)/.exec(line)?.[1] ?? "UNKNOWN",
21
+ errors: Number(/\((\d+) errors?/.exec(line)?.[1] ?? 0),
22
+ warnings: Number(/(\d+) warnings?\)/.exec(line)?.[1] ?? 0)
23
+ };
24
+ }
25
+ const MARKS = {
26
+ PASS: "✅ OK",
27
+ INCOMPLETE: "❌ Incomplete",
28
+ FAIL: "❌ Failed"
29
+ };
30
+ const read = (file) => fs.existsSync(file) ? fs.readFileSync(file, "utf8") : void 0;
31
+ function comment(reviews, env = process.env) {
32
+ const { artifacts, id, url } = pipeline(env);
33
+ const link = (file) => artifacts ? `${artifacts}/${file}` : file;
34
+ const reports = (stem) => `[md](${link(`${stem}.md`)}) · [html](${link(`${stem}.html`)})`;
35
+ const out = [
36
+ "## AI review",
37
+ "",
38
+ "| Review | Verdict | Errors | Warnings | Report |",
39
+ "| --- | --- | --- | --- | --- |"
40
+ ];
41
+ for (const review of reviews) {
42
+ const [name, file = `${review}.md`] = review.split("=");
43
+ const v = verdictRow(read(file));
44
+ out.push(`| ${name} | ${MARKS[v.state] ?? `⚠️ ${v.state}`} | ${v.errors} | ${v.warnings} | ${reports(file.replace(/\.md$/, ""))} |`);
45
+ }
46
+ out.push("");
47
+ if (fs.existsSync("spec-coverage.md")) out.push(`Coverage: ${reports("spec-coverage")}`, "");
48
+ const diff = read("spec-diff.md");
49
+ if (diff !== void 0) out.push(`Specification diff — ${diff.split("\n")[0]}: ${reports("spec-diff")}`, "");
50
+ const gating = env.AUDIT_GATING || "gating";
51
+ out.push(`This was ${gating === "advisory" ? "an advisory" : "a gating"} run (${env.AUDIT_RUN || "unknown"}, scope ${env.AUDIT_SCOPE || "corpus"}, judged by ${env.AUDIT_MODEL_VERIFY || "unknown"}). ERROR findings fail a gating run and mark an advisory run failed without stopping the pipeline; an INCOMPLETE review — one that sampled or skipped a check — fails its job with exit code 3. WARN and INFO are published for triage.${id && url ? ` Pipeline [#${id}](${url}).` : ""}`);
52
+ const text = out.join("\n") + "\n";
53
+ fs.writeFileSync(COMMENT_FILE, text);
54
+ return text;
55
+ }
56
+ //#endregion
57
+ export { comment };
@@ -0,0 +1 @@
1
+ export { n as AUDIT_NAMES } from "./files-QlzY687_.mjs";
@@ -0,0 +1,38 @@
1
+ //#region spec-tools/src/files.ts
2
+ /**
3
+ * The files the audit passes hand to one another, at the repository root. Kept apart from the modules that write them so
4
+ * a pass that only reads them — the merge, the workers — never loads what the writers need (the TypeScript compiler).
5
+ */
6
+ /** The evidence each part's reader judges; the audits write their findings beneath it. */
7
+ const PARTS_DIR = "audit-parts";
8
+ /** Every unit in scope with its class, for the merge to grade a finding against an ⚠️ Advisory requirement. */
9
+ const UNITS_FILE = `${PARTS_DIR}/units.json`;
10
+ /** spec-steward's evidence model, which `spec-steward evidence --json` writes. */
11
+ const EVIDENCE_FILE = "spec-evidence.json";
12
+ const AUDIT_NAMES = ["spec-verify", "spec-steward"];
13
+ const AUDIT_FILES = {
14
+ "spec-verify": {
15
+ scope: "audit-scope.json",
16
+ findings: `${PARTS_DIR}/findings`,
17
+ data: "spec-verify.json",
18
+ report: "spec-verify.md",
19
+ verified: `${PARTS_DIR}/findings/.verified`
20
+ },
21
+ "spec-steward": {
22
+ scope: `${PARTS_DIR}/steward/scope.json`,
23
+ findings: `${PARTS_DIR}/steward/findings`,
24
+ data: `${PARTS_DIR}/steward/review.json`,
25
+ report: "spec-review.md",
26
+ verified: `${PARTS_DIR}/steward/findings/.verified`
27
+ }
28
+ };
29
+ const VERIFY = AUDIT_FILES["spec-verify"];
30
+ const SCOPE_JSON = VERIFY.scope;
31
+ const FINDINGS_DIR = VERIFY.findings;
32
+ const REPORT_FILE = VERIFY.report;
33
+ const REPORT_JSON = VERIFY.data;
34
+ const VERIFIED_MARKER = VERIFY.verified;
35
+ /** Where one reader of one part writes its findings. */
36
+ const findingsFile = (part, reader, audit = "spec-verify") => `${AUDIT_FILES[audit].findings}/part-${part}-${reader}.json`;
37
+ //#endregion
38
+ export { PARTS_DIR as a, SCOPE_JSON as c, findingsFile as d, FINDINGS_DIR as i, UNITS_FILE as l, AUDIT_NAMES as n, REPORT_FILE as o, EVIDENCE_FILE as r, REPORT_JSON as s, AUDIT_FILES as t, VERIFIED_MARKER as u };