UNPKG

taskflow-ai

Version:

TaskFlow AI - 智能PRD文档解析与任务管理助手,支持多模型AI协同、MCP编辑器集成,专为开发团队设计的CLI工具

142 lines (141 loc) 3.79 kB
/** * 统一命令处理器 * 标准化所有CLI命令的执行和响应处理 */ import { CommandResult } from './unified-response'; /** * 命令选项接口 */ export interface CommandOptions { [key: string]: string | number | boolean | undefined; } /** * 命令上下文接口 */ export interface CommandContext { command: string; args: string[]; options: CommandOptions; startTime: number; requestId: string; } /** * 命令处理器接口 */ export interface CommandHandler<T = unknown> { execute(context: CommandContext): Promise<T>; validate?(context: CommandContext): Promise<void>; cleanup?(context: CommandContext): Promise<void>; } /** * 命令执行器 */ export declare class CommandExecutor { private static performanceMonitor; /** * 执行命令 */ static execute<T = unknown>(command: string, args: string[], options: CommandOptions, handler: CommandHandler<T>): Promise<CommandResult<T>>; /** * 执行带进度显示的命令 */ static executeWithProgress<T = unknown>(command: string, args: string[], options: CommandOptions, handler: CommandHandler<T>, progressMessage?: string): Promise<CommandResult<T>>; /** * 批量执行命令 */ static executeBatch<T = unknown>(commands: Array<{ command: string; args: string[]; options: CommandOptions; handler: CommandHandler<T>; }>): Promise<CommandResult<T>[]>; /** * 记录性能指标 */ private static recordPerformanceMetrics; /** * 生成请求ID */ private static generateRequestId; } /** * 抽象命令处理器基类 */ export declare abstract class BaseCommandHandler<T = unknown> implements CommandHandler<T> { /** * 执行命令(子类必须实现) */ abstract execute(context: CommandContext): Promise<T>; /** * 验证命令参数(可选重写) */ validate(context: CommandContext): Promise<void>; /** * 清理资源(可选重写) */ cleanup(_context: CommandContext): Promise<void>; /** * 获取必需参数列表(子类可重写) */ protected getRequiredArgs(): string[]; /** * 获取可选参数列表(子类可重写) */ protected getOptionalArgs(): string[]; /** * 验证参数类型 */ protected validateArgType(value: unknown, expectedType: 'string' | 'number' | 'boolean', argName: string): void; /** * 显示帮助信息 */ protected showHelp(command: string): void; } /** * 命令注册器 */ export declare class CommandRegistry { private static handlers; /** * 注册命令处理器 */ static register(command: string, handler: CommandHandler): void; /** * 获取命令处理器 */ static get(command: string): CommandHandler | undefined; /** * 获取所有注册的命令 */ static getCommands(): string[]; /** * 检查命令是否已注册 */ static has(command: string): boolean; /** * 注销命令处理器 */ static unregister(command: string): boolean; /** * 清空所有注册的命令 */ static clear(): void; } /** * 示例:Init命令处理器 */ export declare class InitCommandHandler extends BaseCommandHandler<{ projectPath: string; filesGenerated: string[]; configCreated: boolean; }> { protected getRequiredArgs(): string[]; protected getOptionalArgs(): string[]; validate(context: CommandContext): Promise<void>; execute(context: CommandContext): Promise<{ projectPath: string; filesGenerated: string[]; configCreated: boolean; }>; cleanup(_context: CommandContext): Promise<void>; }