A globally installable WebSocket client that runs as a child process with structured logging capabilities, designed for communication between Cursor IDE and Roo extension.
- Node.js >= 18.0.0
- pnpm >= 8.0.0
Install globally using pnpm (recommended):
pnpm add -g @cursor/socket-server
Or using npm:
npm install -g @cursor/socket-server
Or using yarn:
yarn global add @cursor/socket-server
Basic usage with default URL (ws://localhost:8080):
cursor-socket
Specify a different URL:
cursor-socket "ws://example.com:8080"
Connect to a specific port (useful for multiple Roo instances):
cursor-socket "ws://localhost" 8080
cursor-socket "ws://localhost" 8081 # Another instance
You can run multiple instances of the client to connect to different Roo servers:
# Terminal 1 - Connect to Roo instance on port 8080
cursor-socket "ws://localhost" 8080
# Terminal 2 - Connect to another Roo instance on port 8081
cursor-socket "ws://localhost" 8081
The client uses a structured message protocol for communication:
- System Messages:
{
role: 'system',
type: 'initialization' | 'configuration' | 'termination',
content: string
}
- User Messages:
{
role: 'user',
type: 'command' | 'query' | 'response',
content: string
}
- AI Messages:
{
role: 'ai',
type: 'completion' | 'analysis' | 'suggestion',
content: string
}
The client handles these WebSocket events:
- Connection Events:
{
"type": "connection",
"status": "connected",
"data": "ws://localhost:8080"
}
- Message Events:
{
"type": "message",
"data": {
"role": "user",
"type": "command",
"content": "analyze code"
}
}
- Error Events:
{
"type": "error",
"message": "Connection failed"
}
The client uses Winston for robust logging, writing all activity to ~/.cursor-socket.log
. Logs are automatically rotated (5MB max size, keeping last 5 files) and include colorized console output.
View logs using the built-in commands:
# View last 10 lines of logs
cursor-socket-logs tail
# View last N lines of logs
cursor-socket-logs tail 20
# Follow logs in real-time
cursor-socket-logs follow
Logs are stored in a concise JSON format with Winston enhancements:
{
"t": "10:30:45 PM",
"l": "INFO",
"m": "WebSocket connected",
"d": {
"url": "ws://localhost:8080",
"data": {
"role": "system",
"type": "initialization",
"content": "Connected to Roo instance"
}
}
}
Fields:
t
: Timestamp (human-readable time)l
: Log level (INFO, ERROR, DEBUG)m
: Messaged
: Additional data (optional)meta
: Structured message data (when applicable)
-
Log Rotation:
- Maximum file size: 5MB
- Keeps last 5 log files
- Automatic rotation
-
Console Output:
- Colorized by log level
- Real-time display
- Formatted for readability
-
Log Types:
Connection Events:
{"t":"10:30:45 PM","l":"INFO","m":"WebSocket connected","d":{"url":"ws://localhost:8080"}} {"t":"10:30:46 PM","l":"INFO","m":"WebSocket disconnected"}
Message Events:
{"t":"10:30:47 PM","l":"DEBUG","m":"Sent message to WebSocket","d":{"message":"Hello"}} {"t":"10:30:48 PM","l":"DEBUG","m":"Received WebSocket message","d":{"data":"Response"}}
Error Events (with stack traces):
{"t":"10:30:49 PM","l":"ERROR","m":"Failed to send message","d":{"reason":"Client not connected","stack":"..."}}
index.ts
: Main WebSocket manager that spawns and manages the client processwsClient.ts
: WebSocket client implementation that runs as a child processlogs.ts
: Command-line interface for viewing logstypes.ts
: TypeScript type definitions for messages and logging
- Clone the repository:
git clone https://github.com/cursor/socket-server.git
cd socket-server
- Install dependencies:
pnpm install
- Run locally:
pnpm start
- Run tests:
# Run tests once
pnpm test
# Run tests in watch mode
pnpm test:watch
- Lint code:
# Check for linting issues
pnpm lint
# Fix linting issues
pnpm lint:fix
ISC