@warpgogol/forge 9.3.1 → 9.4.0

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 (467) hide show
  1. package/AGENTS.md +32 -0
  2. package/CHANGELOG.md +25 -0
  3. package/README.md +2 -2
  4. package/bin/cli.ts +4 -4
  5. package/dist/bin/cli.js +4 -4
  6. package/dist/bin/cli.js.map +1 -1
  7. package/dist/os/adr/handlers/list-create.d.ts.map +1 -1
  8. package/dist/os/adr/handlers/list-create.js +23 -2
  9. package/dist/os/adr/handlers/list-create.js.map +1 -1
  10. package/dist/os/adr/types.d.ts +2 -0
  11. package/dist/os/adr/types.d.ts.map +1 -1
  12. package/dist/os/adr/types.js +2 -2
  13. package/dist/os/adr/types.js.map +1 -1
  14. package/dist/os/compass/handlers/compass-audit-handler.d.ts.map +1 -1
  15. package/dist/os/compass/handlers/compass-audit-handler.js +3 -1
  16. package/dist/os/compass/handlers/compass-audit-handler.js.map +1 -1
  17. package/dist/os/compass/handlers/compass-header-scaffold-handler.d.ts.map +1 -1
  18. package/dist/os/compass/handlers/compass-header-scaffold-handler.js +6 -12
  19. package/dist/os/compass/handlers/compass-header-scaffold-handler.js.map +1 -1
  20. package/dist/os/compass/handlers/git-revision.d.ts +2 -0
  21. package/dist/os/compass/handlers/git-revision.d.ts.map +1 -1
  22. package/dist/os/compass/handlers/git-revision.js +7 -2
  23. package/dist/os/compass/handlers/git-revision.js.map +1 -1
  24. package/dist/os/compass/handlers/summary-record.d.ts.map +1 -1
  25. package/dist/os/compass/handlers/summary-record.js +24 -14
  26. package/dist/os/compass/handlers/summary-record.js.map +1 -1
  27. package/dist/os/conformance/conformance.module.d.ts.map +1 -1
  28. package/dist/os/conformance/conformance.module.js +21 -4
  29. package/dist/os/conformance/conformance.module.js.map +1 -1
  30. package/dist/os/conformance/handlers/conformance-validate.d.ts.map +1 -1
  31. package/dist/os/conformance/handlers/conformance-validate.js +64 -8
  32. package/dist/os/conformance/handlers/conformance-validate.js.map +1 -1
  33. package/dist/os/core/archive-regen.d.ts +99 -0
  34. package/dist/os/core/archive-regen.d.ts.map +1 -0
  35. package/dist/os/core/archive-regen.js +220 -0
  36. package/dist/os/core/archive-regen.js.map +1 -0
  37. package/dist/os/core/core.module.d.ts.map +1 -1
  38. package/dist/os/core/core.module.js +159 -18
  39. package/dist/os/core/core.module.js.map +1 -1
  40. package/dist/os/core/handlers/assets-helpers.d.ts.map +1 -1
  41. package/dist/os/core/handlers/assets-helpers.js +8 -3
  42. package/dist/os/core/handlers/assets-helpers.js.map +1 -1
  43. package/dist/os/core/handlers/forge-autonomy-validate.d.ts.map +1 -1
  44. package/dist/os/core/handlers/forge-autonomy-validate.js +3 -1
  45. package/dist/os/core/handlers/forge-autonomy-validate.js.map +1 -1
  46. package/dist/os/core/handlers/package-health.d.ts +130 -0
  47. package/dist/os/core/handlers/package-health.d.ts.map +1 -1
  48. package/dist/os/core/handlers/package-health.js +548 -7
  49. package/dist/os/core/handlers/package-health.js.map +1 -1
  50. package/dist/os/core/handlers/release-prepare.d.ts.map +1 -1
  51. package/dist/os/core/handlers/release-prepare.js +5 -2
  52. package/dist/os/core/handlers/release-prepare.js.map +1 -1
  53. package/dist/os/flow/digest.d.ts.map +1 -1
  54. package/dist/os/flow/digest.js +3 -1
  55. package/dist/os/flow/digest.js.map +1 -1
  56. package/dist/os/flow/dirty-classify.d.ts +48 -0
  57. package/dist/os/flow/dirty-classify.d.ts.map +1 -0
  58. package/dist/os/flow/dirty-classify.js +81 -0
  59. package/dist/os/flow/dirty-classify.js.map +1 -0
  60. package/dist/os/flow/flow.module.d.ts.map +1 -1
  61. package/dist/os/flow/flow.module.js +85 -19
  62. package/dist/os/flow/flow.module.js.map +1 -1
  63. package/dist/os/flow/gate-engine.d.ts +13 -0
  64. package/dist/os/flow/gate-engine.d.ts.map +1 -0
  65. package/dist/os/flow/gate-engine.js +32 -0
  66. package/dist/os/flow/gate-engine.js.map +1 -0
  67. package/dist/os/flow/git.d.ts +45 -4
  68. package/dist/os/flow/git.d.ts.map +1 -1
  69. package/dist/os/flow/git.js +95 -27
  70. package/dist/os/flow/git.js.map +1 -1
  71. package/dist/os/flow/handlers/flow-backmerge.d.ts.map +1 -1
  72. package/dist/os/flow/handlers/flow-backmerge.js +12 -5
  73. package/dist/os/flow/handlers/flow-backmerge.js.map +1 -1
  74. package/dist/os/flow/handlers/flow-check.d.ts.map +1 -1
  75. package/dist/os/flow/handlers/flow-check.js +25 -3
  76. package/dist/os/flow/handlers/flow-check.js.map +1 -1
  77. package/dist/os/flow/handlers/flow-cut.d.ts +4 -1
  78. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
  79. package/dist/os/flow/handlers/flow-cut.js +54 -31
  80. package/dist/os/flow/handlers/flow-cut.js.map +1 -1
  81. package/dist/os/flow/handlers/flow-discard.d.ts.map +1 -1
  82. package/dist/os/flow/handlers/flow-discard.js +33 -5
  83. package/dist/os/flow/handlers/flow-discard.js.map +1 -1
  84. package/dist/os/flow/handlers/flow-fix.d.ts.map +1 -1
  85. package/dist/os/flow/handlers/flow-fix.js +13 -10
  86. package/dist/os/flow/handlers/flow-fix.js.map +1 -1
  87. package/dist/os/flow/handlers/flow-hold.d.ts.map +1 -1
  88. package/dist/os/flow/handlers/flow-hold.js +13 -7
  89. package/dist/os/flow/handlers/flow-hold.js.map +1 -1
  90. package/dist/os/flow/handlers/flow-install.d.ts +2 -1
  91. package/dist/os/flow/handlers/flow-install.d.ts.map +1 -1
  92. package/dist/os/flow/handlers/flow-install.js +56 -13
  93. package/dist/os/flow/handlers/flow-install.js.map +1 -1
  94. package/dist/os/flow/handlers/flow-integrate.d.ts +48 -2
  95. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
  96. package/dist/os/flow/handlers/flow-integrate.js +536 -65
  97. package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
  98. package/dist/os/flow/handlers/flow-open.d.ts +14 -0
  99. package/dist/os/flow/handlers/flow-open.d.ts.map +1 -1
  100. package/dist/os/flow/handlers/flow-open.js +117 -12
  101. package/dist/os/flow/handlers/flow-open.js.map +1 -1
  102. package/dist/os/flow/handlers/flow-status.d.ts +13 -0
  103. package/dist/os/flow/handlers/flow-status.d.ts.map +1 -1
  104. package/dist/os/flow/handlers/flow-status.js +35 -14
  105. package/dist/os/flow/handlers/flow-status.js.map +1 -1
  106. package/dist/os/flow/index.d.ts +1 -0
  107. package/dist/os/flow/index.d.ts.map +1 -1
  108. package/dist/os/flow/index.js +3 -1
  109. package/dist/os/flow/index.js.map +1 -1
  110. package/dist/os/flow/line-version.d.ts.map +1 -1
  111. package/dist/os/flow/line-version.js +2 -1
  112. package/dist/os/flow/line-version.js.map +1 -1
  113. package/dist/os/flow/locks.d.ts +37 -1
  114. package/dist/os/flow/locks.d.ts.map +1 -1
  115. package/dist/os/flow/locks.js +34 -14
  116. package/dist/os/flow/locks.js.map +1 -1
  117. package/dist/os/flow/preflight.d.ts +114 -0
  118. package/dist/os/flow/preflight.d.ts.map +1 -0
  119. package/dist/os/flow/preflight.js +620 -0
  120. package/dist/os/flow/preflight.js.map +1 -0
  121. package/dist/os/flow/publish.d.ts +7 -0
  122. package/dist/os/flow/publish.d.ts.map +1 -1
  123. package/dist/os/flow/publish.js +165 -3
  124. package/dist/os/flow/publish.js.map +1 -1
  125. package/dist/os/flow/registry.d.ts +26 -1
  126. package/dist/os/flow/registry.d.ts.map +1 -1
  127. package/dist/os/flow/registry.js +27 -6
  128. package/dist/os/flow/registry.js.map +1 -1
  129. package/dist/os/flow/scripts.d.ts +4 -0
  130. package/dist/os/flow/scripts.d.ts.map +1 -1
  131. package/dist/os/flow/scripts.js +8 -2
  132. package/dist/os/flow/scripts.js.map +1 -1
  133. package/dist/os/flow/session-checkout.d.ts +33 -0
  134. package/dist/os/flow/session-checkout.d.ts.map +1 -0
  135. package/dist/os/flow/session-checkout.js +151 -0
  136. package/dist/os/flow/session-checkout.js.map +1 -0
  137. package/dist/os/flow/worktree-path.d.ts.map +1 -1
  138. package/dist/os/flow/worktree-path.js +9 -3
  139. package/dist/os/flow/worktree-path.js.map +1 -1
  140. package/dist/os/instructions/handlers/budget-validate.d.ts +1 -0
  141. package/dist/os/instructions/handlers/budget-validate.d.ts.map +1 -1
  142. package/dist/os/instructions/handlers/budget-validate.js +12 -4
  143. package/dist/os/instructions/handlers/budget-validate.js.map +1 -1
  144. package/dist/os/instructions/instructions.module.d.ts.map +1 -1
  145. package/dist/os/instructions/instructions.module.js +4 -1
  146. package/dist/os/instructions/instructions.module.js.map +1 -1
  147. package/dist/os/mission/open-missions.d.ts +8 -0
  148. package/dist/os/mission/open-missions.d.ts.map +1 -0
  149. package/dist/os/mission/open-missions.js +42 -0
  150. package/dist/os/mission/open-missions.js.map +1 -0
  151. package/dist/os/queue/manifest.d.ts.map +1 -1
  152. package/dist/os/queue/manifest.js +11 -1
  153. package/dist/os/queue/manifest.js.map +1 -1
  154. package/dist/os/rfc/acceptance.d.ts +14 -0
  155. package/dist/os/rfc/acceptance.d.ts.map +1 -1
  156. package/dist/os/rfc/acceptance.js +18 -10
  157. package/dist/os/rfc/acceptance.js.map +1 -1
  158. package/dist/os/rfc/decision-log.d.ts.map +1 -1
  159. package/dist/os/rfc/decision-log.js +11 -2
  160. package/dist/os/rfc/decision-log.js.map +1 -1
  161. package/dist/os/rfc/frontmatter-io.d.ts +23 -0
  162. package/dist/os/rfc/frontmatter-io.d.ts.map +1 -1
  163. package/dist/os/rfc/frontmatter-io.js +82 -1
  164. package/dist/os/rfc/frontmatter-io.js.map +1 -1
  165. package/dist/os/rfc/handlers/implement-stamp-deviations.d.ts.map +1 -1
  166. package/dist/os/rfc/handlers/implement-stamp-deviations.js +24 -2
  167. package/dist/os/rfc/handlers/implement-stamp-deviations.js.map +1 -1
  168. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  169. package/dist/os/rfc/handlers/implement-stamp.js +16 -3
  170. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  171. package/dist/os/rfc/handlers/index-graph.d.ts.map +1 -1
  172. package/dist/os/rfc/handlers/index-graph.js +5 -4
  173. package/dist/os/rfc/handlers/index-graph.js.map +1 -1
  174. package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
  175. package/dist/os/rfc/handlers/list-create.js +83 -8
  176. package/dist/os/rfc/handlers/list-create.js.map +1 -1
  177. package/dist/os/rfc/handlers/rfc-evidence-sync.d.ts +48 -0
  178. package/dist/os/rfc/handlers/rfc-evidence-sync.d.ts.map +1 -1
  179. package/dist/os/rfc/handlers/rfc-evidence-sync.js +131 -2
  180. package/dist/os/rfc/handlers/rfc-evidence-sync.js.map +1 -1
  181. package/dist/os/rfc/handlers/validate-rules.d.ts +21 -1
  182. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  183. package/dist/os/rfc/handlers/validate-rules.js +77 -5
  184. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  185. package/dist/os/rfc/handlers/validate.d.ts.map +1 -1
  186. package/dist/os/rfc/handlers/validate.js +64 -6
  187. package/dist/os/rfc/handlers/validate.js.map +1 -1
  188. package/dist/os/rfc/next-id.d.ts +38 -0
  189. package/dist/os/rfc/next-id.d.ts.map +1 -0
  190. package/dist/os/rfc/next-id.js +165 -0
  191. package/dist/os/rfc/next-id.js.map +1 -0
  192. package/dist/os/rfc/probe-batch.d.ts.map +1 -1
  193. package/dist/os/rfc/probe-batch.js +6 -1
  194. package/dist/os/rfc/probe-batch.js.map +1 -1
  195. package/dist/os/rfc/rfc.module.d.ts.map +1 -1
  196. package/dist/os/rfc/rfc.module.js +36 -8
  197. package/dist/os/rfc/rfc.module.js.map +1 -1
  198. package/dist/os/rfc/types.d.ts +35 -6
  199. package/dist/os/rfc/types.d.ts.map +1 -1
  200. package/dist/os/rfc/types.js +6 -6
  201. package/dist/os/rfc/types.js.map +1 -1
  202. package/dist/os/rfc/verification-evidence.d.ts +1 -1
  203. package/dist/os/rfc/verification-evidence.d.ts.map +1 -1
  204. package/dist/os/rfc/verification-evidence.js +81 -28
  205. package/dist/os/rfc/verification-evidence.js.map +1 -1
  206. package/dist/os/rfc/verification-origin.d.ts +8 -0
  207. package/dist/os/rfc/verification-origin.d.ts.map +1 -1
  208. package/dist/os/rfc/verification-origin.js +47 -0
  209. package/dist/os/rfc/verification-origin.js.map +1 -1
  210. package/dist/os/session/handlers/save.d.ts.map +1 -1
  211. package/dist/os/session/handlers/save.js +31 -7
  212. package/dist/os/session/handlers/save.js.map +1 -1
  213. package/dist/os/spec/spec-schema.d.ts +8 -0
  214. package/dist/os/spec/spec-schema.d.ts.map +1 -1
  215. package/dist/os/spec/spec-schema.js +1 -0
  216. package/dist/os/spec/spec-schema.js.map +1 -1
  217. package/dist/os/spec/spec-status.d.ts +8 -0
  218. package/dist/os/spec/spec-status.d.ts.map +1 -1
  219. package/dist/os/spec/spec-status.js +18 -6
  220. package/dist/os/spec/spec-status.js.map +1 -1
  221. package/dist/os/spec/spec-validate.d.ts.map +1 -1
  222. package/dist/os/spec/spec-validate.js +62 -15
  223. package/dist/os/spec/spec-validate.js.map +1 -1
  224. package/dist/os/spec/spec.module.d.ts.map +1 -1
  225. package/dist/os/spec/spec.module.js +13 -5
  226. package/dist/os/spec/spec.module.js.map +1 -1
  227. package/dist/os/system/handlers/system-map-validate.d.ts.map +1 -1
  228. package/dist/os/system/handlers/system-map-validate.js +2 -1
  229. package/dist/os/system/handlers/system-map-validate.js.map +1 -1
  230. package/dist/os/system/handlers/system-outbox-scan.d.ts +11 -0
  231. package/dist/os/system/handlers/system-outbox-scan.d.ts.map +1 -1
  232. package/dist/os/system/handlers/system-outbox-scan.js +54 -6
  233. package/dist/os/system/handlers/system-outbox-scan.js.map +1 -1
  234. package/dist/os/system/handlers/system-task-create.d.ts.map +1 -1
  235. package/dist/os/system/handlers/system-task-create.js +6 -1
  236. package/dist/os/system/handlers/system-task-create.js.map +1 -1
  237. package/dist/os/system/handlers/system-versionset-record.d.ts +14 -0
  238. package/dist/os/system/handlers/system-versionset-record.d.ts.map +1 -1
  239. package/dist/os/system/handlers/system-versionset-record.js +246 -6
  240. package/dist/os/system/handlers/system-versionset-record.js.map +1 -1
  241. package/dist/os/system/repo.d.ts +1 -1
  242. package/dist/os/system/repo.d.ts.map +1 -1
  243. package/dist/os/system/repo.js +53 -3
  244. package/dist/os/system/repo.js.map +1 -1
  245. package/dist/os/system/scenario-schemas.d.ts +109 -3
  246. package/dist/os/system/scenario-schemas.d.ts.map +1 -1
  247. package/dist/os/system/scenario-schemas.js +66 -10
  248. package/dist/os/system/scenario-schemas.js.map +1 -1
  249. package/dist/os/system/system.module.d.ts.map +1 -1
  250. package/dist/os/system/system.module.js +69 -17
  251. package/dist/os/system/system.module.js.map +1 -1
  252. package/dist/os/system/tests/contract-fixtures.d.ts +17 -0
  253. package/dist/os/system/tests/contract-fixtures.d.ts.map +1 -0
  254. package/dist/os/system/tests/contract-fixtures.js +109 -0
  255. package/dist/os/system/tests/contract-fixtures.js.map +1 -0
  256. package/dist/src/config/forge-config.d.ts +54 -18
  257. package/dist/src/config/forge-config.d.ts.map +1 -1
  258. package/dist/src/config/forge-config.js +41 -9
  259. package/dist/src/config/forge-config.js.map +1 -1
  260. package/dist/src/conformance/index.d.ts +6 -0
  261. package/dist/src/conformance/index.d.ts.map +1 -1
  262. package/dist/src/conformance/index.js +36 -1
  263. package/dist/src/conformance/index.js.map +1 -1
  264. package/dist/src/formal/proof-runner.d.ts.map +1 -1
  265. package/dist/src/formal/proof-runner.js +10 -2
  266. package/dist/src/formal/proof-runner.js.map +1 -1
  267. package/dist/src/migration-adapters/node-typescript-pnpm/index.js +3 -1
  268. package/dist/src/migration-adapters/node-typescript-pnpm/index.js.map +1 -1
  269. package/dist/src/migration-adapters/phaser-pnpm/index.js +3 -1
  270. package/dist/src/migration-adapters/phaser-pnpm/index.js.map +1 -1
  271. package/dist/src/onboarding/agents-generate.js +4 -4
  272. package/dist/src/onboarding/agents-generate.js.map +1 -1
  273. package/dist/src/onboarding/nested-agents-generate.d.ts.map +1 -1
  274. package/dist/src/onboarding/nested-agents-generate.js +3 -1
  275. package/dist/src/onboarding/nested-agents-generate.js.map +1 -1
  276. package/dist/src/onboarding/scaffold-project.js +2 -2
  277. package/dist/src/onboarding/scaffold-project.js.map +1 -1
  278. package/dist/src/onboarding/upgrade.d.ts.map +1 -1
  279. package/dist/src/onboarding/upgrade.js +14 -2
  280. package/dist/src/onboarding/upgrade.js.map +1 -1
  281. package/dist/src/onboarding/workspace-discovery.d.ts.map +1 -1
  282. package/dist/src/onboarding/workspace-discovery.js +3 -1
  283. package/dist/src/onboarding/workspace-discovery.js.map +1 -1
  284. package/dist/src/skill-schema.d.ts +3 -0
  285. package/dist/src/skill-schema.d.ts.map +1 -1
  286. package/dist/src/skill-schema.js +9 -2
  287. package/dist/src/skill-schema.js.map +1 -1
  288. package/dist/src/spec/resolve-spec-source.d.ts +45 -0
  289. package/dist/src/spec/resolve-spec-source.d.ts.map +1 -0
  290. package/dist/src/spec/resolve-spec-source.js +153 -0
  291. package/dist/src/spec/resolve-spec-source.js.map +1 -0
  292. package/dist/src/utils/command-inventory.d.ts +28 -0
  293. package/dist/src/utils/command-inventory.d.ts.map +1 -0
  294. package/dist/src/utils/command-inventory.js +84 -0
  295. package/dist/src/utils/command-inventory.js.map +1 -0
  296. package/dist/src/utils/io.d.ts.map +1 -1
  297. package/dist/src/utils/io.js +6 -1
  298. package/dist/src/utils/io.js.map +1 -1
  299. package/dist/src/utils/repo-path.d.ts +10 -0
  300. package/dist/src/utils/repo-path.d.ts.map +1 -0
  301. package/dist/src/utils/repo-path.js +52 -0
  302. package/dist/src/utils/repo-path.js.map +1 -0
  303. package/dist/src/utils/spawn.d.ts +23 -0
  304. package/dist/src/utils/spawn.d.ts.map +1 -0
  305. package/dist/src/utils/spawn.js +83 -0
  306. package/dist/src/utils/spawn.js.map +1 -0
  307. package/docs/branch-model.md +1 -1
  308. package/docs/guides/existing-project.md +1 -1
  309. package/docs/maintainers/publishing.md +1 -1
  310. package/docs/reference/cli.md +8 -2
  311. package/docs/reference/profiles.md +1 -1
  312. package/os/adr/handlers/list-create.ts +26 -2
  313. package/os/adr/types.ts +4 -2
  314. package/os/compass/handlers/compass-audit-handler.ts +6 -1
  315. package/os/compass/handlers/compass-header-scaffold-handler.ts +12 -11
  316. package/os/compass/handlers/git-revision.ts +8 -2
  317. package/os/compass/handlers/summary-record.ts +25 -14
  318. package/os/compass/handlers/tests/compass-invariant-binding.test.ts +3 -2
  319. package/os/conformance/conformance.module.ts +21 -4
  320. package/os/conformance/handlers/conformance-validate.ts +108 -16
  321. package/os/conformance/handlers/tests/conformance-package-consumer.test.ts +200 -0
  322. package/os/core/archive-regen.ts +279 -0
  323. package/os/core/core.module.ts +176 -29
  324. package/os/core/docs-archive.test.ts +413 -3
  325. package/os/core/handlers/assets-helpers.ts +8 -3
  326. package/os/core/handlers/forge-autonomy-validate.ts +3 -1
  327. package/os/core/handlers/package-health.test.ts +418 -4
  328. package/os/core/handlers/package-health.ts +629 -7
  329. package/os/core/handlers/release-prepare.ts +5 -2
  330. package/os/flow/digest.ts +3 -1
  331. package/os/flow/dirty-classify.ts +112 -0
  332. package/os/flow/flow.module.ts +92 -24
  333. package/os/flow/gate-engine.ts +45 -0
  334. package/os/flow/git.ts +117 -29
  335. package/os/flow/handlers/flow-backmerge.ts +14 -4
  336. package/os/flow/handlers/flow-check.ts +27 -2
  337. package/os/flow/handlers/flow-cut.ts +97 -46
  338. package/os/flow/handlers/flow-discard.ts +33 -5
  339. package/os/flow/handlers/flow-fix.ts +22 -10
  340. package/os/flow/handlers/flow-hold.ts +20 -7
  341. package/os/flow/handlers/flow-install.ts +59 -12
  342. package/os/flow/handlers/flow-integrate.ts +808 -182
  343. package/os/flow/handlers/flow-open.ts +135 -11
  344. package/os/flow/handlers/flow-status.ts +45 -13
  345. package/os/flow/index.ts +3 -1
  346. package/os/flow/line-version.ts +2 -1
  347. package/os/flow/locks.ts +56 -14
  348. package/os/flow/preflight.ts +763 -0
  349. package/os/flow/publish.ts +200 -5
  350. package/os/flow/registry.ts +43 -7
  351. package/os/flow/scripts.ts +13 -2
  352. package/os/flow/session-checkout.ts +186 -0
  353. package/os/flow/tests/dirty-classify.test.ts +116 -0
  354. package/os/flow/tests/fixtures/branch-names.yaml +40 -40
  355. package/os/flow/tests/flow-discard.test.ts +32 -0
  356. package/os/flow/tests/flow-guard-parity.test.ts +10 -2
  357. package/os/flow/tests/flow-install.test.ts +7 -3
  358. package/os/flow/tests/flow-integrate.gate-report.test.ts +144 -0
  359. package/os/flow/tests/flow-integrate.preflight.test.ts +561 -0
  360. package/os/flow/tests/flow-integrate.reattach.test.ts +197 -0
  361. package/os/flow/tests/flow-integrate.remediation.test.ts +254 -0
  362. package/os/flow/tests/flow-integrate.test.ts +348 -17
  363. package/os/flow/tests/flow-open.pending.test.ts +277 -0
  364. package/os/flow/tests/flow-open.test.ts +52 -9
  365. package/os/flow/tests/flow-push-publish.test.ts +124 -0
  366. package/os/flow/tests/flow-status.test.ts +31 -1
  367. package/os/flow/tests/locks.test.ts +39 -3
  368. package/os/flow/tests/scripts.test.ts +5 -2
  369. package/os/flow/tests/state-roots.test.ts +8 -5
  370. package/os/flow/worktree-path.ts +9 -3
  371. package/os/formal/handlers/proof-check.test.ts +6 -3
  372. package/os/instructions/budget.test.ts +31 -0
  373. package/os/instructions/handlers/budget-validate.ts +13 -4
  374. package/os/instructions/instructions.module.ts +4 -1
  375. package/os/mission/open-missions.ts +50 -0
  376. package/os/queue/decision-ledger.test.ts +18 -0
  377. package/os/queue/manifest.ts +17 -1
  378. package/os/rfc/acceptance.ts +30 -10
  379. package/os/rfc/decision-log.ts +13 -2
  380. package/os/rfc/frontmatter-io.ts +89 -1
  381. package/os/rfc/handlers/implement-stamp-deviations.test.ts +83 -0
  382. package/os/rfc/handlers/implement-stamp-deviations.ts +22 -2
  383. package/os/rfc/handlers/implement-stamp-stale.test.ts +5 -1
  384. package/os/rfc/handlers/implement-stamp.ts +16 -3
  385. package/os/rfc/handlers/index-graph.ts +5 -4
  386. package/os/rfc/handlers/lifecycle.test.ts +136 -0
  387. package/os/rfc/handlers/list-create.test.ts +82 -0
  388. package/os/rfc/handlers/list-create.ts +101 -8
  389. package/os/rfc/handlers/rfc-evidence-sync.test.ts +504 -0
  390. package/os/rfc/handlers/rfc-evidence-sync.ts +192 -2
  391. package/os/rfc/handlers/tests/index-graph.test.ts +2 -1
  392. package/os/rfc/handlers/validate-rules-rfc1454.test.ts +73 -0
  393. package/os/rfc/handlers/validate-rules.ts +103 -7
  394. package/os/rfc/handlers/validate.ts +68 -4
  395. package/os/rfc/next-id.ts +232 -0
  396. package/os/rfc/probe-batch.ts +6 -1
  397. package/os/rfc/rfc.module.ts +41 -8
  398. package/os/rfc/types.ts +28 -6
  399. package/os/rfc/verification-emit-freshness.test.ts +5 -1
  400. package/os/rfc/verification-emit.test.ts +5 -1
  401. package/os/rfc/verification-evidence.ts +99 -33
  402. package/os/rfc/verification-origin.ts +59 -0
  403. package/os/rfc/verification-refresh.test.ts +5 -1
  404. package/os/rfc/verifier/rfc-1333/imp12-binding.acceptance.test.ts +5 -1
  405. package/os/session/handlers/save.ts +35 -7
  406. package/os/session/tests/session-save.test.ts +154 -0
  407. package/os/spec/spec-schema.ts +3 -0
  408. package/os/spec/spec-status.ts +22 -6
  409. package/os/spec/spec-validate.package-source.test.ts +187 -0
  410. package/os/spec/spec-validate.ts +65 -14
  411. package/os/spec/spec.module.ts +13 -5
  412. package/os/system/handlers/system-map-validate.ts +4 -2
  413. package/os/system/handlers/system-outbox-scan.ts +65 -21
  414. package/os/system/handlers/system-task-create.ts +6 -1
  415. package/os/system/handlers/system-versionset-record.ts +301 -16
  416. package/os/system/repo.ts +59 -18
  417. package/os/system/scenario-schemas.ts +91 -12
  418. package/os/system/system.module.ts +70 -17
  419. package/os/system/tests/contract-fixtures.ts +139 -0
  420. package/os/system/tests/scenario-pin-drift-check.test.ts +114 -0
  421. package/os/system/tests/scenario-validator-check.test.ts +96 -0
  422. package/os/system/tests/system-task-dispatch.test.ts +4 -1
  423. package/os/system/tests/system-versionset.test.ts +7 -3
  424. package/os/system/tests/version-set-v2.test.ts +78 -0
  425. package/package.json +9 -1
  426. package/skills/fo/fo-doctor/SKILL.md +151 -0
  427. package/skills/fo/fo-handoff/SKILL.md +22 -0
  428. package/skills/fo/fo-idea-create-rfc/acceptance-criteria-standard.md +2 -1
  429. package/skills/fo/fo-idea-implement/SKILL.md +5 -2
  430. package/skills/fo/fo-idea-plan/SKILL.md +5 -5
  431. package/skills/fo/fo-session-retro/SKILL.md +37 -11
  432. package/skills/fo/fo-spec-ingest/SKILL.md +8 -0
  433. package/skills/fo/fo-system-dispatch/SKILL.md +1 -0
  434. package/skills/meta/skill-create/SKILL.md +2 -1
  435. package/src/bin-entry.test.ts +3 -1
  436. package/src/config/forge-config.ts +57 -13
  437. package/src/conformance/index.ts +46 -1
  438. package/src/formal/proof-runner.ts +10 -2
  439. package/src/migration-adapters/node-typescript-pnpm/index.ts +3 -1
  440. package/src/migration-adapters/phaser-pnpm/index.ts +3 -1
  441. package/src/onboarding/agents-generate.ts +4 -4
  442. package/src/onboarding/nested-agents-generate.ts +3 -1
  443. package/src/onboarding/scaffold-project.ts +2 -2
  444. package/src/onboarding/upgrade.ts +13 -2
  445. package/src/onboarding/workspace-discovery.ts +3 -1
  446. package/src/pipeline-status.test.ts +1 -1
  447. package/src/skill-schema.ts +9 -2
  448. package/src/spec/resolve-spec-source.ts +184 -0
  449. package/src/tests/acceptance-probe-kinds.test.ts +3 -1
  450. package/src/tests/agents-generate-domain.test.ts +3 -2
  451. package/src/tests/agents-generate.test.ts +2 -1
  452. package/src/tests/create-flow.test.ts +3 -1
  453. package/src/tests/create.test.ts +12 -2
  454. package/src/tests/editable-generated-region.test.ts +2 -2
  455. package/src/tests/fixtures/agents-generate-business-before.txt +2 -0
  456. package/src/tests/implement-stamp.test.ts +5 -2
  457. package/src/tests/rfc-implement-stamp-governance.test.ts +6 -2
  458. package/src/tests/rfc-verification-verdict-ingest.test.ts +5 -1
  459. package/src/tests/scaffold-project.test.ts +3 -1
  460. package/src/tests/upgrade.test.ts +79 -3
  461. package/src/tests/workspace-discovery.test.ts +4 -3
  462. package/src/utils/command-inventory.ts +105 -0
  463. package/src/utils/io.ts +6 -1
  464. package/src/utils/repo-path.ts +49 -0
  465. package/src/utils/spawn.ts +88 -0
  466. package/src/tests/rfc-evidence-sync.test.ts +0 -369
  467. package/src/tests/skill-agents-sync.test.ts +0 -192
