@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,373 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>flow.push — the only outbound path (RFC-1491): refuse preflight
4
+ FLOW-PUSH-01/02/03/06/07, run the atomic push of develop+main+tags under
5
+ FORGE_FLOW_OP=push, journal the push, then publish the package-line tags
6
+ (pushed now plus journal-scoped pending, minus baseline) through
7
+ repo-extract with a single ours-merge reconcile — never force-push, never
8
+ a manual push path.</purpose>
9
+ <non-goals>
10
+ <item>No digest computation beyond collectDigest — digest.ts owns the shape.</item>
11
+ <item>No real repo-extract in tests — fixtures install a fake binary.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <KEY_DECISIONS>
15
+ <item>The digest must be quoted: a recomputed digestId mismatch refuses FLOW-PUSH-02 and names the new id, so the operator always pushes what they reviewed.</item>
16
+ <item>A rerun with an empty develop/main/tag digest skips the push but still retries pendingPublications — publication retries are journal-scoped to this machine's pushes only (AUDIT-RFC-1491-G1).</item>
17
+ <item>Publication failures are FLOW-PUSH-05 per tag; the command continues with the next tag and exits non-zero at the end.</item>
18
+ </KEY_DECISIONS>
19
+ <CHANGE_SUMMARY>
20
+ <item>RFC-1491: step 5 — flow.push (preflight, atomic push, publications, journals)</item>
21
+ <item>RFC-1491: step 5 — flow.push atomic outbound path + extract publication</item>
22
+ <item>RFC-1491: independent-review pass — shared lock constants, publishable pending filter, declared rules, hold ordering, sha-pinned refspecs</item>
23
+ <item>RFC-1501: one argv-shaped read-only git allowlist for the recording and read-only adapters (RFC-1501)
24
+
25
+ READ_ONLY_GIT_QUERIES / isReadOnlyGitQuery replace the recording adapter's
26
+ first-argument allowlist; the read-only adapter and the static scan use the same
27
+ table. The kernel forwards --dry-run into commands that declare a dry-run flag,
28
+ and flow.push / flow.hold dry-runs no longer fetch. The switch-over runbook goes
29
+ back to werkstatt run flow.install --dry-run.</item>
30
+ </CHANGE_SUMMARY>
31
+ */
32
+
33
+ import { join } from "node:path";
34
+
35
+ import type {
36
+ Diagnostic,
37
+ ForgeCommandInput,
38
+ ForgeCommandResult,
39
+ ForgeRuntimeContext,
40
+ WorkspaceIO,
41
+ } from "../../../src/types.ts";
42
+ import { resolveIo } from "../../../src/utils/io.ts";
43
+ import { collectDigest, lineForTag } from "../digest.ts";
44
+ import {
45
+ git,
46
+ requireGit,
47
+ topLevel,
48
+ } from "../git.ts";
49
+ import { markerIsValid } from "../markers.ts";
50
+ import { publishTag, tagAnnotationLevel, type PublicationRow } from "../publish.ts";
51
+ import {
52
+ appendJournal,
53
+ commonGitDir,
54
+ FlowRegistrySchemaError,
55
+ } from "../registry.ts";
56
+ import { discoverReleaseLines, type ReleaseLine } from "../release-lines.ts";
57
+ import { primaryWorktree } from "../worktree-path.ts";
58
+
59
+ export interface FlowPushData {
60
+ digestId: string;
61
+ pushed: boolean;
62
+ refs: string[];
63
+ publications: PublicationRow[];
64
+ diagnostics: Diagnostic[];
65
+ /** RFC-1501: whether the preflight digest fetched origin; absent on early refusals. */
66
+ fetched?: boolean;
67
+ }
68
+
69
+ function refuse(ruleId: string, message: string, fixHint?: string): FlowPushData {
70
+ return {
71
+ digestId: "",
72
+ pushed: false,
73
+ refs: [],
74
+ publications: [],
75
+ diagnostics: [{ ruleId, severity: "error", message, fixHint }],
76
+ };
77
+ }
78
+
79
+ /**
80
+ * Core of flow.push — callable in tests. Every refusal is a diagnostic in
81
+ * the returned data; nothing leaves the machine unless pushed: true.
82
+ */
83
+ export async function pushFlow(
84
+ repoRoot: string,
85
+ io: WorkspaceIO,
86
+ opts: { digest: string; dryRun: boolean; now?: Date },
87
+ ): Promise<FlowPushData> {
88
+ const common = await commonGitDir(io, repoRoot);
89
+ const primary = await primaryWorktree(io, repoRoot);
90
+
91
+ // --- preflight -------------------------------------------------------------
92
+ // RFC-1501: a dry-run never fetches — `git fetch origin --prune` rewrites
93
+ // and prunes remote-tracking refs. It judges the digest exactly like
94
+ // `flow.digest --no-fetch`; a real push still fetches first.
95
+ const digest = await collectDigest(repoRoot, io, { fetch: !opts.dryRun });
96
+ const noOrigin = digest.diagnostics.find(
97
+ (d) => d.ruleId === "FLOW-PUSH-01" && d.severity === "error",
98
+ );
99
+ if (noOrigin !== undefined) {
100
+ return refuse("FLOW-PUSH-01", noOrigin.message, "add an 'origin' remote first");
101
+ }
102
+ if (digest.digestId !== opts.digest) {
103
+ return refuse(
104
+ "FLOW-PUSH-02",
105
+ `the digest is stale — the current digestId is ${digest.digestId}, not ${opts.digest}`,
106
+ `run flow.digest, review the new state and re-run flow.push --digest ${digest.digestId}`,
107
+ );
108
+ }
109
+
110
+ for (const [branch, remote] of [
111
+ ["develop", digest.develop.remote],
112
+ ["main", digest.main.remote],
113
+ ] as const) {
114
+ if (remote === null) continue;
115
+ const ancestor = await git(repoRoot, io, [
116
+ "merge-base",
117
+ "--is-ancestor",
118
+ remote,
119
+ branch,
120
+ ]);
121
+ if (ancestor.exitCode !== 0) {
122
+ return refuse(
123
+ "FLOW-PUSH-03",
124
+ `origin/${branch} is not an ancestor of ${branch} — someone pushed elsewhere`,
125
+ "fetch, inspect the divergence and reconcile before pushing",
126
+ );
127
+ }
128
+ }
129
+
130
+ const { lines } = await discoverReleaseLines(repoRoot, io);
131
+
132
+ // Publications: package-line tags pushed now + journal-scoped pending,
133
+ // minus baseline annotations.
134
+ const publicationTags = new Map<string, ReleaseLine>();
135
+ for (const tag of digest.tags) {
136
+ const line = lineForTag(lines, tag);
137
+ if (line !== null && line.id !== "repo") publicationTags.set(tag, line);
138
+ }
139
+ for (const pending of digest.pendingPublications) {
140
+ const line = lines.find((l) => l.id === pending.line) ?? lineForTag(lines, pending.tag);
141
+ if (line !== null && line.id !== "repo") publicationTags.set(pending.tag, line);
142
+ }
143
+ const publishable: Array<{ tag: string; line: ReleaseLine }> = [];
144
+ const baselineSkipped: PublicationRow[] = [];
145
+ for (const [tag, line] of [...publicationTags.entries()].sort(([a], [b]) => a.localeCompare(b))) {
146
+ const level = await tagAnnotationLevel(repoRoot, io, tag);
147
+ if (level === "baseline") {
148
+ baselineSkipped.push({
149
+ tag,
150
+ line: line.id,
151
+ status: "skipped-baseline",
152
+ dest: null,
153
+ verify: null,
154
+ reconciled: false,
155
+ destHead: null,
156
+ });
157
+ } else {
158
+ publishable.push({ tag, line });
159
+ }
160
+ }
161
+
162
+ for (const { line } of publishable) {
163
+ const dir = line.paths[0]!;
164
+ if (!(await markerIsValid(join(primary, dir, "forge.generated.yaml"), io))) {
165
+ return refuse(
166
+ "FLOW-PUSH-06",
167
+ `package line ${line.id} has no valid forge.generated.yaml in ${dir} — it must not be published`,
168
+ "re-run flow.install to restore the marker, or remove the line's tags",
169
+ );
170
+ }
171
+ }
172
+
173
+ const extractBin = join(primary, "node_modules", ".bin", "repo-extract");
174
+ if (publishable.length > 0 && !(await io.exists(extractBin))) {
175
+ return refuse(
176
+ "FLOW-PUSH-07",
177
+ `${extractBin} is missing while ${publishable.length} tag(s) wait to publish`,
178
+ "install the workspace dependencies so repo-extract is linked",
179
+ );
180
+ }
181
+
182
+ // Sha-pinned refspecs — the push ships exactly the reviewed tips; a local
183
+ // branch that moved since the digest stays local instead of sneaking in.
184
+ const refspecs = [
185
+ `${digest.develop.local}:refs/heads/develop`,
186
+ `${digest.main.local}:refs/heads/main`,
187
+ ...digest.tags.map((t) => `refs/tags/${t}:refs/tags/${t}`),
188
+ ];
189
+
190
+ if (opts.dryRun) {
191
+ return {
192
+ digestId: digest.digestId,
193
+ fetched: digest.fetched,
194
+ pushed: false,
195
+ refs: refspecs,
196
+ publications: [
197
+ ...baselineSkipped,
198
+ ...publishable.map(
199
+ (p): PublicationRow => ({
200
+ tag: p.tag,
201
+ line: p.line.id,
202
+ status: "pending",
203
+ dest: null,
204
+ verify: null,
205
+ reconciled: false,
206
+ destHead: null,
207
+ }),
208
+ ),
209
+ ],
210
+ diagnostics: [],
211
+ };
212
+ }
213
+
214
+ // --- push ------------------------------------------------------------------
215
+ const hasRefs = digest.develop.ahead > 0 || digest.main.ahead > 0 || digest.tags.length > 0;
216
+ const journalWarnings: string[] = [];
217
+ let pushed = false;
218
+ if (hasRefs) {
219
+ const push = await git(repoRoot, io, ["push", "--atomic", "origin", ...refspecs], {
220
+ env: { FORGE_FLOW_OP: "push" },
221
+ });
222
+ if (push.exitCode !== 0) {
223
+ return {
224
+ digestId: digest.digestId,
225
+ fetched: digest.fetched,
226
+ pushed: false,
227
+ refs: refspecs,
228
+ publications: [],
229
+ diagnostics: [
230
+ {
231
+ ruleId: "FLOW-PUSH-04",
232
+ severity: "error",
233
+ message: `git push --atomic failed — nothing was updated: ${push.stderr.trim().split("\n").slice(-1)[0] ?? "unknown error"}`,
234
+ fixHint: "inspect the remote error, reconcile, and re-run with a fresh digest",
235
+ },
236
+ ],
237
+ };
238
+ }
239
+ pushed = true;
240
+ try {
241
+ await appendJournal(io, common, {
242
+ event: "push",
243
+ branch: "develop",
244
+ sha: digest.develop.local,
245
+ base: digest.develop.remote ?? undefined,
246
+ detail: digest.tags.join(" "),
247
+ });
248
+ } catch (error) {
249
+ journalWarnings.push(
250
+ `push journal record could not be appended — pending-publication retries for ${digest.tags.join(", ") || "no tags"} are lost: ${String(error)}`,
251
+ );
252
+ }
253
+ }
254
+
255
+ // --- publications ------------------------------------------------------------
256
+ const publications: PublicationRow[] = [...baselineSkipped];
257
+ const diagnostics: Diagnostic[] = journalWarnings.map(
258
+ (message): Diagnostic => ({
259
+ ruleId: "FLOW-07",
260
+ severity: "warning",
261
+ message,
262
+ }),
263
+ );
264
+ for (const { tag, line } of publishable) {
265
+ const row = await publishTag(primary, io, { line, tag });
266
+ publications.push(row);
267
+ if (row.status === "failed") {
268
+ diagnostics.push({
269
+ ruleId: "FLOW-PUSH-05",
270
+ severity: "error",
271
+ message: `publication of ${tag} (${line.id}) failed: ${row.error ?? "unknown"}`,
272
+ fixHint: "fix the extract or destination, then re-run flow.push with a fresh digest — pending publications are retried",
273
+ });
274
+ continue;
275
+ }
276
+ if (row.status === "published") {
277
+ try {
278
+ await appendJournal(io, common, {
279
+ event: "publish",
280
+ branch: tag,
281
+ sha: row.destHead ?? "",
282
+ detail: row.dest ?? "",
283
+ });
284
+ } catch (error) {
285
+ diagnostics.push({
286
+ ruleId: "FLOW-07",
287
+ severity: "warning",
288
+ message: `publish journal record for ${tag} could not be appended — the tag will be retried as pending: ${String(error)}`,
289
+ });
290
+ }
291
+ }
292
+ }
293
+
294
+ return {
295
+ digestId: digest.digestId,
296
+ fetched: digest.fetched,
297
+ pushed,
298
+ refs: refspecs,
299
+ publications,
300
+ diagnostics,
301
+ };
302
+ }
303
+
304
+ export async function runFlowPush(
305
+ input: ForgeCommandInput,
306
+ context: ForgeRuntimeContext,
307
+ ): Promise<ForgeCommandResult<FlowPushData>> {
308
+ const { workspaceRoot, logger, outputFormat } = context;
309
+ const io: WorkspaceIO = resolveIo(context.io);
310
+ await requireGit(io);
311
+
312
+ const repoRoot = await topLevel(workspaceRoot, io);
313
+ if (repoRoot === null) {
314
+ throw new Error("flow.push must run inside a git repository");
315
+ }
316
+
317
+ const digestFlag = typeof input.flags["digest"] === "string" ? input.flags["digest"] : "";
318
+ if (digestFlag.length === 0) {
319
+ return {
320
+ data: refuse(
321
+ "FLOW-PUSH-02",
322
+ "--digest <id> is required — run flow.digest first and quote its digestId",
323
+ ),
324
+ exitCode: 1,
325
+ summary: "[flow.push] missing --digest",
326
+ };
327
+ }
328
+
329
+ let data: FlowPushData;
330
+ try {
331
+ data = await pushFlow(repoRoot, io, {
332
+ digest: digestFlag,
333
+ dryRun: input.flags["dry-run"] === true,
334
+ });
335
+ } catch (error) {
336
+ if (error instanceof FlowRegistrySchemaError) {
337
+ data = refuse("FLOW-07", error.message);
338
+ } else {
339
+ throw error;
340
+ }
341
+ }
342
+ const errors = data.diagnostics.filter((d) => d.severity === "error");
343
+ const publishedCount = data.publications.filter((p) => p.status === "published").length;
344
+
345
+ if (outputFormat === "pretty") {
346
+ for (const d of data.diagnostics) {
347
+ if (d.severity === "error") logger.error(` ${d.ruleId}: ${d.message}`);
348
+ else logger.warn(` ${d.ruleId}: ${d.message}`);
349
+ }
350
+ if (data.pushed) {
351
+ logger.info(` pushed: ${data.refs.join(", ")}`);
352
+ }
353
+ for (const pub of data.publications) {
354
+ if (pub.status === "published") {
355
+ logger.info(` published ${pub.tag} → ${pub.dest}${pub.reconciled ? " (reconciled)" : ""}`);
356
+ } else if (pub.status === "skipped-baseline") {
357
+ logger.info(` skipped baseline tag ${pub.tag}`);
358
+ } else if (pub.status === "pending") {
359
+ logger.info(` would publish ${pub.tag} (dry-run)`);
360
+ }
361
+ }
362
+ }
363
+
364
+ return {
365
+ data,
366
+ exitCode: errors.length > 0 ? 1 : 0,
367
+ summary: input.flags["dry-run"] === true
368
+ ? `[flow.push] dry-run — ${data.refs.length} ref(s), ${data.publications.length} publication candidate(s)`
369
+ : data.pushed || publishedCount > 0
370
+ ? `[flow.push] pushed ${data.refs.length} ref(s), ${publishedCount} publication(s)`
371
+ : `[flow.push] refused — ${errors.length} error(s)`,
372
+ };
373
+ }
@@ -0,0 +1,283 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>flow.status — the read-only session-branch report (RFC-1487). Lists
4
+ every auto branch with its registry entry, worktree, uncommitted-change
5
+ count, distance to develop, last commit time, held state and the 72 h stale
6
+ flag. collectFlowStatus also feeds flow.check's FLOW-06/07 — one fact source
7
+ for both surfaces.</purpose>
8
+ <non-goals>
9
+ <item>No mutation — a dead session is named, never reaped here.</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <KEY_DECISIONS>
13
+ <item>The branch set is the union of local auto names and registry entries — a dead session leaves a branch, an entry or a worktree, and each shows up with its mismatch fields set.</item>
14
+ <item>Stale is max(lastCommitAt, updatedAt) &gt; 72 h for registered entries and lastCommitAt &gt; 72 h for unregistered branches; held entries are never stale (RFC FLOW-06).</item>
15
+ <item>Stray (RFC-1498): a local auto branch with no registry entry and no worktree checkout anywhere is exposed as unregisteredBranchesWithoutWorktree regardless of age — the leftover shape a failed branch -D leaves.</item>
16
+ </KEY_DECISIONS>
17
+ <CHANGE_SUMMARY>
18
+ <item>RFC-1487: close rfc-1487 review findings — dirty-check parity with git worktree remove, ownership-verified lock release, FLOW-07 registry-error mapping, residual RFC-1462 docs removed
19
+
20
+ The dirty gate for session worktrees now uses full porcelain status
21
+ (untracked files included) because it predicts 'git worktree remove';
22
+ the primary-clean gate keeps tracked-only semantics because it predicts
23
+ 'merge --ff-only'. Lock release verifies the held payload before
24
+ unlinking. Registry/journal failures map to FLOW-07 in every handler.
25
+ The final branch-name collision reports FLOW-OPEN-04, flow.discard
26
+ propagates its teardown result and predicts FLOW-DIS-03 on --dry-run,
27
+ and integrate exposes teardown as its own field.</item>
28
+ <item>RFC-1490: independent-review pass — lock-held planning, fix-branch verification, spec-shaped data, coverage</item>
29
+ <item>RFC-1491: step 1 — journal base/rewrites + held registry widening, W1-1 discard tip, FLOW-INT-11</item>
30
+ <item>RFC-1498: step 1 — FLOW-07 for stray auto branches
31
+
32
+ collectFlowStatus exposes unregisteredBranchesWithoutWorktree — local auto/* branch names with no registry entry and no worktree checkout anywhere (primary or linked), the shape a failed branch -D leaves behind. flow.check emits one FLOW-07 warning per stray regardless of age: the 72 h rule in FLOW-06 only covered staleness, so a fresh leftover went unreported. The fix hint names flow.status for inspection and flow.discard for teardown, and flags that a branch with unique commits needs a human decision. Tests AC-1 (fresh stray branch reports FLOW-07, not FLOW-06) and AC-2 (a registered session with a live worktree reports none).</item>
33
+ <item>RFC-1498: step 2 — network-only marker source
34
+
35
+ 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>
36
+ <history>RFC-1487</history>
37
+ </CHANGE_SUMMARY>
38
+ */
39
+
40
+ import type {
41
+ Diagnostic,
42
+ ForgeCommandInput,
43
+ ForgeCommandResult,
44
+ ForgeRuntimeContext,
45
+ WorkspaceIO,
46
+ } from "../../../src/types.ts";
47
+ import { resolveIo } from "../../../src/utils/io.ts";
48
+ import { parseFlowBranch } from "../branch-name.ts";
49
+ import {
50
+ currentBranch,
51
+ git,
52
+ lastCommitAt,
53
+ listLocalBranches,
54
+ requireGit,
55
+ statusDirty,
56
+ statusTracked,
57
+ topLevel,
58
+ worktreeList,
59
+ } from "../git.ts";
60
+ import {
61
+ commonGitDir,
62
+ FlowRegistrySchemaError,
63
+ readRegistry,
64
+ STALE_AFTER_HOURS,
65
+ type FlowRegistryEntry,
66
+ } from "../registry.ts";
67
+ import { primaryWorktree } from "../worktree-path.ts";
68
+
69
+ export interface FlowBranchStatus {
70
+ name: string;
71
+ registered: boolean;
72
+ kind: "session" | "task" | "fix" | null;
73
+ worktree: string | null;
74
+ worktreeExists: boolean;
75
+ /** Tracked-modification count in the worktree; null when no worktree exists. */
76
+ dirty: number | null;
77
+ aheadOfDevelop: number | null;
78
+ behindDevelop: number | null;
79
+ lastCommitAt: string | null;
80
+ stale: boolean;
81
+ /** Held payload (RFC-1491) — the branch is parked, worktree intentionally absent. */
82
+ held: { heldAt: string; riskCategory: string; reason: string; tip: string } | null;
83
+ /** Back-merge port payload when the entry is a port branch (RFC-1490). */
84
+ port: { mainSha: string; tags: string[] } | null;
85
+ }
86
+
87
+ export interface FlowStatusData {
88
+ primary: { path: string; branch: string | null; clean: boolean };
89
+ branches: FlowBranchStatus[];
90
+ }
91
+
92
+ export interface FlowStatusOutcome {
93
+ data: FlowStatusData;
94
+ diagnostics: Diagnostic[];
95
+ /** Registry entries whose branch ref is missing (FLOW-07 material). */
96
+ missingBranchEntries: FlowRegistryEntry[];
97
+ /** Registry entries whose worktree is absent on disk (FLOW-07 material). */
98
+ missingWorktreeEntries: FlowRegistryEntry[];
99
+ /** auto/* worktree paths with no registry entry (FLOW-07 material). */
100
+ unregisteredWorktrees: string[];
101
+ /**
102
+ * RFC-1498: local auto/* branch names with no registry entry and no
103
+ * worktree checkout anywhere — the shape a failed `branch -D` leaves
104
+ * behind. Reported regardless of age (FLOW-06's 72 h rule only covers
105
+ * staleness).
106
+ */
107
+ unregisteredBranchesWithoutWorktree: string[];
108
+ registryError: FlowRegistrySchemaError | null;
109
+ }
110
+
111
+ /**
112
+ * Collect the registry/git/worktree view. `now` is injectable for
113
+ * deterministic stale evaluation. A schema-invalid registry reports
114
+ * `registryError` (FLOW-07 error) and an empty branch list — never rewritten.
115
+ */
116
+ export async function collectFlowStatus(
117
+ repoRoot: string,
118
+ io: WorkspaceIO,
119
+ opts?: { now?: Date },
120
+ ): Promise<FlowStatusOutcome> {
121
+ const now = opts?.now ?? new Date();
122
+ const staleBeforeMs = now.getTime() - STALE_AFTER_HOURS * 3_600_000;
123
+
124
+ const diagnostics: Diagnostic[] = [];
125
+ const primary = await primaryWorktree(io, repoRoot);
126
+ const [primaryBranch, primaryDirty, worktrees, local] = await Promise.all([
127
+ currentBranch(primary, io),
128
+ statusTracked(primary, io),
129
+ worktreeList(repoRoot, io),
130
+ listLocalBranches(repoRoot, io),
131
+ ]);
132
+
133
+ const common = await commonGitDir(io, repoRoot);
134
+ let entries: FlowRegistryEntry[] = [];
135
+ let registryError: FlowRegistrySchemaError | null = null;
136
+ try {
137
+ entries = (await readRegistry(io, common)).branches;
138
+ } catch (error) {
139
+ if (error instanceof FlowRegistrySchemaError) registryError = error;
140
+ else throw error;
141
+ }
142
+
143
+ const developExists = (await git(repoRoot, io, ["rev-parse", "--verify", "-q", "refs/heads/develop"])).exitCode === 0;
144
+ const worktreeByBranch = new Map(
145
+ worktrees.filter((w) => w.branch !== null).map((w) => [w.branch as string, w.path]),
146
+ );
147
+ const entryByName = new Map(entries.map((e) => [e.name, e]));
148
+
149
+ const autoBranches = local.filter((n) => parseFlowBranch(n) !== null);
150
+ const names = new Set<string>([...autoBranches, ...entries.map((e) => e.name)]);
151
+
152
+ const missingBranchEntries: FlowRegistryEntry[] = [];
153
+ const missingWorktreeEntries: FlowRegistryEntry[] = [];
154
+ const unregisteredWorktrees = worktrees
155
+ .filter((w) => w.branch !== null && parseFlowBranch(w.branch) !== null && !entryByName.has(w.branch))
156
+ .filter((w) => w.path !== primary)
157
+ .map((w) => w.path);
158
+
159
+ // RFC-1498: a stray is a local auto branch nothing owns — no registry
160
+ // entry and no worktree (primary or linked) checks it out.
161
+ const unregisteredBranchesWithoutWorktree = autoBranches
162
+ .filter((name) => !entryByName.has(name) && !worktreeByBranch.has(name))
163
+ .sort();
164
+
165
+ const branches: FlowBranchStatus[] = [];
166
+ for (const name of [...names].sort()) {
167
+ const entry = entryByName.get(name);
168
+ const branchRefExists = autoBranches.includes(name);
169
+ const worktree = worktreeByBranch.get(name) ?? entry?.worktree ?? null;
170
+ const worktreeExists = worktree !== null && (await io.exists(worktree));
171
+
172
+ if (entry && !branchRefExists) missingBranchEntries.push(entry);
173
+ // A held entry's null worktree is its expected state — never a FLOW-07
174
+ // disagreement (AUDIT-RFC-1491-C1). Held-with-worktree or unheld-without
175
+ // is rejected by the registry schema, surfacing as registryError.
176
+ if (entry && !worktreeExists && entry.held === null) missingWorktreeEntries.push(entry);
177
+
178
+ const last = branchRefExists ? await lastCommitAt(repoRoot, io, name) : null;
179
+ let ahead: number | null = null;
180
+ let behind: number | null = null;
181
+ if (branchRefExists && developExists) {
182
+ const counts = await git(repoRoot, io, [
183
+ "rev-list",
184
+ "--left-right",
185
+ "--count",
186
+ `develop...${name}`,
187
+ ]);
188
+ const [behindStr, aheadStr] = counts.stdout.trim().split(/\s+/);
189
+ behind = Number(behindStr) || 0;
190
+ ahead = Number(aheadStr) || 0;
191
+ }
192
+ const dirty = worktreeExists ? (await statusDirty(worktree, io)).length : null;
193
+
194
+ const held = entry?.held ?? null;
195
+ let stale = false;
196
+ if (held === null) {
197
+ if (entry) {
198
+ const newest = [last, entry.updatedAt]
199
+ .filter((t): t is string => t !== null)
200
+ .map((t) => Date.parse(t))
201
+ .reduce((a, b) => Math.max(a, b), 0);
202
+ stale = newest > 0 && newest < staleBeforeMs;
203
+ } else if (last !== null) {
204
+ stale = Date.parse(last) < staleBeforeMs;
205
+ }
206
+ }
207
+
208
+ branches.push({
209
+ name,
210
+ registered: entry !== undefined,
211
+ kind: entry?.kind ?? parseFlowBranch(name)?.kind ?? null,
212
+ worktree,
213
+ worktreeExists,
214
+ dirty,
215
+ aheadOfDevelop: ahead,
216
+ behindDevelop: behind,
217
+ lastCommitAt: last,
218
+ stale,
219
+ held,
220
+ port: entry?.port ?? null,
221
+ });
222
+ }
223
+
224
+ return {
225
+ data: {
226
+ primary: { path: primary, branch: primaryBranch, clean: primaryDirty.length === 0 },
227
+ branches,
228
+ },
229
+ diagnostics,
230
+ missingBranchEntries,
231
+ missingWorktreeEntries,
232
+ unregisteredWorktrees,
233
+ unregisteredBranchesWithoutWorktree,
234
+ registryError,
235
+ };
236
+ }
237
+
238
+ export async function runFlowStatus(
239
+ input: ForgeCommandInput,
240
+ context: ForgeRuntimeContext,
241
+ ): Promise<ForgeCommandResult<FlowStatusData & { diagnostics: Diagnostic[] }>> {
242
+ const { workspaceRoot, logger, outputFormat } = context;
243
+ const io = resolveIo(context.io);
244
+ await requireGit(io);
245
+
246
+ const repoRoot = await topLevel(workspaceRoot, io);
247
+ if (repoRoot === null) {
248
+ throw new Error("flow.status must run inside a git repository");
249
+ }
250
+
251
+ const outcome = await collectFlowStatus(repoRoot, io);
252
+ if (outcome.registryError) {
253
+ outcome.diagnostics.push({
254
+ ruleId: "FLOW-07",
255
+ severity: "error",
256
+ message: outcome.registryError.message,
257
+ fixHint: `repair or remove ${outcome.registryError.file}`,
258
+ });
259
+ }
260
+
261
+ if (outputFormat === "pretty") {
262
+ logger.section("flow.status");
263
+ logger.info(
264
+ ` primary: ${outcome.data.primary.path} on ${outcome.data.primary.branch ?? "detached"} (${outcome.data.primary.clean ? "clean" : "dirty"})`,
265
+ );
266
+ for (const b of outcome.data.branches) {
267
+ logger.info(
268
+ b.held !== null
269
+ ? ` ${b.name}: held (${b.held.riskCategory}): ${b.held.reason}`
270
+ : ` ${b.name}: ${b.registered ? "registered" : "unregistered"}, worktree ${b.worktreeExists ? "present" : "absent"}, dirty ${b.dirty ?? "-"}, +${b.aheadOfDevelop ?? "-"}/-${b.behindDevelop ?? "-"}, stale ${b.stale}`,
271
+ );
272
+ }
273
+ for (const d of outcome.diagnostics) {
274
+ logger.error(` ${d.ruleId}: ${d.message}`);
275
+ }
276
+ }
277
+
278
+ return {
279
+ data: { ...outcome.data, diagnostics: outcome.diagnostics },
280
+ exitCode: outcome.diagnostics.some((d) => d.severity === "error") ? 1 : 0,
281
+ summary: `[flow.status] ${outcome.data.branches.length} auto branch(es), ${outcome.data.branches.filter((b) => b.stale).length} stale`,
282
+ };
283
+ }