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