@warpgogol/forge 9.7.0 → 9.7.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 (182) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/os/adr/handlers/archive.d.ts.map +1 -1
  3. package/dist/os/adr/handlers/archive.js +3 -7
  4. package/dist/os/adr/handlers/archive.js.map +1 -1
  5. package/dist/os/adr/handlers/list-create.d.ts.map +1 -1
  6. package/dist/os/adr/handlers/list-create.js +8 -6
  7. package/dist/os/adr/handlers/list-create.js.map +1 -1
  8. package/dist/os/audit/handlers/archive.d.ts.map +1 -1
  9. package/dist/os/audit/handlers/archive.js +3 -7
  10. package/dist/os/audit/handlers/archive.js.map +1 -1
  11. package/dist/os/core/archive-regen.d.ts +1 -0
  12. package/dist/os/core/archive-regen.d.ts.map +1 -1
  13. package/dist/os/core/archive-regen.js +31 -6
  14. package/dist/os/core/archive-regen.js.map +1 -1
  15. package/dist/os/core/core.module.d.ts.map +1 -1
  16. package/dist/os/core/core.module.js +5 -0
  17. package/dist/os/core/core.module.js.map +1 -1
  18. package/dist/os/core/handlers/pinned-check.d.ts +13 -0
  19. package/dist/os/core/handlers/pinned-check.d.ts.map +1 -1
  20. package/dist/os/core/handlers/pinned-check.js +25 -0
  21. package/dist/os/core/handlers/pinned-check.js.map +1 -1
  22. package/dist/os/core/handlers/pinned-types.d.ts +7 -0
  23. package/dist/os/core/handlers/pinned-types.d.ts.map +1 -1
  24. package/dist/os/core/handlers/pinned-validate.d.ts.map +1 -1
  25. package/dist/os/core/handlers/pinned-validate.js +24 -1
  26. package/dist/os/core/handlers/pinned-validate.js.map +1 -1
  27. package/dist/os/flow/digest.d.ts +73 -1
  28. package/dist/os/flow/digest.d.ts.map +1 -1
  29. package/dist/os/flow/digest.js +344 -92
  30. package/dist/os/flow/digest.js.map +1 -1
  31. package/dist/os/flow/evidence-lock.d.ts +36 -0
  32. package/dist/os/flow/evidence-lock.d.ts.map +1 -0
  33. package/dist/os/flow/evidence-lock.js +156 -0
  34. package/dist/os/flow/evidence-lock.js.map +1 -0
  35. package/dist/os/flow/flow.module.d.ts.map +1 -1
  36. package/dist/os/flow/flow.module.js +36 -14
  37. package/dist/os/flow/flow.module.js.map +1 -1
  38. package/dist/os/flow/git.d.ts +50 -3
  39. package/dist/os/flow/git.d.ts.map +1 -1
  40. package/dist/os/flow/git.js +144 -12
  41. package/dist/os/flow/git.js.map +1 -1
  42. package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
  43. package/dist/os/flow/handlers/flow-digest.js +3 -5
  44. package/dist/os/flow/handlers/flow-digest.js.map +1 -1
  45. package/dist/os/flow/handlers/flow-push.d.ts +81 -0
  46. package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
  47. package/dist/os/flow/handlers/flow-push.js +642 -138
  48. package/dist/os/flow/handlers/flow-push.js.map +1 -1
  49. package/dist/os/flow/locks.d.ts +8 -0
  50. package/dist/os/flow/locks.d.ts.map +1 -1
  51. package/dist/os/flow/locks.js +6 -3
  52. package/dist/os/flow/locks.js.map +1 -1
  53. package/dist/os/flow/preflight.d.ts.map +1 -1
  54. package/dist/os/flow/preflight.js +4 -2
  55. package/dist/os/flow/preflight.js.map +1 -1
  56. package/dist/os/flow/registry.d.ts +9 -5
  57. package/dist/os/flow/registry.d.ts.map +1 -1
  58. package/dist/os/flow/registry.js +2 -2
  59. package/dist/os/flow/registry.js.map +1 -1
  60. package/dist/os/friction/friction.module.d.ts.map +1 -1
  61. package/dist/os/friction/friction.module.js +30 -5
  62. package/dist/os/friction/friction.module.js.map +1 -1
  63. package/dist/os/friction/handlers/friction-add.d.ts.map +1 -1
  64. package/dist/os/friction/handlers/friction-add.js +10 -17
  65. package/dist/os/friction/handlers/friction-add.js.map +1 -1
  66. package/dist/os/friction/handlers/friction-migrate.d.ts.map +1 -1
  67. package/dist/os/friction/handlers/friction-migrate.js +188 -2
  68. package/dist/os/friction/handlers/friction-migrate.js.map +1 -1
  69. package/dist/os/friction/store.d.ts +4 -0
  70. package/dist/os/friction/store.d.ts.map +1 -1
  71. package/dist/os/friction/store.js +20 -0
  72. package/dist/os/friction/store.js.map +1 -1
  73. package/dist/os/friction/types.d.ts +12 -0
  74. package/dist/os/friction/types.d.ts.map +1 -1
  75. package/dist/os/friction/types.js +8 -0
  76. package/dist/os/friction/types.js.map +1 -1
  77. package/dist/os/gate/handlers/gate-probe-catalog.d.ts.map +1 -1
  78. package/dist/os/gate/handlers/gate-probe-catalog.js +38 -5
  79. package/dist/os/gate/handlers/gate-probe-catalog.js.map +1 -1
  80. package/dist/os/mission/handlers/archive.d.ts.map +1 -1
  81. package/dist/os/mission/handlers/archive.js +3 -7
  82. package/dist/os/mission/handlers/archive.js.map +1 -1
  83. package/dist/os/plan/handlers/archive.d.ts.map +1 -1
  84. package/dist/os/plan/handlers/archive.js +3 -7
  85. package/dist/os/plan/handlers/archive.js.map +1 -1
  86. package/dist/os/rfc/handlers/archive.d.ts.map +1 -1
  87. package/dist/os/rfc/handlers/archive.js +3 -7
  88. package/dist/os/rfc/handlers/archive.js.map +1 -1
  89. package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
  90. package/dist/os/rfc/handlers/list-create.js +15 -7
  91. package/dist/os/rfc/handlers/list-create.js.map +1 -1
  92. package/dist/os/session/handlers/archive.d.ts.map +1 -1
  93. package/dist/os/session/handlers/archive.js +3 -7
  94. package/dist/os/session/handlers/archive.js.map +1 -1
  95. package/dist/os/system/handlers/system-product-register.d.ts +24 -0
  96. package/dist/os/system/handlers/system-product-register.d.ts.map +1 -0
  97. package/dist/os/system/handlers/system-product-register.js +322 -0
  98. package/dist/os/system/handlers/system-product-register.js.map +1 -0
  99. package/dist/os/system/handlers/system-products-status.d.ts +23 -0
  100. package/dist/os/system/handlers/system-products-status.d.ts.map +1 -0
  101. package/dist/os/system/handlers/system-products-status.js +235 -0
  102. package/dist/os/system/handlers/system-products-status.js.map +1 -0
  103. package/dist/os/system/schemas.d.ts +13 -0
  104. package/dist/os/system/schemas.d.ts.map +1 -1
  105. package/dist/os/system/schemas.js +15 -0
  106. package/dist/os/system/schemas.js.map +1 -1
  107. package/dist/os/system/system.module.d.ts.map +1 -1
  108. package/dist/os/system/system.module.js +113 -3
  109. package/dist/os/system/system.module.js.map +1 -1
  110. package/dist/src/config/forge-config.d.ts +2 -0
  111. package/dist/src/config/forge-config.d.ts.map +1 -1
  112. package/dist/src/config/forge-config.js +11 -10
  113. package/dist/src/config/forge-config.js.map +1 -1
  114. package/dist/src/onboarding/create.d.ts.map +1 -1
  115. package/dist/src/onboarding/create.js +27 -2
  116. package/dist/src/onboarding/create.js.map +1 -1
  117. package/dist/src/profiles/stack-profile.js +2 -2
  118. package/dist/src/types.js +2 -2
  119. package/dist/src/utils/verifier-git.d.ts +27 -1
  120. package/dist/src/utils/verifier-git.d.ts.map +1 -1
  121. package/dist/src/utils/verifier-git.js +36 -6
  122. package/dist/src/utils/verifier-git.js.map +1 -1
  123. package/docs/reference/system-hub.md +104 -0
  124. package/os/adr/handlers/archive.ts +3 -11
  125. package/os/adr/handlers/list-create.test.ts +174 -0
  126. package/os/adr/handlers/list-create.ts +16 -8
  127. package/os/audit/handlers/archive.ts +3 -11
  128. package/os/core/archive-regen.ts +33 -7
  129. package/os/core/core.module.ts +7 -0
  130. package/os/core/docs-archive.test.ts +25 -0
  131. package/os/core/handlers/pinned-check.ts +30 -0
  132. package/os/core/handlers/pinned-types.ts +7 -0
  133. package/os/core/handlers/pinned-validate.ts +28 -3
  134. package/os/flow/digest.ts +436 -95
  135. package/os/flow/evidence-lock.ts +184 -0
  136. package/os/flow/flow.module.ts +37 -14
  137. package/os/flow/git.ts +206 -11
  138. package/os/flow/handlers/flow-digest.ts +12 -8
  139. package/os/flow/handlers/flow-push.ts +725 -137
  140. package/os/flow/locks.ts +24 -7
  141. package/os/flow/preflight.ts +4 -2
  142. package/os/flow/registry.ts +7 -3
  143. package/os/flow/tests/digest-id-inputs.test.ts +106 -0
  144. package/os/flow/tests/digest-persist.test.ts +243 -0
  145. package/os/flow/tests/evidence-preflight-surface-skip.test.ts +218 -0
  146. package/os/flow/tests/flow-push-attest.test.ts +137 -0
  147. package/os/flow/tests/flow-push-review-baseline.test.ts +339 -0
  148. package/os/flow/tests/flow-push-verifier-batch.test.ts +134 -0
  149. package/os/friction/friction-add.test.ts +42 -0
  150. package/os/friction/friction-migrate.test.ts +67 -2
  151. package/os/friction/friction.module.ts +33 -5
  152. package/os/friction/handlers/friction-add.ts +10 -15
  153. package/os/friction/handlers/friction-migrate.ts +220 -1
  154. package/os/friction/store.ts +19 -0
  155. package/os/friction/types.ts +8 -0
  156. package/os/gate/handlers/gate-probe-catalog.ts +39 -7
  157. package/os/gate/handlers/gate-probe-ratchet.test.ts +57 -22
  158. package/os/mission/handlers/archive.ts +3 -11
  159. package/os/plan/handlers/archive.ts +3 -11
  160. package/os/rfc/handlers/archive.ts +3 -11
  161. package/os/rfc/handlers/list-create.ts +22 -17
  162. package/os/session/handlers/archive.ts +3 -11
  163. package/os/system/handlers/system-product-register.ts +492 -0
  164. package/os/system/handlers/system-products-status.ts +395 -0
  165. package/os/system/schemas.ts +17 -0
  166. package/os/system/system.module.ts +117 -3
  167. package/os/system/tests/system-product-register.test.ts +304 -0
  168. package/os/system/tests/system-products-status.test.ts +154 -0
  169. package/package.json +1 -1
  170. package/profiles/root-agents-system.md +82 -0
  171. package/profiles/system.yaml +1 -0
  172. package/src/config/forge-config.ts +16 -11
  173. package/src/onboarding/create-superfolder-guard.test.ts +73 -0
  174. package/src/onboarding/create.ts +28 -2
  175. package/src/profiles/stack-profile.ts +2 -2
  176. package/src/tests/evidence-consult-serialization.test.ts +202 -0
  177. package/src/tests/pinned-validate.test.ts +194 -0
  178. package/src/tests/profile-flow-hooks.test.ts +1 -0
  179. package/src/tests/profile-schema.test.ts +1 -0
  180. package/src/tests/stack-profile.test.ts +1 -0
  181. package/src/types.ts +2 -2
  182. package/src/utils/verifier-git.ts +53 -5
