Skip to content

refactor: consolidate scattered constants into centralized consts.internal.ts#111

Merged
ryoppippi merged 5 commits intomainfrom
consts
Jun 18, 2025
Merged

refactor: consolidate scattered constants into centralized consts.internal.ts#111
ryoppippi merged 5 commits intomainfrom
consts

Conversation

@ryoppippi
Copy link
Owner

@ryoppippi ryoppippi commented Jun 18, 2025

Summary

  • Consolidate scattered constants from multiple files into a centralized consts.internal.ts
  • Add comprehensive JSDoc documentation for all constants
  • Use context-specific naming conventions (e.g., BLOCKS_, DEBUG_, MCP_) for clarity
  • Replace hardcoded values with named constants throughout the codebase
  • Maintain single source of truth for configuration values

Changes Made

Constants Consolidated

Time/Duration Constants:

  • DEFAULT_RECENT_DAYS = 3 - Recent days filtering across commands

UI/Display Constants:

  • BLOCKS_WARNING_THRESHOLD = 0.8 - Usage warning threshold (80%)
  • BLOCKS_COMPACT_WIDTH_THRESHOLD = 120 - Terminal width for compact mode
  • BLOCKS_DEFAULT_TERMINAL_WIDTH = 120 - Fallback terminal width

Threshold/Tolerance Constants:

  • DEBUG_MATCH_THRESHOLD_PERCENT = 0.1 - Cost matching tolerance for debug validation

File/Path Constants:

  • DEFAULT_CLAUDE_CODE_PATH = ".claude" - Claude data directory name
  • CLAUDE_PROJECTS_DIR_NAME = "projects" - Projects directory name
  • USAGE_DATA_GLOB_PATTERN = "**/*.jsonl" - JSONL file search pattern

Network/System Constants:

  • MCP_DEFAULT_PORT = 8080 - MCP server default port
  • USER_HOME_DIR - Centralized home directory access

Files Modified

  • src/consts.internal.ts - New centralized constants file
  • src/commands/blocks.ts - Updated to use centralized constants
  • src/commands/mcp.ts - Updated to use MCP_DEFAULT_PORT
  • src/data-loader.ts - Updated to use path and file constants
  • src/debug.ts - Updated to use debug threshold constant
  • src/session-blocks.internal.ts - Removed duplicate constants

Benefits

  1. Single Source of Truth: All configuration values in one place
  2. Better Maintainability: Easy to update values across the entire codebase
  3. Clear Naming: Context-specific prefixes make usage intent obvious
  4. Documentation: JSDoc explains purpose and usage for each constant
  5. Type Safety: No more magic numbers/strings scattered throughout code

Test Plan

  • All existing tests pass (182/182)
  • TypeScript compilation succeeds
  • ESLint formatting completes without errors
  • No functional changes - pure refactoring
  • Constants maintain same values as before consolidation

Summary by CodeRabbit

  • Refactor
    • Centralized configuration values and path definitions by replacing hardcoded constants and strings with shared constants across the application.
    • Updated descriptions and behaviors to dynamically reflect these centralized values.
  • Chores
    • Improved maintainability by consolidating default settings, directory names, file patterns, and thresholds into a single internal module.

- Move DEFAULT_RECENT_DAYS constant to consts.internal.ts with detailed JSDoc
- Remove duplicate RECENT_DAYS_DEFAULT from commands/blocks.ts
- Remove duplicate DEFAULT_RECENT_DAYS from session-blocks.internal.ts
- Update imports to use centralized constant
- Ensure consistent behavior across session blocks and commands

This change eliminates duplication of the 3-day default value and
provides a single source of truth for recent days filtering logic.
- Move WARNING_THRESHOLD, COMPACT_WIDTH_THRESHOLD, DEFAULT_TERMINAL_WIDTH to consts.internal.ts
- Add comprehensive JSDoc explaining usage warning thresholds and responsive display logic
- Remove duplicate constants from commands/blocks.ts
- Update imports to use centralized UI constants

This consolidation ensures consistent thresholds across the application
for warning displays and responsive table formatting behavior.
- Move DEBUG_MATCH_THRESHOLD_PERCENT to consts.internal.ts with JSDoc
- Rename UI constants with BLOCKS_ prefix for clarity:
  - WARNING_THRESHOLD → BLOCKS_WARNING_THRESHOLD
  - COMPACT_WIDTH_THRESHOLD → BLOCKS_COMPACT_WIDTH_THRESHOLD
  - DEFAULT_TERMINAL_WIDTH → BLOCKS_DEFAULT_TERMINAL_WIDTH
