# Runtime source agent guide
## Ownership
`lib.rs` declares runtime boundaries. The binary in `bin/magi-code.rs` delegates to the library entrypoint; CLI parsing is not a separate execution engine.
## Cross-module navigation
| Command selection and launch validation | `cli/`, `commands/` |
| Cargo updates, version checks, process bounds and restart | `updates.rs`, `updates/`; idle TUI handoff: `tui/controller/app/updates.rs` |
| Provider selection for a turn | `agent/runner/preparation.rs` |
| Provider validation and construction | `providers/factory.rs` |
| Frontend protocol, adapters, streamed turn coordination | `service/` |
| Session-title provider/background orchestration | `session_titles.rs` |
| Durable title recording | `sessions/` |
| Session-summary observation, provider work, and separate checkpoint log | `summarizer.rs`, `summarizer/`; display only: `tui/state/summary.rs` |
| Offline measurement facade and implementation | `tool_output_measurement.rs`, `tool_output_measurement/` |
| Shared cancellation and lexical paths | `cancellation.rs`, `path_utils.rs` |
| Display events versus display projection | `output/`, `rendering/`, `tui/` |
## Local conventions
- The intentional public surface is documented in `lib.rs`: process entrypoints, config/context/session modules, and shared message, usage, and thinking types. Keep changes to those exports explicit.
- `PersistentService` is an intentional transport-independent public adapter boundary. It owns the persistent coordinator thread; `service/unix.rs` adds the private Unix daemon adapter and `daemon` CLI commands.
- CLI code chooses Mission Control (default), application service, or maintenance subcommands and validates flags; provider, tool, auth, session, and TUI policy stays with its owner. There is no text REPL or print conversation path.
- Keep extracted implementations behind their owning facade, including `agent/runner/`, `config/settings/`, and tool-output measurement children.
- Keep shared runtime helpers neutral. Avoid dependencies from cancellation/path utilities back into an individual subsystem.
- Keep title-provider work outside the storage facade; orchestration delegates durable recording to `sessions/`.
- The application-service dispatcher is transport-neutral. Adapters inject transport capabilities and own writing outbound messages; its local guide defines request-reservation lifetimes.
- Do not move durable or security-sensitive behavior into display modules, or widen filesystem/process access from a convenience helper.