feat(jarvis): 本地沙箱改多目录白名单 + 让它知道自己能操作这台电脑

单目录沙箱做不了"操作我电脑"——只能在一个文件夹里打转,跨目录整理直接没戏。
且模型压根不知道 shell 除了跑脚本还能开 App、控 App、触发快捷指令。

沙箱:单根 → 多根白名单
- 用户授权多个目录(设置里每行一个,可一键填入桌面/下载/文档),其余一律拒
- 路径改绝对路径(多根之下相对路径没有唯一含义),支持 ~ 展开,相对路径兜底按首个根解释
- local_list_dir 留空 path = 返回授权目录清单 → 模型据此自己发现"我能访问哪儿"
- local_exec 可指定 cwd(须在授权目录内)
- 防逃逸不变:软链解析后必须落在某个根内,越界即拒(单测覆盖 ../ 与软链逃逸)

告诉模型它能干什么
- local_exec 描述展开:文件整理(mv/cp/find)、mdfind 全盘搜、open 开应用/文件/网址、
  osascript 控制 Mac App、shortcuts run/list 触发快捷指令、系统信息
- 语音系统提示词把 JARVIS 定位成"这台电脑的操作者",并要求先想清用哪个工具再动手

live 验证(两个授权目录):
① "你能访问哪些目录,里面有什么" → 自主先查授权清单、再逐个列举,答全对
② "把下载里的图片挪到桌面" → 自主 mv,文件真的跨目录移动了

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-25 15:42:58 +08:00
parent 149c4dc89a
commit a16229573b
10 changed files with 255 additions and 96 deletions
@@ -12,6 +12,13 @@
// @ts-ignore: Unused imports
import { Call as $Call, CancellablePromise as $CancellablePromise, Create as $Create } from "@wailsio/runtime";
/**
* DefaultLocalDirs 返回建议授权的常用目录(桌面/下载/文档),供设置界面一键填入。
*/
export function DefaultLocalDirs(): $CancellablePromise<string> {
return $Call.ByID(2376992125);
}
/**
* LocalExecEnabled 供前端显示开关状态。
*/
@@ -66,11 +73,11 @@ export function SetLocalExecEnabled(on: boolean): $CancellablePromise<void> {
}
/**
* StartLocalRunner 开启本地文件访问:以 workdir 为沙箱根连接 gateway 注册执行器
* StartLocalRunner 开启本地访问:dirs 是换行分隔的授权目录列表(沙箱白名单)
* 幂等:重复调用先停旧连接。断线自动重连(5s 退避)直到 StopLocalRunner。
*/
export function StartLocalRunner(gatewayURL: string, token: string, workdir: string): $CancellablePromise<void> {
return $Call.ByID(2808780368, gatewayURL, token, workdir);
export function StartLocalRunner(gatewayURL: string, token: string, dirs: string): $CancellablePromise<void> {
return $Call.ByID(2808780368, gatewayURL, token, dirs);
}
/**
+10 -4
View File
@@ -33,10 +33,16 @@ export function localRunnerAvailable(): boolean {
return inWails();
}
// startLocalRunner:以 workdir 为沙箱根开启本地文件访问(Go host 连 gateway 注册执行器)
export async function startLocalRunner(gatewayURL: string, token: string, workdir: string): Promise<void> {
if (!inWails()) throw new Error("本地文件访问仅桌面端可用");
await App.StartLocalRunner(gatewayURL, token, workdir);
// startLocalRunner:以 dirs(换行分隔的多个目录)为沙箱白名单开启本地访问
export async function startLocalRunner(gatewayURL: string, token: string, dirs: string): Promise<void> {
if (!inWails()) throw new Error("本地访问仅桌面端可用");
await App.StartLocalRunner(gatewayURL, token, dirs);
}
// defaultLocalDirs:桌面/下载/文档的绝对路径(换行分隔),供一键填入。
export async function defaultLocalDirs(): Promise<string> {
if (!inWails()) return "";
return App.DefaultLocalDirs();
}
export function stopLocalRunner(): void {
@@ -4,6 +4,7 @@ import { Button } from "../ui/Button";
import { useToast } from "../ui/Toast";
import { getMyJarvis, saveMyJarvis, type JarvisConfig, GATEWAY, getToken } from "../lib/api";
import {
defaultLocalDirs,
localExecEnabled,
localRunnerAvailable,
localRunnerStatus,
@@ -155,10 +156,10 @@ function LocalAccessSection() {
stopLocalRunner();
setStatus("offline");
} else {
if (!dir.trim()) throw new Error("填一个允许 JARVIS 访问的本地目录(绝对路径)");
if (!dir.trim()) throw new Error("至少填一个允许 JARVIS 访问的目录(绝对路径,每行一个");
await startLocalRunner(GATEWAY, getToken(), dir.trim());
setStatus("connecting");
toast.push("success", "本地文件访问已开启(只读,锁定在该目录");
toast.push("success", "本地访问已开启(仅限授权目录)");
}
} catch (e) {
toast.push("error", (e as Error).message);
@@ -170,24 +171,39 @@ function LocalAccessSection() {
return (
<div className="space-y-2 rounded-md border border-line bg-ink-900/50 p-3">
<div className="flex items-center justify-between">
<span className="text-xs text-slate-400">访 · </span>
<span className="text-xs text-slate-400">访</span>
<span className={online ? "text-[11px] text-emerald-400" : "text-[11px] text-slate-500"}>
{online ? "已开启" : status === "connecting" ? "连接中…" : "未开启"}
</span>
</div>
<p className="text-[11px] leading-relaxed text-slate-500">
JARVIS <b>/</b>
JARVIS
</p>
{online ? (
<p className="break-all font-mono text-[11px] text-slate-400">{status.slice("online:".length)}</p>
<div className="space-y-0.5">
{status.slice("online:".length).split("\n").filter(Boolean).map((d) => (
<p key={d} className="break-all font-mono text-[11px] text-slate-400">· {d}</p>
))}
</div>
) : (
<input
className="w-full rounded-md border border-line bg-ink-850 px-3 py-1.5 font-mono text-sm text-slate-100 focus:border-brand focus:outline-none"
value={dir}
onChange={(e) => setDir(e.target.value)}
placeholder="/Users/你/Documents/某个目录"
/>
<>
<textarea
rows={3}
className="w-full resize-none rounded-md border border-line bg-ink-850 px-3 py-1.5 font-mono text-xs text-slate-100 focus:border-brand focus:outline-none"
value={dir}
onChange={(e) => setDir(e.target.value)}
placeholder={"每行一个目录(绝对路径),例:\n/Users/你/Desktop\n/Users/你/Downloads"}
/>
<button
type="button"
className="text-[11px] text-brand-400 transition hover:underline"
onClick={() => void defaultLocalDirs().then((d) => d && setDir(d))}
>
+ / /
</button>
</>
)}
<Button variant={online ? "ghost" : "secondary"} size="sm" onClick={onToggle} disabled={busy}>
{online || status === "connecting" ? "关闭本地访问" : "开启本地访问"}
+17 -5
View File
@@ -131,7 +131,7 @@ func askApproval(title, detail string) bool {
}
// execWrite 写文件(沙箱内 + 审批)。
func execWrite(root string, req *runnerReq) *runnerResp {
func execWrite(roots []string, req *runnerReq) *runnerResp {
fail := func(m string) *runnerResp { return &runnerResp{ID: req.ID, OK: false, Error: m} }
if !execAllowed() {
return fail("用户未开启「允许执行命令与写文件」。请如实告知用户需要在 JARVIS 设置里打开。")
@@ -141,7 +141,7 @@ func execWrite(root string, req *runnerReq) *runnerResp {
if strings.TrimSpace(rel) == "" {
return fail("缺少文件路径")
}
p, err := resolveInRoot(root, rel)
p, err := resolveAllowed(roots, rel)
if err != nil {
return fail(err.Error())
}
@@ -162,7 +162,7 @@ func execWrite(root string, req *runnerReq) *runnerResp {
}
// execCommand 在沙箱工作目录里跑一条命令(黑名单 + 审批 + 超时 + 输出截断)。
func execCommand(root string, req *runnerReq) *runnerResp {
func execCommand(roots []string, req *runnerReq) *runnerResp {
fail := func(m string) *runnerResp { return &runnerResp{ID: req.ID, OK: false, Error: m} }
if !execAllowed() {
return fail("用户未开启「允许执行命令与写文件」。请如实告知用户需要在 JARVIS 设置里打开。")
@@ -175,14 +175,26 @@ func execCommand(root string, req *runnerReq) *runnerResp {
if reason := checkDenied(cmdStr); reason != "" {
return fail(reason) // 硬拒:连审批框都不弹
}
if !askApproval("JARVIS 想在你的电脑上执行命令", "工作目录:"+root+"\n\n命令:\n"+cmdStr) {
cwd := ""
if len(roots) > 0 {
cwd = roots[0]
}
// 模型可指定在哪个授权目录里跑(不给就用第一个);越界目录直接拒。
if d, _ := req.Args["cwd"].(string); strings.TrimSpace(d) != "" {
resolved, rerr := resolveAllowed(roots, d)
if rerr != nil {
return fail(rerr.Error())
}
cwd = resolved
}
if !askApproval("JARVIS 想在你的电脑上执行命令", "工作目录:"+cwd+"\n\n命令:\n"+cmdStr) {
return fail("用户拒绝了这次执行。")
}
ctx, cancel := context.WithTimeout(context.Background(), execTimeout)
defer cancel()
c := exec.CommandContext(ctx, "/bin/sh", "-c", cmdStr)
c.Dir = root // 工作目录锁在沙箱根
c.Dir = cwd // 工作目录锁在授权目录内
out, err := c.CombinedOutput()
text := string(out)
if len(text) > execMaxOutput {
+3 -3
View File
@@ -62,10 +62,10 @@ func TestExecDeniedWhenSwitchOff(t *testing.T) {
gate.mu.Unlock()
root := t.TempDir()
if r := execCommand(root, &runnerReq{ID: "1", Tool: "local_exec", Args: map[string]any{"command": "ls"}}); r.OK {
if r := execCommand([]string{root}, &runnerReq{ID: "1", Tool: "local_exec", Args: map[string]any{"command": "ls"}}); r.OK {
t.Fatal("开关关闭时命令仍被执行")
}
if r := execWrite(root, &runnerReq{ID: "2", Tool: "local_write_file", Args: map[string]any{"path": "x.txt", "content": "y"}}); r.OK {
if r := execWrite([]string{root}, &runnerReq{ID: "2", Tool: "local_write_file", Args: map[string]any{"path": "x.txt", "content": "y"}}); r.OK {
t.Fatal("开关关闭时写入仍被执行")
}
}
@@ -82,7 +82,7 @@ func TestDenylistPrecedesApproval(t *testing.T) {
gate.mu.Unlock()
}()
r := execCommand(t.TempDir(), &runnerReq{ID: "1", Tool: "local_exec", Args: map[string]any{"command": "sudo rm -rf /"}})
r := execCommand([]string{t.TempDir()}, &runnerReq{ID: "1", Tool: "local_exec", Args: map[string]any{"command": "sudo rm -rf /"}})
if r.OK {
t.Fatal("黑名单命令未被拒绝")
}
+106 -39
View File
@@ -16,11 +16,12 @@ import (
// 本地执行 runnerJARVIS「本地的手」,LOCAL_AGENT_DESIGN 档 A / JARVIS_BRAIN_DESIGN P4):
// 桌面端 Go host 连 gateway 的 /api/v1/local/runner WS,把自己注册成本用户的本地执行器;
// 服务端把 local_* 工具调用转发过来,这里在**用户自选工作目录的沙箱内**执行并回结果。
// 服务端把 local_* 工具调用转发过来,这里在**用户授权目录的沙箱内**执行并回结果。
//
// 安全铁律P1 只读起步)
// - 只实现 list_dir / read_file,无写无 exec
// - 一切路径锁死在用户显式选择的 workdir 根下(清洗 + 软链解析后前缀校验,越界即拒);
// 安全铁律:
// - 多目录白名单:用户授权哪些目录(桌面/下载/文档/项目…),就只能动这些目录,其余一律拒
// - 防逃逸靠软链解析后前缀校验(软链指向白名单外也拒);
// - 写文件/执行命令另有独立开关 + 硬黑名单 + 逐次原生确认框(见 localexec.go);
// - 用户不点"开启",runner 永不连接——本地访问是显式授权,不是默认能力。
type runnerReq struct {
@@ -39,37 +40,69 @@ type runnerResp struct {
// LocalRunner 管一条 runner 连接的生命周期(App 持有单例)。
type LocalRunner struct {
mu sync.Mutex
cancel context.CancelFunc
workdir string
status string // offline / connecting / online
mu sync.Mutex
cancel context.CancelFunc
roots []string // 已授权目录白名单(绝对路径)
status string // offline / connecting / online
}
// StartLocalRunner 开启本地文件访问:以 workdir 为沙箱根连接 gateway 注册执行器
// StartLocalRunner 开启本地访问:dirs 是换行分隔的授权目录列表(沙箱白名单)
// 幂等:重复调用先停旧连接。断线自动重连(5s 退避)直到 StopLocalRunner。
func (a *App) StartLocalRunner(gatewayURL, token, workdir string) error {
abs, err := filepath.Abs(strings.TrimSpace(workdir))
if err != nil {
return fmt.Errorf("工作目录无效: %w", err)
func (a *App) StartLocalRunner(gatewayURL, token, dirs string) error {
var roots []string
for _, line := range strings.Split(dirs, "\n") {
d := strings.TrimSpace(line)
if d == "" {
continue
}
if d == "~" || strings.HasPrefix(d, "~/") {
if home, err := os.UserHomeDir(); err == nil {
d = filepath.Join(home, strings.TrimPrefix(strings.TrimPrefix(d, "~"), "/"))
}
}
abs, err := filepath.Abs(d)
if err != nil {
return fmt.Errorf("目录无效: %s", d)
}
if fi, err := os.Stat(abs); err != nil || !fi.IsDir() {
return fmt.Errorf("目录不存在或不是目录: %s", abs)
}
roots = append(roots, abs)
}
if fi, err := os.Stat(abs); err != nil || !fi.IsDir() {
return fmt.Errorf("工作目录不存在或不是目录: %s", abs)
if len(roots) == 0 {
return fmt.Errorf("至少要授权一个目录")
}
a.runner.stop()
ctx, cancel := context.WithCancel(context.Background())
a.runner.mu.Lock()
a.runner.cancel = cancel
a.runner.workdir = abs
a.runner.roots = roots
a.runner.status = "connecting"
a.runner.mu.Unlock()
wsURL := strings.Replace(strings.TrimRight(gatewayURL, "/"), "http", "ws", 1) +
"/api/v1/local/runner?token=" + token
go a.runner.loop(ctx, wsURL, abs)
go a.runner.loop(ctx, wsURL, roots)
return nil
}
// DefaultLocalDirs 返回建议授权的常用目录(桌面/下载/文档),供设置界面一键填入。
func (a *App) DefaultLocalDirs() string {
home, err := os.UserHomeDir()
if err != nil {
return ""
}
var out []string
for _, name := range []string{"Desktop", "Downloads", "Documents"} {
p := filepath.Join(home, name)
if fi, err := os.Stat(p); err == nil && fi.IsDir() {
out = append(out, p)
}
}
return strings.Join(out, "\n")
}
// StopLocalRunner 关闭本地文件访问(幂等)。
func (a *App) StopLocalRunner() { a.runner.stop() }
@@ -78,7 +111,7 @@ func (a *App) LocalRunnerStatus() string {
a.runner.mu.Lock()
defer a.runner.mu.Unlock()
if a.runner.status == "online" {
return "online:" + a.runner.workdir
return "online:" + strings.Join(a.runner.roots, "\n")
}
return a.runner.status
}
@@ -100,9 +133,9 @@ func (r *LocalRunner) setStatus(s string) {
}
// loop 连接→服务→断线重连(5s 退避),直到 ctx 取消。
func (r *LocalRunner) loop(ctx context.Context, wsURL, root string) {
func (r *LocalRunner) loop(ctx context.Context, wsURL string, roots []string) {
for {
if err := r.serve(ctx, wsURL, root); err != nil && ctx.Err() == nil {
if err := r.serve(ctx, wsURL, roots); err != nil && ctx.Err() == nil {
r.setStatus("connecting")
}
select {
@@ -115,7 +148,7 @@ func (r *LocalRunner) loop(ctx context.Context, wsURL, root string) {
}
// serve 一条连接的会话:发 hello → 循环收请求、沙箱内执行、回结果。
func (r *LocalRunner) serve(ctx context.Context, wsURL, root string) error {
func (r *LocalRunner) serve(ctx context.Context, wsURL string, roots []string) error {
dctx, dcancel := context.WithTimeout(ctx, 10*time.Second)
conn, _, err := websocket.Dial(dctx, wsURL, nil)
dcancel()
@@ -126,7 +159,7 @@ func (r *LocalRunner) serve(ctx context.Context, wsURL, root string) error {
conn.SetReadLimit(1 << 20)
r.setStatus("online")
hello, _ := json.Marshal(runnerResp{ID: "hello", OK: true, Workdir: root})
hello, _ := json.Marshal(runnerResp{ID: "hello", OK: true, Workdir: strings.Join(roots, "、")})
if err := conn.Write(ctx, websocket.MessageText, hello); err != nil {
return err
}
@@ -140,7 +173,7 @@ func (r *LocalRunner) serve(ctx context.Context, wsURL, root string) error {
if json.Unmarshal(data, &req) != nil {
continue
}
resp := execLocal(root, &req)
resp := execLocal(roots, &req)
out, _ := json.Marshal(resp)
if err := conn.Write(ctx, websocket.MessageText, out); err != nil {
return err
@@ -155,10 +188,33 @@ const (
maxDirEntries = 200 // list_dir 上限条数
)
// resolveInRoot 把相对路径解析进沙箱根:清洗 + 软链解析后必须仍在 root 下,越界即错
func resolveInRoot(root, rel string) (string, error) {
p := filepath.Join(root, filepath.Clean("/"+rel)) // 前置 "/" 再 Clean:吃掉 ../ 逃逸
// 软链解析(目标可能不存在:解析其父目录)
// resolveAllowed 把一个路径解析并校验是否落在**任一**授权目录内
// 单目录沙箱做不了"操作我电脑"(只能在一个文件夹里打转),改成多目录白名单:
// 用户授权哪些目录(桌面/下载/文档/项目目录…),agent 就只能在这些目录里动手。
// 路径用绝对路径(多根之下相对路径没有唯一含义),支持 ~ 展开。
// 防逃逸仍靠"软链解析后前缀校验"——软链指向白名单之外一律拒。
func resolveAllowed(roots []string, p string) (string, error) {
p = strings.TrimSpace(p)
if p == "" {
return "", fmt.Errorf("缺少路径")
}
if p == "~" || strings.HasPrefix(p, "~/") {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
p = filepath.Join(home, strings.TrimPrefix(strings.TrimPrefix(p, "~"), "/"))
}
if !filepath.IsAbs(p) {
// 相对路径按第一个授权目录解释(兜底:模型偶尔会给相对路径)
if len(roots) == 0 {
return "", fmt.Errorf("没有已授权的目录")
}
p = filepath.Join(roots[0], filepath.Clean("/"+p))
}
p = filepath.Clean(p)
// 软链解析(目标可能不存在:那就用清洗后的路径本身比对)
resolved, err := filepath.EvalSymlinks(p)
if err != nil {
if !os.IsNotExist(err) {
@@ -166,23 +222,34 @@ func resolveInRoot(root, rel string) (string, error) {
}
resolved = p
}
rootR, err := filepath.EvalSymlinks(root)
if err != nil {
rootR = root
for _, root := range roots {
rootR, err := filepath.EvalSymlinks(root)
if err != nil {
rootR = root
}
if resolved == rootR || strings.HasPrefix(resolved, rootR+string(filepath.Separator)) {
return resolved, nil
}
}
if resolved != rootR && !strings.HasPrefix(resolved, rootR+string(filepath.Separator)) {
return "", fmt.Errorf("路径越出工作目录沙箱")
}
return resolved, nil
return "", fmt.Errorf("路径 %s 不在已授权目录内(当前授权:%s)", p, strings.Join(roots, "、"))
}
func execLocal(root string, req *runnerReq) *runnerResp {
func execLocal(roots []string, req *runnerReq) *runnerResp {
fail := func(msg string) *runnerResp { return &runnerResp{ID: req.ID, OK: false, Error: msg} }
rel, _ := req.Args["path"].(string)
switch req.Tool {
case "local_list_dir":
p, err := resolveInRoot(root, rel)
// 空路径 = 列出所有已授权目录(多根之下没有唯一"根")。
// 这也是模型发现"我能访问哪些地方"的入口。
if strings.TrimSpace(rel) == "" {
data, _ := json.Marshal(map[string]any{
"authorized_dirs": roots,
"hint": "这些是用户授权可访问的目录。要看某个目录内容,把它的绝对路径作为 path 再调一次。",
})
return &runnerResp{ID: req.ID, OK: true, Content: string(data)}
}
p, err := resolveAllowed(roots, rel)
if err != nil {
return fail(err.Error())
}
@@ -214,7 +281,7 @@ func execLocal(root string, req *runnerReq) *runnerResp {
if strings.TrimSpace(rel) == "" {
return fail("缺少文件路径")
}
p, err := resolveInRoot(root, rel)
p, err := resolveAllowed(roots, rel)
if err != nil {
return fail(err.Error())
}
@@ -240,10 +307,10 @@ func execLocal(root string, req *runnerReq) *runnerResp {
// 能动的手(localexec.go):各自带独立开关 + 黑名单 + 原生审批框。
case "local_write_file":
return execWrite(root, req)
return execWrite(roots, req)
case "local_exec":
return execCommand(root, req)
return execCommand(roots, req)
default:
return fail("本地执行器不支持该操作: " + req.Tool)
+13 -7
View File
@@ -34,7 +34,7 @@ func TestResolveInRootBlocksEscape(t *testing.T) {
rootR = root
}
for _, rel := range []string{"..", "../..", "../../etc/passwd", "sub/../../outside", "/etc/passwd"} {
p, err := resolveInRoot(root, rel)
p, err := resolveAllowed([]string{root}, rel)
// 前置 "/"+Clean 把绝对路径/.. 都钉回 root 下(如 root/etc/passwd,不算逃逸);
// 无论哪种形式,成功解析的结果都必须仍在 root(解析后)之内。
if err == nil && p != rootR && !strings.HasPrefix(p, rootR+string(filepath.Separator)) {
@@ -53,7 +53,7 @@ func TestResolveInRootBlocksSymlinkEscape(t *testing.T) {
if err := os.Symlink(outside, link); err != nil {
t.Skip("无法创建软链,跳过")
}
if _, err := resolveInRoot(root, "evil/secret.txt"); err == nil {
if _, err := resolveAllowed([]string{root}, "evil/secret.txt"); err == nil {
t.Fatal("软链逃逸未被拦截")
}
}
@@ -61,8 +61,14 @@ func TestResolveInRootBlocksSymlinkEscape(t *testing.T) {
func TestExecLocalListAndRead(t *testing.T) {
root := newSandbox(t)
// list_dir 根目录
resp := execLocal(root, &runnerReq{ID: "1", Tool: "local_list_dir", Args: map[string]any{"path": ""}})
// list_dir 空路径 = 列出授权目录清单(模型据此发现能访问哪里)
resp := execLocal([]string{root}, &runnerReq{ID: "0", Tool: "local_list_dir", Args: map[string]any{"path": ""}})
if !resp.OK || !strings.Contains(resp.Content, "authorized_dirs") {
t.Fatalf("空路径应返回授权目录清单: ok=%v content=%s", resp.OK, resp.Content)
}
// list_dir 指定目录
resp = execLocal([]string{root}, &runnerReq{ID: "1", Tool: "local_list_dir", Args: map[string]any{"path": root}})
if !resp.OK {
t.Fatalf("list_dir 失败: %s", resp.Error)
}
@@ -80,19 +86,19 @@ func TestExecLocalListAndRead(t *testing.T) {
}
// read_file 子目录文件
resp = execLocal(root, &runnerReq{ID: "2", Tool: "local_read_file", Args: map[string]any{"path": "sub/b.txt"}})
resp = execLocal([]string{root}, &runnerReq{ID: "2", Tool: "local_read_file", Args: map[string]any{"path": "sub/b.txt"}})
if !resp.OK || resp.Content != "world" {
t.Fatalf("read_file 失败: ok=%v content=%q err=%s", resp.OK, resp.Content, resp.Error)
}
// read_file 越界必须拒
resp = execLocal(root, &runnerReq{ID: "3", Tool: "local_read_file", Args: map[string]any{"path": "../outside.txt"}})
resp = execLocal([]string{root}, &runnerReq{ID: "3", Tool: "local_read_file", Args: map[string]any{"path": "/etc/passwd"}})
if resp.OK {
t.Fatal("越界读未被拦截")
}
// 未知工具(写/exec 都不在只读版里)必须拒
resp = execLocal(root, &runnerReq{ID: "4", Tool: "local_write_file", Args: map[string]any{"path": "a.txt"}})
resp = execLocal([]string{root}, &runnerReq{ID: "4", Tool: "local_write_file", Args: map[string]any{"path": "a.txt"}})
if resp.OK {
t.Fatal("未注册操作未被拦截")
}