@warpgogol/forge 9.3.0 → 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 (472) hide show
  1. package/AGENTS.md +32 -0
  2. package/CHANGELOG.md +33 -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 +13 -3
  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 +23 -7
  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 +18 -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/profiles/forge-shell.yaml +1 -2
  427. package/profiles/knowledge.yaml +1 -1
  428. package/profiles/system.yaml +2 -2
  429. package/profiles/typescript.yaml +0 -1
  430. package/skills/fo/fo-doctor/SKILL.md +151 -0
  431. package/skills/fo/fo-handoff/SKILL.md +22 -0
  432. package/skills/fo/fo-idea-create-rfc/acceptance-criteria-standard.md +2 -1
  433. package/skills/fo/fo-idea-implement/SKILL.md +5 -2
  434. package/skills/fo/fo-idea-plan/SKILL.md +5 -5
  435. package/skills/fo/fo-session-retro/SKILL.md +37 -11
  436. package/skills/fo/fo-spec-ingest/SKILL.md +8 -0
  437. package/skills/fo/fo-system-dispatch/SKILL.md +1 -0
  438. package/skills/meta/skill-create/SKILL.md +2 -1
  439. package/src/bin-entry.test.ts +3 -1
  440. package/src/config/forge-config.ts +57 -13
  441. package/src/conformance/index.ts +46 -1
  442. package/src/formal/proof-runner.ts +10 -2
  443. package/src/migration-adapters/node-typescript-pnpm/index.ts +3 -1
  444. package/src/migration-adapters/phaser-pnpm/index.ts +3 -1
  445. package/src/onboarding/agents-generate.ts +4 -4
  446. package/src/onboarding/nested-agents-generate.ts +3 -1
  447. package/src/onboarding/scaffold-project.ts +2 -2
  448. package/src/onboarding/upgrade.ts +13 -2
  449. package/src/onboarding/workspace-discovery.ts +3 -1
  450. package/src/pipeline-status.test.ts +1 -1
  451. package/src/skill-schema.ts +9 -2
  452. package/src/spec/resolve-spec-source.ts +184 -0
  453. package/src/tests/acceptance-probe-kinds.test.ts +3 -1
  454. package/src/tests/agents-generate-domain.test.ts +3 -2
  455. package/src/tests/agents-generate.test.ts +2 -1
  456. package/src/tests/create-flow.test.ts +3 -1
  457. package/src/tests/create.test.ts +12 -2
  458. package/src/tests/editable-generated-region.test.ts +2 -2
  459. package/src/tests/fixtures/agents-generate-business-before.txt +2 -0
  460. package/src/tests/implement-stamp.test.ts +5 -2
  461. package/src/tests/profile-flow-hooks.test.ts +15 -0
  462. package/src/tests/rfc-implement-stamp-governance.test.ts +6 -2
  463. package/src/tests/rfc-verification-verdict-ingest.test.ts +5 -1
  464. package/src/tests/scaffold-project.test.ts +3 -1
  465. package/src/tests/upgrade.test.ts +79 -3
  466. package/src/tests/workspace-discovery.test.ts +4 -3
  467. package/src/utils/command-inventory.ts +105 -0
  468. package/src/utils/io.ts +6 -1
  469. package/src/utils/repo-path.ts +49 -0
  470. package/src/utils/spawn.ts +88 -0
  471. package/src/tests/rfc-evidence-sync.test.ts +0 -369
  472. package/src/tests/skill-agents-sync.test.ts +0 -192
@@ -14,13 +14,16 @@ and return the RFC publications[] row for the journal.</purpose>
14
14
  <item>Destination resolution mirrors the retired publish-forge.mjs (RFC-1499) resolveDest(): destBase/destName parsed from extract.config.yaml, anchored at dirname(primary), destBase default "packages".</item>
15
15
  <item>Reconcile only on non-fast-forward (the same regex as the retired publish-forge.mjs, RFC-1499) — auth, hook and transient failures never trigger an ours-merge.</item>
16
16
  <item>verifyLineAtRef (RFC-1502) extracts into an mkdtemp scratch via `--dest` — the configured destination is never touched — and a spawn failure of the repo-extract binary reports as a verification failure, not a crash.</item>
