@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,92 @@
1
+ // ABOUTME: L2's facts call: what the forge holds of each card's line of work, read before L3
2
+ // claims, and the one read of a card's pull requests, and of the one open among them, L2's settle makes.
3
+
4
+ import { worktreeTopic } from '../config/validate.mjs';
5
+ import { topicFor } from '../execution/workspace.mjs';
6
+
7
+ /**
8
+ * What `read` answers, or a failure naming `cards`, the numbers it was reading for, and the read's
9
+ * own error, kept as the cause.
10
+ */
11
+ async function forCards(cards, read) {
12
+ try {
13
+ return await read();
14
+ } catch (failure) {
15
+ const named = cards.map((number) => `#${number}`).join(', ');
16
+ throw new Error(`L2 could not read what the forge holds for card ${named}: ${failure.message}`, { cause: failure });
17
+ }
18
+ }
19
+
20
+ /**
21
+ * What the forge holds of a card's one open pull request `pull`, `{ number, head, base }` as
22
+ * `readPullRequests` answers it, read through `reads`, the forge adapter's repository reads, each
23
+ * as `Promise.allSettled` records its outcome: `pull`, the pull request's `{ number, base, head }`,
24
+ * `base` the merge base its diff is taken from and `head` its head SHA, both as the forge answers
25
+ * them; `diff`; `comments`, which hold its markers; `mergeable`, the forge's mergeability answer;
26
+ * `rules`, the effective rules of its base branch, by name; and `checks`, the states at its head
27
+ * of the checks those rules require, which a failed read of the rules leaves unread, failing as
28
+ * that read did. These are the facts L2's review loop reads, and a read that fails is answered as
29
+ * its failure, which the review loop names (`reviewAnswer`).
30
+ */
31
+ async function reviewed(pull, reads) {
32
+ const [base, diff, comments, mergeable, rules] = await Promise.allSettled([
33
+ reads.readMergeBase(pull.number), reads.readDiff(pull.number), reads.readComments(pull.number),
34
+ reads.readMergeable(pull.number), reads.readEffectiveRules(pull.base),
35
+ ]);
36
+ const [checks] = rules.status === 'fulfilled' ? await Promise.allSettled([reads.readCheckStates(pull.head, rules.value)]) : [rules];
37
+ const read = base.status === 'fulfilled' ? { status: 'fulfilled', value: { number: pull.number, base: base.value.mergeBase, head: base.value.head } } : base;
38
+ return { pull: read, diff, comments, mergeable, rules, checks };
39
+ }
40
+
41
+ /**
42
+ * What the forge holds of card `number`'s line of work `line`, as `{ line, open, merged, closed }`, the
43
+ * pull requests from it read once through `reads.readPullRequests`, the forge adapter's read
44
+ * side's, and, where exactly one is open and `review` holds, what `reviewed` reads of it beside
45
+ * them. A read of the pull requests that fails rejects naming the card and the read.
46
+ */
47
+ export async function pullRequestsFrom(number, line, reads, review = true) {
48
+ const { open, merged, closed } = await forCards([number], () => reads.readPullRequests(line));
49
+ return { line, open, merged, closed, ...(review && open.length === 1 ? await reviewed(open[0], reads) : {}) };
50
+ }
51
+
52
+ /**
53
+ * L2's facts call over the board `config` names, through `reads`, the forge adapter's repository
54
+ * reads (`repositoryReads`). `decide` is
55
+ * L2's next action for a card, as the verb built it.
56
+ *
57
+ * Handed the cards L3 read, it reads, for each card in the `ready`, `coding`, `review` or `owner` column,
58
+ * what the forge holds of its line of work, the branch the topic rule names: whether the branch is
59
+ * there, read once for every such card, and the open, merged and closed pull requests from it, read for
60
+ * each card in turn (the architect's ruling 2, P1, on #467). For a card in the `coding`, `review`
61
+ * or `owner` column holding exactly one open pull request from it, it also reads what `reviewed`
62
+ * reads of that pull request, the facts L2's review loop reads. A read of the branches or the pull requests that
63
+ * fails rejects naming each card it was reading for and the read, and answers no facts at all.
64
+ *
65
+ * It answers the `decide` L3 calls at the pull, synchronously: `decide` handed each card read with
66
+ * its facts as `forge`, `{ stage, line, branch, open, merged, closed }` with `reviewed`'s beside them where
67
+ * they were read, `stage` naming the column's key, and any other card as it was. L3 reads nothing of this answer but calls it (the architect's
68
+ * ruling 1, Q4, and ruling 2, P2).
69
+ */
70
+ export function factsCall({ config, reads, decide }) {
71
+ const { columns } = config.board;
72
+ const topic = worktreeTopic(config);
73
+ const stages = new Map(['ready', 'coding', 'review', 'owner'].map((stage) => [columns[stage], stage]));
74
+ return async (cards, { judge } = {}) => {
75
+ // A dispatched judge is settled against its original pull, whatever the board now holds.
76
+ if (judge !== undefined) {
77
+ const [comments] = await Promise.allSettled([reads.readComments(judge.facts.pull)]);
78
+ return comments;
79
+ }
80
+ const offered = cards.filter((card) => stages.has(card.column));
81
+ const lines = new Map(offered.map((card) => [card.number, topicFor(topic, card.number)]));
82
+ const branches = offered.length === 0 ? {} : await forCards([...lines.keys()], () => reads.readBranches([...lines.values()]));
83
+ const held = new Map();
84
+ for (const card of offered) {
85
+ const line = lines.get(card.number);
86
+ const stage = stages.get(card.column);
87
+ const facts = await pullRequestsFrom(card.number, line, reads, stage !== 'ready');
88
+ held.set(card.number, { stage, branch: branches[line] === true, ...facts });
89
+ }
90
+ return (card, ...rest) => decide(held.has(card.number) ? { ...card, forge: held.get(card.number) } : card, ...rest);
91
+ };
92
+ }
@@ -0,0 +1,17 @@
1
+ // ABOUTME: Finds the first matching issue above a recorded number, written by a repository writer.
2
+
3
+ import { WRITERS } from './marker.mjs';
4
+
5
+ /** Reads every number through the newest, passing over non-issues and untrusted authors. */
6
+ export async function firstAbove(k, reads, matches, active = () => true) {
7
+ if (!active()) return undefined;
8
+ const newest = await reads.readNewestNumber();
9
+ for (let candidate = k + 1; candidate <= newest; candidate += 1) {
10
+ if (!active()) return undefined;
11
+ const issue = await reads.readIssue(candidate);
12
+ if (issue === null || issue.author === null || !matches(issue)) continue;
13
+ if (!active()) return undefined;
14
+ if (WRITERS.includes(await reads.readPermission(issue.author))) return issue;
15
+ }
16
+ return undefined;
17
+ }
@@ -0,0 +1,88 @@
1
+ // ABOUTME: L2's acceptance form check: whether a card's acceptance, read from the body's source
2
+ // text, has the form a card needs before it is admitted, and the reason when it does not.
3
+
4
+ /**
5
+ * The source-level form #218 states (the owner's ruling D on the maker's escalation). The check
6
+ * reads lines and nothing else: it renders nothing, and HTML, blockquotes, setext headings and
7
+ * lines below a bullet are not modelled.
8
+ */
9
+ const FENCE = /^ {0,3}(`{3,}|~{3,})/;
10
+ // The `s` flag lets `.` take a stray CR, U+2028 or U+2029, which the rule leaves inside a line.
11
+ const HEADING = /^ {0,3}(#{1,6})(?: (.*))?$/s;
12
+ const BULLET = /^ {0,3}[-*+] (.*)$/s;
13
+ const TASK = /^\[[ xX]\]/;
14
+ // A thematic break: three or more of one marker, with spaces between them allowed.
15
+ const BREAK = /^ {0,3}([-*+])(?: *\1){2,} *$/;
16
+ // Text holding nothing but HTML comments and whitespace, such as `<!-- fill in -->`. Each comment
17
+ // ends at its first `-->`, so text between two comments, as in `<!-- a --> real <!-- b -->`, is
18
+ // never swallowed into one (the owner's (c) ruling of 2026-09-25).
19
+ const COMMENTS = /^(?:\s*<!--(?:(?!-->).)*-->)+\s*$/s;
20
+
21
+ /** The two reasons a card is refused, which `R-CARD-8` makes the whole of the check. */
22
+ const MISSING = 'missing acceptance';
23
+ const RESTATED = 'restated title';
24
+
25
+ /**
26
+ * Whether a line closes the fence its opening `marks` began: only a run at least as long, followed
27
+ * by nothing but spaces or tabs.
28
+ */
29
+ function closes(line, marks) {
30
+ const run = /^ {0,3}(`+|~+)[ \t]*$/.exec(line)?.[1];
31
+ return run !== undefined && run[0] === marks[0] && run.length >= marks.length;
32
+ }
33
+
34
+ /** A heading's text, with surrounding whitespace and any closing run of `#` removed. */
35
+ const headingText = (text = '') => text.trim().replace(/#+$/, '').trim();
36
+
37
+ /**
38
+ * The text of every plain bullet in every acceptance section. A section runs from a heading whose
39
+ * text is exactly `Acceptance` to the next heading with as many `#` or fewer. Lines inside a
40
+ * fence are skipped, and an unclosed fence runs to the end of the body. Thematic breaks,
41
+ * task-list items, bullets with no text and bullets whose text is only HTML comments are no items.
42
+ * This is how a card's acceptance is read from its body's source text (`R-CARD-12`), so L2's maker
43
+ * prompt carries these items too.
44
+ */
45
+ export function acceptanceItems(body) {
46
+ const items = [];
47
+ let section = null;
48
+ let fence = null;
49
+ for (const line of body.split(/\r?\n/)) {
50
+ if (fence) {
51
+ if (closes(line, fence)) fence = null;
52
+ continue;
53
+ }
54
+ fence = FENCE.exec(line)?.[1] ?? null;
55
+ if (fence) continue;
56
+ const heading = HEADING.exec(line);
57
+ if (heading) {
58
+ const level = heading[1].length;
59
+ if (section !== null && level <= section) section = null;
60
+ if (section === null && headingText(heading[2]) === 'Acceptance') section = level;
61
+ continue;
62
+ }
63
+ const text = section !== null && !BREAK.test(line) ? BULLET.exec(line)?.[1] : undefined;
64
+ if (text !== undefined && text.trim() && !TASK.test(text) && !COMMENTS.test(text)) items.push(text);
65
+ }
66
+ return items;
67
+ }
68
+
69
+ /**
70
+ * Text as the restated-title rule compares it (the owner's U2 ruling): letters folded to lower
71
+ * case, every Unicode punctuation and symbol character deleted, and runs of whitespace collapsed
72
+ * and trimmed. Deleting before collapsing, and deleting symbols as well as punctuation, are the
73
+ * owner's (a) ruling of 2026-09-25.
74
+ */
75
+ const normalise = (text) => text.toLowerCase().replace(/[\p{P}\p{S}]/gu, '').replace(/\s+/g, ' ').trim();
76
+
77
+ /**
78
+ * Whether a card's acceptance passes the form check. A card is `{ number, title, body }` as the
79
+ * forge holds it. The result is `{ admitted: true }`, or `{ admitted: false, card, reason }` naming
80
+ * the card's number and one of the two reasons.
81
+ */
82
+ export function checkAcceptanceForm(card) {
83
+ const items = acceptanceItems(card.body);
84
+ if (items.length === 0) return { admitted: false, card: card.number, reason: MISSING };
85
+ const title = normalise(card.title);
86
+ if (items.every((item) => normalise(item) === title)) return { admitted: false, card: card.number, reason: RESTATED };
87
+ return { admitted: true };
88
+ }
@@ -0,0 +1,62 @@
1
+ // ABOUTME: L2's pure gate rule over verdict markers, configured judges, and required check states.
2
+
3
+ import { readMarkers } from './marker.mjs';
4
+
5
+ export const GATE_CONTEXT = 'rigger/gate';
6
+
7
+ /**
8
+ * The owner's role, as the config validator's `OWNER` spells it, which a test holds equal to
9
+ * this. The rule tells the owner from an agent judge by this name, never by whether a provider is
10
+ * handed (`D24`; the delta's section 3), and imports nothing but the marker reader to know it.
11
+ */
12
+ export const OWNER = 'owner';
13
+
14
+ /** A provider's form, as the marker's `provider` is read: one or more characters and no whitespace. */
15
+ const PROVIDER = /^\S+$/;
16
+
17
+ /**
18
+ * The gate's answer for a card round. `comments` have the forge read's shape; `card`, `pull`,
19
+ * `head`, `digest` and acceptance-item `count` identify the round; `judges` is the kind's ordered
20
+ * panel, as L2's panel function answers it: `{ role: 'owner' }` for the owner, `{ role, provider }`
21
+ * for an agent judge, `provider` the one the config requires of it for the card, or one `{ conflict
22
+ * }` in place of every entry, which refuses the card with its reason and reads no marker. `checks`
23
+ * is the required contexts' state map. Each refusal names a judge or check and its reason. For one
24
+ * judge it is the first that applies: no fresh marker, edited, unreadable, the provider, the
25
+ * verdict, the coverage, then each unmet item. The caller determines the judges and checks before
26
+ * asking this pure rule.
27
+ */
28
+ export function gateAnswer({ comments, card, pull, head, digest, count, judges, checks }) {
29
+ const conflict = judges.find((entry) => entry.conflict !== undefined);
30
+ const refusals = conflict === undefined ? judgeRefusals({ comments, card, pull, head, digest, count, judges }) : [{ judge: '(panel)', reason: conflict.conflict }];
31
+ for (const [check, { state }] of Object.entries(checks)) {
32
+ if (state !== 'passed') refusals.push({ check, reason: ['failed', 'pending', 'absent'].includes(state) ? state : `unknown check state: ${state}` });
33
+ }
34
+ return refusals.length === 0 ? { admit: true } : { admit: false, refusals };
35
+ }
36
+
37
+ /** The refusals of each of `judges`, a panel holding no conflict, read from `comments` at the round. */
38
+ function judgeRefusals({ comments, card, pull, head, digest, count, judges }) {
39
+ const { governing, markers } = readMarkers(comments, { card, pull, head, digest, count });
40
+ const refusals = judges.flatMap(({ role: judge, provider }) => {
41
+ const owner = judge === OWNER;
42
+ if (!owner && !(typeof provider === 'string' && PROVIDER.test(provider))) return [{ judge, reason: 'no provider is required of it, so the panel is malformed' }];
43
+ const held = governing.get(judge);
44
+ if (held === undefined) {
45
+ const olderDigest = markers.filter((each) => each.role === judge && each.head === head && each.digest !== digest).at(-1);
46
+ if (olderDigest) return [{ judge, reason: `stale digest: ${olderDigest.digest}; current digest: ${digest}` }];
47
+ const older = markers.filter((each) => each.role === judge && each.head !== head).at(-1);
48
+ return [{ judge, reason: older ? `stale head: ${older.head}; current head: ${head}` : 'no marker' }];
49
+ }
50
+ if (held.edited) return [{ judge, reason: 'marker edited' }];
51
+ if (held.state === 'unreadable') return [{ judge, reason: `unreadable: ${held.reason}` }];
52
+ const named = held.marker.provider;
53
+ if (owner && named !== undefined) return [{ judge, reason: `the owner's marker names a provider: ${named}` }];
54
+ if (!owner && named === undefined) return [{ judge, reason: `names no provider; the config requires ${provider}` }];
55
+ if (!owner && named !== provider) return [{ judge, reason: `provider ${named}; the config requires ${provider}` }];
56
+ if (held.marker.verdict !== 'sound') return [{ judge, reason: `verdict ${held.marker.verdict}` }];
57
+ if (held.marker.coverage === 'insufficient') return [{ judge, reason: `coverage insufficient: ${held.marker.coverageReason}` }];
58
+ return held.marker.items.flatMap((item, index) => item === 'met' ? [] : [{ judge, reason: `item ${index + 1} unmet` }]);
59
+ });
60
+ if (judges.length === 0) refusals.push({ judge: '(none)', reason: 'no judges configured' });
61
+ return refusals;
62
+ }