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,200 @@
1
+ /**
2
+ * The `last-light/review` Check Run — as a **projection of run state**.
3
+ *
4
+ * Before this module the check was created in `dispatcher.ts` and completed
5
+ * inside a `.then()` chained onto the in-memory workflow promise, and
6
+ * `updateCheckRun` appeared nowhere else. `resume.ts` and `admission.ts` never
7
+ * touched it, and the queued branch said so out loud: *"Documented limitation:
8
+ * the check stays in-progress until admission fires."* So a check stranded
9
+ * `in_progress` on every server restart mid-review (i.e. **every deploy**),
10
+ * every queued-then-resumed run, every `expireStaleRuns` cancellation and every
11
+ * crash. Nobody noticed because `check-prs-awaiting-review` re-reviewed the PR
12
+ * within 30 minutes and `createCheckRun` posted a *new* check under the same
13
+ * name, superseding the stranded one — the polling cron was the de facto repair
14
+ * mechanism for stuck checks. That repair is accidental, and the per-SHA review
15
+ * dedup breaks it: a check strands most often on a review that ran and posted,
16
+ * and in that state `botReviewAtHead` is set, so the dedup skips the run and
17
+ * posts no superseding check. You can have the dedup or the accidental repair,
18
+ * not both.
19
+ *
20
+ * The bug is not routing, it is that **the check's state lived somewhere the
21
+ * run's state did not** (09-state-machine.md → S2, locked decision 16). So:
22
+ *
23
+ * 1. The check id (+ owner, repo, head SHA) is persisted on the run row the
24
+ * moment the run exists — {@link recordReviewCheck}.
25
+ * 2. It is completed from the run's TERMINAL TRANSITION — the same place that
26
+ * writes `succeeded` / `failed` / `cancelled` — via the store's
27
+ * `TerminalRunObserver`. `simple.ts`, `resume.ts`, `expireQueued` and the
28
+ * admin cancel therefore all resolve it for free, and a future terminal path
29
+ * cannot forget to.
30
+ * 3. A run that never dispatches creates no check at all, rather than creating
31
+ * one and immediately concluding it.
32
+ *
33
+ * Boot-time reconciliation is deliberately NOT needed: terminal-transition
34
+ * completion plus the existing `MAX_RESTART_RESUMES` resume path covers
35
+ * restart.
36
+ *
37
+ * The one thing that is NOT a run — the `queued` / `neutral` PLACEHOLDER a
38
+ * deferred review leaves behind ({@link postPlaceholderReviewCheck}) — is
39
+ * terminal by construction: `neutral` is already concluded, and a `queued`
40
+ * check is superseded by the real one the moment a review dispatches (GitHub
41
+ * shows the latest run for a check name), with the 30-minute sweep as the
42
+ * backstop that guarantees one arrives.
43
+ */
44
+ import type { StateDb } from "../state/db.js";
45
+ import type { WorkflowRun } from "../state/workflow-run-store.js";
46
+ import type { GitHubClient } from "./github/github.js";
47
+ import type { ReviewCheckPlacement } from "./pr-decisions.js";
48
+ /** The check-run name branch protection can require. */
49
+ export declare const REVIEW_CHECK_NAME = "last-light/review";
50
+ /** The workflow whose runs own a {@link REVIEW_CHECK_NAME} check. */
51
+ export declare const REVIEW_WORKFLOW = "pr-review";
52
+ /** `workflow_runs.scratch` key holding {@link PersistedReviewCheck}. */
53
+ export declare const REVIEW_CHECK_SCRATCH_KEY = "reviewCheck";
54
+ /**
55
+ * Everything the terminal transition needs to conclude the check, persisted
56
+ * beside the run.
57
+ *
58
+ * The head SHA is stored rather than re-read: the check is pinned to the commit
59
+ * it was created against, so that is the commit whose review verdict it must
60
+ * report. A rebase mid-review produces a *new* head with its own checks; the
61
+ * old one is superseded, not retro-actively re-judged.
62
+ */
63
+ export interface PersistedReviewCheck {
64
+ checkRunId: number;
65
+ owner: string;
66
+ repo: string;
67
+ headSha: string;
68
+ }
69
+ /** Read the persisted ref off a run row, tolerating rows that have none. */
70
+ export declare function readReviewCheck(run: WorkflowRun): PersistedReviewCheck | null;
71
+ /** Persist the ref so the terminal transition can find it. */
72
+ export declare function recordReviewCheck(db: StateDb, runId: string, ref: PersistedReviewCheck): void;
73
+ /** Everything {@link openReviewCheck} / {@link postPlaceholderReviewCheck} need. */
74
+ export interface ReviewCheckDeps {
75
+ github: GitHubClient | null;
76
+ /** `<botName>[bot]` — whose review the conclusion is derived from. */
77
+ botLogin?: string;
78
+ /** `@<botName>` handle, for the `on-request` placeholder's instructions. */
79
+ botMention?: string;
80
+ }
81
+ /**
82
+ * Open the in-progress check for a review that IS about to run.
83
+ *
84
+ * Best-effort: a failed create returns null and the review proceeds without a
85
+ * check. Losing the check is a UI gap; refusing the review over it would not be.
86
+ */
87
+ export declare function openReviewCheck(args: {
88
+ owner: string;
89
+ repo: string;
90
+ headSha: string;
91
+ }, deps: ReviewCheckDeps): Promise<PersistedReviewCheck | null>;
92
+ /**
93
+ * Open the check AND bind it to a run, as one step.
94
+ *
95
+ * The two halves must not be separable, and that is a defect report rather than
96
+ * a preference: the check used to be created at the top of `dispatchWorkflow`
97
+ * and recorded only inside the runner's `onRunStart` callback — which
98
+ * `runSimpleWorkflow` never reaches when the run is over the concurrency cap
99
+ * (it returns `{ queued: true }` first). The check was created, never
100
+ * persisted, never seen by the terminal observer, and never concluded; and the
101
+ * accidental repair that used to hide this is gone, because a `queued` run
102
+ * counts as active for its trigger, so the 30-minute sweep resolves
103
+ * `run-in-flight` → placement `none` and posts no superseding check.
104
+ *
105
+ * Best-effort throughout: a failed create returns null and the review proceeds
106
+ * without a check. Losing the check is a UI gap; refusing the review over it
107
+ * would not be.
108
+ */
109
+ export declare function openAndBindReviewCheck(db: StateDb, runId: string, args: {
110
+ owner: string;
111
+ repo: string;
112
+ headSha: string;
113
+ detailsUrl?: string;
114
+ }, deps: ReviewCheckDeps): Promise<PersistedReviewCheck | null>;
115
+ /** What {@link bindQueuedReviewCheck} needs to find the row and describe the check. */
116
+ export interface QueuedReviewCheckArgs {
117
+ /** `owner/repo#N` — exactly the id `simple.ts` derived for the run. */
118
+ triggerId: string;
119
+ workflowName: string;
120
+ owner: string;
121
+ repo: string;
122
+ headSha: string;
123
+ /** Dashboard deep link for whichever run turns out to own the check. */
124
+ detailsUrl?: (runId: string) => string | undefined;
125
+ }
126
+ /**
127
+ * Bind a check to the run a dispatch just QUEUED.
128
+ *
129
+ * A queued run never reaches `onRunStart` — `runSimpleWorkflow` writes the row
130
+ * and returns — and admission promotes it through `resumeSimpleRun`, which
131
+ * takes no callbacks at all. So this is the only moment at which a queued
132
+ * review's check can be attached to its run, and attaching it is what makes the
133
+ * TTL expiry, the admin cancel and the eventual completion resolve it for free.
134
+ *
135
+ * Returns null (creating nothing) when there is no queued row of this workflow
136
+ * to own it, or when the row already carries one — a duplicate trigger on an
137
+ * already-queued run also returns `queued`, and a second check would orphan the
138
+ * first rather than supersede it.
139
+ */
140
+ export declare function bindQueuedReviewCheck(db: StateDb, args: QueuedReviewCheckArgs, deps: ReviewCheckDeps): Promise<PersistedReviewCheck | null>;
141
+ /**
142
+ * Post the placeholder a DEFERRED review leaves behind — see
143
+ * `reviewCheckPlacement`.
144
+ *
145
+ * `queued` (`after-checks`): branch protection already sees the check, so a repo
146
+ * can require `last-light/review` without racing the settle event that will
147
+ * eventually dispatch the real review.
148
+ *
149
+ * `neutral` (`on-request`): treated as passing by branch protection, so it never
150
+ * blocks a merge, and its Re-run button becomes the request affordance — the
151
+ * check *is* the button (`check_run.rerequested` on this name is normalised to
152
+ * an explicit review request).
153
+ *
154
+ * Never throws; a placeholder is advisory.
155
+ */
156
+ export declare function postPlaceholderReviewCheck(args: {
157
+ owner: string;
158
+ repo: string;
159
+ headSha: string;
160
+ }, placement: Exclude<ReviewCheckPlacement, "in-progress" | "none">, deps: ReviewCheckDeps): Promise<void>;
161
+ /**
162
+ * The placeholder half of the dispatch gate: called from BOTH skip sites (the
163
+ * dispatcher's webhook/comment gate and `dispatchWorkflow`'s cron/API gate), the
164
+ * same way `escalatePr` is, so the two routes cannot drift.
165
+ *
166
+ * Only ever fires on a PR-ATTENTION event. That is the whole rate limit: a
167
+ * placeholder is a statement about a head SHA, and `pr.opened` / `synchronize` /
168
+ * `reopened` / `ready_for_review` arrive roughly once per SHA, whereas the
169
+ * 30-minute sweep would re-post one on every tick for the life of the PR.
170
+ */
171
+ export declare function postReviewCheckForSkip(args: {
172
+ workflowName: string;
173
+ placement: ReviewCheckPlacement;
174
+ postsCheck: boolean;
175
+ route: "attention" | "checks-settled" | "sweep";
176
+ owner: string;
177
+ repo: string;
178
+ headSha: string;
179
+ }, deps: ReviewCheckDeps): Promise<void>;
180
+ /** Point an already-open check at the run's dashboard deep link. */
181
+ export declare function linkReviewCheck(ref: PersistedReviewCheck, detailsUrl: string, deps: ReviewCheckDeps): Promise<void>;
182
+ /**
183
+ * Conclude the check for a run that has just reached a terminal status.
184
+ *
185
+ * The conclusion is read from what the run actually POSTED — the bot's review
186
+ * at the check's head SHA — rather than from the run's exit code, because a
187
+ * `succeeded` run that legitimately skipped (already reviewed, nothing to say)
188
+ * must not claim an approval it did not give. `neutral` is the honest answer
189
+ * whenever there is no verdict to report, and branch protection treats it as
190
+ * passing, so a review that failed to run never blocks a merge on its own.
191
+ *
192
+ * Idempotent enough: the persisted ref is cleared first, so a second terminal
193
+ * notification for the same run (a retry, a racing cancel) is a no-op.
194
+ */
195
+ export declare function concludeReviewCheck(db: StateDb, run: WorkflowRun, status: "succeeded" | "failed" | "cancelled", deps: ReviewCheckDeps): Promise<void>;
196
+ /**
197
+ * Wire {@link concludeReviewCheck} onto every terminal run transition. Called
198
+ * once, at boot.
199
+ */
200
+ export declare function installReviewCheckObserver(db: StateDb, deps: ReviewCheckDeps): void;
@@ -0,0 +1,305 @@
1
+ /**
2
+ * The `last-light/review` Check Run — as a **projection of run state**.
3
+ *
4
+ * Before this module the check was created in `dispatcher.ts` and completed
5
+ * inside a `.then()` chained onto the in-memory workflow promise, and
6
+ * `updateCheckRun` appeared nowhere else. `resume.ts` and `admission.ts` never
7
+ * touched it, and the queued branch said so out loud: *"Documented limitation:
8
+ * the check stays in-progress until admission fires."* So a check stranded
9
+ * `in_progress` on every server restart mid-review (i.e. **every deploy**),
10
+ * every queued-then-resumed run, every `expireStaleRuns` cancellation and every
11
+ * crash. Nobody noticed because `check-prs-awaiting-review` re-reviewed the PR
12
+ * within 30 minutes and `createCheckRun` posted a *new* check under the same
13
+ * name, superseding the stranded one — the polling cron was the de facto repair
14
+ * mechanism for stuck checks. That repair is accidental, and the per-SHA review
15
+ * dedup breaks it: a check strands most often on a review that ran and posted,
16
+ * and in that state `botReviewAtHead` is set, so the dedup skips the run and
17
+ * posts no superseding check. You can have the dedup or the accidental repair,
18
+ * not both.
19
+ *
20
+ * The bug is not routing, it is that **the check's state lived somewhere the
21
+ * run's state did not** (09-state-machine.md → S2, locked decision 16). So:
22
+ *
23
+ * 1. The check id (+ owner, repo, head SHA) is persisted on the run row the
24
+ * moment the run exists — {@link recordReviewCheck}.
25
+ * 2. It is completed from the run's TERMINAL TRANSITION — the same place that
26
+ * writes `succeeded` / `failed` / `cancelled` — via the store's
27
+ * `TerminalRunObserver`. `simple.ts`, `resume.ts`, `expireQueued` and the
28
+ * admin cancel therefore all resolve it for free, and a future terminal path
29
+ * cannot forget to.
30
+ * 3. A run that never dispatches creates no check at all, rather than creating
31
+ * one and immediately concluding it.
32
+ *
33
+ * Boot-time reconciliation is deliberately NOT needed: terminal-transition
34
+ * completion plus the existing `MAX_RESTART_RESUMES` resume path covers
35
+ * restart.
36
+ *
37
+ * The one thing that is NOT a run — the `queued` / `neutral` PLACEHOLDER a
38
+ * deferred review leaves behind ({@link postPlaceholderReviewCheck}) — is
39
+ * terminal by construction: `neutral` is already concluded, and a `queued`
40
+ * check is superseded by the real one the moment a review dispatches (GitHub
41
+ * shows the latest run for a check name), with the 30-minute sweep as the
42
+ * backstop that guarantees one arrives.
43
+ */
44
+ /** The check-run name branch protection can require. */
45
+ export const REVIEW_CHECK_NAME = "last-light/review";
46
+ /** The workflow whose runs own a {@link REVIEW_CHECK_NAME} check. */
47
+ export const REVIEW_WORKFLOW = "pr-review";
48
+ /** `workflow_runs.scratch` key holding {@link PersistedReviewCheck}. */
49
+ export const REVIEW_CHECK_SCRATCH_KEY = "reviewCheck";
50
+ /** Read the persisted ref off a run row, tolerating rows that have none. */
51
+ export function readReviewCheck(run) {
52
+ const raw = (run.scratch ?? {})[REVIEW_CHECK_SCRATCH_KEY];
53
+ if (!raw || typeof raw !== "object")
54
+ return null;
55
+ const r = raw;
56
+ if (typeof r.checkRunId !== "number" || typeof r.owner !== "string")
57
+ return null;
58
+ if (typeof r.repo !== "string" || typeof r.headSha !== "string")
59
+ return null;
60
+ return { checkRunId: r.checkRunId, owner: r.owner, repo: r.repo, headSha: r.headSha };
61
+ }
62
+ /** Persist the ref so the terminal transition can find it. */
63
+ export function recordReviewCheck(db, runId, ref) {
64
+ db.runs.mergeScratch(runId, { [REVIEW_CHECK_SCRATCH_KEY]: ref });
65
+ }
66
+ /**
67
+ * Open the in-progress check for a review that IS about to run.
68
+ *
69
+ * Best-effort: a failed create returns null and the review proceeds without a
70
+ * check. Losing the check is a UI gap; refusing the review over it would not be.
71
+ */
72
+ export async function openReviewCheck(args, deps) {
73
+ const { github } = deps;
74
+ if (!github || !args.headSha)
75
+ return null;
76
+ try {
77
+ const checkRunId = await github.createCheckRun(args.owner, args.repo, args.headSha, REVIEW_CHECK_NAME, {
78
+ output: {
79
+ title: "Review in progress",
80
+ summary: "Last Light is reviewing this PR. The conclusion will land here when the review completes.",
81
+ },
82
+ });
83
+ console.log(`[check] Posted in-progress check ${checkRunId} for ${args.owner}/${args.repo} on ${args.headSha.slice(0, 7)}`);
84
+ return { checkRunId, owner: args.owner, repo: args.repo, headSha: args.headSha };
85
+ }
86
+ catch (err) {
87
+ const msg = err instanceof Error ? err.message : String(err);
88
+ console.warn(`[check] failed to create in-progress check: ${msg}`);
89
+ return null;
90
+ }
91
+ }
92
+ /**
93
+ * Open the check AND bind it to a run, as one step.
94
+ *
95
+ * The two halves must not be separable, and that is a defect report rather than
96
+ * a preference: the check used to be created at the top of `dispatchWorkflow`
97
+ * and recorded only inside the runner's `onRunStart` callback — which
98
+ * `runSimpleWorkflow` never reaches when the run is over the concurrency cap
99
+ * (it returns `{ queued: true }` first). The check was created, never
100
+ * persisted, never seen by the terminal observer, and never concluded; and the
101
+ * accidental repair that used to hide this is gone, because a `queued` run
102
+ * counts as active for its trigger, so the 30-minute sweep resolves
103
+ * `run-in-flight` → placement `none` and posts no superseding check.
104
+ *
105
+ * Best-effort throughout: a failed create returns null and the review proceeds
106
+ * without a check. Losing the check is a UI gap; refusing the review over it
107
+ * would not be.
108
+ */
109
+ export async function openAndBindReviewCheck(db, runId, args, deps) {
110
+ const ref = await openReviewCheck(args, deps);
111
+ if (!ref)
112
+ return null;
113
+ db.runs.mergeScratch(runId, { [REVIEW_CHECK_SCRATCH_KEY]: ref });
114
+ if (args.detailsUrl)
115
+ linkReviewCheck(ref, args.detailsUrl, deps).catch(() => { });
116
+ return ref;
117
+ }
118
+ /**
119
+ * Bind a check to the run a dispatch just QUEUED.
120
+ *
121
+ * A queued run never reaches `onRunStart` — `runSimpleWorkflow` writes the row
122
+ * and returns — and admission promotes it through `resumeSimpleRun`, which
123
+ * takes no callbacks at all. So this is the only moment at which a queued
124
+ * review's check can be attached to its run, and attaching it is what makes the
125
+ * TTL expiry, the admin cancel and the eventual completion resolve it for free.
126
+ *
127
+ * Returns null (creating nothing) when there is no queued row of this workflow
128
+ * to own it, or when the row already carries one — a duplicate trigger on an
129
+ * already-queued run also returns `queued`, and a second check would orphan the
130
+ * first rather than supersede it.
131
+ */
132
+ export async function bindQueuedReviewCheck(db, args, deps) {
133
+ const run = db.runs.getByTrigger(args.triggerId);
134
+ if (!run || run.workflowName !== args.workflowName || run.status !== "queued")
135
+ return null;
136
+ if (readReviewCheck(run))
137
+ return null;
138
+ return openAndBindReviewCheck(db, run.id, {
139
+ owner: args.owner,
140
+ repo: args.repo,
141
+ headSha: args.headSha,
142
+ detailsUrl: args.detailsUrl?.(run.id),
143
+ }, deps);
144
+ }
145
+ /**
146
+ * Post the placeholder a DEFERRED review leaves behind — see
147
+ * `reviewCheckPlacement`.
148
+ *
149
+ * `queued` (`after-checks`): branch protection already sees the check, so a repo
150
+ * can require `last-light/review` without racing the settle event that will
151
+ * eventually dispatch the real review.
152
+ *
153
+ * `neutral` (`on-request`): treated as passing by branch protection, so it never
154
+ * blocks a merge, and its Re-run button becomes the request affordance — the
155
+ * check *is* the button (`check_run.rerequested` on this name is normalised to
156
+ * an explicit review request).
157
+ *
158
+ * Never throws; a placeholder is advisory.
159
+ */
160
+ export async function postPlaceholderReviewCheck(args, placement, deps) {
161
+ const { github } = deps;
162
+ if (!github || !args.headSha)
163
+ return;
164
+ const mention = deps.botMention ?? "@last-light";
165
+ const options = placement === "queued"
166
+ ? {
167
+ status: "queued",
168
+ output: {
169
+ title: "Waiting for CI",
170
+ summary: "Waiting for CI to finish before reviewing.",
171
+ },
172
+ }
173
+ : {
174
+ status: "completed",
175
+ conclusion: "neutral",
176
+ output: {
177
+ title: "Review available on request",
178
+ summary: `Review available on request — use Re-run, or comment \`${mention} review\`.`,
179
+ },
180
+ };
181
+ try {
182
+ const id = await github.createCheckRun(args.owner, args.repo, args.headSha, REVIEW_CHECK_NAME, options);
183
+ console.log(`[check] Posted ${placement} check ${id} for ${args.owner}/${args.repo} on ${args.headSha.slice(0, 7)}`);
184
+ }
185
+ catch (err) {
186
+ const msg = err instanceof Error ? err.message : String(err);
187
+ console.warn(`[check] failed to create ${placement} check: ${msg}`);
188
+ }
189
+ }
190
+ /**
191
+ * The placeholder half of the dispatch gate: called from BOTH skip sites (the
192
+ * dispatcher's webhook/comment gate and `dispatchWorkflow`'s cron/API gate), the
193
+ * same way `escalatePr` is, so the two routes cannot drift.
194
+ *
195
+ * Only ever fires on a PR-ATTENTION event. That is the whole rate limit: a
196
+ * placeholder is a statement about a head SHA, and `pr.opened` / `synchronize` /
197
+ * `reopened` / `ready_for_review` arrive roughly once per SHA, whereas the
198
+ * 30-minute sweep would re-post one on every tick for the life of the PR.
199
+ */
200
+ export async function postReviewCheckForSkip(args, deps) {
201
+ if (args.workflowName !== REVIEW_WORKFLOW || !args.postsCheck)
202
+ return;
203
+ if (args.route !== "attention")
204
+ return;
205
+ if (args.placement !== "queued" && args.placement !== "neutral")
206
+ return;
207
+ await postPlaceholderReviewCheck({ owner: args.owner, repo: args.repo, headSha: args.headSha }, args.placement, deps);
208
+ }
209
+ /** Point an already-open check at the run's dashboard deep link. */
210
+ export async function linkReviewCheck(ref, detailsUrl, deps) {
211
+ if (!deps.github || !detailsUrl)
212
+ return;
213
+ try {
214
+ await deps.github.updateCheckRun(ref.owner, ref.repo, ref.checkRunId, { detailsUrl });
215
+ console.log(`[check] linked check ${ref.checkRunId} → ${detailsUrl}`);
216
+ }
217
+ catch (err) {
218
+ const msg = err instanceof Error ? err.message : String(err);
219
+ console.warn(`[check] failed to set details_url on check ${ref.checkRunId}: ${msg}`);
220
+ }
221
+ }
222
+ /**
223
+ * Conclude the check for a run that has just reached a terminal status.
224
+ *
225
+ * The conclusion is read from what the run actually POSTED — the bot's review
226
+ * at the check's head SHA — rather than from the run's exit code, because a
227
+ * `succeeded` run that legitimately skipped (already reviewed, nothing to say)
228
+ * must not claim an approval it did not give. `neutral` is the honest answer
229
+ * whenever there is no verdict to report, and branch protection treats it as
230
+ * passing, so a review that failed to run never blocks a merge on its own.
231
+ *
232
+ * Idempotent enough: the persisted ref is cleared first, so a second terminal
233
+ * notification for the same run (a retry, a racing cancel) is a no-op.
234
+ */
235
+ export async function concludeReviewCheck(db, run, status, deps) {
236
+ const ref = readReviewCheck(run);
237
+ if (!ref || !deps.github)
238
+ return;
239
+ // Clear before the network call: a failed update must not leave a ref that
240
+ // re-fires on the next terminal transition of the same row.
241
+ db.runs.mergeScratch(run.id, { [REVIEW_CHECK_SCRATCH_KEY]: null });
242
+ const github = deps.github;
243
+ let conclusion = "neutral";
244
+ let title = "Review completed";
245
+ let summary = "Review complete.";
246
+ if (status === "cancelled") {
247
+ conclusion = "cancelled";
248
+ title = "Review cancelled";
249
+ summary = "The review run was cancelled before it could post a verdict.";
250
+ }
251
+ else {
252
+ let review = null;
253
+ try {
254
+ review = await github.getLatestBotReview(ref.owner, ref.repo, run.issueNumber ?? 0, ref.headSha, deps.botLogin);
255
+ }
256
+ catch (err) {
257
+ const msg = err instanceof Error ? err.message : String(err);
258
+ console.warn(`[check] could not read the posted review for check ${ref.checkRunId}: ${msg}`);
259
+ }
260
+ if (status === "failed" && !review) {
261
+ title = "Review didn't complete";
262
+ summary = "The review run failed before posting a verdict.";
263
+ }
264
+ else if (review?.state === "APPROVED") {
265
+ conclusion = "success";
266
+ title = "Review approved";
267
+ summary = review.body?.slice(0, 65000) || "Approved.";
268
+ }
269
+ else if (review?.state === "CHANGES_REQUESTED") {
270
+ conclusion = "failure";
271
+ title = "Review requested changes";
272
+ summary = review.body?.slice(0, 65000) || "Changes requested.";
273
+ }
274
+ else if (review) {
275
+ summary = review.body?.slice(0, 65000) || "Review complete.";
276
+ }
277
+ }
278
+ try {
279
+ await github.updateCheckRun(ref.owner, ref.repo, ref.checkRunId, {
280
+ status: "completed",
281
+ conclusion,
282
+ output: { title, summary },
283
+ });
284
+ console.log(`[check] Completed check ${ref.checkRunId} → ${conclusion} (run ${status})`);
285
+ }
286
+ catch (err) {
287
+ const msg = err instanceof Error ? err.message : String(err);
288
+ console.warn(`[check] failed to complete check ${ref.checkRunId}: ${msg}`);
289
+ }
290
+ }
291
+ /**
292
+ * Wire {@link concludeReviewCheck} onto every terminal run transition. Called
293
+ * once, at boot.
294
+ */
295
+ export function installReviewCheckObserver(db, deps) {
296
+ db.runs.setTerminalObserver((run, status) => {
297
+ if (!readReviewCheck(run))
298
+ return;
299
+ concludeReviewCheck(db, run, status, deps).catch((err) => {
300
+ const msg = err instanceof Error ? err.message : String(err);
301
+ console.warn(`[check] terminal conclusion failed for run ${run.id}: ${msg}`);
302
+ });
303
+ });
304
+ }
305
+ //# sourceMappingURL=review-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review-check.js","sourceRoot":"","sources":["../../src/engine/review-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAOH,wDAAw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AAK,CAAC,CAAC,GAAY,EAAE,EAAE;YAChE,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7D,OAAO,CAAC,IAAI,CAAC,8CAA8C,GAAG,CAAC,EAAE,KAAK,GAAG,EAAE,CAAC,CAAC;QAC/E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { EventEnvelope } from "../connectors/types.js";
2
+ import { type ReviewConfig } from "../config/config.js";
2
3
  import type { StateDb } from "../state/db.js";
