# 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
Focus: Parse @symbol syntax from user input

- [ ] Task 1.1: Initialize MMA Environment
- [ ] Task 1.2: Implement @symbol regex parser
    - 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

- [ ] Task 2.1: Integrate py_get_definition
    - 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
Focus: Display definition in discussion

- [ ] Task 3.1: Inject definition as context
    - WHERE: `src/gui_2.py` `_send_callback()`
    - WHAT: Append definition to message
    - HOW:
      ```python
      symbols = parse_symbols(user_message)
      for symbol in symbols:
       result = get_symbol_definition(symbol, self.project_files)
       if result:
        file_path, definition = result
        user_message += f"\n\n[Definition: {symbol} from {file_path}]\n```python\n{definition}\n```"
      ```

## Phase 4: Click Navigation
Focus: Allow clicking definition to open file

- [ ] Task 4.1: Store file/line metadata with definition
    - WHERE: Discussion entry structure
    - WHAT: Track source location
    - HOW: Add to discussion entry dict

- [ ] Task 4.2: Add click handler
    - WHERE: `src/gui_2.py` discussion rendering
    - WHAT: On click, scroll to definition
    - HOW: Use selectable text with callback

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