lastlight-core 0.32.2 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) 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 +301 -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 +264 -0
  9. package/dist/admin/board.js +376 -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 +104 -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 +355 -0
  31. package/dist/engine/build-gate.js.map +1 -0
  32. package/dist/engine/github/github.d.ts +195 -6
  33. package/dist/engine/github/github.js +331 -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 +51 -0
  62. package/dist/state/workflow-run-store.js +98 -0
  63. package/dist/state/workflow-run-store.js.map +1 -1
  64. package/dist/workflows/simple.d.ts +40 -1
  65. package/dist/workflows/simple.js +113 -2
  66. package/dist/workflows/simple.js.map +1 -1
  67. package/package.json +3 -3
  68. package/workflows/cron-autonomy.yaml +24 -0
  69. package/workflows/prompts/pr.md +18 -1
@@ -0,0 +1,355 @@
1
+ /**
2
+ * The BUILD dispatch gate — the IMPURE half of `./build-decisions.ts`.
3
+ *
4
+ * `resolveBuildTrigger` is a pure function over one resolved input record. This
5
+ * module is what stands between it and the world: it RESOLVES those inputs from
6
+ * the config and the state DB, logs the verdict, and applies the one consequence
7
+ * that belongs to the DECISION rather than to the route. Nothing here re-decides
8
+ * anything — every branch of the policy lives in the pure function, and a second
9
+ * copy of any of it here is the exact drift the pure/impure split exists to stop.
10
+ *
11
+ * It is the issue-side mirror of `applyPrDispatchGate` (`./dispatcher.ts`), and
12
+ * the header there states the rule this one also follows: a consequence that
13
+ * belongs to the decision is applied HERE, so no caller can forget it. On this
14
+ * path that consequence is the stage-label advance, which is not decoration —
15
+ * it is **guard 2** of the four-guard loop-safety argument
16
+ * (`./build-decisions.ts`, `./stage-advance.ts`).
17
+ *
18
+ * **Why its own module rather than `dispatcher.ts`.** The PR gate lives there
19
+ * because the dispatcher is where the webhook route decides for itself. Nothing
20
+ * on the issue side needs that: the gate has exactly one caller today
21
+ * (`dispatchWorkflow`) and the two Phase 4 surfaces — the backstop sweep and
22
+ * `/api/run` — reach the same choke point. Keeping it out of a 1,000-line module
23
+ * keeps the footprint of this feature small enough to read in one sitting.
24
+ */
25
+ import { getAutonomyConfig, getHoldLabel, isAutonomousRepo } from "../config/config.js";
26
+ import { issueTriggerId, resolveBuildTrigger } from "./build-decisions.js";
27
+ import { advanceStage } from "./stage-advance.js";
28
+ import { recordActivity } from "../activity.js";
29
+ import { logger } from "../logging/logger.js";
30
+ const log = logger("build-gate");
31
+ export async function applyBuildDispatchGate(args, deps) {
32
+ // ── 1. THE STAGE ─────────────────────────────────────────────────────────
33
+ //
34
+ // The stage is what names the workflow, the labels and the gates, so an
35
+ // unknown one leaves the gate with nothing to enforce. Fail CLOSED: a stage
36
+ // dispatch we cannot identify must not run un-gated, because everything below
37
+ // — the idempotency key, the hold, the label advance — is keyed on names only
38
+ // the stage carries. An operator who renamed a stage gets no build and one
39
+ // warning, rather than an ungoverned one.
40
+ const stage = getAutonomyConfig().stages[args.stage];
41
+ if (!stage) {
42
+ const reason = `unknown-stage: \`${args.stage}\` is not in \`autonomy.stages\`, so there is no workflow, no labels and no gates to run behind`;
43
+ log.warn("Build gate refused an unknown stage", {
44
+ repo: args.repo,
45
+ issueNumber: args.issueNumber,
46
+ stage: args.stage,
47
+ reason,
48
+ });
49
+ return { decision: "skip", reason };
50
+ }
51
+ // ── 2. THE INPUTS ────────────────────────────────────────────────────────
52
+ //
53
+ // Resolved once, here, so the pure function reads a single consistent record
54
+ // — the same rule `resolvePrState` follows for the PR side.
55
+ const triggerId = issueTriggerId(args.repo, args.issueNumber);
56
+ const budget = getAutonomyConfig().budget;
57
+ const [owner, name] = args.repo.split("/");
58
+ // Every day-scoped budget input is measured from the same instant, resolved
59
+ // ONCE here. Two reads that each called "start of today" separately could
60
+ // straddle midnight and answer about different days.
61
+ const sinceIso = startOfUtcDayIso();
62
+ const [alreadyBuilt, inFlight, activeRuns, buildsForRepoToday, dailyStats, repoSpend] = await Promise.all([
63
+ // GUARD 3 — the real lock. A fact in our own database, in ANY status, that
64
+ // no GitHub outage can move.
65
+ deps.db.runs.hasRunForTrigger(triggerId, stage.workflow),
66
+ // `activeForTrigger`, not `getByTrigger`: both mean "queued | running |
67
+ // paused for this trigger", but `getByTrigger` answers for ANY workflow, so
68
+ // a live issue-triage run on the same issue would read as a build in
69
+ // flight. The constraint being protected is two agents in one build
70
+ // workspace, which is scoped to the stage's own workflow — and it is what
71
+ // the decision's `run-in-flight:` reason claims in prose.
72
+ deps.db.runs.activeForTrigger([stage.workflow], triggerId),
73
+ // The concurrency input. `listActive()` + a filter, NOT `countRunning()`:
74
+ // that one counts every running workflow in the harness — a PR review, a
75
+ // triage, a cron fan-out — so the autonomy pipeline's own ceiling would be
76
+ // consumed by work it has nothing to do with, and a busy deployment would
77
+ // refuse every autonomous build while running none.
78
+ deps.db.runs.listActive(),
79
+ // Guard 4's counter. Runs STARTED for this repo today, in any status.
80
+ deps.db.runs.countRunsForRepoSince(stage.workflow, args.repo, sinceIso),
81
+ // `dailyStats(1)` is the inclusive window [today, today] — one bucket, and
82
+ // it is synthesised as a zero row when nothing has run, so the array is
83
+ // never empty. Read defensively anyway: a spend input that read `undefined`
84
+ // as "over budget" would refuse every build on a quiet morning.
85
+ deps.db.executions.dailyStats(1),
86
+ deps.db.executions.repoCostSince(owner ?? "", name ?? "", sinceIso),
87
+ ]);
88
+ const concurrentAutonomousBuilds = activeRuns.filter((run) => run.workflowName === stage.workflow && isAutonomousRun(run)).length;
89
+ const spendTodayUsd = dailyStats[dailyStats.length - 1]?.costUsd ?? 0;
90
+ const decision = resolveBuildTrigger({
91
+ repo: args.repo,
92
+ issueNumber: args.issueNumber,
93
+ labels: args.labels,
94
+ addedLabel: args.addedLabel,
95
+ route: args.route,
96
+ senderIsBot: args.senderIsBot,
97
+ autonomyEnabled: isAutonomousRepo(args.repo),
98
+ alreadyBuilt,
99
+ runInFlight: !!inFlight,
100
+ holdLabel: getHoldLabel(),
101
+ concurrentAutonomousBuilds,
102
+ buildsForRepoToday,
103
+ spendTodayUsd,
104
+ repoSpendTodayUsd: repoSpend.costUsd,
105
+ }, budget);
106
+ // ── 3. THE LOG ───────────────────────────────────────────────────────────
107
+ //
108
+ // One line per dispatch, in the same shape `applyPrDispatchGate` logs: the
109
+ // decision AND the reason that produced it, because the reason is the single
110
+ // source the comment and the admin panel also render.
111
+ log.info("Build gate decision", {
112
+ workflow: stage.workflow,
113
+ repo: args.repo,
114
+ issueNumber: args.issueNumber,
115
+ decision: decision.decision,
116
+ reason: decision.reason,
117
+ });
118
+ if (decision.decision === "skip") {
119
+ await applySkipConsequence(args, stage, decision, deps);
120
+ return { decision: "skip", reason: decision.reason };
121
+ }
122
+ // ── 4. GUARD 2 — advance the label BEFORE the run starts ─────────────────
123
+ //
124
+ // Load-bearing, and the ORDERING is the whole point. The Phase 4 backstop
125
+ // sweep queries `label:<enter>`; while the entry label is still on the issue,
126
+ // every sweep tick and every re-delivered webhook sees a pipeline entry it is
127
+ // entitled to pick up. Moving the label off here — before the run exists —
128
+ // makes a re-dispatch structurally impossible rather than merely caught.
129
+ //
130
+ // A FAILED advance must not block the dispatch. `advanceStage` never throws
131
+ // for exactly this reason: the labels are the human-readable projection of
132
+ // the fact, and guard 3 (`hasRunForTrigger`) is the fact. So the cost of a
133
+ // failure here is visibility, not a double build — but it IS guard 2 silently
134
+ // degrading, so it gets a warning rather than passing unremarked.
135
+ const advance = await advanceStage({
136
+ owner: owner ?? "",
137
+ repo: name ?? "",
138
+ issueNumber: args.issueNumber,
139
+ from: stage.enter,
140
+ to: stage.running,
141
+ // A run is STARTING, so neither terminal verdict holds any more. Nothing
142
+ // else ever clears them: this advance removes `enter`, and the terminal
143
+ // observer removes `running` — so without this an issue that failed and
144
+ // was then re-run successfully keeps `agent-blocked` alongside its new
145
+ // `ready-for-human`, and the board files it under the older verdict.
146
+ // Best-effort by contract; a stale label is untidy, never unsafe.
147
+ alsoRemove: [stage.on_success, stage.on_failure],
148
+ }, { github: deps.github });
149
+ if (!advance.advanced || !advance.removed) {
150
+ log.warn("Stage label advance degraded — the sweep's re-pickup guard is weaker for this issue", {
151
+ workflow: stage.workflow,
152
+ repo: args.repo,
153
+ issueNumber: args.issueNumber,
154
+ from: stage.enter,
155
+ to: stage.running,
156
+ advanced: advance.advanced,
157
+ removed: advance.removed,
158
+ reason: advance.reason,
159
+ });
160
+ }
161
+ // The stage's gates travel back to the caller rather than being applied here:
162
+ // they belong to the RUN, which does not exist yet. The union happens where
163
+ // the run's effective approval map is composed (`workflows/simple.ts`).
164
+ return { decision: "dispatch", reason: decision.reason, gates: stage.gates };
165
+ }
166
+ /**
167
+ * Midnight UTC today, as an ISO string — the boundary every day-scoped budget
168
+ * is measured from.
169
+ *
170
+ * UTC rather than a deployment-local day because that is what the ledger
171
+ * already buckets on (`dayBucket()` slices the first ten characters of the
172
+ * stored ISO timestamp), so a local-midnight boundary here would disagree with
173
+ * the numbers on the dashboard's own stats page. Every reason string that names
174
+ * this ceiling says "midnight UTC" out loud for the same reason.
175
+ */
176
+ function startOfUtcDayIso(now = new Date()) {
177
+ return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())).toISOString();
178
+ }
179
+ /**
180
+ * Was this run dispatched by the autonomy pipeline?
181
+ *
182
+ * The flag is stamped on the run's `context` at dispatch. `context` is a JSON
183
+ * column typed `Record<string, unknown>` — anything at all may be in it, and on
184
+ * an old row nothing is — so this is a defensive read with an explicit `=== true`
185
+ * rather than a truthiness test: the question is "did the pipeline stamp this",
186
+ * and a run carrying the string `"false"` is not an answer of yes.
187
+ */
188
+ function isAutonomousRun(run) {
189
+ const ctx = run.context;
190
+ if (!ctx || typeof ctx !== "object")
191
+ return false;
192
+ return ctx._autonomous === true;
193
+ }
194
+ /**
195
+ * The greppable case name out of a `"<case>: <explanation>"` reason.
196
+ *
197
+ * Reading the CASE off the reason is blessed by `build-decisions.ts`'s own
198
+ * module header — the grammar exists precisely so the case stays greppable
199
+ * without a parallel enum to keep in sync. Reading the PROSE would not be: the
200
+ * one skip with a durable consequence keys on the typed `budgetExhausted`
201
+ * field, never on this.
202
+ */
203
+ function caseOf(reason) {
204
+ const colon = reason.indexOf(":");
205
+ return colon > 0 ? reason.slice(0, colon) : reason;
206
+ }
207
+ /**
208
+ * What a skip costs — recorded, never silent, but PROPORTIONATE.
209
+ *
210
+ * `pr-escalation.ts` states the doctrine this follows: a skip that is terminal
211
+ * for the problem owes a human an explanation on the subject itself, and a skip
212
+ * that is merely "come back later" owes them nothing but a log line. Applying
213
+ * the loud treatment to a transient skip is not a harmless excess — a cron that
214
+ * re-ticks every twenty minutes would comment every twenty minutes, which is
215
+ * the #256 failure shape (a notice with no de-duplication) rebuilt on a new
216
+ * subject.
217
+ *
218
+ * So, three tiers:
219
+ *
220
+ * | case | log | activity row | comment |
221
+ * |-------------------------|------|--------------|---------|
222
+ * | `concurrency-exhausted` | info | no | no |
223
+ * | `repo-quota-exhausted` | warn | yes | no |
224
+ * | `budget-exhausted` | warn | yes | once |
225
+ *
226
+ * `concurrency-exhausted` clears itself in minutes and fires on every sweep
227
+ * tick while it holds, so a row per tick would be noise in the one stream whose
228
+ * value is that a human can read it. The day quota is worth a row — it is a
229
+ * ceiling somebody configured and may want to raise — but not a comment: the
230
+ * issue is still going to be built, just not today. Only the spend ceiling is
231
+ * terminal for the day in a way the issue itself should carry.
232
+ *
233
+ * Every skip NOT in that table (`on-hold`, `not-autonomous`, `already-built`,
234
+ * `run-in-flight`) is silent here by design, as it was in Phase 1.
235
+ *
236
+ * Never throws: `recordActivity` swallows its own failures, and the GitHub half
237
+ * is best-effort. A refusal that failed to be recorded is still a refusal.
238
+ */
239
+ async function applySkipConsequence(args, stage, decision, deps) {
240
+ const skipCase = caseOf(decision.reason);
241
+ if (skipCase !== "repo-quota-exhausted" && skipCase !== "budget-exhausted")
242
+ return;
243
+ const triggerId = issueTriggerId(args.repo, args.issueNumber);
244
+ // A ceiling somebody configured has been hit. `warn`, not `info`: this is the
245
+ // level an operator filters for when asking "is the pipeline stuck, or just
246
+ // quiet?", and both cases are answers to that question.
247
+ log.warn("Build gate refused a dispatch on a budget ceiling", {
248
+ workflow: stage.workflow,
249
+ repo: args.repo,
250
+ issueNumber: args.issueNumber,
251
+ case: skipCase,
252
+ reason: decision.reason,
253
+ });
254
+ await recordActivity(deps.db, {
255
+ action: "autonomy.skip",
256
+ // Nobody asked for this — the pipeline refused itself.
257
+ actorType: "system",
258
+ targetType: "issue",
259
+ targetId: triggerId,
260
+ // `denied`, not `ok`: the row records an action that did NOT happen, which
261
+ // is the same reading `pr.retry` gives a gate-refused retry.
262
+ outcome: "denied",
263
+ detail: { case: skipCase, workflow: stage.workflow, reason: decision.reason },
264
+ });
265
+ // The typed field, not the case name, is what gates the comment — and it is
266
+ // set on exactly one branch.
267
+ const exhausted = decision.budgetExhausted;
268
+ if (!exhausted)
269
+ return;
270
+ const github = deps.github;
271
+ const [owner, name] = args.repo.split("/");
272
+ if (!github || !owner || !name)
273
+ return;
274
+ // ── The de-duplication, keyed on a DURABLE FACT ──────────────────────────
275
+ //
276
+ // The label's absence is the key, exactly as `noticeForkPr` keys on its
277
+ // persisted record rather than on scanning comments for its own prose. This
278
+ // is the only thing standing between "one comment" and "one comment every
279
+ // twenty minutes for the rest of the day": the budget does not clear until
280
+ // midnight, so every sweep tick between now and then reaches this same
281
+ // branch. A body-text marker would not do — it costs an API scan per tick and
282
+ // breaks the moment the wording changes — and neither would a timestamp,
283
+ // which we would have nowhere to put.
284
+ //
285
+ // `args.labels` is the issue's CURRENT label set, the same snapshot the hold
286
+ // check read.
287
+ if (args.labels.includes(stage.on_failure))
288
+ return;
289
+ // Label FIRST, comment second — the crash-window argument `noticeForkPr`
290
+ // makes about its record. Crash between the two and the issue carries the
291
+ // blocked label with no explanation: wrong, but bounded and recoverable by a
292
+ // human taking the label off. Crash the other way round and the issue carries
293
+ // a comment with no label, so the dedup key was never written and every tick
294
+ // until midnight comments again. Between one missing sentence and an
295
+ // unbounded comment loop, the durable write goes first.
296
+ //
297
+ // Note this is `advanceStage` with a `to` and NO `from`: it ADDS the blocked
298
+ // label and removes nothing. The entry label must stay exactly where it is —
299
+ // the build has not run, so the issue has not left the queue, and the sweep
300
+ // re-picking it tomorrow is the intended behaviour. Advancing to `running`
301
+ // here would be the opposite of the truth.
302
+ const advance = await advanceStage({ owner, repo: name, issueNumber: args.issueNumber, to: stage.on_failure }, { github });
303
+ if (!advance.added) {
304
+ // No durable key was written, so a comment now would repeat on the next
305
+ // tick. Say nothing; the activity row above is still the record.
306
+ log.warn("Could not label a budget-exhausted issue — saying nothing, since a comment with no label would repeat every tick", {
307
+ repo: args.repo,
308
+ issueNumber: args.issueNumber,
309
+ label: stage.on_failure,
310
+ reason: advance.reason,
311
+ });
312
+ return;
313
+ }
314
+ try {
315
+ await github.postComment(owner, name, args.issueNumber, renderBudgetExhaustedComment({
316
+ scope: exhausted.scope,
317
+ limitUsd: exhausted.limitUsd,
318
+ spentUsd: exhausted.spentUsd,
319
+ repo: args.repo,
320
+ blockedLabel: stage.on_failure,
321
+ }));
322
+ }
323
+ catch (err) {
324
+ log.warn("Budget-exhausted comment failed", {
325
+ repo: args.repo,
326
+ issueNumber: args.issueNumber,
327
+ err,
328
+ });
329
+ }
330
+ }
331
+ /**
332
+ * The budget-exhausted comment. Pure, so its wording is table-testable — the
333
+ * same split `renderEscalationComment` makes.
334
+ *
335
+ * Three things it has to say, and nothing else. **Which ceiling**, with the
336
+ * configured number, because "I am out of budget" is unactionable and "I have
337
+ * spent $10.40 of this repo's $10.00" tells somebody exactly what to change.
338
+ * **When it resets**, because the default assumption is that a blocked bot
339
+ * stays blocked. And **both exits**, because this comment is the only place
340
+ * most people will ever learn there are any — the `pr-escalation.ts` rule that
341
+ * every exit which works must be named, and every exit named must work.
342
+ *
343
+ * Short on purpose: it is an interruption on somebody's issue, not a report.
344
+ */
345
+ export function renderBudgetExhaustedComment(args) {
346
+ const ceiling = args.scope === "harness"
347
+ ? `my daily model budget across every repository ($${args.limitUsd.toFixed(2)})`
348
+ : `the daily model budget for \`${args.repo}\` ($${args.limitUsd.toFixed(2)})`;
349
+ return (`I'm not starting a build here: I've hit ${ceiling}, having spent ` +
350
+ `$${args.spentUsd.toFixed(2)} so far today. It resets at midnight UTC.\n\n` +
351
+ `Two ways on from here: remove the \`${args.blockedLabel}\` label to re-arm me — ` +
352
+ `I'll pick this up again once the budget has reset — or ask whoever runs this ` +
353
+ `deployment to raise the limit.`);
354
+ }
355
+ //# sourceMappingURL=build-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-gate.js","sourceRoot":"","sources":["../../src/engine/build-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAExF,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAO9C,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAmCjC,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,IAAmB,EACnB,IAAmB;IAEnB,4EAA4E;IAC5E,EAAE;IACF,wE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CAAC;AACJ,CAAC"}
@@ -145,6 +145,63 @@ export interface RepoActivityItem {
145
145
  labels: string[];
146
146
  htmlUrl: string;
147
147
  }
