Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
One-time setup that gathers your project's design context and saves it to CLAUDE.md for future sessions.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/pin.mjs
1#!/usr/bin/env node2/**3* Pin/unpin sub-commands as standalone skill shortcuts.4*5* Usage:6* node <scripts_path>/pin.mjs pin <command>7* node <scripts_path>/pin.mjs unpin <command>8*9* `pin audit` creates a lightweight /audit skill that redirects to /impeccable audit.10* `unpin audit` removes that shortcut.11*12* The script discovers harness directories (.claude/skills, .cursor/skills, etc.)13* in the project root and creates/removes the pin in all of them.14*/1516import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync, readdirSync } from 'node:fs';17import { join, resolve, dirname } from 'node:path';18import { fileURLToPath } from 'node:url';1920const __dirname = dirname(fileURLToPath(import.meta.url));2122// All known harness directories23const HARNESS_DIRS = [24'.claude', '.cursor', '.gemini', '.codex', '.agents',25'.trae', '.trae-cn', '.pi', '.opencode', '.kiro', '.rovodev',26];2728// Valid sub-command names29const VALID_COMMANDS = [30'craft', 'teach', 'extract', 'document', 'shape',31'critique', 'audit',32'polish', 'bolder', 'quieter', 'distill', 'harden', 'onboard', 'live',33'animate', 'colorize', 'typeset', 'layout', 'delight', 'overdrive',34'clarify', 'adapt', 'optimize',35];3637// Marker to identify pinned skills (so unpin doesn't delete user skills)38const PIN_MARKER = '<!-- impeccable-pinned-skill -->';3940/**41* Walk up from startDir to find a project root.42*/43function findProjectRoot(startDir = process.cwd()) {44let dir = resolve(startDir);45while (dir !== '/') {46if (47existsSync(join(dir, 'package.json')) ||48existsSync(join(dir, '.git')) ||49existsSync(join(dir, 'skills-lock.json'))50) {51return dir;52}53const parent = resolve(dir, '..');54if (parent === dir) break;55dir = parent;56}57return resolve(startDir);58}5960/**61* Find harness skill directories that have an impeccable skill installed.62*/63function findHarnessDirs(projectRoot) {64const dirs = [];65for (const harness of HARNESS_DIRS) {66const skillsDir = join(projectRoot, harness, 'skills');67// Only pin in harness dirs that already have impeccable installed68const impeccableDir = join(skillsDir, 'impeccable');69if (existsSync(impeccableDir) || existsSync(join(skillsDir, 'i-impeccable'))) {70dirs.push(skillsDir);71}72}73return dirs;74}7576/**77* Load command metadata (descriptions for pinned skills).78*/79function loadCommandMetadata() {80const metadataPath = join(__dirname, 'command-metadata.json');81if (existsSync(metadataPath)) {82return JSON.parse(readFileSync(metadataPath, 'utf-8'));83}84return {};85}8687/**88* Generate a pinned skill's SKILL.md content.89*/90function generatePinnedSkill(command, metadata) {91const desc = metadata[command]?.description || `Shortcut for /impeccable ${command}.`;92const hint = metadata[command]?.argumentHint || '[target]';9394return `---95name: ${command}96description: "${desc}"97argument-hint: "${hint}"98user-invocable: true99---100101${PIN_MARKER}102103This is a pinned shortcut for \`{{command_prefix}}impeccable ${command}\`.104105Invoke {{command_prefix}}impeccable ${command}, passing along any arguments provided here, and follow its instructions.106`;107}108109/**110* Pin a command: create shortcut skill in all harness dirs.111*/112function pin(command, projectRoot) {113const metadata = loadCommandMetadata();114const harnessDirs = findHarnessDirs(projectRoot);115116if (harnessDirs.length === 0) {117console.log('No harness directories with impeccable installed found.');118return false;119}120121const content = generatePinnedSkill(command, metadata);122let created = 0;123124for (const skillsDir of harnessDirs) {125// Check if skill already exists (and isn't a pin)126const skillDir = join(skillsDir, command);127if (existsSync(skillDir)) {128const existingMd = join(skillDir, 'SKILL.md');129if (existsSync(existingMd)) {130const existing = readFileSync(existingMd, 'utf-8');131if (!existing.includes(PIN_MARKER)) {132console.log(` SKIP: ${skillDir} (non-pinned skill already exists)`);133continue;134}135}136}137138mkdirSync(skillDir, { recursive: true });139writeFileSync(join(skillDir, 'SKILL.md'), content, 'utf-8');140console.log(` + ${skillDir}`);141created++;142}143144if (created > 0) {145console.log(`\nPinned '${command}' as a standalone shortcut in ${created} location(s).`);146console.log(`You can now use /${command} directly.`);147}148149return created > 0;150}151152/**153* Unpin a command: remove shortcut skill from all harness dirs.154*/155function unpin(command, projectRoot) {156const harnessDirs = findHarnessDirs(projectRoot);157let removed = 0;158159for (const skillsDir of harnessDirs) {160const skillDir = join(skillsDir, command);161if (!existsSync(skillDir)) continue;162163const skillMd = join(skillDir, 'SKILL.md');164if (!existsSync(skillMd)) continue;165166// Safety: only remove if it's a pinned skill167const content = readFileSync(skillMd, 'utf-8');168if (!content.includes(PIN_MARKER)) {169console.log(` SKIP: ${skillDir} (not a pinned skill)`);170continue;171}172173rmSync(skillDir, { recursive: true, force: true });174console.log(` - ${skillDir}`);175removed++;176}177178if (removed > 0) {179console.log(`\nUnpinned '${command}' from ${removed} location(s).`);180console.log(`Use /impeccable ${command} to access it.`);181} else {182console.log(`No pinned '${command}' shortcut found.`);183}184185return removed > 0;186}187188// --- CLI ---189const [,, action, command] = process.argv;190191if (!action || !command) {192console.log('Usage: node pin.mjs <pin|unpin> <command>');193console.log(`\nAvailable commands: ${VALID_COMMANDS.join(', ')}`);194process.exit(1);195}196197if (action !== 'pin' && action !== 'unpin') {198console.error(`Unknown action: ${action}. Use 'pin' or 'unpin'.`);199process.exit(1);200}201202if (!VALID_COMMANDS.includes(command)) {203console.error(`Unknown command: ${command}`);204console.error(`Available commands: ${VALID_COMMANDS.join(', ')}`);205process.exit(1);206}207208const root = findProjectRoot();209210if (action === 'pin') {211pin(command, root);212} else {213unpin(command, root);214}215