17
+ <item>preflight-extract-gates (RFC-1517) reads CHANGELOG.md and package.json AT `ref` via `git show` — never the working tree: during flow.cut the freshly-written version section lives only in the release commit, so a working-tree read would false-refuse every legitimate publish.</item>
18
+ <item>preflight fails open on unreadable git objects (missing CHANGELOG, unparseable package.json, unresolvable ref) — mirroring the post-extract gate's parity-note contract; a preflight must never block a publish it cannot judge.</item>
19
+ <item>RFC-1517 r1: the fixture scan enumerates `../` candidates AT `ref` via one `git grep -nI --full-name` — the extract materializes the ref's tree, so an untracked dist/ or a post-tag fix can't false-refuse or evade the way a working-tree walk did. Each candidate path is then judged by the same isShippedEntry/literalEscapesInLine core PKG-HEALTH-10 uses.</item>
17
20
  </KEY_DECISIONS>
18
21
  <CHANGE_SUMMARY>
19
- <item>RFC-1491: independent-review pass — shared lock constants, publishable pending filter, declared rules, hold ordering, sha-pinned refspecs</item>
20
22
  <item>RFC-1499: step 2 — retire publish-forge/bump-forge scripts, add extract-verify hook</item>
21
23
  <item>RFC-1502: steps 1-5 — release-prepare hook, pre-tag extract verification, ordered steps</item>
22
24
  <item>RFC-1502: step 7 — remediation entries, docs, deviations, generated indexes</item>
23
25
  <item>RFC-1502: review r1 — fix-cut rollback on FLOW-CUT-12/13, populated steps[], hook validation, GIT_* env scrub</item>
26
+ <item>RFC-1517: add preflight-extract-gates — FLOW-PUB-01 changelog check at ref plus shared PKG-HEALTH-10 fixture-path scan for RFC-1517</item>
24
27
  <history>RFC-1491</history>
25
28
  </CHANGE_SUMMARY>
26
29
  */
@@ -30,6 +33,13 @@ import { tmpdir } from "node:os";
30
33
  import { dirname, join, resolve } from "node:path";
31
34
 
32
35
  import type { WorkspaceIO } from "../../src/types.ts";
36
+ import {
37
+ fixtureScanSkipped,
38
+ isShippedEntry,
39
+ literalEscapesInLine,
40
+ parseHealthScanConfig,
41
+ type FixtureEscape,
42
+ } from "../core/handlers/package-health.ts";
33
43
  import { git, gitCommit } from "./git.ts";
34
44
  import { runFlowScript, type FlowScriptResult } from "./scripts.ts";
35
45
  import type { ReleaseLine } from "./release-lines.ts";
@@ -84,6 +94,161 @@ export async function tagAnnotationLevel(
84
94
  return result.stdout.match(/^level:\s*(\S+)\s*$/m)?.[1] ?? null;
85
95
  }
86
96
 
