Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit b3f56c1

Browse files
committed
Complete comprehensive documentation overhaul for Dialectic
User Guide sections: - Create Ask Socratic Shell user guide with terminal selection and routing - Create walkthrough presentation guide with navigation and review modes - Update FAQ with ### headers for linkability and current daemon architecture - Update quick start with dual workflows (review + Ask Socratic Shell) System Overview sections: - Rewrite communication protocol for daemon message bus architecture - Update VSCode extension docs with terminal registry and Ask Socratic Shell - Create comprehensive daemon message bus documentation - Create detailed MCP server implementation documentation - Streamline MCP tool interface to reference format with mdbook includes - Add mdbook anchors for automatic code synchronization Documentation now provides complete coverage of: - Multi-window daemon message bus architecture - Intelligent terminal routing without configuration - Ask Socratic Shell integration with smart terminal detection - Professional Mermaid diagrams with click-to-enlarge functionality - Comprehensive user guides and technical reference documentation All major components (MCP Server, Daemon, VSCode Extension) now have dedicated technical documentation with implementation details, error handling, and testing strategies. Documentation is production-ready.
1 parent 04762c0 commit b3f56c1

File tree

11 files changed

+492
-182
lines changed

11 files changed

+492
-182
lines changed

md/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
- [System overview](./design/overview.md) <!-- 💡: High-level architecture showing MCP server ↔ VSCode extension communication via Unix sockets -->
2121
- [Communication protocol](./design/protocol.md) <!-- 💡: JSON message format, Unix socket/named pipe IPC, and error handling between components -->
2222
- [Message flows](./design/message-flows.md) <!-- 💡: Detailed sequence diagrams and examples for review presentation and Ask Socratic Shell flows -->
23+
- [Daemon message bus](./design/daemon.md) <!-- 💡: Central message router implementation, client management, process lifecycle, and Unix socket server architecture -->
24+
- [MCP server](./design/mcp-server.md) <!-- 💡: AI assistant bridge implementation, process discovery, tool handlers, and daemon client functionality -->
2325
- [Security considerations](./design/security.md) <!-- 💡: CSP headers, DOMPurify sanitization, and secure webview practices for markdown rendering -->
2426
- [MCP Tool interface](./design/mcp-tool-interface.md) <!-- 💡: API specification for AI assistants calling present_review tool with markdown content -->
2527
- [AI Guidance design considerations](./design/ai-guidance.md) <!-- 💡: Design decisions made specifically to work well with AI collaboration patterns from socratic shell -->

md/ask-socratic-shell.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,79 @@
11
# Ask Socratic Shell
2+
3+
Ask Socratic Shell lets you send selected code directly to your AI assistant for discussion, creating a seamless bridge between your editor and AI chat sessions.
4+
5+
## How It Works
6+
7+
When you select code in VSCode, Dialectic automatically detects which terminals have active AI assistants and routes your selection to the right place.
8+
9+
## Using Ask Socratic Shell
10+
11+
### 1. Select Code
12+
Highlight any code in your VSCode editor - a function, a few lines, or even a single variable.
13+
14+
### 2. Trigger the Action
15+
Right-click and choose **"Ask Socratic Shell"** from the context menu, or use the lightbulb quick action that appears.
16+
17+
### 3. Choose Your AI (if needed)
18+
- **Single AI assistant**: Your message goes directly to that terminal
19+
- **Multiple AI assistants**: A picker appears showing available options
20+
- **No AI assistants**: You'll see a helpful message about starting an AI session
21+
22+
### 4. Continue the Conversation
23+
The selected code appears in your AI terminal with context about the file and location. Continue the conversation naturally.
24+
25+
## Terminal Selection
26+
27+
### Smart Detection
28+
Dialectic automatically finds terminals with active AI assistants - no need to name terminals or configure anything.
29+
30+
### Multiple AI Assistants
31+
When you have multiple AI sessions running, the terminal picker shows:
32+
- **Quick access option**: "Use last terminal: [Name]" at the top
33+
- **All available terminals**: Listed with their process IDs
34+
- **Memory**: Your last choice is remembered and highlighted
35+
36+
### Example Picker
37+
```
38+
┌─ Multiple AI-enabled terminals found ─────────────────┐
39+
│ Select terminal for AI chat (first option = quick...) │
40+
├───────────────────────────────────────────────────────┤
41+
│ ● 📜 Use last terminal: Terminal 2 PID: 67890 │
42+
│ Quick access to your previously used terminal │
43+
│ │
44+
│ ─ All available terminals │
45+
│ │
46+
│ Terminal (qterm) PID: 35059 │
47+
│ Terminal with active MCP server │
48+
│ │
49+
│ ⭐ Terminal 2 PID: 67890 (last used) │
50+
│ Terminal with active MCP server │
51+
└───────────────────────────────────────────────────────┘
52+
```
53+
54+
## Message Format
55+
56+
Your selected code is sent with helpful context:
57+
58+
```
59+
<context>looking at this code from src/auth.ts:42:1-45:20 <content>function validateUser(email) {
60+
if (!email.includes('@')) {
61+
return false;
62+
}
63+
return true;
64+
}</content></context> can you help me improve this validation?
65+
```
66+
67+
This gives your AI assistant:
68+
- **File location**: `src/auth.ts:42:1-45:20`
69+
- **Actual code**: The selected content
70+
- **Your question**: Added automatically or you can type more
71+
72+
## Tips
73+
74+
- **Select meaningful chunks**: Functions, classes, or logical blocks work best
75+
- **Add your question**: The context menu adds "can you help me improve this?" but you can edit it
76+
- **Use consistently**: The system remembers your preferred terminal for quick access
77+
- **Multiple windows**: Each VSCode window tracks its own AI assistants independently
78+
79+
Ask Socratic Shell eliminates the friction of copying code to chat - just select, click, and discuss!