@@ -20,25 +20,28 @@ at cleanup without moving develop again.</purpose>
20
20
  <item>Task-file preservation runs inside the cleanup branch BEFORE the worktree-teardown hook and only for owner.kind task — a `git clean -fdx` teardown would destroy `.forge/task/` first, and a copy failure refuses cleanup (FLOW-INT-04) so the report is never lost with the worktree (RFC-1509 Q-16).</item>
21
21
  </KEY_DECISIONS>
22
22
  <CHANGE_SUMMARY>
23
- <item>RFC-1504: steps 2-3 — holderIsDead, boot-id payload, dead-holder break in withFlowLock</item>
24
- <item>RFC-1509: implement RFC-1509 — system task queue, dispatch briefs and task reports</item>
25
- <item>RFC-1509: record task-file preservation decisions in flow handlers</item>
26
- <item>RFC-1509: close RFC-1509 review r1 findings — mark-failed escape, open-error refusal, dry-run coverage</item>
27
- <item>RFC-1509: record RFC-1509 preserve-before-teardown ordering in key decisions</item>
28
- <history>RFC-1487, RFC-1490, RFC-1491</history>
23
+ <item>RFC-1528: close review findings — manifest-union command inventory for regen/preflight</item>
24
+ <item>RFC-1536: owning-checkout routing, FLOW-OPEN-01 dirty-primary warning, shared governance-id allocation (RFC+ADR)</item>
25
+ <item>RFC-1538: revalidate integration preconditions post-lock and reuse the session engine</item>
26
+ <item>RFC-1531: remediation flags --reattach/--auto-clean/--autocommit on the classified dirty set, FLOW-INT-17 remediation-failure refusals, classified FLOW-INT-01 data</item>
27
+ <item>RFC-1532: persist integration-gate reports per attempt and link them from the flow journal</item>
28
+ <history>RFC-1487, RFC-1490, RFC-1491, RFC-1504, RFC-1509, RFC-1515, RFC-1528, RFC-1537</history>
29
29
  </CHANGE_SUMMARY>
