ovis icon indicating copy to clipboard operation
ovis copied to clipboard

Local API for programs on the same machine: guarded pane input, delivery on failures, and a heartbeat the event stream can see

Open fivetaku opened this issue 2 weeks ago • 0 comments

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):

  1. Input lands wherever the pane happens to be. POST /api/pane/input checks only for Claude's rewind dialog, then calls paneSendText straight 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 sends claude --resume <id>\r can 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-core agent.start (server/herdr-core/adapter.ts, the 10-second retry in server/agent-launch.ts), but not for plain input.

  2. A failure does not say whether the request reached herdr. errorResponse answers 502 for connect_failed and timeout and 404 for every other HerdrError (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.

  3. A dead event stream looks alive. /api/machines/events sends : heartbeat every 15 s (server/machine-api.ts:278). SSE comment lines never reach EventSource.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.

  1. Run /api/pane/input and /api/pane/keys through the same per-pane queue as WebSocket input, and accept optional guards:
    • expected_terminal_id: answer 409 terminal_changed if the pane now holds another terminal. The same field on POST /api/pane/close.
    • when: "idle_shell": send only when the foreground is the pane's interactive shell (the check agent.start already makes), else 409 agent_pane_busy.
    • text into a blocked pane needs force: true; keys still go, so a program can still answer a menu.
  2. Give HerdrError a delivery of not_sent (0 bytes written) or unknown (some written), and fix the status table: not_found 404, invalid_params 400, cancelled/agent_blocked 409, connect_failed 502 with not_sent, timeout/closed/socket_error 504 with delivery. Covered by contract tests, as .github/REVIEW.md asks for HTTP contracts.
  3. 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 a features flag 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.

fivetaku avatar Nov 16 '26 06:11 fivetaku