@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
@@ -1,35 +1,122 @@
1
1
  import { Type } from "@earendil-works/pi-ai";
2
2
  import { defineTool } from "@earendil-works/pi-coding-agent";
3
- import { createMemoryToolDescriptors } from "@noopolis/mneme";
4
- const fallbackContext = (agentId) => ({
5
- wakeId: "manual",
6
- threadId: "manual",
7
- principal: { agentId, scope: "global" },
8
- conversationScope: "global",
9
- audienceKey: agentId,
10
- transport: "in_process"
11
- });
3
+ import { canonicalScopeKey, createMemoryToolDescriptors, memoryScopeId, schemaForModelToolName } from "@noopolis/mneme";
4
+ const MAX_ALLOWED_SCOPES = 32;
5
+ const MEMORY_PRINCIPAL_SCOPES = new Set([
6
+ "artifact",
7
+ "global",
8
+ "pair",
9
+ "role",
10
+ "room",
11
+ "task",
12
+ "team"
13
+ ]);
14
+ const trustedAllowedScopes = (agentId, prepared) => {
15
+ if (!Array.isArray(prepared.allowedScopes)
16
+ || prepared.allowedScopes.length === 0
17
+ || prepared.allowedScopes.length > MAX_ALLOWED_SCOPES) {
18
+ throw new Error("prepared memory turn requires a bounded finite scope set");
19
+ }
20
+ const scopes = prepared.allowedScopes.map((scope) => {
21
+ if (typeof scope !== "string" || scope !== canonicalScopeKey(scope)
22
+ || scope.length > 512 || /[\u0000-\u001f\u007f]/u.test(scope)) {
23
+ throw new Error("prepared memory turn contains an invalid scope");
24
+ }
25
+ return scope;
26
+ });
27
+ const agentPrefix = canonicalScopeKey(`agent:${agentId}/scope:`);
28
+ if (new Set(scopes).size !== scopes.length || scopes.some((scope) => !scope.startsWith(agentPrefix))) {
29
+ throw new Error("prepared memory turn contains a foreign or duplicate scope");
30
+ }
31
+ const activeScope = canonicalScopeKey(memoryScopeId(prepared.principal));
32
+ if (!scopes.includes(activeScope)) {
33
+ throw new Error("prepared memory turn omits its active principal scope");
34
+ }
35
+ return Object.freeze([...scopes]);
36
+ };
37
+ export const createTrustedPiMemoryToolContext = (input) => {
38
+ if (input.prepared.principal.agentId !== input.agentId
39
+ || input.memory.authority.bankId !== input.agentId) {
40
+ throw new Error("prepared memory authority does not match the Pi agent");
41
+ }
42
+ if (!MEMORY_PRINCIPAL_SCOPES.has(input.prepared.principal.scope)) {
43
+ throw new Error("prepared memory turn contains an invalid principal scope");
44
+ }
45
+ const principal = Object.freeze({ ...input.prepared.principal });
46
+ const activeScope = canonicalScopeKey(memoryScopeId(principal));
47
+ return Object.freeze({
48
+ allowedScopes: trustedAllowedScopes(input.agentId, input.prepared),
49
+ audienceKey: activeScope,
50
+ authority: input.memory.authority,
51
+ conversationScope: activeScope,
52
+ mode: input.mode,
53
+ principal,
54
+ threadId: input.threadId,
55
+ transport: "in_process",
56
+ wakeId: input.wakeId
57
+ });
58
+ };
59
+ const requireTrustedContext = (agentId, contextRef) => {
60
+ const context = contextRef.current;
61
+ if (context === undefined
62
+ || context.principal.agentId !== agentId
63
+ || context.authority?.bankId !== agentId
64
+ || !Array.isArray(context.allowedScopes)) {
65
+ throw new Error("Pi memory tool requires the active trusted turn context");
66
+ }
67
+ return context;
68
+ };
12
69
  const textContent = (result) => ({
13
70
  content: [{ type: "text", text: JSON.stringify(result) }],
14
71
  details: result
15
72
  });
