@warpgogol/forge 9.4.0 → 9.5.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 (167) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +4 -2
  3. package/README.uk.md +10 -8
  4. package/bin/cli.ts +152 -11
  5. package/dist/bin/cli.js +125 -5
  6. package/dist/bin/cli.js.map +1 -1
  7. package/dist/os/flow/dirty-classify.d.ts +11 -1
  8. package/dist/os/flow/dirty-classify.d.ts.map +1 -1
  9. package/dist/os/flow/dirty-classify.js +13 -0
  10. package/dist/os/flow/dirty-classify.js.map +1 -1
  11. package/dist/os/flow/flow.module.d.ts.map +1 -1
  12. package/dist/os/flow/flow.module.js +29 -3
  13. package/dist/os/flow/flow.module.js.map +1 -1
  14. package/dist/os/flow/handlers/flow-check.d.ts.map +1 -1
  15. package/dist/os/flow/handlers/flow-check.js +9 -9
  16. package/dist/os/flow/handlers/flow-check.js.map +1 -1
  17. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
  18. package/dist/os/flow/handlers/flow-cut.js +22 -8
  19. package/dist/os/flow/handlers/flow-cut.js.map +1 -1
  20. package/dist/os/flow/handlers/flow-integrate.d.ts +6 -0
  21. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
  22. package/dist/os/flow/handlers/flow-integrate.js +155 -44
  23. package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
  24. package/dist/os/flow/handlers/flow-open.d.ts.map +1 -1
  25. package/dist/os/flow/handlers/flow-open.js +14 -19
  26. package/dist/os/flow/handlers/flow-open.js.map +1 -1
  27. package/dist/os/flow/handlers/flow-peers.d.ts +24 -0
  28. package/dist/os/flow/handlers/flow-peers.d.ts.map +1 -0
  29. package/dist/os/flow/handlers/flow-peers.js +99 -0
  30. package/dist/os/flow/handlers/flow-peers.js.map +1 -0
  31. package/dist/os/flow/index.d.ts +3 -0
  32. package/dist/os/flow/index.d.ts.map +1 -1
  33. package/dist/os/flow/index.js +9 -4
  34. package/dist/os/flow/index.js.map +1 -1
  35. package/dist/os/flow/ops-registry.d.ts +33 -0
  36. package/dist/os/flow/ops-registry.d.ts.map +1 -0
  37. package/dist/os/flow/ops-registry.js +177 -0
  38. package/dist/os/flow/ops-registry.js.map +1 -0
  39. package/dist/os/flow/preflight.d.ts +70 -3
  40. package/dist/os/flow/preflight.d.ts.map +1 -1
  41. package/dist/os/flow/preflight.js +545 -49
  42. package/dist/os/flow/preflight.js.map +1 -1
  43. package/dist/os/flow/registry.d.ts +2 -2
  44. package/dist/os/flow/standalone-invoke.d.ts +11 -0
  45. package/dist/os/flow/standalone-invoke.d.ts.map +1 -0
  46. package/dist/os/flow/standalone-invoke.js +75 -0
  47. package/dist/os/flow/standalone-invoke.js.map +1 -0
  48. package/dist/os/gate-run/detach.d.ts +27 -0
  49. package/dist/os/gate-run/detach.d.ts.map +1 -0
  50. package/dist/os/gate-run/detach.js +85 -0
  51. package/dist/os/gate-run/detach.js.map +1 -0
  52. package/dist/os/gate-run/gate-run.module.d.ts +3 -0
  53. package/dist/os/gate-run/gate-run.module.d.ts.map +1 -0
  54. package/dist/os/gate-run/gate-run.module.js +23 -0
  55. package/dist/os/gate-run/gate-run.module.js.map +1 -0
  56. package/dist/os/gate-run/index.d.ts +7 -0
  57. package/dist/os/gate-run/index.d.ts.map +1 -0
  58. package/dist/os/gate-run/index.js +5 -0
  59. package/dist/os/gate-run/index.js.map +1 -0
  60. package/dist/os/gate-run/record.d.ts +47 -0
  61. package/dist/os/gate-run/record.d.ts.map +1 -0
  62. package/dist/os/gate-run/record.js +157 -0
  63. package/dist/os/gate-run/record.js.map +1 -0
  64. package/dist/os/gate-run/status.d.ts +41 -0
  65. package/dist/os/gate-run/status.d.ts.map +1 -0
  66. package/dist/os/gate-run/status.js +142 -0
  67. package/dist/os/gate-run/status.js.map +1 -0
  68. package/dist/os/gate-run/types.d.ts +47 -0
  69. package/dist/os/gate-run/types.d.ts.map +1 -0
  70. package/dist/os/gate-run/types.js +24 -0
  71. package/dist/os/gate-run/types.js.map +1 -0
  72. package/dist/os/mission/handlers/archive.d.ts.map +1 -1
  73. package/dist/os/mission/handlers/archive.js +12 -8
  74. package/dist/os/mission/handlers/archive.js.map +1 -1
  75. package/dist/os/mission/importer-block.d.ts +19 -0
  76. package/dist/os/mission/importer-block.d.ts.map +1 -0
  77. package/dist/os/mission/importer-block.js +124 -0
  78. package/dist/os/mission/importer-block.js.map +1 -0
  79. package/dist/os/mission/lockfile.d.ts +17 -0
  80. package/dist/os/mission/lockfile.d.ts.map +1 -1
  81. package/dist/os/mission/lockfile.js +38 -0
  82. package/dist/os/mission/lockfile.js.map +1 -1
  83. package/dist/os/rfc/evidence-annotation.d.ts +26 -0
  84. package/dist/os/rfc/evidence-annotation.d.ts.map +1 -0
  85. package/dist/os/rfc/evidence-annotation.js +52 -0
  86. package/dist/os/rfc/evidence-annotation.js.map +1 -0
  87. package/dist/os/rfc/handlers/fixed-inputs.d.ts.map +1 -1
  88. package/dist/os/rfc/handlers/fixed-inputs.js +7 -1
  89. package/dist/os/rfc/handlers/fixed-inputs.js.map +1 -1
  90. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  91. package/dist/os/rfc/handlers/implement-stamp.js +21 -28
  92. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  93. package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
  94. package/dist/os/rfc/handlers/list-create.js +25 -3
  95. package/dist/os/rfc/handlers/list-create.js.map +1 -1
  96. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  97. package/dist/os/rfc/handlers/validate-rules.js +127 -7
  98. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  99. package/dist/os/rfc/rfc.module.d.ts.map +1 -1
  100. package/dist/os/rfc/rfc.module.js +3 -2
  101. package/dist/os/rfc/rfc.module.js.map +1 -1
  102. package/dist/os/rfc/types.d.ts +9 -2
  103. package/dist/os/rfc/types.d.ts.map +1 -1
  104. package/dist/os/rfc/types.js +2 -2
  105. package/dist/os/rfc/types.js.map +1 -1
  106. package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -1
  107. package/dist/os/system/handlers/system-task-collect.js +11 -5
  108. package/dist/os/system/handlers/system-task-collect.js.map +1 -1
  109. package/dist/src/cli-flags.d.ts.map +1 -1
  110. package/dist/src/cli-flags.js +6 -0
  111. package/dist/src/cli-flags.js.map +1 -1
  112. package/dist/src/onboarding/prettierignore.d.ts.map +1 -1
  113. package/dist/src/onboarding/prettierignore.js +2 -0
  114. package/dist/src/onboarding/prettierignore.js.map +1 -1
  115. package/dist/src/types.d.ts +7 -0
  116. package/dist/src/types.d.ts.map +1 -1
  117. package/dist/src/types.js +2 -8
  118. package/dist/src/types.js.map +1 -1
  119. package/os/flow/dirty-classify.ts +21 -0
  120. package/os/flow/flow.module.ts +31 -3
  121. package/os/flow/handlers/flow-check.ts +17 -18
  122. package/os/flow/handlers/flow-cut.ts +28 -11
  123. package/os/flow/handlers/flow-integrate.ts +229 -62
  124. package/os/flow/handlers/flow-open.ts +24 -31
  125. package/os/flow/handlers/flow-peers.ts +142 -0
  126. package/os/flow/index.ts +10 -8
  127. package/os/flow/ops-registry.ts +194 -0
  128. package/os/flow/preflight.ts +608 -55
  129. package/os/flow/standalone-invoke.ts +85 -0
  130. package/os/flow/tests/dirty-classify.test.ts +139 -4
  131. package/os/flow/tests/flow-cut.test.ts +21 -0
  132. package/os/flow/tests/flow-integrate.preflight.test.ts +34 -9
  133. package/os/flow/tests/flow-integrate.test.ts +433 -17
  134. package/os/flow/tests/lockfile-induced.test.ts +328 -0
  135. package/os/flow/tests/ops-registry.test.ts +136 -0
  136. package/os/gate-run/detach.ts +106 -0
  137. package/os/gate-run/gate-run.module.ts +25 -0
  138. package/os/gate-run/index.ts +16 -0
  139. package/os/gate-run/record.ts +194 -0
  140. package/os/gate-run/status.ts +168 -0
  141. package/os/gate-run/tests/gate-run-detach.test.ts +144 -0
  142. package/os/gate-run/tests/gate-run-record.test.ts +200 -0
  143. package/os/gate-run/types.ts +73 -0
  144. package/os/mission/handlers/archive.ts +22 -14
  145. package/os/mission/importer-block.ts +119 -0
  146. package/os/mission/lockfile.ts +41 -0
  147. package/os/rfc/evidence-annotation.ts +61 -0
  148. package/os/rfc/handlers/fixed-inputs.test.ts +70 -0
  149. package/os/rfc/handlers/fixed-inputs.ts +11 -1
  150. package/os/rfc/handlers/implement-stamp.ts +25 -28
  151. package/os/rfc/handlers/list-create.test.ts +58 -5
  152. package/os/rfc/handlers/list-create.ts +30 -3
  153. package/os/rfc/handlers/validate-evidence-shape.test.ts +218 -0
  154. package/os/rfc/handlers/validate-probe-meta.test.ts +71 -0
  155. package/os/rfc/handlers/validate-rules.ts +169 -17
  156. package/os/rfc/handlers/validate-transient-probes.test.ts +222 -0
  157. package/os/rfc/rfc-0000-template.md +10 -10
  158. package/os/rfc/rfc.module.ts +3 -2
  159. package/os/rfc/types.ts +5 -2
  160. package/os/system/handlers/system-task-collect.ts +11 -5
  161. package/os/system/tests/system-task-collect.test.ts +16 -0
  162. package/package.json +17 -1
  163. package/skills/fo/fo-session-retro/SKILL.md +12 -4
  164. package/src/cli-flags.ts +7 -0
  165. package/src/onboarding/prettierignore.ts +2 -0
  166. package/src/tests/prettierignore-manage.test.ts +11 -0
  167. package/src/types.ts +9 -8
