/** * Command Executor - Orchestrates command pipeline * * Responsibilities: * - Orchestrate the four-phase pattern (validate → execute → report/blocked) * - Handle implicit inference (ADR-104) when validation fails with pronouns * - Pass results between phases * - Return the final TurnResult * * All event creation is owned by the action components themselves. */ import { ISystemEvent, IGenericEventSource, Result } from '@sharpee/core'; import { IParser, IValidatedCommand, IParsedCommand, IValidationError } from '@sharpee/world-model'; import { ISound } from '@sharpee/if-domain'; import { WorldModel } from '@sharpee/world-model'; import { EventProcessor } from '@sharpee/event-processor'; import { ActionRegistry } from '@sharpee/stdlib'; import { GameContext, TurnResult, EngineConfig } from './types'; /** * Data passed to pre-action hook listeners (ADR-148). * * Emitted after command validation but before the action's validate phase. * Listeners can modify world state (e.g., break concealment before a noisy action). */ export interface BeforeActionHookData { /** The action about to execute */ actionId: string; /** The actor performing the action */ actorId?: string; /** Direct object entity ID, if any */ directObjectId?: string; } /** * Listener for pre-action hooks. * * @param data - Hook data describing the action about to execute * @param world - The world model (mutable — listeners can change state) */ export type BeforeActionHookListener = (data: BeforeActionHookData, world: WorldModel) => void; /** * Transformer function for parsed commands. * Called after parsing but before validation. * Can modify the parsed command to bypass or alter validation behavior. * * @param parsed - The parsed command from the parser * @param world - The world model for checking state (e.g., gdtMode) * @returns The (potentially modified) parsed command */ export type ParsedCommandTransformer = (parsed: IParsedCommand, world: WorldModel) => IParsedCommand; export declare class CommandExecutor { private parser; private validator; private actionRegistry; private eventProcessor; private scopeResolver?; private parsedCommandTransformers; private beforeActionListeners; constructor(world: WorldModel, actionRegistry: ActionRegistry, eventProcessor: EventProcessor, parser: IParser, systemEvents?: IGenericEventSource); /** * Validate a parsed command against the world model. * * @param command - The parsed command to validate * @returns Result with validated command or validation error */ validateCommand(command: IParsedCommand): Result; /** * Register a transformer that can modify parsed commands before validation. * Transformers are called in order of registration. * * @param transformer - Function to transform parsed commands */ registerParsedCommandTransformer(transformer: ParsedCommandTransformer): void; /** * Unregister a previously registered transformer. * * @param transformer - The transformer to remove * @returns true if the transformer was found and removed */ unregisterParsedCommandTransformer(transformer: ParsedCommandTransformer): boolean; /** * Register a listener for the pre-action hook (ADR-148). * * Listeners fire after command context creation but before the action's * validate phase. They can modify world state (e.g., break concealment). * * @param listener - The hook listener to register */ onBeforeAction(listener: BeforeActionHookListener): void; /** * Emit the pre-action hook to all registered listeners. */ private emitBeforeAction; execute(input: string, world: WorldModel, context: GameContext, config?: EngineConfig, soundBuffer?: ISound[]): Promise; } export declare function createCommandExecutor(world: WorldModel, actionRegistry: ActionRegistry, eventProcessor: EventProcessor, parser: IParser, systemEvents?: IGenericEventSource): CommandExecutor; //# sourceMappingURL=command-executor.d.ts.map