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

Commit facd038

Browse files
committed
Streamline LLM guidance and fix file reference format
- Move guidance to project root as guidance.md, integrate with mdbook via include - Streamline guidance from verbose version to ~60% shorter while keeping essentials - Update file reference format to [`filename:line`][] (rustdoc-style) throughout - Fix webview regex to detect <code>[filename:line][]</code> pattern in rendered HTML - Refine sample review to use 'code-first tour' approach with code references as headers - Update guidance to emphasize guided code tours rather than pure narrative style - Fix UUID-based socket paths to avoid Unix socket path length truncation issues Guidance now produces more focused, structured reviews while being much easier for LLMs to digest. Fresh Claude validation shows high-quality output.
1 parent 0e64c44 commit facd038

File tree

6 files changed

+107
-106
lines changed

6 files changed

+107
-106
lines changed

extension/.vscode/launch.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"type": "extensionHost",
77
"request": "launch",
88
"args": [
9-
"--extensionDevelopmentPath=${workspaceFolder}",
10-
]
9+
"--extensionDevelopmentPath=${workspaceFolder}"
10+
],
11+
"cwd": "${workspaceFolder}/playground"
1112
}
1213
]
1314
}

extension/src/extension.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
22
import * as net from 'net';
33
import * as path from 'path';
44
import * as fs from 'fs';
5+
import * as crypto from 'crypto';
56
import { ReviewWebviewProvider } from './reviewWebview';
67

78
// 💡: Types for IPC communication with MCP server
@@ -110,20 +111,12 @@ function createIPCServer(context: vscode.ExtensionContext, reviewProvider: Revie
110111
}
111112

112113
function getSocketPath(context: vscode.ExtensionContext): string {
113-
// 💡: Use workspace-specific storage to avoid conflicts between projects
114-
const storageUri = context.storageUri || context.globalStorageUri;
115-
const socketDir = storageUri.fsPath;
116-
117-
// Ensure directory exists
118-
if (!fs.existsSync(socketDir)) {
119-
fs.mkdirSync(socketDir, { recursive: true });
120-
}
121-
122-
// 💡: Platform-specific socket naming (Windows uses named pipes)
114+
// 💡: Use UUID-based filename to avoid path length limits and ensure uniqueness
123115
if (process.platform === 'win32') {
124-
return `\\\\.\\pipe\\dialectic-${Date.now()}`;
116+
return `\\\\.\\pipe\\dialectic-${crypto.randomUUID()}`;
125117
} else {
126-
return path.join(socketDir, 'dialectic.sock');
118+
// Use /tmp with UUID for short, unique socket path
119+
return `/tmp/dialectic-${crypto.randomUUID()}.sock`;
127120
}
128121
}
129122

extension/src/reviewWebview.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ export class ReviewWebviewProvider {
167167
* Process HTML to make file:line references clickable
168168
*/
169169
private processFileReferences(html: string): string {
170-
// 💡: Find patterns like (src/main.rs:42) and make them clickable
170+
// 💡: Find patterns like [`src/main.rs:42`][] (rustdoc-style) and make them clickable
171171
return html.replace(
172-
/\(([^:)]+):(\d+)\)/g,
173-
'<a href="#" class="file-ref" data-file="$1" data-line="$2">($1:$2)</a>'
172+
/<code>\[([^:\]]+):(\d+)\]<\/code>\[\]/g,
173+
'<a href="#" class="file-ref" data-file="$1" data-line="$2"><code>[$1:$2][]</code></a>'
174174
);
175175
}
176176

