mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 12:39:42 +02:00
refactor: consolidate shared regex patterns and token validation
- Create src/utils/regex-patterns.ts with ANSI_ESCAPE_PATTERN_FULL, ANSI_ESCAPE_PATTERN_SIMPLE, TOKEN_PATTERN, and helper functions - Create src/utils/token-validation.ts with MAX_SESSION_TOKENS and validation utilities - Update session.ts, respawn-controller.ts, ai-checker-base.ts, ralph-tracker.ts, state-store.ts to use shared utilities - Export all new utilities from src/utils/index.ts Reduces code duplication while maintaining pre-compiled patterns for performance. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -18,6 +18,7 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync, renameSync, unlinkS
|
||||
import { homedir } from 'node:os';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { AppState, createInitialState, RalphSessionState, createInitialRalphSessionState, GlobalStats, createInitialGlobalStats, TokenStats, TokenUsageEntry } from './types.js';
|
||||
import { MAX_SESSION_TOKENS } from './utils/index.js';
|
||||
|
||||
/** Debounce delay for batching state writes (ms) */
|
||||
const SAVE_DEBOUNCE_MS = 500;
|
||||
@@ -369,8 +370,7 @@ export class StateStore {
|
||||
* Call when a session is deleted to preserve its usage in lifetime stats.
|
||||
*/
|
||||
addToGlobalStats(inputTokens: number, outputTokens: number, cost: number): void {
|
||||
// Sanity check: reject absurdly large values (max 500k tokens per session)
|
||||
const MAX_SESSION_TOKENS = 500_000;
|
||||
// Sanity check: reject absurdly large values
|
||||
if (inputTokens > MAX_SESSION_TOKENS || outputTokens > MAX_SESSION_TOKENS) {
|
||||
console.warn(`[StateStore] Rejected absurd global stats: input=${inputTokens}, output=${outputTokens}`);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user