Repository navigation
CONTRACT: feat(ui-sdk,ui-server,backends): host GitHub read tools with a dedicated credential - #4028
Merged
Merged
Conversation
…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>
|
No uploads on this PR yet This PR changes UI files (
Tips for agentsLabel each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one 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 afterNo CLI? With the Uploads MCP, call 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 Workspace admins can turn this comment off in Settings → GitHub · docs |
This was referenced Nov 15, 2026
9 tasks done
…-tools # Conflicts: # packages/ui-backend-claude/tests/sdk-options-snapshot.test.ts
This was referenced Nov 15, 2026
Merged
This was referenced Nov 15, 2026
This was referenced Nov 15, 2026
6 of 7 tasks
schlessera
marked this pull request as ready for review
November 15, 2026 21:28
This was referenced Nov 15, 2026
Merged
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3797
What changed
A hosted chat turn can now read GitHub through two host tools,
brain_github_issue_readandbrain_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 callshttps://api.github.comwith a new dedicated token,BRAIN_UI_GITHUB_TOOLS_TOKEN, and never falls back toGITHUB_TOKEN. Without the token the tools stay listed and answerunavailable(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 inpackages/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 markeduntrusted: truein the schema. Every direct link is either validated ornull. A read records the session's taint as the new sourcegithub_resultbefore any text returns, and if that record fails, the text is withheld. The contract also declares the two write tools,brain_github_issue_createandbrain_github_issue_comment, with their final schemas and payloads. They are not registered yet and the host answers themunavailable(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 exacthttps:/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:
{ ok: true, tool, result } | { ok: false, tool, error: { code, reason, message } }and the error codes, includingpolicy_deniedandapproval_declined, reserved for ui-server: GitHub write tools behind a policy repository allow-list and approval cards #3798.GITHUB_ISSUE_READ_PAYLOAD_SCHEMA(issue or pull request),GITHUB_ISSUE_SEARCH_PAYLOAD_SCHEMA, the create and comment payloads,githubBoundedList,GITHUB_RESULT_SCHEMAS, and the validatorsgithubDirectUrl,githubSearchUrlandisGithubSearchUrl, for ui-server: serve on-demand GitHub detail pages to the chat components, outside the model's context #3796's routes and the ui-react, ui-kit: render GitHub tool results as dedicated issue, PR, review, commit and merge components #3795/ui-kit: GitHub component family (PR, issue, thread, review, commit, merge, results) with stories #3800 components.BackendBridge.github(call)andhandleGithubTool. The governance taint sourcegithub_result.Design choices that go beyond the issue's text:
state_reasonalso admitsduplicate, because the API returns it today.commentsholds the 30 most recent comments, oldest first, so a read of a long thread reaches its latest rulings.merge_commit_shais set only once a pull request is merged, because GitHub fills that field with a test-merge sha while it is open.reviews.total_countisnullonly beyond 100 reviews, where GitHub reports no total.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.comresponses: issue, pull, reviews, commits, issue and review commenthtml_urlfragments, check runs, combined status, and/search/issueswithoutis:.Proof
New tests:
packages/ui-sdk/tests/github-tool-contract.test.ts(23): all four schemas and every epic and §8 field, including checksnullversus 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): realcreateApp, pi and claude bridges. The stand-in receivesBearer <dedicated sentinel>, threegithub_resulttaints are recorded, and no subprocess audience or operator extra carries the token. With onlyGITHUB_TOKENset, the tools answerunavailable, send nothing and taint nothing.packages/ui-backend-pi/tests/github-tools.test.tsand the Claudesdk-options-mcpmode 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-credentialsin ui-sdk and ui-server: the new token, for worker and maintenance launches and transports.tests/installed-turn-surface.test.tsandscripts/turn-surface-fixture.ts: 43 eager bridge tools.Mutation receipts (each mutation restored afterwards):
if (url.hostname !== "github.com") return null;in githubDirectUrl's common rules ->packages/ui-sdk/tests/github-tool-contract.test.tsfailed withGITHUB_URL_NULL_issue_host suffix: https://github.com.evil.example/odysseus/ithaca/issues/42(and the same for every link kind). Restored -> 23 pass.packages/ui-sdk/tests/host-git-credentials.test.tsfailed:SDK_MAINTENANCE_GITHUB_TOOLS_TOKEN_ABSENT(Received "odysseus-github-tools-token") andDIRECT_WORKER_HAS_ONLY_ITS_PROVIDER_CREDENTIAL("tools": "odysseus-github-tools-token") for both direct agent and maintenance launches. Restored -> 4 pass.await options.untrusted(...)onbrain_github_issue_readinpackages/ui-server/src/github/host.ts->GITHUB_READ_TAINTSandGITHUB_TEXT_WITHHELD_WITHOUT_TAINT(github-tools-host.test.ts) andGITHUB_READ_TAINTS_SESSIONfor both the pi and claude turns (ws-github.test.ts) failed. Restored -> 14 + 3 pass.github: falsefrom Pi's autonomous caps inpackages/ui-backend-pi/src/session-pool.ts->packages/ui-backend-pi/tests/github-tools.test.tsfailed withPI_GITHUB_AUTONOMOUS_restricted. Restored -> pass.Local environment notes:
origin/mainworktree.packages/ui-server/tests/host-git-credentials.test.tsfail before their assertions withworker_host_unsupported(no uid_map here), as the pre-existing cases do, so hosted CI is their proof.bun run buildandtsc --noEmitare 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 4028at heada8eab6965): 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
docs/reflect the change, or nothing documented moved.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):
github_resulttaint cannot be committed has its text withheld. A host withoutBRAIN_UI_GITHUB_TOOLS_TOKENanswersunavailable. Neither guard covers rawcurlto GitHub, which keeps theNetworkcard (ui-server, docs: prove the Network card for raw GitHub API connections and document the GitHub tools #3799).GITHUB_TOKENwas rejected by ruling 3.unavailable/no_credential, orupstream_error), and a recorder failure is logged as a WARN on the brain log.GITHUB_TEXT_WITHHELD_WITHOUT_TAINTshows a recorder failure refuses only that call.GITHUB_NO_FALLBACK_TO_GITHUB_TOKENshows 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
Networkcard proof and the decision record: ui-server, docs: prove the Network card for raw GitHub API connections and document the GitHub tools #3799. Display routes: ui-server: serve on-demand GitHub detail pages to the chat components, outside the model's context #3796. Components: ui-react, ui-kit: render GitHub tool results as dedicated issue, PR, review, commit and merge components #3795 and ui-kit: GitHub component family (PR, issue, thread, review, commit, merge, results) with stories #3800.needs: decision) for a ruling on whether it gates the epic.🤖 Generated with Claude Code