73
+ export function canonicalToolFieldNames(name, representation) {
74
+ const source = arguments.length >= 2 ? representation : schemaForModelToolName(name);
75
+ if (source !== null && typeof source === "object") {
76
+ const candidate = source;
77
+ const fields = candidate.shape !== undefined ? candidate.shape : source;
78
+ if (fields !== null && typeof fields === "object" && !Array.isArray(fields)) {
79
+ const names = Object.keys(fields);
80
+ if (names.length > 0) {
81
+ return names;
82
+ }
83
+ }
84
+ }
85
+ throw new Error(`@noopolis/mneme returned no usable field contract for memory tool ${name}`);
86
+ }
87
+ export const MEMORY_TOOL_ARGUMENT_FIELDS = Object.fromEntries(createMemoryToolDescriptors({}, { mode: "dream" })
88
+ .map(({ modelName }) => [modelName, new Set(canonicalToolFieldNames(modelName))]));
89
+ const requireExactModelArguments = (toolName, params) => {
90
+ if (typeof params !== "object" || params === null || Array.isArray(params)) {
91
+ throw new Error("Pi memory tool arguments must be an object");
92
+ }
93
+ const allowed = MEMORY_TOOL_ARGUMENT_FIELDS[toolName];
94
+ if (allowed === undefined) {
95
+ throw new Error(`Pi memory tool ${toolName} has no argument contract`);
96
+ }
97
+ for (const field of Reflect.ownKeys(params)) {
98
+ if (typeof field !== "string" || !allowed.has(field)) {
99
+ throw new Error(`Pi memory tool ${toolName} received unexpected top-level argument ${String(field)}`);
100
+ }
101
+ }
102
+ };
16
103
  const contentSchema = Type.Object({
17
104
  kind: Type.String({ description: "Memory content kind: text, claim, decision, artifact, or relationship." })
18
105
  }, { additionalProperties: true });
19
- const schemaFor = (name) => {
106
+ export const schemaFor = (name) => {
20
107
  if (name === "memory_search") {
21
108
  return Type.Object({
22
109
  scope: Type.String({ description: "Scope alias or canonical scope id. Use current, global, or all when appropriate." }),
23
110
  query: Type.String({ description: "Search query." }),
24
111
  limit: Type.Optional(Type.Number({ description: "Maximum result count." }))
25
- });
112
+ }, { additionalProperties: false });
26
113
  }
27
114
  if (name === "memory_locate") {
28
115
  return Type.Object({
29
116
  query: Type.String({ description: "What to locate in memory." }),
30
117
  limit: Type.Optional(Type.Number({ description: "Maximum candidate count." })),
31
118
  active_scope: Type.Optional(Type.String({ description: "Optional active scope hint." }))
32
- });
119
+ }, { additionalProperties: false });
33
120
  }
34
121
  if (name === "memory_register") {
35
122
  return Type.Object({
@@ -38,24 +125,34 @@ const schemaFor = (name) => {
38
125
  content: contentSchema,
39
126
  visibility: Type.String({ description: "private, pair, team, room, global, public, or sealed." }),
40
127
  sensitivity: Type.String({ description: "normal, sensitive, or secret." }),
41
- evidence_event_ids: Type.Array(Type.String(), { description: "Event ids that justify the memory." }),
42
128
  source_type: Type.String({ description: "Source label for the registered memory." }),
43
- confidence: Type.Optional(Type.Number({ description: "Confidence from 0 to 1." }))
44
- });
129
+ confidence: Type.Optional(Type.Number({ description: "Confidence from 0 to 1." })),
130
+ memory_id: Type.Optional(Type.String({ description: "Existing memory chain id for a new revision." }))
131
+ }, { additionalProperties: false });
45
132
  }
46
133
  if (name === "memory_summarize") {
47
134
  return Type.Object({
48
135
  scope: Type.String({ description: "Scope alias or canonical scope id to summarize." }),
49
136
  horizon: Type.Optional(Type.Number({ description: "Approximate number of recent memories to include." }))
50
- });
137
+ }, { additionalProperties: false });
51
138
  }
