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:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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" ? "关闭本地访问" : "开启本地访问"}
|
||||
|
||||
Reference in New Issue
Block a user