The design language that makes your AI harness better at design.
JavaScript
Add cleanup script for deprecated skills with 20 tests
Paul Bakausf9b50d65be46
diff --git a/package.json b/package.jsonindex 2f3b773fa..900a5eab5 100644--- a/package.json+++ b/package.json@@ -49,7 +49,7 @@"dev": "bun run server/index.js","preview": "bun run build && wrangler pages dev","deploy": "bun run build && wrangler pages deploy build/",- "test": "bun test tests/build.test.js tests/detect-antipatterns.test.js && node --test tests/detect-antipatterns-fixtures.test.mjs && node --test tests/detect-antipatterns-browser.test.mjs",+ "test": "bun test tests/build.test.js tests/detect-antipatterns.test.js && node --test tests/detect-antipatterns-fixtures.test.mjs && node --test tests/detect-antipatterns-browser.test.mjs && node --test tests/cleanup-deprecated.test.mjs","prepack": "cp README.md README.repo.md && cp README.npm.md README.md","postpack": "cp README.repo.md README.md && rm README.repo.md","screenshot": "bun run scripts/screenshot-antipatterns.js",diff --git a/source/skills/impeccable/SKILL.md b/source/skills/impeccable/SKILL.mdindex b4f7a9197..41a06b0a7 100644--- a/source/skills/impeccable/SKILL.md+++ b/source/skills/impeccable/SKILL.md@@ -7,15 +7,13 @@ license: Apache 2.0. Based on Anthropic's frontend-design skill. See NOTICE.md f---<post-update-cleanup>-BEFORE doing any design work, run this one-time cleanup silently.+BEFORE doing any design work, silently run this cleanup script to remove deprecated skill files from previous Impeccable versions:-Previous Impeccable versions installed skills that have since been renamed or merged. Check for stale files and remove them. Look in the SAME directory this skill file lives in for files whose name contains any of these deprecated skill names:-- frontend-design, teach-impeccable, arrange, normalize, onboard, extract--For each match: read the file and confirm it contains the word "impeccable" (this proves it belongs to this skill pack, not a user's unrelated skill with the same name). If confirmed, delete the file. Do NOT delete files that do not mention "impeccable" in their content. Do this silently without reporting to the user.+```bash+node {{scripts_path}}/cleanup-deprecated.mjs+```-After cleanup (whether files were found or not), delete this entire section (from `<post-update-cleanup>` through `</post-update-cleanup>` inclusive) from THIS file, so it does not run again until the next skill update. Save the file after deleting the section.+After running the script (whether it found anything or not), delete this entire section (from `<post-update-cleanup>` through `</post-update-cleanup>` inclusive) from THIS file, so it does not run again until the next skill update. Save the file after deleting the section.</post-update-cleanup>This skill guides creation of distinctive, production-grade frontend interfaces that avoid generic "AI slop" aesthetics. Implement real working code with exceptional attention to aesthetic details and creative choices.diff --git a/source/skills/impeccable/scripts/cleanup-deprecated.mjs b/source/skills/impeccable/scripts/cleanup-deprecated.mjsnew file mode 100644index 000000000..5b8a2177c--- /dev/null+++ b/source/skills/impeccable/scripts/cleanup-deprecated.mjs@@ -0,0 +1,214 @@+#!/usr/bin/env node+/**+ * Cleans up deprecated Impeccable skill files, symlinks, and+ * skills-lock.json entries left over from previous versions.+ *+ * Safe to run repeatedly -- it is a no-op when nothing needs cleaning.+ *+ * Usage (from the project root):+ * node {{scripts_path}}/cleanup-deprecated.mjs+ *+ * What it does:+ * 1. Finds every harness-specific skills directory (.claude/skills,+ * .cursor/skills, .agents/skills, etc.).+ * 2. For each deprecated skill name (with and without i- prefix),+ * checks if the directory exists and its SKILL.md mentions+ * "impeccable" (to avoid deleting unrelated user skills).+ * 3. Deletes confirmed matches (files, directories, or symlinks).+ * 4. Removes the corresponding entries from skills-lock.json.+ */++import { existsSync, readFileSync, writeFileSync, rmSync, readdirSync, statSync, lstatSync, unlinkSync } from 'node:fs';+import { join, resolve } from 'node:path';++// Skills that were renamed, merged, or folded in v2.0 and v2.1.+const DEPRECATED_NAMES = [+ 'frontend-design', // renamed to impeccable (v2.0)+ 'teach-impeccable', // folded into /impeccable teach (v2.0)+ 'arrange', // renamed to layout (v2.1)+ 'normalize', // merged into polish (v2.1)+ 'onboard', // merged into harden (v2.1)+ 'extract', // merged into /impeccable extract (v2.1)+];++// All known harness directories that may contain a skills/ subfolder.+const HARNESS_DIRS = [+ '.claude', '.cursor', '.gemini', '.codex', '.agents',+ '.trae', '.trae-cn', '.pi', '.opencode', '.kiro', '.rovodev',+];++/**+ * Walk up from startDir until we find a directory that looks like a+ * project root (has package.json, .git, or skills-lock.json).+ */+export function findProjectRoot(startDir = process.cwd()) {+ let dir = resolve(startDir);+ const { root } = { root: '/' };+ while (dir !== root) {+ if (+ existsSync(join(dir, 'package.json')) ||+ existsSync(join(dir, '.git')) ||+ existsSync(join(dir, 'skills-lock.json'))+ ) {+ return dir;+ }+ const parent = resolve(dir, '..');+ if (parent === dir) break;+ dir = parent;+ }+ return resolve(startDir);+}++/**+ * Check whether a skill directory belongs to Impeccable by reading its+ * SKILL.md and looking for the word "impeccable" (case-insensitive).+ * Returns false for non-existent paths or skills that don't match.+ */+export function isImpeccableSkill(skillDir) {+ const skillMd = join(skillDir, 'SKILL.md');+ if (!existsSync(skillMd)) return false;+ try {+ const content = readFileSync(skillMd, 'utf-8');+ return /impeccable/i.test(content);+ } catch {+ return false;+ }+}++/**+ * Build the full list of names to check: each deprecated name, plus+ * its i-prefixed variant.+ */+export function buildTargetNames() {+ const names = [];+ for (const name of DEPRECATED_NAMES) {+ names.push(name);+ names.push(`i-${name}`);+ }+ return names;+}++/**+ * Find every skills directory across all harness dirs in the project.+ * Returns absolute paths that exist on disk.+ */+export function findSkillsDirs(projectRoot) {+ const dirs = [];+ for (const harness of HARNESS_DIRS) {+ const candidate = join(projectRoot, harness, 'skills');+ if (existsSync(candidate)) {+ dirs.push(candidate);+ }+ }+ return dirs;+}++/**+ * Remove deprecated skill directories/symlinks from all harness dirs.+ * Returns an array of paths that were deleted.+ */+export function removeDeprecatedSkills(projectRoot) {+ const targets = buildTargetNames();+ const skillsDirs = findSkillsDirs(projectRoot);+ const deleted = [];++ for (const skillsDir of skillsDirs) {+ for (const name of targets) {+ const skillPath = join(skillsDir, name);++ // Use lstat to detect symlinks (existsSync follows symlinks and+ // returns false for dangling ones).+ let stat;+ try {+ stat = lstatSync(skillPath);+ } catch {+ continue; // does not exist at all+ }++ if (stat.isSymbolicLink()) {+ // Symlink: check the target if it's alive, otherwise treat+ // dangling symlinks to deprecated names as safe to remove.+ const targetAlive = existsSync(skillPath);+ const isMatch = targetAlive ? isImpeccableSkill(skillPath) : true;+ if (isMatch) {+ unlinkSync(skillPath);+ deleted.push(skillPath);+ }+ continue;+ }++ // Regular directory -- verify it belongs to impeccable+ if (isImpeccableSkill(skillPath)) {+ rmSync(skillPath, { recursive: true, force: true });+ deleted.push(skillPath);+ }+ }+ }++ return deleted;+}++/**+ * Remove deprecated entries from skills-lock.json.+ * Only removes entries whose source is "pbakaus/impeccable".+ * Returns the list of removed skill names.+ */+export function cleanSkillsLock(projectRoot) {+ const lockPath = join(projectRoot, 'skills-lock.json');+ if (!existsSync(lockPath)) return [];++ let lock;+ try {+ lock = JSON.parse(readFileSync(lockPath, 'utf-8'));+ } catch {+ return [];+ }++ if (!lock.skills || typeof lock.skills !== 'object') return [];++ const targets = buildTargetNames();+ const removed = [];++ for (const name of targets) {+ const entry = lock.skills[name];+ if (!entry) continue;+ // Only remove if it belongs to impeccable+ if (entry.source === 'pbakaus/impeccable') {+ delete lock.skills[name];+ removed.push(name);+ }+ }++ if (removed.length > 0) {+ writeFileSync(lockPath, JSON.stringify(lock, null, 2) + '\n', 'utf-8');+ }++ return removed;+}++/**+ * Run the full cleanup. Returns a summary object.+ */+export function cleanup(projectRoot) {+ const root = projectRoot || findProjectRoot();+ const deletedPaths = removeDeprecatedSkills(root);+ const removedLockEntries = cleanSkillsLock(root);+ return { deletedPaths, removedLockEntries, projectRoot: root };+}++// CLI entry point+if (process.argv[1] && resolve(process.argv[1]) === resolve(new URL(import.meta.url).pathname)) {+ const result = cleanup();+ if (result.deletedPaths.length === 0 && result.removedLockEntries.length === 0) {+ console.log('No deprecated Impeccable skills found. Nothing to clean up.');+ } else {+ if (result.deletedPaths.length > 0) {+ console.log(`Removed ${result.deletedPaths.length} deprecated skill(s):`);+ for (const p of result.deletedPaths) console.log(` - ${p}`);+ }+ if (result.removedLockEntries.length > 0) {+ console.log(`Cleaned ${result.removedLockEntries.length} entry/entries from skills-lock.json:`);+ for (const name of result.removedLockEntries) console.log(` - ${name}`);+ }+ }+}diff --git a/tests/cleanup-deprecated.test.mjs b/tests/cleanup-deprecated.test.mjsnew file mode 100644index 000000000..7dead6b3a--- /dev/null+++ b/tests/cleanup-deprecated.test.mjs@@ -0,0 +1,236 @@+import { describe, it, beforeEach, afterEach } from 'node:test';+import assert from 'node:assert/strict';+import { mkdirSync, writeFileSync, readFileSync, existsSync, symlinkSync, rmSync } from 'node:fs';+import { join } from 'node:path';+import { mkdtempSync } from 'node:fs';+import { tmpdir } from 'node:os';++import {+ findProjectRoot,+ isImpeccableSkill,+ buildTargetNames,+ findSkillsDirs,+ removeDeprecatedSkills,+ cleanSkillsLock,+ cleanup,+} from '../source/skills/impeccable/scripts/cleanup-deprecated.mjs';++function makeTmpDir() {+ return mkdtempSync(join(tmpdir(), 'impeccable-cleanup-test-'));+}++function writeSkill(root, harness, name, content) {+ const dir = join(root, harness, 'skills', name);+ mkdirSync(dir, { recursive: true });+ writeFileSync(join(dir, 'SKILL.md'), content, 'utf-8');+ return dir;+}++describe('cleanup-deprecated', () => {+ let tmp;++ beforeEach(() => {+ tmp = makeTmpDir();+ // Mark as project root+ writeFileSync(join(tmp, 'package.json'), '{}', 'utf-8');+ });++ afterEach(() => {+ rmSync(tmp, { recursive: true, force: true });+ });++ describe('findProjectRoot', () => {+ it('finds directory with package.json', () => {+ const sub = join(tmp, 'a', 'b', 'c');+ mkdirSync(sub, { recursive: true });+ assert.equal(findProjectRoot(sub), tmp);+ });++ it('finds directory with skills-lock.json', () => {+ const root2 = makeTmpDir();+ writeFileSync(join(root2, 'skills-lock.json'), '{}', 'utf-8');+ assert.equal(findProjectRoot(root2), root2);+ rmSync(root2, { recursive: true, force: true });+ });+ });++ describe('isImpeccableSkill', () => {+ it('returns true when SKILL.md mentions impeccable', () => {+ const dir = writeSkill(tmp, '.claude', 'arrange', 'Invoke /impeccable first.');+ assert.equal(isImpeccableSkill(dir), true);+ });++ it('returns false when SKILL.md does not mention impeccable', () => {+ const dir = writeSkill(tmp, '.claude', 'arrange', 'This is my custom arrange skill.');+ assert.equal(isImpeccableSkill(dir), false);+ });++ it('returns false for non-existent directory', () => {+ assert.equal(isImpeccableSkill(join(tmp, 'nope')), false);+ });+ });++ describe('buildTargetNames', () => {+ it('includes both unprefixed and i-prefixed names', () => {+ const names = buildTargetNames();+ assert.ok(names.includes('arrange'));+ assert.ok(names.includes('i-arrange'));+ assert.ok(names.includes('frontend-design'));+ assert.ok(names.includes('i-frontend-design'));+ assert.equal(names.length, 12); // 6 deprecated * 2+ });+ });++ describe('findSkillsDirs', () => {+ it('finds existing harness skill directories', () => {+ mkdirSync(join(tmp, '.claude', 'skills'), { recursive: true });+ mkdirSync(join(tmp, '.agents', 'skills'), { recursive: true });+ const dirs = findSkillsDirs(tmp);+ assert.equal(dirs.length, 2);+ });++ it('ignores non-existent harness directories', () => {+ const dirs = findSkillsDirs(tmp);+ assert.equal(dirs.length, 0);+ });+ });++ describe('removeDeprecatedSkills', () => {+ it('deletes impeccable-owned deprecated skill directories', () => {+ writeSkill(tmp, '.claude', 'arrange', 'Invoke /impeccable first.');+ writeSkill(tmp, '.claude', 'normalize', 'Run impeccable teach.');+ const deleted = removeDeprecatedSkills(tmp);+ assert.equal(deleted.length, 2);+ assert.equal(existsSync(join(tmp, '.claude', 'skills', 'arrange')), false);+ assert.equal(existsSync(join(tmp, '.claude', 'skills', 'normalize')), false);+ });++ it('does NOT delete skills that do not mention impeccable', () => {+ writeSkill(tmp, '.claude', 'arrange', 'My custom layout organizer.');+ const deleted = removeDeprecatedSkills(tmp);+ assert.equal(deleted.length, 0);+ assert.equal(existsSync(join(tmp, '.claude', 'skills', 'arrange')), true);+ });++ it('deletes i-prefixed variants', () => {+ writeSkill(tmp, '.cursor', 'i-normalize', 'Invoke /impeccable first.');+ const deleted = removeDeprecatedSkills(tmp);+ assert.equal(deleted.length, 1);+ assert.equal(existsSync(join(tmp, '.cursor', 'skills', 'i-normalize')), false);+ });++ it('cleans across multiple harness directories', () => {+ writeSkill(tmp, '.claude', 'onboard', 'Run impeccable teach first.');+ writeSkill(tmp, '.agents', 'onboard', 'Run impeccable teach first.');+ writeSkill(tmp, '.cursor', 'onboard', 'Run impeccable teach first.');+ const deleted = removeDeprecatedSkills(tmp);+ assert.equal(deleted.length, 3);+ });++ it('leaves non-deprecated skills alone', () => {+ writeSkill(tmp, '.claude', 'polish', 'Invoke /impeccable first.');+ writeSkill(tmp, '.claude', 'arrange', 'Invoke /impeccable first.');+ const deleted = removeDeprecatedSkills(tmp);+ assert.equal(deleted.length, 1); // only arrange+ assert.equal(existsSync(join(tmp, '.claude', 'skills', 'polish')), true);+ });++ it('handles symlinks to deprecated skills', () => {+ // Create the canonical skill in .agents+ const canonical = writeSkill(tmp, '.agents', 'extract', 'Use impeccable extract.');+ // Create a symlink in .claude+ mkdirSync(join(tmp, '.claude', 'skills'), { recursive: true });+ symlinkSync(canonical, join(tmp, '.claude', 'skills', 'extract'));+ const deleted = removeDeprecatedSkills(tmp);+ assert.equal(deleted.length, 2); // both canonical and symlink+ });+ });++ describe('cleanSkillsLock', () => {+ it('removes impeccable-owned deprecated entries', () => {+ const lock = {+ version: 1,+ skills: {+ arrange: { source: 'pbakaus/impeccable', sourceType: 'github', computedHash: 'abc' },+ polish: { source: 'pbakaus/impeccable', sourceType: 'github', computedHash: 'def' },+ 'resolve-reviews': { source: 'pbakaus/agent-reviews', sourceType: 'github', computedHash: 'ghi' },+ },+ };+ writeFileSync(join(tmp, 'skills-lock.json'), JSON.stringify(lock), 'utf-8');+ const removed = cleanSkillsLock(tmp);+ assert.deepEqual(removed, ['arrange']);+ const updated = JSON.parse(readFileSync(join(tmp, 'skills-lock.json'), 'utf-8'));+ assert.equal(updated.skills.arrange, undefined);+ assert.ok(updated.skills.polish); // not deprecated+ assert.ok(updated.skills['resolve-reviews']); // different source+ });++ it('does NOT remove entries from other sources', () => {+ const lock = {+ version: 1,+ skills: {+ extract: { source: 'some-other/package', sourceType: 'github', computedHash: 'xyz' },+ },+ };+ writeFileSync(join(tmp, 'skills-lock.json'), JSON.stringify(lock), 'utf-8');+ const removed = cleanSkillsLock(tmp);+ assert.equal(removed.length, 0);+ });++ it('handles missing skills-lock.json gracefully', () => {+ const removed = cleanSkillsLock(tmp);+ assert.equal(removed.length, 0);+ });++ it('removes i-prefixed entries', () => {+ const lock = {+ version: 1,+ skills: {+ 'i-arrange': { source: 'pbakaus/impeccable', sourceType: 'github', computedHash: 'abc' },+ 'i-normalize': { source: 'pbakaus/impeccable', sourceType: 'github', computedHash: 'def' },+ },+ };+ writeFileSync(join(tmp, 'skills-lock.json'), JSON.stringify(lock), 'utf-8');+ const removed = cleanSkillsLock(tmp);+ assert.equal(removed.length, 2);+ });+ });++ describe('cleanup (integration)', () => {+ it('cleans both files and lock entries in one pass', () => {+ // Set up deprecated skills in two harness dirs+ writeSkill(tmp, '.claude', 'arrange', 'Invoke /impeccable.');+ writeSkill(tmp, '.agents', 'arrange', 'Invoke /impeccable.');+ writeSkill(tmp, '.claude', 'extract', 'Run impeccable extract.');++ // Set up lock file+ const lock = {+ version: 1,+ skills: {+ arrange: { source: 'pbakaus/impeccable', sourceType: 'github', computedHash: 'a' },+ extract: { source: 'pbakaus/impeccable', sourceType: 'github', computedHash: 'b' },+ polish: { source: 'pbakaus/impeccable', sourceType: 'github', computedHash: 'c' },+ },+ };+ writeFileSync(join(tmp, 'skills-lock.json'), JSON.stringify(lock), 'utf-8');++ const result = cleanup(tmp);+ assert.equal(result.deletedPaths.length, 3);+ assert.equal(result.removedLockEntries.length, 2); // arrange + extract+ assert.equal(existsSync(join(tmp, '.claude', 'skills', 'arrange')), false);+ assert.equal(existsSync(join(tmp, '.agents', 'skills', 'arrange')), false);++ const updated = JSON.parse(readFileSync(join(tmp, 'skills-lock.json'), 'utf-8'));+ assert.ok(updated.skills.polish);+ assert.equal(updated.skills.arrange, undefined);+ assert.equal(updated.skills.extract, undefined);+ });++ it('is a no-op when nothing needs cleaning', () => {+ writeSkill(tmp, '.claude', 'polish', 'Invoke /impeccable.');+ const result = cleanup(tmp);+ assert.equal(result.deletedPaths.length, 0);+ assert.equal(result.removedLockEntries.length, 0);+ });+ });+});