/** * Command executor - orchestrates command execution * Refactored to use smaller, focused classes for better maintainability */ import type { CommandResult, IsolatedExecutionOptions } from '../types/command.types.js'; import type { DocumentOutputOptions } from '../types/document.types.js'; import type { MCPSamplingService } from '../types/mcp.types.js'; import { AgentLoader } from '../executor/agent-loader.js'; import { CommandLoader } from '../executor/command-loader.js'; import { type Logger } from '../output/logger.js'; import { type AgentSelectionAnalyticsService, type DynamicAgentResolverService } from '../services/index.js'; import { SessionLifecycle } from '../session/lifecycle.js'; import { DocumentOutputProcessor } from './document-output-processor.js'; import { CLIProviderResolver } from './provider-resolver.js'; import { CLISessionManager } from './session-manager.js'; export interface CommandExecutionOptions { args: string[]; documentOutput?: DocumentOutputOptions; flags: Record; interactive?: boolean; isolation?: IsolatedExecutionOptions; sessionId?: string; } /** * Dependencies required by CommandExecutor */ export interface CommandExecutorDependencies { agentLoader: AgentLoader; analyticsService?: AgentSelectionAnalyticsService; commandLoader: CommandLoader; documentOutputProcessor?: DocumentOutputProcessor; dynamicAgentResolver?: DynamicAgentResolverService; logger: Logger; mcpSampling?: MCPSamplingService; providerResolver: CLIProviderResolver; sessionLifecycle: SessionLifecycle; sessionManager: CLISessionManager; } export declare class CommandExecutor { private agentLoader; private commandLoader; private analyticsService?; private dynamicAgentResolver?; private logger; private mcpSampling?; private providerResolver; private sessionLifecycle; private sessionManager; private commandResolver; private commandValidator; private documentOutputProcessor; private errorHandler; private executionCoordinator; private resultPresenter; /** * Creates a CommandExecutor instance * * @param dependencies - Injected dependencies or optional MCP sampling service for backwards compatibility */ constructor(dependencies: CommandExecutorDependencies | MCPSamplingService); /** * Initialize dependencies with default implementations (backwards compatibility) */ private initializeDependencies; /** * Initialize focused service classes (synchronous, analytics deferred) */ private initializeServices; /** * Ensure analytics service is initialized (called on first execution) */ private ensureAnalyticsInitialized; /** * Check if MCP sampling is available */ hasMCPSampling(): boolean; /** * Execute a command using focused service classes */ execute(commandName: string, options: CommandExecutionOptions): Promise; /** * Setup stash protection if enabled for this command */ private setupStashProtection; /** * Restore stashed changes after successful execution */ private restoreStashProtection; /** * Restore stashed changes on error (with error handling) */ private restoreStashOnError; /** * Calculate detailed token usage breakdown from command result */ private calculateTokenUsage; /** * Compute cost from a token breakdown and append a record to the spending ledger. * Returns the cost result for passing through to the result presenter. */ private computeAndRecordSpending; /** * List available commands */ listCommands(): Promise; /** * Validate command prerequisites (command existence and file arguments) */ private validatePrerequisites; /** * Handle successful command result (display and document processing) */ private handleSuccessfulResult; /** * Process document output and update session lifecycle */ private processDocumentOutput; /** * Handle failed command result (display and lifecycle) */ private handleFailedResult; /** * Derive optimization metrics from execution data. * Fields that require workflow signals (early_exit, pattern detection, etc.) are left * undefined — they can be set by the relevant stage outputs when those features exist. */ private computeOptimizationMetrics; /** * Count files referenced in stage outputs (proxy for files_generated). */ private countFilesGenerated; /** * Update session state after execution (history, context, caches) */ private updateSessionState; /** * Save loaded prompts and agents to session context for faster resume * Called after successful command execution */ private saveLoaderCachesToSession; /** * Restore cached prompts and agents from session context * Called when resuming a session with --session-id */ private restoreLoaderCachesFromSession; /** * Save stage outputs to session context for reuse in subsequent commands * Allows commands in the same session to reference previous stage outputs */ private saveStageOutputsToSession; } //# sourceMappingURL=command-executor.d.ts.map