@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
package/dist/main.js CHANGED
@@ -4,10 +4,12 @@ import { homedir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { parseArgs } from "node:util";
6
6
  import { listAdrs, renderAdrList } from "./adr.js";
7
- import { changeAnswer, changeChecks, changeClose, changeDraft, changeFeedback, changeOpen, changeReview, changeShow, } from "./commands/change.js";
7
+ import { changeAnswer, changeChecks, changeClose, changeDraft, changeFeedback, changeMerge, changeOpen, changeReady, changeReview, changeShow, } from "./commands/change.js";
8
8
  import { epicAbort, epicBranch, epicSync } from "./commands/epic.js";
9
+ import { executionRecord, executionStart } from "./commands/execution.js";
9
10
  import { initCommand, updateCommand } from "./commands/install.js";
10
- import { procedureRecord } from "./commands/procedure.js";
11
+ import { listLocks } from "./commands/locks.js";
12
+ import { reactionAdd, reactionList, reactionReply, tryRemove, tryStart, } from "./commands/reaction.js";
11
13
  import { runEnd, runFinish, runNext, runRecord } from "./commands/run.js";
12
14
  import { claudeItems, SQUASH_JQ, setup } from "./commands/setup.js";
13
15
  import { specInit } from "./commands/spec.js";
@@ -15,9 +17,9 @@ import { status } from "./commands/status.js";
15
17
  import { check, trace } from "./commands/trace.js";
16
18
  import { wait } from "./commands/wait.js";
17
19
  import { workClose, workFile, workList, workLog, workReopen, workShow } from "./commands/work.js";
18
- import { workspaceSetup } from "./commands/workspace.js";
20
+ import { cloneUrl, workspaceSetup } from "./commands/workspace.js";
19
21
  import { worktree, worktreeRemove } from "./commands/worktree.js";
20
- import { CONFIG_PATH, ConfigError, DEFAULT_PATHS, loadConfig, parseConfig, resolveComponents, } from "./config.js";
22
+ import { CONFIG_PATH, ConfigError, cloneUrlOf, DEFAULT_PATHS, hostKindOf, loadConfig, parseConfig, resolveComponents, } from "./config.js";
21
23
  import { today } from "./day.js";
22
24
  import { E2E_PROFILE, parseProfile } from "./e2e.js";
23
25
  import { CC_SDD_VERSION, ENGINE_LANGUAGE, specPath } from "./engine/cc-sdd.js";
@@ -28,14 +30,14 @@ import { terminalIo } from "./io.js";
28
30
  import { repoRoot } from "./repo.js";
29
31
  import { templateKinds, templatePath } from "./templates.js";
30
32
  import { version } from "./version.js";
31
- import { identifyRepo, reposOf, slugsOf, workspace } from "./workspace.js";
33
+ import { identifyRepo, NotClonedError, reposOf, slugsOf, workspace, } from "./workspace.js";
32
34
  const USAGE = `Usage: cupola <command> [options]
33
35
 
34
36
  Commands:
35
37
  init Write .cupola/config.json and install Cupola (--config-file <file>, or --hub, --component name[:path[:role]], --language, --tracker, --reviewer). The dialogue is the cupola-init skill
36
38
  setup claude|host What Claude Code and the code host need, item by item (--apply makes the items it can; claude: --scope project|local, --subagents <n>)
37
39
  update Install or update Cupola's files (--keep <path>, --take-new <path> for local edits; a directory chooses every file under it)
38
- doctor Validate the configuration and its copies, managed files edited here, Claude Code's permissions and limits, e2e environments (--host: also the code host's authentication and squash merges)
40
+ doctor Validate the configuration and its copies, managed files edited here, Claude Code's permissions and limits, e2e environments; repositories still to set up are listed as pending (--host: also the code host's authentication and squash merges)
39
41
  workspace setup Clone the other repositories under the hub (several repositories)
40
42
  run next <work> The next phase of a work item and what it is given
41
43
  run record <work> Record a phase's outcome (--outcome <file>)
@@ -43,29 +45,38 @@ Commands:
43
45
  run end <work> Carry out a card that ends the run: abort, or file a case (to-case)
44
46
  worktree <work> Create or find the work's worktree (--from <ref>; --epic-branch for an epic's own; --remove after the merge; --component <name> for work in that component's repository)
45
47
  change open <work> Push the work's branch and open its change, a draft unless --ready (--title, --body-file)
46
- change show <work> The work's change
47
- change draft <work> Turn the change back into a draft (a send-back)
48
+ change show <work> The work's change (--release: the epic's release, from any branch)
49
+ change draft <work> Turn the change back into a draft: after a No-Go, or an epic's change while cards are open (--body-file: describe it anew)
50
+ change ready <work> Mark the change ready for its gate: an epic's change once no card is open (--body-file: describe it anew)
48
51
  change close <work> Close the change without merging, its branch kept (--body-file <why>)
52
+ change merge <work> For people: merge the ready changes on a git host, each as one commit (--release: the epic's release)
49
53
  change review <work> Ask the configured reviewer to review the change
50
- change feedback <work> Open feedback, and whether the reviewer answered (--since <time>, --wait <seconds>)
51
- change answer <work> Answer feedback (--feedback <id> --body-file <file> [--settle])
54
+ change feedback <work> The reviewer's open feedback, and whether it answered (--since <time>, --wait <seconds>)
55
+ change answer <work> Answer the reviewer's feedback (--feedback <id> --body-file <file> [--settle])
56
+ reaction list <work> The reactions of the work's gate (comment, try, No-Go), on its change and from sessions, and which are not processed
57
+ reaction reply <work> Answer a reaction, which processes it (--reaction <id> --body-file <file>; a session's needs no body)
58
+ reaction add <work> Keep a reaction given in a session for the next gate (--kind comment|try|no-go [--body-file <words>] [--who <name>])
59
+ try start <work> A try branch from the change's head, pushed, in a worktree of its own
60
+ try remove <work> Delete the work's tries once its gate is passed
52
61
  change checks <work> The change's CI result (--wait <seconds>)
53
62
  work list Every case in the tracker, open and closed
54
63
  work show <case> A case's document
55
64
  work file File a case or a run's case draft (--body-file <file>)
56
65
  work log <case> Append a line to a case's Log (--body-file <file>)
57
- work close <case> G5: the problem is gone; log the human's words and close the case (--body-file <file>; --without-epic for a case that needs no work)
58
- work reopen <case> G5: not solved yet; log why, and the epics judged no longer count (--body-file <file>)
66
+ work close <case> Resolution: the problem is gone; log the human's words and close the case (--body-file <file>; --without-epic for a case that needs no work)
67
+ work reopen <case> Resolution: not solved yet; log why, and the epics judged no longer count (--body-file <file>)
59
68
  template <kind> Print a template this method serves (card, changes/catalog, …)
60
69
  trace [<area>] Requirements → tests → latest results (--index regenerates the catalog index)
61
70
  check Self-check the catalog and Cupola documents before opening a change
62
71
  status <work> Where a work item stands, whose turn it is, and what comes next (--case: a case only)
63
- wait <work> At G1, G3, or G4: waits, with no model running, until the human merges or sends it back, then prints the new status (--timeout <s>, --interval <s>)
72
+ locks [<component>] The locks on shared e2e environments: who holds each, since when, and the id to take it over
73
+ wait <work> At start, acceptance, or release: waits, with no model running, until the human merges, reacts, or closes the change, then prints the new status (--timeout <s>, --interval <s>)
64
74
  adr list The decision records, newest first, derived from their front matter (--applies-to x,y)
65
75
  epic branch <epic> Create the epic branch of an agreed epic with two or more specs
66
76
  epic sync <epic> Merge origin's default branch into the epic branch
67
77
  epic abort <epic> Carry out an abort: close the epic's changes, record it on its cases (--body-file <reason>)
68
- procedure record <epic> <runbook> Record a step of an operating epic's procedure on its cases (--step <P#> --result done|stopped, or --result finished; --body-file <line>)
78
+ execution start <runbook> Start an execution of an agreed runbook: its record on its own branch, a draft change (--for <epic|case>; --param <name>=<value> for each param, for a case)
79
+ execution record <execution> Record a step in the human's words (--step <P#|X#> --result done|stopped), or the end (--result finished|given-up, marks the change ready); --body-file <line>
69
80
  spec path <spec> Where the spec engine keeps a spec's documents
70
81
  spec init <spec> Create a spec of an agreed epic on its branch (--epic <epic>)
71
82
 
@@ -92,6 +103,7 @@ export async function main(argv, given) {
92
103
  "body-file": { type: "string" },
93
104
  base: { type: "string" },
94
105
  ready: { type: "boolean" },
106
+ release: { type: "boolean" },
95
107
  from: { type: "string" },
96
108
  index: { type: "boolean" },
97
109
  "applies-to": { type: "string", multiple: true },
@@ -101,6 +113,9 @@ export async function main(argv, given) {
101
113
  timeout: { type: "string" },
102
114
  interval: { type: "string" },
103
115
  feedback: { type: "string" },
116
+ reaction: { type: "string" },
117
+ kind: { type: "string" },
118
+ who: { type: "string" },
104
119
  settle: { type: "boolean" },
105
120
  keep: { type: "string", multiple: true },
106
121
  "take-new": { type: "string", multiple: true },
@@ -118,6 +133,8 @@ export async function main(argv, given) {
118
133
  case: { type: "boolean" },
119
134
  "epic-branch": { type: "boolean" },
120
135
  step: { type: "string" },
136
+ for: { type: "string" },
137
+ param: { type: "string", multiple: true },
121
138
  result: { type: "string" },
122
139
  "without-epic": { type: "boolean" },
123
140
  },
@@ -244,14 +261,16 @@ export async function main(argv, given) {
244
261
  open: changeOpen,
245
262
  show: changeShow,
246
263
  draft: changeDraft,
264
+ ready: changeReady,
247
265
  close: changeClose,
266
+ merge: changeMerge,
248
267
  review: changeReview,
249
268
  feedback: changeFeedback,
250
269
  answer: changeAnswer,
251
270
  checks: changeChecks,
252
271
  }[sub ?? ""];
253
272
  if (!run || !id) {
254
- return usage("cupola change open|show|draft|close|review|reviews|reply|checks <work> [options]");
273
+ return usage("cupola change open|show|draft|ready|close|merge|review|feedback|answer|checks <work> [options]");
255
274
  }
256
275
  const opts = {
257
276
  json,
@@ -263,6 +282,26 @@ export async function main(argv, given) {
263
282
  feedback: str(values.feedback),
264
283
  settle: values.settle === true,
265
284
  ready: values.ready === true,
285
+ release: values.release === true,
286
+ };
287
+ return guard(() => run(io, id, opts));
288
+ }
289
+ case "reaction":
290
+ case "try": {
291
+ const [, sub, id] = positionals;
292
+ const run = command === "reaction"
293
+ ? { list: reactionList, reply: reactionReply, add: reactionAdd }[sub ?? ""]
294
+ : { start: tryStart, remove: tryRemove }[sub ?? ""];
295
+ if (!run || !id)
296
+ return usage(command === "reaction"
297
+ ? "cupola reaction list|reply|add <work> [options]"
298
+ : "cupola try start|remove <work>");
299
+ const opts = {
300
+ json,
301
+ reaction: str(values.reaction),
302
+ kind: str(values.kind),
303
+ who: str(values.who),
304
+ bodyFile: str(values["body-file"]),
266
305
  };
267
306
  return guard(() => run(io, id, opts));
268
307
  }
@@ -291,6 +330,10 @@ export async function main(argv, given) {
291
330
  const [, area] = positionals;
292
331
  return guard(() => trace(io, area, { json, index: values.index === true }));
293
332
  }
333
+ case "locks": {
334
+ const [, component] = positionals;
335
+ return guard(() => listLocks(io, component, { json }));
336
+ }
294
337
  case "check":
295
338
  return guard(() => check(io, { json }));
296
339
  case "adr": {
@@ -324,17 +367,23 @@ export async function main(argv, given) {
324
367
  }
325
368
  return usage("cupola epic branch <epic> | epic sync <epic> | epic abort <epic> --body-file <f>");
326
369
  }
327
- case "procedure": {
328
- const [, sub, epic, runbook] = positionals;
329
- if (sub === "record" && epic && runbook) {
330
- return guard(() => procedureRecord(io, epic, runbook, {
331
- json,
332
- bodyFile: str(values["body-file"]),
333
- step: str(values.step),
334
- result: str(values.result),
335
- }));
336
- }
337
- return usage("cupola procedure record <epic> <runbook> (--step <P#> --result done|stopped | --result finished) --body-file <f>");
370
+ case "execution": {
371
+ const [, sub, id] = positionals;
372
+ const opts = {
373
+ json,
374
+ for: str(values.for),
375
+ params: Array.isArray(values.param)
376
+ ? values.param.filter((p) => typeof p === "string")
377
+ : [],
378
+ bodyFile: str(values["body-file"]),
379
+ step: str(values.step),
380
+ result: str(values.result),
381
+ };
382
+ if (sub === "start" && id)
383
+ return guard(() => executionStart(io, id, opts));
384
+ if (sub === "record" && id)
385
+ return guard(() => executionRecord(io, id, opts));
386
+ return usage("cupola execution start <runbook> --for <epic|case> [--param <name>=<value>…] | execution record <execution> (--step <P#> --result done|stopped | --result finished|given-up) --body-file <f>");
338
387
  }
339
388
  case "spec": {
340
389
  const [, sub, spec] = positionals;
@@ -463,20 +512,28 @@ async function doctor(io, json, host = false) {
463
512
  ...c,
464
513
  checkout: across.checkouts.get(c.repo),
465
514
  }));
466
- const ok = across.problems.length === 0;
515
+ // Repositories not set up yet are not problems: the setup goes on, and doctor is ok once it is done.
516
+ const ok = across.problems.length === 0 && across.pending.length === 0;
467
517
  if (json) {
468
518
  io.out(JSON.stringify({
469
519
  ok,
470
520
  problems: across.problems,
521
+ pending: across.pending,
471
522
  warnings,
472
523
  components: listed,
473
524
  paths: config.paths,
474
525
  }));
475
526
  }
476
527
  else {
477
- io.out(ok ? "Configuration is valid." : "Configuration has problems:");
528
+ io.out(ok
529
+ ? "Configuration is valid."
530
+ : across.problems.length > 0
531
+ ? "Configuration has problems:"
532
+ : "Configuration is valid; repositories still to set up:");
478
533
  for (const p of across.problems)
479
534
  io.out(`problem: ${p}`);
535
+ for (const p of across.pending)
536
+ io.out(`pending: ${p}`);
480
537
  const where = (repo, path, checkout) => `${repo} ${path}${checkout ? ` (${checkout})` : ""}`;
481
538
  for (const c of listed)
482
539
  io.out(c.code
@@ -530,24 +587,55 @@ async function driftWarnings(root) {
530
587
  return out;
531
588
  }
532
589
  /** The code host (`doctor --host`): authentication, and squash merges on every repository. */
590
+ function derivedUrl(hubUrl, slug) {
591
+ try {
592
+ return hubUrl ? cloneUrl(hubUrl, slug) : undefined;
593
+ }
594
+ catch {
595
+ return undefined;
596
+ }
597
+ }
533
598
  async function hostWarnings(root, config) {
599
+ // Every repository a change is merged into, code included.
600
+ const all = reposOf(config);
601
+ const plain = all.filter((slug) => hostKindOf(config, slug) === "git");
602
+ const slugs = all.filter((slug) => !plain.includes(slug));
603
+ const out = [];
604
+ // A git host is reached through origin; its URL is the one it names, or the hub's with its name.
605
+ const hubUrl = await git(root, ["remote", "get-url", "origin"]).catch(() => "");
606
+ for (const slug of plain) {
607
+ const url = cloneUrlOf(config, slug) ?? derivedUrl(hubUrl, slug);
608
+ if (!url) {
609
+ out.push(`${slug}: no clone URL; name it in repositories.${slug}.url`);
610
+ continue;
611
+ }
612
+ try {
613
+ await git(root, ["ls-remote", "--heads", url], { timeoutMs: 30_000 });
614
+ }
615
+ catch {
616
+ out.push(`${slug}: ${url} cannot be reached (git's credentials for it)`);
617
+ }
618
+ }
619
+ if (slugs.length === 0)
620
+ return out;
534
621
  try {
535
622
  await gh(root, ["auth", "status"]);
536
623
  }
