Skip to content

Conversation

@dalmia007
Copy link
Contributor

@dalmia007 dalmia007 commented Jun 22, 2025

Summary by CodeRabbit

  • Style
    • Improved formatting and readability of live monitoring display functions. No changes to app behavior or output.

@coderabbitai
Copy link

coderabbitai bot commented Jun 22, 2025

Walkthrough

The update adds a call to clear the monitor cache after each fetch of the active block in the live monitoring loop. Additionally, the codebase undergoes extensive formatting changes for improved readability, particularly in error handling and rendering functions, without altering any logic or output content.

Changes

File(s) Change Summary
src/commands/_blocks.live.ts Added monitor.clearCache() after fetching active block; reformatted error handling and rendering functions for readability; no logic changes.

Possibly related PRs

Suggested reviewers

  • ryoppippi

Poem

In the code where live blocks gleam,
A cache is cleared—like a fresh stream!
Formatting neat, lines now align,
Ternaries dance in orderly design.
The rabbit hops, with joy anew,
For code that’s clear and easier to view!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b76448f129add9405d2be19292fd44064dcde86 and a0f9c48.

📒 Files selected for processing (1)
  • src/commands/_blocks.live.ts (15 hunks)
🧰 Additional context used
🪛 ESLint
src/commands/_blocks.live.ts

[error] 196-196: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 196-196: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 196-196: Unsafe member access .cyan on an error typed value.

(ts/no-unsafe-member-access)


[error] 197-197: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 197-197: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 197-197: Unsafe member access .gray on an error typed value.

(ts/no-unsafe-member-access)


[error] 219-219: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 219-219: Unsafe member access .bold on an error typed value.

(ts/no-unsafe-member-access)


[error] 225-225: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 225-225: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 225-225: Unsafe member access .bold on an error typed value.

(ts/no-unsafe-member-access)


[error] 226-226: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 226-226: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 229-229: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 244-244: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 270-270: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 270-270: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 271-271: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 271-271: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 271-271: Unsafe member access .gray on an error typed value.

(ts/no-unsafe-member-access)


[error] 275-275: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 275-275: Unsafe member access .green on an error typed value.

(ts/no-unsafe-member-access)


[error] 275-275: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 275-275: Unsafe member access .gray on an error typed value.

(ts/no-unsafe-member-access)


[error] 279-286: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 282-282: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 282-282: Unsafe member access .red on an error typed value.

(ts/no-unsafe-member-access)


[error] 284-284: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 284-284: Unsafe member access .yellow on an error typed value.

(ts/no-unsafe-member-access)


[error] 285-285: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 285-285: Unsafe member access .green on an error typed value.

(ts/no-unsafe-member-access)


[error] 289-289: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 289-289: Unsafe member access .bold on an error typed value.

(ts/no-unsafe-member-access)


[error] 290-290: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 290-290: Unsafe member access .bold on an error typed value.

(ts/no-unsafe-member-access)


[error] 293-293: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 293-293: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 293-293: Unsafe member access .bold on an error typed value.

(ts/no-unsafe-member-access)


[error] 294-294: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 294-294: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 298-298: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 313-313: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 319-319: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 332-332: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 362-362: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 362-362: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 363-363: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 363-363: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 363-363: Unsafe member access .gray on an error typed value.

(ts/no-unsafe-member-access)


[error] 367-367: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 367-367: Unsafe member access .green on an error typed value.

(ts/no-unsafe-member-access)


[error] 367-367: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 367-367: Unsafe member access .gray on an error typed value.

(ts/no-unsafe-member-access)


[error] 369-376: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 372-372: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 372-372: Unsafe member access .red on an error typed value.

(ts/no-unsafe-member-access)


[error] 374-374: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 374-374: Unsafe member access .yellow on an error typed value.

(ts/no-unsafe-member-access)


[error] 375-375: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 375-375: Unsafe member access .green on an error typed value.

(ts/no-unsafe-member-access)


[error] 376-376: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 376-376: Unsafe member access .green on an error typed value.

