@warpgogol/forge 2.8.0 → 2.8.2

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 (271) hide show
  1. package/AGENTS.md +1 -1
  2. package/README.md +23 -13
  3. package/README.uk.md +19 -12
  4. package/dist/os/session/handlers/validate.d.ts.map +1 -1
  5. package/dist/os/session/handlers/validate.js +23 -1
  6. package/dist/os/session/handlers/validate.js.map +1 -1
  7. package/dist/os/session/types.d.ts +31 -1
  8. package/dist/os/session/types.d.ts.map +1 -1
  9. package/dist/os/session/types.js +7 -0
  10. package/dist/os/session/types.js.map +1 -1
  11. package/os/adr/adr.module.ts +158 -0
  12. package/os/adr/frontmatter-io.ts +80 -0
  13. package/os/adr/handlers/archive.ts +244 -0
  14. package/os/adr/handlers/implement-stamp.ts +331 -0
  15. package/os/adr/handlers/list-create.ts +207 -0
  16. package/os/adr/handlers/validate.test.ts +232 -0
  17. package/os/adr/handlers/validate.ts +429 -0
  18. package/os/adr/index.ts +33 -0
  19. package/os/adr/types.ts +141 -0
  20. package/os/audit/audit.module.ts +48 -0
  21. package/os/audit/frontmatter-io.ts +84 -0
  22. package/os/audit/handlers/archive.ts +239 -0
  23. package/os/audit/index.ts +23 -0
  24. package/os/audit/types.ts +29 -0
  25. package/os/compass/compass.module.ts +186 -0
  26. package/os/compass/handlers/compass-audit-handler.ts +382 -0
  27. package/os/compass/handlers/compass-change-summary-handler.ts +272 -0
  28. package/os/compass/handlers/compass-inventory-handler.ts +294 -0
  29. package/os/compass/handlers/compass-inventory.ts +521 -0
  30. package/os/compass/handlers/git-revision.ts +137 -0
  31. package/os/compass/handlers/resolve-scan-root-workpiece.test.ts +65 -0
  32. package/os/compass/handlers/resolve-scan-root.ts +79 -0
  33. package/os/compass/index.ts +33 -0
  34. package/os/core/core.module.ts +948 -0
  35. package/os/core/handlers/assets-check.ts +122 -0
  36. package/os/core/handlers/assets-helpers.ts +174 -0
  37. package/os/core/handlers/assets-list.ts +99 -0
  38. package/os/core/handlers/build.ts +155 -0
  39. package/os/core/handlers/determinism-check.ts +354 -0
  40. package/os/core/handlers/dev.ts +127 -0
  41. package/os/core/handlers/invariant-engine.test.ts +681 -0
  42. package/os/core/handlers/knowledge-compact.ts +248 -0
  43. package/os/core/handlers/lifecycle-handlers.test.ts +524 -0
  44. package/os/core/handlers/note-frontmatter-validate.test.ts +93 -0
  45. package/os/core/handlers/note-link-validate.test.ts +117 -0
  46. package/os/core/handlers/note-orphan-detect.test.ts +94 -0
  47. package/os/core/handlers/package-health.test.ts +226 -0
  48. package/os/core/handlers/package-health.ts +231 -0
  49. package/os/core/handlers/pinned-check.ts +200 -0
  50. package/os/core/handlers/pinned-init.ts +333 -0
  51. package/os/core/handlers/pinned-types.ts +50 -0
  52. package/os/core/handlers/pinned-validate.ts +301 -0
  53. package/os/core/handlers/profile-resolve.ts +92 -0
  54. package/os/core/handlers/release-prepare.ts +294 -0
  55. package/os/core/handlers/release-publish.ts +211 -0
  56. package/os/core/handlers/validate.ts +262 -0
  57. package/os/core/handlers/workspace-deps.ts +55 -0
  58. package/os/core/index.ts +13 -0
  59. package/os/exploration/exploration.module.ts +90 -0
  60. package/os/exploration/frontmatter-io.ts +77 -0
  61. package/os/exploration/handlers/archive.ts +159 -0
  62. package/os/exploration/handlers/list.ts +77 -0
  63. package/os/exploration/handlers/show.ts +107 -0
  64. package/os/exploration/index.ts +25 -0
  65. package/os/exploration/types.ts +65 -0
  66. package/os/mission/handlers/archive.test.ts +391 -0
  67. package/os/mission/handlers/archive.ts +453 -0
  68. package/os/mission/index.ts +1 -0
  69. package/os/mission/mission.module.ts +48 -0
  70. package/os/mission/types.ts +41 -0
  71. package/os/naming/index.ts +14 -0
  72. package/os/naming/naming-convention.test.ts +163 -0
  73. package/os/naming/naming-convention.ts +378 -0
  74. package/os/naming/naming.module.ts +36 -0
  75. package/os/notes/index.ts +10 -0
  76. package/os/notes/notes.module.ts +109 -0
  77. package/os/plan/frontmatter-io.ts +82 -0
  78. package/os/plan/handlers/archive.ts +238 -0
  79. package/os/plan/index.ts +23 -0
  80. package/os/plan/plan.module.ts +48 -0
  81. package/os/plan/types.ts +29 -0
  82. package/os/program/discovery.ts +294 -0
  83. package/os/program/handlers/complete.ts +419 -0
  84. package/os/program/handlers/lease.ts +433 -0
  85. package/os/program/handlers/seal.ts +332 -0
  86. package/os/program/handlers/validate.ts +213 -0
  87. package/os/program/lease.ts +156 -0
  88. package/os/program/program.module.ts +212 -0
  89. package/os/program/schemas.ts +218 -0
  90. package/os/program/state.ts +264 -0
  91. package/os/rfc/acceptance.ts +344 -0
  92. package/os/rfc/decision-log.ts +310 -0
  93. package/os/rfc/dna-trace.ts +280 -0
  94. package/os/rfc/frontmatter-io.test.ts +132 -0
  95. package/os/rfc/frontmatter-io.ts +130 -0
  96. package/os/rfc/handlers/archive.ts +300 -0
  97. package/os/rfc/handlers/check.ts +238 -0
  98. package/os/rfc/handlers/implement-stamp.ts +515 -0
  99. package/os/rfc/handlers/index-graph.ts +237 -0
  100. package/os/rfc/handlers/lifecycle.test.ts +127 -0
  101. package/os/rfc/handlers/lifecycle.ts +249 -0
  102. package/os/rfc/handlers/list-create.ts +296 -0
  103. package/os/rfc/handlers/pipeline-status.ts +173 -0
  104. package/os/rfc/handlers/shared.ts +121 -0
  105. package/os/rfc/handlers/supersede-propose.ts +241 -0
  106. package/os/rfc/handlers/validate-rules.test.ts +891 -0
  107. package/os/rfc/handlers/validate-rules.ts +984 -0
  108. package/os/rfc/handlers/validate.ts +166 -0
  109. package/os/rfc/handlers.ts +19 -0
  110. package/os/rfc/index.ts +97 -0
  111. package/os/rfc/rfc.module.ts +416 -0
  112. package/os/rfc/types.ts +596 -0
  113. package/os/rfc/verification-evidence.ts +244 -0
  114. package/os/session/atif-parser.ts +166 -0
  115. package/os/session/frontmatter-io.ts +163 -0
  116. package/os/session/handlers/archive.ts +288 -0
  117. package/os/session/handlers/list.ts +174 -0
  118. package/os/session/handlers/save.ts +348 -0
  119. package/os/session/handlers/validate.ts +250 -0
  120. package/os/session/index.ts +50 -0
  121. package/os/session/session.module.ts +126 -0
  122. package/os/session/types.ts +203 -0
  123. package/os/spec/live-spec-list-show-validate.test.ts +257 -0
  124. package/os/spec/live-spec-list.ts +78 -0
  125. package/os/spec/live-spec-merge.test.ts +261 -0
  126. package/os/spec/live-spec-merge.ts +413 -0
  127. package/os/spec/live-spec-show.ts +117 -0
  128. package/os/spec/live-spec-types.ts +93 -0
  129. package/os/spec/live-spec-validate.ts +170 -0
  130. package/os/spec/spec-materialize.ts +390 -0
  131. package/os/spec/spec-schema.ts +174 -0
  132. package/os/spec/spec-status.ts +284 -0
  133. package/os/spec/spec-validate.ts +513 -0
  134. package/os/spec/spec.module.ts +135 -0
  135. package/os/werkstatt/handlers/lock.ts +168 -0
  136. package/os/werkstatt/handlers/schema.ts +47 -0
  137. package/os/werkstatt/handlers/werkstatt-lock-recover.ts +175 -0
  138. package/os/werkstatt/handlers/werkstatt-lock-status.ts +73 -0
  139. package/os/werkstatt/handlers/werkstatt-operation-validate.ts +104 -0
  140. package/os/werkstatt/index.ts +39 -0
  141. package/os/werkstatt/werkstatt.module.ts +62 -0
  142. package/os/workflow/handlers.ts +304 -0
  143. package/os/workflow/index.ts +28 -0
  144. package/os/workflow/types.ts +99 -0
  145. package/os/workflow/workflow.module.ts +54 -0
  146. package/package.json +3 -3
  147. package/profiles/godot-csharp.yaml +4 -4
  148. package/profiles/knowledge-typescript-turborepo.yaml +110 -0
  149. package/profiles/phaser-turborepo.yaml +5 -5
  150. package/skills/_shared/fo-session-summary.md +132 -16
  151. package/skills/fo/fo-add-tests/pbt-guide.md +13 -13
  152. package/skills/fo/fo-doc-audit/SKILL.md +6 -6
  153. package/skills/fo/fo-handoff/SKILL.md +5 -0
  154. package/skills/fo/fo-idea/SKILL.md +1 -1
  155. package/skills/fo/fo-review/SKILL.md +1 -1
  156. package/skills/fo/fo-session-retro/SKILL.md +8 -0
  157. package/skills/fo/fo-session-save/SKILL.md +8 -0
  158. package/src/cli-output.ts +59 -0
  159. package/src/config/__tests__/resolve-terminology.test.ts +45 -0
  160. package/src/config/forge-config.ts +524 -0
  161. package/src/forge-module.ts +39 -0
  162. package/src/index.ts +172 -0
  163. package/src/knowledge/__tests__/promote.test.ts +219 -0
  164. package/src/knowledge/__tests__/serialize.test.ts +192 -0
  165. package/src/knowledge/budgets.ts +202 -0
  166. package/src/knowledge/compact.ts +405 -0
  167. package/src/knowledge/index.ts +53 -0
  168. package/src/knowledge/parse.ts +227 -0
  169. package/src/knowledge/promote.ts +156 -0
  170. package/src/knowledge/schema.ts +112 -0
  171. package/src/knowledge/serialize.ts +72 -0
  172. package/src/migration-adapters/__tests__/ignored-files.test.ts +51 -0
  173. package/src/migration-adapters/__tests__/registry.test.ts +131 -0
  174. package/src/migration-adapters/__tests__/types.test.ts +86 -0
  175. package/src/migration-adapters/git-utils.ts +71 -0
  176. package/src/migration-adapters/ignored-files.ts +221 -0
  177. package/src/migration-adapters/index.ts +21 -0
  178. package/src/migration-adapters/node-typescript-pnpm/index.ts +189 -0
  179. package/src/migration-adapters/phaser-pnpm/index.ts +189 -0
  180. package/src/migration-adapters/registry.ts +61 -0
  181. package/src/migration-adapters/types.ts +68 -0
  182. package/src/onboarding/__tests__/workspace-discovery.test.ts +134 -0
  183. package/src/onboarding/agents-generate.ts +443 -0
  184. package/src/onboarding/create.ts +427 -0
  185. package/src/onboarding/doctor.ts +1297 -0
  186. package/src/onboarding/init.ts +337 -0
  187. package/src/onboarding/invariant-engine.ts +448 -0
  188. package/src/onboarding/memory-scaffold.ts +189 -0
  189. package/src/onboarding/nested-agents-generate.ts +93 -0
  190. package/src/onboarding/nested-agents-templates.ts +233 -0
  191. package/src/onboarding/profile-validate.ts +139 -0
  192. package/src/onboarding/scaffold-project.ts +299 -0
  193. package/src/onboarding/scaffold.ts +143 -0
  194. package/src/onboarding/upgrade.ts +558 -0
  195. package/src/onboarding/workspace-discovery.ts +167 -0
  196. package/src/profiles/__tests__/profile-schema.test.ts +228 -0
  197. package/src/profiles/__tests__/stack-profile.test.ts +190 -0
  198. package/src/profiles/__tests__/terminology-utils.test.ts +71 -0
  199. package/src/profiles/profile-schema.ts +350 -0
  200. package/src/profiles/stack-profile.ts +188 -0
  201. package/src/profiles/terminology-utils.ts +36 -0
  202. package/src/registry.ts +185 -0
  203. package/src/skill-schema.ts +37 -0
  204. package/src/tests/acceptance-criteria.test.ts +99 -0
  205. package/src/tests/adr-implement-stamp.test.ts +368 -0
  206. package/src/tests/agents-generate-domain.test.ts +317 -0
  207. package/src/tests/agents-generate.test.ts +458 -0
  208. package/src/tests/bindings-schema.test.ts +314 -0
  209. package/src/tests/budgets.test.ts +213 -0
  210. package/src/tests/cli-output.test.ts +196 -0
  211. package/src/tests/compact.test.ts +796 -0
  212. package/src/tests/create.test.ts +289 -0
  213. package/src/tests/doctor-autonomy.test.ts +98 -0
  214. package/src/tests/doctor-bindings.test.ts +286 -0
  215. package/src/tests/doctor-domain.test.ts +113 -0
  216. package/src/tests/exploration-handlers.test.ts +256 -0
  217. package/src/tests/fixtures/agents-generate-business-before.txt +288 -0
  218. package/src/tests/forge-config.test.ts +420 -0
  219. package/src/tests/fs-atomic.test.ts +96 -0
  220. package/src/tests/fs.test.ts +103 -0
  221. package/src/tests/generated-marker.test.ts +161 -0
  222. package/src/tests/hash.test.ts +37 -0
  223. package/src/tests/implement-stamp.test.ts +505 -0
  224. package/src/tests/init-bindings.test.ts +183 -0
  225. package/src/tests/knowledge-parse.test.ts +307 -0
  226. package/src/tests/knowledge-pbt.test.ts +164 -0
  227. package/src/tests/memory-scaffold.test.ts +192 -0
  228. package/src/tests/migration-adapters.test.ts +480 -0
  229. package/src/tests/package-files.test.ts +54 -0
  230. package/src/tests/pinned-check.test.ts +194 -0
  231. package/src/tests/pinned-init.test.ts +126 -0
  232. package/src/tests/profile-schema.test.ts +194 -0
  233. package/src/tests/profile-validate.test.ts +120 -0
  234. package/src/tests/program-lease.test.ts +245 -0
  235. package/src/tests/program-paths-extended.test.ts +117 -0
  236. package/src/tests/program-paths.test.ts +98 -0
  237. package/src/tests/program-property.test.ts +139 -0
  238. package/src/tests/program-schemas.test.ts +445 -0
  239. package/src/tests/program-spec-node.test.ts +250 -0
  240. package/src/tests/promote.test.ts +481 -0
  241. package/src/tests/registry.test.ts +73 -0
  242. package/src/tests/scaffold-project.test.ts +150 -0
  243. package/src/tests/session-handlers.test.ts +503 -0
  244. package/src/tests/session-pbt.test.ts +190 -0
  245. package/src/tests/skill-schema.test.ts +146 -0
  246. package/src/tests/skill-validate-knowledge.test.ts +26 -0
  247. package/src/tests/skill-validate.test.ts +254 -0
  248. package/src/tests/stack-profile.test.ts +221 -0
  249. package/src/tests/string-utils.test.ts +42 -0
  250. package/src/tests/upgrade.test.ts +428 -0
  251. package/src/tests/werkstatt-lock.test.ts +343 -0
  252. package/src/tests/workspace-discovery-domain.test.ts +112 -0
  253. package/src/tests/workspace-discovery.test.ts +135 -0
  254. package/src/types.ts +221 -0
  255. package/src/utils/__tests__/fs-idempotent.test.ts +73 -0
  256. package/src/utils/__tests__/fs-trash.test.ts +45 -0
  257. package/src/utils/fs-atomic.ts +93 -0
  258. package/src/utils/fs-idempotent.ts +41 -0
  259. package/src/utils/fs-trash-sync.ts +37 -0
  260. package/src/utils/fs-trash.ts +24 -0
  261. package/src/utils/fs.ts +74 -0
  262. package/src/utils/generated-marker.ts +166 -0
  263. package/src/utils/hash.ts +19 -0
  264. package/src/utils/index.ts +29 -0
  265. package/src/utils/string-utils.ts +19 -0
  266. package/src/validators/__tests__/note-orphan-detect.test.ts +94 -0
  267. package/src/validators/note-frontmatter-validate.ts +142 -0
  268. package/src/validators/note-link-validate.ts +145 -0
  269. package/src/validators/note-orphan-detect.ts +146 -0
  270. package/src/validators/port-validate.ts +97 -0
  271. package/src/validators/skill-validate.ts +831 -0
