@kyuki3rain/cupola 0.1.0 → 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.
Files changed (84) hide show
  1. package/CHANGELOG.md +158 -0
  2. package/README.md +3 -2
  3. package/dist/branch-store.js +73 -0
  4. package/dist/commands/change.js +245 -39
  5. package/dist/commands/epic.js +3 -3
  6. package/dist/commands/execution.js +482 -0
  7. package/dist/commands/locks.js +69 -1
  8. package/dist/commands/reaction.js +185 -0
  9. package/dist/commands/revision.js +4 -4
  10. package/dist/commands/run.js +68 -62
  11. package/dist/commands/setup.js +54 -22
  12. package/dist/commands/spec.js +1 -1
  13. package/dist/commands/status.js +437 -138
  14. package/dist/commands/trace.js +106 -29
  15. package/dist/commands/wait.js +14 -11
  16. package/dist/commands/work.js +12 -7
  17. package/dist/commands/workspace.js +16 -5
  18. package/dist/commands/worktree.js +3 -3
  19. package/dist/config.js +66 -2
  20. package/dist/epic.js +24 -5
  21. package/dist/execution.js +272 -0
  22. package/dist/feedback.js +3 -17
  23. package/dist/host/git.js +224 -0
  24. package/dist/host/github.js +145 -48
  25. package/dist/host/host.js +3 -1
  26. package/dist/host/index.js +63 -0
  27. package/dist/main.js +143 -48
  28. package/dist/reaction.js +110 -0
  29. package/dist/record.js +52 -18
  30. package/dist/runbook.js +26 -5
  31. package/dist/status.js +158 -27
  32. package/dist/templates.js +2 -1
  33. package/dist/tracker/files.js +9 -66
  34. package/dist/tracker/index.js +8 -1
  35. package/dist/tree.js +17 -0
  36. package/dist/work.js +27 -6
  37. package/dist/workspace.js +37 -12
  38. package/npm-shrinkwrap.json +2 -2
  39. package/package.json +1 -1
  40. package/skills/cupola-abort/SKILL.md +11 -5
  41. package/skills/cupola-adr/SKILL.md +23 -10
  42. package/skills/cupola-catalog/SKILL.md +1 -1
  43. package/skills/cupola-catalog-draft/SKILL.md +6 -4
  44. package/skills/cupola-complete/SKILL.md +35 -15
  45. package/skills/cupola-decide/SKILL.md +64 -25
  46. package/skills/cupola-e2e-setup/SKILL.md +1 -1
  47. package/skills/cupola-epic-accept/SKILL.md +14 -10
  48. package/skills/cupola-epic-create/SKILL.md +67 -27
  49. package/skills/cupola-epic-revise/SKILL.md +39 -18
  50. package/skills/cupola-epic-run/SKILL.md +81 -42
  51. package/skills/cupola-fix/SKILL.md +7 -5
  52. package/skills/cupola-init/SKILL.md +79 -24
  53. package/skills/cupola-intake/SKILL.md +19 -2
  54. package/skills/cupola-operate/SKILL.md +62 -45
  55. package/skills/cupola-resolve/SKILL.md +21 -14
  56. package/skills/cupola-respond/SKILL.md +73 -0
  57. package/skills/cupola-review/SKILL.md +14 -15
  58. package/skills/cupola-spec-design/SKILL.md +15 -10
  59. package/skills/cupola-spec-impl/SKILL.md +6 -4
  60. package/skills/cupola-spec-run/SKILL.md +29 -17
  61. package/skills/cupola-steering/SKILL.md +13 -6
  62. package/skills/cupola-try/SKILL.md +38 -0
  63. package/templates/install/.kiro/steering/operations.md +2 -2
  64. package/templates/install/.kiro/steering/principles.md +1 -1
  65. package/templates/install/cc-sdd/patches.json +1 -1
  66. package/templates/method-1/card.md +11 -3
  67. package/templates/method-1/case.md +2 -2
  68. package/templates/method-1/changes/catalog.md +1 -1
  69. package/templates/method-1/changes/epic.md +3 -2
  70. package/templates/method-1/changes/fix.md +1 -1
  71. package/templates/method-1/changes/release.md +1 -1
  72. package/templates/method-1/changes/spec.md +1 -1
  73. package/templates/method-1/cupola-issue-draft.md +1 -1
  74. package/templates/method-1/epic.md +17 -6
  75. package/templates/method-1/execution.md +55 -0
  76. package/templates/method-1/no-go.md +28 -0
  77. package/templates/method-1/reaction.md +17 -0
  78. package/templates/method-1/record.json +3 -3
  79. package/templates/method-1/report.md +3 -3
  80. package/templates/method-1/runbook.md +8 -2
  81. package/templates/method-1/runner-result.json +1 -1
  82. package/dist/commands/procedure.js +0 -92
  83. package/dist/procedure.js +0 -60
  84. package/templates/method-1/send-back.md +0 -23