(ts/no-unsafe-member-access)


[error] 379-379: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 379-379: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 379-379: Unsafe member access .bold on an error typed value.

(ts/no-unsafe-member-access)


[error] 380-380: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 380-380: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 384-384: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 399-399: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 405-405: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 420-420: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 432-432: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 469-470: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 470-470: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 470-470: Unsafe member access .red on an error typed value.

(ts/no-unsafe-member-access)


[error] 470-470: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 470-470: Unsafe member access .yellow on an error typed value.

(ts/no-unsafe-member-access)


[error] 470-470: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 470-470: Unsafe member access .green on an error typed value.

(ts/no-unsafe-member-access)

🔇 Additional comments (3)
src/commands/_blocks.live.ts (3)

107-110: Good formatting improvement for error handling.

Breaking the complex conditional checks into multiple lines improves readability while preserving the same logic.

Also applies to: 127-130


158-162: Good formatting improvement for function signature.

The multi-line parameter format with trailing comma improves readability and makes future parameter additions cleaner in diffs.


194-200: Excellent formatting improvements throughout the file.

The extensive formatting changes significantly improve code readability by:

  • Breaking long lines into manageable chunks
  • Properly formatting multi-line ternary operators
  • Consistent indentation for complex expressions
  • Clear separation of calculation logic

These changes make the code much easier to read and maintain without altering any functionality.

Also applies to: 203-214, 218-220, 228-229, 243-244, 251-254, 266-275, 279-290, 297-298, 312-313, 318-319, 331-332, 343-346, 358-367, 369-376, 383-384, 398-399, 404-405, 419-420, 431-432, 462-464, 469-473

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @dalmia007, 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 primarily addresses an issue where live usage tokens were not updating correctly in the monitoring display by introducing a cache-clearing step. Additionally, it includes significant code formatting improvements to enhance the readability and maintainability of the display rendering logic.

Highlights

  • Core Functionality Fix: Implemented a cache-clearing mechanism in the live monitoring loop (startLiveMonitoring) to ensure real-time updates of usage tokens, addressing the primary issue of stale data.
  • Code Readability & Formatting: Applied extensive formatting changes across display rendering functions (renderLiveDisplay and renderCompactLiveDisplay), including line breaks and indentation, to enhance code readability and maintainability.
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and 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 to provide feedback.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix an issue where live usage tokens were not updating. The main change involves clearing the LiveMonitor's cache on each refresh loop to force a full data reload.

While this approach likely resolves the stale data problem, it introduces a significant performance issue by disabling the incremental loading feature of LiveMonitor. My review focuses on this key change, recommending an investigation into the root cause of the update failure rather than using a brute-force cache clearing. The other changes in this PR are stylistic and appear to be from a code formatter, which I have not commented on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This change appears to fix the issue of tokens not updating, but it does so by completely disabling the incremental loading mechanism of LiveMonitor.

The LiveMonitor class is designed for efficiency by only reading new or modified files and processing new entries. Calling monitor.clearCache() on every loop iteration forces a full reload of all usage data files, which can be very inefficient, especially as the data grows. This negates the entire purpose of the LiveMonitor's caching and incremental update logic, as described in its documentation.

I recommend investigating the root cause of the stale data issue instead. It might be related to:

  • How file modifications are detected (e.g., issues with getEarliestTimestamp).
  • Caching logic within LiveMonitor that incorrectly filters out new data.

A targeted fix will be much more performant and maintainable. Please consider removing this line and debugging LiveMonitor.getActiveBlock() to find why it's not picking up new usage entries.

@ryoppippi
Copy link
Owner

ryoppippi commented Jun 22, 2025

@dalmia007 This PR looks good. can you start commit message with fix: ?
you can force push it

@dalmia007 dalmia007 changed the title Fix for live usage tokens not getting updated Fix: Fix for live usage tokens not getting updated Jun 22, 2025
@ryoppippi
Copy link
Owner

@dalmia007 I mean your commit message

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 22, 2025

