@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,265 @@
1
+ // ABOUTME: L2's verdict marker: the syntax of the block a judge's verdict comment holds, the
2
+ // instruction asking a judge for one, the parse reading one back, the acceptance and evidence
3
+ // digests a marker is bound by, and the one read of a pull request's markers.
4
+
5
+ import { createHash } from 'node:crypto';
6
+
7
+ import { acceptanceItems } from './form-check.mjs';
8
+
9
+ /**
10
+ * The marker's syntax, held once so the instruction, the gate's run summary and the parse cannot
11
+ * drift (`ARCHITECTURE.md`, "Markers"). A marker is one pull request comment: its first line is free
12
+ * text, and on its second a block opens with a fence whose info string is `rigger-marker`, closing
13
+ * on a bare fence. Inside, each line is `key: value`, one field per line in any order, and each
14
+ * acceptance item is a line `item <n>: met` or `item <n>: unmet`, keyed by its 1-based ordinal.
15
+ */
16
+ const OPEN = '```rigger-marker';
17
+ const CLOSE = '```';
18
+
19
+ /** The three verdicts, which Rigger fixes and no consumer adds to (`R-VERDICT-1`, `R-VERDICT-2`). */
20
+ export const VERDICTS = ['sound', 'needs revision', 'critical'];
21
+
22
+ /** An item's two rulings, and the acceptance's two coverage rulings (`R-LOOP-5`, `R-LOOP-6`). */
23
+ const RULINGS = ['met', 'unmet'];
24
+ const COVERAGES = ['covered', 'insufficient'];
25
+
26
+ /** The permissions on the repository that count as write access. */
27
+ export const WRITERS = ['admin', 'maintain', 'write'];
28
+
29
+ const POSITIVE = /^[1-9][0-9]*$/;
30
+ const SHA = /^[0-9a-f]{40}$/;
31
+ const DIGEST = /^[0-9a-f]{64}$/;
32
+ const ROLE = /^\S+$/;
33
+ /** A provider is checked for its form only, as `role` is: the parse never reads L0's adapters. */
34
+ const PROVIDER = ROLE;
35
+ const DISPATCH = /^d-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
36
+ const LINE = /^.+$/;
37
+
38
+ /** A value one of `values`, as a pattern. */
39
+ const oneOf = (values) => new RegExp(`^(?:${values.join('|')})$`);
40
+
41
+ /**
42
+ * The fields a marker holds besides its items, in the order a composed block writes them: what a
43
+ * value must match, how the parse reads it, and whether the marker needs it. `coverageReason` is
44
+ * needed where coverage is insufficient and `toSound` where the verdict is not sound. `provider`,
45
+ * `dispatch` and `evidence` are optional for every role, so a judge Rigger did not dispatch, and the
46
+ * owner, can write a marker. Whether an agent judge's marker must name its provider is the gate
47
+ * rule's to say, since only it is handed which roles are agent judges (`D24` rule 2).
48
+ */
49
+ const FIELDS = {
50
+ // A number field also holds a safe integer, so a value too long for one is not read as Infinity.
51
+ card: { valid: POSITIVE, read: Number, required: true },
52
+ pull: { valid: POSITIVE, read: Number, required: true },
53
+ head: { valid: SHA, required: true },
54
+ digest: { valid: DIGEST, required: true },
55
+ role: { valid: ROLE, required: true },
56
+ provider: { valid: PROVIDER },
57
+ verdict: { valid: oneOf(VERDICTS), required: true },
58
+ coverage: { valid: oneOf(COVERAGES), required: true },
59
+ coverageReason: { valid: LINE },
60
+ toSound: { valid: LINE },
61
+ dispatch: { valid: DISPATCH },
62
+ evidence: { valid: DIGEST },
63
+ };
64
+
65
+ /** A field line, `key: value`, the key a name or `item <n>`; a key with nothing after its colon has an empty value. */
66
+ const FIELD = /^(item [^:]*|[A-Za-z]+):(?: (.*))?$/;
67
+
68
+ /** A fence opening a code block, with the run of marks it must be closed by. */
69
+ const FENCE = /^ {0,3}(`{3,}|~{3,})/;
70
+
71
+ /** The SHA-256 of `text`'s UTF-8 bytes, as 64 lowercase hex characters. */
72
+ const sha256 = (text) => createHash('sha256').update(text, 'utf8').digest('hex');
73
+
74
+ /**
75
+ * The acceptance digest of a card whose body is `body`: SHA-256 of the items `acceptanceItems`
76
+ * reads from it, in order, each followed by one LF. An edit outside the acceptance leaves it as it
77
+ * was, so it stales no marker (`R-LOOP-8`).
78
+ */
79
+ export const acceptanceDigest = (body) => sha256(acceptanceItems(body).map((item) => `${item}\n`).join(''));
80
+
81
+ /** The evidence digest of `evidence`, the one L1 records at `dispatch.start` and a marker carries. */
82
+ export const evidenceDigest = (evidence) => sha256(evidence);
83
+
84
+ /** The lines of a marker block holding `fields`, written in the schema's order, with `items` as one line per ordinal. */
85
+ function blockLines({ items, ...fields }) {
86
+ const written = (key) => (fields[key] === undefined ? [] : [`${key}: ${fields[key]}`]);
87
+ return [
88
+ OPEN,
89
+ ...['card', 'pull', 'head', 'digest', 'role', 'provider', 'verdict'].flatMap(written),
90
+ ...items.map((ruling, at) => `item ${at + 1}: ${ruling}`),
91
+ ...['coverage', 'coverageReason', 'toSound', 'dispatch', 'evidence'].flatMap(written),
92
+ CLOSE,
93
+ ];
94
+ }
95
+
96
+ /** A comment whose first line is `heading` and whose marker block holds `marker`, each of its fields as the parse answers them. */
97
+ export const composeMarker = (marker, heading) => [heading, ...blockLines(marker), ''].join('\n');
98
+
99
+ /** The slot in a judge's instruction that L3's dispatch id fills (`dispatched`). */
100
+ const DISPATCH_SLOT = '<the dispatch id>';
101
+
102
+ /**
103
+ * The part of a judge's instruction that asks for its marker: one comment on pull request `pull`,
104
+ * whose block carries `card`, `pull`, `head`, the acceptance `digest`, `role`, the `provider` an
105
+ * agent judge runs on and the `evidence` digest as given, the dispatch id L3 fills in at dispatch,
106
+ * and a ruling on each of `items`, the acceptance items, listed by ordinal. The owner is handed no
107
+ * provider, so its block names none (`D24` rule 2).
108
+ */
109
+ export const markerInstruction = ({ evidence, ...asked }) => instruction({ ...asked, dispatch: DISPATCH_SLOT, evidence });
110
+
111
+ /**
112
+ * The same instruction for a judge Rigger did not dispatch, which the gate's run summary prints:
113
+ * its block writes no dispatch or evidence line, since such a judge holds neither, and the parse
114
+ * reads a marker without them.
115
+ */
116
+ export const undispatchedInstruction = (asked) => instruction(asked);
117
+
118
+ /** The instruction asking a judge for its marker, its block holding `dispatch` and `evidence` where given. */
119
+ function instruction({ card, pull, head, digest, role, provider, items, dispatch, evidence }) {
120
+ const template = blockLines({
121
+ card,
122
+ pull,
123
+ head,
124
+ digest,
125
+ role,
126
+ provider,
127
+ verdict: `<${VERDICTS.slice(0, -1).join(', ')} or ${VERDICTS.at(-1)}>`,
128
+ items: items.map(() => `<${RULINGS.join(' or ')}>`),
129
+ coverage: `<${COVERAGES.join(' or ')}: whether the acceptance covered what the card asked>`,
130
+ coverageReason: '<one line: why the acceptance does not cover what the card asked, written only where coverage is insufficient>',
131
+ toSound: '<one line: what would make the work sound, written only where the verdict is not sound>',
132
+ dispatch,
133
+ evidence,
134
+ });
135
+ return [
136
+ `Rule on every acceptance item below, by its number, as met or unmet, then write your verdict as one comment on pull request #${pull}.`,
137
+ 'Its first line is yours, for the person reading the pull request. Its second line opens this block, which you fill in and write exactly once, under no other fence, leaving out the two optional lines where they do not apply:',
138
+ '',
139
+ ...template,
140
+ '',
141
+ 'The acceptance items, by number:',
142
+ ...items.map((item, at) => `${at + 1}. ${item}`),
143
+ ].join('\n');
144
+ }
145
+
146
+ /** L2's role answer `answer` for a judge, with dispatch id `id`, which L3 minted, written into its instruction's marker block. */
147
+ export const dispatched = (answer, id) => ({ ...answer, instruction: answer.instruction.replace(`dispatch: ${DISPATCH_SLOT}`, `dispatch: ${id}`) });
148
+
149
+ /**
150
+ * The marker `body`, a comment's text, holds, read against an acceptance of `count` items. LF and
151
+ * CRLF read alike. It answers one of:
152
+ * - `{ state: 'none' }`, where no marker block opens on the comment's second line, or where its
153
+ * first line opens a fence, which quotes the line under it;
154
+ * - `{ state: 'unreadable', reason, fields }`, naming why, with `fields` the values the block gave
155
+ * each field it names, as written, a block never closed read to the comment's end;
156
+ * - `{ state: 'marker', marker, absent }`, `marker` holding each field the block gives, `card` and
157
+ * `pull` as numbers and `items` as each ordinal's ruling in order, and `absent` naming
158
+ * `provider`, `dispatch` and `evidence` where the block leaves them out.
159
+ */
160
+ export function parseMarker(body, count) {
161
+ const written = String(body).split(/\r?\n/);
162
+ // Fence lines are compared without trailing whitespace; field lines are read as written, so a
163
+ // value holding whitespace is refused rather than trimmed into a valid one.
164
+ const lines = written.map((line) => line.trimEnd());
165
+ if (lines[1] !== OPEN || FENCE.test(lines[0])) return { state: 'none' };
166
+ const closed = lines.indexOf(CLOSE, 2);
167
+ const close = closed === -1 ? lines.length : closed;
168
+ const fields = {};
169
+ const items = new Map();
170
+ const faults = closed === -1 ? ['the marker block opened on line 2 is never closed'] : [];
171
+ const second = secondBlock(lines, close + 1);
172
+ if (second !== undefined) faults.push(`the comment holds two marker blocks, on line 2 and on line ${second + 1}`);
173
+ for (let at = 2; at < close; at += 1) {
174
+ const field = FIELD.exec(written[at]);
175
+ if (field === null) {
176
+ faults.push(`line ${at + 1}, ${JSON.stringify(written[at])}, is not \`key: value\``);
177
+ continue;
178
+ }
179
+ const [, key, value = ''] = field;
180
+ if (key.startsWith('item ')) {
181
+ const ordinal = key.slice('item '.length);
182
+ if (!POSITIVE.test(ordinal) || Number(ordinal) > count) faults.push(`${key} is outside 1 to ${count}`);
183
+ else if (items.has(Number(ordinal))) faults.push(`${key} is given twice`);
184
+ else if (!RULINGS.includes(value)) faults.push(`${key} is ruled ${JSON.stringify(value)}, not met or unmet`);
185
+ else items.set(Number(ordinal), value);
186
+ } else if (!Object.hasOwn(FIELDS, key)) faults.push(`the field ${key} is not one the schema names`);
187
+ else if (Object.hasOwn(fields, key)) faults.push(`the field ${key} is given twice`);
188
+ else fields[key] = value;
189
+ }
190
+ for (const [key, { valid, read, required }] of Object.entries(FIELDS)) {
191
+ if (!Object.hasOwn(fields, key)) {
192
+ if (required) faults.push(`the field ${key} is missing`);
193
+ } else if (!valid.test(fields[key]) || (read === Number && !Number.isSafeInteger(Number(fields[key])))) faults.push(`the field ${key} holds ${JSON.stringify(fields[key])}, which is not its form`);
194
+ }
195
+ for (let ordinal = 1; ordinal <= count; ordinal += 1) if (!items.has(ordinal)) faults.push(`item ${ordinal} is missing`);
196
+ if (fields.coverage === 'insufficient' && !Object.hasOwn(fields, 'coverageReason')) faults.push('coverage is ruled insufficient with no coverageReason');
197
+ if (Object.hasOwn(fields, 'verdict') && fields.verdict !== 'sound' && !Object.hasOwn(fields, 'toSound')) faults.push(`the verdict ${fields.verdict} names no toSound`);
198
+ if (faults.length > 0) return { state: 'unreadable', reason: faults.join('; '), fields };
199
+ const marker = Object.fromEntries(Object.entries(fields).map(([key, value]) => [key, (FIELDS[key].read ?? String)(value)]));
200
+ marker.items = [...items.keys()].sort((one, other) => one - other).map((ordinal) => items.get(ordinal));
201
+ return { state: 'marker', marker: ordered(marker), absent: ['provider', 'dispatch', 'evidence'].filter((key) => !Object.hasOwn(fields, key)) };
202
+ }
203
+
204
+ /** `marker` with its fields in the schema's order, `items` after `verdict`. */
205
+ function ordered(marker) {
206
+ const keys = ['card', 'pull', 'head', 'digest', 'role', 'provider', 'verdict', 'items', 'coverage', 'coverageReason', 'toSound', 'dispatch', 'evidence'];
207
+ return Object.fromEntries(keys.filter((key) => Object.hasOwn(marker, key)).map((key) => [key, marker[key]]));
208
+ }
209
+
210
+ /**
211
+ * The index of the first line from `from` on that opens a second marker block, outside any other
212
+ * fence, or nothing where none does.
213
+ */
214
+ function secondBlock(lines, from) {
215
+ let fence = null;
216
+ for (let at = from; at < lines.length; at += 1) {
217
+ const line = lines[at];
218
+ if (fence !== null) {
219
+ const run = /^ {0,3}(`+|~+)[ \t]*$/.exec(line)?.[1];
220
+ if (run !== undefined && run[0] === fence[0] && run.length >= fence.length) fence = null;
221
+ } else if (line === OPEN) return at;
222
+ else fence = FENCE.exec(line)?.[1] ?? null;
223
+ }
224
+ return undefined;
225
+ }
226
+
227
+ /** Whether `one` was written before `other`: by `createdAt`, then, at one `createdAt`, by comment id. */
228
+ const before = (one, other) => {
229
+ const created = Date.parse(one.createdAt) - Date.parse(other.createdAt);
230
+ if (created !== 0) return created < 0;
231
+ return one.id.length !== other.id.length ? one.id.length < other.id.length : one.id < other.id;
232
+ };
233
+
234
+ /**
235
+ * The markers on `comments`, a pull request's comments in the shape the forge's read answers, `{
236
+ * body, createdAt, id, author, permission, edited }`, read for card `card`'s pull request `pull`,
237
+ * at head `head` and acceptance digest `digest` over `count` items. Only a comment whose author
238
+ * holds `admin`, `maintain` or `write` on the repository counts, and a marker naming another card
239
+ * or pull request counts as none.
240
+ *
241
+ * It answers `governing`, each role's governing marker, the latest by `createdAt` at `head` and
242
+ * `digest`, and at one `createdAt` the later comment id: the parse's answer, with `comment` as its
243
+ * source id and `edited` as its comment's. An unreadable marker governs for the card, pull request, role, head and digest its
244
+ * block names, each read without surrounding whitespace, so whitespace that makes a field
245
+ * unreadable does not also move the marker off its role. It also
246
+ * answers `markers`, every readable marker counted, oldest first.
247
+ */
248
+ export function readMarkers(comments, { card, pull, head, digest, count }) {
249
+ const namedBy = (parsed) => parsed.marker ?? Object.fromEntries(Object.entries(parsed.fields).map(([key, value]) => [key, value.trim()]));
250
+ const counted = comments
251
+ .filter((comment) => comment.author !== null && WRITERS.includes(comment.permission))
252
+ .map((comment) => ({ comment, parsed: parseMarker(comment.body, count) }))
253
+ .filter(({ parsed }) => parsed.state !== 'none')
254
+ .filter(({ parsed }) => {
255
+ const named = namedBy(parsed);
256
+ return String(named.card) === String(card) && String(named.pull) === String(pull);
257
+ })
258
+ .sort((one, other) => (before(one.comment, other.comment) ? -1 : 1));
259
+ const governing = new Map();
260
+ for (const { comment, parsed } of counted) {
261
+ const named = namedBy(parsed);
262
+ if (named.head === head && named.digest === digest) governing.set(named.role, { ...parsed, comment: comment.id, edited: comment.edited === true });
263
+ }
264
+ return { governing, markers: counted.filter(({ parsed }) => parsed.state === 'marker').map(({ parsed }) => parsed.marker) };
265
+ }