@bastani/atomic 0.9.74 → 0.9.75-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (383) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/dist/builtin/intercom/package.json +2 -2
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/CHANGELOG.md +8 -0
  5. package/dist/builtin/subagents/package.json +3 -3
  6. package/dist/builtin/subagents/skills/agent-browser/SKILL.md +8 -10
  7. package/dist/builtin/subagents/skills/agent-desktop/SKILL.md +9 -5
  8. package/dist/builtin/subagents/src/extension/index.bundle.mjs +7 -1
  9. package/dist/builtin/web-access/package.json +2 -2
  10. package/dist/builtin/workflows/CHANGELOG.md +32 -0
  11. package/dist/builtin/workflows/README.md +5 -2
  12. package/dist/builtin/workflows/builtin/{chunk-m8eg152f.js → chunk-89we7r4p.js} +1 -1
  13. package/dist/builtin/workflows/builtin/{chunk-a4fdm2cw.js → chunk-8yfssw01.js} +1 -1
  14. package/dist/builtin/workflows/builtin/{chunk-774myqzs.js → chunk-v8mb0005.js} +366 -45
  15. package/dist/builtin/workflows/builtin/{chunk-d5cxskkp.js → chunk-wh2p4qjg.js} +2 -2
  16. package/dist/builtin/workflows/builtin/goal.js +2 -2
  17. package/dist/builtin/workflows/builtin/index.d.ts +10 -0
  18. package/dist/builtin/workflows/builtin/index.js +4 -4
  19. package/dist/builtin/workflows/builtin/open-claude-design.d.ts +12 -0
  20. package/dist/builtin/workflows/builtin/open-claude-design.js +1 -1
  21. package/dist/builtin/workflows/builtin/ralph.js +2 -2
  22. package/dist/builtin/workflows/package.json +2 -2
  23. package/dist/builtin/workflows/skills/impeccable/SKILL.md +4 -4
  24. package/dist/builtin/workflows/skills/impeccable/reference/android.md +1 -1
  25. package/dist/builtin/workflows/skills/impeccable/reference/audit.md +2 -2
  26. package/dist/builtin/workflows/skills/impeccable/reference/craft-floor.md +1 -1
  27. package/dist/builtin/workflows/skills/impeccable/reference/degraded/asset-producer.md +1 -1
  28. package/dist/builtin/workflows/skills/impeccable/reference/degraded/documenter.md +4 -4
  29. package/dist/builtin/workflows/skills/impeccable/reference/degraded/finish-reviewer.md +2 -2
  30. package/dist/builtin/workflows/skills/impeccable/reference/degraded/manual-edit-applier.md +3 -2
  31. package/dist/builtin/workflows/skills/impeccable/reference/distill.md +3 -3
  32. package/dist/builtin/workflows/skills/impeccable/reference/doctor.md +1 -1
  33. package/dist/builtin/workflows/skills/impeccable/reference/document.md +3 -3
  34. package/dist/builtin/workflows/skills/impeccable/reference/harden.md +19 -0
  35. package/dist/builtin/workflows/skills/impeccable/reference/hooks.md +15 -8
  36. package/dist/builtin/workflows/skills/impeccable/reference/init.md +2 -0
  37. package/dist/builtin/workflows/skills/impeccable/reference/live.md +8 -6
  38. package/dist/builtin/workflows/skills/impeccable/reference/new-work.md +4 -4
  39. package/dist/builtin/workflows/skills/impeccable/reference/optimize.md +0 -1
  40. package/dist/builtin/workflows/skills/impeccable/reference/visualize.md +1 -1
  41. package/dist/builtin/workflows/skills/impeccable/scripts/VERSION +1 -1
  42. package/dist/builtin/workflows/skills/impeccable/scripts/command-metadata.json +2 -2
  43. package/dist/builtin/workflows/skills/impeccable/scripts/engine-checksums.txt +9 -0
  44. package/dist/builtin/workflows/skills/impeccable/scripts/impeccable +98 -44
  45. package/dist/builtin/workflows/skills/impeccable/scripts/impeccable.cmd +101 -34
  46. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-ignores.js +6 -2
  47. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser-session.js +4 -1
  48. package/dist/builtin/workflows/skills/impeccable/scripts/live-browser.js +444 -144
  49. package/dist/builtin/workflows/skills/prompt-engineer/SKILL.md +3 -1
  50. package/dist/builtin/workflows/skills/prompt-engineer/references/advanced_patterns.md +2 -2
  51. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5.md +13 -11
  52. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_1.md +10 -8
  53. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_2.md +143 -0
  54. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_haiku_5_5.md +11 -7
  55. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_4_8.md +3 -3
  56. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5.md +6 -2
  57. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5_5.md +7 -7
  58. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5.md +2 -2
  59. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_sonnet_5_5.md +3 -3
  60. package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_5.md +2 -2
  61. package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_5_6.md +2 -2
  62. package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6.md +6 -5
  63. package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_sol.md +4 -4
  64. package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_terra.md +2 -2
  65. package/dist/builtin/workflows/skills/prompt-engineer/references/quality_improvement.md +4 -3
  66. package/dist/builtin/workflows/skills/skill-creator/scripts/aggregate_benchmark.py +0 -0
  67. package/dist/builtin/workflows/skills/skill-creator/scripts/generate_report.py +0 -0
  68. package/dist/builtin/workflows/skills/skill-creator/scripts/improve_description.py +0 -0
  69. package/dist/builtin/workflows/skills/skill-creator/scripts/package_skill.py +0 -0
  70. package/dist/builtin/workflows/skills/skill-creator/scripts/quick_validate.py +0 -0
  71. package/dist/builtin/workflows/skills/skill-creator/scripts/run_eval.py +0 -0
  72. package/dist/builtin/workflows/skills/skill-creator/scripts/run_loop.py +0 -0
  73. package/dist/builtin/workflows/skills/unslop/SKILL.md +15 -34
  74. package/dist/builtin/workflows/src/durable/journal/memory-run-journal.d.ts +1 -0
  75. package/dist/builtin/workflows/src/durable/journal/values.d.ts +2 -0
  76. package/dist/builtin/workflows/src/extension/index.bundle.mjs +809 -410
  77. package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +695 -305
  78. package/dist/builtin/workflows/src/index.js +685 -295
  79. package/dist/builtin/workflows/src/local-worker-entry.mjs +695 -305
  80. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +6 -6
  81. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +2 -2
  82. package/dist/builtin/workflows/src/shared/serializable-error-families.d.ts +2 -0
  83. package/dist/bun/app-host-modules.d.ts +1 -1
  84. package/dist/bun/app-host-modules.d.ts.map +1 -1
  85. package/dist/bun/app-host-modules.js.map +1 -1
  86. package/dist/bun/internal-workflow-worker.d.ts +2 -0
  87. package/dist/bun/internal-workflow-worker.d.ts.map +1 -1
  88. package/dist/bun/internal-workflow-worker.js +2 -1
  89. package/dist/bun/internal-workflow-worker.js.map +1 -1
  90. package/dist/codemode-worker.js +2 -0
  91. package/dist/config.d.ts +8 -0
  92. package/dist/config.d.ts.map +1 -1
  93. package/dist/config.js +14 -0
  94. package/dist/config.js.map +1 -1
  95. package/dist/core/agent-session-bash.d.ts.map +1 -1
  96. package/dist/core/agent-session-bash.js +2 -1
  97. package/dist/core/agent-session-bash.js.map +1 -1
  98. package/dist/core/agent-session-blueprint-environment.d.ts +10 -0
  99. package/dist/core/agent-session-blueprint-environment.d.ts.map +1 -0
  100. package/dist/core/agent-session-blueprint-environment.js +28 -0
  101. package/dist/core/agent-session-blueprint-environment.js.map +1 -0
  102. package/dist/core/agent-session-events.d.ts.map +1 -1
  103. package/dist/core/agent-session-events.js +2 -0
  104. package/dist/core/agent-session-events.js.map +1 -1
  105. package/dist/core/agent-session-methods.d.ts +1 -0
  106. package/dist/core/agent-session-methods.d.ts.map +1 -1
  107. package/dist/core/agent-session-methods.js.map +1 -1
  108. package/dist/core/agent-session-retry.d.ts.map +1 -1
  109. package/dist/core/agent-session-retry.js +14 -4
  110. package/dist/core/agent-session-retry.js.map +1 -1
  111. package/dist/core/agent-session-runtime.d.ts +20 -0
  112. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  113. package/dist/core/agent-session-runtime.js +55 -6
  114. package/dist/core/agent-session-runtime.js.map +1 -1
  115. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  116. package/dist/core/agent-session-tool-registry.js +2 -1
  117. package/dist/core/agent-session-tool-registry.js.map +1 -1
  118. package/dist/core/agent-session.d.ts +2 -0
  119. package/dist/core/agent-session.d.ts.map +1 -1
  120. package/dist/core/agent-session.js +2 -0
  121. package/dist/core/agent-session.js.map +1 -1
  122. package/dist/core/async-scope.d.ts +13 -0
  123. package/dist/core/async-scope.d.ts.map +1 -0
  124. package/dist/core/async-scope.js +20 -0
  125. package/dist/core/async-scope.js.map +1 -0
  126. package/dist/core/cache-warmer.d.ts +3 -14
  127. package/dist/core/cache-warmer.d.ts.map +1 -1
  128. package/dist/core/cache-warmer.js +8 -60
  129. package/dist/core/cache-warmer.js.map +1 -1
  130. package/dist/core/extensions/extension-work.js +2 -2
  131. package/dist/core/extensions/extension-work.js.map +1 -1
  132. package/dist/core/extensions/loader-host-modules.d.ts.map +1 -1
  133. package/dist/core/extensions/loader-host-modules.js +3 -1
  134. package/dist/core/extensions/loader-host-modules.js.map +1 -1
  135. package/dist/core/extensions/ui-types.d.ts +2 -1
  136. package/dist/core/extensions/ui-types.d.ts.map +1 -1
  137. package/dist/core/extensions/ui-types.js.map +1 -1
  138. package/dist/core/extensions/workflow-events.d.ts +1 -1
  139. package/dist/core/extensions/workflow-events.d.ts.map +1 -1
  140. package/dist/core/extensions/workflow-events.js.map +1 -1
  141. package/dist/core/extensions/workflow-run-control.d.ts +4 -2
  142. package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
  143. package/dist/core/extensions/workflow-run-control.js.map +1 -1
  144. package/dist/core/model-fallback-failures.d.ts +6 -0
  145. package/dist/core/model-fallback-failures.d.ts.map +1 -1
  146. package/dist/core/model-fallback-failures.js +10 -1
  147. package/dist/core/model-fallback-failures.js.map +1 -1
  148. package/dist/core/preferred-providers.d.ts +19 -0
  149. package/dist/core/preferred-providers.d.ts.map +1 -0
  150. package/dist/core/preferred-providers.js +25 -0
  151. package/dist/core/preferred-providers.js.map +1 -0
  152. package/dist/core/provider-alias.d.ts.map +1 -1
  153. package/dist/core/provider-alias.js +4 -0
  154. package/dist/core/provider-alias.js.map +1 -1
  155. package/dist/core/provider-composer.d.ts.map +1 -1
  156. package/dist/core/provider-composer.js +1 -0
  157. package/dist/core/provider-composer.js.map +1 -1
  158. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  159. package/dist/core/remote-catalog-provider.js +3 -0
  160. package/dist/core/remote-catalog-provider.js.map +1 -1
  161. package/dist/core/resume/blueprint/action-expressions.d.ts +32 -0
  162. package/dist/core/resume/blueprint/action-expressions.d.ts.map +1 -0
  163. package/dist/core/resume/blueprint/action-expressions.js +389 -0
  164. package/dist/core/resume/blueprint/action-expressions.js.map +1 -0
  165. package/dist/core/resume/blueprint/actions.d.ts +90 -0
  166. package/dist/core/resume/blueprint/actions.d.ts.map +1 -0
  167. package/dist/core/resume/blueprint/actions.js +818 -0
  168. package/dist/core/resume/blueprint/actions.js.map +1 -0
  169. package/dist/core/resume/blueprint/build.d.ts +102 -0
  170. package/dist/core/resume/blueprint/build.d.ts.map +1 -0
  171. package/dist/core/resume/blueprint/build.js +535 -0
  172. package/dist/core/resume/blueprint/build.js.map +1 -0
  173. package/dist/core/resume/blueprint/context.d.ts +11 -0
  174. package/dist/core/resume/blueprint/context.d.ts.map +1 -0
  175. package/dist/core/resume/blueprint/context.js +106 -0
  176. package/dist/core/resume/blueprint/context.js.map +1 -0
  177. package/dist/core/resume/blueprint/envrc.d.ts +19 -0
  178. package/dist/core/resume/blueprint/envrc.d.ts.map +1 -0
  179. package/dist/core/resume/blueprint/envrc.js +77 -0
  180. package/dist/core/resume/blueprint/envrc.js.map +1 -0
  181. package/dist/core/resume/blueprint/errors.d.ts +179 -0
  182. package/dist/core/resume/blueprint/errors.d.ts.map +1 -0
  183. package/dist/core/resume/blueprint/errors.js +169 -0
  184. package/dist/core/resume/blueprint/errors.js.map +1 -0
  185. package/dist/core/resume/blueprint/ledger.d.ts +51 -0
  186. package/dist/core/resume/blueprint/ledger.d.ts.map +1 -0
  187. package/dist/core/resume/blueprint/ledger.js +119 -0
  188. package/dist/core/resume/blueprint/ledger.js.map +1 -0
  189. package/dist/core/resume/blueprint/notices.d.ts +14 -0
  190. package/dist/core/resume/blueprint/notices.d.ts.map +1 -0
  191. package/dist/core/resume/blueprint/notices.js +44 -0
  192. package/dist/core/resume/blueprint/notices.js.map +1 -0
  193. package/dist/core/resume/blueprint/process.d.ts +44 -0
  194. package/dist/core/resume/blueprint/process.d.ts.map +1 -0
  195. package/dist/core/resume/blueprint/process.js +142 -0
  196. package/dist/core/resume/blueprint/process.js.map +1 -0
  197. package/dist/core/resume/blueprint/resume.d.ts +73 -0
  198. package/dist/core/resume/blueprint/resume.d.ts.map +1 -0
  199. package/dist/core/resume/blueprint/resume.js +206 -0
  200. package/dist/core/resume/blueprint/resume.js.map +1 -0
  201. package/dist/core/resume/blueprint/schema.d.ts +26 -0
  202. package/dist/core/resume/blueprint/schema.d.ts.map +1 -0
  203. package/dist/core/resume/blueprint/schema.js +243 -0
  204. package/dist/core/resume/blueprint/schema.js.map +1 -0
  205. package/dist/core/resume/blueprint/steps.d.ts +54 -0
  206. package/dist/core/resume/blueprint/steps.d.ts.map +1 -0
  207. package/dist/core/resume/blueprint/steps.js +155 -0
  208. package/dist/core/resume/blueprint/steps.js.map +1 -0
  209. package/dist/core/resume/blueprint/types.d.ts +63 -0
  210. package/dist/core/resume/blueprint/types.d.ts.map +1 -0
  211. package/dist/core/resume/blueprint/types.js +2 -0
  212. package/dist/core/resume/blueprint/types.js.map +1 -0
  213. package/dist/core/resume/errors.d.ts +7 -35
  214. package/dist/core/resume/errors.d.ts.map +1 -1
  215. package/dist/core/resume/errors.js +1 -21
  216. package/dist/core/resume/errors.js.map +1 -1
  217. package/dist/core/resume/index.d.ts +12 -4
  218. package/dist/core/resume/index.d.ts.map +1 -1
  219. package/dist/core/resume/index.js +11 -4
  220. package/dist/core/resume/index.js.map +1 -1
  221. package/dist/core/resume/run-setup.d.ts +36 -15
  222. package/dist/core/resume/run-setup.d.ts.map +1 -1
  223. package/dist/core/resume/run-setup.js +70 -54
  224. package/dist/core/resume/run-setup.js.map +1 -1
  225. package/dist/core/resume/session-resume.d.ts +34 -20
  226. package/dist/core/resume/session-resume.d.ts.map +1 -1
  227. package/dist/core/resume/session-resume.js +244 -106
  228. package/dist/core/resume/session-resume.js.map +1 -1
  229. package/dist/core/retry-policy.d.ts +19 -1
  230. package/dist/core/retry-policy.d.ts.map +1 -1
  231. package/dist/core/retry-policy.js +26 -1
  232. package/dist/core/retry-policy.js.map +1 -1
  233. package/dist/core/sdk.js +1 -1
  234. package/dist/core/sdk.js.map +1 -1
  235. package/dist/core/session-cwd.d.ts +56 -1
  236. package/dist/core/session-cwd.d.ts.map +1 -1
  237. package/dist/core/session-cwd.js +94 -4
  238. package/dist/core/session-cwd.js.map +1 -1
  239. package/dist/core/session-manager-core.d.ts +1 -1
  240. package/dist/core/session-manager-core.d.ts.map +1 -1
  241. package/dist/core/session-manager-core.js +10 -5
  242. package/dist/core/session-manager-core.js.map +1 -1
  243. package/dist/core/session-worktree-snapshots.d.ts +11 -0
  244. package/dist/core/session-worktree-snapshots.d.ts.map +1 -1
  245. package/dist/core/session-worktree-snapshots.js +10 -4
  246. package/dist/core/session-worktree-snapshots.js.map +1 -1
  247. package/dist/core/settings-defaults.d.ts +1 -1
  248. package/dist/core/settings-defaults.d.ts.map +1 -1
  249. package/dist/core/settings-defaults.js +1 -1
  250. package/dist/core/settings-defaults.js.map +1 -1
  251. package/dist/core/settings-manager-basic-accessors.d.ts +3 -2
  252. package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
  253. package/dist/core/settings-manager-basic-accessors.js.map +1 -1
  254. package/dist/core/settings-schema.d.ts.map +1 -1
  255. package/dist/core/settings-schema.js +2 -1
  256. package/dist/core/settings-schema.js.map +1 -1
  257. package/dist/core/slash-commands.d.ts.map +1 -1
  258. package/dist/core/slash-commands.js +4 -0
  259. package/dist/core/slash-commands.js.map +1 -1
  260. package/dist/core/storage/write-ahead-log.d.ts +2 -1
  261. package/dist/core/storage/write-ahead-log.d.ts.map +1 -1
  262. package/dist/core/storage/write-ahead-log.js +27 -6
  263. package/dist/core/storage/write-ahead-log.js.map +1 -1
  264. package/dist/core/system-prompt.d.ts.map +1 -1
  265. package/dist/core/system-prompt.js +10 -0
  266. package/dist/core/system-prompt.js.map +1 -1
  267. package/dist/core/tools/file-tool-errors.d.ts +1 -1
  268. package/dist/core/tools/file-tool-errors.js +1 -1
  269. package/dist/core/tools/file-tool-errors.js.map +1 -1
  270. package/dist/core/tools/find.d.ts.map +1 -1
  271. package/dist/core/tools/find.js +52 -26
  272. package/dist/core/tools/find.js.map +1 -1
  273. package/dist/core/tools/grep.d.ts +2 -0
  274. package/dist/core/tools/grep.d.ts.map +1 -1
  275. package/dist/core/tools/grep.js.map +1 -1
  276. package/dist/core/tools/powershell.d.ts.map +1 -1
  277. package/dist/core/tools/powershell.js +10 -2
  278. package/dist/core/tools/powershell.js.map +1 -1
  279. package/dist/core/tools/tool-concurrency.d.ts.map +1 -1
  280. package/dist/core/tools/tool-concurrency.js +2 -2
  281. package/dist/core/tools/tool-concurrency.js.map +1 -1
  282. package/dist/index.d.ts +3 -2
  283. package/dist/index.d.ts.map +1 -1
  284. package/dist/index.js +2 -1
  285. package/dist/index.js.map +1 -1
  286. package/dist/main-session.d.ts +12 -4
  287. package/dist/main-session.d.ts.map +1 -1
  288. package/dist/main-session.js +28 -4
  289. package/dist/main-session.js.map +1 -1
  290. package/dist/main.d.ts.map +1 -1
  291. package/dist/main.js +6 -8
  292. package/dist/main.js.map +1 -1
  293. package/dist/modes/interactive/components/chat-session-host.d.ts +5 -1
  294. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  295. package/dist/modes/interactive/components/chat-session-host.js +6 -1
  296. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  297. package/dist/modes/interactive/components/oauth-selector.d.ts +10 -3
  298. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  299. package/dist/modes/interactive/components/oauth-selector.js +34 -13
  300. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  301. package/dist/modes/interactive/components/provider-brand.d.ts +16 -0
  302. package/dist/modes/interactive/components/provider-brand.d.ts.map +1 -0
  303. package/dist/modes/interactive/components/provider-brand.js +67 -0
  304. package/dist/modes/interactive/components/provider-brand.js.map +1 -0
  305. package/dist/modes/interactive/interactive-auth-routing.d.ts.map +1 -1
  306. package/dist/modes/interactive/interactive-auth-routing.js +8 -6
  307. package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
  308. package/dist/modes/interactive/interactive-extension-dialogs.js +4 -3
  309. package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -1
  310. package/dist/modes/interactive/interactive-extension-runtime.js +8 -3
  311. package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
  312. package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
  313. package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
  314. package/dist/modes/interactive/interactive-mode-deps.js +1 -1
  315. package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
  316. package/dist/modes/interactive/interactive-mode-surface.d.ts +12 -2
  317. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  318. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  319. package/dist/modes/interactive/interactive-session-routing.js +59 -21
  320. package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
  321. package/dist/modes/interactive/interactive-slash-commands.js +23 -12
  322. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  323. package/dist/modes/interactive/login-provider-options.d.ts.map +1 -1
  324. package/dist/modes/interactive/login-provider-options.js +2 -1
  325. package/dist/modes/interactive/login-provider-options.js.map +1 -1
  326. package/dist/modes/interactive-engine/isolated-runtime.d.ts +2 -0
  327. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  328. package/dist/modes/interactive-engine/isolated-runtime.js +8 -3
  329. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  330. package/dist/modes/rpc/rpc-client-api.d.ts +2 -1
  331. package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
  332. package/dist/modes/rpc/rpc-client-api.js.map +1 -1
  333. package/dist/modes/rpc/rpc-client.d.ts +0 -1
  334. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  335. package/dist/modes/rpc/rpc-client.js +2 -18
  336. package/dist/modes/rpc/rpc-client.js.map +1 -1
  337. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  338. package/dist/modes/rpc/rpc-command-handler.js +8 -2
  339. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  340. package/dist/modes/rpc/rpc-error-decoding.d.ts +7 -0
  341. package/dist/modes/rpc/rpc-error-decoding.d.ts.map +1 -0
  342. package/dist/modes/rpc/rpc-error-decoding.js +25 -0
  343. package/dist/modes/rpc/rpc-error-decoding.js.map +1 -0
  344. package/dist/modes/rpc/rpc-responses.d.ts.map +1 -1
  345. package/dist/modes/rpc/rpc-responses.js +12 -0
  346. package/dist/modes/rpc/rpc-responses.js.map +1 -1
  347. package/dist/modes/rpc/rpc-types.d.ts +11 -0
  348. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  349. package/dist/modes/rpc/rpc-types.js.map +1 -1
  350. package/dist/package-manager-cli.d.ts.map +1 -1
  351. package/dist/package-manager-cli.js +12 -3
  352. package/dist/package-manager-cli.js.map +1 -1
  353. package/docs/background-tasks.md +1 -1
  354. package/docs/codemode.md +22 -0
  355. package/docs/extensions/api-reference.md +27 -1
  356. package/docs/extensions/authoring.md +1 -1
  357. package/docs/extensions/ui.md +1 -1
  358. package/docs/getting-started/first-session.md +1 -1
  359. package/docs/guides/resume-on-any-machine.md +72 -19
  360. package/docs/models/evals.md +85 -17
  361. package/docs/models/reference.md +1 -1
  362. package/docs/providers.md +38 -5
  363. package/docs/reference/cli.md +2 -0
  364. package/docs/rpc/protocol.md +11 -1
  365. package/docs/sdk/reference.md +36 -4
  366. package/docs/sdk.md +2 -2
  367. package/docs/sessions.md +11 -1
  368. package/docs/settings.md +7 -2
  369. package/docs/skills.md +3 -3
  370. package/docs/storage.md +1 -1
  371. package/docs/tools.md +3 -1
  372. package/docs/workflows/api-reference.md +14 -12
  373. package/docs/workflows/authoring.md +29 -1
  374. package/docs/workflows/builtins.md +9 -1
  375. package/docs/workflows/operations.md +8 -8
  376. package/docs/worktree-snapshots.md +3 -2
  377. package/npm-shrinkwrap.json +83 -67
  378. package/package.json +7 -7
  379. package/schemas/settings.schema.json +3 -2
  380. package/dist/core/resume/setup-hook.d.ts +0 -69
  381. package/dist/core/resume/setup-hook.d.ts.map +0 -1
  382. package/dist/core/resume/setup-hook.js +0 -261
  383. package/dist/core/resume/setup-hook.js.map +0 -1