Open in StackBlitz

npm i https://pkg.pr.new/ryoppippi/ccusage@164

commit: a0f9c48

@dalmia007 dalmia007 changed the title Fix: Fix for live usage tokens not getting updated Fix for live usage tokens not getting updated Jun 22, 2025
@dalmia007
Copy link
Contributor Author

@ryoppippi its done!

@ryoppippi ryoppippi requested a review from Copilot June 22, 2025 19:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures live token usage is updated by clearing the cache each refresh and improves readability of the live monitoring display formatting.

  • Adds monitor.clearCache() inside the monitoring loop to force reloads
  • Refactors multi-line progress bar and padding logic for consistent formatting
Comments suppressed due to low confidence (2)

src/commands/_blocks.live.ts:98

  • [nitpick] Consider adding a brief comment explaining why clearCache() is needed on each loop iteration to clarify its impact on live token updates.
			monitor.clearCache(); // Force reload for next refresh

src/commands/_blocks.live.ts:98

  • Add or update unit tests to verify that clearing the cache correctly triggers token usage refresh in the live monitoring loop.
			monitor.clearCache(); // Force reload for next refresh

while (!abortController.signal.aborted) {
// Get active block with lightweight refresh
const activeBlock = await monitor.getActiveBlock();
monitor.clearCache(); // Force reload for next refresh
Copy link

Copilot AI Jun 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing the cache on every refresh may affect performance; consider invoking clearCache() only when token data actually changes.

Suggested change
monitor.clearCache(); // Force reload for next refresh
// Clear cache only if token data has changed
if (activeBlock?.tokenData !== previousTokenData) {
monitor.clearCache();
previousTokenData = activeBlock?.tokenData;
}

Copilot uses AI. Check for mistakes.
const sessionBarStr = `${sessionLabel}${''.padEnd(Math.max(0, labelWidth - sessionLabelWidth))} ${sessionProgressBar} ${sessionPercent.toFixed(1).padStart(6)}%`;
const sessionBarPadded = sessionBarStr + ' '.repeat(Math.max(0, boxWidth - 3 - stringWidth(sessionBarStr)));
const sessionBarPadded
= sessionBarStr + ' '.repeat(Math.max(0, boxWidth - 3 - stringWidth(sessionBarStr)));
Copy link

Copilot AI Jun 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] There’s duplicated padding logic across several sections; consider extracting a helper function (e.g., padToWidth) to reduce repetition.

Suggested change
= sessionBarStr + ' '.repeat(Math.max(0, boxWidth - 3 - stringWidth(sessionBarStr)));
= sessionBarStr + padToWidth('', Math.max(0, boxWidth - 3 - stringWidth(sessionBarStr)));

Copilot uses AI. Check for mistakes.
@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🔵 In progress
View logs
ccusage-guide a0f9c48 Jun 22 2025, 07:06 PM

@ryoppippi
Copy link
Owner

ryoppippi commented Jun 22, 2025

Damm it changes styles a lot.
I need format it.
Please send a PR with critical changes

So the change is all about monitor.clearCache(); // Force reload for next refresh and other stuff is not the changes, right?

@ryoppippi
Copy link
Owner

Oh you mistakenly close it? I'm just reviewing your changes
@dalmia007

@ryoppippi
Copy link
Owner

Please explain what is the changes and why it matters.
I'm really appreciate that you have interests to fix this issue!
@dalmia007

@dalmia007
Copy link
Contributor Author

@ryoppippi I deleted the branch in my repo and I think it closed the PR. I will open a new one. The only change I have made is adding the monitor.clearCache() after the activeBlock is defined. At the moment the activeBlock is not getting updated between refreshes. My solution my might not be the best honestly. Its more of a quick fix.

@ryoppippi
Copy link
Owner

ok I got it.
Please send a new PR with this small changes. I'll see the format by myself.
create a commit by git commint -n -m "fix:blablra"!!!
@dalmia007

@dalmia007
Copy link
Contributor Author

I have created a new PR

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.

2 participants