97
+ interface PreflightFailure {
98
+ step: "preflight-extract-gates";
99
+ ruleId: "FLOW-PUB-01" | "PKG-HEALTH-10";
100
+ detail: string;
101
+ }
102
+
103
+ const REGEXP_META = /[.*+?^${}()|[\]\\]/g;
104
+
105
+ /**
106
+ * Keep-a-Changelog emits both `## [v]` release headings AND bare `[v]: <url>`
107
+ * link references at the file's foot — a substring `[v]` check passes a
108
+ * changelog that only links the version. The gate therefore anchors on a
109
+ * heading line (`## [v]` or `## v`); a missing file has no section.
110
+ */
111
+ export function hasChangelogSection(changelog: string | null, version: string): boolean {
112
+ if (changelog === null) return false;
113
+ const v = version.replace(REGEXP_META, "\\$&");
114
+ return new RegExp(`^#{1,6}\\s+(?:\\[${v}\\]|${v})(?=\\s|$)`, "m").test(changelog);
115
+ }
116
+
117
+ /**
118
+ * RFC-1517 `preflight-extract-gates`: refuse publish-blocking defects that are
119
+ * decidable on the source repository before any repo-extract spawn (F-0064,
120
+ * F-0072). Both checks fail open on unreadable inputs — the post-extract
121
+ * changelog gate in scripts/verify-extract.mjs stays as defense in depth.
122
+ *
123
+ * - changelog gate — the line's `CHANGELOG.md` AT `ref` must contain
124
+ * `[<version>]` for the package.json version AT `ref` (the working tree
125
+ * lags a just-created release commit; git object reads are the correct
126
+ * source). Refusal FLOW-PUB-01 names file, expected section, ordering rule.
127
+ * - fixture-path scan — every file the extract ships (derived from the same
128
+ * extract.config.yaml keys repo-extract consumes) is scanned for `../`
129
+ * literals escaping the package root through the shared
130
+ * `scanFixturePathEscapes` literal core; each escape refuses PKG-HEALTH-10
131
+ * at file:line.
132
+ */
133
+ async function preflightExtractGates(
134
+ primary: string,
135
+ io: WorkspaceIO,
136
+ opts: { line: ReleaseLine; ref: string },
137
+ ): Promise<PreflightFailure | null> {
138
+ const { line, ref } = opts;
139
+ const dir = line.paths[0];
140
+ if (dir === undefined) return null;
141
+
142
+ const configPath = join(primary, dir, "extract.config.yaml");
143
+ let configRaw: string | null = null;
144
+ try {
145
+ configRaw = await io.readFile(configPath);
146
+ } catch {
147
+ configRaw = null;
148
+ }
149
+ const projectDirRel =
150
+ configRaw?.match(/^projectDir:\s*(\S+)\s*$/m)?.[1]?.replace(/^["']|["']$/g, "") ?? dir;
151
+ const projectRoot = resolve(primary, projectDirRel);
152
+
153
+ // Changelog gate — read both files at `ref` so the checked content is
154
+ // exactly what the extract will ship.
155
+ const show = async (rel: string): Promise<string | null> => {
156
+ const res = await git(primary, io, ["show", `${ref}:${rel}`]);
157
+ return res.exitCode === 0 ? res.stdout : null;
158
+ };
159
+ const pkgJsonRaw = await show(`${projectDirRel}/package.json`);
160
+ let version: string | null = null;
161
+ if (pkgJsonRaw !== null) {
162
+ try {
163
+ const parsed = JSON.parse(pkgJsonRaw) as { version?: unknown };
164
+ version = typeof parsed.version === "string" ? parsed.version : null;
165
+ } catch {
166
+ version = null;
167
+ }
168
+ }
169
+ const changelogRaw = await show(`${projectDirRel}/CHANGELOG.md`);
170
+ // Parity with the post-extract gate: an absent CHANGELOG.md is a parity-note
171
+ // skip, not a refusal; an unreadable/non-string version cannot yield the
172
+ // expected section, so the same blind spot the post-extract gate carries is
173
+ // preserved rather than diverged.
174
+ if (version !== null && changelogRaw !== null && !hasChangelogSection(changelogRaw, version)) {
175
+ return {
176
+ step: "preflight-extract-gates",
177
+ ruleId: "FLOW-PUB-01",
178
+ detail:
179
+ `${projectDirRel}/CHANGELOG.md has no [${version}] release section; ` +
180
+ `write the version section before publishing (packages/AGENTS.md publish-order rule). repo-extract was NOT spawned.`,
181
+ };
182
+ }
183
+
184
+ // Fixture-path scan — enumerate `../` candidates AT `ref` via one
185
+ // `git grep` (the extract materializes the ref's tree, so the scan sees
186
+ // exactly what ships: untracked dist/ output and post-tag fixes are both
187
+ // handled correctly). `-I` skips binary files; each matched path is then
188
+ // judged by the same shipped-entry predicate + literal matcher
189
+ // PKG-HEALTH-10 uses on the working tree.
190
+ const scanCfg = parseHealthScanConfig(configRaw);
191
+ const grep = await git(primary, io, [
192
+ "grep",
193
+ "-n",
194
+ "-I",
195
+ "--full-name",
196
+ "-e",
197
+ "\\.\\./",
198
+ ref,
199
+ "--",
200
+ projectDirRel,
201
+ ]);
202
+ const escapes: FixtureEscape[] = [];
203
+ if (grep.exitCode === 0) {
204
+ for (const row of grep.stdout.split("\n")) {
205
+ if (!row.startsWith(`${ref}:`)) continue;
206
+ const rest = row.slice(ref.length + 1);
207
+ const m = rest.match(/^(.+?):(\d+):(.*)$/);
208
+ if (!m) continue;
209
+ const [, relPath, lineNo, text] = m;
210
+ const rel = relPath!.slice(projectDirRel.length + 1);
211
+ const name = rel.split("/").pop()!;
212
+ if (
213
+ scanCfg.suppressions.has(rel) ||
214
+ fixtureScanSkipped(rel) ||
215
+ !isShippedEntry(rel, name, false, scanCfg)
216
+ ) {
217
+ continue;
218
+ }
219
+ escapes.push(
220
+ ...literalEscapesInLine(
221
+ rel,
222
+ text!,
223
+ Number(lineNo),
224
+ dirname(join(projectRoot, rel)),
225
+ projectRoot,
226
+ ),
227
+ );
228
+ }
229
+ }
230
+ escapes.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line);
231
+ if (escapes.length > 0) {
232
+ const listed = escapes
233
+ .slice(0, 5)
234
+ .map(
235
+ (e) =>
236
+ `${projectDirRel}/${e.file}:${e.line} fixture path "${e.literal}" ` +
237
+ `resolves outside ${projectDirRel}`,
238
+ )
239
+ .join("; ");
240
+ const more = escapes.length > 5 ? ` (+${escapes.length - 5} more)` : "";
241
+ return {
242
+ step: "preflight-extract-gates",
243
+ ruleId: "PKG-HEALTH-10",
244
+ detail:
245
+ `${listed}${more}; shipped files must reference paths inside the package root (same-line "// pkg-health-10:" suppression or pkgHealth10Suppressions in extract.config.yaml for justified non-path literals). ` +
246
+ `repo-extract was NOT spawned.`,
247
+ };
248
+ }
249
+ return null;
250
+ }
251
+
87
252
  /**
88
253
  * Publish one package-line tag: extract at the tag ref, verify via the hook,
89
254
  * push the destination. A non-fast-forward rejection reconciles once with
@@ -118,10 +283,25 @@ export async function publishTag(
118
283
  return row;
119
284
  }
120
285
 
286
+ // 0. preflight-extract-gates (RFC-1517) — refuse source-derivable
287
+ // publish-blocking defects before the repo-extract spawn.
288
+ const preflight = await preflightExtractGates(primary, io, { line, ref: tag });
289
+ if (preflight !== null) {
290
+ row.status = "failed";
291
+ row.error = `${preflight.step}: ${preflight.ruleId} — ${preflight.detail}`;
292
+ return row;
293
+ }
294
+
121
295
  // 1. Extract — the binary lives in the adopting repository's own install.
296
+ // node_modules/.bin/repo-extract is a POSIX sh shim even on Windows (the
297
+ // package ships one file), so the extract runs through `sh` — same seam
298
+ // flow scripts already use — rather than spawning the shim as an exec.
122
299
  const extract = await io.exec(
123
- join(primary, "node_modules", ".bin", "repo-extract"),
124
- ["--config", `${dir}/extract.config.yaml`, "--ref", tag, "--no-push"],
300
+ "sh",
301
+ [
302
+ join(primary, "node_modules", ".bin", "repo-extract"),
303
+ "--config", `${dir}/extract.config.yaml`, "--ref", tag, "--no-push",
304
+ ],
125
305
  { cwd: primary },
126
306
  );
127
307
  if (extract.exitCode !== 0) {
@@ -230,14 +410,29 @@ export async function verifyLineAtRef(
230
410
  if (dir === undefined || !(await io.exists(join(primary, dir, "extract.config.yaml")))) {
231
411
  return { ok: true, skipped: true, detail: "" };
232
412
  }
413
+ // preflight-extract-gates (RFC-1517) — source-derivable refusals before
414
+ // the scratch extract: changelog section at ref, fixture-path escapes.
415
+ const preflight = await preflightExtractGates(primary, io, { line, ref });
416
+ if (preflight !== null) {
417
+ return {
418
+ ok: false,
419
+ skipped: false,
420
+ detail: `${preflight.step}: ${preflight.ruleId} — ${preflight.detail}`,
421
+ };
422
+ }
233
423
  const scratch = await mkdtemp(join(tmpdir(), "flow-extract-"));
234
424
  try {
235
425
  const extractBin = join(primary, "node_modules", ".bin", "repo-extract");
236
426
  let extract;
237
427
  try {
428
+ // The .bin shim is a POSIX sh script — exec it through sh so the
429
+ // verification extract works on Windows runners as well as POSIX.
238
430
  extract = await io.exec(
239
- extractBin,
240
- ["--config", `${dir}/extract.config.yaml`, "--ref", ref, "--dest", scratch, "--no-push"],
431
+ "sh",
432
+ [
433
+ extractBin,
434
+ "--config", `${dir}/extract.config.yaml`, "--ref", ref, "--dest", scratch, "--no-push",
435
+ ],
241
436
  { cwd: primary },
242
437
  );
243
438
  } catch (error) {
@@ -17,16 +17,18 @@ forge/journal.jsonl.</purpose>
17
17
  <item>`held` is typed null now — the wave-2 outbound RFC widens it to { heldAt, riskCategory, reason }.</item>
18
18
  </KEY_DECISIONS>
19
19
  <CHANGE_SUMMARY>
20
- <item>RFC-1487: step 1 — worktree path contracts, O_EXCL locks, branch registry and journal</item>
21
- <item>RFC-1490: step 2 — registry fix/port widening, FORGE_FLOW_COMMIT gitCommit helper, verified version-files writes</item>
22
- <item>RFC-1491: step 1 — journal base/rewrites + held registry widening, W1-1 discard tip, FLOW-INT-11</item>
23
- <item>RFC-1491: step 3 — flow.digest risk digest with journal-attributed items, categories, digestId</item>
24
20
  <item>RFC-1503: steps 1-5 — highest-per-line pending selection, publish-superseded/publish-retired journal events, flow.publication.retire</item>
25
- <history>RFC-1487</history>
21
+ <item>RFC-1515: close rfc-1515 review findings — delete tolerated paths before worktree remove, prune vanished registrations, verified branch -D, shared held-lock render, gated e2e throw, journal toleratedState, edge tests</item>
22
+ <item>RFC-1537: integrate-refusal journal event + rule/toleratedDirt fields — every flow.integrate refusal journals {branch, rule, summary, at} for flow.status lastRefusal; appendJournal now serializes toleratedState (was silently dropped)</item>
23
+ <item>RFC-1532: FlowJournalEvent.gateReport — the repo-relative path links integrate/backmerge and integrate-refusal events to the attempt's persisted gate report</item>
24
+ <item>RFC-1538: revalidate integration preconditions post-lock and reuse the session engine</item>
25
+ <item>RFC-1531: add flow.integrate remediation flags on the shared dirty classifier</item>
26
+ <history>RFC-1487, RFC-1490, RFC-1491</history>
26
27
  </CHANGE_SUMMARY>
27
28
  */
28
29
 
29
30
  import { dirname, isAbsolute, join, resolve } from "node:path";
31
+ import { canonicalRepoDir } from "../../src/utils/repo-path.ts";
30
32
 
31
33
  import { parse as yamlParse, stringify as yamlStringify } from "yaml";
32
34
  import { z } from "zod";
@@ -133,12 +135,35 @@ export interface FlowJournalEvent {
133
135
  | "push"
134
136
  | "publish"
135
137
  | "publish-superseded"
136
- | "publish-retired";
138
+ | "publish-retired"
139
+ | "integrate-refusal";
137
140
  branch: string;
138
141
  sha: string;
139
142
  detail: string;
140
143
  /** develop before (integrate/backmerge/cut/hold); branch base (discard) — W1-1. */
141
144
  base?: string;
145
+ /** RFC-1537: diagnostic rule id on integrate-refusal (FLOW-INT-01/WT-GATE-01/…)
146
+ * — flow.status renders it as lastRefusal.rule. */
147
+ rule?: string;
148
+ /** RFC-1515: forge-local state the integrate/discard tolerated and deleted
149
+ * with the worktree — recorded so the journal carries the allowlist hit. */
150
+ toleratedState?: string[];
151
+ /** RFC-1537: declared regenerable dirt tolerated during integrate —
152
+ * {path, class} per classified path. */
153
+ toleratedDirt?: Array<{ path: string; class: string }>;
154
+ /** RFC-1538: generated conflict paths auto-resolved by owner regeneration
155
+ * during the integrate's rebase. */
156
+ autoResolved?: string[];
157
+ /** RFC-1531: worktree path --reattach recreated before the integrate. */
158
+ reattachedTo?: string;
159
+ /** RFC-1531: disposable-class paths --auto-clean deleted. */
160
+ autoCleaned?: string[];
161
+ /** RFC-1531: sha of the --autocommit sweep commit that landed with the branch. */
162
+ autocommitSha?: string;
163
+ /** RFC-1532: repo-relative `gate-reports/<file>` for integrate/backmerge
164
+ * events whose gate wrote a report — the journal's link to the attempt's
165
+ * full check evidence. */
166
+ gateReport?: string;
142
167
  /** hold only — the new (base, sha] range of every replayed item. */
143
168
  rewrites?: Array<{
144
169
  branch: string;
@@ -168,7 +193,10 @@ export async function commonGitDir(io: WorkspaceIO, cwd: string): Promise<string
168
193
  );
169
194
  }
170
195
  const dir = result.stdout.trim();
171
- return isAbsolute(dir) ? dir : resolve(cwd, dir);
196
+ // Canonicalize — a linked worktree's --git-common-dir answer (absolute,
197
+ // git's frame) and a primary's relative `.git` must compare equal when
198
+ // they name the same directory, including across Windows 8.3 aliases.
199
+ return canonicalRepoDir(isAbsolute(dir) ? dir : resolve(cwd, dir));
172
200
  }
