@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,145 @@
1
+ import { Ajv2020 } from "ajv/dist/2020.js";
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError } from "@modelcontextprotocol/sdk/types.js";
4
+ export class McpToolTurnLimitError extends Error {
5
+ constructor(maxToolTurns) {
6
+ super(`McpToolTurnLimitError: maximum ${maxToolTurns} calls per wake`);
7
+ this.name = "McpToolTurnLimitError";
8
+ }
9
+ }
10
+ export class McpWakeDeadlineError extends Error {
11
+ constructor() {
12
+ super("McpWakeDeadlineError: wake deadline exceeded");
13
+ this.name = "McpWakeDeadlineError";
14
+ }
15
+ }
16
+ /**
17
+ * A non-standard request AGY issues during its MCP handshake.
18
+ *
19
+ * Captured live from `agy --print … --output-format stream-json`, the client
20
+ * sends `initialize`, `notifications/initialized`, **`server/discover`**,
21
+ * `tools/list`, `tools/call`. `server/discover` is not in the MCP
22
+ * specification, and the throwaway probe that proved AGY's headless tool
23
+ * calling answered it with `{}`. Codex and Grok never send it.
24
+ *
25
+ * This server answers it the same way that working probe did, rather than the
26
+ * SDK default of `MethodNotFound`, because a refusal here is the one observable
27
+ * difference between this server and the one AGY is known to work against, and
28
+ * the cost of being wrong is that every AGY agent silently loses every tool.
29
+ * The allowance is exactly this one method: any other unknown method still gets
30
+ * `MethodNotFound`, so a genuine protocol mistake is never hidden.
31
+ */
32
+ export const AGY_SERVER_DISCOVER_METHOD = "server/discover";
33
+ const jsonSchema = (parameters) => {
34
+ if (parameters === null || typeof parameters !== "object" || Array.isArray(parameters)) {
35
+ throw new TypeError("Pi tool parameters must be a JSON schema object");
36
+ }
37
+ return Object.fromEntries(Object.entries(parameters));
38
+ };
39
+ const toolResult = (result) => ({
40
+ content: result.content,
41
+ ...(result.details !== undefined && typeof result.details === "object" && result.details !== null
42
+ ? { structuredContent: Object.fromEntries(Object.entries(result.details)) }
43
+ : {})
44
+ });
45
+ /** Bound on the rendered Ajv violations, so a pathological schema cannot flood a turn. */
46
+ const MAX_SCHEMA_VIOLATION_BYTES = 2_048;
47
+ /**
48
+ * Why the arguments were rejected, in the schema's own words.
49
+ *
50
+ * A bare `Invalid arguments for tool X` tells an agent that its call was wrong
51
+ * and nothing about how, which leaves trial and error as the only way to learn
52
+ * a tool's argument shape. Ajv already knows which instance path failed and
53
+ * which keyword it failed on; saying so turns a guessing loop into one
54
+ * correction.
55
+ */
56
+ const schemaViolations = (validator) => {
57
+ const rendered = (validator.errors ?? [])
58
+ .map((issue) => `${issue.instancePath === "" ? "(root)" : issue.instancePath} ${issue.message ?? "is invalid"}`.trim())
59
+ .join("; ");
60
+ if (rendered.length === 0)
61
+ return "the arguments do not match the tool's declared input schema";
62
+ return rendered.length > MAX_SCHEMA_VIOLATION_BYTES ? `${rendered.slice(0, MAX_SCHEMA_VIOLATION_BYTES)}…` : rendered;
63
+ };
64
+ const toolError = (error) => ({
65
+ content: [{ type: "text", text: error instanceof Error ? `${error.name}: ${error.message}` : String(error) }],
66
+ isError: true
67
+ });
68
+ // Pi's ExtensionContext has no meaning outside a Pi session. Mounted tools
69
+ // must not read it; this named value documents the explicit absence.
70
+ // The MCP mount deliberately has no Pi session context; `never` preserves typed positional checks.
71
+ const NO_PI_EXTENSION_CONTEXT = undefined;
72
+ const validateOptions = (options) => {
73
+ if (options.maxToolTurns !== undefined && (!Number.isSafeInteger(options.maxToolTurns) || options.maxToolTurns < 1)) {
74
+ throw new TypeError("maxToolTurns must be a positive safe integer");
75
+ }
76
+ if (options.wakeDeadline !== undefined && !Number.isFinite(options.wakeDeadline)) {
77
+ throw new TypeError("wakeDeadline must be a finite epoch-millisecond deadline");
78
+ }
79
+ };
80
+ export const createPiToolMcpServer = (tools, options) => {
81
+ validateOptions(options);
82
+ const server = new Server({ name: "daimon-pi-tools", version: "0.1.2" });
83
+ server.fallbackRequestHandler = async (request) => {
84
+ if (request.method !== AGY_SERVER_DISCOVER_METHOD) {
85
+ throw new McpError(ErrorCode.MethodNotFound, `Method not found: ${request.method}`);
86
+ }
87
+ return {};
88
+ };
89
+ const validators = new Map(tools.map((tool) => {
90
+ const schema = jsonSchema(tool.parameters);
91
+ return [tool.name, new Ajv2020({ strict: false }).compile(schema)];
92
+ }));
93
+ let toolTurns = 0;
94
+ server.registerCapabilities({ tools: { listChanged: true } });
95
+ server.setRequestHandler(ListToolsRequestSchema, () => ({
96
+ tools: tools.map((tool) => ({
97
+ name: tool.name,
98
+ title: tool.label,
99
+ description: tool.description,
100
+ inputSchema: jsonSchema(tool.parameters)
101
+ }))
102
+ }));
103
+ server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
104
+ try {
105
+ if (options.wakeDeadline !== undefined && Date.now() >= options.wakeDeadline)
106
+ throw new McpWakeDeadlineError();
107
+ if (options.maxToolTurns !== undefined && toolTurns >= options.maxToolTurns)
108
+ throw new McpToolTurnLimitError(options.maxToolTurns);
109
+ const tool = tools.find((candidate) => candidate.name === request.params.name);
110
+ const validator = validators.get(request.params.name);
111
+ if (tool === undefined || validator === undefined) {
112
+ throw new McpError(ErrorCode.InvalidParams, `Unknown tool: ${request.params.name}`);
113
+ }
114
+ const args = request.params.arguments ?? {};
115
+ if (!validator(args)) {
116
+ throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for tool ${tool.name}: ${schemaViolations(validator)}`);
117
+ }
118
+ toolTurns += 1;
119
+ // Ajv validated this value against this tool's own schema immediately above.
120
+ const validatedArgs = args;
121
+ const deadlineController = options.wakeDeadline === undefined ? undefined : new AbortController();
122
+ const remainingMs = options.wakeDeadline === undefined ? undefined : Math.max(0, options.wakeDeadline - Date.now());
123
+ const deadlineTimer = deadlineController === undefined ? undefined : setTimeout(() => deadlineController.abort(), remainingMs);
124
+ const signal = deadlineController === undefined ? extra.signal
125
+ : extra.signal === undefined ? deadlineController.signal : AbortSignal.any([extra.signal, deadlineController.signal]);
126
+ const deadline = deadlineController === undefined ? undefined : new Promise((_resolve, reject) => {
127
+ deadlineController.signal.addEventListener("abort", () => reject(new McpWakeDeadlineError()), { once: true });
128
+ });
129
+ let result;
130
+ try {
131
+ const execution = tool.execute(`mcp-tool-turn-${toolTurns}`, validatedArgs, signal, undefined, NO_PI_EXTENSION_CONTEXT);
132
+ result = deadline === undefined ? await execution : await Promise.race([execution, deadline]);
133
+ }
134
+ finally {
135
+ if (deadlineTimer !== undefined)
136
+ clearTimeout(deadlineTimer);
137
+ }
138
+ return toolResult(result);
139
+ }
140
+ catch (error) {
141
+ return toolError(error);
142
+ }
143
+ });
144
+ return server;
145
+ };
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Daimon's own copy of the `noopolis.causal-event.v1` wire envelope. Field-
3
+ * for-field the canonical shape in `specs/causal-event.v1.schema.json` and
4
+ * `specs/CAUSAL.md` (root repo) — daimon is an independent repo and does not
5
+ * import that schema, it only conforms to it. The wire JSON emitted by
6
+ * `appendCausalEvent` is the actual contract; this type is local sugar over
7
+ * it.
8
+ */
9
+ export declare const CAUSAL_EVENT_VERSION: "noopolis.causal-event.v1";
10
+ export type CausalEventSystem = "simfile" | "moltnet" | "mneme" | "daimon";
11
+ export interface CausalEventEmitter {
12
+ system: CausalEventSystem;
13
+ stream_id: string;
14
+ seq: number;
15
+ }
16
+ export interface CausalEvent<TPayload = Record<string, unknown>> {
17
+ cause_event_ids: string[];
18
+ emitter: CausalEventEmitter;
19
+ event_id: string;
20
+ payload: TPayload;
21
+ principal_id: string;
22
+ recorded_at: string;
23
+ run_id: string;
24
+ type: string;
25
+ version: typeof CAUSAL_EVENT_VERSION;
26
+ }
27
+ /** Payload for `turn.input.submitted`, stamped just before a Pi session prompt call. */
28
+ export interface TurnInputSubmittedPayload extends Record<string, unknown> {
29
+ input_content_sha256: string;
30
+ input_message_ids: string[];
31
+ prompt_sha256: string;
32
+ turn_id: string;
33
+ }
34
+ /** Payload for `turn.output.completed`, stamped once a Pi turn finishes successfully. */
35
+ export interface TurnOutputCompletedPayload extends Record<string, unknown> {
36
+ output_sha256: string;
37
+ turn_id: string;
38
+ }
39
+ export declare const TURN_INPUT_SUBMITTED_TYPE: "turn.input.submitted";
40
+ export declare const TURN_OUTPUT_COMPLETED_TYPE: "turn.output.completed";
41
+ /** Name of the environment variable every Noopolis authority reads `run_id` from. Never model output. */
42
+ export declare const NOOPOLIS_RUN_ID_ENV = "NOOPOLIS_RUN_ID";
43
+ /**
44
+ * Resolves `run_id` from the `NOOPOLIS_RUN_ID` environment variable, per
45
+ * `specs/CAUSAL.md`. Never derived from a WakeEvent, model output, or any
46
+ * other in-turn data. A causal event cannot be emitted without a real run id.
47
+ */
48
+ export declare const resolveRunId: (env?: NodeJS.ProcessEnv) => string;
49
+ export declare const sha256Hex: (value: string) => string;
50
+ /** Deterministic, non-model-derived event id for a turn's `turn.input.submitted` record. */
51
+ export declare const turnInputSubmittedEventId: (turnId: string) => string;
52
+ /** Deterministic, non-model-derived event id for a turn's `turn.output.completed` record. */
53
+ export declare const turnOutputCompletedEventId: (turnId: string) => string;
54
+ /**
55
+ * The `cause_event_ids` an outbound Moltnet reply for `turnId` should carry.
56
+ * Pure and deterministic from `turn_id` alone — the harness owns this value,
57
+ * never the model. Daimon does not construct Moltnet `SendMessageRequest`
58
+ * values itself (see repo AGENTS.md: Moltnet wiring belongs to the caller,
59
+ * not this package), so this helper is what a caller sending the reply on
60
+ * Daimon's behalf attaches to that request's `cause_event_ids`.
61
+ */
62
+ export declare const replyCauseEventIds: (turnId: string) => string[];
63
+ /**
64
+ * Allocates the next contiguous seq number for `(run_id, stream_id)`,
65
+ * persisted under `runtimeHome/telemetry/causal.seq.json`. Allocation is
66
+ * serialized in-process and mutually excluded across processes by a lock
67
+ * file; the counter is written atomically and fsynced.
68
+ */
69
+ export declare const nextCausalSeq: (input: {
70
+ runId: string;
71
+ runtimeHomePath: string;
72
+ streamId: string;
73
+ }) => Promise<number>;
74
+ /** Appends one CausalEvent record as a line of `runtimeHome/telemetry/causal.jsonl`. */
75
+ export declare const appendCausalEvent: (runtimeHomePath: string, event: CausalEvent) => Promise<void>;
76
+ export interface EmitCausalEventInput<TPayload extends Record<string, unknown>> {
77
+ agentId: string;
78
+ causeEventIds: string[];
79
+ eventId: string;
80
+ payload: TPayload;
81
+ principalId: string;
82
+ runId: string;
83
+ runtimeHomePath: string;
84
+ type: string;
85
+ }
86
+ /**
87
+ * Stamps and appends one causal event for this agent's stream
88
+ * (`agent:<agentId>`). `run_id` and `principal_id` are always caller-
89
+ * supplied values (never read from `payload` or model output) — see
90
+ * `piHarness.ts`, which is the only caller and always passes the resolved
91
+ * `NOOPOLIS_RUN_ID` and the authenticated agent identity.
92
+ */
93
+ export declare const emitCausalEvent: <TPayload extends Record<string, unknown>>(input: EmitCausalEventInput<TPayload>) => Promise<CausalEvent<TPayload>>;
94
+ export interface EmitTurnInputSubmittedInput {
95
+ agentId: string;
96
+ causeEventIds: string[];
97
+ inputContentSha256: string;
98
+ inputMessageIds: string[];
99
+ principalId: string;
100
+ promptSha256: string;
101
+ runId: string;
102
+ runtimeHomePath: string;
103
+ turnId: string;
104
+ }
105
+ /** Stamps `turn.input.submitted` for one Pi turn, right before the engine prompt call. */
106
+ export declare const emitTurnInputSubmitted: (input: EmitTurnInputSubmittedInput) => Promise<CausalEvent<TurnInputSubmittedPayload>>;
107
+ export interface EmitTurnOutputCompletedInput {
108
+ agentId: string;
109
+ causeEventIds: string[];
110
+ outputSha256: string;
111
+ principalId: string;
112
+ runId: string;
113
+ runtimeHomePath: string;
114
+ turnId: string;
115
+ }
116
+ /** Stamps `turn.output.completed` once a Pi turn finishes successfully. */
117
+ export declare const emitTurnOutputCompleted: (input: EmitTurnOutputCompletedInput) => Promise<CausalEvent<TurnOutputCompletedPayload>>;
118
+ //# sourceMappingURL=causalEvents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"causalEvents.d.ts","sourceRoot":"","sources":["../../src/observability/causalEvents.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,223 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { constants } from "node:fs";
3
+ import { appendFile, open, readFile, rename, stat, unlink } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { ensureRuntimeHomeDirectory } from "../runtime/runtimeHomeLayout.js";
6
+ /**
7
+ * Daimon's own copy of the `noopolis.causal-event.v1` wire envelope. Field-
8
+ * for-field the canonical shape in `specs/causal-event.v1.schema.json` and
9
+ * `specs/CAUSAL.md` (root repo) — daimon is an independent repo and does not
10
+ * import that schema, it only conforms to it. The wire JSON emitted by
11
+ * `appendCausalEvent` is the actual contract; this type is local sugar over
12
+ * it.
13
+ */
14
+ export const CAUSAL_EVENT_VERSION = "noopolis.causal-event.v1";
15
+ export const TURN_INPUT_SUBMITTED_TYPE = "turn.input.submitted";
16
+ export const TURN_OUTPUT_COMPLETED_TYPE = "turn.output.completed";
17
+ /** Name of the environment variable every Noopolis authority reads `run_id` from. Never model output. */
18
+ export const NOOPOLIS_RUN_ID_ENV = "NOOPOLIS_RUN_ID";
19
+ /**
20
+ * Resolves `run_id` from the `NOOPOLIS_RUN_ID` environment variable, per
21
+ * `specs/CAUSAL.md`. Never derived from a WakeEvent, model output, or any
22
+ * other in-turn data. A causal event cannot be emitted without a real run id.
23
+ */
24
+ export const resolveRunId = (env = process.env) => {
25
+ const value = env[NOOPOLIS_RUN_ID_ENV];
26
+ if (typeof value !== "string" || value.trim().length === 0) {
27
+ throw new Error(`${NOOPOLIS_RUN_ID_ENV} must be set to a non-blank value`);
28
+ }
29
+ return value.trim();
30
+ };
31
+ export const sha256Hex = (value) => createHash("sha256").update(value, "utf8").digest("hex");
32
+ /** Deterministic, non-model-derived event id for a turn's `turn.input.submitted` record. */
33
+ export const turnInputSubmittedEventId = (turnId) => `daimon:${turnId}:turn.input.submitted`;
34
+ /** Deterministic, non-model-derived event id for a turn's `turn.output.completed` record. */
35
+ export const turnOutputCompletedEventId = (turnId) => `daimon:${turnId}:turn.output.completed`;
36
+ /**
37
+ * The `cause_event_ids` an outbound Moltnet reply for `turnId` should carry.
38
+ * Pure and deterministic from `turn_id` alone — the harness owns this value,
39
+ * never the model. Daimon does not construct Moltnet `SendMessageRequest`
40
+ * values itself (see repo AGENTS.md: Moltnet wiring belongs to the caller,
41
+ * not this package), so this helper is what a caller sending the reply on
42
+ * Daimon's behalf attaches to that request's `cause_event_ids`.
43
+ */
44
+ export const replyCauseEventIds = (turnId) => [turnOutputCompletedEventId(turnId)];
45
+ const telemetryDir = (runtimeHomePath) => path.join(runtimeHomePath, "telemetry");
46
+ const seqFilePath = (runtimeHomePath) => path.join(telemetryDir(runtimeHomePath), "causal.seq.json");
47
+ const jsonlFilePath = (runtimeHomePath) => path.join(telemetryDir(runtimeHomePath), "causal.jsonl");
48
+ const STALE_LOCK_MS = 30_000;
49
+ const seqAllocationQueues = new Map();
50
+ const readSeqStore = async (runtimeHomePath) => {
51
+ try {
52
+ const raw = await readFile(seqFilePath(runtimeHomePath), "utf8");
53
+ return JSON.parse(raw);
54
+ }
55
+ catch (error) {
56
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
57
+ return {};
58
+ }
59
+ throw error;
60
+ }
61
+ };
62
+ const writeSeqStore = async (runtimeHomePath, store) => {
63
+ const directory = await ensureRuntimeHomeDirectory(runtimeHomePath, "telemetry");
64
+ const file = seqFilePath(runtimeHomePath);
65
+ const temporary = `${file}.${randomUUID()}.tmp`;
66
+ const handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY, 0o600);
67
+ try {
68
+ await handle.writeFile(`${JSON.stringify(store, null, 2)}\n`, "utf8");
69
+ await handle.sync();
70
+ }
71
+ finally {
72
+ await handle.close();
73
+ }
74
+ try {
75
+ await rename(temporary, file);
76
+ await syncDirectory(directory);
77
+ }
78
+ finally {
79
+ await unlink(temporary).catch((error) => {
80
+ if (error.code !== "ENOENT")
81
+ throw error;
82
+ });
83
+ }
84
+ };
85
+ const syncDirectory = async (directory) => {
86
+ const handle = await open(directory, constants.O_RDONLY);
87
+ try {
88
+ await handle.sync();
89
+ }
90
+ finally {
91
+ await handle.close();
92
+ }
93
+ };
94
+ const acquireSeqLock = async (lockPath) => {
95
+ const startedAt = Date.now();
96
+ let backoffMs = 2;
97
+ while (Date.now() - startedAt < 5_000) {
98
+ try {
99
+ const handle = await open(lockPath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY, 0o600);
100
+ await handle.close();
101
+ return;
102
+ }
103
+ catch (error) {
104
+ if (!(error && typeof error === "object" && "code" in error && error.code === "EEXIST"))
105
+ throw error;
106
+ }
107
+ try {
108
+ const observed = await stat(lockPath);
109
+ if (Date.now() - observed.mtimeMs > STALE_LOCK_MS) {
110
+ const confirmed = await stat(lockPath);
111
+ if (confirmed.mtimeMs === observed.mtimeMs) {
112
+ await unlink(lockPath).catch((error) => {
113
+ if (error.code !== "ENOENT")
114
+ throw error;
115
+ });
116
+ continue;
117
+ }
118
+ }
119
+ }
120
+ catch (error) {
121
+ if (!(error && typeof error === "object" && "code" in error && error.code === "ENOENT"))
122
+ throw error;
123
+ continue;
124
+ }
125
+ await new Promise((resolve) => setTimeout(resolve, backoffMs));
126
+ backoffMs = Math.min(backoffMs * 2, 25);
127
+ }
128
+ throw new Error(`Timed out acquiring causal sequence lock: ${lockPath}`);
129
+ };
130
+ /**
131
+ * Allocates the next contiguous seq number for `(run_id, stream_id)`,
132
+ * persisted under `runtimeHome/telemetry/causal.seq.json`. Allocation is
133
+ * serialized in-process and mutually excluded across processes by a lock
134
+ * file; the counter is written atomically and fsynced.
135
+ */
136
+ export const nextCausalSeq = async (input) => {
137
+ const lockPath = path.resolve(telemetryDir(input.runtimeHomePath), "causal.seq.lock");
138
+ const previous = seqAllocationQueues.get(lockPath) ?? Promise.resolve();
139
+ const allocation = previous.catch(() => undefined).then(async () => {
140
+ await ensureRuntimeHomeDirectory(input.runtimeHomePath, "telemetry");
141
+ await acquireSeqLock(lockPath);
142
+ try {
143
+ const store = await readSeqStore(input.runtimeHomePath);
144
+ const forRun = store[input.runId] ?? {};
145
+ const next = (forRun[input.streamId] ?? 0) + 1;
146
+ forRun[input.streamId] = next;
147
+ store[input.runId] = forRun;
148
+ await writeSeqStore(input.runtimeHomePath, store);
149
+ return next;
150
+ }
151
+ finally {
152
+ await unlink(lockPath).catch((error) => {
153
+ if (error.code !== "ENOENT")
154
+ throw error;
155
+ });
156
+ }
157
+ });
158
+ seqAllocationQueues.set(lockPath, allocation);
159
+ void allocation.finally(() => {
160
+ if (seqAllocationQueues.get(lockPath) === allocation)
161
+ seqAllocationQueues.delete(lockPath);
162
+ }).catch(() => undefined);
163
+ return allocation;
164
+ };
165
+ /** Appends one CausalEvent record as a line of `runtimeHome/telemetry/causal.jsonl`. */
166
+ export const appendCausalEvent = async (runtimeHomePath, event) => {
167
+ await ensureRuntimeHomeDirectory(runtimeHomePath, "telemetry");
168
+ await appendFile(jsonlFilePath(runtimeHomePath), `${JSON.stringify(event)}\n`, "utf8");
169
+ };
170
+ /**
171
+ * Stamps and appends one causal event for this agent's stream
172
+ * (`agent:<agentId>`). `run_id` and `principal_id` are always caller-
173
+ * supplied values (never read from `payload` or model output) — see
174
+ * `piHarness.ts`, which is the only caller and always passes the resolved
175
+ * `NOOPOLIS_RUN_ID` and the authenticated agent identity.
176
+ */
177
+ export const emitCausalEvent = async (input) => {
178
+ const streamId = `agent:${input.agentId}`;
179
+ const seq = await nextCausalSeq({ runId: input.runId, runtimeHomePath: input.runtimeHomePath, streamId });
180
+ const event = {
181
+ cause_event_ids: [...input.causeEventIds],
182
+ emitter: { system: "daimon", stream_id: streamId, seq },
183
+ event_id: input.eventId,
184
+ payload: input.payload,
185
+ principal_id: input.principalId,
186
+ recorded_at: new Date().toISOString(),
187
+ run_id: input.runId,
188
+ type: input.type,
189
+ version: CAUSAL_EVENT_VERSION
190
+ };
191
+ await appendCausalEvent(input.runtimeHomePath, event);
192
+ return event;
193
+ };
194
+ /** Stamps `turn.input.submitted` for one Pi turn, right before the engine prompt call. */
195
+ export const emitTurnInputSubmitted = (input) => emitCausalEvent({
196
+ agentId: input.agentId,
197
+ causeEventIds: input.causeEventIds,
198
+ eventId: turnInputSubmittedEventId(input.turnId),
199
+ payload: {
200
+ input_content_sha256: input.inputContentSha256,
201
+ input_message_ids: [...input.inputMessageIds],
202
+ prompt_sha256: input.promptSha256,
203
+ turn_id: input.turnId
204
+ },
205
+ principalId: input.principalId,
206
+ runId: input.runId,
207
+ runtimeHomePath: input.runtimeHomePath,
208
+ type: TURN_INPUT_SUBMITTED_TYPE
209
+ });
210
+ /** Stamps `turn.output.completed` once a Pi turn finishes successfully. */
211
+ export const emitTurnOutputCompleted = (input) => emitCausalEvent({
212
+ agentId: input.agentId,
213
+ causeEventIds: input.causeEventIds,
214
+ eventId: turnOutputCompletedEventId(input.turnId),
215
+ payload: {
216
+ output_sha256: input.outputSha256,
217
+ turn_id: input.turnId
218
+ },
219
+ principalId: input.principalId,
220
+ runId: input.runId,
221
+ runtimeHomePath: input.runtimeHomePath,
222
+ type: TURN_OUTPUT_COMPLETED_TYPE
223
+ });
@@ -0,0 +1,117 @@
1
+ import { type CausalEvent } from "./causalEvents.js";
2
+ /**
3
+ * Control-wake causal emitters for root's two wake-acceptance surfaces
4
+ * (`src/runtime/pi/appControlSource.ts`, root repo, out of scope here):
5
+ * the operator-only control endpoint and the Moltnet loopback delivery
6
+ * endpoint (`/agents/:slug/wake`). Both stamp `control.wake.accepted` —
7
+ * enforcement point #3 in `specs/CAUSAL.md` §"Enforcement points" — but with
8
+ * different `principal_id` authorities, per the B62 fix (Option B): the
9
+ * operator endpoint stamps `operator:<name>` (`emitControlWakeAccepted`),
10
+ * the delivery endpoint stamps the fixed `system:moltnet` authority
11
+ * (`emitDeliveryWakeAccepted`), never a caller-supplied `from`/agent field.
12
+ * `control.wake.denied` (`emitControlWakeDenied`) stays operator-only: the
13
+ * delivery endpoint has no bearer-token deny path to stamp. Root's generated
14
+ * app calls these directly; this file has no knowledge of HTTP, tokens, or
15
+ * the request shape, only the causal envelope contract.
16
+ */
17
+ export declare const CONTROL_WAKE_ACCEPTED_TYPE: "control.wake.accepted";
18
+ export declare const CONTROL_WAKE_DENIED_TYPE: "control.wake.denied";
19
+ /** Payload for `control.wake.accepted`. */
20
+ export interface ControlWakeAcceptedPayload extends Record<string, unknown> {
21
+ target_agent_id: string;
22
+ wake_kind: string;
23
+ }
24
+ /** Payload for `control.wake.denied`. */
25
+ export interface ControlWakeDeniedPayload extends Record<string, unknown> {
26
+ reason: string;
27
+ target_agent_id: string;
28
+ }
29
+ /**
30
+ * Payload for a Moltnet-delivered `control.wake.accepted` (same event type
31
+ * as the operator path — it is still an accepted wake; `principal_id` is
32
+ * what distinguishes authority). Adds `delivered_by` so downstream readers
33
+ * can tell a delivery-stamped event from an operator-stamped one without
34
+ * inspecting `principal_id`.
35
+ */
36
+ export interface DeliveryWakeAcceptedPayload extends ControlWakeAcceptedPayload {
37
+ delivered_by: "moltnet";
38
+ }
39
+ /**
40
+ * Principal grammar per `specs/CAUSAL.md` §3 (`^(agent|operator|system):.+`):
41
+ * an authenticated operator identity, e.g. `operator:control`. Callers must
42
+ * pass the identity behind the verified bearer token, never a value read
43
+ * from the request body or model output.
44
+ */
45
+ export declare const operatorPrincipalId: (operatorName: string) => string;
46
+ /**
47
+ * Fixed principal for wakes accepted through the Moltnet loopback delivery
48
+ * endpoint (`/agents/:slug/wake`): the delivering authority itself, never an
49
+ * identity derived from a caller-supplied `from`/agent field on the request.
50
+ */
51
+ export declare const DELIVERY_PRINCIPAL_ID: "system:moltnet";
52
+ /** Deterministic, non-model-derived event id for a control wake acceptance. */
53
+ export declare const controlWakeAcceptedEventId: (requestId: string) => string;
54
+ /** Deterministic, non-model-derived event id for a control wake denial. */
55
+ export declare const controlWakeDeniedEventId: (requestId: string) => string;
56
+ /**
57
+ * Deterministic, non-model-derived event id for a Moltnet-delivered wake
58
+ * acceptance. Distinct from `controlWakeAcceptedEventId` (own `.delivery.`
59
+ * segment) so the two paths never collide even if a future caller reused a
60
+ * `requestId` across both endpoints for the same target.
61
+ */
62
+ export declare const deliveryWakeAcceptedEventId: (requestId: string) => string;
63
+ export interface EmitControlWakeAcceptedInput {
64
+ causeEventIds?: string[];
65
+ operatorName: string;
66
+ requestId: string;
67
+ runId?: string;
68
+ runtimeHomePath: string;
69
+ targetAgentId: string;
70
+ wakeKind: string;
71
+ }
72
+ /**
73
+ * Stamps `control.wake.accepted` once root's operator-control endpoint has
74
+ * verified the bearer token and is about to wake `targetAgentId`.
75
+ * `principal_id` is always `operator:<operatorName>` (the authenticated
76
+ * operator behind the verified token), never derived from the request body.
77
+ * `run_id` defaults to `resolveRunId()` like every other daimon emitter.
78
+ */
79
+ export declare const emitControlWakeAccepted: (input: EmitControlWakeAcceptedInput) => Promise<CausalEvent<ControlWakeAcceptedPayload>>;
80
+ export interface EmitDeliveryWakeAcceptedInput {
81
+ causeEventIds?: string[];
82
+ requestId: string;
83
+ runId?: string;
84
+ runtimeHomePath: string;
85
+ targetAgentId: string;
86
+ wakeKind: string;
87
+ }
88
+ /**
89
+ * Stamps `control.wake.accepted` once root's Moltnet loopback delivery
90
+ * endpoint (`/agents/:slug/wake`) is about to wake `targetAgentId` on behalf
91
+ * of an inter-agent message. `principal_id` is always the fixed
92
+ * `DELIVERY_PRINCIPAL_ID` (`system:moltnet`) — the delivering authority —
93
+ * never derived from a caller-supplied `from`/agent field, and never
94
+ * `operator:<name>` (that principal is reserved for the operator-only
95
+ * control endpoint; see `emitControlWakeAccepted`). `run_id` defaults to
96
+ * `resolveRunId()` like every other daimon emitter.
97
+ */
98
+ export declare const emitDeliveryWakeAccepted: (input: EmitDeliveryWakeAcceptedInput) => Promise<CausalEvent<DeliveryWakeAcceptedPayload>>;
99
+ export interface EmitControlWakeDeniedInput {
100
+ causeEventIds?: string[];
101
+ operatorName: string;
102
+ reason: string;
103
+ requestId: string;
104
+ runId?: string;
105
+ runtimeHomePath: string;
106
+ targetAgentId: string;
107
+ }
108
+ /**
109
+ * Stamps `control.wake.denied` when root's operator-control endpoint rejects
110
+ * a wake request over a missing or invalid bearer token. Deny paths must
111
+ * never drop silently (see `specs/CAUSAL.md` enforcement point #3 / T5):
112
+ * every 401 the endpoint returns should carry exactly one of these. As with
113
+ * `emitControlWakeAccepted`, `principal_id` is always the authenticated
114
+ * operator identity, never a value read from the request.
115
+ */
116
+ export declare const emitControlWakeDenied: (input: EmitControlWakeDeniedInput) => Promise<CausalEvent<ControlWakeDeniedPayload>>;
117
+ //# sourceMappingURL=controlCausal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controlCausal.d.ts","sourceRoot":"","sources":["../../src/observability/controlCausal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEpF;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,0BAA0B,EAAG,uBAAgC,CAAC;AAC3E,eAAO,MAAM,wBAAwB,EAAG,qBAA8B,CAAC;AAEvE,2CAA2C;AAC3C,MAAM,WAAW,0BAA2B,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACzE,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,yCAAyC;AACzC,MAAM,WAAW,wBAAyB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,2BAA4B,SAAQ,0BAA0B;IAC7E,YAAY,EAAE,SAAS,CAAC;CACzB;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,cAAc,MAAM,KAAG,MAAoC,CAAC;AAEhG;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAG,gBAAyB,CAAC;AAE/D,+EAA+E;AAC/E,eAAO,MAAM,0BAA0B,GAAI,WAAW,MAAM,KAAG,MAClB,CAAC;AAE9C,2EAA2E;AAC3E,eAAO,MAAM,wBAAwB,GAAI,WAAW,MAAM,KAAG,MAAmD,CAAC;AAEjH;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GAAI,WAAW,MAAM,KAAG,MAClB,CAAC;AAE/C,MAAM,WAAW,4BAA4B;IAC3C,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAClC,OAAO,4BAA4B,KAClC,OAAO,CAAC,WAAW,CAAC,0BAA0B,CAAC,CAa9C,CAAC;AAEL,MAAM,WAAW,6BAA6B;IAC5C,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB,GACnC,OAAO,6BAA6B,KACnC,OAAO,CAAC,WAAW,CAAC,2BAA2B,CAAC,CAc/C,CAAC;AAEL,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAChC,OAAO,0BAA0B,KAChC,OAAO,CAAC,WAAW,CAAC,wBAAwB,CAAC,CAa5C,CAAC"}