把 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
60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
package tool
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// NewMonitor builds the Monitor tool: start a long-running streaming process in
|
|
// the background (tail -f, watch, a dev server, a polling loop) and return
|
|
// immediately. Inspect it with Read/TaskOutput and end it with TaskStop.
|
|
func NewMonitor() CoreTool {
|
|
return Build(Spec{
|
|
Name: "Monitor",
|
|
Description: "Starts a long-running streaming process in the background (e.g. tail -f, watch, a dev server, a polling loop) and returns immediately with a task id and output-file path. Use Read or TaskOutput to inspect it and TaskStop to end it.",
|
|
Prompt: "Provide a command that streams output over time. It always runs in the background; you are notified if it exits on its own.",
|
|
Schema: map[string]any{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"command": map[string]any{"type": "string", "description": "The streaming command to run."},
|
|
"description": map[string]any{"type": "string", "description": "Short description of what is being monitored."},
|
|
},
|
|
"required": []any{"command"},
|
|
},
|
|
// Same catastrophic-command safety floor as Bash.
|
|
Permissions: bashPermissions,
|
|
Run: runMonitor,
|
|
})
|
|
}
|
|
|
|
func runMonitor(_ context.Context, input json.RawMessage, tc *ToolContext) (Result, error) {
|
|
var in struct {
|
|
Command string `json:"command"`
|
|
Description string `json:"description"`
|
|
}
|
|
if err := json.Unmarshal(input, &in); err != nil {
|
|
return Result{}, err
|
|
}
|
|
if strings.TrimSpace(in.Command) == "" {
|
|
return Errorf("Error: command is required"), nil
|
|
}
|
|
if tc == nil || tc.Tasks == nil {
|
|
return Errorf("Error: background tasks are not enabled"), nil
|
|
}
|
|
t, err := tc.Tasks.Spawn(SpawnSpec{
|
|
Command: in.Command,
|
|
Description: in.Description,
|
|
Kind: KindMonitor,
|
|
WorkingDir: tc.WorkingDir,
|
|
})
|
|
if err != nil {
|
|
return Errorf("Error: failed to start monitor: " + err.Error()), nil
|
|
}
|
|
tc.Tasks.Background(t.ID)
|
|
return Text(fmt.Sprintf(
|
|
"Started monitor %s. Output file: %s\nUse TaskOutput{task_id:%q} or Read to inspect it; TaskStop{task_id:%q} to end it.",
|
|
t.ID, t.OutputPath, t.ID, t.ID)), nil
|
|
}
|