@vttforge/cli 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-D3qRQqRr.mjs","names":["MANIFEST_FILES"],"sources":["../package.json","../src/audit/manifest-rules.ts","../src/audit/release-rules.ts","../src/audit/source-rules.ts","../src/audit/template-rules.ts","../src/audit/types.ts","../src/audit/legacy-globals.ts","../src/audit/mask.ts","../src/audit/v14-rules.ts","../src/audit/index.ts","../src/audit/reporter.ts","../src/commands/audit.ts","../src/manifest.ts","../src/package-manager.ts","../src/vite-runner.ts","../src/zip.ts","../src/commands/build.ts","../src/symlink.ts","../src/dev-module-install.ts","../src/dev-server.ts","../src/dev-watcher.ts","../src/foundry-data-dir.ts","../src/commands/dev.ts","../src/git.ts","../src/scaffold.ts","../src/commands/init.ts","../src/commands/lint.ts","../src/index.ts"],"sourcesContent":["","/**\n * Manifest-scope audit rules.\n *\n * These rules operate on the parsed contents of `system.json` and/or\n * `module.json` at the project root. They cover the v14 manifest\n * footguns from the VTTForge audit catalog:\n *\n * VTTF-AUDIT-001 (HIGH) : flags.hotReload shape\n * VTTF-AUDIT-002 (HIGH) : removed gridDistance/gridUnits\n * VTTF-AUDIT-003 (LOW) : styles array of strings (v12 shape)\n * VTTF-AUDIT-009 (MEDIUM): a documentTypes subtype with no TYPES label\n * VTTF-AUDIT-010 (HIGH) : template.json erasing documentTypes metadata\n *\n * Each rule emits zero or more `RuleResult`s. Line numbers are looked up\n * cheaply by scanning the raw JSON for the offending key. Accurate\n * enough for navigation, no AST dependency.\n */\n\nimport { existsSync, readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport type { RuleResult } from './types.js';\n\nconst MANIFEST_FILES = ['system.json', 'module.json'] as const;\n\ninterface LoadedManifest {\n path: string;\n raw: string;\n parsed: Record<string, unknown>;\n}\n\n/**\n * Load the manifest(s) at the project root. Returns at most two entries\n * (system + module), skipping anything that can't be parsed as a JSON\n * object. We tolerate parse errors here because that's a separate failure\n * mode the user will hit when they actually run `vite build`; the audit\n * shouldn't double-report it.\n */\nasync function loadManifests(cwd: string): Promise<LoadedManifest[]> {\n const out: LoadedManifest[] = [];\n for (const file of MANIFEST_FILES) {\n const path = join(cwd, file);\n if (!existsSync(path)) continue;\n let raw: string;\n try {\n raw = await readFile(path, 'utf8');\n } catch {\n continue;\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n continue;\n }\n if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {\n out.push({ path, raw, parsed: parsed as Record<string, unknown> });\n }\n }\n return out;\n}\n\n/**\n * Find the 1-based line number of the first `\"key\":` occurrence in JSON\n * source. Good enough for navigation: JSON keys are usually unique at\n * the level we report on, and even when nested duplicates exist the\n * first occurrence points at the right region of the file.\n */\nfunction findKeyLine(raw: string, key: string): number | undefined {\n const needle = `\"${key}\"`;\n const idx = raw.indexOf(needle);\n if (idx < 0) return undefined;\n let line = 1;\n for (let i = 0; i < idx; i += 1) {\n if (raw[i] === '\\n') line += 1;\n }\n return line;\n}\n\n/**\n * VTTF-AUDIT-001 (HIGH): flags.hotReload shape.\n *\n * v12 accepted `\"hotReload\": [\"css\", \"hbs\", ...]` (array). v13+ expects\n * `\"hotReload\": { \"extensions\": [...], \"paths\": [...] }` (object at the\n * root of `flags`, NOT nested under a package id). With the array shape\n * the server's chokidar watcher reads `.extensions` and gets undefined,\n * silently disabling HMR for the package.\n */\nfunction ruleHotReload(manifest: LoadedManifest): RuleResult[] {\n const flags = manifest.parsed.flags;\n if (!flags || typeof flags !== 'object' || Array.isArray(flags)) return [];\n const hr = (flags as Record<string, unknown>).hotReload;\n if (hr === undefined) return [];\n\n const line = findKeyLine(manifest.raw, 'hotReload');\n if (Array.isArray(hr)) {\n return [\n {\n ruleId: 'VTTF-AUDIT-001',\n title: 'flags.hotReload uses the deprecated v12 array shape',\n severity: 'HIGH',\n filePath: manifest.path,\n line,\n message:\n 'flags.hotReload is an array; Foundry expects an object `{ \"extensions\": [...], \"paths\": [...] }`. With the array shape Foundry silently disables HMR for this package.',\n remediation:\n 'Replace the array with an object: `\"hotReload\": { \"extensions\": [\"css\", \"hbs\", \"json\"], \"paths\": [\"styles\", \"templates\", \"lang\"] }`.',\n },\n ];\n }\n // `typeof null === 'object'` would slip past a naive check, so the\n // null / scalar / array branches are all rejected explicitly before\n // we trust hr as an object.\n if (hr === null || typeof hr !== 'object') {\n return [\n {\n ruleId: 'VTTF-AUDIT-001',\n title: 'flags.hotReload has an invalid shape',\n severity: 'HIGH',\n filePath: manifest.path,\n line,\n message: 'flags.hotReload must be an object with `extensions` and `paths` arrays.',\n remediation: 'Replace with `\"hotReload\": { \"extensions\": [...], \"paths\": [...] }`.',\n },\n ];\n }\n // Object shape: `extensions` is mandatory (Foundry has no default for\n // which extensions to watch), but `paths` is optional: when omitted,\n // Foundry watches the entire package root. Don't penalise users who\n // legitimately want the broader watch scope.\n const hrObj = hr as Record<string, unknown>;\n if (!Array.isArray(hrObj.extensions)) {\n return [\n {\n ruleId: 'VTTF-AUDIT-001',\n title: 'flags.hotReload is missing the required `extensions` key',\n severity: 'HIGH',\n filePath: manifest.path,\n line,\n message:\n 'flags.hotReload must declare an `extensions` array. Foundry has no default and the watcher silently does nothing without it.',\n remediation:\n 'Add `extensions`: `\"hotReload\": { \"extensions\": [\"css\", \"hbs\", \"json\"], \"paths\": [\"styles\", \"templates\", \"lang\"] }`. `paths` is optional (defaults to the package root) but recommended.',\n },\n ];\n }\n return [];\n}\n\n/**\n * VTTF-AUDIT-002 (HIGH): removed top-level grid fields.\n *\n * v12 used flat `gridDistance` + `gridUnits`. v13 auto-migrated them to\n * `grid: { type, distance, units, diagonals }` with a warning; v14 dropped\n * the shim. The keys are now ignored and the system silently falls back to\n * the default grid.\n */\nfunction ruleGridShape(manifest: LoadedManifest): RuleResult[] {\n const hasLegacyDistance = 'gridDistance' in manifest.parsed;\n const hasLegacyUnits = 'gridUnits' in manifest.parsed;\n if (!hasLegacyDistance && !hasLegacyUnits) return [];\n\n const offendingKey = hasLegacyDistance ? 'gridDistance' : 'gridUnits';\n return [\n {\n ruleId: 'VTTF-AUDIT-002',\n title: 'Top-level gridDistance / gridUnits are removed v12 fields',\n severity: 'HIGH',\n filePath: manifest.path,\n line: findKeyLine(manifest.raw, offendingKey),\n message:\n 'gridDistance and gridUnits at the manifest root are the v12 shape. v14 removed the migration shim: the keys are ignored and the system falls back to the default grid with no warning.',\n remediation:\n 'Replace with `\"grid\": { \"type\": 1, \"distance\": 5, \"units\": \"ft\", \"diagonals\": 0 }` (adjust values to your system).',\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-003 (LOW): styles array of strings.\n *\n * v12 took `styles: [\"styles/foo.css\"]`. v13+ expects `styles: [{ src,\n * layer? }]` so cascade-layer ordering can be declared in the manifest.\n * The string form still works (Foundry auto-migrates) but emits a\n * deprecation warning and loses the ability to control layer placement.\n */\nfunction ruleStylesShape(manifest: LoadedManifest): RuleResult[] {\n const styles = manifest.parsed.styles;\n if (!Array.isArray(styles) || styles.length === 0) return [];\n\n // The whole array is uniform in the v12 shape: entries are strings.\n // Mixed arrays (some string, some object) also fail the v13+ shape.\n const hasString = styles.some((entry) => typeof entry === 'string');\n if (!hasString) return [];\n\n return [\n {\n ruleId: 'VTTF-AUDIT-003',\n title: 'styles uses the deprecated v12 string-array shape',\n severity: 'LOW',\n filePath: manifest.path,\n line: findKeyLine(manifest.raw, 'styles'),\n message:\n 'styles entries should be objects of the form `{ \"src\": \"path/to.css\", \"layer\": \"optional-layer\" }` since v13. String entries auto-migrate today but the conversion drops your control over cascade-layer placement.',\n remediation:\n 'Replace each string with `{ \"src\": \"<that-path>\" }`. Add a `\"layer\"` field per entry where you want explicit cascade ordering.',\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-009 (MEDIUM) — a declared subtype with no name.\n *\n * Foundry looks a subtype's label up under `TYPES.<Document>.<key>`, where a\n * module's key carries its id: `TYPES.Item.my-module.note`. With the label\n * missing it prints that path, so the sheet is titled\n * `TYPES.Item.my-module.note: Rope` and the Create dialog offers\n * `my-module.note` in its type dropdown.\n *\n * Nothing errors. The type works; it just has no name anywhere a reader\n * looks, which is the sort of thing that ships and stays.\n */\nasync function ruleTypeLabels(cwd: string, manifest: LoadedManifest): Promise<RuleResult[]> {\n const documentTypes = manifest.parsed.documentTypes;\n if (documentTypes === null || typeof documentTypes !== 'object') return [];\n\n const id = typeof manifest.parsed.id === 'string' ? manifest.parsed.id : null;\n if (id === null) return [];\n // A module namespaces its subtypes under its own id; a system does not.\n const isModule = manifest.path.endsWith('module.json');\n\n const languages = await loadLanguages(cwd, manifest);\n // Nothing to check against. Missing language files are their own problem.\n if (languages.length === 0) return [];\n\n const missing: string[] = [];\n for (const [document, subtypes] of Object.entries(documentTypes as Record<string, unknown>)) {\n if (subtypes === null || typeof subtypes !== 'object') continue;\n for (const subtype of Object.keys(subtypes as Record<string, unknown>)) {\n const path = isModule ? ['TYPES', document, id, subtype] : ['TYPES', document, subtype];\n const named = languages.some((catalogue) => readPath(catalogue, path) !== undefined);\n if (!named) missing.push(path.join('.'));\n }\n }\n if (missing.length === 0) return [];\n\n return [\n {\n ruleId: 'VTTF-AUDIT-009',\n title: 'Declared subtype has no name in any language file',\n severity: 'MEDIUM',\n filePath: manifest.path,\n line: findKeyLine(manifest.raw, 'documentTypes'),\n message: `No language file names ${missing.join(', ')}. Foundry falls back to printing the key, so the sheet title and the type dropdown read the raw path instead of a name.`,\n remediation: `Add the label to a language file, nested: ${nestedExample(missing[0] ?? '')}`,\n },\n ];\n}\n\n/** Every language catalogue the manifest declares, parsed. Unreadable ones are skipped. */\nasync function loadLanguages(\n cwd: string,\n manifest: LoadedManifest,\n): Promise<Record<string, unknown>[]> {\n const declared = manifest.parsed.languages;\n if (!Array.isArray(declared)) return [];\n const out: Record<string, unknown>[] = [];\n for (const entry of declared) {\n if (entry === null || typeof entry !== 'object') continue;\n const path = (entry as { path?: unknown }).path;\n if (typeof path !== 'string') continue;\n try {\n out.push(JSON.parse(await readFile(join(cwd, path), 'utf8')));\n } catch {\n // Missing or malformed. Not this rule's finding to make.\n }\n }\n return out;\n}\n\n/**\n * Read a dotted path, allowing for either nesting.\n *\n * Foundry flattens its catalogues, so `{\"TYPES.Item.x\": \"X\"}` and the fully\n * nested form both work. A rule that only understood one shape would report\n * a label that is really there.\n */\nfunction readPath(catalogue: Record<string, unknown>, path: readonly string[]): unknown {\n for (let split = path.length; split > 0; split -= 1) {\n const head = path.slice(0, split).join('.');\n const value = catalogue[head];\n if (value === undefined) continue;\n if (split === path.length) return value;\n if (value === null || typeof value !== 'object') continue;\n const rest = readPath(value as Record<string, unknown>, path.slice(split));\n if (rest !== undefined) return rest;\n }\n return undefined;\n}\n\n/** The JSON a reader should paste, for the first missing label. */\nfunction nestedExample(dotted: string): string {\n const parts = dotted.split('.');\n let json = '\"Some Name\"';\n for (const key of parts.reverse()) json = `{ ${JSON.stringify(key)}: ${json} }`;\n return json;\n}\n\n/**\n * Entry point: run every manifest rule against every manifest at the\n * project root.\n */\n/**\n * VTTF-AUDIT-010 (HIGH) — `template.json` erases the metadata that\n * `system.json` declares for the same type.\n *\n * On load, Foundry reads `template.json` and, for every type it lists,\n * replaces that type's entry in `documentTypes` with a fresh object. Into the\n * new object it copies only `htmlFields`, `filePathFields` and `gmOnlyFields`,\n * and it reads them from the document level of `template.json`, not from the\n * type. So this in `system.json`:\n *\n * ```json\n * \"documentTypes\": { \"Actor\": { \"character\": { \"htmlFields\": [\"biography\"] } } }\n * ```\n *\n * is thrown away the moment `template.json` lists `character` under `Actor`.\n *\n * Nothing errors, and the type still works. What is lost is every behaviour\n * that keys off those lists: HTML sanitization, ProseMirror enrichment, asset\n * path migration and search indexing. The field goes on saving and loading,\n * so the loss is invisible until a value comes back stripped or a path fails\n * to migrate.\n *\n * A system whose schemas come from `TypeDataModel` does not need\n * `template.json` at all: `documentTypes` declares the types and the data\n * model owns the shape.\n */\nfunction ruleTemplateJsonShadowing(cwd: string, manifest: LoadedManifest): RuleResult[] {\n // Only a system manifest is affected; Foundry reads no template.json for a\n // module.\n if (!manifest.path.endsWith('system.json')) return [];\n\n const templatePath = join(cwd, 'template.json');\n if (!existsSync(templatePath)) return [];\n\n const documentTypes = manifest.parsed.documentTypes;\n if (documentTypes === null || typeof documentTypes !== 'object') return [];\n\n let template: Record<string, unknown>;\n try {\n template = JSON.parse(readFileSync(templatePath, 'utf8')) as Record<string, unknown>;\n } catch {\n // A template.json that will not parse is a different failure, and the\n // build reports it. Not this rule's business.\n return [];\n }\n\n const CARRIED = ['htmlFields', 'filePathFields', 'gmOnlyFields'] as const;\n const results: RuleResult[] = [];\n\n for (const [documentName, declared] of Object.entries(documentTypes as Record<string, unknown>)) {\n if (declared === null || typeof declared !== 'object') continue;\n const templateDoc = template[documentName];\n if (templateDoc === null || typeof templateDoc !== 'object') continue;\n const listed = (templateDoc as { types?: unknown }).types;\n if (!Array.isArray(listed)) continue;\n\n for (const [type, meta] of Object.entries(declared as Record<string, unknown>)) {\n if (!listed.includes(type)) continue;\n if (meta === null || typeof meta !== 'object') continue;\n\n // Only report what is actually lost. A bare `{}` loses nothing, and a\n // key already present at the document level survives the copy.\n const lost = CARRIED.filter(\n (key) => key in (meta as Record<string, unknown>) && !(key in templateDoc),\n );\n if (lost.length === 0) continue;\n\n results.push({\n ruleId: 'VTTF-AUDIT-010',\n title: 'template.json erases documentTypes metadata',\n severity: 'HIGH',\n filePath: 'template.json',\n line: findKeyLine(readFileSync(templatePath, 'utf8'), documentName),\n message: `template.json lists ${documentName} type \"${type}\", so Foundry replaces that type's documentTypes entry and drops ${lost.join(', ')} declared in system.json. Sanitization, enrichment and asset migration stop applying to those fields, silently.`,\n remediation:\n 'Delete template.json. Your types are declared in system.json under `documentTypes`, and the schema comes from the TypeDataModel registered on `CONFIG.<Document>.dataModels`. If you still need it, move the lost keys up to the document level of template.json instead of the type.',\n });\n }\n }\n\n return results;\n}\n\nexport async function runManifestRules(cwd: string): Promise<RuleResult[]> {\n const manifests = await loadManifests(cwd);\n const results: RuleResult[] = [];\n for (const manifest of manifests) {\n results.push(...ruleHotReload(manifest));\n results.push(...ruleGridShape(manifest));\n results.push(...ruleStylesShape(manifest));\n results.push(...(await ruleTypeLabels(cwd, manifest)));\n results.push(...ruleTemplateJsonShadowing(cwd, manifest));\n }\n return results;\n}\n","/**\n * VTTF-AUDIT-020 (HIGH): the release workflow ships the checkout, but the\n * project builds to `dist/`.\n *\n * A project on the vite plugin runs from `dist/`: the entry is bundled, the\n * manifest is copied and rewritten there. A release workflow written for the\n * old layout zips `system.json` and a list of source folders straight from\n * the checkout, and the published package has no entry file at all. Nothing\n * fails until a player installs it. This rule reads `.github/workflows` for\n * a workflow that publishes a zip and checks that it builds first and zips\n * `dist/`.\n */\n\nimport { existsSync } from 'node:fs';\nimport { readdir, readFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport type { RuleResult } from './types.js';\n\nconst RULE_ID = 'VTTF-AUDIT-020';\nconst TITLE = 'Release workflow ships the checkout, not dist/';\n\nconst VITE_CONFIGS = [\n 'vite.config.js',\n 'vite.config.mjs',\n 'vite.config.ts',\n 'vite.config.mts',\n 'vite.config.cjs',\n];\n\n/** A line that runs the build. */\nconst BUILD_STEP = /\\b(?:vttforge\\s+build|vite\\s+build|(?:pnpm|npm|yarn|bun)\\s+(?:run\\s+)?build)\\b/;\n/** A line that makes or names the artifact. */\nconst ZIP_COMMAND = /\\bzip\\s+(?:-\\S+\\s+)*\\S+\\.zip\\b|\\bzip\\s+-r\\b/;\nconst ARTIFACT_LIST = /^\\s*(?:artifacts|files|asset_path|path)\\s*:/;\nconst MANIFEST = /\\b(?:system|module)\\.json\\b/;\nconst RELEASE_ACTION = /(?:release-action|action-gh-release|upload-release-asset)/;\n\n/** Whether this project builds through the vite plugin (or a `build` script that runs vite). */\nasync function buildsToDist(cwd: string): Promise<boolean> {\n for (const name of VITE_CONFIGS) {\n const path = join(cwd, name);\n if (!existsSync(path)) continue;\n const text = await readFile(path, 'utf8');\n if (/@vttforge\\/vite-plugin|vttforge\\s*\\(/.test(text)) return true;\n }\n const pkg = join(cwd, 'package.json');\n if (!existsSync(pkg)) return false;\n try {\n const parsed = JSON.parse(await readFile(pkg, 'utf8')) as { scripts?: Record<string, string> };\n const build = parsed.scripts?.build ?? '';\n return /vttforge\\s+build|vite\\s+build/.test(build);\n } catch {\n return false;\n }\n}\n\nasync function workflowFiles(cwd: string): Promise<string[]> {\n const dir = join(cwd, '.github', 'workflows');\n if (!existsSync(dir)) return [];\n const entries = await readdir(dir, { withFileTypes: true });\n return entries\n .filter((e) => e.isFile() && /\\.ya?ml$/.test(e.name))\n .map((e) => join(dir, e.name))\n .sort();\n}\n\ninterface Shipping {\n /** 1-based line of the step that makes or names the artifact. */\n line: number;\n /** Whether that step reads from `dist/`. */\n fromDist: boolean;\n /** Whether a build ran before it. */\n builtBefore: boolean;\n}\n\n/** The first step that ships a package, or null when the workflow ships nothing. */\nfunction shippingStep(text: string): Shipping | null {\n const lines = text.split('\\n');\n let builtBefore = false;\n let inArtifactList = false;\n for (let i = 0; i < lines.length; i += 1) {\n const line = lines[i] ?? '';\n if (BUILD_STEP.test(line)) builtBefore = true;\n if (ZIP_COMMAND.test(line)) {\n // `cd dist && zip ...`, `zip -r ../x.zip dist/`, or a zip of the checkout's own files.\n const fromDist =\n /\\bdist\\b/.test(line) ||\n /\\bcd\\s+dist\\b/.test(lines.slice(Math.max(0, i - 3), i).join('\\n'));\n return { line: i + 1, fromDist, builtBefore };\n }\n if (ARTIFACT_LIST.test(line)) {\n inArtifactList = true;\n const inline = line.slice(line.indexOf(':') + 1);\n if (MANIFEST.test(inline) || /\\.zip\\b/.test(inline)) {\n return { line: i + 1, fromDist: /\\bdist\\//.test(inline), builtBefore };\n }\n continue;\n }\n if (inArtifactList) {\n if (/^\\s*-?\\s*\\S/.test(line) && !/^\\s*-\\s/.test(line) && !/^\\s{4,}\\S/.test(line))\n inArtifactList = false;\n else if (MANIFEST.test(line) || /\\.zip\\b/.test(line)) {\n return { line: i + 1, fromDist: /\\bdist\\//.test(line), builtBefore };\n }\n }\n }\n return null;\n}\n\n/**\n * VTTF-AUDIT-020: a release workflow that publishes a zip must build first\n * and ship `dist/`.\n */\nexport async function runReleaseRules(cwd: string): Promise<RuleResult[]> {\n if (!(await buildsToDist(cwd))) return [];\n const findings: RuleResult[] = [];\n for (const file of await workflowFiles(cwd)) {\n const text = await readFile(file, 'utf8');\n const publishes =\n RELEASE_ACTION.test(text) || /\\brelease\\s*:/.test(text) || /\\btags\\s*:/.test(text);\n if (!publishes) continue;\n const ship = shippingStep(text);\n if (!ship) continue;\n const relPath = relative(cwd, file);\n if (!ship.builtBefore) {\n findings.push({\n ruleId: RULE_ID,\n title: TITLE,\n severity: 'HIGH',\n filePath: relPath,\n line: ship.line,\n message:\n 'The release workflow zips the checkout without building it. This project bundles to dist/, so the published package has no entry file and no world can start on it.',\n remediation:\n 'Install and build before the artifact step (`pnpm install --frozen-lockfile` then `pnpm build`), rewrite the manifest URLs in dist/system.json, and zip from inside dist/ so system.json and main.mjs sit at the zip root.',\n });\n } else if (!ship.fromDist) {\n findings.push({\n ruleId: RULE_ID,\n title: TITLE,\n severity: 'HIGH',\n filePath: relPath,\n line: ship.line,\n message:\n 'The release workflow builds, then zips the source tree instead of dist/. The published package carries the unbundled entry and misses what the build wrote.',\n remediation:\n 'Point the artifact step at dist/: rewrite the manifest URLs in dist/system.json and zip from inside dist/ (`cd dist && zip -r ../system.zip .`).',\n });\n }\n }\n return findings;\n}\n","/**\n * Source-tree audit rules.\n *\n * These walk `.ts` / `.tsx` / `.mjs` / `.cjs` / `.js` files under the\n * project root (excluding common build/dependency dirs) and apply regex\n * heuristics to spot four footguns from the VTTForge audit catalog:\n *\n * VTTF-AUDIT-004 (MEDIUM): HTMLField/FilePathField missing manifest declaration\n * VTTF-AUDIT-005 (MEDIUM): extends TypeDataModel without prepareBaseData stub\n * VTTF-AUDIT-006 (LOW) : `_addDataFieldMigrations` override (wrong signature)\n * VTTF-AUDIT-007 (MEDIUM): manifest primary/secondaryTokenAttribute not matched\n * by a `value`/`max` SchemaField in source\n *\n * Regex-based on purpose: avoids pulling in a TypeScript AST dependency\n * for what amount to four pattern checks. The trade-off is occasional\n * false negatives on heavily-formatted code; the alternative would be a\n * 30MB+ runtime dep for marginal gains.\n */\n\nimport { existsSync, readFileSync } from 'node:fs';\nimport { readdir, readFile, stat } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport type { RuleResult } from './types.js';\n\n/** Directories we never descend into; they are not user source. */\nconst EXCLUDED_DIRS = new Set([\n 'node_modules',\n 'dist',\n 'build',\n '.git',\n '.turbo',\n '.vttforge',\n '.next',\n 'coverage',\n '.vitest-cache',\n]);\n\n// `.mts`/`.cts` are valid TS ESM/CJS source files; `.d.ts`/`.d.mts`/`.d.cts`\n// are declaration-only and skipped (no real source to scan).\nconst SOURCE_EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts', '.mjs', '.cjs', '.js'] as const;\n\nfunction isSourceFile(name: string): boolean {\n if (name.endsWith('.d.ts') || name.endsWith('.d.mts') || name.endsWith('.d.cts')) {\n return false;\n }\n // A minified bundle is a vendored library, not the project's source: the\n // findings in it are not the author's to fix, and one line of it matches\n // every pattern there is.\n if (/\\.min\\.[cm]?js$/.test(name)) return false;\n return SOURCE_EXTENSIONS.some((ext) => name.endsWith(ext));\n}\n\n/** Every `.hbs` / `.html` in the project, outside the build and dependency folders. */\nasync function* walkTemplateFiles(cwd: string): AsyncGenerator<string> {\n const entries = await readdir(cwd, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory()) {\n if (EXCLUDED_DIRS.has(entry.name)) continue;\n yield* walkTemplateFiles(join(cwd, entry.name));\n } else if (entry.isFile() && /\\.(?:hbs|html)$/.test(entry.name)) {\n yield join(cwd, entry.name);\n }\n }\n}\n\nasync function* walkSourceFiles(cwd: string): AsyncGenerator<string> {\n const entries = await readdir(cwd, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.name.startsWith('.') && EXCLUDED_DIRS.has(entry.name)) continue;\n if (entry.isDirectory()) {\n if (EXCLUDED_DIRS.has(entry.name)) continue;\n yield* walkSourceFiles(join(cwd, entry.name));\n } else if (entry.isFile() && isSourceFile(entry.name)) {\n yield join(cwd, entry.name);\n }\n }\n}\n\n/** Find the 1-based line number of the first occurrence of `needle`. */\nfunction lineOf(content: string, needle: string | RegExp): number | undefined {\n const idx = typeof needle === 'string' ? content.indexOf(needle) : content.search(needle);\n if (idx < 0) return undefined;\n let line = 1;\n for (let i = 0; i < idx; i += 1) {\n if (content[i] === '\\n') line += 1;\n }\n return line;\n}\n\n/** VTTF-AUDIT-005: `extends TypeDataModel` without a `prepareBaseData(...)` method. */\nfunction rule005(filePath: string, content: string): RuleResult[] {\n // Find every direct TypeDataModel subclass with its body extents so we\n // can check each class independently. The previous file-wide check\n // would pass a whole file if ANY class in it had prepareBaseData; that\n // silently let sibling subclasses miss the hook.\n const out: RuleResult[] = [];\n const directClasses = findDirectTypeDataModelClasses(content);\n for (const cls of directClasses) {\n const body = content.slice(cls.openIdx + 1, cls.endIdx);\n if (/prepareBaseData\\s*\\(/.test(body)) continue;\n out.push({\n ruleId: 'VTTF-AUDIT-005',\n title: 'TypeDataModel subclass missing prepareBaseData stub',\n severity: 'MEDIUM',\n filePath,\n line: cls.startLine,\n message: `Class \\`${cls.className}\\` extends TypeDataModel directly but does not define prepareBaseData(). Active Effects apply between prepareBaseData and prepareDerivedData; without the hook, AE consumers see uninitialised fields.`,\n remediation:\n 'Add a no-op `prepareBaseData()` method (or extend `BaseTypeDataModel()` from `@vttforge/core`, which provides the stub).',\n });\n }\n return out;\n}\n\n/**\n * Subset of `findClassRanges` that only returns classes whose `extends`\n * names `TypeDataModel` (and not via the `BaseTypeDataModel()` factory).\n * The word boundary in `\\bTypeDataModel\\b` keeps the factory pattern\n * out, same as the lower-level helper.\n */\nfunction findDirectTypeDataModelClasses(content: string): ClassRange[] {\n const re = /class\\s+(\\w+)\\s+extends\\s+(?:[\\w.]+\\.)?\\bTypeDataModel\\b[^{]*\\{/g;\n const out: ClassRange[] = [];\n for (const match of content.matchAll(re)) {\n if (match.index === undefined) continue;\n const openIdx = match.index + match[0].length - 1;\n let depth = 0;\n let endIdx = -1;\n for (let i = openIdx; i < content.length; i += 1) {\n if (content[i] === '{') depth += 1;\n else if (content[i] === '}') {\n depth -= 1;\n if (depth === 0) {\n endIdx = i;\n break;\n }\n }\n }\n if (endIdx < 0) continue;\n let line = 1;\n for (let i = 0; i < match.index; i += 1) {\n if (content[i] === '\\n') line += 1;\n }\n out.push({ className: match[1] ?? '(anonymous)', startLine: line, openIdx, endIdx });\n }\n return out;\n}\n\n/** VTTF-AUDIT-006: `_addDataFieldMigrations(` override on a TypeDataModel subclass. */\nfunction rule006(filePath: string, content: string): RuleResult[] {\n if (!/_addDataFieldMigrations\\s*\\(/.test(content)) return [];\n // Only flag when the file defines a TypeDataModel-derived class, direct\n // `TypeDataModel` OR the VTTForge `BaseTypeDataModel()` factory. The\n // factory case matters because templates lean on it; an override there\n // is the most likely place users would write the buggy signature.\n if (!/extends\\s+(?:[\\w.]+\\.)?(?:Base)?TypeDataModel\\b/.test(content)) return [];\n return [\n {\n ruleId: 'VTTF-AUDIT-006',\n title: 'Method name confused with Foundry migration API',\n severity: 'LOW',\n filePath,\n line: lineOf(content, /_addDataFieldMigrations\\s*\\(/),\n message:\n 'The plural `_addDataFieldMigrations` is not a real Foundry API. The canonical migration hook is a static `migrateData(source)` override that calls singular `super._addDataFieldMigration(source, oldKey, newKey, apply?)` for each rename. Instance overrides named `_addDataFieldMigrations` never run.',\n remediation:\n 'Replace the override with `static migrateData(source) { super._addDataFieldMigration(source, \"oldKey\", \"newKey\"); return super.migrateData(source); }`.',\n },\n ];\n}\n\n/**\n * Track each class declaration's brace-balanced range so we can ask\n * \"which class encloses position X?\" later. Without this, rule 004 has\n * to fall back to a global declared-fields union, which silently passes\n * when two subtypes share a field name but only one declares it.\n */\ninterface ClassRange {\n className: string;\n startLine: number;\n openIdx: number;\n endIdx: number;\n}\n\nfunction findClassRanges(content: string): ClassRange[] {\n const out: ClassRange[] = [];\n const re = /class\\s+(\\w+)(?:\\s+extends\\s+[^{]+)?\\{/g;\n for (const match of content.matchAll(re)) {\n if (match.index === undefined) continue;\n const openIdx = match.index + match[0].length - 1;\n let depth = 0;\n let endIdx = -1;\n for (let i = openIdx; i < content.length; i += 1) {\n if (content[i] === '{') depth += 1;\n else if (content[i] === '}') {\n depth -= 1;\n if (depth === 0) {\n endIdx = i;\n break;\n }\n }\n }\n if (endIdx < 0) continue;\n let line = 1;\n for (let i = 0; i < match.index; i += 1) {\n if (content[i] === '\\n') line += 1;\n }\n out.push({ className: match[1] ?? '(anonymous)', startLine: line, openIdx, endIdx });\n }\n return out;\n}\n\nfunction findEnclosingClass(ranges: ClassRange[], idx: number): string | undefined {\n // Inner class wins (later in the array, since classes are flat in typical\n // Foundry code). Iterate in reverse so a nested class beats its parent.\n for (let i = ranges.length - 1; i >= 0; i -= 1) {\n const r = ranges[i];\n if (!r) continue;\n if (idx >= r.openIdx && idx <= r.endIdx) return r.className;\n }\n return undefined;\n}\n\n/**\n * A class built on the `BaseTypeDataModel(defineSchema)` factory keeps its\n * schema in a function outside the class body. Rules that ask \"which class\n * owns this field\" would otherwise see the field as unowned. So the body of\n * that function is reported as a range owned by the class, alongside the\n * class's own body.\n *\n * Both the arrow and the `function` form are recognised, as long as the\n * function is named and passed by name. An inline arrow is already inside\n * the `class ... {` match and needs no help.\n */\nfunction findSchemaFactoryRanges(content: string): ClassRange[] {\n const out: ClassRange[] = [];\n const classRe = /class\\s+(\\w+)\\s+extends\\s+(?:[\\w.]+\\.)?BaseTypeDataModel\\s*\\(\\s*(\\w+)\\s*\\)/g;\n for (const match of content.matchAll(classRe)) {\n const className = match[1];\n const fnName = match[2];\n if (!className || !fnName) continue;\n const fnRe = new RegExp(\n // An arrow may carry a return type between `)` and `=>`; a function\n // may carry one between `)` and `{`. Neither is captured.\n String.raw`(?:(?:const|let|var)\\s+${fnName}\\s*=\\s*(?:async\\s*)?(?:\\([^)]*\\)|\\w+)\\s*(?::[^=]*?)?=>\\s*\\(?\\s*\\{|function\\s+${fnName}\\s*\\([^)]*\\)\\s*(?::[^{]*?)?\\{)`,\n );\n const fnMatch = fnRe.exec(content);\n if (fnMatch === null) continue;\n const openIdx = fnMatch.index + fnMatch[0].length - 1;\n const endIdx = findMatchingBrace(content, openIdx);\n if (endIdx < 0) continue;\n let line = 1;\n for (let i = 0; i < fnMatch.index; i += 1) {\n if (content[i] === '\\n') line += 1;\n }\n out.push({ className, startLine: line, openIdx, endIdx });\n }\n return out;\n}\n\n/** Every range whose fields belong to a class: class bodies, then factory bodies. */\nfunction findSchemaOwnerRanges(content: string): ClassRange[] {\n return [...findClassRanges(content), ...findSchemaFactoryRanges(content)];\n}\n\n/**\n * Index of the `}` that closes the `{` at `openIdx`, skipping braces inside\n * string literals, template literals and comments. Returns -1 when unbalanced.\n */\nfunction findMatchingBrace(content: string, openIdx: number): number {\n let depth = 0;\n let i = openIdx;\n while (i < content.length) {\n const ch = content[i];\n const next = content[i + 1];\n if (ch === '/' && next === '/') {\n i = content.indexOf('\\n', i);\n if (i < 0) return -1;\n continue;\n }\n if (ch === '/' && next === '*') {\n i = content.indexOf('*/', i + 2);\n if (i < 0) return -1;\n i += 2;\n continue;\n }\n if (ch === \"'\" || ch === '\"' || ch === '`') {\n i += 1;\n while (i < content.length && content[i] !== ch) {\n if (content[i] === '\\\\') i += 1;\n i += 1;\n }\n i += 1;\n continue;\n }\n if (ch === '{') depth += 1;\n else if (ch === '}') {\n depth -= 1;\n if (depth === 0) return i;\n }\n i += 1;\n }\n return -1;\n}\n\n/**\n * Detect class→subtype registrations in three forms:\n *\n * 1. `CONFIG.<Doc>.dataModels.<subtype> = <ClassName>` (direct assignment)\n * 2. `CONFIG.<Doc>.dataModels = { <subtype>: <ClassName>, … }` (block)\n * 3. `registerSystem({ actorDataModels: { <subtype>: <ClassName>, … }, … })`\n * and the analogous `itemDataModels`, `activeEffectDataModels`, etc.\n * VTTForge's templated entry point uses this form, so without case\n * (3) the bundled scaffolds register through an unknown surface and\n * rule 004 falls back to the looser global-union check.\n */\ninterface ConfigMapping {\n doc: string;\n subtype: string;\n className: string;\n}\n\n/**\n * One `<subtype>: <Class>` entry inside a dataModels object literal.\n *\n * The key is bare for a system (`character`) and quoted for a module\n * (`'my-module.vehicle'`), because the module form contains a dot.\n */\nconst SUBTYPE_ENTRY_RE = /(?:['\"]([^'\"]+)['\"]|(\\w+))\\s*:\\s*(\\w+)/g;\n\n/** Map a `registerSystem({ ...DataModels })` key to the document name. */\nconst REGISTER_SYSTEM_KEYS: ReadonlyArray<{ key: string; doc: string }> = [\n { key: 'actorDataModels', doc: 'Actor' },\n { key: 'itemDataModels', doc: 'Item' },\n { key: 'activeEffectDataModels', doc: 'ActiveEffect' },\n { key: 'journalEntryPageDataModels', doc: 'JournalEntryPage' },\n { key: 'regionBehaviorDataModels', doc: 'RegionBehavior' },\n];\n\nfunction findConfigMappings(content: string): ConfigMapping[] {\n const out: ConfigMapping[] = [];\n\n // (1) Direct CONFIG.<Doc>.dataModels.<subtype> = <Class>\n const direct = /CONFIG\\.(\\w+)\\.dataModels\\.(\\w+)\\s*=\\s*(\\w+)/g;\n for (const m of content.matchAll(direct)) {\n out.push({ doc: m[1] ?? '', subtype: m[2] ?? '', className: m[3] ?? '' });\n }\n\n // (1b) Bracket CONFIG.<Doc>.dataModels['<subtype>'] = <Class>\n //\n // Modules must use this form: Foundry registers their subtypes as\n // `<moduleId>.<type>`, and a dot in the key rules out property access.\n // Without this case module registrations are invisible, every module\n // field falls through to the looser global check, and a genuinely\n // undeclared path can hide behind a same-named one declared elsewhere.\n const bracket = /CONFIG\\.(\\w+)\\.dataModels\\[\\s*['\"]([^'\"]+)['\"]\\s*\\]\\s*=\\s*(\\w+)/g;\n for (const m of content.matchAll(bracket)) {\n out.push({ doc: m[1] ?? '', subtype: m[2] ?? '', className: m[3] ?? '' });\n }\n\n // (2) Block CONFIG.<Doc>.dataModels = { <subtype>: <Class>, … }\n const block = /CONFIG\\.(\\w+)\\.dataModels\\s*=\\s*\\{([\\s\\S]*?)\\}/g;\n for (const m of content.matchAll(block)) {\n const doc = m[1] ?? '';\n const body = m[2] ?? '';\n for (const e of body.matchAll(SUBTYPE_ENTRY_RE)) {\n out.push({ doc, subtype: e[1] ?? e[2] ?? '', className: e[3] ?? '' });\n }\n }\n\n // (3) registerSystem({ actorDataModels: { ... }, itemDataModels: { ... }, … })\n // Find every `<KeyName>: {` block within the file body, then grab the\n // pairs inside. We use balanced-brace extraction so a nested SchemaField\n // initializer doesn't truncate the body. But `dataModels` blocks\n // typically only contain simple `<subtype>: <ClassName>` entries.\n for (const { key, doc } of REGISTER_SYSTEM_KEYS) {\n const re = new RegExp(String.raw`\\b${key}\\s*:\\s*\\{`, 'g');\n for (const m of content.matchAll(re)) {\n if (m.index === undefined) continue;\n const openIdx = m.index + m[0].length - 1;\n let depth = 0;\n let endIdx = -1;\n for (let i = openIdx; i < content.length; i += 1) {\n if (content[i] === '{') depth += 1;\n else if (content[i] === '}') {\n depth -= 1;\n if (depth === 0) {\n endIdx = i;\n break;\n }\n }\n }\n if (endIdx < 0) continue;\n const body = content.slice(openIdx + 1, endIdx);\n for (const pair of body.matchAll(SUBTYPE_ENTRY_RE)) {\n out.push({ doc, subtype: pair[1] ?? pair[2] ?? '', className: pair[3] ?? '' });\n }\n }\n }\n\n return out;\n}\n\n/**\n * Match `<name>: new (f|fields|foundry.data.fields).HTMLField(` or\n * `.FilePathField(`. We capture the field name, the field type, the\n * enclosing class, AND the dot-path through any enclosing SchemaField\n * wrappers, so rule 004 compares against the FULL manifest declaration\n * path (`profile.bio`), not just the leaf segment (`bio`).\n */\nconst RICH_FIELD_RE = /(\\w+)\\s*:\\s*new\\s+(?:[\\w.]+\\.)?(HTMLField|FilePathField)\\s*\\(/g;\n\ninterface RichFieldUsage {\n fieldName: string;\n type: 'HTMLField' | 'FilePathField';\n line: number;\n enclosingClass: string | undefined;\n /** Dot-path through SchemaField nesting (e.g. `profile.bio`, or just `bio` at top level). */\n schemaPath: string;\n}\n\nfunction findRichFields(content: string, classes: ClassRange[]): RichFieldUsage[] {\n const out: RichFieldUsage[] = [];\n for (const m of content.matchAll(RICH_FIELD_RE)) {\n if (m.index === undefined) continue;\n let line = 1;\n for (let i = 0; i < m.index; i += 1) {\n if (content[i] === '\\n') line += 1;\n }\n const fieldName = m[1] ?? '(anonymous)';\n out.push({\n fieldName,\n type: (m[2] as 'HTMLField' | 'FilePathField') ?? 'HTMLField',\n line,\n enclosingClass: findEnclosingClass(classes, m.index),\n schemaPath: buildSchemaPath(content, m.index, fieldName),\n });\n }\n return out;\n}\n\n/**\n * Walk backward from a rich-field match looking for enclosing SchemaField\n * wrappers, building the dot-path up to the outermost schema.\n *\n * For `profile: new SchemaField({ bio: new HTMLField() })`, the rich-field\n * match is `bio: new HTMLField(`; walking back, we find the enclosing `{`\n * that's preceded by `profile: new ...SchemaField(`, prepend `profile`, and\n * recurse. Top-level fields (immediate children of `defineSchema()`'s\n * returned object) recurse until the enclosing `{` has no SchemaField\n * ancestor, returning just the field name.\n */\nfunction buildSchemaPath(content: string, idx: number, fieldName: string): string {\n // Find the immediate enclosing `{` by walking backward, tracking balance.\n let depth = 0;\n let openIdx = -1;\n for (let i = idx - 1; i >= 0; i -= 1) {\n const ch = content[i];\n if (ch === '}') depth += 1;\n else if (ch === '{') {\n if (depth === 0) {\n openIdx = i;\n break;\n }\n depth -= 1;\n }\n }\n if (openIdx < 0) return fieldName;\n\n // Look at the text immediately preceding the enclosing `{` for a\n // `<key>: new <prefix>SchemaField(` pattern. The lookback window is\n // bounded so we don't accidentally cross other constructs.\n const lookbackStart = Math.max(0, openIdx - 200);\n const before = content.slice(lookbackStart, openIdx);\n const m = before.match(/(\\w+)\\s*:\\s*new\\s+(?:[\\w.]+\\.)?SchemaField\\s*\\(\\s*$/);\n if (!m) return fieldName;\n const parentName = m[1] ?? '';\n if (!parentName) return fieldName;\n // The parent's match position relative to content; recurse from there\n // so multi-level nesting (`profile.contact.email`) is captured.\n const parentMatchStart = lookbackStart + (m.index ?? 0);\n const parentPath = buildSchemaPath(content, parentMatchStart, parentName);\n return `${parentPath}.${fieldName}`;\n}\n\ninterface DeclaredFields {\n /**\n * Keyed `Doc.subtype` → declared htmlFields / filePathFields.\n * Paths are stored AFTER stripping a leading `system.` prefix (Foundry\n * convention puts TypeDataModel-driven manifests under `system.…`) so\n * we can compare against source-side paths that don't include the\n * `system.` root.\n */\n perSubtype: Map<string, { html: Set<string>; filePath: Set<string> }>;\n /**\n * The manifest's own `id`. Modules declare subtypes under a bare key\n * (`vehicle`) but Foundry registers them prefixed (`my-module.vehicle`),\n * which is the form that appears in source. Stripping this prefix is\n * what lets the two sides meet.\n */\n packageId: string | null;\n /** Union across every subtype; used as a fallback when class→subtype lookup fails. */\n globalHtml: Set<string>;\n globalFilePath: Set<string>;\n}\n\n/**\n * Foundry's manifest convention puts TypeDataModel-driven field paths\n * under the `system.` root (`system.biography`). Source-side rich-field\n * paths from `buildSchemaPath` don't include that prefix because they\n * start from `defineSchema()`'s returned object. Strip it for matching.\n */\nfunction normalizeDeclaredPath(path: string): string {\n return path.startsWith('system.') ? path.slice('system.'.length) : path;\n}\n\n/**\n * Find one subtype's declarations, accounting for the module prefix.\n *\n * A system declares `character` in the manifest and registers `character`\n * in source, so the two match directly. A module declares `vehicle` but\n * Foundry registers it as `my-module.vehicle`, and that prefixed form is\n * what appears in source. Comparing the two verbatim reports every\n * correctly declared module field as missing, so fall back to the bare key\n * once the package's own prefix is stripped.\n *\n * Only this package's prefix is stripped. A subtype contributed by some\n * other module is genuinely not ours to have declared.\n */\nfunction lookupSubtype(\n declared: DeclaredFields,\n doc: string,\n subtype: string,\n): { html: Set<string>; filePath: Set<string> } | undefined {\n const direct = declared.perSubtype.get(`${doc}.${subtype}`);\n if (direct) return direct;\n const prefix = declared.packageId ? `${declared.packageId}.` : null;\n if (!prefix || !subtype.startsWith(prefix)) return undefined;\n return declared.perSubtype.get(`${doc}.${subtype.slice(prefix.length)}`);\n}\n\n/**\n * VTTF-AUDIT-004: cross-check source HTMLField/FilePathField usages\n * against the manifest's documentTypes declarations.\n *\n * Subtype-aware: if the enclosing class is registered on\n * `CONFIG.<Doc>.dataModels.<subtype>`, the field must be declared in\n * THAT subtype's htmlFields / filePathFields. Otherwise (class\n * unregistered, registration spread across files, dynamic registration)\n * we fall back to the global union check (catches the common \"forgot to\n * declare anything\" case without false positives on advanced setups).\n */\nfunction rule004(\n filePath: string,\n content: string,\n declared: DeclaredFields,\n classToSubtypes: Map<string, ConfigMapping[]>,\n): RuleResult[] {\n const classes = findSchemaOwnerRanges(content);\n const usages = findRichFields(content, classes);\n const out: RuleResult[] = [];\n for (const usage of usages) {\n const declaredBucketName = usage.type === 'HTMLField' ? 'htmlFields' : 'filePathFields';\n const mappings = usage.enclosingClass ? (classToSubtypes.get(usage.enclosingClass) ?? []) : [];\n const sourcePath = usage.schemaPath;\n\n if (mappings.length > 0) {\n // Strict per-subtype check: every subtype this class is registered\n // under must declare the field's FULL source path. `profile.bio`\n // declared in `Actor.character` doesn't cover an undeclared\n // `profile.bio` in `Actor.npc`.\n const missing = mappings.filter((mapping) => {\n const decl = lookupSubtype(declared, mapping.doc, mapping.subtype);\n const bucket = usage.type === 'HTMLField' ? decl?.html : decl?.filePath;\n return !bucket?.has(sourcePath);\n });\n if (missing.length > 0) {\n const locations = missing.map((mapping) => `${mapping.doc}.${mapping.subtype}`).join(', ');\n out.push({\n ruleId: 'VTTF-AUDIT-004',\n title: `${usage.type} not declared in manifest documentTypes`,\n severity: 'MEDIUM',\n filePath,\n line: usage.line,\n message: `\\`${usage.enclosingClass}\\` declares \\`${sourcePath}\\` as ${usage.type}, but documentTypes.${locations}.${declaredBucketName} does not list this path. The Foundry server only sanitises declared paths.`,\n remediation: `Add \\`${sourcePath}\\` (or \\`system.${sourcePath}\\`) to documentTypes.${missing[0]?.doc}.${missing[0]?.subtype}.${declaredBucketName} in your manifest.`,\n });\n }\n continue;\n }\n\n // Fallback: no class→subtype mapping detected (class not registered,\n // registration via an unrecognized API, dynamic registration). Check\n // the global union: still useful, but with looser semantics. Match\n // on FULL source path so `profile.bio` declared doesn't silently\n // shadow an undeclared `journal.bio`.\n const bucket = usage.type === 'HTMLField' ? declared.globalHtml : declared.globalFilePath;\n if (bucket.has(sourcePath)) continue;\n out.push({\n ruleId: 'VTTF-AUDIT-004',\n title: `${usage.type} not declared in manifest documentTypes`,\n severity: 'MEDIUM',\n filePath,\n line: usage.line,\n message: `Schema declares \\`${sourcePath}\\` as ${usage.type}, but no documentTypes.<Doc>.<subtype>.${declaredBucketName} entry lists this path. The Foundry server only sanitises declared paths.`,\n remediation: `Add \\`${sourcePath}\\` (or \\`system.${sourcePath}\\`) to documentTypes.<Doc>.<subtype>.${declaredBucketName} in your manifest.`,\n });\n }\n return out;\n}\n\n/**\n * VTTF-AUDIT-007: manifest's `primaryTokenAttribute` /\n * `secondaryTokenAttribute` must point at a SchemaField with `value` +\n * `max` keys. If not, Foundry's `getBarAttribute` silently degrades to\n * value-only rendering (no bar at all).\n *\n * Cross-check walks the source for every SchemaField declaration paired\n * with its full schema path (`buildSchemaPath`). The manifest path is\n * matched EXACTLY: `primaryTokenAttribute: 'health'` does not accept a\n * nested `attributes.health` SchemaField, and a nested path like\n * `attributes.hp` is resolved by finding the declaration at that exact\n * dot-path. No more \"verify manually\" branch; either the path resolves\n * or it doesn't.\n */\nasync function rule007(\n manifestPath: string | null,\n manifestRaw: string | null,\n manifestParsed: Record<string, unknown> | null,\n sourceFiles: string[],\n classToSubtypes: Map<string, ConfigMapping[]>,\n): Promise<RuleResult[]> {\n if (!manifestPath || !manifestRaw || !manifestParsed) return [];\n const actorClasses = new Set(\n [...classToSubtypes.entries()]\n .filter(([, mappings]) => mappings.some((m) => m.doc === 'Actor'))\n .map(([className]) => className),\n );\n\n const out: RuleResult[] = [];\n for (const key of ['primaryTokenAttribute', 'secondaryTokenAttribute'] as const) {\n const value = manifestParsed[key];\n if (typeof value !== 'string' || value.length === 0) continue;\n const matched =\n (await sourceHasValueMaxSchemaAtPath(sourceFiles, value, actorClasses)) ||\n templateJsonHasValueMax(manifestPath, value);\n if (!matched) {\n out.push({\n ruleId: 'VTTF-AUDIT-007',\n title: `${key} does not resolve to a {value, max} SchemaField`,\n severity: 'MEDIUM',\n filePath: manifestPath,\n line: lineOfInRaw(manifestRaw, key),\n message: `Manifest ${key} is \\`${value}\\`, but no TypeDataModel schema in the source declares a SchemaField at this path with both \\`value\\` and \\`max\\` keys. Foundry's getBarAttribute degrades silently when the structure doesn't match.`,\n remediation: `Define \\`${value}\\` as a SchemaField with \\`value\\` and \\`max\\` NumberField children in your TypeDataModel schema (matching the manifest path exactly).`,\n });\n }\n }\n return out;\n}\n\n/**\n * The same check against `template.json`, for a system that still declares\n * its types there. Each Actor type is the merge of the templates it lists and\n * its own keys; the path resolves when any type has an object with `value`\n * and `max` at it. Foundry reads the bar the same way, per actor.\n */\nfunction templateJsonHasValueMax(manifestPath: string, path: string): boolean {\n const file = join(dirname(manifestPath), 'template.json');\n if (!existsSync(file)) return false;\n let template: Record<string, unknown>;\n try {\n template = JSON.parse(readFileSync(file, 'utf8')) as Record<string, unknown>;\n } catch {\n return false;\n }\n const actor = template.Actor;\n if (!actor || typeof actor !== 'object') return false;\n const { types = [], templates = {} } = actor as {\n types?: string[];\n templates?: Record<string, Record<string, unknown>>;\n };\n for (const type of types) {\n const own = (actor as Record<string, unknown>)[type];\n if (!own || typeof own !== 'object') continue;\n const merged: Record<string, unknown> = {};\n for (const name of (own as { templates?: string[] }).templates ?? []) {\n Object.assign(merged, templates[name] ?? {});\n }\n Object.assign(merged, own);\n let node: unknown = merged;\n for (const segment of path.split('.')) {\n if (!node || typeof node !== 'object') break;\n node = (node as Record<string, unknown>)[segment];\n }\n if (node && typeof node === 'object' && 'value' in node && 'max' in node) return true;\n }\n return false;\n}\n\nfunction lineOfInRaw(raw: string, key: string): number | undefined {\n const idx = raw.indexOf(`\"${key}\"`);\n if (idx < 0) return undefined;\n let line = 1;\n for (let i = 0; i < idx; i += 1) {\n if (raw[i] === '\\n') line += 1;\n }\n return line;\n}\n\n/**\n * Path-aware lookup for the rule-007 cross-check. For every SchemaField\n * declaration in every source file, compute its FULL schema path via\n * `buildSchemaPath`. Match the manifest's `primaryTokenAttribute` (which\n * may be a single key like `health` or a dotted path like `attributes.hp`)\n * against the declaration's path exactly. Only declarations whose schema\n * path equals the manifest value contribute to the value+max check.\n *\n * Why exact path: an unqualified `health: new SchemaField(...)` inside\n * `attributes: new SchemaField({...})` has schema path `attributes.health`.\n * Manifest `primaryTokenAttribute: 'health'` should NOT resolve to that\n * nested declaration. Foundry walks the document path structurally and\n * would look for `health.value` at the top of `system`, not under\n * `attributes`.\n */\nasync function sourceHasValueMaxSchemaAtPath(\n sourceFiles: string[],\n targetPath: string,\n actorClasses: ReadonlySet<string>,\n): Promise<boolean> {\n for (const file of sourceFiles) {\n let content: string;\n try {\n content = await readFile(file, 'utf8');\n } catch {\n continue;\n }\n const classes = findSchemaOwnerRanges(content);\n for (const decl of findAllSchemaFields(content)) {\n if (decl.path !== targetPath) continue;\n // Token bars read `actor.system`, so only a schema registered as an\n // Actor data model can satisfy the manifest. An Item model that\n // happens to declare the same path does not. Accepting it would\n // pass the rule on a system whose token bars are in fact broken.\n //\n // This narrowing only applies when the registrations are known.\n // With none found there is no ground truth to narrow by, so every\n // declaration counts, the same fallback rule 004 takes when it cannot\n // resolve a class to its subtypes.\n // A declaration outside any class is a shared fragment (a `baseFields(f)`\n // several models spread); it is not an Item model, so it counts.\n if (actorClasses.size > 0) {\n const owner = classes.find((c) => decl.index > c.openIdx && decl.index < c.endIdx);\n if (owner && !actorClasses.has(owner.className)) continue;\n }\n const topKeys = extractTopLevelKeys(decl.body);\n if (topKeys.has('value') && topKeys.has('max')) return true;\n }\n }\n return false;\n}\n\n/**\n * Find every `<name>: new ...SchemaField({...})` declaration in `content`,\n * returning each with its FULL dot-path through enclosing SchemaField\n * wrappers and the raw object-literal body. Used by rule 007 to look up\n * a SchemaField at an exact manifest path.\n */\ninterface SchemaFieldDecl {\n path: string;\n body: string;\n /** Offset of the declaration, used to find its enclosing class. */\n index: number;\n}\n\nfunction findAllSchemaFields(content: string): SchemaFieldDecl[] {\n const out: SchemaFieldDecl[] = [];\n const startRe = /(\\w+)\\s*:\\s*new\\s+(?:[\\w.]+\\.)?SchemaField\\s*\\(\\s*\\{/g;\n for (const m of content.matchAll(startRe)) {\n if (m.index === undefined) continue;\n const fieldName = m[1] ?? '';\n const openIdx = m.index + m[0].length - 1;\n let depth = 0;\n let endIdx = -1;\n for (let i = openIdx; i < content.length; i += 1) {\n if (content[i] === '{') depth += 1;\n else if (content[i] === '}') {\n depth -= 1;\n if (depth === 0) {\n endIdx = i;\n break;\n }\n }\n }\n if (endIdx < 0) continue;\n out.push({\n path: buildSchemaPath(content, m.index, fieldName),\n body: content.slice(openIdx + 1, endIdx),\n index: m.index,\n });\n }\n return out;\n}\n\n/**\n * Extract identifier keys declared at depth 0 of an object-literal body.\n *\n * The naive `value:`/`max:` regex check matches nested constructor options\n * too: `value: new NumberField({ max: 100 })` looked to a flat regex like\n * both keys were SchemaField siblings. Walking the body byte-by-byte with\n * depth tracking + string-boundary handling correctly distinguishes\n * top-level keys from nested ones.\n */\nfunction extractTopLevelKeys(body: string): Set<string> {\n const keys = new Set<string>();\n let depth = 0;\n let inString: '\"' | \"'\" | '`' | null = null;\n let escaped = false;\n let pos = 0;\n const idStart = /[a-zA-Z_$]/;\n const idCont = /[\\w$]/;\n const ws = /\\s/;\n while (pos < body.length) {\n const ch = body[pos];\n if (ch === undefined) break;\n if (escaped) {\n escaped = false;\n pos += 1;\n continue;\n }\n if (inString) {\n if (ch === '\\\\') escaped = true;\n else if (ch === inString) inString = null;\n pos += 1;\n continue;\n }\n if (ch === '\"' || ch === \"'\" || ch === '`') {\n inString = ch;\n pos += 1;\n continue;\n }\n if (ch === '{' || ch === '(' || ch === '[') {\n depth += 1;\n pos += 1;\n continue;\n }\n if (ch === '}' || ch === ')' || ch === ']') {\n depth -= 1;\n pos += 1;\n continue;\n }\n if (depth === 0 && idStart.test(ch)) {\n let end = pos;\n while (end < body.length && idCont.test(body[end] ?? '')) end += 1;\n const name = body.slice(pos, end);\n let after = end;\n while (after < body.length && ws.test(body[after] ?? '')) after += 1;\n if (body[after] === ':') {\n keys.add(name);\n pos = after + 1;\n continue;\n }\n pos = end;\n continue;\n }\n pos += 1;\n }\n return keys;\n}\n\n/**\n * Load every manifest at the project root, then return:\n * - declared.perSubtype: per `Doc.subtype` htmlFields / filePathFields sets\n * - declared.globalHtml / globalFilePath: union across all subtypes\n * - manifest path/raw/parsed for the manifest we found first\n *\n * Used by rules 004 and 007. The per-subtype map lets rule 004 do a strict\n * cross-check when it knows which subtype a source class is registered to;\n * the global union is the fallback when no class→subtype mapping is found.\n */\nasync function collectDeclaredRichFields(cwd: string): Promise<{\n declared: DeclaredFields;\n manifestPath: string | null;\n manifestRaw: string | null;\n manifestParsed: Record<string, unknown> | null;\n}> {\n const perSubtype = new Map<string, { html: Set<string>; filePath: Set<string> }>();\n const globalHtml = new Set<string>();\n const globalFilePath = new Set<string>();\n let manifestPath: string | null = null;\n let manifestRaw: string | null = null;\n let manifestParsed: Record<string, unknown> | null = null;\n let packageId: string | null = null;\n\n for (const file of ['system.json', 'module.json']) {\n const p = join(cwd, file);\n if (!existsSync(p)) continue;\n let raw: string;\n try {\n raw = await readFile(p, 'utf8');\n } catch {\n continue;\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n continue;\n }\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) continue;\n if (!manifestPath) {\n manifestPath = p;\n manifestRaw = raw;\n manifestParsed = parsed as Record<string, unknown>;\n const id = (parsed as Record<string, unknown>).id;\n packageId = typeof id === 'string' && id.length > 0 ? id : null;\n }\n const docTypes = (parsed as Record<string, unknown>).documentTypes;\n if (!docTypes || typeof docTypes !== 'object' || Array.isArray(docTypes)) continue;\n for (const [docName, docType] of Object.entries(docTypes as Record<string, unknown>)) {\n if (!docType || typeof docType !== 'object' || Array.isArray(docType)) continue;\n for (const [subName, subtype] of Object.entries(docType as Record<string, unknown>)) {\n if (!subtype || typeof subtype !== 'object' || Array.isArray(subtype)) continue;\n const sub = subtype as Record<string, unknown>;\n const key = `${docName}.${subName}`;\n const entry = perSubtype.get(key) ?? {\n html: new Set<string>(),\n filePath: new Set<string>(),\n };\n if (Array.isArray(sub.htmlFields)) {\n for (const e of sub.htmlFields) {\n if (typeof e === 'string') {\n const normalized = normalizeDeclaredPath(e);\n entry.html.add(normalized);\n globalHtml.add(normalized);\n }\n }\n }\n // `filePathFields` is an object, not an array: its KEYS are the\n // field paths and each value lists the file categories allowed\n // there. `htmlFields` above really is a flat array; the two\n // differ, and reading both as arrays drops every correctly\n // declared path.\n for (const declaredPath of declaredFilePathKeys(sub.filePathFields)) {\n const normalized = normalizeDeclaredPath(declaredPath);\n entry.filePath.add(normalized);\n globalFilePath.add(normalized);\n }\n perSubtype.set(key, entry);\n }\n }\n }\n // A system that still ships template.json declares its rich fields there,\n // at the document level. While the file exists the server resets each\n // listed type's documentTypes entry and copies that document-level block\n // back, so those paths are declared for every type the file lists.\n const templatePath = join(cwd, 'template.json');\n if (existsSync(templatePath)) {\n let template: unknown;\n try {\n template = JSON.parse(await readFile(templatePath, 'utf8'));\n } catch {\n template = null;\n }\n if (template && typeof template === 'object' && !Array.isArray(template)) {\n for (const [docName, doc] of Object.entries(template as Record<string, unknown>)) {\n if (!doc || typeof doc !== 'object' || Array.isArray(doc)) continue;\n const { types, htmlFields, filePathFields } = doc as {\n types?: unknown;\n htmlFields?: unknown;\n filePathFields?: unknown;\n };\n if (!Array.isArray(types)) continue;\n const html = Array.isArray(htmlFields)\n ? htmlFields.filter((e): e is string => typeof e === 'string').map(normalizeDeclaredPath)\n : [];\n const filePath = declaredFilePathKeys(filePathFields).map(normalizeDeclaredPath);\n for (const type of types) {\n if (typeof type !== 'string') continue;\n const key = `${docName}.${type}`;\n const entry = perSubtype.get(key) ?? {\n html: new Set<string>(),\n filePath: new Set<string>(),\n };\n for (const path of html) {\n entry.html.add(path);\n globalHtml.add(path);\n }\n for (const path of filePath) {\n entry.filePath.add(path);\n globalFilePath.add(path);\n }\n perSubtype.set(key, entry);\n }\n }\n }\n }\n return {\n declared: { perSubtype, packageId, globalHtml, globalFilePath },\n manifestPath,\n manifestRaw,\n manifestParsed,\n };\n}\n\n/**\n * Read the declared file-path keys off one subtype's `filePathFields`.\n *\n * The manifest shape is an object keyed by field path, whose values name\n * the permitted file categories. Older hand-written manifests sometimes\n * carry a bare array instead; that shape does not validate, but reading it\n * costs nothing and avoids reporting a field as undeclared when the author\n * plainly declared it.\n */\nfunction declaredFilePathKeys(value: unknown): string[] {\n if (Array.isArray(value)) {\n return value.filter((e): e is string => typeof e === 'string');\n }\n if (value && typeof value === 'object') {\n return Object.keys(value as Record<string, unknown>);\n }\n return [];\n}\n\n/**\n * Aggregate every `CONFIG.<Doc>.dataModels.<subtype> = <ClassName>`\n * mapping discovered across all source files, keyed by class name.\n * Rule 004 reads this to determine which subtype each rich-field's\n * enclosing class is registered under.\n */\nfunction buildClassToSubtypes(fileContents: Iterable<string>): Map<string, ConfigMapping[]> {\n const map = new Map<string, ConfigMapping[]>();\n for (const content of fileContents) {\n for (const mapping of findConfigMappings(content)) {\n if (!mapping.className) continue;\n const existing = map.get(mapping.className) ?? [];\n existing.push(mapping);\n map.set(mapping.className, existing);\n }\n }\n return map;\n}\n\n/** Strip a dot-path to its final segment (e.g. `system.biography` → `biography`). */\nfunction lastSegment(path: string): string {\n const idx = path.lastIndexOf('.');\n return idx < 0 ? path : path.slice(idx + 1);\n}\n\n/** Entry point: gather everything once, then dispatch to the per-file rules. */\nexport async function runSourceRules(cwd: string): Promise<RuleResult[]> {\n if (!existsSync(cwd)) return [];\n const info = await stat(cwd);\n if (!info.isDirectory()) return [];\n\n const { declared, manifestPath, manifestRaw, manifestParsed } =\n await collectDeclaredRichFields(cwd);\n const sourceFiles: string[] = [];\n for await (const file of walkSourceFiles(cwd)) {\n sourceFiles.push(file);\n }\n\n // Read every source file once so rule 004's class→subtype map can scan\n // across the whole project (CONFIG mappings frequently live in `main.ts`\n // separate from the data-model files).\n const contents = new Map<string, string>();\n for (const file of sourceFiles) {\n try {\n contents.set(file, await readFile(file, 'utf8'));\n } catch {\n // skip unreadable files\n }\n }\n const classToSubtypes = buildClassToSubtypes(contents.values());\n\n const results: RuleResult[] = [];\n for (const [file, content] of contents) {\n results.push(...rule005(file, content));\n results.push(...rule006(file, content));\n results.push(...rule004(file, content, declared, classToSubtypes));\n }\n results.push(\n ...(await rule007(manifestPath, manifestRaw, manifestParsed, sourceFiles, classToSubtypes)),\n );\n return results;\n}\n\n// Internal helpers exported so tests can drive the file walker without\n// pulling in the orchestrator's manifest dependency.\nexport const _internal = {\n walkSourceFiles,\n walkTemplateFiles,\n isSourceFile,\n lineOf,\n lastSegment,\n // Shared with template-rules.ts, which has to know which class a `PARTS`\n // entry belongs to before it can say whether its template is wrong.\n findClassRanges,\n EXCLUDED_DIRS,\n};\n","/**\n * Template-scope audit rules.\n *\n * VTTF-AUDIT-008 (HIGH): a sheet template that opens its own `<form>`\n *\n * The two rules before this read the manifest and the source. This one reads\n * the Handlebars, because that is where the mistake lives and nothing else\n * looks there.\n */\n\nimport { readFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport { _internal } from './source-rules.js';\nimport type { RuleResult } from './types.js';\n\n/**\n * The bases that make the application element a form.\n *\n * `BaseActorSheet` and `BaseItemSheet` set `tag: 'form'`, which is what makes\n * `submitOnChange` work at all. `BaseApplication` and `BaseDocumentSheet` do\n * not, and a template of theirs may open a form of its own quite correctly.\n */\nconst FORM_TAGGED_BASES = /extends\\s+(?:[\\w.]+\\.)?(?:BaseActorSheet|BaseItemSheet)\\s*\\(/;\n\n/** `template: '.../foo.hbs'`, in a `static PARTS` block or anywhere near one. */\nconst TEMPLATE_RE = /template:\\s*[`'\"]([^`'\"]*\\.hbs)[`'\"]/g;\n\n/** A `<form>` start tag, ignoring what a Handlebars comment says about one. */\nconst FORM_TAG_RE = /<form[\\s>]/i;\nconst HANDLEBARS_COMMENT_RE = /\\{\\{!--[\\s\\S]*?--\\}\\}|\\{\\{![^}]*\\}\\}/g;\n\n/** Blank out Handlebars comments, keeping their newlines so line numbers still point at the source. */\nfunction withoutComments(source: string): string {\n return source.replace(HANDLEBARS_COMMENT_RE, (m) => m.replace(/[^\\n]/g, ''));\n}\n\n/**\n * The templates a form-tagged sheet declares, as paths inside the project.\n *\n * A `PARTS` entry names the path Foundry serves it from, like\n * `systems/my-system/templates/actor/sheet.hbs`. On disk the package root is\n * the project root, so the first two segments come off.\n */\nfunction templatesOfFormSheets(source: string): string[] {\n const classes = _internal.findClassRanges(source);\n const out: string[] = [];\n for (const match of source.matchAll(TEMPLATE_RE)) {\n if (match.index === undefined) continue;\n const owner = classes.find((c) => match.index > c.openIdx && match.index < c.endIdx);\n if (!owner) continue;\n // Look at the class header, which is where `extends` is.\n const header = source.slice(Math.max(0, owner.openIdx - 240), owner.openIdx);\n if (!FORM_TAGGED_BASES.test(header)) continue;\n const served = match[1];\n if (served === undefined) continue;\n const parts = served.split('/');\n // `systems/<id>/…` and `modules/<id>/…` both map to the project root.\n const local = parts[0] === 'systems' || parts[0] === 'modules' ? parts.slice(2) : parts;\n if (local.length > 0) out.push(local.join('/'));\n }\n return [...new Set(out)];\n}\n\n/**\n * VTTF-AUDIT-008 (HIGH) — a sheet template that opens its own `<form>`.\n *\n * `BaseActorSheet` and `BaseItemSheet` set `tag: 'form'`, so the application\n * element already is one. A `<form>` inside it owns every field inside it,\n * and the submit reads the outer element: `new FormData` on it comes back\n * empty and nothing is written.\n *\n * HIGH because of how it fails. There is no error and no warning. The sheet\n * looks right, accepts what you type, and drops it when the window closes.\n */\n/**\n * VTTF-AUDIT-021 (HIGH) — a Handlebars helper v14 removed.\n *\n * `{{#select}}` and `{{colorPicker}}` are gone. A template that still calls\n * one fails to render with \"Missing helper\", and the sheet, dialog or settings\n * form it belongs to never opens. Every `.hbs` / `.html` in the project is\n * read, since the failing template can belong to anything.\n */\nconst REMOVED_HELPERS: ReadonlyArray<{ pattern: RegExp; name: string; fix: string }> = [\n {\n pattern: /\\{\\{#?select\\b/,\n name: '{{#select}}',\n fix: 'Replace the block with `{{selectOptions choices selected=value}}` (add `localize=true` when the labels are keys), or write the `<option>` list with `{{#each}}` and a `selected` attribute you compute yourself.',\n },\n {\n pattern: /\\{\\{colorPicker\\b/,\n name: '{{colorPicker}}',\n fix: 'Replace it with the `<color-picker>` element, `<color-picker name=\"...\" value=\"{{value}}\"></color-picker>`.',\n },\n];\n\nasync function runRemovedHelperRule(cwd: string): Promise<RuleResult[]> {\n const results: RuleResult[] = [];\n const files: string[] = [];\n for await (const file of _internal.walkTemplateFiles(cwd)) files.push(file);\n for (const path of files.sort()) {\n let source: string;\n try {\n source = await readFile(path, 'utf8');\n } catch {\n continue;\n }\n const markup = withoutComments(source);\n for (const helper of REMOVED_HELPERS) {\n if (!helper.pattern.test(markup)) continue;\n const line = markup.split('\\n').findIndex((text) => helper.pattern.test(text)) + 1;\n results.push({\n ruleId: 'VTTF-AUDIT-021',\n title: 'Template calls a Handlebars helper v14 removed',\n severity: 'HIGH',\n filePath: relative(cwd, path),\n line: line > 0 ? line : 1,\n message: `${helper.name} was removed in v14. Rendering this template throws \"Missing helper\", so whatever renders it never opens.`,\n remediation: helper.fix,\n });\n }\n }\n return results;\n}\n\nexport async function runTemplateRules(cwd: string): Promise<RuleResult[]> {\n const removedHelpers = await runRemovedHelperRule(cwd);\n const templates = new Set<string>();\n for await (const file of _internal.walkSourceFiles(cwd)) {\n let content: string;\n try {\n content = await readFile(file, 'utf8');\n } catch {\n continue;\n }\n for (const template of templatesOfFormSheets(content)) templates.add(template);\n }\n\n const results: RuleResult[] = [];\n for (const template of [...templates].sort()) {\n const path = join(cwd, template);\n let source: string;\n try {\n source = await readFile(path, 'utf8');\n } catch {\n // A `PARTS` entry naming a file that is not there is a different\n // problem, and Foundry reports that one itself.\n continue;\n }\n const markup = withoutComments(source);\n if (!FORM_TAG_RE.test(markup)) continue;\n\n const lines = markup.split('\\n');\n const line = lines.findIndex((text) => FORM_TAG_RE.test(text)) + 1;\n results.push({\n ruleId: 'VTTF-AUDIT-008',\n title: 'Sheet template opens a form the sheet already is',\n severity: 'HIGH',\n filePath: relative(cwd, path) || template,\n line: line > 0 ? line : 1,\n message:\n 'This template is rendered by a sheet built on BaseActorSheet or BaseItemSheet, which set `tag: \"form\"`, so the application element already is a form. A nested form owns the fields inside it, so the submit reads the outer element and finds nothing. Every edit is dropped when the window closes, with no error.',\n remediation:\n 'Replace the `<form>` wrapper with a `<div>`. Keep one root element: a part that renders several top-level elements fails to render. The fields belong to the application element, and `submitOnChange` saves them as they change.',\n });\n }\n return [...results, ...removedHelpers];\n}\n","/**\n * Shared types for the `vttforge audit` rule engine.\n *\n * The audit catalog covers the breakages that fail quietly on v14. Each rule produces zero or more `RuleResult` entries; the\n * orchestrator aggregates them into an `AuditReport` which the reporter\n * renders as JSON or markdown.\n *\n * The CLI never touches the source tree; audit is purely read-only.\n */\n\nexport type Severity = 'HIGH' | 'MEDIUM' | 'LOW';\n\nexport interface RuleResult {\n /** Stable identifier, used by users to suppress / pin / look up specific rules. */\n ruleId: string;\n /** Human title. Shown in markdown report headers. */\n title: string;\n severity: Severity;\n /** Absolute or project-relative path of the file the finding refers to. */\n filePath: string;\n /** Optional line number (1-based) inside `filePath`. */\n line?: number;\n /** One-line description of what was found. */\n message: string;\n /** Optional follow-up describing how to fix it. */\n remediation?: string;\n}\n\nexport interface AuditReport {\n /** Project root the audit ran against. */\n cwd: string;\n /** ISO timestamp of when the run started. */\n startedAt: string;\n /** Findings, ordered by severity then by ruleId. */\n findings: ReadonlyArray<RuleResult>;\n /** Per-severity tallies, for exit-code logic and report headers. */\n counts: { HIGH: number; MEDIUM: number; LOW: number };\n}\n\n/** Severity rank for sorting (HIGH first). */\nexport const SEVERITY_RANK: Record<Severity, number> = {\n HIGH: 0,\n MEDIUM: 1,\n LOW: 2,\n};\n\n/**\n * A rule is a plain function over the project root. Manifest rules parse\n * `system.json` / `module.json`; source rules walk `scripts/` / `src/`.\n * Rules return their own findings; the orchestrator stitches them\n * together. Pure functions over the filesystem so tests inject tmp dirs.\n */\n// (kept here for tests/library consumers that want to define their own rules)\nexport type RuleFn = (cwd: string) => Promise<RuleResult[]> | RuleResult[];\n","/**\n * The bare globals v13 turned into aliases of a `foundry.*` path.\n *\n * Each still resolves on v14 with a deprecation warning, and none resolves\n * on v15. The namespaced path is the same object, so a rewrite from one to\n * the other changes nothing at runtime and removes a removal date. The list\n * is the part of the public API a system or module is likely to reach for\n * bare; the canvas shaders and the rest are left out on purpose.\n *\n * `Application`, `FormApplication`, `Dialog` and `DocumentSheet` are not\n * here: those are plain aliases with no warning, and the whole v1 framework\n * goes in v16, which `VTTF-AUDIT-018` reports.\n */\nexport const LEGACY_GLOBALS: Readonly<Record<string, string>> = Object.freeze({\n // Handlebars\n renderTemplate: 'foundry.applications.handlebars.renderTemplate',\n loadTemplates: 'foundry.applications.handlebars.loadTemplates',\n getTemplate: 'foundry.applications.handlebars.getTemplate',\n // Application v1 sheets\n ActorSheet: 'foundry.appv1.sheets.ActorSheet',\n ItemSheet: 'foundry.appv1.sheets.ItemSheet',\n JournalSheet: 'foundry.appv1.sheets.JournalSheet',\n JournalPageSheet: 'foundry.appv1.sheets.JournalPageSheet',\n JournalTextPageSheet: 'foundry.appv1.sheets.JournalTextPageSheet',\n // UX helpers\n TextEditor: 'foundry.applications.ux.TextEditor.implementation',\n ContextMenu: 'foundry.applications.ux.ContextMenu.implementation',\n DragDrop: 'foundry.applications.ux.DragDrop.implementation',\n Draggable: 'foundry.applications.ux.Draggable.implementation',\n FormDataExtended: 'foundry.applications.ux.FormDataExtended',\n SearchFilter: 'foundry.applications.ux.SearchFilter',\n Tabs: 'foundry.applications.ux.Tabs',\n ProseMirrorEditor: 'foundry.applications.ux.ProseMirrorEditor',\n FilePicker: 'foundry.applications.apps.FilePicker.implementation',\n ImagePopout: 'foundry.applications.apps.ImagePopout',\n DocumentSheetConfig: 'foundry.applications.apps.DocumentSheetConfig',\n // Sheets and configs\n ActiveEffectConfig: 'foundry.applications.sheets.ActiveEffectConfig',\n TokenConfig: 'foundry.applications.sheets.TokenConfig',\n SceneConfig: 'foundry.applications.sheets.SceneConfig',\n MacroConfig: 'foundry.applications.sheets.MacroConfig',\n SettingsConfig: 'foundry.applications.settings.SettingsConfig',\n // Sidebar and UI\n Sidebar: 'foundry.applications.sidebar.Sidebar',\n ChatLog: 'foundry.applications.sidebar.tabs.ChatLog',\n CombatTracker: 'foundry.applications.sidebar.tabs.CombatTracker',\n ActorDirectory: 'foundry.applications.sidebar.tabs.ActorDirectory',\n ItemDirectory: 'foundry.applications.sidebar.tabs.ItemDirectory',\n JournalDirectory: 'foundry.applications.sidebar.tabs.JournalDirectory',\n CompendiumDirectory: 'foundry.applications.sidebar.tabs.CompendiumDirectory',\n Compendium: 'foundry.applications.sidebar.apps.Compendium',\n ModuleManagement: 'foundry.applications.sidebar.apps.ModuleManagement',\n Hotbar: 'foundry.applications.ui.Hotbar',\n SceneControls: 'foundry.applications.ui.SceneControls',\n SceneNavigation: 'foundry.applications.ui.SceneNavigation',\n Players: 'foundry.applications.ui.Players',\n Notifications: 'foundry.applications.ui.Notifications',\n TokenHUD: 'foundry.applications.hud.TokenHUD',\n // Collections\n Actors: 'foundry.documents.collections.Actors',\n Items: 'foundry.documents.collections.Items',\n Journal: 'foundry.documents.collections.Journal',\n Macros: 'foundry.documents.collections.Macros',\n Messages: 'foundry.documents.collections.ChatMessages',\n Playlists: 'foundry.documents.collections.Playlists',\n RollTables: 'foundry.documents.collections.RollTables',\n Scenes: 'foundry.documents.collections.Scenes',\n Users: 'foundry.documents.collections.Users',\n Folders: 'foundry.documents.collections.Folders',\n CompendiumCollection: 'foundry.documents.collections.CompendiumCollection',\n CompendiumPacks: 'foundry.documents.collections.CompendiumPacks',\n WorldCollection: 'foundry.documents.abstract.WorldCollection',\n DocumentCollection: 'foundry.documents.abstract.DocumentCollection',\n // Canvas\n Canvas: 'foundry.canvas.Canvas',\n CanvasLayer: 'foundry.canvas.layers.CanvasLayer',\n InteractionLayer: 'foundry.canvas.layers.InteractionLayer',\n PlaceablesLayer: 'foundry.canvas.layers.PlaceablesLayer',\n PlaceableObject: 'foundry.canvas.placeables.PlaceableObject',\n Token: 'foundry.canvas.placeables.Token',\n Tile: 'foundry.canvas.placeables.Tile',\n Drawing: 'foundry.canvas.placeables.Drawing',\n Note: 'foundry.canvas.placeables.Note',\n Wall: 'foundry.canvas.placeables.Wall',\n Region: 'foundry.canvas.placeables.Region',\n AmbientLight: 'foundry.canvas.placeables.AmbientLight',\n AmbientSound: 'foundry.canvas.placeables.AmbientSound',\n Ray: 'foundry.canvas.geometry.Ray',\n ClockwiseSweepPolygon: 'foundry.canvas.geometry.ClockwiseSweepPolygon',\n CanvasAnimation: 'foundry.canvas.animation.CanvasAnimation',\n ChatBubbles: 'foundry.canvas.animation.ChatBubbles',\n MouseInteractionManager: 'foundry.canvas.interaction.MouseInteractionManager',\n Ruler: 'foundry.canvas.interaction.Ruler',\n TextureLoader: 'foundry.canvas.TextureLoader',\n getTexture: 'foundry.canvas.getTexture',\n loadTexture: 'foundry.canvas.loadTexture',\n srcExists: 'foundry.canvas.srcExists',\n // Helpers\n ClientSettings: 'foundry.helpers.ClientSettings',\n ClientKeybindings: 'foundry.helpers.interaction.ClientKeybindings',\n GameTime: 'foundry.helpers.GameTime',\n Localization: 'foundry.helpers.Localization',\n SocketInterface: 'foundry.helpers.SocketInterface',\n TooltipManager: 'foundry.helpers.interaction.TooltipManager.implementation',\n VideoHelper: 'foundry.helpers.media.VideoHelper',\n ImageHelper: 'foundry.helpers.media.ImageHelper',\n AsyncWorker: 'foundry.helpers.AsyncWorker',\n SortingHelpers: 'foundry.utils.SortingHelpers',\n saveDataToFile: 'foundry.utils.saveDataToFile',\n readTextFromFile: 'foundry.utils.readTextFromFile',\n // Packages and tours\n Module: 'foundry.packages.Module',\n System: 'foundry.packages.System',\n World: 'foundry.packages.World',\n Tour: 'foundry.nue.Tour',\n Tours: 'foundry.nue.ToursCollection',\n});\n\n/**\n * Does the file declare or import the name itself?\n *\n * A module that defines its own `Token` class or imports `Tabs` from a\n * library is using that, not Foundry's global.\n */\nexport function definesName(source: string, name: string): boolean {\n return new RegExp(\n `(?:\\\\b(?:class|function|const|let|var)\\\\s+${name}\\\\b|import[^;]*\\\\b${name}\\\\b|\\\\b${name}\\\\s*\\\\([^)]*\\\\)\\\\s*\\\\{)`,\n ).test(source);\n}\n\n/**\n * A bare use of `name`: not a property (`x.Token`), not an object key\n * (`{ Token: 1 }`), not part of a longer identifier.\n */\nexport function bareUsePattern(name: string): RegExp {\n return new RegExp(`(?<![\\\\w$.])${name}\\\\b(?!\\\\s*:(?!:))(?=[\\\\s.(,;)\\\\]}]|$)`, 'gm');\n}\n","/**\n * Blank out the comments in a source file, so a pattern that names a call\n * or a key does not match the prose around it.\n *\n * Every character inside a `//` or `/* *\\/` comment becomes `\\0`, except the\n * newlines, so offsets and line numbers in the result line up with the\n * original. Strings and template literals are walked so a `//` inside a URL\n * does not start a comment, and a regex literal is walked so `/\\/\\//` does\n * not either. `\\0` never appears in real source, which is what makes it a\n * safe marker: `masked[i] === '\\0'` says \"this index is a comment\".\n */\nexport const MASK = '\\0';\n\nexport function maskComments(source: string, { strings = false } = {}): string {\n const out = source.split('');\n let quote: string | null = null;\n let lastCode = '';\n for (let i = 0; i < source.length; i += 1) {\n const ch = source[i] ?? '';\n const next = source[i + 1] ?? '';\n if (quote !== null) {\n if (ch === '\\\\') {\n if (strings) {\n out[i] = MASK;\n if (source[i + 1] !== '\\n') out[i + 1] = MASK;\n }\n i += 1;\n } else if (ch === quote) quote = null;\n else if (strings && ch !== '\\n') out[i] = MASK;\n continue;\n }\n if (ch === '\"' || ch === \"'\" || ch === '`') {\n quote = ch;\n lastCode = ch;\n continue;\n }\n if (ch === '/' && next === '/') {\n const end = source.indexOf('\\n', i);\n const stop = end === -1 ? source.length : end;\n for (let j = i; j < stop; j += 1) out[j] = MASK;\n i = stop - 1;\n continue;\n }\n if (ch === '/' && next === '*') {\n const close = source.indexOf('*/', i + 2);\n const stop = close === -1 ? source.length : close + 2;\n for (let j = i; j < stop; j += 1) if (source[j] !== '\\n') out[j] = MASK;\n i = stop - 1;\n continue;\n }\n if (ch === '/' && startsRegex(lastCode)) {\n // Walk to the closing slash, honouring escapes and character classes.\n let inClass = false;\n let j = i + 1;\n for (; j < source.length; j += 1) {\n const c = source[j] ?? '';\n if (c === '\\\\') j += 1;\n else if (c === '\\n') break;\n else if (inClass) inClass = c !== ']';\n else if (c === '[') inClass = true;\n else if (c === '/') break;\n }\n i = j;\n lastCode = '/';\n continue;\n }\n if (!/\\s/.test(ch)) lastCode = ch;\n }\n return out.join('');\n}\n\n/** After one of these a `/` opens a regex literal, not a division. */\nfunction startsRegex(lastCode: string): boolean {\n return lastCode === '' || '(,=:[!&|?{};+-*%<>~^'.includes(lastCode);\n}\n","/**\n * Source rules for the v13 code that v14 broke or deprecated.\n *\n * VTTF-AUDIT-011 (HIGH) : a bare utility global v14 removed (`mergeObject(`, ...)\n * VTTF-AUDIT-012 (MEDIUM): `-=` / `==` update keys, replaced by data operators\n * VTTF-AUDIT-013 (MEDIUM): `rollMode`, replaced by `messageMode`\n * VTTF-AUDIT-014 (MEDIUM): `CONFIG.statusEffects = [...]`, which empties the collection first\n * VTTF-AUDIT-015 (MEDIUM): `legacyTransferral`, a flag v14 no longer reads\n * VTTF-AUDIT-016 (MEDIUM): numeric Active Effect modes, replaced by string change types\n * VTTF-AUDIT-017 (MEDIUM): the jQuery `renderChatMessage` hook, removed in v15\n * VTTF-AUDIT-018 (LOW) : an Application v1 base class, removed in v16\n * VTTF-AUDIT-019 (MEDIUM): a bare v13 global alias (`renderTemplate`, `ActorSheet`, ...), removed in v15\n *\n * Regex heuristics like the rest of the source rules, for the same reason:\n * the patterns are short and a TypeScript AST would not make them more\n * precise. Comments are blanked first, so prose that mentions a call is not\n * a finding. Each rule reports the first match per file; one finding is\n * enough to send the reader to the file, and the fix is a search-and-replace\n * there.\n */\n\nimport { readFile } from 'node:fs/promises';\nimport { bareUsePattern, definesName, LEGACY_GLOBALS } from './legacy-globals.js';\nimport { maskComments } from './mask.js';\nimport { _internal } from './source-rules.js';\nimport type { RuleResult } from './types.js';\n\n/**\n * VTTF-AUDIT-011 (HIGH): a bare utility global v14 removed.\n *\n * v13 kept the v12-era globals (`mergeObject`, `getProperty`, ...) as\n * deprecation shims over `foundry.utils`. v14 removed the shims, so a bare\n * call throws `ReferenceError` the first time it runs, which for a helper\n * called from a sheet or a migration means a feature that dies on click.\n *\n * Only names with no plausible user-land meaning are listed: `duplicate`\n * and `debounce` are left out because a project can define its own.\n */\nexport const REMOVED_UTILS = [\n 'mergeObject',\n 'getProperty',\n 'setProperty',\n 'hasProperty',\n 'deepClone',\n 'expandObject',\n 'flattenObject',\n 'diffObject',\n 'isNewerVersion',\n 'randomID',\n] as const;\n\ninterface RemovedGlobal {\n readonly name: string;\n readonly pattern: RegExp;\n readonly replacement: string;\n}\n\nconst REMOVED_GLOBALS: readonly RemovedGlobal[] = [\n ...REMOVED_UTILS.map((name) => ({\n name,\n pattern: new RegExp(`(?<![\\\\w$.])${name}\\\\s*\\\\(`),\n replacement: `\\`foundry.utils.${name}\\``,\n })),\n { name: 'Math.clamped', pattern: /\\bMath\\.clamped\\s*\\(/, replacement: '`Math.clamp`' },\n {\n name: 'game.template',\n pattern: /\\bgame\\.template\\b/,\n replacement: '`game.model` or the `documentTypes` on the package',\n },\n];\n\n/**\n * A file that declares, imports, or defines the name as a method (a test\n * mock's `utils: { mergeObject(a, b) {...} }`) is using its own, not\n * Foundry's. The method-shorthand alternative uses `[^)]*` (no nested\n * parens) to avoid a false positive on call-sites inside conditional blocks\n * like `if (hasProperty(obj, 'key')) {`, where a lazy `[\\s\\S]*?` would\n * backtrack through the outer `)` and match the block brace.\n */\nfunction definesItself(content: string, name: string): boolean {\n return new RegExp(\n `(?:function\\\\s+${name}\\\\b|(?:const|let|var)\\\\s+${name}\\\\b|import[^;]*\\\\b${name}\\\\b|\\\\b${name}\\\\s*\\\\([^)]*\\\\)\\\\s*\\\\{)`,\n ).test(content);\n}\n\nfunction rule011(filePath: string, content: string): RuleResult[] {\n // Each removed name is checked on its own, so a file that wraps one of\n // them in a helper of the same name still gets its other hits reported.\n const hits = REMOVED_GLOBALS.flatMap((global) => {\n const idx = content.search(global.pattern);\n if (idx < 0) return [];\n if (\n REMOVED_UTILS.includes(global.name as (typeof REMOVED_UTILS)[number]) &&\n definesItself(content, global.name)\n ) {\n return [];\n }\n return [{ global, idx }];\n });\n const first = hits.sort((a, b) => a.idx - b.idx)[0];\n if (first === undefined) return [];\n\n return [\n {\n ruleId: 'VTTF-AUDIT-011',\n title: 'A global v14 removed',\n severity: 'HIGH',\n filePath,\n line: _internal.lineOf(content, first.global.pattern),\n message: `\\`${first.global.name}\\` was a v12 shim that v13 kept and v14 removed. The call throws ReferenceError the first time it runs.`,\n remediation: `Use ${first.global.replacement}.`,\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-012 (MEDIUM): `-=` / `==` update keys.\n *\n * Deprecated since v14, removed in v16. The replacement is a data operator:\n * `{ \"system.old\": _del }` and `{ \"system.stats\": _replace({...}) }`, or the\n * classes under `foundry.data.operators`.\n */\nfunction rule012(filePath: string, content: string): RuleResult[] {\n const pattern = /['\"`](?:[\\w$]+\\.)*(?:-=|==)[\\w$]/;\n if (!pattern.test(content)) return [];\n return [\n {\n ruleId: 'VTTF-AUDIT-012',\n title: 'Update key uses the -= / == prefix',\n severity: 'MEDIUM',\n filePath,\n line: _internal.lineOf(content, pattern),\n message:\n 'The `-=key` and `==key` update syntax is deprecated since v14 and removed in v16. Foundry warns on every write that uses it.',\n remediation:\n 'Delete with `{ \"path.to.key\": _del }` and replace with `{ \"path.to.key\": _replace(value) }`, or use `foundry.data.operators.ForcedDeletion` / `ForcedReplacement`. `mergeObject` takes `{ applyOperators: true }` where it took `{ performDeletions: true }`.',\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-013 (MEDIUM): `rollMode`.\n *\n * v14 renamed the option to `messageMode`, moved the user default to the\n * `core.messageMode` setting, and made `CONFIG.Dice.rollModes` and\n * `CONST.DICE_ROLL_MODES` deprecation proxies over `CONFIG.ChatMessage.modes`.\n * The old names warn until v16.\n */\nfunction rule013(filePath: string, content: string): RuleResult[] {\n const pattern = /\\brollMode\\s*:|['\"]rollMode['\"]|CONFIG\\.Dice\\.rollModes|DICE_ROLL_MODES/;\n if (!pattern.test(content)) return [];\n return [\n {\n ruleId: 'VTTF-AUDIT-013',\n title: 'rollMode is deprecated in favour of messageMode',\n severity: 'MEDIUM',\n filePath,\n line: _internal.lineOf(content, pattern),\n message:\n 'The `rollMode` option, the `core.rollMode` setting, `CONFIG.Dice.rollModes` and `CONST.DICE_ROLL_MODES` are deprecated since v14 and removed in v16.',\n remediation:\n 'Pass `{ messageMode }` (a key of `CONFIG.ChatMessage.modes`: public, gm, blind, self, ic) to `Roll#toMessage` and `ChatMessage.create`; read the user default from `game.settings.get(\"core\", \"messageMode\")`; map an old value with `Roll._mapLegacyRollMode`.',\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-014 (MEDIUM): `CONFIG.statusEffects = [...]`.\n *\n * v14 keys the collection by id. Assigning a whole array still works, but\n * the setter empties the collection first, so every condition another\n * package added earlier in `init` is gone, with no warning.\n */\nfunction rule014(filePath: string, content: string): RuleResult[] {\n const pattern = /CONFIG\\.statusEffects\\s*=[^=]/;\n if (!pattern.test(content)) return [];\n return [\n {\n ruleId: 'VTTF-AUDIT-014',\n title: 'CONFIG.statusEffects is assigned wholesale',\n severity: 'MEDIUM',\n filePath,\n line: _internal.lineOf(content, pattern),\n message:\n 'Assigning an array to `CONFIG.statusEffects` empties the collection first, which drops the conditions other packages added before this code ran. v14 deprecates the assignment.',\n remediation:\n 'Add and remove by id: `CONFIG.statusEffects[\"my-id\"] = { id: \"my-id\", name, img }` and `delete CONFIG.statusEffects.dead`. `registerSystem` and `registerModule` do this for the `statusEffects` option.',\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-015 (MEDIUM): `legacyTransferral`.\n *\n * v14 removed the flag. Effects on owned Items with `transfer: true` apply\n * to the Actor in place; nothing is copied. Setting the flag does nothing,\n * and code that reasons about copied effects reasons about the wrong model.\n */\nfunction rule015(filePath: string, content: string): RuleResult[] {\n const pattern = /\\blegacyTransferral\\b/;\n if (!pattern.test(content)) return [];\n return [\n {\n ruleId: 'VTTF-AUDIT-015',\n title: 'legacyTransferral no longer exists',\n severity: 'MEDIUM',\n filePath,\n line: _internal.lineOf(content, pattern),\n message:\n '`CONFIG.ActiveEffect.legacyTransferral` was removed in v14. Item effects with `transfer: true` apply to the Actor in place through `allApplicableEffects()`; the flag is ignored.',\n remediation:\n 'Delete the assignment. If the code relied on effects being copied onto the Actor, iterate `actor.allApplicableEffects()` instead of `actor.effects`.',\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-016 (MEDIUM): numeric Active Effect modes.\n *\n * v14 moved `changes` to `system.changes` and replaced the numeric `mode`\n * with a string `type` (`add`, `multiply`, `override`, `upgrade`,\n * `downgrade`, `subtract`, `custom`). The old shape loads through a\n * migration shim that warns until v16.\n */\nfunction rule016(filePath: string, content: string): RuleResult[] {\n const pattern = /\\bACTIVE_EFFECT_MODES\\b/;\n if (!pattern.test(content)) return [];\n return [\n {\n ruleId: 'VTTF-AUDIT-016',\n title: 'Active Effect changes use numeric modes',\n severity: 'MEDIUM',\n filePath,\n line: _internal.lineOf(content, pattern),\n message:\n '`CONST.ACTIVE_EFFECT_MODES` and a numeric `mode` on a change are deprecated since v14 and removed in v16. Changes live in `system.changes` with a string `type`.',\n remediation:\n 'Write `{ key, type: \"add\", value }` under `system.changes`; register extra types in `CONFIG.ActiveEffect.changeTypes`.',\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-017 (MEDIUM): the `renderChatMessage` hook.\n *\n * Deprecated since v13 and removed in v15, one version earlier than the\n * rest of this list. Its replacement, `renderChatMessageHTML`, hands the\n * message element instead of a jQuery object, so the handler body changes\n * too: `html.find(...)` becomes `html.querySelector(...)`.\n */\nfunction rule017(filePath: string, content: string): RuleResult[] {\n const pattern = /Hooks\\.(?:on|once)\\(\\s*['\"]renderChatMessage['\"]/;\n if (!pattern.test(content)) return [];\n return [\n {\n ruleId: 'VTTF-AUDIT-017',\n title: 'renderChatMessage is removed in v15',\n severity: 'MEDIUM',\n filePath,\n line: _internal.lineOf(content, pattern),\n message:\n 'The `renderChatMessage` hook is deprecated since v13 and removed in v15. It hands a jQuery object; `renderChatMessageHTML` hands the element.',\n remediation:\n 'Listen to `renderChatMessageHTML(message, html, context)` and rewrite the handler against the DOM: `html.find(x)` → `html.querySelector(x)`, `.on(\"click\", f)` → `.addEventListener(\"click\", f)`.',\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-018 (LOW): an Application v1 base class.\n *\n * `Application`, `FormApplication`, `Dialog`, `ActorSheet`, `ItemSheet` and\n * the rest of `foundry.appv1` are deprecated since v13 and removed in v16.\n * Nothing breaks on v14, which is why this is LOW; it is the largest piece\n * of work on the list, which is why it is on the list.\n */\nfunction rule018(filePath: string, content: string): RuleResult[] {\n const pattern =\n /extends\\s+(?:foundry\\.appv1\\.(?:api|sheets)\\.)?(?:Application|FormApplication|Dialog|DocumentSheet|ActorSheet|ItemSheet)\\b(?!V2)/;\n if (!pattern.test(content)) return [];\n return [\n {\n ruleId: 'VTTF-AUDIT-018',\n title: 'An Application v1 base class',\n severity: 'LOW',\n filePath,\n line: _internal.lineOf(content, pattern),\n message:\n 'This class extends an Application v1 base, deprecated since v13 and removed in v16. It still works on v14.',\n remediation:\n 'Move to `foundry.applications.api.ApplicationV2` with `HandlebarsApplicationMixin`, or `foundry.applications.sheets.ActorSheetV2` / `ItemSheetV2`; `DialogV2` for dialogs. `@vttforge/core` offers `BaseApplication`, `BaseActorSheet` and `BaseItemSheet` on top of those.',\n },\n ];\n}\n\n/**\n * VTTF-AUDIT-019 (MEDIUM): a bare v13 global alias.\n *\n * v13 moved these under `foundry.*` and kept the bare name as an alias that\n * warns; v15 removes the alias. Unlike the v12 utilities of rule 011 nothing\n * throws on v14, but every one of them is a `ReferenceError` one version\n * out, and the fix is a rename to the same object.\n */\nfunction rule019(filePath: string, content: string): RuleResult[] {\n const code = maskComments(content, { strings: true });\n let first: { name: string; index: number } | undefined;\n for (const name of Object.keys(LEGACY_GLOBALS)) {\n const match = bareUsePattern(name).exec(code);\n if (!match || definesName(code, name)) continue;\n if (first === undefined || match.index < first.index) first = { name, index: match.index };\n }\n if (first === undefined) return [];\n const path = LEGACY_GLOBALS[first.name];\n return [\n {\n ruleId: 'VTTF-AUDIT-019',\n title: 'A v13 global alias, removed in v15',\n severity: 'MEDIUM',\n filePath,\n line: _internal.lineOf(content, bareUsePattern(first.name)),\n message: `\\`${first.name}\\` is a bare alias of \\`${path}\\`, deprecated since v13 and removed in v15. It warns on every use today and throws ReferenceError on v15.`,\n remediation: `Use \\`${path}\\`. \\`vttforge migrate\\` renames every alias in this list.`,\n },\n ];\n}\n\nexport async function runV14Rules(cwd: string): Promise<RuleResult[]> {\n const results: RuleResult[] = [];\n for await (const file of _internal.walkSourceFiles(cwd)) {\n let content: string;\n try {\n content = await readFile(file, 'utf8');\n } catch {\n continue;\n }\n // Comments are blanked before matching, so a call quoted in a JSDoc\n // block or a `// TODO: drop mergeObject(` line is not a finding. The\n // mask keeps every offset, so the line numbers still point at the file.\n content = maskComments(content);\n results.push(\n ...rule011(file, content),\n ...rule012(file, content),\n ...rule013(file, content),\n ...rule014(file, content),\n ...rule015(file, content),\n ...rule016(file, content),\n ...rule017(file, content),\n ...rule018(file, content),\n ...rule019(file, content),\n );\n }\n return results;\n}\n","/**\n * Audit orchestrator: runs every rule against a project root and\n * aggregates the findings into an `AuditReport`.\n *\n * Rule organisation:\n * - manifest-rules.ts → VTTF-AUDIT-001, 002, 003 (manifest-only)\n * - source-rules.ts → VTTF-AUDIT-004, 005, 006, 007 (source walker\n * + cross-check with manifest where needed)\n * - template-rules.ts → VTTF-AUDIT-008 (the Handlebars, cross-checked\n * against which base each sheet is built on)\n * - v14-rules.ts → VTTF-AUDIT-011 to 019 (v13 code that v14 broke\n * or deprecated)\n * - release-rules.ts → VTTF-AUDIT-020 (a release workflow that ships the\n * checkout of a project that builds to dist/)\n *\n * The orchestrator stays minimal. It knows which rule sets exist, but\n * the rules themselves are responsible for their own file IO. This keeps\n * the individual rule files testable in isolation.\n */\n\nimport { existsSync, statSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { runManifestRules } from './manifest-rules.js';\nimport { runReleaseRules } from './release-rules.js';\nimport { runSourceRules } from './source-rules.js';\nimport { runTemplateRules } from './template-rules.js';\nimport { type AuditReport, type RuleResult, SEVERITY_RANK } from './types.js';\nimport { runV14Rules } from './v14-rules.js';\n\nexport interface RunAuditOptions {\n cwd: string;\n}\n\nexport class AuditTargetError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'AuditTargetError';\n }\n}\n\nexport async function runAudit(options: RunAuditOptions): Promise<AuditReport> {\n const cwd = resolve(options.cwd);\n // A missing or non-directory target must fail loudly. Otherwise both\n // rule sets return zero findings, the CLI prints \"No issues found\" and\n // exits 0, silently auditing nothing in CI. The mistyped-path failure\n // mode is invisible without this check.\n if (!existsSync(cwd)) {\n throw new AuditTargetError(`Audit target does not exist: ${cwd}`);\n }\n if (!statSync(cwd).isDirectory()) {\n throw new AuditTargetError(`Audit target is not a directory: ${cwd}`);\n }\n const startedAt = new Date().toISOString();\n\n const [manifestFindings, sourceFindings, templateFindings, v14Findings, releaseFindings] =\n await Promise.all([\n runManifestRules(cwd),\n runSourceRules(cwd),\n runTemplateRules(cwd),\n runV14Rules(cwd),\n runReleaseRules(cwd),\n ]);\n\n const findings: RuleResult[] = [\n ...manifestFindings,\n ...sourceFindings,\n ...templateFindings,\n ...v14Findings,\n ...releaseFindings,\n ].sort(compareFindings);\n\n return {\n cwd,\n startedAt,\n findings,\n counts: countBySeverity(findings),\n };\n}\n\n/** Sort: HIGH first, then by ruleId for deterministic output. */\nfunction compareFindings(a: RuleResult, b: RuleResult): number {\n const sev = SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity];\n if (sev !== 0) return sev;\n if (a.ruleId !== b.ruleId) return a.ruleId.localeCompare(b.ruleId);\n return a.filePath.localeCompare(b.filePath);\n}\n\nfunction countBySeverity(findings: ReadonlyArray<RuleResult>): AuditReport['counts'] {\n const counts = { HIGH: 0, MEDIUM: 0, LOW: 0 };\n for (const f of findings) counts[f.severity] += 1;\n return counts;\n}\n","/**\n * Render an `AuditReport` as JSON (machine-readable, stable schema) or\n * markdown (terminal-friendly, sectioned by severity).\n *\n * JSON output is the contract for downstream CI tooling: stable shape,\n * stable severity strings, stable ruleId namespace `VTTF-AUDIT-NNN`. The\n * markdown variant exists so a human running `vttforge audit` in a\n * scrollback gets immediate signal without piping through `jq`.\n */\n\nimport { relative } from 'node:path';\nimport type { AuditReport, RuleResult } from './types.js';\n\nexport type ReportFormat = 'json' | 'markdown';\n\nexport function formatReport(report: AuditReport, format: ReportFormat): string {\n return format === 'json' ? formatJson(report) : formatMarkdown(report);\n}\n\nfunction formatJson(report: AuditReport): string {\n return `${JSON.stringify(report, null, 2)}\\n`;\n}\n\nfunction formatMarkdown(report: AuditReport): string {\n const { findings, counts, cwd } = report;\n const lines: string[] = [];\n lines.push('# vttforge audit report');\n lines.push('');\n lines.push(`- cwd: \\`${cwd}\\``);\n lines.push(`- started: ${report.startedAt}`);\n lines.push(\n `- findings: ${findings.length} (${counts.HIGH} HIGH · ${counts.MEDIUM} MEDIUM · ${counts.LOW} LOW)`,\n );\n lines.push('');\n if (findings.length === 0) {\n lines.push('No issues found. The system / module looks healthy against the v14 catalog.');\n lines.push('');\n return lines.join('\\n');\n }\n\n for (const severity of ['HIGH', 'MEDIUM', 'LOW'] as const) {\n const bucket = findings.filter((f) => f.severity === severity);\n if (bucket.length === 0) continue;\n lines.push(`## ${severity} (${bucket.length})`);\n lines.push('');\n for (const finding of bucket) {\n lines.push(formatFinding(finding, cwd));\n lines.push('');\n }\n }\n return lines.join('\\n');\n}\n\nfunction formatFinding(finding: RuleResult, cwd: string): string {\n const location = formatLocation(finding, cwd);\n const lines: string[] = [];\n lines.push(`### \\`${finding.ruleId}\\`: ${finding.title}`);\n lines.push('');\n lines.push(`- file: ${location}`);\n lines.push(`- message: ${finding.message}`);\n if (finding.remediation) {\n lines.push(`- fix: ${finding.remediation}`);\n }\n return lines.join('\\n');\n}\n\nfunction formatLocation(finding: RuleResult, cwd: string): string {\n const rel = relativizeIfBelow(finding.filePath, cwd);\n return finding.line !== undefined ? `\\`${rel}:${finding.line}\\`` : `\\`${rel}\\``;\n}\n\n/**\n * Show paths relative to `cwd` when they live underneath it (cleaner reports),\n * fall back to the absolute path otherwise so we don't lie about where the\n * file actually is.\n */\nfunction relativizeIfBelow(filePath: string, cwd: string): string {\n const rel = relative(cwd, filePath);\n if (rel === '' || rel.startsWith('..') || rel.startsWith('/')) {\n return filePath;\n }\n return rel;\n}\n","/**\n * `vttforge audit`: scan a system/module project against the VTTForge\n * audit catalog (the v14 manifest, source and template breakages that fail quietly).\n *\n * The rules live under `audit/` (manifest, source, template and v14 sets);\n * this file is the CLI surface that orchestrates them and prints the report.\n *\n * Exit codes:\n * 0: clean run, or only MEDIUM/LOW findings (informational)\n * 1: at least one HIGH finding (or any finding in `--strict` mode)\n */\n\nimport { resolve } from 'node:path';\nimport { runAudit } from '../audit/index.js';\nimport { formatReport, type ReportFormat } from '../audit/reporter.js';\nimport type { AuditReport } from '../audit/types.js';\n\nexport interface AuditOptions {\n /** Project root to scan. Defaults to `process.cwd()`. */\n cwd?: string;\n /** Output format. Default: 'markdown'. */\n format?: ReportFormat;\n /**\n * When true, MEDIUM and LOW findings also trigger a non-zero exit.\n * Default false: HIGH-only is the canonical \"block CI\" line.\n */\n strict?: boolean;\n /** Custom writer (tests). Defaults to process.stdout.write. */\n write?: (chunk: string) => void;\n}\n\nexport interface AuditResult {\n report: AuditReport;\n /** Suggested exit code under the current strictness setting. */\n exitCode: 0 | 1;\n}\n\n/**\n * @experimental Shape is unproven: no consumer has asked for this yet. It can\n * change in a minor.\n */\nexport async function runAuditCommand(options: AuditOptions = {}): Promise<AuditResult> {\n const cwd = resolve(options.cwd ?? process.cwd());\n const format: ReportFormat = options.format ?? 'markdown';\n const strict = options.strict === true;\n const write =\n options.write ??\n ((chunk: string) => {\n process.stdout.write(chunk);\n });\n\n const report = await runAudit({ cwd });\n write(formatReport(report, format));\n\n const exitCode: 0 | 1 =\n report.counts.HIGH > 0 || (strict && (report.counts.MEDIUM > 0 || report.counts.LOW > 0))\n ? 1\n : 0;\n\n return { report, exitCode };\n}\n","/**\n * Read a built manifest (`dist/system.json` or `dist/module.json`).\n *\n * The vite plugin emits the manifest into `dist/` during build, so the CLI\n * commands that come after a build (dev's initial symlink, build's release\n * zip) read from there rather than walking source. This file is intentionally\n * tiny: we extract just the fields the CLI cares about and surface the\n * rest as `raw` for any consumer that wants more.\n */\n\nimport { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\n\nexport type PackageType = 'system' | 'module';\n\nexport interface FoundryManifest {\n /** Manifest id: folder name Foundry serves the package under. */\n id: string;\n /** Semver-ish version string from the manifest. */\n version: string;\n /** Detected from which filename was present in dist/. */\n type: PackageType;\n /** Full parsed JSON for callers that need extra fields (compatibility, etc.). */\n raw: Record<string, unknown>;\n}\n\nconst MANIFEST_FILES: ReadonlyArray<{ file: string; type: PackageType }> = [\n { file: 'system.json', type: 'system' },\n { file: 'module.json', type: 'module' },\n];\n\n// Foundry package ids are folder names. We mirror what `vttforge init`\n// allows (lowercase letters, digits, dashes, plus dot/underscore for\n// legacy packages) and reject anything that would let `join()` escape\n// the intended Data/<systems|modules>/ folder: slashes, backslashes,\n// `..` traversal, null bytes, whitespace, control chars.\nconst MANIFEST_ID_RE = /^[a-z][a-z0-9._-]*$/;\n// Version strings end up in the release zip filename. Allow the common\n// semver alphabet (`1.2.3-beta.1+abc123`) and reject anything else for\n// the same reason: `join(cwd, `${id}-${version}.zip`)` must not climb\n// out of cwd.\nconst MANIFEST_VERSION_RE = /^[0-9A-Za-z._+-]+$/;\n\n/**\n * Locate and parse the Foundry manifest inside the given dist directory.\n * Prefers `system.json`, falls back to `module.json` (a single dist can't\n * be both; the vite plugin emits exactly one based on the project type).\n *\n * Throws if neither file exists, required fields are missing/non-string,\n * or the id/version contain characters that would let downstream `join()`\n * calls escape their intended directory.\n *\n * @experimental Shape is unproven: no consumer has asked for this yet.\n * It can change in a minor.\n */\nexport async function readManifest(distDir: string): Promise<FoundryManifest> {\n for (const { file, type } of MANIFEST_FILES) {\n const path = join(distDir, file);\n if (!existsSync(path)) continue;\n let parsed: unknown;\n try {\n parsed = JSON.parse(await readFile(path, 'utf8'));\n } catch (err) {\n throw new Error(\n `Failed to parse ${path}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n throw new Error(`Manifest at ${path} is not a JSON object.`);\n }\n const raw = parsed as Record<string, unknown>;\n const id = raw.id;\n const version = raw.version;\n if (typeof id !== 'string' || id.length === 0) {\n throw new Error(`Manifest at ${path} is missing a non-empty \"id\" field.`);\n }\n if (!MANIFEST_ID_RE.test(id)) {\n throw new Error(\n `Manifest at ${path} has an invalid \"id\" (${JSON.stringify(id)}). Foundry package ids must match ${MANIFEST_ID_RE}: lowercase letters, digits, dashes, dots, underscores; must start with a letter.`,\n );\n }\n if (typeof version !== 'string' || version.length === 0) {\n throw new Error(`Manifest at ${path} is missing a non-empty \"version\" field.`);\n }\n if (!MANIFEST_VERSION_RE.test(version)) {\n throw new Error(\n `Manifest at ${path} has an invalid \"version\" (${JSON.stringify(version)}). Use a semver-ish string with letters, digits, dots, dashes, plus, or underscore.`,\n );\n }\n return { id, version, type, raw };\n }\n throw new Error(\n `No Foundry manifest found in ${distDir}. Expected system.json or module.json. Did you run \\`vite build\\` first?`,\n );\n}\n","/**\n * Detect which package manager invoked the CLI so we can run the right\n * `install` command after scaffolding.\n *\n * Strategy: read `npm_config_user_agent`, which pnpm/npm/bun/yarn all set when\n * they spawn a child process (including `pnpm dlx`, `pnpm create`, etc.).\n * Falls back to `pnpm` because that's the VTTForge house default and the\n * most common Foundry-developer choice, but any concrete signal in the\n * environment wins over the default.\n */\n\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\nexport type PackageManager = 'pnpm' | 'npm' | 'bun' | 'yarn';\n\n/**\n * @internal Implementation detail of the `vttforge` binary. Not supported for\n * outside use, and going away in the next major.\n */\nexport function detectPackageManager(env: NodeJS.ProcessEnv = process.env): PackageManager {\n const ua = env.npm_config_user_agent;\n if (typeof ua === 'string' && ua.length > 0) {\n if (ua.startsWith('pnpm')) return 'pnpm';\n if (ua.startsWith('bun')) return 'bun';\n if (ua.startsWith('yarn')) return 'yarn';\n if (ua.startsWith('npm')) return 'npm';\n }\n return 'pnpm';\n}\n\n/**\n * @internal Implementation detail of the `vttforge` binary. Not supported for\n * outside use, and going away in the next major.\n */\nexport function installCommand(pm: PackageManager): string {\n return `${pm} install`;\n}\n\n/**\n * Detect a project's package manager by looking at which lockfile it\n * ships. `dev` and `build` need this: by the time the user runs\n * `vttforge dev`, npm_config_user_agent reflects whatever shell launched\n * the binary (often nothing in a global install), not how the project\n * was bootstrapped. The lockfile is the project's own contract.\n *\n * Falls back to {@link detectPackageManager} for fresh checkouts that\n * haven't been installed yet.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function detectProjectPackageManager(\n cwd: string,\n env: NodeJS.ProcessEnv = process.env,\n): PackageManager {\n if (existsSync(join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';\n // Yarn 1 ships .lock; Yarn 2+ Plug'n'Play also keeps yarn.lock at root.\n if (existsSync(join(cwd, 'yarn.lock'))) return 'yarn';\n // Bun text format (bun.lock) supersedes the older binary bun.lockb in 1.1+.\n if (existsSync(join(cwd, 'bun.lock')) || existsSync(join(cwd, 'bun.lockb'))) return 'bun';\n // npm supports both package-lock.json (common) and npm-shrinkwrap.json\n // (published-package convention). Accept either as evidence of an npm\n // project, otherwise we'd misclassify shrinkwrap projects as pnpm.\n if (existsSync(join(cwd, 'package-lock.json')) || existsSync(join(cwd, 'npm-shrinkwrap.json'))) {\n return 'npm';\n }\n return detectPackageManager(env);\n}\n\n/**\n * Argument vector to invoke `vite` (or any other locally-installed CLI)\n * via the project's package manager. We always shell out through `<pm>\n * exec` so the call works regardless of the linker's choices. Yarn 4\n * Plug'n'Play, pnpm's symlinked layout, npm's flattened node_modules,\n * Bun's symlinked node_modules. Each manager exposes a uniform \"run a\n * locally-resolved binary in the project's dependency graph\" command.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function execInvocation(pm: PackageManager, bin: string): [string, string[]] {\n switch (pm) {\n case 'pnpm':\n return ['pnpm', ['exec', bin]];\n case 'yarn':\n // `yarn exec` runs in the PnP context; the `--` separator keeps any\n // bin-side flags from being parsed by yarn itself.\n return ['yarn', ['exec', '--', bin]];\n case 'bun':\n // `bun x <bin>` is the equivalent of `npx`; it resolves through the\n // project's node_modules and works without a global install.\n return ['bun', ['x', bin]];\n case 'npm':\n return ['npx', ['--no-install', bin]];\n }\n}\n","/**\n * Spawn the user's project-local `vite` through their package manager.\n *\n * We deliberately go through `<pm> exec vite` instead of probing a\n * `node_modules/vite/bin/vite.js` path: Yarn 4 Plug'n'Play stores\n * dependencies in `.yarn/cache/` rather than `node_modules/`, and even\n * within npm/pnpm projects PNP-style linkers may not materialize the\n * binary on disk. The package-manager command always resolves the\n * locally-installed vite correctly regardless of linker.\n */\n\nimport { type ChildProcess, spawn } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { detectProjectPackageManager, execInvocation } from './package-manager.js';\n\n/**\n * @internal Implementation detail of the `vttforge` binary. Not supported for\n * outside use, and going away in the next major.\n */\nexport class ViteNotInstalledError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ViteNotInstalledError';\n }\n}\n\n/** Spawn args for invoking the user's vite (e.g. `[\"pnpm\", [\"exec\", \"vite\"]]`).\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function resolveViteInvocation(cwd: string): [string, string[]] {\n // Lightweight sanity check: the project must have a `package.json` so we\n // know we're inside a real project root. We do NOT require\n // `node_modules/vite/bin/vite.js` because Yarn PnP intentionally skips\n // creating that file.\n if (!existsSync(join(cwd, 'package.json'))) {\n throw new ViteNotInstalledError(\n `No package.json found at ${cwd}. Run \\`vttforge dev\\` / \\`vttforge build\\` from inside a scaffolded project.`,\n );\n }\n const pm = detectProjectPackageManager(cwd);\n return execInvocation(pm, 'vite');\n}\n\n/** Run `vite build` once and wait for it to exit. Throws on non-zero exit.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport async function runViteBuildOnce(cwd: string): Promise<void> {\n const [bin, baseArgs] = resolveViteInvocation(cwd);\n await new Promise<void>((resolveBuild, rejectBuild) => {\n const child = spawn(bin, [...baseArgs, 'build'], {\n cwd,\n stdio: 'inherit',\n env: process.env,\n // `shell: false` keeps the args list quoted; npx/pnpm/yarn/bun all\n // accept bare argv without shell expansion.\n shell: false,\n });\n child.on('error', (err) => {\n // Surface a friendlier message if the PM binary itself isn't on PATH.\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n rejectBuild(\n new Error(\n `Could not invoke \"${bin}\". Is the project's package manager installed and on PATH?`,\n ),\n );\n } else {\n rejectBuild(err);\n }\n });\n child.on('exit', (code) => {\n if (code === 0) {\n resolveBuild();\n } else {\n rejectBuild(new Error(`vite build exited with code ${code ?? 'unknown'}`));\n }\n });\n });\n}\n\n/**\n * Spawn `vite build --watch` and return the child process. The caller is\n * responsible for waiting on it and tearing it down (the dev command kills\n * it on SIGINT).\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function spawnViteWatch(cwd: string): ChildProcess {\n const [bin, baseArgs] = resolveViteInvocation(cwd);\n return spawn(bin, [...baseArgs, 'build', '--watch'], {\n cwd,\n stdio: 'inherit',\n env: process.env,\n shell: false,\n });\n}\n","/**\n * Emit a foundryvtt.com-compatible release zip.\n *\n * foundryvtt.com expects the package contents at the zip root (no wrapper\n * folder), so `unzip release.zip` produces `system.json`, `scripts/`, etc.\n * directly. The vite build output already matches that layout, so we feed\n * `dist/` straight into archiver with `false` as the second arg to disable\n * the wrap-with-source-dir-name default.\n *\n * Optional extras (LICENSE / README / CHANGELOG) ride along when present at\n * the project root and not already inside `dist/`. We never duplicate.\n */\n\nimport { createWriteStream, existsSync } from 'node:fs';\nimport { stat } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { ZipArchive } from 'archiver';\n\nexport interface EmitZipOptions {\n /** Directory whose contents go into the zip at root. */\n sourceDir: string;\n /** Output zip path. Parent directory must exist. */\n outFile: string;\n /** Filenames (relative to extrasFrom) to add at the zip root if present. */\n extras?: string[];\n /** Where to look for `extras`. Required when `extras` is non-empty. */\n extrasFrom?: string;\n}\n\nexport interface EmitZipResult {\n outFile: string;\n byteSize: number;\n}\n\n/**\n * @experimental Shape is unproven: no consumer has asked for this yet. It can\n * change in a minor.\n */\nexport async function emitZip(opts: EmitZipOptions): Promise<EmitZipResult> {\n const { sourceDir, outFile, extras = [], extrasFrom } = opts;\n if (!existsSync(sourceDir)) {\n throw new Error(`emitZip: sourceDir does not exist: ${sourceDir}`);\n }\n if (extras.length > 0 && !extrasFrom) {\n throw new Error('emitZip: extrasFrom is required when extras are provided.');\n }\n\n await new Promise<void>((resolveZip, rejectZip) => {\n const output = createWriteStream(outFile);\n const archive = new ZipArchive({ zlib: { level: 9 } });\n\n output.on('close', () => resolveZip());\n output.on('error', rejectZip);\n archive.on('error', rejectZip);\n // archiver emits 'warning' for non-fatal recoverable issues (e.g. an\n // extras file disappeared between existsSync and stream open). ENOENT\n // is the only one safe to swallow; everything else is a real failure.\n archive.on('warning', (err) => {\n if (err.code !== 'ENOENT') rejectZip(err);\n });\n\n archive.pipe(output);\n archive.directory(sourceDir, false);\n\n if (extrasFrom) {\n for (const name of extras) {\n const srcPath = join(extrasFrom, name);\n if (!existsSync(srcPath)) continue;\n const distPath = join(sourceDir, name);\n if (existsSync(distPath)) continue;\n archive.file(srcPath, { name });\n }\n }\n\n archive.finalize().catch(rejectZip);\n });\n\n const info = await stat(outFile);\n return { outFile, byteSize: info.size };\n}\n","/**\n * `vttforge build`: emit a foundryvtt.com-ready release zip.\n *\n * Flow:\n * 1. Clean dist/\n * 2. Run `vite build` (production mode)\n * 3. Read the resulting manifest → id + version\n * 4. Zip dist/ + LICENSE/README/CHANGELOG (if present) into\n * `<cwd>/<id>-<version>.zip` with contents at the zip root\n *\n * The release workflows shipped by the templates upload this zip to a\n * GitHub release; the manifest URL points at `releases/latest/download/`\n * so Foundry's auto-update catches new versions.\n */\n\nimport { rm } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport { type FoundryManifest, readManifest } from '../manifest.js';\nimport { runViteBuildOnce } from '../vite-runner.js';\nimport { emitZip } from '../zip.js';\n\nexport interface BuildOptions {\n /** Override the project root. Defaults to `process.cwd()`. */\n cwd?: string;\n}\n\n/** Files we copy into the zip at root when they exist at project root. */\nconst RELEASE_ZIP_EXTRAS = ['LICENSE', 'README.md', 'CHANGELOG.md'];\n\n/** Format a byte count as `12 B`, `4.3 KB`, or `1.2 MB`. */\nfunction formatBytes(n: number): string {\n if (!Number.isFinite(n) || n < 0) return `${n} B`;\n const units = ['B', 'KB', 'MB'] as const;\n let v = n;\n let unitIndex = 0;\n while (v >= 1024 && unitIndex < units.length - 1) {\n v /= 1024;\n unitIndex += 1;\n }\n return `${v.toFixed(v >= 10 || unitIndex === 0 ? 0 : 1)} ${units[unitIndex]}`;\n}\n\n/**\n * Internal building block exposed for tests: assumes dist/ is already\n * populated (vite has run, manifest is present) and just emits the zip.\n *\n * @experimental Shape is unproven: no consumer has asked for this yet.\n * It can change in a minor.\n */\nexport async function emitReleaseZip(opts: {\n cwd: string;\n}): Promise<{ zipFile: string; byteSize: number; manifest: FoundryManifest }> {\n const cwd = resolve(opts.cwd);\n const distDir = join(cwd, 'dist');\n const manifest = await readManifest(distDir);\n const zipName = `${manifest.id}-${manifest.version}.zip`;\n const zipFile = join(cwd, zipName);\n const { byteSize } = await emitZip({\n sourceDir: distDir,\n outFile: zipFile,\n extras: RELEASE_ZIP_EXTRAS,\n extrasFrom: cwd,\n });\n return { zipFile, byteSize, manifest };\n}\n\n/**\n * @experimental Shape is unproven: no consumer has asked for this yet. It can\n * change in a minor.\n */\nexport async function runBuild(options: BuildOptions = {}): Promise<void> {\n const cwd = options.cwd ? resolve(options.cwd) : process.cwd();\n p.intro('🜲 vttforge build: release zip');\n\n const distDir = join(cwd, 'dist');\n\n // Wipe dist/ so stale files from a previous dev session don't sneak\n // into a tagged release zip.\n await rm(distDir, { recursive: true, force: true });\n\n const buildSpinner = p.spinner();\n buildSpinner.start('vite build (production)');\n try {\n await runViteBuildOnce(cwd);\n buildSpinner.stop('Build complete');\n } catch (err) {\n buildSpinner.stop('Build failed');\n throw err;\n }\n\n const { zipFile, byteSize } = await emitReleaseZip({ cwd });\n\n p.note(`${zipFile}\\n${formatBytes(byteSize)}`, 'Release artifact');\n p.outro(\n `Upload this zip to your release. The release workflow shipped with the template handles tag→GitHub Release → foundryvtt.com manifest update.`,\n );\n}\n","/**\n * Cross-platform symlink helpers for `vttforge dev`.\n *\n * The dev loop drops a symlink from Foundry's `Data/<systems|modules>/<id>/`\n * back to the project's `dist/` so Foundry serves freshly-built files as\n * vite writes them. The win32 path matters: with `type: 'junction'` the\n * operation works on standard Windows shells without Developer Mode, while\n * `type: 'dir'` requires admin. We never silently fall back to copying;\n * Foundry's HMR relies on live file mutation, and a copy snapshot defeats\n * the loop. If the symlink fails, we surface the platform-specific fix.\n */\n\nimport { lstat, mkdir, readlink, symlink, unlink } from 'node:fs/promises';\nimport { dirname, resolve } from 'node:path';\n\nexport interface CreateLinkOptions {\n /**\n * Overwrite an existing symlink that points elsewhere. Real files and\n * directories are never overwritten; that path needs explicit user\n * action outside the tool.\n */\n overwrite?: boolean;\n}\n\n/**\n * Read a symlink target. Returns the absolute path the link points at, or\n * `null` if `path` doesn't exist or isn't a symlink. Relative symlink\n * targets are resolved against the link's own directory (matches the\n * semantics callers expect when comparing to a known absolute source).\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport async function readLinkTarget(path: string): Promise<string | null> {\n try {\n const info = await lstat(path);\n if (!info.isSymbolicLink()) return null;\n const target = await readlink(path);\n return resolve(dirname(path), target);\n } catch {\n return null;\n }\n}\n\n/**\n * Create a symlink at `target` pointing to `source`. Win32 uses `'junction'`\n * so the call succeeds without elevation; everywhere else uses `'dir'`.\n *\n * Idempotency:\n * - target already points to source → no-op\n * - target points elsewhere → throws unless `options.overwrite`\n * - target is a real file/dir → throws unconditionally\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport async function createLink(\n target: string,\n source: string,\n options: CreateLinkOptions = {},\n): Promise<void> {\n const absSource = resolve(source);\n const absTarget = resolve(target);\n\n let info: Awaited<ReturnType<typeof lstat>> | null;\n try {\n info = await lstat(absTarget);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n info = null;\n } else {\n throw err;\n }\n }\n\n if (info?.isSymbolicLink()) {\n const existing = await readLinkTarget(absTarget);\n if (existing === absSource) return;\n if (!options.overwrite) {\n throw new Error(\n `Symlink already exists at ${absTarget} pointing to ${existing}. Pass { overwrite: true } or remove it manually.`,\n );\n }\n await unlink(absTarget);\n } else if (info) {\n const kind = info.isDirectory() ? 'directory' : 'file';\n throw new Error(`Refusing to overwrite ${absTarget}: path exists as a ${kind}, not a symlink.`);\n }\n\n await mkdir(dirname(absTarget), { recursive: true });\n\n const linkType: 'dir' | 'junction' = process.platform === 'win32' ? 'junction' : 'dir';\n try {\n await symlink(absSource, absTarget, linkType);\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code === 'EPERM' && process.platform === 'win32') {\n throw new Error(\n `Could not create symlink at ${absTarget}: permission denied. On Windows, enable Developer Mode (Settings → Update & Security → For Developers) or relaunch the terminal as administrator.`,\n );\n }\n throw err;\n }\n}\n\n/**\n * Remove a symlink at `path`. No-ops when the path doesn't exist. Throws\n * when the path exists but isn't a symlink; we never unlink real files\n * or directories.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport async function removeLink(path: string): Promise<void> {\n let info: Awaited<ReturnType<typeof lstat>>;\n try {\n info = await lstat(path);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return;\n throw err;\n }\n if (!info.isSymbolicLink()) {\n const kind = info.isDirectory() ? 'directory' : 'file';\n throw new Error(`Refusing to remove ${path}: it is a ${kind}, not a symlink.`);\n }\n await unlink(path);\n}\n","/**\n * Put `@vttforge/dev-module` where Foundry will find it.\n *\n * Foundry loads a module from a directory under `Data/modules/<id>/` holding\n * `module.json` and the files it names. The published package already has\n * exactly that shape, so the install is a link to the package root, no copy\n * to keep in step, and a `pnpm update` is picked up on the next reload.\n *\n * A container is the other case: it cannot follow a host symlink, so the\n * compose file mounts the same directory instead. `vttforge dev` prints the\n * mount rather than editing anyone's compose file for them.\n */\nimport { existsSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { createLink, readLinkTarget } from './symlink.js';\n\nconst DEV_MODULE_ID = 'vttforge-dev';\n\nexport interface InstallResult {\n /** Where the module now lives, from Foundry's point of view. */\n target: string;\n /** The package directory it points at: what a container should mount. */\n source: string;\n /** False when the link was already correct. */\n changed: boolean;\n}\n\n/**\n * Find the installed package directory.\n *\n * Resolved from the consumer's project so their `node_modules` answers,\n * falling back to this CLI's own resolution, which is what makes it work\n * inside this repository, where the package is a workspace link.\n */\nexport function resolveDevModuleDir(cwd: string): string | null {\n const candidates = [\n join(cwd, 'node_modules', '@vttforge', 'dev-module'),\n // `dist/` of the CLI sits two levels under its package root; the sibling\n // package is one level up from there.\n join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'dev-module'),\n ];\n for (const dir of candidates) {\n if (existsSync(join(dir, 'module.json'))) return dir;\n }\n return null;\n}\n\nexport async function installDevModule(\n modulesDir: string,\n packageDir: string,\n): Promise<InstallResult> {\n const target = join(modulesDir, DEV_MODULE_ID);\n const existing = await readLinkTarget(target);\n if (existing === packageDir) {\n return { target, source: packageDir, changed: false };\n }\n await createLink(target, packageDir, { overwrite: true });\n return { target, source: packageDir, changed: true };\n}\n\n/** The compose line a containerised Foundry needs, ready to paste. */\nexport function composeMountLine(packageDir: string): string {\n return `- ${packageDir}:/data/Data/modules/${DEV_MODULE_ID}:ro`;\n}\n","/**\n * A one-way WebSocket server: `vttforge dev` pushes, the dev module listens.\n *\n * Hand-written rather than pulled from a package. The CLI ships to every\n * consumer, so each dependency is one they install too, and what is needed\n * here is a narrow slice of RFC 6455: accept the upgrade, send unmasked text\n * frames, notice when a client goes away. No client payloads are read, no\n * compression, no extensions.\n */\nimport { createHash } from 'node:crypto';\nimport { createServer, type Server } from 'node:http';\nimport type { Duplex } from 'node:stream';\n\n/** Fixed GUID from RFC 6455 §1.3, concatenated with the client key. */\nconst WS_GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';\n\n/** Frame lengths above these switch to a wider length field. */\nconst LEN_16_BIT = 126;\nconst LEN_64_BIT = 65_536;\n\n/** Opcode 0x8: the client is closing. */\nconst OPCODE_CLOSE = 0x8;\n\nexport interface DevServer {\n /** Send one message to every connected client. */\n broadcast: (message: string) => void;\n /** Number of clients currently attached: used to say something truthful. */\n clientCount: () => number;\n close: () => Promise<void>;\n /**\n * The port actually bound, which is not always the one requested: port 0\n * asks the OS to choose. Reporting the request back would leave the caller\n * unable to tell anyone where to connect.\n */\n port: number;\n}\n\n/**\n * Compute the handshake response header.\n *\n * Exported because it is the one part of the handshake with a published test\n * vector, and a wrong value fails as a silent non-connection.\n */\nexport function acceptKey(clientKey: string): string {\n return createHash('sha1')\n .update(clientKey + WS_GUID)\n .digest('base64');\n}\n\n/**\n * Encode one text frame, server to client.\n *\n * Server frames are never masked. The payload length picks one of three\n * widths, and getting the boundary wrong corrupts the stream rather than\n * failing loudly, hence the explicit constants and the tests around them.\n */\nexport function encodeTextFrame(message: string): Buffer {\n const payload = Buffer.from(message, 'utf8');\n const len = payload.length;\n\n let header: Buffer;\n if (len < LEN_16_BIT) {\n header = Buffer.from([0x81, len]);\n } else if (len < LEN_64_BIT) {\n header = Buffer.alloc(4);\n header[0] = 0x81;\n header[1] = LEN_16_BIT;\n header.writeUInt16BE(len, 2);\n } else {\n header = Buffer.alloc(10);\n header[0] = 0x81;\n header[1] = 127;\n header.writeBigUInt64BE(BigInt(len), 2);\n }\n return Buffer.concat([header, payload]);\n}\n\n/** Is this inbound frame a close? That is the only opcode worth reading. */\nexport function isCloseFrame(chunk: Buffer): boolean {\n const first = chunk.at(0);\n return first !== undefined && (first & 0x0f) === OPCODE_CLOSE;\n}\n\nexport interface StartOptions {\n port: number;\n /** Loopback by default: this serves a developer's own machine. */\n host?: string;\n}\n\nexport async function startDevServer(options: StartOptions): Promise<DevServer> {\n const sockets = new Set<Duplex>();\n\n // A plain GET gets a flat answer. Anything that is not an upgrade has\n // reached the wrong port, and saying so beats an unexplained hang.\n const server: Server = createServer((_req, res) => {\n res.writeHead(426, { 'Content-Type': 'text/plain' });\n res.end('This port speaks WebSocket only; it is the vttforge dev bridge.\\n');\n });\n\n server.on('upgrade', (req, socket) => {\n const key = req.headers['sec-websocket-key'];\n if (typeof key !== 'string') {\n socket.destroy();\n return;\n }\n socket.write(\n [\n 'HTTP/1.1 101 Switching Protocols',\n 'Upgrade: websocket',\n 'Connection: Upgrade',\n `Sec-WebSocket-Accept: ${acceptKey(key)}`,\n '\\r\\n',\n ].join('\\r\\n'),\n );\n // Nagle would hold small frames back waiting for company; a reload\n // payload should leave immediately. Node types the upgrade socket as a\n // Duplex even though an HTTP upgrade always hands over a TCP socket, so\n // check for the method rather than asserting the wider type away.\n if ('setNoDelay' in socket && typeof socket.setNoDelay === 'function') {\n (socket as Duplex & { setNoDelay: (on: boolean) => void }).setNoDelay(true);\n }\n sockets.add(socket);\n\n const drop = () => {\n sockets.delete(socket);\n socket.destroy();\n };\n socket.on('data', (chunk: Buffer) => {\n if (isCloseFrame(chunk)) drop();\n });\n socket.on('close', () => sockets.delete(socket));\n // A browser tab closing surfaces as an error on some platforms and a\n // close on others. Either way the socket is gone, and neither should\n // reach the top level.\n socket.on('error', drop);\n });\n\n await new Promise<void>((resolveStart, rejectStart) => {\n server.once('error', rejectStart);\n server.listen(options.port, options.host ?? '127.0.0.1', () => {\n server.removeListener('error', rejectStart);\n resolveStart();\n });\n });\n\n const address = server.address();\n const boundPort = typeof address === 'object' && address ? address.port : options.port;\n\n return {\n broadcast: (message) => {\n const frame = encodeTextFrame(message);\n for (const socket of sockets) {\n // One dead socket must not stop the rest from being told.\n try {\n socket.write(frame);\n } catch {\n sockets.delete(socket);\n }\n }\n },\n clientCount: () => sockets.size,\n close: async () => {\n for (const socket of sockets) socket.destroy();\n sockets.clear();\n await new Promise<void>((resolveClose) => server.close(() => resolveClose()));\n },\n port: boundPort,\n };\n}\n","/**\n * Watch the build output and turn each change into a reload payload.\n *\n * Watching `dist/` rather than hooking into Vite is deliberate: Vite rebuilds\n * into that directory whatever its internals look like, so this stays correct\n * across bundler versions and gives the served path directly: `dist/` is what\n * Foundry mounts, so a file's position inside it is its position under\n * `/systems/<id>/`.\n */\nimport { createHash } from 'node:crypto';\nimport { existsSync, type FSWatcher, readdirSync, readFileSync, watch } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { extname, join, posix, sep } from 'node:path';\n\n/** What the dev module knows how to apply without a page reload. */\nconst RELOADABLE = new Set(['css', 'hbs', 'html', 'json']);\n\n/**\n * Editors save in bursts (write, rename, truncate) and a burst should be\n * one reload, not four.\n */\nconst DEBOUNCE_MS = 40;\n\nexport interface WatchOptions {\n distDir: string;\n packageId: string;\n packageType: 'system' | 'module';\n /** Called once per settled change with the JSON frame to send. */\n onPayload: (frame: string) => void;\n onError?: (message: string) => void;\n debounceMs?: number;\n}\n\nexport interface DistWatcher {\n close: () => void;\n}\n\n/**\n * The path Foundry serves this file at.\n *\n * Always POSIX separators: it becomes a URL, and a Windows backslash would\n * not match the `<link>` the browser rendered.\n */\nexport function servedPath(\n relative: string,\n packageId: string,\n packageType: 'system' | 'module',\n): string {\n const normalized = relative.split(sep).join(posix.sep);\n return posix.join(`${packageType}s`, packageId, normalized);\n}\n\n/** Extension without the dot, lowercased. Empty when there is none. */\nexport function reloadableExtension(relative: string): string | null {\n const ext = extname(relative).replace('.', '').toLowerCase();\n return RELOADABLE.has(ext) ? ext : null;\n}\n\nconst digest = (content: string): string => createHash('sha1').update(content).digest('hex');\n\n/**\n * Record what every reloadable file already contains.\n *\n * Vite rewrites its whole output on each build, so without a baseline the\n * first rebuild after startup looks like every file changed at once.\n *\n * Read synchronously and before the watcher exists, on purpose. Doing it\n * asynchronously races the very first change: the walk can pick up a file\n * written a moment ago and then the change event finds a matching hash and\n * drops a real edit. The output tree is small; correctness is worth the wait.\n */\nfunction seedDigests(distDir: string): Map<string, string> {\n const seen = new Map<string, string>();\n const walk = (dir: string, prefix: string): void => {\n let items: Array<{ name: string; isDirectory: () => boolean }>;\n try {\n items = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n for (const item of items) {\n const rel = prefix ? `${prefix}/${item.name}` : item.name;\n if (item.isDirectory()) {\n walk(join(dir, item.name), rel);\n continue;\n }\n if (!reloadableExtension(rel)) continue;\n try {\n seen.set(rel, digest(readFileSync(join(distDir, rel), 'utf8')));\n } catch {\n // Unreadable now; the first change will record it.\n }\n }\n };\n walk(distDir, '');\n return seen;\n}\n\nexport function watchDist(options: WatchOptions): DistWatcher {\n const debounceMs = options.debounceMs ?? DEBOUNCE_MS;\n const pending = new Map<string, ReturnType<typeof setTimeout>>();\n /**\n * Last content seen per file.\n *\n * A rebuild rewrites every output file, changed or not, so the filesystem\n * event alone says \"the bundler ran\", not \"the developer edited this\".\n * Comparing content is what makes a reload mean the second thing, and it\n * matters: a language file rewritten untouched would redraw every open\n * window, undoing the scoped re-render on the file that did change.\n */\n const digests = seedDigests(options.distDir);\n\n const send = async (relative: string): Promise<void> => {\n const extension = reloadableExtension(relative);\n if (!extension) return;\n let content: string;\n try {\n content = await readFile(join(options.distDir, relative), 'utf8');\n } catch {\n // The file was renamed or removed between the event and the read.\n // Nothing to send, and nothing worth interrupting the developer for.\n return;\n }\n\n const hash = digest(content);\n if (digests.get(relative) === hash) return;\n digests.set(relative, hash);\n\n options.onPayload(\n JSON.stringify({\n packageType: options.packageType,\n packageId: options.packageId,\n content,\n path: servedPath(relative, options.packageId, options.packageType),\n extension,\n }),\n );\n };\n\n // Platforms disagree about a missing directory: macOS throws from `watch`,\n // Linux hands back a watcher that reports nothing at all. Checking first\n // gives the same answer everywhere instead of relying on either.\n if (!existsSync(options.distDir)) {\n options.onError?.(`Cannot watch ${options.distDir}: the directory does not exist.`);\n return { close: () => undefined };\n }\n\n let watcher: FSWatcher;\n try {\n watcher = watch(options.distDir, { recursive: true }, (_event, filename) => {\n if (!filename) return;\n const relative = filename.toString();\n clearTimeout(pending.get(relative));\n pending.set(\n relative,\n setTimeout(() => {\n pending.delete(relative);\n void send(relative);\n }, debounceMs),\n );\n });\n } catch (err) {\n options.onError?.(err instanceof Error ? err.message : String(err));\n return { close: () => undefined };\n }\n\n // Platforms disagree about how a bad path surfaces: macOS throws from\n // `watch` itself, Linux hands back a watcher that emits `error` a tick\n // later. Handling only the throw means a missing dist/ fails silently on\n // Linux, which is where CI runs.\n watcher.on('error', (err: unknown) => {\n options.onError?.(err instanceof Error ? err.message : String(err));\n });\n\n return {\n close: () => {\n for (const timer of pending.values()) clearTimeout(timer);\n pending.clear();\n watcher.close();\n },\n };\n}\n","/**\n * Foundry user-data directory discovery + persistence.\n *\n * Foundry stores worlds, systems, and modules under a single user-data\n * directory (`Data/` lives at its root). `vttforge dev` needs to know where\n * that is so it can symlink the built `dist/` into `Data/systems/<id>/` or\n * `Data/modules/<id>/` and let Foundry pick it up.\n *\n * Precedence (top wins):\n * 1. Explicit `--data-dir` flag passed to the command\n * 2. `FOUNDRY_DATA_DIR` env var (useful in Docker/CI)\n * 3. `<project>/.vttforge/config.json :: foundryDataDir`\n * 4. OS default + interactive prompt that saves to (3) for next time\n *\n * The OS-default detection treats `XDG_DATA_HOME` (Linux) and `%LOCALAPPDATA%`\n * (Windows) as part of the OS convention, not as Foundry-specific overrides.\n *\n * Everything here is pure: `platform`, `env`, and `home` flow through\n * options so tests can drive every branch without monkey-patching globals.\n */\n\nimport { existsSync } from 'node:fs';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { basename, dirname, join, resolve } from 'node:path';\n\n/** Shape persisted to `<project>/.vttforge/config.json`. */\nexport interface VTTForgeConfig {\n foundryDataDir?: string;\n}\n\n/**\n * Return the OS-default Foundry user-data directory, or `null` on unknown\n * platforms / missing platform-specific env vars. Does NOT check existence;\n * callers prompt the user when the suggested path doesn't resolve.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function autoDetectFoundryDataDir(\n platform: NodeJS.Platform = process.platform,\n env: NodeJS.ProcessEnv = process.env,\n home: string = homedir(),\n): string | null {\n switch (platform) {\n case 'darwin':\n return join(home, 'Library', 'Application Support', 'FoundryVTT');\n case 'linux': {\n const xdg = env.XDG_DATA_HOME;\n if (typeof xdg === 'string' && xdg.length > 0) {\n return join(xdg, 'FoundryVTT');\n }\n return join(home, '.local', 'share', 'FoundryVTT');\n }\n case 'win32': {\n const localAppData = env.LOCALAPPDATA;\n if (typeof localAppData === 'string' && localAppData.length > 0) {\n return join(localAppData, 'FoundryVTT');\n }\n return null;\n }\n default:\n return null;\n }\n}\n\n/**\n * Heuristic: a path looks like a Foundry user-data root if it contains a\n * `Data/` subdirectory (canonical Foundry layout) OR if it already contains\n * `systems/` or `modules/` (the path is already the Data folder itself).\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function looksLikeFoundryDataDir(path: string): boolean {\n if (!existsSync(path)) return false;\n return (\n existsSync(join(path, 'Data')) ||\n existsSync(join(path, 'systems')) ||\n existsSync(join(path, 'modules'))\n );\n}\n\nconst CONFIG_DIR = '.vttforge';\nconst CONFIG_FILE = 'config.json';\n\n/** Absolute path to the project-local config file (whether or not it exists).\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function configPath(cwd: string): string {\n return join(resolve(cwd), CONFIG_DIR, CONFIG_FILE);\n}\n\n/** Load `<cwd>/.vttforge/config.json` if it exists and is valid JSON.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport async function loadConfig(cwd: string): Promise<VTTForgeConfig | null> {\n const path = configPath(cwd);\n if (!existsSync(path)) return null;\n try {\n const raw = await readFile(path, 'utf8');\n const parsed: unknown = JSON.parse(raw);\n if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {\n return parsed as VTTForgeConfig;\n }\n return null;\n } catch {\n // Corrupted JSON: treat as missing rather than crashing the dev loop.\n // The next save (after a successful prompt) overwrites it cleanly.\n return null;\n }\n}\n\n/** Persist `<cwd>/.vttforge/config.json`. Creates the `.vttforge/` dir as needed.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport async function saveConfig(cwd: string, config: VTTForgeConfig): Promise<void> {\n const path = configPath(cwd);\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, `${JSON.stringify(config, null, 2)}\\n`, 'utf8');\n}\n\n/**\n * Heuristic: is `path` already Foundry's `Data/` folder (vs. its parent)?\n * We treat the path as Data when:\n * - basename is \"Data\" (case-insensitive, since macOS/Windows file systems\n * are case-insensitive by default), OR\n * - any of `systems/`, `modules/`, `worlds/` exists inside (proof that\n * Foundry has previously written package folders here).\n *\n * Used by `foundryPackagesDir` so users can supply EITHER the user-data\n * root OR the `Data/` folder directly without us double-nesting `Data/Data`.\n */\nfunction isFoundryDataFolder(path: string): boolean {\n // basename match, case-insensitive so `DATA`, `data`, `Data` all work on\n // macOS/Windows volumes that don't preserve case strictly. On Linux the\n // folder is always \"Data\" exactly; case-insensitive compare is harmless.\n if (basename(path).toLowerCase() === 'data') return true;\n return (\n existsSync(join(path, 'systems')) ||\n existsSync(join(path, 'modules')) ||\n existsSync(join(path, 'worlds'))\n );\n}\n\n/**\n * Resolve the packages directory (`Data/systems/` or `Data/modules/`) under\n * the given Foundry user-data root. Accepts the path Foundry itself runs\n * with (the user-data folder, which contains `Data/`) OR the `Data/` folder\n * directly; both are common in muscle memory.\n *\n * The returned path is not guaranteed to exist yet; callers `mkdir -p` it\n * before creating the symlink.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function foundryPackagesDir(dataRoot: string, type: 'system' | 'module'): string {\n const subFolder = type === 'system' ? 'systems' : 'modules';\n if (isFoundryDataFolder(dataRoot)) {\n return join(dataRoot, subFolder);\n }\n return join(dataRoot, 'Data', subFolder);\n}\n\n/**\n * Expand `~` / `~/` prefixes to the user's home directory. Shells do this\n * automatically; Node's `path.resolve` does NOT, so a user who types the\n * prompt's own example `~/Library/Application Support/FoundryVTT` would\n * end up with a symlink under `<cwd>/~/Library/...` if we skipped this.\n */\nfunction expandTilde(p: string, home: string): string {\n if (p === '~') return home;\n if (p.startsWith('~/') || p.startsWith('~\\\\')) return join(home, p.slice(2));\n return p;\n}\n\nexport interface ResolveDataDirOptions {\n /** Project root: also where `.vttforge/config.json` is read/written. */\n cwd: string;\n /** `--data-dir` flag value. Skips persistence and prompting when present. */\n override?: string;\n /**\n * Interactive prompt for the first run. Receives the OS-default path\n * (may be `null` on unknown platforms) and resolves with the chosen path,\n * or `null` if the user cancelled. When undefined, the function refuses\n * to ask and throws, appropriate for non-TTY contexts (CI, scripts).\n */\n prompt?: (autoDetected: string | null) => Promise<string | null>;\n /** Override `process.platform` (tests). */\n platform?: NodeJS.Platform;\n /** Override `process.env` (tests). */\n env?: NodeJS.ProcessEnv;\n /** Override `os.homedir()` (tests). */\n home?: string;\n}\n\n/**\n * Walk the precedence chain and return the chosen Foundry user-data path.\n * Saves the user's choice to the project config on first interactive run so\n * subsequent invocations skip the prompt.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport async function resolveFoundryDataDir(opts: ResolveDataDirOptions): Promise<string> {\n const { cwd, override, prompt } = opts;\n const env = opts.env ?? process.env;\n const platform = opts.platform ?? process.platform;\n const home = opts.home ?? homedir();\n\n if (typeof override === 'string' && override.length > 0) {\n return resolve(expandTilde(override, home));\n }\n\n const envValue = env.FOUNDRY_DATA_DIR;\n if (typeof envValue === 'string' && envValue.length > 0) {\n return resolve(expandTilde(envValue, home));\n }\n\n const config = await loadConfig(cwd);\n if (config?.foundryDataDir && existsSync(config.foundryDataDir)) {\n return config.foundryDataDir;\n }\n\n const detected = autoDetectFoundryDataDir(platform, env, home);\n\n if (prompt) {\n const choice = await prompt(detected);\n if (!choice) {\n throw new Error('No Foundry data directory selected. Aborting.');\n }\n const chosen = resolve(expandTilde(choice, home));\n await saveConfig(cwd, { ...config, foundryDataDir: chosen });\n return chosen;\n }\n\n // Non-interactive fallback: use the OS default if it actually exists.\n // Otherwise fail loudly with the env/flag/config knobs spelled out.\n if (detected && existsSync(detected)) {\n return detected;\n }\n throw new Error(\n 'Foundry data directory not configured. Set FOUNDRY_DATA_DIR, pass --data-dir, or run `vttforge dev` interactively to save the path to .vttforge/config.json.',\n );\n}\n","/**\n * `vttforge dev`: symlink dist/ into Foundry Data and run vite watch.\n *\n * Flow:\n * 1. Sanity-check the project layout (package.json present)\n * 2. Run `vite build` once to populate dist/\n * 3. Read the resulting manifest → id + system/module type\n * 4. Resolve the Foundry user-data directory (override / env / config /\n * OS default + interactive prompt that saves the choice)\n * 5. Create a symlink: `<dataRoot>/Data/<type>s/<id>` → `<cwd>/dist`\n * 6. Spawn `vite build --watch` with inherited stdio\n * 7. Block until SIGINT/SIGTERM, then clean up the symlink and kill vite\n *\n * Foundry's built-in `--hotReload` server flag wires the `flags.hotReload`\n * manifest entry (extensions + paths) to chokidar; the symlink we drop is\n * what chokidar watches, so saves through vite re-emit and Foundry reloads.\n * No additional client integration needed in this version.\n */\n\nimport type { ChildProcess } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport { composeMountLine, installDevModule, resolveDevModuleDir } from '../dev-module-install.js';\nimport { startDevServer } from '../dev-server.js';\nimport { watchDist } from '../dev-watcher.js';\nimport {\n foundryPackagesDir,\n type ResolveDataDirOptions,\n resolveFoundryDataDir,\n} from '../foundry-data-dir.js';\nimport { readManifest } from '../manifest.js';\nimport { createLink, readLinkTarget, removeLink } from '../symlink.js';\nimport { runViteBuildOnce, spawnViteWatch } from '../vite-runner.js';\n\nexport interface DevOptions {\n /** Override the project root. Defaults to `process.cwd()`. */\n cwd?: string;\n /** `--data-dir` flag value. Skips env/config/prompt lookup when set. */\n dataDir?: string;\n /** Port for the hot reload bridge. */\n hmrPort?: number;\n}\n\n/**\n * Where the bridge listens.\n *\n * `@vttforge/dev-module` dials this same number. If the two drift apart the\n * module retries a port nobody is listening on, forever and quietly. So a\n * test asserts they still agree.\n */\nexport const DEFAULT_HMR_PORT = 31_313;\n\ninterface BridgeOptions {\n cwd: string;\n distDir: string;\n dataRoot: string;\n manifest: Awaited<ReturnType<typeof readManifest>>;\n port: number;\n}\n\ninterface Bridge {\n close: () => Promise<void>;\n}\n\n/**\n * Stand up the hot reload bridge: install the companion module, open the\n * socket, watch the build output.\n *\n * Every failure here returns null rather than throwing. A busy port or a\n * missing companion package should cost the developer hot reload, not the\n * dev loop: the build and the symlink are the load-bearing parts, and they\n * already succeeded by the time this runs.\n */\nasync function startHotReloadBridge(opts: BridgeOptions): Promise<Bridge | null> {\n const packageDir = resolveDevModuleDir(opts.cwd);\n if (!packageDir) {\n p.note(\n 'Could not find @vttforge/dev-module. Install it to reload saves in place:\\n pnpm add -D @vttforge/dev-module',\n 'Hot reload unavailable',\n );\n return null;\n }\n\n let server: Awaited<ReturnType<typeof startDevServer>>;\n try {\n server = await startDevServer({ port: opts.port });\n } catch {\n p.note(\n `Port ${opts.port} is in use; another \\`vttforge dev\\` is probably running.\\nPass --hmr-port to use a different one.`,\n 'Hot reload unavailable',\n );\n return null;\n }\n\n const modulesDir = foundryPackagesDir(opts.dataRoot, 'module');\n try {\n const install = await installDevModule(modulesDir, packageDir);\n p.note(\n [\n `Companion module linked → ${install.target}`,\n 'Enable \"VTTForge Dev\" in the world, once.',\n '',\n 'Foundry in a container cannot follow that link. Mount it instead:',\n ` ${composeMountLine(packageDir)}`,\n ].join('\\n'),\n 'Hot reload',\n );\n } catch (err) {\n await server.close();\n p.note(\n `Could not install the companion module: ${err instanceof Error ? err.message : String(err)}`,\n 'Hot reload unavailable',\n );\n return null;\n }\n\n const watcher = watchDist({\n distDir: opts.distDir,\n packageId: opts.manifest.id,\n packageType: opts.manifest.type,\n onPayload: (frame) => server.broadcast(frame),\n onError: (message) => p.note(message, 'Watch error'),\n });\n\n return {\n close: async () => {\n watcher.close();\n await server.close();\n },\n };\n}\n\n/**\n * Compose a clack prompt that resolves to a Foundry user-data path or\n * `null` if the user cancels. Suitable for passing to\n * `resolveFoundryDataDir`.\n */\nfunction createDataDirPrompt(): NonNullable<ResolveDataDirOptions['prompt']> {\n return async (autoDetected) => {\n p.note(\n autoDetected\n ? `Detected Foundry user-data directory:\\n ${autoDetected}`\n : 'Could not auto-detect a Foundry user-data directory on this OS. Please type the path.',\n 'First-run setup',\n );\n if (autoDetected) {\n const useDetected = await p.confirm({\n message: 'Use detected directory?',\n initialValue: true,\n });\n if (p.isCancel(useDetected)) return null;\n if (useDetected === true) return autoDetected;\n }\n const custom = await p.text({\n message:\n 'Foundry user-data directory (the folder that contains Data/, e.g. ~/Library/Application Support/FoundryVTT)',\n placeholder: autoDetected ?? '/path/to/FoundryVTT',\n validate: (value: string | undefined) => {\n if (!value || value.trim().length === 0) return 'A path is required';\n return undefined;\n },\n });\n if (p.isCancel(custom)) return null;\n return String(custom).trim();\n };\n}\n\n/**\n * Install signal handlers that fire once. We use `process.once` so a second\n * Ctrl-C while cleanup is in flight propagates as a hard exit instead of\n * being swallowed (the user gave up on graceful shutdown; let them).\n */\nfunction installSignalHandlers(cleanup: () => Promise<void>): () => void {\n let invoked = false;\n const handler = () => {\n if (invoked) return;\n invoked = true;\n void cleanup();\n };\n process.once('SIGINT', handler);\n process.once('SIGTERM', handler);\n return () => {\n process.removeListener('SIGINT', handler);\n process.removeListener('SIGTERM', handler);\n };\n}\n\n/**\n * @experimental Shape is unproven: no consumer has asked for this yet. It can\n * change in a minor.\n */\nexport async function runDev(options: DevOptions = {}): Promise<void> {\n const cwd = options.cwd ? resolve(options.cwd) : process.cwd();\n\n p.intro('🜲 vttforge dev: symlink + watch');\n\n if (!existsSync(join(cwd, 'package.json'))) {\n p.cancel(`No package.json at ${cwd}. Run \\`vttforge dev\\` from inside a scaffolded project.`);\n throw new Error('Missing package.json');\n }\n\n // 1. Initial build\n const buildSpinner = p.spinner();\n buildSpinner.start('vite build (initial)');\n try {\n await runViteBuildOnce(cwd);\n buildSpinner.stop('Initial build complete');\n } catch (err) {\n buildSpinner.stop('Initial build failed');\n throw err;\n }\n\n const distDir = join(cwd, 'dist');\n\n // 2. Read manifest emitted by vite\n const manifest = await readManifest(distDir);\n\n // 3. Resolve Foundry data dir\n const interactive = Boolean(process.stdout.isTTY);\n const dataRoot = await resolveFoundryDataDir({\n cwd,\n override: options.dataDir,\n prompt: interactive ? createDataDirPrompt() : undefined,\n });\n\n // 4. Create symlink. We pass overwrite: true so the dev loop \"just works\"\n // when the user switches between projects with the same id. Real\n // files/dirs are still refused inside createLink.\n const packagesDir = foundryPackagesDir(dataRoot, manifest.type);\n const target = join(packagesDir, manifest.id);\n const existingTarget = await readLinkTarget(target);\n if (existingTarget && existingTarget !== distDir) {\n p.note(\n `Replacing stale symlink:\\n ${target}\\n was: ${existingTarget}\\n now: ${distDir}`,\n 'Symlink',\n );\n }\n await createLink(target, distDir, { overwrite: true });\n\n p.note(\n `Linked dist/ → ${target}\\nFoundry serves the package under /${manifest.type}s/${manifest.id}/.`,\n 'Symlinked',\n );\n // 5. Hot reload bridge. Failing to start it must not cost the developer\n // the whole dev loop: the build and the symlink are the load-bearing\n // parts, and a busy port should degrade to \"no hot reload\", not to\n // \"vttforge dev does not run\".\n const bridge = await startHotReloadBridge({\n cwd,\n distDir,\n dataRoot,\n manifest,\n port: options.hmrPort ?? DEFAULT_HMR_PORT,\n });\n\n p.note(\n `${bridge ? 'Saves apply in place, no page refresh.' : 'Hot reload is off; saves need a page refresh.'}\\nCtrl-C to stop.`,\n 'Watching',\n );\n\n // 6. Spawn watcher\n const watcher = spawnViteWatch(cwd);\n\n // 6. Block until SIGINT/SIGTERM\n await new Promise<void>((resolveDev) => {\n const cleanup = async () => {\n try {\n await cleanupDevSymlink({ target, expectedSource: distDir });\n } catch {\n // best-effort; Foundry rediscovers the next time dev runs.\n }\n await bridge?.close();\n if (!watcher.killed) watcher.kill('SIGINT');\n uninstall();\n resolveDev();\n };\n const uninstall = installSignalHandlers(cleanup);\n // If vite watcher dies on its own, surface it but don't auto-clean:\n // the user can re-run vttforge dev to re-establish.\n watcher.on('exit', (code) => {\n if (code !== 0 && code !== null) {\n // eslint-disable-next-line no-console\n console.error(`\\nvite watcher exited with code ${code}.`);\n }\n });\n });\n\n p.outro('Stopped. Symlink cleaned up.');\n}\n\n/**\n * Internal building block exposed for tests: given an already-built `dist/`\n * (vite has run, manifest is present) and a resolved Foundry data dir,\n * create the symlink and return the target path + manifest. Skips the\n * vite spawn and the signal-loop, so tests can drive the orchestration\n * deterministically.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport async function setupDevSymlink(opts: { cwd: string; dataRoot: string }): Promise<{\n target: string;\n manifest: Awaited<ReturnType<typeof readManifest>>;\n childProcess?: ChildProcess;\n}> {\n const cwd = resolve(opts.cwd);\n const distDir = join(cwd, 'dist');\n const manifest = await readManifest(distDir);\n const packagesDir = foundryPackagesDir(opts.dataRoot, manifest.type);\n const target = join(packagesDir, manifest.id);\n await createLink(target, distDir, { overwrite: true });\n return { target, manifest };\n}\n\n/**\n * Tear down a dev symlink iff it still points at the expected source.\n * Refuses to remove a symlink that another `vttforge dev` session (or a\n * manual `ln -s`) has since redirected. That link doesn't belong to us\n * and removing it would silently disconnect their setup.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport async function cleanupDevSymlink(opts: {\n target: string;\n expectedSource: string;\n}): Promise<void> {\n const current = await readLinkTarget(opts.target);\n if (current === opts.expectedSource) {\n await removeLink(opts.target);\n }\n}\n","/**\n * Git helpers for the init scaffolder. Optional: every step degrades to a\n * warning, never throws. The scaffold completes even if git is missing or\n * the user has no global git config. The user can still `git init`\n * themselves later.\n */\nimport { execFile } from 'node:child_process';\nimport { promisify } from 'node:util';\n\nconst execFileAsync = promisify(execFile);\n\n/**\n * Read `git config user.name` to pre-fill the author prompt. Returns\n * `undefined` if git is missing or the value is unset.\n */\nexport async function readGitAuthorName(): Promise<string | undefined> {\n try {\n const { stdout } = await execFileAsync('git', ['config', '--get', 'user.name']);\n const value = stdout.trim();\n return value.length > 0 ? value : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Initialize a fresh git repository in `cwd`, run an initial commit. Errors\n * are swallowed and converted to a return value so the caller can decide\n * whether to warn or move on.\n */\nexport async function initGitRepo(cwd: string): Promise<{ ok: boolean; reason?: string }> {\n try {\n await execFileAsync('git', ['init', '--initial-branch=main'], { cwd });\n await execFileAsync('git', ['add', '.'], { cwd });\n await execFileAsync('git', ['commit', '-m', 'chore: initial scaffold from @vttforge/cli'], {\n cwd,\n });\n return { ok: true };\n } catch (err) {\n return { ok: false, reason: err instanceof Error ? err.message : String(err) };\n }\n}\n","/**\n * Template copy with `{{var}}` placeholder substitution.\n *\n * Templates live under `packages/cli/templates/<variant>/` and are shipped\n * inside the published tarball (see the `files` array in package.json).\n * Each file is read, substituted, and written to the destination directory\n * preserving the relative path. Directories are created lazily on first\n * write.\n *\n * We intentionally avoid Handlebars or any other template engine. The\n * substitution surface is small (a flat string-to-string map), and bundling\n * a dependency for ten lines of regex would be wasteful in a tool whose\n * value is being fast to invoke.\n */\n\nimport { existsSync } from 'node:fs';\nimport { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nexport interface ScaffoldVars {\n ID: string;\n TITLE: string;\n DESCRIPTION: string;\n AUTHOR: string;\n LICENSE: string;\n FOUNDRY_MIN_VERSION: string;\n FOUNDRY_VERIFIED_VERSION: string;\n LOCALE_PREFIX: string;\n YEAR: string;\n}\n\nexport interface ScaffoldOptions {\n /** Absolute path to the template root (e.g. `<cli-pkg>/templates/system-ts`). */\n templateDir: string;\n /** Absolute path to the destination directory. Created if it doesn't exist. */\n destDir: string;\n /** Variables to substitute into `{{NAME}}` placeholders inside template files. */\n vars: ScaffoldVars;\n}\n\nconst PLACEHOLDER_RE = /\\{\\{(\\w+)\\}\\}/g;\n\n/**\n * Replace `{{NAME}}` placeholders in `content` using the `vars` map.\n * Unknown placeholders are passed through unchanged so partially-templated\n * files (e.g. a snippet that contains `{{handlebarsLikeSyntax}}` as literal\n * content) still scaffold without surprises.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function substitute(content: string, vars: ScaffoldVars): string {\n const lookup = vars as unknown as Record<string, string>;\n return content.replace(PLACEHOLDER_RE, (match, key: string) =>\n Object.hasOwn(lookup, key) ? (lookup[key] ?? match) : match,\n );\n}\n\n/**\n * Walk `dir` recursively and yield every file path relative to `dir`.\n */\nasync function* walkRelative(dir: string, base: string = dir): AsyncGenerator<string> {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const full = join(dir, entry.name);\n if (entry.isDirectory()) {\n yield* walkRelative(full, base);\n } else if (entry.isFile()) {\n yield relative(base, full);\n }\n }\n}\n\n/**\n * Files that should be substituted as text. Binary assets (.png, .ico, …)\n * bypass substitution and are copied byte-for-byte. The list of binary\n * extensions is intentionally small; extend if we add real binary assets\n * to templates.\n */\nconst BINARY_EXTENSIONS = new Set([\n '.png',\n '.jpg',\n '.jpeg',\n '.gif',\n '.webp',\n '.ico',\n '.woff',\n '.woff2',\n '.ttf',\n '.otf',\n]);\n\nfunction isBinaryPath(path: string): boolean {\n const dotIndex = path.lastIndexOf('.');\n if (dotIndex < 0) return false;\n return BINARY_EXTENSIONS.has(path.slice(dotIndex).toLowerCase());\n}\n\n/**\n * Files whose source name in the template is rewritten at scaffold time so\n * npm packaging doesn't strip or rename them. npm transforms `.gitignore`\n * into `.npmignore` on publish, so templates ship `_gitignore` and the\n * scaffolder writes `.gitignore` into the generated project.\n */\nconst SCAFFOLD_PATH_RENAMES = new Map<string, string>([['_gitignore', '.gitignore']]);\n\nfunction rewriteDestRelPath(relPath: string): string {\n const base = relPath.split('/').pop() ?? relPath;\n const replacement = SCAFFOLD_PATH_RENAMES.get(base);\n if (replacement === undefined) return relPath;\n return relPath.slice(0, relPath.length - base.length) + replacement;\n}\n\n/**\n * @internal Implementation detail of the `vttforge` binary. Not supported for\n * outside use, and going away in the next major.\n */\nexport async function scaffold({ templateDir, destDir, vars }: ScaffoldOptions): Promise<void> {\n if (!existsSync(templateDir)) {\n throw new Error(`[vttforge] template directory does not exist: ${templateDir}`);\n }\n const info = await stat(templateDir);\n if (!info.isDirectory()) {\n throw new Error(`[vttforge] template path is not a directory: ${templateDir}`);\n }\n\n await mkdir(destDir, { recursive: true });\n\n for await (const relPath of walkRelative(templateDir)) {\n const srcPath = join(templateDir, relPath);\n // Apply substitution to the path itself so we can name files like\n // `{{ID}}.code-workspace` if we ever need that. Today no template path\n // uses placeholders, but the support is free. Then apply the rename map\n // so packaging-stripped names (e.g. `_gitignore`) land at their real\n // destination (e.g. `.gitignore`).\n const substituted = substitute(relPath, vars);\n const destPath = join(destDir, rewriteDestRelPath(substituted));\n await mkdir(dirname(destPath), { recursive: true });\n\n if (isBinaryPath(srcPath)) {\n const bytes = await readFile(srcPath);\n await writeFile(destPath, bytes);\n continue;\n }\n\n const content = await readFile(srcPath, 'utf8');\n await writeFile(destPath, substitute(content, vars), 'utf8');\n }\n}\n\n/**\n * Resolve the templates directory relative to this module's file URL. tsdown\n * emits `dist/scaffold.mjs`, so `import.meta.url` points there at runtime;\n * we walk up two segments to land at the package root, then descend into\n * `templates/`.\n *\n * @internal Implementation detail of the `vttforge` binary. Not supported\n * for outside use, and going away in the next major.\n */\nexport function templatesRoot(): string {\n const here = fileURLToPath(import.meta.url);\n // dist/scaffold.mjs → ../ = dist/, ../../ = package root\n return resolve(here, '..', '..', 'templates');\n}\n","/**\n * `vttforge init`: interactive scaffolder.\n *\n * Honors CLI flags first, prompts for everything missing, then copies the\n * matching template into the destination directory. Optionally `git init`s\n * and runs the detected package manager's install command at the end.\n */\n\nimport { spawn } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport { initGitRepo, readGitAuthorName } from '../git.js';\nimport { detectPackageManager, installCommand } from '../package-manager.js';\nimport { type ScaffoldVars, scaffold, templatesRoot } from '../scaffold.js';\n\nexport interface InitOptions {\n name?: string;\n type?: 'system' | 'module';\n lang?: 'ts' | 'js';\n /** Manifest id. Defaults to a slug of the directory name. */\n id?: string;\n /** Human-readable title shown in Foundry's setup screens. */\n title?: string;\n /** One-line description for the manifest. */\n description?: string;\n /** Author name for the manifest. Defaults to the local git author. */\n author?: string;\n /** SPDX license id written to package.json. */\n license?: string;\n /**\n * Take the default for anything not supplied instead of asking.\n *\n * Required to scaffold without a terminal: a prompt with nothing to read\n * from waits forever, which is no way to fail.\n */\n yes?: boolean;\n noInstall?: boolean;\n noGit?: boolean;\n /** Override the working directory (test hook). Defaults to `process.cwd()`. */\n cwd?: string;\n}\n\nexport interface ResolvedInitOptions\n extends Required<\n Omit<InitOptions, 'cwd' | 'id' | 'title' | 'description' | 'author' | 'license' | 'yes'>\n > {\n cwd: string;\n dest: string;\n id: string;\n title: string;\n description: string;\n author: string;\n license: string;\n foundryMinVersion: string;\n foundryVerifiedVersion: string;\n templateVariant: TemplateVariant;\n}\n\nexport type TemplateVariant = 'system-ts' | 'system-js' | 'module-ts' | 'module-js';\n\nconst PACKAGE_ID_RE = /^[a-z][a-z0-9-]*$/;\nconst UNSAFE_METADATA_CHARS_RE = /[\"\\\\\\r\\n\\t]/;\n\n// Clack hands validators `string | undefined`; the prompt calls them before\n// anything is typed. Blank metadata is allowed here; only the `Required`\n// variant below rejects it.\nexport function validateMetadata(value: string | undefined): string | undefined {\n if (!value) return undefined;\n // Reject characters that would break JSON string contexts in the\n // generated manifests/i18n catalogues. Apostrophes are fine: every JS\n // string literal in the templates is double-quoted, every JSON value is\n // double-quoted. Backslashes and double quotes need explicit escaping\n // we don't perform during substitution, so we reject them at the\n // prompt instead of producing broken scaffolds.\n if (UNSAFE_METADATA_CHARS_RE.test(value)) {\n return 'Avoid backslashes, double quotes, and line breaks; they break the generated manifest.';\n }\n // Reject `*/` because metadata is interpolated into JS/CSS block-comment\n // headers in the generated files; a stray comment terminator there\n // closes the header early and leaves trailing source garbage.\n if (value.includes('*/')) {\n return 'Avoid `*/`; it closes block comments in the generated source headers.';\n }\n return undefined;\n}\n\nexport function validateRequiredMetadata(value: string | undefined): string | undefined {\n if (!value || value.trim().length === 0) {\n return 'Required: Foundry rejects packages with a blank title.';\n }\n return validateMetadata(value);\n}\n\nexport function validatePackageId(value: string | undefined): string | undefined {\n // Coalesce before the test. `PACKAGE_ID_RE.test(undefined)` coerces to the\n // string \"undefined\", which matches the pattern and would let a missing id\n // through.\n if (!PACKAGE_ID_RE.test(value ?? '')) {\n return 'Package id must start with a letter and contain only lowercase letters, digits, dashes';\n }\n return undefined;\n}\n\n/**\n * Thrown when the scaffolder cannot continue: bad input, an existing\n * destination, a cancelled prompt, etc. `runInit` propagates these instead\n * of calling `process.exit`, so library consumers (tests, other CLIs) can\n * catch and recover. The `vttforge` bin wraps `runInit` in a top-level\n * handler that prints the message and exits with code 1.\n */\nexport class ScaffoldError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ScaffoldError';\n }\n}\n\nfunction isCancelled(value: unknown): boolean {\n return p.isCancel(value);\n}\n\nfunction bail(message: string): never {\n p.cancel(message);\n throw new ScaffoldError(message);\n}\n\nfunction slugify(input: string): string {\n return input\n .toLowerCase()\n .replace(/[^a-z0-9-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .replace(/-{2,}/g, '-');\n}\n\nfunction localePrefix(id: string): string {\n return id.toUpperCase().replace(/-/g, '_');\n}\n\nfunction titleCase(input: string): string {\n return input\n .split(/[-_\\s]+/)\n .filter((part) => part.length > 0)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(' ');\n}\n\n/**\n * Whether we may ask the user anything at all.\n *\n * Clack reads from stdin. With no terminal attached there is nothing to read,\n * and the prompt simply hangs. So a run that cannot ask has to be told every\n * answer up front, or be given `--yes` and take the defaults.\n */\nfunction canPrompt(yes: boolean | undefined): boolean {\n return yes !== true && Boolean(process.stdin.isTTY);\n}\n\nfunction templateVariantFor(type: 'system' | 'module', lang: 'ts' | 'js'): TemplateVariant {\n return `${type}-${lang}` as TemplateVariant;\n}\n\nexport async function runInit(options: InitOptions = {}): Promise<void> {\n const cwd = options.cwd ?? process.cwd();\n const interactive = canPrompt(options.yes);\n p.intro('🜲 vttforge init: scaffold a Foundry v14+ system or module');\n\n // --- name ------------------------------------------------------------------\n let name = options.name?.trim();\n if (!name && !interactive) {\n bail(\n 'A directory name is required when running without prompts. Pass it as the first argument: `vttforge init my-module --yes`.',\n );\n }\n if (!name) {\n const answer = await p.text({\n message: 'Directory name (also the default manifest id)',\n placeholder: 'my-system',\n validate: (value: string | undefined) => {\n const trimmed = value?.trim() ?? '';\n if (trimmed.length === 0) return 'Name is required';\n if (!PACKAGE_ID_RE.test(trimmed)) {\n return 'Use only lowercase letters, digits, and dashes (no spaces, slashes, dots).';\n }\n return undefined;\n },\n });\n if (isCancelled(answer)) bail('Scaffold cancelled.');\n name = String(answer).trim();\n } else if (!PACKAGE_ID_RE.test(name)) {\n bail(\n `Invalid name \"${name}\": use only lowercase letters, digits, and dashes (no spaces, slashes, dots).`,\n );\n }\n const dest = resolve(cwd, name);\n if (existsSync(dest)) {\n bail(`Directory already exists: ${dest}`);\n }\n\n // --- type ------------------------------------------------------------------\n let type = options.type;\n if (type !== 'system' && type !== 'module' && !interactive) {\n type = 'system';\n }\n if (type !== 'system' && type !== 'module') {\n const answer = await p.select({\n message: 'What are you building?',\n options: [\n { value: 'system', label: 'system: defines the game rules (Actor/Item types, sheets)' },\n {\n value: 'module',\n label: 'module: extends an existing system or adds cross-system features',\n },\n ],\n initialValue: 'system',\n });\n if (isCancelled(answer)) bail('Scaffold cancelled.');\n type = answer as 'system' | 'module';\n }\n\n // --- lang ------------------------------------------------------------------\n let lang = options.lang;\n if (lang !== 'ts' && lang !== 'js' && !interactive) {\n lang = 'ts';\n }\n if (lang !== 'ts' && lang !== 'js') {\n const answer = await p.select({\n message: 'Language',\n options: [\n { value: 'ts', label: 'TypeScript' },\n { value: 'js', label: 'JavaScript (.mjs)' },\n ],\n initialValue: 'ts',\n });\n if (isCancelled(answer)) bail('Scaffold cancelled.');\n lang = answer as 'ts' | 'js';\n }\n\n // --- id / title / description / author ------------------------------------\n /**\n * Resolve one metadata field: an explicit flag wins, otherwise ask, and\n * when asking is impossible take the default.\n */\n const resolveField = async (\n provided: string | undefined,\n fallback: string,\n ask: () => Promise<unknown>,\n validate: (value: string) => string | undefined,\n ): Promise<string> => {\n if (provided !== undefined) {\n const trimmed = provided.trim();\n const failure = validate(trimmed);\n if (failure !== undefined) bail(`${failure} (got ${JSON.stringify(provided)})`);\n return trimmed;\n }\n if (!interactive) return fallback;\n const answer = await ask();\n if (isCancelled(answer)) bail('Scaffold cancelled.');\n const value = String(answer).trim();\n return value.length > 0 ? value : fallback;\n };\n\n const defaultId = slugify(name);\n const id = await resolveField(\n options.id,\n defaultId,\n () =>\n p.text({\n message: 'Package id (used as the folder Foundry serves under /<systems|modules>/<id>/)',\n initialValue: defaultId,\n validate: validatePackageId,\n }),\n validatePackageId,\n );\n\n const title = await resolveField(\n options.title,\n titleCase(id),\n () =>\n p.text({\n message: 'Title (human-readable, shown in Foundry setup screens)',\n initialValue: titleCase(id),\n validate: validateRequiredMetadata,\n }),\n validateRequiredMetadata,\n );\n\n const defaultDescription = `A Foundry v14+ ${type} built with VTTForge`;\n const description = await resolveField(\n options.description,\n defaultDescription,\n () =>\n p.text({\n message: 'One-line description',\n placeholder: defaultDescription,\n initialValue: defaultDescription,\n validate: validateMetadata,\n }),\n validateMetadata,\n );\n\n const rawDetectedAuthor = await readGitAuthorName();\n // The git fallback bypasses Clack validation, so apply the same metadata\n // safety check before letting it through. If the local git config has\n // something we'd reject from a prompt, drop the suggestion and let the\n // user type a clean value (or land on the 'Anonymous' default).\n const detectedAuthor =\n rawDetectedAuthor && validateMetadata(rawDetectedAuthor) === undefined\n ? rawDetectedAuthor\n : undefined;\n const author = await resolveField(\n options.author,\n detectedAuthor ?? 'Anonymous',\n () =>\n p.text({\n message: 'Author name (used in the manifest)',\n placeholder: detectedAuthor ?? 'Your Name',\n initialValue: detectedAuthor ?? '',\n validate: validateMetadata,\n }),\n validateMetadata,\n );\n\n const license = await resolveField(\n options.license,\n 'MIT',\n () =>\n p.select({\n message: 'License',\n options: [\n { value: 'MIT', label: 'MIT (recommended for Foundry community packages)' },\n { value: 'Apache-2.0', label: 'Apache-2.0' },\n { value: 'GPL-3.0-or-later', label: 'GPL-3.0-or-later' },\n { value: 'UNLICENSED', label: 'UNLICENSED (private use only)' },\n ],\n initialValue: 'MIT',\n }),\n validateRequiredMetadata,\n );\n\n const foundryMinVersion = '14';\n const foundryVerifiedVersion = '14';\n\n // --- scaffold --------------------------------------------------------------\n const templateVariant = templateVariantFor(type, lang);\n const templateDir = resolve(templatesRoot(), templateVariant);\n if (!existsSync(templateDir)) {\n bail(`Template \"${templateVariant}\" not found at ${templateDir}`);\n }\n\n const vars: ScaffoldVars = {\n ID: id,\n TITLE: title,\n DESCRIPTION: description,\n AUTHOR: author,\n LICENSE: license,\n FOUNDRY_MIN_VERSION: foundryMinVersion,\n FOUNDRY_VERIFIED_VERSION: foundryVerifiedVersion,\n LOCALE_PREFIX: localePrefix(id),\n YEAR: String(new Date().getFullYear()),\n };\n\n const scaffoldSpinner = p.spinner();\n scaffoldSpinner.start(`Scaffolding ${templateVariant} into ${name}/`);\n try {\n await scaffold({ templateDir, destDir: dest, vars });\n scaffoldSpinner.stop(`Scaffold written to ${dest}`);\n } catch (err) {\n scaffoldSpinner.stop('Scaffold failed.');\n throw err;\n }\n\n // --- install ---------------------------------------------------------------\n // Install runs BEFORE git init so the lockfile lands in the initial commit\n // Generated repos that ship with a lockfile install reproducibly and\n // the working tree stays clean after scaffold.\n const pm = detectPackageManager();\n let shouldInstall = !options.noInstall;\n if (shouldInstall && interactive) {\n const confirm = await p.confirm({\n message: `Install dependencies now with ${pm}?`,\n initialValue: true,\n });\n if (isCancelled(confirm))\n bail('Scaffold cancelled at install prompt (your scaffold is intact).');\n shouldInstall = confirm === true;\n }\n\n if (shouldInstall) {\n const installSpinner = p.spinner();\n installSpinner.start(`Running ${installCommand(pm)}`);\n try {\n await runInstall(pm, dest);\n installSpinner.stop(`Dependencies installed (${pm}).`);\n } catch (err) {\n installSpinner.stop(`Install failed: ${err instanceof Error ? err.message : String(err)}`);\n p.note(\n `Run \\`${installCommand(pm)}\\` inside ${name}/ to retry.`,\n 'Continuing without install.',\n );\n }\n }\n\n // --- git -------------------------------------------------------------------\n // Runs AFTER install so the resulting lockfile is captured by the first\n // commit and the working tree stays clean.\n if (!options.noGit) {\n const gitSpinner = p.spinner();\n gitSpinner.start('Initializing git repository');\n const gitResult = await initGitRepo(dest);\n if (gitResult.ok) {\n gitSpinner.stop('Git initialized (branch: main, initial commit landed).');\n } else {\n gitSpinner.stop(`Skipped git init: ${gitResult.reason ?? 'unknown error'}`);\n }\n }\n\n // --- outro -----------------------------------------------------------------\n const nextSteps = [\n `cd ${name}`,\n !shouldInstall ? installCommand(pm) : null,\n `${pm} run build`,\n 'Symlink dist/ into your Foundry Data/<systems|modules>/<id>/ (or use the dev compose mount)',\n ]\n .filter((line): line is string => line !== null)\n .map((line, idx) => ` ${idx + 1}. ${line}`)\n .join('\\n');\n p.note(nextSteps, 'Next steps');\n p.outro('Have fun building.');\n}\n\nfunction runInstall(pm: string, cwd: string): Promise<void> {\n return new Promise((resolveInstall, rejectInstall) => {\n const child = spawn(pm, ['install'], {\n cwd,\n stdio: 'inherit',\n env: process.env,\n });\n child.on('error', rejectInstall);\n child.on('exit', (code) => {\n if (code === 0) resolveInstall();\n else rejectInstall(new Error(`${pm} install exited with code ${code}`));\n });\n });\n}\n","/**\n * `vttforge lint`: Biome over the project, then the v14 audit.\n *\n * Biome ships as a dependency of this package, so a scaffolded project has\n * a linter and a formatter without installing or configuring one. The\n * config it runs with is `<cli-pkg>/lint/vttforge-biome.json` unless the project\n * has its own `biome.json` / `biome.jsonc` at its root, in which case that\n * one wins and the shipped config is not read at all. A project that wants\n * to tweak a rule copies the shipped file and edits it.\n *\n * `--fix` writes the safe fixes and formats the files; without it the run\n * only reports. The audit runs after Biome either way (`--no-audit` skips\n * it), and the exit code is non-zero when either half fails.\n */\n\nimport { spawn } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { runAuditCommand } from './audit.js';\n\nexport interface LintOptions {\n /** Project root to lint. Defaults to `process.cwd()`. */\n cwd?: string;\n /** Write the safe fixes and format the files. Default false: report only. */\n fix?: boolean;\n /** Run `vttforge audit` after Biome. Default true. */\n audit?: boolean;\n /** Passed to the audit: any finding fails, not only HIGH. Default false. */\n strict?: boolean;\n /** Custom writer for the audit report (tests). Defaults to process.stdout.write. */\n write?: (chunk: string) => void;\n}\n\nexport interface LintResult {\n /** Exit code of the Biome run. */\n biomeExitCode: number;\n /** Exit code of the audit, or `null` when it was skipped. */\n auditExitCode: 0 | 1 | null;\n /** Non-zero when either half failed. */\n exitCode: number;\n /** The shipped Biome config file in use. `null` means the project's own. */\n configPath: string | null;\n}\n\nclass BiomeNotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'BiomeNotFoundError';\n }\n}\n\n/**\n * The Biome config shipped with the CLI, resolved from the built module.\n *\n * The file is not named `biome.json` on purpose: Biome treats a file with\n * that name as a nested root config and refuses to run, which would break\n * a project (or this monorepo) that holds the CLI inside another\n * Biome-rooted tree. `--config-path` accepts any file path.\n */\nconst SHIPPED_CONFIG_NAME = 'vttforge-biome.json';\n\nfunction shippedConfig(): string {\n const here = fileURLToPath(import.meta.url);\n // dist/bin.mjs → ../ = dist/, ../../ = package root. In tests the file\n // is src/commands/lint.ts, so the same walk must also land at the root.\n const fromDist = resolve(here, '..', '..', 'lint', SHIPPED_CONFIG_NAME);\n if (existsSync(fromDist)) return fromDist;\n return resolve(here, '..', '..', '..', 'lint', SHIPPED_CONFIG_NAME);\n}\n\n/** The project's own config wins when it has one. */\nfunction projectConfig(cwd: string): string | null {\n for (const name of ['biome.json', 'biome.jsonc']) {\n const file = join(cwd, name);\n if (existsSync(file)) return file;\n }\n return null;\n}\n\n/** The Biome bin shim, resolved from this package's own dependency graph. */\nfunction biomeBin(): string {\n const require = createRequire(import.meta.url);\n try {\n return require.resolve('@biomejs/biome/bin/biome');\n } catch {\n throw new BiomeNotFoundError(\n 'Could not resolve @biomejs/biome from @vttforge/cli. Reinstall the CLI (it ships Biome as a dependency).',\n );\n }\n}\n\n/** The argv for Biome: `ci .` to report, `check --write .` to fix. */\nexport function biomeArgs(opts: { fix: boolean; configPath: string | null }): string[] {\n const args = opts.fix ? ['check', '--write', '.'] : ['ci', '.'];\n if (opts.configPath) args.push(`--config-path=${opts.configPath}`);\n return args;\n}\n\nfunction runBiome(cwd: string, args: string[]): Promise<number> {\n const bin = biomeBin();\n return new Promise((resolveRun, rejectRun) => {\n const child = spawn(process.execPath, [bin, ...args], {\n cwd,\n stdio: 'inherit',\n env: process.env,\n shell: false,\n });\n child.on('error', rejectRun);\n child.on('exit', (code) => resolveRun(code ?? 1));\n });\n}\n\n/**\n * @experimental Shape is unproven: no consumer has asked for this yet. It can\n * change in a minor.\n */\nexport async function runLintCommand(options: LintOptions = {}): Promise<LintResult> {\n const cwd = resolve(options.cwd ?? process.cwd());\n const fix = options.fix === true;\n const audit = options.audit !== false;\n\n if (!existsSync(join(cwd, 'package.json'))) {\n throw new Error(\n `No package.json found at ${cwd}. Run \\`vttforge lint\\` from inside a scaffolded project.`,\n );\n }\n\n const configPath = projectConfig(cwd) === null ? shippedConfig() : null;\n const biomeExitCode = await runBiome(cwd, biomeArgs({ fix, configPath }));\n\n let auditExitCode: 0 | 1 | null = null;\n if (audit) {\n const result = await runAuditCommand({\n cwd,\n strict: options.strict === true,\n write: options.write,\n });\n auditExitCode = result.exitCode;\n }\n\n const exitCode = biomeExitCode !== 0 ? biomeExitCode : (auditExitCode ?? 0);\n return { biomeExitCode, auditExitCode, exitCode, configPath };\n}\n","/**\n * @vttforge/cli: public library exports.\n *\n * The product here is the `vttforge` binary. These exports exist so another\n * tool can drive the same work without shelling out, and they fall into three\n * groups, marked per export below.\n *\n * **Supported.** `runInit` and the audit surface. `create-vttforge` calls\n * `runInit`, and the audit rules are a documented extension point: a project\n * can write its own `RuleFn` and hand it to the same reporter the CLI uses.\n * These follow the deprecation policy.\n *\n * **`@experimental`.** Plausibly useful to a tool author, but no consumer has\n * ever asked for them, so the shape is a guess. They can change in a minor.\n *\n * **`@internal`.** Implementation detail of the binary that reached the index\n * by accident. Nothing outside this package imports them. They are staying\n * only until the next major, and importing one is not supported today.\n *\n * See apps/docs/stability.md for what each tag promises.\n */\n\nimport { version } from '../package.json' with { type: 'json' };\n\n/** Supported: run every audit rule over a project root. */\nexport { type RunAuditOptions, runAudit } from './audit/index.js';\nexport { runManifestRules } from './audit/manifest-rules.js';\nexport type { ReportFormat } from './audit/reporter.js';\nexport { formatReport } from './audit/reporter.js';\nexport { runSourceRules } from './audit/source-rules.js';\nexport type { AuditReport, RuleFn, RuleResult, Severity } from './audit/types.js';\nexport { SEVERITY_RANK } from './audit/types.js';\nexport type { AuditOptions, AuditResult } from './commands/audit.js';\n/** @experimental The command wrapper. Prefer `runAudit` plus `formatReport`. */\nexport { runAuditCommand } from './commands/audit.js';\nexport type { BuildOptions } from './commands/build.js';\n/** @experimental Shape is a guess; no consumer has asked for it yet. */\nexport { emitReleaseZip, runBuild } from './commands/build.js';\nexport type { DevOptions } from './commands/dev.js';\n/** @experimental Shape is unproven; `vttforge dev` is the supported way in. */\nexport { runDev } from './commands/dev.js';\nexport type { InitOptions, ResolvedInitOptions, TemplateVariant } from './commands/init.js';\n/** Supported: scaffold a project. This is what `create-vttforge` calls. */\nexport { runInit, ScaffoldError } from './commands/init.js';\nexport type { LintOptions, LintResult } from './commands/lint.js';\n/** @experimental The command wrapper around Biome plus the audit. */\nexport { runLintCommand } from './commands/lint.js';\nexport type { FoundryManifest, PackageType } from './manifest.js';\n/** @experimental Reads `system.json` / `module.json`. Useful, unproven. */\nexport { readManifest } from './manifest.js';\nexport type { EmitZipOptions, EmitZipResult } from './zip.js';\n/** @experimental Lower level than `emitReleaseZip`. */\nexport { emitZip } from './zip.js';\n\nexport const VTTFORGE_CLI_VERSION: string = version;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACuBA,MAAMA,mBAAiB,CAAC,eAAe,aAAa;;;;;;;;AAepD,eAAe,cAAc,KAAwC;CACnE,MAAM,MAAwB,CAAC;CAC/B,KAAK,MAAM,QAAQA,kBAAgB;EACjC,MAAM,OAAO,KAAK,KAAK,IAAI;EAC3B,IAAI,CAAC,WAAW,IAAI,GAAG;EACvB,IAAI;EACJ,IAAI;GACF,MAAM,MAAM,SAAS,MAAM,MAAM;EACnC,QAAQ;GACN;EACF;EACA,IAAI;EACJ,IAAI;GACF,SAAS,KAAK,MAAM,GAAG;EACzB,QAAQ;GACN;EACF;EACA,IAAI,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,MAAM,GAC/D,IAAI,KAAK;GAAE;GAAM;GAAa;EAAkC,CAAC;CAErE;CACA,OAAO;AACT;;;;;;;AAQA,SAAS,YAAY,KAAa,KAAiC;CACjE,MAAM,SAAS,IAAI,IAAI;CACvB,MAAM,MAAM,IAAI,QAAQ,MAAM;CAC9B,IAAI,MAAM,GAAG,OAAO,KAAA;CACpB,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,KAAK,GAC5B,IAAI,IAAI,OAAO,MAAM,QAAQ;CAE/B,OAAO;AACT;;;;;;;;;;AAWA,SAAS,cAAc,UAAwC;CAC7D,MAAM,QAAQ,SAAS,OA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