| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import {
- copyFileSync,
- existsSync,
- mkdirSync,
- readdirSync,
- statSync,
- } from 'node:fs';
- import { join, dirname } from 'node:path';
- import { homedir } from 'node:os';
- /**
- * A custom skill bundled in this repository.
- * Unlike npx-installed skills, these are copied from src/skills/ to ~/.config/opencode/skills/
- */
- export interface CustomSkill {
- /** Skill name (folder name) */
- name: string;
- /** Human-readable description */
- description: string;
- /** List of agents that should auto-allow this skill */
- allowedAgents: string[];
- /** Source path in this repo (relative to project root) */
- sourcePath: string;
- }
- /**
- * Registry of custom skills bundled in this repository.
- */
- export const CUSTOM_SKILLS: CustomSkill[] = [
- {
- name: 'cartography',
- description: 'Repository understanding and hierarchical codemap generation',
- allowedAgents: ['orchestrator'],
- sourcePath: 'src/skills/cartography',
- },
- ];
- /**
- * Get the target directory for custom skills installation.
- */
- export function getCustomSkillsDir(): string {
- return join(homedir(), '.config', 'opencode', 'skills');
- }
- /**
- * Recursively copy a directory.
- */
- function copyDirRecursive(src: string, dest: string): void {
- if (!existsSync(dest)) {
- mkdirSync(dest, { recursive: true });
- }
- const entries = readdirSync(src);
- for (const entry of entries) {
- const srcPath = join(src, entry);
- const destPath = join(dest, entry);
- const stat = statSync(srcPath);
- if (stat.isDirectory()) {
- copyDirRecursive(srcPath, destPath);
- } else {
- const destDir = dirname(destPath);
- if (!existsSync(destDir)) {
- mkdirSync(destDir, { recursive: true });
- }
- copyFileSync(srcPath, destPath);
- }
- }
- }
- /**
- * Install a custom skill by copying from src/skills/ to ~/.config/opencode/skills/
- * @param skill - The custom skill to install
- * @param projectRoot - Root directory of oh-my-opencode-slim project
- * @returns True if installation succeeded, false otherwise
- */
- export function installCustomSkill(
- skill: CustomSkill,
- projectRoot: string,
- ): boolean {
- try {
- const sourcePath = join(projectRoot, skill.sourcePath);
- const targetPath = join(getCustomSkillsDir(), skill.name);
- // Validate source exists
- if (!existsSync(sourcePath)) {
- console.error(`Custom skill source not found: ${sourcePath}`);
- return false;
- }
- // Copy skill directory
- copyDirRecursive(sourcePath, targetPath);
- return true;
- } catch (error) {
- console.error(`Failed to install custom skill: ${skill.name}`, error);
- return false;
- }
- }
|