An open-source, faster Devin alternative
TypeScript
docs(agent-sessions): align v3 docs with design — structured work product + ergonomics
Igor Zalutski8241fba12d94
diff --git a/docs/agent-sessions/api-reference.mdx b/docs/agent-sessions/api-reference.mdxindex e8105dae..4e2b4b16 100644--- a/docs/agent-sessions/api-reference.mdx+++ b/docs/agent-sessions/api-reference.mdx@@ -9,32 +9,41 @@ Base URL `https://api.opencomputer.dev/v3`. Management calls authenticate with y| Method · Path | Purpose || --- | --- |-| `POST /sessions` | Start a session. Body: `agent?`, `prompt?`, `model?`, `runtime?`, `input`, `key?`, `webhook?`, `destinations?[]`. Returns `{ session, client_token }`. |+| `POST /sessions` | Start a session. Body: `agent?`, `prompt?`, `model?`, `runtime?`, `input`, `key?`, `webhook?`, `destinations?[]`, `max_usd?`, `max_turn_seconds?`, `max_turns?`. Returns `{ session, client_token }`. || `GET /sessions/:id` | Fetch a session. |-| `GET /sessions` | List sessions. |-| `POST /sessions/:id/archive` | Archive (close) a session. |+| `GET /sessions?status=&agent=&key=&after=&before=&limit=` | List sessions (filtered, paginated). |+| `POST /sessions/:id/archive` | Cancel any active turn, then close (read-only). |+| `POST /sessions/:id/cancel` | Cooperatively stop the active turn (no-op if not running). |+| `GET /sessions/:id/result` | The result helper — `{ last_turn, result? }` (the resolved final event). |+| `GET /sessions/:id/turns` · `GET …/turns/:turnId` | Per-turn history: timing, usage, error. || `POST /sessions/:id/client-tokens` | Mint a client token. Body: `scopes?`, `ttl?`. |-Provide `agent` (a saved agent id) **or** inline `prompt` + `model` + `runtime`. `key` gives get-or-create (one session per key); a request-level `Idempotency-Key` header makes a keyless create retry-safe. `input` is the task — a string or a full [envelope](/agent-sessions/messaging#the-envelope).+Provide `agent` (a saved agent id) **or** inline `prompt` + `model` + `runtime`. `key` gives get-or-create (one session per key); a request-level `Idempotency-Key` header makes a keyless create retry-safe. `input` is the task — a string or a full [envelope](/agent-sessions/messaging#the-envelope) (structured context rides `input.refs`: `repo`/`branch`/`commit`/`issue`/…). The bounds `max_usd` / `max_turn_seconds` / `max_turns` cap spend, per-turn wall-clock, and auto-runs; hitting one ends the turn with a matching `last_turn.yield_reason`.```Session = { id, status, head, cursor,agent_snapshot: { prompt_hash, model, runtime },- last_turn: { state, turn_id, started_at, completed_at?, result_event_id?, error?, budget_exceeded? },- usage: { active_seconds, usd, cap_usd?, tokens? }, key?, created_at }+ last_turn: { state, yield_reason?, turn_id, started_at, completed_at?, result_event_id?, error?, budget_exceeded? },+ usage: { active_seconds, usd, cap_usd?, tokens? },+ limits: { max_usd?, max_turn_seconds?, max_turns? }, key?, created_at }```+`yield_reason` (`completed | needs_input | error | budget_exceeded | deadline_exceeded | max_turns | canceled`) is the machine-readable "why the turn ended" — `needs_input` means the agent asked a question; answer it by [steering](#steer).+## Events| Method · Path | Purpose || --- | --- |-| `GET /sessions/:id/events?after=<seq>&level=<lvl>&limit=<n>` | Read events since a cursor. |+| `GET /sessions/:id/events?after=<seq>&level=<lvl>&kind=&type=&turn_id=&limit=<n>` | Read events since a cursor (filter by `kind`, `body.type`, or `turn_id`). || `GET /sessions/:id/events?after=<seq>&level=<lvl>&stream=sse` | Live SSE stream from a cursor. |+| `GET /sessions/:id/events/:eventId` | Fetch one event (resolve `result_event_id`). |+| `GET /sessions/:id/events/:eventId/content` | Fetch a blob-backed body (large outputs/artifacts). |+| `GET /sessions/:id/messages?after=<seq>&limit=<n>` | User-message history (alias for `level=user` + `kind=message`). |-`after` resumes from a `seq`; `level` is the max [level](/agent-sessions/events#levels) to receive.+`after` resumes from a `seq`; `level` is a **visibility threshold** — `user` returns only user-facing events, `progress` adds work updates, `internal` adds everything (see [levels](/agent-sessions/events#levels)). Switch on [`body.type`](/agent-sessions/events#event-shape), don't parse prose.```-Event = { id, seq, ts, session, actor, kind, level, body, refs }+Event = { id, seq, ts, session, actor, kind, level, body, refs, operation_key? }```## Steer@@ -87,3 +96,7 @@ Delivery = { id, destination_id, event_id, status, attempts, last_attempt_at,Credential = { id, provider, name?, last4, created_at }ClientToken = { token, scopes, expires_at }```++## Errors & rate limits++Errors use one envelope: `{ "error": { "type", "message", "code", "param?", "request_id" } }`. Cross-owner resources return `404` (not `403`). Over a rate or concurrency limit, calls return **`429`** with a **`Retry-After`** header — back off and retry.diff --git a/docs/agent-sessions/authentication.mdx b/docs/agent-sessions/authentication.mdxindex 0eb347a5..ed7b6703 100644--- a/docs/agent-sessions/authentication.mdx+++ b/docs/agent-sessions/authentication.mdx@@ -30,6 +30,8 @@ curl https://api.opencomputer.dev/v3/sessions/$ID/client-tokens \The pattern: your backend creates the session with the org key, then hands the `client_token` to the browser, which uses it directly for the SSE stream and steer calls.+<Warning>A client token can **spend**: each `steer` starts a turn, which incurs model cost on the session it's scoped to. Mint short-lived tokens, and rely on the session's [bounds](/agent-sessions/sessions#bounds) (`max_usd`/`max_turn_seconds`/`max_turns`) to cap exposure.</Warning>+```browser ──(create task)──▶ your backend ──(org key)──▶ POST /v3/sessionsbrowser ◀──(client_token)── your backenddiff --git a/docs/agent-sessions/events.mdx b/docs/agent-sessions/events.mdxindex 1befaba0..79ee06c5 100644--- a/docs/agent-sessions/events.mdx+++ b/docs/agent-sessions/events.mdx@@ -9,7 +9,8 @@ Every step a session takes is an **event**, appended to the log in order. The lo{ "id": "evt_…", "seq": 12, "ts": "…", "session": "sess_…","actor": { "id": "agent", "type": "agent" },"kind": "message", "level": "user",- "body": { "text": "3 tests fail in auth.spec.ts" }, "refs": {} }+ "body": { "type": "agent.message", "text": "3 tests fail in auth.spec.ts", "final": true },+ "refs": {} }```- **`id`** — the event's own unique id (`evt_…`). The client idempotency key for steering is separate (deduped per session — see [steering](/agent-sessions/messaging)).@@ -20,7 +21,25 @@ Every step a session takes is an **event**, appended to the log in order. The loInbound and outbound messages share one [envelope](/agent-sessions/messaging#the-envelope) shape.-## Levels — pick what to show+## Event shape++The three `kind`s stay small; the **stable contract is `body.type`** — switch on it, **don't parse prose.** Unknown types render fine from their `text`/`summary`, so new ones are additive.++| `kind` · `body.type` | `body` shape | Use it for |+| --- | --- | --- |+| `message` · `agent.message` | `{ text, final? }` | agent output; the result is the `final` one (= `last_turn.result_event_id`) |+| `message` · `user.message` | `{ text }` | a steer you sent |+| `status` · `turn.started` | `{ turn_id }` | a turn began |+| `status` · `turn.completed` | `{ turn_id, yield_reason, result_event_id? }` | **the "done" signal — await this** |+| `status` · `tool.call` | `{ tool, args_summary }` | the agent invoked a tool |+| `status` · `exec.completed` | `{ command, exit_code, summary, content_ref?, bytes? }` | a finished command |+| `error` · `error.*` | `{ code, message, retriable? }` | a failure |++**Coming soon** (already shaped, additive): `test.results`, `diff`/`patch`, `artifact`, `pr.result`, `preview.url`.++**Artifacts & large output.** Any event may carry `refs.artifacts[]` = `[{ name, content_ref | url, content_type, bytes }]`, and a large `body` is offloaded to a `content_ref`. Fetch the bytes with `GET /sessions/:id/events/:eventId/content` — that's how you render diffs, command logs, generated files, screenshots, and reports.++## LevelsEvery event carries a `level` saying **who it's for**. You filter the stream (and webhook deliveries) by it, so each surface shows the right amount of detail.diff --git a/docs/agent-sessions/messaging.mdx b/docs/agent-sessions/messaging.mdxindex 940eabaa..64031809 100644--- a/docs/agent-sessions/messaging.mdx+++ b/docs/agent-sessions/messaging.mdx@@ -39,6 +39,7 @@ Every inbound and outbound message normalizes to this shape. The core fields are- **`actor`** — who sent it (`human` | `agent` | `system`), namespaced.- **`conversation`** — an opaque reply/routing anchor.- **`text`** — the content the agent reads (or that you receive).+- **`refs`** — structured context the agent shouldn't have to infer from prose. Blessed keys: `repo`, `branch`, `commit`, `ref`, `issue`, `pr` (plus your own). Pass them on the initial `input` so a coding agent knows its target.- **`raw`** — untouched original payload; optional, never read by the core.To get a session's output **out**, register a webhook destination — see [Webhooks](/agent-sessions/webhooks).diff --git a/docs/agent-sessions/overview.mdx b/docs/agent-sessions/overview.mdxindex 9ce6b80d..feb7336c 100644--- a/docs/agent-sessions/overview.mdx+++ b/docs/agent-sessions/overview.mdx@@ -34,7 +34,7 @@ The non-trivial parts you'd otherwise build — and get subtly wrong — handledThe agent's loop runs separately from the sandbox where its file changes and commands execute — the untrusted work is contained, apart from the loop and your model credentials.</Card><Card title="Durable log & resume" icon="database">- Every step is recorded in a durable event log. Reconnect from any point and resume exactly where you left off — nothing lost or replayed.+ Every step is recorded in a durable event log. Reconnect from any point and the event stream resumes exactly where you left off — no events missed or duplicated.</Card></CardGroup>diff --git a/docs/agent-sessions/quickstart.mdx b/docs/agent-sessions/quickstart.mdxindex 23652bdc..e057f05a 100644--- a/docs/agent-sessions/quickstart.mdx+++ b/docs/agent-sessions/quickstart.mdx@@ -24,9 +24,9 @@ curl https://api.opencomputer.dev/v3/sessions \"webhook": "https://your.app/oc-webhook" }'```-```json+```jsonc{- "session": { "id": "sess_abc", "status": "running", "head": 0, "cursor": 0 },+ "session": { "id": "sess_abc", "status": "queued", "head": 0, "cursor": 0 },"client_token": "ct_…" // session-scoped; safe to hand to a browser (read + steer)}```diff --git a/docs/agent-sessions/runtime-tools.mdx b/docs/agent-sessions/runtime-tools.mdxnew file mode 100644index 00000000..1ab60536--- /dev/null+++ b/docs/agent-sessions/runtime-tools.mdx@@ -0,0 +1,38 @@+---+title: "Claude runtime tools"+description: "The tools the claude runtime can use — what to rely on when you write prompts"+---++When you write a prompt for the `claude` [runtime](/agent-sessions/runtimes), it's useful to know exactly what the agent can do. Every side effect runs through a fixed set of tools against the session's **sandbox** — the agent has no direct filesystem, shell, or network of its own. The built-in local tools are disabled; only these remote tools are available.++## Working in the sandbox++| Tool | What it does |+| --- | --- |+| `bash` | Run a shell command in the sandbox — the **only** place commands run. Each call is a fresh shell, so use absolute paths or `cd /workspace && …`. Returns exit code + stdout/stderr. |+| `read` | Read a file from the sandbox. |+| `write` | Write a file to the sandbox. |+| `ls` | List a directory in the sandbox. |+| `use_repo` | Clone/check out a repository into the workspace to work on it. |++These map to events you can stream: a `bash` run surfaces as a `status` · `exec.completed` event (`{ command, exit_code, summary }`), with large output available via [`content_ref`](/agent-sessions/events#event-shape).++## Talking to the user++| Tool | What it does |+| --- | --- |+| `say` | Emit a message to the user — a `user`-level [`message`](/agent-sessions/events) event. The agent's final `say` is the session's result. |+| `ask` | Ask the user a question and **pause** — the turn ends with `yield_reason: "needs_input"`. Answer by [steering](/agent-sessions/messaging) a reply, which wakes the session. |++<Note>`ask` is how an agent gets a decision today. The turn yields rather than blocking; your app sees `last_turn.yield_reason = "needs_input"` and replies with a steer. The formal blocking `ask` state is coming soon.</Note>++## Delivering work to external systems++`deliver` (open/update a pull request or post a comment) and `reconcile` (declare the desired end state and let the platform converge to it) are how an agent acts **outside** the sandbox. They land with the channel launches (GitHub, etc.); until then, get a session's output out via [webhooks](/agent-sessions/webhooks) — the agent's `user`-level messages and results are delivered there.++## Writing good prompts++- Tell the agent to do all work in the sandbox via `bash`/`read`/`write` — it can't touch your machine.+- To work on a repo, point it at one (`use_repo`, or `bash` + `git clone` for a public repo); pass the target in [`input.refs`](/agent-sessions/messaging) (`repo`, `branch`, `commit`) rather than burying it in prose.+- Have it `say` a clear final result — that's what `GET /sessions/:id/result` returns.+- Have it `ask` only when it genuinely needs a decision; otherwise it should proceed.diff --git a/docs/agent-sessions/sessions.mdx b/docs/agent-sessions/sessions.mdxindex 089362d5..5f452561 100644--- a/docs/agent-sessions/sessions.mdx+++ b/docs/agent-sessions/sessions.mdx@@ -18,11 +18,31 @@ A **session** is the durable unit of an [agent](/agent-sessions/agents) at work:| Status | Meaning || --- | --- |+| `queued` | Scheduled; a turn hasn't started running yet. || `running` | A turn is executing. || `idle` | Quiescent and steerable; the sandbox is hibernated. || `failed` | The session errored out. || `archived` | Closed; read-only. |-A session also carries `last_turn = { state: "running" | "ok" | "error", turn_id, started_at, completed_at?, result_event_id?, error?, budget_exceeded? }` and a `usage` summary (`active_seconds`, `usd`). Together with the status, these tell you whether a one-shot **finished**, is **waiting for steer**, or **stopped** on an error or budget cap — and what it produced. By convention the **final result is a `user`-level [`message`](/agent-sessions/events) event**.+A session also carries `last_turn = { state, yield_reason?, turn_id, started_at, completed_at?, result_event_id?, error?, budget_exceeded? }` and `usage` (`active_seconds`, `usd`). The **`yield_reason`** tells you *why* the last turn ended — `completed`, `needs_input` (the agent asked a question; answer by [steering](/agent-sessions/messaging)), `budget_exceeded` / `deadline_exceeded` / `max_turns` (a [bound](#bounds) tripped), or `canceled`.-<Note>Blocking on input mid-turn (`ask` / awaiting-input) is coming soon. Today, steer is fire-and-continue: send a message and the session incorporates it on its next turn.</Note>+## Get the result++Don't sniff prose for "is it done." Await the **`status` · `turn.completed`** event (on the [stream](/agent-sessions/events) or a [webhook](/agent-sessions/webhooks)), then fetch the answer:++```bash+curl https://api.opencomputer.dev/v3/sessions/$ID/result \+ -H "Authorization: Bearer $OPENCOMPUTER_API_KEY"+# → { "last_turn": { "state": "ok", "yield_reason": "completed", "result_event_id": "evt_…" },+# "result": { "kind": "message", "body": { "type": "agent.message", "text": "…", "final": true } } }+```++## Bounds++Cap a session at create (or default it on the [agent](/agent-sessions/agents)): `max_usd`, `max_turn_seconds` (per-turn wall-clock), `max_turns`. Hitting one ends the turn with the matching `yield_reason`.++## Stop a session++`POST /sessions/:id/cancel` cooperatively stops the active turn and stops billing; `POST /sessions/:id/archive` cancels any active turn, then closes the session read-only.++<Note>Blocking on input mid-turn (formal `ask` / awaiting-input) is coming soon. Today the agent signals it needs input via `yield_reason: "needs_input"`, and you reply by [steering](/agent-sessions/messaging) — fire-and-continue.</Note>diff --git a/docs/agent-sessions/webhooks.mdx b/docs/agent-sessions/webhooks.mdxindex 31cf8764..cd2acd61 100644--- a/docs/agent-sessions/webhooks.mdx+++ b/docs/agent-sessions/webhooks.mdx@@ -12,11 +12,13 @@ curl https://api.opencomputer.dev/v3/sessions/$ID/destinations \-H "Authorization: Bearer $OPENCOMPUTER_API_KEY" \-d '{ "url": "https://your.app/oc-webhook","secret": "whsec_…",- "level": "user", // user (default) | progress- "kinds": ["message"], // optional allow-list; default all- "include_raw": false }' // strip raw from the delivered envelope+ "level": "user",+ "kinds": ["message"],+ "include_raw": false }'```+`level` is the visibility threshold (`user` default, or `progress`); `kinds` is an optional allow-list (default: all); `include_raw: false` strips `raw` from the delivered envelope.+| Method · Path | Purpose || --- | --- || `POST /sessions/:id/destinations` | Register a destination. |@@ -57,13 +59,17 @@ Delivery = { id, destination_id, event_id, status, attempts, last_attempt_at, re```jsimport { createHmac, timingSafeEqual } from "node:crypto";-function verify(req, secret, body) { // body = the RAW request body string, read before JSON.parse- const ts = req.headers["x-oc-timestamp"];- if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; // reject stale → replay guard- const expected = createHmac("sha256", secret).update(`${ts}.${body}`).digest("hex");+// body = the RAW request body string, read BEFORE JSON.parse+function verify(req, secret, body) {+ const ts = req.headers["x-oc-timestamp"];const got = req.headers["x-oc-signature"];- return got.length === expected.length &&- timingSafeEqual(Buffer.from(got), Buffer.from(expected));+ if (!ts || !got) return false; // missing headers → reject+ if (!/^\d+$/.test(ts) || Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; // bad/stale ts → replay guard+ const expected = createHmac("sha256", secret).update(`${ts}.${body}`).digest("hex");+ let a, b;+ try { a = Buffer.from(got, "hex"); b = Buffer.from(expected, "hex"); } // decode hex explicitly+ catch { return false; } // malformed signature+ return a.length === b.length && timingSafeEqual(a, b); // constant-time compare}```diff --git a/docs/docs.json b/docs/docs.jsonindex fcb0745c..a899d78f 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -71,6 +71,7 @@"agent-sessions/messaging","agent-sessions/webhooks","agent-sessions/runtimes",+ "agent-sessions/runtime-tools","agent-sessions/api-reference"]},