@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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { epicPath } from "../config.js";
|
|
4
|
+
import { today } from "../day.js";
|
|
5
|
+
import { originDefaultBranch } from "../git.js";
|
|
6
|
+
import { procedureMarker, procedureRecords, } from "../procedure.js";
|
|
7
|
+
import { parseRunbook } from "../runbook.js";
|
|
8
|
+
import { epicFront } from "../spec.js";
|
|
9
|
+
import { gitTree } from "../tree.js";
|
|
10
|
+
import { workspace } from "../workspace.js";
|
|
11
|
+
import { workStatus } from "./status.js";
|
|
12
|
+
import { trackerOf } from "./work.js";
|
|
13
|
+
const RESULTS = ["done", "stopped", "finished"];
|
|
14
|
+
/**
|
|
15
|
+
* `cupola procedure record <epic> <runbook> --result done|stopped --step <P#>`,
|
|
16
|
+
* or `--result finished`: records one step of the procedure a human is
|
|
17
|
+
* carrying out, or its end, as a Log line on every case of the epic. The epic must be operating,
|
|
18
|
+
* on that procedure.
|
|
19
|
+
*/
|
|
20
|
+
export async function procedureRecord(io, epic, runbook, opts) {
|
|
21
|
+
const result = opts.result;
|
|
22
|
+
if (!RESULTS.includes(result))
|
|
23
|
+
throw new Error("give --result done, stopped, or finished");
|
|
24
|
+
const step = opts.step;
|
|
25
|
+
if (result === "finished" ? step !== undefined : step === undefined)
|
|
26
|
+
throw new Error(result === "finished"
|
|
27
|
+
? "a finished procedure names no step"
|
|
28
|
+
: `give the step it records: --step <P#>`);
|
|
29
|
+
if (!opts.bodyFile)
|
|
30
|
+
throw new Error("give the line: --body-file <file>");
|
|
31
|
+
const line = (await readFile(resolve(io.cwd, opts.bodyFile), "utf8")).trim();
|
|
32
|
+
if (line === "" || line.includes("\n"))
|
|
33
|
+
throw new Error("a Log entry is one line");
|
|
34
|
+
if (line.includes("{{"))
|
|
35
|
+
throw new Error("the Log entry still has template placeholders ({{…}})");
|
|
36
|
+
// Epics, runbooks, and cases are the hub's.
|
|
37
|
+
const ws = await workspace(io);
|
|
38
|
+
const root = ws.here.isHub ? ws.root : ws.hub.main;
|
|
39
|
+
const now = await workStatus(io, root, ws.config, epic);
|
|
40
|
+
if (now.work.kind !== "epic")
|
|
41
|
+
throw new Error(`${epic} is not an epic`);
|
|
42
|
+
if (now.status !== "operating" || !now.procedure)
|
|
43
|
+
throw new Error(`${epic} is ${now.status}: a procedure is recorded while its epic is operating`);
|
|
44
|
+
if (now.procedure.runbook !== runbook)
|
|
45
|
+
throw new Error(`${epic} carries out ${now.procedure.runbook} now, not ${runbook}`);
|
|
46
|
+
// Operating means agreed: the epic and its runbooks are on origin's default branch.
|
|
47
|
+
const base = await originDefaultBranch(root);
|
|
48
|
+
const agreed = gitTree(root, base ? `refs/remotes/origin/${base}` : "HEAD");
|
|
49
|
+
const path = epicPath(ws.config.paths, epic);
|
|
50
|
+
const { front } = epicFront(path, (await agreed.read(path)) ?? "");
|
|
51
|
+
const bookPath = `${ws.config.paths.runbooks}/${runbook}.md`;
|
|
52
|
+
const raw = await agreed.read(bookPath);
|
|
53
|
+
if (raw === undefined)
|
|
54
|
+
throw new Error(`no ${bookPath} on origin's default branch`);
|
|
55
|
+
const steps = parseRunbook(raw).steps.map((s) => s.id);
|
|
56
|
+
// Steps are carried out in the runbook's order: the next is the first not done yet.
|
|
57
|
+
const next = steps.find((s) => !now.procedure?.done.includes(s));
|
|
58
|
+
if (step !== undefined) {
|
|
59
|
+
if (!steps.includes(step))
|
|
60
|
+
throw new Error(`${runbook} has no step ${step}`);
|
|
61
|
+
if (step !== next)
|
|
62
|
+
throw new Error(next
|
|
63
|
+
? `${runbook} goes on at ${next}, not ${step}: steps are recorded in the runbook's order`
|
|
64
|
+
: `every step of ${runbook} is done: record it finished`);
|
|
65
|
+
}
|
|
66
|
+
else if (next) {
|
|
67
|
+
throw new Error(`${runbook} is not done: ${next} is next`);
|
|
68
|
+
}
|
|
69
|
+
const tracker = await trackerOf(io);
|
|
70
|
+
const day = await today(io);
|
|
71
|
+
const record = { epic, runbook, ...(step ? { step } : {}), result };
|
|
72
|
+
const marker = procedureMarker(record);
|
|
73
|
+
const what = `epic ${epic}: ${runbook}${step ? ` ${step}` : ""} ${result}`;
|
|
74
|
+
// Run again after a write that reached only some cases: the cases that have it are left alone.
|
|
75
|
+
const latest = (text) => procedureRecords([text], epic).at(-1);
|
|
76
|
+
const same = (r) => r !== undefined && JSON.stringify(r) === JSON.stringify(record);
|
|
77
|
+
const texts = new Map();
|
|
78
|
+
for (const c of front.cases)
|
|
79
|
+
texts.set(c, (await tracker.show(c))?.text ?? "");
|
|
80
|
+
const retry = [...texts.values()].some((t) => same(latest(t)));
|
|
81
|
+
const logged = [];
|
|
82
|
+
for (const c of front.cases) {
|
|
83
|
+
if (retry && same(latest(texts.get(c) ?? "")))
|
|
84
|
+
continue;
|
|
85
|
+
await tracker.log(c, `${day} ${what}: ${line} ${marker}`);
|
|
86
|
+
logged.push(c);
|
|
87
|
+
}
|
|
88
|
+
io.out(opts.json
|
|
89
|
+
? JSON.stringify({ epic, runbook, step, result, logged })
|
|
90
|
+
: `${what}; logged on ${logged.join(", ") || "no case (already recorded)"}`);
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { appendFile, mkdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { epicPath, pathsAt } from "../config.js";
|
|
5
|
+
import { git, originDefaultBranch } from "../git.js";
|
|
6
|
+
import { github } from "../host/github.js";
|
|
7
|
+
import { writeInside } from "../safe-write.js";
|
|
8
|
+
import { epicFront, readBlock, revisionsOf } from "../spec.js";
|
|
9
|
+
import { gitTree } from "../tree.js";
|
|
10
|
+
import { assertWorkId, workBranchName } from "../work.js";
|
|
11
|
+
import { recordsAbort } from "./epic.js";
|
|
12
|
+
import { fetchOrKeep, workTree } from "./status.js";
|
|
13
|
+
import { trackerOf } from "./work.js";
|
|
14
|
+
/**
|
|
15
|
+
* Revisions of a running epic: the agreed epic on origin's
|
|
16
|
+
* default branch, and the draft of a revision whose `epic` change is open.
|
|
17
|
+
*/
|
|
18
|
+
/** The agreed epic's text, from origin's default branch. */
|
|
19
|
+
export async function agreedEpicText(root, epic) {
|
|
20
|
+
const base = await originDefaultBranch(root);
|
|
21
|
+
if (!base)
|
|
22
|
+
return undefined;
|
|
23
|
+
const ref = `refs/remotes/origin/${base}`;
|
|
24
|
+
try {
|
|
25
|
+
await fetchOrKeep(root, `refs/heads/${base}`, ref);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return gitTree(root, ref).read(epicPath(await pathsAt(root), epic));
|
|
31
|
+
}
|
|
32
|
+
/** The draft of a revision under agreement (its `epic` change is open), or undefined. */
|
|
33
|
+
async function draftEpicText(io, root, epic) {
|
|
34
|
+
const change = await (io.host ?? github)(root).findChange(workBranchName(epic));
|
|
35
|
+
if (change?.state !== "open")
|
|
36
|
+
return undefined;
|
|
37
|
+
return (await workTree(root, workBranchName(epic))).tree.read(epicPath(await pathsAt(root), epic));
|
|
38
|
+
}
|
|
39
|
+
function revisions(path, text) {
|
|
40
|
+
return text === undefined ? [] : revisionsOf(epicFront(path, text).epic);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The plan a revision under agreement has for a component other than
|
|
44
|
+
* `continue`: the spec waits until it is agreed.
|
|
45
|
+
*/
|
|
46
|
+
export async function pendingPlan(io, root, epic, component) {
|
|
47
|
+
const path = epicPath(await pathsAt(root), epic);
|
|
48
|
+
const draft = revisions(path, await draftEpicText(io, root, epic));
|
|
49
|
+
if (draft.length === 0)
|
|
50
|
+
return undefined;
|
|
51
|
+
const agreed = Math.max(1, ...revisions(path, await agreedEpicText(root, epic)).map((r) => r.n));
|
|
52
|
+
for (const r of draft.filter((r) => r.n > agreed)) {
|
|
53
|
+
const plan = r.plans.get(component);
|
|
54
|
+
if (plan && plan !== "continue")
|
|
55
|
+
return { revision: r.n, plan };
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
/** The agreed revisions a spec has not taken in yet, with its component's plan in each. */
|
|
60
|
+
export async function revisionsToApply(root, block) {
|
|
61
|
+
const path = epicPath(await pathsAt(root), block.epic);
|
|
62
|
+
return revisions(path, await agreedEpicText(root, block.epic))
|
|
63
|
+
.filter((r) => r.n > (block.revision ?? 1))
|
|
64
|
+
.map((r) => ({ revision: r.n, plan: r.plans.get(block.component) ?? "continue" }));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Cards whose `revise-epic` answer a revision has carried out (its `from:
|
|
68
|
+
* card <spec>#<n>`, agreed or under agreement): they no longer end the run.
|
|
69
|
+
*/
|
|
70
|
+
export async function carriedOut(io, root, spec, epic, cards) {
|
|
71
|
+
if (!cards.some((c) => c.effect === "revise-epic"))
|
|
72
|
+
return cards;
|
|
73
|
+
const path = epicPath(await pathsAt(root), epic);
|
|
74
|
+
const from = new Set([
|
|
75
|
+
...revisions(path, await agreedEpicText(root, epic)),
|
|
76
|
+
...revisions(path, await draftEpicText(io, root, epic)),
|
|
77
|
+
].flatMap((r) => (r.from ? [r.from] : [])));
|
|
78
|
+
return cards.map((c) => c.effect === "revise-epic" && from.has(`${spec}#${c.card}`) ? { ...c, effect: "continue" } : c);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Why a spec of a running epic no longer runs, if it does not: an agreed
|
|
82
|
+
* revision drops its component, or the epic was aborted (recorded on its
|
|
83
|
+
* cases).
|
|
84
|
+
*/
|
|
85
|
+
export async function droppedBecause(io, root, epic, component) {
|
|
86
|
+
const path = epicPath(await pathsAt(root), epic);
|
|
87
|
+
const agreed = await agreedEpicText(root, epic);
|
|
88
|
+
if (agreed === undefined)
|
|
89
|
+
return undefined;
|
|
90
|
+
const drop = revisionsOf(epicFront(path, agreed).epic).find((r) => r.plans.get(component) === "drop");
|
|
91
|
+
if (drop)
|
|
92
|
+
return `R${drop.n} of ${epic} drops it`;
|
|
93
|
+
const tracker = await trackerOf(io);
|
|
94
|
+
for (const c of epicFront(path, agreed).front.cases) {
|
|
95
|
+
const shown = await tracker.show(c);
|
|
96
|
+
if (shown && recordsAbort(shown.text, epic))
|
|
97
|
+
return `epic ${epic} is aborted`;
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
/** The first agreed revision a spec has not taken in that redesigns it, if any. */
|
|
102
|
+
export async function redesignToTakeIn(root, tree, spec) {
|
|
103
|
+
const file = `.kiro/specs/${spec}/spec.json`;
|
|
104
|
+
const raw = await tree.read(file);
|
|
105
|
+
const block = raw === undefined ? undefined : readBlock(file, raw);
|
|
106
|
+
if (!block)
|
|
107
|
+
return undefined;
|
|
108
|
+
return (await revisionsToApply(root, block)).find((t) => t.plan === "redesign")?.revision;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* In a component's repository, which has no epics of its own, the
|
|
112
|
+
* agreed epic a spec runs against is copied from the hub into the worktree at
|
|
113
|
+
* the same path as in the hub, kept out of git by the repository's exclude file, so that
|
|
114
|
+
* the spec and its phases read it where the hub's specs do. Returns whether a
|
|
115
|
+
* copy was written; in the hub, the epic is on the branch itself.
|
|
116
|
+
*/
|
|
117
|
+
export async function snapshotEpic(ws, root, epic) {
|
|
118
|
+
assertWorkId(epic);
|
|
119
|
+
if (ws.here.isHub)
|
|
120
|
+
return false;
|
|
121
|
+
const text = await agreedEpicText(ws.hub.main, epic);
|
|
122
|
+
if (text === undefined) {
|
|
123
|
+
throw new Error(`${epicPath(ws.config.paths, epic)} is not on the hub's default branch: is the epic agreed?`);
|
|
124
|
+
}
|
|
125
|
+
const dir = ws.config.paths.epics;
|
|
126
|
+
const exclude = await git(root, [
|
|
127
|
+
"rev-parse",
|
|
128
|
+
"--path-format=absolute",
|
|
129
|
+
"--git-path",
|
|
130
|
+
"info/exclude",
|
|
131
|
+
]);
|
|
132
|
+
const have = existsSync(exclude) ? await readFile(exclude, "utf8") : "";
|
|
133
|
+
if (!have.split("\n").includes(`/${dir}/`)) {
|
|
134
|
+
await mkdir(dirname(exclude), { recursive: true });
|
|
135
|
+
await appendFile(exclude, `${have === "" || have.endsWith("\n") ? "" : "\n"}/${dir}/\n`);
|
|
136
|
+
}
|
|
137
|
+
await writeInside(root, join(dir, `${epic}.md`), text);
|
|
138
|
+
return true;
|
|
139
|
+
}
|