Repository navigation
Description
Context
Part of #3791 (the epic holds the rulings, the incident evidence and the shared context; read it first). This is the first slice: the tool contract, the dedicated credential, and the two read tools. Writes (slice 2) and the raw-connection card check and docs (slice 3) build on it, and so do #3796 and #3795/#3800.
- Precedent contracts:
packages/ui-sdk/src/tool-contracts/compute.ts:146andpackages/ui-sdk/src/tool-contracts/apify.ts. Host tools run asmcp__brain-ui__…on both backends. - Credential stripping:
HOST_GIT_CREDENTIAL_ENV,packages/ui-sdk/src/server/subprocess-env.ts:243-247. Environment reference:packages/ui-server/src/config/env.ts(seeBRAIN_UI_SKILLS_GITHUB_TOKENat:185). - Untrusted-input taint:
hostRemotePages,packages/ui-server/src/activity/ingestion-taint.ts:134. - This contract owns the payload fields the approved component design needs (design §8 of the 15:08 proposal, approved with revision 2 on 2026-11-10) and the validation of every GitHub URL the components may open directly (D2/D3 rulings, 2026-11-10, recorded on ui-react, ui-kit: render GitHub tool results as dedicated issue, PR, review, commit and merge components #3795 and Epic: hosted turns read and file GitHub issues through governed host tools #3791).
Scope
packages/ui-sdk/src/tool-contracts/github.ts: fixed names and strict schemas for all four tools (brain_github_issue_read,brain_github_issue_search,brain_github_issue_create,brain_github_issue_comment; final names in the PR), with the structured payload types the epic specifies. Each bounded list carries its total count and a "more exists" flag, untrusted strings are marked, andhtml_urlcomes from the API. ui-server: serve on-demand GitHub detail pages to the chat components, outside the model's context #3796 reuses these types.- Approved payload fields (design §8, maintainer 2026-11-10). In addition to the epic's original list, the payload types carry:
total_countandhas_moreon every bounded list: comments, reviews, commits, labels;fetched_at, to anchor relative times;- issue
state_reason(completed/not_planned/reopened) andlocked; - PR
head_ref,base_ref,merged_by,merged_at,merge_commit_sha,requested_reviewers(pending), and the latest review state per reviewer, includingdismissed; - the checks summary as counts
{passed, failed, running, skipped}, ornullwhen not reported;nullstays distinct from zero; - per author, comment and review:
author_association,is_bot, and a nullable login (deleted user); body_lengthandbody_truncated;- search:
total_count,incomplete_results, and per itemkind,state,state_reason,draft,merged_at, comment count,updated_at, labels and an optional bounded body excerpt; review and checks summaries per item only if cheap (optional fields). - No merge-method field: the API does not expose it, and nothing infers it.
- Direct-link URLs (D2 and D3, maintainer 2026-11-10). The link boundary widens from "the canonical fetched object only" to three kinds of URL the components open directly. Every one is validated on the host by one exported validator in
tool-contracts/github.ts(final name in the PR), which ui-server: serve on-demand GitHub detail pages to the chat components, outside the model's context #3796 and the ui-react, ui-kit: render GitHub tool results as dedicated issue, PR, review, commit and merge components #3795 renderer reuse. A URL that fails becomesnull(each field is nullable), and the item still renders without a direct link. A failing URL is never repaired or rebuilt.- Common rules. The value parses as a WHATWG URL.
protocolis exactlyhttps:,hostnameis exactlygithub.com(no subdomain, no trailing dot), with no port, no username and no password. Path segments are matched after parsing, and./..segments and percent-encoded/or\in a segment are refused. No scheme, host or path segment ever comes from model input or untrusted GitHub text. - Canonical object (
html_urlof the issue or PR, from the API): path/{owner}/{repo}/issues/{n}or/{owner}/{repo}/pull/{n}, naming the same owner, repo and number as the fetched object, with no query and no fragment. - Sub-objects (D3):
html_urlon each comment, review, review comment and commit item, taken from the API response, never constructed. The path names the same owner, repo and number as the parent object, and the shape matches the item's kind: comment/{owner}/{repo}/(issues|pull)/{n}with fragment#issuecomment-{id}; review/{owner}/{repo}/pull/{n}with#pullrequestreview-{id}; review comment/{owner}/{repo}/pull/{n}with#discussion_r{id}; commit/{owner}/{repo}/commit/{sha}(or/{owner}/{repo}/pull/{n}/commits/{sha}).{id}is digits and equals the item's own id;{sha}is 40 hex characters and equals the item's own sha. No query; no fragment beyond the one the kind requires. - Search (D2): a search-results URL on the search payload (final field name in the PR), constructed by the host from a fixed
https://github.comorigin constant. Repo-scoped search uses path/{owner}/{repo}/issues, with owner and repo equal to the searched repository and matching GitHub's name grammar (owner[A-Za-z0-9-]{1,39}, repo[A-Za-z0-9._-]{1,100}, not.or..). Cross-repository search, if the tool offers it, uses path/searchwithtype=issues. The search text is set only throughURLSearchParamsas theqvalue, so model-supplied text can only ever be a percent-encoded query value. No other parameters and no fragment. After construction the URL is re-parsed and must pass the same checks, or the field isnulland the components show the footnote only.
- Common rules. The value parses as a WHATWG URL.
- Host implementation and registration of the two read tools for both backends. The write tools are registered in slice 2.
BRAIN_UI_GITHUB_TOOLS_TOKEN(final name in the PR): read with no fallback, declared in the environment reference, added toHOST_GIT_CREDENTIAL_ENV. Without it, the read tools stay listed and answerunavailablewith a reason.- Reads taint the session under the existing untrusted-input rules (add the read tools to the host remote-page set). They are not exempt.
Out of scope
- Write tools, the policy allow-list and approval cards (slice 2).
- The raw-connection
Networkcard check and the decision-record and capability-note docs (slice 3). - The display route (ui-server: serve on-demand GitHub detail pages to the chat components, outside the model's context #3796) and the components (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).
- Links inside untrusted text (bodies, comments): those stay behind the interstitial and are not validated or rewritten here.
Acceptance criteria
- With the credential configured,
brain_github_issue_readreturns an issue's and a PR's structured payload, andbrain_github_issue_searchreturns a bounded list with count and "more exists". A keyless test against a loopback stand-in for the GitHub API asserts that the stand-in received the host credential and that no worker environment contained it. - With only
GITHUB_TOKENset, the read tools answerunavailable(no fallback). With the dedicated variable set, no worker or maintenance subprocess environment contains it. Tests prove both. - A read records a
taintevent under the untrusted-input rules (test). - Contract tests assert all four tool schemas, including every payload field the epic lists and every approved §8 field above (checks
nulldistinct from zero, nullable login, nullable direct-link URLs). The stable-roster test pins the read tools' names in every mode. - Validator tests, for the canonical-object and each sub-object kind: a conforming API URL passes, and each of these becomes
null:http:scheme;github.com.evil.example;evil.example/github.com/…;gist.github.com; a trailing-dot host; userinfo; a port;javascript:; a different owner, repo or number from the parent; a non-numeric or mismatched id; a mismatched or short sha; a..segment; a percent-encoded/in a segment; an extra query parameter or fragment. - Search-URL tests: a search text containing
&,#,/,?,https://evil.example, a newline and non-ASCII characters yields a URL whose parsed origin ishttps://github.com, whose path is the expected shape, whose only parameters areq(plustypefor/search), and whose decodedqequals the input. An invalid owner or repo name yieldsnull. - Mutation receipts: drop the variable from
HOST_GIT_CREDENTIAL_ENV, and the worker-environment test fails; drop the exact-host check from the validator, and thegithub.com.evil.examplecase fails.
Verification
bun run test packages/ui-sdk/tests packages/ui-server/tests packages/ui-backend-claude/tests packages/ui-backend-pi/tests(new cases, stable-roster).
Contract impact
Additive CONTRACT: new tool names and schemas in the integration contract's tool list, and a new documented host environment variable. The schemas include the approved §8 fields and the nullable, validated direct-link URLs (canonical object, comment/review/review-comment/commit, and the constructed search URL). Commit prefixed CONTRACT:, integration contract updated in the same commit.
Triage 2026-11-10 at main 3aadc8df5: Decision (maintainer, 2026-11-10): design revision 2 on #3795 approved including the §8 payload fields; D2 adds a constructed, validated GitHub search URL; D3 adds independently validated comment/review/commit URLs. This contract-owning child now pins the §8 fields and owns the URL validator and its tests. Corrected citations env.ts:185 and ingestion-taint.ts:134. Still agent-ready, p1, 0.45.0.
Activity
schlessera commentedon Nov 10, 2026
Decision (maintainer, 2026-11-10):
2026-11-10 triage at main
3aadc8df5: as the contract-owning child, this issue now pins the approved §8 fields and owns the exported URL validator. That covers the canonical object, API-provided comment/review/review-comment/commit URLs (never constructed) and the host-constructed search URL (fixedhttps://github.comorigin, search text only as the encodedq). Every URL must behttps:, on host exactlygithub.com, with no userinfo or port, the expected path and fragment shape, and the same owner/repo/number. A failing URL isnull. Added hostile-URL and search-URL criteria and a mutation receipt. Contract impact is still additiveCONTRACT:, now naming these fields. Corrected the citations toenv.ts:185andingestion-taint.ts:134. Labels unchanged (agent-ready).schlessera commentedon Nov 15, 2026
Claimed for implementation. Claim token:
claim-59c6ef65. Branch:feat/3797-github-read-tools.Path collisions (detection only): #4002 ingestion-taint.ts; #4008 and #4024 config/env.ts.
CONTRACT: feat(ui-sdk,ui-server,backends): host GitHub read tools wit…
schlessera commentedon Nov 15, 2026
Delivered by #4028, squash
cc326cc64348a765325adc1cbe74248d60844845on main (milestone 0.45.0). Exact-head candidate proof passed (run 43763909355). Draft heavy feedback had already passed every category earlier.packages/ui-sdk/src/tool-contracts/github.tsdefines all four tools with strict schemas, the typed issue, pull request and search payloads with every epic field and approved §8 field, and the exported validatorsgithubDirectUrl,githubSearchUrlandisGithubSearchUrl.brain_github_issue_readandbrain_github_issue_searchare in every interactive session's fixed roster on both backends and in no autonomous roster. The host calls GitHub withBRAIN_UI_GITHUB_TOOLS_TOKENonly, with no fallback, and answersunavailable(no_credential) without it. The token is stripped from every worker and maintenance launch.github_resultbefore any text returns.unavailable(not_registered) until ui-server: GitHub write tools behind a policy repository allow-list and approval cards #3798.Mutation receipts are in the PR: dropping the token from
HOST_GIT_CREDENTIAL_ENV, dropping the exact-host check, skipping the taint, and listing the tools in autonomous rosters each fail the named test.Follow-up: #4029 asks for a ruling on applying G2 provider-policy routing to GitHub as a recipient. Shapes #3795, #3796, #3798 and #3799 build on are listed in the PR under "Why this shape".
feat(ui-react): render the host GitHub tools as the ui-kit GitHub com…