@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,160 @@
1
+ /**
2
+ * The in-flight MCP tool calls of one brokered turn.
3
+ *
4
+ * Daimon writes a tool receipt only when a call *completes*, so a call that
5
+ * started and never returned is byte-identical, in every artifact, to a call
6
+ * that was never made. A live Grok turn stopped acting after its eighth
7
+ * provider response and was killed by the trial deadline seven minutes later
8
+ * with the proxy's per-request ledger reporting `open: 0` — every provider
9
+ * request closed — which leaves exactly one unlit path: a tool call the worker
10
+ * issued and the facade never answered.
11
+ *
12
+ * This is that light, and it follows the per-request ledger's rules rather
13
+ * than inventing its own:
14
+ *
15
+ * - **names and timings only.** The tool name off the JSON-RPC envelope and
16
+ * two clocks. Never arguments, never a result, never a session id, never a
17
+ * capability or bearer. A name that is not a plain short identifier is
18
+ * recorded as {@link ENGINE_BROKER_MCP_CALL_INVALID} rather than passed
19
+ * through, and the list is bounded at
20
+ * {@link ENGINE_BROKER_MCP_OUTSTANDING_MAX} with
21
+ * {@link ENGINE_BROKER_MCP_CALL_TRUNCATED} as its last entry.
22
+ * - **absence stays absence.** A turn the log never opened observes as
23
+ * `undefined`; a turn that made no call observes `started: 0`, which is not
24
+ * the same statement as an answered call. A POST whose body the facade could
25
+ * not read counts in `undecoded` and never as a call with a name, because a
26
+ * fabricated name is byte-identical to a measured one — and because "zero
27
+ * calls started" is exactly the reading this instrument exists to make
28
+ * trustworthy.
29
+ * - **it cannot fail a turn.** Every operation here is arithmetic over a map,
30
+ * the one parse is wrapped, and the facade treats a missing handle as a
31
+ * no-op.
32
+ *
33
+ * The same map carries the facade's *other* channel, and for the same reason.
34
+ * A `tools/call` is a POST that answers; the standalone `GET` SSE tunnel the
35
+ * Streamable HTTP transport opens once per session is the route a server
36
+ * notification or progress frame takes, and it stays open for the whole
37
+ * session by design. A worker parked reading that tunnel is, in every artifact
38
+ * the broker writes, indistinguishable from a worker doing nothing at all:
39
+ * every provider request closed, every tool call answered, and the turn idle
40
+ * until its deadline. {@link EngineBrokerMcpCallLog.openTunnel} records the
41
+ * lifecycle — how many the facade relayed, how many ended, and for the ones
42
+ * still open at seal time how long each has been open and whether the mount
43
+ * ever pushed a single byte through it. A tunnel held open having delivered
44
+ * nothing is a different fact from one actively carrying frames, and it is the
45
+ * difference that decides whether the tunnel is the blocker.
46
+ *
47
+ * Observing is all it does. The facade's behaviour is unchanged: nothing here
48
+ * closes, times out or refuses a tunnel, because an instrument that tore down
49
+ * the stream would destroy the evidence it exists to gather.
50
+ *
51
+ * "Answered" means the facade wrote a complete response back to the worker —
52
+ * the relay reached its own `end()`. A relay that was torn down (the worker
53
+ * died, the tunnel broke, the turn aborted) did *not* answer, so its calls stay
54
+ * outstanding with the elapsed time they had reached. That is the whole point:
55
+ * the turn's death must not retroactively mark the call it was blocked on as
56
+ * finished.
57
+ */
58
+ /**
59
+ * The same map carries the facade's *refusals*, for the sharpest form of the
60
+ * same problem. A refused request never reaches the relay at all, so a turn
61
+ * every one of whose requests was 403'd sealed as `answered == started,
62
+ * outstanding: []` — byte-identical to a healthy turn, which is precisely the
63
+ * reading this instrument exists to make trustworthy. The reason class is what
64
+ * makes it actionable: an exhausted per-turn capability budget — the facade's
65
+ * `ENGINE_BROKER_MCP_CAPABILITY_REQUESTS`, derived from the compiled turn
66
+ * bound times what a round may spend — is a different fault from a mount that
67
+ * was never registered, and both differ from a worker asking for a route the
68
+ * facade does not serve. Counts only, keyed by a closed vocabulary:
69
+ * never the token, the capability, the URL or the body. A refusal the facade
70
+ * cannot attribute to a turn — a bearer no live grant matches — is recorded
71
+ * nowhere, because attributing it to a turn would be inventing the fact.
72
+ */
73
+ export declare const ENGINE_BROKER_MCP_OUTSTANDING_MAX = 16;
74
+ export declare const ENGINE_BROKER_MCP_CALL_INVALID = "<invalid>";
75
+ export declare const ENGINE_BROKER_MCP_CALL_TRUNCATED = "<truncated>";
76
+ /** A plain short identifier, or one of the two sentinels above. */
77
+ export declare const ENGINE_BROKER_MCP_CALL_NAME: RegExp;
78
+ /** Open GET tunnels reported: a session opens one, so more than a handful is already the anomaly. */
79
+ export declare const ENGINE_BROKER_MCP_TUNNEL_MAX = 8;
80
+ /**
81
+ * Why the facade refused one relayed request, as a closed vocabulary:
82
+ * - `route`: a path or method the facade does not serve.
83
+ * - `expired`: the turn capability's TTL had passed.
84
+ * - `exhausted`: the turn capability's request budget was spent.
85
+ * - `unrouted`: a live capability whose turn has no registered mount.
86
+ * - `oversized`: a POST body past the facade's own request bound.
87
+ */
88
+ export declare const ENGINE_BROKER_MCP_REFUSAL_REASONS: readonly ["route", "expired", "exhausted", "unrouted", "oversized"];
89
+ export type EngineBrokerMcpRefusalReason = (typeof ENGINE_BROKER_MCP_REFUSAL_REASONS)[number];
90
+ /** How many requests of this turn the facade refused, by reason class. Every member is a measurement; the whole member is absent only where it was never measured. */
91
+ export type EngineBrokerMcpRefusalObservation = Readonly<Record<EngineBrokerMcpRefusalReason, number>>;
92
+ export type EngineBrokerOutstandingMcpCall = Readonly<{
93
+ name: string;
94
+ outstandingMs: number;
95
+ }>;
96
+ /** One GET SSE tunnel still open at observation: how long it has been open, and whether the mount ever pushed through it. */
97
+ export type EngineBrokerOpenMcpTunnel = Readonly<{
98
+ openMs: number;
99
+ delivered: boolean;
100
+ }>;
101
+ /**
102
+ * What the facade saw of one turn's standalone GET SSE tunnels: how many it
103
+ * relayed, how many ended, how many ever carried a byte from the mount, and
104
+ * the ones still open with the age of each.
105
+ */
106
+ export type EngineBrokerMcpTunnelObservation = Readonly<{
107
+ opened: number;
108
+ closed: number;
109
+ delivered: number;
110
+ open: readonly EngineBrokerOpenMcpTunnel[];
111
+ }>;
112
+ /**
113
+ * What the facade saw of one turn's tool calls: how many started, how many the
114
+ * facade answered, how many POST bodies it could not read, and the ones still
115
+ * unanswered with the time each has been outstanding.
116
+ */
117
+ export type EngineBrokerMcpCallObservation = Readonly<{
118
+ started: number;
119
+ answered: number;
120
+ undecoded: number;
121
+ outstanding: readonly EngineBrokerOutstandingMcpCall[];
122
+ tunnels?: EngineBrokerMcpTunnelObservation;
123
+ refusals?: EngineBrokerMcpRefusalObservation;
124
+ }>;
125
+ /** One relayed POST's calls. `answer` marks a complete relay; `close` ends it unanswered. Both are idempotent. */
126
+ export interface EngineBrokerMcpCallHandle {
127
+ answer(): void;
128
+ close(): void;
129
+ }
130
+ /** One relayed GET tunnel. `deliver` marks the first byte the mount pushed; `close` ends it. Both are idempotent. */
131
+ export interface EngineBrokerMcpTunnelHandle {
132
+ deliver(): void;
133
+ close(): void;
134
+ }
135
+ export declare class EngineBrokerMcpCallLog {
136
+ private readonly now;
137
+ private readonly turns;
138
+ constructor(now?: () => number);
139
+ /** A turn the facade registered. Re-opening an id resets it: a turn id is unique per turn. */
140
+ open(turnId: string): void;
141
+ close(turnId: string): void;
142
+ /** A POST body the facade is about to relay. Anything that is not a `tools/call` records nothing. */
143
+ begin(turnId: string, body: Uint8Array | undefined): EngineBrokerMcpCallHandle;
144
+ /**
145
+ * A GET SSE tunnel the facade is about to relay. Counted when it opens, not
146
+ * when it succeeds: a tunnel the mount refused still ends, so `opened` and
147
+ * `closed` stay a pair and an open one is exactly `opened - closed`.
148
+ */
149
+ openTunnel(turnId: string): EngineBrokerMcpTunnelHandle;
150
+ /**
151
+ * A request the facade refused before it could ever be relayed. A refusal it
152
+ * cannot attribute to a turn is never recorded against one, so an unknown
153
+ * turn is a no-op here exactly as every other operation is.
154
+ */
155
+ refuse(turnId: string, reason: EngineBrokerMcpRefusalReason): void;
156
+ /** A POST whose body the facade refused to read (over its own bound), which is a call it cannot name. */
157
+ undecodable(turnId: string): void;
158
+ observe(turnId: string): EngineBrokerMcpCallObservation | undefined;
159
+ }
160
+ //# sourceMappingURL=engineBrokerMcpCallLog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineBrokerMcpCallLog.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerMcpCallLog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iCAAiC,KAAK,CAAC;AACpD,eAAO,MAAM,8BAA8B,cAAc,CAAC;AAC1D,eAAO,MAAM,gCAAgC,gBAAgB,CAAC;AAC9D,mEAAmE;AACnE,eAAO,MAAM,2BAA2B,QAAsD,CAAC;AAG/F,qGAAqG;AACrG,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,qEAAsE,CAAC;AACrH,MAAM,MAAM,4BAA4B,GAAG,CAAC,OAAO,iCAAiC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9F,sKAAsK;AACtK,MAAM,MAAM,iCAAiC,GAAG,QAAQ,CAAC,MAAM,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvG,MAAM,MAAM,8BAA8B,GAAG,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAC/F,6HAA6H;AAC7H,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACzF;;;;GAIG;AACH,MAAM,MAAM,gCAAgC,GAAG,QAAQ,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,yBAAyB,EAAE,CAAA;CAAE,CAAC,CAAC;AAC3J;;;;GAIG;AACH,MAAM,MAAM,8BAA8B,GAAG,QAAQ,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,SAAS,8BAA8B,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,gCAAgC,CAAC;IAAC,QAAQ,CAAC,EAAE,iCAAiC,CAAA;CAAE,CAAC,CAAC;AAElQ,kHAAkH;AAClH,MAAM,WAAW,yBAAyB;IAAG,MAAM,IAAI,IAAI,CAAC;IAAC,KAAK,IAAI,IAAI,CAAA;CAAE;AAE5E,qHAAqH;AACrH,MAAM,WAAW,2BAA2B;IAAG,OAAO,IAAI,IAAI,CAAC;IAAC,KAAK,IAAI,IAAI,CAAA;CAAE;AAY/E,qBAAa,sBAAsB;IAErB,OAAO,CAAC,QAAQ,CAAC,GAAG;IADhC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA8B;gBACvB,GAAG,GAAE,MAAM,MAAiB;IAEzD,8FAA8F;IAC9F,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAC1B,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAE3B,qGAAqG;IACrG,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,yBAAyB;IA8B9E;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,2BAA2B;IAavD;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,4BAA4B,GAAG,IAAI;IAElE,yGAAyG;IACzG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAEjC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,8BAA8B,GAAG,SAAS;CAmBpE"}
@@ -0,0 +1,219 @@
1
+ /**
2
+ * The in-flight MCP tool calls of one brokered turn.
3
+ *
4
+ * Daimon writes a tool receipt only when a call *completes*, so a call that
5
+ * started and never returned is byte-identical, in every artifact, to a call
6
+ * that was never made. A live Grok turn stopped acting after its eighth
7
+ * provider response and was killed by the trial deadline seven minutes later
8
+ * with the proxy's per-request ledger reporting `open: 0` — every provider
9
+ * request closed — which leaves exactly one unlit path: a tool call the worker
10
+ * issued and the facade never answered.
11
+ *
12
+ * This is that light, and it follows the per-request ledger's rules rather
13
+ * than inventing its own:
14
+ *
15
+ * - **names and timings only.** The tool name off the JSON-RPC envelope and
16
+ * two clocks. Never arguments, never a result, never a session id, never a
17
+ * capability or bearer. A name that is not a plain short identifier is
18
+ * recorded as {@link ENGINE_BROKER_MCP_CALL_INVALID} rather than passed
19
+ * through, and the list is bounded at
20
+ * {@link ENGINE_BROKER_MCP_OUTSTANDING_MAX} with
21
+ * {@link ENGINE_BROKER_MCP_CALL_TRUNCATED} as its last entry.
22
+ * - **absence stays absence.** A turn the log never opened observes as
23
+ * `undefined`; a turn that made no call observes `started: 0`, which is not
24
+ * the same statement as an answered call. A POST whose body the facade could
25
+ * not read counts in `undecoded` and never as a call with a name, because a
26
+ * fabricated name is byte-identical to a measured one — and because "zero
27
+ * calls started" is exactly the reading this instrument exists to make
28
+ * trustworthy.
29
+ * - **it cannot fail a turn.** Every operation here is arithmetic over a map,
30
+ * the one parse is wrapped, and the facade treats a missing handle as a
31
+ * no-op.
32
+ *
33
+ * The same map carries the facade's *other* channel, and for the same reason.
34
+ * A `tools/call` is a POST that answers; the standalone `GET` SSE tunnel the
35
+ * Streamable HTTP transport opens once per session is the route a server
36
+ * notification or progress frame takes, and it stays open for the whole
37
+ * session by design. A worker parked reading that tunnel is, in every artifact
38
+ * the broker writes, indistinguishable from a worker doing nothing at all:
39
+ * every provider request closed, every tool call answered, and the turn idle
40
+ * until its deadline. {@link EngineBrokerMcpCallLog.openTunnel} records the
41
+ * lifecycle — how many the facade relayed, how many ended, and for the ones
42
+ * still open at seal time how long each has been open and whether the mount
43
+ * ever pushed a single byte through it. A tunnel held open having delivered
44
+ * nothing is a different fact from one actively carrying frames, and it is the
45
+ * difference that decides whether the tunnel is the blocker.
46
+ *
47
+ * Observing is all it does. The facade's behaviour is unchanged: nothing here
48
+ * closes, times out or refuses a tunnel, because an instrument that tore down
49
+ * the stream would destroy the evidence it exists to gather.
50
+ *
51
+ * "Answered" means the facade wrote a complete response back to the worker —
52
+ * the relay reached its own `end()`. A relay that was torn down (the worker
53
+ * died, the tunnel broke, the turn aborted) did *not* answer, so its calls stay
54
+ * outstanding with the elapsed time they had reached. That is the whole point:
55
+ * the turn's death must not retroactively mark the call it was blocked on as
56
+ * finished.
57
+ */
58
+ /**
59
+ * The same map carries the facade's *refusals*, for the sharpest form of the
60
+ * same problem. A refused request never reaches the relay at all, so a turn
61
+ * every one of whose requests was 403'd sealed as `answered == started,
62
+ * outstanding: []` — byte-identical to a healthy turn, which is precisely the
63
+ * reading this instrument exists to make trustworthy. The reason class is what
64
+ * makes it actionable: an exhausted per-turn capability budget — the facade's
65
+ * `ENGINE_BROKER_MCP_CAPABILITY_REQUESTS`, derived from the compiled turn
66
+ * bound times what a round may spend — is a different fault from a mount that
67
+ * was never registered, and both differ from a worker asking for a route the
68
+ * facade does not serve. Counts only, keyed by a closed vocabulary:
69
+ * never the token, the capability, the URL or the body. A refusal the facade
70
+ * cannot attribute to a turn — a bearer no live grant matches — is recorded
71
+ * nowhere, because attributing it to a turn would be inventing the fact.
72
+ */
73
+ export const ENGINE_BROKER_MCP_OUTSTANDING_MAX = 16;
74
+ export const ENGINE_BROKER_MCP_CALL_INVALID = "<invalid>";
75
+ export const ENGINE_BROKER_MCP_CALL_TRUNCATED = "<truncated>";
76
+ /** A plain short identifier, or one of the two sentinels above. */
77
+ export const ENGINE_BROKER_MCP_CALL_NAME = /^(?:<invalid>|<truncated>|[A-Za-z0-9_.-]{1,64})$/u;
78
+ const TOOL_NAME = /^[A-Za-z0-9_.-]{1,64}$/u;
79
+ /** Open GET tunnels reported: a session opens one, so more than a handful is already the anomaly. */
80
+ export const ENGINE_BROKER_MCP_TUNNEL_MAX = 8;
81
+ /**
82
+ * Why the facade refused one relayed request, as a closed vocabulary:
83
+ * - `route`: a path or method the facade does not serve.
84
+ * - `expired`: the turn capability's TTL had passed.
85
+ * - `exhausted`: the turn capability's request budget was spent.
86
+ * - `unrouted`: a live capability whose turn has no registered mount.
87
+ * - `oversized`: a POST body past the facade's own request bound.
88
+ */
89
+ export const ENGINE_BROKER_MCP_REFUSAL_REASONS = ["route", "expired", "exhausted", "unrouted", "oversized"];
90
+ const INERT = { answer: () => undefined, close: () => undefined };
91
+ const INERT_TUNNEL = { deliver: () => undefined, close: () => undefined };
92
+ const noRefusals = () => ({ route: 0, expired: 0, exhausted: 0, unrouted: 0, oversized: 0 });
93
+ export class EngineBrokerMcpCallLog {
94
+ now;
95
+ turns = new Map();
96
+ constructor(now = Date.now) {
97
+ this.now = now;
98
+ }
99
+ /** A turn the facade registered. Re-opening an id resets it: a turn id is unique per turn. */
100
+ open(turnId) { this.turns.set(turnId, { started: 0, answered: 0, undecoded: 0, live: new Set(), ended: [], tunnelsOpened: 0, tunnelsClosed: 0, tunnelsDelivered: 0, openTunnels: new Set(), refusals: noRefusals() }); }
101
+ close(turnId) { this.turns.delete(turnId); }
102
+ /** A POST body the facade is about to relay. Anything that is not a `tools/call` records nothing. */
103
+ begin(turnId, body) {
104
+ const log = this.turns.get(turnId);
105
+ if (log === undefined || body === undefined || body.byteLength === 0)
106
+ return INERT;
107
+ const names = toolCallNames(body);
108
+ if (names === undefined) {
109
+ log.undecoded += 1;
110
+ return INERT;
111
+ }
112
+ if (names.length === 0)
113
+ return INERT;
114
+ const startedAt = this.now();
115
+ const records = names.map((name) => ({ name, startedAt }));
116
+ log.started += records.length;
117
+ for (const record of records)
118
+ log.live.add(record);
119
+ let settled = false;
120
+ return {
121
+ answer: () => {
122
+ if (settled)
123
+ return;
124
+ settled = true;
125
+ log.answered += records.length;
126
+ for (const record of records)
127
+ log.live.delete(record);
128
+ },
129
+ close: () => {
130
+ if (settled)
131
+ return;
132
+ settled = true;
133
+ const endedAt = this.now();
134
+ for (const record of records) {
135
+ log.live.delete(record);
136
+ record.endedAt = endedAt;
137
+ // Retain only as many as can be reported; the earliest are the ones
138
+ // a hang is about, so a later flood cannot displace them.
139
+ if (log.ended.length < ENGINE_BROKER_MCP_OUTSTANDING_MAX)
140
+ log.ended.push(record);
141
+ }
142
+ }
143
+ };
144
+ }
145
+ /**
146
+ * A GET SSE tunnel the facade is about to relay. Counted when it opens, not
147
+ * when it succeeds: a tunnel the mount refused still ends, so `opened` and
148
+ * `closed` stay a pair and an open one is exactly `opened - closed`.
149
+ */
150
+ openTunnel(turnId) {
151
+ const log = this.turns.get(turnId);
152
+ if (log === undefined)
153
+ return INERT_TUNNEL;
154
+ const record = { openedAt: this.now(), delivered: false };
155
+ log.tunnelsOpened += 1;
156
+ log.openTunnels.add(record);
157
+ let ended = false;
158
+ return {
159
+ deliver: () => { if (record.delivered)
160
+ return; record.delivered = true; log.tunnelsDelivered += 1; },
161
+ close: () => { if (ended)
162
+ return; ended = true; log.tunnelsClosed += 1; log.openTunnels.delete(record); }
163
+ };
164
+ }
165
+ /**
166
+ * A request the facade refused before it could ever be relayed. A refusal it
167
+ * cannot attribute to a turn is never recorded against one, so an unknown
168
+ * turn is a no-op here exactly as every other operation is.
169
+ */
170
+ refuse(turnId, reason) { const log = this.turns.get(turnId); if (log !== undefined)
171
+ log.refusals[reason] += 1; }
172
+ /** A POST whose body the facade refused to read (over its own bound), which is a call it cannot name. */
173
+ undecodable(turnId) { const log = this.turns.get(turnId); if (log !== undefined)
174
+ log.undecoded += 1; }
175
+ observe(turnId) {
176
+ const log = this.turns.get(turnId);
177
+ if (log === undefined)
178
+ return undefined;
179
+ const at = this.now();
180
+ const pending = [...log.live, ...log.ended].sort((left, right) => left.startedAt - right.startedAt);
181
+ const outstanding = pending.map((record) => ({ name: record.name, outstandingMs: Math.max(0, (record.endedAt ?? at) - record.startedAt) }));
182
+ const open = [...log.openTunnels]
183
+ .sort((left, right) => left.openedAt - right.openedAt)
184
+ .slice(0, ENGINE_BROKER_MCP_TUNNEL_MAX)
185
+ .map((record) => ({ openMs: Math.max(0, at - record.openedAt), delivered: record.delivered }));
186
+ return {
187
+ started: log.started, answered: log.answered, undecoded: log.undecoded,
188
+ refusals: { ...log.refusals },
189
+ tunnels: { opened: log.tunnelsOpened, closed: log.tunnelsClosed, delivered: log.tunnelsDelivered, open },
190
+ outstanding: outstanding.length > ENGINE_BROKER_MCP_OUTSTANDING_MAX
191
+ ? [...outstanding.slice(0, ENGINE_BROKER_MCP_OUTSTANDING_MAX - 1), { name: ENGINE_BROKER_MCP_CALL_TRUNCATED, outstandingMs: 0 }]
192
+ : outstanding
193
+ };
194
+ }
195
+ }
196
+ /**
197
+ * The tool names one JSON-RPC POST asks for: `undefined` when the body did not
198
+ * decode at all (which is a fact of its own, not zero calls), `[]` when it
199
+ * decoded and asked for no tool. A batch names each of its calls.
200
+ */
201
+ function toolCallNames(body) {
202
+ let parsed;
203
+ try {
204
+ parsed = JSON.parse(Buffer.from(body.buffer, body.byteOffset, body.byteLength).toString("utf8"));
205
+ }
206
+ catch {
207
+ return undefined;
208
+ }
209
+ const entries = Array.isArray(parsed) ? parsed : [parsed];
210
+ const names = [];
211
+ for (const entry of entries) {
212
+ if (!isRecord(entry) || entry.method !== "tools/call")
213
+ continue;
214
+ const name = isRecord(entry.params) ? entry.params.name : undefined;
215
+ names.push(typeof name === "string" && TOOL_NAME.test(name) ? name : ENGINE_BROKER_MCP_CALL_INVALID);
216
+ }
217
+ return names;
218
+ }
219
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -0,0 +1,56 @@
1
+ import { type ServerResponse } from "node:http";
2
+ import { type EngineBrokerMcpCallObservation } from "./engineBrokerMcpCallLog.js";
3
+ export declare const ENGINE_BROKER_MCP_FACADE_PORT = 43124;
4
+ /** Requests one worker round may legitimately make: its `search_tool`, its `use_tool`, and one spare for a retry or a second discovery. */
5
+ export declare const ENGINE_BROKER_MCP_ROUND_REQUESTS = 3;
6
+ /** The session's fixed cost, once per turn: `initialize`, `notifications/initialized`, `tools/list`, the standalone GET tunnel, the closing DELETE. */
7
+ export declare const ENGINE_BROKER_MCP_SESSION_REQUESTS = 5;
8
+ /**
9
+ * Requests one turn capability may spend, across all three methods — *derived*
10
+ * from the compiled turn bound rather than chosen.
11
+ *
12
+ * It was 128, and a legitimate 48-round wake needs ~101 of them: a worker's
13
+ * round is a `search_tool` and a `use_tool`, so the first round that also
14
+ * retries, or looks something up twice, eats the margin. A bound that can be
15
+ * predicted to bite mid-turn is not a bound, it is a 403 storm waiting for a
16
+ * real wake — and a number raised until it feels comfortable is not one
17
+ * either, because the budget exists to cap a *compromised* worker.
18
+ *
19
+ * So the two numbers that must agree are kept in one place: the launcher's
20
+ * `--max-turns` backstop ({@link GROK_WORKER_MAX_TURNS}) times what a round
21
+ * may legitimately spend, plus the session's fixed cost. Raising the turn
22
+ * bound raises this with it, and a compromised worker still gets exactly three
23
+ * MCP calls per round it was compiled to take and not one more. The arithmetic
24
+ * is spelled out rather than folded into a literal so it can be audited: the
25
+ * two multiplicands above each say what they are.
26
+ */
27
+ export declare const ENGINE_BROKER_MCP_CAPABILITY_REQUESTS: number;
28
+ export declare const ENGINE_BROKER_MCP_CAPABILITY_TTL_MS: number;
29
+ export declare function startEngineBrokerMcpFacade(): Promise<{
30
+ register(agentId: string, turnId: string, endpoint: string): string;
31
+ revoke(turnId: string): void;
32
+ /**
33
+ * What the facade saw of this turn's tool calls, GET tunnels and refusals,
34
+ * or `undefined` for a turn
35
+ * it never registered. Read on the failure path, before `revoke`.
36
+ */
37
+ observe: (turnId: string) => EngineBrokerMcpCallObservation | undefined;
38
+ close: () => Promise<void>;
39
+ }>;
40
+ /**
41
+ * Waits for a backpressured tunnel to drain, or for the tunnel to end —
42
+ * whichever happens first, but always one of them.
43
+ *
44
+ * A bare `once("drain")` never settles for a client that hung up mid-write:
45
+ * `drain` cannot fire on a socket nobody is reading, and neither the
46
+ * response's own `close` nor the turn's abort woke that await. The GET SSE
47
+ * tunnel stays open for a whole session, so the handler — and the upstream
48
+ * call it was relaying — leaked for the life of the broker process, with no
49
+ * refusal, no status and no line anywhere to read. Every outcome settles this
50
+ * now, and every outcome but an actual drain *rejects*, so the caller tears
51
+ * the tunnel down instead of writing into a socket that is gone.
52
+ *
53
+ * Exported for its own test: a hang is only observable from inside.
54
+ */
55
+ export declare function awaitMcpTunnelDrain(response: ServerResponse, signal: AbortSignal): Promise<void>;
56
+ //# sourceMappingURL=engineBrokerMcpFacade.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineBrokerMcpFacade.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerMcpFacade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAIpF,OAAO,EAA0B,KAAK,8BAA8B,EAAuE,MAAM,6BAA6B,CAAC;AA4C/K,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAEpD,2IAA2I;AAC3I,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAClD,uJAAuJ;AACvJ,eAAO,MAAM,kCAAkC,IAAI,CAAC;AACpD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,qCAAqC,QAAgG,CAAC;AACnJ,eAAO,MAAM,mCAAmC,QAAc,CAAC;AAI/D,wBAAsB,0BAA0B;sBA0G1B,MAAM,UAAU,MAAM,YAAY,MAAM,GAAG,MAAM;mBAQpD,MAAM,GAAG,IAAI;IAM5B;;;;OAIG;sBACe,MAAM,KAAG,8BAA8B,GAAG,SAAS;iBACpD,OAAO,CAAC,IAAI,CAAC;GAUjC;AAoED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAehG"}