@williacj/rigger 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +370 -2
  3. package/package.json +56 -4
  4. package/scripts/doc-reference-check.mjs +59 -0
  5. package/scripts/gate-check.mjs +249 -0
  6. package/scripts/lib/pack-result.mjs +9 -0
  7. package/scripts/record-commit.mjs +67 -0
  8. package/src/cli/doctor.mjs +1021 -0
  9. package/src/cli/init.mjs +384 -0
  10. package/src/cli/once.mjs +489 -0
  11. package/src/cli/pause.mjs +56 -0
  12. package/src/cli/plan.mjs +106 -0
  13. package/src/cli/recording.mjs +52 -0
  14. package/src/cli/report.mjs +242 -0
  15. package/src/cli/resume.mjs +96 -0
  16. package/src/cli/rigger.mjs +12 -0
  17. package/src/cli/run.mjs +10 -0
  18. package/src/cli/setup-board.mjs +108 -0
  19. package/src/cli/verbs.mjs +82 -0
  20. package/src/cli/verdict.mjs +180 -0
  21. package/src/config/validate.mjs +960 -0
  22. package/src/execution/groups.mjs +185 -0
  23. package/src/execution/kept-output.mjs +21 -0
  24. package/src/execution/role.mjs +171 -0
  25. package/src/execution/run.mjs +490 -0
  26. package/src/execution/step.mjs +26 -0
  27. package/src/execution/workspace.mjs +866 -0
  28. package/src/observation/push.mjs +103 -0
  29. package/src/observation/report.mjs +415 -0
  30. package/src/observation/sink.mjs +271 -0
  31. package/src/package-commit.json +1 -0
  32. package/src/scheduling/admission.mjs +390 -0
  33. package/src/scheduling/clock.mjs +98 -0
  34. package/src/scheduling/lane.mjs +160 -0
  35. package/src/scheduling/loop.mjs +1738 -0
  36. package/src/scheduling/pull-order.mjs +46 -0
  37. package/src/substrate/data-ref.mjs +147 -0
  38. package/src/substrate/forge/assets.mjs +5 -0
  39. package/src/substrate/forge/graphql.mjs +258 -0
  40. package/src/substrate/forge/item-write.mjs +74 -0
  41. package/src/substrate/forge/read.mjs +998 -0
  42. package/src/substrate/forge/repository-write.mjs +152 -0
  43. package/src/substrate/forge/runners.mjs +510 -0
  44. package/src/substrate/forge/schema-write.mjs +70 -0
  45. package/src/substrate/forge/write-made.mjs +40 -0
  46. package/src/substrate/git-environment.mjs +54 -0
  47. package/src/substrate/host.mjs +23 -0
  48. package/src/substrate/launchd.mjs +23 -0
  49. package/src/substrate/process-table.sh +48 -0
  50. package/src/substrate/process.mjs +2474 -0
  51. package/src/substrate/providers/adapters.mjs +8 -0
  52. package/src/substrate/providers/claude.mjs +427 -0
  53. package/src/substrate/providers/codex.mjs +349 -0
  54. package/src/substrate/standard-error.mjs +134 -0
  55. package/src/substrate/worktrees.mjs +517 -0
  56. package/src/workflow/clock-mark.mjs +40 -0
  57. package/src/workflow/escalation.mjs +110 -0
  58. package/src/workflow/facts.mjs +92 -0
  59. package/src/workflow/first-above.mjs +17 -0
  60. package/src/workflow/form-check.mjs +88 -0
  61. package/src/workflow/gate.mjs +62 -0
  62. package/src/workflow/judges.mjs +695 -0
  63. package/src/workflow/marker.mjs +265 -0
  64. package/src/workflow/next-action.mjs +456 -0
  65. package/src/workflow/status-issue.mjs +268 -0
  66. package/src/workflow/transitions.mjs +588 -0
  67. package/templates/claude/agents/architect.md +116 -0
  68. package/templates/claude/agents/engineer.md +57 -0
  69. package/templates/claude/agents/pm.md +114 -0
  70. package/templates/claude/agents/reviewer.md +37 -0
  71. package/templates/claude/agents/spike-engineer.md +80 -0
  72. package/templates/claude/hooks/refuse-reserved-git-commands.mjs +909 -0
  73. package/templates/claude/settings.json +50 -0
  74. package/templates/claude/skills/acceptance/SKILL.md +275 -0
  75. package/templates/claude/skills/agent-style/SKILL.md +78 -0
  76. package/templates/claude/skills/code-review/SKILL.md +242 -0
  77. package/templates/claude/skills/proposal/SKILL.md +175 -0
  78. package/templates/claude/skills/spec-style/SKILL.md +112 -0
  79. package/templates/claude/skills/tdd/SKILL.md +230 -0
  80. package/templates/codex/config.toml +19 -0
  81. package/templates/doc-reference-check.md +25 -0
  82. package/templates/githooks/pre-push +24 -0
  83. package/templates/github/workflows/rigger-gate.yml +209 -0
  84. package/templates/launchd/com.williacj.rigger.plist +31 -0
  85. package/templates/rigger.config.mjs +78 -0
