Lee
2026-04-30
来自河北
只有read write edit bash这几个tool 。 如何解决一些非常识的定制的工具调用?比如我自己的业务提供得mcp 或者skill了。这些都是大模型肯定是不知道。
1
Hanson
2026-04-30
来自广东
func (t *BashTool) Execute(ctx context.Context, args json.RawMessage) (string, error) { var input struct { Command string `json:"command"` Background bool `json:"background"` // 新增标志位 TaskID string `json:"task_id"` // 用于读取日志或停止任务 } if err := json.Unmarshal(args, &input); err != nil { return "", fmt.Errorf("参数解析失败: %w", err) } // --- 场景 A:查看已有后台任务的日志 --- if input.TaskID != "" && input.Command == "logs" { return t.getTaskLogs(input.TaskID) } // --- 场景 B:启动新任务 --- // 基础配置 var shellName string var shellArgs []string if runtime.GOOS == "windows" { shellName = "powershell" shellArgs = []string{"-NoProfile", "-Command", input.Command} } else { shellName = "bash" shellArgs = []string{"-c", input.Command} } if input.Background { return t.startBackgroundProcess(input.Command, shellName, shellArgs) } // --- 场景 C:传统的同步执行 (保留原有 30s 超时逻辑) --- return t.executeSync(ctx, input.Command, shellName, shellArgs) }
展开
琥珀·
2026-04-29
来自山西
大模型分析后,bash.go的cmd命令执行可以根据不同的操作系统进行选择 // 根据操作系统选择不同的 shell var cmd *exec.Cmd if runtime.GOOS == "windows" { cmd = exec.CommandContext(timeoutCtx, "powershell", "-Command", input.Command) } else { cmd = exec.CommandContext(timeoutCtx, "bash", "-c", input.Command) }
$侯
2026-04-29
来自浙江
bash -c 那里改成下面,windows上的powershell里就也能跑起来了: ```go import "runtime" // 记得在 import 处添加 // ... var cmd *exec.Cmd if runtime.GOOS == "windows" { // Windows 环境:使用 powershell 执行 // 加上 -NoProfile 可以避免加载冗长的用户脚本,防止命令干扰 cmd = exec.CommandContext(timeoutCtx, "powershell", "-NoProfile", "-NonInteractive", "-Command", input.Command) } else { // macOS/Linux 环境:保持使用 bash cmd = exec.CommandContext(timeoutCtx, "bash", "-c", input.Command) } ```
lJ
2026-04-29
来自江苏
引入ExecTool + ProcessManager + SessionRegistry 架构: Engine Loop ├── bash tool ── 同步执行(30s 超时),适合短期命令 └── exec tool ── 后台进程管理 └── ProcessManager ── SessionRegistry (sessionId -> ProcessSession) 核心 1. 非阻塞启动:cmd.Start() 不等待进程退出,cmd.Wait() 在后台 goroutine 执行 2. 进程组终止:kill(-pid, SIGKILL) 清理进程及所有子进程 3. 输出缓冲:bytes.Buffer 存储 stdout/stderr,支持后续查询 数据结构 - ProcessSession — 存储 PID、Command、Status、OutputBuffer、StdinWriter - ProcessManager — 全局单例,管理所有会话生命周期 - SessionRegistry — 线程安全的 sessionId → ProcessSession 映射 ExecTool action 参数 - run — 必需参数 command,启动进程,background=true 时后台运行 - poll — 必需参数 sessionId,查询进程状态和退出码 - read — 必需参数 sessionId,读取 stdout/stderr 输出 - write — 必需参数 sessionId 和 data,向进程 stdin 写入数据 - kill — 必需参数 sessionId,终止进程组
展开