# CLAUDE.md - Ruchy Compiler Implementation Protocol
## IMPORTANT: Auto-Generated and Single-Source-of-Truth Files
**đ¨ ABSOLUTELY FORBIDDEN TO EDIT - THESE FILES ARE AUTO-GENERATED:**
1. **`deep_context.md`** - Auto-generated, will be overwritten
## IMPORTANT: Roadmap Single Source of Truth
**â
ALWAYS USE `docs/execution/roadmap.yaml`** - This is the ONLY roadmap file
- **DELETED**: `docs/execution/roadmap.md` (removed 2025-10-20)
- **Rationale**: Maintaining duplicate .md file caused confusion and merge conflicts
- **Migration**: All roadmap data now lives exclusively in YAML format
- **Benefits**: Machine-readable, programmatically accessible, prevents drift
## Prime Directive
**Generate correct code that compiles on first attempt. Quality is built-in, not bolted-on.**
**Extreme TDD means - TDD augmented by mutation + property + fuzz testing + pmat complexity, satd, tdg, entropy**
## đ¨ CRITICAL: E2E Testing Protocol (DEFECT-001 Response)
**SACRED RULE**: NEVER commit frontend changes without E2E tests passing.
**Reference**: `docs/defects/CRITICAL-DEFECT-001-UI-EXECUTION-BROKEN.md`
### Mandatory E2E Testing Checklist
**Before ANY commit touching frontend code** (`static/**/*.html`, `*.js`, `*.css`):
1. â
**Run E2E smoke tests**: `./run-e2e-tests.sh tests/e2e/notebook/00-smoke-test.spec.ts`
2. â
**Verify selectors exist**: Use `validateSelectors()` helper (prevent phantom UI)
3. â
**Check coverage**: Frontend coverage âĽ80% (enforced)
4. â
**Lint frontend**: `make lint-frontend` passes
5. â
**Visual check**: Manually verify in browser (Genchi Genbutsu)
### đ¨ CRITICAL: Phantom UI Prevention Protocol (DEFECT-E2E-PHANTOM-UI Response)
**ROOT CAUSE LEARNED**: E2E tests were written for non-existent UI elements, causing 100% test failure rate.
**Reference**: `docs/issues/DEFECT-E2E-PHANTOM-UI.md`
**MANDATORY PROTOCOL** (Before Writing ANY E2E Test):
1. đ **GENCHI GENBUTSU**: Read actual HTML file BEFORE writing tests
- Example: Read `static/notebook.html` to see real element IDs
- NEVER assume UI elements exist based on planned/future designs
2. â
**Selector Validation**: Verify EVERY selector exists in actual HTML
```typescript
// â FORBIDDEN: Writing tests for phantom UI
await page.locator('#status').toHaveClass(/status-ready/); // Element doesn't exist!
// â
CORRECT: Use actual notebook UI elements
await page.waitForSelector('#notebook-cells', { timeout: 10000 });
await expect(page.locator('.CodeMirror').first()).toBeVisible();
```
3. đŤ **No Phantom UI**: NEVER write tests for planned/future UI elements
- Tests describe CURRENT reality, not future plans
- If UI doesn't exist yet, don't write E2E tests for it
4. â
**Manual Verification**: View page in browser to confirm elements exist
- Open `static/notebook.html` in browser
- Use DevTools to inspect actual element IDs and classes
- Take screenshot if needed for reference
**Toyota Way**: GENCHI GENBUTSU - Go and see what's actually there, don't test phantom UI
## đ¨ CRITICAL: A+ Code Standard (From paiml-mcp-agent-toolkit)
**ABSOLUTE REQUIREMENT**: All NEW code MUST achieve A+ quality standards:
- **Maximum Cyclomatic Complexity**: â¤10 (not 20, not 15, TEN!)
- **Maximum Cognitive Complexity**: â¤10 (simple, readable, maintainable)
- **Function Size**: â¤30 lines (if longer, decompose it)
- **Single Responsibility**: Each function does ONE thing well
- **Zero SATD**: No TODO, FIXME, HACK, or "temporary" solutions
- **TDD Mandatory**: Write test FIRST, then implementation
- **Test Coverage**: 100% for new functions (no exceptions)
**Enforcement Example**:
```rust
// â BAD: Complexity 15+
// â
GOOD: Complexity â¤10
fn process_data(items: Vec<Item>) -> Result<Output> {
items.into_iter()
.filter(|item| item.valid)
.map(process_single_item)
.collect()
}
```
## EXTREME TDD Protocol (CRITICAL RESPONSE TO ANY BUG)
**đ¨ ABSOLUTE RULE: NO BUG IS OUT OF SCOPE (MANDATORY - ZERO EXCEPTIONS)**
**FORBIDDEN RESPONSES** (ABSOLUTELY NEVER SAY THESE):
- â "This bug is out of scope" / "Let's mark this test as ignored" / "Let's defer this"
- â "This is a parser bug, we're working on the formatter" / "This is a separate issue"
- â "Let's work around this for now" / "This is a known limitation"
**TOYOTA WAY**: When you find ANY bug (parser, transpiler, runtime, linter, tooling) â STOP THE LINE and FIX IT immediately.
**MANDATORY RESPONSE PROTOCOL**:
1. đ **STOP THE LINE**: Halt ALL other work immediately
2. đ **ROOT CAUSE ANALYSIS**: Five Whys + GENCHI GENBUTSU (go and see)
3. đ **CREATE TICKET**: Add to docs/execution/roadmap.yaml ([PARSER-XXX], [TRANSPILER-XXX], etc.)
4. â
**EXTREME TDD FIX** (REDâGREENâREFACTOR):
- **RED**: Write failing test that reproduces bug FIRST
- **GREEN**: Fix bug with minimal code changes
- **REFACTOR**: Apply PMAT quality gates (A- minimum, â¤10 complexity)
5. đ§Ş **PROPERTY TESTS**: Verify invariants with 10K+ random inputs
6. đ§Ź **MUTATION TESTS**: Prove tests catch real bugs (âĽ75% mutation coverage)
7. â
**COMMIT**: Document fix with ticket reference
### đ¨ CRITICAL: Missing Language Feature Protocol (MANDATORY)
**IF YOU DISCOVER A LANGUAGE FEATURE IS "NOT IMPLEMENTED" - IMPLEMENT IT, DON'T SKIP IT!**
**WRONG RESPONSE** (FORBIDDEN):
- â "This feature isn't implemented, let's skip it"
- â "Let's document it as not working"
- â "Let's work around it"
- â "Let's simplify the examples to avoid it"
**CORRECT RESPONSE** (MANDATORY):
1. đ **STOP THE LINE**: Halt current work immediately
2. đ **INVESTIGATE**: Use GENCHI GENBUTSU to verify feature is truly missing (don't assume!)
3. đ **CREATE TICKET**: Add to docs/execution/roadmap.yaml with format: [FEATURE-XXX]
4. â
**EXTREME TDD IMPLEMENTATION**:
- **RED**: Write tests for the missing feature FIRST (they will fail)
- **GREEN**: Implement the feature minimally to pass tests
- **REFACTOR**: Apply quality gates (â¤10 complexity, A- grade)
5. đ **VALIDATE**: Property tests + mutation tests (âĽ75% coverage)
6. đ **DOCUMENT**: Update LANG-COMP with working examples
7. â
**COMMIT**: Complete implementation with ticket reference
**Example**: Missing feature â STOP â Verify with Genchi Genbutsu â Create ticket â TDD implementation â Commit
**Toyota Way**: Missing features ARE defects - implement with TDD, never skip
### Test Coverage Requirements (MANDATORY - ALL Bug Categories):
- **Unit Tests**: Parser (tokens/grammar/edge cases), Transpiler (RuchyâRust mappings), Runtime (evaluation paths/errors), Linter (rules/scope/AST), Tooling (CLI/flags/output)
- **Integration Tests**: Full compile â execute â validate pipeline + All examples/
- **Property Tests**: 10K+ cases via proptest (verify invariants hold)
- **Fuzz Tests**: Millions of inputs via cargo-fuzz/AFL (find edge cases)
- **Mutation Tests**: âĽ75% coverage via cargo-mutants (prove tests catch real bugs)
- **Regression Tests**: Every GitHub issue gets specific test case
### đ DEBUGGING TOOLKIT (RuchyRuchy v1.9.0+ - PRODUCTION READY)
**â
NOW AVAILABLE**: Comprehensive debugging tools via ruchydbg CLI (installed via `cargo install ruchyruchy`)
**What EXISTS Now (v1.9.0)**:
- â
RuchyRuchy repository: https://github.com/paiml/ruchyruchy
- â
`ruchydbg run` - Timeout detection + type-aware tracing (Ruchy v3.149.0+)
- â
`ruchydbg validate` - Validates debugging infrastructure
- â
Bug discovery: Property tests, differential tests, fuzz tests, code churn analysis
- â
Bug replication: Delta debugging, git bisection, test generation
- â
Bug reporting: GitHub integration, Five-Whys analysis
- â
Quality tools: 10 static analysis tools (TDG, dead code, ML defect prediction, etc.)
**Bug Detection Workflow** (Automated, 2-5 minutes):
1. **Create Test File**: Property-based test with expected behavior (1 minute)
```ruchy
// test_issue.ruchy - Property: Must NOT hang
struct Logger { level: LogLevel }
impl Logger { fun test(&self) { self.level as i32; } }
```
2. **Run with ruchydbg**: Detect hangs + type-aware tracing (30 seconds)
```bash
ruchydbg run test_issue.ruchy --timeout 1000 --trace
```
3. **GENCHI GENBUTSU**: Read actual code to find root cause (3-10 minutes)
```bash
```
4. **Validate Fix**: Use Ruchy's 15 native tools + type tracing (1 minute)
```bash
ruchy check test.ruchy ruchy --trace run test.ruchy ruchy ast test.ruchy ```
**Time Savings**: Manual (30+ min/bug) â ruchydbg + tracing (2-5 min/bug) = **6-15x faster**
**Type-Aware Tracing (Ruchy v3.149.0+)**:
```bash
# Shows argument and return types for debugging
ruchy --trace run test.ruchy
# Or via ruchydbg wrapper:
ruchydbg run test.ruchy --trace
# Output: TRACE: â square(5: integer), TRACE: â square = 25: integer
```
**Resources**:
- Installation: `cargo install ruchyruchy` (includes ruchydbg CLI)
- Integration Guide: `../ruchyruchy/INTEGRATION_GUIDE.md` (comprehensive usage)
- Quick Start: `../ruchyruchy/QUICK_START_FOR_RUCHY_DEVS.md` (10-minute tutorial)
- Bug Patterns: `../ruchyruchy/WHACK_A_MOLE_BUG_HUNTERS_GUIDE.md` (1,200+ lines)
- Repository: https://github.com/paiml/ruchyruchy
**Success Story - Issue #79 (2025-10-29)**:
- â
Used `ruchydbg run --timeout` to detect enum cast hang instantly
- â
Applied timeout methodology: detected bug in 1 second
- â
Used GENCHI GENBUTSU to find root causes (dispatch_method_call, eval_struct_instance_method)
- â
Fixed 2 bugs (RUNTIME-093, RUNTIME-094) with 8/8 tests passing
- âąď¸ **Time**: ~2 hours total (vs estimated 4-6 hours manual debugging)
- đ **Detection**: Bug found in 1 second with timeout vs 30+ minutes manually
### Mutation Testing Protocol (MANDATORY - Sprint 8)
**CRITICAL**: Mutation testing is the GOLD STANDARD for test quality validation.
#### Why Mutation Testing Matters:
- **Line coverage measures execution, mutation coverage measures effectiveness**
- 99% line coverage can have 20% mutation coverage (tests run code but don't validate it)
- Mutation testing empirically proves tests catch real bugs, not just exercise code paths
- Each mutation simulates a real bug - if tests don't catch it, they're inadequate
#### Incremental Mutation Testing Strategy:
```bash
# NEVER run full baseline (10+ hours) - use incremental file-by-file approach
cargo mutants --file src/frontend/parser/core.rs --timeout 300 # 5-30 min
# Analyze gaps immediately
grep "MISSED" core_mutations.txt
# Write tests targeting SPECIFIC mutations
# Re-run to validate 80%+ coverage achieved
```
#### Mutation-Driven TDD:
1. Run mutation test FIRST to identify gaps
2. Write test targeting SPECIFIC mutation
3. Re-run mutation test to verify fix
4. Repeat until 80%+ coverage achieved
5. No speculative tests - only evidence-based
#### Acceptable Mutations (Rare):
- **Semantically Equivalent**: Mutation produces identical observable behavior
- **Example**: `Vec::leak(Vec::new())` vs `self.state.get_errors()` both return empty slice
- Document why mutation is uncatchable and mark ACCEPTABLE
## Scientific Method Protocol
**WE DON'T GUESS, WE PROVE VIA QUANTITATIVE METHODS AND TESTING.**
### Evidence-Based Development Rules:
1. **NO ASSUMPTIONS**: Every claim must be backed by concrete evidence
2. **MEASURE EVERYTHING**: Use tests, benchmarks, and metrics to validate behavior
3. **REPRODUCE ISSUES**: Create minimal test cases that demonstrate problems
4. **QUANTIFY IMPROVEMENTS**: Before/after metrics prove effectiveness
5. **DOCUMENT EVIDENCE**: All findings must be recorded with reproducible steps
### Investigation Protocol:
1. **Hypothesis**: State what you believe is happening
2. **Test**: Create specific tests that prove/disprove the hypothesis
3. **Measure**: Collect concrete data (test results, timings, coverage)
4. **Analyze**: Draw conclusions only from the evidence
5. **Document**: Record findings and next steps
## Mandatory Testing Requirements
**Target**: 80% property test coverage across all modules (Sprint 88 pattern)
**Requirements**:
1. **Doctests**: Every public function has runnable documentation examples
2. **Property Tests**: `proptest!` macro with 10K+ random inputs (80% of modules)
3. **Examples**: Working code in examples/ directory demonstrating usage
4. **Code Coverage**: âĽ33.34% baseline (enforced by pre-commit hooks, NEVER decrease)
- Current: 33.34% (post-QUALITY-007: character literals, tuple destructuring, rest patterns)
- Direction: Must increase or stay same
## PMAT Quality Gates & Enforcement (v2.70+)
**Standards**: A- (âĽ85), Complexity â¤10, SATD=0, Duplication <10%, Docs >70%, Coverage âĽ80%
**Setup**: `pmat quality-gates init; pmat hooks install`
**Daily Workflow**:
- **Before Work**: `pmat tdg . --top-files 10; pmat tdg dashboard --port 8080 --open &`
- **During**: Monitor dashboard, check files: `pmat tdg <file> --include-components`
- **Before Commit**: `pmat tdg . --min-grade A- --fail-on-violation` (BLOCKING)
**Health Check**: `pmat maintain health` (~10s)
**Key Rules**:
- **PMAT FIRST**: Run quality gates before ANY task
- **NO BYPASS**: Never `--no-verify`, fix root cause via Five Whys
- **TDD MANDATORY**: Write test first, prove fix works
- Use cargo-llvm-cov (not tarpaulin)
- All bugs solved with TDD, never manual hacks
- Mix: unit/doctests/property-tests/fuzz tests
- Check ../ruchy-book and ../rosetta-ruchy at sprint start
## Scripting Policy
**CRITICAL**: Use ONLY Ruchy scripts for adhoc scripting and testing. No Python, Bash scripts, or other languages for testing Ruchy functionality.
â
**Allowed**: `*.ruchy` files loaded via `:load` command in REPL
â **Forbidden**: Python scripts, shell scripts, or any non-Ruchy testing code
## đ¨ CRITICAL: Ruchy Execution Safety Protocol
**ROOT CAUSE OF SESSION HANGS**: Runaway Ruchy processes with infinite loops caused 7 zombie processes running 50-96 days at 98% CPU each, system load 18.43.
**MANDATORY: ALL ruchy script executions MUST have timeouts**
### Execution Pattern (NO EXCEPTIONS):
```bash
# â
CORRECT - Always use timeout
timeout 10 ruchy script.ruchy # 10s for most operations
timeout 10 ruchy transpile file.ruchy # 10s for transpilation
timeout 60 ruchy test --mutations # 60s for heavy operations
timeout 120 cargo test # 120s for test suites
# â FORBIDDEN - Never run without timeout
ruchy script.ruchy # Can hang forever
cargo run -- eval script.ruchy # Can hang forever
```
### Safety Rules:
1. **NEVER execute ruchy without timeout** - Use `timeout` command for ALL invocations
2. **Check for infinite loops** - Validate scripts don't have `while true` with blocking I/O
3. **Monitor temp files** - Clean up `/tmp/*.ruchy` after execution
4. **Kill zombies immediately** - If you see high CPU ruchy processes, kill them: `pkill -9 -f "ruchy /tmp/"`
### Preventive Measures:
```bash
# Before starting work: Check for zombie processes
# Clean up temp files
rm -f /tmp/*.ruchy
# Kill any ruchy processes older than 5 minutes
pkill -f "ruchy /tmp/" --older 300
```
### Incident Response:
If Claude session hangs during `cargo run` or `ruchy` execution:
1. đ **Diagnose**: `ps aux | grep ruchy | grep -v grep`
2. đ **Kill zombies**: `pkill -9 -f "ruchy /tmp/"`
3. đ§š **Clean up**: `rm -f /tmp/*.ruchy`
4. đ **Verify**: `uptime` (load should be <4 on this system)
**Reference Incident**: 2025-10-23 - 7 processes, 96 days runtime, system load 18.43 â killed â load 8.05
## đ¨ CRITICAL: Claude Zombie Process Prevention
**ROOT CAUSE OF PERSISTENT HANGS**: Zombie Claude Code processes accumulate over time, consuming CPU and memory.
**Discovered 2025-10-23**: 6 zombie Claude processes:
- 3 processes: **194-197% CPU** (2 full cores each), running **111-231 DAYS** (3-7 months!)
- 3 processes: **8-10% CPU**, running **9-10 days**, 576-987MB RAM each
- **Impact**: System load 7.4, 22GB swap usage, competing for resources with active sessions
### Prevention Protocol (MANDATORY):
**Before starting ANY Claude session:**
```bash
# 1. Check for zombie Claude processes (>1 day old)
# 2. Kill zombies older than 1 day
pkill -f "claude --dangerously-skip-permissions" --older 86400
# 3. Verify system health
uptime # Load should be <4 on this system
free -h # Swap usage should be <5GB
```
### Daily Cleanup (MANDATORY):
```bash
# Add to crontab: Kill Claude processes older than 24 hours
0 */6 * * * pkill -f "claude --dangerously-skip-permissions" --older 86400
# Check system load
0 */1 * * * uptime >> /tmp/system-load-monitor.log
```
### When to Manually Kill Claude Sessions:
1. **High CPU** (>50% for >10 minutes) â Old background session, kill it
2. **Old sessions** (>24 hours) â Likely zombie, kill it
3. **High memory** (>2GB for single session) â Memory leak, kill it
4. **High system load** (>4 sustained) â Check for zombies: `ps aux | grep claude`
**Why This Matters:**
- Zombie Claude processes accumulate like zombie ruchy processes
- Each zombie consumes 1-2 CPU cores indefinitely
- Memory and swap usage grow over time
- Active sessions compete with zombies, causing hangs
**Reference Incident**: 2025-10-23
- Before: 6 zombies, load 7.4, 22GB swap, sessions freezing
- After: All killed, load 5.5 â 2.0, 7GB swap, sessions stable
## bashrs Quality Enforcement (Shell Scripts & Makefiles)
**SACRED RULE**: ALL shell scripts MUST either:
1. **Use bashrs validation** (for infrastructure/build scripts like Makefile, pre-commit hooks), OR
2. **Be replaced with Ruchy scripts** (PREFERRED for all new scripting)
**MANDATORY**: All remaining shell scripts and Makefiles MUST pass bashrs quality checks before commit.
**Policy**:
- **New Scripts**: Write in Ruchy (`.ruchy` files) whenever possible
- **Existing Scripts**: Either migrate to Ruchy OR enforce bashrs quality gates
- **Infrastructure**: Build tools, CI/CD, and git hooks may remain in bash with bashrs validation
- **Zero Exceptions**: No raw bash without bashrs validation
### Installation
```bash
cargo install bashrs # Already installed at ~/.cargo/bin/bashrs
```
### Usage
**Manual Linting**:
```bash
# Lint single shell script
bashrs lint <script.sh>
# Lint Makefile
bashrs make lint Makefile
# Lint all via Makefile targets
make lint-scripts # All .sh files
make lint-make # Makefile only
make lint-bashrs # Everything (scripts + Makefile)
```
**Pre-commit Hook**: bashrs validation runs automatically on staged files
- â
**Errors**: Block commit (exit 1)
- â ď¸ **Warnings**: Allow commit (non-blocking)
**Quality Standards**: Errors block commits, warnings are non-blocking. Run `make lint-bashrs` before changes.
### Documented Exceptions
**DET002 (Non-deterministic timestamps)** - Acceptable in logging/testing scripts:
- `.pmat/run_overnight_mutations.sh`: Timestamps are INTENTIONAL for test logging
- Rationale: Logging scripts need timestamps for debugging and audit trails
- Pattern: Add header comment explaining why timestamps are required
- Pre-commit: Excluded from bashrs validation (documented in .git/hooks/pre-commit)
**Exception Criteria**:
- Script purpose is logging, testing, or debugging (not build/deployment)
- Timestamps provide valuable debugging information
- Script is NOT used in reproducible builds or CI/CD pipelines
- Exception is documented in script header AND CLAUDE.md
## Implementation Hierarchy
```yaml
Navigation:
1. SPECIFICATION.md # What to build (reference)
2. docs/execution/roadmap.yaml # Strategic priorities and current tasks
3. docs/execution/ # Tactical work breakdown
4. ../ruchy-book/INTEGRATION.md # Book compatibility tracking
5. CHANGELOG.md # Version history and release notes
```
## Book Compatibility Monitoring
**CRITICAL**: Check `../ruchy-book/INTEGRATION.md` for current compatibility status and regression detection.
### ruchy-book Validation
**MANDATORY**: Pre-commit hook validates Ch01-05. Run `make validate-book` or auto via `git commit`.
**Features**: Parallel execution, fail-fast, 120s timeout. See `../ruchy-book/INTEGRATION.md`
## Absolute Rules (From paiml-mcp-agent-toolkit)
1. **NEVER Leave Stub Implementations**: Every feature must be fully functional. No "TODO" or "not yet implemented".
2. **NEVER Add SATD Comments**: Zero tolerance for TODO, FIXME, HACK comments. Complete implementation only.
3. **NEVER Use Simple Heuristics**: Always use proper AST-based analysis and accurate algorithms.
4. **NEVER Duplicate Core Logic**: ONE implementation per feature. All consumers use same underlying logic.
5. **ALWAYS Dogfood via MCP First**: Use our own MCP tools as primary interface when available.
6. **NEVER Bypass Quality Gates**: Zero tolerance for `--no-verify`. Fix issues, don't bypass.
7. **NEVER Use Git Branches**: Work directly on main branch. Continuous integration prevents conflicts.
8. **ALWAYS Apply Kaizen**: Small, incremental improvements. One file at a time.
9. **ALWAYS Use Genchi Genbutsu**: Don't guess. Use PMAT to find actual root causes.
10. **ALWAYS Apply Jidoka**: Automate with human verification. Use `pmat refactor auto`.
## Task Execution Protocol
### MANDATORY: Roadmap and Ticket Tracking
**CRITICAL**: ALL development work MUST follow roadmap-driven development:
1. **ALWAYS Use Ticket Numbers**: Every commit, PR, and task MUST reference a ticket ID from docs/execution/roadmap.yaml
2. **Roadmap-First Development**: No work begins without a corresponding roadmap entry
3. **Ticket Format**: Use format "QUALITY-XXX", "PARSER-XXX", "DF-XXX", "WASM-XXX" per roadmap
4. **Traceability**: Every change must be traceable back to business requirements via ticket system
5. **Sprint Planning**: Work is organized by sprint with clear task dependencies and priorities
### CLI Testing Standard
**Pattern**: Use `assert_cmd::Command` with predicates, NOT `std::process::Command`
**Reference**: See `tests/fifteen_tool_validation.rs` for examples
### MANDATORY: Test Naming Convention (TRACEABILITY)
**CRITICAL**: Every test MUST be traceable to its documentation/specification via naming convention.
**Naming Pattern** (MANDATORY - NO EXCEPTIONS):
```
test_<TICKET_ID>_<section>_<feature>_<scenario>
Examples:
- test_langcomp_003_01_if_expression_true_branch()
- test_langcomp_003_01_if_expression_example_file()
- test_langcomp_003_02_match_literal_pattern()
- test_langcomp_003_05_break_exits_loop()
```
**Component Breakdown**:
1. `TICKET_ID`: LANG-COMP-003 â `langcomp_003` (lowercase, underscored)
2. `section`: File number (01, 02, 03, 04, 05)
3. `feature`: What is being tested (if_expression, match_pattern, for_loop)
4. `scenario`: Specific test case (true_branch, example_file, literal_pattern)
**Why Naming Convention is Mandatory**:
- **Traceability**: Instantly map test â documentation â ticket â requirement
- **Findability**: `grep "langcomp_003_01"` finds all if-expression tests
- **Validation**: Prove documentation examples are tested (not just written)
- **Toyota Way**: Standard work enables quality - no standard = no quality
**Generic Names are DEFECTS**: `test_if_true_branch()` provides ZERO traceability. Use ticket-based naming.
### Commit Message Format
```
[TICKET-ID] Brief description
- Specific changes
- Test coverage
- TDG Score: src/file.rs: 68.2â82.5 (C+âB+)
Closes: TICKET-ID
```
### đ¨ MANDATORY: Update Roadmap & Changelog on EVERY Commit
**ABSOLUTE REQUIREMENT**: EVERY commit MUST update documentation to prevent stale roadmap.
**Pre-Commit Checklist (NO EXCEPTIONS)**:
1. â
**Update docs/execution/roadmap.yaml**:
- Add completed task to appropriate sprint section
- Update progress percentages
- Document test metrics (unit/property/mutation counts)
- Mark dependencies as complete
2. â
**Update CHANGELOG.md**:
- Add entry under appropriate version header
- Document what changed (Added/Fixed/Changed/Removed)
- Include ticket reference and file paths
- Note breaking changes if any
**Why This Matters**:
- **Single Source of Truth**: roadmap.yaml is machine-readable and programmatically validated
- **Historical Record**: CHANGELOG.md provides human-readable version history
- **No Stale Documentation**: Every commit keeps documentation current
- **Toyota Way**: Jidoka (quality built-in) - documentation is part of the commit, not an afterthought
**Workflow**: Code changes â Update roadmap.yaml â Update CHANGELOG.md â Commit atomically
**Forbidden**: Code commits without documentation updates
### End-of-Sprint Git Commit Protocol (MANDATORY)
**Sprint Completion Checklist**:
1. â
All sprint tasks complete + unit tests passing
2. â
**Property tests**: `cargo test <module>::property_tests -- --ignored --nocapture` (report results)
3. â
**Mutation tests**: `cargo mutants --file tests/lang_comp/<module>.rs --timeout 300` (âĽ75% CAUGHT/MISSED)
4. â
**15-Tool Validation**: All examples work with ALL 15 native tools
5. â
**Roadmap + Documentation updated** with sprint status + test metrics
6. â
**GIT COMMIT IMMEDIATELY**: `git add . && git commit` with sprint summary, test metrics, ticket list
**Toyota Way**: Atomic sprint commits prevent integration hell and data loss
## TDG Scoring & Enforcement
**Grades**: A+ (95-100), A (90-94), A- (85-89), B (80-84), C (70-79), D (60-69), F (<60)
**Pre-Commit**: `pmat tdg . --min-grade A- --fail-on-violation` (BLOCKING)
## Compiler Architecture Patterns
**Parser**: Pratt parsing with error recovery, operator precedence via binding power
**Type Inference**: Bidirectional checking (check vs infer), unification for type matching
## Quality Gates Enforcement (BLOCKING - Not Advisory)
### SACRED RULE: NEVER BYPASS QUALITY GATES
- â **FORBIDDEN**: `git commit --no-verify`, skipping tests, ignoring checks, dismissing warnings
- â
**Toyota Way**: Stop the line for ANY defect, fix root cause via Five Whys
**Pre-commit Hooks** (AUTO-INSTALLED via `pmat hooks install`):
- TDG A-, Function complexity â¤10, Basic REPL test, bashrs validation, book validation
**When Clippy Blocks** - Fix root cause:
- Missing `# Errors` â Add documentation with examples
- `unwrap()` â Replace with `expect()` + meaningful messages
- Dead code â Remove or prefix with underscore
- Missing doctests â Add runnable examples
**Make Lint Contract**: `cargo clippy --all-targets --all-features -- -D warnings` (EVERY warning = error)
### đ¨ CRITICAL: Pre-commit Hook Management (PMAT-Generated)
**ABSOLUTE PROHIBITION**: Quality gate checks MUST NEVER be "temporarily disabled"
**Reference Issue**: `docs/issues/PMAT-HOOK-DISABLED-CHECKS.md` - Comprehensive Five Whys analysis
**Problem**: PMAT-generated pre-commit hooks (`.git/hooks/pre-commit`) may contain commented-out checks with "â ď¸ (temporarily disabled)" warnings. This violates Toyota Way "Stop the Line" principle.
**Toyota Way Violation**:
```bash
# â FORBIDDEN PATTERN (found in auto-generated hooks)
# 1. Complexity analysis (TEMPORARILY DISABLED for PARSER-055 commit)
# TODO: Re-enable after fixing cognitive complexity violations
echo -n " Complexity check... "
echo "â ď¸ (temporarily disabled)"
```
**Correct Approach (MANDATORY)**:
1. đ **STOP THE LINE**: If quality gate fails, halt work immediately
2. đ **FIVE WHYS**: Perform root cause analysis (documented in tracking issue)
3. đ§ **FIX VIOLATIONS**: Refactor code to meet quality standards (â¤10 complexity, zero SATD)
4. â
**RE-ENABLE CHECKS**: Use `pmat hooks refresh` to regenerate with checks enabled
5. đ **VERIFY**: Test commit to confirm gates block violations
**When Pre-commit Hook Shows Disabled Checks**:
```bash
# 1. Identify disabled checks
grep "temporarily disabled" .git/hooks/pre-commit
# 2. Document issue (if not already tracked)
# Create docs/issues/PMAT-HOOK-DISABLED-CHECKS-<DATE>.md
# 3. Fix underlying violations
pmat analyze complexity --max-cyclomatic 10 # Find violations
pmat analyze satd # Find SATD comments
# Refactor files until all violations fixed
# 4. Regenerate hooks (after PMAT upstream fix)
pmat hooks refresh
# 5. Verify gates work
git commit # Should block if violations exist
```
**If PMAT Not Yet Fixed** (Temporary Workaround):
1. Create tracking issue in PMAT repository
2. Manually uncomment checks in `.git/hooks/pre-commit`
3. Add header comment: `# TEMPORARY FIX: Re-enabled until PMAT upstream fix`
4. Fix all violations before committing
5. Document in commit message why manual hook edit was necessary
**FORBIDDEN RESPONSES**:
- â "Let's just disable the check for now"
- â "We'll fix it later"
- â "Use `--no-verify` to bypass"
- â "It's only temporary"
**Toyota Way**: Temporary bypasses become permanent. Fix root causes, never mask symptoms.
### DUAL-RELEASE PUBLISHING PROTOCOL
**After version bump**: Publish `ruchy` first, wait 30s, then `ruchy-wasm` (same version)
**Checklist**: Tests pass, CHANGELOG updated, git commit/push, both crates build
## Language Feature Testing Protocol
### CRITICAL REQUIREMENT: Language Compatibility First
**NO CODE CHANGES can be committed without passing language feature compatibility tests.**
#### Compatibility Test Suite (MANDATORY)
```bash
# Run before EVERY commit - no exceptions
make compatibility # Or: cargo test compatibility_report --test compatibility_suite -- --nocapture --ignored
```
**Current Standards (v1.0.0)**:
- â
**One-liners**: 100% (15/15) - Baseline
- â
**Basic Language Features**: 100% (5/5) - Core syntax complete
- â
**Control Flow**: 100% (5/5) - if/match/for/while/pattern-guards
- â
**Data Structures**: 100% (7/7) - Objects functional
- â
**String Operations**: 100% (5/5) - String methods working
- â
**Numeric Operations**: 100% (4/4) - Integer.to_string() + math ops
- â
**Advanced Features**: 100% (4/4) - Pattern guards complete
**Total: 41/41 features working**
### Test Organization (Industry Standard)
```
tests/
âââ compatibility_suite.rs # Main feature compatibility (100% required)
âââ properties/ # Property-based testing (Haskell style)
âââ regression/ # Bug prevention (every GitHub issue)
âââ benchmarks/ # Performance baselines (SQLite style)
```
Language compatibility testing is **GATE 2** in our mandatory pre-commit hooks - more critical than complexity or linting because **language regressions break user code**.
## 15 Native Tool Validation Protocol (LANG-COMP MANDATORY)
**đ¨ SACRED PRINCIPLE: LANG-COMP TESTS ARE DEFECT-FINDING TOOLS**
**Purpose**: Find compiler/interpreter defects, NOT documentation
- **NO WORKAROUNDS EVER**: LANG-COMP test fails â FIX THE COMPILER (Stop The Line)
- **Success**: DEFECT-POW (pow() missing in eval), DEFECT-REF (& operator missing), DEFECT-TUPLE (tuple field access)
- **Sacred Rule**: LANG-COMP failure = Compiler bug
**Tool Support** (TOOL-VALIDATION sprint 2025-10-07):
- **REPL**: `ruchy -e "$(cat file.ruchy)"` for eval validation
- **Notebook**: Accepts file parameter for non-interactive mode
- **WASM**: Validate with simple code (some feature limitations)
### 15-Tool Validation Requirements (MANDATORY - NO EXCEPTIONS)
#### Mandatory Test Pattern (ALL 15 TOOLS - NO SKIPS):
**ALL 15 tools**: check, transpile, -e (eval), lint, compile, run, coverage, runtime --bigo, ast, wasm, provability, property-tests, mutations, fuzz, notebook
**Test Structure**:
- **Naming**: `fn test_langcomp_XXX_YY_feature_name()` (XXX = ticket, YY = section)
- **Pattern**: Invoke all 15 tools via `ruchy_cmd().arg(<tool>).arg(&example).assert().success()`
- **Acceptance**: Test passes ONLY if ALL 15 tools succeed
**Makefile Target**: `make test-lang-comp` runs `cargo test --test lang_comp_suite`
- Tests LANG-COMP-006 (Data Structures), 007 (Type Annotations), 008 (Methods), 009 (Pattern Matching)
- Current: 4 test modules with full 15-tool coverage
**Reference**: docs/SPECIFICATION.md Section 31
## Development Flow (PMAT-Enforced)
**MANDATORY Steps**:
1. **BASELINE**: `pmat quality-gate --fail-on-violation --checks=all`
2. **LOCATE**: Find spec in SPECIFICATION.md + task in docs/execution/roadmap.yaml (MANDATORY ticket)
3. **VERIFY**: Dependencies complete via roadmap DAG
4. **CHECK PATTERNS**: Use GENCHI GENBUTSU - examine existing code patterns (assert_cmd, proptest, cargo-mutants)
5. **IMPLEMENT**: <10 complexity (verify via `pmat analyze complexity`) + Zero SATD
6. **VALIDATE**: `pmat quality-gate` before commit (TDG âĽA-, 85 points)
7. **COMMIT**: With ticket reference (only if PMAT passes)
**TDG Violation Response**: HALT â ANALYZE (`pmat tdg <file> --include-components`) â REFACTOR â VERIFY A-
## Sprint Hygiene Protocol
### Pre-Sprint Cleanup (MANDATORY)
```bash
# Remove all debug binaries before starting sprint
rm -f test_* debug_*
find . -type f -executable -not -path "./target/*" -not -path "./.git/*" -delete
# Verify no large files
find . -type f -size +100M -not -path "./target/*" -not -path "./.git/*"
```
---
**Remember**: Compiler engineering is about systematic transformation, not clever hacks. Every abstraction must have zero runtime cost. Every error must be actionable. Every line of code must justify its complexity budget.
## Documentation Standards
**Professional Documentation Requirements**:
- Use precise, factual language without hyperbole or marketing speak
- Avoid excessive exclamation marks and celebratory language
- State achievements and features objectively
- Focus on technical accuracy over promotional language
- Never create documentation files proactively unless explicitly requested
- Documentation should be maintainable and verifiable