@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,52 @@
1
+ // ABOUTME: What every verb that opens L5's sink shares: the state directory's name, and the one way a
2
+ // verb opens its sink, hands L0 its end, and ends it on every path the verb returns through.
3
+
4
+ import { randomUUID } from 'node:crypto';
5
+ import { join } from 'node:path';
6
+
7
+ import { openSink } from '../observation/sink.mjs';
8
+ import { atExit } from '../substrate/process.mjs';
9
+
10
+ /**
11
+ * The state directory, where L5's stream lives. `ARCHITECTURE.md`'s Engine settings row names
12
+ * `.rigger/` as its default, and the published config shape offers no key to name another.
13
+ */
14
+ export const STATE = '.rigger';
15
+
16
+ /**
17
+ * What `work` answers, handed the run's sink, opened before `work` makes any spawn; `run`, the run
18
+ * id the sink stamps on every event, which a verb hands what it writes rather than drawing an id of
19
+ * its own (the architect's placement ruling, finding 4, on #937); `name`, which names the state
20
+ * directory in the repository `named` once the guard has settled it; and `admitted`, by which the
21
+ * verb names the config it read once the validator admitted it.
22
+ *
23
+ * L0 is handed the sink's end when it opens, so an ending the verb does not return through, a
24
+ * signal among them, still ends it after L0's kills. The sink is ended on every path `work`
25
+ * returns or throws through, and ending it twice writes nothing more (the architect's ruling 3,
26
+ * §3, on #332).
27
+ *
28
+ * `push`, where given, is L5's push, which `src/cli/verbs.mjs` hands `run` and `once` alone
29
+ * (`R-RECORD-20`): once `work` returns normally, having named both a repository and a config, and
30
+ * before the sink ends, it is handed the sink, the run, that config, that repository and its state
31
+ * directory, and the verb's answer, and answers the answer the verb gives. A path that throws, a
32
+ * signal and exit cleanup never reach it, and a caller handing none, as every other verb and the
33
+ * gate script do, never pushes (the architect's attack on #1122, placement A).
34
+ */
35
+ export async function recording(work, push) {
36
+ const run = randomUUID();
37
+ const sink = openSink({ run, now: Date.now });
38
+ atExit(sink.end);
39
+ let repository;
40
+ let config;
41
+ const name = (named) => {
42
+ sink.name(join(named, STATE));
43
+ repository = named;
44
+ };
45
+ try {
46
+ const answer = await work({ sink, run, name, admitted: (read) => { config = read; } });
47
+ if (push === undefined || repository === undefined || config === undefined) return answer;
48
+ return await push({ sink, run, config, repository, directory: join(repository, STATE), answer });
49
+ } finally {
50
+ sink.end();
51
+ }
52
+ }
@@ -0,0 +1,242 @@
1
+ // ABOUTME: The `report` verb: prints L5's derived signals, one section per layer, and unmatched
2
+ // marker reads from the consumer's event stream, and refuses its own source tree.
3
+
4
+ import { join } from 'node:path';
5
+
6
+ import { HOUR, report as derive } from '../observation/report.mjs';
7
+ import { PACKAGE, outsideText, settled } from './doctor.mjs';
8
+ import { STATE, recording } from './recording.mjs';
9
+
10
+ /** A figure as printed: to four decimal places at most, which states every value a test sets exactly. */
11
+ const figure = (value) => String(Number(value.toFixed(4)));
12
+
13
+ /** A duration in milliseconds, printed in hours. */
14
+ const hours = (ms) => `${figure(ms / HOUR)} h`;
15
+
16
+ /**
17
+ * A value from the stream as a JSON-quoted site prints it. Any of them comes from the stream, where
18
+ * any string can stand (boundary rule 4), so a number prints as itself, -0 as `-0`, which `String`
19
+ * would print as `0`, and every other value as JSON, through `outsideText`. JSON quotes every string
20
+ * and escapes the quotes and backslashes in it, and `outsideText` the line breaks JSON leaves raw,
21
+ * so no value can print a boundary of the list or line it stands in: one dispatch, role or author
22
+ * never prints as two, and none breaks a line. A value printed unquoted passes through
23
+ * `outsideText` alone, which keeps it as written but for its breaks and controls.
24
+ */
25
+ const shown = (value) => {
26
+ if (Object.is(value, -0)) return '-0';
27
+ return typeof value === 'number' ? String(value) : outsideText(JSON.stringify(value) ?? String(value));
28
+ };
29
+
30
+ /** The lines one run's queue carried prints as: one per L3 `pull`, in line order, or one saying it recorded none. */
31
+ const queueLines = (queue) => (queue.length === 0
32
+ ? [' the run recorded no pull, so L3 has no queue carried for it']
33
+ : queue.map(({ card, queueDepth }) => ` queue carried at the pull of card #${outsideText(card)}: ${outsideText(queueDepth)}`));
34
+
35
+ /** The lines one run's L3 signals print as, each figure beside the facts it was computed from, then its queue carried. */
36
+ function runLines({ run, from, to, releases, pulled, n, throughput, utilization, queue }) {
37
+ const span = to - from;
38
+ const heading = ` run ${outsideText(run)}: from ${new Date(from).toISOString()} to ${new Date(to).toISOString()}, a span of ${hours(span)}`;
39
+ if (span === 0) return [heading, ' the span is zero, so L3 has no throughput and no utilization for this run', ...queueLines(queue)];
40
+ return [
41
+ heading,
42
+ ` L3 throughput: ${figure(throughput)} slot releases per hour (${releases} slot releases over ${hours(span)})`,
43
+ utilization === null
44
+ ? ' the run recorded no N, so L3 has no utilization for it'
45
+ : ` L3 utilization: ${figure(utilization)} (${hours(pulled)} from pull to release, over N ${outsideText(n)} x ${hours(span)})`,
46
+ ...queueLines(queue),
47
+ ];
48
+ }
49
+
50
+ /** A rate's line, beside its numerator and denominator, or why there is none where the denominator is zero. */
51
+ const rateLine = (name, part, whole, { counted, of, none }) => (of === 0
52
+ ? ` no ${name}: ${none}`
53
+ : ` ${name}: ${figure(counted / of)} (${part} ${counted}, over ${whole} ${of})`);
54
+
55
+ /** The survivor rate's line, `where` naming the run or the stream it is over. */
56
+ const survivorLine = ({ killed, of }, where) => rateLine('survivor rate', 'dispatches with a survivor or group killed', 'dispatches that ended with a result',
57
+ { counted: killed, of, none: `no dispatch in ${where} ended with a result` });
58
+
59
+ /** A system's fault rate line, `where` naming the run or the stream it is over. */
60
+ const faultLine = (system, { faults, calls }, where) => rateLine(`${system} fault rate`,
61
+ `${system} calls that failed or timed out`, `${system} calls`, { counted: faults, of: calls, none: `no ${system} call in ${where}` });
62
+
63
+ /** The lines L0's section prints under its heading: each run's forge and git fault rates, then the stream's. */
64
+ function l0Lines({ runs, stream }) {
65
+ return [
66
+ ...runs.flatMap(({ run, forge, git }) => [` run ${outsideText(run)}`, faultLine('forge', forge, 'this run'), faultLine('git', git, 'this run')]),
67
+ ' across the stream',
68
+ faultLine('forge', stream.forge, 'the stream'),
69
+ faultLine('git', stream.git, 'the stream'),
70
+ ];
71
+ }
72
+
73
+ /** The lines L1's section prints under its heading: each run's durations and survivor rate, then the stream's. */
74
+ function l1Lines({ runs, stream }) {
75
+ return [
76
+ ...runs.flatMap(({ run, durations, survivors }) => [
77
+ ` run ${outsideText(run)}`,
78
+ ...durations.map(({ dispatch, card, ms }) => ` dispatch ${outsideText(dispatch)}${card === undefined ? '' : `, card #${outsideText(card)}`}: ${outsideText(ms)} ms`),
79
+ survivorLine(survivors, 'this run'),
80
+ ]),
81
+ ' across the stream',
82
+ ` dispatch.end events: ${stream.ended}, each listed under its run`,
83
+ survivorLine(stream.survivors, 'the stream'),
84
+ ` redos after an interruption: ${stream.redos.length}, first attempts: ${stream.firstAttempts}`,
85
+ ...stream.redos.map(({ card, run }) => ` redo after an interruption: card #${outsideText(card)}, run ${outsideText(run)}`),
86
+ ];
87
+ }
88
+
89
+ /** The escalation rate over the named span, beside its distinct card counts. */
90
+ const escalationLine = ({ escalated, pulled }, where) => rateLine('escalation rate', 'cards escalated', 'cards pulled',
91
+ { counted: escalated, of: pulled, none: `no card pulled in ${where}` });
92
+
93
+ /** Each escalation in line order, with subsequent reason lines indented two spaces further. */
94
+ function escalationLines(entries) {
95
+ return entries.flatMap(({ card, category, raiser, reason, destination }) => {
96
+ const [first, ...later] = String(reason).split('\n');
97
+ return [
98
+ ` card #${outsideText(card)}, category ${outsideText(category)}, raiser ${outsideText(raiser)}${destination == null ? '' : `, destination ${shown(destination)}`}: ${outsideText(first)}`,
99
+ ...later.map((line) => ` ${outsideText(line)}`),
100
+ ];
101
+ });
102
+ }
103
+
104
+ /** Across-stream rounds grouped by kind; only cards the rounds derivation supplies are listed. */
105
+ function roundLines(rounds) {
106
+ const kinds = new Map();
107
+ for (const row of rounds) {
108
+ if (!kinds.has(row.kind)) kinds.set(row.kind, []);
109
+ kinds.get(row.kind).push(row);
110
+ }
111
+ return [' rounds per card, by kind of work', ...[...kinds].flatMap(([kind, cards]) => [
112
+ kind === null ? ' no kind' : ` kind ${shown(kind)}`,
113
+ ...cards.map(({ card, rounds: count }) => ` card #${outsideText(card)}: ${count} round${count === 1 ? '' : 's'}`),
114
+ ])];
115
+ }
116
+
117
+ /** Event counts by recorded class, with infrastructure totals beside each run and stream count. */
118
+ function causeLines({ runs, stream }) {
119
+ const counted = (where, { classes, infrastructure }) => [
120
+ ` escalations by cause ${where}: ${classes.map(({ class: cause, count }) => `${cause === null ? 'unclassified' : shown(cause)} ${count}`).join(', ') || 'none'}`,
121
+ ` infrastructure-caused escalations ${where}: ${infrastructure}`,
122
+ ];
123
+ return [...runs.flatMap((each) => counted(`in run ${shown(each.run)}`, each)), ...counted('across the stream', stream)];
124
+ }
125
+
126
+ /** Fresh-verdict proof's card rate, and each merged card without qualifying proof. */
127
+ function freshLines({ fresh, of, flagged }) {
128
+ return [
129
+ rateLine('merges with fresh verdicts', 'proved cards', 'merged cards', { counted: fresh, of, none: 'no card merged in the stream' }),
130
+ ...flagged.map((card) => ` flagged merged card #${outsideText(card)}: no qualifying merge decision and later merged end`),
131
+ ];
132
+ }
133
+
134
+ /** Admission hold counts, with literal ids and reasons and any matching open beside each hold. */
135
+ function holdLines({ runs, stream }) {
136
+ return [
137
+ ` admission holds across the stream: ${stream.count}`,
138
+ ...runs.flatMap(({ run, count, entries }) => [
139
+ ` admission holds in run ${shown(run)}: ${count}`,
140
+ ...entries.map(({ id, reason, opened }) => ` hold ${shown(id)}: ${shown(reason)}${opened ? `; admission.open ${shown(id)}` : ''}`),
141
+ ]),
142
+ ];
143
+ }
144
+
145
+ /** A heading and its lines, or `none` beneath it where there are none. */
146
+ const listed = (heading, lines) => [heading, ...(lines.length === 0 ? [' none'] : lines)];
147
+
148
+ /** The acceptance changes across the stream, as L2 prints them: changes, deleted content, growth, the maker's changes, and authors. */
149
+ function acceptanceLines({ changes, deleted, grew, authors }) {
150
+ const by = (dispatches) => dispatches.map(({ dispatch, role }) => `, dispatch ${shown(dispatch)} (role ${shown(role)})`).join('');
151
+ const at = (card, editedAt) => ` card #${shown(card)} at ${shown(editedAt)}`;
152
+ return [
153
+ ...listed(' acceptance changes, each with who made it', changes.map(({ card, editedAt, editor, dispatches }) =>
154
+ `${at(card, editedAt)}: editor ${shown(editor)}${by(dispatches)}`)),
155
+ ...listed(' content deleted from a card\'s history', deleted.map(({ card, editedAt, editor }) =>
156
+ `${at(card, editedAt)}: editor ${shown(editor)}`)),
157
+ ...listed(' acceptances that grew after admission', grew.map(({ card, editedAt, items, admitted }) =>
158
+ `${at(card, editedAt)}: ${shown(items)} items, over ${shown(admitted)} at its first pull`)),
159
+ ...listed(' acceptance changes made during the card\'s maker dispatch', changes.filter(({ duringMaker }) => duringMaker)
160
+ .map(({ card, editedAt }) => at(card, editedAt))),
161
+ ...listed(' each card\'s author', authors.map(({ card, source, names }) => {
162
+ if (source === 'author') return ` card #${shown(card)}: ${shown(names[0])}, as its acceptance.history records`;
163
+ if (source === 'dispatches') return ` card #${shown(card)}: roles ${names.map(shown).join(', ')}, whose dispatch windows hold its opening`;
164
+ return ` card #${shown(card)}: the owner, since no role dispatch window holds its opening`;
165
+ })),
166
+ ];
167
+ }
168
+
169
+ /** The lines L2 prints: rates and escalations per run, then stream rates, acceptance changes and rounds by kind. */
170
+ function l2Lines({ runs, escalationCauses, stream }) {
171
+ const line = ({ faults, claims }, where) => rateLine('host-fault rate', 'host faults', 'work claims', { counted: faults, of: claims, none: `no work claim in ${where}` });
172
+ return [
173
+ ...runs.flatMap(({ run, hostFaults, escalations }) => [
174
+ ` run ${outsideText(run)}`, line(hostFaults, 'this run'), escalationLine(escalations, 'this run'), ...escalationLines(escalations.entries),
175
+ ]),
176
+ ' across the stream',
177
+ line(stream.hostFaults, 'the stream'),
178
+ escalationLine(stream.escalations, 'the stream'),
179
+ ' each escalation is listed under its run',
180
+ ...causeLines(escalationCauses),
181
+ ...freshLines(stream.freshMerges),
182
+ ...acceptanceLines(stream.acceptance),
183
+ ...roundLines(stream.rounds),
184
+ ];
185
+ }
186
+
187
+ /** The lines L4 prints: each run's rework, then the stream's rework, first-pass rate and tier accuracy. */
188
+ function l4Lines({ runs, stream: { rework, firstPass, tierAccuracy } }) {
189
+ return [
190
+ ...runs.flatMap((each) => [` run ${outsideText(each.run)}`, ` rework: ${each.rework}`]),
191
+ ' across the stream',
192
+ ` rework: ${rework}`,
193
+ rateLine('first-pass rate', 'cards merged after one round', 'cards judged and merged',
194
+ { counted: firstPass.first, of: firstPass.of, none: 'no card in the stream was judged and merged' }),
195
+ rateLine('tier accuracy', 'card and role pairs with no tier correction', 'card and role pairs dispatched at a tier',
196
+ { counted: tierAccuracy.accurate, of: tierAccuracy.of, none: 'no card and role in the stream was dispatched at a tier' }),
197
+ ];
198
+ }
199
+
200
+ /**
201
+ * What the command prints for a `report` run, and the status it exits with. It writes nothing but
202
+ * what L0 records of a process it kills, through the sink `recording` opens.
203
+ */
204
+ export const report = (options) => recording((opened) => reporting(opened, options));
205
+
206
+ /** `report`'s work, recording through the sink `opened` holds once the guard has settled. */
207
+ async function reporting(opened, { target = process.cwd(), packageRoot = PACKAGE, ask } = {}) {
208
+ const { named, refusal } = await settled('report', opened, { target, packageRoot, ask });
209
+ if (refusal) return refusal;
210
+ let derived;
211
+ try {
212
+ derived = derive(join(named, STATE));
213
+ } catch (refused) {
214
+ return { text: `rigger report: ${refused.message}, so no signal is derived`, code: 1 };
215
+ }
216
+ return { text: reportText(derived), code: 0 };
217
+ }
218
+
219
+ /** The report lines shared by the report verb and a clock firing handed to run. */
220
+ export function reportText({ path, l0, l1, l2, runs, holds, l4, markers }) {
221
+ if (runs === null) return `rigger report: no events are recorded; there is no stream at ${path}`;
222
+ const markerLines = markers.map(({ card, role, head, dispatch, reason }) =>
223
+ ` card #${outsideText(card)}, ${outsideText(role)}, head ${outsideText(head)}, dispatch ${outsideText(dispatch)}${reason === undefined ? '' : `: ${outsideText(reason)}`}`);
224
+ return [
225
+ `rigger report: the events recorded at ${path}`,
226
+ 'L0',
227
+ ...l0Lines(l0),
228
+ 'L1',
229
+ ...l1Lines(l1),
230
+ 'L2',
231
+ ...l2Lines(l2),
232
+ 'L3',
233
+ ...holdLines(holds),
234
+ ...runs.flatMap(runLines),
235
+ 'L4',
236
+ ...l4Lines(l4),
237
+ 'markers no dispatch wrote',
238
+ ...markerLines,
239
+ ' only markers L2 recorded in this state directory are named',
240
+ ' markers of role owner are never checked',
241
+ ].join('\n');
242
+ }
@@ -0,0 +1,96 @@
1
+ // ABOUTME: The `resume` verb: a thin caller of L3's admission module, whose `resume` removal removes
2
+ // every closer it read and records each, and then of L2's notice function, which closes the status
3
+ // issue; it says what it removed and closed, or why it removed or closed nothing, an unreadable
4
+ // admission's entries in the words `doctor` names them in.
5
+
6
+ import { join } from 'node:path';
7
+
8
+ import { FIXED_LABELS, validate } from '../config/validate.mjs';
9
+ import { admission, admissions } from '../scheduling/admission.mjs';
10
+ import { causeOf } from '../workflow/status-issue.mjs';
11
+ import { columnChanges } from '../workflow/transitions.mjs';
12
+ import { CONFIG } from './init.mjs';
13
+ import { PACKAGE, consumerConfig, outsideText, removedCloserLine, settled, unreadableAdmission } from './doctor.mjs';
14
+ import { STATE, recording } from './recording.mjs';
15
+
16
+
17
+
18
+ /**
19
+ * What `rigger resume` prints, and the status it exits with, in `ARCHITECTURE.md`'s order: it
20
+ * resolves the repository and its state directory as `once` does, removes the closers it read,
21
+ * and only then reads `rigger.config.mjs`, so a missing config or the forge never keeps admission
22
+ * closed (`R-SCHED-23`). It reaches L2's notice function through L2's own entry point, built from
23
+ * the config, as `once` reaches L2, to close each issue a removed closer's name gave and every other
24
+ * open issue carrying the status label (`R-SCHED-24`). Where it removed nothing, it reads no config
25
+ * and closes no issue. `now` is the module's clock, `fs` the `node:fs` calls the module makes and
26
+ * `send` the runners' spawn, each a test's to replace. `sink` replaces only admission's sink for tests.
27
+ */
28
+ export const resume = (options) => recording((opened) => resuming(opened, options));
29
+
30
+ /** `resume`'s work, recording through the sink `opened` holds once `settled` has named its state directory. */
31
+ async function resuming(opened, {
32
+ target = process.cwd(), packageRoot = PACKAGE, ask, now = Date.now, fs, send, sink,
33
+ } = {}) {
34
+ const { named, refusal } = await settled('resume', opened, { target, packageRoot, ask });
35
+ if (refusal) return refusal;
36
+ const admissionRecord = admission({ directory: join(named, STATE), run: opened.run, now, sink: sink ?? opened.sink, ...(fs && { fs }) });
37
+ const refusalLines = (events = []) => events.map(({ name, why }) => `rigger resume: the sink refused the admission.open event for ${outsideText(name)}: ${outsideText(why)}`);
38
+ let answer;
39
+ try {
40
+ answer = await admissionRecord.resume();
41
+ } catch (failure) {
42
+ // Only a failure admission built is read for its fields; any other is said whole.
43
+ const { unreadable, removed: removedSoFar, unrecorded } = admissions(failure) ? failure : {};
44
+ if (Array.isArray(unreadable)) return { text: `rigger resume: ${unreadableAdmission(unreadable)}`, code: 1 };
45
+ // A removal that stopped partway still names each closer it removed, then why no issue was closed.
46
+ const done = Array.isArray(removedSoFar) ? removedSoFar : [];
47
+ return {
48
+ text: [
49
+ ...done.map((closer) => `rigger resume: ${removedCloserLine(closer)}`),
50
+ ...refusalLines(unrecorded),
51
+ `rigger resume: ${outsideText(causeOf(failure))}`,
52
+ ...(done.length === 0 ? [] : ['rigger resume: no status issue was closed, because the removal of the closers stopped before every closer was removed']),
53
+ ].join('\n'),
54
+ code: 1,
55
+ };
56
+ }
57
+ const { removed, gone, unrecorded: admissionRefusals } = answer;
58
+ if (removed.length === 0 && gone.length === 0) return { text: 'rigger resume: admission was already open', code: 0 };
59
+ const lines = [
60
+ ...removed.map((closer) => `rigger resume: ${removedCloserLine(closer)}`),
61
+ ...gone.map(({ kind, path }) => `rigger resume: the ${kind} closer ${path} was already gone`),
62
+ ...refusalLines(admissionRefusals),
63
+ ];
64
+ // Every closer read was gone at its removal: another `resume` removed them, and closes the issue.
65
+ if (removed.length === 0) return { text: lines.join('\n'), code: 0 };
66
+ /** The answer where nothing after the removal reached L2: the removals made, and why no issue was closed. */
67
+ const unclosed = (why) => ({ text: [...lines, `rigger resume: no status issue was closed, because ${outsideText(why)}`].join('\n'), code: 1 });
68
+ const { config, problem } = await consumerConfig(named);
69
+ if (problem !== undefined) return unclosed(problem);
70
+ const invalid = validate(config);
71
+ if (invalid.length > 0) return unclosed(`\`${CONFIG}\`: ${invalid.join('; ')}`);
72
+ const { notice } = columnChanges({ config, sink: opened.sink, send });
73
+ const issues = [...removed, ...gone].filter(({ issue }) => issue !== undefined).map(({ issue }) => Number(issue));
74
+ let closing;
75
+ try {
76
+ closing = await notice.close(issues);
77
+ } catch (failure) {
78
+ // L2 answers each issue's failure itself, so a throw here came before its first write.
79
+ return unclosed(`closing the status issues stopped: ${causeOf(failure)}`);
80
+ }
81
+ const { closed, left, unrecorded, unread } = closing;
82
+ /** The record a write the forge made for issue `number` and the sink refused, as `write` names it, or undefined. */
83
+ const refused = (number, write) => unrecorded.find((each) => each.issue === number && each.write === write)?.why;
84
+ /** `said`, then, where `why` names a refused record, that the sink refused it. */
85
+ const but = (said, why) => (why === undefined ? said : `${said}, but the sink refused its record: ${outsideText(why)}`);
86
+ return {
87
+ text: [
88
+ ...lines,
89
+ ...unrecorded.filter(({ write }) => write === 'label').map(({ issue, why }) => `rigger resume: ${but(`removed the status label from issue #${issue}`, why)}`),
90
+ ...closed.map((number) => `rigger resume: ${but(`closed the status issue #${number}`, refused(number, 'close'))}`),
91
+ ...(unread === undefined ? [] : [`rigger resume: the read of the open issues labelled ${FIXED_LABELS.status} failed, so only the issues the closers named were closed: ${outsideText(unread)}`]),
92
+ ...left.map(({ issue, why: cause, unlabelled }) => `rigger resume: the status issue #${issue} was left open${unlabelled ? ', its status label already removed, so no later read by label finds it' : ''}: ${outsideText(cause)}`),
93
+ ].join('\n'),
94
+ code: left.length === 0 && unrecorded.length === 0 && unread === undefined && admissionRefusals.length === 0 ? 0 : 1,
95
+ };
96
+ }
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ // ABOUTME: The `rigger` command: the file the package declares as its bin. It reads the
3
+ // arguments, writes what the surface answers, and exits with the status it gives.
4
+
5
+ import { run } from './verbs.mjs';
6
+
7
+ // Nothing guards this against being imported, because nothing imports it: what a test needs is
8
+ // `verbs.mjs`, and a guard comparing this file against `process.argv[1]` would have to resolve
9
+ // the symlink an installed bin is reached through.
10
+ const { text, code } = await run(process.argv.slice(2));
11
+ (code === 0 ? console.log : console.error)(text);
12
+ process.exit(code);
@@ -0,0 +1,10 @@
1
+ // ABOUTME: The `run` verb: hands L3 the board drain, which refills freed slots and dispatches
2
+ // each card's work through L1 and L2, with the shared claiming-verb presenter.
3
+
4
+ import { claimVerb } from './once.mjs';
5
+
6
+ /**
7
+ * What the command prints and exits with. L3 reads N and the clock declaration from the config,
8
+ * drains the board without a clock trigger, and otherwise keeps the run up until stopped.
9
+ */
10
+ export const run = (options) => claimVerb('run', undefined, options);
@@ -0,0 +1,108 @@
1
+ // ABOUTME: The `setup-board` verb: it reads the board the config names, works out what the config
2
+ // declares and the board lacks, and adds that through the schema-write side, one line per write.
3
+
4
+ import { declaredLabels, sameLabel, validate } from '../config/validate.mjs';
5
+ import { boardOf, readSide } from '../substrate/forge/read.mjs';
6
+ import { schemaWriteSide } from '../substrate/forge/schema-write.mjs';
7
+ import { unrecordedNamed } from '../workflow/transitions.mjs';
8
+ import { consumerConfig, settled, sharedWith } from './doctor.mjs';
9
+ import { recording } from './recording.mjs';
10
+
11
+ /** The type GitHub names a single-select field by, which is the only type a priority field may be. */
12
+ const SINGLE_SELECT = 'SINGLE_SELECT';
13
+
14
+ /**
15
+ * A name as a printed line shows it: every control character and every line or paragraph
16
+ * separator written as its `\u` escape, so a name the validator accepts, which may hold any of
17
+ * them, prints on the one line its write is given and sends the terminal nothing but text.
18
+ */
19
+ const shown = (name) => name.replace(/[\p{Cc}\u2028\u2029]/gu, (char) => `\\u${char.codePointAt(0).toString(16).padStart(4, '0')}`);
20
+
21
+ /**
22
+ * What the board holds that setup-board compares the config against: the names of its columns,
23
+ * every field's name and type, the repository's labels, and what the forge adapter reports of
24
+ * the other repositories whose items are on it. Read before anything is written, each read sent
25
+ * with the `L0` emitter `emitter`.
26
+ */
27
+ async function survey(board, emitter) {
28
+ const read = readSide(board, { emitter });
29
+ return {
30
+ others: await read.readOtherRepositories(),
31
+ columns: (await boardOf('setup-board', board, { emitter })).columns.options.map((option) => option.name),
32
+ fields: await read.readFieldTypes(),
33
+ labels: await read.readLabels(),
34
+ };
35
+ }
36
+
37
+ /**
38
+ * The writes that add the declared and fixed labels and board fields `held` lacks, each as the schema-write
39
+ * operation, its arguments and the line printed for it, or `{ refusal }` where the board holds
40
+ * another repository's items or one it cannot read, or cannot take the config without changing
41
+ * something it already holds. Nothing held is ever removed, renamed or changed: a priority
42
+ * field already there is left as it is, whatever its options.
43
+ */
44
+ function writesFor(config, held) {
45
+ const shared = sharedWith(config.board.project, held.others);
46
+ if (shared) return { refusal: `${shared}, and two engines never share one board, so nothing was written` };
47
+ const writes = [];
48
+ for (const name of new Set(Object.values(config.board.columns))) {
49
+ if (!held.columns.includes(name)) writes.push({ operation: 'createColumn', args: [name], line: `added the column ${shown(name)}` });
50
+ }
51
+ const { priority } = config.board;
52
+ if (priority) {
53
+ const field = held.fields.find(({ name }) => name === priority.field);
54
+ if (field && field.type !== SINGLE_SELECT) {
55
+ return { refusal: `the board's field ${shown(field.name)} is a ${field.type} field, and a priority field is ${SINGLE_SELECT}, so nothing was written` };
56
+ }
57
+ if (!field) {
58
+ writes.push({ operation: 'createField', args: [priority.field, priority.options], line: `created the field ${shown(priority.field)} with the options ${priority.options.map(shown).join(', ')}` });
59
+ }
60
+ }
61
+ for (const name of declaredLabels(config)) {
62
+ if (!held.labels.some((label) => sameLabel(label, name))) writes.push({ operation: 'createLabel', args: [name], line: `created the label ${shown(name)}` });
63
+ }
64
+ return { writes };
65
+ }
66
+
67
+ /**
68
+ * What the command prints for a `setup-board` run, and the status it exits with. Every read and
69
+ * write goes through L0 with an `L0` emitter on the sink `recording` opens.
70
+ */
71
+ export const setupBoard = (options) => recording((opened) => settingUp(opened, options));
72
+
73
+ /** `setupBoard`'s work, recording through the sink `opened` holds once `settled` has named its state directory. */
74
+ async function settingUp(opened, { target = process.cwd() } = {}) {
75
+ const { named, refusal } = await settled('setup-board', opened, { target });
76
+ if (refusal) return refusal;
77
+ const { sink } = opened;
78
+ const { config, problem } = await consumerConfig(named);
79
+ if (problem) return { text: `rigger setup-board: ${problem}`, code: 1 };
80
+ const refusals = validate(config);
81
+ if (refusals.length > 0) return { text: `rigger setup-board: \`${named}\`'s config earns refusals, so nothing was written: ${refusals.join('; ')}`, code: 1 };
82
+
83
+ const board = { repo: config.repo, ...config.board };
84
+ const where = `board ${board.project}`;
85
+ const emitter = sink.emitter({ layer: 'L0' });
86
+ let planned;
87
+ try {
88
+ planned = writesFor(config, await survey(board, emitter));
89
+ } catch (error) {
90
+ return { text: `rigger setup-board: ${shown(error.message)}, so nothing was written`, code: 1 };
91
+ }
92
+ if (planned.refusal) return { text: `rigger setup-board: ${planned.refusal}`, code: 1 };
93
+
94
+ const side = schemaWriteSide(board, { emitter });
95
+ const made = [];
96
+ for (const { operation, args, line } of planned.writes) {
97
+ try {
98
+ await side[operation](...args);
99
+ } catch (error) {
100
+ if (!error.made) return { text: [`rigger setup-board: ${made.length} writes to ${where} before one failed`, ...made, ` ${shown(error.message)}`].join('\n'), code: 1 };
101
+ // The schema-write side marked the write made: the board took it, and only its record was refused.
102
+ made.push(` ${line}`);
103
+ return { text: [`rigger setup-board: ${made.length} writes to ${where}`, ...made, ` and the event sink refused to record the last of them: ${shown(unrecordedNamed(error))}`].join('\n'), code: 1 };
104
+ }
105
+ made.push(` ${line}`);
106
+ }
107
+ return { text: [`rigger setup-board: ${made.length} writes to ${where}`, ...made].join('\n'), code: 0 };
108
+ }
@@ -0,0 +1,82 @@
1
+ // ABOUTME: The CLI surface: the verbs Rigger accepts, which of them have landed, what `--help`
2
+ // lists for them, and how a word that is no verb is refused.
3
+
4
+ import { pushAtReturn } from '../observation/push.mjs';
5
+ import { doctor } from './doctor.mjs';
6
+ import { init } from './init.mjs';
7
+ import { once } from './once.mjs';
8
+ import { pause } from './pause.mjs';
9
+ import { plan } from './plan.mjs';
10
+ import { report } from './report.mjs';
11
+ import { resume } from './resume.mjs';
12
+ import { run as runVerb } from './run.mjs';
13
+ import { setupBoard } from './setup-board.mjs';
14
+ import { verdict } from './verdict.mjs';
15
+
16
+ /**
17
+ * Every verb, in the order the README's "Install and usage" block lists them, each with the help
18
+ * text this command shows for it.
19
+ *
20
+ * The README is the CLI contract (`AGENTS.md`, "What binds"), so it owns which verbs exist and in
21
+ * what order; `test/cli.test.mjs` reads that block and holds this list to it. The help text beside
22
+ * each verb is this command's own, except `doctor`'s, which that test holds to the README's comment
23
+ * beside `doctor`, so that `--help` names every check `doctor` runs.
24
+ */
25
+ export const VERBS = [
26
+ ['init', 'write a starter config, fork the role templates'],
27
+ [
28
+ 'doctor',
29
+ 'check Node, gh version, gh auth, agent CLI auth, config, board reachability, board columns, board priority field, board sharing, gate check required, admission, launchd job',
30
+ ],
31
+ ['setup-board', 'create the board columns, fields, and labels'],
32
+ ['plan', 'show what the next run would pull, and what it refuses'],
33
+ ['once', 'claim one card, provision its workspace and dispatch its maker, then exit'],
34
+ ['run', 'claim cards and dispatch their makers until the board drains, or, while a clock trigger is declared, until stopped'],
35
+ ['pause', 'stop admitting new cards; in-flight cards finish'],
36
+ ['resume', 'reopen admission and close the status issue'],
37
+ ['report', 'derive the signals from the event stream'],
38
+ ['verdict', 'post your verdict on a pull request, once you confirm it'],
39
+ ];
40
+
41
+ /**
42
+ * The verbs whose milestone has landed, each with what running it does.
43
+ *
44
+ * Every verb the README lists is here. Exported because `test/cli.test.mjs` holds this list to the
45
+ * README's both ways, and a list of landed verbs kept in the test would drift from this one.
46
+ */
47
+ export const LANDED = { init, doctor, 'setup-board': setupBoard, plan, once, run: runVerb, pause, resume, report, verdict };
48
+
49
+ /** The verbs that dispatch work, and the only ones handed L5's push (`R-RECORD-20`). */
50
+ const PUSHING = new Set(['once', 'run']);
51
+
52
+ /** What `--help` prints: one line per verb, the verb first. */
53
+ export function help(verbs = VERBS) {
54
+ const width = Math.max(...verbs.map(([verb]) => verb.length));
55
+ return [
56
+ 'Usage: rigger <verb>',
57
+ '',
58
+ 'Verbs:',
59
+ ...verbs.map(([verb, summary]) => ` ${verb.padEnd(width)} ${summary}`),
60
+ '',
61
+ ].join('\n');
62
+ }
63
+
64
+ /**
65
+ * What the command prints for these arguments, and the status it exits with.
66
+ *
67
+ * Awaited, because a landed verb may have to wait for something: `doctor` imports the consumer's
68
+ * config, which is an ES module and so cannot be read any other way. A verb that answers without
69
+ * waiting is awaited here too and costs nothing.
70
+ */
71
+ export async function run(argv) {
72
+ const [first] = argv;
73
+ if (first === '--help') return { text: help(), code: 0 };
74
+ if (!VERBS.some(([verb]) => verb === first)) {
75
+ const said = first === undefined ? 'rigger: a verb is required' : `rigger ${first}: no such verb`;
76
+ return { text: `${said}\n\n${help()}`, code: 1 };
77
+ }
78
+ // A verb is handed the words after it; those that take none read nothing from them. Only `run`
79
+ // and `once` are handed L5's push, which each hands `recording`: no other verb copies the record
80
+ // (`R-RECORD-20`; `ARCHITECTURE.md`, "When L5 pushes").
81
+ if (Object.hasOwn(LANDED, first)) return LANDED[first]({ args: argv.slice(1), ...(PUSHING.has(first) ? { push: pushAtReturn() } : {}) });
82
+ }