@noopolis/daimon 0.1.2 → 0.2.1
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 +275 -51
- package/dist/contracts/attentionContract.d.ts +142 -0
- package/dist/contracts/attentionContract.d.ts.map +1 -0
- package/dist/contracts/attentionContract.js +21 -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/grokBrokerTaskClock.d.ts +18 -0
- package/dist/contracts/grokBrokerTaskClock.d.ts.map +1 -0
- package/dist/contracts/grokBrokerTaskClock.js +16 -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 +841 -0
- package/dist/contracts/organizationRuntimeContract.d.ts.map +1 -0
- package/dist/contracts/organizationRuntimeContract.js +123 -0
- package/dist/contracts/runtimeContractManifest.d.ts +1822 -0
- package/dist/contracts/runtimeContractManifest.d.ts.map +1 -0
- package/dist/contracts/runtimeContractManifest.js +206 -0
- package/dist/contracts/shellEnvironmentPolicy.d.ts +3 -0
- package/dist/contracts/shellEnvironmentPolicy.d.ts.map +1 -0
- package/dist/contracts/shellEnvironmentPolicy.js +5 -0
- package/dist/contracts/wakeMomentContract.d.ts +61 -0
- package/dist/contracts/wakeMomentContract.d.ts.map +1 -0
- package/dist/contracts/wakeMomentContract.js +27 -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/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/examples/jungianPlayAgent.d.ts +1 -0
- package/dist/examples/jungianPlayAgent.d.ts.map +1 -1
- package/dist/examples/jungianPlayAgent.js +6 -2
- package/dist/mcp/toolServer.d.ts +19 -2
- package/dist/mcp/toolServer.d.ts.map +1 -1
- package/dist/mcp/toolServer.js +57 -17
- package/dist/observability/causalEvents.d.ts +6 -6
- package/dist/observability/causalEvents.d.ts.map +1 -1
- package/dist/observability/causalEvents.js +107 -19
- 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 +169 -0
- package/dist/pi/cliEnvironment.d.ts +12 -0
- package/dist/pi/cliEnvironment.d.ts.map +1 -0
- package/dist/pi/cliEnvironment.js +34 -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 +86 -24
- package/dist/pi/cliSession.d.ts.map +1 -1
- package/dist/pi/cliSession.js +251 -173
- package/dist/pi/cliSessionMcp.d.ts +9 -0
- package/dist/pi/cliSessionMcp.d.ts.map +1 -0
- package/dist/pi/cliSessionMcp.js +80 -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/engineTaskClock.d.ts +9 -0
- package/dist/pi/engineTaskClock.d.ts.map +1 -0
- package/dist/pi/engineTaskClock.js +28 -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 +58 -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/memoryClock.d.ts +25 -0
- package/dist/pi/memoryClock.d.ts.map +1 -0
- package/dist/pi/memoryClock.js +18 -0
- package/dist/pi/piAgentHandle.d.ts +6 -3
- package/dist/pi/piAgentHandle.d.ts.map +1 -1
- package/dist/pi/piAgentHandle.js +42 -12
- package/dist/pi/piAgentWakeSupport.d.ts +35 -0
- package/dist/pi/piAgentWakeSupport.d.ts.map +1 -1
- package/dist/pi/piAgentWakeSupport.js +4 -0
- package/dist/pi/piHarness.d.ts +18 -3
- package/dist/pi/piHarness.d.ts.map +1 -1
- package/dist/pi/piHarness.js +83 -14
- package/dist/pi/prompts.d.ts +1 -0
- package/dist/pi/prompts.d.ts.map +1 -1
- package/dist/pi/prompts.js +24 -0
- package/dist/pi/taskClockProcess.d.ts +6 -0
- package/dist/pi/taskClockProcess.d.ts.map +1 -0
- package/dist/pi/taskClockProcess.js +8 -0
- package/dist/pi/turnCausal.d.ts +4 -2
- package/dist/pi/turnCausal.d.ts.map +1 -1
- package/dist/pi/turnCausal.js +4 -4
- package/dist/pi/turnTrace.d.ts.map +1 -1
- package/dist/pi/turnTrace.js +5 -8
- package/dist/pi/wakeAcceptance.d.ts +1 -1
- package/dist/pi/wakeAcceptance.d.ts.map +1 -1
- package/dist/pi/wakeAcceptance.js +2 -2
- package/dist/pi/worldTrajectory.d.ts +1 -1
- package/dist/pi/worldTrajectory.d.ts.map +1 -1
- package/dist/pi/worldTrajectory.js +3 -3
- 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 +26 -0
- package/dist/runtime/attention.d.ts.map +1 -0
- package/dist/runtime/attention.js +49 -0
- package/dist/runtime/attentionDispatcher.d.ts +78 -0
- package/dist/runtime/attentionDispatcher.d.ts.map +1 -0
- package/dist/runtime/attentionDispatcher.js +365 -0
- package/dist/runtime/cli.d.ts +7 -0
- package/dist/runtime/cli.d.ts.map +1 -0
- package/dist/runtime/cli.js +256 -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 +40 -0
- package/dist/runtime/engineBrokerCapabilities.d.ts.map +1 -0
- package/dist/runtime/engineBrokerCapabilities.js +69 -0
- package/dist/runtime/engineBrokerControlClient.d.ts +55 -0
- package/dist/runtime/engineBrokerControlClient.d.ts.map +1 -0
- package/dist/runtime/engineBrokerControlClient.js +228 -0
- package/dist/runtime/engineBrokerCredentialJournal.d.ts +12 -0
- package/dist/runtime/engineBrokerCredentialJournal.d.ts.map +1 -0
- package/dist/runtime/engineBrokerCredentialJournal.js +26 -0
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts +53 -0
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts.map +1 -0
- package/dist/runtime/engineBrokerInferenceProtocol.js +65 -0
- package/dist/runtime/engineBrokerMcpCallLog.d.ts +171 -0
- package/dist/runtime/engineBrokerMcpCallLog.d.ts.map +1 -0
- package/dist/runtime/engineBrokerMcpCallLog.js +231 -0
- package/dist/runtime/engineBrokerMcpFacade.d.ts +59 -0
- package/dist/runtime/engineBrokerMcpFacade.d.ts.map +1 -0
- package/dist/runtime/engineBrokerMcpFacade.js +346 -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 +167 -0
- package/dist/runtime/engineBrokerProtocol.d.ts.map +1 -0
- package/dist/runtime/engineBrokerProtocol.js +357 -0
- package/dist/runtime/engineBrokerSealLedger.d.ts +70 -0
- package/dist/runtime/engineBrokerSealLedger.d.ts.map +1 -0
- package/dist/runtime/engineBrokerSealLedger.js +132 -0
- package/dist/runtime/engineBrokerService.d.ts +43 -0
- package/dist/runtime/engineBrokerService.d.ts.map +1 -0
- package/dist/runtime/engineBrokerService.js +196 -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 +55 -0
- package/dist/runtime/engineBrokerServiceConfig.d.ts.map +1 -0
- package/dist/runtime/engineBrokerServiceConfig.js +130 -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 +159 -0
- package/dist/runtime/engineDispatcher.d.ts +38 -0
- package/dist/runtime/engineDispatcher.d.ts.map +1 -0
- package/dist/runtime/engineDispatcher.js +228 -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 +23 -0
- package/dist/runtime/grokBrokerCredentialAuthority.d.ts.map +1 -0
- package/dist/runtime/grokBrokerCredentialAuthority.js +150 -0
- package/dist/runtime/grokBrokerCredentialReader.d.ts +6 -0
- package/dist/runtime/grokBrokerCredentialReader.d.ts.map +1 -0
- package/dist/runtime/grokBrokerCredentialReader.js +38 -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 +114 -0
- package/dist/runtime/grokBrokerProjection.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProjection.js +101 -0
- package/dist/runtime/grokBrokerProviderClock.d.ts +26 -0
- package/dist/runtime/grokBrokerProviderClock.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProviderClock.js +133 -0
- package/dist/runtime/grokBrokerProxy.d.ts +69 -0
- package/dist/runtime/grokBrokerProxy.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxy.js +326 -0
- package/dist/runtime/grokBrokerProxyJson.d.ts +10 -0
- package/dist/runtime/grokBrokerProxyJson.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxyJson.js +31 -0
- package/dist/runtime/grokBrokerProxyRequest.d.ts +30 -0
- package/dist/runtime/grokBrokerProxyRequest.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxyRequest.js +85 -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/grokBrokerRunBudget.d.ts +20 -0
- package/dist/runtime/grokBrokerRunBudget.d.ts.map +1 -0
- package/dist/runtime/grokBrokerRunBudget.js +85 -0
- package/dist/runtime/grokBrokerSlot.d.ts +6 -0
- package/dist/runtime/grokBrokerSlot.d.ts.map +1 -0
- package/dist/runtime/grokBrokerSlot.js +21 -0
- package/dist/runtime/grokBrokerTaskClock.d.ts +32 -0
- package/dist/runtime/grokBrokerTaskClock.d.ts.map +1 -0
- package/dist/runtime/grokBrokerTaskClock.js +120 -0
- package/dist/runtime/grokBrokerTurnMeter.d.ts +180 -0
- package/dist/runtime/grokBrokerTurnMeter.d.ts.map +1 -0
- package/dist/runtime/grokBrokerTurnMeter.js +337 -0
- package/dist/runtime/grokBrokerWorkerConfig.d.ts +89 -0
- package/dist/runtime/grokBrokerWorkerConfig.d.ts.map +1 -0
- package/dist/runtime/grokBrokerWorkerConfig.js +154 -0
- package/dist/runtime/grokEngineBroker.d.ts +88 -0
- package/dist/runtime/grokEngineBroker.d.ts.map +1 -0
- package/dist/runtime/grokEngineBroker.js +202 -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 +82 -0
- package/dist/runtime/grokEngineBrokerTurn.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerTurn.js +348 -0
- package/dist/runtime/grokEngineBrokerTurnEnd.d.ts +88 -0
- package/dist/runtime/grokEngineBrokerTurnEnd.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerTurnEnd.js +148 -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 +85 -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 +175 -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 +32 -0
- package/dist/runtime/grokWorkerHomeAttestation.d.ts.map +1 -0
- package/dist/runtime/grokWorkerHomeAttestation.js +75 -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 +31 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +27 -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 +168 -0
- package/dist/runtime/organizationRuntime.d.ts.map +1 -0
- package/dist/runtime/organizationRuntime.js +3 -0
- package/dist/runtime/organizationRuntimeAdmission.d.ts +6 -0
- package/dist/runtime/organizationRuntimeAdmission.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeAdmission.js +22 -0
- package/dist/runtime/organizationRuntimeControl.d.ts +51 -0
- package/dist/runtime/organizationRuntimeControl.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeControl.js +283 -0
- package/dist/runtime/organizationRuntimeHost.d.ts +19 -0
- package/dist/runtime/organizationRuntimeHost.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeHost.js +368 -0
- package/dist/runtime/organizationRuntimeParsing.d.ts +6 -0
- package/dist/runtime/organizationRuntimeParsing.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeParsing.js +373 -0
- package/dist/runtime/organizationRuntimeReadiness.d.ts +12 -0
- package/dist/runtime/organizationRuntimeReadiness.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeReadiness.js +67 -0
- package/dist/runtime/organizationRuntimeRecording.d.ts +7 -0
- package/dist/runtime/organizationRuntimeRecording.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeRecording.js +58 -0
- package/dist/runtime/physicalReadiness.d.ts +59 -0
- package/dist/runtime/physicalReadiness.d.ts.map +1 -0
- package/dist/runtime/physicalReadiness.js +176 -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 +336 -0
- package/dist/runtime/relocateRuntimeConfig.d.ts +14 -0
- package/dist/runtime/relocateRuntimeConfig.d.ts.map +1 -0
- package/dist/runtime/relocateRuntimeConfig.js +38 -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 +376 -0
- package/dist/runtime/storeCoordination.d.ts +33 -0
- package/dist/runtime/storeCoordination.d.ts.map +1 -0
- package/dist/runtime/storeCoordination.js +117 -0
- package/dist/runtime/taskClock.d.ts +42 -0
- package/dist/runtime/taskClock.d.ts.map +1 -0
- package/dist/runtime/taskClock.js +102 -0
- package/dist/runtime/taskClockProcess.d.ts +17 -0
- package/dist/runtime/taskClockProcess.d.ts.map +1 -0
- package/dist/runtime/taskClockProcess.js +58 -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 +155 -0
- package/dist/runtime/turnRequestLedger.d.ts.map +1 -0
- package/dist/runtime/turnRequestLedger.js +251 -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/wakeAcceptanceClaimDiagnostics.d.ts +34 -0
- package/dist/runtime/wakeAcceptanceClaimDiagnostics.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceClaimDiagnostics.js +79 -0
- package/dist/runtime/wakeAcceptanceIndex.d.ts +55 -0
- package/dist/runtime/wakeAcceptanceIndex.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceIndex.js +158 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts +25 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.js +54 -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 +25 -0
- package/dist/runtime/wakeAcceptanceRecord.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceRecord.js +58 -0
- package/dist/runtime/wakeAcceptanceRetention.d.ts +36 -0
- package/dist/runtime/wakeAcceptanceRetention.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceRetention.js +38 -0
- package/dist/runtime/wakeAcceptanceStore.d.ts +113 -0
- package/dist/runtime/wakeAcceptanceStore.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceStore.js +561 -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 +124 -0
- package/dist/runtime/wakeFuse.d.ts.map +1 -0
- package/dist/runtime/wakeFuse.js +466 -0
- package/dist/runtime/wakeMomentFs.d.ts +27 -0
- package/dist/runtime/wakeMomentFs.d.ts.map +1 -0
- package/dist/runtime/wakeMomentFs.js +223 -0
- package/dist/runtime/wakeMomentHistory.d.ts +26 -0
- package/dist/runtime/wakeMomentHistory.d.ts.map +1 -0
- package/dist/runtime/wakeMomentHistory.js +109 -0
- package/dist/runtime/wakeMomentIo.d.ts +22 -0
- package/dist/runtime/wakeMomentIo.d.ts.map +1 -0
- package/dist/runtime/wakeMomentIo.js +114 -0
- package/dist/runtime/wakeMomentRecorder.d.ts +33 -0
- package/dist/runtime/wakeMomentRecorder.d.ts.map +1 -0
- package/dist/runtime/wakeMomentRecorder.js +81 -0
- package/dist/runtime/wakeMomentRetention.d.ts +7 -0
- package/dist/runtime/wakeMomentRetention.d.ts.map +1 -0
- package/dist/runtime/wakeMomentRetention.js +143 -0
- package/dist/runtime/wakeMomentRows.d.ts +8 -0
- package/dist/runtime/wakeMomentRows.d.ts.map +1 -0
- package/dist/runtime/wakeMomentRows.js +66 -0
- package/dist/runtime/wakeMomentSnapshot.d.ts +56 -0
- package/dist/runtime/wakeMomentSnapshot.d.ts.map +1 -0
- package/dist/runtime/wakeMomentSnapshot.js +248 -0
- package/package.json +22 -11
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { GROK_ENGINE_BROKER } from "../contracts/runtimeContractManifest.js";
|
|
4
|
+
import { grokBrokerProjectionSha256 } from "./grokBrokerProjection.js";
|
|
5
|
+
export const GROK_SLOT_PREFLIGHT_VERSION = GROK_ENGINE_BROKER.slotPreflightVersion;
|
|
6
|
+
const sha256 = z.string().regex(/^[a-f0-9]{64}$/u);
|
|
7
|
+
const NONCE = /^[a-f0-9]{64}$/u;
|
|
8
|
+
const canonicalAbsolute = z.string().max(4_096).refine((value) => path.posix.isAbsolute(value) && path.posix.normalize(value) === value && value !== "/" && !value.endsWith("/") && !value.includes("\0"), "canonical absolute path");
|
|
9
|
+
/**
|
|
10
|
+
* One denied-path canary: the root supervisor ran a real sandboxed read of
|
|
11
|
+
* `path` as the slot's worker uid (a stub-model turn under the attested
|
|
12
|
+
* profile) and the read was denied. Only denials are representable — a
|
|
13
|
+
* supervisor that observed a readable path writes no receipt at all.
|
|
14
|
+
*/
|
|
15
|
+
export const grokSlotPreflightCanarySchema = z.strictObject({
|
|
16
|
+
path: canonicalAbsolute,
|
|
17
|
+
method: z.literal("sandboxed-read"),
|
|
18
|
+
result: z.literal("denied")
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* `noopolis.daimon.grok-slot-preflight.v2`: what the root slot supervisor (P5)
|
|
22
|
+
* writes after provisioning or recycling one broker slot, and what an
|
|
23
|
+
* evaluator (Paideia, P4) must hold before it runs a Grok subject turn in that
|
|
24
|
+
* slot. It binds the slot to one exact projection by digest, so any change to
|
|
25
|
+
* the model, limits, deny list, profile, worker config, or pinned executable
|
|
26
|
+
* invalidates it.
|
|
27
|
+
*
|
|
28
|
+
* The projection digest is identical across recycles of the same slot, so v1
|
|
29
|
+
* could not tell this recycle's receipt from an earlier one. v2 adds
|
|
30
|
+
* freshness: `generation` is the supervisor-owned per-slot counter, strictly
|
|
31
|
+
* increasing on every provision/recycle, and `nonce` echoes the 32 random
|
|
32
|
+
* bytes (hex) the evaluator passed in its recycle request. A v1 receipt is
|
|
33
|
+
* refused.
|
|
34
|
+
*/
|
|
35
|
+
export const grokSlotPreflightReceiptSchema = z.strictObject({
|
|
36
|
+
version: z.literal(GROK_SLOT_PREFLIGHT_VERSION),
|
|
37
|
+
slot: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
|
38
|
+
worker_uid: z.number().int().min(GROK_ENGINE_BROKER.identities.firstWorkerUid).max(4_294_967_294),
|
|
39
|
+
/** Supervisor-owned, strictly increasing per slot across provisions and recycles; starts at 1. */
|
|
40
|
+
generation: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
|
41
|
+
/** The caller's recycle nonce: 32 random bytes, lowercase hex. */
|
|
42
|
+
nonce: z.string().regex(NONCE),
|
|
43
|
+
projection_sha256: sha256,
|
|
44
|
+
/** The bubblewrap/Landlock `daimon-strict` profile bytes' digest (the projection's `profileSha256`). */
|
|
45
|
+
sandbox_profile_sha256: sha256,
|
|
46
|
+
/** The container seccomp profile the worker ran under. */
|
|
47
|
+
seccomp_profile_sha256: sha256,
|
|
48
|
+
/** Grok 1.0.34 runs every profile inside bubblewrap; the supervisor observed it present and working. */
|
|
49
|
+
sandbox_runtime: z.literal("bubblewrap"),
|
|
50
|
+
grok_executable_sha256: sha256,
|
|
51
|
+
canaries: z.array(grokSlotPreflightCanarySchema).min(1).max(256),
|
|
52
|
+
created_at: z.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u).refine((value) => !Number.isNaN(Date.parse(value)) && new Date(value).toISOString() === value, "exact RFC3339 timestamp")
|
|
53
|
+
}).superRefine((receipt, context) => {
|
|
54
|
+
const paths = receipt.canaries.map((canary) => canary.path);
|
|
55
|
+
if (new Set(paths).size !== paths.length)
|
|
56
|
+
context.addIssue({ code: "custom", path: ["canaries"], message: "duplicate canary path" });
|
|
57
|
+
});
|
|
58
|
+
/** Strict parse: unknown members, off-contract values, or duplicate canaries throw. */
|
|
59
|
+
export function parseGrokSlotPreflightReceipt(value) {
|
|
60
|
+
const result = grokSlotPreflightReceiptSchema.safeParse(value);
|
|
61
|
+
if (!result.success)
|
|
62
|
+
throw new TypeError(`invalid Grok slot preflight receipt: ${result.error.issues.map((issue) => `${issue.path.join(".") || "receipt"}: ${issue.message}`).join("; ")}`);
|
|
63
|
+
return result.data;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parse a receipt and require that it proves *this* projection's slot: same
|
|
67
|
+
* digest, slot, worker uid, profile and executable, and a denied canary for
|
|
68
|
+
* exactly every projected deny path (no more, no fewer), under the projected
|
|
69
|
+
* seccomp profile and sandbox runtime — and that it is *this* recycle's
|
|
70
|
+
* receipt: the caller's nonce, at or above the caller's minimum generation.
|
|
71
|
+
* A receipt replayed from an earlier recycle fails on the nonce, and one
|
|
72
|
+
* whose generation went backwards fails on the generation.
|
|
73
|
+
*/
|
|
74
|
+
export function verifyGrokSlotPreflightReceipt(value, projection, freshness) {
|
|
75
|
+
if (freshness === null || typeof freshness !== "object" || typeof freshness.expectedNonce !== "string" || !NONCE.test(freshness.expectedNonce) || !Number.isSafeInteger(freshness.minGeneration) || freshness.minGeneration < 1)
|
|
76
|
+
throw new TypeError("invalid Grok slot preflight freshness");
|
|
77
|
+
const receipt = parseGrokSlotPreflightReceipt(value);
|
|
78
|
+
const mismatch = (member) => { throw new Error(`Grok slot preflight receipt does not match the projection: ${member}`); };
|
|
79
|
+
if (receipt.nonce !== freshness.expectedNonce)
|
|
80
|
+
throw new Error("Grok slot preflight receipt is stale: nonce");
|
|
81
|
+
if (receipt.generation < freshness.minGeneration)
|
|
82
|
+
throw new Error("Grok slot preflight receipt is stale: generation");
|
|
83
|
+
if (receipt.projection_sha256 !== grokBrokerProjectionSha256(projection))
|
|
84
|
+
mismatch("projection_sha256");
|
|
85
|
+
if (receipt.slot !== projection.slot)
|
|
86
|
+
mismatch("slot");
|
|
87
|
+
if (receipt.worker_uid !== projection.workerUid)
|
|
88
|
+
mismatch("worker_uid");
|
|
89
|
+
if (receipt.sandbox_profile_sha256 !== projection.profileSha256)
|
|
90
|
+
mismatch("sandbox_profile_sha256");
|
|
91
|
+
if (receipt.grok_executable_sha256 !== projection.grokExecutableSha256)
|
|
92
|
+
mismatch("grok_executable_sha256");
|
|
93
|
+
if (receipt.seccomp_profile_sha256 !== projection.seccompProfileSha256)
|
|
94
|
+
mismatch("seccomp_profile_sha256");
|
|
95
|
+
if (receipt.sandbox_runtime !== projection.attestation.sandboxRuntime)
|
|
96
|
+
mismatch("sandbox_runtime");
|
|
97
|
+
const denied = receipt.canaries.map((canary) => canary.path).sort();
|
|
98
|
+
if (denied.length !== projection.denyPaths.length || denied.some((entry, index) => entry !== projection.denyPaths[index]))
|
|
99
|
+
mismatch("canaries");
|
|
100
|
+
return receipt;
|
|
101
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GrokAgent, GrokSubscriptionRealm, GrokSubscriptionRealmOptions } from "./grokSubscriptionRealmTypes.js";
|
|
2
|
+
export type { GrokSubscriptionRealm, GrokSubscriptionRealmOptions } from "./grokSubscriptionRealmTypes.js";
|
|
3
|
+
export declare function startGrokSubscriptionRealm(configuredAgents: readonly GrokAgent[], options?: GrokSubscriptionRealmOptions): Promise<GrokSubscriptionRealm>;
|
|
4
|
+
//# sourceMappingURL=grokSubscriptionRealm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokSubscriptionRealm.d.ts","sourceRoot":"","sources":["../../src/runtime/grokSubscriptionRealm.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,SAAS,EAET,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAO3G,wBAAsB,0BAA0B,CAC9C,gBAAgB,EAAE,SAAS,SAAS,EAAE,EACtC,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,qBAAqB,CAAC,CAqChC"}
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { spawnRealTime as spawn } from "./taskClockProcess.js";
|
|
4
|
+
import { lstat, open, rename, unlink } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { terminateChild, trackCliChild } from "../pi/cliProcess.js";
|
|
7
|
+
import { GROK_SUBSCRIPTION_REALM } from "./contractManifest.js";
|
|
8
|
+
import { hasRefreshablePortableCredential } from "./portableCredentialAuth.js";
|
|
9
|
+
import { asGrokAuthenticationRejected } from "./grokAuthenticationError.js";
|
|
10
|
+
const AUTH_FILE = "auth.json";
|
|
11
|
+
const JOURNAL_FILE = "lease.json";
|
|
12
|
+
const STALE_FILE = "stale.json";
|
|
13
|
+
const BOOTSTRAP_FILE = "bootstrap.json";
|
|
14
|
+
const LEASE_FILE = ".daimon-lease";
|
|
15
|
+
const MAX_CONTROL_BYTES = 4_096;
|
|
16
|
+
export async function startGrokSubscriptionRealm(configuredAgents, options = {}) {
|
|
17
|
+
const durablePath = options.durablePath ?? GROK_SUBSCRIPTION_REALM.durableMountPath;
|
|
18
|
+
const bootstrapPath = options.bootstrapPath ?? GROK_SUBSCRIPTION_REALM.bootstrapMountPath;
|
|
19
|
+
await verifyPrivateDirectory(durablePath);
|
|
20
|
+
const lease = await acquireRealmLease(durablePath, options);
|
|
21
|
+
const agents = new Map(configuredAgents.map((agent) => [agent.id, agent]));
|
|
22
|
+
let tail = Promise.resolve();
|
|
23
|
+
let closed = false;
|
|
24
|
+
let closePromise;
|
|
25
|
+
let bootstrapDigest;
|
|
26
|
+
try {
|
|
27
|
+
bootstrapDigest = await initializeRealm(durablePath, bootstrapPath, agents);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
await terminateChild(lease).catch(() => undefined);
|
|
31
|
+
throw redact(error);
|
|
32
|
+
}
|
|
33
|
+
const withCredential = async (agent, operation) => {
|
|
34
|
+
if (closed || agents.get(agent.id)?.runtimeHomePath !== agent.runtimeHomePath)
|
|
35
|
+
throw redact();
|
|
36
|
+
let release;
|
|
37
|
+
const prior = tail;
|
|
38
|
+
tail = new Promise((resolve) => { release = resolve; });
|
|
39
|
+
await prior;
|
|
40
|
+
try {
|
|
41
|
+
if (closed)
|
|
42
|
+
throw redact();
|
|
43
|
+
return await runLeasedTurn(durablePath, bootstrapDigest, agent, operation, options.onTransitionForTest);
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
release();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
withCredential,
|
|
51
|
+
close: () => closePromise ??= (async () => {
|
|
52
|
+
closed = true;
|
|
53
|
+
await tail;
|
|
54
|
+
await terminateChild(lease);
|
|
55
|
+
})()
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async function initializeRealm(durablePath, bootstrapPath, agents) {
|
|
59
|
+
const bootstrap = await readCredential(bootstrapPath);
|
|
60
|
+
try {
|
|
61
|
+
const observedBootstrap = await readBootstrap(path.join(durablePath, BOOTSTRAP_FILE));
|
|
62
|
+
const journal = await readJournal(path.join(durablePath, JOURNAL_FILE));
|
|
63
|
+
if (journal !== undefined) {
|
|
64
|
+
await recoverJournal(durablePath, journal, agents, observedBootstrap?.bootstrap_digest ?? bootstrap.digest);
|
|
65
|
+
}
|
|
66
|
+
const stale = await readStale(path.join(durablePath, STALE_FILE));
|
|
67
|
+
const authority = await readOptionalAuthority(path.join(durablePath, AUTH_FILE));
|
|
68
|
+
const shouldImport = stale !== undefined
|
|
69
|
+
? stale.bootstrap_digest !== bootstrap.digest
|
|
70
|
+
: authority === undefined || (observedBootstrap !== undefined
|
|
71
|
+
&& observedBootstrap.bootstrap_digest !== bootstrap.digest);
|
|
72
|
+
authority?.bytes.fill(0);
|
|
73
|
+
if (shouldImport) {
|
|
74
|
+
await atomicCredentialWrite(path.join(durablePath, AUTH_FILE), bootstrap.bytes);
|
|
75
|
+
await unlink(path.join(durablePath, STALE_FILE)).catch(ignoreMissing);
|
|
76
|
+
await syncDirectory(durablePath);
|
|
77
|
+
}
|
|
78
|
+
if (shouldImport || observedBootstrap === undefined) {
|
|
79
|
+
await writeBootstrap(path.join(durablePath, BOOTSTRAP_FILE), bootstrap.digest);
|
|
80
|
+
}
|
|
81
|
+
if (await readStale(path.join(durablePath, STALE_FILE)) !== undefined)
|
|
82
|
+
throw redact();
|
|
83
|
+
return bootstrap.digest;
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
bootstrap.bytes.fill(0);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function runLeasedTurn(durablePath, bootstrapDigest, agent, operation, onTransition) {
|
|
90
|
+
if (await readStale(path.join(durablePath, STALE_FILE)) !== undefined)
|
|
91
|
+
throw redact();
|
|
92
|
+
await verifyPrivateDirectory(path.dirname(path.join(agent.runtimeHomePath, GROK_SUBSCRIPTION_REALM.agentCredentialRelativePath)));
|
|
93
|
+
const target = path.join(agent.runtimeHomePath, GROK_SUBSCRIPTION_REALM.agentCredentialRelativePath);
|
|
94
|
+
await assertAbsent(target);
|
|
95
|
+
const authority = await readCredential(path.join(durablePath, AUTH_FILE));
|
|
96
|
+
const journalPath = path.join(durablePath, JOURNAL_FILE);
|
|
97
|
+
try {
|
|
98
|
+
await writeJournal(journalPath, { agent_id: agent.id, source_digest: authority.digest, state: "preparing", version: "noopolis.daimon.grok-credential-lease.v1" });
|
|
99
|
+
await atomicCredentialWrite(target, authority.bytes);
|
|
100
|
+
await writeJournal(journalPath, { agent_id: agent.id, source_digest: authority.digest, state: "active", version: "noopolis.daimon.grok-credential-lease.v1" });
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
authority.bytes.fill(0);
|
|
104
|
+
}
|
|
105
|
+
let result;
|
|
106
|
+
let operationError;
|
|
107
|
+
try {
|
|
108
|
+
result = await operation();
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
operationError = error;
|
|
112
|
+
}
|
|
113
|
+
if (asGrokAuthenticationRejected(operationError) !== undefined) {
|
|
114
|
+
await unlink(target).catch(ignoreMissing);
|
|
115
|
+
await syncDirectory(path.dirname(target));
|
|
116
|
+
await markStale(durablePath, bootstrapDigest);
|
|
117
|
+
throw redact();
|
|
118
|
+
}
|
|
119
|
+
const candidate = await tryReadCredential(target);
|
|
120
|
+
if (candidate === undefined) {
|
|
121
|
+
await unlink(target).catch(ignoreMissing);
|
|
122
|
+
await syncDirectory(path.dirname(target));
|
|
123
|
+
await markStale(durablePath, bootstrapDigest);
|
|
124
|
+
throw redact(operationError);
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
await writeJournal(journalPath, {
|
|
128
|
+
agent_id: agent.id,
|
|
129
|
+
promoted_digest: candidate.digest,
|
|
130
|
+
source_digest: authority.digest,
|
|
131
|
+
state: "promoting",
|
|
132
|
+
version: "noopolis.daimon.grok-credential-lease.v1"
|
|
133
|
+
});
|
|
134
|
+
await onTransition?.("promotion_prepared");
|
|
135
|
+
await atomicCredentialWrite(path.join(durablePath, AUTH_FILE), candidate.bytes);
|
|
136
|
+
await onTransition?.("authority_replaced");
|
|
137
|
+
await writeJournal(journalPath, {
|
|
138
|
+
agent_id: agent.id,
|
|
139
|
+
promoted_digest: candidate.digest,
|
|
140
|
+
source_digest: authority.digest,
|
|
141
|
+
state: "promoted",
|
|
142
|
+
version: "noopolis.daimon.grok-credential-lease.v1"
|
|
143
|
+
});
|
|
144
|
+
await unlink(target).catch(ignoreMissing);
|
|
145
|
+
await syncDirectory(path.dirname(target));
|
|
146
|
+
await unlink(journalPath).catch(ignoreMissing);
|
|
147
|
+
await syncDirectory(durablePath);
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
candidate.bytes.fill(0);
|
|
151
|
+
}
|
|
152
|
+
if (operationError !== undefined)
|
|
153
|
+
throw operationError;
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
async function recoverJournal(durablePath, journal, agents, bootstrapDigest) {
|
|
157
|
+
const agent = agents.get(journal.agent_id);
|
|
158
|
+
const target = agent === undefined ? undefined
|
|
159
|
+
: path.join(agent.runtimeHomePath, GROK_SUBSCRIPTION_REALM.agentCredentialRelativePath);
|
|
160
|
+
if (target !== undefined)
|
|
161
|
+
await verifyPrivateDirectory(path.dirname(target));
|
|
162
|
+
const authority = await readCredential(path.join(durablePath, AUTH_FILE));
|
|
163
|
+
const authorityDigest = authority.digest;
|
|
164
|
+
try {
|
|
165
|
+
const expected = journal.state === "promoted" ? [journal.promoted_digest]
|
|
166
|
+
: journal.state === "promoting" ? [journal.source_digest, journal.promoted_digest]
|
|
167
|
+
: [journal.source_digest];
|
|
168
|
+
if (!expected.includes(authorityDigest)) {
|
|
169
|
+
if (target !== undefined) {
|
|
170
|
+
await unlink(target).catch(ignoreMissing);
|
|
171
|
+
await syncDirectory(path.dirname(target));
|
|
172
|
+
}
|
|
173
|
+
await markStale(durablePath, bootstrapDigest);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
authority.bytes.fill(0);
|
|
179
|
+
}
|
|
180
|
+
if (journal.state === "promoted") {
|
|
181
|
+
if (target !== undefined) {
|
|
182
|
+
await unlink(target).catch(ignoreMissing);
|
|
183
|
+
await syncDirectory(path.dirname(target));
|
|
184
|
+
}
|
|
185
|
+
await unlink(path.join(durablePath, JOURNAL_FILE)).catch(ignoreMissing);
|
|
186
|
+
await syncDirectory(durablePath);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (journal.state === "preparing") {
|
|
190
|
+
if (target !== undefined)
|
|
191
|
+
await unlink(target).catch(ignoreMissing);
|
|
192
|
+
await unlink(path.join(durablePath, JOURNAL_FILE)).catch(ignoreMissing);
|
|
193
|
+
await syncDirectory(durablePath);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const candidate = target === undefined ? undefined : await tryReadCredential(target);
|
|
197
|
+
if (candidate === undefined) {
|
|
198
|
+
if (target !== undefined) {
|
|
199
|
+
await unlink(target).catch(ignoreMissing);
|
|
200
|
+
await syncDirectory(path.dirname(target));
|
|
201
|
+
}
|
|
202
|
+
await markStale(durablePath, bootstrapDigest);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
if (journal.state === "promoting" && candidate.digest !== journal.promoted_digest) {
|
|
207
|
+
await markStale(durablePath, bootstrapDigest);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (journal.state === "active")
|
|
211
|
+
await writeJournal(path.join(durablePath, JOURNAL_FILE), { ...journal, promoted_digest: candidate.digest, state: "promoting" });
|
|
212
|
+
if (authorityDigest === journal.source_digest) {
|
|
213
|
+
await atomicCredentialWrite(path.join(durablePath, AUTH_FILE), candidate.bytes);
|
|
214
|
+
}
|
|
215
|
+
await writeJournal(path.join(durablePath, JOURNAL_FILE), {
|
|
216
|
+
...journal, promoted_digest: candidate.digest, state: "promoted"
|
|
217
|
+
});
|
|
218
|
+
await unlink(target).catch(ignoreMissing);
|
|
219
|
+
await syncDirectory(path.dirname(target));
|
|
220
|
+
await unlink(path.join(durablePath, JOURNAL_FILE)).catch(ignoreMissing);
|
|
221
|
+
await syncDirectory(durablePath);
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
candidate.bytes.fill(0);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function markStale(durablePath, bootstrapDigest) {
|
|
228
|
+
await atomicJsonWrite(path.join(durablePath, STALE_FILE), {
|
|
229
|
+
bootstrap_digest: bootstrapDigest,
|
|
230
|
+
version: "noopolis.daimon.grok-credential-stale.v1"
|
|
231
|
+
});
|
|
232
|
+
await unlink(path.join(durablePath, JOURNAL_FILE)).catch(ignoreMissing);
|
|
233
|
+
await syncDirectory(durablePath);
|
|
234
|
+
}
|
|
235
|
+
async function readCredential(file) {
|
|
236
|
+
let handle;
|
|
237
|
+
try {
|
|
238
|
+
const before = await lstat(file);
|
|
239
|
+
assertCredentialIdentity(before);
|
|
240
|
+
handle = await open(file, constants.O_RDONLY | noFollow());
|
|
241
|
+
const opened = await handle.stat();
|
|
242
|
+
assertCredentialIdentity(opened);
|
|
243
|
+
if (!sameIdentity(before, opened))
|
|
244
|
+
throw new Error("changed");
|
|
245
|
+
const bytes = await handle.readFile();
|
|
246
|
+
const after = await handle.stat();
|
|
247
|
+
if (!sameIdentity(opened, after) || !hasRefreshablePortableCredential("grok", bytes)) {
|
|
248
|
+
bytes.fill(0);
|
|
249
|
+
throw new Error("invalid");
|
|
250
|
+
}
|
|
251
|
+
return { bytes, digest: createHash("sha256").update(bytes).digest("hex") };
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
throw redact();
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
await handle?.close().catch(() => undefined);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function tryReadCredential(file) {
|
|
261
|
+
try {
|
|
262
|
+
return await readCredential(file);
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async function readOptionalAuthority(file) {
|
|
269
|
+
try {
|
|
270
|
+
return await readCredential(file);
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
try {
|
|
274
|
+
await lstat(file);
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
if (error.code === "ENOENT")
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
throw redact();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
async function atomicCredentialWrite(file, bytes) {
|
|
284
|
+
await atomicWrite(file, bytes, GROK_SUBSCRIPTION_REALM.fileMode);
|
|
285
|
+
const checked = await readCredential(file);
|
|
286
|
+
checked.bytes.fill(0);
|
|
287
|
+
}
|
|
288
|
+
async function atomicJsonWrite(file, value) {
|
|
289
|
+
await atomicWrite(file, Buffer.from(`${JSON.stringify(value)}\n`), 0o600);
|
|
290
|
+
}
|
|
291
|
+
async function atomicWrite(file, bytes, mode) {
|
|
292
|
+
const temporary = path.join(path.dirname(file), `.${path.basename(file)}.${randomUUID()}.tmp`);
|
|
293
|
+
let handle;
|
|
294
|
+
try {
|
|
295
|
+
handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | noFollow(), mode);
|
|
296
|
+
await handle.writeFile(bytes);
|
|
297
|
+
await handle.chmod(mode);
|
|
298
|
+
await handle.sync();
|
|
299
|
+
await handle.close();
|
|
300
|
+
handle = undefined;
|
|
301
|
+
await rename(temporary, file);
|
|
302
|
+
await syncDirectory(path.dirname(file));
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
throw redact();
|
|
306
|
+
}
|
|
307
|
+
finally {
|
|
308
|
+
await handle?.close().catch(() => undefined);
|
|
309
|
+
await unlink(temporary).catch(() => undefined);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async function writeJournal(file, value) { await atomicJsonWrite(file, value); }
|
|
313
|
+
async function readJournal(file) {
|
|
314
|
+
return readPrivateJson(file, (value) => {
|
|
315
|
+
const candidate = value;
|
|
316
|
+
if (candidate.version !== "noopolis.daimon.grok-credential-lease.v1" || !["active", "preparing", "promoted", "promoting"].includes(candidate.state ?? "")
|
|
317
|
+
|| typeof candidate.agent_id !== "string" || !candidate.agent_id || !/^[a-f0-9]{64}$/u.test(candidate.source_digest ?? "")
|
|
318
|
+
|| (["promoted", "promoting"].includes(candidate.state ?? "") && !/^[a-f0-9]{64}$/u.test(candidate.promoted_digest ?? "")))
|
|
319
|
+
throw new Error("invalid");
|
|
320
|
+
return candidate;
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
async function readStale(file) {
|
|
324
|
+
return readPrivateJson(file, (value) => {
|
|
325
|
+
const candidate = value;
|
|
326
|
+
if (candidate.version !== "noopolis.daimon.grok-credential-stale.v1" || typeof candidate.bootstrap_digest !== "string" || !/^[a-f0-9]{64}$/u.test(candidate.bootstrap_digest))
|
|
327
|
+
throw new Error("invalid");
|
|
328
|
+
return { bootstrap_digest: candidate.bootstrap_digest };
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
async function readBootstrap(file) {
|
|
332
|
+
return readPrivateJson(file, (value) => {
|
|
333
|
+
const candidate = value;
|
|
334
|
+
if (candidate.version !== "noopolis.daimon.grok-bootstrap-observation.v1" || typeof candidate.bootstrap_digest !== "string" || !/^[a-f0-9]{64}$/u.test(candidate.bootstrap_digest))
|
|
335
|
+
throw new Error("invalid");
|
|
336
|
+
return { bootstrap_digest: candidate.bootstrap_digest };
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async function writeBootstrap(file, bootstrapDigest) {
|
|
340
|
+
await atomicJsonWrite(file, {
|
|
341
|
+
bootstrap_digest: bootstrapDigest,
|
|
342
|
+
version: "noopolis.daimon.grok-bootstrap-observation.v1"
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
async function readPrivateJson(file, parse) {
|
|
346
|
+
let handle;
|
|
347
|
+
let bytes;
|
|
348
|
+
try {
|
|
349
|
+
const before = await lstat(file);
|
|
350
|
+
assertPrivateFileIdentity(before, MAX_CONTROL_BYTES);
|
|
351
|
+
handle = await open(file, constants.O_RDONLY | noFollow());
|
|
352
|
+
const opened = await handle.stat();
|
|
353
|
+
assertPrivateFileIdentity(opened, MAX_CONTROL_BYTES);
|
|
354
|
+
if (!sameIdentity(before, opened))
|
|
355
|
+
throw new Error("changed");
|
|
356
|
+
bytes = await handle.readFile();
|
|
357
|
+
const after = await handle.stat();
|
|
358
|
+
if (!sameIdentity(opened, after))
|
|
359
|
+
throw new Error("changed");
|
|
360
|
+
return parse(JSON.parse(bytes.toString("utf8")));
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
if (error.code === "ENOENT")
|
|
364
|
+
return undefined;
|
|
365
|
+
throw redact();
|
|
366
|
+
}
|
|
367
|
+
finally {
|
|
368
|
+
bytes?.fill(0);
|
|
369
|
+
await handle?.close().catch(() => undefined);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
async function verifyPrivateDirectory(directory) {
|
|
373
|
+
try {
|
|
374
|
+
const entry = await lstat(directory);
|
|
375
|
+
if (!entry.isDirectory() || entry.isSymbolicLink() || entry.uid !== process.getuid?.() || (entry.mode & 0o777) !== GROK_SUBSCRIPTION_REALM.directoryMode)
|
|
376
|
+
throw new Error("unsafe");
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
throw redact();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
async function assertAbsent(file) {
|
|
383
|
+
try {
|
|
384
|
+
await lstat(file);
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
if (error.code === "ENOENT")
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
throw redact();
|
|
391
|
+
}
|
|
392
|
+
async function acquireRealmLease(durablePath, options) {
|
|
393
|
+
let lock;
|
|
394
|
+
let child;
|
|
395
|
+
try {
|
|
396
|
+
lock = await open(path.join(durablePath, LEASE_FILE), constants.O_CREAT | constants.O_RDWR | noFollow(), 0o600);
|
|
397
|
+
const entry = await lock.stat();
|
|
398
|
+
if (!entry.isFile() || entry.uid !== process.getuid?.() || entry.nlink !== 1 || (entry.mode & 0o777) !== 0o600)
|
|
399
|
+
throw new Error("unsafe");
|
|
400
|
+
child = trackCliChild(spawn(options.shell ?? "/bin/sh", ["-c", "\"$1\" --exclusive --nonblock --conflict-exit-code 73 3 || exit 73; printf 'ready\\n'; IFS= read -r _hold || :", "daimon-grok-lease", options.flock ?? "flock"], { detached: process.platform !== "win32", env: { LANG: "C", LC_ALL: "C", PATH: process.env.PATH }, stdio: ["pipe", "pipe", "ignore", lock.fd] }));
|
|
401
|
+
await waitForReady(child);
|
|
402
|
+
return child;
|
|
403
|
+
}
|
|
404
|
+
catch {
|
|
405
|
+
if (child !== undefined)
|
|
406
|
+
await terminateChild(child).catch(() => undefined);
|
|
407
|
+
throw redact();
|
|
408
|
+
}
|
|
409
|
+
finally {
|
|
410
|
+
await lock?.close().catch(() => undefined);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
async function waitForReady(child) {
|
|
414
|
+
await new Promise((resolve, reject) => {
|
|
415
|
+
const timer = setTimeout(() => reject(new Error("timeout")), 5_000);
|
|
416
|
+
child.stdout?.once("data", (value) => { clearTimeout(timer); value.toString("utf8") === "ready\n" ? resolve() : reject(new Error("invalid")); });
|
|
417
|
+
child.once("close", () => { clearTimeout(timer); reject(new Error("closed")); });
|
|
418
|
+
child.once("error", () => { clearTimeout(timer); reject(new Error("failed")); });
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
async function syncDirectory(directory) { const handle = await open(directory, constants.O_RDONLY); try {
|
|
422
|
+
await handle.sync();
|
|
423
|
+
}
|
|
424
|
+
finally {
|
|
425
|
+
await handle.close();
|
|
426
|
+
} }
|
|
427
|
+
const ignoreMissing = (error) => { if (error.code !== "ENOENT")
|
|
428
|
+
throw error; };
|
|
429
|
+
const noFollow = () => constants.O_NOFOLLOW ?? 0;
|
|
430
|
+
const sameIdentity = (left, right) => left.dev === right.dev && left.ino === right.ino && left.mode === right.mode && left.nlink === right.nlink && left.size === right.size && left.uid === right.uid && left.mtimeMs === right.mtimeMs;
|
|
431
|
+
const assertCredentialIdentity = (entry) => { if (!entry.isFile() || entry.isSymbolicLink() || Number(entry.uid) !== process.getuid?.() || Number(entry.nlink) !== 1 || (Number(entry.mode) & 0o777) !== GROK_SUBSCRIPTION_REALM.fileMode || Number(entry.size) < 1 || Number(entry.size) > GROK_SUBSCRIPTION_REALM.maxCredentialBytes)
|
|
432
|
+
throw new Error("unsafe"); };
|
|
433
|
+
const assertPrivateFileIdentity = (entry, maxBytes) => { if (!entry.isFile() || entry.isSymbolicLink() || Number(entry.uid) !== process.getuid?.() || Number(entry.nlink) !== 1 || (Number(entry.mode) & 0o777) !== 0o600 || Number(entry.size) < 1 || Number(entry.size) > maxBytes)
|
|
434
|
+
throw new Error("unsafe"); };
|
|
435
|
+
const redact = (_cause) => new Error("Grok subscription credential realm is unavailable or stale");
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { OrganizationRuntimeAgentConfig } from "./organizationRuntime.js";
|
|
2
|
+
export type GrokAgent = OrganizationRuntimeAgentConfig & {
|
|
3
|
+
engine: {
|
|
4
|
+
kind: "grok";
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export type GrokCredentialJournal = Readonly<{
|
|
8
|
+
agent_id: string;
|
|
9
|
+
promoted_digest?: string;
|
|
10
|
+
source_digest: string;
|
|
11
|
+
state: "active" | "preparing" | "promoted" | "promoting";
|
|
12
|
+
version: "noopolis.daimon.grok-credential-lease.v1";
|
|
13
|
+
}>;
|
|
14
|
+
export type GrokSubscriptionRealm = Readonly<{
|
|
15
|
+
withCredential<T>(agent: GrokAgent, operation: () => Promise<T>): Promise<T>;
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
}>;
|
|
18
|
+
export type GrokSubscriptionRealmOptions = Readonly<{
|
|
19
|
+
bootstrapPath?: string;
|
|
20
|
+
durablePath?: string;
|
|
21
|
+
flock?: string;
|
|
22
|
+
/** @internal deterministic crash-transition test seam. */
|
|
23
|
+
onTransitionForTest?: (stage: "authority_replaced" | "promotion_prepared") => Promise<void> | void;
|
|
24
|
+
shell?: string;
|
|
25
|
+
}>;
|
|
26
|
+
//# sourceMappingURL=grokSubscriptionRealmTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokSubscriptionRealmTypes.d.ts","sourceRoot":"","sources":["../../src/runtime/grokSubscriptionRealmTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG,8BAA8B,GAAG;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAEtF,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;IACzD,OAAO,EAAE,0CAA0C,CAAC;CACrD,CAAC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC,CAAC;AAEH,MAAM,MAAM,4BAA4B,GAAG,QAAQ,CAAC;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,GAAG,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACnG,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|