spawnfile 0.1.14 → 0.1.17

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 (546) hide show
  1. package/README.md +60 -159
  2. package/dist/audit/checksShared.d.ts +1 -1
  3. package/dist/auth/importers.d.ts +10 -0
  4. package/dist/auth/importers.js +29 -4
  5. package/dist/auth/index.d.ts +2 -0
  6. package/dist/auth/index.js +1 -0
  7. package/dist/auth/paths.d.ts +1 -1
  8. package/dist/auth/profileStore.js +9 -9
  9. package/dist/auth/targetSecretSourceFsIdentity.d.ts +40 -0
  10. package/dist/auth/targetSecretSourceFsIdentity.js +42 -0
  11. package/dist/auth/targetSecretSourceFsPublish.d.ts +2 -0
  12. package/dist/auth/targetSecretSourceFsPublish.js +3 -1
  13. package/dist/auth/targetSecretSourceFsPublishImmutable.d.ts +2 -1
  14. package/dist/auth/targetSecretSourceFsPublishImmutable.js +104 -71
  15. package/dist/auth/targetSecretSourceFsRead.js +5 -14
  16. package/dist/auth/trainingAuth.d.ts +21 -0
  17. package/dist/auth/trainingAuth.js +86 -0
  18. package/dist/auth/types.d.ts +1 -1
  19. package/dist/cli/authCommands.d.ts +1 -1
  20. package/dist/cli/authCommands.js +9 -0
  21. package/dist/cli/canaryCutoverCommand.d.ts +2 -0
  22. package/dist/cli/canaryCutoverCommand.js +30 -0
  23. package/dist/cli/capabilitiesCommand.d.ts +3 -0
  24. package/dist/cli/capabilitiesCommand.js +12 -0
  25. package/dist/cli/capabilitiesReceipt.d.ts +56 -0
  26. package/dist/cli/capabilitiesReceipt.js +56 -0
  27. package/dist/cli/compileBuildCommands.js +13 -0
  28. package/dist/cli/composedLifecycleContractSet.d.ts +21 -0
  29. package/dist/cli/composedLifecycleContractSet.js +204 -0
  30. package/dist/cli/devCommands.js +2 -0
  31. package/dist/cli/downCommand.js +19 -8
  32. package/dist/cli/evidenceExportHelperCommand.d.ts +13 -0
  33. package/dist/cli/evidenceExportHelperCommand.js +51 -0
  34. package/dist/cli/index.js +12 -3
  35. package/dist/cli/lifecycleMachine.d.ts +7 -1
  36. package/dist/cli/lifecycleMachine.js +2 -2
  37. package/dist/cli/paideiaDelegation.d.ts +17 -0
  38. package/dist/cli/paideiaDelegation.js +210 -0
  39. package/dist/cli/paideiaSupervisor.d.ts +17 -0
  40. package/dist/cli/paideiaSupervisor.js +48 -0
  41. package/dist/cli/productStateCloneCommand.d.ts +2 -0
  42. package/dist/cli/productStateCloneCommand.js +34 -0
  43. package/dist/cli/runCli.d.ts +13 -3
  44. package/dist/cli/runCli.js +37 -9
  45. package/dist/cli/targetCommands.d.ts +4 -7
  46. package/dist/cli/targetCommands.js +16 -46
  47. package/dist/cli/targetConfigPreparedPlan.d.ts +3 -0
  48. package/dist/cli/targetConfigPreparedPlan.js +74 -0
  49. package/dist/cli/targetConfigResolver.d.ts +3 -0
  50. package/dist/cli/targetConfigResolver.js +111 -0
  51. package/dist/cli/targetConfigResolverCommand.d.ts +6 -0
  52. package/dist/cli/targetConfigResolverCommand.js +43 -0
  53. package/dist/cli/targetConfigResolverContracts.d.ts +56 -0
  54. package/dist/cli/targetConfigResolverContracts.js +30 -0
  55. package/dist/cli/targetConfigResolverDocker.d.ts +4 -0
  56. package/dist/cli/targetConfigResolverDocker.js +47 -0
  57. package/dist/cli/targetConfigResolverValidation.d.ts +10 -0
  58. package/dist/cli/targetConfigResolverValidation.js +94 -0
  59. package/dist/cli/targetDefaultAuthorities.d.ts +2 -0
  60. package/dist/cli/targetDefaultAuthorities.js +3 -0
  61. package/dist/cli/targetDefaultConfig.d.ts +7 -0
  62. package/dist/cli/targetDefaultConfig.js +22 -5
  63. package/dist/cli/targetDefaultConfigStdin.js +7 -1
  64. package/dist/cli/targetDefaultHandlerFactory.js +23 -2
  65. package/dist/cli/targetDefaultHandlers.d.ts +2 -2
  66. package/dist/cli/targetProductionCommands.d.ts +5 -0
  67. package/dist/cli/targetProductionCommands.js +45 -0
  68. package/dist/cli/trainCommand.d.ts +3 -0
  69. package/dist/cli/trainCommand.js +61 -0
  70. package/dist/cli/upCommand.js +35 -6
  71. package/dist/cli/upLifecycleRecovery.d.ts +2 -2
  72. package/dist/cli/upLifecycleRecovery.js +188 -44
  73. package/dist/cli/usageCommand.d.ts +40 -0
  74. package/dist/cli/usageCommand.js +284 -0
  75. package/dist/cli/usageCommandLive.d.ts +84 -0
  76. package/dist/cli/usageCommandLive.js +95 -0
  77. package/dist/cli/usageDeploymentSource.d.ts +9 -0
  78. package/dist/cli/usageDeploymentSource.js +22 -0
  79. package/dist/cli/workspaceResourceMigrationCommand.d.ts +8 -0
  80. package/dist/cli/workspaceResourceMigrationCommand.js +36 -0
  81. package/dist/compiler/buildCompilePlanTeams.d.ts +1 -1
  82. package/dist/compiler/buildCompilePlanTeams.js +6 -1
  83. package/dist/compiler/compilePlanHelpers.js +3 -0
  84. package/dist/compiler/compileProject.d.ts +2 -0
  85. package/dist/compiler/compileProject.js +5 -1
  86. package/dist/compiler/compileProjectSupport.js +9 -0
  87. package/dist/compiler/containerArtifacts.d.ts +3 -1
  88. package/dist/compiler/containerArtifacts.js +92 -40
  89. package/dist/compiler/containerArtifactsPlans.d.ts +1 -1
  90. package/dist/compiler/containerArtifactsPlans.js +24 -7
  91. package/dist/compiler/containerArtifactsRender.d.ts +2 -1
  92. package/dist/compiler/containerArtifactsRender.js +91 -58
  93. package/dist/compiler/containerArtifactsTypes.d.ts +8 -0
  94. package/dist/compiler/containerBackedMountRender.d.ts +56 -0
  95. package/dist/compiler/containerBackedMountRender.js +101 -0
  96. package/dist/compiler/containerDaimonBrokerRender.d.ts +112 -0
  97. package/dist/compiler/containerDaimonBrokerRender.js +191 -0
  98. package/dist/compiler/containerDaimonGrokWorkerProvisioning.d.ts +38 -0
  99. package/dist/compiler/containerDaimonGrokWorkerProvisioning.js +108 -0
  100. package/dist/compiler/containerDaimonGrokWorkerRender.d.ts +172 -0
  101. package/dist/compiler/containerDaimonGrokWorkerRender.js +268 -0
  102. package/dist/compiler/containerDaimonOwnershipGuardRender.d.ts +12 -0
  103. package/dist/compiler/containerDaimonOwnershipGuardRender.js +191 -0
  104. package/dist/compiler/containerDaimonUidEntrypointRender.d.ts +24 -0
  105. package/dist/compiler/containerDaimonUidEntrypointRender.js +297 -0
  106. package/dist/compiler/containerEntrypointRender.d.ts +7 -0
  107. package/dist/compiler/containerEntrypointRender.js +28 -22
  108. package/dist/compiler/containerPersistentMounts.d.ts +30 -0
  109. package/dist/compiler/containerPersistentMounts.js +66 -0
  110. package/dist/compiler/containerReadinessPaths.d.ts +1 -0
  111. package/dist/compiler/containerReadinessPaths.js +1 -0
  112. package/dist/compiler/containerRuntimeLinkMaterializer.d.ts +2 -0
  113. package/dist/compiler/containerRuntimeLinkMaterializer.js +12 -0
  114. package/dist/compiler/containerRuntimeReadinessRender.d.ts +7 -0
  115. package/dist/compiler/containerRuntimeReadinessRender.js +40 -0
  116. package/dist/compiler/containerStateOwnershipRender.d.ts +4 -0
  117. package/dist/compiler/containerStateOwnershipRender.js +75 -0
  118. package/dist/compiler/containerTargetResources.d.ts +22 -1
  119. package/dist/compiler/containerTargetResources.js +94 -2
  120. package/dist/compiler/containerVolumeBootstrap.d.ts +3 -0
  121. package/dist/compiler/containerVolumeBootstrap.js +3 -0
  122. package/dist/compiler/containerWorkspaceResourceRender.js +49 -1
  123. package/dist/compiler/daimonTelemetryArtifacts.d.ts +2 -2
  124. package/dist/compiler/daimonTelemetryArtifacts.js +5 -10
  125. package/dist/compiler/deploymentLineage.d.ts +40 -0
  126. package/dist/compiler/deploymentLineage.js +50 -0
  127. package/dist/compiler/index.d.ts +3 -0
  128. package/dist/compiler/index.js +3 -0
  129. package/dist/compiler/initProject.d.ts +2 -0
  130. package/dist/compiler/initProject.js +39 -1
  131. package/dist/compiler/localMoltnetAuthority.d.ts +64 -0
  132. package/dist/compiler/localMoltnetAuthority.js +177 -0
  133. package/dist/compiler/memoryArtifacts.d.ts +1 -1
  134. package/dist/compiler/memoryArtifacts.js +108 -32
  135. package/dist/compiler/modelEnv.d.ts +5 -0
  136. package/dist/compiler/modelEnv.js +8 -2
  137. package/dist/compiler/moltnetArtifactPaths.d.ts +17 -12
  138. package/dist/compiler/moltnetArtifactPaths.js +17 -15
  139. package/dist/compiler/moltnetArtifactTypes.d.ts +10 -0
  140. package/dist/compiler/moltnetArtifacts.d.ts +1 -1
  141. package/dist/compiler/moltnetArtifacts.js +52 -12
  142. package/dist/compiler/moltnetBinaries.d.ts +16 -4
  143. package/dist/compiler/moltnetBinaries.js +46 -6
  144. package/dist/compiler/moltnetClientConfig.js +1 -1
  145. package/dist/compiler/moltnetConfigLowering.d.ts +3 -1
  146. package/dist/compiler/moltnetConfigLowering.js +30 -6
  147. package/dist/compiler/moltnetNodeConfig.js +1 -1
  148. package/dist/compiler/moltnetReleaseAuthority.d.ts +24 -1
  149. package/dist/compiler/moltnetReleaseAuthority.js +33 -4
  150. package/dist/compiler/moltnetRepresentativeResolution.d.ts +1 -1
  151. package/dist/compiler/moltnetRepresentativeResolution.js +2 -2
  152. package/dist/compiler/moltnetResolution.js +9 -15
  153. package/dist/compiler/moltnetRoomMemberships.js +20 -5
  154. package/dist/compiler/moltnetRoomPolicyCompatibility.d.ts +1 -1
  155. package/dist/compiler/moltnetRoomPolicyCompatibility.js +3 -1
  156. package/dist/compiler/moltnetRuntimeConfig.d.ts +1 -1
  157. package/dist/compiler/moltnetRuntimeConfig.js +22 -2
  158. package/dist/compiler/moltnetServerPlans.js +19 -0
  159. package/dist/compiler/organizationExternalParticipants.d.ts +3 -0
  160. package/dist/compiler/organizationExternalParticipants.js +176 -0
  161. package/dist/compiler/organizationIdentity.d.ts +3 -9
  162. package/dist/compiler/organizationIdentity.js +37 -270
  163. package/dist/compiler/organizationIdentityGraph.d.ts +15 -0
  164. package/dist/compiler/organizationIdentityGraph.js +115 -0
  165. package/dist/compiler/organizationReadyEvidence.d.ts +8 -0
  166. package/dist/compiler/organizationReadyEvidence.js +23 -3
  167. package/dist/compiler/runProject.d.ts +4 -2
  168. package/dist/compiler/runProject.js +32 -6
  169. package/dist/compiler/runProjectAuth.d.ts +3 -1
  170. package/dist/compiler/runProjectAuth.js +19 -3
  171. package/dist/compiler/runProjectDaimonCodexDocker.d.ts +3 -0
  172. package/dist/compiler/runProjectDaimonCodexDocker.js +36 -0
  173. package/dist/compiler/runProjectDocker.d.ts +8 -4
  174. package/dist/compiler/runProjectDocker.js +43 -18
  175. package/dist/compiler/runProjectDockerDaimonGuards.d.ts +15 -0
  176. package/dist/compiler/runProjectDockerDaimonGuards.js +122 -0
  177. package/dist/compiler/runProjectDockerReservation.d.ts +3 -0
  178. package/dist/compiler/runProjectDockerReservation.js +118 -0
  179. package/dist/compiler/runProjectLifecycle.js +1 -1
  180. package/dist/compiler/training/broker/declaration.d.ts +45 -0
  181. package/dist/compiler/training/broker/declaration.js +55 -0
  182. package/dist/compiler/training/broker/entrypoint.d.ts +39 -0
  183. package/dist/compiler/training/broker/entrypoint.js +111 -0
  184. package/dist/compiler/training/broker/index.d.ts +10 -0
  185. package/dist/compiler/training/broker/index.js +10 -0
  186. package/dist/compiler/training/broker/main.d.ts +2 -0
  187. package/dist/compiler/training/broker/main.js +14 -0
  188. package/dist/compiler/training/broker/paths.d.ts +196 -0
  189. package/dist/compiler/training/broker/paths.js +241 -0
  190. package/dist/compiler/training/broker/processes.d.ts +42 -0
  191. package/dist/compiler/training/broker/processes.js +99 -0
  192. package/dist/compiler/training/broker/projection.d.ts +51 -0
  193. package/dist/compiler/training/broker/projection.js +76 -0
  194. package/dist/compiler/training/broker/provisioning.d.ts +87 -0
  195. package/dist/compiler/training/broker/provisioning.js +213 -0
  196. package/dist/compiler/training/broker/receipt.d.ts +77 -0
  197. package/dist/compiler/training/broker/receipt.js +110 -0
  198. package/dist/compiler/training/broker/registration.d.ts +41 -0
  199. package/dist/compiler/training/broker/registration.js +102 -0
  200. package/dist/compiler/training/broker/runtime.d.ts +25 -0
  201. package/dist/compiler/training/broker/runtime.js +173 -0
  202. package/dist/compiler/training/broker/seccompRoutes.d.ts +31 -0
  203. package/dist/compiler/training/broker/seccompRoutes.js +36 -0
  204. package/dist/compiler/training/broker/supervisor.d.ts +109 -0
  205. package/dist/compiler/training/broker/supervisor.js +173 -0
  206. package/dist/compiler/training/container/contract.d.ts +31 -0
  207. package/dist/compiler/training/container/contract.js +33 -0
  208. package/dist/compiler/training/container/index.d.ts +4 -0
  209. package/dist/compiler/training/container/index.js +2 -0
  210. package/dist/compiler/training/container/launch.d.ts +18 -0
  211. package/dist/compiler/training/container/launch.js +173 -0
  212. package/dist/compiler/training/container/prepare.d.ts +8 -0
  213. package/dist/compiler/training/container/prepare.js +80 -0
  214. package/dist/compiler/training/container/process.d.ts +14 -0
  215. package/dist/compiler/training/container/process.js +70 -0
  216. package/dist/compiler/training/container/security.d.ts +36 -0
  217. package/dist/compiler/training/container/security.js +58 -0
  218. package/dist/compiler/training/context.d.ts +7 -0
  219. package/dist/compiler/training/context.js +93 -0
  220. package/dist/compiler/training/contract.d.ts +142 -0
  221. package/dist/compiler/training/contract.js +34 -0
  222. package/dist/compiler/training/index.d.ts +4 -0
  223. package/dist/compiler/training/index.js +3 -0
  224. package/dist/compiler/training/preparation/assets/Dockerfile +98 -0
  225. package/dist/compiler/training/preparation/assets/package-lock.json +3787 -0
  226. package/dist/compiler/training/preparation/broker.d.ts +21 -0
  227. package/dist/compiler/training/preparation/broker.js +43 -0
  228. package/dist/compiler/training/preparation/contextModes.d.ts +12 -0
  229. package/dist/compiler/training/preparation/contextModes.js +38 -0
  230. package/dist/compiler/training/preparation/contract.d.ts +182 -0
  231. package/dist/compiler/training/preparation/contract.js +94 -0
  232. package/dist/compiler/training/preparation/copyAssets.d.ts +1 -0
  233. package/dist/compiler/training/preparation/copyAssets.js +8 -0
  234. package/dist/compiler/training/preparation/daimonParent.d.ts +42 -0
  235. package/dist/compiler/training/preparation/daimonParent.js +114 -0
  236. package/dist/compiler/training/preparation/files.d.ts +25 -0
  237. package/dist/compiler/training/preparation/files.js +85 -0
  238. package/dist/compiler/training/preparation/image.d.ts +28 -0
  239. package/dist/compiler/training/preparation/image.js +102 -0
  240. package/dist/compiler/training/preparation/index.d.ts +3 -0
  241. package/dist/compiler/training/preparation/index.js +2 -0
  242. package/dist/compiler/training/preparation/inputs.d.ts +23 -0
  243. package/dist/compiler/training/preparation/inputs.js +93 -0
  244. package/dist/compiler/training/preparation/prepare.d.ts +33 -0
  245. package/dist/compiler/training/preparation/prepare.js +186 -0
  246. package/dist/compiler/training/preparation/scratch.d.ts +19 -0
  247. package/dist/compiler/training/preparation/scratch.js +48 -0
  248. package/dist/compiler/training/repair/compatibility.d.ts +11 -0
  249. package/dist/compiler/training/repair/compatibility.js +34 -0
  250. package/dist/compiler/training/repair/contract.d.ts +506 -0
  251. package/dist/compiler/training/repair/contract.js +31 -0
  252. package/dist/compiler/training/repair/index.d.ts +3 -0
  253. package/dist/compiler/training/repair/index.js +3 -0
  254. package/dist/compiler/training/repair/prepare.d.ts +230 -0
  255. package/dist/compiler/training/repair/prepare.js +74 -0
  256. package/dist/compiler/training/repair/witness.d.ts +203 -0
  257. package/dist/compiler/training/repair/witness.js +42 -0
  258. package/dist/compiler/types.d.ts +2 -0
  259. package/dist/compiler/upProject.d.ts +26 -1
  260. package/dist/compiler/upProject.js +117 -178
  261. package/dist/compiler/upProjectHandoff.d.ts +62 -0
  262. package/dist/compiler/upProjectHandoff.js +204 -0
  263. package/dist/compiler/upReceipt.js +49 -4
  264. package/dist/compiler/updateProjectModels.js +1 -0
  265. package/dist/compiler/view/types.d.ts +1 -1
  266. package/dist/compiler/workspaceBundleArtifacts.d.ts +3 -0
  267. package/dist/compiler/workspaceBundleArtifacts.js +106 -0
  268. package/dist/compiler/workspaceResources.d.ts +4 -1
  269. package/dist/compiler/workspaceResources.js +12 -7
  270. package/dist/deployment/artifactsExportPlan.js +51 -1
  271. package/dist/deployment/canaryCutover.d.ts +42 -0
  272. package/dist/deployment/canaryCutover.js +140 -0
  273. package/dist/deployment/candidateDiagnostics.d.ts +15 -0
  274. package/dist/deployment/candidateDiagnostics.js +90 -0
  275. package/dist/deployment/dockerLogs.js +4 -1
  276. package/dist/deployment/dockerManager.js +9 -3
  277. package/dist/deployment/dockerProbeGateway.d.ts +17 -0
  278. package/dist/deployment/dockerProbeGateway.js +17 -2
  279. package/dist/deployment/downDeployment.d.ts +5 -0
  280. package/dist/deployment/downDeployment.js +109 -8
  281. package/dist/deployment/downReceiptTypes.d.ts +17 -2
  282. package/dist/deployment/downReceiptTypes.js +17 -2
  283. package/dist/deployment/index.d.ts +4 -0
  284. package/dist/deployment/index.js +4 -0
  285. package/dist/deployment/lifecycleCompletionContracts.d.ts +66 -0
  286. package/dist/deployment/lifecycleCompletionContracts.js +34 -0
  287. package/dist/deployment/lifecycleCompletionPaths.d.ts +4 -1
  288. package/dist/deployment/lifecycleCompletionPaths.js +3 -0
  289. package/dist/deployment/lifecycleCompletionPublication.d.ts +2 -0
  290. package/dist/deployment/lifecycleCompletionPublication.js +18 -4
  291. package/dist/deployment/lifecycleCompletionStore.d.ts +1 -1
  292. package/dist/deployment/lifecycleCompletionStore.js +7 -7
  293. package/dist/deployment/lifecycleUpRecords.d.ts +11 -0
  294. package/dist/deployment/lifecycleUpRecords.js +127 -0
  295. package/dist/deployment/native/AGENTS.md +11 -0
  296. package/dist/deployment/native/rename-noreplace-arm64 +0 -0
  297. package/dist/deployment/native/rename-noreplace-arm64.provenance.json +1 -0
  298. package/dist/deployment/native/rename-noreplace-x64 +0 -0
  299. package/dist/deployment/native/rename-noreplace-x64.provenance.json +1 -0
  300. package/dist/deployment/noReplaceActivation.d.ts +17 -0
  301. package/dist/deployment/noReplaceActivation.js +50 -0
  302. package/dist/deployment/organizationHandoffAuthorityFsBudget.d.ts +110 -0
  303. package/dist/deployment/organizationHandoffAuthorityFsBudget.js +156 -0
  304. package/dist/deployment/organizationHandoffAuthorityFsClient.js +82 -27
  305. package/dist/deployment/organizationHandoffAuthorityFsElection.d.ts +21 -0
  306. package/dist/deployment/organizationHandoffAuthorityFsElection.js +57 -0
  307. package/dist/deployment/organizationHandoffAuthorityFsWorker.js +254 -108
  308. package/dist/deployment/organizationHandoffAuthorityFsWorkerStall.fixture.d.ts +1 -0
  309. package/dist/deployment/organizationHandoffAuthorityFsWorkerStall.fixture.js +16 -0
  310. package/dist/deployment/organizationHandoffAuthorityStore.js +14 -7
  311. package/dist/deployment/organizationHandoffAuthorityTypes.d.ts +2 -2
  312. package/dist/deployment/organizationHandoffAuthorityTypes.js +2 -1
  313. package/dist/deployment/organizationReady.d.ts +2 -0
  314. package/dist/deployment/organizationReady.js +36 -4
  315. package/dist/deployment/productStateClone.d.ts +43 -0
  316. package/dist/deployment/productStateClone.js +319 -0
  317. package/dist/deployment/upLifecycleRecoveryState.d.ts +23 -0
  318. package/dist/deployment/upLifecycleRecoveryState.js +12 -0
  319. package/dist/deployment/upReceiptTypes.d.ts +32 -6
  320. package/dist/deployment/upReceiptTypes.js +29 -2
  321. package/dist/deployment/workspaceResourceMigration.d.ts +55 -0
  322. package/dist/deployment/workspaceResourceMigration.js +315 -0
  323. package/dist/dev/project.d.ts +7 -0
  324. package/dist/dev/project.js +9 -0
  325. package/dist/distribution/consumeImage.d.ts +2 -0
  326. package/dist/distribution/consumeImage.js +98 -73
  327. package/dist/distribution/consumeImageDaimonDocker.d.ts +3 -0
  328. package/dist/distribution/consumeImageDaimonDocker.js +45 -0
  329. package/dist/distribution/consumeImageLifecycle.d.ts +17 -0
  330. package/dist/distribution/consumeImageLifecycle.js +231 -0
  331. package/dist/distribution/consumeImageSupport.d.ts +12 -0
  332. package/dist/distribution/consumeImageSupport.js +15 -0
  333. package/dist/distribution/distributionReportSchema.d.ts +11 -1
  334. package/dist/distribution/distributionReportSchema.js +15 -2
  335. package/dist/distribution/dockerRunner.d.ts +6 -1
  336. package/dist/distribution/dockerRunner.js +31 -4
  337. package/dist/distribution/imageRuntimeAuth.d.ts +9 -1
  338. package/dist/distribution/imageRuntimeAuth.js +70 -1
  339. package/dist/distribution/index.d.ts +1 -1
  340. package/dist/distribution/index.js +1 -1
  341. package/dist/distribution/preflight.js +5 -1
  342. package/dist/distribution/types.d.ts +14 -1
  343. package/dist/distribution/types.js +3 -0
  344. package/dist/evidenceExportHelper/boundedExecutor.d.ts +3 -0
  345. package/dist/evidenceExportHelper/boundedExecutor.js +33 -0
  346. package/dist/evidenceExportHelper/helperProgram.mjs +156 -0
  347. package/dist/evidenceExportHelper/index.d.ts +4 -0
  348. package/dist/evidenceExportHelper/index.js +4 -0
  349. package/dist/evidenceExportHelper/preparedAuthority.d.ts +64 -0
  350. package/dist/evidenceExportHelper/preparedAuthority.js +228 -0
  351. package/dist/evidenceExportHelper/preparedBuilder.d.ts +10 -0
  352. package/dist/evidenceExportHelper/preparedBuilder.js +183 -0
  353. package/dist/evidenceExportHelper/preparedBuilderTypes.d.ts +19 -0
  354. package/dist/evidenceExportHelper/preparedBuilderTypes.js +1 -0
  355. package/dist/evidenceExportHelper/recipe.d.ts +7 -0
  356. package/dist/evidenceExportHelper/recipe.js +83 -0
  357. package/dist/filesystem/io.d.ts +2 -0
  358. package/dist/filesystem/io.js +16 -1
  359. package/dist/manifest/executionSchemas.d.ts +27 -0
  360. package/dist/manifest/executionSchemas.js +21 -2
  361. package/dist/manifest/mcpSchemas.d.ts +1 -0
  362. package/dist/manifest/mcpSchemas.js +3 -0
  363. package/dist/manifest/renderSpawnfileNetworks.js +11 -0
  364. package/dist/manifest/renderSpawnfileWorkspace.js +5 -0
  365. package/dist/manifest/scheduleSchemas.d.ts +3 -1
  366. package/dist/manifest/scheduleSchemas.js +91 -5
  367. package/dist/manifest/schemas.d.ts +237 -12
  368. package/dist/manifest/schemas.js +5 -2
  369. package/dist/manifest/teamNetworkAccessSchemas.d.ts +5 -1
  370. package/dist/manifest/teamNetworkAccessSchemas.js +11 -0
  371. package/dist/manifest/teamNetworkAuthSchemas.d.ts +1 -1
  372. package/dist/manifest/teamNetworkSchemas.d.ts +17 -3
  373. package/dist/manifest/teamNetworkSchemas.js +19 -1
  374. package/dist/manifest/teamNetworkServerSchemas.d.ts +8 -3
  375. package/dist/manifest/teamNetworkServerSchemas.js +18 -2
  376. package/dist/manifest/workspaceSchemas.d.ts +16 -0
  377. package/dist/manifest/workspaceSchemas.js +11 -0
  378. package/dist/report/types.d.ts +34 -4
  379. package/dist/runtime/common.d.ts +28 -1
  380. package/dist/runtime/common.js +33 -3
  381. package/dist/runtime/container.js +49 -33
  382. package/dist/runtime/daimon/adapter.d.ts +14 -0
  383. package/dist/runtime/daimon/adapter.js +243 -0
  384. package/dist/runtime/daimon/attention.d.ts +8 -0
  385. package/dist/runtime/daimon/attention.js +32 -0
  386. package/dist/runtime/daimon/config.d.ts +25 -0
  387. package/dist/runtime/daimon/config.js +272 -0
  388. package/dist/runtime/daimon/contractManifest.d.ts +295 -0
  389. package/dist/runtime/daimon/contractManifest.js +319 -0
  390. package/dist/runtime/daimon/grokModel.d.ts +19 -0
  391. package/dist/runtime/daimon/grokModel.js +33 -0
  392. package/dist/runtime/daimon/grokWorkerConfigBytes.d.ts +26 -0
  393. package/dist/runtime/daimon/grokWorkerConfigBytes.js +36 -0
  394. package/dist/runtime/daimon/grokWorkerContract.d.ts +22 -0
  395. package/dist/runtime/daimon/grokWorkerContract.js +48 -0
  396. package/dist/runtime/daimon/memory.d.ts +57 -0
  397. package/dist/runtime/daimon/memory.js +125 -0
  398. package/dist/runtime/daimon/runAuth.d.ts +51 -0
  399. package/dist/runtime/daimon/runAuth.js +279 -0
  400. package/dist/runtime/daimon/runtimeIdentity.d.ts +22 -0
  401. package/dist/runtime/daimon/runtimeIdentity.js +22 -0
  402. package/dist/runtime/daimon/scheduleAuthority.d.ts +3 -0
  403. package/dist/runtime/daimon/scheduleAuthority.js +17 -0
  404. package/dist/runtime/index.d.ts +4 -0
  405. package/dist/runtime/index.js +4 -0
  406. package/dist/runtime/install.d.ts +3 -0
  407. package/dist/runtime/install.js +3 -0
  408. package/dist/runtime/localDaimonAuthority.d.ts +11 -0
  409. package/dist/runtime/localDaimonAuthority.js +77 -0
  410. package/dist/runtime/mnemeMcp.d.ts +13 -0
  411. package/dist/runtime/mnemeMcp.js +26 -0
  412. package/dist/runtime/openclaw/adapter.js +2 -2
  413. package/dist/runtime/pi/adapter.d.ts +0 -1
  414. package/dist/runtime/pi/adapter.js +2 -6
  415. package/dist/runtime/pi/appCliSource.js +1 -1
  416. package/dist/runtime/pi/appScheduleSource.js +6 -2
  417. package/dist/runtime/pi/appTemplateTypes.d.ts +1 -1
  418. package/dist/runtime/picoclaw/adapter.js +2 -2
  419. package/dist/runtime/registry.d.ts +3 -0
  420. package/dist/runtime/registry.js +19 -2
  421. package/dist/runtime/scheduleUtils.d.ts +1 -0
  422. package/dist/runtime/scheduleUtils.js +5 -1
  423. package/dist/runtime/types.d.ts +25 -0
  424. package/dist/runtime/usageLedger.d.ts +158 -0
  425. package/dist/runtime/usageLedger.js +269 -0
  426. package/dist/runtime/usageLedgerRead.d.ts +48 -0
  427. package/dist/runtime/usageLedgerRead.js +102 -0
  428. package/dist/runtime/usageRequestLedger.d.ts +42 -0
  429. package/dist/runtime/usageRequestLedger.js +72 -0
  430. package/dist/shared/daimonCodexDocker.d.ts +32 -0
  431. package/dist/shared/daimonCodexDocker.js +120 -0
  432. package/dist/shared/daimonGrokSeccompProfile.d.ts +10 -0
  433. package/dist/shared/daimonGrokSeccompProfile.js +11 -0
  434. package/dist/shared/index.d.ts +2 -0
  435. package/dist/shared/index.js +2 -0
  436. package/dist/shared/types.d.ts +1 -1
  437. package/dist/shared/volumeNames.d.ts +6 -0
  438. package/dist/shared/volumeNames.js +14 -0
  439. package/dist/target/dockerArtifactsProvider.js +34 -7
  440. package/dist/target/dockerBaseImage.d.ts +2 -0
  441. package/dist/target/dockerBaseImage.js +11 -0
  442. package/dist/target/dockerCommandExecutor.d.ts +11 -0
  443. package/dist/target/dockerCommandExecutor.js +53 -2
  444. package/dist/target/dockerCommandExecutorCore.d.ts +2 -1
  445. package/dist/target/dockerCommandExecutorCore.js +4 -2
  446. package/dist/target/dockerPublicArtifactSnapshot.d.ts +3 -3
  447. package/dist/target/dockerPublicArtifactSnapshot.js +17 -33
  448. package/dist/target/dockerTarget.d.ts +1 -0
  449. package/dist/target/dockerTargetBinding.d.ts +1 -2
  450. package/dist/target/dockerTargetBinding.js +2 -3
  451. package/dist/target/dockerTargetExecFile.d.ts +19 -0
  452. package/dist/target/dockerTargetExecFile.js +194 -0
  453. package/dist/target/dockerWorldServiceProvider.d.ts +4 -0
  454. package/dist/target/dockerWorldServiceProvider.js +13 -1
  455. package/dist/target/evidenceExport.d.ts +3 -1
  456. package/dist/target/evidenceExport.js +12 -3
  457. package/dist/target/evidenceExportOperationsTestKit.js +3 -3
  458. package/dist/target/evidenceExportProvider.d.ts +2 -0
  459. package/dist/target/evidenceExportProvider.js +15 -5
  460. package/dist/target/publicArtifactSnapshot.d.ts +31 -0
  461. package/dist/target/publicArtifactSnapshot.js +37 -3
  462. package/examples/README.md +45 -0
  463. package/examples/agent-with-subagents/AGENTS.md +3 -0
  464. package/examples/agent-with-subagents/Spawnfile +30 -0
  465. package/examples/agent-with-subagents/subagents/critic/AGENTS.md +3 -0
  466. package/examples/agent-with-subagents/subagents/critic/Spawnfile +15 -0
  467. package/examples/agent-with-subagents/subagents/researcher/AGENTS.md +3 -0
  468. package/examples/agent-with-subagents/subagents/researcher/Spawnfile +17 -0
  469. package/examples/daimon-org/Spawnfile +68 -0
  470. package/examples/daimon-org/TEAM.md +4 -0
  471. package/examples/daimon-org/agents/mapper/AGENTS.md +4 -0
  472. package/examples/daimon-org/agents/mapper/Spawnfile +37 -0
  473. package/examples/daimon-org/shared/skills/file-note/SKILL.md +9 -0
  474. package/examples/daimon-org/teams/review/Spawnfile +53 -0
  475. package/examples/daimon-org/teams/review/agents/reviewer/AGENTS.md +4 -0
  476. package/examples/daimon-org/teams/review/agents/reviewer/Spawnfile +37 -0
  477. package/examples/daimon-public-host/AGENTS.md +3 -0
  478. package/examples/daimon-public-host/Spawnfile +21 -0
  479. package/examples/distribution-org/Spawnfile +43 -0
  480. package/examples/distribution-org/TEAM.md +4 -0
  481. package/examples/distribution-org/agents/coordinator/AGENTS.md +1 -0
  482. package/examples/distribution-org/agents/coordinator/Spawnfile +20 -0
  483. package/examples/distribution-org/agents/researcher/AGENTS.md +1 -0
  484. package/examples/distribution-org/agents/researcher/Spawnfile +20 -0
  485. package/examples/jungian-daimon-org/Spawnfile +41 -0
  486. package/examples/jungian-daimon-org/TEAM.md +21 -0
  487. package/examples/jungian-daimon-org/teams/luna/Spawnfile +47 -0
  488. package/examples/jungian-daimon-org/teams/luna/TEAM.md +4 -0
  489. package/examples/jungian-daimon-org/teams/luna/agents/animus/AGENTS.md +10 -0
  490. package/examples/jungian-daimon-org/teams/luna/agents/animus/Spawnfile +33 -0
  491. package/examples/jungian-daimon-org/teams/luna/agents/representative/AGENTS.md +21 -0
  492. package/examples/jungian-daimon-org/teams/luna/agents/representative/Spawnfile +30 -0
  493. package/examples/jungian-daimon-org/teams/luna/agents/shadow/AGENTS.md +10 -0
  494. package/examples/jungian-daimon-org/teams/luna/agents/shadow/Spawnfile +33 -0
  495. package/examples/jungian-daimon-org/teams/selene/Spawnfile +47 -0
  496. package/examples/jungian-daimon-org/teams/selene/TEAM.md +4 -0
  497. package/examples/jungian-daimon-org/teams/selene/agents/animus/AGENTS.md +10 -0
  498. package/examples/jungian-daimon-org/teams/selene/agents/animus/Spawnfile +33 -0
  499. package/examples/jungian-daimon-org/teams/selene/agents/representative/AGENTS.md +19 -0
  500. package/examples/jungian-daimon-org/teams/selene/agents/representative/Spawnfile +33 -0
  501. package/examples/jungian-daimon-org/teams/selene/agents/shadow/AGENTS.md +10 -0
  502. package/examples/jungian-daimon-org/teams/selene/agents/shadow/Spawnfile +30 -0
  503. package/examples/mixed-runtime-org/Spawnfile +71 -0
  504. package/examples/mixed-runtime-org/TEAM.md +8 -0
  505. package/examples/mixed-runtime-org/agents/analyst/AGENTS.md +8 -0
  506. package/examples/mixed-runtime-org/agents/analyst/Spawnfile +27 -0
  507. package/examples/mixed-runtime-org/agents/conductor/AGENTS.md +8 -0
  508. package/examples/mixed-runtime-org/agents/conductor/Spawnfile +27 -0
  509. package/examples/mixed-runtime-org/agents/localist/AGENTS.md +7 -0
  510. package/examples/mixed-runtime-org/agents/localist/Spawnfile +50 -0
  511. package/examples/moltnet-team-chat/Spawnfile +43 -0
  512. package/examples/moltnet-team-chat/TEAM.md +5 -0
  513. package/examples/moltnet-team-chat/agents/coordinator/AGENTS.md +9 -0
  514. package/examples/moltnet-team-chat/agents/coordinator/Spawnfile +26 -0
  515. package/examples/moltnet-team-chat/teams/analysis/Spawnfile +23 -0
  516. package/examples/moltnet-team-chat/teams/analysis/TEAM.md +3 -0
  517. package/examples/moltnet-team-chat/teams/analysis/agents/observer/AGENTS.md +5 -0
  518. package/examples/moltnet-team-chat/teams/analysis/agents/observer/Spawnfile +19 -0
  519. package/examples/moltnet-team-chat/teams/analysis/agents/representative/AGENTS.md +5 -0
  520. package/examples/moltnet-team-chat/teams/analysis/agents/representative/Spawnfile +19 -0
  521. package/examples/moltnet-team-chat/teams/field/Spawnfile +41 -0
  522. package/examples/moltnet-team-chat/teams/field/TEAM.md +3 -0
  523. package/examples/moltnet-team-chat/teams/field/agents/observer/AGENTS.md +5 -0
  524. package/examples/moltnet-team-chat/teams/field/agents/observer/Spawnfile +26 -0
  525. package/examples/moltnet-team-chat/teams/field/agents/representative/AGENTS.md +11 -0
  526. package/examples/moltnet-team-chat/teams/field/agents/representative/Spawnfile +26 -0
  527. package/examples/single-agent/AGENTS.md +3 -0
  528. package/examples/single-agent/HEARTBEAT.md +3 -0
  529. package/examples/single-agent/IDENTITY.md +3 -0
  530. package/examples/single-agent/MEMORY.md +3 -0
  531. package/examples/single-agent/SOUL.md +3 -0
  532. package/examples/single-agent/Spawnfile +41 -0
  533. package/examples/single-agent/skills/web_search/SKILL.md +6 -0
  534. package/moltnet-releases.json +5 -4
  535. package/package.json +36 -9
  536. package/runtimes.yaml +5 -2
  537. package/dist/cli/targetWorldClockCrossProcess.test-helper.d.ts +0 -13
  538. package/dist/cli/targetWorldClockCrossProcess.test-helper.js +0 -109
  539. package/dist/deployment/providerRuntimeBoundaryScanner.test-helper.d.ts +0 -8
  540. package/dist/deployment/providerRuntimeBoundaryScanner.test-helper.js +0 -60
  541. package/dist/deployment/simfileFixtureBoundary.test-helper.d.ts +0 -8
  542. package/dist/deployment/simfileFixtureBoundary.test-helper.js +0 -103
  543. package/dist/ownership/simfileRunOperatorInputs.d.ts +0 -103
  544. package/dist/ownership/simfileRunOperatorInputs.js +0 -139
  545. package/dist/target/cleanupRunDocker.test-helper.d.ts +0 -67
  546. package/dist/target/cleanupRunDocker.test-helper.js +0 -238
