@warpgogol/forge 9.2.3 → 9.3.1

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 (252) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/bin/cli.ts +3 -2
  3. package/dist/bin/cli.js +3 -2
  4. package/dist/bin/cli.js.map +1 -1
  5. package/dist/os/adr/handlers/implement-stamp.d.ts +6 -0
  6. package/dist/os/adr/handlers/implement-stamp.d.ts.map +1 -1
  7. package/dist/os/adr/handlers/implement-stamp.js +23 -15
  8. package/dist/os/adr/handlers/implement-stamp.js.map +1 -1
  9. package/dist/os/checks/handlers/counters-journal.d.ts.map +1 -1
  10. package/dist/os/checks/handlers/counters-journal.js +9 -1
  11. package/dist/os/checks/handlers/counters-journal.js.map +1 -1
  12. package/dist/os/core/core.module.d.ts.map +1 -1
  13. package/dist/os/core/core.module.js +27 -36
  14. package/dist/os/core/core.module.js.map +1 -1
  15. package/dist/os/core/lock-holder.d.ts +32 -0
  16. package/dist/os/core/lock-holder.d.ts.map +1 -0
  17. package/dist/os/core/lock-holder.js +81 -0
  18. package/dist/os/core/lock-holder.js.map +1 -0
  19. package/dist/os/core/stamp-lock.d.ts +30 -0
  20. package/dist/os/core/stamp-lock.d.ts.map +1 -0
  21. package/dist/os/core/stamp-lock.js +112 -0
  22. package/dist/os/core/stamp-lock.js.map +1 -0
  23. package/dist/os/flow/digest.d.ts +19 -0
  24. package/dist/os/flow/digest.d.ts.map +1 -1
  25. package/dist/os/flow/digest.js +33 -4
  26. package/dist/os/flow/digest.js.map +1 -1
  27. package/dist/os/flow/flow.module.d.ts.map +1 -1
  28. package/dist/os/flow/flow.module.js +61 -6
  29. package/dist/os/flow/flow.module.js.map +1 -1
  30. package/dist/os/flow/handlers/flow-cut.d.ts +8 -0
  31. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
  32. package/dist/os/flow/handlers/flow-cut.js +91 -5
  33. package/dist/os/flow/handlers/flow-cut.js.map +1 -1
  34. package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
  35. package/dist/os/flow/handlers/flow-digest.js +6 -0
  36. package/dist/os/flow/handlers/flow-digest.js.map +1 -1
  37. package/dist/os/flow/handlers/flow-discard.d.ts.map +1 -1
  38. package/dist/os/flow/handlers/flow-discard.js +17 -13
  39. package/dist/os/flow/handlers/flow-discard.js.map +1 -1
  40. package/dist/os/flow/handlers/flow-fix.d.ts.map +1 -1
  41. package/dist/os/flow/handlers/flow-fix.js +99 -10
  42. package/dist/os/flow/handlers/flow-fix.js.map +1 -1
  43. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
  44. package/dist/os/flow/handlers/flow-integrate.js +32 -15
  45. package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
  46. package/dist/os/flow/handlers/flow-publication-retire.d.ts +17 -0
  47. package/dist/os/flow/handlers/flow-publication-retire.d.ts.map +1 -0
  48. package/dist/os/flow/handlers/flow-publication-retire.js +132 -0
  49. package/dist/os/flow/handlers/flow-publication-retire.js.map +1 -0
  50. package/dist/os/flow/handlers/flow-push.d.ts +7 -0
  51. package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
  52. package/dist/os/flow/handlers/flow-push.js +106 -15
  53. package/dist/os/flow/handlers/flow-push.js.map +1 -1
  54. package/dist/os/flow/locks.d.ts +6 -1
  55. package/dist/os/flow/locks.d.ts.map +1 -1
  56. package/dist/os/flow/locks.js +53 -23
  57. package/dist/os/flow/locks.js.map +1 -1
  58. package/dist/os/flow/publication-order.d.ts +25 -0
  59. package/dist/os/flow/publication-order.d.ts.map +1 -0
  60. package/dist/os/flow/publication-order.js +75 -0
  61. package/dist/os/flow/publication-order.js.map +1 -0
  62. package/dist/os/flow/publish.d.ts +18 -0
  63. package/dist/os/flow/publish.d.ts.map +1 -1
  64. package/dist/os/flow/publish.js +58 -2
  65. package/dist/os/flow/publish.js.map +1 -1
  66. package/dist/os/flow/registry.d.ts +1 -1
  67. package/dist/os/flow/registry.d.ts.map +1 -1
  68. package/dist/os/flow/registry.js +2 -1
  69. package/dist/os/flow/registry.js.map +1 -1
  70. package/dist/os/flow/release-tags.d.ts +1 -0
  71. package/dist/os/flow/release-tags.d.ts.map +1 -1
  72. package/dist/os/flow/release-tags.js +5 -4
  73. package/dist/os/flow/release-tags.js.map +1 -1
  74. package/dist/os/flow/scripts.d.ts +1 -1
  75. package/dist/os/flow/scripts.d.ts.map +1 -1
  76. package/dist/os/flow/scripts.js +6 -1
  77. package/dist/os/flow/scripts.js.map +1 -1
  78. package/dist/os/flow/task-files.d.ts +11 -0
  79. package/dist/os/flow/task-files.d.ts.map +1 -0
  80. package/dist/os/flow/task-files.js +51 -0
  81. package/dist/os/flow/task-files.js.map +1 -0
  82. package/dist/os/flow/tests/helpers.d.ts +4 -1
  83. package/dist/os/flow/tests/helpers.d.ts.map +1 -1
  84. package/dist/os/flow/tests/helpers.js +9 -5
  85. package/dist/os/flow/tests/helpers.js.map +1 -1
  86. package/dist/os/mission/handlers/archive.d.ts.map +1 -1
  87. package/dist/os/mission/handlers/archive.js +30 -74
  88. package/dist/os/mission/handlers/archive.js.map +1 -1
  89. package/dist/os/mission/lockfile.d.ts +21 -0
  90. package/dist/os/mission/lockfile.d.ts.map +1 -0
  91. package/dist/os/mission/lockfile.js +76 -0
  92. package/dist/os/mission/lockfile.js.map +1 -0
  93. package/dist/os/mission/mission.module.d.ts.map +1 -1
  94. package/dist/os/mission/mission.module.js +2 -1
  95. package/dist/os/mission/mission.module.js.map +1 -1
  96. package/dist/os/rfc/handlers/implement-stamp.d.ts +6 -0
  97. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  98. package/dist/os/rfc/handlers/implement-stamp.js +24 -19
  99. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  100. package/dist/os/system/handlers/outbox-validate.d.ts +8 -0
  101. package/dist/os/system/handlers/outbox-validate.d.ts.map +1 -0
  102. package/dist/os/system/handlers/outbox-validate.js +102 -0
  103. package/dist/os/system/handlers/outbox-validate.js.map +1 -0
  104. package/dist/os/system/handlers/system-map-validate.d.ts +13 -0
  105. package/dist/os/system/handlers/system-map-validate.d.ts.map +1 -0
  106. package/dist/os/system/handlers/system-map-validate.js +78 -0
  107. package/dist/os/system/handlers/system-map-validate.js.map +1 -0
  108. package/dist/os/system/handlers/system-outbox-scan.d.ts +10 -0
  109. package/dist/os/system/handlers/system-outbox-scan.d.ts.map +1 -0
  110. package/dist/os/system/handlers/system-outbox-scan.js +195 -0
  111. package/dist/os/system/handlers/system-outbox-scan.js.map +1 -0
  112. package/dist/os/system/handlers/system-task-collect.d.ts +13 -0
  113. package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -0
  114. package/dist/os/system/handlers/system-task-collect.js +238 -0
  115. package/dist/os/system/handlers/system-task-collect.js.map +1 -0
  116. package/dist/os/system/handlers/system-task-create.d.ts +32 -0
  117. package/dist/os/system/handlers/system-task-create.d.ts.map +1 -0
  118. package/dist/os/system/handlers/system-task-create.js +216 -0
  119. package/dist/os/system/handlers/system-task-create.js.map +1 -0
  120. package/dist/os/system/handlers/system-task-dispatch.d.ts +14 -0
  121. package/dist/os/system/handlers/system-task-dispatch.d.ts.map +1 -0
  122. package/dist/os/system/handlers/system-task-dispatch.js +290 -0
  123. package/dist/os/system/handlers/system-task-dispatch.js.map +1 -0
  124. package/dist/os/system/handlers/system-task-move.d.ts +12 -0
  125. package/dist/os/system/handlers/system-task-move.d.ts.map +1 -0
  126. package/dist/os/system/handlers/system-task-move.js +217 -0
  127. package/dist/os/system/handlers/system-task-move.js.map +1 -0
  128. package/dist/os/system/handlers/system-task-status.d.ts +20 -0
  129. package/dist/os/system/handlers/system-task-status.d.ts.map +1 -0
  130. package/dist/os/system/handlers/system-task-status.js +139 -0
  131. package/dist/os/system/handlers/system-task-status.js.map +1 -0
  132. package/dist/os/system/handlers/system-versionset-record.d.ts +12 -0
  133. package/dist/os/system/handlers/system-versionset-record.d.ts.map +1 -0
  134. package/dist/os/system/handlers/system-versionset-record.js +332 -0
  135. package/dist/os/system/handlers/system-versionset-record.js.map +1 -0
  136. package/dist/os/system/index.d.ts +6 -0
  137. package/dist/os/system/index.d.ts.map +1 -0
  138. package/dist/os/system/index.js +18 -0
  139. package/dist/os/system/index.js.map +1 -0
  140. package/dist/os/system/outbox-schema.d.ts +30 -0
  141. package/dist/os/system/outbox-schema.d.ts.map +1 -0
  142. package/dist/os/system/outbox-schema.js +29 -0
  143. package/dist/os/system/outbox-schema.js.map +1 -0
  144. package/dist/os/system/repo.d.ts +64 -0
  145. package/dist/os/system/repo.d.ts.map +1 -0
  146. package/dist/os/system/repo.js +364 -0
  147. package/dist/os/system/repo.js.map +1 -0
  148. package/dist/os/system/scenario-schemas.d.ts +26 -0
  149. package/dist/os/system/scenario-schemas.d.ts.map +1 -0
  150. package/dist/os/system/scenario-schemas.js +53 -0
  151. package/dist/os/system/scenario-schemas.js.map +1 -0
  152. package/dist/os/system/schemas.d.ts +63 -0
  153. package/dist/os/system/schemas.d.ts.map +1 -0
  154. package/dist/os/system/schemas.js +83 -0
  155. package/dist/os/system/schemas.js.map +1 -0
  156. package/dist/os/system/system.module.d.ts +3 -0
  157. package/dist/os/system/system.module.d.ts.map +1 -0
  158. package/dist/os/system/system.module.js +429 -0
  159. package/dist/os/system/system.module.js.map +1 -0
  160. package/dist/os/system/task-schemas.d.ts +108 -0
  161. package/dist/os/system/task-schemas.d.ts.map +1 -0
  162. package/dist/os/system/task-schemas.js +152 -0
  163. package/dist/os/system/task-schemas.js.map +1 -0
  164. package/dist/os/system/task-store.d.ts +41 -0
  165. package/dist/os/system/task-store.d.ts.map +1 -0
  166. package/dist/os/system/task-store.js +142 -0
  167. package/dist/os/system/task-store.js.map +1 -0
  168. package/dist/os/system/tests/helpers.d.ts +30 -0
  169. package/dist/os/system/tests/helpers.d.ts.map +1 -0
  170. package/dist/os/system/tests/helpers.js +178 -0
  171. package/dist/os/system/tests/helpers.js.map +1 -0
  172. package/dist/src/index.d.ts +3 -0
  173. package/dist/src/index.d.ts.map +1 -1
  174. package/dist/src/index.js +5 -4
  175. package/dist/src/index.js.map +1 -1
  176. package/os/adr/handlers/implement-stamp-lock.test.ts +90 -0
  177. package/os/adr/handlers/implement-stamp.ts +29 -20
  178. package/os/checks/handlers/counters-journal.test.ts +10 -0
  179. package/os/checks/handlers/counters-journal.ts +8 -1
  180. package/os/core/core.module.ts +32 -36
  181. package/os/core/lock-holder.ts +88 -0
  182. package/os/core/stamp-lock.ts +142 -0
  183. package/os/flow/digest.ts +46 -4
  184. package/os/flow/flow.module.ts +62 -6
  185. package/os/flow/handlers/flow-cut.ts +118 -5
  186. package/os/flow/handlers/flow-digest.ts +6 -0
  187. package/os/flow/handlers/flow-discard.ts +22 -13
  188. package/os/flow/handlers/flow-fix.ts +116 -10
  189. package/os/flow/handlers/flow-integrate.ts +31 -15
  190. package/os/flow/handlers/flow-publication-retire.ts +156 -0
  191. package/os/flow/handlers/flow-push.ts +128 -13
  192. package/os/flow/locks.ts +75 -25
  193. package/os/flow/publication-order.ts +99 -0
  194. package/os/flow/publish.ts +73 -2
  195. package/os/flow/registry.ts +5 -2
  196. package/os/flow/release-tags.ts +5 -4
  197. package/os/flow/scripts.ts +12 -5
  198. package/os/flow/task-files.ts +59 -0
  199. package/os/flow/tests/flow-cut-prepare.test.ts +298 -0
  200. package/os/flow/tests/flow-cut.test.ts +5 -1
  201. package/os/flow/tests/flow-publication-retire.test.ts +191 -0
  202. package/os/flow/tests/flow-push-supersede.test.ts +221 -0
  203. package/os/flow/tests/flow-task-files.test.ts +59 -0
  204. package/os/flow/tests/helpers.ts +9 -5
  205. package/os/flow/tests/locks.test.ts +219 -0
  206. package/os/flow/tests/publication-order.test.ts +102 -0
  207. package/os/flow/tests/scripts.test.ts +13 -0
  208. package/os/mission/handlers/archive.test.ts +97 -52
  209. package/os/mission/handlers/archive.ts +31 -76
  210. package/os/mission/lockfile.ts +84 -0
  211. package/os/mission/mission.module.ts +2 -1
  212. package/os/rfc/handlers/implement-stamp-lock.test.ts +133 -0
  213. package/os/rfc/handlers/implement-stamp.ts +30 -24
  214. package/os/system/handlers/outbox-validate.ts +120 -0
  215. package/os/system/handlers/system-map-validate.ts +107 -0
  216. package/os/system/handlers/system-outbox-scan.ts +320 -0
  217. package/os/system/handlers/system-task-collect.ts +305 -0
  218. package/os/system/handlers/system-task-create.ts +271 -0
  219. package/os/system/handlers/system-task-dispatch.ts +387 -0
  220. package/os/system/handlers/system-task-move.ts +353 -0
  221. package/os/system/handlers/system-task-status.ts +176 -0
  222. package/os/system/handlers/system-versionset-record.ts +476 -0
  223. package/os/system/index.ts +47 -0
  224. package/os/system/outbox-schema.ts +47 -0
  225. package/os/system/repo.ts +451 -0
  226. package/os/system/scenario-schemas.ts +62 -0
  227. package/os/system/schemas.ts +102 -0
  228. package/os/system/system.module.ts +449 -0
  229. package/os/system/task-schemas.ts +190 -0
  230. package/os/system/task-store.ts +184 -0
  231. package/os/system/tests/helpers.ts +189 -0
  232. package/os/system/tests/outbox-validate.test.ts +92 -0
  233. package/os/system/tests/system-map-validate.test.ts +321 -0
  234. package/os/system/tests/system-outbox-scan.test.ts +273 -0
  235. package/os/system/tests/system-profile.test.ts +90 -0
  236. package/os/system/tests/system-task-collect.test.ts +293 -0
  237. package/os/system/tests/system-task-dispatch.test.ts +279 -0
  238. package/os/system/tests/system-task-status.test.ts +153 -0
  239. package/os/system/tests/system-task.test.ts +330 -0
  240. package/os/system/tests/system-versionset.test.ts +314 -0
  241. package/package.json +33 -1
  242. package/profiles/forge-shell.yaml +1 -2
  243. package/profiles/knowledge.yaml +1 -1
  244. package/profiles/system.yaml +650 -0
  245. package/profiles/typescript.yaml +0 -1
  246. package/skills/fo/fo-outbox/SKILL.md +71 -0
  247. package/skills/fo/fo-system-dispatch/SKILL.md +65 -0
  248. package/skills/fo/fo-task-run/SKILL.md +75 -0
  249. package/src/index.ts +11 -4
  250. package/src/tests/fixtures/agents-generate-business-before.txt +6 -0
  251. package/src/tests/profile-flow-hooks.test.ts +15 -0
  252. package/src/tests/profile-schema.test.ts +2 -1
