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

Commit b77dffd

Browse files
committed
Complete mdbook documentation update with Mermaid diagrams and new design sections
- Add Mermaid preprocessor support to book.toml with JavaScript assets - Update system overview with enhanced Mermaid architecture diagram showing AI Assistant - Add proper links to key concepts (daemon message bus, terminal registry, MCP tool) - Create comprehensive message flows documentation with sequence diagrams: * Review presentation flow with PID matching logic * Ask Socratic Shell flow with terminal picker scenarios * Extension reload flow showing Marco-Polo rediscovery * Discovery protocol for MCP server announcements - Create terminal registry documentation covering: * PID discovery through process tree walking * Registry updates via Polo/Goodbye messages * Terminal matching for Ask Socratic Shell integration * Multi-window support architecture - Update SUMMARY.md with new design sections for better organization - Replace ASCII art with professional Mermaid diagrams throughout Documentation now provides clear visual representation of the daemon message bus architecture and intelligent terminal routing system.
1 parent 980bbb2 commit b77dffd

14 files changed

+2979
-70
lines changed

book.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ authors = ["Niko Matsakis"]
33
language = "en"
44
src = "md"
55
title = "Dialectic"
6+
7+
[preprocessor.mermaid]
8+
command = "mdbook-mermaid"
9+
10+
[output.html]
11+
additional-js = ["mermaid.min.js", "mermaid-init.js"]

md/SUMMARY.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@
88

99
- [Installation](./installation.md) <!-- 💡: Step-by-step setup for both VSCode extension and MCP server components -->
1010
- [Quick start](./quick-start.md) <!-- 💡: Basic workflow example showing AI assistant → review display → navigation cycle -->
11-
- [Review format](./review-format.md) <!-- 💡: Explains file:line syntax, reference-style links [file:line][], and markdown conventions AI assistants should follow -->
11+
- [Features]()
12+
- [Presenting a walkthrough](./walkthrough-presentation.md) <!-- 💡: Explain how presentation works, from a user's perspective -->
13+
- [Ask Socratic Shell](./ask-socratic-shell.md) <!-- 💡: Explain how Ask Socratic Shell works, from a user's perspective -->
14+
- [Review format](./review-format.md) <!-- 💡: Explains file:line syntax, reference-style links [file:line][], and markdown conventions AI assistants should follow -->
1215
- [Frequently asked questions](./faq.md) <!-- 💡: Anticipated user questions about common errors, expected workflow, purpose, comparisons with other tools, etc -->
1316

1417
# Development and contribution guide <!-- 💡: Technical documentation for contributors and people wanting to understand system internals -->
1518

1619
- [Building and testing](./design/build-and-test.md) <!-- 💡: Development environment setup, build process, and testing procedures -->
1720
- [System overview](./design/overview.md) <!-- 💡: High-level architecture showing MCP server ↔ VSCode extension communication via Unix sockets -->
1821
- [Communication protocol](./design/protocol.md) <!-- 💡: JSON message format, Unix socket/named pipe IPC, and error handling between components -->
22+
- [Message flows](./design/message-flows.md) <!-- 💡: Detailed sequence diagrams and examples for review presentation and Ask Socratic Shell flows -->
1923
- [Security considerations](./design/security.md) <!-- 💡: CSP headers, DOMPurify sanitization, and secure webview practices for markdown rendering -->
2024
- [MCP Tool interface](./design/mcp-tool-interface.md) <!-- 💡: API specification for AI assistants calling present_review tool with markdown content -->
2125
- [AI Guidance design considerations](./design/ai-guidance.md) <!-- 💡: Design decisions made specifically to work well with AI collaboration patterns from socratic shell -->
2226
- [VSCode extension](./design/extension.md) <!-- 💡: Highlights of the VSCode Extension design and implementation: activation, establishing IPC protocol -->
27+
- [Terminal registry](./design/terminal-registry.md) <!-- 💡: Implementation details for tracking active MCP servers, PID discovery, and capability-based routing -->
2328
- [Markdown rendering](./design/markdown-rendering.md) <!-- 💡: markdown-it pipeline, custom renderer rules for file references, and HTML generation process -->
2429

