@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,231 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Tag reading for release lines (RFC-1488): list the annotated tags
4
+ reachable from HEAD that match a line's tag prefix (`v*` | `&lt;pkg&gt;@*`),
5
+ pick the semantically highest one (not the nearest — a stale older tag must
6
+ never hide a higher baseline) and expose the reachable set for evidence.
7
+ Lightweight tags are invisible to release lines by design.</purpose>
8
+ <non-goals>
9
+ <item>No tag creation — flow.install's baseline step owns that, and it is the only writer.</item>
10
+ <item>No version math — semver.ts and release-level.ts own it.</item>
11
+ </non-goals>
12
+ </MODULE_CONTRACT>
13
+ <KEY_DECISIONS>
14
+ <item>`--merged HEAD` scopes to reachable tags only: a tag on an abandoned side branch must not become the baseline.</item>
15
+ <item>`%(objecttype)` + `%(*objectname)` distinguishes annotated (`tag`) from lightweight (`commit`) — only annotated tags carry a line.</item>
16
+ <item>Highest reachable wins over nearest: the historical `forge@0.15.0` predates real `forge@9.x` tags and must not lower the reported version.</item>
17
+ <item>listLegacyTags (RFC-1498) is reporting-only: one for-each-ref pass with NUL-delimited records (contents is multi-line) classifies prefix+semver-matching tags the reader does not honour — never rewrites them.</item>
18
+ </KEY_DECISIONS>
19
+ <CHANGE_SUMMARY>
20
+ <item>RFC-1488: review r1 — parse guard, door/rules metadata, id-exact RFC binding, refname precision, FLOW-09 top-level anchor, test cleanup</item>
21
+ <item>RFC-1490: step 1 — explicit ref param on tag/level helpers + W1-2 +0.<hash>.dirty shape (AC-12)</item>
22
+ <item>RFC-1490: step 4 — ordinary flow.cut (release branch, verified versions, gate, main swap, tags, resume)</item>
23
+ <item>RFC-1490: independent-review pass — lock-held planning, fix-branch verification, spec-shaped data, coverage</item>
24
+ <item>RFC-1498: step 3 — legacy-tags report in flow.install
25
+
26
+ 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>
27
+ <history>RFC-1488</history>
28
+ </CHANGE_SUMMARY>
29
+ */
30
+
31
+ import type { WorkspaceIO } from "../../src/types.ts";
32
+ import { git } from "./git.ts";
33
+ import type { ReleaseLine } from "./release-lines.ts";
34
+ import { compareVersions, parseVersion, type SemVer } from "./semver.ts";
35
+
36
+ export interface LineTags {
37
+ /** Highest-version annotated reachable tag matching the line's prefix. */
38
+ lastTag: { name: string; version: SemVer } | null;
39
+ /** All matching annotated reachable tag names, newest first (for evidence). */
40
+ reachable: string[];
41
+ }
42
+
43
+ interface TagRow {
44
+ name: string;
45
+ objecttype: string;
46
+ peeled: string;
47
+ creatordate: string;
48
+ }
49
+
50
+ const NULL_FIELD = "";
51
+
52
+ /**
53
+ * Annotated tags reachable from HEAD matching `line.tagPrefix`, newest first.
54
+ * Format: `<refname:short>\x1f<objecttype>\x1f<*objectname>\x1f<creatordate>`.
55
+ * Lightweight tags (`objecttype` = commit/blob) are dropped; a non-semver
56
+ * suffix after the prefix (e.g. `v-next`) is dropped too.
57
+ */
58
+ async function listAnnotated(
59
+ repoRoot: string,
60
+ line: ReleaseLine,
61
+ io: WorkspaceIO,
62
+ ref: string,
63
+ ): Promise<TagRow[]> {
64
+ const head = await git(repoRoot, io, ["rev-parse", "--verify", "-q", ref]);
65
+ if (head.exitCode !== 0) return []; // unborn branch — nothing reachable
66
+ const sep = "\x1f";
67
+ // %(refname) (full form) — %(refname:short) would hide a tag sharing its
68
+ // name with a branch (shortening is ambiguous by design).
69
+ const format = `%(refname)${sep}%(objecttype)${sep}%(*objectname)${sep}%(creatordate:iso-strict)`;
70
+ const result = await git(repoRoot, io, [
71
+ "for-each-ref",
72
+ `refs/tags/${line.tagPrefix}*`,
73
+ `--format=${format}`,
74
+ "--sort=-creatordate",
75
+ "--merged",
76
+ ref,
77
+ ]);
78
+ if (result.exitCode !== 0) return [];
79
+ const rows: TagRow[] = [];
80
+ for (const raw of result.stdout.split("\n")) {
81
+ const line_ = raw.trimEnd();
82
+ if (!line_) continue;
83
+ const [refname = "", objecttype = "", peeled = "", creatordate = ""] = line_.split(sep);
84
+ if (objecttype !== "tag") continue; // annotated only
85
+ const name = refname.startsWith("refs/tags/") ? refname.slice("refs/tags/".length) : refname;
86
+ const versionText = name.startsWith(line.tagPrefix)
87
+ ? name.slice(line.tagPrefix.length)
88
+ : NULL_FIELD;
89
+ if (!versionText || parseVersion(versionText) === null) continue;
90
+ rows.push({ name, objecttype, peeled, creatordate });
91
+ }
92
+ return rows;
93
+ }
94
+
95
+ /**
96
+ * Read a line's tag state: `lastTag` is the highest-version annotated
97
+ * reachable tag for its prefix, `reachable` the full matching set newest
98
+ * first. Null/empty when the line was never tagged.
99
+ */
100
+ export async function listLineTags(
101
+ repoRoot: string,
102
+ line: ReleaseLine,
103
+ io: WorkspaceIO,
104
+ ref = "HEAD",
105
+ ): Promise<LineTags> {
106
+ const rows = await listAnnotated(repoRoot, line, io, ref);
107
+ let lastTag: LineTags["lastTag"] = null;
108
+ for (const row of rows) {
109
+ const version = parseVersion(row.name.slice(line.tagPrefix.length));
110
+ if (version === null) continue;
111
+ if (lastTag === null || compareVersions(version, lastTag.version) > 0) {
112
+ lastTag = { name: row.name, version };
113
+ }
114
+ }
115
+ return { lastTag, reachable: rows.map((r) => r.name) };
116
+ }
117
+
118
+ export interface LegacyTag {
119
+ /** Full tag name, e.g. v1.2.2 or lib@0.1.0. */
120
+ name: string;
121
+ /** Release-line id whose tag grammar the name matches. */
122
+ line: string;
123
+ /**
124
+ * Why the release-line reader does not treat it as a line tag:
125
+ * lightweight tags are invisible by design; an annotated tag without
126
+ * the forge/release-tag@1 schema line predates the program.
127
+ */
128
+ kind: "lightweight" | "annotated-without-schema";
129
+ }
130
+
131
+ const RELEASE_TAG_SCHEMA_LINE = /^schema:\s*forge\/release-tag@1\s*$/m;
132
+
133
+ /**
134
+ * Pre-program tags (RFC-1498): every tag whose name matches a discovered
135
+ * line's grammar (tagPrefix + strict semver) but that the release-line
136
+ * reader does not honour — lightweight tags, and annotated tags whose
137
+ * body lacks the `schema: forge/release-tag@1` line. One `for-each-ref`
138
+ * pass; %00 delimits records because %(contents) is multi-line.
139
+ */
140
+ export async function listLegacyTags(
141
+ repoRoot: string,
142
+ lines: ReleaseLine[],
143
+ io: WorkspaceIO,
144
+ ): Promise<LegacyTag[]> {
145
+ const sep = "\x1f";
146
+ const format = `%(refname)${sep}%(objecttype)${sep}%(contents)%00`;
147
+ const result = await git(repoRoot, io, ["for-each-ref", "refs/tags", `--format=${format}`]);
148
+ if (result.exitCode !== 0) return [];
149
+ const legacy: LegacyTag[] = [];
150
+ for (const rec of result.stdout.split("\x00")) {
151
+ const firstSep = rec.indexOf(sep);
152
+ const secondSep = firstSep === -1 ? -1 : rec.indexOf(sep, firstSep + 1);
153
+ if (firstSep === -1 || secondSep === -1) continue;
154
+ const refname = rec.slice(0, firstSep).replace(/^\s+/, "");
155
+ const objecttype = rec.slice(firstSep + 1, secondSep);
156
+ const contents = rec.slice(secondSep + 1);
157
+ const name = refname.startsWith("refs/tags/") ? refname.slice("refs/tags/".length) : refname;
158
+ const line = lines.find(
159
+ (l) =>
160
+ name.startsWith(l.tagPrefix) &&
161
+ parseVersion(name.slice(l.tagPrefix.length)) !== null,
162
+ );
163
+ if (line === undefined) continue;
164
+ if (objecttype === "tag") {
165
+ if (!RELEASE_TAG_SCHEMA_LINE.test(contents)) {
166
+ legacy.push({ name, line: line.id, kind: "annotated-without-schema" });
167
+ }
168
+ } else {
169
+ legacy.push({ name, line: line.id, kind: "lightweight" });
170
+ }
171
+ }
172
+ return legacy;
173
+ }
174
+
175
+ /** Short (9-char) form of a full commit hash — derived-version metadata. */
176
+ export function shortHash(hash: string): string {
177
+ return hash.slice(0, 9);
178
+ }
179
+
180
+ /**
181
+ * forge/release-tag@1 annotation body (RFC-1488). `previous`/`rfcs`/`fingerprints`
182
+ * come from the cut's pendingLevel and the fingerprint hook.
183
+ */
184
+ export function releaseTagAnnotation(fields: {
185
+ tag: string;
186
+ line: string;
187
+ version: string;
188
+ level: string;
189
+ previous: string | null;
190
+ rfcs: string[];
191
+ fingerprints: Record<string, string>;
192
+ }): string {
193
+ const fp = Object.entries(fields.fingerprints)
194
+ .map(([k, v]) => ` ${k}: ${/^[A-Za-z0-9._/+@-]+$/.test(v) ? v : JSON.stringify(v)}`)
195
+ .join("\n");
196
+ return [
197
+ `release ${fields.tag}`,
198
+ "",
199
+ "schema: forge/release-tag@1",
200
+ `line: ${fields.line}`,
201
+ `version: ${fields.version}`,
202
+ `level: ${fields.level}`,
203
+ `previous: ${fields.previous ?? "null"}`,
204
+ `rfcs: [${fields.rfcs.map((r) => `"${r}"`).join(", ")}]`,
205
+ fp.length > 0 ? `fingerprints:\n${fp}` : "fingerprints: {}",
206
+ ].join("\n");
207
+ }
208
+
209
+ export interface ReleaseTagSpec {
210
+ /** Full tag name, e.g. v1.3.0 or lib@2.1.0. */
211
+ name: string;
212
+ /** Commit the tag points at. */
213
+ target: string;
214
+ /** Full annotation text (the forge/release-tag@1 body). */
215
+ annotation: string;
216
+ }
217
+
218
+ /**
219
+ * Create an annotated release tag at `target` with the given annotation
220
+ * body via `git tag -a <name> <target> -m <annotation>`. Callers build the
221
+ * forge/release-tag@1 text; this is the single tag-writing seam (flow.install
222
+ * baselines and flow.cut releases share it).
223
+ */
224
+ export async function writeReleaseTag(
225
+ repoRoot: string,
226
+ io: WorkspaceIO,
227
+ spec: ReleaseTagSpec,
228
+ ): Promise<{ exitCode: number | null; stderr: string }> {
229
+ const result = await git(repoRoot, io, ["tag", "-a", spec.name, spec.target, "-m", spec.annotation]);
230
+ return { exitCode: result.exitCode, stderr: result.stderr };
231
+ }
@@ -0,0 +1,117 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Repository-kind detection for the fixed branch model (RFC-1486) —
4
+ classifies a repository as governed (forge.yaml, no marker), exempt
5
+ (forge.generated.yaml carrying the forge/generated@1 schema) or ungoverned.
6
+ Generated repositories are never blocked by the guard or by flow.check.</purpose>
7
+ <non-goals>
8
+ <item>No flow.check rule evaluation — handlers turn detection results into diagnostics.</item>
9
+ </non-goals>
10
+ </MODULE_CONTRACT>
11
+ <KEY_DECISIONS>
12
+ <item>A marker that fails the schema is a structured error (FLOW-05 material), never an exemption — implicit exemption by malformed file would silently unprotect a governed repo.</item>
13
+ <item>Bare repositories read root files via `git show HEAD:<name>` — they carry no working tree.</item>
14
+ </KEY_DECISIONS>
15
+ <CHANGE_SUMMARY>
16
+ <item>RFC-1486: step 1 — fixed branch-model grammar, marker detection contracts, git helpers</item>
17
+ <item>RFC-1486: step 1 — branch grammar, marker detection, git helpers</item>
18
+ <item>RFC-1486: review r1 — committed-state adoption gate, uncommitted-hook committedness, step-failure trail, idempotency declaration, lazy asset resolution</item>
19
+ <item>RFC-1491: independent-review pass — shared lock constants, publishable pending filter, declared rules, hold ordering, sha-pinned refspecs</item>
20
+ </CHANGE_SUMMARY>
21
+ */
22
+
23
+ import { join } from "node:path";
24
+
25
+ import { parse as yamlParse } from "yaml";
26
+ import { z } from "zod";
27
+
28
+ import type { WorkspaceIO } from "../../src/types.ts";
29
+
30
+ import { isBare } from "./git.ts";
31
+
32
+ export const GENERATED_MARKER_FILE = "forge.generated.yaml";
33
+ export const FORGE_CONFIG_FILE = "forge.yaml";
34
+
35
+ export const generatedMarkerSchema = z
36
+ .object({
37
+ schema: z.literal("forge/generated@1"),
38
+ generator: z.string().min(1),
39
+ source: z.string().min(1),
40
+ })
41
+ .strict();
42
+ export type GeneratedMarker = z.infer<typeof generatedMarkerSchema>;
43
+
44
+ export type RepoKind =
45
+ | { kind: "governed" } // forge.yaml present, no marker
46
+ | { kind: "exempt"; marker: GeneratedMarker }
47
+ | { kind: "ungoverned" }; // no forge.yaml
48
+
49
+ export type RepoKindDetection =
50
+ | { ok: true; repoKind: RepoKind }
51
+ /** The marker exists but fails forge/generated@1 — FLOW-05 material. */
52
+ | { ok: false; reason: "invalid-marker"; detail: string };
53
+
54
+ /**
55
+ * Detect the repository kind from committed/working state only (DNA-105) —
56
+ * the working-tree marker for non-bare repositories, `HEAD:<file>` for bare
57
+ * ones. Never consults process-global state.
58
+ */
59
+ export async function detectRepoKind(
60
+ repoRoot: string,
61
+ io: WorkspaceIO,
62
+ ): Promise<RepoKindDetection> {
63
+ const bare = await isBare(repoRoot, io);
64
+ const markerText = await readRepoRootFile(repoRoot, GENERATED_MARKER_FILE, io, bare);
65
+ if (markerText !== null) {
66
+ let markerData: unknown;
67
+ try {
68
+ markerData = yamlParse(markerText);
69
+ } catch (error) {
70
+ return {
71
+ ok: false,
72
+ reason: "invalid-marker",
73
+ detail: `${GENERATED_MARKER_FILE} is not parseable YAML: ${error instanceof Error ? error.message : String(error)}`,
74
+ };
75
+ }
76
+ const parsed = generatedMarkerSchema.safeParse(markerData);
77
+ if (!parsed.success) {
78
+ return {
79
+ ok: false,
80
+ reason: "invalid-marker",
81
+ detail: `${GENERATED_MARKER_FILE} fails the forge/generated@1 schema: ${parsed.error.issues
82
+ .map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`)
83
+ .join("; ")}`,
84
+ };
85
+ }
86
+ return { ok: true, repoKind: { kind: "exempt", marker: parsed.data } };
87
+ }
88
+ const forgeConfig = await readRepoRootFile(repoRoot, FORGE_CONFIG_FILE, io, bare);
89
+ return {
90
+ ok: true,
91
+ repoKind: forgeConfig !== null ? { kind: "governed" } : { kind: "ungoverned" },
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Read a file at the repository top level: from the working tree for non-bare
97
+ * repositories, from `git show HEAD:<name>` for bare ones. Returns null when
98
+ * the file does not exist.
99
+ */
100
+ export async function readRepoRootFile(
101
+ repoRoot: string,
102
+ name: string,
103
+ io: WorkspaceIO,
104
+ bare: boolean,
105
+ ): Promise<string | null> {
106
+ if (bare) {
107
+ // Adoption state lives on develop in the fixed branch model — HEAD on a
108
+ // bare repository may point at main, which carries no markers/hooks.
109
+ for (const ref of ["refs/heads/develop", "HEAD"]) {
110
+ const result = await io.exec("git", ["-C", repoRoot, "show", `${ref}:${name}`]);
111
+ if (result.exitCode === 0) return result.stdout;
112
+ }
113
+ return null;
114
+ }
115
+ const path = join(repoRoot, name);
116
+ return (await io.exists(path)) ? io.readFile(path) : null;
117
+ }
@@ -0,0 +1,73 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Repository hook-script runner for the session lifecycle (RFC-1487):
4
+ worktree-setup.sh, integration-gate.sh and worktree-teardown.sh are optional
5
+ repository conventions executed from the PRIMARY worktree — never from the
6
+ branch worktree, so a session cannot weaken its own gate — with cwd set to
7
+ the branch worktree and the declared FLOW_* environment.</purpose>
8
+ <non-goals>
9
+ <item>No lifecycle decisions — handlers map a non-zero exit to their own diagnostics.</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <KEY_DECISIONS>
13
+ <item>Scripts run as `sh &lt;primary&gt;/hooks/&lt;name&gt;.sh` through io.exec with an argument vector — no shell interpolation (DNA-89, AUDIT-RFC-1487-G1).</item>
14
+ <item>Absent script → skipped; a script present in the branch worktree but absent in the primary is skipped identically — only develop's version gates.</item>
15
+ <item>stderrTail is the last 40 lines — enough for the report without flooding it (DNA-106).</item>
16
+ </KEY_DECISIONS>
17
+ <CHANGE_SUMMARY>
18
+ <item>RFC-1487: step 2 — primary-side hook-script runner</item>
19
+ <item>RFC-1490: step 4 — ordinary flow.cut (release branch, verified versions, gate, main swap, tags, resume)</item>
20
+ <item>RFC-1491: step 5 — flow.push atomic outbound path + extract publication</item>
21
+ </CHANGE_SUMMARY>
22
+ */
23
+
24
+ import { join } from "node:path";
25
+
26
+ import type { WorkspaceIO } from "../../src/types.ts";
27
+
28
+ export type FlowScriptName =
29
+ | "worktree-setup"
30
+ | "integration-gate"
31
+ | "worktree-teardown"
32
+ | "release-fingerprints"
33
+ | "extract-verify";
34
+
35
+ export interface FlowScriptResult {
36
+ status: "done" | "skipped" | "failed";
37
+ exitCode: number | null;
38
+ stderrTail: string;
39
+ /** stdout truncated to 64 KiB with a trailing `…[truncated]` marker. */
40
+ stdout: string;
41
+ }
42
+
43
+ const STDERR_TAIL_LINES = 40;
44
+ const STDOUT_CAP = 64 * 1024;
45
+
46
+ /**
47
+ * Run `<primary>/hooks/<name>.sh` with cwd inside `cwd` (the branch
48
+ * worktree). The script bytes always come from the primary checkout — the
49
+ * develop version, already integrated.
50
+ */
51
+ export async function runFlowScript(
52
+ io: WorkspaceIO,
53
+ name: FlowScriptName,
54
+ opts: { primary: string; cwd: string; env: Record<string, string> },
55
+ ): Promise<FlowScriptResult> {
56
+ const scriptPath = join(opts.primary, "hooks", `${name}.sh`);
57
+ if (!(await io.exists(scriptPath))) {
58
+ return { status: "skipped", exitCode: null, stderrTail: "", stdout: "" };
59
+ }
60
+ const result = await io.exec("sh", [scriptPath], { cwd: opts.cwd, env: opts.env });
61
+ const tail = result.stderr
62
+ .split("\n")
63
+ .filter((line) => line.length > 0)
64
+ .slice(-STDERR_TAIL_LINES)
65
+ .join("\n");
66
+ const stdout =
67
+ result.stdout.length > STDOUT_CAP
68
+ ? `${result.stdout.slice(0, STDOUT_CAP)}…[truncated]`
69
+ : result.stdout;
70
+ return result.exitCode === 0
71
+ ? { status: "done", exitCode: result.exitCode, stderrTail: tail, stdout }
72
+ : { status: "failed", exitCode: result.exitCode, stderrTail: tail, stdout };
73
+ }
@@ -0,0 +1,82 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Strict three-integer semver for release lines (RFC-1488) — parse,
4
+ compare and bump `X.Y.Z` versions with no pre-release/build segments: release
5
+ tags are `vX.Y.Z` and `<package>@X.Y.Z`, nothing else ever matches.</purpose>
6
+ <non-goals>
7
+ <item>No loose semver (pre-release, build metadata, ranges) — the release-line grammar is fixed.</item>
8
+ </non-goals>
9
+ </MODULE_CONTRACT>
10
+ <KEY_DECISIONS>
11
+ <item>Strict `^\d+\.\d+\.\d+$` — a pre-release or build suffix would silently break the tag-name match, so it is a parse failure, never normalized.</item>
12
+ </KEY_DECISIONS>
13
+ <CHANGE_SUMMARY>
14
+ <item>RFC-1488: step 1 — strict X.Y.Z parse/compare/bump</item>
15
+ <item>RFC-1488: step 1 — semver helper + release-line discovery (extract.config.yaml workspace globs)</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+
19
+ export interface SemVer {
20
+ major: number;
21
+ minor: number;
22
+ patch: number;
23
+ }
24
+
25
+ export type ReleaseLevel = "none" | "patch" | "minor" | "major";
26
+
27
+ /**
28
+ * Parse a strict `X.Y.Z` version — three non-negative integers, no leading
29
+ * `v`, no pre-release or build suffix. Returns null on anything else.
30
+ */
31
+ export function parseVersion(raw: string): SemVer | null {
32
+ const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(raw.trim());
33
+ if (!match) return null;
34
+ return {
35
+ major: Number.parseInt(match[1]!, 10),
36
+ minor: Number.parseInt(match[2]!, 10),
37
+ patch: Number.parseInt(match[3]!, 10),
38
+ };
39
+ }
40
+
41
+ /** Format a parsed version back to `X.Y.Z`. */
42
+ export function formatVersion(v: SemVer): string {
43
+ return `${v.major}.${v.minor}.${v.patch}`;
44
+ }
45
+
46
+ /** Numeric compare: -1 / 0 / +1. */
47
+ export function compareVersions(a: SemVer, b: SemVer): -1 | 0 | 1 {
48
+ if (a.major !== b.major) return a.major < b.major ? -1 : 1;
49
+ if (a.minor !== b.minor) return a.minor < b.minor ? -1 : 1;
50
+ if (a.patch !== b.patch) return a.patch < b.patch ? -1 : 1;
51
+ return 0;
52
+ }
53
+
54
+ /** Bump `version` one level: patch → Z+1; minor → Y+1, Z=0; major → X+1, Y=Z=0. */
55
+ export function bumpVersion(v: SemVer, level: Exclude<ReleaseLevel, "none">): SemVer {
56
+ switch (level) {
57
+ case "major":
58
+ return { major: v.major + 1, minor: 0, patch: 0 };
59
+ case "minor":
60
+ return { major: v.major, minor: v.minor + 1, patch: 0 };
61
+ case "patch":
62
+ return { major: v.major, minor: v.minor, patch: v.patch + 1 };
63
+ }
64
+ }
65
+
66
+ /** Ordering of release levels for max() — `none` ranks below every real level. */
67
+ export function levelRank(level: ReleaseLevel): number {
68
+ switch (level) {
69
+ case "none":
70
+ return 0;
71
+ case "patch":
72
+ return 1;
73
+ case "minor":
74
+ return 2;
75
+ case "major":
76
+ return 3;
77
+ }
78
+ }
79
+
80
+ export function maxLevel(a: ReleaseLevel, b: ReleaseLevel): ReleaseLevel {
81
+ return levelRank(a) >= levelRank(b) ? a : b;
82
+ }
@@ -0,0 +1,136 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>AC-1: parseFlowBranch accepts exactly the FI-1 grammar rows and
4
+ returns null for every invalid row of the shared name table
5
+ (tests/fixtures/branch-names.yaml); formatFlowBranch round-trips valid names
6
+ and renders the date in UTC.</purpose>
7
+ </MODULE_CONTRACT>
8
+ <CHANGE_SUMMARY>
9
+ <item>RFC-1486: step 1 — fixed branch-model grammar, marker detection contracts, git helpers</item>
10
+ <item>RFC-1486: step 1 — branch grammar, marker detection, git helpers</item>
11
+ </CHANGE_SUMMARY>
12
+ */
13
+
14
+ import { readFileSync } from "node:fs";
15
+ import { fileURLToPath } from "node:url";
16
+
17
+ import { parse as yamlParse } from "yaml";
18
+ import { describe, expect, it } from "vitest";
19
+
20
+ import {
21
+ classifyBranch,
22
+ formatFlowBranch,
23
+ isValidFlowDate,
24
+ parseFlowBranch,
25
+ } from "../branch-name.ts";
26
+
27
+ interface NameRow {
28
+ name: string;
29
+ verdict: "allow" | "refuse";
30
+ rule: "FLOW-GUARD-01" | "FLOW-GUARD-02" | null;
31
+ ref_ok: boolean;
32
+ }
33
+
34
+ const table = yamlParse(
35
+ readFileSync(fileURLToPath(new URL("./fixtures/branch-names.yaml", import.meta.url)), "utf8"),
36
+ ) as { rows: NameRow[] };
37
+
38
+ describe("shared name table", () => {
39
+ it("carries at least 30 rows and marks uncreatable refs as refuse", () => {
40
+ expect(table.rows.length).toBeGreaterThanOrEqual(30);
41
+ const uncreatable = table.rows.filter((row) => !row.ref_ok);
42
+ expect(uncreatable.length).toBeGreaterThan(0);
43
+ for (const row of uncreatable) {
44
+ expect(row.verdict, `uncreatable ref must be a refuse row: ${row.name}`).toBe("refuse");
45
+ }
46
+ });
47
+ });
48
+
49
+ describe("parseFlowBranch", () => {
50
+ for (const row of table.rows) {
51
+ it(`${row.verdict === "allow" ? "accepts" : "rejects"} "${row.name}"`, () => {
52
+ const parsed = parseFlowBranch(row.name);
53
+ if (row.verdict === "allow") {
54
+ expect(parsed, `expected "${row.name}" to parse`).not.toBeNull();
55
+ expect(parsed!.name).toBe(row.name);
56
+ expect(["task", "session", "fix"]).toContain(parsed!.kind);
57
+ expect(isValidFlowDate(parsed!.date)).toBe(true);
58
+ expect(parsed!.seq).toBeGreaterThanOrEqual(1);
59
+ expect(parsed!.seq).toBeLessThanOrEqual(99);
60
+ expect(parsed!.slug.length).toBeGreaterThanOrEqual(3);
61
+ expect(parsed!.slug.length).toBeLessThanOrEqual(48);
62
+ } else {
63
+ expect(parsed, `expected "${row.name}" to return null`).toBeNull();
64
+ }
65
+ });
66
+ }
67
+ });
68
+
69
+ describe("classifyBranch", () => {
70
+ it("maps every table row to the verdict the shell guard must produce", () => {
71
+ for (const row of table.rows) {
72
+ const cls = classifyBranch(row.name);
73
+ const expectedRule =
74
+ cls.kind === "protected"
75
+ ? "FLOW-GUARD-01"
76
+ : cls.kind === "nonconforming"
77
+ ? "FLOW-GUARD-02"
78
+ : null;
79
+ expect(expectedRule, `classifyBranch("${row.name}")`).toBe(row.rule);
80
+ expect(cls.kind !== "flow", `verdict of "${row.name}"`).toBe(row.verdict === "refuse");
81
+ }
82
+ });
83
+ });
84
+
85
+ describe("formatFlowBranch", () => {
86
+ it("round-trips every valid table row", () => {
87
+ for (const row of table.rows.filter((r) => r.verdict === "allow")) {
88
+ const parsed = parseFlowBranch(row.name)!;
89
+ const date = new Date(
90
+ Date.UTC(
91
+ 2000 + Number(parsed.date.slice(0, 2)),
92
+ Number(parsed.date.slice(2, 4)) - 1,
93
+ Number(parsed.date.slice(4, 6)),
94
+ ),
95
+ );
96
+ expect(
97
+ formatFlowBranch({ kind: parsed.kind, date, seq: parsed.seq, slug: parsed.slug }),
98
+ ).toBe(row.name);
99
+ }
100
+ });
101
+
102
+ it("renders the date in UTC regardless of the Date's wall-clock edge", () => {
103
+ // 2026-11-01 23:30 UTC is still 2026-11-01 in UTC — and 2026-11-02 in
104
+ // UTC+2. The name must follow UTC, not the local zone.
105
+ const edge = new Date(Date.UTC(2026, 10, 1, 23, 30));
106
+ expect(formatFlowBranch({ kind: "session", date: edge, seq: 1, slug: "forge-flow" })).toBe(
107
+ "auto/session-261101-01-forge-flow",
108
+ );
109
+ });
110
+
111
+ it("throws on out-of-range seq and malformed slug", () => {
112
+ const date = new Date(Date.UTC(2026, 10, 1));
113
+ for (const seq of [0, 100, -1, 1.5]) {
114
+ expect(() =>
115
+ formatFlowBranch({ kind: "task", date, seq, slug: "abc" }),
116
+ ).toThrow(/seq/);
117
+ }
118
+ for (const slug of ["ab", "a_b", "ABC", "a".repeat(49), "a-"]) {
119
+ expect(() =>
120
+ formatFlowBranch({ kind: "task", date, seq: 1, slug }),
121
+ ).toThrow(/slug/);
122
+ }
123
+ });
124
+ });
125
+
126
+ describe("isValidFlowDate", () => {
127
+ it("accepts real calendar dates and rejects impossible ones", () => {
128
+ for (const ok of ["261101", "240229", "241231", "991231"]) {
129
+ expect(isValidFlowDate(ok), ok).toBe(true);
130
+ }
131
+ // 99 is a valid 2-digit year (2099-12-31): YYMMDD has no century pivot.
132
+ for (const bad of ["261332", "260230", "260229", "230229", "261100", "261131", "abcdef", "26110"]) {
133
+ expect(isValidFlowDate(bad), bad).toBe(false);
134
+ }
135
+ });
136
+ });