- Update all usage locations in commands/blocks.ts and debug.ts
- Add context-specific JSDoc explaining usage domains

This improves constant naming by making it clear which module or
command each constant is primarily intended for, reducing confusion
when reading code across different files.
- Move DEFAULT_CLAUDE_CODE_PATH to consts.internal.ts as path component only
- Add CLAUDE_PROJECTS_DIR_NAME for "projects" directory references
- Add USAGE_DATA_GLOB_PATTERN for "**/*.jsonl" glob pattern
- Update data-loader.ts to use centralized path constants with proper joining
- Update debug.ts to use centralized constants for consistent paths
- Add comprehensive JSDoc explaining each constant"s purpose and usage

This consolidation eliminates hardcoded path strings throughout the codebase
and provides a single source of truth for Claude data structure navigation.
- Add MCP_DEFAULT_PORT constant for MCP server default port (8080)
- Add USER_HOME_DIR constant for centralized home directory access
- Update commands/mcp.ts to use MCP_DEFAULT_PORT for consistent port handling
- Replace homedir() calls with USER_HOME_DIR in data-loader.ts and debug.ts
- Keep homedir import in data-loader.ts for test usage (tree-shaken in production)
- Add comprehensive JSDoc explaining network and system path constants

This consolidation provides centralized access to system paths and network
configuration, eliminating scattered hardcoded values across the application.
@coderabbitai
Copy link

coderabbitai bot commented Jun 18, 2025

Walkthrough

This update centralizes various configuration constants by moving them from multiple source files into a single internal constants module. All affected files are refactored to import these constants, replacing previous hardcoded values and local definitions for paths, thresholds, default settings, and patterns. No logic or control flow changes are introduced.

Changes

File(s) Change Summary
src/consts.internal.ts Added new constants for default days, thresholds, directory names, glob patterns, server ports, and user home path.
src/commands/blocks.ts Replaced local hardcoded constants with imports from the centralized constants module.
src/commands/mcp.ts Replaced hardcoded default port and its description with imported constant.
src/data-loader.ts Replaced inline path strings and glob patterns with imported constants for directories and usage data.
src/debug.ts Replaced local constants and path/glob strings with imported centralized constants.
src/session-blocks.internal.ts Replaced local default days constant with imported constant.

Sequence Diagram(s)

sequenceDiagram
    participant Command as CLI Command (e.g., blocks)
    participant Consts as Constants Module
    participant Loader as Data Loader
    participant Debug as Debug Module

    Command->>Consts: Import configuration constants
    Loader->>Consts: Import directory and pattern constants
    Debug->>Consts: Import thresholds and path constants
    Command->>Loader: Call data loading functions (using imported constants)
    Debug->>Loader: Call data loading with updated constants
Loading

Possibly related PRs

  • ryoppippi/ccusage#70: Refactors path handling for the Claude data directory, related to this PR's centralization of path constants.
  • ryoppippi/ccusage#80: Introduces the blocks command, which is refactored in this PR to use centralized constants.

Poem

A bunny hopped through fields of code,
Gathering constants from every road.
No more hardcoded values in sight—
Just imports that feel just right!
Now all the paths and thresholds align,
In one cozy module, by design.
🐇✨

✨ 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 18, 2025

Open in StackBlitz

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

commit: 5be5275

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 pure refactoring effort aimed at improving the codebase's maintainability and readability by centralizing all application constants. The goal is to establish a single source of truth for configuration values, making it easier to manage and understand critical parameters across the project. This change has no functional impact and ensures consistency in how constants are defined and used.

Highlights

  • Centralized Constants File: I've introduced a new file, src/consts.internal.ts, to serve as a single source of truth for various application constants. This consolidates values previously scattered across multiple files.
  • Refactoring and Usage Updates: Existing files such as src/commands/blocks.ts, src/commands/mcp.ts, src/data-loader.ts, src/debug.ts, and src/session-blocks.internal.ts have been updated to import and utilize these new centralized constants, replacing their previously hardcoded or locally defined equivalents.
  • Improved Readability and Maintainability: All consolidated constants now include comprehensive JSDoc documentation and follow context-specific naming conventions (e.g., BLOCKS_, DEBUG_, MCP_), enhancing code clarity and making future updates more straightforward.
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 requested a review from Copilot June 18, 2025 14:12
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 consolidates scattered constants into a centralized consts.internal.ts file, significantly improving maintainability and clarity. The changes are well-executed, with clear JSDoc documentation for the new constants and consistent naming conventions.