@@ -0,0 +1,185 @@
1
+ import { existsSync } from "node:fs";
2
+ import { readFile, rm } from "node:fs/promises";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { loadConfig } from "../config.js";
5
+ import { commitPaths, git, gitUserEmail, workBranch } from "../git.js";
6
+ import { gateComments, hostReactions, REACTION_KINDS, reactionFile, reactionsDir, SESSION, sessionReactions, triesOf, tryBranch, } from "../reaction.js";
7
+ import { repoRoot } from "../repo.js";
8
+ import { assertInsideRepository, writeInside } from "../safe-write.js";
9
+ import { fsTree } from "../tree.js";
10
+ import { runsOn, workBranchName } from "../work.js";
11
+ import { openChangeOf, readBody } from "./change.js";
12
+ import { addWorktree, existingWorktree } from "./worktree.js";
13
+ /** Every reaction of the work in this checkout: on its open changes, and given in a session. */
14
+ async function gather(io, id) {
15
+ const { root, all } = await openChangeOf(io, id);
16
+ const config = await loadConfig(root);
17
+ const where = new Map();
18
+ const reactions = [];
19
+ const unread = [];
20
+ for (const c of all) {
21
+ const got = await hostReactions(c.host, c.change, config);
22
+ if (got.unread)
23
+ unread.push(`${c.change.url}: ${got.unread}`);
24
+ for (const r of got.reactions) {
25
+ where.set(r.id, c);
26
+ reactions.push({ ...r, from: "host" });
27
+ }
28
+ }
29
+ for (const r of await sessionReactions(fsTree(root), id))
30
+ reactions.push({ ...r, from: "session" });
31
+ reactions.sort((a, b) => a.at.localeCompare(b.at));
32
+ return { root, reactions, where, unread };
33
+ }
34
+ /**
35
+ * `cupola reaction list <work>`: the reactions of the work's gate, oldest
36
+ * first, from its changes and from sessions: each with whether it is
37
+ * answered, and `gate` for the comments a No-Go takes in (those given since
38
+ * the last No-Go was processed). `pending` lists the ones not processed yet.
39
+ */
40
+ export async function reactionList(io, id, opts) {
41
+ const { root, reactions, unread } = await gather(io, id);
42
+ const taken = new Set(gateComments(reactions).map((r) => r.id));
43
+ const shown = reactions.map((r) => ({
44
+ id: r.id,
45
+ kind: r.kind,
46
+ who: r.author,
47
+ at: r.at,
48
+ body: r.body,
49
+ place: r.place,
50
+ answered: r.answered,
51
+ from: r.from,
52
+ ...(taken.has(r.id) ? { gate: true } : {}),
53
+ }));
54
+ const pending = shown.filter((r) => !r.answered).map((r) => r.id);
55
+ const tries = await triesOf(root, id);
56
+ if (opts.json) {
57
+ io.out(JSON.stringify({ reactions: shown, pending, tries, ...(unread.length ? { unread } : {}) }));
58
+ return 0;
59
+ }
60
+ io.out(`${pending.length} not processed${tries.length ? `; tries: ${tries.join(", ")}` : ""}`);
61
+ for (const r of shown)
62
+ io.out(` ${r.id} ${r.kind} by ${r.who}${r.answered ? " (answered)" : ""}: ${r.body.split("\n")[0] ?? ""}`);
63
+ for (const u of unread)
64
+ io.out(` not read: ${u}`);
65
+ return 0;
66
+ }
67
+ /**
68
+ * `cupola reaction reply <work> --reaction <id> --body-file <f>`: answers a
69
+ * reaction, which processes it. On the change, the reply goes there; a
70
+ * session's reaction has its file removed (the reply is the session's report).
71
+ */
72
+ export async function reactionReply(io, id, opts) {
73
+ if (!opts.reaction)
74
+ throw new Error("give the reaction to answer: --reaction <id>");
75
+ if (opts.reaction.startsWith(SESSION)) {
76
+ const root = await repoRoot(io.cwd);
77
+ const branch = await workBranch(root);
78
+ if (!runsOn(branch, id))
79
+ throw new Error(`${id} is on ${workBranchName(id)}, but this checkout is on ${branch}`);
80
+ const n = opts.reaction.slice(SESSION.length);
81
+ const file = join(reactionsDir(id), `${n}.md`);
82
+ if (!/^\d+$/.test(n) || !existsSync(join(root, file)))
83
+ throw new Error(`no reaction ${opts.reaction} of ${id} waits in this checkout`);
84
+ await rm(assertInsideRepository(root, file));
85
+ await commitPaths(root, branch, [file], `cupola: ${id}: reaction ${n} processed`);
86
+ io.out(opts.json ? JSON.stringify({ answered: opts.reaction }) : `processed ${opts.reaction}`);
87
+ return 0;
88
+ }
89
+ if (!opts.bodyFile)
90
+ throw new Error("give the reply: --body-file <file>");
91
+ const body = await readBody(io.cwd, opts.bodyFile);
92
+ const { reactions, where } = await gather(io, id);
93
+ const r = reactions.find((x) => x.id === opts.reaction);
94
+ const c = where.get(opts.reaction);
95
+ if (!r || !c)
96
+ throw new Error(`no reaction ${opts.reaction} on the changes of ${id}`);
97
+ await c.host.reply(c.change.number, r.id, body);
98
+ io.out(opts.json ? JSON.stringify({ answered: r.id }) : `answered ${r.id}`);
99
+ return 0;
100
+ }
101
+ /**
102
+ * `cupola reaction add <work> --kind comment|try|no-go [--body-file <f>] [--who <name>]`:
103
+ * keeps a reaction given in a session outside a gate (or to a work whose host
104
+ * takes none) for the next gate, as a file on the work's branch.
105
+ */
106
+ export async function reactionAdd(io, id, opts) {
107
+ const kind = (opts.kind ?? "");
108
+ if (!REACTION_KINDS.includes(kind))
109
+ throw new Error(`give its kind: --kind ${REACTION_KINDS.join("|")}`);
110
+ if (!opts.bodyFile && kind !== "no-go")
111
+ throw new Error("give its words: --body-file <file>");
112
+ const body = opts.bodyFile ? await readFile(resolve(io.cwd, opts.bodyFile), "utf8") : "";
113
+ if (body.includes("{{"))
114
+ throw new Error(`${opts.bodyFile} still has template placeholders`);
115
+ const root = await repoRoot(io.cwd);
116
+ const branch = await workBranch(root);
117
+ if (!runsOn(branch, id))
118
+ throw new Error(`${id} is on ${workBranchName(id)}, but this checkout is on ${branch}`);
119
+ const dir = reactionsDir(id);
120
+ const taken = (await fsTree(root).list(dir))
121
+ .map((f) => Number(/^(\d+)\.md$/.exec(f)?.[1] ?? 0))
122
+ .filter((n) => n > 0);
123
+ // Numbers are never reused while the branch remembers them: a processed one is gone from the
124
+ // directory, but not from its history.
125
+ const history = await git(root, [
126
+ "log",
127
+ "--format=%s",
128
+ "--fixed-strings",
129
+ `--grep=cupola: ${id}: reaction `,
130
+ ]);
131
+ const used = [...history.matchAll(/reaction (\d+)/g)].map((m) => Number(m[1]));
132
+ const n = Math.max(0, ...taken, ...used) + 1;
133
+ const who = opts.who ?? (await gitUserEmail(root));
134
+ const at = (io.now?.() ?? new Date()).toISOString();
135
+ const file = join(dir, `${n}.md`);
136
+ await writeInside(root, file, reactionFile(n, kind, who, at, body));
137
+ await commitPaths(root, branch, [file], `cupola: ${id}: reaction ${n} kept for the gate`);
138
+ const out = { reaction: `${SESSION}${n}`, kind, who, at, file };
139
+ io.out(opts.json ? JSON.stringify(out) : `kept ${out.reaction} (${kind}) for the next gate`);
140
+ return 0;
141
+ }
142
+ /**
143
+ * `cupola try start <work>`: a try of the work in this checkout — the next
144
+ * try branch, from the head of its change, pushed, in a worktree next to this
145
+ * one. The work and its status do not change.
146
+ */
147
+ export async function tryStart(io, id, opts) {
148
+ const root = await repoRoot(io.cwd);
149
+ const branch = await workBranch(root);
150
+ if (!runsOn(branch, id))
151
+ throw new Error(`${id} is on ${workBranchName(id)}, but this checkout is on ${branch}`);
152
+ await git(root, [
153
+ "fetch",
154
+ "--quiet",
155
+ "origin",
156
+ `+refs/heads/${branch}:refs/remotes/origin/${branch}`,
157
+ ]);
158
+ const n = Math.max(0, ...(await triesOf(root, id))) + 1;
159
+ const name = tryBranch(id, n);
160
+ const path = join(dirname(root), `${id}-try-${n}`);
161
+ await addWorktree(root, path, name, { from: `origin/${branch}` });
162
+ await git(path, ["push", "--quiet", "-u", "origin", `HEAD:refs/heads/${name}`]);
163
+ const out = { try: n, branch: name, path, from: branch };
164
+ io.out(opts.json ? JSON.stringify(out) : `try-${n} on ${name} at ${path}`);
165
+ return 0;
166
+ }
167
+ /**
168
+ * `cupola try remove <work>`: deletes the work's tries — their branches on
169
+ * origin and here, and their worktrees — once its gate is passed.
170
+ */
171
+ export async function tryRemove(io, id, opts) {
172
+ const root = await repoRoot(io.cwd);
173
+ const removed = [];
174
+ for (const n of await triesOf(root, id)) {
175
+ const name = tryBranch(id, n);
176
+ const path = await existingWorktree(root, name);
177
+ if (path)
178
+ await git(root, ["worktree", "remove", "--force", path]);
179
+ await git(root, ["branch", "-D", name]).catch(() => "");
180
+ await git(root, ["push", "--quiet", "origin", "--delete", name]);
181
+ removed.push(name);
182
+ }
183
+ io.out(opts.json ? JSON.stringify({ removed }) : `removed ${removed.length} tries`);
184
+ return 0;
185
+ }
@@ -1,9 +1,9 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { appendFile, mkdir, readFile } from "node:fs/promises";
3
- import { dirname, join } from "node:path";
3
+ import { dirname } from "node:path";
4
4
  import { epicPath, pathsAt } from "../config.js";