537
624
  catch {
538
- return ["the code host is not authenticated: `gh auth login`"];
625
+ return [...out, "the code host is not authenticated: `gh auth login`"];
539
626
  }
540
- // Every repository a change is merged into, code included.
541
- const slugs = reposOf(config);
542
627
  const squashes = await Promise.all(slugs.map((slug) => gh(root, ["api", `repos/${slug}`, "--jq", SQUASH_JQ]).catch(() => undefined)));
543
- return slugs.flatMap((slug, i) => {
544
- const squash = squashes[i];
545
- if (squash === undefined)
546
- return [`${slug}: its settings could not be read`];
547
- if (squash !== "true")
548
- return [`${slug} does not squash merges titled by the change: \`cupola setup host\``];
549
- return [];
550
- });
628
+ return [
629
+ ...out,
630
+ ...slugs.flatMap((slug, i) => {
631
+ const squash = squashes[i];
632
+ if (squash === undefined)
633
+ return [`${slug}: its settings could not be read`];
634
+ if (squash !== "true")
635
+ return [`${slug} does not squash merges titled by the change: \`cupola setup host\``];
636
+ return [];
637
+ }),
638
+ ];
551
639
  }
552
640
  /**
553
641
  * Components no e2e environment runs: their work is verified only
@@ -584,18 +672,21 @@ async function e2eWarnings(root, config, checkouts, here) {
584
672
  /**
585
673
  * With several repositories: every repository is cloned under
586
674
  * the hub, and its copy of the configuration on origin's default branch is the
587
- * hub's. A copy that differs is a problem: it would route work elsewhere.
675
+ * hub's. A copy that differs is a problem: it would route work elsewhere. A
676
+ * repository not cloned yet, or with no copy on its default branch yet, is
677
+ * pending: the setup is not done, nothing is wrong.
588
678
  */
