@warpgogol/forge 9.6.1 → 9.6.3

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 (74) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/CONTRIBUTING.md +19 -25
  3. package/README.md +42 -18
  4. package/README.uk.md +60 -36
  5. package/dist/os/core/core.module.d.ts.map +1 -1
  6. package/dist/os/core/core.module.js +58 -5
  7. package/dist/os/core/core.module.js.map +1 -1
  8. package/dist/os/core/handlers/package-health.d.ts.map +1 -1
  9. package/dist/os/core/handlers/package-health.js +95 -8
  10. package/dist/os/core/handlers/package-health.js.map +1 -1
  11. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
  12. package/dist/os/flow/handlers/flow-cut.js +27 -6
  13. package/dist/os/flow/handlers/flow-cut.js.map +1 -1
  14. package/dist/src/migration-adapters/ignored-files.d.ts +14 -0
  15. package/dist/src/migration-adapters/ignored-files.d.ts.map +1 -1
  16. package/dist/src/migration-adapters/ignored-files.js +62 -0
  17. package/dist/src/migration-adapters/ignored-files.js.map +1 -1
  18. package/dist/src/migration-adapters/index.d.ts +3 -3
  19. package/dist/src/migration-adapters/index.d.ts.map +1 -1
  20. package/dist/src/migration-adapters/index.js +2 -2
  21. package/dist/src/migration-adapters/index.js.map +1 -1
  22. package/dist/src/migration-adapters/node-typescript-pnpm/index.d.ts.map +1 -1
  23. package/dist/src/migration-adapters/node-typescript-pnpm/index.js +9 -7
  24. package/dist/src/migration-adapters/node-typescript-pnpm/index.js.map +1 -1
  25. package/dist/src/migration-adapters/phaser-pnpm/index.d.ts.map +1 -1
  26. package/dist/src/migration-adapters/phaser-pnpm/index.js +9 -7
  27. package/dist/src/migration-adapters/phaser-pnpm/index.js.map +1 -1
  28. package/dist/src/migration-adapters/types.d.ts +19 -1
  29. package/dist/src/migration-adapters/types.d.ts.map +1 -1
  30. package/dist/src/migration-adapters/types.js +19 -0
  31. package/dist/src/migration-adapters/types.js.map +1 -1
  32. package/dist/src/onboarding/scaffold-project.d.ts.map +1 -1
  33. package/dist/src/onboarding/scaffold-project.js +21 -2
  34. package/dist/src/onboarding/scaffold-project.js.map +1 -1
  35. package/dist/src/validators/skill-doc-sync.d.ts +76 -0
  36. package/dist/src/validators/skill-doc-sync.d.ts.map +1 -0
  37. package/dist/src/validators/skill-doc-sync.js +333 -0
  38. package/dist/src/validators/skill-doc-sync.js.map +1 -0
  39. package/docs/concepts/governance-model.md +9 -1
  40. package/docs/concepts/verification-model.md +31 -0
  41. package/docs/concepts/why-forge.md +1 -1
  42. package/docs/evidence/release-9.6.2.md +31 -0
  43. package/docs/grants/devin-startups.md +25 -0
  44. package/docs/guides/existing-project.md +15 -3
  45. package/docs/guides/skills.md +27 -8
  46. package/docs/guides/upgrading.md +6 -2
  47. package/docs/guides/verification-and-evidence.md +45 -0
  48. package/docs/integrations/devin.md +63 -0
  49. package/docs/reference/cli.md +13 -2
  50. package/docs/reference/fleet-measurement.md +52 -0
  51. package/docs/reference/forge-yaml.md +1 -1
  52. package/docs/reference/programmatic-api.md +62 -33
  53. package/os/core/core.module.ts +70 -11
  54. package/os/core/handlers/package-health.test.ts +104 -23
  55. package/os/core/handlers/package-health.ts +133 -19
  56. package/os/flow/handlers/flow-cut.ts +27 -6
  57. package/os/flow/tests/flow-cut.rerun.test.ts +54 -4
  58. package/package.json +3 -2
  59. package/profiles/forge-shell.yaml +1 -0
  60. package/profiles/godot-game.yaml +1 -0
  61. package/profiles/phaser-game.yaml +1 -0
  62. package/profiles/site-workshop.yaml +1 -0
  63. package/profiles/system.yaml +1 -0
  64. package/profiles/typescript.yaml +1 -0
  65. package/skills/meta/forge-bootstrap/SKILL.md +18 -12
  66. package/src/migration-adapters/ignored-files.ts +64 -0
  67. package/src/migration-adapters/index.ts +19 -3
  68. package/src/migration-adapters/node-typescript-pnpm/index.ts +21 -5
  69. package/src/migration-adapters/phaser-pnpm/index.ts +21 -5
  70. package/src/migration-adapters/types.ts +36 -1
  71. package/src/onboarding/scaffold-project.ts +19 -2
  72. package/src/tests/migration-adapters.test.ts +73 -5
  73. package/src/tests/skill-doc-sync.test.ts +233 -0
  74. package/src/validators/skill-doc-sync.ts +449 -0
@@ -6,14 +6,24 @@
6
6
  </non-goals>
7
7
  </MODULE_CONTRACT>
8
8
  <CHANGE_SUMMARY>
9
- <item>RFC-1528: extract dry-run regen gate for AC-6 evidence
10
-
11
- shouldRunArchiveRegen makes the report-only contract a tested unit instead of an inline closure check.</item>
12
- <item>RFC-1528: close review findings — manifest-union command inventory for regen/preflight</item>
13
9
  <item>RFC-1528: note moved[] under-count on archiver throw (review F-10)</item>
