@mergelight/cli 0.1.18 → 0.1.20
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/dist/answer.js +85 -0
- package/dist/cli.js +228 -21
- package/dist/cloud.js +3 -2
- package/dist/connect-claude.js +17 -4
- package/dist/connect.js +363 -50
- package/dist/github.js +5 -0
- package/dist/jobs-command.js +182 -0
- package/dist/jobs.js +437 -0
- package/dist/prompt.js +49 -6
- package/dist/providers/claude.js +25 -5
- package/dist/providers/codex.js +280 -11
- package/dist/publish/api.js +4 -2
- package/dist/publish/closed.js +1 -1
- package/dist/publish/handled.js +13 -7
- package/dist/publish/markdown.js +100 -5
- package/dist/publish/publish.js +106 -19
- package/dist/publish/state.js +2 -1
- package/dist/push-jobs.js +381 -0
- package/dist/render.js +5 -0
- package/dist/repo-rules.js +62 -19
- package/dist/review.js +66 -20
- package/dist/run-jobs.js +522 -0
- package/dist/schema.js +5 -0
- package/dist/setup.js +11 -7
- package/dist/types.js +6 -1
- package/dist/update.js +2 -1
- package/dist/workspace.js +457 -21
- package/package.json +1 -1
- package/scripts/refresh-login.mjs +123 -2
- package/scripts/save-login.sh +2 -0
- package/templates/mergelight-jobs.yml +137 -0
- package/templates/mergelight.yml +15 -4
package/dist/review.js
CHANGED
|
@@ -4,12 +4,14 @@ import { join } from "node:path";
|
|
|
4
4
|
import { actionsUsedBy, fetchActionSources, notRead } from "./action-source.js";
|
|
5
5
|
import { fetchPullRequest } from "./github.js";
|
|
6
6
|
import { buildCheckPrompt, buildHunterPrompt, buildSweepPrompt, buildVerifierPrompt, focusesFor, ruleApplies, usedMemories, } from "./prompt.js";
|
|
7
|
-
import { LimitError, LoginError } from "./providers/codex.js";
|
|
7
|
+
import { LimitError, LoginError, SandboxError } from "./providers/codex.js";
|
|
8
8
|
import { MAX_REPO_RULES } from "./repo-rules.js";
|
|
9
9
|
import { claudeAvailable, runModel as runOneModel, TOOLING } from "./providers/index.js";
|
|
10
10
|
import { candidateSchema, checkSchema, reviewSchema, reviewSchemaWithDecisions } from "./schema.js";
|
|
11
11
|
import { CHECK_TIMEOUT_MS, startTeamChecks } from "./checks.js";
|
|
12
12
|
import { run } from "./run.js";
|
|
13
|
+
import { LATE_ROUND } from "./types.js";
|
|
14
|
+
export { LATE_ROUND } from "./types.js";
|
|
13
15
|
import { cacheDir, prepareWorkspace } from "./workspace.js";
|
|
14
16
|
/**
|
|
15
17
|
* Stable id for a finding: the file plus the code it points at, ignoring
|
|
@@ -64,19 +66,33 @@ export function assignIds(findings, previous, fingerprintOf) {
|
|
|
64
66
|
* Posting everything it would fix meant about 4.5 comments per PR, and all of
|
|
65
67
|
* Codex's about 6.
|
|
66
68
|
*/
|
|
67
|
-
export function tierOf(f) {
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
export function tierOf(f, round = 1) {
|
|
70
|
+
return placeFinding(f, round).tier;
|
|
71
|
+
}
|
|
72
|
+
/** A major bug, or a major problem that exposes secrets, data or actions: it holds the merge in every round. */
|
|
73
|
+
export function mustHold(f) {
|
|
74
|
+
return f.severity === "major" && (f.class === "bug" || f.security === true);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Where a finding goes in this round, and why the loop breaker left it alone when it would otherwise
|
|
78
|
+
* hold the merge. Teams fixed few rare findings (10%, against 45% of minor bugs), and only a problem
|
|
79
|
+
* known to break for real users is worth another round.
|
|
80
|
+
*/
|
|
81
|
+
export function placeFinding(f, round = 1) {
|
|
82
|
+
// Teams fixed few minor risks (19%). They stay readable in the collapsed section.
|
|
70
83
|
const majorBug = f.class === "bug" && f.severity !== "minor";
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
const tier = !majorBug && f.class === "risk" && f.severity === "minor" ? "hardening" : f.rank ? "post" : f.recommendation === "fix" ? "list" : f.recommendation === "decide" ? "decision" : "hardening";
|
|
85
|
+
// A major bug or a major security problem holds the merge even when the verifier said to leave it,
|
|
86
|
+
// as for a costly fix: a person decides.
|
|
87
|
+
if (mustHold(f))
|
|
88
|
+
return { tier: tier === "hardening" ? "decision" : tier };
|
|
89
|
+
if (tier === "hardening")
|
|
90
|
+
return { tier };
|
|
91
|
+
if (f.likelihood === "rare" || f.likelihood === "theoretical")
|
|
92
|
+
return { tier: "hardening", left_alone: "rare" };
|
|
93
|
+
if (round >= LATE_ROUND && f.likelihood !== "common")
|
|
94
|
+
return { tier: "hardening", left_alone: "late" };
|
|
95
|
+
return { tier };
|
|
80
96
|
}
|
|
81
97
|
/** Red if a major bug must be fixed, yellow if anything else is posted or needs a decision, green otherwise. */
|
|
82
98
|
export function mergeLight(findings) {
|
|
@@ -151,7 +167,8 @@ export async function verifyCandidates(dir, input, found, opts) {
|
|
|
151
167
|
const findings = assignIds(review.findings, input.previous ?? [], (f) => fingerprint(dir, f))
|
|
152
168
|
.map((f, i) => {
|
|
153
169
|
const rank = top.includes(i + 1) ? top.indexOf(i + 1) + 1 : null;
|
|
154
|
-
|
|
170
|
+
const { tier, left_alone } = placeFinding({ ...f, rank }, opts.round);
|
|
171
|
+
return { ...f, tier, rank, ...(left_alone ? { left_alone } : {}) };
|
|
155
172
|
})
|
|
156
173
|
.sort((a, b) => ORDER[a.class] - ORDER[b.class] || a.file.localeCompare(b.file) || a.line - b.line);
|
|
157
174
|
return { summary: review.summary, findings, rejected: review.rejected, model: result.model, cost_usd: result.cost_usd ?? null, usage: result.usage };
|
|
@@ -236,10 +253,14 @@ export async function reviewPullRequest(ref, opts = {}) {
|
|
|
236
253
|
diff: ws.diff,
|
|
237
254
|
diffTruncated: ws.diffTruncated,
|
|
238
255
|
previous: opts.previous,
|
|
256
|
+
...(opts.round ? { round: opts.round } : {}),
|
|
257
|
+
...(opts.teamAnswer ? { teamAnswer: opts.teamAnswer } : {}),
|
|
239
258
|
memories: memoriesFor(opts.memories, ws.changedFiles.map((f) => f.path), pr.number),
|
|
240
259
|
// Matched against every path the pull request touches, exactly as git has it.
|
|
241
260
|
skills: teamSkills,
|
|
242
261
|
conventions: ws.conventions,
|
|
262
|
+
// Only when it is the commit under review: an older job commit is part of the diff like any other.
|
|
263
|
+
...(opts.jobCommit && opts.jobCommit.sha === ws.headSha ? { jobCommit: opts.jobCommit } : {}),
|
|
243
264
|
// The dashboard's rules, then the ones written in the repository.
|
|
244
265
|
rules: [...(opts.rules ?? []), ...ws.rules].filter((r) => r.kind === "rule" && ruleApplies(r, ws.touchedPaths)).slice(0, MAX_RULES),
|
|
245
266
|
};
|
|
@@ -256,7 +277,8 @@ export async function reviewPullRequest(ref, opts = {}) {
|
|
|
256
277
|
}
|
|
257
278
|
// Who checks is known before the hunt, so the first reviewer that answers can name both models.
|
|
258
279
|
const verifyWith = opts.verifyWith ?? (provider === "claude" || (await claudeAvailable()) ? "claude" : "codex");
|
|
259
|
-
|
|
280
|
+
// The reviewer's model only carries over to the same AI: a Claude model name means nothing to Codex.
|
|
281
|
+
const verifyModel = verifyWith === "codex" ? (opts.verifyModel ?? (provider === "codex" ? opts.model : undefined)) : (opts.verifyModel ?? "opus");
|
|
260
282
|
let named = false;
|
|
261
283
|
const nameModels = (reviewerModel) => {
|
|
262
284
|
if (named)
|
|
@@ -342,13 +364,36 @@ export async function reviewPullRequest(ref, opts = {}) {
|
|
|
342
364
|
if (!opts.verifyWith && verifyWith === "codex")
|
|
343
365
|
progress("Claude Code isn't installed, so Codex checks the findings");
|
|
344
366
|
progress(`Checking ${found.length} candidate${found.length === 1 ? "" : "s"}${verifyWith === "codex" ? "" : ` with ${verifyWith}`}`);
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
model:
|
|
367
|
+
const servedModelSoFar = () => {
|
|
368
|
+
const first = hunts.find((h) => h.status === "fulfilled");
|
|
369
|
+
return first?.status === "fulfilled" ? first.value.model : null;
|
|
370
|
+
};
|
|
371
|
+
const verifyWithAi = (ai, model) => verifyCandidates(ws.dir, input, found, {
|
|
372
|
+
provider: ai,
|
|
373
|
+
round: opts.round,
|
|
374
|
+
model,
|
|
348
375
|
effort,
|
|
349
|
-
logFile: log("verify"),
|
|
376
|
+
logFile: log(ai === verifyWith ? "verify" : "verify-fallback"),
|
|
350
377
|
onCommand: (cmd) => progress(`Checking ${found.length} candidates: ${cmd.replace(/\s+/g, " ").slice(0, 80)}`, true),
|
|
351
378
|
});
|
|
379
|
+
// The other AI checking is extra: when its login doesn't work or its plan is used up, the reviewer's
|
|
380
|
+
// own AI checks instead, and the summary says why. The reviewer's own failures still stop the review.
|
|
381
|
+
let checkerFailed;
|
|
382
|
+
let verified;
|
|
383
|
+
try {
|
|
384
|
+
verified = await verifyWithAi(verifyWith, verifyModel);
|
|
385
|
+
}
|
|
386
|
+
catch (err) {
|
|
387
|
+
if (verifyWith === provider || !(err instanceof LoginError || err instanceof LimitError || err instanceof SandboxError))
|
|
388
|
+
throw err;
|
|
389
|
+
checkerFailed = err instanceof LimitError ? "limit" : err instanceof SandboxError ? "sandbox" : "login-failed";
|
|
390
|
+
progress(`${verifyWith === "codex" ? "Codex" : "Claude"} couldn't check (${err.message.slice(0, 120)}), so ${provider === "codex" ? "Codex" : "Claude"} checks the findings`);
|
|
391
|
+
const fallbackModel = provider === "codex" ? opts.model : (opts.model ?? "opus");
|
|
392
|
+
// The live comment names the AI that checks now.
|
|
393
|
+
opts.onModels?.({ reviewer: { name: provider, model: servedModelSoFar() }, checker: { name: provider, model: fallbackModel ?? null } });
|
|
394
|
+
verified = await verifyWithAi(provider, fallbackModel);
|
|
395
|
+
}
|
|
396
|
+
const checkedBy = checkerFailed ? provider : verifyWith;
|
|
352
397
|
// Every path the pull request touches counts here, the lockfiles and generated files the reviewers skip included.
|
|
353
398
|
const needsHuman = filesNeedingHuman(opts.rules, ws.touchedPaths);
|
|
354
399
|
const team_checks = teamChecks ? await teamChecks.done : null;
|
|
@@ -369,7 +414,8 @@ export async function reviewPullRequest(ref, opts = {}) {
|
|
|
369
414
|
head_sha: ws.headSha,
|
|
370
415
|
},
|
|
371
416
|
provider: { name: provider, model: servedModel, effort },
|
|
372
|
-
verifier: { name:
|
|
417
|
+
verifier: { name: checkedBy, model: verified.model, effort, cost_usd: verified.cost_usd },
|
|
418
|
+
...(checkerFailed ? { checker_missed: verifyWith, checker_missed_why: checkerFailed } : {}),
|
|
373
419
|
light: lightWith(verified.findings, needsHuman),
|
|
374
420
|
summary: summaryWith(verified.summary, needsHuman, opts.rulesUnread === true),
|
|
375
421
|
...(needsHuman.length ? { needs_human: needsHuman } : {}),
|