@@ -0,0 +1,73 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Unit tests for the forge.create superfolder guard (RFC-1639 AC-7, CREATE-SUPERFOLDER-01) — a directory of forge-governed children refuses scaffolding in favour of the system-hub model.</purpose>
4
+ <non-goals>
5
+ <item>Not a contract source of truth — the implementation under test owns the behaviour.</item>
6
+ </non-goals>
7
+ </MODULE_CONTRACT>
8
+ <CHANGE_SUMMARY>
9
+ <item>RFC-1639: step 5-6 — acceptance tests, system-hub reference, regenerated manifests</item>
10
+ </CHANGE_SUMMARY>
11
+ */
12
+
13
+ import { test, expect, describe, beforeEach, afterEach } from "vitest";
14
+ import fs from "node:fs/promises";
15
+ import path from "node:path";
16
+ import os from "node:os";
17
+
18
+ import type { ForgeRuntimeContext } from "../types.ts";
19
+ import { runCreate } from "./create.ts";
20
+
21
+ let tmpDir: string;
22
+
23
+ beforeEach(async () => {
24
+ tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "create-superfolder-"));
25
+ });
26
+
27
+ afterEach(async () => {
28
+ await fs.rm(tmpDir, { recursive: true, force: true });
29
+ });
30
+
31
+ function ctx(): ForgeRuntimeContext {
32
+ const sink = (_msg: string, _details?: unknown): void => {};
33
+ return {
34
+ workspaceRoot: tmpDir,
35
+ logger: { section: sink, info: sink, warn: sink, error: sink, success: sink },
36
+ dryRun: false,
37
+ outputFormat: "json",
38
+ };
39
+ }
40
+
41
+ async function childWithForge(name: string): Promise<void> {
42
+ await fs.mkdir(path.join(tmpDir, name), { recursive: true });
43
+ await fs.writeFile(path.join(tmpDir, name, "forge.yaml"), 'schema: "forge/workspace@1"\n');
44
+ }
45
+
46
+ describe("forge.create — CREATE-SUPERFOLDER-01 (RFC-1639)", () => {
47
+ test("a directory of ≥2 forge-governed children refuses with the hub diagnostic", async () => {
48
+ await childWithForge("alpha");
49
+ await childWithForge("beta");
50
+ const result = await runCreate(
51
+ { argv: [], flags: { "in-place": true, profile: "typescript" } },
52
+ ctx(),
53
+ );
54
+ expect(result.exitCode).toBe(1);
55
+ expect(result.data?.status).toBe("fail");
56
+ const msg = result.data?.errors.join("\n") ?? "";
57
+ expect(msg).toContain("CREATE-SUPERFOLDER-01");
58
+ expect(msg).toContain("system-profile hub");
59
+ expect(result.data?.filesCreated).toEqual([]);
60
+ });
61
+
62
+ test("a single forge-governed child falls through to the plain empty-dir refusal", async () => {
63
+ await childWithForge("alpha");
64
+ const result = await runCreate(
65
+ { argv: [], flags: { "in-place": true, profile: "typescript" } },
66
+ ctx(),
67
+ );
68
+ expect(result.exitCode).toBe(1);
69
+ const msg = result.data?.errors.join("\n") ?? "";
70
+ expect(msg).toContain("Directory is not empty");
71
+ expect(msg).not.toContain("CREATE-SUPERFOLDER-01");
72
+ });
73
+ });
@@ -9,7 +9,6 @@
9
9
  </non-goals>