5
5
  import { git, originDefaultBranch } from "../git.js";
6
- import { github } from "../host/github.js";
6
+ import { codeHost } from "../host/index.js";
7
7
  import { writeInside } from "../safe-write.js";
8
8
  import { epicFront, readBlock, revisionsOf } from "../spec.js";
9
9
  import { gitTree } from "../tree.js";
@@ -31,7 +31,7 @@ export async function agreedEpicText(root, epic) {
31
31
  }
32
32
  /** The draft of a revision under agreement (its `epic` change is open), or undefined. */
33
33
  async function draftEpicText(io, root, epic) {
34
- const change = await (io.host ?? github)(root).findChange(workBranchName(epic));
34
+ const change = await (io.host ?? codeHost)(root).findChange(workBranchName(epic));
35
35
  if (change?.state !== "open")
36
36
  return undefined;
37
37
  return (await workTree(root, workBranchName(epic))).tree.read(epicPath(await pathsAt(root), epic));
@@ -134,6 +134,6 @@ export async function snapshotEpic(ws, root, epic) {
134
134
  await mkdir(dirname(exclude), { recursive: true });
135
135
  await appendFile(exclude, `${have === "" || have.endsWith("\n") ? "" : "\n"}/${dir}/\n`);
136
136
  }
137
- await writeInside(root, join(dir, `${epic}.md`), text);
137
+ await writeInside(root, epicPath(ws.config.paths, epic), text);
138
138
  return true;
139
139
  }