52
- return Type.Object({
53
- scope: Type.String({ description: "Scope alias or canonical scope id for the tombstone." }),
54
- event_ids: Type.Array(Type.String(), { description: "Memory event ids to tombstone." }),
55
- reason: Type.Optional(Type.String({ description: "Why these memories should be forgotten." }))
56
- });
139
+ if (name === "memory_promote") {
140
+ return Type.Object({
141
+ scope: Type.String({ description: "Scope alias or canonical scope id the memory belongs to." }),
142
+ memory_id: Type.String({ description: "Current memory chain head to promote." }),
143
+ reason: Type.Optional(Type.String({ description: "Why this memory is being promoted." }))
144
+ }, { additionalProperties: false });
145
+ }
146
+ if (name === "memory_forget") {
147
+ return Type.Object({
148
+ scope: Type.String({ description: "Scope alias or canonical scope id for the tombstone." }),
149
+ event_ids: Type.Array(Type.String(), { description: "Memory event ids to tombstone." }),
150
+ reason: Type.Optional(Type.String({ description: "Why these memories should be forgotten." }))
151
+ }, { additionalProperties: false });
152
+ }
153
+ throw new Error(`Unknown Pi memory tool: ${name}`);
57
154
  };
58
- export const createPiMemoryTools = (input) => createMemoryToolDescriptors(input.memory.kernel).map((descriptor) => defineTool({
155
+ export const createPiMemoryTools = (input) => createMemoryToolDescriptors(input.memory.kernel, { mode: input.mode ?? "awake" }).map((descriptor) => defineTool({
59
156
  name: descriptor.modelName,
60
157
  label: descriptor.label,
61
158
  description: descriptor.description,
@@ -63,8 +160,31 @@ export const createPiMemoryTools = (input) => createMemoryToolDescriptors(input.
63
160
  promptGuidelines: descriptor.promptGuidelines,
64
161
  parameters: schemaFor(descriptor.modelName),
65
162
  async execute(_toolCallId, params) {
66
- const result = await descriptor.invoke(params, input.contextRef.current ?? fallbackContext(input.agentId));
67
- return textContent(result);
163
+ const startedAt = Date.now();
164
+ try {
165
+ requireExactModelArguments(descriptor.modelName, params);
166
+ const result = await descriptor.invoke(params, requireTrustedContext(input.agentId, input.contextRef));
167
+ input.contextRef.observeTool?.({
168
+ contentCount: result.content.length,
169
+ decision: result.decision,
170
+ durationMs: Date.now() - startedAt,
171
+ kind: "memory",
172
+ name: descriptor.modelName,
173
+ redactionCount: result.content.reduce((total, content) => total + content.redactions.length, 0),
174
+ status: "completed"
175
+ });
176
+ return textContent(result);
177
+ }
178
+ catch (error) {
179
+ input.contextRef.observeTool?.({
180
+ durationMs: Date.now() - startedAt,
181
+ error: error instanceof Error ? error.message : String(error),
182
+ kind: "memory",
183
+ name: descriptor.modelName,
184
+ status: "failed"
185
+ });
186
+ throw error;
187
+ }
68
188
  }
69
189
  }));
70
190
  export const piMemoryToolNames = (tools) => tools.map((tool) => tool.name);
@@ -0,0 +1,13 @@
1
+ import { AuthStorage, ModelRegistry } from "@earendil-works/pi-coding-agent";
2
+ import type { HarnessModelSpec } from "../core/types.js";
3
+ export interface PiModelRegistryOptions {
4
+ model?: {
5
+ auth?: HarnessModelSpec["auth"];
6
+ endpoint?: HarnessModelSpec["endpoint"];
7
+ provider: string;
8
+ name: string;
9
+ };
10
+ modelsPath?: string;
11
+ }
12
+ export declare const createPiModelRegistry: (authStorage: AuthStorage, options: PiModelRegistryOptions) => ModelRegistry;
13
+ //# sourceMappingURL=modelRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modelRegistry.d.ts","sourceRoot":"","sources":["../../src/pi/modelRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,aAAa,EACd,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIzD,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAChC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACxC,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,qBAAqB,GAChC,aAAa,WAAW,EACxB,SAAS,sBAAsB,KAC9B,aAkBF,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { ModelRegistry } from "@earendil-works/pi-coding-agent";
2
+ import { resolvePiHarnessModel } from "./modelConfig.js";
3
+ export const createPiModelRegistry = (authStorage, options) => {
4
+ const registry = options.modelsPath
5
+ ? ModelRegistry.create(authStorage, options.modelsPath)
6
+ : ModelRegistry.inMemory(authStorage);
7
+ if (!options.modelsPath && options.model?.endpoint) {
8
+ const { modelsConfig } = resolvePiHarnessModel(options.model);
9
+ for (const [provider, config] of Object.entries(modelsConfig.providers)) {
10
+ registry.registerProvider(provider, {
11
+ api: config.api,
12
+ apiKey: config.apiKey,
13
+ baseUrl: config.baseUrl,
14
+ models: config.models
15
+ });
16
+ }
17
+ }
18
+ return registry;
19
+ };
@@ -0,0 +1,46 @@
1
+ import type { AgentHandle, AgentStatus, WakeEvent, WakeResult } from "../core/types.js";
2
+ import { type PiMemoryToolContextRef } from "./memoryTools.js";
3
+ import { stampTurnInputSubmitted, stampTurnOutputCompleted } from "./turnCausal.js";
4
+ import { type WakeAcceptanceStoreLike } from "./wakeAcceptance.js";
5
+ import { persistPiTurnTrace, type PiTurnTraceModel } from "./turnTrace.js";
6
+ import { type PiRawTrainingCaptureOptions, type PiRawTrainingCaptureRef } from "./rawTrainingCapture.js";
7
+ import { type PiWorldToolContextRef } from "./worldNudge.js";
8
+ import { type PiWorldTrajectoryIdentity } from "./worldTrajectory.js";
9
+ import { type PiNativeSessionCreator, type PiSession, type PiSessionCreator, type PiSessionLike, type PiWakeEnvironmentContextRef } from "./piAgentWakeSupport.js";
10
+ import { type MemoryRuntime } from "@noopolis/mneme";
11
+ export type { PiSession, PiSessionLike, PiSessionCreator, PiNativeSessionCreator } from "./piAgentWakeSupport.js";
12
+ export type WakeAcceptanceInput = {
13
+ runWake?: typeof stampTurnInputSubmitted;
14
+ completeTurn?: typeof stampTurnOutputCompleted;
15
+ traceTurn?: typeof persistPiTurnTrace;
16
+ createWakeAcceptance?: (runtimeHomePath: string, agentId: string) => WakeAcceptanceStoreLike;
17
+ };
18
+ export declare class PiAgentHandle implements AgentHandle {
19
+ readonly id: string;
20
+ private readonly session;
21
+ private readonly createSession;
22
+ private readonly runtimeHomePath;
23
+ private readonly traceModel;
24
+ private readonly memory?;
25
+ private readonly memoryToolContext?;
26
+ private readonly worldToolContext?;
27
+ private readonly rawTrainingCaptureRef?;
28
+ private readonly rawTrainingCaptureOptions?;
29
+ private readonly worldTrajectoryIdentity?;
30
+ private readonly piSessionForRawCapture?;
31
+ private readonly wakeEnvironmentContext?;
32
+ private state;
33
+ private lastWakeAt;
34
+ private lastError;
35
+ private readonly wakeDeliveryQueue;
36
+ private readonly stampTurnInputSubmitted;
37
+ private readonly stampTurnOutputCompleted;
38
+ private readonly persistTrace;
39
+ constructor(id: string, session: PiSession, createSession: PiNativeSessionCreator, runtimeHomePath: string, traceModel: PiTurnTraceModel, memory?: MemoryRuntime, memoryToolContext?: PiMemoryToolContextRef, dependencies?: WakeAcceptanceInput, worldToolContext?: PiWorldToolContextRef, rawTrainingCaptureRef?: PiRawTrainingCaptureRef, rawTrainingCaptureOptions?: PiRawTrainingCaptureOptions, worldTrajectoryIdentity?: PiWorldTrajectoryIdentity, rawTrainingCaptureSession?: PiSession, wakeEnvironmentContext?: PiWakeEnvironmentContextRef);
40
+ constructor(id: string, session: PiSessionLike, createSession: PiSessionCreator, runtimeHomePath: string, traceModel: PiTurnTraceModel, memory?: MemoryRuntime, memoryToolContext?: PiMemoryToolContextRef, dependencies?: WakeAcceptanceInput, worldToolContext?: PiWorldToolContextRef, rawTrainingCaptureRef?: never, rawTrainingCaptureOptions?: never, worldTrajectoryIdentity?: PiWorldTrajectoryIdentity, rawTrainingCaptureSession?: never, wakeEnvironmentContext?: PiWakeEnvironmentContextRef);
41
+ wake(event: WakeEvent): Promise<WakeResult>;
42
+ private runWake;
43
+ status(): AgentStatus;
44
+ stop(): Promise<void>;
45
+ }
46
+ //# sourceMappingURL=piAgentHandle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"piAgentHandle.d.ts","sourceRoot":"","sources":["../../src/pi/piAgentHandle.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,351 @@
1
+ import { createTrustedPiMemoryToolContext } from "./memoryTools.js";
2
+ import { formatWakePrompt, preserveModelFacingWakeIdentity } from "./prompts.js";
3
+ import { stampTurnInputSubmitted, stampTurnOutputCompleted } from "./turnCausal.js";
4
+ import { WakeAcceptanceStore } from "./wakeAcceptance.js";
5
+ import { persistPiTurnTrace } from "./turnTrace.js";
6
+ import { formatDreamPrompt } from "./wakeModes.js";
7
+ import { createPiRawTrainingCapture } from "./rawTrainingCapture.js";
8
+ import { formatWorldWakePrompt, worldWakeContext } from "./worldNudge.js";
9
+ import { createPiWorldTrajectoryCapture } from "./worldTrajectory.js";
10
+ import { cloneWakeEvent, disposePiSession, persistPiTurnArtifacts, PiWakeDeliveryQueue, selectPiSessionForWake, subscribeToPiTurnEvents } from "./piAgentWakeSupport.js";
11
+ import { readMemoryContext } from "@noopolis/mneme";
12
+ export class PiAgentHandle {
13
+ id;
14
+ session;
15
+ createSession;
16
+ runtimeHomePath;
17
+ traceModel;
18
+ memory;
19
+ memoryToolContext;
20
+ worldToolContext;
21
+ rawTrainingCaptureRef;
22
+ rawTrainingCaptureOptions;
23
+ worldTrajectoryIdentity;
24
+ piSessionForRawCapture;
25
+ wakeEnvironmentContext;
26
+ state = "idle";
27
+ lastWakeAt;
28
+ lastError;
29
+ wakeDeliveryQueue;
30
+ stampTurnInputSubmitted;
31
+ stampTurnOutputCompleted;
32
+ persistTrace;
33
+ constructor(id, session, createSession, runtimeHomePath, traceModel, memory, memoryToolContext, dependencies = {}, worldToolContext, rawTrainingCaptureRef, rawTrainingCaptureOptions, worldTrajectoryIdentity, piSessionForRawCapture, wakeEnvironmentContext) {
34
+ this.id = id;
35
+ this.session = session;
36
+ this.createSession = createSession;
37
+ this.runtimeHomePath = runtimeHomePath;
38
+ this.traceModel = traceModel;
39
+ this.memory = memory;
40
+ this.memoryToolContext = memoryToolContext;
41
+ this.worldToolContext = worldToolContext;
42
+ this.rawTrainingCaptureRef = rawTrainingCaptureRef;
43
+ this.rawTrainingCaptureOptions = rawTrainingCaptureOptions;
44
+ this.worldTrajectoryIdentity = worldTrajectoryIdentity;
45
+ this.piSessionForRawCapture = piSessionForRawCapture;
46
+ this.wakeEnvironmentContext = wakeEnvironmentContext;
47
+ this.stampTurnInputSubmitted = dependencies.runWake ?? stampTurnInputSubmitted;
48
+ this.stampTurnOutputCompleted = dependencies.completeTurn ?? stampTurnOutputCompleted;
49
+ this.persistTrace = dependencies.traceTurn ?? persistPiTurnTrace;
50
+ const wakeAcceptance = dependencies.createWakeAcceptance?.(runtimeHomePath, id) ??
51
+ new WakeAcceptanceStore(runtimeHomePath, id);
52
+ this.wakeDeliveryQueue = new PiWakeDeliveryQueue(id, wakeAcceptance);
53
+ }
54
+ async wake(event) {
55
+ const wakeEvent = cloneWakeEvent(event);
56
+ return this.wakeDeliveryQueue.wake(wakeEvent, (queuedEvent, transition) => this.runWake(queuedEvent, transition));
57
+ }
58
+ async runWake(event, transitionToInvoking) {
59
+ const startedAt = new Date();
60
+ const startedAtMs = Date.now();
61
+ const chunks = [];
62
+ const tools = [];
63
+ let enginePromptMs;
64
+ let memoryPrepare;
65
+ let selectedSession;
66
+ let rawTrainingCapture;
67
+ let rawTrainingCapturePersistAttempted = false;
68
+ let unsubscribe;
69
+ let stage = "select_session";
70
+ let prepared;
71
+ this.state = "running";
72
+ this.lastWakeAt = new Date().toISOString();
73
+ this.lastError = undefined;
74
+ const memoryContext = readMemoryContext({
75
+ kind: event.kind,
76
+ id: event.id,
77
+ from: event.from,
78
+ text: event.text,
79
+ context: event.context
80
+ });
81
+ const worldContext = this.worldToolContext === undefined
82
+ ? undefined
83
+ : worldWakeContext(event);
84
+ const safeWakeText = worldContext === undefined
85
+ ? event.text
86
+ : event.kind === "message" && event.delivery !== undefined && event.transportText !== undefined
87
+ ? `${formatWorldWakePrompt(worldContext)}\n\n${formatWakePrompt(event)}`
88
+ : formatWorldWakePrompt(worldContext);
89
+ const worldTrajectory = worldContext?.decisionToken === undefined
90
+ ? undefined
91
+ : createPiWorldTrajectoryCapture();
92
+ const request = {
93
+ eventId: /^(simfile|moltnet|mneme|daimon):.+$/u.test(event.id) ? event.id : `daimon:${event.id}`,
94
+ kind: event.kind,
95
+ text: safeWakeText,
96
+ from: event.from,
97
+ context: memoryContext
98
+ };
99
+ let promptText = worldContext === undefined
100
+ ? formatWakePrompt(event)
101
+ : safeWakeText;
102
+ try {
103
+ if (this.wakeEnvironmentContext !== undefined) {
104
+ this.wakeEnvironmentContext.current = event.id;
105
+ this.wakeEnvironmentContext.spokeFor = undefined;
106
+ }
107
+ if (this.worldToolContext !== undefined) {
108
+ this.worldToolContext.current = worldContext;
109
+ }
110
+ selectedSession = await selectPiSessionForWake({
111
+ agentId: this.id,
112
+ createSession: this.createSession,
113
+ event,
114
+ memoryContext,
115
+ runtimeHomePath: this.runtimeHomePath,
116
+ session: this.session
117
+ });
118
+ if (this.rawTrainingCaptureRef !== undefined
119
+ && this.rawTrainingCaptureOptions !== undefined) {
120
+ rawTrainingCapture = createPiRawTrainingCapture();
121
+ this.rawTrainingCaptureRef.current = rawTrainingCapture;
122
+ }
123
+ unsubscribe = subscribeToPiTurnEvents({
124
+ chunks,
125
+ rawTrainingCapture,
126
+ session: selectedSession.session,
127
+ tools,
128
+ worldTrajectory
129
+ });
130
+ if (this.memory !== undefined) {
131
+ stage = "memory_prepare";
132
+ const memoryStartedAt = Date.now();
133
+ try {
134
+ prepared = await this.memory.prepareTurn(request);
135
+ }
136
+ catch (error) {
137
+ memoryPrepare = {
138
+ durationMs: Date.now() - memoryStartedAt,
139
+ status: "failed"
140
+ };
141
+ throw error;
142
+ }
143
+ memoryPrepare = {
144
+ durationMs: Date.now() - memoryStartedAt,
145
+ prepared,
146
+ status: "completed"
147
+ };
148
+ promptText = preserveModelFacingWakeIdentity(prepared.promptText, event, request.eventId);
149
+ if (this.memoryToolContext !== undefined) {
150
+ this.memoryToolContext.observeTool = (toolEvent) => tools.push(toolEvent);
151
+ this.memoryToolContext.current = createTrustedPiMemoryToolContext({
152
+ agentId: this.id,
153
+ memory: this.memory,
154
+ mode: selectedSession.mode,
155
+ prepared,
156
+ threadId: selectedSession.threadId,
157
+ wakeId: event.id
158
+ });
159
+ }
160
+ }
161
+ if (selectedSession.mode === "dream") {
162
+ promptText = formatDreamPrompt(promptText, selectedSession.threadId);
163
+ }
164
+ stage = "causal_input";
165
+ const turnInput = await this.stampTurnInputSubmitted({
166
+ agentId: this.id,
167
+ event,
168
+ prepared,
169
+ promptText,
170
+ runtimeHomePath: this.runtimeHomePath
171
+ });
172
+ stage = "invoking";
173
+ if (transitionToInvoking !== undefined) {
174
+ await transitionToInvoking();
175
+ }
176
+ stage = "engine_prompt";
177
+ const engineStartedAt = Date.now();
178
+ selectedSession.session.bindWake?.(event);
179
+ await selectedSession.session.prompt(promptText, { expandPromptTemplates: false });
180
+ enginePromptMs = Date.now() - engineStartedAt;
181
+ this.state = "idle";
182
+ const outputText = chunks.join("\n").trim();
183
+ stage = "causal_output";
184
+ await this.stampTurnOutputCompleted({
185
+ agentId: this.id,
186
+ causeEventId: turnInput.event_id,
187
+ outputText,
188
+ runtimeHomePath: this.runtimeHomePath,
189
+ turnId: event.id
190
+ });
191
+ if (this.memory !== undefined && prepared !== undefined) {
192
+ await this.memory.recordTurn({ principal: prepared.principal, prompt: prepared.packet, request, recall: prepared.recall, result: "completed", outputText, toolEvents: tools })
193
+ .catch((recordError) => { this.lastError = `memory record failed: ${recordError instanceof Error ? recordError.message : String(recordError)}`; });
194
+ }
195
+ await this.persistTrace({
196
+ agentId: this.id,
197
+ enginePromptMs,
198
+ event,
199
+ memoryPrepare,
200
+ memoryEnabled: Boolean(this.memory),
201
+ model: this.traceModel,
202
+ outputText,
203
+ promptText,
204
+ runtimeHomePath: this.runtimeHomePath,
205
+ session: selectedSession,
206
+ startedAt,
207
+ status: "completed",
208
+ tools,
209
+ totalMs: Date.now() - startedAtMs,
210
+ ...(this.worldToolContext === undefined
211
+ ? {}
212
+ : { worldContextBound: worldContext !== undefined })
213
+ });
214
+ if (rawTrainingCapture !== undefined
215
+ && this.rawTrainingCaptureOptions !== undefined
216
+ && this.piSessionForRawCapture !== undefined) {
217
+ rawTrainingCapturePersistAttempted = true;
218
+ }
219
+ await persistPiTurnArtifacts({
220
+ agentId: this.id,
221
+ completedAt: new Date(),
222
+ model: this.traceModel,
223
+ piSessionForRawCapture: this.piSessionForRawCapture,
224
+ promptText,
225
+ rawTrainingCapture,
226
+ rawTrainingCaptureOptions: this.rawTrainingCaptureOptions,
227
+ runtimeHomePath: this.runtimeHomePath,
228
+ startedAt,
229
+ status: "completed",
230
+ totalMs: Date.now() - startedAtMs,
231
+ turnId: event.id,
232
+ worldContext,
233
+ worldTrajectory,
234
+ worldTrajectoryIdentity: this.worldTrajectoryIdentity
235
+ });
236
+ // An agent with a mounted `moltnet_send` tool has exactly one
237
+ // legitimate publication channel; its terminal text is always a
238
+ // private note to the runtime — whether it spoke, stayed silent, or
239
+ // narrated a failure back as its reply — never the bridge's
240
+ // terminal-text fallback (moltnet/internal/bridge/daimon/
241
+ // receipt_tracker.go), which is reserved for agents with no send tool
242
+ // at all. `outputText` itself stays intact for the turn trace and
243
+ // memory record above.
244
+ const hasSendCapability = this.wakeEnvironmentContext?.hasSendCapability === true;
245
+ return {
246
+ agentId: this.id,
247
+ text: hasSendCapability ? "" : outputText,
248
+ durationMs: Date.now() - startedAtMs
249
+ };
250
+ }
251
+ catch (error) {
252
+ this.state = "failed";
253
+ const message = error instanceof Error ? error.message : String(error);
254
+ this.lastError = message;
255
+ if (memoryPrepare === undefined && this.memory !== undefined) {
256
+ memoryPrepare = {
257
+ prepared,
258
+ status: "failed"
259
+ };
260
+ }
261
+ await this.persistTrace({
262
+ agentId: this.id,
263
+ enginePromptMs,
264
+ error: {
265
+ message,
266
+ stage
267
+ },
268
+ event,
269
+ memoryPrepare,
270
+ memoryEnabled: Boolean(this.memory),
271
+ model: this.traceModel,
272
+ outputText: chunks.join("\n").trim(),
273
+ promptText,
274
+ runtimeHomePath: this.runtimeHomePath,
275
+ session: selectedSession,
276
+ startedAt,
277
+ status: "failed",
278
+ tools,
279
+ totalMs: Date.now() - startedAtMs,
280
+ ...(this.worldToolContext === undefined
281
+ ? {}
282
+ : { worldContextBound: worldContext !== undefined })
283
+ }).catch(() => undefined);
284
+ if (this.memory !== undefined && prepared !== undefined) {
285
+ await this.memory.recordTurn({ principal: prepared.principal, prompt: prepared.packet, request, recall: prepared.recall, result: "failed", error: message, outputText: chunks.join("\n").trim(), toolEvents: tools }).catch(() => undefined);
286
+ }
287
+ const persistRawCapture = !rawTrainingCapturePersistAttempted
288
+ && selectedSession !== undefined;
289
+ if (persistRawCapture && rawTrainingCapture !== undefined) {
290
+ rawTrainingCapturePersistAttempted = true;
291
+ }
292
+ await persistPiTurnArtifacts({
293
+ agentId: this.id,
294
+ completedAt: new Date(),
295
+ model: this.traceModel,
296
+ piSessionForRawCapture: persistRawCapture
297
+ ? this.piSessionForRawCapture
298
+ : undefined,
299
+ promptText,
300
+ rawTrainingCapture: persistRawCapture ? rawTrainingCapture : undefined,
301
+ rawTrainingCaptureOptions: persistRawCapture
302
+ ? this.rawTrainingCaptureOptions
303
+ : undefined,
304
+ runtimeHomePath: this.runtimeHomePath,
305
+ startedAt,
306
+ status: "failed",
307
+ totalMs: Date.now() - startedAtMs,
308
+ turnId: event.id,
309
+ worldContext,
310
+ worldTrajectory,
311
+ worldTrajectoryIdentity: this.worldTrajectoryIdentity
312
+ });
313
+ throw error;
314
+ }
315
+ finally {
316
+ selectedSession?.session.bindWake?.();
317
+ if (this.wakeEnvironmentContext !== undefined) {
318
+ this.wakeEnvironmentContext.current = undefined;
319
+ this.wakeEnvironmentContext.spokeFor = undefined;
320
+ }
321
+ if (this.memoryToolContext !== undefined) {
322
+ this.memoryToolContext.current = undefined;
323
+ this.memoryToolContext.observeTool = undefined;
324
+ }
325
+ if (this.worldToolContext) {
326
+ this.worldToolContext.current = undefined;
327
+ }
328
+ if (this.rawTrainingCaptureRef) {
329
+ this.rawTrainingCaptureRef.current = undefined;
330
+ }
331
+ unsubscribe?.();
332
+ if (selectedSession?.disposeAfterWake) {
333
+ selectedSession.session.dispose();
334
+ }
335
+ }
336
+ }
337
+ status() {
338
+ return {
339
+ agentId: this.id,
340
+ state: this.state,
341
+ lastWakeAt: this.lastWakeAt,
342
+ lastError: this.lastError
343
+ };
344
+ }
345
+ async stop() {
346
+ // CLI-backed sessions may own a process group, while native Pi remains
347
+ // source-compatible through the synchronous dispose() hook.
348
+ await disposePiSession(this.session);
349
+ this.state = "stopped";
350
+ }
351
+ }