10
10
  </MODULE_CONTRACT>
11
11
  <CHANGE_SUMMARY>
12
- <item>RFC-1500: step 2 — forge.create adopts the fixed branch model</item>
13
12
  <item>RFC-1500: link branch-model guide in committed NEXT_STEPS.md (review r1)</item>
14
13
  <item>RFC-1578: correctness manifest, validator, promotes gate
15
14
 
@@ -20,7 +19,8 @@ F1 code-only anchor scan (markdown fences never declare anchors); F2 generated i
20
19
  <item>RFC-1578: close review REVIEW-CODE-2026-11-12-09 findings
21
20
 
22
21
  N1 index-hint rows count only for files in the workspace listing; N2 forge create leaves exempt repositories unbound; N3 listing test stages a file. Record DEV-3/DEV-4 amendments (CORR-07 future/escaping captures, index as re-verified hint) in the RFC Deviations section.</item>
23
- <history>RFC-0544, RFC-0548, RFC-0550, RFC-0640, RFC-0643, RFC-0664, RFC-0877, RFC-1097, RFC-1224</history>
22
+ <item>RFC-1639: step 3-4 — friction.migrate --from ingest, friction.add --level, CREATE-SUPERFOLDER-01 guard</item>
23
+ <history>RFC-0544, RFC-0548, RFC-0550, RFC-0640, RFC-0643, RFC-0664, RFC-0877, RFC-1097, RFC-1224, RFC-1500</history>
24
24
  </CHANGE_SUMMARY>
