This document describes the current module boundaries after the 2026-02-28 modularization refactor (M1-M6), and where to extend behavior safely.
- CLI and orchestration:
src/main.rssrc/cli.rssrc/app/*
- Runtime command/event pipeline:
src/runtime/schema.rs(contracts)src/runtime/mod.rs+src/runtime/{approvals,sessions,tasks}.rs(actor/execution)src/ui/runtime/*(runtime event to terminal render mapping)
- Core agent loop:
src/agent/mod.rssrc/agent/{events,history,normalization,prompt_aug}.rs
- Model transport:
src/api/client/{mod,auth,retry,transport}.rssrc/api/completions.rssrc/api/responses/{mod,request_builder,response_parser,sse_parser}.rssrc/api/anthropic.rssrc/api/{provider_compat,policy}.rs
- Config/auth/session primitives:
src/config/*src/auth/*src/session.rssrc/tokens.rssrc/types.rssrc/error.rs
- Tooling and execution:
src/tools/mod.rs+ built-in tool modulessrc/tools/execution/*(local/container/ssh execution backends)src/tmux/*(shared tmux session/pane/capture/send/run domain)
- Terminal UI:
src/ui/render.rs+src/ui/terminal/*src/ui/runtime/*src/tui/*(compatibility re-export only)src/repl/*(shared REPL/runtime task-state helpers)
src/
main.rs
cli.rs
app/
agent/
api/
auth/
config/
runtime/
ui/
runtime/
repl/
tools/
execution/
tmux/
tui/
session.rs
tokens.rs
types.rs
error.rs
prompt.rs
preflight.rs
templates/
- Implement
Toolin a newsrc/tools/<name>.rs. - Register it in
src/app/entry.rsviaToolRegistry(build_tools). - If it needs shell/container/ssh/tmux execution, route through
ExecutionContext(src/tools/execution/mod.rs) instead of direct process calls. - Add unit tests in the tool module.
- Keep provider-agnostic request/response normalization in
src/api/completions.rsorsrc/api/responses/*. - Add provider policy checks to
src/api/policy.rs. - Keep auth resolution in
src/api/client/auth.rsand provider-login flow insrc/auth/*. - Add regression fixtures in
src/api/mod.rstests to preserve normalized internal semantics.
- Prefer new runtime events in
src/runtime/schema.rsover direct renderer calls from orchestration. - Handle event-to-UI mapping in
src/ui/runtime/handlers/*. - Keep text styling/layout details in
src/ui/terminal/*. - Keep prompt/task helper state in
src/repl/*.
- Define schema in
src/config/types.rs. - Add defaults in
src/config/defaults.rs. - Wire parsing/resolution in
src/config/{loader,resolve,env}.rs. - Update compiled template
src/templates/buddy.toml. - Add/adjust config characterization tests in
src/config/mod.rs.
- CLI and config compatibility:
- Existing subcommands/flags should remain backward compatible unless a migration is documented.
- Precedence remains: CLI overrides loaded config; env overrides are applied during config resolution.
- Runtime event contract:
- Runtime actor emits structured task/model/tool/session events consumed by REPL and alternate frontends.
- Tool safety:
run_shell/send-keysrequire safety metadata (risk,mutation,privesc,why).- Tool outputs are bounded and wrapped with
harness_timestamp.
- Tmux behavior:
- Managed session defaults to
buddy-<agent.name>. - Managed pane/window target is
sharedfor execution and capture.
- Managed session defaults to
- Fast gate for any architectural edit:
cargo test. - Parser property coverage when touching parsing code:
cargo test --features fuzz-tests. - Live model/protocol smoke checks (explicit, not default):
cargo test --test model_regression -- --ignored --nocapture.