173
201
 
174
202
  /** Read the registry; a missing file yields the empty registry. */
@@ -244,6 +272,14 @@ export async function appendJournal(
244
272
  detail: event.detail,
245
273
  };
246
274
  if (event.base !== undefined) line.base = event.base;
275
+ if (event.rule !== undefined) line.rule = event.rule;
276
+ if (event.toleratedState !== undefined) line.toleratedState = event.toleratedState;
277
+ if (event.toleratedDirt !== undefined) line.toleratedDirt = event.toleratedDirt;
278
+ if (event.autoResolved !== undefined) line.autoResolved = event.autoResolved;
279
+ if (event.reattachedTo !== undefined) line.reattachedTo = event.reattachedTo;
280
+ if (event.autoCleaned !== undefined) line.autoCleaned = event.autoCleaned;
281
+ if (event.autocommitSha !== undefined) line.autocommitSha = event.autocommitSha;
282
+ if (event.gateReport !== undefined) line.gateReport = event.gateReport;
247
283
  if (event.rewrites !== undefined) line.rewrites = event.rewrites;
248
284
  await io.appendFile(file, `${JSON.stringify(line)}\n`);
249
285
  }
@@ -15,6 +15,7 @@ the branch worktree and the declared FLOW_* environment.</purpose>
15
15
  <item>stderrTail is the last 40 lines — enough for the report without flooding it (DNA-106).</item>
