@warpgogol/forge 9.1.0 → 9.2.3

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 (380) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +15 -8
  3. package/README.uk.md +15 -8
  4. package/bin/cli.ts +3 -2
  5. package/dist/bin/cli.js +3 -2
  6. package/dist/bin/cli.js.map +1 -1
  7. package/dist/os/core/core.module.d.ts.map +1 -1
  8. package/dist/os/core/core.module.js +6 -4
  9. package/dist/os/core/core.module.js.map +1 -1
  10. package/dist/os/flow/branch-name.d.ts +56 -0
  11. package/dist/os/flow/branch-name.d.ts.map +1 -0
  12. package/dist/os/flow/branch-name.js +108 -0
  13. package/dist/os/flow/branch-name.js.map +1 -0
  14. package/dist/os/flow/digest.d.ts +73 -0
  15. package/dist/os/flow/digest.d.ts.map +1 -0
  16. package/dist/os/flow/digest.js +634 -0
  17. package/dist/os/flow/digest.js.map +1 -0
  18. package/dist/os/flow/flow.module.d.ts +3 -0
  19. package/dist/os/flow/flow.module.d.ts.map +1 -0
  20. package/dist/os/flow/flow.module.js +716 -0
  21. package/dist/os/flow/flow.module.js.map +1 -0
  22. package/dist/os/flow/git.d.ts +68 -0
  23. package/dist/os/flow/git.d.ts.map +1 -0
  24. package/dist/os/flow/git.js +257 -0
  25. package/dist/os/flow/git.js.map +1 -0
  26. package/dist/os/flow/guard-files.d.ts +50 -0
  27. package/dist/os/flow/guard-files.d.ts.map +1 -0
  28. package/dist/os/flow/guard-files.js +147 -0
  29. package/dist/os/flow/guard-files.js.map +1 -0
  30. package/dist/os/flow/handlers/flow-backmerge.d.ts +27 -0
  31. package/dist/os/flow/handlers/flow-backmerge.d.ts.map +1 -0
  32. package/dist/os/flow/handlers/flow-backmerge.js +332 -0
  33. package/dist/os/flow/handlers/flow-backmerge.js.map +1 -0
  34. package/dist/os/flow/handlers/flow-check.d.ts +42 -0
  35. package/dist/os/flow/handlers/flow-check.d.ts.map +1 -0
  36. package/dist/os/flow/handlers/flow-check.js +347 -0
  37. package/dist/os/flow/handlers/flow-check.js.map +1 -0
  38. package/dist/os/flow/handlers/flow-cut.d.ts +63 -0
  39. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -0
  40. package/dist/os/flow/handlers/flow-cut.js +636 -0
  41. package/dist/os/flow/handlers/flow-cut.js.map +1 -0
  42. package/dist/os/flow/handlers/flow-digest.d.ts +5 -0
  43. package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -0
  44. package/dist/os/flow/handlers/flow-digest.js +110 -0
  45. package/dist/os/flow/handlers/flow-digest.js.map +1 -0
  46. package/dist/os/flow/handlers/flow-discard.d.ts +22 -0
  47. package/dist/os/flow/handlers/flow-discard.d.ts.map +1 -0
  48. package/dist/os/flow/handlers/flow-discard.js +200 -0
  49. package/dist/os/flow/handlers/flow-discard.js.map +1 -0
  50. package/dist/os/flow/handlers/flow-fix.d.ts +47 -0
  51. package/dist/os/flow/handlers/flow-fix.d.ts.map +1 -0
  52. package/dist/os/flow/handlers/flow-fix.js +443 -0
  53. package/dist/os/flow/handlers/flow-fix.js.map +1 -0
  54. package/dist/os/flow/handlers/flow-hold.d.ts +32 -0
  55. package/dist/os/flow/handlers/flow-hold.d.ts.map +1 -0
  56. package/dist/os/flow/handlers/flow-hold.js +359 -0
  57. package/dist/os/flow/handlers/flow-hold.js.map +1 -0
  58. package/dist/os/flow/handlers/flow-install.d.ts +92 -0
  59. package/dist/os/flow/handlers/flow-install.d.ts.map +1 -0
  60. package/dist/os/flow/handlers/flow-install.js +883 -0
  61. package/dist/os/flow/handlers/flow-install.js.map +1 -0
  62. package/dist/os/flow/handlers/flow-integrate.d.ts +35 -0
  63. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -0
  64. package/dist/os/flow/handlers/flow-integrate.js +419 -0
  65. package/dist/os/flow/handlers/flow-integrate.js.map +1 -0
  66. package/dist/os/flow/handlers/flow-open.d.ts +63 -0
  67. package/dist/os/flow/handlers/flow-open.d.ts.map +1 -0
  68. package/dist/os/flow/handlers/flow-open.js +294 -0
  69. package/dist/os/flow/handlers/flow-open.js.map +1 -0
  70. package/dist/os/flow/handlers/flow-push.d.ts +22 -0
  71. package/dist/os/flow/handlers/flow-push.d.ts.map +1 -0
  72. package/dist/os/flow/handlers/flow-push.js +306 -0
  73. package/dist/os/flow/handlers/flow-push.js.map +1 -0
  74. package/dist/os/flow/handlers/flow-status.d.ts +65 -0
  75. package/dist/os/flow/handlers/flow-status.d.ts.map +1 -0
  76. package/dist/os/flow/handlers/flow-status.js +193 -0
  77. package/dist/os/flow/handlers/flow-status.js.map +1 -0
  78. package/dist/os/flow/handlers/flow-unhold.d.ts +20 -0
  79. package/dist/os/flow/handlers/flow-unhold.d.ts.map +1 -0
  80. package/dist/os/flow/handlers/flow-unhold.js +158 -0
  81. package/dist/os/flow/handlers/flow-unhold.js.map +1 -0
  82. package/dist/os/flow/handlers/flow-version.d.ts +39 -0
  83. package/dist/os/flow/handlers/flow-version.d.ts.map +1 -0
  84. package/dist/os/flow/handlers/flow-version.js +122 -0
  85. package/dist/os/flow/handlers/flow-version.js.map +1 -0
  86. package/dist/os/flow/index.d.ts +30 -0
  87. package/dist/os/flow/index.d.ts.map +1 -0
  88. package/dist/os/flow/index.js +83 -0
  89. package/dist/os/flow/index.js.map +1 -0
  90. package/dist/os/flow/line-version.d.ts +23 -0
  91. package/dist/os/flow/line-version.d.ts.map +1 -0
  92. package/dist/os/flow/line-version.js +83 -0
  93. package/dist/os/flow/line-version.js.map +1 -0
  94. package/dist/os/flow/locks.d.ts +34 -0
  95. package/dist/os/flow/locks.d.ts.map +1 -0
  96. package/dist/os/flow/locks.js +147 -0
  97. package/dist/os/flow/locks.js.map +1 -0
  98. package/dist/os/flow/markers.d.ts +49 -0
  99. package/dist/os/flow/markers.d.ts.map +1 -0
  100. package/dist/os/flow/markers.js +112 -0
  101. package/dist/os/flow/markers.js.map +1 -0
  102. package/dist/os/flow/publish.d.ts +28 -0
  103. package/dist/os/flow/publish.d.ts.map +1 -0
  104. package/dist/os/flow/publish.js +153 -0
  105. package/dist/os/flow/publish.js.map +1 -0
  106. package/dist/os/flow/registry.d.ts +142 -0
  107. package/dist/os/flow/registry.d.ts.map +1 -0
  108. package/dist/os/flow/registry.js +198 -0
  109. package/dist/os/flow/registry.js.map +1 -0
  110. package/dist/os/flow/release-level.d.ts +23 -0
  111. package/dist/os/flow/release-level.d.ts.map +1 -0
  112. package/dist/os/flow/release-level.js +102 -0
  113. package/dist/os/flow/release-level.js.map +1 -0
  114. package/dist/os/flow/release-lines.d.ts +25 -0
  115. package/dist/os/flow/release-lines.d.ts.map +1 -0
  116. package/dist/os/flow/release-lines.js +172 -0
  117. package/dist/os/flow/release-lines.js.map +1 -0
  118. package/dist/os/flow/release-tags.d.ts +72 -0
  119. package/dist/os/flow/release-tags.d.ts.map +1 -0
  120. package/dist/os/flow/release-tags.js +166 -0
  121. package/dist/os/flow/release-tags.js.map +1 -0
  122. package/dist/os/flow/repo-kind.d.ts +41 -0
  123. package/dist/os/flow/repo-kind.d.ts.map +1 -0
  124. package/dist/os/flow/repo-kind.js +92 -0
  125. package/dist/os/flow/repo-kind.js.map +1 -0
  126. package/dist/os/flow/scripts.d.ts +20 -0
  127. package/dist/os/flow/scripts.d.ts.map +1 -0
  128. package/dist/os/flow/scripts.js +49 -0
  129. package/dist/os/flow/scripts.js.map +1 -0
  130. package/dist/os/flow/semver.d.ts +21 -0
  131. package/dist/os/flow/semver.d.ts.map +1 -0
  132. package/dist/os/flow/semver.js +73 -0
  133. package/dist/os/flow/semver.js.map +1 -0
  134. package/dist/os/flow/tests/helpers.d.ts +52 -0
  135. package/dist/os/flow/tests/helpers.d.ts.map +1 -0
  136. package/dist/os/flow/tests/helpers.js +189 -0
  137. package/dist/os/flow/tests/helpers.js.map +1 -0
  138. package/dist/os/flow/version-files.d.ts +21 -0
  139. package/dist/os/flow/version-files.d.ts.map +1 -0
  140. package/dist/os/flow/version-files.js +94 -0
  141. package/dist/os/flow/version-files.js.map +1 -0
  142. package/dist/os/flow/worktree-path.d.ts +31 -0
  143. package/dist/os/flow/worktree-path.d.ts.map +1 -0
  144. package/dist/os/flow/worktree-path.js +80 -0
  145. package/dist/os/flow/worktree-path.js.map +1 -0
  146. package/dist/os/mission/handlers/archive.d.ts.map +1 -1
  147. package/dist/os/mission/handlers/archive.js +43 -6
  148. package/dist/os/mission/handlers/archive.js.map +1 -1
  149. package/dist/os/program/handlers/seal.d.ts.map +1 -1
  150. package/dist/os/program/handlers/seal.js +1 -1
  151. package/dist/os/program/handlers/seal.js.map +1 -1
  152. package/dist/os/program/handlers/validate.d.ts.map +1 -1
  153. package/dist/os/program/handlers/validate.js +1 -1
  154. package/dist/os/program/handlers/validate.js.map +1 -1
  155. package/dist/os/program/program.module.d.ts.map +1 -1
  156. package/dist/os/program/program.module.js +2 -1
  157. package/dist/os/program/program.module.js.map +1 -1
  158. package/dist/os/program/schemas.d.ts +4 -6
  159. package/dist/os/program/schemas.d.ts.map +1 -1
  160. package/dist/os/program/schemas.js +16 -6
  161. package/dist/os/program/schemas.js.map +1 -1
  162. package/dist/os/program/state.d.ts +0 -1
  163. package/dist/os/program/state.d.ts.map +1 -1
  164. package/dist/os/program/state.js +1 -7
  165. package/dist/os/program/state.js.map +1 -1
  166. package/dist/os/rfc/acceptance.d.ts +21 -0
  167. package/dist/os/rfc/acceptance.d.ts.map +1 -1
  168. package/dist/os/rfc/acceptance.js +62 -13
  169. package/dist/os/rfc/acceptance.js.map +1 -1
  170. package/dist/os/rfc/frontmatter-io.d.ts +19 -0
  171. package/dist/os/rfc/frontmatter-io.d.ts.map +1 -1
  172. package/dist/os/rfc/frontmatter-io.js +65 -12
  173. package/dist/os/rfc/frontmatter-io.js.map +1 -1
  174. package/dist/os/rfc/handlers/validate-rules.d.ts +2 -5
  175. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  176. package/dist/os/rfc/handlers/validate-rules.js +10 -8
  177. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  178. package/dist/os/rfc/handlers/validate.d.ts.map +1 -1
  179. package/dist/os/rfc/handlers/validate.js +15 -5
  180. package/dist/os/rfc/handlers/validate.js.map +1 -1
  181. package/dist/os/rfc/index.d.ts +2 -2
  182. package/dist/os/rfc/index.d.ts.map +1 -1
  183. package/dist/os/rfc/index.js +5 -2
  184. package/dist/os/rfc/index.js.map +1 -1
  185. package/dist/os/rfc/probe-batch.d.ts +71 -0
  186. package/dist/os/rfc/probe-batch.d.ts.map +1 -0
  187. package/dist/os/rfc/probe-batch.js +251 -0
  188. package/dist/os/rfc/probe-batch.js.map +1 -0
  189. package/dist/os/rfc/rfc.module.d.ts.map +1 -1
  190. package/dist/os/rfc/rfc.module.js +16 -2
  191. package/dist/os/rfc/rfc.module.js.map +1 -1
  192. package/dist/os/rfc/verification-evidence.d.ts.map +1 -1
  193. package/dist/os/rfc/verification-evidence.js +21 -10
  194. package/dist/os/rfc/verification-evidence.js.map +1 -1
  195. package/dist/os/rfc/verification-refresh.d.ts.map +1 -1
  196. package/dist/os/rfc/verification-refresh.js +20 -13
  197. package/dist/os/rfc/verification-refresh.js.map +1 -1
  198. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts.map +1 -1
  199. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js +21 -7
  200. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js.map +1 -1
  201. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts.map +1 -1
  202. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js +1 -1
  203. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js.map +1 -1
  204. package/dist/os/werkstatt/werkstatt.module.d.ts.map +1 -1
  205. package/dist/os/werkstatt/werkstatt.module.js +2 -82
  206. package/dist/os/werkstatt/werkstatt.module.js.map +1 -1
  207. package/dist/src/config/forge-config.d.ts +0 -3
  208. package/dist/src/config/forge-config.d.ts.map +1 -1
  209. package/dist/src/config/forge-config.js +2 -4
  210. package/dist/src/config/forge-config.js.map +1 -1
  211. package/dist/src/index.d.ts +3 -0
  212. package/dist/src/index.d.ts.map +1 -1
  213. package/dist/src/index.js +2 -0
  214. package/dist/src/index.js.map +1 -1
  215. package/dist/src/onboarding/agents-generate.d.ts.map +1 -1
  216. package/dist/src/onboarding/agents-generate.js +49 -4
  217. package/dist/src/onboarding/agents-generate.js.map +1 -1
  218. package/dist/src/onboarding/create.d.ts +13 -0
  219. package/dist/src/onboarding/create.d.ts.map +1 -1
  220. package/dist/src/onboarding/create.js +95 -9
  221. package/dist/src/onboarding/create.js.map +1 -1
  222. package/dist/src/onboarding/doctor.d.ts.map +1 -1
  223. package/dist/src/onboarding/doctor.js +2 -47
  224. package/dist/src/onboarding/doctor.js.map +1 -1
  225. package/dist/src/onboarding/upgrade.d.ts +5 -0
  226. package/dist/src/onboarding/upgrade.d.ts.map +1 -1
  227. package/dist/src/onboarding/upgrade.js +70 -1
  228. package/dist/src/onboarding/upgrade.js.map +1 -1
  229. package/dist/src/types.d.ts +9 -0
  230. package/dist/src/types.d.ts.map +1 -1
  231. package/dist/src/types.js +2 -2
  232. package/docs/branch-model.md +98 -0
  233. package/docs/maintainers/publishing.md +14 -6
  234. package/docs/reference/cli.md +125 -0
  235. package/docs/reference/profiles.md +1 -0
  236. package/os/core/core.module.ts +7 -4
  237. package/os/flow/assets/flow-guard.sh +176 -0
  238. package/os/flow/branch-name.ts +139 -0
  239. package/os/flow/digest.ts +761 -0
  240. package/os/flow/flow.module.ts +740 -0
  241. package/os/flow/git.ts +342 -0
  242. package/os/flow/guard-files.ts +172 -0
  243. package/os/flow/handlers/flow-backmerge.ts +488 -0
  244. package/os/flow/handlers/flow-check.ts +450 -0
  245. package/os/flow/handlers/flow-cut.ts +912 -0
  246. package/os/flow/handlers/flow-digest.ts +124 -0
  247. package/os/flow/handlers/flow-discard.ts +301 -0
  248. package/os/flow/handlers/flow-fix.ts +597 -0
  249. package/os/flow/handlers/flow-hold.ts +500 -0
  250. package/os/flow/handlers/flow-install.ts +1185 -0
  251. package/os/flow/handlers/flow-integrate.ts +607 -0
  252. package/os/flow/handlers/flow-open.ts +447 -0
  253. package/os/flow/handlers/flow-push.ts +373 -0
  254. package/os/flow/handlers/flow-status.ts +283 -0
  255. package/os/flow/handlers/flow-unhold.ts +220 -0
  256. package/os/flow/handlers/flow-version.ts +196 -0
  257. package/os/flow/index.ts +102 -0
  258. package/os/flow/line-version.ts +113 -0
  259. package/os/flow/locks.ts +177 -0
  260. package/os/flow/markers.ts +135 -0
  261. package/os/flow/publish.ts +201 -0
  262. package/os/flow/registry.ts +266 -0
  263. package/os/flow/release-level.ts +139 -0
  264. package/os/flow/release-lines.ts +208 -0
  265. package/os/flow/release-tags.ts +231 -0
  266. package/os/flow/repo-kind.ts +117 -0
  267. package/os/flow/scripts.ts +73 -0
  268. package/os/flow/semver.ts +82 -0
  269. package/os/flow/tests/branch-name.test.ts +136 -0
  270. package/os/flow/tests/fixtures/branch-names.yaml +56 -0
  271. package/os/flow/tests/flow-backmerge.test.ts +267 -0
  272. package/os/flow/tests/flow-check-version.test.ts +138 -0
  273. package/os/flow/tests/flow-check.test.ts +213 -0
  274. package/os/flow/tests/flow-cut.rerun.test.ts +95 -0
  275. package/os/flow/tests/flow-cut.test.ts +319 -0
  276. package/os/flow/tests/flow-digest.test.ts +313 -0
  277. package/os/flow/tests/flow-discard.test.ts +220 -0
  278. package/os/flow/tests/flow-fix.test.ts +359 -0
  279. package/os/flow/tests/flow-guard-merge.test.ts +100 -0
  280. package/os/flow/tests/flow-guard-parity.test.ts +115 -0
  281. package/os/flow/tests/flow-guard-push.test.ts +100 -0
  282. package/os/flow/tests/flow-guard.test.ts +135 -0
  283. package/os/flow/tests/flow-hold.test.ts +465 -0
  284. package/os/flow/tests/flow-install-baseline.rerun.test.ts +73 -0
  285. package/os/flow/tests/flow-install-baseline.test.ts +164 -0
  286. package/os/flow/tests/flow-install-markers.test.ts +161 -0
  287. package/os/flow/tests/flow-install.rerun.test.ts +212 -0
  288. package/os/flow/tests/flow-install.test.ts +330 -0
  289. package/os/flow/tests/flow-integrate.rerun.test.ts +92 -0
  290. package/os/flow/tests/flow-integrate.test.ts +229 -0
  291. package/os/flow/tests/flow-open.test.ts +200 -0
  292. package/os/flow/tests/flow-push-publish.test.ts +282 -0
  293. package/os/flow/tests/flow-push.test.ts +160 -0
  294. package/os/flow/tests/flow-stale.test.ts +136 -0
  295. package/os/flow/tests/flow-status.test.ts +93 -0
  296. package/os/flow/tests/flow-version-level.test.ts +116 -0
  297. package/os/flow/tests/flow-version.test.ts +169 -0
  298. package/os/flow/tests/helpers.ts +235 -0
  299. package/os/flow/tests/is-flow-adopted.test.ts +71 -0
  300. package/os/flow/tests/registry.test.ts +150 -0
  301. package/os/flow/tests/repository-line-version.test.ts +100 -0
  302. package/os/flow/tests/scripts.test.ts +97 -0
  303. package/os/flow/tests/state-roots.test.ts +127 -0
  304. package/os/flow/tests/version-files.test.ts +145 -0
  305. package/os/flow/version-files.ts +115 -0
  306. package/os/flow/worktree-path.ts +107 -0
  307. package/os/mission/handlers/archive.test.ts +27 -0
  308. package/os/mission/handlers/archive.ts +46 -6
  309. package/os/program/handlers/seal.ts +1 -1
  310. package/os/program/handlers/validate.ts +1 -1
  311. package/os/program/program.module.ts +2 -1
  312. package/os/program/schemas.ts +51 -34
  313. package/os/program/state.ts +1 -9
  314. package/os/rfc/acceptance.ts +84 -19
  315. package/os/rfc/frontmatter-io.ts +78 -12
  316. package/os/rfc/handlers/implement-stamp-stale.test.ts +22 -0
  317. package/os/rfc/handlers/validate-rules.test.ts +9 -6
  318. package/os/rfc/handlers/validate-rules.ts +12 -10
  319. package/os/rfc/handlers/validate.ts +17 -5
  320. package/os/rfc/index.ts +13 -1
  321. package/os/rfc/probe-batch.ts +329 -0
  322. package/os/rfc/rfc.module.ts +19 -2
  323. package/os/rfc/verification-emit-check.test.ts +22 -0
  324. package/os/rfc/verification-emit-freshness.test.ts +22 -0
  325. package/os/rfc/verification-emit.test.ts +22 -0
  326. package/os/rfc/verification-evidence.ts +21 -16
  327. package/os/rfc/verification-refresh.test.ts +22 -0
  328. package/os/rfc/verification-refresh.ts +20 -18
  329. package/os/rfc/verifier/rfc-1333/imp12-binding.acceptance.test.ts +9 -0
  330. package/os/werkstatt/handlers/werkstatt-lock-recover.ts +22 -5
  331. package/os/werkstatt/handlers/werkstatt-operation-validate.ts +1 -1
  332. package/os/werkstatt/werkstatt.module.ts +2 -85
  333. package/package.json +17 -1
  334. package/profiles/forge-shell.yaml +22 -10
  335. package/profiles/godot-game.yaml +24 -13
  336. package/profiles/knowledge.yaml +19 -0
  337. package/profiles/phaser-game.yaml +25 -13
  338. package/profiles/site-workshop.yaml +27 -10
  339. package/profiles/typescript.yaml +26 -9
  340. package/skills/fo/fo-session-retro/SKILL.md +18 -7
  341. package/skills/fo/fo-step-commit/SKILL.md +2 -1
  342. package/src/config/forge-config.ts +2 -6
  343. package/src/index.ts +8 -0
  344. package/src/onboarding/agents-generate.ts +49 -5
  345. package/src/onboarding/create.ts +101 -9
  346. package/src/onboarding/doctor.ts +2 -51
  347. package/src/onboarding/upgrade.ts +86 -1
  348. package/src/tests/agents-generate-flow.test.ts +132 -0
  349. package/src/tests/create-flow.test.ts +114 -0
  350. package/src/tests/create.test.ts +22 -21
  351. package/src/tests/doctor-autonomy.test.ts +2 -1
  352. package/src/tests/implement-stamp.test.ts +26 -3
  353. package/src/tests/profile-flow-hooks.test.ts +77 -0
  354. package/src/tests/program-schemas.test.ts +66 -6
  355. package/src/tests/program-spec-node.test.ts +1 -5
  356. package/src/tests/rfc-evidence-sync.test.ts +22 -0
  357. package/src/tests/rfc-implement-stamp-governance.test.ts +25 -1
  358. package/src/tests/rfc-verification-verdict-ingest.test.ts +22 -0
  359. package/src/tests/upgrade-flow.test.ts +174 -0
  360. package/src/types.ts +11 -2
  361. package/dist/os/werkstatt/handlers/session-close.d.ts +0 -13
  362. package/dist/os/werkstatt/handlers/session-close.d.ts.map +0 -1
  363. package/dist/os/werkstatt/handlers/session-close.js +0 -56
  364. package/dist/os/werkstatt/handlers/session-close.js.map +0 -1
  365. package/dist/os/werkstatt/handlers/session-engine.d.ts +0 -3
  366. package/dist/os/werkstatt/handlers/session-engine.d.ts.map +0 -1
  367. package/dist/os/werkstatt/handlers/session-engine.js +0 -28
  368. package/dist/os/werkstatt/handlers/session-engine.js.map +0 -1
  369. package/dist/os/werkstatt/handlers/session-open.d.ts +0 -10
  370. package/dist/os/werkstatt/handlers/session-open.d.ts.map +0 -1
  371. package/dist/os/werkstatt/handlers/session-open.js +0 -46
  372. package/dist/os/werkstatt/handlers/session-open.js.map +0 -1
  373. package/dist/os/werkstatt/handlers/session-status.d.ts +0 -9
  374. package/dist/os/werkstatt/handlers/session-status.d.ts.map +0 -1
  375. package/dist/os/werkstatt/handlers/session-status.js +0 -34
  376. package/dist/os/werkstatt/handlers/session-status.js.map +0 -1
  377. package/os/werkstatt/handlers/session-close.ts +0 -82
  378. package/os/werkstatt/handlers/session-engine.ts +0 -34
  379. package/os/werkstatt/handlers/session-open.ts +0 -68
  380. package/os/werkstatt/handlers/session-status.ts +0 -55
