Docs
Lifecycle phases
TRW organizes work into six phases: research, plan, implement, validate, review, deliver. Ceremony tiers select which phases are mandatory, but validation is never skipped. Phase exit criteria guide the work and warn by default; machine-enforced build and review gates are evaluated at delivery.
Two rules to remember
Every phase has exit criteria
The lifecycle says what evidence should exist before work advances. Phase progression warns and proceeds by default unless strict mode is enabled.
Delivery is the hard boundary
For coding, RCA, and eval tasks, delivery requires a passing recorded build check or one of the explicit exception paths.
Phase overview
Skim this table first. Then read the phase sections below when you want the mechanics and examples.
ResearchInspect
- Purpose
- Load prior learnings, audit codebase, gather evidence
- Key tools
trw_session_starttrw_recall- Exit criteria
- Findings registered, relevant learnings loaded
PlanInspect
- Purpose
- Design approach, identify dependencies, create execution plan
- Key tools
trw_inittrw_prd_create- Exit criteria
- Plan recorded and ready for implementation
ImplementInspect
- Purpose
- Execute the plan with periodic checkpoints
- Key tools
trw_checkpoint- Exit criteria
- Code written, checkpoints saved
ValidateInspect
- Purpose
- Run tests and type-check, verify coverage meets thresholds
- Key tools
trw_build_check- Exit criteria
- Build passes, coverage met
ReviewInspect
- Purpose
- Independent quality audit (DRY/KISS/SOLID), fix gaps, record discoveries
- Key tools
trw_reviewtrw_learn- Exit criteria
- Review passes or issues resolved
DeliverInspect
- Purpose
- Sync artifacts, refresh client instruction file, close run
- Key tools
trw_delivertrw_instructions_sync- Exit criteria
- Learnings persisted, run closed
| Phase | Purpose | Key tools | Exit criteria |
|---|---|---|---|
| Research | Load prior learnings, audit codebase, gather evidence | trw_session_starttrw_recall | Findings registered, relevant learnings loaded |
| Plan | Design approach, identify dependencies, create execution plan | trw_inittrw_prd_create | Plan recorded and ready for implementation |
| Implement | Execute the plan with periodic checkpoints | trw_checkpoint | Code written, checkpoints saved |
| Validate | Run tests and type-check, verify coverage meets thresholds | trw_build_check | Build passes, coverage met |
| Review | Independent quality audit (DRY/KISS/SOLID), fix gaps, record discoveries | trw_reviewtrw_learn | Review passes or issues resolved |
| Deliver | Sync artifacts, refresh client instruction file, close run | trw_delivertrw_instructions_sync | Learnings persisted, run closed |
Research
trw_session_start is the first TRW action in every session. It returns bounded, relevant learning candidates and checks for interrupted runs. Treat recalled context as a lead to verify against the current repository, not as current truth.
COMPREHENSIVE work includes a distinct Research phase. MINIMAL and STANDARD profiles skip that phase, but can still use trw_recall for a focused lookup before changing unfamiliar code.
trw_session_start()
# -> Loaded 47 learnings (12 high-impact)
# -> Recovered active run: sprint-52-auth-refactor
trw_recall("rate limiting middleware")
# -> 3 relevant learnings foundExit criteria: Findings registered, relevant learnings loaded.
Plan
The AI designs its approach before writing code. For larger tasks, it calls trw_init to create a tracked run with a named directory for checkpoints. For features that need requirements, trw_prd_create generates a structured PRD.
MINIMAL work skips the Plan phase. STANDARD and COMPREHENSIVE work should record an explicit plan that identifies files to change, dependencies, proof, and the order of operations.
trw_init("auth-middleware-refactor")
# -> Run created: .trw/runs/auth-middleware-refactor/
# -> Phase: PLANExit criteria: Plan recorded and ready for implementation.
Implement
The AI writes code and saves periodic progress records via trw_checkpoint. A checkpoint preserves a resume directive and the current milestone state. If the context window compacts mid-session, a later session can recover that record instead of relying only on conversation history.
# ... write code ...
trw_checkpoint("rate limiter middleware complete, tests next")
# -> Checkpoint saved: 3/5 tasks done
# ... write more code ...
trw_checkpoint("all middleware tests passing")
# -> Checkpoint saved: 5/5 tasks doneExit criteria: Code written, checkpoints saved.
Validate
Run your project-native verification first, then call trw_build_check to record the evidence: command scope, pass/fail status, failure details, static-check state, and coverage percentages when measured. Phase discipline says to resolve failures before review; the default runtime warns rather than hard-blocking phase progression. The hard coding gate is evaluated at delivery.
pytest tests/ && mypy src/
# -> validation commands pass locally
trw_build_check(
tests_passed=True,
test_count=247,
failure_count=0,
static_checks_clean=True,
coverage_pct=94,
scope="full",
)
# -> recorded evidence: 247 passed, 0 failed
# -> static checks: clean
# -> coverage: 94%Exit criteria: Build passes, coverage met.
Review
Review the actual diff for correctness, security, maintainability, and requirement drift. Independence depends on who performed the review: use a scoped helper or cross-model mode when independent evidence matters. Record reviewed findings via trw_learn so future sessions benefit from what this session found.
trw_review(
findings=[{
"category": "maintainability",
"severity": "medium",
"description": "Duplicated validation logic in auth.py and api_keys.py",
}],
review_completed=True,
)
# -> substantive manual review recorded with 1 finding
trw_learn(
"auth validation helpers should be shared",
"Both auth.py and api_keys.py independently validate API key format..."
)
# -> Learning recorded (impact: 0.7)Exit criteria: Review passes or issues resolved.
Deliver
trw_deliver closes the run after checking the configured delivery policy. It persists delivery state and session maintenance data. Learnings remain in the memory store and surface through session start or recall; delivery does not silently copy them into client instruction files.
trw_deliver()
# -> Build gate: PASS (247 tests, mypy clean)
# -> Delivery state persisted
# -> Run closed: auth-middleware-refactorExit criteria: Learnings persisted, run closed.
Adaptive ceremony
Not every task needs all six phases. TRW scores task complexity and assigns a ceremony tier. Bounded fixes use a smaller phase set. Architecture and other high-risk changes use the complete lifecycle. The system scales process to match the risk of the change.
MINIMALInspect
- When
- Quick fixes, typos, config changes
- Phases used
- Implement, Validate, Deliver
- Phases skipped
- Research, Plan, Review
STANDARDInspect
- When
- Bug fixes, small features, refactors
- Phases used
- Plan, Implement, Validate, Review, Deliver
- Phases skipped
- Research
COMPREHENSIVEInspect
- When
- Architecture, cross-package, or P0/P1 risk
- Phases used
- All 6 phases
- Phases skipped
- None
| Tier | When | Phases used | Phases skipped |
|---|---|---|---|
MINIMAL | Quick fixes, typos, config changes | Implement, Validate, Deliver | Research, Plan, Review |
STANDARD | Bug fixes, small features, refactors | Plan, Implement, Validate, Review, Deliver | Research |
COMPREHENSIVE | Architecture, cross-package, or P0/P1 risk | All 6 phases | None |
TRW classifies the tier from scope, novelty, cross-cutting or architectural impact, external integrations, refactor depth, and explicit security, migration, or unfamiliar-code risk.
Bounded fix vs comprehensive change
A genuinely bounded fix can begin at implementation. Architecture, cross-package, and other high-risk changes use all six phases. Scope and risk decide the workflow, not whether the request is labeled a feature or a fix.
trw_session_start()
# load prior context
# -> fix the bug
pytest tests/test_target.py
trw_build_check(tests_passed=True, test_count=1, failure_count=0, scope="targeted")
trw_deliver()
# minimal ceremony: implement -> validate -> delivertrw_session_start() # Research
trw_recall("auth")
trw_init("feature") # Plan
trw_checkpoint(...) # Implement
trw_build_check(tests_passed=True, test_count=247, failure_count=0, scope="full") # Validate
trw_review(findings=[...], review_completed=True) # Review actual diff
trw_learn(...)
trw_deliver() # DeliverPhase reversion
Phases are not strictly linear. When later evidence reveals a problem, return to the earlier phase that can resolve it instead of narrating progress past the failure.
- Validate fails - revert to Implement. Fix the code, then re-validate.
- Review finds design issues - revert to Plan. Rethink the approach, then re-implement.
- Implementation hits unknowns - revert to Research. Gather more context, then re-plan.
Hooks
Hooks are optional client adapters. When a client exposes compatible events, they can add reminders, checkpoints, or bounded blocking; correctness remains in TRW tools and middleware when no hook fires.
- Session start - may prompt or invoke startup behavior when the client exposes a compatible event
- Pre-compaction - can request a checkpoint on clients that expose a pre-compaction event
- Phase gates - surface discipline warnings; strict blocking is configuration- and adapter-dependent
- Session end - can warn when delivery was skipped; the MCP delivery tool remains canonical
Where to go next
Continue into requirements if you want the spec layer that sits immediately after workflow understanding. Continue into tools and hooks if you want the mechanics that make those phase boundaries real in day-to-day use.