30
30
  */
31
31
  import { resolveIo } from "../../../src/utils/io.js";
32
- import { branchExists, currentBranch, git, isAncestor, requireGit, statusDirty, statusTracked, topLevel, worktreeList, } from "../git.js";
33
- import { LockTimeoutError, withFlowLock } from "../locks.js";
34
- import { appendJournal, commonGitDir, FlowRegistrySchemaError, INTEGRATE_LOCK_RELATIVE_PATH, readRegistry, registryPath, updateRegistry, } from "../registry.js";
32
+ import { AUTO_CLEAN_PASS_CLASSES, SWEEP_COMMIT_SUBJECT, classifyDirtyPath, classifyDirtyTree, summarizeClasses, } from "../dirty-classify.js";
33
+ import { branchExists, currentBranch, git, gitCommit, isAncestor, requireGit, statusDirty, statusTracked, topLevel, worktreeAdd, worktreeList, } from "../git.js";
34
+ import { describeHeldLock, LockTimeoutError, withFlowLock, } from "../locks.js";
35
+ import { appendJournal, readJournal, commonGitDir, FlowRegistrySchemaError, INTEGRATE_LOCK_RELATIVE_PATH, readRegistry, registryPath, updateRegistry, } from "../registry.js";
35
36
  import { runFlowScript } from "../scripts.js";
