@kyuki3rain/cupola 0.0.0-stage → 0.2.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 +184 -0
- package/LICENSE +202 -0
- package/README.md +41 -2
- package/dist/adr.js +106 -0
- package/dist/branch-store.js +73 -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 +728 -0
- package/dist/commands/epic.js +311 -0
- package/dist/commands/execution.js +482 -0
- package/dist/commands/install.js +109 -0
- package/dist/commands/locks.js +243 -0
- package/dist/commands/reaction.js +185 -0
- package/dist/commands/revision.js +139 -0
- package/dist/commands/run.js +1021 -0
- package/dist/commands/setup.js +414 -0
- package/dist/commands/spec.js +80 -0
- package/dist/commands/status.js +1457 -0
- package/dist/commands/trace.js +474 -0
- package/dist/commands/wait.js +105 -0
- package/dist/commands/work.js +126 -0
- package/dist/commands/workspace.js +137 -0
- package/dist/commands/worktree.js +422 -0
- package/dist/config.js +353 -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 +379 -0
- package/dist/execution.js +272 -0
- package/dist/feedback.js +20 -0
- package/dist/frontmatter.js +20 -0
- package/dist/git.js +365 -0
- package/dist/host/git.js +224 -0
- package/dist/host/github.js +387 -0
- package/dist/host/host.js +3 -0
- package/dist/host/index.js +63 -0
- package/dist/install.js +182 -0
- package/dist/io.js +46 -0
- package/dist/main.js +866 -0
- package/dist/method/v1.js +56 -0
- package/dist/reaction.js +110 -0
- package/dist/record.js +507 -0
- package/dist/release.js +84 -0
- package/dist/repo.js +13 -0
- package/dist/runbook.js +132 -0
- package/dist/safe-write.js +80 -0
- package/dist/spec.js +171 -0
- package/dist/status.js +321 -0
- package/dist/templates.js +50 -0
- package/dist/trace.js +275 -0
- package/dist/tracker/files.js +99 -0
- package/dist/tracker/github-issues.js +217 -0
- package/dist/tracker/index.js +34 -0
- package/dist/tracker/tracker.js +69 -0
- package/dist/tree.js +59 -0
- package/dist/trust.js +13 -0
- package/dist/version.js +5 -0
- package/dist/work.js +170 -0
- package/dist/workspace.js +324 -0
- package/npm-shrinkwrap.json +2014 -0
- package/package.json +41 -4
- package/skills/cupola-abort/SKILL.md +51 -0
- package/skills/cupola-adr/SKILL.md +54 -0
- package/skills/cupola-ask/SKILL.md +42 -0
- package/skills/cupola-catalog/SKILL.md +41 -0
- package/skills/cupola-catalog-draft/SKILL.md +116 -0
- package/skills/cupola-complete/SKILL.md +107 -0
- package/skills/cupola-decide/SKILL.md +99 -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 +166 -0
- package/skills/cupola-epic-create/SKILL.md +160 -0
- package/skills/cupola-epic-revise/SKILL.md +92 -0
- package/skills/cupola-epic-run/SKILL.md +166 -0
- package/skills/cupola-fix/SKILL.md +117 -0
- package/skills/cupola-init/SKILL.md +143 -0
- package/skills/cupola-intake/SKILL.md +95 -0
- package/skills/cupola-operate/SKILL.md +81 -0
- package/skills/cupola-resolve/SKILL.md +93 -0
- package/skills/cupola-respond/SKILL.md +73 -0
- package/skills/cupola-review/SKILL.md +131 -0
- package/skills/cupola-spec-design/SKILL.md +169 -0
- package/skills/cupola-spec-impl/SKILL.md +137 -0
- package/skills/cupola-spec-run/SKILL.md +137 -0
- package/skills/cupola-steering/SKILL.md +53 -0
- package/skills/cupola-try/SKILL.md +38 -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 +49 -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 +30 -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 +147 -0
- package/templates/method-1/execution.md +55 -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/no-go.md +28 -0
- package/templates/method-1/phase-outcome.json +29 -0
- package/templates/method-1/reaction.md +17 -0
- package/templates/method-1/record.json +63 -0
- package/templates/method-1/report.md +27 -0
- package/templates/method-1/runbook.md +45 -0
- package/templates/method-1/runner-result.json +6 -0
- package/templates/methods.json +13 -0
package/dist/status.js
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { endingCard, pendingNoGos } from "./record.js";
|
|
2
|
+
/** How long ago `since` was, in words: "3 minutes ago"; undefined when it is not a time. */
|
|
3
|
+
export function ago(since, now = new Date()) {
|
|
4
|
+
const at = Date.parse(since);
|
|
5
|
+
if (Number.isNaN(at))
|
|
6
|
+
return undefined;
|
|
7
|
+
const minutes = Math.max(0, Math.floor((now.getTime() - at) / 60_000));
|
|
8
|
+
const [n, unit] = minutes < 1
|
|
9
|
+
? [0, ""]
|
|
10
|
+
: minutes < 60
|
|
11
|
+
? [minutes, "minute"]
|
|
12
|
+
: minutes < 48 * 60
|
|
13
|
+
? [Math.floor(minutes / 60), "hour"]
|
|
14
|
+
: [Math.floor(minutes / (24 * 60)), "day"];
|
|
15
|
+
return n === 0 ? "less than a minute ago" : `${n} ${unit}${n === 1 ? "" : "s"} ago`;
|
|
16
|
+
}
|
|
17
|
+
/** What a person does at acceptance, by how its host lets them reach the change. */
|
|
18
|
+
function acceptanceText(id, reach) {
|
|
19
|
+
const where = reach.reactions
|
|
20
|
+
? `on the change (a review that requests changes is a No-Go) or with \`cupola-decide ${id}\``
|
|
21
|
+
: `with \`cupola-decide ${id}\``;
|
|
22
|
+
return `Read "Needs confirmation" in ${reach.read}, ${reach.merge}, then run the command; or comment, ask for a try, or give a No-Go ${where}.`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A status at a gate (start, acceptance, release) with its reactions: those not processed yet
|
|
26
|
+
* come first — the AI's to process, by a session waiting at the gate or by
|
|
27
|
+
* the command — while the status keeps its name and gate. Tries made, and
|
|
28
|
+
* reactions that could not be read, are told in the text.
|
|
29
|
+
*/
|
|
30
|
+
export function withReactions(r, id, g = {}) {
|
|
31
|
+
const pending = g.reactions ?? [];
|
|
32
|
+
const tries = g.tries ?? [];
|
|
33
|
+
const out = {
|
|
34
|
+
...r,
|
|
35
|
+
...(pending.length > 0 ? { reactions: pending } : {}),
|
|
36
|
+
...(tries.length > 0 ? { tries } : {}),
|
|
37
|
+
...(g.unread ? { unread: g.unread } : {}),
|
|
38
|
+
};
|
|
39
|
+
const told = [
|
|
40
|
+
...(tries.length > 0
|
|
41
|
+
? [
|
|
42
|
+
`Tries built: ${tries.map((n) => `try-${n}`).join(", ")} (compared in the replies; a No-Go naming one takes it in).`,
|
|
43
|
+
]
|
|
44
|
+
: []),
|
|
45
|
+
...(g.unread
|
|
46
|
+
? [
|
|
47
|
+
`Reactions on the change could not be read (${g.unread}), so none given there is processed: give them with \`cupola-decide ${id}\`.`,
|
|
48
|
+
]
|
|
49
|
+
: []),
|
|
50
|
+
];
|
|
51
|
+
if (pending.length > 0) {
|
|
52
|
+
const listed = pending.map((p) => `${p.kind} ${p.id} by ${p.who}`).join(", ");
|
|
53
|
+
return {
|
|
54
|
+
...out,
|
|
55
|
+
turn: "ai",
|
|
56
|
+
next: {
|
|
57
|
+
kind: "run",
|
|
58
|
+
text: [
|
|
59
|
+
`${pending.length} reaction${pending.length === 1 ? "" : "s"} not processed yet (${listed}): a session waiting at this gate processes them; with none waiting, run the command.`,
|
|
60
|
+
...told,
|
|
61
|
+
].join(" "),
|
|
62
|
+
command: `cupola-respond ${id}`,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return told.length > 0
|
|
67
|
+
? { ...out, next: { ...r.next, text: [r.next.text, ...told].join(" ") } }
|
|
68
|
+
: out;
|
|
69
|
+
}
|
|
70
|
+
/** The `ask` of a status listing these open cards: only cards that name someone, and only when any does. */
|
|
71
|
+
export function askOf(cards, open) {
|
|
72
|
+
const ask = cards
|
|
73
|
+
.filter((c) => open.includes(c.card) && (c.ask?.length ?? 0) > 0)
|
|
74
|
+
.map((c) => ({ card: c.card, ask: c.ask ?? [] }));
|
|
75
|
+
return ask.length > 0 ? { ask } : {};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Why a run stopped on something outside the AI's control, while nothing has
|
|
79
|
+
* happened since: the record is not held, its latest event is `blocked`, and
|
|
80
|
+
* the phase it stopped at has not started again (a start, or any outcome
|
|
81
|
+
* after it, clears it). Undefined when it is not blocked.
|
|
82
|
+
*/
|
|
83
|
+
export function blockedBy(record) {
|
|
84
|
+
if (!record || record.active)
|
|
85
|
+
return undefined;
|
|
86
|
+
const last = record.events.at(-1);
|
|
87
|
+
if (last?.what !== "blocked")
|
|
88
|
+
return undefined;
|
|
89
|
+
const at = record.phases.find((p) => p.name === last.phase);
|
|
90
|
+
if (at?.state !== "pending" || at.started)
|
|
91
|
+
return undefined;
|
|
92
|
+
if (record.phases.some((p) => p.finished !== undefined && p.finished > last.at))
|
|
93
|
+
return undefined;
|
|
94
|
+
return { blocker: last.note?.replace(/\.\s*$/, "") || "no reason was given", at: last.at };
|
|
95
|
+
}
|
|
96
|
+
export function deriveStatus({ work, change, reach, record, cards, finished, gate, closedByHand, untidy, waiting, revision, dropped, retake, environment, now, }) {
|
|
97
|
+
const base = { work, change: change ?? null, cards: [], run: null };
|
|
98
|
+
const id = work.id;
|
|
99
|
+
const resume = `cupola-spec-run ${id}`;
|
|
100
|
+
if (change?.state === "merged") {
|
|
101
|
+
const complete = `cupola-complete ${id}`;
|
|
102
|
+
return {
|
|
103
|
+
...base,
|
|
104
|
+
status: "done",
|
|
105
|
+
turn: untidy ? "human" : "none",
|
|
106
|
+
gate: null,
|
|
107
|
+
next: untidy
|
|
108
|
+
? {
|
|
109
|
+
kind: "run",
|
|
110
|
+
text: `Merged: \`${complete}\` tidies up and moves on.`,
|
|
111
|
+
command: complete,
|
|
112
|
+
}
|
|
113
|
+
: { kind: "nothing", text: "Done." },
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (change?.state === "closed" && closedByHand && !dropped) {
|
|
117
|
+
// Closing is no reaction: nothing says whether the spec is to go, or the epic.
|
|
118
|
+
const epic = closedByHand;
|
|
119
|
+
const blocker = `its change was closed by hand, with nothing recorded (${change.url})`;
|
|
120
|
+
return {
|
|
121
|
+
...base,
|
|
122
|
+
status: "blocked",
|
|
123
|
+
turn: "human",
|
|
124
|
+
gate: null,
|
|
125
|
+
blocked: { blocker },
|
|
126
|
+
next: {
|
|
127
|
+
kind: "gate",
|
|
128
|
+
text: `Its change was closed by hand, and nothing records what is to happen. Stop the epic with \`cupola-abort ${epic}\`, drop this spec with a revision (\`cupola-epic-revise ${epic}\`, then its start gate), or reopen the change if closing it was a mistake.`,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (change?.state === "closed") {
|
|
133
|
+
return {
|
|
134
|
+
...base,
|
|
135
|
+
status: "dropped",
|
|
136
|
+
turn: "none",
|
|
137
|
+
gate: null,
|
|
138
|
+
next: { kind: "nothing", text: "Dropped." },
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// Dropped by its epic before anything else: its cards no longer ask anything.
|
|
142
|
+
if (dropped) {
|
|
143
|
+
return {
|
|
144
|
+
...base,
|
|
145
|
+
status: "dropped",
|
|
146
|
+
turn: "none",
|
|
147
|
+
gate: null,
|
|
148
|
+
next: { kind: "nothing", text: `Dropped: ${dropped}.` },
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const unanswered = cards.filter((c) => !c.answered).map((c) => c.card);
|
|
152
|
+
if (unanswered.length > 0) {
|
|
153
|
+
return {
|
|
154
|
+
...base,
|
|
155
|
+
status: "awaiting-decision",
|
|
156
|
+
turn: "human",
|
|
157
|
+
gate: null,
|
|
158
|
+
cards: unanswered,
|
|
159
|
+
...askOf(cards, unanswered),
|
|
160
|
+
next: {
|
|
161
|
+
kind: "gate",
|
|
162
|
+
text: `Answer cards ${unanswered.join(", ")}; the run resumes when the answers are recorded.`,
|
|
163
|
+
command: `cupola-decide ${id}`,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const aiWorking = (run, next) => ({
|
|
168
|
+
...base,
|
|
169
|
+
status: "ai-working",
|
|
170
|
+
turn: "ai",
|
|
171
|
+
gate: null,
|
|
172
|
+
run,
|
|
173
|
+
next,
|
|
174
|
+
});
|
|
175
|
+
// A No-Go processed at acceptance is a card written before the change goes back to draft; the run
|
|
176
|
+
// resumes from it. The run removes its directory, cards included, before acceptance, so a
|
|
177
|
+
// card found without a record is a No-Go written after that.
|
|
178
|
+
const noGos = pendingNoGos(record, cards);
|
|
179
|
+
if (noGos.length > 0) {
|
|
180
|
+
return aiWorking({ phase: null, active: null }, {
|
|
181
|
+
kind: "run",
|
|
182
|
+
text: `No-Go (card ${noGos.map((c) => c.card).join(", ")}): the run goes back to ${noGos.map((c) => c.redo).join(", ")}; resume it.`,
|
|
183
|
+
command: resume,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
// An answer that ends the run is carried out by the dialogue that recorded it.
|
|
187
|
+
const ending = endingCard(record, cards);
|
|
188
|
+
if (ending) {
|
|
189
|
+
return aiWorking({ phase: null, active: null }, {
|
|
190
|
+
kind: "run",
|
|
191
|
+
text: `Card ${ending.card} chose ${ending.effect}, which is not carried out yet.`,
|
|
192
|
+
command: `cupola-decide ${id}`,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// A revision under agreement plans to change it: it waits, even at acceptance, for a human to agree
|
|
196
|
+
// the revision (its start gate) by merging the epic's change.
|
|
197
|
+
if (revision && !record?.active) {
|
|
198
|
+
const where = revision.url ? ` (${revision.url})` : "";
|
|
199
|
+
return {
|
|
200
|
+
...base,
|
|
201
|
+
status: "waiting",
|
|
202
|
+
turn: "human",
|
|
203
|
+
gate: null,
|
|
204
|
+
run: null,
|
|
205
|
+
next: {
|
|
206
|
+
kind: "gate",
|
|
207
|
+
text: `${revision.text}. Read the revision of ${revision.epic} and merge its change to agree${where}; the epic's run then takes it in.`,
|
|
208
|
+
command: `cupola-epic-run ${revision.epic}`,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
if (retake) {
|
|
213
|
+
return {
|
|
214
|
+
...base,
|
|
215
|
+
status: "ai-working",
|
|
216
|
+
turn: "ai",
|
|
217
|
+
gate: null,
|
|
218
|
+
next: { kind: "run", text: retake.text, command: retake.command },
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (change?.state === "open" && !change.draft && !record) {
|
|
222
|
+
return withReactions({
|
|
223
|
+
...base,
|
|
224
|
+
status: "awaiting-acceptance",
|
|
225
|
+
turn: "human",
|
|
226
|
+
gate: "acceptance",
|
|
227
|
+
next: {
|
|
228
|
+
kind: "gate",
|
|
229
|
+
text: acceptanceText(id, reach ?? { read: change.url, merge: "merge it", reactions: true }),
|
|
230
|
+
command: `cupola-complete ${id}`,
|
|
231
|
+
},
|
|
232
|
+
}, id, gate);
|
|
233
|
+
}
|
|
234
|
+
const phase = record?.phases.find((p) => p.state === "running")?.name ??
|
|
235
|
+
record?.phases.find((p) => p.state === "pending" || p.state === "redo")?.name ??
|
|
236
|
+
null;
|
|
237
|
+
const active = record?.active
|
|
238
|
+
? {
|
|
239
|
+
id: record.active.id,
|
|
240
|
+
who: record.active.who,
|
|
241
|
+
session: record.active.session,
|
|
242
|
+
since: record.active.since,
|
|
243
|
+
}
|
|
244
|
+
: null;
|
|
245
|
+
const run = { phase, active };
|
|
246
|
+
if (active) {
|
|
247
|
+
const started = ago(active.since, now);
|
|
248
|
+
// A work its epic runs is taken over through the epic's run, by the session that held it.
|
|
249
|
+
const takeOver = work.epic
|
|
250
|
+
? `cupola-epic-run ${work.epic} --take-over ${active.session}`
|
|
251
|
+
: `${resume} --take-over ${active.id}`;
|
|
252
|
+
return aiWorking(run, {
|
|
253
|
+
kind: "nothing",
|
|
254
|
+
text: `Running ${phase ?? "its last steps"}: ${active.who} started it in session ${active.session}` +
|
|
255
|
+
`${started ? `, ${started}` : ""} (${active.since}). ` +
|
|
256
|
+
`If that session is gone, take the run over with \`${takeOver}\`.`,
|
|
257
|
+
command: takeOver,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
if (!record && finished) {
|
|
261
|
+
return aiWorking(run, {
|
|
262
|
+
kind: "run",
|
|
263
|
+
text: "The finish was interrupted; run again to finish.",
|
|
264
|
+
command: resume,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const blocked = blockedBy(record);
|
|
268
|
+
if (blocked) {
|
|
269
|
+
return {
|
|
270
|
+
...base,
|
|
271
|
+
status: "blocked",
|
|
272
|
+
turn: "human",
|
|
273
|
+
gate: null,
|
|
274
|
+
run,
|
|
275
|
+
blocked,
|
|
276
|
+
next: {
|
|
277
|
+
kind: "run",
|
|
278
|
+
text: `Blocked at ${phase ?? "its last steps"}: ${blocked.blocker}. Fix that, then resume the run.`,
|
|
279
|
+
command: resume,
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
if (environment) {
|
|
284
|
+
return {
|
|
285
|
+
...base,
|
|
286
|
+
status: "waiting",
|
|
287
|
+
turn: "ai",
|
|
288
|
+
gate: null,
|
|
289
|
+
run,
|
|
290
|
+
next: {
|
|
291
|
+
kind: "nothing",
|
|
292
|
+
text: `It waits: ${environment}. Run it again once that is released.`,
|
|
293
|
+
command: resume,
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
if (phase === "design" && waiting && waiting.for.length > 0) {
|
|
298
|
+
return {
|
|
299
|
+
...base,
|
|
300
|
+
status: "waiting",
|
|
301
|
+
turn: "ai",
|
|
302
|
+
gate: null,
|
|
303
|
+
run,
|
|
304
|
+
next: {
|
|
305
|
+
kind: "nothing",
|
|
306
|
+
text: `Its design waits for the design of ${waiting.for.join(", ")}; the epic's run starts it then.`,
|
|
307
|
+
command: waiting.resume,
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
if (!record)
|
|
312
|
+
return aiWorking(run, { kind: "run", text: "Start the run.", command: resume });
|
|
313
|
+
if (!phase) {
|
|
314
|
+
return aiWorking(run, {
|
|
315
|
+
kind: "run",
|
|
316
|
+
text: "Every phase is done; the run finishes the work (looks back, removes the record, marks the change ready).",
|
|
317
|
+
command: resume,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
return aiWorking(run, { kind: "run", text: `Resume the run at ${phase}.`, command: resume });
|
|
321
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
"no-go",
|
|
9
|
+
"reaction",
|
|
10
|
+
"case-draft",
|
|
11
|
+
"cupola-issue-draft",
|
|
12
|
+
"phase-outcome",
|
|
13
|
+
"changes/catalog",
|
|
14
|
+
"changes/fix",
|
|
15
|
+
"changes/spec",
|
|
16
|
+
"changes/release",
|
|
17
|
+
];
|
|
18
|
+
function methodDir(method) {
|
|
19
|
+
return fileURLToPath(new URL(`../templates/method-${method}/`, import.meta.url));
|
|
20
|
+
}
|
|
21
|
+
/** Every template a method serves, by kind: `card`, `changes/catalog`, … */
|
|
22
|
+
export function templateKinds(method = METHOD) {
|
|
23
|
+
const dir = methodDir(method);
|
|
24
|
+
const kinds = new Map();
|
|
25
|
+
for (const entry of readdirSync(dir, { recursive: true, withFileTypes: true })) {
|
|
26
|
+
if (!entry.isFile())
|
|
27
|
+
continue;
|
|
28
|
+
const full = join(entry.parentPath, entry.name);
|
|
29
|
+
const rel = full.slice(dir.length).replaceAll("\\", "/");
|
|
30
|
+
kinds.set(rel.replace(/\.(md|json)$/, ""), full);
|
|
31
|
+
}
|
|
32
|
+
// The steering a project owns, for the dialogue that writes or grows it (cupola-steering).
|
|
33
|
+
const steering = fileURLToPath(new URL("../templates/install/.kiro/steering/", import.meta.url));
|
|
34
|
+
for (const name of ["operations", "principles", "e2e"]) {
|
|
35
|
+
kinds.set(`steering/${name}`, join(steering, `${name}.md`));
|
|
36
|
+
}
|
|
37
|
+
return kinds;
|
|
38
|
+
}
|
|
39
|
+
export function templatePath(kind, method = METHOD) {
|
|
40
|
+
const kinds = templateKinds(method);
|
|
41
|
+
const path = kinds.get(kind);
|
|
42
|
+
if (!path) {
|
|
43
|
+
const known = [...kinds.keys()].sort().join(", ");
|
|
44
|
+
throw new Error(`no template ${kind} in method ${method}; known: ${known}`);
|
|
45
|
+
}
|
|
46
|
+
return path;
|
|
47
|
+
}
|
|
48
|
+
export function runTemplates(method = METHOD) {
|
|
49
|
+
return Object.fromEntries(RUN_TEMPLATES.map((t) => [t, templatePath(t, method)]));
|
|
50
|
+
}
|
package/dist/trace.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { glob, readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { XMLParser } from "fast-xml-parser";
|
|
5
|
+
import { git, gitRaw } from "./git.js";
|
|
6
|
+
const REF = /@req\s+([a-z0-9-]+\.[a-z0-9-]+|[a-z0-9-]+#[A-Z]+[0-9]+(?:\.[ag][0-9]+)?)/g;
|
|
7
|
+
const TEST_NAME = [
|
|
8
|
+
/\b(?:it|test|specify|scenario|t\.Run)\s*(?:\.\w+\s*)?\(\s*(["'`])(.+?)\1/, // JS/TS, Go subtests
|
|
9
|
+
/\bdef\s+(test_\w+)/, // Python
|
|
10
|
+
/\bfunc\s+(Test\w+)/, // Go
|
|
11
|
+
/\bfn\s+(\w+)\s*\(/, // Rust (after #[test])
|
|
12
|
+
/\bfun\s+`?([^`(]+?)`?\s*\(/, // Kotlin
|
|
13
|
+
/\bvoid\s+(\w+)\s*\(/, // JVM
|
|
14
|
+
];
|
|
15
|
+
function testName(line) {
|
|
16
|
+
for (const re of TEST_NAME) {
|
|
17
|
+
const m = re.exec(line);
|
|
18
|
+
if (m)
|
|
19
|
+
return m[2] ?? m[1];
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Finds `@req` markers in tracked text files with `git grep`, so a large
|
|
25
|
+
* repository is not read file by file. A marker scopes to the test on its own
|
|
26
|
+
* line, or to the next test declared within a few lines below it.
|
|
27
|
+
*/
|
|
28
|
+
export async function findMarkers(root, exclude = [],
|
|
29
|
+
/** A commit to read instead of the working tree. */
|
|
30
|
+
at) {
|
|
31
|
+
let out;
|
|
32
|
+
try {
|
|
33
|
+
out = await git(root, [
|
|
34
|
+
"grep",
|
|
35
|
+
"-n",
|
|
36
|
+
"-o",
|
|
37
|
+
"-I",
|
|
38
|
+
"-z",
|
|
39
|
+
"-E",
|
|
40
|
+
"@req[[:space:]]",
|
|
41
|
+
...(at ? [at] : []),
|
|
42
|
+
"--",
|
|
43
|
+
":!*.md",
|
|
44
|
+
// Cupola's own records; the acceptance checks under `.cupola/` carry markers too.
|
|
45
|
+
":!.cupola/runs/",
|
|
46
|
+
":!.cupola/work/",
|
|
47
|
+
":!.cupola/*.json",
|
|
48
|
+
...exclude.map((d) => `:!${d}/`),
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error.code === 1)
|
|
53
|
+
return []; // no matches
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
const byFile = new Map(); // -o prints a line once per match
|
|
57
|
+
for (const line of out.split("\n")) {
|
|
58
|
+
const [named, lineNo] = line.split("\0");
|
|
59
|
+
// At a commit, git grep names each file `<commit>:<path>`.
|
|
60
|
+
const file = at && named?.startsWith(`${at}:`) ? named.slice(at.length + 1) : named;
|
|
61
|
+
if (!file || !lineNo)
|
|
62
|
+
continue;
|
|
63
|
+
byFile.set(file, (byFile.get(file) ?? new Set()).add(Number(lineNo)));
|
|
64
|
+
}
|
|
65
|
+
const markers = [];
|
|
66
|
+
for (const [file, numbers] of byFile) {
|
|
67
|
+
const text = at
|
|
68
|
+
? await gitRaw(root, ["show", `${at}:${file}`])
|
|
69
|
+
: await readFile(join(root, file), "utf8");
|
|
70
|
+
const lines = text.split(/\r?\n/);
|
|
71
|
+
for (const n of numbers) {
|
|
72
|
+
const line = lines[n - 1] ?? "";
|
|
73
|
+
for (const m of line.matchAll(REF)) {
|
|
74
|
+
let test = testName(line);
|
|
75
|
+
for (let j = n; !test && j < Math.min(lines.length, n + 5); j++)
|
|
76
|
+
test = testName(lines[j] ?? "");
|
|
77
|
+
markers.push({ ref: m[1] ?? "", file, line: n, test });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return markers;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The markers of a checkout and of the code mounted in it (`documents: "hub"`): each mounted
|
|
85
|
+
* repository is grepped on its own, its
|
|
86
|
+
* files named from the hub's root (`<clone>/<path>`). With `at`, the hub is
|
|
87
|
+
* read at that commit and each mounted repository at the commit `codeAt`
|
|
88
|
+
* gives it; a repository it gives none is skipped.
|
|
89
|
+
*/
|
|
90
|
+
export async function findAllMarkers(root, mounts, exclude = [], at) {
|
|
91
|
+
const out = await findMarkers(root, exclude, at?.hub);
|
|
92
|
+
for (const mount of mounts) {
|
|
93
|
+
const source = typeof mount === "string" ? { dir: mount, path: join(root, mount) } : mount;
|
|
94
|
+
const { dir, path } = source;
|
|
95
|
+
if (!existsSync(join(path, ".git")))
|
|
96
|
+
continue;
|
|
97
|
+
const commit = at ? await at.codeAt(dir) : source.ref;
|
|
98
|
+
if (at && !commit)
|
|
99
|
+
continue;
|
|
100
|
+
for (const m of await findMarkers(path, [], commit))
|
|
101
|
+
out.push({ ...m, file: `${dir}/${m.file}` });
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
/** Test results from JUnit XML reports matching the configured globs. Unreadable reports are skipped. */
|
|
106
|
+
export async function readReports(root, patterns,
|
|
107
|
+
/** Top-level directories not to look in: the other repositories cloned under the hub. */
|
|
108
|
+
skip = []) {
|
|
109
|
+
const parser = new XMLParser({
|
|
110
|
+
ignoreAttributes: false,
|
|
111
|
+
attributeNamePrefix: "",
|
|
112
|
+
isArray: (n) => n === "testcase" || n === "testsuite",
|
|
113
|
+
});
|
|
114
|
+
const results = [];
|
|
115
|
+
const warnings = [];
|
|
116
|
+
for (const pattern of patterns) {
|
|
117
|
+
const exclude = (f) => skip.some((d) => f === d || f.startsWith(`${d}/`));
|
|
118
|
+
for await (const file of glob(pattern, { cwd: root, exclude })) {
|
|
119
|
+
if (exclude(file))
|
|
120
|
+
continue;
|
|
121
|
+
let xml;
|
|
122
|
+
try {
|
|
123
|
+
xml = parser.parse(await readFile(join(root, file), "utf8"), true);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
warnings.push(`${file}: not readable as JUnit XML (${error.message.split("\n")[0]})`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const walk = (node, suiteFile) => {
|
|
130
|
+
if (!node || typeof node !== "object")
|
|
131
|
+
return;
|
|
132
|
+
const n = node;
|
|
133
|
+
const here = typeof n.file === "string" ? n.file : suiteFile;
|
|
134
|
+
if (Array.isArray(n.testcase)) {
|
|
135
|
+
for (const c of n.testcase) {
|
|
136
|
+
const result = "failure" in c || "error" in c ? "failed" : "skipped" in c ? "skipped" : "passed";
|
|
137
|
+
results.push({
|
|
138
|
+
name: String(c.name ?? ""),
|
|
139
|
+
file: typeof c.file === "string" ? c.file : here,
|
|
140
|
+
classname: typeof c.classname === "string" ? c.classname : undefined,
|
|
141
|
+
result,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
for (const key of ["testsuites", "testsuite"]) {
|
|
146
|
+
const child = n[key];
|
|
147
|
+
if (Array.isArray(child))
|
|
148
|
+
for (const c of child)
|
|
149
|
+
walk(c, here);
|
|
150
|
+
else
|
|
151
|
+
walk(child, here);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
walk(xml, undefined);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { results, warnings };
|
|
158
|
+
}
|
|
159
|
+
function sameTest(name, test) {
|
|
160
|
+
return (name === test ||
|
|
161
|
+
name.endsWith(` > ${test}`) || // vitest; jest-junit with ancestorSeparator " > "
|
|
162
|
+
name.endsWith(` › ${test}`) ||
|
|
163
|
+
name.startsWith(`${test}[`) || // pytest parameters
|
|
164
|
+
name.startsWith(`${test}/`) || // a Go test with subtests
|
|
165
|
+
name.endsWith(`/${test.replaceAll(" ", "_")}`) // a Go subtest, from t.Run
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
const slashes = (path) => path.replaceAll("\\", "/");
|
|
169
|
+
/** Whether two repository paths name the same file, one possibly relative to a subdirectory. */
|
|
170
|
+
function samePath(a, b) {
|
|
171
|
+
return a === b || a.endsWith(`/${b}`) || b.endsWith(`/${a}`);
|
|
172
|
+
}
|
|
173
|
+
/** Whether a result comes from the marker's file, judged by whatever the report gives. */
|
|
174
|
+
function sameFile(marker, r) {
|
|
175
|
+
if (r.file)
|
|
176
|
+
return samePath(slashes(r.file), marker.file);
|
|
177
|
+
const cls = r.classname ? slashes(r.classname).replace(/\$.*$/, "") : undefined;
|
|
178
|
+
if (!cls)
|
|
179
|
+
return undefined;
|
|
180
|
+
const ext = /\.[A-Za-z0-9]+$/.exec(marker.file)?.[0];
|
|
181
|
+
if (ext && cls.endsWith(ext))
|
|
182
|
+
return samePath(cls, marker.file); // a file path: vitest, jest
|
|
183
|
+
if (cls.includes("/")) {
|
|
184
|
+
// a package path: go-junit-report
|
|
185
|
+
const dir = marker.file.split("/").slice(0, -1).join("/");
|
|
186
|
+
if (dir === "")
|
|
187
|
+
return undefined; // the module's root package: nothing to compare
|
|
188
|
+
return samePath(cls, dir) || dir.split("/").at(-1) === cls.split("/").at(-1);
|
|
189
|
+
}
|
|
190
|
+
if (cls.includes(".")) {
|
|
191
|
+
// a dotted module, possibly followed by classes: pytest, surefire
|
|
192
|
+
const dotted = marker.file.replace(/\.[^./]+$/, "").replaceAll("/", ".");
|
|
193
|
+
const parts = cls.split(".");
|
|
194
|
+
for (let k = 0; k < Math.min(3, parts.length - 1) + 1; k++) {
|
|
195
|
+
const c = parts.slice(0, parts.length - k).join(".");
|
|
196
|
+
if (c === dotted || dotted.endsWith(`.${c}`))
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
// A bare name, such as pytest's module at the root: it can only be the file's own name.
|
|
202
|
+
const stem = marker.file
|
|
203
|
+
.split("/")
|
|
204
|
+
.at(-1)
|
|
205
|
+
?.replace(/\.[^.]+$/, "");
|
|
206
|
+
return cls === stem ? true : undefined;
|
|
207
|
+
}
|
|
208
|
+
function matches(marker, r, results) {
|
|
209
|
+
if (!marker.test || !sameTest(r.name, marker.test))
|
|
210
|
+
return false;
|
|
211
|
+
const file = sameFile(marker, r);
|
|
212
|
+
if (file !== undefined)
|
|
213
|
+
return file;
|
|
214
|
+
// No file to go by: accept the name only when no other test result shares it.
|
|
215
|
+
return results.filter((x) => sameTest(x.name, marker.test)).length === 1;
|
|
216
|
+
}
|
|
217
|
+
/** The epic references a catalog entry answers to, through its `origin: epic <id> <ref>`. */
|
|
218
|
+
function epicRefsOf(origin, epics) {
|
|
219
|
+
const m = /^epic\s+(\S+)\s+(\S+)$/.exec(origin?.trim() ?? "");
|
|
220
|
+
if (!m)
|
|
221
|
+
return [];
|
|
222
|
+
const [, epic = "", ref = ""] = m;
|
|
223
|
+
return [ref, ...(epics.get(epic)?.get(ref) ?? [])].map((r) => `${epic}#${r}`);
|
|
224
|
+
}
|
|
225
|
+
export function buildTrace(areas, markers, results, warnings = [], epics = new Map()) {
|
|
226
|
+
const ids = new Set(areas.flatMap((a) => a.entries.map((e) => e.id)));
|
|
227
|
+
const entries = areas.flatMap((a) => a.entries.map((e) => {
|
|
228
|
+
const refs = new Set([e.id, ...epicRefsOf(e.origin, epics)]);
|
|
229
|
+
const tests = markers
|
|
230
|
+
.filter((m) => refs.has(m.ref))
|
|
231
|
+
.map((m) => {
|
|
232
|
+
const found = results.filter((r) => matches(m, r, results));
|
|
233
|
+
const result = found.some((r) => r.result === "failed")
|
|
234
|
+
? "failed"
|
|
235
|
+
: found.some((r) => r.result === "passed")
|
|
236
|
+
? "passed"
|
|
237
|
+
: found.length > 0
|
|
238
|
+
? "skipped"
|
|
239
|
+
: null;
|
|
240
|
+
return { file: m.file, line: m.line, test: m.test, result };
|
|
241
|
+
});
|
|
242
|
+
let status;
|
|
243
|
+
if (tests.length === 0) {
|
|
244
|
+
status = e.verified?.startsWith("manual")
|
|
245
|
+
? "manual"
|
|
246
|
+
: e.verified?.startsWith("untestable")
|
|
247
|
+
? "untestable"
|
|
248
|
+
: "unverified";
|
|
249
|
+
}
|
|
250
|
+
else if (tests.some((t) => t.result === "failed"))
|
|
251
|
+
status = "failing";
|
|
252
|
+
else if (tests.some((t) => t.result === "passed"))
|
|
253
|
+
status = "passing";
|
|
254
|
+
else
|
|
255
|
+
status = "no-result";
|
|
256
|
+
return {
|
|
257
|
+
id: e.id,
|
|
258
|
+
area: a.area,
|
|
259
|
+
component: a.component,
|
|
260
|
+
path: a.path,
|
|
261
|
+
line: e.line,
|
|
262
|
+
origin: e.origin,
|
|
263
|
+
verified: e.verified,
|
|
264
|
+
mark: e.mark,
|
|
265
|
+
tests,
|
|
266
|
+
status,
|
|
267
|
+
};
|
|
268
|
+
}));
|
|
269
|
+
return {
|
|
270
|
+
entries,
|
|
271
|
+
warnings,
|
|
272
|
+
orphans: markers.filter((m) => !m.ref.includes("#") && !ids.has(m.ref)),
|
|
273
|
+
epicRefs: markers.filter((m) => m.ref.includes("#")),
|
|
274
|
+
};
|
|
275
|
+
}
|