3
4
  import type { GitHubClient } from "./github/github.js";
4
5
  /**
@@ -29,6 +30,32 @@ export interface RouterDeps {
29
30
  * comment classifies as normal.
30
31
  */
31
32
  github?: GitHubClient | null;
33
+ /**
34
+ * Resolve the target repo's `.lastlight/` POLICY layer — the SAME injected
35
+ * seam the dispatcher carries (`DispatchDeps.resolveRepoPolicy`), threaded
36
+ * one level up.
37
+ *
38
+ * Used by exactly one branch: `pr.labeled`, to learn a repo's own
39
+ * `review.requestLabel`. The router is otherwise deliberately operator-only,
40
+ * and that is the right default — routing is the operator's, and a router
41
+ * that resolves repo config on every event is a fetch per event.
42
+ *
43
+ * This one branch is different because the label route is the ONLY way a
44
+ * repo's `on-request` mode can actually be triggered (a GitHub App bot user
45
+ * cannot be picked in the reviewer dropdown), and the shipped operator
46
+ * default is `null` — so every `pr.labeled` event was dropped here before any
47
+ * repo layer was resolved, and a key documented as repo-settable on both doc
48
+ * surfaces did nothing (#256). The cost is one CACHED config resolution per
49
+ * `pr.labeled` event: `fetchRepoLayer` memoises per repo for 60 s, so it is a
50
+ * conditional request per repo per minute, far below the `resolvePrState`
51
+ * this branch's hard ignore exists to avoid.
52
+ *
53
+ * Omitted (chat-only wiring, tests) means "no repo layer" — the operator's
54
+ * value alone, which is exactly the old behaviour.
55
+ */
56
+ resolveRepoPolicy?: (workflowName: string, context: Record<string, unknown>) => Promise<{
57
+ review?: Partial<ReviewConfig>;
58
+ } | undefined>;
32
59
  }
33
60
  /**
34
61
  * Event routing — deterministic for most events, LLM-classified for comments.