@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,281 @@
|
|
|
1
|
+
import { resolveRunId } from "../observability/causalEvents.js";
|
|
2
|
+
import { candidateFromDelivery, WAKE_ACCEPTANCE_FILE_BYTES_MAX, WAKE_ACCEPTANCE_VERSION, WakeAcceptanceError, emptyWakeAcceptanceState, parseWakeAcceptanceState, pruneCompletedRecords, serializeWakeAcceptanceState } from "./wakeAcceptanceSchema.js";
|
|
3
|
+
import { WakeAcceptanceFs } from "./wakeAcceptanceFs.js";
|
|
4
|
+
const UTF8 = "utf8";
|
|
5
|
+
const COMPLETED_STATE = "completed";
|
|
6
|
+
const MAX_SEQUENCE = Number.MAX_SAFE_INTEGER;
|
|
7
|
+
const CAPABILITY_BRAND = Symbol("wake-acceptance-capability");
|
|
8
|
+
export class WakeAcceptanceStore {
|
|
9
|
+
runtimeHomePath;
|
|
10
|
+
agentId;
|
|
11
|
+
fs;
|
|
12
|
+
runId;
|
|
13
|
+
capabilities = new WeakMap();
|
|
14
|
+
constructor(runtimeHomePath, agentId, fs = new WakeAcceptanceFs(runtimeHomePath)) {
|
|
15
|
+
this.runtimeHomePath = runtimeHomePath;
|
|
16
|
+
this.agentId = agentId;
|
|
17
|
+
this.fs = fs;
|
|
18
|
+
this.runId = resolveRunId();
|
|
19
|
+
}
|
|
20
|
+
getAcceptanceFilePath() {
|
|
21
|
+
return this.fs.stateFilePath;
|
|
22
|
+
}
|
|
23
|
+
candidateFromDelivery(event) {
|
|
24
|
+
return candidateFromDelivery({
|
|
25
|
+
event,
|
|
26
|
+
runId: this.runId,
|
|
27
|
+
trustedAgentId: this.agentId
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
candidateFromEvent(event) {
|
|
31
|
+
return this.candidateFromDelivery(event);
|
|
32
|
+
}
|
|
33
|
+
async begin(event) {
|
|
34
|
+
const attempt = this.candidateFromDelivery(event);
|
|
35
|
+
return this.beginFromAttempt(attempt);
|
|
36
|
+
}
|
|
37
|
+
async beginFromAttempt(attempt) {
|
|
38
|
+
let capability;
|
|
39
|
+
const admission = await this.withClaim(async () => {
|
|
40
|
+
await this.fs.cleanupTemps();
|
|
41
|
+
const state = await this.loadStateUnsafe();
|
|
42
|
+
const existing = state.records.find((record) => record.identity === attempt.identity);
|
|
43
|
+
if (existing !== undefined) {
|
|
44
|
+
if (existing.digest !== attempt.digest) {
|
|
45
|
+
throw this.makeError("wake_delivery_conflict", true);
|
|
46
|
+
}
|
|
47
|
+
if (existing.state !== COMPLETED_STATE) {
|
|
48
|
+
throw this.makeError("wake_delivery_incomplete", true);
|
|
49
|
+
}
|
|
50
|
+
return "replay";
|
|
51
|
+
}
|
|
52
|
+
const nextSequence = this.nextSequence(state.next_sequence);
|
|
53
|
+
const nextState = this.makeRecord(attempt, "accepted", nextSequence);
|
|
54
|
+
const withAddition = pruneCompletedRecords([...state.records, nextState]);
|
|
55
|
+
const nextStore = {
|
|
56
|
+
...state,
|
|
57
|
+
next_sequence: nextState.sequence,
|
|
58
|
+
records: withAddition
|
|
59
|
+
};
|
|
60
|
+
await this.persistState(nextStore);
|
|
61
|
+
return nextState;
|
|
62
|
+
}, (result) => {
|
|
63
|
+
if (result === "replay") {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
capability = this.createCapability({
|
|
67
|
+
identity: result.identity,
|
|
68
|
+
digest: result.digest,
|
|
69
|
+
phase: "accepted",
|
|
70
|
+
sequence: result.sequence
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
if (admission === "replay") {
|
|
74
|
+
return { mode: "replay" };
|
|
75
|
+
}
|
|
76
|
+
if (capability === undefined) {
|
|
77
|
+
throw this.makeError("wake_acceptance_store_corrupt", false);
|
|
78
|
+
}
|
|
79
|
+
return { mode: "run", capability };
|
|
80
|
+
}
|
|
81
|
+
async markInvoking(capability) {
|
|
82
|
+
const issued = this.consumeCapability(capability, "accepted");
|
|
83
|
+
let replacement;
|
|
84
|
+
return this.withClaim(async () => {
|
|
85
|
+
return this.transitionAttempt(issued, "invoking");
|
|
86
|
+
}, (record) => {
|
|
87
|
+
this.capabilities.delete(capability);
|
|
88
|
+
replacement = this.createCapability({
|
|
89
|
+
identity: record.identity,
|
|
90
|
+
digest: record.digest,
|
|
91
|
+
phase: "invoking",
|
|
92
|
+
sequence: record.sequence
|
|
93
|
+
});
|
|
94
|
+
}).then(() => {
|
|
95
|
+
if (replacement === undefined) {
|
|
96
|
+
throw this.makeError("wake_acceptance_store_corrupt", false);
|
|
97
|
+
}
|
|
98
|
+
return replacement;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async markCompleted(capability) {
|
|
102
|
+
const issued = this.consumeCapability(capability, "invoking");
|
|
103
|
+
await this.withClaim(async () => {
|
|
104
|
+
await this.transitionAttempt(issued, COMPLETED_STATE);
|
|
105
|
+
}, () => {
|
|
106
|
+
this.capabilities.delete(capability);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async markIncomplete(capability) {
|
|
110
|
+
const issued = this.consumeCapability(capability, "accepted", "invoking");
|
|
111
|
+
await this.withClaim(async () => {
|
|
112
|
+
await this.transitionAttempt(issued, "incomplete");
|
|
113
|
+
}, () => {
|
|
114
|
+
this.capabilities.delete(capability);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async loadState() {
|
|
118
|
+
const raw = await this.fs.readStateText();
|
|
119
|
+
if (raw === undefined) {
|
|
120
|
+
return emptyWakeAcceptanceState({
|
|
121
|
+
runId: this.runId,
|
|
122
|
+
agentId: this.agentId
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
return parseWakeAcceptanceState(JSON.parse(raw), { runId: this.runId, agentId: this.agentId });
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error instanceof WakeAcceptanceError) {
|
|
130
|
+
throw this.makeError(error.code, true);
|
|
131
|
+
}
|
|
132
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async loadStateUnsafe() {
|
|
136
|
+
return this.loadState();
|
|
137
|
+
}
|
|
138
|
+
makeRecord(attempt, state, sequence) {
|
|
139
|
+
return {
|
|
140
|
+
body_sha256: attempt.bodySha256,
|
|
141
|
+
context_id: attempt.contextId,
|
|
142
|
+
digest: attempt.digest,
|
|
143
|
+
event_id: attempt.eventId,
|
|
144
|
+
identity: attempt.identity,
|
|
145
|
+
kind: attempt.kind,
|
|
146
|
+
sender: attempt.sender,
|
|
147
|
+
state,
|
|
148
|
+
sequence,
|
|
149
|
+
target: attempt.target
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
makeError(code, safeToRelease) {
|
|
153
|
+
const error = new WakeAcceptanceError(code);
|
|
154
|
+
error.safeToRelease = safeToRelease;
|
|
155
|
+
return error;
|
|
156
|
+
}
|
|
157
|
+
canRelease(error) {
|
|
158
|
+
if (!(error instanceof WakeAcceptanceError)) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
const info = error;
|
|
162
|
+
return info.safeToRelease !== false;
|
|
163
|
+
}
|
|
164
|
+
async withClaim(operation, afterRelease) {
|
|
165
|
+
await this.fs.acquireClaim();
|
|
166
|
+
let result;
|
|
167
|
+
try {
|
|
168
|
+
result = await operation();
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (this.canRelease(error)) {
|
|
172
|
+
try {
|
|
173
|
+
await this.fs.releaseClaim();
|
|
174
|
+
}
|
|
175
|
+
catch (releaseError) {
|
|
176
|
+
if (releaseError instanceof WakeAcceptanceError) {
|
|
177
|
+
throw releaseError;
|
|
178
|
+
}
|
|
179
|
+
throw this.makeError("wake_acceptance_store_corrupt", false);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
await this.fs.releaseClaim();
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (error instanceof WakeAcceptanceError) {
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
throw this.makeError("wake_acceptance_store_corrupt", false);
|
|
192
|
+
}
|
|
193
|
+
if (afterRelease !== undefined) {
|
|
194
|
+
await afterRelease(result);
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
createCapability(record) {
|
|
199
|
+
const token = {
|
|
200
|
+
[CAPABILITY_BRAND]: record.phase
|
|
201
|
+
};
|
|
202
|
+
this.capabilities.set(token, record);
|
|
203
|
+
return token;
|
|
204
|
+
}
|
|
205
|
+
consumeCapability(capability, ...phases) {
|
|
206
|
+
const record = this.capabilities.get(capability);
|
|
207
|
+
if (record === undefined) {
|
|
208
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
209
|
+
}
|
|
210
|
+
if (!phases.includes(record.phase)) {
|
|
211
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
212
|
+
}
|
|
213
|
+
return record;
|
|
214
|
+
}
|
|
215
|
+
async transitionAttempt(data, nextState) {
|
|
216
|
+
const state = await this.loadStateUnsafe();
|
|
217
|
+
const index = state.records.findIndex((record) => record.identity === data.identity);
|
|
218
|
+
if (index === -1) {
|
|
219
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
220
|
+
}
|
|
221
|
+
const existing = state.records[index];
|
|
222
|
+
if (existing.digest !== data.digest) {
|
|
223
|
+
throw this.makeError("wake_delivery_conflict", true);
|
|
224
|
+
}
|
|
225
|
+
if (data.sequence !== existing.sequence) {
|
|
226
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
227
|
+
}
|
|
228
|
+
if (nextState === "invoking" && existing.state !== "accepted") {
|
|
229
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
230
|
+
}
|
|
231
|
+
if (nextState === COMPLETED_STATE && existing.state !== "invoking") {
|
|
232
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
233
|
+
}
|
|
234
|
+
if (nextState === "incomplete" && existing.state !== "accepted" && existing.state !== "invoking") {
|
|
235
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
236
|
+
}
|
|
237
|
+
if (nextState === existing.state) {
|
|
238
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
239
|
+
}
|
|
240
|
+
const nextSequence = this.nextSequence(state.next_sequence);
|
|
241
|
+
const next = {
|
|
242
|
+
...existing,
|
|
243
|
+
sequence: nextSequence,
|
|
244
|
+
state: nextState
|
|
245
|
+
};
|
|
246
|
+
const records = [...state.records];
|
|
247
|
+
records[index] = next;
|
|
248
|
+
const nextStore = {
|
|
249
|
+
...state,
|
|
250
|
+
next_sequence: nextSequence,
|
|
251
|
+
records: pruneCompletedRecords(records)
|
|
252
|
+
};
|
|
253
|
+
await this.persistState(nextStore);
|
|
254
|
+
return next;
|
|
255
|
+
}
|
|
256
|
+
async persistState(state) {
|
|
257
|
+
const body = serializeWakeAcceptanceState(state);
|
|
258
|
+
if (Buffer.byteLength(body, UTF8) > WAKE_ACCEPTANCE_FILE_BYTES_MAX) {
|
|
259
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
260
|
+
}
|
|
261
|
+
if (state.version !== WAKE_ACCEPTANCE_VERSION) {
|
|
262
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
263
|
+
}
|
|
264
|
+
const validated = parseWakeAcceptanceState(JSON.parse(body), {
|
|
265
|
+
runId: this.runId,
|
|
266
|
+
agentId: this.agentId
|
|
267
|
+
});
|
|
268
|
+
const canonical = serializeWakeAcceptanceState(validated);
|
|
269
|
+
if (Buffer.byteLength(canonical, UTF8) > WAKE_ACCEPTANCE_FILE_BYTES_MAX) {
|
|
270
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
271
|
+
}
|
|
272
|
+
await this.fs.writeStateText(canonical);
|
|
273
|
+
}
|
|
274
|
+
nextSequence(previous) {
|
|
275
|
+
if (previous >= MAX_SEQUENCE) {
|
|
276
|
+
throw this.makeError("wake_acceptance_store_corrupt", true);
|
|
277
|
+
}
|
|
278
|
+
return previous + 1;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
export { WAKE_ACCEPTANCE_VERSION, WakeAcceptanceError } from "./wakeAcceptanceSchema.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { lstat, mkdir, open, readdir, readFile, rename, unlink } from "node:fs/promises";
|
|
2
|
+
export interface WakeAcceptanceFsHooks {
|
|
3
|
+
preWrite?: (tempPath: string) => void | Promise<void>;
|
|
4
|
+
preSync?: (tempPath: string) => void | Promise<void>;
|
|
5
|
+
preClose?: (tempPath: string) => void | Promise<void>;
|
|
6
|
+
preRename?: (tempPath: string, finalPath: string) => void | Promise<void>;
|
|
7
|
+
preDirectorySync?: (directoryPath: string) => void | Promise<void>;
|
|
8
|
+
preClaimAcquire?: () => void | Promise<void>;
|
|
9
|
+
preClaimRelease?: () => void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface WakeAcceptanceFsDependencies {
|
|
12
|
+
lstat: typeof lstat;
|
|
13
|
+
mkdir: typeof mkdir;
|
|
14
|
+
open: typeof open;
|
|
15
|
+
readdir: typeof readdir;
|
|
16
|
+
readFile: typeof readFile;
|
|
17
|
+
rename: typeof rename;
|
|
18
|
+
unlink: typeof unlink;
|
|
19
|
+
syncDirectory: (directoryPath: string) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export interface WakeAcceptanceFsOptions {
|
|
22
|
+
dependencies?: Partial<WakeAcceptanceFsDependencies>;
|
|
23
|
+
hooks?: WakeAcceptanceFsHooks;
|
|
24
|
+
randomUUID?: () => string;
|
|
25
|
+
}
|
|
26
|
+
export declare class WakeAcceptanceFs {
|
|
27
|
+
readonly runtimeHomePath: string;
|
|
28
|
+
readonly stateDirectoryPath: string;
|
|
29
|
+
readonly stateFilePath: string;
|
|
30
|
+
readonly lockPath: string;
|
|
31
|
+
readonly deps: WakeAcceptanceFsDependencies;
|
|
32
|
+
private readonly randomId;
|
|
33
|
+
private readonly hooks;
|
|
34
|
+
constructor(runtimeHomePath: string, options?: WakeAcceptanceFsOptions);
|
|
35
|
+
assertRuntimeDirectory(): Promise<void>;
|
|
36
|
+
assertStoreDirectory(): Promise<void>;
|
|
37
|
+
acquireClaim(): Promise<void>;
|
|
38
|
+
releaseClaim(): Promise<void>;
|
|
39
|
+
readStateText(): Promise<string | undefined>;
|
|
40
|
+
private removeOwnedTemp;
|
|
41
|
+
writeStateText(body: string): Promise<void>;
|
|
42
|
+
cleanupTemps(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=wakeAcceptanceFs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wakeAcceptanceFs.d.ts","sourceRoot":"","sources":["../../src/pi/wakeAcceptanceFs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAmB,MAAM,kBAAkB,CAAC;AAwF1G,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,gBAAgB,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,eAAe,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,eAAe,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,QAAQ,EAAE,OAAO,QAAQ,CAAC;IAC1B,MAAM,EAAE,OAAO,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,MAAM,CAAC;IACtB,aAAa,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,uBAAuB;IACtC,YAAY,CAAC,EAAE,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACrD,KAAK,CAAC,EAAE,qBAAqB,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC;CAC3B;AAED,qBAAa,gBAAgB;IAQf,QAAQ,CAAC,eAAe,EAAE,MAAM;IAP5C,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,4BAA4B,CAAC;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IACxC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwB;gBAEzB,eAAe,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B;IAmB7E,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAiCvC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAkCrC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAsC7B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAa7B,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;YAsBpC,eAAe;IAavB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA6E3C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAqBpC"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, open, readdir, readFile, rename, unlink } from "node:fs/promises";
|
|
3
|
+
import { open as openDirectory } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { WAKE_ACCEPTANCE_FILE, WAKE_ACCEPTANCE_FILE_BYTES_MAX } from "./wakeAcceptanceSchema.js";
|
|
6
|
+
import { WakeAcceptanceError } from "./wakeAcceptanceSchema.js";
|
|
7
|
+
const UTF8 = "utf8";
|
|
8
|
+
const isNoEnt = (value) => Boolean(value && typeof value === "object" && "code" in value && value.code === "ENOENT");
|
|
9
|
+
const isEEXIST = (value) => Boolean(value && typeof value === "object" && "code" in value && value.code === "EEXIST");
|
|
10
|
+
const isExactMode = (mode, expected) => (mode & 0o777) === expected;
|
|
11
|
+
const hasGroupOrWorldWrite = (mode) => (mode & 0o022) !== 0;
|
|
12
|
+
const isSymbolic = (stats) => stats.isSymbolicLink();
|
|
13
|
+
const safeDirectory = (stats) => {
|
|
14
|
+
if (!stats.isDirectory() || isSymbolic(stats) || hasGroupOrWorldWrite(stats.mode)) {
|
|
15
|
+
throw new WakeAcceptanceError("wake_acceptance_store_corrupt");
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const exactDirectory = (stats) => {
|
|
19
|
+
if (!stats.isDirectory() || isSymbolic(stats) || !isExactMode(stats.mode, 0o700)) {
|
|
20
|
+
throw new WakeAcceptanceError("wake_acceptance_store_corrupt");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const exactFile = (stats) => {
|
|
24
|
+
if (!stats.isFile() || isSymbolic(stats) || !isExactMode(stats.mode, 0o600)) {
|
|
25
|
+
throw new WakeAcceptanceError("wake_acceptance_store_corrupt");
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const syncDirectory = async (directoryPath) => {
|
|
29
|
+
const handle = await openDirectory(directoryPath, "r");
|
|
30
|
+
try {
|
|
31
|
+
await handle.sync();
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
await handle.close();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const markSafeToRelease = (error, safeToRelease) => {
|
|
38
|
+
error.safeToRelease = safeToRelease;
|
|
39
|
+
return error;
|
|
40
|
+
};
|
|
41
|
+
const noEntAsSafe = (error) => markSafeToRelease(error, true);
|
|
42
|
+
const convertErr = (safeToRelease = true) => markSafeToRelease(new WakeAcceptanceError("wake_acceptance_store_corrupt"), safeToRelease);
|
|
43
|
+
const runHook = async (hook, safeToRelease, ...args) => {
|
|
44
|
+
if (hook === undefined)
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
await hook(...args);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
throw convertErr(safeToRelease);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const stateTempPrefix = `${WAKE_ACCEPTANCE_FILE}.`;
|
|
54
|
+
const stateTempSuffix = ".tmp";
|
|
55
|
+
const isStateTempNamespace = (name) => name.startsWith(stateTempPrefix) && name.endsWith(stateTempSuffix);
|
|
56
|
+
const isOwnedStateTemp = (name) => isStateTempNamespace(name) && /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u.test(name.slice(stateTempPrefix.length, -stateTempSuffix.length));
|
|
57
|
+
export class WakeAcceptanceFs {
|
|
58
|
+
runtimeHomePath;
|
|
59
|
+
stateDirectoryPath;
|
|
60
|
+
stateFilePath;
|
|
61
|
+
lockPath;
|
|
62
|
+
deps;
|
|
63
|
+
randomId;
|
|
64
|
+
hooks;
|
|
65
|
+
constructor(runtimeHomePath, options = {}) {
|
|
66
|
+
this.runtimeHomePath = runtimeHomePath;
|
|
67
|
+
this.stateDirectoryPath = path.join(runtimeHomePath, ".wake-acceptance");
|
|
68
|
+
this.stateFilePath = path.join(this.stateDirectoryPath, WAKE_ACCEPTANCE_FILE);
|
|
69
|
+
this.lockPath = path.join(this.stateDirectoryPath, "claim.lock");
|
|
70
|
+
this.randomId = options.randomUUID ?? randomUUID;
|
|
71
|
+
this.hooks = options.hooks ?? {};
|
|
72
|
+
this.deps = {
|
|
73
|
+
lstat,
|
|
74
|
+
mkdir,
|
|
75
|
+
open,
|
|
76
|
+
readdir,
|
|
77
|
+
readFile,
|
|
78
|
+
rename,
|
|
79
|
+
unlink,
|
|
80
|
+
syncDirectory,
|
|
81
|
+
...options.dependencies
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async assertRuntimeDirectory() {
|
|
85
|
+
try {
|
|
86
|
+
const stat = await this.deps.lstat(this.runtimeHomePath);
|
|
87
|
+
safeDirectory(stat);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (!isNoEnt(error)) {
|
|
92
|
+
throw convertErr();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
await this.deps.mkdir(this.runtimeHomePath, { mode: 0o700 });
|
|
97
|
+
const stat = await this.deps.lstat(this.runtimeHomePath);
|
|
98
|
+
safeDirectory(stat);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (isEEXIST(error)) {
|
|
103
|
+
try {
|
|
104
|
+
const stat = await this.deps.lstat(this.runtimeHomePath);
|
|
105
|
+
safeDirectory(stat);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
catch (statsError) {
|
|
109
|
+
if (statsError instanceof WakeAcceptanceError) {
|
|
110
|
+
throw statsError;
|
|
111
|
+
}
|
|
112
|
+
throw convertErr();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
throw convertErr();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async assertStoreDirectory() {
|
|
119
|
+
await this.assertRuntimeDirectory();
|
|
120
|
+
try {
|
|
121
|
+
const stats = await this.deps.lstat(this.stateDirectoryPath);
|
|
122
|
+
exactDirectory(stats);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (!isNoEnt(error)) {
|
|
127
|
+
throw convertErr();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
await this.deps.mkdir(this.stateDirectoryPath, { mode: 0o700 });
|
|
132
|
+
const stat = await this.deps.lstat(this.stateDirectoryPath);
|
|
133
|
+
exactDirectory(stat);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (isEEXIST(error)) {
|
|
137
|
+
try {
|
|
138
|
+
const stat = await this.deps.lstat(this.stateDirectoryPath);
|
|
139
|
+
exactDirectory(stat);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
catch (statsError) {
|
|
143
|
+
if (statsError instanceof WakeAcceptanceError) {
|
|
144
|
+
throw statsError;
|
|
145
|
+
}
|
|
146
|
+
throw convertErr();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
throw convertErr();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async acquireClaim() {
|
|
153
|
+
await this.assertStoreDirectory();
|
|
154
|
+
await runHook(this.hooks.preClaimAcquire, true);
|
|
155
|
+
let acquiredHandle = false;
|
|
156
|
+
let handle;
|
|
157
|
+
try {
|
|
158
|
+
handle = await this.deps.open(this.lockPath, "wx", 0o600);
|
|
159
|
+
acquiredHandle = true;
|
|
160
|
+
await handle.chmod(0o600);
|
|
161
|
+
await handle.sync();
|
|
162
|
+
await handle.close();
|
|
163
|
+
handle = undefined;
|
|
164
|
+
await this.deps.syncDirectory(this.stateDirectoryPath);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (handle !== undefined) {
|
|
169
|
+
await handle.close().catch(() => undefined);
|
|
170
|
+
handle = undefined;
|
|
171
|
+
}
|
|
172
|
+
if (isEEXIST(error) && !acquiredHandle) {
|
|
173
|
+
try {
|
|
174
|
+
const lockStat = await this.deps.lstat(this.lockPath);
|
|
175
|
+
exactFile(lockStat);
|
|
176
|
+
throw markSafeToRelease(new WakeAcceptanceError("wake_delivery_incomplete"), false);
|
|
177
|
+
}
|
|
178
|
+
catch (statsError) {
|
|
179
|
+
if (statsError instanceof WakeAcceptanceError) {
|
|
180
|
+
throw statsError;
|
|
181
|
+
}
|
|
182
|
+
throw convertErr();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
throw convertErr(false);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async releaseClaim() {
|
|
189
|
+
try {
|
|
190
|
+
await runHook(this.hooks.preClaimRelease, false);
|
|
191
|
+
await this.deps.unlink(this.lockPath);
|
|
192
|
+
await this.deps.syncDirectory(this.stateDirectoryPath);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (error instanceof WakeAcceptanceError) {
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
throw convertErr(false);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async readStateText() {
|
|
202
|
+
await this.assertStoreDirectory();
|
|
203
|
+
try {
|
|
204
|
+
const stats = await this.deps.lstat(this.stateFilePath);
|
|
205
|
+
exactFile(stats);
|
|
206
|
+
const body = await this.deps.readFile(this.stateFilePath, UTF8);
|
|
207
|
+
if (Buffer.byteLength(body, UTF8) > WAKE_ACCEPTANCE_FILE_BYTES_MAX) {
|
|
208
|
+
throw convertErr();
|
|
209
|
+
}
|
|
210
|
+
return body;
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
if (isNoEnt(error)) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
if (error instanceof WakeAcceptanceError) {
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
throw convertErr();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async removeOwnedTemp(pathName) {
|
|
223
|
+
try {
|
|
224
|
+
const stats = await this.deps.lstat(pathName);
|
|
225
|
+
exactFile(stats);
|
|
226
|
+
await this.deps.unlink(pathName);
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
if (isNoEnt(error)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
throw convertErr(false);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async writeStateText(body) {
|
|
236
|
+
if (Buffer.byteLength(body, UTF8) > WAKE_ACCEPTANCE_FILE_BYTES_MAX) {
|
|
237
|
+
throw convertErr(true);
|
|
238
|
+
}
|
|
239
|
+
await this.assertStoreDirectory();
|
|
240
|
+
const tempPath = `${this.stateFilePath}.${this.randomId()}.tmp`;
|
|
241
|
+
let handle;
|
|
242
|
+
let renamed = false;
|
|
243
|
+
let tempCreated = false;
|
|
244
|
+
try {
|
|
245
|
+
handle = await this.deps.open(tempPath, "wx", 0o600);
|
|
246
|
+
tempCreated = true;
|
|
247
|
+
await handle.chmod(0o600);
|
|
248
|
+
await runHook(this.hooks.preWrite, true, tempPath);
|
|
249
|
+
await handle.writeFile(body, UTF8);
|
|
250
|
+
await handle.sync();
|
|
251
|
+
await runHook(this.hooks.preSync, true, tempPath);
|
|
252
|
+
await runHook(this.hooks.preClose, true, tempPath);
|
|
253
|
+
await handle.close();
|
|
254
|
+
handle = undefined;
|
|
255
|
+
await runHook(this.hooks.preRename, true, tempPath, this.stateFilePath);
|
|
256
|
+
try {
|
|
257
|
+
const finalStat = await this.deps.lstat(this.stateFilePath);
|
|
258
|
+
exactFile(finalStat);
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
if (!isNoEnt(error)) {
|
|
262
|
+
throw convertErr(true);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
await this.deps.rename(tempPath, this.stateFilePath);
|
|
266
|
+
renamed = true;
|
|
267
|
+
await runHook(this.hooks.preDirectorySync, true, this.stateDirectoryPath);
|
|
268
|
+
await this.deps.syncDirectory(this.stateDirectoryPath);
|
|
269
|
+
const finalStateStat = await this.deps.lstat(this.stateFilePath);
|
|
270
|
+
exactFile(finalStateStat);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
if (handle !== undefined) {
|
|
275
|
+
await handle.close().catch(() => undefined);
|
|
276
|
+
}
|
|
277
|
+
let safeToRelease = true;
|
|
278
|
+
if (!renamed && tempCreated) {
|
|
279
|
+
try {
|
|
280
|
+
await this.removeOwnedTemp(tempPath);
|
|
281
|
+
}
|
|
282
|
+
catch (cleanupError) {
|
|
283
|
+
safeToRelease = false;
|
|
284
|
+
if (cleanupError instanceof WakeAcceptanceError) {
|
|
285
|
+
throw markSafeToRelease(cleanupError, false);
|
|
286
|
+
}
|
|
287
|
+
throw convertErr(false);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
safeToRelease = safeToRelease && !renamed;
|
|
291
|
+
if (error instanceof WakeAcceptanceError) {
|
|
292
|
+
throw markSafeToRelease(error, safeToRelease);
|
|
293
|
+
}
|
|
294
|
+
throw convertErr(safeToRelease);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async cleanupTemps() {
|
|
298
|
+
await this.assertStoreDirectory();
|
|
299
|
+
let entries = [];
|
|
300
|
+
try {
|
|
301
|
+
entries = await this.deps.readdir(this.stateDirectoryPath, { withFileTypes: true });
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
if (isNoEnt(error)) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
throw convertErr();
|
|
308
|
+
}
|
|
309
|
+
for (const entry of entries) {
|
|
310
|
+
if (!isStateTempNamespace(entry.name)) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (!isOwnedStateTemp(entry.name))
|
|
314
|
+
throw convertErr(false);
|
|
315
|
+
await this.removeOwnedTemp(path.join(this.stateDirectoryPath, entry.name));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|