@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,104 @@
1
+ # System hub — superfolder governance (RFC-1639, RFC-1641)
2
+
3
+ A **superfolder** is a directory whose immediate children are forge-governed repositories — for example `~/projects/warpgogol/` holding `werkstatt`, `lagebild`, `dater`, and the rest. Folder-level governance (member health, folder-level frictions, the task queue) lives **inside one member repository** — the system hub — never in a `forge.yaml` at the superfolder root.
4
+
5
+ ## Deploying a hub for a new business
6
+
7
+ Three commands onboard a business folder end to end — no hand-edited yaml:
8
+
9
+ ```bash
10
+ # 1. Scaffold the hub inside the business folder
11
+ cd <business-folder> && forge create --in-place --profile system
12
+
13
+ # 2. Populate the member roster — scans the folder for forge siblings,
14
+ # resolves each one's git origin, writes products.yaml + products.local.yaml
15
+ forge system.product.register --discover [--dry-run]
16
+
17
+ # 3. Verify the roster against disk reality
18
+ forge system.products.status
19
+ ```
20
+
21
+ Explicit registration for members outside the folder or not yet cloned:
22
+
23
+ ```bash
24
+ forge system.product.register --id <kebab> --remote <url> [--folder <path>] \
25
+ [--offers <contract>]* [--frozen] [--update]
26
+ ```
27
+
28
+ A fresh hub also generates a hub-native root `AGENTS.md` (`profiles/root-agents-system.md` via `rootAgentsMdTemplate`) — agents in the repo learn the member model, the sweep command, the folder-level friction path, and the task queue from their instruction layer.
29
+
30
+ ## The hub model
31
+
32
+ - The hub is an ordinary git repository with `profile: system` in its `forge.yaml`. On this installation it is `warpgogol-verbund`.
33
+ - The canonical member roster is `system/products.yaml` (`forge/system-products@1`): `products[]` with `id`, `remote`, `offers`, and the additive `frozen` flag; a top-level `ignored[]` list names sibling directories (`{id, note?}`) that are deliberately outside the member model.
34
+ - The local checkout map is `system/products.local.yaml` (`forge/system-products-local@1`, gitignored): `folders:` maps each product id to an absolute or hub-relative folder.
35
+ - Because the hub is a normal repository, its friction registry is the standard `docs/frictions/` `F-NNNN` per-record store — folder-level records are versioned, gated, and journaled like everything else. There is no second id namespace: a folder-level record is an `F-NNNN` record in the hub's registry carrying `level: folder`.
36
+
37
+ ## Commands
38
+
39
+ ### `system.product.register`
40
+
41
+ The roster write surface (RFC-1641). Writes `system/products.yaml` and the gitignored `system/products.local.yaml` — the session commits.
42
+
43
+ - **Explicit:** `--id <kebab> --remote <url> [--folder <path>] [--offers <contract>]* [--frozen] [--update] [--dry-run]`. New ids require `--remote`; a duplicate id without `--update` refuses; a `--folder` already mapped to another product refuses; a `--folder` absent on disk warns but records.
44
+ - **Discover:** `--discover` scans the hub's parent directory and registers every sibling carrying `forge.yaml` that is not already registered — id from the directory name, remote from `git remote get-url origin`, folder as `../<name>`. Skips `ignored[]` names, `@`-worktrees, hidden dirs, the hub itself, non-kebab names, and siblings with no readable origin — each reported under `skipped[]` with a reason; warning-class skips never fail the run.
45
+ - Errors are `SYSTEM-PRODUCTS-03` (writes nothing); warnings are `SYSTEM-PRODUCTS-04`. Idempotent: an identical re-run reports `skipped: already-registered` rather than rewriting.
46
+
47
+ ```bash
48
+ werkstatt run system.product.register --id billing --remote git@github.com:org/billing.git --folder ../billing --offers billing-api
49
+ werkstatt run system.product.register --discover --dry-run
50
+ ```
51
+
52
+ ### `system.products.status`
53
+
54
+ Read-only member health report for the hub. Run inside the system-profile repository it probes each product in `system/products.local.yaml`:
55
+
56
+ - `folder`, `profile`, `forgeVersion` — from the member's own `forge.yaml`
57
+ - `versionOk` — member `forge.syncedVersion` against the hub baseline
58
+ - `dirty`, `sessionWorktrees`, `aheadOfOrigin` — git probes that degrade to `null` + warning when the member is not a git checkout
59
+ - `frozen` — a frozen member is reported but exempt from error diagnostics: a missing or broken frozen product warns, never fails the command
60
+
61
+ It also scans the hub's **sibling directories** (the superfolder) and warns on:
62
+
63
+ - a sibling carrying `forge.yaml` that is not a registered product — an adoption gap (register it in `system/products.yaml` or name it `ignored`)
64
+ - a git-initialized sibling without `forge.yaml` — a pre-adoption signal
65
+
66
+ ```bash
67
+ werkstatt run system.products.status [--json]
68
+ ```
69
+
70
+ ### `friction.migrate --from <external frictions.yaml>`
71
+
72
+ Ingests a legacy single-file `docs/frictions.yaml` registry from **outside** the workspace — the superfolder-level file lands inside the hub. Each record:
73
+
74
+ - mints the next `F-NNNN` id via the shared git-dir ledger (never dir-scan)
75
+ - carries `migratedFrom` (its old `F-NNNN` id), `origin` (the source folder's name, unwrapping a trailing `docs/`), and `level` (default `folder`, `--level repo` overrides)
76
+ - is skipped on re-run when a record with the same `origin` + `migratedFrom` already exists — a crash-interrupted run re-derives the same mapping
77
+
78
+ The source file is removed **last**, only when the run is clean. `--from` must point outside the workspace; the no-flag path owns the workspace's own `docs/frictions.yaml` as before.
79
+
80
+ ```bash
81
+ werkstatt run friction.migrate --from ../docs/frictions.yaml [--dry-run] [--level folder] [--session <id>]
82
+ ```
83
+
84
+ ### `friction.add --level folder`
85
+
86
+ Marks a new record as concerning the superfolder rather than the repo holding the registry. `repo` is the default and is omitted from the written record; any other value refuses (FRICTION-03).
87
+
88
+ ```bash
89
+ werkstatt run friction.add --category tooling --signature "…" --friction "…" \
90
+ --measure "…" --level folder
91
+ ```
92
+
93
+ ## Bounded surfaces
94
+
95
+ - `forge create --in-place` refuses a directory whose immediate children already carry `forge.yaml` (CREATE-SUPERFOLDER-01): that folder is a superfolder, and its governance belongs in a system-profile hub repository, not in a folder-level `forge.yaml`. The guard bounds the command only — a hand-written `forge.yaml` is untouched.
96
+ - Everything else treats the hub as an ordinary workspace repository — frictions, sessions, journal, and queue flow through the existing commands.
97
+
98
+ ## Record fields
99
+
100
+ | Field | Shape | Meaning |
101
+ | --- | --- | --- |
102
+ | `level` | `repo \| folder` (optional) | `folder` = the record concerns the superfolder, not this repo |
103
+ | `origin` | string (optional) | Source folder name an ingested record came from |
104
+ | `migratedFrom` | `F-NNNN` (optional) | The id the record carried in its previous registry |
@@ -26,7 +26,7 @@ import type {
26
26
  ForgeRuntimeContext,
27
27
  } from "../../../src/types.ts";
28
28
  import { ADR_DIR } from "../types.ts";
29
- import { loadPinnedManifest, isPinned, isIntraDirMove } from "../../core/handlers/pinned-check.ts";
29
+ import { loadPinnedManifest, isArchiveBlocked } from "../../core/handlers/pinned-check.ts";
30
30
 
31
31
  export const ADR_TERMINAL_STATUSES = ["implemented", "rejected", "superseded"] as const;
32
32
 
@@ -116,11 +116,7 @@ export async function runAdrArchive(
116
116
 
117
117
  // RFC-0733: Check if file is pinned before moving
118
118
  // Gap fix: exempt intra-directory moves (file stays within the same pinned dir)
119
- if (
120
- pinnedManifest &&
121
- isPinned(pinnedManifest, relFile) &&
122
- !isIntraDirMove(pinnedManifest, relFile, targetRel)
123
- ) {
119
+ if (pinnedManifest && isArchiveBlocked(pinnedManifest, relFile, targetRel)) {
124
120
  skipped.push({ id, file: relFile, reason: "pinned (protected by .forge/pinned.yaml)" });
125
121
  if (outputFormat === "pretty") {
126
122
  logger.warn(` pinned: skipping ${relFile} (protected)`);
@@ -165,11 +161,7 @@ export async function runAdrArchive(
165
161
 
166
162
  // RFC-0733: Check if file is pinned before moving
167
163
  // Gap fix: exempt intra-directory moves (file stays within the same pinned dir)
168
- if (
169
- pinnedManifest &&
170
- isPinned(pinnedManifest, relFile) &&
171
- !isIntraDirMove(pinnedManifest, relFile, targetRel)
172
- ) {
164
+ if (pinnedManifest && isArchiveBlocked(pinnedManifest, relFile, targetRel)) {
173
165
  skipped.push({ id, file: relFile, reason: "pinned (protected by .forge/pinned.yaml)" });
174
166
  if (outputFormat === "pretty") {
175
167
  logger.warn(` pinned: skipping ${relFile} (protected)`);
@@ -0,0 +1,174 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Unit tests for runAdrCreate — the --related flag must land in the created
5
+ ADR's frontmatter across every template shape (F-0005).
6
+ </purpose>
7
+ <non-goals>
8
+ <item>Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only.</item>
9
+ </non-goals>
10
+ </MODULE_CONTRACT>
11
+ <CHANGE_SUMMARY>
12
+ <item>F-0005: --related flag honored across `related: []`, bare `related:`, and seeded-list template shapes</item>
13
+ </CHANGE_SUMMARY>
14
+ */
15
+
16
+ import { test, expect, describe } from "vitest";
17
+ import { mkdtemp, rm, mkdir, writeFile, readFile } from "node:fs/promises";
18
+ import { execFile } from "node:child_process";
19
+ import { promisify } from "node:util";
20
+ import { join } from "node:path";
21
+ import { tmpdir } from "node:os";
22
+ import { runAdrCreate } from "./list-create.ts";
23
+ import type { ForgeCommandInput, ForgeFlagValue, ForgeRuntimeContext } from "../../../src/types.ts";
24
+
25
+ const execFileAsync = promisify(execFile);
26
+
27
+ function makeContext(workspaceRoot: string): ForgeRuntimeContext {
28
+ return {
29
+ workspaceRoot,
30
+ logger: {
31
+ section: () => {},
32
+ info: () => {},
33
+ warn: () => {},
34
+ error: () => {},
35
+ success: () => {},
36
+ },
37
+ dryRun: false,
38
+ outputFormat: "json",
39
+ };
40
+ }
41
+
42
+ function makeInput(flags: Record<string, ForgeFlagValue>): ForgeCommandInput {
43
+ return { argv: [], flags };
44
+ }
45
+
46
+ async function git(dir: string, args: string[]): Promise<void> {
47
+ await execFileAsync("git", args, { cwd: dir });
48
+ }
49
+
50
+ const TEMPLATE_FM = `---
51
+ id: ADR-0000
52
+ title: "Short imperative title"
53
+ status: proposed
54
+ scope: package
55
+ decider: architecture
56
+ createdAt: YYYY-MM-DD
57
+ updatedAt: YYYY-MM-DD
58
+ implementedAt:
59
+ closedAt:
60
+ supersedes: []
61
+ supersededBy:
62
+ RELATED_FIELD
63
+ reviewers: []
64
+ ---
65
+
66
+ # ADR-0000: Short imperative title
67
+
68
+ ## Context
69
+
70
+ ctx
71
+
72
+ ## Decision
73
+
74
+ dec
75
+
76
+ ## Consequences
77
+
78
+ con
79
+ `;
80
+
81
+ /**
82
+ * Scaffold a git repo with docs/adrs/adr-0000-template.md where the
83
+ * `related:` field takes the given template shape.
84
+ */
85
+ async function makeRepo(relatedField: string): Promise<string> {
86
+ const dir = await mkdtemp(join(tmpdir(), "forge-adr-create-test-"));
87
+ await git(dir, ["init"]);
88
+ await git(dir, ["config", "user.email", "test@example.com"]);
89
+ await git(dir, ["config", "user.name", "Test"]);
90
+ await mkdir(join(dir, "docs", "adrs"), { recursive: true });
91
+ await writeFile(
92
+ join(dir, "docs", "adrs", "adr-0000-template.md"),
93
+ TEMPLATE_FM.replace("RELATED_FIELD", relatedField),
94
+ );
95
+ await git(dir, ["add", "-A"]);
96
+ await git(dir, ["commit", "-m", "init"]);
97
+ return dir;
98
+ }
99
+
100
+ describe("runAdrCreate --related (F-0005)", () => {
101
+ test("writes related ids when the template ships `related: []`", async () => {
102
+ const dir = await makeRepo("related: []");
103
+ try {
104
+ const result = await runAdrCreate(
105
+ makeInput({ title: "Use X", related: "RFC-0365,ADR-0001" }),
106
+ makeContext(dir),
107
+ );
108
+ expect(result.data?.status).toBe("ok");
109
+ const content = await readFile(join(dir, result.data!.file!), "utf8");
110
+ expect(content).toMatch(/related:\n {2}- RFC-0365\n {2}- ADR-0001/);
111
+ expect(content).not.toContain("related: []");
112
+ } finally {
113
+ await rm(dir, { recursive: true, force: true });
114
+ }
115
+ });
116
+
117
+ test("writes related ids when the template ships a bare `related:`", async () => {
118
+ const dir = await makeRepo("related:");
119
+ try {
120
+ const result = await runAdrCreate(
121
+ makeInput({ title: "Use X", related: "RFC-0001" }),
122
+ makeContext(dir),
123
+ );
124
+ expect(result.data?.status).toBe("ok");
125
+ const content = await readFile(join(dir, result.data!.file!), "utf8");
126
+ expect(content).toMatch(/related:\n {2}- RFC-0001\n/);
127
+ } finally {
128
+ await rm(dir, { recursive: true, force: true });
129
+ }
130
+ });
131
+
132
+ test("replaces a seeded `related:\\n - RFC-0001` list", async () => {
133
+ const dir = await makeRepo("related:\n - RFC-0001");
134
+ try {
135
+ const result = await runAdrCreate(
136
+ makeInput({ title: "Use X", related: "RFC-0002" }),
137
+ makeContext(dir),
138
+ );
139
+ expect(result.data?.status).toBe("ok");
140
+ const content = await readFile(join(dir, result.data!.file!), "utf8");
141
+ expect(content).toMatch(/related:\n {2}- RFC-0002\n/);
142
+ expect(content).not.toContain("- RFC-0001");
143
+ } finally {
144
+ await rm(dir, { recursive: true, force: true });
145
+ }
146
+ });
147
+
148
+ test("normalizes lowercase and unpadded ids", async () => {
149
+ const dir = await makeRepo("related: []");
150
+ try {
151
+ const result = await runAdrCreate(
152
+ makeInput({ title: "Use X", related: "rfc-365,adr-1" }),
153
+ makeContext(dir),
154
+ );
155
+ expect(result.data?.status).toBe("ok");
156
+ const content = await readFile(join(dir, result.data!.file!), "utf8");
157
+ expect(content).toMatch(/related:\n {2}- RFC-0365\n {2}- ADR-0001/);
158
+ } finally {
159
+ await rm(dir, { recursive: true, force: true });
160
+ }
161
+ });
162
+
163
+ test("no --related flag leaves `related: []`", async () => {
164
+ const dir = await makeRepo("related: []");
165
+ try {
166
+ const result = await runAdrCreate(makeInput({ title: "Use X" }), makeContext(dir));
167
+ expect(result.data?.status).toBe("ok");
168
+ const content = await readFile(join(dir, result.data!.file!), "utf8");
169
+ expect(content).toContain("related: []");
170
+ } finally {
171
+ await rm(dir, { recursive: true, force: true });
172
+ }
173
+ });
174
+ });
@@ -188,15 +188,23 @@ export async function runAdrCreate(
188
188
  .split(",")
189
189
  .map((s) => s.trim())
190
190
  .filter(Boolean)
191
+ .map((id) =>
192
+ id.replace(
193
+ /^(rfc|adr|dna|ap)-(\d+)$/i,
194
+ (_, p, n) => `${String(p).toUpperCase()}-${String(n).padStart(4, "0")}`,
195
+ ),
196
+ )
191
197
  : [];
192
- if (relatedIds.length > 0) {
193
- content = content.replace(
194
- /^related:\s*\n\s*- RFC-0001\s*$/m,
195
- `related:\n${relatedIds.map((id) => ` - ${id}`).join("\n")}`,
196
- );
197
- } else {
198
- content = content.replace(/^related:\s*\n\s*- RFC-0001\s*$/m, `related: []`);
199
- }
198
+ // Templates ship `related:` as `related: []`, a bare `related:`, or a seeded
199
+ // `related:\n - RFC-0001` list — replace the field plus any list items under
200
+ // it. The previous regex only matched the seeded shape and silently no-oped
201
+ // on `related: []` (F-0005).
202
+ content = content.replace(
203
+ /^related:[^\n]*(?:\n[ \t]+-[^\n]*)*/m,
204
+ relatedIds.length > 0
205
+ ? `related:\n${relatedIds.map((id) => ` - ${id}`).join("\n")}`
206
+ : `related: []`,
207
+ );
200
208
 
201
209
  try {
202
210
  await fs.mkdir(adrDirPath);
@@ -29,7 +29,7 @@ import type {
29
29
  } from "../../../src/types.ts";
30
30
  import { AUDIT_DIR } from "../types.ts";
31
31
  import type { AuditArchiveResult } from "../types.ts";
32
- import { loadPinnedManifest, isPinned, isIntraDirMove } from "../../core/handlers/pinned-check.ts";
32
+ import { loadPinnedManifest, isArchiveBlocked } from "../../core/handlers/pinned-check.ts";
33
33
 
34
34
  const TERMINAL_STATUSES = ["implemented", "rejected", "superseded"] as const;
35
35
 
@@ -99,11 +99,7 @@ export async function runAuditArchive(
99
99
 
100
100
  // RFC-0733: Check if file is pinned before moving
101
101
  // Gap fix: exempt intra-directory moves (file stays within the same pinned dir)
102
- if (
103
- pinnedManifest &&
104
- isPinned(pinnedManifest, relFile) &&
105
- !isIntraDirMove(pinnedManifest, relFile, targetRel)
106
- ) {
102
+ if (pinnedManifest && isArchiveBlocked(pinnedManifest, relFile, targetRel)) {
107
103
  skipped.push({
108
104
  id: rfcId,
109
105
  file: relFile,
@@ -152,11 +148,7 @@ export async function runAuditArchive(
152
148
 
153
149
  // RFC-0733: Check if file is pinned before moving
154
150
  // Gap fix: exempt intra-directory moves (file stays within the same pinned dir)
155
- if (
156
- pinnedManifest &&
157
- isPinned(pinnedManifest, relFile) &&
158
- !isIntraDirMove(pinnedManifest, relFile, targetRel)
159
- ) {
151
+ if (pinnedManifest && isArchiveBlocked(pinnedManifest, relFile, targetRel)) {
160
152
  skipped.push({
161
153
  id: rfcId,
162
154
  file: relFile,
@@ -271,27 +271,53 @@ export async function runArchiveRegen(options: {
271
271
  export async function stageMovedPairs(options: {
272
272
  movedPaths: string[];
273
273
  workspaceRoot: string;
274
- }): Promise<{ staged: number; error?: string }> {
274
+ }): Promise<{ staged: number; ignored: string[]; error?: string }> {
275
275
  const { movedPaths, workspaceRoot } = options;
276
- if (movedPaths.length === 0) return { staged: 0 };
276
+ if (movedPaths.length === 0) return { staged: 0, ignored: [] };
277
277
  // Anchored mutation on the judged channel — the ambient exec layer
278
278
  // inherits the session's `GIT_*`, so `git add` could stage into a
279
279
  // foreign index or under a hostile env (CX-170). A refused surface
280
280
  // reports an error, never a fabricated `staged`.
281
281
  const preflight = await evidenceRepoPreflight(workspaceRoot);
282
282
  if (preflight === null) {
283
- return { staged: 0, error: "repo surface unverifiable — refusing to stage" };
283
+ return { staged: 0, ignored: [], error: "repo surface unverifiable — refusing to stage" };
284
284
  }
285
285
  try {
286
- const result = await evidenceAnchoredGit(workspaceRoot, ["add", "-A", "--", ...movedPaths], {
286
+ // F-0004: a moved path hidden by .gitignore makes `git add` refuse the
287
+ // whole pathspec — the commit would carry the source delete alone and
288
+ // pinned.validate would report a bare `D`. `-f` is off the anchored
289
+ // table by design, so the ignored set is filtered out first and
290
+ // surfaces as a caller-visible diagnostic instead. `check-ignore`
291
+ // exit 0 = some ignored, 1 = none, other = error (fail open — the
292
+ // add below then reports it).
293
+ const ignoredResult = await verifierGit(workspaceRoot, ["check-ignore", "--", ...movedPaths]);
294
+ // `git add` refuses only ignored paths it would ADD — a deleted source
295
+ // matching a broad ignore pattern still stages its delete cleanly, so
296
+ // the refusal set (and the stageable set) sees only worktree-present
297
+ // ignored paths.
298
+ const ignored =
299
+ ignoredResult.exitCode === 0
300
+ ? ignoredResult.stdout
301
+ .split("\n")
302
+ .filter((l) => l.length > 0 && existsSync(path.join(workspaceRoot, l)))
303
+ : [];
304
+ const stageable = movedPaths.filter((p) => !ignored.includes(p));
305
+ if (stageable.length === 0) {
306
+ return { staged: 0, ignored };
307
+ }
308
+ const result = await evidenceAnchoredGit(workspaceRoot, ["add", "-A", "--", ...stageable], {
287
309
  preflight,
288
310
  });
289
311
  if (result.exitCode !== 0) {
290
- return { staged: 0, error: result.stderr || `git add exit ${result.exitCode}` };
312
+ return { staged: 0, ignored, error: result.stderr || `git add exit ${result.exitCode}` };
291
313
  }
292
- return { staged: movedPaths.length };
314
+ return { staged: stageable.length, ignored };
293
315
  } catch (error) {
294
- return { staged: 0, error: error instanceof Error ? error.message : String(error) };
316
+ return {
317
+ staged: 0,
318
+ ignored: [],
319
+ error: error instanceof Error ? error.message : String(error),
320
+ };
295
321
  } finally {
296
322
  closeEvidenceIndex(preflight);
297
323
  }
@@ -1480,6 +1480,13 @@ export async function createForgeCoreModule(): Promise<ForgeModule> {
1480
1480
  logger.info(` docs.archive: staged ${staged.staged} move path(s) (both sides)`);
1481
1481
  }
1482
1482
  }
1483
+ // F-0004: an ignored move destination never staged — the commit
1484
+ // would carry the source `D` alone and pinned.validate flags it.
1485
+ for (const ignoredPath of staged.ignored) {
1486
+ bookkeepingWarnings.push(
1487
+ `${ignoredPath} is .gitignore'd — the move destination was not staged; commit would carry the source delete alone`,
1488
+ );
1489
+ }
1483
1490
  // RFC-1602 AC-4: MM sweep over the bookkeeping set — staged
1484
1491
  // prune + worktree restore leaves X/Y both non-space residue;
1485
1492
  // surface the exact index→worktree remediation, exit stays 0.
@@ -505,6 +505,31 @@ describe("RFC-1535 stageMovedPairs", () => {
505
505
  expect(status).toMatch(/docs\/rfcs\/archive\/rfc-1\.md/);
506
506
  });
507
507
 
508
+ it("a gitignored move destination surfaces in the ignored diagnostic", async () => {
509
+ const root = mkdtempSync(path.join(tmpdir(), "docs-archive-ignored-"));
510
+ execFileSync("git", ["-C", root, "init", "-q"], { stdio: "pipe" });
511
+ execFileSync("git", ["-C", root, "config", "user.email", "t@t"], { stdio: "pipe" });
512
+ execFileSync("git", ["-C", root, "config", "user.name", "T"], { stdio: "pipe" });
513
+ // F-0004 shape: a consumer's `archive/` ignore rule silently swallows the
514
+ // destination add — the commit would carry the source delete alone.
515
+ writeFileSync(path.join(root, ".gitignore"), "archive/\n");
516
+ mkdirSync(path.join(root, "docs/rfcs"), { recursive: true });
517
+ writeFileSync(path.join(root, "docs/rfcs/rfc-1.md"), "# rfc\n");
518
+ execFileSync("git", ["-C", root, "add", ".", "-f"], { stdio: "pipe" });
519
+ execFileSync("git", ["-C", root, "commit", "-qm", "init"], { stdio: "pipe" });
520
+ mkdirSync(path.join(root, "docs/rfcs/archive"), { recursive: true });
521
+ renameSync(
522
+ path.join(root, "docs/rfcs/rfc-1.md"),
523
+ path.join(root, "docs/rfcs/archive/rfc-1.md"),
524
+ );
525
+ const outcome = await stageMovedPairs({
526
+ movedPaths: ["docs/rfcs/rfc-1.md", "docs/rfcs/archive/rfc-1.md"],
527
+ workspaceRoot: root,
528
+ });
529
+ expect(outcome.error).toBeUndefined();
530
+ expect(outcome.ignored).toEqual(["docs/rfcs/archive/rfc-1.md"]);
531
+ });
532
+
508
533
  it("a non-git tree reports the error without throwing", async () => {
509
534
  const root = mkdtempSync(path.join(tmpdir(), "docs-archive-nogit-"));
510
535
  const outcome = await stageMovedPairs({
@@ -107,11 +107,18 @@ export async function loadPinnedManifest(repoRoot: string): Promise<PinnedManife
107
107
  `pinned.yaml: entry "${entryPath}" must have a non-empty reason string`,
108
108
  );
109
109
  }
110
+ const entryArchive = entry["archive"];
111
+ if (entryArchive !== undefined && typeof entryArchive !== "boolean") {
112
+ throw new PinnedManifestMalformedError(
113
+ `pinned.yaml: entry "${entryPath}" has invalid archive "${String(entryArchive)}" — must be a boolean`,
114
+ );
115
+ }
110
116
 
111
117
  entries.push({
112
118
  path: entryPath,
113
119
  mode: entryMode as PinnedMode,
114
120
  reason: entryReason,
121
+ archive: entryArchive,
115
122
  });
116
123
  }
117
124
 
@@ -178,6 +185,29 @@ export function isIntraDirMove(
178
185
  return false;
179
186
  }
180
187
 
188
+ /**
189
+ * Check whether an archive handler must NOT relocate sourceRel to destRel.
190
+ * Returns the blocking PinnedEntry or null when the move is allowed.
191
+ *
192
+ * Blocked cases:
193
+ * - Source matches a `freeze` entry — freeze means no relocation at all,
194
+ * even inside the pinned directory.
195
+ * - Source matches an entry declared `archive: false` — the consumer's
196
+ * explicit opt-out (F-0004): docs.archive family leaves it alone.
197
+ * - Any pinned source whose destination leaves the same pinned directory
198
+ * (i.e. not an intra-directory move).
199
+ */
200
+ export function isArchiveBlocked(
201
+ manifest: PinnedManifest,
202
+ sourceRel: string,
203
+ destRel: string,
204
+ ): PinnedEntry | null {
205
+ const entry = isPinned(manifest, sourceRel);
206
+ if (!entry) return null;
207
+ if (entry.mode === "freeze" || entry.archive === false) return entry;
208
+ return isIntraDirMove(manifest, sourceRel, destRel) ? null : entry;
209
+ }
210
+
181
211
  /**
182
212
  * Batch-check multiple file paths against the manifest.
183
213
  * Returns violations for files that match a pinned entry.
@@ -21,6 +21,13 @@ export interface PinnedEntry {
21
21
  path: string;
22
22
  mode: PinnedMode;
23
23
  reason: string;
24
+ /**
25
+ * Opt-out for the archive family (docs.archive and the per-domain
26
+ * *.archive handlers): `archive: false` makes those commands skip files
27
+ * under this entry entirely — including the intra-directory moves that
28
+ * `protect` mode otherwise exempts. Absent = archive allowed.
29
+ */
30
+ archive?: boolean;
24
31
  }
25
32
 
26
33
  export interface PinnedManifest {
@@ -58,10 +58,10 @@ const AUDIT_LOG_PATH = path.join(".forge", "pinned-audit.log");
58
58
  */
59
59
  function parseGitNameStatus(
60
60
  output: string,
61
- ): Array<{ relPath: string; operation: PinnedViolation["operation"]; destPath?: string }> {
61
+ ): Array<{ relPath: string; operation: PinnedViolation["operation"] | "add"; destPath?: string }> {
62
62
  const entries: Array<{
63
63
  relPath: string;
64
- operation: PinnedViolation["operation"];
64
+ operation: PinnedViolation["operation"] | "add";
65
65
  destPath?: string;
66
66
  }> = [];
67
67
  const lines = output.trim().split("\n").filter(Boolean);
@@ -78,8 +78,10 @@ function parseGitNameStatus(
78
78
  entries.push({ relPath: oldPath, operation: "delete" });
79
79
  } else if (statusCode.startsWith("R") || statusCode.startsWith("C")) {
80
80
  entries.push({ relPath: oldPath, operation: "move", destPath: newPath });
81
- } else if (statusCode.startsWith("M")) {
81
+ } else if (statusCode.startsWith("M") || statusCode.startsWith("T")) {
82
82
  entries.push({ relPath: oldPath, operation: "modify" });
83
+ } else if (statusCode.startsWith("A")) {
84
+ entries.push({ relPath: oldPath, operation: "add" });
83
85
  }
84
86
  }
85
87
 
@@ -231,9 +233,20 @@ export async function runPinnedValidate(
231
233
 
232
234
  const changedFiles = parseGitNameStatus(diffOutput);
233
235
 
236
+ // Pairing candidates for the D-side of moves git reported as delete+add
237
+ // (rename detection off, similarity under the threshold, or a destination
238
+ // already tracked in HEAD → `D`+`A`/`D`+`M` instead of `R`). Collect every
239
+ // non-delete touched path — an `add` is never a violation itself.
240
+ const nonDeletePaths = changedFiles
241
+ .filter((e) => e.operation !== "delete")
242
+ .flatMap((e) => (e.destPath ? [e.destPath] : [e.relPath]));
243
+
234
244
  // Check each changed file against the manifest
235
245
  const allViolations: PinnedViolation[] = [];
236
246
  for (const { relPath, operation, destPath } of changedFiles) {
247
+ if (operation === "add") {
248
+ continue;
249
+ }
237
250
  if (operation === "move" && destPath) {
238
251
  // Exempt intra-directory moves — the file stays inside the same pinned
239
252
  // dir (e.g. docs.archive moves docs/rfcs/x.md → docs/rfcs/archive/…/x.md).
@@ -261,6 +274,18 @@ export async function runPinnedValidate(
261
274
  if (entry.mode === "protect" && operation === "modify") {
262
275
  continue;
263
276
  }
277
+ if (operation === "delete") {
278
+ // Paired-move exemption: a same-basename add/modify under the same
279
+ // pinned dir means this "delete" is an intra-dir move git did not
280
+ // pair as `R` — apply the same exemption the `R` branch gets.
281
+ const basename = relPath.split("/").pop();
282
+ const isPairedMove = nonDeletePaths.some(
283
+ (p) => p.split("/").pop() === basename && isIntraDirMove(manifest, relPath, p),
284
+ );
285
+ if (isPairedMove) {
286
+ continue;
287
+ }
288
+ }
264
289
  allViolations.push({
265
290
  path: relPath,
266
291
  mode: entry.mode,