@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
@@ -0,0 +1,88 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Liveness check for file-lock holders (RFC-1504): `holderIsDead`
4
+ decides whether the process that wrote a lock no longer exists — dead pids
5
+ are broken without waiting, foreign hosts keep the age rule, a foreign boot
6
+ id on this host means the holder died with the last boot. `currentBootId`
7
+ reads /proc/sys/kernel/random/boot_id when the platform has one.</purpose>
8
+ <non-goals>
9
+ <item>No lock acquisition — os/flow/locks.ts and os/core/stamp-lock.ts own
10
+ the O_EXCL path.</item>
11
+ </non-goals>
12
+ </MODULE_CONTRACT>
13
+ <CHANGE_SUMMARY>
14
+ <item>RFC-1504: step 2 — holderIsDead + currentBootId</item>
15
+ <item>RFC-1504: steps 2-3 — holderIsDead, boot-id payload, dead-holder break in withFlowLock</item>
16
+ <item>RFC-1504: review fixes — legacy acquiredAt fallback, atomic break claim, verified stamp release, onStale warnings</item>
17
+ </CHANGE_SUMMARY>
18
+ */
19
+
20
+ import { readFileSync } from "node:fs";
21
+ import { readFile, rename } from "node:fs/promises";
22
+ import { hostname } from "node:os";
23
+
24
+ export interface LockHolder {
25
+ pid: number;
26
+ host?: string;
27
+ at?: string;
28
+ bootId?: string;
29
+ }
30
+
31
+ /** The machine's boot id, or undefined on platforms without one / on any read error. */
32
+ export function currentBootId(): string | undefined {
33
+ try {
34
+ const raw = readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
35
+ return raw.length > 0 ? raw : undefined;
36
+ } catch {
37
+ return undefined;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * True when the recorded holder cannot exist anymore. A lock from another
43
+ * host (or with no host at all) is never judged by pid — pid namespaces
44
+ * differ, so the age rule stays the only breaker there. A same-host lock
45
+ * carrying a bootId different from the current boot is dead by definition:
46
+ * the machine restarted since it was written. Otherwise `kill(pid, 0)`
47
+ * probes: ESRCH is dead, EPERM and success are alive; any other error is
48
+ * treated as alive (fail closed).
49
+ */
50
+ export function holderIsDead(lock: LockHolder, bootId: string | undefined = currentBootId()): boolean {
51
+ if (lock.host === undefined || lock.host !== hostname()) return false;
52
+ if (lock.bootId !== undefined && bootId !== undefined && lock.bootId !== bootId) return true;
53
+ try {
54
+ process.kill(lock.pid, 0);
55
+ return false;
56
+ } catch (error) {
57
+ return (error as NodeJS.ErrnoException).code === "ESRCH";
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Atomically claim the right to remove a stale/dead lock file: re-read the
63
+ * file, verify it still carries the `expected` holder (same pid and at), and
64
+ * rename it to a unique tombstone path. Returns the tombstone path for the
65
+ * caller to unlink, or null when the lock changed hands in between — in
66
+ * that case a fresh holder stands and the file must not be touched.
67
+ * The rename is the claim: two contenders racing the same dead lock cannot
68
+ * both land it, so a winner never deletes another contender's fresh lock.
69
+ */
70
+ export async function claimLockBreak(
71
+ lockPath: string,
72
+ expected: { pid: number; at: string } | null,
73
+ ): Promise<string | null> {
74
+ const tombPath = `${lockPath}.tomb.${process.pid}.${Date.now()}`;
75
+ try {
76
+ const current = JSON.parse(await readFile(lockPath, "utf8")) as Record<string, unknown>;
77
+ if (expected !== null) {
78
+ const at = typeof current["at"] === "string" ? current["at"]
79
+ : typeof current["acquiredAt"] === "string" ? current["acquiredAt"]
80
+ : "";
81
+ if (current["pid"] !== expected.pid || at !== expected.at) return null;
82
+ }
83
+ await rename(lockPath, tombPath);
84
+ return tombPath;
85
+ } catch {
86
+ return null;
87
+ }
88
+ }
@@ -0,0 +1,142 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Shared one-shot stamp lock for rfc.implement.stamp and
4
+ adr.implement.stamp (RFC-1504): O_EXCL acquisition carrying
5
+ {pid, host, at, bootId?}; on contention the holder's file is judged —
6
+ a dead holder or a lock older than STAMP_LOCK_STALE_MS is claimed by an
7
+ atomic rename and removed, then the acquire retries (bounded attempts);
8
+ a live or foreign holder returns acquired:false so the caller keeps its
9
+ IMP-05 refusal. Legacy lock files written as {pid, acquiredAt} have no
10
+ host — they are judged by age only, reading acquiredAt when at is absent.
11
+ No wait loop — stamp locks never had one.</purpose>
12
+ <non-goals>
13
+ <item>No release — callers keep their own verified rm(lockPath).</item>
14
+ </non-goals>
15
+ </MODULE_CONTRACT>
16
+ <CHANGE_SUMMARY>
17
+ <item>RFC-1504: step 4 — shared stamp lock with dead-holder break</item>
18
+ <item>RFC-1504: review fixes — acquiredAt fallback, atomic break claim, held payload for verified release</item>
19
+ </CHANGE_SUMMARY>
20
+ */
21
+
22
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
23
+ import { hostname } from "node:os";
24
+ import { dirname } from "node:path";
25
+
26
+ import { claimLockBreak, currentBootId, holderIsDead } from "./lock-holder.ts";
27
+
28
+ export const STAMP_LOCK_STALE_MS = 30 * 60 * 1000;
29
+
30
+ export interface StampLockOptions {
31
+ /** Called when a stale or dead lock file is removed. */
32
+ onStale?: (info: {
33
+ path: string;
34
+ reason: "dead-holder" | "stale-age";
35
+ at?: string;
36
+ pid?: number;
37
+ host?: string;
38
+ ageMs?: number;
39
+ }) => void;
40
+ /** Injectable clock for tests. */
41
+ now?: () => number;
42
+ }
43
+
44
+ export interface StampLockHeld {
45
+ pid: number;
46
+ at: string;
47
+ }
48
+
49
+ interface StampLockContent {
50
+ pid: number;
51
+ host?: string;
52
+ at: string;
53
+ bootId?: string;
54
+ }
55
+
56
+ async function tryAcquire(lockPath: string, content: StampLockContent): Promise<boolean> {
57
+ try {
58
+ await writeFile(lockPath, JSON.stringify(content), { flag: "wx" });
59
+ return true;
60
+ } catch (error) {
61
+ if ((error as NodeJS.ErrnoException).code === "EEXIST") return false;
62
+ throw error;
63
+ }
64
+ }
65
+
66
+ async function readHolder(lockPath: string): Promise<StampLockContent | null> {
67
+ try {
68
+ const parsed = JSON.parse(await readFile(lockPath, "utf8")) as Record<string, unknown>;
69
+ if (typeof parsed["pid"] !== "number") return null;
70
+ // RFC-1504: legacy locks carry acquiredAt instead of at — read either.
71
+ const at = typeof parsed["at"] === "string" ? parsed["at"]
72
+ : typeof parsed["acquiredAt"] === "string" ? parsed["acquiredAt"]
73
+ : "";
74
+ return {
75
+ pid: parsed["pid"],
76
+ host: typeof parsed["host"] === "string" ? parsed["host"] : undefined,
77
+ at,
78
+ bootId: typeof parsed["bootId"] === "string" ? parsed["bootId"] : undefined,
79
+ };
80
+ } catch {
81
+ return null;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Acquire `lockPath` once. Returns {acquired:true, held} after claiming and
87
+ * removing a dead or stale holder, {acquired:false} while a live or foreign
88
+ * holder stands. `held` is the payload just written — pass it to a verified
89
+ * release so a lock taken over mid-run is never deleted.
90
+ */
91
+ export async function acquireStampLock(
92
+ lockPath: string,
93
+ opts: StampLockOptions = {},
94
+ ): Promise<{ acquired: boolean; lockPath: string; held?: StampLockHeld }> {
95
+ const now = opts.now ?? (() => Date.now());
96
+ await mkdir(dirname(lockPath), { recursive: true });
97
+ const bootId = currentBootId();
98
+
99
+ for (let attempt = 0; attempt < 3; attempt += 1) {
100
+ const at = new Date(now()).toISOString();
101
+ const content: StampLockContent = { pid: process.pid, host: hostname(), at };
102
+ if (bootId !== undefined) content.bootId = bootId;
103
+ if (await tryAcquire(lockPath, content)) {
104
+ return { acquired: true, lockPath, held: { pid: process.pid, at } };
105
+ }
106
+
107
+ const holder = await readHolder(lockPath);
108
+ const heldAtMs = holder !== null && holder.at.length > 0 ? Date.parse(holder.at) : NaN;
109
+ const ageMs = Number.isNaN(heldAtMs) ? NaN : now() - heldAtMs;
110
+
111
+ if (holder !== null && holderIsDead(holder, bootId)) {
112
+ opts.onStale?.({
113
+ path: lockPath,
114
+ reason: "dead-holder",
115
+ at: holder.at,
116
+ pid: holder.pid,
117
+ host: holder.host,
118
+ ageMs: Number.isNaN(ageMs) ? undefined : ageMs,
119
+ });
120
+ // Atomic claim: only the contender whose rename lands removes the file —
121
+ // a loser racing the same dead lock gets null and retries normally.
122
+ const tomb = await claimLockBreak(lockPath, holder);
123
+ if (tomb !== null) await rm(tomb, { force: true });
124
+ continue;
125
+ }
126
+ if (!Number.isNaN(ageMs) && ageMs > STAMP_LOCK_STALE_MS) {
127
+ opts.onStale?.({
128
+ path: lockPath,
129
+ reason: "stale-age",
130
+ at: holder?.at,
131
+ pid: holder?.pid,
132
+ host: holder?.host,
133
+ ageMs,
134
+ });
135
+ const tomb = await claimLockBreak(lockPath, holder);
136
+ if (tomb !== null) await rm(tomb, { force: true });
137
+ continue;
138
+ }
139
+ return { acquired: false, lockPath };
140
+ }
141
+ return { acquired: false, lockPath };
142
+ }
package/os/flow/digest.ts CHANGED
@@ -18,8 +18,6 @@ flow.push must quote.</purpose>
18
18
  <item>tagTriggers (RFC-1498) is part of digestId input: a workflow-file change between digest and push must invalidate the quoted id. Unparseable workflows and ununderstood patterns warn FLOW-11 and match nothing — never block the digest.</item>
19
19
  </KEY_DECISIONS>
20
20
  <CHANGE_SUMMARY>
21
- <item>RFC-1491: step 3 — flow.digest risk digest with journal-attributed items, categories, digestId</item>
22
- <item>RFC-1491: step 5 — flow.push atomic outbound path + extract publication</item>
23
21
  <item>RFC-1491: independent-review pass — shared lock constants, publishable pending filter, declared rules, hold ordering, sha-pinned refspecs</item>
24
22
  <item>RFC-1491: digest segments develop by first-parent chain; hold of the topmost item skips the empty replay
25
23
 
@@ -29,6 +27,8 @@ Steering-session verification of wave 2 found two outbound defects:
29
27
  <item>RFC-1498: step 4 — CI tag triggers and FLOW-11 in flow.digest
30
28
 
31
29
  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>
30
+ <item>RFC-1503: steps 1-5 — highest-per-line pending selection, publish-superseded/publish-retired journal events, flow.publication.retire</item>
31
+ <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>
32
32
  <history>RFC-1491</history>
33
33
  </CHANGE_SUMMARY>
34
34
  */
@@ -49,8 +49,10 @@ import {
49
49
  type FlowJournalEvent,
50
50
  type RiskCategory,
51
51
  } from "./registry.ts";
52
+ import { planPublications, type PublicationPlanEntry } from "./publication-order.ts";
52
53
  import { tagAnnotationLevel } from "./publish.ts";
53
54
  import { discoverReleaseLines, type ReleaseLine } from "./release-lines.ts";
55
+ import { parseVersion, type SemVer } from "./semver.ts";
54
56
  import { listLineTags } from "./release-tags.ts";
55
57
  import { primaryWorktree } from "./worktree-path.ts";
56
58
 
@@ -83,7 +85,18 @@ export interface FlowDigestData {
83
85
  riskCategory: RiskCategory;
84
86
  heldAt: string;
85
87
  }>;
88
+ /**
89
+ * RFC-1503: the highest pending tag per package line — what the next
90
+ * flow.push actually attempts. Lower pending tags moved to
91
+ * `supersededPublications`.
92
+ */
86
93
  pendingPublications: Array<{ tag: string; line: string }>;
94
+ /**
95
+ * RFC-1503: lower pending tags the next push supersedes (`by` = the
96
+ * superseding tag, null when the tag waits behind a higher candidate
97
+ * that has not published yet).
98
+ */
99
+ supersededPublications: Array<{ tag: string; line: string; by: string | null }>;
87
100
  /**
88
101
  * RFC-1498: CI workflows a push of each digest tag would start —
89
102
  * `.github/workflows` files whose `on.push.tags` filter matches the tag
@@ -537,6 +550,14 @@ export function lineForTag(lines: ReleaseLine[], tag: string): ReleaseLine | nul
537
550
  return best;
538
551
  }
539
552
 
553
+ /** Strict semver of `tag` under the line with id `lineId` — null when the
554
+ * line is unknown, the prefix does not match, or the suffix is not X.Y.Z. */
555
+ export function versionOfTag(lines: ReleaseLine[], tag: string, lineId: string): SemVer | null {
556
+ const line = lines.find((l) => l.id === lineId);
557
+ if (line === undefined || !tag.startsWith(line.tagPrefix)) return null;
558
+ return parseVersion(tag.slice(line.tagPrefix.length));
559
+ }
560
+
540
561
  /** Recursively key-sorted JSON.stringify — the digestId's canonical form. */
541
562
  function canonicalJson(value: unknown): string {
542
563
  if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
@@ -685,9 +706,13 @@ export async function collectDigest(
685
706
  heldAt: b.held!.heldAt,
686
707
  }));
687
708
 
688
- const pendingPublications: Array<{ tag: string; line: string }> = [];
709
+ // RFC-1503: pending candidates are journal-scoped — pushed, not published,
710
+ // not superseded, not retired. planPublications picks the highest per line
711
+ // as the real pending list and routes the rest to supersededPublications.
689
712
  const pushedTags = new Set<string>();
690
713
  const publishedTags = new Set<string>();
714
+ const supersededTags = new Set<string>();
715
+ const retiredTags = new Set<string>();
691
716
  for (const event of journal) {
692
717
  if (event.event === "push") {
693
718
  for (const token of event.detail.split(/[^A-Za-z0-9._/@-]+/)) {
@@ -695,17 +720,31 @@ export async function collectDigest(
695
720
  }
696
721
  } else if (event.event === "publish") {
697
722
  publishedTags.add(event.branch);
723
+ } else if (event.event === "publish-superseded") {
724
+ supersededTags.add(event.branch);
725
+ } else if (event.event === "publish-retired") {
726
+ retiredTags.add(event.branch);
698
727
  }
699
728
  }
729
+ const pendingCandidates: PublicationPlanEntry[] = [];
700
730
  for (const tag of [...pushedTags].sort((a, b) => a.localeCompare(b))) {
701
731
  if (!allLocalTags.has(tag) || publishedTags.has(tag)) continue;
732
+ if (supersededTags.has(tag) || retiredTags.has(tag)) continue;
702
733
  const line = lineForTag(lines, tag);
703
734
  // Repo-line tags are never extracted, and baseline annotations are
704
735
  // skipped at push time — neither ever gains a publish record.
705
736
  if (line === null || line.id === "repo") continue;
706
737
  if ((await tagAnnotationLevel(repoRoot, io, tag)) === "baseline") continue;
707
- pendingPublications.push({ tag, line: line.id });
738
+ pendingCandidates.push({ tag, line: line.id });
708
739
  }
740
+ const plan = planPublications(
741
+ pendingCandidates,
742
+ publishedTags,
743
+ retiredTags,
744
+ (tag, line) => versionOfTag(lines, tag, line),
745
+ );
746
+ const pendingPublications = plan.attempt;
747
+ const supersededPublications = plan.superseded;
709
748
 
710
749
  // --- CI workflows a tag push would trigger (RFC-1498) --------------------
711
750
  // Read on the primary checkout — that is the working copy the operator
@@ -738,6 +777,8 @@ export async function collectDigest(
738
777
  main: { local: mainLocal, remote: mainRemote, ahead: mainTail.length },
739
778
  tags,
740
779
  tagTriggers,
780
+ pendingPublications,
781
+ supersededPublications,
741
782
  items: items.map((i) => ({ id: i.id, tip: i.tip })),
742
783
  }),
743
784
  )
@@ -755,6 +796,7 @@ export async function collectDigest(
755
796
  byCategory,
756
797
  held,
757
798
  pendingPublications,
799
+ supersededPublications,
758
800
  tagTriggers,
759
801
  diagnostics,
760
802
  };
@@ -9,14 +9,14 @@ the idempotent two-phase repository adoption (FLOW-ADOPT-01..06, -08).</purpose>
9
9
  </non-goals>
10
10
  </MODULE_CONTRACT>
11
11
  <CHANGE_SUMMARY>
12
- <item>RFC-1491: step 3 — flow.digest risk digest with journal-attributed items, categories, digestId</item>
13
- <item>RFC-1491: step 4 — flow.hold replay + flow.unhold worktree restore</item>
14
- <item>RFC-1491: step 5 — flow.push atomic outbound path + extract publication</item>
15
12
  <item>RFC-1491: independent-review pass — shared lock constants, publishable pending filter, declared rules, hold ordering, sha-pinned refspecs</item>
16
13
  <item>RFC-1498: step 4 — CI tag triggers and FLOW-11 in flow.digest
17
14
 
18
15
  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>
19
- <history>RFC-1486, RFC-1487, RFC-1488, RFC-1490</history>
16
+ <item>RFC-1503: steps 1-5 — highest-per-line pending selection, publish-superseded/publish-retired journal events, flow.publication.retire</item>
17
+ <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>
18
+ <item>RFC-1502: steps 1-5 — release-prepare hook, pre-tag extract verification, ordered steps</item>
19
+ <history>RFC-1486, RFC-1487, RFC-1488, RFC-1490, RFC-1491</history>
20
20
  </CHANGE_SUMMARY>
21
21
  */
22
22
 
@@ -34,6 +34,7 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
34
34
  const { runFlowIntegrate } = await import("./handlers/flow-integrate.ts");
35
35
  const { runFlowOpen } = await import("./handlers/flow-open.ts");
36
36
  const { runFlowPush } = await import("./handlers/flow-push.ts");
37
+ const { runFlowPublicationRetire } = await import("./handlers/flow-publication-retire.ts");
37
38
  const { runFlowStatus } = await import("./handlers/flow-status.ts");
38
39
  const { runFlowUnhold } = await import("./handlers/flow-unhold.ts");
39
40
  const { runFlowVersion } = await import("./handlers/flow-version.ts");
@@ -301,7 +302,10 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
301
302
  "Cut a release on the fixed branch model (RFC-1490): plan refusals " +
302
303
  "FLOW-CUT-01..07, then under the integration lock — release branch " +
303
304
  "through flow.open (owner release), verified version-file writes, " +
304
- "chore(release) commit, gate + fast-forward into develop, " +
305
+ "release-prepare hook (RFC-1502: FLOW-CUT-12 refusal, FLOW-CUT-14 " +
306
+ "untracked warning), chore(release) commit, pre-tag extract " +
307
+ "verification per named package line (FLOW-CUT-13), " +
308
+ "gate + fast-forward into develop, " +
305
309
  "release-fingerprints hook, main compare-and-swap, release tags " +
306
310
  "(repository line always, package lines via --lines), journal. " +
307
311
  "Rerun-safe: resumes at fingerprints after an integrated release " +
@@ -320,6 +324,9 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
320
324
  { id: "FLOW-CUT-09", severity: "error" },
321
325
  { id: "FLOW-CUT-10", severity: "error" },
322
326
  { id: "FLOW-CUT-11", severity: "error" },
327
+ { id: "FLOW-CUT-12", severity: "error" },
328
+ { id: "FLOW-CUT-13", severity: "error" },
329
+ { id: "FLOW-CUT-14", severity: "warning" },
323
330
  { id: "FLOW-INT-02", severity: "error" },
324
331
  { id: "FLOW-INT-05", severity: "error" },
325
332
  { id: "FLOW-INT-06", severity: "error" },
@@ -339,7 +346,7 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
339
346
  generates: [],
340
347
  coverage: "operator",
341
348
  coverageNote: "release workflow — activated by the wave-4 switch-over RFC",
342
- reads: ["forge.yaml", "forge.generated.yaml", ".git/**", "hooks/**", "pnpm-workspace.yaml", "package.json", "packages/*/package.json"],
349
+ reads: ["forge.yaml", "forge.generated.yaml", ".git/**", "hooks/**", "pnpm-workspace.yaml", "package.json", "packages/*/package.json", "packages/*/extract.config.yaml"],
343
350
  cacheable: false,
344
351
  flags: {
345
352
  lines: {
@@ -713,6 +720,55 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
713
720
  },
714
721
  execute: runFlowPush,
715
722
  },
723
+ {
724
+ name: "flow.publication.retire",
725
+ description:
726
+ "Retire a pending publication tag (RFC-1503) — operator-only. " +
727
+ "Appends one publish-retired journal event so flow.push never " +
728
+ "attempts the tag again: the escape for a pushed tag that can " +
729
+ "never publish (broken extract config the destination must not " +
730
+ "see, a version that must not ship). Refuses FLOW-RETIRE-01 " +
731
+ "when the tag is not pending and FLOW-RETIRE-02 on an empty " +
732
+ "--reason.",
733
+ scope: "workspace",
734
+ contract: "flow",
735
+ rules: [
736
+ { id: "FLOW-RETIRE-01", severity: "error" },
737
+ { id: "FLOW-RETIRE-02", severity: "error" },
738
+ { id: "FLOW-07", severity: "error" },
739
+ ],
740
+ mutatesState: true,
741
+ idempotency: "not-idempotent",
742
+ execOnReadOnly: false,
743
+ mutatingFlags: [],
744
+ writes: [".git/**"],
745
+ generates: [],
746
+ coverage: "operator",
747
+ coverageNote: "outbound journal mutation — operator command only (RFC-1503)",
748
+ reads: [
749
+ "forge.yaml",
750
+ ".git/**",
751
+ "docs/rfcs/*.md",
752
+ "pnpm-workspace.yaml",
753
+ "package.json",
754
+ "packages/*/package.json",
755
+ ".github/workflows/**",
756
+ ],
757
+ cacheable: false,
758
+ flags: {
759
+ tag: {
760
+ kind: "string",
761
+ required: true,
762
+ description: "The pending publication tag to retire (e.g. lib@1.2.3).",
763
+ },
764
+ reason: {
765
+ kind: "string",
766
+ required: true,
767
+ description: "Why the tag can never publish — journaled verbatim.",
768
+ },
769
+ },
770
+ execute: runFlowPublicationRetire,
771
+ },
716
772
  {
717
773
  name: "flow.status",
718
774
  description:
@@ -17,13 +17,14 @@ released with no mutation.</purpose>
17
17
  <item>The integration lock spans open→main-move so no second integration can interleave between the gate and the main fast-forward.</item>
18
18
  <item>Version writes are verified textual replacements (VersionWriteError → FLOW-CUT-11); the release branch is removed on that failure per AUDIT-RFC-1490-C3.</item>
19
19
  <item>Resume keys on the develop tip's `chore(release):` subject — the subject is the persisted declaration of which tags the release intends.</item>
20
+ <item>RFC-1502: `git add -u` folds the release-prepare hook's tracked edits in; its untracked leftovers are listed as FLOW-CUT-14 then removed via io.rm (the integrate gate demands a clean tree, and `git clean -f` is blocked in agent sessions). Pre-tag verification extracts every named line at the release commit — a failure deletes worktree+branch before any ref or tag moves (FLOW-CUT-13).</item>
20
21
  </KEY_DECISIONS>
21
22
  <CHANGE_SUMMARY>
22
- <item>RFC-1490: step 4 — ordinary flow.cut (release branch, verified versions, gate, main swap, tags, resume)</item>
23
- <item>RFC-1490: step 6 — flow.fix + fix-mode cut (patch-only, rebase on moved main, gate target main, trailing back-merge)</item>
24
23
  <item>RFC-1490: independent-review pass — lock-held planning, fix-branch verification, spec-shaped data, coverage</item>
25
24
  <item>RFC-1491: step 1 — journal base/rewrites + held registry widening, W1-1 discard tip, FLOW-INT-11</item>
26
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>
27
28
  <history>RFC-1490</history>
28
29
  </CHANGE_SUMMARY>
29
30
  */
@@ -72,6 +73,7 @@ import {
72
73
  } from "../release-tags.ts";
73
74
  import { runFlowScript, type FlowScriptResult } from "../scripts.ts";
74
75
  import { VersionWriteError, writeLineVersion, writeSyncedForgeVersion } from "../version-files.ts";
76
+ import { verifyLineAtRef } from "../publish.ts";
75
77
  import { primaryWorktree } from "../worktree-path.ts";
76
78
  import { integrateFlowBranch } from "./flow-integrate.ts";
77
79
  import { openFlowBranchCore } from "./flow-open.ts";
@@ -110,6 +112,8 @@ export interface FlowCutData {
110
112
  gate: FlowScriptResult | null;
111
113
  /** Fix mode only: the trailing back-merge's full data (null on ordinary cuts). */
112
114
  backmerge: FlowBackmergeData | null;
115
+ /** Ordered plan steps — populated on --dry-run (RFC-1502), [] elsewhere. */
116
+ steps: string[];
113
117
  diagnostics: Diagnostic[];
114
118
  }
115
119
 
@@ -143,6 +147,7 @@ function refuse(
143
147
  fingerprints: {},
144
148
  gate: null,
145
149
  backmerge: null,
150
+ steps: [],
146
151
  diagnostics: [{ ruleId, severity: "error", message, fixHint }],
147
152
  };
148
153
  }
@@ -443,6 +448,40 @@ export function toFlowCutLines(
443
448
  });
444
449
  }
445
450
 
451
+ /**
452
+ * `extract-verify:<line>` steps for named non-repository lines with an
453
+ * extract.config.yaml — anchored on the primary checkout, same probe the
454
+ * execution path uses (RFC-1502).
455
+ */
456
+ export async function plannedExtractVerifySteps(
457
+ primary: string,
458
+ io: WorkspaceIO,
459
+ cutLines: CutLine[],
460
+ repoLine: ReleaseLine,
461
+ ): Promise<string[]> {
462
+ const steps: string[] = [];
463
+ for (const c of cutLines) {
464
+ if (c.line.id === repoLine.id) continue;
465
+ const dir = c.line.paths[0];
466
+ if (dir !== undefined && (await io.exists(join(primary, dir, "extract.config.yaml")))) {
467
+ steps.push(`extract-verify:${c.line.id}`);
468
+ }
469
+ }
470
+ return steps;
471
+ }
472
+
473
+ /** Ordered step names the --dry-run plan reports (RFC-1502 AC-6). */
474
+ async function plannedCutSteps(
475
+ primary: string,
476
+ io: WorkspaceIO,
477
+ plan: Pick<CutPlan, "cutLines" | "repoLine">,
478
+ ): Promise<string[]> {
479
+ const steps = ["open-branch", "version-writes", "release-prepare", "release-commit"];
480
+ steps.push(...(await plannedExtractVerifySteps(primary, io, plan.cutLines, plan.repoLine)));
481
+ steps.push("integrate", "fingerprints", "main", "tags", "journal");
482
+ return steps;
483
+ }
484
+
446
485
  function completedReleaseData(outcome: {
447
486
  ref: string;
448
487
  tags: string[];
@@ -465,6 +504,7 @@ function completedReleaseData(outcome: {
465
504
  fingerprints: {},
466
505
  gate: null,
467
506
  backmerge: null,
507
+ steps: [],
468
508
  diagnostics: [],
469
509
  };
470
510
  }
@@ -508,6 +548,7 @@ export async function runOrdinaryCut(
508
548
  fingerprints: {},
509
549
  gate: null,
510
550
  backmerge: null,
551
+ steps: await plannedCutSteps(plan.primary, io, plan),
511
552
  diagnostics: [],
512
553
  };
513
554
  }
@@ -605,8 +646,59 @@ export async function runOrdinaryCut(
605
646
  throw error;
606
647
  }
607
648
 
608
- // 3. release commit.
609
- await git(wt, io, ["add", "-A"]);
649
+ // 2b. release-prepare hook (RFC-1502): the repository regenerates
650
+ // version-hashed derived artifacts into the release commit. The
651
+ // script always comes from the primary — a session cannot weaken it.
652
+ const warnings: Diagnostic[] = [];
653
+ const prep = await runFlowScript(io, "release-prepare", {
654
+ primary,
655
+ cwd: wt,
656
+ env: {
657
+ FORGE_FLOW_RELEASE_TAGS: tagList.join(" "),
658
+ FORGE_FLOW_RELEASE_VERSIONS: JSON.stringify(
659
+ Object.fromEntries(cutLines.map((c) => [c.line.id, c.nextVersion])),
660
+ ),
661
+ },
662
+ });
663
+ if (prep.status === "failed") {
664
+ await git(repoRoot, io, ["worktree", "remove", "--force", wt]);
665
+ await git(repoRoot, io, ["branch", "-D", releaseBranch]);
666
+ return refuse(
667
+ "FLOW-CUT-12",
668
+ `hooks/release-prepare.sh failed (exit ${prep.exitCode}): ${prep.stderrTail}`,
669
+ "fix the release-prepare hook and re-run flow.cut",
670
+ { releaseBranch },
671
+ );
672
+ }
673
+
674
+ // 3. release commit — `add -u` folds the hook's tracked edits in;
675
+ // untracked files it left stay out and are reported.
676
+ await git(wt, io, ["add", "-u"]);
677
+ const untrackedFiles = (
678
+ await git(wt, io, [
679
+ "-c",
680
+ "core.quotepath=false",
681
+ "ls-files",
682
+ "-z",
683
+ "--others",
684
+ "--exclude-standard",
685
+ ])
686
+ ).stdout
687
+ .split("\0")
688
+ .filter((f) => f.length > 0);
689
+ if (untrackedFiles.length > 0) {
690
+ warnings.push({
691
+ ruleId: "FLOW-CUT-14",
692
+ severity: "warning",
693
+ message: `release-prepare left untracked file(s) excluded from the release commit and removed from the release worktree: ${untrackedFiles.join(", ")}`,
694
+ });
695
+ // The cut continues — the same unignored-untracked set comes out of
696
+ // the worktree so the integrate gate sees a clean tree. Removed via
697
+ // io.rm: `git clean -f` is blocked in agent sessions.
698
+ for (const file of untrackedFiles) {
699
+ await io.rm(join(wt, file));
700
+ }
701
+ }
610
702
  const body = cutLines
611
703
  .map((c) => `${c.tag} ${c.level} ${c.previousTag ?? "null"}`)
612
704
  .join("\n");
@@ -615,6 +707,25 @@ export async function runOrdinaryCut(
615
707
  return refuse("FLOW-CUT-01", `release commit failed: ${commit.stderr.trim()}`, "inspect the release worktree state", { releaseBranch });
616
708
  }
617
709
 
710
+ // 3b. pre-tag extract verification (RFC-1502): every named package
711
+ // line extracts at the release commit into a scratch and runs
712
+ // extract-verify — before the integration that makes it a release.
713
+ const releaseSha = (await git(wt, io, ["rev-parse", "HEAD"])).stdout.trim();
714
+ for (const c of cutLines) {
715
+ if (c.line.id === repoLine.id) continue;
716
+ const verify = await verifyLineAtRef(primary, io, { line: c.line, ref: releaseSha });
717
+ if (!verify.ok) {
718
+ await git(repoRoot, io, ["worktree", "remove", "--force", wt]);
719
+ await git(repoRoot, io, ["branch", "-D", releaseBranch]);
720
+ return refuse(
721
+ "FLOW-CUT-13",
722
+ `pre-tag extract verification failed for line ${c.line.id}: ${verify.detail}`,
723
+ "fix the extract or verify failure and re-run flow.cut",
724
+ { releaseBranch },
725
+ );
726
+ }
727
+ }
728
+
618
729
  // 4. integrate (gate + ff + cleanup) with the lock already held.
619
730
  const integrated = await integrateFlowBranch(repoRoot, io, {
620
731
  branch: releaseBranch,
@@ -634,7 +745,7 @@ export async function runOrdinaryCut(
634
745
  }
635
746
 
636
747
  // 5–8. fingerprints → main → tags → journal.
637
- return finishCutTail(repoRoot, io, {
748
+ const tail = await finishCutTail(repoRoot, io, {
638
749
  developTip: integrated.developAfter ?? plan.ref,
639
750
  tagNames: tagList,
640
751
  cutLines,
@@ -646,6 +757,7 @@ export async function runOrdinaryCut(
646
757
  journalBranch: releaseBranch,
647
758
  journalBase: integrated.developBefore ?? plan.ref,
648
759
  });
760
+ return { ...tail, diagnostics: [...warnings, ...tail.diagnostics] };
649
761
  },
650
762
  io,
651
763
  );
@@ -814,6 +926,7 @@ async function finishCutTail(
814
926
  fingerprints,
815
927
  gate,
816
928
  backmerge: null,
929
+ steps: await plannedCutSteps(primary, io, { cutLines, repoLine }),
817
930
  diagnostics: [],
818
931
  };
819
932
  }