Skip to content

Conversation

@ryoppippi
Copy link
Owner

@ryoppippi ryoppippi commented Sep 17, 2025

Summary

This PR extracts terminal utilities into a dedicated @ccusage/terminal package to improve the monorepo structure and enable better code reuse across packages.

What Changed

  • New @ccusage/terminal package created

    • Created new private package at packages/terminal
    • Exports two modules: /table and /utils
    • Preserves all in-source tests with vitest
    • Logger is now passed as a constructor option (defaults to console.warn)
  • Files moved

    • apps/ccusage/src/_terminal-utils.tspackages/terminal/src/utils.ts
    • apps/ccusage/src/_table.tspackages/terminal/src/table.ts
  • Dependencies reorganized

    • cli-table3 moved to @ccusage/terminal dependencies
    • ansi-escapes and string-width remain in both packages as needed
    • @oxc-project/runtime kept in dependencies for potential future use
  • All imports updated across ccusage

    • Updated 12 files to import from @ccusage/terminal/table
    • Updated 2 files to import from @ccusage/terminal/utils
  • Configuration files added

    • ESLint config with svelte disabled
    • TypeScript config extending root config
    • Vitest config for in-source testing

Why

  • Improved Monorepo Structure: Separates terminal utilities into a focused, reusable package
  • Better Code Organization: Terminal-specific functionality is now isolated and can be shared
  • Maintainability: Changes to terminal utilities won't affect core ccusage logic
  • Future-Proofing: Other packages can now reuse terminal utilities without code duplication

Testing

  • ✅ All existing tests preserved and passing (305 total tests)
  • ✅ All 30 tests in the new terminal package passing
  • ✅ Type checking successful across all packages
  • ✅ ESLint formatting applied and passing
  • ✅ No breaking changes for end users

Related Issues

None - this is a proactive refactoring to improve codebase organization.

Summary by CodeRabbit

  • New Features

    • Introduced a shared terminal utilities package for formatting and rendering.
  • Refactor

    • Migrated app imports to use the new terminal utilities package. No functional changes expected.
  • Chores

    • Updated workspace to include new packages directory and adjusted dependencies.
  • Tests

    • Added a test configuration for the terminal utilities package.
  • Style

    • Added an ESLint configuration for the terminal utilities package.
  • Other

    • Standardized warning output to use console.warn when no custom logger is provided.

…terminal package

This is a significant refactoring to improve the monorepo structure by extracting
reusable terminal utilities into a dedicated package.

## Changes made:

### New @ccusage/terminal package created
- Created new private package at packages/terminal
- Exports two modules: /table and /utils
- Preserves all in-source tests with vitest
- Logger is now passed as a constructor option (defaults to console.warn)

### Files moved:
- apps/ccusage/src/_terminal-utils.ts → packages/terminal/src/utils.ts
- apps/ccusage/src/_table.ts → packages/terminal/src/table.ts

### Dependencies reorganized:
- cli-table3 moved to @ccusage/terminal dependencies
- ansi-escapes and string-width remain in both packages as needed
- @oxc-project/runtime kept in dependencies for potential future use

### All imports updated across ccusage:
- Updated 12 files to import from @ccusage/terminal/table
- Updated 2 files to import from @ccusage/terminal/utils
- All tests passing (275 tests in ccusage, 30 tests in terminal)

### Configuration files added:
- ESLint config with svelte disabled
- TypeScript config extending root config
- Vitest config for in-source testing

## Testing:
- All existing tests preserved and passing
- Type checking successful
- ESLint formatting applied
@coderabbitai
Copy link

coderabbitai bot commented Sep 17, 2025

Walkthrough

Introduces a new internal package "@ccusage/terminal" and updates ccusage app imports to use it. Adds workspace configuration for packages, ESLint, TS, and Vitest configs for the terminal package. Adjusts ccusage devDependencies. Changes a default logger fallback in the terminal table implementation to use console.warn.

Changes

