# Implementation Plan: Manual Skeleton Context Injection (manual_skeleton_injection_20260306)

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

## Phase 1: UI Foundation
Focus: Add file injection button and state

- [ ] Task 1.1: Initialize MMA Environment
    - Run `activate_skill mma-orchestrator` before starting

- [ ] Task 1.2: Add injection state variables
    - WHERE: `src/gui_2.py` `App.__init__`
    - WHAT: State for injection UI
    - HOW:
      ```python
      self._inject_file_path: str = ""
      self._inject_mode: str = "skeleton"  # "skeleton" | "full"
      self._inject_preview: str = ""
      self._show_inject_modal: bool = False
      ```
    - CODE STYLE: 1-space indentation

- [ ] Task 1.3: Add inject button to discussion panel
    - WHERE: `src/gui_2.py` discussion panel
    - WHAT: Button to open injection modal
    - HOW:
      ```python
      if imgui.button("Inject File"):
       self._show_inject_modal = True
      ```

## Phase 2: File Selection
Focus: File picker and path validation

- [ ] Task 2.1: Create file selection modal
    - WHERE: `src/gui_2.py`
    - WHAT: Modal for selecting project file
    - HOW:
      ```python
      if self._show_inject_modal:
       imgui.open_popup("Inject File")
      if imgui.begin_popup_modal("Inject File"):
       # File list from project files
       for file_path in self.project.get("files", {}).get("paths", []):
        if imgui.selectable(file_path, self._inject_file_path == file_path):
         self._inject_file_path = file_path
         self._update_inject_preview()
       imgui.end_popup()
      ```

- [ ] Task 2.2: Validate selected path
    - WHERE: `src/gui_2.py`
    - WHAT: Ensure path is within project
    - HOW: Check against `files.base_dir`

## Phase 3: Preview Generation
Focus: Generate and display skeleton/full preview

- [ ] Task 3.1: Implement preview update function
    - WHERE: `src/gui_2.py`
    - WHAT: Generate preview based on mode
    - HOW:
      ```python
      def _update_inject_preview(self) -> None:
       if not self._inject_file_path:
        self._inject_preview = ""
        return
       base_dir = self.project.get("files", {}).get("base_dir", ".")
       full_path = Path(base_dir) / self._inject_file_path
       try:
        content = full_path.read_text(encoding="utf-8")
        if self._inject_mode == "skeleton":
         parser = ASTParser("python")
         self._inject_preview = parser.get_skeleton(content)
        else:
         self._inject_preview = content
        # Truncate to 500 lines
        lines = self._inject_preview.split("\n")[:500]
        self._inject_preview = "\n".join(lines)
        if len(lines) >= 500:
         self._inject_preview += "\n... (truncated)"
       except Exception as e:
        self._inject_preview = f"Error reading file: {e}"
      ```

- [ ] Task 3.2: Add mode toggle
    - WHERE: `src/gui_2.py` inject modal
    - WHAT: Radio buttons for skeleton/full
    - HOW:
      ```python
      if imgui.radio_button("Skeleton", self._inject_mode == "skeleton"):
       self._inject_mode = "skeleton"
       self._update_inject_preview()
      imgui.same_line()
      if imgui.radio_button("Full File", self._inject_mode == "full"):
       self._inject_mode = "full"
       self._update_inject_preview()
      ```

- [ ] Task 3.3: Display preview
    - WHERE: `src/gui_2.py` inject modal
    - WHAT: Scrollable preview area
    - HOW:
      ```python
      imgui.begin_child("preview", height=300)
      imgui.text_wrapped(self._inject_preview)
      imgui.end_child()
      ```

## Phase 4: Inject Action
Focus: Append to discussion input

- [ ] Task 4.1: Implement inject button
    - WHERE: `src/gui_2.py` inject modal
    - WHAT: Button to inject content
    - HOW:
      ```python
      if imgui.button("Inject"):
       formatted = f"\n## File: {self._inject_file_path}\n```python\n{self._inject_preview}\n```\n"
       self.ui_input_text += formatted
       self._show_inject_modal = False
       imgui.close_current_popup()
      imgui.same_line()
      if imgui.button("Cancel"):
       self._show_inject_modal = False
       imgui.close_current_popup()
      ```

## Phase 5: Testing
Focus: Verify all functionality

- [ ] Task 5.1: Write unit tests
    - WHERE: `tests/test_skeleton_injection.py` (new file)
    - WHAT: Test preview generation, truncation
    - HOW: Create test files, verify skeleton output

- [ ] Task 5.2: Conductor - Phase Verification
    - Run: `uv run pytest tests/test_skeleton_injection.py -v`
    - Manual: Verify inject modal works in GUI
    # Footer
    imgui.end_table()
