@jmfederico/pi-web 1.202608.0 → 1.202608.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/README.md +4 -4
  2. package/dist/cli.js +69 -7
  3. package/dist/cli.js.map +1 -1
  4. package/dist/client/assets/{CodeViewer-D91Sp61M.js → CodeViewer-mEiBZFA5.js} +2 -2
  5. package/dist/client/assets/{TerminalPanel-fYrKc3jh.js → TerminalPanel-O9381Eme.js} +6 -6
  6. package/dist/client/assets/index-uI2AGFUy.js +4091 -0
  7. package/dist/client/index.html +1 -1
  8. package/dist/config.js +109 -73
  9. package/dist/config.js.map +1 -1
  10. package/dist/docker/piWebDockerCommandPlan.js +4 -3
  11. package/dist/docker/piWebDockerCommandPlan.js.map +1 -1
  12. package/dist/nativeServices/servicePlan.js +1 -1
  13. package/dist/nativeServices/servicePlan.js.map +1 -1
  14. package/dist/pi-web-plugins/git/browser/git-contract.js +108 -0
  15. package/dist/pi-web-plugins/git/browser/git-panel.js +609 -0
  16. package/dist/pi-web-plugins/git/browser/gitFileList.js +43 -0
  17. package/dist/pi-web-plugins/git/browser/gitFileShared.js +16 -0
  18. package/dist/pi-web-plugins/git/browser/gitFileTree.js +81 -0
  19. package/dist/pi-web-plugins/git/browser/gitFileViewPreference.js +35 -0
  20. package/dist/pi-web-plugins/git/browser/gitRoute.js +42 -0
  21. package/dist/pi-web-plugins/git/browser/pi-web-plugin.js +10 -0
  22. package/dist/pi-web-plugins/git/browser/unifiedDiff.js +301 -0
  23. package/dist/{server/git/gitService.js → pi-web-plugins/git/git-backend.js} +209 -60
  24. package/dist/pi-web-plugins/git/package.json +16 -0
  25. package/dist/pi-web-plugins/git/server-plugin.js +176 -0
  26. package/dist/pi-web-plugins/info/infoInternals.js +1 -2
  27. package/dist/pi-web-plugins/info/package.json +1 -1
  28. package/dist/pi-web-plugins/info/pi-web-plugin.js +2 -2
  29. package/dist/pi-web-plugins/relays/package.json +1 -1
  30. package/dist/pi-web-plugins/relays/pi-web-plugin.js +3 -3
  31. package/dist/pi-web-plugins/updates/package.json +1 -1
  32. package/dist/pi-web-plugins/updates/pi-web-plugin.js +1 -1
  33. package/dist/pi-web-plugins/workspace-tasks/package.json +1 -1
  34. package/dist/pi-web-plugins/workspace-tasks/pi-web-plugin.js +3 -3
  35. package/dist/plugin-api.d.ts +33 -16
  36. package/dist/pluginRecoveryCli.js +172 -0
  37. package/dist/pluginRecoveryCli.js.map +1 -0
  38. package/dist/server/activity/workspaceActivityService.js +27 -19
  39. package/dist/server/activity/workspaceActivityService.js.map +1 -1
  40. package/dist/server/app.js +35 -15
  41. package/dist/server/app.js.map +1 -1
  42. package/dist/server/configRoutes.js +3 -21
  43. package/dist/server/configRoutes.js.map +1 -1
  44. package/dist/server/machines/machineClient.js +23 -4
  45. package/dist/server/machines/machineClient.js.map +1 -1
  46. package/dist/server/machines/machinePluginProxyRoutes.js +74 -17
  47. package/dist/server/machines/machinePluginProxyRoutes.js.map +1 -1
  48. package/dist/server/machines/machineProxyRoutes.js +165 -8
  49. package/dist/server/machines/machineProxyRoutes.js.map +1 -1
  50. package/dist/server/machines/machineService.js +22 -0
  51. package/dist/server/machines/machineService.js.map +1 -1
  52. package/dist/server/piWebPluginCatalog.js +584 -0
  53. package/dist/server/piWebPluginCatalog.js.map +1 -0
  54. package/dist/server/piWebPluginLifecycle.js +162 -0
  55. package/dist/server/piWebPluginLifecycle.js.map +1 -0
  56. package/dist/server/piWebPluginService.js +159 -261
  57. package/dist/server/piWebPluginService.js.map +1 -1
  58. package/dist/server/piWebStatus.js +28 -7
  59. package/dist/server/piWebStatus.js.map +1 -1
  60. package/dist/server/plugins/pluginBackendProxyRoutes.js +69 -0
  61. package/dist/server/plugins/pluginBackendProxyRoutes.js.map +1 -0
  62. package/dist/server/plugins/serverPluginExec.js +184 -0
  63. package/dist/server/plugins/serverPluginExec.js.map +1 -0
  64. package/dist/server/plugins/serverPluginRuntime.js +480 -0
  65. package/dist/server/plugins/serverPluginRuntime.js.map +1 -0
  66. package/dist/server/realtime/sessionEventHub.js +26 -11
  67. package/dist/server/realtime/sessionEventHub.js.map +1 -1
  68. package/dist/server/requestCancellation.js +32 -0
  69. package/dist/server/requestCancellation.js.map +1 -0
  70. package/dist/server/sessiond/agentProcessEnvironment.js +29 -30
  71. package/dist/server/sessiond/agentProcessEnvironment.js.map +1 -1
  72. package/dist/server/sessiond/pluginBackendRoutes.js +64 -0
  73. package/dist/server/sessiond/pluginBackendRoutes.js.map +1 -0
  74. package/dist/server/sessiond/sessionDaemonShutdown.js +24 -0
  75. package/dist/server/sessiond/sessionDaemonShutdown.js.map +1 -0
  76. package/dist/server/sessiond/sessionProxyRoutes.js +2 -2
  77. package/dist/server/sessiond/sessionProxyRoutes.js.map +1 -1
  78. package/dist/server/sessiond/sessionServiceDependencies.js +2 -1
  79. package/dist/server/sessiond/sessionServiceDependencies.js.map +1 -1
  80. package/dist/server/sessiond/sessiondStateOwnership.js +235 -0
  81. package/dist/server/sessiond/sessiondStateOwnership.js.map +1 -0
  82. package/dist/server/sessiond/workspaceCatalogRoutes.js +31 -0
  83. package/dist/server/sessiond/workspaceCatalogRoutes.js.map +1 -0
  84. package/dist/server/sessiond/workspaceRemovalRoutes.js +41 -0
  85. package/dist/server/sessiond/workspaceRemovalRoutes.js.map +1 -0
  86. package/dist/server/sessiond.js +265 -99
  87. package/dist/server/sessiond.js.map +1 -1
  88. package/dist/server/sessions/authService.js +15 -54
  89. package/dist/server/sessions/authService.js.map +1 -1
  90. package/dist/server/sessions/dockerEnvironmentFacts.js +254 -0
  91. package/dist/server/sessions/dockerEnvironmentFacts.js.map +1 -0
  92. package/dist/server/sessions/modelCatalogRefresher.js +4 -3
  93. package/dist/server/sessions/modelCatalogRefresher.js.map +1 -1
  94. package/dist/server/sessions/piSessionManagerGateway.js +18 -67
  95. package/dist/server/sessions/piSessionManagerGateway.js.map +1 -1
  96. package/dist/server/sessions/piSessionService.js +141 -134
  97. package/dist/server/sessions/piSessionService.js.map +1 -1
  98. package/dist/server/sessions/sessionCommandService.js +24 -1
  99. package/dist/server/sessions/sessionCommandService.js.map +1 -1
  100. package/dist/server/sessions/sessionEnvironmentFacts.js +48 -0
  101. package/dist/server/sessions/sessionEnvironmentFacts.js.map +1 -0
  102. package/dist/server/sessions/sessionFileFormat.js +27 -0
  103. package/dist/server/sessions/sessionFileFormat.js.map +1 -0
  104. package/dist/server/sessions/sessionFileHeader.js +1 -14
  105. package/dist/server/sessions/sessionFileHeader.js.map +1 -1
  106. package/dist/server/sessions/sessionRoutes.js +14 -0
  107. package/dist/server/sessions/sessionRoutes.js.map +1 -1
  108. package/dist/server/sessions/sessionSummaryScanner.js +96 -224
  109. package/dist/server/sessions/sessionSummaryScanner.js.map +1 -1
  110. package/dist/server/sessions/spawnSubsessionTool.js +5 -9
  111. package/dist/server/sessions/spawnSubsessionTool.js.map +1 -1
  112. package/dist/server/sessions/spawnTargetResolver.js +1 -1
  113. package/dist/server/status/machineStatusRoutes.js +8 -0
  114. package/dist/server/status/machineStatusRoutes.js.map +1 -0
  115. package/dist/server/status/machineStatusService.js +181 -0
  116. package/dist/server/status/machineStatusService.js.map +1 -0
  117. package/dist/server/status/workspaceAttribution.js +87 -0
  118. package/dist/server/status/workspaceAttribution.js.map +1 -0
  119. package/dist/server/terminalProxyRoutes.js +2 -1
  120. package/dist/server/terminalProxyRoutes.js.map +1 -1
  121. package/dist/server/workspaceExplorerRoutes.js +20 -13
  122. package/dist/server/workspaceExplorerRoutes.js.map +1 -1
  123. package/dist/server/workspaces/fileContentService.js +18 -9
  124. package/dist/server/workspaces/fileContentService.js.map +1 -1
  125. package/dist/server/workspaces/filePreviewResponseHeaders.js +18 -0
  126. package/dist/server/workspaces/filePreviewResponseHeaders.js.map +1 -0
  127. package/dist/server/workspaces/filePreviewResponsePolicy.js +55 -0
  128. package/dist/server/workspaces/filePreviewResponsePolicy.js.map +1 -0
  129. package/dist/server/workspaces/filePreviewService.js +81 -0
  130. package/dist/server/workspaces/filePreviewService.js.map +1 -0
  131. package/dist/server/workspaces/projectWorkspaceCwds.js +0 -5
  132. package/dist/server/workspaces/projectWorkspaceCwds.js.map +1 -1
  133. package/dist/server/workspaces/sessionDaemonWorkspaceCatalog.js +402 -0
  134. package/dist/server/workspaces/sessionDaemonWorkspaceCatalog.js.map +1 -0
  135. package/dist/server/workspaces/workspaceCatalog.js +47 -0
  136. package/dist/server/workspaces/workspaceCatalog.js.map +1 -0
  137. package/dist/server/workspaces/workspaceContext.js +1 -3
  138. package/dist/server/workspaces/workspaceContext.js.map +1 -1
  139. package/dist/server/workspaces/workspaceDeletionRoutes.js +35 -125
  140. package/dist/server/workspaces/workspaceDeletionRoutes.js.map +1 -1
  141. package/dist/server/workspaces/workspaceProviderRegistry.js +651 -0
  142. package/dist/server/workspaces/workspaceProviderRegistry.js.map +1 -0
  143. package/dist/server/workspaces/workspaceRemovalService.js +256 -0
  144. package/dist/server/workspaces/workspaceRemovalService.js.map +1 -0
  145. package/dist/server/workspaces/workspaceRouteErrors.js +7 -0
  146. package/dist/server/workspaces/workspaceRouteErrors.js.map +1 -0
  147. package/dist/server/workspaces/worktreePreRemoveHook.js +39 -0
  148. package/dist/server/workspaces/worktreePreRemoveHook.js.map +1 -0
  149. package/dist/server-plugin-api.d.ts +140 -0
  150. package/dist/server-plugin-api.js +2 -0
  151. package/dist/server-plugin-api.js.map +1 -0
  152. package/dist/serverPluginRecovery.js +138 -0
  153. package/dist/serverPluginRecovery.js.map +1 -0
  154. package/dist/sessiond/activeAgentProfile.js +3 -22
  155. package/dist/sessiond/activeAgentProfile.js.map +1 -1
  156. package/dist/sessiond/config.js +11 -0
  157. package/dist/sessiond/config.js.map +1 -1
  158. package/dist/sessiond/sessionDaemonClient.js +11 -9
  159. package/dist/sessiond/sessionDaemonClient.js.map +1 -1
  160. package/dist/shared/activeAgentProfile.js +2 -41
  161. package/dist/shared/activeAgentProfile.js.map +1 -1
  162. package/dist/shared/activity.js +0 -3
  163. package/dist/shared/activity.js.map +1 -1
  164. package/dist/shared/apiTypes.js +7 -5
  165. package/dist/shared/apiTypes.js.map +1 -1
  166. package/dist/shared/capabilities.js +8 -6
  167. package/dist/shared/capabilities.js.map +1 -1
  168. package/dist/shared/federatedRoutes.js +28 -5
  169. package/dist/shared/federatedRoutes.js.map +1 -1
  170. package/dist/shared/machinePluginIds.js +4 -2
  171. package/dist/shared/machinePluginIds.js.map +1 -1
  172. package/dist/shared/machineStatus.js +94 -0
  173. package/dist/shared/machineStatus.js.map +1 -0
  174. package/dist/shared/piWebStatusParsing.js +29 -0
  175. package/dist/shared/piWebStatusParsing.js.map +1 -1
  176. package/dist/shared/pluginApiTypes.d.ts +148 -0
  177. package/dist/shared/pluginApiTypes.js +3 -0
  178. package/dist/shared/pluginApiTypes.js.map +1 -0
  179. package/dist/shared/pluginBackendProtocol.js +110 -0
  180. package/dist/shared/pluginBackendProtocol.js.map +1 -0
  181. package/dist/shared/pluginIds.js +5 -0
  182. package/dist/shared/pluginIds.js.map +1 -1
  183. package/dist/shared/pluginRecoveryCommands.js +14 -0
  184. package/dist/shared/pluginRecoveryCommands.js.map +1 -0
  185. package/dist/shared/workspaceFiles.js +41 -2
  186. package/dist/shared/workspaceFiles.js.map +1 -1
  187. package/dist/shared/workspaceRemovalProtocol.js +24 -0
  188. package/dist/shared/workspaceRemovalProtocol.js.map +1 -0
  189. package/docs/config.md +89 -51
  190. package/docs/plugins.md +383 -136
  191. package/examples/workspace-provider-plugin/README.md +52 -0
  192. package/examples/workspace-provider-plugin/package.json +25 -0
  193. package/examples/workspace-provider-plugin/src/browser/index.ts +69 -0
  194. package/examples/workspace-provider-plugin/src/server.ts +64 -0
  195. package/examples/workspace-provider-plugin/tsconfig.json +21 -0
  196. package/package.json +29 -10
  197. package/server-plugin-api.d.ts +1 -0
  198. package/dist/client/assets/UnifiedDiffViewer-BafLWGtF.js +0 -39
  199. package/dist/client/assets/index-CA8q9_o7.js +0 -4025
  200. package/dist/plugin-api/unstable.d.ts +0 -22
  201. package/dist/server/activity/workspaceActivityRoutes.js +0 -4
  202. package/dist/server/activity/workspaceActivityRoutes.js.map +0 -1
  203. package/dist/server/git/gitService.js.map +0 -1
  204. package/dist/server/gitRoutes.js +0 -23
  205. package/dist/server/gitRoutes.js.map +0 -1
  206. package/dist/server/sessions/parentSessionLocator.js +0 -75
  207. package/dist/server/sessions/parentSessionLocator.js.map +0 -1
  208. package/dist/server/workspaces/gitWorktreeDiscovery.js +0 -43
  209. package/dist/server/workspaces/gitWorktreeDiscovery.js.map +0 -1
  210. package/dist/server/workspaces/imagePreviewService.js +0 -40
  211. package/dist/server/workspaces/imagePreviewService.js.map +0 -1
  212. package/dist/server/workspaces/workspaceService.js +0 -52
  213. package/dist/server/workspaces/workspaceService.js.map +0 -1
  214. package/dist/shared/apiTypes.d.ts +0 -1217
  215. package/dist/shared/thinkingLevels.d.ts +0 -27
  216. package/plugin-api/unstable.d.ts +0 -1