Cohort / File(s) Summary
App devDependency update
apps/ccusage/package.json
Adds devDependency @ccusage/terminal (workspace), removes cli-table3 devDependency.
App import path migration (terminal/utils & table)
apps/ccusage/src/_live-rendering.ts, apps/ccusage/src/commands/_blocks.live.ts, apps/ccusage/src/commands/_session_id.ts, apps/ccusage/src/commands/blocks.ts, apps/ccusage/src/commands/daily.ts, apps/ccusage/src/commands/monthly.ts, apps/ccusage/src/commands/session.ts, apps/ccusage/src/commands/statusline.ts, apps/ccusage/src/commands/weekly.ts
Switches imports from local files to @ccusage/terminal/{table,utils} for the same symbols; no logic changes.
New terminal package setup
packages/terminal/package.json, packages/terminal/src/table.ts, packages/terminal/eslint.config.js, packages/terminal/tsconfig.json, packages/terminal/vitest.config.ts
Creates @ccusage/terminal package with ESM exports ./table and ./utils, project tooling configs, and adjusts default logger in ResponsiveTable to console.warn.
Workspace configuration
pnpm-workspace.yaml
Adds packages/* to workspace globs.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CCUsage App
  participant TerminalPkg as @ccusage/terminal
  User->>CCUsage App: Run command
  CCUsage App->>TerminalPkg: Import utils/table APIs
  CCUsage App->>TerminalPkg: Build/Render tables
  alt No custom logger provided
    TerminalPkg-->>CCUsage App: Fallback to console.warn
  else Custom logger provided
    TerminalPkg-->>CCUsage App: Use provided logger
  end
  CCUsage App-->>User: Rendered output
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I hopped through paths with tidy cheer,
Packed up tables, brought them near—
A terminal burrow, clean and bright,
Where logs now whisper with console light.
Imports align, the carrots stack,
Monorepo trails on a single track. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely summarizes the primary change—extracting terminal utilities into a dedicated @ccusage/terminal package—and uses an appropriate refactor(scope) prefix. It accurately reflects the PR objectives and the reported file moves and import updates, making the main intent understandable to reviewers.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/extract-terminal-package

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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 significantly refactors the project's structure by extracting terminal-related utility functions and components from the main "ccusage" application into a new, dedicated monorepo package named "@ccusage/terminal". This strategic move aims to enhance modularity, promote code reuse across different parts of the monorepo, and centralize terminal-specific logic, ultimately improving maintainability and organization without introducing breaking changes for end-users.

Highlights

  • New Package Creation: A new private package, "@ccusage/terminal", has been introduced under "packages/terminal" to house shared terminal utilities.
  • Utility Extraction: Core terminal utilities, previously found in "_table.ts" and "_terminal-utils.ts" within "apps/ccusage/src", have been moved to the new "@ccusage/terminal" package.
  • Dependency Reorganization: Dependencies like "cli-table3" have been relocated to the new terminal package, while "ansi-escapes" and "string-width" remain in both where needed.
  • Import Path Updates: All relevant import statements across the "ccusage" application have been updated to reference the new "@ccusage/terminal" package.
  • Dedicated Configuration: The new package includes its own ESLint, TypeScript, and Vitest configuration files, ensuring independent setup and testing.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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

  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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 17, 2025

Open in StackBlitz

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

commit: cd8943d

@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)
✅ Deployment successful!
View logs
ccusage-guide cd8943d Sep 17 2025, 06:51 PM

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 effectively refactors terminal-related utilities into a new, dedicated @ccusage/terminal package. This is a solid improvement for the monorepo's structure, enhancing modularity and code reuse. The file moves, dependency updates, and new package configurations are well-executed. I have a few suggestions regarding dependency management and configuration to further improve maintainability and robustness.

os: win32
version: 1.2.22
hasBin: true
version: 0.0.0
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 in the lockfile for bun@runtime from version 1.2.22 to 0.0.0 is suspicious. While it might be an artifact of how pnpm handles runtime: specifiers, a zeroed-out version could potentially break environment setup in CI or for other developers. Could you please verify if this change is intentional and correct? If it's an unintended side effect, it might be worth investigating why pnpm made this change.

"format": "pnpm run lint --fix"
},
"dependencies": {
"@oxc-project/runtime": "catalog:build",
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 dependency @oxc-project/runtime is included but doesn't seem to be used anywhere in the new @ccusage/terminal package. The PR description mentions keeping it for "potential future use," but it's generally better to add dependencies only when they are actually needed to avoid package bloat and potential security vulnerabilities from unmaintained dependencies. I suggest removing this line for now. It can always be added back later when it's required.

@@ -0,0 +1,38 @@
{
"compilerOptions": {
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 PR description mentions that this new TypeScript config extends the root config, but the extends property is missing. In a monorepo, it's a best practice for package-level tsconfig.json files to extend a common base configuration from the root. This ensures consistency in compiler options across the project and makes maintenance easier. Please add an extends property pointing to the root tsconfig.base.json (or equivalent).

Suggested change
"compilerOptions": {
"extends": "../../tsconfig.base.json",
"compilerOptions": {

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/terminal/src/table.ts (2)

64-65: Avoid console. as default logger; prefer a no‑op to comply with “no console” guideline.*

This package shouldn’t depend on ccusage’s logger, but defaulting to console.warn violates the guideline. Use a no‑op and log only when a logger is supplied.

-		this.logger = options.logger ?? console.warn;
+		// Default to silent; consumers may inject their own logger.
+		this.logger = options.logger ?? (() => {});

932-936: Fix misleading comment about toFixed rounding.

The "$10.99" expectation for 10.995 arises from IEEE‑754 representation/rounding quirks, not “banker’s rounding.” Update the comment to avoid confusion.

-			expect(formatCurrency(10.995)).toBe('$10.99'); // JavaScript's toFixed uses banker's rounding
+			// Note: 10.995 is not exactly representable in binary; Number#toFixed(2) often yields 10.99.
+			expect(formatCurrency(10.995)).toBe('$10.99');
packages/terminal/tsconfig.json (1)

4-5: Remove JSX setting (not used here).

This package doesn’t use React/JSX; drop jsx to reduce noise.

-		"jsx": "react-jsx",
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7156aa and cd8943d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (16)
  • apps/ccusage/package.json (1 hunks)
  • apps/ccusage/src/_live-rendering.ts (2 hunks)
  • apps/ccusage/src/commands/_blocks.live.ts (1 hunks)
  • apps/ccusage/src/commands/_session_id.ts (1 hunks)
  • apps/ccusage/src/commands/blocks.ts (1 hunks)
  • apps/ccusage/src/commands/daily.ts (2 hunks)
  • apps/ccusage/src/commands/monthly.ts (2 hunks)
  • apps/ccusage/src/commands/session.ts (2 hunks)
  • apps/ccusage/src/commands/statusline.ts (1 hunks)
  • apps/ccusage/src/commands/weekly.ts (2 hunks)
  • packages/terminal/eslint.config.js (1 hunks)
  • packages/terminal/package.json (1 hunks)
  • packages/terminal/src/table.ts (1 hunks)
  • packages/terminal/tsconfig.json (1 hunks)
  • packages/terminal/vitest.config.ts (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Use ESLint formatting with tab indentation and double quotes
Do not use console.log; use logger.ts instead (only allow via explicit eslint-disable if unavoidable)
Always use Node.js path utilities (path, fs, URL) for file paths for cross-platform compatibility
Use .ts extensions for local file imports (e.g., import { foo } from "./utils.ts")
Prefer @praha/byethrow Result type over traditional try/catch for error handling
Wrap throwable operations with Result.try() and check with Result.isFailure()/Result.isSuccess()
Favor early returns for failures (e.g., if (Result.isFailure(r)) return/continue) over ternaries
Keep traditional try/catch only for complex file I/O or legacy code that’s hard to refactor
Use in-source testing via if (import.meta.vitest != null) blocks; tests live in the same files as source
Vitest globals are enabled—use describe, it, expect without imports
Never use await import() dynamic imports anywhere; especially never in Vitest test blocks
All tests must use current Claude 4 model names (Sonnet and Opus) matching LiteLLM’s pricing database
Model naming must follow claude-{model-type}-{generation}-{date} (e.g., claude-sonnet-4-20250514)
Verify new model names exist in LiteLLM before adding tests; failures often indicate missing pricing entries

Files:

  • apps/ccusage/src/commands/statusline.ts
  • apps/ccusage/src/_live-rendering.ts
  • apps/ccusage/src/commands/daily.ts
  • apps/ccusage/src/commands/_blocks.live.ts
  • apps/ccusage/src/commands/weekly.ts
  • apps/ccusage/src/commands/session.ts
  • apps/ccusage/src/commands/monthly.ts
  • apps/ccusage/src/commands/_session_id.ts
  • apps/ccusage/src/commands/blocks.ts
  • packages/terminal/vitest.config.ts
  • packages/terminal/src/table.ts
apps/ccusage/src/**/*.ts

