diff --git a/README.md b/README.md index 1541d17..fb30eb1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ From left to right: - πŸ€– the model (terminal only; the desktop composer already shows it) - πŸ’° this session's cost - πŸ“Š today's Claude Code cost -- 🚦 the 5-hour and 7-day quota used +- 🚦 the 5-hour and 7-day quota used (only 7-day on plans without a 5-hour limit) - ⏱️ today's AI agent time - πŸ“ˆ the context window used diff --git a/plugins/shelltime-statusline/README.md b/plugins/shelltime-statusline/README.md index 3fb2d8a..169823d 100644 --- a/plugins/shelltime-statusline/README.md +++ b/plugins/shelltime-statusline/README.md @@ -20,7 +20,7 @@ In the desktop app it is one flat row, with no borders or padding, in tones that | πŸ€– | Model (terminal only) | | | | πŸ’° | This session's cost | cyan | the session on shelltime.xyz | | πŸ“Š | Today's Claude Code cost | yellow (amber on desktop), gray `-` with none | your coding agent page | -| 🚦 | 5-hour and 7-day quota used | green, yellow from 50%, red from 80%; on desktop each bucket has its own bar and color | claude.ai usage | +| 🚦 | 5-hour and 7-day quota used; a plan without a 5-hour limit shows `7d` alone | green, yellow from 50%, red from 80%; on desktop each bucket has its own bar and color | claude.ai usage | | ⏱️ | Today's AI agent time | magenta, gray `-` with none | your profile | | πŸ“ˆ | Context window used, with a bar on desktop | green, yellow from 50%, red from 80% | | diff --git a/plugins/shelltime-statusline/hooks/register.test.ts b/plugins/shelltime-statusline/hooks/register.test.ts index 3e0d480..026ac81 100644 --- a/plugins/shelltime-statusline/hooks/register.test.ts +++ b/plugins/shelltime-statusline/hooks/register.test.ts @@ -23,7 +23,12 @@ function ran(stdout: string, exitCode = 0) { // The world beneath the plugin: a session in a dirty git checkout on `main`, // and the CLI's config holding `token` when one is given. -function world(on: On, token?: string) { +const RATE_LIMITS = [ + { kind: 'five_hour', percentUsed: 23 }, + { kind: 'seven_day', percentUsed: 45 }, +] + +function world(on: On, token?: string, rateLimits = RATE_LIMITS) { mock.env(on, { HOME: '/home/me' }) const clock = mock.clock(on, { now: Date.UTC(2026, 9, 4, 12) }) @@ -32,10 +37,7 @@ function world(on: On, token?: string) { value: { startedAt: 0, context: { tokens: 84_000, window: 200_000, percent: 42 }, - rateLimits: [ - { kind: 'five_hour', percentUsed: 23 }, - { kind: 'seven_day', percentUsed: 45 }, - ], + rateLimits, cost: { usd: 1.234 }, }, })) @@ -157,6 +159,28 @@ test('without a ShellTime token: local figures only, no API calls', async ($, on await desktop.unmount() }) +test('a plan without a 5-hour limit shows the 7-day quota alone', async ($, on) => { + const { clock } = world(on, undefined, [{ kind: 'seven_day', percentUsed: 45 }]) + + await $.session.start({ cwd: '/work/app', surface: 'terminal', isInteractive: true }) + await clock.advance(300) + await clock.settle() + + const terminal = await mountBand($, 'terminal') + expect(await terminal.find({ type: 'Text', text: '🚦 7d:45%' })).toBeDefined() + await terminal.unmount() + + const desktop = await mountBand($, 'desktop') + expect(await desktop.find({ type: 'Text', text: '7d' })).toBeDefined() + expect(await desktop.find({ type: 'Text', text: '45%' })).toBeDefined() + expect(await desktop.find({ type: 'Text', text: '5h' })).toBeUndefined() + expect((await desktop.findAll({ type: 'Svg' })).map(svg => svg.props.alt)).toEqual([ + '7-day quota used: 45%', + 'Context window used: 42%', + ]) + await desktop.unmount() +}) + test('the API is asked at most once per 15 seconds', async ($, on) => { const { clock, requests } = world(on, 'tok-123') diff --git a/plugins/shelltime-statusline/hooks/segments.test.ts b/plugins/shelltime-statusline/hooks/segments.test.ts index 3972c24..13297fb 100644 --- a/plugins/shelltime-statusline/hooks/segments.test.ts +++ b/plugins/shelltime-statusline/hooks/segments.test.ts @@ -108,7 +108,7 @@ describe('buildSegments', () => { }) describe('quotaSegment', () => { - test('either bucket missing is a gray dash, still linked', () => { + test('both buckets missing is a gray dash, still linked', () => { expect(quotaSegment(null, null)).toEqual({ key: 'quota', icon: '🚦', @@ -116,8 +116,24 @@ describe('quotaSegment', () => { color: 'gray', url: CLAUDE_USAGE_URL, }) - expect(quotaSegment(null, 45).value).toBe('-') - expect(quotaSegment(null, 45).meters).toBeUndefined() + }) + + test('a plan without a 5-hour limit shows the 7-day bucket alone, colored by it', () => { + expect(quotaSegment(null, 45)).toEqual({ + key: 'quota', + icon: '🚦', + value: '7d:45%', + color: 'green', + url: CLAUDE_USAGE_URL, + meters: [{ label: '7d', percent: 45, description: '7-day quota used' }], + }) + expect(quotaSegment(null, 85).color).toBe('red') + }) + + test('a lone 5-hour bucket is shown too', () => { + expect(quotaSegment(55, null).value).toBe('5h:55%') + expect(quotaSegment(55, null).color).toBe('yellow') + expect(quotaSegment(55, null).meters).toEqual([{ label: '5h', percent: 55, description: '5-hour quota used' }]) }) test('colored by the higher bucket', () => { diff --git a/plugins/shelltime-statusline/hooks/segments.ts b/plugins/shelltime-statusline/hooks/segments.ts index 3fcae8f..5623717 100644 --- a/plugins/shelltime-statusline/hooks/segments.ts +++ b/plugins/shelltime-statusline/hooks/segments.ts @@ -72,20 +72,23 @@ function missing(key: SegmentKey, icon: string, url?: string): Segment { return { key, icon, value: '-', color: 'gray', url } } +// The windows the account has: a plan without a 5-hour limit shows `7d:45%` +// alone, colored by it. A dash only when there is neither. export function quotaSegment(fiveHour: number | null, sevenDay: number | null): Segment { - if (fiveHour === null || sevenDay === null) { + const meters = [ + { label: '5h', percent: fiveHour, description: '5-hour quota used' }, + { label: '7d', percent: sevenDay, description: '7-day quota used' }, + ].filter((meter): meter is Meter & { label: string } => meter.percent !== null) + if (meters.length === 0) { return missing('quota', '🚦', CLAUDE_USAGE_URL) } return { key: 'quota', icon: '🚦', - value: `5h:${Math.round(fiveHour)}% 7d:${Math.round(sevenDay)}%`, - color: thresholdColor(Math.max(fiveHour, sevenDay)), + value: meters.map(meter => `${meter.label}:${Math.round(meter.percent)}%`).join(' '), + color: thresholdColor(Math.max(...meters.map(meter => meter.percent))), url: CLAUDE_USAGE_URL, - meters: [ - { label: '5h', percent: fiveHour, description: '5-hour quota used' }, - { label: '7d', percent: sevenDay, description: '7-day quota used' }, - ], + meters, } } diff --git a/stories/shelltime-statusline/Desktop.stories.tsx b/stories/shelltime-statusline/Desktop.stories.tsx index 57802b6..4a74980 100644 --- a/stories/shelltime-statusline/Desktop.stories.tsx +++ b/stories/shelltime-statusline/Desktop.stories.tsx @@ -24,6 +24,9 @@ export const NoToken: Story = { args: { view: 'noToken' } } export const HighUsage: Story = { args: { view: 'highUsage' } } +// A plan without a 5-hour limit shows the 7-day quota alone. +export const NoFiveHour: Story = { args: { view: 'noFiveHour' } } + export const NoGit: Story = { args: { view: 'noGit' } } // A docked pane leaves the band narrow: segments wrap whole. diff --git a/stories/shelltime-statusline/Terminal.stories.tsx b/stories/shelltime-statusline/Terminal.stories.tsx index d78f668..957d45e 100644 --- a/stories/shelltime-statusline/Terminal.stories.tsx +++ b/stories/shelltime-statusline/Terminal.stories.tsx @@ -24,6 +24,9 @@ export const NoToken: Story = { args: { view: 'noToken' } } export const HighUsage: Story = { args: { view: 'highUsage' } } +// A plan without a 5-hour limit shows the 7-day quota alone. +export const NoFiveHour: Story = { args: { view: 'noFiveHour' } } + export const NoGit: Story = { args: { view: 'noGit' } } // Narrower than the line: it wraps between segments. diff --git a/stories/shelltime-statusline/fixtures.ts b/stories/shelltime-statusline/fixtures.ts index a641fda..ed2cd15 100644 --- a/stories/shelltime-statusline/fixtures.ts +++ b/stories/shelltime-statusline/fixtures.ts @@ -22,6 +22,8 @@ export const VIEWS = { noToken: { ...FULL, daily: null, login: '', webEndpoint: '' }, // Close to the limits: quota and context past the thresholds. highUsage: { ...FULL, fiveHourPercent: 85, sevenDayPercent: 62, contextPercent: 91, sessionCost: 18.4 }, + // A plan without a 5-hour limit: the 7-day window alone. + noFiveHour: { ...FULL, fiveHourPercent: null }, // Outside a repo, before the rate limits are known. noGit: { ...FULL, git: null, fiveHourPercent: null, sevenDayPercent: null }, // A long branch name. diff --git a/tests/shelltime-statusline/desktop.spec.ts b/tests/shelltime-statusline/desktop.spec.ts index b55c7d4..f901549 100644 --- a/tests/shelltime-statusline/desktop.spec.ts +++ b/tests/shelltime-statusline/desktop.spec.ts @@ -49,6 +49,7 @@ describe('desktop row', () => { expect(textOf(segment(VIEWS.full, 'git'))).toBe('🌿main*') expect(textOf(segment(VIEWS.full, 'sessionCost'))).toBe('πŸ’°$1.23') expect(textOf(segment(VIEWS.full, 'quota'))).toBe('🚦5h23%7d45%') + expect(textOf(segment(VIEWS.noFiveHour, 'quota'))).toBe('🚦7d45%') expect(textOf(segment(VIEWS.full, 'context'))).toBe('πŸ“ˆ42%') }) diff --git a/tests/shelltime-statusline/terminal.spec.ts b/tests/shelltime-statusline/terminal.spec.ts index 05553ea..1a663d3 100644 --- a/tests/shelltime-statusline/terminal.spec.ts +++ b/tests/shelltime-statusline/terminal.spec.ts @@ -35,6 +35,7 @@ describe('terminal line', () => { expect(textProps(VIEWS.full, '⏱️ 1h5m')).toEqual({ color: 'merged' }) expect(textProps(VIEWS.full, 'πŸ“ˆ 42%')).toEqual({ color: 'success' }) expect(textProps(VIEWS.highUsage, '🚦 5h:85% 7d:62%')).toEqual({ color: 'error' }) + expect(textProps(VIEWS.noFiveHour, '🚦 7d:45%')).toEqual({ color: 'success' }) expect(textProps(VIEWS.highUsage, 'πŸ“ˆ 91%')).toEqual({ color: 'error' }) })