import { existsSync } from 'node:fs'; import { join } from 'node:path'; import { homedir } from 'node:os'; import type { AgentAdapter } from './base.js'; import { createSkillXml } from './base.js'; import type { Skill, AgentType } from '@skillkit/core'; export class GitHubCopilotAdapter implements AgentAdapter { readonly type: AgentType = 'github-copilot'; readonly name = 'GitHub Copilot'; readonly skillsDir = '.github/skills'; readonly configFile = 'AGENTS.md'; generateConfig(skills: Skill[]): string { const enabledSkills = skills.filter(s => s.enabled); if (enabledSkills.length === 0) { return ''; } const skillsXml = enabledSkills.map(createSkillXml).join('\n\n'); return ` ## Available Skills When users ask you to perform tasks, check if any of the available skills below can help complete the task more effectively. Skills provide specialized capabilities and domain knowledge. How to use skills: - Invoke: \`skillkit read \` or \`npx skillkit read \` - The skill content will load with detailed instructions on how to complete the task - Base directory provided in output for resolving bundled resources (references/, scripts/, assets/) Usage notes: - Only use skills listed in below - Do not invoke a skill that is already loaded in your context - Each skill invocation is stateless ${skillsXml} `; } parseConfig(content: string): string[] { const skillNames: string[] = []; const skillRegex = /([^<]+)<\/name>/g; let match; while ((match = skillRegex.exec(content)) !== null) { skillNames.push(match[1].trim()); } return skillNames; } getInvokeCommand(skillName: string): string { return `skillkit read ${skillName}`; } async isDetected(): Promise { const projectGithub = join(process.cwd(), '.github', 'skills'); const globalCopilot = join(homedir(), '.copilot'); return existsSync(projectGithub) || existsSync(globalCopilot); } }