📄 CodeRabbit inference engine (apps/ccusage/CLAUDE.md)

apps/ccusage/src/**/*.ts: Write tests in-source using if (import.meta.vitest != null) blocks rather than separate test files
Use Vitest globals (describe, it, expect) directly without imports in test blocks
In tests, use current Claude 4 models (sonnet-4, opus-4)
Use fs-fixture with createFixture() for mock Claude data in tests
Prefer @praha/byethrow Result-based error handling over try/catch
Use explicit .ts extensions for local imports (e.g., import { x } from './utils.ts')
Only export symbols that are actually used by other modules
Do not use console.log; use the logger.ts utilities instead

Files:

  • apps/ccusage/src/commands/statusline.ts
  • apps/ccusage/src/_live-rendering.ts
  • apps/ccusage/src/commands/daily.ts
  • apps/ccusage/src/commands/_blocks.live.ts
  • apps/ccusage/src/commands/weekly.ts
  • apps/ccusage/src/commands/session.ts
  • apps/ccusage/src/commands/monthly.ts
  • apps/ccusage/src/commands/_session_id.ts
  • apps/ccusage/src/commands/blocks.ts
apps/ccusage/**/!(*.d).ts

📄 CodeRabbit inference engine (apps/ccusage/CLAUDE.md)