@@ -0,0 +1,883 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>flow.install — repository adoption for the fixed branch model
4
+ (RFC-1486). Two phases: planInstall evaluates steps 1–5 preconditions and the
5
+ hook-file diffs without mutating (a refusal exits 1 with nothing changed,
6
+ --dry-run stops here); executeInstall performs steps 3–9 in order, ending
7
+ with one adoption commit on develop under FORGE_FLOW_OP=install and an
8
+ embedded flow.check report.</purpose>
9
+ <non-goals>
10
+ <item>Never refuses anything a later refusal could invalidate — all FLOW-ADOPT refusals are detected in the plan phase.</item>
11
+ <item>Never touches refs other than develop/HEAD, remote refs, or files outside hooks/ and .git/config.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <KEY_DECISIONS>
15
+ <item>develop checked out in a dirty linked worktree → FLOW-ADOPT-04; checked out cleanly → ff-merge inside that worktree (branch -f cannot move a checked-out ref).</item>
16
+ <item>develop checked out in a NON-primary worktree while the primary sits on main → FLOW-ADOPT-08: the adoption commit must land in the primary on develop, and git refuses a double checkout.</item>
17
+ <item>Step 8 passes FORGE_FLOW_OP=install only to the commit child — the closed vocabulary is the guard's own escape hatch (FI-4).</item>
18
+ <item>markerSource resolves at plan time (RFC-1498): a non-network origin warns in the step detail by kind, never by path, and execution reuses the planned value — one git call, no plan/execute drift.</item>
19
+ </KEY_DECISIONS>
20
+ <CHANGE_SUMMARY>
21
+ <item>RFC-1490: pre-merge-commit guard mode + per-mode op vocabulary; amends the wave-1 guard RFC's backmerge escape (AC-11)</item>
22
+ <item>RFC-1490: independent-review pass — lock-held planning, fix-branch verification, spec-shaped data, coverage</item>
23
+ <item>RFC-1491: step 2 — pre-push guard mode, install steps pre-push + markers, FLOW-10</item>
24
+ <item>RFC-1498: step 2 — network-only marker source
25
+
26
+ markerSource accepts only network-shaped origins — http/https/ssh/git schemes or the scp user-at-host form — and returns { source, rejectedOrigin }. A local path or file:// URL falls back to the repository directory basename with rejectedOrigin naming the kind (local-path or file-url), so no machine-local path is ever written into an extract repository marker; embedded credentials are still stripped from network URLs. flow.install resolves the source at plan time, stores it on the plan for the execute phase, and the markers step warns origin rejected (kind) — using the directory name, never printing the path. Tests AC-3 (local path and file:// rejected, basename used, path absent from the step detail) and AC-4 (scp URL kept verbatim, https credentials stripped). Also carries the KEY_DECISIONS compass notes for step 1's stray-branch rule.</item>
27
+ <item>RFC-1498: step 3 — legacy-tags report in flow.install
28
+
29
+ listLegacyTags scans refs/tags in a single for-each-ref pass carrying objecttype and NUL-delimited contents: a tag whose name matches a line grammar (tagPrefix + strict semver) is pre-program when it is lightweight, or annotated but its body lacks the schema forge/release-tag@1 line. flow.install gains an informational legacy-tags plan step listing every such tag as name (kind) — never a refusal, nothing is deleted or rewritten; execution simply marks the step done. Tests AC-5 (a lightweight v1.2.2 and a schema-less annotated lib at 0.1.0 appear with their kinds) and AC-6 (installation proceeds and both tags remain). Compass metadata updated.</item>
30
+ <history>RFC-1486, RFC-1488, RFC-1490</history>
31
+ </CHANGE_SUMMARY>
32
+ */
33
+ import { join } from "node:path";
34
+ import { resolveIo } from "../../../src/utils/io.js";
35
+ import { currentBranch, fileInTree, git, gitCommit, isBare, isUnborn, requireGit, revListHasSubject, statusTracked, topLevel, worktreeList, configGet, branchExists, revListCount, } from "../git.js";
36
+ import { ADOPTION_COMMIT_SUBJECT, GUARD_BEGIN_MARKER, GUARD_END_MARKER, GUARD_FILE, guardFileMatches, mergeManagedBlock, mergeManagedBlockForMode, PRECOMMIT_FILE, PREMERGE_FILE, PREPUSH_FILE, readGuardAsset, renderManagedHook, renderManagedPreCommit, } from "../guard-files.js";
37
+ import { MARKER_FILE, markerContent, markerSource, missingLineMarkers, } from "../markers.js";
38
+ import { detectRepoKind } from "../repo-kind.js";
39
+ import { discoverReleaseLines, readLineVersionFile, } from "../release-lines.js";
40
+ import { listLegacyTags, listLineTags, releaseTagAnnotation, writeReleaseTag } from "../release-tags.js";
41
+ import { compareVersions, parseVersion } from "../semver.js";
42
+ import { collectFlowCheck } from "./flow-check.js";
43
+ function refusalDiagnostic(ruleId, message, fixHint) {
44
+ return { ruleId, severity: "error", message, fixHint };
45
+ }
46
+ /**
47
+ * Plan phase — RFC steps 1–5 preconditions plus the step-6/7 diffs. Never
48
+ * mutates; every FLOW-ADOPT refusal is decided here.
49
+ */
50
+ export async function planInstall(repoRoot, io) {
51
+ const steps = [];
52
+ const refuse = (step, diagnostic) => {
53
+ steps.push({ step, status: "refused", detail: diagnostic.message });
54
+ return {
55
+ repoRoot,
56
+ primary: repoRoot,
57
+ repoKind: "governed",
58
+ steps,
59
+ refusal: diagnostic,
60
+ developAction: { kind: "already-equal" },
61
+ hooksPathAction: "already",
62
+ checkoutAction: "already",
63
+ guardChange: "identical",
64
+ guardCommitted: false,
65
+ preCommitChange: "identical",
66
+ preCommitCommitted: false,
67
+ preMergeChange: "identical",
68
+ preMergeCommitted: false,
69
+ prePushChange: "identical",
70
+ prePushCommitted: false,
71
+ markerPlans: [],
72
+ markerSource: { source: "", rejectedOrigin: null },
73
+ tagPlans: [],
74
+ };
75
+ };
76
+ // 1. detect — only governed repositories are adopted.
77
+ const detection = await detectRepoKind(repoRoot, io);
78
+ if (!detection.ok) {
79
+ return refuse("detect", refusalDiagnostic("FLOW-ADOPT-05", `${detection.detail} — the repository is not adoptable`, "fix forge.generated.yaml to satisfy forge/generated@1 or remove it"));
80
+ }
81
+ if (detection.repoKind.kind !== "governed") {
82
+ return refuse("detect", refusalDiagnostic("FLOW-ADOPT-05", `repository is ${detection.repoKind.kind}, not governed — only repositories with forge.yaml and no generated marker are adopted`, "adopt the fixed branch model in a governed repository"));
83
+ }
84
+ steps.push({ step: "detect", status: "done", detail: "governed repository" });
85
+ if (await isBare(repoRoot, io)) {
86
+ return refuse("detect", refusalDiagnostic("FLOW-ADOPT-05", "the repository is bare — flow.install adopts working repositories with a primary worktree", "run flow.install inside a non-bare clone of the repository"));
87
+ }
88
+ // 2. primary — the primary worktree must have no tracked modifications.
89
+ const worktrees = await worktreeList(repoRoot, io);
90
+ const primary = worktrees[0]?.path ?? repoRoot;
91
+ const dirty = await statusTracked(primary, io);
92
+ if (dirty.length > 0) {
93
+ return refuse("primary", refusalDiagnostic("FLOW-ADOPT-03", `primary worktree has tracked modifications: ${dirty.join(", ")}`, `commit or stash the tracked changes in ${primary}, then re-run`));
94
+ }
95
+ steps.push({ step: "primary", status: "done", detail: `clean: ${primary}` });
96
+ // Adoption state. Once flow.install has run, develop being ahead of main is
97
+ // the model's normal state (the adoption commit and later integrated work
98
+ // live there); the FLOW-ADOPT-01 leveling refusal only guards the
99
+ // not-yet-adopted bootstrap. Two committed-state signals mark a previous
100
+ // adoption: core.hooksPath === "hooks" (only install sets it), or the
101
+ // adoption-commit subject on develop (survives hooksPath drift). Working-
102
+ // tree guard bytes are deliberately NOT a signal — a drifted guard is the
103
+ // state the remedy re-runs install to repair.
104
+ const earlyHooksPath = await configGet(repoRoot, io, "core.hooksPath");
105
+ // 3. develop — resolve its shape relative to main (or an unborn HEAD).
106
+ const developExists = await branchExists(repoRoot, io, "develop");
107
+ const mainExists = await branchExists(repoRoot, io, "main");
108
+ const adoptedBefore = earlyHooksPath === "hooks" ||
109
+ (developExists &&
110
+ (await revListHasSubject(repoRoot, io, "develop", ADOPTION_COMMIT_SUBJECT)));
111
+ let developAction;
112
+ {
113
+ if (!mainExists && !developExists) {
114
+ if (!(await isUnborn(repoRoot, io))) {
115
+ return refuse("develop", refusalDiagnostic("FLOW-ADOPT-06", "repository has commits but no 'main' branch", "rename the default branch to main first"));
116
+ }
117
+ developAction = { kind: "adopt-unborn" };
118
+ steps.push({ step: "develop", status: "planned", detail: "point unborn HEAD at develop" });
119
+ }
120
+ else if (!mainExists) {
121
+ return refuse("develop", refusalDiagnostic("FLOW-ADOPT-06", "repository has commits but no 'main' branch", "rename the default branch to main first"));
122
+ }
123
+ else if (!developExists) {
124
+ developAction = { kind: "create-at-main" };
125
+ steps.push({ step: "develop", status: "planned", detail: "create develop at main" });
126
+ }
127
+ else {
128
+ const devAhead = await revListCount(repoRoot, io, "main..develop");
129
+ if (devAhead > 0) {
130
+ if (adoptedBefore) {
131
+ developAction = { kind: "already-equal" };
132
+ steps.push({
133
+ step: "develop",
134
+ status: "planned",
135
+ detail: `already adopted — develop is ${devAhead} commit(s) ahead of main (normal state)`,
136
+ });
137
+ }
138
+ else {
139
+ const mainAhead = await revListCount(repoRoot, io, "develop..main");
140
+ return refuse("develop", refusalDiagnostic("FLOW-ADOPT-01", `develop has ${devAhead} commit(s) that are not in main (main is ${mainAhead} ahead) — the fixed model needs develop to fast-forward to main, not to diverge`, "rebase or merge develop's commits through an auto branch first"));
141
+ }
142
+ }
143
+ else {
144
+ const mainAhead = await revListCount(repoRoot, io, "develop..main");
145
+ if (mainAhead === 0) {
146
+ developAction = { kind: "already-equal" };
147
+ steps.push({ step: "develop", status: "planned", detail: "develop already equals main" });
148
+ }
149
+ else {
150
+ const devWorktree = worktrees.find((w) => w.branch === "develop");
151
+ if (devWorktree) {
152
+ const devDirty = await statusTracked(devWorktree.path, io);
153
+ if (devDirty.length > 0) {
154
+ return refuse("develop", refusalDiagnostic("FLOW-ADOPT-04", `develop is checked out in worktree ${devWorktree.path} which has tracked modifications: ${devDirty.join(", ")}`, "commit or stash that worktree's tracked changes, then re-run"));
155
+ }
156
+ developAction = { kind: "merge-ff", worktree: devWorktree.path, count: mainAhead };
157
+ steps.push({
158
+ step: "develop",
159
+ status: "planned",
160
+ detail: `fast-forward develop ${mainAhead} commit(s) to main inside ${devWorktree.path}`,
161
+ });
162
+ }
163
+ else {
164
+ developAction = { kind: "branch-f", count: mainAhead };
165
+ steps.push({
166
+ step: "develop",
167
+ status: "planned",
168
+ detail: `fast-forward develop ${mainAhead} commit(s) to main`,
169
+ });
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ if (developAction === undefined) {
176
+ throw new Error("flow.install: develop shape unresolved — internal error");
177
+ }
178
+ // 4. hooksPath — shared repository config, never --worktree.
179
+ const hooksPath = earlyHooksPath;
180
+ let hooksPathAction;
181
+ if (hooksPath === null) {
182
+ hooksPathAction = "set";
183
+ steps.push({ step: "hooksPath", status: "planned", detail: "set core.hooksPath to 'hooks'" });
184
+ }
185
+ else if (hooksPath === "hooks") {
186
+ hooksPathAction = "already";
187
+ steps.push({ step: "hooksPath", status: "planned", detail: "core.hooksPath already 'hooks'" });
188
+ }
189
+ else {
190
+ return refuse("hooksPath", refusalDiagnostic("FLOW-ADOPT-02", `core.hooksPath is '${hooksPath}', expected 'hooks' or unset`, `repoint core.hooksPath to 'hooks' and move existing hooks under hooks/`));
191
+ }
192
+ // 5. checkout — the primary must be on main or develop.
193
+ const primaryBranch = await currentBranch(primary, io);
194
+ let checkoutAction;
195
+ if (primaryBranch === "develop" || developAction.kind === "adopt-unborn") {
196
+ checkoutAction = "already";
197
+ steps.push({
198
+ step: "checkout",
199
+ status: "planned",
200
+ detail: developAction.kind === "adopt-unborn"
201
+ ? "HEAD will already point at unborn develop"
202
+ : "primary already on develop",
203
+ });
204
+ }
205
+ else if (primaryBranch === "main") {
206
+ const devElsewhere = worktrees.find((w) => w.branch === "develop" && w.path !== primary);
207
+ if (devElsewhere) {
208
+ return refuse("checkout", refusalDiagnostic("FLOW-ADOPT-08", `primary is on 'main' but develop is already checked out in worktree ${devElsewhere.path} — git cannot check it out twice`, `run flow.install from ${devElsewhere.path}, or detach that worktree first`));
209
+ }
210
+ checkoutAction = "switch";
211
+ steps.push({ step: "checkout", status: "planned", detail: "switch primary to develop" });
212
+ }
213
+ else {
214
+ return refuse("checkout", refusalDiagnostic("FLOW-ADOPT-08", `primary worktree is on branch '${primaryBranch ?? "(detached)"}', expected 'main' or 'develop'`, `switch the primary worktree to main first: git -C ${primary} switch main`));
215
+ }
216
+ // Steps 6/7 diffs — computed now so --dry-run reports real intent. The
217
+ // parent ref the adoption commit lands on: post-leveling content is main's
218
+ // for create/ff actions; an already-equal develop is never leveled, so the
219
+ // committed-state check must look there (RFC-1487 worktrees check out
220
+ // committed content — byte-exact-but-uncommitted hook files still need the
221
+ // adoption commit).
222
+ const hookBaseRef = developAction.kind === "adopt-unborn"
223
+ ? null
224
+ : developAction.kind === "already-equal" && developExists
225
+ ? "develop"
226
+ : "main";
227
+ const guardIdentical = await guardFileMatches(async () => (await io.exists(join(primary, GUARD_FILE)))
228
+ ? io.readFile(join(primary, GUARD_FILE))
229
+ : null);
230
+ const guardCommitted = hookBaseRef !== null && (await fileInTree(repoRoot, io, hookBaseRef, GUARD_FILE));
231
+ const guardChange = guardIdentical && guardCommitted ? "identical" : "write";
232
+ steps.push({
233
+ step: "guard",
234
+ status: "planned",
235
+ detail: guardIdentical
236
+ ? guardCommitted
237
+ ? "hooks/flow-guard.sh already matches the asset"
238
+ : "hooks/flow-guard.sh matches the asset but is uncommitted — land it on develop"
239
+ : "install the fixed branch model guard as hooks/flow-guard.sh (0755)",
240
+ });
241
+ const preCommitPath = join(primary, PRECOMMIT_FILE);
242
+ const preCommitExisting = (await io.exists(preCommitPath))
243
+ ? await io.readFile(preCommitPath)
244
+ : null;
245
+ const preCommitCommitted = hookBaseRef !== null && (await fileInTree(repoRoot, io, hookBaseRef, PRECOMMIT_FILE));
246
+ let preCommitChange;
247
+ if (preCommitExisting === null) {
248
+ preCommitChange = "create";
249
+ }
250
+ else if (mergeManagedBlock(preCommitExisting) === null) {
251
+ preCommitChange = "identical";
252
+ }
253
+ else {
254
+ // Marker span present but block differs → merge replaces between the
255
+ // markers; absent/dangling markers → insert after the shebang.
256
+ const beginIdx = preCommitExisting.indexOf(GUARD_BEGIN_MARKER);
257
+ const endIdx = preCommitExisting.indexOf(GUARD_END_MARKER);
258
+ preCommitChange = beginIdx !== -1 && endIdx !== -1 && beginIdx < endIdx ? "replace" : "insert";
259
+ }
260
+ steps.push({
261
+ step: "pre-commit",
262
+ status: "planned",
263
+ detail: preCommitChange === "identical"
264
+ ? preCommitCommitted
265
+ ? "hooks/pre-commit already carries the managed block"
266
+ : "hooks/pre-commit carries the managed block but is uncommitted — land it on develop"
267
+ : `${preCommitChange} managed block in hooks/pre-commit`,
268
+ });
269
+ const preMergePath = join(primary, PREMERGE_FILE);
270
+ const preMergeExisting = (await io.exists(preMergePath))
271
+ ? await io.readFile(preMergePath)
272
+ : null;
273
+ const preMergeCommitted = hookBaseRef !== null && (await fileInTree(repoRoot, io, hookBaseRef, PREMERGE_FILE));
274
+ let preMergeChange;
275
+ if (preMergeExisting === null) {
276
+ preMergeChange = "create";
277
+ }
278
+ else if (mergeManagedBlockForMode(preMergeExisting, "pre-merge-commit") === null) {
279
+ preMergeChange = "identical";
280
+ }
281
+ else {
282
+ const beginIdx = preMergeExisting.indexOf(GUARD_BEGIN_MARKER);
283
+ const endIdx = preMergeExisting.indexOf(GUARD_END_MARKER);
284
+ preMergeChange = beginIdx !== -1 && endIdx !== -1 && beginIdx < endIdx ? "replace" : "insert";
285
+ }
286
+ steps.push({
287
+ step: "pre-merge-commit",
288
+ status: "planned",
289
+ detail: preMergeChange === "identical"
290
+ ? preMergeCommitted
291
+ ? "hooks/pre-merge-commit already carries the managed block"
292
+ : "hooks/pre-merge-commit carries the managed block but is uncommitted — land it on develop"
293
+ : `${preMergeChange} managed block in hooks/pre-merge-commit`,
294
+ });
295
+ const prePushPath = join(primary, PREPUSH_FILE);
296
+ const prePushExisting = (await io.exists(prePushPath))
297
+ ? await io.readFile(prePushPath)
298
+ : null;
299
+ const prePushCommitted = hookBaseRef !== null && (await fileInTree(repoRoot, io, hookBaseRef, PREPUSH_FILE));
300
+ let prePushChange;
301
+ if (prePushExisting === null) {
302
+ prePushChange = "create";
303
+ }
304
+ else if (mergeManagedBlockForMode(prePushExisting, "pre-push") === null) {
305
+ prePushChange = "identical";
306
+ }
307
+ else {
308
+ const beginIdx = prePushExisting.indexOf(GUARD_BEGIN_MARKER);
309
+ const endIdx = prePushExisting.indexOf(GUARD_END_MARKER);
310
+ prePushChange = beginIdx !== -1 && endIdx !== -1 && beginIdx < endIdx ? "replace" : "insert";
311
+ }
312
+ steps.push({
313
+ step: "pre-push",
314
+ status: "planned",
315
+ detail: prePushChange === "identical"
316
+ ? prePushCommitted
317
+ ? "hooks/pre-push already carries the managed block"
318
+ : "hooks/pre-push carries the managed block but is uncommitted — land it on develop"
319
+ : `${prePushChange} managed block in hooks/pre-push`,
320
+ });
321
+ // markers (RFC-1491) — every package line gets a forge.generated.yaml the
322
+ // extract copies into its repository; the repo line never carries one.
323
+ // RFC-1498: the source is resolved at plan time so the step can warn when
324
+ // origin is not a network URL — the warning names the kind, never the path.
325
+ const marker = await markerSource(repoRoot, io);
326
+ const { markers: markerPlans } = await missingLineMarkers(repoRoot, io);
327
+ steps.push({
328
+ step: "markers",
329
+ status: "planned",
330
+ detail: (markerPlans.length > 0
331
+ ? `marker(s): ${markerPlans.map((m) => join(m.dir, MARKER_FILE)).join(", ")}`
332
+ : "every package line already carries a valid marker") +
333
+ (marker.rejectedOrigin !== null
334
+ ? ` — origin rejected (${marker.rejectedOrigin}), using the directory name`
335
+ : ""),
336
+ });
337
+ const commitNeeded = guardChange === "write" ||
338
+ !guardCommitted ||
339
+ preCommitChange !== "identical" ||
340
+ !preCommitCommitted ||
341
+ preMergeChange !== "identical" ||
342
+ !preMergeCommitted ||
343
+ prePushChange !== "identical" ||
344
+ !prePushCommitted ||
345
+ markerPlans.length > 0;
346
+ steps.push({
347
+ step: "commit",
348
+ status: "planned",
349
+ detail: commitNeeded
350
+ ? `adoption commit '${ADOPTION_COMMIT_SUBJECT}' on develop`
351
+ : "hook files unchanged — no adoption commit",
352
+ });
353
+ // 8.5 tags (RFC-1488) — baseline every line whose version file V outruns
354
+ // its last reachable annotated tag T. V == T → skipped; V < T → refuse
355
+ // FLOW-ADOPT-07 (never tag backwards); a baseline commit that is not an
356
+ // ancestor of main → FLOW-ADOPT-07. Evaluated in the plan phase so a
357
+ // refusal leaves no tag behind.
358
+ const tagPlans = [];
359
+ let legacyTags = [];
360
+ if (!mainExists) {
361
+ steps.push({
362
+ step: "tags",
363
+ status: "planned",
364
+ detail: "no main branch — baseline tags deferred until the repository has commits",
365
+ });
366
+ }
367
+ else {
368
+ const { lines, diagnostics: discoveryDiagnostics } = await discoverReleaseLines(repoRoot, io);
369
+ const collision = discoveryDiagnostics.find((d) => d.severity === "error");
370
+ if (collision) {
371
+ return refuse("tags", collision);
372
+ }
373
+ for (const line of lines) {
374
+ const versionText = await readLineVersionFile(repoRoot, line, io);
375
+ if (versionText === null)
376
+ continue; // no version file value — nothing to tag
377
+ const V = parseVersion(versionText);
378
+ if (V === null) {
379
+ return refuse("tags", refusalDiagnostic("FLOW-ADOPT-07", `release line '${line.id}' carries an unparsable version '${versionText}' in ${line.versionFile} — release tags are strict X.Y.Z`, `fix ${line.versionFile} to a strict X.Y.Z version`));
380
+ }
381
+ const tags = await listLineTags(repoRoot, line, io);
382
+ const T = tags.lastTag;
383
+ const cmp = T === null ? 1 : compareVersions(V, T.version);
384
+ if (cmp === 0)
385
+ continue; // tag already matches the version file
386
+ if (cmp < 0) {
387
+ return refuse("tags", refusalDiagnostic("FLOW-ADOPT-07", `release line '${line.id}' version file says ${versionText} but its last tag is ${T.name} — never tag backwards`, `raise ${line.versionFile} above ${T.name}, or fix the wrong tag manually`));
388
+ }
389
+ const commit = await findVersionCommit(repoRoot, line.versionFile, versionText, io);
390
+ if (commit === null) {
391
+ return refuse("tags", refusalDiagnostic("FLOW-ADOPT-07", `release line '${line.id}': could not find the commit that introduced version ${versionText} in ${line.versionFile}`, `commit the version change first, or create the baseline tag ${line.tagPrefix}${versionText} manually`));
392
+ }
393
+ const ancestor = await git(repoRoot, io, ["merge-base", "--is-ancestor", commit, "main"]);
394
+ if (ancestor.exitCode !== 0) {
395
+ return refuse("tags", refusalDiagnostic("FLOW-ADOPT-07", `release line '${line.id}': commit ${commit.slice(0, 9)} introducing version ${versionText} is not an ancestor of main`, "land the version change on main first"));
396
+ }
397
+ tagPlans.push({
398
+ line: line.id,
399
+ tag: `${line.tagPrefix}${versionText}`,
400
+ version: versionText,
401
+ commit,
402
+ previous: T?.name ?? null,
403
+ });
404
+ }
405
+ steps.push({
406
+ step: "tags",
407
+ status: "planned",
408
+ detail: tagPlans.length > 0
409
+ ? `baseline tag(s): ${tagPlans.map((t) => `${t.tag}@${t.commit.slice(0, 9)}`).join(", ")}`
410
+ : "no baseline tags needed",
411
+ });
412
+ legacyTags = await listLegacyTags(repoRoot, lines, io);
413
+ }
414
+ // RFC-1498 — pre-program tags stay, but the operator sees them: every
415
+ // tag matching a line grammar that the release-line reader ignores
416
+ // (lightweight) or accepts without the forge/release-tag@1 schema.
417
+ // Informational — never a refusal.
418
+ steps.push({
419
+ step: "legacy-tags",
420
+ status: "planned",
421
+ detail: legacyTags.length > 0
422
+ ? `pre-program tag(s): ${legacyTags.map((t) => `${t.name} (${t.kind})`).join(", ")}`
423
+ : "none",
424
+ });
425
+ steps.push({ step: "report", status: "planned", detail: "embed flow.check diagnostics" });
426
+ return {
427
+ repoRoot,
428
+ primary,
429
+ repoKind: "governed",
430
+ steps,
431
+ refusal: null,
432
+ developAction,
433
+ hooksPathAction,
434
+ checkoutAction,
435
+ guardChange,
436
+ guardCommitted,
437
+ preCommitChange,
438
+ preCommitCommitted,
439
+ preMergeChange,
440
+ preMergeCommitted,
441
+ prePushChange,
442
+ prePushCommitted,
443
+ markerPlans,
444
+ markerSource: marker,
445
+ tagPlans,
446
+ };
447
+ }
448
+ /**
449
+ * The commit that introduced `version` in `versionFile` — pickaxe on the
450
+ * canonical `"version": "X.Y.Z"` formatting first, then a `git log -p` scan
451
+ * for the newest commit adding a normalized-matching line (audit G2: files
452
+ * formatted without the space after the colon defeat -S).
453
+ */
454
+ async function findVersionCommit(repoRoot, versionFile, version, io) {
455
+ const needle = `"version": "${version}"`;
456
+ const pick = await git(repoRoot, io, [
457
+ "log",
458
+ "-1",
459
+ "--format=%H",
460
+ `-S${needle}`,
461
+ "--",
462
+ versionFile,
463
+ ]);
464
+ if (pick.exitCode === 0 && pick.stdout.trim().length > 0) {
465
+ return pick.stdout.trim();
466
+ }
467
+ const log = await git(repoRoot, io, ["log", "-p", "--format=%H", "--", versionFile]);
468
+ if (log.exitCode !== 0)
469
+ return null;
470
+ const normalizedNeedle = needle.replace(/\s+/g, "");
471
+ let commit = null;
472
+ for (const raw of log.stdout.split("\n")) {
473
+ const line = raw.trimEnd();
474
+ if (/^[0-9a-f]{40}$/.test(line)) {
475
+ commit = line;
476
+ continue;
477
+ }
478
+ if (commit !== null &&
479
+ line.startsWith("+") &&
480
+ !line.startsWith("+++") &&
481
+ line.slice(1).replace(/\s+/g, "").includes(normalizedNeedle)) {
482
+ return commit;
483
+ }
484
+ }
485
+ return null;
486
+ }
487
+ function setStep(plan, step, status, detail) {
488
+ const entry = plan.steps.find((s) => s.step === step);
489
+ if (entry) {
490
+ entry.status = status;
491
+ if (detail !== undefined)
492
+ entry.detail = detail;
493
+ }
494
+ }
495
+ /**
496
+ * Execute phase — steps 3–9 in order on an approved plan. A failing step
497
+ * reports status "failed" into steps[] and every still-planned later step is
498
+ * marked "skipped" — the step trail stays complete for the report (DNA-106).
499
+ */
500
+ export async function executeInstall(plan, io) {
501
+ const { repoRoot, primary } = plan;
502
+ const STEP_ORDER = [
503
+ "develop",
504
+ "hooksPath",
505
+ "checkout",
506
+ "guard",
507
+ "pre-commit",
508
+ "pre-merge-commit",
509
+ "pre-push",
510
+ "markers",
511
+ "commit",
512
+ "tags",
513
+ "legacy-tags",
514
+ "report",
515
+ ];
516
+ const failStep = (step, detail) => {
517
+ setStep(plan, step, "failed", detail);
518
+ const idx = STEP_ORDER.indexOf(step);
519
+ for (const s of plan.steps) {
520
+ if (STEP_ORDER.indexOf(s.step) > idx && s.status === "planned") {
521
+ setStep(plan, s.step, "skipped");
522
+ }
523
+ }
524
+ return { check: null, checkDiagnostics: [] };
525
+ };
526
+ // 3. develop
527
+ switch (plan.developAction.kind) {
528
+ case "create-at-main": {
529
+ const r = await git(repoRoot, io, ["branch", "develop", "main"]);
530
+ if (r.exitCode !== 0) {
531
+ return failStep("develop", `git branch develop main failed: ${r.stderr.trim()}`);
532
+ }
533
+ setStep(plan, "develop", "done", "created develop at main");
534
+ break;
535
+ }
536
+ case "branch-f": {
537
+ const r = await git(repoRoot, io, ["branch", "-f", "develop", "main"]);
538
+ if (r.exitCode !== 0) {
539
+ return failStep("develop", `git branch -f develop main failed: ${r.stderr.trim()}`);
540
+ }
541
+ setStep(plan, "develop", "done", `fast-forwarded develop ${plan.developAction.count} commit(s) to main`);
542
+ break;
543
+ }
544
+ case "merge-ff": {
545
+ const r = await git(plan.developAction.worktree, io, ["merge", "--ff-only", "main"]);
546
+ if (r.exitCode !== 0) {
547
+ return failStep("develop", `git -C ${plan.developAction.worktree} merge --ff-only main failed: ${r.stderr.trim()}`);
548
+ }
549
+ setStep(plan, "develop", "done", `fast-forwarded develop ${plan.developAction.count} commit(s) to main inside ${plan.developAction.worktree}`);
550
+ break;
551
+ }
552
+ case "adopt-unborn": {
553
+ const r = await git(repoRoot, io, ["symbolic-ref", "HEAD", "refs/heads/develop"]);
554
+ if (r.exitCode !== 0) {
555
+ return failStep("develop", `git symbolic-ref HEAD refs/heads/develop failed: ${r.stderr.trim()}`);
556
+ }
557
+ setStep(plan, "develop", "done", "pointed unborn HEAD at develop");
558
+ break;
559
+ }
560
+ case "already-equal": {
561
+ const planned = plan.steps.find((s) => s.step === "develop");
562
+ setStep(plan, "develop", "skipped", planned?.detail ?? "develop already equals main");
563
+ break;
564
+ }
565
+ }
566
+ // 4. hooksPath — shared config only.
567
+ if (plan.hooksPathAction === "set") {
568
+ const r = await git(repoRoot, io, ["config", "core.hooksPath", "hooks"]);
569
+ if (r.exitCode !== 0) {
570
+ return failStep("hooksPath", `git config core.hooksPath hooks failed: ${r.stderr.trim()}`);
571
+ }
572
+ setStep(plan, "hooksPath", "done", "core.hooksPath set to 'hooks'");
573
+ }
574
+ else {
575
+ setStep(plan, "hooksPath", "skipped", "core.hooksPath already 'hooks'");
576
+ }
577
+ // 5. checkout
578
+ if (plan.checkoutAction === "switch") {
579
+ const r = await git(primary, io, ["switch", "develop"]);
580
+ if (r.exitCode !== 0) {
581
+ return failStep("checkout", `git -C ${primary} switch develop failed: ${r.stderr.trim()}`);
582
+ }
583
+ setStep(plan, "checkout", "done", "primary switched to develop");
584
+ }
585
+ else {
586
+ setStep(plan, "checkout", "skipped");
587
+ }
588
+ // 6. guard — byte copy of the shipped asset, mode 0755. An already
589
+ // byte-exact but uncommitted file still needs staging for the adoption
590
+ // commit (worktrees check out committed content).
591
+ let hooksNeedCommit = false;
592
+ const guardPath = join(primary, GUARD_FILE);
593
+ if (plan.guardChange === "write") {
594
+ try {
595
+ await io.mkdir(join(primary, "hooks"));
596
+ await io.writeFile(guardPath, readGuardAsset());
597
+ }
598
+ catch (err) {
599
+ return failStep("guard", `writing ${GUARD_FILE} failed: ${err.message}`);
600
+ }
601
+ const chmod = await io.exec("chmod", ["0755", guardPath]);
602
+ if (chmod.exitCode !== 0) {
603
+ return failStep("guard", `chmod 0755 ${GUARD_FILE} failed: ${chmod.stderr.trim()}`);
604
+ }
605
+ hooksNeedCommit = true;
606
+ setStep(plan, "guard", "done", "wrote hooks/flow-guard.sh (0755)");
607
+ }
608
+ else if (!plan.guardCommitted) {
609
+ hooksNeedCommit = true;
610
+ setStep(plan, "guard", "done", "hooks/flow-guard.sh already byte-exact — staged for commit");
611
+ }
612
+ else {
613
+ setStep(plan, "guard", "skipped", "hooks/flow-guard.sh already matches the asset");
614
+ }
615
+ // 7. pre-commit — create, insert after the shebang, or replace the block.
616
+ const preCommitPath = join(primary, PRECOMMIT_FILE);
617
+ if (plan.preCommitChange === "identical") {
618
+ if (!plan.preCommitCommitted) {
619
+ hooksNeedCommit = true;
620
+ setStep(plan, "pre-commit", "done", "managed block already correct — staged for commit");
621
+ }
622
+ else {
623
+ setStep(plan, "pre-commit", "skipped", "managed block already present");
624
+ }
625
+ }
626
+ else {
627
+ const existing = (await io.exists(preCommitPath)) ? await io.readFile(preCommitPath) : null;
628
+ const next = existing === null ? renderManagedPreCommit() : mergeManagedBlock(existing);
629
+ if (next === null) {
630
+ if (!plan.preCommitCommitted) {
631
+ hooksNeedCommit = true;
632
+ setStep(plan, "pre-commit", "done", "managed block already correct — staged for commit");
633
+ }
634
+ else {
635
+ setStep(plan, "pre-commit", "skipped", "managed block already present");
636
+ }
637
+ }
638
+ else {
639
+ try {
640
+ await io.mkdir(join(primary, "hooks"));
641
+ await io.writeFile(preCommitPath, next.endsWith("\n") ? next : `${next}\n`);
642
+ }
643
+ catch (err) {
644
+ return failStep("pre-commit", `writing ${PRECOMMIT_FILE} failed: ${err.message}`);
645
+ }
646
+ const chmod = await io.exec("chmod", ["0755", preCommitPath]);
647
+ if (chmod.exitCode !== 0) {
648
+ return failStep("pre-commit", `chmod 0755 ${PRECOMMIT_FILE} failed: ${chmod.stderr.trim()}`);
649
+ }
650
+ hooksNeedCommit = true;
651
+ setStep(plan, "pre-commit", "done", `${plan.preCommitChange}d managed block in hooks/pre-commit`);
652
+ }
653
+ }
654
+ // 7.5 pre-merge-commit — same managed-block mechanics, pre-merge-commit mode.
655
+ const preMergePath = join(primary, PREMERGE_FILE);
656
+ if (plan.preMergeChange === "identical") {
657
+ if (!plan.preMergeCommitted) {
658
+ hooksNeedCommit = true;
659
+ setStep(plan, "pre-merge-commit", "done", "managed block already correct — staged for commit");
660
+ }
661
+ else {
662
+ setStep(plan, "pre-merge-commit", "skipped", "managed block already present");
663
+ }
664
+ }
665
+ else {
666
+ const existing = (await io.exists(preMergePath)) ? await io.readFile(preMergePath) : null;
667
+ const next = existing === null
668
+ ? renderManagedHook("pre-merge-commit")
669
+ : mergeManagedBlockForMode(existing, "pre-merge-commit");
670
+ if (next === null) {
671
+ if (!plan.preMergeCommitted) {
672
+ hooksNeedCommit = true;
673
+ setStep(plan, "pre-merge-commit", "done", "managed block already correct — staged for commit");
674
+ }
675
+ else {
676
+ setStep(plan, "pre-merge-commit", "skipped", "managed block already present");
677
+ }
678
+ }
679
+ else {
680
+ try {
681
+ await io.mkdir(join(primary, "hooks"));
682
+ await io.writeFile(preMergePath, next.endsWith("\n") ? next : `${next}\n`);
683
+ }
684
+ catch (err) {
685
+ return failStep("pre-merge-commit", `writing ${PREMERGE_FILE} failed: ${err.message}`);
686
+ }
687
+ const chmod = await io.exec("chmod", ["0755", preMergePath]);
688
+ if (chmod.exitCode !== 0) {
689
+ return failStep("pre-merge-commit", `chmod 0755 ${PREMERGE_FILE} failed: ${chmod.stderr.trim()}`);
690
+ }
691
+ hooksNeedCommit = true;
692
+ setStep(plan, "pre-merge-commit", "done", `${plan.preMergeChange}d managed block in hooks/pre-merge-commit`);
693
+ }
694
+ }
695
+ // 7.7 pre-push — the RFC-1491 outbound mode.
696
+ const prePushPath = join(primary, PREPUSH_FILE);
697
+ if (plan.prePushChange === "identical") {
698
+ if (!plan.prePushCommitted) {
699
+ hooksNeedCommit = true;
700
+ setStep(plan, "pre-push", "done", "managed block already correct — staged for commit");
701
+ }
702
+ else {
703
+ setStep(plan, "pre-push", "skipped", "managed block already present");
704
+ }
705
+ }
706
+ else {
707
+ const existing = (await io.exists(prePushPath)) ? await io.readFile(prePushPath) : null;
708
+ const next = existing === null
709
+ ? renderManagedHook("pre-push")
710
+ : mergeManagedBlockForMode(existing, "pre-push");
711
+ if (next === null) {
712
+ if (!plan.prePushCommitted) {
713
+ hooksNeedCommit = true;
714
+ setStep(plan, "pre-push", "done", "managed block already correct — staged for commit");
715
+ }
716
+ else {
717
+ setStep(plan, "pre-push", "skipped", "managed block already present");
718
+ }
719
+ }
720
+ else {
721
+ try {
722
+ await io.mkdir(join(primary, "hooks"));
723
+ await io.writeFile(prePushPath, next.endsWith("\n") ? next : `${next}\n`);
724
+ }
725
+ catch (err) {
726
+ return failStep("pre-push", `writing ${PREPUSH_FILE} failed: ${err.message}`);
727
+ }
728
+ const chmod = await io.exec("chmod", ["0755", prePushPath]);
729
+ if (chmod.exitCode !== 0) {
730
+ return failStep("pre-push", `chmod 0755 ${PREPUSH_FILE} failed: ${chmod.stderr.trim()}`);
731
+ }
732
+ hooksNeedCommit = true;
733
+ setStep(plan, "pre-push", "done", `${plan.prePushChange}d managed block in hooks/pre-push`);
734
+ }
735
+ }
736
+ // 7.8 markers (RFC-1491) — forge.generated.yaml per package line so every
737
+ // extract repository carries the generated marker.
738
+ if (plan.markerPlans.length === 0) {
739
+ setStep(plan, "markers", "skipped", "every package line already carries a valid marker");
740
+ }
741
+ else {
742
+ const { source } = plan.markerSource;
743
+ for (const m of plan.markerPlans) {
744
+ try {
745
+ await io.mkdir(join(primary, m.dir));
746
+ await io.writeFile(join(primary, m.dir, MARKER_FILE), markerContent(`${source}#${m.dir}`));
747
+ }
748
+ catch (err) {
749
+ return failStep("markers", `writing ${m.dir}/${MARKER_FILE} failed: ${err.message}`);
750
+ }
751
+ }
752
+ hooksNeedCommit = true;
753
+ setStep(plan, "markers", "done", `wrote ${plan.markerPlans.length} marker(s)`);
754
+ }
755
+ // 8. adoption commit — under FORGE_FLOW_OP=install, nothing else staged.
756
+ if (hooksNeedCommit) {
757
+ const markerPaths = plan.markerPlans.map((m) => join(m.dir, MARKER_FILE));
758
+ const add = await git(primary, io, [
759
+ "add",
760
+ GUARD_FILE,
761
+ PRECOMMIT_FILE,
762
+ PREMERGE_FILE,
763
+ PREPUSH_FILE,
764
+ ...markerPaths,
765
+ ]);
766
+ if (add.exitCode !== 0) {
767
+ return failStep("commit", `git add failed: ${add.stderr.trim()}`);
768
+ }
769
+ const commit = await gitCommit(primary, io, ["commit", "-m", ADOPTION_COMMIT_SUBJECT], "install", { FORGE_FLOW_OP: "install" });
770
+ if (commit.exitCode !== 0) {
771
+ return failStep("commit", `git commit failed: ${commit.stderr.trim()}`);
772
+ }
773
+ setStep(plan, "commit", "done", `committed '${ADOPTION_COMMIT_SUBJECT}' on develop`);
774
+ }
775
+ else {
776
+ setStep(plan, "commit", "skipped", "hook files unchanged — nothing to commit");
777
+ }
778
+ // 8.5 tags (RFC-1488) — the baselines the plan phase approved. Tags are
779
+ // local objects only; pushing them is the wave-2 outbound command.
780
+ if (plan.tagPlans.length > 0) {
781
+ for (const tagPlan of plan.tagPlans) {
782
+ const r = await writeReleaseTag(repoRoot, io, {
783
+ name: tagPlan.tag,
784
+ target: tagPlan.commit,
785
+ annotation: releaseTagAnnotation({
786
+ tag: tagPlan.tag,
787
+ line: tagPlan.line,
788
+ version: tagPlan.version,
789
+ level: "baseline",
790
+ previous: tagPlan.previous,
791
+ rfcs: [],
792
+ fingerprints: {},
793
+ }),
794
+ });
795
+ if (r.exitCode !== 0) {
796
+ return failStep("tags", `git tag -a ${tagPlan.tag} failed: ${r.stderr.trim()}`);
797
+ }
798
+ }
799
+ setStep(plan, "tags", "done", `created baseline tag(s): ${plan.tagPlans.map((t) => `${t.tag}@${t.commit.slice(0, 9)}`).join(", ")}`);
800
+ }
801
+ else {
802
+ setStep(plan, "tags", "skipped", "no baseline tags needed");
803
+ }
804
+ // legacy-tags (RFC-1498) — informational only: the plan phase already
805
+ // listed them; execution changes nothing about existing tags.
806
+ {
807
+ const planned = plan.steps.find((s) => s.step === "legacy-tags");
808
+ setStep(plan, "legacy-tags", "done", planned?.detail ?? "none");
809
+ }
810
+ // 9. report — the flow.check rule set, embedded.
811
+ try {
812
+ const outcome = await collectFlowCheck(repoRoot, io);
813
+ setStep(plan, "report", "done", `${outcome.diagnostics.length} diagnostic(s) embedded`);
814
+ return { check: outcome.data, checkDiagnostics: outcome.diagnostics };
815
+ }
816
+ catch (err) {
817
+ return failStep("report", `flow.check failed: ${err.message}`);
818
+ }
819
+ }
820
+ export async function runFlowInstall(input, context) {
821
+ const { workspaceRoot, logger, outputFormat } = context;
822
+ const io = resolveIo(context.io);
823
+ const dryRun = context.dryRun || input.flags?.["dry-run"] === true;
824
+ await requireGit(io);
825
+ const repoRoot = await topLevel(workspaceRoot, io);
826
+ if (repoRoot === null) {
827
+ throw new Error("flow.install must run inside a git repository");
828
+ }
829
+ const plan = await planInstall(repoRoot, io);
830
+ if (plan.refusal) {
831
+ if (outputFormat === "pretty") {
832
+ logger.error(`flow.install refused: ${plan.refusal.message}`);
833
+ }
834
+ return {
835
+ data: {
836
+ repoKind: "governed",
837
+ dryRun,
838
+ steps: plan.steps,
839
+ },
840
+ exitCode: 1,
841
+ summary: `[flow.install] refused: ${plan.refusal.ruleId} ${plan.refusal.message}`,
842
+ };
843
+ }
844
+ if (dryRun) {
845
+ if (outputFormat === "pretty") {
846
+ logger.section("flow.install (dry run)");
847
+ for (const s of plan.steps) {
848
+ logger.info(` ${s.step}: ${s.status}${s.detail ? ` — ${s.detail}` : ""}`);
849
+ }
850
+ }
851
+ return {
852
+ data: { repoKind: plan.repoKind, dryRun: true, steps: plan.steps },
853
+ exitCode: 0,
854
+ summary: `[flow.install] dry run — ${plan.steps.length} step(s) planned, nothing changed`,
855
+ };
856
+ }
857
+ const { check, checkDiagnostics } = await executeInstall(plan, io);
858
+ const failedStep = plan.steps.find((s) => s.status === "failed");
859
+ if (outputFormat === "pretty") {
860
+ logger.section("flow.install");
861
+ for (const s of plan.steps) {
862
+ const line = ` ${s.step}: ${s.status}${s.detail ? ` — ${s.detail}` : ""}`;
863
+ if (s.status === "failed")
864
+ logger.error(line);
865
+ else
866
+ logger.info(line);
867
+ }
868
+ }
869
+ return {
870
+ data: {
871
+ repoKind: plan.repoKind,
872
+ dryRun: false,
873
+ steps: plan.steps,
874
+ check,
875
+ checkDiagnostics,
876
+ },
877
+ exitCode: failedStep ? 1 : 0,
878
+ summary: failedStep
879
+ ? `[flow.install] failed at ${failedStep.step}: ${failedStep.detail}`
880
+ : `[flow.install] adopted — ${plan.steps.filter((s) => s.status === "done").length} step(s) done, ${checkDiagnostics.length} check diagnostic(s)`,
881
+ };
882
+ }
883
+ //# sourceMappingURL=flow-install.js.map