Skip to content

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

Closed

Description

@schlessera

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.

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, and html_url comes 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_count and has_more on every bounded list: comments, reviews, commits, labels;
    • fetched_at, to anchor relative times;
    • issue state_reason (completed / not_planned / reopened) and locked;
    • PR head_ref, base_ref, merged_by, merged_at, merge_commit_sha, requested_reviewers (pending), and the latest review state per reviewer, including dismissed;
    • the checks summary as counts {passed, failed, running, skipped}, or null when not reported; null stays distinct from zero;
    • per author, comment and review: author_association, is_bot, and a nullable login (deleted user);
    • body_length and body_truncated;
    • search: total_count, incomplete_results, and per item kind, 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 becomes null (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. protocol is exactly https:, hostname is exactly github.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_url of 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_url on 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.com origin 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 /search with type=issues. The search text is set only through URLSearchParams as the q value, 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 is null and the components show the footnote only.
  • 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 to HOST_GIT_CREDENTIAL_ENV. Without it, the read tools stay listed and answer unavailable with 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

Acceptance criteria

  • With the credential configured, brain_github_issue_read returns an issue's and a PR's structured payload, and brain_github_issue_search returns 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_TOKEN set, the read tools answer unavailable (no fallback). With the dedicated variable set, no worker or maintenance subprocess environment contains it. Tests prove both.
  • A read records a taint event 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 null distinct 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 is https://github.com, whose path is the expected shape, whose only parameters are q (plus type for /search), and whose decoded q equals the input. An invalid owner or repo name yields null.
  • 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 the github.com.evil.example case 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

  1. added this to the 0.45.0 milestone on Nov 9, 2026
  2. added
    type: featA new capability or a change in user-visible behaviour.
    area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.
    area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.
    area: backendsAgentBackend implementations and the seam they share.
    priority: p1Scheduled into the current or next milestone.
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.
    on Nov 9, 2026
  3. schlessera commented on Nov 10, 2026

    @schlessera
    OwnerAuthor

    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 (fixed https://github.com origin, search text only as the encoded q). Every URL must be https:, on host exactly github.com, with no userinfo or port, the expected path and fragment shape, and the same owner/repo/number. A failing URL is null. Added hostile-URL and search-URL criteria and a mutation receipt. Contract impact is still additive CONTRACT:, now naming these fields. Corrected the citations to env.ts:185 and ingestion-taint.ts:134. Labels unchanged (agent-ready).

  4. self-assigned this
    on Nov 15, 2026
  5. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    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.

  6. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    Delivered by #4028, squash cc326cc64348a765325adc1cbe74248d60844845 on main (milestone 0.45.0). Exact-head candidate proof passed (run 43763909355). Draft heavy feedback had already passed every category earlier.

    • The contract in packages/ui-sdk/src/tool-contracts/github.ts defines 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 validators githubDirectUrl, githubSearchUrl and isGithubSearchUrl.
    • brain_github_issue_read and brain_github_issue_search are in every interactive session's fixed roster on both backends and in no autonomous roster. The host calls GitHub with BRAIN_UI_GITHUB_TOOLS_TOKEN only, with no fallback, and answers unavailable (no_credential) without it. The token is stripped from every worker and maintenance launch.
    • A read records the taint source github_result before any text returns.
    • The write tools are declared and answer 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: backendsAgentBackend implementations and the seam they share.area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.priority: p1Scheduled into the current or next milestone.type: featA new capability or a change in user-visible behaviour.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions