# Implementation Plan: On-Demand Definition Lookup (on_demand_def_lookup_20260306)

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

## Phase 1: Symbol Parsing [checkpoint: f392aa3]
Focus: Parse @symbol syntax from user input

- [x] Task 1.1: Initialize MMA Environment
- [x] Task 1.2: Implement @symbol regex parser (a0a9d00)
    - WHERE: `src/gui_2.py` in `_send_callback()`
    - WHAT: Extract @SymbolName patterns
    - HOW:
      ```python
      import re
      def parse_symbols(text: str) -> list[str]:
       return re.findall(r'@(\w+(?:\.\w+)*)', text)
      ```

## Phase 2: Definition Retrieval
Focus: Use existing MCP tool to get definitions

- [x] Task 2.1: Integrate py_get_definition (c6f9dc8)
    - WHERE: `src/gui_2.py`
    - WHAT: Call MCP tool for each symbol
    - HOW:
      ```python
      from src import mcp_client
      def get_symbol_definition(symbol: str, files: list[str]) -> tuple[str, str] | None:
       for file_path in files:
        result = mcp_client.py_get_definition(file_path, symbol)
        if result and "not found" not in result.lower():
         return (file_path, result)
       return None
      ```

## Phase 3: Inline Display [checkpoint: 7ea833e]
Focus: Display definition in discussion

- [x] Task 3.1: Inject definition as context (7ea833e)

## Phase 4: Click Navigation [checkpoint: 7ea833e]
Focus: Allow clicking definition to open file

- [x] Task 4.1: Store file/line metadata with definition (7ea833e)
- [x] Task 4.2: Add click handler (7ea833e)

## Phase 5: Testing [checkpoint: 7ea833e]
- [x] Task 5.1: Write unit tests for parsing (7ea833e)
- [x] Task 5.2: Conductor - Phase Verification (7ea833e)
