@chainingintention/pi-web-cn 1.202610.1 → 1.202610.3
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.
- package/README.md +60 -106
- package/dist/.plugins-ready +1 -0
- package/dist/cli.js +161 -45
- package/dist/cli.js.map +1 -1
- package/dist/client/assets/index-CFhaGb5m.js +4357 -0
- package/dist/client/assets/vendor-editor-core-YWog6mAR.js +10 -0
- package/dist/client/assets/vendor-editor-languages-DOCw3vc9.js +28 -0
- package/dist/client/index.html +5 -5
- package/dist/config.js +30 -6
- package/dist/config.js.map +1 -1
- package/dist/docker/piWebDockerCommandPlan.js +13 -4
- package/dist/docker/piWebDockerCommandPlan.js.map +1 -1
- package/dist/nativeServices/installedServiceDefinitions.js +23 -10
- package/dist/nativeServices/installedServiceDefinitions.js.map +1 -1
- package/dist/nativeServices/serviceAction.js +78 -20
- package/dist/nativeServices/serviceAction.js.map +1 -1
- package/dist/nativeServices/serviceDoctor.js +339 -67
- package/dist/nativeServices/serviceDoctor.js.map +1 -1
- package/dist/nativeServices/servicePlan.js +2 -2
- package/dist/nativeServices/servicePlan.js.map +1 -1
- package/dist/pi-packages/captains-log/README.md +11 -0
- package/dist/pi-packages/captains-log/dist/browser/channelProtocol.js +29 -0
- package/dist/pi-packages/captains-log/dist/browser/index.js +146 -0
- package/dist/pi-packages/captains-log/dist/browser/markdown.js +67 -0
- package/dist/pi-packages/captains-log/dist/browser/panel.js +151 -0
- package/dist/pi-packages/captains-log/dist/browser/protocol.js +26 -0
- package/dist/pi-packages/captains-log/dist/companion.js +126 -0
- package/dist/pi-packages/captains-log/dist/roundtrip.js +62 -0
- package/dist/pi-packages/captains-log/dist/server.js +210 -0
- package/dist/pi-packages/captains-log/dist/store.js +75 -0
- package/dist/pi-packages/captains-log/docs/usage.md +29 -0
- package/dist/pi-packages/captains-log/package.json +35 -0
- package/dist/pi-packages/captains-log/tsconfig.json +21 -0
- package/dist/pi-packages/captains-log/vite.config.mjs +28 -0
- package/dist/pi-packages/relays/pi-web-plugin.js +9 -9
- package/dist/pi-packages/relays/prompts/relay.md +1 -1
- package/dist/pi-packages/relays/relaysPanelElement.js +8 -8
- package/dist/pi-packages/relays/skills/relay-runner/SKILL.md +21 -13
- package/dist/pi-web-plugins/files/browser/assets/files-icon-DZObYhxb.svg +3 -0
- package/dist/pi-web-plugins/files/browser/pi-web-plugin.js +456 -0
- package/dist/pi-web-plugins/files/package.json +15 -0
- package/dist/pi-web-plugins/git/browser/git-panel.js +55 -32
- package/dist/pi-web-plugins/git/browser/pi-web-plugin.js +2 -2
- package/dist/pi-web-plugins/git/git-backend.js +19 -26
- package/dist/pi-web-plugins/git/gitStatusCache.js +48 -0
- package/dist/pi-web-plugins/git/package.json +1 -0
- package/dist/pi-web-plugins/git/server-plugin.js +11 -10
- package/dist/pi-web-plugins/info/infoInternals.js +4 -1
- package/dist/pi-web-plugins/info/package.json +1 -1
- package/dist/pi-web-plugins/info/pi-web-plugin.js +8 -8
- package/dist/pi-web-plugins/mermaid/browser/mermaid-engine.js +3590 -0
- package/dist/pi-web-plugins/mermaid/browser/pi-web-plugin.js +6 -0
- package/dist/pi-web-plugins/mermaid/package.json +13 -0
- package/dist/pi-web-plugins/terminal/browser/pi-web-plugin.js +210 -0
- package/dist/pi-web-plugins/terminal/package.json +16 -0
- package/dist/pi-web-plugins/terminal/server-plugin.js +365 -0
- package/dist/pi-web-plugins/terminal/terminalService.js +435 -0
- package/dist/pi-web-plugins/updates/package.json +1 -1
- package/dist/pi-web-plugins/updates/pi-web-plugin.js +69 -68
- package/dist/pi-web-plugins/workspace-tasks/package.json +1 -1
- package/dist/pi-web-plugins/workspace-tasks/pi-web-plugin.js +3 -3
- package/dist/piWebVersionReport.js +47 -24
- package/dist/piWebVersionReport.js.map +1 -1
- package/dist/plugin-api.d.ts +260 -25
- package/dist/plugin-api.js +1 -0
- package/dist/pluginRecoveryCli.js +3 -2
- package/dist/pluginRecoveryCli.js.map +1 -1
- package/dist/server/activity/workspaceActivityService.js +5 -5
- package/dist/server/activity/workspaceActivityService.js.map +1 -1
- package/dist/server/app.js +71 -44
- package/dist/server/app.js.map +1 -1
- package/dist/server/audit/managementAuditStore.js +1 -1
- package/dist/server/browserMessageProjection.js +0 -2
- package/dist/server/browserMessageProjection.js.map +1 -1
- package/dist/server/configRoutes.js +1 -2
- package/dist/server/configRoutes.js.map +1 -1
- package/dist/server/knownPiPackages.js +12 -0
- package/dist/server/knownPiPackages.js.map +1 -0
- package/dist/server/machines/machineClient.js +2 -2
- package/dist/server/machines/machineClient.js.map +1 -1
- package/dist/server/machines/machinePluginProxyRoutes.js +120 -21
- package/dist/server/machines/machinePluginProxyRoutes.js.map +1 -1
- package/dist/server/machines/machineProxyRoutes.js +80 -22
- package/dist/server/machines/machineProxyRoutes.js.map +1 -1
- package/dist/server/machines/machineService.js +22 -0
- package/dist/server/machines/machineService.js.map +1 -1
- package/dist/server/managementEmbed.js +1 -1
- package/dist/server/managementEmbed.js.map +1 -1
- package/dist/server/managementPrivileges.js +7 -1
- package/dist/server/managementPrivileges.js.map +1 -1
- package/dist/server/managementTerminalProxyRoutes.js +124 -0
- package/dist/server/managementTerminalProxyRoutes.js.map +1 -0
- package/dist/server/normalAuth.js +5 -1
- package/dist/server/normalAuth.js.map +1 -1
- package/dist/server/notices/serverNoticeStore.js +50 -6
- package/dist/server/notices/serverNoticeStore.js.map +1 -1
- package/dist/server/piPackageService.js +5 -5
- package/dist/server/piPackageService.js.map +1 -1
- package/dist/server/piWebPluginCatalog.js +211 -34
- package/dist/server/piWebPluginCatalog.js.map +1 -1
- package/dist/server/piWebPluginLifecycle.js +29 -3
- package/dist/server/piWebPluginLifecycle.js.map +1 -1
- package/dist/server/piWebPluginService.js +176 -291
- package/dist/server/piWebPluginService.js.map +1 -1
- package/dist/server/piWebStatus.js +45 -55
- package/dist/server/piWebStatus.js.map +1 -1
- package/dist/server/pluginCallbackDrain.js +35 -0
- package/dist/server/pluginCallbackDrain.js.map +1 -0
- package/dist/server/plugins/pluginBackendChannelProxyAdmission.js +84 -0
- package/dist/server/plugins/pluginBackendChannelProxyAdmission.js.map +1 -0
- package/dist/server/plugins/pluginBackendChannelProxyCoordinator.js +234 -0
- package/dist/server/plugins/pluginBackendChannelProxyCoordinator.js.map +1 -0
- package/dist/server/plugins/pluginBackendChannelProxyRoutes.js +63 -0
- package/dist/server/plugins/pluginBackendChannelProxyRoutes.js.map +1 -0
- package/dist/server/plugins/pluginBackendProxyRoutes.js +7 -4
- package/dist/server/plugins/pluginBackendProxyRoutes.js.map +1 -1
- package/dist/server/plugins/pluginBackendRegistry.js +773 -0
- package/dist/server/plugins/pluginBackendRegistry.js.map +1 -0
- package/dist/server/plugins/serverPluginPiSessionEventsCapability.js +34 -0
- package/dist/server/plugins/serverPluginPiSessionEventsCapability.js.map +1 -0
- package/dist/server/plugins/serverPluginPiSessionsCapability.js +185 -0
- package/dist/server/plugins/serverPluginPiSessionsCapability.js.map +1 -0
- package/dist/server/plugins/serverPluginRuntime.js +1049 -107
- package/dist/server/plugins/serverPluginRuntime.js.map +1 -1
- package/dist/server/plugins/serverPluginWorkspacesCapability.js +114 -0
- package/dist/server/plugins/serverPluginWorkspacesCapability.js.map +1 -0
- package/dist/server/projectTrustRoutes.js +86 -0
- package/dist/server/projectTrustRoutes.js.map +1 -0
- package/dist/server/projects/projectLifecycleService.js +84 -0
- package/dist/server/projects/projectLifecycleService.js.map +1 -0
- package/dist/server/projects/projectService.js +2 -0
- package/dist/server/projects/projectService.js.map +1 -1
- package/dist/server/realtime/sessionEventHub.js +35 -41
- package/dist/server/realtime/sessionEventHub.js.map +1 -1
- package/dist/server/sessiond/agentHttpDispatcher.js +108 -0
- package/dist/server/sessiond/agentHttpDispatcher.js.map +1 -0
- package/dist/server/sessiond/pluginBackendChannelRoutes.js +397 -0
- package/dist/server/sessiond/pluginBackendChannelRoutes.js.map +1 -0
- package/dist/server/sessiond/pluginBackendRoutes.js +19 -9
- package/dist/server/sessiond/pluginBackendRoutes.js.map +1 -1
- package/dist/server/sessiond/projectMutationRoutes.js +38 -0
- package/dist/server/sessiond/projectMutationRoutes.js.map +1 -0
- package/dist/server/sessiond/sessionDaemonShutdown.js +36 -0
- package/dist/server/sessiond/sessionDaemonShutdown.js.map +1 -0
- package/dist/server/sessiond/sessionDaemonStartup.js +30 -4
- package/dist/server/sessiond/sessionDaemonStartup.js.map +1 -1
- package/dist/server/sessiond/sessionProxyRoutes.js +47 -15
- package/dist/server/sessiond/sessionProxyRoutes.js.map +1 -1
- package/dist/server/sessiond/sessionServiceDependencies.js +4 -0
- package/dist/server/sessiond/sessionServiceDependencies.js.map +1 -1
- package/dist/server/sessiond/sessiondStateOwnership.js +174 -39
- package/dist/server/sessiond/sessiondStateOwnership.js.map +1 -1
- package/dist/server/sessiond/workspaceRemovalRoutes.js +1 -1
- package/dist/server/sessiond/workspaceRemovalRoutes.js.map +1 -1
- package/dist/server/sessiond.js +226 -56
- package/dist/server/sessiond.js.map +1 -1
- package/dist/server/sessions/askUserTool.js +0 -3
- package/dist/server/sessions/askUserTool.js.map +1 -1
- package/dist/server/sessions/attachmentService.js +0 -1
- package/dist/server/sessions/attachmentService.js.map +1 -1
- package/dist/server/sessions/authService.js +8 -1
- package/dist/server/sessions/authService.js.map +1 -1
- package/dist/server/sessions/builtinCommands.js +2 -2
- package/dist/server/sessions/builtinCommands.js.map +1 -1
- package/dist/server/sessions/clientSessionPreview.js +14 -0
- package/dist/server/sessions/clientSessionPreview.js.map +1 -0
- package/dist/server/sessions/dockerEnvironmentFacts.js +82 -9
- package/dist/server/sessions/dockerEnvironmentFacts.js.map +1 -1
- package/dist/server/sessions/managementAgentTools.js +11 -6
- package/dist/server/sessions/managementAgentTools.js.map +1 -1
- package/dist/server/sessions/managementPermissionSystem.js +16 -4
- package/dist/server/sessions/managementPermissionSystem.js.map +1 -1
- package/dist/server/sessions/messagePaging.js +2 -2
- package/dist/server/sessions/messagePaging.js.map +1 -1
- package/dist/server/sessions/modelCatalogRefresher.js +4 -3
- package/dist/server/sessions/modelCatalogRefresher.js.map +1 -1
- package/dist/server/sessions/oauthLoginFlowService.js +2 -5
- package/dist/server/sessions/oauthLoginFlowService.js.map +1 -1
- package/dist/server/sessions/pendingAskStore.js +0 -3
- package/dist/server/sessions/pendingAskStore.js.map +1 -1
- package/dist/server/sessions/piSessionEventConnections.js +65 -0
- package/dist/server/sessions/piSessionEventConnections.js.map +1 -0
- package/dist/server/sessions/piSessionManagerGateway.js +56 -3
- package/dist/server/sessions/piSessionManagerGateway.js.map +1 -1
- package/dist/server/sessions/piSessionService.js +774 -448
- package/dist/server/sessions/piSessionService.js.map +1 -1
- package/dist/server/sessions/projectAuthService.js +29 -2
- package/dist/server/sessions/projectAuthService.js.map +1 -1
- package/dist/server/sessions/projectSettingsScope.js +12 -4
- package/dist/server/sessions/projectSettingsScope.js.map +1 -1
- package/dist/server/sessions/projectTrust.js +119 -0
- package/dist/server/sessions/projectTrust.js.map +1 -0
- package/dist/server/sessions/sessionActivityMarker.js +105 -0
- package/dist/server/sessions/sessionActivityMarker.js.map +1 -0
- package/dist/server/sessions/sessionArchiveMapping.js +2 -8
- package/dist/server/sessions/sessionArchiveMapping.js.map +1 -1
- package/dist/server/sessions/sessionCommandService.js +12 -10
- package/dist/server/sessions/sessionCommandService.js.map +1 -1
- package/dist/server/sessions/sessionEnvironmentFacts.js +5 -4
- package/dist/server/sessions/sessionEnvironmentFacts.js.map +1 -1
- package/dist/server/sessions/sessionModelScope.js +42 -5
- package/dist/server/sessions/sessionModelScope.js.map +1 -1
- package/dist/server/sessions/sessionNameGenerator.js +6 -6
- package/dist/server/sessions/sessionNameGenerator.js.map +1 -1
- package/dist/server/sessions/sessionRoutes.js +63 -15
- package/dist/server/sessions/sessionRoutes.js.map +1 -1
- package/dist/server/sessions/sessionTreeProjection.js +29 -29
- package/dist/server/sessions/sessionTreeProjection.js.map +1 -1
- package/dist/server/sessions/sessionUiEvents.js +6 -7
- package/dist/server/sessions/sessionUiEvents.js.map +1 -1
- package/dist/server/sessions/sessionUnreadStore.js +26 -1
- package/dist/server/sessions/sessionUnreadStore.js.map +1 -1
- package/dist/server/sessions/spawnSessionTool.js +3 -3
- package/dist/server/sessions/spawnSessionTool.js.map +1 -1
- package/dist/server/sessions/spawnSubsessionTool.js +5 -5
- package/dist/server/sessions/spawnSubsessionTool.js.map +1 -1
- package/dist/server/sessions/spawnTargetResolver.js +1 -1
- package/dist/server/sessions/transcriptMessages.js +54 -0
- package/dist/server/sessions/transcriptMessages.js.map +1 -0
- package/dist/server/status/machineStatusService.js +3 -1
- package/dist/server/status/machineStatusService.js.map +1 -1
- package/dist/server/terminals/{terminalService.js → managementCommandRunService.js} +79 -107
- package/dist/server/terminals/managementCommandRunService.js.map +1 -0
- package/dist/server/terminals/managementTerminalRoutes.js +91 -0
- package/dist/server/terminals/managementTerminalRoutes.js.map +1 -0
- package/dist/server/terminals/requiredTerminalService.js +103 -0
- package/dist/server/terminals/requiredTerminalService.js.map +1 -0
- package/dist/server/webSocketBridge.js +339 -0
- package/dist/server/webSocketBridge.js.map +1 -1
- package/dist/server/workbench/gatewayIntegration.js +4 -1
- package/dist/server/workbench/gatewayIntegration.js.map +1 -1
- package/dist/server/workspaceExplorerRoutes.js +13 -12
- package/dist/server/workspaceExplorerRoutes.js.map +1 -1
- package/dist/server/workspaces/fileContentService.js +9 -7
- package/dist/server/workspaces/fileContentService.js.map +1 -1
- package/dist/server/workspaces/fileOperationService.js +4 -3
- package/dist/server/workspaces/fileOperationService.js.map +1 -1
- package/dist/server/workspaces/projectWorkspaceCwds.js +0 -5
- package/dist/server/workspaces/projectWorkspaceCwds.js.map +1 -1
- package/dist/server/workspaces/sessionDaemonWorkspaceCatalog.js +36 -12
- package/dist/server/workspaces/sessionDaemonWorkspaceCatalog.js.map +1 -1
- package/dist/server/workspaces/workspaceCatalog.js +6 -4
- package/dist/server/workspaces/workspaceCatalog.js.map +1 -1
- package/dist/server/workspaces/workspaceDeletionRoutes.js +5 -57
- package/dist/server/workspaces/workspaceDeletionRoutes.js.map +1 -1
- package/dist/server/workspaces/workspaceProviderRegistry.js +75 -24
- package/dist/server/workspaces/workspaceProviderRegistry.js.map +1 -1
- package/dist/server/workspaces/workspaceRemovalService.js +25 -3
- package/dist/server/workspaces/workspaceRemovalService.js.map +1 -1
- package/dist/server-plugin-api.d.ts +274 -44
- package/dist/server-plugin-api.js +319 -2
- package/dist/server-plugin-api.js.map +1 -1
- package/dist/serverPluginRecovery.js +4 -0
- package/dist/serverPluginRecovery.js.map +1 -1
- package/dist/sessiond/activeAgentProfile.js +27 -2
- package/dist/sessiond/activeAgentProfile.js.map +1 -1
- package/dist/sessiond/config.js +4 -3
- package/dist/sessiond/config.js.map +1 -1
- package/dist/sessiond/sessionDaemonClient.js +29 -8
- package/dist/sessiond/sessionDaemonClient.js.map +1 -1
- package/dist/shared/activeAgentProfile.js +2 -34
- package/dist/shared/activeAgentProfile.js.map +1 -1
- package/dist/shared/activity.js +0 -3
- package/dist/shared/activity.js.map +1 -1
- package/dist/shared/apiTypes.js +7 -2
- package/dist/shared/apiTypes.js.map +1 -1
- package/dist/shared/capabilities.js +5 -0
- package/dist/shared/capabilities.js.map +1 -1
- package/dist/shared/federatedRoutes.js +49 -9
- package/dist/shared/federatedRoutes.js.map +1 -1
- package/dist/shared/machinePluginIds.js +30 -7
- package/dist/shared/machinePluginIds.js.map +1 -1
- package/dist/shared/machineStatus.js +35 -1
- package/dist/shared/machineStatus.js.map +1 -1
- package/dist/shared/piWebStatusParsing.js +29 -0
- package/dist/shared/piWebStatusParsing.js.map +1 -1
- package/dist/shared/pluginApiTypes.d.ts +24 -9
- package/dist/shared/pluginApiTypes.js +2 -0
- package/dist/shared/pluginApiTypes.js.map +1 -0
- package/dist/shared/pluginBackendProtocol.js +163 -2
- package/dist/shared/pluginBackendProtocol.js.map +1 -1
- package/dist/shared/pluginIds.js +10 -1
- package/dist/shared/pluginIds.js.map +1 -1
- package/dist/shared/requiredTerminalPlugin.js +6 -0
- package/dist/shared/requiredTerminalPlugin.js.map +1 -0
- package/dist/shared/serverNoticeContract.js +88 -0
- package/dist/shared/serverNoticeContract.js.map +1 -0
- package/dist/shared/sessionDefaults.js +41 -0
- package/dist/shared/sessionDefaults.js.map +1 -0
- package/dist/shared/workspaceFiles.js.map +1 -1
- package/docs/config.md +270 -323
- package/docs/plugins.md +171 -956
- package/examples/session-bridge-plugin/README.md +20 -0
- package/examples/session-bridge-plugin/docs/usage.md +54 -0
- package/examples/session-bridge-plugin/package.json +26 -0
- package/examples/session-bridge-plugin/src/browser/index.ts +87 -0
- package/examples/session-bridge-plugin/src/browser/protocol.ts +24 -0
- package/examples/session-bridge-plugin/src/companion.ts +65 -0
- package/examples/session-bridge-plugin/src/reviewRun.ts +39 -0
- package/examples/session-bridge-plugin/src/server.ts +85 -0
- package/examples/session-bridge-plugin/src/store.ts +80 -0
- package/examples/session-bridge-plugin/tsconfig.json +21 -0
- package/examples/workspace-provider-plugin/README.md +39 -0
- package/examples/workspace-provider-plugin/package.json +25 -0
- package/examples/workspace-provider-plugin/src/browser/index.ts +69 -0
- package/examples/workspace-provider-plugin/src/server.ts +68 -0
- package/examples/workspace-provider-plugin/tsconfig.json +21 -0
- package/package.json +22 -13
- package/skills/README.md +27 -2
- package/skills/relay-runner/SKILL.md +21 -13
- package/dist/client/assets/CodeViewer-CZHnKRwQ.js +0 -4
- package/dist/client/assets/TerminalPanel-B_EaRPHY.js +0 -187
- package/dist/client/assets/index-Bv1v-Jz7.js +0 -4717
- package/dist/client/assets/vendor-editor-core-vUi74DnD.js +0 -12
- package/dist/client/assets/vendor-editor-languages-DoaXUodB.js +0 -46
- package/dist/client/assets/vendor-editor-legacy-CYBnW6ZU.js +0 -1
- package/dist/client/assets/vendor-terminal-BrP-ENHg.css +0 -1
- package/dist/client/assets/vendor-terminal-D8k4UKM2.js +0 -35
- package/dist/server/git/gitService.js +0 -316
- package/dist/server/git/gitService.js.map +0 -1
- package/dist/server/gitRoutes.js +0 -23
- package/dist/server/gitRoutes.js.map +0 -1
- package/dist/server/terminalProxyRoutes.js +0 -181
- package/dist/server/terminalProxyRoutes.js.map +0 -1
- package/dist/server/terminals/terminalRoutes.js +0 -164
- package/dist/server/terminals/terminalRoutes.js.map +0 -1
- package/dist/server/terminals/terminalService.js.map +0 -1
- package/dist/server/terminals/terminalSize.js +0 -17
- package/dist/server/terminals/terminalSize.js.map +0 -1
- package/dist/server/workspaces/gitWorktreeDiscovery.js +0 -43
- package/dist/server/workspaces/gitWorktreeDiscovery.js.map +0 -1
- package/dist/server/workspaces/workspaceService.js +0 -52
- package/dist/server/workspaces/workspaceService.js.map +0 -1
package/docs/plugins.md
CHANGED
|
@@ -1,1062 +1,277 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 插件与 Pi 包
|
|
2
2
|
|
|
3
|
-
PI WEB
|
|
3
|
+
使用工作区工具、快捷操作和集成定制 PI WEB。可以安装现成的包,也可以让代理为具体工作流创建插件,无需修改 PI WEB 本身。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
本指南说明可实现的功能和使用方式;实现时请查阅[公开契约与示例](#agent-development),不要把本页作为第二份 API 声明。
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- add compact workspace-label items in the workspace list, panel header, and status bar;
|
|
10
|
-
- call browser APIs and documented PI WEB plugin context helpers;
|
|
11
|
-
- read workspace files and start workspace terminal commands through documented helpers;
|
|
12
|
-
- serve their own static assets from the plugin directory.
|
|
7
|
+
<a id="what-can-be-built"></a>
|
|
8
|
+
## 可实现的功能
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
| 目标 | 插件功能 |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| 展示项目健康状态、服务链接、环境信息 | 工作区标签与面板 |
|
|
13
|
+
| 添加仪表盘、文件查看器或项目工具 | 工作区面板、文件帮助方法与浏览器 UI |
|
|
14
|
+
| 方便查找常用操作 | 操作面板命令与快捷键 |
|
|
15
|
+
| 运行构建、测试或开发服务器 | 工作区终端命令 |
|
|
16
|
+
| 定制外观 | 主题及明暗主题组合 |
|
|
17
|
+
| 在聊天和文件中预览图表、文本格式 | 浏览器内容渲染器 |
|
|
18
|
+
| 读取或修改工作区文件 | 列出、读取、写入、移动、删除及上传文件 |
|
|
19
|
+
| 显示后端实时结果 | 浏览器入口与服务端入口之间的请求或流式通道 |
|
|
20
|
+
| 保存插件自己的结果和偏好 | 持久化服务端插件目录 |
|
|
21
|
+
| 发起 Pi 对话或与 Pi 扩展协作 | 宿主会话能力与会话内消息 |
|
|
22
|
+
| 使用其他系统替代 Git 工作区发现 | 工作区提供器 |
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
面板可支持直达链接和浏览器历史,并在文件变化或代理工作完成后刷新。文件和终端帮助方法始终针对面板所属机器与工作区,包括远端机器。
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
例如,可以请求代理创建“运行项目检查并显示结果的面板”“链接工作区预览部署的徽标”或“启动审查会话并保存结论的工具”。
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
<a id="pi-packages-extensions-and-plugins"></a>
|
|
29
|
+
## Pi 包、扩展与插件
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
- **Pi 包**是可安装的分发包,可以包含扩展、技能、提示词模板、主题和 PI WEB 插件。
|
|
32
|
+
- **Pi 扩展**定制代理的工具、命令、钩子、模型提供器及会话行为。
|
|
33
|
+
- **PI WEB 插件**定制 Web 应用及工作区集成。
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
一个包可包含上述三种定制。安装包与启用 PI WEB 插件是独立操作;禁用插件不会移除包里的 Pi 扩展、技能或提示词。
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
代理行为放在 Pi 扩展中,Web UI 放在 PI WEB 插件中。需要两者协作时一起发布,通过已托管会话的连接通信。
|
|
35
38
|
|
|
36
|
-
-
|
|
37
|
-
|
|
38
|
-
- **浏览器刷新后可恢复,最先提交的回答生效。** 浏览器刷新后会根据会话状态重新显示打开的对话框。同一会话打开多个标签页时,最先提交的回答会结束对话框,其他标签页随后显示结束状态。
|
|
39
|
-
- **结束状态卡片会保留到用户关闭。** 已回答或已关闭的对话框会在会话记录中保留结果卡片。回答只会传给扩展,因此该卡片是这次交互唯一的可见记录。卡片属于浏览器本地状态:只有见过对话框打开的浏览器会显示它,切换会话或刷新页面后会清除。
|
|
40
|
-
- **超时。** 扩展自身的 `timeout` 仍然生效,守护进程还提供 `extensionDialogsTimeoutMs` 安全超时(默认 5 分钟,设为 `0` 时永久等待;见[扩展对话框](https://pi-web.dev/config#extension-dialogs))。最终期限取两者中较早的时间。没有回答就关闭的对话框会返回对应类型的取消值:确认框为 `false`,选择框和输入框为 `undefined`。
|
|
41
|
-
- **中止和运行时替换。** 中止当前运行时,本轮运行中打开的对话框会立即以取消值结束。替换会话运行时(例如 `/reload` 或销毁会话)也会结束所有仍打开的对话框;新运行时的钩子可以重新打开对话框。扩展传入的 `AbortSignal` 同样有效,中止信号会关闭对话框并返回取消值。
|
|
42
|
-
- **其他 UI 能力仍为空实现。** 除这三种对话框外,PI WEB 尚未实现 `ExtensionUIContext` 的其他方法(组件、状态、编辑器和 `custom`)。即使 `hasUI` 为 `true`,也不能仅凭它判断这些能力可用。
|
|
39
|
+
<a id="how-plugins-work"></a>
|
|
40
|
+
## 插件如何运行
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
包可以声明浏览器入口、服务端入口或双入口:
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
- **浏览器入口**贡献操作、面板、标签、主题与内容渲染器,使用宿主帮助方法访问文件、终端及提示词编辑器。
|
|
45
|
+
- **服务端入口**运行在会话守护进程中,可为浏览器入口服务、存储插件数据、使用宿主能力或提供工作区。
|
|
46
|
+
- **包内对等入口**连接同一插件的浏览器与服务端。宿主解析机器和工作区;插件不必拥有该工作区才能为其服务。
|
|
47
|
+
- **能力**声明所需的宿主或插件功能。启动前必须满足指定版本的依赖。
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
在 `activate()` 中声明贡献,在 `start()` 中初始化依赖支持的工作,在 `dispose()` 中释放资源。长时间工作遵循 `lifetimeSignal`。简单浏览器插件仅需返回贡献。
|
|
49
50
|
|
|
50
|
-
|
|
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
|
+
### 从聊天打开工作区文件
|
|
54
52
|
|
|
55
|
-
|
|
53
|
+
聊天 Markdown 中的相对文件链接(包括 `./file`)和会话工作区内的绝对路径会在内置文件面板中打开。修饰键、新标签页点击或没有面板接受链接时仍使用下载 URL。文件访问仍经过服务端工作区包含检查。
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
工作区面板通过同步 `fileOpenQuery(context, path)` 选择是否接受链接。上下文属于该贡献,路径是解码后的工作区相对路径;返回如 `{ file: path }` 的导航查询,或返回 `undefined` 拒绝。钩子不能产生副作用。宿主按面板 `order`、标题顺序打开当前机器上第一个可见、启用且接受链接的面板,通过普通导航设置命名空间查询。面板从 `context.navigation.query` 读取选择,不需要依赖文件插件。
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
### 面板与标签导航
|
|
60
58
|
|
|
61
|
-
|
|
59
|
+
URL 的 `view` 选择响应式面板:`navigation`、`chat` 或 `workspace`。独立的 `tool` 参数按贡献 ID 选择工作区标签。打开工具设置 `view=workspace` 和对应 `tool`;切换聊天保留工具选择。`view` 不接受贡献 ID。浏览器插件用 `selectMainView("workspace")` 显示工作区但不改变标签,或用 `selectWorkspaceTool(panelId)` 选择并显示工具。
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
- "Add a workspace panel with links to logs, dashboards, and local services for this repo."
|
|
65
|
-
- "Add an action-palette command that starts a standard code-review prompt."
|
|
66
|
-
- "Show whether the current workspace is a git worktree, main checkout, staging env, or feature branch."
|
|
67
|
-
- "Add a compact status badge based on a project health file or command output saved in the repo."
|
|
61
|
+
无效值留在 URL 中,不自动重定向。无效 `view` 显示警告,移动布局展示导航;双列布局保留导航,并展示有效请求工具,否则展示聊天;桌面保留常规列。有效工作区视图配无效工具时显示标签不可用,不选择其他标签,也不重复警告。省略参数使用默认值,不是错误。
|
|
68
62
|
|
|
69
|
-
|
|
63
|
+
操作与工作区面板上下文提供完整目的地导航 `navigate(destination): Promise<void>`:
|
|
70
64
|
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
Use the appropriate extension points from the docs.
|
|
80
|
-
Validate by checking /pi-web-plugins/manifest.json and explain how to reload/debug it.
|
|
81
|
-
Do not modify PI WEB itself.
|
|
65
|
+
```ts
|
|
66
|
+
await context.navigate({
|
|
67
|
+
machineId: context.machine.id,
|
|
68
|
+
projectId: context.workspace.projectId,
|
|
69
|
+
workspaceId: context.workspace.id,
|
|
70
|
+
sessionId: sourceSessionId,
|
|
71
|
+
view: "chat",
|
|
72
|
+
});
|
|
82
73
|
```
|
|
83
74
|
|
|
84
|
-
|
|
75
|
+
所有字段都可省略:`machineId`、`projectId`、`workspaceId`、`sessionId`、`view` 及完整贡献 ID 的 `tool`。省略机器意味着调用时选中的机器。这不是路由补丁:省略字段使用宿主普通恢复默认值,不复制当前会话、工具或贡献查询;默认值可以恢复记忆中的会话。打开已知会话时提供项目和工作区作用域。宿主不会遍历查找 ID,也不会创建不存在的目的地。
|
|
85
76
|
|
|
86
|
-
|
|
87
|
-
Improve the PI WEB plugin at <path>.
|
|
88
|
-
Before coding, read the PI WEB plugin docs:
|
|
89
|
-
https://pi-web.dev/plugins
|
|
90
|
-
Full API reference:
|
|
91
|
-
https://pi-web.dev/plugins.md
|
|
92
|
-
Keep the plugin compatible with the documented v1 API.
|
|
93
|
-
After editing, check the manifest endpoint and browser-console failure cases.
|
|
94
|
-
```
|
|
77
|
+
Promise 在恢复完成时结束,也可在被较新导航取代时正常结束。缺失或不可用的目的地使用普通宿主 UI,不再额外拒绝 Promise。参数类型错误或无效 `view` 会在改变 URL/UI 前以 `TypeError` 拒绝。Captain's Log 用此接口打开结果记录的源会话。
|
|
95
78
|
|
|
96
|
-
|
|
79
|
+
### 聊天与文件内容预览
|
|
97
80
|
|
|
98
|
-
|
|
81
|
+
浏览器插件可贡献 `contentRenderers`:`id`、Markdown 围栏标签 `languages`、不含点的 `fileExtensions`,以及同步返回 Lit 模板的 `render(input)`。选择器不区分大小写,语言或扩展名任一匹配即可。`renderMode?: 'manual' | 'automatic'` 默认 `manual`:先显示源码与“渲染”按钮,不调用渲染器。这是初始策略,不限制用户显式预览;无关正文更新不重启已激活预览。作者可选择 `automatic`,并负责高效激活与异步工作。
|
|
99
82
|
|
|
100
|
-
|
|
83
|
+
同一渲染器用于聊天围栏、文件 Markdown 围栏和独立文本文件,遵循有效机器的插件可用性及便携/机器专属优先级。多个匹配项提供选择器,同时仅挂载选中项。默认按来源插件 ID(不是远端运行时前缀)、局部贡献 ID 的大小写敏感、与区域设置无关的码元顺序排序。标签同时标明插件与贡献;没有插件排序字段或排序 UI。
|
|
101
84
|
|
|
102
|
-
|
|
85
|
+
聊天按代码块在当前浏览器标签页记忆显式渲染器与“源码/预览”选择:从最后一次显式选择起 **15 分钟**,最多 **128** 个最近选择块。作用域包含机器、会话、消息/entry、part、块和精确源码。查看或重新挂载不延长期限;到期在再次访问时生效,不撤掉正在显示的预览。源码变化或选中渲染器不可用会失效该选择并恢复确定性默认策略。自动渲染不产生显式记忆;DOM 不缓存,重新挂载重新渲染。刷新或关闭标签页清除记忆。文件 Markdown 不使用聊天记忆。
|
|
103
86
|
|
|
104
|
-
|
|
105
|
-
pi-web-plugins/info/package.json
|
|
106
|
-
pi-web-plugins/info/pi-web-plugin.ts
|
|
107
|
-
pi-web-plugins/info/infoInternals.ts
|
|
108
|
-
```
|
|
87
|
+
独立文件仅在没有浏览器本地“源码/预览”偏好时采用插件初始策略。已保存“预览”授权所有文件渲染,包括 Markdown 中的手动渲染器;已保存“源码”禁止预览。Markdown 预览内仍可逐块选择源码或渲染器,URL 模式优先。默认策略不会自动保存为用户选择,内置文件预览保留原默认行为。
|
|
109
88
|
|
|
110
|
-
|
|
89
|
+
聊天图表块保留“源码”“预览”“复制源码”工具栏;独立文件在“下载”旁使用文件头部的“源码/预览”控件,遵循文件模式偏好。Markdown 文件图表保留逐块控件。未闭合围栏保持可复制源码;闭合围栏可在消息结束前预览。追加正文不重启未变的闭合块;失败回退源码;未知格式保持普通代码显示。
|
|
111
90
|
|
|
112
|
-
|
|
91
|
+
`input` 包含 `text`、中止 `signal`、`fail(error)`。同步渲染,组件自己管理异步工作,在断开连接或中止时清理,通过 `fail` 报告异步错误;过期错误被忽略。文本不可信:转义/净化输出,不执行源码,不放宽 Markdown 策略。宿主跳过截断输入及超过 **100,000 UTF-16 码元**的块,文件还保留内联字节大小限制。聊天与文件 Markdown 保留各自的净化器。
|
|
113
92
|
|
|
114
|
-
|
|
115
|
-
dist/pi-web-plugins/info/pi-web-plugin.js
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
Package metadata:
|
|
93
|
+
文件等消费者在 `requires` 声明 `{ pluginId: "pi-web", id: "content-rendering", version: 1, parse }`,在 `start` 中解析。公开 `ContentRenderingCapability` 描述 `listRenderers(request)`、`renderText(request)` 和 `renderMarkdown({ machineId, text, truncated?, toSafeHtml, allowManualPreview? })`。`listRenderers` 返回排序后的 `{ id, label, renderMode }`,不调用渲染器。
|
|
119
94
|
|
|
120
|
-
|
|
121
|
-
{
|
|
122
|
-
"name": "@pi-web/info-plugin",
|
|
123
|
-
"private": true,
|
|
124
|
-
"piWeb": {
|
|
125
|
-
"plugins": [
|
|
126
|
-
{ "id": "info", "module": "pi-web-plugin.js" }
|
|
127
|
-
]
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
```
|
|
95
|
+
只有 `controls: "external"` 的 `renderText` 接受可选 `rendererId`,缺失或不可用时选择首个匹配项。内嵌控件拥有选择,忽略外部 ID。消费者自己提供选择器、模式切换与源码访问(如文件头部)时使用外部控件,否则使用内嵌控件。外部“源码”控件必须移除预览。
|
|
131
96
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
```js
|
|
135
|
-
export default {
|
|
136
|
-
apiVersion: 2,
|
|
137
|
-
name: "Info Plugin",
|
|
138
|
-
activate: ({ html, svg }) => ({
|
|
139
|
-
contributions: {
|
|
140
|
-
actions: [/* action definitions */],
|
|
141
|
-
workspaceLabels: [/* compact label definitions */],
|
|
142
|
-
workspacePanels: [/* panel definitions using html, optional icons using svg */],
|
|
143
|
-
},
|
|
144
|
-
}),
|
|
145
|
-
};
|
|
146
|
-
```
|
|
97
|
+
消费者管理用户意图,可用 `allowManualPreview: true` 显式授权手动预览;Markdown 授权符合条件的围栏,但不覆盖逐块“源码”选择。省略或 `false` 保留渲染器默认策略及自动预览;聊天不传此覆盖。公开能力不存用户意图,聊天有界记忆是宿主私有策略。Markdown 请求不带文件路径或语言选择器,语言来自围栏。创建 `renderText` 模板不调用渲染器。每个 Markdown 图表独立选择;切换渲染器中止旧预览并清除错误。`renderMarkdown` 必须使用消费者可信净化器,不允许插入不可信 HTML。参见[文件消费者](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/blob/main/pi-web-plugins/files/pi-web-plugin.ts)和 [Mermaid 贡献](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/tree/main/pi-web-plugins/mermaid)。
|
|
147
98
|
|
|
148
|
-
|
|
99
|
+
### 会话与配套扩展
|
|
149
100
|
|
|
150
|
-
|
|
101
|
+
服务端插件可创建普通、可见的 Pi 会话,可带初始提示词,也可不带。配套 Pi 扩展可与后端交换消息,使用 Pi API 执行代理工作。
|
|
151
102
|
|
|
152
|
-
|
|
103
|
+
**会话一旦发布就属于用户。** 初始任务完成、浏览器关闭或发起插件销毁,都不会丢弃会话或停止用户后续工作;用户可以继续对话。
|
|
153
104
|
|
|
154
|
-
|
|
105
|
+
消息连接只针对该机器已托管的会话,不自动打开已保存会话。发送成功不能证明配套扩展已安装或工作成功,集成必须自己报告进度与结果。连接不重放启动消息;关闭连接不停止代理。
|
|
155
106
|
|
|
156
|
-
|
|
107
|
+
### 存储与后台工作
|
|
157
108
|
|
|
158
|
-
|
|
109
|
+
服务端插件获得独立于安装代码的持久化 `dataDirectory`,同一机器上该插件的各项目共享该目录。插件自己负责格式、迁移与清理,宿主不提供另一套存储 API。
|
|
159
110
|
|
|
160
|
-
|
|
161
|
-
mkdir -p ~/.pi-web/plugins
|
|
162
|
-
ln -s /path/to/plugin-folder ~/.pi-web/plugins/plugin-id
|
|
163
|
-
```
|
|
111
|
+
请求和通道有界,可能失败、超时或断开。发送成功不保证送达,宿主不自动重试不确定工作。长任务应自行持久化状态,让 UI 重连时不重复启动任务。
|
|
164
112
|
|
|
165
|
-
|
|
113
|
+
### 工作区提供器
|
|
166
114
|
|
|
167
|
-
|
|
115
|
+
提供器决定项目包含哪些工作区。主提供器可对它声明的项目替代内置 Git;Git 为后备,没有提供器认领时项目目录仍可作为工作区。
|
|
168
116
|
|
|
169
|
-
|
|
117
|
+
声明冲突会明确报错;认领后失败不会静默把所有权交给另一提供器。提供器也可声明工作区删除能力,删除作为可见终端操作运行。
|
|
170
118
|
|
|
171
|
-
|
|
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.
|
|
119
|
+
工作区发现必须在宿主会话服务启动前就绪。包同时需要提供器和会话功能时,在同一个包中声明两个插件入口,无需拆分分发包。
|
|
177
120
|
|
|
178
|
-
|
|
121
|
+
<a id="install-and-manage"></a>
|
|
122
|
+
## 安装与管理
|
|
179
123
|
|
|
180
|
-
|
|
124
|
+
在 **设置 → Pi 包** 安装、更新、移除 npm、git/URL 或本地来源的包;在 **设置 → PI WEB 插件** 启用/禁用集成,查看是否激活、是否需要重启。
|
|
181
125
|
|
|
182
|
-
|
|
183
|
-
|
|
126
|
+
| 变更 | 后续操作 |
|
|
127
|
+
| --- | --- |
|
|
128
|
+
| 安装或编辑纯浏览器插件 | 刷新浏览器 |
|
|
129
|
+
| 安装、更新、配置、启用、禁用服务端插件 | 重启目标机器会话守护进程,再刷新浏览器 |
|
|
130
|
+
| 改变普通 Pi 扩展、技能或提示词 | 在每个空闲会话执行 `/reload` |
|
|
131
|
+
| 改变注册模型提供器的扩展 | 遵循[提供器重启规则](https://pi-web.dev/config#pi-extension-provider-baseline) |
|
|
184
132
|
|
|
185
|
-
|
|
133
|
+
**重启会话守护进程可能中断活跃会话和终端。** 先检查活跃工作,从它托管的会话之外重启。原生 systemd 用户服务:
|
|
186
134
|
|
|
187
|
-
```
|
|
188
|
-
|
|
135
|
+
```sh
|
|
136
|
+
systemctl --user restart pi-web-sessiond
|
|
189
137
|
```
|
|
190
138
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
## Manage PI WEB plugins
|
|
139
|
+
浏览器刷新、Web/API 重启或 Pi `/reload` 不激活服务端插件变更。重启前“期望”与“实际”状态可能不同;浏览器入口与实际服务端不匹配时会暂缓提供,不运行不兼容代码。
|
|
194
140
|
|
|
195
|
-
|
|
141
|
+
多数插件默认启用,包可以默认关闭,设置可以覆盖。插件配置保存在普通 [PI WEB 配置](https://pi-web.dev/config),不是安装文件里。
|
|
196
142
|
|
|
197
|
-
|
|
143
|
+
### 本地开发
|
|
198
144
|
|
|
199
|
-
|
|
145
|
+
代理可在任意目录开发包,再链接到本地插件目录:
|
|
200
146
|
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
"workspace-tasks": {
|
|
205
|
-
"enabled": true,
|
|
206
|
-
"settings": {}
|
|
207
|
-
},
|
|
208
|
-
"info": {
|
|
209
|
-
"enabled": false
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
147
|
+
```sh
|
|
148
|
+
mkdir -p ~/.pi-web/plugins
|
|
149
|
+
ln -s /path/to/plugin-folder ~/.pi-web/plugins/my-plugin
|
|
213
150
|
```
|
|
214
151
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
After changing plugin enablement, reload the PI WEB browser tab. Already-loaded plugin JavaScript is not unloaded from the current page.
|
|
218
|
-
|
|
219
|
-
## Built-in plugins
|
|
220
|
-
|
|
221
|
-
PI WEB ships core, discoverable plugins in the main `@chainingintention/pi-web-cn` npm package. Updates and Workspace Tasks are loaded directly from the PI WEB package. Relays is shipped as a real Pi package and installed automatically for the active agent profile, so it also requires no manual `pi install` step.
|
|
152
|
+
设置 `PI_WEB_DATA_DIR` 时改用 `$PI_WEB_DATA_DIR/plugins`。无需重建 PI WEB,但包必须包含编译后的 JavaScript;宿主不编译任意已安装插件源码。
|
|
222
153
|
|
|
223
|
-
|
|
154
|
+
<a id="remote-machines"></a>
|
|
155
|
+
## 远端机器
|
|
224
156
|
|
|
225
|
-
|
|
157
|
+
安装与设置针对设置中选中的机器。远端服务端代码运行在远端,浏览器界面经网关显示。文件、终端、对等帮助方法保留机器作用域。机器专属插件使用该机器自身安装;便携的纯浏览器插件可复用网关副本。主题属于整个应用,远端主题贡献忽略。
|
|
226
158
|
|
|
227
|
-
|
|
228
|
-
**What it does:** adds a conditional **Updates** workspace tab with PI WEB update, restart, and installed-service guidance, plus a **Check for PI WEB Updates** action for the selected machine.
|
|
159
|
+
此 API 迁移期间网关与目标一起升级,重启更新后的 Web/API 与相关会话守护进程,再刷新浏览器。混合版本会使远端插件(包括 Git)不可用,宿主不静默替换为网关后端。
|
|
229
160
|
|
|
230
|
-
|
|
161
|
+
<a id="included-tools-and-optional-packages"></a>
|
|
162
|
+
## 内置工具与可选包
|
|
231
163
|
|
|
232
|
-
|
|
164
|
+
- **终端**提供终端和命令运行,是普通启动的必需插件,仅紧急安全启动可跳过。
|
|
165
|
+
- **文件**提供文件浏览、预览、上传;禁用面板不移除其他插件的文件帮助方法。
|
|
166
|
+
- **Git**发现工作区并显示状态/差异;禁用后保留项目目录工作区,除非其他提供器认领。
|
|
167
|
+
- **Mermaid**默认手动模式,点击“渲染”预览 `mermaid` 围栏和 `.mmd`/`.mermaid` 文件。内置引擎在不透明来源、网络受阻的沙箱中本地运行,不发送源码给图表服务。交互链接和外部资源不可用。禁用后保持代码显示;纯浏览器插件只需刷新页面。
|
|
168
|
+
- **信息**显示 PI WEB 状态与可复制诊断。
|
|
169
|
+
- **更新**在需要时显示更新/重启建议,并提供手动检查。
|
|
170
|
+
- **工作区任务**将项目命令显示为可运行操作。
|
|
233
171
|
|
|
234
|
-
|
|
235
|
-
{
|
|
236
|
-
"plugins": {
|
|
237
|
-
"updates": { "enabled": false }
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
```
|
|
172
|
+
### 工作区任务
|
|
241
173
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
**Plugin id:** `workspace-tasks`
|
|
245
|
-
**Config file:** `.pi-web/tasks.json`
|
|
246
|
-
**What it does:** adds a **Tasks** workspace tab for running configured shell commands in dedicated PI WEB terminals.
|
|
247
|
-
|
|
248
|
-
Workspace Tasks is enabled by default. To hide it, disable `workspace-tasks` in **Settings → PI WEB plugins** or set:
|
|
249
|
-
|
|
250
|
-
```json
|
|
251
|
-
{
|
|
252
|
-
"plugins": {
|
|
253
|
-
"workspace-tasks": { "enabled": false }
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
Configure workspace tasks in `.pi-web/tasks.json`:
|
|
174
|
+
在项目创建 `.pi-web/tasks.json`:
|
|
259
175
|
|
|
260
176
|
```json
|
|
261
177
|
{
|
|
262
178
|
"version": 1,
|
|
263
179
|
"tasks": [
|
|
264
|
-
{
|
|
265
|
-
|
|
266
|
-
"title": "Start app",
|
|
267
|
-
"group": "Development",
|
|
268
|
-
"description": "Start the local development server.",
|
|
269
|
-
"command": "npm run dev"
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
"id": "db.reset",
|
|
273
|
-
"title": "Reset DB",
|
|
274
|
-
"group": "Database",
|
|
275
|
-
"command": "go -C klingit-go run ./cli db reset",
|
|
276
|
-
"confirm": true
|
|
277
|
-
}
|
|
278
|
-
]
|
|
279
|
-
}
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
Open a workspace, choose the **Tasks** tab, and click **Run** next to a task. Commands run in the workspace root because PI WEB creates the terminal for that workspace.
|
|
283
|
-
|
|
284
|
-
Task fields:
|
|
285
|
-
|
|
286
|
-
- `version`: must be `1`.
|
|
287
|
-
- `tasks`: array of task definitions.
|
|
288
|
-
- `id`: stable task id, matching `^[a-z][a-z0-9.-]*$`.
|
|
289
|
-
- `title`: button label.
|
|
290
|
-
- `command`: literal shell command sent to the terminal.
|
|
291
|
-
- `description`: optional explanatory text.
|
|
292
|
-
- `group`: optional group heading.
|
|
293
|
-
- `confirm`: optional boolean. When true, the browser asks before dispatching the command.
|
|
294
|
-
|
|
295
|
-
Review task configs before running them, especially in shared projects. Workspace Tasks runs trusted shell commands from your repositories.
|
|
296
|
-
|
|
297
|
-
### Relays
|
|
298
|
-
|
|
299
|
-
**Plugin id:** `relays`
|
|
300
|
-
**What it does:** adds a read-only **Relays** workspace tab for browsing the workspace's relays, plus an **Open Workspace Relays** action for the selected workspace that opens the same tab.
|
|
301
|
-
|
|
302
|
-
A relay is a directory of markdown notes under `.pi-web/relays/<name>/` in the workspace root — the convention used by the Relay method for chaining agent sessions. The tab lists each relay's documents with `status.md`, `charter.md`, and `log.md` first (in that order), followed by any other files alphabetically, and opens `status.md` by default. Markdown documents render as sanitized HTML; other files render as preformatted text, and binary files have no preview. Truncated documents show a notice, and **Refresh** re-scans the workspace and reloads the open document.
|
|
303
|
-
|
|
304
|
-
Documents in subfolders are listed too. Folders appear as chips in the document strip, and expanding one inserts its files inline after it. Expanding a folder collapses its siblings at the same level, while collapsing the folder that contains the open document keeps the selection and highlights that folder. Relay trees deeper than five levels, larger than 200 documents, or containing more than 50 folders are listed partially with a notice.
|
|
305
|
-
|
|
306
|
-
With several relays, a picker pre-selects the most recently modified one; a single relay opens directly. A workspace without `.pi-web/relays/` shows an empty state explaining the convention. The tab never creates, edits, or deletes relay files.
|
|
307
|
-
|
|
308
|
-
Relays is shipped as the `@jmfederico/pi-relay` Pi package. On session-daemon startup, PI WEB installs the shipped package for the active agent profile when it is not already configured. This best-effort install never blocks daemon startup. Removing the package through **Settings → Pi packages** records that choice for the profile, so later startups do not add it back; the same panel offers a one-click install suggestion when you want it again.
|
|
309
|
-
|
|
310
|
-
Once installed, the browser plugin is enabled by default. To hide its browser UI without removing the Pi package, disable `relays` in **Settings → PI WEB plugins** or set:
|
|
311
|
-
|
|
312
|
-
```json
|
|
313
|
-
{
|
|
314
|
-
"plugins": {
|
|
315
|
-
"relays": { "enabled": false }
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
## Discovery and packaging
|
|
321
|
-
|
|
322
|
-
PI WEB builds the gateway `/pi-web-plugins/manifest.json` from these sources:
|
|
323
|
-
|
|
324
|
-
1. Bundled plugins in the PI WEB package:
|
|
325
|
-
|
|
326
|
-
```text
|
|
327
|
-
pi-web-plugins/<plugin-package>/
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
2. User-local plugins:
|
|
331
|
-
|
|
332
|
-
```text
|
|
333
|
-
~/.pi-web/plugins/<plugin-package>/
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
Entries may be real directories or symlinks. This is the recommended development workflow.
|
|
337
|
-
|
|
338
|
-
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.
|
|
339
|
-
|
|
340
|
-
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.
|
|
341
|
-
|
|
342
|
-
Plugin package directory names and plugin ids must be valid identifiers:
|
|
343
|
-
|
|
344
|
-
```text
|
|
345
|
-
^[a-z][a-z0-9.-]*$
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
A package can expose one or more PI WEB plugin modules. There is exactly one supported `package.json` metadata shape:
|
|
349
|
-
|
|
350
|
-
```json
|
|
351
|
-
{
|
|
352
|
-
"private": true,
|
|
353
|
-
"piWeb": {
|
|
354
|
-
"plugins": [
|
|
355
|
-
{ "id": "review", "module": "dist/review.js" },
|
|
356
|
-
{ "id": "dashboard", "module": "dist/dashboard.js", "machineSpecific": true }
|
|
357
|
-
]
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
Rules:
|
|
363
|
-
|
|
364
|
-
- `piWeb.plugins` must be an array of objects.
|
|
365
|
-
- Each entry must have an explicit `id` and `module`.
|
|
366
|
-
- `id` must match `^[a-z][a-z0-9.-]*$`.
|
|
367
|
-
- `module` must be a safe relative path inside the plugin package root.
|
|
368
|
-
- `machineSpecific` is optional and must be a boolean; omit it for the default portable gateway behavior.
|
|
369
|
-
- Duplicate plugin ids are not auto-renamed; later duplicates are skipped.
|
|
370
|
-
- Legacy shortcuts such as `piWeb.plugin`, string entries in `piWeb.plugins`, `piWeb.id` fallback ids, and no-`package.json` fallbacks are not supported.
|
|
371
|
-
|
|
372
|
-
### Manifest and assets
|
|
373
|
-
|
|
374
|
-
The manifest contains each discovered plugin module. Current PI WEB releases emit `module` as a leading application-root reference:
|
|
375
|
-
|
|
376
|
-
```json
|
|
377
|
-
{
|
|
378
|
-
"plugins": [
|
|
379
|
-
{
|
|
380
|
-
"id": "my-plugin",
|
|
381
|
-
"module": "/pi-web-plugins/my-plugin/pi-web-plugin.js?v=1234567890",
|
|
382
|
-
"source": "local",
|
|
383
|
-
"scope": "local",
|
|
384
|
-
"machineSpecific": false
|
|
385
|
-
}
|
|
180
|
+
{ "id": "app.start", "title": "启动应用", "command": "npm run dev" },
|
|
181
|
+
{ "id": "db.reset", "title": "重置数据库", "command": "npm run db:reset", "confirm": true }
|
|
386
182
|
]
|
|
387
183
|
}
|
|
388
184
|
```
|
|
389
185
|
|
|
390
|
-
|
|
186
|
+
从“任务”标签运行工作区终端命令。任务可带 `description`;尤其共享仓库中,运行前检查命令。禁用插件只隐藏标签,不修改项目文件。
|
|
391
187
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
At an origin-root deployment, a plugin's static assets are available under:
|
|
395
|
-
|
|
396
|
-
```text
|
|
397
|
-
/pi-web-plugins/<plugin-id>/<path-inside-plugin-root>
|
|
398
|
-
```
|
|
188
|
+
### 中继
|
|
399
189
|
|
|
400
|
-
|
|
190
|
+
随包分发的 Relay 提供跨会话工作提示词和技能,并在只读“中继”标签展示 `.pi-web/relays/` 计划与进度,不从标签启动或编辑中继。
|
|
401
191
|
|
|
402
|
-
|
|
403
|
-
const iconUrl = new URL("./assets/icon.svg", import.meta.url);
|
|
404
|
-
```
|
|
192
|
+
普通模式在当前 agent 配置未安装时自动安装 Relay;从 **设置 → Pi 包** 移除会被记忆,不静默重装,可从“可用包”恢复。单独禁用中继插件只隐藏标签,不移除代理资源。管理嵌入的 `relay` 与 `relay-runner` 模板同步继续限定在授权工作区,不改变普通启动的技能文件。
|
|
405
193
|
|
|
406
|
-
|
|
194
|
+
### 试用 Captain's Log
|
|
407
195
|
|
|
408
|
-
|
|
196
|
+
Captain's Log 是可选示例,将会话最近的助手回复改写为海盗风格简报,演示浏览器面板、后端和 Pi 配套扩展协作。
|
|
409
197
|
|
|
410
|
-
|
|
198
|
+
1. 在目标机器的 **设置 → Pi 包 → 可用包** 安装 **船长日志**。
|
|
199
|
+
2. 在 **设置 → PI WEB 插件** 启用它。
|
|
200
|
+
3. 安全时重启目标机器会话守护进程,再刷新浏览器。
|
|
201
|
+
4. 选择会话,打开“船长日志”,点击“让船长来讲述”。
|
|
411
202
|
|
|
412
|
-
|
|
203
|
+
它随主包预构建发布,**默认不安装、不启用**,无需现场编译。读取源回复但不修改源会话,另建海盗会话;需要模型凭据,源文本会发给海盗会话的模型提供器,可能产生模型费用。已有结果会保存。守护进程重启后,可从“会话”打开已有海盗会话继续上下文。
|
|
413
204
|
|
|
414
|
-
|
|
415
|
-
interface PiWebPlugin {
|
|
416
|
-
apiVersion: 2;
|
|
417
|
-
name: string;
|
|
418
|
-
activate: (context: PluginActivationContext) => PluginActivationResult;
|
|
419
|
-
}
|
|
205
|
+
详见[船长日志使用指南](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/blob/main/pi-packages/captains-log/docs/usage.md)。
|
|
420
206
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
pluginId: string;
|
|
424
|
-
runtimePluginId?: string;
|
|
425
|
-
html: typeof import("lit").html;
|
|
426
|
-
svg: typeof import("lit").svg;
|
|
427
|
-
}
|
|
207
|
+
<a id="pi-extension-dialogs"></a>
|
|
208
|
+
## Pi 扩展对话框
|
|
428
209
|
|
|
429
|
-
|
|
430
|
-
contributions: PluginContributions;
|
|
431
|
-
}
|
|
432
|
-
```
|
|
210
|
+
Pi 扩展可请求确认、选择或文本输入;问题以内联方式展示,包括会话启动和工具等待阶段。刷新后仍可回答,多标签页最先回答生效。
|
|
433
211
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
```js
|
|
437
|
-
export default {
|
|
438
|
-
apiVersion: 2,
|
|
439
|
-
name: "My Plugin",
|
|
440
|
-
activate: ({ pluginId, html }) => ({
|
|
441
|
-
contributions: {
|
|
442
|
-
actions: [],
|
|
443
|
-
workspacePanels: [],
|
|
444
|
-
workspaceLabels: [],
|
|
445
|
-
},
|
|
446
|
-
}),
|
|
447
|
-
};
|
|
448
|
-
```
|
|
212
|
+
有效期限取扩展超时和[宿主超时](https://pi-web.dev/config#extension-dialogs)中较早者。中止工作或替换运行时关闭相关问题。已回答卡片属于浏览器本地状态,不保证刷新后保留。新会话尚在创建时刷新可临时丢失卡片,但守护进程中的问题仍有期限。
|
|
449
213
|
|
|
450
|
-
|
|
214
|
+
仅支持这三种对话框,不支持自定义编辑器或组件等其他 Pi UI;不要因为 `hasUI` 为真就假定所有 UI 可用。
|
|
451
215
|
|
|
452
|
-
|
|
216
|
+
<a id="agent-development"></a>
|
|
217
|
+
## 代理开发
|
|
453
218
|
|
|
454
|
-
|
|
219
|
+
给代理具体目标、数据来源及允许的动作:
|
|
455
220
|
|
|
456
221
|
```text
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
`activate()` returns a `contributions` object with any combination of these arrays:
|
|
465
|
-
|
|
466
|
-
```ts
|
|
467
|
-
interface PluginContributions {
|
|
468
|
-
actions?: PluginAction[];
|
|
469
|
-
workspacePanels?: WorkspacePanelContribution[];
|
|
470
|
-
workspaceLabels?: WorkspaceLabelContribution[];
|
|
471
|
-
}
|
|
222
|
+
为此项目创建 PI WEB 插件。
|
|
223
|
+
目标:<描述工作流和预期界面>。
|
|
224
|
+
先读 https://pi-web.dev/plugins.md,再按当前安装的 PI WEB 版本
|
|
225
|
+
查阅公开契约与示例。
|
|
226
|
+
只使用受支持的插件 API,不修改 PI WEB,不调用私有路由。
|
|
227
|
+
说明安装、权限或模型使用情况,以及刷新方式。
|
|
228
|
+
验证行为,包括失败和清理。
|
|
472
229
|
```
|
|
473
230
|
|
|
474
|
-
###
|
|
475
|
-
|
|
476
|
-
Actions appear in the action palette. They can inspect app state and call UI/runtime helpers.
|
|
477
|
-
|
|
478
|
-
```js
|
|
479
|
-
actions: [
|
|
480
|
-
{
|
|
481
|
-
id: "copy-diagnostics",
|
|
482
|
-
title: "Copy PI WEB Diagnostics",
|
|
483
|
-
description: "Copy version, installation, and status details for this machine",
|
|
484
|
-
group: "Info",
|
|
485
|
-
run: async (context) => {
|
|
486
|
-
const version = context.state.piWebStatus?.components.web.runtimeVersion ?? "unknown";
|
|
487
|
-
await navigator.clipboard.writeText(`PI WEB ${version}`);
|
|
488
|
-
},
|
|
489
|
-
},
|
|
490
|
-
]
|
|
491
|
-
```
|
|
492
|
-
|
|
493
|
-
Action type:
|
|
494
|
-
|
|
495
|
-
```ts
|
|
496
|
-
interface PluginAction {
|
|
497
|
-
id: string;
|
|
498
|
-
title: string;
|
|
499
|
-
description?: string;
|
|
500
|
-
shortcut?: string;
|
|
501
|
-
group?: string;
|
|
502
|
-
enabled?: (context: PluginRuntimeContext) => boolean;
|
|
503
|
-
disabledReason?: (context: PluginRuntimeContext) => string | undefined;
|
|
504
|
-
run: (context: PluginRuntimeContext) => void | Promise<void>;
|
|
505
|
-
}
|
|
506
|
-
```
|
|
507
|
-
|
|
508
|
-
If an action is disabled and returns `disabledReason`, PI WEB can keep it visible in the action palette with that explanation instead of hiding it.
|
|
509
|
-
|
|
510
|
-
Stable runtime context fields:
|
|
511
|
-
|
|
512
|
-
```ts
|
|
513
|
-
interface PluginRuntimeContext {
|
|
514
|
-
state: {
|
|
515
|
-
selectedMachine?: PluginMachine;
|
|
516
|
-
selectedWorkspace?: Workspace;
|
|
517
|
-
selectedSession?: unknown;
|
|
518
|
-
piWebStatus?: PiWebStatusResponse;
|
|
519
|
-
};
|
|
520
|
-
prompt: PluginPromptEditor;
|
|
521
|
-
openActionPalette: () => void;
|
|
522
|
-
focusPrompt: () => void;
|
|
523
|
-
addProject: () => void | Promise<void>;
|
|
524
|
-
configureAuth: () => void | Promise<void>;
|
|
525
|
-
logoutAuth: () => void | Promise<void>;
|
|
526
|
-
selectWorkspaceTool: (tool: QualifiedContributionId) => void;
|
|
527
|
-
openTerminal: (options?: { terminalId?: string }) => void;
|
|
528
|
-
refreshFiles: () => void | Promise<void>;
|
|
529
|
-
refreshGit: () => void | Promise<void>;
|
|
530
|
-
checkForPiWebUpdates?: () => void | Promise<void>;
|
|
531
|
-
startSession: () => void | Promise<void>;
|
|
532
|
-
archiveSession: () => void | Promise<void>;
|
|
533
|
-
stopActiveWork: () => void | Promise<void>;
|
|
534
|
-
}
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
Notes:
|
|
538
|
-
|
|
539
|
-
- `state` is a snapshot of current UI state when actions are built.
|
|
540
|
-
- 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.
|
|
541
|
-
- Other `state` fields may exist at runtime, but they are private PI WEB internals that may graduate into stable helpers, change shape, or disappear.
|
|
542
|
-
- `enabled` is evaluated when the action palette asks for actions.
|
|
543
|
-
- `selectWorkspaceTool()` expects a qualified panel id such as `my-plugin:workspace.info`.
|
|
544
|
-
- `openTerminal()` switches to the built-in terminal panel. Pass `{ terminalId }` to deep-link to a specific terminal.
|
|
545
|
-
- Only fields documented here and declared in `plugin-api.d.ts` are stable public browser plugin API. Runtime-only fields and private HTTP routes are not compatibility surfaces.
|
|
546
|
-
|
|
547
|
-
### Prompt editor API
|
|
231
|
+
### 实现入口
|
|
548
232
|
|
|
549
|
-
|
|
233
|
+
从符合目标的最小示例开始。以下源码链接跟随 `main`;对发布版开发时,**使用对应标签或已安装的公开声明**。
|
|
550
234
|
|
|
551
|
-
|
|
|
235
|
+
| 需求 | 入口 |
|
|
552
236
|
| --- | --- |
|
|
553
|
-
|
|
|
554
|
-
|
|
|
555
|
-
|
|
|
237
|
+
| 浏览器贡献与帮助方法 | [plugin-api.ts](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/blob/main/src/plugin-api.ts),公开为 `@chainingintention/pi-web-cn/plugin-api` |
|
|
238
|
+
| 服务端生命周期、对等入口、提供器与宿主能力 | [server-plugin-api.ts](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/blob/main/src/server-plugin-api.ts),公开为 `@chainingintention/pi-web-cn/server-plugin-api` |
|
|
239
|
+
| 小型浏览器插件 | [信息](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/tree/main/pi-web-plugins/info) |
|
|
240
|
+
| 独立浏览器/服务端包 | [工作区提供器示例](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/tree/main/examples/workspace-provider-plugin) |
|
|
241
|
+
| 生产工作区提供器与配套 UI | [Git](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/tree/main/pi-web-plugins/git) |
|
|
242
|
+
| 已托管会话、实时更新与 Pi 配套扩展 | [Captain's Log](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/tree/main/pi-packages/captains-log) |
|
|
243
|
+
| 简单初始提示词工作流 | [工作区审查示例](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/tree/main/examples/session-bridge-plugin) |
|
|
244
|
+
| 发现规则与诊断 | [插件目录](https://github.com/nayuto-wakusei/pi-web-ChineseTranslation/blob/main/src/server/piWebPluginCatalog.ts) |
|
|
556
245
|
|
|
557
|
-
|
|
246
|
+
当前浏览器契约是 **API v4**,服务端契约是 **API v3**。旧入口必须迁移,没有兼容 shim。公开源码契约和测试是签名、验证、限制与生命周期的依据。
|
|
558
247
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
248
|
+
- 在 `package.json` 的 `piWeb.plugins` 声明入口,参考独立示例的打包方式;同一包可含多个入口。
|
|
249
|
+
- 仅使用公开包入口,内部路由、服务及 `dist/**` 导入不是受支持 API。
|
|
250
|
+
- `browserRoot` 尽量窄,里面所有内容都对浏览器公开。包含所需依赖与资产,秘密放在之外。安装插件包限制为 **4,096** 项、**16 MiB**,不计 `.git`/`node_modules`。
|
|
251
|
+
- 机器/工作区操作使用宿主帮助方法,插件资产使用模块相对 URL,不硬编码应用路径。
|
|
252
|
+
- 面板没有重新挂载时也可能重复渲染。自己管理异步状态,组件生命周期清理连接、计时器与监听器。
|
|
253
|
+
- 工作区发现与会话支持功能分离,代理行为放在 Pi 配套扩展,而不是导入宿主内部模块。
|
|
562
254
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const selection = context.prompt.getSelection(); // { start, end, text } | null
|
|
566
|
-
```
|
|
567
|
-
|
|
568
|
-
Use `focusPrompt()` on `PluginRuntimeContext` to move focus to the prompt editor. Workspace panels can call `context.prompt.insertText()` from explicit user interactions such as button clicks; panel contexts target the currently selected session's mounted prompt editor.
|
|
569
|
-
|
|
570
|
-
#### Keyboard shortcuts
|
|
571
|
-
|
|
572
|
-
- App-level keyboard shortcuts must be attached to actions. PI WEB does not support standalone plugin keyboard commands; contribute an action first, then add a `shortcut` if it needs a keybinding.
|
|
573
|
-
- `shortcut` is the action's default keybinding. It is displayed in the action palette and handled by the global shortcut dispatcher when the action is enabled.
|
|
574
|
-
- Use modified shortcuts such as `mod+shift+p`; plain letter shortcuts are intentionally ignored so normal typing is never captured.
|
|
575
|
-
- Future PI WEB versions may allow users to override or disable action shortcuts by action id, so plugins should treat `shortcut` as a default rather than a guaranteed final binding.
|
|
576
|
-
- Choose shortcuts carefully to avoid conflicts. There is no user-facing shortcut override or conflict resolver yet.
|
|
577
|
-
- Local text input, terminal input, list navigation, and dialog keys such as Enter, Escape, and arrow keys do not need to be plugin actions unless they are app-level commands.
|
|
578
|
-
|
|
579
|
-
### Workspace panels
|
|
580
|
-
|
|
581
|
-
Workspace panels add tools next to built-in workspace tools. They render inside the workspace side panel on desktop and as mobile tabs on smaller screens.
|
|
582
|
-
|
|
583
|
-
```js
|
|
584
|
-
workspacePanels: [
|
|
585
|
-
{
|
|
586
|
-
id: "workspace.info",
|
|
587
|
-
title: "Info",
|
|
588
|
-
icon: svg`
|
|
589
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
590
|
-
<circle cx="12" cy="12" r="9"></circle>
|
|
591
|
-
<path d="M12 10v6"></path>
|
|
592
|
-
<path d="M12 7h.01"></path>
|
|
593
|
-
</svg>
|
|
594
|
-
`,
|
|
595
|
-
order: 100,
|
|
596
|
-
visible: ({ workspace }) => workspace.isGitRepo,
|
|
597
|
-
render: ({ workspace }) => html`
|
|
598
|
-
<section class="toolbar"><strong>Info</strong></section>
|
|
599
|
-
<section class="viewer">
|
|
600
|
-
<p class="muted">${workspace.label}</p>
|
|
601
|
-
<p class="muted">${workspace.path}</p>
|
|
602
|
-
</section>
|
|
603
|
-
`,
|
|
604
|
-
},
|
|
605
|
-
]
|
|
606
|
-
```
|
|
607
|
-
|
|
608
|
-
Panel type:
|
|
609
|
-
|
|
610
|
-
```ts
|
|
611
|
-
interface WorkspacePanelContribution {
|
|
612
|
-
id: string;
|
|
613
|
-
title: string;
|
|
614
|
-
icon?: TemplateResult;
|
|
615
|
-
order?: number;
|
|
616
|
-
visible?: (context: WorkspacePanelContext) => boolean;
|
|
617
|
-
badge?: (context: WorkspacePanelContext) => string | number | TemplateResult | undefined;
|
|
618
|
-
render: (context: WorkspacePanelContext) => TemplateResult;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
interface WorkspacePanelContext {
|
|
622
|
-
machine: PluginMachine;
|
|
623
|
-
workspace: Workspace;
|
|
624
|
-
state?: PluginRuntimeState;
|
|
625
|
-
files: {
|
|
626
|
-
readFile(path: string): Promise<FileContentResponse>;
|
|
627
|
-
listFiles(path: string): Promise<FileTreeResponse>;
|
|
628
|
-
writeFile(path: string, content: string | Uint8Array, options?: WriteWorkspaceFileOptions): Promise<WriteWorkspaceFileResponse>;
|
|
629
|
-
deleteFile(path: string): Promise<DeleteWorkspaceFileResponse>;
|
|
630
|
-
moveFile(fromPath: string, toPath: string, options?: MoveWorkspaceFileOptions): Promise<MoveWorkspaceFileResponse>;
|
|
631
|
-
};
|
|
632
|
-
prompt: PluginPromptEditor;
|
|
633
|
-
terminal: {
|
|
634
|
-
open(options?: { terminalId?: string }): void;
|
|
635
|
-
runCommand(input: {
|
|
636
|
-
title: string;
|
|
637
|
-
command: string;
|
|
638
|
-
metadata?: Record<string, string>;
|
|
639
|
-
open?: boolean;
|
|
640
|
-
}): Promise<TerminalCommandRunHandle>;
|
|
641
|
-
};
|
|
642
|
-
host: {
|
|
643
|
-
requestRender(): void;
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
```
|
|
647
|
-
|
|
648
|
-
`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.
|
|
649
|
-
|
|
650
|
-
`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`.
|
|
651
|
-
|
|
652
|
-
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()`.
|
|
653
|
-
|
|
654
|
-
Useful workspace and machine shapes:
|
|
655
|
-
|
|
656
|
-
```ts
|
|
657
|
-
interface PluginMachine {
|
|
658
|
-
id: string;
|
|
659
|
-
name: string;
|
|
660
|
-
kind: "local" | "remote";
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
interface Workspace {
|
|
664
|
-
id: string;
|
|
665
|
-
projectId: string;
|
|
666
|
-
path: string;
|
|
667
|
-
label: string;
|
|
668
|
-
branch?: string;
|
|
669
|
-
isMain: boolean;
|
|
670
|
-
isGitRepo: boolean;
|
|
671
|
-
isGitWorktree: boolean;
|
|
672
|
-
}
|
|
673
|
-
```
|
|
674
|
-
|
|
675
|
-
`machine.id` is included in panel contexts so plugins can keep caches machine-scoped. Do not infer the selected machine from global browser state.
|
|
676
|
-
|
|
677
|
-
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.
|
|
678
|
-
|
|
679
|
-
### Workspace labels
|
|
680
|
-
|
|
681
|
-
Workspace labels add compact inline metadata wherever PI WEB displays a workspace label: workspace list, workspace panel header, and status bar.
|
|
682
|
-
|
|
683
|
-
Use them for short facts like project environment, local URL, branch status, container name, or health state.
|
|
684
|
-
|
|
685
|
-
```js
|
|
686
|
-
workspaceLabels: [
|
|
687
|
-
{
|
|
688
|
-
id: "dev-url",
|
|
689
|
-
order: 10,
|
|
690
|
-
visible: ({ workspace }) => workspace.path.includes("my-app"),
|
|
691
|
-
items: () => [{
|
|
692
|
-
type: "link",
|
|
693
|
-
text: "web:5173",
|
|
694
|
-
href: "http://localhost:5173",
|
|
695
|
-
title: "Open dev server",
|
|
696
|
-
target: "_blank",
|
|
697
|
-
}],
|
|
698
|
-
},
|
|
699
|
-
]
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
Label contribution type:
|
|
703
|
-
|
|
704
|
-
```ts
|
|
705
|
-
interface WorkspaceLabelContribution {
|
|
706
|
-
id: string;
|
|
707
|
-
order?: number;
|
|
708
|
-
visible?: (context: WorkspaceLabelContext) => boolean;
|
|
709
|
-
items: (context: WorkspaceLabelContext) => WorkspaceLabelItem[];
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
interface WorkspaceLabelContext {
|
|
713
|
-
machine: PluginMachine;
|
|
714
|
-
workspace: Workspace;
|
|
715
|
-
state?: PluginRuntimeState;
|
|
716
|
-
files: {
|
|
717
|
-
readFile(path: string): Promise<FileContentResponse>;
|
|
718
|
-
listFiles(path: string): Promise<FileTreeResponse>;
|
|
719
|
-
writeFile(path: string, content: string | Uint8Array, options?: WriteWorkspaceFileOptions): Promise<WriteWorkspaceFileResponse>;
|
|
720
|
-
deleteFile(path: string): Promise<DeleteWorkspaceFileResponse>;
|
|
721
|
-
moveFile(fromPath: string, toPath: string, options?: MoveWorkspaceFileOptions): Promise<MoveWorkspaceFileResponse>;
|
|
722
|
-
};
|
|
723
|
-
host: {
|
|
724
|
-
requestRender(): void;
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
```
|
|
728
|
-
|
|
729
|
-
`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.
|
|
730
|
-
|
|
731
|
-
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.
|
|
732
|
-
|
|
733
|
-
#### Text items
|
|
734
|
-
|
|
735
|
-
```js
|
|
736
|
-
{ type: "text", text: "staging", title: "Staging workspace" }
|
|
737
|
-
```
|
|
738
|
-
|
|
739
|
-
#### Link items
|
|
740
|
-
|
|
741
|
-
```js
|
|
742
|
-
{
|
|
743
|
-
type: "link",
|
|
744
|
-
text: "web:5173",
|
|
745
|
-
href: "http://localhost:5173",
|
|
746
|
-
title: "Open dev server",
|
|
747
|
-
target: "_blank"
|
|
748
|
-
}
|
|
749
|
-
```
|
|
750
|
-
|
|
751
|
-
PI WEB renders the anchor and adds safe defaults such as `rel="noopener noreferrer"` for `_blank` links. `javascript:` and `data:` links are rendered as plain text instead of links.
|
|
752
|
-
|
|
753
|
-
#### Render items
|
|
754
|
-
|
|
755
|
-
Use render items when a label contribution needs custom UI, async data, or caching. Render items should stay compact and inline.
|
|
756
|
-
|
|
757
|
-
```js
|
|
758
|
-
class MyWorkspaceBadge extends HTMLElement {
|
|
759
|
-
set workspace(value) {
|
|
760
|
-
this._workspace = value;
|
|
761
|
-
this.textContent = value?.branch === "main" ? "main" : "branch";
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
if (!customElements.get("my-workspace-badge")) {
|
|
766
|
-
customElements.define("my-workspace-badge", MyWorkspaceBadge);
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
export default {
|
|
770
|
-
apiVersion: 2,
|
|
771
|
-
name: "My Plugin",
|
|
772
|
-
activate: ({ html }) => ({
|
|
773
|
-
contributions: {
|
|
774
|
-
workspaceLabels: [
|
|
775
|
-
{
|
|
776
|
-
id: "badge",
|
|
777
|
-
order: 10,
|
|
778
|
-
items: ({ workspace }) => [{
|
|
779
|
-
type: "render",
|
|
780
|
-
render: () => html`<my-workspace-badge .workspace=${workspace}></my-workspace-badge>`,
|
|
781
|
-
}],
|
|
782
|
-
},
|
|
783
|
-
],
|
|
784
|
-
},
|
|
785
|
-
}),
|
|
786
|
-
};
|
|
787
|
-
```
|
|
788
|
-
|
|
789
|
-
## Reading workspace files
|
|
790
|
-
|
|
791
|
-
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.
|
|
792
|
-
|
|
793
|
-
```js
|
|
794
|
-
workspacePanels: [
|
|
795
|
-
{
|
|
796
|
-
id: "workspace.env",
|
|
797
|
-
title: "Env",
|
|
798
|
-
render: ({ files }) => html`
|
|
799
|
-
<my-env-viewer .files=${files}></my-env-viewer>
|
|
800
|
-
`,
|
|
801
|
-
},
|
|
802
|
-
]
|
|
803
|
-
|
|
804
|
-
class MyEnvViewer extends HTMLElement {
|
|
805
|
-
set files(value) {
|
|
806
|
-
this._files = value;
|
|
807
|
-
void this.load();
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
async load() {
|
|
811
|
-
try {
|
|
812
|
-
const file = await this._files.readFile(".env.example");
|
|
813
|
-
this.textContent = file.binary ? "Binary file" : file.content;
|
|
814
|
-
} catch (error) {
|
|
815
|
-
this.textContent = error instanceof Error ? error.message : String(error);
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
```
|
|
820
|
-
|
|
821
|
-
Labels should use the same helper through a plugin-owned cache because `items()` itself must return synchronously:
|
|
822
|
-
|
|
823
|
-
```js
|
|
824
|
-
const envCache = new Map();
|
|
825
|
-
|
|
826
|
-
function envKey(machine, workspace) {
|
|
827
|
-
return `${machine.id}:${workspace.id}:.env.local`;
|
|
828
|
-
}
|
|
255
|
+
<a id="trust-and-recovery"></a>
|
|
256
|
+
## 信任与恢复
|
|
829
257
|
|
|
830
|
-
|
|
831
|
-
const key = envKey(context.machine, context.workspace);
|
|
832
|
-
const cached = envCache.get(key);
|
|
833
|
-
if (cached !== undefined) return cached;
|
|
834
|
-
|
|
835
|
-
const pending = { status: "loading", label: undefined };
|
|
836
|
-
envCache.set(key, pending);
|
|
837
|
-
context.files.readFile(".env.local")
|
|
838
|
-
.then((file) => {
|
|
839
|
-
pending.status = "ready";
|
|
840
|
-
pending.label = file.content.match(/^DEV_URL=(.+)$/m)?.[1];
|
|
841
|
-
context.host.requestRender();
|
|
842
|
-
})
|
|
843
|
-
.catch(() => {
|
|
844
|
-
pending.status = "missing";
|
|
845
|
-
context.host.requestRender();
|
|
846
|
-
});
|
|
847
|
-
return pending;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
workspaceLabels: [
|
|
851
|
-
{
|
|
852
|
-
id: "dev-url",
|
|
853
|
-
items: (context) => {
|
|
854
|
-
const cached = loadEnvLabel(context);
|
|
855
|
-
return cached.label === undefined ? [] : [{
|
|
856
|
-
type: "link",
|
|
857
|
-
text: cached.label,
|
|
858
|
-
href: cached.label,
|
|
859
|
-
target: "_blank",
|
|
860
|
-
}];
|
|
861
|
-
},
|
|
862
|
-
},
|
|
863
|
-
]
|
|
864
|
-
```
|
|
865
|
-
|
|
866
|
-
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.
|
|
867
|
-
|
|
868
|
-
## Listing workspace files
|
|
869
|
-
|
|
870
|
-
`files.listFiles(path)` lists the entries of a workspace directory. Pass `""` for the workspace root. Like `readFile`, PI WEB binds the call to the callback's machine and workspace, so it works the same for local and federated machines.
|
|
871
|
-
|
|
872
|
-
```js
|
|
873
|
-
const listing = await context.files.listFiles("src");
|
|
874
|
-
for (const entry of listing.entries) {
|
|
875
|
-
// entry: { name, path, type: "file" | "directory" | "symlink", size?, modifiedAt? }
|
|
876
|
-
}
|
|
877
|
-
```
|
|
878
|
-
|
|
879
|
-
The listing response includes `path`, `entries`, `scannedAt`, and `truncated`. When `truncated` is true, the server cut the listing short, so treat the entries as partial.
|
|
880
|
-
|
|
881
|
-
`listFiles` rejects when the directory does not exist or cannot be read, matching `readFile` error behavior. When a directory is optional, catch the error and treat it as an empty listing:
|
|
882
|
-
|
|
883
|
-
```js
|
|
884
|
-
async function listSubdirectoryNames(context, path) {
|
|
885
|
-
try {
|
|
886
|
-
const listing = await context.files.listFiles(path);
|
|
887
|
-
return listing.entries.filter((entry) => entry.type === "directory").map((entry) => entry.name);
|
|
888
|
-
} catch {
|
|
889
|
-
return [];
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
```
|
|
893
|
-
|
|
894
|
-
## Writing, deleting, and moving workspace files
|
|
895
|
-
|
|
896
|
-
Workspace panels and workspace labels can write, delete, and move files through the documented `files` helper. Like `readFile`, PI WEB binds these helpers to the callback's machine and workspace, so they work the same for local and federated machines.
|
|
897
|
-
|
|
898
|
-
### Writing files
|
|
899
|
-
|
|
900
|
-
```js
|
|
901
|
-
workspacePanels: [
|
|
902
|
-
{
|
|
903
|
-
id: "workspace.generate",
|
|
904
|
-
title: "Generate",
|
|
905
|
-
render: ({ files }) => html`
|
|
906
|
-
<button @click=${async () => {
|
|
907
|
-
const result = await files.writeFile("output/result.txt", "Generated content\n");
|
|
908
|
-
console.log("Wrote", result.path, result.size, "bytes");
|
|
909
|
-
}}>Generate</button>
|
|
910
|
-
`,
|
|
911
|
-
},
|
|
912
|
-
]
|
|
913
|
-
```
|
|
914
|
-
|
|
915
|
-
### Binary writes
|
|
916
|
-
|
|
917
|
-
Pass a `Uint8Array` for binary content such as images:
|
|
918
|
-
|
|
919
|
-
```js
|
|
920
|
-
const png = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a]);
|
|
921
|
-
await files.writeFile("screenshots/thumb.png", png);
|
|
922
|
-
```
|
|
923
|
-
|
|
924
|
-
### Options
|
|
925
|
-
|
|
926
|
-
`files.writeFile` accepts an optional third argument:
|
|
927
|
-
|
|
928
|
-
- `createDirs` (default `true`): create intermediate directories, like `mkdir -p`.
|
|
929
|
-
- `overwrite` (default `true`): overwrite existing files. Set to `false` to throw if the file already exists.
|
|
930
|
-
|
|
931
|
-
```js
|
|
932
|
-
// Create only — throw if the file already exists
|
|
933
|
-
await files.writeFile("config/new-config.json", jsonContent, { overwrite: false });
|
|
934
|
-
```
|
|
935
|
-
|
|
936
|
-
### Deleting files
|
|
937
|
-
|
|
938
|
-
`files.deleteFile` removes a workspace file. It is idempotent: deleting a file that does not exist returns `{ existed: false }` instead of throwing.
|
|
939
|
-
|
|
940
|
-
```js
|
|
941
|
-
const result = await files.deleteFile("temp/cache.json");
|
|
942
|
-
console.log(result.existed ? "File deleted" : "File did not exist");
|
|
943
|
-
```
|
|
944
|
-
|
|
945
|
-
### Moving files
|
|
258
|
+
**仅安装可信插件。** 浏览器入口在页面内运行;服务端入口在守护进程内使用其文件系统、环境及进程权限,没有独立沙箱。阻塞或故障服务端代码可影响同一守护进程所有会话;超时只能帮助配合取消的工作,不能停止阻塞代码。管理嵌入继续保留独立认证、授权资源、能力与审计边界,不向插件放开普通模式能力。
|
|
946
259
|
|
|
947
|
-
|
|
260
|
+
先在目标机器 **设置 → PI WEB 插件** 检查安装、启用、兼容和激活状态。浏览器失败看控制台,服务端失败在目标机器执行 `pi-web logs`。过期或需重启状态通常需要重启守护进程后刷新浏览器。
|
|
948
261
|
|
|
949
|
-
|
|
950
|
-
// Rename a file
|
|
951
|
-
await files.moveFile("old-name.txt", "new-name.txt");
|
|
262
|
+
UI 无法恢复时,在目标机器直接运行:
|
|
952
263
|
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
// Move without creating intermediate directories
|
|
960
|
-
await files.moveFile("file.txt", "deep/nested/file.txt", { createDirs: false }); // throws if dirs don't exist
|
|
961
|
-
```
|
|
962
|
-
|
|
963
|
-
`files.moveFile` accepts an optional third argument:
|
|
964
|
-
|
|
965
|
-
- `createDirs` (default `true`): create intermediate directories for the target path.
|
|
966
|
-
- `overwrite` (default `false`): overwrite the target file if it exists. The default is safer than `writeFile` because moving is a more destructive operation.
|
|
967
|
-
|
|
968
|
-
### Error handling
|
|
969
|
-
|
|
970
|
-
All file mutations share the same safety layer:
|
|
971
|
-
|
|
972
|
-
- `overwrite: false` on `writeFile` or existing target on `moveFile` (default) throws if the file already exists.
|
|
973
|
-
- Path traversal (e.g., `../../etc/passwd`) is blocked by the workspace safety layer.
|
|
974
|
-
- Writing to or moving to a path that is a directory returns an error.
|
|
975
|
-
- Deleting a directory returns an error.
|
|
976
|
-
- Intermediate directory creation with `createDirs: false` fails if the parent directory does not exist.
|
|
977
|
-
|
|
978
|
-
After any mutation (`writeFile`, `deleteFile`, or `moveFile`), the File Explorer updates automatically. No explicit `refreshFiles()` call is needed from plugin code. For label and badge updates, call `context.host.requestRender()` if the UI should reflect the change.
|
|
979
|
-
|
|
980
|
-
### Security
|
|
981
|
-
|
|
982
|
-
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.
|
|
983
|
-
|
|
984
|
-
## Running workspace terminal commands
|
|
985
|
-
|
|
986
|
-
Workspace panels can start terminal commands through the documented `terminal` helper. Commands run in the current workspace on the panel's machine.
|
|
987
|
-
|
|
988
|
-
```js
|
|
989
|
-
render: ({ terminal }) => html`
|
|
990
|
-
<button @click=${() => terminal.runCommand({
|
|
991
|
-
title: "Build",
|
|
992
|
-
command: "npm run build",
|
|
993
|
-
open: true,
|
|
994
|
-
metadata: { "my-plugin.task": "build" },
|
|
995
|
-
})}>Build</button>
|
|
996
|
-
`
|
|
997
|
-
```
|
|
998
|
-
|
|
999
|
-
Review command strings carefully. They are trusted shell commands executed in the workspace terminal.
|
|
1000
|
-
|
|
1001
|
-
## Private and experimental PI WEB APIs
|
|
1002
|
-
|
|
1003
|
-
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.
|
|
1004
|
-
|
|
1005
|
-
The stable browser API is the documented helper surface and the type-only `@chainingintention/pi-web-cn/plugin-api` export. The stable server API is the separate type-only `@chainingintention/pi-web-cn/server-plugin-api` export. The former browser `plugin-api/unstable` entry is not part of API v2 and is no longer exported. Code that deliberately depends on another private runtime surface must keep that dependency local and expect to revisit it after PI WEB upgrades.
|
|
1006
|
-
|
|
1007
|
-
## Async data and caching
|
|
1008
|
-
|
|
1009
|
-
PI WEB does not provide a plugin cache/invalidation framework. Keep host callbacks cheap:
|
|
1010
|
-
|
|
1011
|
-
- simple contributions should be synchronous and cheap;
|
|
1012
|
-
- expensive or async work should live inside the plugin;
|
|
1013
|
-
- custom elements in `type: "render"` label items or panels are a good place to own async loading;
|
|
1014
|
-
- dedupe async reads/commands and avoid unbounded polling;
|
|
1015
|
-
- clean up intervals/event listeners in custom elements' `disconnectedCallback()`.
|
|
1016
|
-
|
|
1017
|
-
## Agent implementation checklist
|
|
1018
|
-
|
|
1019
|
-
If you are an AI agent building or editing a PI WEB plugin, follow this checklist:
|
|
1020
|
-
|
|
1021
|
-
1. Create or update a plugin folder with `package.json` and a JavaScript module such as `pi-web-plugin.js`.
|
|
1022
|
-
2. Use the single supported package metadata shape: `piWeb.plugins` array with `{ id, module, machineSpecific? }` entries.
|
|
1023
|
-
3. Default-export `{ apiVersion: 2, name, activate }` from a browser module. Server modules use server-plugin API v1.
|
|
1024
|
-
4. Return `{ contributions: { actions, workspacePanels, workspaceLabels } }` from `activate()`.
|
|
1025
|
-
5. Use ids matching `^[a-z][a-z0-9.-]*$`.
|
|
1026
|
-
6. Use the activation context's `html` function for Lit templates.
|
|
1027
|
-
7. Keep `activate()` synchronous and cheap; return contribution definitions only.
|
|
1028
|
-
8. Add actions for command-palette operations.
|
|
1029
|
-
9. Add workspace panels for larger workspace UI.
|
|
1030
|
-
10. Add workspace labels for compact inline metadata.
|
|
1031
|
-
11. Return arrays from workspace label `items()`; return an empty array to render nothing.
|
|
1032
|
-
12. Use documented context helpers first: `files`, `terminal`, `host.requestRender`, `workspace`, `machine`, `state.selectedWorkspace`, `state.selectedSession`, `state.piWebStatus`, and `prompt`.
|
|
1033
|
-
13. Do not fetch PI WEB `/api/...` endpoints directly unless you intentionally accept private API churn; prefer documented helpers such as the paired workspace `backend` bridge.
|
|
1034
|
-
14. Treat plugins as trusted code and avoid reading or displaying secrets unless intentional.
|
|
1035
|
-
15. After local edits, tell the user to hard reload the browser and check the console for plugin errors.
|
|
1036
|
-
|
|
1037
|
-
## Troubleshooting
|
|
1038
|
-
|
|
1039
|
-
Check discovery:
|
|
1040
|
-
|
|
1041
|
-
```bash
|
|
1042
|
-
curl http://127.0.0.1:8504/pi-web-plugins/manifest.json
|
|
264
|
+
```sh
|
|
265
|
+
pi-web plugins disable <plugin-id> --restart
|
|
266
|
+
pi-web plugins safe-start show
|
|
267
|
+
pi-web plugins safe-start set bundled-only --restart
|
|
268
|
+
pi-web plugins safe-start set none --restart
|
|
269
|
+
pi-web plugins safe-start clear --restart
|
|
1043
270
|
```
|
|
1044
271
|
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
```
|
|
272
|
+
- **disable** 禁止指定可选插件在下次启动加载,拒绝禁用必需终端。
|
|
273
|
+
- **bundled-only** 排除外部服务端插件,保留内置工具及必需终端。
|
|
274
|
+
- **none** 不导入任何服务端插件;诊断和项目目录工作区仍可用,但终端与依赖终端的工作流不可用。
|
|
275
|
+
- **clear** 修复或移除故障包后恢复普通启动。
|
|
1050
276
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
- invalid plugin id or contribution id;
|
|
1054
|
-
- missing default export;
|
|
1055
|
-
- missing browser `apiVersion: 2`, `name`, or `activate` function;
|
|
1056
|
-
- missing `package.json` or incorrect `piWeb.plugins` metadata;
|
|
1057
|
-
- legacy shortcuts such as `piWeb.plugin`, string plugin entries, or no-`package.json` fallback;
|
|
1058
|
-
- duplicate plugin ids; later duplicates are skipped rather than renamed;
|
|
1059
|
-
- entry module path points outside the plugin root or file does not exist;
|
|
1060
|
-
- browser cache not refreshed after editing;
|
|
1061
|
-
- plugin directory is not under `~/.pi-web/plugins` or symlinked there;
|
|
1062
|
-
- plugin throws during module import, `activate()`, `visible()`, `enabled()`, `items()`, or `render()`; check the browser console.
|
|
277
|
+
安全启动持久保留直到清除。`--restart` 仅在识别到安全的已安装服务操作时重启,否则给出手动指引;配置在尝试重启前持久保存。命令离线编辑配置,不导入插件代码。自定义配置加 `--config /path/to/config.json`。有效 JSON 中不支持的 `serverPlugins.safeStart` 形状/值按 `none` 失败关闭;通过 `show`、`set` 或 `clear` 修复。重启前检查活跃工作。
|