25
25
  */
26
26
 
@@ -258,6 +258,32 @@ export async function runCreate(
258
258
  } catch {
259
259
  dirEntries = [];
260
260
  }
261
+ // RFC-1639 (CREATE-SUPERFOLDER-01): a directory whose immediate children
262
+ // already carry forge.yaml is a superfolder — its governance belongs in a
263
+ // system-profile hub repository, never in a folder-level forge.yaml. The
264
+ // guard bounds the command; a hand-written forge.yaml is untouched.
265
+ let forgeChildren = 0;
266
+ for (const name of dirEntries) {
267
+ if (await fio.exists(path.join(targetDir, name, "forge.yaml"))) forgeChildren++;
268
+ }
269
+ if (forgeChildren >= 2) {
270
+ const msg =
271
+ `CREATE-SUPERFOLDER-01: ${targetDir} already holds ${forgeChildren} forge-governed repositories — ` +
272
+ `this is a superfolder. Folder-level governance lives in a system-profile hub repository ` +
273
+ `(profile: system — system/products.yaml, friction registry, task queue), never in a ` +
274
+ `forge.yaml at this level. Refusing to scaffold.`;
275
+ errors.push(msg);
276
+ if (outputFormat === "pretty") {
277
+ logger.error(msg);
278
+ }
279
+ return {
280
+ data: { command: "forge.create", status: "fail", projectDir: targetDir, profile, filesCreated: [], errors },
281
+ nextSteps: failNextSteps,
282
+ exitCode: 1,
283
+ summary: `forge.create: failed — ${msg}`,
284
+ };
285
+ }
286
+
261
287
  const unexpectedEntries = dirEntries.filter((e) => !ALLOWED_EXISTING_DIRS.has(e));
