Skip to content

Conversation

@ryoppippi
Copy link
Owner

@ryoppippi ryoppippi commented Jun 17, 2025

Summary

This PR adds comprehensive JSDoc documentation throughout the codebase to improve developer experience and code maintainability.

Changes Made

  • Type Definitions & Constants: Added JSDoc for shared types, CLI arguments, and configuration constants
  • Core Utilities: Documented logger, cost calculation, and formatting functions
  • Data Processing: Added documentation for data loading, aggregation, and validation schemas
  • Pricing System: Comprehensive documentation for LiteLLM integration and cost calculations
  • Session Blocks: Detailed docs for billing period analysis and usage projections
  • Debug Tools: Documentation for pricing mismatch detection and reporting
  • CLI Commands: Added docs for command infrastructure and user interface components

Test Plan

  • All existing tests pass
  • TypeScript compilation succeeds
  • ESLint formatting applied
  • JSDoc comments follow consistent style
  • Function parameters and return types documented
  • Complex algorithms explained with clear descriptions

Benefits

  • Easier onboarding for new contributors
  • Better IDE intellisense and autocomplete
  • Clear understanding of function purposes and parameters
  • Improved code maintainability
  • Consistent documentation style across the codebase

Summary by CodeRabbit

  • Documentation
    • Added comprehensive inline documentation throughout the codebase, including detailed descriptions for constants, types, classes, and functions.
    • Improved clarity on parameters, return values, and usage of various exported entities.
    • Enhanced code readability and maintainability with JSDoc-style comments.
    • No changes to application behavior or functionality.

Add comprehensive JSDoc documentation for:
- Cost calculation modes and sort order types in types.internal.ts
- Shared CLI argument definitions in shared-args.internal.ts
- LiteLLM pricing URL constant in consts.internal.ts

These foundational types and constants are used throughout the application
and benefit from clear documentation explaining their purpose and usage.
Add JSDoc documentation for:
- Logger instance and console.log export in logger.ts
- Token calculation and aggregation functions in calculate-cost.ts

These utility functions are fundamental building blocks used across
the application for logging and cost calculations.
Add JSDoc documentation for:
- Number, currency, and model name formatting functions in utils.internal.ts
- ResponsiveTable class and helper methods in utils.table.ts

These utilities handle data presentation and table rendering with
responsive design for different terminal widths.
Add comprehensive JSDoc documentation for PricingFetcher class:
- Class overview and Disposable pattern implementation
- Model pricing fetching and caching methods
- Cost calculation functions with detailed parameter documentation

The PricingFetcher is critical for accurate cost calculations from
LiteLLM pricing data with fallback matching for model names.
Add JSDoc documentation for pricing mismatch detection:
- Threshold constants and type definitions for discrepancy tracking
- Functions to detect and analyze pricing mismatches between
  pre-calculated costs and token-based calculations
- Comprehensive reporting functionality for debugging cost differences

This helps developers and users identify and troubleshoot pricing
calculation inconsistencies in usage data.
Add comprehensive JSDoc documentation for session block management:
- Type definitions for usage entries, blocks, and projections
- Block identification and creation algorithms
- Burn rate calculation and usage projection functions
- Recent block filtering for time-based analysis

Session blocks are core to billing period analysis and represent
5-hour usage windows with gap detection and projection capabilities.
Add JSDoc documentation for core data loading functionality:
- Valibot schemas for usage data validation
- Type definitions for daily, monthly, and session usage
- Data loading functions with filtering and aggregation
- Claude data directory path resolution and cost calculation modes

The data loader is the foundation of the application, handling JSONL
file processing, deduplication, and cost calculation integration.
Add JSDoc documentation for command line interface:
- Main command setup and subcommand mapping in commands/index.ts
- Session blocks command with formatting and parsing utilities
- Constants for display thresholds and terminal width handling

These command modules provide the user-facing CLI interface with
responsive display formatting and comprehensive usage reporting.
@coderabbitai
Copy link

coderabbitai bot commented Jun 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces comprehensive JSDoc-style documentation across the codebase, annotating types, constants, functions, and classes in multiple modules. The changes clarify the purpose, parameters, and return values of exported entities, improving code readability and maintainability. No logic, control flow, or functional behavior is altered; all modifications are purely documentation enhancements.

Changes