Do not use dynamic await import() anywhere (especially in test blocks)

Files:

  • apps/ccusage/src/commands/statusline.ts
  • apps/ccusage/src/_live-rendering.ts
  • apps/ccusage/src/commands/daily.ts
  • apps/ccusage/src/commands/_blocks.live.ts
  • apps/ccusage/src/commands/weekly.ts
  • apps/ccusage/src/commands/session.ts
  • apps/ccusage/src/commands/monthly.ts
  • apps/ccusage/src/commands/_session_id.ts
  • apps/ccusage/src/commands/blocks.ts
**/_*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Internal-only modules should use underscore-prefixed filenames (e.g., _types.ts, _utils.ts, _consts.ts)

Files:

  • apps/ccusage/src/_live-rendering.ts
  • apps/ccusage/src/commands/_blocks.live.ts
  • apps/ccusage/src/commands/_session_id.ts
**/package.json

📄 CodeRabbit inference engine (CLAUDE.md)

Add dependencies as devDependencies unless explicitly required otherwise

Files:

  • packages/terminal/package.json
  • apps/ccusage/package.json
apps/ccusage/**/package.json

📄 CodeRabbit inference engine (apps/ccusage/CLAUDE.md)

Add packages as devDependencies unless explicitly required as runtime dependencies

Files:

  • apps/ccusage/package.json
**/tsconfig.json

📄 CodeRabbit inference engine (CLAUDE.md)

Enable TypeScript strict mode and bundler module resolution in tsconfig

Files:

  • packages/terminal/tsconfig.json
🧠 Learnings (16)
📓 Common learnings
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/src/**/*.ts : Use explicit `.ts` extensions for local imports (e.g., `import { x } from './utils.ts'`)
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/src/**/*.ts : Do not use `console.log`; use the `logger.ts` utilities instead
📚 Learning: 2025-09-17T18:28:29.654Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:29.654Z
Learning: CLI architecture: data-loader.ts parses JSONL from Claude directories; calculate-cost.ts aggregates tokens/costs; commands/ orchestrate; index.ts wires CLI routes

Applied to files:

  • apps/ccusage/src/commands/statusline.ts
  • apps/ccusage/src/commands/daily.ts
  • apps/ccusage/src/commands/weekly.ts
  • apps/ccusage/src/commands/session.ts
  • apps/ccusage/src/commands/monthly.ts
  • apps/ccusage/src/commands/blocks.ts
📚 Learning: 2025-09-17T18:28:48.879Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/src/**/*.ts : Use explicit `.ts` extensions for local imports (e.g., `import { x } from './utils.ts'`)

Applied to files:

  • apps/ccusage/src/_live-rendering.ts
  • apps/ccusage/src/commands/_blocks.live.ts
  • apps/ccusage/src/commands/weekly.ts
  • apps/ccusage/src/commands/session.ts
  • apps/ccusage/src/commands/_session_id.ts
  • apps/ccusage/src/commands/blocks.ts
📚 Learning: 2025-09-17T18:28:48.879Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/src/**/*.ts : Only export symbols that are actually used by other modules

Applied to files:

  • apps/ccusage/src/_live-rendering.ts
  • packages/terminal/package.json
  • apps/ccusage/src/commands/blocks.ts
📚 Learning: 2025-09-17T18:28:48.879Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/**/package.json : Add packages as `devDependencies` unless explicitly required as runtime dependencies

Applied to files:

  • apps/ccusage/package.json
