@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
@@ -0,0 +1,200 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1568 gate-run record lifecycle tests (AC-2, AC-3): attached-mode
4
+ finish writes endedAt + exit code; a `running` record whose pid is dead
5
+ classifies `lost`; retention deletes beyond 50 per command but never
6
+ touches running records; corrupt records are skipped, not thrown.</purpose>
7
+ <non-goals>
8
+ <item>No real git repo — records live under a temp common dir.</item>
9
+ </non-goals>
10
+ </MODULE_CONTRACT>
11
+ <CHANGE_SUMMARY>
12
+ <item>RFC-1568: step 2 — record lifecycle tests</item>
13
+ <item>RFC-1568: durable gate-run records, --detach mechanics, and forge CLI wiring</item>
14
+ </CHANGE_SUMMARY>
15
+ */
16
+
17
+ import { spawnSync } from "node:child_process";
18
+ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
19
+ import { hostname, tmpdir } from "node:os";
20
+ import { join } from "node:path";
21
+
22
+ import { afterEach, describe, expect, it } from "vitest";
23
+
24
+ import { resolveIo } from "../../../src/utils/io.ts";
25
+ import {
26
+ GATE_RUN_RETENTION,
27
+ classifyGateRun,
28
+ finishGateRun,
29
+ gateRunsDir,
30
+ listGateRuns,
31
+ saveGateRun,
32
+ startGateRun,
33
+ } from "../record.ts";
34
+ import { GATE_RUN_SCHEMA, type GateRunRecord } from "../types.ts";
35
+
36
+ const dirs: string[] = [];
37
+ afterEach(async () => {
38
+ for (const dir of dirs.splice(0)) await rm(dir, { recursive: true, force: true });
39
+ }, 20_000);
40
+
41
+ async function tempCommon(): Promise<string> {
42
+ const dir = await mkdtemp(join(tmpdir(), "gate-run-"));
43
+ dirs.push(dir);
44
+ return dir;
45
+ }
46
+
47
+ const deadPid = (): number => {
48
+ const pid = spawnSync(process.execPath, ["-e", ""]).pid;
49
+ if (pid === undefined) throw new Error("spawn failed — cannot produce a dead pid");
50
+ return pid;
51
+ };
52
+
53
+ function fixtureRecord(over: Partial<GateRunRecord> = {}): GateRunRecord {
54
+ return {
55
+ schema: GATE_RUN_SCHEMA,
56
+ runId: over.runId ?? `gr-test-${Math.random().toString(36).slice(2, 8)}`,
57
+ command: "flow.integrate",
58
+ argv: [],
59
+ cwd: ".",
60
+ detached: false,
61
+ pid: process.pid,
62
+ host: hostname(),
63
+ startedAt: new Date().toISOString(),
64
+ status: "running",
65
+ ...over,
66
+ };
67
+ }
68
+
69
+ const io = resolveIo(undefined);
70
+
71
+ describe("startGateRun / finishGateRun", () => {
72
+ it("AC-2: finish writes endedAt, exit code, and succeeded status", async () => {
73
+ const common = await tempCommon();
74
+ const record = await startGateRun({
75
+ commonGitDir: common,
76
+ command: "flow.integrate",
77
+ argv: ["--dry-run"],
78
+ cwd: ".",
79
+ detached: false,
80
+ io,
81
+ });
82
+ expect(record.status).toBe("running");
83
+ expect(record.pid).toBe(process.pid);
84
+
85
+ await finishGateRun(common, record, { exitCode: 0, summary: "[flow.integrate] done" }, io);
86
+
87
+ const raw = JSON.parse(
88
+ await readFile(join(gateRunsDir(common), `${record.runId}.json`), "utf8"),
89
+ ) as GateRunRecord;
90
+ expect(raw.status).toBe("succeeded");
91
+ expect(raw.exitCode).toBe(0);
92
+ expect(raw.endedAt).toBeDefined();
93
+ expect(raw.summary).toBe("[flow.integrate] done");
94
+ });
95
+
96
+ it("AC-2: a non-zero exit records failed", async () => {
97
+ const common = await tempCommon();
98
+ const record = await startGateRun({
99
+ commonGitDir: common,
100
+ command: "ecosystem.commit",
101
+ argv: [],
102
+ cwd: ".",
103
+ detached: false,
104
+ io,
105
+ });
106
+ await finishGateRun(common, record, { exitCode: 1 }, io);
107
+ const [read] = await listGateRuns(common, io);
108
+ expect(read?.status).toBe("failed");
109
+ expect(read?.exitCode).toBe(1);
110
+ });
111
+ });
112
+
113
+ describe("classifyGateRun", () => {
114
+ it("AC-3: running record with a dead pid classifies lost", () => {
115
+ const record = fixtureRecord({ pid: deadPid(), host: hostname() });
116
+ expect(classifyGateRun(record)).toBe("lost");
117
+ });
118
+
119
+ it("running record with a live pid stays running", () => {
120
+ const record = fixtureRecord({ pid: process.pid, host: hostname() });
121
+ expect(classifyGateRun(record)).toBe("running");
122
+ });
123
+
124
+ it("terminal statuses pass through unchanged", () => {
125
+ expect(classifyGateRun(fixtureRecord({ status: "succeeded" }))).toBe("succeeded");
126
+ expect(classifyGateRun(fixtureRecord({ status: "failed" }))).toBe("failed");
127
+ });
128
+ });
129
+
130
+ describe("listGateRuns", () => {
131
+ it("skips corrupt records and returns newest first", async () => {
132
+ const common = await tempCommon();
133
+ const older = fixtureRecord({ runId: "gr-older", startedAt: "2026-01-01T00:00:00.000Z" });
134
+ const newer = fixtureRecord({ runId: "gr-newer", startedAt: "2026-01-02T00:00:00.000Z" });
135
+ await saveGateRun(common, older, io);
136
+ await saveGateRun(common, newer, io);
137
+ await writeFile(join(gateRunsDir(common), "gr-corrupt.json"), "{not json");
138
+
139
+ const runs = await listGateRuns(common, io);
140
+ expect(runs.map((r) => r.runId)).toEqual(["gr-newer", "gr-older"]);
141
+ });
142
+
143
+ it("filters by command and limit", async () => {
144
+ const common = await tempCommon();
145
+ await saveGateRun(common, fixtureRecord({ runId: "gr-a", command: "flow.integrate" }), io);
146
+ await saveGateRun(common, fixtureRecord({ runId: "gr-b", command: "ecosystem.commit" }), io);
147
+
148
+ const filtered = await listGateRuns(common, io, { command: "flow.integrate" });
149
+ expect(filtered).toHaveLength(1);
150
+ expect(filtered[0]?.runId).toBe("gr-a");
151
+
152
+ const limited = await listGateRuns(common, io, { limit: 1 });
153
+ expect(limited).toHaveLength(1);
154
+ });
155
+ });
156
+
157
+ describe("retention", () => {
158
+ it("deletes finished records beyond the per-command cap but never running ones", async () => {
159
+ const common = await tempCommon();
160
+ const dir = gateRunsDir(common);
161
+ // 51 finished + 1 running → after the next start, finished are trimmed
162
+ // to 50 and the running record survives.
163
+ for (let i = 0; i < GATE_RUN_RETENTION + 1; i++) {
164
+ await saveGateRun(
165
+ common,
166
+ fixtureRecord({
167
+ runId: `gr-old-${String(i).padStart(3, "0")}`,
168
+ status: "succeeded",
169
+ startedAt: new Date(2026, 0, i + 1).toISOString(),
170
+ }),
171
+ io,
172
+ );
173
+ }
174
+ await saveGateRun(
175
+ common,
176
+ fixtureRecord({
177
+ runId: "gr-alive",
178
+ status: "running",
179
+ startedAt: "2026-06-01T00:00:00.000Z",
180
+ }),
181
+ io,
182
+ );
183
+
184
+ await startGateRun({
185
+ commonGitDir: common,
186
+ command: "flow.integrate",
187
+ argv: [],
188
+ cwd: ".",
189
+ detached: false,
190
+ io,
191
+ });
192
+
193
+ const runs = await listGateRuns(common, io, { command: "flow.integrate" });
194
+ expect(runs.some((r) => r.runId === "gr-alive")).toBe(true);
195
+ expect(runs.filter((r) => r.status === "succeeded")).toHaveLength(GATE_RUN_RETENTION);
196
+ // oldest finished record was pruned, its file gone from disk.
197
+ const files = await readFile(join(dir, "gr-alive.json"), "utf8").then(() => true);
198
+ expect(files).toBe(true);
199
+ });
200
+ });
@@ -0,0 +1,73 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1568 — durable gate-run record contract: one JSON record per
4
+ detachable-command execution under `<git common dir>/forge/gate-runs/`,
5
+ carrying lifecycle (running → succeeded|failed, `lost` derived), pid liveness
6
+ inputs, and pointers at the run's log/gate-report artifacts.</purpose>
7
+ <non-goals>
8
+ <item>No liveness rules of its own — classify delegates to os/core/lock-holder.</item>
9
+ <item>No remote/queued execution — records are written by the runner itself.</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1568: step 1 — gate-run record contract + refusal ids</item>
14
+ <item>RFC-1568: durable gate-run records, --detach mechanics, and forge CLI wiring</item>
15
+ </CHANGE_SUMMARY>
16
+ */
17
+
18
+ export type GateRunStatus = "running" | "succeeded" | "failed" | "lost";
19
+
20
+ export const GATE_RUN_SCHEMA = "forge:gate-run/v1" as const;
21
+
22
+ export interface GateRunRecord {
23
+ schema: typeof GATE_RUN_SCHEMA;
24
+ /** gr-<UTC yyyymmddThhmmssZ>-<command>-<4 hex> */
25
+ runId: string;
26
+ command: string;
27
+ /** argv as invoked, without --detach. */
28
+ argv: string[];
29
+ /** repo-relative to the common-dir parent when possible. */
30
+ cwd: string;
31
+ detached: boolean;
32
+ pid: number;
33
+ host: string;
34
+ bootId?: string;
35
+ startedAt: string;
36
+ endedAt?: string;
37
+ exitCode?: number;
38
+ /** "running" on disk until the end write; "lost" is derived, never written. */
39
+ status: GateRunStatus;
40
+ /** the command result summary line. */
41
+ summary?: string;
42
+ /** detached runs: <common>/forge/gate-runs/<runId>.log */
43
+ logPath?: string;
44
+ /** RFC-1532 gate report, when the command produced one. */
45
+ reportPath?: string;
46
+ /** mission.validate */
47
+ missionId?: string;
48
+ }
49
+
50
+ /** Minimal spawn surface detach.ts needs — injectable for tests. */
51
+ export interface SpawnLikeChild {
52
+ pid?: number;
53
+ unref(): void;
54
+ }
55
+
56
+ export interface SpawnLike {
57
+ (
58
+ file: string,
59
+ args: string[],
60
+ opts: {
61
+ detached?: boolean;
62
+ stdio?: unknown[];
63
+ env?: Record<string, string | undefined>;
64
+ },
65
+ ): SpawnLikeChild;
66
+ }
67
+
68
+ /** GATE-RUN-01..03 — command-level refusal ids declared on gate.run.status. */
69
+ export const GATE_RUN_RULES = [
70
+ { id: "GATE-RUN-01", severity: "error" as const },
71
+ { id: "GATE-RUN-02", severity: "error" as const },
72
+ { id: "GATE-RUN-03", severity: "error" as const },
73
+ ];
@@ -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(
@@ -0,0 +1,119 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Text-splice primitives for a single importer subtree inside
4
+ pnpm-lock.yaml (RFC-1544). A mission workpiece registers as the importer key
5
+ `missions/<id>/workpiece:` at the fixed two-space indent under `importers:`;
6
+ both consumers — flow.integrate's foreign-open-mission restore and
7
+ mission.archive's bookkeeping prune — must move exactly that key's block and
8
+ nothing else, so a whole-file checkout or a YAML round-trip (which rewrites
9
+ unrelated formatting) is never the mechanism.</purpose>
10
+ <non-goals>
11
+ <item>No YAML semantics — block boundaries are indent arithmetic on the pnpm-lock layout, not a parse.</item>
12
+ <item>No git/file I/O — pure string transforms; callers own reads and writes.</item>
13
+ </non-goals>
14
+ </MODULE_CONTRACT>
15
+ <CHANGE_SUMMARY>
16
+ <item>RFC-1544: importer-block extract/insert/remove text splices shared by flow.integrate restore and mission.archive prune</item>
17
+ <item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
18
+ </CHANGE_SUMMARY>
19
+ */
20
+
21
+ const IMPORTER_INDENT = 2;
22
+
23
+ function indentOf(line: string): number {
24
+ return line.length - line.trimStart().length;
25
+ }
26
+
27
+ /** Locate ` <key>:` at the importer indent — exact key, no prefix bleed. */
28
+ function importerKeyIndex(lines: string[], key: string): number {
29
+ const wanted = `${" ".repeat(IMPORTER_INDENT)}${key}:`;
30
+ return lines.findIndex((l) => l.trimEnd() === wanted);
31
+ }
32
+
33
+ /**
34
+ * The importer block lines for `key` inside lockfile `text`: the key line
35
+ * plus every deeper-indented member, trailing blanks excluded. Null when the
36
+ * key is absent.
37
+ */
38
+ export function extractImporterBlock(text: string, key: string): string[] | null {
39
+ const lines = text.split("\n");
40
+ const start = importerKeyIndex(lines, key);
41
+ if (start === -1) return null;
42
+ let end = start + 1;
43
+ while (end < lines.length) {
44
+ const l = lines[end];
45
+ if (l.trim().length === 0) {
46
+ end += 1;
47
+ continue;
48
+ }
49
+ if (indentOf(l) <= IMPORTER_INDENT) break;
50
+ end += 1;
51
+ }
52
+ while (end > start + 1 && lines[end - 1].trim().length === 0) end -= 1;
53
+ return lines.slice(start, end);
54
+ }
55
+
56
+ /**
57
+ * `text` without `key`'s importer block — the block plus its separating
58
+ * blank line(s), so removal leaves the surrounding layout intact. Returns
59
+ * the input unchanged when the key is absent.
60
+ */
61
+ export function removeImporterBlock(text: string, key: string): string {
62
+ const lines = text.split("\n");
63
+ const start = importerKeyIndex(lines, key);
64
+ if (start === -1) return text;
65
+ let end = start + 1;
66
+ while (end < lines.length) {
67
+ const l = lines[end];
68
+ if (l.trim().length === 0) {
69
+ end += 1;
70
+ continue;
71
+ }
72
+ if (indentOf(l) <= IMPORTER_INDENT) break;
73
+ end += 1;
74
+ }
75
+ // Also absorb the blank separator BEFORE the block when one exists —
76
+ // pnpm separates importer stanzas with a single blank line.
77
+ let s = start;
78
+ if (s > 0 && lines[s - 1].trim().length === 0) s -= 1;
79
+ const out = [...lines.slice(0, s), ...lines.slice(end)];
80
+ // Collapse a doubled blank left at the seam when both sides kept one.
81
+ return out.join("\n").replace(/\n{3,}/g, "\n\n");
82
+ }
83
+
84
+ /**
85
+ * `text` with `block` inserted under `importers:` at pnpm's alphabetical
86
+ * position — before the first importer key sorting after `key`, else at the
87
+ * end of the importers section. Null when no `importers:` section exists.
88
+ */
89
+ export function insertImporterBlock(text: string, key: string, block: string[]): string | null {
90
+ const lines = text.split("\n");
91
+ const importersIdx = lines.findIndex((l) => l.trimEnd() === "importers:");
92
+ if (importersIdx === -1) return null;
93
+ // Section end: first non-blank line with indent < 2 (or EOF).
94
+ let sectionEnd = lines.length;
95
+ for (let i = importersIdx + 1; i < lines.length; i += 1) {
96
+ const l = lines[i];
97
+ if (l.trim().length === 0) continue;
98
+ if (indentOf(l) < IMPORTER_INDENT) {
99
+ sectionEnd = i;
100
+ break;
101
+ }
102
+ }
103
+ // First importer key sorting after ours — mid-section insert.
104
+ for (let i = importersIdx + 1; i < sectionEnd; i += 1) {
105
+ const l = lines[i];
106
+ if (l.trim().length === 0 || indentOf(l) !== IMPORTER_INDENT) continue;
107
+ const other = l.trim().replace(/:$/, "");
108
+ if (other > key) {
109
+ return [...lines.slice(0, i), ...block, "", ...lines.slice(i)].join("\n");
110
+ }
111
+ }
112
+ // End-of-section insert: splice before the trailing blank run when one
113
+ // exists (it already separates the last block from the next section).
114
+ let at = sectionEnd;
115
+ while (at > importersIdx + 1 && lines[at - 1].trim().length === 0) at -= 1;
116
+ const hadTrailingBlanks = at < sectionEnd;
117
+ const payload = ["", ...block, ...(hadTrailingBlanks ? [] : [""])];
118
+ return [...lines.slice(0, at), ...payload, ...lines.slice(at)].join("\n");
119
+ }
@@ -16,12 +16,14 @@ restores the file committed at HEAD so the worktree returns clean.
16
16
  <item>RFC-1505: steps 3-5 — tracked lockfile restore, no side-effect commits</item>
17
17
  <item>RFC-1505: review r1 — durable projections and lockfile restore hardening</item>
18
18
  <item>RFC-1505: review r2 — clone-only sternsystem enumeration and mission-gated lockfile net</item>
19
+ <item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
19
20
  </CHANGE_SUMMARY>
20
21
  */
21
22
 
22
23
  import path from "node:path";
23
24
  import { execFileSync } from "../../src/utils/sync-fs.ts";
24
25
  import type { ExecOptions, ExecResult, WorkspaceIO } from "../../src/types.ts";
26
+ import { extractImporterBlock, removeImporterBlock } from "./importer-block.ts";
25
27
 
26
28
  const LOCKFILE_NAME = "pnpm-lock.yaml";
27
29
 
@@ -82,3 +84,42 @@ export function execFileSyncAdapter(): Pick<WorkspaceIO, "exec"> {
82
84
  },
83
85
  };
