Skip to content

Commit 9813950

Browse files
committed
refactor(consts): move refresh interval to constants
- Add DEFAULT_REFRESH_INTERVAL_SECONDS, MIN_REFRESH_INTERVAL_SECONDS, MAX_REFRESH_INTERVAL_SECONDS to _consts.ts - Update blocks.ts to use these constants instead of hardcoded values - Improve maintainability by centralizing refresh interval configuration
1 parent 2b7e43b commit 9813950

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎src/_consts.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,21 @@ export const USAGE_DATA_GLOB_PATTERN = '**/*.jsonl';
8484
* Used when no port is specified for MCP server communication
8585
*/
8686
export const MCP_DEFAULT_PORT = 8080;
87+
88+
/**
89+
* Default refresh interval in seconds for live monitoring mode
90+
* Used in blocks command for real-time updates
91+
*/
92+
export const DEFAULT_REFRESH_INTERVAL_SECONDS = 1;
93+
94+
/**
95+
* Minimum refresh interval in seconds for live monitoring mode
96+
* Prevents too-frequent updates that could impact performance
97+
*/
98+
export const MIN_REFRESH_INTERVAL_SECONDS = 1;
99+
100+
/**
101+
* Maximum refresh interval in seconds for live monitoring mode
102+
* Prevents too-slow updates that reduce monitoring effectiveness
103+
*/
104+
export const MAX_REFRESH_INTERVAL_SECONDS = 60;

‎src/commands/blocks.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import process from 'node:process';
22
import { define } from 'gunshi';
33
import pc from 'picocolors';
4-
import { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, DEFAULT_RECENT_DAYS } from '../_consts.ts';
4+
import { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, DEFAULT_RECENT_DAYS, DEFAULT_REFRESH_INTERVAL_SECONDS, MAX_REFRESH_INTERVAL_SECONDS, MIN_REFRESH_INTERVAL_SECONDS } from '../_consts.ts';
55
import {
66
calculateBurnRate,
77
DEFAULT_SESSION_DURATION_HOURS,
@@ -139,8 +139,8 @@ export const blocksCommand = define({
139139
},
140140
refreshInterval: {
141141
type: 'number',
142-
description: 'Refresh interval in seconds for live mode (default: 1)',
143-
default: 1,
142+
description: `Refresh interval in seconds for live mode (default: ${DEFAULT_REFRESH_INTERVAL_SECONDS})`,
143+
default: DEFAULT_REFRESH_INTERVAL_SECONDS,
144144
},
145145
},
146146
toKebab: true,
@@ -225,9 +225,9 @@ export const blocksCommand = define({
225225
}
226226

227227
// Validate refresh interval
228-
const refreshInterval = Math.max(1, Math.min(60, ctx.values.refreshInterval));
228+
const refreshInterval = Math.max(MIN_REFRESH_INTERVAL_SECONDS, Math.min(MAX_REFRESH_INTERVAL_SECONDS, ctx.values.refreshInterval));
229229
if (refreshInterval !== ctx.values.refreshInterval) {
230-
logger.warn(`Refresh interval adjusted to ${refreshInterval} seconds (valid range: 1-60)`);
230+
logger.warn(`Refresh interval adjusted to ${refreshInterval} seconds (valid range: ${MIN_REFRESH_INTERVAL_SECONDS}-${MAX_REFRESH_INTERVAL_SECONDS})`);
231231
}
232232

233233
// Start live monitoring

0 commit comments

Comments
 (0)