16
16
  </KEY_DECISIONS>
17
17
  <CHANGE_SUMMARY>
18
+ <item>RFC-1532: parse the integration-gate's `gate-report:` stdout marker into FlowScriptResult.reportPath</item>
18
19
  <item>RFC-1487: step 2 — primary-side hook-script runner</item>
19
20
  <item>RFC-1490: step 4 — ordinary flow.cut (release branch, verified versions, gate, main swap, tags, resume)</item>
20
21
  <item>RFC-1491: step 5 — flow.push atomic outbound path + extract publication</item>
@@ -40,6 +41,10 @@ export interface FlowScriptResult {
40
41
  stderrTail: string;
41
42
  /** stdout truncated to 64 KiB with a trailing `…[truncated]` marker. */
42
43
  stdout: string;
44
+ /** RFC-1532: repo-relative `gate-reports/<file>` parsed from the
45
+ * integration-gate's stdout marker; null when the gate wrote none (or a
46
+ * WT-GATE-07 write failure), absent for other scripts and older gates. */
47
+ reportPath?: string | null;
43
48
  }
44
49
 
45
50
  const STDERR_TAIL_LINES = 40;
@@ -60,16 +65,27 @@ export async function runFlowScript(
60
65
  return { status: "skipped", exitCode: null, stderrTail: "", stdout: "" };
61
66
  }
