Skip to main content

Module ipc_socket

Module ipc_socket 

Source
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 write command 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.