diff --git a/src/lib/tray-primary-progress.test.ts b/src/lib/tray-primary-progress.test.ts index f2989a5ba..f233f31b6 100644 --- a/src/lib/tray-primary-progress.test.ts +++ b/src/lib/tray-primary-progress.test.ts @@ -302,5 +302,46 @@ describe("getTrayPrimaryBars", () => { }) expect(bars).toEqual([]) }) + + it("falls back to the first progress line when no declared candidate is present", () => { + // Usage-based Codex plans report only "Credits", never the declared "Session" + // candidate. Without a fallback the tray renders "--%" instead of a real number. + const bars = getTrayPrimaryBars({ + pluginsMeta: [ + { + id: "codex", + name: "Codex", + iconUrl: "", + primaryCandidates: ["Session"], + lines: [], + }, + ], + pluginSettings: { order: ["codex"], disabled: [] }, + pluginStates: { + codex: { + data: { + providerId: "codex", + displayName: "Codex", + iconUrl: "", + lines: [ + { + type: "progress", + label: "Credits", + used: 1000, + limit: 1000, + format: { kind: "count", suffix: "credits" }, + }, + ], + }, + loading: false, + error: null, + }, + }, + displayMode: "left", + }) + + // 1000 of 1000 used, "left" mode -> 0 remaining -> 0%, not undefined + expect(bars).toEqual([{ id: "codex", fraction: 0 }]) + }) }) diff --git a/src/lib/tray-primary-progress.ts b/src/lib/tray-primary-progress.ts index a139e29df..6ff0e88d6 100644 --- a/src/lib/tray-primary-progress.ts +++ b/src/lib/tray-primary-progress.ts @@ -65,18 +65,21 @@ export function getTrayPrimaryBars(args: { const primaryLabel = meta.primaryCandidates.find((label) => data.lines.some((line) => isProgressLine(line) && line.label === label) ) - if (primaryLabel) { - const primaryLine = data.lines.find( - (line): line is ProgressLine => - isProgressLine(line) && line.label === primaryLabel - ) - if (primaryLine && primaryLine.limit > 0) { - const shownAmount = - displayMode === "used" - ? primaryLine.used - : primaryLine.limit - primaryLine.used - fraction = clamp01(shownAmount / primaryLine.limit) - } + // Some plans expose none of the declared candidates (usage-based Codex reports only + // "Credits", never "Session"). Fall back to the first progress line so the tray shows + // a real number instead of "--%". + const primaryLine = primaryLabel + ? data.lines.find( + (line): line is ProgressLine => + isProgressLine(line) && line.label === primaryLabel + ) + : data.lines.find((line): line is ProgressLine => isProgressLine(line)) + if (primaryLine && primaryLine.limit > 0) { + const shownAmount = + displayMode === "used" + ? primaryLine.used + : primaryLine.limit - primaryLine.used + fraction = clamp01(shownAmount / primaryLine.limit) } }