feat(statusline): add total AI agent time to CC statusline display#198
feat(statusline): add total AI agent time to CC statusline display#198
Conversation
Display totalSessionSeconds from backend GraphQL API in the statusline. The new display format shows agent time in magenta between daily cost and context percentage: 🤖 model | 💰 $session | 📊 $daily | ⏱️ time | 📈 context% Time is formatted as: - Under 1 minute: 45s - Under 1 hour: 2m5s - 1+ hours: 1h30m (drops seconds for readability) Changes: - Add TotalSessionSeconds to GraphQL query and response types - Update daemon CCInfoCache and CCInfoResponse structs - Add CCStatuslineDailyStats type for cache and service layer - Add formatSessionDuration helper function - Update all related tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the AI agent statusline by integrating and displaying the total session time. It involves updating the data fetching logic to retrieve session duration from the backend, modifying internal data models to store this new metric, and adjusting the statusline rendering to present the time in a user-friendly, formatted manner. The changes ensure that users have a more comprehensive overview of their AI agent usage directly in the statusline. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request enhances the status line functionality by adding the display of AI agent session time alongside the existing cost and context percentage. This involved updating various data structures (e.g., CCInfoCache, CCInfoResponse, CCStatuslineDailyStats) to include session duration in seconds. The GraphQL API query was modified to fetch this new totalSessionSeconds field, and the daemon's caching and communication logic (cc_info_timer.go, socket.go) were adjusted to handle and transmit this data. A new formatSessionDuration helper function was introduced to convert seconds into a human-readable format for display. All related functions, including getDailyCostWithDaemonFallback (renamed to getDailyStatsWithDaemonFallback) and formatStatuslineOutput, were updated to incorporate the new session time. Corresponding test cases were also updated or added to cover these changes. A review comment suggested improving the CCStatuslineCacheSet function by calling time.Now() only once to ensure consistency for both Date and FetchedAt fields.
| statuslineCache.entry = &ccStatuslineCacheEntry{ | ||
| Date: time.Now().Format("2006-01-02"), | ||
| CostUsd: costUsd, | ||
| FetchedAt: time.Now(), | ||
| TTL: statuslineCache.ttl, | ||
| Date: time.Now().Format("2006-01-02"), | ||
| CostUsd: stats.Cost, | ||
| SessionSeconds: stats.SessionSeconds, | ||
| FetchedAt: time.Now(), | ||
| TTL: statuslineCache.ttl, | ||
| } |
There was a problem hiding this comment.
Calling time.Now() multiple times within the same function can lead to subtle bugs if the execution happens to cross a time boundary (like midnight). Here, Date and FetchedAt are derived from two separate calls.
To ensure consistency and atomicity for the timestamp, it's better to call time.Now() once and reuse the result.
| statuslineCache.entry = &ccStatuslineCacheEntry{ | |
| Date: time.Now().Format("2006-01-02"), | |
| CostUsd: costUsd, | |
| FetchedAt: time.Now(), | |
| TTL: statuslineCache.ttl, | |
| Date: time.Now().Format("2006-01-02"), | |
| CostUsd: stats.Cost, | |
| SessionSeconds: stats.SessionSeconds, | |
| FetchedAt: time.Now(), | |
| TTL: statuslineCache.ttl, | |
| } | |
| now := time.Now() | |
| statuslineCache.entry = &ccStatuslineCacheEntry{ | |
| Date: now.Format("2006-01-02"), | |
| CostUsd: stats.Cost, | |
| SessionSeconds: stats.SessionSeconds, | |
| FetchedAt: now, | |
| TTL: statuslineCache.ttl, | |
| } |
Summary
totalSessionSecondsfrom backend GraphQL API to the CC statusline display🤖 model | 💰 $session | 📊 $daily | ⏱️ time | 📈 context%45s,2m5s, or1h30mTest plan
🤖 Generated with Claude Code