#!/usr/bin/env node import { readdir, readFile, stat } from "node:fs/promises"; import { join, relative } from "node:path"; const root = new URL("..", import.meta.url).pathname; const scannedExtensions = new Set([".md", ".json", ".ts", ".js", ".mjs", ".sh"]); const installSpecificPath = ["", "Users", "stefano"].join("/"); const forbidden = [ { pattern: installSpecificPath, message: "Source files must not hardcode this install path" } ]; function extensionOf(path) { const dot = path.lastIndexOf("."); return dot === -1 ? "" : path.slice(dot); } async function walk(dir) { const entries = await readdir(dir); const files = []; for (const entry of entries) { if (["node_modules", "dist", "coverage", "tmp", "out"].includes(entry)) { continue; } const path = join(dir, entry); const info = await stat(path); if (info.isDirectory()) { files.push(...await walk(path)); } else if (scannedExtensions.has(extensionOf(path)) || entry === "SKILL.md") { files.push(path); } } return files; } const failures = []; for (const file of await walk(root)) { const text = await readFile(file, "utf8"); for (const rule of forbidden) { if (text.includes(rule.pattern)) { failures.push(`${relative(root, file)}: ${rule.message}`); } } } if (failures.length > 0) { for (const failure of failures) { console.error(failure); } process.exitCode = 1; }