Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
ADR 0262: Chat File References Complete in Main and Open in the File View
- Status: Accepted
- Date: 2026-09-14
- Related: ADR 0104 · ADR 0124 · ADR 0163 · ADR 0241 · 04-ux/09-interaction-patterns
Context
ADR 0163 made transcript file references clickable but trusted the token as
written, so an agent naming only openimage.js resolved at the workspace root and
painted an empty panel or a blank browser page, indistinguishable from a slow
load. The click also always chose the host file: tab, while the panel's capable
surface is the vendored pi.file-manager view (ADR 0241), which had no way to be
told which file to show.
Decision
- Completion runs in Electron main as
fs.resolveRef, because only main sees the open project and the session scratch store (<data_dir>/scratch/<sessionId>/, ADR 0124). An absolute reference naming a real file inside a known root wins outright; anattachments/<sha256>blob resolves against the attachment store; otherwise roots are searched in priority order — open project, session scratch, attachment store — with the project exhausted before the scratch store is considered. Inside one root an exact path beats a shorthand, which resolves only when its complete supplied suffix uniquely identifies one safe file: it never degrades, ambiguous matches resolve to nothing, the files-panel ignore set applies, and a reference that matches nothing opens nothing and reports itself. - The destination follows where the reference resolved. A project file opens
in
pi.file-manager, except a positioned reference (:line,:line:column,:line-range,#Lline[-Lend]), which opens in the host's read-onlyfile:tab so the requested source line can be shown — the bundled view has no line-navigation contract. Scratch and attachment files open in the hostfile:tab because they live outside that view's project root. An unpositioned.html/.htmfile in the session's project group or own scratch directory opens in the side browser (ADR 0163), with browser roots resolved from the owning session. A direct user click on a project file actively ensures the bundled view runs — enabling an off plugin or reloading one with no contributed view — without restoring a missingui.viewgrant or widening project scope; if either boundary excludes the project, or the plugin still cannot start, the hostfile:tab opens with a notice. - A contributed view's
locationstops being browser-only. It travels as the view entry URL'spiViewOpenquery parameter on creation and as theview:openpreload event after load. A location that arrives before the firstdid-finish-loadrestarts the load; a loaded view is never navigated, because a plugin may hold unsaved edits, and re-opening the same location does nothing. The payload is opaque to the host, and no permission or SDK method is added. - The view decides its own presentation.
pi.file-managerv0.4.0 opens the requested file, expands its ancestors, and collapses its left file list for a host request. An absolute path outside the project root is treated as an explicitly host-chosen file: raw Nodefswith the credential deny list applied to the raw, normalized andrealpathforms and no root containment, which itssafetyNotesstates. ADR 0339 drops root containment for the host as well:fs/resolveRef,fs/read,fs/reveal, andfs/openopen an exact absolute path outside managed roots. The host applies no deny list because it only shows the file to the user who clicked it, while the plugin keeps its own. - The bundled copy moves to v0.4.0 through ADR 0241's re-sync procedure and ships the same bytes as the plugin-center release.
Consequences
- A shorthand lands on the file the agent meant, or says that nothing matched, so the two failure modes ADR 0163 left indistinguishable are distinguishable.
- The transcript's file surface is the same editable view the launcher offers; the
host now depends on a plugin version for a chat affordance and degrades to the
host
file:tab with a notice when the plugin cannot start. - The view is unconfined to the project root only when the host asks for a path it picked itself, extending ADR 0241's trust position by one named case.
- A chat click no longer hands a file to the OS default application, which remains
in the file view's context menu.
fs.resolveRefis a new renderer-facing channel whilefs/open(ADR 0163) stays on the IPC surface.
Alternatives
- Resolve the shorthand in the renderer: rejected, it cannot see the scratch store and both roots must be ranked in one place.
- Add a
ui.openView(pluginId, viewId, payload)SDK method: rejected, the tab already carrieslocationand no new public API is needed. - Reload the view with the new location: rejected, it discards plugin state.
- Widen the plugin's declared
fsroot to the scratch store: rejected, it would grant every project access to every session's scratch data. - Route workspace HTML through the file view: rejected, it renders a page as source.
- Keep the OS default application as the destination: rejected, it is not the panel.