@@ -0,0 +1,180 @@
1
+ // ABOUTME: The `verdict` verb: the owner's verdict on a pull request, built against the round the gate
2
+ // reads, shown whole, and posted as one comment once the owner confirms it on the terminal at
3
+ // standard input. It never edits or deletes a comment, and nothing it reads skips the question.
4
+
5
+ import { createInterface } from 'node:readline';
6
+
7
+ import { validate, worktreeTopic } from '../config/validate.mjs';
8
+ import { cardOfBranch } from '../execution/workspace.mjs';
9
+ import { repositoryReads } from '../substrate/forge/read.mjs';
10
+ import { repositoryWriteSide } from '../substrate/forge/repository-write.mjs';
11
+ import { acceptanceItems, checkAcceptanceForm } from '../workflow/form-check.mjs';
12
+ import { OWNER } from '../workflow/gate.mjs';
13
+ import { acceptanceDigest, composeMarker } from '../workflow/marker.mjs';
14
+ import { unrecordedNamed } from '../workflow/transitions.mjs';
15
+ import { PACKAGE, consumerConfig, settled } from './doctor.mjs';
16
+ import { CONFIG } from './init.mjs';
17
+ import { recording } from './recording.mjs';
18
+
19
+ /** The verdict each word the owner gives names, among the three `R-VERDICT-2` fixes. */
20
+ const VERDICTS = { sound: 'sound', 'needs-revision': 'needs revision', critical: 'critical' };
21
+
22
+ /** The options the verb names, each taking one value. */
23
+ const OPTIONS = ['--to-sound', '--unmet', '--insufficient'];
24
+
25
+ /** What a value the marker writes on one line may not hold: the line endings its parse splits on and those `.` does not match. */
26
+ const BREAK = /[\n\r\u2028\u2029]/;
27
+
28
+ /** What the verb prints and exits with where it posts nothing, for `why`. */
29
+ const refused = (why) => ({ text: `rigger verdict: ${why}, so nothing is posted`, code: 1 });
30
+
31
+ /**
32
+ * The owner's verdict as `args` give it, `{ pull, verdict, unmet, toSound, insufficient }`, or `{
33
+ * refusal }` naming why it is none. Item numbers past the acceptance's count are checked once the
34
+ * card is read.
35
+ */
36
+ function ruling(args) {
37
+ const [pull, word, ...rest] = args;
38
+ if (pull === undefined) return { refusal: 'it was given no pull request number' };
39
+ if (!/^[1-9][0-9]*$/.test(pull) || !Number.isSafeInteger(Number(pull))) return { refusal: `${JSON.stringify(pull)} is not a pull request number` };
40
+ if (word === undefined) return { refusal: `it was given no verdict: give one of ${Object.keys(VERDICTS).join(', ')}` };
41
+ if (!Object.hasOwn(VERDICTS, word)) return { refusal: `${JSON.stringify(word)} is no verdict: give one of ${Object.keys(VERDICTS).join(', ')} (\`R-VERDICT-2\`)` };
42
+ const given = {};
43
+ for (let at = 0; at < rest.length; at += 2) {
44
+ const option = rest[at];
45
+ if (!OPTIONS.includes(option)) {
46
+ return { refusal: option.startsWith('-') ? `${JSON.stringify(option)} is an option it does not name` : `${JSON.stringify(option)} is an argument past those it names` };
47
+ }
48
+ if (Object.hasOwn(given, option)) return { refusal: `${option} is given twice` };
49
+ const value = rest[at + 1];
50
+ if (value === undefined || OPTIONS.includes(value)) return { refusal: `${option} is given no value` };
51
+ if (option !== '--unmet' && value.trim() === '') return { refusal: `${option}'s value is empty` };
52
+ if (option !== '--unmet' && BREAK.test(value)) return { refusal: `${option}'s value holds a line break, and it is written on one line` };
53
+ given[option] = value;
54
+ }
55
+ const verdict = VERDICTS[word];
56
+ if (verdict === 'sound' && given['--unmet'] !== undefined) return { refusal: 'a sound verdict rules no item unmet (`R-VERDICT-4`)' };
57
+ if (verdict === 'sound' && given['--to-sound'] !== undefined) return { refusal: 'a sound verdict names nothing that would make it sound' };
58
+ if (verdict !== 'sound' && given['--to-sound'] === undefined) return { refusal: `a ${verdict} verdict names what would make the work sound, with --to-sound (\`R-VERDICT-3\`)` };
59
+ const listed = given['--unmet'];
60
+ if (listed !== undefined && !/^[0-9]+(?:,[0-9]+)*$/.test(listed)) return { refusal: `--unmet ${JSON.stringify(listed)} is not item numbers, as <n>[,<n>...]` };
61
+ const unmet = listed === undefined ? [] : listed.split(',').map(Number);
62
+ if (unmet.includes(0)) return { refusal: '--unmet names item 0, and the items are numbered from 1' };
63
+ const twice = unmet.find((item, at) => unmet.indexOf(item) !== at);
64
+ if (twice !== undefined) return { refusal: `--unmet names item ${twice} twice` };
65
+ return { pull: Number(pull), verdict, unmet, toSound: given['--to-sound'], insufficient: given['--insufficient'] };
66
+ }
67
+
68
+ /** The first line `input` gives, without its ending, or null where it ends before one. */
69
+ function lineFrom(input) {
70
+ const lines = createInterface({ input, terminal: false });
71
+ return new Promise((resolve) => {
72
+ lines.once('line', (line) => {
73
+ resolve(line);
74
+ lines.close();
75
+ });
76
+ lines.once('close', () => resolve(null));
77
+ });
78
+ }
79
+
80
+ /**
81
+ * What the command prints for a `verdict` run, and the status it exits with. `args` are the words
82
+ * after the verb. It asks only on a terminal at its standard input, and reads the answer there
83
+ * (`R-VERDICT-10`).
84
+ */
85
+ export async function verdict({ args = [] } = {}) {
86
+ const given = ruling(args);
87
+ if (given.refusal) return refused(given.refusal);
88
+ if (process.stdin.isTTY !== true) return refused('its standard input is no terminal, so it has no terminal to ask on');
89
+ return recording((opened) => posting(opened, given));
90
+ }
91
+
92
+ /** `verdict`'s work once the owner's verdict is read, recording through the sink `opened` holds. */
93
+ async function posting(opened, given) {
94
+ const { named, refusal } = await settled('verdict', opened, { target: process.cwd(), packageRoot: PACKAGE });
95
+ if (refusal) return refusal;
96
+ const { config, problem } = await consumerConfig(named);
97
+ if (problem) return refused(problem);
98
+ const refusals = validate(config);
99
+ if (refusals.length > 0) return refused(`\`${CONFIG}\` in ${named} is refused: ${refusals.join('; ')}`);
100
+ const emitter = opened.sink.emitter({ layer: 'L0' });
101
+ // The verb reads the repository its config names and no board, so its reads name none.
102
+ const forge = { repo: config.repo, project: 'none' };
103
+ const reads = repositoryReads(forge, { emitter });
104
+ const read = async (what, reading) => {
105
+ try {
106
+ return { value: await reading() };
107
+ } catch (error) {
108
+ return { problem: `the read of ${what} failed: ${error.message}` };
109
+ }
110
+ };
111
+
112
+ // The gate's own read of the default branch's config, loaded here rather than with the verb
113
+ // table, so no other verb's start loads the gate check script.
114
+ const { defaultConfig } = await import('../../scripts/gate-check.mjs');
115
+ const main = await defaultConfig(reads, config.repo);
116
+ if (main.problem) return refused(`the config in ${named} names ${config.repo}, whose default branch's config answers: ${main.problem}`);
117
+ const number = given.pull;
118
+ const pulled = await read(`pull request #${number}`, () => reads.readPullRequestByNumber(number));
119
+ if (pulled.problem) return refused(pulled.problem);
120
+ const pull = pulled.value;
121
+ if (!pull.fromRepository) return refused(`pull request #${number}'s head is in ${pull.headRepository ?? 'a deleted repository'}, not ${config.repo}`);
122
+ if (pull.state !== 'open') return refused(`pull request #${number} is ${pull.state}, not open`);
123
+ const topic = worktreeTopic(main.config);
124
+ const card = cardOfBranch(topic, pull.branch);
125
+ if (card === null) return refused(`pull request #${number}'s branch ${pull.branch} names no card under the default branch's topic rule \`${topic}\``);
126
+ const issued = await read(`issue #${card}`, () => reads.readIssue(card));
127
+ if (issued.problem) return refused(issued.problem);
128
+ const issue = issued.value;
129
+ if (issue === null) return refused(`pull request #${number}'s branch ${pull.branch} names #${card}, which is no issue in ${config.repo}`);
130
+ const form = checkAcceptanceForm(issue);
131
+ if (!form.admitted) return refused(`card #${card}'s acceptance fails the form check: ${form.reason}`);
132
+ const items = acceptanceItems(issue.body);
133
+ const past = given.unmet.find((item) => item > items.length);
134
+ if (past !== undefined) return refused(`--unmet names item ${past}, and card #${card}'s acceptance holds ${items.length} items`);
135
+
136
+ const marker = {
137
+ card,
138
+ pull: number,
139
+ head: pull.head,
140
+ digest: acceptanceDigest(issue.body),
141
+ role: OWNER,
142
+ verdict: given.verdict,
143
+ items: items.map((_, at) => (given.unmet.includes(at + 1) ? 'unmet' : 'met')),
144
+ coverage: given.insufficient === undefined ? 'covered' : 'insufficient',
145
+ coverageReason: given.insufficient,
146
+ toSound: given.toSound,
147
+ };
148
+ const body = composeMarker(marker, `The owner's verdict on pull request #${number}: ${given.verdict}.`);
149
+ process.stdout.write([
150
+ `rigger verdict: the comment it posts on pull request #${number} once you confirm it:`,
151
+ '',
152
+ body,
153
+ `The acceptance items of card #${card}, each with its ruling:`,
154
+ ...items.map((item, at) => ` ${at + 1}. ${marker.items[at]}: ${item}`),
155
+ '',
156
+ `Post this comment as your verdict on pull request #${number}? [y/N] `,
157
+ ].join('\n'));
158
+ const answer = await lineFrom(process.stdin);
159
+ if (answer === null) return refused('standard input ended before an answer');
160
+ if (!/^(?:y|yes)$/i.test(answer)) return refused(`the answer was ${JSON.stringify(answer)}, not y or yes`);
161
+
162
+ // The round is read again, so a verdict shown against one head or acceptance never lands on another.
163
+ const again = await read(`pull request #${number}`, () => reads.readPullRequestByNumber(number));
164
+ if (again.problem) return refused(again.problem);
165
+ if (again.value.state !== 'open') return refused(`pull request #${number} is ${again.value.state}, not open, after the verdict was shown`);
166
+ if (again.value.head !== pull.head) return refused(`pull request #${number}'s head moved from ${pull.head} to ${again.value.head} after the verdict was shown`);
167
+ const reissued = await read(`issue #${card}`, () => reads.readIssue(card));
168
+ if (reissued.problem) return refused(reissued.problem);
169
+ if (reissued.value === null || acceptanceDigest(reissued.value.body) !== marker.digest) return refused(`card #${card}'s acceptance changed after the verdict was shown`);
170
+
171
+ let posted;
172
+ try {
173
+ posted = await repositoryWriteSide(forge, { emitter }).postComment(number, body);
174
+ } catch (error) {
175
+ // A post the repository-write side marked made is on the pull request; only its record was refused.
176
+ if (error.made) return { text: `rigger verdict: posted the owner's verdict on pull request #${number}: ${error.made.answer.html_url}, and the event sink refused to record it: ${unrecordedNamed(error)}`, code: 1 };
177
+ return { text: `rigger verdict: the post failed, and it is not tried again: ${error.message}`, code: 1 };
178
+ }
179
+ return { text: `rigger verdict: posted the owner's verdict on pull request #${number}: ${posted.html_url}`, code: 0 };
180
+ }