pi-red-green
v0.2.2
Published
A Pi extension that enforces Test-Driven Development (RED-GREEN-REFACTOR) discipline during agent coding sessions.
Maintainers
Readme
pi-red-green
TDD enforcement for Pi coding agent sessions. Forces agents to follow the RED-GREEN-REFACTOR cycle: write failing tests first, implement minimally, then refactor.
Installation
pi install npm:pi-red-greenUsage
Start a TDD session
/tdd Add user authenticationThis enters RED phase. The agent's system prompt is modified to enforce writing failing tests first.
Check status
/tdd-statusShows current phase, task, file history, test results, and staleness.
End a TDD session
/tdd offPhase cycle
- RED: Write failing tests. Agent is blocked from writing implementation.
- GREEN: Tests are failing as expected. Write the simplest code to pass.
- REFACTOR: Tests pass. Clean up without adding behavior.
- COMPLETE: Cycle done. Start a new task or deactivate.
Phase transitions happen automatically when test runner output is detected (vitest, jest, pytest, go test, cargo test, etc).
LLM Tools
The extension registers three tools the agent can call:
| Tool | Description |
|------|-------------|
| tdd_status | Returns current phase, task, file history, test results |
| tdd_advance | Manually advance to next phase (escape hatch) |
| tdd_reset | Reset TDD state to idle |
Configuration
Create ~/.pi/red-green/config.json to override defaults:
{
"injection_mode": "active-only",
"ordering_enforcement": "warn",
"auto_advance": true,
"coverage_threshold": 80,
"coverage_enabled": false,
"test_file_patterns": {
"typescript": ["**/*.test.ts", "**/*.spec.ts"],
"python": ["**/test_*.py", "**/*_test.py"],
"go": ["**/*_test.go"],
"rust": ["**/tests/**/*.rs"],
"java": ["**/*Test.java", "**/*Spec.java"],
"php": ["**/*Test.php"]
},
"test_runner_patterns": [
"vitest", "jest", "pytest", "go test", "cargo test",
"phpunit", "mix test", "npm test"
]
}Injection modes
active-only(default): Only inject TDD prompts when/tddis activealways: Inject TDD guidance on every turn, nudge when idlenudge: Inject gentle "consider writing tests first" remindersoff: No injection
Ordering enforcement
warn(default): Warn when implementation files are edited before test filesstrict: Instruct the agent to delete implementation and start over with testsoff: No enforcement
Storage
Runtime data lives under ~/.pi/red-green/:
~/.pi/red-green/
config.json # User config overrides
state.json # Current TDD state (survives session restarts)
history.jsonl # Completed TDD cyclesLicense
MIT