@@ -14,6 +14,7 @@ flow.push must quote; --no-fetch skips the git fetch for offline review.</purpos
14
14
  <item>RFC-1498: step 4 — CI tag triggers and FLOW-11 in flow.digest
15
15
 
16
16
  flow.digest now reads .github/workflows on the primary checkout and reports tagTriggers: for every digest tag the workflows whose on.push.tags filter matches its name. Matching evaluates the GitHub glob subset — star inside a segment, double-star across, question for one char; character classes and leading negations report FLOW-11 as pattern not understood and match nothing. A workflow that cannot be parsed reports FLOW-11 and contributes nothing, never blocking the digest. tagTriggers feeds digestId so a workflow change invalidates a quoted id, the pretty output prints one line per triggered tag, and flow.module declares FLOW-11 warning plus the workflows read glob. Tests AC-7 (a v1.0.1 tag maps to the v-star workflow only) and AC-8 (broken YAML and a bracket pattern warn while the digest still returns). Compass metadata updated.</item>
17
+ <item>RFC-1503: steps 1-5 — highest-per-line pending selection, publish-superseded/publish-retired journal events, flow.publication.retire</item>
17
18
  </CHANGE_SUMMARY>
18
19
  */
19
20
 
@@ -44,6 +45,7 @@ function emptyDigestData(diagnostics: Diagnostic[]): FlowDigestData {
44
45
  byCategory: Object.fromEntries(RISK_CATEGORIES.map((c) => [c, [] as string[]])) as FlowDigestData["byCategory"],
45
46
  held: [],
46
47
  pendingPublications: [],
48
+ supersededPublications: [],
47
49
  tagTriggers: [],
48
50
  diagnostics,
49
51
  };
