@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,214 @@
1
+ /**
2
+ * Lowering an upstream MCP server's `CallToolResult` onto a Pi tool result.
3
+ *
4
+ * Every `mcp_*` tool is a *passthrough*: Daimon calls a declared MCP server and
5
+ * has to hand the model back what that server actually said. It used to hand
6
+ * back routing metadata instead — `details: { server, tool, is_error }` — and
7
+ * because the MCP mount lowers `details` to `structuredContent`
8
+ * (`src/mcp/toolServer.ts`) and the engines render `structuredContent` in
9
+ * preference to `content`, an agent calling any declared MCP tool saw
10
+ * `{"server":"newsroom","tool":"file_article","is_error":true}` and nothing
11
+ * else. The tool's own answer, and the reason for its own failure, never
12
+ * reached the model. `moltnet_read` was the same defect in a Daimon-authored
13
+ * tool; this is the wider one, in the tools Daimon does not author.
14
+ *
15
+ * Three rules follow, and they are the whole design:
16
+ *
17
+ * 1. **Both channels always carry the payload.** `content` and
18
+ * `structuredContent` are each filled with the result, mirroring whichever
19
+ * one the server did not send. Daimon has already been wrong once about
20
+ * which channel an engine renders; carrying the answer in both is the only
21
+ * shape where being wrong again costs nothing. A server that sent
22
+ * `structuredContent` gets it forwarded *verbatim*, so a declared
23
+ * `outputSchema` still describes what the model sees.
24
+ *
25
+ * 2. **`isError` is raised, not reported.** Pi's `AgentToolResult` has no
26
+ * error channel — a Pi tool signals failure by throwing, and
27
+ * `toolServer.ts` lowers a throw to `isError: true` plus the message. So an
28
+ * upstream `isError: true` becomes a thrown {@link McpToolCallError}
29
+ * carrying the server's own reason text. The model then gets a result
30
+ * flagged as a failure *and* the sentence explaining it, which is the
31
+ * difference between correcting a call and guessing at it.
32
+ *
33
+ * 3. **The bound truncates; it never throws the payload away.** An oversized
34
+ * result used to be refused outright, so the agent got
35
+ * `Error: MCP tool result exceeds bound` and none of the data. It is now
36
+ * degraded to a head of the serialized result plus an explicit marker
37
+ * naming both sizes.
38
+ *
39
+ * Daimon deliberately does *not* re-declare the upstream `outputSchema` on its
40
+ * own mount. A declared output schema obliges every result to carry conforming
41
+ * `structuredContent`, which neither a content-only server response nor rule 3's
42
+ * truncation marker can satisfy — declaring it would turn a degraded result into
43
+ * a client-side protocol error and lose the payload all over again.
44
+ */
45
+ /** Bound on the whole receipt record, mirrored from `productionAgentTools.ts`. */
46
+ const MAX_RECEIPT_BYTES = 65_536;
47
+ /**
48
+ * Headroom left inside the receipt bound for the receipt's own envelope.
49
+ *
50
+ * A successful MCP result is stored in its receipt so a replayed identical call
51
+ * in the same wake answers with the result rather than with a digest of it. The
52
+ * envelope (`kind`, ids, engine, server, tool, digest, `is_error`, `at`) is a
53
+ * few hundred bytes for any sane name; 4096 is generous enough that a stored
54
+ * result can never push the receipt past its own bound.
55
+ */
56
+ export const MCP_RECEIPT_ENVELOPE_RESERVE_BYTES = 4_096;
57
+ /** Bound on one lowered MCP tool result, model-facing and receipt-facing alike. */
58
+ export const MCP_TOOL_RESULT_MAX_BYTES = MAX_RECEIPT_BYTES - MCP_RECEIPT_ENVELOPE_RESERVE_BYTES;
59
+ /** Rendered for a server that answered with neither content nor structured content. */
60
+ export const MCP_EMPTY_RESULT_TEXT = "[daimon: the MCP server returned a result with no content]";
61
+ /** Reason used when a server flags an error but supplies no text for it. */
62
+ export const MCP_ERROR_WITHOUT_DETAIL = "the MCP server reported an error and gave no reason";
63
+ /**
64
+ * An upstream MCP tool that answered with `isError: true`.
65
+ *
66
+ * The reason is the server's own words. `toolServer.ts` renders a thrown error
67
+ * as `"<name>: <message>"` inside an `isError: true` result, so the model
68
+ * receives both the failure flag and the explanation.
69
+ */
70
+ export class McpToolCallError extends Error {
71
+ server;
72
+ tool;
73
+ reason;
74
+ constructor(server, tool, reason) {
75
+ super(`${server}/${tool} failed: ${reason}`);
76
+ this.name = "McpToolCallError";
77
+ this.server = server;
78
+ this.tool = tool;
79
+ this.reason = reason;
80
+ }
81
+ }
82
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
83
+ /** Flatten an MCP content array to text, naming the parts that are not text. */
84
+ export function mcpContentText(content) {
85
+ if (!Array.isArray(content))
86
+ return "";
87
+ return content
88
+ .map((part) => {
89
+ if (!isRecord(part))
90
+ return "";
91
+ if (part.type === "text" && typeof part.text === "string")
92
+ return part.text;
93
+ return `[${typeof part.type === "string" ? part.type : "unknown"} content part]`;
94
+ })
95
+ .filter((text) => text.length > 0)
96
+ .join("\n");
97
+ }
98
+ /** Truncate to a byte budget without splitting a UTF-8 code point. */
99
+ export function truncateUtf8(value, maxBytes) {
100
+ const bytes = Buffer.from(value, "utf8");
101
+ if (bytes.byteLength <= maxBytes)
102
+ return { text: value, truncated: false, originalBytes: bytes.byteLength };
103
+ let end = Math.max(0, maxBytes);
104
+ while (end > 0 && (bytes[end] & 0xc0) === 0x80)
105
+ end -= 1;
106
+ return { text: bytes.subarray(0, end).toString("utf8"), truncated: true, originalBytes: bytes.byteLength };
107
+ }
108
+ const truncationMarker = (resultBytes, boundBytes) => `\n[daimon: truncated — the MCP tool result was ${resultBytes} bytes, above the ${boundBytes}-byte tool result bound]`;
109
+ /**
110
+ * The server's own explanation for an `isError: true` result.
111
+ *
112
+ * Both channels are consulted, because a server may put a human sentence in
113
+ * `content` and a machine-readable code in `structuredContent`, and an agent
114
+ * that has to fix its own call needs whichever one it was given.
115
+ */
116
+ export function mcpErrorReason(result, maxBytes) {
117
+ const text = mcpContentText(result.content);
118
+ const structured = result.structuredContent === undefined ? "" : safeStringify(result.structuredContent);
119
+ const reason = [text, structured].filter((piece) => piece.length > 0).join(" ");
120
+ if (reason.length === 0)
121
+ return MCP_ERROR_WITHOUT_DETAIL;
122
+ const bounded = truncateUtf8(reason, maxBytes);
123
+ return bounded.truncated ? `${bounded.text}${truncationMarker(bounded.originalBytes, maxBytes)}` : bounded.text;
124
+ }
125
+ function safeStringify(value) {
126
+ try {
127
+ return JSON.stringify(value) ?? "";
128
+ }
129
+ catch {
130
+ return "[daimon: the MCP server returned a value that is not JSON-serialisable]";
131
+ }
132
+ }
133
+ /** Everything a result carries beyond the three fields this module names. */
134
+ function otherFields(result) {
135
+ if (!isRecord(result))
136
+ return undefined;
137
+ const rest = Object.fromEntries(Object.entries(result).filter(([key]) => key !== "content" && key !== "structuredContent" && key !== "isError"));
138
+ return Object.keys(rest).length === 0 ? undefined : rest;
139
+ }
140
+ const measure = (content, details) => Buffer.byteLength(safeStringify({ content, structuredContent: details }), "utf8");
141
+ /**
142
+ * Lower one upstream result, or throw {@link McpToolCallError} when it is an
143
+ * error result.
144
+ */
145
+ export function renderMcpToolResult(input) {
146
+ const maxBytes = input.maxBytes ?? MCP_TOOL_RESULT_MAX_BYTES;
147
+ if (input.result.isError === true) {
148
+ throw new McpToolCallError(input.server, input.tool, mcpErrorReason(input.result, Math.floor(maxBytes / 2)));
149
+ }
150
+ const upstreamContent = Array.isArray(input.result.content) ? input.result.content : undefined;
151
+ // A server predating the `content` field answers in some other shape entirely
152
+ // (the SDK still types `toolResult` for those). Forward whatever it did send
153
+ // rather than reporting an empty result over the top of a real one.
154
+ const legacy = upstreamContent === undefined && !isRecord(input.result.structuredContent) ? otherFields(input.result) : undefined;
155
+ const structured = isRecord(input.result.structuredContent) ? input.result.structuredContent : legacy;
156
+ const content = upstreamContent !== undefined && upstreamContent.length > 0
157
+ ? upstreamContent
158
+ : structured !== undefined
159
+ ? [{ type: "text", text: safeStringify(structured) }]
160
+ : [{ type: "text", text: MCP_EMPTY_RESULT_TEXT }];
161
+ // Rule 1: the channel the server left empty mirrors the one it filled, so the
162
+ // payload is present whichever one the engine chooses to render.
163
+ const details = structured ?? { content: upstreamContent ?? [] };
164
+ if (measure(content, details) <= maxBytes)
165
+ return { content, details, truncated: false };
166
+ return degrade(input.result, measure(content, details), maxBytes);
167
+ }
168
+ /**
169
+ * Rule 3: an oversized result becomes a bounded head of itself plus a marker.
170
+ *
171
+ * Both channels still mirror each other, so the head is written twice; the
172
+ * budget is halved to pay for that and then shrunk until the whole record
173
+ * genuinely fits, rather than trusting an estimate of the JSON overhead.
174
+ */
175
+ function degrade(result, resultBytes, maxBytes) {
176
+ const serialized = safeStringify({
177
+ ...(result.content === undefined ? {} : { content: result.content }),
178
+ ...(result.structuredContent === undefined ? {} : { structured_content: result.structuredContent })
179
+ });
180
+ const marker = truncationMarker(resultBytes, maxBytes);
181
+ const build = (head) => ({
182
+ content: [{ type: "text", text: `${head}${marker}` }],
183
+ details: { daimon_truncated: true, bound_bytes: maxBytes, result_bytes: resultBytes, result_json_head: head },
184
+ truncated: true
185
+ });
186
+ let budget = Math.max(0, Math.floor(maxBytes / 2));
187
+ let candidate = build(truncateUtf8(serialized, budget).text);
188
+ for (let attempt = 0; attempt < 8 && budget > 0; attempt += 1) {
189
+ const size = measure(candidate.content, candidate.details);
190
+ if (size <= maxBytes)
191
+ return candidate;
192
+ budget = Math.max(0, budget - Math.ceil((size - maxBytes) / 2) - 16);
193
+ candidate = build(truncateUtf8(serialized, budget).text);
194
+ }
195
+ return candidate;
196
+ }
197
+ /**
198
+ * Rebuild a tool answer from a receipt written by an earlier identical call.
199
+ *
200
+ * The wake-scoped receipt exists so a repeated identical call is not sent
201
+ * upstream twice. It used to be *returned* to the model in place of the result,
202
+ * so a retried call answered with `{"kind":"mcp",…,"digest":"sha256:…"}` — the
203
+ * least useful thing an agent stuck in a retry loop could possibly receive.
204
+ * A recorded failure is replayed as the same failure, with the same reason.
205
+ */
206
+ export function replayMcpReceipt(server, tool, receipt) {
207
+ if (typeof receipt.error === "string")
208
+ throw new McpToolCallError(server, tool, receipt.error);
209
+ const stored = receipt.result;
210
+ if (isRecord(stored) && Array.isArray(stored.content) && isRecord(stored.details)) {
211
+ return { content: stored.content, details: stored.details, truncated: receipt.truncated === true };
212
+ }
213
+ throw new McpToolCallError(server, tool, "an identical earlier call in this wake was recorded without its result, so it cannot be replayed; change the arguments to make a new call");
214
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Paging and error semantics for Moltnet's frozen `machine` read wire.
3
+ *
4
+ * The wire is a strict v1 with two caps that a naive read ignores, and both are
5
+ * enforced *server side* by `projectRead` in the Moltnet CLI
6
+ * (`moltnet/internal/machine/service.go`), which answers
7
+ * `{"error":{"code":"transport"}}` rather than truncating:
8
+ *
9
+ * - `MachineMaxOutputLineBytes` (16384) bounds the whole encoded response
10
+ * line. `MachineReadPage.Validate` measures it against a *worst case*
11
+ * envelope — a maximum-length correlation id and target id — so the
12
+ * effective payload budget is roughly 250 bytes tighter than the line an
13
+ * agent actually receives.
14
+ * - `MachineMaxReadPartTextBytes` (4096) bounds any single message part.
15
+ *
16
+ * An agent asking for `limit: 100` on a room of six ~2000-byte messages
17
+ * therefore never got a page at all: seven such messages already overflow the
18
+ * line. Reading in small pages and following the returned cursor is the only
19
+ * way to get a busy room across this wire, so that behaviour lives here rather
20
+ * than in the tool that happens to call it.
21
+ */
22
+ /** `protocol.MachineMaxOutputLineBytes`, quoted for diagnostics only. */
23
+ export declare const MOLTNET_MACHINE_MAX_OUTPUT_LINE_BYTES = 16384;
24
+ /** `protocol.MachineMaxReadPartTextBytes`, quoted for diagnostics only. */
25
+ export declare const MOLTNET_MACHINE_MAX_READ_PART_TEXT_BYTES = 4096;
26
+ /**
27
+ * Messages requested per wire page.
28
+ *
29
+ * Six ~2000-byte messages were the largest page observed to encode inside the
30
+ * line cap against the real 0.1.17 binary, so five leaves headroom for a page
31
+ * of unusually large messages before the adaptive halving below is needed.
32
+ */
33
+ export declare const MOLTNET_READ_PAGE_LIMIT = 5;
34
+ /** Hard stop on wire round trips, so a misbehaving cursor cannot spin forever. */
35
+ export declare const MOLTNET_READ_MAX_PAGES = 64;
36
+ /**
37
+ * A `machine` response that carried `error.code`.
38
+ *
39
+ * The code is the whole diagnosis — a `transport` is a cap overflow, a
40
+ * `not_found` is an undeclared target, a `canceled` is a stdin race — and
41
+ * collapsing all of them into one generic string is what hid a never-working
42
+ * tool for as long as it did.
43
+ */
44
+ export declare class MoltnetMachineError extends Error {
45
+ readonly code: string;
46
+ constructor(operation: string, code: string);
47
+ }
48
+ /**
49
+ * Unwrap one `machine` response, surfacing `error.code` as a thrown
50
+ * {@link MoltnetMachineError} rather than an anonymous refusal.
51
+ */
52
+ export declare function moltnetOperationResult(response: Record<string, unknown>, key: string, operation: string): Record<string, unknown> | undefined;
53
+ export interface MoltnetReadWirePage {
54
+ readonly messages: readonly unknown[];
55
+ readonly hasMore: boolean;
56
+ readonly nextBefore?: string;
57
+ readonly nextAfter?: string;
58
+ readonly target?: unknown;
59
+ }
60
+ export type MoltnetReadFetch = (request: {
61
+ readonly limit: number;
62
+ readonly before?: string;
63
+ readonly after?: string;
64
+ }) => Promise<MoltnetReadWirePage>;
65
+ export interface MoltnetReadTruncation {
66
+ readonly reason: "message_exceeds_machine_wire_caps" | "result_bound" | "page_bound";
67
+ readonly detail: string;
68
+ readonly cursor?: string;
69
+ }
70
+ export interface MoltnetPagedRead {
71
+ readonly target?: unknown;
72
+ readonly messages: readonly unknown[];
73
+ readonly hasMore: boolean;
74
+ readonly nextBefore?: string;
75
+ readonly nextAfter?: string;
76
+ readonly pages: number;
77
+ readonly truncated?: MoltnetReadTruncation;
78
+ }
79
+ export interface MoltnetPagedReadOptions {
80
+ readonly requested: number;
81
+ readonly before?: string;
82
+ readonly after?: string;
83
+ readonly maxBytes: number;
84
+ readonly pageLimit?: number;
85
+ readonly fetch: MoltnetReadFetch;
86
+ }
87
+ /**
88
+ * Read `requested` messages by walking the wire in pages small enough to encode.
89
+ *
90
+ * Direction follows the caller's cursor: an `after` read walks forward through
91
+ * `next_after`, everything else walks backward from the newest message through
92
+ * `next_before`. Either way the returned messages are in one stable
93
+ * chronological order, oldest first, matching the order a single page arrives
94
+ * in.
95
+ */
96
+ export declare function readMoltnetPages(options: MoltnetPagedReadOptions): Promise<MoltnetPagedRead>;
97
+ //# sourceMappingURL=moltnetMachineRead.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moltnetMachineRead.d.ts","sourceRoot":"","sources":["../../src/runtime/moltnetMachineRead.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,yEAAyE;AACzE,eAAO,MAAM,qCAAqC,QAAS,CAAC;AAC5D,2EAA2E;AAC3E,eAAO,MAAM,wCAAwC,OAAQ,CAAC;AAC9D;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC;;;;;;;GAOG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEV,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAKnD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAUrC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,MAAM,gBAAgB,GAAG,CAC7B,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KACnF,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAElC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,mCAAmC,GAAG,cAAc,GAAG,YAAY,CAAC;IACrF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,qBAAqB,CAAC;CAC5C;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;CAClC;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAuElG"}
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Paging and error semantics for Moltnet's frozen `machine` read wire.
3
+ *
4
+ * The wire is a strict v1 with two caps that a naive read ignores, and both are
5
+ * enforced *server side* by `projectRead` in the Moltnet CLI
6
+ * (`moltnet/internal/machine/service.go`), which answers
7
+ * `{"error":{"code":"transport"}}` rather than truncating:
8
+ *
9
+ * - `MachineMaxOutputLineBytes` (16384) bounds the whole encoded response
10
+ * line. `MachineReadPage.Validate` measures it against a *worst case*
11
+ * envelope — a maximum-length correlation id and target id — so the
12
+ * effective payload budget is roughly 250 bytes tighter than the line an
13
+ * agent actually receives.
14
+ * - `MachineMaxReadPartTextBytes` (4096) bounds any single message part.
15
+ *
16
+ * An agent asking for `limit: 100` on a room of six ~2000-byte messages
17
+ * therefore never got a page at all: seven such messages already overflow the
18
+ * line. Reading in small pages and following the returned cursor is the only
19
+ * way to get a busy room across this wire, so that behaviour lives here rather
20
+ * than in the tool that happens to call it.
21
+ */
22
+ /** `protocol.MachineMaxOutputLineBytes`, quoted for diagnostics only. */
23
+ export const MOLTNET_MACHINE_MAX_OUTPUT_LINE_BYTES = 16_384;
24
+ /** `protocol.MachineMaxReadPartTextBytes`, quoted for diagnostics only. */
25
+ export const MOLTNET_MACHINE_MAX_READ_PART_TEXT_BYTES = 4_096;
26
+ /**
27
+ * Messages requested per wire page.
28
+ *
29
+ * Six ~2000-byte messages were the largest page observed to encode inside the
30
+ * line cap against the real 0.1.17 binary, so five leaves headroom for a page
31
+ * of unusually large messages before the adaptive halving below is needed.
32
+ */
33
+ export const MOLTNET_READ_PAGE_LIMIT = 5;
34
+ /** Hard stop on wire round trips, so a misbehaving cursor cannot spin forever. */
35
+ export const MOLTNET_READ_MAX_PAGES = 64;
36
+ /**
37
+ * A `machine` response that carried `error.code`.
38
+ *
39
+ * The code is the whole diagnosis — a `transport` is a cap overflow, a
40
+ * `not_found` is an undeclared target, a `canceled` is a stdin race — and
41
+ * collapsing all of them into one generic string is what hid a never-working
42
+ * tool for as long as it did.
43
+ */
44
+ export class MoltnetMachineError extends Error {
45
+ code;
46
+ constructor(operation, code) {
47
+ super(`Moltnet ${operation} failed: ${code}`);
48
+ this.name = "MoltnetMachineError";
49
+ this.code = code;
50
+ }
51
+ }
52
+ /**
53
+ * Unwrap one `machine` response, surfacing `error.code` as a thrown
54
+ * {@link MoltnetMachineError} rather than an anonymous refusal.
55
+ */
56
+ export function moltnetOperationResult(response, key, operation) {
57
+ const error = response.error;
58
+ if (error !== undefined && error !== null) {
59
+ const code = typeof error === "object" && typeof error.code === "string"
60
+ ? error.code
61
+ : "unknown";
62
+ throw new MoltnetMachineError(operation, code);
63
+ }
64
+ const result = response[key];
65
+ return typeof result === "object" && result !== null ? result : undefined;
66
+ }
67
+ /**
68
+ * Read `requested` messages by walking the wire in pages small enough to encode.
69
+ *
70
+ * Direction follows the caller's cursor: an `after` read walks forward through
71
+ * `next_after`, everything else walks backward from the newest message through
72
+ * `next_before`. Either way the returned messages are in one stable
73
+ * chronological order, oldest first, matching the order a single page arrives
74
+ * in.
75
+ */
76
+ export async function readMoltnetPages(options) {
77
+ const forward = options.after !== undefined;
78
+ const pageLimit = Math.max(1, options.pageLimit ?? MOLTNET_READ_PAGE_LIMIT);
79
+ const collected = [];
80
+ const visited = new Set();
81
+ let cursor = forward ? options.after : options.before;
82
+ let target;
83
+ let total = 0;
84
+ let pages = 0;
85
+ let bytes = 0;
86
+ let hasMore = false;
87
+ let nextCursor;
88
+ let truncated;
89
+ while (total < options.requested && pages < MOLTNET_READ_MAX_PAGES) {
90
+ const wanted = Math.min(pageLimit, options.requested - total);
91
+ const page = await fetchWithinCaps(options.fetch, wanted, forward, cursor);
92
+ if (page instanceof MoltnetMachineError) {
93
+ // A cursor the caller supplied that yields nothing is a bad cursor, not a
94
+ // message too large to encode: the two are indistinguishable on this wire
95
+ // (both are `transport`), and an empty truncated read hides the mistake
96
+ // where the code names it.
97
+ if (pages === 0 && (options.before !== undefined || options.after !== undefined))
98
+ throw page;
99
+ truncated = oversizedMessage(cursor);
100
+ hasMore = true;
101
+ nextCursor = cursor;
102
+ break;
103
+ }
104
+ const pageBytes = Buffer.byteLength(JSON.stringify(page.messages));
105
+ if (pages > 0 && bytes + pageBytes > options.maxBytes) {
106
+ truncated = {
107
+ reason: "result_bound",
108
+ detail: `the concatenated read reached the ${options.maxBytes} byte tool result bound`,
109
+ ...(cursor === undefined ? {} : { cursor })
110
+ };
111
+ hasMore = true;
112
+ nextCursor = cursor;
113
+ break;
114
+ }
115
+ if (target === undefined)
116
+ target = page.target;
117
+ collected.push(page.messages);
118
+ bytes += pageBytes;
119
+ total += page.messages.length;
120
+ pages += 1;
121
+ const next = forward ? page.nextAfter : page.nextBefore;
122
+ const resumable = page.hasMore && typeof next === "string" && next.length > 0;
123
+ hasMore = resumable;
124
+ nextCursor = resumable ? next : undefined;
125
+ // A repeated cursor or an empty page means the wire stopped making
126
+ // progress; continuing would spin without ever satisfying `requested`.
127
+ if (!resumable || page.messages.length === 0 || visited.has(next))
128
+ break;
129
+ visited.add(next);
130
+ cursor = next;
131
+ }
132
+ if (hasMore && truncated === undefined && pages >= MOLTNET_READ_MAX_PAGES) {
133
+ truncated = {
134
+ reason: "page_bound",
135
+ detail: `the read stopped after ${MOLTNET_READ_MAX_PAGES} wire pages`,
136
+ ...(nextCursor === undefined ? {} : { cursor: nextCursor })
137
+ };
138
+ }
139
+ return {
140
+ ...(target === undefined ? {} : { target }),
141
+ messages: forward ? collected.flat() : collected.reverse().flat(),
142
+ hasMore,
143
+ ...(nextCursor === undefined ? {} : forward ? { nextAfter: nextCursor } : { nextBefore: nextCursor }),
144
+ pages,
145
+ ...(truncated === undefined ? {} : { truncated })
146
+ };
147
+ }
148
+ /**
149
+ * Fetch one page, halving the requested limit on every `transport` refusal.
150
+ *
151
+ * A returned {@link MoltnetMachineError} means even a single message could not
152
+ * be projected onto the wire. The wire offers no way to name or skip that
153
+ * message — a cursor only ever comes back inside a page that encoded — so the
154
+ * caller decides between reporting the blockage and failing outright.
155
+ */
156
+ async function fetchWithinCaps(fetch, wanted, forward, cursor) {
157
+ let limit = wanted;
158
+ for (;;) {
159
+ try {
160
+ return await fetch({
161
+ limit,
162
+ ...(cursor === undefined ? {} : forward ? { after: cursor } : { before: cursor })
163
+ });
164
+ }
165
+ catch (error) {
166
+ if (!(error instanceof MoltnetMachineError) || error.code !== "transport")
167
+ throw error;
168
+ if (limit <= 1)
169
+ return error;
170
+ limit = Math.max(1, Math.floor(limit / 2));
171
+ }
172
+ }
173
+ }
174
+ function oversizedMessage(cursor) {
175
+ return {
176
+ reason: "message_exceeds_machine_wire_caps",
177
+ detail: "one Moltnet message could not be encoded onto the machine read wire"
178
+ + ` (part text limit ${MOLTNET_MACHINE_MAX_READ_PART_TEXT_BYTES} bytes,`
179
+ + ` response line limit ${MOLTNET_MACHINE_MAX_OUTPUT_LINE_BYTES} bytes);`
180
+ + " the read returned everything up to it rather than failing",
181
+ ...(cursor === undefined ? {} : { cursor })
182
+ };
183
+ }
@@ -0,0 +1,165 @@
1
+ import type { AttentionConfig } from "../contracts/attentionContract.js";
2
+ import { ORGANIZATION_RUNTIME_CODEX_REASONING_EFFORTS, ORGANIZATION_RUNTIME_CODEX_WORKSPACE_NO_NETWORK_POLICY, ORGANIZATION_RUNTIME_CONFIG_SCHEMA, ORGANIZATION_RUNTIME_CONFIG_V2_SCHEMA, ORGANIZATION_RUNTIME_MAX_AGENTS, ORGANIZATION_RUNTIME_MAX_CONFIG_BYTES, ORGANIZATION_RUNTIME_MAX_INSTRUCTIONS_CODEPOINTS, ORGANIZATION_RUNTIME_MAX_STRING_BYTES, ORGANIZATION_RUNTIME_MAX_STRING_CODEPOINTS, ORGANIZATION_RUNTIME_MAX_WAKE_TEXT_BYTES, ORGANIZATION_RUNTIME_MAX_SCHEDULE_INTERVAL_MS, ORGANIZATION_RUNTIME_MAX_SCHEDULE_JITTER_SECONDS, ORGANIZATION_RUNTIME_V2_VERSION, ORGANIZATION_RUNTIME_VERSION } from "../contracts/organizationRuntimeContract.js";
3
+ export { ORGANIZATION_RUNTIME_CODEX_REASONING_EFFORTS, ORGANIZATION_RUNTIME_CODEX_WORKSPACE_NO_NETWORK_POLICY, ORGANIZATION_RUNTIME_CONFIG_SCHEMA, ORGANIZATION_RUNTIME_CONFIG_V2_SCHEMA, ORGANIZATION_RUNTIME_MAX_AGENTS, ORGANIZATION_RUNTIME_MAX_CONFIG_BYTES, ORGANIZATION_RUNTIME_MAX_INSTRUCTIONS_CODEPOINTS, ORGANIZATION_RUNTIME_MAX_STRING_BYTES, ORGANIZATION_RUNTIME_MAX_STRING_CODEPOINTS, ORGANIZATION_RUNTIME_MAX_WAKE_TEXT_BYTES, ORGANIZATION_RUNTIME_MAX_SCHEDULE_INTERVAL_MS, ORGANIZATION_RUNTIME_MAX_SCHEDULE_JITTER_SECONDS, ORGANIZATION_RUNTIME_V2_VERSION, ORGANIZATION_RUNTIME_VERSION };
4
+ export type OrganizationRuntimeEngineKind = "codex" | "grok" | "agy";
5
+ /**
6
+ * `model`/`reasoningEffort` are accepted for codex (open model name) and for
7
+ * grok (closed broker lists, declared together); agy owns its own model
8
+ * selection and `organizationRuntimeParsing.ts` rejects either field there at
9
+ * parse time rather than silently ignoring it. The type stays flat
10
+ * — not a `kind`-discriminated union — because every parsed value already
11
+ * satisfies the invariant; callers that need it narrow on `kind === "codex"`.
12
+ */
13
+ export type OrganizationRuntimeCodexSandboxPolicy = Readonly<{
14
+ mode: "workspace-write";
15
+ networkAccess: false;
16
+ webSearch: "disabled";
17
+ }>;
18
+ export type OrganizationRuntimeEngineIntent = Readonly<{
19
+ kind: OrganizationRuntimeEngineKind;
20
+ model?: string;
21
+ reasoningEffort?: string;
22
+ codexSandbox?: OrganizationRuntimeCodexSandboxPolicy;
23
+ }>;
24
+ export type OrganizationRuntimeMcpServer = Readonly<{
25
+ name: string;
26
+ transport: "stdio" | "sse" | "streamable_http";
27
+ command?: string;
28
+ args: readonly string[];
29
+ env: Readonly<Record<string, string>>;
30
+ authSecretEnv?: string;
31
+ url?: string;
32
+ tools: readonly string[];
33
+ }>;
34
+ export type OrganizationRuntimeMoltnet = Readonly<{
35
+ cliPath: string;
36
+ configPath: string;
37
+ networks: readonly Readonly<{
38
+ id: string;
39
+ rooms: readonly string[];
40
+ dms: boolean;
41
+ }>[];
42
+ }>;
43
+ export type OrganizationRuntimeMemory = Readonly<{
44
+ runtimeHomePath: string;
45
+ source?: string;
46
+ tokenBudget?: number;
47
+ }>;
48
+ export type OrganizationRuntimeSchedule = Readonly<{
49
+ kind: "disabled";
50
+ }> | Readonly<{
51
+ kind: "every";
52
+ interval_ms: number;
53
+ prompt: string;
54
+ jitter_seconds?: number;
55
+ }> | Readonly<{
56
+ kind: "cron";
57
+ cron: string;
58
+ timezone: string;
59
+ prompt: string;
60
+ jitter_seconds?: number;
61
+ }>;
62
+ export type OrganizationRuntimeAgentConfig = Readonly<{
63
+ id: string;
64
+ name: string;
65
+ instructions: string;
66
+ workspacePath: string;
67
+ runtimeHomePath: string;
68
+ engine: OrganizationRuntimeEngineIntent;
69
+ attention?: AttentionConfig;
70
+ schedule?: OrganizationRuntimeSchedule;
71
+ mcp?: readonly OrganizationRuntimeMcpServer[];
72
+ moltnet?: OrganizationRuntimeMoltnet;
73
+ memory?: OrganizationRuntimeMemory;
74
+ }>;
75
+ export type OrganizationRuntimeHostConfig = Readonly<{
76
+ bindHost: string;
77
+ port: number; /** Variable name only; never secret configuration data. */
78
+ controlTokenEnv: string;
79
+ }>;
80
+ export type OrganizationRuntimeConfig = Readonly<{
81
+ version: typeof ORGANIZATION_RUNTIME_VERSION | typeof ORGANIZATION_RUNTIME_V2_VERSION;
82
+ host: OrganizationRuntimeHostConfig;
83
+ agents: readonly OrganizationRuntimeAgentConfig[];
84
+ }>;
85
+ export type OrganizationRuntimeLifecycleState = "starting" | "running" | "stopping" | "stopped";
86
+ export type OrganizationRuntimeWakeEvent = Readonly<{
87
+ version: "noopolis.daimon.wake.v1";
88
+ id: string;
89
+ kind: "manual" | "message" | "schedule" | "external";
90
+ text: string;
91
+ occurredAt: string;
92
+ }>;
93
+ export type OrganizationRuntimeWakeRequest = Readonly<{
94
+ token: string | undefined;
95
+ agentId: string;
96
+ event: OrganizationRuntimeWakeEvent;
97
+ }>;
98
+ export type OrganizationRuntimeWakeResult = Readonly<{
99
+ version: "noopolis.daimon.wake-result.v1";
100
+ status: "completed";
101
+ agentId: string;
102
+ wakeId: string;
103
+ text: string;
104
+ durationMs: number;
105
+ }> | Readonly<{
106
+ version: "noopolis.daimon.wake-result.v1";
107
+ status: "rejected";
108
+ agentId: string;
109
+ wakeId: string;
110
+ code: "invalid_request" | "unauthorized" | "unknown_agent" | "queue_full" | "durable_inbox_required";
111
+ }> | Readonly<{
112
+ version: "noopolis.daimon.wake-result.v1";
113
+ status: "stopped";
114
+ agentId: string;
115
+ wakeId: string;
116
+ code: "host_stopping" | "host_stopped" | "queued_wake_stopped" | "active_wake_aborted";
117
+ }> | Readonly<{
118
+ version: "noopolis.daimon.wake-result.v1";
119
+ status: "failed";
120
+ agentId: string;
121
+ wakeId: string;
122
+ code: "engine_failed";
123
+ detail?: string;
124
+ }>;
125
+ export type OrganizationRuntimeAgentHealth = Readonly<{
126
+ agentId: string;
127
+ engine: OrganizationRuntimeEngineIntent["kind"];
128
+ state: OrganizationRuntimeLifecycleState | "idle" | "running" | "failed";
129
+ }>;
130
+ export type OrganizationRuntimeHealth = Readonly<{
131
+ version: "noopolis.daimon.organization-runtime-health.v1";
132
+ state: OrganizationRuntimeLifecycleState;
133
+ agents: readonly OrganizationRuntimeAgentHealth[];
134
+ }>;
135
+ export type OrganizationRuntimeActivityRequest = Readonly<{
136
+ agentId?: string;
137
+ cursor?: string;
138
+ limit: number;
139
+ }>;
140
+ export type OrganizationRuntimeActivity = Readonly<{
141
+ id: string;
142
+ agentId: string;
143
+ wakeId?: string;
144
+ kind: "wake_started" | "wake_completed" | "wake_rejected" | "wake_aborted" | "agent_stopped";
145
+ occurredAt: string;
146
+ }>;
147
+ export type OrganizationRuntimeActivityPage = Readonly<{
148
+ version: "noopolis.daimon.organization-runtime-activity.v1";
149
+ items: readonly OrganizationRuntimeActivity[];
150
+ nextCursor?: string;
151
+ }>;
152
+ export type OrganizationRuntimeShutdownCompletion = Readonly<{
153
+ version: "noopolis.daimon.organization-runtime-stop.v1";
154
+ state: "stopped";
155
+ }>;
156
+ /** One host runs isolated agents; it never coordinates their work. */
157
+ export interface OrganizationRuntimeHost {
158
+ start(): Promise<void>;
159
+ wake(request: OrganizationRuntimeWakeRequest): Promise<OrganizationRuntimeWakeResult>;
160
+ health(agentId?: string): Promise<OrganizationRuntimeHealth>;
161
+ activity(request: OrganizationRuntimeActivityRequest): Promise<OrganizationRuntimeActivityPage>;
162
+ stop(): Promise<OrganizationRuntimeShutdownCompletion>;
163
+ }
164
+ export { isOrganizationRuntimeConfig, parseOrganizationRuntimeConfig, parseOrganizationRuntimeWakeRequest, validateOrganizationRuntimeConfig } from "./organizationRuntimeParsing.js";
165
+ //# sourceMappingURL=organizationRuntime.d.ts.map