lastlight-core 0.23.4 → 0.23.6

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 (46) hide show
  1. package/config/default.yaml +16 -0
  2. package/dist/admin/routes.d.ts +29 -0
  3. package/dist/admin/routes.js +136 -0
  4. package/dist/admin/routes.js.map +1 -1
  5. package/dist/config/config.d.ts +23 -0
  6. package/dist/config/config.js +25 -0
  7. package/dist/config/config.js.map +1 -1
  8. package/dist/cron/dependabot-discovery.d.ts +43 -4
  9. package/dist/cron/dependabot-discovery.js +47 -7
  10. package/dist/cron/dependabot-discovery.js.map +1 -1
  11. package/dist/engine/dispatcher.d.ts +5 -1
  12. package/dist/engine/dispatcher.js +88 -8
  13. package/dist/engine/dispatcher.js.map +1 -1
  14. package/dist/engine/fix-markers.d.ts +27 -0
  15. package/dist/engine/fix-markers.js +31 -0
  16. package/dist/engine/fix-markers.js.map +1 -1
  17. package/dist/engine/github/github.d.ts +1 -1
  18. package/dist/engine/github/github.js +1 -1
  19. package/dist/engine/pr-decisions.d.ts +71 -8
  20. package/dist/engine/pr-decisions.js +121 -24
  21. package/dist/engine/pr-decisions.js.map +1 -1
  22. package/dist/engine/pr-escalation.d.ts +112 -18
  23. package/dist/engine/pr-escalation.js +204 -31
  24. package/dist/engine/pr-escalation.js.map +1 -1
  25. package/dist/engine/pr-state.d.ts +152 -15
  26. package/dist/engine/pr-state.js +351 -94
  27. package/dist/engine/pr-state.js.map +1 -1
  28. package/dist/engine/router.js +116 -4
  29. package/dist/engine/router.js.map +1 -1
  30. package/dist/index.js +12 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/sandbox/index.js +41 -1
  33. package/dist/sandbox/index.js.map +1 -1
  34. package/dist/sandbox/k8s/init-clone.d.ts +7 -4
  35. package/dist/sandbox/k8s/init-clone.js +35 -5
  36. package/dist/sandbox/k8s/init-clone.js.map +1 -1
  37. package/dist/workflows/simple.d.ts +24 -1
  38. package/dist/workflows/simple.js +39 -7
  39. package/dist/workflows/simple.js.map +1 -1
  40. package/package.json +3 -3
  41. package/skills/fixing/SKILL.md +83 -11
  42. package/workflows/dependabot-ci-fix.yaml +47 -0
  43. package/workflows/pr-fix.yaml +13 -0
  44. package/workflows/prompts/dependabot-ci-fix.md +40 -19
  45. package/workflows/prompts/dependabot-pr-merge.md +16 -9
  46. package/workflows/prompts/pr-fix.md +15 -6
@@ -26,6 +26,60 @@ import { type DiagnosisClass } from "./fix-markers.js";
26
26
  import { type PrNote } from "./pr-notes.js";
27
27
  /** Aggregate check state for a ref, as {@link GitHubClient.getChecksConclusion} reports it. */
28
28
  export type ChecksState = "passing" | "failing" | "pending" | "none";
29
+ /**
30
+ * How a retry arrived. Three surfaces, ONE record (03-retry-intervention.md).
31
+ *
32
+ * - `comment` — `@<bot> retry [reason]`, already maintainer-gated by the
33
+ * `author_association` check that governs the whole `@`-mention path.
34
+ * - `label` — a human took `requires-human` off. Maintainer-gated for free:
35
+ * GitHub requires triage permission to change a label.
36
+ * - `api` — the admin endpoint behind `lastlight pr retry`, gated by the
37
+ * authenticated admin session.
38
+ */
39
+ export type InterventionVia = "comment" | "label" | "api";
40
+ /**
41
+ * The last time a human told us to try again — the one thing that makes an
42
+ * escalated problem dispatchable without a new commit.
43
+ *
44
+ * `by` and `note` are recorded for DISPLAY and for the journal. **No decision
45
+ * function reads either** — the same rule {@link PrNote} lives under. Capability
46
+ * is checked at the surface (`author_association`, GitHub's own label
47
+ * permissions, or the admin session); identity is never a decision input
48
+ * (locked decision 5). There is no precedence between two maintainers either:
49
+ * last one wins (locked decision 6), which is what one nullable field with a
50
+ * timestamp gives for free.
51
+ */
52
+ export interface PrIntervention {
53
+ at: string;
54
+ /** The head SHA the retry was asked for — the retry's own idempotency key. */
55
+ atSha: string;
56
+ /** How it arrived: a comment, a label removal, or the admin API. */
57
+ via: InterventionVia;
58
+ by?: string;
59
+ note?: string;
60
+ }
61
+ /**
62
+ * What a SURFACE hands in. `at` and `atSha` are stamped by
63
+ * {@link applyDerivedState}, so no caller can date a retry itself or key one to
64
+ * a head SHA it did not read.
65
+ */
66
+ export interface InterventionRequest {
67
+ via: InterventionVia;
68
+ by?: string;
69
+ /** Free text from the comment / CLI. Sanitized on the way in; never trusted. */
70
+ note?: string;
71
+ }
72
+ /**
73
+ * The phase a STANDALONE retry record terminates on — `recordIntervention`'s row
74
+ * (`./pr-escalation.ts`, which re-exports this as its public name).
75
+ *
76
+ * Defined HERE, at the reading end, because the value is load-bearing on this
77
+ * side: {@link applyDerivedState} has to recognise the row to keep it out of
78
+ * {@link PrState.assessedHeadShaByWorkflow}. Importing it from
79
+ * `./pr-escalation.ts` would close a module cycle (that module already imports
80
+ * this one), so the definition lives on the side with no outbound edge.
81
+ */
82
+ export declare const INTERVENTION_PHASE = "retry-requested";
29
83
  /**
30
84
  * Everything the harness knows about one pull request at one moment.
31
85
  *
@@ -64,8 +118,8 @@ export interface PrState {
64
118
  * Derived here rather than left to each call site so the decision functions
65
119
  * stay pure over the snapshot and never need the bot identity. It is the
66
120
  * discriminator behind both the attempt table (our push = same problem;
67
- * anyone else's = the world moved) and the stateful `requires-human` guard
68
- * (our own commit on top of an escalation does not count as intervention).
121
+ * anyone else's = the world moved) and the {@link escalatedAtSha} guard (our
122
+ * own commit on top of an escalation does not count as intervention).
69
123
  */