262
288
  if (unexpectedEntries.length > 0) {
263
289
  const msg = `Directory is not empty. Found: ${unexpectedEntries.slice(0, 10).join(", ")}${unexpectedEntries.length > 10 ? ` (and ${unexpectedEntries.length - 10} more)` : ""}. The target directory must be empty. Refusing to scaffold.`;
@@ -7,7 +7,6 @@
7
7
  </non-goals>
8
8
  </MODULE_CONTRACT>
9
9
  <CHANGE_SUMMARY>
10
- <item>RFC-0679: add assets field to stackProfileSchema for asset management commands.</item>
11
10
  <item>RFC-0680: add release field to stackProfileSchema for release lifecycle commands.</item>
12
11
  <item>ADR-0043: add scriptDir field for agent-generated script directory convention.</item>
13
12
  <item>RFC-1097: step 6 — compass.migrate codemod run
@@ -16,7 +15,8 @@ Mechanical v1 to v2 header migration across the workspace: 942 files rewritten
16
15
  <item>RFC-1097: sweep — packages/forge + services clean
17
16
 
18
17
  Sweep batch 2: real KEY_DECISIONS on 10 files, expanded purposes (CONTRACT-02/PURPOSE-02), headers on mission/index + gen-upstreams, sanitizeItemText in summary.record (literal Compass tags corrupted history), excludedPaths for wrangler types, test-fixtures testPattern. forge+services now 0 diagnostics under --mode error.</item>
19
- <history>RFC-0392, RFC-0638, RFC-0674</history>
18
+ <item>RFC-1639: revert container-scope contracts — superfolder governance moves to the system hub</item>
19
+ <history>RFC-0392, RFC-0638, RFC-0674, RFC-0679</history>
20
20
  </CHANGE_SUMMARY>
21
21
  */
22
22
 
@@ -0,0 +1,202 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1633: evidence-consult serialization + degraded reader mode —
4
+ AC-1/AC-4 lock serialization + dead-holder recovery on the
5
+ withEvidenceConsultLock seam, AC-2 bestEffort marks trusted:false and
6
+ never touches the lock, AC-3 assertJudgedEvidence boundary throw,
7
+ AC-5 EVIDENCE-BUDGET phase refusal, AC-7 concurrent holders serialize and
8
+ all complete. Plus the call-site scan: `mode: "bestEffort"` may appear
9
+ only in the enumerated non-judging call sites.</purpose>
10
+ <non-goals>
11
+ <item>No full judged-consult e2e — the preflight/watch/settle machinery is
12
+ RFC-1616's own suite; this file covers the scheduling layer.</item>
13
+ </non-goals>
14
+ </MODULE_CONTRACT>
15
+ <CHANGE_SUMMARY>
16
+ <item>RFC-1633: step 5 — serialization/mode/budget/scan-guard tests</item>
17
+ <item>RFC-1633: serialize evidence consults + bestEffort reader mode (RFC-1633)</item>
18
+ <item>RFC-1633: review round 1 — digest envInputs, package-wide bestEffort scan, holder command, serialized standalone preflight</item>
19
+ </CHANGE_SUMMARY>
20
+ */
21
+
22
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
23
+ import { existsSync, mkdirSync, readFileSync, readdirSync } from "node:fs";
24
+ import { tmpdir, hostname } from "node:os";
25
+ import { join, relative, resolve } from "node:path";
26
+ import { spawnSync } from "node:child_process";
27
+
28
+ import { afterEach, describe, expect, it } from "vitest";
29
+
30
+ import { assertJudgedEvidence, evidenceBudgetBreach, gitEvidence } from "../../os/flow/git.ts";
31
+ import {
32
+ EVIDENCE_CONSULT_LOCK_RELATIVE_PATH,
33
+ resolveEvidenceCommonGitDir,
34
+ withEvidenceConsultLock,
35
+ } from "../../os/flow/evidence-lock.ts";
36
+
37
+ const dirs: string[] = [];
38
+ afterEach(async () => {
39
+ for (const dir of dirs.splice(0)) await rm(dir, { recursive: true, force: true });
40
+ }, 20_000);
41
+
42
+ const HOST = hostname();
43
+
44
+ async function scratchRepo(): Promise<string> {
45
+ const dir = await mkdtemp(join(tmpdir(), "ev-consult-"));
46
+ dirs.push(dir);
47
+ mkdirSync(join(dir, ".git"));
48
+ return dir;
49
+ }
50
+
51
+ async function realRepo(): Promise<string> {
52
+ const dir = await mkdtemp(join(tmpdir(), "ev-real-"));
53
+ dirs.push(dir);
54
+ const init = spawnSync("git", ["init", "-q", dir]);
55
+ if (init.status !== 0) throw new Error(`git init failed: ${init.stderr}`);
56
+ return dir;
57
+ }
58
+
59
+ const deferred = <T>() => {
60
+ let resolve!: (v: T) => void;
61
+ let reject!: (e: unknown) => void;
62
+ const promise = new Promise<T>((res, rej) => {
63
+ resolve = res;
64
+ reject = rej;
65
+ });
66
+ return { promise, resolve, reject };
67
+ };
68
+
69
+ describe("evidence-consult lock serialization (AC-1, AC-4, AC-7)", () => {
70
+ it("AC-1: two overlapping consults on one commonGitDir never interleave", async () => {
71
+ const repo = await scratchRepo();
72
+ let inside = 0;
73
+ let maxInside = 0;
74
+ const gate = deferred<void>();
75
+ const order: string[] = [];
76
+ const first = withEvidenceConsultLock(repo, { waitMs: 5_000 }, async () => {
77
+ inside++;
78
+ maxInside = Math.max(maxInside, inside);
79
+ order.push("first-in");
80
+ await gate.promise;
81
+ inside--;
82
+ order.push("first-out");
83
+ });
84
+ // Yield so the first consult holds the lock before the second starts.
85
+ await new Promise((r) => setTimeout(r, 20));
86
+ const second = withEvidenceConsultLock(repo, { waitMs: 5_000 }, async () => {
87
+ inside++;
88
+ maxInside = Math.max(maxInside, inside);
89
+ order.push("second-in");
90
+ inside--;
91
+ order.push("second-out");
92
+ });
93
+ gate.resolve();
94
+ await Promise.all([first, second]);
95
+ expect(maxInside).toBe(1);
96
+ expect(order).toEqual(["first-in", "first-out", "second-in", "second-out"]);
97
+ });
98
+
99
+ it("AC-4: a dead holder's lock is broken without waiting", async () => {
100
+ const repo = await scratchRepo();
101
+ const common = resolveEvidenceCommonGitDir(repo);
102
+ expect(common).not.toBeNull();
103
+ const lockPath = join(common!, EVIDENCE_CONSULT_LOCK_RELATIVE_PATH);
104
+ mkdirSync(join(common!, "forge"), { recursive: true });
105
+ const deadPid = spawnSync(process.execPath, ["-e", ""]).pid;
106
+ expect(deadPid).toBeDefined();
107
+ await writeFile(
108
+ lockPath,
109
+ JSON.stringify({ pid: deadPid, host: HOST, at: new Date().toISOString() }),
110
+ );
111
+ let ran = false;
112
+ await withEvidenceConsultLock(repo, { waitMs: 2_000 }, async () => {
113
+ ran = true;
114
+ });
115
+ expect(ran).toBe(true);
116
+ // The lock released cleanly after fn.
117
+ expect(existsSync(lockPath)).toBe(false);
118
+ });
119
+
120
+ it("AC-7: three concurrent holders serialize and all complete", async () => {
121
+ const repo = await scratchRepo();
122
+ let inside = 0;
123
+ let maxInside = 0;
124
+ const holder = async () => {
125
+ await withEvidenceConsultLock(repo, { waitMs: 5_000 }, async () => {
126
+ inside++;
127
+ maxInside = Math.max(maxInside, inside);
128
+ await new Promise((r) => setTimeout(r, 15));
129
+ inside--;
130
+ });
131
+ };
132
+ await Promise.all([holder(), holder(), holder()]);
133
+ expect(maxInside).toBe(1);
134
+ });
135
+ });
136
+
137
+ describe("bestEffort mode (AC-2) + boundary (AC-3)", () => {
138
+ it("AC-2: mode:'bestEffort' returns trusted:false and creates no lock", async () => {
139
+ const repo = await realRepo();
140
+ const r = await gitEvidence(repo, ["rev-parse", "--git-dir"], {
141
+ mode: "bestEffort",
142
+ });
143
+ expect(r.exitCode).toBe(0);
144
+ expect(r.trusted).toBe(false);
145
+ // No preflight, no watch, no lock — the lock artifact never appears.
146
+ const common = resolveEvidenceCommonGitDir(repo);
147
+ expect(existsSync(join(common!, EVIDENCE_CONSULT_LOCK_RELATIVE_PATH))).toBe(false);
148
+ });
149
+
150
+ it("AC-3: assertJudgedEvidence throws EVIDENCE-MODE on trusted:false", () => {
151
+ expect(() =>
152
+ assertJudgedEvidence({ exitCode: 0, stdout: "", stderr: "", trusted: false }),
153
+ ).toThrowError(/EVIDENCE-MODE/);
154
+ expect(() =>
155
+ assertJudgedEvidence({ exitCode: 0, stdout: "", stderr: "", trusted: true }),
156
+ ).not.toThrow();
157
+ });
158
+ });
159
+
160
+ describe("consult budget (AC-5)", () => {
161
+ it("AC-5: a breach refuses EVIDENCE-BUDGET naming phase and elapsed vs budget", () => {
162
+ const startedAt = Date.now() - 10_000;
163
+ const refusal = evidenceBudgetBreach(["rev-parse", "--git-dir"], "arm", startedAt, 5_000);
164
+ expect(refusal).not.toBeNull();
165
+ expect(refusal!.exitCode).toBe(-1);
166
+ expect(refusal!.stderr).toContain("EVIDENCE-BUDGET");
167
+ expect(refusal!.stderr).toContain("arm");
168
+ expect(refusal!.stderr).toMatch(/elapsed > 5000ms budget/);
169
+ // No clock started → no budget accounting (preflight:false reads).
170
+ expect(evidenceBudgetBreach(["x"], "arm", undefined, 5)).toBeNull();
171
+ });
172
+ });
173
+
174
+ describe("bestEffort call-site scan", () => {
175
+ it("mode:'bestEffort' appears only in the enumerated non-judging call sites", () => {
176
+ const PKG_DIR = resolve(__dirname, "../..");
177
+ const ALLOWLIST = new Set(["digest.ts"]);
178
+ const offenders: string[] = [];
179
+ const scan = (dir: string) => {
180
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
181
+ const p = join(dir, entry.name);
182
+ const rel = relative(PKG_DIR, p).replaceAll("\\", "/");
183
+ if (entry.isDirectory()) {
184
+ if (rel === "src/tests" || entry.name === "tests" || entry.name === "node_modules") {
185
+ continue;
186
+ }
187
+ scan(p);
188
+ continue;
189
+ }
190
+ if (!entry.name.endsWith(".ts")) continue;
191
+ const content = readFileSync(p, "utf8");
192
+ if (/mode:\s*"bestEffort"/.test(content)) {
193
+ if (!ALLOWLIST.has(entry.name)) offenders.push(p);
194
+ }
195
+ }
196
+ };
197
+ for (const root of [join(PKG_DIR, "os"), join(PKG_DIR, "src")]) {
198
+ if (existsSync(root)) scan(root);
199
+ }
200
+ expect(offenders).toEqual([]);
201
+ });
202
+ });
@@ -19,6 +19,7 @@ import { promisify } from "node:util";
19
19
  import { join } from "node:path";
