@kyuki3rain/cupola 0.0.0-stage → 0.1.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 (116) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +202 -0
  3. package/README.md +40 -2
  4. package/dist/adr.js +106 -0
  5. package/dist/catalog.js +137 -0
  6. package/dist/check.js +192 -0
  7. package/dist/cli.js +8 -0
  8. package/dist/code.js +216 -0
  9. package/dist/commands/change.js +522 -0
  10. package/dist/commands/epic.js +311 -0
  11. package/dist/commands/install.js +109 -0
  12. package/dist/commands/locks.js +175 -0
  13. package/dist/commands/procedure.js +92 -0
  14. package/dist/commands/revision.js +139 -0
  15. package/dist/commands/run.js +1015 -0
  16. package/dist/commands/setup.js +382 -0
  17. package/dist/commands/spec.js +80 -0
  18. package/dist/commands/status.js +1158 -0
  19. package/dist/commands/trace.js +397 -0
  20. package/dist/commands/wait.js +102 -0
  21. package/dist/commands/work.js +121 -0
  22. package/dist/commands/workspace.js +126 -0
  23. package/dist/commands/worktree.js +422 -0
  24. package/dist/config.js +289 -0
  25. package/dist/day.js +29 -0
  26. package/dist/e2e-project.js +62 -0
  27. package/dist/e2e.js +207 -0
  28. package/dist/engine/cc-sdd.js +164 -0
  29. package/dist/epic.js +360 -0
  30. package/dist/feedback.js +34 -0
  31. package/dist/frontmatter.js +20 -0
  32. package/dist/git.js +365 -0
  33. package/dist/host/github.js +290 -0
  34. package/dist/host/host.js +1 -0
  35. package/dist/install.js +182 -0
  36. package/dist/io.js +46 -0
  37. package/dist/main.js +771 -0
  38. package/dist/method/v1.js +56 -0
  39. package/dist/procedure.js +60 -0
  40. package/dist/record.js +473 -0
  41. package/dist/release.js +84 -0
  42. package/dist/repo.js +13 -0
  43. package/dist/runbook.js +111 -0
  44. package/dist/safe-write.js +80 -0
  45. package/dist/spec.js +171 -0
  46. package/dist/status.js +190 -0
  47. package/dist/templates.js +49 -0
  48. package/dist/trace.js +275 -0
  49. package/dist/tracker/files.js +156 -0
  50. package/dist/tracker/github-issues.js +217 -0
  51. package/dist/tracker/index.js +27 -0
  52. package/dist/tracker/tracker.js +69 -0
  53. package/dist/tree.js +42 -0
  54. package/dist/trust.js +13 -0
  55. package/dist/version.js +5 -0
  56. package/dist/work.js +149 -0
  57. package/dist/workspace.js +299 -0
  58. package/npm-shrinkwrap.json +2014 -0
  59. package/package.json +41 -4
  60. package/skills/cupola-abort/SKILL.md +45 -0
  61. package/skills/cupola-adr/SKILL.md +41 -0
  62. package/skills/cupola-ask/SKILL.md +42 -0
  63. package/skills/cupola-catalog/SKILL.md +41 -0
  64. package/skills/cupola-catalog-draft/SKILL.md +114 -0
  65. package/skills/cupola-complete/SKILL.md +87 -0
  66. package/skills/cupola-decide/SKILL.md +60 -0
  67. package/skills/cupola-doc/SKILL.md +52 -0
  68. package/skills/cupola-e2e-setup/SKILL.md +78 -0
  69. package/skills/cupola-e2e-test/SKILL.md +115 -0
  70. package/skills/cupola-epic-accept/SKILL.md +162 -0
  71. package/skills/cupola-epic-create/SKILL.md +120 -0
  72. package/skills/cupola-epic-revise/SKILL.md +71 -0
  73. package/skills/cupola-epic-run/SKILL.md +127 -0
  74. package/skills/cupola-fix/SKILL.md +115 -0
  75. package/skills/cupola-init/SKILL.md +88 -0
  76. package/skills/cupola-intake/SKILL.md +78 -0
  77. package/skills/cupola-operate/SKILL.md +64 -0
  78. package/skills/cupola-resolve/SKILL.md +86 -0
  79. package/skills/cupola-review/SKILL.md +132 -0
  80. package/skills/cupola-spec-design/SKILL.md +164 -0
  81. package/skills/cupola-spec-impl/SKILL.md +135 -0
  82. package/skills/cupola-spec-run/SKILL.md +125 -0
  83. package/skills/cupola-steering/SKILL.md +46 -0
  84. package/templates/install/.kiro/steering/e2e.md +48 -0
  85. package/templates/install/.kiro/steering/operations.md +109 -0
  86. package/templates/install/.kiro/steering/principles.md +25 -0
  87. package/templates/install/CLAUDE.md +19 -0
  88. package/templates/install/adr/TEMPLATE.md +38 -0
  89. package/templates/install/cc-sdd/patches.json +31 -0
  90. package/templates/method-1/behavior-area.md +43 -0
  91. package/templates/method-1/behavior-index.md +16 -0
  92. package/templates/method-1/card.md +41 -0
  93. package/templates/method-1/case-draft.md +25 -0
  94. package/templates/method-1/case.md +38 -0
  95. package/templates/method-1/catalog-spec.md +33 -0
  96. package/templates/method-1/changes/adr.md +4 -0
  97. package/templates/method-1/changes/catalog.md +29 -0
  98. package/templates/method-1/changes/doc.md +5 -0
  99. package/templates/method-1/changes/e2e.md +7 -0
  100. package/templates/method-1/changes/epic.md +29 -0
  101. package/templates/method-1/changes/fix.md +21 -0
  102. package/templates/method-1/changes/release.md +23 -0
  103. package/templates/method-1/changes/spec.md +55 -0
  104. package/templates/method-1/changes/system.md +13 -0
  105. package/templates/method-1/cupola-issue-draft.md +17 -0
  106. package/templates/method-1/epic.md +136 -0
  107. package/templates/method-1/fix-spec.md +34 -0
  108. package/templates/method-1/fix.md +39 -0
  109. package/templates/method-1/lock.json +13 -0
  110. package/templates/method-1/phase-outcome.json +29 -0
  111. package/templates/method-1/record.json +63 -0
  112. package/templates/method-1/report.md +27 -0
  113. package/templates/method-1/runbook.md +39 -0
  114. package/templates/method-1/runner-result.json +6 -0
  115. package/templates/method-1/send-back.md +23 -0
  116. package/templates/methods.json +13 -0
