@noopolis/daimon 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/README.md +307 -45
  2. package/dist/contracts/attentionContract.d.ts +117 -0
  3. package/dist/contracts/attentionContract.d.ts.map +1 -0
  4. package/dist/contracts/attentionContract.js +14 -0
  5. package/dist/contracts/canonicalJson.d.ts +3 -0
  6. package/dist/contracts/canonicalJson.d.ts.map +1 -0
  7. package/dist/contracts/canonicalJson.js +54 -0
  8. package/dist/contracts/grokWorkerContract.d.ts +74 -0
  9. package/dist/contracts/grokWorkerContract.d.ts.map +1 -0
  10. package/dist/contracts/grokWorkerContract.js +88 -0
  11. package/dist/contracts/organizationRuntimeContract.d.ts +765 -0
  12. package/dist/contracts/organizationRuntimeContract.d.ts.map +1 -0
  13. package/dist/contracts/organizationRuntimeContract.js +121 -0
  14. package/dist/contracts/runtimeContractManifest.d.ts +1615 -0
  15. package/dist/contracts/runtimeContractManifest.d.ts.map +1 -0
  16. package/dist/contracts/runtimeContractManifest.js +181 -0
  17. package/dist/core/credentialRedaction.d.ts +4 -0
  18. package/dist/core/credentialRedaction.d.ts.map +1 -0
  19. package/dist/core/credentialRedaction.js +28 -0
  20. package/dist/core/siblingBuildFreshness.d.ts +21 -0
  21. package/dist/core/siblingBuildFreshness.d.ts.map +1 -0
  22. package/dist/core/siblingBuildFreshness.js +25 -0
  23. package/dist/core/types.d.ts +10 -1
  24. package/dist/core/types.d.ts.map +1 -1
  25. package/dist/examples/exampleCausalId.d.ts +3 -0
  26. package/dist/examples/exampleCausalId.d.ts.map +1 -0
  27. package/dist/examples/exampleCausalId.js +8 -0
  28. package/dist/examples/jungian-play-org.js +3 -2
  29. package/dist/examples/jungian-triad-org.js +3 -2
  30. package/dist/examples/jungianPlayAgent.d.ts +1 -1
  31. package/dist/examples/jungianPlayAgent.d.ts.map +1 -1
  32. package/dist/examples/jungianPlayAgent.js +1 -1
  33. package/dist/examples/jungianProfiles.d.ts +1 -1
  34. package/dist/examples/jungianProfiles.d.ts.map +1 -1
  35. package/dist/examples/jungianTriadProfiles.d.ts +1 -1
  36. package/dist/examples/jungianTriadProfiles.d.ts.map +1 -1
  37. package/dist/examples/pi-agent.js +3 -2
  38. package/dist/examples/pi-memory-org.js +6 -5
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +1 -0
  42. package/dist/mcp/toolServer.d.ts +31 -0
  43. package/dist/mcp/toolServer.d.ts.map +1 -0
  44. package/dist/mcp/toolServer.js +145 -0
  45. package/dist/observability/causalEvents.d.ts +118 -0
  46. package/dist/observability/causalEvents.d.ts.map +1 -0
  47. package/dist/observability/causalEvents.js +223 -0
  48. package/dist/observability/controlCausal.d.ts +117 -0
  49. package/dist/observability/controlCausal.d.ts.map +1 -0
  50. package/dist/observability/controlCausal.js +107 -0
  51. package/dist/observability/emitCausalFixture.d.ts +25 -0
  52. package/dist/observability/emitCausalFixture.d.ts.map +1 -0
  53. package/dist/observability/emitCausalFixture.js +98 -0
  54. package/dist/observability/index.d.ts +2 -0
  55. package/dist/observability/index.d.ts.map +1 -1
  56. package/dist/observability/index.js +2 -0
  57. package/dist/observability/orgObserver.d.ts.map +1 -1
  58. package/dist/observability/orgObserver.js +3 -3
  59. package/dist/pi/agyHeadlessResult.d.ts +60 -0
  60. package/dist/pi/agyHeadlessResult.d.ts.map +1 -0
  61. package/dist/pi/agyHeadlessResult.js +95 -0
  62. package/dist/pi/cliChildOutput.d.ts +67 -0
  63. package/dist/pi/cliChildOutput.d.ts.map +1 -0
  64. package/dist/pi/cliChildOutput.js +269 -0
  65. package/dist/pi/cliEngineRun.d.ts +16 -0
  66. package/dist/pi/cliEngineRun.d.ts.map +1 -0
  67. package/dist/pi/cliEngineRun.js +27 -0
  68. package/dist/pi/cliEngineSpawn.d.ts +55 -0
  69. package/dist/pi/cliEngineSpawn.d.ts.map +1 -0
  70. package/dist/pi/cliEngineSpawn.js +164 -0
  71. package/dist/pi/cliEnvironment.d.ts +12 -0
  72. package/dist/pi/cliEnvironment.d.ts.map +1 -0
  73. package/dist/pi/cliEnvironment.js +32 -0
  74. package/dist/pi/cliMcpRegistration.d.ts +61 -0
  75. package/dist/pi/cliMcpRegistration.d.ts.map +1 -0
  76. package/dist/pi/cliMcpRegistration.js +75 -0
  77. package/dist/pi/cliProcess.d.ts +7 -0
  78. package/dist/pi/cliProcess.d.ts.map +1 -0
  79. package/dist/pi/cliProcess.js +132 -0
  80. package/dist/pi/cliSession.d.ts +106 -0
  81. package/dist/pi/cliSession.d.ts.map +1 -0
  82. package/dist/pi/cliSession.js +379 -0
  83. package/dist/pi/cliTurnMetering.d.ts +60 -0
  84. package/dist/pi/cliTurnMetering.d.ts.map +1 -0
  85. package/dist/pi/cliTurnMetering.js +60 -0
  86. package/dist/pi/codexFilesystemRules.d.ts +3 -0
  87. package/dist/pi/codexFilesystemRules.d.ts.map +1 -0
  88. package/dist/pi/codexFilesystemRules.js +28 -0
  89. package/dist/pi/codexHeadlessResult.d.ts +68 -0
  90. package/dist/pi/codexHeadlessResult.d.ts.map +1 -0
  91. package/dist/pi/codexHeadlessResult.js +122 -0
  92. package/dist/pi/codexRolloutUsage.d.ts +95 -0
  93. package/dist/pi/codexRolloutUsage.d.ts.map +1 -0
  94. package/dist/pi/codexRolloutUsage.js +221 -0
  95. package/dist/pi/engineWakeLimits.d.ts +39 -0
  96. package/dist/pi/engineWakeLimits.d.ts.map +1 -0
  97. package/dist/pi/engineWakeLimits.js +55 -0
  98. package/dist/pi/grokHeadlessResult.d.ts +36 -0
  99. package/dist/pi/grokHeadlessResult.d.ts.map +1 -0
  100. package/dist/pi/grokHeadlessResult.js +118 -0
  101. package/dist/pi/grokHomeMcpRegistration.d.ts +21 -0
  102. package/dist/pi/grokHomeMcpRegistration.d.ts.map +1 -0
  103. package/dist/pi/grokHomeMcpRegistration.js +57 -0
  104. package/dist/pi/grokSandbox.d.ts +11 -0
  105. package/dist/pi/grokSandbox.d.ts.map +1 -0
  106. package/dist/pi/grokSandbox.js +216 -0
  107. package/dist/pi/grokStreamUsage.d.ts +31 -0
  108. package/dist/pi/grokStreamUsage.d.ts.map +1 -0
  109. package/dist/pi/grokStreamUsage.js +51 -0
  110. package/dist/pi/index.d.ts +5 -0
  111. package/dist/pi/index.d.ts.map +1 -1
  112. package/dist/pi/index.js +5 -0
  113. package/dist/pi/memoryTools.d.ts +55 -1
  114. package/dist/pi/memoryTools.d.ts.map +1 -1
  115. package/dist/pi/memoryTools.js +144 -24
  116. package/dist/pi/modelRegistry.d.ts +13 -0
  117. package/dist/pi/modelRegistry.d.ts.map +1 -0
  118. package/dist/pi/modelRegistry.js +19 -0
  119. package/dist/pi/piAgentHandle.d.ts +46 -0
  120. package/dist/pi/piAgentHandle.d.ts.map +1 -0
  121. package/dist/pi/piAgentHandle.js +351 -0
  122. package/dist/pi/piAgentWakeSupport.d.ts +103 -0
  123. package/dist/pi/piAgentWakeSupport.d.ts.map +1 -0
  124. package/dist/pi/piAgentWakeSupport.js +151 -0
  125. package/dist/pi/piHarness.d.ts +40 -5
  126. package/dist/pi/piHarness.d.ts.map +1 -1
  127. package/dist/pi/piHarness.js +151 -256
  128. package/dist/pi/prompts.d.ts +10 -0
  129. package/dist/pi/prompts.d.ts.map +1 -0
  130. package/dist/pi/prompts.js +63 -0
  131. package/dist/pi/rawTrainingCapture.d.ts +59 -0
  132. package/dist/pi/rawTrainingCapture.d.ts.map +1 -0
  133. package/dist/pi/rawTrainingCapture.js +175 -0
  134. package/dist/pi/turnCausal.d.ts +73 -0
  135. package/dist/pi/turnCausal.d.ts.map +1 -0
  136. package/dist/pi/turnCausal.js +75 -0
  137. package/dist/pi/turnTrace.d.ts +128 -0
  138. package/dist/pi/turnTrace.d.ts.map +1 -0
  139. package/dist/pi/turnTrace.js +138 -0
  140. package/dist/pi/wakeAcceptance.d.ts +49 -0
  141. package/dist/pi/wakeAcceptance.d.ts.map +1 -0
  142. package/dist/pi/wakeAcceptance.js +281 -0
  143. package/dist/pi/wakeAcceptanceFs.d.ts +44 -0
  144. package/dist/pi/wakeAcceptanceFs.d.ts.map +1 -0
  145. package/dist/pi/wakeAcceptanceFs.js +318 -0
  146. package/dist/pi/wakeAcceptanceSchema.d.ts +75 -0
  147. package/dist/pi/wakeAcceptanceSchema.d.ts.map +1 -0
  148. package/dist/pi/wakeAcceptanceSchema.js +265 -0
  149. package/dist/pi/wakeModes.d.ts +9 -0
  150. package/dist/pi/wakeModes.d.ts.map +1 -0
  151. package/dist/pi/wakeModes.js +19 -0
  152. package/dist/pi/worldNudge.d.ts +22 -0
  153. package/dist/pi/worldNudge.d.ts.map +1 -0
  154. package/dist/pi/worldNudge.js +62 -0
  155. package/dist/pi/worldToolProtocol.d.ts +13 -0
  156. package/dist/pi/worldToolProtocol.d.ts.map +1 -0
  157. package/dist/pi/worldToolProtocol.js +49 -0
  158. package/dist/pi/worldTools.d.ts +32 -0
  159. package/dist/pi/worldTools.d.ts.map +1 -0
  160. package/dist/pi/worldTools.js +373 -0
  161. package/dist/pi/worldTrajectory.d.ts +52 -0
  162. package/dist/pi/worldTrajectory.d.ts.map +1 -0
  163. package/dist/pi/worldTrajectory.js +131 -0
  164. package/dist/runtime/agySubscriptionBootstrap.d.ts +16 -0
  165. package/dist/runtime/agySubscriptionBootstrap.d.ts.map +1 -0
  166. package/dist/runtime/agySubscriptionBootstrap.js +80 -0
  167. package/dist/runtime/agySubscriptionRealm.d.ts +38 -0
  168. package/dist/runtime/agySubscriptionRealm.d.ts.map +1 -0
  169. package/dist/runtime/agySubscriptionRealm.js +242 -0
  170. package/dist/runtime/attention.d.ts +21 -0
  171. package/dist/runtime/attention.d.ts.map +1 -0
  172. package/dist/runtime/attention.js +36 -0
  173. package/dist/runtime/attentionDispatcher.d.ts +66 -0
  174. package/dist/runtime/attentionDispatcher.d.ts.map +1 -0
  175. package/dist/runtime/attentionDispatcher.js +271 -0
  176. package/dist/runtime/cli.d.ts +7 -0
  177. package/dist/runtime/cli.d.ts.map +1 -0
  178. package/dist/runtime/cli.js +251 -0
  179. package/dist/runtime/codexSandboxProjection.d.ts +17 -0
  180. package/dist/runtime/codexSandboxProjection.d.ts.map +1 -0
  181. package/dist/runtime/codexSandboxProjection.js +40 -0
  182. package/dist/runtime/contract-manifest.json +1 -0
  183. package/dist/runtime/contract-manifest.sha256 +1 -0
  184. package/dist/runtime/contractManifest.d.ts +8 -0
  185. package/dist/runtime/contractManifest.d.ts.map +1 -0
  186. package/dist/runtime/contractManifest.js +4 -0
  187. package/dist/runtime/engineBrokerCapabilities.d.ts +30 -0
  188. package/dist/runtime/engineBrokerCapabilities.d.ts.map +1 -0
  189. package/dist/runtime/engineBrokerCapabilities.js +59 -0
  190. package/dist/runtime/engineBrokerControlClient.d.ts +44 -0
  191. package/dist/runtime/engineBrokerControlClient.d.ts.map +1 -0
  192. package/dist/runtime/engineBrokerControlClient.js +132 -0
  193. package/dist/runtime/engineBrokerCredentialJournal.d.ts +10 -0
  194. package/dist/runtime/engineBrokerCredentialJournal.d.ts.map +1 -0
  195. package/dist/runtime/engineBrokerCredentialJournal.js +17 -0
  196. package/dist/runtime/engineBrokerInferenceProtocol.d.ts +52 -0
  197. package/dist/runtime/engineBrokerInferenceProtocol.d.ts.map +1 -0
  198. package/dist/runtime/engineBrokerInferenceProtocol.js +65 -0
  199. package/dist/runtime/engineBrokerMcpCallLog.d.ts +160 -0
  200. package/dist/runtime/engineBrokerMcpCallLog.d.ts.map +1 -0
  201. package/dist/runtime/engineBrokerMcpCallLog.js +219 -0
  202. package/dist/runtime/engineBrokerMcpFacade.d.ts +56 -0
  203. package/dist/runtime/engineBrokerMcpFacade.d.ts.map +1 -0
  204. package/dist/runtime/engineBrokerMcpFacade.js +343 -0
  205. package/dist/runtime/engineBrokerNativeClient.d.ts +52 -0
  206. package/dist/runtime/engineBrokerNativeClient.d.ts.map +1 -0
  207. package/dist/runtime/engineBrokerNativeClient.js +151 -0
  208. package/dist/runtime/engineBrokerProtocol.d.ts +135 -0
  209. package/dist/runtime/engineBrokerProtocol.d.ts.map +1 -0
  210. package/dist/runtime/engineBrokerProtocol.js +274 -0
  211. package/dist/runtime/engineBrokerSealLedger.d.ts +70 -0
  212. package/dist/runtime/engineBrokerSealLedger.d.ts.map +1 -0
  213. package/dist/runtime/engineBrokerSealLedger.js +123 -0
  214. package/dist/runtime/engineBrokerService.d.ts +37 -0
  215. package/dist/runtime/engineBrokerService.d.ts.map +1 -0
  216. package/dist/runtime/engineBrokerService.js +138 -0
  217. package/dist/runtime/engineBrokerServiceCli.d.ts +5 -0
  218. package/dist/runtime/engineBrokerServiceCli.d.ts.map +1 -0
  219. package/dist/runtime/engineBrokerServiceCli.js +32 -0
  220. package/dist/runtime/engineBrokerServiceConfig.d.ts +50 -0
  221. package/dist/runtime/engineBrokerServiceConfig.d.ts.map +1 -0
  222. package/dist/runtime/engineBrokerServiceConfig.js +92 -0
  223. package/dist/runtime/engineBrokerSingleflight.d.ts +13 -0
  224. package/dist/runtime/engineBrokerSingleflight.d.ts.map +1 -0
  225. package/dist/runtime/engineBrokerSingleflight.js +24 -0
  226. package/dist/runtime/engineBrokerTurnAccounting.d.ts +76 -0
  227. package/dist/runtime/engineBrokerTurnAccounting.d.ts.map +1 -0
  228. package/dist/runtime/engineBrokerTurnAccounting.js +108 -0
  229. package/dist/runtime/engineBrokerTurnRegistry.d.ts +57 -0
  230. package/dist/runtime/engineBrokerTurnRegistry.d.ts.map +1 -0
  231. package/dist/runtime/engineBrokerTurnRegistry.js +158 -0
  232. package/dist/runtime/engineDispatcher.d.ts +36 -0
  233. package/dist/runtime/engineDispatcher.d.ts.map +1 -0
  234. package/dist/runtime/engineDispatcher.js +216 -0
  235. package/dist/runtime/engineReadiness.d.ts +23 -0
  236. package/dist/runtime/engineReadiness.d.ts.map +1 -0
  237. package/dist/runtime/engineReadiness.js +222 -0
  238. package/dist/runtime/grokAuthenticationError.d.ts +8 -0
  239. package/dist/runtime/grokAuthenticationError.d.ts.map +1 -0
  240. package/dist/runtime/grokAuthenticationError.js +20 -0
  241. package/dist/runtime/grokBrokerCredentialAuthority.d.ts +22 -0
  242. package/dist/runtime/grokBrokerCredentialAuthority.d.ts.map +1 -0
  243. package/dist/runtime/grokBrokerCredentialAuthority.js +124 -0
  244. package/dist/runtime/grokBrokerCredentialReader.d.ts +5 -0
  245. package/dist/runtime/grokBrokerCredentialReader.d.ts.map +1 -0
  246. package/dist/runtime/grokBrokerCredentialReader.js +37 -0
  247. package/dist/runtime/grokBrokerModelPolicy.d.ts +23 -0
  248. package/dist/runtime/grokBrokerModelPolicy.d.ts.map +1 -0
  249. package/dist/runtime/grokBrokerModelPolicy.js +28 -0
  250. package/dist/runtime/grokBrokerProjection.d.ts +106 -0
  251. package/dist/runtime/grokBrokerProjection.d.ts.map +1 -0
  252. package/dist/runtime/grokBrokerProjection.js +94 -0
  253. package/dist/runtime/grokBrokerProxy.d.ts +55 -0
  254. package/dist/runtime/grokBrokerProxy.d.ts.map +1 -0
  255. package/dist/runtime/grokBrokerProxy.js +262 -0
  256. package/dist/runtime/grokBrokerProxyRequest.d.ts +30 -0
  257. package/dist/runtime/grokBrokerProxyRequest.d.ts.map +1 -0
  258. package/dist/runtime/grokBrokerProxyRequest.js +74 -0
  259. package/dist/runtime/grokBrokerRealmLease.d.ts +4 -0
  260. package/dist/runtime/grokBrokerRealmLease.d.ts.map +1 -0
  261. package/dist/runtime/grokBrokerRealmLease.js +33 -0
  262. package/dist/runtime/grokBrokerRefresh.d.ts +2 -0
  263. package/dist/runtime/grokBrokerRefresh.d.ts.map +1 -0
  264. package/dist/runtime/grokBrokerRefresh.js +15 -0
  265. package/dist/runtime/grokBrokerTurnMeter.d.ts +128 -0
  266. package/dist/runtime/grokBrokerTurnMeter.d.ts.map +1 -0
  267. package/dist/runtime/grokBrokerTurnMeter.js +251 -0
  268. package/dist/runtime/grokBrokerWorkerConfig.d.ts +86 -0
  269. package/dist/runtime/grokBrokerWorkerConfig.d.ts.map +1 -0
  270. package/dist/runtime/grokBrokerWorkerConfig.js +135 -0
  271. package/dist/runtime/grokEngineBroker.d.ts +48 -0
  272. package/dist/runtime/grokEngineBroker.d.ts.map +1 -0
  273. package/dist/runtime/grokEngineBroker.js +114 -0
  274. package/dist/runtime/grokEngineBrokerLedger.d.ts +52 -0
  275. package/dist/runtime/grokEngineBrokerLedger.d.ts.map +1 -0
  276. package/dist/runtime/grokEngineBrokerLedger.js +114 -0
  277. package/dist/runtime/grokEngineBrokerMetering.d.ts +51 -0
  278. package/dist/runtime/grokEngineBrokerMetering.d.ts.map +1 -0
  279. package/dist/runtime/grokEngineBrokerMetering.js +34 -0
  280. package/dist/runtime/grokEngineBrokerTurn.d.ts +58 -0
  281. package/dist/runtime/grokEngineBrokerTurn.d.ts.map +1 -0
  282. package/dist/runtime/grokEngineBrokerTurn.js +165 -0
  283. package/dist/runtime/grokInferenceClientConfig.d.ts +41 -0
  284. package/dist/runtime/grokInferenceClientConfig.d.ts.map +1 -0
  285. package/dist/runtime/grokInferenceClientConfig.js +62 -0
  286. package/dist/runtime/grokInferenceGrants.d.ts +77 -0
  287. package/dist/runtime/grokInferenceGrants.d.ts.map +1 -0
  288. package/dist/runtime/grokInferenceGrants.js +116 -0
  289. package/dist/runtime/grokInferenceProxy.d.ts +29 -0
  290. package/dist/runtime/grokInferenceProxy.d.ts.map +1 -0
  291. package/dist/runtime/grokInferenceProxy.js +82 -0
  292. package/dist/runtime/grokInferenceProxyRequest.d.ts +23 -0
  293. package/dist/runtime/grokInferenceProxyRequest.d.ts.map +1 -0
  294. package/dist/runtime/grokInferenceProxyRequest.js +63 -0
  295. package/dist/runtime/grokSlotPreflightReceipt.d.ts +70 -0
  296. package/dist/runtime/grokSlotPreflightReceipt.d.ts.map +1 -0
  297. package/dist/runtime/grokSlotPreflightReceipt.js +101 -0
  298. package/dist/runtime/grokSubscriptionRealm.d.ts +4 -0
  299. package/dist/runtime/grokSubscriptionRealm.d.ts.map +1 -0
  300. package/dist/runtime/grokSubscriptionRealm.js +435 -0
  301. package/dist/runtime/grokSubscriptionRealmTypes.d.ts +26 -0
  302. package/dist/runtime/grokSubscriptionRealmTypes.d.ts.map +1 -0
  303. package/dist/runtime/grokSubscriptionRealmTypes.js +1 -0
  304. package/dist/runtime/grokWorkerAttestation.d.ts +170 -0
  305. package/dist/runtime/grokWorkerAttestation.d.ts.map +1 -0
  306. package/dist/runtime/grokWorkerAttestation.js +266 -0
  307. package/dist/runtime/grokWorkerDenyPlacement.d.ts +80 -0
  308. package/dist/runtime/grokWorkerDenyPlacement.d.ts.map +1 -0
  309. package/dist/runtime/grokWorkerDenyPlacement.js +128 -0
  310. package/dist/runtime/grokWorkerHomeAttestation.d.ts +30 -0
  311. package/dist/runtime/grokWorkerHomeAttestation.d.ts.map +1 -0
  312. package/dist/runtime/grokWorkerHomeAttestation.js +69 -0
  313. package/dist/runtime/grokWorkerSandboxProfile.d.ts +27 -0
  314. package/dist/runtime/grokWorkerSandboxProfile.d.ts.map +1 -0
  315. package/dist/runtime/grokWorkerSandboxProfile.js +44 -0
  316. package/dist/runtime/grokWorkerTmpAttestation.d.ts +55 -0
  317. package/dist/runtime/grokWorkerTmpAttestation.d.ts.map +1 -0
  318. package/dist/runtime/grokWorkerTmpAttestation.js +63 -0
  319. package/dist/runtime/index.d.ts +26 -0
  320. package/dist/runtime/index.d.ts.map +1 -0
  321. package/dist/runtime/index.js +23 -0
  322. package/dist/runtime/inferenceUsageLedger.d.ts +38 -0
  323. package/dist/runtime/inferenceUsageLedger.d.ts.map +1 -0
  324. package/dist/runtime/inferenceUsageLedger.js +53 -0
  325. package/dist/runtime/mcpToolResult.d.ts +127 -0
  326. package/dist/runtime/mcpToolResult.d.ts.map +1 -0
  327. package/dist/runtime/mcpToolResult.js +214 -0
  328. package/dist/runtime/moltnetMachineRead.d.ts +97 -0
  329. package/dist/runtime/moltnetMachineRead.d.ts.map +1 -0
  330. package/dist/runtime/moltnetMachineRead.js +183 -0
  331. package/dist/runtime/native/daimon-engine-broker +0 -0
  332. package/dist/runtime/organizationRuntime.d.ts +165 -0
  333. package/dist/runtime/organizationRuntime.d.ts.map +1 -0
  334. package/dist/runtime/organizationRuntime.js +3 -0
  335. package/dist/runtime/organizationRuntimeControl.d.ts +42 -0
  336. package/dist/runtime/organizationRuntimeControl.d.ts.map +1 -0
  337. package/dist/runtime/organizationRuntimeControl.js +235 -0
  338. package/dist/runtime/organizationRuntimeHost.d.ts +19 -0
  339. package/dist/runtime/organizationRuntimeHost.d.ts.map +1 -0
  340. package/dist/runtime/organizationRuntimeHost.js +359 -0
  341. package/dist/runtime/organizationRuntimeParsing.d.ts +6 -0
  342. package/dist/runtime/organizationRuntimeParsing.d.ts.map +1 -0
  343. package/dist/runtime/organizationRuntimeParsing.js +370 -0
  344. package/dist/runtime/organizationRuntimeReadiness.d.ts +12 -0
  345. package/dist/runtime/organizationRuntimeReadiness.d.ts.map +1 -0
  346. package/dist/runtime/organizationRuntimeReadiness.js +59 -0
  347. package/dist/runtime/physicalReadiness.d.ts +47 -0
  348. package/dist/runtime/physicalReadiness.d.ts.map +1 -0
  349. package/dist/runtime/physicalReadiness.js +142 -0
  350. package/dist/runtime/portableCredentialAuth.d.ts +6 -0
  351. package/dist/runtime/portableCredentialAuth.d.ts.map +1 -0
  352. package/dist/runtime/portableCredentialAuth.js +70 -0
  353. package/dist/runtime/portableCredentialMaterial.d.ts +8 -0
  354. package/dist/runtime/portableCredentialMaterial.d.ts.map +1 -0
  355. package/dist/runtime/portableCredentialMaterial.js +169 -0
  356. package/dist/runtime/productionAgentTools.d.ts +5 -0
  357. package/dist/runtime/productionAgentTools.d.ts.map +1 -0
  358. package/dist/runtime/productionAgentTools.js +328 -0
  359. package/dist/runtime/runtimeHomeLayout.d.ts +48 -0
  360. package/dist/runtime/runtimeHomeLayout.d.ts.map +1 -0
  361. package/dist/runtime/runtimeHomeLayout.js +84 -0
  362. package/dist/runtime/schedule.d.ts +40 -0
  363. package/dist/runtime/schedule.d.ts.map +1 -0
  364. package/dist/runtime/schedule.js +371 -0
  365. package/dist/runtime/storeCoordination.d.ts +23 -0
  366. package/dist/runtime/storeCoordination.d.ts.map +1 -0
  367. package/dist/runtime/storeCoordination.js +94 -0
  368. package/dist/runtime/toolResultSpill.d.ts +152 -0
  369. package/dist/runtime/toolResultSpill.d.ts.map +1 -0
  370. package/dist/runtime/toolResultSpill.js +351 -0
  371. package/dist/runtime/turnRequestLedger.d.ts +160 -0
  372. package/dist/runtime/turnRequestLedger.d.ts.map +1 -0
  373. package/dist/runtime/turnRequestLedger.js +249 -0
  374. package/dist/runtime/turnUsageLedger.d.ts +143 -0
  375. package/dist/runtime/turnUsageLedger.d.ts.map +1 -0
  376. package/dist/runtime/turnUsageLedger.js +203 -0
  377. package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts +17 -0
  378. package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts.map +1 -0
  379. package/dist/runtime/wakeAcceptanceProcessIdentity.js +50 -0
  380. package/dist/runtime/wakeAcceptanceReconciliation.d.ts +211 -0
  381. package/dist/runtime/wakeAcceptanceReconciliation.d.ts.map +1 -0
  382. package/dist/runtime/wakeAcceptanceReconciliation.js +289 -0
  383. package/dist/runtime/wakeAcceptanceRecord.d.ts +23 -0
  384. package/dist/runtime/wakeAcceptanceRecord.d.ts.map +1 -0
  385. package/dist/runtime/wakeAcceptanceRecord.js +56 -0
  386. package/dist/runtime/wakeAcceptanceRetention.d.ts +12 -0
  387. package/dist/runtime/wakeAcceptanceRetention.d.ts.map +1 -0
  388. package/dist/runtime/wakeAcceptanceRetention.js +12 -0
  389. package/dist/runtime/wakeAcceptanceStore.d.ts +113 -0
  390. package/dist/runtime/wakeAcceptanceStore.d.ts.map +1 -0
  391. package/dist/runtime/wakeAcceptanceStore.js +558 -0
  392. package/dist/runtime/wakeAcceptanceTypes.d.ts +179 -0
  393. package/dist/runtime/wakeAcceptanceTypes.d.ts.map +1 -0
  394. package/dist/runtime/wakeAcceptanceTypes.js +95 -0
  395. package/dist/runtime/wakeFuse.d.ts +69 -0
  396. package/dist/runtime/wakeFuse.d.ts.map +1 -0
  397. package/dist/runtime/wakeFuse.js +367 -0
  398. package/package.json +25 -17
  399. package/dist/examples/mixed-engine-org.d.ts +0 -2
  400. package/dist/examples/mixed-engine-org.d.ts.map +0 -1
  401. package/dist/examples/mixed-engine-org.js +0 -351
  402. package/dist/examples/mixedEngineCli.d.ts +0 -15
  403. package/dist/examples/mixedEngineCli.d.ts.map +0 -1
  404. package/dist/examples/mixedEngineCli.js +0 -174
