@noopolis/daimon 0.1.2 → 0.2.1

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 (422) hide show
  1. package/README.md +275 -51
  2. package/dist/contracts/attentionContract.d.ts +142 -0
  3. package/dist/contracts/attentionContract.d.ts.map +1 -0
  4. package/dist/contracts/attentionContract.js +21 -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/grokBrokerTaskClock.d.ts +18 -0
  9. package/dist/contracts/grokBrokerTaskClock.d.ts.map +1 -0
  10. package/dist/contracts/grokBrokerTaskClock.js +16 -0
  11. package/dist/contracts/grokWorkerContract.d.ts +74 -0
  12. package/dist/contracts/grokWorkerContract.d.ts.map +1 -0
  13. package/dist/contracts/grokWorkerContract.js +88 -0
  14. package/dist/contracts/organizationRuntimeContract.d.ts +841 -0
  15. package/dist/contracts/organizationRuntimeContract.d.ts.map +1 -0
  16. package/dist/contracts/organizationRuntimeContract.js +123 -0
  17. package/dist/contracts/runtimeContractManifest.d.ts +1822 -0
  18. package/dist/contracts/runtimeContractManifest.d.ts.map +1 -0
  19. package/dist/contracts/runtimeContractManifest.js +206 -0
  20. package/dist/contracts/shellEnvironmentPolicy.d.ts +3 -0
  21. package/dist/contracts/shellEnvironmentPolicy.d.ts.map +1 -0
  22. package/dist/contracts/shellEnvironmentPolicy.js +5 -0
  23. package/dist/contracts/wakeMomentContract.d.ts +61 -0
  24. package/dist/contracts/wakeMomentContract.d.ts.map +1 -0
  25. package/dist/contracts/wakeMomentContract.js +27 -0
  26. package/dist/core/credentialRedaction.d.ts +4 -0
  27. package/dist/core/credentialRedaction.d.ts.map +1 -0
  28. package/dist/core/credentialRedaction.js +28 -0
  29. package/dist/core/types.d.ts +2 -0
  30. package/dist/core/types.d.ts.map +1 -1
  31. package/dist/examples/jungianPlayAgent.d.ts +1 -0
  32. package/dist/examples/jungianPlayAgent.d.ts.map +1 -1
  33. package/dist/examples/jungianPlayAgent.js +6 -2
  34. package/dist/mcp/toolServer.d.ts +19 -2
  35. package/dist/mcp/toolServer.d.ts.map +1 -1
  36. package/dist/mcp/toolServer.js +57 -17
  37. package/dist/observability/causalEvents.d.ts +6 -6
  38. package/dist/observability/causalEvents.d.ts.map +1 -1
  39. package/dist/observability/causalEvents.js +107 -19
  40. package/dist/observability/orgObserver.d.ts.map +1 -1
  41. package/dist/observability/orgObserver.js +3 -3
  42. package/dist/pi/agyHeadlessResult.d.ts +60 -0
  43. package/dist/pi/agyHeadlessResult.d.ts.map +1 -0
  44. package/dist/pi/agyHeadlessResult.js +95 -0
  45. package/dist/pi/cliChildOutput.d.ts +67 -0
  46. package/dist/pi/cliChildOutput.d.ts.map +1 -0
  47. package/dist/pi/cliChildOutput.js +269 -0
  48. package/dist/pi/cliEngineRun.d.ts +16 -0
  49. package/dist/pi/cliEngineRun.d.ts.map +1 -0
  50. package/dist/pi/cliEngineRun.js +27 -0
  51. package/dist/pi/cliEngineSpawn.d.ts +55 -0
  52. package/dist/pi/cliEngineSpawn.d.ts.map +1 -0
  53. package/dist/pi/cliEngineSpawn.js +169 -0
  54. package/dist/pi/cliEnvironment.d.ts +12 -0
  55. package/dist/pi/cliEnvironment.d.ts.map +1 -0
  56. package/dist/pi/cliEnvironment.js +34 -0
  57. package/dist/pi/cliMcpRegistration.d.ts +61 -0
  58. package/dist/pi/cliMcpRegistration.d.ts.map +1 -0
  59. package/dist/pi/cliMcpRegistration.js +75 -0
  60. package/dist/pi/cliProcess.d.ts +7 -0
  61. package/dist/pi/cliProcess.d.ts.map +1 -0
  62. package/dist/pi/cliProcess.js +132 -0
  63. package/dist/pi/cliSession.d.ts +86 -24
  64. package/dist/pi/cliSession.d.ts.map +1 -1
  65. package/dist/pi/cliSession.js +251 -173
  66. package/dist/pi/cliSessionMcp.d.ts +9 -0
  67. package/dist/pi/cliSessionMcp.d.ts.map +1 -0
  68. package/dist/pi/cliSessionMcp.js +80 -0
  69. package/dist/pi/cliTurnMetering.d.ts +60 -0
  70. package/dist/pi/cliTurnMetering.d.ts.map +1 -0
  71. package/dist/pi/cliTurnMetering.js +60 -0
  72. package/dist/pi/codexFilesystemRules.d.ts +3 -0
  73. package/dist/pi/codexFilesystemRules.d.ts.map +1 -0
  74. package/dist/pi/codexFilesystemRules.js +28 -0
  75. package/dist/pi/codexHeadlessResult.d.ts +68 -0
  76. package/dist/pi/codexHeadlessResult.d.ts.map +1 -0
  77. package/dist/pi/codexHeadlessResult.js +122 -0
  78. package/dist/pi/codexRolloutUsage.d.ts +95 -0
  79. package/dist/pi/codexRolloutUsage.d.ts.map +1 -0
  80. package/dist/pi/codexRolloutUsage.js +221 -0
  81. package/dist/pi/engineTaskClock.d.ts +9 -0
  82. package/dist/pi/engineTaskClock.d.ts.map +1 -0
  83. package/dist/pi/engineTaskClock.js +28 -0
  84. package/dist/pi/engineWakeLimits.d.ts +39 -0
  85. package/dist/pi/engineWakeLimits.d.ts.map +1 -0
  86. package/dist/pi/engineWakeLimits.js +55 -0
  87. package/dist/pi/grokHeadlessResult.d.ts +36 -0
  88. package/dist/pi/grokHeadlessResult.d.ts.map +1 -0
  89. package/dist/pi/grokHeadlessResult.js +118 -0
  90. package/dist/pi/grokHomeMcpRegistration.d.ts +21 -0
  91. package/dist/pi/grokHomeMcpRegistration.d.ts.map +1 -0
  92. package/dist/pi/grokHomeMcpRegistration.js +58 -0
  93. package/dist/pi/grokSandbox.d.ts +11 -0
  94. package/dist/pi/grokSandbox.d.ts.map +1 -0
  95. package/dist/pi/grokSandbox.js +216 -0
  96. package/dist/pi/grokStreamUsage.d.ts +31 -0
  97. package/dist/pi/grokStreamUsage.d.ts.map +1 -0
  98. package/dist/pi/grokStreamUsage.js +51 -0
  99. package/dist/pi/memoryClock.d.ts +25 -0
  100. package/dist/pi/memoryClock.d.ts.map +1 -0
  101. package/dist/pi/memoryClock.js +18 -0
  102. package/dist/pi/piAgentHandle.d.ts +6 -3
  103. package/dist/pi/piAgentHandle.d.ts.map +1 -1
  104. package/dist/pi/piAgentHandle.js +42 -12
  105. package/dist/pi/piAgentWakeSupport.d.ts +35 -0
  106. package/dist/pi/piAgentWakeSupport.d.ts.map +1 -1
  107. package/dist/pi/piAgentWakeSupport.js +4 -0
  108. package/dist/pi/piHarness.d.ts +18 -3
  109. package/dist/pi/piHarness.d.ts.map +1 -1
  110. package/dist/pi/piHarness.js +83 -14
  111. package/dist/pi/prompts.d.ts +1 -0
  112. package/dist/pi/prompts.d.ts.map +1 -1
  113. package/dist/pi/prompts.js +24 -0
  114. package/dist/pi/taskClockProcess.d.ts +6 -0
  115. package/dist/pi/taskClockProcess.d.ts.map +1 -0
  116. package/dist/pi/taskClockProcess.js +8 -0
  117. package/dist/pi/turnCausal.d.ts +4 -2
  118. package/dist/pi/turnCausal.d.ts.map +1 -1
  119. package/dist/pi/turnCausal.js +4 -4
  120. package/dist/pi/turnTrace.d.ts.map +1 -1
  121. package/dist/pi/turnTrace.js +5 -8
  122. package/dist/pi/wakeAcceptance.d.ts +1 -1
  123. package/dist/pi/wakeAcceptance.d.ts.map +1 -1
  124. package/dist/pi/wakeAcceptance.js +2 -2
  125. package/dist/pi/worldTrajectory.d.ts +1 -1
  126. package/dist/pi/worldTrajectory.d.ts.map +1 -1
  127. package/dist/pi/worldTrajectory.js +3 -3
  128. package/dist/runtime/agySubscriptionBootstrap.d.ts +16 -0
  129. package/dist/runtime/agySubscriptionBootstrap.d.ts.map +1 -0
  130. package/dist/runtime/agySubscriptionBootstrap.js +80 -0
  131. package/dist/runtime/agySubscriptionRealm.d.ts +38 -0
  132. package/dist/runtime/agySubscriptionRealm.d.ts.map +1 -0
  133. package/dist/runtime/agySubscriptionRealm.js +242 -0
  134. package/dist/runtime/attention.d.ts +26 -0
  135. package/dist/runtime/attention.d.ts.map +1 -0
  136. package/dist/runtime/attention.js +49 -0
  137. package/dist/runtime/attentionDispatcher.d.ts +78 -0
  138. package/dist/runtime/attentionDispatcher.d.ts.map +1 -0
  139. package/dist/runtime/attentionDispatcher.js +365 -0
  140. package/dist/runtime/cli.d.ts +7 -0
  141. package/dist/runtime/cli.d.ts.map +1 -0
  142. package/dist/runtime/cli.js +256 -0
  143. package/dist/runtime/codexSandboxProjection.d.ts +17 -0
  144. package/dist/runtime/codexSandboxProjection.d.ts.map +1 -0
  145. package/dist/runtime/codexSandboxProjection.js +40 -0
  146. package/dist/runtime/contract-manifest.json +1 -0
  147. package/dist/runtime/contract-manifest.sha256 +1 -0
  148. package/dist/runtime/contractManifest.d.ts +8 -0
  149. package/dist/runtime/contractManifest.d.ts.map +1 -0
  150. package/dist/runtime/contractManifest.js +4 -0
  151. package/dist/runtime/engineBrokerCapabilities.d.ts +40 -0
  152. package/dist/runtime/engineBrokerCapabilities.d.ts.map +1 -0
  153. package/dist/runtime/engineBrokerCapabilities.js +69 -0
  154. package/dist/runtime/engineBrokerControlClient.d.ts +55 -0
  155. package/dist/runtime/engineBrokerControlClient.d.ts.map +1 -0
  156. package/dist/runtime/engineBrokerControlClient.js +228 -0
  157. package/dist/runtime/engineBrokerCredentialJournal.d.ts +12 -0
  158. package/dist/runtime/engineBrokerCredentialJournal.d.ts.map +1 -0
  159. package/dist/runtime/engineBrokerCredentialJournal.js +26 -0
  160. package/dist/runtime/engineBrokerInferenceProtocol.d.ts +53 -0
  161. package/dist/runtime/engineBrokerInferenceProtocol.d.ts.map +1 -0
  162. package/dist/runtime/engineBrokerInferenceProtocol.js +65 -0
  163. package/dist/runtime/engineBrokerMcpCallLog.d.ts +171 -0
  164. package/dist/runtime/engineBrokerMcpCallLog.d.ts.map +1 -0
  165. package/dist/runtime/engineBrokerMcpCallLog.js +231 -0
  166. package/dist/runtime/engineBrokerMcpFacade.d.ts +59 -0
  167. package/dist/runtime/engineBrokerMcpFacade.d.ts.map +1 -0
  168. package/dist/runtime/engineBrokerMcpFacade.js +346 -0
  169. package/dist/runtime/engineBrokerNativeClient.d.ts +52 -0
  170. package/dist/runtime/engineBrokerNativeClient.d.ts.map +1 -0
  171. package/dist/runtime/engineBrokerNativeClient.js +151 -0
  172. package/dist/runtime/engineBrokerProtocol.d.ts +167 -0
  173. package/dist/runtime/engineBrokerProtocol.d.ts.map +1 -0
  174. package/dist/runtime/engineBrokerProtocol.js +357 -0
  175. package/dist/runtime/engineBrokerSealLedger.d.ts +70 -0
  176. package/dist/runtime/engineBrokerSealLedger.d.ts.map +1 -0
  177. package/dist/runtime/engineBrokerSealLedger.js +132 -0
  178. package/dist/runtime/engineBrokerService.d.ts +43 -0
  179. package/dist/runtime/engineBrokerService.d.ts.map +1 -0
  180. package/dist/runtime/engineBrokerService.js +196 -0
  181. package/dist/runtime/engineBrokerServiceCli.d.ts +5 -0
  182. package/dist/runtime/engineBrokerServiceCli.d.ts.map +1 -0
  183. package/dist/runtime/engineBrokerServiceCli.js +32 -0
  184. package/dist/runtime/engineBrokerServiceConfig.d.ts +55 -0
  185. package/dist/runtime/engineBrokerServiceConfig.d.ts.map +1 -0
  186. package/dist/runtime/engineBrokerServiceConfig.js +130 -0
  187. package/dist/runtime/engineBrokerSingleflight.d.ts +13 -0
  188. package/dist/runtime/engineBrokerSingleflight.d.ts.map +1 -0
  189. package/dist/runtime/engineBrokerSingleflight.js +24 -0
  190. package/dist/runtime/engineBrokerTurnAccounting.d.ts +76 -0
  191. package/dist/runtime/engineBrokerTurnAccounting.d.ts.map +1 -0
  192. package/dist/runtime/engineBrokerTurnAccounting.js +108 -0
  193. package/dist/runtime/engineBrokerTurnRegistry.d.ts +57 -0
  194. package/dist/runtime/engineBrokerTurnRegistry.d.ts.map +1 -0
  195. package/dist/runtime/engineBrokerTurnRegistry.js +159 -0
  196. package/dist/runtime/engineDispatcher.d.ts +38 -0
  197. package/dist/runtime/engineDispatcher.d.ts.map +1 -0
  198. package/dist/runtime/engineDispatcher.js +228 -0
  199. package/dist/runtime/engineReadiness.d.ts +23 -0
  200. package/dist/runtime/engineReadiness.d.ts.map +1 -0
  201. package/dist/runtime/engineReadiness.js +222 -0
  202. package/dist/runtime/grokAuthenticationError.d.ts +8 -0
  203. package/dist/runtime/grokAuthenticationError.d.ts.map +1 -0
  204. package/dist/runtime/grokAuthenticationError.js +20 -0
  205. package/dist/runtime/grokBrokerCredentialAuthority.d.ts +23 -0
  206. package/dist/runtime/grokBrokerCredentialAuthority.d.ts.map +1 -0
  207. package/dist/runtime/grokBrokerCredentialAuthority.js +150 -0
  208. package/dist/runtime/grokBrokerCredentialReader.d.ts +6 -0
  209. package/dist/runtime/grokBrokerCredentialReader.d.ts.map +1 -0
  210. package/dist/runtime/grokBrokerCredentialReader.js +38 -0
  211. package/dist/runtime/grokBrokerModelPolicy.d.ts +23 -0
  212. package/dist/runtime/grokBrokerModelPolicy.d.ts.map +1 -0
  213. package/dist/runtime/grokBrokerModelPolicy.js +28 -0
  214. package/dist/runtime/grokBrokerProjection.d.ts +114 -0
  215. package/dist/runtime/grokBrokerProjection.d.ts.map +1 -0
  216. package/dist/runtime/grokBrokerProjection.js +101 -0
  217. package/dist/runtime/grokBrokerProviderClock.d.ts +26 -0
  218. package/dist/runtime/grokBrokerProviderClock.d.ts.map +1 -0
  219. package/dist/runtime/grokBrokerProviderClock.js +133 -0
  220. package/dist/runtime/grokBrokerProxy.d.ts +69 -0
  221. package/dist/runtime/grokBrokerProxy.d.ts.map +1 -0
  222. package/dist/runtime/grokBrokerProxy.js +326 -0
  223. package/dist/runtime/grokBrokerProxyJson.d.ts +10 -0
  224. package/dist/runtime/grokBrokerProxyJson.d.ts.map +1 -0
  225. package/dist/runtime/grokBrokerProxyJson.js +31 -0
  226. package/dist/runtime/grokBrokerProxyRequest.d.ts +30 -0
  227. package/dist/runtime/grokBrokerProxyRequest.d.ts.map +1 -0
  228. package/dist/runtime/grokBrokerProxyRequest.js +85 -0
  229. package/dist/runtime/grokBrokerRealmLease.d.ts +4 -0
  230. package/dist/runtime/grokBrokerRealmLease.d.ts.map +1 -0
  231. package/dist/runtime/grokBrokerRealmLease.js +33 -0
  232. package/dist/runtime/grokBrokerRefresh.d.ts +2 -0
  233. package/dist/runtime/grokBrokerRefresh.d.ts.map +1 -0
  234. package/dist/runtime/grokBrokerRefresh.js +15 -0
  235. package/dist/runtime/grokBrokerRunBudget.d.ts +20 -0
  236. package/dist/runtime/grokBrokerRunBudget.d.ts.map +1 -0
  237. package/dist/runtime/grokBrokerRunBudget.js +85 -0
  238. package/dist/runtime/grokBrokerSlot.d.ts +6 -0
  239. package/dist/runtime/grokBrokerSlot.d.ts.map +1 -0
  240. package/dist/runtime/grokBrokerSlot.js +21 -0
  241. package/dist/runtime/grokBrokerTaskClock.d.ts +32 -0
  242. package/dist/runtime/grokBrokerTaskClock.d.ts.map +1 -0
  243. package/dist/runtime/grokBrokerTaskClock.js +120 -0
  244. package/dist/runtime/grokBrokerTurnMeter.d.ts +180 -0
  245. package/dist/runtime/grokBrokerTurnMeter.d.ts.map +1 -0
  246. package/dist/runtime/grokBrokerTurnMeter.js +337 -0
  247. package/dist/runtime/grokBrokerWorkerConfig.d.ts +89 -0
  248. package/dist/runtime/grokBrokerWorkerConfig.d.ts.map +1 -0
  249. package/dist/runtime/grokBrokerWorkerConfig.js +154 -0
  250. package/dist/runtime/grokEngineBroker.d.ts +88 -0
  251. package/dist/runtime/grokEngineBroker.d.ts.map +1 -0
  252. package/dist/runtime/grokEngineBroker.js +202 -0
  253. package/dist/runtime/grokEngineBrokerLedger.d.ts +52 -0
  254. package/dist/runtime/grokEngineBrokerLedger.d.ts.map +1 -0
  255. package/dist/runtime/grokEngineBrokerLedger.js +114 -0
  256. package/dist/runtime/grokEngineBrokerMetering.d.ts +51 -0
  257. package/dist/runtime/grokEngineBrokerMetering.d.ts.map +1 -0
  258. package/dist/runtime/grokEngineBrokerMetering.js +34 -0
  259. package/dist/runtime/grokEngineBrokerTurn.d.ts +82 -0
  260. package/dist/runtime/grokEngineBrokerTurn.d.ts.map +1 -0
  261. package/dist/runtime/grokEngineBrokerTurn.js +348 -0
  262. package/dist/runtime/grokEngineBrokerTurnEnd.d.ts +88 -0
  263. package/dist/runtime/grokEngineBrokerTurnEnd.d.ts.map +1 -0
  264. package/dist/runtime/grokEngineBrokerTurnEnd.js +148 -0
  265. package/dist/runtime/grokInferenceClientConfig.d.ts +41 -0
  266. package/dist/runtime/grokInferenceClientConfig.d.ts.map +1 -0
  267. package/dist/runtime/grokInferenceClientConfig.js +62 -0
  268. package/dist/runtime/grokInferenceGrants.d.ts +77 -0
  269. package/dist/runtime/grokInferenceGrants.d.ts.map +1 -0
  270. package/dist/runtime/grokInferenceGrants.js +116 -0
  271. package/dist/runtime/grokInferenceProxy.d.ts +29 -0
  272. package/dist/runtime/grokInferenceProxy.d.ts.map +1 -0
  273. package/dist/runtime/grokInferenceProxy.js +85 -0
  274. package/dist/runtime/grokInferenceProxyRequest.d.ts +23 -0
  275. package/dist/runtime/grokInferenceProxyRequest.d.ts.map +1 -0
  276. package/dist/runtime/grokInferenceProxyRequest.js +63 -0
  277. package/dist/runtime/grokSlotPreflightReceipt.d.ts +70 -0
  278. package/dist/runtime/grokSlotPreflightReceipt.d.ts.map +1 -0
  279. package/dist/runtime/grokSlotPreflightReceipt.js +101 -0
  280. package/dist/runtime/grokSubscriptionRealm.d.ts +4 -0
  281. package/dist/runtime/grokSubscriptionRealm.d.ts.map +1 -0
  282. package/dist/runtime/grokSubscriptionRealm.js +435 -0
  283. package/dist/runtime/grokSubscriptionRealmTypes.d.ts +26 -0
  284. package/dist/runtime/grokSubscriptionRealmTypes.d.ts.map +1 -0
  285. package/dist/runtime/grokSubscriptionRealmTypes.js +1 -0
  286. package/dist/runtime/grokWorkerAttestation.d.ts +175 -0
  287. package/dist/runtime/grokWorkerAttestation.d.ts.map +1 -0
  288. package/dist/runtime/grokWorkerAttestation.js +266 -0
  289. package/dist/runtime/grokWorkerDenyPlacement.d.ts +80 -0
  290. package/dist/runtime/grokWorkerDenyPlacement.d.ts.map +1 -0
  291. package/dist/runtime/grokWorkerDenyPlacement.js +128 -0
  292. package/dist/runtime/grokWorkerHomeAttestation.d.ts +32 -0
  293. package/dist/runtime/grokWorkerHomeAttestation.d.ts.map +1 -0
  294. package/dist/runtime/grokWorkerHomeAttestation.js +75 -0
  295. package/dist/runtime/grokWorkerSandboxProfile.d.ts +27 -0
  296. package/dist/runtime/grokWorkerSandboxProfile.d.ts.map +1 -0
  297. package/dist/runtime/grokWorkerSandboxProfile.js +44 -0
  298. package/dist/runtime/grokWorkerTmpAttestation.d.ts +55 -0
  299. package/dist/runtime/grokWorkerTmpAttestation.d.ts.map +1 -0
  300. package/dist/runtime/grokWorkerTmpAttestation.js +63 -0
  301. package/dist/runtime/index.d.ts +31 -0
  302. package/dist/runtime/index.d.ts.map +1 -0
  303. package/dist/runtime/index.js +27 -0
  304. package/dist/runtime/inferenceUsageLedger.d.ts +38 -0
  305. package/dist/runtime/inferenceUsageLedger.d.ts.map +1 -0
  306. package/dist/runtime/inferenceUsageLedger.js +53 -0
  307. package/dist/runtime/mcpToolResult.d.ts +127 -0
  308. package/dist/runtime/mcpToolResult.d.ts.map +1 -0
  309. package/dist/runtime/mcpToolResult.js +214 -0
  310. package/dist/runtime/moltnetMachineRead.d.ts +97 -0
  311. package/dist/runtime/moltnetMachineRead.d.ts.map +1 -0
  312. package/dist/runtime/moltnetMachineRead.js +183 -0
  313. package/dist/runtime/native/daimon-engine-broker +0 -0
  314. package/dist/runtime/organizationRuntime.d.ts +168 -0
  315. package/dist/runtime/organizationRuntime.d.ts.map +1 -0
  316. package/dist/runtime/organizationRuntime.js +3 -0
  317. package/dist/runtime/organizationRuntimeAdmission.d.ts +6 -0
  318. package/dist/runtime/organizationRuntimeAdmission.d.ts.map +1 -0
  319. package/dist/runtime/organizationRuntimeAdmission.js +22 -0
  320. package/dist/runtime/organizationRuntimeControl.d.ts +51 -0
  321. package/dist/runtime/organizationRuntimeControl.d.ts.map +1 -0
  322. package/dist/runtime/organizationRuntimeControl.js +283 -0
  323. package/dist/runtime/organizationRuntimeHost.d.ts +19 -0
  324. package/dist/runtime/organizationRuntimeHost.d.ts.map +1 -0
  325. package/dist/runtime/organizationRuntimeHost.js +368 -0
  326. package/dist/runtime/organizationRuntimeParsing.d.ts +6 -0
  327. package/dist/runtime/organizationRuntimeParsing.d.ts.map +1 -0
  328. package/dist/runtime/organizationRuntimeParsing.js +373 -0
  329. package/dist/runtime/organizationRuntimeReadiness.d.ts +12 -0
  330. package/dist/runtime/organizationRuntimeReadiness.d.ts.map +1 -0
  331. package/dist/runtime/organizationRuntimeReadiness.js +67 -0
  332. package/dist/runtime/organizationRuntimeRecording.d.ts +7 -0
  333. package/dist/runtime/organizationRuntimeRecording.d.ts.map +1 -0
  334. package/dist/runtime/organizationRuntimeRecording.js +58 -0
  335. package/dist/runtime/physicalReadiness.d.ts +59 -0
  336. package/dist/runtime/physicalReadiness.d.ts.map +1 -0
  337. package/dist/runtime/physicalReadiness.js +176 -0
  338. package/dist/runtime/portableCredentialAuth.d.ts +6 -0
  339. package/dist/runtime/portableCredentialAuth.d.ts.map +1 -0
  340. package/dist/runtime/portableCredentialAuth.js +70 -0
  341. package/dist/runtime/portableCredentialMaterial.d.ts +8 -0
  342. package/dist/runtime/portableCredentialMaterial.d.ts.map +1 -0
  343. package/dist/runtime/portableCredentialMaterial.js +169 -0
  344. package/dist/runtime/productionAgentTools.d.ts +5 -0
  345. package/dist/runtime/productionAgentTools.d.ts.map +1 -0
  346. package/dist/runtime/productionAgentTools.js +336 -0
  347. package/dist/runtime/relocateRuntimeConfig.d.ts +14 -0
  348. package/dist/runtime/relocateRuntimeConfig.d.ts.map +1 -0
  349. package/dist/runtime/relocateRuntimeConfig.js +38 -0
  350. package/dist/runtime/runtimeHomeLayout.d.ts +48 -0
  351. package/dist/runtime/runtimeHomeLayout.d.ts.map +1 -0
  352. package/dist/runtime/runtimeHomeLayout.js +84 -0
  353. package/dist/runtime/schedule.d.ts +40 -0
  354. package/dist/runtime/schedule.d.ts.map +1 -0
  355. package/dist/runtime/schedule.js +376 -0
  356. package/dist/runtime/storeCoordination.d.ts +33 -0
  357. package/dist/runtime/storeCoordination.d.ts.map +1 -0
  358. package/dist/runtime/storeCoordination.js +117 -0
  359. package/dist/runtime/taskClock.d.ts +42 -0
  360. package/dist/runtime/taskClock.d.ts.map +1 -0
  361. package/dist/runtime/taskClock.js +102 -0
  362. package/dist/runtime/taskClockProcess.d.ts +17 -0
  363. package/dist/runtime/taskClockProcess.d.ts.map +1 -0
  364. package/dist/runtime/taskClockProcess.js +58 -0
  365. package/dist/runtime/toolResultSpill.d.ts +152 -0
  366. package/dist/runtime/toolResultSpill.d.ts.map +1 -0
  367. package/dist/runtime/toolResultSpill.js +351 -0
  368. package/dist/runtime/turnRequestLedger.d.ts +155 -0
  369. package/dist/runtime/turnRequestLedger.d.ts.map +1 -0
  370. package/dist/runtime/turnRequestLedger.js +251 -0
  371. package/dist/runtime/turnUsageLedger.d.ts +143 -0
  372. package/dist/runtime/turnUsageLedger.d.ts.map +1 -0
  373. package/dist/runtime/turnUsageLedger.js +203 -0
  374. package/dist/runtime/wakeAcceptanceClaimDiagnostics.d.ts +34 -0
  375. package/dist/runtime/wakeAcceptanceClaimDiagnostics.d.ts.map +1 -0
  376. package/dist/runtime/wakeAcceptanceClaimDiagnostics.js +79 -0
  377. package/dist/runtime/wakeAcceptanceIndex.d.ts +55 -0
  378. package/dist/runtime/wakeAcceptanceIndex.d.ts.map +1 -0
  379. package/dist/runtime/wakeAcceptanceIndex.js +158 -0
  380. package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts +25 -0
  381. package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts.map +1 -0
  382. package/dist/runtime/wakeAcceptanceProcessIdentity.js +54 -0
  383. package/dist/runtime/wakeAcceptanceReconciliation.d.ts +211 -0
  384. package/dist/runtime/wakeAcceptanceReconciliation.d.ts.map +1 -0
  385. package/dist/runtime/wakeAcceptanceReconciliation.js +289 -0
  386. package/dist/runtime/wakeAcceptanceRecord.d.ts +25 -0
  387. package/dist/runtime/wakeAcceptanceRecord.d.ts.map +1 -0
  388. package/dist/runtime/wakeAcceptanceRecord.js +58 -0
  389. package/dist/runtime/wakeAcceptanceRetention.d.ts +36 -0
  390. package/dist/runtime/wakeAcceptanceRetention.d.ts.map +1 -0
  391. package/dist/runtime/wakeAcceptanceRetention.js +38 -0
  392. package/dist/runtime/wakeAcceptanceStore.d.ts +113 -0
  393. package/dist/runtime/wakeAcceptanceStore.d.ts.map +1 -0
  394. package/dist/runtime/wakeAcceptanceStore.js +561 -0
  395. package/dist/runtime/wakeAcceptanceTypes.d.ts +179 -0
  396. package/dist/runtime/wakeAcceptanceTypes.d.ts.map +1 -0
  397. package/dist/runtime/wakeAcceptanceTypes.js +95 -0
  398. package/dist/runtime/wakeFuse.d.ts +124 -0
  399. package/dist/runtime/wakeFuse.d.ts.map +1 -0
  400. package/dist/runtime/wakeFuse.js +466 -0
  401. package/dist/runtime/wakeMomentFs.d.ts +27 -0
  402. package/dist/runtime/wakeMomentFs.d.ts.map +1 -0
  403. package/dist/runtime/wakeMomentFs.js +223 -0
  404. package/dist/runtime/wakeMomentHistory.d.ts +26 -0
  405. package/dist/runtime/wakeMomentHistory.d.ts.map +1 -0
  406. package/dist/runtime/wakeMomentHistory.js +109 -0
  407. package/dist/runtime/wakeMomentIo.d.ts +22 -0
  408. package/dist/runtime/wakeMomentIo.d.ts.map +1 -0
  409. package/dist/runtime/wakeMomentIo.js +114 -0
  410. package/dist/runtime/wakeMomentRecorder.d.ts +33 -0
  411. package/dist/runtime/wakeMomentRecorder.d.ts.map +1 -0
  412. package/dist/runtime/wakeMomentRecorder.js +81 -0
  413. package/dist/runtime/wakeMomentRetention.d.ts +7 -0
  414. package/dist/runtime/wakeMomentRetention.d.ts.map +1 -0
  415. package/dist/runtime/wakeMomentRetention.js +143 -0
  416. package/dist/runtime/wakeMomentRows.d.ts +8 -0
  417. package/dist/runtime/wakeMomentRows.d.ts.map +1 -0
  418. package/dist/runtime/wakeMomentRows.js +66 -0
  419. package/dist/runtime/wakeMomentSnapshot.d.ts +56 -0
  420. package/dist/runtime/wakeMomentSnapshot.d.ts.map +1 -0
  421. package/dist/runtime/wakeMomentSnapshot.js +248 -0
  422. package/package.json +22 -11