@@ -0,0 +1,164 @@
1
+ import { execFile } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import { mkdtemp, readdir, readFile, rm } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join, relative } from "node:path";
6
+ import { promisify } from "node:util";
7
+ import { z } from "zod";
8
+ /**
9
+ * The cc-sdd spec engine: a dependency, not
10
+ * vendored. Cupola runs it at a pinned version into a temporary directory,
11
+ * takes its skills and settings, and applies its own declarative patches.
12
+ */
13
+ export const CC_SDD_VERSION = "3.1.0";
14
+ /**
15
+ * What cc-sdd writes at CC_SDD_VERSION in ENGINE_LANGUAGE, as `digest` computes it: a
16
+ * check that the package npx fetched is the one Cupola was built against.
17
+ */
18
+ export const CC_SDD_DIGEST = "sha256:3c39d72500e753fba922f39a4917f8283b526b892c6bb01772feaaa7d833ee23";
19
+ /** A digest of the files taken, by path and content. */
20
+ export function digest(files) {
21
+ const hash = createHash("sha256");
22
+ for (const f of [...files].sort((a, b) => (a.path < b.path ? -1 : 1))) {
23
+ hash.update(f.path).update("\0").update(f.content).update("\0");
24
+ }
25
+ return `sha256:${hash.digest("hex")}`;
26
+ }
27
+ /**
28
+ * The language the spec engine is installed and run in. Its files are read
29
+ * only by agents, so they are English whatever `language` is: `language` is
30
+ * the language of what humans read.
31
+ */
32
+ export const ENGINE_LANGUAGE = "en";
33
+ /** The languages cc-sdd's `--lang` accepts. */
34
+ export const CC_SDD_LANGUAGES = [
35
+ "ja",
36
+ "en",
37
+ "zh-TW",
38
+ "zh",
39
+ "es",
40
+ "pt",
41
+ "de",
42
+ "fr",
43
+ "ru",
44
+ "it",
45
+ "ko",
46
+ "ar",
47
+ "el",
48
+ "vi",
49
+ ];
50
+ /** Refuses a language cc-sdd cannot write, before anything is written. */
51
+ export function assertEngineLanguage(language) {
52
+ if (!CC_SDD_LANGUAGES.includes(language)) {
53
+ throw new Error(`cc-sdd has no language ${language}; \`language\` must be one of ${CC_SDD_LANGUAGES.join(", ")}`);
54
+ }
55
+ }
56
+ /** Which of cc-sdd's files a project takes: its skills and settings, never its CLAUDE.md. */
57
+ export function taken(path) {
58
+ return /^\.claude\/skills\/kiro-[^/]+\//.test(path) || path.startsWith(".kiro/settings/");
59
+ }
60
+ async function walk(dir, root) {
61
+ const out = [];
62
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
63
+ const full = join(dir, entry.name);
64
+ if (entry.isDirectory())
65
+ out.push(...(await walk(full, root)));
66
+ else if (entry.isFile())
67
+ out.push(relative(root, full).split("\\").join("/"));
68
+ }
69
+ return out;
70
+ }
71
+ /** Runs `npx cc-sdd@<pinned>` into a temporary directory and reads what it wrote. */
72
+ export const runCcSdd = async (language) => {
73
+ assertEngineLanguage(language);
74
+ const dir = await mkdtemp(join(tmpdir(), "cupola-cc-sdd-"));
75
+ try {
76
+ try {
77
+ await promisify(execFile)("npx", ["-y", `cc-sdd@${CC_SDD_VERSION}`, "--claude-skills", "--lang", language, "--yes"],
78
+ // npx is npx.cmd on Windows, which only a shell starts.
79
+ {
80
+ cwd: dir,
81
+ maxBuffer: 16 * 1024 * 1024,
82
+ timeout: 5 * 60_000,
83
+ shell: process.platform === "win32",
84
+ });
85
+ }
86
+ catch (error) {
87
+ const e = error;
88
+ if (e.code === "ENOENT") {
89
+ throw new Error("npx is not on PATH: installing cc-sdd needs Node.js with npm");
90
+ }
91
+ if (e.killed)
92
+ throw new Error(`cc-sdd ${CC_SDD_VERSION} did not finish within 5 minutes`);
93
+ throw new Error(`cc-sdd ${CC_SDD_VERSION} failed: ${(e.stderr ?? e.message).trim()}`);
94
+ }
95
+ const files = [];
96
+ for (const path of (await walk(dir, dir)).sort()) {
97
+ if (taken(path))
98
+ files.push({ path, content: await readFile(join(dir, path), "utf8") });
99
+ }
100
+ if (!files.some((f) => f.path === ".claude/skills/kiro-impl/SKILL.md")) {
101
+ throw new Error(`cc-sdd ${CC_SDD_VERSION} wrote no kiro-impl skill`);
102
+ }
103
+ if (language === ENGINE_LANGUAGE && digest(files) !== CC_SDD_DIGEST) {
104
+ throw new Error(`cc-sdd ${CC_SDD_VERSION} wrote other files than the ones Cupola was built against (${digest(files)}, expected ${CC_SDD_DIGEST}); nothing was installed`);
105
+ }
106
+ return files;
107
+ }
108
+ finally {
109
+ await rm(dir, { recursive: true, force: true });
110
+ }
111
+ };
112
+ const Patch = z.discriminatedUnion("kind", [
113
+ z.strictObject({
114
+ id: z.string(),
115
+ file: z.string(),
116
+ kind: z.literal("replace"),
117
+ from: z.string(),
118
+ to: z.string(),
119
+ }),
120
+ z.strictObject({
121
+ id: z.string(),
122
+ file: z.string(),
123
+ kind: z.literal("append"),
124
+ text: z.string(),
125
+ }),
126
+ z.strictObject({
127
+ id: z.string(),
128
+ file: z.string(),
129
+ kind: z.literal("insert-before"),
130
+ anchor: z.string(),
131
+ text: z.string(),
132
+ }),
133
+ ]);
134
+ export const Patches = z.strictObject({ patches: z.array(Patch) });
135
+ export class PatchError extends Error {
136
+ }
137
+ /** Applies one patch; a missing anchor stops the update and names the patch. */
138
+ export function applyPatch(content, patch) {
139
+ switch (patch.kind) {
140
+ case "replace":
141
+ if (!content.includes(patch.from)) {
142
+ throw new PatchError(`patch ${patch.id}: ${patch.file} no longer contains ${JSON.stringify(patch.from)}`);
143
+ }
144
+ // A function, so that `$` in the replacement is taken literally.
145
+ return content.replace(patch.from, () => patch.to);
146
+ case "append":
147
+ return `${content.trimEnd()}\n\n${patch.text.trimEnd()}\n`;
148
+ case "insert-before": {
149
+ const at = content.split("\n").findIndex((l) => l.trimEnd() === patch.anchor);
150
+ if (at < 0) {
151
+ throw new PatchError(`patch ${patch.id}: ${patch.file} has no line ${JSON.stringify(patch.anchor)}`);
152
+ }
153
+ const lines = content.split("\n");
154
+ lines.splice(at, 0, ...patch.text.trimEnd().split("\n"), "");
155
+ return lines.join("\n");
156
+ }
157
+ }
158
+ }
159
+ /** Where a spec's engine documents live (`cupola spec path`), with `/` separators. */
160
+ export function specPath(spec) {
161
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(spec))
162
+ throw new Error(`not a spec name: ${spec}`);
163
+ return `.kiro/specs/${spec}`;
164
+ }
package/dist/epic.js ADDED
@@ -0,0 +1,360 @@
1
+ import { z } from "zod";
2
+ import { parseFrontMatter } from "./frontmatter.js";
3
+ /**
4
+ * The epic: front matter, and ID-led entries read with the
5
+ * catalog's grammar. Headings are never parsed beyond their first token, and
6
+ * the composition is read from its line facts, not from its section.
7
+ */
8
+ export const PRECISE = "<!-- precise layer -->";
9
+ const KEBAB = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
10
+ /** Entry IDs of an epic, longest prefix first so that EA1 is not read as E…. */
11
+ const EPIC_ID = /^(EA|U|X|E|C|R)(\d+)$/;
12
+ export const EpicFront = z
13
+ .strictObject({
14
+ kind: z.literal("epic"),
15
+ method: z.number().int(),
16
+ id: z.string().regex(KEBAB, "a kebab-case name"),
17
+ title: z.string().min(1),
18
+ cases: z.array(z.string().regex(KEBAB, "case ids are kebab-case")).min(1),
19
+ compatibility: z.enum(["required", "not-required"]),
20
+ specs: z
21
+ .array(z.strictObject({
22
+ component: z.string().min(1),
23
+ after: z.array(z.string()).optional(),
24
+ }))
25
+ .default([]),
26
+ /** Procedures run after the specs are released, in this order. */
27
+ procedures: z
28
+ .array(z.strictObject({ runbook: z.string().regex(KEBAB, "runbook ids are kebab-case") }))
29
+ .default([]),
30
+ })
31
+ .refine((f) => f.specs.length + f.procedures.length > 0, {
32
+ message: "an epic needs specs, procedures, or both",
33
+ });
34
+ const FIELD = /^-\s+([a-z][a-z0-9-]*):\s*(.*)$/;
35
+ const COMPOSITION = /^-\s+(E\d+|C\d+\.a\d+)\s*<=\s*(.+)$/;
36
+ const PARTICIPANT = /^\s*(participant|actor)\s+(\S+)(?:\s+as\s+(.+?))?\s*$/;
37
+ const ARROW = /^\s*([^\s:+-][^:]*?)\s*(-{1,2}(?:>>|>|x|\)))[+-]?\s*([^:]+?)\s*:\s*(.*)$/;
38
+ /** A line without its HTML comments, and whether a comment is still open at its end. */
39
+ export function stripComments(line, open) {
40
+ let out = "";
41
+ let rest = line;
42
+ let comment = open;
43
+ while (rest !== "") {
44
+ if (comment) {
45
+ const end = rest.indexOf("-->");
46
+ if (end < 0)
47
+ return [out, true];
48
+ rest = rest.slice(end + 3);
49
+ comment = false;
50
+ }
51
+ else {
52
+ const start = rest.indexOf("<!--");
53
+ if (start < 0)
54
+ return [out + rest, false];
55
+ out += rest.slice(0, start);
56
+ rest = rest.slice(start + 4);
57
+ comment = true;
58
+ }
59
+ }
60
+ return [out, comment];
61
+ }
62
+ export function parseEpic(raw) {
63
+ const text = raw.replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n");
64
+ const { data, body } = parseFrontMatter(text);
65
+ const offset = text.slice(0, text.length - body.length).split("\n").length - 1;
66
+ const lines = body.split("\n");
67
+ const entries = [];
68
+ const composition = [];
69
+ const messages = [];
70
+ const placeholders = [];
71
+ let current;
72
+ let fence;
73
+ let mermaid;
74
+ let precise = false;
75
+ let comment = false;
76
+ lines.forEach((original, i) => {
77
+ let line = original;
78
+ const n = offset + i + 1;
79
+ if (!comment && !fence && line.trim() === PRECISE) {
80
+ precise = true;
81
+ return;
82
+ }
83
+ // Guidance comments are not part of the document, wherever they start and end.
84
+ if (!fence) {
85
+ const had = comment || line.includes("<!--");
86
+ [line, comment] = stripComments(line, comment);
87
+ if (had && line.trim() === "")
88
+ return;
89
+ }
90
+ if (line.includes("{{"))
91
+ placeholders.push(n);
92
+ const fenceMark = /^(```+|~~~+)\s*(\S*)/.exec(line.trim());
93
+ if (fence !== undefined || fenceMark) {
94
+ if (fence === undefined) {
95
+ fence = fenceMark?.[1];
96
+ mermaid = fenceMark?.[2] === "mermaid" ? new Map() : undefined;
97
+ }
98
+ else if (fenceMark?.[1]?.startsWith(fence) && !fenceMark[2]) {
99
+ fence = undefined;
100
+ mermaid = undefined;
101
+ }
102
+ else if (mermaid) {
103
+ const p = PARTICIPANT.exec(line);
104
+ if (p)
105
+ mermaid.set(p[2] ?? "", (p[3] ?? p[2] ?? "").trim());
106
+ const m = ARROW.exec(line);
107
+ if (m) {
108
+ const from = (m[1] ?? "").trim();
109
+ const to = (m[3] ?? "").trim();
110
+ messages.push({
111
+ from: mermaid.get(from) ?? from,
112
+ to: mermaid.get(to) ?? to,
113
+ fromId: from,
114
+ toId: to,
115
+ label: (m[4] ?? "").trim(),
116
+ line: n,
117
+ });
118
+ }
119
+ }
120
+ return;
121
+ }
122
+ const heading = /^#{1,6}\s+(\S+)\s*(.*)$/.exec(line);
123
+ if (heading) {
124
+ const id = heading[1] ?? "";
125
+ const kind = EPIC_ID.exec(id);
126
+ current = kind
127
+ ? { id, type: kind[1] ?? "", title: (heading[2] ?? "").trim(), line: n, fields: [] }
128
+ : undefined;
129
+ if (current)
130
+ entries.push(current);
131
+ return;
132
+ }
133
+ const comp = COMPOSITION.exec(line);
134
+ if (comp && !current) {
135
+ composition.push({
136
+ left: comp[1] ?? "",
137
+ right: (comp[2] ?? "")
138
+ .split(",")
139
+ .map((s) => s.trim())
140
+ .filter(Boolean),
141
+ line: n,
142
+ });
143
+ return;
144
+ }
145
+ const field = FIELD.exec(line);
146
+ if (field && current)
147
+ current.fields.push({ key: field[1] ?? "", value: (field[2] ?? "").trim(), line: n });
148
+ });
149
+ return { front: data, entries, composition, messages, precise, placeholders };
150
+ }
151
+ const field = (e, key) => e.fields.find((f) => f.key === key)?.value;
152
+ const list = (value) => (value ?? "")
153
+ .split(",")
154
+ .map((s) => s.trim())
155
+ .filter(Boolean);
156
+ const X_VERIFY = /^(acceptance [a-z0-9-]+|acceptance-check)$/;
157
+ const E_VERIFY = /^(acceptance [a-z0-9-]+|acceptance-check|spec-tests|e2e|procedure [a-z0-9-]+|none: .+)$/;
158
+ const CATALOG_ID = /^[a-z0-9-]+\.[a-z0-9-]+$/;
159
+ /**
160
+ * What `cupola check` lints in an epic: the deterministic part.
161
+ * The composition checker agent judges whether the contracts really imply the
162
+ * requirements. Whether every case criterion is covered needs the cases, which
163
+ * the skill reads from the tracker.
164
+ */
165
+ export function checkEpic(file, raw, components,
166
+ /** The runbooks in the hub, when known. */
167
+ runbooks) {
168
+ const problems = [];
169
+ const p = (message, line) => problems.push({ file, ...(line ? { line } : {}), message });
170
+ let epic;
171
+ try {
172
+ epic = parseEpic(raw);
173
+ }
174
+ catch (error) {
175
+ p(error.message);
176
+ return problems;
177
+ }
178
+ const front = EpicFront.safeParse(epic.front);
179
+ if (!front.success) {
180
+ for (const issue of front.error.issues)
181
+ p(`front matter ${issue.path.join(".") || "(root)"}: ${issue.message}`);
182
+ }
183
+ const fm = front.success ? front.data : undefined;
184
+ const name = file.split("/").at(-1)?.replace(/\.md$/, "");
185
+ if (fm && fm.id !== name)
186
+ p(`id is ${fm.id}, but the file is ${name}.md`);
187
+ const specComponents = fm?.specs.map((s) => s.component) ?? [];
188
+ const procedures = fm?.procedures.map((r) => r.runbook) ?? [];
189
+ procedures.forEach((r, i) => {
190
+ if (procedures.indexOf(r) !== i)
191
+ p(`procedures: ${r} is listed twice`);
192
+ if (runbooks && !runbooks.has(r))
193
+ p(`procedures: no runbook ${r}`);
194
+ });
195
+ for (const s of fm?.specs ?? []) {
196
+ if (!components.includes(s.component))
197
+ p(`specs: ${s.component} is not a configured component`);
198
+ for (const a of s.after ?? [])
199
+ if (!specComponents.includes(a))
200
+ p(`specs: ${s.component} waits for ${a}, which has no spec`);
201
+ }
202
+ // Designs that wait for each other would never start.
203
+ // A follow-up spec repeats its component: the waits of all its specs count.
204
+ const after = new Map();
205
+ for (const s of fm?.specs ?? []) {
206
+ after.set(s.component, [...(after.get(s.component) ?? []), ...(s.after ?? [])]);
207
+ }
208
+ const waits = (from, seen) => (after.get(from) ?? []).some((a) => seen.has(a) || waits(a, new Set([...seen, a])));
209
+ for (const c of new Set(specComponents))
210
+ if (waits(c, new Set([c])))
211
+ p(`specs: ${c} waits for itself through \`after\``);
212
+ const multi = new Set(specComponents).size > 1;
213
+ const verifiedIn = (id, v, line) => {
214
+ if (v.startsWith("acceptance ") && !specComponents.includes(v.slice(11)))
215
+ p(`${id}: ${v.slice(11)} has no spec in this epic`, line);
216
+ if (v.startsWith("procedure ") && !procedures.includes(v.slice(10)))
217
+ p(`${id}: ${v.slice(10)} is not one of the epic's procedures`, line);
218
+ if (v === "acceptance-check" && !multi)
219
+ p(`${id}: a one-component epic has no acceptance check; verify by \`acceptance <component>\``, line);
220
+ };
221
+ if (!epic.precise)
222
+ p("no `<!-- precise layer -->` marker");
223
+ for (const line of epic.placeholders)
224
+ p("template placeholder left ({{…}})", line);
225
+ const byId = new Map();
226
+ for (const e of epic.entries) {
227
+ if (byId.has(e.id))
228
+ p(`${e.id} is used twice; IDs are never reused`, e.line);
229
+ byId.set(e.id, e);
230
+ }
231
+ const live = epic.entries.filter((e) => field(e, "removed") === undefined);
232
+ const of = (type) => live.filter((e) => e.type === type);
233
+ const cases = new Set(fm?.cases ?? []);
234
+ for (const x of of("X")) {
235
+ const v = field(x, "verify");
236
+ if (!v)
237
+ p(`${x.id} has no verify`, x.line);
238
+ else if (!X_VERIFY.test(v))
239
+ p(`${x.id}: verify must be \`acceptance <component>\` or \`acceptance-check\``, x.line);
240
+ else
241
+ verifiedIn(x.id, v, x.line);
242
+ for (const k of ["given", "when", "then"])
243
+ if (!field(x, k))
244
+ p(`${x.id} has no ${k}`, x.line);
245
+ }
246
+ for (const e of of("E")) {
247
+ const v = field(e, "verify");
248
+ if (!v)
249
+ p(`${e.id} has no verify`, e.line);
250
+ else if (!E_VERIFY.test(v))
251
+ p(`${e.id}: verify must be acceptance <component>, acceptance-check, spec-tests, e2e, procedure <runbook>, or none: <what instead>`, e.line);
252
+ else
253
+ verifiedIn(e.id, v, e.line);
254
+ const examples = list(field(e, "examples"));
255
+ if (v && (v === "acceptance-check" || v.startsWith("acceptance ")) && examples.length === 0)
256
+ p(`${e.id} is verified by acceptance, which needs the examples it lists`, e.line);
257
+ const covers = list(field(e, "covers"));
258
+ if (covers.length === 0 && !field(e, "keeps"))
259
+ p(`${e.id} has neither covers nor keeps`, e.line);
260
+ for (const c of covers) {
261
+ const m = /^([a-z0-9-]+)#S\d+$/.exec(c);
262
+ if (!m)
263
+ p(`${e.id}: covers ${c} is not <case>#S<n>`, e.line);
264
+ else if (!cases.has(m[1] ?? ""))
265
+ p(`${e.id}: covers ${c}, but ${m[1]} is not in cases`, e.line);
266
+ }
267
+ for (const x of examples) {
268
+ const ex = byId.get(x);
269
+ if (ex?.type !== "X")
270
+ p(`${e.id}: example ${x} does not exist`, e.line);
271
+ else if (field(ex, "removed") !== undefined)
272
+ p(`${e.id}: example ${x} was removed`, e.line);
273
+ }
274
+ const keeps = field(e, "keeps");
275
+ for (const k of list(keeps))
276
+ if (!CATALOG_ID.test(k))
277
+ p(`${e.id}: keeps ${k} is not a catalog ID`, e.line);
278
+ }
279
+ // Only procedures: nothing is built, so nothing is verified by tests.
280
+ if (fm && specComponents.length === 0) {
281
+ for (const x of of("X"))
282
+ p(`${x.id}: an epic without specs has no examples; they are verified by a spec`, x.line);
283
+ for (const e of of("E")) {
284
+ const v = field(e, "verify") ?? "";
285
+ if (v && !v.startsWith("procedure ") && !v.startsWith("none: "))
286
+ p(`${e.id}: an epic without specs verifies by \`procedure <runbook>\` or \`none: …\``, e.line);
287
+ }
288
+ }
289
+ const contracts = of("C");
290
+ if (!multi && contracts.length > 0)
291
+ p("a one-component epic has no contracts: its requirements are its contract");
292
+ if (multi && contracts.length === 0)
293
+ p("an epic across components needs contracts (C#)");
294
+ /** Each contract line's ID, with where it is written. */
295
+ const lineAt = new Map();
296
+ const lines = { has: (id) => lineAt.has(id) };
297
+ for (const c of contracts) {
298
+ const component = c.title.split(/\s+/)[0] ?? "";
299
+ if (!specComponents.includes(component))
300
+ p(`${c.id}: ${component || "(no component)"} has no spec in this epic`, c.line);
301
+ if (!/^\d+$/.test(field(c, "rev") ?? ""))
302
+ p(`${c.id} has no rev (a number)`, c.line);
303
+ for (const f of c.fields) {
304
+ if (/^[ag]\d+$/.test(f.key)) {
305
+ const id = `${c.id}.${f.key}`;
306
+ if (lines.has(id))
307
+ p(`${id} is used twice`, f.line);
308
+ lineAt.set(id, f.line);
309
+ }
310
+ else if (!["rev", "removed"].includes(f.key))
311
+ p(`${c.id}: unknown key ${f.key}`, f.line);
312
+ }
313
+ }
314
+ const eas = new Set(of("EA").map((e) => e.id));
315
+ if (multi) {
316
+ const left = new Map();
317
+ for (const c of epic.composition)
318
+ left.set(c.left, (left.get(c.left) ?? 0) + 1);
319
+ for (const e of of("E")) {
320
+ const n = left.get(e.id) ?? 0;
321
+ if (n !== 1)
322
+ p(`${e.id} is on the left of ${n} composition lines; it must be on exactly one`, e.line);
323
+ }
324
+ for (const [id, at] of lineAt) {
325
+ if (!/\.a\d+$/.test(id))
326
+ continue;
327
+ const n = left.get(id) ?? 0;
328
+ if (n !== 1)
329
+ p(`${id} is on the left of ${n} composition lines; it must be on exactly one`, at);
330
+ }
331
+ for (const c of epic.composition) {
332
+ for (const r of c.right) {
333
+ const known = c.left.startsWith("E")
334
+ ? lines.has(r) && /\.g\d+$/.test(r)
335
+ : (lines.has(r) && /\.g\d+$/.test(r)) || eas.has(r) || CATALOG_ID.test(r);
336
+ if (!known)
337
+ p(`composition ${c.left}: ${r} is not a declared guarantee${c.left.startsWith("E") ? "" : ", EA#, or catalog ID"}`, c.line);
338
+ }
339
+ if (!byId.has(c.left.split(".")[0] ?? "") || (c.left.includes(".") && !lines.has(c.left)))
340
+ p(`composition: ${c.left} is not declared`, c.line);
341
+ }
342
+ const declared = new Set(contracts.map((c) => c.id));
343
+ for (const m of epic.messages) {
344
+ const side = (name, id) => specComponents.includes(name) ? name : specComponents.includes(id) ? id : undefined;
345
+ const from = side(m.from, m.fromId);
346
+ const to = side(m.to, m.toId);
347
+ if (!from || !to || from === to)
348
+ continue;
349
+ const cited = /^(C\d+)\b/.exec(m.label)?.[1];
350
+ if (!cited)
351
+ p(`message ${from} → ${to} cites no contract ("${m.label.slice(0, 40)}")`, m.line);
352
+ else if (!declared.has(cited))
353
+ p(`message ${from} → ${to} cites ${cited}, which is not declared`, m.line);
354
+ }
355
+ }
356
+ else if (epic.composition.length > 0) {
357
+ p("a one-component epic has no composition", epic.composition[0]?.line);
358
+ }
359
+ return problems;
360
+ }
@@ -0,0 +1,34 @@
1
+ import { trustedBy } from "./trust.js";
2
+ /**
3
+ * Feedback on a change, as the work reads it (the host's adapter says what
4
+ * it is on the host): whose remarks count, and when a person has sent the
5
+ * change back by leaving feedback on it.
6
+ */
7
+ /** Whether a remark's author is the reviewer asked for: a login, or `copilot` (a bot account). */
8
+ export function byReviewer(r, reviewer) {
9
+ return reviewer === "copilot"
10
+ ? r.bot && /copilot/i.test(r.author)
11
+ : r.author.toLowerCase() === reviewer.toLowerCase();
12
+ }
13
+ /**
14
+ * Whether what someone wrote may steer the work: the configured reviewer's, or
15
+ * that of someone the configuration trusts. Anyone else's is counted, never
16
+ * acted on.
17
+ */
18
+ export function trusted(r, reviewer, trust) {
19
+ return trustedBy(trust, r) || byReviewer(r, reviewer);
20
+ }
21
+ /**
22
+ * Open feedback a person left that Cupola has not answered yet: its latest
23
+ * remark that counts is by someone trusted other than the reviewer. On a
24
+ * change at its gate, this is the human sending it back.
25
+ */
26
+ export function fromPeople(items, reviewer, trust) {
27
+ const ok = (a) => trusted(a, reviewer, trust);
28
+ return items.filter((f) => {
29
+ if (!f.open || f.answered)
30
+ return false;
31
+ const last = [f, ...f.replies].filter(ok).at(-1);
32
+ return last !== undefined && !byReviewer(last, reviewer);
33
+ });
34
+ }
@@ -0,0 +1,20 @@
1
+ import { parse } from "yaml";
2
+ /** Splits a Markdown document into its YAML front matter and body; `file` names it in errors. */
3
+ export function parseFrontMatter(text, file) {
4
+ const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text);
5
+ if (!match)
6
+ return { data: {}, body: text };
7
+ const where = file ? `${file}: front matter` : "front matter";
8
+ let data;
9
+ try {
10
+ data = parse(match[1] ?? "") ?? {};
11
+ }
12
+ catch (error) {
13
+ // A value with a colon in it is the usual cause: quoting it fixes it.
14
+ throw new Error(`${where}: ${error.message.split("\n")[0]} (quote a value that holds ": ", and write \\" for a quote inside the quotes)`);
15
+ }
16
+ if (typeof data !== "object" || Array.isArray(data)) {
17
+ throw new Error(`${where} is not a mapping`);
18
+ }
19
+ return { data: data, body: text.slice(match[0].length) };
20
+ }