@@ -1,5 +1,5 @@
1
1
  import { existsSync } from "node:fs";
2
- import { readFile, rm } from "node:fs/promises";
2
+ import { readdir, readFile, rm } from "node:fs/promises";
3
3
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
4
  import { mountWork } from "../code.js";
5
5
  import { epicPath, loadConfig, resolveComponents } from "../config.js";
@@ -9,9 +9,9 @@ import { projectProfile } from "../e2e-project.js";
9
9
  import { specPath } from "../engine/cc-sdd.js";
10
10
  import { parseFrontMatter } from "../frontmatter.js";
11
11
  import { behindOrigin, commitPaths, git, gitUserEmail, head, originDefaultBranch, pushBranch, workBranch, } from "../git.js";
12
- import { github } from "../host/github.js";
12
+ import { codeHost } from "../host/index.js";
13
13
  import { phaseDef } from "../method/v1.js";
14
- import { createFromSendBacks, createRecord, endingCard, next, parseOutcome, parseRecord, pendingSendBacks, RecordError, recordOutcome, serializeRecord, } from "../record.js";
14
+ import { createFromNoGos, createRecord, endingCard, next, parseOutcome, parseRecord, pendingNoGos, RecordError, recordOutcome, redoFromAcceptance, serializeRecord, } from "../record.js";
15
15
  import { releaseBody, releasesOf } from "../release.js";
16
16
  import { assertInsideRepository, writeInside } from "../safe-write.js";
17
17
  import { epicBranchName, epicFront, newBlock, readBlock, reassertBlock } from "../spec.js";
@@ -24,7 +24,7 @@ import { workspace } from "../workspace.js";
24
24
  import { codeBody, openCodeChanges, readBody } from "./change.js";
25
25
  import { claimEnvironments, releaseEnvironments, unknownNeeds } from "./locks.js";
26
26
  import { agreedEpicText, carriedOut, droppedBecause, pendingPlan, redesignToTakeIn, revisionsToApply, snapshotEpic, } from "./revision.js";
27
- import { peopleFeedback, waitingFor } from "./status.js";
27
+ import { waitingFor } from "./status.js";
28
28
  import { trackerOf } from "./work.js";
29
29
  import { worktree } from "./worktree.js";
