Skip to content

Commit 34e84bc

Browse files
committed
fix(tray): show real percentage when no declared candidate is present
A plan can expose progress lines that are absent from its plugin manifest's declared primary candidates. Usage-based Codex accounts (Self_serve_business_usage_based) report only a "Credits" progress line and never "Session", which is the only candidate codex declares via primaryOrder. getTrayPrimaryBars then matched no label, left fraction undefined, and the tray rendered "--%" even though a perfectly usable progress line was present (used 1000 / limit 1000). Fall back to the first progress line in the runtime data when none of the declared candidates match, so the tray shows a real number. Plugins that declare no candidates at all are still skipped, exactly as before.
1 parent 2bc8093 commit 34e84bc

2 files changed

Lines changed: 56 additions & 12 deletions

File tree

src/lib/tray-primary-progress.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,5 +302,46 @@ describe("getTrayPrimaryBars", () => {
302302
})
303303
expect(bars).toEqual([])
304304
})
305+
306+
it("falls back to the first progress line when no declared candidate is present", () => {
307+
// Usage-based Codex plans report only "Credits", never the declared "Session"
308+
// candidate. Without a fallback the tray renders "--%" instead of a real number.
309+
const bars = getTrayPrimaryBars({
310+
pluginsMeta: [
311+
{
312+
id: "codex",
313+
name: "Codex",
314+
iconUrl: "",
315+
primaryCandidates: ["Session"],
316+
lines: [],
317+
},
318+
],
319+
pluginSettings: { order: ["codex"], disabled: [] },
320+
pluginStates: {
321+
codex: {
322+
data: {
323+
providerId: "codex",
324+
displayName: "Codex",
325+
iconUrl: "",
326+
lines: [
327+
{
328+
type: "progress",
329+
label: "Credits",
330+
used: 1000,
331+
limit: 1000,
332+
format: { kind: "count", suffix: "credits" },
333+
},
334+
],
335+
},
336+
loading: false,
337+
error: null,
338+
},
339+
},
340+
displayMode: "left",
341+
})
342+
343+
// 1000 of 1000 used, "left" mode -> 0 remaining -> 0%, not undefined
344+
expect(bars).toEqual([{ id: "codex", fraction: 0 }])
345+
})
305346
})
306347

src/lib/tray-primary-progress.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,21 @@ export function getTrayPrimaryBars(args: {
6565
const primaryLabel = meta.primaryCandidates.find((label) =>
6666
data.lines.some((line) => isProgressLine(line) && line.label === label)
6767
)
68-
if (primaryLabel) {
69-
const primaryLine = data.lines.find(
70-
(line): line is ProgressLine =>
71-
isProgressLine(line) && line.label === primaryLabel
72-
)
73-
if (primaryLine && primaryLine.limit > 0) {
74-
const shownAmount =
75-
displayMode === "used"
76-
? primaryLine.used
77-
: primaryLine.limit - primaryLine.used
78-
fraction = clamp01(shownAmount / primaryLine.limit)
79-
}
68+
// Some plans expose none of the declared candidates (usage-based Codex reports only
69+
// "Credits", never "Session"). Fall back to the first progress line so the tray shows
70+
// a real number instead of "--%".
71+
const primaryLine = primaryLabel
72+
? data.lines.find(
73+
(line): line is ProgressLine =>
74+
isProgressLine(line) && line.label === primaryLabel
75+
)
76+
: data.lines.find((line): line is ProgressLine => isProgressLine(line))
77+
if (primaryLine && primaryLine.limit > 0) {
78+
const shownAmount =
79+
displayMode === "used"
80+
? primaryLine.used
81+
: primaryLine.limit - primaryLine.used
82+
fraction = clamp01(shownAmount / primaryLine.limit)
8083
}
8184
}
8285

0 commit comments

Comments
 (0)