@@ -0,0 +1,535 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { copyFile, mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
+ import { getBlueprintActionsDir, getGlobalBlueprintPath, getProjectBlueprintPath } from "../../../config.js";
5
+ import { getHomeDir } from "../../../utils/paths.js";
6
+ import { getShellEnv } from "../../../utils/shell.js";
7
+ import { sessionEnvrcPath } from "./envrc.js";
8
+ import { BlueprintBuildFailedError, BlueprintInvalidError, isBlueprintError, } from "./errors.js";
9
+ import { blueprintDigest, readLedger, repositoryKey, rootKey, updateLedger, workspaceKey, } from "./ledger.js";
10
+ import { hostPlatform, parseBlueprint, selectDocument } from "./schema.js";
11
+ import { BLUEPRINT_STEP_TIMEOUT_MS, runSection } from "./steps.js";
12
+ /** A full build runs instead of a differential one when the last full build is older than this: 7 days. */
13
+ export const BLUEPRINT_FULL_BUILD_MAX_AGE_MS = 7 * 24 * 60 * 60_000;
14
+ /** The name the deprecated `resume.setupCommand` alias goes by in steps, logs and failures. */
15
+ export const SETUP_COMMAND_ALIAS = "resume.setupCommand";
16
+ async function readIfPresent(path) {
17
+ try {
18
+ return await readFile(path, "utf8");
19
+ }
20
+ catch (error) {
21
+ const code = error.code;
22
+ if (code === "ENOENT" || code === "ENOTDIR")
23
+ return undefined;
24
+ throw error;
25
+ }
26
+ }
27
+ async function fileExists(path) {
28
+ try {
29
+ await stat(path);
30
+ return true;
31
+ }
32
+ catch (error) {
33
+ const code = error.code;
34
+ return code !== "ENOENT" && code !== "ENOTDIR";
35
+ }
36
+ }
37
+ function unreadable(path, error) {
38
+ return new BlueprintBuildFailedError({ phase: "read-blueprint", detail: `${path} could not be read` }, error instanceof Error ? error : new Error(String(error)));
39
+ }
40
+ async function loadBlueprint(path, scope, platform) {
41
+ let source;
42
+ try {
43
+ source = await readIfPresent(path);
44
+ }
45
+ catch (error) {
46
+ return { path, scope, source: "", parsed: undefined, document: undefined, invalid: unreadable(path, error) };
47
+ }
48
+ if (source === undefined)
49
+ return { path, scope, source, parsed: undefined, document: undefined, invalid: undefined };
50
+ try {
51
+ const parsed = parseBlueprint(source, { path, scope });
52
+ return { path, scope, source, parsed, document: selectDocument(parsed, platform), invalid: undefined };
53
+ }
54
+ catch (error) {
55
+ if (error instanceof BlueprintInvalidError) {
56
+ return { path, scope, source, parsed: undefined, document: undefined, invalid: error };
57
+ }
58
+ return { path, scope, source, parsed: undefined, document: undefined, invalid: unreadable(path, error) };
59
+ }
60
+ }
61
+ function aliasStep(command) {
62
+ return { kind: "run", name: SETUP_COMMAND_ALIAS, run: command, env: {} };
63
+ }
64
+ /** The document of the global blueprint as the agent sees it: the alias is one more global maintenance step. */
65
+ function withAlias(document, alias, platform) {
66
+ if (alias === undefined)
67
+ return document;
68
+ const base = document ?? {
69
+ platforms: [platform],
70
+ shell: "default",
71
+ initialize: [],
72
+ maintenance: [],
73
+ knowledge: [],
74
+ postBuild: [],
75
+ includes: [],
76
+ };
77
+ return { ...base, maintenance: [...base.maintenance, aliasStep(alias)] };
78
+ }
79
+ function layerOf(loaded, root, directory, state, document = loaded.document) {
80
+ return { scope: loaded.scope, blueprint: loaded.path, root, directory, document, state };
81
+ }
82
+ async function loadGlobal(config, platform) {
83
+ return loadBlueprint(getGlobalBlueprintPath(config.agentDir), "global", platform);
84
+ }
85
+ async function includedWorkspaces(root, rootBlueprint) {
86
+ return (rootBlueprint.document?.includes ?? []).map((include) => ({
87
+ directory: include.directory,
88
+ path: join(root, include.file),
89
+ }));
90
+ }
91
+ /**
92
+ * What the blueprints of `repositories` and the global blueprint say, without running anything: every layer carries
93
+ * `state` as given. This is what the agent is told when no build ran (an untrusted project, a checkout used in place).
94
+ */
95
+ export async function describeBlueprints(repositories, config, reason, includeGlobal = true) {
96
+ const platform = config.platform ?? hostPlatform();
97
+ const state = { kind: "not-run", reason };
98
+ const layers = [];
99
+ const global = includeGlobal ? await loadGlobal(config, platform) : undefined;
100
+ const globalDocument = withAlias(global?.document, config.setupCommand?.trim() || undefined, platform);
101
+ if (global !== undefined && (globalDocument !== undefined || global.invalid !== undefined)) {
102
+ layers.push(layerOf(global, null, null, state, globalDocument));
103
+ }
104
+ for (const repository of repositories) {
105
+ layers.push(...(await describeRepository(repository, platform, state)));
106
+ }
107
+ return layers;
108
+ }
109
+ async function describeRepository(repository, platform, state) {
110
+ const root = await loadBlueprint(getProjectBlueprintPath(repository.root), "repository", platform);
111
+ if (root.source === undefined)
112
+ return [];
113
+ const layers = [layerOf(root, repository.root, ".", state)];
114
+ for (const include of await includedWorkspaces(repository.root, root)) {
115
+ const workspace = await loadBlueprint(include.path, "workspace", platform);
116
+ if (workspace.source !== undefined)
117
+ layers.push(layerOf(workspace, repository.root, include.directory, state));
118
+ }
119
+ return layers;
120
+ }
121
+ function stepContext(run, options) {
122
+ return {
123
+ blueprint: options.blueprint,
124
+ scope: options.scope,
125
+ cwd: options.cwd,
126
+ shell: options.document.shell,
127
+ platform: run.platform,
128
+ envrcPath: run.envrcPath,
129
+ logDirectory: join(run.config.storeDir, "blueprint-logs"),
130
+ logPrefix: `${run.buildId}-${options.tag}`,
131
+ timeoutMs: run.config.stepTimeoutMs ?? BLUEPRINT_STEP_TIMEOUT_MS,
132
+ environment: run.environment,
133
+ actionsCacheDir: getBlueprintActionsDir(run.config.agentDir),
134
+ fetchAction: run.config.fetchAction,
135
+ signal: run.signal,
136
+ };
137
+ }
138
+ function tagOf(root, directory) {
139
+ if (root === null)
140
+ return "global";
141
+ const slug = (directory ?? ".").replaceAll(/[^A-Za-z0-9]+/gu, "_");
142
+ return `${rootKey(root).slice(0, 8)}-${slug}`;
143
+ }
144
+ function failureOf(loaded, root, directory, step) {
145
+ return {
146
+ scope: loaded.scope,
147
+ blueprint: loaded.path,
148
+ root,
149
+ directory,
150
+ error: step.error,
151
+ logPath: step.logPath,
152
+ outputTail: step.outputTail,
153
+ };
154
+ }
155
+ function failureSection(error) {
156
+ const section = error.fields.section;
157
+ return section === "initialize" || section === "maintenance" || section === "post-build" ? section : null;
158
+ }
159
+ /** Builds one repository or workspace blueprint: initialize when it needs a rebuild, then maintenance. */
160
+ async function buildBlueprint(run, repository, loaded, directory, forceRebuild) {
161
+ const key = workspaceKey(repository.identity, directory);
162
+ const source = loaded.source ?? "";
163
+ const digest = blueprintDigest(directory, source);
164
+ const builtAt = new Date((run.config.now ?? Date.now)()).toISOString();
165
+ const entry = run.ledger.workspaces[key];
166
+ const action = run.full || forceRebuild || entry === undefined || entry.digest !== digest || entry.status !== "success"
167
+ ? "rebuild"
168
+ : "inherit";
169
+ const finish = (failure) => {
170
+ run.workspaces.set(key, failure === undefined
171
+ ? { digest, status: "success", builtAt }
172
+ : {
173
+ digest,
174
+ status: "failed",
175
+ builtAt,
176
+ failedStep: String(failure.error.fields.step ?? failure.blueprint),
177
+ ...(failure.logPath === null ? {} : { logPath: failure.logPath }),
178
+ });
179
+ if (failure !== undefined)
180
+ run.failures.push(failure);
181
+ };
182
+ if (loaded.invalid !== undefined) {
183
+ const failure = failureOf(loaded, repository.root, directory, {
184
+ error: loaded.invalid,
185
+ logPath: null,
186
+ outputTail: "",
187
+ });
188
+ finish(failure);
189
+ return layerOf(loaded, repository.root, directory, { kind: "failed", failure, section: null });
190
+ }
191
+ const document = loaded.document;
192
+ if (document === undefined) {
193
+ finish(undefined);
194
+ return layerOf(loaded, repository.root, directory, { kind: "no-document" });
195
+ }
196
+ run.warnings.push(...(loaded.parsed?.warnings ?? []));
197
+ const context = stepContext(run, {
198
+ blueprint: loaded.path,
199
+ scope: loaded.scope,
200
+ cwd: directory === "." ? repository.root : join(repository.root, directory),
201
+ document,
202
+ tag: tagOf(repository.root, directory),
203
+ });
204
+ let failed;
205
+ if (action === "rebuild")
206
+ failed = (await runSection("initialize", document.initialize, context)).failure;
207
+ if (failed === undefined)
208
+ failed = (await runSection("maintenance", document.maintenance, context)).failure;
209
+ const failure = failed === undefined ? undefined : failureOf(loaded, repository.root, directory, failed);
210
+ finish(failure);
211
+ return layerOf(loaded, repository.root, directory, failure === undefined
212
+ ? { kind: "built", action }
213
+ : { kind: "failed", failure, section: failureSection(failure.error) });
214
+ }
215
+ async function buildRepository(run, repository, seen) {
216
+ const forceRebuild = run.ledger.roots[rootKey(repository.root)]?.state === "running";
217
+ const root = await loadBlueprint(getProjectBlueprintPath(repository.root), "repository", run.platform);
218
+ if (root.source === undefined)
219
+ return;
220
+ seen.add(workspaceKey(repository.identity, "."));
221
+ run.layers.push(await buildBlueprint(run, repository, root, ".", forceRebuild));
222
+ for (const include of await includedWorkspaces(repository.root, root)) {
223
+ const workspace = await loadBlueprint(include.path, "workspace", run.platform);
224
+ if (workspace.source !== undefined) {
225
+ seen.add(workspaceKey(repository.identity, include.directory));
226
+ run.layers.push(await buildBlueprint(run, repository, workspace, include.directory, forceRebuild));
227
+ }
228
+ }
229
+ }
230
+ function removedWorkspaces(run, repositories, seen) {
231
+ for (const repository of repositories) {
232
+ const prefix = `${repositoryKey(repository.identity)}:`;
233
+ for (const key of Object.keys(run.ledger.workspaces)) {
234
+ if (key.startsWith(prefix) && !seen.has(key)) {
235
+ run.workspaces.set(key, null);
236
+ run.removed.push(key.slice(prefix.length));
237
+ }
238
+ }
239
+ }
240
+ }
241
+ async function runGlobalLayers(run, global, repositories) {
242
+ const alias = run.config.setupCommand?.trim() || undefined;
243
+ const document = global.document;
244
+ const display = withAlias(document, alias, run.platform);
245
+ if (global.invalid !== undefined) {
246
+ const failure = failureOf(global, null, null, { error: global.invalid, logPath: null, outputTail: "" });
247
+ run.failures.push(failure);
248
+ return layerOf(global, null, null, { kind: "failed", failure, section: null });
249
+ }
250
+ if (display === undefined)
251
+ return undefined;
252
+ run.warnings.push(...(global.parsed?.warnings ?? []));
253
+ const home = run.config.homeDir ?? getHomeDir();
254
+ const context = (cwd, blueprint) => stepContext(run, { blueprint, scope: "global", cwd, document: display, tag: "global" });
255
+ let failed;
256
+ if (document !== undefined && run.full) {
257
+ failed = (await runSection("initialize", document.initialize, context(home, global.path))).failure;
258
+ }
259
+ if (failed === undefined && document !== undefined) {
260
+ failed = (await runSection("maintenance", document.maintenance, context(home, global.path))).failure;
261
+ }
262
+ if (failed === undefined && alias !== undefined) {
263
+ for (const repository of repositories) {
264
+ const result = await runSection("maintenance", [aliasStep(alias)], {
265
+ ...context(repository.root, SETUP_COMMAND_ALIAS),
266
+ logPrefix: `${run.buildId}-${tagOf(repository.root, "alias")}`,
267
+ });
268
+ if (result.failure !== undefined) {
269
+ failed = result.failure;
270
+ break;
271
+ }
272
+ }
273
+ }
274
+ if (failed === undefined)
275
+ return layerOf(global, null, null, { kind: "built", action: run.full ? "rebuild" : "inherit" }, display);
276
+ const failure = failureOf({ path: failedBlueprint(failed, global.path), scope: "global" }, null, null, failed);
277
+ run.failures.push(failure);
278
+ return layerOf(global, null, null, { kind: "failed", failure, section: failureSection(failed.error) }, display);
279
+ }
280
+ function failedBlueprint(failure, globalPath) {
281
+ const blueprint = failure.error.fields.blueprint;
282
+ return typeof blueprint === "string" ? blueprint : globalPath;
283
+ }
284
+ async function runPostBuild(run, global, layer) {
285
+ const document = global.document;
286
+ if (document === undefined || document.postBuild.length === 0)
287
+ return layer;
288
+ const context = stepContext(run, {
289
+ blueprint: global.path,
290
+ scope: "global",
291
+ cwd: run.config.homeDir ?? getHomeDir(),
292
+ document,
293
+ tag: "global",
294
+ });
295
+ const { failure: failed } = await runSection("post-build", document.postBuild, context);
296
+ if (failed === undefined)
297
+ return layer;
298
+ const failure = failureOf(global, null, null, failed);
299
+ run.failures.push(failure);
300
+ return { ...layer, state: { kind: "failed", failure, section: "post-build" } };
301
+ }
302
+ /** Runs `work`; its failure is the typed build failure of `phase`, with the original error as its cause. */
303
+ async function inPhase(phase, detail, work) {
304
+ try {
305
+ return await work();
306
+ }
307
+ catch (error) {
308
+ if (isBlueprintError(error))
309
+ throw error;
310
+ throw new BlueprintBuildFailedError({ phase, detail }, error instanceof Error ? error : new Error(String(error)));
311
+ }
312
+ }
313
+ async function writeSessionEnvironment(run, roots) {
314
+ const content = await readFile(run.envrcPath, "utf8");
315
+ for (const repository of roots) {
316
+ const target = sessionEnvrcPath(run.config.storeDir, repository.root);
317
+ if (content.trim() === "") {
318
+ await rm(target, { force: true });
319
+ continue;
320
+ }
321
+ await mkdir(dirname(target), { recursive: true });
322
+ await copyFile(run.envrcPath, target);
323
+ }
324
+ }
325
+ function statusOf(run, globalFailed) {
326
+ if (globalFailed)
327
+ return "failed";
328
+ return run.failures.length > 0 ? "partial" : "success";
329
+ }
330
+ async function executeBuild(repositories, config, signal) {
331
+ const platform = config.platform ?? hostPlatform();
332
+ const now = config.now ?? Date.now;
333
+ const trusted = repositories.filter((repository) => config.trusted(repository.root));
334
+ const untrusted = repositories.filter((repository) => !trusted.includes(repository));
335
+ const global = await loadGlobal(config, platform);
336
+ const alias = config.setupCommand?.trim() || undefined;
337
+ const layers = [];
338
+ const untrustedLayers = await describeBlueprints(untrusted, config, "untrusted", false);
339
+ const hasTrustedBlueprint = global.source !== undefined ||
340
+ alias !== undefined ||
341
+ (await Promise.all(trusted.map((repository) => fileExists(getProjectBlueprintPath(repository.root))))).some(Boolean);
342
+ if (trusted.length === 0 || !hasTrustedBlueprint) {
343
+ const described = await describeBlueprints(trusted, config, trusted.length === 0 ? "untrusted" : "skipped");
344
+ const all = [...described, ...untrustedLayers];
345
+ return {
346
+ status: all.length === 0 ? "none" : "skipped",
347
+ kind: undefined,
348
+ layers: all,
349
+ failures: [],
350
+ warnings: [],
351
+ removed: [],
352
+ };
353
+ }
354
+ const ledger = await inPhase("ledger", "the build ledger could not be read", () => readLedger(config.storeDir));
355
+ const globalDigest = blueprintDigest(".", global.source ?? "", alias ?? "");
356
+ const last = ledger.global;
357
+ const full = last === undefined ||
358
+ last.status !== "success" ||
359
+ last.digest !== globalDigest ||
360
+ last.lastFullBuildAt === undefined ||
361
+ now() - Date.parse(last.lastFullBuildAt) > (config.fullBuildMaxAgeMs ?? BLUEPRINT_FULL_BUILD_MAX_AGE_MS);
362
+ const buildId = `${new Date(now()).toISOString().replaceAll(/[-:.TZ]/gu, "")}-${randomUUID().slice(0, 8)}`;
363
+ const envrcPath = join(config.storeDir, "blueprint-builds", `${buildId}.envrc`);
364
+ await inPhase("environment", "the $ENVRC file could not be created", async () => {
365
+ await mkdir(dirname(envrcPath), { recursive: true });
366
+ await writeFile(envrcPath, "", { mode: 0o600 });
367
+ });
368
+ const run = {
369
+ config,
370
+ platform,
371
+ buildId,
372
+ full,
373
+ ledger,
374
+ envrcPath,
375
+ environment: config.environment ?? getShellEnv(),
376
+ signal,
377
+ layers,
378
+ failures: [],
379
+ warnings: [],
380
+ removed: [],
381
+ workspaces: new Map(),
382
+ roots: new Map(),
383
+ };
384
+ const startedAt = new Date(now()).toISOString();
385
+ await inPhase("ledger", "the build ledger could not be written", () => updateLedger(config.storeDir, (current) => ({
386
+ ...current,
387
+ roots: {
388
+ ...current.roots,
389
+ ...Object.fromEntries(trusted.map((repository) => [rootKey(repository.root), { state: "running", at: startedAt }])),
390
+ },
391
+ })));
392
+ try {
393
+ let globalLayer = await runGlobalLayers(run, global, trusted);
394
+ const globalFailed = globalLayer?.state.kind === "failed";
395
+ const seen = new Set();
396
+ if (globalFailed) {
397
+ for (const repository of trusted) {
398
+ run.layers.push(...(await describeRepository(repository, platform, { kind: "not-run", reason: "global-failed" })));
399
+ }
400
+ }
401
+ else {
402
+ for (const repository of trusted)
403
+ await buildRepository(run, repository, seen);
404
+ removedWorkspaces(run, trusted, seen);
405
+ if (globalLayer !== undefined)
406
+ globalLayer = await runPostBuild(run, global, globalLayer);
407
+ }
408
+ const globalOk = globalLayer === undefined || globalLayer.state.kind !== "failed";
409
+ const finishedAt = new Date(now()).toISOString();
410
+ const failedRoots = new Set(run.failures.map((failure) => failure.root).filter((root) => root !== null));
411
+ await inPhase("environment", "the $ENVRC of the build could not be kept for the session", () => writeSessionEnvironment(run, trusted));
412
+ await inPhase("ledger", "the build ledger could not be written", () => updateLedger(config.storeDir, (current) => {
413
+ const workspaces = { ...current.workspaces };
414
+ for (const [key, entry] of run.workspaces) {
415
+ if (entry === null)
416
+ delete workspaces[key];
417
+ else
418
+ workspaces[key] = entry;
419
+ }
420
+ return {
421
+ version: 1,
422
+ global: {
423
+ digest: globalDigest,
424
+ status: globalOk ? "success" : "failed",
425
+ builtAt: finishedAt,
426
+ ...(globalOk && full
427
+ ? { lastFullBuildAt: finishedAt }
428
+ : !full && last?.lastFullBuildAt !== undefined
429
+ ? { lastFullBuildAt: last.lastFullBuildAt }
430
+ : {}),
431
+ },
432
+ workspaces,
433
+ roots: {
434
+ ...current.roots,
435
+ ...Object.fromEntries(trusted.map((repository) => [
436
+ rootKey(repository.root),
437
+ {
438
+ state: !globalOk || failedRoots.has(repository.root)
439
+ ? "failed"
440
+ : "success",
441
+ at: finishedAt,
442
+ },
443
+ ])),
444
+ },
445
+ };
446
+ }));
447
+ return {
448
+ status: statusOf(run, !globalOk),
449
+ kind: full ? "full" : "differential",
450
+ layers: [...(globalLayer === undefined ? [] : [globalLayer]), ...run.layers, ...untrustedLayers],
451
+ failures: run.failures,
452
+ warnings: run.warnings,
453
+ removed: run.removed,
454
+ };
455
+ }
456
+ finally {
457
+ await rm(envrcPath, { force: true });
458
+ }
459
+ }
460
+ function crashedBuild(error) {
461
+ const cause = error instanceof Error ? error : new Error(String(error));
462
+ return new BlueprintBuildFailedError({ phase: "unknown", detail: cause.message.slice(0, 200) }, cause);
463
+ }
464
+ /**
465
+ * The layers of a build that stopped before it finished: what each repository's blueprints say, labelled as not
466
+ * confirmed, and the global layer carrying `failure`, so the agent still gets the maintenance, the knowledge and the
467
+ * failure. Never throws: when the blueprints cannot even be described, only the global layer is returned.
468
+ */
469
+ async function layersOfCrashedBuild(repositories, config, failure) {
470
+ const failedState = { kind: "failed", failure, section: null };
471
+ const bare = {
472
+ scope: "global",
473
+ blueprint: failure.blueprint,
474
+ root: null,
475
+ directory: null,
476
+ document: undefined,
477
+ state: failedState,
478
+ };
479
+ try {
480
+ const trusted = repositories.filter((repository) => config.trusted(repository.root));
481
+ const untrusted = repositories.filter((repository) => !trusted.includes(repository));
482
+ const described = [
483
+ ...(await describeBlueprints(trusted, config, "build-failed")),
484
+ ...(await describeBlueprints(untrusted, config, "untrusted", false)),
485
+ ];
486
+ const global = described.find((layer) => layer.scope === "global");
487
+ return [{ ...(global ?? bare), state: failedState }, ...described.filter((layer) => layer.scope !== "global")];
488
+ }
489
+ catch {
490
+ return [bare];
491
+ }
492
+ }
493
+ /**
494
+ * Builds the worktrees a resume restored: global `initialize` (in a full build) and `maintenance`, then each trusted
495
+ * repository's `initialize` (when it needs a rebuild) and `maintenance` with its included workspaces, then the global
496
+ * `post-build`. A step that fails stops the rest of its blueprint, never the other blueprints, and never the resume:
497
+ * the failure is in the outcome. Only `signal` aborting rejects, with its reason. Untrusted repositories run nothing.
498
+ */
499
+ export async function runBlueprintBuild(repositories, config, signal) {
500
+ signal?.throwIfAborted();
501
+ try {
502
+ return await executeBuild(repositories, config, signal);
503
+ }
504
+ catch (error) {
505
+ if (signal?.aborted)
506
+ throw error;
507
+ const crash = isBlueprintError(error) ? error : crashedBuild(error);
508
+ const failure = {
509
+ scope: "global",
510
+ blueprint: getGlobalBlueprintPath(config.agentDir),
511
+ root: null,
512
+ directory: null,
513
+ error: crash,
514
+ logPath: null,
515
+ outputTail: "",
516
+ };
517
+ return {
518
+ status: "failed",
519
+ kind: undefined,
520
+ layers: await layersOfCrashedBuild(repositories, config, failure),
521
+ failures: [failure],
522
+ warnings: [],
523
+ removed: [],
524
+ };
525
+ }
526
+ }
527
+ /**
528
+ * Whether the worktree at `root`, restored by Atomic, still needs a build: its last build failed or never finished, or
529
+ * the ledger has no record of one (the worktree was never built, or a build died before it could write one).
530
+ */
531
+ export function needsRebuild(ledger, root) {
532
+ const state = ledger.roots[rootKey(root)]?.state;
533
+ return state === undefined || state === "failed" || state === "running";
534
+ }
535
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../../src/core/resume/blueprint/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7G,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACN,yBAAyB,EAEzB,qBAAqB,EAGrB,gBAAgB,GAChB,MAAM,aAAa,CAAC;AACrB,OA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E,EAAE;YACZ,OAAO,EAAE,EAAE;SACX,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,MAAuB,EAAE,IAAY;IACjE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC;IACjD,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,SAAS,CAAC;AACzE,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { copyFile, mkdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { getBlueprintActionsDir, getGlobalBlueprintPath, getProjectBlueprintPath } from \"../../../config.js\";\nimport { getHomeDir } from \"../../../utils/paths.ts\";\nimport { getShellEnv } from \"../../../utils/shell.ts\";\nimport type { ActionFetcher } from \"./actions.ts\";\nimport { sessionEnvrcPath } from \"./envrc.ts\";\nimport {\n\tBlueprintBuildFailedError,\n\ttype BlueprintError,\n\tBlueprintInvalidError,\n\ttype BlueprintScope,\n\ttype BlueprintSection,\n\tisBlueprintError,\n} from \"./errors.ts\";\nimport {\n\ttype BlueprintLedger,\n\tblueprintDigest,\n\treadLedger,\n\trepositoryKey,\n\trootKey,\n\tupdateLedger,\n\ttype WorkspaceLedgerEntry,\n\tworkspaceKey,\n} from \"./ledger.ts\";\nimport { hostPlatform, parseBlueprint, selectDocument } from \"./schema.ts\";\nimport { BLUEPRINT_STEP_TIMEOUT_MS, runSection, type StepContext, type StepFailure } from \"./steps.ts\";\nimport type { BlueprintDocument, BlueprintPlatform, BlueprintWarning, ParsedBlueprint, RunStep } from \"./types.ts\";\n\n/** A full build runs instead of a differential one when the last full build is older than this: 7 days. */\nexport const BLUEPRINT_FULL_BUILD_MAX_AGE_MS = 7 * 24 * 60 * 60_000;\n\n/** The name the deprecated `resume.setupCommand` alias goes by in steps, logs and failures. */\nexport const SETUP_COMMAND_ALIAS = \"resume.setupCommand\";\n\n/** A repository a build sets up: the worktree restored for it and a stable identity for the ledger. */\nexport interface BlueprintRepository {\n\t/** Root of the restored worktree. */\n\treadonly root: string;\n\t/** What makes two restores the same repository on this machine: its sorted remotes, else its root. */\n\treadonly identity: string;\n}\n\nexport interface BlueprintBuildConfig {\n\treadonly agentDir: string;\n\t/** Host directory that holds the build ledger, logs and `$ENVRC` files. */\n\treadonly storeDir: string;\n\t/** Whether the project at a worktree is trusted: only trusted projects run build steps. */\n\treadonly trusted: (worktree: string) => boolean;\n\t/** The deprecated `resume.setupCommand`, run as one global maintenance step in each restored repository root. */\n\treadonly setupCommand?: string;\n\treadonly platform?: BlueprintPlatform;\n\treadonly homeDir?: string;\n\treadonly now?: () => number;\n\treadonly stepTimeoutMs?: number;\n\treadonly fullBuildMaxAgeMs?: number;\n\t/** The environment steps start from. Default: the shell environment of Atomic's own tools. */\n\treadonly environment?: NodeJS.ProcessEnv;\n\treadonly fetchAction?: ActionFetcher;\n}\n\n/** A blueprint that did not complete: which one, which step, and where its log is. */\nexport interface BlueprintFailure {\n\treadonly scope: BlueprintScope;\n\t/** The blueprint file, or {@link SETUP_COMMAND_ALIAS}. */\n\treadonly blueprint: string;\n\t/** The repository root the blueprint belongs to; null for the global blueprint. */\n\treadonly root: string | null;\n\t/** The workspace directory within the repository, `.` for its root; null for the global blueprint. */\n\treadonly directory: string | null;\n\treadonly error: BlueprintError;\n\treadonly logPath: string | null;\n\t/** The end of the failing step's output. */\n\treadonly outputTail: string;\n}\n\nexport type BlueprintLayerState =\n\t| { readonly kind: \"built\"; readonly action: \"rebuild\" | \"inherit\" }\n\t| {\n\t\t\treadonly kind: \"not-run\";\n\t\t\treadonly reason: \"untrusted\" | \"in-place\" | \"earlier\" | \"global-failed\" | \"build-failed\" | \"skipped\";\n\t }\n\t| { readonly kind: \"failed\"; readonly failure: BlueprintFailure; readonly section: BlueprintSection | null }\n\t| { readonly kind: \"no-document\" };\n\n/** One blueprint of a build: its document for this platform, and what the build did with it. */\nexport interface BlueprintLayer {\n\treadonly scope: BlueprintScope;\n\treadonly blueprint: string;\n\treadonly root: string | null;\n\treadonly directory: string | null;\n\t/** The document that targets this platform; undefined when the file is invalid or has none. */\n\treadonly document: BlueprintDocument | undefined;\n\treadonly state: BlueprintLayerState;\n}\n\n/**\n * `none`: no blueprint applies. `skipped`: blueprints apply but nothing ran (an untrusted project). `success`,\n * `partial` (a repository or workspace blueprint failed) and `failed` (the global blueprint or its post-build did).\n */\nexport type BlueprintBuildStatus = \"none\" | \"skipped\" | \"success\" | \"partial\" | \"failed\";\n\nexport interface BlueprintBuildOutcome {\n\treadonly status: BlueprintBuildStatus;\n\t/** Undefined when nothing ran. */\n\treadonly kind: \"full\" | \"differential\" | undefined;\n\treadonly layers: readonly BlueprintLayer[];\n\treadonly failures: readonly BlueprintFailure[];\n\treadonly warnings: readonly BlueprintWarning[];\n\t/** The workspace directories dropped from the ledger because their blueprint is gone. */\n\treadonly removed: readonly string[];\n}\n\ninterface LoadedBlueprint {\n\treadonly path: string;\n\treadonly scope: BlueprintScope;\n\treadonly source: string | undefined;\n\treadonly parsed: ParsedBlueprint | undefined;\n\treadonly document: BlueprintDocument | undefined;\n\t/** Why the blueprint cannot be used: it is invalid, or it could not be read. */\n\treadonly invalid: BlueprintInvalidError | BlueprintBuildFailedError | undefined;\n}\n\nasync function readIfPresent(path: string): Promise<string | undefined> {\n\ttry {\n\t\treturn await readFile(path, \"utf8\");\n\t} catch (error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\tif (code === \"ENOENT\" || code === \"ENOTDIR\") return undefined;\n\t\tthrow error;\n\t}\n}\n\nasync function fileExists(path: string): Promise<boolean> {\n\ttry {\n\t\tawait stat(path);\n\t\treturn true;\n\t} catch (error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code !== \"ENOENT\" && code !== \"ENOTDIR\";\n\t}\n}\n\nfunction unreadable(path: string, error: unknown): BlueprintBuildFailedError {\n\treturn new BlueprintBuildFailedError(\n\t\t{ phase: \"read-blueprint\", detail: `${path} could not be read` },\n\t\terror instanceof Error ? error : new Error(String(error)),\n\t);\n}\n\nasync function loadBlueprint(\n\tpath: string,\n\tscope: BlueprintScope,\n\tplatform: BlueprintPlatform,\n): Promise<LoadedBlueprint> {\n\tlet source: string | undefined;\n\ttry {\n\t\tsource = await readIfPresent(path);\n\t} catch (error) {\n\t\treturn { path, scope, source: \"\", parsed: undefined, document: undefined, invalid: unreadable(path, error) };\n\t}\n\tif (source === undefined) return { path, scope, source, parsed: undefined, document: undefined, invalid: undefined };\n\ttry {\n\t\tconst parsed = parseBlueprint(source, { path, scope });\n\t\treturn { path, scope, source, parsed, document: selectDocument(parsed, platform), invalid: undefined };\n\t} catch (error) {\n\t\tif (error instanceof BlueprintInvalidError) {\n\t\t\treturn { path, scope, source, parsed: undefined, document: undefined, invalid: error };\n\t\t}\n\t\treturn { path, scope, source, parsed: undefined, document: undefined, invalid: unreadable(path, error) };\n\t}\n}\n\nfunction aliasStep(command: string): RunStep {\n\treturn { kind: \"run\", name: SETUP_COMMAND_ALIAS, run: command, env: {} };\n}\n\n/** The document of the global blueprint as the agent sees it: the alias is one more global maintenance step. */\nfunction withAlias(document: BlueprintDocument | undefined, alias: string | undefined, platform: BlueprintPlatform) {\n\tif (alias === undefined) return document;\n\tconst base: BlueprintDocument = document ?? {\n\t\tplatforms: [platform],\n\t\tshell: \"default\",\n\t\tinitialize: [],\n\t\tmaintenance: [],\n\t\tknowledge: [],\n\t\tpostBuild: [],\n\t\tincludes: [],\n\t};\n\treturn { ...base, maintenance: [...base.maintenance, aliasStep(alias)] };\n}\n\nfunction layerOf(\n\tloaded: LoadedBlueprint,\n\troot: string | null,\n\tdirectory: string | null,\n\tstate: BlueprintLayerState,\n\tdocument: BlueprintDocument | undefined = loaded.document,\n): BlueprintLayer {\n\treturn { scope: loaded.scope, blueprint: loaded.path, root, directory, document, state };\n}\n\nasync function loadGlobal(config: BlueprintBuildConfig, platform: BlueprintPlatform): Promise<LoadedBlueprint> {\n\treturn loadBlueprint(getGlobalBlueprintPath(config.agentDir), \"global\", platform);\n}\n\nasync function includedWorkspaces(\n\troot: string,\n\trootBlueprint: LoadedBlueprint,\n): Promise<{ readonly directory: string; readonly path: string }[]> {\n\treturn (rootBlueprint.document?.includes ?? []).map((include) => ({\n\t\tdirectory: include.directory,\n\t\tpath: join(root, include.file),\n\t}));\n}\n\n/**\n * What the blueprints of `repositories` and the global blueprint say, without running anything: every layer carries\n * `state` as given. This is what the agent is told when no build ran (an untrusted project, a checkout used in place).\n */\nexport async function describeBlueprints(\n\trepositories: readonly BlueprintRepository[],\n\tconfig: BlueprintBuildConfig,\n\treason: \"untrusted\" | \"in-place\" | \"earlier\" | \"build-failed\" | \"skipped\",\n\tincludeGlobal = true,\n): Promise<BlueprintLayer[]> {\n\tconst platform = config.platform ?? hostPlatform();\n\tconst state: BlueprintLayerState = { kind: \"not-run\", reason };\n\tconst layers: BlueprintLayer[] = [];\n\tconst global = includeGlobal ? await loadGlobal(config, platform) : undefined;\n\tconst globalDocument = withAlias(global?.document, config.setupCommand?.trim() || undefined, platform);\n\tif (global !== undefined && (globalDocument !== undefined || global.invalid !== undefined)) {\n\t\tlayers.push(layerOf(global, null, null, state, globalDocument));\n\t}\n\tfor (const repository of repositories) {\n\t\tlayers.push(...(await describeRepository(repository, platform, state)));\n\t}\n\treturn layers;\n}\n\nasync function describeRepository(\n\trepository: BlueprintRepository,\n\tplatform: BlueprintPlatform,\n\tstate: BlueprintLayerState,\n): Promise<BlueprintLayer[]> {\n\tconst root = await loadBlueprint(getProjectBlueprintPath(repository.root), \"repository\", platform);\n\tif (root.source === undefined) return [];\n\tconst layers = [layerOf(root, repository.root, \".\", state)];\n\tfor (const include of await includedWorkspaces(repository.root, root)) {\n\t\tconst workspace = await loadBlueprint(include.path, \"workspace\", platform);\n\t\tif (workspace.source !== undefined) layers.push(layerOf(workspace, repository.root, include.directory, state));\n\t}\n\treturn layers;\n}\n\ninterface BuildRun {\n\treadonly config: BlueprintBuildConfig;\n\treadonly platform: BlueprintPlatform;\n\treadonly buildId: string;\n\treadonly full: boolean;\n\treadonly ledger: BlueprintLedger;\n\treadonly envrcPath: string;\n\treadonly environment: NodeJS.ProcessEnv;\n\treadonly signal: AbortSignal | undefined;\n\treadonly layers: BlueprintLayer[];\n\treadonly failures: BlueprintFailure[];\n\treadonly warnings: BlueprintWarning[];\n\treadonly removed: string[];\n\treadonly workspaces: Map<string, WorkspaceLedgerEntry | null>;\n\treadonly roots: Map<string, \"success\" | \"failed\">;\n}\n\nfunction stepContext(\n\trun: BuildRun,\n\toptions: { blueprint: string; scope: BlueprintScope; cwd: string; document: BlueprintDocument; tag: string },\n): StepContext {\n\treturn {\n\t\tblueprint: options.blueprint,\n\t\tscope: options.scope,\n\t\tcwd: options.cwd,\n\t\tshell: options.document.shell,\n\t\tplatform: run.platform,\n\t\tenvrcPath: run.envrcPath,\n\t\tlogDirectory: join(run.config.storeDir, \"blueprint-logs\"),\n\t\tlogPrefix: `${run.buildId}-${options.tag}`,\n\t\ttimeoutMs: run.config.stepTimeoutMs ?? BLUEPRINT_STEP_TIMEOUT_MS,\n\t\tenvironment: run.environment,\n\t\tactionsCacheDir: getBlueprintActionsDir(run.config.agentDir),\n\t\tfetchAction: run.config.fetchAction,\n\t\tsignal: run.signal,\n\t};\n}\n\nfunction tagOf(root: string | null, directory: string | null): string {\n\tif (root === null) return \"global\";\n\tconst slug = (directory ?? \".\").replaceAll(/[^A-Za-z0-9]+/gu, \"_\");\n\treturn `${rootKey(root).slice(0, 8)}-${slug}`;\n}\n\nfunction failureOf(\n\tloaded: { path: string; scope: BlueprintScope },\n\troot: string | null,\n\tdirectory: string | null,\n\tstep: StepFailure | { error: BlueprintError; logPath: null; outputTail: string },\n): BlueprintFailure {\n\treturn {\n\t\tscope: loaded.scope,\n\t\tblueprint: loaded.path,\n\t\troot,\n\t\tdirectory,\n\t\terror: step.error,\n\t\tlogPath: step.logPath,\n\t\toutputTail: step.outputTail,\n\t};\n}\n\nfunction failureSection(error: BlueprintError): BlueprintSection | null {\n\tconst section = (error.fields as { section?: unknown }).section;\n\treturn section === \"initialize\" || section === \"maintenance\" || section === \"post-build\" ? section : null;\n}\n\n/** Builds one repository or workspace blueprint: initialize when it needs a rebuild, then maintenance. */\nasync function buildBlueprint(\n\trun: BuildRun,\n\trepository: BlueprintRepository,\n\tloaded: LoadedBlueprint,\n\tdirectory: string,\n\tforceRebuild: boolean,\n): Promise<BlueprintLayer> {\n\tconst key = workspaceKey(repository.identity, directory);\n\tconst source = loaded.source ?? \"\";\n\tconst digest = blueprintDigest(directory, source);\n\tconst builtAt = new Date((run.config.now ?? Date.now)()).toISOString();\n\tconst entry = run.ledger.workspaces[key];\n\tconst action =\n\t\trun.full || forceRebuild || entry === undefined || entry.digest !== digest || entry.status !== \"success\"\n\t\t\t? \"rebuild\"\n\t\t\t: \"inherit\";\n\tconst finish = (failure: BlueprintFailure | undefined): void => {\n\t\trun.workspaces.set(\n\t\t\tkey,\n\t\t\tfailure === undefined\n\t\t\t\t? { digest, status: \"success\", builtAt }\n\t\t\t\t: {\n\t\t\t\t\t\tdigest,\n\t\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\t\tbuiltAt,\n\t\t\t\t\t\tfailedStep: String((failure.error.fields as { step?: unknown }).step ?? failure.blueprint),\n\t\t\t\t\t\t...(failure.logPath === null ? {} : { logPath: failure.logPath }),\n\t\t\t\t\t},\n\t\t);\n\t\tif (failure !== undefined) run.failures.push(failure);\n\t};\n\tif (loaded.invalid !== undefined) {\n\t\tconst failure = failureOf(loaded, repository.root, directory, {\n\t\t\terror: loaded.invalid,\n\t\t\tlogPath: null,\n\t\t\toutputTail: \"\",\n\t\t});\n\t\tfinish(failure);\n\t\treturn layerOf(loaded, repository.root, directory, { kind: \"failed\", failure, section: null });\n\t}\n\tconst document = loaded.document;\n\tif (document === undefined) {\n\t\tfinish(undefined);\n\t\treturn layerOf(loaded, repository.root, directory, { kind: \"no-document\" });\n\t}\n\trun.warnings.push(...(loaded.parsed?.warnings ?? []));\n\tconst context = stepContext(run, {\n\t\tblueprint: loaded.path,\n\t\tscope: loaded.scope,\n\t\tcwd: directory === \".\" ? repository.root : join(repository.root, directory),\n\t\tdocument,\n\t\ttag: tagOf(repository.root, directory),\n\t});\n\tlet failed: StepFailure | undefined;\n\tif (action === \"rebuild\") failed = (await runSection(\"initialize\", document.initialize, context)).failure;\n\tif (failed === undefined) failed = (await runSection(\"maintenance\", document.maintenance, context)).failure;\n\tconst failure = failed === undefined ? undefined : failureOf(loaded, repository.root, directory, failed);\n\tfinish(failure);\n\treturn layerOf(\n\t\tloaded,\n\t\trepository.root,\n\t\tdirectory,\n\t\tfailure === undefined\n\t\t\t? { kind: \"built\", action }\n\t\t\t: { kind: \"failed\", failure, section: failureSection(failure.error) },\n\t);\n}\n\nasync function buildRepository(run: BuildRun, repository: BlueprintRepository, seen: Set<string>): Promise<void> {\n\tconst forceRebuild = run.ledger.roots[rootKey(repository.root)]?.state === \"running\";\n\tconst root = await loadBlueprint(getProjectBlueprintPath(repository.root), \"repository\", run.platform);\n\tif (root.source === undefined) return;\n\tseen.add(workspaceKey(repository.identity, \".\"));\n\trun.layers.push(await buildBlueprint(run, repository, root, \".\", forceRebuild));\n\tfor (const include of await includedWorkspaces(repository.root, root)) {\n\t\tconst workspace = await loadBlueprint(include.path, \"workspace\", run.platform);\n\t\tif (workspace.source !== undefined) {\n\t\t\tseen.add(workspaceKey(repository.identity, include.directory));\n\t\t\trun.layers.push(await buildBlueprint(run, repository, workspace, include.directory, forceRebuild));\n\t\t}\n\t}\n}\n\nfunction removedWorkspaces(run: BuildRun, repositories: readonly BlueprintRepository[], seen: Set<string>): void {\n\tfor (const repository of repositories) {\n\t\tconst prefix = `${repositoryKey(repository.identity)}:`;\n\t\tfor (const key of Object.keys(run.ledger.workspaces)) {\n\t\t\tif (key.startsWith(prefix) && !seen.has(key)) {\n\t\t\t\trun.workspaces.set(key, null);\n\t\t\t\trun.removed.push(key.slice(prefix.length));\n\t\t\t}\n\t\t}\n\t}\n}\n\nasync function runGlobalLayers(\n\trun: BuildRun,\n\tglobal: LoadedBlueprint,\n\trepositories: readonly BlueprintRepository[],\n): Promise<BlueprintLayer | undefined> {\n\tconst alias = run.config.setupCommand?.trim() || undefined;\n\tconst document = global.document;\n\tconst display = withAlias(document, alias, run.platform);\n\tif (global.invalid !== undefined) {\n\t\tconst failure = failureOf(global, null, null, { error: global.invalid, logPath: null, outputTail: \"\" });\n\t\trun.failures.push(failure);\n\t\treturn layerOf(global, null, null, { kind: \"failed\", failure, section: null });\n\t}\n\tif (display === undefined) return undefined;\n\trun.warnings.push(...(global.parsed?.warnings ?? []));\n\tconst home = run.config.homeDir ?? getHomeDir();\n\tconst context = (cwd: string, blueprint: string) =>\n\t\tstepContext(run, { blueprint, scope: \"global\", cwd, document: display, tag: \"global\" });\n\tlet failed: StepFailure | undefined;\n\tif (document !== undefined && run.full) {\n\t\tfailed = (await runSection(\"initialize\", document.initialize, context(home, global.path))).failure;\n\t}\n\tif (failed === undefined && document !== undefined) {\n\t\tfailed = (await runSection(\"maintenance\", document.maintenance, context(home, global.path))).failure;\n\t}\n\tif (failed === undefined && alias !== undefined) {\n\t\tfor (const repository of repositories) {\n\t\t\tconst result = await runSection(\"maintenance\", [aliasStep(alias)], {\n\t\t\t\t...context(repository.root, SETUP_COMMAND_ALIAS),\n\t\t\t\tlogPrefix: `${run.buildId}-${tagOf(repository.root, \"alias\")}`,\n\t\t\t});\n\t\t\tif (result.failure !== undefined) {\n\t\t\t\tfailed = result.failure;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (failed === undefined)\n\t\treturn layerOf(global, null, null, { kind: \"built\", action: run.full ? \"rebuild\" : \"inherit\" }, display);\n\tconst failure = failureOf({ path: failedBlueprint(failed, global.path), scope: \"global\" }, null, null, failed);\n\trun.failures.push(failure);\n\treturn layerOf(global, null, null, { kind: \"failed\", failure, section: failureSection(failed.error) }, display);\n}\n\nfunction failedBlueprint(failure: StepFailure, globalPath: string): string {\n\tconst blueprint = (failure.error.fields as { blueprint?: unknown }).blueprint;\n\treturn typeof blueprint === \"string\" ? blueprint : globalPath;\n}\n\nasync function runPostBuild(run: BuildRun, global: LoadedBlueprint, layer: BlueprintLayer): Promise<BlueprintLayer> {\n\tconst document = global.document;\n\tif (document === undefined || document.postBuild.length === 0) return layer;\n\tconst context = stepContext(run, {\n\t\tblueprint: global.path,\n\t\tscope: \"global\",\n\t\tcwd: run.config.homeDir ?? getHomeDir(),\n\t\tdocument,\n\t\ttag: \"global\",\n\t});\n\tconst { failure: failed } = await runSection(\"post-build\", document.postBuild, context);\n\tif (failed === undefined) return layer;\n\tconst failure = failureOf(global, null, null, failed);\n\trun.failures.push(failure);\n\treturn { ...layer, state: { kind: \"failed\", failure, section: \"post-build\" } };\n}\n\n/** Runs `work`; its failure is the typed build failure of `phase`, with the original error as its cause. */\nasync function inPhase<T>(phase: \"ledger\" | \"environment\", detail: string, work: () => Promise<T>): Promise<T> {\n\ttry {\n\t\treturn await work();\n\t} catch (error) {\n\t\tif (isBlueprintError(error)) throw error;\n\t\tthrow new BlueprintBuildFailedError({ phase, detail }, error instanceof Error ? error : new Error(String(error)));\n\t}\n}\n\nasync function writeSessionEnvironment(run: BuildRun, roots: readonly BlueprintRepository[]): Promise<void> {\n\tconst content = await readFile(run.envrcPath, \"utf8\");\n\tfor (const repository of roots) {\n\t\tconst target = sessionEnvrcPath(run.config.storeDir, repository.root);\n\t\tif (content.trim() === \"\") {\n\t\t\tawait rm(target, { force: true });\n\t\t\tcontinue;\n\t\t}\n\t\tawait mkdir(dirname(target), { recursive: true });\n\t\tawait copyFile(run.envrcPath, target);\n\t}\n}\n\nfunction statusOf(run: BuildRun, globalFailed: boolean): BlueprintBuildStatus {\n\tif (globalFailed) return \"failed\";\n\treturn run.failures.length > 0 ? \"partial\" : \"success\";\n}\n\nasync function executeBuild(\n\trepositories: readonly BlueprintRepository[],\n\tconfig: BlueprintBuildConfig,\n\tsignal: AbortSignal | undefined,\n): Promise<BlueprintBuildOutcome> {\n\tconst platform = config.platform ?? hostPlatform();\n\tconst now = config.now ?? Date.now;\n\tconst trusted = repositories.filter((repository) => config.trusted(repository.root));\n\tconst untrusted = repositories.filter((repository) => !trusted.includes(repository));\n\tconst global = await loadGlobal(config, platform);\n\tconst alias = config.setupCommand?.trim() || undefined;\n\tconst layers: BlueprintLayer[] = [];\n\tconst untrustedLayers = await describeBlueprints(untrusted, config, \"untrusted\", false);\n\tconst hasTrustedBlueprint =\n\t\tglobal.source !== undefined ||\n\t\talias !== undefined ||\n\t\t(await Promise.all(trusted.map((repository) => fileExists(getProjectBlueprintPath(repository.root))))).some(\n\t\t\tBoolean,\n\t\t);\n\tif (trusted.length === 0 || !hasTrustedBlueprint) {\n\t\tconst described = await describeBlueprints(trusted, config, trusted.length === 0 ? \"untrusted\" : \"skipped\");\n\t\tconst all = [...described, ...untrustedLayers];\n\t\treturn {\n\t\t\tstatus: all.length === 0 ? \"none\" : \"skipped\",\n\t\t\tkind: undefined,\n\t\t\tlayers: all,\n\t\t\tfailures: [],\n\t\t\twarnings: [],\n\t\t\tremoved: [],\n\t\t};\n\t}\n\tconst ledger = await inPhase(\"ledger\", \"the build ledger could not be read\", () => readLedger(config.storeDir));\n\tconst globalDigest = blueprintDigest(\".\", global.source ?? \"\", alias ?? \"\");\n\tconst last = ledger.global;\n\tconst full =\n\t\tlast === undefined ||\n\t\tlast.status !== \"success\" ||\n\t\tlast.digest !== globalDigest ||\n\t\tlast.lastFullBuildAt === undefined ||\n\t\tnow() - Date.parse(last.lastFullBuildAt) > (config.fullBuildMaxAgeMs ?? BLUEPRINT_FULL_BUILD_MAX_AGE_MS);\n\tconst buildId = `${new Date(now()).toISOString().replaceAll(/[-:.TZ]/gu, \"\")}-${randomUUID().slice(0, 8)}`;\n\tconst envrcPath = join(config.storeDir, \"blueprint-builds\", `${buildId}.envrc`);\n\tawait inPhase(\"environment\", \"the $ENVRC file could not be created\", async () => {\n\t\tawait mkdir(dirname(envrcPath), { recursive: true });\n\t\tawait writeFile(envrcPath, \"\", { mode: 0o600 });\n\t});\n\tconst run: BuildRun = {\n\t\tconfig,\n\t\tplatform,\n\t\tbuildId,\n\t\tfull,\n\t\tledger,\n\t\tenvrcPath,\n\t\tenvironment: config.environment ?? getShellEnv(),\n\t\tsignal,\n\t\tlayers,\n\t\tfailures: [],\n\t\twarnings: [],\n\t\tremoved: [],\n\t\tworkspaces: new Map(),\n\t\troots: new Map(),\n\t};\n\tconst startedAt = new Date(now()).toISOString();\n\tawait inPhase(\"ledger\", \"the build ledger could not be written\", () =>\n\t\tupdateLedger(config.storeDir, (current) => ({\n\t\t\t...current,\n\t\t\troots: {\n\t\t\t\t...current.roots,\n\t\t\t\t...Object.fromEntries(\n\t\t\t\t\ttrusted.map((repository) => [rootKey(repository.root), { state: \"running\" as const, at: startedAt }]),\n\t\t\t\t),\n\t\t\t},\n\t\t})),\n\t);\n\ttry {\n\t\tlet globalLayer = await runGlobalLayers(run, global, trusted);\n\t\tconst globalFailed = globalLayer?.state.kind === \"failed\";\n\t\tconst seen = new Set<string>();\n\t\tif (globalFailed) {\n\t\t\tfor (const repository of trusted) {\n\t\t\t\trun.layers.push(\n\t\t\t\t\t...(await describeRepository(repository, platform, { kind: \"not-run\", reason: \"global-failed\" })),\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const repository of trusted) await buildRepository(run, repository, seen);\n\t\t\tremovedWorkspaces(run, trusted, seen);\n\t\t\tif (globalLayer !== undefined) globalLayer = await runPostBuild(run, global, globalLayer);\n\t\t}\n\t\tconst globalOk = globalLayer === undefined || globalLayer.state.kind !== \"failed\";\n\t\tconst finishedAt = new Date(now()).toISOString();\n\t\tconst failedRoots = new Set(run.failures.map((failure) => failure.root).filter((root) => root !== null));\n\t\tawait inPhase(\"environment\", \"the $ENVRC of the build could not be kept for the session\", () =>\n\t\t\twriteSessionEnvironment(run, trusted),\n\t\t);\n\t\tawait inPhase(\"ledger\", \"the build ledger could not be written\", () =>\n\t\t\tupdateLedger(config.storeDir, (current) => {\n\t\t\t\tconst workspaces = { ...current.workspaces };\n\t\t\t\tfor (const [key, entry] of run.workspaces) {\n\t\t\t\t\tif (entry === null) delete workspaces[key];\n\t\t\t\t\telse workspaces[key] = entry;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tglobal: {\n\t\t\t\t\t\tdigest: globalDigest,\n\t\t\t\t\t\tstatus: globalOk ? \"success\" : \"failed\",\n\t\t\t\t\t\tbuiltAt: finishedAt,\n\t\t\t\t\t\t...(globalOk && full\n\t\t\t\t\t\t\t? { lastFullBuildAt: finishedAt }\n\t\t\t\t\t\t\t: !full && last?.lastFullBuildAt !== undefined\n\t\t\t\t\t\t\t\t? { lastFullBuildAt: last.lastFullBuildAt }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t},\n\t\t\t\t\tworkspaces,\n\t\t\t\t\troots: {\n\t\t\t\t\t\t...current.roots,\n\t\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\t\ttrusted.map((repository) => [\n\t\t\t\t\t\t\t\trootKey(repository.root),\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tstate:\n\t\t\t\t\t\t\t\t\t\t!globalOk || failedRoots.has(repository.root)\n\t\t\t\t\t\t\t\t\t\t\t? (\"failed\" as const)\n\t\t\t\t\t\t\t\t\t\t\t: (\"success\" as const),\n\t\t\t\t\t\t\t\t\tat: finishedAt,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\t\treturn {\n\t\t\tstatus: statusOf(run, !globalOk),\n\t\t\tkind: full ? \"full\" : \"differential\",\n\t\t\tlayers: [...(globalLayer === undefined ? [] : [globalLayer]), ...run.layers, ...untrustedLayers],\n\t\t\tfailures: run.failures,\n\t\t\twarnings: run.warnings,\n\t\t\tremoved: run.removed,\n\t\t};\n\t} finally {\n\t\tawait rm(envrcPath, { force: true });\n\t}\n}\n\nfunction crashedBuild(error: unknown): BlueprintBuildFailedError {\n\tconst cause = error instanceof Error ? error : new Error(String(error));\n\treturn new BlueprintBuildFailedError({ phase: \"unknown\", detail: cause.message.slice(0, 200) }, cause);\n}\n\n/**\n * The layers of a build that stopped before it finished: what each repository's blueprints say, labelled as not\n * confirmed, and the global layer carrying `failure`, so the agent still gets the maintenance, the knowledge and the\n * failure. Never throws: when the blueprints cannot even be described, only the global layer is returned.\n */\nasync function layersOfCrashedBuild(\n\trepositories: readonly BlueprintRepository[],\n\tconfig: BlueprintBuildConfig,\n\tfailure: BlueprintFailure,\n): Promise<BlueprintLayer[]> {\n\tconst failedState: BlueprintLayerState = { kind: \"failed\", failure, section: null };\n\tconst bare: BlueprintLayer = {\n\t\tscope: \"global\",\n\t\tblueprint: failure.blueprint,\n\t\troot: null,\n\t\tdirectory: null,\n\t\tdocument: undefined,\n\t\tstate: failedState,\n\t};\n\ttry {\n\t\tconst trusted = repositories.filter((repository) => config.trusted(repository.root));\n\t\tconst untrusted = repositories.filter((repository) => !trusted.includes(repository));\n\t\tconst described = [\n\t\t\t...(await describeBlueprints(trusted, config, \"build-failed\")),\n\t\t\t...(await describeBlueprints(untrusted, config, \"untrusted\", false)),\n\t\t];\n\t\tconst global = described.find((layer) => layer.scope === \"global\");\n\t\treturn [{ ...(global ?? bare), state: failedState }, ...described.filter((layer) => layer.scope !== \"global\")];\n\t} catch {\n\t\treturn [bare];\n\t}\n}\n\n/**\n * Builds the worktrees a resume restored: global `initialize` (in a full build) and `maintenance`, then each trusted\n * repository's `initialize` (when it needs a rebuild) and `maintenance` with its included workspaces, then the global\n * `post-build`. A step that fails stops the rest of its blueprint, never the other blueprints, and never the resume:\n * the failure is in the outcome. Only `signal` aborting rejects, with its reason. Untrusted repositories run nothing.\n */\nexport async function runBlueprintBuild(\n\trepositories: readonly BlueprintRepository[],\n\tconfig: BlueprintBuildConfig,\n\tsignal?: AbortSignal,\n): Promise<BlueprintBuildOutcome> {\n\tsignal?.throwIfAborted();\n\ttry {\n\t\treturn await executeBuild(repositories, config, signal);\n\t} catch (error) {\n\t\tif (signal?.aborted) throw error;\n\t\tconst crash = isBlueprintError(error) ? error : crashedBuild(error);\n\t\tconst failure: BlueprintFailure = {\n\t\t\tscope: \"global\",\n\t\t\tblueprint: getGlobalBlueprintPath(config.agentDir),\n\t\t\troot: null,\n\t\t\tdirectory: null,\n\t\t\terror: crash,\n\t\t\tlogPath: null,\n\t\t\toutputTail: \"\",\n\t\t};\n\t\treturn {\n\t\t\tstatus: \"failed\",\n\t\t\tkind: undefined,\n\t\t\tlayers: await layersOfCrashedBuild(repositories, config, failure),\n\t\t\tfailures: [failure],\n\t\t\twarnings: [],\n\t\t\tremoved: [],\n\t\t};\n\t}\n}\n\n/**\n * Whether the worktree at `root`, restored by Atomic, still needs a build: its last build failed or never finished, or\n * the ledger has no record of one (the worktree was never built, or a build died before it could write one).\n */\nexport function needsRebuild(ledger: BlueprintLedger, root: string): boolean {\n\tconst state = ledger.roots[rootKey(root)]?.state;\n\treturn state === undefined || state === \"failed\" || state === \"running\";\n}\n"]}