@@ -327,17 +327,17 @@ export class ReviewWebviewProvider {
327327
The application needed secure user authentication to protect user data and enable personalized features. This implements a JWT-based authentication system with secure password hashing.
328328
329329
## Changes Made
330-
- Added authentication middleware (src/auth/middleware.ts:23)
331-
- Created user login/signup endpoints (src/routes/auth.ts:45)
332-
- Updated user model with password hashing (src/models/user.ts:67)
333-
- Added JWT token generation and validation (src/utils/jwt.ts:12)
330+
- Added authentication middleware [\`src/auth/middleware.ts:23\`][]
331+
- Created user login/signup endpoints [\`src/routes/auth.ts:45\`][]
332+
- Updated user model with password hashing [\`src/models/user.ts:67\`][]
333+
- Added JWT token generation and validation [\`src/utils/jwt.ts:12\`][]
334334
335335
## Implementation Details
336336
337-
### Authentication Flow (src/auth/middleware.ts:23)
337+
### Authentication Flow [\`src/auth/middleware.ts:23\`][]
338338
The middleware intercepts requests and validates JWT tokens. If the token is valid, the user object is attached to the request for downstream handlers to use.
339339
340-
### Password Security (src/models/user.ts:67)
340+
### Password Security [\`src/models/user.ts:67\`][]
341341
Passwords are hashed using bcrypt with a salt factor of 12. The plaintext password is never stored in the database.
342342
343343
## Design Decisions

guidance.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# AI Assistant Guidelines for Dialectic
2+
3+
## When to Present Reviews
4+
5+
Call `present_review` after making significant code changes when:
6+
- You've implemented a feature or made substantial modifications
7+
- The user asks for a review or explanation of changes
8+
- You've completed a logical unit of work that warrants documentation
9+
10+
**Don't** call for minor fixes, work-in-progress changes, or every individual file modification.
11+
12+
## Review Structure
13+
14+
### Write as Code Tours
15+
Structure reviews as guided tours through specific code locations. Lead with the code reference, then explain what's happening there and why it matters. Order sections to follow the logical flow of operations, not file order.
16+
17+
### Include Context and Reasoning
18+
Explain not just what changed, but why:
19+
- Design decisions and trade-offs made
20+
- Alternative approaches considered
21+
- Known limitations or future improvements needed
22+
23+
### Use Consistent Structure
24+
- **Summary** - High-level overview suitable for commit message
25+
- **Implementation Walkthrough** - Narrative code tour
26+
- **Design Decisions** - Rationale for key choices
27+
- **Next Steps** - Future considerations
28+
29+
## Code References
30+
31+
**CRITICAL**: Use [`filename:line`][] format for all code references:
32+
- [`src/auth.ts:23`][] - Points to specific line
33+
- [`README.md:1`][] - Points to file beginning
34+
35+
This renders as clickable links in VSCode and aligns with rustdoc conventions.
36+
37+
## Update Modes
38+
- `replace` (default) - Complete review rewrite
39+
- `update-section` - Modify specific section (specify section header)
40+
- `append` - Add new content to existing review
41+
42+
## Sample Review
43+
44+
```markdown
45+
# Add comprehensive error handling to user registration
46+
47+
## Summary
48+
Enhanced user registration endpoint with proper validation, duplicate detection,
49+
and structured error responses for better client integration.
50+
51+
## Code Tour
52+
53+
### Input Validation [`src/routes/auth.ts:34`][]
54+
55+
Here we validate email format, password strength, and required fields before
56+
processing the registration. Invalid inputs return structured error responses
57+
with specific field-level feedback rather than generic "validation failed"
58+
messages to improve UX.
59+
60+
### Duplicate Detection [`src/models/user.ts:89`][]
61+
62+
This query checks for existing accounts before creating new users. Running this
63+
check before password hashing avoids unnecessary computation on duplicate attempts
64+
and provides better performance for the common case of legitimate registrations.
65+
66+
### Error Response Handling [`src/routes/auth.ts:67`][]
67+
68+
Database operations are wrapped in try-catch blocks with specific handling for
69+
constraint violations, connection issues, and unexpected failures. Each error
70+
type returns appropriate HTTP status codes with consistent `{error, message, details}`
71+
structure across all endpoints.
72+
73+
## Design Decisions
74+
75+
- **Early duplicate detection**: Checks email uniqueness before expensive bcrypt hashing
76+
- **Structured error format**: Consistent response shape for easier client handling
77+
78+
## Next Steps
79+
80+
- Add rate limiting for registration attempts
81+
- Implement email verification workflow
82+
```

md/design/ai-guidelines.md

Lines changed: 4 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,7 @@
11
# AI Assistant Guidelines
22

3-
*This chapter defines how AI assistants should effectively use the Dialectic system. This content will eventually be incorporated into user installation instructions.*
3+
*This chapter defines how AI assistants should effectively use the Dialectic system.*
44

5-
## When to Present Reviews
6-
7-
Call `present-review` after making significant code changes when:
8-
- You've implemented a feature or made substantial modifications
9-
- The user asks for a review or explanation of changes
10-
- You've completed a logical unit of work that warrants documentation
11-
12-
**Don't** call `present-review` for:
13-
- Minor single-line fixes or typos
14-
- Work-in-progress changes that aren't ready for review
15-
- Every individual file modification during active development
16-
17-
## Review Structure Guidelines
18-
19-
### Use Narrative Style
20-
Write reviews as guided tours through the code, not just lists of changes:
21-
22-
**Good**: "When a user logs in (auth.ts:23), we first validate their credentials against the database. If successful, we generate a JWT token (auth.ts:45) and store the session..."
23-
24-
**Poor**: "Modified auth.ts lines 23-50. Added login function. Updated token generation."
25-
26-
### Include Context and Reasoning
27-
Explain not just what changed, but why:
28-
- Design decisions and trade-offs made
29-
- Alternative approaches considered
30-
- Known limitations or future improvements needed
31-
32-
### Structure with Clear Sections
33-
Use consistent markdown structure:
34-
- **Summary** - High-level overview
35-
- **Implementation Walkthrough** - Narrative code tour
36-
- **Design Decisions** - Rationale for key choices
37-
- **Next Steps** - Future considerations
38-
39-
## Code References
40-
41-
Use `file:line` format for all code references:
42-
- `src/auth.ts:23` - Points to specific line
43-
- `README.md:1` - Points to file beginning
44-
- Include context about what the reference shows
45-
46-
*TODO: Add guidelines for referencing ranges, functions, classes*
47-
48-
## Update Modes
49-
50-
### replace
51-
Use for complete review rewrites when:
52-
- The changes are too extensive for incremental updates
53-
- The review structure needs significant reorganization
54-
55-
### update-section
56-
Use to modify specific parts when:
57-
- Only certain components changed
58-
- You want to preserve other sections unchanged
59-
- Specify the section header to update
60-
61-
### append
62-
Use to add new content when:
63-
- Adding information about additional changes
64-
- Including follow-up notes or discoveries
65-
66-
## Best Practices
67-
68-
*TODO: Expand with specific examples and anti-patterns*
69-
70-
- Keep line references current by updating them as you make further changes
71-
- Use descriptive section headers that make navigation easy
72-
- Balance detail with readability - explain complex logic but don't over-document obvious code
73-
- Include rationale for non-obvious design choices
74-
75-
## Common Pitfalls
76-
77-
*TODO: Document common mistakes and how to avoid them*
78-
79-
## Integration with Socratic Shell
80-
81-
This tool works best within the collaborative patterns established by the socratic shell project:
82-
- Use reviews to facilitate dialogue, not just report status
83-
- Encourage questions and iteration rather than assuming first implementations are final
84-
- Preserve the reasoning process for future reference
5+
```
6+
{{#include ../../guidance.md}}
7+
```

server/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class DialecticMCPServer {
5252
name: 'present_review',
5353
description: [
5454
'Display a code review in the VSCode review panel.',
55-
'Reviews should be structured markdown with clear sections and actionable feedback.'
55+
'Reviews should be structured markdown with clear sections and actionable feedback.',
56+
'Use [`filename:line`][] format for file references (rustdoc-style).'
5657
].join(' '),
5758
inputSchema: {
5859
type: 'object',
@@ -64,7 +65,8 @@ class DialecticMCPServer {
6465
'1) Brief summary suitable for commit message,',
6566
'2) Detailed findings with file references,',
6667
'3) Specific suggestions for improvement.',
67-
'Use `file:line` format for code references (e.g., `src/main.ts:42`).'
68+
'Use [`filename:line`][] format for file references.',
69+
'Example: "Updated authentication in [`src/auth.rs:45`][]"'
6870
].join(' '),
6971
},
7072
mode: {

0 commit comments

Comments
 (0)