claude-code-templates 1.14.11 → 1.14.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js CHANGED
@@ -106,6 +106,12 @@ async function createClaudeConfig(options = {}) {
106
106
  return;
107
107
  }
108
108
 
109
+ // Handle workflow installation
110
+ if (options.workflow) {
111
+ await installWorkflow(options.workflow, targetDir, options);
112
+ return;
113
+ }
114
+
109
115
  // Handle command stats analysis (both singular and plural)
110
116
  if (options.commandStats || options.commandsStats) {
111
117
  await runCommandStats(options);
@@ -345,9 +351,11 @@ async function installIndividualAgent(agentName, targetDir, options) {
345
351
  const targetFile = path.join(agentsDir, `${fileName}.md`);
346
352
  await fs.writeFile(targetFile, agentContent, 'utf8');
347
353
 
348
- console.log(chalk.green(`āœ… Agent "${agentName}" installed successfully!`));
349
- console.log(chalk.cyan(`šŸ“ Installed to: ${path.relative(targetDir, targetFile)}`));
350
- console.log(chalk.cyan(`šŸ“¦ Downloaded from: ${githubUrl}`));
354
+ if (!options.silent) {
355
+ console.log(chalk.green(`āœ… Agent "${agentName}" installed successfully!`));
356
+ console.log(chalk.cyan(`šŸ“ Installed to: ${path.relative(targetDir, targetFile)}`));
357
+ console.log(chalk.cyan(`šŸ“¦ Downloaded from: ${githubUrl}`));
358
+ }
351
359
 
352
360
  // Track successful agent installation
353
361
  trackingService.trackDownload('agent', agentName, {
@@ -406,9 +414,11 @@ async function installIndividualCommand(commandName, targetDir, options) {
406
414
 
407
415
  await fs.writeFile(targetFile, commandContent, 'utf8');
408
416
 
409
- console.log(chalk.green(`āœ… Command "${commandName}" installed successfully!`));
410
- console.log(chalk.cyan(`šŸ“ Installed to: ${path.relative(targetDir, targetFile)}`));
411
- console.log(chalk.cyan(`šŸ“¦ Downloaded from: ${githubUrl}`));
417
+ if (!options.silent) {
418
+ console.log(chalk.green(`āœ… Command "${commandName}" installed successfully!`));
419
+ console.log(chalk.cyan(`šŸ“ Installed to: ${path.relative(targetDir, targetFile)}`));
420
+ console.log(chalk.cyan(`šŸ“¦ Downloaded from: ${githubUrl}`));
421
+ }
412
422
 
413
423
  // Track successful command installation
414
424
  trackingService.trackDownload('command', commandName, {
@@ -450,6 +460,15 @@ async function installIndividualMCP(mcpName, targetDir, options) {
450
460
 
451
461
  const mcpConfigText = await response.text();
452
462
  const mcpConfig = JSON.parse(mcpConfigText);
463
+
464
+ // Remove description field from each MCP server before merging
465
+ if (mcpConfig.mcpServers) {
466
+ for (const serverName in mcpConfig.mcpServers) {
467
+ if (mcpConfig.mcpServers[serverName] && typeof mcpConfig.mcpServers[serverName] === 'object') {
468
+ delete mcpConfig.mcpServers[serverName].description;
469
+ }
470
+ }
471
+ }
453
472
 
454
473
  // Check if .mcp.json exists in target directory
455
474
  const targetMcpFile = path.join(targetDir, '.mcp.json');
@@ -477,9 +496,11 @@ async function installIndividualMCP(mcpName, targetDir, options) {
477
496
  // Write the merged configuration
478
497
  await fs.writeJson(targetMcpFile, mergedConfig, { spaces: 2 });
479
498
 
480
- console.log(chalk.green(`āœ… MCP "${mcpName}" installed successfully!`));
481
- console.log(chalk.cyan(`šŸ“ Configuration merged into: ${path.relative(targetDir, targetMcpFile)}`));
482
- console.log(chalk.cyan(`šŸ“¦ Downloaded from: ${githubUrl}`));
499
+ if (!options.silent) {
500
+ console.log(chalk.green(`āœ… MCP "${mcpName}" installed successfully!`));
501
+ console.log(chalk.cyan(`šŸ“ Configuration merged into: ${path.relative(targetDir, targetMcpFile)}`));
502
+ console.log(chalk.cyan(`šŸ“¦ Downloaded from: ${githubUrl}`));
503
+ }
483
504
 
484
505
  // Track successful MCP installation
485
506
  trackingService.trackDownload('mcp', mcpName, {
@@ -609,4 +630,321 @@ async function showAvailableAgents() {
609
630
  console.log('');
610
631
  }
611
632
 
633
+ /**
634
+ * Install workflow from hash
635
+ */
636
+ async function installWorkflow(workflowHash, targetDir, options) {
637
+ console.log(chalk.blue(`šŸ”§ Installing workflow from hash: ${workflowHash}`));
638
+
639
+ try {
640
+ // Extract hash from format #hash
641
+ const hash = workflowHash.startsWith('#') ? workflowHash.substring(1) : workflowHash;
642
+
643
+ if (!hash || hash.length < 3) {
644
+ throw new Error('Invalid workflow hash format. Expected format: #hash');
645
+ }
646
+
647
+ console.log(chalk.gray(`šŸ“„ Fetching workflow configuration...`));
648
+
649
+ // Fetch workflow configuration from a remote service
650
+ // For now, we'll simulate this by using a local storage approach
651
+ // In production, this would fetch from a workflow registry
652
+ const workflowData = await fetchWorkflowData(hash);
653
+
654
+ if (!workflowData) {
655
+ throw new Error(`Workflow with hash "${hash}" not found. Please check the hash and try again.`);
656
+ }
657
+
658
+ console.log(chalk.green(`āœ… Workflow found: ${workflowData.name}`));
659
+ console.log(chalk.cyan(`šŸ“ Description: ${workflowData.description}`));
660
+ console.log(chalk.cyan(`šŸ·ļø Tags: ${workflowData.tags.join(', ')}`));
661
+ console.log(chalk.cyan(`šŸ“Š Steps: ${workflowData.steps.length}`));
662
+
663
+ // Install all required components
664
+ const installPromises = [];
665
+
666
+ // Group components by type
667
+ const agents = workflowData.steps.filter(step => step.type === 'agent');
668
+ const commands = workflowData.steps.filter(step => step.type === 'command');
669
+ const mcps = workflowData.steps.filter(step => step.type === 'mcp');
670
+
671
+ console.log(chalk.blue(`\nšŸ“¦ Installing workflow components...`));
672
+ console.log(chalk.gray(` Agents: ${agents.length}`));
673
+ console.log(chalk.gray(` Commands: ${commands.length}`));
674
+ console.log(chalk.gray(` MCPs: ${mcps.length}`));
675
+
676
+ // Install agents
677
+ for (const agent of agents) {
678
+ console.log(chalk.gray(` Installing agent: ${agent.name}`));
679
+ await installIndividualAgent(agent.path, targetDir, { ...options, silent: true });
680
+ }
681
+
682
+ // Install commands
683
+ for (const command of commands) {
684
+ console.log(chalk.gray(` Installing command: ${command.name}`));
685
+ await installIndividualCommand(command.path, targetDir, { ...options, silent: true });
686
+ }
687
+
688
+ // Install MCPs
689
+ for (const mcp of mcps) {
690
+ console.log(chalk.gray(` Installing MCP: ${mcp.name}`));
691
+ await installIndividualMCP(mcp.path, targetDir, { ...options, silent: true });
692
+ }
693
+
694
+ // Generate and save workflow YAML
695
+ const yamlContent = generateWorkflowYAML(workflowData);
696
+ const workflowsDir = path.join(targetDir, '.claude', 'workflows');
697
+ const workflowFile = path.join(workflowsDir, `${workflowData.name.replace(/[^a-z0-9]/gi, '_').toLowerCase()}.yaml`);
698
+
699
+ // Ensure .claude/workflows directory exists
700
+ await fs.ensureDir(workflowsDir);
701
+ await fs.writeFile(workflowFile, yamlContent, 'utf8');
702
+
703
+ console.log(chalk.green(`\nāœ… Workflow "${workflowData.name}" installed successfully!`));
704
+ console.log(chalk.cyan(`šŸ“ Components installed to: .claude/`));
705
+ console.log(chalk.cyan(`šŸ“„ Workflow file: ${path.relative(targetDir, workflowFile)}`));
706
+ console.log(chalk.cyan(`šŸš€ Use the workflow file with Claude Code to execute the complete workflow`));
707
+
708
+ // Track successful workflow installation
709
+ trackingService.trackDownload('workflow', hash, {
710
+ installation_type: 'workflow',
711
+ workflow_name: workflowData.name,
712
+ components_count: workflowData.steps.length,
713
+ agents_count: agents.length,
714
+ commands_count: commands.length,
715
+ mcps_count: mcps.length,
716
+ target_directory: path.relative(process.cwd(), targetDir)
717
+ });
718
+
719
+ } catch (error) {
720
+ console.log(chalk.red(`āŒ Error installing workflow: ${error.message}`));
721
+
722
+ if (error.message.includes('not found')) {
723
+ console.log(chalk.yellow('\nšŸ’” Possible solutions:'));
724
+ console.log(chalk.gray(' • Check that the workflow hash is correct'));
725
+ console.log(chalk.gray(' • Verify the workflow was generated successfully'));
726
+ console.log(chalk.gray(' • Try generating a new workflow from the builder'));
727
+ }
728
+ }
729
+ }
730
+
731
+ /**
732
+ * Fetch workflow data from hash
733
+ * In production, this would fetch from a remote workflow registry
734
+ * For now, we'll simulate this functionality
735
+ */
736
+ async function fetchWorkflowData(hash) {
737
+ // Simulate fetching workflow data
738
+ // In production, this would make an API call to a workflow registry
739
+ // For demo purposes, we'll return a sample workflow if hash matches demo
740
+
741
+ // Demo workflow for testing
742
+ if (hash === 'demo123' || hash === 'abc123test') {
743
+ console.log(chalk.green('šŸŽÆ Demo workflow found! Using sample configuration...'));
744
+ return {
745
+ name: 'Full Stack Development Workflow',
746
+ description: 'Complete workflow for setting up a full-stack development environment with React frontend, Node.js backend, and security auditing',
747
+ tags: ['development', 'fullstack', 'react', 'security'],
748
+ version: '1.0.0',
749
+ hash: hash,
750
+ steps: [
751
+ {
752
+ type: 'agent',
753
+ name: 'frontend-developer',
754
+ path: 'development-team/frontend-developer',
755
+ category: 'development-team',
756
+ description: 'Setup React frontend development environment'
757
+ },
758
+ {
759
+ type: 'agent',
760
+ name: 'backend-architect',
761
+ path: 'development-team/backend-architect',
762
+ category: 'development-team',
763
+ description: 'Configure Node.js backend architecture'
764
+ },
765
+ {
766
+ type: 'command',
767
+ name: 'generate-tests',
768
+ path: 'testing/generate-tests',
769
+ category: 'testing',
770
+ description: 'Generate comprehensive test suite'
771
+ },
772
+ {
773
+ type: 'agent',
774
+ name: 'api-security-audit',
775
+ path: 'security/api-security-audit',
776
+ category: 'security',
777
+ description: 'Perform security audit on APIs'
778
+ },
779
+ {
780
+ type: 'mcp',
781
+ name: 'github-integration',
782
+ path: 'integration/github-integration',
783
+ category: 'integration',
784
+ description: 'Setup GitHub integration for repository management'
785
+ }
786
+ ]
787
+ };
788
+ }
789
+
790
+ // This is where we would integrate with a workflow registry API
791
+ // For now, return null to indicate workflow not found for other hashes
792
+ console.log(chalk.yellow('\nāš ļø Workflow registry not yet implemented.'));
793
+ console.log(chalk.gray('To test with demo workflow, use hash: demo123'));
794
+ console.log(chalk.gray('Example: --workflow "#demo123"'));
795
+
796
+ return null;
797
+ }
798
+
799
+ /**
800
+ * Generate workflow YAML from workflow data
801
+ */
802
+ function generateWorkflowYAML(workflowData) {
803
+ const yaml = `#═══════════════════════════════════════════════════════════════════════════════
804
+ # šŸ¤– CLAUDE CODE WORKFLOW CONFIGURATION
805
+ #═══════════════════════════════════════════════════════════════════════════════
806
+ #
807
+ # WORKFLOW: ${workflowData.name}
808
+ # DESCRIPTION: ${workflowData.description}
809
+ # GENERATED: ${new Date().toISOString()}
810
+ # HASH: ${workflowData.hash || 'generated'}
811
+ #
812
+ #═══════════════════════════════════════════════════════════════════════════════
813
+ # šŸ“‹ INSTRUCTIONS FOR CLAUDE CODE
814
+ #═══════════════════════════════════════════════════════════════════════════════
815
+ #
816
+ # This is a WORKFLOW EXECUTION FILE for Claude Code. When you encounter this file,
817
+ # you should execute it as a complete automated workflow. Here's how:
818
+ #
819
+ # šŸŽÆ EXECUTION BEHAVIOR:
820
+ # 1. READ this entire YAML file to understand the workflow structure
821
+ # 2. EXECUTE each step in the exact order listed below (sequential mode)
822
+ # 3. For AGENTS: Use the agent specified to perform the task described
823
+ # 4. For COMMANDS: Execute the Claude Code command as specified
824
+ # 5. For MCPs: Ensure the MCP server is available and use it as needed
825
+ # 6. STOP if any step fails (on_error: stop)
826
+ # 7. PROVIDE progress updates after each step completion
827
+ #
828
+ # šŸ”§ STEP EXECUTION PATTERN:
829
+ # - Announce: "Executing Step X: [step.name]"
830
+ # - Action: Perform the task using the specified component
831
+ # - Confirm: "āœ… Step X completed successfully"
832
+ # - Continue to next step
833
+ #
834
+ # šŸ’” IMPORTANT NOTES:
835
+ # - All components are already installed in .claude/ directories
836
+ # - Each step builds upon the previous ones
837
+ # - Follow the descriptions exactly as specified
838
+ # - Use confirmation_required: true for user approval before starting
839
+ # - Maintain context and outputs between steps for workflow continuity
840
+ #
841
+ #═══════════════════════════════════════════════════════════════════════════════
842
+
843
+ name: "${workflowData.name}"
844
+ description: "${workflowData.description}"
845
+ tags: [${workflowData.tags.map(tag => `"${tag}"`).join(', ')}]
846
+ version: "${workflowData.version || '1.0.0'}"
847
+
848
+ #═══════════════════════════════════════════════════════════════════════════════
849
+ # šŸš€ WORKFLOW STEPS - EXECUTE IN ORDER
850
+ #═══════════════════════════════════════════════════════════════════════════════
851
+
852
+ steps:
853
+ ${workflowData.steps.map((step, index) => ` - step: ${index + 1}
854
+ type: ${step.type}
855
+ name: "${step.name}"
856
+ path: "${step.path}"
857
+ category: "${step.category}"
858
+ description: "${step.description}"
859
+
860
+ # CLAUDE CODE INSTRUCTIONS FOR THIS STEP:
861
+ claude_instructions: |
862
+ Execute this step using the ${step.type} located at .claude/${step.type}s/${step.name}.${step.type === 'mcp' ? 'json' : 'md'}
863
+ Task: ${step.description}
864
+ ${step.type === 'agent' ? 'Use this agent to perform the specified task with full context from previous steps.' : ''}
865
+ ${step.type === 'command' ? 'Execute this command with appropriate parameters based on workflow context.' : ''}
866
+ ${step.type === 'mcp' ? 'Ensure MCP server is running and utilize its capabilities for the task.' : ''}
867
+
868
+ action_template: |
869
+ echo "šŸ”„ Executing Step ${index + 1}: ${step.name}"
870
+ echo "šŸ“ Task: ${step.description}"
871
+ echo "šŸŽÆ Using ${step.type}: ${step.path}"
872
+ # [CLAUDE CODE WILL REPLACE THIS WITH ACTUAL EXECUTION]
873
+ echo "āœ… Step ${index + 1} completed successfully"
874
+ `).join('\n')}
875
+
876
+ #═══════════════════════════════════════════════════════════════════════════════
877
+ # āš™ļø EXECUTION CONFIGURATION
878
+ #═══════════════════════════════════════════════════════════════════════════════
879
+
880
+ execution:
881
+ mode: "sequential" # Execute steps one by one, in order
882
+ on_error: "stop" # Stop workflow if any step fails
883
+ timeout: 300 # Maximum time per step (5 minutes)
884
+ continue_on_warning: true # Continue if warnings occur
885
+ save_outputs: true # Save outputs between steps for context
886
+
887
+ #═══════════════════════════════════════════════════════════════════════════════
888
+ # šŸ“¦ INSTALLED COMPONENTS REFERENCE
889
+ #═══════════════════════════════════════════════════════════════════════════════
890
+
891
+ components:
892
+ agents: [${workflowData.steps.filter(s => s.type === 'agent').map(s => `"${s.path}"`).join(', ')}]
893
+ commands: [${workflowData.steps.filter(s => s.type === 'command').map(s => `"${s.path}"`).join(', ')}]
894
+ mcps: [${workflowData.steps.filter(s => s.type === 'mcp').map(s => `"${s.path}"`).join(', ')}]
895
+
896
+ #═══════════════════════════════════════════════════════════════════════════════
897
+ # šŸ¤– CLAUDE CODE INTEGRATION SETTINGS
898
+ #═══════════════════════════════════════════════════════════════════════════════
899
+
900
+ claudecode:
901
+ workflow_mode: true # Enable workflow execution mode
902
+ auto_execute: false # Require user confirmation before starting
903
+ confirmation_required: true # Ask user before each step
904
+ show_progress: true # Display progress indicators
905
+ save_context: true # Maintain context between steps
906
+
907
+ # WORKFLOW EXECUTION INSTRUCTIONS FOR CLAUDE:
908
+ execution_instructions: |
909
+ When executing this workflow:
910
+
911
+ 1. šŸŽÆ PREPARATION PHASE:
912
+ - Confirm all components are installed in .claude/ directories
913
+ - Verify user wants to execute this workflow
914
+ - Explain what will happen in each step
915
+
916
+ 2. šŸš€ EXECUTION PHASE:
917
+ - Execute each step sequentially
918
+ - Use the exact agent/command/mcp specified for each step
919
+ - Maintain outputs and context between steps
920
+ - Provide clear progress updates
921
+
922
+ 3. āœ… COMPLETION PHASE:
923
+ - Summarize what was accomplished
924
+ - Highlight any outputs or files created
925
+ - Suggest next steps if applicable
926
+
927
+ 4. āŒ ERROR HANDLING:
928
+ - If a step fails, stop execution immediately
929
+ - Provide clear error message and suggested fixes
930
+ - Offer to retry the failed step after fixes
931
+
932
+ Remember: This workflow was designed to work as a complete automation.
933
+ Each step builds upon the previous ones. Execute with confidence!
934
+
935
+ #═══════════════════════════════════════════════════════════════════════════════
936
+ # šŸ“‹ WORKFLOW SUMMARY
937
+ #═══════════════════════════════════════════════════════════════════════════════
938
+ #
939
+ # This workflow will execute ${workflowData.steps.length} steps in sequence:
940
+ ${workflowData.steps.map((step, index) => `# ${index + 1}. ${step.description} (${step.type}: ${step.name})`).join('\n')}
941
+ #
942
+ # Total estimated time: ${Math.ceil(workflowData.steps.length * 2)} minutes
943
+ # Components required: ${workflowData.steps.filter(s => s.type === 'agent').length} agents, ${workflowData.steps.filter(s => s.type === 'command').length} commands, ${workflowData.steps.filter(s => s.type === 'mcp').length} MCPs
944
+ #═══════════════════════════════════════════════════════════════════════════════
945
+ `;
946
+
947
+ return yaml;
948
+ }
949
+
612
950
  module.exports = { createClaudeConfig, showMainMenu };