Skip to main content

Code Quality Loop

warning

This page is a retained loop design. Its named template and prompt are not currently tracked under .agents/tasks; restore and review those artifacts before attempting to run it.

Overview

The code quality loop runs scoped static analysis, triages findings by severity, applies safe fixes, and verifies no regressions were introduced. It never changes observable behavior -- all fixes are mechanical (type errors, unused imports, dead code).

Template: prd-code-quality.template.json Prompt: PROMPT_code-quality.md Stories: 6 (Q00-Q05) Slash command: /code-quality-loop-bootstrap [scope]

Story Breakdown

IDTitleDepends OnOutput
Q00Preflight: load and lock effective scope--.ralph/scope-effective.md
Q01Baseline: run scoped quality checksQ00.ralph/quality-findings.md
Q02Triage: rank and plan remediationQ01.ralph/quality-plan.md
Q03Remediation: apply critical/high fixesQ02Modified source files
Q04Verification: rerun checks and testsQ03.ralph/quality-report.md
Q05Handoff: publish quality reportQ04.ralph/quality-report.md (final)

Flow

What the Loop Fixes

Safe to FixDeferred to Human
TypeScript type errors in scopeFunction signature changes
Unused imports and variablesComplex cascading type errors
Unreachable / dead codeChanges that affect public behavior
Missing type annotations on exportsArchitectural refactors
ESLint violations (if configured)Performance improvements

Finding Severity

SeverityExamples
CriticalTypeScript compile error, broken import, undefined reference
HighUnhandled promise, missing null check on user input, deprecated API
MediumUnused variables, unreachable code, console.log in production
LowStyle preferences, naming conventions, minor readability

Q03 addresses critical and high findings. Medium and low are addressed if capacity allows.

Quality Gates

  • Read .ralph/intake/current-guidelines.json at the start of every story
  • Never modify files outside scope.include except tracking artifacts
  • Preserve public behavior unless constraints explicitly allow changes
  • Do not apply fixes before findings are captured in quality-findings.md
  • Do not mark remediation complete without post-fix validation evidence
  • For touched files, run the narrowest available lint/test checks first
  • Document before/after counts by severity in quality-report.md

Artifacts

FileWritten ByPurpose
.ralph/scope-effective.mdQ00Expanded include/exclude paths with hard guards
.ralph/quality-findings.mdQ01Normalized findings (severity, rule, file, fix hint)
.ralph/quality-plan.mdQ02Ordered remediation batches with deferred items
.ralph/quality-report.mdQ04-Q05Before/after counts, residual risk, next steps

Run Command

# Bootstrap with a specific scope:
/code-quality-loop-bootstrap src/auth/**

# Then run Ralph:
PROMPT_BUILD=.agents/ralph/PROMPT_code-quality.md \
PRD_PATH=.agents/tasks/prd-active.json \
bash .agents/ralph/loop.sh