|
| 1 | +# Spec Reference Enforcement Rules |
| 2 | + |
| 3 | +**MANDATORY: ALL CODING AGENTS MUST FOLLOW THESE SPEC REFERENCE REQUIREMENTS** |
| 4 | + |
| 5 | +This file defines the mandatory requirements for including specification references in all generated code files. These rules ensure maintainability, traceability, and consistency across the codebase. |
| 6 | + |
| 7 | +**VIOLATION ENFORCEMENT:** All violations of rules in this file are subject to the universal violation enforcement system defined in [violation-enforcement.rules.md](./violation-enforcement.rules.md). |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## CORE REQUIREMENT |
| 12 | + |
| 13 | +**MANDATORY SPEC REFERENCES:** |
| 14 | +ALL generated code files MUST include spec reference comments that clearly identify: |
| 15 | +1. The specification file that guided the implementation |
| 16 | +2. The specific section within that specification |
| 17 | +3. The relationship between the code and the spec requirements |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## COMMENT FORMAT REQUIREMENTS |
| 22 | + |
| 23 | +### STANDARD FORMAT |
| 24 | +``` |
| 25 | +[COMMENT_SYNTAX] Implementation based on: [project-specs/<filename>.spec.md] - Section: [Specific Section Name] |
| 26 | +``` |
| 27 | + |
| 28 | +### LANGUAGE-SPECIFIC COMMENT ADAPTATION |
| 29 | + |
| 30 | +**AGENT RESPONSIBILITY:** |
| 31 | +- **KNOW** the appropriate comment syntax for the target programming language |
| 32 | +- **ADAPT** the spec reference format to use the correct comment syntax |
| 33 | +- **RESEARCH** comment syntax if uncertain about a language |
| 34 | + |
| 35 | +**COMMON LANGUAGE EXAMPLES:** |
| 36 | +```javascript |
| 37 | +// Implementation based on: [project-specs/ui-components.spec.md] - Section: Button Component Design |
| 38 | +``` |
| 39 | + |
| 40 | +```python |
| 41 | +# Implementation based on: [project-specs/data-processing.spec.md] - Section: CSV Parser Requirements |
| 42 | +``` |
| 43 | + |
| 44 | +```css |
| 45 | +/* Implementation based on: [project-specs/styling.spec.md] - Section: Color Palette and Typography */ |
| 46 | +``` |
| 47 | + |
| 48 | +```html |
| 49 | +<!-- Implementation based on: [project-specs/layout.spec.md] - Section: Header Navigation Structure --> |
| 50 | +``` |
| 51 | + |
| 52 | +```sql |
| 53 | +-- Implementation based on: [project-specs/database.spec.md] - Section: User Table Schema |
| 54 | +``` |
| 55 | + |
| 56 | +**UNKNOWN LANGUAGE PROTOCOL:** |
| 57 | +1. **RESEARCH** the language's comment syntax using available tools |
| 58 | +2. **WEB SEARCH** if necessary to find official documentation |
| 59 | +3. **ASK USER** if research yields no results or conflicting information - **USE `run_command` TOOL** - **MUST FOLLOW** [interactive-input.rules.md](./interactive-input.rules.md) for context on using run_command tool |
| 60 | +4. **USE** the format: "What is the proper comment syntax for [language name]?" - **USE `run_command` TOOL** - **MUST FOLLOW** [interactive-input.rules.md](./interactive-input.rules.md) for context on using run_command tool |
| 61 | +5. **DOCUMENT** the decision for future reference - **FOLLOW** [spec-management.rules.md](./spec-management.rules.md) for specification documentation workflow |
| 62 | + |
| 63 | +--- |
| 64 | + |
| 65 | +## PLACEMENT REQUIREMENTS |
| 66 | + |
| 67 | +### PRIMARY PLACEMENT |
| 68 | +**TOP OF FILE** - Immediately after any license/copyright headers, before any imports or code |
| 69 | + |
| 70 | +### SECONDARY PLACEMENTS |
| 71 | +1. **Before imports** - Spec references come before any import statements |
| 72 | +2. **Function-specific** - Additional references before complex functions implementing different spec sections |
| 73 | +3. **Class-specific** - Additional references before class definitions implementing specific spec components |
| 74 | +4. **Module-specific** - References at module level for large implementations |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## MULTIPLE SPEC REFERENCES |
| 79 | + |
| 80 | +When code implements multiple specifications, use multi-line format: |
| 81 | + |
| 82 | +```javascript |
| 83 | +// Implementation based on: |
| 84 | +// - [project-specs/authentication.spec.md] - Section: Login Flow |
| 85 | +// - [project-specs/ui-components.spec.md] - Section: Form Validation |
| 86 | +// - [project-specs/security.spec.md] - Section: Password Requirements |
| 87 | +``` |
| 88 | + |
| 89 | +**ORGANIZATION:** |
| 90 | +- List specs in order of implementation priority |
| 91 | +- Include specific section names for each spec |
| 92 | +- Maintain consistent formatting across all references |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## EXISTING CODE ENFORCEMENT |
| 97 | + |
| 98 | +### MANDATORY CHECKS |
| 99 | +When modifying existing code files, agents MUST: |
| 100 | + |
| 101 | +1. **CHECK** for existing spec reference comments |
| 102 | +2. **READ** and understand all referenced specifications |
| 103 | +3. **FOLLOW** the patterns and requirements from referenced specs |
| 104 | +4. **MAINTAIN** consistency with existing spec-driven implementations |
| 105 | +5. **UPDATE** spec references when adding new functionality |
| 106 | + |
| 107 | +### MODIFICATION PROTOCOL |
| 108 | +- **PRESERVE** existing spec references unless they become obsolete |
| 109 | +- **ADD** new spec references for additional functionality |
| 110 | +- **UPDATE** section references if spec sections change |
| 111 | +- **MAINTAIN** the same comment format as existing references |
| 112 | + |
| 113 | +### LEGACY CODE HANDLING |
| 114 | + |
| 115 | +**TRIGGER CONDITION:** When modifying existing code files that lack spec reference comments |
| 116 | + |
| 117 | +**MANDATORY WORKFLOW REFERENCE:** |
| 118 | +For complete workflow requirements when handling legacy code without specifications, agents MUST follow the comprehensive workflow defined in [spec-management.rules.md](./spec-management.rules.md) under the "LEGACY CODE SPECIFICATION WORKFLOW" section. |
| 119 | + |
| 120 | +**IMMEDIATE REQUIREMENTS:** |
| 121 | +- **HALT** all modification activities when encountering code without spec references |
| 122 | +- **FOLLOW** the complete legacy code workflow in [spec-management.rules.md](./spec-management.rules.md) |
| 123 | +- **ADD** proper spec reference comments after workflow completion |
| 124 | +- **ENSURE** correct comment syntax for the file's programming language |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## MAINTENANCE BENEFITS |
| 129 | + |
| 130 | +**QUICK SPEC IDENTIFICATION:** |
| 131 | +- Developers can immediately identify relevant specifications |
| 132 | +- Maintenance tasks can quickly locate governing requirements |
| 133 | +- Code reviews can verify spec compliance |
| 134 | +- Refactoring can maintain spec alignment |
| 135 | + |
| 136 | +**TRACEABILITY:** |
| 137 | +- Clear connection between code and requirements |
| 138 | +- Audit trail for implementation decisions |
| 139 | +- Documentation of architectural choices |
| 140 | +- Historical context for code changes |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +## ENFORCEMENT PROTOCOL |
| 145 | + |
| 146 | +**MANDATORY COMPLIANCE:** |
| 147 | +- **NO EXCEPTIONS** - All generated code files must include spec references |
| 148 | +- **IMMEDIATE IMPLEMENTATION** - Add references during initial code generation |
| 149 | +- **CONSISTENT FORMAT** - Use language-appropriate comment syntax |
| 150 | +- **COMPLETE INFORMATION** - Include both spec file and section names |
| 151 | + |
| 152 | +**VIOLATION CONSEQUENCES:** |
| 153 | +All violations are subject to the universal violation enforcement system defined in [violation-enforcement.rules.md](./violation-enforcement.rules.md). |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +## INTEGRATION WITH OTHER RULES |
| 158 | + |
| 159 | +**CROSS-REFERENCES:** |
| 160 | +- **Spec Management:** [spec-management.rules.md](./spec-management.rules.md) - Overall specification workflow and legacy code handling |
| 161 | +- **Core Principles:** [core-principles.rules.md](./core-principles.rules.md) - Implementation workflow integration |
| 162 | +- **Interactive Input:** [interactive-input.rules.md](./interactive-input.rules.md) - User clarification procedures |
| 163 | +- **Violation Enforcement:** [violation-enforcement.rules.md](./violation-enforcement.rules.md) - Universal violation enforcement system |
| 164 | + |
| 165 | +**WORKFLOW INTEGRATION:** |
| 166 | +This rule integrates with the core agent workflow at the "IMPLEMENT ACCORDING TO SPECIFICATIONS" step, ensuring all generated code maintains proper spec traceability. For legacy code without specifications, agents must follow the "LEGACY CODE SPECIFICATION WORKFLOW" defined in [spec-management.rules.md](./spec-management.rules.md). |
0 commit comments