Skip to content

feat: add Peak Hours widget with color-coded countdown#279

Open
elhoim wants to merge 1 commit intosirmalloc:mainfrom
elhoim:feature/peak-hours
Open

feat: add Peak Hours widget with color-coded countdown#279
elhoim wants to merge 1 commit intosirmalloc:mainfrom
elhoim:feature/peak-hours

Conversation

@elhoim
Copy link
Copy Markdown

@elhoim elhoim commented Apr 3, 2026

Summary

  • Adds a new Peak Hours widget that shows Anthropic's peak hours status (weekdays 5am-11am PT) with a countdown timer
  • Displays red with ⚠ warning sign during peak hours, green with time-until-next-peak outside
  • Uses Intl.DateTimeFormat with America/Los_Angeles timezone for automatic DST handling
  • Generalizes preserveColors in the renderer to work for any widget type (not just custom-command)

Widget details

  • Type slug: peak-hours | Category: Usage
  • Supports compact mode (s keybind) and raw value mode
  • Widget manages its own ANSI color codes (red/green) — getDefaultColor() returns '' to prevent renderer from overriding
  • Reuses existing formatUsageDuration, formatRawOrLabeledValue, isUsageCompact, and applyColors utilities
  • Intl.DateTimeFormat formatter is cached at module level for performance

Files changed

  • src/widgets/PeakHours.ts — New widget (165 lines)
  • src/widgets/__tests__/PeakHours.test.ts — 34 tests covering timezone logic, rendering, colors, editor actions
  • src/utils/renderer.ts — Generalize preserveColors check (4 locations)
  • src/utils/widget-manifest.ts — Register widget
  • src/widgets/index.ts — Export widget

Test plan

  • bun test — all 631 tests pass (including 34 new)
  • bun run lint — zero errors
  • Manual test with piped input confirms green "Peak in: Xhr Xm" output outside peak hours
  • Manual test confirms red "⚠ Peak: Xhr Xm" during peak hours (via withFixedTime in tests)

🤖 Generated with Claude Code

Shows Anthropic's peak hours status (weekdays 5am-11am PT) with a
countdown timer. Displays red with warning sign during peak hours,
green with time-until-next-peak outside. Uses Intl.DateTimeFormat
for automatic DST handling. Also generalizes preserveColors in the
renderer to work for any widget type, not just custom-command.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant