Move the skill to .agents/skills/tttk-authoring and point gen:skill-reference at it. Activate it by symlinking ~/.agents/skills/tttk-authoring to the in-repo copy. Extend the reference drift guard to cover the skill copy now that it is versioned, and document activation in docs/development.md.
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
/**
|
|
* Drift guard: `KNOWN_ELEMENTS` in `known.ts` must match the `customElement`
|
|
* registrations under `src/components`. This is what would have caught
|
|
* `:md-card` — matched by the completion scanner but registered nowhere.
|
|
*/
|
|
|
|
import { readdirSync, readFileSync } from "fs";
|
|
import { join } from "path";
|
|
import { ELEMENT_NAMES } from "./known.js";
|
|
import { renderReference } from "./reference.js";
|
|
|
|
const COMPONENTS_DIR = join(process.cwd(), "src", "components");
|
|
const CUSTOM_ELEMENT_RE = /customElement(?:<[^>]*>)?\(\s*["'](md-[\w-]+)["']/g;
|
|
|
|
function sourceFiles(dir: string): string[] {
|
|
const files: string[] = [];
|
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
const full = join(dir, entry.name);
|
|
if (entry.isDirectory()) files.push(...sourceFiles(full));
|
|
else if (/\.tsx?$/.test(entry.name)) files.push(full);
|
|
}
|
|
return files;
|
|
}
|
|
|
|
function registeredElements(): Set<string> {
|
|
const names = new Set<string>();
|
|
for (const file of sourceFiles(COMPONENTS_DIR)) {
|
|
const source = readFileSync(file, "utf-8");
|
|
for (const match of source.matchAll(CUSTOM_ELEMENT_RE)) {
|
|
names.add(match[1]);
|
|
}
|
|
}
|
|
return names;
|
|
}
|
|
|
|
describe("known element catalog", () => {
|
|
test("matches the customElement registrations under src/components", () => {
|
|
const registered = [...registeredElements()].sort();
|
|
const known = [...ELEMENT_NAMES].sort();
|
|
|
|
expect(known).toEqual(registered);
|
|
});
|
|
|
|
test.each([
|
|
["docs/reference.md"],
|
|
[join(".agents", "skills", "tttk-authoring", "reference.md")],
|
|
])("%s is up to date", (relativePath) => {
|
|
const committed = readFileSync(join(process.cwd(), relativePath), "utf-8");
|
|
|
|
expect(committed).toBe(renderReference());
|
|
});
|
|
});
|