20
20
  import { tmpdir } from "node:os";
21
21
  import { runPinnedValidate } from "../../os/core/handlers/pinned-validate.ts";
22
+ import { isArchiveBlocked, loadPinnedManifest } from "../../os/core/handlers/pinned-check.ts";
22
23
  import type { ForgeCommandInput, ForgeRuntimeContext } from "../../src/types.ts";
23
24
 
24
25
  const execFileAsync = promisify(execFile);
@@ -145,4 +146,197 @@ describe("runPinnedValidate", () => {
145
146
  await rm(dir, { recursive: true, force: true });
146
147
  }
147
148
  });
149
+
150
+ test("passes an intra-dir move reported as D+A (rename detection off)", async () => {
151
+ const dir = await makeRepo();
152
+ try {
153
+ // A consumer's `diff.renames=false` (or a below-threshold similarity)
154
+ // splits the move into D + A — same exemption as the R pair.
155
+ await git(dir, ["config", "diff.renames", "false"]);
156
+ await mkdir(join(dir, "docs", "rfcs", "archive", "implemented"), { recursive: true });
157
+ await git(dir, ["mv", "docs/rfcs/rfc-0001.md", "docs/rfcs/archive/implemented/rfc-0001.md"]);
158
+
159
+ const result = await runPinnedValidate(makeInput(), makeContext(dir));
160
+ expect(result.data?.status).toBe("pass");
161
+ expect(result.data?.violations).toHaveLength(0);
162
+ } finally {
163
+ await rm(dir, { recursive: true, force: true });
164
+ }
165
+ });
166
+
167
+ test("passes an intra-dir move reported as D+M (destination already tracked)", async () => {
168
+ const dir = await makeRepo();
169
+ try {
170
+ // docs/rfcs/archive/rfc-0001.md already exists in HEAD — git reports
171
+ // `D docs/rfcs/rfc-0001.md` + `M docs/rfcs/archive/rfc-0001.md`, never R.
172
+ await mkdir(join(dir, "docs", "rfcs", "archive"), { recursive: true });
173
+ await writeFile(join(dir, "docs", "rfcs", "archive", "rfc-0001.md"), "# old\n");
174
+ await git(dir, ["add", "-A"]);
175
+ await git(dir, ["commit", "-m", "archive dir"]);
176
+ await writeFile(join(dir, "docs", "rfcs", "archive", "rfc-0001.md"), "# RFC 1\n");
177
+ await git(dir, ["rm", "docs/rfcs/rfc-0001.md"]);
178
+ await git(dir, ["add", "-A"]);
179
+
180
+ const result = await runPinnedValidate(makeInput(), makeContext(dir));
181
+ expect(result.data?.status).toBe("pass");
182
+ expect(result.data?.violations).toHaveLength(0);
183
+ } finally {
184
+ await rm(dir, { recursive: true, force: true });
185
+ }
186
+ });
187
+
188
+ test("still flags a delete when the same-basename file lands outside the pinned dir", async () => {
189
+ const dir = await makeRepo();
190
+ try {
191
+ await git(dir, ["config", "diff.renames", "false"]);
192
+ await mkdir(join(dir, "docs", "other"), { recursive: true });
193
+ await git(dir, ["mv", "docs/rfcs/rfc-0001.md", "docs/other/rfc-0001.md"]);
194
+
195
+ const result = await runPinnedValidate(makeInput(), makeContext(dir));
196
+ expect(result.data?.status).toBe("fail");
197
+ expect(
198
+ result.data?.violations.some(
199
+ (v) => v.path === "docs/rfcs/rfc-0001.md" && v.operation === "delete",
200
+ ),
201
+ ).toBe(true);
202
+ } finally {
203
+ await rm(dir, { recursive: true, force: true });
204
+ }
205
+ });
206
+
207
+ test("still flags a bare delete with no same-basename counterpart", async () => {
208
+ const dir = await makeRepo();
209
+ try {
210
+ await git(dir, ["config", "diff.renames", "false"]);
211
+ // Delete + unrelated add under the same pinned dir — not a move.
212
+ await git(dir, ["rm", "docs/rfcs/rfc-0001.md"]);
213
+ await mkdir(join(dir, "docs", "rfcs"), { recursive: true });
214
+ await writeFile(join(dir, "docs", "rfcs", "rfc-0002.md"), "# RFC 2\n");
215
+ await git(dir, ["add", "-A"]);
216
+
217
+ const result = await runPinnedValidate(makeInput(), makeContext(dir));
218
+ expect(result.data?.status).toBe("fail");
219
+ expect(
220
+ result.data?.violations.some(
221
+ (v) => v.path === "docs/rfcs/rfc-0001.md" && v.operation === "delete",
222
+ ),
223
+ ).toBe(true);
224
+ } finally {
225
+ await rm(dir, { recursive: true, force: true });
226
+ }
227
+ });
228
+ });
229
+
230
+ describe("isArchiveBlocked (F-0004 archive opt-out)", () => {
231
+ async function makeManifestRepo(entries: string): Promise<string> {
232
+ const dir = await makeTempDir();
233
+ await mkdir(join(dir, ".forge"), { recursive: true });
234
+ await writeFile(join(dir, ".forge", "pinned.yaml"), entries);
235
+ return dir;
236
+ }
237
+
238
+ test("protect-pinned dir allows the intra-dir archive move (default contract)", async () => {
239
+ const dir = await makeManifestRepo(
240
+ "pinned:\n - path: docs/rfcs/\n mode: protect\n reason: RFC directory\n",
241
+ );
242
+ try {
243
+ const manifest = (await loadPinnedManifest(dir))!;
244
+ expect(
245
+ isArchiveBlocked(manifest, "docs/rfcs/rfc-1.md", "docs/rfcs/archive/rfc-1.md"),
246
+ ).toBeNull();
247
+ expect(
248
+ isArchiveBlocked(manifest, "docs/rfcs/rfc-1.md", "docs/other/rfc-1.md"),
249
+ )?.not.toBeNull();
250
+ } finally {
251
+ await rm(dir, { recursive: true, force: true });
252
+ }
253
+ });
254
+
255
+ test("archive: false blocks the intra-dir move entirely", async () => {
256
+ const dir = await makeManifestRepo(
257
+ "pinned:\n - path: docs/rfcs/\n mode: protect\n reason: RFC directory\n archive: false\n",
258
+ );
259
+ try {
260
+ const manifest = (await loadPinnedManifest(dir))!;
261
+ const blocked = isArchiveBlocked(
262
+ manifest,
263
+ "docs/rfcs/rfc-1.md",
264
+ "docs/rfcs/archive/rfc-1.md",
265
+ );
266
+ expect(blocked).not.toBeNull();
267
+ expect(blocked?.archive).toBe(false);
268
+ } finally {
269
+ await rm(dir, { recursive: true, force: true });
270
+ }
271
+ });
272
+
273
+ test("freeze mode blocks the intra-dir move too", async () => {
274
+ const dir = await makeManifestRepo(
275
+ "pinned:\n - path: docs/rfcs/\n mode: freeze\n reason: locked\n",
276
+ );
277
+ try {
278
+ const manifest = (await loadPinnedManifest(dir))!;
279
+ expect(
280
+ isArchiveBlocked(manifest, "docs/rfcs/rfc-1.md", "docs/rfcs/archive/rfc-1.md"),
281
+ ).not.toBeNull();
282
+ } finally {
283
+ await rm(dir, { recursive: true, force: true });
284
+ }
285
+ });
286
+
287
+ test("non-pinned source is never blocked", async () => {
288
+ const dir = await makeManifestRepo(
289
+ "pinned:\n - path: docs/rfcs/\n mode: protect\n reason: RFC directory\n archive: false\n",
290
+ );
291
+ try {
292
+ const manifest = (await loadPinnedManifest(dir))!;
293
+ expect(isArchiveBlocked(manifest, "docs/other/x.md", "docs/rfcs/x.md")).toBeNull();
294
+ } finally {
295
+ await rm(dir, { recursive: true, force: true });
296
+ }
297
+ });
298
+
299
+ test("a non-boolean archive value is malformed", async () => {
300
+ const dir = await makeManifestRepo(
301
+ "pinned:\n - path: docs/rfcs/\n mode: protect\n reason: RFC directory\n archive: never\n",
302
+ );
303
+ try {
304
+ await expect(loadPinnedManifest(dir)).rejects.toThrow(/invalid archive/);
305
+ } finally {
306
+ await rm(dir, { recursive: true, force: true });
307
+ }
308
+ });
309
+ });
310
+
311
+ describe("session.archive with archive:false entries (F-0004)", () => {
312
+ const SESSION_FM = (date: string) =>
313
+ `---\nid: s-1\ndate: ${date}\ntype: session\n---\n\n# session\n`;
314
+
315
+ test("docs.archive family skips files under archive:false dirs entirely", async () => {
316
+ const { runSessionArchive } = await import("../../os/session/handlers/archive.ts");
317
+ const dir = await makeTempDir();
318
+ await mkdir(join(dir, ".forge"), { recursive: true });
319
+ await writeFile(
320
+ join(dir, ".forge", "pinned.yaml"),
321
+ "pinned:\n - path: docs/sessions/\n mode: protect\n reason: Session directory\n archive: false\n",
322
+ );
323
+ await mkdir(join(dir, "docs", "sessions"), { recursive: true });
324
+ await writeFile(
325
+ join(dir, "docs", "sessions", "2020-01-01-00-00-00-aaaaaa.md"),
326
+ SESSION_FM("2020-01-01"),
327
+ );
328
+ try {
329
+ const result = await runSessionArchive(
330
+ { argv: [], flags: { "max-age-days": "7" } },
331
+ makeContext(dir),
332
+ );
333
+ expect(result.data?.moved).toHaveLength(0);
334
+ expect(result.data?.skipped.some((s) => s.reason?.includes("pinned"))).toBe(true);
335
+ // File stays in place — nothing was moved.
336
+ const { existsSync } = await import("node:fs");
337
+ expect(existsSync(join(dir, "docs", "sessions", "2020-01-01-00-00-00-aaaaaa.md"))).toBe(true);
338
+ } finally {
339
+ await rm(dir, { recursive: true, force: true });
340
+ }
341
+ });
148
342
  });
