UNPKG

@jjdenhertog/ai-driven-development

Version:

AI-driven development workflow with learning capabilities for Claude

379 lines (327 loc) • 10.2 kB
--- description: "Phase 0: INVENTORY & SEARCH - Catalogs existing code and finds reusable components" allowed-tools: ["Read", "Grep", "Glob", "LS", "Bash", "Write", "mcp__*"] disallowed-tools: ["Edit", "MultiEdit", "NotebookEdit", "git", "Task", "TodoWrite", "WebFetch", "WebSearch"] --- # Command: aidev-code-phase0 # šŸ” CRITICAL: PHASE 0 = INVENTORY & SEARCH ONLY šŸ” **YOU ARE IN PHASE 0 OF 7:** - **Phase 0 (NOW)**: Inventory existing code and find reusable components - **Phase 1 (LATER)**: Architect agent creates enhanced PRP - **Phase 2 (LATER)**: Test designer creates test specifications - **Phase 3 (LATER)**: Programmer implements based on tests - **Phase 4A (LATER)**: Test executor validates implementation - **Phase 4B (LATER)**: Test fixer automatically fixes failing tests (if needed) - **Phase 5 (LATER)**: Reviewer agent performs final review **PHASE 0 OUTPUTS ONLY:** āœ… `<task_output_folder>/phase_outputs/inventory/component_catalog.json` āœ… `<task_output_folder>/phase_outputs/inventory/reusable_components.json` āœ… `<task_output_folder>/phase_outputs/inventory/pattern_matches.json` āœ… `<task_output_folder>/phase_outputs/inventory/search_results.md` āœ… `<task_output_folder>/context.json` (initialize) āœ… `<task_output_folder>/decision_tree.jsonl` (initialize) **PHASE 0 ABSOLUTELY FORBIDDEN:** āŒ Creating ANY source code files āŒ Running npm/yarn/pnpm install āŒ Setting up projects or environments āŒ Implementing features āŒ Writing files outside of .aidev-storage/tasks_output/ <role-context> You are a code inventory specialist. Your job is to catalog the existing codebase and identify reusable components BEFORE any new code is written. This prevents the 4x code duplication problem identified in AI coding research. **CRITICAL**: You MUST find and document existing implementations to maximize code reuse. </role-context> ## Purpose Phase 0 of the enhanced multi-agent pipeline. Uses pre-built codebase index to quickly identify reusable components and prevent code duplication. ## Process ### 0. Pre-Flight Check (Bash for Critical Validation Only) ```bash echo "====================================" echo "šŸ” PHASE 0: INVENTORY & SEARCH ONLY" echo "====================================" echo "āœ… Will: Query pre-built index" echo "āœ… Will: Find reusable components" echo "āŒ Will NOT: Create any source code" echo "====================================" # Check if index exists if [ ! -d ".aidev-storage/index" ]; then echo "āŒ FATAL ERROR: Codebase index not found!" echo "Please run: aidev index" exit 1 fi # Verify required index files REQUIRED_INDEX_FILES="components.json hooks.json utilities.json styles.json layouts.json api_routes.json patterns.json metadata.json" for INDEX_FILE in $REQUIRED_INDEX_FILES; do if [ ! -f ".aidev-storage/index/$INDEX_FILE" ]; then echo "āŒ ERROR: Index file missing: $INDEX_FILE" exit 1 fi done # Parse parameters PARAMETERS_JSON='<extracted-json-from-prompt>' TASK_FILENAME=$(echo "$PARAMETERS_JSON" | jq -r '.task_filename') TASK_OUTPUT_FOLDER=$(echo "$PARAMETERS_JSON" | jq -r '.task_output_folder // empty') if [ -z "$TASK_FILENAME" ] || [ "$TASK_FILENAME" = "null" ]; then echo "ERROR: task_filename not found in parameters" exit 1 fi if [ -z "$TASK_OUTPUT_FOLDER" ] || [ "$TASK_OUTPUT_FOLDER" = "null" ]; then echo "ERROR: task_output_folder not found in parameters" exit 1 fi # Load task if [ ! -f ".aidev-storage/tasks/$TASK_FILENAME.json" ]; then echo "Task not found: $TASK_FILENAME" exit 1 fi echo "āœ… Pre-flight checks passed" ``` ### 1. Load Task and Index Using Structured Operations <load-task-spec> Use the Read tool to load: - Task file: `.aidev-storage/tasks/$TASK_FILENAME.json` - Task description: `.aidev-storage/tasks/$TASK_FILENAME.md` Extract and structure: ```json { "task_id": "extracted_id", "task_name": "extracted_name", "task_type": "feature|bugfix|refactor|pattern", "task_description": "full_description", "complexity_score": 0-100, "test_strategy": "full|minimal|skip", "search_terms": ["term1", "term2", "term3"] } ``` </load-task-spec> <load-indexes> Use the Read tool to load all index files: - `.aidev-storage/index/components.json` - `.aidev-storage/index/hooks.json` - `.aidev-storage/index/utilities.json` - `.aidev-storage/index/styles.json` - `.aidev-storage/index/layouts.json` - `.aidev-storage/index/api_routes.json` - `.aidev-storage/index/patterns.json` - `.aidev-storage/index/metadata.json` </load-indexes> ### 2. Semantic Search with Enhanced Capabilities <search-strategy> Implement intelligent search with these capabilities: 1. **Term Expansion**: - auth → authentication, authorization, login, signin, signout, session - form → form, input, field, submission, validation, formik, react-hook-form - modal → modal, dialog, popup, overlay, portal - table → table, grid, list, datagrid, datatable 2. **Fuzzy Matching**: - Calculate similarity scores for partial matches - Include components with >70% name similarity - Consider camelCase/PascalCase variations 3. **Contextual Relevance**: - Boost scores for frequently used components - Prioritize components in similar feature areas - Consider import relationships </search-strategy> <structured-search> For each index category, search using this structure: ```json { "search_params": { "terms": ["expanded_term_list"], "fuzzy_threshold": 0.7, "include_related": true, "max_results": 20 }, "ranking_criteria": { "usage_count": 0.3, "name_similarity": 0.3, "last_modified": 0.2, "complexity_match": 0.2 } } ``` </structured-search> ### 3. Pattern Analysis and Learning <load-learned-patterns> Always check for learned patterns: Use Read tool on `.aidev-storage/planning/learned-patterns.json` if it exists. Structure pattern analysis: ```json { "high_priority_patterns": [ { "id": "pattern_id", "rule": "pattern_rule", "category": "api|state|architecture|error-handling", "confidence": 0.95, "source": "user_correction", "must_apply": true } ], "applicable_patterns": [] } ``` </load-learned-patterns> ### 4. Duplication Detection <duplication-analysis> Analyze for these duplication patterns: 1. **Component Duplication**: - Similar component names (edit distance < 3) - Components with identical prop interfaces - Similar file structures 2. **Style Duplication**: - Repeated CSS patterns - Identical style combinations - Hardcoded values that should use tokens 3. **Logic Duplication**: - Similar utility functions - Repeated API call patterns - Duplicated state management Output format: ```json { "duplication_risks": [ { "type": "component|style|logic", "existing": "path/to/existing", "similarity": 0.95, "recommendation": "reuse|extend|refactor" } ] } ``` </duplication-analysis> ### 5. Generate Structured Outputs <component-catalog> Create `component_catalog.json`: ```json { "task_context": { "id": "task_id", "name": "task_name", "search_terms": ["term1", "term2"] }, "search_results": { "components": [...], "hooks": [...], "utilities": [...], "api_routes": [...], "styles": [...] }, "statistics": { "total_matches": 0, "high_relevance": 0, "reuse_candidates": 0 } } ``` </component-catalog> <reusable-components> Create `reusable_components.json`: ```json { "must_reuse": [ { "reason": "user_pattern|high_usage|exact_match", "confidence": 0.95, "component": {...} } ], "should_reuse": [...], "can_extend": [...], "warnings": [ "šŸ”“ CRITICAL: User pattern detected - must follow existing auth pattern", "āš ļø Found 5 similar form components - avoid creating new" ] } ``` </reusable-components> <pattern-matches> Create `pattern_matches.json`: ```json { "matched_patterns": [...], "learned_patterns": { "applicable": [...], "must_follow": [...] }, "architectural_guidance": { "state_management": "detected_approach", "styling": "detected_approach", "data_fetching": "detected_approach" } } ``` </pattern-matches> ### 6. Context Initialization <initialize-context> Create initial context for the pipeline: ```json { "task_id": "id", "current_phase": "inventory", "phases_completed": ["inventory"], "phase_history": [ { "phase": "inventory", "completed_at": "ISO_timestamp", "success": true, "key_outputs": { "components_found": 0, "reuse_opportunities": 0, "critical_patterns": 0 } } ], "critical_context": { "task_type": "type", "task_complexity": "simple|normal|complex", "complexity_score": 0-100, "test_strategy": "full|minimal|skip", "reuse_requirements": [...], "pattern_constraints": [...], "architectural_decisions": [] } } ``` </initialize-context> ### 7. Generate Human-Readable Report <search-results-md> Create a comprehensive markdown report that includes: - Executive summary of findings - Reuse opportunities with confidence scores - Critical patterns that must be followed - Duplication warnings - Architectural insights - Recommendations for next phases </search-results-md> ## Key Requirements <phase0-constraints> <inventory-only> This phase MUST: ā–” Search extensively using index ā–” Identify ALL reuse opportunities ā–” Detect duplication risks ā–” Apply learned patterns ā–” Create structured outputs This phase MUST NOT: ā–” Write any code files ā–” Modify existing code ā–” Make architectural decisions ā–” Run tests or builds </inventory-only> <search-quality> Search must be: ā–” Semantic (understand variations) ā–” Fuzzy (catch similar names) ā–” Contextual (consider relationships) ā–” Exhaustive (check all categories) </search-quality> </phase0-constraints> ## Success Criteria Phase 0 is successful when: - Comprehensive component catalog exists - All reuse opportunities identified - Learned patterns documented - Duplication risks highlighted - No code files were created - Context initialized for pipeline