An open-source, faster Devin alternative
TypeScript
docs/sdk(repos): contract coherence + broker security (review round)
Igor Zalutskiece2e4a4637b
diff --git a/docs/agent-sessions/api-reference.mdx b/docs/agent-sessions/api-reference.mdxindex 2a111a3a..db169381 100644--- a/docs/agent-sessions/api-reference.mdx+++ b/docs/agent-sessions/api-reference.mdx@@ -32,6 +32,7 @@ const session = await oc.sessions.get("ses_..."); // server, org key| `session.cancel()` | Cooperatively stop the active turn (no-op if not running). || `session.result()` | `{ lastTurn, result? }` — the resolved final event. || `session.turns()` · `session.turn(id)` | Per-turn history: timing, error. |+| `session.sources` | Source checkout status — `SourceSummary[]`. || `session.mintClientToken(opts)` | Mint a client token. |</Tab>@@ -47,6 +48,7 @@ const session = await oc.sessions.get("ses_..."); // server, org key| `POST /sessions/:id/cancel` | Cooperatively stop the active turn (no-op if not running). || `GET /sessions/:id/result` | The result helper — `{ last_turn, result? }`. || `GET /sessions/:id/turns` · `…/turns/:turnId` | Per-turn history: timing, error. |+| `GET /sessions/:id/sources` | Source checkout status (`SourceSummary[]`). || `POST /sessions/:id/client-tokens` | Mint a client token. |</Tab>@@ -71,13 +73,14 @@ Turn = {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+SessionSource = // a sources[] entry — WIRE shape (SDK is+ { repo, ref, sha, name? } // camelCase: brokerUrl, expiresAt)+ | { url, ref, sha, name?, auth } // name defaults to the repo name; type defaults "git"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+SourceSummary = { name, status, path, sha } // sanitized; in the create response + GET …/sources+// status: pending | materializing | resolved | failed | unavailable | auth_required````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).@@ -287,7 +290,16 @@ Create body: `owner`, `repo`, `provider?` (`github`, default), `name?` (a handleRepo = { 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`.)+The response **never** contains a token or secret. (SDK is camelCase: `brokerUrl`, `branchNamespace`.) `defaults.allow` is a **GitHub permission ceiling** (e.g. `contents:read`, `pull_requests:write`) — not a free-form list.++**Broker request** (the contract your `broker_url` implements). At materialization OpenComputer `POST`s your broker a **signed** request (verify against OpenComputer's published JWKS):++```+→ { owner_id, repo, operation, permissions, ref, sha } // signed by OpenComputer+← { token, expires_at, permissions } // a JIT installation token+```++**Bind `owner_id` to your OpenComputer org** (allowlist or a one-time registration) so a foreign org can't point at your broker URL and mint tokens for your installation. Mint only the intersection of your grant/policy and the requested scope — never broader. See the [Repos guide](/agent-sessions/repos#what-you-provide).## Credentialsdiff --git a/docs/agent-sessions/repos.mdx b/docs/agent-sessions/repos.mdxindex 5377ff97..e77f53a0 100644--- a/docs/agent-sessions/repos.mdx+++ b/docs/agent-sessions/repos.mdx@@ -19,24 +19,29 @@ the repo's dedicated operation sandbox, one operation at a time.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.-## What you provide+<Note>**Status — in active rollout.** Today a session accepts inline `sources` at+create (below). Registered **Repos**, the broker drop-in, automatic checkout, and the+GitHub tools are landing now; this page is the target contract.</Note>-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:+## What you provide-```ts-import { ocGithubBroker } from "@opencomputer/sdk";+You own a **GitHub App** (you hold its private key) and host a small **token broker**+endpoint. OpenComputer stores no GitHub credential; at materialization it calls your+broker with a **signed** request, and your broker mints a fresh, repo-scoped,+short-lived installation token for that one operation. Your broker:-app.post("/oc/github-token", ocGithubBroker({- appId: process.env.GITHUB_APP_ID!,- privateKey: process.env.GITHUB_APP_PRIVATE_KEY!,- policy: { allowedRepos: ["acme/*"] }, // ceiling on what any request may mint-}));-```+1. **Verifies the request is OpenComputer's** — each request is signed; verify it+ against OpenComputer's published JWKS (no shared secret for you to store).+2. **Binds it to your org** — the request carries the OpenComputer `owner_id`, the+ `repo`, and the `operation`. Confirm the `owner_id` is *your* OpenComputer org (an+ allowlist, or a one-time registration handshake) — so another customer can't point+ at your broker URL and have it mint tokens for your installation (confused-deputy).+3. **Mints to the policy, never more** — issue an installation token scoped to that+ repo and the minimum permissions the operation needs, with a short TTL.-It verifies OpenComputer's request against the published JWKS (no shared secret to-store), applies your policy, and mints the token.+<Note>A drop-in `ocGithubBroker()` that does all three is **coming soon**. Until then,+implement the contract above — it's a thin wrapper over your existing GitHub App+client. See the [broker contract](/agent-sessions/api-reference#repos) for exact shapes.</Note>## Register a repo@@ -119,7 +124,8 @@ Write actions need write scope; if the repo's grant doesn't cover it the action<Note>**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.+`risky_short_lived_token` auth. OpenComputer rejects a far-future/missing expiry, stores+it **encrypted** only until the first checkout, then purges it — it never becomes a+durable credential, and the source can't be recovered once the token expires. Prefer the+broker.</Note>diff --git a/docs/agent-sessions/runtime-tools.mdx b/docs/agent-sessions/runtime-tools.mdxindex 6cf0fbb6..8d976a09 100644--- a/docs/agent-sessions/runtime-tools.mdx+++ b/docs/agent-sessions/runtime-tools.mdx@@ -17,7 +17,7 @@ When you write a prompt for a [runtime](/agent-sessions/runtimes) (`claude` or ``bash` is the only place commands run. Each call is a fresh shell, so use absolute paths or `cd /workspace && ...`. A run surfaces as an [`exec.completed`](/agent-sessions/events#event-shape) event (`{ command, exit_code, summary }`), with large output available via `content_ref`.-To work on a repo, the agent `git clone`s it via `bash` — the sandbox has open outbound internet (below). Prepared [workspaces](/agent-sessions/workspaces) and private-repo access are coming soon.+To work on a **public** repo, the agent `git clone`s it via `bash` — the sandbox has open outbound internet (below). For **private** repos, register a [Repo](/agent-sessions/repos) and reference it in the session's `sources`: it's checked out before the first turn and the GitHub credential never enters the sandbox. Prepared [workspaces](/agent-sessions/workspaces) are coming soon.<Note>**Network:** the sandbox has **open outbound internet** by default (so `git clone`, package installs, and API calls just work), with private, loopback, link-local, and cloud-metadata addresses blocked. Per-agent egress allowlists are coming.</Note>@@ -39,6 +39,6 @@ The agent's final `say` is the session result. `ask` ends the turn with `yield_r## Prompt guidance- 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, include the repo URL and branch or commit in the task text, then have the agent `git clone` it with `bash`. Public repos work today; private-repo connections are coming soon.+- **Public repo:** include the URL + branch/commit in the task text and have the agent `git clone` it with `bash`. **Private repo:** register a [Repo](/agent-sessions/repos) and list it in the session's `sources` — checked out before the first turn, no credential in the sandbox.- 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/sdks/typescript/src/agents/repos.ts b/sdks/typescript/src/agents/repos.tsindex 9c7b4194..b8edbe90 100644--- a/sdks/typescript/src/agents/repos.ts+++ b/sdks/typescript/src/agents/repos.ts@@ -20,7 +20,8 @@ export type RepoAuth = {export interface RepoDefaults {/** Branch namespace for agent pushes; default `oc/{session}/`. No protected/base push. */branchNamespace?: string;- /** Operation classes this repo may ever authorize (a ceiling; the broker still decides per call). */+ /** GitHub permission ceiling (e.g. `contents:read`, `pull_requests:write`) this repo+ * may ever authorize — a ceiling; the broker still decides what to mint per call. */allow?: string[];}diff --git a/sdks/typescript/src/agents/sessions.ts b/sdks/typescript/src/agents/sessions.tsindex 61159ee6..6b430615 100644--- a/sdks/typescript/src/agents/sessions.ts+++ b/sdks/typescript/src/agents/sessions.ts@@ -95,11 +95,11 @@ export class Sessions {async create(params: CreateSessionParams): Promise<Session> {const { idempotencyKey, ...body } = params;- const r = await this.http.request<{ session: SessionData; clientToken?: string }>(+ const r = await this.http.request<{ session: SessionData; clientToken?: string; sources?: SourceSummary[] }>("POST", "/sessions",{ body, idempotencyKey, idempotent: Boolean(idempotencyKey || params.key) },);- return new Session(this.http, r.session, r.clientToken);+ return new Session(this.http, r.session, r.clientToken, r.sources);}async get(id: string): Promise<Session> {return new Session(this.http, await this.http.request<SessionData>("GET", `/sessions/${id}`));@@ -191,16 +191,21 @@ export class Session extends ClientSession {readonly destinations: Destinations;readonly deliveries: Deliveries;private data: SessionData;+ private _sources: SourceSummary[];- constructor(http: Http, data: SessionData, clientToken?: string) {+ constructor(http: Http, data: SessionData, clientToken?: string, sources?: SourceSummary[]) {super(http, data.id, clientToken);this.data = data;+ this._sources = sources ?? [];this.destinations = new Destinations(http, data.id);this.deliveries = new Deliveries(http, data.id);}get status(): SessionStatus { return this.data.status; }get lastTurn(): LastTurn | undefined { return this.data.lastTurn; }+ /** Source checkout status from create — `{ name, status, path, sha }[]` (empty when none).+ * For live status after create, poll `GET /sessions/:id/sources`. */+ get sources(): SourceSummary[] { return this._sources; }/** Opaque app routing state set at create (`null` when unset). See {@link CreateSessionParams.metadata}. */get metadata(): Record<string, unknown> | null { return this.data.metadata ?? null; }/** The latest fetched session record. */