@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
@@ -0,0 +1,449 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ RFC-1585: derive skill counts/inventory in docs from FORGE_SKILLS instead of
5
+ hand-maintained literals. `--write` re-renders marked regions
6
+ (`<!-- forge:skills-count -->` / `<!-- forge:skills-inventory -->`) in place;
7
+ `--check` (default) fails on marked-region drift and on skill-count claims
8
+ outside markers that contradict the registry.
9
+ </purpose>
10
+ <non-goals>
11
+ <item>Does not rewrite prose outside marked regions — claim drift is reported, never auto-fixed.</item>
12
+ <item>Does not count project skill packs (RFC-0539) — the rendered registry is FORGE_SKILLS; pack-specific count claims carry an exemption marker.</item>
13
+ </non-goals>
14
+ <KEY_DECISIONS>
15
+ <item>Paired open/close HTML markers (forge:custom discipline, RFC-1153) — content between markers is generated, everything outside is authored.</item>
16
+ <item>Claim grammar is intentionally narrow (three literal forms) — ambiguous prose is never flagged; authors exempt intentional claims with a same-line `<!-- forge-skill-count:ok: <reason> -->` marker.</item>
17
+ <item>Historical record trees (rfcs/adrs/audits/reviews/plans/queues, changelogs, generated docs) are excluded from the claim lint — dated statements quote the registry of their day.</item>
18
+ </KEY_DECISIONS>
19
+ <CHANGE_SUMMARY>
20
+ <item>RFC-1585: initial implementation — markers, render, drift check, claim lint, doc surface discovery.</item>
21
+ <item>RFC-1585: review wave — write-path corruptions, --check flag, scaffold hydration
22
+
23
+ Independent fo-review (isolation: subagent) found: empty marker pairs lost
24
+ their open tag on --write, multi-line regions collapsed line numbers, a
25
+ leading fence injected a phantom line, --check was undocumented-undeclared,
26
+ and --write exited 1 on a successful heal. Fixes: open-marker capture,
27
+ newline-preserving placeholder, empty-chunk skip, check flag, healedRegions
28
+ split (write always exits 0), dryRun/io threading, byte-exact inventory
29
+ compare on the prettier-stable canonical form, CHECK-13 delegated through
30
+ commandRegistry/invoke so the registry-integrity scan stays within its
31
+ slice cap (KNOWN_TRUNCATED_SCANS is shrink-only), record-tree exclusions
32
+ extended, two real stale claims corrected, profile templates ship empty
33
+ markers hydrated at scaffold write time. RFC amended to implemented
34
+ grammar/result/exclusions; command moved to commands.added.</item>
35
+ </CHANGE_SUMMARY>
36
+ */
37
+
38
+ import path from "node:path";
39
+ import * as sfs from "../utils/sync-fs.ts";
40
+ import { writeFileIfChanged } from "../utils/fs-idempotent.ts";
41
+ import { FORGE_SKILLS } from "../registry.ts";
42
+ import type { ForgeSkillEntry } from "../registry.ts";
43
+ import type { WorkspaceIO } from "../types.ts";
44
+
45
+ // ─── Markers ────────────────────────────────────────────────────────────────
46
+
47
+ export const SKILL_DOC_MARKERS = {
48
+ inventory: "forge:skills-inventory",
49
+ count: "forge:skills-count",
50
+ } as const;
51
+
52
+ export type SkillDocMarkerKind = keyof typeof SKILL_DOC_MARKERS;
53
+
54
+ /** `<!-- forge-skill-count:ok: <reason> -->` exempts one line from the claim lint. */
55
+ export const SKILL_CLAIM_EXEMPT_RE = /forge-skill-count:ok(?:\s*:\s*[^\n]*?)?\s*(?:-->\s*)?$/;
56
+
57
+ /** Paired `<!-- forge:X -->…<!-- /forge:X -->` region. */
58
+ const REGION_RE =
59
+ /<!--\s*forge:(skills-inventory|skills-count)\s*-->([\s\S]*?)<!--\s*\/forge:\1\s*-->/g;
60
+
61
+ // ─── Registry projection ────────────────────────────────────────────────────
62
+
63
+ export interface SkillCounts {
64
+ total: number;
65
+ fo: number;
66
+ shared: number;
67
+ meta: number;
68
+ }
69
+
70
+ export function skillCounts(skills: ForgeSkillEntry[] = FORGE_SKILLS): SkillCounts {
71
+ const by = (category: ForgeSkillEntry["category"]) =>
72
+ skills.filter((s) => s.category === category).length;
73
+ return { total: skills.length, fo: by("fo"), shared: by("shared"), meta: by("meta") };
74
+ }
75
+
76
+ /** Canonical one-line literal used by the `skills-count` marker and the claim lint. */
77
+ export function renderCountLiteral(skills: ForgeSkillEntry[] = FORGE_SKILLS): string {
78
+ const c = skillCounts(skills);
79
+ return `${c.total} skills (${c.fo} fo + ${c.shared} shared + ${c.meta} meta)`;
80
+ }
81
+
82
+ /** Canonical inventory block for the `skills-inventory` marker. */
83
+ export function renderInventoryBlock(skills: ForgeSkillEntry[] = FORGE_SKILLS): string {
84
+ const c = skillCounts(skills);
85
+ const names = (category: ForgeSkillEntry["category"]) =>
86
+ skills
87
+ .filter((s) => s.category === category)
88
+ .map((s) => s.name)
89
+ .sort()
90
+ .map((n) => `\`${n}\``)
91
+ .join(", ");
92
+ return [
93
+ `**${c.total} skills** — ${c.fo} fo, ${c.shared} shared, ${c.meta} meta.`,
94
+ ``,
95
+ `- **fo (${c.fo}):** ${names("fo")}`,
96
+ `- **shared (${c.shared}):** ${names("shared")}`,
97
+ `- **meta (${c.meta}):** ${names("meta")}`,
98
+ ].join("\n");
99
+ }
100
+
101
+ function renderRegion(kind: SkillDocMarkerKind, skills: ForgeSkillEntry[]): string {
102
+ return kind === "count" ? renderCountLiteral(skills) : renderInventoryBlock(skills);
103
+ }
104
+
105
+ // ─── Drift model ────────────────────────────────────────────────────────────
106
+
107
+ export interface SkillDocDrift {
108
+ file: string;
109
+ line: number;
110
+ kind:
111
+ "marked-region" | "claim-total" | "claim-decomposition" | "claim-category" | "inline-inventory";
112
+ expected: string;
113
+ found: string;
114
+ }
115
+
116
+ export interface SkillDocSyncResult {
117
+ command: "forge.skill.doc-sync";
118
+ status: "pass" | "fail";
119
+ filesScanned: number;
120
+ markedRegions: number;
121
+ /** Residual drift — unhealed claims in check mode, all drift in write mode. */
122
+ drift: SkillDocDrift[];
123
+ /** Marked regions healed by --write. */
124
+ healedRegions: SkillDocDrift[];
125
+ written: string[];
126
+ dryRun: boolean;
127
+ }
128
+
129
+ // ─── Claim grammar (unmarked regions only) ──────────────────────────────────
130
+
131
+ /** `34 fo + 4 shared + 3 meta` — ordered decomposition, all three required. */
132
+ const CLAIM_DECOMPOSITION_RE = /(\d+)\s*fo\D{0,10}?\+\s*(\d+)\s*shared\D{0,10}?\+\s*(\d+)\s*meta/g;
133
+ /** `41 skills`, `41 skill definitions`, `41 built-in skills`, `41 forge skills`. */
134
+ const CLAIM_TOTAL_RE =
135
+ /\b(\d+)\s+(?:built-in\s+|forge(?:-managed)?\s+)?skill\s*(?:definitions|s)?\b/gi;
136
+ /** `34 fo skills`, `4 shared skills`, `3 meta skills`. */
137
+ const CLAIM_CATEGORY_RE = /\b(\d+)\s+(fo|shared|meta)\s+skills?\b/g;
138
+
139
+ const FENCE_RE = /^```/;
140
+
141
+ interface LintOutcome {
142
+ drift: SkillDocDrift[];
143
+ markedRegions: number;
144
+ /** Marked regions --write just healed (not residual drift). */
145
+ healedRegions: SkillDocDrift[];
146
+ rewritten?: string;
147
+ }
148
+
149
+ /** Strip marked regions and fenced blocks, then lint remaining lines for stale skill-count claims. */
150
+ export function lintSkillDocContent(
151
+ relFile: string,
152
+ content: string,
153
+ skills: ForgeSkillEntry[] = FORGE_SKILLS,
154
+ write = false,
155
+ ): LintOutcome {
156
+ const counts = skillCounts(skills);
157
+ const drift: SkillDocDrift[] = [];
158
+ let markedRegions = 0;
159
+ let healedRegions: SkillDocDrift[] = [];
160
+
161
+ // 1. Marked regions — compare or rewrite. Fenced code blocks are doc
162
+ // examples, never live regions — regions are scanned per unfenced chunk.
163
+ const chunks: { text: string; fenced: boolean }[] = [];
164
+ {
165
+ let fenced = false;
166
+ let buf: string[] = [];
167
+ const flush = (): void => {
168
+ if (buf.length > 0) chunks.push({ text: buf.join("\n"), fenced });
169
+ buf = [];
170
+ };
171
+ for (const l of content.split("\n")) {
172
+ if (FENCE_RE.test(l.trimStart())) {
173
+ flush();
174
+ buf.push(l);
175
+ fenced = !fenced;
176
+ continue;
177
+ }
178
+ buf.push(l);
179
+ }
180
+ flush();
181
+ }
182
+
183
+ const healed: SkillDocDrift[] = [];
184
+ const processRegion = (
185
+ whole: string,
186
+ kind: string,
187
+ inner: string,
188
+ offset: number,
189
+ chunkText: string,
190
+ lineBase: number,
191
+ ): string => {
192
+ markedRegions++;
193
+ const line = lineBase + chunkText.slice(0, offset).split("\n").length - 1;
194
+ const marker = kind === "skills-inventory" ? "inventory" : "count";
195
+ const rendered = renderRegion(marker as SkillDocMarkerKind, skills);
196
+ if (marker === "inventory" && !whole.includes("\n")) {
197
+ // Inline inventory marker would corrupt layout — flag, never rewrite.
198
+ drift.push({
199
+ file: relFile,
200
+ line,
201
+ kind: "inline-inventory",
202
+ expected: "inventory markers on their own lines",
203
+ found: whole.slice(0, 80),
204
+ });
205
+ return whole;
206
+ }
207
+ // Inventory's canonical inner keeps the blank lines prettier inserts
208
+ // around HTML comment blocks — byte-exact AND format-stable.
209
+ const expectedInner = marker === "count" ? rendered : `\n\n${rendered}\n\n`;
210
+ // Count regions tolerate padding (prettier aligns table cells); inventory
211
+ // compares byte-exact — whitespace drift inside a generated block is real drift.
212
+ const stale = marker === "count" ? inner.trim() !== rendered : inner !== expectedInner;
213
+ if (stale) {
214
+ const entry: SkillDocDrift = {
215
+ file: relFile,
216
+ line,
217
+ kind: "marked-region",
218
+ expected: rendered.split("\n")[0]!,
219
+ found: inner.trim().split("\n")[0]!.slice(0, 80) || "(empty)",
220
+ };
221
+ (write ? healed : drift).push(entry);
222
+ }
223
+ if (!write || !stale) return whole;
224
+ const openEnd = whole.indexOf("-->");
225
+ const open = openEnd === -1 ? whole : whole.slice(0, openEnd + 3);
226
+ const close = `<!-- /forge:${kind} -->`;
227
+ return `${open}${expectedInner}${close}`;
228
+ };
229
+
230
+ const rewrittenParts: string[] = [];
231
+ let lineBase = 1;
232
+ for (const chunk of chunks) {
233
+ if (chunk.fenced) {
234
+ rewrittenParts.push(chunk.text);
235
+ } else {
236
+ rewrittenParts.push(
237
+ chunk.text.replace(REGION_RE, (whole, kind, inner, offset) =>
238
+ processRegion(whole, kind, inner, offset, chunk.text, lineBase),
239
+ ),
240
+ );
241
+ }
242
+ lineBase += chunk.text.split("\n").length;
243
+ }
244
+ const rewritten = rewrittenParts.join("\n");
245
+ healedRegions = healed;
246
+
247
+ // 2. Claim lint — only outside marked regions and fenced blocks. Regions
248
+ // collapse to whitespace that preserves their newline count — a multi-line
249
+ // region must not shift the line numbers of claims that follow it.
250
+ const body = (write ? rewritten : content)
251
+ .replace(REGION_RE, (m) => m.replace(/[^\n]/g, " "))
252
+ .split("\n")
253
+ .map((l, i) => ({ line: i + 1, text: l }));
254
+ let inFence = false;
255
+ for (const { line, text } of body) {
256
+ if (FENCE_RE.test(text.trimStart())) {
257
+ inFence = !inFence;
258
+ continue;
259
+ }
260
+ if (inFence || SKILL_CLAIM_EXEMPT_RE.test(text)) continue;
261
+
262
+ for (const m of text.matchAll(CLAIM_DECOMPOSITION_RE)) {
263
+ const [fo, shared, meta] = [Number(m[1]), Number(m[2]), Number(m[3])];
264
+ if (fo !== counts.fo || shared !== counts.shared || meta !== counts.meta) {
265
+ drift.push({
266
+ file: relFile,
267
+ line,
268
+ kind: "claim-decomposition",
269
+ expected: `${counts.fo} fo + ${counts.shared} shared + ${counts.meta} meta`,
270
+ found: m[0].trim(),
271
+ });
272
+ }
273
+ }
274
+ for (const m of text.matchAll(CLAIM_CATEGORY_RE)) {
275
+ const cat = m[2] as "fo" | "shared" | "meta";
276
+ if (Number(m[1]) !== counts[cat]) {
277
+ drift.push({
278
+ file: relFile,
279
+ line,
280
+ kind: "claim-category",
281
+ expected: `${counts[cat]} ${cat} skills`,
282
+ found: m[0].trim(),
283
+ });
284
+ }
285
+ }
286
+ for (const m of text.matchAll(CLAIM_TOTAL_RE)) {
287
+ if (Number(m[1]) !== counts.total) {
288
+ drift.push({
289
+ file: relFile,
290
+ line,
291
+ kind: "claim-total",
292
+ expected: `${counts.total} skills`,
293
+ found: m[0].trim(),
294
+ });
295
+ }
296
+ }
297
+ }
298
+
299
+ return { drift, markedRegions, healedRegions, rewritten: write ? rewritten : undefined };
300
+ }
301
+
302
+ // ─── Doc surface ────────────────────────────────────────────────────────────
303
+
304
+ /** Historical record trees quote the registry of their day — never claim-linted. */
305
+ export const SKILL_DOC_SURFACE_EXCLUDE_RES = [
306
+ /(^|\/)CHANGELOG\.md$/,
307
+ /\.generated\.md$/,
308
+ /(^|\/)docs\/(rfcs|adrs|audits|reviews|plans|queues|archive|sessions|specs|historical|summits|metrics|explorations|evidence|outbox|frictions|decisions)\//,
309
+ /(^|\/)lagebild-archive\//,
310
+ ];
311
+
312
+ /**
313
+ * Collect the claim-lint surface under a package root: README*.md, AGENTS.md,
314
+ * docs/**. Intentionally a different surface than package-health's
315
+ * DOCS_SURFACE — it adds README locale variants and drops the record trees
316
+ * (rfcs/audits/…) DOCS_SURFACE includes, since dated records quote old counts.
317
+ */
318
+ export function collectSkillDocFiles(root: string): string[] {
319
+ const files: string[] = [];
320
+ const walk = (dir: string): void => {
321
+ let entries: sfs.Dirent[];
322
+ try {
323
+ entries = sfs.readdirSync(dir, { withFileTypes: true });
324
+ } catch {
325
+ return;
326
+ }
327
+ for (const e of entries) {
328
+ const abs = path.join(dir, e.name);
329
+ if (e.isDirectory()) walk(abs);
330
+ else if (e.isFile() && e.name.endsWith(".md")) files.push(abs);
331
+ }
332
+ };
333
+ const docsDir = path.join(root, "docs");
334
+ if (sfs.existsSync(docsDir)) walk(docsDir);
335
+ for (const name of sfs.existsSync(root) ? sfs.readdirSync(root) : []) {
336
+ if (/^README.*\.md$/.test(name) || name === "AGENTS.md") files.push(path.join(root, name));
337
+ }
338
+ return files
339
+ .filter((f) => {
340
+ const rel = path.relative(root, f).split(path.sep).join("/");
341
+ return !SKILL_DOC_SURFACE_EXCLUDE_RES.some((re) => re.test(rel));
342
+ })
343
+ .sort();
344
+ }
345
+
346
+ /** Lint a concrete file list — shared by the command and the package-health composition. */
347
+ export async function lintSkillDocFiles(
348
+ root: string,
349
+ files: string[],
350
+ skills: ForgeSkillEntry[] = FORGE_SKILLS,
351
+ write = false,
352
+ opts: { io?: WorkspaceIO; dryRun?: boolean } = {},
353
+ ): Promise<{
354
+ drift: SkillDocDrift[];
355
+ healedRegions: SkillDocDrift[];
356
+ markedRegions: number;
357
+ written: string[];
358
+ }> {
359
+ const drift: SkillDocDrift[] = [];
360
+ const healedRegions: SkillDocDrift[] = [];
361
+ const written: string[] = [];
362
+ let markedRegions = 0;
363
+ for (const abs of files) {
364
+ let content: string;
365
+ try {
366
+ content = sfs.readFileSync(abs, "utf8");
367
+ } catch {
368
+ continue;
369
+ }
370
+ const rel = path.relative(root, abs).split(path.sep).join("/");
371
+ const outcome = lintSkillDocContent(rel, content, skills, write);
372
+ drift.push(...outcome.drift);
373
+ healedRegions.push(...outcome.healedRegions);
374
+ markedRegions += outcome.markedRegions;
375
+ if (write && outcome.rewritten !== undefined && outcome.rewritten !== content) {
376
+ if (!opts.dryRun) await writeFileIfChanged(abs, outcome.rewritten, opts.io);
377
+ written.push(rel);
378
+ }
379
+ }
380
+ return { drift, healedRegions, markedRegions, written };
381
+ }
382
+
383
+ /**
384
+ * Fill marked regions in scaffolded content at create time — the literals are
385
+ * rendered from the registry of the forge doing the scaffolding, so profile
386
+ * templates never carry a hand-bumped count (RFC-1585, review F-12).
387
+ */
388
+ export function hydrateSkillDocMarkers(
389
+ content: string,
390
+ skills: ForgeSkillEntry[] = FORGE_SKILLS,
391
+ ): string {
392
+ return content.replace(REGION_RE, (_whole, kind: string) => {
393
+ const marker = kind === "skills-inventory" ? "inventory" : "count";
394
+ const rendered = renderRegion(marker as SkillDocMarkerKind, skills);
395
+ const inner = marker === "count" ? rendered : `\n\n${rendered}\n\n`;
396
+ return `<!-- forge:${kind} -->${inner}<!-- /forge:${kind} -->`;
397
+ });
398
+ }
399
+
400
+ // ─── Command runner ─────────────────────────────────────────────────────────
401
+
402
+ interface SkillDocSyncFlags {
403
+ write?: boolean;
404
+ check?: boolean;
405
+ files?: string;
406
+ root?: string;
407
+ }
408
+
409
+ export async function runSkillDocSync(
410
+ input: unknown,
411
+ context: unknown,
412
+ ): Promise<SkillDocSyncResult> {
413
+ const flags =
414
+ (input as { flags?: SkillDocSyncFlags } | undefined)?.flags ??
415
+ (input as SkillDocSyncFlags) ??
416
+ {};
417
+ const ctx = (context ?? {}) as {
418
+ workspaceRoot?: string;
419
+ io?: WorkspaceIO;
420
+ dryRun?: boolean;
421
+ };
422
+ const root = flags.root
423
+ ? path.resolve(ctx.workspaceRoot ?? process.cwd(), flags.root)
424
+ : (ctx.workspaceRoot ?? process.cwd());
425
+ const files = flags.files
426
+ ? flags.files.split(",").map((f) => path.resolve(root, f.trim()))
427
+ : collectSkillDocFiles(root);
428
+ // --check is the explicit form of the default; --write renders and always
429
+ // exits 0 (claim drift it cannot heal is reported, never auto-fixed).
430
+ const write = flags.write === true && flags.check !== true;
431
+
432
+ const { drift, healedRegions, markedRegions, written } = await lintSkillDocFiles(
433
+ root,
434
+ files,
435
+ FORGE_SKILLS,
436
+ write,
437
+ { io: ctx.io, dryRun: ctx.dryRun === true },
438
+ );
439
+ return {
440
+ command: "forge.skill.doc-sync",
441
+ status: !write && drift.length > 0 ? "fail" : "pass",
442
+ filesScanned: files.length,
443
+ markedRegions,
444
+ drift,
445
+ healedRegions,
446
+ written,
447
+ dryRun: ctx.dryRun === true,
448
+ };
449
+ }