mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-05 01:50:27 +08:00
- Added main JavaScript functionality for CLAUDE.md management including file loading, rendering, and editing capabilities. - Created a test HTML file to validate the functionality of the CLAUDE.md manager. - Introduced CLI generation examples and documentation for rules creation via CLI. - Enhanced error handling and notifications for file operations.
6.5 KiB
6.5 KiB
Implementation Summary: Rules CLI Generation Feature
Status: ✅ Complete
Files Modified
D:\Claude_dms3\ccw\src\core\routes\rules-routes.ts
Changes:
- Added import for
executeCliToolfrom cli-executor - Implemented
generateRuleViaCLI()function - Modified POST
/api/rules/createendpoint to supportmode: 'cli-generate'
Implementation Details
1. New Function: generateRuleViaCLI()
Location: lines 224-340
Purpose: Generate rule content using Gemini CLI based on different generation strategies
Parameters:
generationType: 'description' | 'template' | 'extract'description: Natural language description of the ruletemplateType: Template category for structured generationextractScope: File pattern for code analysis (e.g., 'src/**/*.ts')extractFocus: Focus areas for extraction (e.g., 'error handling, naming')fileName: Target filename (must end with .md)location: 'project' or 'user'subdirectory: Optional subdirectory pathprojectPath: Project root directory
Process Flow:
- Parse parameters and determine generation type
- Build appropriate CLI prompt template based on type
- Execute Gemini CLI with:
- Tool: 'gemini'
- Mode: 'write' for description/template, 'analysis' for extract
- Timeout: 10 minutes (600000ms)
- Working directory: projectPath
- Validate CLI execution result
- Extract generated content from stdout
- Call
createRule()to save the file - Return result with execution ID
2. Prompt Templates
Description Mode (write)
PURPOSE: Generate Claude Code memory rule from description to guide Claude's behavior
TASK: • Analyze rule requirements • Generate markdown content with clear instructions
MODE: write
EXPECTED: Complete rule content in markdown format
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/universal/00-universal-rigorous-style.txt)
Template Mode (write)
PURPOSE: Generate Claude Code rule from template type
TASK: • Create rule based on {templateType} • Generate structured markdown content
MODE: write
EXPECTED: Complete rule content in markdown format following template structure
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/universal/00-universal-rigorous-style.txt)
Extract Mode (analysis)
PURPOSE: Extract coding rules from existing codebase to document patterns and conventions
TASK: • Analyze code patterns • Extract common conventions • Identify best practices
MODE: analysis
CONTEXT: @{extractScope || '**/*'}
EXPECTED: Rule content based on codebase analysis with examples
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/analysis/02-analyze-code-patterns.txt)
3. API Endpoint Modification
Endpoint: POST /api/rules/create
Enhanced Request Body:
{
"mode": "cli-generate", // NEW: triggers CLI generation
"generationType": "description", // NEW: 'description' | 'template' | 'extract'
"description": "...", // NEW: for description mode
"templateType": "...", // NEW: for template mode
"extractScope": "src/**/*.ts", // NEW: for extract mode
"extractFocus": "...", // NEW: for extract mode
"fileName": "rule-name.md", // REQUIRED
"location": "project", // REQUIRED: 'project' | 'user'
"subdirectory": "", // OPTIONAL
"projectPath": "..." // OPTIONAL: defaults to initialPath
}
Backward Compatibility: Existing manual creation still works:
{
"fileName": "rule-name.md",
"content": "# Rule Content\n...",
"location": "project",
"paths": [],
"subdirectory": ""
}
Response Format:
{
"success": true,
"fileName": "rule-name.md",
"location": "project",
"path": "/absolute/path/to/rule-name.md",
"subdirectory": null,
"generatedContent": "# Generated Content\n...",
"executionId": "1734168000000-gemini"
}
Error Handling
Validation Errors
- Missing
fileName: "File name is required" - Missing
location: "Location is required (project or user)" - Missing
generationTypein CLI mode: "generationType is required for CLI generation mode" - Missing
descriptionfor description mode: "description is required for description-based generation" - Missing
templateTypefor template mode: "templateType is required for template-based generation" - Unknown
generationType: "Unknown generation type: {type}"
CLI Execution Errors
- CLI tool failure: Returns
{ error: "CLI execution failed: ...", stderr: "..." } - Empty content: Returns
{ error: "CLI execution returned empty content", stdout: "...", stderr: "..." } - Timeout: CLI executor will timeout after 10 minutes
- File exists: "Rule '{fileName}' already exists in {location} location"
Testing
Test Document
Created: D:\Claude_dms3\test-rules-cli-generation.md
Contains:
- API usage examples for all 3 generation types
- Request/response format examples
- Error handling scenarios
- Integration details
Compilation Test
✅ TypeScript compilation successful (npm run build)
Integration Points
Dependencies
- cli-executor.ts: Provides
executeCliTool()for Gemini execution - createRule(): Existing function for file creation
- handlePostRequest(): Existing request handler from RouteContext
CLI Tool
- Tool: Gemini (via
executeCliTool()) - Timeout: 10 minutes (600000ms)
- Mode: 'write' for generation, 'analysis' for extraction
- Working Directory: Project path for context access
Next Steps (Not Implemented)
- UI Integration: Add frontend interface in Rules Manager dashboard
- Streaming Output: Display CLI execution progress in real-time
- Preview: Show generated content before saving
- Refinement: Allow iterative refinement of generated rules
- Templates Library: Add predefined template types
- History: Track generation history and allow regeneration
Verification Checklist
- Import cli-executor functions
- Implement
generateRuleViaCLI()with 3 generation types - Build appropriate prompts for each type
- Use correct MODE (analysis vs write)
- Set timeout to at least 10 minutes
- Integrate with
createRule()for file creation - Modify POST endpoint to support
mode: 'cli-generate' - Validate required parameters
- Return unified result format
- Handle errors appropriately
- Maintain backward compatibility
- Verify TypeScript compilation
- Create test documentation
Files Created
D:\Claude_dms3\test-rules-cli-generation.md: Test documentationD:\Claude_dms3\IMPLEMENTATION_SUMMARY.md: This file