Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(plugins): allow registered roots beyond browse boundary

Seraph-x6ba8d6b073f5
diff --git a/apps/pi-host/src/host-operations.ts b/apps/pi-host/src/host-operations.ts
index 170cdbca1..45400a6a0 100644
--- a/apps/pi-host/src/host-operations.ts
+++ b/apps/pi-host/src/host-operations.ts
@@ -262,6 +262,11 @@ export function createHostOperations(deps: HostOperationsDeps): Omit<RacpHostOpe
workspacePluginFiles: createWorkspacePluginFiles({
browseRoot: deps.browseRoot ?? homedir(),
protectedPaths: [deps.dataDir ?? join(homedir(), ".pi-desktop")],
+ isRegisteredRoot: async (root) => {
+ const host = requireHost(deps.getHost);
+ const result = await host.call<{ projects: ProjectRow[] }>("projects.list", {}).catch(hostError);
+ return (result.projects ?? []).some((project) => project.path === root);
+ },
}),
...(deps.revokeDevice ? { revokeDevice: deps.revokeDevice } : {}),
};
diff --git a/apps/pi-host/src/plugin-workspace-files.test.ts b/apps/pi-host/src/plugin-workspace-files.test.ts
index 929302c34..2b8b47446 100644
--- a/apps/pi-host/src/plugin-workspace-files.test.ts
+++ b/apps/pi-host/src/plugin-workspace-files.test.ts
@@ -9,6 +9,17 @@ afterEach(async () => {
await Promise.all(temporary.splice(0).map((path) => rm(path, { recursive: true, force: true })));
});
+function projectHost(paths: readonly string[]) {
+ return {
+ async call<T>(method: string): Promise<T> {
+ if (method === "projects.list") {
+ return { projects: paths.map((path, index) => ({ id: index + 1, path, name: `project-${index + 1}` })) } as T;
+ }
+ throw new Error(`unexpected ${method}`);
+ },
+ };
+}
+
async function fixture() {
const home = await realpath(await mkdtemp(join(tmpdir(), "pi-plugin-remote-")));
temporary.push(home);
@@ -21,7 +32,7 @@ async function fixture() {
await writeFile(join(root, ".env"), "private fixture");
await writeFile(join(data, "tokens.json"), "private host fixture");
const operations = createHostOperations({
- getHost: () => null,
+ getHost: () => projectHost([]),
runtime: { compact: async () => ({ accepted: true }), isBusy: () => false },
browseRoot: home,
dataDir: data,
@@ -85,6 +96,36 @@ it("refuses credentials, escaped links, protected Host data and browse-root esca
expect(home).not.toBe(outside);
});
+it("allows an explicitly registered workspace root outside the browse root", { timeout: 60_000 }, async () => {
+ const scratch = await realpath(await mkdtemp(join(tmpdir(), "pi-plugin-registered-")));
+ temporary.push(scratch);
+ const browseRoot = join(scratch, "home");
+ const root = join(scratch, "workspace", "repo");
+ const unregistered = join(scratch, "workspace", "other");
+ await mkdir(browseRoot);
+ await mkdir(root, { recursive: true });
+ await mkdir(unregistered);
+ await writeFile(join(root, "README.md"), "registered workspace\n");
+ const operations = createHostOperations({
+ getHost: () => projectHost([root]),
+ runtime: { compact: async () => ({ accepted: true }), isBusy: () => false },
+ browseRoot,
+ dataDir: join(scratch, "host-data"),
+ });
+ const read = (path: string) => operations.workspacePluginFiles!.read({
+ path,
+ ref: "",
+ operation: "list",
+ scope: ["**"],
+ });
+
+ expect(await read(root)).toMatchObject({
+ kind: "list",
+ entries: [{ name: "README.md", path: "README.md", isDirectory: false }],
+ });
+ await expect(read(unregistered)).rejects.toMatchObject({ code: "REMOTE_PATH_FORBIDDEN" });
+});
+
it("returns explicit oversized/binary results and missing-file errors", { timeout: 60_000 }, async () => {
const { root, read } = await fixture();
await writeFile(join(root, "large.txt"), "x".repeat(512 * 1024 + 1));
diff --git a/apps/pi-host/src/plugin-workspace-files.ts b/apps/pi-host/src/plugin-workspace-files.ts
index e5a7cded1..e71084aa7 100644
--- a/apps/pi-host/src/plugin-workspace-files.ts
+++ b/apps/pi-host/src/plugin-workspace-files.ts
@@ -37,6 +37,7 @@ async function canonical(path: string): Promise<string> {
export function createWorkspacePluginFiles(options: {
browseRoot: string;
protectedPaths: readonly string[];
+ isRegisteredRoot?: (path: string) => Promise<boolean>;
}): NonNullable<RacpHostOperations["workspacePluginFiles"]> {
return { async read(input: WorkspacePluginFilesRequest): Promise<WorkspacePluginFilesResult> {
if (!isAbsolute(input.path) || /[\u0000-\u001f]/.test(input.path)
@@ -53,7 +54,8 @@ export function createWorkspacePluginFiles(options: {
}
}));
const protectedPath = (path: string) => protectedRoots.some((guarded) => inside(guarded, path));
- if (!inside(browseRoot, root) || protectedPath(root) || isDeniedFsPath(root)) throw forbidden();
+ if (protectedPath(root) || isDeniedFsPath(root)) throw forbidden();
+ if (!inside(browseRoot, root) && !(await options.isRegisteredRoot?.(root))) throw forbidden();
if (!(await stat(root)).isDirectory()) throw new RacpError("INVALID_ARGUMENT", "workspace is not a directory");
const authorize = async (requested: string, file: boolean) => {
diff --git a/docs/adr/plugin-remote-workspace-reads.md b/docs/adr/plugin-remote-workspace-reads.md
index b25f79373..0106976fd 100644
--- a/docs/adr/plugin-remote-workspace-reads.md
+++ b/docs/adr/plugin-remote-workspace-reads.md
@@ -21,7 +21,9 @@ resolves the remote binding from host-owned project records, and sends a closed
`workspace/pluginFiles` request. The remote Host advertises this optional
capability and accepts it only from paired owners. It validates canonical
containment, protected Host data, the credential deny-list and the declared
-scope before reading. Requested and canonical file names must both match scope.
+scope before reading. A workspace root must be under the folder picker's browse
+root or exactly match a canonical project root registered on the Host. Requested
+and canonical file names must both match scope.
The SDK accepts an optional expected workspace identity. All calls, including
legacy calls without this argument, capture their root before asynchronous
diff --git a/docs/spec/03-runtime/19-remote-agent-control-protocol.md b/docs/spec/03-runtime/19-remote-agent-control-protocol.md
index a58141ae0..e77898cb8 100644
--- a/docs/spec/03-runtime/19-remote-agent-control-protocol.md
+++ b/docs/spec/03-runtime/19-remote-agent-control-protocol.md
@@ -643,8 +643,9 @@ Legacy remote-Agent operations above remain unchanged.
by optional capability `workspacePluginFiles`. It accepts only
`{ path, operation: "list" | "preview", ref, scope: string[] }`; no Host key,
write payload or external absolute `ref` is accepted. The Host checks its browse
-root, protected data, canonical containment, credential denials, and requested
-and canonical scope before delivery. Results are a closed `kind` union: `list`
+root or an exact canonical project root already registered on that Host,
+protected data, canonical containment, credential denials, and requested and
+canonical scope before delivery. Results are a closed `kind` union: `list`
with root-relative entries, or `text`/`image`/`binary`/`tooLarge` with real size
and `mtimeMs`. Text and images use the existing 512 KiB / 5 MiB preview caps.
Desktop derives the remote root from its admitted project binding and rejects
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index ed84fc13a..e6513f998 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -18710,12 +18710,14 @@ compatible Electron runtime. `PI_E2E_ARTIFACTS` optionally preserves screenshots
The isolated production plugin process and `file://` view use Desktop's actual
SDK broker, durable-binding reader, loopback RACP transport and Host filesystem
service. Only the fixture's project-record lookup and authentication bootstrap
-are supplied by the harness. Verify nested listings, text/image bytes, hidden
-credentials, read-only editor/save/menu controls, visible disconnect errors and
-refresh recovery, rejected late previews and ancestor opens after a project
-switch, and restored local editing/Browser/editor detection. No model, user
-profile or external SSH server participates. Real SSH transport and native
-Windows/Linux behavior require their separate platform acceptance.
+are supplied by the harness. The remote fixture root is registered explicitly
+outside the Host folder picker's browse root. Verify nested listings,
+text/image bytes, hidden credentials, read-only editor/save/menu controls,
+visible disconnect errors and refresh recovery, rejected late previews and
+ancestor opens after a project switch, and restored local
+editing/Browser/editor detection. No model, user profile or external SSH server
+participates. Real SSH transport and native Windows/Linux behavior require
+their separate platform acceptance.
### E2E-GENUI-inline-visualization-card: a visualization renders inline and stays sandboxed
diff --git a/docs/spec/07-plugins/03-plugin-api.md b/docs/spec/07-plugins/03-plugin-api.md
index 19a115cbc..4dc7f337b 100644
--- a/docs/spec/07-plugins/03-plugin-api.md
+++ b/docs/spec/07-plugins/03-plugin-api.md
@@ -391,9 +391,11 @@ identity and adds `remote: { path, readOnly: true }`; `remote.path` is a display
path, never a local filesystem root. `fs.list` and `fs.readPreview` route these
roots through the paired owner Host's optional `workspacePluginFiles`
capability. The Host enforces canonical containment, protected paths, credential
-denials and the plugin's declared scope. Other filesystem channels remain local
-and reject opaque remote roots. A missing capability reports
-`HOST_VERSION_MISMATCH`; no request falls back to the Desktop filesystem.
+denials and the plugin's declared scope. The root must be below the Host's folder
+picker browse root or exactly match a canonical project root registered on that
+Host. Other filesystem channels remain local and reject opaque remote roots. A
+missing capability reports `HOST_VERSION_MISMATCH`; no request falls back to the
+Desktop filesystem.
The optional `workspacePath` must equal the workspace identity captured by the
view. A mismatch reports `WORKSPACE_CHANGED`. All reads capture their root
diff --git a/docs/zh-CN/spec/03-runtime/19-remote-agent-control-protocol.md b/docs/zh-CN/spec/03-runtime/19-remote-agent-control-protocol.md
index f3f61b27d..018fa9645 100644
--- a/docs/zh-CN/spec/03-runtime/19-remote-agent-control-protocol.md
+++ b/docs/zh-CN/spec/03-runtime/19-remote-agent-control-protocol.md
@@ -12,7 +12,8 @@
插件远程只读文件使用独立的 owner-only `workspace/pluginFiles`,由可选能力
`workspacePluginFiles` 广播。封闭请求为
`{ path, operation: "list" | "preview", ref, scope: string[] }`,不接受 Host key、
-写入或根外绝对 ref。Host 校验浏览根、受保护数据、规范路径包含关系、凭据拒绝列表,
+写入或根外绝对 ref。工作区根必须位于文件夹选择器的浏览根内,或精确匹配已在该 Host
+注册的规范项目根;Host 继续校验受保护数据、规范路径包含关系、凭据拒绝列表,
以及原始/规范相对路径的 scope。结果为 `list` 条目或带真实 size/mtimeMs 的
`text`、`image`、`binary`、`tooLarge`;文本/图片上限为 512 KiB / 5 MiB。
Desktop 从已准入项目绑定选择远程根,绑定或连接生命周期改变后拒绝过期结果。
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index ef8fc7fca..4cccbcbc2 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -9960,7 +9960,8 @@ PluginPack 产物的解包目录,仅用于开发验证。验收 #1711 前需
隔离的真实插件进程与生产 `file://` 视图经过 Desktop SDK 网关、持久绑定读取器、
本机回环 RACP 传输和真实 Host 文件服务。仅项目记录查询和认证启动由夹具提供。
-检查嵌套目录、文本/图片、凭据隐藏、编辑器/保存/菜单只读、断线错误和刷新恢复,
+远程夹具根会显式注册在 Host 文件夹选择器浏览根之外。检查嵌套目录、文本/图片、
+凭据隐藏、编辑器/保存/菜单只读、断线错误和刷新恢复,
以及切换项目后拒绝延迟预览和祖先打开请求,并恢复本地编辑、Browser 和编辑器探测。
不使用模型、用户 profile 或外部 SSH;真实 SSH 及 Windows/Linux 原生行为需另行平台验收。
diff --git a/docs/zh-CN/spec/07-plugins/03-plugin-api.md b/docs/zh-CN/spec/07-plugins/03-plugin-api.md
index f82fceeb3..90f68319b 100644
--- a/docs/zh-CN/spec/07-plugins/03-plugin-api.md
+++ b/docs/zh-CN/spec/07-plugins/03-plugin-api.md
@@ -327,7 +327,9 @@ pi.fs.requestDirectory(): Promise<{ path: string; name: string } | null>
SSH 项目的 `workspace.get` 保留不透明的 `remote-project:` 身份,并新增
`remote: { path, readOnly: true }`。`remote.path` 仅用于显示,不能交给本地文件系统。
`fs.list` 与 `fs.readPreview` 经配对 owner Host 的可选 `workspacePluginFiles`
-能力读取;Host 检查规范路径包含关系、受保护目录、凭据拒绝列表与插件声明的 scope。
+能力读取;工作区根必须位于 Host 文件夹选择器的浏览根内,或精确匹配已在该 Host
+注册的规范项目根;Host 继续检查规范路径包含关系、受保护目录、凭据拒绝列表与插件
+声明的 scope。
远程预览还返回真实 `mtimeMs`;其他文件通道仍限本地并明确拒绝远程身份。
缺少能力返回 `HOST_VERSION_MISMATCH`,不会改读 Desktop 文件系统。
diff --git a/scripts/e2e-remote-file-manager.mjs b/scripts/e2e-remote-file-manager.mjs
index 470d79ebe..d471e6872 100644
--- a/scripts/e2e-remote-file-manager.mjs
+++ b/scripts/e2e-remote-file-manager.mjs
@@ -47,6 +47,7 @@ try {
const localPath = join(temp, "local-control");
await mkdir(join(remotePath, "docs"), { recursive: true });
await mkdir(localPath);
+ await mkdir(join(temp, "browse-root"));
await mkdir(join(remotePath, "nested"));
await mkdir(join(localPath, "nested"));
await writeFile(join(remotePath, "nested/deep.txt"), "REMOTE NESTED\n");
@@ -67,7 +68,9 @@ try {
assert.equal(method, "project.groups.list", "only durable binding lookup is stubbed"); return { groups };
} };
protocol = await harness({ operations: { workspacePluginFiles: createWorkspacePluginFiles({
- browseRoot: temp, protectedPaths: [join(temp, "host-data")],
+ browseRoot: join(temp, "browse-root"),
+ protectedPaths: [join(temp, "host-data")],
+ isRegisteredRoot: async path => path === remotePath,
}) } });
binding = await bindRacpWebSocket({ server: protocol.server, authenticator: protocol.authenticator,
port: 0, log: () => {} });