man oscar The manual Integrations

Oscar harness protocol (v1)

The JSON-lines protocol in detail.

MANUAL / INTEGRATIONS 23 / 29

This is Oscar's protocol, not Pi's RPC. Pi's own --mode rpc protocol is documented by the Pi project; a thin adapter on the Pi side translates between the two (contrib/pi-adapter). Oscar never claims to speak Pi's RPC.

Transport: oscar serve --jsonl, records on stdin/stdout.

Framing

  • One JSON object per line, terminated by \n.
  • Split only on LF; tolerate a preceding CR. Do not treat U+2028/U+2029 as record boundaries — both are legal inside JSON strings.
  • stdout carries protocol records only. Logs go to stderr.
  • A malformed line yields a parse-error record; the process does not exit.
  • A single command may emit many events. Events for a command repeat its id.

Records

Command → Oscar

json
{"type":"command","id":"t1","command":"task.run","task":"read demo.txt"}
{"type":"command","approval_id":"a1","decision":"allow"}
{"type":"command","id":"p1","command":"ping"}

decision is allow or deny. A reason may accompany deny.

Oscar → client

json
{"type":"event","id":"t1","event":"tool.call","name":"read_file","summary":"demo.txt"}
{"type":"event","id":"t1","event":"tool.result","name":"read_file","ok":true}
{"type":"event","id":"t1","event":"approval.request","approval_id":"a1","name":"bash","summary":"ls"}
{"type":"event","id":"t1","event":"delta","text":"partial text"}
{"type":"event","id":"t1","event":"usage","prompt_tokens":10,"completion_tokens":5,"cached_tokens":0,"cache_write_tokens":0}
{"type":"event","id":"t1","event":"context.compressed","elided_tool_outputs":0,"summarized":true,"replaced":40,"tokens_before":150000,"tokens_after":30000}
{"type":"event","id":"t1","event":"output.truncated","tool_call":false,"continued":true,"limit":64000}
{"type":"event","id":"t1","event":"turn.budget","used":150,"max":150,"stopped":true}
{"type":"response","id":"t1","event":"done","ok":true,"text":"final answer"}
{"type":"response","id":"t1","event":"done","ok":false,"code":"provider_error","message":"..."}

turn.budget with stopped: false warns that the turn's budget of model calls is nearly used; with stopped: true the turn ended at the budget and done carries the model's summary of where it stopped. The model's reasoning is never sent to clients.

Rules

  1. Exactly one terminal done per command id.
  2. Approvals carry their own approval_id, never the turn id — one turn may raise several. Answer with a command record quoting that approval_id.
  3. Timeout or disconnect denies. The server waits 60 s, then denies. A missing answer is never an allow.
  4. summary is sanitized for display: a short phrase or the first line of a command, capped at 80 chars. It is not a place for tool output.
  5. Error codes are stable: unknown_command, busy, approval_timeout, provider_error, internal.
  6. The harness grants no capability. It cannot widen confinement, approve its own escalation, or read anything the runtime could not already read.

Minimal exchange

text
→ {"type":"command","id":"t1","command":"task.run","task":"read demo.txt"}
← {"type":"event","id":"t1","event":"tool.call","name":"read_file","summary":"demo.txt"}
← {"type":"event","id":"t1","event":"tool.result","name":"read_file","ok":true}
← {"type":"event","id":"t1","event":"delta","text":"demo says: "}
← {"type":"event","id":"t1","event":"delta","text":"hello oscar"}
← {"type":"response","id":"t1","event":"done","ok":true,"text":"demo says: hello oscar"}

Conformance

crates/oscar-harness/tests/roundtrip.rs exercises this document in-process (fake client). The adapter has been run against a real Pi release (1.6.0) for a task with an approval round trip.