# Implementation Plan: MMA Core Engine Implementation

## Phase 1: Track 1 - The Memory Foundations (AST Parser)
- [x] Task: Dependency Setup (8fb75cc)
    - [x] Add `tree-sitter` and `tree-sitter-python` to `pyproject.toml` / `requirements.txt` (8fb75cc)
- [ ] Task: Core Parser Class
    - [ ] Create `ASTParser` in `file_cache.py`
- [ ] Task: Skeleton View Extraction
    - [ ] Write query to extract `function_definition` and `class_definition`
    - [ ] Replace bodies with `pass`, keep type hints and signatures
- [ ] Task: Curated View Extraction
    - [ ] Keep class structures, module docstrings
    - [ ] Preserve `@core_logic` or `# [HOT]` function bodies, hide others

## Phase 2: Track 2 - State Machine & Data Structures
- [ ] Task: The Dataclasses
    - [ ] Create `models.py` defining `Ticket` and `Track`
- [ ] Task: Worker Context Definition
    - [ ] Define `WorkerContext` holding `Ticket` ID, model config, and ephemeral messages
- [ ] Task: State Mutator Methods
    - [ ] Implement `ticket.mark_blocked()`, `ticket.mark_complete()`, `track.get_executable_tickets()`

## Phase 3: Track 3 - The Linear Orchestrator & Execution Clutch
- [ ] Task: The Engine Core
    - [ ] Create `multi_agent_conductor.py` containing `ConductorEngine` and `run_worker_lifecycle`
- [ ] Task: Context Injection
    - [ ] Format context strings using `file_cache.py` target AST views
- [ ] Task: The HITL Execution Clutch
    - [ ] Before executing `write_file`/`shell_runner.py` tools in step-mode, prompt user for confirmation
    - [ ] Provide functionality to mutate the history JSON before resuming execution

## Phase 4: Track 4 - Tier 4 QA Interception
- [ ] Task: The Interceptor Loop
    - [ ] Catch `subprocess.run()` execution errors inside `shell_runner.py`
- [ ] Task: Tier 4 Instantiation
    - [ ] Make a secondary API call to `default_cheap` model passing `stderr` and snippet
- [ ] Task: Payload Formatting
    - [ ] Inject the 20-word fix summary into the Tier 3 worker history

## Phase 5: Track 5 - UI Decoupling & Tier 1/2 Routing (The Final Boss)
- [ ] Task: The Event Bus
    - [ ] Implement an `asyncio.Queue` linking GUI actions to the backend engine
- [ ] Task: Tier 1 & 2 System Prompts
    - [ ] Create structured system prompts for Epic routing and Ticket creation
- [ ] Task: The Dispatcher Loop
    - [ ] Read Tier 2 JSON flat-lists, construct Tickets, execute Stub resolution paths
- [ ] Task: UI Component Update
    - [ ] Refactor `gui_2.py` to push `UserRequestEvent` instead of blocking on API generation