@@ -0,0 +1,135 @@
1
+ import { type EngineBrokerInferenceRequest, type EngineBrokerInferenceResponse } from "./engineBrokerInferenceProtocol.js";
2
+ import { type EngineBrokerMcpCallObservation } from "./engineBrokerMcpCallLog.js";
3
+ import { type EngineBrokerTurnAccounting, type EngineBrokerTurnLimitOverrides } from "./engineBrokerTurnAccounting.js";
4
+ /**
5
+ * Control protocol v2. Both ends ship in the same Daimon package and image
6
+ * (organization runtime client, broker service), so the wire moved to v2 in
7
+ * one step: v1 frames are refused. v1 survives only as a *durable record*
8
+ * shape, which {@link parseEngineBrokerV1TerminalResponse} still reads so
9
+ * turns sealed before the upgrade keep replaying.
10
+ */
11
+ declare const VERSION: "noopolis.daimon.engine-broker.v2";
12
+ export declare const ENGINE_BROKER_VERSION: "noopolis.daimon.engine-broker.v2";
13
+ declare const V1: "noopolis.daimon.engine-broker.v1";
14
+ export declare const ENGINE_BROKER_MAX_FRAME_BYTES = 1048576;
15
+ export type EngineBrokerRequest = Readonly<{
16
+ version: typeof VERSION;
17
+ kind: "health";
18
+ requestId: string;
19
+ }> | Readonly<{
20
+ version: typeof VERSION;
21
+ kind: "start_turn";
22
+ requestId: string;
23
+ turnId: string;
24
+ agentId: string;
25
+ wakeId: string;
26
+ prompt: string;
27
+ mcpEndpoint: string;
28
+ limits?: EngineBrokerTurnLimitOverrides;
29
+ }> | Readonly<{
30
+ version: typeof VERSION;
31
+ kind: "cancel_turn";
32
+ requestId: string;
33
+ turnId: string;
34
+ }> | EngineBrokerInferenceRequest;
35
+ /**
36
+ * `reason` is the worker's own last words (`engineBrokerNativeClient.ts`),
37
+ * already redacted and flattened to one bounded line by the broker. It is the
38
+ * only field a failed turn carries that the worker itself wrote, so it is
39
+ * optional, bounded, control-character free, and admitted only for the
40
+ * statuses where a worker actually ran and spoke.
41
+ */
42
+ export interface EngineBrokerFailureDiagnostic {
43
+ status: string;
44
+ stage: string;
45
+ failureClass: string;
46
+ profileApplied: boolean;
47
+ reason?: string;
48
+ exitCode: number;
49
+ termSignal: number;
50
+ workerPid: number;
51
+ workerUid: number;
52
+ startTicks: string;
53
+ }
54
+ export declare const ENGINE_BROKER_MAX_DIAGNOSTIC_REASON_BYTES = 768;
55
+ export type EngineBrokerResponse = Readonly<{
56
+ version: typeof VERSION;
57
+ kind: "ready";
58
+ requestId: string;
59
+ brokerUid: 2100;
60
+ providerProxyPort: 43123;
61
+ mcpFacadePort: 43124;
62
+ registrations: number;
63
+ credentialStale: false;
64
+ realmLease: true;
65
+ workerIsolation: true;
66
+ }> | Readonly<{
67
+ version: typeof VERSION;
68
+ kind: "accepted";
69
+ requestId: string;
70
+ turnId: string;
71
+ }> | (Readonly<{
72
+ version: typeof VERSION;
73
+ kind: "completed";
74
+ requestId: string;
75
+ turnId: string;
76
+ text: string;
77
+ workerPid: number;
78
+ workerUid: number;
79
+ workerStartTime: string;
80
+ }> & EngineBrokerTurnAccounting) | (Readonly<{
81
+ version: typeof VERSION;
82
+ kind: "failed";
83
+ requestId: string;
84
+ turnId: string;
85
+ code: EngineBrokerFailureCode;
86
+ diagnostic?: EngineBrokerFailureDiagnostic;
87
+ mcpCalls?: EngineBrokerMcpCallObservation;
88
+ }> & EngineBrokerTurnAccounting) | EngineBrokerInferenceResponse;
89
+ /**
90
+ * The one name for a fenced credential realm. The turn's failure code, the
91
+ * proxy's refusal reason on a worker request, and the grant path's 401 body
92
+ * (`GROK_INFERENCE_AUTH_STALE_BODY`) all say this same word, so an operator
93
+ * greps one string across every surface instead of three spellings of it.
94
+ */
95
+ export declare const ENGINE_BROKER_AUTH_STALE: "auth_stale";
96
+ export declare const ENGINE_BROKER_FAILURE_CODES: readonly ["auth_stale", "cancelled", "engine_failed", "invalid_request", "limit_exceeded", "turn_conflict", "unavailable"];
97
+ export type EngineBrokerFailureCode = (typeof ENGINE_BROKER_FAILURE_CODES)[number];
98
+ export type EngineBrokerTerminalResponse = Extract<EngineBrokerResponse, {
99
+ kind: "completed" | "failed";
100
+ }>;
101
+ type V1Completed = Readonly<{
102
+ version: typeof V1;
103
+ kind: "completed";
104
+ requestId: string;
105
+ turnId: string;
106
+ text: string;
107
+ workerPid: number;
108
+ workerUid: number;
109
+ workerStartTime: string;
110
+ }>;
111
+ type V1Failed = Readonly<{
112
+ version: typeof V1;
113
+ kind: "failed";
114
+ requestId: string;
115
+ turnId: string;
116
+ code: Exclude<EngineBrokerFailureCode, "limit_exceeded">;
117
+ diagnostic?: EngineBrokerFailureDiagnostic;
118
+ }>;
119
+ export type EngineBrokerV1TerminalResponse = V1Completed | V1Failed;
120
+ export declare function parseEngineBrokerRequest(value: unknown): EngineBrokerRequest;
121
+ export declare function parseEngineBrokerResponse(value: unknown): EngineBrokerResponse;
122
+ /**
123
+ * A terminal response persisted by a pre-v2 broker: the v1 field sets exactly,
124
+ * with no accounting. Accepted only from the durable turn registry, never from
125
+ * the wire.
126
+ */
127
+ export declare function parseEngineBrokerV1TerminalResponse(value: unknown): EngineBrokerV1TerminalResponse;
128
+ export declare function encodeEngineBrokerFrame(value: EngineBrokerRequest | EngineBrokerResponse): Buffer;
129
+ export declare class EngineBrokerFrameDecoder {
130
+ private buffered;
131
+ push(chunk: Uint8Array): unknown[];
132
+ finish(): void;
133
+ }
134
+ export {};
135
+ //# sourceMappingURL=engineBrokerProtocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineBrokerProtocol.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerProtocol.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,274 @@
1
+ import { isEngineBrokerInferenceRequestKind, isEngineBrokerInferenceResponseKind, parseEngineBrokerInferenceRequest, parseEngineBrokerInferenceResponse } from "./engineBrokerInferenceProtocol.js";
2
+ import { ENGINE_BROKER_MCP_CALL_NAME, ENGINE_BROKER_MCP_OUTSTANDING_MAX, ENGINE_BROKER_MCP_REFUSAL_REASONS, ENGINE_BROKER_MCP_TUNNEL_MAX } from "./engineBrokerMcpCallLog.js";
3
+ import { parseEngineBrokerTurnAccounting, parseEngineBrokerTurnLimitOverrides } from "./engineBrokerTurnAccounting.js";
4
+ /**
5
+ * Control protocol v2. Both ends ship in the same Daimon package and image
6
+ * (organization runtime client, broker service), so the wire moved to v2 in
7
+ * one step: v1 frames are refused. v1 survives only as a *durable record*
8
+ * shape, which {@link parseEngineBrokerV1TerminalResponse} still reads so
9
+ * turns sealed before the upgrade keep replaying.
10
+ */
11
+ const VERSION = "noopolis.daimon.engine-broker.v2";
12
+ export const ENGINE_BROKER_VERSION = VERSION;
13
+ const V1 = "noopolis.daimon.engine-broker.v1";
14
+ export const ENGINE_BROKER_MAX_FRAME_BYTES = 1_048_576;
15
+ const ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
16
+ export const ENGINE_BROKER_MAX_DIAGNOSTIC_REASON_BYTES = 768;
17
+ /**
18
+ * The one name for a fenced credential realm. The turn's failure code, the
19
+ * proxy's refusal reason on a worker request, and the grant path's 401 body
20
+ * (`GROK_INFERENCE_AUTH_STALE_BODY`) all say this same word, so an operator
21
+ * greps one string across every surface instead of three spellings of it.
22
+ */
23
+ export const ENGINE_BROKER_AUTH_STALE = "auth_stale";
24
+ export const ENGINE_BROKER_FAILURE_CODES = [ENGINE_BROKER_AUTH_STALE, "cancelled", "engine_failed", "invalid_request", "limit_exceeded", "turn_conflict", "unavailable"];
25
+ const ACCOUNTING = ["outcome", "usage", "model", "requests", "limitReason"];
26
+ const record = (value) => {
27
+ if (value === null || typeof value !== "object" || Array.isArray(value) || (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null))
28
+ throw new TypeError("invalid broker frame");
29
+ return value;
30
+ };
31
+ const exact = (value, fields) => {
32
+ if (Object.keys(value).length !== fields.length || fields.some((field) => !Object.hasOwn(value, field)))
33
+ throw new TypeError("invalid broker frame");
34
+ };
35
+ const text = (value, maxBytes) => {
36
+ if (typeof value !== "string" || value.length === 0 || Buffer.byteLength(value, "utf8") > maxBytes)
37
+ throw new TypeError("invalid broker frame");
38
+ return value;
39
+ };
40
+ const id = (value) => { const result = text(value, 128); if (!ID.test(result))
41
+ throw new TypeError("invalid broker frame"); return result; };
42
+ const version = (value) => { if (value !== VERSION)
43
+ throw new TypeError("invalid broker frame"); return VERSION; };
44
+ export function parseEngineBrokerRequest(value) {
45
+ const input = record(value);
46
+ version(input.version);
47
+ if (input.kind === "health") {
48
+ exact(input, ["version", "kind", "requestId"]);
49
+ return { version: VERSION, kind: "health", requestId: id(input.requestId) };
50
+ }
51
+ if (input.kind === "start_turn") {
52
+ const fields = ["version", "kind", "requestId", "turnId", "agentId", "wakeId", "prompt", "mcpEndpoint"];
53
+ exact(input, input.limits === undefined ? fields : [...fields, "limits"]);
54
+ const mcpEndpoint = text(input.mcpEndpoint, 2048);
55
+ const url = new URL(mcpEndpoint);
56
+ if (url.protocol !== "http:" || url.hostname !== "127.0.0.1" || url.pathname !== "/mcp")
57
+ throw new TypeError("invalid broker frame");
58
+ let limits;
59
+ if (input.limits !== undefined) {
60
+ try {
61
+ limits = parseEngineBrokerTurnLimitOverrides(input.limits);
62
+ }
63
+ catch {
64
+ throw new TypeError("invalid broker frame");
65
+ }
66
+ }
67
+ return { version: VERSION, kind: "start_turn", requestId: id(input.requestId), turnId: id(input.turnId), agentId: id(input.agentId), wakeId: id(input.wakeId), prompt: text(input.prompt, 65_536), mcpEndpoint, ...(limits === undefined ? {} : { limits }) };
68
+ }
69
+ if (input.kind === "cancel_turn") {
70
+ exact(input, ["version", "kind", "requestId", "turnId"]);
71
+ return { version: VERSION, kind: "cancel_turn", requestId: id(input.requestId), turnId: id(input.turnId) };
72
+ }
73
+ if (isEngineBrokerInferenceRequestKind(input.kind))
74
+ return parseEngineBrokerInferenceRequest(input, id(input.requestId), VERSION);
75
+ throw new TypeError("invalid broker frame");
76
+ }
77
+ export function parseEngineBrokerResponse(value) {
78
+ const input = record(value);
79
+ version(input.version);
80
+ if (input.kind === "ready") {
81
+ exact(input, ["version", "kind", "requestId", "brokerUid", "providerProxyPort", "mcpFacadePort", "registrations", "credentialStale", "realmLease", "workerIsolation"]);
82
+ if (input.brokerUid !== 2100 || input.providerProxyPort !== 43123 || input.mcpFacadePort !== 43124 || !Number.isSafeInteger(input.registrations) || input.registrations < 1 || input.credentialStale !== false || input.realmLease !== true || input.workerIsolation !== true)
83
+ throw new TypeError("invalid broker frame");
84
+ return { version: VERSION, kind: "ready", requestId: id(input.requestId), brokerUid: 2100, providerProxyPort: 43123, mcpFacadePort: 43124, registrations: input.registrations, credentialStale: false, realmLease: true, workerIsolation: true };
85
+ }
86
+ if (input.kind === "accepted") {
87
+ exact(input, ["version", "kind", "requestId", "turnId"]);
88
+ return { version: VERSION, kind: "accepted", requestId: id(input.requestId), turnId: id(input.turnId) };
89
+ }
90
+ if (input.kind === "completed" || input.kind === "failed")
91
+ return parseTerminal(input, VERSION);
92
+ if (isEngineBrokerInferenceResponseKind(input.kind))
93
+ return parseEngineBrokerInferenceResponse(input, id(input.requestId), VERSION);
94
+ throw new TypeError("invalid broker frame");
95
+ }
96
+ /**
97
+ * A terminal response persisted by a pre-v2 broker: the v1 field sets exactly,
98
+ * with no accounting. Accepted only from the durable turn registry, never from
99
+ * the wire.
100
+ */
101
+ export function parseEngineBrokerV1TerminalResponse(value) {
102
+ const input = record(value);
103
+ if (input.version !== V1 || (input.kind !== "completed" && input.kind !== "failed"))
104
+ throw new TypeError("invalid broker frame");
105
+ return parseTerminal(input, V1);
106
+ }
107
+ function parseTerminal(input, expected) {
108
+ const accounting = expected === VERSION ? ACCOUNTING : [];
109
+ if (input.kind === "completed") {
110
+ exact(input, ["version", "kind", "requestId", "turnId", "text", "workerPid", "workerUid", "workerStartTime", ...accounting]);
111
+ if (!Number.isSafeInteger(input.workerPid) || input.workerPid < 1 || !Number.isSafeInteger(input.workerUid) || input.workerUid < 1)
112
+ throw new TypeError("invalid broker frame");
113
+ const base = { kind: "completed", requestId: id(input.requestId), turnId: id(input.turnId), text: text(input.text, 262_144), workerPid: input.workerPid, workerUid: input.workerUid, workerStartTime: id(input.workerStartTime) };
114
+ return expected === VERSION ? { version: VERSION, ...base, ...parseEngineBrokerTurnAccounting(input, "completed") } : { version: V1, ...base };
115
+ }
116
+ // `mcpCalls` is the broker's own observation of the worker's tool calls
117
+ // (`engineBrokerMcpCallLog.ts`), additive in v2 and never part of a v1
118
+ // record, which predates the instrument entirely.
119
+ if (expected === V1 && input.mcpCalls !== undefined)
120
+ throw new TypeError("invalid broker frame");
121
+ const fields = ["version", "kind", "requestId", "turnId", "code", ...accounting, ...(input.diagnostic === undefined ? [] : ["diagnostic"]), ...(input.mcpCalls === undefined ? [] : ["mcpCalls"])];
122
+ exact(input, fields);
123
+ const codes = expected === VERSION ? ENGINE_BROKER_FAILURE_CODES : ENGINE_BROKER_FAILURE_CODES.filter((code) => code !== "limit_exceeded");
124
+ if (!codes.includes(input.code))
125
+ throw new TypeError("invalid broker frame");
126
+ let diagnostic;
127
+ if (input.diagnostic !== undefined) {
128
+ const value = record(input.diagnostic);
129
+ const fields = ["status", "stage", "failureClass", "profileApplied", "exitCode", "termSignal", "workerPid", "workerUid", "startTicks"];
130
+ exact(value, value.reason === undefined ? fields : [...fields, "reason"]);
131
+ if (value.reason !== undefined && (typeof value.reason !== "string" || value.reason.length === 0 || Buffer.byteLength(value.reason, "utf8") > ENGINE_BROKER_MAX_DIAGNOSTIC_REASON_BYTES || /[\u0000-\u001f\u007f]/u.test(value.reason)))
132
+ throw new TypeError("invalid broker frame");
133
+ const status = ["prelaunch_failed", "worker_failed", "output_failed", "cancelled"], stage = ["peer", "request", "registration", "executable", "exec", "wait", "output", "attestation"], failureClass = ["peer", "protocol", "registration", "executable", "exec", "wait", "output_limit", "cancelled", "profile_missing", "profile_invalid"];
134
+ if (!status.includes(value.status) || !stage.includes(value.stage) || !failureClass.includes(value.failureClass) || typeof value.profileApplied !== "boolean" || ![value.exitCode, value.termSignal, value.workerPid, value.workerUid].every(Number.isSafeInteger) || typeof value.startTicks !== "string" || !/^(0|[1-9][0-9]*)$/u.test(value.startTicks) || !closedDiagnostic(value))
135
+ throw new TypeError("invalid broker frame");
136
+ diagnostic = value;
137
+ }
138
+ const base = { kind: "failed", requestId: id(input.requestId), turnId: id(input.turnId), code: input.code, ...(diagnostic ? { diagnostic } : {}) };
139
+ if (expected === V1)
140
+ return { version: V1, ...base };
141
+ const accountingValue = parseEngineBrokerTurnAccounting(input, "failed");
142
+ if ((input.code === "limit_exceeded") !== (accountingValue.limitReason !== "none"))
143
+ throw new TypeError("invalid broker frame");
144
+ const mcpCalls = input.mcpCalls === undefined ? undefined : parseMcpCallObservation(input.mcpCalls);
145
+ return { version: VERSION, ...base, ...(mcpCalls === undefined ? {} : { mcpCalls }), ...accountingValue };
146
+ }
147
+ /**
148
+ * Names and timings, bounded, and internally consistent: a report can never
149
+ * claim more answered calls than started ones, nor more outstanding ones than
150
+ * started minus answered. Every count is its own measurement, so a missing
151
+ * field is refused rather than defaulted — a zero the broker did not measure
152
+ * would read exactly like one it did.
153
+ */
154
+ function parseMcpCallObservation(value) {
155
+ const input = record(value);
156
+ // `tunnels` is optional for one reason only: a turn sealed before the GET
157
+ // tunnel was observed carries no such member, and its record must still
158
+ // replay. Absence there means "the instrument did not exist", never zero.
159
+ exact(input, ["started", "answered", "undecoded", "outstanding", ...(input.tunnels === undefined ? [] : ["tunnels"]), ...(input.refusals === undefined ? [] : ["refusals"])]);
160
+ const started = input.started, answered = input.answered, undecoded = input.undecoded;
161
+ if (![started, answered, undecoded].every((count) => Number.isSafeInteger(count) && count >= 0))
162
+ throw new TypeError("invalid broker frame");
163
+ if (!Array.isArray(input.outstanding) || input.outstanding.length > ENGINE_BROKER_MCP_OUTSTANDING_MAX)
164
+ throw new TypeError("invalid broker frame");
165
+ const outstanding = input.outstanding.map((entry) => {
166
+ const call = record(entry);
167
+ exact(call, ["name", "outstandingMs"]);
168
+ if (typeof call.name !== "string" || !ENGINE_BROKER_MCP_CALL_NAME.test(call.name))
169
+ throw new TypeError("invalid broker frame");
170
+ if (!Number.isSafeInteger(call.outstandingMs) || call.outstandingMs < 0)
171
+ throw new TypeError("invalid broker frame");
172
+ return { name: call.name, outstandingMs: call.outstandingMs };
173
+ });
174
+ if (answered > started || outstanding.length > started - answered)
175
+ throw new TypeError("invalid broker frame");
176
+ const tunnels = input.tunnels === undefined ? undefined : parseMcpTunnelObservation(input.tunnels);
177
+ const refusals = input.refusals === undefined ? undefined : parseMcpRefusalObservation(input.refusals);
178
+ return { started: started, answered: answered, undecoded: undecoded, outstanding, ...(tunnels === undefined ? {} : { tunnels }), ...(refusals === undefined ? {} : { refusals }) };
179
+ }
180
+ /**
181
+ * The refused requests, by reason class: one count per closed reason, all of
182
+ * them required once the member is present. Optional for the same single
183
+ * reason `tunnels` is — a turn sealed before the facade counted its refusals
184
+ * must still replay — so its absence means "not measured" and never zero, and
185
+ * a partial member is refused rather than zero-filled.
186
+ */
187
+ function parseMcpRefusalObservation(value) {
188
+ const input = record(value);
189
+ exact(input, ENGINE_BROKER_MCP_REFUSAL_REASONS);
190
+ for (const reason of ENGINE_BROKER_MCP_REFUSAL_REASONS) {
191
+ if (!Number.isSafeInteger(input[reason]) || input[reason] < 0)
192
+ throw new TypeError("invalid broker frame");
193
+ }
194
+ return Object.fromEntries(ENGINE_BROKER_MCP_REFUSAL_REASONS.map((reason) => [reason, input[reason]]));
195
+ }
196
+ /**
197
+ * The GET SSE tunnels, under the call observation's rules: counts and elapsed
198
+ * milliseconds, bounded, and internally consistent. A tunnel cannot close
199
+ * before it opened, cannot deliver without having opened, and no more can be
200
+ * reported open than `opened - closed` — a report claiming otherwise is a
201
+ * frame, not a measurement.
202
+ */
203
+ function parseMcpTunnelObservation(value) {
204
+ const input = record(value);
205
+ exact(input, ["opened", "closed", "delivered", "open"]);
206
+ const opened = input.opened, closed = input.closed, delivered = input.delivered;
207
+ if (![opened, closed, delivered].every((count) => Number.isSafeInteger(count) && count >= 0))
208
+ throw new TypeError("invalid broker frame");
209
+ if (closed > opened || delivered > opened)
210
+ throw new TypeError("invalid broker frame");
211
+ if (!Array.isArray(input.open) || input.open.length > ENGINE_BROKER_MCP_TUNNEL_MAX || input.open.length > opened - closed)
212
+ throw new TypeError("invalid broker frame");
213
+ const open = input.open.map((entry) => {
214
+ const tunnel = record(entry);
215
+ exact(tunnel, ["openMs", "delivered"]);
216
+ if (!Number.isSafeInteger(tunnel.openMs) || tunnel.openMs < 0 || typeof tunnel.delivered !== "boolean")
217
+ throw new TypeError("invalid broker frame");
218
+ return { openMs: tunnel.openMs, delivered: tunnel.delivered };
219
+ });
220
+ return { opened: opened, closed: closed, delivered: delivered, open };
221
+ }
222
+ function closedDiagnostic(value) {
223
+ if (value.profileApplied !== false || value.workerPid < 0 || value.workerUid < 0)
224
+ return false;
225
+ // Only a worker that ran and wrote something can have said why it failed:
226
+ // no prelaunch failure and no attestation refusal carries worker words.
227
+ if (value.reason !== undefined && !((value.status === "worker_failed" && value.stage === "wait") || value.status === "output_failed" || value.status === "cancelled"))
228
+ return false;
229
+ const noWorker = value.workerPid === 0 && value.workerUid === 0 && value.startTicks === "0";
230
+ const worker = value.workerPid > 0 && value.workerUid >= 2200 && value.startTicks !== "0";
231
+ if (value.status === "prelaunch_failed")
232
+ return noWorker && { peer: "peer", request: "protocol", registration: "registration", executable: "executable", exec: "exec" }[value.stage] === value.failureClass;
233
+ if (value.status === "worker_failed" && value.stage === "attestation")
234
+ return worker && (value.failureClass === "profile_missing" || value.failureClass === "profile_invalid");
235
+ if (value.status === "worker_failed")
236
+ return worker && value.stage === "wait" && (value.failureClass === "exec" || value.failureClass === "wait");
237
+ if (value.status === "output_failed")
238
+ return worker && value.stage === "output" && value.failureClass === "output_limit";
239
+ return value.status === "cancelled" && worker && value.stage === "wait" && value.failureClass === "cancelled";
240
+ }
241
+ export function encodeEngineBrokerFrame(value) {
242
+ const body = Buffer.from(JSON.stringify(value), "utf8");
243
+ if (body.length > ENGINE_BROKER_MAX_FRAME_BYTES)
244
+ throw new TypeError("invalid broker frame");
245
+ const frame = Buffer.allocUnsafe(body.length + 4);
246
+ frame.writeUInt32BE(body.length);
247
+ body.copy(frame, 4);
248
+ return frame;
249
+ }
250
+ export class EngineBrokerFrameDecoder {
251
+ buffered = Buffer.alloc(0);
252
+ push(chunk) {
253
+ this.buffered = Buffer.concat([this.buffered, chunk]);
254
+ const values = [];
255
+ while (this.buffered.length >= 4) {
256
+ const length = this.buffered.readUInt32BE(0);
257
+ if (length === 0 || length > ENGINE_BROKER_MAX_FRAME_BYTES)
258
+ throw new TypeError("invalid broker frame");
259
+ if (this.buffered.length < length + 4)
260
+ break;
261
+ const body = this.buffered.subarray(4, length + 4);
262
+ this.buffered = this.buffered.subarray(length + 4);
263
+ try {
264
+ values.push(JSON.parse(body.toString("utf8")));
265
+ }
266
+ catch {
267
+ throw new TypeError("invalid broker frame");
268
+ }
269
+ }
270
+ return values;
271
+ }
272
+ finish() { if (this.buffered.length !== 0)
273
+ throw new TypeError("incomplete broker frame"); }
274
+ }
@@ -0,0 +1,70 @@
1
+ import type { EngineBrokerTerminalResponse } from "./engineBrokerProtocol.js";
2
+ /**
3
+ * The operator-visible half of a sealed terminal turn, as a durable row.
4
+ *
5
+ * The seal itself already carries everything an operator needs to read a turn
6
+ * that stopped acting — the failure code, the worker's own redacted last words,
7
+ * and `engineBrokerMcpCallLog.ts`'s observation of the tool call the worker was
8
+ * blocked on. All of it travels in the control-protocol terminal response, and
9
+ * that response is the one artifact a *hung* turn never produces: the client is
10
+ * gone before the broker answers, the turn registry record lives in the
11
+ * broker's own `0700` turn store, and a training slot's control root is tmpfs
12
+ * that dies with the container. Six live runs reproduced the same signature and
13
+ * none of them could read the instrument built for it.
14
+ *
15
+ * What does survive a slot is the broker's ledger directory: Paideia already
16
+ * recovers `usage.jsonl` and `requests.jsonl` from it on the failure path. So
17
+ * this is a third stream beside those two, written by the broker — still the
18
+ * single sealed usage writer — from the sealed response and nothing else, at
19
+ * the moment that response is sealed.
20
+ *
21
+ * Its rules are the two ledgers' rules:
22
+ *
23
+ * - **Numbers, names, timings and closed vocabularies only.** The failure code,
24
+ * the accounting, the diagnostic's closed `status`/`stage`/`failure_class`
25
+ * and its already-redacted, already-bounded, control-character-free `reason`
26
+ * (`engineBrokerNativeClient.ts` produced it; nothing here re-derives it),
27
+ * plus tool-call names, GET-tunnel counts and elapsed milliseconds. Never a
28
+ * prompt, a body, a
29
+ * reply, a bearer, a capability or a session id — none of which the terminal
30
+ * response carries in the first place.
31
+ * - **Absence stays absence.** `mcp` is written only when the facade actually
32
+ * observed the turn, `diagnostic` only when the sealed response carried one,
33
+ * and `code` only for a failure. A turn that called no tool publishes
34
+ * `started: 0`, which is a measurement; a turn the facade never registered
35
+ * publishes no `mcp` member at all, which is not.
36
+ * - **It can never fail a turn.** The row is rendered from an
37
+ * already-validated frame and appended through `recordLedgerLines`, which
38
+ * swallows every I/O fault.
39
+ *
40
+ * A separate stream and a separate `v`, for `turnRequestLedger.ts`'s reason:
41
+ * Spawnfile's reader pins `noopolis.daimon.turn-usage.v1` and drops any other
42
+ * `v` outright, and Paideia's request reader refuses a row it cannot type. A
43
+ * row in a new file is invisible to both.
44
+ */
45
+ export declare const TURN_SEAL_LEDGER_VERSION: "noopolis.daimon.turn-seal.v1";
46
+ /** Default location: beside `usage.jsonl` and `requests.jsonl`, no new mount. */
47
+ export declare const TURN_SEAL_LEDGER: {
48
+ readonly version: "noopolis.daimon.turn-seal.v1";
49
+ readonly directoryPath: "/var/lib/spawnfile/daimon/usage";
50
+ readonly filePath: "/var/lib/spawnfile/daimon/usage/turns.jsonl";
51
+ readonly rotatedFilePath: "/var/lib/spawnfile/daimon/usage/turns.jsonl.1";
52
+ readonly fileMode: 416;
53
+ };
54
+ /** A rendered seal line is bounded by its own contents: a 768-byte reason, 16 bounded names and 8 tunnel timings. */
55
+ export declare const TURN_SEAL_MAX_LINE_BYTES = 8192;
56
+ export type BrokerTurnSealEntry = Readonly<{
57
+ agent: string;
58
+ wake: string;
59
+ at: string;
60
+ }>;
61
+ /**
62
+ * One newline-terminated row for one sealed terminal turn.
63
+ *
64
+ * Every member is copied from the terminal response the protocol already
65
+ * validated, so this projection cannot widen what the response admits; it is an
66
+ * allow-list rather than a spread, so a future additive member of the response
67
+ * does not silently become a ledger field.
68
+ */
69
+ export declare const renderBrokerTurnSealLine: (terminal: EngineBrokerTerminalResponse, entry: BrokerTurnSealEntry) => string;
70
+ //# sourceMappingURL=engineBrokerSealLedger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineBrokerSealLedger.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerSealLedger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAG9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,wBAAwB,EAAG,8BAAuC,CAAC;AAEhF,iFAAiF;AACjF,eAAO,MAAM,gBAAgB;;;;;;CAMnB,CAAC;AAEX,qHAAqH;AACrH,eAAO,MAAM,wBAAwB,OAAQ,CAAC;AAE9C,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAIxF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,UAAU,4BAA4B,EAAE,OAAO,mBAAmB,KAAG,MAyDxG,CAAC"}
@@ -0,0 +1,123 @@
1
+ import { ENGINE_BROKER_MCP_CALL_NAME, ENGINE_BROKER_MCP_OUTSTANDING_MAX, ENGINE_BROKER_MCP_REFUSAL_REASONS, ENGINE_BROKER_MCP_TUNNEL_MAX } from "./engineBrokerMcpCallLog.js";
2
+ import { TURN_USAGE_LEDGER, TURN_USAGE_MAX_IDENTIFIER_CHARS } from "./turnUsageLedger.js";
3
+ /**
4
+ * The operator-visible half of a sealed terminal turn, as a durable row.
5
+ *
6
+ * The seal itself already carries everything an operator needs to read a turn
7
+ * that stopped acting — the failure code, the worker's own redacted last words,
8
+ * and `engineBrokerMcpCallLog.ts`'s observation of the tool call the worker was
9
+ * blocked on. All of it travels in the control-protocol terminal response, and
10
+ * that response is the one artifact a *hung* turn never produces: the client is
11
+ * gone before the broker answers, the turn registry record lives in the
12
+ * broker's own `0700` turn store, and a training slot's control root is tmpfs
13
+ * that dies with the container. Six live runs reproduced the same signature and
14
+ * none of them could read the instrument built for it.
15
+ *
16
+ * What does survive a slot is the broker's ledger directory: Paideia already
17
+ * recovers `usage.jsonl` and `requests.jsonl` from it on the failure path. So
18
+ * this is a third stream beside those two, written by the broker — still the
19
+ * single sealed usage writer — from the sealed response and nothing else, at
20
+ * the moment that response is sealed.
21
+ *
22
+ * Its rules are the two ledgers' rules:
23
+ *
24
+ * - **Numbers, names, timings and closed vocabularies only.** The failure code,
25
+ * the accounting, the diagnostic's closed `status`/`stage`/`failure_class`
26
+ * and its already-redacted, already-bounded, control-character-free `reason`
27
+ * (`engineBrokerNativeClient.ts` produced it; nothing here re-derives it),
28
+ * plus tool-call names, GET-tunnel counts and elapsed milliseconds. Never a
29
+ * prompt, a body, a
30
+ * reply, a bearer, a capability or a session id — none of which the terminal
31
+ * response carries in the first place.
32
+ * - **Absence stays absence.** `mcp` is written only when the facade actually
33
+ * observed the turn, `diagnostic` only when the sealed response carried one,
34
+ * and `code` only for a failure. A turn that called no tool publishes
35
+ * `started: 0`, which is a measurement; a turn the facade never registered
36
+ * publishes no `mcp` member at all, which is not.
37
+ * - **It can never fail a turn.** The row is rendered from an
38
+ * already-validated frame and appended through `recordLedgerLines`, which
39
+ * swallows every I/O fault.
40
+ *
41
+ * A separate stream and a separate `v`, for `turnRequestLedger.ts`'s reason:
42
+ * Spawnfile's reader pins `noopolis.daimon.turn-usage.v1` and drops any other
43
+ * `v` outright, and Paideia's request reader refuses a row it cannot type. A
44
+ * row in a new file is invisible to both.
45
+ */
46
+ export const TURN_SEAL_LEDGER_VERSION = "noopolis.daimon.turn-seal.v1";
47
+ /** Default location: beside `usage.jsonl` and `requests.jsonl`, no new mount. */
48
+ export const TURN_SEAL_LEDGER = {
49
+ version: TURN_SEAL_LEDGER_VERSION,
50
+ directoryPath: TURN_USAGE_LEDGER.directoryPath,
51
+ filePath: `${TURN_USAGE_LEDGER.directoryPath}/turns.jsonl`,
52
+ rotatedFilePath: `${TURN_USAGE_LEDGER.directoryPath}/turns.jsonl.1`,
53
+ fileMode: TURN_USAGE_LEDGER.fileMode
54
+ };
55
+ /** A rendered seal line is bounded by its own contents: a 768-byte reason, 16 bounded names and 8 tunnel timings. */
56
+ export const TURN_SEAL_MAX_LINE_BYTES = 8_192;
57
+ const bounded = (value) => [...value].slice(0, TURN_USAGE_MAX_IDENTIFIER_CHARS).join("");
58
+ /**
59
+ * One newline-terminated row for one sealed terminal turn.
60
+ *
61
+ * Every member is copied from the terminal response the protocol already
62
+ * validated, so this projection cannot widen what the response admits; it is an
63
+ * allow-list rather than a spread, so a future additive member of the response
64
+ * does not silently become a ledger field.
65
+ */
66
+ export const renderBrokerTurnSealLine = (terminal, entry) => `${JSON.stringify({
67
+ v: TURN_SEAL_LEDGER_VERSION,
68
+ agent: bounded(entry.agent),
69
+ wake: bounded(entry.wake),
70
+ engine: "grok",
71
+ at: entry.at,
72
+ turn: terminal.turnId,
73
+ outcome: terminal.outcome,
74
+ requests: terminal.requests,
75
+ model: terminal.model,
76
+ limit_reason: terminal.limitReason,
77
+ ...(terminal.kind === "failed" ? { code: terminal.code } : {}),
78
+ ...(terminal.kind === "failed" && terminal.diagnostic !== undefined
79
+ ? {
80
+ diagnostic: {
81
+ status: terminal.diagnostic.status,
82
+ stage: terminal.diagnostic.stage,
83
+ failure_class: terminal.diagnostic.failureClass,
84
+ exit_code: terminal.diagnostic.exitCode,
85
+ term_signal: terminal.diagnostic.termSignal,
86
+ ...(terminal.diagnostic.reason === undefined ? {} : { reason: terminal.diagnostic.reason })
87
+ }
88
+ }
89
+ : {}),
90
+ ...(terminal.kind === "failed" && terminal.mcpCalls !== undefined
91
+ ? {
92
+ mcp: {
93
+ started: terminal.mcpCalls.started,
94
+ answered: terminal.mcpCalls.answered,
95
+ undecoded: terminal.mcpCalls.undecoded,
96
+ outstanding: terminal.mcpCalls.outstanding
97
+ .slice(0, ENGINE_BROKER_MCP_OUTSTANDING_MAX)
98
+ .map((call) => ({ name: ENGINE_BROKER_MCP_CALL_NAME.test(call.name) ? call.name : "<invalid>", outstanding_ms: call.outstandingMs })),
99
+ // Every request the facade refused before it could relay it, by reason
100
+ // class. Without it a turn whose capability was spent seals as
101
+ // `answered == started, outstanding: []`, which is what a healthy turn
102
+ // seals as.
103
+ ...(terminal.mcpCalls.refusals === undefined
104
+ ? {}
105
+ : { refusals: Object.fromEntries(ENGINE_BROKER_MCP_REFUSAL_REASONS.map((reason) => [reason, terminal.mcpCalls.refusals[reason]])) }),
106
+ // The session's standalone GET tunnel, absent for a turn sealed before
107
+ // the facade observed that channel at all.
108
+ ...(terminal.mcpCalls.tunnels === undefined
109
+ ? {}
110
+ : {
111
+ tunnels: {
112
+ opened: terminal.mcpCalls.tunnels.opened,
113
+ closed: terminal.mcpCalls.tunnels.closed,
114
+ delivered: terminal.mcpCalls.tunnels.delivered,
115
+ open: terminal.mcpCalls.tunnels.open
116
+ .slice(0, ENGINE_BROKER_MCP_TUNNEL_MAX)
117
+ .map((tunnel) => ({ open_ms: tunnel.openMs, delivered: tunnel.delivered }))
118
+ }
119
+ })
120
+ }
121
+ }
122
+ : {})
123
+ })}\n`;
@@ -0,0 +1,37 @@
1
+ import type { EngineBrokerTurnAccounting, EngineBrokerTurnLimitOverrides } from "./engineBrokerTurnAccounting.js";
2
+ import { type GrokInferenceGrantIssued, type GrokInferenceGrantRequest } from "./grokInferenceGrants.js";
3
+ export interface EngineBrokerServiceEngine {
4
+ turn(agentId: string, wakeId: string, prompt: string, mcpEndpoint: string, signal?: AbortSignal, limits?: EngineBrokerTurnLimitOverrides): Promise<Readonly<{
5
+ text: string;
6
+ workerPid: number;
7
+ workerUid: number;
8
+ workerStartTime: string;
9
+ }> & EngineBrokerTurnAccounting>;
10
+ readiness(): Readonly<{
11
+ providerProxyPort: number;
12
+ mcpFacadePort: number;
13
+ registrations: number;
14
+ credentialStale: boolean;
15
+ realmLease: boolean;
16
+ workerIsolation: boolean;
17
+ }>;
18
+ close(): Promise<void>;
19
+ /** Evaluator inference grants; an engine without them refuses every grant request as `unavailable`. Refusals throw {@link GrokInferenceGrantRefused}. */
20
+ requestInferenceGrant?(request: GrokInferenceGrantRequest): GrokInferenceGrantIssued;
21
+ releaseInferenceGrant?(grantId: string): boolean;
22
+ }
23
+ export declare function startEngineBrokerService(broker: EngineBrokerServiceEngine, socketPath?: string): Promise<{
24
+ close: () => Promise<void>;
25
+ health: () => {
26
+ activeTurns: number;
27
+ socketPath: string;
28
+ };
29
+ }>;
30
+ export declare function startEngineBrokerServiceWithIdentity(broker: EngineBrokerServiceEngine, socketPath: string, expectedUid: number): Promise<{
31
+ close: () => Promise<void>;
32
+ health: () => {
33
+ activeTurns: number;
34
+ socketPath: string;
35
+ };
36
+ }>;
37
+ //# sourceMappingURL=engineBrokerService.d.ts.map