30
30
  async function context(io, id, opts) {
@@ -153,23 +153,9 @@ async function takeInRevisions(ctx, id, record) {
153
153
  throw new Error(`cannot read the agreed ${epicFile} from origin to take its revisions in`);
154
154
  }
155
155
  const { epic } = epicFront(epicFile, agreed);
156
- const order = record.phases.map((p) => p.name);
157
156
  const redesign = todo.find((t) => t.plan === "redesign");
158
- if (redesign) {
159
- // From the acceptance tests: they were written from the examples the revision may change.
160
- const from = order.indexOf("acceptance");
161
- for (const p of record.phases.slice(from)) {
162
- if (p.state === "done")
163
- p.state = "redo";
164
- else if (p.state === "running")
165
- p.state = "pending";
166
- else if (p.state === "skipped" && p.skipped_by && order.indexOf(p.skipped_by) >= from) {
167
- p.state = "pending";
168
- delete p.skipped_by;
169
- delete p.note;
170
- }
171
- }
172
- }
157
+ if (redesign)
158
+ redoFromAcceptance(record);
173
159
  record.events.push({
174
160
  at: ctx.runner.now,
175
161
  phase: redesign
@@ -226,43 +212,30 @@ export async function runNext(io, id, opts) {
226
212
  // An epic with one spec runs its acceptance check in that spec's run.
227
213
  onlySpecOfEpic: epic ? epic.front.specs.length === 1 : false,
228
214
  };
229
- const sendBacks = pendingSendBacks(loaded, cards);
230
- // Feedback a person left on the change, with no run going, sends it back as a card does:
231
- // the review phase answers it, and may send the work back further.
232
- // Only a work whose run has a review phase, at its gate (G4 still sends back only in dialogue).
215
+ // A No-Go a gate processed is a card: the run goes back to the phase it names.
216
+ const noGos = pendingNoGos(loaded, cards);
233
217
  let toDraft;
234
- if (!loaded && sendBacks.length === 0 && doc.kind !== "epic") {
235
- const host = (io.host ?? github)(ctx.root);
218
+ if (!loaded && noGos.length > 0) {
219
+ const host = (io.host ?? codeHost)(ctx.root);
236
220
  const change = await host.findChange(ctx.branch);
237
- const people = await peopleFeedback(host, change, loaded, config);
238
- if (change && people > 0) {
239
- sendBacks.push({
240
- card: Math.max(0, ...cards.map((c) => c.card)),
241
- type: "send-back",
242
- file: "",
243
- effect: null,
244
- answered: true,
245
- redo: "review",
246
- label: `feedback on the change (${people})`,
247
- });
248
- // Back to draft once the record exists, so that a failure leaves the change at its gate.
221
+ // Back to draft once the record exists, so that a failure leaves the change at its gate.
222
+ if (change?.state === "open" && !change.draft)
249
223
  toDraft = () => host.markDraft(change.number);
250
- }
251
224
  }
252
- // A send-back starts a new record, with a new lineage, even over a finished one; the
225
+ // A No-Go starts a new record, with a new lineage, even over a finished one; the
253
226
  // record the finish removed still says what is owed and which phases were skipped.
254
- const finished = !loaded && sendBacks.length > 0 ? await finishedRecord(ctx, id) : undefined;
255
- const record = sendBacks.length > 0
256
- ? createFromSendBacks(work, config.review.max_rounds, sendBacks, ctx.runner.now, loaded ?? finished, !loaded && finished !== undefined)
227
+ const finished = !loaded && noGos.length > 0 ? await finishedRecord(ctx, id) : undefined;
228
+ const record = noGos.length > 0
229
+ ? createFromNoGos(work, config.review.max_rounds, noGos, ctx.runner.now, loaded ?? finished, !loaded && finished !== undefined)
257
230
  : (loaded ?? createRecord(work, config.review.max_rounds));
258
231
  const created = record !== loaded;
259
232
  if (toDraft)
260
233
  await toDraft();
261
- if (!loaded && sendBacks.length === 0) {
234
+ if (!loaded && noGos.length === 0) {
262
235
  // Without a record, a ready or finished change means the run already reached its gate.
263
- const change = await (io.host ?? github)(ctx.root).findChange(ctx.branch);
236
+ const change = await (io.host ?? codeHost)(ctx.root).findChange(ctx.branch);
264
237
  if (change && (change.state !== "open" || !change.draft)) {
265
- const gate = ctx.branch === epicBranchName(id) ? "awaiting release (G4)" : "awaiting acceptance (G3)";
238
+ const gate = ctx.branch === epicBranchName(id) ? "awaiting release" : "awaiting acceptance";
266
239
  const where = change.state === "open" ? gate : change.state;
267
240
  throw new Error(`${id} is ${where} at ${change.url}; there is nothing to run (see \`cupola status ${id}\`)`);
268
241
  }
@@ -278,7 +251,7 @@ export async function runNext(io, id, opts) {
278
251
  (await git(ctx.root, ["log", "-1", "--format=%s"])) === `cupola: ${id}: finish`) {
279
252
  const result = {
280
253
  spec: id,
281
- stopped: ctx.branch === epicBranchName(id) ? "G4" : "G3",
254
+ stopped: ctx.branch === epicBranchName(id) ? "release" : "acceptance",
282
255
  resume: "finish",
283
256
  note: `the finish was interrupted; run \`cupola run finish ${id}\` again (the description is already written)`,
284
257
  };
@@ -410,8 +383,10 @@ export async function runNext(io, id, opts) {
410
383
  io.out(opts.json ? JSON.stringify(result) : `${id}: stopped at ${action.stopped} — ${action.note}`);
411
384
  return 0;
412
385
  }
413
- // Finishing clears the cards, so every send-back here belongs to this run's restart.
414
- const sentBack = cards.filter((c) => c.type === "send-back").sort((a, b) => a.card - b.card);
386
+ // Finishing clears the cards, so every No-Go card here belongs to this run's restart.
387
+ const noGoCards = cards
388
+ .filter((c) => c.type === "no-go" && c.effect === "continue")
389
+ .sort((a, b) => a.card - b.card);
415
390
  // The only spec of an epic outside the hub writes the epic's own files (its system catalog
416
391
  // entries) in the hub, on a branch of their own merged with it: the `system` change.
417
392
  let hubFiles;
@@ -458,9 +433,9 @@ export async function runNext(io, id, opts) {
458
433
  // Code in a repository of its own, mounted here: committed and pushed there, not at the root.
459
434
  ...(mounts.length > 0 ? { code: mounts.map((m) => ({ repo: m.slug, dir: m.dir })) } : {}),
460
435
  ...(doc.kind === "spec" ? { spec: specPath(id) } : {}),
461
- // A run restarted at G3: the send-back cards say what the human found wrong.
462
- ...(sentBack.length > 0
463
- ? { sendBacks: sentBack.map((c) => join(ctx.dir, "cards", c.file)) }
436
+ // A run restarted at acceptance: the No-Go cards say what the human found wrong.
437
+ ...(noGoCards.length > 0
438
+ ? { noGos: noGoCards.map((c) => join(ctx.dir, "cards", c.file)) }
464
439
  : {}),
465
440
  };
466
441
  if (opts.json) {
@@ -505,6 +480,22 @@ export async function runRecord(io, id, opts) {
505
480
  throw new RecordError(`environments: ${unknown.join(", ")} is neither an environment nor a pool of shared environments in ${E2E_PROFILE}`);
506
481
  }
507
482
  }
483
+ // A spec its epic no longer runs — aborted, or dropped by an agreed revision, while the phase
484
+ // ran — stops here, as `run next` would: the outcome is not recorded.
485
+ // The record names its work: an engine may have rewritten the spec's own block meanwhile.
486
+ const inEpic = record.work.kind === "spec" ? (record.work.epic ?? undefined) : undefined;
487
+ const dropped = inEpic
488
+ ? await droppedBecause(io, ctx.hub, inEpic, record.work.component)
489
+ : undefined;
490
+ if (dropped) {
491
+ const held = record.phases.find((p) => p.state === "running")?.locks ?? [];
492
+ await releaseEnvironments(project.rootOf, held, id);
493
+ const result = { spec: id, stopped: "blocked", note: `${dropped}; it does not run` };
494
+ io.out(opts.json
495
+ ? JSON.stringify({ continue: false, result })
496
+ : `${id}: stopped at blocked — ${result.note}`);
497
+ return 0;
498
+ }
508
499
  const cards = await readCards(fsTree(ctx.root), id);
509
500
  const { record: updated, result } = recordOutcome(record, outcome, { ...ctx.runner, commit: await head(ctx.root) }, cards);
510
501
  // The outcome is merged into the record once the record is written; a copy
@@ -542,12 +533,12 @@ export async function runRecord(io, id, opts) {
542
533
  /**
543
534
  * `cupola run finish <work> --body-file <f>`: after the runner has looked back
544
535
  * over the record, removes the run directory in a last commit,
545
- * writes the change description, and marks the change ready: G3.
536
+ * writes the change description, and marks the change ready: acceptance.
546
537
  */
547
538
  export async function runFinish(io, id, opts) {
548
539
  const ctx = await context(io, id, opts);
549
540
  const body = opts.bodyFile ? await readBody(io.cwd, opts.bodyFile) : undefined;
550
- const host = (io.host ?? github)(ctx.root);
541
+ const host = (io.host ?? codeHost)(ctx.root);
551
542
  const change = await host.findChange(ctx.branch);
552
543
  if (change?.state !== "open") {
553
544
  throw new Error(`${id} has no open change; open it with \`cupola change open ${id}\``);
@@ -604,10 +595,11 @@ export async function runFinish(io, id, opts) {
604
595
  const ref = await head(ctx.root);
605
596
  const described = await describe(io, fsTree(ctx.root), ctx, record, body, ref);
606
597
  await host.setBody(change.number, releases.length > 1 ? releaseBody(described, hubRelease(), releases) : described);
607
- await rm(assertInsideRepository(ctx.root, ctx.dir), { recursive: true, force: true });
598
+ // Reactions given in a session while it ran are kept: the gate it now reaches processes them.
599
+ await removeRunDir(ctx.root, ctx.dir);
608
600
  await commitPaths(ctx.root, ctx.branch, [ctx.dir], finishCommit);
609
601
  }
610
- // The system change first: if it cannot be opened, the spec is not offered at G3 alone.
602
+ // The system change first: if it cannot be opened, the spec is not offered for acceptance alone.
611
603
  const work = record?.work ?? finishedWork;
612
604
  const system = work?.kind === "spec" &&
613
605
  work.epic &&
@@ -641,7 +633,7 @@ export async function runFinish(io, id, opts) {
641
633
  }
642
634
  // Every repository's release change, in the order they are merged.
643
635
  const changes = released.sort((a, b) => a.order - b.order).map((r) => r.url);
644
- const gate = ctx.branch === epicBranchName(id) ? "G4" : "G3";
636
+ const gate = ctx.branch === epicBranchName(id) ? "release" : "acceptance";
645
637
  const where = changes.length > 1
646
638
  ? `${changes.join(", then ")} (merged in this order)`
647
639
  : code.length > 0
@@ -650,7 +642,7 @@ export async function runFinish(io, id, opts) {
650
642
  const result = {
651
643
  spec: id,
652
644
  stopped: gate,
653
- note: `ready for ${gate === "G4" ? "release" : "acceptance"}: ${where}${system ? `, with the system change ${system}` : ""}`,
645
+ note: `ready for ${gate === "release" ? "release" : "acceptance"}: ${where}${system ? `, with the system change ${system}` : ""}`,
654
646
  ...(system ? { system } : {}),
655
647
  ...(changes.length > 1 ? { changes } : {}),
656
648
  ...(code.length > 0 ? { code } : {}),
@@ -681,7 +673,7 @@ export async function runEnd(io, id, opts) {
681
673
  if (ending.effect === "revise-epic") {
682
674
  throw new Error(`card ${ending.card} chose to revise the epic: that is \`cupola-epic-revise\``);
683
675
  }
684
- const host = (io.host ?? github)(root);
676
+ const host = (io.host ?? codeHost)(root);
685
677
  const change = await host.findChange(branch);
686
678
  // Problems the run found are filed either way. The stop-fix card's own case
687
679
  // is filed only by to-case: abort leaves it unfiled.
@@ -831,7 +823,7 @@ async function pushCode(io, ctx, id) {
831
823
  if (ctx.ws.config.documents !== "hub" || ctx.branch === epicBranchName(id))
832
824
  return [];
833
825
  try {
834
- const hub = await (io.host ?? github)(ctx.root).findChange(ctx.branch);
826
+ const hub = await (io.host ?? codeHost)(ctx.root).findChange(ctx.branch);
835
827
  if (hub?.state !== "open")
836
828
  return [];
837
829
  const opened = await openCodeChanges(io, ctx.ws, ctx.root, id, ctx.branch, {
@@ -856,8 +848,8 @@ async function pushCode(io, ctx, id) {
856
848
  async function finishCode(io, ctx, id, change) {
857
849
  if (ctx.ws.config.documents !== "hub" || ctx.branch === epicBranchName(id))
858
850
  return [];
859
- const host = (io.host ?? github)(ctx.root);
860
- // Everything committed in a code repository is pushed to its change before it is offered at G3.
851
+ const host = (io.host ?? codeHost)(ctx.root);
852
+ // Everything committed in a code repository is pushed to its change before it is offered for acceptance.
861
853
  await mountWork(ctx.ws, ctx.root, id, ctx.branch);
862
854
  const opened = await openCodeChanges(io, ctx.ws, ctx.root, id, ctx.branch, {
863
855
  title: `Code: ${id}`,
@@ -1013,3 +1005,17 @@ async function epicBranchWorktrees(io, ctx, epic, components) {
1013
1005
  }
1014
1006
  return out;
1015
1007
  }
1008
+ /** Removes a run's directory, all but the reactions kept for its gate. */
1009
+ async function removeRunDir(root, dir) {
1010
+ const full = assertInsideRepository(root, dir);
1011
+ if (!existsSync(full))
1012
+ return;
1013
+ const entries = await readdir(full);
1014
+ if (!entries.includes("reactions"))
1015
+ return rm(full, { recursive: true, force: true });
1016
+ for (const entry of entries) {
1017
+ if (entry === "reactions")
1018
+ continue;
1019
+ await rm(join(full, entry), { recursive: true, force: true });
1020
+ }
1021
+ }
@@ -2,7 +2,8 @@ import { existsSync } from "node:fs";
2
2
  import { mkdir, readFile, writeFile } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
- import { loadConfig } from "../config.js";
5
+ import { hostKindOf, loadConfig } from "../config.js";
6
+ import { originDefaultBranch } from "../git.js";
6
7
  import { gh } from "../host/github.js";
7
8
  import { repoRoot } from "../repo.js";
8
9
  import { writeInside } from "../safe-write.js";
@@ -41,6 +42,16 @@ export const CLAUDE_ALLOW = ["Bash(npx @kyuki3rain/cupola *)", "Bash(cupola *)",
41
42
  * also matches an ordinary command only returns a denial the run can work
42
43
  * around (a commit message reworded), but such matches are kept rare.
43
44
  */
45
+ /** A push to one of these branches, by name, `:<branch>`, or `refs/heads/<branch>`. */
46
+ function pushTo(branches) {
47
+ return [
48
+ ...branches.flatMap((b) => [`push * ${b}`, `push * ${b} *`]),
49
+ ...branches.flatMap((b) => [`push *:${b}`, `push *:${b} *`]),
50
+ ...branches.flatMap((b) => [`push *refs/heads/${b}`, `push *refs/heads/${b} *`]),
51
+ ];
52
+ }
53
+ // `main` and `master` always: the default branch of a repository whose origin cannot be read.
54
+ const PUSH_TO_DEFAULT = pushTo(["main", "master"]);
44
55
  const GIT_DENIED = [
45
56
  "--config-env*",
46
57
  "remote add*",
@@ -52,18 +63,7 @@ const GIT_DENIED = [
52
63
  "push * +*",
53
64
  "push --mirror*",
54
65
  "push * --mirror*",
55
- "push * main",
56
- "push * main *",
57
- "push * master",
58
- "push * master *",
59
- "push *:main",
60
- "push *:main *",
61
- "push *:master",
62
- "push *:master *",
63
- "push *refs/heads/main",
64
- "push *refs/heads/main *",
65
- "push *refs/heads/master",
66
- "push *refs/heads/master *",
66
+ ...PUSH_TO_DEFAULT,
67
67
  "push http*",
68
68
  "push * http*",
69
69
  "push git@*",
@@ -105,16 +105,26 @@ const GIT_C_CONFIG = [
105
105
  "url",
106
106
  ].map((section) => `config ${section}.*`),
107
107
  ];
108
- export const CLAUDE_DENY = [
109
- ...["-c *", "config *", ...GIT_DENIED].map((r) => `Bash(git ${r})`),
110
- ...[...GIT_C_CONFIG, ...GIT_DENIED].map((r) => `Bash(git -C * ${r})`),
111
- ];
112
108
  /**
113
- * The CLI's operations that only a human decides, prompted each time: closing a case (G5). Only
109
+ * The deny rules, for a repository whose default branch is `defaultBranch`: pushes to it are
110
+ * denied as pushes to `main` and `master` are, in the same forms.
111
+ */
112
+ export function claudeDeny(defaultBranch) {
113
+ const extra = defaultBranch && !["main", "master"].includes(defaultBranch) ? pushTo([defaultBranch]) : [];
114
+ const denied = [...GIT_DENIED, ...extra];
115
+ return [
116
+ ...["-c *", "config *", ...denied].map((r) => `Bash(git ${r})`),
117
+ ...[...GIT_C_CONFIG, ...denied].map((r) => `Bash(git -C * ${r})`),
118
+ ];
119
+ }
120
+ export const CLAUDE_DENY = claudeDeny();
121
+ /**
122
+ * The CLI's operations that only a human decides, prompted each time: closing a case (resolution), and
123
+ * merging a change on a git host (acceptance, release). Only
114
124
  * what no execution skill runs: `cupola change close` (a dropped spec, in `cupola-epic-run`) and
115
125
  * `cupola epic abort` (`cupola-abort`, on a human's instruction) run without a prompt.
116
126
  */
117
- export const CLAUDE_ASK = ["work close"].flatMap((c) => [
127
+ export const CLAUDE_ASK = ["work close", "change merge"].flatMap((c) => [
118
128
  `Bash(cupola ${c}*)`,
119
129
  `Bash(npx @kyuki3rain/cupola ${c}*)`,
120
130
  ]);
@@ -123,6 +133,10 @@ const LISTS = [
123
133
  { key: "deny", prefix: "deny", rules: CLAUDE_DENY, have: "denied" },
124
134
  { key: "ask", prefix: "ask", rules: CLAUDE_ASK, have: "asked each time" },
125
135
  ];
136
+ /** The lists, with pushes to the repository's default branch denied too. */
137
+ function listsFor(defaultBranch) {
138
+ return LISTS.map((l) => (l.key === "deny" ? { ...l, rules: claudeDeny(defaultBranch) } : l));
139
+ }
126
140
  /** What a run needs of Claude Code's limits; the default is in parentheses. */
127
141
  export const CLAUDE_LIMITS = [
128
142
  { key: "CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH", want: 3, absent: 3 },
@@ -164,6 +178,10 @@ async function readSettings(file) {
164
178
  * permissions for the CLI and git, and the subagent limits.
165
179
  */
166
180
  export async function claudeItems(root, opts) {
181
+ const defaultBranch = "defaultBranch" in opts
182
+ ? opts.defaultBranch
183
+ : await originDefaultBranch(root, { timeoutMs: 15_000, retry: false });
184
+ const lists = listsFor(defaultBranch);
167
185
  const files = settingsFiles(root, opts.home);
168
186
  const read = await Promise.all(files.map((f) => readSettings(f.file)));
169
187
  const all = read.filter((s) => s !== "invalid");
@@ -180,7 +198,7 @@ export async function claudeItems(root, opts) {
180
198
  return s && s !== "invalid" ? [s] : [];
181
199
  });
182
200
  const where = opts.target ?? ".claude/settings.json";
183
- const items = LISTS.flatMap((list) => {
201
+ const items = lists.flatMap((list) => {
184
202
  const set = new Set(all.flatMap((s) => s.permissions?.[list.key] ?? []));
185
203
  return list.rules.map((rule) => ({
186
204
  id: `${list.prefix} ${rule}`,
@@ -286,7 +304,21 @@ export const SQUASH_JQ = '.allow_squash_merge and .squash_merge_commit_title ==
286
304
  async function host(root, apply) {
287
305
  const config = await loadConfig(root);
288
306
  const items = [];
289
- for (const slug of reposOf(config)) {
307
+ const onGithub = reposOf(config).filter((slug) => hostKindOf(config, slug) === "github");
308
+ for (const slug of reposOf(config).filter((s) => !onGithub.includes(s))) {
309
+ // A git host has no settings to read: people merge through Cupola, one commit per change.
310
+ items.push({
311
+ id: `squash merge ${slug}`,
312
+ state: "ok",
313
+ detail: "a git host: people merge with `cupola change merge`, one commit per change",
314
+ });
315
+ items.push({
316
+ id: `pull requests required ${slug}`,
317
+ state: "manual",
318
+ detail: "a git host: let only the people who merge push to its default branch, on the git server",
319
+ });
320
+ }
321
+ for (const slug of onGithub) {
290
322
  let squash;
291
323
  try {
292
324
  squash = (await gh(root, ["api", `repos/${slug}`, "--jq", SQUASH_JQ])) === "true";
@@ -338,7 +370,7 @@ async function host(root, apply) {
338
370
  });
339
371
  }
340
372
  }
341
- for (const slug of reposOf(config))
373
+ for (const slug of onGithub)
342
374
  items.push(await pullRequestRequired(root, slug));
343
375
  return items;
344
376
  }
@@ -15,7 +15,7 @@ const INIT_TEMPLATE = ".kiro/settings/templates/specs/init.json";
15
15
  /**
16
16
  * `cupola spec init <spec> --epic <epic>`: creates a full spec's `spec.json`
17
17
  * on the spec's branch, from the engine's template and with Cupola's block,
18
- * and pushes it. Run in the spec's worktree, after G1. Running
18
+ * and pushes it. Run in the spec's worktree, after the epic's start. Running
19
19
  * it again on a spec that exists changes nothing.
20
20
  */
21
21
  export async function specInit(io, spec, opts) {