@@ -11,14 +11,12 @@ and a held integration lock is waited out.</purpose>
11
11
  </non-goals>
12
12
  </MODULE_CONTRACT>
13
13
  <CHANGE_SUMMARY>
14
- <item>RFC-1515: harden forge flow worktree lifecycle against vanished paths, forge-local state, dead-holder locks and generated drift</item>
15
- <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>
16
- <item>RFC-1528: flow.integrate bounded preflight before rebase and gate
17
-
18
- Classified lockfile diffs on FLOW-INT-01/03, early primary check, and resolvable validators (ecosystem.manifest.validate, scoped rfc.validate, friction.validate) refusing as FLOW-INT-12/13/14.</item>
19
- <item>RFC-1537: classify regenerable worktree dirt and journal integrate refusals cheapest-first</item>
20
- <item>RFC-1538: revalidate integration preconditions post-lock and reuse the session engine</item>
21
- <history>RFC-1487</history>
14
+ <item>RFC-1546: derive-and-repair recoverable state across flow surfaces (AC-1..AC-5)</item>
15
+ <item>RFC-1545: standalone generated-conflict regeneration in flow.integrate</item>
16
+ <item>RFC-1543: attribute shared-checkout dirt to live ops and expose peers (RFC-1543)</item>
17
+ <item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
18
+ <item>ADR-0128: FLOW-INT-02 names rebase stderr tail + porcelain status when no unmerged paths; cap path list at 20 (+N more) (ADR-0128 F-0188)</item>
19
+ <history>RFC-1487, RFC-1515, RFC-1528, RFC-1537, RFC-1538</history>
22
20
  </CHANGE_SUMMARY>
