From d529b4cda73902d1d0842d014bb39103d69494ea Mon Sep 17 00:00:00 2001 From: yuez Date: Thu, 29 Oct 2026 14:32:47 +0800 Subject: [PATCH] docs(protocol): document the plugin `bye` record MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit §2 now shows the frame (`{"v":1,"type":"bye","payload":{"reason":"stopped"}}`) and states the obligation: a plugin that stops on purpose writes one `bye` before closing a live socket, so the daemon records `plugin said bye` instead of a generic `socket closed` — which is what `src/instances/connection.ts` already does. --- docs/protocol.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/protocol.md b/docs/protocol.md index 747799c..c050e05 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -56,6 +56,8 @@ The plugin dials the daemon (`/d.sock`), sends `hello` first. {"v":1,"type":"event","sessionId":"s1","epoch":"e1","seq":11,"ts":1733234400123,"payload":{"event":{ /* SessionEvent */ }}} {"v":1,"type":"ack","id":"req-1","seq":12,"payload":{"disposition":"started"}} {"v":1,"type":"error","id":"req-1","payload":{"code":"E_LEASE","message":"session is owned by instance i-2","retryable":false}} +// deliberate disconnect: sent once before the socket closes (`:PiWebStop`, VimLeavePre) +{"v":1,"type":"bye","payload":{"reason":"stopped"}} // daemon → plugin {"v":1,"type":"cmd","id":"req-1","sessionId":"s1","payload":{"method":"prompt.send","params":{"text":"hi"},"clientRequestId":"c-9"}} @@ -69,6 +71,12 @@ The plugin dials the daemon (`/d.sock`), sends `hello` first. Plugin obligations: +- **Say `bye` when leaving on purpose.** A plugin that stops the bridge (`:PiWebStop`, `VimLeavePre`) + writes one framed `bye` (`payload.reason`) before closing the socket, and only when the connection + was live. The daemon records it as the instance's close reason (`plugin said bye`) instead of a + generic `socket closed`, so a deliberate disconnect is distinguishable from a crash; a plugin that + simply disappears stays a socket close. + - **`hello` requires `lua/pi/host.lua`.** A daemon-spawned instance is started as `nvim --headless … -u -c 'lua require("pi.host").start()'`, so the host module is what answers on a spawned workspace. Without it the daemon cannot start a workspace from the web