14
10
  <item>RFC-1528: exclude non-generator commands from docs.archive owner regen (F-0126)</item>
15
11
  <item>RFC-1536: owning-checkout routing, FLOW-OPEN-01 dirty-primary warning, shared governance-id allocation (RFC+ADR)</item>
16
12
  <item>RFC-1535: docs.archive self-stages both sides of every move pair — no half-staged EC-31 pairs (F-0038)</item>
13
+ <item>RFC-1585: review wave — write-path corruptions, --check flag, scaffold hydration
14
+
15
+ Independent fo-review (isolation: subagent) found: empty marker pairs lost
16
+ their open tag on --write, multi-line regions collapsed line numbers, a
17
+ leading fence injected a phantom line, --check was undocumented-undeclared,
18
+ and --write exited 1 on a successful heal. Fixes: open-marker capture,
19
+ newline-preserving placeholder, empty-chunk skip, check flag, healedRegions
20
+ split (write always exits 0), dryRun/io threading, byte-exact inventory
21
+ compare on the prettier-stable canonical form, CHECK-13 delegated through
22
+ commandRegistry/invoke so the registry-integrity scan stays within its
23
+ slice cap (KNOWN_TRUNCATED_SCANS is shrink-only), record-tree exclusions
24
+ extended, two real stale claims corrected, profile templates ship empty
25
+ markers hydrated at scaffold write time. RFC amended to implemented
26
+ grammar/result/exclusions; command moved to commands.added.</item>
17
27
  <history>ADR-0021, RFC-0374, RFC-0521, RFC-0539, RFC-0542, RFC-0543, RFC-0544, RFC-0546, RFC-0640, RFC-0662, RFC-0674, RFC-0678, RFC-0679, RFC-0680, RFC-0711, RFC-0733, RFC-0877, RFC-0940, RFC-1080, RFC-1088, RFC-1089, RFC-1097, RFC-1173, RFC-1230, RFC-1231, RFC-1235, RFC-1248, RFC-1251, RFC-1254, RFC-1255, RFC-1351, RFC-1354, RFC-1360, RFC-1366, RFC-1461, RFC-1500, RFC-1505, RFC-1508, RFC-1517, RFC-1518, RFC-1522, RFC-1528</history>
18
28
  </CHANGE_SUMMARY>
19
29
  */
@@ -41,6 +51,7 @@ import { resolveOwningCheckout } from "../flow/session-checkout.ts";
41
51
  export async function createForgeCoreModule(): Promise<ForgeModule> {
42
52
  const { runScaffold } = await import("../../src/onboarding/scaffold.ts");
43
53
  const { runSkillValidate } = await import("../../src/validators/skill-validate.ts");
54
+ const { runSkillDocSync } = await import("../../src/validators/skill-doc-sync.ts");
44
55
  const { runPortValidate } = await import("../../src/validators/port-validate.ts");
45
56
  const { runDoctor } = await import("../../src/onboarding/doctor.ts");
46
57
  const { runAgentsGenerate } = await import("../../src/onboarding/agents-generate.ts");
@@ -121,6 +132,21 @@ export async function createForgeCoreModule(): Promise<ForgeModule> {
121
132
  };
122
133
  };
123
134
 