package/docs/plugins.md CHANGED
@@ -1,33 +1,34 @@
1
1
  # PI WEB plugin API
2
2
 
3
- PI WEB plugins are trusted browser-side ES modules that extend the PI WEB UI. They are intended for personal, team, and project-local customization, and simple enough for an LLM to create or modify directly.
3
+ PI WEB plugins are trusted packages that can extend the browser UI, provide workspace semantics in the session daemon, or pair both entries. They are intended for personal, team, and project-local customization, and simple enough for an LLM to create or modify directly.
4
4
 
5
5
  Plugins can currently:
6
6
 
7
7
  - add action-palette commands;
8
- - add workspace tools/panels next to Files, Git, and Terminal;
8
+ - add workspace tools/panels next to Files and Terminal;
9
9
  - add compact workspace-label items in the workspace list, panel header, and status bar;
10
10
  - call browser APIs and documented PI WEB plugin context helpers;
11
11
  - read workspace files and start workspace terminal commands through documented helpers;
12
- - serve their own static assets from the plugin directory.
12
+ - serve browser-public files from an explicitly declared `browserRoot`;
13
+ - contribute one server-side workspace provider, with optional JSON backend requests and workspace-removal planning.
13
14
 
14
- They do **not** run in the session daemon, do not get a server-side hook API, and are not sandboxed.
15
+ Browser entries run in the PI WEB page through browser plugin API v2. Declared server entries run in the session daemon through the separate server-plugin API v1. Plugins do not get raw Fastify access, arbitrary routes, concrete core services, a generic event bus, Pi model-provider registration, or a general server-hook API. Neither entry is sandboxed.
15
16
 
16
17
  ## Pi packages, Pi extensions, and PI WEB plugins
17
18
 
18
- **Pi packages** are distribution bundles managed by Pi (`pi install`, `pi remove`, `pi update`). A Pi package can provide Pi extensions, skills, prompt templates, themes, context/system prompt files, and/or PI WEB browser plugins. Many Pi packages do not include a PI WEB plugin.
19
+ **Pi packages** are distribution bundles managed by Pi (`pi install`, `pi remove`, `pi update`). A Pi package can provide Pi extensions, skills, prompt templates, themes, context/system prompt files, and/or PI WEB plugins. Many Pi packages do not include a PI WEB plugin.
19
20
 
20
- **Pi extensions** are runtime modules loaded by the session daemon. They can register Pi tools, hooks, commands, and model providers. They are not PI WEB plugins.
21
+ **Pi extensions** are runtime modules loaded by the session daemon. They can register Pi tools, hooks, commands, and model providers. They are not PI WEB plugins and use a different API and lifecycle.
21
22
 
22
- **PI WEB plugins** are browser-side UI modules discovered from bundled, local, dev, and installed Pi-package sources. They cannot register model providers or server-side hooks. Enabling or disabling a PI WEB plugin is a PI WEB config task; installing, removing, or updating a Pi package is a separate Pi package-manager task.
23
+ **PI WEB plugins** are packages discovered from bundled, local, dev, and installed Pi-package sources. A plugin can declare a browser `module`, a sessiond `serverModule`, or both. A server entry can participate only in the documented PI WEB plugin lifecycle and workspace-provider contract; it cannot register Pi model providers or arbitrary hooks.
23
24
 
24
25
  Use **Settings → Pi packages** to view configured Pi packages or install/remove/update a package. Enter only the package source, such as `npm:@scope/package`, a git/URL source, or a local path. PI WEB uses Pi's default package location, equivalent to `pi install <source>`, and does not ask for an install location.
25
26
 
26
27
  When machine federation is enabled, **Settings → Pi packages** targets the currently selected machine. The panel labels whether changes will run on the local/gateway machine or on a selected remote PI WEB machine.
27
28
 
28
- Use **Settings → PI WEB plugins** to enable or disable discovered PI WEB browser plugins before the browser imports them. In a federated setup, this plugin enablement surface targets the currently selected machine and labels where changes are saved.
29
+ Use **Settings → PI WEB plugins** to edit the desired enablement of discovered plugins on the selected machine. Browser-only changes apply after a page reload. A server-backed change also requires a session-daemon restart before its paired browser module can load against the new active revision. If an older or unavailable remote PI WEB server does not support the versioned plugin lifecycle, PI WEB reports plugin settings as unsupported or unavailable instead of silently falling back to the gateway.
29
30
 