@@ -11,6 +11,7 @@ shebang first line and a clean `sh -n` parse.</purpose>
11
11
  <CHANGE_SUMMARY>
12
12
  <item>RFC-1500: step 1 — profile flow hooks contract test</item>
13
13
  <item>RFC-1500: step 1 — profile flow hooks</item>
14
+ <item>RFC-1639: revert container-scope contracts — superfolder governance moves to the system hub</item>
14
15
  </CHANGE_SUMMARY>
15
16
  */
16
17
 
@@ -10,6 +10,7 @@ Unit tests for profile schema covering its documented public contract and regres
10
10
  <CHANGE_SUMMARY>
11
11
  <item>RFC-0638: initial domain field tests — parsing, defaults, validation, backward compat.</item>
12
12
  <item>RFC-1508: implement RFC-1508 — system profile, system map schemas and system.map.validate</item>
13
+ <item>RFC-1639: revert container-scope contracts — superfolder governance moves to the system hub</item>
13
14
  </CHANGE_SUMMARY>
14
15
  */
15
16
 
@@ -9,6 +9,7 @@ Unit tests for stack profile covering its documented public contract and regress
9
9
  </MODULE_CONTRACT>
10
10
  <CHANGE_SUMMARY>
11
11
  <item>RFC-0392: initial stack profile tests.</item>
