@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.
- package/CHANGELOG.md +26 -0
- package/LICENSE +202 -0
- package/README.md +40 -2
- package/dist/adr.js +106 -0
- package/dist/catalog.js +137 -0
- package/dist/check.js +192 -0
- package/dist/cli.js +8 -0
- package/dist/code.js +216 -0
- package/dist/commands/change.js +522 -0
- package/dist/commands/epic.js +311 -0
- package/dist/commands/install.js +109 -0
- package/dist/commands/locks.js +175 -0
- package/dist/commands/procedure.js +92 -0
- package/dist/commands/revision.js +139 -0
- package/dist/commands/run.js +1015 -0
- package/dist/commands/setup.js +382 -0
- package/dist/commands/spec.js +80 -0
- package/dist/commands/status.js +1158 -0
- package/dist/commands/trace.js +397 -0
- package/dist/commands/wait.js +102 -0
- package/dist/commands/work.js +121 -0
- package/dist/commands/workspace.js +126 -0
- package/dist/commands/worktree.js +422 -0
- package/dist/config.js +289 -0
- package/dist/day.js +29 -0
- package/dist/e2e-project.js +62 -0
- package/dist/e2e.js +207 -0
- package/dist/engine/cc-sdd.js +164 -0
- package/dist/epic.js +360 -0
- package/dist/feedback.js +34 -0
- package/dist/frontmatter.js +20 -0
- package/dist/git.js +365 -0
- package/dist/host/github.js +290 -0
- package/dist/host/host.js +1 -0
- package/dist/install.js +182 -0
- package/dist/io.js +46 -0
- package/dist/main.js +771 -0
- package/dist/method/v1.js +56 -0
- package/dist/procedure.js +60 -0
- package/dist/record.js +473 -0
- package/dist/release.js +84 -0
- package/dist/repo.js +13 -0
- package/dist/runbook.js +111 -0
- package/dist/safe-write.js +80 -0
- package/dist/spec.js +171 -0
- package/dist/status.js +190 -0
- package/dist/templates.js +49 -0
- package/dist/trace.js +275 -0
- package/dist/tracker/files.js +156 -0
- package/dist/tracker/github-issues.js +217 -0
- package/dist/tracker/index.js +27 -0
- package/dist/tracker/tracker.js +69 -0
- package/dist/tree.js +42 -0
- package/dist/trust.js +13 -0
- package/dist/version.js +5 -0
- package/dist/work.js +149 -0
- package/dist/workspace.js +299 -0
- package/npm-shrinkwrap.json +2014 -0
- package/package.json +41 -4
- package/skills/cupola-abort/SKILL.md +45 -0
- package/skills/cupola-adr/SKILL.md +41 -0
- package/skills/cupola-ask/SKILL.md +42 -0
- package/skills/cupola-catalog/SKILL.md +41 -0
- package/skills/cupola-catalog-draft/SKILL.md +114 -0
- package/skills/cupola-complete/SKILL.md +87 -0
- package/skills/cupola-decide/SKILL.md +60 -0
- package/skills/cupola-doc/SKILL.md +52 -0
- package/skills/cupola-e2e-setup/SKILL.md +78 -0
- package/skills/cupola-e2e-test/SKILL.md +115 -0
- package/skills/cupola-epic-accept/SKILL.md +162 -0
- package/skills/cupola-epic-create/SKILL.md +120 -0
- package/skills/cupola-epic-revise/SKILL.md +71 -0
- package/skills/cupola-epic-run/SKILL.md +127 -0
- package/skills/cupola-fix/SKILL.md +115 -0
- package/skills/cupola-init/SKILL.md +88 -0
- package/skills/cupola-intake/SKILL.md +78 -0
- package/skills/cupola-operate/SKILL.md +64 -0
- package/skills/cupola-resolve/SKILL.md +86 -0
- package/skills/cupola-review/SKILL.md +132 -0
- package/skills/cupola-spec-design/SKILL.md +164 -0
- package/skills/cupola-spec-impl/SKILL.md +135 -0
- package/skills/cupola-spec-run/SKILL.md +125 -0
- package/skills/cupola-steering/SKILL.md +46 -0
- package/templates/install/.kiro/steering/e2e.md +48 -0
- package/templates/install/.kiro/steering/operations.md +109 -0
- package/templates/install/.kiro/steering/principles.md +25 -0
- package/templates/install/CLAUDE.md +19 -0
- package/templates/install/adr/TEMPLATE.md +38 -0
- package/templates/install/cc-sdd/patches.json +31 -0
- package/templates/method-1/behavior-area.md +43 -0
- package/templates/method-1/behavior-index.md +16 -0
- package/templates/method-1/card.md +41 -0
- package/templates/method-1/case-draft.md +25 -0
- package/templates/method-1/case.md +38 -0
- package/templates/method-1/catalog-spec.md +33 -0
- package/templates/method-1/changes/adr.md +4 -0
- package/templates/method-1/changes/catalog.md +29 -0
- package/templates/method-1/changes/doc.md +5 -0
- package/templates/method-1/changes/e2e.md +7 -0
- package/templates/method-1/changes/epic.md +29 -0
- package/templates/method-1/changes/fix.md +21 -0
- package/templates/method-1/changes/release.md +23 -0
- package/templates/method-1/changes/spec.md +55 -0
- package/templates/method-1/changes/system.md +13 -0
- package/templates/method-1/cupola-issue-draft.md +17 -0
- package/templates/method-1/epic.md +136 -0
- package/templates/method-1/fix-spec.md +34 -0
- package/templates/method-1/fix.md +39 -0
- package/templates/method-1/lock.json +13 -0
- package/templates/method-1/phase-outcome.json +29 -0
- package/templates/method-1/record.json +63 -0
- package/templates/method-1/report.md +27 -0
- package/templates/method-1/runbook.md +39 -0
- package/templates/method-1/runner-result.json +6 -0
- package/templates/method-1/send-back.md +23 -0
- package/templates/methods.json +13 -0
package/dist/runbook.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PRECISE, stripComments } from "./epic.js";
|
|
3
|
+
import { parseFrontMatter } from "./frontmatter.js";
|
|
4
|
+
/**
|
|
5
|
+
* A runbook: the procedure an epic runs on the running system
|
|
6
|
+
* or outside the code, kept in the hub (`paths.runbooks`) so that later epics reuse
|
|
7
|
+
* it. Front matter, then steps `P#` with `- key: value` bullets.
|
|
8
|
+
*/
|
|
9
|
+
const KEBAB = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
10
|
+
const STEP = /^P\d+$/;
|
|
11
|
+
const KEYS = ["do", "check", "stop-if", "undo"];
|
|
12
|
+
export const RunbookFront = z.strictObject({
|
|
13
|
+
kind: z.literal("runbook"),
|
|
14
|
+
method: z.number().int(),
|
|
15
|
+
id: z.string().regex(KEBAB, "a kebab-case name"),
|
|
16
|
+
title: z.string().min(1),
|
|
17
|
+
"applies-to": z.array(z.string().min(1)).min(1),
|
|
18
|
+
});
|
|
19
|
+
const FIELD = /^-\s+([a-z][a-z0-9-]*):\s*(.*)$/;
|
|
20
|
+
export function parseRunbook(raw) {
|
|
21
|
+
const text = raw.replace(/^/, "").replace(/\r\n?/g, "\n");
|
|
22
|
+
const { data, body } = parseFrontMatter(text);
|
|
23
|
+
const offset = text.slice(0, text.length - body.length).split("\n").length - 1;
|
|
24
|
+
const steps = [];
|
|
25
|
+
const placeholders = [];
|
|
26
|
+
let current;
|
|
27
|
+
let precise = false;
|
|
28
|
+
let comment = false;
|
|
29
|
+
let fence = false;
|
|
30
|
+
body.split("\n").forEach((original, i) => {
|
|
31
|
+
const n = offset + i + 1;
|
|
32
|
+
if (!comment && !fence && original.trim() === PRECISE) {
|
|
33
|
+
precise = true;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (/^\s*(```|~~~)/.test(original)) {
|
|
37
|
+
fence = !fence;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (fence)
|
|
41
|
+
return;
|
|
42
|
+
const had = comment || original.includes("<!--");
|
|
43
|
+
let line;
|
|
44
|
+
[line, comment] = stripComments(original, comment);
|
|
45
|
+
if (had && line.trim() === "")
|
|
46
|
+
return;
|
|
47
|
+
if (line.includes("{{"))
|
|
48
|
+
placeholders.push(n);
|
|
49
|
+
const heading = /^#{1,6}\s+(\S+)\s*(.*)$/.exec(line);
|
|
50
|
+
if (heading) {
|
|
51
|
+
const id = heading[1] ?? "";
|
|
52
|
+
current =
|
|
53
|
+
precise && STEP.test(id)
|
|
54
|
+
? { id, title: (heading[2] ?? "").trim(), line: n, fields: [] }
|
|
55
|
+
: undefined;
|
|
56
|
+
if (current)
|
|
57
|
+
steps.push(current);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const field = FIELD.exec(line);
|
|
61
|
+
if (field && current)
|
|
62
|
+
current.fields.push({ key: field[1] ?? "", value: (field[2] ?? "").trim(), line: n });
|
|
63
|
+
});
|
|
64
|
+
return { front: data, steps, precise, placeholders };
|
|
65
|
+
}
|
|
66
|
+
/** Whether a step cannot be undone: the human's go is needed before it starts. */
|
|
67
|
+
export function irreversible(step) {
|
|
68
|
+
return step.fields.find((f) => f.key === "undo")?.value.toLowerCase() === "none";
|
|
69
|
+
}
|
|
70
|
+
/** What `cupola check` lints in a runbook. */
|
|
71
|
+
export function checkRunbook(file, raw, components) {
|
|
72
|
+
const problems = [];
|
|
73
|
+
const p = (message, line) => problems.push({ file, ...(line ? { line } : {}), message });
|
|
74
|
+
const book = parseRunbook(raw);
|
|
75
|
+
const front = RunbookFront.safeParse(book.front);
|
|
76
|
+
if (!front.success) {
|
|
77
|
+
for (const issue of front.error.issues)
|
|
78
|
+
p(`front matter ${issue.path.join(".") || "(root)"}: ${issue.message}`);
|
|
79
|
+
}
|
|
80
|
+
const name = file.split("/").at(-1)?.replace(/\.md$/, "");
|
|
81
|
+
if (front.success && front.data.id !== name)
|
|
82
|
+
p(`id is ${front.data.id}, but the file is ${name}.md`);
|
|
83
|
+
for (const c of front.success ? front.data["applies-to"] : [])
|
|
84
|
+
if (!components.includes(c))
|
|
85
|
+
p(`applies-to: ${c} is not a configured component`);
|
|
86
|
+
if (!book.precise)
|
|
87
|
+
p("no `<!-- precise layer -->` marker, so no step is read");
|
|
88
|
+
for (const line of book.placeholders)
|
|
89
|
+
p("template placeholder left ({{…}})", line);
|
|
90
|
+
if (book.precise && book.steps.length === 0)
|
|
91
|
+
p("no steps (### P1 …)");
|
|
92
|
+
const seen = new Set();
|
|
93
|
+
for (const s of book.steps) {
|
|
94
|
+
if (seen.has(s.id))
|
|
95
|
+
p(`${s.id} is used twice`, s.line);
|
|
96
|
+
seen.add(s.id);
|
|
97
|
+
if (s.title === "")
|
|
98
|
+
p(`${s.id} has no title`, s.line);
|
|
99
|
+
for (const f of s.fields)
|
|
100
|
+
if (!KEYS.includes(f.key))
|
|
101
|
+
p(`${s.id}: unknown key ${f.key}`, f.line);
|
|
102
|
+
const count = (key) => s.fields.filter((f) => f.key === key && f.value !== "").length;
|
|
103
|
+
if (count("do") === 0)
|
|
104
|
+
p(`${s.id} has no do`, s.line);
|
|
105
|
+
if (count("check") === 0)
|
|
106
|
+
p(`${s.id} has no check`, s.line);
|
|
107
|
+
if (count("undo") !== 1)
|
|
108
|
+
p(`${s.id} needs one undo: how to undo it, or none when it cannot be undone`, s.line);
|
|
109
|
+
}
|
|
110
|
+
return problems;
|
|
111
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { lstatSync, realpathSync } from "node:fs";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
|
+
/** A write that would leave the repository through a symbolic link, or a path outside it. */
|
|
5
|
+
export class OutsideRepositoryError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "OutsideRepositoryError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Checks that writing `path` (absolute, or relative to `root`) stays inside
|
|
13
|
+
* the repository at `root`: the target is not a symbolic link, and the real
|
|
14
|
+
* path of its nearest existing directory is under the repository's real path,
|
|
15
|
+
* so that no link committed to the repository leads the write elsewhere.
|
|
16
|
+
* Returns the absolute path.
|
|
17
|
+
*/
|
|
18
|
+
export function assertInsideRepository(root, path) {
|
|
19
|
+
const target = resolve(root, path);
|
|
20
|
+
let realRoot;
|
|
21
|
+
try {
|
|
22
|
+
realRoot = realpathSync(root);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new OutsideRepositoryError(`the repository at ${root} cannot be resolved (${error.code ?? "unknown"}); nothing was written`);
|
|
26
|
+
}
|
|
27
|
+
// Paths are compared as strings: on a case-insensitive file system, or with
|
|
28
|
+
// Windows short (8.3) names, a path inside may be spelled differently and be refused.
|
|
29
|
+
if (!within(resolve(root), target)) {
|
|
30
|
+
throw new OutsideRepositoryError(`${path} is outside the repository; nothing was written`);
|
|
31
|
+
}
|
|
32
|
+
let stat;
|
|
33
|
+
try {
|
|
34
|
+
stat = lstatSync(target);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
stat = undefined;
|
|
38
|
+
}
|
|
39
|
+
if (stat?.isSymbolicLink()) {
|
|
40
|
+
throw new OutsideRepositoryError(`${relative(root, target)} is a symbolic link; Cupola does not write through links`);
|
|
41
|
+
}
|
|
42
|
+
let dir = stat?.isDirectory() ? target : dirname(target);
|
|
43
|
+
for (;;) {
|
|
44
|
+
try {
|
|
45
|
+
lstatSync(dir);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
const up = dirname(dir);
|
|
50
|
+
if (up === dir)
|
|
51
|
+
break;
|
|
52
|
+
dir = up;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
let real;
|
|
56
|
+
try {
|
|
57
|
+
real = realpathSync(dir);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
real = "";
|
|
61
|
+
}
|
|
62
|
+
if (real === "" || !within(realRoot, real)) {
|
|
63
|
+
throw new OutsideRepositoryError(`${relative(root, target)} leads outside the repository through a symbolic link; nothing was written`);
|
|
64
|
+
}
|
|
65
|
+
return target;
|
|
66
|
+
}
|
|
67
|
+
/** Creates a directory inside the repository, with its parents, refusing to follow links out of it. */
|
|
68
|
+
export async function mkdirInside(root, path) {
|
|
69
|
+
await mkdir(assertInsideRepository(root, path), { recursive: true });
|
|
70
|
+
}
|
|
71
|
+
/** Writes a file inside the repository, creating its directory, refusing to follow links out of it. */
|
|
72
|
+
export async function writeInside(root, path, text) {
|
|
73
|
+
const target = assertInsideRepository(root, path);
|
|
74
|
+
await mkdir(dirname(target), { recursive: true });
|
|
75
|
+
await writeFile(target, text);
|
|
76
|
+
}
|
|
77
|
+
function within(dir, path) {
|
|
78
|
+
const rel = relative(dir, path);
|
|
79
|
+
return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
80
|
+
}
|
package/dist/spec.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { EpicFront, parseEpic } from "./epic.js";
|
|
3
|
+
import { METHOD } from "./method/v1.js";
|
|
4
|
+
/**
|
|
5
|
+
* A full-mode spec: the spec engine's documents under
|
|
6
|
+
* `.kiro/specs/<epic>-<component>/`, whose `spec.json` carries Cupola's
|
|
7
|
+
* namespaced block.
|
|
8
|
+
*/
|
|
9
|
+
export const CupolaBlock = z.strictObject({
|
|
10
|
+
method: z.int().positive(),
|
|
11
|
+
epic: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "must be a work id (kebab-case)"),
|
|
12
|
+
component: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "must be kebab-case"),
|
|
13
|
+
/** Each implemented contract, with the epic revision it implements. */
|
|
14
|
+
contracts: z.record(z.string().regex(/^C\d+$/), z.int().positive()),
|
|
15
|
+
/** The epic's revision this spec has taken in (the highest `R#`, 1 without one). */
|
|
16
|
+
revision: z.int().positive().optional(),
|
|
17
|
+
});
|
|
18
|
+
export class SpecError extends Error {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "SpecError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** The branch an epic with two or more specs integrates on. */
|
|
25
|
+
export function epicBranchName(epic) {
|
|
26
|
+
return `epic/${epic}`;
|
|
27
|
+
}
|
|
28
|
+
/** The spec's name: the epic's and its component's. */
|
|
29
|
+
export function specName(epic, component) {
|
|
30
|
+
return `${epic}-${component}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The names of an epic's specs, in the order of its `specs`: a
|
|
34
|
+
* follow-up spec of the same component, added by a revision, is `-2`, `-3`, ….
|
|
35
|
+
*/
|
|
36
|
+
export function specNamesOf(epic, specs) {
|
|
37
|
+
const seen = new Map();
|
|
38
|
+
return specs.map(({ component }) => {
|
|
39
|
+
const n = (seen.get(component) ?? 0) + 1;
|
|
40
|
+
seen.set(component, n);
|
|
41
|
+
return {
|
|
42
|
+
name: n === 1 ? specName(epic, component) : `${specName(epic, component)}-${n}`,
|
|
43
|
+
component,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function revisionsOf(epic) {
|
|
48
|
+
return epic.entries
|
|
49
|
+
.filter((e) => e.type === "R")
|
|
50
|
+
.map((e) => {
|
|
51
|
+
const plans = new Map();
|
|
52
|
+
let changed = [];
|
|
53
|
+
let from;
|
|
54
|
+
for (const f of e.fields) {
|
|
55
|
+
if (f.key === "changed")
|
|
56
|
+
changed = f.value.split(/[,\s]+/).filter(Boolean);
|
|
57
|
+
else if (f.key === "from")
|
|
58
|
+
from = /card\s+(\S+#\d+)/.exec(f.value)?.[1];
|
|
59
|
+
else if (f.key !== "removed")
|
|
60
|
+
plans.set(f.key, f.value.trim().split(/\s/)[0] ?? "");
|
|
61
|
+
}
|
|
62
|
+
return { n: Number(e.id.slice(1)), changed, from, plans };
|
|
63
|
+
})
|
|
64
|
+
.sort((a, b) => a.n - b.n);
|
|
65
|
+
}
|
|
66
|
+
/** The epic's revision: its highest `R#`, 1 without one. */
|
|
67
|
+
export function currentRevision(epic) {
|
|
68
|
+
return Math.max(1, ...revisionsOf(epic).map((r) => r.n));
|
|
69
|
+
}
|
|
70
|
+
/** The epic's front matter, or an error naming the file. */
|
|
71
|
+
export function epicFront(path, raw) {
|
|
72
|
+
const epic = parseEpic(raw);
|
|
73
|
+
const front = EpicFront.safeParse(epic.front);
|
|
74
|
+
if (!front.success) {
|
|
75
|
+
throw new SpecError(`${path}: its front matter is not an epic's (cupola check says why)`);
|
|
76
|
+
}
|
|
77
|
+
return { front: front.data, epic };
|
|
78
|
+
}
|
|
79
|
+
/** The contracts an epic gives a component, with their revisions. */
|
|
80
|
+
export function contractsOf(epic, component) {
|
|
81
|
+
const out = {};
|
|
82
|
+
for (const e of epic.entries) {
|
|
83
|
+
if (e.type !== "C")
|
|
84
|
+
continue;
|
|
85
|
+
const owner = e.title.split(/\s+[—–-]\s+/)[0]?.trim();
|
|
86
|
+
if (owner !== component)
|
|
87
|
+
continue;
|
|
88
|
+
const rev = Number(e.fields.find((f) => f.key === "rev")?.value);
|
|
89
|
+
out[e.id] = Number.isInteger(rev) && rev > 0 ? rev : 1;
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/** The block a new spec of `component` in `epic` starts with. */
|
|
94
|
+
export function newBlock(epicId, epic, component) {
|
|
95
|
+
return {
|
|
96
|
+
method: METHOD,
|
|
97
|
+
epic: epicId,
|
|
98
|
+
component,
|
|
99
|
+
contracts: contractsOf(epic, component),
|
|
100
|
+
revision: currentRevision(epic),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Reads the Cupola block of a spec.json; undefined for a plain cc-sdd spec. */
|
|
104
|
+
export function readBlock(path, raw) {
|
|
105
|
+
let json;
|
|
106
|
+
try {
|
|
107
|
+
json = JSON.parse(raw);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw new SpecError(`${path}: not valid JSON: ${error.message}`);
|
|
111
|
+
}
|
|
112
|
+
const block = json?.cupola;
|
|
113
|
+
if (block === undefined)
|
|
114
|
+
return undefined;
|
|
115
|
+
const parsed = CupolaBlock.safeParse(block);
|
|
116
|
+
if (!parsed.success) {
|
|
117
|
+
const why = parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
|
|
118
|
+
throw new SpecError(`${path}: its cupola block is invalid: ${why}`);
|
|
119
|
+
}
|
|
120
|
+
return parsed.data;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A new spec.json from the engine's `init.json`: the spec's name, the time,
|
|
124
|
+
* the language, and Cupola's block.
|
|
125
|
+
*/
|
|
126
|
+
export function initSpecJson(template, spec, language, now, block) {
|
|
127
|
+
const filled = template
|
|
128
|
+
.replaceAll("{{FEATURE_NAME}}", spec)
|
|
129
|
+
.replaceAll("{{TIMESTAMP}}", now)
|
|
130
|
+
.replace(/("language"\s*:\s*)"[^"]*"/, `$1${JSON.stringify(language)}`);
|
|
131
|
+
let json;
|
|
132
|
+
try {
|
|
133
|
+
json = JSON.parse(filled);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new SpecError(`the engine's init.json is not valid JSON: ${error.message}`);
|
|
137
|
+
}
|
|
138
|
+
return `${JSON.stringify({ ...json, language, cupola: block }, null, 2)}\n`;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Puts the block back when the engine's skills rewrote spec.json without it
|
|
142
|
+
* or changed it. Returns the new text, or undefined when the
|
|
143
|
+
* block is intact. The method and the contract revisions the spec was created
|
|
144
|
+
* with are kept; only a block lost whole takes `expected`'s.
|
|
145
|
+
*/
|
|
146
|
+
export function reassertBlock(path, raw, expected) {
|
|
147
|
+
let json;
|
|
148
|
+
try {
|
|
149
|
+
json = JSON.parse(raw);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
throw new SpecError(`${path}: not valid JSON: ${error.message}`);
|
|
153
|
+
}
|
|
154
|
+
const parsed = CupolaBlock.safeParse(json.cupola);
|
|
155
|
+
// Work in flight keeps its method; only a block lost whole takes the expected one.
|
|
156
|
+
const block = parsed.success
|
|
157
|
+
? {
|
|
158
|
+
...expected,
|
|
159
|
+
method: parsed.data.method,
|
|
160
|
+
contracts: parsed.data.contracts,
|
|
161
|
+
revision: parsed.data.revision ?? expected.revision,
|
|
162
|
+
}
|
|
163
|
+
: expected;
|
|
164
|
+
// The contracts are kept as they were, so only the identifying fields can differ.
|
|
165
|
+
if (parsed.success &&
|
|
166
|
+
parsed.data.epic === block.epic &&
|
|
167
|
+
parsed.data.component === block.component) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
return `${JSON.stringify({ ...json, cupola: block }, null, 2)}\n`;
|
|
171
|
+
}
|
package/dist/status.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { endingCard, pendingSendBacks } from "./record.js";
|
|
2
|
+
export function deriveStatus({ work, change, record, cards, finished, feedback, untidy, waiting, revision, dropped, retake, environment, }) {
|
|
3
|
+
const base = { work, change: change ?? null, cards: [], run: null };
|
|
4
|
+
const id = work.id;
|
|
5
|
+
const resume = `cupola-spec-run ${id}`;
|
|
6
|
+
if (change?.state === "merged") {
|
|
7
|
+
const complete = `cupola-complete ${id}`;
|
|
8
|
+
return {
|
|
9
|
+
...base,
|
|
10
|
+
status: "done",
|
|
11
|
+
turn: untidy ? "human" : "none",
|
|
12
|
+
gate: null,
|
|
13
|
+
next: untidy
|
|
14
|
+
? {
|
|
15
|
+
kind: "run",
|
|
16
|
+
text: `Merged: \`${complete}\` tidies up and moves on.`,
|
|
17
|
+
command: complete,
|
|
18
|
+
}
|
|
19
|
+
: { kind: "nothing", text: "Done." },
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (change?.state === "closed") {
|
|
23
|
+
return {
|
|
24
|
+
...base,
|
|
25
|
+
status: "dropped",
|
|
26
|
+
turn: "none",
|
|
27
|
+
gate: null,
|
|
28
|
+
next: { kind: "nothing", text: "Dropped." },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Dropped by its epic before anything else: its cards no longer ask anything.
|
|
32
|
+
if (dropped) {
|
|
33
|
+
return {
|
|
34
|
+
...base,
|
|
35
|
+
status: "dropped",
|
|
36
|
+
turn: "none",
|
|
37
|
+
gate: null,
|
|
38
|
+
next: { kind: "nothing", text: `Dropped: ${dropped}.` },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const unanswered = cards.filter((c) => !c.answered).map((c) => c.card);
|
|
42
|
+
if (unanswered.length > 0) {
|
|
43
|
+
return {
|
|
44
|
+
...base,
|
|
45
|
+
status: "awaiting-decision",
|
|
46
|
+
turn: "human",
|
|
47
|
+
gate: "G2",
|
|
48
|
+
cards: unanswered,
|
|
49
|
+
next: {
|
|
50
|
+
kind: "gate",
|
|
51
|
+
text: `Answer cards ${unanswered.join(", ")}; the run resumes when the answers are recorded.`,
|
|
52
|
+
command: `cupola-decide ${id}`,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const aiWorking = (run, next) => ({
|
|
57
|
+
...base,
|
|
58
|
+
status: "ai-working",
|
|
59
|
+
turn: "ai",
|
|
60
|
+
gate: null,
|
|
61
|
+
run,
|
|
62
|
+
next,
|
|
63
|
+
});
|
|
64
|
+
// A send-back is written before the change goes back to draft; the run resumes from it.
|
|
65
|
+
// The run removes its whole directory, cards included, before G3, so a
|
|
66
|
+
// card found without a record is a send-back written after that.
|
|
67
|
+
const sendBacks = pendingSendBacks(record, cards);
|
|
68
|
+
if (sendBacks.length > 0) {
|
|
69
|
+
return aiWorking({ phase: null, active: null }, {
|
|
70
|
+
kind: "run",
|
|
71
|
+
text: `Sent back (card ${sendBacks.map((c) => c.card).join(", ")}); resume the run.`,
|
|
72
|
+
command: resume,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// Feedback a person left on the change sends it back as a card does: the run answers it.
|
|
76
|
+
if (feedback && feedback > 0 && !record) {
|
|
77
|
+
return aiWorking({ phase: null, active: null }, {
|
|
78
|
+
kind: "run",
|
|
79
|
+
text: `Sent back on the change (${feedback} remark${feedback === 1 ? "" : "s"} to answer); resume the run.`,
|
|
80
|
+
command: resume,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// An answer that ends the run is carried out by the dialogue that recorded it.
|
|
84
|
+
const ending = endingCard(record, cards);
|
|
85
|
+
if (ending) {
|
|
86
|
+
return aiWorking({ phase: null, active: null }, {
|
|
87
|
+
kind: "run",
|
|
88
|
+
text: `Card ${ending.card} chose ${ending.effect}, which is not carried out yet.`,
|
|
89
|
+
command: `cupola-decide ${id}`,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// A revision under agreement plans to change it: it waits, even at G3.
|
|
93
|
+
if (revision && !record?.active) {
|
|
94
|
+
return {
|
|
95
|
+
...base,
|
|
96
|
+
status: "waiting",
|
|
97
|
+
turn: "ai",
|
|
98
|
+
gate: null,
|
|
99
|
+
run: null,
|
|
100
|
+
next: { kind: "nothing", text: `${revision}.` },
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (retake) {
|
|
104
|
+
return {
|
|
105
|
+
...base,
|
|
106
|
+
status: "ai-working",
|
|
107
|
+
turn: "ai",
|
|
108
|
+
gate: null,
|
|
109
|
+
next: { kind: "run", text: retake.text, command: retake.command },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (change?.state === "open" && !change.draft && !record) {
|
|
113
|
+
return {
|
|
114
|
+
...base,
|
|
115
|
+
status: "awaiting-acceptance",
|
|
116
|
+
turn: "human",
|
|
117
|
+
gate: "G3",
|
|
118
|
+
next: {
|
|
119
|
+
kind: "gate",
|
|
120
|
+
text: `Read "Needs confirmation" on ${change.url}, merge it, then run the command; or send it back by leaving feedback on the change, or with \`cupola-decide ${id}\`.`,
|
|
121
|
+
command: `cupola-complete ${id}`,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const phase = record?.phases.find((p) => p.state === "running")?.name ??
|
|
126
|
+
record?.phases.find((p) => p.state === "pending" || p.state === "redo")?.name ??
|
|
127
|
+
null;
|
|
128
|
+
const active = record?.active
|
|
129
|
+
? {
|
|
130
|
+
id: record.active.id,
|
|
131
|
+
who: record.active.who,
|
|
132
|
+
session: record.active.session,
|
|
133
|
+
since: record.active.since,
|
|
134
|
+
}
|
|
135
|
+
: null;
|
|
136
|
+
const run = { phase, active };
|
|
137
|
+
if (active) {
|
|
138
|
+
return aiWorking(run, {
|
|
139
|
+
kind: "nothing",
|
|
140
|
+
text: `Running ${phase ?? "its last steps"} (${active.who}, session ${active.session}, since ${active.since}). ` +
|
|
141
|
+
`If that session has ended, resume with --take-over ${active.id}.`,
|
|
142
|
+
command: `${resume} --take-over ${active.id}`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if (!record && finished) {
|
|
146
|
+
return aiWorking(run, {
|
|
147
|
+
kind: "run",
|
|
148
|
+
text: "The finish was interrupted; run again to finish.",
|
|
149
|
+
command: resume,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (environment) {
|
|
153
|
+
return {
|
|
154
|
+
...base,
|
|
155
|
+
status: "waiting",
|
|
156
|
+
turn: "ai",
|
|
157
|
+
gate: null,
|
|
158
|
+
run,
|
|
159
|
+
next: {
|
|
160
|
+
kind: "nothing",
|
|
161
|
+
text: `It waits: ${environment}. Run it again once that is released.`,
|
|
162
|
+
command: resume,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (phase === "design" && waiting && waiting.for.length > 0) {
|
|
167
|
+
return {
|
|
168
|
+
...base,
|
|
169
|
+
status: "waiting",
|
|
170
|
+
turn: "ai",
|
|
171
|
+
gate: null,
|
|
172
|
+
run,
|
|
173
|
+
next: {
|
|
174
|
+
kind: "nothing",
|
|
175
|
+
text: `Its design waits for the design of ${waiting.for.join(", ")}; the epic's run starts it then.`,
|
|
176
|
+
command: waiting.resume,
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (!record)
|
|
181
|
+
return aiWorking(run, { kind: "run", text: "Start the run.", command: resume });
|
|
182
|
+
if (!phase) {
|
|
183
|
+
return aiWorking(run, {
|
|
184
|
+
kind: "run",
|
|
185
|
+
text: "Every phase is done; the run finishes the work (looks back, removes the record, marks the change ready).",
|
|
186
|
+
command: resume,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return aiWorking(run, { kind: "run", text: `Resume the run at ${phase}.`, command: resume });
|
|
190
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { METHOD } from "./method/v1.js";
|
|
5
|
+
/** Templates a run writes from, served from the package per method. */
|
|
6
|
+
const RUN_TEMPLATES = [
|
|
7
|
+
"card",
|
|
8
|
+
"send-back",
|
|
9
|
+
"case-draft",
|
|
10
|
+
"cupola-issue-draft",
|
|
11
|
+
"phase-outcome",
|
|
12
|
+
"changes/catalog",
|
|
13
|
+
"changes/fix",
|
|
14
|
+
"changes/spec",
|
|
15
|
+
"changes/release",
|
|
16
|
+
];
|
|
17
|
+
function methodDir(method) {
|
|
18
|
+
return fileURLToPath(new URL(`../templates/method-${method}/`, import.meta.url));
|
|
19
|
+
}
|
|
20
|
+
/** Every template a method serves, by kind: `card`, `changes/catalog`, … */
|
|
21
|
+
export function templateKinds(method = METHOD) {
|
|
22
|
+
const dir = methodDir(method);
|
|
23
|
+
const kinds = new Map();
|
|
24
|
+
for (const entry of readdirSync(dir, { recursive: true, withFileTypes: true })) {
|
|
25
|
+
if (!entry.isFile())
|
|
26
|
+
continue;
|
|
27
|
+
const full = join(entry.parentPath, entry.name);
|
|
28
|
+
const rel = full.slice(dir.length).replaceAll("\\", "/");
|
|
29
|
+
kinds.set(rel.replace(/\.(md|json)$/, ""), full);
|
|
30
|
+
}
|
|
31
|
+
// The steering a project owns, for the dialogue that writes or grows it (cupola-steering).
|
|
32
|
+
const steering = fileURLToPath(new URL("../templates/install/.kiro/steering/", import.meta.url));
|
|
33
|
+
for (const name of ["operations", "principles", "e2e"]) {
|
|
34
|
+
kinds.set(`steering/${name}`, join(steering, `${name}.md`));
|
|
35
|
+
}
|
|
36
|
+
return kinds;
|
|
37
|
+
}
|
|
38
|
+
export function templatePath(kind, method = METHOD) {
|
|
39
|
+
const kinds = templateKinds(method);
|
|
40
|
+
const path = kinds.get(kind);
|
|
41
|
+
if (!path) {
|
|
42
|
+
const known = [...kinds.keys()].sort().join(", ");
|
|
43
|
+
throw new Error(`no template ${kind} in method ${method}; known: ${known}`);
|
|
44
|
+
}
|
|
45
|
+
return path;
|
|
46
|
+
}
|
|
47
|
+
export function runTemplates(method = METHOD) {
|
|
48
|
+
return Object.fromEntries(RUN_TEMPLATES.map((t) => [t, templatePath(t, method)]));
|
|
49
|
+
}
|