# Implementation Plan: Native Orchestrator (native_orchestrator_20260306)

> **Reference:** [Spec](./spec.md) | [Architecture Guide](../../../docs/guide_architecture.md)

## Phase 1: Plan File Operations
Focus: Native plan.md read/write

- [ ] Task 1.1: Initialize MMA Environment
- [ ] Task 1.2: Implement read_plan function
    - WHERE: `src/orchestrator_pm.py` or new `src/native_orchestrator.py`
    - WHAT: Parse plan.md content
    - HOW:
      ```python
      def read_plan(track_id: str, base_dir: str = ".") -> str:
       plan_path = Path(base_dir) / "conductor" / "tracks" / track_id / "plan.md"
       if not plan_path.exists():
        return ""
       return plan_path.read_text(encoding="utf-8")
      ```

- [ ] Task 1.3: Implement write_plan function
    - WHERE: Same as above
    - WHAT: Write plan.md content
    - HOW:
      ```python
      def write_plan(track_id: str, content: str, base_dir: str = ".") -> None:
       plan_path = Path(base_dir) / "conductor" / "tracks" / track_id / "plan.md"
       plan_path.parent.mkdir(parents=True, exist_ok=True)
       plan_path.write_text(content, encoding="utf-8")
      ```

- [ ] Task 1.4: Parse task checkboxes
    - WHERE: Same as above
    - WHAT: Extract task status from plan
    - HOW:
      ```python
      def parse_plan_tasks(content: str) -> list[dict]:
       tasks = []
       for line in content.split("\n"):
        if line.strip().startswith("- ["):
         checked = "[x]" in line
         tasks.append({"text": line, "completed": checked})
       return tasks
      ```

## Phase 2: Metadata Operations
Focus: Native metadata.json management

- [ ] Task 2.1: Implement read_metadata
    - WHERE: Same as above
    - HOW:
      ```python
      def read_metadata(track_id: str, base_dir: str = ".") -> dict:
       meta_path = Path(base_dir) / "conductor" / "tracks" / track_id / "metadata.json"
       if not meta_path.exists():
        return {}
       return json.loads(meta_path.read_text(encoding="utf-8"))
      ```

- [ ] Task 2.2: Implement write_metadata
    - WHERE: Same as above
    - HOW:
      ```python
      def write_metadata(track_id: str, data: dict, base_dir: str = ".") -> None:
       meta_path = Path(base_dir) / "conductor" / "tracks" / track_id / "metadata.json"
       meta_path.parent.mkdir(parents=True, exist_ok=True)
       meta_path.write_text(json.dumps(data, indent=2), encoding="utf-8")
      ```

## Phase 3: In-Process Tier Delegation
Focus: Replace subprocess calls with direct function calls

- [ ] Task 3.1: Create NativeOrchestrator class
    - WHERE: `src/native_orchestrator.py` (new file)
    - WHAT: Class with tier methods
    - HOW:
      ```python
      class NativeOrchestrator:
       def __init__(self, base_dir: str = "."):
        self.base_dir = Path(base_dir)
       
       def generate_tickets(self, brief: str) -> list[Ticket]:
        return conductor_tech_lead.generate_tickets(brief, ...)
       
       def execute_ticket(self, ticket: Ticket, context: str) -> str:
        return ai_client.send(context, ticket.description, ...)
       
       def analyze_error(self, error: str) -> str:
        return ai_client.run_tier4_analysis(error)
      ```

- [ ] Task 3.2: Integrate with ConductorEngine
    - WHERE: `src/multi_agent_conductor.py`
    - WHAT: Use NativeOrchestrator instead of subprocess
    - HOW: Import and call methods directly

## Phase 4: CLI Fallback
Focus: Maintain mma_exec.py compatibility

- [ ] Task 4.1: Update mma_exec.py to use NativeOrchestrator
    - WHERE: `scripts/mma_exec.py`
    - WHAT: Thin wrapper around native module
    - HOW: Import NativeOrchestrator and call methods

## Phase 5: Testing
- [ ] Task 5.1: Write unit tests
- [ ] Task 5.2: Conductor - Phase Verification
