@chainingintention/pi-web-cn 1.202610.1 → 1.202610.2
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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-web/terminal-plugin",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"piWeb": {
|
|
6
|
+
"plugins": [
|
|
7
|
+
{
|
|
8
|
+
"id": "pi-web.terminal",
|
|
9
|
+
"browserRoot": "browser",
|
|
10
|
+
"module": "browser/pi-web-plugin.js",
|
|
11
|
+
"serverModule": "server-plugin.js",
|
|
12
|
+
"machineSpecific": true
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
// Generated from pi-web-plugins/terminal/server/server-plugin.ts. Do not edit directly.
|
|
2
|
+
import { TerminalService, } from "./terminalService.js";
|
|
3
|
+
const TERMINAL_CHANNEL_OUTPUT_FRAME_TARGET_BYTES = 60 * 1024;
|
|
4
|
+
export const TERMINAL_SERVICE_CAPABILITY = Object.freeze({
|
|
5
|
+
pluginId: "pi-web.terminal",
|
|
6
|
+
id: "service",
|
|
7
|
+
version: 1,
|
|
8
|
+
parse: snapshotTerminalServiceCapability,
|
|
9
|
+
});
|
|
10
|
+
const plugin = {
|
|
11
|
+
apiVersion: 3,
|
|
12
|
+
name: "终端",
|
|
13
|
+
activate(context) {
|
|
14
|
+
return activateTerminalPlugin(context);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export default plugin;
|
|
18
|
+
export function activateTerminalPlugin(context) {
|
|
19
|
+
if (context.pluginId !== "pi-web.terminal") {
|
|
20
|
+
throw new Error(`终端服务端入口必须以插件标识 pi-web.terminal 激活,实际为 ${context.pluginId}`);
|
|
21
|
+
}
|
|
22
|
+
const notices = context.notices;
|
|
23
|
+
if (notices?.version !== 1) {
|
|
24
|
+
throw new Error("终端服务端入口需要版本 1 的服务通知报告器");
|
|
25
|
+
}
|
|
26
|
+
const service = new TerminalService((input) => { notices.record(input); });
|
|
27
|
+
const requiredTerminalService = Object.freeze({
|
|
28
|
+
closeForCwd: (cwd) => { service.closeForCwd(cwd); },
|
|
29
|
+
runCommand: (options) => service.runCommand(options),
|
|
30
|
+
bindActivitySink: (sink) => { service.bindActivitySink(sink); },
|
|
31
|
+
});
|
|
32
|
+
const serviceProvision = Object.freeze({
|
|
33
|
+
capability: TERMINAL_SERVICE_CAPABILITY,
|
|
34
|
+
value: requiredTerminalService,
|
|
35
|
+
});
|
|
36
|
+
let stopped = false;
|
|
37
|
+
return Object.freeze({
|
|
38
|
+
peer: createTerminalPeer(service, context),
|
|
39
|
+
provides: Object.freeze([serviceProvision]),
|
|
40
|
+
health: () => stopped
|
|
41
|
+
? Object.freeze({ status: "unhealthy", message: "终端服务已停止" })
|
|
42
|
+
: Object.freeze({ status: "healthy" }),
|
|
43
|
+
dispose: () => {
|
|
44
|
+
if (stopped)
|
|
45
|
+
return;
|
|
46
|
+
stopped = true;
|
|
47
|
+
service.dispose();
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function snapshotTerminalServiceCapability(value) {
|
|
52
|
+
if (!isRequiredTerminalServiceContribution(value)) {
|
|
53
|
+
throw new Error("终端服务能力必须提供 closeForCwd、runCommand 和 bindActivitySink");
|
|
54
|
+
}
|
|
55
|
+
return Object.freeze({
|
|
56
|
+
closeForCwd: (cwd) => { value.closeForCwd(cwd); },
|
|
57
|
+
runCommand: (options) => value.runCommand(options),
|
|
58
|
+
bindActivitySink: (sink) => { value.bindActivitySink(sink); },
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function isRequiredTerminalServiceContribution(value) {
|
|
62
|
+
if (typeof value !== "object" || value === null)
|
|
63
|
+
return false;
|
|
64
|
+
return typeof Reflect.get(value, "closeForCwd") === "function"
|
|
65
|
+
&& typeof Reflect.get(value, "runCommand") === "function"
|
|
66
|
+
&& typeof Reflect.get(value, "bindActivitySink") === "function";
|
|
67
|
+
}
|
|
68
|
+
export function createTerminalPeer(service, activationContext) {
|
|
69
|
+
return Object.freeze({
|
|
70
|
+
request: (context) => terminalRequest(service, context),
|
|
71
|
+
openChannel: (context) => openTerminalChannel(service, context, activationContext),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function terminalRequest(service, context) {
|
|
75
|
+
throwIfAborted(context.signal);
|
|
76
|
+
const scope = terminalScope(context);
|
|
77
|
+
switch (context.operation) {
|
|
78
|
+
case "terminal.list":
|
|
79
|
+
requireNullishInput(context.input, context.operation);
|
|
80
|
+
return service.list(scope).map(terminalInfoJson);
|
|
81
|
+
case "terminal.create": {
|
|
82
|
+
const input = requireObject(context.input, context.operation);
|
|
83
|
+
return terminalInfoJson(service.create({
|
|
84
|
+
...scope,
|
|
85
|
+
...optionalTerminalName(input),
|
|
86
|
+
...optionalTerminalSize(input),
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
case "terminal.close": {
|
|
90
|
+
service.close(scope, requireIdInput(context.input, context.operation, "terminalId"));
|
|
91
|
+
return { closed: true };
|
|
92
|
+
}
|
|
93
|
+
case "terminal.continue":
|
|
94
|
+
return terminalInfoJson(service.continue(scope, requireIdInput(context.input, context.operation, "terminalId")));
|
|
95
|
+
case "terminal.run": {
|
|
96
|
+
const input = requireObject(context.input, context.operation);
|
|
97
|
+
return commandRunJson(service.runCommand(parseRunCommand(scope, input)));
|
|
98
|
+
}
|
|
99
|
+
case "terminal.list-runs": {
|
|
100
|
+
const input = requireObjectOrEmpty(context.input, context.operation);
|
|
101
|
+
return service.listCommandRunsForScope(scope, parseCommandRunFilter(input)).map(commandRunJson);
|
|
102
|
+
}
|
|
103
|
+
case "terminal.get-run": {
|
|
104
|
+
const run = service.getCommandRunForScope(scope, requireIdInput(context.input, context.operation, "runId"));
|
|
105
|
+
return run === undefined ? null : commandRunJson(run);
|
|
106
|
+
}
|
|
107
|
+
case "terminal.cancel-run":
|
|
108
|
+
return commandRunJson(service.cancelCommandRunForScope(scope, requireIdInput(context.input, context.operation, "runId")));
|
|
109
|
+
default:
|
|
110
|
+
throw new Error(`不支持的终端操作: ${context.operation}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function openTerminalChannel(service, context, activationContext) {
|
|
114
|
+
if (context.operation !== "terminal.attach") {
|
|
115
|
+
throw new Error(`不支持的终端通道操作: ${context.operation}`);
|
|
116
|
+
}
|
|
117
|
+
throwIfAborted(context.signal);
|
|
118
|
+
const scope = terminalScope(context);
|
|
119
|
+
const input = requireObject(context.input, context.operation);
|
|
120
|
+
const terminalId = requireString(input, "terminalId", context.operation);
|
|
121
|
+
const size = optionalTerminalSize(input);
|
|
122
|
+
if (size.cols !== undefined && size.rows !== undefined) {
|
|
123
|
+
service.resize(scope, terminalId, size.cols, size.rows);
|
|
124
|
+
}
|
|
125
|
+
let resolveCompleted = () => undefined;
|
|
126
|
+
const completed = new Promise((resolve) => { resolveCompleted = resolve; });
|
|
127
|
+
let opening = true;
|
|
128
|
+
let detach = () => undefined;
|
|
129
|
+
const send = (frame) => {
|
|
130
|
+
try {
|
|
131
|
+
context.send(frame);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (opening)
|
|
135
|
+
throw error;
|
|
136
|
+
detach();
|
|
137
|
+
activationContext?.logger.error("终端通道输出失败", {
|
|
138
|
+
terminalId,
|
|
139
|
+
message: boundedErrorMessage(error),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
detach = service.attach(scope, terminalId, {
|
|
144
|
+
output(data, replay) {
|
|
145
|
+
for (const frame of terminalOutputFrames(data, replay))
|
|
146
|
+
send(frame);
|
|
147
|
+
},
|
|
148
|
+
exit(exitCode) {
|
|
149
|
+
send({ type: "exit", ...(exitCode === undefined ? {} : { exitCode }) });
|
|
150
|
+
},
|
|
151
|
+
closed() {
|
|
152
|
+
resolveCompleted();
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
opening = false;
|
|
156
|
+
let cleanedUp = false;
|
|
157
|
+
const cleanup = () => {
|
|
158
|
+
if (cleanedUp)
|
|
159
|
+
return;
|
|
160
|
+
cleanedUp = true;
|
|
161
|
+
context.signal.removeEventListener("abort", cleanup);
|
|
162
|
+
detach();
|
|
163
|
+
};
|
|
164
|
+
context.signal.addEventListener("abort", cleanup, { once: true });
|
|
165
|
+
return Object.freeze({
|
|
166
|
+
closed: completed,
|
|
167
|
+
receive(data, signal) {
|
|
168
|
+
throwIfAborted(signal);
|
|
169
|
+
throwIfAborted(context.signal);
|
|
170
|
+
const frame = requireObject(data, "terminal.attach frame");
|
|
171
|
+
const type = requireString(frame, "type", "terminal.attach frame");
|
|
172
|
+
if (type === "input") {
|
|
173
|
+
service.write(scope, terminalId, requireTerminalInputData(frame));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (type === "resize") {
|
|
177
|
+
const parsed = requireTerminalSize(frame, "terminal.attach resize frame");
|
|
178
|
+
service.resize(scope, terminalId, parsed.cols, parsed.rows);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
throw new Error(`不支持的终端通道消息: ${type}`);
|
|
182
|
+
},
|
|
183
|
+
close() {
|
|
184
|
+
cleanup();
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function terminalScope(context) {
|
|
189
|
+
if (context.workspace.projectId !== context.project.id) {
|
|
190
|
+
throw new Error("终端工作区的项目作用域与宿主项目不匹配");
|
|
191
|
+
}
|
|
192
|
+
return Object.freeze({
|
|
193
|
+
projectId: context.project.id,
|
|
194
|
+
workspaceId: context.workspace.id,
|
|
195
|
+
cwd: context.workspace.path,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function parseRunCommand(scope, input) {
|
|
199
|
+
const metadata = input["metadata"];
|
|
200
|
+
return {
|
|
201
|
+
...scope,
|
|
202
|
+
origin: requireString(input, "origin", "terminal.run"),
|
|
203
|
+
title: requireString(input, "title", "terminal.run"),
|
|
204
|
+
command: requireString(input, "command", "terminal.run"),
|
|
205
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
206
|
+
...optionalTerminalSize(input),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function parseCommandRunFilter(input) {
|
|
210
|
+
const terminalId = optionalString(input, "terminalId", "terminal.list-runs");
|
|
211
|
+
const metadataValue = input["metadata"];
|
|
212
|
+
const statusesValue = input["statuses"];
|
|
213
|
+
const metadata = metadataValue === undefined ? undefined : stringRecord(metadataValue, "terminal.list-runs metadata");
|
|
214
|
+
const statuses = statusesValue === undefined ? undefined : requireArray(statusesValue, "terminal.list-runs statuses").map((status) => parseCommandRunStatus(status));
|
|
215
|
+
return {
|
|
216
|
+
...(terminalId === undefined ? {} : { terminalId }),
|
|
217
|
+
...(statuses === undefined ? {} : { statuses }),
|
|
218
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function terminalInfoJson(info) {
|
|
222
|
+
return {
|
|
223
|
+
id: info.id,
|
|
224
|
+
cwd: info.cwd,
|
|
225
|
+
name: info.name,
|
|
226
|
+
createdAt: info.createdAt,
|
|
227
|
+
exited: info.exited,
|
|
228
|
+
...(info.exitCode === undefined ? {} : { exitCode: info.exitCode }),
|
|
229
|
+
...(info.commandRunId === undefined ? {} : { commandRunId: info.commandRunId }),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function commandRunJson(run) {
|
|
233
|
+
return {
|
|
234
|
+
id: run.id,
|
|
235
|
+
origin: run.origin,
|
|
236
|
+
projectId: run.projectId,
|
|
237
|
+
workspaceId: run.workspaceId,
|
|
238
|
+
terminalId: run.terminalId,
|
|
239
|
+
title: run.title,
|
|
240
|
+
command: run.command,
|
|
241
|
+
status: run.status,
|
|
242
|
+
...(run.exitCode === undefined ? {} : { exitCode: run.exitCode }),
|
|
243
|
+
createdAt: run.createdAt,
|
|
244
|
+
...(run.startedAt === undefined ? {} : { startedAt: run.startedAt }),
|
|
245
|
+
...(run.completedAt === undefined ? {} : { completedAt: run.completedAt }),
|
|
246
|
+
metadata: { ...run.metadata },
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function optionalTerminalName(input) {
|
|
250
|
+
const name = optionalString(input, "name", "terminal.create");
|
|
251
|
+
return name === undefined ? {} : { name };
|
|
252
|
+
}
|
|
253
|
+
function optionalTerminalSize(input) {
|
|
254
|
+
const cols = input["cols"];
|
|
255
|
+
const rows = input["rows"];
|
|
256
|
+
if (cols === undefined && rows === undefined)
|
|
257
|
+
return {};
|
|
258
|
+
return requireTerminalSize(input, "Terminal size");
|
|
259
|
+
}
|
|
260
|
+
function requireTerminalSize(input, label) {
|
|
261
|
+
const cols = input["cols"];
|
|
262
|
+
const rows = input["rows"];
|
|
263
|
+
if (typeof cols !== "number" || !Number.isFinite(cols) || cols <= 0)
|
|
264
|
+
throw new Error(`${label} cols 必须是正数`);
|
|
265
|
+
if (typeof rows !== "number" || !Number.isFinite(rows) || rows <= 0)
|
|
266
|
+
throw new Error(`${label} rows 必须是正数`);
|
|
267
|
+
return { cols: Math.floor(cols), rows: Math.floor(rows) };
|
|
268
|
+
}
|
|
269
|
+
function requireIdInput(input, operation, key) {
|
|
270
|
+
return requireString(requireObject(input, operation), key, operation);
|
|
271
|
+
}
|
|
272
|
+
function requireObject(value, label) {
|
|
273
|
+
if (!isJsonObject(value))
|
|
274
|
+
throw new Error(`${label} 输入必须是对象`);
|
|
275
|
+
return value;
|
|
276
|
+
}
|
|
277
|
+
function isJsonObject(value) {
|
|
278
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
279
|
+
}
|
|
280
|
+
function requireObjectOrEmpty(value, label) {
|
|
281
|
+
return value === null ? {} : requireObject(value, label);
|
|
282
|
+
}
|
|
283
|
+
function requireNullishInput(value, label) {
|
|
284
|
+
if (value !== null && (typeof value !== "object" || Array.isArray(value) || Object.keys(value).length > 0)) {
|
|
285
|
+
throw new Error(`${label} 输入必须是 null 或空对象`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function requireString(record, key, label) {
|
|
289
|
+
const value = record[key];
|
|
290
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
291
|
+
throw new Error(`${label} ${key} 必须是非空字符串`);
|
|
292
|
+
return value;
|
|
293
|
+
}
|
|
294
|
+
function requireTerminalInputData(record) {
|
|
295
|
+
const value = record["data"];
|
|
296
|
+
if (typeof value !== "string" || value === "")
|
|
297
|
+
throw new Error("terminal.attach input frame data 必须是非空字符串");
|
|
298
|
+
return value;
|
|
299
|
+
}
|
|
300
|
+
function optionalString(record, key, label) {
|
|
301
|
+
const value = record[key];
|
|
302
|
+
if (value === undefined)
|
|
303
|
+
return undefined;
|
|
304
|
+
if (typeof value !== "string")
|
|
305
|
+
throw new Error(`${label} ${key} 必须是字符串`);
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
function stringRecord(value, label) {
|
|
309
|
+
const record = requireObject(value, label);
|
|
310
|
+
return Object.fromEntries(Object.entries(record).map(([key, child]) => {
|
|
311
|
+
if (typeof child !== "string")
|
|
312
|
+
throw new Error(`${label} ${key} 必须是字符串`);
|
|
313
|
+
return [key, child];
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
316
|
+
function requireArray(value, label) {
|
|
317
|
+
if (!isJsonArray(value))
|
|
318
|
+
throw new Error(`${label} 必须是数组`);
|
|
319
|
+
return value;
|
|
320
|
+
}
|
|
321
|
+
function isJsonArray(value) {
|
|
322
|
+
return Array.isArray(value);
|
|
323
|
+
}
|
|
324
|
+
function parseCommandRunStatus(value) {
|
|
325
|
+
if (value === "queued" || value === "running" || value === "succeeded" || value === "failed")
|
|
326
|
+
return value;
|
|
327
|
+
throw new Error(`无效的终端命令运行状态: ${JSON.stringify(value)}`);
|
|
328
|
+
}
|
|
329
|
+
export function terminalOutputFrames(value, replay) {
|
|
330
|
+
const emptyFrame = terminalOutputFrame("", replay, false);
|
|
331
|
+
const emptyFrameBytes = Buffer.byteLength(JSON.stringify(emptyFrame), "utf8");
|
|
332
|
+
const chunks = [];
|
|
333
|
+
let chunk = "";
|
|
334
|
+
let encodedBytes = emptyFrameBytes;
|
|
335
|
+
for (const character of value) {
|
|
336
|
+
// JSON escaping can expand control characters well beyond their raw UTF-8
|
|
337
|
+
// size, so budget the serialized representation rather than the PTY text.
|
|
338
|
+
const characterBytes = Buffer.byteLength(JSON.stringify(character), "utf8") - 2;
|
|
339
|
+
if (encodedBytes + characterBytes > TERMINAL_CHANNEL_OUTPUT_FRAME_TARGET_BYTES && chunk !== "") {
|
|
340
|
+
chunks.push(chunk);
|
|
341
|
+
chunk = "";
|
|
342
|
+
encodedBytes = emptyFrameBytes;
|
|
343
|
+
}
|
|
344
|
+
chunk += character;
|
|
345
|
+
encodedBytes += characterBytes;
|
|
346
|
+
}
|
|
347
|
+
if (chunk !== "" || value === "")
|
|
348
|
+
chunks.push(chunk);
|
|
349
|
+
return chunks.map((data, index) => terminalOutputFrame(data, replay, index === chunks.length - 1));
|
|
350
|
+
}
|
|
351
|
+
function terminalOutputFrame(data, replay, replayComplete) {
|
|
352
|
+
return replay
|
|
353
|
+
? { type: "output", data, replay: true, replayComplete }
|
|
354
|
+
: { type: "output", data, replay: false };
|
|
355
|
+
}
|
|
356
|
+
function throwIfAborted(signal) {
|
|
357
|
+
if (!signal.aborted)
|
|
358
|
+
return;
|
|
359
|
+
const reason = signal.reason;
|
|
360
|
+
throw reason instanceof Error ? reason : new Error("终端操作已取消", { cause: reason });
|
|
361
|
+
}
|
|
362
|
+
function boundedErrorMessage(error) {
|
|
363
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
364
|
+
return message.length <= 1_024 ? message : `${message.slice(0, 1_021)}...`;
|
|
365
|
+
}
|