lastlight-core 0.21.14 → 0.23.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 (124) hide show
  1. package/config/default.yaml +119 -1
  2. package/dist/admin/routes.js +195 -38
  3. package/dist/admin/routes.js.map +1 -1
  4. package/dist/config/config-resolve.d.ts +38 -1
  5. package/dist/config/config-resolve.js +41 -17
  6. package/dist/config/config-resolve.js.map +1 -1
  7. package/dist/config/config.d.ts +114 -0
  8. package/dist/config/config.js +225 -7
  9. package/dist/config/config.js.map +1 -1
  10. package/dist/config/repo-config.d.ts +120 -0
  11. package/dist/config/repo-config.js +447 -0
  12. package/dist/config/repo-config.js.map +1 -0
  13. package/dist/connectors/github-webhook.d.ts +17 -0
  14. package/dist/connectors/github-webhook.js +150 -17
  15. package/dist/connectors/github-webhook.js.map +1 -1
  16. package/dist/connectors/types.d.ts +48 -1
  17. package/dist/cron/dependabot-discovery.d.ts +68 -11
  18. package/dist/cron/dependabot-discovery.js +78 -20
  19. package/dist/cron/dependabot-discovery.js.map +1 -1
  20. package/dist/cron/fanout.d.ts +10 -0
  21. package/dist/cron/fanout.js +35 -2
  22. package/dist/cron/fanout.js.map +1 -1
  23. package/dist/cron/jobs.d.ts +16 -2
  24. package/dist/cron/jobs.js +69 -9
  25. package/dist/cron/jobs.js.map +1 -1
  26. package/dist/cron/repo-crons.d.ts +110 -0
  27. package/dist/cron/repo-crons.js +169 -0
  28. package/dist/cron/repo-crons.js.map +1 -0
  29. package/dist/cron/review-discovery.d.ts +33 -20
  30. package/dist/cron/review-discovery.js +23 -30
  31. package/dist/cron/review-discovery.js.map +1 -1
  32. package/dist/engine/agent-executor.d.ts +1 -1
  33. package/dist/engine/agent-executor.js +1 -1
  34. package/dist/engine/agent-executor.js.map +1 -1
  35. package/dist/engine/dispatcher.d.ts +98 -1
  36. package/dist/engine/dispatcher.js +248 -231
  37. package/dist/engine/dispatcher.js.map +1 -1
  38. package/dist/engine/executors/orchestrator.js +39 -15
  39. package/dist/engine/executors/orchestrator.js.map +1 -1
  40. package/dist/engine/executors/shared.d.ts +43 -0
  41. package/dist/engine/executors/shared.js +65 -0
  42. package/dist/engine/executors/shared.js.map +1 -1
  43. package/dist/engine/fix-harvest.d.ts +169 -0
  44. package/dist/engine/fix-harvest.js +345 -0
  45. package/dist/engine/fix-harvest.js.map +1 -0
  46. package/dist/engine/fix-markers.d.ts +184 -0
  47. package/dist/engine/fix-markers.js +329 -0
  48. package/dist/engine/fix-markers.js.map +1 -0
  49. package/dist/engine/fix-scratch.d.ts +76 -0
  50. package/dist/engine/fix-scratch.js +77 -0
  51. package/dist/engine/fix-scratch.js.map +1 -0
  52. package/dist/engine/github/github.d.ts +302 -5
  53. package/dist/engine/github/github.js +614 -54
  54. package/dist/engine/github/github.js.map +1 -1
  55. package/dist/engine/github/profiles.d.ts +45 -1
  56. package/dist/engine/github/profiles.js +35 -0
  57. package/dist/engine/github/profiles.js.map +1 -1
  58. package/dist/engine/pr-decisions.d.ts +342 -0
  59. package/dist/engine/pr-decisions.js +721 -0
  60. package/dist/engine/pr-decisions.js.map +1 -0
  61. package/dist/engine/pr-escalation.d.ts +152 -0
  62. package/dist/engine/pr-escalation.js +320 -0
  63. package/dist/engine/pr-escalation.js.map +1 -0
  64. package/dist/engine/pr-notes.d.ts +175 -0
  65. package/dist/engine/pr-notes.js +315 -0
  66. package/dist/engine/pr-notes.js.map +1 -0
  67. package/dist/engine/pr-state.d.ts +313 -0
  68. package/dist/engine/pr-state.js +515 -0
  69. package/dist/engine/pr-state.js.map +1 -0
  70. package/dist/engine/review-check.d.ts +200 -0
  71. package/dist/engine/review-check.js +305 -0
  72. package/dist/engine/review-check.js.map +1 -0
  73. package/dist/engine/router.d.ts +27 -0
  74. package/dist/engine/router.js +156 -22
  75. package/dist/engine/router.js.map +1 -1
  76. package/dist/evals-api.d.ts +10 -0
  77. package/dist/evals-api.js +38 -0
  78. package/dist/evals-api.js.map +1 -1
  79. package/dist/index.js +313 -23
  80. package/dist/index.js.map +1 -1
  81. package/dist/sandbox/index.d.ts +13 -0
  82. package/dist/sandbox/index.js +30 -0
  83. package/dist/sandbox/index.js.map +1 -1
  84. package/dist/sandbox/k8s/init-clone.d.ts +5 -0
  85. package/dist/sandbox/k8s/init-clone.js +27 -0
  86. package/dist/sandbox/k8s/init-clone.js.map +1 -1
  87. package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +26 -1
  88. package/dist/sandbox/k8s/kubernetes-sandbox.js +30 -1
  89. package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
  90. package/dist/state/execution-store.d.ts +27 -0
  91. package/dist/state/execution-store.js +45 -0
  92. package/dist/state/execution-store.js.map +1 -1
  93. package/dist/state/workflow-run-store.d.ts +73 -0
  94. package/dist/state/workflow-run-store.js +106 -24
  95. package/dist/state/workflow-run-store.js.map +1 -1
  96. package/dist/workflows/pr-scope.d.ts +63 -0
  97. package/dist/workflows/pr-scope.js +113 -0
  98. package/dist/workflows/pr-scope.js.map +1 -0
  99. package/dist/workflows/resume.js +113 -8
  100. package/dist/workflows/resume.js.map +1 -1
  101. package/dist/workflows/runner.d.ts +2 -1
  102. package/dist/workflows/runner.js +143 -10
  103. package/dist/workflows/runner.js.map +1 -1
  104. package/dist/workflows/simple.d.ts +280 -1
  105. package/dist/workflows/simple.js +499 -8
  106. package/dist/workflows/simple.js.map +1 -1
  107. package/dist/workflows/target-policy.d.ts +0 -12
  108. package/dist/workflows/target-policy.js +9 -15
  109. package/dist/workflows/target-policy.js.map +1 -1
  110. package/package.json +4 -4
  111. package/skills/README.md +11 -5
  112. package/skills/dependency-impact/SKILL.md +83 -0
  113. package/skills/fixing/SKILL.md +190 -0
  114. package/skills/pr-review/SKILL.md +26 -9
  115. package/workflows/cron-dependabot-ci-fix.yaml +8 -5
  116. package/workflows/cron-review.yaml +14 -5
  117. package/workflows/dependabot-ci-fix.yaml +86 -2
  118. package/workflows/dependabot-pr-merge.yaml +13 -1
  119. package/workflows/pr-fix.yaml +84 -1
  120. package/workflows/pr-review.yaml +7 -0
  121. package/workflows/prompts/dependabot-ci-fix.md +70 -17
  122. package/workflows/prompts/dependabot-pr-merge.md +203 -80
  123. package/workflows/prompts/diagnose-ci.md +96 -0
  124. package/workflows/prompts/pr-fix.md +63 -4