@@ -0,0 +1,228 @@
1
+ import { brokerProcessClock } from "./grokBrokerTaskClock.js";
2
+ import { reportEngineTaskClockGap } from "../pi/engineTaskClock.js";
3
+ import { attentionTools } from "./attention.js";
4
+ import { readTaskClock } from "./taskClock.js";
5
+ import { memoryClockOptions } from "../pi/memoryClock.js";
6
+ import { grokDaimonToolName, grokMountedToolNamingRule } from "../contracts/grokWorkerContract.js";
7
+ import path from "node:path";
8
+ import { AGY_MAX_TOOL_TURNS, createCliSessionFactory, resolveCodexWakeTimeoutMs, resolveCodexWakeTokenCeiling, resolveEngineWakeLimitOverrides } from "../pi/cliSession.js";
9
+ import { GROK_DAIMON_SANDBOX_PROFILE, prepareAndVerifyGrokSandbox } from "../pi/grokSandbox.js";
10
+ import { PiHarnessAdapter } from "../pi/piHarness.js";
11
+ import { engineAuthFile, engineHomeName, prepareEngineExecutable, prepareEngineReadiness, readPortableEngineCredentialSecrets } from "./engineReadiness.js";
12
+ import { createProductionAgentTools } from "./productionAgentTools.js";
13
+ import { AGY_SUBSCRIPTION_REALM, GROK_SUBSCRIPTION_REALM } from "./contractManifest.js";
14
+ import { recordTurnUsage, resolveTurnUsageLedgerPath } from "./turnUsageLedger.js";
15
+ import { recordCodexTurnRequests } from "./turnRequestLedger.js";
16
+ /**
17
+ * The production-only bridge from a closed runtime engine intent to Daimon's
18
+ * existing one-agent harness. Configuration never carries a command or env.
19
+ */
20
+ export async function startOrganizationRuntimeEngine(agent, controlTokenEnv, paths, agyBusAddress, grokBroker, organizationAgents, sharedProtectedPaths = [], attention) {
21
+ const clock = readTaskClock();
22
+ reportEngineTaskClockGap(agent.engine.kind);
23
+ if (agent.memory !== undefined)
24
+ memoryClockOptions(clock);
25
+ // A declared Grok model is enforced by the broker proxy and worker config;
26
+ // the direct path has neither, so it refuses rather than silently ignoring it.
27
+ if (agent.engine.kind === "grok" && agent.engine.model !== undefined && grokBroker === undefined)
28
+ throw new Error(`Agent ${agent.id} declares a Grok model, which requires the engine broker`);
29
+ await paths?.verify();
30
+ const canonicalAgent = paths === undefined ? agent : { ...agent, workspacePath: paths.workspacePath, runtimeHomePath: paths.runtimeHomePath };
31
+ const readiness = canonicalAgent.engine.kind === "grok" && grokBroker !== undefined
32
+ ? { ...(await prepareEngineExecutable(canonicalAgent.id, "grok")), engineHomePath: path.join(canonicalAgent.runtimeHomePath, engineHomeName("grok")) }
33
+ : await prepareEngineReadiness(canonicalAgent, canonicalAgent.runtimeHomePath, agyBusAddress);
34
+ const wakeContext = {};
35
+ const grokSandbox = canonicalAgent.engine.kind === "grok" && paths !== undefined && organizationAgents !== undefined
36
+ ? () => prepareAndVerifyGrokSandbox({
37
+ command: readiness.executablePath,
38
+ cwd: canonicalAgent.workspacePath,
39
+ engineHomePath: readiness.engineHomePath,
40
+ protectedPaths: grokSandboxProtectedPaths(canonicalAgent.id, organizationAgents, sharedProtectedPaths),
41
+ runtimeHomePath: canonicalAgent.runtimeHomePath
42
+ })
43
+ : undefined;
44
+ const codexSandboxPaths = canonicalAgent.engine.kind === "codex" && canonicalAgent.engine.codexSandbox !== undefined
45
+ ? {
46
+ protectedPaths: codexSandboxProtectedPaths(canonicalAgent.id, canonicalAgent, readiness.engineHomePath, organizationAgents ?? [canonicalAgent], sharedProtectedPaths),
47
+ readablePaths: codexSandboxReadablePaths(canonicalAgent)
48
+ }
49
+ : undefined;
50
+ const mountedTools = [...await createProductionAgentTools(canonicalAgent, wakeContext), ...(agent.attention !== undefined && attention !== undefined ? attentionTools(agent.id, attention) : [])];
51
+ const adapter = adapterFor(canonicalAgent, controlTokenEnv, readiness.verify, readiness.executablePath, readiness.engineHomePath, paths?.verify, agyBusAddress, mountedTools, wakeContext, grokSandbox, grokBroker, codexSandboxPaths, mountedTools.map((tool) => tool.name));
52
+ const handle = await adapter.startAgent({
53
+ id: canonicalAgent.id,
54
+ name: canonicalAgent.name,
55
+ instructions: canonicalAgent.instructions,
56
+ runtimeHomePath: canonicalAgent.runtimeHomePath,
57
+ workspacePath: canonicalAgent.workspacePath
58
+ });
59
+ await paths?.verify();
60
+ const result = {
61
+ ...handle,
62
+ async wake(event) {
63
+ await paths?.verify();
64
+ await readiness.verify();
65
+ try {
66
+ return await handle.wake(event);
67
+ }
68
+ finally {
69
+ await paths?.verify();
70
+ await readiness.verify();
71
+ }
72
+ },
73
+ async stop() { await handle.stop(); },
74
+ status: () => handle.status()
75
+ };
76
+ return result;
77
+ }
78
+ export function grokSandboxProtectedPaths(currentAgentId, organizationAgents, sharedProtectedPaths = []) {
79
+ return [
80
+ GROK_SUBSCRIPTION_REALM.bootstrapMountPath,
81
+ GROK_SUBSCRIPTION_REALM.durableMountPath,
82
+ ...(organizationAgents.some((peer) => peer.engine.kind === "agy") ? [
83
+ AGY_SUBSCRIPTION_REALM.unlockMountPath,
84
+ AGY_SUBSCRIPTION_REALM.durableMountPath
85
+ ] : []),
86
+ ...sharedProtectedPaths,
87
+ ...organizationAgents.filter((peer) => peer.id !== currentAgentId)
88
+ .flatMap((peer) => [peer.runtimeHomePath, peer.workspacePath])
89
+ ];
90
+ }
91
+ export function codexSandboxProtectedPaths(currentAgentId, currentAgent, currentEngineHomePath, organizationAgents, sharedProtectedPaths = []) {
92
+ return [...new Set([
93
+ engineAuthFile("codex", currentEngineHomePath),
94
+ path.join(currentAgent.runtimeHomePath, ".daimon-inbound"),
95
+ "/proc",
96
+ "/run",
97
+ ...grokSandboxProtectedPaths(currentAgentId, organizationAgents, sharedProtectedPaths)
98
+ ])];
99
+ }
100
+ export function codexSandboxReadablePaths(currentAgent) {
101
+ return [path.join(currentAgent.runtimeHomePath, "tool-output")];
102
+ }
103
+ function adapterFor(agent, controlTokenEnv, verifyExecutable, executablePath, engineHomePath, verifyRuntimePaths, agyBusAddress, productionTools = [], wakeEnvironmentContext = {}, verifyGrokSandbox, grokBroker, codexSandboxPaths, mountedToolNames = []) {
104
+ const engine = agent.engine.kind;
105
+ const sessionFactory = createCliSessionFactory(engine === "agy"
106
+ ? { engine, maxToolTurns: AGY_MAX_TOOL_TURNS, timeoutMs: 180_000, dbusSessionBusAddress: agyBusAddress, redactedEnvironmentNames: [controlTokenEnv], identityPrompt: identityEnvelope(agent, mountedToolNames), command: executablePath, engineHomePath, verifyExecutable, verifyRuntimePaths,
107
+ // AGY has no broker to meter it, so the session hands its decoded
108
+ // terminal-frame usage straight to the same ledger the Grok broker
109
+ // appends to. `recordTurnUsage` is advisory and never rejects.
110
+ onTurnUsage: (usage, outcome) => recordTurnUsage(resolveTurnUsageLedgerPath(), { agent: agent.id, wake: wakeEnvironmentContext.current ?? "wake", engine: "agy", usage, outcome }) }
111
+ : { engine, redactedEnvironmentNames: [controlTokenEnv], identityPrompt: identityEnvelope(agent, mountedToolNames), command: executablePath, engineHomePath, verifyExecutable, verifyRuntimePaths,
112
+ ...(engine === "codex" ? {
113
+ // Codex has no broker to meter it, so publish terminal-frame usage
114
+ // to the shared advisory ledger — on the wake that published and on
115
+ // the wake that failed after Codex had already reported its spend.
116
+ onTurnUsage: (usage, outcome) => recordTurnUsage(resolveTurnUsageLedgerPath(), { agent: agent.id, wake: wakeEnvironmentContext.current ?? "wake", engine: "codex", usage, outcome }),
117
+ // Per-model-request accounting, written to its own stream beside the
118
+ // ledger. `engineHomePath` is the agent's `CODEX_HOME`
119
+ // (`../pi/cliEnvironment.ts`), so the rollout Codex just wrote for
120
+ // this thread is under it. Advisory throughout: it never fails a wake.
121
+ onCodexTurnRequests: (threadId) => recordCodexTurnRequests({ agent: agent.id, wake: wakeEnvironmentContext.current ?? "wake", codexHome: engineHomePath, threadId }).then(() => undefined),
122
+ // `maxToolTurns` mediates only daimon-MCP tool calls; Codex's own
123
+ // shell is never routed through it, so it gets its own wall-clock
124
+ // and per-wake token bounds instead (`cliSession.ts`).
125
+ timeoutMs: resolveCodexWakeTimeoutMs(),
126
+ codexTokenCeiling: resolveCodexWakeTokenCeiling(),
127
+ // Present only when the parsed config declared them; absent keeps
128
+ // today's unpinned Codex CLI default and today's exact argv.
129
+ ...(agent.engine.model === undefined ? {} : { model: agent.engine.model }),
130
+ ...(agent.engine.reasoningEffort === undefined ? {} : { reasoningEffort: agent.engine.reasoningEffort }),
131
+ ...(agent.engine.codexSandbox === undefined ? {} : { codexSandbox: agent.engine.codexSandbox }),
132
+ ...(codexSandboxPaths === undefined ? {} : {
133
+ codexSandboxProtectedPaths: codexSandboxPaths.protectedPaths,
134
+ codexSandboxReadablePaths: codexSandboxPaths.readablePaths
135
+ })
136
+ } : {}),
137
+ ...(engine === "grok" && grokBroker !== undefined ? {} : { credentialSecretValues: () => readPortableEngineCredentialSecrets(agent.id, engine, engineHomePath) }),
138
+ // The broker seals usage and enforces its registration's limits; the
139
+ // wake may only lower them (DAIMON_ENGINE_WAKE_*), and a declared model
140
+ // must be the one the broker reports it ran.
141
+ ...(engine === "grok" && grokBroker !== undefined ? { grokBrokerTurn: grokBrokerTurnFor(agent, grokBroker, wakeEnvironmentContext) } : {}),
142
+ ...(engine === "grok" && verifyGrokSandbox ? {
143
+ grokSandboxProfile: GROK_DAIMON_SANDBOX_PROFILE,
144
+ verifyGrokSandbox
145
+ } : {}) });
146
+ return cliHarness(agent, sessionFactory, [controlTokenEnv], productionTools, wakeEnvironmentContext);
147
+ }
148
+ /** @internal The same callback used by the production session; no native process clock enters the engine environment. */
149
+ export function grokBrokerTurnFor(agent, grokBroker, wakeEnvironmentContext) {
150
+ const limits = resolveEngineWakeLimitOverrides();
151
+ const options = { ...(limits === undefined ? {} : { limits }), ...(agent.engine.model === undefined ? {} : { model: agent.engine.model }) };
152
+ return (prompt, endpoint, signal) => {
153
+ const processClock = brokerProcessClock();
154
+ return grokBroker.turn(agent.id, wakeEnvironmentContext.current ?? "wake", prompt, endpoint, signal, { ...options, ...(processClock === undefined ? {} : { processClock }) });
155
+ };
156
+ }
157
+ /**
158
+ * CLI engines do not consume Pi's resource loader. Frame the same immutable
159
+ * identity in JSON so arbitrary names/instructions cannot change its shape.
160
+ */
161
+ /**
162
+ * The caller-owned prompt preamble.
163
+ *
164
+ * It names the mounted tools explicitly, because a CLI engine reaches Daimon's
165
+ * tools over MCP and an agent whose instructions name another engine's tool
166
+ * spelling can finish a turn having called nothing. The declared names are the
167
+ * caller's own configuration, not engine-supplied text.
168
+ *
169
+ * On Grok the bare names are not the callable ones: every Daimon tool is a
170
+ * deferred MCP tool of server `daimon`, and Grok 1.0.34 refuses an unqualified
171
+ * name before any HTTP ("Tool names must be qualified as `server__tool`"). This
172
+ * envelope used to instruct exactly that refused form. The correct rule is not
173
+ * restated here — it is rendered by `grokMountedToolNamingRule` in the same
174
+ * contract module that renders the worker's pinned system prompt, so the two
175
+ * texts cannot contradict each other again. Every other engine's sentence is
176
+ * unchanged, byte for byte.
177
+ */
178
+ export function identityEnvelope(agent, mountedToolNames = []) {
179
+ return [
180
+ "<daimon-agent-identity>",
181
+ JSON.stringify({ id: agent.id, name: agent.name, instructions: agent.instructions }),
182
+ "</daimon-agent-identity>",
183
+ ...(mountedToolNames.length === 0 ? [] : [
184
+ (agent.engine.kind === "grok"
185
+ ? grokMountedToolNamingRule(mountedToolNames)
186
+ : `Your mounted tools are exactly: ${mountedToolNames.join(", ")}. Call them by these names; `
187
+ + "your instructions may spell them differently.")
188
+ + " No other tool reaches the newsroom."
189
+ ]),
190
+ // The one tool that reaches colleagues is named the way this engine can
191
+ // call it. Meaning and prohibition are unchanged; only the spelling is.
192
+ `Colleagues only hear you when you call ${engineToolName(agent, "moltnet_send")}; your terminal response is a private note to the runtime, not a message to anyone — keep it to one line or leave it empty. `
193
+ + "Do not seek transport credentials or invoke a transport CLI unless the caller explicitly mounted an authenticated transport tool.",
194
+ "The following is the current wake event."
195
+ ].join("\n") + "\n";
196
+ }
197
+ /**
198
+ * One Daimon tool name, spelled the way this agent's engine accepts it.
199
+ *
200
+ * On Grok the bare form is refused as an invalid MCP tool name, so any
201
+ * engine-facing sentence that *names* a tool renders it through the contract's
202
+ * `grokDaimonToolName`; every other engine keeps the bare name byte for byte.
203
+ * Grok's own native tools (`read_file`, `search_tool`, `use_tool`) are not
204
+ * Daimon tools and never take the prefix.
205
+ */
206
+ const engineToolName = (agent, tool) => agent.engine.kind === "grok" ? grokDaimonToolName(tool) : tool;
207
+ function cliHarness(agent, sessionFactory, protectedEnvironmentNames, productionTools, wakeEnvironmentContext) {
208
+ return new PiHarnessAdapter({
209
+ authPath: path.join(agent.runtimeHomePath, "auth.json"),
210
+ // Pi owns the harness envelope while the session factory owns this CLI.
211
+ model: {
212
+ auth: { method: "none" },
213
+ endpoint: { baseUrl: "http://127.0.0.1/daimon-cli", compatibility: "openai" },
214
+ name: "daimon-cli",
215
+ provider: "daimon-cli"
216
+ },
217
+ sessionFactory,
218
+ protectedEnvironmentNames,
219
+ productionTools,
220
+ ...(agent.engine.kind === "codex" && agent.engine.codexSandbox !== undefined ? { toolNames: [] } : {}),
221
+ wakeEnvironmentContext,
222
+ ...(agent.memory === undefined ? {} : { memory: {
223
+ runtimeHomePath: agent.memory.runtimeHomePath,
224
+ ...(agent.memory.source === undefined ? {} : { source: agent.memory.source }),
225
+ ...(agent.memory.tokenBudget === undefined ? {} : { tokenBudget: agent.memory.tokenBudget })
226
+ } })
227
+ });
228
+ }
@@ -0,0 +1,23 @@
1
+ import type { OrganizationRuntimeAgentConfig } from "./organizationRuntime.js";
2
+ export type EngineReadiness = Readonly<{
3
+ executablePath: string;
4
+ engineHomePath: string;
5
+ verify(): Promise<void>;
6
+ }>;
7
+ export type EngineExecutableReadiness = Readonly<{
8
+ executablePath: string;
9
+ verify(): Promise<void>;
10
+ }>;
11
+ /**
12
+ * Resolves and pins the small, local authority needed by one CLI engine. This
13
+ * deliberately does not start an agent, contact a provider, or read a secret
14
+ * beyond the bounded structural authentication check.
15
+ */
16
+ export declare function prepareEngineReadiness(agent: OrganizationRuntimeAgentConfig, runtimeHomePath: string, agyBusAddress?: string): Promise<EngineReadiness>;
17
+ export declare function prepareEngineExecutable(agentId: string, engine: "codex" | "grok" | "agy"): Promise<EngineExecutableReadiness>;
18
+ export declare function engineHomeName(engine: "codex" | "grok"): string;
19
+ export declare function engineAuthFile(_engine: "codex" | "grok", engineHomePath: string): string;
20
+ /** Securely rereads the currently staged provider credential for exact output redaction. */
21
+ export declare function readPortableEngineCredentialSecrets(agentId: string, engine: "codex" | "grok", engineHomePath: string): Promise<readonly string[]>;
22
+ export declare function verifyAgySubscriptionEnrollment(agentId: string, executablePath: string, runtimeHomePath: string, busAddress: string | undefined): Promise<void>;
23
+ //# sourceMappingURL=engineReadiness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineReadiness.d.ts","sourceRoot":"","sources":["../../src/runtime/engineReadiness.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAM/E,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC/C,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC,CAAC;AAIH;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,8BAA8B,EACrC,eAAe,EAAE,MAAM,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,eAAe,CAAC,CAa1B;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,GAC/B,OAAO,CAAC,yBAAyB,CAAC,CAqBpC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAE/D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAExF;AAqFD,4FAA4F;AAC5F,wBAAsB,mCAAmC,CACvD,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,OAAO,GAAG,MAAM,EACxB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAqB5B;AAUD,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -0,0 +1,222 @@
1
+ import { constants } from "node:fs";
2
+ import { lstat, open, realpath, stat } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { spawnRealTime as spawn } from "./taskClockProcess.js";
5
+ import { createHash } from "node:crypto";
6
+ import { cliChildEnvironment } from "../pi/cliEnvironment.js";
7
+ import { hasRefreshablePortableCredential, portableCredentialSecretValues } from "./portableCredentialAuth.js";
8
+ const MAX_AUTH_BYTES = 64 * 1024;
9
+ const MAX_PROBE_BYTES = 8 * 1024;
10
+ /**
11
+ * Resolves and pins the small, local authority needed by one CLI engine. This
12
+ * deliberately does not start an agent, contact a provider, or read a secret
13
+ * beyond the bounded structural authentication check.
14
+ */
15
+ export async function prepareEngineReadiness(agent, runtimeHomePath, agyBusAddress) {
16
+ const executable = await prepareEngineExecutable(agent.id, agent.engine.kind);
17
+ const executablePath = executable.executablePath;
18
+ const engineHomePath = agent.engine.kind === "agy" ? runtimeHomePath : path.join(runtimeHomePath, engineHomeName(agent.engine.kind));
19
+ await verifyEngineAuth(agent.id, agent.engine.kind, engineHomePath, executablePath, runtimeHomePath, agyBusAddress);
20
+ return {
21
+ executablePath,
22
+ engineHomePath,
23
+ async verify() {
24
+ await executable.verify();
25
+ await verifyEngineAuth(agent.id, agent.engine.kind, engineHomePath, executablePath, runtimeHomePath, agyBusAddress);
26
+ }
27
+ };
28
+ }
29
+ export async function prepareEngineExecutable(agentId, engine) {
30
+ const executablePath = await resolveExecutable(agentId, engine);
31
+ const executableIdentity = identity(await stat(executablePath));
32
+ const capability = await probeExecutable(agentId, executablePath, engine);
33
+ return {
34
+ executablePath,
35
+ async verify() {
36
+ let current;
37
+ try {
38
+ const entry = await lstat(executablePath);
39
+ if (entry.isSymbolicLink())
40
+ throw new Error("link");
41
+ current = await stat(executablePath);
42
+ }
43
+ catch {
44
+ throw unavailable(agentId, engine, "engine executable changed");
45
+ }
46
+ if (!sameIdentity(executableIdentity, identity(current)) || !current.isFile()) {
47
+ throw unavailable(agentId, engine, "engine executable changed");
48
+ }
49
+ if (await probeExecutable(agentId, executablePath, engine) !== capability) {
50
+ throw unavailable(agentId, engine, "engine capability changed");
51
+ }
52
+ }
53
+ };
54
+ }
55
+ export function engineHomeName(engine) {
56
+ return engine === "codex" ? ".codex" : ".grok";
57
+ }
58
+ export function engineAuthFile(_engine, engineHomePath) {
59
+ return path.join(engineHomePath, "auth.json");
60
+ }
61
+ async function resolveExecutable(agentId, engine) {
62
+ const sourcePath = process.env.PATH ?? "";
63
+ for (const directory of sourcePath.split(path.delimiter)) {
64
+ if (!directory || !path.isAbsolute(directory))
65
+ continue;
66
+ try {
67
+ const canonicalDirectory = await realpath(directory);
68
+ const directoryEntry = await lstat(canonicalDirectory);
69
+ if (!directoryEntry.isDirectory() || directoryEntry.isSymbolicLink() || (directoryEntry.mode & 0o022) !== 0)
70
+ continue;
71
+ const candidate = path.join(canonicalDirectory, engine);
72
+ const entry = await lstat(candidate);
73
+ if (!entry.isFile() && !entry.isSymbolicLink())
74
+ continue;
75
+ const canonical = await realpath(candidate);
76
+ const resolved = await lstat(canonical);
77
+ if (!resolved.isFile() || resolved.isSymbolicLink() || (resolved.mode & 0o111) === 0)
78
+ continue;
79
+ return canonical;
80
+ }
81
+ catch (error) {
82
+ if (error.code === "ENOENT")
83
+ continue;
84
+ throw unavailable(agentId, engine, "engine executable cannot be inspected");
85
+ }
86
+ }
87
+ throw unavailable(agentId, engine, "engine executable is unavailable");
88
+ }
89
+ async function probeExecutable(agentId, executablePath, engine) {
90
+ return new Promise((resolve, reject) => {
91
+ const child = spawn(executablePath, ["--version"], { cwd: path.dirname(executablePath), env: { PATH: process.env.PATH ?? path.dirname(executablePath), LANG: "C", LC_ALL: "C" }, stdio: ["ignore", "pipe", "pipe"] });
92
+ let bytes = 0;
93
+ const output = [];
94
+ // Only stdout fingerprints the capability. stderr carries environment-dependent
95
+ // diagnostics -- allocator warnings under emulation, for one -- which are not a
96
+ // capability change but would otherwise invalidate the engine mid-run.
97
+ const consume = (chunk, capture) => { bytes += chunk.length; if (bytes > MAX_PROBE_BYTES)
98
+ child.kill("SIGKILL");
99
+ else if (capture)
100
+ output.push(chunk); };
101
+ child.stdout?.on("data", (chunk) => consume(chunk, true));
102
+ child.stderr?.on("data", (chunk) => consume(chunk, false));
103
+ const timer = setTimeout(() => child.kill("SIGKILL"), 3_000);
104
+ child.once("error", () => { clearTimeout(timer); reject(unavailable(agentId, engine, "engine capability probe failed")); });
105
+ child.once("close", (code) => {
106
+ clearTimeout(timer);
107
+ if (code === 0 && bytes <= MAX_PROBE_BYTES)
108
+ resolve(createHash("sha256").update(Buffer.concat(output)).digest("hex"));
109
+ else
110
+ reject(unavailable(agentId, engine, "engine capability probe failed"));
111
+ });
112
+ });
113
+ }
114
+ async function verifyEngineAuth(agentId, engine, engineHomePath, executablePath, runtimeHomePath, agyBusAddress) {
115
+ if (engine === "agy") {
116
+ await verifyAgySubscriptionEnrollment(agentId, executablePath, runtimeHomePath, agyBusAddress);
117
+ return;
118
+ }
119
+ await verifyPortableEngineAuth(agentId, engine, engineHomePath);
120
+ }
121
+ async function verifyPortableEngineAuth(agentId, engine, engineHomePath) {
122
+ const authPath = engineAuthFile(engine, engineHomePath);
123
+ let handle;
124
+ let buffer;
125
+ try {
126
+ const home = await lstat(engineHomePath);
127
+ if (!home.isDirectory() || home.isSymbolicLink() || home.uid !== process.getuid?.() || (home.mode & 0o777) !== 0o700) {
128
+ throw new Error("unsafe engine home");
129
+ }
130
+ const entry = await lstat(authPath);
131
+ assertPrivateAuthEntry(entry);
132
+ handle = await open(authPath, constants.O_RDONLY | noFollow());
133
+ const opened = await handle.stat();
134
+ assertPrivateAuthEntry(opened);
135
+ if (!sameIdentity(identity(entry), identity(opened)))
136
+ throw new Error("auth artifact changed");
137
+ buffer = await handle.readFile();
138
+ const after = await handle.stat();
139
+ assertPrivateAuthEntry(after);
140
+ if (!sameIdentity(identity(opened), identity(after)))
141
+ throw new Error("auth artifact changed");
142
+ if (!hasRefreshablePortableCredential(engine, buffer))
143
+ throw new Error("unsupported auth artifact");
144
+ }
145
+ catch {
146
+ throw unavailable(agentId, engine, "subscription authentication is not ready; provision the supported local credential and retry");
147
+ }
148
+ finally {
149
+ buffer?.fill(0);
150
+ await handle?.close().catch(() => undefined);
151
+ }
152
+ }
153
+ /** Securely rereads the currently staged provider credential for exact output redaction. */
154
+ export async function readPortableEngineCredentialSecrets(agentId, engine, engineHomePath) {
155
+ const authPath = engineAuthFile(engine, engineHomePath);
156
+ let handle;
157
+ let buffer;
158
+ try {
159
+ const home = await lstat(engineHomePath);
160
+ if (!home.isDirectory() || home.isSymbolicLink() || home.uid !== process.getuid?.() || (home.mode & 0o777) !== 0o700)
161
+ throw new Error("unsafe");
162
+ const before = await lstat(authPath);
163
+ assertPrivateAuthEntry(before);
164
+ handle = await open(authPath, constants.O_RDONLY | noFollow());
165
+ const opened = await handle.stat();
166
+ assertPrivateAuthEntry(opened);
167
+ if (!sameIdentity(identity(before), identity(opened)))
168
+ throw new Error("changed");
169
+ buffer = await handle.readFile();
170
+ const after = await handle.stat();
171
+ assertPrivateAuthEntry(after);
172
+ if (!sameIdentity(identity(opened), identity(after)) || !hasRefreshablePortableCredential(engine, buffer))
173
+ throw new Error("changed");
174
+ return portableCredentialSecretValues(engine, buffer);
175
+ }
176
+ catch {
177
+ throw unavailable(agentId, engine, "subscription authentication is not ready");
178
+ }
179
+ finally {
180
+ buffer?.fill(0);
181
+ await handle?.close().catch(() => undefined);
182
+ }
183
+ }
184
+ function assertPrivateAuthEntry(entry) {
185
+ if (!entry.isFile() || entry.isSymbolicLink() || Number(entry.uid) !== process.getuid?.()
186
+ || Number(entry.nlink) !== 1 || (Number(entry.mode) & 0o777) !== 0o600
187
+ || Number(entry.size) < 1 || Number(entry.size) > MAX_AUTH_BYTES) {
188
+ throw new Error("unsafe auth artifact");
189
+ }
190
+ }
191
+ export async function verifyAgySubscriptionEnrollment(agentId, executablePath, runtimeHomePath, busAddress) {
192
+ if (busAddress === undefined)
193
+ throw unavailable(agentId, "agy", "Daimon subscription realm is unavailable");
194
+ await new Promise((resolve, reject) => {
195
+ const child = spawn(executablePath, ["models"], {
196
+ cwd: runtimeHomePath,
197
+ env: cliChildEnvironment([], runtimeHomePath, {
198
+ dbusSessionBusAddress: busAddress,
199
+ engine: "agy",
200
+ executablePath,
201
+ engineHomePath: runtimeHomePath
202
+ }),
203
+ stdio: ["ignore", "ignore", "ignore"]
204
+ });
205
+ const timer = setTimeout(() => child.kill("SIGKILL"), 10_000);
206
+ child.once("error", () => { clearTimeout(timer); reject(unavailable(agentId, "agy", "native secure-storage authentication probe failed")); });
207
+ child.once("close", (code) => {
208
+ clearTimeout(timer);
209
+ if (code === 0)
210
+ resolve();
211
+ else
212
+ reject(unavailable(agentId, "agy", "subscription enrollment is required; run the Daimon AGY bootstrap command"));
213
+ });
214
+ });
215
+ }
216
+ function noFollow() { return constants.O_NOFOLLOW ?? 0; }
217
+ function identity(value) {
218
+ const numeric = value;
219
+ return { dev: numeric.dev, ino: numeric.ino, size: numeric.size, mtimeMs: numeric.mtimeMs, mode: numeric.mode & 0o7777 };
220
+ }
221
+ function sameIdentity(left, right) { return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.mode === right.mode; }
222
+ function unavailable(agentId, engine, detail) { return new Error(`agent ${agentId} ${engine} is unavailable: ${detail}`); }
@@ -0,0 +1,8 @@
1
+ /** Classifies a bounded streaming diagnostic without retaining provider output. */
2
+ export declare function classifyGrokAuthenticationDiagnostic(diagnostic: string): GrokSubscriptionAuthenticationRejectedError | undefined;
3
+ /** Fixed-message marker used to stale-fence a rotating Grok credential realm. */
4
+ export declare class GrokSubscriptionAuthenticationRejectedError extends Error {
5
+ constructor(cleanupFailure?: Error);
6
+ }
7
+ export declare function asGrokAuthenticationRejected(error: unknown): GrokSubscriptionAuthenticationRejectedError | undefined;
8
+ //# sourceMappingURL=grokAuthenticationError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grokAuthenticationError.d.ts","sourceRoot":"","sources":["../../src/runtime/grokAuthenticationError.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,wBAAgB,oCAAoC,CAClD,UAAU,EAAE,MAAM,GACjB,2CAA2C,GAAG,SAAS,CAIzD;AAED,iFAAiF;AACjF,qBAAa,2CAA4C,SAAQ,KAAK;gBACjD,cAAc,CAAC,EAAE,KAAK;CAO1C;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,2CAA2C,GAAG,SAAS,CAIpH"}
@@ -0,0 +1,20 @@
1
+ const AUTH_REJECTION = /(?:Authentication rejected by server|Auth recovery exhausted|RefreshTokenRejected|Not signed in|Not logged in|NoRefresh|NoRecovery|PinnedTeamMismatch|ServerRejected)/iu;
2
+ /** Classifies a bounded streaming diagnostic without retaining provider output. */
3
+ export function classifyGrokAuthenticationDiagnostic(diagnostic) {
4
+ return AUTH_REJECTION.test(diagnostic)
5
+ ? new GrokSubscriptionAuthenticationRejectedError()
6
+ : undefined;
7
+ }
8
+ /** Fixed-message marker used to stale-fence a rotating Grok credential realm. */
9
+ export class GrokSubscriptionAuthenticationRejectedError extends Error {
10
+ constructor(cleanupFailure) {
11
+ super("Grok subscription authentication was rejected; operator re-enrollment is required", cleanupFailure === undefined ? undefined : { cause: cleanupFailure });
12
+ this.name = "GrokSubscriptionAuthenticationRejectedError";
13
+ }
14
+ }
15
+ export function asGrokAuthenticationRejected(error) {
16
+ if (error instanceof GrokSubscriptionAuthenticationRejectedError)
17
+ return error;
18
+ const message = error instanceof Error ? error.message : String(error);
19
+ return classifyGrokAuthenticationDiagnostic(message);
20
+ }
@@ -0,0 +1,23 @@
1
+ export declare class DurableGrokBrokerCredentialAuthority {
2
+ private readonly command;
3
+ private readonly home;
4
+ private readonly authFile;
5
+ private readonly flight;
6
+ private readonly fence;
7
+ private stale;
8
+ private initialized;
9
+ private staleWrite;
10
+ private lastDigest;
11
+ private generation;
12
+ private ancestorDigests;
13
+ constructor(command: string, home: string, authFile?: string);
14
+ initialize(): Promise<void>;
15
+ accessToken(forceRefresh: boolean): Promise<string>;
16
+ refreshAfterRejection(rejectedTokenDigest: string): Promise<string>;
17
+ private refresh;
18
+ markRejected(rejectedTokenDigest?: string): Promise<void>;
19
+ isStale(): boolean;
20
+ private markStale;
21
+ private write;
22
+ }
23
+ //# sourceMappingURL=grokBrokerCredentialAuthority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grokBrokerCredentialAuthority.d.ts","sourceRoot":"","sources":["../../src/runtime/grokBrokerCredentialAuthority.ts"],"names":[],"mappings":"AAUA,qBAAa,oCAAoC;IAGnC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAU,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFtG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0C;IAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqC;IAAC,OAAO,CAAC,KAAK,CAAS;IAAA,OAAO,CAAC,WAAW,CAAO;IAAA,OAAO,CAAC,UAAU,CAAyB;IAAA,OAAO,CAAC,UAAU,CAAkB;IAAA,OAAO,CAAC,UAAU,CAAG;IAClR,OAAO,CAAC,eAAe,CAAyB;gBACnB,OAAO,EAAE,MAAM,EAAmB,IAAI,EAAE,MAAM,EAAmB,QAAQ,SAA+B;IAC/H,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAiC3B,WAAW,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD,qBAAqB,CAAC,mBAAmB,EAAC,MAAM,GAAE,OAAO,CAAC,MAAM,CAAC;IACvE,OAAO,CAAC,OAAO;IAYT,YAAY,CAAC,mBAAmB,CAAC,EAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAC9D,OAAO,IAAG,OAAO;IACjB,OAAO,CAAC,SAAS;YACH,KAAK;CAKpB"}