Local API for programs on the same machine: guarded pane input, delivery on failures, and a heartbeat the event stream can see
Problem
I run a small session board on the same Mac as Ovis. It lists the agent panes across my herdr desks, shows which one needs me next, and opens or resumes a session when I click it. I would like it to sit on top of Ovis's local server instead of talking to herdr and herdr-core directly, so that Ovis stays the one place that understands panes. Three gaps stop a program from using the server safely today (checked on main a81ec59):
-
Input lands wherever the pane happens to be.
POST /api/pane/inputchecks only for Claude's rewind dialog, then callspaneSendTextstraight away (server/pane-routes.ts:473-488). It does not go through the per-pane queue the WebSocket input uses (serialize(paneId),server/core/input.ts), and it has no way to say "only if this pane is still the terminal I read" or "only at an idle shell". A program that reads/api/session, decides the pane is a quiet shell, and then sendsclaude --resume <id>\rcan type that line into an agent's input box if the agent came to the front in between, or into a different terminal that herdr reused the pane id for. The idle-shell check already exists for herdr-coreagent.start(server/herdr-core/adapter.ts, the 10-second retry inserver/agent-launch.ts), but not for plain input. -
A failure does not say whether the request reached herdr.
errorResponseanswers 502 forconnect_failedandtimeoutand 404 for every otherHerdrError(server/http.ts:42). The herdr client already knows how many bytes it wrote (written,server/herdr/client.ts:321-386), and its own comment says a connected failure "must not be mistaken for proof that no request was sent", but that is not visible over HTTP. A caller cannot tell "not sent, safe to try again" from "may have been typed, read the screen first", so it either drops the request or risks typing it twice. -
A dead event stream looks alive.
/api/machines/eventssends: heartbeatevery 15 s (server/machine-api.ts:278). SSE comment lines never reachEventSource.onmessage(src/lib/eventStream.ts:45), so neither the app nor an outside listener can notice a half-open connection; they wait for the next real event.
Proposal
All three are optional and leave existing callers unchanged.
- Run
/api/pane/inputand/api/pane/keysthrough the same per-pane queue as WebSocket input, and accept optional guards:expected_terminal_id: answer 409terminal_changedif the pane now holds another terminal. The same field onPOST /api/pane/close.when: "idle_shell": send only when the foreground is the pane's interactive shell (the checkagent.startalready makes), else 409agent_pane_busy.- text into a
blockedpane needsforce: true; keys still go, so a program can still answer a menu.
- Give
HerdrErroradeliveryofnot_sent(0 bytes written) orunknown(some written), and fix the status table:not_found404,invalid_params400,cancelled/agent_blocked409,connect_failed502 withnot_sent,timeout/closed/socket_error504 withdelivery. Covered by contract tests, as.github/REVIEW.mdasks for HTTP contracts. - Send the heartbeat as a data frame (
{"type":"heartbeat"}) when nothing else was sent in the interval, and have the client close and reopen the stream after about 30 s with no message. This could sit behind afeaturesflag if older clients matter.
I can send these as three separate PRs, in this order, once you say yes to any of them.
Where
Other
Where it exists today
herdr-core, which the desktop app already bundles, does the first and third for its own clients: terminal.send waits 3 s after the last human key and refuses a blocked terminal without --force, and a subscriber that falls behind gets a missed notice with a fresh snapshot instead of silence. I am not aware of a coding-agent app that offers a local HTTP API with exactly these guards.
Workarounds and alternatives
Today my board keeps talking to herdr and herdr-core directly for these steps, and reads the screen before every send. That duplicates what Ovis already knows and breaks when herdr changes. The alternative is to keep Ovis for the phone and point the board at the Herdr app's core only, which I would rather avoid.
Related: #3867 / #3868 (opening a pane in the desktop window from another program, on hold). These requests do not depend on it.