70
124
  headIsOurs: boolean;
71
125
  /** The PR's head branch — what a fix run clones and pushes to. */
@@ -137,18 +191,58 @@ export interface PrState {
137
191
  attempt: number;
138
192
  /** Consecutive `flaky` diagnoses so far, bounded by `fix.maxFlakyDeferrals`. */
139
193
  flakyDeferrals: number;
140
- /** Head SHA at which one of OUR runs escalated this PR, or null. */
194
+ /**
195
+ * Head SHA at which one of OUR runs escalated this PR, or null.
196
+ *
197
+ * The WHOLE of the escalation state. There is no companion "who applied the
198
+ * label" field, and its absence is the point: `requires-human` is a
199
+ * notification, read by nothing, so `escalatedAtSha !== null` is the only
200
+ * question a decision asks — "did a run of ours stop here, and is this still
201
+ * the head it stopped at?". A maintainer who wants the bot off a PR applies
202
+ * the HOLD label instead, which is an instruction rather than something
203
+ * inferred from a label we also write ourselves (02-hold-label.md).
204
+ *
205
+ * Written by `./pr-escalation.ts` and by nothing else, which is why that
206
+ * module records a run row BEFORE it labels: a skip writes no row, so an
207
+ * escalation that stayed a row-less skip would never persist this and would
208
+ * re-comment on every subsequent event.
209
+ *
210
+ * **Consumed by an {@link intervention}.** A recorded retry clears this back
211
+ * to null — that is how a re-arm becomes visible to the pure decision
212
+ * functions, which see only the snapshot. The mechanism stays bounded because
213
+ * the next escalation writes a fresh value at the same head while the
214
+ * intervention is by then the one the prior run already saw.
215
+ */
141
216
  escalatedAtSha: string | null;
142
217
  /**
143
- * Who put `requires-human` on this PR:
144
- * - `"us"` — a run of ours escalated it (we know the SHA, so a later push
145
- * clears the guard automatically).
146
- * - `"human"` — the label is present but no run of ours escalated: a
147
- * maintainer applied it to mean "bot, stay out". A hard, permanent
148
- * override.
149
- * - `null` — not escalated.
218
+ * The last time a human told us to try again, or null — the RETRY direction
219
+ * of human intent, and the counterpart to {@link escalatedAtSha}
220
+ * (03-retry-intervention.md).
221
+ *
222
+ * Before this field the state machine modelled *the PR's problem* precisely
223
+ * and *human intent* not at all: the only way to say "a human intervened" was
224
+ * that the head SHA changed and we did not author it, which is an INFERENCE
225
+ * FROM A COMMIT rather than a record of a decision. Two of the three things a
226
+ * maintainer would naturally try — commenting, removing the label — cleared
227
+ * the escalation guard without moving the budget window, so both fell straight
228
+ * back through `budget-exhausted` and posted a duplicate escalation comment.
229
+ *
230
+ * Recording it fixes both halves at once: `sameProblem` reads it, so a retry
231
+ * re-arms the attempt counter AND the cost baseline exactly as a push does
232
+ * (locked decision 7), and the record is what makes the re-arm ONCE-ONLY —
233
+ * the next dispatch reads the same intervention back off the prior run's
234
+ * snapshot and does not re-arm again.
235
+ *
236
+ * `by` and `note` are for display and for the journal. **No decision function
237
+ * reads either** — see {@link PrIntervention}.
238
+ *
239
+ * Written wherever the retry is recorded: on the dispatched run's own
240
+ * snapshot when the retry results in a run, and on a standalone row
241
+ * (`recordIntervention`, `./pr-escalation.ts`) when it does not — the same
242
+ * "a skip writes no row, so the record must" reasoning `escalatePr` is built
243
+ * on.
150
244
  */
151
- escalatedBy: "us" | "human" | null;
245
+ intervention: PrIntervention | null;
152
246
  /**
153
247
  * Head SHA at which we told this PR's author we cannot fix a fork, or null.
154
248
  *
@@ -198,10 +292,22 @@ export interface PrState {
198
292
  * is fresh.
199
293
  *
200
294
  * Deliberately NOT carried across a run that diagnosed nothing — unlike
201
- * {@link flakyDeferrals}, which persists. That asymmetry is what keeps the
202
- * manual exit working: a maintainer who removes `requires-human` by hand is
203
- * asking for another try, and a remembered `infra-dependent` would re-escalate
204
- * on the next event and put the label straight back.
295
+ * {@link flakyDeferrals}, which persists — and cleared outright by a fresh
296
+ * problem, whether the freshness came from a push or from an
297
+ * {@link intervention}. Both halves exist so that a remembered
298
+ * `infra-dependent` cannot re-escalate on the next event and put the label
299
+ * straight back.
300
+ *
301
+ * That was written as *"what keeps the manual exit working"*, and until
302
+ * 03-retry-intervention.md it only described one of the three cases. Removing
303
+ * `requires-human` by hand did clear a remembered `not-retryable` — but
304
+ * `budget-exhausted` and `attempts-exhausted` do not read this field at all,
305
+ * so the label removal cleared the guard, the budget gate fired anyway, and
306
+ * the label went straight back with a duplicate comment. **The manual exit
307
+ * now works for all three**, because it is no longer this field that carries
308
+ * it: a retry is a RECORD ({@link intervention}), it re-arms the counter and
309
+ * the cost baseline together, and this field being null is one consequence of
310
+ * that rather than the whole mechanism.
205
311
  */
206
312
  priorDiagnosisClass: DiagnosisClass | null;
207
313
  /**
@@ -241,6 +347,12 @@ export interface PrState {
241
347
  * works because correct-but-stopped outcomes (`flaky`, `infra-dependent`,
242
348
  * `upstream-broken`) now record `succeeded`: before that, the dedup did not
243
349
  * fire for exactly the cases that must not be re-attempted.
350
+ *
351
+ * A `retry-requested` row is the one `succeeded` row that never counts — it
352
+ * records a dispatch that did NOT happen, which is the opposite of the claim
353
+ * this field makes — and the fix family's entries are dropped entirely while a
354
+ * retry asked at this head is still waiting for a run to serve it. See
355
+ * `unassessForPendingRetry`.
244
356
  */
245
357
  assessedHeadShaByWorkflow: Record<string, string>;
246
358
  /**
@@ -293,6 +405,17 @@ export interface PrStateDeps {
293
405
  * existing test) still gets the exclusion.
294
406
  */
295
407
  botName?: string;
408
+ /**
409
+ * A retry that arrived WITH this event — `@<bot> retry` on the comment route,
410
+ * or `lastlight pr retry` on the admin route.
411
+ *
412
+ * Handed to the resolver rather than written by the caller afterwards, because
413
+ * the whole point of the record is that `sameProblem` reads it: an
414
+ * intervention applied after the snapshot was derived would re-arm nothing.
415
+ * The `label` surface needs no equivalent — its evidence is the live label
416
+ * read, which is already here.
417
+ */
418
+ intervention?: InterventionRequest;
296
419
  }
297
420
  /**
298
421
  * Resolve the whole snapshot. Called ONCE per dispatch, at the
@@ -311,3 +434,17 @@ export declare function resolvePrState(owner: string, repo: string, prNumber: nu
311
434
  * table without touching GitHub.
312
435
  */
313
436
  export declare function applyDerivedState(state: PrState, deps: PrStateDeps): void;
437
+ /**
438
+ * The identity of one ask — "is this the same retry the prior run already
439
+ * consumed, or a new one?".
440
+ *
441
+ * The timestamp alone is not enough, and the reason is a real one rather than a
442
+ * theoretical one: `at` has millisecond resolution, so two asks that land in the
443
+ * same millisecond read as one and the second silently re-arms nothing. The
444
+ * whole tuple is what a human actually varied — when, how, who, and why — and
445
+ * two asks identical on all four are the same ask for every purpose this has.
446
+ *
447
+ * Shared with `recordIntervention` (`./pr-escalation.ts`), so the row-writing
448
+ * side and the folding side cannot disagree about what "already recorded" means.
449
+ */
450
+ export declare function interventionKey(intervention: PrIntervention | null | undefined): string | null;