23
21
  */
24
22
 
@@ -130,6 +128,72 @@ describe("flow.integrate", () => {
130
128
  expect(wt.stdout.trim()).toBe("");
131
129
  }, 20_000);
132
130
 
131
+ it("names the cause when the rebase fails without unmerged paths (ADR-0128, F-0188)", async () => {
132
+ const repo = await governedRepo();
133
+ const session = await openSession(repo, "blocked");
134
+ // the session branch needs a unique commit so the integrate actually
135
+ // reaches the rebase stage; without it the branch fast-forwards trivially.
136
+ await commitIn(session.worktree!, "session.txt", "session work\n");
137
+ // develop-only path whose worktree twin is tolerated dirt — the dirty
138
+ // preflight lets it through (FORGE_STATE_FILES) but the rebase checkout
139
+ // refuses on it before any unmerged path exists.
140
+ await mkdir(join(repo, ".forge"), { recursive: true });
141
+ await commitIn(repo, ".forge/knowledge-conflicts.txt", "develop content\n");
142
+ await mkdir(join(session.worktree!, ".forge"), { recursive: true });
143
+ await writeFile(
144
+ join(session.worktree!, ".forge/knowledge-conflicts.txt"),
145
+ "session-local state\n",
146
+ );
147
+
148
+ const data = await integrateFlowBranch(repo, ambientIo, {
149
+ branch: session.branch!,
150
+ dryRun: false,
151
+ now: NOW,
152
+ });
153
+
154
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
155
+ const message = data.diagnostics[0]?.message ?? "";
156
+ expect(message).toContain("failed without unmerged paths");
157
+ expect(message).toContain("knowledge-conflicts.txt");
158
+ expect(data.diagnostics[0]?.fixHint).toContain("clean the listed worktree state");
159
+ const details = (data.diagnostics[0] as { data?: Record<string, unknown> }).data;
160
+ expect(details?.conflictedPaths).toEqual([]);
161
+ expect((details?.rebaseStderrTail as string[]).join("\n")).toContain(
162
+ "knowledge-conflicts.txt",
163
+ );
164
+ expect((details?.statusPorcelain as string[]).join("\n")).toContain(".forge/");
165
+ }, 20_000);
166
+
167
+ it("caps the conflicted path list at 20 and reports the remainder (ADR-0128, F-0188)", async () => {
168
+ const repo = await governedRepo();
169
+ const session = await openSession(repo, "many");
170
+ // 22 files conflict in ONE commit each side — the rebase stops with all
171
+ // of them unmerged at once.
172
+ for (let i = 0; i < 22; i++) {
173
+ await writeFile(join(session.worktree!, `f${String(i).padStart(2, "0")}.txt`), "session\n");
174
+ }
175
+ await gitExec(session.worktree!, ["add", "."]);
176
+ await gitExec(session.worktree!, ["commit", "-m", "session adds 22 files"]);
177
+ for (let i = 0; i < 22; i++) {
178
+ await writeFile(join(repo, `f${String(i).padStart(2, "0")}.txt`), "develop\n");
179
+ }
180
+ await gitExec(repo, ["add", "."]);
181
+ await gitExec(repo, ["commit", "-m", "develop edits 22 files"]);
182
+
183
+ const data = await integrateFlowBranch(repo, ambientIo, {
184
+ branch: session.branch!,
185
+ dryRun: false,
186
+ now: NOW,
187
+ });
188
+
189
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
190
+ const message = data.diagnostics[0]?.message ?? "";
191
+ expect(message).toContain("(+2 more)");
192
+ expect(message).not.toContain("f21.txt");
193
+ const details = (data.diagnostics[0] as { data?: Record<string, unknown> }).data;
194
+ expect((details?.conflictedPaths as string[]).length).toBe(22);
195
+ }, 20_000);
196
+
133
197
  it("refuses FLOW-INT-05 when the primary gate fails though the branch's copy passes (AC-5)", async () => {
134
198
  const repo = await governedRepo();
135
199
  const session = await openSession(repo, "gate");
@@ -330,7 +394,9 @@ describe("flow.integrate — RFC-1515 lifecycle hardening", () => {
330
394
  });
331
395
 
332
396
  const common = await commonGitDir(ambientIo, repo);
333
- await (await import("../registry.ts")).appendJournal(ambientIo, common, {
397
+ await (
398
+ await import("../registry.ts")
399
+ ).appendJournal(ambientIo, common, {
334
400
  event: "hold",
335
401
  branch: session.branch!,
336
402
  sha: await sha(repo, session.branch!),
@@ -503,10 +569,8 @@ describe("flow.integrate — RFC-1538 post-lock revalidation, session engine, au
503
569
  const session = await openSession(repo, "genconf");
504
570
  await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
505
571
  await mkdir(join(repo, "docs", "rfcs"), { recursive: true });
506
- const sessionIndex =
507
- "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n";
508
- const developIndex =
509
- "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n";
572
+ const sessionIndex = "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n";
573
+ const developIndex = "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n";
510
574
  await commitIn(session.worktree!, "docs/rfcs/index.yaml", sessionIndex);
511
575
  await commitIn(repo, "docs/rfcs/index.yaml", developIndex);
512
576
 
@@ -532,15 +596,180 @@ describe("flow.integrate — RFC-1538 post-lock revalidation, session engine, au
532
596
  );
533
597
  }, 20_000);
534
598
 
599
+ it("a generated-only conflict without an invoke port engages the standalone adapter — spawn failure escalates FLOW-INT-02 (RFC-1545 AC-2/AC-4)", async () => {
600
+ const repo = await governedRepo();
601
+ const session = await openSession(repo, "standalone");
602
+ await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
603
+ await mkdir(join(repo, "docs", "rfcs"), { recursive: true });
604
+ await commitIn(
605
+ session.worktree!,
606
+ "docs/rfcs/index.yaml",
607
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n",
608
+ );
609
+ await commitIn(
610
+ repo,
611
+ "docs/rfcs/index.yaml",
612
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n",
613
+ );
614
+
615
+ // No invoke port — the adapter spawns `pnpm exec werkstatt run …` in the
616
+ // bare fixture worktree where no werkstatt binary resolves; the failure
617
+ // escalates as FLOW-INT-02, proving the standalone path engaged.
618
+ const data = await integrateFlowBranch(repo, ambientIo, {
619
+ branch: session.branch!,
620
+ dryRun: false,
621
+ now: NOW,
622
+ });
623
+
624
+ expect(data.integrated).toBe(false);
625
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
626
+ expect(data.diagnostics[0]?.message).toContain("auto-resolve of generated conflict");
627
+ }, 20_000);
628
+
629
+ it("a failing generator escalates to FLOW-INT-02 with its stderr in diagnostics (RFC-1545 AC-4)", async () => {
630
+ const repo = await governedRepo();
631
+ const session = await openSession(repo, "genfail");
632
+ await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
633
+ await mkdir(join(repo, "docs", "rfcs"), { recursive: true });
634
+ await commitIn(
635
+ session.worktree!,
636
+ "docs/rfcs/index.yaml",
637
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n",
638
+ );
639
+ await commitIn(
640
+ repo,
641
+ "docs/rfcs/index.yaml",
642
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n",
643
+ );
644
+
645
+ const data = await integrateFlowBranch(repo, ambientIo, {
646
+ branch: session.branch!,
647
+ dryRun: false,
648
+ now: NOW,
649
+ invoke: async () => ({
650
+ ok: false,
651
+ exitCode: 1,
652
+ summary: "rfc.index.generate crashed: schema error at docs/rfcs/rfc-0001.md",
653
+ }),
654
+ });
655
+
656
+ expect(data.integrated).toBe(false);
657
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
658
+ expect(data.diagnostics[0]?.message).toContain("auto-resolve of generated conflict");
659
+ expect(data.diagnostics[0]?.message).toContain("schema error");
660
+ }, 20_000);
661
+
662
+ it("a generator that leaves residual conflict markers escalates to FLOW-INT-02 (RFC-1545 AC-4)", async () => {
663
+ const repo = await governedRepo();
664
+ const session = await openSession(repo, "genmarkers");
665
+ await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
666
+ await mkdir(join(repo, "docs", "rfcs"), { recursive: true });
667
+ await commitIn(
668
+ session.worktree!,
669
+ "docs/rfcs/index.yaml",
670
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n",
671
+ );
672
+ await commitIn(
673
+ repo,
674
+ "docs/rfcs/index.yaml",
675
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n",
676
+ );
677
+
678
+ const data = await integrateFlowBranch(repo, ambientIo, {
679
+ branch: session.branch!,
680
+ dryRun: false,
681
+ now: NOW,
682
+ invoke: async () => {
683
+ // A "successful" regen that writes marker-laden output must not land.
684
+ await writeFile(
685
+ join(session.worktree!, "docs/rfcs/index.yaml"),
686
+ "command: rfc.index.generate\n<<<<<<< HEAD\ncount: 9\n=======\ncount: 2\n>>>>>>> branch\n",
687
+ );
688
+ return { ok: true, exitCode: 0 };
689
+ },
690
+ });
691
+
692
+ expect(data.integrated).toBe(false);
693
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
694
+ expect(data.diagnostics[0]?.message).toContain("conflict markers");
695
+ }, 20_000);
696
+
697
+ it("primary dirt held only by a live foreign claim waits, then refuses FLOW-INT-03 naming the holder (RFC-1543 AC-4)", async () => {
698
+ const repo = await governedRepo();
699
+ const session = await openSession(repo, "foreign");
700
+ await commitIn(session.worktree!, "f.txt", "f");
701
+ await commitIn(repo, "claimed.txt", "base");
702
+ // A live foreign op claims the file it is about to dirty on primary.
703
+ const { claimOp } = await import("../ops-registry.ts");
704
+ const { writeFile: wf } = await import("node:fs/promises");
705
+ await claimOp(repo, ambientIo, {
706
+ opId: "ship-001",
707
+ command: "leitstand.ship",
708
+ workspaceRoot: repo,
709
+ paths: ["claimed.txt"],
710
+ });
711
+ await wf(join(repo, "claimed.txt"), "dirty-in-flight");
712
+
713
+ const data = await integrateFlowBranch(repo, ambientIo, {
714
+ branch: session.branch!,
715
+ dryRun: false,
716
+ now: NOW,
717
+ waitForeignSeconds: 1,
718
+ });
719
+
720
+ expect(data.integrated).toBe(false);
721
+ const diag = data.diagnostics.find((d) => d.ruleId === "FLOW-INT-03");
722
+ expect(diag).toBeDefined();
723
+ expect(diag?.message).toContain("leitstand.ship ship-001");
724
+ expect((diag?.data?.["foreignHolders"] as { opId: string }[] | undefined)?.[0]?.opId).toBe(
725
+ "ship-001",
726
+ );
727
+ }, 30_000);
728
+
729
+ it("foreign-held primary dirt clears mid-wait and the integration proceeds (RFC-1543 AC-4)", async () => {
730
+ const repo = await governedRepo();
731
+ const session = await openSession(repo, "foreign2");
732
+ await commitIn(session.worktree!, "f2.txt", "f2");
733
+ await commitIn(repo, "claimed.txt", "base");
734
+ const { claimOp, releaseOp } = await import("../ops-registry.ts");
735
+ const { writeFile: wf } = await import("node:fs/promises");
736
+ await claimOp(repo, ambientIo, {
737
+ opId: "ship-002",
738
+ command: "leitstand.ship",
739
+ workspaceRoot: repo,
740
+ paths: ["claimed.txt"],
741
+ });
742
+ await wf(join(repo, "claimed.txt"), "dirty-in-flight");
743
+
744
+ // The foreign op finishes mid-wait: claim released, dirt committed away.
745
+ const clearer = setTimeout(() => {
746
+ void (async () => {
747
+ await releaseOp(repo, ambientIo, "ship-002");
748
+ await wf(join(repo, "claimed.txt"), "committed-away");
749
+ await gitExec(repo, ["add", "claimed.txt"]);
750
+ await gitExec(repo, ["commit", "-m", "foreign op lands its write"]);
751
+ })();
752
+ }, 1200);
753
+
754
+ const data = await integrateFlowBranch(repo, ambientIo, {
755
+ branch: session.branch!,
756
+ dryRun: false,
757
+ now: NOW,
758
+ waitForeignSeconds: 8,
759
+ });
760
+ clearTimeout(clearer);
761
+
762
+ expect(data.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
763
+ expect(data.integrated).toBe(true);
764
+ }, 30_000);
765
+
535
766
  it("a mixed generated/non-generated conflict set still refuses FLOW-INT-02 (AC-3 boundary)", async () => {
536
767
  const repo = await governedRepo();
537
768
  const session = await openSession(repo, "mixed");
538
769
  await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
539
770
  await mkdir(join(repo, "docs", "rfcs"), { recursive: true });
540
- const sessionIndex =
541
- "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n";
542
- const developIndex =
543
- "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n";
771
+ const sessionIndex = "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n";
772
+ const developIndex = "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n";
544
773
  await commitIn(session.worktree!, "docs/rfcs/index.yaml", sessionIndex);
545
774
  await commitIn(session.worktree!, "real.txt", "session-side");
546
775
  await commitIn(repo, "docs/rfcs/index.yaml", developIndex);
@@ -558,3 +787,190 @@ describe("flow.integrate — RFC-1538 post-lock revalidation, session engine, au
558
787
  expect(data.diagnostics[0]?.message).toContain("real.txt");
559
788
  }, 20_000);
560
789
  });
790
+
791
+ describe("flow.integrate — recoverable manifest drift (RFC-1546 AC-1)", () => {
792
+ it("sole FLOW-INT-12 drift regenerates the manifest and continues", async () => {
793
+ const repo = await governedRepo();
794
+ const session = await openSession(repo, "regen");
795
+ const { runIntegratePreflight } = await import("../preflight.ts");
796
+ const invoked: string[] = [];
797
+ let validateCalls = 0;
798
+ const cmd = (name: string) => ({
799
+ name,
800
+ provider: "workspace" as const,
801
+ description: name,
802
+ scope: "workspace" as const,
803
+ });
804
+ const preflight = await runIntegratePreflight({
805
+ primary: repo,
806
+ branchWorktree: session.worktree!,
807
+ branch: session.branch!,
808
+ io: ambientIo,
809
+ worktreeDirty: { entries: [], toleratedState: [] },
810
+ commands: [
811
+ "ecosystem.manifest.validate",
812
+ "ecosystem.manifest.generate",
813
+ "rfc.validate",
814
+ "friction.validate",
815
+ ].map(cmd),
816
+ invoke: async (name) => {
817
+ invoked.push(name);
818
+ if (name === "ecosystem.manifest.validate") {
819
+ validateCalls++;
820
+ return validateCalls === 1
821
+ ? { ok: false, exitCode: 1, summary: "stale: docs/ecosystem.generated.yaml" }
822
+ : { ok: true, exitCode: 0 };
823
+ }
824
+ return { ok: true, exitCode: 0 };
825
+ },
826
+ });
827
+ expect(preflight.ok).toBe(true);
828
+ expect(invoked).toEqual([
829
+ "ecosystem.manifest.validate",
830
+ "friction.validate",
831
+ "ecosystem.manifest.generate",
832
+ "ecosystem.manifest.validate",
833
+ ]);
834
+ }, 20_000);
835
+
836
+ it("a second violation alongside drift refuses without regenerating", async () => {
837
+ const repo = await governedRepo();
838
+ const session = await openSession(repo, "regen");
839
+ const { runIntegratePreflight } = await import("../preflight.ts");
840
+ const invoked: string[] = [];
841
+ const cmd = (name: string) => ({
842
+ name,
843
+ provider: "workspace" as const,
844
+ description: name,
845
+ scope: "workspace" as const,
846
+ });
847
+ const preflight = await runIntegratePreflight({
848
+ primary: repo,
849
+ branchWorktree: session.worktree!,
850
+ branch: session.branch!,
851
+ io: ambientIo,
852
+ worktreeDirty: { entries: [], toleratedState: [] },
853
+ commands: [
854
+ "ecosystem.manifest.validate",
855
+ "ecosystem.manifest.generate",
856
+ "friction.validate",
857
+ ].map(cmd),
858
+ invoke: async (name) => {
859
+ invoked.push(name);
860
+ if (name === "ecosystem.manifest.validate") {
861
+ return { ok: false, exitCode: 1, summary: "stale: docs/ecosystem.generated.yaml" };
862
+ }
863
+ // friction.validate is also red — drift is not the sole violation.
864
+ return { ok: false, exitCode: 1, summary: `${name} failed` };
865
+ },
866
+ });
867
+ expect(preflight.ok).toBe(false);
868
+ // The coexisting refusal fires; the regeneration never ran.
869
+ expect(preflight.refuse?.ruleId).toBe("FLOW-INT-14");
870
+ expect(invoked).toEqual(["ecosystem.manifest.validate", "friction.validate"]);
871
+ }, 20_000);
872
+ });
873
+
874
+ // RFC-1544 AC-2/AC-4: referent-aware importer-prune resolution inside
875
+ // flow.integrate — a foreign checkout's open mission restores its importer
876
+ // subtree (journaled), a stale prune commits as cleanup, and any prune diff
877
+ // that is not importer-only still refuses FLOW-INT-01.
878
+ const LOCK_WITH_IMPORTER = [
879
+ "importers:",
880
+ "",
881
+ " .:",
882
+ " dependencies: {}",
883
+ "",
884
+ " missions/m-foreign/workpiece:",
885
+ " dependencies:",
886
+ " vite: 5.0.0",
887
+ "",
888
+ "packages:",
889
+ " vite: 5.0.0",
890
+ "",
891
+ ].join("\n");
892
+ const LOCK_PRUNED = [
893
+ "importers:",
894
+ "",
895
+ " .:",
896
+ " dependencies: {}",
897
+ "",
898
+ "packages:",
899
+ " vite: 5.0.0",
900
+ "",
901
+ ].join("\n");
902
+
903
+ describe("flow.integrate — mission importer referents (RFC-1544)", () => {
904
+ it("AC-2: a foreign-open-mission prune is auto-restored and journaled", async () => {
905
+ const repo = await governedRepo();
906
+ await commitIn(repo, "pnpm-lock.yaml", LOCK_WITH_IMPORTER);
907
+ const session = await openSession(repo, "importer-foreign");
908
+ await commitIn(session.worktree!, "session.txt", "work");
909
+ // The foreign checkout: a detached worktree holding the open mission.
910
+ const foreign = join(repo, "..", `foreign-holder-${Date.now()}`);
911
+ dirs.push(foreign);
912
+ const add = await gitExec(repo, ["worktree", "add", "--detach", foreign, "develop"]);
913
+ expect(add.exitCode).toBe(0);
914
+ await mkdir(join(foreign, "missions", "m-foreign", "workpiece"), { recursive: true });
915
+ await writeFile(join(foreign, "missions", "m-foreign", "mission.yaml"), 'state: "open"\n');
916
+ // The session worktree's install pruned the importer it cannot see.
917
+ await writeFile(join(session.worktree!, "pnpm-lock.yaml"), LOCK_PRUNED);
918
+
919
+ const data = await integrateFlowBranch(repo, ambientIo, {
920
+ branch: session.branch!,
921
+ dryRun: false,
922
+ now: NOW,
923
+ });
924
+
925
+ expect(data.diagnostics).toEqual([]);
926
+ expect(data.integrated).toBe(true);
927
+ expect(data.restoredImporters).toEqual(["m-foreign"]);
928
+ // The restored lockfile matched HEAD — no prune commit reached develop.
929
+ const headLock = await gitExec(repo, ["show", "develop:pnpm-lock.yaml"]);
930
+ expect(headLock.stdout).toContain("missions/m-foreign/workpiece:");
931
+ }, 30_000);
932
+
933
+ it("AC-4: a prune diff that is not importer-only still refuses FLOW-INT-01", async () => {
934
+ const repo = await governedRepo();
935
+ await commitIn(repo, "pnpm-lock.yaml", LOCK_WITH_IMPORTER);
936
+ const session = await openSession(repo, "importer-mixed");
937
+ await commitIn(session.worktree!, "session.txt", "work");
938
+ // Importer prune + an unrelated removal — ambiguous, never computed.
939
+ await writeFile(
940
+ join(session.worktree!, "pnpm-lock.yaml"),
941
+ LOCK_PRUNED.replace(" vite: 5.0.0\n", ""),
942
+ );
943
+
944
+ const data = await integrateFlowBranch(repo, ambientIo, {
945
+ branch: session.branch!,
946
+ dryRun: false,
947
+ now: NOW,
948
+ });
949
+
950
+ expect(data.integrated).toBe(false);
951
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-01");
952
+ expect(data.restoredImporters).toBeUndefined();
953
+ expect(data.staleImporterCommitSha).toBeUndefined();
954
+ }, 30_000);
955
+
956
+ it("a prune whose referent exists nowhere commits as stale cleanup", async () => {
957
+ const repo = await governedRepo();
958
+ await commitIn(repo, "pnpm-lock.yaml", LOCK_WITH_IMPORTER);
959
+ const session = await openSession(repo, "importer-stale");
960
+ await commitIn(session.worktree!, "session.txt", "work");
961
+ await writeFile(join(session.worktree!, "pnpm-lock.yaml"), LOCK_PRUNED);
962
+
963
+ const data = await integrateFlowBranch(repo, ambientIo, {
964
+ branch: session.branch!,
965
+ dryRun: false,
966
+ now: NOW,
967
+ });
968
+
969
+ expect(data.diagnostics).toEqual([]);
970
+ expect(data.integrated).toBe(true);
971
+ expect(data.staleImporterCommitSha).toBeDefined();
972
+ // The prune commit rode the branch into develop — residue is gone.
973
+ const headLock = await gitExec(repo, ["show", "develop:pnpm-lock.yaml"]);
974
+ expect(headLock.stdout).not.toContain("missions/m-foreign/workpiece:");
975
+ }, 30_000);
976
+ });