* 工具执行入口
(params: Record<string, any>)
| 83 | * 工具执行入口 |
| 84 | */ |
| 85 | async execute(params: Record<string, any>): Promise<CommandExecutionResult> { |
| 86 | try { |
| 87 | // 预处理参数 |
| 88 | const processedParams = await this.preprocessParameters(params); |
| 89 | |
| 90 | // 构建命令 |
| 91 | const command = await this.buildCommand(processedParams); |
| 92 | |
| 93 | // 获取确认选项 |
| 94 | const confirmationOptions = this.getConfirmationOptions(processedParams); |
| 95 | |
| 96 | // 获取工作目录 |
| 97 | const workingDirectory = this.getWorkingDirectory(processedParams); |
| 98 | |
| 99 | // 预检查命令 |
| 100 | const preCheckResult = await this.preCheckCommand(command, workingDirectory, processedParams); |
| 101 | |
| 102 | if (!preCheckResult.valid) { |
| 103 | return await this.handlePreCheckFailure( |
| 104 | preCheckResult, |
| 105 | workingDirectory, |
| 106 | confirmationOptions |
| 107 | ); |
| 108 | } |
| 109 | |
| 110 | // 如果需要确认,进行用户确认 |
| 111 | if (!confirmationOptions.skipConfirmation) { |
| 112 | const confirmed = await this.confirmExecution( |
| 113 | command, |
| 114 | workingDirectory, |
| 115 | confirmationOptions, |
| 116 | processedParams |
| 117 | ); |
| 118 | |
| 119 | if (!confirmed) { |
| 120 | return { |
| 121 | success: false, |
| 122 | error: '用户取消执行', |
| 123 | cancelled: true, |
| 124 | }; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // 执行命令 |
| 129 | return await this.executeCommand( |
| 130 | command, |
| 131 | workingDirectory, |
| 132 | confirmationOptions, |
| 133 | processedParams |
| 134 | ); |
| 135 | } catch (error: any) { |
| 136 | return { |
| 137 | success: false, |
| 138 | error: `工具执行失败: ${error.message}`, |
| 139 | }; |
| 140 | } |
| 141 | } |
| 142 |
nothing calls this directly
no test coverage detected