Conversation
- 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.
WalkthroughThis 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
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
Possibly related PRs
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
commit: |
There was a problem hiding this comment.
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, andsrc/session-blocks.internal.tshave 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
-
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. ↩
There was a problem hiding this comment.
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.
| * Default Claude data directory path (~/.claude) | ||
| * Used as base path for loading usage data from JSONL files | ||
| */ |
There was a problem hiding this comment.
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.
| * 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. |
There was a problem hiding this comment.
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.tswith JSDoc for all constants - Refactors
session-blocks.internal.ts,debug.ts,data-loader.ts,commands/mcp.ts, andcommands/blocks.tsto 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_PATHis only the directory name (.claude). Consider clarifying that it represents the directory name, not the resolved path.
* Default Claude data directory path (~/.claude)
| `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. |
There was a problem hiding this comment.
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.
| 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'; |
There was a problem hiding this comment.
[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.
| 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'; |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/consts.internal.ts (1)
67-67: Add explicit type annotation forUSER_HOME_DIR
Explicitly typing this constant asstringwill satisfy thets/no-unsafe-callhint 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
📒 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 ofhomedirfrom Node.js OS module
Necessary for deriving the user's home directory path.
13-13: Centralize default recent days constant
DEFAULT_RECENT_DAYSis now sourced from a single location for consistency.
19-19: Centralize blocks warning threshold
BLOCKS_WARNING_THRESHOLDis documented and exported for shared use.
25-25: Centralize compact width threshold
BLOCKS_COMPACT_WIDTH_THRESHOLDconsolidates UI layout logic.
31-31: Centralize default terminal width
BLOCKS_DEFAULT_TERMINAL_WIDTHprovides a clear fallback.
37-37: Centralize debug match threshold
DEBUG_MATCH_THRESHOLD_PERCENTstandardizes cost‐matching tolerance.
43-43: Centralize Claude code path
DEFAULT_CLAUDE_CODE_PATHdocuments the base directory for Claude data.
49-49: Centralize projects directory name
CLAUDE_PROJECTS_DIR_NAMEclarifies the subdirectory for Claude projects.
55-55: Centralize usage data file glob pattern
USAGE_DATA_GLOB_PATTERNreplaces ad-hoc patterns across the codebase.
61-61: Centralize MCP default port
MCP_DEFAULT_PORTremoves magic numbers from server setup.src/commands/mcp.ts (2)
3-3: Replace hardcoded port with centralized constant
ImportingMCP_DEFAULT_PORTaligns the default port with the constants module.
27-28: UseMCP_DEFAULT_PORTin description and default
Dynamic interpolation ensures the help text always matches the actual default.src/session-blocks.internal.ts (1)
2-2: ImportDEFAULT_RECENT_DAYSfrom central constants
Removes the local duplication in favor of the shared definition.src/debug.ts (3)
5-5: Consolidate imports fromconsts.internal.ts
Replaces scattered literals and OS calls with centralized constants.
67-68: ConstructclaudeDirand file glob using constants
USER_HOME_DIR,DEFAULT_CLAUDE_CODE_PATH,CLAUDE_PROJECTS_DIR_NAME, andUSAGE_DATA_GLOB_PATTERNnow drive directory resolution and file discovery.
144-144: Replace hardcoded match threshold with constant
UseDEBUG_MATCH_THRESHOLD_PERCENThere instead of the literal0.1to 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 fromconsts.internal.jsconsolidates configuration, reducing magic strings.
58-58: Use centralized default Claude code path
Replacing inlinehomedir()and string literal withUSER_HOME_DIRandDEFAULT_CLAUDE_CODE_PATHaligns with the centralized config.
65-65: Update error message to reference centralized default path
Usingpath.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'withCLAUDE_PROJECTS_DIR_NAMEremoves duplication.
74-74: Update project path error message to use centralized constant
ReferencingDEFAULT_CLAUDE_CODE_PATHin the message maintains consistency with the actual default path.
585-586: Replace hardcoded glob pattern and subdirectory in daily loader
Switching toUSAGE_DATA_GLOB_PATTERNandCLAUDE_PROJECTS_DIR_NAMEeliminates inline patterns and directory names.
707-708: Apply centralized constants in session data loader
Consistently usingCLAUDE_PROJECTS_DIR_NAMEandUSAGE_DATA_GLOB_PATTERNacross 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
UsingDEFAULT_RECENT_DAYSin help text keeps documentation in sync with actual defaults.
183-183: Use centralized default for filtering recent blocks
Explicitly passingDEFAULT_RECENT_DAYSensures the filter matches the shared default.
232-232: Apply warning threshold constant in JSON output
UsingBLOCKS_WARNING_THRESHOLDmakes status logic data-driven and consistent.
293-293: Use threshold constant in active view status
ReferencingBLOCKS_WARNING_THRESHOLD * 100ensures the UI warning matches the configured threshold.
332-332: Use default terminal width constant as fallback
Falling back toBLOCKS_DEFAULT_TERMINAL_WIDTHavoids magic numbers.
333-333: Decide compact format using centralized threshold
BLOCKS_COMPACT_WIDTH_THRESHOLDdrives UI adaptation, improving clarity on the break point.
refactor: consolidate scattered constants into centralized consts.internal.ts
Summary
Changes Made
Constants Consolidated
Time/Duration Constants:
UI/Display Constants:
Threshold/Tolerance Constants:
File/Path Constants:
Network/System Constants:
Files Modified
Benefits
Test Plan
Summary by CodeRabbit