84
86
  }
87
+
88
+ /**
89
+ * RFC-1544 AC-5: drop the listed missions' `missions/<id>/workpiece`
90
+ * importer subtrees from the tracked `pnpm-lock.yaml` and stage the result
91
+ * for the archive bookkeeping commit. The written bytes are HEAD-minus-
92
+ * importers — the post-archive `pnpm install` may churn unrelated lockfile
93
+ * state, and only the importer removal is legitimate tracked change, so
94
+ * everything else is discarded exactly like `restoreTrackedLockfile` did.
95
+ *
96
+ * Returns `pruned` = mission ids whose importer block was actually removed;
97
+ * `staged` = whether `pnpm-lock.yaml` reached the index. When no listed
98
+ * importer exists at HEAD the tracked file is restored instead (the old
99
+ * churn-discard behavior) and `staged` stays false.
100
+ */
101
+ export async function pruneMissionImportersFromLockfile(
102
+ root: string,
103
+ missionIds: string[],
104
+ io: Pick<WorkspaceIO, "exec" | "writeFile">,
105
+ ): Promise<{ pruned: string[]; staged: boolean }> {
106
+ const head = await io.exec("git", ["show", `HEAD:${LOCKFILE_NAME}`], { cwd: root });
107
+ if (head.exitCode !== 0) return { pruned: [], staged: false };
108
+ let next = head.stdout;
109
+ const pruned: string[] = [];
110
+ for (const missionId of missionIds) {
111
+ const key = `missions/${missionId}/workpiece`;
112
+ if (extractImporterBlock(next, key) === null) continue;
113
+ next = removeImporterBlock(next, key);
114
+ pruned.push(missionId);
115
+ }
116
+ const target = path.join(root, LOCKFILE_NAME);
117
+ if (pruned.length === 0) {
118
+ // Nothing legitimately prunes — keep the discard-churn restore.
119
+ await io.writeFile(target, head.stdout);
120
+ return { pruned, staged: false };
121
+ }
122
+ await io.writeFile(target, next);
123
+ const add = await io.exec("git", ["add", LOCKFILE_NAME], { cwd: root });
124
+ return { pruned, staged: add.exitCode === 0 };
125
+ }
@@ -0,0 +1,61 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1569 — the single evidence-annotation grammar shared by
4
+ rfc.implement.stamp (resolution) and rfc.validate V-53 (shape lint). Pure —
5
+ no IO; the stamp decides resolution, V-53 only asks "is this a form the
6
+ stamp can resolve".</purpose>
7
+ <non-goals>
8
+ <item>No file existence or probe-envelope checks — resolution stays the
9
+ stamp's job (RFC-1322).</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1569: step 1 — extract the annotation grammar into a pure parser</item>
14
+ <item>RFC-1569: lint rfc evidence annotations and transient probe targets</item>
15
+ </CHANGE_SUMMARY>
16
+ */
17
+
18
+ export type EvidenceAnnotation =
19
+ | { kind: "probe"; criterion: string }
20
+ | { kind: "test" | "file"; path: string; lines?: string }
21
+ | { kind: "path-line"; path: string; lines: string }
22
+ | { kind: "invalid"; raw: string; reason: string };
23
+
24
+ const PROBE_RE = /^probe:\s*([A-Za-z][\w.:-]*)$/;
25
+ const TEST_FILE_RE = /^(test|file):\s*(\S+?)(?::(\d+(?:-\d+)?))?$/;
26
+ const PATH_LINE_RE = /^([^\s:]+):(\d+(?:-\d+)?)$/;
27
+
28
+ export const EVIDENCE_FORMS = "probe:AC-N | test:<path> | file:<path> | <path>:<line>";
29
+
30
+ /**
31
+ * Parse the `(evidence: …)` payload. Whitespace after the prefix colon is
32
+ * tolerated; paths carry no whitespace. The probe arm accepts the full
33
+ * criterion-id alphabet (`AC-N`, `design:<heading>`) — whether the named
34
+ * criterion exists and binds a passing probe is the caller's arbitration,
35
+ * not the regex's.
36
+ */
37
+ export function parseEvidenceAnnotation(raw: string): EvidenceAnnotation {
38
+ const annotation = raw.trim();
39
+ if (annotation === "") return { kind: "invalid", raw, reason: "empty annotation" };
40
+
41
+ const probe = PROBE_RE.exec(annotation);
42
+ if (probe) return { kind: "probe", criterion: probe[1]! };
43
+
44
+ const testFile = TEST_FILE_RE.exec(annotation);
45
+ if (testFile) {
46
+ return {
47
+ kind: testFile[1] === "test" ? "test" : "file",
48
+ path: testFile[2]!,
49
+ ...(testFile[3] !== undefined ? { lines: testFile[3] } : {}),
50
+ };
51
+ }
52
+
53
+ const pathLine = PATH_LINE_RE.exec(annotation);
54
+ if (pathLine) return { kind: "path-line", path: pathLine[1]!, lines: pathLine[2]! };
55
+
56
+ return {
57
+ kind: "invalid",
58
+ raw,
59
+ reason: `not a resolvable form (expected ${EVIDENCE_FORMS})`,
60
+ };
61
+ }
@@ -0,0 +1,70 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1569 — V-50 containment compares each fixed-input literal
4
+ against the regex-UNESCAPED probe pattern (escaped metachar literals keep
5
+ coverage).</purpose>
6
+ <non-goals>
7
+ <item>Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only.</item>
8
+ </non-goals>
9
+ </MODULE_CONTRACT>
10
+ <CHANGE_SUMMARY>
11
+ <item>RFC-1569: V-50 unescape-before-containment tests (AC-9)</item>
12
+ <item>RFC-1569: lint rfc evidence annotations and transient probe targets</item>
13
+ </CHANGE_SUMMARY>
14
+ */
15
+
16
+ import { test, expect, describe } from "vitest";
17
+ import { evaluateFixedInputs } from "./fixed-inputs.ts";
18
+
19
+ const body = (value: string): string =>
20
+ `## Fixed inputs\n\n| ID | Value | Source | Checked by |\n| --- | --- | --- | --- |\n| FI-1 | ${value} | decision | AC-1 |\n`;
21
+
22
+ describe("V-50: regex-unescaped containment (RFC-1569)", () => {
23
+ test("AC-9: escaped \\$\\{WORKSPACE_ROOT\\} pattern covers the literal", () => {
24
+ const diags = evaluateFixedInputs(
25
+ body("`${WORKSPACE_ROOT}`"),
26
+ ["AC-1"],
27
+ [
28
+ {
29
+ probe: "file-contains",
30
+ criterion: "AC-1",
31
+ path: "x",
32
+ pattern: "\\$\\{WORKSPACE_ROOT\\}",
33
+ } as never,
34
+ ],
35
+ );
36
+ expect(diags.filter((d) => d.message.includes("not contained"))).toEqual([]);
37
+ });
38
+
39
+ test("unescaped metachars in a literal still report uncovered", () => {
40
+ const diags = evaluateFixedInputs(
41
+ body("`${WORKSPACE_ROOT}`"),
42
+ ["AC-1"],
43
+ [
44
+ {
45
+ probe: "file-contains",
46
+ criterion: "AC-1",
47
+ path: "x",
48
+ pattern: "literal plain text",
49
+ } as never,
50
+ ],
51
+ );
52
+ expect(diags.some((d) => d.message.includes("not contained"))).toBe(true);
53
+ });
54
+
55
+ test("dotted literal covered by escaped a\\.b pattern", () => {
56
+ const diags = evaluateFixedInputs(
57
+ body("`a.b`"),
58
+ ["AC-1"],
59
+ [
60
+ {
61
+ probe: "file-contains",
62
+ criterion: "AC-1",
63
+ path: "x",
64
+ pattern: "a\\.b",
65
+ } as never,
66
+ ],
67
+ );
68
+ expect(diags.filter((d) => d.message.includes("not contained"))).toEqual([]);
69
+ });
70
+ });
@@ -17,6 +17,7 @@ warning nudge. All functions are pure — no I/O.
17
17
  <CHANGE_SUMMARY>
