@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
@@ -0,0 +1,763 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>flow.integrate preflight (RFC-1528) — a bounded, deterministic check list that
4
+ runs between the dirty-tree checks and the integration-gate spawn, refusing in
5
+ seconds what the gate would catch minutes later. Ordered: (1) worktree dirty +
6
+ lockfile-diff classification, (2) primary tracked dirt + classification,
7
+ (3) ecosystem.manifest.validate, (4) rfc.validate --id per changed RFC file,
8
+ (5) friction.validate. Each check runs only when resolvable (invoke port +
9
+ registry entry) — absence degrades with a note, never blocks. The list is
10
+ closed by the RFC: adding a check requires an amendment.</purpose>
11
+ <non-goals>
12
+ <item>No auto-fix, no auto-commit — the lockfile classifier only labels the importer-prune-only shape with a remedy hint; a dirty pnpm-lock.yaml still refuses.</item>
13
+ <item>No builds, no test suites — sub-minute deterministic validators only.</item>
14
+ </non-goals>
15
+ </MODULE_CONTRACT>
16
+ <CHANGE_SUMMARY>
17
+ <item>RFC-1528: initial — classifyLockfileDiff + runIntegratePreflight (FLOW-INT-01/03 classification, FLOW-INT-12/13/14 validator refusals).</item>
18
+ <item>RFC-1528: flow.integrate bounded preflight before rebase and gate
19
+
20
+ Classified lockfile diffs on FLOW-INT-01/03, early primary check, and resolvable validators (ecosystem.manifest.validate, scoped rfc.validate, friction.validate) refusing as FLOW-INT-12/13/14.</item>
21
+ <item>RFC-1528: close review findings — manifest-union command inventory for regen/preflight</item>
22
+ <item>RFC-1537: regenerable dirt classifier (importer-materialize, skill-twin-sync), cheap-first open-mission check (WT-GATE-01), toleratedState surfacing</item>
23
+ <item>RFC-1538: revalidate integration preconditions post-lock and reuse the session engine</item>
24
+ <item>RFC-1531: shared DirtyClass enum via dirty-classify.ts (Q-4), classified FLOW-INT-01/03 data.entries, classifyDirtyEntries for the remediation flags</item>
25
+ </CHANGE_SUMMARY>
26
+ */
27
+
28
+ import { basename, dirname, join } from "node:path";
29
+
30
+ import type {
31
+ CommandRegistry,
32
+ ForgeFlagValue,
33
+ ForgeInvokeCommand,
34
+ ForgeRegisteredCommandInfo,
35
+ WorkspaceIO,
36
+ } from "../../src/types.ts";
37
+ import { loadLiveCommandInventory } from "../../src/utils/command-inventory.ts";
38
+ import {
39
+ isGeneratedContent,
40
+ isGeneratedPathName,
41
+ REGEN_FLAGS,
42
+ } from "../core/archive-regen.ts";
43
+ import { openMissionsIn } from "../mission/open-missions.ts";
44
+ import {
45
+ classifyDirtyPath,
46
+ summarizeClasses,
47
+ type ClassifiedDirtyEntry,
48
+ type DirtyClass,
49
+ } from "./dirty-classify.ts";
50
+ import { currentBranch, git, statusTracked } from "./git.ts";
51
+
52
+ export type LockfileClassification = "importer-prune-only" | "other";
53
+
54
+ /**
55
+ * Strict match for the pnpm-prune shape: ONLY removed lines, every one either
56
+ * a `missions/<id>/workpiece:` importer key or a deeper-indented member of
57
+ * such a key's block. Any added line, any other removed line, or a diff with
58
+ * no removals classifies "other" — ambiguous diffs stay ordinary refusals.
59
+ */
60
+ export function classifyLockfileDiff(diffText: string): LockfileClassification {
61
+ let sawImporterKey = false;
62
+ let openBlockIndent: number | null = null;
63
+ for (const raw of diffText.split("\n")) {
64
+ if (
65
+ raw === "" ||
66
+ raw.startsWith("diff ") ||
67
+ raw.startsWith("index ") ||
68
+ raw.startsWith("---") ||
69
+ raw.startsWith("+++") ||
70
+ raw.startsWith("@@")
71
+ ) {
72
+ if (raw.startsWith("@@")) openBlockIndent = null;
73
+ continue;
74
+ }
75
+ if (raw.startsWith("+")) return "other";
76
+ const line = raw.slice(1);
77
+ if (raw[0] === " ") {
78
+ const indent = line.length - line.trimStart().length;
79
+ if (openBlockIndent !== null && line.trim().length > 0 && indent <= openBlockIndent) {
80
+ openBlockIndent = null;
81
+ }
82
+ continue;
83
+ }
84
+ if (raw[0] !== "-") continue;
85
+ if (line.trim().length === 0) {
86
+ // A blank removed line only tolerates inside an open importer block.
87
+ if (openBlockIndent === null) return "other";
88
+ continue;
89
+ }
90
+ const indent = line.length - line.trimStart().length;
91
+ if (/^\s*missions\/[^\s/]+\/workpiece:\s*$/.test(line)) {
92
+ sawImporterKey = true;
93
+ openBlockIndent = indent;
94
+ continue;
95
+ }
96
+ if (openBlockIndent !== null && indent > openBlockIndent) continue;
97
+ return "other";
98
+ }
99
+ return sawImporterKey ? "importer-prune-only" : "other";
100
+ }
101
+
102
+ /**
103
+ * Mirror of the prune shape for materialization (RFC-1537): ONLY added lines,
104
+ * every one either a `missions/<id>/workpiece:` importer key or a deeper-
105
+ * indented member of such a block. Returns the sorted mission ids on match,
106
+ * null otherwise — any removal or foreign addition is ambiguous.
107
+ */
108
+ export function classifyLockfileMaterialize(diffText: string): string[] | null {
109
+ const ids = new Set<string>();
110
+ let sawImporterKey = false;
111
+ let openBlockIndent: number | null = null;
112
+ for (const raw of diffText.split("\n")) {
113
+ if (
114
+ raw === "" ||
115
+ raw.startsWith("diff ") ||
116
+ raw.startsWith("index ") ||
117
+ raw.startsWith("---") ||
118
+ raw.startsWith("+++") ||
119
+ raw.startsWith("@@")
120
+ ) {
121
+ if (raw.startsWith("@@")) openBlockIndent = null;
122
+ continue;
123
+ }
124
+ if (raw.startsWith("-")) return null;
125
+ const line = raw.slice(1);
126
+ if (raw[0] === " ") {
127
+ const indent = line.length - line.trimStart().length;
128
+ if (openBlockIndent !== null && line.trim().length > 0 && indent <= openBlockIndent) {
129
+ openBlockIndent = null;
130
+ }
131
+ continue;
132
+ }
133
+ if (raw[0] !== "+") continue;
134
+ if (line.trim().length === 0) {
135
+ // A blank added line only tolerates inside an open importer block.
136
+ if (openBlockIndent === null) return null;
137
+ continue;
138
+ }
139
+ const indent = line.length - line.trimStart().length;
140
+ const key = /^\s*missions\/([^\s/]+)\/workpiece:\s*$/.exec(line);
141
+ if (key) {
142
+ sawImporterKey = true;
143
+ ids.add(key[1]);
144
+ openBlockIndent = indent;
145
+ continue;
146
+ }
147
+ if (openBlockIndent !== null && indent > openBlockIndent) continue;
148
+ return null;
149
+ }
150
+ return sawImporterKey ? [...ids].sort() : null;
151
+ }
152
+
153
+ /** Classify the pnpm-lock.yaml diff of `repo` when the lockfile is dirty. */
154
+ async function classifyDirtyLockfile(
155
+ repo: string,
156
+ io: WorkspaceIO,
157
+ dirtyEntries: string[],
158
+ runGit: typeof git,
159
+ ): Promise<LockfileClassification | null> {
160
+ const lockfileDirty = dirtyEntries.some((entry) => entry.slice(3).trim() === "pnpm-lock.yaml");
161
+ if (!lockfileDirty) return null;
162
+ const diff = await runGit(repo, io, ["diff", "HEAD", "--", "pnpm-lock.yaml"]);
163
+ return classifyLockfileDiff(diff.stdout);
164
+ }
165
+
166
+ // ── RFC-1537: regenerable dirt classifier ────────────────────────────────
167
+ // Q-4 (RFC-1531): the class enum is shared — dirty-classify.ts owns the
168
+ // closed vocabulary; this module only assigns its diff-aware members.
169
+
170
+ export type { DirtyClass } from "./dirty-classify.ts";
171
+
172
+ export interface ToleratedEntry {
173
+ path: string;
174
+ class: DirtyClass;
175
+ }
176
+
177
+ export interface DirtVerdict {
178
+ tolerated: ToleratedEntry[];
179
+ /** Porcelain lines that match no declared regenerable shape — still refuse. */
180
+ unattributed: string[];
181
+ }
182
+
183
+ const TWIN_ROOT = ".agents/skills/";
184
+
185
+ /** Canonical candidates for a `.agents/skills/<dir>/<rel>` twin path. */
186
+ function twinCanonicalCandidates(dir: string, rel: string): string[] {
187
+ const candidates = [
188
+ `packages/forge/skills/${dir}/${rel}`,
189
+ `packages/forge/skills/fo/${dir}/${rel}`,
190
+ `packages/forge/skills/meta/${dir}/${rel}`,
191
+ `packages/werkstatt-site/src/domain/skills/${dir}/${rel}`,
192
+ ];
193
+ if (dir === "shared-knowledge") {
194
+ candidates.push(`packages/forge/skills/shared/knowledge/${rel}`);
195
+ }
196
+ return candidates;
197
+ }
198
+
199
+ async function fileBytesEqual(a: string, b: string, io: WorkspaceIO): Promise<boolean> {
200
+ const [ba, bb] = await Promise.all([io.readFileBytes(a), io.readFileBytes(b)]);
201
+ return ba.length === bb.length && ba.every((v, i) => v === bb[i]);
202
+ }
203
+
204
+ /** `.prettierignore` diff is twin-sync only when every change adds .agents/skills/ lines. */
205
+ function prettierignoreTwinOnly(diffText: string): boolean {
206
+ let saw = false;
207
+ for (const raw of diffText.split("\n")) {
208
+ if (
209
+ raw === "" ||
210
+ raw.startsWith("diff ") ||
211
+ raw.startsWith("index ") ||
212
+ raw.startsWith("---") ||
213
+ raw.startsWith("+++") ||
214
+ raw.startsWith("@@") ||
215
+ raw.startsWith(" ")
216
+ ) {
217
+ continue;
218
+ }
219
+ if (raw.startsWith("-")) return false;
220
+ if (raw.startsWith("+")) {
221
+ if (!/^\+\s*\.agents\/skills\/[^\s]+\/?\s*$/.test(raw)) return false;
222
+ saw = true;
223
+ }
224
+ }
225
+ return saw;
226
+ }
227
+
228
+ /**
229
+ * Partition porcelain lines into declared regenerable classes (tolerated —
230
+ * journaled, never committed) and `unattributed` lines that still refuse.
231
+ * The shapes are closed by RFC-1537: ambiguity always degrades to
232
+ * unattributed, never to tolerance.
233
+ */
234
+ export async function classifyDirt(
235
+ repo: string,
236
+ io: WorkspaceIO,
237
+ entries: string[],
238
+ deps: { runGit: typeof git } = { runGit: git },
239
+ ): Promise<DirtVerdict> {
240
+ const tolerated: ToleratedEntry[] = [];
241
+ const unattributed: string[] = [];
242
+ const byPath = new Map<string, string[]>();
243
+ for (const line of entries) {
244
+ const p = line.slice(3).trim();
245
+ byPath.set(p, [...(byPath.get(p) ?? []), line]);
246
+ }
247
+
248
+ let openMissions: Set<string> | null = null;
249
+ const openMissionIds = async (): Promise<Set<string>> => {
250
+ if (openMissions === null) {
251
+ openMissions = new Set(await openMissionsIn(repo, io));
252
+ }
253
+ return openMissions;
254
+ };
255
+
256
+ outer: for (const [path, lines] of byPath) {
257
+ if (path === "pnpm-lock.yaml") {
258
+ const diff = await deps.runGit(repo, io, ["diff", "HEAD", "--", "pnpm-lock.yaml"]);
259
+ if (classifyLockfileDiff(diff.stdout) === "importer-prune-only") {
260
+ tolerated.push({ path, class: "importer-prune" });
261
+ continue;
262
+ }
263
+ const ids = classifyLockfileMaterialize(diff.stdout);
264
+ if (ids !== null) {
265
+ const open = await openMissionIds();
266
+ if (ids.every((id) => open.has(id))) {
267
+ tolerated.push({ path, class: "importer-materialize" });
268
+ continue;
269
+ }
270
+ }
271
+ unattributed.push(...lines);
272
+ continue;
273
+ }
274
+ if (path === ".prettierignore") {
275
+ const diff = await deps.runGit(repo, io, ["diff", "HEAD", "--", ".prettierignore"]);
276
+ if (prettierignoreTwinOnly(diff.stdout)) {
277
+ tolerated.push({ path, class: "skill-twin-sync" });
278
+ continue;
279
+ }
280
+ unattributed.push(...lines);
281
+ continue;
282
+ }
283
+ if (path.startsWith(TWIN_ROOT) && path.length > TWIN_ROOT.length) {
284
+ const rel = path.slice(TWIN_ROOT.length).replace(/\/$/, "");
285
+ const dir = rel.split("/")[0];
286
+ const fileRel = rel.slice(dir.length + 1);
287
+ if (fileRel === "") {
288
+ // `?? .agents/skills/<dir>/` — an untracked twin DIRECTORY. Fail
289
+ // closed: every file inside must byte-match a canonical source or be
290
+ // the .forge-managed marker beside one; a single stray stays dirty.
291
+ const canonicalDir = async (): Promise<boolean> => {
292
+ for (const c of twinCanonicalCandidates(dir, "SKILL.md")) {
293
+ if (await io.exists(join(repo, dirname(c)))) return true;
294
+ }
295
+ return false;
296
+ };
297
+ const files = (await io.glob(`${TWIN_ROOT}${rel}/**`, { cwd: repo })).filter(
298
+ (f) => !f.endsWith("/"),
299
+ );
300
+ let allTwins = files.length > 0 && (await canonicalDir());
301
+ for (const f of allTwins ? files : []) {
302
+ const frel = f.slice(`${TWIN_ROOT}${rel}/`.length);
303
+ if (frel === ".forge-managed") continue;
304
+ let matched = false;
305
+ for (const c of twinCanonicalCandidates(dir, frel)) {
306
+ const abs = join(repo, c);
307
+ if ((await io.exists(abs)) && (await fileBytesEqual(join(repo, f), abs, io))) {
308
+ matched = true;
309
+ break;
310
+ }
311
+ }
312
+ if (!matched) {
313
+ allTwins = false;
314
+ break;
315
+ }
316
+ }
317
+ if (allTwins) tolerated.push({ path, class: "skill-twin-sync" });
318
+ else unattributed.push(...lines);
319
+ continue;
320
+ }
321
+ if (fileRel === ".forge-managed") {
322
+ // Twin bookkeeping file — tolerated when the dir has any canonical
323
+ // skill source; a free-floating marker is real dirt.
324
+ let markerOk = false;
325
+ for (const c of twinCanonicalCandidates(dir, "SKILL.md")) {
326
+ if (await io.exists(join(repo, dirname(c)))) {
327
+ markerOk = true;
328
+ break;
329
+ }
330
+ }
331
+ if (markerOk) tolerated.push({ path, class: "skill-twin-sync" });
332
+ else unattributed.push(...lines);
333
+ continue;
334
+ }
335
+ let matched = false;
336
+ for (const c of twinCanonicalCandidates(dir, fileRel)) {
337
+ const abs = join(repo, c);
338
+ if ((await io.exists(abs)) && (await fileBytesEqual(join(repo, path), abs, io))) {
339
+ matched = true;
340
+ break;
341
+ }
342
+ }
343
+ if (matched) tolerated.push({ path, class: "skill-twin-sync" });
344
+ else unattributed.push(...lines);
345
+ continue;
346
+ }
347
+ unattributed.push(...lines);
348
+ }
349
+ return { tolerated, unattributed };
350
+ }
351
+
352
+ /**
353
+ * RFC-1531 AC-6: classify EVERY dirty entry — tolerated-family classes come
354
+ * from the diff-aware classifyDirt; the remaining entries get their
355
+ * path-only class (disposable or work — importer/twin classes can only be
356
+ * diff-assigned, so they never appear here). Used for FLOW-INT-01's
357
+ * data.entries and by the remediation flags.
358
+ */
359
+ export async function classifyDirtyEntries(
360
+ repo: string,
361
+ io: WorkspaceIO,
362
+ entries: string[],
363
+ deps: { runGit: typeof git } = { runGit: git },
364
+ ): Promise<ClassifiedDirtyEntry[]> {
365
+ const verdict = await classifyDirt(repo, io, entries, deps);
366
+ const out: ClassifiedDirtyEntry[] = verdict.tolerated.map((t) => ({
367
+ path: t.path,
368
+ class: t.class,
369
+ }));
370
+ for (const line of verdict.unattributed) {
371
+ const path = line.slice(3).trim();
372
+ out.push({ path, class: classifyDirtyPath(path) });
373
+ }
374
+ return out;
375
+ }
376
+
377
+ const LOCKFILE_PRUNE_HINT =
378
+ " — its diff matches the vanished mission-importer prune shape; restore it " +
379
+ "(`git checkout -- pnpm-lock.yaml` is blocked for agents: copy HEAD bytes " +
380
+ "with `git show HEAD:pnpm-lock.yaml > pnpm-lock.yaml`) or commit the prune deliberately";
381
+
382
+ export interface PreflightRefuse {
383
+ ruleId: string;
384
+ message: string;
385
+ fixHint: string;
386
+ data?: Record<string, unknown>;
387
+ }
388
+
389
+ export interface PreflightSkip {
390
+ check: string;
391
+ reason: "no-invoke" | "unresolvable";
392
+ }
393
+
394
+ export interface IntegratePreflightResult {
395
+ ok: boolean;
396
+ /** Check names that ran, in order. */
397
+ checked: string[];
398
+ /** Checks skipped — invoke port absent, or command not in the inventory. */
399
+ skipped: PreflightSkip[];
400
+ /** RFC-1537: regenerable dirt tolerated on this run — journaled, never
401
+ * committed or silently absorbed. */
402
+ tolerated: ToleratedEntry[];
403
+ refuse?: PreflightRefuse;
404
+ }
405
+
406
+ /**
407
+ * The bounded preflight — first failure wins. `deps` seams exist for tests;
408
+ * production passes the real git helpers.
409
+ */
410
+ export async function runIntegratePreflight(
411
+ opts: {
412
+ primary: string;
413
+ branchWorktree: string;
414
+ branch: string;
415
+ io: WorkspaceIO;
416
+ /** Already-computed statusDirty() of the branch worktree. */
417
+ worktreeDirty: { entries: string[]; toleratedState: string[] };
418
+ invoke?: ForgeInvokeCommand;
419
+ commandRegistry?: CommandRegistry;
420
+ /** Test seam — overrides the live inventory union (registry + command manifest). */
421
+ commands?: ForgeRegisteredCommandInfo[];
422
+ },
423
+ deps: {
424
+ runGit: typeof git;
425
+ runStatusTracked: typeof statusTracked;
426
+ runCurrentBranch: typeof currentBranch;
427
+ } = { runGit: git, runStatusTracked: statusTracked, runCurrentBranch: currentBranch },
428
+ ): Promise<IntegratePreflightResult> {
429
+ const checked: string[] = [];
430
+ const skipped: PreflightSkip[] = [];
431
+ const tolerated: ToleratedEntry[] = [];
432
+ const { io } = opts;
433
+ // D-001 union: werkstatt run supplies invoke but no commandRegistry — the
434
+ // generated manifest (in the primary checkout) covers resolvability.
435
+ const commands = opts.commands ?? loadLiveCommandInventory(opts.primary, opts.commandRegistry);
436
+ const commandNames = new Set(commands.map((c) => c.name));
437
+ const resolvable = (name: string) => opts.invoke !== undefined && commandNames.has(name);
438
+
439
+ // (0) open mission in the integrating worktree — WT-GATE-01 semantics at
440
+ // preflight price (RFC-1537): ahead of every validator arm and even the
441
+ // dirty checks, since a live mission outranks a dirty tree. A scan failure
442
+ // skips with a note — the downstream gate still enforces.
443
+ try {
444
+ const openMissions = await openMissionsIn(opts.branchWorktree, io);
445
+ checked.push("open-mission");
446
+ if (openMissions.length > 0) {
447
+ return {
448
+ ok: false,
449
+ checked,
450
+ skipped,
451
+ tolerated,
452
+ refuse: {
453
+ ruleId: "WT-GATE-01",
454
+ message: `worktree has ${openMissions.length} open mission(s): ${openMissions.join(", ")}`,
455
+ fixHint: "close or abort the mission(s) in the worktree before integrating or tearing down",
456
+ data: { openMissions },
457
+ },
458
+ };
459
+ }
460
+ } catch {
461
+ skipped.push({ check: "open-mission", reason: "unresolvable" });
462
+ }
463
+
464
+ // (1) worktree dirty — FLOW-INT-01 only on unattributed entries; declared
465
+ // regenerable classes journal as tolerated (RFC-1537).
466
+ checked.push("worktree-dirty");
467
+ if (opts.worktreeDirty.entries.length > 0) {
468
+ const verdict = await classifyDirt(opts.branchWorktree, io, opts.worktreeDirty.entries, {
469
+ runGit: deps.runGit,
470
+ });
471
+ tolerated.push(...verdict.tolerated);
472
+ if (verdict.unattributed.length > 0) {
473
+ const lockfile = await classifyDirtyLockfile(
474
+ opts.branchWorktree,
475
+ io,
476
+ verdict.unattributed,
477
+ deps.runGit,
478
+ );
479
+ return {
480
+ ok: false,
481
+ checked,
482
+ skipped,
483
+ tolerated,
484
+ refuse: {
485
+ ruleId: "FLOW-INT-01",
486
+ message:
487
+ `worktree ${opts.branchWorktree} has ${verdict.unattributed.length} uncommitted change(s): ${verdict.unattributed.slice(0, 10).join(", ")}` +
488
+ (verdict.tolerated.length > 0
489
+ ? ` — tolerated regenerable state: ${verdict.tolerated.map((t) => `${t.path} (${t.class})`).join(", ")}`
490
+ : "") +
491
+ (opts.worktreeDirty.toleratedState.length > 0
492
+ ? ` — tolerated forge-local state: ${opts.worktreeDirty.toleratedState.join(", ")}`
493
+ : "") +
494
+ (lockfile === "importer-prune-only" ? ` — pnpm-lock.yaml${LOCKFILE_PRUNE_HINT}` : ""),
495
+ fixHint:
496
+ "commit or revert the uncommitted changes inside the session worktree, or remediate with --auto-clean / --autocommit, then re-run",
497
+ data: {
498
+ // RFC-1531 AC-6: per-path classes so the remedy is read from
499
+ // the diagnostic — disposable members may --auto-clean away,
500
+ // work members must be committed or reverted (or --autocommit).
501
+ entries: verdict.unattributed.map((line) => {
502
+ const path = line.slice(3).trim();
503
+ return { path, class: classifyDirtyPath(path) };
504
+ }),
505
+ classes: summarizeClasses(
506
+ verdict.unattributed.map((line) => {
507
+ const path = line.slice(3).trim();
508
+ return { path, class: classifyDirtyPath(path) };
509
+ }),
510
+ ),
511
+ toleratedState: opts.worktreeDirty.toleratedState,
512
+ toleratedDirt: verdict.tolerated,
513
+ ...(lockfile !== null ? { lockfileClassification: lockfile } : {}),
514
+ },
515
+ },
516
+ };
517
+ }
518
+ }
519
+
520
+ // (2) primary must sit clean on develop — early FLOW-INT-03, same
521
+ // classification; the post-gate check stays (primary can dirty mid-gate).
522
+ checked.push("primary-dirty");
523
+ const primaryBranch = await deps.runCurrentBranch(opts.primary, io);
524
+ const primaryDirty = await deps.runStatusTracked(opts.primary, io);
525
+ if (primaryDirty.entries.length > 0) {
526
+ const verdict = await classifyDirt(opts.primary, io, primaryDirty.entries, {
527
+ runGit: deps.runGit,
528
+ });
529
+ tolerated.push(...verdict.tolerated);
530
+ if (primaryBranch !== "develop" || verdict.unattributed.length > 0) {
531
+ const lockfile = await classifyDirtyLockfile(
532
+ opts.primary,
533
+ io,
534
+ verdict.unattributed,
535
+ deps.runGit,
536
+ );
537
+ return {
538
+ ok: false,
539
+ checked,
540
+ skipped,
541
+ tolerated,
542
+ refuse: {
543
+ ruleId: "FLOW-INT-03",
544
+ message:
545
+ (primaryBranch !== "develop"
546
+ ? `primary worktree is on ${primaryBranch ?? "detached HEAD"}, not develop`
547
+ : `primary worktree has ${verdict.unattributed.length} uncommitted change(s)`) +
548
+ (verdict.tolerated.length > 0
549
+ ? ` — tolerated regenerable state: ${verdict.tolerated.map((t) => `${t.path} (${t.class})`).join(", ")}`
550
+ : "") +
551
+ (lockfile === "importer-prune-only" ? ` — pnpm-lock.yaml${LOCKFILE_PRUNE_HINT}` : ""),
552
+ fixHint:
553
+ "switch the primary to develop and commit or revert its tracked changes, then re-run — the branch stays rebased",
554
+ data: {
555
+ entries: verdict.unattributed.map((line) => {
556
+ const path = line.slice(3).trim();
557
+ return { path, class: classifyDirtyPath(path) };
558
+ }),
559
+ toleratedDirt: verdict.tolerated,
560
+ ...(lockfile !== null ? { lockfileClassification: lockfile } : {}),
561
+ },
562
+ },
563
+ };
564
+ }
565
+ } else if (primaryBranch !== "develop") {
566
+ return {
567
+ ok: false,
568
+ checked,
569
+ skipped,
570
+ tolerated,
571
+ refuse: {
572
+ ruleId: "FLOW-INT-03",
573
+ message: `primary worktree is on ${primaryBranch ?? "detached HEAD"}, not develop`,
574
+ fixHint:
575
+ "switch the primary to develop and commit or revert its tracked changes, then re-run — the branch stays rebased",
576
+ },
577
+ };
578
+ }
579
+
580
+ // (3) ecosystem.manifest.validate — stale generated manifest refuses early.
581
+ if (resolvable("ecosystem.manifest.validate")) {
582
+ checked.push("ecosystem.manifest.validate");
583
+ const result = await opts.invoke!("ecosystem.manifest.validate", {});
584
+ if (result.ok === false || (result.exitCode !== undefined && result.exitCode !== 0)) {
585
+ return {
586
+ ok: false,
587
+ checked,
588
+ skipped,
589
+ tolerated,
590
+ refuse: {
591
+ ruleId: "FLOW-INT-12",
592
+ message: `preflight: ecosystem.manifest.validate refused — ${result.summary ?? `exit ${result.exitCode}`}`,
593
+ fixHint:
594
+ "regenerate the manifest via `pnpm exec werkstatt run ecosystem.manifest.generate`, commit, then re-run flow.integrate",
595
+ data: { command: "ecosystem.manifest.validate", summary: result.summary },
596
+ },
597
+ };
598
+ }
599
+ } else {
600
+ skipped.push({
601
+ check: "ecosystem.manifest.validate",
602
+ reason: opts.invoke === undefined ? "no-invoke" : "unresolvable",
603
+ });
604
+ }
605
+
606
+ // (4) rfc.validate --id per changed RFC file on develop...branch.
607
+ // --diff-filter=d excludes deletions — an archive move's old path must not
608
+ // produce a validate-id on a vanished file.
609
+ const diff = await deps.runGit(opts.primary, io, [
610
+ "diff",
611
+ "--name-only",
612
+ "--diff-filter=d",
613
+ `develop...${opts.branch}`,
614
+ ]);
615
+ const changedRfcIds = [
616
+ ...new Set(
617
+ diff.stdout
618
+ .split("\n")
619
+ .map(
620
+ (l) =>
621
+ /^docs\/rfcs\/(?:archive\/(?:implemented|rejected|superseded)\/)?rfc-(\d+)-[^/]*\.md$/.exec(
622
+ l.trim(),
623
+ )?.[1],
624
+ )
625
+ .filter((m): m is string => m !== undefined)
626
+ .map((n) => `RFC-${n.padStart(4, "0")}`),
627
+ ),
628
+ ];
629
+ if (changedRfcIds.length > 0) {
630
+ if (resolvable("rfc.validate")) {
631
+ for (const id of changedRfcIds) {
632
+ checked.push(`rfc.validate:${id}`);
633
+ const result = await opts.invoke!("rfc.validate", { id });
634
+ if (result.ok === false || (result.exitCode !== undefined && result.exitCode !== 0)) {
635
+ return {
636
+ ok: false,
637
+ checked,
638
+ skipped,
639
+ tolerated,
640
+ refuse: {
641
+ ruleId: "FLOW-INT-13",
642
+ message: `preflight: rfc.validate ${id} refused — ${result.summary ?? `exit ${result.exitCode}`}`,
643
+ fixHint: "fix the RFC diagnostics, commit, then re-run flow.integrate",
644
+ data: { command: "rfc.validate", id, summary: result.summary },
645
+ },
646
+ };
647
+ }
648
+ }
649
+ } else {
650
+ skipped.push({
651
+ check: "rfc.validate",
652
+ reason: opts.invoke === undefined ? "no-invoke" : "unresolvable",
653
+ });
654
+ }
655
+ }
656
+
657
+ // (5) friction.validate — a broken registry refuses early.
658
+ if (resolvable("friction.validate")) {
659
+ checked.push("friction.validate");
660
+ const result = await opts.invoke!("friction.validate", {});
661
+ if (result.ok === false || (result.exitCode !== undefined && result.exitCode !== 0)) {
662
+ return {
663
+ ok: false,
664
+ checked,
665
+ skipped,
666
+ tolerated,
667
+ refuse: {
668
+ ruleId: "FLOW-INT-14",
669
+ message: `preflight: friction.validate refused — ${result.summary ?? `exit ${result.exitCode}`}`,
670
+ fixHint:
671
+ "repair docs/frictions.yaml (e.g. a duplicate id), commit, then re-run flow.integrate",
672
+ data: { command: "friction.validate", summary: result.summary },
673
+ },
674
+ };
675
+ }
676
+ } else {
677
+ skipped.push({
678
+ check: "friction.validate",
679
+ reason: opts.invoke === undefined ? "no-invoke" : "unresolvable",
680
+ });
681
+ }
682
+
683
+ return { ok: true, checked, skipped, tolerated };
684
+ }
685
+
686
+ // ── RFC-1538: generated-conflict classification ──────────────────────────
687
+
688
+ export interface ConflictOwner {
689
+ path: string;
690
+ command: string;
691
+ flags: Record<string, ForgeFlagValue>;
692
+ }
693
+
694
+ export interface RebaseConflictVerdict {
695
+ /** Generated paths with a discoverable owner command — auto-resolvable. */
696
+ owners: ConflictOwner[];
697
+ /** Non-generated paths, or generated paths with no owner → FLOW-INT-02. */
698
+ nonGenerated: string[];
699
+ }
700
+
701
+ /** `.generated.` basenames whose owner command is fixed by convention. */
702
+ const GENERATED_BASENAME_OWNERS: Record<string, string> = {
703
+ "ecosystem.generated.yaml": "ecosystem.manifest.generate",
704
+ "command-manifest.generated.yaml": "command.manifest.generate",
705
+ };
706
+
707
+ /**
708
+ * Classify a rebase conflict set (RFC-1538): every path must classify
709
+ * generated via isGeneratedPathName/isGeneratedContent (stage-2/3 content),
710
+ * and every generated path must name an owner command — from its own
711
+ * generated header (`command:`/`regenerateCommand:`/`ownerCommand:`), or the
712
+ * `.generated.` basename registry. Anything else stays nonGenerated and the
713
+ * integrate refuses FLOW-INT-02 exactly as before.
714
+ */
715
+ export async function classifyRebaseConflicts(
716
+ repo: string,
717
+ io: WorkspaceIO,
718
+ paths: string[],
719
+ deps: { runGit: typeof git } = { runGit: git },
720
+ ): Promise<RebaseConflictVerdict> {
721
+ const owners: ConflictOwner[] = [];
722
+ const nonGenerated: string[] = [];
723
+ for (const p of paths) {
724
+ let content = "";
725
+ for (const stage of [":2:", ":3:"]) {
726
+ const r = await deps.runGit(repo, io, ["show", `${stage}${p}`]);
727
+ if (r.exitCode === 0 && r.stdout.length > 0) {
728
+ content = r.stdout;
729
+ break;
730
+ }
731
+ }
732
+ const byName = isGeneratedPathName(p);
733
+ const byContent = content !== "" && isGeneratedContent(content);
734
+ if (!byName && !byContent) {
735
+ nonGenerated.push(p);
736
+ continue;
737
+ }
738
+ const header = /^(?:command|regenerateCommand|ownerCommand):\s*(\S.*?)\s*$/m.exec(
739
+ content.split("\n").slice(0, 15).join("\n"),
740
+ )?.[1];
741
+ const line = header ?? GENERATED_BASENAME_OWNERS[basename(p)] ?? null;
742
+ if (line === null) {
743
+ nonGenerated.push(p);
744
+ continue;
745
+ }
746
+ const [name, ...rest] = line.split(/\s+/);
747
+ const flags: Record<string, ForgeFlagValue> = { ...(REGEN_FLAGS[name] ?? {}) };
748
+ for (let i = 0; i < rest.length; i++) {
749
+ const t = rest[i];
750
+ if (!t.startsWith("--")) continue;
751
+ const eq = t.indexOf("=");
752
+ if (eq > 2) {
753
+ flags[t.slice(2, eq)] = t.slice(eq + 1);
754
+ } else if (i + 1 < rest.length && !rest[i + 1].startsWith("--")) {
755
+ flags[t.slice(2)] = rest[++i];
756
+ } else {
757
+ flags[t.slice(2)] = true;
758
+ }
759
+ }
760
+ owners.push({ path: p, command: name, flags });
761
+ }
762
+ return { owners, nonGenerated };
763
+ }