Execute 执行命令
(ctx context.Context, commandName string, args map[string]string)
| 43 | |
| 44 | // Execute 执行命令 |
| 45 | func (e *Executor) Execute(ctx context.Context, commandName string, args map[string]string) (string, error) { |
| 46 | // 1. 加载命令定义 |
| 47 | cmd, err := e.loader.Load(ctx, commandName) |
| 48 | if err != nil { |
| 49 | return "", fmt.Errorf("load command: %w", err) |
| 50 | } |
| 51 | |
| 52 | // 2. 执行前置脚本(如果有) |
| 53 | if cmd.Scripts.Sh != "" { |
| 54 | if err := e.executeScript(ctx, cmd.Scripts.Sh); err != nil { |
| 55 | return "", fmt.Errorf("execute script: %w", err) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // 3. 渲染提示词 |
| 60 | prompt := e.renderPrompt(cmd.PromptTemplate, args) |
| 61 | |
| 62 | // 4. 构建完整的命令消息 |
| 63 | message := e.buildCommandMessage(cmd, prompt) |
| 64 | |
| 65 | return message, nil |
| 66 | } |
| 67 | |
| 68 | // executeScript 执行前置脚本 |
| 69 | func (e *Executor) executeScript(ctx context.Context, scriptPath string) error { |
nothing calls this directly
no test coverage detected