(ctx context.Context, input map[string]any, tc *tools.ToolContext)
| 78 | } |
| 79 | |
| 80 | func (t *BashOutputTool) Execute(ctx context.Context, input map[string]any, tc *tools.ToolContext) (any, error) { |
| 81 | // 验证必需参数 |
| 82 | if err := ValidateRequired(input, []string{"bash_id"}); err != nil { |
| 83 | return NewClaudeErrorResponse(err), nil |
| 84 | } |
| 85 | |
| 86 | bashID := GetStringParam(input, "bash_id", "") |
| 87 | filter := GetStringParam(input, "filter", "") |
| 88 | lines := GetIntParam(input, "lines", 100) |
| 89 | follow := GetBoolParam(input, "follow", false) |
| 90 | includeStderr := GetBoolParam(input, "include_stderr", true) |
| 91 | since := GetStringParam(input, "since", "") |
| 92 | resourceInfo := GetBoolParam(input, "resource_info", false) |
| 93 | clearCache := GetBoolParam(input, "clear_cache", false) |
| 94 | |
| 95 | if bashID == "" { |
| 96 | return NewClaudeErrorResponse(errors.New("bash_id cannot be empty")), nil |
| 97 | } |
| 98 | |
| 99 | start := time.Now() |
| 100 | |
| 101 | // 获取任务管理器 |
| 102 | taskManager := GetGlobalTaskManager() |
| 103 | |
| 104 | // 获取任务信息 |
| 105 | task, err := taskManager.GetTask(bashID) |
| 106 | if err != nil { |
| 107 | return map[string]any{ |
| 108 | "ok": false, |
| 109 | "error": "background task not found: " + bashID, |
| 110 | "recommendations": []string{ |
| 111 | "确认bash_id是否正确", |
| 112 | "检查任务是否还在运行", |
| 113 | "使用Bash工具查看可用的后台任务", |
| 114 | }, |
| 115 | "bash_id": bashID, |
| 116 | "duration_ms": time.Since(start).Milliseconds(), |
| 117 | }, nil |
| 118 | } |
| 119 | |
| 120 | // 获取任务输出 |
| 121 | stdout, stderr, err := taskManager.GetTaskOutput(bashID, filter, lines) |
| 122 | if err != nil { |
| 123 | return map[string]any{ |
| 124 | "ok": false, |
| 125 | "error": fmt.Sprintf("failed to get task output: %v", err), |
| 126 | "bash_id": bashID, |
| 127 | "duration_ms": time.Since(start).Milliseconds(), |
| 128 | }, nil |
| 129 | } |
| 130 | |
| 131 | // 处理clear_cache |
| 132 | if clearCache { |
| 133 | // 清理任务的输出文件缓存 |
| 134 | tm := taskManager.(*FileTaskManager) |
| 135 | _ = tm.cleanupOutputFiles(bashID) |
| 136 | } |
| 137 |
nothing calls this directly
no test coverage detected