@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,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-wake engine bounds, and the one place they are decided.
|
|
3
|
+
*
|
|
4
|
+
* `maxToolTurns` mediates only daimon-MCP tool calls; Codex's own shell
|
|
5
|
+
* (`exec_command`) is never routed through that gate, so a single Codex turn
|
|
6
|
+
* previously had no ceiling at all — one production wake ran 23:32→23:42
|
|
7
|
+
* (unbounded wall clock) making 51 shell calls. Codex's `--json` stream
|
|
8
|
+
* reports token usage exactly once, on `turn.completed` — there is no
|
|
9
|
+
* incremental total to watch mid-turn (verified against a live multi-tool-call
|
|
10
|
+
* turn: `item.completed` fires once per tool call, but usage is reported only
|
|
11
|
+
* on the single terminal `turn.completed`) — so the token ceiling is the best
|
|
12
|
+
* bound obtainable from that wire shape: it converts an over-budget turn into
|
|
13
|
+
* an explicit, killed, named failure instead of a silent success, and the
|
|
14
|
+
* wall-clock timeout is what actually interrupts a runaway turn in progress.
|
|
15
|
+
*
|
|
16
|
+
* The names are engine-neutral: `DAIMON_ENGINE_WAKE_TIMEOUT_MS` and
|
|
17
|
+
* `DAIMON_ENGINE_WAKE_TOKEN_CEILING` bound Codex locally and are passed to the
|
|
18
|
+
* Grok broker as the wake's *lowering* limits (the broker refuses a value above
|
|
19
|
+
* its registration). The `DAIMON_CODEX_*` names remain aliases; setting both
|
|
20
|
+
* names of one bound to different values is refused rather than guessed.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEFAULT_CODEX_WAKE_TIMEOUT_MS = 240000;
|
|
23
|
+
export declare const DEFAULT_CODEX_WAKE_TOKEN_CEILING = 300000;
|
|
24
|
+
export declare const DAIMON_ENGINE_WAKE_TIMEOUT_MS_ENV = "DAIMON_ENGINE_WAKE_TIMEOUT_MS";
|
|
25
|
+
export declare const DAIMON_ENGINE_WAKE_TOKEN_CEILING_ENV = "DAIMON_ENGINE_WAKE_TOKEN_CEILING";
|
|
26
|
+
export declare const DAIMON_CODEX_WAKE_TIMEOUT_MS_ENV = "DAIMON_CODEX_WAKE_TIMEOUT_MS";
|
|
27
|
+
export declare const DAIMON_CODEX_WAKE_TOKEN_CEILING_ENV = "DAIMON_CODEX_WAKE_TOKEN_CEILING";
|
|
28
|
+
export declare const resolveCodexWakeTimeoutMs: (environment?: NodeJS.ProcessEnv) => number;
|
|
29
|
+
export declare const resolveCodexWakeTokenCeiling: (environment?: NodeJS.ProcessEnv) => number;
|
|
30
|
+
/**
|
|
31
|
+
* The limits a wake asks a broker to lower to: only the bounds the operator
|
|
32
|
+
* actually set, never the Codex defaults (a broker registration's declared
|
|
33
|
+
* limits already are the defaults there).
|
|
34
|
+
*/
|
|
35
|
+
export declare const resolveEngineWakeLimitOverrides: (environment?: NodeJS.ProcessEnv) => Readonly<{
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
maxTokens?: number;
|
|
38
|
+
}> | undefined;
|
|
39
|
+
//# sourceMappingURL=engineWakeLimits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engineWakeLimits.d.ts","sourceRoot":"","sources":["../../src/pi/engineWakeLimits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,6BAA6B,SAAU,CAAC;AACrD,eAAO,MAAM,gCAAgC,SAAU,CAAC;AACxD,eAAO,MAAM,iCAAiC,kCAAkC,CAAC;AACjF,eAAO,MAAM,oCAAoC,qCAAqC,CAAC;AACvF,eAAO,MAAM,gCAAgC,iCAAiC,CAAC;AAC/E,eAAO,MAAM,mCAAmC,oCAAoC,CAAC;AAgBrF,eAAO,MAAM,yBAAyB,GAAI,cAAa,MAAM,CAAC,UAAwB,KAAG,MACoC,CAAC;AAC9H,eAAO,MAAM,4BAA4B,GAAI,cAAa,MAAM,CAAC,UAAwB,KAAG,MAC0C,CAAC;AAEvI;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,GAAI,cAAa,MAAM,CAAC,UAAwB,KAAG,QAAQ,CAAC;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAKrJ,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-wake engine bounds, and the one place they are decided.
|
|
3
|
+
*
|
|
4
|
+
* `maxToolTurns` mediates only daimon-MCP tool calls; Codex's own shell
|
|
5
|
+
* (`exec_command`) is never routed through that gate, so a single Codex turn
|
|
6
|
+
* previously had no ceiling at all — one production wake ran 23:32→23:42
|
|
7
|
+
* (unbounded wall clock) making 51 shell calls. Codex's `--json` stream
|
|
8
|
+
* reports token usage exactly once, on `turn.completed` — there is no
|
|
9
|
+
* incremental total to watch mid-turn (verified against a live multi-tool-call
|
|
10
|
+
* turn: `item.completed` fires once per tool call, but usage is reported only
|
|
11
|
+
* on the single terminal `turn.completed`) — so the token ceiling is the best
|
|
12
|
+
* bound obtainable from that wire shape: it converts an over-budget turn into
|
|
13
|
+
* an explicit, killed, named failure instead of a silent success, and the
|
|
14
|
+
* wall-clock timeout is what actually interrupts a runaway turn in progress.
|
|
15
|
+
*
|
|
16
|
+
* The names are engine-neutral: `DAIMON_ENGINE_WAKE_TIMEOUT_MS` and
|
|
17
|
+
* `DAIMON_ENGINE_WAKE_TOKEN_CEILING` bound Codex locally and are passed to the
|
|
18
|
+
* Grok broker as the wake's *lowering* limits (the broker refuses a value above
|
|
19
|
+
* its registration). The `DAIMON_CODEX_*` names remain aliases; setting both
|
|
20
|
+
* names of one bound to different values is refused rather than guessed.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_CODEX_WAKE_TIMEOUT_MS = 240_000;
|
|
23
|
+
export const DEFAULT_CODEX_WAKE_TOKEN_CEILING = 300_000;
|
|
24
|
+
export const DAIMON_ENGINE_WAKE_TIMEOUT_MS_ENV = "DAIMON_ENGINE_WAKE_TIMEOUT_MS";
|
|
25
|
+
export const DAIMON_ENGINE_WAKE_TOKEN_CEILING_ENV = "DAIMON_ENGINE_WAKE_TOKEN_CEILING";
|
|
26
|
+
export const DAIMON_CODEX_WAKE_TIMEOUT_MS_ENV = "DAIMON_CODEX_WAKE_TIMEOUT_MS";
|
|
27
|
+
export const DAIMON_CODEX_WAKE_TOKEN_CEILING_ENV = "DAIMON_CODEX_WAKE_TOKEN_CEILING";
|
|
28
|
+
const positiveInteger = (value, name) => {
|
|
29
|
+
const parsed = Number(value);
|
|
30
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0)
|
|
31
|
+
throw new Error(`${name} must be a positive integer`);
|
|
32
|
+
return parsed;
|
|
33
|
+
};
|
|
34
|
+
const declared = (environment, neutral, alias) => {
|
|
35
|
+
const primary = environment[neutral], legacy = environment[alias];
|
|
36
|
+
const value = primary === undefined ? undefined : positiveInteger(primary, neutral);
|
|
37
|
+
const aliased = legacy === undefined ? undefined : positiveInteger(legacy, alias);
|
|
38
|
+
if (value !== undefined && aliased !== undefined && value !== aliased)
|
|
39
|
+
throw new Error(`${neutral} and ${alias} disagree; set one`);
|
|
40
|
+
return value ?? aliased;
|
|
41
|
+
};
|
|
42
|
+
export const resolveCodexWakeTimeoutMs = (environment = process.env) => declared(environment, DAIMON_ENGINE_WAKE_TIMEOUT_MS_ENV, DAIMON_CODEX_WAKE_TIMEOUT_MS_ENV) ?? DEFAULT_CODEX_WAKE_TIMEOUT_MS;
|
|
43
|
+
export const resolveCodexWakeTokenCeiling = (environment = process.env) => declared(environment, DAIMON_ENGINE_WAKE_TOKEN_CEILING_ENV, DAIMON_CODEX_WAKE_TOKEN_CEILING_ENV) ?? DEFAULT_CODEX_WAKE_TOKEN_CEILING;
|
|
44
|
+
/**
|
|
45
|
+
* The limits a wake asks a broker to lower to: only the bounds the operator
|
|
46
|
+
* actually set, never the Codex defaults (a broker registration's declared
|
|
47
|
+
* limits already are the defaults there).
|
|
48
|
+
*/
|
|
49
|
+
export const resolveEngineWakeLimitOverrides = (environment = process.env) => {
|
|
50
|
+
const timeoutMs = declared(environment, DAIMON_ENGINE_WAKE_TIMEOUT_MS_ENV, DAIMON_CODEX_WAKE_TIMEOUT_MS_ENV);
|
|
51
|
+
const maxTokens = declared(environment, DAIMON_ENGINE_WAKE_TOKEN_CEILING_ENV, DAIMON_CODEX_WAKE_TOKEN_CEILING_ENV);
|
|
52
|
+
if (timeoutMs === undefined && maxTokens === undefined)
|
|
53
|
+
return undefined;
|
|
54
|
+
return { ...(timeoutMs === undefined ? {} : { timeoutMs }), ...(maxTokens === undefined ? {} : { maxTokens }) };
|
|
55
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token accounting for one turn, as the engine itself reported it.
|
|
3
|
+
*
|
|
4
|
+
* These are subscription-backed CLIs, so nothing here is billed: the counts are
|
|
5
|
+
* real quota consumption and `notionalUsd` is what the same turn would have cost
|
|
6
|
+
* at metered API rates. Kept away from anything named `cost` so a later reader
|
|
7
|
+
* cannot mistake it for a charge.
|
|
8
|
+
*
|
|
9
|
+
* Field provenance is the `streaming-messages-json` terminal `result` frame,
|
|
10
|
+
* which production hardcodes (`grokBrokerWorkerConfig.ts`). Its `result.usage`
|
|
11
|
+
* is the Messages API `message.usage` shape with three *disjoint* prompt-side
|
|
12
|
+
* buckets, so the full turn cost is
|
|
13
|
+
* `input_tokens + cache_read_input_tokens + cache_creation_input_tokens + output_tokens`.
|
|
14
|
+
*/
|
|
15
|
+
export type GrokTurnUsage = Readonly<{
|
|
16
|
+
input: number;
|
|
17
|
+
output: number;
|
|
18
|
+
cacheRead: number;
|
|
19
|
+
cacheWrite: number;
|
|
20
|
+
total: number;
|
|
21
|
+
calls: number;
|
|
22
|
+
notionalUsd: number;
|
|
23
|
+
complete: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
export type GrokHeadlessTurn = Readonly<{
|
|
26
|
+
text: string;
|
|
27
|
+
usage?: GrokTurnUsage;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Decode Grok's terminal message stream without treating progress messages as a
|
|
31
|
+
* reply, and extract the turn's own token accounting from the same frame.
|
|
32
|
+
*/
|
|
33
|
+
export declare const decodeGrokHeadlessTurn: (output: string) => GrokHeadlessTurn;
|
|
34
|
+
/** Text-only view of {@link decodeGrokHeadlessTurn}, for callers that do not meter. */
|
|
35
|
+
export declare const decodeGrokHeadlessResult: (output: string) => string;
|
|
36
|
+
//# sourceMappingURL=grokHeadlessResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokHeadlessResult.d.ts","sourceRoot":"","sources":["../../src/pi/grokHeadlessResult.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AA8DjF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM,KAAG,gBA+BvD,CAAC;AAEF,uFAAuF;AACvF,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,KAAG,MAA6C,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const PUBLISHABLE_STOP_REASONS = new Set(["end_turn", "stop_sequence"]);
|
|
2
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
const invalidResult = (detail) => new Error(`Grok CLI returned no publishable terminal response: ${detail}`);
|
|
4
|
+
/**
|
|
5
|
+
* The four disjoint token buckets grok emits on `result.usage`. All four must be
|
|
6
|
+
* present and be non-negative safe integers; a renamed, stringified, negative,
|
|
7
|
+
* or fractional field rejects the whole block rather than silently contributing
|
|
8
|
+
* a zero, because a zero bucket is byte-indistinguishable from a real one.
|
|
9
|
+
*/
|
|
10
|
+
const USAGE_TOKEN_FIELDS = ["input_tokens", "output_tokens", "cache_read_input_tokens", "cache_creation_input_tokens"];
|
|
11
|
+
const tokenCount = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
12
|
+
const nonNegativeAmount = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
13
|
+
/**
|
|
14
|
+
* Extract per-turn usage from the terminal `result` frame.
|
|
15
|
+
*
|
|
16
|
+
* Advisory: a malformed or absent usage block yields `undefined` rather than
|
|
17
|
+
* failing a turn that published correctly, and never throws.
|
|
18
|
+
*
|
|
19
|
+
* `complete` is a stated heuristic, not a wire-observable signal. grok's own
|
|
20
|
+
* embedded documentation for this stream says any bucket it cannot account for
|
|
21
|
+
* "falls back to `0`, because the Messages API schema has no marker for
|
|
22
|
+
* incomplete or absent usage", and instructs consumers to "read an all-zero
|
|
23
|
+
* `usage` here as 'unknown', not 'free'". That is exactly the rule below. It
|
|
24
|
+
* cannot catch a *partially* zero-filled turn, which sums to a plausible total
|
|
25
|
+
* and is stamped `complete: true` while under-counting — so every count this
|
|
26
|
+
* decoder produces is a lower bound.
|
|
27
|
+
*/
|
|
28
|
+
const decodeTurnUsage = (result) => {
|
|
29
|
+
if (!isRecord(result.usage))
|
|
30
|
+
return undefined;
|
|
31
|
+
const usage = result.usage;
|
|
32
|
+
const counts = USAGE_TOKEN_FIELDS.map((field) => tokenCount(usage[field]));
|
|
33
|
+
if (counts.some((count) => count === undefined))
|
|
34
|
+
return undefined;
|
|
35
|
+
const [input, output, cacheRead, cacheWrite] = counts;
|
|
36
|
+
const total = input + cacheRead + cacheWrite + output;
|
|
37
|
+
return { input, output, cacheRead, cacheWrite, total, calls: tokenCount(result.num_turns) ?? 0, notionalUsd: nonNegativeAmount(result.total_cost_usd), complete: total > 0 };
|
|
38
|
+
};
|
|
39
|
+
const decodeTerminalAssistant = (event) => {
|
|
40
|
+
if (event.type !== "assistant" || event.parent_tool_use_id !== null)
|
|
41
|
+
return undefined;
|
|
42
|
+
if (typeof event.session_id !== "string" || !isRecord(event.message))
|
|
43
|
+
throw invalidResult("invalid assistant event");
|
|
44
|
+
const message = event.message;
|
|
45
|
+
if (message.role !== "assistant" || typeof message.stop_reason !== "string" || !Array.isArray(message.content)) {
|
|
46
|
+
throw invalidResult("invalid assistant event");
|
|
47
|
+
}
|
|
48
|
+
if (!PUBLISHABLE_STOP_REASONS.has(message.stop_reason))
|
|
49
|
+
return { sessionId: event.session_id, stopReason: message.stop_reason, text: "" };
|
|
50
|
+
let text = "";
|
|
51
|
+
let textBlocks = 0;
|
|
52
|
+
for (const block of message.content) {
|
|
53
|
+
if (!isRecord(block) || typeof block.type !== "string")
|
|
54
|
+
throw invalidResult("invalid assistant content");
|
|
55
|
+
if (block.type === "thinking")
|
|
56
|
+
continue;
|
|
57
|
+
if (block.type !== "text" || typeof block.text !== "string")
|
|
58
|
+
throw invalidResult("invalid terminal content");
|
|
59
|
+
text += block.text;
|
|
60
|
+
textBlocks += 1;
|
|
61
|
+
}
|
|
62
|
+
if (textBlocks === 0 || text.trim().length === 0)
|
|
63
|
+
throw invalidResult("empty response");
|
|
64
|
+
return { sessionId: event.session_id, stopReason: message.stop_reason, text };
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Decode Grok's terminal message stream without treating progress messages as a
|
|
68
|
+
* reply, and extract the turn's own token accounting from the same frame.
|
|
69
|
+
*/
|
|
70
|
+
export const decodeGrokHeadlessTurn = (output) => {
|
|
71
|
+
const lines = output.split(/\r?\n/).filter((line) => line.length > 0);
|
|
72
|
+
if (lines.length === 0)
|
|
73
|
+
throw invalidResult("empty stream");
|
|
74
|
+
let finalAssistant;
|
|
75
|
+
let result;
|
|
76
|
+
for (const [index, line] of lines.entries()) {
|
|
77
|
+
let event;
|
|
78
|
+
try {
|
|
79
|
+
event = JSON.parse(line);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw invalidResult("invalid JSON");
|
|
83
|
+
}
|
|
84
|
+
if (!isRecord(event) || typeof event.type !== "string")
|
|
85
|
+
throw invalidResult("invalid event");
|
|
86
|
+
if (event.type === "error") {
|
|
87
|
+
const rejection = asGrokAuthenticationRejected(JSON.stringify(event));
|
|
88
|
+
if (rejection !== undefined)
|
|
89
|
+
throw rejection;
|
|
90
|
+
throw invalidResult("engine error");
|
|
91
|
+
}
|
|
92
|
+
const assistant = decodeTerminalAssistant(event);
|
|
93
|
+
if (assistant !== undefined)
|
|
94
|
+
finalAssistant = assistant;
|
|
95
|
+
if (event.type === "result") {
|
|
96
|
+
if (index !== lines.length - 1)
|
|
97
|
+
throw invalidResult("non-terminal result");
|
|
98
|
+
result = event;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (result === undefined || result.subtype !== "success" || result.is_error !== false)
|
|
102
|
+
throw invalidResult("unsuccessful result");
|
|
103
|
+
if (typeof result.stop_reason !== "string" || !PUBLISHABLE_STOP_REASONS.has(result.stop_reason))
|
|
104
|
+
throw invalidResult("non-terminal stop");
|
|
105
|
+
if ("errors" in result && (!Array.isArray(result.errors) || result.errors.length > 0))
|
|
106
|
+
throw invalidResult("engine error");
|
|
107
|
+
if (typeof result.result !== "string" || result.result.trim().length === 0)
|
|
108
|
+
throw invalidResult("empty response");
|
|
109
|
+
if (finalAssistant === undefined || finalAssistant.stopReason !== result.stop_reason ||
|
|
110
|
+
finalAssistant.sessionId !== result.session_id || finalAssistant.text !== result.result) {
|
|
111
|
+
throw invalidResult("terminal result mismatch");
|
|
112
|
+
}
|
|
113
|
+
const usage = decodeTurnUsage(result);
|
|
114
|
+
return usage === undefined ? { text: result.result.trim() } : { text: result.result.trim(), usage };
|
|
115
|
+
};
|
|
116
|
+
/** Text-only view of {@link decodeGrokHeadlessTurn}, for callers that do not meter. */
|
|
117
|
+
export const decodeGrokHeadlessResult = (output) => decodeGrokHeadlessTurn(output).text;
|
|
118
|
+
import { asGrokAuthenticationRejected } from "../runtime/grokAuthenticationError.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CliMcpRegistration } from "./cliMcpRegistration.js";
|
|
2
|
+
/**
|
|
3
|
+
* Per-wake MCP registration for the direct (non-broker) Grok CLI path.
|
|
4
|
+
*
|
|
5
|
+
* `grok mcp add --scope project` writes `<cwd>/.grok/config.toml`, which Grok
|
|
6
|
+
* 1.0.34 skips entirely in an untrusted workspace — and Daimon keeps every
|
|
7
|
+
* workspace untrusted so cwd `AGENTS.md` and project skills never load. The
|
|
8
|
+
* endpoint therefore goes into the agent's own Daimon-owned `GROK_HOME`
|
|
9
|
+
* config, rendered from the same lean base the broker worker uses
|
|
10
|
+
* (`renderGrokLeanBaseConfig`), and is removed again after the turn by
|
|
11
|
+
* rewriting the base alone.
|
|
12
|
+
*
|
|
13
|
+
* There is no fallback to the operator's `~/.grok`: without an explicit
|
|
14
|
+
* `engineHomePath` the session refuses, rather than editing a human's config.
|
|
15
|
+
*/
|
|
16
|
+
export declare function registerGrokHomeMcpServer(input: Readonly<{
|
|
17
|
+
engineHomePath: string | undefined;
|
|
18
|
+
endpoint: string;
|
|
19
|
+
verify?: () => Promise<void>;
|
|
20
|
+
}>): Promise<CliMcpRegistration>;
|
|
21
|
+
//# sourceMappingURL=grokHomeMcpRegistration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokHomeMcpRegistration.d.ts","sourceRoot":"","sources":["../../src/pi/grokHomeMcpRegistration.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE;;;;;;;;;;;;;GAaG;AACH,wBAAsB,yBAAyB,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAE,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAepL"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { lstat, mkdir, open, rename, unlink } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { renderGrokLeanBaseConfig } from "../runtime/grokBrokerWorkerConfig.js";
|
|
6
|
+
import { grokTaskClockConfig } from "./engineTaskClock.js";
|
|
7
|
+
/**
|
|
8
|
+
* Per-wake MCP registration for the direct (non-broker) Grok CLI path.
|
|
9
|
+
*
|
|
10
|
+
* `grok mcp add --scope project` writes `<cwd>/.grok/config.toml`, which Grok
|
|
11
|
+
* 1.0.34 skips entirely in an untrusted workspace — and Daimon keeps every
|
|
12
|
+
* workspace untrusted so cwd `AGENTS.md` and project skills never load. The
|
|
13
|
+
* endpoint therefore goes into the agent's own Daimon-owned `GROK_HOME`
|
|
14
|
+
* config, rendered from the same lean base the broker worker uses
|
|
15
|
+
* (`renderGrokLeanBaseConfig`), and is removed again after the turn by
|
|
16
|
+
* rewriting the base alone.
|
|
17
|
+
*
|
|
18
|
+
* There is no fallback to the operator's `~/.grok`: without an explicit
|
|
19
|
+
* `engineHomePath` the session refuses, rather than editing a human's config.
|
|
20
|
+
*/
|
|
21
|
+
export async function registerGrokHomeMcpServer(input) {
|
|
22
|
+
const home = input.engineHomePath;
|
|
23
|
+
if (home === undefined || !path.isAbsolute(home)) {
|
|
24
|
+
throw new Error("Grok direct CLI sessions require a Daimon-owned GROK_HOME (engineHomePath): Grok 1.0.34 ignores project-scoped MCP servers in untrusted workspaces");
|
|
25
|
+
}
|
|
26
|
+
if (!/^http:\/\/127\.0\.0\.1:\d{1,5}\/[A-Za-z0-9/_-]*$/u.test(input.endpoint))
|
|
27
|
+
throw new Error("Grok MCP endpoint must be a loopback http URL");
|
|
28
|
+
await input.verify?.();
|
|
29
|
+
await writeConfig(home, `${grokTaskClockConfig()}${renderGrokLeanBaseConfig()}[mcp_servers.daimon]\nurl = ${JSON.stringify(input.endpoint)}\n`);
|
|
30
|
+
let closePromise;
|
|
31
|
+
return {
|
|
32
|
+
close: () => closePromise ??= (async () => {
|
|
33
|
+
await input.verify?.();
|
|
34
|
+
await writeConfig(home, renderGrokLeanBaseConfig());
|
|
35
|
+
})()
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async function writeConfig(home, text) {
|
|
39
|
+
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
40
|
+
const directory = await lstat(home);
|
|
41
|
+
if (!directory.isDirectory() || directory.isSymbolicLink())
|
|
42
|
+
throw new Error("Grok engine home is not a private directory");
|
|
43
|
+
const target = path.join(home, "config.toml");
|
|
44
|
+
const temporary = path.join(home, `.config.toml.${randomUUID()}.tmp`);
|
|
45
|
+
let handle;
|
|
46
|
+
try {
|
|
47
|
+
handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
|
|
48
|
+
await handle.writeFile(text);
|
|
49
|
+
await handle.sync();
|
|
50
|
+
await handle.close();
|
|
51
|
+
handle = undefined;
|
|
52
|
+
await rename(temporary, target);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
await handle?.close().catch(() => undefined);
|
|
56
|
+
await unlink(temporary).catch(() => undefined);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const GROK_DAIMON_SANDBOX_PROFILE: "daimon-strict";
|
|
2
|
+
export interface GrokSandboxAuthority {
|
|
3
|
+
readonly command: string;
|
|
4
|
+
readonly commandArgs?: readonly string[];
|
|
5
|
+
readonly cwd: string;
|
|
6
|
+
readonly engineHomePath: string;
|
|
7
|
+
readonly protectedPaths: readonly string[];
|
|
8
|
+
readonly runtimeHomePath: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function prepareAndVerifyGrokSandbox(authority: GrokSandboxAuthority): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=grokSandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokSandbox.d.ts","sourceRoot":"","sources":["../../src/pi/grokSandbox.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,2BAA2B,iBAA8B,CAAC;AAOvE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED,wBAAsB,2BAA2B,CAC/C,SAAS,EAAE,oBAAoB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAsCf"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { spawnRealTime as spawn } from "../runtime/taskClockProcess.js";
|
|
3
|
+
import { constants } from "node:fs";
|
|
4
|
+
import { lstat, mkdir, open, realpath, rename, unlink } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { readChild } from "./cliChildOutput.js";
|
|
7
|
+
import { cliChildEnvironment } from "./cliEnvironment.js";
|
|
8
|
+
import { terminateChild, trackCliChild } from "./cliProcess.js";
|
|
9
|
+
import { renderGrokSandboxArgs } from "./cliEngineSpawn.js";
|
|
10
|
+
import { assertGrokWorkerDenyPathsPlaceable } from "../runtime/grokWorkerDenyPlacement.js";
|
|
11
|
+
import { GROK_WORKER_SANDBOX_EVENTS_RELATIVE_PATH, GROK_WORKER_SANDBOX_PROFILE, renderGrokWorkerSandboxProfile } from "../runtime/grokWorkerSandboxProfile.js";
|
|
12
|
+
export const GROK_DAIMON_SANDBOX_PROFILE = GROK_WORKER_SANDBOX_PROFILE;
|
|
13
|
+
const SANDBOX_CONFIG = "sandbox.toml";
|
|
14
|
+
/** Grok 1.0.34 logs sandbox events under `sessions/`; the root file stays empty. */
|
|
15
|
+
const SANDBOX_EVENTS = GROK_WORKER_SANDBOX_EVENTS_RELATIVE_PATH;
|
|
16
|
+
const MAX_EVENTS_BYTES = 16 * 1024 * 1024;
|
|
17
|
+
const ROTATE_EVENTS_BYTES = 8 * 1024 * 1024;
|
|
18
|
+
export async function prepareAndVerifyGrokSandbox(authority) {
|
|
19
|
+
const engineHome = await realpath(authority.engineHomePath);
|
|
20
|
+
const cwd = await realpath(authority.cwd);
|
|
21
|
+
await assertPrivateDirectory(engineHome);
|
|
22
|
+
const denied = [...new Set(await Promise.all(authority.protectedPaths.map((entry) => realpath(entry))))].sort();
|
|
23
|
+
if (denied.some((entry) => overlaps(entry, cwd) || overlaps(entry, engineHome))) {
|
|
24
|
+
throw unavailable();
|
|
25
|
+
}
|
|
26
|
+
// Grok 1.0.34 materializes every deny target inside bubblewrap as the uid it
|
|
27
|
+
// runs Grok under — here, this process's own — and refuses the whole profile
|
|
28
|
+
// if one cannot be resolved. Refusing now names the path; letting it through
|
|
29
|
+
// would kill every turn with a bare `bwrap: Can't create file at …`.
|
|
30
|
+
await assertGrokWorkerDenyPathsPlaceable(denied, { uid: process.getuid?.() ?? 0, gid: process.getgid?.() ?? 0 });
|
|
31
|
+
await writeProfile(engineHome, denied);
|
|
32
|
+
const beforeBytes = await eventFileSize(path.join(engineHome, SANDBOX_EVENTS));
|
|
33
|
+
const child = trackCliChild(spawn(authority.command, [
|
|
34
|
+
...renderGrokSandboxArgs(authority.commandArgs, GROK_DAIMON_SANDBOX_PROFILE),
|
|
35
|
+
"--cwd", cwd,
|
|
36
|
+
"inspect"
|
|
37
|
+
], {
|
|
38
|
+
cwd,
|
|
39
|
+
detached: process.platform !== "win32",
|
|
40
|
+
env: cliChildEnvironment([], authority.runtimeHomePath, {
|
|
41
|
+
engine: "grok",
|
|
42
|
+
engineHomePath: engineHome,
|
|
43
|
+
executablePath: authority.command
|
|
44
|
+
}),
|
|
45
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
46
|
+
}));
|
|
47
|
+
try {
|
|
48
|
+
await readChild(child, 10_000, []);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw unavailable();
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
await terminateChild(child).catch(() => undefined);
|
|
55
|
+
}
|
|
56
|
+
await verifyEnforcementEvent(path.join(engineHome, SANDBOX_EVENTS), beforeBytes, cwd, denied);
|
|
57
|
+
await verifyProfile(engineHome, denied);
|
|
58
|
+
}
|
|
59
|
+
const profileText = (denied) => renderGrokWorkerSandboxProfile(denied);
|
|
60
|
+
async function writeProfile(engineHome, denied) {
|
|
61
|
+
const target = path.join(engineHome, SANDBOX_CONFIG);
|
|
62
|
+
const temporary = path.join(engineHome, `.${SANDBOX_CONFIG}.${randomUUID()}.tmp`);
|
|
63
|
+
let handle;
|
|
64
|
+
try {
|
|
65
|
+
handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | noFollow(), 0o600);
|
|
66
|
+
await handle.writeFile(profileText(denied));
|
|
67
|
+
await handle.chmod(0o600);
|
|
68
|
+
await handle.sync();
|
|
69
|
+
await handle.close();
|
|
70
|
+
handle = undefined;
|
|
71
|
+
await rename(temporary, target);
|
|
72
|
+
await syncDirectory(engineHome);
|
|
73
|
+
await verifyProfile(engineHome, denied);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
throw unavailable();
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
await handle?.close().catch(() => undefined);
|
|
80
|
+
await unlink(temporary).catch(() => undefined);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function verifyProfile(engineHome, denied) {
|
|
84
|
+
const file = path.join(engineHome, SANDBOX_CONFIG);
|
|
85
|
+
let handle;
|
|
86
|
+
try {
|
|
87
|
+
const before = await lstat(file);
|
|
88
|
+
assertPrivateFile(before, 64 * 1024);
|
|
89
|
+
handle = await open(file, constants.O_RDONLY | noFollow());
|
|
90
|
+
const opened = await handle.stat();
|
|
91
|
+
assertPrivateFile(opened, 64 * 1024);
|
|
92
|
+
if (!sameIdentity(before, opened) || await handle.readFile("utf8") !== profileText(denied))
|
|
93
|
+
throw new Error("changed");
|
|
94
|
+
const after = await handle.stat();
|
|
95
|
+
if (!sameIdentity(opened, after))
|
|
96
|
+
throw new Error("changed");
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
throw unavailable();
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
await handle?.close().catch(() => undefined);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function verifyEnforcementEvent(file, beforeBytes, cwd, denied) {
|
|
106
|
+
let handle;
|
|
107
|
+
try {
|
|
108
|
+
const before = await lstat(file);
|
|
109
|
+
assertPrivateFile(before, MAX_EVENTS_BYTES);
|
|
110
|
+
if (before.size <= beforeBytes)
|
|
111
|
+
throw new Error("missing event");
|
|
112
|
+
handle = await open(file, constants.O_RDONLY | noFollow());
|
|
113
|
+
const opened = await handle.stat();
|
|
114
|
+
if (!sameIdentity(before, opened))
|
|
115
|
+
throw new Error("changed");
|
|
116
|
+
const bytes = await handle.readFile();
|
|
117
|
+
const after = await handle.stat();
|
|
118
|
+
if (!sameIdentity(opened, after))
|
|
119
|
+
throw new Error("changed");
|
|
120
|
+
const appended = bytes.subarray(beforeBytes).toString("utf8").trim().split("\n").filter(Boolean);
|
|
121
|
+
const event = JSON.parse(appended.at(-1) ?? "null");
|
|
122
|
+
const observedDenied = Array.isArray(event?.deny_paths)
|
|
123
|
+
? event.deny_paths.filter((entry) => typeof entry === "string").sort()
|
|
124
|
+
: [];
|
|
125
|
+
if (event?.event_type !== "ProfileApplied" || event.profile !== GROK_DAIMON_SANDBOX_PROFILE
|
|
126
|
+
|| event.enforced !== true || event.restrict_network !== true || event.workspace !== cwd
|
|
127
|
+
|| !/^(?:linux\/landlock|macos\/seatbelt)$/u.test(String(event.platform ?? ""))
|
|
128
|
+
|| JSON.stringify(observedDenied) !== JSON.stringify(denied))
|
|
129
|
+
throw new Error("not enforced");
|
|
130
|
+
bytes.fill(0);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
throw unavailable();
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
await handle?.close().catch(() => undefined);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function eventFileSize(file) {
|
|
140
|
+
try {
|
|
141
|
+
const entry = await lstat(file);
|
|
142
|
+
assertPrivateFile(entry, MAX_EVENTS_BYTES, true);
|
|
143
|
+
if (entry.size >= ROTATE_EVENTS_BYTES) {
|
|
144
|
+
await replaceWithEmptyPrivateFile(file);
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
return Number(entry.size);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (error.code === "ENOENT") {
|
|
151
|
+
await mkdir(path.dirname(file), { mode: 0o700, recursive: true });
|
|
152
|
+
const handle = await open(file, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | noFollow(), 0o600);
|
|
153
|
+
try {
|
|
154
|
+
await handle.sync();
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
await handle.close();
|
|
158
|
+
}
|
|
159
|
+
await syncDirectory(path.dirname(file));
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
throw unavailable();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async function replaceWithEmptyPrivateFile(file) {
|
|
166
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
167
|
+
let handle;
|
|
168
|
+
try {
|
|
169
|
+
handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | noFollow(), 0o600);
|
|
170
|
+
await handle.sync();
|
|
171
|
+
await handle.close();
|
|
172
|
+
handle = undefined;
|
|
173
|
+
await rename(temporary, file);
|
|
174
|
+
await syncDirectory(path.dirname(file));
|
|
175
|
+
const entry = await lstat(file);
|
|
176
|
+
assertPrivateFile(entry, 0, true);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
throw unavailable();
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
await handle?.close().catch(() => undefined);
|
|
183
|
+
await unlink(temporary).catch(() => undefined);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async function assertPrivateDirectory(directory) {
|
|
187
|
+
try {
|
|
188
|
+
const entry = await lstat(directory);
|
|
189
|
+
if (!entry.isDirectory() || entry.isSymbolicLink() || entry.uid !== process.getuid?.()
|
|
190
|
+
|| (Number(entry.mode) & 0o777) !== 0o700)
|
|
191
|
+
throw new Error("unsafe");
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
throw unavailable();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function syncDirectory(directory) {
|
|
198
|
+
const handle = await open(directory, constants.O_RDONLY);
|
|
199
|
+
try {
|
|
200
|
+
await handle.sync();
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
await handle.close();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const overlaps = (left, right) => left === right || left.startsWith(`${right}${path.sep}`) || right.startsWith(`${left}${path.sep}`);
|
|
207
|
+
const sameIdentity = (left, right) => left.dev === right.dev && left.ino === right.ino && left.mode === right.mode
|
|
208
|
+
&& left.nlink === right.nlink && left.size === right.size && left.uid === right.uid && left.mtimeMs === right.mtimeMs;
|
|
209
|
+
const assertPrivateFile = (entry, maxBytes, allowEmpty = false) => {
|
|
210
|
+
if (!entry.isFile() || entry.isSymbolicLink() || entry.uid !== process.getuid?.()
|
|
211
|
+
|| entry.nlink !== 1 || (Number(entry.mode) & 0o777) !== 0o600
|
|
212
|
+
|| (!allowEmpty && entry.size < 1) || entry.size > maxBytes)
|
|
213
|
+
throw new Error("unsafe");
|
|
214
|
+
};
|
|
215
|
+
const noFollow = () => constants.O_NOFOLLOW ?? 0;
|
|
216
|
+
const unavailable = () => new Error("Grok kernel sandbox enforcement is unavailable");
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-request token accounting read off a Grok `streaming-messages-json`
|
|
3
|
+
* stream.
|
|
4
|
+
*
|
|
5
|
+
* Grok 1.0.34 puts the usage of each model request on that request's
|
|
6
|
+
* top-level `assistant` frame (`message.usage`, the same four disjoint
|
|
7
|
+
* Messages API buckets as the terminal `result.usage`), before any tool result
|
|
8
|
+
* of that request, and the per-request frames sum exactly to the terminal
|
|
9
|
+
* result (P0 host matrix). That makes the stream usable in two places the
|
|
10
|
+
* terminal frame is not: a turn that failed before its `result` frame, and a
|
|
11
|
+
* per-request ledger row.
|
|
12
|
+
*
|
|
13
|
+
* Never throws, and never invents a number: a usage block that is present but
|
|
14
|
+
* does not decode discards *all* requests, because one fabricated zero is
|
|
15
|
+
* byte-identical to a measured one.
|
|
16
|
+
*/
|
|
17
|
+
export type GrokRequestUsage = Readonly<{
|
|
18
|
+
index: number;
|
|
19
|
+
input: number;
|
|
20
|
+
cacheRead: number;
|
|
21
|
+
cacheWrite: number;
|
|
22
|
+
output: number;
|
|
23
|
+
total: number;
|
|
24
|
+
}>;
|
|
25
|
+
export type GrokStreamUsage = Readonly<{
|
|
26
|
+
requests: readonly GrokRequestUsage[];
|
|
27
|
+
sessionId?: string;
|
|
28
|
+
reportedModels: readonly string[];
|
|
29
|
+
}>;
|
|
30
|
+
export declare const decodeGrokStreamUsage: (output: string) => GrokStreamUsage;
|
|
31
|
+
//# sourceMappingURL=grokStreamUsage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokStreamUsage.d.ts","sourceRoot":"","sources":["../../src/pi/grokStreamUsage.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAChJ,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IAAE,QAAQ,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC;AAkBzI,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,KAAG,eAmBtD,CAAC"}
|