src/parser/README.md
See also docs/contributing/TECHNICAL.md for the full architecture overview
The parser infrastructure provides a unified, three-tier parsing system for tool outputs with graceful degradation:
┌─────────────────────────────────────────────────────────┐
│ ToolCommand Builder │
│ Command::new("vitest").arg("--reporter=json") │
└─────────────────────┬───────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────┐
│ OutputParser<T> Trait │
│ parse() → ParseResult<T> │
│ ├─ Full(T) - Tier 1: Complete JSON parse │
│ ├─ Degraded(T, warn) - Tier 2: Partial with warnings │
│ └─ Passthrough(str) - Tier 3: Truncated raw output │
└─────────────────────┬───────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────┐
│ Canonical Types │
│ TestResult, LintResult, DependencyState, BuildOutput │
└─────────────────────┬───────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────┐
│ TokenFormatter Trait │
│ format_compact() / format_verbose() / format_ultra() │
└─────────────────────────────────────────────────────────┘
OutputParser for a tool — try JSON (Tier 1), fall back to regex (Tier 2), then passthrough (Tier 3)Parser::parse(), then data.format(FormatMode::from_verbosity(verbose))[RTK:DEGRADED] in verbose mode, [RTK:PASSTHROUGH] on full fallbackSee src/parser/types.rs for the OutputParser trait and ParseResult enum.
For test runners (vitest, playwright, jest, etc.)
total, passed, failed, skipped, duration_ms, failuresFor linters (eslint, biome, tsc, etc.)
total_files, files_with_issues, total_issues, errors, warnings, issuesFor package managers (pnpm, npm, cargo, etc.)
total_packages, outdated_count, dependenciesFor build tools (next, webpack, vite, cargo, etc.)
success, duration_ms, bundles, routes, warnings, errorsJsonError: Line/column context for debuggingPatternMismatch: Regex pattern failedPartialParse: Some fields missingInvalidFormat: Unexpected structureMissingField: Required field absentVersionMismatch: Tool version incompatibleEmptyOutput: No data to parse[RTK:DEGRADED] vitest parser: JSON parse failed at line 42, using regex fallback
[RTK:PASSTHROUGH] playwright parser: Pattern mismatch, showing truncated output
Replace direct filter_*_output() calls with Parser::parse() + FormatMode. Key change: add --reporter=json flag injection, match on ParseResult (Full/Degraded/Passthrough), format with data.format(mode). Degraded and Passthrough tiers handle tool version changes gracefully.
Run cargo test parser::tests. Each parser should have tier validation tests: assert result.tier() == 1 for valid JSON fixtures, tier() == 2 for regex fallback inputs, and tier() == 3 for completely malformed output.
parse_tier, format_modertk parse-health command