AGENTS.md

# Coding Rules for Gemma 4 (OpenCode Match Optimization)

## CRITICAL EXECUTION POLICY: File Edits & Match Anchors

1. **Keep `oldString` Ultra-Short (1-2 Lines Max):**
   - NEVER pass full code blocks or multi-line paragraphs inside `oldString`.
   - Your `oldString` must contain ONLY 1 to 2 lines of unique code to pinpoint the edit location.
   - Example:
     ```json
     // BAD (Do NOT do this):
     "oldString": "def calculate_total(items):\n    total = 0\n    for item in items:\n        total += item.price\n    return total"

     // GOOD (Do this):
     "oldString": "def calculate_total(items):"
     ```

2. **Always Re-Read First:**
   - Execute `read_file` on the target area immediately before calling an edit. Never edit from distant memory.
   - Copy the exact characters directly from the most recent `read_file` output block.

3. **Fallback Procedure on Match Failure:**
   - If you get "Could not find oldString in the file", STOP immediately.
   - Re-read the file to check line numbers and whitespace.
   - Retry using a single unique line as the `oldString` anchor.

4. **Disambiguate Duplicate Anchors:**
   - If the target `oldString` line appears multiple times in the file (e.g., `return True` or `pass`), expand `oldString` to 2–3 lines *only* until it includes a completely unique structural element (like a specific variable name or function header) to ensure the edit lands in the correct location.

5. **Strict Indentation Mirroring:**
   - When writing the `newString` replacement block, perfectly mirror the exact spaces or tabs observed in the preceding `read_file` output. Do not assume or alter the indentation level unless explicitly instructed to refactor it.