12
+ <item>RFC-1639: revert container-scope contracts — superfolder governance moves to the system hub</item>
12
13
  </CHANGE_SUMMARY>
13
14
  */
14
15
 
package/src/types.ts CHANGED
@@ -9,12 +9,12 @@ can be registered in a Warpgogol kernel without direct dependency.</purpose>
9
9
  </non-goals>
10
10
  </MODULE_CONTRACT>
11
11
  <CHANGE_SUMMARY>
12
- <item>RFC-1463: composite gates report complete violation sets and self-ensure prerequisites — ensure/compositeGate metadata, executor ensure runner, blockedBy skip tracking, ENSURE-01..04 + GATE-CMP-01, runCompositeGate</item>
13
12
  <item>RFC-1486: review r1 — committed-state adoption gate, uncommitted-hook committedness, step-failure trail, idempotency declaration, lazy asset resolution</item>
14
13
  <item>RFC-1568: durable gate-run records, --detach mechanics, and forge CLI wiring</item>
15
14
  <item>RFC-1622: honor RFC-1622 receipt capability</item>
16
15
  <item>RFC-1622: preserve single manifest render during archive replay RFC-1622</item>
17
- <history>RFC-0518, RFC-1097, RFC-1147, RFC-1231, RFC-1306, RFC-1354, RFC-1360, RFC-1366, RFC-1461</history>
16
+ <item>RFC-1639: revert container-scope contracts — superfolder governance moves to the system hub</item>
17
+ <history>RFC-0518, RFC-1097, RFC-1147, RFC-1231, RFC-1306, RFC-1354, RFC-1360, RFC-1366, RFC-1461, RFC-1463</history>
18
18
  </CHANGE_SUMMARY>
19
19
  */
20
20