@agimon-ai/po 0.0.0-alpha.21 → 0.0.0-alpha.211
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/LICENSE +97 -8
- package/README.md +37 -722
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts +2 -2
- package/dist/bin/cli.cjs +12 -7
- package/dist/bin/cli.cjs.map +1 -1
- package/dist/bin/cli.mjs +12 -7
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/bin/poRunner.cjs +24 -7
- package/dist/bin/poRunner.cjs.map +1 -1
- package/dist/bin/poRunner.d.mts +8 -0
- package/dist/bin/poRunner.d.mts.map +1 -1
- package/dist/bin/poRunner.mjs +24 -7
- package/dist/bin/poRunner.mjs.map +1 -1
- package/dist/bin/serve.cjs +28 -17
- package/dist/bin/serve.cjs.map +1 -1
- package/dist/bin/serve.mjs +28 -17
- package/dist/bin/serve.mjs.map +1 -1
- package/dist/builders/cli/extensionAssembler/index.cjs +53 -40
- package/dist/builders/cli/extensionAssembler/index.cjs.map +1 -1
- package/dist/builders/cli/extensionAssembler/index.d.mts +11 -6
- package/dist/builders/cli/extensionAssembler/index.d.mts.map +1 -1
- package/dist/builders/cli/extensionAssembler/index.mjs +53 -41
- package/dist/builders/cli/extensionAssembler/index.mjs.map +1 -1
- package/dist/catalog/index.json +662 -105
- package/dist/cli.cjs +9 -14
- package/dist/cli.d.mts +1 -3
- package/dist/cli.mjs +1 -3
- package/dist/commands.cjs +13 -15
- package/dist/commands.d.mts +1 -2
- package/dist/commands.mjs +1 -2
- package/dist/config.cjs +9 -14
- package/dist/config.d.mts +3 -2
- package/dist/config.mjs +3 -2
- package/dist/extensions/server.cjs +30 -23
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +31 -24
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/harnessContext.cjs +0 -1
- package/dist/harnessContext.d.mts +2 -2
- package/dist/harnessContext.mjs +1 -1
- package/dist/harnessState.cjs +2 -1
- package/dist/help.cjs +9 -11
- package/dist/help.d.mts +1 -2
- package/dist/help.mjs +1 -2
- package/dist/index.cjs +40 -67
- package/dist/index.d.mts +7 -16
- package/dist/index.mjs +7 -14
- package/dist/locales/vi.cjs +218 -0
- package/dist/locales/vi.cjs.map +1 -0
- package/dist/locales/vi.mjs +213 -0
- package/dist/locales/vi.mjs.map +1 -0
- package/dist/locales/zh-CN.cjs +218 -0
- package/dist/locales/zh-CN.cjs.map +1 -0
- package/dist/locales/zh-CN.mjs +213 -0
- package/dist/locales/zh-CN.mjs.map +1 -0
- package/dist/matrixOptions.cjs +10 -5
- package/dist/matrixOptions.d.mts +2 -2
- package/dist/matrixOptions.mjs +1 -1
- package/dist/package.cjs +11 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.mjs +6 -0
- package/dist/package.mjs.map +1 -0
- package/dist/projectTrust.cjs +3 -0
- package/dist/projectTrust.d.mts +2 -2
- package/dist/projectTrust.mjs +1 -1
- package/dist/repository.cjs +1 -0
- package/dist/repository.d.mts +2 -2
- package/dist/repository.mjs +1 -1
- package/dist/services.cjs +5 -20
- package/dist/services.d.mts +3 -8
- package/dist/services.mjs +3 -8
- package/dist/shared.cjs +4 -17
- package/dist/shared.d.mts +2 -2
- package/dist/shared.mjs +1 -1
- package/dist/src/bin/agentDirectory.cjs +19 -15
- package/dist/src/bin/agentDirectory.cjs.map +1 -1
- package/dist/src/bin/agentDirectory.mjs +16 -13
- package/dist/src/bin/agentDirectory.mjs.map +1 -1
- package/dist/src/builders/apiContractExport/index.cjs +23 -22
- package/dist/src/builders/apiContractExport/index.cjs.map +1 -1
- package/dist/src/builders/apiContractExport/index.mjs +22 -21
- package/dist/src/builders/apiContractExport/index.mjs.map +1 -1
- package/dist/src/builders/cli/entryResolution.cjs +2 -2
- package/dist/src/builders/cli/entryResolution.cjs.map +1 -1
- package/dist/src/builders/cli/entryResolution.mjs +1 -1
- package/dist/src/builders/cli/entryResolution.mjs.map +1 -1
- package/dist/src/builders/cli/harnessContext.cjs +38 -43
- package/dist/src/builders/cli/harnessContext.cjs.map +1 -1
- package/dist/src/builders/cli/harnessContext.d.mts +11 -10
- package/dist/src/builders/cli/harnessContext.d.mts.map +1 -1
- package/dist/src/builders/cli/harnessContext.mjs +37 -41
- package/dist/src/builders/cli/harnessContext.mjs.map +1 -1
- package/dist/src/builders/cli/sessionComposition.cjs +23 -12
- package/dist/src/builders/cli/sessionComposition.cjs.map +1 -1
- package/dist/src/builders/cli/sessionComposition.mjs +23 -12
- package/dist/src/builders/cli/sessionComposition.mjs.map +1 -1
- package/dist/src/builders/isolate/compile.cjs +226 -0
- package/dist/src/builders/isolate/compile.cjs.map +1 -0
- package/dist/src/builders/isolate/compile.mjs +222 -0
- package/dist/src/builders/isolate/compile.mjs.map +1 -0
- package/dist/src/builders/isolate/index.cjs +195 -0
- package/dist/src/builders/isolate/index.cjs.map +1 -0
- package/dist/src/builders/isolate/index.mjs +192 -0
- package/dist/src/builders/isolate/index.mjs.map +1 -0
- package/dist/src/builders/isolate/membrane.cjs +198 -0
- package/dist/src/builders/isolate/membrane.cjs.map +1 -0
- package/dist/src/builders/isolate/membrane.mjs +198 -0
- package/dist/src/builders/isolate/membrane.mjs.map +1 -0
- package/dist/src/builders/isolate/names.cjs +10 -0
- package/dist/src/builders/isolate/names.cjs.map +1 -0
- package/dist/src/builders/isolate/names.mjs +9 -0
- package/dist/src/builders/isolate/names.mjs.map +1 -0
- package/dist/src/builders/native/index.cjs +229 -67
- package/dist/src/builders/native/index.cjs.map +1 -1
- package/dist/src/builders/native/index.d.mts +4 -2
- package/dist/src/builders/native/index.d.mts.map +1 -1
- package/dist/src/builders/native/index.mjs +229 -68
- package/dist/src/builders/native/index.mjs.map +1 -1
- package/dist/src/builders/npm/index.cjs +76 -0
- package/dist/src/builders/npm/index.cjs.map +1 -0
- package/dist/src/builders/npm/index.mjs +73 -0
- package/dist/src/builders/npm/index.mjs.map +1 -0
- package/dist/src/builders/server/backgroundSync.cjs +62 -39
- package/dist/src/builders/server/backgroundSync.cjs.map +1 -1
- package/dist/src/builders/server/backgroundSync.mjs +62 -38
- package/dist/src/builders/server/backgroundSync.mjs.map +1 -1
- package/dist/src/builders/server/bundlerService.cjs +165 -35
- package/dist/src/builders/server/bundlerService.cjs.map +1 -1
- package/dist/src/builders/server/bundlerService.mjs +164 -36
- package/dist/src/builders/server/bundlerService.mjs.map +1 -1
- package/dist/src/builders/server/capabilities.cjs +103 -0
- package/dist/src/builders/server/capabilities.cjs.map +1 -0
- package/dist/src/builders/server/capabilities.mjs +101 -0
- package/dist/src/builders/server/capabilities.mjs.map +1 -0
- package/dist/src/builders/server/computerUseBinding.cjs +62 -10
- package/dist/src/builders/server/computerUseBinding.cjs.map +1 -1
- package/dist/src/builders/server/computerUseBinding.mjs +60 -8
- package/dist/src/builders/server/computerUseBinding.mjs.map +1 -1
- package/dist/src/builders/server/computerUseRecordings.cjs +152 -51
- package/dist/src/builders/server/computerUseRecordings.cjs.map +1 -1
- package/dist/src/builders/server/computerUseRecordings.mjs +158 -59
- package/dist/src/builders/server/computerUseRecordings.mjs.map +1 -1
- package/dist/src/builders/server/containedSessions.cjs +152 -0
- package/dist/src/builders/server/containedSessions.cjs.map +1 -0
- package/dist/src/builders/server/containedSessions.mjs +146 -0
- package/dist/src/builders/server/containedSessions.mjs.map +1 -0
- package/dist/src/builders/server/defaultWorkspace.cjs +46 -11
- package/dist/src/builders/server/defaultWorkspace.cjs.map +1 -1
- package/dist/src/builders/server/defaultWorkspace.mjs +42 -10
- package/dist/src/builders/server/defaultWorkspace.mjs.map +1 -1
- package/dist/src/builders/server/electronBinding.cjs +82 -0
- package/dist/src/builders/server/electronBinding.cjs.map +1 -0
- package/dist/src/builders/server/electronBinding.mjs +82 -0
- package/dist/src/builders/server/electronBinding.mjs.map +1 -0
- package/dist/src/builders/server/federation.cjs +364 -0
- package/dist/src/builders/server/federation.cjs.map +1 -0
- package/dist/src/builders/server/federation.mjs +363 -0
- package/dist/src/builders/server/federation.mjs.map +1 -0
- package/dist/src/builders/server/hostDisplayName.cjs +14 -0
- package/dist/src/builders/server/hostDisplayName.cjs.map +1 -0
- package/dist/src/builders/server/hostDisplayName.mjs +14 -0
- package/dist/src/builders/server/hostDisplayName.mjs.map +1 -0
- package/dist/src/builders/server/hostModelGateway.cjs +41 -0
- package/dist/src/builders/server/hostModelGateway.cjs.map +1 -0
- package/dist/src/builders/server/hostModelGateway.mjs +39 -0
- package/dist/src/builders/server/hostModelGateway.mjs.map +1 -0
- package/dist/src/builders/server/hostTeam.cjs +188 -0
- package/dist/src/builders/server/hostTeam.cjs.map +1 -0
- package/dist/src/builders/server/hostTeam.mjs +180 -0
- package/dist/src/builders/server/hostTeam.mjs.map +1 -0
- package/dist/src/builders/server/idleRestart.cjs +185 -40
- package/dist/src/builders/server/idleRestart.cjs.map +1 -1
- package/dist/src/builders/server/idleRestart.mjs +176 -39
- package/dist/src/builders/server/idleRestart.mjs.map +1 -1
- package/dist/src/builders/server/index.cjs +58 -19
- package/dist/src/builders/server/index.cjs.map +1 -1
- package/dist/src/builders/server/index.mjs +57 -19
- package/dist/src/builders/server/index.mjs.map +1 -1
- package/dist/src/builders/server/liveActivityPush.cjs +202 -0
- package/dist/src/builders/server/liveActivityPush.cjs.map +1 -0
- package/dist/src/builders/server/liveActivityPush.mjs +202 -0
- package/dist/src/builders/server/liveActivityPush.mjs.map +1 -0
- package/dist/src/builders/server/logSink.cjs +12 -10
- package/dist/src/builders/server/logSink.cjs.map +1 -1
- package/dist/src/builders/server/logSink.mjs +12 -10
- package/dist/src/builders/server/logSink.mjs.map +1 -1
- package/dist/src/builders/server/mcpApp.cjs +27 -20
- package/dist/src/builders/server/mcpApp.cjs.map +1 -1
- package/dist/src/builders/server/mcpApp.mjs +25 -18
- package/dist/src/builders/server/mcpApp.mjs.map +1 -1
- package/dist/src/builders/server/mcpAppBuild.cjs +61 -41
- package/dist/src/builders/server/mcpAppBuild.cjs.map +1 -1
- package/dist/src/builders/server/mcpAppBuild.d.mts +3 -6
- package/dist/src/builders/server/mcpAppBuild.d.mts.map +1 -1
- package/dist/src/builders/server/mcpAppBuild.mjs +61 -40
- package/dist/src/builders/server/mcpAppBuild.mjs.map +1 -1
- package/dist/src/builders/server/mcpBundle.cjs +20 -16
- package/dist/src/builders/server/mcpBundle.cjs.map +1 -1
- package/dist/src/builders/server/mcpBundle.d.mts +2 -1
- package/dist/src/builders/server/mcpBundle.d.mts.map +1 -1
- package/dist/src/builders/server/mcpBundle.mjs +20 -15
- package/dist/src/builders/server/mcpBundle.mjs.map +1 -1
- package/dist/src/builders/server/nativePush.cjs +229 -0
- package/dist/src/builders/server/nativePush.cjs.map +1 -0
- package/dist/src/builders/server/nativePush.mjs +228 -0
- package/dist/src/builders/server/nativePush.mjs.map +1 -0
- package/dist/src/builders/server/network.cjs +887 -0
- package/dist/src/builders/server/network.cjs.map +1 -0
- package/dist/src/builders/server/network.mjs +886 -0
- package/dist/src/builders/server/network.mjs.map +1 -0
- package/dist/src/builders/server/networkGateway.cjs +123 -0
- package/dist/src/builders/server/networkGateway.cjs.map +1 -0
- package/dist/src/builders/server/networkGateway.mjs +123 -0
- package/dist/src/builders/server/networkGateway.mjs.map +1 -0
- package/dist/src/builders/server/networkRelay.cjs +83 -0
- package/dist/src/builders/server/networkRelay.cjs.map +1 -0
- package/dist/src/builders/server/networkRelay.mjs +81 -0
- package/dist/src/builders/server/networkRelay.mjs.map +1 -0
- package/dist/src/builders/server/orgPluginLibraryBinding.cjs +72 -0
- package/dist/src/builders/server/orgPluginLibraryBinding.cjs.map +1 -0
- package/dist/src/builders/server/orgPluginLibraryBinding.mjs +72 -0
- package/dist/src/builders/server/orgPluginLibraryBinding.mjs.map +1 -0
- package/dist/src/builders/server/packageReloadCheck.cjs +46 -2
- package/dist/src/builders/server/packageReloadCheck.cjs.map +1 -1
- package/dist/src/builders/server/packageReloadCheck.mjs +46 -3
- package/dist/src/builders/server/packageReloadCheck.mjs.map +1 -1
- package/dist/src/builders/server/packageUrl.cjs +161 -58
- package/dist/src/builders/server/packageUrl.cjs.map +1 -1
- package/dist/src/builders/server/packageUrl.mjs +162 -58
- package/dist/src/builders/server/packageUrl.mjs.map +1 -1
- package/dist/src/builders/server/privateRelay.cjs +309 -0
- package/dist/src/builders/server/privateRelay.cjs.map +1 -0
- package/dist/src/builders/server/privateRelay.mjs +305 -0
- package/dist/src/builders/server/privateRelay.mjs.map +1 -0
- package/dist/src/builders/server/privateRelayCarrier.cjs +316 -0
- package/dist/src/builders/server/privateRelayCarrier.cjs.map +1 -0
- package/dist/src/builders/server/privateRelayCarrier.mjs +309 -0
- package/dist/src/builders/server/privateRelayCarrier.mjs.map +1 -0
- package/dist/src/builders/server/runtime.cjs +2750 -486
- package/dist/src/builders/server/runtime.cjs.map +1 -1
- package/dist/src/builders/server/runtime.mjs +2760 -500
- package/dist/src/builders/server/runtime.mjs.map +1 -1
- package/dist/src/builders/server/runtimeResources.cjs +37 -0
- package/dist/src/builders/server/runtimeResources.cjs.map +1 -1
- package/dist/src/builders/server/runtimeResources.mjs +38 -2
- package/dist/src/builders/server/runtimeResources.mjs.map +1 -1
- package/dist/src/builders/server/sandboxRouter.cjs +815 -0
- package/dist/src/builders/server/sandboxRouter.cjs.map +1 -0
- package/dist/src/builders/server/sandboxRouter.mjs +811 -0
- package/dist/src/builders/server/sandboxRouter.mjs.map +1 -0
- package/dist/src/builders/server/sandboxSessionHandoff.cjs +298 -0
- package/dist/src/builders/server/sandboxSessionHandoff.cjs.map +1 -0
- package/dist/src/builders/server/sandboxSessionHandoff.mjs +287 -0
- package/dist/src/builders/server/sandboxSessionHandoff.mjs.map +1 -0
- package/dist/src/builders/server/scopeReloadController.cjs +80 -0
- package/dist/src/builders/server/scopeReloadController.cjs.map +1 -0
- package/dist/src/builders/server/scopeReloadController.mjs +80 -0
- package/dist/src/builders/server/scopeReloadController.mjs.map +1 -0
- package/dist/src/builders/server/selectionStatus.cjs +2 -2
- package/dist/src/builders/server/selectionStatus.cjs.map +1 -1
- package/dist/src/builders/server/selectionStatus.mjs +2 -2
- package/dist/src/builders/server/selectionStatus.mjs.map +1 -1
- package/dist/src/builders/server/sessionArguments.cjs +65 -7
- package/dist/src/builders/server/sessionArguments.cjs.map +1 -1
- package/dist/src/builders/server/sessionArguments.mjs +64 -8
- package/dist/src/builders/server/sessionArguments.mjs.map +1 -1
- package/dist/src/builders/server/sessionRemoval.cjs +233 -0
- package/dist/src/builders/server/sessionRemoval.cjs.map +1 -0
- package/dist/src/builders/server/sessionRemoval.mjs +224 -0
- package/dist/src/builders/server/sessionRemoval.mjs.map +1 -0
- package/dist/src/builders/server/sessionSummaries.cjs +32 -0
- package/dist/src/builders/server/sessionSummaries.cjs.map +1 -0
- package/dist/src/builders/server/sessionSummaries.mjs +31 -0
- package/dist/src/builders/server/sessionSummaries.mjs.map +1 -0
- package/dist/src/builders/server/shutdown.cjs +23 -0
- package/dist/src/builders/server/shutdown.cjs.map +1 -1
- package/dist/src/builders/server/shutdown.mjs +21 -1
- package/dist/src/builders/server/shutdown.mjs.map +1 -1
- package/dist/src/builders/server/shutdownStack.cjs +44 -0
- package/dist/src/builders/server/shutdownStack.cjs.map +1 -0
- package/dist/src/builders/server/shutdownStack.mjs +43 -0
- package/dist/src/builders/server/shutdownStack.mjs.map +1 -0
- package/dist/src/builders/server/toolBoundaryHold.cjs +55 -0
- package/dist/src/builders/server/toolBoundaryHold.cjs.map +1 -0
- package/dist/src/builders/server/toolBoundaryHold.mjs +55 -0
- package/dist/src/builders/server/toolBoundaryHold.mjs.map +1 -0
- package/dist/src/builders/server/watcherService.cjs +55 -28
- package/dist/src/builders/server/watcherService.cjs.map +1 -1
- package/dist/src/builders/server/watcherService.mjs +55 -27
- package/dist/src/builders/server/watcherService.mjs.map +1 -1
- package/dist/src/builders/server/webTemplateDecision.cjs +7 -3
- package/dist/src/builders/server/webTemplateDecision.cjs.map +1 -1
- package/dist/src/builders/server/webTemplateDecision.mjs +7 -3
- package/dist/src/builders/server/webTemplateDecision.mjs.map +1 -1
- package/dist/src/builders/server/workspaceAdmission.cjs +96 -0
- package/dist/src/builders/server/workspaceAdmission.cjs.map +1 -0
- package/dist/src/builders/server/workspaceAdmission.mjs +90 -0
- package/dist/src/builders/server/workspaceAdmission.mjs.map +1 -0
- package/dist/src/builders/server/workspaceCheckout.cjs +16 -7
- package/dist/src/builders/server/workspaceCheckout.cjs.map +1 -1
- package/dist/src/builders/server/workspaceCheckout.mjs +16 -7
- package/dist/src/builders/server/workspaceCheckout.mjs.map +1 -1
- package/dist/src/builders/web/bundle.cjs +16 -14
- package/dist/src/builders/web/bundle.cjs.map +1 -1
- package/dist/src/builders/web/bundle.d.mts +3 -0
- package/dist/src/builders/web/bundle.d.mts.map +1 -1
- package/dist/src/builders/web/bundle.mjs +15 -13
- package/dist/src/builders/web/bundle.mjs.map +1 -1
- package/dist/src/builders/web/index.cjs +92 -59
- package/dist/src/builders/web/index.cjs.map +1 -1
- package/dist/src/builders/web/index.d.mts +21 -14
- package/dist/src/builders/web/index.d.mts.map +1 -1
- package/dist/src/builders/web/index.mjs +91 -59
- package/dist/src/builders/web/index.mjs.map +1 -1
- package/dist/src/builders/web/webPluginGenerate.cjs +84 -45
- package/dist/src/builders/web/webPluginGenerate.cjs.map +1 -1
- package/dist/src/builders/web/webPluginGenerate.d.mts +13 -4
- package/dist/src/builders/web/webPluginGenerate.d.mts.map +1 -1
- package/dist/src/builders/web/webPluginGenerate.mjs +82 -44
- package/dist/src/builders/web/webPluginGenerate.mjs.map +1 -1
- package/dist/src/builders/web/webPluginManifest.cjs +24 -17
- package/dist/src/builders/web/webPluginManifest.cjs.map +1 -1
- package/dist/src/builders/web/webPluginManifest.d.mts +11 -23
- package/dist/src/builders/web/webPluginManifest.d.mts.map +1 -1
- package/dist/src/builders/web/webPluginManifest.mjs +23 -16
- package/dist/src/builders/web/webPluginManifest.mjs.map +1 -1
- package/dist/src/builders/web/webPluginScan.cjs +11 -8
- package/dist/src/builders/web/webPluginScan.cjs.map +1 -1
- package/dist/src/builders/web/webPluginScan.d.mts +1 -1
- package/dist/src/builders/web/webPluginScan.d.mts.map +1 -1
- package/dist/src/builders/web/webPluginScan.mjs +10 -7
- package/dist/src/builders/web/webPluginScan.mjs.map +1 -1
- package/dist/src/builders/web/webPluginVite.cjs +5 -5
- package/dist/src/builders/web/webPluginVite.cjs.map +1 -1
- package/dist/src/builders/web/webPluginVite.d.mts +1 -1
- package/dist/src/builders/web/webPluginVite.d.mts.map +1 -1
- package/dist/src/builders/web/webPluginVite.mjs +3 -3
- package/dist/src/builders/web/webPluginVite.mjs.map +1 -1
- package/dist/src/cli/cliApp.cjs +18 -19
- package/dist/src/cli/cliApp.cjs.map +1 -1
- package/dist/src/cli/cliApp.d.mts +1 -1
- package/dist/src/cli/cliApp.d.mts.map +1 -1
- package/dist/src/cli/cliApp.mjs +18 -19
- package/dist/src/cli/cliApp.mjs.map +1 -1
- package/dist/src/cli/commands/api-export/index.cjs +14 -13
- package/dist/src/cli/commands/api-export/index.cjs.map +1 -1
- package/dist/src/cli/commands/api-export/index.mjs +13 -12
- package/dist/src/cli/commands/api-export/index.mjs.map +1 -1
- package/dist/src/cli/commands/doctor/help.cjs +4 -3
- package/dist/src/cli/commands/doctor/help.cjs.map +1 -1
- package/dist/src/cli/commands/doctor/help.d.mts.map +1 -1
- package/dist/src/cli/commands/doctor/help.mjs +4 -3
- package/dist/src/cli/commands/doctor/help.mjs.map +1 -1
- package/dist/src/cli/commands/doctor/index.cjs +30 -17
- package/dist/src/cli/commands/doctor/index.cjs.map +1 -1
- package/dist/src/cli/commands/doctor/index.d.mts +4 -4
- package/dist/src/cli/commands/doctor/index.d.mts.map +1 -1
- package/dist/src/cli/commands/doctor/index.mjs +28 -15
- package/dist/src/cli/commands/doctor/index.mjs.map +1 -1
- package/dist/src/cli/commands/emit-mcp/index.cjs +3 -2
- package/dist/src/cli/commands/emit-mcp/index.cjs.map +1 -1
- package/dist/src/cli/commands/emit-mcp/index.d.mts.map +1 -1
- package/dist/src/cli/commands/emit-mcp/index.mjs +3 -2
- package/dist/src/cli/commands/emit-mcp/index.mjs.map +1 -1
- package/dist/src/cli/commands/explain/index.cjs +53 -38
- package/dist/src/cli/commands/explain/index.cjs.map +1 -1
- package/dist/src/cli/commands/explain/index.d.mts +3 -4
- package/dist/src/cli/commands/explain/index.d.mts.map +1 -1
- package/dist/src/cli/commands/explain/index.mjs +52 -37
- package/dist/src/cli/commands/explain/index.mjs.map +1 -1
- package/dist/src/cli/commands/init/help.cjs +3 -2
- package/dist/src/cli/commands/init/help.cjs.map +1 -1
- package/dist/src/cli/commands/init/help.d.mts.map +1 -1
- package/dist/src/cli/commands/init/help.mjs +3 -2
- package/dist/src/cli/commands/init/help.mjs.map +1 -1
- package/dist/src/cli/commands/init/index.cjs +17 -12
- package/dist/src/cli/commands/init/index.cjs.map +1 -1
- package/dist/src/cli/commands/init/index.d.mts.map +1 -1
- package/dist/src/cli/commands/init/index.mjs +16 -11
- package/dist/src/cli/commands/init/index.mjs.map +1 -1
- package/dist/src/cli/commands/init/presenter.cjs +29 -21
- package/dist/src/cli/commands/init/presenter.cjs.map +1 -1
- package/dist/src/cli/commands/init/presenter.mjs +29 -21
- package/dist/src/cli/commands/init/presenter.mjs.map +1 -1
- package/dist/src/cli/commands/sync/help.cjs +7 -3
- package/dist/src/cli/commands/sync/help.cjs.map +1 -1
- package/dist/src/cli/commands/sync/help.d.mts.map +1 -1
- package/dist/src/cli/commands/sync/help.mjs +7 -3
- package/dist/src/cli/commands/sync/help.mjs.map +1 -1
- package/dist/src/cli/commands/sync/index.cjs +72 -40
- package/dist/src/cli/commands/sync/index.cjs.map +1 -1
- package/dist/src/cli/commands/sync/index.d.mts.map +1 -1
- package/dist/src/cli/commands/sync/index.mjs +69 -37
- package/dist/src/cli/commands/sync/index.mjs.map +1 -1
- package/dist/src/cli/commands/sync/presenter.cjs +10 -1
- package/dist/src/cli/commands/sync/presenter.cjs.map +1 -1
- package/dist/src/cli/commands/sync/presenter.d.mts +0 -9
- package/dist/src/cli/commands/sync/presenter.d.mts.map +1 -1
- package/dist/src/cli/commands/sync/presenter.mjs +10 -1
- package/dist/src/cli/commands/sync/presenter.mjs.map +1 -1
- package/dist/src/cli/commands/web/index.cjs +7 -6
- package/dist/src/cli/commands/web/index.cjs.map +1 -1
- package/dist/src/cli/commands/web/index.mjs +6 -5
- package/dist/src/cli/commands/web/index.mjs.map +1 -1
- package/dist/src/cli/harnessOptions.cjs +15 -24
- package/dist/src/cli/harnessOptions.cjs.map +1 -1
- package/dist/src/cli/harnessOptions.d.mts +2 -2
- package/dist/src/cli/harnessOptions.d.mts.map +1 -1
- package/dist/src/cli/harnessOptions.mjs +14 -22
- package/dist/src/cli/harnessOptions.mjs.map +1 -1
- package/dist/src/cli/help.cjs +20 -26
- package/dist/src/cli/help.cjs.map +1 -1
- package/dist/src/cli/help.d.mts +1 -2
- package/dist/src/cli/help.d.mts.map +1 -1
- package/dist/src/cli/help.mjs +15 -20
- package/dist/src/cli/help.mjs.map +1 -1
- package/dist/src/cli/locale.cjs +30 -0
- package/dist/src/cli/locale.cjs.map +1 -0
- package/dist/src/cli/locale.mjs +27 -0
- package/dist/src/cli/locale.mjs.map +1 -0
- package/dist/src/cli/matrixOptions.cjs +85 -37
- package/dist/src/cli/matrixOptions.cjs.map +1 -1
- package/dist/src/cli/matrixOptions.d.mts +22 -16
- package/dist/src/cli/matrixOptions.d.mts.map +1 -1
- package/dist/src/cli/matrixOptions.mjs +76 -33
- package/dist/src/cli/matrixOptions.mjs.map +1 -1
- package/dist/src/cli/options.cjs +51 -128
- package/dist/src/cli/options.cjs.map +1 -1
- package/dist/src/cli/options.d.mts +1 -1
- package/dist/src/cli/options.d.mts.map +1 -1
- package/dist/src/cli/options.mjs +53 -130
- package/dist/src/cli/options.mjs.map +1 -1
- package/dist/src/cli/router.cjs +0 -1
- package/dist/src/cli/router.cjs.map +1 -1
- package/dist/src/cli/router.d.mts +1 -1
- package/dist/src/cli/router.mjs +0 -1
- package/dist/src/cli/router.mjs.map +1 -1
- package/dist/src/cli/server/options.cjs +37 -7
- package/dist/src/cli/server/options.cjs.map +1 -1
- package/dist/src/cli/server/options.mjs +37 -7
- package/dist/src/cli/server/options.mjs.map +1 -1
- package/dist/src/cli/server/processGuards.cjs +22 -15
- package/dist/src/cli/server/processGuards.cjs.map +1 -1
- package/dist/src/cli/server/processGuards.mjs +21 -14
- package/dist/src/cli/server/processGuards.mjs.map +1 -1
- package/dist/src/cli/server/restartPolicy.cjs +38 -0
- package/dist/src/cli/server/restartPolicy.cjs.map +1 -0
- package/dist/src/cli/server/restartPolicy.d.mts +21 -0
- package/dist/src/cli/server/restartPolicy.d.mts.map +1 -0
- package/dist/src/cli/server/restartPolicy.mjs +36 -0
- package/dist/src/cli/server/restartPolicy.mjs.map +1 -0
- package/dist/src/cli/server/run.cjs +12 -11
- package/dist/src/cli/server/run.cjs.map +1 -1
- package/dist/src/cli/server/run.mjs +11 -10
- package/dist/src/cli/server/run.mjs.map +1 -1
- package/dist/src/cli/server/supervise.cjs +89 -0
- package/dist/src/cli/server/supervise.cjs.map +1 -0
- package/dist/src/cli/server/supervise.mjs +89 -0
- package/dist/src/cli/server/supervise.mjs.map +1 -0
- package/dist/src/composition/harnessState/index.cjs +2 -1
- package/dist/src/composition/harnessState/index.cjs.map +1 -1
- package/dist/src/composition/harnessState/index.d.mts +2 -1
- package/dist/src/composition/harnessState/index.d.mts.map +1 -1
- package/dist/src/composition/harnessState/index.mjs +2 -1
- package/dist/src/composition/harnessState/index.mjs.map +1 -1
- package/dist/src/composition/layerPackageInstaller/index.cjs +293 -86
- package/dist/src/composition/layerPackageInstaller/index.cjs.map +1 -1
- package/dist/src/composition/layerPackageInstaller/index.d.mts +25 -2
- package/dist/src/composition/layerPackageInstaller/index.d.mts.map +1 -1
- package/dist/src/composition/layerPackageInstaller/index.mjs +295 -94
- package/dist/src/composition/layerPackageInstaller/index.mjs.map +1 -1
- package/dist/src/composition/marketplaceCatalog/index.cjs +136 -0
- package/dist/src/composition/marketplaceCatalog/index.cjs.map +1 -0
- package/dist/src/composition/marketplaceCatalog/index.mjs +132 -0
- package/dist/src/composition/marketplaceCatalog/index.mjs.map +1 -0
- package/dist/src/composition/orgPluginActivation/index.cjs +179 -0
- package/dist/src/composition/orgPluginActivation/index.cjs.map +1 -0
- package/dist/src/composition/orgPluginActivation/index.mjs +177 -0
- package/dist/src/composition/orgPluginActivation/index.mjs.map +1 -0
- package/dist/src/composition/orgPluginLibrary/index.cjs +205 -0
- package/dist/src/composition/orgPluginLibrary/index.cjs.map +1 -0
- package/dist/src/composition/orgPluginLibrary/index.mjs +200 -0
- package/dist/src/composition/orgPluginLibrary/index.mjs.map +1 -0
- package/dist/src/composition/pluginMarketplace/index.cjs +304 -0
- package/dist/src/composition/pluginMarketplace/index.cjs.map +1 -0
- package/dist/src/composition/pluginMarketplace/index.mjs +302 -0
- package/dist/src/composition/pluginMarketplace/index.mjs.map +1 -0
- package/dist/src/composition/poHomeMigration/index.cjs +46 -26
- package/dist/src/composition/poHomeMigration/index.cjs.map +1 -1
- package/dist/src/composition/poHomeMigration/index.d.mts.map +1 -1
- package/dist/src/composition/poHomeMigration/index.mjs +45 -25
- package/dist/src/composition/poHomeMigration/index.mjs.map +1 -1
- package/dist/src/composition/projectTrust/index.cjs +40 -3
- package/dist/src/composition/projectTrust/index.cjs.map +1 -1
- package/dist/src/composition/projectTrust/index.d.mts +8 -0
- package/dist/src/composition/projectTrust/index.d.mts.map +1 -1
- package/dist/src/composition/projectTrust/index.mjs +33 -2
- package/dist/src/composition/projectTrust/index.mjs.map +1 -1
- package/dist/src/composition/repository/index.cjs +29 -12
- package/dist/src/composition/repository/index.cjs.map +1 -1
- package/dist/src/composition/repository/index.d.mts +10 -3
- package/dist/src/composition/repository/index.d.mts.map +1 -1
- package/dist/src/composition/repository/index.mjs +29 -13
- package/dist/src/composition/repository/index.mjs.map +1 -1
- package/dist/src/composition/syncPrune/index.cjs +23 -16
- package/dist/src/composition/syncPrune/index.cjs.map +1 -1
- package/dist/src/composition/syncPrune/index.d.mts.map +1 -1
- package/dist/src/composition/syncPrune/index.mjs +22 -15
- package/dist/src/composition/syncPrune/index.mjs.map +1 -1
- package/dist/src/composition/syncService/index.cjs +441 -194
- package/dist/src/composition/syncService/index.cjs.map +1 -1
- package/dist/src/composition/syncService/index.d.mts +4 -1
- package/dist/src/composition/syncService/index.d.mts.map +1 -1
- package/dist/src/composition/syncService/index.mjs +440 -196
- package/dist/src/composition/syncService/index.mjs.map +1 -1
- package/dist/src/composition/syncService/localBuilds.cjs +41 -37
- package/dist/src/composition/syncService/localBuilds.cjs.map +1 -1
- package/dist/src/composition/syncService/localBuilds.mjs +40 -37
- package/dist/src/composition/syncService/localBuilds.mjs.map +1 -1
- package/dist/src/composition/transitionLayers.cjs.map +1 -1
- package/dist/src/composition/transitionLayers.d.mts +3 -3
- package/dist/src/composition/transitionLayers.d.mts.map +1 -1
- package/dist/src/composition/transitionLayers.mjs.map +1 -1
- package/dist/src/composition/types/harness.d.mts +4 -9
- package/dist/src/composition/types/harness.d.mts.map +1 -1
- package/dist/src/extensions/setupDiagnostics.cjs +8 -8
- package/dist/src/extensions/setupDiagnostics.cjs.map +1 -1
- package/dist/src/extensions/setupDiagnostics.mjs +8 -8
- package/dist/src/extensions/setupDiagnostics.mjs.map +1 -1
- package/dist/webBuilder.cjs +2 -0
- package/dist/webBuilder.d.mts +3 -3
- package/dist/webBuilder.mjs +3 -3
- package/docs/server/api-export.md +9 -9
- package/docs/server/api.md +22 -125
- package/docs/server/getting-started.md +21 -85
- package/docs/server/index.md +13 -58
- package/docs/server/ipc.md +26 -72
- package/docs/server/lifecycle.md +18 -91
- package/docs/server/security.md +20 -80
- package/locales/vi.json +208 -0
- package/locales/zh-CN.json +208 -0
- package/package.json +52 -69
- package/src/prompts/po-author-extension/SKILL.md +2 -2
- package/src/prompts/po-author-extension/references/extension-contract.md +4 -6
- package/dist/antigravity.cjs +0 -5
- package/dist/antigravity.d.mts +0 -2
- package/dist/antigravity.mjs +0 -1
- package/dist/codex.cjs +0 -8
- package/dist/codex.d.mts +0 -2
- package/dist/codex.mjs +0 -1
- package/dist/compatibility.cjs +0 -27
- package/dist/compatibility.d.mts +0 -6
- package/dist/compatibility.mjs +0 -6
- package/dist/compatibilityCommand.cjs +0 -4
- package/dist/compatibilityCommand.d.mts +0 -2
- package/dist/compatibilityCommand.mjs +0 -1
- package/dist/compatibilityContext.cjs +0 -3
- package/dist/compatibilityContext.d.mts +0 -2
- package/dist/compatibilityContext.mjs +0 -1
- package/dist/compatibilityOptions.cjs +0 -5
- package/dist/compatibilityOptions.d.mts +0 -2
- package/dist/compatibilityOptions.mjs +0 -1
- package/dist/process.cjs +0 -12
- package/dist/process.d.mts +0 -2
- package/dist/process.mjs +0 -1
- package/dist/src/builders/hooks/index.cjs +0 -238
- package/dist/src/builders/hooks/index.cjs.map +0 -1
- package/dist/src/builders/hooks/index.mjs +0 -231
- package/dist/src/builders/hooks/index.mjs.map +0 -1
- package/dist/src/cli/commands/compat/context.cjs +0 -115
- package/dist/src/cli/commands/compat/context.cjs.map +0 -1
- package/dist/src/cli/commands/compat/context.d.mts +0 -22
- package/dist/src/cli/commands/compat/context.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/context.mjs +0 -110
- package/dist/src/cli/commands/compat/context.mjs.map +0 -1
- package/dist/src/cli/commands/compat/help.cjs +0 -26
- package/dist/src/cli/commands/compat/help.cjs.map +0 -1
- package/dist/src/cli/commands/compat/help.d.mts +0 -4
- package/dist/src/cli/commands/compat/help.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/help.mjs +0 -25
- package/dist/src/cli/commands/compat/help.mjs.map +0 -1
- package/dist/src/cli/commands/compat/index.cjs +0 -73
- package/dist/src/cli/commands/compat/index.cjs.map +0 -1
- package/dist/src/cli/commands/compat/index.d.mts +0 -14
- package/dist/src/cli/commands/compat/index.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/index.mjs +0 -70
- package/dist/src/cli/commands/compat/index.mjs.map +0 -1
- package/dist/src/cli/commands/compat/options.cjs +0 -88
- package/dist/src/cli/commands/compat/options.cjs.map +0 -1
- package/dist/src/cli/commands/compat/options.d.mts +0 -15
- package/dist/src/cli/commands/compat/options.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/options.mjs +0 -86
- package/dist/src/cli/commands/compat/options.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/antigravity.cjs +0 -294
- package/dist/src/cli/commands/compat/providers/antigravity.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/antigravity.d.mts +0 -9
- package/dist/src/cli/commands/compat/providers/antigravity.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/antigravity.mjs +0 -289
- package/dist/src/cli/commands/compat/providers/antigravity.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/codex.cjs +0 -178
- package/dist/src/cli/commands/compat/providers/codex.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/codex.d.mts +0 -17
- package/dist/src/cli/commands/compat/providers/codex.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/codex.mjs +0 -170
- package/dist/src/cli/commands/compat/providers/codex.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/index.cjs +0 -65
- package/dist/src/cli/commands/compat/providers/index.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/index.d.mts +0 -15
- package/dist/src/cli/commands/compat/providers/index.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/index.mjs +0 -45
- package/dist/src/cli/commands/compat/providers/index.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/process.cjs +0 -172
- package/dist/src/cli/commands/compat/providers/process.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/process.d.mts +0 -33
- package/dist/src/cli/commands/compat/providers/process.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/process.mjs +0 -159
- package/dist/src/cli/commands/compat/providers/process.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/shared.cjs +0 -76
- package/dist/src/cli/commands/compat/providers/shared.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/shared.d.mts +0 -40
- package/dist/src/cli/commands/compat/providers/shared.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/shared.mjs +0 -61
- package/dist/src/cli/commands/compat/providers/shared.mjs.map +0 -1
- package/dist/src/cli/commands/compat/types.d.mts +0 -31
- package/dist/src/cli/commands/compat/types.d.mts.map +0 -1
- package/dist/src/cli/commands/init/constants.cjs +0 -11
- package/dist/src/cli/commands/init/constants.cjs.map +0 -1
- package/dist/src/cli/commands/init/constants.mjs +0 -11
- package/dist/src/cli/commands/init/constants.mjs.map +0 -1
|
@@ -1,59 +1,216 @@
|
|
|
1
|
-
import { HARNESS_STATE_KEYS, HARNESS_STATE_POINTER,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { HARNESS_STATE_KEYS, HARNESS_STATE_POINTER, updateHarnessState } from "../../composition/harnessState/index.mjs";
|
|
2
|
+
import { resolveWorkspaceRoot } from "../../composition/repository/index.mjs";
|
|
3
|
+
import { poPackageRoot } from "../cli/entryResolution.mjs";
|
|
4
|
+
import { createLayerResolvers, isFixedHostPackage, resolveExtensionComposition, unsyncedSelectors } from "../../../builders/cli/extensionAssembler/index.mjs";
|
|
5
|
+
import { compositionPackageRoots, mountWebPluginSlots, newestGlobalWebBuildKey, readGlobalWebBuildRecord, readGlobalWebBuildStatus, unslottedWebPackages, webShellLocaleRoots } from "../web/index.mjs";
|
|
5
6
|
import { mountNativePluginIds, readGlobalNativeBuildRecord, readGlobalNativeBuildStatus } from "../native/index.mjs";
|
|
6
|
-
import { missingLayerPackageSpecifiers } from "../../composition/layerPackageInstaller/index.mjs";
|
|
7
|
+
import { catalogPackageNames, missingLayerPackageSpecifiers } from "../../composition/layerPackageInstaller/index.mjs";
|
|
7
8
|
import { readMcpAppBuild } from "./mcpAppBuild.mjs";
|
|
8
|
-
import { globalWebPluginRoots, readSyncPointer, syncPointerPath } from "../../composition/syncService/index.mjs";
|
|
9
|
-
import { createBackgroundSync,
|
|
9
|
+
import { globalWebPluginRoots, processIsAlive, readSyncPointer, syncPointerPath } from "../../composition/syncService/index.mjs";
|
|
10
|
+
import { createBackgroundSync, createSyncCheckpoints, syncedBuildKeys } from "./backgroundSync.mjs";
|
|
10
11
|
import { buildHarnessContext } from "../cli/harnessContext.mjs";
|
|
11
|
-
import {
|
|
12
|
+
import { readCompositionLocales } from "./index.mjs";
|
|
13
|
+
import { createOrgPluginLibrary } from "../../composition/orgPluginLibrary/index.mjs";
|
|
14
|
+
import { createOrgPluginActivation } from "../../composition/orgPluginActivation/index.mjs";
|
|
15
|
+
import { createPluginMarketplace } from "../../composition/pluginMarketplace/index.mjs";
|
|
16
|
+
import { createNodeIsolate } from "../isolate/index.mjs";
|
|
17
|
+
import { createNodeNpm } from "../npm/index.mjs";
|
|
18
|
+
import { createPackageReloadCheck } from "./packageReloadCheck.mjs";
|
|
12
19
|
import { createBundlerService } from "./bundlerService.mjs";
|
|
20
|
+
import { collectNodeCapabilities } from "./capabilities.mjs";
|
|
13
21
|
import { createComputerUseBinding } from "./computerUseBinding.mjs";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
22
|
+
import { registerContainedSessionMethods } from "./containedSessions.mjs";
|
|
23
|
+
import { DEFAULT_WORKSPACE_NAME, createNamedWorkspaceFolder, createSessionWorkspaceFolder, discardEmptySessionFolder } from "./defaultWorkspace.mjs";
|
|
24
|
+
import { createElectronBinding } from "./electronBinding.mjs";
|
|
25
|
+
import { cliFederationPlatform } from "./federation.mjs";
|
|
26
|
+
import { hostDisplayName } from "./hostDisplayName.mjs";
|
|
27
|
+
import { createHostModelGateway } from "./hostModelGateway.mjs";
|
|
28
|
+
import { createSessionShares, createTeamHost, remoteCallerStamps } from "./hostTeam.mjs";
|
|
29
|
+
import { backgroundRestartBlocker, createIdleRestart, keepRelayIntent, keepTunnelIntent, prepareSessionRestore, readRecycleState, relayIntentKept, removeRecycleFile, reopenRecycledSessions, takeTunnelIntent, testIdleRestartOverrides, writeRecycleFile } from "./idleRestart.mjs";
|
|
30
|
+
import { subscribeLiveActivityPush } from "./liveActivityPush.mjs";
|
|
16
31
|
import { ensureGlobalLogSink } from "./logSink.mjs";
|
|
32
|
+
import { loadNativePushCredentials, subscribeNativePush } from "./nativePush.mjs";
|
|
33
|
+
import { createOrgPluginLibraryBinding } from "./orgPluginLibraryBinding.mjs";
|
|
34
|
+
import { createPrivateRelayLink, createPrivateRelayOptions, privateRelayConfiguration } from "./privateRelay.mjs";
|
|
17
35
|
import { monitorRuntimeResources } from "./runtimeResources.mjs";
|
|
36
|
+
import { SANDBOX_UNREACHABLE, createSandboxRouter } from "./sandboxRouter.mjs";
|
|
37
|
+
import { CONTAINER_WORKTREE_GONE, createSandboxSessionHandoff, handoffProvider } from "./sandboxSessionHandoff.mjs";
|
|
38
|
+
import { createScopeReloadController } from "./scopeReloadController.mjs";
|
|
18
39
|
import { publishHeadlessSelectionStatus } from "./selectionStatus.mjs";
|
|
19
|
-
import { resolveSessionIdentity, sessionSelectionArgs } from "./sessionArguments.mjs";
|
|
20
|
-
import {
|
|
40
|
+
import { launchSessionRequest, profileSelectionArgs, resolveSessionIdentity, sessionSelectionArgs } from "./sessionArguments.mjs";
|
|
41
|
+
import { createHostSessionRemoval, purgeSession } from "./sessionRemoval.mjs";
|
|
42
|
+
import { createSessionSummaries, recordCarryOver } from "./sessionSummaries.mjs";
|
|
43
|
+
import { SANDBOX_STOP_DEADLINE_MS, isCleanUserStop, stopSandboxProviders, withShutdownDeadline } from "./shutdown.mjs";
|
|
44
|
+
import { createShutdownStack, runBoundedShutdownStep } from "./shutdownStack.mjs";
|
|
45
|
+
import { holdAtToolBoundaries } from "./toolBoundaryHold.mjs";
|
|
21
46
|
import { createWatcherService, outsideNodeModules } from "./watcherService.mjs";
|
|
22
47
|
import { resolveWebTemplateDecision } from "./webTemplateDecision.mjs";
|
|
48
|
+
import { readAdmittedWorkspaceDeclarations, refreshRememberedWorkspaceDeclarations, resolveWorkspaceAdmission, workspaceSessionAgentArgs } from "./workspaceAdmission.mjs";
|
|
23
49
|
import { checkoutWorkspaceId } from "./workspaceCheckout.mjs";
|
|
24
|
-
import fs from "node:fs";
|
|
25
|
-
import path from "node:path";
|
|
26
50
|
import os from "node:os";
|
|
27
|
-
import {
|
|
28
|
-
import
|
|
29
|
-
import {
|
|
51
|
+
import { PO_COMPOSITION_LOCALES_CONTRACT, PO_LANG_CONTRACT, formatMessage } from "@agimon-ai/po-core/locale";
|
|
52
|
+
import path from "node:path";
|
|
53
|
+
import { loadProfileCatalog } from "@agimon-ai/po-config/profiles";
|
|
54
|
+
import { loadPresetsConfig } from "@agimon-ai/po-config/sync";
|
|
30
55
|
import { createHarnessTelemetry } from "@agimon-ai/po-core/runtimeLogSinkTelemetry";
|
|
31
|
-
import
|
|
32
|
-
import {
|
|
33
|
-
import crypto from "node:crypto";
|
|
34
|
-
import { createOpenSessionRegistry, createRequestReceipts, createWorkspaceRegistry, identifyWorkspace, listSavedSessionRecords, listSavedSessions, readSqliteTranscript, readWorkspaceMarker, writeWorkspaceMarker } from "@agimon-ai/po-core/history";
|
|
56
|
+
import fs from "node:fs/promises";
|
|
57
|
+
import { SESSION_MEMBER_ENVIRONMENT, globalPoConfigDirectory, readPoConfig, readWorkspaceDeclarations, refreshGlobalSettingsCache } from "@agimon-ai/po-config/config";
|
|
35
58
|
import { createNodePlatform } from "@agimon-ai/po-core/nodePlatform";
|
|
59
|
+
import { piAgentDirectory, poHomeDirectory } from "@agimon-ai/po-core/piSettings";
|
|
60
|
+
import { BACKGROUND_CONTEXT, PO_SESSION_ARTIFACT_DIR, PO_SPACE_SERVICE, createSerialRunner, getOrThrow, nodeHost, pathExists, readPoSpace, readSessionFileDirectories, removeSessionFiles } from "@agimon-ai/po-core/platform";
|
|
61
|
+
import { resolveLayers, writePreset } from "@agimon-ai/po-config/presets";
|
|
62
|
+
import { PO_HOST_SERVICES_CONTRACT, PO_HOST_TEAM_CONTRACT, PO_REMOTE_GATEWAY_CONTRACT, createHostServicesRegistry, defineServiceContract, loadServerPackages, parsePoWebBrainMetadata, readPoServerHost, requirePoServerHost, selectedServerProviderOverrides } from "@agimon-ai/po-core/serverPlugin";
|
|
63
|
+
import crypto from "node:crypto";
|
|
64
|
+
import { createOpenSessionRegistry, createRequestReceipts, createWorkspaceRegistry, listSavedSessionRecords, listSavedSessions, moveSessionWorkspace, readSavedSelection, readSqliteTranscript, readWorkspaceMarker, writeWorkspaceMarker } from "@agimon-ai/po-core/history";
|
|
65
|
+
import { PO_DIR, createSettingsApi } from "@agimon-ai/po-config";
|
|
66
|
+
import { createRemoteRuntime } from "@agimon-ai/po-remote";
|
|
67
|
+
import { PO_PACKAGE_HEALTH_CONTRACT, PO_SELF_IMPROVE_CONTRACT } from "@agimon-ai/po-core/help";
|
|
68
|
+
import net from "node:net";
|
|
69
|
+
import { resolveWorkspaceArtifactDirectory } from "@agimon-ai/po-artifact/artifactFiles";
|
|
70
|
+
import { PO_CALENDAR_HOST_PAIR_SERVICE, PO_FEDERATION_CLIENT_SERVICE } from "@agimon-ai/po-core";
|
|
36
71
|
import { readPoBackgroundWorkService } from "@agimon-ai/po-core/backgroundWork";
|
|
72
|
+
import { createClientDeviceRegistry } from "@agimon-ai/po-core/clientDevices";
|
|
37
73
|
import { createHeadlessHub } from "@agimon-ai/po-core/headlessHub";
|
|
38
74
|
import { serveHeadlessServer } from "@agimon-ai/po-core/headlessServer";
|
|
39
75
|
import { createHeadlessSessionManager } from "@agimon-ai/po-core/headlessSessionManager";
|
|
76
|
+
import { PoHubParentUnavailableError, WORKFLOW_STEP_SESSION_PROVENANCE } from "@agimon-ai/po-core/hubChannel";
|
|
40
77
|
import { loadMcpPlugins, mcpUiResource } from "@agimon-ai/po-core/mcpFacet";
|
|
78
|
+
import { PO_HOST_REQUESTS_CONTRACT, PO_SHARED_MODELS_CONTRACT, createModelGatewayContainer } from "@agimon-ai/po-core/modelGateway";
|
|
79
|
+
import { PO_NOTIFICATION_ENTRY_TYPE, createPoNotificationEntryData } from "@agimon-ai/po-core/notification";
|
|
41
80
|
import { PO_SHARE_FILE_REMOTE_OFF_MESSAGE, createServerExecutionBudget } from "@agimon-ai/po-core/packageApi";
|
|
42
81
|
import { serveSessionApis } from "@agimon-ai/po-core/packageApiServer";
|
|
43
|
-
import {
|
|
82
|
+
import { poPluginMountToWire, poScopedToWire } from "@agimon-ai/po-core/pluginProtocol";
|
|
83
|
+
import { PO_REMOTE_ORIGIN_CONTRACT } from "@agimon-ai/po-core/remoteOrigin";
|
|
84
|
+
import { PO_SANDBOX_IDENTITY_CONTRACT } from "@agimon-ai/po-core/sandboxIdentity";
|
|
44
85
|
import { createServerTelemetry } from "@agimon-ai/po-core/serverTelemetry";
|
|
45
|
-
import { createWebCompositions } from "@agimon-ai/po-core/webCompositions";
|
|
46
|
-
import {
|
|
86
|
+
import { createWebCompositions, reapAbandonedPublications } from "@agimon-ai/po-core/webCompositions";
|
|
87
|
+
import { PO_WORKSPACE_REGISTRY_CONTRACT, createPoWorkspaceRegistry } from "@agimon-ai/po-core/workspaceRegistry";
|
|
88
|
+
import { PO_WORKSPACE_SANDBOXES_CONTRACT, createWorkspaceSandboxRegistry } from "@agimon-ai/po-core/workspaceSandboxes";
|
|
89
|
+
import { PO_DB_CONTRACT } from "@agimon-ai/po-db";
|
|
90
|
+
import { readModeCatalog } from "@agimon-ai/po-mode";
|
|
91
|
+
import { createNativePushSender } from "@agimon-ai/po-notification";
|
|
92
|
+
import { PERSON_PROFILE_SERVICE, PROFILE_INITIAL_OUTCOME_SERVICE, ProfileRestoreError, createDeadline, mergeProfiles, readProfileSources, requirePersonProfile, resolveInitialProfile } from "@agimon-ai/po-profile";
|
|
93
|
+
import { PO_ROSTER_PEER_CONTRACT, canSessionsCommunicate, createCoordinatorService, sessionCoordinates } from "@agimon-ai/po-session";
|
|
94
|
+
import { createSessionMcpServer } from "@agimon-ai/po-session-mcp";
|
|
95
|
+
import { PO_VAULT_ACCOUNT_CONTRACT, createAccountVault } from "@agimon-ai/po-vault";
|
|
47
96
|
//#region src/builders/server/runtime.ts
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
97
|
+
/** What asked every scope to recheck: a watched change, a watcher tick, a finished sync or an upm install. */
|
|
98
|
+
/** The largest protocol message a contained server accepts from its host. */
|
|
99
|
+
const CONTAINED_MAX_PAYLOAD_BYTES = 8388608;
|
|
100
|
+
/** The base path of po-config's settings API, the one API a sandboxed workspace still answers on the host. */
|
|
101
|
+
const SETTINGS_API = "settings";
|
|
102
|
+
/** Package failures Help reports at once; the oldest drop first. */
|
|
103
|
+
const PACKAGE_FAILURE_LIMIT = 64;
|
|
104
|
+
const REVIVAL_RETRY_LIMIT = 15;
|
|
105
|
+
const REVIVAL_RETRY_MAX_DELAY_MS = 3e4;
|
|
106
|
+
/**
|
|
107
|
+
* How long a shared package swap waits for live sessions to finish their tool round before it goes ahead.
|
|
108
|
+
* Short on purpose: quick rounds (read, grep, edit) land inside it, and a long build would not land in any
|
|
109
|
+
* wait worth making everyone else sit through.
|
|
110
|
+
*/
|
|
111
|
+
const SHARED_RELOAD_HOLD_MS = 2e3;
|
|
112
|
+
/** The mount key of the compositions another host's sessions borrow; no local workspace or session uses it. */
|
|
113
|
+
const REMOTE_COMPOSITION_ID = "po-remote";
|
|
114
|
+
/** Whether a listen address stays on this machine: `localhost`, `127.0.0.0/8`, or `::1`. */
|
|
115
|
+
function isLoopbackHost(host) {
|
|
116
|
+
const address = host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
|
|
117
|
+
if (address.toLowerCase() === "localhost") return true;
|
|
118
|
+
if (net.isIPv4(address)) return address.startsWith("127.");
|
|
119
|
+
if (!net.isIPv6(address)) return false;
|
|
120
|
+
const lower = address.toLowerCase();
|
|
121
|
+
return lower === "::1" || lower.startsWith("::ffff:") && net.isIPv4(lower.slice(7)) && lower.slice(7).startsWith("127.");
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A read-only runtime's installed payload, which the server imports in place. An installed Po sits at
|
|
125
|
+
* `<payload>/node_modules/@agimon-ai/po`; a source checkout uses its own package root.
|
|
126
|
+
*/
|
|
127
|
+
function installedPayloadRoot(packageRoot) {
|
|
128
|
+
const scopeDirectory = path.dirname(packageRoot);
|
|
129
|
+
return path.basename(path.dirname(scopeDirectory)) === "node_modules" ? path.resolve(packageRoot, "../../..") : packageRoot;
|
|
130
|
+
}
|
|
131
|
+
function asError(error) {
|
|
132
|
+
return error instanceof Error ? error : new Error(String(error), { cause: error });
|
|
133
|
+
}
|
|
134
|
+
function errorMessage(error) {
|
|
135
|
+
return error instanceof Error ? error.message : String(error);
|
|
136
|
+
}
|
|
137
|
+
/** Whether the host itself serves the workspace: admitted here and not run by a sandbox. */
|
|
138
|
+
function compositionToWire(composition) {
|
|
139
|
+
return composition === void 0 ? void 0 : poScopedToWire(composition);
|
|
140
|
+
}
|
|
141
|
+
function templateToWire(decision) {
|
|
142
|
+
return {
|
|
143
|
+
...decision,
|
|
144
|
+
mount: poPluginMountToWire(decision.mount)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function servedOnHost(workspace) {
|
|
148
|
+
return workspace.available !== false && workspace.sandbox === void 0;
|
|
149
|
+
}
|
|
150
|
+
/** The hub's view of a workspace record: one mapping, so every registration carries its sandbox and its state. */
|
|
151
|
+
function hubWorkspace(record, available, status = {}) {
|
|
152
|
+
return {
|
|
153
|
+
id: record.id,
|
|
154
|
+
root: record.root,
|
|
155
|
+
...record.kind === void 0 ? {} : { kind: record.kind },
|
|
156
|
+
...record.name === void 0 ? {} : { name: record.name },
|
|
157
|
+
...record.sandbox === void 0 ? {} : { sandbox: record.sandbox },
|
|
158
|
+
...record.instructions === void 0 ? {} : { instructions: record.instructions },
|
|
159
|
+
...status.sandboxState === void 0 ? {} : { sandboxState: status.sandboxState },
|
|
160
|
+
...status.sandboxReason === void 0 ? {} : { sandboxReason: status.sandboxReason },
|
|
161
|
+
available
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const sameSandboxStatus = (left, right) => left.sandboxState === right.sandboxState && left.sandboxReason === right.sandboxReason;
|
|
165
|
+
/** Paired devices reach the protocol host as remote callers; their client metadata rides along for display and arbitration. */
|
|
166
|
+
function remoteProtocolAcceptor(cockpit) {
|
|
167
|
+
return (pathname, link, deviceId, client, access) => {
|
|
168
|
+
const host = cockpit();
|
|
169
|
+
if (!host) throw new Error("The headless protocol listener is not ready.");
|
|
170
|
+
return host.acceptProtocol(pathname, link, remoteCallerStamps(deviceId, access), client);
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* A Cloud account's protocol stream reaches this computer as its checked linker, with the owner access a paired device
|
|
175
|
+
* of the owner has. The host socket gets that device's protocol; a session's own socket keeps the narrower chat that
|
|
176
|
+
* older apps open. The principal comes from the saved link, never from the stream, and no device stands behind it.
|
|
177
|
+
*/
|
|
178
|
+
function cloudChatAcceptor(cockpit) {
|
|
179
|
+
return (pathname, link, caller, client) => {
|
|
180
|
+
const host = cockpit();
|
|
181
|
+
if (!host) throw new Error("The headless protocol listener is not ready.");
|
|
182
|
+
const stamps = remoteCallerStamps(`cloud-account:${caller.subject}`, {
|
|
183
|
+
access: "owner",
|
|
184
|
+
caller: {
|
|
185
|
+
principal: {
|
|
186
|
+
issuer: caller.issuer,
|
|
187
|
+
subject: caller.subject
|
|
188
|
+
},
|
|
189
|
+
org: caller.org,
|
|
190
|
+
device: { keyId: `cloud:${caller.issuer}` }
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
return host.acceptProtocol(pathname, link, stamps, client, pathname === "/api/ws" ? void 0 : "cloud-chat");
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/** Host admission boundary shared by coordinator role changes and workspace moves. */
|
|
197
|
+
function bindCoordinatorMoves(service, move) {
|
|
198
|
+
const admit = createSerialRunner();
|
|
199
|
+
return {
|
|
200
|
+
...service,
|
|
201
|
+
ensureHome: (settings) => admit(() => service.ensureHome(settings)),
|
|
202
|
+
add: (workspaceId, profile) => admit(() => service.add(workspaceId, profile)),
|
|
203
|
+
setRole: (sessionId, coordinator) => admit(() => service.setRole(sessionId, coordinator)),
|
|
204
|
+
moveSession: (sessionId, workspaceId) => admit(() => move(sessionId, workspaceId))
|
|
205
|
+
};
|
|
54
206
|
}
|
|
55
207
|
async function runServerRuntime(options, runtime) {
|
|
56
|
-
const { cwd: baseCwd, environment: incomingEnvironment, notice: rawNotice, resolveHarnessOptions, signal, onExtensionCheck } = runtime;
|
|
208
|
+
const { cwd: baseCwd, environment: incomingEnvironment, notice: rawNotice, resolveHarnessOptions, signal, onExtensionCheck, automation } = runtime;
|
|
209
|
+
if (options.host !== void 0 && options.contained !== true && !isLoopbackHost(options.host)) throw new Error(`--host ${options.host} is not a loopback address. Only a --contained server may listen on it.`);
|
|
210
|
+
const sandboxIdentity = options.contained === true ? Object.freeze({
|
|
211
|
+
contained: true,
|
|
212
|
+
...options.workspaceId === void 0 ? {} : { workspaceId: options.workspaceId }
|
|
213
|
+
}) : void 0;
|
|
57
214
|
const baseEnvironment = {
|
|
58
215
|
...incomingEnvironment,
|
|
59
216
|
LOG_SINK_INSTANCE: "global"
|
|
@@ -75,56 +232,148 @@ async function runServerRuntime(options, runtime) {
|
|
|
75
232
|
};
|
|
76
233
|
const homeDirectory = baseEnvironment.HOME ?? os.homedir();
|
|
77
234
|
const serverDirectory = path.join(piAgentDirectory(baseEnvironment), "server");
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
235
|
+
const temporaryDirectory = path.resolve(baseEnvironment.TMPDIR || baseEnvironment.TMP || baseEnvironment.TEMP || os.tmpdir());
|
|
236
|
+
const electron = await createElectronBinding();
|
|
237
|
+
const platform = {
|
|
238
|
+
...electron && { electron },
|
|
239
|
+
...createNodePlatform({
|
|
240
|
+
homeDirectory,
|
|
241
|
+
temporaryDirectory,
|
|
242
|
+
sessionsRoot: path.join(serverDirectory, "sessions")
|
|
243
|
+
}),
|
|
244
|
+
isolate: createNodeIsolate(),
|
|
245
|
+
npm: createNodeNpm({
|
|
246
|
+
poHome: poHomeDirectory(homeDirectory, baseEnvironment),
|
|
247
|
+
homeDirectory,
|
|
248
|
+
temporaryDirectory,
|
|
249
|
+
environment: baseEnvironment
|
|
250
|
+
})
|
|
251
|
+
};
|
|
252
|
+
const scopeReload = createScopeReloadController({ notice });
|
|
253
|
+
/** Queues any trigger arriving before the host mount can publish so it never silently becomes a no-op. */
|
|
254
|
+
const createQueuedTrigger = () => {
|
|
255
|
+
let handler;
|
|
256
|
+
let pending = false;
|
|
257
|
+
return {
|
|
258
|
+
trigger: () => {
|
|
259
|
+
if (handler === void 0) {
|
|
260
|
+
pending = true;
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
handler();
|
|
264
|
+
},
|
|
265
|
+
bind: (next) => {
|
|
266
|
+
handler = next;
|
|
267
|
+
if (pending) {
|
|
268
|
+
pending = false;
|
|
269
|
+
next();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
const hostServicesTrigger = createQueuedTrigger();
|
|
275
|
+
const hostOwnersTrigger = createQueuedTrigger();
|
|
276
|
+
const hostServicesChanged = hostServicesTrigger.trigger;
|
|
277
|
+
const hostOwnersChanged = hostOwnersTrigger.trigger;
|
|
278
|
+
const hostFiles = platform.env(baseCwd);
|
|
279
|
+
const watcherOptions = {
|
|
280
|
+
onChange: (source) => scopeReload.pickUpChange(source),
|
|
281
|
+
onNotice: notice,
|
|
282
|
+
exists: async (directory) => {
|
|
283
|
+
const info = await hostFiles.fileInfo(directory, BACKGROUND_CONTEXT);
|
|
284
|
+
return info.ok && info.value.kind === "directory";
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const watcher = createWatcherService(watcherOptions);
|
|
288
|
+
const localPackageRoots = /* @__PURE__ */ new Set();
|
|
289
|
+
let packageWatcher;
|
|
290
|
+
const watchPackage = (packageRoot) => {
|
|
291
|
+
packageWatcher?.add({
|
|
292
|
+
path: packageRoot,
|
|
293
|
+
recursive: true,
|
|
294
|
+
include: outsideNodeModules
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
const refreshPackageWatching = async () => {
|
|
298
|
+
const enabled = (await readPoConfig(hostFiles, globalPoConfigDirectory(homeDirectory, baseEnvironment), BACKGROUND_CONTEXT, {
|
|
299
|
+
homeDirectory,
|
|
300
|
+
environment: baseEnvironment
|
|
301
|
+
})).server?.watchPackages ?? baseEnvironment.PO_CHECKOUT_PACKAGES === void 0;
|
|
302
|
+
if (enabled === (packageWatcher !== void 0)) return;
|
|
303
|
+
packageWatcher?.close();
|
|
304
|
+
packageWatcher = enabled ? createWatcherService(watcherOptions) : void 0;
|
|
305
|
+
if (enabled) for (const packageRoot of localPackageRoots) watchPackage(packageRoot);
|
|
306
|
+
};
|
|
88
307
|
const isConfig = (file) => /\.ya?ml$/u.test(file);
|
|
89
308
|
watcher.add({
|
|
90
|
-
path: globalPoConfigDirectory(homeDirectory),
|
|
309
|
+
path: globalPoConfigDirectory(homeDirectory, baseEnvironment),
|
|
91
310
|
include: isConfig
|
|
92
311
|
});
|
|
93
312
|
/** Compiles and loads packages once per content; every scope and session selects from it. */
|
|
313
|
+
let capabilityRevision = 0;
|
|
94
314
|
const bundler = createBundlerService({
|
|
315
|
+
files: hostFiles,
|
|
95
316
|
homeDirectory,
|
|
96
317
|
environment: baseEnvironment,
|
|
97
|
-
|
|
318
|
+
...sandboxIdentity !== void 0 || baseEnvironment.PO_IMMUTABLE_INSTALL === "1" ? { immutableRoot: installedPayloadRoot(poPackageRoot()) } : baseEnvironment.PO_DISTRIBUTION === "desktop" && baseEnvironment.PO_PACKAGE_ROOT ? { immutableRoot: path.resolve(baseEnvironment.PO_PACKAGE_ROOT, "../../..") } : {},
|
|
319
|
+
onNotice: notice,
|
|
320
|
+
onCompositions: (root, _compositions, packageRoots) => {
|
|
321
|
+
capabilityRevision += 1;
|
|
98
322
|
watcher.add({
|
|
99
323
|
path: path.join(root, ".po"),
|
|
100
324
|
include: isConfig
|
|
101
325
|
});
|
|
102
|
-
for (const packageRoot of
|
|
103
|
-
path
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
326
|
+
for (const packageRoot of packageRoots) {
|
|
327
|
+
if (packageRoot.includes(`${path.sep}node_modules${path.sep}`)) continue;
|
|
328
|
+
localPackageRoots.add(packageRoot);
|
|
329
|
+
watchPackage(packageRoot);
|
|
330
|
+
}
|
|
107
331
|
}
|
|
108
332
|
});
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
333
|
+
const shippedPackages = await catalogPackageNames(baseEnvironment);
|
|
334
|
+
const distributionManifest = JSON.parse(getOrThrow(await hostFiles.readTextFile(path.join(poPackageRoot(), "package.json"), BACKGROUND_CONTEXT)));
|
|
335
|
+
const distribution = typeof distributionManifest.version === "string" ? {
|
|
336
|
+
version: distributionManifest.version,
|
|
337
|
+
catalogPackages: [...shippedPackages ?? []]
|
|
338
|
+
} : void 0;
|
|
339
|
+
const clientInventories = /* @__PURE__ */ new Map();
|
|
340
|
+
const clientInventoryFor = (mount) => {
|
|
341
|
+
const key = mount.scope === "host" ? "host" : mount.scope === "workspace" ? `workspace:${mount.workspaceId}` : `session:${mount.sessionId}`;
|
|
342
|
+
let inventory = clientInventories.get(key);
|
|
343
|
+
if (!inventory) clientInventories.set(key, inventory = {
|
|
344
|
+
available: false,
|
|
345
|
+
packages: []
|
|
346
|
+
});
|
|
347
|
+
return inventory;
|
|
348
|
+
};
|
|
117
349
|
const requestReceipts = createRequestReceipts({ directory: path.join(serverDirectory, "request-receipts-v1") });
|
|
118
|
-
const
|
|
350
|
+
const clientDeviceFile = path.join(serverDirectory, "client-devices.json");
|
|
351
|
+
const clientDevices = createClientDeviceRegistry({
|
|
352
|
+
async load() {
|
|
353
|
+
try {
|
|
354
|
+
return JSON.parse(await fs.readFile(clientDeviceFile, "utf8"));
|
|
355
|
+
} catch (error) {
|
|
356
|
+
if (error.code === "ENOENT") return [];
|
|
357
|
+
throw asError(error);
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
async save(records) {
|
|
361
|
+
await fs.mkdir(serverDirectory, { recursive: true });
|
|
362
|
+
const temporary = `${clientDeviceFile}.tmp`;
|
|
363
|
+
await fs.writeFile(temporary, JSON.stringify(records), { mode: 384 });
|
|
364
|
+
await fs.rename(temporary, clientDeviceFile);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
const activeMedia = /* @__PURE__ */ new Map();
|
|
119
368
|
const mediaArbitration = {
|
|
120
|
-
register(busy) {
|
|
121
|
-
activeMedia.
|
|
369
|
+
register(busy, deviceId) {
|
|
370
|
+
activeMedia.set(busy, deviceId);
|
|
122
371
|
return () => {
|
|
123
|
-
activeMedia.delete(busy);
|
|
372
|
+
if (activeMedia.get(busy) === deviceId) activeMedia.delete(busy);
|
|
124
373
|
};
|
|
125
374
|
},
|
|
126
|
-
available(busy) {
|
|
127
|
-
return activeMedia.has(busy) && [...activeMedia].every((other) => other === busy || !other());
|
|
375
|
+
available(busy, deviceId) {
|
|
376
|
+
return activeMedia.has(busy) && [...activeMedia].every(([other, otherDevice]) => other === busy || otherDevice() !== deviceId || !other());
|
|
128
377
|
}
|
|
129
378
|
};
|
|
130
379
|
const activePeerAgents = /* @__PURE__ */ new Map();
|
|
@@ -146,10 +395,148 @@ async function runServerRuntime(options, runtime) {
|
|
|
146
395
|
directory: serverDirectory,
|
|
147
396
|
onNotice: notice
|
|
148
397
|
});
|
|
398
|
+
const declarationsByRoot = /* @__PURE__ */ new Map();
|
|
399
|
+
const declarationNotices = /* @__PURE__ */ new Set();
|
|
400
|
+
const invalidDeclarationRoots = /* @__PURE__ */ new Set();
|
|
401
|
+
const refreshWorkspaceDeclarations = async (root) => {
|
|
402
|
+
try {
|
|
403
|
+
const result = await readAdmittedWorkspaceDeclarations(hostFiles, root, workspaces.list());
|
|
404
|
+
declarationsByRoot.set(root, result.declarations);
|
|
405
|
+
invalidDeclarationRoots.delete(root);
|
|
406
|
+
for (const message of result.notices) {
|
|
407
|
+
if (declarationNotices.has(message)) continue;
|
|
408
|
+
declarationNotices.add(message);
|
|
409
|
+
notice(message);
|
|
410
|
+
}
|
|
411
|
+
} catch (error) {
|
|
412
|
+
declarationsByRoot.delete(root);
|
|
413
|
+
invalidDeclarationRoots.add(root);
|
|
414
|
+
throw asError(error);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
const workspaceInventory = createPoWorkspaceRegistry(() => workspaces.list().filter((record) => record.sandbox !== void 0 || !invalidDeclarationRoots.has(record.root)).map((record) => {
|
|
418
|
+
const declaration = record.sandbox !== void 0 || record.declaration === void 0 ? void 0 : declarationsByRoot.get(record.root)?.find((entry) => entry.name === record.declaration);
|
|
419
|
+
return {
|
|
420
|
+
id: record.id,
|
|
421
|
+
root: record.root,
|
|
422
|
+
name: record.name,
|
|
423
|
+
declaration: record.declaration,
|
|
424
|
+
alias: declaration?.alias,
|
|
425
|
+
metadata: declaration?.metadata ?? {}
|
|
426
|
+
};
|
|
427
|
+
}));
|
|
428
|
+
if (sandboxIdentity?.workspaceId !== void 0) {
|
|
429
|
+
const containedRoot = await resolveWorkspaceRoot(baseCwd);
|
|
430
|
+
for (const record of workspaces.list()) if (record.root === containedRoot && record.id !== sandboxIdentity.workspaceId) workspaces.remove(record.id);
|
|
431
|
+
if (!workspaces.list().some((record) => record.id === sandboxIdentity.workspaceId && record.root === containedRoot)) workspaces.add({
|
|
432
|
+
id: sandboxIdentity.workspaceId,
|
|
433
|
+
root: containedRoot
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
const sandboxes = createWorkspaceSandboxRegistry();
|
|
437
|
+
const modelSources = /* @__PURE__ */ new Set();
|
|
438
|
+
const sharedModels = { register(source) {
|
|
439
|
+
modelSources.add(source);
|
|
440
|
+
return () => {
|
|
441
|
+
modelSources.delete(source);
|
|
442
|
+
};
|
|
443
|
+
} };
|
|
444
|
+
const servedWorkspaces = /* @__PURE__ */ new Set();
|
|
445
|
+
/** Each workspace served here, first by id, with the packages its default selection offers the host scope. */
|
|
446
|
+
let hostOffers = [];
|
|
447
|
+
/** Set at shutdown, so no workspace copy takes over a host surface while the scopes unload. */
|
|
448
|
+
let hostServicesStopping = false;
|
|
449
|
+
const hostServices = createHostServicesRegistry({
|
|
450
|
+
identify: (owner) => owner.scope === "host" ? "host" : owner.context.workspaceId,
|
|
451
|
+
rank: (ownerId, packageName) => {
|
|
452
|
+
if (hostServicesStopping) return void 0;
|
|
453
|
+
if (ownerId === "host") return 0;
|
|
454
|
+
const index = hostOffers.findIndex(({ workspaceId, packages }) => workspaceId === ownerId && packages.get(packageName)?.server === true);
|
|
455
|
+
return index === -1 ? void 0 : index + 1;
|
|
456
|
+
},
|
|
457
|
+
open: async (packageName, metadata) => {
|
|
458
|
+
const scope = await hub.sessionParentScope(void 0);
|
|
459
|
+
const host = readPoServerHost(scope.root);
|
|
460
|
+
if (host === void 0) throw new Error("The host scope is not served.");
|
|
461
|
+
const fiber = await scope.root.plugin({
|
|
462
|
+
name: `${packageName}/host`,
|
|
463
|
+
apply: () => void 0
|
|
464
|
+
});
|
|
465
|
+
return {
|
|
466
|
+
context: fiber.ctx,
|
|
467
|
+
host,
|
|
468
|
+
provide: (contract, value) => scope.bind(contract, value, metadata),
|
|
469
|
+
dispose: () => fiber.dispose()
|
|
470
|
+
};
|
|
471
|
+
},
|
|
472
|
+
onNotice: notice,
|
|
473
|
+
onOwnersChanged: () => hostOwnersChanged()
|
|
474
|
+
});
|
|
475
|
+
const failedAdmissions = /* @__PURE__ */ new Map();
|
|
149
476
|
const openSessions = createOpenSessionRegistry({
|
|
150
477
|
directory: serverDirectory,
|
|
151
478
|
onNotice: notice
|
|
152
479
|
});
|
|
480
|
+
const recycled = await readRecycleState(serverDirectory);
|
|
481
|
+
const savedBotIds = openSessions.list().filter((record) => record.bot !== void 0).map((record) => record.sessionId);
|
|
482
|
+
const restorePlan = prepareSessionRestore(recycled === void 0 ? void 0 : {
|
|
483
|
+
...recycled,
|
|
484
|
+
sessionIds: [.../* @__PURE__ */ new Set([...recycled.sessionIds, ...savedBotIds])]
|
|
485
|
+
});
|
|
486
|
+
let crashRestoreCounted = recycled?.kind === "live" && (recycled.sessionIds.length > 0 || savedBotIds.length > 0);
|
|
487
|
+
const recoverySessionIds = new Set(restorePlan.sessionIds);
|
|
488
|
+
const keptTunnel = await takeTunnelIntent(serverDirectory);
|
|
489
|
+
const tunnelToRestore = recycled?.tunnel ?? keptTunnel;
|
|
490
|
+
let recoveryTunnel = tunnelToRestore;
|
|
491
|
+
const keptRelay = await relayIntentKept(serverDirectory);
|
|
492
|
+
/** The saved Po Cloud link's digest, set once relay setup loads, so a restart restores only that same link. */
|
|
493
|
+
let relayLinkBinding;
|
|
494
|
+
let relayWrites = Promise.resolve();
|
|
495
|
+
let persistRecovery = () => {};
|
|
496
|
+
let cleanShutdown = false;
|
|
497
|
+
let recoveryWork = Promise.resolve();
|
|
498
|
+
let recoveryWrites = Promise.resolve();
|
|
499
|
+
let recovering = false;
|
|
500
|
+
const recordLiveSession = (created, repoRoot, groupingRoot) => {
|
|
501
|
+
if (created.workspaceId === void 0) throw new Error("The new session has no workspace.");
|
|
502
|
+
const previous = openSessions.list().find((record) => record.sessionId === created.id);
|
|
503
|
+
const botState = (previous?.botRevision ?? 0) > (created.botRevision ?? 0) ? previous : created;
|
|
504
|
+
if (openSessions.add({
|
|
505
|
+
sessionId: created.id,
|
|
506
|
+
workspaceId: created.workspaceId,
|
|
507
|
+
cwd: created.cwd,
|
|
508
|
+
repoRoot,
|
|
509
|
+
groupingRoot,
|
|
510
|
+
name: created.name,
|
|
511
|
+
createdAt: created.createdAt,
|
|
512
|
+
...created.parentSessionId === void 0 ? {} : { parentSessionId: created.parentSessionId },
|
|
513
|
+
...created.sessionProvenance === void 0 ? {} : { sessionProvenance: created.sessionProvenance },
|
|
514
|
+
...created.startedBy === void 0 ? {} : { startedBy: created.startedBy },
|
|
515
|
+
...created.interaction === void 0 ? {} : { interaction: created.interaction },
|
|
516
|
+
...created.groups === void 0 || created.groups.length === 0 ? {} : { groups: [...created.groups] },
|
|
517
|
+
...botState?.bot === void 0 ? {} : {
|
|
518
|
+
bot: { ...botState.bot },
|
|
519
|
+
botRevision: botState.botRevision ?? 0
|
|
520
|
+
},
|
|
521
|
+
...recordCarryOver(previous)
|
|
522
|
+
}) === false) throw new Error("The new session could not be durably recorded.");
|
|
523
|
+
recoverySessionIds.add(created.id);
|
|
524
|
+
persistRecovery();
|
|
525
|
+
};
|
|
526
|
+
/** Named jobs running now, and every job that ran since the last sample, so a stall names what was busy. */
|
|
527
|
+
const activeJobs = /* @__PURE__ */ new Map();
|
|
528
|
+
const recentJobs = /* @__PURE__ */ new Set();
|
|
529
|
+
const trackJob = async (name, run) => {
|
|
530
|
+
activeJobs.set(name, (activeJobs.get(name) ?? 0) + 1);
|
|
531
|
+
recentJobs.add(name);
|
|
532
|
+
try {
|
|
533
|
+
return await run();
|
|
534
|
+
} finally {
|
|
535
|
+
const left = (activeJobs.get(name) ?? 1) - 1;
|
|
536
|
+
if (left === 0) activeJobs.delete(name);
|
|
537
|
+
else activeJobs.set(name, left);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
153
540
|
let lastBudgetSnapshot = "";
|
|
154
541
|
let nextEventLoopTick = performance.now() + 1e3;
|
|
155
542
|
const eventLoopMonitor = setInterval(() => {
|
|
@@ -167,7 +554,13 @@ async function runServerRuntime(options, runtime) {
|
|
|
167
554
|
}
|
|
168
555
|
const delay = Math.max(0, now - nextEventLoopTick);
|
|
169
556
|
nextEventLoopTick = now + 1e3;
|
|
170
|
-
|
|
557
|
+
const jobs = [...recentJobs].join(":") || "none";
|
|
558
|
+
recentJobs.clear();
|
|
559
|
+
for (const name of activeJobs.keys()) recentJobs.add(name);
|
|
560
|
+
if (delay >= 100) telemetry.recordEvent("po_server.event_loop_delay", {
|
|
561
|
+
duration_ms: Math.round(delay),
|
|
562
|
+
job_name: jobs
|
|
563
|
+
}).catch((error) => notice(`event loop telemetry failed: ${String(error)}`));
|
|
171
564
|
}, 1e3);
|
|
172
565
|
eventLoopMonitor.unref();
|
|
173
566
|
const harnessTelemetry = createHarnessTelemetry({
|
|
@@ -178,10 +571,10 @@ async function runServerRuntime(options, runtime) {
|
|
|
178
571
|
});
|
|
179
572
|
const baseSessionManager = createHeadlessSessionManager({
|
|
180
573
|
publishSelectionStatus: publishHeadlessSelectionStatus,
|
|
181
|
-
contextGroups: (context) => (
|
|
574
|
+
contextGroups: (context) => (readModeCatalog(context)?.list() ?? []).filter(({ state }) => state.activation === "active").map(({ descriptor }) => ({
|
|
182
575
|
id: descriptor.id,
|
|
183
576
|
label: descriptor.label,
|
|
184
|
-
kind: "
|
|
577
|
+
kind: "mode"
|
|
185
578
|
}))
|
|
186
579
|
});
|
|
187
580
|
/** The server's environment rooted at one configuration root, with no harness state of its own. */
|
|
@@ -199,6 +592,10 @@ async function runServerRuntime(options, runtime) {
|
|
|
199
592
|
const sessionArtifacts = /* @__PURE__ */ new Map();
|
|
200
593
|
/** Each host's session package root, where its session services (background work included) live. */
|
|
201
594
|
const sessionServiceRoots = /* @__PURE__ */ new WeakMap();
|
|
595
|
+
/** Assigned once packages can load: reloads one running session's own packages. */
|
|
596
|
+
let reloadSessionPackages;
|
|
597
|
+
/** Assigned with reloadSessionPackages: re-applies one session's selection axes from disk. */
|
|
598
|
+
let refreshSessionSelection;
|
|
202
599
|
let mountSessionApis;
|
|
203
600
|
/**
|
|
204
601
|
* Shutdown runs every session through the same close path a user-initiated
|
|
@@ -206,10 +603,172 @@ async function runServerRuntime(options, runtime) {
|
|
|
206
603
|
* it exists to survive.
|
|
207
604
|
*/
|
|
208
605
|
let shuttingDown = false;
|
|
606
|
+
const reviving = /* @__PURE__ */ new Map();
|
|
607
|
+
const revivalRetries = /* @__PURE__ */ new Map();
|
|
608
|
+
let recoveryQueue = Promise.resolve();
|
|
609
|
+
const enqueueRecovery = (open) => {
|
|
610
|
+
const next = recoveryQueue.then(open);
|
|
611
|
+
recoveryQueue = next.catch(() => void 0);
|
|
612
|
+
return next;
|
|
613
|
+
};
|
|
614
|
+
let settleRecoveryWorkspaces;
|
|
615
|
+
const clearRevivalRetry = (sessionId) => {
|
|
616
|
+
const retry = revivalRetries.get(sessionId);
|
|
617
|
+
if (retry === void 0) return 0;
|
|
618
|
+
clearTimeout(retry.timer);
|
|
619
|
+
revivalRetries.delete(sessionId);
|
|
620
|
+
return retry.count;
|
|
621
|
+
};
|
|
622
|
+
const cancelRevival = (sessionId) => {
|
|
623
|
+
clearRevivalRetry(sessionId);
|
|
624
|
+
const opening = reviving.get(sessionId);
|
|
625
|
+
if (opening === void 0) return;
|
|
626
|
+
return hub.closeSession(sessionId, { keepDormant: true }).then(() => Promise.allSettled([opening.promise])).catch((error) => notice(`Session '${sessionId}' recovery cancellation failed: ${errorMessage(error)}`));
|
|
627
|
+
};
|
|
628
|
+
persistRecovery = () => {
|
|
629
|
+
if (shuttingDown || signal.aborted) return;
|
|
630
|
+
const ids = [...recoverySessionIds];
|
|
631
|
+
const details = {
|
|
632
|
+
kind: "live",
|
|
633
|
+
crashRestores: restorePlan.crashRestores,
|
|
634
|
+
...recoveryTunnel === void 0 ? {} : { tunnel: recoveryTunnel }
|
|
635
|
+
};
|
|
636
|
+
recoveryWrites = recoveryWrites.then(() => writeRecycleFile(serverDirectory, ids, details)).catch((error) => {
|
|
637
|
+
notice(`Could not persist crash recovery: ${error instanceof Error ? error.message : String(error)}`);
|
|
638
|
+
});
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* Remove: a host session is hidden and kept restorable for 7 days (the sweep tears it down later). Container
|
|
642
|
+
* sessions, and a contained server's own sessions, keep the immediate path because their files live in a container.
|
|
643
|
+
*/
|
|
644
|
+
const markSessionRemoved = async (sessionId) => {
|
|
645
|
+
await cancelRevival(sessionId);
|
|
646
|
+
recoverySessionIds.delete(sessionId);
|
|
647
|
+
persistRecovery();
|
|
648
|
+
const handedTo = handoff?.handedOff(sessionId);
|
|
649
|
+
if (router !== void 0 && (router.owns(sessionId) || handedTo !== void 0)) {
|
|
650
|
+
await router.removeSession(sessionId, handedTo);
|
|
651
|
+
handoff?.forget(sessionId);
|
|
652
|
+
openSessions.remove(sessionId);
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
if (sandboxIdentity === void 0) {
|
|
656
|
+
await sessionRemoval.mark(sessionId);
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
const directories = await readSessionFileDirectories(platform.sessions, sessionId);
|
|
660
|
+
await removeSessionFiles({
|
|
661
|
+
platform,
|
|
662
|
+
sessionId,
|
|
663
|
+
environment: baseEnvironment,
|
|
664
|
+
artifactDirectory: path.join(directories?.agentDirectory ?? piAgentDirectory(baseEnvironment, homeDirectory), "po-artifacts", sessionId),
|
|
665
|
+
...directories === void 0 ? {} : { directories }
|
|
666
|
+
});
|
|
667
|
+
openSessions.remove(sessionId);
|
|
668
|
+
};
|
|
669
|
+
/** Routes the sessions of contained workspaces into their containers; host servers only. */
|
|
670
|
+
let router;
|
|
671
|
+
/** Hands sessions over between the host and a sandbox's Po home when a workspace switches; host servers only. */
|
|
672
|
+
let handoff;
|
|
673
|
+
/** The sandboxed workspace's provider, when it runs with a Po home on host disk that sessions can move into. */
|
|
674
|
+
const handoffProviderOf = (workspaceId) => {
|
|
675
|
+
const sandbox = workspaces.list().find((workspace) => workspace.id === workspaceId)?.sandbox;
|
|
676
|
+
return sandbox === void 0 ? void 0 : handoffProvider(sandboxes.get(sandbox));
|
|
677
|
+
};
|
|
678
|
+
/** The host's own part of a sandbox's state: a handover in progress, or a switch that failed. */
|
|
679
|
+
const sandboxTransitions = /* @__PURE__ */ new Map();
|
|
680
|
+
/** Set once the host scope has loaded, so a provider missing by then is missing for good. */
|
|
681
|
+
let sandboxProvidersSettled = false;
|
|
682
|
+
/**
|
|
683
|
+
* A workspace's live sandbox state. A sandboxed one: the host's transition, else running while linked, else what
|
|
684
|
+
* its provider reports. A local one: unavailable when no provider is loaded at all, or when every provider that
|
|
685
|
+
* reports availability cannot run sandboxes now, so the switch can say why it is off.
|
|
686
|
+
*/
|
|
687
|
+
const sandboxStatus = (record) => {
|
|
688
|
+
if (record.sandbox === void 0) {
|
|
689
|
+
if (sandboxProvidersSettled && sandboxIdentity === void 0 && sandboxes.list().length === 0) return {
|
|
690
|
+
sandboxState: "unavailable",
|
|
691
|
+
sandboxReason: "No sandbox provider is loaded. Turn on Help mode and ask Po to check the sandbox setup."
|
|
692
|
+
};
|
|
693
|
+
const reports = sandboxes.list().map((provider) => provider.availability?.()).filter((report) => report !== void 0);
|
|
694
|
+
const blocked = reports.find((report) => !report.available);
|
|
695
|
+
return blocked === void 0 || blocked.available || reports.some((report) => report.available) ? {} : {
|
|
696
|
+
sandboxState: "unavailable",
|
|
697
|
+
sandboxReason: blocked.reason
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
const transition = sandboxTransitions.get(record.id);
|
|
701
|
+
if (transition !== void 0 && transition.sandboxState !== "starting") return transition;
|
|
702
|
+
if (router?.connected(record.id) === true) return { sandboxState: "running" };
|
|
703
|
+
const provider = sandboxes.get(record.sandbox);
|
|
704
|
+
if (provider === void 0) return sandboxProvidersSettled ? {
|
|
705
|
+
sandboxState: "unavailable",
|
|
706
|
+
sandboxReason: `The sandbox provider '${record.sandbox}' is not installed.`
|
|
707
|
+
} : {};
|
|
708
|
+
const availability = provider.availability?.();
|
|
709
|
+
if (availability !== void 0 && !availability.available) return {
|
|
710
|
+
sandboxState: "unavailable",
|
|
711
|
+
sandboxReason: availability.reason
|
|
712
|
+
};
|
|
713
|
+
const status = provider.status?.(record.id);
|
|
714
|
+
if (status?.state === "failed") return {
|
|
715
|
+
sandboxState: "failed",
|
|
716
|
+
sandboxReason: status.reason
|
|
717
|
+
};
|
|
718
|
+
return transition ?? (status !== void 0 || provider.availability !== void 0 && availability === void 0 ? { sandboxState: "starting" } : {});
|
|
719
|
+
};
|
|
720
|
+
const hubEntry = (record, available) => hubWorkspace(record, available, sandboxStatus(record));
|
|
721
|
+
/** Registers the workspace again when its availability or sandbox state changed, so clients see it live. */
|
|
722
|
+
const refreshWorkspace = (workspaceId) => {
|
|
723
|
+
const record = workspaces.list().find((workspace) => workspace.id === workspaceId);
|
|
724
|
+
const known = hub.workspaces().find((workspace) => workspace.id === workspaceId);
|
|
725
|
+
if (record === void 0 || known === void 0 || known.sandbox !== record.sandbox) return;
|
|
726
|
+
const available = record.sandbox === void 0 ? known.available !== false : router?.connected(workspaceId) === true;
|
|
727
|
+
const entry = hubEntry(record, available);
|
|
728
|
+
if (available === (known.available !== false) && sameSandboxStatus(entry, known)) return;
|
|
729
|
+
hub.registerWorkspace(entry);
|
|
730
|
+
hostServicesChanged();
|
|
731
|
+
};
|
|
732
|
+
const refreshWorkspaces = () => {
|
|
733
|
+
for (const workspace of hub.workspaces()) refreshWorkspace(workspace.id);
|
|
734
|
+
};
|
|
735
|
+
const stopSandboxWatches = [];
|
|
736
|
+
/**
|
|
737
|
+
* A host session of a workspace that is now sandboxed closed: it follows the workspace into the sandbox, and the
|
|
738
|
+
* host scope, kept only for host sessions, unloads with the last of them.
|
|
739
|
+
*/
|
|
740
|
+
const handOffClosedSession = async (sessionId, workspaceId, keepDormant) => {
|
|
741
|
+
const provider = handoffProviderOf(workspaceId);
|
|
742
|
+
if (provider === void 0 || handoff === void 0) return;
|
|
743
|
+
try {
|
|
744
|
+
await handoff.sessionClosed(sessionId, workspaceId, keepDormant, provider);
|
|
745
|
+
} catch (error) {
|
|
746
|
+
notice(`Session ${sessionId} could not follow its workspace into the sandbox: ${errorMessage(error)}`);
|
|
747
|
+
}
|
|
748
|
+
if (baseSessionManager.sessions().some((host) => host.runtime.sessionId !== sessionId && hub.session(host.runtime.sessionId)?.workspaceId === workspaceId) || !servedWorkspaces.has(workspaceId)) return;
|
|
749
|
+
servedWorkspaces.delete(workspaceId);
|
|
750
|
+
await hub.unloadWorkspaceScope?.(workspaceId).catch((error) => notice(`Workspace '${workspaceId}' scope did not unload: ${errorMessage(error)}`));
|
|
751
|
+
hostServicesChanged();
|
|
752
|
+
};
|
|
209
753
|
const closeManagedSession = async (sessionId, options) => {
|
|
210
|
-
if (
|
|
754
|
+
if (options?.keepDormant !== true || shuttingDown) cancelRevival(sessionId);
|
|
755
|
+
else clearRevivalRetry(sessionId);
|
|
756
|
+
if (router?.mirror(sessionId) !== void 0) {
|
|
757
|
+
await router.closeSession(sessionId, {
|
|
758
|
+
keepDormant: options?.keepDormant === true,
|
|
759
|
+
disposeOnly: shuttingDown
|
|
760
|
+
});
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
const closingWorkspaceId = openSessions.list().find((record) => record.sessionId === sessionId)?.workspaceId;
|
|
764
|
+
if (!shuttingDown) {
|
|
765
|
+
recoverySessionIds.delete(sessionId);
|
|
766
|
+
persistRecovery();
|
|
767
|
+
if (options?.keepDormant !== true) openSessions.remove(sessionId);
|
|
768
|
+
}
|
|
211
769
|
const artifacts = sessionArtifacts.get(sessionId);
|
|
212
770
|
sessionArtifacts.delete(sessionId);
|
|
771
|
+
clientInventories.delete(`session:${sessionId}`);
|
|
213
772
|
webCompositions?.remove({
|
|
214
773
|
scope: "session",
|
|
215
774
|
sessionId
|
|
@@ -220,7 +779,7 @@ async function runServerRuntime(options, runtime) {
|
|
|
220
779
|
});
|
|
221
780
|
const failures = [];
|
|
222
781
|
try {
|
|
223
|
-
await withShutdownDeadline(() => baseSessionManager.closeSession(sessionId), `Session '${sessionId}' runtime shutdown`);
|
|
782
|
+
await withShutdownDeadline(() => baseSessionManager.closeSession(sessionId, { reason: shuttingDown ? "host_shutdown" : options?.reason }), `Session '${sessionId}' runtime shutdown`);
|
|
224
783
|
} catch (error) {
|
|
225
784
|
failures.push(error);
|
|
226
785
|
}
|
|
@@ -235,6 +794,7 @@ async function runServerRuntime(options, runtime) {
|
|
|
235
794
|
failures.push(error);
|
|
236
795
|
}
|
|
237
796
|
if (failures.length > 0) throw new AggregateError(failures, `Session '${sessionId}' shutdown failed`);
|
|
797
|
+
if (!shuttingDown && closingWorkspaceId !== void 0) await handOffClosedSession(sessionId, closingWorkspaceId, options?.keepDormant === true);
|
|
238
798
|
};
|
|
239
799
|
const sessionManager = {
|
|
240
800
|
async create(sessionOptions) {
|
|
@@ -244,7 +804,7 @@ async function runServerRuntime(options, runtime) {
|
|
|
244
804
|
host = await baseSessionManager.create(sessionOptions);
|
|
245
805
|
} catch (error) {
|
|
246
806
|
if (setup !== void 0 && pendingSessions.delete(sessionOptions.sessionId)) await setup.cleanup().catch((cleanupError) => notice(String(cleanupError)));
|
|
247
|
-
throw error;
|
|
807
|
+
throw asError(error);
|
|
248
808
|
}
|
|
249
809
|
if (setup === void 0 || mountSessionApis === void 0) return host;
|
|
250
810
|
try {
|
|
@@ -259,48 +819,160 @@ async function runServerRuntime(options, runtime) {
|
|
|
259
819
|
pendingSessions.delete(sessionOptions.sessionId);
|
|
260
820
|
await baseSessionManager.closeSession(sessionOptions.sessionId).catch((closeError) => notice(String(closeError)));
|
|
261
821
|
await setup.cleanup().catch((cleanupError) => notice(String(cleanupError)));
|
|
262
|
-
throw error;
|
|
822
|
+
throw asError(error);
|
|
263
823
|
}
|
|
264
824
|
},
|
|
265
|
-
get: (sessionId) => baseSessionManager.get(sessionId),
|
|
266
|
-
sessions: () => baseSessionManager.sessions(),
|
|
825
|
+
get: (sessionId) => baseSessionManager.get(sessionId) ?? router?.mirror(sessionId),
|
|
826
|
+
sessions: () => [...baseSessionManager.sessions(), ...router?.mirrors() ?? []],
|
|
267
827
|
closeSession: closeManagedSession,
|
|
268
828
|
async close() {
|
|
269
|
-
const ids =
|
|
829
|
+
const ids = sessionManager.sessions().map((session) => session.runtime.sessionId);
|
|
270
830
|
const failures = (await Promise.allSettled(ids.map((id) => closeManagedSession(id)))).filter((outcome) => outcome.status === "rejected").map((outcome) => outcome.reason);
|
|
271
831
|
if (failures.length > 0) throw new AggregateError(failures, "Headless session shutdown failed");
|
|
272
832
|
}
|
|
273
833
|
};
|
|
274
834
|
let requestSessionApi = async () => Response.json({ error: "Session API unavailable." }, { status: 404 });
|
|
835
|
+
/** Assigned once the shared API context exists: the host-side APIs of a workspace whose scope it does not serve. */
|
|
836
|
+
let unservedWorkspaceApi = () => void 0;
|
|
275
837
|
let openSession = async () => {
|
|
276
838
|
throw new Error("The cockpit session service is not ready.");
|
|
277
839
|
};
|
|
278
840
|
let admitWorkspace = async () => {
|
|
279
841
|
throw new Error("Workspace admission is not ready.");
|
|
280
842
|
};
|
|
843
|
+
let generalWorkspace;
|
|
844
|
+
/** Assigned once session revival is wired; absent before then, when no session or workspace can ask for one. */
|
|
845
|
+
let coordinators;
|
|
846
|
+
/** Assigned with the session API wiring, before any session can be revived. */
|
|
847
|
+
let restoreSessionSummary = () => void 0;
|
|
848
|
+
/** Set once start-up restore has settled; until then the stored directory may still be changing. */
|
|
849
|
+
let directoryRestored = false;
|
|
850
|
+
const allDormant = () => [...openSessions.list(), ...router?.dormant() ?? []];
|
|
851
|
+
const startupSandboxWorkspaces = new Set(workspaces.list().filter((entry) => entry.sandbox !== void 0).map((entry) => entry.id));
|
|
852
|
+
const startupRecoveryIds = /* @__PURE__ */ new Set();
|
|
853
|
+
let sandboxBotRecovery = Promise.resolve();
|
|
854
|
+
let resolveRevivalReady;
|
|
855
|
+
const revivalReady = new Promise((resolve) => {
|
|
856
|
+
resolveRevivalReady = resolve;
|
|
857
|
+
});
|
|
858
|
+
let reviveSession = async (sessionId, options) => {
|
|
859
|
+
if (!options?.automatic) throw new Error("Session revival is not ready.");
|
|
860
|
+
await revivalReady;
|
|
861
|
+
return reviveSession(sessionId, options);
|
|
862
|
+
};
|
|
281
863
|
let remoteRuntime;
|
|
864
|
+
const remoteOrigin = {
|
|
865
|
+
current: () => remoteRuntime?.remote.publicOrigin(),
|
|
866
|
+
revision: () => remoteRuntime?.remote.publicOriginRevision() ?? 0
|
|
867
|
+
};
|
|
868
|
+
const refreshGlobalSettings = () => refreshGlobalSettingsCache(hostFiles, async (operation, input) => remoteRuntime?.accountCall?.(operation, input), BACKGROUND_CONTEXT, {
|
|
869
|
+
homeDirectory,
|
|
870
|
+
environment: baseEnvironment
|
|
871
|
+
}).catch((error) => notice(`Global settings refresh failed: ${String(error)}`));
|
|
872
|
+
const globalSettingsRefresh = setInterval(() => void refreshGlobalSettings(), 6e5);
|
|
873
|
+
globalSettingsRefresh.unref();
|
|
874
|
+
let stopNativePush;
|
|
875
|
+
let liveActivityPush;
|
|
282
876
|
const computerUse = await createComputerUseBinding(process, {
|
|
283
877
|
isDeviceAuthorized: (id) => remoteRuntime?.remote.isDeviceAuthorized(id) === true,
|
|
284
878
|
stepUpRequired: () => remoteRuntime?.remote.stepUpRequired("computer-use.activate") === true
|
|
285
879
|
});
|
|
880
|
+
/** Packages whose build failed since their scope's last commit, keyed like `bundler` scopes. */
|
|
881
|
+
const failedPackages = /* @__PURE__ */ new Map();
|
|
882
|
+
/** What Help's `help_status` reads: each package's latest failure per scope, oldest dropped first. */
|
|
883
|
+
const packageFailures = /* @__PURE__ */ new Map();
|
|
884
|
+
const recordPackageFailure = (record) => {
|
|
885
|
+
const id = `${record.scope}\0${record.packageName}`;
|
|
886
|
+
const reason = record.reason.slice(0, 512);
|
|
887
|
+
const repeated = packageFailures.get(id)?.reason === reason;
|
|
888
|
+
packageFailures.delete(id);
|
|
889
|
+
packageFailures.set(id, {
|
|
890
|
+
...record,
|
|
891
|
+
reason,
|
|
892
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
893
|
+
});
|
|
894
|
+
for (const oldest of packageFailures.keys()) {
|
|
895
|
+
if (packageFailures.size <= PACKAGE_FAILURE_LIMIT) break;
|
|
896
|
+
packageFailures.delete(oldest);
|
|
897
|
+
}
|
|
898
|
+
if (!repeated) notifyPackageFailure(record);
|
|
899
|
+
};
|
|
900
|
+
/** Shows a failure once in each live top-level session of its scope, as a notification the hub sends to web and native. */
|
|
901
|
+
const notifyPackageFailure = (record) => {
|
|
902
|
+
for (const session of hub.snapshot()) {
|
|
903
|
+
if (session.parentSessionId !== void 0 || session.host.agentSession !== void 0) continue;
|
|
904
|
+
if (record.scope !== "host" && record.scope !== `workspace:${session.workspaceId}`) continue;
|
|
905
|
+
const t = session.host.translate ?? ((_key, fallback) => fallback);
|
|
906
|
+
const vars = {
|
|
907
|
+
package: record.packageName,
|
|
908
|
+
stage: record.stage === "load" ? t("cli.notice.stageLoad", "load") : t("cli.notice.stageApply", "apply"),
|
|
909
|
+
reason: record.reason
|
|
910
|
+
};
|
|
911
|
+
const body = record.previous === "restored" ? t("cli.notice.pluginFailedRestored", "{package} could not {stage} ({reason}). Its previous build still runs.") : t("cli.notice.pluginFailed", "{package} could not {stage} ({reason})");
|
|
912
|
+
const data = createPoNotificationEntryData({
|
|
913
|
+
title: t("cli.notice.pluginFailedTitle", "Plugin failed"),
|
|
914
|
+
body: formatMessage(body, vars),
|
|
915
|
+
level: "error"
|
|
916
|
+
});
|
|
917
|
+
if (!data) continue;
|
|
918
|
+
session.host.runtime.appendCustomEntry(PO_NOTIFICATION_ENTRY_TYPE, data).catch((error) => notice(`Plugin failure notice for session ${session.id} failed: ${String(error)}`));
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
/** Ends one install of a scope: returns the packages that failed to apply and clears the rest's record. */
|
|
922
|
+
const takeFailedPackages = (key, packages) => {
|
|
923
|
+
const failed = failedPackages.get(key) ?? /* @__PURE__ */ new Set();
|
|
924
|
+
failedPackages.delete(key);
|
|
925
|
+
for (const { declaration } of packages) if (!failed.has(declaration.packageName)) packageFailures.delete(`${key}\0${declaration.packageName}`);
|
|
926
|
+
return failed;
|
|
927
|
+
};
|
|
928
|
+
const profileSourceScopes = /* @__PURE__ */ new Map();
|
|
286
929
|
let hub;
|
|
287
930
|
/** Assigned once the global builds can be read; no session opens before then. */
|
|
288
931
|
let publishSessionCompositions = () => ({});
|
|
289
932
|
hub = createHeadlessHub({
|
|
933
|
+
clientDevices,
|
|
290
934
|
manager: sessionManager,
|
|
291
935
|
platform,
|
|
292
|
-
|
|
293
|
-
|
|
936
|
+
communicationPolicy: canSessionsCommunicate,
|
|
937
|
+
coordinationPolicy: sessionCoordinates,
|
|
938
|
+
resolveProfileIdentity: (root, name) => {
|
|
939
|
+
const scope = profileSourceScopes.get(root);
|
|
940
|
+
const sources = scope === void 0 ? void 0 : readProfileSources(scope.context, { workspaceId: scope.workspaceId });
|
|
941
|
+
const identity = mergeProfiles(loadProfileCatalog(root, homeDirectory).profiles, sources).find((profile) => profile.name === name)?.identity;
|
|
294
942
|
return identity === void 0 ? void 0 : {
|
|
295
943
|
displayName: identity.name,
|
|
296
944
|
icon: identity.icon
|
|
297
945
|
};
|
|
298
946
|
},
|
|
299
|
-
publishSessionCompositions: (sessionId, root,
|
|
300
|
-
admitWorkspace: async ({ root, name }) =>
|
|
947
|
+
publishSessionCompositions: (sessionId, root, preset, extraLayers) => publishSessionCompositions(sessionId, root, preset, extraLayers),
|
|
948
|
+
admitWorkspace: async ({ root, name, declaration, instructions }) => {
|
|
949
|
+
const byName = root === void 0 || root.trim() === "";
|
|
950
|
+
if (root !== void 0) {
|
|
951
|
+
const resolved = await resolveWorkspaceRoot(root);
|
|
952
|
+
if (workspaces.list().some((record) => record.kind === "session" && record.root === resolved)) throw new Error("The session backing workspace is managed by Po.");
|
|
953
|
+
}
|
|
954
|
+
const admitted = await admitWorkspace(byName ? await createNamedWorkspaceFolder(name ?? "", homeDirectory) : root, {
|
|
955
|
+
name,
|
|
956
|
+
declaration,
|
|
957
|
+
instructions
|
|
958
|
+
});
|
|
959
|
+
if (byName && admitted.sandbox !== void 0) throw new Error(`Workspace '${admitted.name ?? admitted.id}' runs in a sandbox and cannot be admitted by name.`);
|
|
960
|
+
return admitted;
|
|
961
|
+
},
|
|
962
|
+
dormantSessions: allDormant,
|
|
963
|
+
...sandboxIdentity === void 0 ? { removedSessions: async (workspaceId) => (await sessionRemoval.list(workspaceId)).map((entry) => ({
|
|
964
|
+
sessionId: entry.id,
|
|
965
|
+
name: entry.name ?? "",
|
|
966
|
+
removedAt: entry.removedAt
|
|
967
|
+
})) } : {},
|
|
968
|
+
reviveSession: (sessionId, options) => reviveSession(sessionId, options),
|
|
969
|
+
directoryReady: (workspaceId) => directoryRestored && openSessions.complete?.() === true && (router?.contains(workspaceId) !== true || router.directoryReady(workspaceId)),
|
|
301
970
|
onWorkspaceRemoved: (workspaceId) => {
|
|
971
|
+
for (const [root, scope] of profileSourceScopes) if (scope.workspaceId === workspaceId) profileSourceScopes.delete(root);
|
|
302
972
|
workspaces.remove(workspaceId);
|
|
303
973
|
bundler.forgetScope(`workspace:${workspaceId}`);
|
|
974
|
+
clientInventories.delete(`workspace:${workspaceId}`);
|
|
975
|
+
hostServicesChanged();
|
|
304
976
|
webCompositions?.remove({
|
|
305
977
|
scope: "workspace",
|
|
306
978
|
workspaceId
|
|
@@ -312,41 +984,204 @@ async function runServerRuntime(options, runtime) {
|
|
|
312
984
|
},
|
|
313
985
|
createSession: async (request, placement) => {
|
|
314
986
|
if (placement === void 0) return openSession(request);
|
|
315
|
-
if (checkoutWorkspaceId(workspaces.list(), request.cwd) !== placement.workspaceId) throw new Error("The session directory is outside this workspace.");
|
|
987
|
+
if (await checkoutWorkspaceId(workspaces.list(), request.cwd, placement.workspaceId) !== placement.workspaceId) throw new Error("The session directory is outside this workspace.");
|
|
316
988
|
return openSession(request, void 0, placement.workspaceId);
|
|
317
989
|
},
|
|
318
990
|
sessionReservations: {
|
|
319
991
|
read(id, parentSessionId) {
|
|
320
|
-
|
|
321
|
-
return cockpit.sessionReservations.read(id, parentSessionId);
|
|
992
|
+
return reservations().read(id, parentSessionId);
|
|
322
993
|
},
|
|
323
994
|
async prepare(id, parentSessionId, cwd) {
|
|
324
|
-
|
|
325
|
-
return cockpit.sessionReservations.prepare(id, parentSessionId, cwd);
|
|
995
|
+
return reservations().prepare(id, parentSessionId, cwd);
|
|
326
996
|
},
|
|
327
997
|
async complete(id, parentSessionId) {
|
|
328
|
-
|
|
329
|
-
return cockpit.sessionReservations.complete(id, parentSessionId);
|
|
998
|
+
return reservations().complete(id, parentSessionId);
|
|
330
999
|
}
|
|
331
1000
|
},
|
|
332
1001
|
onNotice: notice,
|
|
1002
|
+
onPackageFailed: (mount, failure) => {
|
|
1003
|
+
if (mount.scope === "session") return;
|
|
1004
|
+
const key = mount.scope === "host" ? "host" : `workspace:${mount.workspaceId}`;
|
|
1005
|
+
failedPackages.set(key, (failedPackages.get(key) ?? /* @__PURE__ */ new Set()).add(failure.packageName));
|
|
1006
|
+
recordPackageFailure({
|
|
1007
|
+
scope: key,
|
|
1008
|
+
stage: "apply",
|
|
1009
|
+
...failure
|
|
1010
|
+
});
|
|
1011
|
+
},
|
|
333
1012
|
hubToken: () => attachToken,
|
|
334
1013
|
requestSessionApi: (scope, request) => requestSessionApi(scope, request),
|
|
1014
|
+
unservedWorkspaceApi: (workspaceId, basePath) => unservedWorkspaceApi(workspaceId, basePath),
|
|
335
1015
|
...computerUse === void 0 ? {} : { computerUse }
|
|
336
1016
|
});
|
|
1017
|
+
const stopRecoveryReports = hub.lifecycle.subscribe(({ sessionId, attemptId, trigger: source, state: phase, reason }) => {
|
|
1018
|
+
if (source === "create" || source === void 0 && phase !== "paused") return;
|
|
1019
|
+
const trigger = source ?? "boot";
|
|
1020
|
+
try {
|
|
1021
|
+
hub.directEvents.publish("po/session/recovery", sessionId, {
|
|
1022
|
+
attemptId,
|
|
1023
|
+
trigger,
|
|
1024
|
+
phase,
|
|
1025
|
+
reason
|
|
1026
|
+
});
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
rawNotice(`Session recovery listener failed: ${errorMessage(error)}`);
|
|
1029
|
+
}
|
|
1030
|
+
rawNotice(`Session '${sessionId}' recovery ${String(attemptId)} (${trigger}): ${phase}${reason === void 0 ? "" : ` (${reason})`}.`);
|
|
1031
|
+
telemetry.recordEvent("po_server.session_recovery", {
|
|
1032
|
+
session_id: sessionId,
|
|
1033
|
+
attempt_id: attemptId,
|
|
1034
|
+
trigger,
|
|
1035
|
+
outcome: phase,
|
|
1036
|
+
...reason === void 0 ? {} : { reason }
|
|
1037
|
+
}).catch((error) => rawNotice(`session recovery telemetry failed: ${errorMessage(error)}`));
|
|
1038
|
+
});
|
|
1039
|
+
const pauseRevival = (sessionId) => {
|
|
1040
|
+
hub.lifecycle.rememberDormant(sessionId);
|
|
1041
|
+
const snapshot = hub.lifecycle.snapshot(sessionId);
|
|
1042
|
+
if (snapshot?.state === "dormant" || snapshot?.state === "failed") hub.lifecycle.transition(sessionId, snapshot.attemptId, "paused", "crash_limit");
|
|
1043
|
+
};
|
|
1044
|
+
const modelGateway = sandboxIdentity === void 0 ? void 0 : createModelGatewayContainer({ hub });
|
|
1045
|
+
/** Assigned once the global builds can be read: a mirror's compositions come from the host composition. */
|
|
1046
|
+
let publishMirrorCompositions = () => ({});
|
|
1047
|
+
/** Assigned once the global builds can be read: another host's sessions run this host's signed plugin copies. */
|
|
1048
|
+
let publishRemoteCompositions = () => void 0;
|
|
1049
|
+
let hostModels;
|
|
1050
|
+
if (sandboxIdentity === void 0) router = createSandboxRouter({
|
|
1051
|
+
hub,
|
|
1052
|
+
sandboxes,
|
|
1053
|
+
workspaces: () => workspaces.list(),
|
|
1054
|
+
announceWorkspace: (workspaceId) => refreshWorkspace(workspaceId),
|
|
1055
|
+
sessionCompositions: (sessionId) => publishMirrorCompositions(sessionId),
|
|
1056
|
+
forgetCompositions: (sessionId) => {
|
|
1057
|
+
webCompositions?.remove({
|
|
1058
|
+
scope: "session",
|
|
1059
|
+
sessionId
|
|
1060
|
+
});
|
|
1061
|
+
webCompositions?.removeNative({
|
|
1062
|
+
scope: "session",
|
|
1063
|
+
sessionId
|
|
1064
|
+
});
|
|
1065
|
+
},
|
|
1066
|
+
modelGateway: () => hostModels ??= createHostModelGateway(piAgentDirectory(baseEnvironment, homeDirectory), homeDirectory).catch((error) => {
|
|
1067
|
+
notice(`The host models for sandboxes could not load: ${error instanceof Error ? error.message : String(error)}`);
|
|
1068
|
+
hostModels = void 0;
|
|
1069
|
+
}),
|
|
1070
|
+
onBotDirectoryReady: (workspaceId) => {
|
|
1071
|
+
if (!startupSandboxWorkspaces.delete(workspaceId)) return;
|
|
1072
|
+
const bots = allDormant().filter((record) => record.workspaceId === workspaceId && record.bot !== void 0 && record.sessionProvenance !== WORKFLOW_STEP_SESSION_PROVENANCE && !startupRecoveryIds.has(record.sessionId));
|
|
1073
|
+
if (bots.length > 0 && recycled?.kind === "live" && !crashRestoreCounted) {
|
|
1074
|
+
const latePlan = prepareSessionRestore({
|
|
1075
|
+
...recycled,
|
|
1076
|
+
sessionIds: bots.map((record) => record.sessionId)
|
|
1077
|
+
});
|
|
1078
|
+
restorePlan.crashRestores = latePlan.crashRestores;
|
|
1079
|
+
restorePlan.blocked = latePlan.blocked;
|
|
1080
|
+
crashRestoreCounted = true;
|
|
1081
|
+
}
|
|
1082
|
+
for (const record of bots) {
|
|
1083
|
+
startupRecoveryIds.add(record.sessionId);
|
|
1084
|
+
recoverySessionIds.add(record.sessionId);
|
|
1085
|
+
}
|
|
1086
|
+
persistRecovery();
|
|
1087
|
+
if (restorePlan.blocked) return;
|
|
1088
|
+
sandboxBotRecovery = sandboxBotRecovery.then(async () => {
|
|
1089
|
+
await revivalReady;
|
|
1090
|
+
for (const record of bots) {
|
|
1091
|
+
if (shuttingDown || signal.aborted) return;
|
|
1092
|
+
try {
|
|
1093
|
+
await enqueueRecovery(async () => {
|
|
1094
|
+
if (!shuttingDown && !signal.aborted) await reviveSession(record.sessionId, { automatic: true });
|
|
1095
|
+
});
|
|
1096
|
+
} catch (error) {
|
|
1097
|
+
if (hub.session(record.sessionId) === void 0) notice(`Bot '${record.sessionId}' did not reopen after the restart: ${errorMessage(error)}`);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
},
|
|
1102
|
+
onLinked: (workspaceId) => {
|
|
1103
|
+
const transition = sandboxTransitions.get(workspaceId)?.sandboxState;
|
|
1104
|
+
if (transition === "starting" || transition === "failed") sandboxTransitions.delete(workspaceId);
|
|
1105
|
+
refreshWorkspace(workspaceId);
|
|
1106
|
+
const provider = handoffProviderOf(workspaceId);
|
|
1107
|
+
const workspace = workspaces.list().find((entry) => entry.id === workspaceId);
|
|
1108
|
+
if (provider === void 0 || workspace === void 0 || handoff === void 0) return;
|
|
1109
|
+
handoff.retry(workspace, provider).catch((error) => notice(`Workspace '${workspaceId}' handover retry failed: ${errorMessage(error)}`));
|
|
1110
|
+
},
|
|
1111
|
+
onNotice: notice
|
|
1112
|
+
});
|
|
1113
|
+
const sessionRemoval = createHostSessionRemoval({
|
|
1114
|
+
database: async () => (await hub.sessionParentScope(void 0)).resolve(PO_DB_CONTRACT),
|
|
1115
|
+
openSessions,
|
|
1116
|
+
summary: async (sessionId, workspaceId) => {
|
|
1117
|
+
const root = hub.workspaces().find((workspace) => workspace.id === workspaceId)?.root;
|
|
1118
|
+
if (!root) return void 0;
|
|
1119
|
+
const others = new Set((await platform.sessions.list(BACKGROUND_CONTEXT)).map((stored) => stored.sessionId).filter((id) => id !== sessionId));
|
|
1120
|
+
return (await listSavedSessions(platform.sessions, root, others, workspaceId))[0];
|
|
1121
|
+
},
|
|
1122
|
+
isLive: (sessionId) => hub.session(sessionId) !== void 0 || baseSessionManager.get(sessionId) !== void 0,
|
|
1123
|
+
purge: (sessionId) => purgeSession({
|
|
1124
|
+
platform,
|
|
1125
|
+
sessionId,
|
|
1126
|
+
environment: baseEnvironment,
|
|
1127
|
+
defaultAgentDirectory: piAgentDirectory(baseEnvironment, homeDirectory),
|
|
1128
|
+
home: {
|
|
1129
|
+
poHome: poHomeDirectory(homeDirectory, baseEnvironment),
|
|
1130
|
+
agentDir: path.dirname(serverDirectory)
|
|
1131
|
+
}
|
|
1132
|
+
}),
|
|
1133
|
+
onNotice: notice
|
|
1134
|
+
});
|
|
1135
|
+
if (router !== void 0) {
|
|
1136
|
+
const linkedRouter = router;
|
|
1137
|
+
handoff = createSandboxSessionHandoff({
|
|
1138
|
+
host: {
|
|
1139
|
+
poHome: poHomeDirectory(homeDirectory, baseEnvironment),
|
|
1140
|
+
agentDir: path.dirname(serverDirectory)
|
|
1141
|
+
},
|
|
1142
|
+
openSessions,
|
|
1143
|
+
savedSessionIds: async (workspace) => (await listSavedSessionRecords(platform.sessions, workspace.root, await sessionRemoval.hidden(hub.snapshot().map((active) => active.id)), workspace.id)).map((saved) => saved.summary.id),
|
|
1144
|
+
isLive: (sessionId) => hub.session(sessionId) !== void 0 || baseSessionManager.get(sessionId) !== void 0,
|
|
1145
|
+
adopt: (workspaceId, record) => linkedRouter.adoptSession(workspaceId, record),
|
|
1146
|
+
onNotice: notice
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
337
1149
|
/** Started by the idle restart once the server is serving; until then a restart waits. */
|
|
338
1150
|
let requestRestart;
|
|
1151
|
+
const reportRestartBlocker = (category, age = idleRestart.pendingAgeMs()) => {
|
|
1152
|
+
notice(`Idle restart blocked: category=${category} pending_age_ms=${String(age)}`);
|
|
1153
|
+
telemetry.recordEvent("po_server.idle_restart_blocked", {
|
|
1154
|
+
reason: category,
|
|
1155
|
+
pending_age_ms: age,
|
|
1156
|
+
superseded_module_count: idleRestart.supersededCount()
|
|
1157
|
+
}).catch((error) => notice(`idle restart telemetry failed: ${String(error)}`));
|
|
1158
|
+
};
|
|
339
1159
|
const idleRestart = createIdleRestart({
|
|
340
1160
|
...testIdleRestartOverrides(baseEnvironment),
|
|
341
|
-
busy: async () => {
|
|
1161
|
+
busy: async (signal) => {
|
|
1162
|
+
if (recovering || reviving.size > 0 || hub.lifecycle.list().some(({ sessionId }) => hub.lifecycle.opening(sessionId) !== void 0) || (router?.mirrors().length ?? 0) > 0) {
|
|
1163
|
+
reportRestartBlocker("sandbox_mirror");
|
|
1164
|
+
return true;
|
|
1165
|
+
}
|
|
342
1166
|
const hosts = sessionManager.sessions();
|
|
343
|
-
|
|
1167
|
+
const working = hosts.map((host) => {
|
|
344
1168
|
const root = sessionServiceRoots.get(host);
|
|
345
1169
|
const service = root === void 0 ? void 0 : readPoBackgroundWorkService(root);
|
|
346
|
-
return service
|
|
347
|
-
}))
|
|
348
|
-
|
|
1170
|
+
return service === void 0 ? void 0 : backgroundRestartBlocker(service.snapshot());
|
|
1171
|
+
}).find((category) => category !== void 0);
|
|
1172
|
+
if (working !== void 0) {
|
|
1173
|
+
reportRestartBlocker(working);
|
|
1174
|
+
return true;
|
|
1175
|
+
}
|
|
1176
|
+
const states = await Promise.all(hosts.map((host) => host.runtime.readState()));
|
|
1177
|
+
signal?.throwIfAborted();
|
|
1178
|
+
if (states.some((state) => state.isStreaming || state.isCompacting)) {
|
|
1179
|
+
reportRestartBlocker("streaming_compacting");
|
|
1180
|
+
return true;
|
|
1181
|
+
}
|
|
1182
|
+
return false;
|
|
349
1183
|
},
|
|
1184
|
+
onBlocked: reportRestartBlocker,
|
|
350
1185
|
restart: () => requestRestart?.(),
|
|
351
1186
|
onError: (error) => notice(`Idle restart check failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
352
1187
|
});
|
|
@@ -356,18 +1191,38 @@ async function runServerRuntime(options, runtime) {
|
|
|
356
1191
|
const record = openSessions.list().find((entry) => entry.sessionId === event.session.id);
|
|
357
1192
|
const groups = event.session.groups ?? [];
|
|
358
1193
|
const sameGroups = groups.length === (record?.groups ?? []).length && groups.every((group, index) => record?.groups?.[index] === group);
|
|
359
|
-
|
|
1194
|
+
const { bot, botRevision } = ((event.session.botRevision ?? 0) < (record?.botRevision ?? 0) ? record : event.session) ?? event.session;
|
|
1195
|
+
const sameBot = record?.botRevision === botRevision && JSON.stringify(record?.bot ?? null) === JSON.stringify(bot ?? null);
|
|
1196
|
+
if (record === void 0 || record.name === event.session.name && sameGroups && sameBot) return;
|
|
1197
|
+
const { bot: _bot, botRevision: _botRevision, ...rest } = record;
|
|
360
1198
|
openSessions.add({
|
|
361
|
-
...
|
|
1199
|
+
...rest,
|
|
362
1200
|
name: event.session.name,
|
|
363
|
-
groups
|
|
1201
|
+
groups,
|
|
1202
|
+
...bot === void 0 ? {} : {
|
|
1203
|
+
bot: { ...bot },
|
|
1204
|
+
botRevision: botRevision ?? 0
|
|
1205
|
+
}
|
|
364
1206
|
});
|
|
365
1207
|
});
|
|
366
1208
|
let harnessContext;
|
|
367
1209
|
let launchWorkspaceId;
|
|
368
1210
|
let cockpit;
|
|
1211
|
+
const reservations = () => {
|
|
1212
|
+
if (!cockpit?.sessionReservations) throw new Error("Session setup is not ready.");
|
|
1213
|
+
return cockpit.sessionReservations;
|
|
1214
|
+
};
|
|
1215
|
+
const teamHost = createTeamHost({
|
|
1216
|
+
auditFile: path.join(poHomeDirectory(homeDirectory, baseEnvironment), "audit.jsonl"),
|
|
1217
|
+
onNotice: notice,
|
|
1218
|
+
remote: () => remoteRuntime,
|
|
1219
|
+
cockpit: () => cockpit
|
|
1220
|
+
});
|
|
1221
|
+
let cachedHostRequests;
|
|
369
1222
|
let attachToken;
|
|
370
1223
|
let webCompositions;
|
|
1224
|
+
/** Assigned once background sync exists: the native build is deferred until a phone needs it. */
|
|
1225
|
+
let requestNativeBuild = async () => void 0;
|
|
371
1226
|
const stopResourceMonitor = monitorRuntimeResources({
|
|
372
1227
|
record: (attributes) => telemetry.recordEvent("po_server.resources", attributes),
|
|
373
1228
|
counts: () => {
|
|
@@ -376,29 +1231,58 @@ async function runServerRuntime(options, runtime) {
|
|
|
376
1231
|
sessions: sessionManager.sessions().length,
|
|
377
1232
|
running_jobs: budget.running,
|
|
378
1233
|
queued_jobs: budget.queued,
|
|
379
|
-
job_limit: budget.limit
|
|
1234
|
+
job_limit: budget.limit,
|
|
1235
|
+
superseded_module_count: idleRestart.supersededCount(),
|
|
1236
|
+
idle_restart_pending_age_ms: idleRestart.pendingAgeMs()
|
|
380
1237
|
};
|
|
381
1238
|
},
|
|
382
1239
|
warn: notice
|
|
383
1240
|
});
|
|
384
1241
|
try {
|
|
385
1242
|
await telemetry.runInSpan("po_server.startup", {}, async () => {
|
|
386
|
-
|
|
1243
|
+
await refreshPackageWatching();
|
|
1244
|
+
const token = getOrThrow(await hostFiles.readTextFile(options.tokenFile, BACKGROUND_CONTEXT)).trim();
|
|
387
1245
|
if (!token) throw new Error("The attach token file is empty.");
|
|
388
1246
|
attachToken = token;
|
|
389
1247
|
const resolved = resolveSessionIdentity(options.agentArgs, {
|
|
390
1248
|
sessionId: options.sessionId ?? crypto.randomUUID(),
|
|
391
1249
|
sessionName: options.sessionName
|
|
392
1250
|
});
|
|
393
|
-
const globalRoot = globalPoConfigDirectory(homeDirectory);
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
1251
|
+
const globalRoot = globalPoConfigDirectory(homeDirectory, baseEnvironment);
|
|
1252
|
+
let reconcileOrgPlugins = async () => void 0;
|
|
1253
|
+
const orgAccount = createOrgPluginLibraryBinding();
|
|
1254
|
+
const orgLibrary = orgAccount ? createOrgPluginLibrary({
|
|
1255
|
+
fs: hostFiles,
|
|
1256
|
+
directory: path.join(globalRoot, "org-library"),
|
|
1257
|
+
account: orgAccount,
|
|
1258
|
+
activation: createOrgPluginActivation({
|
|
1259
|
+
fs: hostFiles,
|
|
1260
|
+
homeDirectory,
|
|
1261
|
+
environment: baseEnvironment,
|
|
1262
|
+
globalRoot,
|
|
1263
|
+
reconcile: (packages) => reconcileOrgPlugins(packages)
|
|
1264
|
+
})
|
|
1265
|
+
}) : void 0;
|
|
1266
|
+
await orgLibrary?.sync();
|
|
1267
|
+
const publicationDirectory = path.join(globalRoot, "server");
|
|
1268
|
+
await reapAbandonedPublications(platform.env(baseCwd), publicationDirectory, processIsAlive).catch((error) => notice(`Abandoned publication cleanup failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
1269
|
+
webCompositions = createWebCompositions(publicationDirectory, notice, {
|
|
1270
|
+
pid: nodeHost.processId(),
|
|
1271
|
+
startedAt: Date.now()
|
|
1272
|
+
});
|
|
397
1273
|
const backgroundSync = createBackgroundSync({
|
|
1274
|
+
files: hostFiles,
|
|
398
1275
|
environment: baseEnvironment,
|
|
399
1276
|
onNotice: notice,
|
|
400
|
-
onExit: () => pickUpSync()
|
|
1277
|
+
onExit: () => scopeReload.pickUpSync(),
|
|
1278
|
+
...sandboxIdentity === void 0 ? {} : { skipArtifactBuilds: true }
|
|
401
1279
|
});
|
|
1280
|
+
let nativeBuildRequested = false;
|
|
1281
|
+
requestNativeBuild = async () => {
|
|
1282
|
+
if (nativeBuildRequested) return;
|
|
1283
|
+
nativeBuildRequested = true;
|
|
1284
|
+
await backgroundSync.request("a native client connected", ["native"]);
|
|
1285
|
+
};
|
|
402
1286
|
const syncCheckpoints = createSyncCheckpoints({
|
|
403
1287
|
globalRoot,
|
|
404
1288
|
homeDirectory,
|
|
@@ -408,82 +1292,167 @@ async function runServerRuntime(options, runtime) {
|
|
|
408
1292
|
});
|
|
409
1293
|
watcher.add({
|
|
410
1294
|
path: path.dirname(syncPointerPath(globalRoot)),
|
|
411
|
-
include: (file) => file === path.basename(syncPointerPath(globalRoot))
|
|
1295
|
+
include: (file) => file === path.basename(syncPointerPath(globalRoot)) || /^app-[a-z]+\.json$/u.test(file),
|
|
1296
|
+
source: (file) => file === path.basename(syncPointerPath(globalRoot)) ? "sync-pointer" : "watch"
|
|
412
1297
|
});
|
|
413
1298
|
/** What the root opened without: packages that do not resolve yet and web plugins with no slot. */
|
|
414
|
-
const unsyncedOf = (root) => {
|
|
1299
|
+
const unsyncedOf = async (root) => {
|
|
415
1300
|
try {
|
|
416
1301
|
const compositions = bundler.compositions(root);
|
|
417
|
-
const
|
|
418
|
-
return
|
|
1302
|
+
const webPackages = webBuild === void 0 ? [] : await unslottedWebPackages(webBuild, await compositionPackageRoots(compositions, hostFiles), hostFiles);
|
|
1303
|
+
return {
|
|
1304
|
+
selectors: unsyncedSelectors(compositions),
|
|
1305
|
+
webPackages
|
|
1306
|
+
};
|
|
419
1307
|
} catch (error) {
|
|
420
1308
|
notice(`'${root}' sync state could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
421
|
-
return
|
|
1309
|
+
return {
|
|
1310
|
+
selectors: [],
|
|
1311
|
+
webPackages: []
|
|
1312
|
+
};
|
|
422
1313
|
}
|
|
423
1314
|
};
|
|
424
1315
|
const workspaceLabel = (root, name) => `Workspace '${name ?? path.basename(root)}'`;
|
|
425
1316
|
/** A checkpoint: request a background sync when the root changed since the last one, and warn. */
|
|
426
|
-
const syncCheckpoint = (root, label, request = true) =>
|
|
427
|
-
root
|
|
428
|
-
label,
|
|
429
|
-
|
|
430
|
-
|
|
1317
|
+
const syncCheckpoint = async (root, label, request = true) => {
|
|
1318
|
+
const { selectors, webPackages } = await unsyncedOf(root);
|
|
1319
|
+
if (request && webPackages.length > 0) await syncCheckpoints.requestMissing(`web-slot:${root}:${webPackages.join(",")}`, `${label} has web plugins without a slot: ${webPackages.join(", ")}`);
|
|
1320
|
+
return syncCheckpoints.check({
|
|
1321
|
+
root,
|
|
1322
|
+
label,
|
|
1323
|
+
unsynced: [.../* @__PURE__ */ new Set([...selectors, ...webPackages])]
|
|
1324
|
+
}, request);
|
|
1325
|
+
};
|
|
431
1326
|
let webBuild;
|
|
1327
|
+
/** Workspace package roots the host mount adds: the copy of each host package a workspace runs for it. */
|
|
1328
|
+
let hostPackageRoots = [];
|
|
1329
|
+
const mountPackageRoots = (mount, root, preset, extraLayers) => mount.scope === "host" ? [...bundler.packageRoots(root, preset), ...hostPackageRoots] : bundler.packageRoots(root, preset, extraLayers);
|
|
432
1330
|
/**
|
|
433
1331
|
* Publishes one mount out of the current global build, naming only the plugin slots its root
|
|
434
|
-
* resolves. A session mount passes its
|
|
1332
|
+
* resolves. A session mount passes its preset, so it names only that preset's slots.
|
|
435
1333
|
*/
|
|
436
|
-
const publishWebMount = (mount, root,
|
|
1334
|
+
const publishWebMount = (mount, root, preset, extraLayers) => {
|
|
1335
|
+
if (webBuild === void 0) return void 0;
|
|
1336
|
+
const slots = mountWebPluginSlots(webBuild, mountPackageRoots(mount, root, preset, extraLayers));
|
|
1337
|
+
const publication = webCompositions?.publish(mount, webBuild, hub.channelTypes(), slots, mount.scope === "host" ? hostLocales : void 0);
|
|
1338
|
+
if (publication !== void 0) {
|
|
1339
|
+
const selected = new Set(slots);
|
|
1340
|
+
const inventory = clientInventoryFor(mount);
|
|
1341
|
+
inventory.packages = webBuild.plugins.filter((plugin) => selected.has(plugin.slot)).map((plugin) => {
|
|
1342
|
+
const name = plugin.brain?.packageName;
|
|
1343
|
+
const metadata = parsePoWebBrainMetadata(plugin.brain?.metadata);
|
|
1344
|
+
if (!metadata || typeof name !== "string" || name.length > 128 || !/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/iu.test(name)) return {
|
|
1345
|
+
owner: {
|
|
1346
|
+
kind: "unknown",
|
|
1347
|
+
packageName: null,
|
|
1348
|
+
origin: "unknown"
|
|
1349
|
+
},
|
|
1350
|
+
web: null
|
|
1351
|
+
};
|
|
1352
|
+
return {
|
|
1353
|
+
owner: {
|
|
1354
|
+
kind: "package",
|
|
1355
|
+
packageName: name,
|
|
1356
|
+
origin: isFixedHostPackage(name) || shippedPackages?.has(name) ? "po" : shippedPackages ? "personal" : "unknown"
|
|
1357
|
+
},
|
|
1358
|
+
web: metadata
|
|
1359
|
+
};
|
|
1360
|
+
});
|
|
1361
|
+
inventory.available = true;
|
|
1362
|
+
}
|
|
1363
|
+
return publication;
|
|
1364
|
+
};
|
|
437
1365
|
let nativeBuild;
|
|
438
1366
|
/** Publishes one mount's native composition out of the current global native build. */
|
|
439
|
-
const publishNativeMount = (mount, root,
|
|
440
|
-
|
|
1367
|
+
const publishNativeMount = (mount, root, preset, extraLayers) => nativeBuild === void 0 ? void 0 : webCompositions?.publishNative(mount, nativeBuild, hub.channelTypes(), mountNativePluginIds(nativeBuild, mountPackageRoots(mount, root, preset, extraLayers)), mount.scope === "host" ? hostLocales : void 0);
|
|
1368
|
+
/**
|
|
1369
|
+
* Republishes a host or workspace mount and reports whether its web or native composition
|
|
1370
|
+
* changed, so clients are told to swap only after a publish that succeeded and differs.
|
|
1371
|
+
*/
|
|
1372
|
+
const publishSharedMount = (mount, root) => {
|
|
1373
|
+
const current = () => JSON.stringify([webCompositions?.get(mount), webCompositions?.getNative(mount)]);
|
|
1374
|
+
const before = current();
|
|
1375
|
+
publishNativeMount(mount, root);
|
|
1376
|
+
publishWebMount(mount, root);
|
|
1377
|
+
return current() !== before;
|
|
1378
|
+
};
|
|
1379
|
+
publishSessionCompositions = (sessionId, root, preset, extraLayers) => ({
|
|
441
1380
|
webComposition: publishWebMount({
|
|
442
1381
|
scope: "session",
|
|
443
1382
|
sessionId
|
|
444
|
-
}, root,
|
|
1383
|
+
}, root, preset, extraLayers),
|
|
445
1384
|
nativeComposition: publishNativeMount({
|
|
446
1385
|
scope: "session",
|
|
447
1386
|
sessionId
|
|
448
|
-
}, root,
|
|
1387
|
+
}, root, preset, extraLayers)
|
|
449
1388
|
});
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
1389
|
+
publishMirrorCompositions = (sessionId) => ({
|
|
1390
|
+
webComposition: publishWebMount({
|
|
1391
|
+
scope: "session",
|
|
1392
|
+
sessionId
|
|
1393
|
+
}, globalRoot),
|
|
1394
|
+
nativeComposition: publishNativeMount({
|
|
1395
|
+
scope: "session",
|
|
1396
|
+
sessionId
|
|
1397
|
+
}, globalRoot)
|
|
458
1398
|
});
|
|
1399
|
+
publishRemoteCompositions = (pluginIds) => {
|
|
1400
|
+
if (webBuild === void 0 || webCompositions === void 0) return void 0;
|
|
1401
|
+
const wanted = new Set(pluginIds);
|
|
1402
|
+
const slots = /* @__PURE__ */ new Map();
|
|
1403
|
+
for (const plugin of [...webBuild.plugins].sort((a, b) => Number(b.isHost) - Number(a.isHost))) if (wanted.has(plugin.pluginId) && !slots.has(plugin.pluginId)) slots.set(plugin.pluginId, plugin.slot);
|
|
1404
|
+
const publish = (mount) => compositionToWire(webCompositions.publish(mount, webBuild, hub.channelTypes(), [...slots.values()]));
|
|
1405
|
+
return {
|
|
1406
|
+
workspace: publish({
|
|
1407
|
+
scope: "workspace",
|
|
1408
|
+
workspaceId: REMOTE_COMPOSITION_ID
|
|
1409
|
+
}),
|
|
1410
|
+
session: publish({
|
|
1411
|
+
scope: "session",
|
|
1412
|
+
sessionId: REMOTE_COMPOSITION_ID
|
|
1413
|
+
})
|
|
1414
|
+
};
|
|
1415
|
+
};
|
|
459
1416
|
/** The keys these roots derive the way sync does, each only when its build exists. */
|
|
460
|
-
const ownBuildKeys = () => {
|
|
461
|
-
const pluginRoots = globalWebPluginRoots(globalRoot, homeDirectory, baseEnvironment, notice);
|
|
462
|
-
const web = readGlobalWebBuildStatus({
|
|
1417
|
+
const ownBuildKeys = async () => {
|
|
1418
|
+
const pluginRoots = await globalWebPluginRoots(globalRoot, homeDirectory, baseEnvironment, notice);
|
|
1419
|
+
const web = await readGlobalWebBuildStatus({
|
|
463
1420
|
poHome: globalRoot,
|
|
464
1421
|
pluginRoots,
|
|
465
|
-
environment: baseEnvironment
|
|
1422
|
+
environment: baseEnvironment,
|
|
1423
|
+
files: hostFiles
|
|
466
1424
|
});
|
|
467
|
-
const native = readGlobalNativeBuildStatus({
|
|
1425
|
+
const native = await readGlobalNativeBuildStatus({
|
|
468
1426
|
poHome: globalRoot,
|
|
469
|
-
pluginRoots
|
|
1427
|
+
pluginRoots,
|
|
1428
|
+
files: hostFiles
|
|
470
1429
|
});
|
|
471
1430
|
return {
|
|
472
1431
|
...web.status === "current" ? { webKey: web.key } : {},
|
|
473
1432
|
...native.status === "current" ? { nativeKey: native.key } : {}
|
|
474
1433
|
};
|
|
475
1434
|
};
|
|
476
|
-
|
|
477
|
-
|
|
1435
|
+
/** Requests a sync when the web build these roots derive is missing, as after a web plugin rebuild moves its key. */
|
|
1436
|
+
const requestMissingWebBuild = async () => {
|
|
1437
|
+
const web = await readGlobalWebBuildStatus({
|
|
1438
|
+
poHome: globalRoot,
|
|
1439
|
+
pluginRoots: await globalWebPluginRoots(globalRoot, homeDirectory, baseEnvironment, notice),
|
|
1440
|
+
environment: baseEnvironment,
|
|
1441
|
+
files: hostFiles
|
|
1442
|
+
});
|
|
1443
|
+
if (web.status === "missing") await syncCheckpoints.requestMissing(`web:${web.key}`, `the web build ${web.key} is missing`);
|
|
1444
|
+
};
|
|
1445
|
+
const currentBuildKeys = async () => {
|
|
1446
|
+
const pointer = await readSyncPointer(globalRoot);
|
|
478
1447
|
return syncedBuildKeys({
|
|
479
1448
|
pointer,
|
|
480
|
-
ownsPointer: syncCheckpoints.ownsPointer(pointer),
|
|
1449
|
+
ownsPointer: await syncCheckpoints.ownsPointer(pointer),
|
|
481
1450
|
published: {
|
|
482
1451
|
web: webBuild !== void 0,
|
|
483
1452
|
native: nativeBuild !== void 0
|
|
484
1453
|
},
|
|
485
1454
|
ownKeys: ownBuildKeys,
|
|
486
|
-
newestWebKey: () => newestGlobalWebBuildKey(globalRoot)
|
|
1455
|
+
newestWebKey: () => newestGlobalWebBuildKey(globalRoot, hostFiles)
|
|
487
1456
|
});
|
|
488
1457
|
};
|
|
489
1458
|
/**
|
|
@@ -492,90 +1461,226 @@ async function runServerRuntime(options, runtime) {
|
|
|
492
1461
|
* a missing build leaves the previous one serving. Clients pick a new composition up at
|
|
493
1462
|
* their next refreshWebPluginCompositions.
|
|
494
1463
|
*/
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
if (
|
|
498
|
-
|
|
499
|
-
const
|
|
1464
|
+
let publicationGeneration = 0;
|
|
1465
|
+
const refreshWebBuild = async () => {
|
|
1466
|
+
if (shuttingDown || signal.aborted) return;
|
|
1467
|
+
const generation = ++publicationGeneration;
|
|
1468
|
+
const isCurrent = () => !shuttingDown && !signal.aborted && generation === publicationGeneration;
|
|
1469
|
+
const keys = await currentBuildKeys();
|
|
1470
|
+
const webChanged = keys.webKey != null && keys.webKey !== webBuild?.key;
|
|
1471
|
+
const nativeChanged = keys.nativeKey != null && keys.nativeKey !== nativeBuild?.key;
|
|
1472
|
+
const nextWeb = webChanged ? await readGlobalWebBuildRecord(globalRoot, keys.webKey, hostFiles) : webBuild;
|
|
1473
|
+
const nextNative = nativeChanged ? await readGlobalNativeBuildRecord(globalRoot, keys.nativeKey, hostFiles) : nativeBuild;
|
|
1474
|
+
if (!isCurrent()) return;
|
|
1475
|
+
if (webChanged && nextWeb === void 0) {
|
|
1476
|
+
notice(`The global web build ${String(keys.webKey)} is missing; run po sync.`);
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
if (nativeChanged && nextNative === void 0) {
|
|
1480
|
+
notice(`The global native build ${String(keys.nativeKey)} is missing; run po sync.`);
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
const mounts = hub.workspaces().filter(servedOnHost).map((workspace) => ({
|
|
500
1484
|
root: workspace.root,
|
|
501
1485
|
mount: {
|
|
502
1486
|
scope: "workspace",
|
|
503
1487
|
workspaceId: workspace.id
|
|
504
1488
|
}
|
|
505
1489
|
}));
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
1490
|
+
await Promise.all([globalRoot, ...mounts.map(({ root }) => root)].map((root) => bundler.packageEntries(root)));
|
|
1491
|
+
if (!isCurrent()) return;
|
|
1492
|
+
if (webChanged || nativeChanged) {
|
|
1493
|
+
if (!await telemetry.runInSpan("po_server.bundle_publication", {}, () => webCompositions.prepare(nextWeb, nextNative, isCurrent)) || !isCurrent()) return;
|
|
1494
|
+
webBuild = nextWeb;
|
|
1495
|
+
nativeBuild = nextNative;
|
|
1496
|
+
if (webChanged) hub.bumpRevision?.("host:web-bundle");
|
|
509
1497
|
}
|
|
1498
|
+
const changed = [{
|
|
1499
|
+
root: globalRoot,
|
|
1500
|
+
mount: { scope: "host" }
|
|
1501
|
+
}, ...mounts].filter(({ root, mount }) => publishSharedMount(mount, root)).map(({ mount }) => mount);
|
|
1502
|
+
hub.touchCompositions?.(changed);
|
|
1503
|
+
if (nativeChanged || webChanged) hub.refreshSessionCompositions?.();
|
|
510
1504
|
};
|
|
511
|
-
const loadComposition = async (root, scope, selection) => {
|
|
1505
|
+
const loadComposition = async (root, scope, selection, healthKey) => {
|
|
1506
|
+
if (scope !== "host") await refreshWorkspaceDeclarations(root);
|
|
512
1507
|
const selected = selection ?? bundler.defaultSelection(root);
|
|
513
1508
|
return telemetry.runInSpan("po_server.composition_load", { scope }, async () => loadServerPackages(scope, {
|
|
514
1509
|
entries: await bundler.packageEntries(root),
|
|
515
|
-
|
|
1510
|
+
preset: selected.preset,
|
|
516
1511
|
activeLayers: selected.activeLayers,
|
|
517
1512
|
retainCandidates: scope === "session",
|
|
518
1513
|
onNotice: notice,
|
|
1514
|
+
...healthKey === void 0 ? {} : { onPackageFailed: (packageName, reason) => recordPackageFailure({
|
|
1515
|
+
scope: healthKey,
|
|
1516
|
+
packageName,
|
|
1517
|
+
stage: "load",
|
|
1518
|
+
reason
|
|
1519
|
+
}) },
|
|
519
1520
|
poisoned: bundler.poisoned,
|
|
520
1521
|
importer: bundler.importer
|
|
521
1522
|
}));
|
|
522
1523
|
};
|
|
523
|
-
const
|
|
1524
|
+
const prepareHostLocales = async () => {
|
|
1525
|
+
await bundler.packageEntries(globalRoot);
|
|
1526
|
+
const roots = bundler.packageRoots(globalRoot, bundler.defaultSelection(globalRoot).preset);
|
|
1527
|
+
return readCompositionLocales([.../* @__PURE__ */ new Set([...roots, ...await webShellLocaleRoots(globalRoot, baseEnvironment, hostFiles)])], hostFiles);
|
|
1528
|
+
};
|
|
1529
|
+
let hostLocales;
|
|
1530
|
+
const scopeKey = (mount) => mount.scope === "host" ? "host" : `workspace:${mount.workspaceId}`;
|
|
524
1531
|
const scopeChecks = /* @__PURE__ */ new Map();
|
|
1532
|
+
/** Each package of a scope (`host`, `workspace:<id>`, `session:<id>`) whose current build failed. */
|
|
1533
|
+
const scopeFailures = (key) => [...packageFailures.values()].filter((record) => record.scope === key).map(({ packageName, reason }) => ({
|
|
1534
|
+
packageName,
|
|
1535
|
+
reason
|
|
1536
|
+
}));
|
|
525
1537
|
/**
|
|
526
|
-
* The reload check for one served
|
|
1538
|
+
* The reload check for one served host or workspace scope: recompute its package URLs
|
|
527
1539
|
* and, only when they changed, load the new set and install it. Unchanged URLs come from
|
|
528
1540
|
* the module cache and the scope skips them, so only changed packages import and restart;
|
|
529
1541
|
* a package no longer selected stays installed. A scope this server has not served yet is
|
|
530
1542
|
* left to its admission. Checks of one scope run one at a time; a changed package whose
|
|
531
|
-
* new build fails gets its previous build back
|
|
532
|
-
*
|
|
1543
|
+
* new build fails to apply gets its previous build back and is not committed, so the next
|
|
1544
|
+
* check applies it again. An import failure poisons its URL instead and waits for a rebuild,
|
|
1545
|
+
* which gets a new URL. Runs on a watched change, a finished sync and an upm change, never
|
|
1546
|
+
* on the session path.
|
|
1547
|
+
*
|
|
1548
|
+
* An `explicit` check (Help's reload) runs even when nothing looks changed, retries poisoned
|
|
1549
|
+
* imports, disposes installed packages the scope no longer declares, and rejects on failure.
|
|
533
1550
|
*/
|
|
534
|
-
const checkScope = (root, mount) => {
|
|
1551
|
+
const checkScope = (root, mount, explicit = false) => {
|
|
535
1552
|
const key = scopeKey(mount);
|
|
536
|
-
const
|
|
1553
|
+
const run = (scopeChecks.get(key) ?? Promise.resolve()).then(async () => {
|
|
1554
|
+
if (explicit || mount.scope === "host") await refreshPackageWatching();
|
|
1555
|
+
if (explicit) {
|
|
1556
|
+
try {
|
|
1557
|
+
await refreshWebBuild();
|
|
1558
|
+
} catch (error) {
|
|
1559
|
+
notice(`Web build check failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1560
|
+
}
|
|
1561
|
+
bundler.invalidate();
|
|
1562
|
+
bundler.poisoned.clear();
|
|
1563
|
+
}
|
|
1564
|
+
const change = await bundler.diffScope(key, root, mount.scope);
|
|
1565
|
+
if (change.first) return void 0;
|
|
1566
|
+
const nextLocales = mount.scope === "host" ? await prepareHostLocales() : void 0;
|
|
1567
|
+
if (!explicit && change.changed.length === 0 && change.reselected.length === 0 && change.removed.length === 0) {
|
|
1568
|
+
if (nextLocales !== void 0) {
|
|
1569
|
+
hostLocales = nextLocales;
|
|
1570
|
+
if (publishSharedMount(mount, root)) hub.touchCompositions?.([mount]);
|
|
1571
|
+
}
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
const bundle = await loadComposition(root, mount.scope, void 0, key);
|
|
1575
|
+
failedPackages.delete(key);
|
|
1576
|
+
const declared = new Set(bundle.entries.filter((entry) => entry.scopes.includes(mount.scope)).map((entry) => entry.packageName));
|
|
1577
|
+
let affected;
|
|
537
1578
|
try {
|
|
538
|
-
|
|
1579
|
+
const withdrawn = (await hub.sessionParentScope(mount.scope === "host" ? void 0 : mount.workspaceId)).withdrawnBy(bundle.packages, explicit ? declared : void 0);
|
|
1580
|
+
affected = [...sessionArtifacts].flatMap(([sessionId, artifacts]) => {
|
|
1581
|
+
const runtime = baseSessionManager.get(sessionId)?.runtime;
|
|
1582
|
+
return runtime !== void 0 && artifacts.apis.injectsAny?.(withdrawn) === true ? [runtime] : [];
|
|
1583
|
+
});
|
|
539
1584
|
} catch (error) {
|
|
540
|
-
notice(`
|
|
1585
|
+
notice(`Reload of ${key} could not read the service graph, so every session waits: ${errorMessage(error)}`);
|
|
1586
|
+
affected = baseSessionManager.sessions().map((session) => session.runtime);
|
|
541
1587
|
}
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
1588
|
+
const { installed, removed, failed } = await holdAtToolBoundaries(affected, async () => {
|
|
1589
|
+
let installed = await hub.installPackages(mount, bundle.packages);
|
|
1590
|
+
const removed = explicit ? installed.filter((name) => !declared.has(name)) : [];
|
|
1591
|
+
if (removed.length > 0) installed = await hub.uninstallPackages(mount, removed);
|
|
1592
|
+
const failed = takeFailedPackages(key, bundle.packages);
|
|
1593
|
+
if (nextLocales !== void 0) hostLocales = nextLocales;
|
|
1594
|
+
bundler.commitScope(key, root, mount.scope, bundle.entries, failed);
|
|
1595
|
+
hostServicesChanged();
|
|
1596
|
+
await hostCheck;
|
|
1597
|
+
return {
|
|
1598
|
+
installed,
|
|
1599
|
+
removed,
|
|
1600
|
+
failed
|
|
1601
|
+
};
|
|
1602
|
+
}, {
|
|
1603
|
+
timeoutMs: SHARED_RELOAD_HOLD_MS,
|
|
1604
|
+
onTimeout: (waiting) => notice(`${String(waiting)} session(s) still in a tool round after ${String(SHARED_RELOAD_HOLD_MS / 1e3)}s; reloading ${key} without waiting for them.`)
|
|
1605
|
+
});
|
|
547
1606
|
idleRestart.supersede(change.superseded);
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
notice(`Reloaded ${mount.scope === "
|
|
551
|
-
|
|
1607
|
+
if (publishSharedMount(mount, root)) hub.touchCompositions?.([mount]);
|
|
1608
|
+
if (explicit) await syncCheckpoint(root, mount.scope === "host" ? "The host scope" : workspaceLabel(root, hub.workspaces().find(({ id }) => id === mount.workspaceId)?.name));
|
|
1609
|
+
notice(`Reloaded ${mount.scope === "host" ? "host" : `workspace '${mount.workspaceId}'`} packages (${String(change.changed.length)} changed, ${String(change.removed.length)} no longer selected${removed.length === 0 ? "" : `, ${String(removed.length)} removed`}${failed.size === 0 ? "" : `, ${String(failed.size)} failed and retry at the next check`}).`);
|
|
1610
|
+
return {
|
|
1611
|
+
installed,
|
|
1612
|
+
removed,
|
|
1613
|
+
failed: scopeFailures(key)
|
|
1614
|
+
};
|
|
1615
|
+
});
|
|
1616
|
+
const settled = run.catch((error) => {
|
|
1617
|
+
notice(`Extension check of ${key} failed and retries at the next check: ${error instanceof Error ? error.message : String(error)}`);
|
|
1618
|
+
});
|
|
552
1619
|
scopeChecks.set(key, settled);
|
|
553
1620
|
settled.then(() => {
|
|
554
1621
|
if (scopeChecks.get(key) === settled) scopeChecks.delete(key);
|
|
555
1622
|
});
|
|
556
|
-
return settled;
|
|
1623
|
+
return explicit ? run : settled;
|
|
557
1624
|
};
|
|
1625
|
+
/** Names the host config's own default selection offers the host scope; its copies need no workspace root. */
|
|
1626
|
+
let hostSelected = /* @__PURE__ */ new Set();
|
|
1627
|
+
const hostNotices = /* @__PURE__ */ new Set();
|
|
1628
|
+
hostOwnersTrigger.bind(() => {
|
|
1629
|
+
const roots = [];
|
|
1630
|
+
for (const name of new Set(hostOffers.flatMap(({ packages }) => [...packages.keys()]))) {
|
|
1631
|
+
if (hostSelected.has(name)) continue;
|
|
1632
|
+
const offering = hostOffers.filter(({ packages }) => packages.has(name));
|
|
1633
|
+
const winner = offering.some(({ packages }) => packages.get(name)?.server === true) ? offering.find(({ workspaceId }) => workspaceId === hostServices.owner(name)) : offering[0];
|
|
1634
|
+
const packageRoot = winner?.packages.get(name)?.packageRoot;
|
|
1635
|
+
if (winner === void 0 || packageRoot === void 0) continue;
|
|
1636
|
+
roots.push(packageRoot);
|
|
1637
|
+
for (const { workspaceId } of offering) {
|
|
1638
|
+
const message = `Host package '${name}' of workspace '${workspaceId}' is skipped: workspace '${winner.workspaceId}' provides it.`;
|
|
1639
|
+
if (workspaceId === winner.workspaceId || hostNotices.has(message)) continue;
|
|
1640
|
+
hostNotices.add(message);
|
|
1641
|
+
notice(message);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
if (JSON.stringify(roots) === JSON.stringify(hostPackageRoots)) return;
|
|
1645
|
+
hostPackageRoots = roots;
|
|
1646
|
+
const mount = { scope: "host" };
|
|
1647
|
+
if (publishSharedMount(mount, globalRoot)) hub.touchCompositions?.([mount]);
|
|
1648
|
+
});
|
|
1649
|
+
let hostCheck = Promise.resolve();
|
|
1650
|
+
hostServicesTrigger.bind(() => {
|
|
1651
|
+
hostCheck = hostCheck.then(async () => {
|
|
1652
|
+
const served = hub.workspaces().filter((workspace) => servedOnHost(workspace) && servedWorkspaces.has(workspace.id)).sort((left, right) => left.id < right.id ? -1 : 1);
|
|
1653
|
+
hostSelected = new Set((await bundler.globalPackages(globalRoot)).map(({ name }) => name));
|
|
1654
|
+
hostOffers = await Promise.all(served.map(async (workspace) => ({
|
|
1655
|
+
workspaceId: workspace.id,
|
|
1656
|
+
packages: new Map((await bundler.globalPackages(workspace.root)).map(({ name, ...offer }) => [name, offer]))
|
|
1657
|
+
})));
|
|
1658
|
+
await hostServices.reconcile();
|
|
1659
|
+
hostOwnersChanged();
|
|
1660
|
+
}).catch((error) => notice(`Host package check failed: ${errorMessage(error)}`));
|
|
1661
|
+
});
|
|
558
1662
|
const loadSessionMcp = async (root, selection) => {
|
|
559
1663
|
return telemetry.runInSpan("po_server.mcp_bundle_load", {}, async () => {
|
|
560
1664
|
const { candidates, entries } = await bundler.mcpEntries(root);
|
|
561
1665
|
let app;
|
|
562
1666
|
try {
|
|
563
|
-
app = readMcpAppBuild({
|
|
1667
|
+
app = await readMcpAppBuild({
|
|
564
1668
|
poHome: globalRoot,
|
|
565
|
-
candidates
|
|
1669
|
+
candidates,
|
|
1670
|
+
files: hostFiles
|
|
566
1671
|
});
|
|
567
1672
|
} catch (error) {
|
|
568
1673
|
notice(`The MCP app build could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
569
1674
|
}
|
|
570
1675
|
if (app !== void 0 && app.build === void 0) {
|
|
571
1676
|
notice(`MCP app build ${app.key} is not synced yet; this session runs without MCP widgets.`);
|
|
572
|
-
syncCheckpoints.requestMissing(`mcp-app:${app.key}`, "the MCP app build is missing");
|
|
1677
|
+
await syncCheckpoints.requestMissing(`mcp-app:${app.key}`, "the MCP app build is missing", ["mcp-app"]);
|
|
573
1678
|
}
|
|
574
1679
|
const built = app?.build;
|
|
575
1680
|
return loadMcpPlugins({
|
|
576
1681
|
entries,
|
|
577
1682
|
...built === void 0 ? {} : { uiResource: mcpUiResource(built.html, built.sha256) },
|
|
578
|
-
|
|
1683
|
+
preset: selection.preset,
|
|
579
1684
|
activeLayers: selection.activeLayers,
|
|
580
1685
|
retainCandidates: true,
|
|
581
1686
|
onNotice: notice,
|
|
@@ -584,9 +1689,61 @@ async function runServerRuntime(options, runtime) {
|
|
|
584
1689
|
});
|
|
585
1690
|
});
|
|
586
1691
|
};
|
|
1692
|
+
const prepareSessionHarness = async (options, workspace, requestSignal, intent = options.profile === void 0 ? { kind: "unspecified" } : {
|
|
1693
|
+
kind: "named",
|
|
1694
|
+
name: options.profile
|
|
1695
|
+
}, selectionInput, requiredProfile) => {
|
|
1696
|
+
const parent = await hub.sessionParentScope(workspace.id);
|
|
1697
|
+
const scope = workspace.kind === "session" ? void 0 : { workspaceId: workspace.id };
|
|
1698
|
+
profileSourceScopes.set(workspace.root, {
|
|
1699
|
+
context: parent.root,
|
|
1700
|
+
...scope
|
|
1701
|
+
});
|
|
1702
|
+
const sources = readProfileSources(parent.root, scope);
|
|
1703
|
+
const files = loadProfileCatalog(options.configRoot ?? options.repoRoot, options.homeDirectory ?? homeDirectory).profiles;
|
|
1704
|
+
let outcome = await resolveInitialProfile(files, sources, {
|
|
1705
|
+
intent,
|
|
1706
|
+
scope,
|
|
1707
|
+
signal: requestSignal,
|
|
1708
|
+
required: requiredProfile
|
|
1709
|
+
});
|
|
1710
|
+
const definition = outcome.resolvedProfile === void 0 ? void 0 : mergeProfiles(files, sources).find(({ name }) => name === outcome.resolvedProfile);
|
|
1711
|
+
if (outcome.resolvedProfile !== void 0 && definition === void 0) {
|
|
1712
|
+
if (outcome.required) throw new ProfileRestoreError("profile-changed");
|
|
1713
|
+
outcome = {
|
|
1714
|
+
...outcome,
|
|
1715
|
+
resolvedProfile: void 0,
|
|
1716
|
+
warning: {
|
|
1717
|
+
code: "missing",
|
|
1718
|
+
requested: outcome.resolvedProfile
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
requestSignal.throwIfAborted();
|
|
1723
|
+
const profileSelection = selectionInput === void 0 ? void 0 : profileSelectionArgs(selectionInput.args, selectionInput.environment ?? baseEnvironment, definition);
|
|
1724
|
+
const selectedOptions = selectionInput === void 0 || profileSelection === void 0 || profileSelection.args.length === 0 ? options : await resolveHarnessOptions({
|
|
1725
|
+
...selectionInput,
|
|
1726
|
+
args: [...selectionInput.args, ...profileSelection.args]
|
|
1727
|
+
});
|
|
1728
|
+
try {
|
|
1729
|
+
const context = await buildHarnessContext(selectedOptions, harnessTelemetry, {
|
|
1730
|
+
outcome,
|
|
1731
|
+
definition
|
|
1732
|
+
});
|
|
1733
|
+
return profileSelection === void 0 || profileSelection.applied.length === 0 ? context : {
|
|
1734
|
+
...context,
|
|
1735
|
+
profileSelectionAxes: profileSelection.applied
|
|
1736
|
+
};
|
|
1737
|
+
} catch (error) {
|
|
1738
|
+
if (profileSelection === void 0 || profileSelection.applied.length === 0) throw asError(error);
|
|
1739
|
+
throw new Error(`Profile '${definition?.name}' selects an unavailable ${profileSelection.applied.join(" and ")}: ${errorMessage(error)}`, { cause: error });
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
587
1742
|
const sharedApiContext = {
|
|
1743
|
+
clientDevices,
|
|
588
1744
|
homeDirectory,
|
|
589
1745
|
environment: baseEnvironment,
|
|
1746
|
+
...distribution === void 0 ? {} : { distribution },
|
|
590
1747
|
hubToken: token,
|
|
591
1748
|
sessionService: hub.sessionService,
|
|
592
1749
|
mediaArbitration,
|
|
@@ -594,32 +1751,41 @@ async function runServerRuntime(options, runtime) {
|
|
|
594
1751
|
peerAgents,
|
|
595
1752
|
directEvents: hub.directEvents,
|
|
596
1753
|
requestApi: (mount, basePath, request) => hub.requestApi(mount, basePath, request),
|
|
597
|
-
repositories: () => hub.workspaces().map((workspace) => ({
|
|
1754
|
+
repositories: () => hub.workspaces().filter((workspace) => workspace.kind !== "session").map((workspace) => ({
|
|
598
1755
|
id: workspace.id,
|
|
599
1756
|
path: workspace.root,
|
|
600
|
-
name: workspace.root.split("/").at(-1) ?? workspace.id,
|
|
1757
|
+
name: workspace.name ?? workspace.root.split("/").at(-1) ?? workspace.id,
|
|
601
1758
|
active: hub.snapshot().some((session) => session.workspaceId === workspace.id)
|
|
602
1759
|
})),
|
|
603
|
-
resolveRepository: (id) => hub.workspaces().find((workspace) => workspace.id === id)?.root,
|
|
1760
|
+
resolveRepository: (id) => hub.workspaces().find((workspace) => workspace.id === id && workspace.sandbox === void 0)?.root,
|
|
1761
|
+
serverOrigin: () => {
|
|
1762
|
+
if (cockpit === void 0) throw new Error("The headless server is not listening yet.");
|
|
1763
|
+
return cockpit.url;
|
|
1764
|
+
},
|
|
604
1765
|
/**
|
|
605
1766
|
* Package readiness and the MCP projection, resolved live from the repository. The
|
|
606
1767
|
* context stays until the next read replaces it: the projection names its staged files.
|
|
607
1768
|
*/
|
|
608
1769
|
readRepositorySync: async (id) => {
|
|
609
|
-
const
|
|
1770
|
+
const workspace = hub.workspaces().find((candidate) => candidate.id === id);
|
|
1771
|
+
if (workspace?.sandbox !== void 0) throw new Error("A sandboxed workspace is prepared inside its sandbox, not on the host.");
|
|
1772
|
+
const root = workspace?.root;
|
|
610
1773
|
if (!root) return void 0;
|
|
611
1774
|
const environment = rootEnvironment(root);
|
|
612
|
-
const config =
|
|
1775
|
+
const config = loadPresetsConfig(root, homeDirectory, environment);
|
|
613
1776
|
const missing = missingLayerPackageSpecifiers(config, Object.keys(config.layers), createLayerResolvers(root, environment));
|
|
614
|
-
const context = await buildHarnessContext(
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
1777
|
+
const context = await buildHarnessContext({
|
|
1778
|
+
...await resolveHarnessOptions({
|
|
1779
|
+
args: ["--cwd", root],
|
|
1780
|
+
cwd: root,
|
|
1781
|
+
environment
|
|
1782
|
+
}),
|
|
1783
|
+
profile: void 0
|
|
1784
|
+
});
|
|
619
1785
|
const previous = repositoryContexts.get(root);
|
|
620
1786
|
repositoryContexts.set(root, context);
|
|
621
1787
|
await previous?.cleanup().catch((error) => notice(String(error)));
|
|
622
|
-
const status = syncCheckpoint(root, workspaceLabel(root, hub.workspaces().find((workspace) => workspace.id === id)?.name), false);
|
|
1788
|
+
const status = await syncCheckpoint(root, workspaceLabel(root, hub.workspaces().find((workspace) => workspace.id === id)?.name), false);
|
|
623
1789
|
return {
|
|
624
1790
|
fresh: missing.length === 0 && status.reasons.length === 0,
|
|
625
1791
|
reasons: [...missing.map((specifier) => `configured package is not installed: ${specifier}`), ...status.reasons],
|
|
@@ -627,133 +1793,490 @@ async function runServerRuntime(options, runtime) {
|
|
|
627
1793
|
mcpProjection: context.resources.mcpProjection
|
|
628
1794
|
};
|
|
629
1795
|
},
|
|
630
|
-
onNotice: notice
|
|
1796
|
+
onNotice: notice,
|
|
1797
|
+
...computerUse?.permissions === void 0 ? {} : { desktopPermissions: {
|
|
1798
|
+
authorize: (headers, change) => computerUse.authorizePermissions?.(headers, change) === true,
|
|
1799
|
+
request: (permission) => computerUse.permissions(permission)
|
|
1800
|
+
} }
|
|
1801
|
+
};
|
|
1802
|
+
/**
|
|
1803
|
+
* A sandboxed workspace's settings, answered on the host while it serves no scope for it, so the person can
|
|
1804
|
+
* still see and change them and switch the sandbox off. Reading and writing its `.po` YAML is data only: the host
|
|
1805
|
+
* never loads its composition, runs git or executes anything from it. Closed once it runs on the host again.
|
|
1806
|
+
*/
|
|
1807
|
+
const sandboxedSettings = /* @__PURE__ */ new Map();
|
|
1808
|
+
const releaseSandboxedSettings = (workspaceId) => {
|
|
1809
|
+
sandboxedSettings.get(workspaceId)?.release();
|
|
1810
|
+
sandboxedSettings.delete(workspaceId);
|
|
631
1811
|
};
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
1812
|
+
unservedWorkspaceApi = (workspaceId, basePath) => {
|
|
1813
|
+
const record = workspaces.list().find((workspace) => workspace.id === workspaceId);
|
|
1814
|
+
const held = sandboxedSettings.get(workspaceId);
|
|
1815
|
+
if (held !== void 0 && (record?.sandbox === void 0 || held.root !== record.root)) releaseSandboxedSettings(workspaceId);
|
|
1816
|
+
if (basePath !== SETTINGS_API || record?.sandbox === void 0) return void 0;
|
|
1817
|
+
const current = sandboxedSettings.get(workspaceId);
|
|
1818
|
+
if (current !== void 0) return current.handler;
|
|
1819
|
+
const env = platform.env(record.root);
|
|
1820
|
+
const handler = createSettingsApi(env).start({
|
|
1821
|
+
...sharedApiContext,
|
|
1822
|
+
scope: "workspace",
|
|
1823
|
+
workspaceId,
|
|
1824
|
+
workspaceRoot: record.root,
|
|
1825
|
+
cwd: record.root,
|
|
1826
|
+
resolveRepository: () => void 0
|
|
1827
|
+
});
|
|
1828
|
+
sandboxedSettings.set(workspaceId, {
|
|
1829
|
+
root: record.root,
|
|
1830
|
+
handler,
|
|
1831
|
+
release: () => {
|
|
1832
|
+
handler.close();
|
|
1833
|
+
env.cleanup(BACKGROUND_CONTEXT).catch((error) => notice(String(error)));
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1836
|
+
return handler;
|
|
1837
|
+
};
|
|
1838
|
+
stopSandboxWatches.push(() => {
|
|
1839
|
+
for (const workspaceId of sandboxedSettings.keys()) releaseSandboxedSettings(workspaceId);
|
|
635
1840
|
});
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
1841
|
+
const hostDirectoryExisted = await pathExists(hostFiles, globalRoot, BACKGROUND_CONTEXT);
|
|
1842
|
+
getOrThrow(await hostFiles.createDir(globalRoot, { recursive: true }, BACKGROUND_CONTEXT));
|
|
1843
|
+
if (!hostDirectoryExisted) await nodeHost.setMode(globalRoot, 448);
|
|
1844
|
+
await refreshRememberedWorkspaceDeclarations(workspaces.list(), refreshWorkspaceDeclarations, notice);
|
|
1845
|
+
const hostBundle = await loadComposition(globalRoot, "host", void 0, "host");
|
|
1846
|
+
hostLocales = await prepareHostLocales();
|
|
1847
|
+
if (sandboxIdentity === void 0) {
|
|
1848
|
+
const lanAddress = incomingEnvironment.PO_PRIVATE_LAN_ADDRESS?.trim();
|
|
1849
|
+
const lanCertFile = incomingEnvironment.PO_PRIVATE_LAN_CERT_FILE?.trim();
|
|
1850
|
+
const lanKeyFile = incomingEnvironment.PO_PRIVATE_LAN_KEY_FILE?.trim();
|
|
1851
|
+
let lanTls;
|
|
1852
|
+
if (lanAddress !== void 0 || lanCertFile !== void 0 || lanKeyFile !== void 0) {
|
|
1853
|
+
if (!lanAddress || !lanCertFile || !lanKeyFile || !path.isAbsolute(lanCertFile) || !path.isAbsolute(lanKeyFile)) throw new Error("Private LAN requires PO_PRIVATE_LAN_ADDRESS and absolute certificate and key file paths.");
|
|
1854
|
+
lanTls = {
|
|
1855
|
+
address: lanAddress,
|
|
1856
|
+
cert: getOrThrow(await hostFiles.readTextFile(lanCertFile, BACKGROUND_CONTEXT)),
|
|
1857
|
+
key: getOrThrow(await hostFiles.readTextFile(lanKeyFile, BACKGROUND_CONTEXT))
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
const relayConfiguration = privateRelayConfiguration(incomingEnvironment);
|
|
1861
|
+
delete baseEnvironment.PO_PRIVATE_RELAY_CAPABILITY;
|
|
1862
|
+
if (relayConfiguration !== void 0 && lanTls !== void 0) throw new Error("Private relay and private LAN cannot both be enabled.");
|
|
1863
|
+
const relayOptions = (configuration, saved, subject) => createPrivateRelayOptions({
|
|
1864
|
+
configuration,
|
|
1865
|
+
...subject === void 0 ? {} : { subject },
|
|
1866
|
+
fetchCloud: async (request, caller) => {
|
|
1867
|
+
if (!remoteRuntime) throw new Error("Remote access is not running.");
|
|
1868
|
+
return remoteRuntime.fetchCloudRelay(request, caller);
|
|
1869
|
+
},
|
|
1870
|
+
enrolled: async () => saved ? {
|
|
1871
|
+
networkId: configuration.org,
|
|
1872
|
+
hostId: configuration.host
|
|
1873
|
+
} : (await remoteRuntime?.networkComposition?.())?.network,
|
|
1874
|
+
attest: (tag, fields) => webCompositions?.attestFederation(tag, fields),
|
|
1875
|
+
fetch: async (request) => {
|
|
1876
|
+
if (!remoteRuntime) throw new Error("Remote access is not running.");
|
|
1877
|
+
return remoteRuntime.fetchPrivateRelay(request);
|
|
1878
|
+
},
|
|
1879
|
+
onNotice: notice
|
|
1880
|
+
});
|
|
1881
|
+
const relayLinkFile = path.join(globalRoot, "private-relay-link.json");
|
|
1882
|
+
const privateRelaySetup = lanTls !== void 0 ? void 0 : await createPrivateRelayLink({
|
|
1883
|
+
fetch,
|
|
1884
|
+
publicKey: () => webCompositions?.publicKey(),
|
|
1885
|
+
sign: (fields) => webCompositions?.attestFederation("po/private-relay-link/v1", fields),
|
|
1886
|
+
carrier: (record) => relayOptions(record, true, record.subject),
|
|
1887
|
+
load: async () => {
|
|
1888
|
+
if (!await pathExists(hostFiles, relayLinkFile, BACKGROUND_CONTEXT)) return void 0;
|
|
1889
|
+
await nodeHost.setMode(relayLinkFile, 384);
|
|
1890
|
+
const text = getOrThrow(await hostFiles.readTextFile(relayLinkFile, BACKGROUND_CONTEXT));
|
|
1891
|
+
return JSON.parse(text);
|
|
1892
|
+
},
|
|
1893
|
+
save: async (record) => {
|
|
1894
|
+
const temp = `${relayLinkFile}.${crypto.randomUUID()}.tmp`;
|
|
1895
|
+
try {
|
|
1896
|
+
getOrThrow(await hostFiles.writeFile(temp, JSON.stringify(record), BACKGROUND_CONTEXT));
|
|
1897
|
+
await nodeHost.setMode(temp, 384);
|
|
1898
|
+
getOrThrow(await hostFiles.renameFile(temp, relayLinkFile, BACKGROUND_CONTEXT));
|
|
1899
|
+
} catch (error) {
|
|
1900
|
+
await hostFiles.remove(temp, { force: true }, BACKGROUND_CONTEXT);
|
|
1901
|
+
throw new Error("The Po Cloud relay link could not be saved.", { cause: error });
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}).catch(() => {
|
|
1905
|
+
notice("The saved Po Cloud relay configuration could not be loaded. Relay setup is unavailable.");
|
|
1906
|
+
});
|
|
1907
|
+
relayLinkBinding = privateRelaySetup?.binding;
|
|
1908
|
+
remoteRuntime = createRemoteRuntime({
|
|
1909
|
+
onLiveActivityEnrolled: () => liveActivityPush?.enrolled(),
|
|
1910
|
+
liveActivityReaches: (deviceId, sessionId) => hub.session(sessionId) !== void 0 && teamHost.pushReaches(deviceId, sessionId),
|
|
1911
|
+
homeDirectory,
|
|
1912
|
+
environment: baseEnvironment,
|
|
1913
|
+
...lanTls === void 0 ? {} : { lanTls },
|
|
1914
|
+
...relayConfiguration === void 0 ? {} : { privateRelay: relayOptions(relayConfiguration, false) },
|
|
1915
|
+
...privateRelaySetup === void 0 ? {} : { privateRelaySetup },
|
|
1916
|
+
audit: teamHost.audit,
|
|
1917
|
+
pairingAccount: teamHost.pairingAccount,
|
|
1918
|
+
publicAuth: {
|
|
1919
|
+
issuer: teamHost.issuer,
|
|
1920
|
+
fetch: async (request) => {
|
|
1921
|
+
const auth = hub.publicApi(new URL(request.url).pathname.split("/")[2] ?? "");
|
|
1922
|
+
return auth ? auth.handler.fetch(request) : Response.json({ error: "The sign-in server is unavailable." }, { status: 503 });
|
|
1923
|
+
}
|
|
1924
|
+
},
|
|
1925
|
+
registrationToken: token,
|
|
1926
|
+
onStateChanged: () => hub.bumpRevision?.("host:remote"),
|
|
1927
|
+
onTunnelIntentChanged: (intent) => {
|
|
1928
|
+
recoveryTunnel = intent;
|
|
1929
|
+
persistRecovery();
|
|
1930
|
+
},
|
|
1931
|
+
onRelayIntentChanged: (on) => {
|
|
1932
|
+
const link = on ? relayLinkBinding?.() : void 0;
|
|
1933
|
+
relayWrites = relayWrites.then(() => keepRelayIntent(serverDirectory, link)).catch((error) => notice(`Could not save the Po Cloud relay state: ${String(error)}`));
|
|
1934
|
+
},
|
|
1935
|
+
onDeviceDropped: (id) => computerUse?.revokeDevice?.(id),
|
|
1936
|
+
reservedPorts: () => [options.webPort],
|
|
1937
|
+
federationPlatform: {
|
|
1938
|
+
...cliFederationPlatform({
|
|
1939
|
+
sqlite: platform.sqlite,
|
|
1940
|
+
sessionOperation: (sessionId, basePath, method, path) => sessionArtifacts.get(sessionId)?.apis.operation?.(basePath, method, path),
|
|
1941
|
+
emitPaused: (event) => {
|
|
1942
|
+
hub.sessionParentScope(void 0).then((scope) => scope.broadcast("po/federation/work-paused", event));
|
|
1943
|
+
},
|
|
1944
|
+
capabilityRevision: () => `${capabilityRevision}:${hub.workspaces().map((workspace) => workspace.id).sort().join(",")}`,
|
|
1945
|
+
capabilities: async () => {
|
|
1946
|
+
const workspaces = hub.workspaces().filter((workspace) => workspace.sandbox === void 0);
|
|
1947
|
+
const templateIds = [{
|
|
1948
|
+
cwd: globalRoot,
|
|
1949
|
+
workspaces: []
|
|
1950
|
+
}, ...workspaces.map((workspace) => ({
|
|
1951
|
+
cwd: workspace.root,
|
|
1952
|
+
launchWorkspaceId: workspace.id,
|
|
1953
|
+
workspaces: [workspace]
|
|
1954
|
+
}))].flatMap((decision) => ["web", "native"].flatMap((host) => {
|
|
1955
|
+
const id = resolveWebTemplateDecision({
|
|
1956
|
+
...decision,
|
|
1957
|
+
host,
|
|
1958
|
+
homeDirectory,
|
|
1959
|
+
environment: baseEnvironment,
|
|
1960
|
+
notice
|
|
1961
|
+
}).id;
|
|
1962
|
+
return id ? [id] : [];
|
|
1963
|
+
}));
|
|
1964
|
+
return collectNodeCapabilities([globalRoot, ...workspaces.sort((a, b) => a.id.localeCompare(b.id)).map((workspace) => workspace.root)].map((root) => ({
|
|
1965
|
+
root,
|
|
1966
|
+
compositions: bundler.compositions(root)
|
|
1967
|
+
})), hostFiles, notice, templateIds, await globalWebPluginRoots(globalRoot, homeDirectory, baseEnvironment, notice));
|
|
1968
|
+
},
|
|
1969
|
+
fetch,
|
|
1970
|
+
hub,
|
|
1971
|
+
onNotice: notice,
|
|
1972
|
+
publicOrigin: () => remoteRuntime?.remote.publicOrigin(),
|
|
1973
|
+
forwardNetwork: async (request) => {
|
|
1974
|
+
if (!cockpit || !attachToken) throw new Error("Hub unavailable");
|
|
1975
|
+
const from = new URL(request.url);
|
|
1976
|
+
const headers = new Headers(request.headers);
|
|
1977
|
+
headers.set("x-po-token", attachToken);
|
|
1978
|
+
await fetch(new URL(from.pathname + from.search, cockpit.url), new Request(request, {
|
|
1979
|
+
headers,
|
|
1980
|
+
redirect: "manual"
|
|
1981
|
+
}));
|
|
1982
|
+
},
|
|
1983
|
+
publicKey: () => webCompositions?.publicKey(),
|
|
1984
|
+
attest: (tag, fields) => webCompositions?.attestFederation(tag, fields)
|
|
1985
|
+
}),
|
|
1986
|
+
team: teamHost.team,
|
|
1987
|
+
memberSettings: teamHost.memberSettings,
|
|
1988
|
+
settingsGranted: () => void refreshGlobalSettings()
|
|
1989
|
+
},
|
|
1990
|
+
bundleTrust: () => webCompositions?.shellTrust(),
|
|
1991
|
+
attestHost: (fields) => webCompositions?.attestHost(fields),
|
|
1992
|
+
onNotice: notice,
|
|
1993
|
+
telemetry,
|
|
1994
|
+
forward: async (request) => {
|
|
1995
|
+
if (!cockpit || !attachToken) return Response.json({ error: "The headless server is not ready." }, { status: 503 });
|
|
1996
|
+
const from = new URL(request.url);
|
|
1997
|
+
const headers = new Headers(request.headers);
|
|
1998
|
+
headers.set("x-po-token", attachToken);
|
|
1999
|
+
return fetch(new URL(`${from.pathname}${from.search}`, cockpit.url), new Request(request, {
|
|
2000
|
+
headers,
|
|
2001
|
+
redirect: "manual"
|
|
2002
|
+
}));
|
|
2003
|
+
},
|
|
2004
|
+
acceptProtocol: remoteProtocolAcceptor(() => cockpit),
|
|
2005
|
+
acceptCloudChat: cloudChatAcceptor(() => cockpit)
|
|
2006
|
+
});
|
|
2007
|
+
const pushCredentials = await loadNativePushCredentials(baseEnvironment, platform.env(baseCwd), notice);
|
|
2008
|
+
const pushSender = createNativePushSender({
|
|
2009
|
+
...pushCredentials,
|
|
2010
|
+
diagnostic: ({ provider, outcome, status, reason }) => notice(`Native push ${provider}: ${outcome}${status === void 0 ? "" : ` ${status}`}${reason ? ` ${reason}` : ""}.`)
|
|
2011
|
+
});
|
|
2012
|
+
liveActivityPush = subscribeLiveActivityPush(hub, remoteRuntime.remote, pushSender, notice, teamHost.pushReaches);
|
|
2013
|
+
stopNativePush = subscribeNativePush(hub, remoteRuntime.remote, pushSender, notice, teamHost.pushReaches, async () => (await hub.sessionParentScope(void 0)).resolve(PO_LANG_CONTRACT));
|
|
2014
|
+
}
|
|
2015
|
+
try {
|
|
2016
|
+
const hostScope = await hub.sessionParentScope(void 0);
|
|
2017
|
+
await hostScope.bind(PO_COMPOSITION_LOCALES_CONTRACT, () => hostLocales);
|
|
2018
|
+
if (automation === void 0) await hostScope.bind(PO_WORKSPACE_SANDBOXES_CONTRACT, sandboxes);
|
|
2019
|
+
await hostScope.bind(PO_WORKSPACE_REGISTRY_CONTRACT, workspaceInventory);
|
|
2020
|
+
await hostScope.bind(PO_HOST_SERVICES_CONTRACT, hostServices);
|
|
2021
|
+
await hostScope.bind(PO_HOST_TEAM_CONTRACT, teamHost.service);
|
|
2022
|
+
if (sandboxIdentity !== void 0) await hostScope.bind(PO_SANDBOX_IDENTITY_CONTRACT, sandboxIdentity);
|
|
2023
|
+
await hostScope.bind(PO_PACKAGE_HEALTH_CONTRACT, { failures: () => [...packageFailures.values()] });
|
|
2024
|
+
await hostScope.bind(PO_SELF_IMPROVE_CONTRACT, {
|
|
2025
|
+
reload: async ({ scope, sessionId }) => {
|
|
2026
|
+
await requestMissingWebBuild().catch((error) => notice(`Web build check failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
2027
|
+
if (scope === "session") {
|
|
2028
|
+
if (reloadSessionPackages === void 0) throw new Error("Session reload is not ready yet.");
|
|
2029
|
+
const result = await reloadSessionPackages(sessionId);
|
|
2030
|
+
return {
|
|
2031
|
+
...result,
|
|
2032
|
+
failed: result.failed.map(({ packageName, reason }) => ({
|
|
2033
|
+
packageName,
|
|
2034
|
+
reason
|
|
2035
|
+
}))
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
const workspaceId = hub.session(sessionId)?.workspaceId;
|
|
2039
|
+
const workspace = workspaceId === void 0 ? void 0 : hub.workspaces().find(({ id }) => id === workspaceId);
|
|
2040
|
+
if (scope === "workspace" && (workspace === void 0 || !servedOnHost(workspace))) throw new Error(`Session '${sessionId}' has no workspace served on this host.`);
|
|
2041
|
+
return await checkScope(scope === "host" ? globalRoot : workspace.root, scope === "host" ? { scope: "host" } : {
|
|
2042
|
+
scope: "workspace",
|
|
2043
|
+
workspaceId: workspace.id
|
|
2044
|
+
}, true) ?? {
|
|
2045
|
+
installed: [],
|
|
2046
|
+
removed: [],
|
|
2047
|
+
failed: []
|
|
2048
|
+
};
|
|
2049
|
+
},
|
|
2050
|
+
refresh: async ({ sessionId, axes }) => {
|
|
2051
|
+
if (refreshSessionSelection === void 0) throw new Error("Session refresh is not ready yet.");
|
|
2052
|
+
await refreshSessionSelection(sessionId, axes);
|
|
2053
|
+
}
|
|
2054
|
+
});
|
|
2055
|
+
if (remoteRuntime?.federationClient) {
|
|
2056
|
+
await hostScope.bind(defineServiceContract(PO_FEDERATION_CLIENT_SERVICE, { scope: "host" }), remoteRuntime.federationClient);
|
|
2057
|
+
const federationClient = remoteRuntime.federationClient;
|
|
2058
|
+
hostScope.root.inject([PO_SPACE_SERVICE], (bound) => readPoSpace(bound)?.setOwner(() => federationClient.owner?.()));
|
|
2059
|
+
hostScope.root.inject([PERSON_PROFILE_SERVICE], (bound) => requirePersonProfile(bound).setOwner(() => federationClient.owner?.()));
|
|
662
2060
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
2061
|
+
if (remoteRuntime?.calendarHostPair) await hostScope.bind(defineServiceContract(PO_CALENDAR_HOST_PAIR_SERVICE, { scope: "host" }), remoteRuntime.calendarHostPair);
|
|
2062
|
+
if (sandboxIdentity === void 0) await hostScope.bind(PO_REMOTE_GATEWAY_CONTRACT, { fetch: (request) => remoteRuntime.fetchLocal(request) });
|
|
2063
|
+
await hostScope.bind(PO_REMOTE_ORIGIN_CONTRACT, remoteOrigin);
|
|
2064
|
+
await hostScope.bind(PO_SHARED_MODELS_CONTRACT, sharedModels);
|
|
2065
|
+
await hostScope.bind(PO_HOST_REQUESTS_CONTRACT, {
|
|
2066
|
+
machineName: hostDisplayName(os.hostname()) ?? "This computer",
|
|
2067
|
+
hosts: () => cachedHostRequests?.hosts() ?? [],
|
|
2068
|
+
fetch: async (hostId, request) => (await remoteRuntime?.hostRequests?.())?.fetch(hostId, request),
|
|
2069
|
+
verify: async (request, prefix) => (await remoteRuntime?.hostRequests?.())?.verify(request, prefix)
|
|
2070
|
+
});
|
|
2071
|
+
cachedHostRequests = await remoteRuntime?.hostRequests?.();
|
|
2072
|
+
await hostScope.bind(PO_ROSTER_PEER_CONTRACT, {
|
|
2073
|
+
async connect(hostId, token, exchange) {
|
|
2074
|
+
const peer = await remoteRuntime?.networkPeer?.();
|
|
2075
|
+
if (!peer) throw new Error("Account network unavailable");
|
|
2076
|
+
return peer.connect(hostId, token, exchange);
|
|
2077
|
+
},
|
|
2078
|
+
async accept(proof, token) {
|
|
2079
|
+
const peer = await remoteRuntime?.networkPeer?.();
|
|
2080
|
+
if (!peer) throw new Error("Account network unavailable");
|
|
2081
|
+
return peer.accept(proof, token);
|
|
2082
|
+
}
|
|
2083
|
+
});
|
|
2084
|
+
await hostScope.bind(PO_VAULT_ACCOUNT_CONTRACT, createAccountVault(async (operation, input) => remoteRuntime?.accountCall?.(operation, input), () => remoteRuntime?.federationClient?.owner?.() !== void 0));
|
|
2085
|
+
refreshGlobalSettings();
|
|
2086
|
+
failedPackages.delete("host");
|
|
2087
|
+
await hub.serveScope({
|
|
2088
|
+
...sharedApiContext,
|
|
2089
|
+
scope: "host",
|
|
2090
|
+
clientPlugins: clientInventoryFor({ scope: "host" }),
|
|
2091
|
+
requestReceipts: requestReceipts.receipts
|
|
2092
|
+
}, hostBundle.packages);
|
|
2093
|
+
reconcileOrgPlugins = async (packages) => {
|
|
2094
|
+
await scopeReload.pickUpSync("upm");
|
|
2095
|
+
for (const { root, key, label } of [{
|
|
2096
|
+
root: globalRoot,
|
|
2097
|
+
key: "host",
|
|
2098
|
+
label: "The host scope"
|
|
2099
|
+
}, ...hub.workspaces().filter(servedOnHost).map((workspace) => ({
|
|
2100
|
+
root: workspace.root,
|
|
2101
|
+
key: scopeKey({
|
|
2102
|
+
scope: "workspace",
|
|
2103
|
+
workspaceId: workspace.id
|
|
2104
|
+
}),
|
|
2105
|
+
label: workspaceLabel(workspace.root, workspace.name)
|
|
2106
|
+
}))]) {
|
|
2107
|
+
await syncCheckpoint(root, label);
|
|
2108
|
+
const failed = scopeFailures(key).filter(({ packageName }) => packages.includes(packageName));
|
|
2109
|
+
if (failed.length) throw new Error(`Composition reconciliation failed: ${failed.map(({ packageName, reason }) => `${packageName}: ${reason}`).join("; ")}`);
|
|
2110
|
+
}
|
|
2111
|
+
};
|
|
2112
|
+
requirePoServerHost(hostScope.root).registerApi({
|
|
2113
|
+
basePath: "marketplace",
|
|
2114
|
+
start: () => createPluginMarketplace({
|
|
2115
|
+
fs: hostFiles,
|
|
2116
|
+
homeDirectory,
|
|
2117
|
+
environment: baseEnvironment,
|
|
2118
|
+
globalRoot,
|
|
2119
|
+
signal,
|
|
2120
|
+
orgLibrary,
|
|
2121
|
+
workspaces: () => hub.workspaces().filter(servedOnHost),
|
|
2122
|
+
commit: async (input, definition) => {
|
|
2123
|
+
const repositories = sharedApiContext.repositories();
|
|
2124
|
+
const root = input.scope === "host" ? void 0 : hub.workspaces().filter(servedOnHost).find(({ id }) => input.scope === `workspace:${id}`)?.root;
|
|
2125
|
+
if (input.scope !== "host" && root === void 0) return Response.json({ error: "Workspace is not served on this host." }, { status: 404 });
|
|
2126
|
+
const result = await writePreset(hostFiles, homeDirectory, baseEnvironment, "add-layer", {
|
|
2127
|
+
...input,
|
|
2128
|
+
scope: input.scope === "host" ? "host" : `workspace:${input.scope.slice(10)}`,
|
|
2129
|
+
definition
|
|
2130
|
+
}, root, repositories);
|
|
2131
|
+
if ("error" in result) return result.conflict ? Response.json({
|
|
2132
|
+
error: result.error,
|
|
2133
|
+
hash: result.conflict.hash
|
|
2134
|
+
}, { status: 409 }) : Response.json(result, { status: 422 });
|
|
2135
|
+
return Response.json(result);
|
|
2136
|
+
},
|
|
2137
|
+
reconcile: reconcileOrgPlugins
|
|
2138
|
+
})
|
|
2139
|
+
});
|
|
2140
|
+
} finally {
|
|
2141
|
+
sandboxes.close((provider) => {
|
|
2142
|
+
if (provider.onStatusChange !== void 0) stopSandboxWatches.push(provider.onStatusChange(refreshWorkspaces));
|
|
2143
|
+
refreshWorkspaces();
|
|
2144
|
+
});
|
|
2145
|
+
sandboxProvidersSettled = true;
|
|
2146
|
+
}
|
|
2147
|
+
for (const provider of sandboxes.list()) if (provider.onStatusChange !== void 0) stopSandboxWatches.push(provider.onStatusChange(refreshWorkspaces));
|
|
2148
|
+
bundler.commitScope("host", globalRoot, "host", hostBundle.entries, takeFailedPackages("host", hostBundle.packages));
|
|
2149
|
+
await refreshWebBuild();
|
|
2150
|
+
await syncCheckpoint(globalRoot, "The host scope");
|
|
2151
|
+
orgLibrary?.start(signal, notice);
|
|
2152
|
+
if (!backgroundSync.syncing) await backgroundSync.request("server start");
|
|
674
2153
|
const admissions = /* @__PURE__ */ new Map();
|
|
675
|
-
const isMemberCheckout = (from, workspace) =>
|
|
676
|
-
admitWorkspace = async (from,
|
|
677
|
-
const
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
2154
|
+
const isMemberCheckout = async (from, workspace) => await resolveWorkspaceRoot(from) !== workspace.root;
|
|
2155
|
+
admitWorkspace = async (from, requested = {}) => {
|
|
2156
|
+
const requestedName = requested.name;
|
|
2157
|
+
const directory = await hostFiles.fileInfo(from, BACKGROUND_CONTEXT);
|
|
2158
|
+
if (!directory.ok || directory.value.kind !== "directory") throw new Error(`Folder not found: ${from}`);
|
|
2159
|
+
const checkoutRoot = await resolveWorkspaceRoot(from);
|
|
2160
|
+
const admitSandboxed = (sandboxed) => {
|
|
2161
|
+
const name = requestedName?.trim() || sandboxed.name;
|
|
2162
|
+
const record = {
|
|
2163
|
+
...sandboxed,
|
|
2164
|
+
name,
|
|
2165
|
+
...requested.instructions === void 0 ? {} : { instructions: requested.instructions }
|
|
2166
|
+
};
|
|
2167
|
+
if (name !== sandboxed.name || requested.instructions !== void 0) workspaces.add(record);
|
|
2168
|
+
const available = router?.connected(record.id) === true;
|
|
2169
|
+
const entry = {
|
|
2170
|
+
...hubEntry(record, available),
|
|
2171
|
+
available
|
|
2172
|
+
};
|
|
2173
|
+
const known = hub.workspaces().find((workspace) => workspace.id === record.id);
|
|
2174
|
+
if (known === void 0 || known.available !== false !== available || known.name !== entry.name || known.sandbox !== entry.sandbox || known.instructions !== entry.instructions || !sameSandboxStatus(known, entry)) {
|
|
2175
|
+
if (known === void 0) notice(`Workspace '${record.id}' runs in sandbox '${String(record.sandbox)}'.`);
|
|
2176
|
+
hub.registerWorkspace(entry);
|
|
2177
|
+
}
|
|
2178
|
+
return entry;
|
|
2179
|
+
};
|
|
2180
|
+
const sandboxedHere = workspaces.list().find((workspace) => workspace.sandbox !== void 0 && workspace.root === checkoutRoot && (requested.workspaceId === void 0 || workspace.id === requested.workspaceId));
|
|
2181
|
+
if (sandboxedHere !== void 0) {
|
|
2182
|
+
if (requested.declaration !== void 0 && requested.workspaceId === void 0) throw new Error("Declared workspaces cannot use a sandboxed folder.");
|
|
2183
|
+
return admitSandboxed(sandboxedHere);
|
|
2184
|
+
}
|
|
2185
|
+
const resolved = await resolveWorkspaceAdmission(workspaces.list(), checkoutRoot, requested, {
|
|
2186
|
+
files: hostFiles,
|
|
2187
|
+
environment: baseEnvironment,
|
|
2188
|
+
homeDirectory
|
|
682
2189
|
});
|
|
2190
|
+
const { id, root, name } = resolved.record;
|
|
2191
|
+
const { moved } = resolved;
|
|
683
2192
|
const record = workspaces.list().find((workspace) => workspace.id === id);
|
|
684
|
-
|
|
685
|
-
const named =
|
|
2193
|
+
if (record?.sandbox !== void 0) return admitSandboxed(record);
|
|
2194
|
+
const named = resolved.record;
|
|
686
2195
|
const renamed = record !== void 0 && name !== record.name;
|
|
687
2196
|
const existing = hub.workspaces().find((workspace) => workspace.id === id);
|
|
688
2197
|
if (existing !== void 0 && existing.available !== false && existing.root === root) {
|
|
689
|
-
syncCheckpoint(root, workspaceLabel(root, name));
|
|
690
|
-
if (renamed) {
|
|
2198
|
+
await syncCheckpoint(root, workspaceLabel(root, name));
|
|
2199
|
+
if (renamed || requested.instructions !== void 0) {
|
|
691
2200
|
workspaces.add({
|
|
2201
|
+
...named,
|
|
692
2202
|
id,
|
|
693
|
-
root
|
|
694
|
-
...named
|
|
2203
|
+
root
|
|
695
2204
|
});
|
|
696
|
-
hub.registerWorkspace({
|
|
697
|
-
...existing,
|
|
2205
|
+
hub.registerWorkspace(hubEntry({
|
|
698
2206
|
...named,
|
|
699
|
-
|
|
700
|
-
|
|
2207
|
+
id,
|
|
2208
|
+
root
|
|
2209
|
+
}, true));
|
|
701
2210
|
}
|
|
702
2211
|
return {
|
|
703
|
-
...
|
|
704
|
-
|
|
2212
|
+
...hubEntry({
|
|
2213
|
+
...named,
|
|
2214
|
+
id,
|
|
2215
|
+
root
|
|
2216
|
+
}, true),
|
|
705
2217
|
available: true
|
|
706
2218
|
};
|
|
707
2219
|
}
|
|
708
2220
|
const pending = admissions.get(id);
|
|
709
2221
|
if (pending) return pending;
|
|
710
2222
|
const wasRemembered = record !== void 0;
|
|
711
|
-
|
|
2223
|
+
for (const sibling of resolved.siblings) {
|
|
2224
|
+
workspaces.add(sibling);
|
|
2225
|
+
hub.registerWorkspace(hubEntry(sibling, false));
|
|
2226
|
+
}
|
|
2227
|
+
if (!wasRemembered || moved || renamed || requested.instructions !== void 0) workspaces.add({
|
|
2228
|
+
...named,
|
|
712
2229
|
id,
|
|
713
|
-
root
|
|
714
|
-
...named
|
|
2230
|
+
root
|
|
715
2231
|
});
|
|
716
2232
|
if (moved) notice(`Workspace '${id}' moved to '${root}'.`);
|
|
717
|
-
hub.registerWorkspace({
|
|
718
|
-
id,
|
|
719
|
-
root,
|
|
2233
|
+
hub.registerWorkspace(hubEntry({
|
|
720
2234
|
...named,
|
|
721
|
-
|
|
722
|
-
|
|
2235
|
+
id,
|
|
2236
|
+
root
|
|
2237
|
+
}, false));
|
|
723
2238
|
const admission = (async () => {
|
|
724
|
-
const bundle = await loadComposition(root, "workspace");
|
|
2239
|
+
const bundle = await loadComposition(root, "workspace", void 0, `workspace:${id}`);
|
|
2240
|
+
failedPackages.delete(`workspace:${id}`);
|
|
725
2241
|
await hub.serveScope({
|
|
726
2242
|
...sharedApiContext,
|
|
727
2243
|
scope: "workspace",
|
|
728
2244
|
workspaceId: id,
|
|
2245
|
+
clientPlugins: clientInventoryFor({
|
|
2246
|
+
scope: "workspace",
|
|
2247
|
+
workspaceId: id
|
|
2248
|
+
}),
|
|
729
2249
|
workspaceRoot: root,
|
|
730
2250
|
cwd: root,
|
|
731
2251
|
resolveRepository: (requestedId) => requestedId === id ? root : void 0
|
|
732
2252
|
}, bundle.packages);
|
|
733
|
-
|
|
2253
|
+
servedWorkspaces.add(id);
|
|
2254
|
+
hostServicesChanged();
|
|
2255
|
+
failedAdmissions.delete(id);
|
|
2256
|
+
bundler.commitScope(`workspace:${id}`, root, "workspace", bundle.entries, takeFailedPackages(`workspace:${id}`, bundle.packages));
|
|
734
2257
|
try {
|
|
735
|
-
refreshWebBuild();
|
|
736
|
-
|
|
737
|
-
scope: "workspace",
|
|
738
|
-
workspaceId: id
|
|
739
|
-
}, root);
|
|
740
|
-
publishNativeMount({
|
|
2258
|
+
await refreshWebBuild();
|
|
2259
|
+
const mount = {
|
|
741
2260
|
scope: "workspace",
|
|
742
2261
|
workspaceId: id
|
|
743
|
-
}
|
|
2262
|
+
};
|
|
2263
|
+
if (publishSharedMount(mount, root)) hub.touchCompositions?.([mount]);
|
|
744
2264
|
} catch (error) {
|
|
745
2265
|
notice(`Workspace '${id}' web build check failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
746
2266
|
}
|
|
747
|
-
syncCheckpoint(root, workspaceLabel(root, name));
|
|
2267
|
+
await syncCheckpoint(root, workspaceLabel(root, name));
|
|
2268
|
+
refreshWorkspace(id);
|
|
748
2269
|
try {
|
|
749
|
-
if (readWorkspaceMarker(root) === void 0) writeWorkspaceMarker(root, id);
|
|
2270
|
+
if (named.kind !== "session" && readWorkspaceMarker(root) === void 0) writeWorkspaceMarker(root, named.repositoryId ?? id);
|
|
750
2271
|
} catch (error) {
|
|
751
2272
|
notice(`Workspace '${root}' id could not be recorded in its git data: ${error instanceof Error ? error.message : String(error)}`);
|
|
752
2273
|
}
|
|
753
2274
|
return {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
2275
|
+
...hubEntry({
|
|
2276
|
+
...named,
|
|
2277
|
+
id,
|
|
2278
|
+
root
|
|
2279
|
+
}, true),
|
|
757
2280
|
available: true
|
|
758
2281
|
};
|
|
759
2282
|
})();
|
|
@@ -764,8 +2287,8 @@ async function runServerRuntime(options, runtime) {
|
|
|
764
2287
|
if (!wasRemembered) {
|
|
765
2288
|
await hub.removeWorkspace(id);
|
|
766
2289
|
workspaces.remove(id);
|
|
767
|
-
}
|
|
768
|
-
throw error;
|
|
2290
|
+
} else if (!servedWorkspaces.has(id)) failedAdmissions.set(id, root);
|
|
2291
|
+
throw asError(error);
|
|
769
2292
|
} finally {
|
|
770
2293
|
admissions.delete(id);
|
|
771
2294
|
}
|
|
@@ -774,7 +2297,7 @@ async function runServerRuntime(options, runtime) {
|
|
|
774
2297
|
if (workspaces.list().some((workspace) => workspace.id === record.workspaceId)) continue;
|
|
775
2298
|
try {
|
|
776
2299
|
const candidate = record.groupingRoot ?? record.cwd;
|
|
777
|
-
const root =
|
|
2300
|
+
const root = await resolveWorkspaceRoot(candidate);
|
|
778
2301
|
if ((record.groupingRoot === void 0 || root === candidate) && !workspaces.list().some((workspace) => workspace.root === root)) workspaces.add({
|
|
779
2302
|
id: record.workspaceId,
|
|
780
2303
|
root
|
|
@@ -785,45 +2308,44 @@ async function runServerRuntime(options, runtime) {
|
|
|
785
2308
|
}
|
|
786
2309
|
}
|
|
787
2310
|
for (const workspace of workspaces.list()) {
|
|
788
|
-
hub.registerWorkspace(
|
|
789
|
-
...workspace,
|
|
790
|
-
available: false
|
|
791
|
-
});
|
|
2311
|
+
hub.registerWorkspace(hubEntry(workspace, false));
|
|
792
2312
|
try {
|
|
793
|
-
if (
|
|
2313
|
+
if ((workspace.sandbox === void 0 ? await resolveWorkspaceRoot(workspace.root) : workspace.root) !== workspace.root) {
|
|
794
2314
|
notice(`Workspace '${workspace.root}' no longer resolves to its recorded identity; leaving it unavailable.`);
|
|
795
2315
|
continue;
|
|
796
2316
|
}
|
|
797
|
-
await admitWorkspace(workspace.root
|
|
2317
|
+
await admitWorkspace(workspace.root, {
|
|
2318
|
+
declaration: workspace.declaration,
|
|
2319
|
+
workspaceId: workspace.id
|
|
2320
|
+
});
|
|
798
2321
|
} catch (error) {
|
|
799
2322
|
notice(`Workspace '${workspace.root}' could not be restored: ${error instanceof Error ? error.message : String(error)}`);
|
|
800
2323
|
}
|
|
801
2324
|
}
|
|
802
|
-
const
|
|
803
|
-
const sessionHookModules = (context, sourceRoot) => {
|
|
804
|
-
let descriptor = sessionDescriptors.get(context);
|
|
805
|
-
if (descriptor === void 0) {
|
|
806
|
-
descriptor = context.options.hooks ? liveHookModules(sourceRoot).then((admitted) => checkoutHookDescriptor(admitted, sourceRoot, context.options.repoRoot, context.resources.temporaryDirectory)) : Promise.resolve(void 0);
|
|
807
|
-
sessionDescriptors.set(context, descriptor);
|
|
808
|
-
}
|
|
809
|
-
return descriptor;
|
|
810
|
-
};
|
|
811
|
-
const sessionHostOptions = (context, bundle, mcpBundle, identity, workspace, explicit = { pinned: [] }) => {
|
|
2325
|
+
const sessionHostOptions = async (context, bundle, mcpBundle, identity, workspace, explicit = { pinned: [] }) => {
|
|
812
2326
|
const policyOptions = context.options;
|
|
2327
|
+
const artifactDirectory = (explicit.resume === true || identity.sessionId === resolved.identity.sessionId) && (await platform.sessions.list(BACKGROUND_CONTEXT)).some((entry) => entry.sessionId === identity.sessionId) ? (await readSessionFileDirectories(platform.sessions, identity.sessionId))?.artifactDirectory : explicit.resume === true ? void 0 : await resolveWorkspaceArtifactDirectory({
|
|
2328
|
+
fs: hostFiles,
|
|
2329
|
+
workspaceRoot: workspace.root,
|
|
2330
|
+
checkoutRoot: policyOptions.repoRoot,
|
|
2331
|
+
sessionId: identity.sessionId,
|
|
2332
|
+
environment: context.environment,
|
|
2333
|
+
homeDirectory
|
|
2334
|
+
});
|
|
813
2335
|
const sessionSelection = {
|
|
814
2336
|
root: policyOptions.repoRoot,
|
|
815
|
-
|
|
2337
|
+
preset: policyOptions.preset,
|
|
816
2338
|
activeLayers: context.selectedLayers,
|
|
817
2339
|
domains: policyOptions.domains,
|
|
818
2340
|
profile: context.profile,
|
|
819
|
-
state: {
|
|
2341
|
+
state: { mode: [...explicit.modes ?? policyOptions.modes ?? []] }
|
|
820
2342
|
};
|
|
821
2343
|
const sessionEnvironment = context.environment;
|
|
822
2344
|
updateHarnessState({ compositionFingerprint: resolveExtensionComposition({
|
|
823
|
-
|
|
2345
|
+
preset: policyOptions.preset,
|
|
824
2346
|
layers: [...context.selectedLayers],
|
|
825
|
-
|
|
826
|
-
resolvers: createLayerResolvers(policyOptions.repoRoot, sessionEnvironment),
|
|
2347
|
+
presetsConfig: loadPresetsConfig(policyOptions.configRoot ?? policyOptions.repoRoot, homeDirectory, sessionEnvironment),
|
|
2348
|
+
resolvers: createLayerResolvers(policyOptions.configRoot ?? policyOptions.repoRoot, sessionEnvironment),
|
|
827
2349
|
tolerateUnsynced: true
|
|
828
2350
|
}).fingerprint }, sessionEnvironment);
|
|
829
2351
|
return {
|
|
@@ -839,69 +2361,97 @@ async function runServerRuntime(options, runtime) {
|
|
|
839
2361
|
...explicit.resume ? { resume: true } : {},
|
|
840
2362
|
...identity.parentSessionId === void 0 ? {} : { parentSessionId: identity.parentSessionId },
|
|
841
2363
|
...identity.sessionProvenance === void 0 ? {} : { sessionProvenance: identity.sessionProvenance },
|
|
842
|
-
|
|
843
|
-
|
|
2364
|
+
...identity.interaction === void 0 ? {} : { interaction: identity.interaction },
|
|
2365
|
+
...identity.startedBy === void 0 ? {} : { startedBy: identity.startedBy },
|
|
2366
|
+
agentArgs: workspaceSessionAgentArgs(policyOptions.piArgs, workspaces.list().find((record) => record.id === workspace.id), identity.parentSessionId),
|
|
2367
|
+
environment: Object.freeze({
|
|
2368
|
+
...context.environment,
|
|
2369
|
+
[PO_SESSION_ARTIFACT_DIR]: artifactDirectory
|
|
2370
|
+
}),
|
|
2371
|
+
...artifactDirectory === void 0 ? {} : { artifactDirectory },
|
|
844
2372
|
selection: sessionSelection,
|
|
2373
|
+
...context.initialProfileOutcome?.intent.kind === "named" ? { requestedProfile: context.initialProfileOutcome.intent.name } : context.initialProfileOutcome?.intent.kind === "none" ? { requestedProfile: null } : {},
|
|
845
2374
|
...explicit.allowedTools === void 0 ? {} : { allowedTools: explicit.allowedTools },
|
|
846
2375
|
selectionOverrides: [
|
|
847
|
-
"
|
|
2376
|
+
"preset",
|
|
848
2377
|
"domains",
|
|
849
2378
|
"profile"
|
|
850
2379
|
].filter((axis) => {
|
|
2380
|
+
if (axis === "profile" && context.initialProfileOutcome !== void 0) return true;
|
|
851
2381
|
if (explicit.pinned.includes(axis)) return true;
|
|
852
|
-
|
|
2382
|
+
if (axis !== "profile" && context.profileSelectionAxes?.includes(axis)) return true;
|
|
2383
|
+
const flag = `--${axis}`;
|
|
853
2384
|
return identity.sessionId === resolved.identity.sessionId && resolved.agentArgs.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
|
|
854
2385
|
}),
|
|
855
|
-
inheritedSelection: () => {
|
|
2386
|
+
inheritedSelection: async () => {
|
|
856
2387
|
const environment = { ...baseEnvironment };
|
|
857
2388
|
for (const key of [HARNESS_STATE_POINTER, ...Object.values(HARNESS_STATE_KEYS)]) delete environment[key];
|
|
858
|
-
const defaults = resolveHarnessOptions({
|
|
2389
|
+
const defaults = await resolveHarnessOptions({
|
|
859
2390
|
args: ["--cwd", policyOptions.cwd],
|
|
860
2391
|
cwd: policyOptions.cwd,
|
|
861
2392
|
environment,
|
|
862
2393
|
...policyOptions.configRoot === void 0 ? {} : { configRoot: policyOptions.configRoot }
|
|
863
2394
|
});
|
|
864
2395
|
return {
|
|
865
|
-
|
|
2396
|
+
preset: defaults.preset,
|
|
866
2397
|
domains: defaults.domains,
|
|
867
2398
|
profile: defaults.profile
|
|
868
2399
|
};
|
|
869
2400
|
},
|
|
870
2401
|
candidates: bundle.entries,
|
|
871
|
-
providerOverrides: () => selectedServerProviderOverrides(bundle.packages, sessionEnvironment),
|
|
872
|
-
requiredServerPackages: async () => {
|
|
873
|
-
const harness = loadHarnessState(sessionEnvironment).state;
|
|
874
|
-
if (!harness.hooks) return [];
|
|
875
|
-
return await validateHookModules({
|
|
876
|
-
repoRoot: policyOptions.repoRoot,
|
|
877
|
-
configRoot: policyOptions.configRoot,
|
|
878
|
-
homeDirectory,
|
|
879
|
-
hookGroups: harness.hookGroups,
|
|
880
|
-
descriptor: harness.hookModules,
|
|
881
|
-
isSubagent: Boolean(sessionEnvironment.PI_SUBAGENT_CHILD)
|
|
882
|
-
}) ? ["@agimon-ai/po-hook"] : [];
|
|
883
|
-
},
|
|
2402
|
+
providerOverrides: () => selectedServerProviderOverrides(bundle.packages, sessionEnvironment, notice),
|
|
884
2403
|
mcpPlugins: mcpBundle.plugins,
|
|
2404
|
+
registerModelProviders: async (runtime) => {
|
|
2405
|
+
for (const source of modelSources) try {
|
|
2406
|
+
await source(runtime);
|
|
2407
|
+
} catch (error) {
|
|
2408
|
+
notice(`Shared models unavailable: ${errorMessage(error)}`);
|
|
2409
|
+
}
|
|
2410
|
+
},
|
|
2411
|
+
...modelGateway === void 0 ? {} : { modelDependencies: (hostOptions) => modelGateway.modelDependencies(hostOptions) },
|
|
885
2412
|
resolveSelection: (requested) => {
|
|
886
|
-
const config =
|
|
2413
|
+
const config = loadPresetsConfig(policyOptions.configRoot ?? policyOptions.repoRoot, policyOptions.homeDirectory, policyOptions.environment ?? baseEnvironment);
|
|
887
2414
|
return {
|
|
888
2415
|
...requested,
|
|
889
|
-
activeLayers:
|
|
2416
|
+
activeLayers: resolveLayers(config, requested.preset)
|
|
890
2417
|
};
|
|
891
2418
|
},
|
|
2419
|
+
extensionLayers: () => {
|
|
2420
|
+
const configRoot = policyOptions.configRoot ?? policyOptions.repoRoot;
|
|
2421
|
+
const config = loadPresetsConfig(configRoot, policyOptions.homeDirectory, policyOptions.environment ?? baseEnvironment);
|
|
2422
|
+
const workspaceDirectory = path.join(configRoot, PO_DIR);
|
|
2423
|
+
return Object.entries(config.layers).filter(([, layer]) => layer.filePath !== void 0 && path.dirname(layer.filePath) === workspaceDirectory).map(([name]) => name);
|
|
2424
|
+
},
|
|
892
2425
|
telemetry,
|
|
893
2426
|
onNotice: notice
|
|
894
2427
|
};
|
|
895
2428
|
};
|
|
2429
|
+
const sessionSummaries = createSessionSummaries({
|
|
2430
|
+
setSessionSummary: (sessionId, summary) => hub.setSessionSummary?.(sessionId, summary),
|
|
2431
|
+
currentSummary: (sessionId) => hub.session(sessionId)?.summary,
|
|
2432
|
+
records: () => openSessions.list(),
|
|
2433
|
+
saveRecord: (record) => openSessions.add(record),
|
|
2434
|
+
notice
|
|
2435
|
+
});
|
|
2436
|
+
restoreSessionSummary = (record) => sessionSummaries.restore(record);
|
|
896
2437
|
mountSessionApis = async (sessionOptions, host) => serveSessionApis({
|
|
2438
|
+
clientDevices,
|
|
897
2439
|
parentScope: await hub.sessionParentScope(sessionOptions.workspaceId),
|
|
898
2440
|
sessionId: sessionOptions.sessionId,
|
|
2441
|
+
...sessionOptions.startedBy === void 0 ? {} : { startedBy: sessionOptions.startedBy },
|
|
899
2442
|
platform,
|
|
900
2443
|
cwd: sessionOptions.cwd,
|
|
901
2444
|
environment: sessionOptions.environment,
|
|
2445
|
+
...sessionOptions.artifactDirectory === void 0 ? {} : { artifactDirectory: sessionOptions.artifactDirectory },
|
|
902
2446
|
directEvents: hub.directEvents,
|
|
903
2447
|
requestApi: (mount, basePath, request) => hub.requestApi(mount, basePath, request),
|
|
904
2448
|
publishActivity: (activity) => hub.setSessionActivity?.(sessionOptions.sessionId, activity),
|
|
2449
|
+
publishSummary: (summary) => sessionSummaries.publish(sessionOptions.sessionId, summary),
|
|
2450
|
+
coordination: { startSession: (request) => {
|
|
2451
|
+
if (coordinators === void 0) return Promise.reject(/* @__PURE__ */ new Error("Coordinators are not ready."));
|
|
2452
|
+
return coordinators.startSession(sessionOptions.sessionId, request);
|
|
2453
|
+
} },
|
|
2454
|
+
shareRegisteredFile: (file) => remoteRuntime === void 0 ? Promise.reject(new Error(PO_SHARE_FILE_REMOTE_OFF_MESSAGE)) : remoteRuntime.fileShares.mintRegistered(sessionOptions.sessionId, file),
|
|
905
2455
|
shareFile: (filePath, label) => remoteRuntime === void 0 ? Promise.reject(new Error(PO_SHARE_FILE_REMOTE_OFF_MESSAGE)) : remoteRuntime.fileShares.mint({
|
|
906
2456
|
sessionId: sessionOptions.sessionId,
|
|
907
2457
|
cwd: sessionOptions.cwd,
|
|
@@ -919,6 +2469,16 @@ async function runServerRuntime(options, runtime) {
|
|
|
919
2469
|
authorizeRecording: (headers) => computerUse.authorizeRecording?.(sessionOptions.sessionId, headers) === true,
|
|
920
2470
|
authorizeActivation: (headers) => computerUse.authorizeActivation?.(headers) === true,
|
|
921
2471
|
claim: (headers) => computerUse.claimSession?.(sessionOptions.sessionId, headers),
|
|
2472
|
+
claimApproved: (approvalId) => computerUse.claimApproved?.(sessionOptions.sessionId, approvalId),
|
|
2473
|
+
releaseApproved: (approvalId) => computerUse.releaseApproved?.(sessionOptions.sessionId, approvalId),
|
|
2474
|
+
approvalClaim: () => computerUse.approvalOf?.(sessionOptions.sessionId),
|
|
2475
|
+
targets: (signal) => computerUse.request({
|
|
2476
|
+
sessionId: sessionOptions.sessionId,
|
|
2477
|
+
cwd: sessionOptions.cwd
|
|
2478
|
+
}, {
|
|
2479
|
+
operation: "targets",
|
|
2480
|
+
signal
|
|
2481
|
+
}),
|
|
922
2482
|
fetchRecording: (artifactId, range) => computerUse.readRecording?.({
|
|
923
2483
|
sessionId: sessionOptions.sessionId,
|
|
924
2484
|
cwd: sessionOptions.cwd
|
|
@@ -929,12 +2489,15 @@ async function runServerRuntime(options, runtime) {
|
|
|
929
2489
|
sessionService: hub.sessionService,
|
|
930
2490
|
mediaArbitration,
|
|
931
2491
|
executionBudget,
|
|
932
|
-
editPresence: hub.editPresence,
|
|
933
2492
|
peerAgents,
|
|
934
2493
|
pluginRegistry: hub.pluginRegistry,
|
|
935
2494
|
apis: [],
|
|
936
2495
|
packages: pendingSessions.get(sessionOptions.sessionId)?.bundle.packages ?? [],
|
|
937
2496
|
workspaceId: sessionOptions.workspaceId,
|
|
2497
|
+
clientPlugins: clientInventoryFor({
|
|
2498
|
+
scope: "session",
|
|
2499
|
+
sessionId: sessionOptions.sessionId
|
|
2500
|
+
}),
|
|
938
2501
|
workspaceRoot: sessionOptions.repoRoot,
|
|
939
2502
|
...host.sessionContext === void 0 ? {} : { sessionContext: host.sessionContext },
|
|
940
2503
|
homeDirectory,
|
|
@@ -948,15 +2511,25 @@ async function runServerRuntime(options, runtime) {
|
|
|
948
2511
|
};
|
|
949
2512
|
},
|
|
950
2513
|
preparePackages: (root) => {
|
|
2514
|
+
const outcome = pendingSessions.get(sessionOptions.sessionId)?.initialProfileOutcome;
|
|
2515
|
+
if (outcome !== void 0) root.provide(PROFILE_INITIAL_OUTCOME_SERVICE, outcome);
|
|
951
2516
|
sessionServiceRoots.set(host, root);
|
|
952
2517
|
host.preparePackages(root);
|
|
953
2518
|
},
|
|
954
|
-
activatePackages:
|
|
2519
|
+
activatePackages: async (packages) => {
|
|
2520
|
+
const { sessionId } = sessionOptions;
|
|
2521
|
+
const attempt = hub.lifecycle.opening(sessionId);
|
|
2522
|
+
attempt?.signal.throwIfAborted();
|
|
2523
|
+
if (attempt !== void 0 && pendingSessions.get(sessionId)?.initialProfileOutcome?.required) hub.lifecycle.transition(sessionId, attempt.id, "waiting_provider");
|
|
2524
|
+
await host.activatePackages(packages);
|
|
2525
|
+
attempt?.signal.throwIfAborted();
|
|
2526
|
+
},
|
|
955
2527
|
canDispatch: host.canDispatch,
|
|
956
2528
|
telemetry,
|
|
957
2529
|
onNotice: notice
|
|
958
2530
|
});
|
|
959
2531
|
requestSessionApi = async (scope, request) => {
|
|
2532
|
+
if (router?.mirror(scope.sessionId) !== void 0) return router.requestSessionApi(scope, request);
|
|
960
2533
|
const session = hub.session(scope.sessionId);
|
|
961
2534
|
const artifacts = sessionArtifacts.get(scope.sessionId);
|
|
962
2535
|
if (session === void 0 || session.cwd !== scope.cwd || artifacts === void 0) return Response.json({ error: "Session not found." }, { status: 404 });
|
|
@@ -970,59 +2543,108 @@ async function runServerRuntime(options, runtime) {
|
|
|
970
2543
|
...request.signal === void 0 ? {} : { signal: request.signal }
|
|
971
2544
|
}));
|
|
972
2545
|
};
|
|
973
|
-
if (!options.noSession) {
|
|
974
|
-
const initialOptions = resolveHarnessOptions({
|
|
2546
|
+
if (!options.noSession && recycled === void 0) {
|
|
2547
|
+
const initialOptions = await resolveHarnessOptions({
|
|
975
2548
|
args: resolved.agentArgs,
|
|
976
2549
|
cwd: baseCwd,
|
|
977
2550
|
environment: baseEnvironment
|
|
978
2551
|
});
|
|
979
2552
|
const initialWorkspace = await admitWorkspace(initialOptions.repoRoot);
|
|
980
2553
|
launchWorkspaceId = initialWorkspace.id;
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
const hookModules = await sessionHookModules(harnessContext, initialWorkspace.root);
|
|
989
|
-
updateHarnessState({ hookModules }, harnessContext.environment);
|
|
990
|
-
if (harnessContext.options.hooks) await validateHookModules({
|
|
991
|
-
repoRoot: harnessContext.options.repoRoot,
|
|
992
|
-
configRoot: initialWorkspace.root,
|
|
993
|
-
homeDirectory,
|
|
994
|
-
hookGroups: harnessContext.hookGroups,
|
|
995
|
-
descriptor: hookModules,
|
|
996
|
-
isSubagent: Boolean(baseEnvironment.PI_SUBAGENT_CHILD)
|
|
997
|
-
});
|
|
998
|
-
const initialBundle = await loadComposition(harnessContext.options.repoRoot, "session", {
|
|
999
|
-
root: harnessContext.options.repoRoot,
|
|
1000
|
-
majorMode: harnessContext.options.majorMode,
|
|
1001
|
-
activeLayers: harnessContext.selectedLayers
|
|
2554
|
+
if (initialWorkspace.sandbox !== void 0) {
|
|
2555
|
+
if (router === void 0) throw new Error(SANDBOX_UNREACHABLE);
|
|
2556
|
+
await router.openSession(initialWorkspace.id, {
|
|
2557
|
+
cwd: baseCwd,
|
|
2558
|
+
name: resolved.identity.sessionName,
|
|
2559
|
+
signal,
|
|
2560
|
+
...launchSessionRequest(resolved.agentArgs, initialOptions)
|
|
1002
2561
|
});
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
2562
|
+
} else {
|
|
2563
|
+
harnessContext = await prepareSessionHarness(initialOptions, initialWorkspace, signal, void 0, (await platform.sessions.list(BACKGROUND_CONTEXT)).some((entry) => entry.sessionId === resolved.identity.sessionId) ? void 0 : {
|
|
2564
|
+
args: resolved.agentArgs,
|
|
2565
|
+
cwd: baseCwd,
|
|
2566
|
+
environment: baseEnvironment
|
|
1006
2567
|
});
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
2568
|
+
const activeHarnessContext = harnessContext;
|
|
2569
|
+
try {
|
|
2570
|
+
const loadBundle = () => loadComposition(activeHarnessContext.options.repoRoot, "session", {
|
|
2571
|
+
root: activeHarnessContext.options.repoRoot,
|
|
2572
|
+
preset: activeHarnessContext.options.preset,
|
|
2573
|
+
activeLayers: activeHarnessContext.selectedLayers
|
|
2574
|
+
});
|
|
2575
|
+
const initialBundle = await loadBundle();
|
|
2576
|
+
const initialMcpBundle = await loadSessionMcp(harnessContext.options.repoRoot, {
|
|
2577
|
+
preset: harnessContext.options.preset,
|
|
2578
|
+
activeLayers: harnessContext.selectedLayers
|
|
2579
|
+
});
|
|
2580
|
+
pendingSessions.set(resolved.identity.sessionId, {
|
|
2581
|
+
cleanup: () => activeHarnessContext.cleanup(),
|
|
2582
|
+
bundle: initialBundle,
|
|
2583
|
+
mcpBundle: initialMcpBundle,
|
|
2584
|
+
loadBundle,
|
|
2585
|
+
initialProfileOutcome: activeHarnessContext.initialProfileOutcome
|
|
2586
|
+
});
|
|
2587
|
+
const created = await hub.create(await sessionHostOptions(harnessContext, initialBundle, initialMcpBundle, resolved.identity, initialWorkspace));
|
|
2588
|
+
recordLiveSession(created, harnessContext.options.repoRoot, initialWorkspace.root);
|
|
2589
|
+
} catch (error) {
|
|
2590
|
+
pendingSessions.delete(resolved.identity.sessionId);
|
|
2591
|
+
await activeHarnessContext.cleanup().catch((cleanupError) => notice(String(cleanupError)));
|
|
2592
|
+
throw asError(error);
|
|
2593
|
+
}
|
|
2594
|
+
await runBoundedShutdownStep("initial composition telemetry flush", () => harnessTelemetry.flush(), notice);
|
|
1017
2595
|
}
|
|
1018
|
-
await bounded(harnessTelemetry.flush(), "initial composition telemetry flush", notice);
|
|
1019
2596
|
}
|
|
1020
2597
|
const reservedOpens = /* @__PURE__ */ new Map();
|
|
1021
|
-
|
|
2598
|
+
/** Validates that explicit-ID workflow context came through the dormant step reopen path. */
|
|
2599
|
+
const reopeningSteps = /* @__PURE__ */ new Set();
|
|
2600
|
+
/**
|
|
2601
|
+
* The sandboxed workspace this session would join, decided before any host preparation. The
|
|
2602
|
+
* inherited workspace (placement or parent link) wins; otherwise the checkout's own root is
|
|
2603
|
+
* matched without reading its marker, and only then the marker names an owner.
|
|
2604
|
+
*/
|
|
2605
|
+
const sandboxedWorkspaceOf = async (request, groupingWorkspaceId) => {
|
|
2606
|
+
const records = workspaces.list();
|
|
2607
|
+
const owner = groupingWorkspaceId ?? (request.parentSessionId ? hub.session(request.parentSessionId)?.workspaceId ?? [...openSessions.list(), ...router?.dormant() ?? []].find((record) => record.sessionId === request.parentSessionId)?.workspaceId : void 0) ?? await checkoutWorkspaceId(records, request.cwd);
|
|
2608
|
+
return records.find((record) => record.id === owner && record.sandbox !== void 0)?.id;
|
|
2609
|
+
};
|
|
2610
|
+
openSession = async (request, sessionId, groupingWorkspaceId, keepDormantOnFailure = false, joinedAttempt) => {
|
|
1022
2611
|
request.signal?.throwIfAborted();
|
|
2612
|
+
const parent = request.parentSessionId === void 0 ? void 0 : hub.session(request.parentSessionId) ?? [...openSessions.list(), ...router?.dormant() ?? []].find((record) => record.sessionId === request.parentSessionId);
|
|
2613
|
+
if (request.requiredParentWorkspaceId !== void 0 && (request.workspaceId !== void 0 || parent?.workspaceId !== request.requiredParentWorkspaceId)) throw new PoHubParentUnavailableError();
|
|
2614
|
+
if (parent?.interaction === "unattended") request = {
|
|
2615
|
+
...request,
|
|
2616
|
+
interaction: "unattended"
|
|
2617
|
+
};
|
|
2618
|
+
if (parent !== void 0) {
|
|
2619
|
+
const { startedBy: _requested, ...rest } = request;
|
|
2620
|
+
request = parent.startedBy === void 0 ? rest : {
|
|
2621
|
+
...rest,
|
|
2622
|
+
startedBy: parent.startedBy
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
const sandboxed = await sandboxedWorkspaceOf(request, groupingWorkspaceId);
|
|
2626
|
+
if (sandboxed !== void 0) {
|
|
2627
|
+
if (router === void 0) throw new Error(SANDBOX_UNREACHABLE);
|
|
2628
|
+
return router.openSession(sandboxed, request, sessionId);
|
|
2629
|
+
}
|
|
2630
|
+
const { reopenSessionId, ...unopened } = request;
|
|
2631
|
+
if (reopenSessionId !== void 0) {
|
|
2632
|
+
request = unopened;
|
|
2633
|
+
const record = openSessions.list().find((entry) => entry.sessionId === reopenSessionId);
|
|
2634
|
+
if (request.workflowContext === void 0 || sessionId !== void 0 || request.reservationId !== void 0 || record === void 0 || hub.session(reopenSessionId) !== void 0 || sessionManager.get(reopenSessionId) !== void 0 || hub.lifecycle.opening(reopenSessionId) !== void 0 || record.parentSessionId !== request.parentSessionId || record.sessionProvenance !== WORKFLOW_STEP_SESSION_PROVENANCE || path.resolve(record.cwd) !== path.resolve(request.cwd)) throw new Error("Only a dormant step session of this workflow session can be reopened.");
|
|
2635
|
+
reopeningSteps.add(reopenSessionId);
|
|
2636
|
+
try {
|
|
2637
|
+
const scope = await openSession(request, record.sessionId, record.workspaceId, true);
|
|
2638
|
+
restoreSessionSummary(record);
|
|
2639
|
+
return scope;
|
|
2640
|
+
} finally {
|
|
2641
|
+
reopeningSteps.delete(reopenSessionId);
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
if (request.workflowContext !== void 0 && (request.reservationId !== void 0 || sessionId !== void 0 && !reopeningSteps.has(sessionId) || request.parentSessionId !== request.workflowContext.run.ownerSessionId || request.sessionProvenance !== WORKFLOW_STEP_SESSION_PROVENANCE)) throw new Error("Workflow context requires a new, unreserved step session owned by its workflow session.");
|
|
1023
2645
|
if (request.reservationId !== void 0) {
|
|
1024
2646
|
if (!request.parentSessionId || !cockpit) throw new Error("A reserved session requires its owning parent.");
|
|
1025
|
-
const prepared = await
|
|
2647
|
+
const prepared = await reservations().prepare(request.reservationId, request.parentSessionId, request.cwd);
|
|
1026
2648
|
if (sessionId !== void 0 && sessionId !== prepared.sessionId) throw new Error("Reserved session identity cannot change.");
|
|
1027
2649
|
sessionId = prepared.sessionId;
|
|
1028
2650
|
const existing = hub.session(sessionId);
|
|
@@ -1046,11 +2668,18 @@ async function runServerRuntime(options, runtime) {
|
|
|
1046
2668
|
sessionId: sessionId ?? crypto.randomUUID(),
|
|
1047
2669
|
sessionName: request.name,
|
|
1048
2670
|
parentSessionId: request.parentSessionId,
|
|
1049
|
-
sessionProvenance: request.sessionProvenance
|
|
2671
|
+
sessionProvenance: request.sessionProvenance,
|
|
2672
|
+
interaction: request.interaction,
|
|
2673
|
+
startedBy: request.startedBy
|
|
1050
2674
|
};
|
|
1051
|
-
const inheritedWorkspaceId = groupingWorkspaceId ??
|
|
2675
|
+
const inheritedWorkspaceId = groupingWorkspaceId ?? parent?.workspaceId;
|
|
1052
2676
|
const explicit = sessionSelectionArgs(request);
|
|
1053
2677
|
const openStartedAt = Date.now();
|
|
2678
|
+
const attempt = hub.lifecycle.begin(identity.sessionId, sessionId === void 0 || request.reservationId !== void 0 ? "create" : "wake", joinedAttempt);
|
|
2679
|
+
request = {
|
|
2680
|
+
...request,
|
|
2681
|
+
signal: AbortSignal.any(request.signal ? [request.signal, attempt.signal] : [attempt.signal])
|
|
2682
|
+
};
|
|
1054
2683
|
const start = (async () => {
|
|
1055
2684
|
const parent = request.parentSessionId !== void 0 && (sessionId === void 0 || request.reservationId !== void 0) ? sessionManager.get(request.parentSessionId) : void 0;
|
|
1056
2685
|
let initialFastMode;
|
|
@@ -1065,12 +2694,40 @@ async function runServerRuntime(options, runtime) {
|
|
|
1065
2694
|
...request.environment
|
|
1066
2695
|
};
|
|
1067
2696
|
for (const key of [HARNESS_STATE_POINTER, ...Object.values(HARNESS_STATE_KEYS)]) delete childEnvironment[key];
|
|
2697
|
+
const { startedBy } = identity;
|
|
2698
|
+
if (startedBy?.org === void 0) delete childEnvironment[SESSION_MEMBER_ENVIRONMENT];
|
|
2699
|
+
else childEnvironment[SESSION_MEMBER_ENVIRONMENT] = JSON.stringify({
|
|
2700
|
+
issuer: startedBy.issuer,
|
|
2701
|
+
subject: startedBy.subject,
|
|
2702
|
+
org: startedBy.org
|
|
2703
|
+
});
|
|
1068
2704
|
const workspace = inheritedWorkspaceId === void 0 ? await admitWorkspace(request.cwd) : hub.workspaces().find((candidate) => candidate.id === inheritedWorkspaceId && candidate.available !== false);
|
|
1069
2705
|
if (workspace === void 0) throw new Error("The session workspace is unavailable.");
|
|
1070
|
-
|
|
1071
|
-
if (
|
|
1072
|
-
|
|
1073
|
-
|
|
2706
|
+
if (workspace.kind === "session" && path.resolve(request.cwd) === workspace.root) throw new Error("Create a workspace-free session to allocate its working folder.");
|
|
2707
|
+
if (workspace.sandbox !== void 0) throw new Error(SANDBOX_UNREACHABLE);
|
|
2708
|
+
await syncCheckpoint(globalRoot, "The host scope");
|
|
2709
|
+
if (inheritedWorkspaceId !== void 0) await syncCheckpoint(workspace.root, workspaceLabel(workspace.root, workspace.name));
|
|
2710
|
+
const member = await isMemberCheckout(request.cwd, workspace);
|
|
2711
|
+
let profileIntent = request.selection?.profile === null ? { kind: "none" } : void 0;
|
|
2712
|
+
let restored = false;
|
|
2713
|
+
let requiredProfile;
|
|
2714
|
+
if (sessionId !== void 0 && request.reservationId === void 0 && !reopeningSteps.has(sessionId) && !explicit.pinned.includes("profile")) {
|
|
2715
|
+
const saved = await readSavedSelection(platform.sessions, sessionId);
|
|
2716
|
+
restored = saved !== void 0;
|
|
2717
|
+
const name = saved?.profile ?? saved?.requestedProfile;
|
|
2718
|
+
if (typeof name === "string") {
|
|
2719
|
+
profileIntent = {
|
|
2720
|
+
kind: "named",
|
|
2721
|
+
name
|
|
2722
|
+
};
|
|
2723
|
+
requiredProfile = true;
|
|
2724
|
+
} else if (name === null) profileIntent = { kind: "none" };
|
|
2725
|
+
}
|
|
2726
|
+
if (requiredProfile) {
|
|
2727
|
+
attempt.signal.throwIfAborted();
|
|
2728
|
+
hub.lifecycle.transition(identity.sessionId, attempt.id, "waiting_profile");
|
|
2729
|
+
}
|
|
2730
|
+
const childContext = await prepareSessionHarness(await resolveHarnessOptions({
|
|
1074
2731
|
args: [
|
|
1075
2732
|
"--cwd",
|
|
1076
2733
|
request.cwd,
|
|
@@ -1080,68 +2737,64 @@ async function runServerRuntime(options, runtime) {
|
|
|
1080
2737
|
cwd: request.cwd,
|
|
1081
2738
|
environment: childEnvironment,
|
|
1082
2739
|
...member ? { configRoot: workspace.root } : {}
|
|
1083
|
-
}),
|
|
2740
|
+
}), workspace, request.signal === void 0 ? signal : AbortSignal.any([signal, request.signal]), profileIntent, restored ? void 0 : {
|
|
2741
|
+
args: [
|
|
2742
|
+
"--cwd",
|
|
2743
|
+
request.cwd,
|
|
2744
|
+
...childIdentity.agentArgs,
|
|
2745
|
+
...explicit.args
|
|
2746
|
+
],
|
|
2747
|
+
cwd: request.cwd,
|
|
2748
|
+
environment: childEnvironment,
|
|
2749
|
+
...member ? { configRoot: workspace.root } : {}
|
|
2750
|
+
}, requiredProfile);
|
|
1084
2751
|
try {
|
|
1085
|
-
const
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
configRoot: workspace.root,
|
|
1090
|
-
homeDirectory,
|
|
1091
|
-
hookGroups: childContext.hookGroups,
|
|
1092
|
-
descriptor: hookModules,
|
|
1093
|
-
isSubagent: Boolean(childEnvironment.PI_SUBAGENT_CHILD)
|
|
1094
|
-
});
|
|
1095
|
-
const bundle = await loadComposition(childContext.options.repoRoot, "session", {
|
|
1096
|
-
root: childContext.options.repoRoot,
|
|
1097
|
-
majorMode: childContext.options.majorMode,
|
|
2752
|
+
const compositionRoot = childContext.options.configRoot ?? childContext.options.repoRoot;
|
|
2753
|
+
const loadBundle = () => loadComposition(compositionRoot, "session", {
|
|
2754
|
+
root: compositionRoot,
|
|
2755
|
+
preset: childContext.options.preset,
|
|
1098
2756
|
activeLayers: childContext.selectedLayers
|
|
1099
2757
|
});
|
|
1100
|
-
const
|
|
1101
|
-
|
|
2758
|
+
const bundle = await loadBundle();
|
|
2759
|
+
const mcpBundle = await loadSessionMcp(compositionRoot, {
|
|
2760
|
+
preset: childContext.options.preset,
|
|
1102
2761
|
activeLayers: childContext.selectedLayers
|
|
1103
2762
|
});
|
|
1104
2763
|
request.signal?.throwIfAborted();
|
|
1105
2764
|
pendingSessions.set(identity.sessionId, {
|
|
1106
2765
|
cleanup: () => childContext.cleanup(),
|
|
1107
2766
|
bundle,
|
|
1108
|
-
mcpBundle
|
|
2767
|
+
mcpBundle,
|
|
2768
|
+
loadBundle,
|
|
2769
|
+
initialProfileOutcome: childContext.initialProfileOutcome
|
|
1109
2770
|
});
|
|
1110
|
-
const created = await hub.create(
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
2771
|
+
const created = await hub.create({
|
|
2772
|
+
...await sessionHostOptions(childContext, bundle, mcpBundle, identity, workspace, {
|
|
2773
|
+
pinned: explicit.pinned,
|
|
2774
|
+
...initialFastMode === void 0 ? {} : { initialFastMode },
|
|
2775
|
+
...request.reservationId === void 0 ? {} : { initialAgentLocked: true },
|
|
2776
|
+
...sessionId !== void 0 && request.reservationId === void 0 ? { resume: true } : {},
|
|
2777
|
+
...request.selection?.modes === void 0 ? {} : { modes: request.selection.modes },
|
|
2778
|
+
...request.tools === void 0 ? {} : { allowedTools: request.tools }
|
|
2779
|
+
}),
|
|
2780
|
+
startupSignal: request.signal,
|
|
2781
|
+
...request.workflowContext === void 0 ? {} : { workflowContext: request.workflowContext },
|
|
2782
|
+
...request.requiredPackages === void 0 ? {} : { requiredServerPackages: async () => request.requiredPackages ?? [] }
|
|
2783
|
+
}, attempt);
|
|
1118
2784
|
request.signal?.throwIfAborted();
|
|
1119
|
-
|
|
1120
|
-
if (openSessions.add({
|
|
1121
|
-
sessionId: created.id,
|
|
1122
|
-
workspaceId: created.workspaceId,
|
|
1123
|
-
cwd: created.cwd,
|
|
1124
|
-
repoRoot: childContext.options.repoRoot,
|
|
1125
|
-
groupingRoot: workspace.root,
|
|
1126
|
-
name: created.name,
|
|
1127
|
-
createdAt: created.createdAt,
|
|
1128
|
-
...created.parentSessionId === void 0 ? {} : { parentSessionId: created.parentSessionId },
|
|
1129
|
-
...created.sessionProvenance === void 0 ? {} : { sessionProvenance: created.sessionProvenance },
|
|
1130
|
-
...created.groups === void 0 || created.groups.length === 0 ? {} : { groups: [...created.groups] }
|
|
1131
|
-
}) === false) throw new Error("The new session could not be durably recorded.");
|
|
1132
|
-
}
|
|
2785
|
+
recordLiveSession(created, childContext.options.repoRoot, workspace.root);
|
|
1133
2786
|
return {
|
|
1134
2787
|
sessionId: identity.sessionId,
|
|
1135
2788
|
cwd: childContext.options.cwd,
|
|
1136
2789
|
workspaceId: created.workspaceId
|
|
1137
2790
|
};
|
|
1138
2791
|
} catch (error) {
|
|
1139
|
-
if (hub.session(identity.sessionId)) await hub.closeSession(identity.sessionId);
|
|
2792
|
+
if (hub.session(identity.sessionId)) await hub.closeSession(identity.sessionId, { keepDormant: keepDormantOnFailure });
|
|
1140
2793
|
else {
|
|
1141
2794
|
pendingSessions.delete(identity.sessionId);
|
|
1142
2795
|
await childContext.cleanup().catch((cleanupError) => notice(String(cleanupError)));
|
|
1143
2796
|
}
|
|
1144
|
-
throw error;
|
|
2797
|
+
throw asError(error);
|
|
1145
2798
|
}
|
|
1146
2799
|
})();
|
|
1147
2800
|
start.then(() => "success", () => "failure").then((outcome) => telemetry.recordEvent("po_server.session_open", {
|
|
@@ -1151,33 +2804,126 @@ async function runServerRuntime(options, runtime) {
|
|
|
1151
2804
|
if (request.reservationId !== void 0) reservedOpens.set(identity.sessionId, start);
|
|
1152
2805
|
try {
|
|
1153
2806
|
return await start;
|
|
2807
|
+
} catch (error) {
|
|
2808
|
+
const state = hub.lifecycle.snapshot(identity.sessionId)?.state;
|
|
2809
|
+
hub.lifecycle.fail(identity.sessionId, attempt.id, error, {
|
|
2810
|
+
cancelled: state === "stopping" || state !== "failed" && request.signal?.aborted === true,
|
|
2811
|
+
recorded: openSessions.list().some((record) => record.sessionId === identity.sessionId)
|
|
2812
|
+
});
|
|
2813
|
+
throw asError(error);
|
|
1154
2814
|
} finally {
|
|
1155
2815
|
if (reservedOpens.get(identity.sessionId) === start) reservedOpens.delete(identity.sessionId);
|
|
1156
2816
|
}
|
|
1157
2817
|
};
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
2818
|
+
if (sandboxIdentity !== void 0) registerContainedSessionMethods(hub.pluginRegistry, {
|
|
2819
|
+
open: (request, sessionId) => openSession(request, sessionId),
|
|
2820
|
+
close: (sessionId, keepDormant) => hub.closeSession(sessionId, keepDormant ? { keepDormant: true } : void 0),
|
|
2821
|
+
adopt: async (record) => {
|
|
2822
|
+
if (record.workspaceId !== sandboxIdentity.workspaceId) throw new Error("The adopted session belongs to another workspace.");
|
|
2823
|
+
if (hub.session(record.sessionId) !== void 0) return;
|
|
2824
|
+
if (!openSessions.add(record)) throw new Error("The adopted session could not be durably recorded.");
|
|
2825
|
+
hub.notifyDormantChanged(record.sessionId);
|
|
2826
|
+
}
|
|
2827
|
+
});
|
|
2828
|
+
let readmission;
|
|
2829
|
+
const retryFailedAdmissions = () => {
|
|
2830
|
+
if (readmission) return readmission;
|
|
2831
|
+
readmission = Promise.resolve().then(async () => {
|
|
2832
|
+
for (const [id, root] of new Map(failedAdmissions)) {
|
|
2833
|
+
if (signal.aborted || shuttingDown) return;
|
|
2834
|
+
if (failedAdmissions.get(id) !== root) continue;
|
|
2835
|
+
const record = workspaces.list().find((workspace) => workspace.id === id);
|
|
2836
|
+
if (record?.root !== root) {
|
|
2837
|
+
failedAdmissions.delete(id);
|
|
2838
|
+
continue;
|
|
2839
|
+
}
|
|
2840
|
+
await admitWorkspace(root, {
|
|
2841
|
+
declaration: record.declaration,
|
|
2842
|
+
workspaceId: id
|
|
2843
|
+
}).catch((error) => notice(`Workspace '${root}' is still unavailable and will be retried: ${errorMessage(error)}`));
|
|
2844
|
+
}
|
|
2845
|
+
}).finally(() => {
|
|
2846
|
+
readmission = void 0;
|
|
1165
2847
|
});
|
|
2848
|
+
return readmission;
|
|
2849
|
+
};
|
|
2850
|
+
settleRecoveryWorkspaces = async () => {
|
|
2851
|
+
const deadline = createDeadline(signal, 3e4);
|
|
2852
|
+
try {
|
|
2853
|
+
const result = await deadline.within(async () => {
|
|
2854
|
+
await retryFailedAdmissions();
|
|
2855
|
+
await hostCheck;
|
|
2856
|
+
});
|
|
2857
|
+
if (result.status !== "done") notice(`Recovery workspace preparation: ${result.status}.`);
|
|
2858
|
+
} finally {
|
|
2859
|
+
deadline.dispose();
|
|
2860
|
+
}
|
|
1166
2861
|
};
|
|
1167
|
-
|
|
2862
|
+
scopeReload.bind({
|
|
2863
|
+
trackJob,
|
|
2864
|
+
invalidateCaches: () => {
|
|
2865
|
+
bundler.invalidate();
|
|
2866
|
+
syncCheckpoints.invalidate();
|
|
2867
|
+
},
|
|
2868
|
+
globalRoot,
|
|
2869
|
+
readSyncRevision: async () => {
|
|
2870
|
+
const pointer = await readSyncPointer(globalRoot);
|
|
2871
|
+
return pointer === void 0 ? void 0 : JSON.stringify(pointer);
|
|
2872
|
+
},
|
|
2873
|
+
refreshGlobalBuilds: async () => {
|
|
2874
|
+
try {
|
|
2875
|
+
await refreshWebBuild();
|
|
2876
|
+
} catch (error) {
|
|
2877
|
+
notice(`Web build check failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
2878
|
+
}
|
|
2879
|
+
},
|
|
2880
|
+
checkHostScope: (root) => checkScope(root, { scope: "host" }),
|
|
2881
|
+
listServedWorkspaces: () => hub.workspaces().filter((workspace) => servedOnHost(workspace)),
|
|
2882
|
+
checkWorkspaceScope: (workspace) => checkScope(workspace.root, {
|
|
2883
|
+
scope: "workspace",
|
|
2884
|
+
workspaceId: workspace.id
|
|
2885
|
+
}),
|
|
2886
|
+
retryFailedAdmissions,
|
|
2887
|
+
recordScopeCheck: ({ source, roots, durationMs }) => telemetry.recordEvent("po_server.scope_check", {
|
|
2888
|
+
source,
|
|
2889
|
+
roots,
|
|
2890
|
+
duration_ms: durationMs
|
|
2891
|
+
}),
|
|
2892
|
+
syncCheckpoint,
|
|
2893
|
+
workspaceLabel
|
|
2894
|
+
});
|
|
2895
|
+
onExtensionCheck?.(() => scopeReload.checkAllScopes("upm"));
|
|
1168
2896
|
/**
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1171
|
-
*
|
|
1172
|
-
*
|
|
2897
|
+
* Reloads one session's own packages between tool rounds: changed and added packages install
|
|
2898
|
+
* with per-package rollback, removed ones are disposed, then the selection gates on the new set.
|
|
2899
|
+
* ponytail: provider overrides and MCP plugins keep the set the session opened with; reopen the
|
|
2900
|
+
* session to change those.
|
|
1173
2901
|
*/
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
2902
|
+
reloadSessionPackages = async (sessionId) => {
|
|
2903
|
+
const artifacts = sessionArtifacts.get(sessionId);
|
|
2904
|
+
const host = baseSessionManager.get(sessionId);
|
|
2905
|
+
const reconcile = artifacts?.apis.reconcile;
|
|
2906
|
+
if (artifacts === void 0 || host?.reloadPackages === void 0 || reconcile === void 0) throw new Error(`Session '${sessionId}' cannot reload its packages here.`);
|
|
2907
|
+
return host.runtime.runAtToolBoundary(async () => {
|
|
2908
|
+
await refreshPackageWatching();
|
|
2909
|
+
bundler.invalidate();
|
|
2910
|
+
bundler.poisoned.clear();
|
|
2911
|
+
const accounting = createPackageReloadCheck();
|
|
2912
|
+
const identities = (entries) => entries.filter((entry) => entry.scopes.includes("session"));
|
|
2913
|
+
accounting.commit(sessionId, identities(artifacts.bundle.entries));
|
|
2914
|
+
const bundle = await artifacts.loadBundle();
|
|
2915
|
+
const declared = bundle.entries.filter((entry) => entry.scopes.includes("session")).map((entry) => entry.packageName);
|
|
2916
|
+
const result = await reconcile(bundle.packages, declared);
|
|
2917
|
+
artifacts.bundle = bundle;
|
|
2918
|
+
await host.reloadPackages?.(bundle.entries, result.installed);
|
|
2919
|
+
idleRestart.supersede(accounting.diff(sessionId, identities(bundle.entries)).superseded);
|
|
2920
|
+
return result;
|
|
2921
|
+
});
|
|
1178
2922
|
};
|
|
1179
|
-
|
|
1180
|
-
|
|
2923
|
+
refreshSessionSelection = async (sessionId, axes) => {
|
|
2924
|
+
const host = baseSessionManager.get(sessionId);
|
|
2925
|
+
if (host?.refreshSelection === void 0) throw new Error(`Session '${sessionId}' cannot refresh its selection here.`);
|
|
2926
|
+
await host.runtime.runAtToolBoundary(() => host.refreshSelection(axes));
|
|
1181
2927
|
};
|
|
1182
2928
|
});
|
|
1183
2929
|
const workspaceResumes = /* @__PURE__ */ new Map();
|
|
@@ -1188,51 +2934,375 @@ async function runServerRuntime(options, runtime) {
|
|
|
1188
2934
|
notice(`Saved session ${sessionId} is hidden from History: ${error instanceof Error ? error.message : String(error)}`);
|
|
1189
2935
|
};
|
|
1190
2936
|
const savedHistory = async (workspaceId) => {
|
|
1191
|
-
const root = hub.workspaces().find((workspace) => workspace.id === workspaceId && workspace
|
|
2937
|
+
const root = hub.workspaces().find((workspace) => workspace.id === workspaceId && servedOnHost(workspace))?.root;
|
|
1192
2938
|
if (!root) throw new Error("Workspace not found.");
|
|
1193
|
-
return listSavedSessionRecords(platform.sessions, root,
|
|
2939
|
+
return listSavedSessionRecords(platform.sessions, root, await sessionRemoval.hidden(hub.snapshot().map((active) => active.id)), workspaceId, unreadableHistory);
|
|
1194
2940
|
};
|
|
1195
|
-
const validateExecution = (target, workspaceId) => {
|
|
1196
|
-
const root = hub.workspaces().find((workspace) => workspace.id === workspaceId && workspace
|
|
2941
|
+
const validateExecution = async (target, workspaceId) => {
|
|
2942
|
+
const root = hub.workspaces().find((workspace) => workspace.id === workspaceId && servedOnHost(workspace))?.root;
|
|
1197
2943
|
if (!root || target.groupingRoot !== root || target.workspaceId && target.workspaceId !== workspaceId) throw new Error("Saved session does not belong to this workspace.");
|
|
1198
|
-
if (
|
|
2944
|
+
if (await resolveWorkspaceRoot(target.cwd) !== target.repoRoot) throw new Error("Saved session checkout is unavailable.");
|
|
2945
|
+
};
|
|
2946
|
+
const reviveRecord = (record, options, retryCount = 0) => {
|
|
2947
|
+
if (router?.owns(record.sessionId) === true) return router.revive(record.sessionId, options);
|
|
2948
|
+
const id = record.sessionId;
|
|
2949
|
+
const pending = reviving.get(id);
|
|
2950
|
+
if (pending) {
|
|
2951
|
+
if (options?.automatic) pending.automatic = true;
|
|
2952
|
+
return pending.promise;
|
|
2953
|
+
}
|
|
2954
|
+
if (sessionManager.get(id)) return Promise.resolve();
|
|
2955
|
+
if (shuttingDown || signal.aborted) return Promise.reject(/* @__PURE__ */ new Error("The server is shutting down."));
|
|
2956
|
+
const queuedRetry = clearRevivalRetry(id);
|
|
2957
|
+
const attempt = hub.lifecycle.begin(id, retryCount > 0 ? "retry" : options?.automatic ? "boot" : "wake");
|
|
2958
|
+
const startupSignal = AbortSignal.any([signal, attempt.signal]);
|
|
2959
|
+
const result = {
|
|
2960
|
+
promise: Promise.resolve(),
|
|
2961
|
+
automatic: options?.automatic ?? (queuedRetry > 0 ? true : void 0)
|
|
2962
|
+
};
|
|
2963
|
+
const opening = Promise.resolve().then(async () => {
|
|
2964
|
+
startupSignal.throwIfAborted();
|
|
2965
|
+
if (!await pathExists(hostFiles, record.cwd, BACKGROUND_CONTEXT)) throw new Error(CONTAINER_WORKTREE_GONE);
|
|
2966
|
+
const workspace = hub.workspaces().find(({ id }) => id === record.workspaceId);
|
|
2967
|
+
if (!workspace || record.groupingRoot !== void 0 && workspace.root !== record.groupingRoot) throw new Error("The session workspace is unavailable.");
|
|
2968
|
+
if (record.repoRoot !== void 0 && await resolveWorkspaceRoot(record.cwd) !== record.repoRoot) throw new Error("The session checkout has changed.");
|
|
2969
|
+
if (workspace.available === false) {
|
|
2970
|
+
const error = /* @__PURE__ */ new Error("The session workspace is unavailable.");
|
|
2971
|
+
throw failedAdmissions.has(workspace.id) ? Object.assign(error, { lifecycleReason: "workspace_not_ready" }) : error;
|
|
2972
|
+
}
|
|
2973
|
+
await openSession({
|
|
2974
|
+
cwd: record.cwd,
|
|
2975
|
+
signal: startupSignal,
|
|
2976
|
+
name: record.name,
|
|
2977
|
+
...record.parentSessionId === void 0 ? {} : { parentSessionId: record.parentSessionId },
|
|
2978
|
+
...record.sessionProvenance === void 0 ? {} : { sessionProvenance: record.sessionProvenance },
|
|
2979
|
+
...record.interaction === void 0 ? {} : { interaction: record.interaction },
|
|
2980
|
+
...record.startedBy === void 0 ? {} : { startedBy: record.startedBy }
|
|
2981
|
+
}, record.sessionId, record.workspaceId, true, attempt);
|
|
2982
|
+
startupSignal.throwIfAborted();
|
|
2983
|
+
restoreSessionSummary(record);
|
|
2984
|
+
const groups = record.groups ?? [];
|
|
2985
|
+
const opened = hub.session(record.sessionId)?.groups ?? [];
|
|
2986
|
+
if (groups.length !== opened.length || groups.some((group, index) => opened[index] !== group)) await hub.runtime(record.sessionId)?.setGroups(groups);
|
|
2987
|
+
const { bot, botRevision = 0 } = openSessions.list().find((entry) => entry.sessionId === id) ?? record;
|
|
2988
|
+
if (bot !== void 0) {
|
|
2989
|
+
const runtime = hub.runtime(record.sessionId);
|
|
2990
|
+
let revision = hub.session(record.sessionId)?.botRevision ?? 0;
|
|
2991
|
+
while (runtime !== void 0 && revision < botRevision) {
|
|
2992
|
+
startupSignal.throwIfAborted();
|
|
2993
|
+
const result = await runtime.setBot({
|
|
2994
|
+
bot,
|
|
2995
|
+
expectedRevision: revision
|
|
2996
|
+
});
|
|
2997
|
+
if (!result.ok && result.revision <= revision) break;
|
|
2998
|
+
revision = result.revision;
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
startupSignal.throwIfAborted();
|
|
3002
|
+
}).catch((error) => {
|
|
3003
|
+
const state = hub.lifecycle.snapshot(id)?.state;
|
|
3004
|
+
const cancelled = signal.aborted || state === "stopping" || state === "dormant" || state === void 0;
|
|
3005
|
+
hub.lifecycle.fail(id, attempt.id, error, {
|
|
3006
|
+
cancelled,
|
|
3007
|
+
recorded: true
|
|
3008
|
+
});
|
|
3009
|
+
if (!cancelled) {
|
|
3010
|
+
const failure = hub.lifecycle.classify(error);
|
|
3011
|
+
const retries = Math.max(retryCount, queuedRetry);
|
|
3012
|
+
if (result.automatic && failure.retryable && !restorePlan.blocked && !shuttingDown) {
|
|
3013
|
+
if (retries < REVIVAL_RETRY_LIMIT) {
|
|
3014
|
+
const delay = Math.min(1e3 * 2 ** retries, REVIVAL_RETRY_MAX_DELAY_MS);
|
|
3015
|
+
const timer = setTimeout(() => {
|
|
3016
|
+
enqueueRecovery(async () => {
|
|
3017
|
+
const stillQueued = () => revivalRetries.get(id)?.timer === timer && !signal.aborted && !shuttingDown && !restorePlan.blocked;
|
|
3018
|
+
if (!stillQueued()) return;
|
|
3019
|
+
await settleRecoveryWorkspaces?.();
|
|
3020
|
+
if (!stillQueued()) return;
|
|
3021
|
+
revivalRetries.delete(id);
|
|
3022
|
+
const saved = openSessions.list().find((entry) => entry.sessionId === id);
|
|
3023
|
+
if (saved === void 0 || hub.session(id) !== void 0) return;
|
|
3024
|
+
await reviveRecord(saved, { automatic: true }, retries + 1).catch((retryError) => {
|
|
3025
|
+
if (!revivalRetries.has(id) && !signal.aborted && !shuttingDown) notice(`Session '${id}' did not reopen: ${errorMessage(retryError)}`);
|
|
3026
|
+
});
|
|
3027
|
+
}).catch((error) => {
|
|
3028
|
+
if (revivalRetries.get(id)?.timer === timer) revivalRetries.delete(id);
|
|
3029
|
+
if (!signal.aborted && !shuttingDown) notice(`Session '${id}' recovery preparation failed: ${errorMessage(error)}`);
|
|
3030
|
+
});
|
|
3031
|
+
}, delay);
|
|
3032
|
+
timer.unref();
|
|
3033
|
+
revivalRetries.set(id, {
|
|
3034
|
+
timer,
|
|
3035
|
+
count: retries + 1
|
|
3036
|
+
});
|
|
3037
|
+
}
|
|
3038
|
+
} else if (result.automatic) {
|
|
3039
|
+
recoverySessionIds.delete(id);
|
|
3040
|
+
persistRecovery();
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
throw asError(error);
|
|
3044
|
+
}).finally(() => {
|
|
3045
|
+
reviving.delete(id);
|
|
3046
|
+
idleRestart.poke();
|
|
3047
|
+
});
|
|
3048
|
+
result.promise = opening;
|
|
3049
|
+
reviving.set(id, result);
|
|
3050
|
+
return opening;
|
|
3051
|
+
};
|
|
3052
|
+
reviveSession = async (sessionId, options) => {
|
|
3053
|
+
if (options?.automatic) {
|
|
3054
|
+
await revivalReady;
|
|
3055
|
+
if (restorePlan.blocked) {
|
|
3056
|
+
pauseRevival(sessionId);
|
|
3057
|
+
return "paused";
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
const record = allDormant().find((item) => item.sessionId === sessionId);
|
|
3061
|
+
if (record === void 0) {
|
|
3062
|
+
if (options?.automatic) return "not_found";
|
|
3063
|
+
throw new Error("The session has no saved record.");
|
|
3064
|
+
}
|
|
3065
|
+
await reviveRecord(record, options?.automatic ? { automatic: true } : void 0);
|
|
3066
|
+
return options?.automatic ? "revived" : void 0;
|
|
1199
3067
|
};
|
|
1200
|
-
const
|
|
1201
|
-
const
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
3068
|
+
const createGeneralSession = async ({ name, selection, sessionProvenance, model, startedBy }) => {
|
|
3069
|
+
const { root, cwd } = await createSessionWorkspaceFolder(serverDirectory);
|
|
3070
|
+
try {
|
|
3071
|
+
generalWorkspace ??= admitWorkspace(root, {
|
|
3072
|
+
kind: "session",
|
|
3073
|
+
name: DEFAULT_WORKSPACE_NAME
|
|
3074
|
+
}).catch((error) => {
|
|
3075
|
+
generalWorkspace = void 0;
|
|
3076
|
+
throw asError(error);
|
|
3077
|
+
});
|
|
3078
|
+
const workspace = await generalWorkspace;
|
|
3079
|
+
return await openSession({
|
|
3080
|
+
cwd,
|
|
3081
|
+
name: name?.trim() || "New session",
|
|
3082
|
+
...selection === void 0 ? {} : { selection },
|
|
3083
|
+
...sessionProvenance === void 0 ? {} : { sessionProvenance },
|
|
3084
|
+
...model === void 0 ? {} : { model },
|
|
3085
|
+
...startedBy === void 0 ? {} : { startedBy }
|
|
3086
|
+
}, void 0, workspace.id);
|
|
3087
|
+
} catch (error) {
|
|
3088
|
+
await discardEmptySessionFolder(cwd).catch((cleanupError) => notice(String(cleanupError)));
|
|
3089
|
+
throw asError(error);
|
|
3090
|
+
}
|
|
1213
3091
|
};
|
|
3092
|
+
const coordinatorAdmission = bindCoordinatorMoves(createCoordinatorService({
|
|
3093
|
+
liveSessions: () => hub.snapshot(),
|
|
3094
|
+
records: () => openSessions.list(),
|
|
3095
|
+
saveRecord: (record) => openSessions.add(record),
|
|
3096
|
+
workspaces: () => hub.workspaces(),
|
|
3097
|
+
revive: reviveRecord,
|
|
3098
|
+
createGeneral: createGeneralSession,
|
|
3099
|
+
createInWorkspace: (workspace, request) => openSession({
|
|
3100
|
+
cwd: workspace.root,
|
|
3101
|
+
signal,
|
|
3102
|
+
...request
|
|
3103
|
+
}, void 0, workspace.id),
|
|
3104
|
+
prompt: async (sessionId, text) => {
|
|
3105
|
+
if (hub.sessionService.prompt === void 0) throw new Error("This host cannot prompt sessions.");
|
|
3106
|
+
return hub.sessionService.prompt(sessionId, text);
|
|
3107
|
+
},
|
|
3108
|
+
defaultProfile: (root) => loadProfileCatalog(root ?? globalPoConfigDirectory(homeDirectory, baseEnvironment), homeDirectory, baseEnvironment).defaultProfile,
|
|
3109
|
+
validateProfile: async (profile, workspace) => {
|
|
3110
|
+
const parent = await hub.sessionParentScope(workspace?.id);
|
|
3111
|
+
const scope = workspace === void 0 ? void 0 : { workspaceId: workspace.id };
|
|
3112
|
+
const sources = readProfileSources(parent.root, scope);
|
|
3113
|
+
const files = loadProfileCatalog(workspace?.root ?? globalPoConfigDirectory(homeDirectory, baseEnvironment), homeDirectory, baseEnvironment).profiles;
|
|
3114
|
+
if ((await resolveInitialProfile(files, sources, {
|
|
3115
|
+
intent: {
|
|
3116
|
+
kind: "named",
|
|
3117
|
+
name: profile
|
|
3118
|
+
},
|
|
3119
|
+
scope,
|
|
3120
|
+
signal
|
|
3121
|
+
})).resolvedProfile !== profile) throw new Error(`Profile '${profile}' is unavailable.`);
|
|
3122
|
+
},
|
|
3123
|
+
reopen: async (sessionId, role) => {
|
|
3124
|
+
if (router?.mirror(sessionId) !== void 0) throw new Error("A sandboxed session cannot change its role.");
|
|
3125
|
+
const session = hub.session(sessionId);
|
|
3126
|
+
if (session === void 0) throw new Error("Session not found.");
|
|
3127
|
+
const record = openSessions.list().find((entry) => entry.sessionId === sessionId);
|
|
3128
|
+
await hub.closeSession(sessionId);
|
|
3129
|
+
try {
|
|
3130
|
+
await openSession({
|
|
3131
|
+
cwd: session.cwd,
|
|
3132
|
+
name: session.name,
|
|
3133
|
+
...session.parentSessionId === void 0 ? {} : { parentSessionId: session.parentSessionId },
|
|
3134
|
+
...role.sessionProvenance === void 0 ? {} : { sessionProvenance: role.sessionProvenance },
|
|
3135
|
+
...role.profile === void 0 ? {} : { selection: { profile: role.profile } },
|
|
3136
|
+
...session.interaction === void 0 ? {} : { interaction: session.interaction },
|
|
3137
|
+
...session.startedBy === void 0 ? {} : { startedBy: session.startedBy }
|
|
3138
|
+
}, sessionId, session.workspaceId);
|
|
3139
|
+
} catch (error) {
|
|
3140
|
+
if (record !== void 0) openSessions.add(record);
|
|
3141
|
+
throw asError(error);
|
|
3142
|
+
}
|
|
3143
|
+
},
|
|
3144
|
+
notice
|
|
3145
|
+
}), (sessionId, workspaceId) => moveSessionWorkspace({
|
|
3146
|
+
hub,
|
|
3147
|
+
records: openSessions,
|
|
3148
|
+
sessions: platform.sessions,
|
|
3149
|
+
validateDestination: async (workspace) => {
|
|
3150
|
+
const info = await hostFiles.fileInfo(workspace.root, BACKGROUND_CONTEXT);
|
|
3151
|
+
if (!info.ok || info.value.kind !== "directory" || await resolveWorkspaceRoot(workspace.root) !== workspace.root) throw new Error("The destination workspace folder is unavailable.");
|
|
3152
|
+
},
|
|
3153
|
+
open: async (record, workspace) => {
|
|
3154
|
+
await openSession({
|
|
3155
|
+
cwd: record.cwd,
|
|
3156
|
+
name: record.name,
|
|
3157
|
+
...record.sessionProvenance === void 0 ? {} : { sessionProvenance: record.sessionProvenance },
|
|
3158
|
+
...record.interaction === void 0 ? {} : { interaction: record.interaction },
|
|
3159
|
+
...record.startedBy === void 0 ? {} : { startedBy: record.startedBy }
|
|
3160
|
+
}, record.sessionId, workspace.id, true);
|
|
3161
|
+
restoreSessionSummary(record);
|
|
3162
|
+
await hub.runtime(record.sessionId)?.setGroups(record.groups ?? []);
|
|
3163
|
+
}
|
|
3164
|
+
}, sessionId, workspaceId));
|
|
3165
|
+
coordinators = coordinatorAdmission;
|
|
1214
3166
|
cockpit = await serveHeadlessServer({
|
|
3167
|
+
clientDevices,
|
|
3168
|
+
environment: baseEnvironment,
|
|
3169
|
+
teamMode: teamHost.teamMode,
|
|
3170
|
+
audit: teamHost.audit,
|
|
3171
|
+
teamMember: teamHost.teamMember,
|
|
3172
|
+
sessionShares: createSessionShares(openSessions, allDormant),
|
|
1215
3173
|
port: options.webPort,
|
|
3174
|
+
...options.host === void 0 ? {} : { host: options.host },
|
|
3175
|
+
...sandboxIdentity === void 0 ? {} : {
|
|
3176
|
+
publicRoutes: false,
|
|
3177
|
+
humanInputAttribution: false,
|
|
3178
|
+
webSocketMaxPayload: CONTAINED_MAX_PAYLOAD_BYTES
|
|
3179
|
+
},
|
|
1216
3180
|
headlessHub: hub,
|
|
1217
3181
|
token: attachToken,
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
3182
|
+
sessionMcp: createSessionMcpServer({
|
|
3183
|
+
stateDir: serverDirectory,
|
|
3184
|
+
publicOrigin: remoteOrigin
|
|
3185
|
+
}),
|
|
3186
|
+
createGeneralSession,
|
|
3187
|
+
ensureHomeCoordinator: (request) => coordinatorAdmission.ensureHome(request),
|
|
3188
|
+
addCoordinator: (workspaceId, profile) => coordinatorAdmission.add(workspaceId, profile),
|
|
3189
|
+
setSessionRole: (sessionId, coordinator) => coordinatorAdmission.setRole(sessionId, coordinator),
|
|
1221
3190
|
isSessionPersisted: (sessionId, cwd) => openSessions.list().some((record) => record.sessionId === sessionId && record.cwd === cwd),
|
|
1222
|
-
|
|
3191
|
+
declaredWorkspaces: async (from) => {
|
|
3192
|
+
const root = await resolveWorkspaceRoot(from);
|
|
3193
|
+
const { declarations, notices } = await readWorkspaceDeclarations({
|
|
3194
|
+
fs: hostFiles,
|
|
3195
|
+
repositoryRoot: root,
|
|
3196
|
+
context: BACKGROUND_CONTEXT
|
|
3197
|
+
});
|
|
3198
|
+
for (const message of notices) {
|
|
3199
|
+
if (declarationNotices.has(message)) continue;
|
|
3200
|
+
declarationNotices.add(message);
|
|
3201
|
+
notice(message);
|
|
3202
|
+
}
|
|
3203
|
+
const marker = readWorkspaceMarker(root);
|
|
3204
|
+
return {
|
|
3205
|
+
root,
|
|
3206
|
+
declarations: declarations.map(({ name, instructions }) => {
|
|
3207
|
+
const record = workspaces.list().find((record) => record.declaration === name && (record.root === root || marker !== void 0 && (record.repositoryId ?? record.id) === marker));
|
|
3208
|
+
return {
|
|
3209
|
+
name,
|
|
3210
|
+
instructions,
|
|
3211
|
+
...record === void 0 ? {} : { workspaceId: record.id }
|
|
3212
|
+
};
|
|
3213
|
+
})
|
|
3214
|
+
};
|
|
3215
|
+
},
|
|
3216
|
+
setWorkspaceInstructions: async (workspaceId, instructions) => {
|
|
3217
|
+
if (!workspaces.list().some((record) => record.id === workspaceId)) return { error: "Workspace not found." };
|
|
3218
|
+
if (workspaces.list().some((record) => record.id === workspaceId && record.kind === "session")) return { error: "The session backing workspace is managed by Po." };
|
|
3219
|
+
workspaces.setInstructions(workspaceId, instructions || void 0);
|
|
3220
|
+
const record = workspaces.list().find((record) => record.id === workspaceId);
|
|
3221
|
+
if (record === void 0) return { error: "Workspace not found." };
|
|
3222
|
+
const entry = hubEntry(record, hub.workspaces().find((workspace) => workspace.id === workspaceId)?.available === true);
|
|
3223
|
+
hub.registerWorkspace(entry);
|
|
3224
|
+
return { workspace: entry };
|
|
3225
|
+
},
|
|
3226
|
+
setWorkspaceSandbox: async (workspaceId, sandbox) => {
|
|
3227
|
+
const record = workspaces.list().find((workspace) => workspace.id === workspaceId);
|
|
3228
|
+
if (record === void 0) return { error: "Workspace not found." };
|
|
3229
|
+
if (record.kind === "session") return { error: "The session backing workspace is managed by Po." };
|
|
3230
|
+
if (sandbox !== null && sandboxes.get(sandbox) === void 0) return { error: `Sandbox provider '${sandbox}' is not registered.` };
|
|
3231
|
+
const blocked = sandbox === null || sandbox === record.sandbox ? void 0 : sandboxes.get(sandbox)?.availability?.();
|
|
3232
|
+
if (blocked !== void 0 && !blocked.available) return { error: blocked.reason };
|
|
3233
|
+
const previous = record.sandbox;
|
|
3234
|
+
const switchingOff = previous !== void 0 && previous !== (sandbox ?? void 0);
|
|
3235
|
+
const switchingOn = sandbox !== null && sandbox !== previous;
|
|
3236
|
+
const offProvider = switchingOff ? handoffProvider(sandboxes.get(previous)) : void 0;
|
|
3237
|
+
const onProvider = switchingOn ? handoffProvider(sandboxes.get(sandbox)) : void 0;
|
|
3238
|
+
const failed = (error) => {
|
|
3239
|
+
sandboxTransitions.set(workspaceId, {
|
|
3240
|
+
sandboxState: "failed",
|
|
3241
|
+
sandboxReason: errorMessage(error)
|
|
3242
|
+
});
|
|
3243
|
+
refreshWorkspace(workspaceId);
|
|
3244
|
+
};
|
|
3245
|
+
if (offProvider !== void 0 && handoff !== void 0) {
|
|
3246
|
+
sandboxTransitions.set(workspaceId, { sandboxState: "stopping" });
|
|
3247
|
+
refreshWorkspace(workspaceId);
|
|
3248
|
+
try {
|
|
3249
|
+
await router?.release(workspaceId);
|
|
3250
|
+
for (const sessionId of await handoff.switchOff(record, offProvider)) hub.notifyDormantChanged(sessionId);
|
|
3251
|
+
} catch (error) {
|
|
3252
|
+
failed(error);
|
|
3253
|
+
router?.start();
|
|
3254
|
+
return { error: `The workspace's sessions could not leave its sandbox: ${errorMessage(error)}` };
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
sandboxTransitions.delete(workspaceId);
|
|
3258
|
+
workspaces.setSandbox(workspaceId, sandbox ?? void 0);
|
|
3259
|
+
const updated = workspaces.list().find((workspace) => workspace.id === workspaceId) ?? record;
|
|
3260
|
+
if (updated.sandbox !== void 0) {
|
|
3261
|
+
if (onProvider !== void 0 && handoff !== void 0) sandboxTransitions.set(workspaceId, { sandboxState: "starting" });
|
|
3262
|
+
const entry = hubEntry(updated, router?.connected(workspaceId) === true);
|
|
3263
|
+
hub.registerWorkspace(entry);
|
|
3264
|
+
hostServicesChanged();
|
|
3265
|
+
if (onProvider !== void 0 && handoff !== void 0) {
|
|
3266
|
+
try {
|
|
3267
|
+
for (const sessionId of await handoff.switchOn(updated, onProvider)) hub.notifySessionRemoved(sessionId);
|
|
3268
|
+
} catch (error) {
|
|
3269
|
+
failed(error);
|
|
3270
|
+
return { error: `The workspace's sandbox did not start: ${errorMessage(error)}` };
|
|
3271
|
+
}
|
|
3272
|
+
router?.start();
|
|
3273
|
+
}
|
|
3274
|
+
return { workspace: hub.workspaces().find((workspace) => workspace.id === workspaceId) ?? entry };
|
|
3275
|
+
}
|
|
3276
|
+
if (servedWorkspaces.has(workspaceId)) {
|
|
3277
|
+
const entry = hubEntry(updated, true);
|
|
3278
|
+
hub.registerWorkspace(entry);
|
|
3279
|
+
hostServicesChanged();
|
|
3280
|
+
return { workspace: entry };
|
|
3281
|
+
}
|
|
3282
|
+
hub.registerWorkspace(hubEntry(updated, false));
|
|
3283
|
+
const admitted = await admitWorkspace(updated.root, {
|
|
3284
|
+
declaration: updated.declaration,
|
|
3285
|
+
workspaceId: updated.id
|
|
3286
|
+
});
|
|
3287
|
+
return { workspace: hub.workspaces().find((workspace) => workspace.id === workspaceId) ?? admitted };
|
|
3288
|
+
},
|
|
3289
|
+
workspaceHistory: async (workspaceId) => router?.contains(workspaceId) === true ? await router.history(workspaceId) : (await savedHistory(workspaceId)).map((record) => record.summary),
|
|
1223
3290
|
resumeWorkspaceSession: async (workspaceId, targetSessionId) => {
|
|
3291
|
+
if (router?.contains(workspaceId) === true) return router.resumeWorkspace(workspaceId, targetSessionId);
|
|
1224
3292
|
const key = `${workspaceId}\0${targetSessionId}`;
|
|
1225
3293
|
const pending = workspaceResumes.get(key);
|
|
1226
3294
|
if (pending) return pending;
|
|
1227
3295
|
const resume = (async () => {
|
|
1228
3296
|
const target = (await savedHistory(workspaceId)).find((item) => item.summary.id === targetSessionId);
|
|
1229
3297
|
if (!target) throw new Error("Saved Pi 1.0 session not found in this workspace. Earlier sessions cannot be resumed.");
|
|
1230
|
-
|
|
3298
|
+
if (!await pathExists(hostFiles, target.execution.cwd, BACKGROUND_CONTEXT)) throw new Error(CONTAINER_WORKTREE_GONE);
|
|
3299
|
+
await validateExecution(target.execution, workspaceId);
|
|
1231
3300
|
await openSession({
|
|
1232
3301
|
cwd: target.execution.cwd,
|
|
1233
3302
|
name: target.summary.name ?? "untitled",
|
|
1234
3303
|
...target.execution.parentSessionId ? { parentSessionId: target.execution.parentSessionId } : {},
|
|
1235
|
-
...target.execution.sessionProvenance ? { sessionProvenance: target.execution.sessionProvenance } : {}
|
|
3304
|
+
...target.execution.sessionProvenance ? { sessionProvenance: target.execution.sessionProvenance } : {},
|
|
3305
|
+
...target.execution.interaction === void 0 ? {} : { interaction: target.execution.interaction }
|
|
1236
3306
|
}, target.summary.id, workspaceId);
|
|
1237
3307
|
return target.summary.id;
|
|
1238
3308
|
})();
|
|
@@ -1243,15 +3313,17 @@ async function runServerRuntime(options, runtime) {
|
|
|
1243
3313
|
workspaceResumes.delete(key);
|
|
1244
3314
|
}
|
|
1245
3315
|
},
|
|
1246
|
-
sessionHistory: (session) => {
|
|
3316
|
+
sessionHistory: async (session) => {
|
|
3317
|
+
if (router?.mirror(session.id) !== void 0) return router.sessionHistory(session.id);
|
|
1247
3318
|
const workspaceRoot = hub.workspaces().find((workspace) => workspace.id === session.workspaceId)?.root;
|
|
1248
3319
|
if (!workspaceRoot) throw new Error("Session workspace not found.");
|
|
1249
|
-
return listSavedSessions(platform.sessions, workspaceRoot,
|
|
3320
|
+
return listSavedSessions(platform.sessions, workspaceRoot, await sessionRemoval.hidden(hub.snapshot().map((active) => active.id)), session.workspaceId, unreadableHistory);
|
|
1250
3321
|
},
|
|
1251
|
-
readDormantTranscript: (record, request, context) => {
|
|
3322
|
+
readDormantTranscript: async (record, request, context) => {
|
|
3323
|
+
if (router?.owns(record.sessionId) === true) return router.readTranscript(record.sessionId, request);
|
|
1252
3324
|
const workspaceRoot = hub.workspaces().find((workspace) => workspace.id === record.workspaceId)?.root;
|
|
1253
3325
|
if (!workspaceRoot || record.groupingRoot !== void 0 && record.groupingRoot !== workspaceRoot) throw new Error("Saved transcript unavailable.");
|
|
1254
|
-
const owner =
|
|
3326
|
+
const owner = await resolveWorkspaceRoot(record.cwd);
|
|
1255
3327
|
if (record.repoRoot !== void 0 && record.repoRoot !== owner) throw new Error("Saved transcript checkout has changed.");
|
|
1256
3328
|
return readSqliteTranscript(platform.sessions, record.sessionId, request, context, {
|
|
1257
3329
|
sessionId: record.sessionId,
|
|
@@ -1260,7 +3332,19 @@ async function runServerRuntime(options, runtime) {
|
|
|
1260
3332
|
groupingRoot: workspaceRoot
|
|
1261
3333
|
});
|
|
1262
3334
|
},
|
|
3335
|
+
moveSession: (sessionId, workspaceId) => {
|
|
3336
|
+
if (hub.lifecycle.opening(sessionId) !== void 0 || reviving.has(sessionId)) return Promise.reject(/* @__PURE__ */ new Error("The session is already reopening."));
|
|
3337
|
+
if (router?.owns(sessionId) === true) return Promise.reject(/* @__PURE__ */ new Error("Container sessions cannot be moved."));
|
|
3338
|
+
const moving = coordinatorAdmission.moveSession(sessionId, workspaceId);
|
|
3339
|
+
reviving.set(sessionId, { promise: moving });
|
|
3340
|
+
moving.finally(() => reviving.delete(sessionId)).catch(() => void 0);
|
|
3341
|
+
return moving;
|
|
3342
|
+
},
|
|
1263
3343
|
restartSession: async (session) => {
|
|
3344
|
+
if (router?.mirror(session.id) !== void 0) {
|
|
3345
|
+
await router.restart(session.id);
|
|
3346
|
+
return;
|
|
3347
|
+
}
|
|
1264
3348
|
const record = openSessions.list().find((entry) => entry.sessionId === session.id);
|
|
1265
3349
|
if (!hub.workspaces().find((workspace) => workspace.id === session.workspaceId && workspace.available !== false)?.root) throw new Error("Session workspace not found.");
|
|
1266
3350
|
await hub.closeSession(session.id);
|
|
@@ -1269,19 +3353,22 @@ async function runServerRuntime(options, runtime) {
|
|
|
1269
3353
|
cwd: session.cwd,
|
|
1270
3354
|
name: session.name,
|
|
1271
3355
|
...session.parentSessionId === void 0 ? {} : { parentSessionId: session.parentSessionId },
|
|
1272
|
-
...session.sessionProvenance === void 0 ? {} : { sessionProvenance: session.sessionProvenance }
|
|
3356
|
+
...session.sessionProvenance === void 0 ? {} : { sessionProvenance: session.sessionProvenance },
|
|
3357
|
+
...session.interaction === void 0 ? {} : { interaction: session.interaction },
|
|
3358
|
+
...session.startedBy === void 0 ? {} : { startedBy: session.startedBy }
|
|
1273
3359
|
}, session.id, session.workspaceId);
|
|
1274
3360
|
} catch (error) {
|
|
1275
3361
|
if (record !== void 0) openSessions.add(record);
|
|
1276
|
-
throw error;
|
|
3362
|
+
throw asError(error);
|
|
1277
3363
|
}
|
|
1278
3364
|
},
|
|
1279
3365
|
resumeSession: async (session, targetSessionId) => {
|
|
3366
|
+
if (router?.mirror(session.id) !== void 0) return router.resume(session.id, targetSessionId);
|
|
1280
3367
|
const workspaceId = session.workspaceId;
|
|
1281
3368
|
if (!workspaceId || !hub.workspaces().some((workspace) => workspace.id === workspaceId)) throw new Error("Session workspace not found.");
|
|
1282
3369
|
const target = (await savedHistory(workspaceId)).find((item) => item.summary.id === targetSessionId);
|
|
1283
3370
|
if (!target) throw new Error("Saved Pi 1.0 session not found in this workspace. Earlier sessions cannot be resumed.");
|
|
1284
|
-
validateExecution(target.execution, workspaceId);
|
|
3371
|
+
await validateExecution(target.execution, workspaceId);
|
|
1285
3372
|
const closedRecord = openSessions.list().find((entry) => entry.sessionId === session.id);
|
|
1286
3373
|
await hub.closeSession(session.id);
|
|
1287
3374
|
try {
|
|
@@ -1289,26 +3376,56 @@ async function runServerRuntime(options, runtime) {
|
|
|
1289
3376
|
cwd: target.execution.cwd,
|
|
1290
3377
|
name: target.summary.name ?? "untitled",
|
|
1291
3378
|
...target.execution.parentSessionId ? { parentSessionId: target.execution.parentSessionId } : {},
|
|
1292
|
-
...target.execution.sessionProvenance ? { sessionProvenance: target.execution.sessionProvenance } : {}
|
|
3379
|
+
...target.execution.sessionProvenance ? { sessionProvenance: target.execution.sessionProvenance } : {},
|
|
3380
|
+
...target.execution.interaction === void 0 ? {} : { interaction: target.execution.interaction }
|
|
1293
3381
|
}, target.summary.id, workspaceId);
|
|
1294
3382
|
} catch (error) {
|
|
1295
3383
|
if (closedRecord !== void 0) openSessions.add(closedRecord);
|
|
1296
|
-
throw error;
|
|
3384
|
+
throw asError(error);
|
|
1297
3385
|
}
|
|
1298
3386
|
return target.summary.id;
|
|
1299
3387
|
},
|
|
1300
|
-
dormantSessions:
|
|
1301
|
-
removeDormantSession: (record) =>
|
|
1302
|
-
|
|
3388
|
+
dormantSessions: allDormant,
|
|
3389
|
+
removeDormantSession: (record) => markSessionRemoved(record.sessionId),
|
|
3390
|
+
removeSessionFiles: markSessionRemoved,
|
|
3391
|
+
...sandboxIdentity === void 0 ? {
|
|
3392
|
+
removedSessions: async (workspaceId) => sessionRemoval.list(workspaceId),
|
|
3393
|
+
restoreRemovedSession: async (workspaceId, sessionId) => sessionRemoval.restore(workspaceId, sessionId)
|
|
3394
|
+
} : {},
|
|
3395
|
+
setDormantGroups: async (record, groups) => {
|
|
3396
|
+
if (router?.owns(record.sessionId) === true) return router.setDormantGroups(record.sessionId, groups);
|
|
1303
3397
|
if (!openSessions.add({
|
|
1304
3398
|
...record,
|
|
1305
3399
|
groups: [...groups]
|
|
1306
3400
|
})) throw new Error("The session groups could not be durably recorded.");
|
|
1307
3401
|
},
|
|
1308
|
-
|
|
3402
|
+
setDormantBot: async (record, bot, revision) => {
|
|
3403
|
+
if (router?.owns(record.sessionId) === true) return router.setDormantBot(record.sessionId, bot, revision);
|
|
3404
|
+
const stored = openSessions.list().find((entry) => entry.sessionId === record.sessionId);
|
|
3405
|
+
if (stored?.bot === void 0 || (stored.botRevision ?? 0) !== revision - 1) throw new Error("The bot settings changed. Reload and try again.");
|
|
3406
|
+
if (!openSessions.add({
|
|
3407
|
+
...stored,
|
|
3408
|
+
bot: bot === null ? {} : { ...bot },
|
|
3409
|
+
botRevision: revision
|
|
3410
|
+
})) throw new Error("The bot settings could not be durably recorded.");
|
|
3411
|
+
},
|
|
3412
|
+
reviveSession: async (record, options) => {
|
|
3413
|
+
if (options?.automatic) return await reviveSession(record.sessionId, options) === "paused" ? "paused" : void 0;
|
|
3414
|
+
await reviveRecord(record);
|
|
3415
|
+
},
|
|
3416
|
+
acceptNetworkRelay: async (socket, url) => {
|
|
3417
|
+
if (!remoteRuntime?.acceptNetworkRelay) {
|
|
3418
|
+
socket.close();
|
|
3419
|
+
return;
|
|
3420
|
+
}
|
|
3421
|
+
await remoteRuntime.acceptNetworkRelay(socket, url);
|
|
3422
|
+
},
|
|
3423
|
+
requestNetwork: (request) => remoteRuntime?.requestNetwork?.(request) ?? Promise.resolve(void 0),
|
|
1309
3424
|
requestAsset: (request) => webCompositions?.request(request) ?? Promise.resolve(void 0),
|
|
1310
|
-
|
|
1311
|
-
|
|
3425
|
+
remoteCompositions: (pluginIds) => publishRemoteCompositions(pluginIds),
|
|
3426
|
+
compositions: async ({ nativeClient }) => {
|
|
3427
|
+
if (nativeClient) await requestNativeBuild();
|
|
3428
|
+
const workspaces = hub.workspaces().filter((workspace) => workspace.sandbox === void 0);
|
|
1312
3429
|
const decision = {
|
|
1313
3430
|
cwd: baseCwd,
|
|
1314
3431
|
launchWorkspaceId,
|
|
@@ -1317,26 +3434,41 @@ async function runServerRuntime(options, runtime) {
|
|
|
1317
3434
|
environment: baseEnvironment,
|
|
1318
3435
|
notice
|
|
1319
3436
|
};
|
|
3437
|
+
const displayName = hostDisplayName(os.hostname());
|
|
1320
3438
|
return {
|
|
1321
|
-
|
|
1322
|
-
|
|
3439
|
+
...await remoteRuntime?.networkComposition?.(),
|
|
3440
|
+
...displayName ? { displayName } : {},
|
|
3441
|
+
host: compositionToWire(webCompositions?.get({ scope: "host" })),
|
|
3442
|
+
nativeHost: compositionToWire(webCompositions?.getNative({ scope: "host" })),
|
|
1323
3443
|
publicKey: webCompositions?.publicKey(),
|
|
1324
3444
|
shell: webCompositions?.shellTrust(),
|
|
1325
|
-
template: resolveWebTemplateDecision(decision),
|
|
1326
|
-
nativeTemplate: resolveWebTemplateDecision({
|
|
3445
|
+
template: templateToWire(resolveWebTemplateDecision(decision)),
|
|
3446
|
+
nativeTemplate: templateToWire(resolveWebTemplateDecision({
|
|
1327
3447
|
...decision,
|
|
1328
3448
|
host: "native"
|
|
1329
|
-
}),
|
|
1330
|
-
workspaces: workspaces.map((workspace) =>
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
3449
|
+
})),
|
|
3450
|
+
workspaces: await Promise.all(hub.workspaces().map(async (workspace) => {
|
|
3451
|
+
if (workspace.sandbox !== void 0) return {
|
|
3452
|
+
...workspace,
|
|
3453
|
+
webComposition: null,
|
|
3454
|
+
nativeComposition: null
|
|
3455
|
+
};
|
|
3456
|
+
const { providers } = await remoteRuntime?.workspaceProviders?.(workspace.id) ?? {};
|
|
3457
|
+
return {
|
|
3458
|
+
...workspace,
|
|
3459
|
+
...providers === void 0 ? {} : { providers: providers.map((provider) => ({
|
|
3460
|
+
...provider,
|
|
3461
|
+
operations: provider.operations.map(poScopedToWire)
|
|
3462
|
+
})) },
|
|
3463
|
+
webComposition: compositionToWire(webCompositions?.get({
|
|
3464
|
+
scope: "workspace",
|
|
3465
|
+
workspaceId: workspace.id
|
|
3466
|
+
})),
|
|
3467
|
+
nativeComposition: compositionToWire(webCompositions?.getNative({
|
|
3468
|
+
scope: "workspace",
|
|
3469
|
+
workspaceId: workspace.id
|
|
3470
|
+
}))
|
|
3471
|
+
};
|
|
1340
3472
|
}))
|
|
1341
3473
|
};
|
|
1342
3474
|
},
|
|
@@ -1344,67 +3476,195 @@ async function runServerRuntime(options, runtime) {
|
|
|
1344
3476
|
onNotice: notice
|
|
1345
3477
|
});
|
|
1346
3478
|
notice(`protocol on ${cockpit.url}/api/ws`);
|
|
3479
|
+
remoteRuntime?.startNetwork?.().catch(() => notice("Account network unavailable."));
|
|
3480
|
+
router?.start();
|
|
3481
|
+
if (automation === void 0 && sandboxIdentity === void 0) sessionRemoval.start();
|
|
1347
3482
|
let resolveShutdown;
|
|
1348
3483
|
const shutdown = new Promise((resolve) => {
|
|
1349
3484
|
resolveShutdown = resolve;
|
|
1350
3485
|
});
|
|
1351
3486
|
requestRestart = () => {
|
|
1352
|
-
const ids = openSessions.list().map((record) => record.sessionId).filter((id) =>
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
|
|
3487
|
+
const ids = openSessions.list().map((record) => record.sessionId).filter((id) => recoverySessionIds.has(id));
|
|
3488
|
+
persistRecovery = () => {};
|
|
3489
|
+
const details = {
|
|
3490
|
+
crashRestores: restorePlan.crashRestores,
|
|
3491
|
+
...recoveryTunnel === void 0 ? {} : { tunnel: recoveryTunnel }
|
|
3492
|
+
};
|
|
3493
|
+
recoveryWrites = recoveryWrites.then(async () => {
|
|
3494
|
+
try {
|
|
3495
|
+
await writeRecycleFile(serverDirectory, ids, details);
|
|
3496
|
+
} catch (error) {
|
|
3497
|
+
notice(`Could not write the recycle file: ${error instanceof Error ? error.message : String(error)}`);
|
|
3498
|
+
}
|
|
3499
|
+
notice(`Restarting at idle to release superseded extension versions (${String(ids.length)} sessions reopen).`);
|
|
3500
|
+
resolveShutdown(75);
|
|
3501
|
+
});
|
|
3502
|
+
};
|
|
3503
|
+
const startupCandidates = [.../* @__PURE__ */ new Set([...allDormant().filter((record) => record.bot !== void 0).map((record) => record.sessionId), ...restorePlan.blocked ? recycled?.sessionIds ?? [] : restorePlan.sessionIds])].filter((sessionId) => !startupRecoveryIds.has(sessionId));
|
|
3504
|
+
const startupSessionIds = restorePlan.blocked ? [] : startupCandidates;
|
|
3505
|
+
for (const sessionId of startupSessionIds) {
|
|
3506
|
+
recoverySessionIds.add(sessionId);
|
|
3507
|
+
startupRecoveryIds.add(sessionId);
|
|
3508
|
+
}
|
|
3509
|
+
persistRecovery();
|
|
3510
|
+
if (restorePlan.blocked) {
|
|
3511
|
+
for (const id of startupCandidates) pauseRevival(id);
|
|
3512
|
+
notice("Automatic crash restore paused after two attempts in 15 minutes. Sessions remain dormant; use Wake to retry.");
|
|
3513
|
+
}
|
|
3514
|
+
const stop = () => {
|
|
3515
|
+
cleanShutdown = signal.reason !== "crash";
|
|
3516
|
+
resolveShutdown(0);
|
|
1360
3517
|
};
|
|
1361
|
-
await reopenRecycledSessions(serverDirectory, async (sessionId) => {
|
|
1362
|
-
const record = openSessions.list().find((entry) => entry.sessionId === sessionId);
|
|
1363
|
-
if (record === void 0) throw new Error("its record is gone.");
|
|
1364
|
-
await reviveRecord(record);
|
|
1365
|
-
}, (sessionId, error) => notice(`Session '${sessionId}' did not reopen after the restart: ${error instanceof Error ? error.message : String(error)}`));
|
|
1366
|
-
idleRestart.poke();
|
|
1367
|
-
const stop = () => resolveShutdown(0);
|
|
1368
3518
|
signal.addEventListener("abort", stop, { once: true });
|
|
1369
3519
|
if (signal.aborted) stop();
|
|
3520
|
+
recovering = true;
|
|
3521
|
+
const restoredSessions = (async () => {
|
|
3522
|
+
try {
|
|
3523
|
+
if (!restorePlan.blocked && startupSessionIds.length > 0 && !signal.aborted) await settleRecoveryWorkspaces?.();
|
|
3524
|
+
} finally {
|
|
3525
|
+
resolveRevivalReady();
|
|
3526
|
+
}
|
|
3527
|
+
return reopenRecycledSessions(serverDirectory, (sessionId) => enqueueRecovery(async () => {
|
|
3528
|
+
if (signal.aborted || shuttingDown || !recoverySessionIds.has(sessionId)) return;
|
|
3529
|
+
const record = allDormant().find((entry) => entry.sessionId === sessionId);
|
|
3530
|
+
try {
|
|
3531
|
+
if (record === void 0) throw new Error("its record is gone.");
|
|
3532
|
+
if (record.sessionProvenance === WORKFLOW_STEP_SESSION_PROVENANCE) {
|
|
3533
|
+
recoverySessionIds.delete(sessionId);
|
|
3534
|
+
return;
|
|
3535
|
+
}
|
|
3536
|
+
await reviveSession(sessionId, { automatic: true });
|
|
3537
|
+
} catch (error) {
|
|
3538
|
+
if (!hub.lifecycle.classify(error).retryable && !hub.session(sessionId)) recoverySessionIds.delete(sessionId);
|
|
3539
|
+
if (!revivalRetries.has(sessionId) && !signal.aborted && !shuttingDown) throw asError(error);
|
|
3540
|
+
} finally {
|
|
3541
|
+
persistRecovery();
|
|
3542
|
+
}
|
|
3543
|
+
}), (sessionId, error) => notice(`Session '${sessionId}' did not reopen after the restart: ${errorMessage(error)}`), {
|
|
3544
|
+
sessionIds: startupSessionIds,
|
|
3545
|
+
removeAfter: false
|
|
3546
|
+
});
|
|
3547
|
+
})().catch((error) => notice(`Crash restore failed: ${errorMessage(error)}`));
|
|
3548
|
+
restoredSessions.then(() => {
|
|
3549
|
+
directoryRestored = true;
|
|
3550
|
+
});
|
|
3551
|
+
let restoredTunnel;
|
|
3552
|
+
if (tunnelToRestore !== void 0 && !signal.aborted) restoredTunnel = remoteRuntime?.restoreTunnel(tunnelToRestore).then((result) => {
|
|
3553
|
+
if (!result.ok) notice(`Remote access did not restore: ${result.error}`);
|
|
3554
|
+
}).catch((error) => notice(`Remote access did not restore: ${String(error)}`)).finally(() => {
|
|
3555
|
+
recoveryTunnel = remoteRuntime?.tunnelIntent();
|
|
3556
|
+
persistRecovery();
|
|
3557
|
+
});
|
|
3558
|
+
const relayLink = relayLinkBinding?.();
|
|
3559
|
+
const relayToRestore = keptRelay?.link !== void 0 && keptRelay.link === relayLink;
|
|
3560
|
+
if (keptRelay !== void 0 && !relayToRestore) {
|
|
3561
|
+
notice("The Po Cloud relay was not turned back on because this computer is no longer on the same Po Cloud link.");
|
|
3562
|
+
relayWrites = relayWrites.then(() => keepRelayIntent(serverDirectory, void 0)).catch((error) => notice(`Could not save the Po Cloud relay state: ${String(error)}`));
|
|
3563
|
+
}
|
|
3564
|
+
const restoredRelay = relayToRestore && !signal.aborted ? remoteRuntime?.restoreRelay().then((result) => {
|
|
3565
|
+
if (!result.ok) notice(`The Po Cloud relay did not reconnect: ${result.error}`);
|
|
3566
|
+
}).catch((error) => notice(`The Po Cloud relay did not reconnect: ${String(error)}`)) : void 0;
|
|
3567
|
+
recoveryWork = Promise.allSettled([
|
|
3568
|
+
restoredSessions,
|
|
3569
|
+
restoredTunnel,
|
|
3570
|
+
restoredRelay
|
|
3571
|
+
]).then(() => {
|
|
3572
|
+
recovering = false;
|
|
3573
|
+
idleRestart.poke();
|
|
3574
|
+
});
|
|
3575
|
+
if (automation !== void 0 && !signal.aborted) automation({
|
|
3576
|
+
hub,
|
|
3577
|
+
sessionHost: (sessionId) => sessionManager.get(sessionId),
|
|
3578
|
+
openSession: (request) => openSession(request),
|
|
3579
|
+
closeSession: (sessionId) => closeManagedSession(sessionId),
|
|
3580
|
+
signal
|
|
3581
|
+
}).then((exitCode) => resolveShutdown(exitCode)).catch((error) => {
|
|
3582
|
+
notice(`Native automation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
3583
|
+
resolveShutdown(1);
|
|
3584
|
+
});
|
|
1370
3585
|
try {
|
|
1371
|
-
|
|
3586
|
+
const exitCode = await shutdown;
|
|
3587
|
+
if (exitCode === 0 && signal.reason !== "crash") cleanShutdown = true;
|
|
3588
|
+
return exitCode;
|
|
1372
3589
|
} finally {
|
|
1373
3590
|
signal.removeEventListener("abort", stop);
|
|
1374
3591
|
}
|
|
1375
3592
|
} finally {
|
|
1376
3593
|
shuttingDown = true;
|
|
3594
|
+
const stoppingRevivals = [...reviving.keys()].map((id) => cancelRevival(id));
|
|
3595
|
+
for (const id of revivalRetries.keys()) clearRevivalRetry(id);
|
|
3596
|
+
persistRecovery = () => {};
|
|
3597
|
+
await recoveryWrites;
|
|
3598
|
+
await relayWrites;
|
|
3599
|
+
const cleanUserStop = isCleanUserStop(cleanShutdown, signal);
|
|
3600
|
+
const sandboxesStopped = cleanUserStop && automation === void 0 ? withShutdownDeadline(() => stopSandboxProviders(sandboxes.list(), notice), "sandbox stop", SANDBOX_STOP_DEADLINE_MS).catch((error) => notice(`sandbox stop failed: ${error instanceof Error ? error.message : String(error)}`)) : Promise.resolve();
|
|
3601
|
+
if (cleanUserStop) try {
|
|
3602
|
+
await recoveryWrites;
|
|
3603
|
+
await removeRecycleFile(serverDirectory);
|
|
3604
|
+
await keepTunnelIntent(serverDirectory, recoveryTunnel);
|
|
3605
|
+
} catch (error) {
|
|
3606
|
+
notice(`Could not remove crash recovery state: ${String(error)}`);
|
|
3607
|
+
}
|
|
1377
3608
|
idleRestart.dispose();
|
|
1378
3609
|
stopIdleRestartPoke();
|
|
1379
3610
|
stopResourceMonitor();
|
|
1380
3611
|
executionBudget.close();
|
|
1381
3612
|
watcher.close();
|
|
3613
|
+
packageWatcher?.close();
|
|
1382
3614
|
stopPersistSessionNames();
|
|
3615
|
+
liveActivityPush?.stop();
|
|
3616
|
+
stopNativePush?.();
|
|
3617
|
+
for (const stop of stopSandboxWatches.splice(0)) stop();
|
|
3618
|
+
modelGateway?.dispose();
|
|
1383
3619
|
clearInterval(eventLoopMonitor);
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
3620
|
+
clearInterval(globalSettingsRefresh);
|
|
3621
|
+
teamHost.stop();
|
|
3622
|
+
const shutdownStack = createShutdownStack({ notice });
|
|
3623
|
+
shutdownStack.push("removed sessions sweep shutdown", () => sessionRemoval.stop());
|
|
3624
|
+
shutdownStack.push("shutdown telemetry", () => {
|
|
3625
|
+
stopRecoveryReports();
|
|
3626
|
+
return telemetry.recordEvent("po_server.shutdown");
|
|
3627
|
+
});
|
|
3628
|
+
shutdownStack.push("listener shutdown", () => cockpit?.close());
|
|
3629
|
+
shutdownStack.push("remote control shutdown", () => remoteRuntime?.close());
|
|
3630
|
+
shutdownStack.push("crash recovery shutdown", async () => {
|
|
3631
|
+
for (const result of await Promise.allSettled([
|
|
3632
|
+
recoveryWork,
|
|
3633
|
+
sandboxBotRecovery,
|
|
3634
|
+
...stoppingRevivals
|
|
3635
|
+
])) if (result.status === "rejected") notice(`Crash recovery shutdown failed: ${errorMessage(result.reason)}`);
|
|
3636
|
+
});
|
|
3637
|
+
shutdownStack.push("session manager shutdown", async () => {
|
|
1388
3638
|
await sessionManager.close();
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
3639
|
+
}, { timeoutMs: null });
|
|
3640
|
+
shutdownStack.push("sandbox router shutdown", () => router?.dispose());
|
|
3641
|
+
shutdownStack.push("sandbox stop wait", async () => {
|
|
3642
|
+
await sandboxesStopped;
|
|
3643
|
+
hostServicesStopping = true;
|
|
3644
|
+
}, { timeoutMs: null });
|
|
3645
|
+
shutdownStack.push("host package shutdown", () => hostServices.reconcile());
|
|
3646
|
+
shutdownStack.push("hub shutdown", () => hub.close());
|
|
3647
|
+
shutdownStack.push("receipt shutdown", () => requestReceipts.close());
|
|
3648
|
+
shutdownStack.push("computer use shutdown", () => computerUse?.close?.());
|
|
3649
|
+
shutdownStack.push("web composition shutdown", () => webCompositions?.close());
|
|
3650
|
+
shutdownStack.push("pending session cleanup", async () => {
|
|
3651
|
+
const pendingCleanups = [...pendingSessions.values()].map((setup) => runBoundedShutdownStep("pending session cleanup", () => setup.cleanup(), notice));
|
|
3652
|
+
pendingSessions.clear();
|
|
3653
|
+
await Promise.allSettled(pendingCleanups);
|
|
3654
|
+
}, { timeoutMs: null });
|
|
3655
|
+
shutdownStack.push("repository context cleanup", async () => {
|
|
3656
|
+
const contextCleanups = [...repositoryContexts.values()].map((context) => runBoundedShutdownStep("repository context cleanup", () => context.cleanup(), notice));
|
|
3657
|
+
repositoryContexts.clear();
|
|
3658
|
+
await Promise.allSettled(contextCleanups);
|
|
3659
|
+
}, { timeoutMs: null });
|
|
3660
|
+
shutdownStack.push("harness telemetry flush", () => harnessTelemetry.flush());
|
|
3661
|
+
shutdownStack.push("harness telemetry shutdown", () => harnessTelemetry.shutdown());
|
|
3662
|
+
shutdownStack.push("server telemetry flush", () => telemetry.flush());
|
|
3663
|
+
shutdownStack.push("server telemetry shutdown", () => telemetry.shutdown());
|
|
3664
|
+
await shutdownStack.runOrdered();
|
|
1405
3665
|
}
|
|
1406
3666
|
}
|
|
1407
3667
|
//#endregion
|
|
1408
|
-
export { runServerRuntime };
|
|
3668
|
+
export { bindCoordinatorMoves, cloudChatAcceptor, remoteProtocolAcceptor, runServerRuntime };
|
|
1409
3669
|
|
|
1410
3670
|
//# sourceMappingURL=runtime.mjs.map
|