# Agent runtime guide
## Scope
Owns run preparation, prompt/replay projection, provider turns, tools, and continuation.
## Where to look
| Session and request orchestration | `mod.rs`, `runner.rs` |
| Selection, auth, tools, hooks, title setup | `runner/preparation.rs` |
| Preflight and continuation compaction | `runner/auto_compaction.rs` |
| Stream acceptance and turn state | `provider_stream.rs`, `turn_state.rs` |
| Tool records and continuation | `tool_lifecycle.rs`, `tool_continuation.rs`, `session_persistence.rs` |
| Prompt additions and directory instructions | `prompt.rs`, `prompt_injections.rs`, `subdir_instructions.rs` |
| Steering, recovery, response rules | `steering.rs`, `recovery.rs`, `ttsr.rs` |
| Provider-facing tool summaries | `tool_output_compression.rs` |
## Local rules
- Resolve the normal-run provider in preparation; construct it through `../providers/factory.rs`. Keep automatic compaction around the existing request loop.
- Stream acceptance and terminal partial-text rules are defined in the root manual companion. Apply them at `provider_stream.rs` and `session_persistence.rs`, not in renderers.
- Keep steering delivery at continuation boundaries; do not acknowledge queued input before its required persistence succeeds.
- Keep tool call/result identities and order through retries and continuation. Flush assistant completion before entering the tool phase.
- Persistent service sinks require title-worker cleanup before returning, including cancellation. Keep that wait on the turn worker so its session writer lease cannot be released while a title task still writes.
- Tool-output compression changes provider-facing results, not raw local output. Keep its command recognition conservative.
## Verification landmarks
- `tests/session_replay.rs`, `tests/cancellation.rs`, and `tests/tools_continuation.rs` cover ordering and interrupted turns.
- Preparation and automatic-compaction coverage also lives inside `runner.rs`; do not assume `tests/` contains all run tests.