@noopolis/daimon 0.1.2 → 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 +269 -51
- 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/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 +3 -3
- package/dist/observability/causalEvents.d.ts.map +1 -1
- package/dist/observability/causalEvents.js +103 -15
- 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 +84 -24
- package/dist/pi/cliSession.d.ts.map +1 -1
- package/dist/pi/cliSession.js +313 -158
- 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/piAgentHandle.d.ts +4 -3
- package/dist/pi/piAgentHandle.d.ts.map +1 -1
- package/dist/pi/piAgentHandle.js +37 -10
- 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 +10 -1
- package/dist/pi/piHarness.d.ts.map +1 -1
- package/dist/pi/piHarness.js +61 -8
- 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/turnTrace.d.ts.map +1 -1
- package/dist/pi/turnTrace.js +5 -8
- 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 +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 +20 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cliSession.d.ts","sourceRoot":"","sources":["../../src/pi/cliSession.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cliSession.d.ts","sourceRoot":"","sources":["../../src/pi/cliSession.ts"],"names":[],"mappings":"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"}
|
package/dist/pi/cliSession.js
CHANGED
|
@@ -1,130 +1,149 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { createServer } from "node:http";
|
|
3
|
-
import { spawn } from "node:child_process";
|
|
4
3
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
5
4
|
import { createPiToolMcpServer } from "../mcp/toolServer.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { redactCredentialError, redactCredentialText } from "../core/credentialRedaction.js";
|
|
6
|
+
import { asGrokAuthenticationRejected, classifyGrokAuthenticationDiagnostic, GrokSubscriptionAuthenticationRejectedError } from "../runtime/grokAuthenticationError.js";
|
|
7
|
+
import { readChild } from "./cliChildOutput.js";
|
|
8
|
+
import { cliChildEnvironment } from "./cliEnvironment.js";
|
|
9
|
+
import { spawnEngine } from "./cliEngineSpawn.js";
|
|
10
|
+
import { registerCliMcpServer, renderAgyMcpAddArgs, renderAgyMcpRemoveArgs } from "./cliMcpRegistration.js";
|
|
11
|
+
import { registerGrokHomeMcpServer } from "./grokHomeMcpRegistration.js";
|
|
12
|
+
import { decodeAgyHeadlessTurn } from "./agyHeadlessResult.js";
|
|
13
|
+
import { createCliTurnMeter, decodeCodexTurn, failedTurnOutcome, publishTurnRequests, publishTurnUsage } from "./cliTurnMetering.js";
|
|
14
|
+
import { decodeGrokHeadlessResult } from "./grokHeadlessResult.js";
|
|
15
|
+
import { terminateChild } from "./cliProcess.js";
|
|
16
|
+
import { ensureRuntimeHome, ensureRuntimeHomeDirectory } from "../runtime/runtimeHomeLayout.js";
|
|
17
|
+
/**
|
|
18
|
+
* The per-wake tool-call bound for AGY, and the one place it is decided.
|
|
19
|
+
*
|
|
20
|
+
* Codex and Grok leave this `undefined` — their only bound is the wake
|
|
21
|
+
* deadline. AGY does not get that treatment, for a measured reason: its
|
|
22
|
+
* terminal usage frame is the *sum* over the turn's model steps, and each tool
|
|
23
|
+
* step resends the whole context. The live capture is 13,796 total tokens for a
|
|
24
|
+
* tool-free turn and 45,381 for a turn with a single call against an
|
|
25
|
+
* empty-schema tool — one call roughly triples the wake. An unbounded loop on
|
|
26
|
+
* the one engine whose subscription quota is currently the operator's only
|
|
27
|
+
* working credential is a cost hazard, not a capability.
|
|
28
|
+
*
|
|
29
|
+
* 16 is chosen so a realistic wake is never truncated (read a few declared MCP
|
|
30
|
+
* tools, then send one or two Moltnet messages) while the worst case is bounded
|
|
31
|
+
* at roughly a quarter-million tokens instead of "whatever fits in 180s". The
|
|
32
|
+
* bound degrades gracefully rather than failing the wake: exceeding it returns
|
|
33
|
+
* `McpToolTurnLimitError` to the model as a tool *error*, so the agent can still
|
|
34
|
+
* finish its turn and reply.
|
|
35
|
+
*/
|
|
36
|
+
export const AGY_MAX_TOOL_TURNS = 16;
|
|
37
|
+
export { DAIMON_CODEX_WAKE_TIMEOUT_MS_ENV, DAIMON_CODEX_WAKE_TOKEN_CEILING_ENV, DAIMON_ENGINE_WAKE_TIMEOUT_MS_ENV, DAIMON_ENGINE_WAKE_TOKEN_CEILING_ENV, DEFAULT_CODEX_WAKE_TIMEOUT_MS, DEFAULT_CODEX_WAKE_TOKEN_CEILING, resolveCodexWakeTimeoutMs, resolveCodexWakeTokenCeiling, resolveEngineWakeLimitOverrides } from "./engineWakeLimits.js";
|
|
38
|
+
export const prepareCliRuntimeHome = async (runtimeHomePath) => {
|
|
39
|
+
if (runtimeHomePath === undefined)
|
|
40
|
+
return;
|
|
41
|
+
await ensureRuntimeHome(runtimeHomePath);
|
|
42
|
+
await Promise.all([".config", ".local/share", ".local/state", ".cache", ".tmp"]
|
|
43
|
+
.map((relative) => ensureRuntimeHomeDirectory(runtimeHomePath, relative)));
|
|
10
44
|
};
|
|
11
45
|
const childSecretValues = (redactedNames) => redactedNames
|
|
12
46
|
.map((name) => process.env[name])
|
|
13
47
|
.filter((value) => typeof value === "string" && value.length > 0);
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const redacted = redactChildOutput(output, secretValues).trim();
|
|
23
|
-
return redacted.length > 0 ? `: ${redacted}` : "";
|
|
24
|
-
};
|
|
25
|
-
const terminate = (child) => {
|
|
26
|
-
if (!child.killed)
|
|
27
|
-
child.kill("SIGTERM");
|
|
48
|
+
const captureCleanup = async (current, action) => {
|
|
49
|
+
try {
|
|
50
|
+
await action();
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return current ?? error;
|
|
54
|
+
}
|
|
55
|
+
return current;
|
|
28
56
|
};
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
child.stdout?.on("data", (chunk) => stdout.push(chunk));
|
|
33
|
-
child.stderr?.on("data", (chunk) => stderr.push(chunk));
|
|
34
|
-
const timer = setTimeout(() => {
|
|
35
|
-
terminate(child);
|
|
36
|
-
reject(new Error("CLI engine timed out"));
|
|
37
|
-
}, timeoutMs);
|
|
38
|
-
child.once("error", (error) => {
|
|
39
|
-
clearTimeout(timer);
|
|
40
|
-
reject(error);
|
|
41
|
-
});
|
|
42
|
-
child.once("close", (code, signal) => {
|
|
43
|
-
clearTimeout(timer);
|
|
44
|
-
if (code === 0) {
|
|
45
|
-
resolve(Buffer.concat(stdout).toString("utf8").trim());
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
reject(new Error(`CLI engine exited ${code ?? signal}${childDiagnostic(Buffer.concat(stdout).toString("utf8"), Buffer.concat(stderr).toString("utf8"), secretValues)}`));
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
const startMcp = async (tools, maxToolTurns, wakeDeadline, onToolsMounted) => {
|
|
57
|
+
export { terminateChild } from "./cliProcess.js";
|
|
58
|
+
export { CLI_ENGINE_MAX_DIAGNOSTIC_BYTES, CLI_ENGINE_MAX_OUTPUT_BYTES, readChild } from "./cliChildOutput.js";
|
|
59
|
+
const startMcp = async (tools, maxToolTurns, wakeDeadline, onToolsMounted, onStarted) => {
|
|
53
60
|
onToolsMounted?.(tools);
|
|
54
61
|
const mcpServer = createPiToolMcpServer(tools, { maxToolTurns, wakeDeadline });
|
|
55
62
|
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID() });
|
|
56
|
-
await mcpServer.connect(transport);
|
|
57
63
|
const httpServer = createServer((request, response) => {
|
|
58
64
|
void transport.handleRequest(request, response);
|
|
59
65
|
});
|
|
66
|
+
let lifecycle = "starting";
|
|
67
|
+
let cancelled = false;
|
|
68
|
+
let endpoint = "";
|
|
69
|
+
let closePromise;
|
|
70
|
+
let settleStartup;
|
|
71
|
+
const startupSettled = new Promise((resolve) => { settleStartup = resolve; });
|
|
72
|
+
const close = () => closePromise ??= (async () => {
|
|
73
|
+
cancelled = true;
|
|
74
|
+
if (lifecycle !== "closed")
|
|
75
|
+
lifecycle = "closing";
|
|
76
|
+
// `listen()` begins synchronously but its callback is pending. Waiting for
|
|
77
|
+
// startup prevents dispose from returning while that callback can still bind.
|
|
78
|
+
await startupSettled;
|
|
79
|
+
await transport.close().catch(() => undefined);
|
|
80
|
+
await mcpServer.close().catch(() => undefined);
|
|
81
|
+
// `close` only stops accepting and then waits for every open connection,
|
|
82
|
+
// including the ones the transport has no record of and so cannot end (a
|
|
83
|
+
// socket opened before `initialize`, or a client pool's idle keep-alive
|
|
84
|
+
// socket, which relaying a turn through the broker MCP facade leaves
|
|
85
|
+
// behind). That wait is unbounded and sits on the wake's own completion
|
|
86
|
+
// path: measured, one such connection parked a finished broker turn with
|
|
87
|
+
// its result in hand and published nothing. By here this one wake's engine
|
|
88
|
+
// has returned, failed or been cancelled, so anything still connected is a
|
|
89
|
+
// leftover — see `AGENTS.md`, and the facade, which bounds itself the same
|
|
90
|
+
// way.
|
|
91
|
+
if (httpServer.listening)
|
|
92
|
+
await new Promise((resolve) => { httpServer.close(() => resolve()); httpServer.closeAllConnections(); });
|
|
93
|
+
lifecycle = "closed";
|
|
94
|
+
})();
|
|
95
|
+
const mount = { get endpoint() { return endpoint; }, close };
|
|
96
|
+
onStarted(mount);
|
|
97
|
+
let startupError;
|
|
60
98
|
try {
|
|
99
|
+
if (cancelled)
|
|
100
|
+
throw new Error("MCP startup was cancelled");
|
|
101
|
+
await mcpServer.connect(transport);
|
|
102
|
+
if (cancelled)
|
|
103
|
+
throw new Error("MCP startup was cancelled");
|
|
61
104
|
await new Promise((resolve, reject) => {
|
|
62
|
-
|
|
63
|
-
httpServer.
|
|
105
|
+
const onError = (error) => reject(error);
|
|
106
|
+
httpServer.once("error", onError);
|
|
107
|
+
httpServer.listen(0, "127.0.0.1", () => {
|
|
108
|
+
httpServer.off("error", onError);
|
|
109
|
+
// A disposer can run from a Server.prototype.listen interceptor before
|
|
110
|
+
// this callback. Never publish the server as live in that interleaving.
|
|
111
|
+
if (!cancelled)
|
|
112
|
+
lifecycle = "listening";
|
|
113
|
+
resolve();
|
|
114
|
+
});
|
|
64
115
|
});
|
|
116
|
+
if (cancelled)
|
|
117
|
+
throw new Error("MCP startup was cancelled");
|
|
118
|
+
const address = httpServer.address();
|
|
119
|
+
if (address === null || typeof address === "string") {
|
|
120
|
+
throw new Error("MCP server did not receive an ephemeral port");
|
|
121
|
+
}
|
|
122
|
+
endpoint = `http://127.0.0.1:${address.port}/mcp`;
|
|
123
|
+
return mount;
|
|
65
124
|
}
|
|
66
125
|
catch (error) {
|
|
67
|
-
|
|
68
|
-
await mcpServer.close().catch(() => undefined);
|
|
126
|
+
startupError = error;
|
|
69
127
|
throw error;
|
|
70
128
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
await mcpServer.close();
|
|
76
|
-
throw new Error("MCP server did not receive an ephemeral port");
|
|
129
|
+
finally {
|
|
130
|
+
settleStartup();
|
|
131
|
+
if (cancelled || startupError !== undefined)
|
|
132
|
+
await close();
|
|
77
133
|
}
|
|
78
|
-
const close = async () => {
|
|
79
|
-
await transport.close().catch(() => undefined);
|
|
80
|
-
await mcpServer.close().catch(() => undefined);
|
|
81
|
-
await new Promise((resolve) => httpServer.close(() => resolve()));
|
|
82
|
-
};
|
|
83
|
-
return { endpoint: `http://127.0.0.1:${address.port}/mcp`, close };
|
|
84
|
-
};
|
|
85
|
-
const addGrokServer = async (endpoint, cwd, env, command, commandArgs, secretValues) => {
|
|
86
|
-
const child = spawn(command, [...commandArgs, "mcp", "add", "--transport", "http", "--scope", "project", "daimon", endpoint], {
|
|
87
|
-
cwd,
|
|
88
|
-
env,
|
|
89
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
90
|
-
});
|
|
91
|
-
await readChild(child, 30_000, secretValues);
|
|
92
|
-
};
|
|
93
|
-
export const renderCodexArgs = (options, cwd, endpoint, sandbox = process.env.DAIMON_CODEX_SANDBOX ?? "danger-full-access") => [...(options.commandArgs ?? []), "exec", "--sandbox", sandbox, "--skip-git-repo-check", "--color", "never", "-C", cwd,
|
|
94
|
-
"-c", `mcp_servers.daimon.url=${endpoint}`, "-"];
|
|
95
|
-
export const spawnEngine = (options, prompt, input, endpoint) => {
|
|
96
|
-
const command = options.command ?? options.engine;
|
|
97
|
-
const env = childEnvironment([
|
|
98
|
-
...(options.redactedEnvironmentNames ?? []),
|
|
99
|
-
...(input.daimonSecretEnvironmentNames ?? [])
|
|
100
|
-
]);
|
|
101
|
-
if (options.engine === "codex") {
|
|
102
|
-
const args = renderCodexArgs(options, input.cwd, endpoint);
|
|
103
|
-
const child = spawn(command, args, { cwd: input.cwd, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
104
|
-
child.stdin.on("error", () => undefined);
|
|
105
|
-
child.stdin.write(prompt);
|
|
106
|
-
child.stdin.end();
|
|
107
|
-
return child;
|
|
108
|
-
}
|
|
109
|
-
if (options.engine === "grok") {
|
|
110
|
-
return spawn(command, [...(options.commandArgs ?? []), "--single", prompt, "--max-turns", String(options.maxToolTurns), "--no-memory",
|
|
111
|
-
"--disable-web-search", "--cwd", input.cwd, "--output-format", "plain"], {
|
|
112
|
-
cwd: input.cwd,
|
|
113
|
-
env,
|
|
114
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return spawn(command, [...(options.commandArgs ?? []), "--print", prompt, "--print-timeout", `${options.timeoutMs}ms`], {
|
|
118
|
-
cwd: input.cwd,
|
|
119
|
-
env,
|
|
120
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
121
|
-
});
|
|
122
134
|
};
|
|
123
135
|
class CliSession {
|
|
124
136
|
options;
|
|
125
137
|
input;
|
|
126
138
|
listeners = new Set();
|
|
139
|
+
setupChildren = new Set();
|
|
127
140
|
disposed = false;
|
|
141
|
+
activeChild;
|
|
142
|
+
activeMount;
|
|
143
|
+
activeBrokerTurn;
|
|
144
|
+
mcpRegistration;
|
|
145
|
+
disposePromise;
|
|
146
|
+
wakeId;
|
|
128
147
|
constructor(options, input) {
|
|
129
148
|
this.options = options;
|
|
130
149
|
this.input = input;
|
|
@@ -133,60 +152,215 @@ class CliSession {
|
|
|
133
152
|
this.listeners.add(listener);
|
|
134
153
|
return () => this.listeners.delete(listener);
|
|
135
154
|
}
|
|
155
|
+
bindWake(event) {
|
|
156
|
+
this.wakeId = event?.id;
|
|
157
|
+
}
|
|
136
158
|
async prompt(text) {
|
|
137
159
|
if (this.disposed)
|
|
138
160
|
throw new Error("CLI session is disposed");
|
|
139
|
-
|
|
140
|
-
const
|
|
161
|
+
await prepareCliRuntimeHome(this.input.runtimeHomePath);
|
|
162
|
+
const deadline = this.options.timeoutMs === undefined ? undefined : Date.now() + this.options.timeoutMs;
|
|
163
|
+
const environmentSecretValues = childSecretValues([
|
|
141
164
|
...(this.options.redactedEnvironmentNames ?? []),
|
|
142
165
|
...(this.input.daimonSecretEnvironmentNames ?? [])
|
|
143
166
|
]);
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
167
|
+
const stagedCredentialSecrets = await this.options.credentialSecretValues?.() ?? [];
|
|
168
|
+
const secretValues = [...environmentSecretValues, ...stagedCredentialSecrets];
|
|
169
|
+
let mount;
|
|
170
|
+
let registration;
|
|
171
|
+
let turnUsage;
|
|
172
|
+
// Kept beside the decoded turn so a wake that never reaches its decoder
|
|
173
|
+
// still owes the ledger the usage Codex already reported (`cliTurnMetering.ts`).
|
|
174
|
+
const meter = createCliTurnMeter();
|
|
175
|
+
// Codex's own `thread.started` frame, carried out of the stream so the
|
|
176
|
+
// wake's rollout can be found by identity rather than by recency.
|
|
177
|
+
let codexThreadId;
|
|
178
|
+
let instrumented = false;
|
|
179
|
+
const instrument = async () => {
|
|
180
|
+
if (instrumented)
|
|
181
|
+
return;
|
|
182
|
+
instrumented = true;
|
|
183
|
+
await publishTurnRequests(this.options.onCodexTurnRequests, codexThreadId);
|
|
184
|
+
};
|
|
148
185
|
let child;
|
|
186
|
+
let output;
|
|
187
|
+
let cleanupFailure;
|
|
188
|
+
let promptFailure;
|
|
149
189
|
try {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
190
|
+
// Every CLI engine mounts the same tool surface. AGY used to be the one
|
|
191
|
+
// exception (`toolAccess: "none"`), which is exactly what made an AGY
|
|
192
|
+
// agent unable to reach Moltnet or a declared MCP server, and so unable
|
|
193
|
+
// to take part in an organization at all.
|
|
194
|
+
mount = await startMcp(this.input.customTools ?? [], this.options.maxToolTurns, deadline, this.options.onToolsMounted, (started) => {
|
|
195
|
+
this.activeMount = started;
|
|
196
|
+
if (this.disposed)
|
|
197
|
+
void started.close();
|
|
198
|
+
});
|
|
199
|
+
this.ensureLive();
|
|
200
|
+
if (this.options.engine === "grok" && this.options.grokBrokerTurn !== undefined && mount !== undefined) {
|
|
201
|
+
const controller = new AbortController();
|
|
202
|
+
this.activeBrokerTurn = controller;
|
|
203
|
+
try {
|
|
204
|
+
output = await this.options.grokBrokerTurn(`${this.options.identityPrompt ?? ""}${text}`, mount.endpoint, controller.signal);
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
if (this.activeBrokerTurn === controller)
|
|
208
|
+
this.activeBrokerTurn = undefined;
|
|
209
|
+
}
|
|
155
210
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
211
|
+
else {
|
|
212
|
+
if (this.options.engine === "grok" && mount !== undefined) {
|
|
213
|
+
await this.options.verifyExecutable?.();
|
|
214
|
+
registration = await registerGrokHomeMcpServer({
|
|
215
|
+
engineHomePath: this.options.engineHomePath,
|
|
216
|
+
endpoint: mount.endpoint,
|
|
217
|
+
...(this.options.verifyGrokSandbox !== undefined ? { verify: this.options.verifyGrokSandbox } : {})
|
|
218
|
+
});
|
|
219
|
+
this.mcpRegistration = registration;
|
|
220
|
+
}
|
|
221
|
+
else if (this.options.engine === "agy" && mount !== undefined) {
|
|
222
|
+
await this.options.verifyExecutable?.();
|
|
223
|
+
registration = await registerCliMcpServer({
|
|
224
|
+
addArgs: renderAgyMcpAddArgs(this.options.commandArgs, mount.endpoint),
|
|
225
|
+
removeArgs: renderAgyMcpRemoveArgs(this.options.commandArgs),
|
|
226
|
+
command: this.options.command ?? this.options.engine,
|
|
227
|
+
cwd: this.input.cwd,
|
|
228
|
+
env: cliChildEnvironment([
|
|
229
|
+
...(this.options.redactedEnvironmentNames ?? []),
|
|
230
|
+
...(this.input.daimonSecretEnvironmentNames ?? [])
|
|
231
|
+
], this.input.runtimeHomePath, {
|
|
232
|
+
...(this.options.dbusSessionBusAddress !== undefined ? { dbusSessionBusAddress: this.options.dbusSessionBusAddress } : {}),
|
|
233
|
+
engine: this.options.engine,
|
|
234
|
+
executablePath: this.options.command,
|
|
235
|
+
engineHomePath: this.options.engineHomePath
|
|
236
|
+
}),
|
|
237
|
+
onChild: (setupChild) => { this.setupChildren.add(setupChild); },
|
|
238
|
+
onChildSettled: (setupChild) => this.setupChildren.delete(setupChild),
|
|
239
|
+
secretValues
|
|
240
|
+
});
|
|
241
|
+
this.mcpRegistration = registration;
|
|
242
|
+
}
|
|
243
|
+
this.ensureLive();
|
|
244
|
+
await this.options.verifyRuntimePaths?.();
|
|
245
|
+
await this.options.verifyExecutable?.();
|
|
246
|
+
await this.options.verifyGrokSandbox?.();
|
|
247
|
+
child = spawnEngine(this.options, `${this.options.identityPrompt ?? ""}${text}`, this.input, mount?.endpoint, this.wakeId);
|
|
248
|
+
this.activeChild = child;
|
|
249
|
+
// Attach terminal listeners synchronously. A fast local sentinel may
|
|
250
|
+
// exit before an asynchronous post-spawn authority recheck completes.
|
|
251
|
+
const outputPromise = readChild(child, deadline === undefined ? undefined : Math.max(1, deadline - Date.now()), secretValues, {
|
|
252
|
+
failureClassifier: this.options.engine === "grok" ? classifyGrokAuthenticationDiagnostic : undefined,
|
|
253
|
+
retainNdjson: this.options.engine === "codex" ? "codex" : undefined,
|
|
254
|
+
retainStdoutTail: this.options.engine === "grok",
|
|
255
|
+
timeoutErrorMessage: this.options.engine === "codex" && this.options.timeoutMs !== undefined
|
|
256
|
+
? `Codex wake exceeded its ${this.options.timeoutMs}ms per-wake wall-clock bound`
|
|
257
|
+
: undefined,
|
|
258
|
+
codexTokenCeiling: this.options.engine === "codex" ? this.options.codexTokenCeiling : undefined,
|
|
259
|
+
onCodexTurnCompleted: meter.observeCodexTurnCompleted,
|
|
260
|
+
onCodexThreadStarted: (threadId) => { codexThreadId = threadId; }
|
|
179
261
|
});
|
|
262
|
+
void outputPromise.catch(() => undefined);
|
|
263
|
+
await this.options.verifyRuntimePaths?.();
|
|
264
|
+
await this.options.verifyExecutable?.();
|
|
265
|
+
const childOutput = await outputPromise;
|
|
266
|
+
if (this.options.engine === "grok")
|
|
267
|
+
output = decodeGrokHeadlessResult(childOutput);
|
|
268
|
+
else if (this.options.engine === "codex") {
|
|
269
|
+
const decoded = decodeCodexTurn(childOutput);
|
|
270
|
+
output = decoded.text;
|
|
271
|
+
turnUsage = decoded.usage;
|
|
272
|
+
}
|
|
273
|
+
else if (this.options.engine === "agy") {
|
|
274
|
+
const decoded = decodeAgyHeadlessTurn(childOutput);
|
|
275
|
+
output = decoded.text;
|
|
276
|
+
turnUsage = decoded.usage;
|
|
277
|
+
}
|
|
278
|
+
else
|
|
279
|
+
output = childOutput;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
promptFailure = error;
|
|
180
284
|
}
|
|
181
285
|
finally {
|
|
182
|
-
if (child !== undefined)
|
|
183
|
-
|
|
184
|
-
|
|
286
|
+
cleanupFailure = await captureCleanup(cleanupFailure, async () => { if (child !== undefined)
|
|
287
|
+
await terminateChild(child); });
|
|
288
|
+
if (this.activeChild === child)
|
|
289
|
+
this.activeChild = undefined;
|
|
290
|
+
let registrationClosed = registration === undefined;
|
|
291
|
+
cleanupFailure = await captureCleanup(cleanupFailure, async () => { await registration?.close(); registrationClosed = true; });
|
|
292
|
+
if (registrationClosed && this.mcpRegistration === registration)
|
|
293
|
+
this.mcpRegistration = undefined;
|
|
294
|
+
cleanupFailure = await captureCleanup(cleanupFailure, async () => { await mount?.close(); });
|
|
295
|
+
if (this.activeMount === mount)
|
|
296
|
+
this.activeMount = undefined;
|
|
297
|
+
}
|
|
298
|
+
const refreshedCredentialSecrets = await this.options.credentialSecretValues?.().catch(() => []) ?? [];
|
|
299
|
+
const finalSecrets = [...secretValues, ...refreshedCredentialSecrets];
|
|
300
|
+
// A wake that Codex reported usage for is metered whether or not it goes on
|
|
301
|
+
// to publish. Every throw below this point used to drop that spend on the
|
|
302
|
+
// floor, so a breached ceiling, an expired wall clock, a non-zero exit, or
|
|
303
|
+
// a turn judged unpublishable all cost money the ledger never saw.
|
|
304
|
+
const failure = promptFailure ?? cleanupFailure;
|
|
305
|
+
if (failure !== undefined) {
|
|
306
|
+
await publishTurnUsage(this.options.onTurnUsage, turnUsage ?? meter.reported(), failedTurnOutcome(failure));
|
|
307
|
+
// A wake that failed still made model requests and still paid for them,
|
|
308
|
+
// so its per-request shape is measured on exactly the paths its spend is.
|
|
309
|
+
await instrument();
|
|
310
|
+
}
|
|
311
|
+
if (promptFailure !== undefined) {
|
|
312
|
+
const authRejection = this.options.engine === "grok" ? asGrokAuthenticationRejected(promptFailure) : undefined;
|
|
313
|
+
if (authRejection !== undefined)
|
|
314
|
+
throw new GrokSubscriptionAuthenticationRejectedError(cleanupFailure === undefined ? undefined : redactCredentialError(cleanupFailure, finalSecrets));
|
|
315
|
+
if (cleanupFailure !== undefined)
|
|
316
|
+
throw redactCredentialError(cleanupFailure, finalSecrets);
|
|
317
|
+
throw redactCredentialError(promptFailure, finalSecrets);
|
|
318
|
+
}
|
|
319
|
+
if (cleanupFailure !== undefined) {
|
|
320
|
+
if (this.options.engine === "grok" && asGrokAuthenticationRejected(cleanupFailure) !== undefined) {
|
|
321
|
+
throw new GrokSubscriptionAuthenticationRejectedError();
|
|
322
|
+
}
|
|
323
|
+
throw redactCredentialError(cleanupFailure, finalSecrets);
|
|
185
324
|
}
|
|
325
|
+
if (output === undefined)
|
|
326
|
+
return;
|
|
327
|
+
output = redactCredentialText(output, finalSecrets, 64 * 1024);
|
|
328
|
+
for (const listener of this.listeners)
|
|
329
|
+
listener({
|
|
330
|
+
type: "turn_end",
|
|
331
|
+
message: {
|
|
332
|
+
role: "assistant", content: [{ type: "text", text: output }], api: "openai-completions", provider: "openai", model: "cli",
|
|
333
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
334
|
+
stopReason: "stop", timestamp: Date.now()
|
|
335
|
+
}, toolResults: []
|
|
336
|
+
});
|
|
337
|
+
// Meter only after the turn has published.
|
|
338
|
+
await publishTurnUsage(this.options.onTurnUsage, turnUsage ?? meter.reported(), { status: "completed" });
|
|
339
|
+
await instrument();
|
|
186
340
|
}
|
|
187
341
|
dispose() {
|
|
188
342
|
this.disposed = true;
|
|
189
343
|
this.listeners.clear();
|
|
344
|
+
this.disposePromise ??= this.quiesce();
|
|
345
|
+
}
|
|
346
|
+
async disposeAsync() {
|
|
347
|
+
this.dispose();
|
|
348
|
+
await this.disposePromise;
|
|
349
|
+
}
|
|
350
|
+
ensureLive() {
|
|
351
|
+
if (this.disposed)
|
|
352
|
+
throw new Error("CLI session is disposed");
|
|
353
|
+
}
|
|
354
|
+
async quiesce() {
|
|
355
|
+
let cleanupFailure;
|
|
356
|
+
cleanupFailure = await captureCleanup(cleanupFailure, async () => { if (this.activeChild !== undefined)
|
|
357
|
+
await terminateChild(this.activeChild); });
|
|
358
|
+
this.activeBrokerTurn?.abort();
|
|
359
|
+
cleanupFailure = await captureCleanup(cleanupFailure, () => Promise.all([...this.setupChildren].map((child) => terminateChild(child))).then(() => undefined));
|
|
360
|
+
cleanupFailure = await captureCleanup(cleanupFailure, async () => { await this.mcpRegistration?.close(); });
|
|
361
|
+
cleanupFailure = await captureCleanup(cleanupFailure, async () => { await this.activeMount?.close(); });
|
|
362
|
+
if (cleanupFailure !== undefined)
|
|
363
|
+
throw cleanupFailure;
|
|
190
364
|
}
|
|
191
365
|
}
|
|
192
366
|
export const createCliSessionFactory = (options) => async (input) => {
|
|
@@ -196,29 +370,10 @@ export const createCliSessionFactory = (options) => async (input) => {
|
|
|
196
370
|
session: new CliSession(options, {
|
|
197
371
|
cwd: input.cwd,
|
|
198
372
|
customTools: input.customTools,
|
|
199
|
-
daimonSecretEnvironmentNames: input.daimonSecretEnvironmentNames
|
|
373
|
+
daimonSecretEnvironmentNames: input.daimonSecretEnvironmentNames,
|
|
374
|
+
runtimeHomePath: input.runtimeHomePath
|
|
200
375
|
})
|
|
201
376
|
};
|
|
202
377
|
};
|
|
203
|
-
export
|
|
204
|
-
|
|
205
|
-
const options = engine === "agy"
|
|
206
|
-
? { engine, maxToolTurns: 1, timeoutMs: 180_000, toolAccess: "none" }
|
|
207
|
-
: { engine, maxToolTurns: 2, timeoutMs: 180_000 };
|
|
208
|
-
const session = new CliSession(options, { cwd: paths.workspacePath });
|
|
209
|
-
let text = "";
|
|
210
|
-
const unsubscribe = session.subscribe((event) => {
|
|
211
|
-
if (event.type !== "turn_end")
|
|
212
|
-
return;
|
|
213
|
-
if (!("content" in event.message))
|
|
214
|
-
return;
|
|
215
|
-
text = Array.isArray(event.message.content)
|
|
216
|
-
? event.message.content.filter((entry) => entry.type === "text").map((entry) => entry.text).join("")
|
|
217
|
-
: event.message.content;
|
|
218
|
-
});
|
|
219
|
-
await session.prompt(prompt);
|
|
220
|
-
unsubscribe();
|
|
221
|
-
session.dispose();
|
|
222
|
-
return { durationMs: Date.now() - startedAt, outputChars: text.length, promptChars: prompt.length, text };
|
|
223
|
-
};
|
|
224
|
-
export const runEngine = async (engine, prompt, paths) => (await runEngineDetailed(engine, prompt, paths)).text;
|
|
378
|
+
export { runEngine, runEngineDetailed } from "./cliEngineRun.js";
|
|
379
|
+
export { renderAgyArgs, renderCodexArgs, spawnEngine } from "./cliEngineSpawn.js";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { AgyTurnUsage } from "./agyHeadlessResult.js";
|
|
2
|
+
import { type CodexHeadlessTurn, type CodexTurnUsage } from "./codexHeadlessResult.js";
|
|
3
|
+
import type { TurnUsageOutcome } from "../runtime/turnUsageLedger.js";
|
|
4
|
+
/**
|
|
5
|
+
* What one CLI turn owes the usage ledger, and the rules for when it owes
|
|
6
|
+
* nothing.
|
|
7
|
+
*
|
|
8
|
+
* A wake that fails spends exactly the money a wake that publishes spends, so
|
|
9
|
+
* the engine's reported usage is metered on both paths and the row's outcome
|
|
10
|
+
* says which. A Codex wake that breached its per-wake token ceiling used to
|
|
11
|
+
* record nothing at all: the tokens it burned survived only as a number
|
|
12
|
+
* interpolated into the error message, and a timeout, a killed child, or a
|
|
13
|
+
* non-zero exit lost the figure entirely.
|
|
14
|
+
*
|
|
15
|
+
* The counterweight is that a number is never invented. A zero-filled row is
|
|
16
|
+
* byte-identical to a real zero and would silently poison every aggregate
|
|
17
|
+
* computed over the ledger, so "the engine reported nothing" stays absent.
|
|
18
|
+
*/
|
|
19
|
+
export type CliTurnMeter = Readonly<{
|
|
20
|
+
/** Wire this to `readChild`'s `onCodexTurnCompleted`. */
|
|
21
|
+
observeCodexTurnCompleted: (usage: CodexTurnUsage | undefined) => void;
|
|
22
|
+
/**
|
|
23
|
+
* The usage Codex reported mid-stream, for a wake that never reached its
|
|
24
|
+
* decoder.
|
|
25
|
+
*
|
|
26
|
+
* Trustworthy only under `decodeCodexHeadlessTurn`'s own rule: exactly one
|
|
27
|
+
* `turn.completed` frame. Codex may omit, repeat, or follow that frame with
|
|
28
|
+
* another, and two completions leave no defensible answer for which one the
|
|
29
|
+
* wake actually spent — so this declines rather than guessing, and no frame
|
|
30
|
+
* at all means nothing was reported and nothing is written.
|
|
31
|
+
*/
|
|
32
|
+
reported: () => CodexTurnUsage | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const createCliTurnMeter: () => CliTurnMeter;
|
|
35
|
+
/**
|
|
36
|
+
* A turn Codex reported usage for but that the decoder refuses to publish is
|
|
37
|
+
* still a turn that spent tokens. Tagging the rejection is what lets the
|
|
38
|
+
* ledger row name why the wake failed instead of matching on message prose.
|
|
39
|
+
*/
|
|
40
|
+
export declare const decodeCodexTurn: (output: string) => CodexHeadlessTurn;
|
|
41
|
+
/** The failed row's marker, named by the bound that actually fired. */
|
|
42
|
+
export declare const failedTurnOutcome: (failure: unknown) => TurnUsageOutcome;
|
|
43
|
+
/**
|
|
44
|
+
* Advisory: metering never fails, delays, or rewrites the wake it describes —
|
|
45
|
+
* the same ordering rule the Grok engine broker states in
|
|
46
|
+
* `finishBrokerTurnWithUsage`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const publishTurnUsage: (sink: ((usage: AgyTurnUsage | CodexTurnUsage, outcome: TurnUsageOutcome) => Promise<void>) | undefined, usage: AgyTurnUsage | CodexTurnUsage | undefined, outcome: TurnUsageOutcome) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Advisory per-request instrumentation, under the same ordering rule as
|
|
51
|
+
* {@link publishTurnUsage}: it never fails, delays, or rewrites the wake it
|
|
52
|
+
* describes.
|
|
53
|
+
*
|
|
54
|
+
* No thread id means Codex never announced one — an engine that is not Codex,
|
|
55
|
+
* a child killed before its first frame, or a future stream that renamed the
|
|
56
|
+
* event. Nothing is written in that case, because the alternative is guessing
|
|
57
|
+
* which rollout on disk belongs to this wake.
|
|
58
|
+
*/
|
|
59
|
+
export declare const publishTurnRequests: (sink: ((threadId: string) => Promise<void>) | undefined, threadId: string | undefined) => Promise<void>;
|
|
60
|
+
//# sourceMappingURL=cliTurnMetering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cliTurnMetering.d.ts","sourceRoot":"","sources":["../../src/pi/cliTurnMetering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAA2B,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAChH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;IAClC,yDAAyD;IACzD,yBAAyB,EAAE,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAC;IACvE;;;;;;;;;OASG;IACH,QAAQ,EAAE,MAAM,cAAc,GAAG,SAAS,CAAC;CAC5C,CAAC,CAAC;AAEH,eAAO,MAAM,kBAAkB,QAAO,YAUrC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,iBAGhD,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,iBAAiB,GAAI,SAAS,OAAO,KAAG,gBACwB,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,CAAC,CAAC,KAAK,EAAE,YAAY,GAAG,cAAc,EAAE,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,EACtG,OAAO,YAAY,GAAG,cAAc,GAAG,SAAS,EAChD,SAAS,gBAAgB,KACxB,OAAO,CAAC,IAAI,CAGd,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAC9B,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,EACvD,UAAU,MAAM,GAAG,SAAS,KAC3B,OAAO,CAAC,IAAI,CAGd,CAAC"}
|