The refactoring correctly replaces hardcoded values and local constants with the new centralized versions across multiple files. The introduction of USER_HOME_DIR and adjusting DEFAULT_CLAUDE_CODE_PATH to be a relative path component is a good design choice.

One minor suggestion is to update the JSDoc for DEFAULT_CLAUDE_CODE_PATH to more accurately reflect its new role as a directory name rather than a full path. Overall, this is a solid refactoring that enhances the codebase's structure.

Comment on lines +40 to +42
* Default Claude data directory path (~/.claude)
* Used as base path for loading usage data from JSONL files
*/
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 for DEFAULT_CLAUDE_CODE_PATH could be more precise. It currently states it's the "Default Claude data directory path (~/.claude)". However, with the refactoring, this constant now holds just the directory name (e.g., .claude), and the full path is constructed using USER_HOME_DIR (e.g., path.join(USER_HOME_DIR, DEFAULT_CLAUDE_CODE_PATH)).

Consider updating the JSDoc to reflect that this constant represents the name or relative path component of the default Claude data directory, typically located within the user's home directory.

Suggested change
* Default Claude data directory path (~/.claude)
* Used as base path for loading usage data from JSONL files
*/
* Default name for the Claude data directory (e.g., '.claude')
* This directory is typically located in the user's home directory.
* Used as a base name for constructing the full path to load usage data.

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 centralizes scattered constants into consts.internal.ts and updates usage across the codebase to reference these new definitions instead of hardcoded values.

  • Introduces src/consts.internal.ts with JSDoc for all constants
  • Refactors session-blocks.internal.ts, debug.ts, data-loader.ts, commands/mcp.ts, and commands/blocks.ts to import and use the consolidated constants
  • Removes duplicate and inline constant definitions

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/consts.internal.ts New centralized constants file with comprehensive JSDoc
src/session-blocks.internal.ts Replaced inline DEFAULT_RECENT_DAYS with imported constant
src/debug.ts Swapped hardcoded thresholds and paths for imported constants
src/data-loader.ts Leveraged constants for paths, glob patterns, and project names
src/commands/mcp.ts Updated default port description and value to use MCP_DEFAULT_PORT
src/commands/blocks.ts Replaced multiple hardcoded values with centralized constants
Comments suppressed due to low confidence (1)

src/consts.internal.ts:40

  • The JSDoc implies this constant holds a full path, but DEFAULT_CLAUDE_CODE_PATH is only the directory name (.claude). Consider clarifying that it represents the directory name, not the resolved path.
 * Default Claude data directory path (~/.claude)

