@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,435 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { constants } from "node:fs";
3
+ import { spawn } from "node:child_process";
4
+ import { lstat, open, rename, unlink } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { terminateChild, trackCliChild } from "../pi/cliProcess.js";
7
+ import { GROK_SUBSCRIPTION_REALM } from "./contractManifest.js";
8
+ import { hasRefreshablePortableCredential } from "./portableCredentialAuth.js";
9
+ import { asGrokAuthenticationRejected } from "./grokAuthenticationError.js";
10
+ const AUTH_FILE = "auth.json";
11
+ const JOURNAL_FILE = "lease.json";
12
+ const STALE_FILE = "stale.json";
13
+ const BOOTSTRAP_FILE = "bootstrap.json";
14
+ const LEASE_FILE = ".daimon-lease";
15
+ const MAX_CONTROL_BYTES = 4_096;
16
+ export async function startGrokSubscriptionRealm(configuredAgents, options = {}) {
17
+ const durablePath = options.durablePath ?? GROK_SUBSCRIPTION_REALM.durableMountPath;
18
+ const bootstrapPath = options.bootstrapPath ?? GROK_SUBSCRIPTION_REALM.bootstrapMountPath;
19
+ await verifyPrivateDirectory(durablePath);
20
+ const lease = await acquireRealmLease(durablePath, options);
21
+ const agents = new Map(configuredAgents.map((agent) => [agent.id, agent]));
22
+ let tail = Promise.resolve();
23
+ let closed = false;
24
+ let closePromise;
25
+ let bootstrapDigest;
26
+ try {
27
+ bootstrapDigest = await initializeRealm(durablePath, bootstrapPath, agents);
28
+ }
29
+ catch (error) {
30
+ await terminateChild(lease).catch(() => undefined);
31
+ throw redact(error);
32
+ }
33
+ const withCredential = async (agent, operation) => {
34
+ if (closed || agents.get(agent.id)?.runtimeHomePath !== agent.runtimeHomePath)
35
+ throw redact();
36
+ let release;
37
+ const prior = tail;
38
+ tail = new Promise((resolve) => { release = resolve; });
39
+ await prior;
40
+ try {
41
+ if (closed)
42
+ throw redact();
43
+ return await runLeasedTurn(durablePath, bootstrapDigest, agent, operation, options.onTransitionForTest);
44
+ }
45
+ finally {
46
+ release();
47
+ }
48
+ };
49
+ return {
50
+ withCredential,
51
+ close: () => closePromise ??= (async () => {
52
+ closed = true;
53
+ await tail;
54
+ await terminateChild(lease);
55
+ })()
56
+ };
57
+ }
58
+ async function initializeRealm(durablePath, bootstrapPath, agents) {
59
+ const bootstrap = await readCredential(bootstrapPath);
60
+ try {
61
+ const observedBootstrap = await readBootstrap(path.join(durablePath, BOOTSTRAP_FILE));
62
+ const journal = await readJournal(path.join(durablePath, JOURNAL_FILE));
63
+ if (journal !== undefined) {
64
+ await recoverJournal(durablePath, journal, agents, observedBootstrap?.bootstrap_digest ?? bootstrap.digest);
65
+ }
66
+ const stale = await readStale(path.join(durablePath, STALE_FILE));
67
+ const authority = await readOptionalAuthority(path.join(durablePath, AUTH_FILE));
68
+ const shouldImport = stale !== undefined
69
+ ? stale.bootstrap_digest !== bootstrap.digest
70
+ : authority === undefined || (observedBootstrap !== undefined
71
+ && observedBootstrap.bootstrap_digest !== bootstrap.digest);
72
+ authority?.bytes.fill(0);
73
+ if (shouldImport) {
74
+ await atomicCredentialWrite(path.join(durablePath, AUTH_FILE), bootstrap.bytes);
75
+ await unlink(path.join(durablePath, STALE_FILE)).catch(ignoreMissing);
76
+ await syncDirectory(durablePath);
77
+ }
78
+ if (shouldImport || observedBootstrap === undefined) {
79
+ await writeBootstrap(path.join(durablePath, BOOTSTRAP_FILE), bootstrap.digest);
80
+ }
81
+ if (await readStale(path.join(durablePath, STALE_FILE)) !== undefined)
82
+ throw redact();
83
+ return bootstrap.digest;
84
+ }
85
+ finally {
86
+ bootstrap.bytes.fill(0);
87
+ }
88
+ }
89
+ async function runLeasedTurn(durablePath, bootstrapDigest, agent, operation, onTransition) {
90
+ if (await readStale(path.join(durablePath, STALE_FILE)) !== undefined)
91
+ throw redact();
92
+ await verifyPrivateDirectory(path.dirname(path.join(agent.runtimeHomePath, GROK_SUBSCRIPTION_REALM.agentCredentialRelativePath)));
93
+ const target = path.join(agent.runtimeHomePath, GROK_SUBSCRIPTION_REALM.agentCredentialRelativePath);
94
+ await assertAbsent(target);
95
+ const authority = await readCredential(path.join(durablePath, AUTH_FILE));
96
+ const journalPath = path.join(durablePath, JOURNAL_FILE);
97
+ try {
98
+ await writeJournal(journalPath, { agent_id: agent.id, source_digest: authority.digest, state: "preparing", version: "noopolis.daimon.grok-credential-lease.v1" });
99
+ await atomicCredentialWrite(target, authority.bytes);
100
+ await writeJournal(journalPath, { agent_id: agent.id, source_digest: authority.digest, state: "active", version: "noopolis.daimon.grok-credential-lease.v1" });
101
+ }
102
+ finally {
103
+ authority.bytes.fill(0);
104
+ }
105
+ let result;
106
+ let operationError;
107
+ try {
108
+ result = await operation();
109
+ }
110
+ catch (error) {
111
+ operationError = error;
112
+ }
113
+ if (asGrokAuthenticationRejected(operationError) !== undefined) {
114
+ await unlink(target).catch(ignoreMissing);
115
+ await syncDirectory(path.dirname(target));
116
+ await markStale(durablePath, bootstrapDigest);
117
+ throw redact();
118
+ }
119
+ const candidate = await tryReadCredential(target);
120
+ if (candidate === undefined) {
121
+ await unlink(target).catch(ignoreMissing);
122
+ await syncDirectory(path.dirname(target));
123
+ await markStale(durablePath, bootstrapDigest);
124
+ throw redact(operationError);
125
+ }
126
+ try {
127
+ await writeJournal(journalPath, {
128
+ agent_id: agent.id,
129
+ promoted_digest: candidate.digest,
130
+ source_digest: authority.digest,
131
+ state: "promoting",
132
+ version: "noopolis.daimon.grok-credential-lease.v1"
133
+ });
134
+ await onTransition?.("promotion_prepared");
135
+ await atomicCredentialWrite(path.join(durablePath, AUTH_FILE), candidate.bytes);
136
+ await onTransition?.("authority_replaced");
137
+ await writeJournal(journalPath, {
138
+ agent_id: agent.id,
139
+ promoted_digest: candidate.digest,
140
+ source_digest: authority.digest,
141
+ state: "promoted",
142
+ version: "noopolis.daimon.grok-credential-lease.v1"
143
+ });
144
+ await unlink(target).catch(ignoreMissing);
145
+ await syncDirectory(path.dirname(target));
146
+ await unlink(journalPath).catch(ignoreMissing);
147
+ await syncDirectory(durablePath);
148
+ }
149
+ finally {
150
+ candidate.bytes.fill(0);
151
+ }
152
+ if (operationError !== undefined)
153
+ throw operationError;
154
+ return result;
155
+ }
156
+ async function recoverJournal(durablePath, journal, agents, bootstrapDigest) {
157
+ const agent = agents.get(journal.agent_id);
158
+ const target = agent === undefined ? undefined
159
+ : path.join(agent.runtimeHomePath, GROK_SUBSCRIPTION_REALM.agentCredentialRelativePath);
160
+ if (target !== undefined)
161
+ await verifyPrivateDirectory(path.dirname(target));
162
+ const authority = await readCredential(path.join(durablePath, AUTH_FILE));
163
+ const authorityDigest = authority.digest;
164
+ try {
165
+ const expected = journal.state === "promoted" ? [journal.promoted_digest]
166
+ : journal.state === "promoting" ? [journal.source_digest, journal.promoted_digest]
167
+ : [journal.source_digest];
168
+ if (!expected.includes(authorityDigest)) {
169
+ if (target !== undefined) {
170
+ await unlink(target).catch(ignoreMissing);
171
+ await syncDirectory(path.dirname(target));
172
+ }
173
+ await markStale(durablePath, bootstrapDigest);
174
+ return;
175
+ }
176
+ }
177
+ finally {
178
+ authority.bytes.fill(0);
179
+ }
180
+ if (journal.state === "promoted") {
181
+ if (target !== undefined) {
182
+ await unlink(target).catch(ignoreMissing);
183
+ await syncDirectory(path.dirname(target));
184
+ }
185
+ await unlink(path.join(durablePath, JOURNAL_FILE)).catch(ignoreMissing);
186
+ await syncDirectory(durablePath);
187
+ return;
188
+ }
189
+ if (journal.state === "preparing") {
190
+ if (target !== undefined)
191
+ await unlink(target).catch(ignoreMissing);
192
+ await unlink(path.join(durablePath, JOURNAL_FILE)).catch(ignoreMissing);
193
+ await syncDirectory(durablePath);
194
+ return;
195
+ }
196
+ const candidate = target === undefined ? undefined : await tryReadCredential(target);
197
+ if (candidate === undefined) {
198
+ if (target !== undefined) {
199
+ await unlink(target).catch(ignoreMissing);
200
+ await syncDirectory(path.dirname(target));
201
+ }
202
+ await markStale(durablePath, bootstrapDigest);
203
+ return;
204
+ }
205
+ try {
206
+ if (journal.state === "promoting" && candidate.digest !== journal.promoted_digest) {
207
+ await markStale(durablePath, bootstrapDigest);
208
+ return;
209
+ }
210
+ if (journal.state === "active")
211
+ await writeJournal(path.join(durablePath, JOURNAL_FILE), { ...journal, promoted_digest: candidate.digest, state: "promoting" });
212
+ if (authorityDigest === journal.source_digest) {
213
+ await atomicCredentialWrite(path.join(durablePath, AUTH_FILE), candidate.bytes);
214
+ }
215
+ await writeJournal(path.join(durablePath, JOURNAL_FILE), {
216
+ ...journal, promoted_digest: candidate.digest, state: "promoted"
217
+ });
218
+ await unlink(target).catch(ignoreMissing);
219
+ await syncDirectory(path.dirname(target));
220
+ await unlink(path.join(durablePath, JOURNAL_FILE)).catch(ignoreMissing);
221
+ await syncDirectory(durablePath);
222
+ }
223
+ finally {
224
+ candidate.bytes.fill(0);
225
+ }
226
+ }
227
+ async function markStale(durablePath, bootstrapDigest) {
228
+ await atomicJsonWrite(path.join(durablePath, STALE_FILE), {
229
+ bootstrap_digest: bootstrapDigest,
230
+ version: "noopolis.daimon.grok-credential-stale.v1"
231
+ });
232
+ await unlink(path.join(durablePath, JOURNAL_FILE)).catch(ignoreMissing);
233
+ await syncDirectory(durablePath);
234
+ }
235
+ async function readCredential(file) {
236
+ let handle;
237
+ try {
238
+ const before = await lstat(file);
239
+ assertCredentialIdentity(before);
240
+ handle = await open(file, constants.O_RDONLY | noFollow());
241
+ const opened = await handle.stat();
242
+ assertCredentialIdentity(opened);
243
+ if (!sameIdentity(before, opened))
244
+ throw new Error("changed");
245
+ const bytes = await handle.readFile();
246
+ const after = await handle.stat();
247
+ if (!sameIdentity(opened, after) || !hasRefreshablePortableCredential("grok", bytes)) {
248
+ bytes.fill(0);
249
+ throw new Error("invalid");
250
+ }
251
+ return { bytes, digest: createHash("sha256").update(bytes).digest("hex") };
252
+ }
253
+ catch {
254
+ throw redact();
255
+ }
256
+ finally {
257
+ await handle?.close().catch(() => undefined);
258
+ }
259
+ }
260
+ async function tryReadCredential(file) {
261
+ try {
262
+ return await readCredential(file);
263
+ }
264
+ catch {
265
+ return undefined;
266
+ }
267
+ }
268
+ async function readOptionalAuthority(file) {
269
+ try {
270
+ return await readCredential(file);
271
+ }
272
+ catch {
273
+ try {
274
+ await lstat(file);
275
+ }
276
+ catch (error) {
277
+ if (error.code === "ENOENT")
278
+ return undefined;
279
+ }
280
+ throw redact();
281
+ }
282
+ }
283
+ async function atomicCredentialWrite(file, bytes) {
284
+ await atomicWrite(file, bytes, GROK_SUBSCRIPTION_REALM.fileMode);
285
+ const checked = await readCredential(file);
286
+ checked.bytes.fill(0);
287
+ }
288
+ async function atomicJsonWrite(file, value) {
289
+ await atomicWrite(file, Buffer.from(`${JSON.stringify(value)}\n`), 0o600);
290
+ }
291
+ async function atomicWrite(file, bytes, mode) {
292
+ const temporary = path.join(path.dirname(file), `.${path.basename(file)}.${randomUUID()}.tmp`);
293
+ let handle;
294
+ try {
295
+ handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | noFollow(), mode);
296
+ await handle.writeFile(bytes);
297
+ await handle.chmod(mode);
298
+ await handle.sync();
299
+ await handle.close();
300
+ handle = undefined;
301
+ await rename(temporary, file);
302
+ await syncDirectory(path.dirname(file));
303
+ }
304
+ catch {
305
+ throw redact();
306
+ }
307
+ finally {
308
+ await handle?.close().catch(() => undefined);
309
+ await unlink(temporary).catch(() => undefined);
310
+ }
311
+ }
312
+ async function writeJournal(file, value) { await atomicJsonWrite(file, value); }
313
+ async function readJournal(file) {
314
+ return readPrivateJson(file, (value) => {
315
+ const candidate = value;
316
+ if (candidate.version !== "noopolis.daimon.grok-credential-lease.v1" || !["active", "preparing", "promoted", "promoting"].includes(candidate.state ?? "")
317
+ || typeof candidate.agent_id !== "string" || !candidate.agent_id || !/^[a-f0-9]{64}$/u.test(candidate.source_digest ?? "")
318
+ || (["promoted", "promoting"].includes(candidate.state ?? "") && !/^[a-f0-9]{64}$/u.test(candidate.promoted_digest ?? "")))
319
+ throw new Error("invalid");
320
+ return candidate;
321
+ });
322
+ }
323
+ async function readStale(file) {
324
+ return readPrivateJson(file, (value) => {
325
+ const candidate = value;
326
+ if (candidate.version !== "noopolis.daimon.grok-credential-stale.v1" || typeof candidate.bootstrap_digest !== "string" || !/^[a-f0-9]{64}$/u.test(candidate.bootstrap_digest))
327
+ throw new Error("invalid");
328
+ return { bootstrap_digest: candidate.bootstrap_digest };
329
+ });
330
+ }
331
+ async function readBootstrap(file) {
332
+ return readPrivateJson(file, (value) => {
333
+ const candidate = value;
334
+ if (candidate.version !== "noopolis.daimon.grok-bootstrap-observation.v1" || typeof candidate.bootstrap_digest !== "string" || !/^[a-f0-9]{64}$/u.test(candidate.bootstrap_digest))
335
+ throw new Error("invalid");
336
+ return { bootstrap_digest: candidate.bootstrap_digest };
337
+ });
338
+ }
339
+ async function writeBootstrap(file, bootstrapDigest) {
340
+ await atomicJsonWrite(file, {
341
+ bootstrap_digest: bootstrapDigest,
342
+ version: "noopolis.daimon.grok-bootstrap-observation.v1"
343
+ });
344
+ }
345
+ async function readPrivateJson(file, parse) {
346
+ let handle;
347
+ let bytes;
348
+ try {
349
+ const before = await lstat(file);
350
+ assertPrivateFileIdentity(before, MAX_CONTROL_BYTES);
351
+ handle = await open(file, constants.O_RDONLY | noFollow());
352
+ const opened = await handle.stat();
353
+ assertPrivateFileIdentity(opened, MAX_CONTROL_BYTES);
354
+ if (!sameIdentity(before, opened))
355
+ throw new Error("changed");
356
+ bytes = await handle.readFile();
357
+ const after = await handle.stat();
358
+ if (!sameIdentity(opened, after))
359
+ throw new Error("changed");
360
+ return parse(JSON.parse(bytes.toString("utf8")));
361
+ }
362
+ catch (error) {
363
+ if (error.code === "ENOENT")
364
+ return undefined;
365
+ throw redact();
366
+ }
367
+ finally {
368
+ bytes?.fill(0);
369
+ await handle?.close().catch(() => undefined);
370
+ }
371
+ }
372
+ async function verifyPrivateDirectory(directory) {
373
+ try {
374
+ const entry = await lstat(directory);
375
+ if (!entry.isDirectory() || entry.isSymbolicLink() || entry.uid !== process.getuid?.() || (entry.mode & 0o777) !== GROK_SUBSCRIPTION_REALM.directoryMode)
376
+ throw new Error("unsafe");
377
+ }
378
+ catch {
379
+ throw redact();
380
+ }
381
+ }
382
+ async function assertAbsent(file) {
383
+ try {
384
+ await lstat(file);
385
+ }
386
+ catch (error) {
387
+ if (error.code === "ENOENT")
388
+ return;
389
+ }
390
+ throw redact();
391
+ }
392
+ async function acquireRealmLease(durablePath, options) {
393
+ let lock;
394
+ let child;
395
+ try {
396
+ lock = await open(path.join(durablePath, LEASE_FILE), constants.O_CREAT | constants.O_RDWR | noFollow(), 0o600);
397
+ const entry = await lock.stat();
398
+ if (!entry.isFile() || entry.uid !== process.getuid?.() || entry.nlink !== 1 || (entry.mode & 0o777) !== 0o600)
399
+ throw new Error("unsafe");
400
+ child = trackCliChild(spawn(options.shell ?? "/bin/sh", ["-c", "\"$1\" --exclusive --nonblock --conflict-exit-code 73 3 || exit 73; printf 'ready\\n'; IFS= read -r _hold || :", "daimon-grok-lease", options.flock ?? "flock"], { detached: process.platform !== "win32", env: { LANG: "C", LC_ALL: "C", PATH: process.env.PATH }, stdio: ["pipe", "pipe", "ignore", lock.fd] }));
401
+ await waitForReady(child);
402
+ return child;
403
+ }
404
+ catch {
405
+ if (child !== undefined)
406
+ await terminateChild(child).catch(() => undefined);
407
+ throw redact();
408
+ }
409
+ finally {
410
+ await lock?.close().catch(() => undefined);
411
+ }
412
+ }
413
+ async function waitForReady(child) {
414
+ await new Promise((resolve, reject) => {
415
+ const timer = setTimeout(() => reject(new Error("timeout")), 5_000);
416
+ child.stdout?.once("data", (value) => { clearTimeout(timer); value.toString("utf8") === "ready\n" ? resolve() : reject(new Error("invalid")); });
417
+ child.once("close", () => { clearTimeout(timer); reject(new Error("closed")); });
418
+ child.once("error", () => { clearTimeout(timer); reject(new Error("failed")); });
419
+ });
420
+ }
421
+ async function syncDirectory(directory) { const handle = await open(directory, constants.O_RDONLY); try {
422
+ await handle.sync();
423
+ }
424
+ finally {
425
+ await handle.close();
426
+ } }
427
+ const ignoreMissing = (error) => { if (error.code !== "ENOENT")
428
+ throw error; };
429
+ const noFollow = () => constants.O_NOFOLLOW ?? 0;
430
+ const sameIdentity = (left, right) => left.dev === right.dev && left.ino === right.ino && left.mode === right.mode && left.nlink === right.nlink && left.size === right.size && left.uid === right.uid && left.mtimeMs === right.mtimeMs;
431
+ const assertCredentialIdentity = (entry) => { if (!entry.isFile() || entry.isSymbolicLink() || Number(entry.uid) !== process.getuid?.() || Number(entry.nlink) !== 1 || (Number(entry.mode) & 0o777) !== GROK_SUBSCRIPTION_REALM.fileMode || Number(entry.size) < 1 || Number(entry.size) > GROK_SUBSCRIPTION_REALM.maxCredentialBytes)
432
+ throw new Error("unsafe"); };
433
+ const assertPrivateFileIdentity = (entry, maxBytes) => { if (!entry.isFile() || entry.isSymbolicLink() || Number(entry.uid) !== process.getuid?.() || Number(entry.nlink) !== 1 || (Number(entry.mode) & 0o777) !== 0o600 || Number(entry.size) < 1 || Number(entry.size) > maxBytes)
434
+ throw new Error("unsafe"); };
435
+ const redact = (_cause) => new Error("Grok subscription credential realm is unavailable or stale");
@@ -0,0 +1,26 @@
1
+ import type { OrganizationRuntimeAgentConfig } from "./organizationRuntime.js";
2
+ export type GrokAgent = OrganizationRuntimeAgentConfig & {
3
+ engine: {
4
+ kind: "grok";
5
+ };
6
+ };
7
+ export type GrokCredentialJournal = Readonly<{
8
+ agent_id: string;
9
+ promoted_digest?: string;
10
+ source_digest: string;
11
+ state: "active" | "preparing" | "promoted" | "promoting";
12
+ version: "noopolis.daimon.grok-credential-lease.v1";
13
+ }>;
14
+ export type GrokSubscriptionRealm = Readonly<{
15
+ withCredential<T>(agent: GrokAgent, operation: () => Promise<T>): Promise<T>;
16
+ close(): Promise<void>;
17
+ }>;
18
+ export type GrokSubscriptionRealmOptions = Readonly<{
19
+ bootstrapPath?: string;
20
+ durablePath?: string;
21
+ flock?: string;
22
+ /** @internal deterministic crash-transition test seam. */
23
+ onTransitionForTest?: (stage: "authority_replaced" | "promotion_prepared") => Promise<void> | void;
24
+ shell?: string;
25
+ }>;
26
+ //# sourceMappingURL=grokSubscriptionRealmTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grokSubscriptionRealmTypes.d.ts","sourceRoot":"","sources":["../../src/runtime/grokSubscriptionRealmTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG,8BAA8B,GAAG;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAEtF,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;IACzD,OAAO,EAAE,0CAA0C,CAAC;CACrD,CAAC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC,CAAC;AAEH,MAAM,MAAM,4BAA4B,GAAG,QAAQ,CAAC;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,GAAG,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACnG,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,170 @@
1
+ import { type GrokWorkerTmpOptions } from "./grokWorkerTmpAttestation.js";
2
+ /**
3
+ * The per-turn freshness watermark taken before the worker is launched: the
4
+ * exact inode and its byte length at that moment. Everything at or below
5
+ * `size` is pre-turn history and is never read back — a `ProfileApplied` down
6
+ * there is a replay, not evidence about this turn.
7
+ */
8
+ export type GrokWorkerAttestationSnapshot = Readonly<{
9
+ dev: number;
10
+ ino: number;
11
+ size: number;
12
+ denyPaths: readonly string[];
13
+ }>;
14
+ type Snapshot = GrokWorkerAttestationSnapshot;
15
+ export declare class GrokWorkerAttestationFailure extends Error {
16
+ readonly failureClass: "profile_missing" | "profile_invalid";
17
+ constructor(failureClass: "profile_missing" | "profile_invalid");
18
+ }
19
+ /**
20
+ * Reads the `deny` list out of a worker sandbox profile, but only after the
21
+ * bytes match `profileSha256` exactly.
22
+ *
23
+ * There is no minimum length, and a populated list is supported. Grok 1.0.13
24
+ * refused to start on any non-empty `deny` (its mode-000 placeholders failed
25
+ * an EACCES "__GROK_INSIDE_BWRAP spoof" check), so deployments rendered
26
+ * `deny = []`. Grok 1.0.34 runs every profile inside bubblewrap and enforces a
27
+ * non-empty list, and since its strict base reads all of `/run`, `/var` and
28
+ * `/tmp`, the deny list is what keeps evaluator and host-bind paths away from
29
+ * the worker. `grokWorkerSandboxProfile.ts` renders these bytes.
30
+ *
31
+ * The integrity guarantee is the hash pin, not the length. `profileSha256`
32
+ * comes from `/etc/daimon-engine-broker/service.json`, which the root
33
+ * provisioning phase writes `0440 root:2100` with `flag: 'wx'` and computes
34
+ * from the same `profileFor()` bytes it writes to the profile; the broker
35
+ * reads that config as uid 2100 and cannot rewrite it. A weaker profile
36
+ * therefore cannot be attested: changing any byte — dropping
37
+ * `restrict_network`, swapping `extends = "strict"` for a permissive base,
38
+ * renaming the profile — changes the digest and fails here. And the deny list
39
+ * this returns is not merely parsed and discarded: it is carried into the
40
+ * snapshot and re-asserted against the kernel's own `ProfileApplied`
41
+ * `deny_paths` by `parseGrokWorkerProfileApplied`, which independently
42
+ * requires `enforced`, `restrict_network`, `platform === "linux/landlock"`
43
+ * and the exact workspace. A length floor would only have caught a Spawnfile
44
+ * rendering bug that produced a trivial profile *and* pinned it consistently
45
+ * — and Spawnfile's own tests pin the rendered bytes.
46
+ */
47
+ export declare function parseGrokWorkerSandboxProfile(bytes: Uint8Array, profileSha256: string): readonly string[];
48
+ /**
49
+ * Pre-launch half of the per-turn attestation. Besides the pinned profile and
50
+ * the events watermark it requires the 1.0.34 layout: events under
51
+ * `$GROK_HOME/sessions/` (the root `sandbox-events.jsonl` stays empty on
52
+ * 1.0.34), and a root-owned read-only worker home whose `config.toml` hashes to
53
+ * the declared renderer output (`grokWorkerHomeAttestation.ts`).
54
+ *
55
+ * It also refuses a deny list bubblewrap could not materialize
56
+ * (`grokWorkerDenyPlacement.ts`), naming the entry and the ancestor that stops
57
+ * it. Without this the worker dies with a bare `bwrap: Can't create file at
58
+ * …: Permission denied` on *every* turn, because one unplaceable entry makes
59
+ * Grok refuse the whole profile. The broker cannot descend into a directory
60
+ * opened to the worker's group alone (`<runtime home>/tool-state` under a
61
+ * `2000:<worker> 0710` home), so an `EACCES` there is left undecided; root
62
+ * provisioning, which holds `CAP_DAC_READ_SEARCH`, is the authority that
63
+ * decides every entry.
64
+ */
65
+ export declare function prepareGrokWorkerAttestation(input: Readonly<{
66
+ profilePath: string;
67
+ eventsPath: string;
68
+ profileSha256: string;
69
+ workerUid: number;
70
+ workerGid?: number;
71
+ brokerGid: number;
72
+ configSha256: string;
73
+ registeredWorkers?: readonly Readonly<{
74
+ profilePath: string;
75
+ workerUid: number;
76
+ }>[];
77
+ }>, profileOwner?: Readonly<{
78
+ uid: number;
79
+ gid: number;
80
+ tmp?: GrokWorkerTmpOptions;
81
+ }>): Promise<Snapshot>;
82
+ /** The per-turn attestation input for one registration, carrying every registered worker so sibling temp is attested too. */
83
+ export declare const grokBrokerAttestationInput: <T extends Readonly<{
84
+ profilePath: string;
85
+ eventsPath: string;
86
+ profileSha256: string;
87
+ workerUid: number;
88
+ }>>(registration: T, registrations: readonly Readonly<{
89
+ profilePath: string;
90
+ workerUid: number;
91
+ }>[], configSha256: string) => T & {
92
+ brokerGid: number;
93
+ configSha256: string;
94
+ registeredWorkers: {
95
+ profilePath: string;
96
+ workerUid: number;
97
+ }[];
98
+ };
99
+ /**
100
+ * The accepted `ProfileApplied` line of one turn, as an absolute byte range of
101
+ * the events file plus its digest.
102
+ */
103
+ export type GrokWorkerAttestationLock = {
104
+ accepted?: Readonly<{
105
+ offset: number;
106
+ length: number;
107
+ digest: string;
108
+ }>;
109
+ refused?: GrokWorkerAttestationFailure["failureClass"];
110
+ };
111
+ /**
112
+ * The per-turn isolation guard: every model request of a turn, and the
113
+ * post-turn check, go through the same lock.
114
+ *
115
+ * Why the first verification is trustworthy: the proxy awaits this guard before
116
+ * *every* upstream request, including the first, and the only worker-uid
117
+ * process that exists before request 1 is the Grok the launcher started under
118
+ * the pinned profile — tool children are created only after a model response.
119
+ * So the event accepted at request 1 was written before any tool child could
120
+ * write to the (worker-owned) events file. Later requests must find that exact
121
+ * line, byte for byte, at the same offset: a `ProfileApplied` appended later —
122
+ * which a tool child could forge — is never a substitute, and once a turn has
123
+ * been refused it stays refused.
124
+ */
125
+ export declare function createGrokWorkerIsolationGuard(input: Parameters<typeof verifyGrokWorkerAttestation>[0], before: Snapshot): () => Promise<void>;
126
+ export declare function verifyGrokWorkerAttestation(input: Readonly<{
127
+ eventsPath: string;
128
+ workerUid: number;
129
+ brokerGid: number;
130
+ workspace: string;
131
+ }>, before: Snapshot, lock?: GrokWorkerAttestationLock): Promise<void>;
132
+ /**
133
+ * Requires one fully-conforming `ProfileApplied` event *somewhere* in the
134
+ * fresh region — not as its last line.
135
+ *
136
+ * `sandbox-events.jsonl` is not a profile log. Grok (1.0.13 and 1.0.34) writes its whole
137
+ * sandbox event vocabulary there — verified by reading the shipped binary:
138
+ * `ProfileApplied, ApplyFailed, FsViolation, NetViolation, BypassGranted,
139
+ * BypassDenied` (one contiguous enum blob beside the record fields
140
+ * `timestamp, event_type, read_only_paths, deny_paths, operation, target,
141
+ * command, tool_call_id`, emitted from `xai_grok_sandbox::logging`), and its
142
+ * own embedded documentation says so outright: "Sandbox events (profile
143
+ * applied, violations) are logged to `~/.grok/sandbox-events.jsonl`" (1.0.34
144
+ * moved the file to `~/.grok/sessions/`; a 1.0.34 turn logs `ProfileApplied`
145
+ * followed by an `FsViolation` for every denied read).
146
+ *
147
+ * Requiring `ProfileApplied` to be the *last* line therefore failed on the
148
+ * first denied access of any turn: the violation Grok logged next became the
149
+ * last line, this threw, the proxy's per-request isolation guard refused, and
150
+ * the turn died `profile_invalid`. Denials are the normal operating state of
151
+ * a working sandbox, so that check turned the sandbox doing its job into a
152
+ * turn failure.
153
+ *
154
+ * Scanning the region is not weaker. The region is fresh by construction —
155
+ * the caller reads only bytes above the pre-launch dev/ino/size watermark, so
156
+ * nothing here predates this turn and a stale or replayed event below it is
157
+ * unreachable. Both forms are equally forgeable by the same single actor (a
158
+ * worker-uid process, which can only exist by being a Grok that the launcher
159
+ * already started under the pinned profile), and both detect the failure this
160
+ * guard exists for: a Grok that came up without kernel enforcement, which
161
+ * emits no conforming `ProfileApplied` at all.
162
+ */
163
+ export declare function parseGrokWorkerProfileApplied(bytes: Uint8Array, workspace: string, denyPaths?: readonly string[]): void;
164
+ /** Byte range (within `bytes`) of the first fully-conforming `ProfileApplied` line. */
165
+ export declare function locateGrokWorkerProfileApplied(bytes: Uint8Array, workspace: string, denyPaths?: readonly string[]): Readonly<{
166
+ offset: number;
167
+ length: number;
168
+ }>;
169
+ export {};
170
+ //# sourceMappingURL=grokWorkerAttestation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grokWorkerAttestation.d.ts","sourceRoot":"","sources":["../../src/runtime/grokWorkerAttestation.ts"],"names":[],"mappings":"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"}