|
4 | 4 |
|
5 | 5 | ## Goal |
6 | 6 |
|
7 | | -The VSCode extension provides a simple, focused interface for displaying and interacting with AI-generated code reviews. It eliminates the need to scroll through terminal output by bringing reviews directly into the IDE as a first-class citizen. |
| 7 | +The VSCode extension provides intelligent AI integration with two core capabilities: |
8 | 8 |
|
9 | | -### Core Functionality |
10 | | - |
11 | | -The extension enables three essential capabilities: |
12 | | - |
13 | | -1. **Review Display** - Pop up a dedicated panel when the AI assistant presents a review, showing the structured markdown content with proper formatting |
14 | | - |
15 | | -2. **Code Navigation** - Make `file:line` references in the review clickable, allowing instant navigation to the referenced code locations in the editor |
16 | | - |
17 | | -3. **Content Export** - Provide a "Copy" button to copy the review content to the clipboard for use in commit messages, documentation, or sharing |
18 | | - |
19 | | -These three features support the core workflow: AI generates review → user reads and navigates → user exports for further use. |
| 9 | +1. **Review Display** - Present AI-generated code reviews in a dedicated sidebar panel with clickable navigation |
| 10 | +2. **Ask Socratic Shell** - Route selected code to AI assistants with intelligent terminal detection and routing |
20 | 11 |
|
21 | 12 | ## Architecture |
22 | 13 |
|
23 | | -The extension operates as both a UI component and an IPC server: |
| 14 | +The extension operates as a daemon client and UI component: |
24 | 15 |
|
25 | 16 | ``` |
26 | | -┌─────────────────┐ IPC Server ┌─────────────────┐ Tree View API ┌─────────────────┐ |
27 | | -│ MCP Server │ ←─────────────────→ │ VSCode Extension│ ←─────────────────→ │ VSCode UI │ |
28 | | -└─────────────────┘ └─────────────────┘ └─────────────────┘ |
| 17 | +┌─────────────────┐ Daemon Client ┌─────────────────┐ VSCode APIs ┌─────────────────┐ |
| 18 | +│ Daemon Bus │ ←─────────────────→ │ VSCode Extension│ ←───────────────→ │ VSCode UI │ |
| 19 | +└─────────────────┘ └─────────────────┘ └─────────────────┘ |
| 20 | + │ |
| 21 | + ▼ |
| 22 | + ┌─────────────────┐ |
| 23 | + │Terminal Registry│ |
| 24 | + └─────────────────┘ |
29 | 25 | ``` |
30 | 26 |
|
31 | 27 | **Key Responsibilities:** |
32 | | -- Create and manage Unix socket IPC server for MCP communication |
33 | | -- Set environment variables for MCP server discovery |
34 | | -- Process incoming review messages and update UI components |
| 28 | +- Connect to daemon message bus as client |
| 29 | +- Maintain terminal registry of AI-enabled terminals |
| 30 | +- Process review presentation messages and update UI |
| 31 | +- Implement Ask Socratic Shell with intelligent terminal routing |
35 | 32 | - Provide tree-based review display with clickable navigation |
36 | | -- Handle copy-to-clipboard functionality |
37 | 33 |
|
38 | | -## Implementation Approach |
| 34 | +## Core Components |
| 35 | + |
| 36 | +### Daemon Client |
| 37 | +Manages connection to the daemon message bus: |
| 38 | +- **Connection management** - Connects to daemon Unix socket on activation |
| 39 | +- **Message handling** - Processes PresentReview, Polo, Goodbye, and Marco messages |
| 40 | +- **Response routing** - Sends success/error responses back through daemon |
| 41 | +- **Reconnection logic** - Handles daemon restarts gracefully |
| 42 | + |
| 43 | +### Terminal Registry |
| 44 | +Tracks which terminals have active AI assistants: |
| 45 | +- **PID tracking** - Maintains `Set<number>` of shell PIDs with active MCP servers |
| 46 | +- **Discovery updates** - Updates registry based on Polo/Goodbye messages from daemon |
| 47 | +- **Terminal matching** - Maps VSCode terminals to shell PIDs for routing decisions |
| 48 | +- **Workspace isolation** - Each window maintains independent registry |
| 49 | + |
| 50 | +### Ask Socratic Shell Integration |
| 51 | +Routes selected code to AI assistants: |
| 52 | +- **Code selection** - Captures selected text with file location context |
| 53 | +- **Terminal detection** - Queries terminal registry for AI-enabled terminals |
| 54 | +- **Smart routing** - Auto-routes to single terminal or shows picker for multiple |
| 55 | +- **Terminal picker** - VSCode QuickPick with memory and quick access options |
| 56 | +- **Message formatting** - Formats code with context for AI consumption |
| 57 | + |
| 58 | +### Review Provider |
| 59 | +Displays AI-generated reviews in sidebar: |
| 60 | +- **Tree structure** - Hierarchical display of review sections and content |
| 61 | +- **Markdown rendering** - Processes markdown with custom link handling |
| 62 | +- **Navigation** - Clickable file:line references that jump to code locations |
| 63 | +- **Content management** - Supports replace, update, and append modes |
| 64 | + |
| 65 | +## Implementation Details |
| 66 | + |
| 67 | +### Terminal Registry Implementation |
| 68 | +```typescript |
| 69 | +class DaemonClient { |
| 70 | + private activeTerminals = new Set<number>(); |
| 71 | + |
| 72 | + private handlePoloMessage(message: PoloMessage) { |
| 73 | + this.activeTerminals.add(message.shellPid); |
| 74 | + this.outputChannel.appendLine(`Added terminal PID ${message.shellPid} to registry`); |
| 75 | + } |
| 76 | + |
| 77 | + private handleGoodbyeMessage(message: GoodbyeMessage) { |
| 78 | + this.activeTerminals.delete(message.shellPid); |
| 79 | + this.outputChannel.appendLine(`Removed terminal PID ${message.shellPid} from registry`); |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Ask Socratic Shell Flow |
| 85 | +1. **User selects code** - Context menu or quick action triggers command |
| 86 | +2. **Query registry** - Get list of terminals with active AI assistants |
| 87 | +3. **Route intelligently**: |
| 88 | + - **Single terminal** - Send message directly |
| 89 | + - **Multiple terminals** - Show picker with memory |
| 90 | + - **No terminals** - Display helpful error message |
| 91 | +4. **Format message** - Include file location and selected code |
| 92 | +5. **Send to terminal** - Use VSCode terminal API to inject formatted text |
| 93 | + |
| 94 | +### Terminal Picker UX |
| 95 | +- **Quick access option** - "Use last terminal: [Name]" appears first |
| 96 | +- **Visual indicators** - Star icons and "(last used)" labels |
| 97 | +- **Natural ordering** - Terminals appear in same order as VSCode terminal list |
| 98 | +- **Workspace memory** - Remembers preference per VSCode window |
| 99 | +- **Graceful fallbacks** - Handles terminal closures and MCP server disconnections |
| 100 | + |
| 101 | +### Message Processing |
| 102 | +The extension filters daemon broadcasts based on shell PID matching: |
| 103 | +```typescript |
| 104 | +private async handlePresentReviewMessage(message: PresentReviewMessage) { |
| 105 | + // Check if this message is for a terminal in our window |
| 106 | + const matchingTerminal = await this.findTerminalByPID(message.shellPid); |
| 107 | + if (matchingTerminal) { |
| 108 | + // Process the review for our window |
| 109 | + await this.reviewProvider.presentReview(message); |
| 110 | + return { success: true }; |
| 111 | + } |
| 112 | + // Ignore - another window will handle it |
| 113 | + return null; |
| 114 | +} |
| 115 | +``` |
39 | 116 |
|
40 | | -### Technology Stack |
41 | | -- **Language**: TypeScript with VSCode Extension API |
42 | | -- **UI Framework**: VSCode TreeView API for hierarchical review display |
43 | | -- **IPC**: Node.js `net` module for Unix socket server |
44 | | -- **Markdown Processing**: Custom parser for tree structure generation |
45 | | -- **Navigation**: VSCode editor commands for file/line jumping |
| 117 | +## Multi-Window Support |
46 | 118 |
|
47 | | -### Core Components |
| 119 | +Each VSCode window runs an independent extension instance: |
| 120 | +- **Separate daemon connections** - Each window connects to the same daemon |
| 121 | +- **Independent registries** - Each tracks its own terminals |
| 122 | +- **Automatic routing** - Messages route to correct window based on shell PID |
| 123 | +- **Isolated preferences** - Terminal picker memory is per-window |
| 124 | + |
| 125 | +## Technology Stack |
| 126 | + |
| 127 | +- **Language**: TypeScript with VSCode Extension API |
| 128 | +- **IPC**: Node.js Unix socket client for daemon communication |
| 129 | +- **UI**: VSCode TreeView API for review display, QuickPick for terminal selection |
| 130 | +- **Terminal Integration**: VSCode Terminal API for message injection |
| 131 | +- **State Management**: VSCode workspace state for terminal picker memory |
48 | 132 |
|
49 | | -**Extension Activation**: Main entry point that sets up all functionality |
50 | | -- Creates review provider for tree-based display |
| 133 | +The extension provides seamless AI integration that eliminates configuration while supporting sophisticated multi-window workflows. |
51 | 134 | - Registers tree view with VSCode's sidebar |
52 | 135 | - Sets up IPC server for MCP communication |
53 | 136 | - Registers commands and cleanup handlers |
|
0 commit comments