2530
# In-progress RFCs <!-- 💡: Design proposals under active development and discussion -->

md/ask-socratic-shell.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Ask Socratic Shell

md/design/message-flows.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Message Flows
2+
3+
This section shows the detailed message flows for key Dialectic operations using sequence diagrams.
4+
5+
## Review Presentation Flow
6+
7+
When a user requests a code review, here's the complete message flow:
8+
9+
```mermaid
10+
sequenceDiagram
11+
participant User
12+
participant AI as AI Assistant
13+
participant MCP as MCP Server
14+
participant Daemon as Daemon Bus
15+
participant Ext as VSCode Extension
16+
participant UI as Review Panel
17+
18+
User->>AI: "Present a review of the changes"
19+
AI->>MCP: present_review(content, mode, baseUri)
20+
MCP->>MCP: Discover shell PID
21+
MCP->>Daemon: PresentReview message + shell PID
22+
Daemon->>Ext: Broadcast message to all extensions
23+
Ext->>Ext: Check if shell PID matches terminal
24+
alt PID matches terminal in this window
25+
Ext->>UI: Create/update review panel
26+
Ext->>Daemon: Success response
27+
Daemon->>MCP: Forward success
28+
MCP->>AI: Tool execution success
29+
AI->>User: "Review displayed in VSCode"
30+
else PID doesn't match
31+
Ext->>Daemon: Ignore (no response)
32+
Note over Daemon: Other extensions handle it
33+
end
34+
```
35+
36+
## Ask Socratic Shell Flow
37+
38+
When a user selects code and uses "Ask Socratic Shell":
39+
40+
```mermaid
41+
sequenceDiagram
42+
participant User
43+
participant Ext as VSCode Extension
44+
participant Registry as Terminal Registry
45+
participant Picker as Terminal Picker
46+
participant Term as Target Terminal
47+
participant AI as AI Assistant
48+
49+
User->>Ext: Select code + "Ask Socratic Shell"
50+
Ext->>Registry: Get active terminals
51+
Registry->>Ext: Return AI-enabled terminal PIDs
52+
53+
alt Single AI terminal
54+
Ext->>Term: Send formatted message
55+
Term->>AI: Message appears in terminal
56+
AI->>User: Responds to code question
57+
else Multiple AI terminals
58+
Ext->>Picker: Show terminal selection UI
59+
Picker->>User: Display terminals with last-used option
60+
User->>Picker: Select terminal
61+
Picker->>Ext: Return selected terminal
62+
Ext->>Term: Send formatted message
63+
Term->>AI: Message appears in terminal
64+
AI->>User: Responds to code question
65+
else No AI terminals
66+
Ext->>User: Show "no MCP servers" warning
67+
end
68+
```
69+
70+
## Extension Reload Flow
71+
72+
When a user reloads the VSCode window, the extension restarts but MCP servers continue running:
73+
74+
```mermaid
75+
sequenceDiagram
76+
participant User
77+
participant Ext as VSCode Extension
78+
participant Daemon as Daemon Bus
79+
participant MCP1 as MCP Server 1
80+
participant MCP2 as MCP Server 2
81+
participant Registry as Terminal Registry
82+
83+
Note over User: Reloads VSCode window (Cmd+R)
84+
Note over Ext: Extension deactivates/reactivates
85+
86+
Ext->>Daemon: Connect to daemon
87+
Note over Registry: Registry starts empty
88+
89+
Ext->>Daemon: Marco request (discovery)
90+
Daemon->>MCP1: Broadcast Marco
91+
Daemon->>MCP2: Broadcast Marco
92+
93+
MCP1->>Daemon: Polo response (shell PID 12345)
94+
MCP2->>Daemon: Polo response (shell PID 67890)
95+
96+
Daemon->>Ext: Forward Polo from MCP1
97+
Daemon->>Ext: Forward Polo from MCP2
98+
99+
Ext->>Registry: Add PID 12345
100+
Ext->>Registry: Add PID 67890
101+
102+
Note over Ext,Registry: Registry rebuilt, Ask Socratic Shell works again
103+
```
104+
105+
## Discovery Protocol (Marco-Polo)
106+
107+
How MCP servers announce their presence and maintain the terminal registry:
108+
109+
```mermaid
110+
sequenceDiagram
111+
participant MCP as MCP Server
112+
participant Daemon as Daemon Bus
113+
participant Ext as VSCode Extension
114+
participant Registry as Terminal Registry
115+
116+
Note over MCP: Server starts up
117+
MCP->>MCP: Discover shell PID via process tree
118+
MCP->>Daemon: Polo message (shell PID)
119+
Daemon->>Ext: Broadcast Polo to all extensions
120+
Ext->>Registry: Add PID to active terminals
121+
122+
Note over MCP,Registry: Server running...
123+
124+
Note over MCP: Server shuts down
125+
MCP->>Daemon: Goodbye message (shell PID)
126+
Daemon->>Ext: Broadcast Goodbye to all extensions
127+
Ext->>Registry: Remove PID from active terminals
128+
```
129+
130+
## Key Message Types
131+
132+
### PresentReview Message
133+
```json
134+
{
135+
"type": "PresentReview",
136+
"content": "# Review content...",
137+
"mode": "replace",
138+
"baseUri": "/path/to/project",
139+
"shellPid": 12345
140+
}
141+
```
142+
143+
### Polo Message
144+
```json
145+
{
146+
"type": "Polo",
147+
"shellPid": 12345
148+
}
149+
```
150+
151+
### Goodbye Message
152+
```json
153+
{
154+
"type": "Goodbye",
155+
"shellPid": 12345
156+
}
157+
```
158+
159+
These flows show how the daemon message bus enables intelligent routing and multi-window support while maintaining a simple interface for AI assistants.

