Expand description
Socket-based IPC for editor plugin communication.
Uses Unix domain sockets (Linux/macOS) or Windows named pipes via the
interprocess crate. The socket replaces the file-based IPC mechanism
(NIO WatchService + patch files) for lower latency and no inotify issues.
§Architecture
- Listener (plugin side): The editor plugin starts a socket listener
at
.agent-doc/ipc.sock. It accepts connections and processes JSON messages. - Sender (CLI side): The
agent-doc writecommand connects to the socket and sends patch JSON. Falls back to file-based IPC if socket unavailable.
§Protocol
Messages are newline-delimited JSON (NDJSON). Each message is a single line
terminated by \n. The receiver reads lines and parses each as JSON.
Message types:
{"type": "patch", "file": "...", "patches": [...], "frontmatter": "..."}— apply patches{"type": "reposition", "file": "..."}— reposition boundary marker{"type": "vcs_refresh"}— trigger VCS refresh{"type": "ack", "id": "..."}— acknowledgment from plugin
Functions§
- is_
listener_ active - Check if a socket listener is active.
- send_
message - Send a JSON message to the plugin via socket IPC. Returns Ok(response) if the plugin acknowledges, Err if socket unavailable.
- send_
patch - Send a patch message to the plugin.
- send_
reposition - Send a reposition boundary message.
- send_
vcs_ refresh - Send a VCS refresh signal.
- socket_
path - Get the socket path for a project.
- start_
listener - Start a socket listener (for use by the FFI library / plugin). This blocks the calling thread — run it on a background thread.