把 github.com/Autumn-27/norma v0.4.3(commit 320ae32)的源码复制到 third_party/norma,并用 go.mod 的 replace 指向本地副本。上游删除仓库或 改写 tag 都不再影响本仓库构建。 - 已验证 GOPROXY=off 下可完整编译并打出发行包 - go.sum 中该模块的两条校验记录随之删除(本地 replace 不需要哈希) - 升级方法与授权注意事项见 third_party/README.md
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package tool
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// NewTaskStop builds the TaskStop tool: kill a running background task (or all).
|
|
func NewTaskStop() CoreTool {
|
|
return Build(Spec{
|
|
Name: "TaskStop",
|
|
Description: "Stops a running background task, killing its process tree. Pass a task_id, or omit it to stop all running tasks.",
|
|
Prompt: "Provide task_id to stop one task, or leave it empty to stop all running tasks.",
|
|
Schema: map[string]any{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"task_id": map[string]any{"type": "string", "description": "The id of the task to stop. Empty stops all running tasks."},
|
|
},
|
|
},
|
|
// Stopping a process the agent itself launched is a safe control op.
|
|
Permissions: allowReadOnly,
|
|
Run: runTaskStop,
|
|
})
|
|
}
|
|
|
|
func runTaskStop(_ context.Context, input json.RawMessage, tc *ToolContext) (Result, error) {
|
|
var in struct {
|
|
TaskID string `json:"task_id"`
|
|
}
|
|
_ = json.Unmarshal(input, &in)
|
|
if tc == nil || tc.Tasks == nil {
|
|
return Errorf("Error: background tasks are not enabled"), nil
|
|
}
|
|
if in.TaskID == "" {
|
|
n := tc.Tasks.KillAll()
|
|
return Text(fmt.Sprintf("Stopped %d running task(s).", n)), nil
|
|
}
|
|
if tc.Tasks.Kill(in.TaskID) {
|
|
return Text(fmt.Sprintf("Stopped task %s.", in.TaskID)), nil
|
|
}
|
|
return Errorf(fmt.Sprintf("Error: unknown task %q", in.TaskID)), nil
|
|
}
|