36
37
  import { preserveTaskFiles } from "../task-files.js";
37
- import { primaryWorktree } from "../worktree-path.js";
38
- import { join } from "node:path";
38
+ import { flowWorktreePath, primaryWorktree } from "../worktree-path.js";
39
+ import { pruneReservationsForSession } from "../../rfc/next-id.js";
40
+ import { rm } from "node:fs/promises";
41
+ import { dirname, join } from "node:path";
39
42
  export const INTEGRATE_LOCK_WAIT_MS = 30 * 60_000;
40
43
  export const INTEGRATE_LOCK_STALE_MS = 2 * 3_600_000;
41
- function refuse(ruleId, message, fixHint, partial) {
44
+ function refuse(ruleId, message, fixHint, partial, diagData) {
42
45
  return {
43
46
  branch: partial?.branch ?? null,
44
47
  integrated: partial?.integrated ?? false,
@@ -47,7 +50,15 @@ function refuse(ruleId, message, fixHint, partial) {
47
50
  rebased: partial?.rebased ?? false,
48
51
  gate: partial?.gate ?? null,
49
52
  cleanedUp: partial?.cleanedUp ?? false,
50
- diagnostics: [{ ruleId, severity: "error", message, fixHint }],
53
+ ...(partial?.toleratedState !== undefined ? { toleratedState: partial.toleratedState } : {}),
54
+ ...(partial?.toleratedDirt !== undefined ? { toleratedDirt: partial.toleratedDirt } : {}),
55
+ ...(partial?.reattachedTo !== undefined ? { reattachedTo: partial.reattachedTo } : {}),
56
+ ...(partial?.autoCleaned !== undefined ? { autoCleaned: partial.autoCleaned } : {}),
57
+ ...(partial?.autocommitSha !== undefined ? { autocommitSha: partial.autocommitSha } : {}),
58
+ ...(partial?.lock !== undefined ? { lock: partial.lock } : {}),
59
+ diagnostics: [
60
+ { ruleId, severity: "error", message, fixHint, ...(diagData ? { data: diagData } : {}) },
61
+ ],
51
62
  };
52
63
  }
53
64
  async function resolveEntry(repoRoot, io, branch) {
@@ -56,9 +67,10 @@ async function resolveEntry(repoRoot, io, branch) {
56
67
  return { common, entry: registry.branches.find((b) => b.name === branch) ?? null };
57
68
  }
58
69
  /** Step 6 — teardown, worktree removal, branch delete, registry, journal. */
59
- async function cleanupIntegrated(primary, worktree, entry, common, sha, io, nowIso, journalEvent = "integrate", journalBase) {
70
+ async function cleanupIntegrated(primary, worktree, entry, common, sha, io, nowIso, journalEvent = "integrate", journalBase, journalToleratedDirt, journalAutoResolved, journalRemediation, journalGateReport) {
60
71
  const branchExistsNow = await branchExists(primary, io, entry.name);
61
72
  let teardownRan = null;
73
+ let toleratedPaths = [];
62
74
  if (worktree !== null && (await io.exists(worktree))) {
63
75
  // RFC-1509 Q-16: preserve BEFORE the teardown hook — a `git clean -fdx`
64
76
  // teardown would destroy .forge/task/ with the rest of the worktree.
@@ -101,6 +113,18 @@ async function cleanupIntegrated(primary, worktree, entry, common, sha, io, nowI
101
113
  ],
102
114
  };
103
115
  }
116
+ // RFC-1515: `statusDirty` predicts `git worktree remove` — allowlisted
117
+ // forge-local state is untracked-not-ignored, so a tolerated-only tree
118
+ // still refuses removal. Delete the tolerated paths first (declared-
119
+ // disposable state; task payloads are already preserved above); a
120
+ // fresh check showing real entries leaves remove to report them.
121
+ const residual = await statusDirty(worktree, io);
122
+ if (residual.entries.length === 0 && residual.toleratedState.length > 0) {
123
+ toleratedPaths = residual.toleratedState;
124
+ for (const rel of residual.toleratedState) {
125
+ await rm(join(worktree, rel), { force: true, recursive: true });
126
+ }
127
+ }
104
128
  const remove = await git(primary, io, ["worktree", "remove", worktree]);
105
129
  if (remove.exitCode !== 0) {
106
130
  return {
@@ -118,7 +142,15 @@ async function cleanupIntegrated(primary, worktree, entry, common, sha, io, nowI
118
142
  }
119
143
  }
120
144
  if (branchExistsNow) {
121
- const del = await git(primary, io, ["branch", "-d", entry.name]);
145
+ // RFC-1515: a vanished worktree leaves a stale `git worktree`
146
+ // registration that pins the branch — prune it before deletion. Merged
147
+ // state is already proven by isAncestor, so `-D` is the verified delete
148
+ // (`-d` re-derives containment in the current worktree context, which
149
+ // the F-0093 *.stale race corrupted).
150
+ if (worktree !== null && !(await io.exists(worktree))) {
151
+ await git(primary, io, ["worktree", "prune"]);
152
+ }
153
+ const del = await git(primary, io, ["branch", "-D", entry.name]);
122
154
  if (del.exitCode !== 0) {
123
155
  return {
124
156
  cleanedUp: false,
@@ -146,6 +178,24 @@ async function cleanupIntegrated(primary, worktree, entry, common, sha, io, nowI
146
178
  sha,
147
179
  detail: journalEvent === "backmerge" ? `back-merged into develop` : `integrated into develop`,
148
180
  base: journalBase,
181
+ ...(toleratedPaths.length > 0 ? { toleratedState: toleratedPaths } : {}),
182
+ ...(journalToleratedDirt !== undefined && journalToleratedDirt.length > 0
183
+ ? { toleratedDirt: journalToleratedDirt }
184
+ : {}),
185
+ ...(journalAutoResolved !== undefined && journalAutoResolved.length > 0
186
+ ? { autoResolved: journalAutoResolved }
187
+ : {}),
188
+ ...(journalRemediation?.reattachedTo !== undefined
189
+ ? { reattachedTo: journalRemediation.reattachedTo }
190
+ : {}),
191
+ ...(journalRemediation?.autoCleaned !== undefined &&
192
+ journalRemediation.autoCleaned.length > 0
193
+ ? { autoCleaned: journalRemediation.autoCleaned }
194
+ : {}),
195
+ ...(journalRemediation?.autocommitSha !== undefined
196
+ ? { autocommitSha: journalRemediation.autocommitSha }
197
+ : {}),
198
+ ...(journalGateReport !== undefined ? { gateReport: journalGateReport } : {}),
149
199
  });
150
200
  }
151
201
  catch (error) {
@@ -170,8 +220,38 @@ async function cleanupIntegrated(primary, worktree, entry, common, sha, io, nowI
170
220
  /**
171
221
  * Core of flow.integrate — callable with an injected clock. Refusal paths
172
222
  * return diagnostics; `integrated`/`cleanedUp` report what really happened.
223
+ * The exported wrapper journals every refusal (RFC-1537); this attempt body
224
+ * stays pure.
173
225
  */
174
226
  export async function integrateFlowBranch(repoRoot, io, opts) {
227
+ const data = await integrateFlowBranchAttempt(repoRoot, io, opts);
228
+ const error = data.diagnostics.find((d) => d.severity === "error");
229
+ if (error !== undefined && data.branch !== null) {
230
+ // Best-effort bookkeeping — a journal write failure never adds a refusal.
231
+ try {
232
+ const common = await commonGitDir(io, repoRoot);
233
+ const sha = (await git(repoRoot, io, ["rev-parse", "--verify", "-q", `refs/heads/${data.branch}`]))
234
+ .stdout.trim() || "unknown";
235
+ await appendJournal(io, common, {
236
+ event: "integrate-refusal",
237
+ branch: data.branch,
238
+ sha,
239
+ detail: error.message,
240
+ rule: error.ruleId,
241
+ ...(data.toleratedState !== undefined ? { toleratedState: data.toleratedState } : {}),
242
+ ...(data.toleratedDirt !== undefined ? { toleratedDirt: data.toleratedDirt } : {}),
243
+ // RFC-1532: the refused attempt's report links here too — the journal
244
+ // answers "which gate report belongs to this refusal" in one field.
245
+ ...(data.gate?.reportPath ? { gateReport: data.gate.reportPath } : {}),
246
+ });
247
+ }
248
+ catch {
249
+ /* journal is audit, not gate */
250
+ }
251
+ }
252
+ return data;
253
+ }
254
+ async function integrateFlowBranchAttempt(repoRoot, io, opts) {
175
255
  const now = opts.now ?? new Date();
176
256
  const branch = opts.branch ?? (await currentBranch(repoRoot, io));
177
257
  if (branch === null) {
@@ -189,6 +269,34 @@ export async function integrateFlowBranch(repoRoot, io, opts) {
189
269
  }
190
270
  const { common, entry } = resolved;
191
271
  if (entry === null) {
272
+ // RFC-1538: a second integrate after a successful one finds no entry —
273
+ // report "already-integrated" (exit 0) instead of FLOW-INT-06 when the
274
+ // journal proves the branch landed or develop already contains its tip.
275
+ let contained = false;
276
+ try {
277
+ const journal = await readJournal(io, common);
278
+ contained = journal.some((e) => e.branch === branch && (e.event === "integrate" || e.event === "backmerge"));
279
+ }
280
+ catch {
281
+ contained = false;
282
+ }
283
+ if (!contained && (await branchExists(repoRoot, io, branch))) {
284
+ const tip = (await git(repoRoot, io, ["rev-parse", branch])).stdout.trim();
285
+ contained = await isAncestor(repoRoot, io, tip, "develop");
286
+ }
287
+ if (contained) {
288
+ return {
289
+ branch,
290
+ integrated: true,
291
+ developBefore: null,
292
+ developAfter: null,
293
+ rebased: false,
294
+ gate: null,
295
+ cleanedUp: true,
296
+ disposition: "already-integrated",
297
+ diagnostics: [],
298
+ };
299
+ }
192
300
  return refuse("FLOW-INT-06", `${branch} is not a registered session/task branch`, "register it with flow.open, or check flow.status for live entries", { branch });
193
301
  }
194
302
  if (entry.kind === "fix") {
@@ -203,6 +311,13 @@ export async function integrateFlowBranch(repoRoot, io, opts) {
203
311
  const live = await worktreeList(primary, io);
204
312
  const wtPath = live.find((w) => w.branch === branch)?.path ?? entry.worktree;
205
313
  if (wtPath === null || !(await io.exists(wtPath))) {
314
+ // RFC-1531: report the reattach target --reattach would use — nothing
315
+ // is created under --dry-run (AC-7).
316
+ const wouldReattach = opts.reattach === true
317
+ ? entry.worktree !== null && (await io.exists(dirname(entry.worktree)))
318
+ ? entry.worktree
319
+ : flowWorktreePath(primary, branch)
320
+ : undefined;
206
321
  return {
207
322
  branch,
208
323
  integrated: false,
@@ -211,17 +326,24 @@ export async function integrateFlowBranch(repoRoot, io, opts) {
211
326
  rebased: false,
212
327
  gate: null,
213
328
  cleanedUp: false,
329
+ ...(wouldReattach !== undefined ? { wouldReattach } : {}),
214
330
  diagnostics: [
215
331
  {
216
332
  ruleId: "FLOW-07",
217
333
  severity: "error",
218
- message: `registry entry for ${branch} names worktree ${wtPath}, which does not exist`,
219
- fixHint: "inspect with flow.status — a stale entry may need flow.discard",
334
+ message: `registry entry for ${branch} names worktree ${wtPath}, which does not exist (vanished)` +
335
+ (wouldReattach !== undefined ? ` — --reattach would recreate it at ${wouldReattach}` : ""),
336
+ fixHint: "re-run with --reattach to recreate the worktree at its recorded path, or run flow.discard to drop the registry entry and force-delete the branch",
337
+ data: { vanished: true, ...(wouldReattach !== undefined ? { wouldReattach } : {}) },
220
338
  },
221
339
  ],
222
340
  };
223
341
  }
224
342
  const dirty = await statusDirty(wtPath, io);
343
+ // RFC-1531: the dry-run diagnostic carries the classified dirty set so
344
+ // the operator reads the remedy (--auto-clean scope) without mutating.
345
+ const classified = classifyDirtyTree(dirty.entries);
346
+ const disposable = classified.filter((c) => c.class === "disposable").map((c) => c.path);
225
347
  return {
226
348
  branch,
227
349
  integrated: false,
@@ -230,13 +352,24 @@ export async function integrateFlowBranch(repoRoot, io, opts) {
230
352
  rebased: false,
231
353
  gate: null,
232
354
  cleanedUp: false,
233
- diagnostics: dirty.length > 0
355
+ ...(dirty.toleratedState.length > 0 ? { toleratedState: dirty.toleratedState } : {}),
356
+ diagnostics: dirty.entries.length > 0
234
357
  ? [
235
358
  {
236
359
  ruleId: "FLOW-INT-01",
237
360
  severity: "error",
238
- message: `worktree ${wtPath} has ${dirty.length} uncommitted change(s)`,
239
- fixHint: "commit or revert the uncommitted changes inside the session worktree",
361
+ message: `worktree ${wtPath} has ${dirty.entries.length} uncommitted change(s)` +
362
+ (dirty.toleratedState.length > 0
363
+ ? ` — tolerated forge-local state: ${dirty.toleratedState.join(", ")}`
364
+ : ""),
365
+ fixHint: "commit or revert the uncommitted changes inside the session worktree, or remediate with --auto-clean / --autocommit, then re-run",
366
+ data: {
367
+ entries: classified,
368
+ classes: summarizeClasses(classified),
369
+ toleratedState: dirty.toleratedState,
370
+ ...(opts.autoClean === true ? { wouldAutoClean: disposable } : {}),
371
+ ...(opts.autocommit === true ? { wouldAutocommit: true } : {}),
372
+ },
240
373
  },
241
374
  ]
242
375
  : [],
@@ -268,15 +401,215 @@ export async function integrateFlowBranch(repoRoot, io, opts) {
268
401
  diagnostics: [],
269
402
  };
270
403
  }
404
+ // RFC-1538: post-lock revalidation — the registry observed pre-lock can
405
+ // have changed while this run waited on the integration lock (F-0138:
406
+ // a racing integrate's teardown deleted entry+worktree under us).
407
+ const liveRegistry = await readRegistry(io, common);
408
+ const liveEntry = liveRegistry.branches.find((b) => b.name === branch);
409
+ if (liveEntry === undefined) {
410
+ // Registration vanished mid-wait. Contained work already landed → the
411
+ // winner completed; report idempotently. Otherwise mid-teardown.
412
+ const liveBranch = await branchExists(primary, io, branch);
413
+ const liveContained = liveBranch &&
414
+ (await isAncestor(primary, io, (await git(primary, io, ["rev-parse", branch])).stdout.trim(), "develop"));
415
+ if (liveContained || !liveBranch) {
416
+ return {
417
+ branch,
418
+ integrated: true,
419
+ developBefore,
420
+ developAfter: developBefore,
421
+ rebased: false,
422
+ gate: null,
423
+ cleanedUp: true,
424
+ disposition: "already-integrated",
425
+ diagnostics: [],
426
+ };
427
+ }
428
+ return refuse("FLOW-INT-15", `registry entry for ${branch} vanished while waiting on the integration lock, but the branch is not contained in develop (mid-teardown state)`, "run flow.status for the live view; recover the orphaned entry with flow.discard", { branch, developBefore });
429
+ }
271
430
  // (2) the branch worktree must exist and be clean.
272
431
  const worktrees = await worktreeList(primary, io);
273
- const branchWorktree = worktrees.find((w) => w.branch === branch)?.path ?? entry.worktree;
432
+ // `live` is the worktree git currently associates with the branch — a
433
+ // STALE registration keeps naming the dead recorded path until pruned,
434
+ // so `live !== null` does not prove the directory exists.
435
+ const live = worktrees.find((w) => w.branch === branch)?.path ?? null;
436
+ let branchWorktree = live ?? liveEntry.worktree;
437
+ let reattachedTo;
438
+ // Occupied: the recorded path exists on disk but git associates no live
439
+ // worktree with the branch — a foreign tree squats there.
440
+ const occupied = live === null && liveEntry.worktree !== null && (await io.exists(liveEntry.worktree));
441
+ const vanished = !occupied && (branchWorktree === null || !(await io.exists(branchWorktree)));
442
+ if (opts.reattach === true && occupied) {
443
+ return refuse("FLOW-INT-17", `registry worktree path ${liveEntry.worktree} exists on disk but is not a worktree of ${branch} (occupied)`, "remove or rename the occupant, then re-run flow.integrate --reattach", { branch, developBefore }, { occupied: true });
444
+ }
445
+ if (opts.reattach === true && vanished) {
446
+ // RFC-1531 --reattach: recreate the vanished worktree inside the lock,
447
+ // before the dirty/preflight checks. The recorded registry path is
448
+ // preferred when its parent exists (operators learned that location);
449
+ // the canonical <repo>@<branch> sibling is the fallback.
450
+ const recorded = liveEntry.worktree;
451
+ const target = recorded !== null && (await io.exists(dirname(recorded)))
452
+ ? recorded
453
+ : flowWorktreePath(primary, branch);
454
+ // F-0093: a vanished worktree can leave a stale `git worktree`
455
+ // registration that pins the branch — prune before adding (mirrors
456
+ // cleanupIntegrated's ordering).
457
+ await git(primary, io, ["worktree", "prune"]);
458
+ const add = await worktreeAdd(primary, io, target, branch);
459
+ if (add.exitCode !== 0) {
460
+ return refuse("FLOW-INT-17", `git worktree add ${target} ${branch} failed: ${add.stderr.trim()}`, "resolve the git error (stale registration? occupied path?) and re-run flow.integrate --reattach", { branch, developBefore });
461
+ }
462
+ reattachedTo = target;
463
+ branchWorktree = target;
464
+ opts.onProgress?.(`reattached ${branch} at ${target}`);
465
+ }
274
466
  if (branchWorktree === null || !(await io.exists(branchWorktree))) {
275
- return refuse("FLOW-07", `registry entry for ${branch} names worktree ${branchWorktree}, which does not exist`, "inspect with flow.status — a stale entry may need flow.discard", { branch, developBefore });
467
+ return refuse("FLOW-INT-15", `registry entry for ${branch} names worktree ${branchWorktree}, which does not exist (vanished mid-teardown state — the branch is not contained in develop)`, "re-run with --reattach to recreate the worktree, or run flow.status for the live view and flow.discard to drop the entry", { branch, developBefore }, { vanished: true });
468
+ }
469
+ let dirty = await statusDirty(branchWorktree, io);
470
+ if (dirty.toleratedState.length > 0) {
471
+ opts.onProgress?.(`tolerated forge-local state: ${dirty.toleratedState.join(", ")}`);
472
+ }
473
+ // RFC-1531 remediation flags — before the dirty checks: --auto-clean
474
+ // deletes ONLY disposable-class paths (closed allowlist — a work-class
475
+ // member in the set deletes nothing and still refuses FLOW-INT-01, and
476
+ // an importer-prune lockfile refuses too: restoring/committing it is a
477
+ // content decision, AC-4), then --autocommit sweeps the remainder into
478
+ // the fixed-subject commit. Remediation failures refuse FLOW-INT-17.
479
+ let autoCleaned;
480
+ let autocommitSha;
481
+ if (dirty.entries.length > 0 && (opts.autoClean === true || opts.autocommit === true)) {
482
+ const { classifyDirtyEntries } = await import("../preflight.js");
483
+ const classified = await classifyDirtyEntries(branchWorktree, io, dirty.entries);
484
+ // Pass = AUTO_CLEAN_PASS_CLASSES (tolerated family incl. the RFC-1537
485
+ // regenerable classes) or disposable. Blocker = work or importer-prune
486
+ // — AC-4 names importer-prune a refusal class: restoring/committing a
487
+ // lockfile is a content decision, never a cleanup step.
488
+ const blocker = classified.filter((c) => c.class !== "disposable" && !AUTO_CLEAN_PASS_CLASSES.includes(c.class));
489
+ if (opts.autoClean === true) {
490
+ // A blocker refuses only when nothing downstream will commit it:
491
+ // with --autocommit also set, work members sweep into the commit —
492
+ // the RFC's composed order is clean → commit → integrate.
493
+ if (blocker.length > 0 && opts.autocommit !== true) {
494
+ return refuse("FLOW-INT-01", `worktree ${branchWorktree} has ${blocker.length} uncommitted change(s) outside the disposable set: ${blocker
495
+ .slice(0, 10)
496
+ .map((b) => `${b.path} (${b.class})`)
497
+ .join(", ")} — --auto-clean deletes nothing on a mixed set`, "commit or revert the work-class entries inside the session worktree, or re-run with --autocommit to sweep them into a commit", { branch, developBefore, toleratedState: dirty.toleratedState }, {
498
+ entries: classified,
499
+ classes: summarizeClasses(classified),
500
+ toleratedState: dirty.toleratedState,
501
+ });
502
+ }
503
+ const toDelete = classified.filter((c) => c.class === "disposable");
504
+ autoCleaned = [];
505
+ for (const entry of toDelete) {
506
+ try {
507
+ await rm(join(branchWorktree, entry.path), { force: true, recursive: true });
508
+ autoCleaned.push(entry.path);
509
+ opts.onProgress?.(`auto-clean: deleted ${entry.path}`);
510
+ }
511
+ catch (error) {
512
+ return refuse("FLOW-INT-17", `--auto-clean could not delete ${entry.path}: ${error instanceof Error ? error.message : String(error)}`, "delete the path manually inside the session worktree, then re-run flow.integrate", { branch, developBefore, autoCleaned });
513
+ }
514
+ }
515
+ dirty = await statusDirty(branchWorktree, io);
516
+ }
517
+ if (opts.autocommit === true && dirty.entries.length > 0) {
518
+ // Stage exactly the remaining entry paths — never `git add -A`:
519
+ // tolerated FORGE_STATE paths are journaled, never committed.
520
+ const paths = dirty.entries.map((line) => line.slice(3).trim());
521
+ const add = await git(branchWorktree, io, ["add", "-A", "--", ...paths]);
522
+ if (add.exitCode !== 0) {
523
+ return refuse("FLOW-INT-17", `--autocommit staging failed: ${add.stderr.trim()}`, "inspect the session worktree state, then re-run flow.integrate", { branch, developBefore, autoCleaned });
524
+ }
525
+ const commit = await gitCommit(branchWorktree, io, [
526
+ "commit",
527
+ "-m",
528
+ SWEEP_COMMIT_SUBJECT,
529
+ ], "integrate");
530
+ if (commit.exitCode !== 0) {
531
+ return refuse("FLOW-INT-17", `--autocommit commit failed: ${commit.stderr.trim()}`, "the staging stays for the operator to inspect — resolve and commit or reset inside the session worktree, then re-run", { branch, developBefore, autoCleaned });
532
+ }
533
+ autocommitSha = (await git(branchWorktree, io, ["rev-parse", "HEAD"])).stdout.trim();
534
+ opts.onProgress?.(`autocommit: swept ${paths.length} path(s) into ${autocommitSha.slice(0, 9)} (${SWEEP_COMMIT_SUBJECT})`);
535
+ dirty = await statusDirty(branchWorktree, io);
536
+ }
276
537
  }
277
- const dirty = await statusDirty(branchWorktree, io);
278
- if (dirty.length > 0) {
279
- return refuse("FLOW-INT-01", `worktree ${branchWorktree} has ${dirty.length} uncommitted change(s): ${dirty.slice(0, 10).join(", ")}`, "commit or revert the uncommitted changes inside the session worktree, then re-run", { branch, developBefore });
538
+ // RFC-1537: declared regenerable dirt tolerated on this attempt —
539
+ // surfaced in data + journaled on integrate/refusal, never committed.
540
+ let toleratedDirt = [];
541
+ // RFC-1528: bounded preflight — dirty-tree checks with lockfile
542
+ // classification, then the four validators that used to fire only inside
543
+ // the expensive integration gate. Non-port path only (port entries keep
544
+ // their own FLOW-INT-09/10 semantics); first failure refuses before the
545
+ // rebase and before the gate spawns.
546
+ if (entry.port === null) {
547
+ const { runIntegratePreflight } = await import("../preflight.js");
548
+ const preflight = await runIntegratePreflight({
549
+ primary,
550
+ branchWorktree,
551
+ branch,
552
+ io,
553
+ worktreeDirty: dirty,
554
+ invoke: opts.invoke,
555
+ commandRegistry: opts.commandRegistry,
556
+ });
557
+ toleratedDirt = preflight.tolerated;
558
+ for (const skipped of preflight.skipped) {
559
+ opts.onProgress?.(skipped.reason === "no-invoke"
560
+ ? `preflight: ${skipped.check} skipped — no invoke port (standalone CLI)`
561
+ : `preflight: ${skipped.check} skipped — command not in the live inventory`);
562
+ }
563
+ for (const t of preflight.tolerated) {
564
+ opts.onProgress?.(`tolerated regenerable state: ${t.path} (${t.class})`);
565
+ }
566
+ if (!preflight.ok && preflight.refuse) {
567
+ return refuse(preflight.refuse.ruleId, preflight.refuse.message, preflight.refuse.fixHint, {
568
+ branch,
569
+ developBefore,
570
+ toleratedState: dirty.toleratedState,
571
+ toleratedDirt: preflight.tolerated,
572
+ reattachedTo,
573
+ autoCleaned,
574
+ autocommitSha,
575
+ }, preflight.refuse.data);
576
+ }
577
+ }
578
+ else if (dirty.entries.length > 0) {
579
+ // Port path keeps its own refusal surface but the same regenerable
580
+ // classes still tolerate (RFC-1537) — an importer-materializing port
581
+ // worktree is no harder to integrate than a session one.
582
+ const { classifyDirt } = await import("../preflight.js");
583
+ const verdict = await classifyDirt(branchWorktree, io, dirty.entries);
584
+ toleratedDirt = verdict.tolerated;
585
+ for (const t of verdict.tolerated) {
586
+ opts.onProgress?.(`tolerated regenerable state: ${t.path} (${t.class})`);
587
+ }
588
+ if (verdict.unattributed.length > 0) {
589
+ const entries = verdict.unattributed.map((line) => {
590
+ const path = line.slice(3).trim();
591
+ return { path, class: classifyDirtyPath(path) };
592
+ });
593
+ return refuse("FLOW-INT-01", `worktree ${branchWorktree} has ${verdict.unattributed.length} uncommitted change(s): ${verdict.unattributed.slice(0, 10).join(", ")}` +
594
+ (verdict.tolerated.length > 0
595
+ ? ` — tolerated regenerable state: ${verdict.tolerated.map((t) => `${t.path} (${t.class})`).join(", ")}`
596
+ : "") +
597
+ (dirty.toleratedState.length > 0
598
+ ? ` — tolerated forge-local state: ${dirty.toleratedState.join(", ")}`
599
+ : ""), "commit or revert the uncommitted changes inside the session worktree, or remediate with --auto-clean / --autocommit, then re-run", {
600
+ branch,
601
+ developBefore,
602
+ toleratedState: dirty.toleratedState,
603
+ toleratedDirt: verdict.tolerated,
604
+ reattachedTo,
605
+ autoCleaned,
606
+ autocommitSha,
607
+ }, {
608
+ entries,
609
+ classes: summarizeClasses(entries),
610
+ toleratedState: dirty.toleratedState,
611
+ });
612
+ }
280
613
  }
281
614
  // Port entries (RFC-1490): develop must not have moved since the port
282
615
  // opened, and the tip must be the fixed-message merge whose second
@@ -294,27 +627,94 @@ export async function integrateFlowBranch(repoRoot, io, opts) {
294
627
  }
295
628
  }
296
629
  // (3) rebase onto the current develop — never for port entries.
630
+ // RFC-1538: a conflict confined to generated artifacts resolves via its
631
+ // owner command (checkout --theirs + regenerate + continue) — the
632
+ // generated-file doctrine applied inside the rebase path; anything else
633
+ // still refuses FLOW-INT-02 for a human.
297
634
  const rebaseBase = (await git(primary, io, ["rev-parse", "develop"])).stdout.trim();
298
- const rebase = entry.port !== null
299
- ? { exitCode: 0, stdout: "", stderr: "" }
300
- : await git(branchWorktree, io, ["rebase", "develop"]);
301
- if (rebase.exitCode !== 0) {
302
- const conflicts = await git(branchWorktree, io, [
303
- "diff",
304
- "--name-only",
305
- "--diff-filter=U",
306
- ]);
307
- const paths = conflicts.stdout
308
- .split("\n")
309
- .map((l) => l.trim())
310
- .filter((l) => l.length > 0);
311
- await git(branchWorktree, io, ["rebase", "--abort"]);
312
- return refuse("FLOW-INT-02", `rebase onto develop conflicts in: ${paths.join(", ") || "(unknown paths)"}`, "resolve the rebase inside the session worktree, commit, and re-run flow.integrate", { branch, developBefore });
313
- }
314
- // (4) integration gate — the primary's copy gates the branch.
635
+ const autoResolved = [];
636
+ if (entry.port === null) {
637
+ let rebase = await git(branchWorktree, io, ["rebase", "develop"]);
638
+ let guard = 0;
639
+ while (rebase.exitCode !== 0 && guard++ < 8) {
640
+ const conflicts = await git(branchWorktree, io, [
641
+ "diff",
642
+ "--name-only",
643
+ "--diff-filter=U",
644
+ ]);
645
+ const paths = conflicts.stdout
646
+ .split("\n")
647
+ .map((l) => l.trim())
648
+ .filter((l) => l.length > 0);
649
+ const { classifyRebaseConflicts } = await import("../preflight.js");
650
+ const verdict = await classifyRebaseConflicts(branchWorktree, io, paths);
651
+ const resolvable = paths.length > 0 &&
652
+ verdict.nonGenerated.length === 0 &&
653
+ verdict.owners.length === paths.length &&
654
+ opts.invoke !== undefined;
655
+ if (!resolvable) {
656
+ await git(branchWorktree, io, ["rebase", "--abort"]);
657
+ return refuse("FLOW-INT-02", `rebase onto develop conflicts in: ${paths.join(", ") || "(unknown paths)"}` +
658
+ (verdict.owners.length > 0
659
+ ? opts.invoke === undefined
660
+ ? " — generated conflicts present but no invoke port is available to regenerate them"
661
+ : " — mixed generated/non-generated conflict set"
662
+ : ""), "resolve the rebase inside the session worktree, commit, and re-run flow.integrate", { branch, developBefore });
663
+ }
664
+ let failed = false;
665
+ for (const o of verdict.owners) {
666
+ await git(branchWorktree, io, ["checkout", "--theirs", "--", o.path]);
667
+ const regen = await opts.invoke(o.command, o.flags);
668
+ if (regen.ok === false || (regen.exitCode !== undefined && regen.exitCode !== 0)) {
669
+ await git(branchWorktree, io, ["rebase", "--abort"]);
670
+ failed = true;
671
+ return refuse("FLOW-INT-02", `auto-resolve of generated conflict ${o.path} failed: ${o.command} — ${regen.summary ?? `exit ${regen.exitCode}`}`, "resolve the rebase inside the session worktree manually, commit, and re-run flow.integrate", { branch, developBefore });
672
+ }
673
+ await git(branchWorktree, io, ["add", "--", o.path]);
674
+ opts.onProgress?.(`conflict: ${o.path} — regenerated via ${o.command}`);
675
+ autoResolved.push(o.path);
676
+ }
677
+ if (failed)
678
+ break;
679
+ rebase = await git(branchWorktree, io, [
680
+ "-c",
681
+ "core.editor=true",
682
+ "rebase",
683
+ "--continue",
684
+ ]);
685
+ }
686
+ if (rebase.exitCode !== 0) {
687
+ const conflicts = await git(branchWorktree, io, [
688
+ "diff",
689
+ "--name-only",
690
+ "--diff-filter=U",
691
+ ]);
692
+ const paths = conflicts.stdout
693
+ .split("\n")
694
+ .map((l) => l.trim())
695
+ .filter((l) => l.length > 0);
696
+ await git(branchWorktree, io, ["rebase", "--abort"]);
697
+ return refuse("FLOW-INT-02", `rebase onto develop conflicts in: ${paths.join(", ") || "(unknown paths)"}`, "resolve the rebase inside the session worktree, commit, and re-run flow.integrate", { branch, developBefore });
698
+ }
699
+ }
700
+ // (4) integration gate — the primary's script, executed by the session
701
+ // engine's build when the worktree carries one (RFC-1538): the code
702
+ // under review judges itself; the checks it faces stay primary-owned.
703
+ const { resolveGateEngine } = await import("../gate-engine.js");
704
+ const engine = await resolveGateEngine(branchWorktree, primary, io);
705
+ const warnings = [];
706
+ if (engine.source === "primary" && (await io.exists(join(primary, "hooks", "integration-gate.sh")))) {
707
+ warnings.push({
708
+ ruleId: "FLOW-INT-16",
709
+ severity: "warning",
710
+ message: `no session engine build under ${branchWorktree} — the integration gate runs the primary engine`,
711
+ fixHint: "run pnpm install inside the session worktree to have its own build judged; the F-0137 self-referential escape is a backport worktree",
712
+ });
713
+ }
714
+ opts.onProgress?.(`gate engine: ${engine.source} (${engine.root})`);
315
715
  const gate = await runFlowScript(io, "integration-gate", {
316
716
  primary,
317
- cwd: branchWorktree,
717
+ cwd: engine.root,
318
718
  env: {
319
719
  FLOW_PRIMARY: primary,
320
720
  FLOW_BRANCH: branch,
@@ -323,15 +723,40 @@ export async function integrateFlowBranch(repoRoot, io, opts) {
323
723
  },
324
724
  });
325
725
  if (gate.status === "failed") {
326
- return refuse("FLOW-INT-05", `hooks/integration-gate.sh refused the integration (exit ${gate.exitCode}): ${gate.stderrTail}`, `fix what ${primary}/hooks/integration-gate.sh demands, then re-run`, { branch, developBefore, rebased: entry.port === null, gate });
726
+ return refuse("FLOW-INT-05", `hooks/integration-gate.sh refused the integration (exit ${gate.exitCode}): ${gate.stderrTail}`, `fix what ${primary}/hooks/integration-gate.sh demands, then re-run`, { branch, developBefore, rebased: entry.port === null, gate },
727
+ // RFC-1532 AC-4: name the persisted report so the fixing agent reads
728
+ // full check rows instead of re-running the gate.
729
+ gate.reportPath ? { reportPath: gate.reportPath } : undefined);
327
730
  }
328
- // (5) primary must sit clean on develop, then fast-forward.
731
+ // (5) primary must sit clean on develop, then fast-forward. Mid-gate
732
+ // importer churn from another session's open mission tolerates here too
733
+ // (RFC-1537) — the same classifier the preflight ran.
329
734
  const primaryBranch = await currentBranch(primary, io);
330
735
  const primaryDirty = await statusTracked(primary, io);
331
- if (primaryBranch !== "develop" || primaryDirty.length > 0) {
332
- return refuse("FLOW-INT-03", primaryBranch !== "develop"
333
- ? `primary worktree is on ${primaryBranch ?? "detached HEAD"}, not develop`
334
- : `primary worktree has ${primaryDirty.length} uncommitted change(s)`, "switch the primary to develop and commit or revert its tracked changes, then re-run — the branch stays rebased", { branch, developBefore, rebased: entry.port === null, gate });
736
+ if (primaryBranch !== "develop" || primaryDirty.entries.length > 0) {
737
+ let unattributed = primaryDirty.entries;
738
+ if (primaryDirty.entries.length > 0) {
739
+ const { classifyDirt } = await import("../preflight.js");
740
+ const verdict = await classifyDirt(primary, io, primaryDirty.entries);
741
+ unattributed = verdict.unattributed;
742
+ if (verdict.tolerated.length > 0) {
743
+ toleratedDirt = [...toleratedDirt, ...verdict.tolerated];
744
+ for (const t of verdict.tolerated) {
745
+ opts.onProgress?.(`tolerated regenerable state on primary: ${t.path} (${t.class})`);
746
+ }
747
+ }
748
+ }
749
+ if (primaryBranch !== "develop" || unattributed.length > 0) {
750
+ return refuse("FLOW-INT-03", primaryBranch !== "develop"
751
+ ? `primary worktree is on ${primaryBranch ?? "detached HEAD"}, not develop`
752
+ : `primary worktree has ${unattributed.length} uncommitted change(s)`, "switch the primary to develop and commit or revert its tracked changes, then re-run — the branch stays rebased", {
753
+ branch,
754
+ developBefore,
755
+ rebased: entry.port === null,
756
+ gate,
757
+ ...(toleratedDirt.length > 0 ? { toleratedDirt } : {}),
758
+ });
759
+ }
335
760
  }
336
761
  const developNow = (await git(primary, io, ["rev-parse", "develop"])).stdout.trim();
337
762
  if (!(await isAncestor(primary, io, developNow, branch))) {
@@ -350,38 +775,64 @@ export async function integrateFlowBranch(repoRoot, io, opts) {
350
775
  rebased: entry.port === null,
351
776
  gate,
352
777
  cleanedUp: false,
353
- diagnostics: [],
778
+ ...(dirty.toleratedState.length > 0 ? { toleratedState: dirty.toleratedState } : {}),
779
+ ...(toleratedDirt.length > 0 ? { toleratedDirt } : {}),
780
+ ...(autoResolved.length > 0 ? { autoResolved } : {}),
781
+ ...(reattachedTo !== undefined ? { reattachedTo } : {}),
782
+ ...(autoCleaned !== undefined && autoCleaned.length > 0 ? { autoCleaned } : {}),
783
+ ...(autocommitSha !== undefined ? { autocommitSha } : {}),
784
+ gateEngine: engine.source,
785
+ diagnostics: warnings,
354
786
  };
355
787
  };
356
788
  let inner;
357
789
  try {
358
- inner = opts.lockHeld === true
359
- ? await integrateInner()
360
- : await withFlowLock(lockPath, {
361
- waitMs: INTEGRATE_LOCK_WAIT_MS,
362
- staleMs: INTEGRATE_LOCK_STALE_MS,
363
- progressEveryMs: 60_000,
364
- onProgress: opts.onProgress,
365
- onStale: (l) => opts.onProgress?.(l.reason === "dead-holder"
366
- ? `broke dead-holder integration lock (pid ${l.pid ?? "?"} on ${l.host ?? "?"}, held since ${l.at})`
367
- : `broke stale integration lock (held since ${l.at}, ${Math.round(l.ageMs / 60000)} min old)`),
368
- }, integrateInner, io);
790
+ inner =
791
+ opts.lockHeld === true
792
+ ? await integrateInner()
793
+ : await withFlowLock(lockPath, {
794
+ waitMs: opts.lockWaitMs ?? INTEGRATE_LOCK_WAIT_MS,
795
+ staleMs: INTEGRATE_LOCK_STALE_MS,
796
+ progressEveryMs: 60_000,
797
+ onProgress: opts.onProgress,
798
+ onStale: (l) => opts.onProgress?.(l.reason === "dead-holder"
799
+ ? `broke dead-holder integration lock (pid ${l.pid ?? "?"} on ${l.host ?? "?"}, held since ${l.at})`
800
+ : `broke stale integration lock (held since ${l.at}, ${Math.round(l.ageMs / 60000)} min old)`),
801
+ }, integrateInner, io);
369
802
  }
370
803
  catch (error) {
371
804
  if (error instanceof LockTimeoutError) {
372
- return refuse("FLOW-INT-08", `integration lock ${error.lockPath} is held by another integration`, "wait for the running integration to finish, or break the stale lock after 2 h automatically", { branch });
805
+ // RFC-1515 AC-4: a refused attempt reports the holder on the first
806
+ // try — the lock payload names pid/host/at/heldMs plus a disposition
807
+ // computed by the same dead-holder classifier withFlowLock uses.
808
+ const holder = error.holder;
809
+ const lock = holder === undefined ? undefined : describeHeldLock(holder, INTEGRATE_LOCK_STALE_MS);
810
+ return refuse("FLOW-INT-08", lock === undefined
811
+ ? `integration lock ${error.lockPath} is held by another integration (holder unknown)`
812
+ : `integration lock ${error.lockPath} is held by pid ${lock.pid} on ${lock.host ?? "unknown host"} since ${lock.at} (${lock.disposition})`, "run forge werkstatt.lock.status for the live view, or forge werkstatt.lock.recover to break a dead holder's lock", { branch, lock });
373
813
  }
374
814
  if (error instanceof FlowRegistrySchemaError) {
375
- return refuse("FLOW-07", error.message, `repair or remove ${registryPath(common)}`, { branch });
815
+ return refuse("FLOW-07", error.message, `repair or remove ${registryPath(common)}`, {
816
+ branch,
817
+ });
376
818
  }
377
819
  throw error;
378
820
  }
379
- if (!inner.integrated || inner.diagnostics.length > 0)
821
+ // Only error-severity diagnostics are refusals — warnings (e.g. the
822
+ // FLOW-INT-16 primary-engine notice) must not skip cleanup and journaling.
823
+ if (!inner.integrated || inner.diagnostics.some((d) => d.severity === "error"))
380
824
  return inner;
381
825
  // (6) cleanup — outside the lock; every git call runs with -C primary.
826
+ // RFC-1536: prune this session's own id reservations once the branch
827
+ // landed — other sessions' entries stay untouched.
828
+ await pruneReservationsForSession(io, primary, branch);
382
829
  const worktrees = await worktreeList(primary, io);
383
830
  const branchWorktree = worktrees.find((w) => w.branch === branch)?.path ?? entry.worktree;
384
- const cleanup = await cleanupIntegrated(primary, branchWorktree, entry, common, inner.developAfter ?? inner.developBefore ?? "", io, now.toISOString(), entry.port !== null ? "backmerge" : "integrate", inner.developBefore ?? undefined);
831
+ const cleanup = await cleanupIntegrated(primary, branchWorktree, entry, common, inner.developAfter ?? inner.developBefore ?? "", io, now.toISOString(), entry.port !== null ? "backmerge" : "integrate", inner.developBefore ?? undefined, inner.toleratedDirt, inner.autoResolved, {
832
+ reattachedTo: inner.reattachedTo,
833
+ autoCleaned: inner.autoCleaned,
834
+ autocommitSha: inner.autocommitSha,
835
+ }, inner.gate?.reportPath ?? undefined);
385
836
  return {
386
837
  ...inner,
387
838
  gate: inner.gate,
@@ -403,6 +854,11 @@ export async function runFlowIntegrate(input, context) {
403
854
  branch: typeof branchFlag === "string" ? branchFlag : null,
404
855
  dryRun: context.dryRun || input.flags["dry-run"] === true,
405
856
  onProgress: (m) => logger.info(` ${m}`),
857
+ invoke: context.invoke,
858
+ commandRegistry: context.commandRegistry,
859
+ reattach: input.flags["reattach"] === true,
860
+ autoClean: input.flags["auto-clean"] === true,
861
+ autocommit: input.flags["autocommit"] === true,
406
862
  });
407
863
  const refused = data.diagnostics.find((d) => d.severity === "error");
408
864
  if (outputFormat === "pretty") {
@@ -415,6 +871,21 @@ export async function runFlowIntegrate(input, context) {
415
871
  logger.info(` integrated: ${data.integrated}${data.rebased ? " (rebased)" : ""}`);
416
872
  logger.info(` develop: ${data.developBefore?.slice(0, 9)} → ${data.developAfter?.slice(0, 9)}`);
417
873
  logger.info(` cleanedUp: ${data.cleanedUp}`);
874
+ if (data.toleratedDirt !== undefined && data.toleratedDirt.length > 0) {
875
+ logger.info(` tolerated: ${data.toleratedDirt.map((t) => `${t.path} (${t.class})`).join(", ")}`);
876
+ }
877
+ if (data.toleratedState !== undefined && data.toleratedState.length > 0) {
878
+ logger.info(` tolerated forge state: ${data.toleratedState.join(", ")}`);
879
+ }
880
+ if (data.reattachedTo !== undefined) {
881
+ logger.info(` reattached: ${data.reattachedTo}`);
882
+ }
883
+ if (data.autoCleaned !== undefined && data.autoCleaned.length > 0) {
884
+ logger.info(` auto-cleaned: ${data.autoCleaned.join(", ")}`);
885
+ }
886
+ if (data.autocommitSha !== undefined) {
887
+ logger.info(` autocommit: ${data.autocommitSha.slice(0, 9)} (${SWEEP_COMMIT_SUBJECT})`);
888
+ }
418
889
  }
419
890
  }
420
891
  return {