Files
pbakaus_impeccable/scripts/lib/transformers/cursor.js
T
Paul BakausandClaude Opus 4.5 3083f8addc Add prefixed command option to avoid conflicts
Users can now toggle "Prefix commands with /i-" in the download section
to get bundles with all commands prefixed (e.g., /i-audit instead of /audit).
This helps avoid conflicts with existing custom commands.

Build system changes:
- Transformers now accept optional prefix/outputSuffix parameters
- Build generates both unprefixed and i-prefixed variants
- ZIP bundles created for both variants

UI changes:
- Add toggle switch to download section
- Toggle controls which bundle variant gets downloaded
- Styled to match existing design language

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 20:06:36 -08:00

112 lines
3.9 KiB
JavaScript

import path from 'path';
import { cleanDir, ensureDir, writeFile, generateYamlFrontmatter, replacePlaceholders } from '../utils.js';
/**
* Generate markdown from structured patterns/antipatterns data
*/
function generatePatternsMarkdown(patterns) {
if (!patterns || (!patterns.patterns?.length && !patterns.antipatterns?.length)) {
return '';
}
let md = `## Design Patterns Reference
This reference defines what TO do and what NOT to do when creating frontend interfaces. These patterns fight against model bias—the tendency of LLMs to converge on the same predictable choices.
### What TO Do (Patterns)
Focus on intentional, distinctive design choices:
`;
for (const category of patterns.patterns || []) {
md += `\n**${category.name}**:\n`;
for (const item of category.items || []) {
md += `- ${item}\n`;
}
}
md += `
### What NOT to Do (Anti-Patterns)
These patterns create generic "AI slop" aesthetics:
`;
for (const category of patterns.antipatterns || []) {
md += `\n**${category.name}**:\n`;
for (const item of category.items || []) {
md += `- ${item}\n`;
}
}
md += `
These anti-patterns are baked into training data from countless generic templates. Without explicit guidance, AI reproduces them. This skill ensures your AI knows both what to do AND what to avoid.
`;
return md;
}
/**
* Cursor Transformer (Agent Skills Standard)
*
* Commands: Body only in .cursor/commands/ (Cursor doesn't support command frontmatter)
* Skills: Agent Skills standard with SKILL.md in .cursor/skills/{name}/
* Reference files are copied to skill subdirectories
*
* Note: Agent Skills in Cursor require nightly channel and are agent-decided rules.
*
* @param {Object} options - Optional settings
* @param {string} options.prefix - Prefix to add to command names (e.g., 'i-')
* @param {string} options.outputSuffix - Suffix for output directory (e.g., '-prefixed')
*/
export function transformCursor(commands, skills, distDir, patterns = null, options = {}) {
const { prefix = '', outputSuffix = '' } = options;
const cursorDir = path.join(distDir, `cursor${outputSuffix}`);
const commandsDir = path.join(cursorDir, '.cursor/commands');
const skillsDir = path.join(cursorDir, '.cursor/skills');
cleanDir(cursorDir);
ensureDir(commandsDir);
ensureDir(skillsDir);
// Commands: Body only (Cursor doesn't support command frontmatter/args)
for (const command of commands) {
const commandName = `${prefix}${command.name}`;
const commandBody = replacePlaceholders(command.body, 'cursor');
const outputPath = path.join(commandsDir, `${commandName}.md`);
writeFile(outputPath, commandBody);
}
// Skills: Agent Skills standard with SKILL.md in subdirectories
let refCount = 0;
for (const skill of skills) {
const skillDir = path.join(skillsDir, skill.name);
const frontmatter = generateYamlFrontmatter({
name: skill.name,
description: skill.description,
...(skill.license && { license: skill.license })
});
const skillBody = replacePlaceholders(skill.body, 'cursor');
const content = `${frontmatter}\n\n${skillBody}`;
const outputPath = path.join(skillDir, 'SKILL.md');
writeFile(outputPath, content);
// Copy reference files if they exist
if (skill.references && skill.references.length > 0) {
const refDir = path.join(skillDir, 'reference');
ensureDir(refDir);
for (const ref of skill.references) {
const refOutputPath = path.join(refDir, `${ref.name}.md`);
const refContent = replacePlaceholders(ref.content, 'cursor');
writeFile(refOutputPath, refContent);
refCount++;
}
}
}
const refInfo = refCount > 0 ? ` (${refCount} reference files)` : '';
const prefixInfo = prefix ? ` [${prefix}prefixed]` : '';
console.log(`✓ Cursor${prefixInfo}: ${commands.length} commands, ${skills.length} skills${refInfo}`);
}