File(s) Change Summary
src/calculate-cost.ts Added JSDoc comments to types and functions describing token and cost calculations.
src/commands/blocks.ts Added JSDoc comments to constants and functions for session block formatting and argument parsing.
src/commands/index.ts Replaced inline comments with JSDoc comments for CLI subcommands and main command.
src/consts.internal.ts Added JSDoc comment to the LiteLLM pricing URL constant.
src/data-loader.ts Added comprehensive JSDoc comments to constants, types, schemas, and all exported functions.
src/debug.ts Added JSDoc comments to constants, types, and functions for pricing mismatch detection and reporting.
src/logger.ts Added JSDoc comments to exported logger and log constants.
src/pricing-fetcher.ts Added JSDoc comments to PricingFetcher class and all its methods.
src/session-blocks.internal.ts Added JSDoc comments to all exported types, constants, and functions for session block logic.
src/shared-args.internal.ts Added JSDoc comments to shared CLI argument and command configuration entities.
src/types.internal.ts Added JSDoc comments to validators, type unions, and schemas for cost modes, sort orders, and model pricing.
src/utils.internal.ts Added JSDoc comments to utility functions for formatting numbers, currency, and model names.
src/utils.table.ts Added JSDoc comments to table types, options, and the ResponsiveTable class and its methods.

Possibly related PRs

  • ryoppippi/ccusage#52: Extends usage data structures and tests to include model breakdowns and usage details, modifying data handled by functions that are now documented in this PR.

Poem

🐇✨
With every docstring, clear and bright,
The code now shines with readable light.
Types and functions, once a haze,
Are crystal clear in their documented ways.
A bunny’s joy—no logic to mend,
Just comments to help every friend!
📚💡


📜 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 f67f7eb and a41bb2d.

📒 Files selected for processing (13)
  • src/calculate-cost.ts (3 hunks)
  • src/commands/blocks.ts (3 hunks)
  • src/commands/index.ts (1 hunks)
  • src/consts.internal.ts (1 hunks)
  • src/data-loader.ts (15 hunks)
  • src/debug.ts (4 hunks)
  • src/logger.ts (1 hunks)
  • src/pricing-fetcher.ts (4 hunks)
  • src/session-blocks.internal.ts (8 hunks)
  • src/shared-args.internal.ts (3 hunks)
  • src/types.internal.ts (1 hunks)
  • src/utils.internal.ts (2 hunks)
  • src/utils.table.ts (4 hunks)
✨ 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 17, 2025

Open in StackBlitz

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

commit: a41bb2d

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 @ryoppippi, 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 is a significant documentation effort, introducing comprehensive JSDoc comments throughout the entire codebase. The primary goal is to enhance developer experience, improve code maintainability, and provide clearer understanding of the system's various components, from core utilities to CLI commands and data processing logic.

Highlights

  • Comprehensive Documentation: Added extensive JSDoc comments to all functions, types, and constants across the codebase to improve clarity and maintainability.
  • Improved Developer Experience: The new documentation enhances IDE intellisense, autocompletion, and makes onboarding for new contributors significantly easier.
  • Core Utilities & Data Processing: Documented key utility functions for logging, cost calculation, formatting, and data handling including loading, aggregation, and validation schemas.
  • Pricing & Session Analysis: Provided detailed JSDoc for the LiteLLM integration, cost calculation logic, and session block analysis for billing and usage projections.
  • CLI & Debugging Tools: Documented CLI command infrastructure, user interface components, and tools for detecting pricing mismatches.
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.

@ryoppippi ryoppippi merged commit 02b9296 into main Jun 17, 2025
9 of 10 checks passed
@ryoppippi ryoppippi deleted the ryoppippi/ccusage-docs branch June 17, 2025 18:20
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 successfully adds comprehensive JSDoc documentation across the codebase, significantly improving clarity and maintainability. The documentation covers types, constants, and functions as described, with clear descriptions, parameters, and return values. The effort to document various parts of the system, including data loading, pricing, session blocks, and CLI arguments, is commendable and will greatly benefit developers working with this code. One minor suggestion is to ensure documentation accurately reflects unused parameters if they are not intended for future use.

/**
* Formats the list of models used in a block for display
* @param models - Array of model names
* @param compact - Whether to use compact formatting (unused currently)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The JSDoc notes that the compact parameter is currently unused. If compact formatting is not intended to be implemented for this function, consider removing the parameter and updating the description to avoid confusion.

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