Skip to content

CONTRACT: feat(ui-sdk,ui-server,backends): host GitHub read tools with a dedicated credential - #4028

Merged
schlessera merged 9 commits into
mainfrom
feat/3797-github-read-tools
Nov 15, 2026
Merged

schlessera merged 9 commits into
mainfrom
feat/3797-github-read-tools

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #3797

What changed

A hosted chat turn can now read GitHub through two host tools, brain_github_issue_read and brain_github_issue_search. Both backends list them in every interactive session's fixed roster (typed, voice and no-grant; mcp__brain-ui__* on Claude, plain on pi), auto-allowed, and in no autonomous roster. The host calls https://api.github.com with a new dedicated token, BRAIN_UI_GITHUB_TOOLS_TOKEN, and never falls back to GITHUB_TOKEN. Without the token the tools stay listed and answer unavailable (no_credential). The token is in no subprocess audience, and every worker and maintenance launch strips it. Results are typed payloads for an issue, a pull request and a search, defined in packages/ui-sdk/src/tool-contracts/github.ts. They carry every field the epic lists and every approved §8 field. Text that GitHub users wrote is marked untrusted: true in the schema. Every direct link is either validated or null. A read records the session's taint as the new source github_result before any text returns, and if that record fails, the text is withheld. The contract also declares the two write tools, brain_github_issue_create and brain_github_issue_comment, with their final schemas and payloads. They are not registered yet and the host answers them unavailable (not_registered).

Why this shape

This follows the epic's rulings (#3791: host tools, a dedicated credential with no fallback) and the Apify precedent: fixed contracts in the SDK, a host executor bound to the turn, taint recorded by the host before remote text returns, and a roster that never depends on configuration. The contract defines and exports one validator, githubDirectUrl(value, scope, target), and one search-URL builder, githubSearchUrl(scope, q), for #3796 and #3795 to reuse. A URL must serialise to itself as a WHATWG URL. That one rule refuses dot segments, encoded dots, a default port and stray separators that a parse would otherwise rewrite. On top of it come the exact https: / github.com / no-port / no-userinfo checks and the per-kind path, fragment and identity checks.

