feat(jarvis): 能动的手(写文件/执行命令,三道闸) + 定时任务调度

此前 JARVIS 只能看不能动(本地工具纯只读)、也不会调度,补齐这两块。

【能动的手】local_write_file / local_exec,在用户自选工作目录内动手:
- 独立开关:只开只读访问不给这能力,须单独勾「允许写文件/执行命令」
- 原生确认框逐次审批:展示命令原文,默认按钮=拒绝,60s 无人应答按拒绝
  (防无人值守被静默批准);可选「本次会话都允许」,关开关即失效
- 硬黑名单:删库/提权/管道下载执行/写系统路径/装开机项/摸凭据等,
  用户点同意也不执行,连审批框都不弹。20 条危险命令 + 10 条正常命令单测
- 命令 cwd 锁沙箱根、60s 超时、输出 16KB 截断;非零退出不算失败(编译/测试
  错误对模型是有用信息)

【定时任务】sundynix_schedule + leader 锁 ticker(30s 扫) + 三个平台工具:
- 存自然语言指令而非编排图,到点走语音同一条关卡(preflightCore/launchCore)
  执行,跑完经语音事件主动播报结果
- 先推进 NextRunAt 再提交:提交失败也不会下轮重复捞起反复烧钱
- 停机期间错过的不补跑(补一堆历史提醒是骚扰),直接顺推到下一个未来时刻

【顺带修一个必崩的 bug】dispatcher 工具超时硬编码 3 秒,而审批要等人点
(60s)+执行(60s)——local_exec 100% 超时。改成工具在 list_tools 自报
timeout_sec(不在 dispatcher 硬编码工具名),超时链外松内紧:
dispatcher 160s > 网关 150s > runner 转发 140s > 桌面端 60+60s。

live 验证:①「写个 hello.sh 打印日期然后跑一下」→ 写+执行两步,文件真落磁盘
②「建个定时任务 35 秒后跑 wc -l」→ 到点自动触发 → 自主调 local_exec → 出结果

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-25 13:57:49 +08:00
parent 52988af196
commit 348f1e0249
16 changed files with 832 additions and 25 deletions
@@ -52,6 +52,10 @@ type mcpTool struct {
caller ToolCaller
taskID string
tr *execTracer
// timeout 该工具自报的超时预算(0=用默认 toolCallTimeout)。
// 本地执行类工具要等用户在桌面端点确认框(人的反应时间)+ 真跑命令,
// 远超默认 3 秒;由工具在 list_tools 里声明 timeout_sec,别在这硬编码工具名。
timeout time.Duration
}
func (m *mcpTool) Info(_ context.Context) (*schema.ToolInfo, error) { return m.info, nil }
@@ -68,7 +72,11 @@ func (m *mcpTool) InvokableRun(ctx context.Context, argsJSON string, _ ...tool.O
}
log.Printf("[react] 模型自主调用工具 %s (mcp=%s) task=%s args=%s", m.info.Name, m.mcpName, m.taskID, truncate(argsJSON, 120))
end := m.tr.span("tool:"+m.mcpName, "tool", "模型自主调用 "+m.info.Name)
cctx, cancel := context.WithTimeout(ctx, toolCallTimeout)
budget := toolCallTimeout
if m.timeout > 0 {
budget = m.timeout
}
cctx, cancel := context.WithTimeout(ctx, budget)
defer cancel()
res, err := m.caller.CallTool(cctx, m.subject(m.mcpName), &contract.ToolCall{Tool: m.mcpName, TaskID: m.taskID, Args: args})
if err != nil {
@@ -101,6 +109,8 @@ type toolCatalogEntry struct {
Required bool `json:"required"`
} `json:"params"`
Inject []string `json:"inject"`
// TimeoutSec 工具自报的超时预算(秒,0=用默认)。需要人工确认或长耗时的工具靠它突破默认 3 秒。
TimeoutSec int `json:"timeout_sec"`
}
// agentTools 动态构建 ReAct 可用的工具集:分别向 mcp-go / mcp-py 探 list_tools 自描述目录,
@@ -159,7 +169,8 @@ func (o *Orchestrator) discoverTools(subject func(string) string, b *board, task
mcpName: e.Name,
subject: subject,
caller: o.tools, taskID: taskID, tr: tr,
bind: bind,
bind: bind,
timeout: time.Duration(e.TimeoutSec) * time.Second,
info: &schema.ToolInfo{
Name: name, Desc: e.Desc,
ParamsOneOf: schema.NewParamsOneOfByParams(params),