148
+ /**
149
+ * One open issue or pull request as the BOARD reads it (`src/admin/board.ts`).
150
+ *
151
+ * Deliberately not {@link RepoActivityItem}: the board is a projection of
152
+ * LABELS onto columns, so it needs each label's `color` and `description` (a
153
+ * chip has to render) where the digest needed only names, and it needs nothing
154
+ * about closure or merges because every item it sees is open.
155
+ */
156
+ export interface BoardItem {
157
+ /** Qualified `owner/repo` — the board spans repos, so the bare name is ambiguous. */
158
+ repo: string;
159
+ number: number;
160
+ /** True when this item is a pull request rather than an issue. */
161
+ isPr: boolean;
162
+ title: string;
163
+ url: string;
164
+ author: string;
165
+ createdAt: string;
166
+ updatedAt: string;
167
+ draft: boolean;
168
+ labels: Array<{
169
+ name: string;
170
+ color: string;
171
+ description?: string;
172
+ }>;
173
+ /**
174
+ * GitHub's `bodyText` — the markdown already flattened to prose, so an
175
+ * excerpt reads as a sentence rather than a slice of `<details>` scaffolding.
176
+ * Same field {@link DigestItemDetail} uses, for the same reason.
177
+ *
178
+ * TRUNCATED HERE, not by the reader. A board spans twenty repos at fifty
179
+ * items each, and a handful of essay-length issue bodies would dominate a
180
+ * payload whose whole design is a small response served from cache. The card
181
+ * shows two lines; 280 characters is comfortably more than that.
182
+ */
183
+ body: string;
184
+ }
185
+ /**
186
+ * One repo's slice of a {@link GitHubClient.listOpenBoardItems} answer.
187
+ *
188
+ * A failed repo is a VALUE here, never a throw: the board renders twenty repos
189
+ * and one of them 404ing (or the App losing its installation on that owner)
190
+ * must degrade that column's contents, not the request. The caller reports
191
+ * `error` as a `degraded` entry and keeps serving the rest.
192
+ *
193
+ * `fallback` says the items came from the REST path rather than the GraphQL
194
+ * search — fewer fields (a label has no colour there) and a bounded window —
195
+ * so the caller marks the repo degraded even though it has data.
196
+ * `throttled` says GitHub refused for rate-limit reasons, which is the signal
197
+ * the board cache backs off on.
198
+ */
199
+ export interface BoardRepoItems {
200
+ items: BoardItem[];
201
+ error?: string;
202
+ fallback?: boolean;
203
+ throttled?: boolean;
204
+ }
148
205
  /**
149
206
  * One issue or pull request with its text — the unit
150
207
  * {@link GitHubClient.listRepoDigestDetail} lists.
@@ -231,6 +288,17 @@ export interface ChecksQueryOptions {
231
288
  */