md/design/daemon.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Daemon Message Bus
2+
3+
The daemon message bus serves as the central communication hub that routes messages between MCP servers and VSCode extensions across multiple windows. It eliminates the need for direct connections while enabling intelligent message routing based on terminal capabilities.
4+
5+
## Binary
6+
7+
The [MCP server](./mcp-server.md) and daemon are packaged in the same binary. Daemons are started by passing the `daemon` parameter on the command line.
8+
9+
## Lifecycle
10+
11+
When an [MCP server](./mcp-server.md) starts, it identifies the PID of the IDE it is running inside of and attempts to start a daemon for that PID as a new process. If a daemon is already running, then this has no effect.
12+
13+
The daemon runs as a root process. It periodically monitors the IDE PID to see whether the IDE has exited. If the IDE has terminated, the daemon will automatically terminate.
14+
15+
## IPC communication
16+
17+
Daemons bind an IPC socket whose name is determined by the PID of the IDE (given on the command line).
18+
The [IPC protocol](./protocol.md) is defined separately. Daemons themselves don't understand the protocol, they simple accept newline-delimited messages and re-broadcast them to all connected clients. Daemons are intentionally very simple.

md/design/extension.md

Lines changed: 113 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,133 @@
44

55
## Goal
66

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:
88

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
2011

2112
## Architecture
2213

23-
The extension operates as both a UI component and an IPC server:
14+
The extension operates as a daemon client and UI component:
2415

2516
```
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+
└─────────────────┘
2925
```
3026

3127
**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
3532
- Provide tree-based review display with clickable navigation
36-
- Handle copy-to-clipboard functionality
3733

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+
```
39116

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
46118

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
48132

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.
51134
- Registers tree view with VSCode's sidebar
52135
- Sets up IPC server for MCP communication
53136
- Registers commands and cleanup handlers

md/design/mcp-server.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# MCP Server
2+
3+
The MCP server acts as a bridge between AI assistants and the VSCode extension. It offers [tools](./tool-interface.md) that AI assistants can use to send messages to the extension (e.g., present-review).
4+
5+
## Lifecycle
6+
7+
MCP servers are started automatically by the AI client. They can be long- or short-lived depending on the whims of the client.
8+
9+
## PID identification
10+
11+
When the MCP server starts, it walks up the process tree to identify the PID for the shell it is running within and the IDE that this shell is contained within. If those PIDs cannot be identified, it returns an error. As described in the [daemon lifecycle](./daemon.md#lifecycle), the server will also spawn a daemon process for the IDE PID if needed.
12+
13+
## Tools offered to clients
14+
15+
See the [Tool Interface](./tool-interface.md) section.

md/design/mcp-tool-interface.md

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,66 @@
11
# MCP Tool Interface
22

3-
*This section documents the `present_review` tool that AI assistants use to display code reviews in VSCode.*
4-
5-
## Tool Overview
6-
7-
The `present_review` tool is the primary interface between AI assistants and the Dialectic system. It accepts markdown content and displays it in the VSCode review panel with clickable file references and proper formatting.
3+
*Reference documentation for the `present_review` tool exposed to AI assistants.*
84

95
## Tool Definition
106

11-
The tool is registered with the MCP server and exposed to AI assistants:
12-
13-
```typescript
14-
{{#include ../../server/src/index.ts:tool_definition}}
7+
```rust
8+
{{#include ../../server/src/server.rs:present_review_tool}}
159
```
1610

1711
## Parameters
1812

19-
The tool accepts parameters defined by the `PresentReviewParams` interface:
13+
### `content` (required)
14+
Markdown content of the review to display with support for clickable file references.
2015

21-
```typescript
22-
{{#include ../../server/src/types.ts:present_review_params}}
16+
### `mode` (optional, default: "replace")
17+
- `"replace"` - Replace entire review content
18+
- `"update-section"` - Update specific section of existing review
19+
- `"append"` - Add content to end of existing review
20+
21+
### `baseUri` (required)
22+
Base directory path for resolving relative file references.
23+
24+
### `section` (optional)
25+
Section name for `update-section` mode.
26+
27+
## File Reference Formats
28+
29+
```markdown
30+
[auth.ts](src/auth.ts) # Opens file
31+
[auth.ts:42](src/auth.ts#L42) # Jumps to line 42
32+
[auth.ts:42-50](src/auth.ts#L42-L50) # Highlights line range
33+
[validateUser](src/auth.ts?validateUser) # Finds pattern in file
2334
```
2435

25-
### Parameter Details
36+
## Usage Examples
2637

27-
**`content` (required)**
28-
- **Type**: `string`
29-
- **Description**: Markdown content of the review to display
30-
- **Format**: Standard markdown with support for file references using `[filename:line][]` syntax
38+
### Basic Review
39+
```javascript
40+
await use_mcp_tool("present_review", {
41+
content: "# Code Review\n\nImplemented user authentication...",
42+
baseUri: "/workspace/myapp"
43+
});
44+
```
45+
46+
### Section Update
47+
```javascript
48+
await use_mcp_tool("present_review", {
49+
content: "## Updated Error Handling\n\nImproved validation...",
50+
mode: "update-section",
51+
section: "Error Handling",
52+
baseUri: "/workspace/myapp"
53+
});
54+
```
55+
56+
### Append Mode
57+
```javascript
58+
await use_mcp_tool("present_review", {
59+
content: "## Next Steps\n\n- Add rate limiting\n- Implement caching",
60+
mode: "append",
61+
baseUri: "/workspace/myapp"
62+
});
63+
```
3164
- **Example**:
3265
```markdown
3366
# Authentication System Implementation

0 commit comments

Comments
 (0)