MCPcopy Create free account
hub / github.com/astercloud/aster / Execute

Method Execute

pkg/commands/executor.go:45–66  ·  view source on GitHub ↗

Execute 执行命令

(ctx context.Context, commandName string, args map[string]string)

Source from the content-addressed store, hash-verified

43
44// Execute 执行命令
45func (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 执行前置脚本
69func (e *Executor) executeScript(ctx context.Context, scriptPath string) error {

Callers

nothing calls this directly

Calls 4

executeScriptMethod · 0.95
renderPromptMethod · 0.95
buildCommandMessageMethod · 0.95
LoadMethod · 0.65

Tested by

no test coverage detected