135
+ const skillDocSyncWrapper = async (
136
+ input: ForgeCommandInput,
137
+ context: ForgeRuntimeContext,
138
+ ): Promise<ForgeCommandResult> => {
139
+ const result = await runSkillDocSync(input, context);
140
+ return {
141
+ data: result,
142
+ exitCode: result.status === "pass" ? 0 : 1,
143
+ summary:
144
+ result.status === "pass"
145
+ ? `[forge.skill.doc-sync] OK — ${result.filesScanned} files, ${result.markedRegions} marked regions${result.written.length > 0 ? `, rewrote ${result.written.length}` : ""}${result.drift.length > 0 ? `, ${result.drift.length} unhealable claim drift entries` : ""}`
146
+ : `[forge.skill.doc-sync] ${result.drift.length} drift entries — re-render marked regions with --write; stale claim literals need manual fixes`,
147
+ };
148
+ };
149
+
124
150
  const portValidateWrapper = async (
125
151
  input: ForgeCommandInput,
126
152
  context: ForgeRuntimeContext,
@@ -299,6 +325,39 @@ export async function createForgeCoreModule(): Promise<ForgeModule> {
299
325
  reads: ["packages/forge/src/registry.ts"],
300
326
  execute: skillListWrapper,
301
327
  },
328
+ {
329
+ name: "forge.skill.doc-sync",
330
+ mutatesState: true,
331
+ contract: "forge",
332
+ rules: [],
333
+ description:
334
+ "Derive skill counts and inventory tables in docs from FORGE_SKILLS. --write re-renders <!-- forge:skills-* --> regions; default --check fails on marked-region drift and stale skill-count claims.",
335
+ scope: "workspace",
336
+ acceptsAllFlag: false,
337
+ flags: {
338
+ check: {
339
+ kind: "boolean",
340
+ description:
341
+ "Explicit check mode (the default): fail on marked-region drift and stale skill-count claims.",
342
+ },
343
+ write: {
344
+ kind: "boolean",
345
+ description:
346
+ "Re-render marked regions in place; exits 0 and reports claim drift it cannot heal.",
347
+ },
348
+ files: {
349
+ kind: "string",
350
+ description:
351
+ "Comma-separated doc paths (default: README*.md, AGENTS.md, docs/**/*.md minus record trees).",
352
+ },
353
+ root: { kind: "string", description: "Package root to scan (default: workspace root)." },
354
+ },
355
+ reads: ["README*.md", "AGENTS.md", "docs/**/*.md", "src/registry.ts"],
356
+ writes: ["README*.md", "AGENTS.md", "docs/**/*.md"],
357
+ generates: [],
358
+ cacheable: false,
359
+ execute: skillDocSyncWrapper,
360
+ },
302
361
  {
303
362
  name: "forge.port.validate",
304
363
  coverage: "operator" as const,
@@ -1199,9 +1258,8 @@ export async function createForgeCoreModule(): Promise<ForgeModule> {
1199
1258
  let regenSkipped: string[] = [];
1200
1259
  let regenExcluded: Array<{ command: string; reason: string }> = [];
1201
1260
  let regenFailures: Array<{ command: string; error: string }> = [];
1202
- const { shouldRunArchiveRegen, runArchiveRegen, stageMovedPairs } = await import(
1203
- "./archive-regen.ts"
1204
- );
1261
+ const { shouldRunArchiveRegen, runArchiveRegen, stageMovedPairs } =
1262
+ await import("./archive-regen.ts");
1205
1263
  if (shouldRunArchiveRegen(dryRun, totalMoved)) {
1206
1264
  const movedPaths = new Set<string>();
1207
1265
  for (const data of Object.values(results)) {
@@ -1216,7 +1274,10 @@ export async function createForgeCoreModule(): Promise<ForgeModule> {
1216
1274
  }
1217
1275
  }
1218
1276
  }
1219
- const regen = await runArchiveRegen({ movedPaths: [...movedPaths], context: routedContext });
1277
+ const regen = await runArchiveRegen({
1278
+ movedPaths: [...movedPaths],
1279
+ context: routedContext,
1280
+ });
1220
1281
  regenerated = regen.regenerated;
1221
1282
  regenFailures = regen.failures;
1222
1283
  regenSkipped = regen.skipped;
@@ -1274,9 +1335,7 @@ export async function createForgeCoreModule(): Promise<ForgeModule> {
1274
1335
  } else if (staged.staged > 0) {
1275
1336
  stagedMovePairs = staged.staged;
1276
1337
  if (outputFormat === "pretty") {
1277
- logger.info(
1278
- ` docs.archive: staged ${staged.staged} move path(s) (both sides)`,
1279
- );
1338
+ logger.info(` docs.archive: staged ${staged.staged} move path(s) (both sides)`);
1280
1339
  }
1281
1340
  }
1282
1341
  }
@@ -6,7 +6,6 @@
6
6
  </non-goals>
7
7
  </MODULE_CONTRACT>
8
8
  <CHANGE_SUMMARY>
9
- <item>RFC-1517: make pkg-health-10 shipped-set faithful and scan the publish ref</item>
10
9
  <item>RFC-1518: docs-drift gate PKG-HEALTH-11/12 in forge.package.health
11
10
 
12
11
  Live-inventory docs gate: PKG-HEALTH-11 flags registered commands absent
@@ -26,6 +25,20 @@ werkstatt-knowledge CLI surface.</item>
26
25
  <item>ADR-0131: pkg-health-10 suppression on the line above the literal
27
26
 
28
27
  literalEscapesInLine accepts a // pkg-health-10: comment directly above the literal (one-line reach); the publish at-ref scan fetches that line via git show only for candidate lines; bin/cli.ts drops its prettier-ignore lines.</item>
28
+ <item>RFC-1585: review wave — write-path corruptions, --check flag, scaffold hydration
29
+
30
+ Independent fo-review (isolation: subagent) found: empty marker pairs lost
31
+ their open tag on --write, multi-line regions collapsed line numbers, a
32
+ leading fence injected a phantom line, --check was undocumented-undeclared,
33
+ and --write exited 1 on a successful heal. Fixes: open-marker capture,
34
+ newline-preserving placeholder, empty-chunk skip, check flag, healedRegions
35
+ split (write always exits 0), dryRun/io threading, byte-exact inventory
36
+ compare on the prettier-stable canonical form, CHECK-13 delegated through
37
+ commandRegistry/invoke so the registry-integrity scan stays within its
38
+ slice cap (KNOWN_TRUNCATED_SCANS is shrink-only), record-tree exclusions
39
+ extended, two real stale claims corrected, profile templates ship empty
40
+ markers hydrated at scaffold write time. RFC amended to implemented
41
+ grammar/result/exclusions; command moved to commands.added.</item>
29
42
  <history>RFC-1311, RFC-1517</history>
30
43
  </CHANGE_SUMMARY>
31
44
  */
@@ -35,11 +48,7 @@ import { join } from "node:path";
35
48
  import { writeFileSync, mkdirSync, rmSync } from "node:fs";
36
49
  import { tmpdir } from "node:os";
37
50
  import type { ForgeCommandInput, ForgeRuntimeContext } from "../../../src/types.ts";
38
- import {
39
- deriveShippedFiles,
40
- runPackageHealth,
41
- scanFixturePathEscapes,
42
- } from "./package-health.ts";
51
+ import { deriveShippedFiles, runPackageHealth, scanFixturePathEscapes } from "./package-health.ts";
43
52
 
44
53
  function makeContext(workspaceRoot: string): ForgeRuntimeContext {
45
54
  return {
@@ -590,9 +599,7 @@ test("a ../ literal resolving inside the package root is not flagged (AC-4)", as
590
599
  ok: true,
591
600
  detail: "",
592
601
  }));
593
- expect(
594
- result.data?.violations.filter((v) => v.ruleId === "PKG-HEALTH-10"),
595
- ).toHaveLength(0);
602
+ expect(result.data?.violations.filter((v) => v.ruleId === "PKG-HEALTH-10")).toHaveLength(0);
596
603
  });
