Skip to content

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

docs(plugins): record the fs root following the calling session

andrewliuea7fd2d3cf30
diff --git a/docs/adr/0266-plugin-fs-root-follows-the-calling-session.md b/docs/adr/0266-plugin-fs-root-follows-the-calling-session.md
new file mode 100644
index 000000000..583924ad1
--- /dev/null
+++ b/docs/adr/0266-plugin-fs-root-follows-the-calling-session.md
@@ -0,0 +1,96 @@
+# ADR 0266: Plugin fs Roots Follow the Calling Session
+
+- **Status**: Accepted
+- **Date**: 2026-09-16
+- **Related**: [ADR 0016](0016-sidebar-organization-and-multi-project-tabs.md) ·
+ [ADR 0249](0249-chatgpt-style-logical-project-groups.md) ·
+ [ADR 0263](0263-project-folder-roots-for-plugin-views.md) ·
+ [ADR 0264](0264-host-mediated-actions-follow-the-browsed-folder.md) ·
+ [07-plugins/03-plugin-api](../spec/07-plugins/03-plugin-api.md) ·
+ [07-plugins/13-plugin-permissions-matrix](../spec/07-plugins/13-plugin-permissions-matrix.md)
+
+## Context
+
+D093 gives the sidebar several retained project tabs while the shell keeps one
+selected host workspace, and it fixes the rule this ADR extends: **tool execution
+resolves its root from the durable session project**, so a background session
+keeps its own root when another tab becomes active. ADR 0016 and ADR 0249 carry
+that separation into the project model, and ADR 0263 / ADR 0264 make the folder
+a view browses plugin-local and per project.
+
+That rule never reached a plugin. Every `pi.fs.*` request resolved its root as
+
+```ts
+rule.root === "userSelected" ? loaded.userRoot : this.services.getWorkspacePath()
+```
+
+and `getWorkspacePath()` is the single window-global visible workspace. Two
+sessions on two projects therefore measured every plugin fs call against
+whichever project the window happened to show: a plugin agent tool invoked from
+session B (project B) read project A's root as soon as the user switched tabs, and
+that same tool failed `NOT_FOUND` ("No workspace is open") for every session at
+once when no workspace was visible at all (a temporary chat). The four path-safety
+gates -- permission, realpath containment, the deny-list, and the declared
+scope/consent -- were correct; only the directory they measured against was wrong.
+
+## Decision
+
+1. **The `workspace` root resolves the project of the tool session that invoked
+ the call.** A new private helper `fsRoot(loaded, rule)` in `plugin-runtime.ts`
+ reads the in-flight tool's `sessionId`, asks the additive host service
+ `getWorkspacePathForSession(sessionId)`, and uses the project it answers as the
+ root. The visible workspace is a fallback only, not the primary answer.
+2. **The session is the dimension the root follows; the fallback is the visible
+ workspace.** A panel-bridge call has no tool session, and a session the host
+ does not track -- a runtime that has not launched yet -- resolves the visible
+ workspace exactly as before.
+3. **A `userSelected` mode is unchanged.** It keeps the directory the user picked
+ through `requestDirectory()`, with the same memory-only lifetime.
+4. **`plugin-services.ts` wires the service from the `sessionProjects` map it
+ already keeps** for D093. No new source of truth is introduced, and the plugin
+ runtime caches nothing: each call reads the host's current answer.
+5. **Not one path-safety gate changes.** Permission, realpath containment, the
+ deny-list, and the declared scope with runtime consent still run, in the same
+ order, over the resolved root. Only *which* directory the `workspace` root
+ names changes.
+6. **A session root also resolves when no workspace is visible.** A temporary
+ chat has no visible workspace, so its plugin tools used to fail all at once;
+ with a session project they keep working per session. A panel call in that
+ state still fails closed, because it has nothing else to resolve.
+
+## Consequences
+
+- Two sessions on two projects no longer cross-talk: a plugin agent tool reads and
+ writes under the project of the session that invoked it, whatever tab is active.
+- Panel-bridge fs calls keep their old meaning: they follow the visible workspace.
+- A plugin that only ever ran one session on one project sees no change at all.
+- `NOT_FOUND` for a `workspace` root is now narrower and more precise: neither the
+ invoking session's project nor a visible workspace resolved.
+- The plugin runtime reads session metadata the host already owns, so the change
+ adds no stored state, no migration, and no new plugin permission.
+
+## Alternatives considered
+
+### Keep the visible workspace and let the tool pass a project id
+
+Rejected: the host already knows the invoking session, so the plugin would have to
+learn and forward a project identifier it does not own, and a plugin-supplied root
+would be a grant its manifest never declared.
+
+### Resolve the session's project inside the plugin process
+
+Rejected: the session-to-project map is host-owned session metadata (D093), and
+copying it into a sandboxed plugin process would move it outside the host
+authority that keeps it current.
+
+### Make the visible workspace follow the active session
+
+Rejected: the visible workspace is what the user is looking at, and ADR 0016 with
+D093 deliberately keep several retained tabs over one selected host workspace.
+Changing what the user sees in order to fix a plugin lookup inverts the causality.
+
+### Fall back to the last visible workspace for a session the host does not track
+
+Rejected as no-op: an untracked session plus no visible workspace is exactly the
+temporary-chat case the session root exists to keep working, so the fallback stays
+"the visible workspace, when there is one".
diff --git a/docs/adr/README.md b/docs/adr/README.md
index b5613f641..9a2bb2a04 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -292,3 +292,4 @@ Each ADR includes:
| 0265 | [Priority block and row actions for the Host-owned turn queue](0265-turn-queue-priority-block-and-row-actions.md) | Accepted for implementation (D429; amends ADR 0213 / 0118) |
| session-content-search | [Discover sessions by indexed message text](session-content-search.md) | Accepted |
| transcript-reading-ownership | [Share renderer history and search views](transcript-reading-ownership.md) | Accepted |
+| 0266 | [Plugin fs roots follow the calling session](0266-plugin-fs-root-follows-the-calling-session.md) | Accepted (D093) |
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index a3890c940..9f31fd1f1 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -7654,10 +7654,10 @@ identify the platform validation still needed.
| E — Tools & permissions | E2E-008a, E2E-014, E2E-015, E2E-016, E2E-017, E2E-018, E2E-019, E2E-024I, E2E-024K, E2E-040, E2E-049, E2E-074, E2E-093, E2E-097, E2E-099, E2E-100, E2E-101, E2E-102, E2E-102d, E2E-102e, E2E-102g, E2E-103, E2E-105, E2E-106, E2E-107, E2E-111, E2E-112, E2E-113, E2E-114, E2E-115, E2E-116, E2E-119, E2E-121, E2E-122, E2E-142, E2E-145, E2E-147, E2E-155, E2E-158, E2E-166, E2E-181, E2E-PLUGIN-imported-pi-package-skills, E2E-CHAT-side-chat-stream |
| F — Persistence | E2E-020, E2E-021, E2E-021a, E2E-036, E2E-037, E2E-038, E2E-040, E2E-042, E2E-047, E2E-048, E2E-051, E2E-054, E2E-056, E2E-061, E2E-062, E2E-064, E2E-066, E2E-068, E2E-071, E2E-072, E2E-073, E2E-082, E2E-084, E2E-096, E2E-098, E2E-102, E2E-102b, E2E-102c, E2E-102d, E2E-102g, E2E-102i, E2E-103, E2E-AGENTS-001, E2E-061a, E2E-073a, E2E-104, E2E-106, E2E-107, E2E-108, E2E-109, E2E-110, E2E-112, E2E-118, E2E-119, E2E-120, E2E-121, E2E-123, E2E-142, E2E-146, E2E-146a, E2E-148, E2E-151, E2E-158, E2E-160, E2E-168, E2E-171, E2E-177, E2E-178, E2E-183, E2E-186, E2E-005J, E2E-PLUGIN-session-orchestrator-real-workers, E2E-CHAT-side-chat-fork, E2E-CHAT-side-chat-promote, E2E-CHAT-side-chat-close, E2E-CHAT-annotation-session-state |
| F — Persistence (project ordering) | E2E-251 |
-| G — Plugins | E2E-022, E2E-022A, E2E-022B, E2E-022C, E2E-023, E2E-024, E2E-024B, E2E-024C, E2E-024D, E2E-024E, E2E-024W, E2E-024F, E2E-024G, E2E-024H, E2E-024I, E2E-024J, E2E-024K, E2E-024L, E2E-024M, E2E-024N, E2E-024O, E2E-024P, E2E-025, E2E-026, E2E-105, E2E-117, E2E-120, E2E-122, E2E-123, E2E-024Q, E2E-148, E2E-152, E2E-153, E2E-PLUGIN-imported-pi-package-skills, E2E-PLUGIN-import-extension-installs-dependencies, E2E-PLUGIN-import-extension-reports-missing-dependency, E2E-PLUGIN-global-shortcut-owns-only-its-own-command, E2E-PLUGIN-permission-gate-for-real-time-capabilities, E2E-PLUGIN-background-audio-and-realtime-connection |
+| G — Plugins | E2E-022, E2E-022A, E2E-022B, E2E-022C, E2E-023, E2E-024, E2E-024B, E2E-024C, E2E-024D, E2E-024E, E2E-024W, E2E-024F, E2E-024G, E2E-024H, E2E-024I, E2E-024J, E2E-024K, E2E-024L, E2E-024M, E2E-024N, E2E-024O, E2E-024P, E2E-025, E2E-026, E2E-105, E2E-117, E2E-120, E2E-122, E2E-123, E2E-024Q, E2E-148, E2E-152, E2E-153, E2E-PLUGIN-imported-pi-package-skills, E2E-PLUGIN-import-extension-installs-dependencies, E2E-PLUGIN-import-extension-reports-missing-dependency, E2E-PLUGIN-global-shortcut-owns-only-its-own-command, E2E-PLUGIN-permission-gate-for-real-time-capabilities, E2E-PLUGIN-background-audio-and-realtime-connection, E2E-PLUGIN-fs-root-follows-the-calling-session |
| H — Diagnostics | E2E-027, E2E-031, E2E-034, E2E-042, E2E-096, E2E-098, E2E-104, E2E-107, E2E-108, E2E-109, E2E-110, E2E-113, E2E-115, E2E-116, E2E-118, E2E-121, E2E-146, E2E-146a, E2E-155, E2E-159, E2E-176, E2E-194, E2E-195 |
-| Security | E2E-028, E2E-029, E2E-030, E2E-024J, E2E-024K, E2E-024M, E2E-049, E2E-068, E2E-086, E2E-102c, E2E-102d, E2E-102e, E2E-105, E2E-106, E2E-107, E2E-108, E2E-109, E2E-110, E2E-112, E2E-113, E2E-115, E2E-116, E2E-117, E2E-119, E2E-121, E2E-122, E2E-123, E2E-142, E2E-148, E2E-151, E2E-153, E2E-158, E2E-187, E2E-196c, E2E-196b, E2E-196 |
-| Quality | E2E-032, E2E-033, E2E-039, E2E-043, E2E-044, E2E-045, E2E-046, E2E-047, E2E-048, E2E-048A, E2E-049, E2E-050, E2E-053, E2E-055, E2E-056, E2E-057, E2E-058, E2E-059, E2E-060, E2E-061, E2E-062, E2E-063, E2E-064, E2E-065, E2E-066, E2E-067, E2E-068, E2E-069, E2E-070, E2E-071, E2E-072, E2E-073, E2E-074, E2E-075, E2E-076, E2E-077, E2E-078, E2E-079, E2E-080, E2E-081, E2E-082, E2E-083, E2E-084, E2E-085, E2E-086, E2E-092, E2E-093, E2E-094, E2E-095, E2E-096, E2E-097, E2E-098, E2E-099, E2E-100, E2E-101, E2E-102, E2E-102a, E2E-102b, E2E-102c, E2E-102d, E2E-102e, E2E-103, E2E-AGENTS-001, E2E-021a, E2E-024N, E2E-059a, E2E-060b, E2E-060c, E2E-061a, E2E-073a, E2E-111, E2E-114, E2E-117, E2E-118, E2E-119, E2E-120, E2E-122, E2E-123, E2E-142, E2E-143, E2E-144, E2E-145, E2E-146, E2E-147, E2E-148, E2E-150, E2E-151, E2E-153, E2E-155, E2E-158, E2E-159, E2E-160, E2E-161, E2E-162, E2E-163, E2E-168, E2E-172, E2E-173, E2E-174, E2E-011g, E2E-176, E2E-177, E2E-178, E2E-179, E2E-180, E2E-181, E2E-182, E2E-183, E2E-186, E2E-187, E2E-194, E2E-195, E2E-196a, E2E-196b, E2E-196c, E2E-198, E2E-199, E2E-200, E2E-196, E2E-201, E2E-204, E2E-202, E2E-203, E2E-205, E2E-206, E2E-207, E2E-208, E2E-209, E2E-210, E2E-218, E2E-219, E2E-250, E2E-252, E2E-102i, E2E-SUBAGENT-settlement-updates-before-parent-poll, E2E-PLUGIN-imported-pi-package-skills, E2E-CHAT-quote-prefill, E2E-CHAT-side-chat-fork, E2E-CHAT-side-chat-stream, E2E-CHAT-side-chat-add-to-main, E2E-CHAT-side-chat-promote, E2E-CHAT-side-chat-close, E2E-CHAT-selection-markdown, E2E-CHAT-selection-side-chat, E2E-CHAT-annotation-attachments, E2E-CHAT-annotation-session-state, E2E-CHAT-annotation-source-index, E2E-CHAT-annotation-ack-and-steering |
+| Security | E2E-028, E2E-029, E2E-030, E2E-024J, E2E-024K, E2E-024M, E2E-049, E2E-068, E2E-086, E2E-102c, E2E-102d, E2E-102e, E2E-105, E2E-106, E2E-107, E2E-108, E2E-109, E2E-110, E2E-112, E2E-113, E2E-115, E2E-116, E2E-117, E2E-119, E2E-121, E2E-122, E2E-123, E2E-142, E2E-148, E2E-151, E2E-153, E2E-158, E2E-187, E2E-196c, E2E-196b, E2E-196, E2E-PLUGIN-fs-root-follows-the-calling-session |
+| Quality | E2E-032, E2E-033, E2E-039, E2E-043, E2E-044, E2E-045, E2E-046, E2E-047, E2E-048, E2E-048A, E2E-049, E2E-050, E2E-053, E2E-055, E2E-056, E2E-057, E2E-058, E2E-059, E2E-060, E2E-061, E2E-062, E2E-063, E2E-064, E2E-065, E2E-066, E2E-067, E2E-068, E2E-069, E2E-070, E2E-071, E2E-072, E2E-073, E2E-074, E2E-075, E2E-076, E2E-077, E2E-078, E2E-079, E2E-080, E2E-081, E2E-082, E2E-083, E2E-084, E2E-085, E2E-086, E2E-092, E2E-093, E2E-094, E2E-095, E2E-096, E2E-097, E2E-098, E2E-099, E2E-100, E2E-101, E2E-102, E2E-102a, E2E-102b, E2E-102c, E2E-102d, E2E-102e, E2E-103, E2E-AGENTS-001, E2E-021a, E2E-024N, E2E-059a, E2E-060b, E2E-060c, E2E-061a, E2E-073a, E2E-111, E2E-114, E2E-117, E2E-118, E2E-119, E2E-120, E2E-122, E2E-123, E2E-142, E2E-143, E2E-144, E2E-145, E2E-146, E2E-147, E2E-148, E2E-150, E2E-151, E2E-153, E2E-155, E2E-158, E2E-159, E2E-160, E2E-161, E2E-162, E2E-163, E2E-168, E2E-172, E2E-173, E2E-174, E2E-011g, E2E-176, E2E-177, E2E-178, E2E-179, E2E-180, E2E-181, E2E-182, E2E-183, E2E-186, E2E-187, E2E-194, E2E-195, E2E-196a, E2E-196b, E2E-196c, E2E-198, E2E-199, E2E-200, E2E-196, E2E-201, E2E-204, E2E-202, E2E-203, E2E-205, E2E-206, E2E-207, E2E-208, E2E-209, E2E-210, E2E-218, E2E-219, E2E-250, E2E-252, E2E-102i, E2E-SUBAGENT-settlement-updates-before-parent-poll, E2E-PLUGIN-imported-pi-package-skills, E2E-CHAT-quote-prefill, E2E-CHAT-side-chat-fork, E2E-CHAT-side-chat-stream, E2E-CHAT-side-chat-add-to-main, E2E-CHAT-side-chat-promote, E2E-CHAT-side-chat-close, E2E-CHAT-selection-markdown, E2E-CHAT-selection-side-chat, E2E-CHAT-annotation-attachments, E2E-CHAT-annotation-session-state, E2E-CHAT-annotation-source-index, E2E-CHAT-annotation-ack-and-steering, E2E-PLUGIN-fs-root-follows-the-calling-session |
| Quality (project ordering) | E2E-253 |
| C — Conversation & stream (IME slash alias) | E2E-255 |
| E — Tools & permissions (Skill residency) | E2E-254 |
@@ -7702,7 +7702,7 @@ identify the platform validation still needed.
| M2 (IME slash alias) | E2E-255 |
| M5 (Skill residency) | E2E-254 |
| M6 | E2E-104, E2E-105, E2E-106, E2E-107, E2E-108, E2E-109, E2E-110, E2E-111, E2E-112, E2E-113, E2E-114, E2E-115, E2E-116, E2E-117, E2E-118, E2E-119, E2E-120, E2E-103, E2E-172 |
-| M6+ | E2E-121, E2E-122, E2E-148, E2E-150, E2E-151, E2E-154, E2E-155, E2E-158, E2E-159, E2E-160, E2E-161, E2E-162, E2E-163, E2E-166, E2E-168, E2E-173, E2E-174, E2E-176, E2E-179, E2E-196a, E2E-196b, E2E-196c, E2E-198, E2E-199, E2E-200, E2E-202, E2E-203, E2E-205, E2E-209, E2E-210, E2E-212, E2E-213, E2E-214, E2E-215, E2E-216, E2E-217, E2E-218, E2E-219, E2E-257, E2E-SUBAGENT-settlement-updates-before-parent-poll, E2E-CHAT-quote-prefill, E2E-CHAT-side-chat-fork, E2E-CHAT-side-chat-stream, E2E-CHAT-side-chat-add-to-main, E2E-CHAT-side-chat-promote, E2E-CHAT-side-chat-close, E2E-CHAT-selection-markdown, E2E-CHAT-selection-side-chat, E2E-CHAT-annotation-attachments, E2E-CHAT-annotation-session-state, E2E-CHAT-annotation-source-index, E2E-CHAT-annotation-ack-and-steering |
+| M6+ | E2E-121, E2E-122, E2E-148, E2E-150, E2E-151, E2E-154, E2E-155, E2E-158, E2E-159, E2E-160, E2E-161, E2E-162, E2E-163, E2E-166, E2E-168, E2E-173, E2E-174, E2E-176, E2E-179, E2E-196a, E2E-196b, E2E-196c, E2E-198, E2E-199, E2E-200, E2E-202, E2E-203, E2E-205, E2E-209, E2E-210, E2E-212, E2E-213, E2E-214, E2E-215, E2E-216, E2E-217, E2E-218, E2E-219, E2E-257, E2E-SUBAGENT-settlement-updates-before-parent-poll, E2E-CHAT-quote-prefill, E2E-CHAT-side-chat-fork, E2E-CHAT-side-chat-stream, E2E-CHAT-side-chat-add-to-main, E2E-CHAT-side-chat-promote, E2E-CHAT-side-chat-close, E2E-CHAT-selection-markdown, E2E-CHAT-selection-side-chat, E2E-CHAT-annotation-attachments, E2E-CHAT-annotation-session-state, E2E-CHAT-annotation-source-index, E2E-CHAT-annotation-ack-and-steering, E2E-PLUGIN-fs-root-follows-the-calling-session |
| M6+ (Session Orchestrator) | E2E-PLUGIN-session-orchestrator-real-workers |
| M6+ (Session list responsiveness) | E2E-SESSION-list-refresh-keeps-desktop-responsive |
| M6+ (Independent session communication) | E2E-SESSION-independent-top-level-communication, E2E-SESSION-hover-card-model-and-links |
@@ -12674,3 +12674,45 @@ recovery; `side-chat-draft.test.mjs` covers action-level guards and child drift.
intrinsic size. `disclosure-anchor.test.mjs` covers the pure anchor and input
math, and `transcript-disclosure-reading.test.mjs` covers the wiring. Keyboard,
wheel and animated-activity-group paths remain additional validation.
+#### E2E-PLUGIN-fs-root-follows-the-calling-session: A plugin tool's fs root follows its own session, not the visible workspace
+
+- **Preconditions**: Two projects, A and B, each holding a text file the other
+ does not, and one enabled plugin that registers an agent tool whose execute
+ calls `pi.fs.readText` and `pi.fs.glob` on a root-relative path and declares
+ `fs.read` with the `workspace` root. Both projects have a live session with the
+ plugin tool available, and the window shows project A.
+- **Steps**:
+ 1. Invoke the tool from session A on the file only project A holds, then from
+ session B (project B) on the file only project B holds, without switching
+ the window's visible workspace.
+ 2. Switch the visible workspace to project B and repeat both calls.
+ 3. With the visible workspace on project B, ask session A's tool for a path
+ that exists only under project A, and session B's tool for the same path.
+ 4. Open the plugin's panel and call the same read over the panel bridge with
+ project A visible, then with project B visible.
+ 5. Move one session to a temporary chat so no workspace is visible, invoke the
+ tool from that session, then call the panel bridge in the same state.
+- **Expected**: Steps 1 and 2 answer from the invoking session's own project every
+ time: session A reads and globs project A's file, session B project B's file,
+ and neither answer changes when the visible workspace moves between the two
+ projects. Step 3 returns project A's file for session A and `NOT_FOUND` for
+ session B, so a session can never reach the other project's root. Step 4 is
+ unchanged from before: each panel call resolves the visible workspace, so its
+ answer follows the project on screen rather than either session. Step 5 keeps
+ working per session -- the session's plugin tool resolves its own project -- and
+ the panel call still fails with `NOT_FOUND` ("No workspace is open"). No gate
+ is relaxed anywhere: a denied name, a `..` or absolute path, a symlink out of
+ the root, and a path outside the declared scope behave as they do for a single
+ visible workspace.
+- **Specs linked**: `07-plugins/03-plugin-api.md` §3,
+ `07-plugins/13-plugin-permissions-matrix.md` §6, ADR 0016, ADR 0249, ADR 0266,
+ D093
+- **Acceptance**: G (plugins), Security, Quality
+- **Milestone**: M6+
+- **Status**: Partially automated
+ (`apps/desktop/test/plugin-fs-session-root.test.mjs`): a tool call writes and
+ reads under the project of the invoking session, a panel call and an untracked
+ session fall back to the visible workspace, a `userSelected` mode keeps the
+ picked directory, and a session root stands in when the window shows no
+ project. The two-live-sessions desktop journey and the panel step are Draft
+ (run only in a capable environment when this surface changes)
diff --git a/docs/spec/07-plugins/03-plugin-api.md b/docs/spec/07-plugins/03-plugin-api.md
index 4267a82bd..bef5fdbc6 100644
--- a/docs/spec/07-plugins/03-plugin-api.md
+++ b/docs/spec/07-plugins/03-plugin-api.md
@@ -246,6 +246,9 @@ picked through `requestDirectory()` when the mode declares
anything outside it prompts the user, and the credential deny-list overrides both
(see [04-plugin-security.md](04-plugin-security.md) §6). `remove` is
non-recursive and moves the path to the OS trash.
+Under the `workspace` root, paths are relative to the project of the tool session
+that invoked the call, falling back to the visible workspace for a panel call,
+which has no tool session (ADR 0266).
`list` returns one directory's entries, name-sorted, so a plugin can walk a tree
lazily instead of pulling a whole-repo `glob` and reassembling it. It applies the
diff --git a/docs/spec/07-plugins/13-plugin-permissions-matrix.md b/docs/spec/07-plugins/13-plugin-permissions-matrix.md
index fd7aa7f5b..bc03fef83 100644
--- a/docs/spec/07-plugins/13-plugin-permissions-matrix.md
+++ b/docs/spec/07-plugins/13-plugin-permissions-matrix.md
@@ -173,14 +173,16 @@ Every Host API entry point must assert first. A file entry point then passes
three more gates, in this order — a later gate can only refuse, never widen:
```ts
-assertFsAccess(pluginId, mode, requestedPath) {
+assertFsAccess(pluginId, mode, requestedPath, sessionId) {
assertPermission(pluginId, `fs.${mode}`) // declared AND granted
- full = realpathWithinRoot(root(pluginId, mode), requestedPath)
+ full = realpathWithinRoot(root(pluginId, mode, sessionId), requestedPath)
if (!full) throw NOT_FOUND | INVALID_ARGUMENT // symlinks resolved first
if (isDenied(full) || isHostReserved(full)) throw ERROR_PERMISSION_DENIED
if (!inScope(full, declaredScope(pluginId, mode))) await confirmWithUser(...)
}
```
+The `workspace` root is the invoking tool session's project, falling back to the
+visible workspace for a panel call (ADR 0266).
## 7. Acceptance
diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.md
index 0c3bbe860..fd5e1f644 100644
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@ -5417,3 +5417,29 @@ that was sitting at the bottom — including after the turn had finished.
and no new default. `project.deleteRunningBlocked` keeps its meaning, copy,
and every translation. See ADR 0251, D421, and
E2E-PROJECT-delete-running-sessions-are-named-and-stopped.
+## 2026-09-16 — Plugin `workspace` fs roots follow the calling session (D432)
+
+- Every plugin `pi.fs.*` call whose mode root is `workspace` resolved the one
+ window-global visible workspace, so a plugin agent tool invoked from session B
+ (project B) read project A's root as soon as the user switched tabs, and failed
+ `NOT_FOUND` for every session at once when no workspace was visible (D093 fixed
+ the same rule for built-in tool execution; it never reached a plugin).
+- `plugin-runtime.ts` now resolves that root with a new private `fsRoot(loaded, rule)`
+ helper: the project of the tool session that invoked the call, asked for through
+ the additive host service `getWorkspacePathForSession`. `plugin-services.ts` wires
+ it from the session-to-project map it already keeps, so no new source of truth is
+ introduced.
+- Unchanged: the visible workspace stays the root for a panel-bridge call, which has
+ no tool session, and for a session the host does not track; a `userSelected` mode
+ still keeps the directory the user picked through `requestDirectory()`.
+- A session root now resolves when no workspace is visible at all, so a temporary
+ chat keeps working per session instead of failing for every session at once. A
+ panel call in that state still fails closed. `NOT_FOUND` for a `workspace` root is
+ therefore narrower: neither the invoking session's project nor a visible workspace
+ resolved.
+- No permission, realpath-containment, deny-list, or declared-scope/consent gate
+ changes, and the plugin API surface does not change: `pi.workspace.get` still
+ answers with the visible workspace and its project group.
+- See ADR 0266, `07-plugins/03-plugin-api.md` §3,
+ `07-plugins/13-plugin-permissions-matrix.md` §6, and
+ E2E-PLUGIN-fs-root-follows-the-calling-session.
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 750a99ede..1e95a23ab 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
@@ -7393,3 +7393,18 @@ runner 会在运行时的隔离临时目录中生成六个插件形态 fixture
- **验收**:C(对话与流式)、品质
- **里程碑**:M5
- **状态**:由单测覆盖(`active-turn-surface.test.mjs`),并有通过 `pnpm test:e2e:transcript`(`scripts/e2e/transcript-render.tsx`,无需供应商凭据,需要已安装的 Electron 与图形会话,Linux 上可用 Xvfb)自动化的 React/Chromium 几何回归。当预留通道被移除时,该场景会以 40.125px 的内容高度误差与 40px 的行位移失败(issue #323)。
+
+#### E2E-PLUGIN-fs-root-follows-the-calling-session:插件工具的 fs 根跟随自己的会话,而不是可见工作区
+
+- **先决条件**:两个项目 A 与 B,各自持有一个对方没有的文本文件,以及一个已启用的插件;该插件注册的智能体工具会在 execute 里对根相对路径调用 `pi.fs.readText` 与 `pi.fs.glob`,并声明带 `workspace` 根的 `fs.read`。两个项目都有该插件工具可用的活会话,且窗口显示项目 A。
+- **步骤**:
+ 1. 从会话 A 调用该工具读取只属于项目 A 的文件,再从会话 B(项目 B)调用它读取只属于项目 B 的文件,期间不切换窗口的可见工作区。
+ 2. 把可见工作区切到项目 B,重复上面两次调用。
+ 3. 在可见工作区为项目 B 时,让会话 A 的工具请求只存在于项目 A 下的路径,再让会话 B 的工具请求同一路径。
+ 4. 打开该插件的面板,在项目 A 可见时通过面板桥做同样的读取,然后在项目 B 可见时再做一次。
+ 5. 把其中一个会话移到临时对话,使没有可见工作区,从该会话调用该工具,再在同一状态下调用面板桥。
+- **预期**:步骤 1 与 2 每次都以调用会话自己的项目作答:会话 A 读取并 glob 项目 A 的文件,会话 B 对应项目 B 的文件,可见工作区在这两个项目之间移动时答案都不变。步骤 3 对会话 A 返回项目 A 的文件,对会话 B 返回 `NOT_FOUND`,因此会话永远无法触达另一个项目的根。步骤 4 与之前完全一致:每次面板调用解析可见工作区,所以它的答案跟随屏幕上的项目,而不是任一会话。步骤 5 按会话继续工作 —— 会话的插件工具解析自己的项目 —— 而面板调用仍以 `NOT_FOUND`(「没有打开任何工作区」)失败。任何闸门都没有放宽:被拒的名称、`..` 或绝对路径、指向根外的符号链接,以及超出声明范围的路径,其行为与只有一个可见工作区时相同。
+- **链接规格**:`07-plugins/03-plugin-api.md` §3、`07-plugins/13-plugin-permissions-matrix.md` §6、ADR 0016、ADR 0249、ADR 0266、D093
+- **验收**:G(插件)、安全性、品质
+- **里程碑**:M6+
+- **状态**:部分自动化(`apps/desktop/test/plugin-fs-session-root.test.mjs`):工具调用在发起会话的项目下写入与读取,面板调用与宿主未跟踪的会话回退到可见工作区,`userSelected` 模式保留选定的目录,窗口不显示任何项目时会话根依然生效。双活会话的桌面旅程与面板步骤为草稿(仅在此表面变化时于具备条件的环境中运行)
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 412008868..92d34a9b6 100644
--- a/docs/zh-CN/spec/07-plugins/03-plugin-api.md
+++ b/docs/zh-CN/spec/07-plugins/03-plugin-api.md
@@ -197,6 +197,8 @@ pi.fs.requestDirectory(): Promise<{ path: string; name: string } | null>
而凭证 deny-list 压过两者(参见
[04-plugin-security.md](/zh-CN/spec/07-plugins/04-plugin-security) §6)。
`remove` 不递归,并且把路径移进系统回收站。
+在 `workspace` 根下,路径相对于调用该调用的工具会话所属的项目,面板调用没有工具会话时
+回退到可见工作区(ADR 0266)。
`list` 返回单个目录的条目(按名称排序),使插件可以惰性遍历目录树,
而不必拉取整个仓库的 `glob` 再自行重组。它施加与 `glob` 完全相同的守卫,
diff --git a/docs/zh-CN/spec/07-plugins/13-plugin-permissions-matrix.md b/docs/zh-CN/spec/07-plugins/13-plugin-permissions-matrix.md
index eb8164bc9..a51c6d49e 100644
--- a/docs/zh-CN/spec/07-plugins/13-plugin-permissions-matrix.md
+++ b/docs/zh-CN/spec/07-plugins/13-plugin-permissions-matrix.md
@@ -170,14 +170,15 @@ assertPermission(pluginId, perm) {
顺序固定 —— 后面的门只能拒绝,永远不能放宽:
```ts
-assertFsAccess(pluginId, mode, requestedPath) {
+assertFsAccess(pluginId, mode, requestedPath, sessionId) {
assertPermission(pluginId, `fs.${mode}`) // 已声明且已授予
- full = realpathWithinRoot(root(pluginId, mode), requestedPath)
+ full = realpathWithinRoot(root(pluginId, mode, sessionId), requestedPath)
if (!full) throw NOT_FOUND | INVALID_ARGUMENT // 先解析软链
if (isDenied(full) || isHostReserved(full)) throw ERROR_PERMISSION_DENIED
if (!inScope(full, declaredScope(pluginId, mode))) await confirmWithUser(...)
}
```
+`workspace` 根是调用该调用的工具会话所属的项目,面板调用没有工具会话,回退到可见工作区(ADR 0266)。
## 7. 验收
diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.md
index de54ab62a..59c52b903 100644
--- a/docs/zh-CN/spec/08-meta/decisions-log.md
+++ b/docs/zh-CN/spec/08-meta/decisions-log.md
@@ -4203,3 +4203,12 @@ the retained upstream work-panel lifecycle. See
- 对话框新增一行警告,点名有 `{{count}}` 个会话正在运行,并把确认按钮文案换成 `project.deleteRunningConfirm`(「停止任务并删除」)。确认会精确中止这些会话,然后才调用 `deleteProject`,所以删除一个正在运行的回合仍然是针对已陈述后果的第二次显式确认。取消不删除任何东西。
- 宿主侧的守卫未改动:只要仍有关联会话存在运行中的回合,`projects.remove` 依旧以 1008 / `CONFLICT` 拒绝,对话框也依旧把该拒绝映射为 `project.deleteRunningBlocked`。中止循环之后才开始的回合,正是这条兜底覆盖的情况。
- 仅渲染层:无协议、存储、宿主、权限或迁移改动,也没有新增默认值。`project.deleteRunningBlocked` 的含义、文案与全部翻译保持不变。见 ADR 0251、D421 与 E2E-PROJECT-delete-running-sessions-are-named-and-stopped。
+
+## 2026-09-16 —— 插件 `workspace` fs 根跟随发起调用的会话(D432)
+
+- 所有模式根为 `workspace` 的插件 `pi.fs.*` 调用都解析到窗口级唯一的可见工作区,因此从会话 B(项目 B)发起的插件智能体工具,在用户切换标签页后读到的是项目 A 的根;而在没有可见工作区时,所有会话会一起以 `NOT_FOUND` 失败(D093 已为内置工具执行定下同一条规则,却从未传到插件)。
+- `plugin-runtime.ts` 现在用新增的私有辅助函数 `fsRoot(loaded, rule)` 解析该根:由发起这次调用的工具会话所属项目决定,通过新增的宿主服务 `getWorkspacePathForSession` 询问。`plugin-services.ts` 用它本就维护的「会话到项目」映射完成接线,因此没有引入新的真相来源。
+- 未改动:面板桥调用没有工具会话,宿主不跟踪的会话也一样,它们的根仍是可见工作区;`userSelected` 模式依旧保留用户通过 `requestDirectory()` 选定的目录。
+- 现在没有可见工作区时会话根也能解析,所以临时对话按会话各自继续工作,而不是所有会话一起失败;这种状态下的面板调用仍然失败关闭。于是 `workspace` 根的 `NOT_FOUND` 更窄:既没有解析出调用会话的项目,也没有可见工作区。
+- 权限、realpath 包含、拒绝名单、声明范围与运行时同意这四类闸门都没有改动,插件 API 表面也未变化:`pi.workspace.get` 仍然以可见工作区及其项目组作答。
+- 见 ADR 0266、`07-plugins/03-plugin-api.md` §3、`07-plugins/13-plugin-permissions-matrix.md` §6 与 E2E-PLUGIN-fs-root-follows-the-calling-session。