UNPKG

metacoding

Version:

Cross-agent workflow skill for modern coding agents with gated planning, testing, verification, and handoff defaults

212 lines 8.92 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.SkillManager = void 0; const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); class SkillManager { constructor() { this.sourceSkillDir = path.join(__dirname, '../../skills/metacoding-workflow'); this.claudeAgentTemplatePath = path.join(__dirname, '../../skills/vendor-templates/claude-agent.md.template'); this.vendorDefinitions = { codex: { vendor: 'codex', root: path.join('.codex', 'skills', 'metacoding-workflow'), entryFiles: ['SKILL.md', path.join('agents', 'openai.yaml')], }, 'claude-code': { vendor: 'claude-code', root: path.join('.claude', 'metacoding-workflow'), entryFiles: [path.join('..', 'agents', 'metacoding-workflow.md')], }, antigravity: { vendor: 'antigravity', root: path.join('.agents', 'skills', 'metacoding-workflow'), entryFiles: ['SKILL.md'], }, }; } async isInstalled(vendor) { const vendors = vendor ? [vendor] : await this.getInstalledVendors(); return vendors.length > 0; } async getInstalledVendors() { const installed = []; for (const vendor of Object.keys(this.vendorDefinitions)) { if (await this.hasVendorInstall(vendor)) { installed.push(vendor); } } return installed; } getInstallDirectory(vendor) { return this.vendorDefinitions[vendor].root; } getBackupTargets(vendor) { if (vendor === 'claude-code') { return [ path.join('.claude', 'agents', 'metacoding-workflow.md'), this.vendorDefinitions[vendor].root, ]; } return [this.vendorDefinitions[vendor].root]; } async installSkill(config) { const files = await this.generateInstallationFiles(config); for (const file of files) { await fs.ensureDir(path.dirname(file.path)); await fs.writeFile(file.path, file.content, 'utf8'); } return files.map((file) => file.path); } async generateInstallationFiles(config) { const root = this.getInstallDirectory(config.vendor); const supportFiles = await this.readCoreSupportFiles(root, config.vendor); const projectContext = await this.renderProjectContext(config); const files = [ ...supportFiles, { path: path.join(root, 'references/project-context.md'), content: projectContext, }, ]; if (config.vendor === 'claude-code') { files.push({ path: path.join('.claude', 'agents', 'metacoding-workflow.md'), content: await this.renderClaudeAgentFile(), }); } return files; } async getInstalledFiles(vendor) { const files = await this.listFilesRecursively(this.getInstallDirectory(vendor)); if (vendor === 'claude-code') { const agentPath = path.join('.claude', 'agents', 'metacoding-workflow.md'); if (await fs.pathExists(agentPath)) { files.push(agentPath); } } return files.sort(); } async hasVendorInstall(vendor) { const definition = this.vendorDefinitions[vendor]; for (const relativeEntry of definition.entryFiles) { const fullPath = path.join(definition.root, relativeEntry); if (!(await fs.pathExists(fullPath))) { return false; } } return true; } async readCoreSupportFiles(installRoot, vendor) { const relativePaths = await this.listFilesRecursively(this.sourceSkillDir); const files = []; for (const absolutePath of relativePaths) { const relativePath = path.relative(this.sourceSkillDir, absolutePath); if (vendor !== 'codex' && relativePath.startsWith('agents/')) { continue; } const content = await fs.readFile(absolutePath, 'utf8'); files.push({ path: path.join(installRoot, relativePath), content, }); } return files; } async renderClaudeAgentFile() { return fs.readFile(this.claudeAgentTemplatePath, 'utf8'); } async listFilesRecursively(root) { if (!(await fs.pathExists(root))) { return []; } const entries = await fs.readdir(root, { withFileTypes: true }); const files = []; for (const entry of entries) { const fullPath = path.join(root, entry.name); if (entry.isDirectory()) { files.push(...(await this.listFilesRecursively(fullPath))); } else { files.push(fullPath); } } return files.sort(); } async renderProjectContext(config) { const templatePath = path.join(this.sourceSkillDir, 'assets/templates/project-context.md'); const template = await fs.readFile(templatePath, 'utf8'); const recommendedReferences = this.getRecommendedReferences(config); const variables = { PROJECT_NAME: config.name, PROJECT_DESCRIPTION: config.description, PROJECT_TYPE: config.projectType, TECH_STACK: config.techStack.join(', '), TEST_FRAMEWORK: config.testFramework || 'Use the repo default', BUILD_TOOL: config.buildTool || 'Use the repo default', RECOMMENDED_REFERENCES: recommendedReferences.join('\n'), AGENT_VENDOR: config.vendor, }; return Object.entries(variables).reduce((content, [key, value]) => { return content.replace(new RegExp(`{{${key}}}`, 'g'), value); }, template); } getRecommendedReferences(config) { const references = [ '- `references/workflow-rules.md` for the gated task flow', '- `references/repository-organization.md` for repository structure and MECE documentation ownership', '- `references/platform-adaptation.md` for fallback behavior when repo artifacts or git are missing', ]; if (config.projectType === 'typescript') { references.push('- `references/typescript.md` for shared TypeScript coding, testing, and documentation guidance'); } else if (config.projectType === 'react') { references.push('- `references/typescript.md` for shared TypeScript guidance', '- `references/react.md` for component, testing, and UI workflow guidance'); } else if (config.projectType === 'node') { references.push('- `references/typescript.md` for shared TypeScript guidance', '- `references/node.md` for service, API, and backend workflow guidance'); } else if (config.projectType === 'javascript') { references.push('- `references/javascript.md` for JavaScript coding, testing, and documentation guidance'); } else if (config.projectType === 'python') { references.push('- `references/python.md` for Python coding, testing, and documentation guidance'); } return references; } } exports.SkillManager = SkillManager; //# sourceMappingURL=skill-manager.js.map