@noopolis/daimon 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +307 -45
- package/dist/contracts/attentionContract.d.ts +117 -0
- package/dist/contracts/attentionContract.d.ts.map +1 -0
- package/dist/contracts/attentionContract.js +14 -0
- package/dist/contracts/canonicalJson.d.ts +3 -0
- package/dist/contracts/canonicalJson.d.ts.map +1 -0
- package/dist/contracts/canonicalJson.js +54 -0
- package/dist/contracts/grokWorkerContract.d.ts +74 -0
- package/dist/contracts/grokWorkerContract.d.ts.map +1 -0
- package/dist/contracts/grokWorkerContract.js +88 -0
- package/dist/contracts/organizationRuntimeContract.d.ts +765 -0
- package/dist/contracts/organizationRuntimeContract.d.ts.map +1 -0
- package/dist/contracts/organizationRuntimeContract.js +121 -0
- package/dist/contracts/runtimeContractManifest.d.ts +1615 -0
- package/dist/contracts/runtimeContractManifest.d.ts.map +1 -0
- package/dist/contracts/runtimeContractManifest.js +181 -0
- package/dist/core/credentialRedaction.d.ts +4 -0
- package/dist/core/credentialRedaction.d.ts.map +1 -0
- package/dist/core/credentialRedaction.js +28 -0
- package/dist/core/siblingBuildFreshness.d.ts +21 -0
- package/dist/core/siblingBuildFreshness.d.ts.map +1 -0
- package/dist/core/siblingBuildFreshness.js +25 -0
- package/dist/core/types.d.ts +10 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/examples/exampleCausalId.d.ts +3 -0
- package/dist/examples/exampleCausalId.d.ts.map +1 -0
- package/dist/examples/exampleCausalId.js +8 -0
- package/dist/examples/jungian-play-org.js +3 -2
- package/dist/examples/jungian-triad-org.js +3 -2
- package/dist/examples/jungianPlayAgent.d.ts +1 -1
- package/dist/examples/jungianPlayAgent.d.ts.map +1 -1
- package/dist/examples/jungianPlayAgent.js +1 -1
- package/dist/examples/jungianProfiles.d.ts +1 -1
- package/dist/examples/jungianProfiles.d.ts.map +1 -1
- package/dist/examples/jungianTriadProfiles.d.ts +1 -1
- package/dist/examples/jungianTriadProfiles.d.ts.map +1 -1
- package/dist/examples/pi-agent.js +3 -2
- package/dist/examples/pi-memory-org.js +6 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/mcp/toolServer.d.ts +31 -0
- package/dist/mcp/toolServer.d.ts.map +1 -0
- package/dist/mcp/toolServer.js +145 -0
- package/dist/observability/causalEvents.d.ts +118 -0
- package/dist/observability/causalEvents.d.ts.map +1 -0
- package/dist/observability/causalEvents.js +223 -0
- package/dist/observability/controlCausal.d.ts +117 -0
- package/dist/observability/controlCausal.d.ts.map +1 -0
- package/dist/observability/controlCausal.js +107 -0
- package/dist/observability/emitCausalFixture.d.ts +25 -0
- package/dist/observability/emitCausalFixture.d.ts.map +1 -0
- package/dist/observability/emitCausalFixture.js +98 -0
- package/dist/observability/index.d.ts +2 -0
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +2 -0
- package/dist/observability/orgObserver.d.ts.map +1 -1
- package/dist/observability/orgObserver.js +3 -3
- package/dist/pi/agyHeadlessResult.d.ts +60 -0
- package/dist/pi/agyHeadlessResult.d.ts.map +1 -0
- package/dist/pi/agyHeadlessResult.js +95 -0
- package/dist/pi/cliChildOutput.d.ts +67 -0
- package/dist/pi/cliChildOutput.d.ts.map +1 -0
- package/dist/pi/cliChildOutput.js +269 -0
- package/dist/pi/cliEngineRun.d.ts +16 -0
- package/dist/pi/cliEngineRun.d.ts.map +1 -0
- package/dist/pi/cliEngineRun.js +27 -0
- package/dist/pi/cliEngineSpawn.d.ts +55 -0
- package/dist/pi/cliEngineSpawn.d.ts.map +1 -0
- package/dist/pi/cliEngineSpawn.js +164 -0
- package/dist/pi/cliEnvironment.d.ts +12 -0
- package/dist/pi/cliEnvironment.d.ts.map +1 -0
- package/dist/pi/cliEnvironment.js +32 -0
- package/dist/pi/cliMcpRegistration.d.ts +61 -0
- package/dist/pi/cliMcpRegistration.d.ts.map +1 -0
- package/dist/pi/cliMcpRegistration.js +75 -0
- package/dist/pi/cliProcess.d.ts +7 -0
- package/dist/pi/cliProcess.d.ts.map +1 -0
- package/dist/pi/cliProcess.js +132 -0
- package/dist/pi/cliSession.d.ts +106 -0
- package/dist/pi/cliSession.d.ts.map +1 -0
- package/dist/pi/cliSession.js +379 -0
- package/dist/pi/cliTurnMetering.d.ts +60 -0
- package/dist/pi/cliTurnMetering.d.ts.map +1 -0
- package/dist/pi/cliTurnMetering.js +60 -0
- package/dist/pi/codexFilesystemRules.d.ts +3 -0
- package/dist/pi/codexFilesystemRules.d.ts.map +1 -0
- package/dist/pi/codexFilesystemRules.js +28 -0
- package/dist/pi/codexHeadlessResult.d.ts +68 -0
- package/dist/pi/codexHeadlessResult.d.ts.map +1 -0
- package/dist/pi/codexHeadlessResult.js +122 -0
- package/dist/pi/codexRolloutUsage.d.ts +95 -0
- package/dist/pi/codexRolloutUsage.d.ts.map +1 -0
- package/dist/pi/codexRolloutUsage.js +221 -0
- package/dist/pi/engineWakeLimits.d.ts +39 -0
- package/dist/pi/engineWakeLimits.d.ts.map +1 -0
- package/dist/pi/engineWakeLimits.js +55 -0
- package/dist/pi/grokHeadlessResult.d.ts +36 -0
- package/dist/pi/grokHeadlessResult.d.ts.map +1 -0
- package/dist/pi/grokHeadlessResult.js +118 -0
- package/dist/pi/grokHomeMcpRegistration.d.ts +21 -0
- package/dist/pi/grokHomeMcpRegistration.d.ts.map +1 -0
- package/dist/pi/grokHomeMcpRegistration.js +57 -0
- package/dist/pi/grokSandbox.d.ts +11 -0
- package/dist/pi/grokSandbox.d.ts.map +1 -0
- package/dist/pi/grokSandbox.js +216 -0
- package/dist/pi/grokStreamUsage.d.ts +31 -0
- package/dist/pi/grokStreamUsage.d.ts.map +1 -0
- package/dist/pi/grokStreamUsage.js +51 -0
- package/dist/pi/index.d.ts +5 -0
- package/dist/pi/index.d.ts.map +1 -1
- package/dist/pi/index.js +5 -0
- package/dist/pi/memoryTools.d.ts +55 -1
- package/dist/pi/memoryTools.d.ts.map +1 -1
- package/dist/pi/memoryTools.js +144 -24
- package/dist/pi/modelRegistry.d.ts +13 -0
- package/dist/pi/modelRegistry.d.ts.map +1 -0
- package/dist/pi/modelRegistry.js +19 -0
- package/dist/pi/piAgentHandle.d.ts +46 -0
- package/dist/pi/piAgentHandle.d.ts.map +1 -0
- package/dist/pi/piAgentHandle.js +351 -0
- package/dist/pi/piAgentWakeSupport.d.ts +103 -0
- package/dist/pi/piAgentWakeSupport.d.ts.map +1 -0
- package/dist/pi/piAgentWakeSupport.js +151 -0
- package/dist/pi/piHarness.d.ts +40 -5
- package/dist/pi/piHarness.d.ts.map +1 -1
- package/dist/pi/piHarness.js +151 -256
- package/dist/pi/prompts.d.ts +10 -0
- package/dist/pi/prompts.d.ts.map +1 -0
- package/dist/pi/prompts.js +63 -0
- package/dist/pi/rawTrainingCapture.d.ts +59 -0
- package/dist/pi/rawTrainingCapture.d.ts.map +1 -0
- package/dist/pi/rawTrainingCapture.js +175 -0
- package/dist/pi/turnCausal.d.ts +73 -0
- package/dist/pi/turnCausal.d.ts.map +1 -0
- package/dist/pi/turnCausal.js +75 -0
- package/dist/pi/turnTrace.d.ts +128 -0
- package/dist/pi/turnTrace.d.ts.map +1 -0
- package/dist/pi/turnTrace.js +138 -0
- package/dist/pi/wakeAcceptance.d.ts +49 -0
- package/dist/pi/wakeAcceptance.d.ts.map +1 -0
- package/dist/pi/wakeAcceptance.js +281 -0
- package/dist/pi/wakeAcceptanceFs.d.ts +44 -0
- package/dist/pi/wakeAcceptanceFs.d.ts.map +1 -0
- package/dist/pi/wakeAcceptanceFs.js +318 -0
- package/dist/pi/wakeAcceptanceSchema.d.ts +75 -0
- package/dist/pi/wakeAcceptanceSchema.d.ts.map +1 -0
- package/dist/pi/wakeAcceptanceSchema.js +265 -0
- package/dist/pi/wakeModes.d.ts +9 -0
- package/dist/pi/wakeModes.d.ts.map +1 -0
- package/dist/pi/wakeModes.js +19 -0
- package/dist/pi/worldNudge.d.ts +22 -0
- package/dist/pi/worldNudge.d.ts.map +1 -0
- package/dist/pi/worldNudge.js +62 -0
- package/dist/pi/worldToolProtocol.d.ts +13 -0
- package/dist/pi/worldToolProtocol.d.ts.map +1 -0
- package/dist/pi/worldToolProtocol.js +49 -0
- package/dist/pi/worldTools.d.ts +32 -0
- package/dist/pi/worldTools.d.ts.map +1 -0
- package/dist/pi/worldTools.js +373 -0
- package/dist/pi/worldTrajectory.d.ts +52 -0
- package/dist/pi/worldTrajectory.d.ts.map +1 -0
- package/dist/pi/worldTrajectory.js +131 -0
- package/dist/runtime/agySubscriptionBootstrap.d.ts +16 -0
- package/dist/runtime/agySubscriptionBootstrap.d.ts.map +1 -0
- package/dist/runtime/agySubscriptionBootstrap.js +80 -0
- package/dist/runtime/agySubscriptionRealm.d.ts +38 -0
- package/dist/runtime/agySubscriptionRealm.d.ts.map +1 -0
- package/dist/runtime/agySubscriptionRealm.js +242 -0
- package/dist/runtime/attention.d.ts +21 -0
- package/dist/runtime/attention.d.ts.map +1 -0
- package/dist/runtime/attention.js +36 -0
- package/dist/runtime/attentionDispatcher.d.ts +66 -0
- package/dist/runtime/attentionDispatcher.d.ts.map +1 -0
- package/dist/runtime/attentionDispatcher.js +271 -0
- package/dist/runtime/cli.d.ts +7 -0
- package/dist/runtime/cli.d.ts.map +1 -0
- package/dist/runtime/cli.js +251 -0
- package/dist/runtime/codexSandboxProjection.d.ts +17 -0
- package/dist/runtime/codexSandboxProjection.d.ts.map +1 -0
- package/dist/runtime/codexSandboxProjection.js +40 -0
- package/dist/runtime/contract-manifest.json +1 -0
- package/dist/runtime/contract-manifest.sha256 +1 -0
- package/dist/runtime/contractManifest.d.ts +8 -0
- package/dist/runtime/contractManifest.d.ts.map +1 -0
- package/dist/runtime/contractManifest.js +4 -0
- package/dist/runtime/engineBrokerCapabilities.d.ts +30 -0
- package/dist/runtime/engineBrokerCapabilities.d.ts.map +1 -0
- package/dist/runtime/engineBrokerCapabilities.js +59 -0
- package/dist/runtime/engineBrokerControlClient.d.ts +44 -0
- package/dist/runtime/engineBrokerControlClient.d.ts.map +1 -0
- package/dist/runtime/engineBrokerControlClient.js +132 -0
- package/dist/runtime/engineBrokerCredentialJournal.d.ts +10 -0
- package/dist/runtime/engineBrokerCredentialJournal.d.ts.map +1 -0
- package/dist/runtime/engineBrokerCredentialJournal.js +17 -0
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts +52 -0
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts.map +1 -0
- package/dist/runtime/engineBrokerInferenceProtocol.js +65 -0
- package/dist/runtime/engineBrokerMcpCallLog.d.ts +160 -0
- package/dist/runtime/engineBrokerMcpCallLog.d.ts.map +1 -0
- package/dist/runtime/engineBrokerMcpCallLog.js +219 -0
- package/dist/runtime/engineBrokerMcpFacade.d.ts +56 -0
- package/dist/runtime/engineBrokerMcpFacade.d.ts.map +1 -0
- package/dist/runtime/engineBrokerMcpFacade.js +343 -0
- package/dist/runtime/engineBrokerNativeClient.d.ts +52 -0
- package/dist/runtime/engineBrokerNativeClient.d.ts.map +1 -0
- package/dist/runtime/engineBrokerNativeClient.js +151 -0
- package/dist/runtime/engineBrokerProtocol.d.ts +135 -0
- package/dist/runtime/engineBrokerProtocol.d.ts.map +1 -0
- package/dist/runtime/engineBrokerProtocol.js +274 -0
- package/dist/runtime/engineBrokerSealLedger.d.ts +70 -0
- package/dist/runtime/engineBrokerSealLedger.d.ts.map +1 -0
- package/dist/runtime/engineBrokerSealLedger.js +123 -0
- package/dist/runtime/engineBrokerService.d.ts +37 -0
- package/dist/runtime/engineBrokerService.d.ts.map +1 -0
- package/dist/runtime/engineBrokerService.js +138 -0
- package/dist/runtime/engineBrokerServiceCli.d.ts +5 -0
- package/dist/runtime/engineBrokerServiceCli.d.ts.map +1 -0
- package/dist/runtime/engineBrokerServiceCli.js +32 -0
- package/dist/runtime/engineBrokerServiceConfig.d.ts +50 -0
- package/dist/runtime/engineBrokerServiceConfig.d.ts.map +1 -0
- package/dist/runtime/engineBrokerServiceConfig.js +92 -0
- package/dist/runtime/engineBrokerSingleflight.d.ts +13 -0
- package/dist/runtime/engineBrokerSingleflight.d.ts.map +1 -0
- package/dist/runtime/engineBrokerSingleflight.js +24 -0
- package/dist/runtime/engineBrokerTurnAccounting.d.ts +76 -0
- package/dist/runtime/engineBrokerTurnAccounting.d.ts.map +1 -0
- package/dist/runtime/engineBrokerTurnAccounting.js +108 -0
- package/dist/runtime/engineBrokerTurnRegistry.d.ts +57 -0
- package/dist/runtime/engineBrokerTurnRegistry.d.ts.map +1 -0
- package/dist/runtime/engineBrokerTurnRegistry.js +158 -0
- package/dist/runtime/engineDispatcher.d.ts +36 -0
- package/dist/runtime/engineDispatcher.d.ts.map +1 -0
- package/dist/runtime/engineDispatcher.js +216 -0
- package/dist/runtime/engineReadiness.d.ts +23 -0
- package/dist/runtime/engineReadiness.d.ts.map +1 -0
- package/dist/runtime/engineReadiness.js +222 -0
- package/dist/runtime/grokAuthenticationError.d.ts +8 -0
- package/dist/runtime/grokAuthenticationError.d.ts.map +1 -0
- package/dist/runtime/grokAuthenticationError.js +20 -0
- package/dist/runtime/grokBrokerCredentialAuthority.d.ts +22 -0
- package/dist/runtime/grokBrokerCredentialAuthority.d.ts.map +1 -0
- package/dist/runtime/grokBrokerCredentialAuthority.js +124 -0
- package/dist/runtime/grokBrokerCredentialReader.d.ts +5 -0
- package/dist/runtime/grokBrokerCredentialReader.d.ts.map +1 -0
- package/dist/runtime/grokBrokerCredentialReader.js +37 -0
- package/dist/runtime/grokBrokerModelPolicy.d.ts +23 -0
- package/dist/runtime/grokBrokerModelPolicy.d.ts.map +1 -0
- package/dist/runtime/grokBrokerModelPolicy.js +28 -0
- package/dist/runtime/grokBrokerProjection.d.ts +106 -0
- package/dist/runtime/grokBrokerProjection.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProjection.js +94 -0
- package/dist/runtime/grokBrokerProxy.d.ts +55 -0
- package/dist/runtime/grokBrokerProxy.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxy.js +262 -0
- package/dist/runtime/grokBrokerProxyRequest.d.ts +30 -0
- package/dist/runtime/grokBrokerProxyRequest.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxyRequest.js +74 -0
- package/dist/runtime/grokBrokerRealmLease.d.ts +4 -0
- package/dist/runtime/grokBrokerRealmLease.d.ts.map +1 -0
- package/dist/runtime/grokBrokerRealmLease.js +33 -0
- package/dist/runtime/grokBrokerRefresh.d.ts +2 -0
- package/dist/runtime/grokBrokerRefresh.d.ts.map +1 -0
- package/dist/runtime/grokBrokerRefresh.js +15 -0
- package/dist/runtime/grokBrokerTurnMeter.d.ts +128 -0
- package/dist/runtime/grokBrokerTurnMeter.d.ts.map +1 -0
- package/dist/runtime/grokBrokerTurnMeter.js +251 -0
- package/dist/runtime/grokBrokerWorkerConfig.d.ts +86 -0
- package/dist/runtime/grokBrokerWorkerConfig.d.ts.map +1 -0
- package/dist/runtime/grokBrokerWorkerConfig.js +135 -0
- package/dist/runtime/grokEngineBroker.d.ts +48 -0
- package/dist/runtime/grokEngineBroker.d.ts.map +1 -0
- package/dist/runtime/grokEngineBroker.js +114 -0
- package/dist/runtime/grokEngineBrokerLedger.d.ts +52 -0
- package/dist/runtime/grokEngineBrokerLedger.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerLedger.js +114 -0
- package/dist/runtime/grokEngineBrokerMetering.d.ts +51 -0
- package/dist/runtime/grokEngineBrokerMetering.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerMetering.js +34 -0
- package/dist/runtime/grokEngineBrokerTurn.d.ts +58 -0
- package/dist/runtime/grokEngineBrokerTurn.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerTurn.js +165 -0
- package/dist/runtime/grokInferenceClientConfig.d.ts +41 -0
- package/dist/runtime/grokInferenceClientConfig.d.ts.map +1 -0
- package/dist/runtime/grokInferenceClientConfig.js +62 -0
- package/dist/runtime/grokInferenceGrants.d.ts +77 -0
- package/dist/runtime/grokInferenceGrants.d.ts.map +1 -0
- package/dist/runtime/grokInferenceGrants.js +116 -0
- package/dist/runtime/grokInferenceProxy.d.ts +29 -0
- package/dist/runtime/grokInferenceProxy.d.ts.map +1 -0
- package/dist/runtime/grokInferenceProxy.js +82 -0
- package/dist/runtime/grokInferenceProxyRequest.d.ts +23 -0
- package/dist/runtime/grokInferenceProxyRequest.d.ts.map +1 -0
- package/dist/runtime/grokInferenceProxyRequest.js +63 -0
- package/dist/runtime/grokSlotPreflightReceipt.d.ts +70 -0
- package/dist/runtime/grokSlotPreflightReceipt.d.ts.map +1 -0
- package/dist/runtime/grokSlotPreflightReceipt.js +101 -0
- package/dist/runtime/grokSubscriptionRealm.d.ts +4 -0
- package/dist/runtime/grokSubscriptionRealm.d.ts.map +1 -0
- package/dist/runtime/grokSubscriptionRealm.js +435 -0
- package/dist/runtime/grokSubscriptionRealmTypes.d.ts +26 -0
- package/dist/runtime/grokSubscriptionRealmTypes.d.ts.map +1 -0
- package/dist/runtime/grokSubscriptionRealmTypes.js +1 -0
- package/dist/runtime/grokWorkerAttestation.d.ts +170 -0
- package/dist/runtime/grokWorkerAttestation.d.ts.map +1 -0
- package/dist/runtime/grokWorkerAttestation.js +266 -0
- package/dist/runtime/grokWorkerDenyPlacement.d.ts +80 -0
- package/dist/runtime/grokWorkerDenyPlacement.d.ts.map +1 -0
- package/dist/runtime/grokWorkerDenyPlacement.js +128 -0
- package/dist/runtime/grokWorkerHomeAttestation.d.ts +30 -0
- package/dist/runtime/grokWorkerHomeAttestation.d.ts.map +1 -0
- package/dist/runtime/grokWorkerHomeAttestation.js +69 -0
- package/dist/runtime/grokWorkerSandboxProfile.d.ts +27 -0
- package/dist/runtime/grokWorkerSandboxProfile.d.ts.map +1 -0
- package/dist/runtime/grokWorkerSandboxProfile.js +44 -0
- package/dist/runtime/grokWorkerTmpAttestation.d.ts +55 -0
- package/dist/runtime/grokWorkerTmpAttestation.d.ts.map +1 -0
- package/dist/runtime/grokWorkerTmpAttestation.js +63 -0
- package/dist/runtime/index.d.ts +26 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +23 -0
- package/dist/runtime/inferenceUsageLedger.d.ts +38 -0
- package/dist/runtime/inferenceUsageLedger.d.ts.map +1 -0
- package/dist/runtime/inferenceUsageLedger.js +53 -0
- package/dist/runtime/mcpToolResult.d.ts +127 -0
- package/dist/runtime/mcpToolResult.d.ts.map +1 -0
- package/dist/runtime/mcpToolResult.js +214 -0
- package/dist/runtime/moltnetMachineRead.d.ts +97 -0
- package/dist/runtime/moltnetMachineRead.d.ts.map +1 -0
- package/dist/runtime/moltnetMachineRead.js +183 -0
- package/dist/runtime/native/daimon-engine-broker +0 -0
- package/dist/runtime/organizationRuntime.d.ts +165 -0
- package/dist/runtime/organizationRuntime.d.ts.map +1 -0
- package/dist/runtime/organizationRuntime.js +3 -0
- package/dist/runtime/organizationRuntimeControl.d.ts +42 -0
- package/dist/runtime/organizationRuntimeControl.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeControl.js +235 -0
- package/dist/runtime/organizationRuntimeHost.d.ts +19 -0
- package/dist/runtime/organizationRuntimeHost.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeHost.js +359 -0
- package/dist/runtime/organizationRuntimeParsing.d.ts +6 -0
- package/dist/runtime/organizationRuntimeParsing.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeParsing.js +370 -0
- package/dist/runtime/organizationRuntimeReadiness.d.ts +12 -0
- package/dist/runtime/organizationRuntimeReadiness.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeReadiness.js +59 -0
- package/dist/runtime/physicalReadiness.d.ts +47 -0
- package/dist/runtime/physicalReadiness.d.ts.map +1 -0
- package/dist/runtime/physicalReadiness.js +142 -0
- package/dist/runtime/portableCredentialAuth.d.ts +6 -0
- package/dist/runtime/portableCredentialAuth.d.ts.map +1 -0
- package/dist/runtime/portableCredentialAuth.js +70 -0
- package/dist/runtime/portableCredentialMaterial.d.ts +8 -0
- package/dist/runtime/portableCredentialMaterial.d.ts.map +1 -0
- package/dist/runtime/portableCredentialMaterial.js +169 -0
- package/dist/runtime/productionAgentTools.d.ts +5 -0
- package/dist/runtime/productionAgentTools.d.ts.map +1 -0
- package/dist/runtime/productionAgentTools.js +328 -0
- package/dist/runtime/runtimeHomeLayout.d.ts +48 -0
- package/dist/runtime/runtimeHomeLayout.d.ts.map +1 -0
- package/dist/runtime/runtimeHomeLayout.js +84 -0
- package/dist/runtime/schedule.d.ts +40 -0
- package/dist/runtime/schedule.d.ts.map +1 -0
- package/dist/runtime/schedule.js +371 -0
- package/dist/runtime/storeCoordination.d.ts +23 -0
- package/dist/runtime/storeCoordination.d.ts.map +1 -0
- package/dist/runtime/storeCoordination.js +94 -0
- package/dist/runtime/toolResultSpill.d.ts +152 -0
- package/dist/runtime/toolResultSpill.d.ts.map +1 -0
- package/dist/runtime/toolResultSpill.js +351 -0
- package/dist/runtime/turnRequestLedger.d.ts +160 -0
- package/dist/runtime/turnRequestLedger.d.ts.map +1 -0
- package/dist/runtime/turnRequestLedger.js +249 -0
- package/dist/runtime/turnUsageLedger.d.ts +143 -0
- package/dist/runtime/turnUsageLedger.d.ts.map +1 -0
- package/dist/runtime/turnUsageLedger.js +203 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts +17 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.js +50 -0
- package/dist/runtime/wakeAcceptanceReconciliation.d.ts +211 -0
- package/dist/runtime/wakeAcceptanceReconciliation.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceReconciliation.js +289 -0
- package/dist/runtime/wakeAcceptanceRecord.d.ts +23 -0
- package/dist/runtime/wakeAcceptanceRecord.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceRecord.js +56 -0
- package/dist/runtime/wakeAcceptanceRetention.d.ts +12 -0
- package/dist/runtime/wakeAcceptanceRetention.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceRetention.js +12 -0
- package/dist/runtime/wakeAcceptanceStore.d.ts +113 -0
- package/dist/runtime/wakeAcceptanceStore.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceStore.js +558 -0
- package/dist/runtime/wakeAcceptanceTypes.d.ts +179 -0
- package/dist/runtime/wakeAcceptanceTypes.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceTypes.js +95 -0
- package/dist/runtime/wakeFuse.d.ts +69 -0
- package/dist/runtime/wakeFuse.d.ts.map +1 -0
- package/dist/runtime/wakeFuse.js +367 -0
- package/package.json +25 -17
- package/dist/examples/mixed-engine-org.d.ts +0 -2
- package/dist/examples/mixed-engine-org.d.ts.map +0 -1
- package/dist/examples/mixed-engine-org.js +0 -351
- package/dist/examples/mixedEngineCli.d.ts +0 -15
- package/dist/examples/mixedEngineCli.d.ts.map +0 -1
- package/dist/examples/mixedEngineCli.js +0 -174
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { engineFailureDetail } from "./organizationRuntimeHost.js";
|
|
3
|
+
import { WakeExecutionClaimLostError } from "./wakeAcceptanceStore.js";
|
|
4
|
+
import { ORGANIZATION_RUNTIME_MAX_STRING_CODEPOINTS, ORGANIZATION_RUNTIME_MAX_WAKE_TEXT_BYTES } from "../contracts/organizationRuntimeContract.js";
|
|
5
|
+
import { grokDaimonToolName } from "../contracts/grokWorkerContract.js";
|
|
6
|
+
/** Durable deliveries wait here; only a selected execution reserves a budget slot. */
|
|
7
|
+
export class AttentionDispatcher {
|
|
8
|
+
options;
|
|
9
|
+
owner = randomUUID();
|
|
10
|
+
work = new Map();
|
|
11
|
+
observed = new Map();
|
|
12
|
+
generations = new Map();
|
|
13
|
+
waiters = new Set();
|
|
14
|
+
active = new Map();
|
|
15
|
+
errors = new Map();
|
|
16
|
+
stopping = false;
|
|
17
|
+
fatal;
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.options = options;
|
|
20
|
+
}
|
|
21
|
+
notify(agentId, fresh = false) {
|
|
22
|
+
if (fresh)
|
|
23
|
+
this.generations.set(agentId, (this.generations.get(agentId) ?? 0) + 1);
|
|
24
|
+
if (this.stopping || this.work.has(agentId))
|
|
25
|
+
return;
|
|
26
|
+
const task = this.drain(agentId).catch((error) => { this.observed.set(agentId, this.generations.get(agentId) ?? 0); this.errors.set(agentId, engineFailureDetail(error) ?? "inbox_storage_unavailable"); }).finally(() => {
|
|
27
|
+
this.work.delete(agentId);
|
|
28
|
+
if (!this.stopping && (this.generations.get(agentId) ?? 0) > (this.observed.get(agentId) ?? 0))
|
|
29
|
+
this.notify(agentId);
|
|
30
|
+
this.options.onIdle(agentId);
|
|
31
|
+
});
|
|
32
|
+
this.work.set(agentId, task);
|
|
33
|
+
}
|
|
34
|
+
fatalReason() { return this.fatal; }
|
|
35
|
+
busy(agentId) { return this.work.has(agentId); }
|
|
36
|
+
activeExecutions() { return [...this.active].map(([agent_id, value]) => ({ agent_id, ...value, state: "running" })); }
|
|
37
|
+
failure(agentId) { return this.errors.get(agentId); }
|
|
38
|
+
async stop() {
|
|
39
|
+
this.stopping = true;
|
|
40
|
+
for (const finish of this.waiters)
|
|
41
|
+
finish();
|
|
42
|
+
await Promise.allSettled(this.work.values());
|
|
43
|
+
await this.options.store.releaseClaims(this.owner);
|
|
44
|
+
}
|
|
45
|
+
halt() { this.stopping = true; for (const finish of this.waiters)
|
|
46
|
+
finish(); }
|
|
47
|
+
async drain(agentId) {
|
|
48
|
+
const agent = this.options.agents.find((value) => value.id === agentId);
|
|
49
|
+
let observedGeneration = 0;
|
|
50
|
+
while (!this.stopping) {
|
|
51
|
+
const generation = this.generations.get(agentId) ?? 0;
|
|
52
|
+
const records = (await this.options.store.recoverable(new Set(this.options.agents.map((value) => value.id)))).filter((record) => record.agent_id === agentId);
|
|
53
|
+
const selected = selectBatch(records, agent, generation > observedGeneration);
|
|
54
|
+
observedGeneration = generation;
|
|
55
|
+
this.observed.set(agentId, generation);
|
|
56
|
+
this.errors.delete(agentId);
|
|
57
|
+
if (!selected.length)
|
|
58
|
+
return;
|
|
59
|
+
const budget = await this.options.fuse.snapshot(agentId, agent.attention);
|
|
60
|
+
if (budget.state !== "available")
|
|
61
|
+
return;
|
|
62
|
+
const executionId = selected[0].execution_id ?? randomUUID();
|
|
63
|
+
const acquired = await this.options.store.acquireClaim(selected[0].acceptance_id, this.owner, selected.map((record) => record.acceptance_id), executionId);
|
|
64
|
+
if (acquired.state === "held") {
|
|
65
|
+
await this.waitUntil(acquired.retry_at);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (acquired.state === "terminal")
|
|
69
|
+
continue;
|
|
70
|
+
const claimed = selected.map((record) => ({ record, claim: acquired.claim, done: false }));
|
|
71
|
+
for (const item of claimed)
|
|
72
|
+
item.record = await this.options.store.transitionClaimed(item.record.acceptance_id, item.claim, "running", undefined, undefined, agent.attention === undefined ? undefined : { execution_id: executionId, deferred: false });
|
|
73
|
+
const verdict = await this.options.fuse.admit(agentId, randomUUID(), agent.attention);
|
|
74
|
+
if (verdict.state !== "admitted" || this.stopping) {
|
|
75
|
+
for (const item of claimed)
|
|
76
|
+
await this.options.store.transitionClaimed(item.record.acceptance_id, item.claim, "accepted");
|
|
77
|
+
await this.options.store.releaseClaim(claimed[0].claim);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
await this.execute(agent, claimed, executionId);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async execute(agent, claimed, executionId) {
|
|
84
|
+
const { store, registry, host, token, fuse } = this.options;
|
|
85
|
+
// Serialize tool disposition and lease renewal against the same current claim.
|
|
86
|
+
let mutation = Promise.resolve();
|
|
87
|
+
const serialize = (operation) => {
|
|
88
|
+
const result = mutation.then(operation);
|
|
89
|
+
mutation = result.then(() => undefined, () => undefined);
|
|
90
|
+
void result.catch((error) => { if (error instanceof WakeExecutionClaimLostError)
|
|
91
|
+
this.failClosed(agent.id, error); });
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
const heartbeat = setInterval(() => {
|
|
95
|
+
void serialize(async () => {
|
|
96
|
+
const renewed = await store.renewClaim(claimed[0].claim.acceptance_id, claimed[0].claim);
|
|
97
|
+
for (const item of claimed)
|
|
98
|
+
item.claim = renewed;
|
|
99
|
+
for (const item of claimed.filter((value) => !value.done))
|
|
100
|
+
await store.transitionClaimed(item.record.acceptance_id, item.claim, "running");
|
|
101
|
+
}).catch((error) => this.failClosed(agent.id, error));
|
|
102
|
+
}, store.claimHeartbeatIntervalMs());
|
|
103
|
+
this.active.set(agent.id, { execution_id: agent.attention === undefined ? claimed[0].record.delivery_id : executionId, delivery_ids: claimed.map((item) => item.record.delivery_id) });
|
|
104
|
+
const messages = claimed.map(({ record }) => ({ acceptance_id: record.acceptance_id, delivery_id: record.delivery_id, ...record.event }));
|
|
105
|
+
if (agent.attention !== undefined)
|
|
106
|
+
registry.set(agent.id, {
|
|
107
|
+
executionId, messages, budget: () => fuse.snapshot(agent.id, agent.attention),
|
|
108
|
+
disposition: (deliveryId, disposition) => serialize(async () => {
|
|
109
|
+
const item = claimed.find((value) => value.record.delivery_id === deliveryId);
|
|
110
|
+
if (!item)
|
|
111
|
+
throw new Error("Delivery is outside this agent's selected inbox turn");
|
|
112
|
+
if (item.done && item.record.state === "completed") {
|
|
113
|
+
if (disposition !== "complete")
|
|
114
|
+
throw new Error("A completed delivery cannot be deferred");
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (item.done && disposition === "defer")
|
|
118
|
+
return;
|
|
119
|
+
item.record = await store.transitionClaimed(item.record.acceptance_id, item.claim, disposition === "complete" ? "completed" : "accepted", undefined, disposition === "complete" ? "" : undefined, disposition === "defer" ? { deferred: true, clear_execution: true, execution_error: null } : { execution_id: executionId, deferred: false, execution_error: null });
|
|
120
|
+
item.done = true;
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
let result;
|
|
124
|
+
try {
|
|
125
|
+
const first = claimed[0].record;
|
|
126
|
+
result = await host.wake({ token, agentId: agent.id, event: {
|
|
127
|
+
version: "noopolis.daimon.wake.v1", id: agent.attention === undefined ? first.delivery_id : executionId, kind: first.event.kind,
|
|
128
|
+
occurredAt: first.event.occurred_at,
|
|
129
|
+
text: agent.attention === undefined ? first.event.text : inboxPrompt(messages, agent.engine.kind, agent.attention.maxBatchBytes)
|
|
130
|
+
} });
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
result = { version: "noopolis.daimon.wake-result.v1", status: "failed", agentId: agent.id, wakeId: executionId, code: "engine_failed", detail: engineFailureDetail(error) };
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
clearInterval(heartbeat);
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
await mutation;
|
|
140
|
+
const executionError = result.status === "rejected" ? `wake rejected: ${result.code}`
|
|
141
|
+
: result.status === "failed" ? `engine_failed: ${result.detail ?? "engine execution failed"}` : null;
|
|
142
|
+
for (const item of claimed.filter((value) => !value.done)) {
|
|
143
|
+
// Returned to the inbox for restart, and recording WHY. Only a WAKE OUTCOME
|
|
144
|
+
// decides this: `stopped` — which an aborted in-flight wake also carries, with
|
|
145
|
+
// its own code — is the runtime reclaiming work nobody read. The dispatcher's
|
|
146
|
+
// own halt is not an outcome and must not stand in for one; it guards the
|
|
147
|
+
// pre-wake path, where it belongs. Keying on it here discarded a completed
|
|
148
|
+
// wake's evidence because the host happened to be halting, leaving a record
|
|
149
|
+
// byte-identical to "never ran". Production tolerated it because a restart
|
|
150
|
+
// re-delivers; a one-shot isolated trial has no restart and simply lost it.
|
|
151
|
+
if (result.status === "stopped") {
|
|
152
|
+
await store.transitionClaimed(item.record.acceptance_id, item.claim, "accepted", result.code);
|
|
153
|
+
}
|
|
154
|
+
else if (agent.attention !== undefined) {
|
|
155
|
+
// Successful reading is not completion. A failed execution also keeps
|
|
156
|
+
// unfinished deliveries, and its execution id for idempotent retry.
|
|
157
|
+
await store.transitionClaimed(item.record.acceptance_id, item.claim, "accepted", undefined, undefined, { deferred: true, clear_execution: result.status === "completed", execution_error: executionError });
|
|
158
|
+
}
|
|
159
|
+
else if (result.status === "completed")
|
|
160
|
+
await store.transitionClaimed(item.record.acceptance_id, item.claim, "completed", undefined, result.text);
|
|
161
|
+
else
|
|
162
|
+
await store.transitionClaimed(item.record.acceptance_id, item.claim, "failed", "engine_failed", result.status === "failed" ? result.detail : undefined);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
this.active.delete(agent.id);
|
|
167
|
+
registry.delete(agent.id);
|
|
168
|
+
await store.releaseClaim(claimed[0].claim);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
failClosed(agentId, error) {
|
|
172
|
+
this.errors.set(agentId, engineFailureDetail(error) ?? "execution_claim_lost");
|
|
173
|
+
this.fatal = "ledger_unavailable";
|
|
174
|
+
this.options.registry.clear();
|
|
175
|
+
this.active.clear();
|
|
176
|
+
this.halt();
|
|
177
|
+
// Losing a fence revokes runtime/tool authority before stopping cognition.
|
|
178
|
+
// This host has no per-agent abort lifecycle, so fail closed.
|
|
179
|
+
void this.options.host.stop().catch(() => undefined);
|
|
180
|
+
}
|
|
181
|
+
async waitUntil(timestamp) {
|
|
182
|
+
if (this.stopping)
|
|
183
|
+
return;
|
|
184
|
+
await new Promise((resolve) => {
|
|
185
|
+
const finish = () => { clearTimeout(timer); this.waiters.delete(finish); resolve(); };
|
|
186
|
+
const timer = setTimeout(finish, Math.max(1, Date.parse(timestamp) - Date.now()));
|
|
187
|
+
this.waiters.add(finish);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
export function selectBatch(records, agent, revisitDeferred) {
|
|
192
|
+
const eligible = records.filter((record) => !record.deferred || revisitDeferred);
|
|
193
|
+
const first = eligible[0];
|
|
194
|
+
if (!first)
|
|
195
|
+
return [];
|
|
196
|
+
// A durable execution identity survives a crash and partially completed batch.
|
|
197
|
+
if (first.execution_id !== undefined)
|
|
198
|
+
return records.filter((record) => record.execution_id === first.execution_id);
|
|
199
|
+
if (agent.attention === undefined || first.event.kind !== "message")
|
|
200
|
+
return [first];
|
|
201
|
+
const selected = [];
|
|
202
|
+
const count = agent.attention.maxBatchMessages ?? 8;
|
|
203
|
+
const bytes = agent.attention.maxBatchBytes ?? 12000;
|
|
204
|
+
for (const record of eligible) {
|
|
205
|
+
if (record.event.kind !== "message" || record.execution_id !== undefined || selected.length >= count)
|
|
206
|
+
break;
|
|
207
|
+
const next = [...selected, record];
|
|
208
|
+
if (Buffer.byteLength(JSON.stringify(next.map((value) => ({ acceptance_id: value.acceptance_id, delivery_id: value.delivery_id, ...value.event })))) > bytes)
|
|
209
|
+
break;
|
|
210
|
+
selected.push(record);
|
|
211
|
+
}
|
|
212
|
+
// Oversized individual payloads remain intact in daimon_inbox, not a silently
|
|
213
|
+
// truncated synthetic wake. The prompt references its durable delivery id.
|
|
214
|
+
return selected.length ? selected : [first];
|
|
215
|
+
}
|
|
216
|
+
/** One claimed delivery, rendered as the task it is. */
|
|
217
|
+
function deliveryBlock(message, index) {
|
|
218
|
+
if (message === null || typeof message !== "object")
|
|
219
|
+
return undefined;
|
|
220
|
+
const row = message;
|
|
221
|
+
const text = typeof row.text === "string" ? row.text : undefined;
|
|
222
|
+
if (text === undefined)
|
|
223
|
+
return undefined;
|
|
224
|
+
const from = typeof row.from === "string" ? row.from : undefined;
|
|
225
|
+
const kind = typeof row.kind === "string" ? row.kind : "delivery";
|
|
226
|
+
const id = typeof row.delivery_id === "string" ? row.delivery_id : `#${index + 1}`;
|
|
227
|
+
return [`<delivery id="${id}" kind="${kind}"${from === undefined ? "" : ` from="${from}"`}>`, text, "</delivery>"].join("\n");
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The inbox turn, task first.
|
|
231
|
+
*
|
|
232
|
+
* A delivery's own text *is* the work. Leading with bookkeeping and handing the
|
|
233
|
+
* model `JSON.stringify(messages)` buried the task: an agent read the JSON, did
|
|
234
|
+
* the accounting and deferred without doing the job (observed on Grok: nine
|
|
235
|
+
* model requests, no tool calls, nothing filed). The deliveries are therefore
|
|
236
|
+
* rendered as labelled blocks and the `daimon_inbox` accounting follows them as
|
|
237
|
+
* what to do *after* the work, with the machine-readable payload kept as a
|
|
238
|
+
* trailing appendix while it fits the same budget.
|
|
239
|
+
*
|
|
240
|
+
* Both tools are named the way the agent's own engine can call them. On Grok a
|
|
241
|
+
* Daimon tool is an MCP tool of server `daimon` and its bare name reaches
|
|
242
|
+
* nothing (`grokDaimonToolName`, the same contract module the worker's system
|
|
243
|
+
* prompt and identity envelope render from), so an agent handed the bare name
|
|
244
|
+
* cannot mark its work complete — and an unmarked, finished wake is recorded as
|
|
245
|
+
* deferred.
|
|
246
|
+
*/
|
|
247
|
+
export function inboxPrompt(messages, engine, maxBytes = 12000) {
|
|
248
|
+
const body = JSON.stringify(messages);
|
|
249
|
+
const blocks = messages.map(deliveryBlock).filter((block) => block !== undefined);
|
|
250
|
+
const tool = (name) => engine === "grok" ? grokDaimonToolName(name) : name;
|
|
251
|
+
const accounting = `\nWhen the work above is done, record each delivery with ${tool("daimon_inbox_disposition")} (complete), or defer the ones you could not finish; use ${tool("daimon_inbox")} for deliveries and remaining allowances. Reading or ending this turn never completes a delivery, and deferred work waits for a later external wake.\n`;
|
|
252
|
+
const header = blocks.length === 1 ? "Carry out this delivery.\n" : `Carry out these ${blocks.length} deliveries.\n`;
|
|
253
|
+
const fits = (value) => Buffer.byteLength(value) <= ORGANIZATION_RUNTIME_MAX_WAKE_TEXT_BYTES
|
|
254
|
+
&& [...value].length <= ORGANIZATION_RUNTIME_MAX_STRING_CODEPOINTS;
|
|
255
|
+
if (blocks.length > 0 && Buffer.byteLength(blocks.join("\n\n")) <= maxBytes) {
|
|
256
|
+
const task = header + blocks.join("\n\n") + accounting;
|
|
257
|
+
const withPayload = `${task}\nMachine-readable payload: ${body}`;
|
|
258
|
+
// The inbox budget bounds selection; the v1 execution boundary independently
|
|
259
|
+
// bounds the complete prompt, including metadata, escaping, and instructions.
|
|
260
|
+
if (Buffer.byteLength(body) <= maxBytes && fits(withPayload))
|
|
261
|
+
return withPayload;
|
|
262
|
+
if (fits(task))
|
|
263
|
+
return task;
|
|
264
|
+
}
|
|
265
|
+
const prefix = `Handle this inbox turn. Use ${tool("daimon_inbox")} for deliveries and remaining allowances. Explicitly call ${tool("daimon_inbox_disposition")} for each handled delivery (complete) or unfinished delivery (defer). Reading or ending this turn never completes a delivery. Deferred work waits for a later external wake.\n`;
|
|
266
|
+
const prompt = prefix + body;
|
|
267
|
+
if (Buffer.byteLength(body) > maxBytes || !fits(prompt)) {
|
|
268
|
+
return prefix + `The selected payload exceeds the prompt budget; read it with ${tool("daimon_inbox")}.`;
|
|
269
|
+
}
|
|
270
|
+
return prompt;
|
|
271
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export declare function runOrganizationRuntimeCli(arguments_: readonly string[], environment?: NodeJS.ProcessEnv): Promise<void>;
|
|
3
|
+
export declare function parseOrganizationRuntimeCliArguments(arguments_: readonly string[]): Readonly<{
|
|
4
|
+
configPath: string;
|
|
5
|
+
kind: "agy-login" | "run";
|
|
6
|
+
}>;
|
|
7
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/runtime/cli.ts"],"names":[],"mappings":";AAkBA,wBAAsB,yBAAyB,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,WAAW,oBAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAiDvH;AASD,wBAAgB,oCAAoC,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,QAAQ,CAAC;IAC5F,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,WAAW,GAAG,KAAK,CAAC;CAC3B,CAAC,CASD"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdir, open, readFile, realpath, rename, stat } from "node:fs/promises";
|
|
3
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
4
|
+
import { createServer } from "node:http";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { createOrganizationRuntimeHost } from "./organizationRuntimeHost.js";
|
|
8
|
+
import { createOrganizationRuntimeControlHost } from "./organizationRuntimeControl.js";
|
|
9
|
+
import { runAgySubscriptionBootstrap } from "./agySubscriptionBootstrap.js";
|
|
10
|
+
import { parseOrganizationRuntimeConfig, parseOrganizationRuntimeWakeRequest } from "./organizationRuntime.js";
|
|
11
|
+
import { runEngineBrokerServiceCli } from "./engineBrokerServiceCli.js";
|
|
12
|
+
const MAX_BODY_BYTES = 1_048_576;
|
|
13
|
+
const MAX_CONFIG_BYTES = 1_048_576;
|
|
14
|
+
const ACCEPTANCE_STORE_ENV = "DAIMON_RUNTIME_ACCEPTANCE_STORE";
|
|
15
|
+
const READINESS_RECEIPT_ENV = "DAIMON_RUNTIME_READINESS_RECEIPT";
|
|
16
|
+
export async function runOrganizationRuntimeCli(arguments_, environment = process.env) {
|
|
17
|
+
if (arguments_.length === 2 && arguments_[0] === "engine-broker" && arguments_[1] === "serve") {
|
|
18
|
+
await runEngineBrokerServiceCli();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const command = parseArguments(arguments_);
|
|
22
|
+
const config = parseOrganizationRuntimeConfig(JSON.parse(await readBoundedFile(command.configPath)));
|
|
23
|
+
if (command.kind === "agy-login") {
|
|
24
|
+
await runAgySubscriptionBootstrap(config);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const storePath = environment[ACCEPTANCE_STORE_ENV];
|
|
28
|
+
const control = storePath === undefined || !storePath.trim()
|
|
29
|
+
? undefined
|
|
30
|
+
: createOrganizationRuntimeControlHost(config, { acceptanceStorePath: storePath, controlToken: environment[config.host.controlTokenEnv] });
|
|
31
|
+
const host = control ?? createOrganizationRuntimeHost(config);
|
|
32
|
+
await host.start();
|
|
33
|
+
const server = createServer((request, response) => {
|
|
34
|
+
void handleRequest(request, response, host, control, environment[config.host.controlTokenEnv]);
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
if (environment[READINESS_RECEIPT_ENV])
|
|
38
|
+
await writeReadinessReceipt(environment[READINESS_RECEIPT_ENV], config);
|
|
39
|
+
await listen(server, config.host.bindHost, config.host.port);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
await host.stop();
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
const sockets = new Set();
|
|
46
|
+
server.on("connection", (socket) => { sockets.add(socket); socket.once("close", () => sockets.delete(socket)); });
|
|
47
|
+
// Signals can arrive together (Docker stop commonly sends TERM then KILL).
|
|
48
|
+
// Every path shares one shutdown outcome and only the first initiates it.
|
|
49
|
+
let shutdown;
|
|
50
|
+
let serverClosed = false;
|
|
51
|
+
const stop = () => {
|
|
52
|
+
if (shutdown !== undefined)
|
|
53
|
+
return shutdown;
|
|
54
|
+
const attempt = (async () => {
|
|
55
|
+
if (!serverClosed) {
|
|
56
|
+
await closeServer(server, sockets);
|
|
57
|
+
serverClosed = true;
|
|
58
|
+
}
|
|
59
|
+
await host.stop();
|
|
60
|
+
process.removeListener("SIGINT", onSignal);
|
|
61
|
+
process.removeListener("SIGTERM", onSignal);
|
|
62
|
+
})();
|
|
63
|
+
shutdown = attempt;
|
|
64
|
+
void attempt.catch(() => { if (shutdown === attempt)
|
|
65
|
+
shutdown = undefined; });
|
|
66
|
+
return attempt;
|
|
67
|
+
};
|
|
68
|
+
const onSignal = () => { void stop().catch((error) => { process.stderr.write(`${error instanceof Error ? error.message : "runtime shutdown failed"}\n`); process.exitCode = 1; }); };
|
|
69
|
+
process.once("SIGINT", onSignal);
|
|
70
|
+
process.once("SIGTERM", onSignal);
|
|
71
|
+
}
|
|
72
|
+
async function writeReadinessReceipt(file, config) {
|
|
73
|
+
const value = `${JSON.stringify({ version: "noopolis.daimon.readiness-receipt.v1", agents: config.agents.map((agent) => ({ agent_id: agent.id, engine: agent.engine.kind })).sort((left, right) => left.agent_id.localeCompare(right.agent_id)) })}\n`;
|
|
74
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
75
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
76
|
+
const handle = await open(temporary, "wx", 0o600);
|
|
77
|
+
try {
|
|
78
|
+
await handle.writeFile(value);
|
|
79
|
+
await handle.sync();
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
await handle.close();
|
|
83
|
+
}
|
|
84
|
+
await rename(temporary, file);
|
|
85
|
+
const directory = await open(path.dirname(file), "r");
|
|
86
|
+
try {
|
|
87
|
+
await directory.sync();
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await directory.close();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function parseOrganizationRuntimeCliArguments(arguments_) {
|
|
94
|
+
if (arguments_.length === 3 && arguments_[0] === "run" && arguments_[1] === "--config" && arguments_[2]) {
|
|
95
|
+
return { configPath: arguments_[2], kind: "run" };
|
|
96
|
+
}
|
|
97
|
+
if (arguments_.length === 5 && arguments_[0] === "auth" && arguments_[1] === "agy" && arguments_[2] === "login"
|
|
98
|
+
&& arguments_[3] === "--config" && arguments_[4]) {
|
|
99
|
+
return { configPath: arguments_[4], kind: "agy-login" };
|
|
100
|
+
}
|
|
101
|
+
throw new Error("usage: daimon-runtime run --config <path> | daimon-runtime auth agy login --config <path>");
|
|
102
|
+
}
|
|
103
|
+
const parseArguments = parseOrganizationRuntimeCliArguments;
|
|
104
|
+
async function handleRequest(request, response, host, control, expectedToken) {
|
|
105
|
+
try {
|
|
106
|
+
const url = new URL(request.url ?? "/", "http://runtime.invalid");
|
|
107
|
+
if (request.method === "GET" && url.pathname === "/healthz" && url.search === "") {
|
|
108
|
+
return respond(response, 200, { status: "ok" });
|
|
109
|
+
}
|
|
110
|
+
if (!authorized(request, expectedToken))
|
|
111
|
+
return respond(response, 401, { error: "unauthorized" });
|
|
112
|
+
if (request.method === "POST" && url.pathname === "/v1/wake") {
|
|
113
|
+
if (request.headers["content-type"] !== "application/json")
|
|
114
|
+
throw new TypeError("content-type must be application/json");
|
|
115
|
+
const result = await host.wake(parseOrganizationRuntimeWakeRequest({ ...bodyRecord(await readJson(request)), token: expectedToken }));
|
|
116
|
+
return respond(response, result.status === "completed" ? 200 : result.status === "failed" ? 502 : 409, result);
|
|
117
|
+
}
|
|
118
|
+
if (request.method === "GET" && url.pathname === "/v1/health") {
|
|
119
|
+
return respond(response, 200, await host.health(parseHealthQuery(url)));
|
|
120
|
+
}
|
|
121
|
+
if (request.method === "GET" && url.pathname === "/v1/activity") {
|
|
122
|
+
return respond(response, 200, await host.activity(parseActivityQuery(url)));
|
|
123
|
+
}
|
|
124
|
+
if (control !== undefined && request.method === "POST" && url.pathname === "/v2/wakes") {
|
|
125
|
+
if (request.headers["content-type"] !== "application/json")
|
|
126
|
+
throw new TypeError("content-type must be application/json");
|
|
127
|
+
const result = await control.accept({ ...bodyRecord(await readJson(request)), token: expectedToken });
|
|
128
|
+
const status = result.state === "accepted" ? 202 : result.state === "stopped" ? 409 : result.code === "invalid_request" ? 400 : result.code === "unauthorized" ? 401 : 409;
|
|
129
|
+
return respond(response, status, result);
|
|
130
|
+
}
|
|
131
|
+
if (control !== undefined && request.method === "GET" && /^\/v2\/wake-receipts\/[0-9a-f-]+$/iu.test(url.pathname)) {
|
|
132
|
+
assertQuery(url, []);
|
|
133
|
+
const acceptanceId = url.pathname.slice("/v2/wake-receipts/".length);
|
|
134
|
+
const receipt = await control.wakeReceipt(expectedToken, acceptanceId);
|
|
135
|
+
return receipt === undefined ? respond(response, 404, { error: "not_found" }) : respond(response, 200, receipt);
|
|
136
|
+
}
|
|
137
|
+
if (control !== undefined && request.method === "GET" && url.pathname === "/v2/availability") {
|
|
138
|
+
assertQuery(url, []);
|
|
139
|
+
const availability = await control.availability(expectedToken);
|
|
140
|
+
return availability === undefined ? respond(response, 404, { error: "not_found" }) : respond(response, 200, availability);
|
|
141
|
+
}
|
|
142
|
+
if (control !== undefined && request.method === "GET" && url.pathname === "/v2/activity") {
|
|
143
|
+
assertQuery(url, []);
|
|
144
|
+
const activity = await control.activityV2(expectedToken);
|
|
145
|
+
return activity === undefined ? respond(response, 404, { error: "not_found" }) : respond(response, 200, activity);
|
|
146
|
+
}
|
|
147
|
+
return respond(response, 404, { error: "not_found" });
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return respond(response, 400, { error: error instanceof Error ? error.message : "invalid_request" });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function authorized(request, token) {
|
|
154
|
+
if (token === undefined || !token.trim())
|
|
155
|
+
return false;
|
|
156
|
+
const actual = request.headers.authorization;
|
|
157
|
+
if (actual === undefined)
|
|
158
|
+
return false;
|
|
159
|
+
const digest = (value) => createHash("sha256").update(value).digest();
|
|
160
|
+
return timingSafeEqual(digest(`Bearer ${token}`), digest(actual));
|
|
161
|
+
}
|
|
162
|
+
async function readJson(request) {
|
|
163
|
+
const chunks = [];
|
|
164
|
+
let size = 0;
|
|
165
|
+
for await (const chunk of request) {
|
|
166
|
+
const value = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
167
|
+
size += value.length;
|
|
168
|
+
if (size > MAX_BODY_BYTES)
|
|
169
|
+
throw new TypeError("request body is too large");
|
|
170
|
+
chunks.push(value);
|
|
171
|
+
}
|
|
172
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
173
|
+
}
|
|
174
|
+
function bodyRecord(value) {
|
|
175
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
176
|
+
throw new TypeError("request body must be an object");
|
|
177
|
+
const prototype = Object.getPrototypeOf(value);
|
|
178
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
179
|
+
throw new TypeError("request body must be a plain own-properties object");
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
function parseHealthQuery(url) {
|
|
183
|
+
assertQuery(url, ["agentId"]);
|
|
184
|
+
return url.searchParams.has("agentId") ? nonBlank(url.searchParams.get("agentId"), "agentId") : undefined;
|
|
185
|
+
}
|
|
186
|
+
function parseActivityQuery(url) {
|
|
187
|
+
assertQuery(url, ["agentId", "cursor", "limit"]);
|
|
188
|
+
const rawLimit = url.searchParams.get("limit");
|
|
189
|
+
const limit = rawLimit === null ? 50 : Number(rawLimit);
|
|
190
|
+
if (!Number.isInteger(limit))
|
|
191
|
+
throw new TypeError("limit must be an integer");
|
|
192
|
+
return {
|
|
193
|
+
...(url.searchParams.has("agentId") ? { agentId: nonBlank(url.searchParams.get("agentId"), "agentId") } : {}),
|
|
194
|
+
...(url.searchParams.has("cursor") ? { cursor: nonBlank(url.searchParams.get("cursor"), "cursor") } : {}),
|
|
195
|
+
limit
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function assertQuery(url, allowed) {
|
|
199
|
+
const seen = new Set();
|
|
200
|
+
for (const [key] of url.searchParams) {
|
|
201
|
+
if (!allowed.includes(key) || seen.has(key))
|
|
202
|
+
throw new TypeError("query contains an unsupported or duplicate parameter");
|
|
203
|
+
seen.add(key);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function nonBlank(value, label) {
|
|
207
|
+
if (typeof value !== "string")
|
|
208
|
+
throw new TypeError(`${label} must be a string`);
|
|
209
|
+
const result = value;
|
|
210
|
+
if (!result.trim())
|
|
211
|
+
throw new TypeError(`${label} must not be blank`);
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
async function readBoundedFile(filePath) {
|
|
215
|
+
if ((await stat(filePath)).size > MAX_CONFIG_BYTES)
|
|
216
|
+
throw new TypeError("runtime config is too large");
|
|
217
|
+
const bytes = await readFile(filePath);
|
|
218
|
+
if (bytes.length > MAX_CONFIG_BYTES)
|
|
219
|
+
throw new TypeError("runtime config is too large");
|
|
220
|
+
return bytes.toString("utf8");
|
|
221
|
+
}
|
|
222
|
+
function respond(response, status, value) {
|
|
223
|
+
response.writeHead(status, { "content-type": "application/json; charset=utf-8" });
|
|
224
|
+
response.end(`${JSON.stringify(value)}\n`);
|
|
225
|
+
}
|
|
226
|
+
function listen(server, host, port) {
|
|
227
|
+
return new Promise((resolve, reject) => {
|
|
228
|
+
server.once("error", reject);
|
|
229
|
+
server.listen(port, host, () => resolve());
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
async function closeServer(server, sockets) {
|
|
233
|
+
const closed = new Promise((resolve, reject) => server.close((error) => error === undefined ? resolve() : reject(error)));
|
|
234
|
+
const timeout = setTimeout(() => { for (const socket of sockets)
|
|
235
|
+
socket.destroy(); }, 10_000);
|
|
236
|
+
try {
|
|
237
|
+
await closed;
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
clearTimeout(timeout);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const invokedPath = process.argv[1] === undefined
|
|
244
|
+
? undefined
|
|
245
|
+
: await realpath(process.argv[1]).catch(() => process.argv[1]);
|
|
246
|
+
if (invokedPath !== undefined && import.meta.url === pathToFileURL(invokedPath).href) {
|
|
247
|
+
void runOrganizationRuntimeCli(process.argv.slice(2)).catch((error) => {
|
|
248
|
+
process.stderr.write(`${error instanceof Error ? error.message : "daimon-runtime failed"}\n`);
|
|
249
|
+
process.exitCode = 1;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const CODEX_SANDBOX_PROJECTION_VERSION = "noopolis.daimon.codex-sandbox-projection.v1";
|
|
2
|
+
export type OrganizationCodexSandboxProjection = Readonly<{
|
|
3
|
+
version: typeof CODEX_SANDBOX_PROJECTION_VERSION;
|
|
4
|
+
agentId: string;
|
|
5
|
+
workspacePath: string;
|
|
6
|
+
runtimeHomePath: string;
|
|
7
|
+
engineHomePath: string;
|
|
8
|
+
executablePath: string;
|
|
9
|
+
profileName: string;
|
|
10
|
+
permissionConfig: string;
|
|
11
|
+
sandboxArgs: readonly string[];
|
|
12
|
+
}>;
|
|
13
|
+
/** Resolves the production command policy without importing auth or accepting a wake. */
|
|
14
|
+
export declare function resolveOrganizationCodexSandboxProjection(config: unknown, agentId: string, options: Readonly<{
|
|
15
|
+
acceptanceStorePath: string;
|
|
16
|
+
}>): Promise<OrganizationCodexSandboxProjection>;
|
|
17
|
+
//# sourceMappingURL=codexSandboxProjection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codexSandboxProjection.d.ts","sourceRoot":"","sources":["../../src/runtime/codexSandboxProjection.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,gCAAgC,gDAAgD,CAAC;AAC9F,MAAM,MAAM,kCAAkC,GAAG,QAAQ,CAAC;IACxD,OAAO,EAAE,OAAO,gCAAgC,CAAC;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC,CAAC,CAAC;AAEH,yFAAyF;AACzF,wBAAsB,yCAAyC,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAC9F,OAAO,EAAE,QAAQ,CAAC;IAAE,mBAAmB,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,kCAAkC,CAAC,CA2BjG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { renderCodexArgs } from "../pi/cliEngineSpawn.js";
|
|
3
|
+
import { codexSandboxProtectedPaths, codexSandboxReadablePaths } from "./engineDispatcher.js";
|
|
4
|
+
import { engineHomeName, prepareEngineExecutable } from "./engineReadiness.js";
|
|
5
|
+
import { parseOrganizationRuntimeConfig } from "./organizationRuntime.js";
|
|
6
|
+
import { prepareOrganizationRuntimePaths } from "./physicalReadiness.js";
|
|
7
|
+
export const CODEX_SANDBOX_PROJECTION_VERSION = "noopolis.daimon.codex-sandbox-projection.v1";
|
|
8
|
+
/** Resolves the production command policy without importing auth or accepting a wake. */
|
|
9
|
+
export async function resolveOrganizationCodexSandboxProjection(config, agentId, options) {
|
|
10
|
+
const parsed = parseOrganizationRuntimeConfig(config);
|
|
11
|
+
const selected = parsed.agents.find(agent => agent.id === agentId);
|
|
12
|
+
if (!selected || selected.engine.kind !== "codex" || selected.engine.codexSandbox === undefined) {
|
|
13
|
+
throw new Error("Sandbox projection requires a known strict Codex agent");
|
|
14
|
+
}
|
|
15
|
+
if (!path.isAbsolute(options.acceptanceStorePath))
|
|
16
|
+
throw new Error("Sandbox projection requires an absolute acceptance store path");
|
|
17
|
+
const authority = await prepareOrganizationRuntimePaths(parsed.agents);
|
|
18
|
+
try {
|
|
19
|
+
const paths = authority.forAgent(selected);
|
|
20
|
+
await paths.verify();
|
|
21
|
+
const agent = { ...selected, workspacePath: paths.workspacePath, runtimeHomePath: paths.runtimeHomePath };
|
|
22
|
+
const engineHomePath = path.join(agent.runtimeHomePath, engineHomeName("codex"));
|
|
23
|
+
const executable = await prepareEngineExecutable(agent.id, "codex");
|
|
24
|
+
// These are the same collectors, canonical roots and renderer used by
|
|
25
|
+
// startOrganizationRuntimeEngine and its strict production invocation.
|
|
26
|
+
const args = renderCodexArgs({ codexSandbox: agent.engine.codexSandbox,
|
|
27
|
+
codexSandboxProtectedPaths: codexSandboxProtectedPaths(agent.id, agent, engineHomePath, parsed.agents, [options.acceptanceStorePath]),
|
|
28
|
+
codexSandboxReadablePaths: codexSandboxReadablePaths(agent) }, agent.workspacePath, undefined);
|
|
29
|
+
const permissionConfig = args.find(arg => arg.startsWith("permissions="));
|
|
30
|
+
const profileName = JSON.parse(args.find(arg => arg.startsWith("default_permissions=")).slice("default_permissions=".length));
|
|
31
|
+
await paths.verify();
|
|
32
|
+
await executable.verify();
|
|
33
|
+
return { version: CODEX_SANDBOX_PROJECTION_VERSION, agentId, workspacePath: agent.workspacePath,
|
|
34
|
+
runtimeHomePath: agent.runtimeHomePath, engineHomePath, executablePath: executable.executablePath, profileName, permissionConfig,
|
|
35
|
+
sandboxArgs: ["sandbox", "-P", profileName, "-C", agent.workspacePath, "-c", permissionConfig] };
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
await authority.close();
|
|
39
|
+
}
|
|
40
|
+
}
|