lastlight-core 0.32.2 → 0.33.1

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 (71) hide show
  1. package/config/default.yaml +81 -0
  2. package/dist/admin/board-cache.d.ts +81 -0
  3. package/dist/admin/board-cache.js +303 -0
  4. package/dist/admin/board-cache.js.map +1 -0
  5. package/dist/admin/board-stream.d.ts +47 -0
  6. package/dist/admin/board-stream.js +45 -0
  7. package/dist/admin/board-stream.js.map +1 -0
  8. package/dist/admin/board.d.ts +284 -0
  9. package/dist/admin/board.js +369 -0
  10. package/dist/admin/board.js.map +1 -0
  11. package/dist/admin/routes.js +943 -13
  12. package/dist/admin/routes.js.map +1 -1
  13. package/dist/config/config.d.ts +88 -0
  14. package/dist/config/config.js +156 -0
  15. package/dist/config/config.js.map +1 -1
  16. package/dist/connectors/github-webhook.d.ts +16 -0
  17. package/dist/connectors/github-webhook.js +105 -8
  18. package/dist/connectors/github-webhook.js.map +1 -1
  19. package/dist/connectors/types.d.ts +9 -2
  20. package/dist/cron/issue-discovery.d.ts +120 -0
  21. package/dist/cron/issue-discovery.js +127 -0
  22. package/dist/cron/issue-discovery.js.map +1 -0
  23. package/dist/cron/runner.d.ts +25 -1
  24. package/dist/cron/runner.js +53 -10
  25. package/dist/cron/runner.js.map +1 -1
  26. package/dist/engine/build-decisions.d.ts +91 -0
  27. package/dist/engine/build-decisions.js +295 -0
  28. package/dist/engine/build-decisions.js.map +1 -0
  29. package/dist/engine/build-gate.d.ts +78 -0
  30. package/dist/engine/build-gate.js +423 -0
  31. package/dist/engine/build-gate.js.map +1 -0
  32. package/dist/engine/github/github.d.ts +213 -6
  33. package/dist/engine/github/github.js +340 -6
  34. package/dist/engine/github/github.js.map +1 -1
  35. package/dist/engine/pr-decisions.d.ts +23 -0
  36. package/dist/engine/pr-decisions.js.map +1 -1
  37. package/dist/engine/router.js +108 -1
  38. package/dist/engine/router.js.map +1 -1
  39. package/dist/engine/stage-advance.d.ts +92 -0
  40. package/dist/engine/stage-advance.js +129 -0
  41. package/dist/engine/stage-advance.js.map +1 -0
  42. package/dist/engine/stage-labels.d.ts +57 -0
  43. package/dist/engine/stage-labels.js +58 -0
  44. package/dist/engine/stage-labels.js.map +1 -0
  45. package/dist/engine/stage-observer.d.ts +79 -0
  46. package/dist/engine/stage-observer.js +221 -0
  47. package/dist/engine/stage-observer.js.map +1 -0
  48. package/dist/index.js +110 -2
  49. package/dist/index.js.map +1 -1
  50. package/dist/logging/phase-log.d.ts +6 -0
  51. package/dist/logging/phase-log.js +16 -0
  52. package/dist/logging/phase-log.js.map +1 -1
  53. package/dist/state/activity-store.d.ts +45 -1
  54. package/dist/state/activity-store.js +44 -0
  55. package/dist/state/activity-store.js.map +1 -1
  56. package/dist/state/execution-store.d.ts +48 -0
  57. package/dist/state/execution-store.js +112 -0
  58. package/dist/state/execution-store.js.map +1 -1
  59. package/dist/state/schema/pg.d.ts +2 -2
  60. package/dist/state/schema/sqlite.d.ts +2 -2
  61. package/dist/state/workflow-run-store.d.ts +75 -0
  62. package/dist/state/workflow-run-store.js +151 -7
  63. package/dist/state/workflow-run-store.js.map +1 -1
  64. package/dist/workflows/resume.js +45 -2
  65. package/dist/workflows/resume.js.map +1 -1
  66. package/dist/workflows/simple.d.ts +40 -1
  67. package/dist/workflows/simple.js +113 -2
  68. package/dist/workflows/simple.js.map +1 -1
  69. package/package.json +3 -3
  70. package/workflows/cron-autonomy.yaml +24 -0
  71. package/workflows/prompts/pr.md +18 -1
