Instruction file imported from lacymorrow/pocket-agent (
.cursor/rules/extension-architecture.mdc). Copyright stays with the author.
Extension Architecture
The Pocket Agent extension follows a modular structure for interacting with both Cursor and a backend server.
Lifecycle Management
- Activation: The activate function sets up the extension, creates an output channel, and establishes connections
- Deactivation: The deactivate function cleans up resources when the extension is shut down
Core Components
-
CDP Communication: Uses WebSocket to connect to Cursor's Chrome DevTools Protocol interface
- getWebSocketDebuggerUrlJs - Finds the appropriate debug target
- sendCdpCommandJs - Sends commands to the Cursor window
- evaluateJavascriptInPageJs - Executes JavaScript in the Cursor window
-
Chat Extraction:
- readChatTextLogicJs - Reads chat text from Cursor using CDP
- parseChatTextToStructuredData - Converts raw chat text to structured message data
-
Backend Communication:
- Uses Socket.IO to maintain a WebSocket connection to the backend server
- Periodically sends chat updates to the server
-
Logging:
- Dedicated "Pocket Agent" output channel for extension logs
- Custom logging functions that write to both console and output channel