@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,588 @@
|
|
|
1
|
+
// ABOUTME: L2's column changes: which column a card moves to when L3 claims it or hands L2 its
|
|
2
|
+
// dispatch's outcome, the move itself through the forge adapter's item-write side, and its event.
|
|
3
|
+
|
|
4
|
+
import { worktreeTopic } from '../config/validate.mjs';
|
|
5
|
+
import { FIXED_LABELS, roleTimeout } from '../config/validate.mjs';
|
|
6
|
+
import { topicFor, SCRATCH_REFUSED, WORKSPACE_REFUSED } from '../execution/workspace.mjs';
|
|
7
|
+
import { readSide, repositoryReads } from '../substrate/forge/read.mjs';
|
|
8
|
+
import { itemWriteSide } from '../substrate/forge/item-write.mjs';
|
|
9
|
+
import { repositoryWriteSide } from '../substrate/forge/repository-write.mjs';
|
|
10
|
+
import { NOT_STARTED } from '../substrate/process.mjs';
|
|
11
|
+
import { EVENT_REFUSED } from '../substrate/process.mjs';
|
|
12
|
+
import { escalationDestination, makerEscalation, makerNote, routingComment, escalationRoleInstruction } from './escalation.mjs';
|
|
13
|
+
import { acceptanceItems } from './form-check.mjs';
|
|
14
|
+
import { acceptanceDigest } from './marker.mjs';
|
|
15
|
+
import { pullRequestsFrom } from './facts.mjs';
|
|
16
|
+
import { statusNotice } from './status-issue.mjs';
|
|
17
|
+
import { kindOf, providerOf, tierOf, recordingHalt } from './next-action.mjs';
|
|
18
|
+
import { composeClockMark, carriesClockMark } from './clock-mark.mjs';
|
|
19
|
+
import { clockAuthor } from './clock-mark.mjs';
|
|
20
|
+
import { firstAbove } from './first-above.mjs';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Each change L2 makes to a card's column, by its cause, as the column keys it leaves and enters.
|
|
24
|
+
* Only `created`, for a card L2 opens from a clock firing, enters `ready` in code.
|
|
25
|
+
*/
|
|
26
|
+
const CHANGES = {
|
|
27
|
+
created: { to: 'ready' },
|
|
28
|
+
claimed: { from: 'ready', to: 'coding' },
|
|
29
|
+
redone: { from: 'review', to: 'coding' },
|
|
30
|
+
returned: { from: 'coding', to: 'review' },
|
|
31
|
+
sound: { from: 'review', to: 'owner' },
|
|
32
|
+
continued: { from: 'review', to: 'coding' },
|
|
33
|
+
continuedFromOwner: { from: 'owner', to: 'coding' },
|
|
34
|
+
rejudged: { from: 'owner', to: 'review' },
|
|
35
|
+
merged: { from: 'review', to: 'done' },
|
|
36
|
+
mergedFromOwner: { from: 'owner', to: 'done' },
|
|
37
|
+
conflicted: { from: 'review', to: 'coding' },
|
|
38
|
+
conflictedFromOwner: { from: 'owner', to: 'coding' },
|
|
39
|
+
escalated: { to: 'owner' },
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* How many events a forge write's failure names as unrecorded, and each with its fields and the
|
|
44
|
+
* sink's error, as a report of a write the forge made names them. A write side marks such a failure `made` where
|
|
45
|
+
* the forge took the write and only its record was refused (`ARCHITECTURE.md`, "L0's call events").
|
|
46
|
+
*/
|
|
47
|
+
export const unrecordedNamed = ({ unrecorded }) => `${unrecorded.length} L0 event(s) went unrecorded: ${unrecorded
|
|
48
|
+
.map(({ event, cause, ...fields }) => `${event} ${JSON.stringify(fields)}: ${cause?.message ?? cause}`).join('; ')}`;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The report of `what`, a forge write the forge made, whose record the sink refused as `failure`
|
|
52
|
+
* names, followed by `also`, any further event that went unrecorded.
|
|
53
|
+
*/
|
|
54
|
+
const madeUnrecorded = (what, failure, also = '') => new Error(`${what}, and the event sink refused to record it: ${unrecordedNamed(failure)}${also}`, { cause: failure });
|
|
55
|
+
|
|
56
|
+
/** The changes L2's `move` answers make, each the one change from its column to the column the answer names. */
|
|
57
|
+
const MOVES = ['sound', 'rejudged', 'merged', 'mergedFromOwner'];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The `code` of the failure `settled` rejects with where a maker exited 0 and L2 left the card in
|
|
61
|
+
* coding for what the forge holds, so its caller tells it from a refused event or a failed read
|
|
62
|
+
* without reading the message. The failure carries the facts L2 read as `facts`.
|
|
63
|
+
*/
|
|
64
|
+
export const REVIEW_WITHHELD = 'REVIEW_WITHHELD';
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* L2's column changes on the board `config` names, each recorded through `sink`. `items` is the
|
|
68
|
+
* forge adapter's item-write side for that board, whose move L2 hands an `L0` emitter it opens
|
|
69
|
+
* from `sink`, and a test passes the fake board's operations in its place, or `send` in place of
|
|
70
|
+
* the runners' spawn. `reads` is the forge adapter's repository reads (`repositoryReads`), by which
|
|
71
|
+
* L2 settles a maker's outcome when injected. `cardReads(card, dispatch)` builds a reader under
|
|
72
|
+
* that card and optional dispatch, defaulting to the injected `reads` or the repository read side.
|
|
73
|
+
* Maker settlement and refused-merge reads use it. `roleReads(card, dispatch)` supplies the
|
|
74
|
+
* contextual reader for a completed escalation role. `board` is the read side's board reads, by
|
|
75
|
+
* which L2's notice finds where the status issue stands on the board.
|
|
76
|
+
*/
|
|
77
|
+
export function columnChanges({
|
|
78
|
+
config, sink, send, items = itemWriteSide({ repo: config.repo, project: config.board.project }, { send }),
|
|
79
|
+
repositoryWrites,
|
|
80
|
+
roleReads = (card, dispatch) => repositoryReads({ ...config.board, repo: config.repo }, { send, emitter: sink.emitter({ layer: 'L0', card, dispatch: dispatch ?? null }) }),
|
|
81
|
+
reads,
|
|
82
|
+
cardReads = (card, dispatch) => reads ?? repositoryReads({ ...config.board, repo: config.repo }, { send, emitter: sink.emitter({ layer: 'L0', card, dispatch }) }),
|
|
83
|
+
board = readSide({ ...config.board, repo: config.repo }, { send, emitter: sink.emitter({ layer: 'L0' }) }),
|
|
84
|
+
}) {
|
|
85
|
+
const { columns } = config.board;
|
|
86
|
+
const topic = worktreeTopic(config);
|
|
87
|
+
const repositoryFor = (card) => repositoryWrites ?? repositoryWriteSide({ repo: config.repo }, { send, emitter: sink.emitter({ layer: 'L0', card: card.number }) });
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Appends `card`'s transition event, or fails naming the card, both columns and the sink's
|
|
91
|
+
* error. When Rigger has acted and cannot record it, it fails loudly and the event stays
|
|
92
|
+
* missing, by the owner's ruling (#220; #277): written later, it would carry the wrong time.
|
|
93
|
+
* Starting no further work is L3's halt, not L2's, so L2 keeps no note of the missing event.
|
|
94
|
+
*/
|
|
95
|
+
const record = (card, transition, context = {}) => {
|
|
96
|
+
try {
|
|
97
|
+
sink.emitter({ layer: 'L2', card: card.number, ...context }).emit('transition', transition);
|
|
98
|
+
} catch (refusal) {
|
|
99
|
+
const { from, to } = transition;
|
|
100
|
+
throw new Error(`card #${card.number} moved ${from === undefined ? `to ${to} (${columns[to]})` : `from ${from} to ${to}`}, and the event sink refused to record it: ${refusal.message}`, { cause: refusal });
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Moves `card` for `cause`, then records the move as one `transition` event, and answers the
|
|
106
|
+
* column the board accepted, as L3's memory of set-aside cards takes it ("Cards this run set
|
|
107
|
+
* aside"). A move the board
|
|
108
|
+
* refuses is recorded as nothing, and its caller is told which card and column it was. A move the
|
|
109
|
+
* item-write side marks made still records its transition, and rejects naming the card, both
|
|
110
|
+
* columns and each event that went unrecorded. Either rejection after the board accepted the move
|
|
111
|
+
* carries that column as `column`. The move
|
|
112
|
+
* is handed an `L0` emitter L2 opens from `sink` under the card, so every kill L0 makes in it is
|
|
113
|
+
* recorded with the card's number.
|
|
114
|
+
*/
|
|
115
|
+
const change = async (card, cause, fields = {}, given = {}) => {
|
|
116
|
+
const { from: declaredFrom, to } = CHANGES[cause];
|
|
117
|
+
const from = cause === 'escalated' ? Object.keys(columns).find((key) => columns[key] === card.column) : declaredFrom;
|
|
118
|
+
const context = cause === 'escalated' || cause === 'created' ? { dispatch: null } : given;
|
|
119
|
+
const transitionFields = { ...(from === undefined ? {} : { from }), to, cause, ...fields };
|
|
120
|
+
try {
|
|
121
|
+
await items.moveItem(card.id, columns[to], sink.emitter({ layer: 'L0', card: card.number, ...context }));
|
|
122
|
+
} catch (refusal) {
|
|
123
|
+
if (!refusal.made) throw new Error(`card #${card.number}'s move ${from === undefined ? '' : `from ${from} `}to ${to} (${columns[to]}) was refused: ${refusal.message}`, { cause: refusal });
|
|
124
|
+
// The board took the move, so its transition is still recorded where the sink takes it (`R-RECORD-6`).
|
|
125
|
+
let transition = '';
|
|
126
|
+
try {
|
|
127
|
+
record(card, transitionFields, context);
|
|
128
|
+
} catch (unrecorded) {
|
|
129
|
+
transition = `; its transition went unrecorded too: ${unrecorded.cause.message}`;
|
|
130
|
+
}
|
|
131
|
+
throw Object.assign(madeUnrecorded(`card #${card.number} moved ${from === undefined ? `to ${to} (${columns[to]})` : `from ${from} to ${to}`}`, refusal, transition), { column: columns[to] });
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
record(card, transitionFields, context);
|
|
135
|
+
let history;
|
|
136
|
+
try {
|
|
137
|
+
history = await cardReads(card.number, context.dispatch).readIssueHistory(card.number);
|
|
138
|
+
} catch (failure) {
|
|
139
|
+
if (failure.code === EVENT_REFUSED) throw failure;
|
|
140
|
+
return columns[to];
|
|
141
|
+
}
|
|
142
|
+
const revisions = history.revisions.length === 0
|
|
143
|
+
? [{ editedAt: history.opened.at, editor: history.opened.by, deleted: false, body: history.body }] : history.revisions;
|
|
144
|
+
const author = revisions[0].deleted ? undefined : clockAuthor(revisions[0].body);
|
|
145
|
+
note(card, 'acceptance.history', {
|
|
146
|
+
opened: history.opened,
|
|
147
|
+
revisions: revisions.map(({ editedAt, editor, deleted, body }) => ({ editedAt, editor, deleted,
|
|
148
|
+
...(!deleted && { digest: acceptanceDigest(body), items: acceptanceItems(body).length }) })),
|
|
149
|
+
...(author === undefined ? {} : { author }),
|
|
150
|
+
}, context);
|
|
151
|
+
} catch (unrecorded) {
|
|
152
|
+
throw Object.assign(unrecorded, { column: columns[to] });
|
|
153
|
+
}
|
|
154
|
+
return columns[to];
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Appends `event`, carrying `fields`, under `card`, or fails naming the card, what the event
|
|
159
|
+
* said and the sink's error.
|
|
160
|
+
*/
|
|
161
|
+
const note = (card, event, fields, context = {}) => {
|
|
162
|
+
try {
|
|
163
|
+
sink.emitter({ layer: 'L2', card: card.number, ...context }).emit(event, fields);
|
|
164
|
+
} catch (refusal) {
|
|
165
|
+
throw recordingHalt(`card #${card.number}: ${fields.reason ?? event}, and the event sink refused to record it: ${refusal.message}`, refusal);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Leaves `card` in coding after a maker exited 0, because `why`: records a `review.withheld`
|
|
171
|
+
* event under the card saying why, and tells its caller the card and why, with the `facts` L2
|
|
172
|
+
* read, as a `REVIEW_WITHHELD` failure.
|
|
173
|
+
*/
|
|
174
|
+
const withheld = (card, why, facts, fields = {}, context = {}) => {
|
|
175
|
+
note(card, 'review.withheld', { reason: why, ...fields }, context);
|
|
176
|
+
throw Object.assign(new Error(`card #${card.number} stays in coding: ${why}`), { code: REVIEW_WITHHELD, facts });
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* L3 hands over `next`, L2's `move` answer for `card` at the pull, unread: the card moves from
|
|
181
|
+
* its column to the column the answer names, by the one change L2 makes between them. A move
|
|
182
|
+
* L2 makes no change for is refused, naming the card and both columns, and nothing moves. It
|
|
183
|
+
* answers the column, as `change` does.
|
|
184
|
+
*/
|
|
185
|
+
const moved = async (card, next) => {
|
|
186
|
+
const from = Object.keys(columns).find((key) => columns[key] === card.column);
|
|
187
|
+
const cause = MOVES.find((each) => CHANGES[each].from === from && CHANGES[each].to === next.to);
|
|
188
|
+
if (cause === undefined) throw new Error(`card #${card.number} has no move from ${from ?? card.column} to ${next.to}`);
|
|
189
|
+
return change(card, cause);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** Records the destination and evidence before either escalation write. */
|
|
193
|
+
const recordEscalation = (card, next) => {
|
|
194
|
+
const evidence = {
|
|
195
|
+
category: next.category, reason: next.reason, raiser: next.raiser ?? 'loop',
|
|
196
|
+
...(next.item === undefined ? {} : { item: next.item }),
|
|
197
|
+
...Object.fromEntries(['class', 'pull', 'head', 'line', 'workspace', 'tip', 'tipUnread', 'destination', 'reads', 'elapsedMs'].filter((key) => next[key] !== undefined).map((key) => [key, next[key]])),
|
|
198
|
+
};
|
|
199
|
+
try {
|
|
200
|
+
sink.emitter({ layer: 'L2', card: card.number, dispatch: next.dispatch ?? null }).emit('review.escalate', evidence);
|
|
201
|
+
} catch (refusal) {
|
|
202
|
+
throw new Error(`card #${card.number}'s escalation in category ${next.category} was refused: review.escalate could not be recorded: ${refusal.message}`, { cause: refusal });
|
|
203
|
+
}
|
|
204
|
+
return evidence;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/** Why a maker that exited `exit` left the forge holding nothing of its line of work `line`. */
|
|
208
|
+
const heldNothing = (card, exit, line) => `card #${card.number}'s maker exited ${exit}, and the forge holds no branch of its line of work ${line}, and no open or merged pull request from it`;
|
|
209
|
+
|
|
210
|
+
/** Both exit-time reads, with presence surviving the other read's failure. */
|
|
211
|
+
const failedMakerWork = async (card, exit, reading, noClock, earlier = [], pullFailure) => {
|
|
212
|
+
const line = topicFor(topic, card.number);
|
|
213
|
+
const [branch, pulls] = await Promise.allSettled([
|
|
214
|
+
Promise.resolve().then(() => reading.readBranches([line])),
|
|
215
|
+
Promise.resolve().then(() => pullFailure === undefined ? pullRequestsFrom(card.number, line, reading, false) : Promise.reject(pullFailure)),
|
|
216
|
+
]);
|
|
217
|
+
const present = (branch.status === 'fulfilled' && branch.value[line] === true)
|
|
218
|
+
|| (pulls.status === 'fulfilled' && ['open', 'merged'].some((state) => pulls.value[state].length > 0));
|
|
219
|
+
const failures = [...earlier, ...[branch, pulls].flatMap((outcome, at) => outcome.status === 'fulfilled' ? []
|
|
220
|
+
: [new Error(`card #${card.number}'s ${at === 0 ? 'branch' : 'pull requests'} could not be read after its maker exited ${exit}: ${outcome.reason.message}`, { cause: outcome.reason })])];
|
|
221
|
+
const makerWork = present ? 'present' : [branch, pulls].every(({ status }) => status === 'fulfilled') ? 'absent' : 'unreadable';
|
|
222
|
+
if (failures.length > 0) throw Object.assign(new AggregateError(failures, failures.map(({ message }) => message).join('; ')), { makerWork });
|
|
223
|
+
if (present) return noClock ? { makerWork: 'present' } : undefined;
|
|
224
|
+
return { action: 'set-aside', makerWork: 'absent', reason: heldNothing(card, exit, line) };
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Open the due firing's card, add it to the board and place it in Ready, handing `placed` its
|
|
229
|
+
* number and the column the board accepted. A placing rejected after the board accepted it
|
|
230
|
+
* carries that column as `column`, beside the issue as `issue`.
|
|
231
|
+
*/
|
|
232
|
+
const openClockCard = async (name, occurrence, template, active = () => true, placed = () => {}) => {
|
|
233
|
+
if (!active()) return undefined;
|
|
234
|
+
const author = (template.author ?? 'owner').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
|
|
235
|
+
const body = `${composeClockMark(name, occurrence)}\n\n**Author:** ${author}\n\n## Acceptance\n\n${template.acceptance}`;
|
|
236
|
+
const writes = repositoryWrites ?? repositoryWriteSide({ repo: config.repo }, { send, emitter: sink.emitter({ layer: 'L0' }) });
|
|
237
|
+
let number;
|
|
238
|
+
try {
|
|
239
|
+
number = await writes.openIssue(template.title, body, ...template.labels);
|
|
240
|
+
} catch (refusal) {
|
|
241
|
+
if (refusal.made) {
|
|
242
|
+
const what = `clock trigger ${name} at ${new Date(occurrence).toISOString()} opened issue #${refusal.made.answer}: ${refusal.message}`;
|
|
243
|
+
throw Object.assign(refusal.unrecorded === undefined ? new Error(what, { cause: refusal }) : madeUnrecorded(what, refusal), { issue: refusal.made.answer });
|
|
244
|
+
}
|
|
245
|
+
throw new Error(`clock trigger ${name} at ${new Date(occurrence).toISOString()} could not open its card: ${refusal.message}`, { cause: refusal });
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
if (!active()) return number;
|
|
249
|
+
let id;
|
|
250
|
+
try {
|
|
251
|
+
id = await items.addIssue(number, sink.emitter({ layer: 'L0', card: number }));
|
|
252
|
+
} catch (refusal) {
|
|
253
|
+
if (refusal.made) throw madeUnrecorded(`issue #${number} was added to the board`, refusal);
|
|
254
|
+
throw new Error(`opened issue #${number}'s board add was refused: ${refusal.message}`, { cause: refusal });
|
|
255
|
+
}
|
|
256
|
+
if (!active()) return number;
|
|
257
|
+
placed(number, await change({ number, id }, 'created'));
|
|
258
|
+
} catch (failure) {
|
|
259
|
+
throw Object.assign(failure, { issue: number });
|
|
260
|
+
}
|
|
261
|
+
return number;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
/** The fence the firing records before it opens its card. */
|
|
266
|
+
clockCardNumber: () => (reads ?? cardReads()).readNewestNumber(),
|
|
267
|
+
openClockCard,
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Finds the pending firing's card, places an unplaced open one, or opens from its eligible
|
|
271
|
+
* template. Placing one hands `placed` its number and the column the board accepted, and a
|
|
272
|
+
* placing rejected after the board accepted it carries that column as `column`.
|
|
273
|
+
*/
|
|
274
|
+
clockCardAfter: async (name, occurrence, after, template, floor = 0, active = () => true, placed = () => {}) => {
|
|
275
|
+
const supplied = reads ?? cardReads();
|
|
276
|
+
const issue = await firstAbove(after, { ...supplied, readNewestNumber: async () => Math.max(floor, await supplied.readNewestNumber()) },
|
|
277
|
+
(candidate) => carriesClockMark(candidate.body, name, occurrence), active);
|
|
278
|
+
if (!active()) return issue?.number;
|
|
279
|
+
if (issue === undefined) return template === undefined ? undefined : openClockCard(name, occurrence, template, active, placed);
|
|
280
|
+
try {
|
|
281
|
+
if (issue.state === 'open') {
|
|
282
|
+
const item = (await board.readItems()).find((each) => each.number === issue.number);
|
|
283
|
+
if (!active()) return issue.number;
|
|
284
|
+
if (item?.column == null) {
|
|
285
|
+
const id = item?.id ?? await items.addIssue(issue.number, sink.emitter({ layer: 'L0', card: issue.number }));
|
|
286
|
+
if (!active()) return issue.number;
|
|
287
|
+
placed(issue.number, await change({ number: issue.number, id }, 'created'));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
} catch (failure) {
|
|
291
|
+
throw Object.assign(failure, { issue: issue.number });
|
|
292
|
+
}
|
|
293
|
+
return issue.number;
|
|
294
|
+
},
|
|
295
|
+
|
|
296
|
+
/** L2's notice function for a hold's closer, as `statusNotice` says, its item writes recorded under `L0`. */
|
|
297
|
+
notice: statusNotice({ reads: reads ?? repositoryReads({ ...config.board, repo: config.repo }, { send, emitter: sink.emitter({ layer: 'L0' }) }), writes: repositoryWrites ?? repositoryWriteSide({ repo: config.repo }, { send, emitter: sink.emitter({ layer: 'L0' }) }), board, items: { addIssue: (number) => items.addIssue(number, sink.emitter({ layer: 'L0' })), moveItem: (id, column) => items.moveItem(id, column, sink.emitter({ layer: 'L0' })) }, columns, sink }),
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* L3 has claimed `card`, a board item as the forge adapter read it, on `next`, L2's answer for
|
|
301
|
+
* it at the pull, which L3 hands over unread. A card claimed from coding is there already, and
|
|
302
|
+
* is not moved, and so is one claimed for its judges, which stays in review. One otherwise
|
|
303
|
+
* claimed from review is done again from the beginning, and moves to coding, where it shows
|
|
304
|
+
* while it is (`R-WORK-24`). Any other claim is of a ready card, which moves to coding. A card
|
|
305
|
+
* L2 answered as a continuing attempt moves to coding from review or owner by its continuing
|
|
306
|
+
* change, never as `redone`, since its work goes on from what was pushed; from coding it stays.
|
|
307
|
+
* A move answers its column, as `change` does.
|
|
308
|
+
*/
|
|
309
|
+
claimed: async (card, next) => {
|
|
310
|
+
if (next?.action === 'continue' && card.column !== columns.coding) {
|
|
311
|
+
return change(card, card.column === columns.owner ? 'continuedFromOwner' : 'continued');
|
|
312
|
+
}
|
|
313
|
+
if (card.column === columns.coding || next?.action === 'judge') return undefined;
|
|
314
|
+
return change(card, card.column === columns.review ? 'redone' : 'claimed');
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
moved,
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* L3's lane hands over `next`, L2's `merge` answer for `card` from its rule run again at the
|
|
321
|
+
* lane: L2 records its digest and governing verdicts before merging the pull request it names
|
|
322
|
+
* at the head it names through the repository-write
|
|
323
|
+
* side, and marks an unknown-mergeability refusal for L3's full re-read. Other answers pass
|
|
324
|
+
* through unread, and a failed call rejects as it did.
|
|
325
|
+
*/
|
|
326
|
+
merge: async (card, next) => {
|
|
327
|
+
note(card, 'merge.decided', { pull: next.pull, head: next.head, digest: next.digest, judges: next.verdicts });
|
|
328
|
+
const answer = await repositoryFor(card).mergePullRequest(next.pull, next.head);
|
|
329
|
+
return answer.outcome === 'refused' && answer.reason === 'unknown' ? { ...answer, unknownMergeability: true } : answer;
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* L3's lane hands over `answer`, what L2's `merge` answered for `card` on `next`, once it has
|
|
334
|
+
* recorded the merge's end. A merge the forge made, or had made already, moves the card to Done
|
|
335
|
+
* from its column, as `moved` moves it. A refused merge has L2 read the pull request's
|
|
336
|
+
* mergeability, and only that read decides a conflict, never the refusal's reason (the
|
|
337
|
+
* architect's r3 ruling 5): read as conflicting, the card moves to coding, its transition's cause
|
|
338
|
+
* naming the conflict, where its maker continues on the pull request (`R-CONFLICT-1`). Any other
|
|
339
|
+
* refusal leaves the card where it is. A read that fails leaves it there too, and rejects naming
|
|
340
|
+
* the card and the read. A move answers its column, as `change` does.
|
|
341
|
+
*/
|
|
342
|
+
mergeEnded: async (card, next, answer) => {
|
|
343
|
+
if (['merged', 'already merged'].includes(answer.outcome)) return moved(card, { to: 'done' });
|
|
344
|
+
if (answer.outcome !== 'refused' || answer.unknownMergeability) return undefined;
|
|
345
|
+
let mergeable;
|
|
346
|
+
try {
|
|
347
|
+
mergeable = await cardReads(card.number).readMergeable(next.pull);
|
|
348
|
+
} catch (failure) {
|
|
349
|
+
throw new Error(`card #${card.number}'s merge of pull request #${next.pull} was refused, and L2 could not read its mergeability: ${failure.message}`, { cause: failure });
|
|
350
|
+
}
|
|
351
|
+
return mergeable === 'conflicting' ? change(card, card.column === columns.owner ? 'conflictedFromOwner' : 'conflicted') : undefined;
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
/** Posts L2's return comment on its pull request, without changing the card's column. */
|
|
355
|
+
returned: async (card, next) => {
|
|
356
|
+
try {
|
|
357
|
+
await repositoryFor(card).postComment(next.pull, next.comment);
|
|
358
|
+
} catch (refusal) {
|
|
359
|
+
if (refusal.made) throw madeUnrecorded(`card #${card.number}'s return comment on pull request #${next.pull} was posted`, refusal);
|
|
360
|
+
throw new Error(`card #${card.number}'s return comment on pull request #${next.pull} was refused: ${refusal.message}`, { cause: refusal });
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
/** Posts the route before L3 makes any directory or dispatches the role. */
|
|
365
|
+
routed: async (card, next) => {
|
|
366
|
+
const name = next.destination;
|
|
367
|
+
const declared = config.roles[name];
|
|
368
|
+
const { provider, conflict } = providerOf(card, name, declared, 'escalation');
|
|
369
|
+
if (conflict !== undefined) return ownerEscalation(next, { category: 'ambiguous', reason: conflict });
|
|
370
|
+
const { tier, conflict: tierConflict } = tierOf(card, name, declared, 'escalation');
|
|
371
|
+
if (tierConflict !== undefined) return ownerEscalation(next, { category: 'ambiguous', reason: tierConflict });
|
|
372
|
+
recordEscalation(card, next);
|
|
373
|
+
const writes = repositoryWrites ?? repositoryWriteSide({ repo: config.repo }, { send, emitter: sink.emitter({ layer: 'L0', card: card.number, dispatch: next.dispatch ?? null }) });
|
|
374
|
+
try {
|
|
375
|
+
await writes.postIssueComment(card.number, routingComment(next));
|
|
376
|
+
} catch (refusal) {
|
|
377
|
+
if (refusal.made) throw madeUnrecorded(`card #${card.number}'s routing comment was posted`, refusal);
|
|
378
|
+
const reason = `card #${card.number}'s routing comment was refused: ${refusal.message}`;
|
|
379
|
+
note(card, 'escalation.route-refused', { reason }, { dispatch: next.dispatch ?? null });
|
|
380
|
+
throw new Error(reason, { cause: refusal });
|
|
381
|
+
}
|
|
382
|
+
return { ...next, action: 'dispatch', role: { role: name, agent: declared.agent, provider, tier, timeout: roleTimeout(declared), ...escalationRoleInstruction(card, next) } };
|
|
383
|
+
},
|
|
384
|
+
|
|
385
|
+
/** Settles the escalation role against the forge under the card's existing claim; a handled move answers its `column`. */
|
|
386
|
+
roleSettled: async (card, next, outcome, { dispatch, firstFailure } = {}) => {
|
|
387
|
+
if (outcome.status === 'rejected' && [WORKSPACE_REFUSED, SCRATCH_REFUSED].includes(outcome.reason?.code)) return ownerEscalation(next, { class: 'card-local', category: 'ambiguous', reason: outcome.reason.message, dispatch });
|
|
388
|
+
if (outcome.status === 'rejected' && outcome.reason?.code === NOT_STARTED) {
|
|
389
|
+
if (firstFailure === undefined) return { action: 'again' };
|
|
390
|
+
return ownerEscalation(next, { class: 'environment', category: 'ambiguous', reason: `role ${next.destination} did not start twice: ${firstFailure.reason.message}; ${outcome.reason.message}`, dispatch });
|
|
391
|
+
}
|
|
392
|
+
if (outcome.status === 'rejected') return undefined;
|
|
393
|
+
const reading = roleReads(card.number, dispatch);
|
|
394
|
+
const comments = await reading.readIssueComments(card.number);
|
|
395
|
+
const note = makerNote(comments, dispatch, acceptanceItems(card.body ?? '').length);
|
|
396
|
+
const facts = await pullRequestsFrom(card.number, next.line, reading, false);
|
|
397
|
+
const { pull: priorPull, head: priorHead, ...route } = next;
|
|
398
|
+
const current = { ...route, ...(facts.open.length === 1 ? { pull: facts.open[0].number, head: facts.open[0].head } : {}) };
|
|
399
|
+
if (note !== null) return ownerEscalation(current, note);
|
|
400
|
+
if (outcome.value.exit !== 0) return ownerEscalation(current, { category: 'ambiguous', reason: `role ${next.destination} exited ${outcome.value.exit}`, dispatch });
|
|
401
|
+
const column = facts.open.length === 1 ? await change(card, 'returned', {}, { dispatch: dispatch ?? null }) : undefined;
|
|
402
|
+
return { action: 'handled', facts, ...(column === undefined ? {} : { column }) };
|
|
403
|
+
},
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Records the escalation, then comments on its issue, moves to Owner and labels it, answering
|
|
407
|
+
* Owner's column as `change` does. A refused label carries that column as `column`.
|
|
408
|
+
*/
|
|
409
|
+
escalated: async (card, next) => {
|
|
410
|
+
const evidence = recordEscalation(card, next);
|
|
411
|
+
const writes = repositoryWrites ?? repositoryWriteSide({ repo: config.repo }, { send, emitter: sink.emitter({ layer: 'L0', card: card.number, dispatch: null }) });
|
|
412
|
+
try {
|
|
413
|
+
await writes.postIssueComment(card.number, escalationComment(card, evidence));
|
|
414
|
+
} catch (refusal) {
|
|
415
|
+
if (refusal.made) throw madeUnrecorded(`card #${card.number}'s escalation issue comment was posted`, refusal);
|
|
416
|
+
throw new Error(`card #${card.number}'s escalation issue comment was refused: ${refusal.message}`, { cause: refusal });
|
|
417
|
+
}
|
|
418
|
+
const column = await change(next.from === undefined ? card : { ...card, column: columns[next.from] }, 'escalated');
|
|
419
|
+
try {
|
|
420
|
+
await writes.addIssueLabel(card.number, FIXED_LABELS.escalated);
|
|
421
|
+
} catch (refusal) {
|
|
422
|
+
if (refusal.made) throw Object.assign(madeUnrecorded(`card #${card.number}'s escalation label ${FIXED_LABELS.escalated} was added`, refusal), { column });
|
|
423
|
+
throw Object.assign(new Error(`card #${card.number}'s escalation label ${FIXED_LABELS.escalated} was refused: ${refusal.message}`, { cause: refusal }), { column });
|
|
424
|
+
}
|
|
425
|
+
return column;
|
|
426
|
+
},
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* L3 hands over `card`'s maker `outcome` unread, as `Promise.allSettled` records it: a
|
|
430
|
+
* dispatch that ran and recorded its events is fulfilled with L1's result, its exit code
|
|
431
|
+
* `exit` and its output `stdout` and `stderr`. The failure's `code` names three kinds of
|
|
432
|
+
* rejection: a command that never started (`NOT_STARTED`), a refused event
|
|
433
|
+
* (`EVENT_REFUSED`), which may carry the result of a command that ran, and a record that
|
|
434
|
+
* refused a removal after the command ran (`RECORD_REFUSED`), which carries its result. L2
|
|
435
|
+
* moves nothing on a rejection of any kind, and records one that never started as a
|
|
436
|
+
* `maker.failed` event under the card, classed as the environment's, as it classes a step
|
|
437
|
+
* that never started (the architect's ruling 5 on #467).
|
|
438
|
+
*
|
|
439
|
+
* For a fulfilled outcome or a fresh rejected one carrying a nonzero result, the forge's issue
|
|
440
|
+
* comments are read before classifying the exit. A valid
|
|
441
|
+
* note under the maker's dispatch answers an escalation without a move, with any one open pull
|
|
442
|
+
* request and its head read from the line of work. Otherwise the exit code and the forge alone
|
|
443
|
+
* decide, never the output (the owner's ruling on #220, refined by O5 on #467). Anything but
|
|
444
|
+
* zero leaves the card in coding. A continuing maker's plain nonzero exit answers nothing,
|
|
445
|
+
* without reading forge work. A fresh maker's plain nonzero exit reads the branch and pull requests in
|
|
446
|
+
* every state, without review facts. Where it holds no branch and no open or merged pull request, it answers `set-aside`, with a reason
|
|
447
|
+
* naming the card, exit code and line of work; otherwise it answers nothing. Failed reads
|
|
448
|
+
* reject naming each read, carrying absent, present or unreadable work classification for L3.
|
|
449
|
+
* A no-clock settle also carries its successful classification; a clock-held present answer stays undefined.
|
|
450
|
+
* Zero has L2 read the pull requests from the card's line of work
|
|
451
|
+
* and, where exactly one is open, what L2's judge answer reads of it, as
|
|
452
|
+
* `pullRequestsFrom` reads them. For a continuing attempt, a head other than `expectedHead`
|
|
453
|
+
* answers `waiting` until L3's last read, when L2 withholds review and names both heads.
|
|
454
|
+
* Where that head is `startHead`, the head L3 handed the maker, L2 moves nothing and answers a
|
|
455
|
+
* loop-raised `ambiguous` escalation naming the head and `rulings`, the markers L2 handed the
|
|
456
|
+
* maker, unread by L3 (`R-LOOP-20`).
|
|
457
|
+
* With exactly one open at the expected head, the card moves to review (`R-WORK-18`),
|
|
458
|
+
* and L2 hands `placed` the column the board accepted, as `change` answers it. A move whose record
|
|
459
|
+
* then failed rejects carrying that column as `column`, as `change` says. L2
|
|
460
|
+
* answers the facts it read, `{ line, open, merged, closed }` with those beside them, to its
|
|
461
|
+
* caller, which hands them back unread to L2's next action (the architect's ruling 3, AQ4). With
|
|
462
|
+
* none open, or more than one, the card stays in coding, and L2 records why and
|
|
463
|
+
* tells its caller the card and why, as `withheld` says. A read that fails leaves it in coding too, and its
|
|
464
|
+
* caller is told the card and the read. A fresh maker's exit 0 with none open, or with the read
|
|
465
|
+
* failing, instead answers a loop-raised `ambiguous` escalation (`R-LOOP-21` to `R-LOOP-24`), as
|
|
466
|
+
* `deliveredNothing` says, naming `workspace` and `tip`, which L3 hands unread for a fresh maker,
|
|
467
|
+
* or `tipUnread`, L1's failure to read that tip. A fresh maker is one handed neither
|
|
468
|
+
* `continuing`, `expectedHead` nor `tipFailure`.
|
|
469
|
+
*/
|
|
470
|
+
settled: async (card, outcome, { dispatch, continuing = false, noClock = false, startHead, rulings = [], expectedHead, tipFailure, tip, tipUnread, workspace, lastForgeHead, last = false, reads: readCount, elapsedMs, placed = () => {} } = {}) => {
|
|
471
|
+
const exit = outcome?.status === 'fulfilled' ? outcome.value?.exit : outcome?.status === 'rejected' ? outcome.reason?.result?.exit : undefined;
|
|
472
|
+
// A refused recording retains the result of a command that ran; its failure still reaches L3.
|
|
473
|
+
if (outcome?.status === 'rejected' && ((continuing && !noClock) || !Number.isInteger(exit) || exit === 0)) {
|
|
474
|
+
if (outcome.reason?.code === NOT_STARTED) note(card, 'maker.failed', { class: 'environment', reason: outcome.reason.message }, { dispatch });
|
|
475
|
+
return undefined;
|
|
476
|
+
}
|
|
477
|
+
if (!Number.isInteger(exit)) {
|
|
478
|
+
throw new Error(`card #${card.number}'s dispatch outcome is neither a dispatch that ran with an exit code nor one that threw: ${JSON.stringify(outcome)}`);
|
|
479
|
+
}
|
|
480
|
+
const reading = cardReads(card.number, dispatch);
|
|
481
|
+
let comments;
|
|
482
|
+
try {
|
|
483
|
+
comments = await reading.readIssueComments(card.number);
|
|
484
|
+
} catch (failure) {
|
|
485
|
+
const unread = new Error(`card #${card.number}'s issue comments could not be read: ${failure.message}`, { cause: failure });
|
|
486
|
+
if ((noClock || !continuing) && exit !== 0) return failedMakerWork(card, exit, reading, noClock, [unread]);
|
|
487
|
+
throw unread;
|
|
488
|
+
}
|
|
489
|
+
const escalation = makerNote(comments, dispatch, acceptanceItems(card.body ?? '').length);
|
|
490
|
+
if (escalation !== null) {
|
|
491
|
+
let facts;
|
|
492
|
+
try {
|
|
493
|
+
facts = await pullRequestsFrom(card.number, topicFor(topic, card.number), reading);
|
|
494
|
+
} catch (failure) {
|
|
495
|
+
const unread = new Error(`card #${card.number}'s pull requests could not be read for its escalation: ${failure.message}`, { cause: failure });
|
|
496
|
+
if ((noClock || !continuing) && exit !== 0) return failedMakerWork(card, exit, reading, noClock, [], unread);
|
|
497
|
+
throw unread;
|
|
498
|
+
}
|
|
499
|
+
const kinds = config.kinds ?? {};
|
|
500
|
+
const { kind } = kindOf({ ...card, labels: card.labels ?? [] }, kinds, config.epicLabel);
|
|
501
|
+
const answer = makerEscalation(escalation, facts);
|
|
502
|
+
return { ...answer, destination: escalationDestination({ ...answer, escalate: config.escalate, maker: kinds[kind]?.maker, judges: kinds[kind]?.judges, comments }) };
|
|
503
|
+
}
|
|
504
|
+
if (exit !== 0) {
|
|
505
|
+
if (noClock || !continuing) return failedMakerWork(card, exit, reading, noClock);
|
|
506
|
+
return undefined;
|
|
507
|
+
}
|
|
508
|
+
// L3 hands `expectedHead` or `tipFailure` only for a continuing maker, and `tip` or `tipUnread` only for a fresh one.
|
|
509
|
+
const fresh = !continuing && expectedHead === undefined && tipFailure === undefined;
|
|
510
|
+
if (tipFailure !== undefined) withheld(card, `card #${card.number}'s maker exited 0, but L1 could not read the tip of its line of work in the workspace: ${tipFailure.message}`, undefined, {}, { dispatch });
|
|
511
|
+
let facts;
|
|
512
|
+
try {
|
|
513
|
+
facts = await pullRequestsFrom(card.number, topicFor(topic, card.number), reading);
|
|
514
|
+
} catch (failure) {
|
|
515
|
+
if (fresh) {
|
|
516
|
+
const line = topicFor(topic, card.number);
|
|
517
|
+
return deliveredNothing(card, line, `the forge's open pull requests from its line of work ${line} could not be read: ${failure.message}`, { dispatch, tip, tipUnread, workspace });
|
|
518
|
+
}
|
|
519
|
+
if (expectedHead === undefined) throw failure;
|
|
520
|
+
withheld(card, failure.message, undefined, {
|
|
521
|
+
...(lastForgeHead === undefined ? {} : { forgeHead: lastForgeHead }),
|
|
522
|
+
...(readCount > 1 ? { reads: readCount, elapsedMs } : {}),
|
|
523
|
+
}, { dispatch });
|
|
524
|
+
}
|
|
525
|
+
const { line, open } = facts;
|
|
526
|
+
const observed = expectedHead === undefined ? {} : {
|
|
527
|
+
...(open.length === 1 ? { forgeHead: open[0].head } : lastForgeHead === undefined ? {} : { forgeHead: lastForgeHead }),
|
|
528
|
+
...(readCount > 1 ? { reads: readCount, elapsedMs } : {}),
|
|
529
|
+
};
|
|
530
|
+
if (open.length === 0 && fresh) {
|
|
531
|
+
const merged = facts.merged.length === 0 ? '' : `, and it holds merged pull request ${facts.merged.map((pull) => `#${pull.number}`).join(', ')} from it`;
|
|
532
|
+
return deliveredNothing(card, line, `the forge holds no open pull request from its line of work ${line}${merged}`, { dispatch, tip, tipUnread, workspace });
|
|
533
|
+
}
|
|
534
|
+
if (open.length === 0) withheld(card, `its maker exited 0, and the forge holds no open pull request from its line of work ${line}`, facts, observed, { dispatch });
|
|
535
|
+
if (open.length > 1) withheld(card, `its maker exited 0, and the forge holds more than one open pull request from its line of work ${line}: ${open.map((pull) => `#${pull.number}`).join(', ')}`, facts, observed, { dispatch });
|
|
536
|
+
if (expectedHead !== undefined && open[0].head !== expectedHead) {
|
|
537
|
+
if (!last) return { waiting: true, forgeHead: open[0].head };
|
|
538
|
+
withheld(card, `card #${card.number}'s maker exited 0 at head ${expectedHead}, but the forge last showed pull request #${open[0].number} at head ${open[0].head}`, facts, observed, { dispatch });
|
|
539
|
+
}
|
|
540
|
+
if (startHead !== undefined && expectedHead === startHead) {
|
|
541
|
+
return ownerEscalation({}, {
|
|
542
|
+
category: 'ambiguous', pull: open[0].number, head: open[0].head, dispatch,
|
|
543
|
+
...(readCount > 1 ? { reads: readCount, elapsedMs } : {}),
|
|
544
|
+
reason: [`card #${card.number}'s continuing maker exited 0 at head ${startHead}, the head it was given, so it answered nothing.`, ...rulings.map(standingRuling)].join('\n'),
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
placed(await change(card, 'returned', observed, { dispatch }));
|
|
548
|
+
return facts;
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/** The selected reason and available work identifiers, as data on the card's issue. */
|
|
554
|
+
function escalationComment(card, { category, item, reason, pull, head, line, workspace, tip, tipUnread }) {
|
|
555
|
+
const work = [
|
|
556
|
+
...(item === undefined ? [] : [`Acceptance item: ${item}`]),
|
|
557
|
+
...(pull === undefined ? [] : [`Pull request: #${pull}`]),
|
|
558
|
+
...(head === undefined ? [] : [`Head: ${head}`]),
|
|
559
|
+
...(line === undefined ? [] : [`Line of work: ${line}`]),
|
|
560
|
+
...(workspace === undefined ? [] : [`Workspace: ${workspace}, ${tipUnread === undefined ? `its line of work at ${tip}` : `its tip not read: ${tipUnread}`}`]),
|
|
561
|
+
];
|
|
562
|
+
return `Rigger escalates card #${card.number} to the owner (${category}).\n\n${reason}${work.length === 0 ? '' : `\n\n${work.join('\n')}`}\n`;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/** One ruling a continuing maker was handed, as `continued` in judges.mjs handed it. */
|
|
566
|
+
function standingRuling({ role, verdict, toSound, unmet }) {
|
|
567
|
+
return `${role} (${verdict}): ${[...(toSound === undefined ? [] : [toSound]), ...unmet.map(({ item, text }) => `unmet item ${item}: ${text}`)].join('; ')}`;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* The loop-raised `ambiguous` escalation of `card`, whose maker started its work from the
|
|
572
|
+
* beginning and exited 0, saying `held`, what L2 read of the forge for its line of work `line`
|
|
573
|
+
* (`R-LOOP-21` to `R-LOOP-24`). It names `line`, and the workspace L3 handed with the tip L1 read
|
|
574
|
+
* there, or why L1 read none.
|
|
575
|
+
*/
|
|
576
|
+
function deliveredNothing(card, line, held, { dispatch, tip, tipUnread, workspace }) {
|
|
577
|
+
return ownerEscalation({}, {
|
|
578
|
+
category: 'ambiguous', dispatch, line,
|
|
579
|
+
reason: `card #${card.number}'s maker started its work from the beginning and exited 0, and ${held}`,
|
|
580
|
+
...(workspace === undefined ? {} : { workspace, ...(tipUnread === undefined ? { tip } : { tipUnread: tipUnread.message }) }),
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** A role's unresolved card always returns through L2's one destination function as loop-raised. */
|
|
585
|
+
function ownerEscalation(next, fields) {
|
|
586
|
+
const answer = { ...next, ...fields, action: 'escalate', raiser: 'loop' };
|
|
587
|
+
return { ...answer, destination: escalationDestination(answer) };
|
|
588
|
+
}
|