diff --git a/sundynix-desktop/frontend/bindings/github.com/sundynix/sundynix-desktop/app.ts b/sundynix-desktop/frontend/bindings/github.com/sundynix/sundynix-desktop/app.ts index 534124e..6bf744e 100644 --- a/sundynix-desktop/frontend/bindings/github.com/sundynix/sundynix-desktop/app.ts +++ b/sundynix-desktop/frontend/bindings/github.com/sundynix/sundynix-desktop/app.ts @@ -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 { + return $Call.ByID(2376992125); +} + /** * LocalExecEnabled 供前端显示开关状态。 */ @@ -66,11 +73,11 @@ export function SetLocalExecEnabled(on: boolean): $CancellablePromise { } /** - * StartLocalRunner 开启本地文件访问:以 workdir 为沙箱根连接 gateway 注册执行器。 + * StartLocalRunner 开启本地访问:dirs 是换行分隔的授权目录列表(沙箱白名单)。 * 幂等:重复调用先停旧连接。断线自动重连(5s 退避)直到 StopLocalRunner。 */ -export function StartLocalRunner(gatewayURL: string, token: string, workdir: string): $CancellablePromise { - return $Call.ByID(2808780368, gatewayURL, token, workdir); +export function StartLocalRunner(gatewayURL: string, token: string, dirs: string): $CancellablePromise { + return $Call.ByID(2808780368, gatewayURL, token, dirs); } /** diff --git a/sundynix-desktop/frontend/src/lib/desktop.ts b/sundynix-desktop/frontend/src/lib/desktop.ts index 5eeb851..7b9cc78 100644 --- a/sundynix-desktop/frontend/src/lib/desktop.ts +++ b/sundynix-desktop/frontend/src/lib/desktop.ts @@ -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 { - if (!inWails()) throw new Error("本地文件访问仅桌面端可用"); - await App.StartLocalRunner(gatewayURL, token, workdir); +// startLocalRunner:以 dirs(换行分隔的多个目录)为沙箱白名单开启本地访问。 +export async function startLocalRunner(gatewayURL: string, token: string, dirs: string): Promise { + if (!inWails()) throw new Error("本地访问仅桌面端可用"); + await App.StartLocalRunner(gatewayURL, token, dirs); +} + +// defaultLocalDirs:桌面/下载/文档的绝对路径(换行分隔),供一键填入。 +export async function defaultLocalDirs(): Promise { + if (!inWails()) return ""; + return App.DefaultLocalDirs(); } export function stopLocalRunner(): void { diff --git a/sundynix-desktop/frontend/src/shell/JarvisSettings.tsx b/sundynix-desktop/frontend/src/shell/JarvisSettings.tsx index 841b402..59b28c3 100644 --- a/sundynix-desktop/frontend/src/shell/JarvisSettings.tsx +++ b/sundynix-desktop/frontend/src/shell/JarvisSettings.tsx @@ -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 (
- 本地文件访问(试验 · 只读) + 本地访问(授权目录) {online ? "已开启" : status === "connecting" ? "连接中…" : "未开启"}

- 开启后 JARVIS 能查看/读取下面这个目录里的文件(仅此目录,不能写、不能执行命令)。 - 对话里可以说“看看我工作目录里有什么”。 + JARVIS 只能在你授权的这些目录里活动(其余一律拒绝)。开启后可以说 + “看看我桌面上有什么”“把下载里的图片整理一下”。默认只读;要让它动手改文件、跑命令, + 还得单独打开下面那个开关。

{online ? ( -

{status.slice("online:".length)}

+
+ {status.slice("online:".length).split("\n").filter(Boolean).map((d) => ( +

· {d}

+ ))} +
) : ( - setDir(e.target.value)} - placeholder="/Users/你/Documents/某个目录" - /> + <> +