An open-source, faster Devin alternative
TypeScript
docs(repos): compress + lead with isolation boundary; precise API/SDK reference contracts
Igor Zalutski3e6a9b4d693a
diff --git a/docs/agent-sessions/api-reference.mdx b/docs/agent-sessions/api-reference.mdxindex 6a918024..2a111a3a 100644--- a/docs/agent-sessions/api-reference.mdx+++ b/docs/agent-sessions/api-reference.mdx@@ -53,7 +53,7 @@ const session = await oc.sessions.get("ses_..."); // server, org key</Tabs>-`agent` is **required** (create a saved [agent](#agents) first); a resolvable model [credential](#credentials) is also required (`422 no_credential` otherwise). `key` gives get-or-create (one session per key); a request-level `Idempotency-Key` header makes a keyless create retry-safe. `metadata` is opaque **application routing state** — a JSON object (≤ 16 KB) stored on the session, returned by get/list, and delivered **verbatim in webhooks** so a callback handler can route to the right external record without a lookup; it is **never** shown to the model, **not** indexed/queryable, and distinct from `key` (get-or-create) and `Idempotency-Key` (dedupe). `input` is the task — a string or a full [envelope](/agent-sessions/messaging#message-input). For the managed runtimes (`claude`, `codex`), put all task-critical context in the task text. There's no fixed byte cap on `input`, but it counts against the model's context window — **truncate large inputs** (e.g. a PR diff) and have the agent pull the rest through its [sandbox tools](/agent-sessions/runtime-tools) (clone the repo, read files) rather than inlining it. `limits` `{ tokens, turn_seconds, turns }` are **non-monetary** — token budget, per-turn wall-clock, auto-run count; hitting one ends the turn with a matching `last_turn.yield_reason`. Destinations on an idempotent create-replay are ignored — manage them via the [destinations API](#destinations).+`agent` is **required** (create a saved [agent](#agents) first); a resolvable model [credential](#credentials) is also required (`422 no_credential` otherwise). `key` gives get-or-create (one session per key); a request-level `Idempotency-Key` header makes a keyless create retry-safe. `metadata` is opaque **application routing state** — a JSON object (≤ 16 KB) stored on the session, returned by get/list, and delivered **verbatim in webhooks** so a callback handler can route to the right external record without a lookup; it is **never** shown to the model, **not** indexed/queryable, and distinct from `key` (get-or-create) and `Idempotency-Key` (dedupe). `input` is the task — a string or a full [envelope](/agent-sessions/messaging#message-input). For the managed runtimes (`claude`, `codex`), put all task-critical context in the task text. There's no fixed byte cap on `input`, but it counts against the model's context window — **truncate large inputs** (e.g. a PR diff) and have the agent pull the rest through its [sandbox tools](/agent-sessions/runtime-tools) (clone the repo, read files) rather than inlining it. `limits` `{ tokens, turn_seconds, turns }` are **non-monetary** — token budget, per-turn wall-clock, auto-run count; hitting one ends the turn with a matching `last_turn.yield_reason`. Destinations on an idempotent create-replay are ignored — manage them via the [destinations API](#destinations). `sources` checks out one or more repositories for the agent **before the first turn**; the checkout credential never enters the agent's sandbox (see [Repos](#repos)). Each entry references a registered [repo](#repos) — `{ repo, ref, sha, name? }` — or is inline — `{ url, ref, sha, name?, auth }`. `ref` (the fetch ref, e.g. `refs/pull/N/head`) and `sha` are both **required**: the ref is fetched and the exact `sha` is pinned and verified. The create response echoes sanitized `sources: [{ name, status, path, sha }]`.Client tokens accept `scopes?` (subset of `read`, `steer`) and `ttl?` seconds, clamped to 60–86400 (SDK: `ttlSeconds`).@@ -70,6 +70,14 @@ Turn = {id, state, yield_reason?, result_event_id?, error?,started_at?, completed_at?}++SessionSource = // a sources[] entry (SDK camelCase)+ { repo, ref, sha, name? } // registered repo (repo_… or "owner/repo")+ | { url, ref, sha, name?, auth } // inline; auth = the per-session credential+SourceAuth =+ { type: "token_broker", broker_url, grant } // grant: a short-lived reference, not a token+ | { type: "risky_short_lived_token", token, expires_at } // discouraged; short-lived only+SourceSummary = { name, status, path, sha } // sanitized; echoed in the create response````yield_reason` (`completed | needs_input | error | budget_exceeded | deadline_exceeded | max_turns | canceled`; `requires_action` is reserved, not emitted yet) is the machine-readable "why the turn ended" — `needs_input` means the agent asked a question; answer it by [steering](#steer).@@ -240,6 +248,47 @@ Create body: `name`, `prompt`, `model`, `runtime?` (`claude` | `codex`), `key?`,Pass `key` **or** `credential` (or neither → org default). The agent's `limits` are the defaults for its sessions; a session's own `limits` override. Each agent has a monotonic `revision` (bumped on PATCH) that sessions pin in `agent_snapshot.revision`, so you can tell which version produced a run.+## Repos++A reusable, owner-scoped connection to a Git repository — referenced from a session's `sources`. See the [Repos guide](/agent-sessions/repos) for the security model.++<Tabs>++<Tab title="TypeScript SDK">++| Call | Purpose |+| --- | --- |+| `oc.repos.create(params)` | Register (get-or-create) a repo connection. |+| `oc.repos.get(idOrSlug)` · `oc.repos.list()` | Fetch / list. |+| `oc.repos.update(id, params)` | Update `auth` / policy `defaults`. |++</Tab>++<Tab title="REST API">++| Method · Path | Purpose |+| --- | --- |+| `POST /repos` | Register (get-or-create) a repo connection. |+| `GET /repos/:id` · `GET /repos` | Fetch / list. |+| `PATCH /repos/:id` | Update `auth` / policy `defaults`. |++</Tab>++</Tabs>++Create body: `owner`, `repo`, `provider?` (`github`, default), `name?` (a handle), `auth`, `defaults?`. **Idempotent by `(provider, owner, repo)`** — a fresh register returns **201**, a repeat returns the existing repo with **200**. Stores **no GitHub token** — only the broker URL, repo identity, and policy.++`auth` — how OpenComputer obtains tokens (no standing credential is stored):+- `{ "type": "token_broker", "broker_url": "https://…" }` — your [broker](/agent-sessions/repos#what-you-provide) endpoint; OpenComputer signs each request to it, verified against its published JWKS.++`defaults` (optional policy): `{ "branch_namespace"?: "oc/{session}/", "allow"?: ["contents:read", "pull_requests:write", …] }` — `allow` is a ceiling on what any request may mint.++```+Repo = { id, provider, owner, repo, name?, broker_url?, defaults?, created_at, updated_at }+```++The response **never** contains a token or secret. (SDK is camelCase: `brokerUrl`, `branchNamespace`.)+## Credentials<Tabs>diff --git a/docs/agent-sessions/repos.mdx b/docs/agent-sessions/repos.mdxindex 2785883f..5377ff97 100644--- a/docs/agent-sessions/repos.mdx+++ b/docs/agent-sessions/repos.mdx@@ -1,33 +1,29 @@---title: "Repos"-description: "Connect a Git repository so an agent can work in it — and act on it — without ever holding your GitHub credential"+description: "Connect a private repo to your sessions behind a security boundary — the agent works on the code, GitHub access stays isolated"----A **Repo** is a registered connection to a Git repository: its identity plus how-OpenComputer obtains short-lived tokens for it. Register a repo once, then any session-can check it out and (soon) act on it — open a PR, comment, set a status — **without the-GitHub credential ever entering the agent's sandbox.**--A repo is to *where* an agent works what an [Agent](/agent-sessions/agents) is to *what*-it runs: a small, reusable, owner-scoped entity you create once and reference by id.+A **Repo** connects a Git repository to your sessions and draws a **security boundary**+around it. The agent reads and edits the checked-out code in its own sandbox, but every+authenticated GitHub operation — clone, fetch, push, PR, comment — runs in a+**separate, single-use sandbox the agent can't reach**, with a token minted just in time+and destroyed after. Registering a repo is how you set that boundary up.<Note>-**The boundary that makes this safe:** the agent can *request GitHub outcomes*, it-never receives *GitHub authority*. Your GitHub token is never placed in the agent's-shell, prompt, files, or environment. OpenComputer runs every authenticated Git/GitHub-operation in an isolated, single-use job the agent cannot reach, with a token minted-just in time for that one operation.+**Why isolate.** A GitHub token is *authority*, not just a secret — anything holding it+can push, read your other repos, or exfiltrate. So OpenComputer keeps it out of the+agent entirely: the agent requests GitHub *outcomes*, and the credential lives only in+the repo's dedicated operation sandbox, one operation at a time.</Note>-## What you provide+A Repo is to *where* an agent works what an [Agent](/agent-sessions/agents) is to *what*+it runs: a reusable, owner-scoped entity you register once and reference by id.-You own a **GitHub App** (you hold its private key) and host a small **token broker**-endpoint. OpenComputer never stores a GitHub credential; when it needs to touch GitHub-it calls your broker to mint a fresh, narrowly-scoped installation token for one-operation, uses it in an isolated job, and discards it.+## What you provide-<Tip>-Use the drop-in so you don't hand-roll the broker:+You own a **GitHub App** and host a small **token broker** endpoint. OpenComputer stores+no GitHub credential; when it needs one it calls your broker, which mints a fresh,+repo-scoped, short-lived installation token for that one operation. Use the drop-in:```tsimport { ocGithubBroker } from "@opencomputer/sdk";@@ -35,13 +31,12 @@ import { ocGithubBroker } from "@opencomputer/sdk";app.post("/oc/github-token", ocGithubBroker({appId: process.env.GITHUB_APP_ID!,privateKey: process.env.GITHUB_APP_PRIVATE_KEY!,- policy: { allowedRepos: ["acme/*"] }, // a ceiling on what any request may mint+ policy: { allowedRepos: ["acme/*"] }, // ceiling on what any request may mint}));```-It verifies OpenComputer's signed request against OpenComputer's published JWKS (so-there's no shared secret to store), checks its policy, and mints a scoped token.-</Tip>+It verifies OpenComputer's request against the published JWKS (no shared secret to+store), applies your policy, and mints the token.## Register a repo@@ -52,146 +47,79 @@ const repo = await oc.repos.create({owner: "acme",repo: "web",auth: { type: "token_broker", brokerUrl: "https://app.example.com/oc/github-token" },- defaults: { branchNamespace: "oc/{session}/" },});-// repo.id -> "repo_…"``````http REST API-POST https://api.opencomputer.dev/v3/repos+POST /v3/reposAuthorization: Bearer $OPENCOMPUTER_API_KEY-Content-Type: application/json--{- "provider": "github",- "owner": "acme",- "repo": "web",- "auth": { "type": "token_broker", "broker_url": "https://app.example.com/oc/github-token" }-}++{ "provider": "github", "owner": "acme", "repo": "web",+ "auth": { "type": "token_broker", "broker_url": "https://app.example.com/oc/github-token" } }```</CodeGroup>-`POST /repos` is **get-or-create**, owner-scoped, idempotent by `(provider, owner,-repo)` — safe to call at startup. The response never contains a secret: a registered-repo stores only the broker URL, the repo identity, and your policy defaults. **No-GitHub token is ever stored.**--<Note>-Registering a repo establishes a **connection**: your broker has agreed to mint tokens-for OpenComputer's signature-verified requests for this repo, governed by your broker's-own policy. Sessions can then reference the repo with no per-session secret. For tighter,-time-boxed authorization you can skip the connection and pass a per-session grant-inline (below).-</Note>--## Use a repo in a session+Get-or-create, owner-scoped, idempotent by `(provider, owner, repo)`. It stores only the+broker URL, repo identity, and policy defaults — **never a token**. Sessions then+reference the repo with no per-session secret.-Reference the registered repo plus the exact ref and commit to work on:+## Use it in a session```tsconst session = await oc.sessions.create({agent: agent.id,- input: "Review this pull request and suggest fixes.",- metadata: { github: { owner: "acme", repo: "web", pull: 42 } },+ input: "Review this pull request.",sources: [{ repo: repo.id, ref: "refs/pull/42/head", sha: "abc123…", name: "head" }],});--// session.sources -> [{ name: "head", status: "pending", path: "/workspace/sources/head", sha: "abc123…" }]+// checked out at /workspace/sources/head before the first turn```-The repo is checked out at `/workspace/sources/<name>` before the agent's first turn.-A session can list several sources (e.g. a PR's base and head). Each requires:--- **`ref`** — the fetch ref (a branch, or `refs/pull/N/head`). Required: fetching an- arbitrary private SHA directly isn't reliable, so OpenComputer fetches the ref, then- checks out and **verifies the exact `sha`**.-- **`sha`** — the exact commit, pinned and verified after fetch.+- **`ref`** (required) — the fetch ref (a branch or `refs/pull/N/head`); a private SHA+ can't be fetched directly.+- **`sha`** (required) — the exact commit, pinned and verified after fetch.-Sources are **immutable** for the session. To pull another ref in mid-session the agent-uses `source.fetch_ref`; to work on different source, start a new session.+A session can list several sources (a PR's base + head). Sources are **immutable**; the+agent pulls more refs mid-session via the `source.fetch_ref` tool.-### Inline, without registering--For quick use you can pass the repo inline with per-session auth — no registration:+**Inline, without registering** — pass `url` + a per-session `grant` (a short-lived+reference your app mints) instead of a registered `repo`:```ts-sources: [{- url: "https://github.com/acme/web.git",- ref: "refs/pull/42/head",- sha: "abc123…",- auth: { type: "token_broker", brokerUrl: "https://app.example.com/oc/github-token", grant: "<grant>" },-}]+sources: [{ url: "https://github.com/acme/web.git", ref: "refs/pull/42/head", sha: "abc123…",+ auth: { type: "token_broker", brokerUrl: "…", grant: "<grant>" } }]```-The `grant` is a short-lived **reference** (not a token) your app mints for this-session. Registering a repo is preferred — it moves the broker config off every create-call and lets you manage policy and (later) repo-level workflows in one place.-## What the agent can do-The agent works on the checked-out tree with normal tools (`git status`/`diff`/`log`,-edit files, run tests, local commits). Anything that needs the network is a **typed-tool** — the agent requests an outcome and OpenComputer performs it in the isolated job:+Local Git works normally on the checkout (`status`/`diff`/`log`, edit, test, local+commits). Anything needing the network is a **typed tool** run in the isolated sandbox —+the agent never runs authenticated `git`/`gh` and never sees a token:-| Tool | What it does | Status |+| Tool | Does | Status || --- | --- | --- |-| *(source already checked out)* | read + edit `/workspace/sources/<name>` | **Available** |-| `source.fetch_ref` | fetch another ref into the local repo | Coming soon |-| `github.publish_branch` / `publish_pull_request` | push the agent's changes / open a PR | Coming soon |-| `github.comment` / `github.set_status` | comment on a PR/issue, set a commit status | Coming soon |--The agent never runs authenticated `git` or `gh`, and never sees a token. Results-(branch, commit SHA, PR number/URL) come back as structured tool output.--### Write actions and grants (coming soon)--Write actions (push, PR, comment, status) need write scope. The grant or connection-authorizes a set of **operation classes** — your broker decides what to mint. A-read-only review uses read scope; a session that will open PRs uses a connection or-grant whose policy also allows the write classes. If an action isn't covered, it-resolves to **`auth_required`** (rather than failing silently or reusing read scope);-you attach an action-capable grant and it retries. Read and write authority stay-distinct — OpenComputer never widens read access in place.--## How it works, and what's guaranteed--Materialization runs in a pre-execution step before the agent starts:--1. OpenComputer calls your broker (a request **signed with OpenComputer's key**, which- your broker verifies against the public JWKS) and receives a **just-in-time,- repo-scoped, short-lived** installation token.-2. An **isolated job** — OpenComputer-operated compute the agent cannot reach — fetches- the ref, verifies the SHA, and hands the files to the session sandbox. The token- lives only in that job and is **discarded when it exits**.-3. The agent works on the files; for a write action, OpenComputer mints a fresh scoped- token the same way, performs the mutation in a clean isolated checkout, and returns- the result.--**Token lifecycle and storage:**--- OpenComputer stores **no GitHub token** — ever. A registered repo stores only the- broker URL, repo identity, and policy. A per-session grant is stored encrypted and is- a *reference*, not a credential.-- Tokens are minted **just in time, per operation**, scoped to the one repo and the- minimum permissions, short-lived, and **destroyed with the job**.-- No GitHub token appears in the agent's prompt, shell, files, environment, the event- log, or telemetry.--**Boundaries and limits:**--- Agent pushes go to an `oc/<session-id>/…` branch namespace by default — **no direct- push to protected/base branches, no force-push.**-- Submodules and Git LFS are not supported by default (clear error if required).-- If a session's sandbox is lost, the source is rehydrated from a retained workspace or- re-fetched via your broker; if neither is possible the source reports- `source.unavailable` and you re-trigger. (Recovery behavior is firming up.)-- Very large repositories add bootstrap latency; [Workspaces](/agent-sessions/workspaces)- will offer prebuilt checkouts. (Coming soon.)+| `source.fetch_ref` | fetch another ref into the checkout | Coming soon |+| `github.publish_branch` / `publish_pull_request` | push changes / open a PR | Coming soon |+| `github.comment` / `github.set_status` | comment, set a commit status | Coming soon |++Write actions need write scope; if the repo's grant doesn't cover it the action reports+`auth_required` rather than reusing read scope. *(Coming soon.)*++## Guarantees++- **No GitHub token is ever stored** — a repo holds only a broker URL + identity; a+ per-session grant is an encrypted *reference*, not a credential.+- **Tokens are minted just in time, per operation** — repo-scoped, short-lived, and+ destroyed with the isolated job. None ever reaches the agent's prompt, shell, files,+ env, the event log, or telemetry.+- Agent pushes go to an `oc/<session>/…` branch namespace — **no protected-branch push,+ no force-push.**+- Submodules and Git LFS aren't supported yet. Lost-sandbox recovery and prebuilt+ checkouts for large repos ([Workspaces](/agent-sessions/workspaces)) are firming up.<Note>-**Don't have a broker yet?** You can pass a real short-lived token inline with the-deliberately-named `risky_short_lived_token` auth. OpenComputer rejects a far-future or-missing expiry, holds it only transiently for the one job, and never stores it durably-(so the source can't be recovered after it expires). Prefer the broker.+**No broker yet?** Pass a real short-lived token inline with the deliberately-named+`risky_short_lived_token` auth. OpenComputer rejects a far-future/missing expiry, holds+it only for the one job, and never stores it (so the source can't be recovered after it+expires). Prefer the broker.</Note>