Contract shapes the blocked children build on (#3795, #3796, #3798, #3799), kept stable from here on:

Design choices that go beyond the issue's text:

  • state_reason also admits duplicate, because the API returns it today.
  • comments holds the 30 most recent comments, oldest first, so a read of a long thread reaches its latest rulings.
  • merge_commit_sha is set only once a pull request is merged, because GitHub fills that field with a test-merge sha while it is open.
  • reviews.total_count is null only beyond 100 reviews, where GitHub reports no total.
  • Search refuses repo:/org:/user:/owner: qualifiers, and the host drops any result from another repository, so the scope cannot widen.

The API shapes were checked against live api.github.com responses: issue, pull, reviews, commits, issue and review comment html_url fragments, check runs, combined status, and /search/issues without is:.

Proof

bun run check:pr --base origin/main

New tests:

  • packages/ui-sdk/tests/github-tool-contract.test.ts (23): all four schemas and every epic and §8 field, including checks null versus zero, nullable login and nullable URLs. Every hostile form named in the criteria, for the canonical object and for each sub-object kind, plus the search-URL cases.
  • packages/ui-server/tests/github-tools-host.test.ts (14): the host against a loopback stand-in.
  • packages/ui-server/tests/ws-github.test.ts (3): real createApp, pi and claude bridges. The stand-in receives Bearer <dedicated sentinel>, three github_result taints are recorded, and no subprocess audience or operator extra carries the token. With only GITHUB_TOKEN set, the tools answer unavailable, send nothing and taint nothing.
  • packages/ui-backend-pi/tests/github-tools.test.ts and the Claude sdk-options-mcp mode tests: the stable roster pins both names and exact schemas in typed, voice, no-grant and missing-handler modes, and both tools are absent from autonomous rosters.

Updated tests:

  • host-git-credentials in ui-sdk and ui-server: the new token, for worker and maintenance launches and transports.
  • The Claude SDK-options snapshot, re-recorded for one reviewed change: two roster names and the schema digest in the four interactive modes. Allowlists, prompts and the autonomous modes are byte-identical.
  • tests/installed-turn-surface.test.ts and scripts/turn-surface-fixture.ts: 43 eager bridge tools.

Mutation receipts (each mutation restored afterwards):

  • Validator mutation: commented out if (url.hostname !== "github.com") return null; in githubDirectUrl's common rules -> packages/ui-sdk/tests/github-tool-contract.test.ts failed with GITHUB_URL_NULL_issue_host suffix: https://github.com.evil.example/odysseus/ithaca/issues/42 (and the same for every link kind). Restored -> 23 pass.
  • Credential mutation: removed "BRAIN_UI_GITHUB_TOOLS_TOKEN" from HOST_GIT_CREDENTIAL_ENV -> packages/ui-sdk/tests/host-git-credentials.test.ts failed: SDK_MAINTENANCE_GITHUB_TOOLS_TOKEN_ABSENT (Received "odysseus-github-tools-token") and DIRECT_WORKER_HAS_ONLY_ITS_PROVIDER_CREDENTIAL ("tools": "odysseus-github-tools-token") for both direct agent and maintenance launches. Restored -> 4 pass.
  • Taint mutation: skipped await options.untrusted(...) on brain_github_issue_read in packages/ui-server/src/github/host.ts -> GITHUB_READ_TAINTS and GITHUB_TEXT_WITHHELD_WITHOUT_TAINT (github-tools-host.test.ts) and GITHUB_READ_TAINTS_SESSION for both the pi and claude turns (ws-github.test.ts) failed. Restored -> 14 + 3 pass.
  • Roster mutation: removed github: false from Pi's autonomous caps in packages/ui-backend-pi/src/session-pool.ts -> packages/ui-backend-pi/tests/github-tools.test.ts failed with PI_GITHUB_AUTONOMOUS_restricted. Restored -> pass.

Local environment notes:

  • In this sandbox the package suites fail only in worker, bwrap and runtime files. The ui-sdk, ui-backend-claude and ui-backend-pi failing files are identical, file for file, to a clean origin/main worktree.
  • For ui-server, the failing files rerun in isolation match base. The two credentialed-maintenance cases in packages/ui-server/tests/host-git-credentials.test.ts fail before their assertions with worker_host_unsupported (no uid_map here), as the pre-existing cases do, so hosted CI is their proof.
  • bun run build and tsc --noEmit are clean.

Draft heavy feedback (never proof) passed every category at a8eab6965: run 43748173890 (runtime, runtime_host, browser, layout, captures, endurance, unit, verify, pack).

Collisions (bun scripts/collisions.ts --json --pr 4028 at head a8eab6965): textual overlap only, with open PRs #3622 (docs/http-api.md, packages/ui-server/src/app.ts), #3806 (docs/integration-contract.md) and #4021 (packages/ui-backend-claude/tests/sdk-options-snapshot.test.ts); 13 closure overlaps; no path collision.

{"version":1,"kind":"brain-check-pr-receipt","head":"f8037f45a72167de3a7ade3f4f4228ba695d4afe","base":"origin/main","mode":"focused","startedAt":"2026-11-15T21:23:17.015Z","finishedAt":"2026-11-15T21:27:31.254Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":30538.361236},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":391.4078470000022},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":366.0590450000018},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":40.60680399999546},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":222867.538008}]}

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof.
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only (docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.

Guard checklist (taint-before-text and the missing-credential refusal):

  • Trigger. A read whose github_result taint cannot be committed has its text withheld. A host without BRAIN_UI_GITHUB_TOOLS_TOKEN answers unavailable. Neither guard covers raw curl to GitHub, which keeps the Network card (ui-server, docs: prove the Network card for raw GitHub API connections and document the GitHub tools #3799).
  • Scope. One tool call, nothing wider. The turn, the session and the other tools continue.
  • Restricted mode considered. Returning the text without a taint record was rejected: an unrecorded untrusted input is the failure the G6 rule exists for. Falling back to GITHUB_TOKEN was rejected by ruling 3.
  • Clearing. It clears by itself: the next call retries, and setting the token takes effect at the next boot. No owner action is needed.
  • Where the cause shows. The model reads a coded tool error (unavailable/no_credential, or upstream_error), and a recorder failure is logged as a WARN on the brain log.
  • Scope test. GITHUB_TEXT_WITHHELD_WITHOUT_TAINT shows a recorder failure refuses only that call. GITHUB_NO_FALLBACK_TO_GITHUB_TOKEN shows the rest of the turn completes.

Provider history: the two tools are fixed members of every interactive roster from the first turn of a session. Configuration never adds or removes them, and nothing changes earlier turns. The roster-stability tests above and the snapshot cover it.

Anything left open

🤖 Generated with Claude Code

schlessera and others added 3 commits November 15, 2026 17:29
…h a dedicated credential

The GitHub tool contract (`@schlessera/brain-ui-sdk/tool-contracts`,
`github.ts`) fixes four names and strict schemas: `brain_github_issue_read`,
`brain_github_issue_search`, `brain_github_issue_create` and
`brain_github_issue_comment`. It also pins the typed payloads for an issue, a
pull request and a search, including every field of the approved design (§8):
bounded lists with `total_count` and `has_more`, `fetched_at`, `state_reason`
and `locked`, branch, merge and reviewer fields, the latest review state per
reviewer, checks as counts or `null`, authors with association, bot flag and
nullable login, and body length and truncation. Untrusted text carries
`untrusted: true` in its JSON Schema. One exported validator,
`githubDirectUrl`, admits an API-provided object, comment, review, review
comment or commit URL only when it is `https:` on exactly `github.com` with
the expected path, fragment and identity; `githubSearchUrl` builds the search
link from the fixed origin with the text only as the encoded `q`. A failing
URL is `null`.

Both backends register the two read tools in every interactive session's
fixed roster (Claude as `mcp__brain-ui__*`, pi plain), auto-allowed, and in
no autonomous roster. The host (`packages/ui-server/src/github/host.ts`)
reads `BRAIN_UI_GITHUB_TOOLS_TOKEN` alone, with no fallback to `GITHUB_TOKEN`,
answers `unavailable` without it, calls only `https://api.github.com`, scopes
searches to the named repository, and records the session's taint with the
new source `github_result` before any text returns. The token is a host-only
secret: it is in no subprocess audience and is stripped from every worker and
maintenance launch (`HOST_GIT_CREDENTIAL_ENV`, `HOST_ONLY_SECRET_ENV`).

The write tools are declared and answer `unavailable` until #3798 registers
them with their approval cards.

The integration-contract index, MCP, package-API and wire components, the
governance-event taint list, supported inputs, the environment reference, the
API reports and the Claude SDK-options snapshot (two roster names and the
schema digest in the four interactive modes) are updated here.

Refs #3797

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and keep them out of autonomous sessions

Refs #3797

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: feat A new capability or a change in user-visible behaviour. area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. area: backends AgentBackend implementations and the seam they share. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. labels Nov 15, 2026
@uploads-sh

uploads-sh Bot commented Nov 15, 2026

Copy link
Copy Markdown

No uploads on this PR yet

This PR changes UI files (packages/ui-react/src/components/chat/safety-indicator.tsx). Screenshots help reviewers see what changed.

  • From the CLI: uploads put before.png after.png --pr 4028
  • From an agent: ask it to attach screenshots with uploads.sh
  • By hand: drag images into the PR description and they're imported automatically
Tips for agents

Label each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one put per shot:

uploads put after.png --pr 4028 --meta path=/settings --state after --caption "Saved settings toast"
uploads put chat.png --pr 4028 --app ios --screen "Chat" --state after

No CLI? With the Uploads MCP, call sign_upload_url for files on disk (or put) with repo, pr: 4028 and the same screen, state and caption fields.

This comment updates with each upload, so you don't need to post the images yourself. A shot or two in the PR description is still welcome. Check what's attached with uploads list --pr 4028. More in the github-screenshots skill or the agent docs.

Workspace admins can turn this comment off in Settings → GitHub · docs

…-tools

# Conflicts:
#	packages/ui-backend-claude/tests/sdk-options-snapshot.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backends AgentBackend implementations and the seam they share. area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. type: feat A new capability or a change in user-visible behaviour.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-sdk, ui-server: GitHub tool contract, dedicated credential and host read tools

1 participant