30
- After installing, removing, or updating a Pi package, type `/reload` in each idle PI WEB session on the target machine to refresh ordinary Pi resources such as extensions, skills, prompt templates, themes, and context/system prompt files. Reload the browser page separately for newly discovered or changed PI WEB browser plugins. A provider-registering Pi extension follows a separate daemon-start policy; see [Pi extension provider baseline](https://pi-web.dev/config#pi-extension-provider-baseline).
31
+ After installing, removing, or updating a Pi package, type `/reload` in each idle PI WEB session on the target machine to refresh ordinary Pi resources such as extensions, skills, prompt templates, themes, and context/system prompt files. For PI WEB plugins, manually restart the target session daemon when the package has a server entry, then reload the browser page. A provider-registering Pi extension follows a separate daemon-start policy; see [Pi extension provider baseline](https://pi-web.dev/config#pi-extension-provider-baseline).
31
32
 
32
33
  ## Pi extension dialogs in PI WEB
33
34
 
@@ -45,14 +46,27 @@ One browser-local caveat: reloading the browser while a new session is still bei
45
46
 
46
47
  ## Trust model
47
48
 
48
- Plugins run as JavaScript in the browser app. Treat them as trusted code:
49
+ Treat every plugin package as trusted code:
49
50
 
50
- - they can call browser APIs;
51
- - they can read workspace files and start terminal commands through documented plugin helpers;
52
- - they can render arbitrary Lit templates/custom elements in plugin contribution areas;
53
- - they should not be installed from untrusted sources.
51
+ - browser entries can call browser APIs, read workspace files, start terminal commands through helpers, and render arbitrary UI;
52
+ - server entries execute in-process inside sessiond with the PI WEB service user's filesystem, environment, and process permissions, and they share sessiond's event loop;
53
+ - a CPU-bound, blocking, or deadlocked callback can stall sessions, terminals, and health endpoints; abort/deadline signals bound only cooperative asynchronous code and cannot preempt code that ignores them;
54
+ - ordinary import, activation, start, health, and stop failures are attributed and quarantined where the host can catch them, but this is a stability boundary rather than a security boundary;
55
+ - plugins should not be installed from untrusted sources.
54
56
 
55
- PI WEB's `/api/...` HTTP and WebSocket endpoints are internal implementation details. Plugin code should use the documented context helpers instead. Daring plugins can still reach private routes or runtime objects because they run in the browser, but those private surfaces are experimental: they may graduate into stable helpers, change shape, or disappear.
57
+ PI WEB's `/api/...` HTTP and WebSocket endpoints are internal implementation details. Browser code should use documented context helpers, including `context.backend.request()` for a paired server entry. Server code should use only `@jmfederico/pi-web/server-plugin-api`. Private routes, runtime objects, and source-internal imports are experimental and may change or disappear.
58
+
59
+ ## Workspace providers and replacement ownership
60
+
61
+ Sessiond is the single authority for project workspace discovery and spawned-session target validation. One active plugin exclusively owns a project's workspace semantics:
62
+
63
+ 1. Healthy or degraded primary providers probe first.
64
+ 2. If exactly one primary returns `"claim"`, it owns the project.
65
+ 3. If no primary claims, fallback providers probe. Bundled Git is a fallback provider.
66
+ 4. Multiple claimants in the winning tier produce a visible conflict; PI WEB does not select by plugin id or import order.
67
+ 5. If no provider claims, PI WEB exposes the project folder as the kernel workspace. If a winner claims and then fails to list, PI WEB reports degraded state instead of silently switching owners.
68
+
69
+ PI WEB ships only the bundled Git production provider. Replacement integrations, including Jujutsu providers, are owned and distributed by third parties. An installed and enabled primary provider can claim its projects and suppress fallback Git without any PI WEB core changes; this documentation does not promise or ship a reference replacement.
56
70
 
57
71
  ## What to ask AI to build
58
72
 
@@ -89,7 +103,7 @@ Before coding, read the PI WEB plugin docs:
89
103
  https://pi-web.dev/plugins
90
104
  Full API reference:
91
105
  https://pi-web.dev/plugins.md
92
- Keep the plugin compatible with the documented v1 API.
106
+ Keep the browser entry on API v2 and any server entry on API v1.
93
107
  After editing, check the manifest endpoint and browser-console failure cases.
94
108
  ```
95
109
 
@@ -123,7 +137,7 @@ Package metadata:
123
137
  "private": true,
124
138
  "piWeb": {
125
139
  "plugins": [
126
- { "id": "info", "module": "pi-web-plugin.js" }
140
+ { "id": "info", "browserRoot": ".", "module": "pi-web-plugin.js" }
127
141
  ]
128
142
  }
129
143
  }
@@ -133,7 +147,7 @@ Module shape excerpt:
133
147
 
134
148
  ```js
135
149
  export default {
136
- apiVersion: 1,
150
+ apiVersion: 2,
137
151
  name: "Info Plugin",
138
152
  activate: ({ html, svg }) => ({
139
153
  contributions: {
@@ -151,9 +165,38 @@ The Info panel doubles as an always-available PI WEB status view: it renders the
151
165
 
152
166
  PI WEB also ships an `updates` plugin that demonstrates dynamic `visible` and `badge` callbacks for tabs that only appear when the host has status messages or needs extra install visibility.
153
167
 
168
+ ## Canonical dual-entry provider: bundled Git
169
+
170
+ The bundled `git` plugin is the production example for a paired browser module and workspace-provider server module. Both entries use the same public contracts available to an installed plugin:
171
+
172
+ ```text
173
+ pi-web-plugins/git/package.json
174
+ pi-web-plugins/git/browser/pi-web-plugin.ts
175
+ pi-web-plugins/git/server-plugin.ts
176
+ ```
177
+
178
+ Its built `.js` server entry is a Node ES module, so its package declares `"type": "module"`. Do the same for an installed provider whose `serverModule` ends in `.js`, or emit `.mjs`; do not rely on Node's typeless-module reparsing.
179
+
180
+ Its TypeScript entries import declarations only from the published package subpaths:
181
+
182
+ ```ts
183
+ import type { PiWebPlugin } from "@jmfederico/pi-web/plugin-api";
184
+ import type { PiWebServerPlugin, WorkspaceProvider } from "@jmfederico/pi-web/server-plugin-api";
185
+ ```
186
+
187
+ Git declares `machineSpecific: true`, contributes a fallback workspace provider, and implements its status/diff backend and removal plan through the public provider callbacks. It receives no raw routes or private PI WEB services. Use it to understand the demonstrated contract, not as a template for Git-specific fields: replacement providers define their own private data, public metadata, backend operations, and removal wording.
188
+
189
+ ## Copyable standalone workspace-provider example
190
+
191
+ The repository and published npm package include [`examples/workspace-provider-plugin/`](https://github.com/jmfederico/pi-web/tree/main/examples/workspace-provider-plugin), a small standalone package you can copy without PI WEB source imports. It includes package metadata, a strict NodeNext TypeScript configuration, browser and server source, and build/install instructions.
192
+
193
+ The example uses browser API v2 and server API v1. Its browser entry compares `workspace.provider.pluginId` with the stable source `pluginId`, uses `runtimePluginId` only to open its qualified panel, displays non-secret `publicMetadata`, and calls the backend owned by the selected workspace. Its server provider conservatively claims only projects containing `.pi-web/example-workspace-provider`. The explicit `browserRoot: "dist/browser"` keeps `dist/server.js`, source, package metadata, and dependencies outside browser asset routes.
194
+
195
+ Copy the example from a checkout or from `node_modules/@jmfederico/pi-web/examples/workspace-provider-plugin`, then follow its README. It deliberately does not advertise removal; use the removal contract below when adding that capability.
196
+
154
197
  ## Local plugin usage
155
198
 
156
- This works with the production native-service install. PI WEB discovers plugins from `~/.pi-web/plugins/<plugin-package>/` on the web/API side; no PI WEB rebuild or session-daemon restart is required. If `PI_WEB_DATA_DIR` is set, use `$PI_WEB_DATA_DIR/plugins` instead.
199
+ This works with the production native-service install. PI WEB discovers packages from `~/.pi-web/plugins/<plugin-package>/`; if `PI_WEB_DATA_DIR` is set, use `$PI_WEB_DATA_DIR/plugins` instead. No PI WEB rebuild is required.
157
200
 
158
201
  Symlink a plugin folder into PI WEB's local plugin directory:
159
202
 
@@ -162,46 +205,50 @@ mkdir -p ~/.pi-web/plugins
162
205
  ln -s /path/to/plugin-folder ~/.pi-web/plugins/plugin-id
163
206
  ```
164
207
 
165
- Reload the PI WEB browser tab. PI WEB serves plugin modules with an mtime-based `?v=` cache buster. After editing a plugin, hard reload the browser if you do not see changes.
208
+ For a browser-only package, reload the PI WEB tab after installing or editing it. PI WEB uses a package-content revision in the module URL; hard reload if an already-open page still holds old JavaScript. For a package with `serverModule`, restart sessiond to activate the startup snapshot, then reload the browser. Editing files alone never hot-reloads or unloads server code.
166
209
 
167
210
  ## Remote machine plugins
168
211
 
169
- When [machine federation](https://pi-web.dev/machines) is enabled, PI WEB also loads discovered plugins from the selected remote machine. Remote plugins are trusted browser-side code like local plugins, but their contributions are machine-scoped:
212
+ When [machine federation](https://pi-web.dev/machines) is enabled, PI WEB loads the selected remote machine's compatible browser plugins through the gateway and runs its server entries in that remote machine's session daemon. Contributions and helpers are machine-scoped:
213
+
214
+ - actions, workspace panels, and workspace labels appear only for the applicable selected machine;
215
+ - file and terminal helpers run against that machine;
216
+ - `context.backend.request()` is routed through the gateway to the current workspace owner on that machine;
217
+ - a server-backed browser module is published only when its package source, scope, settings fingerprint, browser revision, and backend revision match the active sessiond snapshot and the backend is not unhealthy;
218
+ - if gateway and remote packages share an original id, `machineSpecific` controls whether the portable gateway copy is reused or the selected machine's own copy is required;
219
+ - remote theme contributions are ignored for now because themes are app-wide.
170
220
 
171
- - actions, workspace panels, and workspace labels only appear while that machine is selected;
172
- - plugin file and terminal helpers run against that machine;
173
- - plugin code is loaded best-effort through the current gateway and cached for the browser page lifetime;
174
- - if the gateway and remote machine both have an enabled plugin with the same original id, `machineSpecific` metadata decides whether the gateway copy is reused or only the selected machine's copy can appear;
175
- - remote theme contributions are ignored for now because themes are app-wide;
176
- - mixed PI WEB versions across federated machines are best-effort and not guaranteed compatible.
221
+ The remote manifest and backend bridge use a versioned lifecycle contract. A future/unsupported lifecycle version, a missing backend route, or a mismatched frontend/backend revision produces an explicit compatibility error; PI WEB does not silently run an unpaired server-backed UI.
177
222
 
178
- Remote plugin enablement is controlled by the remote machine's PI WEB plugin config. To edit or disable a remote machine plugin, select that machine and use **Settings → PI WEB plugins**, or open that machine directly/update its config file.
223
+ Plugin/provider compatibility is intentionally all-or-nothing during a mixed-version fleet rollout. A newer gateway rejects an older target's whole remote plugin manifest when the target lacks the current lifecycle contract, so even that target's browser-only plugin contributions and Git panel are unavailable. In the other upgrade order, an older gateway still calls the legacy core Git routes removed by an updated target, so remote Git status/diff requests return `404`. Upgrade the gateway and target together, restart their updated web/API processes and the target session daemon, then reload the gateway tab. Other machine features remain subject to their own capability negotiation.
224
+
225
+ Remote desired enablement is stored in the remote machine's PI WEB config. Select that machine in **Settings → PI WEB plugins** to edit it, or open the machine directly/edit its config. Browser-only changes need a page reload. Server-backed changes need a restart of that remote session daemon followed by a page reload.
179
226
 
180
227
  Plugin package metadata may set `machineSpecific: true` when the plugin's meaning is tied to the selected PI WEB machine:
181
228
 
182
- - Omitted or `false`: use the gateway copy when the same plugin id is also present on a remote machine. This is best for portable UI plugins whose helpers already route through the selected machine.
183
- - `true`: the gateway copy only appears for the local machine. When a remote machine is selected, only that remote machine's copy can appear; if the remote machine does not expose the plugin, the plugin is hidden. This is best for plugins that report machine-local PI WEB status or depend on machine-local plugin code.
229
+ - Omitted or `false`: valid for browser-only plugins; use the gateway copy when the same id is present remotely.
230
+ - `true`: the gateway copy appears only for the local machine, and a selected remote machine uses only its own copy. Dual browser/server entries are always machine-specific; omitting the field defaults them to `true`, while explicitly setting `false` is invalid.
184
231
 
185
- For portable plugin assets, prefer URLs relative to the plugin module, for example:
232
+ For portable plugin assets, prefer URLs relative to the plugin module:
186
233
 
187
234
  ```js
188
235
  const url = new URL("./asset.json", import.meta.url);
189
236
  ```
190
237
 
191
- If a remote plugin constructs absolute asset URLs, it should use the `pluginId` from `activate()` because PI WEB gives remote plugins a gateway-scoped runtime id. Hard-coded `/pi-web-plugins/<original-id>/...` URLs may point at the gateway instead of the remote machine.
238
+ In browser API v2, activation `pluginId` is always the stable package/source id, locally and through federation. Compare it directly with `workspace.provider.pluginId` for ownership. `runtimePluginId` is the separately named host-unique id for qualified contribution references such as `${runtimePluginId}:workspace.panel`; a remote host may machine-scope it.
192
239
 
193
- ## Manage PI WEB plugins
240
+ Do not construct absolute plugin asset routes from either identity. Module-relative URLs keep the host-selected runtime scope and deployment base automatically; hard-coded `/pi-web-plugins/...` paths can point at the wrong machine or break nested deployments.
194
241
 
195
- Open **Settings → PI WEB plugins** to review discovered bundled, local, dev, and Pi-package-supplied PI WEB plugins for the selected PI WEB machine. When the local machine is selected, this is the gateway plugin list; when a remote machine is selected, the list comes from that remote PI WEB server and includes disabled discovered plugins it exposes. PI WEB can disable any discovered selected-machine plugin before the browser imports it. Core app contributions such as the built-in command palette, base workspace tools, and themes are not managed through this plugin list.
242
+ ## Manage PI WEB plugins
196
243
 
197
- This surface is only for PI WEB plugin enablement. To install, remove, or update Pi packages that may provide PI WEB plugins or other Pi resources, use **Settings → Pi packages**. In a federated setup, both the Pi packages panel and the PI WEB plugins panel target the selected machine; plugin enablement still writes the PI WEB `plugins` config key rather than changing Pi package-manager settings.
244
+ Open **Settings → PI WEB plugins** to compare desired package/config state with the active sessiond startup snapshot on the selected machine. The list includes bundled, local, dev, and Pi-package-supplied plugins, disabled discovered entries, and entries known only to the still-active snapshot. It reports browser-only, active, failed, incompatible, disabled, not-active, unknown, conflict, stale-revision, health, safe-mode, and restart-required states. Settings and diagnostics expose fingerprints and revisions, not plugin setting values.
198
245
 
199
- Plugin preferences are stored under the top-level `plugins` config key in the PI WEB config file:
246
+ Plugin enablement is separate from package installation. Use **Settings → Pi packages** to install, remove, or update a Pi package. The PI WEB plugin panel writes the selected machine's top-level `plugins` config key. It remains possible to edit desired config while sessiond is unavailable, although active state cannot then be verified.
200
247
 
201
248
  ```json
202
249
  {
203
250
  "plugins": {
204
- "workspace-tasks": {
251
+ "git": {
205
252
  "enabled": true,
206
253
  "settings": {}
207
254
  },
@@ -212,16 +259,56 @@ Plugin preferences are stored under the top-level `plugins` config key in the PI
212
259
  }
213
260
  ```
214
261
 
215
- Plugins are enabled by default. Set `enabled` to `false` to remove a plugin from `/pi-web-plugins/manifest.json` so the browser will not import or activate it on the next page load. The optional `settings` object is reserved for plugin-specific settings.
262
+ Plugins are enabled by default. `plugins.<id>.enabled: false` removes a browser-only entry on the next page load and prevents a server entry from loading on the next sessiond start. The optional `settings` object must be JSON-compatible and is captured for a server entry only at sessiond startup.
263
+
264
+ ### Desired versus active state
265
+
266
+ Sessiond resolves one immutable enabled server-plugin snapshot at startup and remains the workspace authority for its lifetime. Saving config or replacing package files changes **desired** state only. The existing backend can remain active until sessiond restarts; conversely, its paired browser module is withheld when active and desired revisions no longer match. A web/API restart or browser reload does not change sessiond's active provider registry.
267
+
268
+ Use this sequence:
269
+
270
+ 1. Install or update the package on the target machine.
271
+ 2. Set the desired plugin enablement/settings.
272
+ 3. For a browser-only plugin, reload the browser tab.
273
+ 4. For a server-backed plugin, manually restart sessiond, wait for it to become available, then reload the browser tab.
274
+
275
+ > **Manual session-daemon restart:** for the native systemd user service, run `systemctl --user restart pi-web-sessiond` (the unit is `pi-web-sessiond.service`). Restarting sessiond may interrupt active sessions and runtime ownership. Web/UI autoreload, restarting only the web/API service, browser reload, and Pi's `/reload` command do not activate server-plugin changes.
276
+
277
+ ### Offline disable and safe start
278
+
279
+ Recovery commands edit global PI WEB config without contacting sessiond, discovering packages, or importing plugin code. Run them on the affected target machine. Add `--config /path/to/config.json` when its services use a non-default `PI_WEB_CONFIG`.
280
+
281
+ ```bash
282
+ pi-web plugins disable <plugin-id> --restart
283
+ pi-web plugins safe-start show
284
+ pi-web plugins safe-start set bundled-only --restart
285
+ pi-web plugins safe-start set none --restart
286
+ pi-web plugins safe-start clear --restart
287
+ ```
288
+
289
+ - `disable` sets that plugin's desired `enabled` value to `false` while preserving unrelated config.
290
+ - `bundled-only` persists safe start and filters discovery before external local or Pi-package server modules are considered.
291
+ - `none` persists the emergency level and imports no server plugins; the kernel folder workspace remains available.
292
+ - `clear` returns the next startup to ordinary configured discovery.
293
+ - `--restart` requests an automatic restart only when PI WEB recognizes a safe installed-service action. Otherwise the command prints manual guidance.
294
+
295
+ An unsupported `serverPlugins.safeStart` shape or value in otherwise valid JSON fails closed as effective `none`: sessiond imports no server plugins and reports a diagnostic. Use `safe-start show`, then `set` or `clear`, to repair it offline. Recovery config is written before an automatic restart is attempted; if that service-manager command fails, restart sessiond manually.
216
296
 
217
- After changing plugin enablement, reload the PI WEB browser tab. Already-loaded plugin JavaScript is not unloaded from the current page.
297
+ Ordinary plugin failures are normally quarantined, but safe start provides a recovery path for code that blocks or terminates sessiond before normal containment can help. Any restart can interrupt active sessions/runtime ownership; inspect active work before using `--restart` or running the manual service command.
218
298
 
219
299
  ## Built-in plugins
220
300
 
221
- PI WEB ships core, discoverable plugins in the main `@jmfederico/pi-web` npm package. No separate `pi install` step is required: update PI WEB, reload the browser tab, and the bundled plugins appear in `/pi-web-plugins/manifest.json`.
301
+ PI WEB ships core, discoverable plugins in the main `@jmfederico/pi-web` npm package. No separate `pi install` step is required. After updating PI WEB, manually restart sessiond so bundled server entries use the installed revision, then reload the browser tab. Browser-only bundled entries need only the tab reload.
222
302
 
223
303
  Built-in plugins can be managed from **Settings → PI WEB plugins** or with the top-level `plugins` config key.
224
304
 
305
+ ### Git
306
+
307
+ **Plugin id:** `git`
308
+ **What it does:** claims Git projects as a fallback workspace provider, discovers worktrees, supplies provider-owned removal plans, and adds the Git status/diff workspace panel through its paired backend.
309
+
310
+ Git is enabled by default and is the only production workspace provider bundled with PI WEB. An enabled primary third-party provider can claim a project before Git. Disabling `git` and restarting sessiond leaves the kernel project-folder workspace available; reload the browser afterward so Git contributions disappear. The generic Files, Terminal, and Session features continue to work in that folder workspace.
311
+
225
312
  ### Updates
226
313
 
227
314
  **Plugin id:** `updates`
@@ -317,7 +404,7 @@ Relays is enabled by default. To hide it, disable `relays` in **Settings → PI
317
404
 
318
405
  ## Discovery and packaging
319
406
 
320
- PI WEB builds the gateway `/pi-web-plugins/manifest.json` from these sources:
407
+ The web/API catalog and sessiond startup catalog use the same package sources. The browser manifest includes only compatible entries that declare `module`; sessiond considers enabled entries that declare `serverModule`:
321
408
 
322
409
  1. Bundled plugins in the PI WEB package:
323
410
 
@@ -335,7 +422,7 @@ PI WEB builds the gateway `/pi-web-plugins/manifest.json` from these sources:
335
422
 
336
423
  3. Installed Pi packages that expose PI WEB plugin metadata. Pi packages may be user or project scoped. Installing/removing/updating Pi packages is done from **Settings → Pi packages** (or Pi's package manager), not from the PI WEB plugin enable/disable list.
337
424
 
338
- Remote machines expose their own manifests through the gateway at `/api/machines/<machine-id>/pi-web-plugins/manifest.json`. Those plugin modules are rewritten to gateway-scoped asset URLs and registered under machine-scoped runtime ids so duplicate plugin ids on different machines do not collide.
425
+ Remote machines expose their versioned browser manifests through the gateway at `/api/machines/<machine-id>/pi-web-plugins/manifest.json`. Those plugin modules are rewritten to gateway-scoped asset URLs and registered under machine-scoped runtime ids so package copies on different machines do not collide.
339
426
 
340
427
  Plugin package directory names and plugin ids must be valid identifiers:
341
428
 
@@ -343,15 +430,27 @@ Plugin package directory names and plugin ids must be valid identifiers:
343
430
  ^[a-z][a-z0-9.-]*$
344
431
  ```
345
432
 
346
- A package can expose one or more PI WEB plugin modules. There is exactly one supported `package.json` metadata shape:
433
+ A package can expose one or more PI WEB plugin entries. There is exactly one supported `package.json` metadata shape:
347
434
 
348
435
  ```json
349
436
  {
350
437
  "private": true,
438
+ "type": "module",
351
439
  "piWeb": {
352
440
  "plugins": [
353
- { "id": "review", "module": "dist/review.js" },
354
- { "id": "dashboard", "module": "dist/dashboard.js", "machineSpecific": true }
441
+ {
442
+ "id": "review",
443
+ "browserRoot": "dist/review",
444
+ "module": "dist/review/index.js"
445
+ },
446
+ {
447
+ "id": "workspaces",
448
+ "browserRoot": "dist/browser",
449
+ "module": "dist/browser/index.js",
450
+ "serverModule": "dist/server.js",
451
+ "machineSpecific": true
452
+ },
453
+ { "id": "server-only", "serverModule": "dist/server-only.js" }
355
454
  ]
356
455
  }
357
456
  }
@@ -360,103 +459,212 @@ A package can expose one or more PI WEB plugin modules. There is exactly one sup
360
459
  Rules:
361
460
 
362
461
  - `piWeb.plugins` must be an array of objects.
363
- - Each entry must have an explicit `id` and `module`.
364
- - `id` must match `^[a-z][a-z0-9.-]*$`.
365
- - `module` must be a safe relative path inside the plugin package root.
366
- - `machineSpecific` is optional and must be a boolean; omit it for the default portable gateway behavior.
367
- - Duplicate plugin ids are not auto-renamed; later duplicates are skipped.
462
+ - Each entry must have an explicit `id` and at least one of `module` or `serverModule`.
463
+ - `id` must match `^[a-z][a-z0-9.-]*$`. Externally declared ids `core`, `themes`, and every `machine.*` id are reserved for the host and rejected with an attributed package diagnostic.
464
+ - Both module paths must be safe canonical relative paths to existing files inside the package root. Backslashes, absolute or Windows drive-qualified paths, and empty, `.`, `..`, `.git`, or `node_modules` segments are rejected.
465
+ - Every browser entry must declare `browserRoot`; a server-only entry must not. The root is `.` or a safe canonical package-relative directory with no empty, `.`, `..`, `.git`, or `node_modules` segment; Windows drive-qualified roots are rejected. It must resolve inside the package, and the browser module must remain inside it both logically and after symlink resolution.
466
+ - Server entries are imported as Node ES modules. When a `serverModule` uses a `.js` path, declare `"type": "module"` in that plugin package; `.mjs` is the explicit-extension alternative.
467
+ - `machineSpecific` is optional and must be boolean. Browser-only and server-only entries default to `false`. Dual browser/server entries default to `true` and cannot explicitly set it to `false`.
468
+ - `plugins.<id>.settings` must be JSON-compatible for server entries; sessiond captures a private copy at startup and diagnostics expose only a fingerprint.
469
+ - A plugin id has one package owner across its browser and server capabilities. Duplicates are diagnosed and never merged or auto-renamed; later package records are skipped.
368
470
  - Legacy shortcuts such as `piWeb.plugin`, string entries in `piWeb.plugins`, `piWeb.id` fallback ids, and no-`package.json` fallbacks are not supported.
369
471
 
472
+ Discovery hashes the package (without traversing `.git` or `node_modules`) to produce one package-wide revision and enforce one package-wide artifact budget. A package is rejected when the scan exceeds **4,096 directory entries** or **16 MiB of file content**. These limits include files outside `browserRoot`, even though those files are not served. Keep generated caches and unrelated large artifacts out of the installed plugin package.
473
+
370
474
  ### Manifest and assets
371
475
 
372
- The manifest contains each discovered plugin module. Current PI WEB releases emit `module` as a leading application-root reference:
476
+ The manifest contains a lifecycle version and each publishable browser module. Current PI WEB releases emit `module` as a leading application-root reference and include `backendRevision` only for a paired active server entry:
373
477
 
374
478
  ```json
375
479
  {
480
+ "lifecycleVersion": 1,
376
481
  "plugins": [
377
482
  {
378
- "id": "my-plugin",
379
- "module": "/pi-web-plugins/my-plugin/pi-web-plugin.js?v=1234567890",
483
+ "id": "workspaces",
484
+ "module": "/pi-web-plugins/workspaces/dist/browser/index.js?v=<content-revision>",
485
+ "backendRevision": "<active-server-revision>",
380
486
  "source": "local",
381
487
  "scope": "local",
382
- "machineSpecific": false
488
+ "machineSpecific": true
383
489
  }
384
490
  ]
385
491
  }
386
492
  ```
387
493
 
388
- The browser maps leading application-root references into the current application base, so the same manifest works at the origin root or under a reverse-proxy path prefix. Keeping this output format also lets gateways from existing PI WEB releases consume plugins from an upgraded remote machine. For compatibility, federated gateways additionally accept explicit manifest-relative references such as `./my-plugin/pi-web-plugin.js` and legacy plugin-root-relative references such as `nested/pi-web-plugin.js`; all accepted forms are rewritten to deployment-portable, gateway-relative references.
494
+ The browser maps leading application-root references into the current application base, so the same manifest works at the origin root or under a reverse-proxy path prefix. Federated gateways additionally accept explicit manifest-relative references such as `./my-plugin/pi-web-plugin.js` and legacy plugin-root-relative references such as `nested/pi-web-plugin.js`; all accepted forms are rewritten to deployment-portable, gateway-relative references.
389
495
 
390
- `source` describes where the plugin came from (`bundled`, `local`, or the Pi package source). `scope` is `bundled`, `local`, `user`, or `project`. `machineSpecific` controls whether the gateway copy is valid for remote machines or only each selected machine's own copy can appear.
496
+ `source` describes where the plugin came from (`bundled`, `local`, or the Pi package source). `scope` is `bundled`, `local`, `user`, or `project`. `machineSpecific` controls whether the gateway copy is valid for remote machines or only each selected machine's own copy can appear. A server-only entry has no browser manifest record. A dual entry is omitted unless sessiond reports the exact active, compatible, non-unhealthy package pairing.
391
497
 
392
- At an origin-root deployment, a plugin's static assets are available under:
498
+ At an origin-root deployment, a browser-public file is available under its package-relative path:
393
499
 
394
500
  ```text
395
- /pi-web-plugins/<plugin-id>/<path-inside-plugin-root>
501
+ /pi-web-plugins/<plugin-id>/<package-relative-path-under-browserRoot>
396
502
  ```
397
503
 
398
- Prefer module-relative asset URLs so they also work for remote machine plugins. For example, a built plugin module can reference an SVG shipped beside it:
504
+ Only files logically inside `browserRoot` and canonically inside that same directory after symlink resolution are captured and served. Files elsewhere in the package—including a sibling server module, source, metadata, and dependencies—return not found through plugin asset routes. Declaring `browserRoot: "."` therefore makes almost the whole scanned package browser-public; prefer a narrow output directory and never place secrets inside it. Unsafe, missing, package-escaping, or module-excluding roots fail discovery with an attributed diagnostic.
505
+
506
+ Prefer module-relative asset URLs so they also work for remote machine plugins and nested deployments. For example, a built plugin module can reference an SVG shipped beside it:
399
507
 
400
508
  ```js
401
509
  const iconUrl = new URL("./assets/icon.svg", import.meta.url);
402
510
  ```
403
511
 
404
- The final installed plugin package must contain `assets/icon.svg` at that path relative to the final built module. PI WEB serves files that already exist in the package; it does not copy a source `public/` directory or apply Vite-style public-directory semantics. Configure the plugin build and package contents to emit or copy the asset into its final module-relative location.
512
+ The final installed plugin package must contain `assets/icon.svg` at that path relative to the final built module and inside `browserRoot`. PI WEB serves files that already exist in the package; it does not copy a source `public/` directory or apply Vite-style public-directory semantics. Configure the plugin build and package contents to emit or copy the asset into its final module-relative location.
405
513
 
406
- PI WEB prevents asset path traversal outside the plugin root. JavaScript, JSON, CSS, HTML, and SVG files get appropriate content types; unknown file types are served as octet-stream.
514
+ PI WEB returns executable JavaScript MIME types for both `.js` and `.mjs`. JSON, CSS, HTML, and SVG receive their corresponding content types; unknown file types are served as octet-stream.
407
515
 
408
- ## Plugin module shape
516
+ ## Browser module shape and v2 migration
409
517
 
410
- The entry module must default-export a plugin object:
518
+ TypeScript browser entries should use a type-only import from the published declaration entrypoint. The built JavaScript must not import PI WEB source internals:
519
+
520
+ ```ts
521
+ import type { PiWebPlugin } from "@jmfederico/pi-web/plugin-api";
522
+
523
+ const plugin: PiWebPlugin = {
524
+ apiVersion: 2,
525
+ name: "My Plugin",
526
+ activate: ({ pluginId, runtimePluginId, html }) => ({
527
+ contributions: {
528
+ actions: [{
529
+ id: "workspace.open",
530
+ title: "Open my panel",
531
+ run: ({ selectWorkspaceTool }) => {
532
+ selectWorkspaceTool(`${runtimePluginId}:workspace.my-panel`);
533
+ },
534
+ }],
535
+ workspacePanels: [{
536
+ id: "workspace.my-panel",
537
+ title: "My panel",
538
+ visible: ({ workspace }) => workspace.provider?.pluginId === pluginId,
539
+ render: ({ workspace }) => html`<p>${workspace.label}</p>`,
540
+ }],
541
+ },
542
+ }),
543
+ };
544
+
545
+ export default plugin;
546
+ ```
547
+
548
+ The activation boundary is:
411
549
 
412
550
  ```ts
413
551
  interface PiWebPlugin {
414
- apiVersion: 1;
552
+ apiVersion: 2;
415
553
  name: string;
416
- activate: (context: PluginActivationContext) => PluginActivationResult;
554
+ activate(context: PluginActivationContext): PluginActivationResult;
417
555
  }
418
556
 
419
557
  interface PluginActivationContext {
420
- apiVersion: 1;
421
- pluginId: string;
422
- html: typeof import("lit").html;
423
- svg: typeof import("lit").svg;
558
+ readonly apiVersion: 2;
559
+ readonly pluginId: string;
560
+ readonly runtimePluginId: string;
561
+ readonly html: HtmlTemplateTag;
562
+ readonly svg: SvgTemplateTag;
424
563
  }
564
+ ```
425
565
 
426
- interface PluginActivationResult {
427
- contributions: PluginContributions;
428
- }
566
+ `activate()` is called once when the UI loads the plugin. Keep it cheap and synchronous: define contributions there, but move expensive or async work into actions, custom elements, or explicit user interactions.
567
+
568
+ Browser API v2 is a deliberate break: the host rejects browser v1 entries with the plugin/module identity and expected version; there is no v1 compatibility shim. Migrate a browser entry by setting `apiVersion: 2`, using stable `pluginId` for package/provider ownership, and using `runtimePluginId` when constructing a host-qualified contribution reference. Replace browser-v1 `refreshGit` with `refreshWorkspacePanels()` plus panel `onInvalidate()`. The browser-v1 `isGitRepo`, `isGitWorktree`, and top-level `workspace.branch` aliases were removed; use the provider-authored `workspace.label` for generic presentation, and keep provider-specific facts in `workspace.provider.metadata` or the owning backend. The former `@jmfederico/pi-web/plugin-api/unstable` type path is not part of v2 and is no longer exported.
569
+
570
+ Contribution ids authored in arrays remain local to the plugin. PI WEB qualifies them internally under the runtime identity:
571
+
572
+ ```text
573
+ <runtime-plugin-id>:<local-contribution-id>
429
574
  ```
430
575
 
431
- Example:
576
+ For a local plugin the runtime and source ids are normally equal. A federated registration may machine-scope `runtimePluginId`, while `pluginId` and `workspace.provider.pluginId` remain the same source id.
432
577
 
433
- ```js
434
- export default {
578
+ ## Server module and workspace provider shape
579
+
580
+ TypeScript server entries import the separately published Node declarations with `import type`:
581
+
582
+ ```ts
583
+ import type {
584
+ PiWebServerPlugin,
585
+ WorkspaceProvider,
586
+ } from "@jmfederico/pi-web/server-plugin-api";
587
+
588
+ const provider: WorkspaceProvider = {
589
+ async probe(project, signal) {
590
+ // Return "claim" only when this provider owns the project's semantics.
591
+ return await projectIsSupported(project, signal) ? "claim" : "pass";
592
+ },
593
+ async list(project, signal) {
594
+ return await listProviderWorkspaces(project, signal);
595
+ },
596
+ async request({ project, workspace, operation, input, signal }) {
597
+ return await handleProviderOperation({ project, workspace, operation, input, signal });
598
+ },
599
+ };
600
+
601
+ const plugin: PiWebServerPlugin = {
435
602
  apiVersion: 1,
436
- name: "My Plugin",
437
- activate: ({ pluginId, html }) => ({
438
- contributions: {
439
- actions: [],
440
- workspacePanels: [],
441
- workspaceLabels: [],
442
- },
443
- }),
603
+ name: "My Workspace Provider",
604
+ activate(context) {
605
+ return {
606
+ workspaceProvider: provider,
607
+ health: async (signal) => ({ status: "healthy" }),
608
+ stop: async (signal) => { /* release plugin-owned resources */ },
609
+ };
610
+ },
444
611
  };
612
+
613
+ export default plugin;
445
614
  ```
446
615
 
447
- `activate()` is called once when the UI loads the plugin. Keep it cheap: define contributions there, but move expensive or async work into actions, custom elements, or explicit user interactions.
616
+ The default export has `apiVersion: 1`, a non-empty `name`, and `activate(context)`. The activation result can contain:
448
617
 
449
- The plugin id comes from `package.json`, not from the JavaScript module. Contribution ids are local to the plugin and PI WEB qualifies them internally as:
618
+ ```ts
619
+ interface ServerPluginActivation {
620
+ workspaceProvider?: WorkspaceProvider;
621
+ start?(signal: AbortSignal): void | Promise<void>;
622
+ stop?(signal: AbortSignal): void | Promise<void>;
623
+ health?(signal: AbortSignal): ServerPluginHealth | Promise<ServerPluginHealth>;
624
+ }
625
+ ```
450
626
 
451
- ```text
452
- <plugin-id>:<local-contribution-id>
627
+ A server plugin may contribute at most one `workspaceProvider`. The host-owned frozen activation context contains its `pluginId`, `packageRoot`, JSON settings snapshot, scoped logger, activation `AbortSignal`, and an argv-based `execFile()` helper. `execFile()` has host-owned timeout/output bounds; pass the current callback's signal into every command request. The API exposes no shell parser, Fastify instance, route registration, concrete service, event bus, or service locator.
628
+
629
+ Every activation, lifecycle, provider, and request signal is scoped to that one invocation. The host aborts it when the invocation times out or settles. Do not retain a signal as a plugin-lifetime shutdown notification; release plugin-owned resources in the explicit `stop()` callback. Deadlines remain cooperative, so plugins must observe each supplied signal.
630
+
631
+ Sessiond resolves the enabled catalog once per process start. It imports, validates, activates, and starts each server entry before publishing its contribution. A failed entry is attributed and skipped without aborting ordinary activation of other plugins; a failed `start` is rolled back with `stop` when available. Successful plugins stop in reverse activation order. Sessiond inspects each optional `health()` callback once while building the startup workspace authority; an unhealthy provider is excluded, a degraded provider remains eligible, and that inspection is not polled again during the process lifetime. Server entries are never hot-reloaded or unloaded after config/package edits.
632
+
633
+ ### Workspace provider contract
634
+
635
+ ```ts
636
+ interface WorkspaceProvider {
637
+ fallback?: boolean;
638
+ probe(project: ProjectInput, signal: AbortSignal): Promise<"claim" | "pass">;
639
+ list(project: ProjectInput, signal: AbortSignal): Promise<ProviderWorkspace[]>;
640
+ request?(context: ProviderRequestContext): Promise<JsonValue>;
641
+ prepareRemove?(context: ProviderRemoveContext): Promise<WorkspaceRemovePlan>;
642
+ }
643
+
644
+ interface ProviderWorkspace {
645
+ key: string;
646
+ path: string;
647
+ label: string;
648
+ isMain: boolean;
649
+ data?: JsonValue;
650
+ publicMetadata?: JsonObject;
651
+ removal?: { actionLabel: string; confirmation: string };
652
+ }
453
653
  ```
454
654
 
455
- For example, plugin `info` with action `workspace.show-path` becomes `info:workspace.show-path`.
655
+ - `probe()` must return only `"claim"` or `"pass"`. Leave `fallback` unset/false for a replacement that should run before bundled Git.
656
+ - `list()` runs only for the selected owner. Return stable provider-local keys, accessible absolute directory paths, unique paths/keys, non-empty labels, and exactly one main workspace.
657
+ - `data` is round-tripped privately to that provider during the current resolution. `publicMetadata` appears under `workspace.provider.metadata` and is visible to **all browser code and API consumers**. Never put secrets in `publicMetadata` or removal wording.
658
+ - `request()` is optional and receives a host-validated frozen current owner/workspace projection plus a bounded operation id, JSON input, and operation-scoped abort signal. It must return JSON.
659
+ - `removal` is display text only and requires `prepareRemove()`. It advertises removal for that specific workspace; browser `workspace.provider.capabilities.remove` is true only when that workspace advertises it and the owning provider implements removal.
660
+ - `prepareRemove()` returns a plan for a visible host-owned terminal run; returning the plan approves the operation but does **not** mean removal has completed. `command` is shell source interpreted by the host's login shell. The host chooses a safe current working directory outside the target, so the provider must use the supplied absolute `workspace.path`, shell-quote it, and keep removal in the foreground. The host records completion when the shell exits, with exit status 0 meaning success.
661
+ - Provider failures and conflicts are diagnostics. A claimant that fails `list()` does not permit fallback takeover for the same resolution.
662
+
663
+ The only supported plugin type entrypoints are the type-only package exports `@jmfederico/pi-web/plugin-api` and `@jmfederico/pi-web/server-plugin-api`. Use them with `import type`; there is no runtime JavaScript export. Private `dist/**` deep imports and any other plugin API subpath are not part of the package contract.
456
664
 
457
665
  ## Contributions
458
666
 
459
- `activate()` returns a `contributions` object with any combination of these arrays:
667
+ The workspace-related contribution arrays returned by `activate()` are:
460
668
 
461
669
  ```ts
462
670
  interface PluginContributions {
@@ -493,6 +701,7 @@ interface PluginAction {
493
701
  title: string;
494
702
  description?: string;
495
703
  shortcut?: string;
704
+ shortcutAliases?: QualifiedContributionId[];
496
705
  group?: string;
497
706
  enabled?: (context: PluginRuntimeContext) => boolean;
498
707
  disabledReason?: (context: PluginRuntimeContext) => string | undefined;
@@ -510,6 +719,8 @@ interface PluginRuntimeContext {
510
719
  selectedMachine?: PluginMachine;
511
720
  selectedWorkspace?: Workspace;
512
721
  selectedSession?: unknown;
722
+ workspaceTool?: string;
723
+ mainView?: string;
513
724
  piWebStatus?: PiWebStatusResponse;
514
725
  };
515
726
  prompt: PluginPromptEditor;
@@ -518,11 +729,15 @@ interface PluginRuntimeContext {
518
729
  addProject: () => void | Promise<void>;
519
730
  configureAuth: () => void | Promise<void>;
520
731
  logoutAuth: () => void | Promise<void>;
732
+ openThemePicker: () => void;
733
+ selectMainView: (view: string) => void;
521
734
  selectWorkspaceTool: (tool: QualifiedContributionId) => void;
522
735
  openTerminal: (options?: { terminalId?: string }) => void;
523
736
  refreshFiles: () => void | Promise<void>;
524
- refreshGit: () => void | Promise<void>;
737
+ refreshWorkspacePanels: (panelId?: QualifiedContributionId) => void | Promise<void>;
738
+ refreshAppData: () => void | Promise<void>;
525
739
  checkForPiWebUpdates?: () => void | Promise<void>;
740
+ reloadPage: () => void;
526
741
  startSession: () => void | Promise<void>;
527
742
  archiveSession: () => void | Promise<void>;
528
743
  stopActiveWork: () => void | Promise<void>;
@@ -532,13 +747,15 @@ interface PluginRuntimeContext {
532
747
  Notes:
533
748
 
534
749
  - `state` is a snapshot of current UI state when actions are built.
535
- - The stable state fields are `state.selectedMachine`, `state.selectedWorkspace`, `state.selectedSession`, and `state.piWebStatus`. `state.selectedMachine` identifies the currently selected machine. `state.piWebStatus` describes the currently selected machine's PI WEB runtime, or the gateway/local runtime when the local machine is selected.
750
+ - The stable state fields are `state.selectedMachine`, `state.selectedWorkspace`, `state.selectedSession`, `state.workspaceTool`, `state.mainView`, and `state.piWebStatus`. `state.selectedMachine` identifies the currently selected machine. `state.piWebStatus` describes the currently selected machine's PI WEB runtime, or the gateway/local runtime when the local machine is selected.
536
751
  - Other `state` fields may exist at runtime, but they are private PI WEB internals that may graduate into stable helpers, change shape, or disappear.
537
752
  - `enabled` is evaluated when the action palette asks for actions.
753
+ - `shortcutAliases` is for migration only: list former fully qualified action ids whose saved shortcut preference should still apply to this action.
538
754
  - `selectWorkspaceTool()` expects a qualified panel id such as `my-plugin:workspace.info`.
539
755
  - `openTerminal()` switches to the built-in terminal panel. Pass `{ terminalId }` to deep-link to a specific terminal.
756
+ - `refreshWorkspacePanels()` invokes `onInvalidate` for the selected workspace, either for every plugin panel or for one qualified `panelId`. The callback owns its refresh and should request a render when its visible state changes.
540
757
  - `checkForPiWebUpdates()` forces a fresh update check on the selected machine and refreshes `state.piWebStatus`. It is optional so plugins remain compatible with older PI WEB hosts.
541
- - Only fields documented here and declared in `plugin-api.d.ts` are stable public plugin API. Anything else is experimental: it may become public API later, change shape, or disappear.
758
+ - Only fields documented here and declared by `@jmfederico/pi-web/plugin-api` are stable public browser API. Anything else is experimental: it may become public API later, change shape, or disappear.
542
759
 
543
760
  ### Prompt editor API
544
761
 
@@ -589,7 +806,7 @@ workspacePanels: [
589
806
  </svg>
590
807
  `,
591
808
  order: 100,
592
- visible: ({ workspace }) => workspace.isGitRepo,
809
+ visible: ({ workspace }) => workspace.isMain,
593
810
  render: ({ workspace }) => html`
594
811
  <section class="toolbar"><strong>Info</strong></section>
595
812
  <section class="viewer">
@@ -609,8 +826,10 @@ interface WorkspacePanelContribution {
609
826
  title: string;
610
827
  icon?: TemplateResult;
611
828
  order?: number;
829
+ routeAliases?: string[];
612
830
  visible?: (context: WorkspacePanelContext) => boolean;
613
831
  badge?: (context: WorkspacePanelContext) => string | number | TemplateResult | undefined;
832
+ onInvalidate?: (context: WorkspacePanelContext) => void | Promise<void>;
614
833
  render: (context: WorkspacePanelContext) => TemplateResult;
615
834
  }
616
835
 
@@ -625,6 +844,9 @@ interface WorkspacePanelContext {
625
844
  deleteFile(path: string): Promise<DeleteWorkspaceFileResponse>;
626
845
  moveFile(fromPath: string, toPath: string, options?: MoveWorkspaceFileOptions): Promise<MoveWorkspaceFileResponse>;
627
846
  };
847
+ backend?: {
848
+ request(operation: string, input: JsonValue): Promise<JsonValue>;
849
+ };
628
850
  prompt: PluginPromptEditor;
629
851
  terminal: {
630
852
  open(options?: { terminalId?: string }): void;
@@ -643,9 +865,7 @@ interface WorkspacePanelContext {
643
865
 
644
866
  `icon` is optional and is used in the compact mobile tab bar. Prefer an SVG rendered with the `svg` helper from `PluginActivationContext`; use `currentColor` so PI WEB themes can style it. If `icon` is omitted, mobile tabs fall back to initials from the panel title, or to the full title when initials collide.
645
867
 
646
- `machine`, `workspace`, `files`, `prompt`, `terminal`, and `host` are documented as stable for panel callbacks. The `files` helper supports `readFile`, `listFiles`, `writeFile`, `deleteFile`, and `moveFile` — see [Reading workspace files](#reading-workspace-files), [Listing workspace files](#listing-workspace-files), and [Writing workspace files](#writing-workspace-files). The `prompt` helper supports panel interactions that insert workspace context into the current prompt — see [Prompt editor API](#prompt-editor-api). Use `terminal.open()` to switch to the built-in terminal panel; pass `{ terminalId }` to deep-link to a specific terminal. Call `host.requestRender()` when async plugin-owned state changes should make PI WEB re-evaluate panel callbacks such as `badge`, `visible`, or `render`.
647
-
648
- For compatibility, PI WEB still provides the old `context.openTerminal()` workspace-panel helper at runtime. It is deprecated, intentionally omitted from the public TypeScript declarations, and planned for removal in v2. Existing JavaScript plugins keep working, while typed plugins should migrate to `context.terminal.open()`.
868
+ `machine`, `workspace`, `files`, optional `backend`, `prompt`, `terminal`, and `host` are documented as stable for panel callbacks. The `files` helper supports `readFile`, `listFiles`, `writeFile`, `deleteFile`, and `moveFile` — see [Reading workspace files](#reading-workspace-files), [Listing workspace files](#listing-workspace-files), and [Writing, deleting, and moving workspace files](#writing-deleting-and-moving-workspace-files). A browser entry with a paired active provider uses `backend.request()` instead of constructing API routes — see [Calling paired workspace backends](#calling-paired-workspace-backends). The `prompt` helper supports panel interactions that insert workspace context into the current prompt — see [Prompt editor API](#prompt-editor-api). Use `terminal.open()` to switch to the built-in terminal panel; pass `{ terminalId }` to deep-link to a specific terminal. `routeAliases` is only for migrating former URL tool/view values. Implement `onInvalidate()` to refresh plugin-owned panel data when an action or host refresh calls `refreshWorkspacePanels()`; call `host.requestRender()` when async state changes should make PI WEB re-evaluate `badge`, `visible`, or `render`.
649
869
 
650
870
  Useful workspace and machine shapes:
651
871
 
@@ -657,18 +877,21 @@ interface PluginMachine {
657
877
  }
658
878
 
659
879
  interface Workspace {
660
- id: string;
661
- projectId: string;
662
- path: string;
663
- label: string;
664
- branch?: string;
665
- isMain: boolean;
666
- isGitRepo: boolean;
667
- isGitWorktree: boolean;
880
+ readonly id: string;
881
+ readonly projectId: string;
882
+ readonly path: string;
883
+ readonly label: string;
884
+ readonly isMain: boolean;
885
+ readonly provider?: {
886
+ readonly pluginId: string;
887
+ readonly capabilities: { readonly request: boolean; readonly remove: boolean };
888
+ readonly metadata?: JsonObject;
889
+ };
890
+ readonly removal?: { readonly actionLabel: string; readonly confirmation: string };
668
891
  }
669
892
  ```
670
893
 
671
- `machine.id` is included in panel contexts so plugins can keep caches machine-scoped. Do not infer the selected machine from global browser state.
894
+ `machine.id` is included in panel contexts so plugins can keep caches machine-scoped. Do not infer the selected machine from global browser state. Use the provider-authored `workspace.label` for provider-neutral presentation. `workspace.provider.pluginId` is the stable source id, and provider-published details such as Git status live in `workspace.provider.metadata`, which the server provider fills from browser-public `publicMetadata`. Provider-specific browser code may interpret metadata it owns; PI WEB core does not assign branch semantics to the generic workspace shape. `capabilities.remove` describes only this workspace, not the provider in general. The browser-v1 `isGitRepo`, `isGitWorktree`, and top-level `branch` aliases were removed.
672
895
 
673
896
  Use existing classes such as `toolbar`, `viewer`, `empty`, and `muted` for panel content when possible. Do not assume a panel owns the whole page; keep layout contained.
674
897
 
@@ -716,13 +939,16 @@ interface WorkspaceLabelContext {
716
939
  deleteFile(path: string): Promise<DeleteWorkspaceFileResponse>;
717
940
  moveFile(fromPath: string, toPath: string, options?: MoveWorkspaceFileOptions): Promise<MoveWorkspaceFileResponse>;
718
941
  };
942
+ backend?: {
943
+ request(operation: string, input: JsonValue): Promise<JsonValue>;
944
+ };
719
945
  host: {
720
946
  requestRender(): void;
721
947
  };
722
948
  }
723
949
  ```
724
950
 
725
- `machine`, `workspace`, `files`, and `host` are documented as stable for label callbacks. The `files` helper supports `readFile`, `listFiles`, `writeFile`, `deleteFile`, and `moveFile` — see [Reading workspace files](#reading-workspace-files), [Listing workspace files](#listing-workspace-files), and [Writing workspace files](#writing-workspace-files). Include `machine.id` in any label caches that depend on workspace data. Call `host.requestRender()` when async plugin-owned state changes should make PI WEB re-evaluate label `visible` or `items` callbacks.
951
+ `machine`, `workspace`, `files`, optional `backend`, and `host` are documented as stable for label callbacks. The `files` helper supports `readFile`, `listFiles`, `writeFile`, `deleteFile`, and `moveFile` — see [Reading workspace files](#reading-workspace-files), [Listing workspace files](#listing-workspace-files), and [Writing, deleting, and moving workspace files](#writing-deleting-and-moving-workspace-files). A browser entry with a paired active provider can call `backend.request()` from a label-owned async cache after checking that the optional helper is present. Include `machine.id` in caches that depend on workspace data. Call `host.requestRender()` when async plugin-owned state changes should make PI WEB re-evaluate label `visible` or `items` callbacks.
726
952
 
727
953
  Items are sorted by `order` and then id. Return an empty array to render nothing. Keep callbacks synchronous and lightweight; start async work from the callback, return cached items, then call `host.requestRender()` when the cache changes.
728
954
 
@@ -754,7 +980,7 @@ Use render items when a label contribution needs custom UI, async data, or cachi
754
980
  class MyWorkspaceBadge extends HTMLElement {
755
981
  set workspace(value) {
756
982
  this._workspace = value;
757
- this.textContent = value?.branch === "main" ? "main" : "branch";
983
+ this.textContent = value?.label ?? "workspace";
758
984
  }
759
985
  }
760
986
 
@@ -763,7 +989,7 @@ if (!customElements.get("my-workspace-badge")) {
763
989
  }
764
990
 
765
991
  export default {
766
- apiVersion: 1,
992
+ apiVersion: 2,
767
993
  name: "My Plugin",
768
994
  activate: ({ html }) => ({
769
995
  contributions: {
@@ -782,6 +1008,23 @@ export default {
782
1008
  };
783
1009
  ```
784
1010
 
1011
+ ## Calling paired workspace backends
1012
+
1013
+ Workspace panel and label contexts include an optional JSON-only backend helper. It is present only for a browser entry paired with an active server backend:
1014
+
1015
+ ```js
1016
+ if (context.backend === undefined) throw new Error("Workspace backend unavailable");
1017
+ const result = await context.backend.request("summary", {
1018
+ includeIgnored: false,
1019
+ });
1020
+ ```
1021
+
1022
+ PI WEB binds the request to the browser module's original package id and active backend revision, plus the callback's selected machine, project, and workspace. The host resolves the current workspace owner again before dispatch. The call succeeds only when that same active plugin still owns the workspace and implements `WorkspaceProvider.request()`.
1023
+
1024
+ Operation ids must match `^[a-z][a-z0-9.-]*$` and be at most 128 characters. Inputs and results must contain only finite JSON values; functions, classes, `undefined`, cycles, and non-finite numbers are rejected. Requests, responses, owner resolution, and provider callbacks are size- and time-bounded.
1025
+
1026
+ The same helper works locally and through machine federation. It preserves machine scoping and active frontend/backend revision pairing, so browser plugins must not construct `/api/plugin-backends/...` or `/api/machines/...` URLs themselves. Missing/inactive backends, stale revisions/workspaces, ownership changes/conflicts, unsupported operations, invalid JSON, failures, and timeouts reject the promise with an attributed error.
1027
+
785
1028
  ## Reading workspace files
786
1029
 
787
1030
  Workspace panels and workspace labels can read files through the documented `files` helper. PI WEB binds this helper to the callback's machine and workspace, so it works the same for local and federated machines.
@@ -859,7 +1102,7 @@ workspaceLabels: [
859
1102
  ]
860
1103
  ```
861
1104
 
862
- The file response includes fields such as `path`, `content`, `truncated`, and `binary`. Be careful with sensitive files such as `.env`: plugins are trusted browser code, and file contents are exposed to the plugin.
1105
+ The file response includes fields such as `path`, `content`, `truncated`, and `binary`. Be careful with sensitive files such as `.env`: browser entries are trusted code, and file contents are exposed to the plugin.
863
1106
 
864
1107
  ## Listing workspace files
865
1108
 
@@ -975,7 +1218,7 @@ After any mutation (`writeFile`, `deleteFile`, or `moveFile`), the File Explorer
975
1218
 
976
1219
  ### Security
977
1220
 
978
- Plugins are trusted browser code. File writes go through the same path safety validation as reads — paths are resolved and checked to stay inside the workspace root.
1221
+ Browser plugin entries are trusted code. File writes go through the same path safety validation as reads — paths are resolved and checked to stay inside the workspace root.
979
1222
 
980
1223
  ## Running workspace terminal commands
981
1224
 
@@ -996,9 +1239,9 @@ Review command strings carefully. They are trusted shell commands executed in th
996
1239
 
997
1240
  ## Private and experimental PI WEB APIs
998
1241
 
999
- PI WEB's `/api/...` HTTP and WebSocket routes and runtime-only fields are private implementation details. They exist because plugins are trusted browser code, and because some capabilities may be evaluated there before they are designed as stable helpers.
1242
+ PI WEB's `/api/...` HTTP and WebSocket routes, runtime-only browser fields, source files, Fastify instance, and internal services are private implementation details. They are outside the supported browser-v2 and server-v1 package contracts and may change or disappear.
1000
1243
 
1001
- That is allowed, but outside the v1 compatibility promise: URLs, response shapes, runtime fields, and machine-federation routing may graduate into stable APIs, change shape, or disappear. The stable public plugin API is only the documented helpers and declarations in `plugin-api.d.ts`. Prefer those whenever they exist; if you rely on private surfaces, keep the dependency local to the plugin and expect to revisit it after PI WEB upgrades.
1244
+ The stable browser API is the documented helpers and the type-only `@jmfederico/pi-web/plugin-api` export; the stable server API is the narrow type-only `@jmfederico/pi-web/server-plugin-api` export. Use `context.backend.request()` for paired browser/server work. If browser code intentionally relies on another private surface, keep that dependency local and expect to revisit it after PI WEB upgrades. A server plugin must not import PI WEB source internals or private `dist/**` declarations.
1002
1245
 
1003
1246
  ## Async data and caching
1004
1247
 
@@ -1014,21 +1257,21 @@ PI WEB does not provide a plugin cache/invalidation framework. Keep host callbac
1014
1257
 
1015
1258
  If you are an AI agent building or editing a PI WEB plugin, follow this checklist:
1016
1259
 
1017
- 1. Create or update a plugin folder with `package.json` and a JavaScript module such as `pi-web-plugin.js`.
1018
- 2. Use the single supported package metadata shape: `piWeb.plugins` array with `{ id, module, machineSpecific? }` entries.
1019
- 3. Default-export `{ apiVersion: 1, name, activate }` from the module.
1020
- 4. Return `{ contributions: { actions, workspacePanels, workspaceLabels } }` from `activate()`.
1021
- 5. Use ids matching `^[a-z][a-z0-9.-]*$`.
1022
- 6. Use the activation context's `html` function for Lit templates.
1023
- 7. Keep `activate()` synchronous and cheap; return contribution definitions only.
1024
- 8. Add actions for command-palette operations.
1025
- 9. Add workspace panels for larger workspace UI.
1026
- 10. Add workspace labels for compact inline metadata.
1027
- 11. Return arrays from workspace label `items()`; return an empty array to render nothing.
1028
- 12. Use documented context helpers first: `files`, `terminal`, `host.requestRender`, `workspace`, `machine`, `state.selectedMachine`, `state.selectedWorkspace`, `state.selectedSession`, `state.piWebStatus`, and `prompt`.
1029
- 13. Do not fetch PI WEB `/api/...` endpoints directly unless you intentionally accept private API churn; prefer documented helpers.
1030
- 14. Treat plugins as trusted code and avoid reading or displaying secrets unless intentional.
1031
- 15. After local edits, tell the user to hard reload the browser and check the console for plugin errors.
1260
+ 1. Create or update a package folder with `package.json` and at least one built JavaScript entry. Declare `"type": "module"` when a `.js` server entry is present, or emit it as `.mjs`.
1261
+ 2. Use `piWeb.plugins` entries shaped as `{ id, browserRoot?, module?, serverModule?, machineSpecific? }`; declare at least one module, give every browser entry a safe root containing its module, and use non-reserved ids matching `^[a-z][a-z0-9.-]*$`.
1262
+ 3. Import browser types only from `@jmfederico/pi-web/plugin-api` and server types only from `@jmfederico/pi-web/server-plugin-api`, always with `import type`; do not use private subpaths or source internals.
1263
+ 4. Default-export `{ apiVersion: 2, name, activate }` from a browser entry and `{ apiVersion: 1, name, activate }` from a server entry.
1264
+ 5. In a browser entry, use source `pluginId` for ownership and `runtimePluginId` for qualified contribution references; return contributions synchronously and use the activation context's `html`/`svg` tags.
1265
+ 6. Add actions for command-palette operations, panels for larger workspace UI, and labels for compact inline metadata.
1266
+ 7. Return arrays synchronously from workspace label `items()`; return an empty array to render nothing.
1267
+ 8. Use documented browser helpers first: `files`, `terminal`, `backend`, `host.requestRender`, `workspace`, `machine`, `state`, and `prompt`. Never construct PI WEB backend, federation, or absolute asset URLs.
1268
+ 9. In a server entry, return only the demonstrated lifecycle callbacks and at most one `workspaceProvider`; treat every supplied `AbortSignal` as operation-scoped and forward it to bounded work.
1269
+ 10. Make provider claims conservative. Return exactly one main workspace, stable keys, absolute accessible directories, JSON data/metadata, and optional request/removal capabilities.
1270
+ 11. Keep backend operations JSON-only, bounded, and provider-owned. Put no secrets in `publicMetadata`, browser responses, removal wording, or diagnostics.
1271
+ 12. Keep the installed package at or below 4,096 entries and 16 MiB, and keep every browser-public file inside a narrow `browserRoot`.
1272
+ 13. Treat both entries as trusted code. A server module shares sessiond's process and user permissions.
1273
+ 14. For browser-only edits, reload or hard-reload the page. For a server-backed edit, restart sessiond and then reload the page.
1274
+ 15. Warn that restarting `pi-web-sessiond.service` may interrupt active sessions/runtime ownership.
1032
1275
 
1033
1276
  ## Troubleshooting
1034
1277
 
@@ -1046,13 +1289,17 @@ curl http://127.0.0.1:8504/pi-web-plugins/my-plugin/pi-web-plugin.js
1046
1289
 
1047
1290
  Common issues:
1048
1291
 
1049
- - invalid plugin id or contribution id;
1050
- - missing default export;
1051
- - missing `apiVersion: 1`, `name`, or `activate` function;
1052
- - missing `package.json` or incorrect `piWeb.plugins` metadata;
1292
+ - invalid plugin or contribution id;
1293
+ - missing default export, browser `apiVersion: 2` or server `apiVersion: 1`, non-empty `name`, or `activate` function;
1294
+ - missing `package.json`, incorrect `piWeb.plugins` metadata, neither module declared, missing/unsafe `browserRoot`, a browser module outside its root, a `.js` server entry without `"type": "module"`, or a dual entry explicitly marked `machineSpecific: false`;
1053
1295
  - legacy shortcuts such as `piWeb.plugin`, string plugin entries, or no-`package.json` fallback;
1054
- - duplicate plugin ids; later duplicates are skipped rather than renamed;
1055
- - entry module path points outside the plugin root or file does not exist;
1056
- - browser cache not refreshed after editing;
1057
- - plugin directory is not under `~/.pi-web/plugins` or symlinked there;
1058
- - plugin throws during module import, `activate()`, `visible()`, `enabled()`, `items()`, or `render()`; check the browser console.
1296
+ - duplicate plugin ids; records are diagnosed, skipped rather than merged, and never renamed;
1297
+ - entry/root path is unsafe, points outside the package, enters `.git`/`node_modules`, does not exist, or the package exceeds 4,096 entries/16 MiB;
1298
+ - package is not installed through Pi or under `$PI_WEB_DATA_DIR/plugins` (`~/.pi-web/plugins` by default);
1299
+ - browser import/activation/render failure; check the browser console;
1300
+ - server state is failed, incompatible, unhealthy, disabled, missing, stale, or conflicted; check **Settings → PI WEB plugins** and `pi-web logs` on the target machine;
1301
+ - a server-backed browser entry is absent because sessiond is unavailable or its active source/settings/revisions do not match desired package state; restart sessiond, then reload the tab;
1302
+ - a federated target lacks the lifecycle/backend capability; update and restart PI WEB on that target instead of falling back to the gateway;
1303
+ - recovery is needed before plugin discovery/import; use `pi-web plugins safe-start show`, offline disable, or one of the documented safe-start levels.
1304
+
1305
+ A manual restart of `pi-web-sessiond.service` may interrupt active sessions/runtime ownership. Inspect active work first and do not assume a web/UI restart is sufficient.