UNPKG

oneie

Version:

šŸ¤ ONE Personal Collaborative Intelligence - Creates personalized AI workspace from your me.md profile. Simple: npx oneie → edit me.md → generate personalized agents, workflows & missions. From students to enterprises, ONE adapts to your context.

303 lines (253 loc) • 10.8 kB
#!/usr/bin/env node /** * Dynamic Agent Command Generator * Creates one:agent-name command files for all agents in .claude/agents/ */ import { promises as fs } from 'fs'; import path from 'path'; import { BackgroundAgentLoader } from './background-agent-loader.js'; /** * Agent Command Generator class */ export class AgentCommandGenerator { constructor(options = {}) { this.agentsPath = options.agentsPath || '.claude/agents'; this.commandsPath = options.commandsPath || '.claude/commands'; this.loader = new BackgroundAgentLoader({ agentsPath: this.agentsPath }); } /** * Generate command files for all agents */ async generateAllCommands() { console.log('šŸ¤– Generating command files for all agents...\n'); try { // Get list of all available agents const agents = await this.loader.listAvailableAgents(); console.log(`Found ${agents.length} agents to process`); // Filter out README and other non-agent files const validAgents = agents.filter(agent => agent !== 'README' && !agent.startsWith('.') && agent.endsWith !== '.DS_Store' ); console.log(`Processing ${validAgents.length} valid agents:\n`); let created = 0; let updated = 0; let skipped = 0; // Generate command file for each agent for (const agentName of validAgents) { try { const result = await this.generateCommandFile(agentName); if (result === 'created') { created++; console.log(`āœ… Created: one-${agentName}.md`); } else if (result === 'updated') { updated++; console.log(`šŸ”„ Updated: one-${agentName}.md`); } else { skipped++; console.log(`ā­ļø Skipped: one-${agentName}.md (already exists)`); } } catch (error) { console.log(`āŒ Error processing ${agentName}:`, error.message); } } console.log(`\nšŸ“Š Summary:`); console.log(` Created: ${created} command files`); console.log(` Updated: ${updated} command files`); console.log(` Skipped: ${skipped} command files`); console.log(` Total agents: ${validAgents.length}`); return { created, updated, skipped, total: validAgents.length }; } catch (error) { console.error('āŒ Failed to generate command files:', error.message); throw error; } } /** * Generate a single command file for an agent */ async generateCommandFile(agentName, overwrite = false) { const commandFileName = `one-${agentName}.md`; const commandFilePath = path.join(this.commandsPath, commandFileName); // Check if command file already exists const exists = await fs.access(commandFilePath).then(() => true).catch(() => false); if (exists && !overwrite) { return 'skipped'; } // Load agent to get metadata const agent = await this.loader.loadAgent(agentName); // Determine if agent is premium (marketing team) const isPremium = agentName.startsWith('marketing-') || agentName.includes('marketing') || agentName.startsWith('crypto-') || agentName.includes('viral'); // Generate command file content const commandContent = this.generateCommandContent(agentName, agent, isPremium); // Write command file await fs.writeFile(commandFilePath, commandContent, 'utf8'); return exists ? 'updated' : 'created'; } /** * Generate the content for a command file */ generateCommandContent(agentName, agent, isPremium = false) { const commandName = `one:${agentName}`; const title = agent.title || this.formatTitle(agentName); const description = agent.description || `${title} specialist agent`; // Extract first sentence of description for brief summary const briefDescription = description.split('.')[0].trim(); // Determine team category const team = this.categorizeAgent(agentName); const premiumWarning = isPremium ? ` **āš ļø PREMIUM AGENT - Requires ${team.charAt(0).toUpperCase() + team.slice(1)} Team Upgrade ($79)** ` : ''; return `# ${commandName} Launch the ${title} agent for specialized ${team} support. ${premiumWarning}This command loads the ${title} agent from \`.claude/agents/${agentName}.md\` and provides: ## ${title} Capabilities ${briefDescription} ## Agent Specialization - **Team**: ${team.charAt(0).toUpperCase() + team.slice(1)} Team - **Focus**: ${this.getAgentFocus(agentName)} - **Integration**: Works with other ${team} agents and cross-functional teams ## Usage Examples \`\`\` ${commandName} "Help me with ${this.getExampleTask(agentName)}" ${commandName} "Review and optimize ${this.getReviewTask(agentName)}" ${commandName} "Create a strategy for ${this.getStrategyTask(agentName)}" \`\`\` ## Agent Integration - **Loads from**: \`.claude/agents/${agentName}.md\` - **Team**: ${team.charAt(0).toUpperCase() + team.slice(1)} ${isPremium ? '(Premium Package - $79)' : '(Free Core Package)'} - **Can coordinate with**: Other ${team} agents and cross-functional specialists - **Available in parallel**: Runs alongside other agents${isPremium ? '\n- **Requires license validation**: Premium agent access verification' : ''} Arguments: $ARGUMENTS (${this.getArgumentDescription(agentName)})`; } /** * Format agent name into a proper title */ formatTitle(agentName) { return agentName .split('-') .map(word => word.charAt(0).toUpperCase() + word.slice(1)) .join(' '); } /** * Categorize agent by team */ categorizeAgent(agentName) { if (agentName.startsWith('engineering-')) return 'engineering'; if (agentName.startsWith('marketing-')) return 'marketing'; if (agentName.startsWith('content-')) return 'content'; if (agentName.startsWith('research-')) return 'research'; if (agentName.startsWith('crypto-')) return 'crypto'; if (agentName.startsWith('company-')) return 'company'; if (agentName.startsWith('service-')) return 'service'; if (agentName.includes('sales')) return 'sales'; return 'specialized'; } /** * Get agent focus area */ getAgentFocus(agentName) { if (agentName.includes('director')) return 'Strategic leadership and coordination'; if (agentName.includes('architect')) return 'System design and architecture'; if (agentName.includes('developer')) return 'Implementation and development'; if (agentName.includes('quality')) return 'Testing and quality assurance'; if (agentName.includes('content')) return 'Content creation and management'; if (agentName.includes('marketing')) return 'Marketing strategy and campaigns'; if (agentName.includes('research')) return 'Analysis and research'; if (agentName.includes('crypto')) return 'Cryptocurrency and blockchain'; return 'Specialized domain expertise'; } /** * Get example task for agent */ getExampleTask(agentName) { if (agentName.includes('director')) return 'strategic planning and team coordination'; if (agentName.includes('architect')) return 'system architecture design'; if (agentName.includes('developer')) return 'feature implementation'; if (agentName.includes('quality')) return 'test strategy and quality assurance'; if (agentName.includes('content')) return 'content strategy and creation'; if (agentName.includes('marketing')) return 'marketing campaign development'; if (agentName.includes('research')) return 'market research and analysis'; if (agentName.includes('crypto')) return 'cryptocurrency strategy'; return 'specialized project requirements'; } /** * Get review task example */ getReviewTask(agentName) { if (agentName.includes('director')) return 'project strategy'; if (agentName.includes('architect')) return 'system architecture'; if (agentName.includes('developer')) return 'code implementation'; if (agentName.includes('quality')) return 'test coverage'; if (agentName.includes('content')) return 'content strategy'; if (agentName.includes('marketing')) return 'marketing campaigns'; if (agentName.includes('research')) return 'research findings'; if (agentName.includes('crypto')) return 'token strategy'; return 'project deliverables'; } /** * Get strategy task example */ getStrategyTask(agentName) { if (agentName.includes('director')) return 'team leadership'; if (agentName.includes('architect')) return 'scalable architecture'; if (agentName.includes('developer')) return 'development workflow'; if (agentName.includes('quality')) return 'testing automation'; if (agentName.includes('content')) return 'content distribution'; if (agentName.includes('marketing')) return 'customer acquisition'; if (agentName.includes('research')) return 'competitive analysis'; if (agentName.includes('crypto')) return 'token economics'; return 'strategic optimization'; } /** * Get argument description */ getArgumentDescription(agentName) { const team = this.categorizeAgent(agentName); return `${team} challenges, project context, specific requirements`; } /** * Validate command files exist for all agents */ async validateCommands() { const agents = await this.loader.listAvailableAgents(); const validAgents = agents.filter(agent => agent !== 'README' && !agent.startsWith('.')); const missing = []; const existing = []; for (const agentName of validAgents) { const commandFile = path.join(this.commandsPath, `one-${agentName}.md`); const exists = await fs.access(commandFile).then(() => true).catch(() => false); if (exists) { existing.push(agentName); } else { missing.push(agentName); } } return { total: validAgents.length, existing: existing.length, missing: missing.length, missingAgents: missing }; } } // CLI usage if (import.meta.url === `file://${process.argv[1]}`) { const generator = new AgentCommandGenerator(); try { await generator.generateAllCommands(); console.log('\nšŸ” Validating command coverage...'); const validation = await generator.validateCommands(); console.log(`āœ… Command files exist for ${validation.existing}/${validation.total} agents`); if (validation.missing > 0) { console.log(`āŒ Missing command files for: ${validation.missingAgents.slice(0, 5).join(', ')}${validation.missingAgents.length > 5 ? '...' : ''}`); } } catch (error) { console.error('āŒ Generation failed:', error.message); process.exit(1); } } export default AgentCommandGenerator;