@@ -106,6 +108,10 @@ export async function runFlowDigest(
106
108
  for (const pending of data.pendingPublications) {
107
109
  logger.info(` pending publication: ${pending.tag} (${pending.line})`);
108
110
  }
111
+ for (const sup of data.supersededPublications) {
112
+ const by = sup.by === null ? "waits behind a higher pending tag" : `superseded by ${sup.by}`;
113
+ logger.info(` superseded publication: ${sup.tag} (${sup.line}) — ${by}`);
114
+ }
109
115
  for (const trigger of data.tagTriggers) {
110
116
  logger.info(` tag ${trigger.tag} triggers: ${trigger.workflows.join(", ")}`);
111
117
  }
@@ -13,22 +13,15 @@ the registry entry and journals the operator's reason.</purpose>
13
13
  <item>Dirty check runs before the teardown script — a discard we will refuse on dirt never executes repository code.</item>
14
14
  <item>`git branch -D` (not -d): a discarded branch is by definition unmerged.</item>
15
15
  <item>All post-removal git calls run with -C &lt;primary&gt; — the caller's cwd may be the removed worktree (AUDIT G3).</item>
16
+ <item>Task-file preservation runs BEFORE the worktree-teardown hook and only for owner.kind task — a `git clean -fdx` teardown would destroy `.forge/task/` first, and a copy failure refuses the discard (FLOW-DIS-02) so the branch and its evidence survive (RFC-1509 Q-16).</item>
16
17
  </KEY_DECISIONS>
17
18
  <CHANGE_SUMMARY>
18
- <item>RFC-1487: step 5 — flow.discard handler</item>
19
- <item>RFC-1487: step 5 — flow.discard, flow.status, flow.check FLOW-06/07</item>
20
- <item>RFC-1487: close rfc-1487 review findings — dirty-check parity with git worktree remove, ownership-verified lock release, FLOW-07 registry-error mapping, residual RFC-1462 docs removed
21
-
22
- The dirty gate for session worktrees now uses full porcelain status
23
- (untracked files included) because it predicts 'git worktree remove';
24
- the primary-clean gate keeps tracked-only semantics because it predicts
25
- 'merge --ff-only'. Lock release verifies the held payload before
26
- unlinking. Registry/journal failures map to FLOW-07 in every handler.
27
- The final branch-name collision reports FLOW-OPEN-04, flow.discard
28
- propagates its teardown result and predicts FLOW-DIS-03 on --dry-run,
29
- and integrate exposes teardown as its own field.</item>
30
- <item>RFC-1491: step 1 — journal base/rewrites + held registry widening, W1-1 discard tip, FLOW-INT-11</item>
31
19
  <item>RFC-1491: independent-review pass — shared lock constants, publishable pending filter, declared rules, hold ordering, sha-pinned refspecs</item>
20
+ <item>RFC-1509: implement RFC-1509 — system task queue, dispatch briefs and task reports</item>
21
+ <item>RFC-1509: record task-file preservation decisions in flow handlers</item>
22
+ <item>RFC-1509: close RFC-1509 review r1 findings — mark-failed escape, open-error refusal, dry-run coverage</item>
23
+ <item>RFC-1509: record RFC-1509 preserve-before-teardown ordering in key decisions</item>
24
+ <history>RFC-1487, RFC-1491</history>
32
25
  </CHANGE_SUMMARY>
33
26
  */
34
27
 
@@ -59,6 +52,7 @@ import {
59
52
  updateRegistry,
60
53
  } from "../registry.ts";
61
54
  import { runFlowScript, type FlowScriptResult } from "../scripts.ts";
55
+ import { preserveTaskFiles } from "../task-files.ts";
62
56
  import { primaryWorktree } from "../worktree-path.ts";
63
57
 
64
58
  export interface FlowDiscardData {
@@ -184,6 +178,21 @@ export async function discardFlowBranch(
184
178
  );
185
179
  }
186
180
 
181
+ // RFC-1509 Q-16: preserve BEFORE the teardown hook — a `git clean -fdx`
182
+ // teardown would destroy .forge/task/ with the rest of the worktree.
183
+ if (entry.owner.kind === "task") {
184
+ try {
185
+ await preserveTaskFiles(common, worktree, entry.owner.id, io);
186
+ } catch (error) {
187
+ return refuse(
188
+ "FLOW-DIS-02",
189
+ `could not preserve .forge/task/ for ${entry.owner.id}: ${error instanceof Error ? error.message : String(error)}`,
190
+ "copy the task files aside by hand, then re-run — the branch and registry entry are kept",
191
+ { branch },
192
+ );
193
+ }
194
+ }
195
+
187
196
  const teardown = await runFlowScript(io, "worktree-teardown", {
188
197
  primary,
189
198
  cwd: worktree,
@@ -14,15 +14,17 @@ conflicted port still reports released: true (DNA-106 per step).</purpose>
14
14
  <KEY_DECISIONS>
15
15
  <item>Touched package lines come from `git diff --name-only baseSha..fixTip` intersected with each line's paths — the fix commits declare what they release (AC-15).</item>
16
16
  <item>The fix cut never fast-forwards develop — it update-refs main at the fix tip, then delegates the port to backmergeFlow so the conflict path reports released + backmerge: conflict.</item>
17
+ <item>RFC-1502: the fix release commit uses the same `add -u` staging + FLOW-CUT-14 untracked removal as the ordinary cut, and verifies named package lines at the fix tip before any ref moves.</item>
18
+ <item>RFC-1502 r1: a refused fix cut rolls the branch back to its pre-release tip via `update-ref` + `read-tree --reset -u HEAD` (the session guard blocks reset --hard/restore/checkout --), so FLOW-CUT-12/13 stay rerun-safe without removing the fix worktree.</item>
17
19
  </KEY_DECISIONS>
18
20
  <CHANGE_SUMMARY>
19
- <item>RFC-1490: step 6 — flow.fix + fix-mode cut (patch-only, rebase on moved main, gate target main, trailing back-merge)</item>
20
- <item>RFC-1490: independent-review pass — lock-held planning, fix-branch verification, spec-shaped data, coverage</item>
21
21
  <item>RFC-1491: step 1 — journal base/rewrites + held registry widening, W1-1 discard tip, FLOW-INT-11</item>
22
22
  <item>RFC-1490: fix-mode cut run inside the fix worktree tears down and back-merges through the primary
23
23
 
24
24
  Steering-session verification of wave 2 (W2-1): flow.cut run inside the fix worktree, the documented path and the one flow.fix's nextSteps print, released main and the tags, then removed that worktree and kept using it as repoRoot. branch -D failed unobserved, leaving an unregistered auto/fix branch, and the trailing back-merge crashed on the vanished directory. The primary is now resolved before the cut and used for every step after the teardown; a failed branch delete surfaces as a FLOW-07 warning. Back-merge refusals are appended to the cut diagnostics instead of replacing them.</item>
25
25
  <item>RFC-1494: step 1 — isFlowAdopted public export</item>
26
+ <item>RFC-1502: steps 1-5 — release-prepare hook, pre-tag extract verification, ordered steps</item>
27
+ <item>RFC-1502: review r1 — fix-cut rollback on FLOW-CUT-12/13, populated steps[], hook validation, GIT_* env scrub</item>
26
28
  <history>RFC-1490</history>
27
29
  </CHANGE_SUMMARY>
28
30
  */
@@ -60,11 +62,12 @@ import {
60
62
  type FlowRegistryEntry,
61
63
  } from "../registry.ts";
62
64
  import { runFlowScript, type FlowScriptResult } from "../scripts.ts";
65
+ import { verifyLineAtRef } from "../publish.ts";
63
66
  import { primaryWorktree } from "../worktree-path.ts";
64
67
  import { VersionWriteError, writeLineVersion } from "../version-files.ts";
65
68
  import { backmergeFlow, type FlowBackmergeData } from "./flow-backmerge.ts";
66
69
  import type { FlowCutData } from "./flow-cut.ts";
67
- import { toFlowCutLines } from "./flow-cut.ts";
70
+ import { plannedExtractVerifySteps, toFlowCutLines } from "./flow-cut.ts";
68
71
  import { isFlowAdopted } from "../index.ts";
69
72
  import type { CutLine } from "./flow-cut.ts";
70
73
  import {
@@ -220,6 +223,7 @@ export async function runFixCut(
220
223
  fingerprints: {},
221
224
  gate: null,
222
225
  backmerge: null,
226
+ steps: [],
223
227
  diagnostics: [],
224
228
  };
225
229
  const cutRefuse = (ruleId: string, message: string, fixHint: string, p?: Partial<FlowCutData>): FlowCutData => ({
@@ -244,9 +248,9 @@ export async function runFixCut(
244
248
  if (!(await io.exists(fixWt))) {
245
249
  return cutRefuse("FLOW-07", `fix worktree ${fixWt} does not exist`, "inspect with flow.status — a stale entry may need flow.discard");
246
250
  }
247
- // add -A sweeps untracked files into the release commit — the dirty check
248
- // must predict it exactly (untracked included), and main must be free for
249
- // the update-ref CAS.
251
+ // The release commit stages tracked changes only (git add -u, RFC-1502) —
252
+ // the dirty check still reports untracked files so the operator sees what
253
+ // the release deliberately leaves out, and main must be free for the CAS.
250
254
  const dirty = await statusDirty(fixWt, io);
251
255
  const mainCheckedOut = live.some((w) => w.branch === "main");
252
256
  if (dirty.length > 0 || mainCheckedOut) {
@@ -310,6 +314,14 @@ export async function runFixCut(
310
314
  const tagList = cutLines.map((c) => c.tag);
311
315
  const subject = `chore(release): ${tagList.join(", ")}`;
312
316
 
317
+ const primary = await primaryWorktree(io, repoRoot);
318
+ const fixSteps = async (): Promise<string[]> => {
319
+ const steps = ["version-writes", "release-prepare", "release-commit"];
320
+ steps.push(...(await plannedExtractVerifySteps(primary, io, cutLines, repoLine)));
321
+ steps.push("gate", "fingerprints", "main", "tags", "teardown", "backmerge");
322
+ return steps;
323
+ };
324
+
313
325
  if (opts.dryRun) {
314
326
  return {
315
327
  ...base,
@@ -317,10 +329,10 @@ export async function runFixCut(
317
329
  versions: Object.fromEntries(cutLines.map((c) => [c.line.id, c.nextVersion])),
318
330
  lines: toFlowCutLines(tagList, cutLines, lines, repoLine),
319
331
  mainBefore: (await git(repoRoot, io, ["rev-parse", "main"])).stdout.trim(),
332
+ steps: await fixSteps(),
320
333
  };
321
334
  }
322
335
 
323
- const primary = await primaryWorktree(io, repoRoot);
324
336
  const common = await commonGitDir(io, repoRoot);
325
337
  const lockPath = join(common, INTEGRATE_LOCK_RELATIVE_PATH);
326
338
 
@@ -346,6 +358,34 @@ export async function runFixCut(
346
358
  fixTip = (await git(repoRoot, io, ["rev-parse", entry.name])).stdout.trim();
347
359
  }
348
360
 
361
+ // Pre-release tip: the cut rolls the fix branch back here when the
362
+ // prepare hook or the extract verification refuses — the branch must
363
+ // stay (it carries the fix) but the cut has to be rerun-safe, which
364
+ // uncommitted version writes or a failed release commit break.
365
+ const preReleaseTip = fixTip;
366
+ const rollbackToTip = async (): Promise<void> => {
367
+ // Destructive shorthands are blocked by the session guard (reset
368
+ // --hard, restore, checkout --) — move the ref directly, then
369
+ // reset index+worktree to the (new) HEAD tree via plumbing.
370
+ await git(fixWt, io, ["update-ref", `refs/heads/${entry.name}`, preReleaseTip]);
371
+ await git(fixWt, io, ["read-tree", "--reset", "-u", "HEAD"]);
372
+ const leftovers = (
373
+ await git(fixWt, io, [
374
+ "-c",
375
+ "core.quotepath=false",
376
+ "ls-files",
377
+ "-z",
378
+ "--others",
379
+ "--exclude-standard",
380
+ ])
381
+ ).stdout
382
+ .split("\0")
383
+ .filter((f) => f.length > 0);
384
+ for (const file of leftovers) {
385
+ await io.rm(join(fixWt, file));
386
+ }
387
+ };
388
+
349
389
  // Verified version writes on the fix branch.
350
390
  try {
351
391
  for (const c of cutLines) {
@@ -358,8 +398,57 @@ export async function runFixCut(
358
398
  throw error;
359
399
  }
360
400
 
361
- // Release commit on the fix branch.
362
- await git(fixWt, io, ["add", "-A"]);
401
+ // release-prepare hook (RFC-1502): same seam as the ordinary cut —
402
+ // version-hashed derived artifacts regenerated into the fix's
403
+ // release commit. Runs from the primary checkout on the fix worktree.
404
+ const warnings: Diagnostic[] = [];
405
+ const prep = await runFlowScript(io, "release-prepare", {
406
+ primary,
407
+ cwd: fixWt,
408
+ env: {
409
+ FORGE_FLOW_RELEASE_TAGS: tagList.join(" "),
410
+ FORGE_FLOW_RELEASE_VERSIONS: JSON.stringify(
411
+ Object.fromEntries(cutLines.map((c) => [c.line.id, c.nextVersion])),
412
+ ),
413
+ },
414
+ });
415
+ if (prep.status === "failed") {
416
+ await rollbackToTip();
417
+ return cutRefuse(
418
+ "FLOW-CUT-12",
419
+ `hooks/release-prepare.sh failed (exit ${prep.exitCode}): ${prep.stderrTail}`,
420
+ "fix the release-prepare hook and re-run flow.cut — the fix branch was rolled back to its pre-release tip",
421
+ );
422
+ }
423
+
424
+ // Release commit on the fix branch — add -u folds the hook's tracked
425
+ // edits in; untracked leftovers stay out and are reported.
426
+ await git(fixWt, io, ["add", "-u"]);
427
+ const untrackedFiles = (
428
+ await git(fixWt, io, [
429
+ "-c",
430
+ "core.quotepath=false",
431
+ "ls-files",
432
+ "-z",
433
+ "--others",
434
+ "--exclude-standard",
435
+ ])
436
+ ).stdout
437
+ .split("\0")
438
+ .filter((f) => f.length > 0);
439
+ if (untrackedFiles.length > 0) {
440
+ warnings.push({
441
+ ruleId: "FLOW-CUT-14",
442
+ severity: "warning",
443
+ message: `release-prepare left untracked file(s) excluded from the release commit and removed from the release worktree: ${untrackedFiles.join(", ")}`,
444
+ });
445
+ // The cut continues — the same unignored-untracked set comes out of
446
+ // the worktree so the gate sees a clean tree. Removed via io.rm:
447
+ // `git clean -f` is blocked in agent sessions.
448
+ for (const file of untrackedFiles) {
449
+ await io.rm(join(fixWt, file));
450
+ }
451
+ }
363
452
  const body = cutLines.map((c) => `${c.tag} patch ${c.previousTag ?? "null"}`).join("\n");
364
453
  const commit = await gitCommit(fixWt, io, ["commit", "-m", `${subject}\n\n${body}`], "cut");
365
454
  if (commit.exitCode !== 0) {
@@ -367,6 +456,22 @@ export async function runFixCut(
367
456
  }
368
457
  fixTip = (await git(repoRoot, io, ["rev-parse", entry.name])).stdout.trim();
369
458
 
459
+ // Pre-tag extract verification (RFC-1502): named package lines
460
+ // extract at the fix's release commit into a scratch — before any
461
+ // ref or tag moves.
462
+ for (const c of cutLines) {
463
+ if (c.line.id === repoLine.id) continue;
464
+ const verify = await verifyLineAtRef(primary, io, { line: c.line, ref: fixTip });
465
+ if (!verify.ok) {
466
+ await rollbackToTip();
467
+ return cutRefuse(
468
+ "FLOW-CUT-13",
469
+ `pre-tag extract verification failed for line ${c.line.id}: ${verify.detail}`,
470
+ "fix the extract or verify failure and re-run flow.cut — the fix branch was rolled back to its pre-release tip",
471
+ );
472
+ }
473
+ }
474
+
370
475
  // Gate with main as the target.
371
476
  const gate = await runFlowScript(io, "integration-gate", {
372
477
  primary,
@@ -494,7 +599,8 @@ export async function runFixCut(
494
599
  fingerprints,
495
600
  gate,
496
601
  releaseBranch: null,
497
- diagnostics: [...base.diagnostics, ...teardownWarnings],
602
+ steps: await fixSteps(),
603
+ diagnostics: [...warnings, ...base.diagnostics, ...teardownWarnings],
498
604
  } satisfies FlowCutData;
499
605
  },
500
606
  io,
@@ -17,22 +17,15 @@ at cleanup without moving develop again.</purpose>
17
17
  <item>Every git call after worktree removal runs with -C &lt;primary&gt; — the caller's cwd may be the removed directory (AUDIT G3/G4).</item>
18
18
  <item>Rerun detection is `isAncestor(branchTip, develop)` on a registered entry — develop already containing the branch means the merge landed; only cleanup remains (AC-9).</item>
19
19
  <item>FLOW-INT-07 covers develop moving between rebase and merge despite the lock — the branch stays rebased; a rerun rebases onto the new tip.</item>
20
+ <item>Task-file preservation runs inside the cleanup branch BEFORE the worktree-teardown hook and only for owner.kind task — a `git clean -fdx` teardown would destroy `.forge/task/` first, and a copy failure refuses cleanup (FLOW-INT-04) so the report is never lost with the worktree (RFC-1509 Q-16).</item>
20
21
  </KEY_DECISIONS>
21
22
  <CHANGE_SUMMARY>
22
- <item>RFC-1487: step 4 — flow.integrate handler</item>
23
- <item>RFC-1487: step 4 — flow.integrate with lock, primary-side gate, ff-only merge and cleanup resume</item>
24
- <item>RFC-1487: close rfc-1487 review findings — dirty-check parity with git worktree remove, ownership-verified lock release, FLOW-07 registry-error mapping, residual RFC-1462 docs removed
25
-
26
- The dirty gate for session worktrees now uses full porcelain status
27
- (untracked files included) because it predicts 'git worktree remove';
28
- the primary-clean gate keeps tracked-only semantics because it predicts
29
- 'merge --ff-only'. Lock release verifies the held payload before
30
- unlinking. Registry/journal failures map to FLOW-07 in every handler.
31
- The final branch-name collision reports FLOW-OPEN-04, flow.discard
32
- propagates its teardown result and predicts FLOW-DIS-03 on --dry-run,
33
- and integrate exposes teardown as its own field.</item>
34
- <item>RFC-1490: step 4 — ordinary flow.cut (release branch, verified versions, gate, main swap, tags, resume)</item>
35
- <item>RFC-1491: step 1 — journal base/rewrites + held registry widening, W1-1 discard tip, FLOW-INT-11</item>
23
+ <item>RFC-1504: steps 2-3 — holderIsDead, boot-id payload, dead-holder break in withFlowLock</item>
24
+ <item>RFC-1509: implement RFC-1509 — system task queue, dispatch briefs and task reports</item>
25
+ <item>RFC-1509: record task-file preservation decisions in flow handlers</item>
26
+ <item>RFC-1509: close RFC-1509 review r1 findings — mark-failed escape, open-error refusal, dry-run coverage</item>
27
+ <item>RFC-1509: record RFC-1509 preserve-before-teardown ordering in key decisions</item>
28
+ <history>RFC-1487, RFC-1490, RFC-1491</history>
36
29
  </CHANGE_SUMMARY>
37
30
  */
38
31
 
@@ -67,6 +60,7 @@ import {
67
60
  type FlowRegistryEntry,
68
61
  } from "../registry.ts";
69
62
  import { runFlowScript, type FlowScriptResult } from "../scripts.ts";
63
+ import { preserveTaskFiles } from "../task-files.ts";
70
64
  import { primaryWorktree } from "../worktree-path.ts";
71
65
  import { join } from "node:path";
72
66
 
@@ -132,6 +126,26 @@ async function cleanupIntegrated(
132
126
  const branchExistsNow = await branchExists(primary, io, entry.name);
133
127
  let teardownRan: FlowScriptResult | null = null;
134
128
  if (worktree !== null && (await io.exists(worktree))) {
129
+ // RFC-1509 Q-16: preserve BEFORE the teardown hook — a `git clean -fdx`
130
+ // teardown would destroy .forge/task/ with the rest of the worktree.
131
+ if (entry.owner.kind === "task") {
132
+ try {
133
+ await preserveTaskFiles(common, worktree, entry.owner.id, io);
134
+ } catch (error) {
135
+ return {
136
+ cleanedUp: false,
137
+ gate: null,
138
+ diagnostics: [
139
+ {
140
+ ruleId: "FLOW-INT-04",
141
+ severity: "error",
142
+ message: `could not preserve .forge/task/ for ${entry.owner.id}: ${error instanceof Error ? error.message : String(error)}`,
143
+ fixHint: `copy ${worktree}/.forge/task/ aside by hand, then re-run flow.integrate — develop already moved`,
144
+ },
145
+ ],
146
+ };
147
+ }
148
+ }
135
149
  const teardown = await runFlowScript(io, "worktree-teardown", {
136
150
  primary,
137
151
  cwd: worktree,
@@ -510,7 +524,9 @@ export async function integrateFlowBranch(
510
524
  onProgress: opts.onProgress,
511
525
  onStale: (l) =>
512
526
  opts.onProgress?.(
513
- `broke stale integration lock (held since ${l.at}, ${Math.round(l.ageMs / 60000)} min old)`,
527
+ l.reason === "dead-holder"
528
+ ? `broke dead-holder integration lock (pid ${l.pid ?? "?"} on ${l.host ?? "?"}, held since ${l.at})`
529
+ : `broke stale integration lock (held since ${l.at}, ${Math.round(l.ageMs / 60000)} min old)`,
514
530
  ),
515
531
  },
516
532
  integrateInner,
@@ -0,0 +1,156 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>flow.publication.retire — operator-only command (RFC-1503): append a
4
+ `publish-retired` journal event for a pending publication tag so flow.push
5
+ never attempts it again. Refuses FLOW-RETIRE-01 when the tag is not pending
6
+ and FLOW-RETIRE-02 on an empty --reason.</purpose>
7
+ <non-goals>
8
+ <item>No tag or remote mutation — the journal record is the whole effect.</item>
9
+ <item>No digest/push — flow.digest and flow.push consume the record.</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1503: step 3 — flow.publication.retire handler</item>
14
+ <item>RFC-1503: steps 1-5 — highest-per-line pending selection, publish-superseded/publish-retired journal events, flow.publication.retire</item>
15
+ <item>RFC-1503: review r1 — FLOW-07 on retire journal failure, journal re-read before publish, publication-order unit tests, stale catalog/inventory regen</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+
19
+ import type {
20
+ Diagnostic,
21
+ ForgeCommandInput,
22
+ ForgeCommandResult,
23
+ ForgeRuntimeContext,
24
+ WorkspaceIO,
25
+ } from "../../../src/types.ts";
26
+ import { resolveIo } from "../../../src/utils/io.ts";
27
+ import { collectDigest } from "../digest.ts";
28
+ import { requireGit, topLevel } from "../git.ts";
29
+ import { appendJournal, commonGitDir, FlowRegistrySchemaError } from "../registry.ts";
30
+
31
+ export interface RetirePublicationData {
32
+ tag: string;
33
+ retired: string | null;
34
+ diagnostics: Diagnostic[];
35
+ }
36
+
37
+ /**
38
+ * Core of flow.publication.retire — callable in tests. Appends one
39
+ * `publish-retired` journal event; the digest then drops the tag from
40
+ * pendingPublications forever.
41
+ */
42
+ export async function retirePublication(
43
+ repoRoot: string,
44
+ io: WorkspaceIO,
45
+ opts: { tag: string; reason: string },
46
+ ): Promise<RetirePublicationData> {
47
+ const reason = opts.reason.trim();
48
+ if (reason.length === 0) {
49
+ return {
50
+ tag: opts.tag,
51
+ retired: null,
52
+ diagnostics: [
53
+ {
54
+ ruleId: "FLOW-RETIRE-02",
55
+ severity: "error",
56
+ message: "--reason must not be empty — the journal records it verbatim",
57
+ fixHint: "pass a short reason naming why the tag can never publish",
58
+ },
59
+ ],
60
+ };
61
+ }
62
+
63
+ const digest = await collectDigest(repoRoot, io, { fetch: false });
64
+ const pending = new Set([
65
+ ...digest.pendingPublications.map((p) => p.tag),
66
+ ...digest.supersededPublications.map((p) => p.tag),
67
+ ]);
68
+ if (!pending.has(opts.tag)) {
69
+ return {
70
+ tag: opts.tag,
71
+ retired: null,
72
+ diagnostics: [
73
+ {
74
+ ruleId: "FLOW-RETIRE-01",
75
+ severity: "error",
76
+ message: `${opts.tag} is not a pending publication — only pushed-but-unpublished tags can be retired`,
77
+ fixHint: "check flow.digest pendingPublications for the tag to retire",
78
+ },
79
+ ],
80
+ };
81
+ }
82
+
83
+ const common = await commonGitDir(io, repoRoot);
84
+ try {
85
+ await appendJournal(io, common, {
86
+ event: "publish-retired",
87
+ branch: opts.tag,
88
+ sha: "",
89
+ detail: reason,
90
+ });
91
+ } catch (error) {
92
+ return {
93
+ tag: opts.tag,
94
+ retired: null,
95
+ diagnostics: [
96
+ {
97
+ ruleId: "FLOW-07",
98
+ severity: "error",
99
+ message: `publish-retired record for ${opts.tag} could not be appended: ${String(error)}`,
100
+ },
101
+ ],
102
+ };
103
+ }
104
+ return { tag: opts.tag, retired: opts.tag, diagnostics: [] };
105
+ }
106
+
107
+ export async function runFlowPublicationRetire(
108
+ input: ForgeCommandInput,
109
+ context: ForgeRuntimeContext,
110
+ ): Promise<ForgeCommandResult<RetirePublicationData>> {
111
+ const { workspaceRoot, logger, outputFormat } = context;
112
+ const io: WorkspaceIO = resolveIo(context.io);
113
+ await requireGit(io);
114
+
115
+ const repoRoot = await topLevel(workspaceRoot, io);
116
+ if (repoRoot === null) {
117
+ throw new Error("flow.publication.retire must run inside a git repository");
118
+ }
119
+
120
+ const tag = typeof input.flags["tag"] === "string" ? input.flags["tag"] : "";
121
+ const reason = typeof input.flags["reason"] === "string" ? input.flags["reason"] : "";
122
+ let data: RetirePublicationData;
123
+ try {
124
+ data = await retirePublication(repoRoot, io, { tag, reason });
125
+ } catch (error) {
126
+ if (error instanceof FlowRegistrySchemaError) {
127
+ data = {
128
+ tag,
129
+ retired: null,
130
+ diagnostics: [{ ruleId: "FLOW-07", severity: "error", message: error.message }],
131
+ };
132
+ } else {
133
+ throw error;
134
+ }
135
+ }
136
+ const errors = data.diagnostics.filter((d) => d.severity === "error");
137
+
138
+ if (outputFormat === "pretty") {
139
+ for (const d of data.diagnostics) {
140
+ if (d.severity === "error") logger.error(` ${d.ruleId}: ${d.message}`);
141
+ else logger.warn(` ${d.ruleId}: ${d.message}`);
142
+ }
143
+ if (data.retired !== null) {
144
+ logger.info(` retired publication: ${data.retired}`);
145
+ }
146
+ }
147
+
148
+ return {
149
+ data,
150
+ exitCode: errors.length > 0 ? 1 : 0,
151
+ summary:
152
+ data.retired !== null
153
+ ? `[flow.publication.retire] ${data.retired} retired — it will never be attempted again`
154
+ : `[flow.publication.retire] refused — ${errors[0]?.ruleId ?? "unknown"}`,
155
+ };
156
+ }