@@ -0,0 +1,313 @@
1
+ /**
2
+ * The PR state machine — one resolved snapshot per dispatch.
3
+ *
4
+ * Before this module, what the harness "knew" about a pull request was read
5
+ * from six sites (`dependencyDedupSkip`, `handlePrFix`, `dispatchWorkflow`,
6
+ * `review-discovery`, and both dependency cron sweeps), each fetching an
7
+ * overlapping subset and each free to disagree — while the state itself lived
8
+ * across seven stores (GitHub labels, the `last-light/review` check run, run
9
+ * `context`, run `scratch`, execution status, live GitHub reads, and a file in
10
+ * the sandbox workspace). Three shipped-defect-grade bugs fell out of that; see
11
+ * `docs/plans/dependency-pr-resilience/09-state-machine.md`.
12
+ *
13
+ * The fix is structural, not incremental: **resolve the PR's state once, then
14
+ * decide**. `resolvePrState` is the only place that reads it; every policy
15
+ * question is a PURE function over the result (`../engine/pr-decisions.ts`), so
16
+ * the decisions are table-testable against literal fixtures with no GitHub mock
17
+ * and no sandbox.
18
+ *
19
+ * {@link PrState} is therefore the documentation of the state machine: it can be
20
+ * read, reviewed and diffed, which prose across ten documents cannot.
21
+ */
22
+ import type { StateDb } from "../state/db.js";
23
+ import type { GitHubClient } from "./github/github.js";
24
+ import type { CiFailureReport } from "./github/github.js";
25
+ import { type DiagnosisClass } from "./fix-markers.js";
26
+ import { type PrNote } from "./pr-notes.js";
27
+ /** Aggregate check state for a ref, as {@link GitHubClient.getChecksConclusion} reports it. */
28
+ export type ChecksState = "passing" | "failing" | "pending" | "none";
29
+ /**
30
+ * Everything the harness knows about one pull request at one moment.
31
+ *
32
+ * Two halves, deliberately kept visually separate:
33
+ *
34
+ * - **live from GitHub** — facts about the PR right now. Nothing here is a
35
+ * verdict of ours, which is what makes it safe to gate dispatch on: a live
36
+ * precondition re-evaluates every event, whereas a stored verdict freezes
37
+ * (see `resolveFixDisposition` and 09 → D1).
38
+ * - **derived from our own history, keyed on the PR** — what WE have already
39
+ * done about it. Keyed on (`PR_FIX_SHAPED_WORKFLOWS`, PR), never on one
40
+ * workflow, because "how many times have we tried to fix this PR" is a fact
41
+ * about the pull request (09 → S1).
42
+ *
43
+ * A snapshot is persisted verbatim on the run context (`context.prState`) so
44
+ * the run detail panel can render the decisions that were actually taken, with
45
+ * the inputs that produced them, long after the live state has moved on.
46
+ */
47
+ export interface PrState {
48
+ /** `owner/repo`. */
49
+ repo: string;
50
+ prNumber: number;
51
+ /** Head commit SHA. The identity of "the problem" for the attempt counter. */
52
+ headSha: string;
53
+ /**
54
+ * The git AUTHOR NAME on the head commit — not a GitHub login.
55
+ *
56
+ * `git-auth.ts` stamps `user.name = botLogin` on the agent's own commits, and
57
+ * the `check_suite` webhook carries the same field, so this is the one value
58
+ * that answers "did we push this head?" identically on both routes.
59
+ */
60
+ headAuthor: string;
61
+ /**
62
+ * `headAuthor === botLogin` — did WE push the head commit?
63
+ *
64
+ * Derived here rather than left to each call site so the decision functions
65
+ * stay pure over the snapshot and never need the bot identity. It is the
66
+ * 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).
69
+ */
70
+ headIsOurs: boolean;
71
+ /** The PR's head branch — what a fix run clones and pushes to. */
72
+ headRef: string;
73
+ /**
74
+ * The PR's REAL base ref.
75
+ *
76
+ * Not `getDefaultBranch()`. A PR targeting a release branch used to have the
77
+ * fix prompt merge `main` into it (00 → "Other latent bugs found" #3).
78
+ */
79
+ baseRef: string;
80
+ isDraft: boolean;
81
+ /**
82
+ * Cross-repo (fork) PR. Its head branch lives on a repo we cannot push to and
83
+ * its head ref is not on origin, so there is nothing for a fix run to clone
84
+ * or push. `head.repo === null` (the fork was deleted) counts as a fork too:
85
+ * the branch is gone either way.
86
+ */
87
+ isFork: boolean;
88
+ /** `owner/repo` of the head, or null when the source fork was deleted. */
89
+ headRepoFullName: string | null;
90
+ labels: string[];
91
+ title: string;
92
+ body: string;
93
+ checksState: ChecksState;
94
+ /**
95
+ * How many checks/statuses have actually SETTLED on the head SHA.
96
+ *
97
+ * `"passing"` on its own is not evidence: a repo with one trivial check and a
98
+ * repo with a full matrix both report it, and a repo with none reports
99
+ * `"none"`. The auto-merge decision needs to tell "CI approved this" from
100
+ * "nothing looked at it" (09 → D10, `dependencies.minSettledChecks`).
101
+ */
102
+ settledCheckCount: number;
103
+ /**
104
+ * Check state of the BASE branch tip — the sole signal for `upstream-broken`.
105
+ * A live precondition, never a stored verdict: see `resolveFixDisposition`.
106
+ */
107
+ baseChecksState: ChecksState;
108
+ /**
109
+ * The bot's own most recent review AT THE CURRENT HEAD SHA, or null. A push
110
+ * invalidates it naturally (GitHub records the review's `commit_id`).
111
+ */
112
+ botReviewAtHead: {
113
+ state: string;
114
+ } | null;
115
+ /**
116
+ * Structured CI evidence for the head SHA (Phase 1), or null when the checks
117
+ * are not failing — the report costs one Actions job-log download per failed
118
+ * check, so it is only fetched when there is something to explain.
119
+ */
120
+ ciReport: CiFailureReport | null;
121
+ /**
122
+ * Which attempt at THIS PROBLEM the next fix run would be — 1-based.
123
+ *
124
+ * `attempt` is scoped to a problem, not to a PR (09 → S1):
125
+ *
126
+ * | live head vs prior | new head's author | attempt |
127
+ * |--------------------|-------------------|--------------|
128
+ * | unchanged | — | prior + 1 |
129
+ * | changed | us (`botLogin`) | prior + 1 |
130
+ * | changed | anyone else | **1** |
131
+ *
132
+ * The third row is what lets a maintainer's push, a Dependabot rebase or a
133
+ * Renovate recreate re-arm the loop. Resetting on author alone would be
134
+ * wrong too: an attempt that pushes nothing leaves the head unchanged, which
135
+ * would reset forever.
136
+ */
137
+ attempt: number;
138
+ /** Consecutive `flaky` diagnoses so far, bounded by `fix.maxFlakyDeferrals`. */
139
+ flakyDeferrals: number;
140
+ /** Head SHA at which one of OUR runs escalated this PR, or null. */
141
+ escalatedAtSha: string | null;
142
+ /**
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.
150
+ */
151
+ escalatedBy: "us" | "human" | null;
152
+ /**
153
+ * Head SHA at which we told this PR's author we cannot fix a fork, or null.
154
+ *
155
+ * The dedup for the fork-PR notice, carried forward exactly as
156
+ * {@link escalatedAtSha} is — the same "the persisted record IS the
157
+ * de-duplication" property `pr-escalation.ts` documents, rather than an API
158
+ * scan asking "did we already comment".
159
+ *
160
+ * Unlike the escalation guard it is never invalidated by a later push, and
161
+ * that asymmetry is the point. An escalation says "this problem needs a
162
+ * human", which a new commit can make untrue; a fork notice says "your branch
163
+ * is not on this repo", which pushing to that same fork does not change. So
164
+ * the notice is once per PR, not once per head — a fork PR that gets ten
165
+ * pushes is one apology, not ten.
166
+ */
167
+ forkNoticedAtSha: string | null;
168
+ /** One marker line per prior attempt, oldest first — rendered as `{{priorAttempts}}`. */
169
+ priorAttempts: string[];
170
+ /**
171
+ * The PR's journal — short, bounded notes agents left for later runs
172
+ * (10-pr-memory.md, `./pr-notes.ts`).
173
+ *
174
+ * A FIELD of the snapshot, never a store beside it. That is the whole point:
175
+ * 09's thesis is that state scattered across stores and free to disagree is
176
+ * the defect, and a free-form scratchpad alongside `PrState` would recreate
177
+ * it. As a field it is resolved once, persisted with the rest of the snapshot,
178
+ * and rendered wherever the snapshot is.
179
+ *
180
+ * Keyed on the PR like everything else here, so `pr-review` reads what
181
+ * `dependabot-ci-fix` learned.
182
+ *
183
+ * **Hints, never instructions.** Nothing in this array may authorise anything.
184
+ * No decision function reads it — `renderContext` projects it to a single
185
+ * FENCED STRING for the prompts and that is its only consumer, so a note can
186
+ * inform an agent and can never make a code path reachable. See
187
+ * `./pr-notes.ts` → the fence, and the rejection of any note carrying a token
188
+ * the marker parser reads.
189
+ */
190
+ notes: PrNote[];
191
+ /**
192
+ * The class the IMMEDIATELY PRECEDING run diagnosed, or null.
193
+ *
194
+ * The only prior-run verdict any dispatch decision is allowed to read, and it
195
+ * is allowed only because the skip it produces WRITES A RUN ROW (09 → D1's
196
+ * general rule; see `resolveFixDisposition`). Null when that run produced no
197
+ * `DIAGNOSIS_COMPLETE`, when the token was unrecognised, or when the problem
198
+ * is fresh.
199
+ *
200
+ * 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.
205
+ */
206
+ priorDiagnosisClass: DiagnosisClass | null;
207
+ /**
208
+ * USD spent on THIS PROBLEM by the fix family (`fix.maxCostUsd`).
209
+ *
210
+ * Scoped to a problem, not to a PR — the same window {@link attempt} uses,
211
+ * and for the same reason. It was the PR's whole lifetime spend, which put it
212
+ * out of step with every other budget in the snapshot: a maintainer's push
213
+ * re-armed `attempt` and cleared the `escalated:` guard, then the very next
214
+ * check fell straight back through `budget-exhausted` and posted another
215
+ * `requires-human` comment — a comment whose own closing paragraph tells the
216
+ * maintainer that pushing is the remedy (#256).
217
+ *
218
+ * Computed as lifetime spend minus {@link costBaselineUsd}.
219
+ */
220
+ cumulativeCostUsd: number;
221
+ /**
222
+ * Lifetime fix-family spend at the moment the current problem began — the
223
+ * offset {@link cumulativeCostUsd} is measured from.
224
+ *
225
+ * Carried forward while the problem is the same and re-stamped to the
226
+ * lifetime total when someone else's push makes it a fresh one, so the two
227
+ * fields together say "we have spent $X since the last human intervention"
228
+ * without a second store or a per-run cost column. Zero on a PR we have never
229
+ * worked, which makes `cumulative = lifetime` — the old behaviour, for the
230
+ * only case where the old behaviour was right.
231
+ */
232
+ costBaselineUsd: number;
233
+ /**
234
+ * Head SHA the most recent SUCCEEDED run of each PR-scoped workflow saw —
235
+ * the "already assessed at this SHA" dedup, per workflow.
236
+ *
237
+ * Per-workflow even though the attempt counter is per-family: `pr-fix` having
238
+ * succeeded at a SHA says nothing about whether `dependabot-pr-merge` has
239
+ * assessed it. SUCCEEDED-only is what makes a retry possible at all — a
240
+ * crashed run leaves no entry, so the same head is attempted again. This only
241
+ * works because correct-but-stopped outcomes (`flaky`, `infra-dependent`,
242
+ * `upstream-broken`) now record `succeeded`: before that, the dedup did not
243
+ * fire for exactly the cases that must not be re-attempted.
244
+ */
245
+ assessedHeadShaByWorkflow: Record<string, string>;
246
+ /**
247
+ * A PR-scoped run already in flight, or null. The lock is across EVERY
248
+ * PR-scoped workflow, not per family (09 → S4).
249
+ */
250
+ runInFlight: {
251
+ workflow: string;
252
+ runId: string;
253
+ } | null;
254
+ /**
255
+ * The GitHub reads that failed while resolving, if any.
256
+ *
257
+ * FAIL-OPEN IS LOAD-BEARING. Every read below is best-effort and every
258
+ * failure degrades to a value that cannot cause a skip — we would far rather
259
+ * occasionally re-run than silently drop a genuine event because GitHub had a
260
+ * bad minute. Decisions that would be unsafe on incomplete data check this
261
+ * list explicitly rather than inferring it from a suspicious-looking field.
262
+ */
263
+ readErrors: string[];
264
+ }
265
+ /**
266
+ * Every PR-scoped workflow — the span of the run lock (09 → S4).
267
+ *
268
+ * Re-exported from `../workflows/pr-scope.ts`, which derives it from each
269
+ * workflow's own `pr_scoped: true` metadata rather than from a hardcoded list
270
+ * of four names the operator is free to route around. The argument for both the
271
+ * span and the derivation lives there; every reader inside the PR state machine
272
+ * reaches for it through this module.
273
+ */
274
+ export { prScopedWorkflows } from "../workflows/pr-scope.js";
275
+ /** The trigger id every PR-scoped run and ledger row is keyed by. */
276
+ export declare function prTriggerId(repo: string, prNumber: number): string;
277
+ /** Collaborators {@link resolvePrState} reads through. */
278
+ export interface PrStateDeps {
279
+ /** `null` in chat-only mode — the live half then degrades wholesale. */
280
+ github: GitHubClient | null;
281
+ db: StateDb;
282
+ /** `<botName>[bot]` — the git author name our own commits carry. */
283
+ botLogin: string;
284
+ /**
285
+ * The App SLUG (`botName`, no `[bot]` suffix) — the `app.slug` GitHub stamps
286
+ * on the check runs WE post.
287
+ *
288
+ * Every check read below is a TRIGGER-side settle computation, so our own
289
+ * `last-light/review` check must be excluded from it or a queued/in-progress
290
+ * review deadlocks the aggregate at `pending` forever (see
291
+ * {@link ChecksQueryOptions.excludeApp}). Optional, and derived from
292
+ * {@link botLogin} when absent, so a caller that only knows the login (every
293
+ * existing test) still gets the exclusion.
294
+ */
295
+ botName?: string;
296
+ }
297
+ /**
298
+ * Resolve the whole snapshot. Called ONCE per dispatch, at the
299
+ * `dispatchWorkflow` choke point every route crosses.
300
+ *
301
+ * Never throws. Every live read is independently best-effort; a failure records
302
+ * a line in {@link PrState.readErrors} and leaves the field at a value that
303
+ * cannot itself cause a skip.
304
+ */
305
+ export declare function resolvePrState(owner: string, repo: string, prNumber: number, deps: PrStateDeps): Promise<PrState>;
306
+ /**
307
+ * Fill the derived half from our own run history.
308
+ *
309
+ * Split out (and exported) because it is a pure-ish function of the DB: a test
310
+ * can hand it a literal live half plus a fake store and assert the attempt
311
+ * table without touching GitHub.
312
+ */
313
+ export declare function applyDerivedState(state: PrState, deps: PrStateDeps): void;