@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,269 @@
1
+ import { redactCredentialText } from "../core/credentialRedaction.js";
2
+ import { headUtf8, tailUtf8 } from "../runtime/toolResultSpill.js";
3
+ import { decodeCodexTurnUsage } from "./codexHeadlessResult.js";
4
+ import { terminateChild, trackCliChild } from "./cliProcess.js";
5
+ /** Maximum assistant reply bytes retained from stdout. */
6
+ export const CLI_ENGINE_MAX_OUTPUT_BYTES = 64 * 1024;
7
+ /** Diagnostic bytes retained from stderr for a failed child: its head and its tail together. */
8
+ export const CLI_ENGINE_MAX_DIAGNOSTIC_BYTES = 768;
9
+ const CLI_ENGINE_FAILURE_SCAN_CHARS = 256;
10
+ /**
11
+ * Which bound or condition failed a wake, carried on the error object itself.
12
+ *
13
+ * The caller needs this to label the usage row a failed wake still owes the
14
+ * ledger, and matching on the message text would make that label depend on
15
+ * prose. The tag is a non-enumerable symbol property, so it never widens the
16
+ * error's serialized form and never reaches a diagnostic string.
17
+ */
18
+ const CLI_CHILD_FAILURE_REASON = Symbol("daimon.cliChildFailureReason");
19
+ export const tagCliChildFailure = (error, reason) => {
20
+ if (!(error instanceof Error))
21
+ return error;
22
+ // Labelling a failure must never become a second failure: a frozen or sealed
23
+ // error simply goes untagged and its row reads `unknown`.
24
+ try {
25
+ Object.defineProperty(error, CLI_CHILD_FAILURE_REASON, { configurable: true, enumerable: false, value: reason, writable: true });
26
+ }
27
+ catch { /* the reason is advisory; the failure it describes is not */ }
28
+ return error;
29
+ };
30
+ export const cliChildFailureReason = (error) => error instanceof Error
31
+ ? error[CLI_CHILD_FAILURE_REASON]
32
+ : undefined;
33
+ const redactChildOutput = (value, secretValues) => {
34
+ return redactCredentialText(value, secretValues, CLI_ENGINE_MAX_OUTPUT_BYTES);
35
+ };
36
+ /**
37
+ * One bounded window over a failed child's own output: its head AND its tail,
38
+ * with an explicit marker naming the bytes elided between them.
39
+ *
40
+ * A pure tail is the wrong end for the process this exists for. A worker that
41
+ * dies early prints its error first and then echoes its own input, so the tail
42
+ * is the echo: one live brokered turn reported 512 bytes of its own prompt
43
+ * read back, with the actual error already off the front and discarded. Both
44
+ * ends cost the same window, and the marker is the one oversized tool results
45
+ * already use (`toolResultSpill.ts`), so a reader meets one shape everywhere.
46
+ *
47
+ * The marker is paid for out of the same budget — it is sized against the
48
+ * largest count it could carry — so the result never exceeds `maxBytes`, and
49
+ * output that fits is returned byte-identical with no marker at all.
50
+ */
51
+ export const boundedDiagnosticWindow = (value, maxBytes) => {
52
+ const total = Buffer.byteLength(value, "utf8");
53
+ if (total <= maxBytes)
54
+ return value;
55
+ const budget = Math.max(0, maxBytes - Buffer.byteLength(elisionMarker(total), "utf8"));
56
+ const head = headUtf8(value, Math.floor(budget / 2));
57
+ const tail = tailUtf8(value, budget - Buffer.byteLength(head, "utf8"));
58
+ const elided = total - Buffer.byteLength(head, "utf8") - Buffer.byteLength(tail, "utf8");
59
+ return `${head}${elisionMarker(elided)}${tail}`;
60
+ };
61
+ const elisionMarker = (elided) => `[… ${elided} bytes elided …]`;
62
+ const childDiagnostic = (stdout, stderr, secretValues) => {
63
+ const output = stderr.trim().length > 0 ? stderr : stdout;
64
+ const redacted = redactCredentialText(output, secretValues, Number.MAX_SAFE_INTEGER).trim();
65
+ const bounded = boundedDiagnosticWindow(redacted, CLI_ENGINE_MAX_DIAGNOSTIC_BYTES).trim();
66
+ return bounded.length > 0 ? `: ${bounded}` : "";
67
+ };
68
+ export const readChild = (child, timeoutMs, secretValues, options = {}) => new Promise((resolve, reject) => {
69
+ trackCliChild(child);
70
+ const stdout = [];
71
+ let stdoutTail = Buffer.alloc(0);
72
+ let droppingStdoutLine = false;
73
+ // Both ends of stderr, retained as it streams: the head frozen once it is
74
+ // full, the tail sliding. A single sliding tail dropped the head at capture
75
+ // time, which is where the cause of an early death lives — no later window
76
+ // can recover what was never kept.
77
+ let stderrHead = Buffer.alloc(0);
78
+ let stderrTail = Buffer.alloc(0);
79
+ let stderrBytes = 0;
80
+ let stdoutBytes = 0;
81
+ let stdoutRemainder = Buffer.alloc(0);
82
+ let droppingNdjsonLine = false;
83
+ let ndjsonCalls = 0;
84
+ let settled = false;
85
+ let cleanupStarted = false;
86
+ let classifiedFailure;
87
+ let failureScanTail = "";
88
+ /**
89
+ * Each retained end carries its reported share PLUS one whole secret, which
90
+ * is the invariant that keeps exact redaction exact: a secret that reaches
91
+ * the reported window can extend at most its own length past that window's
92
+ * cut, so retaining that much more on each side means the redactor always
93
+ * sees the secret whole. Halving one shared budget instead broke it — a
94
+ * 2000-byte secret was cut in the middle and its tail fragment
95
+ * (`…qqq-secret-end`) reached the diagnostic verbatim.
96
+ */
97
+ const stderrSecretAllowance = Math.max(0, ...secretValues.map((secret) => Buffer.byteLength(secret, "utf8")));
98
+ const stderrHeadBytes = Math.floor(CLI_ENGINE_MAX_DIAGNOSTIC_BYTES / 2) + stderrSecretAllowance;
99
+ const stderrTailBytes = CLI_ENGINE_MAX_DIAGNOSTIC_BYTES - Math.floor(CLI_ENGINE_MAX_DIAGNOSTIC_BYTES / 2) + stderrSecretAllowance;
100
+ const settle = (action) => {
101
+ if (settled)
102
+ return;
103
+ settled = true;
104
+ if (timer !== undefined)
105
+ clearTimeout(timer);
106
+ action();
107
+ };
108
+ const abort = (error) => {
109
+ if (cleanupStarted)
110
+ return;
111
+ cleanupStarted = true;
112
+ void terminateChild(child).then(() => settle(() => reject(error)), (cleanupError) => settle(() => reject(cleanupError instanceof Error ? cleanupError : error)));
113
+ };
114
+ const classifyFailure = (chunk) => {
115
+ if (classifiedFailure !== undefined || options.failureClassifier === undefined)
116
+ return;
117
+ const diagnostic = `${failureScanTail}${chunk.toString("utf8")}`;
118
+ classifiedFailure = options.failureClassifier(diagnostic);
119
+ failureScanTail = diagnostic.slice(-CLI_ENGINE_FAILURE_SCAN_CHARS);
120
+ };
121
+ const retainStdout = (chunk) => {
122
+ const value = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
123
+ classifyFailure(value);
124
+ if (options.retainNdjson !== undefined) {
125
+ let incoming = value;
126
+ if (droppingNdjsonLine) {
127
+ const newline = incoming.indexOf(0x0a);
128
+ if (newline < 0)
129
+ return;
130
+ droppingNdjsonLine = false;
131
+ incoming = incoming.subarray(newline + 1);
132
+ }
133
+ stdoutRemainder = Buffer.concat([stdoutRemainder, incoming]);
134
+ let newline;
135
+ while ((newline = stdoutRemainder.indexOf(0x0a)) >= 0) {
136
+ const line = stdoutRemainder.subarray(0, newline).toString("utf8");
137
+ stdoutRemainder = Buffer.from(stdoutRemainder.subarray(newline + 1));
138
+ let frame;
139
+ try {
140
+ const parsed = JSON.parse(line);
141
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed))
142
+ frame = parsed;
143
+ }
144
+ catch { /* decoder reports malformed retained protocol lines */ }
145
+ if (frame === undefined) {
146
+ stdout.push(Buffer.from(`${line}\n`));
147
+ continue;
148
+ }
149
+ if (frame.type === "thread.started" && typeof frame.thread_id === "string") {
150
+ options.onCodexThreadStarted?.(frame.thread_id);
151
+ continue;
152
+ }
153
+ const item = typeof frame.item === "object" && frame.item !== null && !Array.isArray(frame.item) ? frame.item : undefined;
154
+ if (frame.type === "item.completed" && (item?.type === "command_execution" || item?.type === "mcp_tool_call")) {
155
+ ndjsonCalls += 1;
156
+ stdout.push(Buffer.from(`${JSON.stringify({ type: frame.type, item: { type: item.type } })}\n`));
157
+ }
158
+ else if ((frame.type === "item.completed" && item?.type === "agent_message") || frame.type === "turn.completed" || frame.type === "turn.failed") {
159
+ if (frame.type === "turn.completed") {
160
+ // Decode and publish first, kill second: the ceiling breach is the
161
+ // one path guaranteed to destroy this stream, so the accounting
162
+ // has to leave the reader before the child does.
163
+ const usage = decodeCodexTurnUsage(frame, ndjsonCalls);
164
+ options.onCodexTurnCompleted?.(usage);
165
+ if (options.codexTokenCeiling !== undefined && usage !== undefined && usage.total >= options.codexTokenCeiling) {
166
+ abort(tagCliChildFailure(new Error(`Codex wake exceeded its ${options.codexTokenCeiling}-token per-wake ceiling (turn usage ${usage.total} tokens)`), "token_ceiling"));
167
+ return;
168
+ }
169
+ }
170
+ stdout.push(Buffer.from(`${line}\n`));
171
+ }
172
+ stdoutBytes = stdout.reduce((total, part) => total + part.length, 0);
173
+ if (stdoutBytes > CLI_ENGINE_MAX_OUTPUT_BYTES) {
174
+ abort(tagCliChildFailure(new Error(`CLI engine output exceeded ${CLI_ENGINE_MAX_OUTPUT_BYTES} bytes`), "output_limit"));
175
+ return;
176
+ }
177
+ }
178
+ if (stdoutRemainder.length > CLI_ENGINE_MAX_OUTPUT_BYTES) {
179
+ const prefix = stdoutRemainder.subarray(0, Math.min(stdoutRemainder.length, 4096)).toString("utf8");
180
+ if (/"type"\s*:\s*"item\.completed"/u.test(prefix)
181
+ && !/"type"\s*:\s*"agent_message"/u.test(prefix)) {
182
+ const toolType = prefix.match(/"type"\s*:\s*"(command_execution|mcp_tool_call)"/u)?.[1];
183
+ if (toolType !== undefined) {
184
+ ndjsonCalls += 1;
185
+ stdout.push(Buffer.from(`${JSON.stringify({ type: "item.completed", item: { type: toolType } })}\n`));
186
+ }
187
+ stdoutRemainder = Buffer.alloc(0);
188
+ droppingNdjsonLine = true;
189
+ }
190
+ else
191
+ abort(tagCliChildFailure(new Error(`CLI engine output exceeded ${CLI_ENGINE_MAX_OUTPUT_BYTES} bytes`), "output_limit"));
192
+ }
193
+ return;
194
+ }
195
+ if (options.retainStdoutTail === true) {
196
+ let remainder = value;
197
+ if (droppingStdoutLine) {
198
+ const newline = remainder.indexOf(0x0a);
199
+ if (newline < 0)
200
+ return;
201
+ droppingStdoutLine = false;
202
+ remainder = remainder.subarray(newline + 1);
203
+ }
204
+ const combined = Buffer.concat([stdoutTail, remainder]);
205
+ if (combined.length <= CLI_ENGINE_MAX_OUTPUT_BYTES) {
206
+ stdoutTail = combined;
207
+ return;
208
+ }
209
+ const overflow = combined.length - CLI_ENGINE_MAX_OUTPUT_BYTES;
210
+ if (combined[overflow - 1] === 0x0a) {
211
+ stdoutTail = Buffer.from(combined.subarray(overflow));
212
+ return;
213
+ }
214
+ const newline = combined.indexOf(0x0a, overflow);
215
+ stdoutTail = newline < 0 ? Buffer.alloc(0) : Buffer.from(combined.subarray(newline + 1));
216
+ droppingStdoutLine = newline < 0;
217
+ return;
218
+ }
219
+ stdoutBytes += value.length;
220
+ if (stdoutBytes > CLI_ENGINE_MAX_OUTPUT_BYTES) {
221
+ abort(tagCliChildFailure(new Error(`CLI engine output exceeded ${CLI_ENGINE_MAX_OUTPUT_BYTES} bytes`), "output_limit"));
222
+ return;
223
+ }
224
+ stdout.push(value);
225
+ };
226
+ const retainStderrWindow = (chunk) => {
227
+ const value = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
228
+ classifyFailure(value);
229
+ stderrBytes += value.length;
230
+ if (stderrHead.length < stderrHeadBytes)
231
+ stderrHead = Buffer.concat([stderrHead, value.subarray(0, stderrHeadBytes - stderrHead.length)]);
232
+ if (value.length >= stderrTailBytes) {
233
+ stderrTail = Buffer.from(value.subarray(value.length - stderrTailBytes));
234
+ return;
235
+ }
236
+ const overflow = stderrTail.length + value.length - stderrTailBytes;
237
+ stderrTail = Buffer.concat([overflow > 0 ? stderrTail.subarray(overflow) : stderrTail, value]);
238
+ };
239
+ /**
240
+ * The retained stderr, reassembled exactly.
241
+ *
242
+ * Nothing was elided while the whole output fitted the budget, and then the
243
+ * two ends overlap: they tile the stream, so dropping the overlap from the
244
+ * tail rebuilds it byte-identically. Above the budget the ends are joined by
245
+ * the marker, which names how many bytes never reached this process at all.
246
+ */
247
+ const retainedStderr = () => {
248
+ const elided = stderrBytes - stderrHead.length - stderrTail.length;
249
+ if (elided <= 0)
250
+ return Buffer.concat([stderrHead, stderrTail.subarray(stderrHead.length + stderrTail.length - stderrBytes)]).toString("utf8");
251
+ return `${stderrHead.toString("utf8")}${elisionMarker(elided)}${stderrTail.toString("utf8")}`;
252
+ };
253
+ child.stdout?.on("data", retainStdout);
254
+ child.stderr?.on("data", retainStderrWindow);
255
+ const timer = timeoutMs === undefined ? undefined : setTimeout(() => abort(tagCliChildFailure(new Error(options.timeoutErrorMessage ?? "CLI engine timed out"), "wake_timeout")), timeoutMs);
256
+ child.once("error", abort);
257
+ child.once("close", (code, signal) => {
258
+ if (cleanupStarted)
259
+ return;
260
+ if (options.retainNdjson !== undefined && stdoutRemainder.length > 0)
261
+ stdout.push(stdoutRemainder);
262
+ const retainedStdout = options.retainStdoutTail === true ? stdoutTail : Buffer.concat(stdout);
263
+ if (code === 0) {
264
+ settle(() => resolve(redactChildOutput(retainedStdout.toString("utf8"), secretValues).trim()));
265
+ return;
266
+ }
267
+ settle(() => reject(tagCliChildFailure(classifiedFailure ?? new Error(`CLI engine exited ${code ?? signal}${childDiagnostic(retainedStdout.toString("utf8"), retainedStderr(), secretValues)}`), "engine_exit")));
268
+ });
269
+ });
@@ -0,0 +1,16 @@
1
+ import { type CliEngineKind } from "./cliSession.js";
2
+ export interface EngineRunResult {
3
+ readonly durationMs: number;
4
+ readonly outputChars: number;
5
+ readonly promptChars: number;
6
+ readonly text: string;
7
+ }
8
+ export declare const runEngineDetailed: (engine: CliEngineKind, prompt: string, paths: {
9
+ readonly workspacePath: string;
10
+ readonly runtimeHomePath?: string;
11
+ }) => Promise<EngineRunResult>;
12
+ export declare const runEngine: (engine: CliEngineKind, prompt: string, paths: {
13
+ readonly workspacePath: string;
14
+ readonly runtimeHomePath?: string;
15
+ }) => Promise<string>;
16
+ //# sourceMappingURL=cliEngineRun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliEngineRun.d.ts","sourceRoot":"","sources":["../../src/pi/cliEngineRun.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,KAAK,aAAa,EAAyB,MAAM,iBAAiB,CAAC;AAEzH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,aAAa,EACrB,QAAQ,MAAM,EACd,OAAO;IAAE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,KAC3E,OAAO,CAAC,eAAe,CAsBzB,CAAC;AAEF,eAAO,MAAM,SAAS,GACpB,QAAQ,aAAa,EACrB,QAAQ,MAAM,EACd,OAAO;IAAE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,KAC3E,OAAO,CAAC,MAAM,CAA0D,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { AGY_MAX_TOOL_TURNS, createCliSessionFactory } from "./cliSession.js";
2
+ export const runEngineDetailed = async (engine, prompt, paths) => {
3
+ const startedAt = Date.now();
4
+ const options = engine === "agy"
5
+ ? { engine, maxToolTurns: AGY_MAX_TOOL_TURNS, timeoutMs: 180_000 }
6
+ : { engine };
7
+ const { session } = await createCliSessionFactory(options)({
8
+ cwd: paths.workspacePath,
9
+ runtimeHomePath: paths.runtimeHomePath
10
+ });
11
+ let text = "";
12
+ const unsubscribe = session.subscribe((event) => {
13
+ if (event.type !== "turn_end")
14
+ return;
15
+ if (!("content" in event.message))
16
+ return;
17
+ text = Array.isArray(event.message.content)
18
+ ? event.message.content.filter((entry) => entry.type === "text").map((entry) => entry.text).join("")
19
+ : event.message.content;
20
+ });
21
+ await session.prompt(prompt);
22
+ unsubscribe();
23
+ session.dispose();
24
+ await session.disposeAsync?.();
25
+ return { durationMs: Date.now() - startedAt, outputChars: text.length, promptChars: prompt.length, text };
26
+ };
27
+ export const runEngine = async (engine, prompt, paths) => (await runEngineDetailed(engine, prompt, paths)).text;
@@ -0,0 +1,55 @@
1
+ import { type ChildProcess } from "node:child_process";
2
+ import type { CliEngineOptions, CliSessionInput } from "./cliSession.js";
3
+ export declare const GROK_STRICT_SANDBOX_PROFILE = "strict";
4
+ export declare const renderGrokSandboxArgs: (commandArgs: readonly string[] | undefined, profile: string) => string[];
5
+ /**
6
+ * Codex's `--json` stream is unconditional: it is the only output shape that
7
+ * carries `turn.completed.usage`, and an unmetered Codex turn is one whose
8
+ * subscription cost is invisible. The guarded arguments make this Daimon's
9
+ * security and metering boundary rather than a caller-controlled format.
10
+ *
11
+ * `model`/`reasoningEffort` come from parsed, bounded organization-runtime
12
+ * config, but are rendered defensively anyway: each is emitted as a single
13
+ * `--flag=value` argv token (never a bare flag followed by a separate value
14
+ * token), so a value that itself looks like a flag (e.g. `--sandbox`) can
15
+ * never be parsed as a second, independent argument — the same shape already
16
+ * used below for `mcp_servers.daimon.url=`. Omitting both fields leaves Codex's
17
+ * model defaults unchanged.
18
+ *
19
+ * The per-wake MCP server is always enabled and required. Otherwise Codex can
20
+ * continue a normal turn with only built-in tools after MCP startup fails.
21
+ * Subscription apps and installed plugins are not caller-declared tools.
22
+ * Disable their discovery per invocation, including with strict config: the
23
+ * CLI's defaults can otherwise add them even when user config is ignored.
24
+ */
25
+ export declare const renderCodexArgs: (options: Pick<CliEngineOptions, "commandArgs" | "model" | "reasoningEffort" | "codexSandbox" | "codexSandboxProtectedPaths" | "codexSandboxReadablePaths">, cwd: string, endpoint: string | undefined, sandbox?: string) => string[];
26
+ export declare const renderCodexPermissionProfile: (profileName: string, protectedPaths: readonly string[], readablePaths?: readonly string[], workspacePath?: string) => string;
27
+ /**
28
+ * AGY's headless invocation.
29
+ *
30
+ * `--output-format stream-json` is unconditional: it is the only shape that
31
+ * carries `result.usage`, and an AGY turn that is not metered is an AGY turn
32
+ * whose subscription cost is invisible (see `agyHeadlessResult.ts`).
33
+ *
34
+ * `--dangerously-skip-permissions` is required for tools to work at all. AGY's
35
+ * default headless permission mode is `request-review`, and there is no
36
+ * reviewer inside a container, so a tool call can never be approved without it;
37
+ * the live probe that proved AGY's MCP tool calling ran with exactly this flag
38
+ * and reported `permission_mode: always-proceed`. Every Daimon CLI agent mounts
39
+ * at least the protected bash tool (`piHarness.ts`), so there is no AGY wake
40
+ * for which this is unnecessary and no conditional worth forking behavior over.
41
+ *
42
+ * SECURITY: the flag also auto-approves AGY's own ~50 built-in tools —
43
+ * `run_command`, `write_to_file`, the browser tools — none of which Daimon
44
+ * mediates. Inside the container that is the exposure Codex already has
45
+ * (`--sandbox danger-full-access`), but unlike Grok there is no kernel-enforced
46
+ * per-agent profile confining it to this agent's own workspace and runtime
47
+ * home. `DAIMON_AGY_SANDBOX=1` opts into AGY's own terminal-restricting
48
+ * sandbox; it is off by default only because its interaction with the MCP
49
+ * transport could not be verified without spending the operator's subscription
50
+ * quota, and shipping an unverified default that silently disables every tool
51
+ * would be worse than shipping the exposure with this note on it.
52
+ */
53
+ export declare const renderAgyArgs: (options: Pick<CliEngineOptions, "commandArgs" | "timeoutMs">, prompt: string, sandbox?: boolean) => string[];
54
+ export declare const spawnEngine: (options: CliEngineOptions, prompt: string, input: CliSessionInput, endpoint: string | undefined, wakeId?: string) => ChildProcess;
55
+ //# sourceMappingURL=cliEngineSpawn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliEngineSpawn.d.ts","sourceRoot":"","sources":["../../src/pi/cliEngineSpawn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAK9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEzE,eAAO,MAAM,2BAA2B,WAAW,CAAC;AAEpD,eAAO,MAAM,qBAAqB,GAChC,aAAa,SAAS,MAAM,EAAE,GAAG,SAAS,EAC1C,SAAS,MAAM,KACd,MAAM,EAAuE,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,IAAI,CAAC,gBAAgB,EAAE,aAAa,GAAG,OAAO,GAAG,iBAAiB,GAAG,cAAc,GAAG,4BAA4B,GAAG,2BAA2B,CAAC,EAC1J,KAAK,MAAM,EACX,UAAU,MAAM,GAAG,SAAS,EAC5B,UAAS,MAA+F,KACvG,MAAM,EAyBR,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,aAAa,MAAM,EACnB,gBAAgB,SAAS,MAAM,EAAE,EACjC,gBAAe,SAAS,MAAM,EAAO,EACrC,gBAAgB,MAAM,KACrB,MAUF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,aAAa,GACxB,SAAS,IAAI,CAAC,gBAAgB,EAAE,aAAa,GAAG,WAAW,CAAC,EAC5D,QAAQ,MAAM,EACd,UAAS,OAAgD,KACxD,MAAM,EAOR,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,SAAS,gBAAgB,EACzB,QAAQ,MAAM,EACd,OAAO,eAAe,EACtB,UAAU,MAAM,GAAG,SAAS,EAC5B,SAAS,MAAM,KACd,YAyBF,CAAC"}
@@ -0,0 +1,164 @@
1
+ import { spawn } from "node:child_process";
2
+ import { trackCliChild } from "./cliProcess.js";
3
+ import { cliChildEnvironment } from "./cliEnvironment.js";
4
+ import { codexFilesystemRules } from "./codexFilesystemRules.js";
5
+ export const GROK_STRICT_SANDBOX_PROFILE = "strict";
6
+ export const renderGrokSandboxArgs = (commandArgs, profile) => [...assertSafeGrokCommandArgs(commandArgs), "--sandbox", profile];
7
+ /**
8
+ * Codex's `--json` stream is unconditional: it is the only output shape that
9
+ * carries `turn.completed.usage`, and an unmetered Codex turn is one whose
10
+ * subscription cost is invisible. The guarded arguments make this Daimon's
11
+ * security and metering boundary rather than a caller-controlled format.
12
+ *
13
+ * `model`/`reasoningEffort` come from parsed, bounded organization-runtime
14
+ * config, but are rendered defensively anyway: each is emitted as a single
15
+ * `--flag=value` argv token (never a bare flag followed by a separate value
16
+ * token), so a value that itself looks like a flag (e.g. `--sandbox`) can
17
+ * never be parsed as a second, independent argument — the same shape already
18
+ * used below for `mcp_servers.daimon.url=`. Omitting both fields leaves Codex's
19
+ * model defaults unchanged.
20
+ *
21
+ * The per-wake MCP server is always enabled and required. Otherwise Codex can
22
+ * continue a normal turn with only built-in tools after MCP startup fails.
23
+ * Subscription apps and installed plugins are not caller-declared tools.
24
+ * Disable their discovery per invocation, including with strict config: the
25
+ * CLI's defaults can otherwise add them even when user config is ignored.
26
+ */
27
+ export const renderCodexArgs = (options, cwd, endpoint, sandbox = options.codexSandbox?.mode ?? process.env.DAIMON_CODEX_SANDBOX ?? "danger-full-access") => {
28
+ const strictPolicy = options.codexSandbox;
29
+ if (strictPolicy !== undefined && (strictPolicy.mode !== "workspace-write" || strictPolicy.networkAccess !== false || strictPolicy.webSearch !== "disabled" || Object.keys(strictPolicy).length !== 3)) {
30
+ throw new Error("Codex sandbox policy is Daimon-owned and must be workspace-write with network and web search disabled");
31
+ }
32
+ const effectiveSandbox = strictPolicy?.mode ?? sandbox;
33
+ const profileName = "daimon-strict";
34
+ const policyArgs = strictPolicy === undefined ? [] : [
35
+ "--ignore-user-config",
36
+ "--ignore-rules",
37
+ "--strict-config",
38
+ "-c", "web_search=\"disabled\"",
39
+ "-c", `default_permissions=${JSON.stringify(profileName)}`,
40
+ "-c", renderCodexPermissionProfile(profileName, options.codexSandboxProtectedPaths ?? [], options.codexSandboxReadablePaths ?? [], cwd),
41
+ "-c", "approval_policy=\"never\"",
42
+ "-c", `mcp_servers={daimon={url=\"${endpoint}\",enabled=true,default_tools_approval_mode=\"approve\"}}`
43
+ ];
44
+ return [...assertSafeCodexCommandArgs(options.commandArgs, strictPolicy !== undefined), "exec", ...(strictPolicy === undefined ? ["--sandbox", effectiveSandbox] : []), ...policyArgs, "--skip-git-repo-check",
45
+ ...(options.model === undefined ? [] : [`--model=${options.model}`]),
46
+ ...(options.reasoningEffort === undefined ? [] : ["-c", `model_reasoning_effort=${options.reasoningEffort}`]),
47
+ "--color", "never", "--json", "-C", cwd,
48
+ "-c", `mcp_servers.daimon.url=${endpoint}`,
49
+ "-c", "features.apps=false", "-c", "features.plugins=false",
50
+ "-c", "mcp_servers.daimon.enabled=true",
51
+ "-c", "mcp_servers.daimon.required=true", "-"];
52
+ };
53
+ export const renderCodexPermissionProfile = (profileName, protectedPaths, readablePaths = [], workspacePath) => {
54
+ const filesystem = {
55
+ ":workspace_roots": { ".": "write" },
56
+ ...codexFilesystemRules(protectedPaths, readablePaths, workspacePath)
57
+ };
58
+ return `permissions=${tomlInline({ [profileName]: {
59
+ extends: ":workspace",
60
+ filesystem,
61
+ network: { enabled: false }
62
+ } })}`;
63
+ };
64
+ /**
65
+ * AGY's headless invocation.
66
+ *
67
+ * `--output-format stream-json` is unconditional: it is the only shape that
68
+ * carries `result.usage`, and an AGY turn that is not metered is an AGY turn
69
+ * whose subscription cost is invisible (see `agyHeadlessResult.ts`).
70
+ *
71
+ * `--dangerously-skip-permissions` is required for tools to work at all. AGY's
72
+ * default headless permission mode is `request-review`, and there is no
73
+ * reviewer inside a container, so a tool call can never be approved without it;
74
+ * the live probe that proved AGY's MCP tool calling ran with exactly this flag
75
+ * and reported `permission_mode: always-proceed`. Every Daimon CLI agent mounts
76
+ * at least the protected bash tool (`piHarness.ts`), so there is no AGY wake
77
+ * for which this is unnecessary and no conditional worth forking behavior over.
78
+ *
79
+ * SECURITY: the flag also auto-approves AGY's own ~50 built-in tools —
80
+ * `run_command`, `write_to_file`, the browser tools — none of which Daimon
81
+ * mediates. Inside the container that is the exposure Codex already has
82
+ * (`--sandbox danger-full-access`), but unlike Grok there is no kernel-enforced
83
+ * per-agent profile confining it to this agent's own workspace and runtime
84
+ * home. `DAIMON_AGY_SANDBOX=1` opts into AGY's own terminal-restricting
85
+ * sandbox; it is off by default only because its interaction with the MCP
86
+ * transport could not be verified without spending the operator's subscription
87
+ * quota, and shipping an unverified default that silently disables every tool
88
+ * would be worse than shipping the exposure with this note on it.
89
+ */
90
+ export const renderAgyArgs = (options, prompt, sandbox = process.env.DAIMON_AGY_SANDBOX === "1") => [
91
+ ...assertSafeAgyCommandArgs(options.commandArgs),
92
+ "--print", prompt,
93
+ "--output-format", "stream-json",
94
+ "--dangerously-skip-permissions",
95
+ ...(sandbox ? ["--sandbox"] : []),
96
+ ...(options.timeoutMs === undefined ? [] : ["--print-timeout", `${options.timeoutMs}ms`])
97
+ ];
98
+ export const spawnEngine = (options, prompt, input, endpoint, wakeId) => {
99
+ const command = options.command ?? options.engine;
100
+ const env = cliChildEnvironment([
101
+ ...(options.redactedEnvironmentNames ?? []),
102
+ ...(input.daimonSecretEnvironmentNames ?? [])
103
+ ], input.runtimeHomePath, {
104
+ dbusSessionBusAddress: options.engine === "agy" ? options.dbusSessionBusAddress : undefined,
105
+ engine: options.engine,
106
+ executablePath: options.command,
107
+ engineHomePath: options.engineHomePath,
108
+ wakeId
109
+ });
110
+ if (options.engine === "codex") {
111
+ const child = trackCliChild(spawn(command, renderCodexArgs(options, input.cwd, endpoint), { cwd: input.cwd, env, detached: process.platform !== "win32", stdio: ["pipe", "pipe", "pipe"] }));
112
+ child.stdin.on("error", () => undefined);
113
+ child.stdin.write(prompt);
114
+ child.stdin.end();
115
+ return child;
116
+ }
117
+ // Production supplies a Daimon-owned custom profile whose enforcement and
118
+ // explicit realm/peer denies are verified before every Grok process.
119
+ const args = options.engine === "grok"
120
+ ? [...renderGrokSandboxArgs(options.commandArgs, options.grokSandboxProfile ?? GROK_STRICT_SANDBOX_PROFILE), "--always-approve", "--no-subagents", "--single", prompt, "--no-memory", "--disable-web-search", "--cwd", input.cwd,
121
+ "--output-format", "streaming-messages-json"]
122
+ : renderAgyArgs(options, prompt);
123
+ return trackCliChild(spawn(command, args, { cwd: input.cwd, env, detached: process.platform !== "win32", stdio: ["ignore", "pipe", "pipe"] }));
124
+ };
125
+ /**
126
+ * AGY's output format, permission mode, sandbox, and session continuity are
127
+ * Daimon-owned, exactly as Grok's sandbox and approval flags are. A caller
128
+ * cannot re-open the permission boundary, silence the metering stream, or turn
129
+ * a per-wake cold process into a resumed conversation through `commandArgs`.
130
+ */
131
+ const assertSafeAgyCommandArgs = (args) => {
132
+ const values = args ?? [];
133
+ if (values.some((value) => /^(?:--dangerously-skip-permissions|--sandbox|--output-format|--print|--prompt|--prompt-interactive|--mode|--continue|--conversation|-p|-i|-c)(?:=|$)/u.test(value))) {
134
+ throw new Error("AGY security-boundary arguments are Daimon-owned");
135
+ }
136
+ return values;
137
+ };
138
+ /** Caller arguments cannot reopen Codex's sandbox, output, cwd, or config boundary. */
139
+ const assertSafeCodexCommandArgs = (args, strictPolicy = false) => {
140
+ const values = args ?? [];
141
+ const pattern = /^(?:--json|--sandbox|--dangerously-bypass-approvals-and-sandbox|--output-last-message|--config|--ignore-user-config|--ignore-rules|--skip-git-repo-check|--color|--cd|--enable|-c|-C)(?:=|$)/u;
142
+ const strictPattern = /^(?:--strict-config|--profile|-p|-P|--permissions-profile|--enable|--disable|--add-dir|--search)(?:=|$)|^(?:default_permissions|permissions)(?:=|\.)/u;
143
+ if (values.some((value) => pattern.test(value) || (strictPolicy && strictPattern.test(value)))) {
144
+ throw new Error("Codex security-boundary arguments are Daimon-owned");
145
+ }
146
+ return values;
147
+ };
148
+ const assertSafeGrokCommandArgs = (args) => {
149
+ const values = args ?? [];
150
+ if (values.some((value) => /^(?:--sandbox|--always-approve|--permission-mode|--leader-socket)(?:=|$)/u.test(value))) {
151
+ throw new Error("Grok security-boundary arguments are Daimon-owned");
152
+ }
153
+ return values;
154
+ };
155
+ function tomlInline(value) {
156
+ if (typeof value === "string")
157
+ return JSON.stringify(value);
158
+ if (typeof value === "boolean")
159
+ return value ? "true" : "false";
160
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
161
+ return `{${Object.entries(value).map(([key, entry]) => `${JSON.stringify(key)}=${tomlInline(entry)}`).join(",")}}`;
162
+ }
163
+ throw new Error("unsupported Codex permission profile value");
164
+ }
@@ -0,0 +1,12 @@
1
+ type CliEnvironmentIntent = Readonly<{
2
+ dbusSessionBusAddress?: string;
3
+ engine?: "codex" | "grok" | "agy";
4
+ executablePath?: string;
5
+ engineHomePath?: string;
6
+ wakeId?: string;
7
+ }>;
8
+ export declare const DAIMON_WAKE_ID_ENV: "DAIMON_WAKE_ID";
9
+ /** Build a positive child environment; agent CLIs never inherit host secrets. */
10
+ export declare const cliChildEnvironment: (_redactedNames: readonly string[], runtimeHomePath?: string, intent?: CliEnvironmentIntent) => NodeJS.ProcessEnv;
11
+ export {};
12
+ //# sourceMappingURL=cliEnvironment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliEnvironment.d.ts","sourceRoot":"","sources":["../../src/pi/cliEnvironment.ts"],"names":[],"mappings":"AAEA,KAAK,oBAAoB,GAAG,QAAQ,CAAC;IACnC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAG,gBAAyB,CAAC;AAE5D,iFAAiF;AACjF,eAAO,MAAM,mBAAmB,GAC9B,gBAAgB,SAAS,MAAM,EAAE,EAAE,kBAAkB,MAAM,EAAE,SAAQ,oBAAyB,KAC7F,MAAM,CAAC,UA2BT,CAAC"}
@@ -0,0 +1,32 @@
1
+ import path from "node:path";
2
+ export const DAIMON_WAKE_ID_ENV = "DAIMON_WAKE_ID";
3
+ /** Build a positive child environment; agent CLIs never inherit host secrets. */
4
+ export const cliChildEnvironment = (_redactedNames, runtimeHomePath, intent = {}) => {
5
+ if (runtimeHomePath === undefined) {
6
+ // This legacy branch is only used by the standalone Pi helpers, which do
7
+ // not claim production organization-runtime isolation.
8
+ return { PATH: process.env.PATH, LANG: process.env.LANG ?? "C", LC_ALL: process.env.LC_ALL ?? "C", TZ: process.env.TZ ?? "UTC" };
9
+ }
10
+ const engine = intent.engine;
11
+ const engineVariable = engine === "codex" ? "CODEX_HOME" : engine === "grok" ? "GROK_HOME" : engine === "agy" ? "ANTIGRAVITY_CLI_HOME" : undefined;
12
+ const engineHome = intent.engineHomePath;
13
+ const keyringBus = engine === "agy" ? localSecretServiceBus(intent.dbusSessionBusAddress) : undefined;
14
+ return {
15
+ // The executable is pinned absolutely. PATH remains only for a trusted
16
+ // interpreter in a local shebang (and never selects the engine itself).
17
+ PATH: intent.executablePath === undefined ? process.env.PATH : `${path.dirname(intent.executablePath)}${path.delimiter}${path.dirname(process.execPath)}`,
18
+ LANG: process.env.LANG ?? "C",
19
+ LC_ALL: process.env.LC_ALL ?? "C",
20
+ TZ: process.env.TZ ?? "UTC",
21
+ HOME: runtimeHomePath,
22
+ XDG_CONFIG_HOME: `${runtimeHomePath}/.config`,
23
+ XDG_DATA_HOME: `${runtimeHomePath}/.local/share`,
24
+ XDG_STATE_HOME: `${runtimeHomePath}/.local/state`,
25
+ XDG_CACHE_HOME: `${runtimeHomePath}/.cache`,
26
+ TMPDIR: `${runtimeHomePath}/.tmp`,
27
+ ...(engineVariable === undefined || engineHome === undefined ? {} : { [engineVariable]: engineHome }),
28
+ ...(keyringBus === undefined ? {} : { DBUS_SESSION_BUS_ADDRESS: keyringBus }),
29
+ ...(intent.wakeId === undefined ? {} : { [DAIMON_WAKE_ID_ENV]: intent.wakeId })
30
+ };
31
+ };
32
+ const localSecretServiceBus = (value) => value !== undefined && /^unix:(?:path|abstract)=[^;,\r\n]+$/u.test(value) ? value : undefined;