Files
pbakaus_impeccable/scripts/lib/transformers/gemini.js
T
Paul BakausandClaude Opus 4.5 2181137d04 Consolidate skills + add patterns source file
Major changes:
- Consolidate 8 design skills into single frontend-design skill with 7 reference files
- Add source/patterns.md as single source of truth for patterns/antipatterns
- Patterns are merged into skill during build, served via API for website
- Website now dynamically renders both "What TO Do" and "What NOT to Do" sections
- Update build system to handle directory-based skills with references
- Add /api/patterns endpoint to server
- Refactor website with new Antidote section layout

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-15 14:08:30 -08:00

90 lines
3.3 KiB
JavaScript

import path from 'path';
import { cleanDir, ensureDir, writeFile } from '../utils.js';
/**
* Gemini Transformer (Full Featured - TOML + Modular Skills)
*
* Commands: Converts to TOML format with {{args}} placeholders
* Skills: Creates modular files imported via @./GEMINI.{name}.md syntax
* Reference files are inlined into the main skill file for Gemini
*/
export function transformGemini(commands, skills, distDir, patterns = null) {
const geminiDir = path.join(distDir, 'gemini');
const commandsDir = path.join(geminiDir, '.gemini/commands');
cleanDir(geminiDir);
ensureDir(commandsDir);
// Commands: Transform to TOML
for (const command of commands) {
// Replace named placeholders with {{args}}
let prompt = command.body.replace(/\{\{[^}]+\}\}/g, '{{args}}');
const toml = [
`description = "${command.description.replace(/"/g, '\\"')}"`,
`prompt = """`,
prompt,
`"""`
].join('\n');
const outputPath = path.join(commandsDir, `${command.name}.toml`);
writeFile(outputPath, toml);
}
// Skills: Create modular files (with references inlined)
let refCount = 0;
for (const skill of skills) {
let content = skill.body;
// Merge patterns body into frontend-design skill (before Domain Reference Files section)
if (skill.name === 'frontend-design' && patterns && patterns.body) {
const insertPoint = content.indexOf('---\n\n## Domain Reference Files');
if (insertPoint > -1) {
content = content.slice(0, insertPoint) + '\n\n' + patterns.body + '\n\n' + content.slice(insertPoint);
} else {
content += '\n\n' + patterns.body;
}
}
// Inline reference files if they exist
if (skill.references && skill.references.length > 0) {
const refSections = skill.references.map(ref => {
refCount++;
return `\n\n---\n\n## Reference: ${ref.name}\n\n${ref.content}`;
});
content += refSections.join('');
}
const outputPath = path.join(geminiDir, `GEMINI.${skill.name}.md`);
writeFile(outputPath, content);
}
// Create main GEMINI.md that imports skill files
const geminiMd = [
'# Gemini Context',
'',
'This repository contains specialized skills for different tasks. When you detect a user request in a particular domain, the corresponding skill file will be automatically loaded to provide detailed guidance.',
'',
'## Available Skills',
'',
'Each skill provides deep expertise in its domain. The skills below are automatically imported and will guide your responses:',
'',
...skills.map(skill =>
`### ${skill.name}\n\n**When to use**: ${skill.description}\n\n@./GEMINI.${skill.name}.md\n`
),
'',
'## How Skills Work',
'',
'1. Skills are automatically loaded via the import statements above',
'2. When a user request matches a skill domain, apply that skill\'s guidance',
'3. Multiple skills can be combined when the task requires expertise from different domains',
'4. Follow the detailed instructions provided in each imported skill file'
].join('\n');
writeFile(path.join(geminiDir, 'GEMINI.md'), geminiMd);
const refInfo = refCount > 0 ? ` (${refCount} refs inlined)` : '';
console.log(`✓ Gemini: ${commands.length} commands (TOML), ${skills.length} skills (modular)${refInfo}`);
}