# agent-doc
Interactive document sessions with AI agents.
## Conventions
- Use `clap` derive for CLI argument parsing
- Use `serde` derive for all data types
- Use `serde_yaml` for frontmatter parsing
- Use `similar` crate for diffing (pure Rust, no shell `diff` dependency)
- Use `serde_json` for agent response parsing
- Use `std::process::Command` for git operations (not `git2`)
- Use `toml + serde` for config file parsing
- No async — sequential per-run
- Use `anyhow` for application errors
## Module Layout
Use this layout when adding modules. Add new subcommands in their own file, wired through `main.rs`.
```
src/
main.rs # CLI entry point (clap derive)
submit.rs # Core loop: diff, send, merge-safe write, snapshot, git
init.rs # Scaffold session document
reset.rs # Clear session + snapshot
diff.rs # Preview diff (dry run)
clean.rs # Squash git history
frontmatter.rs # YAML frontmatter parse/write
snapshot.rs # Snapshot path/read/write
git.rs # Commit, branch, squash
config.rs # Global config (~/.config/agent-doc/config.toml)
sessions.rs # Session registry (sessions.json) + Tmux struct
route.rs # Route /agent-doc commands to correct tmux pane
start.rs # Start Claude session inside tmux pane
agent/
mod.rs # Agent trait
claude.rs # Claude backend
audit_docs.rs # Audit instruction files (via instruction-files crate)
```
## Agent Backend Contract
Each agent backend implements: take a prompt string, return (response_text, session_id).
The prompt includes the diff and full document. The agent backend handles CLI
invocation, JSON parsing, and session flags.