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

Method Execute

pkg/tools/builtin/killshell.go:62–221  ·  view source on GitHub ↗
(ctx context.Context, input map[string]any, tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

60}
61
62func (t *KillShellTool) Execute(ctx context.Context, input map[string]any, tc *tools.ToolContext) (any, error) {
63 // 验证必需参数
64 if err := ValidateRequired(input, []string{"shell_id"}); err != nil {
65 return NewClaudeErrorResponse(err), nil
66 }
67
68 shellID := GetStringParam(input, "shell_id", "")
69 signal := GetStringParam(input, "signal", "SIGTERM")
70 force := GetBoolParam(input, "force", false)
71 wait := GetBoolParam(input, "wait", true)
72 timeoutSeconds := GetIntParam(input, "timeout", 10)
73 cleanup := GetBoolParam(input, "cleanup", true)
74
75 if shellID == "" {
76 return NewClaudeErrorResponse(errors.New("shell_id cannot be empty")), nil
77 }
78
79 start := time.Now()
80
81 // 获取任务管理器
82 taskManager := GetGlobalTaskManager()
83
84 // 获取任务信息以验证存在
85 task, err := taskManager.GetTask(shellID)
86 if err != nil {
87 return map[string]any{
88 "ok": false,
89 "error": "background shell not found: " + shellID,
90 "recommendations": []string{
91 "确认shell_id是否正确",
92 "检查任务是否已经被终止",
93 "使用BashOutput工具查看可用的后台任务",
94 },
95 "shell_id": shellID,
96 "duration_ms": time.Since(start).Milliseconds(),
97 }, nil
98 }
99
100 // 检查任务状态
101 if task.Status != "running" {
102 return map[string]any{
103 "ok": false,
104 "error": "task is not running, current status: " + task.Status,
105 "shell_id": shellID,
106 "command": task.Command,
107 "pid": task.PID,
108 "status": task.Status,
109 "duration_ms": time.Since(start).Milliseconds(),
110 "recommendations": []string{
111 "任务已经完成或失败,无需终止",
112 "使用BashOutput工具查看任务结果",
113 },
114 }, nil
115 }
116
117 // 确定要发送的信号
118 finalSignal := signal
119 if force {

Callers

nothing calls this directly

Calls 13

getSignalNumberMethod · 0.95
waitForProcessExitMethod · 0.95
isProcessRunningMethod · 0.95
getCleanupInfoMethod · 0.95
ValidateRequiredFunction · 0.85
NewClaudeErrorResponseFunction · 0.85
GetStringParamFunction · 0.85
GetBoolParamFunction · 0.85
GetIntParamFunction · 0.85
GetGlobalTaskManagerFunction · 0.85
GetTaskMethod · 0.65
KillTaskMethod · 0.65

Tested by

no test coverage detected