18
18
  <item>RFC-1455: fixed-inputs section parser + V-50/V-51 evaluator for rfc.validate.</item>
19
19
  <item>RFC-1455: fixed inputs bound to outcome probes — V-50/V-51 + skills</item>
20
+ <item>RFC-1569: lint rfc evidence annotations and transient probe targets</item>
20
21
  </CHANGE_SUMMARY>
21
22
  */
22
23
 
@@ -235,8 +236,17 @@ export function evaluateFixedInputs(
235
236
  }
236
237
 
237
238
  const literals = fixedInputLiterals(row.value);
239
+ // RFC-1569: compare against the regex-UNESCAPED pattern too — a literal
240
+ // carrying metacharacters (${WORKSPACE_ROOT}) cannot be both escaped in
241
+ // the pattern and contained verbatim; `\d`/`\w` shorthand keeps its
242
+ // backslash (unescaping it would fake coverage for single-char literals).
243
+ const unescapePattern = (field: string): string =>
244
+ field.replace(/\\([.*+?^${}()|[\]\\])/g, "$1");
238
245
  const uncovered = literals.filter(
239
- (literal) => !outcomeFields.some((field) => field.includes(literal)),
246
+ (literal) =>
247
+ !outcomeFields.some(
248
+ (field) => field.includes(literal) || unescapePattern(field).includes(literal),
249
+ ),
240
250
  );
241
251
  if (uncovered.length > 0) {
242
252
  diagnostics.push({