589
679
  async function acrossRepositories(io, config) {
590
680
  const problems = [];
681
+ const pending = [];
591
682
  const warnings = [];
592
683
  const checkouts = new Map();
593
684
  const slugs = slugsOf(config);
594
685
  if (slugs.length === 1) {
595
686
  checkouts.set(config.hub, ".");
596
687
  if (reposOf(config).length > 1)
597
- await codeRepositories(io, problems, warnings, checkouts);
598
- return { problems, warnings, checkouts, here: config.hub };
688
+ await codeRepositories(io, problems, pending, warnings, checkouts);
689
+ return { problems, pending, warnings, checkouts, here: config.hub };
599
690
  }
600
691
  let ws;
601
692
  try {
@@ -603,13 +694,14 @@ async function acrossRepositories(io, config) {
603
694
  }
604
695
  catch (error) {
605
696
  problems.push(error.message);
606
- return { problems, warnings, checkouts, here: undefined };
697
+ return { problems, pending, warnings, checkouts, here: undefined };
607
698
  }
608
699
  const want = canonicalJson(config);
609
700
  // Each repository is checked at once; the results are gathered in the configuration's order.
610
701
  const results = await Promise.all(slugs.map(async (slug) => {
611
702
  const r = {
612
703
  problems: [],
704
+ pending: [],
613
705
  warnings: [],
614
706
  main: undefined,
615
707
  };
@@ -618,7 +710,7 @@ async function acrossRepositories(io, config) {
618
710
  main = ws.checkout(slug).main;
619
711
  }
620
712
  catch (error) {
621
- r.problems.push(error.message);
713
+ (error instanceof NotClonedError ? r.pending : r.problems).push(error.message);
622
714
  return r;
623
715
  }
624
716
  // Absolute: skills run `git -C <checkout>` from any worktree.
@@ -639,7 +731,9 @@ async function acrossRepositories(io, config) {
639
731
  raw = undefined;
640
732
  }
641
733
  if (raw === undefined) {
642
- r.problems.push(`${slug} has no ${CONFIG_PATH} on origin's default branch: copy the hub's there`);
734
+ r.pending.push(slug === config.hub
735
+ ? `${slug} has no ${CONFIG_PATH} on origin's ${branch} yet: merge the setup there`
736
+ : `${slug} has no ${CONFIG_PATH} on origin's ${branch} yet: install Cupola there with the hub's configuration (\`cupola init --config-file ${join(ws.hub.main, CONFIG_PATH)}\` in a worktree of it) and merge it`);
643
737
  return r;
644
738
  }
645
739
  let theirs;
@@ -667,16 +761,17 @@ async function acrossRepositories(io, config) {
667
761
  if (r.main !== undefined)
668
762
  checkouts.set(slug, r.main);
669
763
  problems.push(...r.problems);
764
+ pending.push(...r.pending);
670
765
  warnings.push(...r.warnings);
671
766
  });
672
- return { problems, warnings, checkouts, here: ws.here.slug };
767
+ return { problems, pending, warnings, checkouts, here: ws.here.slug };
673
768
  }
674
769
  /**
675
770
  * With every document in the hub: each repository that holds only
676
771
  * code is cloned under the hub. Cupola's files on its default branch are
677
772
  * reported: nothing of Cupola's belongs there, and its work never reads them.
678
773
  */
679
- async function codeRepositories(io, problems, warnings, checkouts) {
774
+ async function codeRepositories(io, problems, pending, warnings, checkouts) {
680
775
  let ws;
681
776
  try {
682
777
  ws = await workspace(io);
@@ -691,7 +786,7 @@ async function codeRepositories(io, problems, warnings, checkouts) {
691
786
  main = ws.checkout(slug).main;
692
787
  }
693
788
  catch (error) {
694
- problems.push(error.message);
789
+ (error instanceof NotClonedError ? pending : problems).push(error.message);
695
790
  continue;
696
791
  }
697
792
  checkouts.set(slug, main);
@@ -0,0 +1,110 @@
1
+ import { join } from "node:path";
2
+ import { byReviewer, trusted } from "./feedback.js";
3
+ import { parseFrontMatter } from "./frontmatter.js";
4
+ import { git } from "./git.js";
5
+ import { runDir, WorkError } from "./work.js";
6
+ /**
7
+ * The reactions of a work at its gate (comment, try, No-Go), wherever they
8
+ * were given: on the change, through the host's adapter, or in a session,
9
+ * kept as files in `.cupola/runs/<work>/reactions/` until a gate processes
10
+ * them. They are processed only at a gate of the epic (start, acceptance, release); what comes outside one
11
+ * waits for the next. Card answers are not here: they are recorded in the
12
+ * card files.
13
+ */
14
+ export const REACTION_KINDS = ["comment", "try", "no-go"];
15
+ /** Where a session's reactions to a work are kept until a gate processes them. */
16
+ export function reactionsDir(id) {
17
+ return join(runDir(id), "reactions");
18
+ }
19
+ /** How a session's reaction is named among the host's: `session:<n>`. */
20
+ export const SESSION = "session:";
21
+ /**
22
+ * The reactions given in a session, from their files. A file exists until a
23
+ * gate processes it, so none of them is answered.
24
+ */
25
+ export async function sessionReactions(tree, id) {
26
+ const dir = reactionsDir(id);
27
+ const out = [];
28
+ for (const file of (await tree.list(dir)).filter((f) => f.endsWith(".md"))) {
29
+ const where = join(dir, file);
30
+ const { data, body } = parseFrontMatter((await tree.read(where)) ?? "", where);
31
+ const kind = String(data.type ?? "");
32
+ if (data.kind !== "reaction" || typeof data.reaction !== "number")
33
+ throw new WorkError(`${where}: not a reaction`);
34
+ if (!REACTION_KINDS.includes(kind))
35
+ throw new WorkError(`${where}: type is ${REACTION_KINDS.join(", ")}, not ${kind}`);
36
+ out.push({
37
+ id: `${SESSION}${data.reaction}`,
38
+ author: String(data.who ?? ""),
39
+ association: "SESSION",
40
+ bot: false,
41
+ at: data.at instanceof Date ? data.at.toISOString() : String(data.at ?? ""),
42
+ kind,
43
+ body: body.replace(/<!--[\s\S]*?-->/g, "").trim(),
44
+ place: null,
45
+ answered: false,
46
+ });
47
+ }
48
+ return out.sort((a, b) => a.at.localeCompare(b.at));
49
+ }
50
+ /** The text of a session's reaction file (`templates/method-1/reaction.md`). */
51
+ export function reactionFile(n, kind, who, at, body) {
52
+ return `---\nkind: reaction\nmethod: 1\nreaction: ${n}\ntype: ${kind}\nwho: ${JSON.stringify(who)}\nat: ${JSON.stringify(at)}\n---\n\n${body.trim()}\n`;
53
+ }
54
+ /**
55
+ * People's reactions on a change: from someone the configuration trusts,
56
+ * neither a bot nor the configured reviewer (whose remarks are the review
57
+ * phase's). Anyone else's are never acted on.
58
+ */
59
+ export async function hostReactions(host, change, config) {
60
+ const { reviewer } = config.review;
61
+ const ok = (a) => trusted(a, reviewer, config.trust);
62
+ try {
63
+ const all = await host.reactions(change.number, ok);
64
+ return { reactions: all.filter((r) => !r.bot && ok(r) && !byReviewer(r, reviewer)) };
65
+ }
66
+ catch (error) {
67
+ return { reactions: [], unread: error.message };
68
+ }
69
+ }
70
+ export function pendingOf(reactions) {
71
+ return reactions
72
+ .filter((r) => !r.answered)
73
+ .map((r) => ({ id: r.id, kind: r.kind, who: r.author, at: r.at }));
74
+ }
75
+ /**
76
+ * The comments a No-Go takes in with its own words: those given since the
77
+ * last No-Go was processed (answered or not), for they are what this gate
78
+ * said. A No-Go with no words and none of these has no content.
79
+ */
80
+ export function gateComments(reactions) {
81
+ const last = reactions
82
+ .filter((r) => r.kind === "no-go" && r.answered)
83
+ .map((r) => r.at)
84
+ .sort()
85
+ .at(-1);
86
+ return reactions.filter((r) => r.kind === "comment" && (last === undefined || r.at > last));
87
+ }
88
+ /** The branch a try of a work is built on: an internal convention of `cupola-try`. */
89
+ export function tryBranch(id, n) {
90
+ return `${TRY_PREFIX}${id}/${n}`;
91
+ }
92
+ const TRY_PREFIX = "cupola-try/";
93
+ /** The tries of a work on origin, by number, oldest first. */
94
+ export async function triesOf(root, id) {
95
+ let out;
96
+ try {
97
+ out = await git(root, ["ls-remote", "--heads", "origin", `refs/heads/${TRY_PREFIX}${id}/*`]);
98
+ }
99
+ catch {
100
+ return [];
101
+ }
102
+ const prefix = `refs/heads/${TRY_PREFIX}${id}/`;
103
+ return out
104
+ .split("\n")
105
+ .map((l) => l.split("\t")[1] ?? "")
106
+ .filter((ref) => ref.startsWith(prefix))
107
+ .map((ref) => Number(ref.slice(prefix.length)))
108
+ .filter((n) => Number.isInteger(n) && n > 0)
109
+ .sort((a, b) => a - b);
110
+ }
package/dist/record.js CHANGED
@@ -31,7 +31,7 @@ const phase = z.strictObject({
31
31
  started: z.string().optional(),
32
32
  finished: z.string().optional(),
33
33
  note: z.string().optional(),
34
- /** For a skipped phase: the phase whose outcome skipped it, so that a send-back keeps the skip. */
34
+ /** For a skipped phase: the phase whose outcome skipped it, so that a No-Go keeps the skip. */
35
35
  skipped_by: z.string().optional(),
36
36
  /** The shared e2e environments its plan needs (an id, or `pool:<name>`); `run next` locks them. */
37
37
  needs: z.array(z.string()).optional(),
@@ -167,11 +167,21 @@ function bump(record) {
167
167
  record.serial += 1;
168
168
  return record;
169
169
  }
170
+ /**
171
+ * Whether a `--take-over` names this marker: by its id, or by the session holding it — the
172
+ * session itself, or one of its runners (`<session>-<component>`), as `cupola-epic-run <epic>
173
+ * --take-over <session>` names every marker of an epic's run at once.
174
+ */
175
+ export function takeOverNames(takeOver, held) {
176
+ if (!takeOver)
177
+ return false;
178
+ return (takeOver === held.id || takeOver === held.session || held.session.startsWith(`${takeOver}-`));
179
+ }
170
180
  /** Takes over another session's marker when it is named; returns whether the record changed. */
171
181
  function claim(record, runner) {
172
182
  const held = record.active;
173
183
  if (held && held.session !== runner.session) {
174
- if (runner.takeOver !== held.id) {
184
+ if (!takeOverNames(runner.takeOver, held)) {
175
185
  throw new RecordError(`${record.work.id} is being run by ${held.who} (session ${held.session}, since ${held.since}). ` +
176
186
  `If that session is gone, run again with --take-over ${held.id}`);
177
187
  }
@@ -188,10 +198,13 @@ function claim(record, runner) {
188
198
  }
189
199
  /** Effects of an answer that end the run; `cupola-decide` carries them out. */
190
200
  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) {
201
+ /**
202
+ * No-Go cards of a work's acceptance, answered (they name the phase to redo) and
203
+ * written after the record started, oldest first.
204
+ */
205
+ export function pendingNoGos(record, cards) {
193
206
  const since = record?.started_from.card ?? 0;
194
- return cards.filter((c) => c.type === "send-back" && c.card > since);
207
+ return cards.filter((c) => c.type === "no-go" && c.answered && c.effect === "continue" && c.card > since);
195
208
  }
196
209
  /**
197
210
  * An answered card of this record whose effect ends the run (abort, revise
@@ -203,10 +216,32 @@ export function endingCard(record, cards) {
203
216
  return cards.find((c) => c.card > since && c.effect !== null && ENDING_EFFECTS.has(c.effect));
204
217
  }
205
218
  /**
206
- * Starts a new record from send-backs: the phases they touch are
219
+ * Sends a full spec's run back to its acceptance tests for an agreed revision
220
+ * that redesigns it: the tests were written from the examples the revision may
221
+ * change. Changes `record` in place.
222
+ */
223
+ export function redoFromAcceptance(record) {
224
+ const order = record.phases.map((p) => p.name);
225
+ const from = order.indexOf("acceptance");
226
+ if (from < 0)
227
+ return;
228
+ for (const p of record.phases.slice(from)) {
229
+ if (p.state === "done")
230
+ p.state = "redo";
231
+ else if (p.state === "running")
232
+ p.state = "pending";
233
+ else if (p.state === "skipped" && p.skipped_by && order.indexOf(p.skipped_by) >= from) {
234
+ p.state = "pending";
235
+ delete p.skipped_by;
236
+ delete p.note;
237
+ }
238
+ }
239
+ }
240
+ /**
241
+ * Starts a new record from No-Go cards: the phases they touch are
207
242
  * to be redone from the earliest one named, and the phases before it are done.
208
243
  */
209
- export function createFromSendBacks(work, maxRounds, sendBacks, now, previous,
244
+ export function createFromNoGos(work, maxRounds, noGos, now, previous,
210
245
  /** Whether `previous` is the record a finish removed: its drafts are filed already. */
211
246
  finished = false) {
212
247
  const record = createRecord(work, maxRounds);
@@ -217,16 +252,16 @@ finished = false) {
217
252
  record.drafts = [...previous.drafts];
218
253
  }
219
254
  const order = record.phases.map((p) => p.name);
220
- for (const c of sendBacks) {
255
+ for (const c of noGos) {
221
256
  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)}`);
257
+ throw new RecordError(`No-Go card ${c.card}: redo must name a phase of this work, not ${String(c.redo)}`);
223
258
  }
224
259
  }
225
- const from = Math.min(...sendBacks.map((c) => order.indexOf(c.redo)));
260
+ const from = Math.min(...noGos.map((c) => order.indexOf(c.redo)));
226
261
  record.phases.forEach((p, i) => {
227
262
  if (i < from && p.state !== "skipped") {
228
263
  p.state = "done";
229
- p.note = "done before the send-back";
264
+ p.note = "done before the No-Go";
230
265
  }
231
266
  // A later phase skipped by a phase that does not run again stays skipped.
232
267
  const before = previous?.phases.find((q) => q.name === p.name);
@@ -236,14 +271,13 @@ finished = false) {
236
271
  Object.assign(p, { state: "skipped", note: before.note, skipped_by: before.skipped_by });
237
272
  }
238
273
  });
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.
274
+ const numbers = noGos.map((c) => c.card).sort((a, b) => a - b);
241
275
  record.started_from.card = numbers.at(-1) || null;
242
276
  record.events.push({
243
277
  at: now,
244
278
  phase: order[from],
245
- what: "sent-back",
246
- note: sendBacks.map((c) => c.label ?? `card ${c.card}`).join(", ") +
279
+ what: "no-go",
280
+ note: noGos.map((c) => `card ${c.card}`).join(", ") +
247
281
  (previous ? ` (after lineage ${previous.lineage})` : ""),
248
282
  });
249
283
  return record;
@@ -265,7 +299,7 @@ export function next(current, cards, runner) {
265
299
  };
266
300
  const unanswered = cards.filter((c) => !c.answered).map((c) => c.card);
267
301
  if (unanswered.length > 0) {
268
- return stop("G2", `cards waiting for a decision: ${unanswered.join(", ")}`);
302
+ return stop("decision", `cards waiting for a decision: ${unanswered.join(", ")}`);
269
303
  }
270
304
  const ending = endingCard(record, cards);
271
305
  if (ending) {
@@ -277,7 +311,7 @@ export function next(current, cards, runner) {
277
311
  const spent = record.events.filter((e) => e.what === "review-budget-spent").at(-1);
278
312
  return stop(
279
313
  // An epic's own run ends at the release gate.
280
- record.work.mode === "epic" ? "G4" : "G3", spent
314
+ record.work.mode === "epic" ? "release" : "acceptance", spent
281
315
  ? `every phase is done; review budget spent: ${spent.note ?? ""}`
282
316
  : "every phase is done; look back over the record, then finish with `cupola run finish`");
283
317
  }
@@ -450,7 +484,7 @@ export function recordOutcome(current, outcome, runner, cards = []) {
450
484
  what: outcome.result === "cards" ? "card" : "not-a-fix",
451
485
  note: (outcome.cards ?? []).join(", ") || outcome.note,
452
486
  });
453
- return stop(outcome.result === "cards" ? "G2" : "not-a-fix", outcome.note);
487
+ return stop(outcome.result === "cards" ? "decision" : "not-a-fix", outcome.note);
454
488
  case "blocked":
455
489
  finish("pending");
456
490
  record.events.push({