feat(plugins): move the file explorer/viewer and the context editor into live plugins #35

Closed
gabrielvidal wants to merge 0 commits from files-plugins into main
pull from: files-plugins
Owner

Summary

Moves the file explorer/viewer (/file/*, the Project page's Files card, what a message's file chip opens) and the owner's context tree + editor (/_/*, the Files drawer's tree) out of the core into two live plugins, file-explorer and context-editor (plugins PR: gabrielvidal/ai-agent-plugins#23). Pair 1 of the migration Gabriel approved (form migrate-files-context-dashboard-to-plugins_imhucu); the data moves behind scoped hub bridges, the old addresses redirect, and the core keeps no fallback UI.

Key changes

  • Bridges backend/plugins/hubfiles.py: hostfiles.read (hub/host-file, host-files, host-files/recent, new host-files/roots) answering as the caller; context.read (context/bundle, context/file) and context.write (PUT context/file, handler-only) owner-only. New hostfiles.roots().
  • Retired /api/bundle, GET|PUT /api/file, /api/host-file, /api/host-files, /api/host-files/recent (+ schemas, orval models, authz entries, golden matrix). /api/host-file/raw stays (joins MEDIA_PREFIXES for frames).
  • Platform hooks (generic, PluginSandboxFrame / PluginCustomPage): aiAgentPlugin.setRoute(r, {replace}) + onRoute(cb) — a page that routes itself keeps its frame across address changes; download(url, name); back(fallback); plugin pages pad above the phone's floating composer (--spawn-drawer-h).
  • Frontend: HostFilePage, Editor, ProjectFiles, FileTree, FileRows, hostFiles.ts, tree.ts deleted; file chips, the skill card's SKILL.md link and the dashboard rows go through usePluginOpener("host-file" | "context-file"); LegacyFileRedirect for /file/* and /_/* (none active: a note naming the plugin + link to the catalogue); Files drawer/landing = shortcuts only; Project page passes {slug, isRoot, isWorker, keyFiles} to project.detail.
  • Mock: mock/filesPlugins.ts (both plugins' pages, slot, actions over the mock tree and context files; ?mockFiles=0).
  • Tests: test_hostfiles.py route section rewritten over HTTP through the bridge; test_files_plugin_bridge.py; opener.test.ts (legacy targets); routeBridge.test.ts (cleanRoute).
  • Docs: CLAUDE.md (file chips + explorer section, new context editor section, perf/security notes), docs/plugins.md ("Files as plugins", capability rows), mock README.

Key decisions

  • Access never wider than before. Every confinement assertion the routes had is now asserted over HTTP on the bridge (other projects, ~/homelab / ~/worktrees for guests, .env, keys, node_modules, a symlink out of the root, a symlink to a secret inside it, lab runtime state). Two tightenings: hostfiles.read is operator-approved (a guest-installed plugin can't hold it; guests reach it through the owner's managed plugin), and a paired machine's proxy token is refused on all three bridges — the tool-proxy door treats an owner's worker as the owner, which would have let e.g. a devbox read ~/homelab; the retired routes never answered a machine (golden matrix: w.read/w.run ✗). A guest's run token reads as the guest, like the cli scope could on /api/host-file.
  • setRoute/onRoute instead of reloads: registering onRoute is the opt-in; without it a subpath/query change still rebuilds the frame (Services etc. unchanged). Needed so the editor keeps its tree and draft and the explorer doesn't flash on every folder.
  • Explorer page in Projects nav (nav: "projects", a Files row above the project list), the closest to how Services was placed; the decisions didn't name a nav.
  • Context editor counts under App usage id page.files (its old core id); the explorer under its own default id.
  • The core UpdateToast's "save your edits" hold is gone with the core editor; the plugin keeps drafts on the hub (written 800 ms after typing stops and on page hide), so a reload loses at most that.
  • Unsaved drafts in the old ui-state blob (edits) are not carried over (rarely any; noted rather than migrated).

Changelog

  • Changed: Files open in the File explorer plugin — a file path in a conversation, a project's Files card and old /file/… links all lead there.
  • Changed: The context files (CLAUDE.md, .claude/, data/) are edited in the Context editor plugin under Files; old /_/… links lead there.
  • Changed: Plugin pages leave room for the phone's floating composer.
  • Removed: The core file page, context editor and Files drawer tree (now plugins), and their /api/bundle, /api/file and /api/host-file* JSON routes.

Test notes

Run on the EVOX2 (no Docker): backend modules each in bwrap with a throwaway /data.

  • Backend: every test_*.py on this branch vs origin/main — 168/168 modules pass except test_typed_plugins.py::test_records_carry_kind, which is path-dependent (inspect_source maps /home/… host paths; it passes from a /tmp checkout of main, fails from a ~/worktrees / ~/projects checkout, as noted before on main). test_hostfiles 16, test_files_plugin_bridge 9, test_authz_matrix, test_guests 58 pass.
  • Frontend: tsc clean; vitest 1104/1105 — the one failure is FreshContext.test.tsx (CacheExpiredNotice), failing on main too; vite build and VITE_MOCK=1 build OK. openapi.json re-dumped + gen:api: no diff.
  • Live local hub (this branch, both plugins seeded from the plugins branch): all actions as owner and guest over HTTP (guest: own project 200; other project, ~/homelab, worktrees, raw route outside the grant → 404; context editor not active). Browser e2e: explorer navigation without frame reload + Back, relative markdown links; editor draft survives reload, ⌘S writes, draft dropped. Screenshots: desktop + phone, explorer, viewer kinds, project Files card, editor (clean/dirty/preview), Files drawer, guest views, redirects.
  • Not verified: a file chip inside a real conversation thread (covered by FileChip.test.tsx / opener tests; the mock's kitchen-sink thread didn't render the message in headless capture).
  • Never deployed from the EVOX2. From the Homelab, in order: merge both PRs; git -C ~/projects/ai-agent-plugins pull; ~/homelab/services/ai-agent/deploy.sh --detach && … --watch — startup seeds file-explorer and context-editor; if either was installed before: ai-agent plugin reload file-explorer --approve, ai-agent plugin reload context-editor --approve. Pair 2 (context-skills dashboard) rebases on this branch and links via context-file {path} and host-file.

Screenshots

02-explorer-project-folder.png
03-viewer-markdown.png
05-viewer-csv.png
06-viewer-image.png
07-project-page-files-card.png
08-context-editor.png
09-context-editor-dirty.png
10-context-editor-preview.png
23-phone-files-drawer.png
20-phone-explorer-file.png
22-phone-editor-file.png
31-guest-folder.png
32-guest-other-project-404.png
12-legacy-file-redirect.png

## Summary Moves the file explorer/viewer (`/file/*`, the Project page's Files card, what a message's file chip opens) and the owner's context tree + editor (`/_/*`, the Files drawer's tree) out of the core into two live plugins, `file-explorer` and `context-editor` (plugins PR: https://git.gabvdl.xyz/gabrielvidal/ai-agent-plugins/pulls/23). Pair 1 of the migration Gabriel approved (form `migrate-files-context-dashboard-to-plugins_imhucu`); the data moves behind scoped hub bridges, the old addresses redirect, and the core keeps no fallback UI. ## Key changes - **Bridges** `backend/plugins/hubfiles.py`: `hostfiles.read` (`hub/host-file`, `host-files`, `host-files/recent`, new `host-files/roots`) answering **as the caller**; `context.read` (`context/bundle`, `context/file`) and `context.write` (`PUT context/file`, handler-only) owner-only. New `hostfiles.roots()`. - **Retired** `/api/bundle`, `GET|PUT /api/file`, `/api/host-file`, `/api/host-files`, `/api/host-files/recent` (+ schemas, orval models, authz entries, golden matrix). `/api/host-file/raw` stays (joins `MEDIA_PREFIXES` for frames). - **Platform hooks** (generic, `PluginSandboxFrame` / `PluginCustomPage`): `aiAgentPlugin.setRoute(r, {replace})` + `onRoute(cb)` — a page that routes itself keeps its frame across address changes; `download(url, name)`; `back(fallback)`; plugin pages pad above the phone's floating composer (`--spawn-drawer-h`). - **Frontend**: `HostFilePage`, `Editor`, `ProjectFiles`, `FileTree`, `FileRows`, `hostFiles.ts`, `tree.ts` deleted; file chips, the skill card's SKILL.md link and the dashboard rows go through `usePluginOpener("host-file" | "context-file")`; `LegacyFileRedirect` for `/file/*` and `/_/*` (none active: a note naming the plugin + link to the catalogue); Files drawer/landing = shortcuts only; Project page passes `{slug, isRoot, isWorker, keyFiles}` to `project.detail`. - **Mock**: `mock/filesPlugins.ts` (both plugins' pages, slot, actions over the mock tree and context files; `?mockFiles=0`). - **Tests**: `test_hostfiles.py` route section rewritten over HTTP through the bridge; `test_files_plugin_bridge.py`; `opener.test.ts` (legacy targets); `routeBridge.test.ts` (`cleanRoute`). - **Docs**: `CLAUDE.md` (file chips + explorer section, new context editor section, perf/security notes), `docs/plugins.md` ("Files as plugins", capability rows), mock README. ## Key decisions - **Access never wider than before.** Every confinement assertion the routes had is now asserted over HTTP on the bridge (other projects, `~/homelab` / `~/worktrees` for guests, `.env`, keys, `node_modules`, a symlink out of the root, a symlink to a secret inside it, lab runtime state). Two tightenings: `hostfiles.read` is **operator-approved** (a guest-installed plugin can't hold it; guests reach it through the owner's managed plugin), and **a paired machine's proxy token is refused** on all three bridges — the tool-proxy door treats an owner's worker as the owner, which would have let e.g. a devbox read `~/homelab`; the retired routes never answered a machine (golden matrix: `w.read`/`w.run` ✗). A guest's run token reads as the guest, like the `cli` scope could on `/api/host-file`. - **`setRoute`/`onRoute` instead of reloads**: registering `onRoute` is the opt-in; without it a subpath/query change still rebuilds the frame (Services etc. unchanged). Needed so the editor keeps its tree and draft and the explorer doesn't flash on every folder. - Explorer page in **Projects** nav (`nav: "projects"`, a *Files* row above the project list), the closest to how Services was placed; the decisions didn't name a nav. - Context editor counts under App usage id `page.files` (its old core id); the explorer under its own default id. - The core `UpdateToast`'s "save your edits" hold is gone with the core editor; the plugin keeps drafts on the hub (written 800 ms after typing stops and on page hide), so a reload loses at most that. - Unsaved drafts in the old ui-state blob (`edits`) are not carried over (rarely any; noted rather than migrated). ## Changelog - Changed: Files open in the File explorer plugin — a file path in a conversation, a project's Files card and old /file/… links all lead there. - Changed: The context files (CLAUDE.md, .claude/, data/) are edited in the Context editor plugin under Files; old /_/… links lead there. - Changed: Plugin pages leave room for the phone's floating composer. - Removed: The core file page, context editor and Files drawer tree (now plugins), and their /api/bundle, /api/file and /api/host-file* JSON routes. ## Test notes Run on the EVOX2 (no Docker): backend modules each in bwrap with a throwaway `/data`. - Backend: every `test_*.py` on this branch vs `origin/main` — 168/168 modules pass except `test_typed_plugins.py::test_records_carry_kind`, which is path-dependent (`inspect_source` maps `/home/…` host paths; it passes from a `/tmp` checkout of main, fails from a `~/worktrees` / `~/projects` checkout, as noted before on main). `test_hostfiles` 16, `test_files_plugin_bridge` 9, `test_authz_matrix`, `test_guests` 58 pass. - Frontend: `tsc` clean; vitest 1104/1105 — the one failure is `FreshContext.test.tsx` (CacheExpiredNotice), failing on main too; `vite build` and `VITE_MOCK=1` build OK. `openapi.json` re-dumped + `gen:api`: no diff. - Live local hub (this branch, both plugins seeded from the plugins branch): all actions as owner and guest over HTTP (guest: own project 200; other project, `~/homelab`, worktrees, raw route outside the grant → 404; context editor not active). Browser e2e: explorer navigation without frame reload + Back, relative markdown links; editor draft survives reload, ⌘S writes, draft dropped. Screenshots: desktop + phone, explorer, viewer kinds, project Files card, editor (clean/dirty/preview), Files drawer, guest views, redirects. - **Not verified**: a file chip inside a real conversation thread (covered by `FileChip.test.tsx` / opener tests; the mock's kitchen-sink thread didn't render the message in headless capture). - **Never deployed from the EVOX2.** From the Homelab, in order: merge both PRs; `git -C ~/projects/ai-agent-plugins pull`; `~/homelab/services/ai-agent/deploy.sh --detach && … --watch` — startup seeds `file-explorer` and `context-editor`; if either was installed before: `ai-agent plugin reload file-explorer --approve`, `ai-agent plugin reload context-editor --approve`. Pair 2 (context-skills dashboard) rebases on this branch and links via `context-file` `{path}` and `host-file`. ## Screenshots ![02-explorer-project-folder.png](https://git.gabvdl.xyz/attachments/1317e429-c33d-43c5-b8f3-0fd2f3b1c297) ![03-viewer-markdown.png](https://git.gabvdl.xyz/attachments/63cda278-159d-4729-b417-f4b4ecf17ca5) ![05-viewer-csv.png](https://git.gabvdl.xyz/attachments/b3e6164d-4185-48f7-a8f7-0d7bafb51ca1) ![06-viewer-image.png](https://git.gabvdl.xyz/attachments/3be7cebb-5378-4bc8-b078-93c27de790a5) ![07-project-page-files-card.png](https://git.gabvdl.xyz/attachments/300eaa2d-3c88-4760-ae56-fe82910736df) ![08-context-editor.png](https://git.gabvdl.xyz/attachments/2b7de250-f2de-484c-9d6e-d930d4ff34e4) ![09-context-editor-dirty.png](https://git.gabvdl.xyz/attachments/6149b73c-467b-42fd-bd1e-c66321be6958) ![10-context-editor-preview.png](https://git.gabvdl.xyz/attachments/a011a4e0-1722-4c61-beeb-b6afc3c0666e) ![23-phone-files-drawer.png](https://git.gabvdl.xyz/attachments/4fa65795-d608-470f-a487-aaf7cc463a5c) ![20-phone-explorer-file.png](https://git.gabvdl.xyz/attachments/01dadc58-392d-4186-9401-f24c4ed034ed) ![22-phone-editor-file.png](https://git.gabvdl.xyz/attachments/a7d9e106-6784-4a10-bf38-f215b4faeb88) ![31-guest-folder.png](https://git.gabvdl.xyz/attachments/2149a04a-3a03-472e-a77c-6673f5301bf0) ![32-guest-other-project-404.png](https://git.gabvdl.xyz/attachments/1c705493-220a-4b3a-9dd2-8044a0f9353f) ![12-legacy-file-redirect.png](https://git.gabvdl.xyz/attachments/5852a2df-ce90-4b83-9db9-9dc455d451f4)
gabrielvidal self-assigned this 2026-11-28 13:45:35 +01:00
gabrielvidal added 1 commit 2026-11-28 13:45:35 +01:00
The host file browser + viewer (/file/*, HostFilePage, the project Files
card) and the context tree + editor (/_/*, Editor, the FilesPanel tree) are
the file-explorer and context-editor plugins' now.

- bridges (plugins/hubfiles.py): hostfiles.read (as the caller; operator-
  approved; machine tokens refused), context.read / context.write (owner)
- /api/bundle, /api/file, /api/host-file, /api/host-files[/recent] retired;
  /api/host-file/raw stays for media and downloads
- pages that route themselves: aiAgentPlugin.setRoute / onRoute; download,
  back; plugin pages pad above the phone composer
- /file/* and /_/* redirect through opens (host-file, context-file)
- mock: filesPlugins.ts; docs and CLAUDE.md updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner
Merged into `main` as e5a5dcde by the auto-ship batch https://ai-agent.lab.gabvdl.xyz/conversation/91782f5a-872e-4531-8bde-f4031df38c26.
gabrielvidal closed this pull request 2026-11-28 14:13:21 +01:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gabrielvidal/ai-agent#35