📚 Learning: 2025-09-17T18:29:15.753Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/mcp/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:29:15.753Z
Learning: Applies to apps/mcp/**/package.json : Add new dependencies as `devDependencies` unless explicitly requested otherwise

Applied to files:

  • apps/ccusage/package.json
📚 Learning: 2025-09-17T18:28:29.654Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:29.654Z
Learning: Applies to **/tsconfig.json : Enable TypeScript strict mode and bundler module resolution in tsconfig

Applied to files:

  • packages/terminal/tsconfig.json
📚 Learning: 2025-09-17T18:28:29.654Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:29.654Z
Learning: Applies to **/*.{ts,tsx} : Vitest globals are enabled—use describe, it, expect without imports

Applied to files:

  • packages/terminal/tsconfig.json
  • packages/terminal/vitest.config.ts
📚 Learning: 2025-09-17T18:28:29.654Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:29.654Z
Learning: Applies to **/*.{ts,tsx} : Use in-source testing via if (import.meta.vitest != null) blocks; tests live in the same files as source

Applied to files:

  • packages/terminal/tsconfig.json
  • packages/terminal/vitest.config.ts
📚 Learning: 2025-09-17T18:28:29.654Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:29.654Z
Learning: Use pnpm scripts: test (vitest, no watch), format (ESLint fix), typecheck (TS), build (tsdown), release (full workflow)

Applied to files:

  • packages/terminal/tsconfig.json
📚 Learning: 2025-09-17T18:28:48.879Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/src/**/*.ts : Prefer `praha/byethrow` Result-based error handling over try/catch

Applied to files:

  • apps/ccusage/src/commands/_session_id.ts
📚 Learning: 2025-09-17T18:28:48.879Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/**/!(*.d).ts : Do not use dynamic `await import()` anywhere (especially in test blocks)

Applied to files:

  • apps/ccusage/src/commands/blocks.ts
📚 Learning: 2025-09-17T18:29:15.753Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/mcp/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:29:15.753Z
Learning: Applies to apps/mcp/**/*.{test,spec}.ts : Vitest globals enabled: use `describe`, `it`, `expect` directly without importing them

Applied to files:

  • packages/terminal/vitest.config.ts
📚 Learning: 2025-09-17T18:28:48.879Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/src/**/*.ts : Use Vitest globals (`describe`, `it`, `expect`) directly without imports in test blocks

Applied to files:

  • packages/terminal/vitest.config.ts
📚 Learning: 2025-09-17T18:28:48.879Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/src/**/*.ts : Write tests in-source using `if (import.meta.vitest != null)` blocks rather than separate test files

Applied to files:

  • packages/terminal/vitest.config.ts
📚 Learning: 2025-09-17T18:28:48.879Z
Learnt from: CR
PR: ryoppippi/ccusage#0
File: apps/ccusage/CLAUDE.md:0-0
Timestamp: 2025-09-17T18:28:48.879Z
Learning: Applies to apps/ccusage/src/**/*.ts : Do not use `console.log`; use the `logger.ts` utilities instead

Applied to files:

  • packages/terminal/src/table.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: Workers Builds: ccusage-guide
🔇 Additional comments (14)
pnpm-workspace.yaml (1)

4-4: Workspace inclusion LGTM.