232
289
  excludeApp?: string;
233
290
  }
291
+ /**
292
+ * One item's body, flattened and clipped to {@link BOARD_EXCERPT_CHARS}.
293
+ *
294
+ * Clipped on the SERVER rather than by the card, because the cost being
295
+ * controlled is the payload: twenty repos x fifty items x an essay-length issue
296
+ * body is a response whose whole design is "small enough to serve from cache
297
+ * every twenty seconds". Whitespace is collapsed first so the clip lands on
298
+ * prose rather than in the middle of a blank line, and a clipped string gets an
299
+ * ellipsis so the card never has to guess whether it is seeing all of it.
300
+ */
301
+ export declare function boardExcerpt(bodyText: string | null | undefined): string;
234
302
  /**
235
303
  * Raised when a harness-side call targets an account the GitHub App is not
236
304
  * installed on. Distinct from a 404 so callers can say the actionable thing
@@ -301,13 +369,17 @@ export declare class GitHubClient {
301
369
  /**
302
370
  * Add labels to an issue/PR, leaving existing labels alone.
303
371
  *
304
- * The only harness-side label WRITE. Every other label mutation in the system
305
- * happens INSIDE the sandbox, through agentic-pi's `github_*` tools driven
306
- * from a prompt — which is the right place for a label whose value is an
307
- * agent's judgement (`dependency-trivial`, the triage vocabulary). This one
308
- * is different in kind: the dispatch-time escalation
372
+ * One of exactly TWO harness-side label WRITEs — {@link removeLabel} is the
373
+ * other, and it arrived with the software-factory stage pipeline. Every other
374
+ * label mutation in the system happens INSIDE the sandbox, through
375
+ * agentic-pi's `github_*` tools driven from a prompt — which is the right
376
+ * place for a label whose value is an agent's judgement
377
+ * (`dependency-trivial`, the triage vocabulary). These two are different in
378
+ * kind, and different for the same reason: both fire at a moment when there
379
+ * is no sandbox and no agent to ask. The dispatch-time escalation
309
380
  * (`../pr-escalation.ts`) fires precisely when we have decided NOT to
310
- * provision a sandbox, so there is no agent to ask.
381
+ * provision a sandbox; the stage advance (`../stage-advance.ts`) fires at the
382
+ * dispatch choke point itself, BEFORE one has been provisioned.
311
383
  *
312
384
  * GitHub's own endpoint creates a label that does not exist yet (with an
313
385
  * arbitrary colour), so there is no `ensureLabels` companion to write.
@@ -316,6 +388,32 @@ export declare class GitHubClient {
316
388
  * `../pr-escalation.ts` for the record that does.
317
389
  */