md/design/overview.md

Lines changed: 84 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,108 @@
44

55
## Architecture Summary
66

7-
Dialectic consists of two main components that communicate via Unix socket IPC:
7+
Dialectic consists of three main components that communicate via a [daemon message bus](./protocol.md):
88

9-
1. **VSCode Extension** - Provides the review panel UI, handles file navigation, and acts as IPC server
10-
2. **MCP Server** - Acts as a bridge between AI assistants and the VSCode extension via IPC client
11-
12-
The AI assistant generates review content as structured markdown and uses the MCP server's `present-review` tool to display it in the VSCode interface through bidirectional IPC communication.
9+
1. **VSCode Extension** - Provides the review panel UI, handles file navigation, and manages [terminal registry](./terminal-registry.md)
10+
2. **Daemon Message Bus** - Routes messages between MCP servers and VSCode extensions across multiple windows; there is one per IDE process
11+
3. **MCP Server** - Acts as a bridge between AI assistants and the VSCode extension via daemon communication
1312

1413
## Communication Architecture
1514

15+
```mermaid
16+
graph TD
17+
AI[AI Assistant]
18+
19+
subgraph IDE[" IDE Process (e.g., VSCode) "]
20+
subgraph Window[" Window "]
21+
Ext[Extension]
22+
Term1[Terminal 1]
23+
Server1[MCP Server 1]
24+
Term2[Terminal 2]
25+
Server2[MCP Server 2]
26+
end
27+
subgraph Window2[" Other window "]
28+
DotDotDot[...]
29+
end
30+
end
31+
32+
Daemon[Daemon Message Bus]
33+
34+
AI --> Server1
35+
AI --> Server2
36+
37+
Ext <--> Daemon
38+
Server1 <--> Daemon
39+
Server2 <--> Daemon
40+
DotDotDot <--> Daemon
41+
42+
%% Terminal connections within windows
43+
Term1 -.-> Server1
44+
Term2 -.-> Server2
45+
46+
%% Styling
47+
classDef daemon fill:#e1f5fe,stroke:#01579b,stroke-width:3px,color:#000
48+
classDef extension fill:#f3e5f5,stroke:#4a148c,stroke-width:2px,color:#000
49+
classDef server fill:#e8f5e8,stroke:#1b5e20,stroke-width:2px,color:#000
50+
classDef terminal fill:#fff3e0,stroke:#e65100,stroke-width:1px,color:#000
51+
classDef window fill:#fafafa,stroke:#424242,stroke-width:1px,stroke-dasharray: 5 5
52+
classDef ai fill:#fff9c4,stroke:#f57f17,stroke-width:2px,color:#000
53+
54+
class Daemon daemon
55+
class Ext extension
56+
class Server1,Server2 server
57+
class Term1,Term2 terminal
58+
class Window window
59+
class AI ai
1660
```
17-
AI Assistant → MCP Tool → Unix Socket → VSCode Extension → Review Panel → User
18-
↑ ↓
19-
└─────────── Response ←─────── IPC Response ←─────── User Interaction ←┘
20-
```
21-
22-
### IPC Communication
23-
24-
The MCP server and VSCode extension communicate via Unix socket IPC using environment variable discovery. The VSCode extension creates a socket server and sets `DIALECTIC_IPC_PATH` for the MCP server to find and connect to.
25-
26-
For detailed information about how the IPC connection is established and what messages are exchanged, see the [Communication Protocol](./protocol.md) chapter.
27-
28-
**Key Design Decisions:**
29-
- **Unix Socket/Named Pipe**: Secure, efficient local IPC following VSCode extension patterns
30-
- **Newline-Delimited JSON**: Simple, debuggable message format with reliable boundaries
31-
- **Promise-Based Tracking**: Supports concurrent operations with unique message IDs
32-
- **Environment Variable Discovery**: Automatic connection without configuration complexity
33-
34-
## Design Philosophy
35-
36-
Dialectic embodies the collaborative patterns from the [socratic shell project](https://socratic-shell.github.io/socratic-shell/). The goal is to enable genuine pair programming partnerships with AI assistants, not create another tool for giving commands to a servant.
3761

38-
**Collaborative Review** - Instead of accepting hunks blindly or micro-managing every change, we work together to understand what was built and why, just like reviewing a colleague's PR.
62+
## Example flow
3963

40-
**Thoughtful Interaction** - The review format encourages narrative explanation and reasoning, not just "what changed" but "how it works" and "why these decisions were made."
64+
Here is a high-level overview of how the flow works when the user requests a review:
4165

42-
**Preserved Context** - Reviews become part of your git history, retaining the collaborative thinking process for future reference and team members.
66+
* User requests a walkthrough. LLM invokes the "present review" [MCP tool](./mcp-tool-interface.md).
67+
* The MCP server sends a message to the [daemon bus](./protocol.md). The daemon bus broadcasts the message to all connected clients. The message includes the PID of the shell in which the MCP server is running.
68+
* The extension receives the message from the daemon bus. It identifies that the shell PID belongs to one of the terminals in its window, so it processes the request and creates a webview.
4369

44-
**Iterative Refinement** - Nothing is right the first time. The review process expects and supports ongoing dialogue, suggestions, and improvements rather than assuming the initial implementation is final.
45-
46-
## Implementation Status
47-
48-
**✅ MVP Complete** - All core features implemented and tested:
49-
- **Review Display**: Tree-based markdown rendering in VSCode sidebar
50-
- **Code Navigation**: Clickable `file:line` references that jump to code locations
51-
- **Content Export**: Copy button to export review content for commit messages
52-
- **IPC Communication**: Full bidirectional communication between AI and extension
53-
54-
**Current State**: Ready for end-to-end testing with real AI assistants in VSCode environments.
55-
56-
**Next Phase**: Package extension for distribution and create installation documentation.
57-
58-
## Technical Stack
59-
60-
- **MCP Server**: TypeScript/Node.js with comprehensive unit testing (49/49 tests passing)
61-
- **VSCode Extension**: TypeScript with VSCode Extension API
62-
- **Communication**: Unix domain sockets (macOS/Linux) and named pipes (Windows)
63-
- **Protocol**: JSON messages with unique ID tracking and timeout protection
64-
- **Testing**: Jest for unit tests with test mode for IPC-free testing
70+
Read more details in the [communication protocol](./protocol.md) section.
6571

6672
## Component Responsibilities
6773

6874
### MCP Server (`server/`)
6975
- Exposes `present-review` tool to AI assistants
70-
- Validates parameters and handles errors gracefully
71-
- Manages IPC client connection to VSCode extension
72-
- Supports concurrent operations with Promise-based tracking
73-
- See `server/src/index.ts` for main server implementation
76+
- Discovers terminal shell PID through process tree walking
77+
- Announces presence to daemon via Marco-Polo protocol
78+
- Handles graceful disconnection and cleanup
79+
- See `server/src/main.rs` for main server implementation
80+
81+
### Daemon Message Bus (`server/src/daemon.rs`)
82+
- Routes messages between MCP servers and VSCode extensions
83+
- Manages client connections and handles disconnections
84+
- Broadcasts messages to appropriate VSCode windows
85+
- Provides process lifecycle management
86+
- Runs as background process tied to VSCode instance
7487

7588
### VSCode Extension (`extension/`)
76-
- Creates IPC server and sets environment variables
77-
- Provides tree-based review display in sidebar
78-
- Handles clickable navigation to code locations
79-
- Manages copy-to-clipboard functionality
80-
- See `extension/src/extension.ts` for activation logic
81-
82-
### Shared Types (`server/src/types.ts`)
83-
- Defines communication protocol interfaces
84-
- Ensures type safety across IPC boundary
85-
- Prevents protocol mismatches during development
89+
- Creates daemon client connection and manages terminal registry
90+
- Provides tree-based review display in sidebar with navigation
91+
- Implements Ask Socratic Shell integration with intelligent terminal routing
92+
- Manages terminal picker UI with memory and quick access options
93+
- Handles workspace state persistence for user preferences
94+
- See `extension/src/extension.ts` for activation and daemon client logic
95+
96+
### Terminal Registry (`extension/src/extension.ts`)
97+
- Tracks active terminals with MCP servers using shell PIDs
98+
- Updates registry based on Marco-Polo discovery messages
99+
- Provides API for Ask Socratic Shell to query AI-enabled terminals
100+
- Maintains workspace-specific preferences and memory
86101

87102
## Key Implementation Files
88103

89-
- `server/src/index.ts` - Main MCP server with tool handlers
90-
- `server/src/ipc.ts` - IPC client communication logic
91-
- `server/src/validation.ts` - Parameter validation and error handling
92-
- `extension/src/extension.ts` - VSCode extension activation and IPC server
104+
- `server/src/main.rs` - Main MCP server with tool handlers and process discovery
105+
- `server/src/daemon.rs` - Daemon message bus with client management
106+
- `server/src/pid_discovery.rs` - Process tree walking for terminal shell PID detection
107+
- `extension/src/extension.ts` - VSCode extension with daemon client and terminal registry
93108
- `extension/src/reviewProvider.ts` - Tree view implementation and markdown parsing
94-
- `server/src/__tests__/` - Comprehensive unit test suite
109+
- `server/tests/` - Integration tests with real daemon and terminal scenarios
95110

96-
For detailed implementation specifics, refer to the source code and inline comments marked with `💡` that explain non-obvious design decisions.
111+
For detailed implementation specifics, refer to the source code and inline comments that explain design decisions and architectural patterns.

0 commit comments

Comments
 (0)