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
@@ -3,7 +3,14 @@ import { Dialog } from "../ui/Dialog";
import { Button } from "../ui/Button";
import { useToast } from "../ui/Toast";
import { getMyJarvis, saveMyJarvis, type JarvisConfig, GATEWAY, getToken } from "../lib/api";
import { localRunnerAvailable, localRunnerStatus, startLocalRunner, stopLocalRunner } from "../lib/desktop";
import {
localExecEnabled,
localRunnerAvailable,
localRunnerStatus,
setLocalExecEnabled,
startLocalRunner,
stopLocalRunner,
} from "../lib/desktop";
// 每用户 JARVIS 设置:名字 / 人设 / (高级)自带豆包配置。
// 名字与人设归用户自己;豆包配置齐全则语音走用户的账号,否则走系统兜底。
@@ -121,11 +128,15 @@ function LocalAccessSection() {
const [dir, setDir] = useState("");
const [status, setStatus] = useState("offline");
const [busy, setBusy] = useState(false);
const [canExec, setCanExec] = useState(false);
useEffect(() => {
if (!localRunnerAvailable()) return;
let alive = true;
const poll = () => localRunnerStatus().then((s) => alive && setStatus(s)).catch(() => {});
const poll = () => {
localRunnerStatus().then((s) => alive && setStatus(s)).catch(() => {});
localExecEnabled().then((v) => alive && setCanExec(v)).catch(() => {});
};
poll();
const iv = window.setInterval(poll, 2000);
return () => {
@@ -181,6 +192,27 @@ function LocalAccessSection() {
<Button variant={online ? "ghost" : "secondary"} size="sm" onClick={onToggle} disabled={busy}>
{online || status === "connecting" ? "关闭本地访问" : "开启本地访问"}
</Button>
{/* 第二道开关:写文件 + 执行命令。风险等级远高于只读,所以单独开、且每次仍要弹框批准。 */}
{online && (
<label className="mt-1 flex cursor-pointer items-start gap-2 border-t border-line pt-3">
<input
type="checkbox"
className="mt-0.5"
checked={canExec}
onChange={(e) => {
setLocalExecEnabled(e.target.checked);
setCanExec(e.target.checked);
}}
/>
<span className="text-[11px] leading-relaxed text-slate-400">
<b className="text-slate-200"> / </b>
<span className="mt-0.5 block text-slate-500">
JARVIS
</span>
</span>
</label>
)}
</div>
);
}