Adding packages/* cleanly brings the new package into the workspace.

packages/terminal/eslint.config.js (1)

1-5: ESLint config LGTM.

Svelte disabled and shared config applied appropriately for the new package.

apps/ccusage/src/commands/statusline.ts (1)

16-16: Import switch LGTM.

Switching formatCurrency to @ccusage/terminal centralizes terminal concerns without behavioral change.

apps/ccusage/src/commands/weekly.ts (1)

1-1: Imports consolidated to @ccusage/terminal — looks good.

Type and helpers sourced from the new package with no runtime changes.

Also applies to: 10-10

apps/ccusage/package.json (1)

54-61: Verify whether @ccusage/terminal is bundled; otherwise promote to dependencies.

Sandbox build failed (sh: 1: bun: not found; node_modules missing), so I couldn't inspect apps/ccusage/dist. Run locally with dependencies installed and bun available, then run:

#!/bin/bash
set -euo pipefail
pnpm -w -C apps/ccusage run build
rg -nP "@ccusage/terminal(?:/|['\"])|from\s+['\"]@ccusage/terminal" apps/ccusage/dist 2>/dev/null \
  && echo "Found imports of @ccusage/terminal in dist — move it to dependencies." \
  || echo "No imports found in dist — safe to keep as devDependency."

If imports are found → move @ccusage/terminal from devDependencies to dependencies.

apps/ccusage/src/_live-rendering.ts (1)

10-10: LGTM: import path switch and type‑only import are appropriate

The migration to @ccusage/terminal/* is clean; type‑only import for TerminalManager avoids runtime coupling.

Also applies to: 19-21

apps/ccusage/src/commands/blocks.ts (1)

17-17: LGTM: table/helpers now sourced from @ccusage/terminal

API parity appears maintained.

apps/ccusage/src/commands/session.ts (1)

1-1: LGTM: centralized table API imports

No behavior changes; type import keeps types isolated.

Also applies to: 10-10

apps/ccusage/src/commands/daily.ts (1)

1-1: LGTM: moved to shared terminal package

Consistent with repo‑wide refactor.

Also applies to: 12-12

apps/ccusage/src/commands/monthly.ts (1)

1-1: LGTM: imports consolidated under @ccusage/terminal

Matches the new package surface.

Also applies to: 10-10

packages/terminal/package.json (2)

7-10: Exports point to .ts sources — resolved (TS runtime present)
pnpm-workspace.yaml:10 declares '@oxc-project/runtime' (^0.82.3), so .ts exports are resolvable; emit JS or add a build step only if deploying to an environment without a TS runtime.


17-24: Move @oxc-project/runtime → devDependencies if unused at runtime; add "sideEffects": false

Repo search found no direct imports of @oxc-project/runtime under packages/terminal; packages/terminal/package.json lists it in dependencies and lacks sideEffects.

  • If the package is not required at runtime, move "@oxc-project/runtime" from "dependencies" to "devDependencies" in packages/terminal/package.json.
  • Add "sideEffects": false to packages/terminal/package.json (e.g., after "description") to improve tree‑shaking.
  • Verify usage before changing: rg -n --hidden --no-ignore -uu '@oxc-project/runtime' -S || true (or inspect the runtime usage in ./src exports).
apps/ccusage/src/commands/_blocks.live.ts (1)

24-29: TerminalManager doesn't accept a logger — update approach

Constructor is constructor(stream: WriteStream = process.stdout) (packages/terminal/src/utils.ts:32–34), so you cannot pass the app logger directly; either (A) extend TerminalManager to accept an options/logger and use it instead of console.* fallbacks, or (B) pass a WriteStream wrapper that forwards writes to the app logger.

Likely an incorrect or invalid review comment.

apps/ccusage/src/commands/_session_id.ts (1)

7-7: Import migration verified — named exports present in @ccusage/terminal/table

formatCurrency (packages/terminal/src/table.ts:314), formatNumber (packages/terminal/src/table.ts:305), ResponsiveTable (packages/terminal/src/table.ts:38) are exported.

Comment on lines +1 to +11
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
includeSource: ['src/**/*.ts'],
},
define: {
'import.meta.vitest': 'undefined',
},
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Do not define import.meta.vitest as undefined in test config—this disables in‑source tests.

In Vitest configs, set it to "true" (or omit define entirely) so blocks guarded by if (import.meta.vitest != null) execute. Also switch to double quotes per repo style.

-import { defineConfig } from 'vitest/config';
+import { defineConfig } from "vitest/config";

 export default defineConfig({
 	test: {
 		globals: true,
 		includeSource: ['src/**/*.ts'],
 	},
 	define: {
-		'import.meta.vitest': 'undefined',
+		"import.meta.vitest": "true",
 	},
 });

If you also have a separate build config, that’s the place to set "import.meta.vitest" to "undefined" for tree‑shaking in production bundles.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
includeSource: ['src/**/*.ts'],
},
define: {
'import.meta.vitest': 'undefined',
},
});
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
globals: true,
includeSource: ['src/**/*.ts'],
},
define: {
"import.meta.vitest": "true",
},
});
🤖 Prompt for AI Agents
In packages/terminal/vitest.config.ts around lines 1 to 11, the config sets
define['import.meta.vitest'] to 'undefined' which disables in‑source Vitest
guards; change this to true or remove the define block entirely so if
(import.meta.vitest != null) blocks run during tests, and update string quoting
to use double quotes to match repo style; if you need tree‑shaking for
production, set "import.meta.vitest" to "undefined" in the build config instead.

@ryoppippi ryoppippi merged commit 9466022 into main Sep 17, 2025
17 checks passed
@ryoppippi ryoppippi deleted the refactor/extract-terminal-package branch September 17, 2025 19:48
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