@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,98 @@
1
+ // ABOUTME: Wakes L3 through one timer on an injectable clock: at each clock occurrence, and, while
2
+ // L3 polls, at each poll of the board.
3
+
4
+ import { schedule } from '../config/validate.mjs';
5
+ import { whenElapsed } from '../substrate/process.mjs';
6
+
7
+ /**
8
+ * Arms the occurrences of each of `triggers` that `armings` names, each `{ armed, fired }`:
9
+ * the instant of its newest arming and the occurrence of its last firing. An occurrence is due
10
+ * after both, and, under `catchUp: 'skip'`, after `started`, the instant the run's start read the
11
+ * record, too, so a missed one fires once
12
+ * at the start's wake under `fire` and never under `skip`. A wake keeps only the newest due
13
+ * occurrence per trigger, and, from each `poll()` on, a poll `interval` milliseconds later. One timer
14
+ * serves both, and it holds the process open. Firings run one at a time, earlier first and then
15
+ * by name, each through `fire`, which answers whether it settled the occurrence. Polls run one
16
+ * at a time independently of firings, so an opening cannot hold back the board. A due poll
17
+ * calls `polled`, which answers whether to poll again, `interval` milliseconds after it settled.
18
+ * Answers `{ poll, stop, started }`: `poll` starts polling, `stop` cancels the timer for good, and
19
+ * `started` settles once the start's wake has fired what was missed. `stop` also answers the
20
+ * settling of callbacks already in flight.
21
+ */
22
+ export function clockWakes({ triggers, poll: interval } = {}, clock = {}, { fire, polled }, { armings = new Map(), started } = {}) {
23
+ const entries = Object.entries(triggers ?? {}).filter(([name]) => armings.has(name));
24
+ const now = clock.now ?? Date.now;
25
+ const last = new Map(entries.map(([name, trigger]) => {
26
+ const { armed, fired } = armings.get(name);
27
+ return [name, Math.max(armed, fired, trigger.catchUp === 'skip' ? started : -Infinity)];
28
+ }));
29
+ let cancel = () => {};
30
+ let active = true;
31
+ const callbacks = new Set();
32
+ let waking = false;
33
+ let polling = false;
34
+ let pollAt;
35
+ let retryAt;
36
+ const arm = () => {
37
+ cancel();
38
+ cancel = () => {};
39
+ if (!active) return;
40
+ const occurrence = waking ? Infinity : Math.min(...entries.map(([, trigger]) => schedule(trigger, now()).next ?? Infinity));
41
+ const next = Math.min(occurrence, polling ? Infinity : pollAt ?? Infinity, waking ? Infinity : retryAt ?? Infinity);
42
+ if (next !== Infinity) cancel = whenElapsed(Math.max(0, next - now()), wake, { schedule: clock.schedule, cancel: clock.cancel, hold: true });
43
+ };
44
+ const tick = async () => {
45
+ if (!active) return;
46
+ const firing = !waking;
47
+ if (firing) waking = true;
48
+ try {
49
+ if (firing) {
50
+ try {
51
+ const current = now();
52
+ retryAt = undefined;
53
+ const due = entries.flatMap(([name, trigger]) => {
54
+ const occurrence = schedule(trigger, current).newest;
55
+ return occurrence !== null && occurrence > last.get(name) ? [{ name, occurrence }] : [];
56
+ }).sort((a, b) => a.occurrence - b.occurrence || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
57
+ arm();
58
+ for (const entry of due) if (active) {
59
+ if (await fire(entry)) last.set(entry.name, entry.occurrence);
60
+ else retryAt = now() + interval;
61
+ }
62
+ } finally {
63
+ waking = false;
64
+ }
65
+ }
66
+ if (active && !polling && pollAt !== undefined && pollAt <= now()) {
67
+ polling = true;
68
+ pollAt = undefined;
69
+ arm();
70
+ try {
71
+ if (await polled()) pollAt = now() + interval;
72
+ } finally {
73
+ polling = false;
74
+ }
75
+ }
76
+ } finally {
77
+ arm();
78
+ }
79
+ };
80
+ const wake = () => {
81
+ const pending = tick();
82
+ callbacks.add(pending);
83
+ pending.then(() => callbacks.delete(pending), () => callbacks.delete(pending));
84
+ return pending;
85
+ };
86
+ return {
87
+ started: wake(),
88
+ poll: () => {
89
+ pollAt = now() + interval;
90
+ arm();
91
+ },
92
+ stop: () => {
93
+ active = false;
94
+ cancel();
95
+ return Promise.allSettled([...callbacks]);
96
+ },
97
+ };
98
+ }
@@ -0,0 +1,160 @@
1
+ // ABOUTME: L3's repo lane merges one card at a time in pull order, records each merge, and asks
2
+ // L1 to remove merged cards' directories before L2 moves them to Done.
3
+
4
+ import { whenElapsed } from '../substrate/process.mjs';
5
+ import { unrecordedNamed } from '../workflow/transitions.mjs';
6
+
7
+ /** What `merge.end` names of L2's merge answer `answer`: its outcome, reason and context. */
8
+ const named = ({ outcome, reason, context }) => ({ outcome, ...(outcome === 'merged' ? {} : { reason: reason ?? (outcome === 'already merged' ? 'the forge held the pull request as merged already' : `the forge ${outcome} the merge call`) }), ...(context === undefined ? {} : { context }) });
9
+
10
+ /** `second` where `first` is null, or the two in one AggregateError saying `sentence`, since neither may hide the other. */
11
+ const beside = (first, second, sentence) => (first === null ? second : new AggregateError([first, second], sentence));
12
+
13
+ /**
14
+ * The lane over the board L0's `board` reads, with L2's facts call `facts` and its column changes
15
+ * `l2`, recording L3's events through `record(event, fields, card)` and naming a refused append as
16
+ * `refused(sentence, refusal)` does. Answers `merge(claim)`, which queues a merge claim behind every
17
+ * merge queued before it and settles once its own merge has ended, so no two merges overlap
18
+ * (`R-SCHED-15`), as `merged` says.
19
+ */
20
+ export function lane({ board, facts, l2, record, refused, removeDirectories, clock = {} }) {
21
+ let tail = Promise.resolve();
22
+ const now = clock.now ?? Date.now;
23
+ const pause = clock.pause ?? ((delay) => new Promise((resolve) => { whenElapsed(delay, resolve, { hold: true }); }));
24
+
25
+ /**
26
+ * The merge of `claim`'s card, L2's `merge` answer `next` at the pull. L3 records `merge.start`
27
+ * under the card, naming the pull request and head, before L2 reads the card again or anything
28
+ * acts on the forge: a merge is a start under the halt, so a start the sink refuses is not made,
29
+ * and rejects naming the card. Then L3 reads the card from the board again and hands it to L2's
30
+ * facts call, and L2 runs its rule again (the architect's r2 ruling 3). Where L2 answers `merge`
31
+ * at the pull request and head pulled, L2 makes the merge call. L3 then records `merge.end`,
32
+ * naming one outcome:
33
+ *
34
+ * - `merged` or `already merged`, as the call answered;
35
+ * - `refused`, with the adapter's `reason`, and its `context` where it names one;
36
+ * - `merged` or `already merged`, with the merge's `sha`, where the merge call rejected with a
37
+ * failure the repository-write side marked made: the forge made the merge, and only an event of
38
+ * it went unrecorded;
39
+ * - `failed`, where the merge call threw otherwise, with its message as `reason`;
40
+ * - `not merged`, where L2 answered other than that, with the `action` it answered, or where the
41
+ * card could not be read again, with why as `reason`.
42
+ *
43
+ * After a recorded `merge.end` of `merged` or `already merged` that the merge call answered, L1
44
+ * removes the card's directories before L2 settles it through `mergeEnded`. A merge marked made
45
+ * is neither removed nor settled: the lane returns its failure, and the next pass reads the pull
46
+ * request as already merged. A `merge.end` the sink refuses is the halt: nothing
47
+ * more is done for the card, and the failure names it. Answers `{ reached, failure }`: `reached`, the card's number, `action`
48
+ * `merge`, the pull request and head, and `merge`, what `merge.end` named; and `failure`, the
49
+ * failure to report, or null where there was none.
50
+ */
51
+ const merged = async ({ card, next }) => {
52
+ const fields = { pull: next.pull, head: next.head };
53
+ try {
54
+ record('merge.start', fields, card.number);
55
+ } catch (refusal) {
56
+ throw refused(`card #${card.number}'s merge of pull request #${next.pull} was not started, because the event sink refused to record its start`, refusal);
57
+ }
58
+ const began = now();
59
+ let answer;
60
+ let ended;
61
+ let failure;
62
+ let item;
63
+ let again;
64
+ let reads = 0;
65
+ let lastRead = began;
66
+ for (;;) {
67
+ const reading = await rerun(card, next);
68
+ reads += 1;
69
+ lastRead = now();
70
+ ({ item, again, ended, failure } = reading);
71
+ if (again?.unknownMergeability && now() - began < 60_000) {
72
+ // D16 rule 3: the forge can still show the old mergeability after the write. #664's
73
+ // journal/P58 saw old facts at about 2, 2.4, 6 and 7 seconds; #664's stream saw new
74
+ // facts on later invocations by 103.5 and 91.7 seconds (#758). Neither measured lag.
75
+ await pause(5_000);
76
+ continue;
77
+ }
78
+ if (ended !== undefined) break;
79
+ try {
80
+ const called = await l2.merge(item, again);
81
+ if (called.unknownMergeability) {
82
+ reads += 1;
83
+ lastRead = now();
84
+ }
85
+ if (called.unknownMergeability && now() - began < 60_000) {
86
+ await pause(5_000);
87
+ continue;
88
+ }
89
+ answer = called;
90
+ ended = named(answer);
91
+ } catch (thrown) {
92
+ if (thrown.made) {
93
+ // The forge made the merge and only its record was refused, so `merge.end` records it
94
+ // merged. Nothing more is done for the card: the next pass reads it already merged.
95
+ failure = new Error(`card #${card.number}'s merge of pull request #${next.pull} was made, and the event sink refused to record it: ${unrecordedNamed(thrown)}`, { cause: thrown });
96
+ ended = { ...named(thrown.made.answer), sha: thrown.made.answer.sha };
97
+ } else {
98
+ failure = new Error(`card #${card.number}'s merge of pull request #${next.pull} failed: ${thrown.message}`, { cause: thrown });
99
+ ended = { outcome: 'failed', reason: thrown.message };
100
+ }
101
+ }
102
+ break;
103
+ }
104
+ if (reads > 1) ended = { ...ended, reads, elapsedMs: lastRead - began };
105
+ const reached = { card: card.number, action: 'merge', ...fields, merge: ended };
106
+ try {
107
+ record('merge.end', { ...fields, ...ended }, card.number);
108
+ } catch (refusal) {
109
+ const unrecorded = refused(`card #${card.number}'s merge of pull request #${next.pull} ended ${ended.outcome}, and the event sink refused to record its end, so nothing more is done for it`, refusal);
110
+ const sentence = failure?.cause?.made ? `card #${card.number}'s merge was made, and the event sink refused to record its events and its end` : `card #${card.number}'s merge failed, and its end went unrecorded`;
111
+ return { reached, failure: beside(failure, unrecorded, sentence) };
112
+ }
113
+ if (answer !== undefined) {
114
+ try {
115
+ if (answer.outcome === 'merged' || answer.outcome === 'already merged') await removeDirectories(card.number);
116
+ await l2.mergeEnded(item, again, answer);
117
+ } catch (thrown) {
118
+ return { reached, failure: beside(failure, thrown, `card #${card.number}'s merge failed, and so did L2's settle of it`) };
119
+ }
120
+ }
121
+ return { reached, failure };
122
+ };
123
+
124
+ /**
125
+ * Reads `card` from the board again and has L2 run its rule again over it through its facts call,
126
+ * answering the item read and L2's answer `again`. Where L2 answers other than `merge` at `next`'s
127
+ * pull request and head, it answers too what `merge.end` names, `ended`; and where the card could
128
+ * not be read again, or L2 answered no action, `ended` names why and `failure` names the card.
129
+ */
130
+ const rerun = async (card, next) => {
131
+ try {
132
+ const item = (await board.readItems()).find((each) => each.number === card.number);
133
+ if (item === undefined) throw new Error(`card #${card.number} is no longer on the board`);
134
+ const again = (await facts([item]))(item);
135
+ const unchanged = again.action === 'merge' && again.pull === next.pull && again.head === next.head;
136
+ const details = [];
137
+ if (again.pull !== undefined) details.push(`pull request #${again.pull}`);
138
+ if (again.head !== undefined) details.push(`head ${again.head}`);
139
+ if (again.to !== undefined) details.push(`to ${again.to}`);
140
+ if (again.category !== undefined) details.push(`category ${again.category}`);
141
+ if (again.judges !== undefined) details.push(`judges ${again.judges.map(({ role, facts }) => `${role} at ${facts.head}`).join(', ')}`);
142
+ const reason = again.reason ?? (again.action === 'merge'
143
+ ? `L2 answered ${details.join(' at ')}, after the lane pulled pull request #${next.pull} at head ${next.head}`
144
+ : `L2 answered ${again.action}${details.length === 0 ? '' : `: ${details.join(', ')}`}`);
145
+ return { item, again, ...(unchanged ? {} : { ended: { outcome: 'not merged', action: again.action, reason } }), failure: null };
146
+ } catch (thrown) {
147
+ const failure = new Error(`card #${card.number} was not merged, because L2 could not run its rule again: ${thrown.message}`, { cause: thrown });
148
+ return { ended: { outcome: 'not merged', reason: thrown.message }, failure };
149
+ }
150
+ };
151
+
152
+ return {
153
+ /** Queues `claim`'s merge behind every merge queued before it, and settles as `merged` does once it has run. */
154
+ merge: (claim) => {
155
+ const turn = tail.then(() => merged(claim));
156
+ tail = turn.catch(() => {});
157
+ return turn;
158
+ },
159
+ };
160
+ }