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