const path = require('node:path'); const { BaseIdeSetup } = require('./_base-ide'); const chalk = require('chalk'); /** * GitHub Copilot IDE setup handler for WDS * Note: GitHub Copilot doesn't support includes/references, so we must copy full agent content */ class GitHubCopilotSetup extends BaseIdeSetup { constructor() { super('github-copilot', 'GitHub Copilot', false); this.configFile = '.github/copilot-instructions.md'; } /** * Setup GitHub Copilot IDE configuration * @param {string} projectDir - Project directory * @param {string} wdsDir - WDS installation directory * @param {Object} options - Setup options */ async setup(projectDir, wdsDir, options = {}) { // Ensure .github directory exists const githubDir = path.join(projectDir, '.github'); await this.ensureDir(githubDir); // Get all WDS agents const agents = await this.getAgents(wdsDir); if (agents.length === 0) { throw new Error('No agents found in WDS installation'); } // Build content to append let content = '\n\n## WDS Agents\n\n'; content += '\n\n'; // For each agent, read the full compiled agent content let agentCount = 0; for (const agent of agents) { // Read the full agent content const agentContent = await this.readFile(agent.path); // Add section header content += `### ${agent.metadata.name} - ${agent.metadata.description}\n\n`; // Add full agent content content += agentContent + '\n\n'; content += '---\n\n'; agentCount++; } // Append to copilot-instructions.md const filePath = path.join(projectDir, this.configFile); if (await this.exists(filePath)) { // File exists, append to it const fs = require('fs-extra'); await fs.appendFile(filePath, content); } else { // File doesn't exist, create it await this.writeFile(filePath, content); } if (options.logger) { options.logger.log(chalk.dim(` - ${agentCount} agent(s) configured for GitHub Copilot`)); } return { success: true, agents: agentCount, }; } /** * Cleanup GitHub Copilot WDS configuration * @param {string} projectDir - Project directory */ async cleanup(projectDir) { const filePath = path.join(projectDir, this.configFile); if (await this.exists(filePath)) { // Read file, remove WDS Agents section const fs = require('fs-extra'); const content = await fs.readFile(filePath, 'utf8'); // Remove WDS Agents section (everything from "## WDS Agents" to the end or next ## section) const wdsAgentsRegex = /\n\n## WDS Agents\n\n[\s\S]*?(?=\n\n##\s|$)/; const cleanedContent = content.replace(wdsAgentsRegex, ''); await fs.writeFile(filePath, cleanedContent); console.log(chalk.dim(`Removed GitHub Copilot WDS configuration`)); } } /** * Detect if GitHub Copilot is configured in project * @param {string} projectDir - Project directory * @returns {boolean} */ async detect(projectDir) { return await this.exists(path.join(projectDir, '.github')); } } module.exports = { GitHubCopilotSetup };