lastlight-core 0.22.0 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/default.yaml +70 -2
- package/dist/config/config.d.ts +35 -0
- package/dist/config/config.js +152 -3
- package/dist/config/config.js.map +1 -1
- package/dist/config/repo-config.d.ts +7 -0
- package/dist/config/repo-config.js +15 -0
- package/dist/config/repo-config.js.map +1 -1
- package/dist/connectors/github-webhook.d.ts +17 -0
- package/dist/connectors/github-webhook.js +150 -17
- package/dist/connectors/github-webhook.js.map +1 -1
- package/dist/connectors/types.d.ts +48 -1
- package/dist/cron/dependabot-discovery.d.ts +68 -11
- package/dist/cron/dependabot-discovery.js +78 -20
- package/dist/cron/dependabot-discovery.js.map +1 -1
- package/dist/cron/jobs.d.ts +4 -0
- package/dist/cron/jobs.js +38 -4
- package/dist/cron/jobs.js.map +1 -1
- package/dist/cron/review-discovery.d.ts +33 -20
- package/dist/cron/review-discovery.js +23 -30
- package/dist/cron/review-discovery.js.map +1 -1
- package/dist/engine/agent-executor.d.ts +1 -1
- package/dist/engine/agent-executor.js +1 -1
- package/dist/engine/agent-executor.js.map +1 -1
- package/dist/engine/dispatcher.d.ts +98 -1
- package/dist/engine/dispatcher.js +248 -231
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/executors/shared.d.ts +43 -0
- package/dist/engine/executors/shared.js +65 -0
- package/dist/engine/executors/shared.js.map +1 -1
- package/dist/engine/fix-harvest.d.ts +169 -0
- package/dist/engine/fix-harvest.js +345 -0
- package/dist/engine/fix-harvest.js.map +1 -0
- package/dist/engine/fix-markers.d.ts +184 -0
- package/dist/engine/fix-markers.js +329 -0
- package/dist/engine/fix-markers.js.map +1 -0
- package/dist/engine/fix-scratch.d.ts +76 -0
- package/dist/engine/fix-scratch.js +77 -0
- package/dist/engine/fix-scratch.js.map +1 -0
- package/dist/engine/github/github.d.ts +212 -5
- package/dist/engine/github/github.js +481 -54
- package/dist/engine/github/github.js.map +1 -1
- package/dist/engine/pr-decisions.d.ts +342 -0
- package/dist/engine/pr-decisions.js +721 -0
- package/dist/engine/pr-decisions.js.map +1 -0
- package/dist/engine/pr-escalation.d.ts +152 -0
- package/dist/engine/pr-escalation.js +320 -0
- package/dist/engine/pr-escalation.js.map +1 -0
- package/dist/engine/pr-notes.d.ts +175 -0
- package/dist/engine/pr-notes.js +315 -0
- package/dist/engine/pr-notes.js.map +1 -0
- package/dist/engine/pr-state.d.ts +313 -0
- package/dist/engine/pr-state.js +515 -0
- package/dist/engine/pr-state.js.map +1 -0
- package/dist/engine/review-check.d.ts +200 -0
- package/dist/engine/review-check.js +305 -0
- package/dist/engine/review-check.js.map +1 -0
- package/dist/engine/router.d.ts +27 -0
- package/dist/engine/router.js +156 -22
- package/dist/engine/router.js.map +1 -1
- package/dist/evals-api.d.ts +7 -0
- package/dist/evals-api.js +30 -0
- package/dist/evals-api.js.map +1 -1
- package/dist/index.js +268 -20
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +13 -0
- package/dist/sandbox/index.js +30 -0
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/k8s/init-clone.d.ts +5 -0
- package/dist/sandbox/k8s/init-clone.js +27 -0
- package/dist/sandbox/k8s/init-clone.js.map +1 -1
- package/dist/state/execution-store.d.ts +27 -0
- package/dist/state/execution-store.js +45 -0
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +73 -0
- package/dist/state/workflow-run-store.js +106 -24
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/workflows/pr-scope.d.ts +63 -0
- package/dist/workflows/pr-scope.js +113 -0
- package/dist/workflows/pr-scope.js.map +1 -0
- package/dist/workflows/resume.js +17 -4
- package/dist/workflows/resume.js.map +1 -1
- package/dist/workflows/simple.d.ts +94 -1
- package/dist/workflows/simple.js +206 -3
- package/dist/workflows/simple.js.map +1 -1
- package/dist/workflows/target-policy.d.ts +0 -12
- package/dist/workflows/target-policy.js +9 -15
- package/dist/workflows/target-policy.js.map +1 -1
- package/package.json +4 -4
- package/skills/README.md +11 -5
- package/skills/dependency-impact/SKILL.md +83 -0
- package/skills/fixing/SKILL.md +194 -0
- package/skills/pr-comment/SKILL.md +4 -1
- package/skills/pr-review/SKILL.md +26 -9
- package/workflows/cron-dependabot-ci-fix.yaml +8 -5
- package/workflows/cron-review.yaml +14 -5
- package/workflows/dependabot-ci-fix.yaml +86 -2
- package/workflows/dependabot-pr-merge.yaml +13 -1
- package/workflows/pr-fix.yaml +84 -1
- package/workflows/pr-review.yaml +7 -0
- package/workflows/prompts/dependabot-ci-fix.md +70 -17
- package/workflows/prompts/dependabot-pr-merge.md +209 -81
- package/workflows/prompts/diagnose-ci.md +96 -0
- package/workflows/prompts/pr-fix.md +63 -4
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The marker harvest — the impure half of `./fix-markers.ts` AND of
|
|
3
|
+
* `./pr-notes.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Two things a fix run leaves behind travel this way, and they ride the same
|
|
6
|
+
* `onPhaseEnd` hook on purpose: the two marker lines the agent emits in its
|
|
7
|
+
* OUTPUT, and the journal it appends to a FILE in the checkout
|
|
8
|
+
* (10-pr-memory.md). One hook, one scratch namespace, one merge — a second hook
|
|
9
|
+
* would be a second thing to wire at three call sites and a second thing to
|
|
10
|
+
* forget to wire at the fourth.
|
|
11
|
+
*
|
|
12
|
+
* A fix run's only durable output, besides the commit it may or may not have
|
|
13
|
+
* pushed, is the pair of marker lines the agent emits. Nothing else survives
|
|
14
|
+
* the run boundary: `{{phaseOutputs}}` is empty across runs, and the shared
|
|
15
|
+
* per-PR workspace is `reset --hard`-ed between them. So the harness reads the
|
|
16
|
+
* markers out of each phase's output as it completes and persists them on the
|
|
17
|
+
* run's `scratch`, where the NEXT dispatch's `applyDerivedState` reads them
|
|
18
|
+
* back off `latestForTrigger` (04-retry.md §4.2, 09-state-machine.md §S1).
|
|
19
|
+
*
|
|
20
|
+
* ## Why `scratch` and not `context`
|
|
21
|
+
*
|
|
22
|
+
* `context.prState` is the resolved snapshot, and it is written at DISPATCH —
|
|
23
|
+
* before any phase runs. The harvest is a post-hoc fact about the run that
|
|
24
|
+
* dispatch produced, so it cannot go there without rewriting the record of
|
|
25
|
+
* what the dispatch decision was actually taken on. `scratch` is the run's
|
|
26
|
+
* mutable phase-to-phase channel and already rides back on the same
|
|
27
|
+
* `latestForTrigger` row, so the transport costs no new column, no new query
|
|
28
|
+
* and no second write path.
|
|
29
|
+
*
|
|
30
|
+
* ## Two traps this module exists to absorb
|
|
31
|
+
*
|
|
32
|
+
* - **`phase` is a LABEL, not a phase name.** A `generic_loop` iteration
|
|
33
|
+
* arrives as `fix_iter_1` / `fix_iter_2`, a soft retry as `fix_iter_1_retry`.
|
|
34
|
+
* Keying on `phase === "fix"` would silently harvest nothing the moment the
|
|
35
|
+
* gate loop lands. This module does not key on the phase at all — the marker
|
|
36
|
+
* lines are self-identifying, so every phase of a fix-shaped workflow is
|
|
37
|
+
* scanned and the LAST marker of each kind wins (which is also the right
|
|
38
|
+
* answer for a loop: iteration 2 supersedes iteration 1).
|
|
39
|
+
* - **`mergeScratch` is a TOP-LEVEL shallow merge.** Writing
|
|
40
|
+
* `{ fixMarkers: { diagnosis } }` after a previous write of
|
|
41
|
+
* `{ fixMarkers: { fix } }` would drop the first. Every write here therefore
|
|
42
|
+
* re-reads the namespace and merges into it.
|
|
43
|
+
*/
|
|
44
|
+
import { closeSync, openSync, readFileSync, readSync, rmSync, statSync } from "fs";
|
|
45
|
+
import { join, resolve, sep } from "path";
|
|
46
|
+
import { getRuntimeConfig } from "../config/config.js";
|
|
47
|
+
import { sandboxRoot } from "../sandbox/reap.js";
|
|
48
|
+
import { PR_FIX_SHAPED_WORKFLOWS } from "../workflows/target-policy.js";
|
|
49
|
+
import { parseAttemptMarkers, } from "./fix-markers.js";
|
|
50
|
+
import { PR_NOTES_FILE_NAME, VERIFY_SCRIPT_NAME } from "./fix-scratch.js";
|
|
51
|
+
import { boundNotes, coerceNotes, parseNoteFile, } from "./pr-notes.js";
|
|
52
|
+
/**
|
|
53
|
+
* The `scratch` key the harvest owns.
|
|
54
|
+
*
|
|
55
|
+
* Deliberately NOT `fix`: a `generic_loop` declares its own `scratch_key` in
|
|
56
|
+
* YAML, `fix` is the obvious name for the gate loop's slot, and both would be
|
|
57
|
+
* merged into the same top-level object by `mergeScratch`.
|
|
58
|
+
*/
|
|
59
|
+
export const FIX_HARVEST_SCRATCH_KEY = "fixMarkers";
|
|
60
|
+
/**
|
|
61
|
+
* Strip the engine's generated loop suffixes off a phase label.
|
|
62
|
+
*
|
|
63
|
+
* `fix_iter_2` → `fix`, `fix_iter_2_retry` → `fix`, `review_recheck_1` →
|
|
64
|
+
* `review`. Used only for the recorded {@link HarvestedFixMarkers.phases}
|
|
65
|
+
* breadcrumb — the harvest itself is label-agnostic on purpose.
|
|
66
|
+
*/
|
|
67
|
+
export function phaseBase(label) {
|
|
68
|
+
return label
|
|
69
|
+
.replace(/_iter_\d+_retry$/, "")
|
|
70
|
+
.replace(/_iter_\d+$/, "")
|
|
71
|
+
.replace(/_fix_\d+$/, "")
|
|
72
|
+
.replace(/_recheck_\d+$/, "");
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Read a run row's harvested markers, or null when the run has none.
|
|
76
|
+
*
|
|
77
|
+
* Tolerates every shape a `scratch` column can hold, including rows written
|
|
78
|
+
* before this key existed — `null` means "nothing was harvested here", which
|
|
79
|
+
* callers must be able to tell from "harvested, and there was no marker".
|
|
80
|
+
*/
|
|
81
|
+
export function readHarvestedMarkers(run) {
|
|
82
|
+
const slot = run?.scratch?.[FIX_HARVEST_SCRATCH_KEY];
|
|
83
|
+
if (!slot || typeof slot !== "object" || Array.isArray(slot))
|
|
84
|
+
return null;
|
|
85
|
+
const raw = slot;
|
|
86
|
+
return {
|
|
87
|
+
diagnosis: raw.diagnosis ?? null,
|
|
88
|
+
fix: raw.fix ?? null,
|
|
89
|
+
phases: Array.isArray(raw.phases) ? raw.phases.filter((p) => typeof p === "string") : [],
|
|
90
|
+
at: typeof raw.at === "string" ? raw.at : "",
|
|
91
|
+
notes: coerceNotes(raw.notes),
|
|
92
|
+
verifyScript: typeof raw.verifyScript === "string" ? raw.verifyScript : null,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// The journal — where it lives, and why not `../`
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
/**
|
|
99
|
+
* The journal is a file inside the checkout's own `.git/` directory
|
|
100
|
+
* (`<workspace>/<repo>/.git/lastlight-notes`) on EVERY backend.
|
|
101
|
+
*
|
|
102
|
+
* That is deliberately the same resolution `.git/lastlight-verify.sh` reached
|
|
103
|
+
* (`./executors/shared.ts` → the push gate), and for the same reasons — with one
|
|
104
|
+
* extra:
|
|
105
|
+
*
|
|
106
|
+
* 1. **Git structurally cannot see it.** `.git/` is the repository, not the
|
|
107
|
+
* work tree; no pathspec walk enters it, so `git add -A` cannot commit the
|
|
108
|
+
* journal on any backend, in any `buildAssets` mode, with nothing to
|
|
109
|
+
* register anywhere. That last clause is the whole point: the journal used
|
|
110
|
+
* to sit at the checkout root and depend on each backend adding it to the
|
|
111
|
+
* local `.git/info/exclude`, and the kubernetes backend never got that code
|
|
112
|
+
* (#256). A guarantee that every new backend must re-implement is not a
|
|
113
|
+
* guarantee.
|
|
114
|
+
* 2. **gondolin is the packaged default** (`sandbox.backend: gondolin`) and
|
|
115
|
+
* mounts only cwd, so a workspace-root sibling reached via `../` is simply
|
|
116
|
+
* unreachable inside the guest. A `../` journal would silently never be
|
|
117
|
+
* written on the default backend — the worst possible failure mode for a
|
|
118
|
+
* memory feature, because it looks like "the agent had nothing to say".
|
|
119
|
+
* `.git/` is inside cwd, so it is reachable there.
|
|
120
|
+
* 3. **One uniform path is what makes the prompt and the harvest agree.** The
|
|
121
|
+
* agent is told a bare relative path with its cwd already the checkout; the
|
|
122
|
+
* harvest resolves the same path from the run row. Neither has to know the
|
|
123
|
+
* backend, which is exactly what `artifactIssueDir` DOES have to know — its
|
|
124
|
+
* relocation is conditional on `buildAssets === "server"` AND a non-gondolin
|
|
125
|
+
* backend, so it is not reusable here.
|
|
126
|
+
*
|
|
127
|
+
* `git clean -fdx -e node_modules` on a cross-run workspace refresh does NOT
|
|
128
|
+
* reach inside `.git/`, so the explicit `resetPrNotesJournal` delete is the only
|
|
129
|
+
* thing that clears a file a crashed run left behind — which is the point of it
|
|
130
|
+
* existing. The journal is DRAINED into the run's scratch at the end of every
|
|
131
|
+
* phase, so its durable home is the snapshot either way.
|
|
132
|
+
*/
|
|
133
|
+
function isWithin(parent, child) {
|
|
134
|
+
return child === parent || child.startsWith(`${parent}${sep}`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Host path to the checkout a run's journal lives in, or null when the run has
|
|
138
|
+
* no workspace we can name.
|
|
139
|
+
*
|
|
140
|
+
* Resolved from the run row exactly as `createTaskSandbox` / `reapSandboxWorkspace`
|
|
141
|
+
* resolve it — `<sandboxes root>/<taskId>/<repo>` — so the three never disagree.
|
|
142
|
+
* `taskId` and `repo` are both persisted on `workflow_runs.context` at creation.
|
|
143
|
+
* A taskId that escapes the sandboxes root is refused rather than followed, the
|
|
144
|
+
* same guard the reaper applies.
|
|
145
|
+
*/
|
|
146
|
+
export function prNotesRepoDir(run, overrides = {}) {
|
|
147
|
+
const ctx = run?.context;
|
|
148
|
+
const taskId = typeof ctx?.taskId === "string" ? ctx.taskId : "";
|
|
149
|
+
const repo = typeof ctx?.repo === "string" ? ctx.repo : "";
|
|
150
|
+
if (!taskId || !repo)
|
|
151
|
+
return null;
|
|
152
|
+
const rt = getRuntimeConfig();
|
|
153
|
+
const stateDir = overrides.stateDir || rt?.stateDir || process.env.STATE_DIR || "data";
|
|
154
|
+
const base = sandboxRoot(stateDir, overrides.sandboxDir ?? rt?.sandboxDir);
|
|
155
|
+
const dir = resolve(base, taskId, repo);
|
|
156
|
+
if (!isWithin(base, dir))
|
|
157
|
+
return null;
|
|
158
|
+
return dir;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Cap on how much of the journal file is read.
|
|
162
|
+
*
|
|
163
|
+
* The file is written by a language model inside a sandbox, so "it will be a
|
|
164
|
+
* handful of lines" is a hope, not a bound. Reading only the TAIL keeps a
|
|
165
|
+
* runaway loop that appended a gigabyte from being pulled into the harness
|
|
166
|
+
* process, and the tail is the right end to keep: notes are appended, so the
|
|
167
|
+
* newest are last — the same "keep the newest" rule the cap itself uses.
|
|
168
|
+
*/
|
|
169
|
+
const MAX_NOTES_FILE_BYTES = 64 * 1024;
|
|
170
|
+
/** Read at most the last {@link MAX_NOTES_FILE_BYTES} of a file, or null. */
|
|
171
|
+
function readTail(path) {
|
|
172
|
+
let size;
|
|
173
|
+
try {
|
|
174
|
+
size = statSync(path).size;
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return null; // no journal — the overwhelmingly common case
|
|
178
|
+
}
|
|
179
|
+
if (size <= MAX_NOTES_FILE_BYTES) {
|
|
180
|
+
try {
|
|
181
|
+
return readFileSync(path, "utf8");
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
let fd;
|
|
188
|
+
try {
|
|
189
|
+
fd = openSync(path, "r");
|
|
190
|
+
const buf = Buffer.alloc(MAX_NOTES_FILE_BYTES);
|
|
191
|
+
const read = readSync(fd, buf, 0, MAX_NOTES_FILE_BYTES, size - MAX_NOTES_FILE_BYTES);
|
|
192
|
+
// Drop the first (probably partial) line rather than parsing half a note.
|
|
193
|
+
return buf.subarray(0, read).toString("utf8").replace(/^[^\n]*\n/, "");
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
if (fd !== undefined) {
|
|
200
|
+
try {
|
|
201
|
+
closeSync(fd);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
/* nothing useful to do */
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Cap on how much of the gate script is recorded.
|
|
211
|
+
*
|
|
212
|
+
* Smaller than the journal's cap and taken from the HEAD rather than the tail:
|
|
213
|
+
* a shell script is read top-down, and the interesting part of a runaway one is
|
|
214
|
+
* where it starts, not where it ends.
|
|
215
|
+
*/
|
|
216
|
+
const MAX_VERIFY_SCRIPT_BYTES = 8 * 1024;
|
|
217
|
+
/**
|
|
218
|
+
* Read the push gate the agent wrote for itself, or null when it wrote none.
|
|
219
|
+
*
|
|
220
|
+
* A READ, not a drain (`drainPrNotes` below is the drain): the same file is the
|
|
221
|
+
* live gate `generic_loop.until_bash` runs on the next iteration, so removing
|
|
222
|
+
* it would disarm the loop this harvest is reporting on. The reset that DOES
|
|
223
|
+
* clear it happens once per attempt, at the start, in `./executors/shared.ts`.
|
|
224
|
+
*
|
|
225
|
+
* Never throws: a failed read must not fail the phase that produced it.
|
|
226
|
+
*/
|
|
227
|
+
export function readVerifyScript(repoDir) {
|
|
228
|
+
const path = join(repoDir, VERIFY_SCRIPT_NAME);
|
|
229
|
+
try {
|
|
230
|
+
const body = readFileSync(path, "utf8");
|
|
231
|
+
if (!body.trim())
|
|
232
|
+
return null;
|
|
233
|
+
return body.length > MAX_VERIFY_SCRIPT_BYTES
|
|
234
|
+
? `${body.slice(0, MAX_VERIFY_SCRIPT_BYTES)}\n… truncated at ${MAX_VERIFY_SCRIPT_BYTES} bytes`
|
|
235
|
+
: body;
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return null; // no gate written yet — the state every run starts in
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Read the journal and DELETE it — a drain, not a read.
|
|
243
|
+
*
|
|
244
|
+
* The delete is what makes the file a per-phase outbox rather than an
|
|
245
|
+
* accumulator: the harvest runs after every phase, and a file left in place
|
|
246
|
+
* would re-contribute `diagnose`'s notes at the end of `fix`. (`boundNotes`
|
|
247
|
+
* de-duplicates, so a failed delete degrades to "nothing new", never to a
|
|
248
|
+
* duplicated journal.)
|
|
249
|
+
*
|
|
250
|
+
* Never throws: a failed drain must not fail the phase that produced it.
|
|
251
|
+
*/
|
|
252
|
+
export function drainPrNotes(repoDir, provenance) {
|
|
253
|
+
const path = join(repoDir, PR_NOTES_FILE_NAME);
|
|
254
|
+
const body = readTail(path);
|
|
255
|
+
if (body === null)
|
|
256
|
+
return [];
|
|
257
|
+
try {
|
|
258
|
+
rmSync(path, { force: true });
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
/* de-duplication covers a file we could not remove */
|
|
262
|
+
}
|
|
263
|
+
return parseNoteFile(body, provenance);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Harvest whatever markers `output` carries — and whatever notes the checkout's
|
|
267
|
+
* journal carries — onto the run's scratch.
|
|
268
|
+
*
|
|
269
|
+
* Wired into `RunnerCallbacks.onPhaseEnd` at all THREE of its call sites —
|
|
270
|
+
* `index.ts` (fresh dispatch) plus both of `resume.ts`'s (GitHub and Slack
|
|
271
|
+
* resume). Harvesting only in the first would silently lose every marker on a
|
|
272
|
+
* run that paused for an approval gate or was resumed after a restart, which
|
|
273
|
+
* is precisely the population whose attempt counter matters most.
|
|
274
|
+
*
|
|
275
|
+
* Never throws: a failed harvest must not fail the phase that produced the
|
|
276
|
+
* output it was reading.
|
|
277
|
+
*/
|
|
278
|
+
export function harvestFixMarkers(db, runId, workflowName, phase, output,
|
|
279
|
+
/** Test seam: the checkout to drain the journal from, bypassing the run row. */
|
|
280
|
+
overrides = {}) {
|
|
281
|
+
// Only the fix family carries the MARKERS, and only it reads them back. The
|
|
282
|
+
// JOURNAL is wider — see the gate below — so this is no longer an early
|
|
283
|
+
// return for the whole function.
|
|
284
|
+
const wantsMarkers = PR_FIX_SHAPED_WORKFLOWS.has(workflowName);
|
|
285
|
+
try {
|
|
286
|
+
const run = db.runs.getRun(runId);
|
|
287
|
+
// Which runs may write a note? Every PR-SCOPED one — `pr-review` reading
|
|
288
|
+
// what `dependabot-ci-fix` learned is the point of keying on the PR
|
|
289
|
+
// (10-pr-memory.md). Rather than import a second workflow-name set (which
|
|
290
|
+
// would put this module and `./pr-state.ts` in an import cycle), the gate
|
|
291
|
+
// reads the fact at its source: a run carries `context.prState` iff the
|
|
292
|
+
// dispatcher resolved a snapshot for it, which is exactly the definition of
|
|
293
|
+
// PR-scoped. It therefore tracks `prScopedWorkflows()` automatically as
|
|
294
|
+
// that set changes — including a workflow an operator adds by declaring
|
|
295
|
+
// `pr_scoped: true` in an overlay.
|
|
296
|
+
const wantsNotes = !!run?.context?.prState;
|
|
297
|
+
if (!wantsMarkers && !wantsNotes)
|
|
298
|
+
return;
|
|
299
|
+
const parsed = wantsMarkers ? parseAttemptMarkers(output ?? "") : {};
|
|
300
|
+
const current = readHarvestedMarkers(run);
|
|
301
|
+
const base = phaseBase(phase);
|
|
302
|
+
const phases = current?.phases ?? [];
|
|
303
|
+
const at = new Date().toISOString();
|
|
304
|
+
let notes = current?.notes ?? [];
|
|
305
|
+
// The gate script is recorded for the FIX FAMILY only — it is the only
|
|
306
|
+
// family that writes one. Its last non-null reading stands: the file is
|
|
307
|
+
// reset once per attempt, not per phase, so a later phase that cannot see
|
|
308
|
+
// the workspace must not blank the gate an earlier one recorded.
|
|
309
|
+
let verifyScript = current?.verifyScript ?? null;
|
|
310
|
+
if (wantsNotes || wantsMarkers) {
|
|
311
|
+
const repoDir = overrides.repoDir !== undefined ? overrides.repoDir : prNotesRepoDir(run);
|
|
312
|
+
if (repoDir) {
|
|
313
|
+
if (wantsNotes) {
|
|
314
|
+
const fresh = drainPrNotes(repoDir, { at, runId, workflow: workflowName, phase });
|
|
315
|
+
if (fresh.length > 0)
|
|
316
|
+
notes = boundNotes([...notes, ...fresh]);
|
|
317
|
+
}
|
|
318
|
+
if (wantsMarkers)
|
|
319
|
+
verifyScript = readVerifyScript(repoDir) ?? verifyScript;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// A PR-scoped run that is not fix-shaped and wrote no note has nothing to
|
|
323
|
+
// record — leave its scratch untouched rather than stamping an empty
|
|
324
|
+
// namespace on every `pr-review` phase.
|
|
325
|
+
if (!wantsMarkers && notes.length === 0)
|
|
326
|
+
return;
|
|
327
|
+
const next = {
|
|
328
|
+
// Last marker of each kind wins. A `generic_loop` iteration 2 supersedes
|
|
329
|
+
// iteration 1; a phase that emitted nothing leaves the earlier value
|
|
330
|
+
// standing rather than blanking it.
|
|
331
|
+
diagnosis: parsed.diagnosis ?? current?.diagnosis ?? null,
|
|
332
|
+
fix: parsed.fix ?? current?.fix ?? null,
|
|
333
|
+
phases: phases.includes(base) ? phases : [...phases, base],
|
|
334
|
+
at,
|
|
335
|
+
notes,
|
|
336
|
+
verifyScript,
|
|
337
|
+
};
|
|
338
|
+
db.runs.mergeScratch(runId, { [FIX_HARVEST_SCRATCH_KEY]: next });
|
|
339
|
+
}
|
|
340
|
+
catch (err) {
|
|
341
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
342
|
+
console.warn(`[fix-harvest] ${workflowName}/${phase} run ${runId}: ${msg}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
//# sourceMappingURL=fix-harvest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix-harvest.js","sourceRoot":"","sources":["../../src/engine/fix-harvest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACnF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MA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CAAC,uBAAuB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,CAAC,iBAAiB,YAAY,IAAI,KAAK,QAAQ,KAAK,KAAK,GAAG,EAAE,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two fix-family marker grammars, parsed.
|
|
3
|
+
*
|
|
4
|
+
* `skills/fixing/SKILL.md` asks the agent to end the `diagnose` and `fix`
|
|
5
|
+
* phases with exactly one machine-readable line:
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* DIAGNOSIS_COMPLETE: pr=<N> attempt=<K> class=<…> cause=<one line> ci_vs_local=<one line> unreproducible=<a,b>
|
|
9
|
+
* CI_FIX_COMPLETE: pr=<N> attempt=<K> outcome=<pushed|no-change|gave-up> tried=<one line> gate=<green|red|skipped>
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Those lines are the ONLY thing that survives a run boundary:
|
|
13
|
+
* `{{phaseOutputs}}` is empty across runs and the per-PR workspace is
|
|
14
|
+
* `reset --hard`-ed between them, so cross-attempt memory has to be small and
|
|
15
|
+
* persisted (04-retry.md §4.2). One parsed line per attempt is replayed into
|
|
16
|
+
* every later attempt's prompt, and the `class=` token decides whether an
|
|
17
|
+
* attempt was spent at all (09-state-machine.md §S1).
|
|
18
|
+
*
|
|
19
|
+
* Three properties this module is written for, in priority order:
|
|
20
|
+
*
|
|
21
|
+
* 1. **It can never throw.** A malformed marker is agent output, which is to
|
|
22
|
+
* say untrusted text produced under time pressure by a language model. It
|
|
23
|
+
* must degrade to "we learned nothing from this run", never to a crashed
|
|
24
|
+
* harvest that fails the run that produced it.
|
|
25
|
+
* 2. **Values are free text, not tokens.** `cause=` is a sentence and may
|
|
26
|
+
* contain `=` and spaces, so the fields are split on the NEXT KNOWN KEY
|
|
27
|
+
* rather than on whitespace. Naive whitespace splitting truncates every
|
|
28
|
+
* cause to its first word.
|
|
29
|
+
* 3. **An unrecognised enum value is `null`, never coerced.** `class=probably-flaky`
|
|
30
|
+
* must not silently become `flaky` and defer the PR forever; it is an
|
|
31
|
+
* unknown class, which the deferral counter treats as "not flaky".
|
|
32
|
+
*
|
|
33
|
+
* Pure: no I/O, no clock, no DB. `./fix-harvest.ts` is the impure half.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* The five diagnosis classes (09 → S1, `skills/fixing/SKILL.md`).
|
|
37
|
+
*
|
|
38
|
+
* Defined in `lastlight-shared` and re-exported here, where every reader of the
|
|
39
|
+
* marker grammar looks for them. They moved because `fix.retryableClasses` is a
|
|
40
|
+
* config leaf naming members of this enum, and both places that validate it —
|
|
41
|
+
* the boot normaliser in core and the repo-layer clamp compiled into the CLI —
|
|
42
|
+
* need it. `shared` is the only package both may reach, and a second hand-kept
|
|
43
|
+
* copy of a closed enum is exactly how `retryableClasses` came to accept
|
|
44
|
+
* `reproducable` in the first place (#256).
|
|
45
|
+
*/
|
|
46
|
+
import { DIAGNOSIS_CLASSES, isDiagnosisClass, type DiagnosisClass } from "lastlight-shared/config-types";
|
|
47
|
+
export { DIAGNOSIS_CLASSES, isDiagnosisClass, type DiagnosisClass };
|
|
48
|
+
/**
|
|
49
|
+
* The two classes that cost NO attempt, per 09-state-machine.md §S1's class
|
|
50
|
+
* table.
|
|
51
|
+
*
|
|
52
|
+
* - `flaky` — by its own definition there is nothing to fix, so it never
|
|
53
|
+
* reaches the `fix` phase. It is bounded by `fix.maxFlakyDeferrals` instead,
|
|
54
|
+
* and that cap only exists BECAUSE it does not spend an attempt; if it did,
|
|
55
|
+
* `maxAttempts` would already bound it and the counter would be dead code.
|
|
56
|
+
* - `upstream-broken` — not this PR's fault. It self-heals the moment the base
|
|
57
|
+
* goes green, and charging the PR for its base branch being red would leave
|
|
58
|
+
* it with no attempts left at the moment it becomes fixable.
|
|
59
|
+
*
|
|
60
|
+
* `infra-dependent` is deliberately NOT here: it costs an attempt and escalates
|
|
61
|
+
* immediately, which is the whole point of not spending the other two on it.
|
|
62
|
+
*/
|
|
63
|
+
export declare const ATTEMPT_FREE_CLASSES: ReadonlySet<DiagnosisClass>;
|
|
64
|
+
/** What the `fix` phase did with the diagnosis. */
|
|
65
|
+
export declare const FIX_OUTCOMES: readonly ["pushed", "no-change", "gave-up"];
|
|
66
|
+
export type FixOutcome = (typeof FIX_OUTCOMES)[number];
|
|
67
|
+
/**
|
|
68
|
+
* The local gate's verdict. `skipped` means no gate ran — which 09 → S1 is
|
|
69
|
+
* explicit never authorises a push, so it is a distinct value rather than
|
|
70
|
+
* being folded into `red`.
|
|
71
|
+
*/
|
|
72
|
+
export declare const GATE_RESULTS: readonly ["green", "red", "skipped"];
|
|
73
|
+
export type GateResult = (typeof GATE_RESULTS)[number];
|
|
74
|
+
/** A parsed `DIAGNOSIS_COMPLETE` line. Every field degrades independently. */
|
|
75
|
+
export interface DiagnosisMarker {
|
|
76
|
+
/** PR number the agent believed it was working on, or null when unparseable. */
|
|
77
|
+
pr: number | null;
|
|
78
|
+
/** Attempt number the agent was told it was on. Advisory — ours is authoritative. */
|
|
79
|
+
attempt: number | null;
|
|
80
|
+
/** One of {@link DIAGNOSIS_CLASSES}, or null when absent OR unrecognised. */
|
|
81
|
+
class: DiagnosisClass | null;
|
|
82
|
+
/** The raw `class=` token as written, so an unknown value stays inspectable. */
|
|
83
|
+
rawClass: string | null;
|
|
84
|
+
/** Why CI failed. Free text, clamped. */
|
|
85
|
+
cause: string;
|
|
86
|
+
/** What differs between CI and the sandbox. Free text, clamped. */
|
|
87
|
+
ciVsLocal: string;
|
|
88
|
+
/** Check names the agent could not reproduce here. */
|
|
89
|
+
unreproducible: string[];
|
|
90
|
+
}
|
|
91
|
+
/** A parsed `CI_FIX_COMPLETE` line. */
|
|
92
|
+
export interface FixOutcomeMarker {
|
|
93
|
+
pr: number | null;
|
|
94
|
+
attempt: number | null;
|
|
95
|
+
/** One of {@link FIX_OUTCOMES}, or null when absent OR unrecognised. */
|
|
96
|
+
outcome: FixOutcome | null;
|
|
97
|
+
rawOutcome: string | null;
|
|
98
|
+
/** What the agent tried. Free text, clamped. */
|
|
99
|
+
tried: string;
|
|
100
|
+
/** One of {@link GATE_RESULTS}, or null when absent OR unrecognised. */
|
|
101
|
+
gate: GateResult | null;
|
|
102
|
+
rawGate: string | null;
|
|
103
|
+
}
|
|
104
|
+
/** The pair of markers one attempt can produce. */
|
|
105
|
+
export interface AttemptMarkers {
|
|
106
|
+
diagnosis?: DiagnosisMarker | null;
|
|
107
|
+
fix?: FixOutcomeMarker | null;
|
|
108
|
+
}
|
|
109
|
+
export declare const DIAGNOSIS_MARKER = "DIAGNOSIS_COMPLETE";
|
|
110
|
+
export declare const CI_FIX_MARKER = "CI_FIX_COMPLETE";
|
|
111
|
+
/**
|
|
112
|
+
* What a fix phase's `on_output.requires_marker` must name — the tag **with its
|
|
113
|
+
* colon**, which is the same string {@link lastMarkerLine} looks for.
|
|
114
|
+
*
|
|
115
|
+
* The engine enforces the postcondition as a bare `output.includes(marker)`, so
|
|
116
|
+
* declaring the tag alone made the gate and the parser disagree about what a
|
|
117
|
+
* marker IS. An output that merely *mentions* `DIAGNOSIS_COMPLETE` — an agent
|
|
118
|
+
* narrating "I'll close with DIAGNOSIS_COMPLETE" and then not, or fencing the
|
|
119
|
+
* word in prose — passed the postcondition and parsed to nothing. The phase went
|
|
120
|
+
* green, the harvest recorded a diagnosis of `null`, and the attempt counter
|
|
121
|
+
* never advanced: the PR sat at attempt 1 for its whole life with
|
|
122
|
+
* `fix.maxCostUsd` as the only remaining brake.
|
|
123
|
+
*
|
|
124
|
+
* Requiring the parseable form instead makes a malformed marker fail the phase
|
|
125
|
+
* loudly, which is what a postcondition is for. Exported so the YAML can be
|
|
126
|
+
* asserted against it rather than against a hand-copied literal.
|
|
127
|
+
*/
|
|
128
|
+
export declare const DIAGNOSIS_MARKER_POSTCONDITION = "DIAGNOSIS_COMPLETE:";
|
|
129
|
+
export declare const CI_FIX_MARKER_POSTCONDITION = "CI_FIX_COMPLETE:";
|
|
130
|
+
/** Longest whole rendered attempt line. */
|
|
131
|
+
export declare const MAX_ATTEMPT_LINE_CHARS = 200;
|
|
132
|
+
/** How many rendered attempt lines {@link boundAttemptLines} keeps. */
|
|
133
|
+
export declare const MAX_PRIOR_ATTEMPT_LINES = 6;
|
|
134
|
+
/**
|
|
135
|
+
* The LAST line of `output` that carries `<tag>:`, with everything up to and
|
|
136
|
+
* including the tag stripped.
|
|
137
|
+
*
|
|
138
|
+
* The skill says the marker is the last line, and this deliberately does not
|
|
139
|
+
* insist on it. Two real shapes break a strict last-line read: an agent that
|
|
140
|
+
* fences the marker in backticks or prefixes it with a bullet, and a
|
|
141
|
+
* `generic_loop` iteration whose `{{previousOutput}}` replays the PREVIOUS
|
|
142
|
+
* iteration's marker earlier in the same text. Scanning backwards and taking
|
|
143
|
+
* the last hit handles both — the genuine final marker always wins.
|
|
144
|
+
*/
|
|
145
|
+
export declare function lastMarkerLine(output: string, tag: string): string | null;
|
|
146
|
+
/**
|
|
147
|
+
* Parse the last `DIAGNOSIS_COMPLETE` line out of a phase's full output.
|
|
148
|
+
*
|
|
149
|
+
* Returns null when there is no marker at all — which is a MEANINGFUL answer,
|
|
150
|
+
* not an error: a run with no `DIAGNOSIS_COMPLETE` spent no attempt (09 → S1,
|
|
151
|
+
* "a crashed run must not consume budget").
|
|
152
|
+
*/
|
|
153
|
+
export declare function parseDiagnosisMarker(output: string): DiagnosisMarker | null;
|
|
154
|
+
/** Parse the last `CI_FIX_COMPLETE` line out of a phase's full output. */
|
|
155
|
+
export declare function parseFixOutcomeMarker(output: string): FixOutcomeMarker | null;
|
|
156
|
+
/** Parse both markers out of one phase output. Either half may be null. */
|
|
157
|
+
export declare function parseAttemptMarkers(output: string): AttemptMarkers;
|
|
158
|
+
/**
|
|
159
|
+
* The single line attempt N leaves behind for attempts N+1, N+2, …
|
|
160
|
+
*
|
|
161
|
+
* ```
|
|
162
|
+
* attempt 2: class=env-mismatch cause=CI runs node 22, sandbox node 20 | outcome=pushed gate=green
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* One line per attempt, not a transcript — attempt 3 needs to know what was
|
|
166
|
+
* tried and what was ruled out, not to re-read two agent sessions. `tried=` is
|
|
167
|
+
* deliberately NOT rendered: `cause=` plus `outcome=` already answer "what was
|
|
168
|
+
* wrong and did the fix land", and the whole line is replayed into every later
|
|
169
|
+
* prompt, so each extra clause is paid for on every subsequent attempt.
|
|
170
|
+
*
|
|
171
|
+
* Returns null when the attempt produced no marker at all — a crashed run
|
|
172
|
+
* leaves no line, exactly as it consumes no attempt.
|
|
173
|
+
*/
|
|
174
|
+
export declare function renderAttemptLine(attempt: number, markers: AttemptMarkers | null): string | null;
|
|
175
|
+
/**
|
|
176
|
+
* Keep the journal bounded: at most {@link MAX_PRIOR_ATTEMPT_LINES} lines,
|
|
177
|
+
* newest kept, oldest dropped, order preserved.
|
|
178
|
+
*
|
|
179
|
+
* A PR can accumulate more RUNS than `fix.maxAttempts` — a `flaky` deferral
|
|
180
|
+
* spends no attempt, and the daily `fix-red-dependency-prs` cron re-picks the
|
|
181
|
+
* PR up every day — so the array needs its own bound rather than inheriting
|
|
182
|
+
* the attempt cap's.
|
|
183
|
+
*/
|
|
184
|
+
export declare function boundAttemptLines(lines: string[]): string[];
|