Comment on lines 73 to +74
`Claude data directory does not exist: ${claudeCodeProjectsPath}.
Please set CLAUDE_CONFIG_DIR to a valid path, or ensure ${DEFAULT_CLAUDE_CODE_PATH} exists.
Please set CLAUDE_CONFIG_DIR to a valid path, or ensure ${path.join(USER_HOME_DIR, DEFAULT_CLAUDE_CODE_PATH)} exists.
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

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

The error message suggests ensuring the base directory exists, but this check is for the projects subdirectory. Consider updating it to reference CLAUDE_PROJECTS_DIR_NAME so the user knows to verify the 'projects' folder specifically.

Copilot uses AI. Check for mistakes.
import path from 'node:path';
import { createFixture } from 'fs-fixture';
import { glob } from 'tinyglobby';
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, DEFAULT_CLAUDE_CODE_PATH, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR } from './consts.internal.js';
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

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

[nitpick] Imports use a mix of .js and .ts extensions (e.g., ./consts.internal.js vs ./data-loader.ts). Consider standardizing on one extension style to reduce import confusion.

Suggested change
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, DEFAULT_CLAUDE_CODE_PATH, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR } from './consts.internal.js';
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, DEFAULT_CLAUDE_CODE_PATH, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR } from './consts.internal.ts';

Copilot uses AI. Check for mistakes.
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: 0

🧹 Nitpick comments (1)
src/consts.internal.ts (1)

67-67: Add explicit type annotation for USER_HOME_DIR
Explicitly typing this constant as string will satisfy the ts/no-unsafe-call hint and improve clarity.
Apply this diff:

-export const USER_HOME_DIR = homedir();
+export const USER_HOME_DIR: string = homedir();
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ec4752 and 5be5275.

📒 Files selected for processing (6)
  • src/commands/blocks.ts (6 hunks)
  • src/commands/mcp.ts (2 hunks)
  • src/consts.internal.ts (1 hunks)
  • src/data-loader.ts (5 hunks)
  • src/debug.ts (3 hunks)
  • src/session-blocks.internal.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/commands/mcp.ts (1)
src/consts.internal.ts (1)
  • MCP_DEFAULT_PORT (61-61)
src/commands/blocks.ts (2)
src/consts.internal.ts (4)
  • DEFAULT_RECENT_DAYS (13-13)
  • BLOCKS_WARNING_THRESHOLD (19-19)
  • BLOCKS_DEFAULT_TERMINAL_WIDTH (31-31)
  • BLOCKS_COMPACT_WIDTH_THRESHOLD (25-25)
src/session-blocks.internal.ts (1)
  • filterRecentBlocks (296-304)
src/data-loader.ts (1)
src/consts.internal.ts (4)
  • USER_HOME_DIR (67-67)
  • DEFAULT_CLAUDE_CODE_PATH (43-43)
  • CLAUDE_PROJECTS_DIR_NAME (49-49)
  • USAGE_DATA_GLOB_PATTERN (55-55)
src/debug.ts (1)
src/consts.internal.ts (5)
  • USER_HOME_DIR (67-67)
  • DEFAULT_CLAUDE_CODE_PATH (43-43)
  • CLAUDE_PROJECTS_DIR_NAME (49-49)
  • USAGE_DATA_GLOB_PATTERN (55-55)
  • DEBUG_MATCH_THRESHOLD_PERCENT (37-37)
🪛 ESLint
src/consts.internal.ts

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

(ts/no-unsafe-assignment)


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

(ts/no-unsafe-call)

src/commands/blocks.ts

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

(ts/no-unsafe-assignment)


[error] 332-332: Unexpected any value in conditional. An explicit comparison or type conversion is required.

(ts/strict-boolean-expressions)


[error] 332-332: Unsafe member access .stdout on an error typed value.

(ts/no-unsafe-member-access)

src/data-loader.ts

[error] 58-58: Unsafe return of a value of type error.

(ts/no-unsafe-return)


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

(ts/no-unsafe-call)


[error] 58-58: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


[error] 62-62: Unexpected any value in conditional. An explicit comparison or type conversion is required.

(ts/strict-boolean-expressions)


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

(ts/no-unsafe-call)


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

(ts/no-unsafe-call)


[error] 65-65: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


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

(ts/no-unsafe-assignment)


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

(ts/no-unsafe-call)


[error] 70-70: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


[error] 71-71: Unexpected any value in conditional. An explicit comparison or type conversion is required.

(ts/strict-boolean-expressions)


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

(ts/no-unsafe-call)


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

(ts/no-unsafe-call)


[error] 74-74: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


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

(ts/no-unsafe-assignment)


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

(ts/no-unsafe-call)


[error] 585-585: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


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

(ts/no-unsafe-call)


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

(ts/no-unsafe-assignment)


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

(ts/no-unsafe-call)


[error] 707-707: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


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

(ts/no-unsafe-call)


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

(ts/no-unsafe-assignment)


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

(ts/no-unsafe-call)


[error] 943-943: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


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

(ts/no-unsafe-call)

src/debug.ts

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

(ts/no-unsafe-assignment)


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

(ts/no-unsafe-call)


[error] 67-67: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


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

(ts/no-unsafe-call)

🔇 Additional comments (31)
src/consts.internal.ts (10)

1-1: Import of homedir from Node.js OS module
Necessary for deriving the user's home directory path.


13-13: Centralize default recent days constant
DEFAULT_RECENT_DAYS is now sourced from a single location for consistency.


19-19: Centralize blocks warning threshold
BLOCKS_WARNING_THRESHOLD is documented and exported for shared use.


25-25: Centralize compact width threshold
BLOCKS_COMPACT_WIDTH_THRESHOLD consolidates UI layout logic.


31-31: Centralize default terminal width
BLOCKS_DEFAULT_TERMINAL_WIDTH provides a clear fallback.


37-37: Centralize debug match threshold
DEBUG_MATCH_THRESHOLD_PERCENT standardizes cost‐matching tolerance.


43-43: Centralize Claude code path
DEFAULT_CLAUDE_CODE_PATH documents the base directory for Claude data.


49-49: Centralize projects directory name
CLAUDE_PROJECTS_DIR_NAME clarifies the subdirectory for Claude projects.


55-55: Centralize usage data file glob pattern
USAGE_DATA_GLOB_PATTERN replaces ad-hoc patterns across the codebase.


61-61: Centralize MCP default port
MCP_DEFAULT_PORT removes magic numbers from server setup.

src/commands/mcp.ts (2)

3-3: Replace hardcoded port with centralized constant
Importing MCP_DEFAULT_PORT aligns the default port with the constants module.


27-28: Use MCP_DEFAULT_PORT in description and default
Dynamic interpolation ensures the help text always matches the actual default.

src/session-blocks.internal.ts (1)

2-2: Import DEFAULT_RECENT_DAYS from central constants
Removes the local duplication in favor of the shared definition.

src/debug.ts (3)

5-5: Consolidate imports from consts.internal.ts
Replaces scattered literals and OS calls with centralized constants.


67-68: Construct claudeDir and file glob using constants
USER_HOME_DIR, DEFAULT_CLAUDE_CODE_PATH, CLAUDE_PROJECTS_DIR_NAME, and USAGE_DATA_GLOB_PATTERN now drive directory resolution and file discovery.


144-144: Replace hardcoded match threshold with constant
Use DEBUG_MATCH_THRESHOLD_PERCENT here instead of the literal 0.1 to avoid divergence.

-                    if (percentDiff < 0.1) {
+                    if (percentDiff < DEBUG_MATCH_THRESHOLD_PERCENT) {

Likely an incorrect or invalid review comment.

src/data-loader.ts (8)

19-19: Centralize path and pattern constants import
Importing directory names and glob patterns from consts.internal.js consolidates configuration, reducing magic strings.


58-58: Use centralized default Claude code path
Replacing inline homedir() and string literal with USER_HOME_DIR and DEFAULT_CLAUDE_CODE_PATH aligns with the centralized config.


65-65: Update error message to reference centralized default path
Using path.join(USER_HOME_DIR, DEFAULT_CLAUDE_CODE_PATH) ensures error messages stay accurate when defaults change in one place.


70-70: Use centralized Claude projects directory constant
Replacing hardcoded 'projects' with CLAUDE_PROJECTS_DIR_NAME removes duplication.


74-74: Update project path error message to use centralized constant
Referencing DEFAULT_CLAUDE_CODE_PATH in the message maintains consistency with the actual default path.


585-586: Replace hardcoded glob pattern and subdirectory in daily loader
Switching to USAGE_DATA_GLOB_PATTERN and CLAUDE_PROJECTS_DIR_NAME eliminates inline patterns and directory names.


707-708: Apply centralized constants in session data loader
Consistently using CLAUDE_PROJECTS_DIR_NAME and USAGE_DATA_GLOB_PATTERN across loaders improves maintainability.


943-944: Use centralized constants in session-blocks loader
Ensures all data loaders use the same directory and pattern definitions.

src/commands/blocks.ts (7)

4-4: Import block-related constants from centralized module
This replaces local hardcoded defaults and brings uniformity across the application.


119-119: Leverage default recent days constant in description
Using DEFAULT_RECENT_DAYS in help text keeps documentation in sync with actual defaults.


183-183: Use centralized default for filtering recent blocks
Explicitly passing DEFAULT_RECENT_DAYS ensures the filter matches the shared default.


232-232: Apply warning threshold constant in JSON output
Using BLOCKS_WARNING_THRESHOLD makes status logic data-driven and consistent.


293-293: Use threshold constant in active view status
Referencing BLOCKS_WARNING_THRESHOLD * 100 ensures the UI warning matches the configured threshold.


332-332: Use default terminal width constant as fallback
Falling back to BLOCKS_DEFAULT_TERMINAL_WIDTH avoids magic numbers.


333-333: Decide compact format using centralized threshold
BLOCKS_COMPACT_WIDTH_THRESHOLD drives UI adaptation, improving clarity on the break point.

@ryoppippi ryoppippi merged commit fd83fad into main Jun 18, 2025
10 checks passed
@ryoppippi ryoppippi deleted the consts branch June 18, 2025 14:14
ryoppippi added a commit that referenced this pull request Jun 22, 2025
refactor: consolidate scattered constants into centralized consts.internal.ts
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