@@ -0,0 +1,831 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>forge.skill.validate — validates all forge skills and declared pack skills against frontmatter contract and invariants SKILL-01..SKILL-21.</purpose>
4
+ <non-goals>
5
+ <item>Do not validate third-party skills — only forge-managed skills in packages/forge/skills/ and declared pack skills.</item>
6
+ </non-goals>
7
+ </MODULE_CONTRACT>
8
+ <CHANGE_SUMMARY>
9
+ <item>RFC-0374: initial forge.skill.validate handler.</item>
10
+ <item>RFC-0393: added SKILL-11 — canonical skill bodies must not contain hardcoded project-specific literals.</item>
11
+ <item>RFC-0523: added SKILL-12 — concerns must be one of four-level enum. Updated SKILL-10 to cover read-only skills.</item>
12
+ <item>RFC-0524: added SKILL-13 — declared knowledge files must exist relative to SKILL.md directory.</item>
13
+ <item>RFC-0539: added SKILL-14 (pack skill name must start with pack prefix) and SKILL-15 (non-forge skill may not use fo- prefix). Extended SKILL-07 with asymmetric dependency direction (forge→pack forbidden). Added pack skill validation loop.</item>
14
+ <item>RFC-0548: added SKILL-16 — triggers field must be an array of 1-5 strings, each 5-100 characters, only allowed on fo-category skills.</item>
15
+ <item>RFC-0553: added SKILL-17 — skill files must not contain specific platform RFC/ADR ids (RFC-\\d{4}, ADR-\\d{4}) or platform names (Warpgogol, WarpGogol).</item>
16
+ <item>RFC-0642: added SKILL-18 — forge skill instruction lines must not reference software-specific binding keys (typecheck, scopedBuild, test); use semantic keys (validate, produce, verify) instead.</item>
17
+ <item>RFC-0660: added SKILL-19 (knowledge entry schema validity) and SKILL-20 (entry identifier uniqueness) for structured knowledge files.</item>
18
+ <item>RFC-0661: added SKILL-21 (knowledge layer token budget warnings), refactored warning handling — warnings go to separate `warnings` array, not `violations`.</item>
19
+ <item>2026-08-03: SKILL-17 WarpGogol brand pattern made case-sensitive — the /gi flag defeated the first pattern's @-lookbehind and false-flagged every `@warpgogol/<pkg>` npm-scope reference.</item>
20
+ </CHANGE_SUMMARY>
21
+ */
22
+
23
+ import fs from "node:fs";
24
+ import path from "node:path";
25
+ import { parse as parseYaml } from "yaml";
26
+ import { skillFrontmatterSchema } from "../skill-schema.ts";
27
+ import { FORGE_SKILLS, discoverPackSkills, type PackSkillEntry } from "../registry.ts";
28
+ import { loadForgeConfig, resolveForgeRoot } from "../config/forge-config.ts";
29
+ import { parseKnowledgeFile } from "../knowledge/index.ts";
30
+ import type { ParsedKnowledgeFile } from "../knowledge/index.ts";
31
+ import {
32
+ computeLayerBudgets,
33
+ resolveKnowledgeBudgets,
34
+ type KnowledgeBudgets,
35
+ } from "../knowledge/budgets.ts";
36
+
37
+ interface Violation {
38
+ skill: string;
39
+ rule: string;
40
+ message: string;
41
+ pack?: string;
42
+ file?: string;
43
+ line?: number;
44
+ severity?: "error" | "warning";
45
+ fixHint?: string;
46
+ }
47
+
48
+ interface Warning {
49
+ skill: string;
50
+ rule: string;
51
+ message: string;
52
+ severity: "warning";
53
+ pack?: string;
54
+ file?: string;
55
+ layer?: string;
56
+ fixHint?: string;
57
+ }
58
+
59
+ interface SkillValidateResult {
60
+ command: string;
61
+ status: "pass" | "fail";
62
+ violations: Violation[];
63
+ warnings: Warning[];
64
+ }
65
+
66
+ const PREFERENCES_PATTERN = /Read `PREFERENCES\.md`/i;
67
+
68
+ export function runSkillValidate(_input: unknown, context: unknown): SkillValidateResult {
69
+ const ctx = context as { workspaceRoot?: string };
70
+ const workspaceRoot = ctx?.workspaceRoot ?? process.cwd();
71
+ const forgeRoot = path.join(workspaceRoot, "packages", "forge");
72
+ const skillsDir = path.join(forgeRoot, "skills");
73
+
74
+ // RFC-0539: Load config to discover declared skill packs
75
+ let packSkills: PackSkillEntry[] = [];
76
+ try {
77
+ const forgeConfigRoot = resolveForgeRoot(workspaceRoot);
78
+ const config = loadForgeConfig(forgeConfigRoot);
79
+ packSkills = discoverPackSkills(workspaceRoot, config);
80
+ } catch {
81
+ // Config not found or invalid — skip pack skill validation
82
+ }
83
+
84
+ // Build known names set for SKILL-07: forge skills + pack skills
85
+ const forgeSkillNames = new Set(FORGE_SKILLS.map((s) => s.name));
86
+ const packSkillNames = new Set(packSkills.map((s) => s.name));
87
+
88
+ const violations: Violation[] = [];
89
+ const warnings: Warning[] = [];
90
+
91
+ // RFC-0661: resolve effective knowledge budgets from forge.yaml
92
+ const budgets = resolveKnowledgeBudgets(workspaceRoot);
93
+
94
+ for (const entry of FORGE_SKILLS) {
95
+ const skillPath = path.join(forgeRoot, entry.path);
96
+ const skillDir = path.dirname(skillPath);
97
+
98
+ // SKILL-02: name matches directory name
99
+ if (path.basename(skillDir) !== entry.name) {
100
+ violations.push({
101
+ skill: entry.name,
102
+ rule: "SKILL-02",
103
+ message: `Directory name "${path.basename(skillDir)}" does not match skill name "${entry.name}"`,
104
+ });
105
+ }
106
+
107
+ if (!fs.existsSync(skillPath)) {
108
+ violations.push({
109
+ skill: entry.name,
110
+ rule: "SKILL-01",
111
+ message: `SKILL.md not found at ${entry.path}`,
112
+ });
113
+ continue;
114
+ }
115
+
116
+ const content = fs.readFileSync(skillPath, "utf8");
117
+ const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
118
+ if (!fmMatch) {
119
+ violations.push({
120
+ skill: entry.name,
121
+ rule: "SKILL-01",
122
+ message: "No frontmatter block found",
123
+ });
124
+ continue;
125
+ }
126
+
127
+ let fm: Record<string, unknown>;
128
+ try {
129
+ fm = parseYaml(fmMatch[1]) as Record<string, unknown>;
130
+ } catch {
131
+ violations.push({
132
+ skill: entry.name,
133
+ rule: "SKILL-01",
134
+ message: "Frontmatter is not valid YAML",
135
+ });
136
+ continue;
137
+ }
138
+
139
+ // SKILL-01: Frontmatter parses against Zod schema
140
+ // SKILL-12: concerns must be one of the four-level enum (RFC-0523)
141
+ const parsed = skillFrontmatterSchema.safeParse(fm);
142
+ if (!parsed.success) {
143
+ for (const issue of parsed.error.issues) {
144
+ const isConcernsIssue = issue.path.join(".") === "concerns";
145
+ violations.push({
146
+ skill: entry.name,
147
+ rule: isConcernsIssue ? "SKILL-12" : "SKILL-01",
148
+ message: `${issue.path.join(".")}: ${issue.message}`,
149
+ });
150
+ }
151
+ continue;
152
+ }
153
+
154
+ // SKILL-02: name matches directory name (already checked above, also check frontmatter)
155
+ if (parsed.data.name !== entry.name) {
156
+ violations.push({
157
+ skill: entry.name,
158
+ rule: "SKILL-02",
159
+ message: `Frontmatter name "${parsed.data.name}" does not match registry name "${entry.name}"`,
160
+ });
161
+ }
162
+
163
+ // SKILL-03: description present and ≤ 200 chars (enforced by Zod)
164
+ // SKILL-04: invocation is user|model (enforced by Zod)
165
+ // SKILL-05: category is fo|shared|meta (enforced by Zod)
166
+ // SKILL-06: concerns is read-only|document-only|content-mutation|code-mutation (enforced by Zod)
167
+ // SKILL-08: languagePolicy is ref(PREFERENCES.md) (enforced by Zod)
168
+
169
+ // SKILL-07: dependsOn entries correspond to existing skill names
170
+ // RFC-0539: Asymmetric dependency direction — forge skills may only depend on
171
+ // other forge skills (forge→pack is forbidden — breaks portability).
172
+ for (const dep of parsed.data.dependsOn) {
173
+ if (!forgeSkillNames.has(dep)) {
174
+ violations.push({
175
+ skill: entry.name,
176
+ rule: "SKILL-07",
177
+ message: `dependsOn references non-existent forge skill '${dep}'`,
178
+ });
179
+ }
180
+ }
181
+
182
+ // SKILL-09: Body contains standardized "Read PREFERENCES.md…" instruction
183
+ const body = content.slice(fmMatch[0].length);
184
+ if (!PREFERENCES_PATTERN.test(body)) {
185
+ violations.push({
186
+ skill: entry.name,
187
+ rule: "SKILL-09",
188
+ message: 'Body does not contain the standardized "Read PREFERENCES.md…" instruction',
189
+ });
190
+ }
191
+
192
+ // SKILL-10: read-only and document-only skills do not contain code execution instructions.
193
+ // NOTE: `exec` is excluded from the pattern because `pnpm exec werkstatt run …`
194
+ // is the standard governance command invocation in this ecosystem, not a code
195
+ // build/install. The pattern catches `pnpm run build`, `pnpm install`, `npm run
196
+ // test`, `npx vitest run`, `tsc --noEmit` (via `tsc` + `run`), etc.
197
+ if (parsed.data.concerns === "read-only" || parsed.data.concerns === "document-only") {
198
+ const execPattern = /\b(pnpm|npm|npx|node|vitest|tsc)\s+(run|install|build)/gi;
199
+ execPattern.lastIndex = 0;
200
+ if (execPattern.test(body)) {
201
+ violations.push({
202
+ skill: entry.name,
203
+ rule: "SKILL-10",
204
+ message: `${parsed.data.concerns} skill contains code execution instructions`,
205
+ });
206
+ }
207
+ }
208
+
209
+ // SKILL-11: Canonical skill bodies must not contain hardcoded project-specific
210
+ // literals in instruction lines (code blocks and "run:" directives).
211
+ // Scans only imperative instruction lines, not narrative prose.
212
+ // Supports <!-- skill-lint-disable SKILL-11 --> escape hatch.
213
+ {
214
+ const skill11Violations = checkSkill11(entry.name, body);
215
+ violations.push(...skill11Violations);
216
+ }
217
+
218
+ // SKILL-18: Forge skill instruction lines must not reference software-specific
219
+ // binding keys (typecheck, scopedBuild, test). Use semantic keys instead
220
+ // (validate, produce, verify). Same scope as SKILL-11 (code blocks + run: directives).
221
+ // Supports <!-- skill-lint-disable SKILL-18 --> escape hatch.
222
+ // Forge-skill path only — pack skills are domain-specific by design.
223
+ {
224
+ const skill18Violations = checkSkill18(entry.name, body);
225
+ violations.push(...skill18Violations);
226
+ }
227
+
228
+ // SKILL-13: Declared knowledge files must exist relative to SKILL.md directory (RFC-0524)
229
+ // SKILL-19/SKILL-20: Knowledge entry schema and identifier uniqueness (RFC-0660)
230
+ // SKILL-21: Knowledge layer token budget warnings (RFC-0661)
231
+ if (parsed.data.knowledge) {
232
+ const parsedFiles: ParsedKnowledgeFile[] = [];
233
+ for (const knowledgeFile of parsed.data.knowledge) {
234
+ const knowledgePath = path.join(skillDir, knowledgeFile);
235
+ if (!fs.existsSync(knowledgePath)) {
236
+ violations.push({
237
+ skill: entry.name,
238
+ rule: "SKILL-13",
239
+ message: `Declared knowledge file '${knowledgeFile}' not found relative to SKILL.md directory`,
240
+ });
241
+ } else {
242
+ const { errors, warnings: skillWarnings } = checkSkill19And20(
243
+ entry.name,
244
+ knowledgeFile,
245
+ knowledgePath,
246
+ );
247
+ violations.push(...errors);
248
+ warnings.push(...skillWarnings);
249
+ // Collect parsed files for SKILL-21 batch budget check
250
+ parsedFiles.push(parseKnowledgeFile(knowledgePath));
251
+ }
252
+ }
253
+ // SKILL-21: Check hot/warm layer budgets
254
+ warnings.push(...checkSkill21Budgets(parsedFiles, budgets, entry.name));
255
+ }
256
+
257
+ // SKILL-16: triggers field format and category restriction (RFC-0548)
258
+ if (parsed.data.triggers) {
259
+ if (entry.category !== "fo") {
260
+ violations.push({
261
+ skill: entry.name,
262
+ rule: "SKILL-16",
263
+ message: `triggers field is only allowed on fo-category skills (got '${entry.category}') — intent-to-skill routing is for fo-skills only`,
264
+ });
265
+ }
266
+ for (const trigger of parsed.data.triggers) {
267
+ if (trigger.length < 5 || trigger.length > 100) {
268
+ violations.push({
269
+ skill: entry.name,
270
+ rule: "SKILL-16",
271
+ message: `triggers entry '${trigger.slice(0, 50)}' must be 5-100 characters (got ${trigger.length})`,
272
+ });
273
+ }
274
+ }
275
+ if (parsed.data.triggers.length > 5) {
276
+ violations.push({
277
+ skill: entry.name,
278
+ rule: "SKILL-16",
279
+ message: `triggers array must have at most 5 entries (got ${parsed.data.triggers.length})`,
280
+ });
281
+ }
282
+ }
283
+
284
+ // SKILL-17: No internal platform RFC/ADR id references or platform names (RFC-0553)
285
+ {
286
+ const skill17Violations = checkSkill17(entry.name, content);
287
+ violations.push(...skill17Violations);
288
+ }
289
+ }
290
+
291
+ // RFC-0539: Validate pack skills
292
+ for (const entry of packSkills) {
293
+ const skillPath = path.join(workspaceRoot, entry.dir, entry.path);
294
+ const skillDir = path.dirname(skillPath);
295
+
296
+ // SKILL-02: name matches directory name
297
+ if (path.basename(skillDir) !== entry.name) {
298
+ violations.push({
299
+ skill: entry.name,
300
+ pack: entry.pack,
301
+ rule: "SKILL-02",
302
+ message: `Directory name "${path.basename(skillDir)}" does not match skill name "${entry.name}"`,
303
+ });
304
+ }
305
+
306
+ if (!fs.existsSync(skillPath)) {
307
+ violations.push({
308
+ skill: entry.name,
309
+ pack: entry.pack,
310
+ rule: "SKILL-01",
311
+ message: `SKILL.md not found at ${entry.dir}/${entry.path}`,
312
+ });
313
+ continue;
314
+ }
315
+
316
+ const content = fs.readFileSync(skillPath, "utf8");
317
+ const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
318
+ if (!fmMatch) {
319
+ violations.push({
320
+ skill: entry.name,
321
+ pack: entry.pack,
322
+ rule: "SKILL-01",
323
+ message: "No frontmatter block found",
324
+ });
325
+ continue;
326
+ }
327
+
328
+ let fm: Record<string, unknown>;
329
+ try {
330
+ fm = parseYaml(fmMatch[1]) as Record<string, unknown>;
331
+ } catch {
332
+ violations.push({
333
+ skill: entry.name,
334
+ pack: entry.pack,
335
+ rule: "SKILL-01",
336
+ message: "Frontmatter is not valid YAML",
337
+ });
338
+ continue;
339
+ }
340
+
341
+ const parsed = skillFrontmatterSchema.safeParse(fm);
342
+ if (!parsed.success) {
343
+ for (const issue of parsed.error.issues) {
344
+ const isConcernsIssue = issue.path.join(".") === "concerns";
345
+ violations.push({
346
+ skill: entry.name,
347
+ pack: entry.pack,
348
+ rule: isConcernsIssue ? "SKILL-12" : "SKILL-01",
349
+ message: `${issue.path.join(".")}: ${issue.message}`,
350
+ });
351
+ }
352
+ continue;
353
+ }
354
+
355
+ // SKILL-02: name matches frontmatter
356
+ if (parsed.data.name !== entry.name) {
357
+ violations.push({
358
+ skill: entry.name,
359
+ pack: entry.pack,
360
+ rule: "SKILL-02",
361
+ message: `Frontmatter name "${parsed.data.name}" does not match directory name "${entry.name}"`,
362
+ });
363
+ }
364
+
365
+ // SKILL-07: dependsOn entries — pack skills may depend on forge skills or other pack skills
366
+ for (const dep of parsed.data.dependsOn) {
367
+ if (!forgeSkillNames.has(dep) && !packSkillNames.has(dep)) {
368
+ violations.push({
369
+ skill: entry.name,
370
+ pack: entry.pack,
371
+ rule: "SKILL-07",
372
+ message: `dependsOn references non-existent skill '${dep}'`,
373
+ });
374
+ }
375
+ }
376
+
377
+ // SKILL-09: Body contains standardized "Read PREFERENCES.md…" instruction
378
+ const body = content.slice(fmMatch[0].length);
379
+ if (!PREFERENCES_PATTERN.test(body)) {
380
+ violations.push({
381
+ skill: entry.name,
382
+ pack: entry.pack,
383
+ rule: "SKILL-09",
384
+ message: 'Body does not contain the standardized "Read PREFERENCES.md…" instruction',
385
+ });
386
+ }
387
+
388
+ // SKILL-10: read-only and document-only skills do not contain code execution instructions
389
+ if (parsed.data.concerns === "read-only" || parsed.data.concerns === "document-only") {
390
+ const execPattern = /\b(pnpm|npm|npx|node|vitest|tsc)\s+(run|install|build)/gi;
391
+ execPattern.lastIndex = 0;
392
+ if (execPattern.test(body)) {
393
+ violations.push({
394
+ skill: entry.name,
395
+ pack: entry.pack,
396
+ rule: "SKILL-10",
397
+ message: `${parsed.data.concerns} skill contains code execution instructions`,
398
+ });
399
+ }
400
+ }
401
+
402
+ // SKILL-11: No hardcoded project-specific literals in canonical skill bodies
403
+ {
404
+ const skill11Violations = checkSkill11(entry.name, body);
405
+ for (const v of skill11Violations) {
406
+ v.pack = entry.pack;
407
+ }
408
+ violations.push(...skill11Violations);
409
+ }
410
+
411
+ // SKILL-13: Declared knowledge files must exist
412
+ // SKILL-19/SKILL-20: Knowledge entry schema and identifier uniqueness (RFC-0660)
413
+ // SKILL-21: Knowledge layer token budget warnings (RFC-0661)
414
+ if (parsed.data.knowledge) {
415
+ const parsedFiles: ParsedKnowledgeFile[] = [];
416
+ for (const knowledgeFile of parsed.data.knowledge) {
417
+ const knowledgePath = path.join(skillDir, knowledgeFile);
418
+ if (!fs.existsSync(knowledgePath)) {
419
+ violations.push({
420
+ skill: entry.name,
421
+ pack: entry.pack,
422
+ rule: "SKILL-13",
423
+ message: `Declared knowledge file '${knowledgeFile}' not found relative to SKILL.md directory`,
424
+ });
425
+ } else {
426
+ const { errors, warnings: skillWarnings } = checkSkill19And20(
427
+ entry.name,
428
+ knowledgeFile,
429
+ knowledgePath,
430
+ entry.pack,
431
+ );
432
+ violations.push(...errors);
433
+ warnings.push(...skillWarnings);
434
+ parsedFiles.push(parseKnowledgeFile(knowledgePath));
435
+ }
436
+ }
437
+ // SKILL-21: Check hot/warm layer budgets for pack skills
438
+ warnings.push(...checkSkill21Budgets(parsedFiles, budgets, entry.name, entry.pack));
439
+ }
440
+
441
+ // SKILL-16: triggers field format (RFC-0548) — pack skills may not use triggers
442
+ if (parsed.data.triggers) {
443
+ violations.push({
444
+ skill: entry.name,
445
+ pack: entry.pack,
446
+ rule: "SKILL-16",
447
+ message:
448
+ "triggers field is only allowed on forge fo-category skills — pack skills may not declare triggers",
449
+ });
450
+ }
451
+
452
+ // SKILL-14: Pack skill name must start with its pack prefix (RFC-0539)
453
+ if (!entry.name.startsWith(`${entry.pack}-`)) {
454
+ violations.push({
455
+ skill: entry.name,
456
+ pack: entry.pack,
457
+ rule: "SKILL-14",
458
+ message: `Pack skill name must start with pack prefix '${entry.pack}-'`,
459
+ });
460
+ }
461
+
462
+ // SKILL-15: Non-forge skill may not use the 'fo-' prefix (RFC-0539)
463
+ if (entry.name.startsWith("fo-")) {
464
+ violations.push({
465
+ skill: entry.name,
466
+ pack: entry.pack,
467
+ rule: "SKILL-15",
468
+ message: "Non-forge skill may not use the 'fo-' prefix (reserved for forge skills)",
469
+ });
470
+ }
471
+
472
+ // SKILL-17: No internal platform RFC/ADR id references or platform names (RFC-0553)
473
+ {
474
+ const skill17Violations = checkSkill17(entry.name, content);
475
+ for (const v of skill17Violations) {
476
+ v.pack = entry.pack;
477
+ }
478
+ violations.push(...skill17Violations);
479
+ }
480
+ }
481
+
482
+ // Check: every SKILL.md on disk has a registry entry
483
+ if (fs.existsSync(skillsDir)) {
484
+ scanForOrphanSkills(skillsDir, new Set(FORGE_SKILLS.map((s) => s.path)), forgeRoot, violations);
485
+ }
486
+
487
+ return {
488
+ command: "forge.skill.validate",
489
+ status: violations.length === 0 ? "pass" : "fail",
490
+ violations,
491
+ warnings,
492
+ };
493
+ }
494
+
495
+ // ---------------------------------------------------------------------------
496
+ // SKILL-11: No hardcoded project-specific literals in canonical skill bodies
497
+ // ---------------------------------------------------------------------------
498
+
499
+ const SKILL11_PATTERNS: RegExp[] = [
500
+ /pnpm\s+exec\s+werkstatt\s+run/gi,
501
+ /docs\/architecture-dna\.md/gi,
502
+ ];
503
+
504
+ const SKILL11_DISABLE_MARKER = "<!-- skill-lint-disable SKILL-11 -->";
505
+
506
+ function checkSkill11(skillName: string, body: string): Violation[] {
507
+ const result: Violation[] = [];
508
+
509
+ // If the entire file has the disable marker, skip all SKILL-11 checks
510
+ if (body.includes(SKILL11_DISABLE_MARKER)) {
511
+ return result;
512
+ }
513
+
514
+ // Extract instruction lines: lines inside code blocks (``` ... ```)
515
+ // and lines starting with "run:" directives
516
+ const instructionLines = extractInstructionLines(body);
517
+
518
+ for (const line of instructionLines) {
519
+ // Check for per-line disable marker
520
+ if (line.includes(SKILL11_DISABLE_MARKER)) {
521
+ continue;
522
+ }
523
+
524
+ for (const pattern of SKILL11_PATTERNS) {
525
+ const re = new RegExp(pattern.source, pattern.flags);
526
+ if (re.test(line)) {
527
+ result.push({
528
+ skill: skillName,
529
+ rule: "SKILL-11",
530
+ message: `Instruction line contains hardcoded project-specific literal: ${line.trim().slice(0, 100)}`,
531
+ });
532
+ break; // one violation per line
533
+ }
534
+ }
535
+ }
536
+
537
+ return result;
538
+ }
539
+
540
+ // ---------------------------------------------------------------------------
541
+ // SKILL-18: No software-specific binding keys in forge skill instruction lines (RFC-0642)
542
+ // ---------------------------------------------------------------------------
543
+
544
+ const SKILL18_PATTERNS: RegExp[] = [
545
+ /bindings\.commands\.typecheck/gi,
546
+ /bindings\.commands\.scopedBuild/gi,
547
+ /bindings\.commands\.test/gi,
548
+ ];
549
+
550
+ const SKILL18_DISABLE_MARKER = "<!-- skill-lint-disable SKILL-18 -->";
551
+
552
+ function checkSkill18(skillName: string, body: string): Violation[] {
553
+ const result: Violation[] = [];
554
+
555
+ if (body.includes(SKILL18_DISABLE_MARKER)) {
556
+ return result;
557
+ }
558
+
559
+ const instructionLines = extractInstructionLines(body);
560
+
561
+ for (const line of instructionLines) {
562
+ if (line.includes(SKILL18_DISABLE_MARKER)) {
563
+ continue;
564
+ }
565
+
566
+ for (const pattern of SKILL18_PATTERNS) {
567
+ const re = new RegExp(pattern.source, pattern.flags);
568
+ const match = re.exec(line);
569
+ if (match) {
570
+ result.push({
571
+ skill: skillName,
572
+ rule: "SKILL-18",
573
+ message: `Instruction line references software-specific binding key '${match[0]}' — use semantic key instead`,
574
+ });
575
+ break;
576
+ }
577
+ }
578
+ }
579
+
580
+ return result;
581
+ }
582
+
583
+ function extractInstructionLines(body: string): string[] {
584
+ const lines: string[] = [];
585
+ const bodyLines = body.split(/\r?\n/);
586
+ let inCodeBlock = false;
587
+
588
+ for (const line of bodyLines) {
589
+ if (line.trim().startsWith("```")) {
590
+ inCodeBlock = !inCodeBlock;
591
+ continue;
592
+ }
593
+
594
+ if (inCodeBlock) {
595
+ lines.push(line);
596
+ } else if (/^\s*run:/i.test(line)) {
597
+ lines.push(line);
598
+ }
599
+ }
600
+
601
+ return lines;
602
+ }
603
+
604
+ // ---------------------------------------------------------------------------
605
+ // SKILL-17: No internal platform RFC/ADR/DNA id references or platform names (RFC-0553)
606
+ // ---------------------------------------------------------------------------
607
+
608
+ const SKILL17_ID_PATTERNS: RegExp[] = [/\bRFC-\d{4}\b/g, /\bADR-\d{4}\b/g, /\bDNA-\d+\b/g];
609
+
610
+ const SKILL17_PLATFORM_PATTERNS: RegExp[] = [/(?<!@)Warpgogol\b/gi, /\bWarpGogol\b/g];
611
+
612
+ const SKILL17_DISABLE_MARKER = "<!-- skill-lint-disable SKILL-17 -->";
613
+
614
+ function checkSkill17(skillName: string, content: string): Violation[] {
615
+ const result: Violation[] = [];
616
+
617
+ if (content.includes(SKILL17_DISABLE_MARKER)) {
618
+ return result;
619
+ }
620
+
621
+ const lines = content.split(/\r?\n/);
622
+
623
+ for (const line of lines) {
624
+ if (line.includes(SKILL17_DISABLE_MARKER)) {
625
+ continue;
626
+ }
627
+
628
+ for (const pattern of SKILL17_ID_PATTERNS) {
629
+ const re = new RegExp(pattern.source, pattern.flags);
630
+ const match = re.exec(line);
631
+ if (match) {
632
+ result.push({
633
+ skill: skillName,
634
+ rule: "SKILL-17",
635
+ message: `Contains internal platform RFC/ADR/DNA id '${match[0]}': ${line.trim().slice(0, 100)}`,
636
+ });
637
+ break;
638
+ }
639
+ }
640
+
641
+ for (const pattern of SKILL17_PLATFORM_PATTERNS) {
642
+ const re = new RegExp(pattern.source, pattern.flags);
643
+ const match = re.exec(line);
644
+ if (match) {
645
+ result.push({
646
+ skill: skillName,
647
+ rule: "SKILL-17",
648
+ message: `Contains internal platform name '${match[0]}': ${line.trim().slice(0, 100)}`,
649
+ });
650
+ break;
651
+ }
652
+ }
653
+ }
654
+
655
+ return result;
656
+ }
657
+
658
+ interface Skill19And20Result {
659
+ errors: Violation[];
660
+ warnings: Warning[];
661
+ }
662
+
663
+ function checkSkill19And20(
664
+ skillName: string,
665
+ fileName: string,
666
+ filePath: string,
667
+ pack?: string,
668
+ ): Skill19And20Result {
669
+ const errors: Violation[] = [];
670
+ const warnings: Warning[] = [];
671
+ const parsed = parseKnowledgeFile(filePath);
672
+
673
+ // Knowledge-adjacent files are exempt from SKILL-19/SKILL-20
674
+ if (parsed.isKnowledgeAdjacent) {
675
+ return { errors, warnings };
676
+ }
677
+
678
+ // SKILL-19: Entry schema validity (errors)
679
+ for (const issue of parsed.parseIssues) {
680
+ errors.push({
681
+ skill: skillName,
682
+ rule: "SKILL-19",
683
+ file: fileName,
684
+ line: issue.line,
685
+ severity: "error",
686
+ message: issue.message,
687
+ pack,
688
+ });
689
+ }
690
+
691
+ // SKILL-19: Legacy section warnings (migration window) — go to warnings, not errors
692
+ if (parsed.legacySections.length > 0) {
693
+ warnings.push({
694
+ skill: skillName,
695
+ rule: "SKILL-19",
696
+ file: fileName,
697
+ severity: "warning",
698
+ message: `${parsed.legacySections.length} legacy section${parsed.legacySections.length === 1 ? "" : "s"} predate RFC-0660 — run the knowledge compaction command to migrate`,
699
+ pack,
700
+ });
701
+ }
702
+
703
+ // SKILL-20: Identifier uniqueness and reference validity (errors)
704
+ const seenIds = new Map<string, number>(); // id → first line
705
+ for (const entry of parsed.entries) {
706
+ // Check id format
707
+ if (!/^K-\d{4}$/.test(entry.meta.id)) {
708
+ errors.push({
709
+ skill: skillName,
710
+ rule: "SKILL-20",
711
+ file: fileName,
712
+ line: entry.lineStart,
713
+ severity: "error",
714
+ message: `Entry id '${entry.meta.id}' does not match ^K-\d{4}$`,
715
+ pack,
716
+ });
717
+ continue;
718
+ }
719
+
720
+ // Check uniqueness
721
+ if (seenIds.has(entry.meta.id)) {
722
+ errors.push({
723
+ skill: skillName,
724
+ rule: "SKILL-20",
725
+ file: fileName,
726
+ line: entry.lineStart,
727
+ severity: "error",
728
+ message: `Duplicate entry id ${entry.meta.id} (first occurrence at line ${seenIds.get(entry.meta.id)})`,
729
+ pack,
730
+ });
731
+ } else {
732
+ seenIds.set(entry.meta.id, entry.lineStart);
733
+ }
734
+ }
735
+
736
+ // Check supersedes references resolve within the same file
737
+ const entryIds = new Set(parsed.entries.map((e) => e.meta.id));
738
+ for (const entry of parsed.entries) {
739
+ if (entry.meta.supersedes) {
740
+ for (const refId of entry.meta.supersedes) {
741
+ if (!entryIds.has(refId)) {
742
+ errors.push({
743
+ skill: skillName,
744
+ rule: "SKILL-20",
745
+ file: fileName,
746
+ line: entry.lineStart,
747
+ severity: "error",
748
+ message: `Entry ${entry.meta.id}: supersedes reference '${refId}' does not resolve to an entry in the same file`,
749
+ pack,
750
+ });
751
+ }
752
+ }
753
+ }
754
+
755
+ // Check promotedTo format
756
+ if (entry.meta.promotedTo !== null && entry.meta.promotedTo !== undefined) {
757
+ if (!/^shared\/K-\d{4}$/.test(entry.meta.promotedTo)) {
758
+ errors.push({
759
+ skill: skillName,
760
+ rule: "SKILL-20",
761
+ file: fileName,
762
+ line: entry.lineStart,
763
+ severity: "error",
764
+ message: `Entry ${entry.meta.id}: promotedTo '${entry.meta.promotedTo}' does not match ^shared/K-\d{4}$`,
765
+ pack,
766
+ });
767
+ }
768
+ }
769
+ }
770
+
771
+ return { errors, warnings };
772
+ }
773
+
774
+ // ---------------------------------------------------------------------------
775
+ // SKILL-21: Knowledge layer token budget warnings (RFC-0661)
776
+ // ---------------------------------------------------------------------------
777
+
778
+ function checkSkill21Budgets(
779
+ parsedFiles: ParsedKnowledgeFile[],
780
+ budgets: KnowledgeBudgets,
781
+ skillName: string,
782
+ pack?: string,
783
+ ): Warning[] {
784
+ const warnings: Warning[] = [];
785
+ const skillNames = new Map<string, string>();
786
+ for (const pf of parsedFiles) {
787
+ skillNames.set(pf.path, skillName);
788
+ }
789
+ const budgetReports = computeLayerBudgets(parsedFiles, budgets, skillNames);
790
+ for (const report of budgetReports) {
791
+ if (report.exceededBy > 0) {
792
+ const layerName = report.layer === "L2" ? "Hot" : "Warm";
793
+ const pctOver = Math.round((report.exceededBy / report.budget) * 100);
794
+ warnings.push({
795
+ skill: skillName,
796
+ rule: "SKILL-21",
797
+ file: report.file,
798
+ layer: report.layer,
799
+ severity: "warning",
800
+ message: `${layerName} layer exceeds budget: ${report.activeChars} of ${report.budget} characters (${pctOver}% over)`,
801
+ fixHint:
802
+ "Run the knowledge compaction command (RFC-0662) to archive stale entries, or promote duplicated principles to the shared layer (RFC-0663)",
803
+ pack,
804
+ });
805
+ }
806
+ }
807
+ return warnings;
808
+ }
809
+
810
+ function scanForOrphanSkills(
811
+ dir: string,
812
+ knownPaths: Set<string>,
813
+ forgeRoot: string,
814
+ violations: Violation[],
815
+ ): void {
816
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
817
+ for (const entry of entries) {
818
+ if (entry.isDirectory()) {
819
+ scanForOrphanSkills(path.join(dir, entry.name), knownPaths, forgeRoot, violations);
820
+ } else if (entry.name === "SKILL.md") {
821
+ const relPath = path.relative(forgeRoot, path.join(dir, entry.name)).replace(/\\/g, "/");
822
+ if (!knownPaths.has(relPath)) {
823
+ violations.push({
824
+ skill: path.basename(dir),
825
+ rule: "SKILL-01",
826
+ message: `SKILL.md at ${relPath} has no registry entry`,
827
+ });
828
+ }
829
+ }
830
+ }
831
+ }