318
390
  addLabels(owner: string, repo: string, issueNumber: number, labels: string[]): Promise<void>;
391
+ /**
392
+ * Remove ONE label from an issue/PR, leaving every other label alone.
393
+ *
394
+ * The second of the two harness-side label writes (see {@link addLabels}),
395
+ * and the load-bearing half of the software-factory stage pipeline: the
396
+ * stage label IS the source of truth for where an issue has got to, and the
397
+ * ENTRY label (`ready-for-agent`) must come off BEFORE the run it triggered
398
+ * starts. That ordering is not cosmetic. The backstop cron sweep finds work
399
+ * by querying `label:ready-for-agent`; if the label is still there while the
400
+ * run is in flight, the sweep is structurally able to re-pick an issue that
401
+ * was already dispatched, and re-pick it again on the next tick. This repo
402
+ * has a recorded production incident of exactly that shape — a cron gated on
403
+ * a signal the work never wrote, every run reporting `succeeded` while it
404
+ * burned roughly $1.30/hour. Removing the entry label at dispatch is what
405
+ * makes the re-pick impossible rather than merely unlikely.
406
+ *
407
+ * **A missing label is a 404, and a 404 here is success.** GitHub answers
408
+ * `404` when the label is not on the issue (and also when the label does not
409
+ * exist in the repo at all). Either way the desired end state — "this label
410
+ * is not on this issue" — already holds, so removing an absent label is a
411
+ * no-op and we swallow that ONE status. Everything else (403 from a
412
+ * downscoped token, 5xx, a network failure) propagates: a blanket catch here
413
+ * would turn "we could not take the entry label off" into silence, which is
414
+ * precisely the re-dispatch loop above.
415
+ */
416
+ removeLabel(owner: string, repo: string, issueNumber: number, label: string): Promise<void>;
319
417
  /**
320
418
  * List every repository ONE installation can access, as `owner/repo` full
321
419
  * names. Paginated — handles installs with hundreds of repos.
@@ -1525,6 +1623,97 @@ export declare class GitHubClient {
1525
1623
  headSha: string;
1526
1624
  createdAt: string;
1527
1625
  }>>;
1626
+ /**
1627
+ * The repo's OPEN ISSUES carrying `label`, as light records (number / title /
1628
+ * labels / created-at).
1629
+ *
1630
+ * The autonomy backstop sweep's one GitHub read (`cron/issue-discovery.ts`):
1631
+ * it asks GitHub to do the filtering — `state: "open"` + `labels:` are both
1632
+ * server-side — so a repo with thousands of issues costs one page, not a walk.
1633
+ * `labels` rides the same response, which is what lets the discoverer exclude
1634
+ * a partially-advanced issue (one carrying the stage's `running` label as well
1635
+ * as its `enter` label) without a second call, and what lets the dispatch gate
1636
+ * read the hold label off the candidate it was handed.
1637
+ *
1638
+ * **A PULL REQUEST IS NEVER RETURNED.** `GET /repos/{o}/{r}/issues` returns
1639
+ * pull requests alongside issues — a PR *is* an issue to this API, and it
1640
+ * carries the same labels — so an unfiltered response would offer PRs to a
1641
+ * pipeline that dispatches `build` runs against an ISSUE number. That would
1642
+ * not fail loudly; it would clone the repo and set an agent to work on a
1643
+ * "feature request" that is somebody's open pull request. `item.pull_request`
1644
+ * is present on exactly those items and absent on real issues, so it is the
1645
+ * discriminator (the same one `listRepoActivitySince` uses to set `isPr`).
1646
+ *
1647
+ * Page-bounded to `maxPages` (3 × 100 = 300 items) for the same reason
1648
+ * `listRepoActivitySince` is: an unbounded paginate here runs per repo on
1649
+ * every tick, which is a rate-limit hazard, and a repo with 300 open issues
1650
+ * sitting at one stage label has a queue problem rather than a paging one.
1651
+ * Oldest first, so the caller's per-repo cap is stable across ticks rather
1652
+ * than starving the same tail.
1653
+ */
1654
+ listOpenIssuesByLabel(owner: string, repo: string, label: string, opts?: {
1655
+ maxPages?: number;
1656
+ }): Promise<Array<{
1657
+ number: number;
1658
+ title: string;
1659
+ labels: string[];
1660
+ createdAt: string;
1661
+ }>>;
1662
+ /**
1663
+ * Every OPEN issue and pull request across `repos`, for the board.
1664
+ *
1665
+ * ## The rate-limit budget is what decides this method's shape
1666
+ *
1667
+ * The obvious implementation — `issues.listForRepo` per repo, per poll — does
1668
+ * not survive contact with the numbers. A dashboard polling at 15 s over 20
1669
+ * repos is ~4,800 requests an hour, and each open tab multiplies it; the
1670
+ * installation's 5,000/hr budget is the SAME budget the harness spends
1671
+ * reviewing pull requests and fixing CI, so a board left open would starve the
1672
+ * work it exists to display. That version must not ship.
1673
+ *
1674
+ * So: ONE GraphQL document per batch of up to ten repos, each an aliased
1675
+ * `search(type: ISSUE, query: "repo:o/r is:open")` block. That is the idiom
1676
+ * {@link listRepoDigestDetail} already uses for its three aliased searches —
1677
+ * aliases ride one request and one rate-limit point between them. Twenty
1678
+ * repos therefore cost TWO requests per refresh, and with the board cache's
1679
+ * 120 s TTL in front (`src/admin/board-cache.ts`) the steady state is ~60
1680
+ * requests an hour **regardless of how many dashboards are open**.
1681
+ *
1682
+ * ## Batched by OWNER, because the token is
1683
+ *
1684
+ * {@link kit} resolves a per-OWNER installation and each installation mints
1685
+ * its own token, so a single document can only span repos of one account.
1686
+ * The caller groups by owner; this method takes the owner explicitly and
1687
+ * treats `repos` as bare names under it.
1688
+ *
1689
+ * ## `search` is subject to SECONDARY limits, which the point budget does not
1690
+ * describe
1691
+ *
1692
+ * GitHub throttles search independently of the documented points, with no
1693
+ * warning in the response headers. A throttle therefore falls back to
1694
+ * {@link listRepoActivitySince} (`maxPages: 1`) per repo and marks the result
1695
+ * `fallback` + `throttled`: the board degrades to a bounded, slightly
1696
+ * lossy view of the repo rather than showing an empty column, and the cache
1697
+ * reads `throttled` as its cue to back off that owner.
1698
+ *
1699
+ * Keyed by the QUALIFIED `owner/repo` so the caller can index one map across
1700
+ * every owner it asked about.
1701
+ */
1702
+ listOpenBoardItems(owner: string, repos: string[], opts?: {
1703
+ first?: number;
1704
+ batchSize?: number;
1705
+ }): Promise<Map<string, BoardRepoItems>>;
1706
+ /** The aliased-search half of {@link listOpenBoardItems}. One request. */
1707
+ private searchOpenBoardItems;
1708
+ /**
1709
+ * The REST fallback for ONE repo when search is throttled.
1710
+ *
1711
+ * Bounded to a single page and to items still open. It is lossy on purpose:
1712
+ * `listRepoActivitySince` filters on `updated_at`, so an open issue nobody has
1713
+ * touched in the window is missing, and its labels carry no colour. A board
1714
+ * that says so (`degraded`) beats a board that shows an empty column.
1715
+ */
1716
+ private restBoardFallback;
1528
1717
  /**
1529
1718
  * What happened in a repo between `sinceIso` and now — issues AND pull
1530
1719
  * requests, opened / closed / merged.