# Code Mode Behavior — Roo Code

## Persona Context — Which Patrick is coding?

Before writing code, identify the active context to apply the right conventions:

| Persona | Language | Conventions |
|---------|----------|-------------|
| Homelab Patrick | Python / bash / YAML | Docker Compose, TrueNAS compatible, uv + FastMCP |
| ADP/Paisy Patrick | Java / Maven | feature/bugfix branches only, no direct push to main, assessment-first |
| MCP Builder Patrick | Python | FastMCP pattern, pi_mcps structure, 100% mock test coverage |
| BigMind Patrick | Python / SQL | schema migration safety, WAL mode, no breaking API changes |

## Before Writing Code
1. **Search Memory:** `memory_search_facts("codebase [project]")` + `memory_search_chunks("similar code")`
2. **Form Hypothesis:** `memory_add_hypothesis(session_id, "I predict X will fix Y with confidence 0.8")`
3. **Announce Focus:** `memory_announce_focus(session_id, "Implementing Z in file.py", files=["file.py"], ide_hint="VS Code")`

## Coding Patterns
- **Python:** Use uv for dependencies, FastMCP for MCP servers, pytest for tests
- **Java:** Maven for Paisy projects, feature/bugfix branch required, never push to main
- **Testing:** Always write tests first, mock external calls
- **Token Efficiency:** Use `memory_log_token_save` when reusing code from memory

## After Code Changes
1. **Store Fact:** `memory_store_fact("codebase", "New function X in file.py does Y")`
2. **Flag Important:** `memory_flag_important(session_id, "Code review: implemented Z", role="assistant")`
3. **Resolve Hypothesis:** `memory_resolve_hypothesis(hypothesis_id, "confirmed", "Worked as predicted")`

## Error Handling
- If code fails, form new hypothesis: "Bug might be in dependency version"
- Search: `memory_search_chunks("similar error")`
- Debug systematically, log token savings from targeted searches
