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