@warpgogol/forge 9.4.0 → 9.4.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 (87) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +4 -2
  3. package/README.uk.md +10 -8
  4. package/dist/os/flow/dirty-classify.d.ts +4 -1
  5. package/dist/os/flow/dirty-classify.d.ts.map +1 -1
  6. package/dist/os/flow/dirty-classify.js +2 -0
  7. package/dist/os/flow/dirty-classify.js.map +1 -1
  8. package/dist/os/flow/flow.module.d.ts.map +1 -1
  9. package/dist/os/flow/flow.module.js +27 -2
  10. package/dist/os/flow/flow.module.js.map +1 -1
  11. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
  12. package/dist/os/flow/handlers/flow-cut.js +22 -8
  13. package/dist/os/flow/handlers/flow-cut.js.map +1 -1
  14. package/dist/os/flow/handlers/flow-integrate.d.ts +6 -0
  15. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
  16. package/dist/os/flow/handlers/flow-integrate.js +118 -40
  17. package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
  18. package/dist/os/flow/handlers/flow-peers.d.ts +24 -0
  19. package/dist/os/flow/handlers/flow-peers.d.ts.map +1 -0
  20. package/dist/os/flow/handlers/flow-peers.js +99 -0
  21. package/dist/os/flow/handlers/flow-peers.js.map +1 -0
  22. package/dist/os/flow/index.d.ts +2 -0
  23. package/dist/os/flow/index.d.ts.map +1 -1
  24. package/dist/os/flow/index.js +4 -1
  25. package/dist/os/flow/index.js.map +1 -1
  26. package/dist/os/flow/ops-registry.d.ts +33 -0
  27. package/dist/os/flow/ops-registry.d.ts.map +1 -0
  28. package/dist/os/flow/ops-registry.js +177 -0
  29. package/dist/os/flow/ops-registry.js.map +1 -0
  30. package/dist/os/flow/preflight.d.ts +46 -3
  31. package/dist/os/flow/preflight.d.ts.map +1 -1
  32. package/dist/os/flow/preflight.js +196 -44
  33. package/dist/os/flow/preflight.js.map +1 -1
  34. package/dist/os/flow/standalone-invoke.d.ts +11 -0
  35. package/dist/os/flow/standalone-invoke.d.ts.map +1 -0
  36. package/dist/os/flow/standalone-invoke.js +75 -0
  37. package/dist/os/flow/standalone-invoke.js.map +1 -0
  38. package/dist/os/mission/handlers/archive.d.ts.map +1 -1
  39. package/dist/os/mission/handlers/archive.js +12 -8
  40. package/dist/os/mission/handlers/archive.js.map +1 -1
  41. package/dist/os/mission/importer-block.d.ts +19 -0
  42. package/dist/os/mission/importer-block.d.ts.map +1 -0
  43. package/dist/os/mission/importer-block.js +124 -0
  44. package/dist/os/mission/importer-block.js.map +1 -0
  45. package/dist/os/mission/lockfile.d.ts +17 -0
  46. package/dist/os/mission/lockfile.d.ts.map +1 -1
  47. package/dist/os/mission/lockfile.js +38 -0
  48. package/dist/os/mission/lockfile.js.map +1 -1
  49. package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
  50. package/dist/os/rfc/handlers/list-create.js +25 -3
  51. package/dist/os/rfc/handlers/list-create.js.map +1 -1
  52. package/dist/os/rfc/types.d.ts +9 -2
  53. package/dist/os/rfc/types.d.ts.map +1 -1
  54. package/dist/os/rfc/types.js +2 -2
  55. package/dist/os/rfc/types.js.map +1 -1
  56. package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -1
  57. package/dist/os/system/handlers/system-task-collect.js +11 -5
  58. package/dist/os/system/handlers/system-task-collect.js.map +1 -1
  59. package/dist/src/onboarding/prettierignore.d.ts.map +1 -1
  60. package/dist/src/onboarding/prettierignore.js +2 -0
  61. package/dist/src/onboarding/prettierignore.js.map +1 -1
  62. package/os/flow/dirty-classify.ts +8 -0
  63. package/os/flow/flow.module.ts +29 -2
  64. package/os/flow/handlers/flow-cut.ts +28 -11
  65. package/os/flow/handlers/flow-integrate.ts +177 -50
  66. package/os/flow/handlers/flow-peers.ts +142 -0
  67. package/os/flow/index.ts +5 -1
  68. package/os/flow/ops-registry.ts +194 -0
  69. package/os/flow/preflight.ts +262 -51
  70. package/os/flow/standalone-invoke.ts +85 -0
  71. package/os/flow/tests/dirty-classify.test.ts +139 -4
  72. package/os/flow/tests/flow-cut.test.ts +21 -0
  73. package/os/flow/tests/flow-integrate.preflight.test.ts +8 -4
  74. package/os/flow/tests/flow-integrate.test.ts +366 -16
  75. package/os/flow/tests/ops-registry.test.ts +136 -0
  76. package/os/mission/handlers/archive.ts +22 -14
  77. package/os/mission/importer-block.ts +119 -0
  78. package/os/mission/lockfile.ts +41 -0
  79. package/os/rfc/handlers/list-create.test.ts +44 -0
  80. package/os/rfc/handlers/list-create.ts +30 -3
  81. package/os/rfc/types.ts +5 -2
  82. package/os/system/handlers/system-task-collect.ts +11 -5
  83. package/os/system/tests/system-task-collect.test.ts +16 -0
  84. package/package.json +1 -1
  85. package/skills/fo/fo-session-retro/SKILL.md +9 -3
  86. package/src/onboarding/prettierignore.ts +2 -0
  87. package/src/tests/prettierignore-manage.test.ts +11 -0
