Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion plugins/shelltime-statusline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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% | |

Expand Down
34 changes: 29 additions & 5 deletions plugins/shelltime-statusline/hooks/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) })

Expand All @@ -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 },
},
}))
Expand Down Expand Up @@ -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')

Expand Down
22 changes: 19 additions & 3 deletions plugins/shelltime-statusline/hooks/segments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,32 @@ 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: '🚦',
value: '-',
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', () => {
Expand Down
17 changes: 10 additions & 7 deletions plugins/shelltime-statusline/hooks/segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
3 changes: 3 additions & 0 deletions stories/shelltime-statusline/Desktop.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions stories/shelltime-statusline/Terminal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions stories/shelltime-statusline/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions tests/shelltime-statusline/desktop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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%')
})

Expand Down
1 change: 1 addition & 0 deletions tests/shelltime-statusline/terminal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
})

Expand Down
Loading