Skip to content

Commit 8f981b1

Browse files
author
Gabor Kajtar
committed
chore: adjust to new readme
2 parents 70db5c0 + 91357d8 commit 8f981b1

21 files changed

+1788
-514
lines changed

CLAUDE.md

Lines changed: 147 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ claudecode.nvim - A Neovim plugin that implements the same WebSocket-based MCP p
2222

2323
### Build Commands
2424

25+
- `make` - **RECOMMENDED**: Run formatting, linting, and testing (complete validation)
2526
- `make all` - Run check and format (default target)
27+
- `make test` - Run all tests using busted with coverage
28+
- `make check` - Check Lua syntax and run luacheck
29+
- `make format` - Format code with stylua (or nix fmt if available)
2630
- `make clean` - Remove generated test files
2731
- `make help` - Show available commands
2832

33+
**Best Practice**: Always use `make` at the end of editing sessions for complete validation.
34+
2935
### Development with Nix
3036

3137
- `nix develop` - Enter development shell with all dependencies
@@ -45,11 +51,20 @@ claudecode.nvim - A Neovim plugin that implements the same WebSocket-based MCP p
4551
### WebSocket Server Implementation
4652

4753
- **TCP Server**: `server/tcp.lua` handles port binding and connections
48-
- **Handshake**: `server/handshake.lua` processes HTTP upgrade requests
54+
- **Handshake**: `server/handshake.lua` processes HTTP upgrade requests with authentication
4955
- **Frame Processing**: `server/frame.lua` implements RFC 6455 WebSocket frames
5056
- **Client Management**: `server/client.lua` manages individual connections
5157
- **Utils**: `server/utils.lua` provides base64, SHA-1, XOR operations in pure Lua
5258

59+
#### Authentication System
60+
61+
The WebSocket server implements secure authentication using:
62+
63+
- **UUID v4 Tokens**: Generated per session with enhanced entropy
64+
- **Header-based Auth**: Uses `x-claude-code-ide-authorization` header
65+
- **Lock File Discovery**: Tokens stored in `~/.claude/ide/[port].lock` for Claude CLI
66+
- **MCP Compliance**: Follows official Claude Code IDE authentication protocol
67+
5368
### MCP Tools Architecture
5469

5570
Tools are registered with JSON schemas and handlers. MCP-exposed tools include:
@@ -76,14 +91,125 @@ Tests are organized in three layers:
7691

7792
Test files follow the pattern `*_spec.lua` or `*_test.lua` and use the busted framework.
7893

94+
### Test Organization Principles
95+
96+
- **Isolation**: Each test should be independent and not rely on external state
97+
- **Mocking**: Use comprehensive mocking for vim APIs and external dependencies
98+
- **Coverage**: Aim for both positive and negative test cases, edge cases included
99+
- **Performance**: Tests should run quickly to encourage frequent execution
100+
- **Clarity**: Test names should clearly describe what behavior is being verified
101+
102+
## Authentication Testing
103+
104+
The plugin implements authentication using UUID v4 tokens that are generated for each server session and stored in lock files. This ensures secure connections between Claude CLI and the Neovim WebSocket server.
105+
106+
### Testing Authentication Features
107+
108+
**Lock File Authentication Tests** (`tests/lockfile_test.lua`):
109+
110+
- Auth token generation and uniqueness validation
111+
- Lock file creation with authentication tokens
112+
- Reading auth tokens from existing lock files
113+
- Error handling for missing or invalid tokens
114+
115+
**WebSocket Handshake Authentication Tests** (`tests/unit/server/handshake_spec.lua`):
116+
117+
- Valid authentication token acceptance
118+
- Invalid/missing token rejection
119+
- Edge cases (empty tokens, malformed headers, length limits)
120+
- Case-insensitive header handling
121+
122+
**Server Integration Tests** (`tests/unit/server_spec.lua`):
123+
124+
- Server startup with authentication tokens
125+
- Auth token state management during server lifecycle
126+
- Token validation throughout server operations
127+
128+
**End-to-End Authentication Tests** (`tests/integration/mcp_tools_spec.lua`):
129+
130+
- Complete authentication flow from server start to tool execution
131+
- Authentication state persistence across operations
132+
- Concurrent operations with authentication enabled
133+
134+
### Manual Authentication Testing
135+
136+
**Test Script Authentication Support**:
137+
138+
```bash
139+
# Test scripts automatically detect and use authentication tokens
140+
cd scripts/
141+
./claude_interactive.sh # Automatically reads auth token from lock file
142+
```
143+
144+
**Authentication Flow Testing**:
145+
146+
1. Start the plugin: `:ClaudeCodeStart`
147+
2. Check lock file contains `authToken`: `cat ~/.claude/ide/*.lock | jq .authToken`
148+
3. Test WebSocket connection with auth: Use test scripts in `scripts/` directory
149+
4. Verify authentication in logs: Set `log_level = "debug"` in config
150+
151+
**Testing Authentication Failures**:
152+
153+
```bash
154+
# Test invalid auth token (should fail)
155+
websocat ws://localhost:PORT --header "x-claude-code-ide-authorization: invalid-token"
156+
157+
# Test missing auth header (should fail)
158+
websocat ws://localhost:PORT
159+
160+
# Test valid auth token (should succeed)
161+
websocat ws://localhost:PORT --header "x-claude-code-ide-authorization: $(cat ~/.claude/ide/*.lock | jq -r .authToken)"
162+
```
163+
164+
### Authentication Logging
165+
166+
Enable detailed authentication logging by setting:
167+
168+
```lua
169+
require("claudecode").setup({
170+
log_level = "debug" -- Shows auth token generation, validation, and failures
171+
})
172+
```
173+
174+
Log levels for authentication events:
175+
176+
- **DEBUG**: Server startup authentication state, client connections, handshake processing, auth token details
177+
- **WARN**: Authentication failures during handshake
178+
- **ERROR**: Auth token generation failures, handshake response errors
179+
180+
### Logging Best Practices
181+
182+
- **Connection Events**: Use DEBUG level for routine connection establishment/teardown
183+
- **Authentication Flow**: Use DEBUG for successful auth, WARN for failures
184+
- **User-Facing Events**: Use INFO sparingly for events users need to know about
185+
- **System Errors**: Use ERROR for failures that require user attention
186+
79187
## Development Notes
80188