@@ -0,0 +1,284 @@
1
+ /**
2
+ * The pipeline board — the PURE projection of labels, runs and approvals onto
3
+ * columns.
4
+ *
5
+ * Everything in this module is a function of its arguments. No Hono, no
6
+ * GitHub, no database: the caller (`admin/routes.ts`) resolves the three
7
+ * inputs — cached live items, one `latestForTriggers` map, one
8
+ * `listPending()` — and hands them over. That is what makes the board's rules
9
+ * table-testable, and it is the same split `pr-decisions.ts` makes against
10
+ * `pr-state.ts`.
11
+ *
12
+ * ## Columns come from CONFIG, never from constants
13
+ *
14
+ * The stage vocabulary is operator-owned (`autonomy.stages`,
15
+ * `engine/stage-labels.ts`), so the columns are read from it in the order the
16
+ * operator declared them. A deployment that has configured no stages gets
17
+ * `configured: false` and NO columns — the UI then says so, rather than the
18
+ * server inventing "Intake / Triage / In Progress / Review". Those names come
19
+ * from a mockup; they are examples, not a schema, and a board that shows
20
+ * columns nothing writes to is a board that lies.
21
+ *
22
+ * Each stage contributes its four labels in pipeline order — `enter`,
23
+ * `running`, `on_success`, `on_failure` — which is what turns one configured
24
+ * stage into a legible four-column board rather than a single column. Labels
25
+ * repeated across stages collapse onto their first column: a card carrying the
26
+ * label belongs in one place, and the earlier position is the one the pipeline
27
+ * reaches first.
28
+ *
29
+ * ## The RUN decides a tie; column order is the fallback
30
+ *
31
+ * A card carrying two stage labels is not an error state to refuse; it is the
32
+ * ordinary result of `stage-advance.ts`'s ADD-then-REMOVE ordering failing
33
+ * halfway (its module header explains why that direction is the safe one), or
34
+ * of a re-run leaving an older verdict behind. Either way the card is flagged
35
+ * `ambiguousStage: true` so the UI shows the pair rather than silently picking.
36
+ *
37
+ * WHICH column it lands in is decided by the latest run, when there is one:
38
+ * a `succeeded` run means the `on_success` column and a `failed` one means
39
+ * `on_failure`, because the run is the FACT and the labels are its projection.
40
+ * Column order alone gets this wrong in the case that actually happens — an
41
+ * issue that failed, was re-run, and succeeded carries both terminal labels,
42
+ * and `on_failure` sits right-most, so the board would file a finished build
43
+ * under "blocked" and show a green SUCCEEDED band inside a red column.
44
+ *
45
+ * With no run, or a run still in flight, the right-most matching column wins:
46
+ * the card has PROGRESSED, and later stages are further right.
47
+ *
48
+ * ## Why the SERVER computes `actions`
49
+ *
50
+ * Because the server is the side that knows the hold label, the run lock and
51
+ * the route map. Deriving them in the SPA would mean a second implementation of
52
+ * policy in a place that cannot see any of the three — the #256 class of defect
53
+ * exactly. In this slice the actions are advisory (the client renders them
54
+ * inert), but they are computed honestly so that wiring them up later is a
55
+ * client change, not a second policy.
56
+ */
57
+ /** A label chip, as GitHub reports it. `color` is a bare hex string, no `#`. */
58
+ export interface BoardLabel {
59
+ name: string;
60
+ color: string;
61
+ description?: string;
62
+ }
63
+ /**
64
+ * A pull request that closes a board issue. Structurally satisfied by the
65
+ * GitHub client's `BoardLinkedPr`.
66
+ */
67
+ export interface BoardLinkedPr {
68
+ number: number;
69
+ url: string;
70
+ title: string;
71
+ /** `OPEN` | `CLOSED` | `MERGED`. */
72
+ state: string;
73
+ draft: boolean;
74
+ }
75
+ /**
76
+ * The live item the board is projecting — one open ISSUE. Pull requests are
77
+ * never cards: the pipeline builds issues, and a PR appears only as a link on
78
+ * the issue it closes ({@link BoardLinkedPr}).
79
+ */
80
+ export interface BoardBuilderItem {
81
+ /** Qualified `owner/repo`. */
82
+ repo: string;
83
+ number: number;
84
+ title: string;
85
+ url: string;
86
+ author: string;
87
+ createdAt: string;
88
+ labels: BoardLabel[];
89
+ /** Pull requests that close this issue. Absent or empty when there are none. */
90
+ linkedPrs?: BoardLinkedPr[];
91
+ /** Flattened, server-truncated body text. Empty when GitHub gave us none. */
92
+ body?: string;
93
+ }
94
+ /**
95
+ * The run facts a card renders. Structurally satisfied by `WorkflowRun`, and
96
+ * declared here rather than imported so the builder's tests need no store.
97
+ */
98
+ export interface BoardBuilderRun {
99
+ id: string;
100
+ workflowName: string;
101
+ status: string;
102
+ currentPhase?: string;
103
+ startedAt: string;
104
+ /**
105
+ * Why this run failed, short enough for a card. Present only on a FAILED run
106
+ * whose ledger carried a reason — see `failureReasonsForRuns`. A FAILED band
107
+ * with no reason cannot distinguish "blocked by guardrails" from "crashed",
108
+ * which on the bootstrap path is the whole question.
109
+ */
110
+ failure?: {
111
+ phase: string;
112
+ reason: string;
113
+ };
114
+ /**
115
+ * The phase to SHOW for this run, when it differs from `currentPhase`.
116
+ *
117
+ * `currentPhase` is written on phase COMPLETION, so it lags by one for every
118
+ * phase after the first — a run working on `executor` reads `architect`. This
119
+ * is the honest answer: the ledger's in-flight phase for a live run, the
120
+ * phase that failed for a failed one. Absent when the two agree or when
121
+ * nothing better is known, and the card falls back to `currentPhase`.
122
+ */
123
+ phase?: string;
124
+ }
125
+ /** The approval facts a card renders. Structurally satisfied by `WorkflowApproval`. */
126
+ export interface BoardBuilderApproval {
127
+ id: string;
128
+ workflowRunId: string;
129
+ gate: string;
130
+ summary?: string;
131
+ artifact?: string;
132
+ createdAt: string;
133
+ }
134
+ /**
135
+ * One configured stage, flattened. Structurally satisfied by
136
+ * `AutonomyStageConfig` plus the record key it was declared under.
137
+ */
138
+ export interface BoardStage {
139
+ /** The key in `autonomy.stages` — `build` for the one shipped stage. */
140
+ id: string;
141
+ enter: string;
142
+ running: string;
143
+ on_success: string;
144
+ on_failure: string;
145
+ }
146
+ /** An action the board offers on a card. */
147
+ export interface BoardAction {
148
+ id: string;
149
+ label: string;
150
+ kind: string;
151
+ enabled: boolean;
152
+ disabledReason?: string | null;
153
+ /**
154
+ * The stage label this action moves the card TO — set only on the
155
+ * move-shaped actions (`unblock`).
156
+ *
157
+ * The SERVER names it for the same reason it computes `enabled`: stage labels
158
+ * are operator-configured, so a client deriving "the entry column" from
159
+ * column order would be re-deriving policy it cannot see. It also means the
160
+ * button and the drag gesture post the identical request.
161
+ */
162
+ to?: string;
163
+ }
164
+ export interface BoardCard {
165
+ /** `owner/repo#123` — also the `workflow_runs.triggerId` for this subject. */
166
+ key: string;
167
+ repo: string;
168
+ number: number;
169
+ title: string;
170
+ author: string;
171
+ createdAt: string;
172
+ url: string;
173
+ labels: BoardLabel[];
174
+ /**
175
+ * Pull requests that close this issue — the build's PR once it exists, or one
176
+ * a human opened. Absent when there are none (or on the throttled fallback,
177
+ * which cannot read closing references).
178
+ */
179
+ linkedPrs?: BoardLinkedPr[];
180
+ /**
181
+ * A short excerpt of the item's body, already flattened and clipped by the
182
+ * GitHub client. Absent or empty means GitHub gave us none — an item with no
183
+ * description, or the throttled REST path, which does not fetch one.
184
+ */
185
+ body?: string;
186
+ /** The stage label this card was filed under; empty for an unstaged card. */
187
+ stageLabel: string;
188
+ /** The card carries more than one configured stage label. */
189
+ ambiguousStage: boolean;
190
+ /** The hold label is on this card — Last Light is off this subject entirely. */
191
+ held: boolean;
192
+ /**
193
+ * WHY it is held, in prose naming the operator's configured hold label.
194
+ *
195
+ * Present only when {@link held}. The server supplies it because the server
196
+ * is the side that knows the label's name — it is operator-configurable, so
197
+ * the client cannot render "remove `lastlight-ignore`" from a bare boolean
198
+ * without hardcoding a string that may be wrong.
199
+ */
200
+ heldReason?: string;
201
+ run?: BoardBuilderRun | null;
202
+ approval?: BoardBuilderApproval | null;
203
+ actions: BoardAction[];
204
+ }
205
+ export interface BoardColumn {
206
+ /** Stable `<stage>.<slot>` id — survives an operator renaming the label. */
207
+ id: string;
208
+ title: string;
209
+ /** The GitHub label this column collects. */
210
+ label: string;
211
+ count: number;
212
+ /** Cards in this column with a pending approval — the HITL badge. */
213
+ awaitingHumanCount: number;
214
+ cards: BoardCard[];
215
+ }
216
+ export interface BoardScope {
217
+ repos: string[];
218
+ truncated: boolean;
219
+ reason: string;
220
+ /**
221
+ * Every repo this board COULD show — the autonomy allow-list intersected with
222
+ * the managed set — whether or not it is in the current `repos` scope.
223
+ *
224
+ * The scope picker is built from this rather than from `GET /repos`. That
225
+ * endpoint answers "what does this deployment manage", which is a strictly
226
+ * larger set, so a picker fed from it offers repos the board can never
227
+ * display: pick one and you get an empty board with no explanation, because
228
+ * the server correctly filtered it out. The eligible list is the server's own
229
+ * answer to the only question the picker is asking.
230
+ */
231
+ eligible: string[];
232
+ }
233
+ export interface BoardDegradation {
234
+ repo: string;
235
+ error: string;
236
+ staleSince?: string;
237
+ }
238
+ export interface BoardResponse {
239
+ generatedAt: string;
240
+ ttlSeconds: number;
241
+ /** False when the operator has configured no `autonomy.stages`. */
242
+ configured: boolean;
243
+ scope: BoardScope;
244
+ degraded: BoardDegradation[];
245
+ columns: BoardColumn[];
246
+ unstaged?: {
247
+ count: number;
248
+ cards: BoardCard[];
249
+ };
250
+ }
251
+ export interface BuildBoardInput {
252
+ /**
253
+ * The phase each ACTIVE run is running right now, keyed by RUN id — one
254
+ * `inFlightPhasesForRuns` answer. See {@link BoardBuilderRun.phase}.
255
+ */
256
+ inFlight?: Map<string, string>;
257
+ /**
258
+ * Why each FAILED run failed, keyed by RUN id — not by trigger id, unlike
259
+ * {@link BuildBoardInput.runs}. One `failureReasonsForRuns` answer, passed in
260
+ * rather than merged by the caller so the clipping rule lives here with the
261
+ * rest of the projection and is table-tested with it.
262
+ */
263
+ failures?: Map<string, {
264
+ phase: string;
265
+ error: string;
266
+ }>;
267
+ items: BoardBuilderItem[];
268
+ /** Keyed by trigger id (`owner/repo#N`) — one `latestForTriggers` answer. */
269
+ runs: Map<string, BoardBuilderRun>;
270
+ /** Pending approvals, in any order; indexed by `workflowRunId` here. */
271
+ approvals: BoardBuilderApproval[];
272
+ /** The ordered `autonomy.stages` list. Empty means "not configured". */
273
+ stages: BoardStage[];
274
+ holdLabel: string;
275
+ scope: BoardScope;
276
+ degraded: BoardDegradation[];
277
+ generatedAt?: string;
278
+ ttlSeconds: number;
279
+ }
280
+ export interface BuildBoardOptions {
281
+ /** Populate the `unstaged` bucket. Off by default — it is the long tail. */
282
+ unstaged?: boolean;
283
+ }
284
+ export declare function buildBoard(input: BuildBoardInput, opts?: BuildBoardOptions): BoardResponse;
@@ -0,0 +1,369 @@
1
+ /**
2
+ * The pipeline board — the PURE projection of labels, runs and approvals onto
3
+ * columns.
4
+ *
5
+ * Everything in this module is a function of its arguments. No Hono, no
6
+ * GitHub, no database: the caller (`admin/routes.ts`) resolves the three
7
+ * inputs — cached live items, one `latestForTriggers` map, one
8
+ * `listPending()` — and hands them over. That is what makes the board's rules
9
+ * table-testable, and it is the same split `pr-decisions.ts` makes against
10
+ * `pr-state.ts`.
11
+ *
12
+ * ## Columns come from CONFIG, never from constants
13
+ *
14
+ * The stage vocabulary is operator-owned (`autonomy.stages`,
15
+ * `engine/stage-labels.ts`), so the columns are read from it in the order the
16
+ * operator declared them. A deployment that has configured no stages gets
17
+ * `configured: false` and NO columns — the UI then says so, rather than the
18
+ * server inventing "Intake / Triage / In Progress / Review". Those names come
19
+ * from a mockup; they are examples, not a schema, and a board that shows
20
+ * columns nothing writes to is a board that lies.
21
+ *
22
+ * Each stage contributes its four labels in pipeline order — `enter`,
23
+ * `running`, `on_success`, `on_failure` — which is what turns one configured
24
+ * stage into a legible four-column board rather than a single column. Labels
25
+ * repeated across stages collapse onto their first column: a card carrying the
26
+ * label belongs in one place, and the earlier position is the one the pipeline
27
+ * reaches first.
28
+ *
29
+ * ## The RUN decides a tie; column order is the fallback
30
+ *
31
+ * A card carrying two stage labels is not an error state to refuse; it is the
32
+ * ordinary result of `stage-advance.ts`'s ADD-then-REMOVE ordering failing
33
+ * halfway (its module header explains why that direction is the safe one), or
34
+ * of a re-run leaving an older verdict behind. Either way the card is flagged
35
+ * `ambiguousStage: true` so the UI shows the pair rather than silently picking.
36
+ *
37
+ * WHICH column it lands in is decided by the latest run, when there is one:
38
+ * a `succeeded` run means the `on_success` column and a `failed` one means
39
+ * `on_failure`, because the run is the FACT and the labels are its projection.
40
+ * Column order alone gets this wrong in the case that actually happens — an
41
+ * issue that failed, was re-run, and succeeded carries both terminal labels,
42
+ * and `on_failure` sits right-most, so the board would file a finished build
43
+ * under "blocked" and show a green SUCCEEDED band inside a red column.
44
+ *
45
+ * With no run, or a run still in flight, the right-most matching column wins:
46
+ * the card has PROGRESSED, and later stages are further right.
47
+ *
48
+ * ## Why the SERVER computes `actions`
49
+ *
50
+ * Because the server is the side that knows the hold label, the run lock and
51
+ * the route map. Deriving them in the SPA would mean a second implementation of
52
+ * policy in a place that cannot see any of the three — the #256 class of defect
53
+ * exactly. In this slice the actions are advisory (the client renders them
54
+ * inert), but they are computed honestly so that wiring them up later is a
55
+ * client change, not a second policy.
56
+ */
57
+ /** The universal subject key. Matches `build-decisions.ts`'s `issueTriggerId`. */
58
+ function cardKey(repo, number) {
59
+ return `${repo}#${number}`;
60
+ }
61
+ /**
62
+ * A column heading from a label name: `ready-for-agent` → `Ready for agent`.
63
+ *
64
+ * Derived rather than mapped, because the label is operator-owned — a lookup
65
+ * table would render a renamed stage as a blank or a stale heading, and the
66
+ * label is the only name the operator ever wrote down.
67
+ */
68
+ function titleForLabel(label) {
69
+ const words = label.replace(/[-_]+/g, " ").trim();
70
+ return words ? words.charAt(0).toUpperCase() + words.slice(1) : label;
71
+ }
72
+ /**
73
+ * The ordered column definitions for a set of stages.
74
+ *
75
+ * Four slots per stage in pipeline order, skipping unconfigured labels and
76
+ * collapsing a label two stages share onto its first column.
77
+ */
78
+ function columnsForStages(stages) {
79
+ const slots = ["enter", "running", "on_success", "on_failure"];
80
+ const seen = new Set();
81
+ const out = [];
82
+ for (const stage of stages) {
83
+ for (const slot of slots) {
84
+ const label = stage[slot];
85
+ if (!label || seen.has(label))
86
+ continue;
87
+ seen.add(label);
88
+ out.push({ id: `${stage.id}.${slot}`, title: titleForLabel(label), label });
89
+ }
90
+ }
91
+ return out;
92
+ }
93
+ /**
94
+ * Why a held card is inert, in the wording `holdReply` uses on every other
95
+ * surface — it NAMES the label, because the label is the remedy.
96
+ *
97
+ * Declared once and read by both the card's `heldReason` and every disabled
98
+ * action's `disabledReason`, so the tooltip and the menu item can never
99
+ * disagree about why the same card is inert. The client used to derive this by
100
+ * taking the first action that happened to carry a reason, which is a guess: on
101
+ * a card whose actions are disabled for an unrelated cause (a run already owns
102
+ * it) that guess reads back the wrong sentence entirely.
103
+ *
104
+ * Not imported from `pr-decisions.ts`'s `holdReply`: this module is pure by
105
+ * construction and has no imports at all, and the two sentences address
106
+ * different readers — that one answers a maintainer who asked the bot to act,
107
+ * this one labels a card in a UI.
108
+ */
109
+ function heldReasonFor(holdLabel) {
110
+ return `Held by \`${holdLabel}\` — remove the label to let Last Light act.`;
111
+ }
112
+ /**
113
+ * What the board offers to DO with a card, and why it can't.
114
+ *
115
+ * The order of the branches is the policy. A hold outranks everything, for the
116
+ * same reason it does at the dispatch gate (`build-decisions.ts` branch 1): it
117
+ * is the one instruction that means "you, the bot, are off this subject
118
+ * entirely", and an action that stayed enabled through it would not mean that.
119
+ * Opening the item on GitHub survives a hold because reading is not acting.
120
+ */
121
+ function actionsFor(args) {
122
+ const { held, holdLabel, run, approval, staged, stageLabel, entryLabel, failureLabel } = args;
123
+ const actions = [
124
+ { id: "open", label: "Open on GitHub", kind: "link", enabled: true, disabledReason: null },
125
+ ];
126
+ const holdReason = heldReasonFor(holdLabel);
127
+ const gate = (action) => held ? { ...action, enabled: false, disabledReason: holdReason } : action;
128
+ if (approval) {
129
+ actions.push(gate({ id: "approve", label: "Approve", kind: "approval", enabled: true, disabledReason: null }), gate({ id: "reject", label: "Reject", kind: "approval", enabled: true, disabledReason: null }));
130
+ }
131
+ const live = run ? ["queued", "running", "paused"].includes(run.status) : false;
132
+ if (live) {
133
+ actions.push(gate({ id: "cancel", label: "Cancel run", kind: "run", enabled: true, disabledReason: null }));
134
+ }
135
+ else if (run && run.status === "failed") {
136
+ actions.push(gate({ id: "retry", label: "Retry run", kind: "run", enabled: true, disabledReason: null }));
137
+ }
138
+ // ── UNBLOCK ───────────────────────────────────────────────────────────
139
+ //
140
+ // The affordance for a card that has STOPPED: it carries the stage's
141
+ // `on_failure` label, or its last run failed, and nothing will move it again
142
+ // on its own — the backstop sweep queries the `enter` label, so a parked card
143
+ // is deliberately invisible to it (`issue-discovery.ts`).
144
+ //
145
+ // Distinct from `retry` above, and the distinction is the whole point.
146
+ // `retry` RESUMES the same run: same row, same branch, same workspace, from
147
+ // the phase that failed. This starts AGAIN — it moves the card back to the
148
+ // entry column, which crosses the dispatch gate as the human who pressed it
149
+ // and begins a fresh build. A guardrails block wants this one; a run that
150
+ // died on a flaky step wants the other.
151
+ //
152
+ // It posts the SAME request the drag gesture does, which is why it carries
153
+ // `to` rather than a dedicated endpoint: one path, one gate, one set of
154
+ // refusals. The stale FAILED band clears by itself, because the new run
155
+ // becomes the latest for this trigger.
156
+ const parked = staged &&
157
+ !!entryLabel &&
158
+ stageLabel !== entryLabel &&
159
+ (run?.status === "failed" || (!!failureLabel && stageLabel === failureLabel));
160
+ if (parked) {
161
+ const disabledReason = held ? holdReason : live ? "A run already owns this issue." : null;
162
+ actions.push({
163
+ id: "unblock",
164
+ label: "Unblock & rebuild",
165
+ kind: "stage",
166
+ enabled: !disabledReason,
167
+ disabledReason,
168
+ to: entryLabel,
169
+ });
170
+ }
171
+ // A PREVIOUS run does NOT disable it, and that is load-bearing. The gate
172
+ // treats a human ask as an explicit retry — `resolveBuildTrigger`'s
173
+ // `already-built` branch hard-skips only a BOT re-label, and this surface
174
+ // crosses with `senderIsBot: false` — so disabling on `run` made the board
175
+ // STRICTER than the server it speaks for, refusing something the endpoint
176
+ // would have honoured.
177
+ //
178
+ // That was a trap with no way out. An issue whose build failed on the ENTRY
179
+ // column has no `unblock` (there is nowhere back to move it) and no
180
+ // `dispatch` (a run exists), leaving only `retry`, which resumes the same
181
+ // failed run in its stale workspace. If the blocker was fixed upstream, that
182
+ // is precisely the one thing that cannot help.
183
+ {
184
+ const disabledReason = held
185
+ ? holdReason
186
+ : live
187
+ ? "A run already owns this issue."
188
+ : !staged
189
+ ? "No stage label — apply one to put this issue in the pipeline."
190
+ : null;
191
+ actions.push({
192
+ id: "dispatch",
193
+ // Named for what it does to THIS card: a first build, or another one.
194
+ label: run ? "Rebuild" : "Start build",
195
+ kind: "dispatch",
196
+ enabled: !disabledReason,
197
+ disabledReason,
198
+ });
199
+ }
200
+ return actions;
201
+ }
202
+ /**
203
+ * Project the live items onto the configured columns.
204
+ *
205
+ * Three inputs, no I/O, no exceptions. An item that matches no column is
206
+ * unstaged — an ordinary open issue the pipeline has not been asked about.
207
+ */
208
+ /**
209
+ * Two rendered lines' worth of reason. The same argument `boardExcerpt` makes
210
+ * about bodies: a thrown failure's `error` can be a whole stack trace, and the
211
+ * payload is the budget — so it is clipped HERE, on the server, rather than by
212
+ * a CSS clamp that ships the whole trace to every open tab.
213
+ */
214
+ const FAILURE_REASON_CHARS = 160;
215
+ /** A ledger error, flattened and clipped for a card. */
216
+ function failureReason(error) {
217
+ const flat = error.replace(/\s+/g, " ").trim();
218
+ return flat.length > FAILURE_REASON_CHARS ? `${flat.slice(0, FAILURE_REASON_CHARS - 1)}…` : flat;
219
+ }
220
+ /**
221
+ * `<workflowName>:<phaseName>` → `phaseName`. Ledger rows are namespaced by
222
+ * their workflow; the card already says which workflow it is.
223
+ */
224
+ function phaseOfSkill(workflowName, skill) {
225
+ const prefix = `${workflowName}:`;
226
+ return skill.startsWith(prefix) ? skill.slice(prefix.length) : skill;
227
+ }
228
+ export function buildBoard(input, opts = {}) {
229
+ const generatedAt = input.generatedAt ?? new Date().toISOString();
230
+ const base = {
231
+ generatedAt,
232
+ ttlSeconds: input.ttlSeconds,
233
+ scope: input.scope,
234
+ degraded: input.degraded,
235
+ };
236
+ const defs = columnsForStages(input.stages);
237
+ if (defs.length === 0) {
238
+ // Not configured. No columns at all — see the module header.
239
+ return { ...base, configured: false, columns: [] };
240
+ }
241
+ const approvalsByRun = new Map();
242
+ for (const approval of input.approvals) {
243
+ // Newest wins only if the caller ordered them so; a run has at most one
244
+ // pending gate in practice, so the first entry stands.
245
+ if (!approvalsByRun.has(approval.workflowRunId))
246
+ approvalsByRun.set(approval.workflowRunId, approval);
247
+ }
248
+ const columnIndexByLabel = new Map();
249
+ defs.forEach((def, idx) => columnIndexByLabel.set(def.label, idx));
250
+ const columns = defs.map((def) => ({
251
+ ...def,
252
+ count: 0,
253
+ awaitingHumanCount: 0,
254
+ cards: [],
255
+ }));
256
+ const unstaged = [];
257
+ for (const item of input.items) {
258
+ const names = item.labels.map((l) => l.name);
259
+ const held = names.includes(input.holdLabel);
260
+ const key = cardKey(item.repo, item.number);
261
+ const baseRun = input.runs.get(key) ?? null;
262
+ // The FALLBACK placement: right-most configured stage, on the reading that
263
+ // the card has progressed. A finished run overrides it just below.
264
+ let index = -1;
265
+ let matches = 0;
266
+ const matched = [];
267
+ for (const name of names) {
268
+ const at = columnIndexByLabel.get(name);
269
+ if (at === undefined)
270
+ continue;
271
+ matches++;
272
+ matched.push(at);
273
+ if (at > index)
274
+ index = at;
275
+ }
276
+ // ── THE TIE-BREAK ───────────────────────────────────────────────────────
277
+ //
278
+ // Two stage labels and a finished run: the RUN is the fact, so it picks the
279
+ // column. See the module header — column order alone files a re-run that
280
+ // succeeded under "blocked", because `on_failure` sits right-most.
281
+ if (matches > 1 && baseRun) {
282
+ const wanted = baseRun.status === "succeeded"
283
+ ? ".on_success"
284
+ : baseRun.status === "failed" || baseRun.status === "cancelled"
285
+ ? ".on_failure"
286
+ : null;
287
+ if (wanted) {
288
+ const byRun = matched.find((at) => defs[at].id.endsWith(wanted));
289
+ if (byRun !== undefined)
290
+ index = byRun;
291
+ }
292
+ }
293
+ // Which STAGE this card is filed under, so "back to the start" means that
294
+ // stage's entry column rather than the board's first one.
295
+ const stageId = index >= 0 ? (defs[index].id.split(".")[0] ?? "") : "";
296
+ const stage = stageId ? input.stages.find((candidate) => candidate.id === stageId) ?? null : null;
297
+ // Only a FAILED run owes an explanation, and only the ledger has one.
298
+ const failed = baseRun?.status === "failed" ? input.failures?.get(baseRun.id) : undefined;
299
+ // The phase to SHOW. `currentPhase` is written on completion, so it lags —
300
+ // prefer the ledger's answer: what a live run is running, or what a failed
301
+ // one died in.
302
+ const liveNow = baseRun ? input.inFlight?.get(baseRun.id) : undefined;
303
+ const displayPhase = failed
304
+ ? phaseOfSkill(baseRun.workflowName, failed.phase)
305
+ : liveNow
306
+ ? phaseOfSkill(baseRun.workflowName, liveNow)
307
+ : undefined;
308
+ const run = baseRun
309
+ ? {
310
+ ...baseRun,
311
+ ...(failed
312
+ ? {
313
+ failure: {
314
+ phase: phaseOfSkill(baseRun.workflowName, failed.phase),
315
+ reason: failureReason(failed.error),
316
+ },
317
+ }
318
+ : {}),
319
+ ...(displayPhase && displayPhase !== baseRun.currentPhase ? { phase: displayPhase } : {}),
320
+ }
321
+ : null;
322
+ const approval = run ? approvalsByRun.get(run.id) ?? null : null;
323
+ const staged = index >= 0;
324
+ const card = {
325
+ key,
326
+ repo: item.repo,
327
+ number: item.number,
328
+ title: item.title,
329
+ author: item.author,
330
+ createdAt: item.createdAt,
331
+ url: item.url,
332
+ labels: item.labels,
333
+ ...(item.body ? { body: item.body } : {}),
334
+ ...(item.linkedPrs && item.linkedPrs.length > 0 ? { linkedPrs: item.linkedPrs } : {}),
335
+ stageLabel: staged ? columns[index].label : "",
336
+ ambiguousStage: matches > 1,
337
+ held,
338
+ ...(held ? { heldReason: heldReasonFor(input.holdLabel) } : {}),
339
+ run,
340
+ approval,
341
+ actions: actionsFor({
342
+ held,
343
+ holdLabel: input.holdLabel,
344
+ run,
345
+ approval,
346
+ staged,
347
+ stageLabel: staged ? columns[index].label : "",
348
+ entryLabel: stage?.enter ?? null,
349
+ failureLabel: stage?.on_failure ?? null,
350
+ }),
351
+ };
352
+ if (!staged) {
353
+ unstaged.push(card);
354
+ continue;
355
+ }
356
+ const column = columns[index];
357
+ column.cards.push(card);
358
+ column.count++;
359
+ if (approval)
360
+ column.awaitingHumanCount++;
361
+ }
362
+ return {
363
+ ...base,
364
+ configured: true,
365
+ columns,
366
+ ...(opts.unstaged ? { unstaged: { count: unstaged.length, cards: unstaged } } : {}),
367
+ };
368
+ }
369
+ //# sourceMappingURL=board.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"board.js","sourceRoot":"","sources":["../../src/admin/board.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AA0OH,kFAAkF;AAClF,SAAS,OAAO,CAAC,IAAY,EAAE,MAAc;IAC3C,OAAO,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO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