62
67
  const result = await io.exec("sh", [scriptPath], { cwd: opts.cwd, env: opts.env });
63
- const tail = result.stderr
64
- .split("\n")
65
- .filter((line) => line.length > 0)
66
- .slice(-STDERR_TAIL_LINES)
67
- .join("\n");
68
+ // A failing hook may report only on stdout (forge commands do); an empty tail
69
+ // would leave the refusal without a reason.
70
+ const tailOf = (text: string): string =>
71
+ text
72
+ .split("\n")
73
+ .filter((line) => line.length > 0)
74
+ .slice(-STDERR_TAIL_LINES)
75
+ .join("\n");
76
+ const stderrTail = tailOf(result.stderr);
77
+ const tail = stderrTail === "" && result.exitCode !== 0 ? tailOf(result.stdout) : stderrTail;
68
78
  const stdout =
69
79
  result.stdout.length > STDOUT_CAP
70
80
  ? `${result.stdout.slice(0, STDOUT_CAP)}…[truncated]`
71
81
  : result.stdout;
82
+ // RFC-1532: the gate prints `gate-report: <repo-relative path>` on stdout —
83
+ // the only channel through the --quiet hook wrapper.
84
+ const reportPath =
85
+ name === "integration-gate"
86
+ ? (result.stdout.match(/^gate-report: (\S+)\s*$/m)?.[1] ?? null)
87
+ : undefined;
72
88
  return result.exitCode === 0
