@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,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 { spawn } from "node:child_process";
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,22 @@
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
+ constructor(command: string, home: string, authFile?: string);
13
+ initialize(): Promise<void>;
14
+ accessToken(forceRefresh: boolean): Promise<string>;
15
+ refreshAfterRejection(rejectedTokenDigest: string): Promise<string>;
16
+ private refresh;
17
+ markRejected(rejectedTokenDigest?: string): Promise<void>;
18
+ isStale(): boolean;
19
+ private markStale;
20
+ private write;
21
+ }
22
+ //# 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;IAEnC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAU,OAAO,CAAC,QAAQ,CAAC,QAAQ;IADtG,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;gBACrP,OAAO,EAAE,MAAM,EAAmB,IAAI,EAAE,MAAM,EAAmB,QAAQ,SAA+B;IAC/H,UAAU,IAAG,OAAO,CAAC,IAAI,CAAC;IAC1B,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;IAOT,YAAY,CAAC,mBAAmB,CAAC,EAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAC9D,OAAO,IAAG,OAAO;IACjB,OAAO,CAAC,SAAS;YACH,KAAK;CAKpB"}
@@ -0,0 +1,124 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { createHash } from "node:crypto";
3
+ import { constants } from "node:fs";
4
+ import { mkdir, open, rename, unlink } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { readGrokBrokerCredential } from "./grokBrokerCredentialReader.js";
7
+ import { refreshGrokBrokerCredential } from "./grokBrokerRefresh.js";
8
+ import { EngineBrokerGenerationFence, EngineBrokerSingleflight } from "./engineBrokerSingleflight.js";
9
+ import { parseBrokerCredentialJournal, recoverBrokerCredentialJournal } from "./engineBrokerCredentialJournal.js";
10
+ export class DurableGrokBrokerCredentialAuthority {
11
+ command;
12
+ home;
13
+ authFile;
14
+ flight = new EngineBrokerSingleflight();
15
+ fence = new EngineBrokerGenerationFence();
16
+ stale = false;
17
+ initialized = false;
18
+ staleWrite;
19
+ lastDigest;
20
+ generation = 0;
21
+ constructor(command, home, authFile = path.join(home, "auth.json")) {
22
+ this.command = command;
23
+ this.home = home;
24
+ this.authFile = authFile;
25
+ }
26
+ async initialize() { if (this.initialized)
27
+ return; const credential = await readGrokBrokerCredential(this.authFile); this.lastDigest = credential.digest; const file = path.join(this.home, ".daimon-broker", "credential-journal.json"); let handle; try {
28
+ handle = await open(file, constants.O_RDONLY | constants.O_NOFOLLOW);
29
+ const stat = await handle.stat();
30
+ if (!stat.isFile() || stat.uid !== process.getuid?.() || (stat.mode & 0o777) !== 0o600 || stat.size > 4096)
31
+ throw unavailable();
32
+ const journal = parseBrokerCredentialJournal(JSON.parse(await handle.readFile("utf8")));
33
+ if (recoverBrokerCredentialJournal(journal, credential.digest) === "stale") {
34
+ this.generation = journal.generation;
35
+ await this.markStale();
36
+ throw unavailable();
37
+ }
38
+ this.generation = journal.generation;
39
+ this.fence.restore(journal.generation);
40
+ }
41
+ catch (error) {
42
+ if (error.code !== "ENOENT")
43
+ throw unavailable();
44
+ }
45
+ finally {
46
+ await handle?.close().catch(() => undefined);
47
+ } this.initialized = true; }
48
+ async accessToken(forceRefresh) {
49
+ if (!this.initialized)
50
+ await this.initialize();
51
+ if (this.stale)
52
+ throw unavailable();
53
+ if (!forceRefresh)
54
+ return (await readGrokBrokerCredential(this.authFile)).accessToken;
55
+ return this.refresh();
56
+ }
57
+ async refreshAfterRejection(rejectedTokenDigest) { if (!/^[a-f0-9]{64}$/u.test(rejectedTokenDigest))
58
+ throw unavailable(); return this.refresh(rejectedTokenDigest); }
59
+ refresh(rejectedTokenDigest) {
60
+ return this.flight.run(async () => {
61
+ if (this.stale)
62
+ throw unavailable();
63
+ const generation = this.fence.snapshot();
64
+ const before = await readGrokBrokerCredential(this.authFile);
65
+ if (rejectedTokenDigest !== undefined && createHash("sha256").update(before.accessToken).digest("hex") !== rejectedTokenDigest)
66
+ return before.accessToken;
67
+ try {
68
+ await this.write({ state: "refreshing", generation, sourceDigest: before.digest });
69
+ await refreshGrokBrokerCredential(this.command, this.home);
70
+ const after = await readGrokBrokerCredential(this.authFile);
71
+ if (after.digest === before.digest)
72
+ throw unavailable();
73
+ const next = this.fence.promote(generation);
74
+ this.generation = next;
75
+ await this.write({ state: "promoted", generation: next, sourceDigest: before.digest, promotedDigest: after.digest });
76
+ this.lastDigest = after.digest;
77
+ return after.accessToken;
78
+ }
79
+ catch {
80
+ await this.markStale();
81
+ throw unavailable();
82
+ }
83
+ });
84
+ }
85
+ async markRejected(rejectedTokenDigest) { if (rejectedTokenDigest !== undefined) {
86
+ if (!/^[a-f0-9]{64}$/u.test(rejectedTokenDigest))
87
+ throw unavailable();
88
+ const current = await readGrokBrokerCredential(this.authFile);
89
+ if (createHash("sha256").update(current.accessToken).digest("hex") !== rejectedTokenDigest)
90
+ throw unavailable();
91
+ } if (!this.stale)
92
+ await this.markStale(); throw unavailable(); }
93
+ isStale() { return this.stale; }
94
+ markStale() { if (this.staleWrite)
95
+ return this.staleWrite; this.stale = true; this.fence.markStale(); return this.staleWrite = (async () => { const rejected = this.lastDigest ?? (await readGrokBrokerCredential(this.authFile)).digest; await this.write({ state: "stale", generation: this.generation, sourceDigest: rejected, promotedDigest: rejected }); })(); }
96
+ async write(value) {
97
+ const root = path.join(this.home, ".daimon-broker");
98
+ await mkdir(root, { recursive: true, mode: 0o700 });
99
+ const file = path.join(root, "credential-journal.json");
100
+ const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
101
+ const handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY, 0o600);
102
+ try {
103
+ await handle.writeFile(`${JSON.stringify({ version: "noopolis.daimon.broker-credential-journal.v1", ...value })}\n`);
104
+ await handle.sync();
105
+ }
106
+ finally {
107
+ await handle.close();
108
+ }
109
+ try {
110
+ await rename(temporary, file);
111
+ const directory = await open(root, constants.O_RDONLY);
112
+ try {
113
+ await directory.sync();
114
+ }
115
+ finally {
116
+ await directory.close();
117
+ }
118
+ }
119
+ finally {
120
+ await unlink(temporary).catch(() => undefined);
121
+ }
122
+ }
123
+ }
124
+ const unavailable = () => new Error("Grok broker credential authority unavailable");
@@ -0,0 +1,5 @@
1
+ export declare function readGrokBrokerCredential(file: string): Promise<Readonly<{
2
+ accessToken: string;
3
+ digest: string;
4
+ }>>;
5
+ //# sourceMappingURL=grokBrokerCredentialReader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grokBrokerCredentialReader.d.ts","sourceRoot":"","sources":["../../src/runtime/grokBrokerCredentialReader.ts"],"names":[],"mappings":"AAIA,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAUvH"}
@@ -0,0 +1,37 @@
1
+ import { createHash } from "node:crypto";
2
+ import { constants } from "node:fs";
3
+ import { lstat, open } from "node:fs/promises";
4
+ export async function readGrokBrokerCredential(file) {
5
+ let handle;
6
+ let bytes;
7
+ try {
8
+ const before = await lstat(file);
9
+ assertFile(before);
10
+ handle = await open(file, constants.O_RDONLY | noFollow());
11
+ const opened = await handle.stat();
12
+ assertFile(opened);
13
+ if (before.dev !== opened.dev || before.ino !== opened.ino)
14
+ throw new Error();
15
+ bytes = await handle.readFile();
16
+ if (bytes.length > 64 * 1024)
17
+ throw new Error();
18
+ const after = await handle.stat();
19
+ if (after.size !== opened.size || after.mtimeMs !== opened.mtimeMs)
20
+ throw new Error();
21
+ const root = JSON.parse(bytes.toString("utf8"));
22
+ const rows = Object.values(root).filter((value) => value !== null && typeof value === "object" && !Array.isArray(value));
23
+ if (rows.length !== 1 || typeof rows[0].key !== "string" || rows[0].key.length < 32 || typeof rows[0].refresh_token !== "string" || rows[0].refresh_token.length < 16)
24
+ throw new Error();
25
+ return { accessToken: rows[0].key, digest: createHash("sha256").update(bytes).digest("hex") };
26
+ }
27
+ catch {
28
+ throw new Error("Grok broker credential authority unavailable");
29
+ }
30
+ finally {
31
+ bytes?.fill(0);
32
+ await handle?.close().catch(() => undefined);
33
+ }
34
+ }
35
+ function assertFile(entry) { if (!entry.isFile() || entry.isSymbolicLink() || Number(entry.uid) !== process.getuid?.() || Number(entry.nlink) !== 1 || (Number(entry.mode) & 0o777) !== 0o600 || Number(entry.size) < 2 || Number(entry.size) > 64 * 1024)
36
+ throw new Error(); }
37
+ function noFollow() { return constants.O_NOFOLLOW ?? 0; }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The closed model and reasoning-effort vocabulary a Grok broker worker may be
3
+ * declared with.
4
+ *
5
+ * Both halves of one declaration are consumed from this single parser: the
6
+ * worker `config.toml` renderer (`grokBrokerWorkerConfig.ts`) writes them into
7
+ * the worker's only custom model, and the provider proxy
8
+ * (`grokBrokerProxyRequest.ts`) refuses any request body that does not carry
9
+ * exactly them. Nothing is inherited: Grok 1.0.34 silently drops an effort for
10
+ * a model that does not declare effort support, and its embedded catalog
11
+ * default for `grok-4.6` is `high`.
12
+ */
13
+ import { GROK_BROKER_MODELS, GROK_BROKER_REASONING_EFFORTS } from "../contracts/grokWorkerContract.js";
14
+ export { GROK_BROKER_MODELS, GROK_BROKER_REASONING_EFFORTS };
15
+ export type GrokBrokerModel = (typeof GROK_BROKER_MODELS)[number];
16
+ export type GrokBrokerReasoningEffort = (typeof GROK_BROKER_REASONING_EFFORTS)[number];
17
+ export type GrokBrokerModelPolicy = Readonly<{
18
+ model: GrokBrokerModel;
19
+ reasoningEffort: GrokBrokerReasoningEffort;
20
+ }>;
21
+ export declare const DEFAULT_GROK_BROKER_MODEL_POLICY: GrokBrokerModelPolicy;
22
+ export declare function parseGrokBrokerModelPolicy(value?: unknown): GrokBrokerModelPolicy;
23
+ //# sourceMappingURL=grokBrokerModelPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grokBrokerModelPolicy.d.ts","sourceRoot":"","sources":["../../src/runtime/grokBrokerModelPolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAEvG,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAClE,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AACvF,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAAE,KAAK,EAAE,eAAe,CAAC;IAAC,eAAe,EAAE,yBAAyB,CAAA;CAAE,CAAC,CAAC;AAErH,eAAO,MAAM,gCAAgC,EAAE,qBAAoF,CAAC;AAEpI,wBAAgB,0BAA0B,CAAC,KAAK,GAAE,OAAY,GAAG,qBAAqB,CAUrF"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The closed model and reasoning-effort vocabulary a Grok broker worker may be
3
+ * declared with.
4
+ *
5
+ * Both halves of one declaration are consumed from this single parser: the
6
+ * worker `config.toml` renderer (`grokBrokerWorkerConfig.ts`) writes them into
7
+ * the worker's only custom model, and the provider proxy
8
+ * (`grokBrokerProxyRequest.ts`) refuses any request body that does not carry
9
+ * exactly them. Nothing is inherited: Grok 1.0.34 silently drops an effort for
10
+ * a model that does not declare effort support, and its embedded catalog
11
+ * default for `grok-4.6` is `high`.
12
+ */
13
+ import { GROK_BROKER_MODELS, GROK_BROKER_REASONING_EFFORTS } from "../contracts/grokWorkerContract.js";
14
+ export { GROK_BROKER_MODELS, GROK_BROKER_REASONING_EFFORTS };
15
+ export const DEFAULT_GROK_BROKER_MODEL_POLICY = Object.freeze({ model: "grok-4.6", reasoningEffort: "low" });
16
+ export function parseGrokBrokerModelPolicy(value = {}) {
17
+ if (value === null || typeof value !== "object" || Array.isArray(value))
18
+ throw new TypeError("invalid Grok broker model policy");
19
+ const input = value;
20
+ if (Object.keys(input).some((key) => key !== "model" && key !== "reasoningEffort"))
21
+ throw new TypeError("invalid Grok broker model policy");
22
+ const model = input.model ?? DEFAULT_GROK_BROKER_MODEL_POLICY.model;
23
+ const reasoningEffort = input.reasoningEffort ?? DEFAULT_GROK_BROKER_MODEL_POLICY.reasoningEffort;
24
+ if (!GROK_BROKER_MODELS.includes(model) || !GROK_BROKER_REASONING_EFFORTS.includes(reasoningEffort)) {
25
+ throw new TypeError("invalid Grok broker model policy");
26
+ }
27
+ return Object.freeze({ model: model, reasoningEffort: reasoningEffort });
28
+ }
@@ -0,0 +1,106 @@
1
+ import { type EngineBrokerServiceRegistration } from "./engineBrokerServiceConfig.js";
2
+ import { type EngineBrokerTurnLimits } from "./engineBrokerTurnAccounting.js";
3
+ import type { GrokBrokerModel, GrokBrokerReasoningEffort } from "./grokBrokerModelPolicy.js";
4
+ import { GROK_WORKER_SANDBOX_PROFILE } from "./grokWorkerSandboxProfile.js";
5
+ export declare const GROK_BROKER_PROJECTION_VERSION: "noopolis.daimon.grok-broker-projection.v1";
6
+ /**
7
+ * Everything a consumer (Spawnfile provisioning, Paideia's native adapter, the
8
+ * root slot supervisor) needs to know about one brokered Grok agent's slot,
9
+ * computed by Daimon from the same renderers and collectors the broker attests
10
+ * against. It never reads credentials, runs a worker, or touches the realm.
11
+ */
12
+ export type OrganizationGrokBrokerProjection = Readonly<{
13
+ version: typeof GROK_BROKER_PROJECTION_VERSION;
14
+ agentId: string;
15
+ workspacePath: string;
16
+ runtimeHomePath: string;
17
+ workerUid: number;
18
+ slot: number;
19
+ profilePath: string;
20
+ profileSha256: string;
21
+ denyPaths: readonly string[];
22
+ workerConfigSha256: string;
23
+ systemPromptSha256: string;
24
+ grokCliVersion: string;
25
+ grokExecutableSha256: string;
26
+ nativeAbiVersion: number;
27
+ model: GrokBrokerModel;
28
+ reasoningEffort: GrokBrokerReasoningEffort;
29
+ limits: EngineBrokerTurnLimits;
30
+ usageLedgerPath: string;
31
+ /** The container seccomp profile the worker must run under (the pinned default-plus-userns profile bubblewrap needs). */
32
+ seccompProfileSha256: string;
33
+ attestation: Readonly<{
34
+ platform: "linux/landlock";
35
+ enforced: true;
36
+ restrictNetwork: true;
37
+ profileName: typeof GROK_WORKER_SANDBOX_PROFILE;
38
+ sandboxRuntime: "bubblewrap";
39
+ eventsPath: string;
40
+ }>;
41
+ }>;
42
+ export type OrganizationGrokBrokerProjectionOptions = Readonly<{
43
+ /** Deployment-assigned slot identity. */
44
+ slot: number;
45
+ workerUid: number;
46
+ /** The worker's home; its `GROK_HOME` is `<workerHomePath>/.grok`. */
47
+ workerHomePath: string;
48
+ architecture: "arm64" | "x64";
49
+ usageLedgerPath: string;
50
+ limits: EngineBrokerTurnLimits;
51
+ /**
52
+ * The deny entry that protects the durable wake-acceptance store: the store
53
+ * itself, or a directory containing it.
54
+ *
55
+ * Grok 1.0.34 materializes every deny target inside bubblewrap **as the
56
+ * worker uid**, so a target whose parent directory the worker cannot search
57
+ * is unplaceable and makes Grok refuse the whole profile — every turn of that
58
+ * worker then fails, not just that path. Deployments that keep the store
59
+ * under a private `state` directory (`2000:2000 0700`) therefore declare that
60
+ * directory here: it covers the store, nothing else lives there, and lifting
61
+ * the mask adds the worker no reach, where opening the parent with `o+x`
62
+ * would. The caller is the one party that knows both the layout and the
63
+ * modes; whoever recomputes this projection must pass the same value or the
64
+ * digests will not match, which is the intended fail-closed outcome.
65
+ */
66
+ acceptanceStorePath: string;
67
+ /** Evaluator and host-bind paths the deployment must keep from the worker (R4). */
68
+ denyPaths?: readonly string[];
69
+ /** sha256 of the seccomp profile bytes the deployment runs the worker under. */
70
+ seccompProfileSha256: string;
71
+ /** When the caller already holds a rendered profile digest, it must equal Daimon's. */
72
+ profileSha256?: string;
73
+ }>;
74
+ /**
75
+ * Resolve the public Grok broker projection for one agent.
76
+ *
77
+ * Paths are taken as given, never resolved: the caller (Spawnfile provisioning)
78
+ * must supply canonical, non-symlink paths — the fixed tmpfs/workspace roots it
79
+ * creates — and its provisioning must verify they are not symlinks before a
80
+ * slot is used; the broker's own attestation re-checks the worker home at
81
+ * every turn.
82
+ *
83
+ * Deterministic and I/O-free on purpose: its digest
84
+ * ({@link grokBrokerProjectionSha256}) is what the slot preflight receipt
85
+ * binds, so the supervisor that writes the receipt and the evaluator that reads
86
+ * it must compute byte-equal projections from the same inputs.
87
+ *
88
+ * The agent must be a Grok agent that *declares* its model and reasoning
89
+ * effort; nothing is defaulted. The deny list is Daimon's own protected set for
90
+ * this agent (realm, bootstrap, peers, and the mask covering the acceptance
91
+ * store) plus the caller's evaluator paths, sorted and deduplicated exactly as
92
+ * the profile renderer does. A supplied `profileSha256` that differs is
93
+ * refused.
94
+ */
95
+ export declare function resolveOrganizationGrokBrokerProjection(config: unknown, agentId: string, options: OrganizationGrokBrokerProjectionOptions): OrganizationGrokBrokerProjection;
96
+ /** sha256 over the projection's canonical JSON; what a slot preflight receipt binds. */
97
+ export declare const grokBrokerProjectionSha256: (projection: OrganizationGrokBrokerProjection) => string;
98
+ /** The `service.json` v2 registration a deployment provisions for this projection, validated by the broker's own parser. */
99
+ export declare function grokBrokerServiceRegistrationFor(projection: OrganizationGrokBrokerProjection): Readonly<Record<string, unknown>>;
100
+ /**
101
+ * Refuses a provisioned registration that does not describe this projection:
102
+ * any differing member — a weaker profile digest, another model, raised
103
+ * limits, a different ledger — is a mismatch, never a merge.
104
+ */
105
+ export declare function verifyGrokBrokerRegistrationMatchesProjection(registration: EngineBrokerServiceRegistration, projection: OrganizationGrokBrokerProjection): void;
106
+ //# sourceMappingURL=grokBrokerProjection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grokBrokerProjection.d.ts","sourceRoot":"","sources":["../../src/runtime/grokBrokerProjection.ts"],"names":[],"mappings":"AAOA,OAAO,EAAkC,KAAK,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACtH,OAAO,EAA+B,KAAK,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE3G,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,EAAE,2BAA2B,EAA2F,MAAM,+BAA+B,CAAC;AAGrK,eAAO,MAAM,8BAA8B,6CAAuC,CAAC;AAEnF;;;;;GAKG;AACH,MAAM,MAAM,gCAAgC,GAAG,QAAQ,CAAC;IACtD,OAAO,EAAE,OAAO,8BAA8B,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,eAAe,CAAC;IACvB,eAAe,EAAE,yBAAyB,CAAC;IAC3C,MAAM,EAAE,sBAAsB,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,yHAAyH;IACzH,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,QAAQ,CAAC;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAC;QAAC,eAAe,EAAE,IAAI,CAAC;QAAC,WAAW,EAAE,OAAO,2BAA2B,CAAC;QAAC,cAAc,EAAE,YAAY,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjM,CAAC,CAAC;AAEH,MAAM,MAAM,uCAAuC,GAAG,QAAQ,CAAC;IAC7D,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,OAAO,GAAG,KAAK,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,sBAAsB,CAAC;IAC/B;;;;;;;;;;;;;;OAcG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mFAAmF;IACnF,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,gFAAgF;IAChF,oBAAoB,EAAE,MAAM,CAAC;IAC7B,uFAAuF;IACvF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uCAAuC,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,uCAAuC,GAAG,gCAAgC,CA8B5K;AAED,wFAAwF;AACxF,eAAO,MAAM,0BAA0B,GAAI,YAAY,gCAAgC,KAAG,MACpB,CAAC;AAEvE,4HAA4H;AAC5H,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,gCAAgC,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAQhI;AAED;;;;GAIG;AACH,wBAAgB,6CAA6C,CAAC,YAAY,EAAE,+BAA+B,EAAE,UAAU,EAAE,gCAAgC,GAAG,IAAI,CAG/J"}