@@ -0,0 +1,102 @@
1
+ import path from "node:path";
2
+ import { SpawnfileError } from "../../../shared/index.js";
3
+ import { DAIMON_GROK_BROKER_MODELS, DAIMON_GROK_BROKER_REASONING_EFFORTS, DAIMON_GROK_ENGINE_BROKER } from "../../../runtime/daimon/contractManifest.js";
4
+ import { DAIMON_GROK_WORKER_HOME_DIRECTORY, daimonGrokWorkerSandboxProfileSha256, renderDaimonGrokWorkerSandboxProfile, resolveDaimonGrokWorkerConfig } from "../../../runtime/daimon/grokWorkerContract.js";
5
+ import { DAIMON_GROK_BASE_PROFILE_GRANTS, assertCanonicalRegisteredPath } from "../../containerDaimonGrokWorkerRender.js";
6
+ import { TRAINING_ADDED_DENY_PATHS, TRAINING_BOOTSTRAP_MOUNT, TRAINING_DEFERRED_DENY_PATHS, TRAINING_REALM_MOUNT, TRAINING_SLOT_INDEX, TRAINING_SLOT_RUNTIME_HOME, TRAINING_SLOT_STATE_ROOT, TRAINING_SLOT_USAGE_LEDGER, TRAINING_SLOT_WORKSPACE, TRAINING_WORKER_HOME, TRAINING_WORKER_UID } from "./paths.js";
7
+ const fail = (message) => {
8
+ throw new SpawnfileError("compile_error", message);
9
+ };
10
+ const within = (candidate, root) => candidate === root || candidate.startsWith(`${root}/`);
11
+ /**
12
+ * The one training slot's deny list: Daimon's own protected set for a
13
+ * single-agent organization (Grok bootstrap, realm, and the slot state root that
14
+ * holds the wake-acceptance store) plus everything this container provisions that the subject must not read —
15
+ * the evaluator roots, the caller's protected `/run/paideia` paths, the broker
16
+ * control and registration roots, the grant home root, the inference ledger,
17
+ * the per-slot ledger, turn store and supervisor socket directory.
18
+ *
19
+ * The same two refusals the production render enforces apply here: an entry
20
+ * that equals or contains a Grok 1.0.34 base-profile grant makes Grok refuse
21
+ * the profile outright, and masks cannot nest, so an entry covered by another
22
+ * entry is a provisioning bug rather than something to silently drop.
23
+ */
24
+ export const resolveTrainingGrokDenyPaths = (added = TRAINING_ADDED_DENY_PATHS) => {
25
+ // The wake-acceptance store is masked through `TRAINING_SLOT_STATE_ROOT`, never directly: Grok 1.0.34
26
+ // materializes every deny target inside bubblewrap AS THE WORKER UID, and the store's parent is
27
+ // `2000:2000 0700`, so the store itself is unplaceable and would make Grok refuse the whole profile
28
+ // (`.runtime/grok-deny-placement/EVIDENCE.md`). The state root covers it and nothing else lives there.
29
+ const daimonOwn = [TRAINING_BOOTSTRAP_MOUNT, TRAINING_REALM_MOUNT, TRAINING_SLOT_STATE_ROOT];
30
+ const grokHome = path.posix.join(TRAINING_WORKER_HOME, DAIMON_GROK_WORKER_HOME_DIRECTORY);
31
+ const grants = [
32
+ ...DAIMON_GROK_BASE_PROFILE_GRANTS, TRAINING_SLOT_WORKSPACE, grokHome,
33
+ path.posix.join(grokHome, "sessions"), path.posix.join(TRAINING_WORKER_HOME, "tmp")
34
+ ];
35
+ const candidates = [...new Set([...daimonOwn, ...added])].sort();
36
+ for (const entry of candidates) {
37
+ assertCanonicalRegisteredPath("deny path", entry);
38
+ const grant = grants.find((candidate) => within(candidate, entry));
39
+ if (grant)
40
+ fail(`Training Grok deny path ${entry} equals or contains the base profile grant ${grant}; Grok refuses such a profile`);
41
+ if (within(TRAINING_SLOT_WORKSPACE, entry) || within(TRAINING_WORKER_HOME, entry) || within(TRAINING_SLOT_RUNTIME_HOME, entry)) {
42
+ fail(`Training Grok deny path ${entry} would hide the subject's own workspace, home, or runtime home`);
43
+ }
44
+ const ancestor = candidates.find((other) => other !== entry && within(entry, other));
45
+ if (ancestor)
46
+ fail(`Training Grok deny path ${ancestor} would cover ${entry}; masks cannot nest`);
47
+ }
48
+ return candidates;
49
+ };
50
+ /**
51
+ * The single brokered Grok registration a training container runs, at the
52
+ * fixed container paths in `paths.ts`. Unlike production it points
53
+ * `usageLedgerPath` at the per-slot ledger, because each trial's spend must be
54
+ * separable and a recycle wipes it; the container-wide ledger and wake fuse do
55
+ * not exist here.
56
+ */
57
+ export const resolveTrainingGrokRegistration = (input) => {
58
+ if (!input.agentId.trim())
59
+ fail("Training Grok slot requires an agent id");
60
+ if (!DAIMON_GROK_BROKER_MODELS.includes(input.model)
61
+ || !DAIMON_GROK_BROKER_REASONING_EFFORTS.includes(input.reasoningEffort)) {
62
+ fail(`Training Grok slot has no declared broker model and reasoning effort: ${input.agentId}`);
63
+ }
64
+ const home = assertCanonicalRegisteredPath("home", TRAINING_WORKER_HOME);
65
+ const grokHome = path.posix.join(home, DAIMON_GROK_WORKER_HOME_DIRECTORY);
66
+ const config = resolveDaimonGrokWorkerConfig(input.model, input.reasoningEffort);
67
+ const denyPaths = resolveTrainingGrokDenyPaths(input.denyPaths);
68
+ const profile = renderDaimonGrokWorkerSandboxProfile(denyPaths);
69
+ const eventsPath = path.posix.join(grokHome, DAIMON_GROK_ENGINE_BROKER.worker.home.sandboxEvents.relativePath);
70
+ const profilePath = path.posix.join(grokHome, "sandbox.toml");
71
+ for (const [label, value] of [["GROK_HOME", grokHome], ["profile", profilePath], ["events", eventsPath],
72
+ ["workspace", TRAINING_SLOT_WORKSPACE], ["runtime home", TRAINING_SLOT_RUNTIME_HOME],
73
+ ["usage ledger", TRAINING_SLOT_USAGE_LEDGER]])
74
+ assertCanonicalRegisteredPath(label, value);
75
+ return {
76
+ agentId: input.agentId,
77
+ config: config.bytes,
78
+ ...(input.limits === undefined ? {} : { limits: { ...input.limits } }),
79
+ configSha256: config.sha256,
80
+ deferredDenyPaths: denyPaths.filter((entry) => TRAINING_DEFERRED_DENY_PATHS.includes(entry)),
81
+ denyPaths,
82
+ eventsPath,
83
+ grokHome,
84
+ home,
85
+ model: input.model,
86
+ profile,
87
+ profilePath,
88
+ profileSha256: daimonGrokWorkerSandboxProfileSha256(denyPaths),
89
+ privateTmp: path.posix.join(home, DAIMON_GROK_ENGINE_BROKER.worker.home.privateTmp.relativeToWorkerHome),
90
+ reasoningEffort: input.reasoningEffort,
91
+ runtimeHome: TRAINING_SLOT_RUNTIME_HOME,
92
+ // Empty on purpose: training has no persistent mounts at all. Everything a trial writes under the slot
93
+ // runtime home is per-slot tmpfs the recycle wipes, and the only thing provisioned inside it is the
94
+ // setgid `tool-output/` spill directory, so the traversable `0710` home exposes nothing else.
95
+ runtimeHomeMounts: [],
96
+ slot: TRAINING_SLOT_INDEX,
97
+ spillDirectory: path.posix.join(TRAINING_SLOT_RUNTIME_HOME, DAIMON_GROK_ENGINE_BROKER.worker.home.spillDirectory.relativeToRuntimeHome),
98
+ uid: TRAINING_WORKER_UID,
99
+ usageLedgerPath: TRAINING_SLOT_USAGE_LEDGER,
100
+ workspace: TRAINING_SLOT_WORKSPACE
101
+ };
102
+ };
@@ -0,0 +1,25 @@
1
+ import type { DaimonGrokRegistration } from "../../containerDaimonGrokWorkerRender.js";
2
+ import type { TrainingBrokerDeclaration } from "./declaration.js";
3
+ import { type BrokerChild } from "./processes.js";
4
+ import type { TrainingSlotRuntime } from "./supervisor.js";
5
+ export interface TrainingSlotRuntimeOptions {
6
+ declaration: TrainingBrokerDeclaration;
7
+ registration: DaimonGrokRegistration;
8
+ projectionSha256: string;
9
+ /** Test seam: the shell the provisioning script runs in and the `/proc` it reads identities from. */
10
+ shell?: string;
11
+ procRoot?: string;
12
+ logPath?: string;
13
+ }
14
+ /**
15
+ * The real slot runtime: what `recycle` actually does to this container.
16
+ *
17
+ * Every mutation goes through the same rendered provisioning the root
18
+ * entrypoint ran at startup, so a recycled slot is byte-identically
19
+ * provisioned — including the credential journal recovery, which is how a
20
+ * recycle that lands on a `refreshing` or `stale` realm either recovers or
21
+ * fails closed with a named error instead of leaving a silently stale realm.
22
+ */
23
+ export declare const createTrainingSlotRuntime: (options: TrainingSlotRuntimeOptions) => TrainingSlotRuntime & {
24
+ children(): readonly BrokerChild[];
25
+ };
@@ -0,0 +1,173 @@
1
+ import { execFile } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
3
+ import { appendFileSync } from "node:fs";
4
+ import { chmod, chown, mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { setTimeout as pause } from "node:timers/promises";
7
+ import { promisify } from "node:util";
8
+ import { SpawnfileError } from "../../../shared/index.js";
9
+ import { DAIMON_GROK_ENGINE_BROKER } from "../../../runtime/daimon/contractManifest.js";
10
+ import { MOUNT_AWARE_CLEAR_HELPER } from "../../containerDaimonBrokerRender.js";
11
+ import { renderTrainingBrokerProvisioning, renderTrainingIdentities } from "./provisioning.js";
12
+ import { startBrokerProcesses, stopBrokerProcesses } from "./processes.js";
13
+ import { buildTrainingSlotReceipt, readGrokExecutableSha256, resolveTrainingCanaries } from "./receipt.js";
14
+ import { DAIMON_ORGANIZATION_UID, TRAINING_HOST_BIND_DENY_PATHS, TRAINING_SEALED_DENY_PATHS, TRAINING_WIPE_TARGETS, TRAINING_SLOT_GENERATION_FILE, TRAINING_SLOT_PREFLIGHT_RECEIPT, TRAINING_SLOT_TURN_STORE, TRAINING_SLOT_USAGE_DIRECTORY, TRAINING_SLOT_WORKSPACE, TRAINING_SUPERVISOR_LOG } from "./paths.js";
15
+ const run = promisify(execFile);
16
+ const quote = (value) => `'${value.replace(/'/gu, `'"'"'`)}'`;
17
+ const CREDENTIAL_JOURNAL = `${DAIMON_GROK_ENGINE_BROKER.credentialHomePath}/.daimon-broker/credential-journal.json`;
18
+ /** State the broker's credential authority may be left in; only `promoted` (or no journal at all) is settled. */
19
+ const settledJournal = async () => {
20
+ const raw = await readFile(CREDENTIAL_JOURNAL, "utf8").catch((error) => {
21
+ if (error.code === "ENOENT")
22
+ return undefined;
23
+ throw error;
24
+ });
25
+ if (raw === undefined)
26
+ return "settled";
27
+ const journal = JSON.parse(raw);
28
+ if (journal.version !== "noopolis.daimon.broker-credential-journal.v1")
29
+ throw new SpawnfileError("runtime_error", "The broker credential journal is not a recognised version");
30
+ return journal.state === "promoted" ? "settled" : journal.state === "refreshing" ? "refreshing" : "stale";
31
+ };
32
+ /** A turn is active while its registry record says so; a terminal record is finished work and never blocks a recycle. */
33
+ const activeTurns = async () => {
34
+ const names = await readdir(TRAINING_SLOT_TURN_STORE).catch((error) => {
35
+ if (error.code === "ENOENT")
36
+ return [];
37
+ throw error;
38
+ });
39
+ let active = 0;
40
+ for (const name of names) {
41
+ if (!name.endsWith(".json"))
42
+ continue;
43
+ const raw = await readFile(path.join(TRAINING_SLOT_TURN_STORE, name), "utf8").catch(() => "");
44
+ try {
45
+ if (JSON.parse(raw).state === "active")
46
+ active += 1;
47
+ }
48
+ catch { /* a half-written record is not an active turn */ }
49
+ }
50
+ return active;
51
+ };
52
+ /**
53
+ * The real slot runtime: what `recycle` actually does to this container.
54
+ *
55
+ * Every mutation goes through the same rendered provisioning the root
56
+ * entrypoint ran at startup, so a recycled slot is byte-identically
57
+ * provisioned — including the credential journal recovery, which is how a
58
+ * recycle that lands on a `refreshing` or `stale` realm either recovers or
59
+ * fails closed with a named error instead of leaving a silently stale realm.
60
+ */
61
+ export const createTrainingSlotRuntime = (options) => {
62
+ const shell = options.shell ?? "/bin/bash";
63
+ const logPath = options.logPath ?? TRAINING_SUPERVISOR_LOG;
64
+ const script = [...renderTrainingIdentities(), ...renderTrainingBrokerProvisioning(options.registration)].join("\n");
65
+ let children = [];
66
+ const log = (line) => {
67
+ const entry = `${new Date().toISOString()} ${line}\n`;
68
+ process.stderr.write(`[slot-supervisor] ${entry}`);
69
+ try {
70
+ appendFileSync(logPath, entry, { mode: 0o640 });
71
+ }
72
+ catch { /* the log is diagnostics, never the gate */ }
73
+ };
74
+ /**
75
+ * One worker-uid reachability attempt. The command below *succeeds* when the
76
+ * worker can still reach the target, so a non-zero exit is the denial.
77
+ *
78
+ * `enter` is the stronger question a sealed root needs answered: a directory
79
+ * can be unreadable (`test -r` fails) and still searchable, and a subject
80
+ * that knows `test.paideia.yaml` by name needs only search permission.
81
+ */
82
+ const probe = async (target, depth) => {
83
+ const quoted = JSON.stringify(target);
84
+ const reachable = depth === "enter"
85
+ ? `test -r ${quoted} || test -x ${quoted} || ls -1 ${quoted} >/dev/null 2>&1`
86
+ : `test -r ${quoted}`;
87
+ try {
88
+ await run("setpriv", ["--clear-groups", `--reuid=${options.registration.uid}`, `--regid=${options.registration.uid}`,
89
+ "--inh-caps=-all", "--ambient-caps=-all", "--bounding-set=-all", "--", "/bin/sh", "-c", reachable], { timeout: 10_000 });
90
+ return false;
91
+ }
92
+ catch {
93
+ return true;
94
+ }
95
+ };
96
+ return {
97
+ log,
98
+ children: () => children,
99
+ drain: async (signal) => {
100
+ for (;;) {
101
+ signal.throwIfAborted();
102
+ const state = await settledJournal();
103
+ if (state === "stale") {
104
+ // The audited provisioning below owns stale-realm recovery; it promotes the bootstrap or refuses outright.
105
+ log("credential journal is stale; the recycle will replay the root credential recovery");
106
+ return;
107
+ }
108
+ if (state === "settled" && await activeTurns() === 0)
109
+ return;
110
+ await pause(100);
111
+ }
112
+ },
113
+ stop: async () => { await stopBrokerProcesses(children, log); children = []; },
114
+ wipe: async () => {
115
+ // Root holds `CAP_CHOWN` and `CAP_DAC_READ_SEARCH` but not `CAP_DAC_OVERRIDE`, so it cannot delete
116
+ // inside a directory it handed to the worker or the broker. Reclaim each tree first, then remove it.
117
+ const targets = TRAINING_WIPE_TARGETS;
118
+ const contents = [TRAINING_SLOT_WORKSPACE, TRAINING_SLOT_USAGE_DIRECTORY];
119
+ const script = [
120
+ ...MOUNT_AWARE_CLEAR_HELPER,
121
+ // The parent has to be reclaimed too: unlinking is a write to the *directory*, and the slot hands
122
+ // several of these parents to uid 2000 or the broker. Provisioning restores every mode right after.
123
+ 'reclaim() { parent=$(dirname "$1"); chown 0:0 "$parent"; chmod u+rwx "$parent"; if [ -e "$1" ]; then chown -R 0:0 "$1"; chmod -R u+rwX "$1"; fi; }',
124
+ ...targets.map((target) => `reclaim ${quote(target)}; spawnfile_remove_tree ${quote(target)}`),
125
+ // The workspace and the per-slot ledger directory keep their own root: the registered paths must
126
+ // stay canonical across a recycle, so only what a trial put inside them goes.
127
+ ...contents.map((target) => `reclaim ${quote(target)}; spawnfile_clear_tree ${quote(target)}`)
128
+ ].join("\n");
129
+ await run(shell, ["--noprofile", "--norc", "-ceu", script], { maxBuffer: 1024 * 1024 }).catch((error) => {
130
+ const detail = error;
131
+ throw new SpawnfileError("runtime_error", `Training slot wipe failed: ${(detail.stderr ?? "").slice(-1024).trim() || "no diagnostic"}`);
132
+ });
133
+ },
134
+ provision: async () => {
135
+ const result = await run(shell, ["--noprofile", "--norc", "-ceu", script], { maxBuffer: 8 * 1024 * 1024 }).catch((error) => {
136
+ const detail = error;
137
+ throw new SpawnfileError("runtime_error", `Training slot provisioning failed: ${(detail.stderr ?? detail.stdout ?? "").slice(-2048).trim()}`);
138
+ });
139
+ if (result.stdout.trim())
140
+ log(`provisioning: ${result.stdout.trim().slice(-2048)}`);
141
+ },
142
+ start: async () => { children = await startBrokerProcesses({ log, procRoot: options.procRoot }); },
143
+ canaries: async () => resolveTrainingCanaries({
144
+ denyPaths: options.registration.denyPaths, probe, log, hostBindPaths: TRAINING_HOST_BIND_DENY_PATHS,
145
+ sealedPaths: TRAINING_SEALED_DENY_PATHS,
146
+ mountinfo: await readFile(`${options.procRoot ?? "/proc"}/self/mountinfo`, "utf8"),
147
+ unenforcedBindPolicy: options.declaration.unenforcedBindPolicy
148
+ }),
149
+ nextGeneration: async () => {
150
+ const previous = await readFile(TRAINING_SLOT_GENERATION_FILE, "utf8").catch(() => "");
151
+ const parsed = Number.parseInt(JSON.parse(previous || "{}").generation ?? "0", 10);
152
+ // Seeded from the wall clock so a container restart cannot hand out a generation an evaluator already accepted.
153
+ const generation = Math.max(Number.isSafeInteger(parsed) && parsed > 0 ? parsed + 1 : 1, Math.floor(Date.now() / 1000));
154
+ await writeFile(TRAINING_SLOT_GENERATION_FILE, `${JSON.stringify({ generation })}\n`, { mode: 0o600 });
155
+ return generation;
156
+ },
157
+ publishReceipt: async ({ generation, nonce, canaries }) => {
158
+ const receipt = buildTrainingSlotReceipt({
159
+ slot: options.registration.slot, workerUid: options.registration.uid, generation, nonce,
160
+ projectionSha256: options.projectionSha256, sandboxProfileSha256: options.registration.profileSha256,
161
+ seccompProfileSha256: options.declaration.seccompProfileSha256,
162
+ grokExecutableSha256: readGrokExecutableSha256(), canaries, createdAt: new Date()
163
+ });
164
+ const temporary = `${TRAINING_SLOT_PREFLIGHT_RECEIPT}.${randomUUID()}.tmp`;
165
+ await mkdir(path.dirname(TRAINING_SLOT_PREFLIGHT_RECEIPT), { recursive: true });
166
+ await writeFile(temporary, `${JSON.stringify(receipt)}\n`, { mode: 0o600, flag: "wx" });
167
+ await chown(temporary, 0, DAIMON_ORGANIZATION_UID);
168
+ await chmod(temporary, 0o640);
169
+ await rename(temporary, TRAINING_SLOT_PREFLIGHT_RECEIPT);
170
+ return TRAINING_SLOT_PREFLIGHT_RECEIPT;
171
+ }
172
+ };
173
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The syscalls a worker-uid namespace escape needs before it can even be
3
+ * attempted: a new user namespace, a new mount namespace, and the mount and
4
+ * unmount calls inside them.
5
+ *
6
+ * `clone`/`clone3` are deliberately absent. The pinned profile allows them only
7
+ * under an argument filter, so a static "is it allowed" question has no honest
8
+ * yes/no answer for them, and `unshare` already gates the route.
9
+ */
10
+ export declare const TRAINING_NAMESPACE_ROUTE_SYSCALLS: readonly ["unshare", "mount", "umount2", "setns"];
11
+ /**
12
+ * Whether the pinned seccomp profile lets the worker uid attempt a namespace
13
+ * escape at all — an **unconditional** `SCMP_ACT_ALLOW`, with no
14
+ * `includes.caps` (the container drops `CAP_SYS_ADMIN`) and no argument filter.
15
+ *
16
+ * This exists to keep one specific lie out of the slot receipt. When a probe
17
+ * route cannot run, the honest record is *which layer refused it*: a syscall
18
+ * the profile filters is a stronger denial than DAC and must be named as
19
+ * `seccomp`, while the same syscall refused by a profile that allows it came
20
+ * from the kernel or an LSM and must be named `kernel`. Merging the two into
21
+ * "denied" would let a filtered-syscall run read as though DAC had held.
22
+ */
23
+ export declare const pinnedProfileAllowsNamespaceRoutes: (bytes?: string) => boolean;
24
+ /**
25
+ * What to blame when the worker uid cannot open the namespace a route needs.
26
+ *
27
+ * Derived, never guessed: seccomp and a DAC/LSM refusal both surface as
28
+ * `EPERM`, so errno cannot tell them apart. The pinned profile can — Spawnfile
29
+ * ships its bytes and the declaration binds their digest.
30
+ */
31
+ export declare const trainingNamespaceDenialMechanism: (bytes?: string) => "seccomp" | "kernel";
@@ -0,0 +1,36 @@
1
+ import { DAIMON_GROK_SECCOMP_PROFILE_BYTES } from "../../../shared/daimonGrokSeccompProfile.js";
2
+ /**
3
+ * The syscalls a worker-uid namespace escape needs before it can even be
4
+ * attempted: a new user namespace, a new mount namespace, and the mount and
5
+ * unmount calls inside them.
6
+ *
7
+ * `clone`/`clone3` are deliberately absent. The pinned profile allows them only
8
+ * under an argument filter, so a static "is it allowed" question has no honest
9
+ * yes/no answer for them, and `unshare` already gates the route.
10
+ */
11
+ export const TRAINING_NAMESPACE_ROUTE_SYSCALLS = ["unshare", "mount", "umount2", "setns"];
12
+ /**
13
+ * Whether the pinned seccomp profile lets the worker uid attempt a namespace
14
+ * escape at all — an **unconditional** `SCMP_ACT_ALLOW`, with no
15
+ * `includes.caps` (the container drops `CAP_SYS_ADMIN`) and no argument filter.
16
+ *
17
+ * This exists to keep one specific lie out of the slot receipt. When a probe
18
+ * route cannot run, the honest record is *which layer refused it*: a syscall
19
+ * the profile filters is a stronger denial than DAC and must be named as
20
+ * `seccomp`, while the same syscall refused by a profile that allows it came
21
+ * from the kernel or an LSM and must be named `kernel`. Merging the two into
22
+ * "denied" would let a filtered-syscall run read as though DAC had held.
23
+ */
24
+ export const pinnedProfileAllowsNamespaceRoutes = (bytes = DAIMON_GROK_SECCOMP_PROFILE_BYTES) => {
25
+ const profile = JSON.parse(bytes);
26
+ return TRAINING_NAMESPACE_ROUTE_SYSCALLS.every((syscall) => (profile.syscalls ?? []).some((rule) => (rule.names ?? []).includes(syscall) && rule.action === "SCMP_ACT_ALLOW"
27
+ && (rule.includes?.caps ?? []).length === 0 && (rule.args ?? []).length === 0));
28
+ };
29
+ /**
30
+ * What to blame when the worker uid cannot open the namespace a route needs.
31
+ *
32
+ * Derived, never guessed: seccomp and a DAC/LSM refusal both surface as
33
+ * `EPERM`, so errno cannot tell them apart. The pinned profile can — Spawnfile
34
+ * ships its bytes and the declaration binds their digest.
35
+ */
36
+ export const trainingNamespaceDenialMechanism = (bytes) => pinnedProfileAllowsNamespaceRoutes(bytes) ? "kernel" : "seccomp";
@@ -0,0 +1,109 @@
1
+ export declare const TRAINING_SUPERVISOR_PROTOCOL: "spawnfile.training-slot-supervisor.v1";
2
+ export declare const TRAINING_SUPERVISOR_MAX_REQUEST_BYTES = 4096;
3
+ /**
4
+ * Everything the recycle verb does to the running slot. It is an interface so
5
+ * the state machine below can be tested without Docker, a broker, or root:
6
+ * the order of these calls *is* the contract, and getting it wrong (wiping
7
+ * before draining, writing a receipt before the canaries) is exactly the class
8
+ * of bug a live check finds far too late.
9
+ */
10
+ export interface TrainingSlotRuntime {
11
+ /** Waits for no active turn and a settled credential journal; throws a named error on an unrecoverable realm. */
12
+ drain(signal: AbortSignal): Promise<void>;
13
+ stop(): Promise<void>;
14
+ /** Removes worker home, slot workspace, wake-acceptance, turn store, per-slot ledger and Grok session state. */
15
+ wipe(): Promise<void>;
16
+ /** Replays the audited root provisioning: registrations, service.json, worker home, temp, spill, ledgers. */
17
+ provision(): Promise<void>;
18
+ start(): Promise<void>;
19
+ /** Worker-uid denial canaries over every deny path; throws when one is still reachable. */
20
+ canaries(): Promise<{
21
+ path: string;
22
+ method: "sandboxed-read";
23
+ result: "denied";
24
+ }[]>;
25
+ /** Writes the slot preflight receipt v2 atomically, readable by the organization uid. */
26
+ publishReceipt(input: {
27
+ generation: number;
28
+ nonce: string;
29
+ canaries: readonly {
30
+ path: string;
31
+ method: "sandboxed-read";
32
+ result: "denied";
33
+ }[];
34
+ }): Promise<string>;
35
+ /** Monotonic per-slot generation; strictly greater than every generation this slot has ever published. */
36
+ nextGeneration(): Promise<number>;
37
+ log(line: string): void;
38
+ }
39
+ /**
40
+ * Bringing a slot up, receipt included — the only way this container starts one.
41
+ *
42
+ * `provision → start` alone was the whole start-up path, and `canaries` and
43
+ * `publishReceipt` were reachable only from `recycle`. The first trial of every
44
+ * run therefore executed with no worker-uid denial evidence at all, and a
45
+ * refusal that should have cost nothing surfaced only after that trial's spend.
46
+ * Trial 1 is exactly the trial whose sealed datasets have never been probed, so
47
+ * it is the one that most needs the evidence.
48
+ *
49
+ * The receipt this publishes carries generation 1..N and a nonce of the
50
+ * container's own, so an evaluator that reads `preflight.json` before its first
51
+ * wake sees the same `noopolis.daimon.grok-slot-preflight.v2` shape a recycle
52
+ * publishes, from the same canaries.
53
+ */
54
+ export declare const startTrainingSlot: (runtime: TrainingSlotRuntime, nonce: string) => Promise<{
55
+ generation: number;
56
+ receipt: string;
57
+ canaries: number;
58
+ }>;
59
+ export interface TrainingSlotSupervisorOptions {
60
+ runtime: TrainingSlotRuntime;
61
+ /** Only this uid may recycle. Paideia, DSPy and the judges all run as it; every worker uid is refused. */
62
+ organizationUid?: number;
63
+ drainTimeoutMs?: number;
64
+ now?: () => number;
65
+ }
66
+ export interface TrainingRecycleResult {
67
+ ok: true;
68
+ verb: "recycle";
69
+ generation: number;
70
+ nonce: string;
71
+ receipt: string;
72
+ durationMs: number;
73
+ }
74
+ /**
75
+ * The single-verb root slot supervisor.
76
+ *
77
+ * One verb, one argument, no path or command ever supplied by the caller: the
78
+ * whole point of D4 is that recycling replays the container's own audited
79
+ * provisioning rather than exposing a root file-system API to the evaluator.
80
+ * Recycles are serialized — a second caller waits rather than interleaving a
81
+ * wipe with a provision.
82
+ */
83
+ export declare const createTrainingSlotSupervisor: (options: TrainingSlotSupervisorOptions) => {
84
+ /** Serialized: a recycle already in flight completes before the next one starts. */
85
+ recycle: (nonce: string, peerUid: number) => Promise<TrainingRecycleResult>;
86
+ };
87
+ export type TrainingSlotSupervisor = ReturnType<typeof createTrainingSlotSupervisor>;
88
+ /**
89
+ * Re-establishes, and re-checks on every connection, the only uid gate this
90
+ * socket has.
91
+ *
92
+ * The scope asked for `SO_PEERCRED`. Node exposes no ancillary-data or
93
+ * peer-credential API on a unix socket and no native addon ships in this
94
+ * image, so the gate is the socket node itself, which the kernel enforces on
95
+ * `connect()` exactly as it does on `open()`: the node is
96
+ * `root:<organization gid> 0660` inside a root-owned `0711` directory on
97
+ * tmpfs, where modes *are* enforced. Only uid 2000 (and root) can connect;
98
+ * uid 2200 gets `EACCES` before a byte is written. A `0600` root-owned socket
99
+ * — the literal reading of the scope — would deny the one caller it exists
100
+ * for, so this is the same restriction stated in the only mechanism available.
101
+ * The directory holds no write permission for anyone but root, so the node
102
+ * cannot be replaced by a laxer one.
103
+ */
104
+ export declare const assertTrainingSupervisorSocketIdentity: (socketPath: string, organizationGid: number) => void;
105
+ /**
106
+ * Line-delimited JSON over a unix socket. Every request is bounded,
107
+ * single-line, and must name the protocol, the one verb and nothing else.
108
+ */
109
+ export declare const serveTrainingSlotSupervisor: (supervisor: TrainingSlotSupervisor, socketPath: string, log: (line: string) => void, organizationUid?: number) => import("net").Server;
@@ -0,0 +1,173 @@
1
+ import { chmodSync, chownSync, lstatSync, rmSync } from "node:fs";
2
+ import { createServer } from "node:net";
3
+ import path from "node:path";
4
+ import { SpawnfileError } from "../../../shared/index.js";
5
+ import { DAIMON_ORGANIZATION_UID } from "./paths.js";
6
+ export const TRAINING_SUPERVISOR_PROTOCOL = "spawnfile.training-slot-supervisor.v1";
7
+ export const TRAINING_SUPERVISOR_MAX_REQUEST_BYTES = 4_096;
8
+ const NONCE = /^[a-f0-9]{64}$/u;
9
+ /**
10
+ * Bringing a slot up, receipt included — the only way this container starts one.
11
+ *
12
+ * `provision → start` alone was the whole start-up path, and `canaries` and
13
+ * `publishReceipt` were reachable only from `recycle`. The first trial of every
14
+ * run therefore executed with no worker-uid denial evidence at all, and a
15
+ * refusal that should have cost nothing surfaced only after that trial's spend.
16
+ * Trial 1 is exactly the trial whose sealed datasets have never been probed, so
17
+ * it is the one that most needs the evidence.
18
+ *
19
+ * The receipt this publishes carries generation 1..N and a nonce of the
20
+ * container's own, so an evaluator that reads `preflight.json` before its first
21
+ * wake sees the same `noopolis.daimon.grok-slot-preflight.v2` shape a recycle
22
+ * publishes, from the same canaries.
23
+ */
24
+ export const startTrainingSlot = async (runtime, nonce) => {
25
+ await runtime.provision();
26
+ await runtime.start();
27
+ const canaries = await runtime.canaries();
28
+ const generation = await runtime.nextGeneration();
29
+ const receipt = await runtime.publishReceipt({ generation, nonce, canaries });
30
+ runtime.log(`slot start generation=${generation} canaries=${canaries.length} receipt=${receipt}`);
31
+ return { generation, receipt, canaries: canaries.length };
32
+ };
33
+ /**
34
+ * The single-verb root slot supervisor.
35
+ *
36
+ * One verb, one argument, no path or command ever supplied by the caller: the
37
+ * whole point of D4 is that recycling replays the container's own audited
38
+ * provisioning rather than exposing a root file-system API to the evaluator.
39
+ * Recycles are serialized — a second caller waits rather than interleaving a
40
+ * wipe with a provision.
41
+ */
42
+ export const createTrainingSlotSupervisor = (options) => {
43
+ const organizationUid = options.organizationUid ?? DAIMON_ORGANIZATION_UID;
44
+ const drainTimeoutMs = options.drainTimeoutMs ?? 120_000;
45
+ const now = options.now ?? Date.now;
46
+ let queue = Promise.resolve();
47
+ const recycle = async (nonce, peerUid) => {
48
+ if (peerUid !== organizationUid)
49
+ throw new SpawnfileError("validation_error", `Grok slot recycle refused for uid ${peerUid}`);
50
+ if (!NONCE.test(nonce))
51
+ throw new SpawnfileError("validation_error", "Grok slot recycle requires a 32-byte hex nonce");
52
+ const started = now();
53
+ const controller = new AbortController();
54
+ const timer = setTimeout(() => controller.abort(), drainTimeoutMs);
55
+ try {
56
+ await options.runtime.drain(controller.signal);
57
+ }
58
+ finally {
59
+ clearTimeout(timer);
60
+ }
61
+ await options.runtime.stop();
62
+ await options.runtime.wipe();
63
+ await options.runtime.provision();
64
+ await options.runtime.start();
65
+ const canaries = await options.runtime.canaries();
66
+ const generation = await options.runtime.nextGeneration();
67
+ const receipt = await options.runtime.publishReceipt({ generation, nonce, canaries });
68
+ const durationMs = now() - started;
69
+ options.runtime.log(`recycle generation=${generation} canaries=${canaries.length} durationMs=${durationMs}`);
70
+ return { ok: true, verb: "recycle", generation, nonce, receipt, durationMs };
71
+ };
72
+ return {
73
+ /** Serialized: a recycle already in flight completes before the next one starts. */
74
+ recycle: (nonce, peerUid) => {
75
+ const next = queue.then(() => recycle(nonce, peerUid));
76
+ queue = next.catch(() => undefined);
77
+ return next;
78
+ }
79
+ };
80
+ };
81
+ const failure = (message) => `${JSON.stringify({ v: TRAINING_SUPERVISOR_PROTOCOL, ok: false, error: message })}\n`;
82
+ /**
83
+ * Re-establishes, and re-checks on every connection, the only uid gate this
84
+ * socket has.
85
+ *
86
+ * The scope asked for `SO_PEERCRED`. Node exposes no ancillary-data or
87
+ * peer-credential API on a unix socket and no native addon ships in this
88
+ * image, so the gate is the socket node itself, which the kernel enforces on
89
+ * `connect()` exactly as it does on `open()`: the node is
90
+ * `root:<organization gid> 0660` inside a root-owned `0711` directory on
91
+ * tmpfs, where modes *are* enforced. Only uid 2000 (and root) can connect;
92
+ * uid 2200 gets `EACCES` before a byte is written. A `0600` root-owned socket
93
+ * — the literal reading of the scope — would deny the one caller it exists
94
+ * for, so this is the same restriction stated in the only mechanism available.
95
+ * The directory holds no write permission for anyone but root, so the node
96
+ * cannot be replaced by a laxer one.
97
+ */
98
+ export const assertTrainingSupervisorSocketIdentity = (socketPath, organizationGid) => {
99
+ const directory = lstatSync(path.posix.dirname(socketPath));
100
+ if (!directory.isDirectory() || directory.uid !== 0 || directory.gid !== 0 || (directory.mode & 0o777) !== 0o711) {
101
+ throw new SpawnfileError("runtime_error", "The slot supervisor socket directory must be root-owned 0711");
102
+ }
103
+ const node = lstatSync(socketPath);
104
+ if (!node.isSocket() || node.uid !== 0 || node.gid !== organizationGid || (node.mode & 0o777) !== 0o660) {
105
+ throw new SpawnfileError("runtime_error", "The slot supervisor socket must be root-owned, organization-group 0660");
106
+ }
107
+ };
108
+ /**
109
+ * Line-delimited JSON over a unix socket. Every request is bounded,
110
+ * single-line, and must name the protocol, the one verb and nothing else.
111
+ */
112
+ export const serveTrainingSlotSupervisor = (supervisor, socketPath, log, organizationUid = DAIMON_ORGANIZATION_UID) => {
113
+ const server = createServer((socket) => {
114
+ let peerUid;
115
+ try {
116
+ assertTrainingSupervisorSocketIdentity(socketPath, organizationUid);
117
+ peerUid = organizationUid;
118
+ }
119
+ catch (error) {
120
+ log(`refusing a connection on an unverified supervisor socket: ${error instanceof Error ? error.message : "unknown"}`);
121
+ }
122
+ let buffer = "", settled = false;
123
+ socket.setTimeout(600_000, () => socket.destroy());
124
+ const answer = (line) => { settled = true; socket.end(line); };
125
+ socket.on("data", (chunk) => {
126
+ if (settled)
127
+ return;
128
+ buffer += chunk.toString("utf8");
129
+ if (Buffer.byteLength(buffer) > TRAINING_SUPERVISOR_MAX_REQUEST_BYTES) {
130
+ answer(failure("request too large"));
131
+ return;
132
+ }
133
+ const newline = buffer.indexOf("\n");
134
+ if (newline < 0)
135
+ return;
136
+ const line = buffer.slice(0, newline);
137
+ let request;
138
+ try {
139
+ request = JSON.parse(line);
140
+ }
141
+ catch {
142
+ answer(failure("request is not JSON"));
143
+ return;
144
+ }
145
+ if (request.v !== TRAINING_SUPERVISOR_PROTOCOL || request.verb !== "recycle" || typeof request.nonce !== "string"
146
+ || Object.keys(request).length !== 3) {
147
+ answer(failure("unsupported request"));
148
+ return;
149
+ }
150
+ if (peerUid === undefined) {
151
+ answer(failure("peer identity is unavailable"));
152
+ return;
153
+ }
154
+ supervisor.recycle(request.nonce, peerUid)
155
+ .then((result) => answer(`${JSON.stringify({ v: TRAINING_SUPERVISOR_PROTOCOL, ...result })}\n`))
156
+ .catch((error) => {
157
+ const message = error instanceof Error ? error.message : "recycle failed";
158
+ log(`recycle failed: ${message}`);
159
+ answer(failure(message));
160
+ });
161
+ });
162
+ socket.on("error", () => socket.destroy());
163
+ });
164
+ rmSync(socketPath, { force: true });
165
+ server.listen(socketPath, () => {
166
+ chownSync(socketPath, 0, 0);
167
+ chmodSync(socketPath, 0o660);
168
+ chownSync(socketPath, 0, organizationUid);
169
+ assertTrainingSupervisorSocketIdentity(socketPath, organizationUid);
170
+ log(`slot supervisor listening on ${socketPath}`);
171
+ });
172
+ return server;
173
+ };