@mergelight/cli 0.1.20 → 0.1.23

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.
@@ -14,13 +14,13 @@ const MAX_BODY = 65_000;
14
14
  export function checkerMissedLine(r) {
15
15
  if (!r.checker_missed || r.checker_missed === r.provider.name)
16
16
  return null;
17
- const name = (ai) => (ai === "codex" ? "Codex" : "Claude");
18
- const login = r.checker_missed === "codex" ? "ChatGPT" : "Claude";
17
+ const name = (ai) => ({ codex: "Codex", claude: "Claude", antigravity: "Antigravity" })[ai];
18
+ const login = { codex: "ChatGPT", claude: "Claude", antigravity: "Antigravity" }[r.checker_missed];
19
19
  const why = {
20
20
  "no-login": `it has no ${login} login yet`,
21
21
  "not-installed": `${name(r.checker_missed)} couldn't be installed on this run`,
22
22
  // Codex's could be a ChatGPT login or an OpenAI API key: the run log says which.
23
- "login-failed": r.checker_missed === "codex" ? "its login didn't work" : `its ${login} login didn't work`,
23
+ "login-failed": r.checker_missed !== "claude" ? "its login didn't work" : `its ${login} login didn't work`,
24
24
  // A plan's usage or an API key's credit: it can be either.
25
25
  limit: "it hit its usage limit",
26
26
  sandbox: `${name(r.checker_missed)}'s sandbox couldn't start on this runner`,
@@ -73,7 +73,7 @@ export function inlineBody(f) {
73
73
  * isn't known, and the model's own name when it isn't one these rules know.
74
74
  */
75
75
  export function modelLabel(name, model) {
76
- const brand = name === "codex" ? "Codex" : "Claude";
76
+ const brand = name === "codex" ? "Codex" : name === "antigravity" ? "Antigravity" : "Claude";
77
77
  // "opus[1m]" asks for the long context, and "claude-opus-5-5@20261101" names a dated build: the
78
78
  // model is the part before them.
79
79
  const m = model?.trim().replace(/\[[^\]]*\]$/, "").replace(/@[\w.-]*$/, "");
@@ -82,6 +82,9 @@ export function modelLabel(name, model) {
82
82
  const cap = (w) => (/^gpt$/i.test(w) ? "GPT" : w.charAt(0).toUpperCase() + w.slice(1));
83
83
  if (name === "codex")
84
84
  return `${brand} ${m.split("-").map(cap).join("-")}`;
85
+ // Antigravity's own slugs, such as "gemini-4-neon-high": shown as they are.
86
+ if (name === "antigravity")
87
+ return `${brand} (${m})`;
85
88
  // "claude-opus-5-5" and the older "claude-3-7-sonnet" both have a family name and version numbers.
86
89
  const parts = m.replace(/^claude-/, "").replace(/-\d{8}$/, "").split("-");
87
90
  const family = parts.find((p) => !/^\d+$/.test(p)) ?? "";
@@ -116,6 +119,9 @@ export function limitNotice(plan, resets) {
116
119
  if (plan === "OpenAI") {
117
120
  return { heading: "⏳ Mergelight: the OpenAI API key has no usage left", body: "This pull request wasn't reviewed, because the OpenAI API key has no usage left: its credit ran out, or its account reached its spending limit. Check both in the OpenAI account, then push a new commit, and the review runs again." };
118
121
  }
122
+ if (plan === "Gemini") {
123
+ return { heading: "⏳ Mergelight: the Gemini API key has no usage left", body: "This pull request wasn't reviewed, because the Gemini API key has no usage left: its Google project ran out of quota, or reached its spending limit. Check the project's quota and billing in Google AI Studio, then push a new commit, and the review runs again." };
124
+ }
119
125
  if (plan === "Anthropic") {
120
126
  return { heading: "⏳ Mergelight: the Anthropic API key has no credit left", body: "This pull request wasn't reviewed, because the Anthropic API key has no credit left. Add credit to its account, then push a new commit, and the review runs again." };
121
127
  }
@@ -231,7 +237,7 @@ function updateBanner({ tag, current, news }) {
231
237
  `> **You're missing out: Mergelight ${tag} is out, and this repo is on ${current}.**`,
232
238
  ...(news.length ? [">", ...news.slice(0, NEWS_SHOWN).map((n) => `> - ${clean(n)}`), ...(more > 0 ? [`> - and ${more} more`] : [])] : []),
233
239
  ">",
234
- "> **[Update now](https://mergelight.dev/setup/)**. It's one click, and only the version lines change.",
240
+ "> **[Update now](https://mergelight.dev/setup/)**. It's one click, and you see every change in a pull request before you merge.",
235
241
  "",
236
242
  ];
237
243
  }
@@ -190,7 +190,7 @@ export async function answerRemembered(api, number, ids, cut, log = () => { }) {
190
190
  export const CHECK_FAILED_TITLE = "Couldn't review this pull request";
191
191
  export const checkLoginTitle = (plan) => `The ${plan} login didn't work`;
192
192
  export const checkHeldTitle = `${CHECK_FAILED_TITLE}: the ChatGPT login was held back`;
193
- export const checkLimitTitle = (plan) => (plan === "OpenAI" || plan === "Anthropic" ? `${CHECK_FAILED_TITLE}: the ${plan} API key has no usage left` : `${CHECK_FAILED_TITLE}: your ${plan} plan hit its limit`);
193
+ export const checkLimitTitle = (plan) => (plan === "OpenAI" || plan === "Anthropic" || plan === "Gemini" ? `${CHECK_FAILED_TITLE}: the ${plan} API key has no usage left` : `${CHECK_FAILED_TITLE}: your ${plan} plan hit its limit`);
194
194
  export const isFailedCheckTitle = (title) => Boolean(title && (title.startsWith(CHECK_FAILED_TITLE) || /^The \w+ login didn't work$/.test(title)));
195
195
  /**
196
196
  * Creates the check, or updates it if it has an id. GitHub only lets Apps write
@@ -215,7 +215,7 @@ export async function writeCheck(api, id, headSha, body, log) {
215
215
  * happening. A login that can't write checks hears about it once, from the last write.
216
216
  */
217
217
  export async function startCheck(api, headSha, provider, handedOver, started) {
218
- const tool = provider === "claude" ? "Claude" : provider === "codex" ? "Codex" : null;
218
+ const tool = provider === "claude" ? "Claude" : provider === "codex" ? "Codex" : provider === "antigravity" ? "Antigravity" : null;
219
219
  // Always a check of the review's own, for the commit it reads: approvals and verdicts then go to the
220
220
  // check this review made, never to an older one.
221
221
  const run = await writeCheck(api, null, headSha, {
@@ -429,6 +429,12 @@ export const UNREVIEWED = "Mergelight couldn't review the newest commit, so its
429
429
  export const APPROVAL_MARKER = "<!-- mergelight:approval -->";
430
430
  /** Only these post Mergelight's reviews, so a person's review that quotes the marker is never touched. */
431
431
  const OWN_REVIEWERS = new Set(["mergelight-ai[bot]", "github-actions[bot]"]);
432
+ /** The Mergelight AI app: every review it posts is Mergelight's, so its approval needs no marker, and shows none. */
433
+ const APP_REVIEWER = "mergelight-ai[bot]";
434
+ /** What an approval says when it needs the marker: posted as github-actions[bot], which other workflows use too. */
435
+ const APPROVAL_TEXT = "🟢 Mergelight found nothing that needs fixing in this commit.";
436
+ /** Mergelight's own approvals: any by its app, and those with the marker by the workflow's own bot. */
437
+ const isOwnApproval = (r) => r.user?.login === APP_REVIEWER || (OWN_REVIEWERS.has(r.user?.login ?? "") && (r.body ?? "").includes(APPROVAL_MARKER));
432
438
  /**
433
439
  * Green approves the pull request, like a reviewer would. Anything else takes back an approval Mergelight gave
434
440
  * earlier, so an old approval can't stand next to a newer finding. Yellow and red never request changes, so a
@@ -436,16 +442,21 @@ const OWN_REVIEWERS = new Set(["mergelight-ai[bot]", "github-actions[bot]"]);
436
442
  */
437
443
  export async function syncApproval(api, number, light, headSha, log = () => { }, dismissal = {}) {
438
444
  try {
439
- const ours = (await api.list(`pulls/${number}/reviews`)).filter((r) => OWN_REVIEWERS.has(r.user?.login ?? "") && (r.body ?? "").includes(APPROVAL_MARKER));
445
+ const ours = (await api.list(`pulls/${number}/reviews`)).filter(isOwnApproval);
440
446
  const standing = ours.filter((r) => r.state === "APPROVED");
441
447
  if (light === "green") {
442
448
  if (standing.some((r) => r.commit_id === headSha))
443
449
  return "already";
444
- await api.write("POST", `pulls/${number}/reviews`, {
445
- commit_id: headSha,
446
- event: "APPROVE",
447
- body: `${APPROVAL_MARKER}\n🟢 Mergelight found nothing that needs fixing in this commit.`,
448
- });
450
+ // A plain approval, like a person's: the summary says the rest.
451
+ const posted = await api.write("POST", `pulls/${number}/reviews`, { commit_id: headSha, event: "APPROVE" });
452
+ // Posted by the workflow's own bot, which other workflows approve as too: the marker tells this one
453
+ // apart, so a later review can take it back. One that can't be told apart is taken back at once.
454
+ if (posted?.id && posted.user?.login !== APP_REVIEWER) {
455
+ await api.write("PUT", `pulls/${number}/reviews/${posted.id}`, { body: `${APPROVAL_MARKER}\n${APPROVAL_TEXT}` }).catch(async (err) => {
456
+ await api.write("PUT", `pulls/${number}/reviews/${posted.id}/dismissals`, { message: "Mergelight couldn't mark this approval as its own, so it takes it back. The next review approves again.", event: "DISMISS" });
457
+ throw err;
458
+ });
459
+ }
449
460
  return "approved";
450
461
  }
451
462
  const taken = dismissal.otherCommitsOnly ? standing.filter((r) => r.commit_id !== headSha) : standing;
package/dist/review.js CHANGED
@@ -6,7 +6,7 @@ import { fetchPullRequest } from "./github.js";
6
6
  import { buildCheckPrompt, buildHunterPrompt, buildSweepPrompt, buildVerifierPrompt, focusesFor, ruleApplies, usedMemories, } from "./prompt.js";
7
7
  import { LimitError, LoginError, SandboxError } from "./providers/codex.js";
8
8
  import { MAX_REPO_RULES } from "./repo-rules.js";
9
- import { claudeAvailable, runModel as runOneModel, TOOLING } from "./providers/index.js";
9
+ import { claudeAvailable, FILE_TOOLS, PROVIDER_LABEL, 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";
@@ -126,12 +126,13 @@ function counting(tally) {
126
126
  /** Tells the prompts which tools the agent has. Without a shell it can't run git diff, so a big diff goes into the checkout. */
127
127
  function forProvider(dir, input, provider) {
128
128
  const tooling = TOOLING[provider];
129
+ const fileTools = tooling === "files" ? FILE_TOOLS[provider] : undefined;
129
130
  if (tooling !== "files" || !input.diffTruncated)
130
- return { ...input, tooling };
131
+ return { ...input, tooling, fileTools };
131
132
  const diffFile = ".mergelight/pr.diff";
132
133
  mkdirSync(join(dir, ".mergelight"), { recursive: true });
133
134
  writeFileSync(join(dir, diffFile), input.diff);
134
- return { ...input, tooling, diffFile };
135
+ return { ...input, tooling, fileTools, diffFile };
135
136
  }
136
137
  /** The diff one of the team's checks reads: at most this much of it goes into the question. */
137
138
  const MAX_CHECK_DIFF = 150_000;
@@ -175,8 +176,8 @@ export async function verifyCandidates(dir, input, found, opts) {
175
176
  }
176
177
  /** Every rule a team can have for one repository: 50 for the org and 50 of its own on the dashboard, and those in its rule files. None is dropped. */
177
178
  const MAX_RULES = 100 + MAX_REPO_RULES;
178
- /** The summary, with what the reader must know about the team's rules: a guarded file was changed, or the rules couldn't be read. */
179
- export function summaryWith(summary, needsHuman, rulesUnread) {
179
+ /** The summary, with what the reader must know about the team's rules: a guarded file was changed, the rules couldn't be read, or the org's plan ended. */
180
+ export function summaryWith(summary, needsHuman, rulesUnread, planEnded = false) {
180
181
  // As code, so a name like __init__.py shows as it is and not as bold text.
181
182
  const code = (path) => `\`${path.replace(/`/g, "'").replace(/[\u0000-\u001f\u007f]/g, "?")}\``;
182
183
  const guarded = needsHuman.length
@@ -184,7 +185,9 @@ export function summaryWith(summary, needsHuman, rulesUnread) {
184
185
  : "";
185
186
  // A team may have rules that would have changed this review. Running without them must never be silent.
186
187
  const unread = rulesUnread ? " Mergelight couldn't get your team's rules, skills, checks and earlier decisions from its server, so this review ran without them." : "";
187
- return `${summary}${guarded}${unread}`;
188
+ // Said, not held: a team that stopped paying still gets its reviews, and must know they ran without its rules.
189
+ const ended = planEnded && !rulesUnread ? " Your org's Mergelight plan ended or is paused, so this review ran without the rules, skills, checks and saved decisions on your Mergelight dashboard." : "";
190
+ return `${summary}${guarded}${unread}${ended}`;
188
191
  }
189
192
  /**
190
193
  * The light, with the team's "always needs a human" files taken into account. Such a file keeps a
@@ -276,9 +279,10 @@ export async function reviewPullRequest(ref, opts = {}) {
276
279
  unread = notRead(input.actionSources);
277
280
  }
278
281
  // Who checks is known before the hunt, so the first reviewer that answers can name both models.
279
- const verifyWith = opts.verifyWith ?? (provider === "claude" || (await claudeAvailable()) ? "claude" : "codex");
282
+ // Antigravity checks its own findings unless told otherwise: nothing says another AI here has a login.
283
+ const verifyWith = opts.verifyWith ?? (provider === "antigravity" ? "antigravity" : provider === "claude" || (await claudeAvailable()) ? "claude" : "codex");
280
284
  // 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");
285
+ const verifyModel = verifyWith === "claude" ? (opts.verifyModel ?? "opus") : (opts.verifyModel ?? (provider === verifyWith ? opts.model : undefined));
282
286
  let named = false;
283
287
  const nameModels = (reviewerModel) => {
284
288
  if (named)
@@ -349,7 +353,7 @@ export async function reviewPullRequest(ref, opts = {}) {
349
353
  const teamChecks = opts.checks?.length
350
354
  ? startTeamChecks(opts.checks, ws.touchedPaths, async (check, files) => (await runModel(provider, {
351
355
  cwd: ws.dir,
352
- prompt: buildCheckPrompt({ ...input, tooling: TOOLING[provider] }, check, files, await checkDiff(ws.dir, ws.mergeBase, ws.headSha, files)),
356
+ prompt: buildCheckPrompt({ ...input, tooling: TOOLING[provider], fileTools: TOOLING[provider] === "files" ? FILE_TOOLS[provider] : undefined }, check, files, await checkDiff(ws.dir, ws.mergeBase, ws.headSha, files)),
353
357
  schema: checkSchema,
354
358
  model: hunterModel,
355
359
  effort,
@@ -363,7 +367,7 @@ export async function reviewPullRequest(ref, opts = {}) {
363
367
  // Opus checks better than Codex: in the eval it posted a third less and kept the same finds.
364
368
  if (!opts.verifyWith && verifyWith === "codex")
365
369
  progress("Claude Code isn't installed, so Codex checks the findings");
366
- progress(`Checking ${found.length} candidate${found.length === 1 ? "" : "s"}${verifyWith === "codex" ? "" : ` with ${verifyWith}`}`);
370
+ progress(`Checking ${found.length} candidate${found.length === 1 ? "" : "s"}${verifyWith === "codex" ? "" : ` with ${PROVIDER_LABEL[verifyWith]}`}`);
367
371
  const servedModelSoFar = () => {
368
372
  const first = hunts.find((h) => h.status === "fulfilled");
369
373
  return first?.status === "fulfilled" ? first.value.model : null;
@@ -387,8 +391,8 @@ export async function reviewPullRequest(ref, opts = {}) {
387
391
  if (verifyWith === provider || !(err instanceof LoginError || err instanceof LimitError || err instanceof SandboxError))
388
392
  throw err;
389
393
  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");
394
+ progress(`${PROVIDER_LABEL[verifyWith]} couldn't check (${err.message.slice(0, 120)}), so ${PROVIDER_LABEL[provider]} checks the findings`);
395
+ const fallbackModel = provider === "claude" ? (opts.model ?? "opus") : opts.model;
392
396
  // The live comment names the AI that checks now.
393
397
  opts.onModels?.({ reviewer: { name: provider, model: servedModelSoFar() }, checker: { name: provider, model: fallbackModel ?? null } });
394
398
  verified = await verifyWithAi(provider, fallbackModel);
@@ -417,7 +421,7 @@ export async function reviewPullRequest(ref, opts = {}) {
417
421
  verifier: { name: checkedBy, model: verified.model, effort, cost_usd: verified.cost_usd },
418
422
  ...(checkerFailed ? { checker_missed: verifyWith, checker_missed_why: checkerFailed } : {}),
419
423
  light: lightWith(verified.findings, needsHuman),
420
- summary: summaryWith(verified.summary, needsHuman, opts.rulesUnread === true),
424
+ summary: summaryWith(verified.summary, needsHuman, opts.rulesUnread === true, opts.planEnded === true),
421
425
  ...(needsHuman.length ? { needs_human: needsHuman } : {}),
422
426
  findings: verified.findings,
423
427
  ...(input.memories?.length ? { used_memories: usedMemories(input.memories, verified.rejected, found) } : {}),
package/dist/setup.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { rolledOut } from "./update.js";
1
2
  import { spawn } from "node:child_process";
2
3
  import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
4
  import { tmpdir } from "node:os";
@@ -43,9 +44,14 @@ export function workflowFiles(skipBranches = [], pin, jobs = false) {
43
44
  });
44
45
  }
45
46
  /** The latest release, as a commit. */
47
+ /** The version @v0 points to: the newest release whose canary passed, never one still being tried. */
46
48
  async function latestPin(deps) {
47
- const tag = (await deps.gh(["api", `repos/${ACTION}/releases/latest`, "--jq", ".tag_name"])).trim();
48
- const sha = (await deps.gh(["api", `repos/${ACTION}/commits/${tag}`, "--jq", ".sha"])).trim();
49
+ // Every page: GitHub lists v0 after all the version tags, so it falls past the first page in time.
50
+ const tags = JSON.parse(await deps.gh(["api", "--paginate", "--slurp", `repos/${ACTION}/tags?per_page=100`])).flat();
51
+ const tag = rolledOut(tags);
52
+ const sha = tags.find((t) => t.name === tag)?.commit.sha;
53
+ if (!tag || !sha)
54
+ throw new Error("Couldn't tell which Mergelight release is current. Run setup again, or use --no-pin.");
49
55
  return { sha, tag };
50
56
  }
51
57
  /** A ChatGPT login is only useful in CI if it can refresh itself. */
package/dist/update.js CHANGED
@@ -16,6 +16,16 @@ export function isNewer(candidate, than) {
16
16
  }
17
17
  return false;
18
18
  }
19
+ /**
20
+ * The version @v0 points to: the newest release whose canary review passed. A newer release that is still
21
+ * being tried has no one pointed at it yet. Null when it can't be told.
22
+ */
23
+ export function rolledOut(tags) {
24
+ const v0 = tags.find((t) => t.name === "v0")?.commit.sha;
25
+ if (!v0)
26
+ return null;
27
+ return tags.filter((t) => t.commit.sha === v0 && /^v\d+\.\d+\.\d+$/.test(t.name)).map((t) => t.name).sort((a, b) => (isNewer(a, b) ? -1 : 1))[0] ?? null;
28
+ }
19
29
  /** The changes a release's generated notes list, without the version bumps. */
20
30
  export function releaseNews(notes) {
21
31
  return [...notes.matchAll(/^\* (.+?) by @\S+ in https:\/\/\S+$/gm)].map((m) => m[1]).filter((title) => !/^Release v\d/.test(title));
@@ -26,7 +36,12 @@ export async function newerVersion(api, current = CURRENT, ref = process.env.MER
26
36
  return null;
27
37
  try {
28
38
  const releases = await api.get("/repos/mergelightai/mergelight/releases?per_page=30");
29
- const newer = releases.filter((r) => !r.draft && !r.prerelease && isNewer(r.tag_name, current)).sort((a, b) => (isNewer(a.tag_name, b.tag_name) ? -1 : 1));
39
+ // Never past the version @v0 points to: a release still in its canary isn't offered yet.
40
+ // Every page: GitHub lists v0 after all the version tags, so it falls past the first page in time.
41
+ const top = rolledOut(await api.list("/repos/mergelightai/mergelight/tags"));
42
+ if (!top)
43
+ return null;
44
+ const newer = releases.filter((r) => !r.draft && !r.prerelease && isNewer(r.tag_name, current) && !isNewer(r.tag_name, top)).sort((a, b) => (isNewer(a.tag_name, b.tag_name) ? -1 : 1));
30
45
  if (!newer.length)
31
46
  return null;
32
47
  return { tag: newer[0].tag_name, current: `v${current.replace(/^v/, "")}`, news: newer.flatMap((r) => releaseNews(r.body ?? "")) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mergelight/cli",
3
- "version": "0.1.20",
3
+ "version": "0.1.23",
4
4
  "description": "AI code review that runs on the Claude or ChatGPT plan you already pay for.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -130,9 +130,27 @@ export function isDue(event, expiry, now) {
130
130
  * Returns the reason if it can tell that something went wrong. Its logs stay out of ours, since they
131
131
  * deal with the login.
132
132
  */
133
+ /**
134
+ * A known cause of a failed refresh in what Codex wrote to its error output, or null. Only the cause, never
135
+ * the output itself, which can hold tokens.
136
+ */
137
+ export function refreshFailure(text) {
138
+ if (/refresh_token_reused|already (?:been )?used/i.test(text)) return "the refresh token was already used";
139
+ if (/refresh_token_expired|refresh token (?:has )?expired/i.test(text)) return "the refresh token ran out";
140
+ if (/refresh_token_invalidated|invalid_grant/i.test(text)) return "the refresh token was refused";
141
+ const status = /\b(?:status(?: code)?|HTTP)[\s:=]*([45]\d\d)\b/i.exec(text)?.[1];
142
+ return status ? `HTTP ${status}` : null;
143
+ }
144
+
133
145
  export function forceRefresh({ env = process.env, spawnImpl = spawn, timeoutMs = 90_000 } = {}) {
134
146
  return new Promise((resolve) => {
135
- const child = spawnImpl("codex", ["app-server"], { stdio: ["pipe", "pipe", "ignore"], env });
147
+ const child = spawnImpl("codex", ["app-server"], { stdio: ["pipe", "pipe", "pipe"], env });
148
+ // Read, so Codex never waits on a full pipe, and kept only to find a known cause in.
149
+ let errors = "";
150
+ child.stderr?.setEncoding?.("utf8");
151
+ child.stderr?.on("data", (chunk) => {
152
+ if (errors.length < 64 * 1024) errors += chunk;
153
+ });
136
154
  const send = (message) => child.stdin.write(`${JSON.stringify(message)}\n`);
137
155
  let done = false;
138
156
  const finish = (reason = null) => {
@@ -140,7 +158,8 @@ export function forceRefresh({ env = process.env, spawnImpl = spawn, timeoutMs =
140
158
  done = true;
141
159
  clearTimeout(timer);
142
160
  child.kill();
143
- resolve(reason);
161
+ // A failed refresh can still answer normally: then Codex's error output may name the cause.
162
+ resolve(reason ?? refreshFailure(errors));
144
163
  };
145
164
  const timer = setTimeout(() => finish("Codex didn't answer in time"), timeoutMs);
146
165
  child.on("error", (err) => finish(err.message));