189+
### Technical Requirements
190+
81191
- Plugin requires Neovim >= 0.8.0
82192
- Uses only Neovim built-ins for WebSocket implementation (vim.loop, vim.json, vim.schedule)
83-
- Lock files are created at `~/.claude/ide/[port].lock` for Claude CLI discovery
84-
- WebSocket server only accepts local connections for security
193+
- Zero external dependencies for core functionality
194+
195+
### Security Considerations
196+
197+
- WebSocket server only accepts local connections (127.0.0.1) for security
198+
- Authentication tokens are UUID v4 with enhanced entropy
199+
- Lock files created at `~/.claude/ide/[port].lock` for Claude CLI discovery
200+
- All authentication events are logged for security auditing
201+
202+
### Performance Optimizations
203+
85204
- Selection tracking is debounced to reduce overhead
205+
- WebSocket frame processing optimized for JSON-RPC payload sizes
206+
- Connection pooling and cleanup to prevent resource leaks
207+
208+
### Integration Support
209+
86210
- Terminal integration supports both snacks.nvim and native Neovim terminal
211+
- Compatible with popular file explorers (nvim-tree, oil.nvim)
212+
- Visual selection tracking across different selection modes
87213

88214
## Release Process
89215

@@ -134,6 +260,23 @@ make
134260
rg "0\.1\.0" . # Should only show CHANGELOG.md historical entries
135261
```
136262

137-
## CRITICAL: Pre-commit Requirements
263+
## Development Workflow
264+
265+
### Pre-commit Requirements
138266

139267
**ALWAYS run `make` before committing any changes.** This runs code quality checks and formatting that must pass for CI to succeed. Never skip this step - many PRs fail CI because contributors don't run the build commands before committing.
268+
269+
### Recommended Development Flow
270+
271+
1. **Start Development**: Use existing tests and documentation to understand the system
272+
2. **Make Changes**: Follow existing patterns and conventions in the codebase
273+
3. **Validate Work**: Run `make` to ensure formatting, linting, and tests pass
274+
4. **Document Changes**: Update relevant documentation (this file, PROTOCOL.md, etc.)
275+
5. **Commit**: Only commit after successful `make` execution
276+
277+
### Code Quality Standards
278+
279+
- **Test Coverage**: Maintain comprehensive test coverage (currently 314+ tests)
280+
- **Zero Warnings**: All code must pass luacheck with 0 warnings/errors
281+
- **Consistent Formatting**: Use `nix fmt` or `stylua` for consistent code style
282+
- **Documentation**: Update CLAUDE.md for architectural changes, PROTOCOL.md for protocol changes

0 commit comments

Comments
 (0)