From 545913790bfecb0b0a966f051bb0fb2626a6733f Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 28 Feb 2026 02:01:21 +0100 Subject: [PATCH] chore: remove dead code and unused exports (-159 lines) Remove confirmed-unused code found via team-based codebase analysis: - Dead interfaces: SessionResponse (types.ts), PlannerResult (plan-orchestrator.ts) - Dead functions: withTimeout (session.ts), getOpenCodeAugmentedPath, resetOpenCodeCache (opencode-cli-resolver.ts) - Dead config constants: MAX_RUN_SUMMARY_EVENTS, TRIM_RUN_SUMMARY_TO, MAX_MESSAGES_PER_CHANNEL (buffer-limits.ts), MAX_TRACKED_AGENTS, MAX_SUBAGENT_ACTIVITY_PER_AGENT, MAX_TOOL_RESULTS_PER_AGENT, COMPLETED_TODO_TTL_MS (map-limits.ts) - Dead legacy code: idleTimer property + clearIdleTimer() no-op method + 6 call sites (respawn-controller.ts) - Stale barrel re-exports: createAnsiPatternFull/Simple, validateTokenCounts/Cost, stripAnsi, normalizePhrase, getOpenCodeAugmentedPath (utils/index.ts) - Un-exported internal-only symbols: ErrorMessages (types.ts), destroyRalphLoop (ralph-loop.ts) Co-Authored-By: Claude Opus 4.6 --- src/config/buffer-limits.ts | 23 ----------------------- src/config/map-limits.ts | 27 --------------------------- src/plan-orchestrator.ts | 6 ------ src/ralph-loop.ts | 2 +- src/respawn-controller.ts | 23 +---------------------- src/session.ts | 24 ------------------------ src/types.ts | 25 +------------------------ src/utils/index.ts | 9 +++------ src/utils/opencode-cli-resolver.ts | 27 +-------------------------- 9 files changed, 7 insertions(+), 159 deletions(-) diff --git a/src/config/buffer-limits.ts b/src/config/buffer-limits.ts index 41f7bcd5..035d1945 100644 --- a/src/config/buffer-limits.ts +++ b/src/config/buffer-limits.ts @@ -85,26 +85,3 @@ export const MAX_RESPAWN_BUFFER_SIZE = 1 * 1024 * 1024; // 1MB * Size to trim respawn buffer to when max is exceeded. */ export const TRIM_RESPAWN_BUFFER_TO = 512 * 1024; // 512KB - -// ============================================================================ -// Run Summary Limits -// ============================================================================ - -/** - * Maximum number of events to keep in run summary. - */ -export const MAX_RUN_SUMMARY_EVENTS = 1000; - -/** - * Number of events to keep when trimming run summary. - */ -export const TRIM_RUN_SUMMARY_TO = 800; - -// ============================================================================ -// Spawn Message Limits -// ============================================================================ - -/** - * Maximum messages per spawn communication channel. - */ -export const MAX_MESSAGES_PER_CHANNEL = 100; diff --git a/src/config/map-limits.ts b/src/config/map-limits.ts index 3fb509fb..c2572b5e 100644 --- a/src/config/map-limits.ts +++ b/src/config/map-limits.ts @@ -14,28 +14,6 @@ * @module config/map-limits */ -// ============================================================================ -// Agent Tracking Limits -// ============================================================================ - -/** - * Maximum number of agents to track across all sessions. - * Oldest agents are evicted when limit is exceeded (LRU policy). - */ -export const MAX_TRACKED_AGENTS = 500; - -/** - * Maximum activity entries to keep per agent. - * Includes tool calls, status updates, progress reports. - */ -export const MAX_SUBAGENT_ACTIVITY_PER_AGENT = 100; - -/** - * Maximum tool results to keep per agent. - * Prevents memory growth from long-running agents with many tool calls. - */ -export const MAX_TOOL_RESULTS_PER_AGENT = 200; - // ============================================================================ // Session Tracking Limits // ============================================================================ @@ -65,11 +43,6 @@ export const MAX_SSE_CLIENTS = 100; */ export const MAX_TODOS_PER_SESSION = 500; -/** - * TTL for completed todo items before cleanup (1 hour). - */ -export const COMPLETED_TODO_TTL_MS = 60 * 60 * 1000; - // ============================================================================ // Pending Tool Calls Limits // ============================================================================ diff --git a/src/plan-orchestrator.ts b/src/plan-orchestrator.ts index 5d96919e..7ed0bc88 100644 --- a/src/plan-orchestrator.ts +++ b/src/plan-orchestrator.ts @@ -79,12 +79,6 @@ export interface ResearchResult { durationMs: number; } -export interface PlannerResult { - items: PlanItem[]; - gaps: string[]; - warnings: string[]; -} - export interface DetailedPlanResult { success: boolean; items?: PlanItem[]; diff --git a/src/ralph-loop.ts b/src/ralph-loop.ts index 1c7c8c7b..f5adaf11 100644 --- a/src/ralph-loop.ts +++ b/src/ralph-loop.ts @@ -509,7 +509,7 @@ export function getRalphLoop(options?: RalphLoopOptions): RalphLoop { } /** Destroys the singleton instance. Use in tests or for cleanup. */ -export function destroyRalphLoop(): void { +function destroyRalphLoop(): void { if (loopInstance) { loopInstance.destroy(); loopInstance = null; diff --git a/src/respawn-controller.ts b/src/respawn-controller.ts index 5322ff9b..86ff52bf 100644 --- a/src/respawn-controller.ts +++ b/src/respawn-controller.ts @@ -641,9 +641,6 @@ export class RespawnController extends EventEmitter { /** Current state machine state */ private _state: RespawnState = 'stopped'; - /** Timer for idle detection timeout */ - private idleTimer: NodeJS.Timeout | null = null; - /** Timer for step delays */ private stepTimer: NodeJS.Timeout | null = null; @@ -1505,7 +1502,6 @@ export class RespawnController extends EventEmitter { this.elicitationDetected = false; // Clear on new work cycle this.resetHookState(); // Clear hook signals on new work this.lastWorkingPatternTime = now; - this.clearIdleTimer(); // Cancel hook confirmation timer if running this.cancelTrackedTimer('hook-confirm', this.hookConfirmTimer, 'working patterns detected'); @@ -1608,7 +1604,6 @@ export class RespawnController extends EventEmitter { * @fires stepCompleted - With step 'update' */ private checkUpdateComplete(): void { - this.clearIdleTimer(); this.log('Update completed (ready indicator)'); this.emit('stepCompleted', 'update'); @@ -1643,7 +1638,6 @@ export class RespawnController extends EventEmitter { * @fires stepCompleted - With step 'clear' */ private checkClearComplete(): void { - this.clearIdleTimer(); // Clear the fallback timer since we got prompt detection this.cancelTrackedTimer('clear-fallback', this.clearFallbackTimer, 'prompt detected'); this.clearFallbackTimer = null; @@ -1667,7 +1661,6 @@ export class RespawnController extends EventEmitter { * @fires stepCompleted - With step 'init' (if no kickstart) */ private checkInitComplete(): void { - this.clearIdleTimer(); this.log('/init completed (ready indicator)'); // P2-004: Record step completion @@ -1715,7 +1708,6 @@ export class RespawnController extends EventEmitter { * @fires stepCompleted - With step 'init' */ private checkMonitoringInitIdle(): void { - this.clearIdleTimer(); if (this.stepTimer) { clearTimeout(this.stepTimer); this.stepTimer = null; @@ -1757,7 +1749,6 @@ export class RespawnController extends EventEmitter { * @fires stepCompleted - With step 'kickstart' */ private checkKickstartComplete(): void { - this.clearIdleTimer(); this.log('Kickstart completed (ready indicator)'); this.emit('stepCompleted', 'kickstart'); @@ -1767,22 +1758,10 @@ export class RespawnController extends EventEmitter { this.completeCycle(); } - // Note: Legacy startIdleTimer removed - now using completion-based detection - // with startCompletionConfirmTimer() and startNoOutputTimer() instead. - - /** Clear the idle detection timer if running (legacy cleanup) */ - private clearIdleTimer(): void { - if (this.idleTimer) { - clearTimeout(this.idleTimer); - this.idleTimer = null; - } - } - - /** Clear all timers (idle, step, completion confirm, no-output, pre-filter, step confirm, auto-accept, hook confirm, and clear fallback) */ + /** Clear all timers (step, completion confirm, no-output, pre-filter, step confirm, auto-accept, hook confirm, and clear fallback) */ private clearTimers(): void { // Clear tracked timers map first to avoid stale entries during individual cleanup this.activeTimers.clear(); - this.clearIdleTimer(); if (this.stepTimer) { clearTimeout(this.stepTimer); this.stepTimer = null; diff --git a/src/session.ts b/src/session.ts index e91024a9..afd5d42b 100644 --- a/src/session.ts +++ b/src/session.ts @@ -49,7 +49,6 @@ import { export type { BackgroundTask } from './task-tracker.js'; export type { RalphTrackerState, RalphTodoItem, ActiveBashTool } from './types.js'; -export { withTimeout }; /** Line buffer flush interval (100ms) - forces processing of partial lines */ const LINE_BUFFER_FLUSH_INTERVAL = 100; @@ -97,29 +96,6 @@ const NEWLINE_SPLIT_PATTERN = /\r?\n/; // Claude CLI PATH resolution — shared utility import { getAugmentedPath } from './utils/claude-cli-resolver.js'; -/** - * Wraps a promise with a timeout to prevent indefinite hangs. - * If the promise doesn't resolve within the timeout, rejects with TimeoutError. - * - * @param promise - The promise to wrap - * @param timeoutMs - Timeout in milliseconds - * @param operation - Description of the operation for error messages - * @returns Promise that resolves/rejects with the original result or timeout error - */ -function withTimeout(promise: Promise, timeoutMs: number, operation: string): Promise { - let timeoutId: NodeJS.Timeout; - - const timeoutPromise = new Promise((_, reject) => { - timeoutId = setTimeout(() => { - reject(new Error(`${operation} timed out after ${timeoutMs}ms`)); - }, timeoutMs); - }); - - return Promise.race([promise, timeoutPromise]).finally(() => { - clearTimeout(timeoutId); - }); -} - /** * Represents a JSON message from Claude CLI's stream-json output format. * Messages are newline-delimited JSON objects parsed from PTY output. diff --git a/src/types.ts b/src/types.ts index 1ff36b6c..2388fafe 100644 --- a/src/types.ts +++ b/src/types.ts @@ -667,7 +667,7 @@ export enum ApiErrorCode { /** * User-friendly error messages for each error code */ -export const ErrorMessages: Record = { +const ErrorMessages: Record = { [ApiErrorCode.NOT_FOUND]: 'The requested resource was not found', [ApiErrorCode.INVALID_INPUT]: 'Invalid input provided', [ApiErrorCode.SESSION_BUSY]: 'Session is currently busy', @@ -711,29 +711,6 @@ export function createErrorResponse(code: ApiErrorCode, details?: string): ApiRe }; } -/** - * Response for session operations - */ -export interface SessionResponse { - /** Whether the request succeeded */ - success: boolean; - /** Session details if successful (light state — no full buffers) */ - session?: SessionState & { - /** Claude session ID from CLI */ - claudeSessionId: string | null; - /** Total API cost */ - totalCost: number; - /** Number of messages */ - messageCount: number; - /** Whether Claude is working */ - isWorking: boolean; - /** Timestamp of last prompt */ - lastPromptTime: number; - }; - /** Error message if failed */ - error?: string; -} - /** * Response for quick start operation */ diff --git a/src/utils/index.ts b/src/utils/index.ts index 8f1cac54..e75d8940 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -15,13 +15,10 @@ export { ANSI_ESCAPE_PATTERN_SIMPLE, TOKEN_PATTERN, SPINNER_PATTERN, - createAnsiPatternFull, - createAnsiPatternSimple, - stripAnsi, } from './regex-patterns.js'; -export { MAX_SESSION_TOKENS, validateTokenCounts, validateTokensAndCost } from './token-validation.js'; -export { stringSimilarity, normalizePhrase, fuzzyPhraseMatch, todoContentHash } from './string-similarity.js'; +export { MAX_SESSION_TOKENS } from './token-validation.js'; +export { stringSimilarity, fuzzyPhraseMatch, todoContentHash } from './string-similarity.js'; export { assertNever } from './type-safety.js'; export { wrapWithNice } from './nice-wrapper.js'; export { findClaudeDir, getAugmentedPath } from './claude-cli-resolver.js'; -export { resolveOpenCodeDir, isOpenCodeAvailable, getOpenCodeAugmentedPath } from './opencode-cli-resolver.js'; +export { resolveOpenCodeDir, isOpenCodeAvailable } from './opencode-cli-resolver.js'; diff --git a/src/utils/opencode-cli-resolver.ts b/src/utils/opencode-cli-resolver.ts index 4600d7a5..57124306 100644 --- a/src/utils/opencode-cli-resolver.ts +++ b/src/utils/opencode-cli-resolver.ts @@ -9,7 +9,7 @@ import { execSync } from 'node:child_process'; import { existsSync } from 'node:fs'; -import { delimiter, dirname, join } from 'node:path'; +import { dirname, join } from 'node:path'; import { homedir } from 'node:os'; /** Timeout for exec commands (5 seconds) */ @@ -71,28 +71,3 @@ export function resolveOpenCodeDir(): string | null { export function isOpenCodeAvailable(): boolean { return resolveOpenCodeDir() !== null; } - -/** - * Returns a PATH string that includes the directory containing `opencode`. - * - * Finds the opencode binary (via `which` or common install locations), then - * prepends its directory to the current PATH if not already present. - * Result is cached for subsequent calls. - */ -export function getOpenCodeAugmentedPath(): string { - const currentPath = process.env.PATH || ''; - const dir = resolveOpenCodeDir(); - - if (dir && !currentPath.split(delimiter).includes(dir)) { - return `${dir}${delimiter}${currentPath}`; - } - - return currentPath; -} - -/** - * Reset cached resolution (for testing). - */ -export function resetOpenCodeCache(): void { - _openCodeDir = null; -}