@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,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method 1: the phase table of each mode. The order
|
|
3
|
+
* of phases is decided here, never by a runner's judgment.
|
|
4
|
+
*/
|
|
5
|
+
export const METHOD = 1;
|
|
6
|
+
const FULL = [
|
|
7
|
+
{ name: "acceptance", skill: "cupola-spec-design" },
|
|
8
|
+
{ name: "design", skill: "cupola-spec-design" },
|
|
9
|
+
{ name: "impl", skill: "cupola-spec-impl", resumesAfterCards: true },
|
|
10
|
+
{ name: "summary", skill: "cupola-spec-impl" },
|
|
11
|
+
{ name: "mutation", skill: "cupola-spec-impl" },
|
|
12
|
+
{ name: "doc", skill: "cupola-doc" },
|
|
13
|
+
{ name: "review", skill: "cupola-review" },
|
|
14
|
+
{ name: "e2e", skill: "cupola-e2e-test", locks: true },
|
|
15
|
+
{ name: "accept", skill: "cupola-epic-accept" },
|
|
16
|
+
];
|
|
17
|
+
const FIX = [
|
|
18
|
+
{ name: "reproduce", skill: "cupola-fix" },
|
|
19
|
+
{ name: "impl", skill: "cupola-fix" },
|
|
20
|
+
{ name: "summary", skill: "cupola-fix" },
|
|
21
|
+
{ name: "review", skill: "cupola-review" },
|
|
22
|
+
{ name: "doc", skill: "cupola-doc" },
|
|
23
|
+
{ name: "e2e", skill: "cupola-e2e-test", locks: true },
|
|
24
|
+
];
|
|
25
|
+
const CATALOG = [
|
|
26
|
+
{ name: "survey-draft", skill: "cupola-catalog-draft" },
|
|
27
|
+
{ name: "tag-pin", skill: "cupola-catalog-draft" },
|
|
28
|
+
{ name: "mutation", skill: "cupola-catalog-draft" },
|
|
29
|
+
{ name: "review", skill: "cupola-review" },
|
|
30
|
+
];
|
|
31
|
+
const EPIC = [
|
|
32
|
+
{ name: "accept", skill: "cupola-epic-accept", locks: true },
|
|
33
|
+
{ name: "open-release", skill: "cupola-epic-accept" },
|
|
34
|
+
];
|
|
35
|
+
export const PHASES = {
|
|
36
|
+
full: FULL,
|
|
37
|
+
fix: FIX,
|
|
38
|
+
catalog: CATALOG,
|
|
39
|
+
epic: EPIC,
|
|
40
|
+
};
|
|
41
|
+
export function modeOf(kind) {
|
|
42
|
+
switch (kind) {
|
|
43
|
+
case "spec":
|
|
44
|
+
return "full";
|
|
45
|
+
case "fix":
|
|
46
|
+
case "fix-spec":
|
|
47
|
+
return "fix";
|
|
48
|
+
case "catalog":
|
|
49
|
+
return "catalog";
|
|
50
|
+
case "epic":
|
|
51
|
+
return "epic";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function phaseDef(mode, name) {
|
|
55
|
+
return PHASES[mode].find((p) => p.name === name);
|
|
56
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How far an epic's procedures have run. Each step a
|
|
3
|
+
* human carries out is recorded as a Log line on every case of the epic, with
|
|
4
|
+
* a marker; the status is derived from those lines and never stored.
|
|
5
|
+
*/
|
|
6
|
+
const MARKER = /<!--\s*cupola:procedure\s+(\{.*?\})\s*-->/g;
|
|
7
|
+
/** The marker `cupola procedure record` appends to the Log line. */
|
|
8
|
+
export function procedureMarker(r) {
|
|
9
|
+
const { epic, runbook, step, result } = r;
|
|
10
|
+
return `<!-- cupola:procedure ${JSON.stringify({ epic, runbook, ...(step ? { step } : {}), result })} -->`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The records of one epic, in the order they were written. Every case of the
|
|
14
|
+
* epic carries the same lines; when a write reached only some of them, the
|
|
15
|
+
* case with the most records has them all.
|
|
16
|
+
*/
|
|
17
|
+
export function procedureRecords(caseTexts, epic) {
|
|
18
|
+
let best = [];
|
|
19
|
+
for (const text of caseTexts) {
|
|
20
|
+
const out = [];
|
|
21
|
+
for (const m of text.matchAll(MARKER)) {
|
|
22
|
+
let r;
|
|
23
|
+
try {
|
|
24
|
+
r = JSON.parse(m[1] ?? "{}");
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
continue; // a marker edited by hand: it records nothing
|
|
28
|
+
}
|
|
29
|
+
if (r.epic !== epic || typeof r.runbook !== "string")
|
|
30
|
+
continue;
|
|
31
|
+
if (r.result !== "done" && r.result !== "stopped" && r.result !== "finished")
|
|
32
|
+
continue;
|
|
33
|
+
out.push({
|
|
34
|
+
epic,
|
|
35
|
+
runbook: r.runbook,
|
|
36
|
+
...(typeof r.step === "string" ? { step: r.step } : {}),
|
|
37
|
+
result: r.result,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (out.length > best.length)
|
|
41
|
+
best = out;
|
|
42
|
+
}
|
|
43
|
+
return best;
|
|
44
|
+
}
|
|
45
|
+
/** The procedure to carry out next, or undefined when every one is finished. */
|
|
46
|
+
export function currentProcedure(procedures, records) {
|
|
47
|
+
for (const runbook of procedures) {
|
|
48
|
+
const own = records.filter((r) => r.runbook === runbook);
|
|
49
|
+
if (own.some((r) => r.result === "finished"))
|
|
50
|
+
continue;
|
|
51
|
+
const last = own.at(-1);
|
|
52
|
+
const done = own.filter((r) => r.result === "done" && r.step).map((r) => r.step);
|
|
53
|
+
return {
|
|
54
|
+
runbook,
|
|
55
|
+
done: [...new Set(done)],
|
|
56
|
+
...(last?.result === "stopped" && last.step ? { stopped: last.step } : {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
package/dist/record.js
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { METHOD, modeOf, PHASES, phaseDef } from "./method/v1.js";
|
|
4
|
+
/**
|
|
5
|
+
* The progress record: `.cupola/runs/<work>/record.json`
|
|
6
|
+
* on the work's branch. Only the CLI writes it; every write raises `serial`.
|
|
7
|
+
*/
|
|
8
|
+
const workKind = z.enum(["spec", "fix", "fix-spec", "catalog", "epic"]);
|
|
9
|
+
const mode = z.enum(["full", "fix", "catalog", "epic"]);
|
|
10
|
+
const phaseState = z.enum(["pending", "running", "done", "redo", "skipped"]);
|
|
11
|
+
const active = z.strictObject({
|
|
12
|
+
id: z.string().min(1),
|
|
13
|
+
who: z.string(),
|
|
14
|
+
session: z.string().min(1),
|
|
15
|
+
since: z.string(),
|
|
16
|
+
cli: z.string(),
|
|
17
|
+
phase: z.string(),
|
|
18
|
+
});
|
|
19
|
+
const outside = z.strictObject({
|
|
20
|
+
kind: z.string().min(1),
|
|
21
|
+
id: z.string().min(1),
|
|
22
|
+
where: z.string(),
|
|
23
|
+
credential: z.string(),
|
|
24
|
+
phase: z.string().optional(),
|
|
25
|
+
cleanup: z.string().regex(/^(done|pending|kept: .+)$/, "done | pending | kept: <reason>"),
|
|
26
|
+
});
|
|
27
|
+
const phase = z.strictObject({
|
|
28
|
+
name: z.string().min(1),
|
|
29
|
+
state: phaseState,
|
|
30
|
+
commit: z.string().optional(),
|
|
31
|
+
started: z.string().optional(),
|
|
32
|
+
finished: z.string().optional(),
|
|
33
|
+
note: z.string().optional(),
|
|
34
|
+
/** For a skipped phase: the phase whose outcome skipped it, so that a send-back keeps the skip. */
|
|
35
|
+
skipped_by: z.string().optional(),
|
|
36
|
+
/** The shared e2e environments its plan needs (an id, or `pool:<name>`); `run next` locks them. */
|
|
37
|
+
needs: z.array(z.string()).optional(),
|
|
38
|
+
/** The shared environments this phase holds the locks of, until `run record` releases them. */
|
|
39
|
+
locks: z.array(z.string()).optional(),
|
|
40
|
+
});
|
|
41
|
+
const event = z.strictObject({
|
|
42
|
+
at: z.string(),
|
|
43
|
+
phase: z.string(),
|
|
44
|
+
what: z.string().min(1),
|
|
45
|
+
note: z.string().optional(),
|
|
46
|
+
});
|
|
47
|
+
export const recordSchema = z.strictObject({
|
|
48
|
+
kind: z.literal("record"),
|
|
49
|
+
method: z.literal(METHOD),
|
|
50
|
+
work: z.strictObject({
|
|
51
|
+
kind: workKind,
|
|
52
|
+
id: z.string().min(1),
|
|
53
|
+
epic: z.string().nullable(),
|
|
54
|
+
component: z.string().min(1),
|
|
55
|
+
mode,
|
|
56
|
+
}),
|
|
57
|
+
lineage: z.string().min(1),
|
|
58
|
+
serial: z.int().nonnegative(),
|
|
59
|
+
started_from: z.strictObject({ card: z.int().positive().nullable() }),
|
|
60
|
+
active: active.nullable(),
|
|
61
|
+
phases: z.array(phase).min(1),
|
|
62
|
+
outside: z.array(outside),
|
|
63
|
+
drafts: z.array(z.string()),
|
|
64
|
+
events: z.array(event),
|
|
65
|
+
review: z.strictObject({ rounds: z.int().nonnegative(), max: z.int().positive() }),
|
|
66
|
+
});
|
|
67
|
+
export const outcomeSchema = z
|
|
68
|
+
.strictObject({
|
|
69
|
+
phase: z.string().min(1),
|
|
70
|
+
result: z.enum([
|
|
71
|
+
"done",
|
|
72
|
+
"redo",
|
|
73
|
+
"cards",
|
|
74
|
+
"blocked",
|
|
75
|
+
"waiting",
|
|
76
|
+
"not-a-fix",
|
|
77
|
+
"needs-environment",
|
|
78
|
+
]),
|
|
79
|
+
redo: z.string().nullable().optional(),
|
|
80
|
+
cards: z.array(z.string()).optional(),
|
|
81
|
+
blocker: z.string().nullable().optional(),
|
|
82
|
+
outside: z.array(outside.omit({ phase: true })).optional(),
|
|
83
|
+
drafts: z.array(z.string()).optional(),
|
|
84
|
+
/** Later phases found not to apply to this work, e.g. doc and e2e of a fix. */
|
|
85
|
+
skip: z.array(z.string()).optional(),
|
|
86
|
+
/** For `needs-environment`: the shared environments the plan needs. */
|
|
87
|
+
environments: z.array(z.string().min(1)).optional(),
|
|
88
|
+
note: z.string(),
|
|
89
|
+
})
|
|
90
|
+
.superRefine((o, ctx) => {
|
|
91
|
+
if (o.result === "redo" && !o.redo) {
|
|
92
|
+
ctx.addIssue({ code: "custom", path: ["redo"], message: "required when result is redo" });
|
|
93
|
+
}
|
|
94
|
+
if (o.result === "cards" && !o.cards?.length) {
|
|
95
|
+
ctx.addIssue({ code: "custom", path: ["cards"], message: "required when result is cards" });
|
|
96
|
+
}
|
|
97
|
+
if (o.result === "needs-environment" && !o.environments?.length) {
|
|
98
|
+
ctx.addIssue({
|
|
99
|
+
code: "custom",
|
|
100
|
+
path: ["environments"],
|
|
101
|
+
message: "required when result is needs-environment",
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (o.result === "blocked" && !o.blocker) {
|
|
105
|
+
ctx.addIssue({
|
|
106
|
+
code: "custom",
|
|
107
|
+
path: ["blocker"],
|
|
108
|
+
message: "required when result is blocked",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
export class RecordError extends Error {
|
|
113
|
+
constructor(message) {
|
|
114
|
+
super(message);
|
|
115
|
+
this.name = "RecordError";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function issues(error) {
|
|
119
|
+
return error.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; ");
|
|
120
|
+
}
|
|
121
|
+
export function parseRecord(raw) {
|
|
122
|
+
const result = recordSchema.safeParse(JSON.parse(raw));
|
|
123
|
+
if (!result.success)
|
|
124
|
+
throw new RecordError(`invalid progress record: ${issues(result.error)}`);
|
|
125
|
+
return result.data;
|
|
126
|
+
}
|
|
127
|
+
export function parseOutcome(raw) {
|
|
128
|
+
let json;
|
|
129
|
+
try {
|
|
130
|
+
json = JSON.parse(raw);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
throw new RecordError(`phase outcome is not valid JSON: ${error.message}`);
|
|
134
|
+
}
|
|
135
|
+
const result = outcomeSchema.safeParse(json);
|
|
136
|
+
if (!result.success)
|
|
137
|
+
throw new RecordError(`invalid phase outcome: ${issues(result.error)}`);
|
|
138
|
+
return result.data;
|
|
139
|
+
}
|
|
140
|
+
export function serializeRecord(record) {
|
|
141
|
+
return `${JSON.stringify(record, null, 2)}\n`;
|
|
142
|
+
}
|
|
143
|
+
export function createRecord(work, maxRounds) {
|
|
144
|
+
const m = modeOf(work.kind);
|
|
145
|
+
return {
|
|
146
|
+
kind: "record",
|
|
147
|
+
method: METHOD,
|
|
148
|
+
work: { kind: work.kind, id: work.id, epic: work.epic, component: work.component, mode: m },
|
|
149
|
+
lineage: randomUUID(),
|
|
150
|
+
serial: 0,
|
|
151
|
+
started_from: { card: null },
|
|
152
|
+
active: null,
|
|
153
|
+
phases: PHASES[m].map((p) => ({
|
|
154
|
+
name: p.name,
|
|
155
|
+
state: m === "full" && p.name === "accept" && !work.onlySpecOfEpic ? "skipped" : "pending",
|
|
156
|
+
})),
|
|
157
|
+
outside: [],
|
|
158
|
+
drafts: [],
|
|
159
|
+
events: [],
|
|
160
|
+
review: { rounds: 0, max: maxRounds },
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function clone(record) {
|
|
164
|
+
return structuredClone(record);
|
|
165
|
+
}
|
|
166
|
+
function bump(record) {
|
|
167
|
+
record.serial += 1;
|
|
168
|
+
return record;
|
|
169
|
+
}
|
|
170
|
+
/** Takes over another session's marker when it is named; returns whether the record changed. */
|
|
171
|
+
function claim(record, runner) {
|
|
172
|
+
const held = record.active;
|
|
173
|
+
if (held && held.session !== runner.session) {
|
|
174
|
+
if (runner.takeOver !== held.id) {
|
|
175
|
+
throw new RecordError(`${record.work.id} is being run by ${held.who} (session ${held.session}, since ${held.since}). ` +
|
|
176
|
+
`If that session is gone, run again with --take-over ${held.id}`);
|
|
177
|
+
}
|
|
178
|
+
record.events.push({
|
|
179
|
+
at: runner.now,
|
|
180
|
+
phase: held.phase,
|
|
181
|
+
what: "taken-over",
|
|
182
|
+
note: `marker ${held.id} of ${held.who} (session ${held.session})`,
|
|
183
|
+
});
|
|
184
|
+
record.active = null;
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
/** Effects of an answer that end the run; `cupola-decide` carries them out. */
|
|
190
|
+
const ENDING_EFFECTS = new Set(["revise-epic", "abort", "to-case"]);
|
|
191
|
+
/** Send-backs written after the record started, oldest first. */
|
|
192
|
+
export function pendingSendBacks(record, cards) {
|
|
193
|
+
const since = record?.started_from.card ?? 0;
|
|
194
|
+
return cards.filter((c) => c.type === "send-back" && c.card > since);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* An answered card of this record whose effect ends the run (abort, revise
|
|
198
|
+
* the epic, turn into a case). Cards from before the record started are
|
|
199
|
+
* history: their effects were carried out.
|
|
200
|
+
*/
|
|
201
|
+
export function endingCard(record, cards) {
|
|
202
|
+
const since = record?.started_from.card ?? 0;
|
|
203
|
+
return cards.find((c) => c.card > since && c.effect !== null && ENDING_EFFECTS.has(c.effect));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Starts a new record from send-backs: the phases they touch are
|
|
207
|
+
* to be redone from the earliest one named, and the phases before it are done.
|
|
208
|
+
*/
|
|
209
|
+
export function createFromSendBacks(work, maxRounds, sendBacks, now, previous,
|
|
210
|
+
/** Whether `previous` is the record a finish removed: its drafts are filed already. */
|
|
211
|
+
finished = false) {
|
|
212
|
+
const record = createRecord(work, maxRounds);
|
|
213
|
+
// What the earlier run left outside the repository, or did not file yet, is still owed.
|
|
214
|
+
if (previous) {
|
|
215
|
+
record.outside = previous.outside.filter((o) => o.cleanup !== "done");
|
|
216
|
+
if (!finished)
|
|
217
|
+
record.drafts = [...previous.drafts];
|
|
218
|
+
}
|
|
219
|
+
const order = record.phases.map((p) => p.name);
|
|
220
|
+
for (const c of sendBacks) {
|
|
221
|
+
if (!order.includes(c.redo ?? "")) {
|
|
222
|
+
throw new RecordError(`send-back card ${c.card}: redo must name a phase of this work, not ${String(c.redo)}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const from = Math.min(...sendBacks.map((c) => order.indexOf(c.redo)));
|
|
226
|
+
record.phases.forEach((p, i) => {
|
|
227
|
+
if (i < from && p.state !== "skipped") {
|
|
228
|
+
p.state = "done";
|
|
229
|
+
p.note = "done before the send-back";
|
|
230
|
+
}
|
|
231
|
+
// A later phase skipped by a phase that does not run again stays skipped.
|
|
232
|
+
const before = previous?.phases.find((q) => q.name === p.name);
|
|
233
|
+
if (i >= from && before?.state === "skipped" && before.skipped_by) {
|
|
234
|
+
const by = order.indexOf(before.skipped_by);
|
|
235
|
+
if (by >= 0 && by < from)
|
|
236
|
+
Object.assign(p, { state: "skipped", note: before.note, skipped_by: before.skipped_by });
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
const numbers = sendBacks.map((c) => c.card).sort((a, b) => a - b);
|
|
240
|
+
// Feedback on the change is no card: with none before it, the record starts from no card.
|
|
241
|
+
record.started_from.card = numbers.at(-1) || null;
|
|
242
|
+
record.events.push({
|
|
243
|
+
at: now,
|
|
244
|
+
phase: order[from],
|
|
245
|
+
what: "sent-back",
|
|
246
|
+
note: sendBacks.map((c) => c.label ?? `card ${c.card}`).join(", ") +
|
|
247
|
+
(previous ? ` (after lineage ${previous.lineage})` : ""),
|
|
248
|
+
});
|
|
249
|
+
return record;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Decides what comes next for a work item: the phase to run, or where the run
|
|
253
|
+
* stops. `unansweredCards` are the card numbers still waiting for a human.
|
|
254
|
+
*/
|
|
255
|
+
export function next(current, cards, runner) {
|
|
256
|
+
const record = clone(current);
|
|
257
|
+
const tookOver = claim(record, runner);
|
|
258
|
+
const stop = (stopped, note) => {
|
|
259
|
+
const changed = tookOver || record.active !== null;
|
|
260
|
+
record.active = null;
|
|
261
|
+
return {
|
|
262
|
+
record: changed ? bump(record) : record,
|
|
263
|
+
action: { kind: "stop", stopped, note },
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
const unanswered = cards.filter((c) => !c.answered).map((c) => c.card);
|
|
267
|
+
if (unanswered.length > 0) {
|
|
268
|
+
return stop("G2", `cards waiting for a decision: ${unanswered.join(", ")}`);
|
|
269
|
+
}
|
|
270
|
+
const ending = endingCard(record, cards);
|
|
271
|
+
if (ending) {
|
|
272
|
+
return stop("blocked", `card ${ending.card} chose ${ending.effect}; \`cupola-decide\` carries that out, not the run`);
|
|
273
|
+
}
|
|
274
|
+
const running = record.phases.find((p) => p.state === "running");
|
|
275
|
+
const target = running ?? record.phases.find((p) => p.state === "pending" || p.state === "redo");
|
|
276
|
+
if (!target) {
|
|
277
|
+
const spent = record.events.filter((e) => e.what === "review-budget-spent").at(-1);
|
|
278
|
+
return stop(
|
|
279
|
+
// An epic's own run ends at the release gate.
|
|
280
|
+
record.work.mode === "epic" ? "G4" : "G3", spent
|
|
281
|
+
? `every phase is done; review budget spent: ${spent.note ?? ""}`
|
|
282
|
+
: "every phase is done; look back over the record, then finish with `cupola run finish`");
|
|
283
|
+
}
|
|
284
|
+
const def = phaseDef(record.work.mode, target.name);
|
|
285
|
+
if (!def)
|
|
286
|
+
throw new RecordError(`phase ${target.name} is not in the ${record.work.mode} table`);
|
|
287
|
+
const restarted = running !== undefined;
|
|
288
|
+
if (restarted) {
|
|
289
|
+
record.events.push({ at: runner.now, phase: target.name, what: "restarted" });
|
|
290
|
+
}
|
|
291
|
+
target.state = "running";
|
|
292
|
+
target.started = runner.now;
|
|
293
|
+
delete target.finished;
|
|
294
|
+
record.active = {
|
|
295
|
+
id: record.active?.id ?? randomUUID().slice(0, 8),
|
|
296
|
+
who: runner.who,
|
|
297
|
+
session: runner.session,
|
|
298
|
+
since: record.active?.since ?? runner.now,
|
|
299
|
+
cli: runner.cli,
|
|
300
|
+
phase: target.name,
|
|
301
|
+
};
|
|
302
|
+
return {
|
|
303
|
+
record: bump(record),
|
|
304
|
+
action: { kind: "phase", phase: target.name, skill: def.skill, restarted },
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/** Records a phase agent's outcome on the running phase. */
|
|
308
|
+
export function recordOutcome(current, outcome, runner, cards = []) {
|
|
309
|
+
const record = clone(current);
|
|
310
|
+
const held = record.active;
|
|
311
|
+
if (!held || held.session !== runner.session) {
|
|
312
|
+
throw new RecordError(`${record.work.id}: this session holds no active run; ask \`cupola run next\` first`);
|
|
313
|
+
}
|
|
314
|
+
const running = record.phases.find((p) => p.state === "running");
|
|
315
|
+
if (!running || running.name !== outcome.phase) {
|
|
316
|
+
throw new RecordError(`${record.work.id}: the outcome is for ${outcome.phase}, but the running phase is ${running?.name ?? "none"}`);
|
|
317
|
+
}
|
|
318
|
+
for (const o of outcome.outside ?? []) {
|
|
319
|
+
const i = record.outside.findIndex((x) => x.kind === o.kind && x.id === o.id);
|
|
320
|
+
const entry = { ...o, phase: outcome.phase };
|
|
321
|
+
if (i >= 0)
|
|
322
|
+
record.outside[i] = entry;
|
|
323
|
+
else
|
|
324
|
+
record.outside.push(entry);
|
|
325
|
+
}
|
|
326
|
+
for (const d of outcome.drafts ?? [])
|
|
327
|
+
if (!record.drafts.includes(d))
|
|
328
|
+
record.drafts.push(d);
|
|
329
|
+
const order = record.phases.map((p) => p.name);
|
|
330
|
+
const here = order.indexOf(running.name);
|
|
331
|
+
for (const name of outcome.skip ?? []) {
|
|
332
|
+
const i = order.indexOf(name);
|
|
333
|
+
const p = record.phases[i];
|
|
334
|
+
// A phase that runs again (after a blocked stop, say) may repeat its own skip.
|
|
335
|
+
if (p?.state === "skipped" && p.skipped_by === running.name && i > here)
|
|
336
|
+
continue;
|
|
337
|
+
if (!p || i <= here || p.state !== "pending") {
|
|
338
|
+
throw new RecordError(`cannot skip ${name}: only a later, pending phase of this work can be skipped`);
|
|
339
|
+
}
|
|
340
|
+
p.state = "skipped";
|
|
341
|
+
p.note = outcome.note;
|
|
342
|
+
p.skipped_by = running.name;
|
|
343
|
+
}
|
|
344
|
+
if (outcome.result === "cards" || outcome.result === "not-a-fix") {
|
|
345
|
+
const named = outcome.cards ?? [];
|
|
346
|
+
for (const file of named) {
|
|
347
|
+
const card = cards.find((c) => c.file === file);
|
|
348
|
+
if (!card)
|
|
349
|
+
throw new RecordError(`card ${file} is not in the run's cards directory`);
|
|
350
|
+
if (card.answered)
|
|
351
|
+
throw new RecordError(`card ${file} is already answered`);
|
|
352
|
+
}
|
|
353
|
+
const stopFix = cards.find((c) => named.includes(c.file) && c.type === "stop-fix");
|
|
354
|
+
if (outcome.result === "not-a-fix" && !stopFix) {
|
|
355
|
+
throw new RecordError("not-a-fix needs a stop-fix card among `cards`");
|
|
356
|
+
}
|
|
357
|
+
if (stopFix?.offers?.includes("to-case") &&
|
|
358
|
+
!(stopFix.case && record.drafts.includes(stopFix.case))) {
|
|
359
|
+
throw new RecordError(`card ${stopFix.file} offers to-case: name its case draft in \`case:\` and list it in \`drafts\``);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (running.name === "review" && (outcome.result === "done" || outcome.result === "redo")) {
|
|
363
|
+
record.review.rounds += 1;
|
|
364
|
+
}
|
|
365
|
+
const finish = (state) => {
|
|
366
|
+
running.state = state;
|
|
367
|
+
running.note = outcome.note;
|
|
368
|
+
// Whatever the result, the phase's locks are released by `run record`.
|
|
369
|
+
delete running.needs;
|
|
370
|
+
delete running.locks;
|
|
371
|
+
if (state === "done") {
|
|
372
|
+
running.commit = runner.commit;
|
|
373
|
+
running.finished = runner.now;
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
delete running.started;
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const stop = (stopped, note) => {
|
|
380
|
+
record.active = null;
|
|
381
|
+
return { record: bump(record), result: { continue: false, stopped, note } };
|
|
382
|
+
};
|
|
383
|
+
switch (outcome.result) {
|
|
384
|
+
case "needs-environment": {
|
|
385
|
+
if (!phaseDef(record.work.mode, running.name)?.locks) {
|
|
386
|
+
throw new RecordError(`${running.name} takes no shared environment`);
|
|
387
|
+
}
|
|
388
|
+
if (running.locks?.length) {
|
|
389
|
+
throw new RecordError(`${running.name} already holds ${running.locks.join(", ")}: run the checks, then record their outcome`);
|
|
390
|
+
}
|
|
391
|
+
const needs = outcome.environments ?? [];
|
|
392
|
+
finish("pending");
|
|
393
|
+
running.needs = needs;
|
|
394
|
+
record.events.push({
|
|
395
|
+
at: runner.now,
|
|
396
|
+
phase: running.name,
|
|
397
|
+
what: "needs-environment",
|
|
398
|
+
note: needs.join(", "),
|
|
399
|
+
});
|
|
400
|
+
return { record: bump(record), result: { continue: true } };
|
|
401
|
+
}
|
|
402
|
+
case "done":
|
|
403
|
+
finish("done");
|
|
404
|
+
return { record: bump(record), result: { continue: true } };
|
|
405
|
+
case "redo": {
|
|
406
|
+
const target = outcome.redo;
|
|
407
|
+
const from = order.indexOf(target);
|
|
408
|
+
if (from < 0)
|
|
409
|
+
throw new RecordError(`cannot redo ${target}: not a phase of this work`);
|
|
410
|
+
if (from > here) {
|
|
411
|
+
throw new RecordError(`cannot redo ${target}: it comes after ${running.name}`);
|
|
412
|
+
}
|
|
413
|
+
finish("done");
|
|
414
|
+
if (running.name === "review" && record.review.rounds >= record.review.max) {
|
|
415
|
+
// The round budget is spent: the loop stops and reports.
|
|
416
|
+
record.events.push({
|
|
417
|
+
at: runner.now,
|
|
418
|
+
phase: "review",
|
|
419
|
+
what: "review-budget-spent",
|
|
420
|
+
note: `${record.review.rounds} of ${record.review.max} rounds; not redoing ${target}: ${outcome.note}`,
|
|
421
|
+
});
|
|
422
|
+
return { record: bump(record), result: { continue: true } };
|
|
423
|
+
}
|
|
424
|
+
for (const p of record.phases.slice(from)) {
|
|
425
|
+
if (p.state === "done")
|
|
426
|
+
p.state = "redo";
|
|
427
|
+
// A skip decided by a phase that is redone is decided again.
|
|
428
|
+
else if (p.state === "skipped" && p.skipped_by && order.indexOf(p.skipped_by) >= from) {
|
|
429
|
+
p.state = "pending";
|
|
430
|
+
delete p.skipped_by;
|
|
431
|
+
delete p.note;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
record.events.push({
|
|
435
|
+
at: runner.now,
|
|
436
|
+
phase: running.name,
|
|
437
|
+
what: "redo",
|
|
438
|
+
note: `${target}: ${outcome.note}`,
|
|
439
|
+
});
|
|
440
|
+
return { record: bump(record), result: { continue: true } };
|
|
441
|
+
}
|
|
442
|
+
case "cards":
|
|
443
|
+
case "not-a-fix":
|
|
444
|
+
finish(outcome.result === "cards" && phaseDef(record.work.mode, running.name)?.resumesAfterCards
|
|
445
|
+
? "pending"
|
|
446
|
+
: "done");
|
|
447
|
+
record.events.push({
|
|
448
|
+
at: runner.now,
|
|
449
|
+
phase: running.name,
|
|
450
|
+
what: outcome.result === "cards" ? "card" : "not-a-fix",
|
|
451
|
+
note: (outcome.cards ?? []).join(", ") || outcome.note,
|
|
452
|
+
});
|
|
453
|
+
return stop(outcome.result === "cards" ? "G2" : "not-a-fix", outcome.note);
|
|
454
|
+
case "blocked":
|
|
455
|
+
finish("pending");
|
|
456
|
+
record.events.push({
|
|
457
|
+
at: runner.now,
|
|
458
|
+
phase: running.name,
|
|
459
|
+
what: "blocked",
|
|
460
|
+
note: outcome.blocker ?? "",
|
|
461
|
+
});
|
|
462
|
+
return stop("blocked", outcome.blocker ?? outcome.note);
|
|
463
|
+
case "waiting":
|
|
464
|
+
finish("pending");
|
|
465
|
+
record.events.push({
|
|
466
|
+
at: runner.now,
|
|
467
|
+
phase: running.name,
|
|
468
|
+
what: "waiting",
|
|
469
|
+
note: outcome.note,
|
|
470
|
+
});
|
|
471
|
+
return stop("waiting", outcome.note);
|
|
472
|
+
}
|
|
473
|
+
}
|
package/dist/release.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { epicBranchName } from "./spec.js";
|
|
2
|
+
import { epicRepos } from "./workspace.js";
|
|
3
|
+
/**
|
|
4
|
+
* The merge order: a repository whose specs others rely on (`after`) comes
|
|
5
|
+
* first; otherwise the configuration's order. The hub, when it holds no spec
|
|
6
|
+
* of the epic, comes last: it carries the epic's own files (system catalog,
|
|
7
|
+
* acceptance-check scripts). With every document in the hub, it comes last
|
|
8
|
+
* too, unless another repository relies on code in it. A cycle across
|
|
9
|
+
* repositories falls back to the configuration's order.
|
|
10
|
+
*/
|
|
11
|
+
export function releaseOrder(ws, specs) {
|
|
12
|
+
const repos = epicRepos(ws, specs.map((s) => s.component));
|
|
13
|
+
const own = new Set(specs.map((s) => ws.codeRepoOf(s.component)));
|
|
14
|
+
const ordered = repos.filter((r) => own.has(r.slug));
|
|
15
|
+
const before = new Map(ordered.map((r) => [r.slug, new Set()]));
|
|
16
|
+
for (const s of specs) {
|
|
17
|
+
const to = ws.codeRepoOf(s.component);
|
|
18
|
+
for (const a of s.after ?? []) {
|
|
19
|
+
const from = ws.codeRepoOf(a);
|
|
20
|
+
if (from !== to)
|
|
21
|
+
before.get(to)?.add(from);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const out = [];
|
|
25
|
+
const placed = new Set();
|
|
26
|
+
while (out.length < ordered.length) {
|
|
27
|
+
const next = ordered.find((r) => !placed.has(r.slug) && [...(before.get(r.slug) ?? [])].every((b) => placed.has(b)));
|
|
28
|
+
if (!next) {
|
|
29
|
+
// A cycle: the rest in the configuration's order.
|
|
30
|
+
for (const r of ordered)
|
|
31
|
+
if (!placed.has(r.slug))
|
|
32
|
+
out.push(r);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
out.push(next);
|
|
36
|
+
placed.add(next.slug);
|
|
37
|
+
}
|
|
38
|
+
const hub = repos.find((r) => r.isHub);
|
|
39
|
+
if (hub && !own.has(hub.slug))
|
|
40
|
+
out.push(hub);
|
|
41
|
+
// With every document in the hub, its release carries every spec's catalog: it goes after
|
|
42
|
+
// the code, unless code elsewhere relies on the hub's own code, which must be deployed first.
|
|
43
|
+
if (hub && own.has(hub.slug) && ws.config.documents === "hub") {
|
|
44
|
+
const relied = [...before.values()].some((from) => from.has(hub.slug));
|
|
45
|
+
if (!relied)
|
|
46
|
+
return [...out.filter((r) => r.slug !== hub.slug), hub];
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** The releases of an epic, in merge order. */
|
|
51
|
+
export function releasesOf(ws, specs) {
|
|
52
|
+
const order = releaseOrder(ws, specs);
|
|
53
|
+
return order.map((repo, i) => ({ repo, order: i + 1, of: order.length }));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A release change's description for one repository: its marker names the
|
|
57
|
+
* repository and its place in the order, and the "Merge order" line says so.
|
|
58
|
+
*/
|
|
59
|
+
export function releaseBody(body, release, all) {
|
|
60
|
+
const names = all.map((r) => r.repo.slug).join(" → ");
|
|
61
|
+
const previous = all[release.order - 2]?.repo.slug;
|
|
62
|
+
const line = `- Merge order: **${release.order} of ${release.of}** — ${names}. ${previous ? `Merge this after ${previous} is deployed.` : "Merge this first."}`;
|
|
63
|
+
return body
|
|
64
|
+
.replace(/(<!--\s*cupola:change\s+)(\{.*?\})(\s*-->)/, (_m, a, json, c) => {
|
|
65
|
+
let marker;
|
|
66
|
+
try {
|
|
67
|
+
marker = JSON.parse(json);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return `${a}${json}${c}`;
|
|
71
|
+
}
|
|
72
|
+
return `${a}${JSON.stringify({ ...marker, repo: release.repo.slug, order: release.order, of: release.of })}${c}`;
|
|
73
|
+
})
|
|
74
|
+
.replace(/^- Merge order:.*$/m, line);
|
|
75
|
+
}
|
|
76
|
+
/** Each release with its change, if opened. */
|
|
77
|
+
export async function releaseChanges(io, ws, epic, releases) {
|
|
78
|
+
const out = [];
|
|
79
|
+
for (const r of releases) {
|
|
80
|
+
const host = ws.host(io, r.repo.slug);
|
|
81
|
+
out.push({ ...r, host, change: (await host.findChange(epicBranchName(epic))) ?? null });
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
package/dist/repo.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const run = promisify(execFile);
|
|
4
|
+
/** The root of the git repository containing `cwd`. */
|
|
5
|
+
export async function repoRoot(cwd) {
|
|
6
|
+
try {
|
|
7
|
+
const { stdout } = await run("git", ["rev-parse", "--show-toplevel"], { cwd });
|
|
8
|
+
return stdout.trim();
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new Error(`${cwd} is not inside a git repository`);
|
|
12
|
+
}
|
|
13
|
+
}
|