597
604
 
598
605
  test("scanFixturePathEscapes honors suppression, raw-mode, and per-extension modes", () => {
@@ -674,21 +681,53 @@ test("handles no packages/ directory gracefully", async () => {
674
681
  // RFC-1518: docs drift gate — PKG-HEALTH-11 coverage + PKG-HEALTH-12 dead refs
675
682
  // ---------------------------------------------------------------------------
676
683
 
677
- function makeRegistryContext(workspaceRoot: string, commands: { name: string; module: string }[]): ForgeRuntimeContext {
684
+ function makeRegistryContext(
685
+ workspaceRoot: string,
686
+ commands: { name: string; module: string }[],
687
+ ): ForgeRuntimeContext {
678
688
  return {
679
689
  ...makeContext(workspaceRoot),
680
690
  commandRegistry: {
681
691
  listCommandNames: () => commands.map((c) => c.name),
682
- listCommands: () => commands.map((c) => ({ name: c.name, module: c.module, provider: "workspace" as const, description: "", scope: "workspace" as const })),
683
- getCommand: () => undefined,
692
+ listCommands: () =>
693
+ commands.map((c) => ({
694
+ name: c.name,
695
+ module: c.module,
696
+ provider: "workspace" as const,
697
+ description: "",
698
+ scope: "workspace" as const,
699
+ })),
700
+ // RFC-1585: package.health delegates CHECK-13 through the registry —
701
+ // resolve the real sibling handler so the positive control exercises
702
+ // the same in-process execution path production does.
703
+ getCommand: (name) =>
704
+ name === "forge.skill.doc-sync"
705
+ ? {
706
+ name,
707
+ description: "test stub — delegates to the real doc-sync runner",
708
+ scope: "workspace" as const,
709
+ execute: async (input, context) => {
710
+ const { runSkillDocSync } =
711
+ await import("../../../src/validators/skill-doc-sync.ts");
712
+ const r = await runSkillDocSync(input, context);
713
+ return { data: r, exitCode: r.status === "pass" ? 0 : 1 };
714
+ },
715
+ }
716
+ : undefined,
684
717
  },
685
718
  };
686
719
  }
687
720
 
688
- function seedDocsPkg(opts: { name?: string; docs?: Record<string, string>; readme?: string; agents?: string } = {}) {
721
+ function seedDocsPkg(
722
+ opts: { name?: string; docs?: Record<string, string>; readme?: string; agents?: string } = {},
723
+ ) {
689
724
  const pkgDir = join(tmpDir, "packages", "lib");
690
725
  mkdirSync(join(pkgDir, "docs", "reference"), { recursive: true });
691
- writePkgJson(pkgDir, { name: opts.name ?? "@warpgogol/lib", version: "1.0.0", engines: { node: ">=20" } });
726
+ writePkgJson(pkgDir, {
727
+ name: opts.name ?? "@warpgogol/lib",
728
+ version: "1.0.0",
729
+ engines: { node: ">=20" },
730
+ });
692
731
  for (const [rel, content] of Object.entries(opts.docs ?? {})) {
693
732
  const abs = join(pkgDir, "docs", rel);
694
733
  mkdirSync(join(abs, ".."), { recursive: true });
@@ -722,7 +761,8 @@ test("PKG-HEALTH-11: a registered command absent from the docs surface errors na
722
761
  test("PKG-HEALTH-12: a doc token resolving to no registered command errors at doc:line; versions and config paths stay silent (AC-3)", async () => {
723
762
  seedDocsPkg({
724
763
  docs: {
725
- "guide.md": "# Guide\n\nRun `lib.retired` first, then check `9.1.0` and `extract.config.yaml`.\n",
764
+ "guide.md":
765
+ "# Guide\n\nRun `lib.retired` first, then check `9.1.0` and `extract.config.yaml`.\n",
726
766
  },
727
767
  });
728
768
  const ctx = makeRegistryContext(tmpDir, [{ name: "lib.alpha", module: "lib-mod" }]);
@@ -757,7 +797,10 @@ test("pkg-health-11/pkg-health-12 markers skip the line and journal the suppress
757
797
 
758
798
  test("excluded surfaces (CHANGELOG, generated, audit archive) are never scanned (AC-5)", async () => {
759
799
  const pkgDir = seedDocsPkg({ docs: {} });
760
- writeFileSync(join(pkgDir, "CHANGELOG.md"), "# Changes\n\n## [9.9.9]\n\n- mentions `lib.retired`\n");
800
+ writeFileSync(
801
+ join(pkgDir, "CHANGELOG.md"),
802
+ "# Changes\n\n## [9.9.9]\n\n- mentions `lib.retired`\n",
803
+ );
761
804
  mkdirSync(join(pkgDir, "docs", "audits", "archive"), { recursive: true });
762
805
  writeFileSync(join(pkgDir, "docs", "audits", "archive", "old.md"), "`lib.retired` history\n");
763
806
  writeFileSync(join(pkgDir, "docs", "status.generated.md"), "`lib.retired` generated\n");
@@ -767,6 +810,20 @@ test("excluded surfaces (CHANGELOG, generated, audit archive) are never scanned
767
810
  expect(v12).toHaveLength(0);
768
811
  });
769
812
 
813
+ test("PKG-HEALTH-13: a stale skill-count claim in package docs errors; correct claims pass (RFC-1585)", async () => {
814
+ seedDocsPkg({
815
+ docs: {
816
+ "reference/cli.md": "# CLI\n\n`lib.alpha` does a thing.\n\nForge ships 999 skills.\n",
817
+ },
818
+ });
819
+ const ctx = makeRegistryContext(tmpDir, [{ name: "lib.alpha", module: "lib-mod" }]);
820
+ const result = await runPackageHealth(makeInput(), ctx, () => ({ ok: true, detail: "" }));
821
+ const v13 = result.data?.violations.filter((v) => v.ruleId === "PKG-HEALTH-13") ?? [];
822
+ expect(v13).toHaveLength(1);
823
+ expect(v13[0]?.message).toContain("docs/reference/cli.md");
824
+ expect(v13[0]?.message).toContain("999 skills");
825
+ });
826
+
770
827
  // r1 review fixes: manifest/registry merge, private-package semantics,
771
828
  // unquoted module-map keys, suppression journal shape.
772
829
 
@@ -782,7 +839,14 @@ test("registry entry without module preserves manifest module provenance (r1)",
782
839
  ...makeContext(tmpDir),
783
840
  commandRegistry: {
784
841
  listCommandNames: () => ["lib.alpha"],
785
- listCommands: () => [{ name: "lib.alpha", provider: "workspace" as const, description: "", scope: "workspace" as const }],
842
+ listCommands: () => [
843
+ {
844
+ name: "lib.alpha",
845
+ provider: "workspace" as const,
846
+ description: "",
847
+ scope: "workspace" as const,
848
+ },
849
+ ],
786
850
  getCommand: () => undefined,
787
851
  },
788
852
  };
@@ -801,8 +865,14 @@ test("private package docs: PKG-HEALTH-12 still fires, PKG-HEALTH-11 stays silen
801
865
  writeFileSync(join(pkgDir, "docs", "notes.md"), "run `lib.retired` first\n");
802
866
  const ctx = makeRegistryContext(tmpDir, [{ name: "lib.alpha", module: "lib-mod" }]);
803
867
  const result = await runPackageHealth(makeInput(), ctx, () => ({ ok: true, detail: "" }));
804
- const v11 = result.data?.violations.filter((v) => v.ruleId === "PKG-HEALTH-11" && v.packageName === "@warpgogol/priv") ?? [];
805
- const v12 = result.data?.violations.filter((v) => v.ruleId === "PKG-HEALTH-12" && v.packageName === "@warpgogol/priv") ?? [];
868
+ const v11 =
869
+ result.data?.violations.filter(
870
+ (v) => v.ruleId === "PKG-HEALTH-11" && v.packageName === "@warpgogol/priv",
871
+ ) ?? [];
872
+ const v12 =
873
+ result.data?.violations.filter(
874
+ (v) => v.ruleId === "PKG-HEALTH-12" && v.packageName === "@warpgogol/priv",
875
+ ) ?? [];
806
876
  expect(v11).toHaveLength(0);
807
877
  expect(v12).toHaveLength(1);
808
878
  expect(v12[0]?.message).toContain("lib.retired");
@@ -822,7 +892,10 @@ test("unquoted module-map keys attribute modules to packages (r1)", async () =>
822
892
  join(tmpDir, "docs", "command-manifest.generated.yaml"),
823
893
  "commands:\n - name: lib.alpha\n module: lib-mod\n",
824
894
  );
825
- const result = await runPackageHealth(makeInput(), makeContext(tmpDir), () => ({ ok: true, detail: "" }));
895
+ const result = await runPackageHealth(makeInput(), makeContext(tmpDir), () => ({
896
+ ok: true,
897
+ detail: "",
898
+ }));
826
899
  const v11 = result.data?.violations.filter((v) => v.ruleId === "PKG-HEALTH-11") ?? [];
827
900
  expect(v11).toHaveLength(1);
828
901
  expect(v11[0]?.packageName).toBe("@warpgogol/lib");
@@ -865,10 +938,17 @@ test("siteScope commands resolve via the SITE map; workspace commands via WORKSH
865
938
  join(tmpDir, "docs", "command-manifest.generated.yaml"),
866
939
  "commands:\n - name: deploy.artifact.build\n module: deploy\n siteScope: false\n - name: client.export\n module: deploy\n siteScope: true\n",
867
940
  );
868
- const result = await runPackageHealth(makeInput(), makeContext(tmpDir), () => ({ ok: true, detail: "" }));
941
+ const result = await runPackageHealth(makeInput(), makeContext(tmpDir), () => ({
942
+ ok: true,
943
+ detail: "",
944
+ }));
869
945
  const v11 = result.data?.violations.filter((v) => v.ruleId === "PKG-HEALTH-11") ?? [];
870
946
  // Workshop deploy.artifact.build attributes to @warpgogol/lib and is uncovered.
871
- expect(v11.some((v) => v.packageName === "@warpgogol/lib" && v.message.includes("deploy.artifact.build"))).toBe(true);
947
+ expect(
948
+ v11.some(
949
+ (v) => v.packageName === "@warpgogol/lib" && v.message.includes("deploy.artifact.build"),
950
+ ),
951
+ ).toBe(true);
872
952
  // Site-scope client.export attributes to the private sitepkg — never to lib.
873
953
  expect(v11.some((v) => v.message.includes("client.export"))).toBe(false);
874
954
  });
@@ -936,7 +1016,8 @@ test("suppression journal sorts by package, file, line (r2)", async () => {
936
1016
  seedDocsPkg({
937
1017
  docs: {
938
1018
  "b.md": "`lib.gone` <!-- pkg-health-12: removed -->\n",
939
- "a.md": "`lib.dead` <!-- pkg-health-12: removed -->\n`lib.dead2` <!-- pkg-health-12: removed -->\n",
1019
+ "a.md":
1020
+ "`lib.dead` <!-- pkg-health-12: removed -->\n`lib.dead2` <!-- pkg-health-12: removed -->\n",
940
1021
  },
941
1022
  });
942
1023
  const ctx = makeRegistryContext(tmpDir, [{ name: "lib.alpha", module: "lib-mod" }]);
@@ -15,13 +15,26 @@
15
15
  <item>Module attribution is provider-aware: deriveModulePackageMap returns separate workshop/site maps because module names collide across buckets (deploy is engine() AND sitePlugin()), and each command resolves through the map matching its manifest siteScope — a flat last-write-wins map silently misattributed the engine deploy.* family to the private site package (RFC-1518 r2, deviation D-004).</item>
16
16
  </KEY_DECISIONS>
17
17
  <CHANGE_SUMMARY>
18
- <item>RFC-1518: attribution merge, private-package docs gate, suppression journal</item>
19
18
  <item>RFC-1518: key decision for private-package docs-gate scope</item>
20
19
  <item>RFC-1518: provider-aware module attribution, per-rule markers, tld-tail scoping</item>
21
20
  <item>RFC-1518: key decision for provider-aware attribution</item>
22
21
  <item>ADR-0131: pkg-health-10 suppression on the line above the literal
23
22
 
24
23
  literalEscapesInLine accepts a // pkg-health-10: comment directly above the literal (one-line reach); the publish at-ref scan fetches that line via git show only for candidate lines; bin/cli.ts drops its prettier-ignore lines.</item>
24
+ <item>RFC-1585: review wave — write-path corruptions, --check flag, scaffold hydration
25
+
26
+ Independent fo-review (isolation: subagent) found: empty marker pairs lost
27
+ their open tag on --write, multi-line regions collapsed line numbers, a
28
+ leading fence injected a phantom line, --check was undocumented-undeclared,
29
+ and --write exited 1 on a successful heal. Fixes: open-marker capture,
30
+ newline-preserving placeholder, empty-chunk skip, check flag, healedRegions
31
+ split (write always exits 0), dryRun/io threading, byte-exact inventory
32
+ compare on the prettier-stable canonical form, CHECK-13 delegated through
33
+ commandRegistry/invoke so the registry-integrity scan stays within its
34
+ slice cap (KNOWN_TRUNCATED_SCANS is shrink-only), record-tree exclusions
35
+ extended, two real stale claims corrected, profile templates ship empty
36
+ markers hydrated at scaffold write time. RFC amended to implemented
37
+ grammar/result/exclusions; command moved to commands.added.</item>
25
38
  <history>PKG-HEALTH-05, RFC-1097, RFC-1254, RFC-1255, RFC-1517, RFC-1518</history>
26
39
  </CHANGE_SUMMARY>
27
40
  */
@@ -29,6 +42,7 @@ literalEscapesInLine accepts a // pkg-health-10: comment directly above the lite
29
42
  import * as fs from "../../../src/utils/sync-fs.ts";
30
43
  import path from "node:path";
31
44
  import { parse as parseYaml } from "yaml";
45
+ import type { SkillDocDrift } from "../../../src/validators/skill-doc-sync.ts";
32
46
  import type {
33
47
  ForgeCommandInput,
34
48
  ForgeCommandResult,
@@ -92,7 +106,14 @@ export interface HealthScanConfig {
92
106
  }
93
107
 
94
108
  const DEFAULT_KEY_SEGMENTS = [".input/signing-key", ".input/batches"];
95
- const BASE_IGNORE_DIRS = new Set(["node_modules", ".turbo", "dist", ".env", ".DS_Store", "Thumbs.db"]);
109
+ const BASE_IGNORE_DIRS = new Set([
110
+ "node_modules",
111
+ ".turbo",
112
+ "dist",
113
+ ".env",
114
+ ".DS_Store",
115
+ "Thumbs.db",
116
+ ]);
96
117
  const IGNORE_FILES = new Set([
97
118
  ".env",
98
119
  ".env.local",
@@ -348,7 +369,13 @@ export function scanDocsSurface(
348
369
  // (warpgogol.com) or TLD-shaped property paths (context.io); a 3+
349
370
  // segment token under a registered namespace (deploy.smoke.run after
350
371
  // removal) stays a dead-reference candidate — never TLD-exempt.
351
- .filter((t) => !registeredCommands || registeredCommands.has(t) || t.split(".").length > 2 || !DOC_TLD_TAIL_RE.test(t));
372
+ .filter(
373
+ (t) =>
374
+ !registeredCommands ||
375
+ registeredCommands.has(t) ||
376
+ t.split(".").length > 2 ||
377
+ !DOC_TLD_TAIL_RE.test(t),
378
+ );
352
379
  const s11 = line.match(DOC_SUPPRESS_11_RE);
353
380
  const s12 = line.match(DOC_SUPPRESS_12_RE);
354
381
  // A marker with an empty reason does not suppress — an exemption needs
@@ -359,14 +386,26 @@ export function scanDocsSurface(
359
386
  const m12 = s12 ? reason(s12) || null : null;
360
387
  for (const token of tokens) {
361
388
  if (m11) {
362
- const entry = { ruleId: "PKG-HEALTH-11" as const, file: rel, line: i + 1, token, reason: m11 };
389
+ const entry = {
390
+ ruleId: "PKG-HEALTH-11" as const,
391
+ file: rel,
392
+ line: i + 1,
393
+ token,
394
+ reason: m11,
395
+ };
363
396
  suppressed11.set(token, entry);
364
397
  suppressions.push(entry);
365
398
  } else {
366
399
  documented.add(token);
367
400
  }
368
401
  if (m12) {
369
- suppressions.push({ ruleId: "PKG-HEALTH-12", file: rel, line: i + 1, token, reason: m12 });
402
+ suppressions.push({
403
+ ruleId: "PKG-HEALTH-12",
404
+ file: rel,
405
+ line: i + 1,
406
+ token,
407
+ reason: m12,
408
+ });
370
409
  documented.add(token);
371
410
  } else if (!refs.has(token)) {
372
411
  refs.set(token, { file: rel, line: i + 1 });
@@ -386,13 +425,27 @@ export function scanDocsSurface(
386
425
  * buckets (deploy is both engine() and sitePlugin()) and commands attribute
387
426
  * through the map matching their siteScope.
388
427
  */
389
- export function deriveModulePackageMap(workspaceRoot: string): { workshop: Map<string, string>; site: Map<string, string> } {
428
+ export function deriveModulePackageMap(workspaceRoot: string): {
429
+ workshop: Map<string, string>;
430
+ site: Map<string, string>;
431
+ } {
390
432
  const out = new Map<string, string>();
391
433
  const site = new Map<string, string>();
392
- const mmPath = path.join(workspaceRoot, "packages", "werkstatt-engine", "src", "kernel", "module-map.ts");
434
+ const mmPath = path.join(
435
+ workspaceRoot,
436
+ "packages",
437
+ "werkstatt-engine",
438
+ "src",
439
+ "kernel",
440
+ "module-map.ts",
441
+ );
393
442
  try {
394
443
  const mm = fs.readFileSync(mmPath, "utf8");
395
- const bucketToConst: Record<string, string> = { engine: "ENGINE", sitePlugin: "SITE", forge: "FORGE" };
444
+ const bucketToConst: Record<string, string> = {
445
+ engine: "ENGINE",
446
+ sitePlugin: "SITE",
447
+ forge: "FORGE",
448
+ };
396
449
  const constToSpec: Record<string, string> = {};
397
450
  for (const m of mm.matchAll(/const (\w+) = "(@warpgogol\/[^"]+)"/g)) constToSpec[m[1]!] = m[2]!;
398
451
  for (const m of mm.matchAll(/["']?([\w-]+)["']?:\s*(engine|sitePlugin|forge)\(/g)) {
@@ -407,7 +460,9 @@ export function deriveModulePackageMap(workspaceRoot: string): { workshop: Map<s
407
460
  const kcPath = path.join(workspaceRoot, "tools", "kernel.config.ts");
408
461
  try {
409
462
  const kc = fs.readFileSync(kcPath, "utf8");
410
- for (const m of kc.matchAll(/["']?(\w[\w-]*)["']?:\s*async[^=]*=>[^;]*?import\("(@warpgogol\/[^"]+)"/g)) {
463
+ for (const m of kc.matchAll(
464
+ /["']?(\w[\w-]*)["']?:\s*async[^=]*=>[^;]*?import\("(@warpgogol\/[^"]+)"/g,
465
+ )) {
411
466
  out.set(m[1]!, `packages/${m[2]!.split("/")[1]}`);
412
467
  }
413
468
  } catch {
@@ -426,14 +481,21 @@ export function deriveModulePackageMap(workspaceRoot: string): { workshop: Map<s
426
481
  */
427
482
  export function loadCommandInventory(
428
483
  workspaceRoot: string,
429
- commandRegistry?: { listCommands(): Array<{ name: string; module?: string; siteScope?: boolean }> },
484
+ commandRegistry?: {
485
+ listCommands(): Array<{ name: string; module?: string; siteScope?: boolean }>;
486
+ },
430
487
  ): Array<{ name: string; module?: string; siteScope?: boolean }> {
431
488
  const byName = new Map<string, { name: string; module?: string; siteScope?: boolean }>();
432
489
  const manifestPath = path.join(workspaceRoot, "docs", "command-manifest.generated.yaml");
433
490
  try {
434
491
  const raw = fs.readFileSync(manifestPath, "utf8");
435
492
  const parsed = parseYaml(raw) as {
436
- commands?: Array<{ name?: unknown; module?: unknown; siteScope?: unknown; providers?: unknown }>;
493
+ commands?: Array<{
494
+ name?: unknown;
495
+ module?: unknown;
496
+ siteScope?: unknown;
497
+ providers?: unknown;
498
+ }>;
437
499
  } | null;
438
500
  for (const c of parsed?.commands ?? []) {
439
501
  if (typeof c.name === "string" && c.name.length > 0) {
@@ -492,10 +554,7 @@ export function isShippedEntry(
492
554
  * repo-extract's `cp` filter; a realpath-set bounds link cycles. Never a
493
555
  * hand-maintained file list.
494
556
  */
495
- export function deriveShippedFiles(
496
- projectRoot: string,
497
- extractConfigRaw: string | null,
498
- ): string[] {
557
+ export function deriveShippedFiles(projectRoot: string, extractConfigRaw: string | null): string[] {
499
558
  const cfg = parseHealthScanConfig(extractConfigRaw);
500
559
  const root = path.resolve(projectRoot);
501
560
  const shipped: string[] = [];
@@ -766,7 +825,9 @@ export async function runPackageHealth(
766
825
  (pkgCommands.get(pkg) ?? pkgCommands.set(pkg, []).get(pkg)!).push(c.name);
767
826
  }
768
827
 
769
- const entries = fs.readdirSync(packagesDir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
828
+ const entries = fs
829
+ .readdirSync(packagesDir, { withFileTypes: true })
830
+ .sort((a, b) => a.name.localeCompare(b.name));
770
831
  for (const entry of entries) {
771
832
  if (!entry.isDirectory()) continue;
772
833
  if (entry.name.startsWith(".")) continue;
@@ -822,6 +883,54 @@ export async function runPackageHealth(
822
883
  }
823
884
  }
824
885
 
886
+ // RFC-1585 CHECK 13 — skill-count claims and <!-- forge:skills-* -->
887
+ // marked regions drifted from FORGE_SKILLS. Runs outside the command-
888
+ // inventory gate: the lint needs no command list. Delegated through the
889
+ // registry (standalone CLI) or the invoke port (kernel host — `werkstatt
890
+ // run` injects no commandRegistry) so the child is judged by its own
891
+ // declaration; an in-handler descent into the doc-sync subtree truncates
892
+ // the registry-integrity scan.
893
+ {
894
+ const docSyncCmd = context.commandRegistry?.getCommand("forge.skill.doc-sync");
895
+ let docSync: { drift?: SkillDocDrift[] } | undefined;
896
+ if (docSyncCmd) {
897
+ const r = await docSyncCmd.execute(
898
+ { argv: [], flags: { check: true, root: pkgDir } },
899
+ context,
900
+ );
901
+ docSync = r?.data as { drift?: SkillDocDrift[] } | undefined;
902
+ } else if (context.invoke) {
903
+ const r = await context.invoke("forge.skill.doc-sync", {
904
+ check: true,
905
+ root: pkgDir,
906
+ });
907
+ docSync = r.data as { drift?: SkillDocDrift[] } | undefined;
908
+ } else {
909
+ violations.push({
910
+ ruleId: "PKG-HEALTH-13",
911
+ packageName,
912
+ severity: "warning",
913
+ message: "skill doc-sync check skipped — no commandRegistry or invoke port in this host",
914
+ file: pkgDir,
915
+ fixHint:
916
+ "Run `forge skill.doc-sync --check` directly, or dispatch through a host that exposes the command.",
917
+ });
918
+ }
919
+ for (const d of docSync?.drift ?? []) {
920
+ violations.push({
921
+ ruleId: "PKG-HEALTH-13",
922
+ packageName,
923
+ severity: "error",
924
+ message: `${d.file}:${d.line} ${d.kind} — found "${d.found}", registry renders "${d.expected}"`,
925
+ file: path.join(pkgDir, d.file),
926
+ fixHint:
927
+ d.kind === "marked-region"
928
+ ? `Run "forge skill.doc-sync --write" to re-render the marked region.`
929
+ : `Fix the literal to the registry count, or journal a same-line "<!-- forge-skill-count:ok: <reason> -->" exemption.`,
930
+ });
931
+ }
932
+ }
933
+
825
934
  if (isPrivate) continue;
826
935
 
827
936
  packagesChecked++;
@@ -1044,7 +1153,10 @@ export async function runPackageHealth(
1044
1153
  }
1045
1154
 
1046
1155
  suppressions.sort(
1047
- (a, b) => (a.packageName ?? "").localeCompare(b.packageName ?? "") || a.file.localeCompare(b.file) || a.line - b.line,
1156
+ (a, b) =>
1157
+ (a.packageName ?? "").localeCompare(b.packageName ?? "") ||
1158
+ a.file.localeCompare(b.file) ||
1159
+ a.line - b.line,
1048
1160
  );
1049
1161
  if (packagesChecked > 0 && commandInfos.length === 0) {
1050
1162
  violations.push({
@@ -1054,7 +1166,8 @@ export async function runPackageHealth(
1054
1166
  message:
1055
1167
  "no command inventory available — docs-drift gate skipped (context.commandRegistry unset and docs/command-manifest.generated.yaml absent or unparsable)",
1056
1168
  file: workspaceRoot,
1057
- fixHint: "Run `werkstatt run command.manifest.generate`, or dispatch through a host that injects commandRegistry.",
1169
+ fixHint:
1170
+ "Run `werkstatt run command.manifest.generate`, or dispatch through a host that injects commandRegistry.",
1058
1171
  });
1059
1172
  } else if (packagesChecked > 0 && commandInfos.length > 0 && attributed === 0) {
1060
1173
  // Inventory exists but no command resolved to a package — module→package
@@ -1066,7 +1179,8 @@ export async function runPackageHealth(
1066
1179
  severity: "warning",
1067
1180
  message: `${commandInfos.length} inventoried command(s) resolved to no package — module attribution unavailable, PKG-HEALTH-11 coverage skipped`,
1068
1181
  file: workspaceRoot,
1069
- fixHint: "Check that packages/werkstatt-engine/src/kernel/module-map.ts or tools/kernel.config.ts declares the command modules.",
1182
+ fixHint:
1183
+ "Check that packages/werkstatt-engine/src/kernel/module-map.ts or tools/kernel.config.ts declares the command modules.",
1070
1184
  });
1071
1185
  }
1072
1186