@@ -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
14
  <item>RFC-1538: revalidate integration preconditions post-lock and reuse the session engine</item>
21
- <history>RFC-1487</history>
15
+ <item>RFC-1546: derive-and-repair recoverable state across flow surfaces (AC-1..AC-5)</item>
16
+ <item>RFC-1545: standalone generated-conflict regeneration in flow.integrate</item>
17
+ <item>RFC-1543: attribute shared-checkout dirt to live ops and expose peers (RFC-1543)</item>
18
+ <item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
19
+ <history>RFC-1487, RFC-1515, RFC-1528, RFC-1537</history>
22
20
  </CHANGE_SUMMARY>
23
21
  */
24
22
 
@@ -330,7 +328,9 @@ describe("flow.integrate — RFC-1515 lifecycle hardening", () => {
330
328
  });
331
329
 
332
330
  const common = await commonGitDir(ambientIo, repo);
333
- await (await import("../registry.ts")).appendJournal(ambientIo, common, {
331
+ await (
332
+ await import("../registry.ts")
333
+ ).appendJournal(ambientIo, common, {
334
334
  event: "hold",
335
335
  branch: session.branch!,
336
336
  sha: await sha(repo, session.branch!),
@@ -503,10 +503,8 @@ describe("flow.integrate — RFC-1538 post-lock revalidation, session engine, au
503
503
  const session = await openSession(repo, "genconf");
504
504
  await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
505
505
  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";
506
+ const sessionIndex = "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n";
507
+ const developIndex = "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n";
510
508
  await commitIn(session.worktree!, "docs/rfcs/index.yaml", sessionIndex);
511
509
  await commitIn(repo, "docs/rfcs/index.yaml", developIndex);
512
510
 
@@ -532,15 +530,180 @@ describe("flow.integrate — RFC-1538 post-lock revalidation, session engine, au
532
530
  );
533
531
  }, 20_000);
534
532
 
533
+ 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 () => {
534
+ const repo = await governedRepo();
535
+ const session = await openSession(repo, "standalone");
536
+ await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
537
+ await mkdir(join(repo, "docs", "rfcs"), { recursive: true });
538
+ await commitIn(
539
+ session.worktree!,
540
+ "docs/rfcs/index.yaml",
541
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n",
542
+ );
543
+ await commitIn(
544
+ repo,
545
+ "docs/rfcs/index.yaml",
546
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n",
547
+ );
548
+
549
+ // No invoke port — the adapter spawns `pnpm exec werkstatt run …` in the
550
+ // bare fixture worktree where no werkstatt binary resolves; the failure
551
+ // escalates as FLOW-INT-02, proving the standalone path engaged.
552
+ const data = await integrateFlowBranch(repo, ambientIo, {
553
+ branch: session.branch!,
554
+ dryRun: false,
555
+ now: NOW,
556
+ });
557
+
558
+ expect(data.integrated).toBe(false);
559
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
560
+ expect(data.diagnostics[0]?.message).toContain("auto-resolve of generated conflict");
561
+ }, 20_000);
562
+
563
+ it("a failing generator escalates to FLOW-INT-02 with its stderr in diagnostics (RFC-1545 AC-4)", async () => {
564
+ const repo = await governedRepo();
565
+ const session = await openSession(repo, "genfail");
566
+ await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
567
+ await mkdir(join(repo, "docs", "rfcs"), { recursive: true });
568
+ await commitIn(
569
+ session.worktree!,
570
+ "docs/rfcs/index.yaml",
571
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n",
572
+ );
573
+ await commitIn(
574
+ repo,
575
+ "docs/rfcs/index.yaml",
576
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n",
577
+ );
578
+
579
+ const data = await integrateFlowBranch(repo, ambientIo, {
580
+ branch: session.branch!,
581
+ dryRun: false,
582
+ now: NOW,
583
+ invoke: async () => ({
584
+ ok: false,
585
+ exitCode: 1,
586
+ summary: "rfc.index.generate crashed: schema error at docs/rfcs/rfc-0001.md",
587
+ }),
588
+ });
589
+
590
+ expect(data.integrated).toBe(false);
591
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
592
+ expect(data.diagnostics[0]?.message).toContain("auto-resolve of generated conflict");
593
+ expect(data.diagnostics[0]?.message).toContain("schema error");
594
+ }, 20_000);
595
+
596
+ it("a generator that leaves residual conflict markers escalates to FLOW-INT-02 (RFC-1545 AC-4)", async () => {
597
+ const repo = await governedRepo();
598
+ const session = await openSession(repo, "genmarkers");
599
+ await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
600
+ await mkdir(join(repo, "docs", "rfcs"), { recursive: true });
601
+ await commitIn(
602
+ session.worktree!,
603
+ "docs/rfcs/index.yaml",
604
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n",
605
+ );
606
+ await commitIn(
607
+ repo,
608
+ "docs/rfcs/index.yaml",
609
+ "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n",
610
+ );
611
+
612
+ const data = await integrateFlowBranch(repo, ambientIo, {
613
+ branch: session.branch!,
614
+ dryRun: false,
615
+ now: NOW,
616
+ invoke: async () => {
617
+ // A "successful" regen that writes marker-laden output must not land.
618
+ await writeFile(
619
+ join(session.worktree!, "docs/rfcs/index.yaml"),
620
+ "command: rfc.index.generate\n<<<<<<< HEAD\ncount: 9\n=======\ncount: 2\n>>>>>>> branch\n",
621
+ );
622
+ return { ok: true, exitCode: 0 };
623
+ },
624
+ });
625
+
626
+ expect(data.integrated).toBe(false);
627
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-02");
628
+ expect(data.diagnostics[0]?.message).toContain("conflict markers");
629
+ }, 20_000);
630
+
631
+ it("primary dirt held only by a live foreign claim waits, then refuses FLOW-INT-03 naming the holder (RFC-1543 AC-4)", async () => {
632
+ const repo = await governedRepo();
633
+ const session = await openSession(repo, "foreign");
634
+ await commitIn(session.worktree!, "f.txt", "f");
635
+ await commitIn(repo, "claimed.txt", "base");
636
+ // A live foreign op claims the file it is about to dirty on primary.
637
+ const { claimOp } = await import("../ops-registry.ts");
638
+ const { writeFile: wf } = await import("node:fs/promises");
639
+ await claimOp(repo, ambientIo, {
640
+ opId: "ship-001",
641
+ command: "leitstand.ship",
642
+ workspaceRoot: repo,
643
+ paths: ["claimed.txt"],
644
+ });
645
+ await wf(join(repo, "claimed.txt"), "dirty-in-flight");
646
+
647
+ const data = await integrateFlowBranch(repo, ambientIo, {
648
+ branch: session.branch!,
649
+ dryRun: false,
650
+ now: NOW,
651
+ waitForeignSeconds: 1,
652
+ });
653
+
654
+ expect(data.integrated).toBe(false);
655
+ const diag = data.diagnostics.find((d) => d.ruleId === "FLOW-INT-03");
656
+ expect(diag).toBeDefined();
657
+ expect(diag?.message).toContain("leitstand.ship ship-001");
658
+ expect((diag?.data?.["foreignHolders"] as { opId: string }[] | undefined)?.[0]?.opId).toBe(
659
+ "ship-001",
660
+ );
661
+ }, 30_000);
662
+
663
+ it("foreign-held primary dirt clears mid-wait and the integration proceeds (RFC-1543 AC-4)", async () => {
664
+ const repo = await governedRepo();
665
+ const session = await openSession(repo, "foreign2");
666
+ await commitIn(session.worktree!, "f2.txt", "f2");
667
+ await commitIn(repo, "claimed.txt", "base");
668
+ const { claimOp, releaseOp } = await import("../ops-registry.ts");
669
+ const { writeFile: wf } = await import("node:fs/promises");
670
+ await claimOp(repo, ambientIo, {
671
+ opId: "ship-002",
672
+ command: "leitstand.ship",
673
+ workspaceRoot: repo,
674
+ paths: ["claimed.txt"],
675
+ });
676
+ await wf(join(repo, "claimed.txt"), "dirty-in-flight");
677
+
678
+ // The foreign op finishes mid-wait: claim released, dirt committed away.
679
+ const clearer = setTimeout(() => {
680
+ void (async () => {
681
+ await releaseOp(repo, ambientIo, "ship-002");
682
+ await wf(join(repo, "claimed.txt"), "committed-away");
683
+ await gitExec(repo, ["add", "claimed.txt"]);
684
+ await gitExec(repo, ["commit", "-m", "foreign op lands its write"]);
685
+ })();
686
+ }, 1200);
687
+
688
+ const data = await integrateFlowBranch(repo, ambientIo, {
689
+ branch: session.branch!,
690
+ dryRun: false,
691
+ now: NOW,
692
+ waitForeignSeconds: 8,
693
+ });
694
+ clearTimeout(clearer);
695
+
696
+ expect(data.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
697
+ expect(data.integrated).toBe(true);
698
+ }, 30_000);
699
+
535
700
  it("a mixed generated/non-generated conflict set still refuses FLOW-INT-02 (AC-3 boundary)", async () => {
536
701
  const repo = await governedRepo();
537
702
  const session = await openSession(repo, "mixed");
538
703
  await mkdir(join(session.worktree!, "docs", "rfcs"), { recursive: true });
539
704
  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";
705
+ const sessionIndex = "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 2\n";
706
+ const developIndex = "command: rfc.index.generate\ngeneratedAt: 2026-11-08\ncount: 9\n";
544
707
  await commitIn(session.worktree!, "docs/rfcs/index.yaml", sessionIndex);
545
708
  await commitIn(session.worktree!, "real.txt", "session-side");
546
709
  await commitIn(repo, "docs/rfcs/index.yaml", developIndex);
@@ -558,3 +721,190 @@ describe("flow.integrate — RFC-1538 post-lock revalidation, session engine, au
558
721
  expect(data.diagnostics[0]?.message).toContain("real.txt");
559
722
  }, 20_000);
560
723
  });
724
+
725
+ describe("flow.integrate — recoverable manifest drift (RFC-1546 AC-1)", () => {
726
+ it("sole FLOW-INT-12 drift regenerates the manifest and continues", async () => {
727
+ const repo = await governedRepo();
728
+ const session = await openSession(repo, "regen");
729
+ const { runIntegratePreflight } = await import("../preflight.ts");
730
+ const invoked: string[] = [];
731
+ let validateCalls = 0;
732
+ const cmd = (name: string) => ({
733
+ name,
734
+ provider: "workspace" as const,
735
+ description: name,
736
+ scope: "workspace" as const,
737
+ });
738
+ const preflight = await runIntegratePreflight({
739
+ primary: repo,
740
+ branchWorktree: session.worktree!,
741
+ branch: session.branch!,
742
+ io: ambientIo,
743
+ worktreeDirty: { entries: [], toleratedState: [] },
744
+ commands: [
745
+ "ecosystem.manifest.validate",
746
+ "ecosystem.manifest.generate",
747
+ "rfc.validate",
748
+ "friction.validate",
749
+ ].map(cmd),
750
+ invoke: async (name) => {
751
+ invoked.push(name);
752
+ if (name === "ecosystem.manifest.validate") {
753
+ validateCalls++;
754
+ return validateCalls === 1
755
+ ? { ok: false, exitCode: 1, summary: "stale: docs/ecosystem.generated.yaml" }
756
+ : { ok: true, exitCode: 0 };
757
+ }
758
+ return { ok: true, exitCode: 0 };
759
+ },
760
+ });
761
+ expect(preflight.ok).toBe(true);
762
+ expect(invoked).toEqual([
763
+ "ecosystem.manifest.validate",
764
+ "friction.validate",
765
+ "ecosystem.manifest.generate",
766
+ "ecosystem.manifest.validate",
767
+ ]);
768
+ }, 20_000);
769
+
770
+ it("a second violation alongside drift refuses without regenerating", async () => {
771
+ const repo = await governedRepo();
772
+ const session = await openSession(repo, "regen");
773
+ const { runIntegratePreflight } = await import("../preflight.ts");
774
+ const invoked: string[] = [];
775
+ const cmd = (name: string) => ({
776
+ name,
777
+ provider: "workspace" as const,
778
+ description: name,
779
+ scope: "workspace" as const,
780
+ });
781
+ const preflight = await runIntegratePreflight({
782
+ primary: repo,
783
+ branchWorktree: session.worktree!,
784
+ branch: session.branch!,
785
+ io: ambientIo,
786
+ worktreeDirty: { entries: [], toleratedState: [] },
787
+ commands: [
788
+ "ecosystem.manifest.validate",
789
+ "ecosystem.manifest.generate",
790
+ "friction.validate",
791
+ ].map(cmd),
792
+ invoke: async (name) => {
793
+ invoked.push(name);
794
+ if (name === "ecosystem.manifest.validate") {
795
+ return { ok: false, exitCode: 1, summary: "stale: docs/ecosystem.generated.yaml" };
796
+ }
797
+ // friction.validate is also red — drift is not the sole violation.
798
+ return { ok: false, exitCode: 1, summary: `${name} failed` };
799
+ },
800
+ });
801
+ expect(preflight.ok).toBe(false);
802
+ // The coexisting refusal fires; the regeneration never ran.
803
+ expect(preflight.refuse?.ruleId).toBe("FLOW-INT-14");
804
+ expect(invoked).toEqual(["ecosystem.manifest.validate", "friction.validate"]);
805
+ }, 20_000);
806
+ });
807
+
808
+ // RFC-1544 AC-2/AC-4: referent-aware importer-prune resolution inside
809
+ // flow.integrate — a foreign checkout's open mission restores its importer
810
+ // subtree (journaled), a stale prune commits as cleanup, and any prune diff
811
+ // that is not importer-only still refuses FLOW-INT-01.
812
+ const LOCK_WITH_IMPORTER = [
813
+ "importers:",
814
+ "",
815
+ " .:",
816
+ " dependencies: {}",
817
+ "",
818
+ " missions/m-foreign/workpiece:",
819
+ " dependencies:",
820
+ " vite: 5.0.0",
821
+ "",
822
+ "packages:",
823
+ " vite: 5.0.0",
824
+ "",
825
+ ].join("\n");
826
+ const LOCK_PRUNED = [
827
+ "importers:",
828
+ "",
829
+ " .:",
830
+ " dependencies: {}",
831
+ "",
832
+ "packages:",
833
+ " vite: 5.0.0",
834
+ "",
835
+ ].join("\n");
836
+
837
+ describe("flow.integrate — mission importer referents (RFC-1544)", () => {
838
+ it("AC-2: a foreign-open-mission prune is auto-restored and journaled", async () => {
839
+ const repo = await governedRepo();
840
+ await commitIn(repo, "pnpm-lock.yaml", LOCK_WITH_IMPORTER);
841
+ const session = await openSession(repo, "importer-foreign");
842
+ await commitIn(session.worktree!, "session.txt", "work");
843
+ // The foreign checkout: a detached worktree holding the open mission.
844
+ const foreign = join(repo, "..", `foreign-holder-${Date.now()}`);
845
+ dirs.push(foreign);
846
+ const add = await gitExec(repo, ["worktree", "add", "--detach", foreign, "develop"]);
847
+ expect(add.exitCode).toBe(0);
848
+ await mkdir(join(foreign, "missions", "m-foreign", "workpiece"), { recursive: true });
849
+ await writeFile(join(foreign, "missions", "m-foreign", "mission.yaml"), 'state: "open"\n');
850
+ // The session worktree's install pruned the importer it cannot see.
851
+ await writeFile(join(session.worktree!, "pnpm-lock.yaml"), LOCK_PRUNED);
852
+
853
+ const data = await integrateFlowBranch(repo, ambientIo, {
854
+ branch: session.branch!,
855
+ dryRun: false,
856
+ now: NOW,
857
+ });
858
+
859
+ expect(data.diagnostics).toEqual([]);
860
+ expect(data.integrated).toBe(true);
861
+ expect(data.restoredImporters).toEqual(["m-foreign"]);
862
+ // The restored lockfile matched HEAD — no prune commit reached develop.
863
+ const headLock = await gitExec(repo, ["show", "develop:pnpm-lock.yaml"]);
864
+ expect(headLock.stdout).toContain("missions/m-foreign/workpiece:");
865
+ }, 30_000);
866
+
867
+ it("AC-4: a prune diff that is not importer-only still refuses FLOW-INT-01", async () => {
868
+ const repo = await governedRepo();
869
+ await commitIn(repo, "pnpm-lock.yaml", LOCK_WITH_IMPORTER);
870
+ const session = await openSession(repo, "importer-mixed");
871
+ await commitIn(session.worktree!, "session.txt", "work");
872
+ // Importer prune + an unrelated removal — ambiguous, never computed.
873
+ await writeFile(
874
+ join(session.worktree!, "pnpm-lock.yaml"),
875
+ LOCK_PRUNED.replace(" vite: 5.0.0\n", ""),
876
+ );
877
+
878
+ const data = await integrateFlowBranch(repo, ambientIo, {
879
+ branch: session.branch!,
880
+ dryRun: false,
881
+ now: NOW,
882
+ });
883
+
884
+ expect(data.integrated).toBe(false);
885
+ expect(data.diagnostics[0]?.ruleId).toBe("FLOW-INT-01");
886
+ expect(data.restoredImporters).toBeUndefined();
887
+ expect(data.staleImporterCommitSha).toBeUndefined();
888
+ }, 30_000);
889
+
890
+ it("a prune whose referent exists nowhere commits as stale cleanup", async () => {
891
+ const repo = await governedRepo();
892
+ await commitIn(repo, "pnpm-lock.yaml", LOCK_WITH_IMPORTER);
893
+ const session = await openSession(repo, "importer-stale");
894
+ await commitIn(session.worktree!, "session.txt", "work");
895
+ await writeFile(join(session.worktree!, "pnpm-lock.yaml"), LOCK_PRUNED);
896
+
897
+ const data = await integrateFlowBranch(repo, ambientIo, {
898
+ branch: session.branch!,
899
+ dryRun: false,
900
+ now: NOW,
901
+ });
902
+
903
+ expect(data.diagnostics).toEqual([]);
904
+ expect(data.integrated).toBe(true);
905
+ expect(data.staleImporterCommitSha).toBeDefined();
906
+ // The prune commit rode the branch into develop — residue is gone.
907
+ const headLock = await gitExec(repo, ["show", "develop:pnpm-lock.yaml"]);
908
+ expect(headLock.stdout).not.toContain("missions/m-foreign/workpiece:");
909
+ }, 30_000);
910
+ });
@@ -0,0 +1,136 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>ops-registry tests (RFC-1543 AC-2/AC-5): claim write lands under the
4
+ shared git dir, liveness requires pid-alive ∧ bootId-match ∧ fresh heartbeat,
5
+ dead records are swept by the next reader, and claimCoversPath honors the
6
+ exact/prefix contract.</purpose>
7
+ <non-goals>
8
+ <item>No classifyDirt coverage — claim→class wiring lives in dirty-classify.test.ts.</item>
9
+ </non-goals>
10
+ </MODULE_CONTRACT>
11
+ <CHANGE_SUMMARY>
12
+ <item>RFC-1543: op-claim registry probes</item>
13
+ <item>RFC-1543: attribute shared-checkout dirt to live ops and expose peers (RFC-1543)</item>
14
+ </CHANGE_SUMMARY>
15
+ */
16
+
17
+ import { rm, writeFile, mkdir } from "node:fs/promises";
18
+ import { join } from "node:path";
19
+ import { afterEach, describe, expect, it } from "vitest";
20
+
21
+ import { ambientIo } from "../../../src/utils/io.ts";
22
+ import {
23
+ claimCoversPath,
24
+ claimOp,
25
+ isClaimLive,
26
+ liveClaims,
27
+ OP_CLAIM_SCHEMA,
28
+ releaseOp,
29
+ } from "../ops-registry.ts";
30
+ import { initRepo } from "./helpers.ts";
31
+
32
+ const dirs: string[] = [];
33
+ afterEach(async () => {
34
+ for (const dir of dirs.splice(0)) {
35
+ await rm(dir, { recursive: true, force: true });
36
+ }
37
+ });
38
+
39
+ async function repo(): Promise<string> {
40
+ const dir = await initRepo({ prefix: "ops-reg-" });
41
+ dirs.push(dir);
42
+ return dir;
43
+ }
44
+
45
+ async function opsDir(repo: string): Promise<string> {
46
+ return join(repo, ".git", "forge", "ops");
47
+ }
48
+
49
+ describe("ops-registry — claim lifecycle (RFC-1543 AC-2)", () => {
50
+ it("claimOp writes a forge/op-claim@1 record the reader reports live", async () => {
51
+ const r = await repo();
52
+ const ok = await claimOp(r, ambientIo, {
53
+ opId: "op-1",
54
+ command: "leitstand.ship",
55
+ workspaceRoot: r,
56
+ paths: ["docs/", "pnpm-lock.yaml"],
57
+ });
58
+ expect(ok).toBe(true);
59
+
60
+ const live = await liveClaims(r, ambientIo);
61
+ expect(live).toHaveLength(1);
62
+ expect(live[0]?.schema).toBe(OP_CLAIM_SCHEMA);
63
+ expect(live[0]?.pid).toBe(process.pid);
64
+ expect(live[0]?.paths).toEqual(["docs/", "pnpm-lock.yaml"]);
65
+ expect(live[0]?.bootId).toBeDefined();
66
+ });
67
+
68
+ it("releaseOp removes the record; a dead pid is swept on read", async () => {
69
+ const r = await repo();
70
+ await claimOp(r, ambientIo, {
71
+ opId: "op-2",
72
+ command: "ecosystem.commit",
73
+ workspaceRoot: r,
74
+ paths: ["docs/"],
75
+ });
76
+ await releaseOp(r, ambientIo, "op-2");
77
+ expect(await liveClaims(r, ambientIo)).toEqual([]);
78
+
79
+ // Hand-write a claim on a pid that cannot be alive.
80
+ const ops = await opsDir(r);
81
+ await mkdir(ops, { recursive: true });
82
+ await writeFile(
83
+ join(ops, "zombie.yaml"),
84
+ [
85
+ `schema: ${OP_CLAIM_SCHEMA}`,
86
+ "opId: zombie",
87
+ "command: mission.git.commit",
88
+ "pid: 999999999",
89
+ `host: ${(await import("node:os")).hostname()}`,
90
+ "startedAt: 2026-11-09T00:00:00Z",
91
+ "heartbeatAt: 2026-11-09T00:00:00Z",
92
+ `workspaceRoot: ${r}`,
93
+ "paths: [docs/]",
94
+ ].join("\n"),
95
+ );
96
+ expect(await liveClaims(r, ambientIo)).toEqual([]);
97
+ // Dead record was swept, not just filtered.
98
+ expect(await ambientIo.exists(join(ops, "zombie.yaml"))).toBe(false);
99
+ });
100
+
101
+ it("an expired heartbeat disqualifies an otherwise-live pid", async () => {
102
+ const r = await repo();
103
+ const stale: import("../ops-registry.ts").OpClaim = {
104
+ schema: OP_CLAIM_SCHEMA,
105
+ opId: "stale-beat",
106
+ command: "x",
107
+ pid: process.pid,
108
+ host: (await import("node:os")).hostname(),
109
+ startedAt: new Date(Date.now() - 600_000).toISOString(),
110
+ heartbeatAt: new Date(Date.now() - 600_000).toISOString(),
111
+ workspaceRoot: r,
112
+ paths: ["docs/"],
113
+ };
114
+ expect(isClaimLive({ ...stale })).toBe(false);
115
+ expect(isClaimLive({ ...stale, heartbeatAt: new Date().toISOString() })).toBe(true);
116
+ });
117
+
118
+ it("claimCoversPath matches exact paths and declared prefixes only", () => {
119
+ const claim: import("../ops-registry.ts").OpClaim = {
120
+ schema: OP_CLAIM_SCHEMA,
121
+ opId: "c",
122
+ command: "x",
123
+ pid: 1,
124
+ host: "h",
125
+ startedAt: "t",
126
+ heartbeatAt: "t",
127
+ workspaceRoot: "/w",
128
+ paths: ["docs/", "pnpm-lock.yaml"],
129
+ };
130
+ expect(claimCoversPath(claim, "pnpm-lock.yaml")).toBe(true);
131
+ expect(claimCoversPath(claim, "docs/rfcs/x.md")).toBe(true);
132
+ expect(claimCoversPath(claim, "docs")).toBe(false); // a FILE named docs is not under docs/
133
+ expect(claimCoversPath(claim, "documentation/x.md")).toBe(false);
134
+ expect(claimCoversPath(claim, "src/docs/x.ts")).toBe(false);
135
+ });
136
+ });
@@ -13,11 +13,11 @@ archive subdirectories back to missions/.
13
13
  </non-goals>
14
14
  </MODULE_CONTRACT>
15
15
  <CHANGE_SUMMARY>
16
- <item>RFC-1397: harden ship-in-flight guard per independent review (RFC-1397)</item>
17
16
  <item>RFC-1495: step 1 - forge state roots</item>
18
17
  <item>RFC-1505: steps 3-5 — tracked lockfile restore, no side-effect commits</item>
19
18
  <item>RFC-1505: review r1 — durable projections and lockfile restore hardening</item>
20
19
  <item>RFC-1505: review r2 — clone-only sternsystem enumeration and mission-gated lockfile net</item>
20
+ <item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
21
21
  <history>RFC-0573, RFC-0733, RFC-0801, RFC-0804, RFC-0982, RFC-1097, RFC-1138, RFC-1397, warpgogol-m000175</history>
22
22
  </CHANGE_SUMMARY>
23
23
  */
@@ -47,7 +47,7 @@ import {
47
47
  type MissionArchiveResult,
48
48
  } from "../types.ts";
49
49
  import { loadPinnedManifest, isPinned, isIntraDirMove } from "../../core/handlers/pinned-check.ts";
50
- import { restoreTrackedLockfile, execFileSyncAdapter } from "../lockfile.ts";
50
+ import { pruneMissionImportersFromLockfile, execFileSyncAdapter } from "../lockfile.ts";
51
51
  import { resolveStateRoots } from "../../flow/worktree-path.ts";
52
52
 
53
53
  const SERVICE_FOLDERS = [
@@ -668,20 +668,28 @@ export async function runMissionArchive(
668
668
  );
669
669
  }
670
670
  try {
671
- // Restore runs even when install failed — a partially-rewritten
672
- // lockfile is still mission-local churn, never tracked bytes.
673
- const restored = await restoreTrackedLockfile(workspaceRoot, {
674
- ...execFileSyncAdapter(),
675
- writeFile: async (target, content) => {
676
- await writeFileIfChanged(target, content);
671
+ // RFC-1544 AC-5: the moved missions' importer blocks are legitimate
672
+ // tracked removals — HEAD-minus-importers is staged for the archive
673
+ // bookkeeping commit; every other install churn is still discarded.
674
+ const pruned = await pruneMissionImportersFromLockfile(
675
+ workspaceRoot,
676
+ moved.map((m) => m.missionId),
677
+ {
678
+ ...execFileSyncAdapter(),
679
+ writeFile: async (target, content) => {
680
+ await writeFileIfChanged(target, content);
681
+ },
677
682
  },
678
- });
679
- if (restored) {
680
- logger.info(" Restored pnpm-lock.yaml to HEAD bytes (install churn discarded)");
681
- } else {
682
- logger.warn(
683
- " No tracked pnpm-lock.yaml at HEAD — install churn left in place; nothing to restore",
683
+ );
684
+ if (pruned.pruned.length > 0) {
685
+ logger.info(
686
+ ` Pruned importer(s) ${pruned.pruned.map((id) => `missions/${id}/workpiece`).join(", ")} from pnpm-lock.yaml` +
687
+ (pruned.staged
688
+ ? " — staged for the bookkeeping commit"
689
+ : " — staging failed; prune left in the working tree"),
684
690
  );
691
+ } else {
692
+ logger.info(" Restored pnpm-lock.yaml to HEAD bytes (install churn discarded)");
685
693
  }
686
694
  } catch (refreshErr) {
687
695
  logger.warn(