@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.
- package/LICENSE +21 -0
- package/README.md +370 -2
- package/package.json +56 -4
- package/scripts/doc-reference-check.mjs +59 -0
- package/scripts/gate-check.mjs +249 -0
- package/scripts/lib/pack-result.mjs +9 -0
- package/scripts/record-commit.mjs +67 -0
- package/src/cli/doctor.mjs +1021 -0
- package/src/cli/init.mjs +384 -0
- package/src/cli/once.mjs +489 -0
- package/src/cli/pause.mjs +56 -0
- package/src/cli/plan.mjs +106 -0
- package/src/cli/recording.mjs +52 -0
- package/src/cli/report.mjs +242 -0
- package/src/cli/resume.mjs +96 -0
- package/src/cli/rigger.mjs +12 -0
- package/src/cli/run.mjs +10 -0
- package/src/cli/setup-board.mjs +108 -0
- package/src/cli/verbs.mjs +82 -0
- package/src/cli/verdict.mjs +180 -0
- package/src/config/validate.mjs +960 -0
- package/src/execution/groups.mjs +185 -0
- package/src/execution/kept-output.mjs +21 -0
- package/src/execution/role.mjs +171 -0
- package/src/execution/run.mjs +490 -0
- package/src/execution/step.mjs +26 -0
- package/src/execution/workspace.mjs +866 -0
- package/src/observation/push.mjs +103 -0
- package/src/observation/report.mjs +415 -0
- package/src/observation/sink.mjs +271 -0
- package/src/package-commit.json +1 -0
- package/src/scheduling/admission.mjs +390 -0
- package/src/scheduling/clock.mjs +98 -0
- package/src/scheduling/lane.mjs +160 -0
- package/src/scheduling/loop.mjs +1738 -0
- package/src/scheduling/pull-order.mjs +46 -0
- package/src/substrate/data-ref.mjs +147 -0
- package/src/substrate/forge/assets.mjs +5 -0
- package/src/substrate/forge/graphql.mjs +258 -0
- package/src/substrate/forge/item-write.mjs +74 -0
- package/src/substrate/forge/read.mjs +998 -0
- package/src/substrate/forge/repository-write.mjs +152 -0
- package/src/substrate/forge/runners.mjs +510 -0
- package/src/substrate/forge/schema-write.mjs +70 -0
- package/src/substrate/forge/write-made.mjs +40 -0
- package/src/substrate/git-environment.mjs +54 -0
- package/src/substrate/host.mjs +23 -0
- package/src/substrate/launchd.mjs +23 -0
- package/src/substrate/process-table.sh +48 -0
- package/src/substrate/process.mjs +2474 -0
- package/src/substrate/providers/adapters.mjs +8 -0
- package/src/substrate/providers/claude.mjs +427 -0
- package/src/substrate/providers/codex.mjs +349 -0
- package/src/substrate/standard-error.mjs +134 -0
- package/src/substrate/worktrees.mjs +517 -0
- package/src/workflow/clock-mark.mjs +40 -0
- package/src/workflow/escalation.mjs +110 -0
- package/src/workflow/facts.mjs +92 -0
- package/src/workflow/first-above.mjs +17 -0
- package/src/workflow/form-check.mjs +88 -0
- package/src/workflow/gate.mjs +62 -0
- package/src/workflow/judges.mjs +695 -0
- package/src/workflow/marker.mjs +265 -0
- package/src/workflow/next-action.mjs +456 -0
- package/src/workflow/status-issue.mjs +268 -0
- package/src/workflow/transitions.mjs +588 -0
- package/templates/claude/agents/architect.md +116 -0
- package/templates/claude/agents/engineer.md +57 -0
- package/templates/claude/agents/pm.md +114 -0
- package/templates/claude/agents/reviewer.md +37 -0
- package/templates/claude/agents/spike-engineer.md +80 -0
- package/templates/claude/hooks/refuse-reserved-git-commands.mjs +909 -0
- package/templates/claude/settings.json +50 -0
- package/templates/claude/skills/acceptance/SKILL.md +275 -0
- package/templates/claude/skills/agent-style/SKILL.md +78 -0
- package/templates/claude/skills/code-review/SKILL.md +242 -0
- package/templates/claude/skills/proposal/SKILL.md +175 -0
- package/templates/claude/skills/spec-style/SKILL.md +112 -0
- package/templates/claude/skills/tdd/SKILL.md +230 -0
- package/templates/codex/config.toml +19 -0
- package/templates/doc-reference-check.md +25 -0
- package/templates/githooks/pre-push +24 -0
- package/templates/github/workflows/rigger-gate.yml +209 -0
- package/templates/launchd/com.williacj.rigger.plist +31 -0
- package/templates/rigger.config.mjs +78 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// ABOUTME: The forge adapter's repository-write side: merges, issue and PR comments, labels,
|
|
2
|
+
// and issue opening and closing, sent through its own runner. Only L2 reaches it.
|
|
3
|
+
|
|
4
|
+
import { firstLine, readRunner, repositoryWriteRunner } from './runners.mjs';
|
|
5
|
+
import { carried, written } from './write-made.mjs';
|
|
6
|
+
import { sameLabel } from '../../config/validate.mjs';
|
|
7
|
+
|
|
8
|
+
/** The HTTP status and message `gh api` printed for a refused write. */
|
|
9
|
+
function refusal(said) {
|
|
10
|
+
let body = {};
|
|
11
|
+
try { body = JSON.parse(said.stdout); } catch { /* gh can fail before receiving an HTTP body. */ }
|
|
12
|
+
return { status: Number(body.status ?? /HTTP (\d+)/.exec(said.stderr ?? '')?.[1]), message: body.message ?? firstLine(said) };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The mapped refusal named by the merge API, or null for a message the forge has not named. */
|
|
16
|
+
function mergeRefusal(status, message) {
|
|
17
|
+
if (status === 409 && /Head branch was modified/.test(message)) return { reason: 'head moved' };
|
|
18
|
+
if (status !== 405) return null;
|
|
19
|
+
if (/Pull Request has merge conflicts/.test(message)) return { reason: 'conflict' };
|
|
20
|
+
const check = /Required status check "([^"]+)" (is failing|is pending|is expected|was not set by the expected GitHub app)\./.exec(message);
|
|
21
|
+
if (check) {
|
|
22
|
+
const reasons = { 'is failing': 'failing', 'is pending': 'pending', 'is expected': 'no record', 'was not set by the expected GitHub app': 'set by another app' };
|
|
23
|
+
return { reason: reasons[check[2]], context: check[1] };
|
|
24
|
+
}
|
|
25
|
+
if (/Base branch was modified/.test(message)) return { reason: 'base modified' };
|
|
26
|
+
if (/out of date|behind/i.test(message)) return { reason: 'behind' };
|
|
27
|
+
if (/merge commit.*not allowed|merge method.*not allowed/i.test(message)) return { reason: 'method' };
|
|
28
|
+
if (/already merged/i.test(message)) return { reason: 'already merged' };
|
|
29
|
+
if (/closed/i.test(message)) return { reason: 'closed' };
|
|
30
|
+
if (/mergeability.*unknown|mergeable.*unknown/i.test(message)) return { reason: 'unknown' };
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The read gives a pull request's state and head before a merge. */
|
|
35
|
+
async function pullOf(board, number, via) {
|
|
36
|
+
if (!Number.isInteger(number) || number < 1) throw new Error(`pull request #${number} is not a pull request number`);
|
|
37
|
+
const said = await readRunner(['api', `repos/${board.repo}/pulls/${number}`, '-X', 'GET'], via);
|
|
38
|
+
if (said.status !== 0) throw new Error(`reading pull request #${number} failed: ${firstLine(said)}`);
|
|
39
|
+
return JSON.parse(said.stdout);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Name an issue write's target and reason, keeping transport and event-refusal codes, and an event
|
|
44
|
+
* refusal's result, unrecorded events and mark.
|
|
45
|
+
*/
|
|
46
|
+
async function issueWrite(operation, kind, number, write) {
|
|
47
|
+
const named = `${operation} on ${kind} #${number} failed: `;
|
|
48
|
+
try {
|
|
49
|
+
return await write();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error.message.startsWith(named)) throw error;
|
|
52
|
+
throw carried(new Error(`${named}${error.message}`, { cause: error }), error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function repositoryWriteSide(board, { send, emitter, timeout } = {}) {
|
|
57
|
+
const via = { send, emitter, timeout };
|
|
58
|
+
/** The parsed answer of an issue write's call `said`, where it exited 0 within its timeout. */
|
|
59
|
+
const issueAnswer = (said) => {
|
|
60
|
+
if (said.status !== 0 || said.timedOut) throw new Error(firstLine(said));
|
|
61
|
+
return JSON.parse(said.stdout);
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Sends the issue write `args` and answers what `accept` makes of its parsed answer. A refused
|
|
65
|
+
* event on the call is marked made where that check passes or marks its own refusal made.
|
|
66
|
+
*/
|
|
67
|
+
const sendIssue = async (args, accept = (answer) => answer) => {
|
|
68
|
+
const check = (said) => accept(issueAnswer(said));
|
|
69
|
+
return check(await written(repositoryWriteRunner(args, via), check));
|
|
70
|
+
};
|
|
71
|
+
const postIssue = (number, endpoint, value, operation, kind = 'issue') => issueWrite(operation, kind, number, async () => {
|
|
72
|
+
if (!Number.isSafeInteger(number) || number < 1) throw new Error(`${operation} on ${kind} #${number} failed: not an ${kind} number`);
|
|
73
|
+
const args = ['api', `repos/${board.repo}/issues/${number}/${endpoint}`, '-X', 'POST', '-f', value];
|
|
74
|
+
// The error names its operation here, so `issueWrite` passes it on as it stands, whatever gh said.
|
|
75
|
+
const posted = (said) => {
|
|
76
|
+
if (said.status !== 0 || said.timedOut) throw new Error(`${operation} on ${kind} #${number} failed: ${firstLine(said)}`);
|
|
77
|
+
return JSON.parse(said.stdout);
|
|
78
|
+
};
|
|
79
|
+
return posted(await written(repositoryWriteRunner(args, via), posted));
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
/** Merge by merge commit only at `expectedHead`, or answer why the forge refused it. */
|
|
83
|
+
mergePullRequest: async (number, expectedHead) => {
|
|
84
|
+
if (!/^[0-9a-f]{40}$/.test(expectedHead ?? '')) throw new Error('mergePullRequest requires an expected head SHA');
|
|
85
|
+
const pull = await pullOf(board, number, via);
|
|
86
|
+
if (pull.head?.sha !== expectedHead) return { outcome: 'refused', reason: 'head moved' };
|
|
87
|
+
if (!pull.merged && pull.state !== 'open') return { outcome: 'refused', reason: 'closed' };
|
|
88
|
+
if (!pull.merged && pull.mergeable === null) return { outcome: 'refused', reason: 'unknown' };
|
|
89
|
+
if (!pull.merged && pull.mergeable === false) return { outcome: 'refused', reason: 'conflict' };
|
|
90
|
+
const args = ['api', `repos/${board.repo}/pulls/${number}/merge`, '-X', 'PUT', '-f', `sha=${expectedHead}`, '-f', 'merge_method=merge'];
|
|
91
|
+
const merged = (made) => {
|
|
92
|
+
if (made.status !== 0 || made.timedOut) throw new Error(firstLine(made));
|
|
93
|
+
const body = JSON.parse(made.stdout);
|
|
94
|
+
if (body.merged !== true) throw new Error(`mergePullRequest #${number} answered merged ${body.merged}`);
|
|
95
|
+
return { outcome: pull.merged ? 'already merged' : 'merged', sha: body.sha };
|
|
96
|
+
};
|
|
97
|
+
const said = await written(repositoryWriteRunner(args, via), merged);
|
|
98
|
+
if (said.timedOut) throw new Error(`mergePullRequest #${number} failed: ${firstLine(said)}`);
|
|
99
|
+
if (said.status === 0) {
|
|
100
|
+
const body = JSON.parse(said.stdout);
|
|
101
|
+
if (body.merged === true) return { outcome: pull.merged ? 'already merged' : 'merged', sha: body.sha };
|
|
102
|
+
}
|
|
103
|
+
const { status, message } = refusal(said);
|
|
104
|
+
const mapped = mergeRefusal(status, message);
|
|
105
|
+
if (mapped) return { outcome: 'refused', ...mapped };
|
|
106
|
+
throw new Error(`mergePullRequest #${number} failed: ${Number.isFinite(status) ? `HTTP ${status} ` : ''}${message}`);
|
|
107
|
+
},
|
|
108
|
+
/** Post `body` on a pull request, refusing an issue number that is not a pull request. */
|
|
109
|
+
postComment: (number, body) => issueWrite('postComment', 'pull request', number, async () => {
|
|
110
|
+
if (!Number.isSafeInteger(number) || number < 1) throw new Error(`postComment on pull request #${number} failed: not a pull request number`);
|
|
111
|
+
const confirmed = await readRunner(['api', `repos/${board.repo}/pulls/${number}`, '-X', 'GET'], via);
|
|
112
|
+
if (confirmed.status !== 0 || confirmed.timedOut) throw new Error(`postComment on pull request #${number} failed: the forge did not confirm a pull request: ${firstLine(confirmed)}`);
|
|
113
|
+
let pull;
|
|
114
|
+
try { pull = JSON.parse(confirmed.stdout); } catch { /* An unreadable response cannot confirm a PR. */ }
|
|
115
|
+
if (typeof pull?.head?.sha !== 'string' || !/^[0-9a-f]{40}$/.test(pull.head.sha)) throw new Error(`postComment on pull request #${number} failed: the forge did not confirm a pull request`);
|
|
116
|
+
return postIssue(number, 'comments', `body=${body}`, 'postComment', 'pull request');
|
|
117
|
+
}),
|
|
118
|
+
/** Append `body` to an issue, including the issue behind a pull request. */
|
|
119
|
+
postIssueComment: (number, body) => postIssue(number, 'comments', `body=${body}`, 'postIssueComment'),
|
|
120
|
+
/** Add one label without replacing the issue's existing labels. */
|
|
121
|
+
addIssueLabel: async (number, label) => {
|
|
122
|
+
if (typeof label !== 'string' || label.length === 0) throw new Error(`addIssueLabel on issue #${number} failed: requires one label name`);
|
|
123
|
+
return postIssue(number, 'labels', `labels[]=${label}`, 'addIssueLabel');
|
|
124
|
+
},
|
|
125
|
+
/** Open one issue with all its labels in the same request, and return its issue number. */
|
|
126
|
+
openIssue: async (title, body, ...labels) => issueWrite('openIssue', 'repository', board.repo, async () => {
|
|
127
|
+
if (typeof title !== 'string' || !title || typeof body !== 'string' || !body || labels.length === 0 || labels.some((label) => typeof label !== 'string' || !label)) {
|
|
128
|
+
throw new Error('requires a title, body and one or more label names');
|
|
129
|
+
}
|
|
130
|
+
const args = ['api', `repos/${board.repo}/issues`, '-X', 'POST', '-f', `title=${title}`, '-f', `body=${body}`, ...labels.flatMap((label) => ['-f', `labels[]=${label}`])];
|
|
131
|
+
return sendIssue(args, (opened) => {
|
|
132
|
+
if (!Number.isSafeInteger(opened?.number) || opened.number < 1) throw new Error('openIssue answered no issue number');
|
|
133
|
+
const missing = labels.filter((name) => !Array.isArray(opened.labels) || !opened.labels.some((held) => sameLabel(held?.name, name)));
|
|
134
|
+
if (missing.length > 0) {
|
|
135
|
+
throw Object.assign(new Error(`openIssue created issue #${opened.number} without label ${missing.join(', ')}`), { made: { answer: opened.number } });
|
|
136
|
+
}
|
|
137
|
+
return opened.number;
|
|
138
|
+
});
|
|
139
|
+
}),
|
|
140
|
+
/** Close one issue. */
|
|
141
|
+
closeIssue: (number) => issueWrite('closeIssue', 'issue', number, async () => {
|
|
142
|
+
if (!Number.isSafeInteger(number) || number < 1) throw new Error('not an issue number');
|
|
143
|
+
return sendIssue(['api', `repos/${board.repo}/issues/${number}`, '-X', 'PATCH', '-f', 'state=closed']);
|
|
144
|
+
}),
|
|
145
|
+
/** Remove one label from one issue. */
|
|
146
|
+
removeIssueLabel: (number, label) => issueWrite('removeIssueLabel', 'issue', number, async () => {
|
|
147
|
+
if (!Number.isSafeInteger(number) || number < 1) throw new Error('not an issue number');
|
|
148
|
+
if (typeof label !== 'string' || !label) throw new Error('requires one label name');
|
|
149
|
+
return sendIssue(['api', `repos/${board.repo}/issues/${number}/labels/${encodeURIComponent(label)}`, '-X', 'DELETE']);
|
|
150
|
+
}),
|
|
151
|
+
};
|
|
152
|
+
}
|