73
- ? { status: "done", exitCode: result.exitCode, stderrTail: tail, stdout }
74
- : { status: "failed", exitCode: result.exitCode, stderrTail: tail, stdout };
89
+ ? { status: "done", exitCode: result.exitCode, stderrTail: tail, stdout, ...(reportPath !== undefined ? { reportPath } : {}) }
90
+ : { status: "failed", exitCode: result.exitCode, stderrTail: tail, stdout, ...(reportPath !== undefined ? { reportPath } : {}) };
75
91
  }
@@ -0,0 +1,186 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1536: owning-checkout resolution for session-artifact writes.
4
+ Commands that produce durable session artifacts (session.save, docs.archive,
5
+ …) must write into the checkout that owns the session — the registered
6
+ auto/* worktree — instead of trusting cwd. This module decides which
7
+ checkout owns a write, given the invocation cwd.</purpose>
8
+ <non-goals>
9
+ <item>No cross-clone attribution — the registry lives in the common git dir; a different clone is invisible by design (bounded consequence, RFC-1536 failure modes).</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <KEY_DECISIONS>
13
+ <item>Attribution precedence: the registry `owner` field is authoritative (durable, lock-written at flow.open); the WERKSTATT_AGENT_ID env is only a fallback hint for pre-registry contexts. Disagreement between the two is a refusal, never a guess.</item>
14
+ <item>Exactly one live session worktree is unambiguous attribution — an owner.id of "unspecified" still routes, because no other session can own the write.</item>
15
+ <item>No registered session worktree at all → kind "primary" — the solo primary flow that worked before keeps working (degrade, never block).</item>
16
+ </KEY_DECISIONS>
17
+ <CHANGE_SUMMARY>
18
+ <item>RFC-1536: owning-checkout resolution for session-artifact writes</item>
19
+ <item>RFC-1536: owning-checkout routing, FLOW-OPEN-01 dirty-primary warning, shared governance-id allocation (RFC+ADR)</item>
20
+ <item>RFC-1536: session-checkout bare-repo degrade to primary semantics</item>
21
+ <item>RFC-1536: type forge flow and rfc io against forge's own WorkspaceIO
22
+
23
+ The standalone forge extract has no @warpgogol/werkstatt-shared; the type-only import failed extract-verify (FLOW-CUT-13) for the 9.4.0 cut.</item>
24
+ </CHANGE_SUMMARY>
25
+ */
26
+
27
+ import { realpath } from "node:fs/promises";
28
+
29
+ import type { WorkspaceIO } from "../../src/types.ts";
30
+
31
+ import { topLevel } from "./git.ts";
32
+ import { commonGitDir, readRegistry, type FlowRegistryEntry } from "./registry.ts";
33
+ import { primaryWorktree } from "./worktree-path.ts";
34
+
35
+ export interface OwningCheckout {
36
+ kind: "primary" | "worktree";
37
+ /** Registered worktree path owning the writes — set when kind === "worktree". */
38
+ worktreePath?: string;
39
+ /** Registered auto/* branch owning the writes — set when kind === "worktree". */
40
+ sessionBranch?: string;
41
+ }
42
+
43
+ export type OwningCheckoutResult =
44
+ | { ok: true; checkout: OwningCheckout; warnings: string[] }
45
+ | {
46
+ ok: false;
47
+ /** SESSION-WRITE-01 detail — registered session worktrees exist but none is attributable. */
48
+ reason: string;
49
+ candidates: string[];
50
+ };
51
+
52
+ /** Env hints consulted for attribution, strongest first. */
53
+ const AGENT_ID_ENV = ["WERKSTATT_AGENT_ID", "AI_AGENT"] as const;
54
+
55
+ function agentIdHint(): string | null {
56
+ for (const name of AGENT_ID_ENV) {
57
+ const value = process.env[name]?.trim();
58
+ if (value) return value;
59
+ }
60
+ return null;
61
+ }
62
+
63
+ async function samePath(a: string, b: string): Promise<boolean> {
64
+ try {
65
+ return (await realpath(a)) === (await realpath(b));
66
+ } catch {
67
+ return a === b;
68
+ }
69
+ }
70
+
71
+ /** Live session entries: kind session, a worktree path that still exists. */
72
+ async function liveSessionEntries(
73
+ io: WorkspaceIO,
74
+ entries: FlowRegistryEntry[],
75
+ ): Promise<FlowRegistryEntry[]> {
76
+ const live: FlowRegistryEntry[] = [];
77
+ for (const entry of entries) {
78
+ if (entry.kind !== "session" || entry.worktree === null) continue;
79
+ if (await io.exists(entry.worktree)) live.push(entry);
80
+ }
81
+ return live;
82
+ }
83
+
84
+ /**
85
+ * Decide which checkout owns a session-artifact write invoked at `cwd`.
86
+ *
87
+ * - cwd inside a registered worktree → that worktree (the write already lands
88
+ * in the owning checkout; callers keep their cwd-relative behavior).
89
+ * - cwd == primary (or anywhere outside registered worktrees):
90
+ * - an explicit sessionId / env hint matching exactly one entry → route;
91
+ * - a hint matching nothing while session worktrees exist → refuse (the
92
+ * registry is authoritative; disagreement is never resolved by guess);
93
+ * - no hint: exactly one live session worktree → route; more → refuse;
94
+ * - zero live session worktrees → primary (degrade).
95
+ * - Registry read failure → primary with a warning (solo flow keeps working).
96
+ */
97
+ export async function resolveOwningCheckout(
98
+ io: WorkspaceIO,
99
+ cwd: string,
100
+ sessionId?: string,
101
+ ): Promise<OwningCheckoutResult> {
102
+ const warnings: string[] = [];
103
+ const repoRoot = await topLevel(cwd, io);
104
+ if (repoRoot === null) {
105
+ return { ok: true, checkout: { kind: "primary" }, warnings };
106
+ }
107
+
108
+ let entries: FlowRegistryEntry[];
109
+ try {
110
+ const common = await commonGitDir(io, repoRoot);
111
+ const registry = await readRegistry(io, common);
112
+ entries = registry.branches;
113
+ } catch (error) {
114
+ warnings.push(
115
+ `flow registry unreadable — degrading to cwd semantics: ${(error as Error).message}`,
116
+ );
117
+ return { ok: true, checkout: { kind: "primary" }, warnings };
118
+ }
119
+
120
+ for (const entry of entries) {
121
+ if (entry.worktree !== null && (await samePath(cwd, entry.worktree))) {
122
+ return {
123
+ ok: true,
124
+ checkout: { kind: "worktree", worktreePath: entry.worktree, sessionBranch: entry.name },
125
+ warnings,
126
+ };
127
+ }
128
+ }
129
+
130
+ const live = await liveSessionEntries(io, entries);
131
+ if (live.length === 0) {
132
+ return { ok: true, checkout: { kind: "primary" }, warnings };
133
+ }
134
+
135
+ let primary: string;
136
+ try {
137
+ primary = await primaryWorktree(io, repoRoot);
138
+ } catch {
139
+ // Bare repo or unreadable worktree list — keep cwd semantics.
140
+ return { ok: true, checkout: { kind: "primary" }, warnings };
141
+ }
142
+ if (!(await samePath(cwd, primary))) {
143
+ // cwd is neither a registered worktree nor the primary — a bare/other
144
+ // checkout the flow model does not govern; keep cwd semantics.
145
+ return { ok: true, checkout: { kind: "primary" }, warnings };
146
+ }
147
+
148
+ const hint = sessionId ?? agentIdHint();
149
+ if (hint !== null) {
150
+ const matched = live.filter((e) => e.owner.id === hint);
151
+ if (matched.length === 1) {
152
+ return {
153
+ ok: true,
154
+ checkout: {
155
+ kind: "worktree",
156
+ worktreePath: matched[0].worktree ?? undefined,
157
+ sessionBranch: matched[0].name,
158
+ },
159
+ warnings,
160
+ };
161
+ }
162
+ return {
163
+ ok: false,
164
+ reason: `session hint '${hint}' matches ${matched.length} of ${live.length} live session worktree(s) — registry owner is authoritative`,
165
+ candidates: live.map((e) => `${e.name} (owner ${e.owner.id})`),
166
+ };
167
+ }
168
+
169
+ if (live.length === 1) {
170
+ return {
171
+ ok: true,
172
+ checkout: {
173
+ kind: "worktree",
174
+ worktreePath: live[0].worktree ?? undefined,
175
+ sessionBranch: live[0].name,
176
+ },
177
+ warnings,
178
+ };
179
+ }
180
+
181
+ return {
182
+ ok: false,
183
+ reason: `${live.length} live session worktrees and no session hint — cannot attribute the write`,
184
+ candidates: live.map((e) => `${e.name} (owner ${e.owner.id})`),
185
+ };
186
+ }