Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/3799-github-tools-brief.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@schlessera/brain-ui-sdk": patch
"@schlessera/brain-backend-claude": patch
"@schlessera/brain-backend-pi": patch
"@schlessera/brain-ui-server": patch
---

#3799: both backends' fixed system brief (the append a new interactive session retains) now names the host GitHub tools by the backend's visible names. It says the worker holds no GitHub credential, so `gh`, `curl` and WebFetch cannot act as the user on GitHub. When the tools answer `unavailable` or `policy_denied`, the model is to tell the user what they said and stop rather than fall back. A session retained earlier keeps its append byte for byte. A raw shell connection to GitHub's API still waits on its `Network` approval card. The `BRAIN_UI_GITHUB_TOOLS_TOKEN` reference now covers the write tools and the fine-grained permissions they need. The hosting guide gains a section on setting up the GitHub tools.
8 changes: 8 additions & 0 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9968,6 +9968,13 @@ signatures (every public export and the types it is made of)
tool: GithubToolName;
error: GithubError;
};
GithubToolsBrief (packages/ui-sdk/src/server/system-prompt.ts)
export interface GithubToolsBrief {
read: string;
search: string;
create: string;
comment: string;
}
GithubUser (packages/ui-sdk/src/tool-contracts/github.ts)
export type GithubUser = z.infer<typeof GITHUB_USER_SCHEMA>;
GithubWriteToolName (packages/ui-sdk/src/tool-contracts/github.ts)
Expand Down Expand Up @@ -15437,6 +15444,7 @@ signatures (every public export and the types it is made of)
execution?: ExecutionBrief;
webSearch?: WebSearchBrief;
webTools?: boolean;
githubTools?: GithubToolsBrief;
}): string;
checkEditedApproval (packages/ui-sdk/src/server/permission-gate.ts)
export function checkEditedApproval(options: EditedApprovalCheckInput): string | null;
Expand Down
54 changes: 54 additions & 0 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4165,6 +4165,60 @@ Microsoft Graph and Exchange Online carry more than mail, so their reads by
an opaque script also wait on the card. The coordinator chose this list for
#1665; the maintainer may override it.

**Host GitHub tools — 2026-11-09 (#3791).** The
[maintainer ruled](https://github.com/schlessera/brain-kit/issues/3791) that a
hosted turn reaches GitHub only through four fixed host MCP tools:
`brain_github_issue_read`, `brain_github_issue_search`,
`brain_github_issue_create` and `brain_github_issue_comment`. Claude sees them
as `mcp__brain-ui__brain_github_*` and pi under the bare names. A relayed `gh`
and a documented "no GitHub here" were both rejected. The rest of the ruling:

- **A dedicated credential.** The tools use the host-only
`BRAIN_UI_GITHUB_TOOLS_TOKEN` and nothing else. There is no fallback to
`GITHUB_TOKEN` or any other token. Every subprocess audience and worker
launch strips the variable. Workers never hold a GitHub credential, so `gh`
and raw API calls inside a turn are never authenticated. Without the token
the tools answer `unavailable` and send nothing.
- **Reads are untrusted input.** GitHub text returned to a turn taints the
session as `github_result` before the model sees it. Reads see only what the
token can see. Routing of reads and searches under G2 is ruled separately on
#4029.
- **Writes have an allow-list.** A write goes only to a repository listed in
the admitted policy's `outward.github.repositories` (`owner/repo` or
`owner/*`). Anything else is refused before any card is shown. Inside the
list, every write still raises its own exact-body approval card. Voice never
approves a write, and autonomous turns have no write surface.
- **The Network card stays.** An unclassified connection to an outward GitHub
host keeps its `Network` approval card (`approveOutward`,
`packages/ui-server/src/brain/turn-egress.ts:256-263`); it is not refused
outright. The hosted report behind #3791 was a compound shell command that
ended in `curl` to `api.github.com`. The classifier reads such a command as
opaque, so no visible-read exception covers it. Its `CONNECT` was held for
68 seconds and then refused as `outward_not_approved`. The record did not
show whether a card was ever displayed.

#3799 proves this path end to end through the real WebSocket handlers. The
card names the method and host (`CONNECT to api.github.com:443`), and the
client's status reads `Waiting for approval: Network`. Allowing admits the
held tunnel. Declining refuses it with `outward_not_approved` and a reason
the tool prints. Stopping the turn cancels the connection and withdraws the
card. If no client is connected when the card is raised, the card is held,
logged as waiting for a reconnect, and sent to the next client that
connects. Only the turn's own timeout bounds that wait
(`resendPendingInteractive`, `packages/ui-server/src/ws/resend.ts:13-16`).
No separate notification exists for a held card. A visible, classified
read, such as `gh issue view` or a plain `curl` GET, still connects without
a card under the exception above, but it reaches GitHub unauthenticated.
- **The model is told.** Both backends' fixed system brief names the four
tools under the backend's visible names. It says that `gh`, `curl` and
WebFetch cannot act as the user on GitHub. When the tools answer
`unavailable` or `policy_denied`, the model is to report what they said and
stop rather than fall back (`githubToolsLine`,
`packages/ui-sdk/src/server/system-prompt.ts:297-307`). The line lives in the
append each session retains once (the tools are in every interactive
roster), not in the per-turn sandbox note, so it never moves between turns.
A session retained before #3799 keeps its earlier append byte for byte.

### Untrusted input (G6)

**Prospective supersession — 2026-11-05 (#3599).** The
Expand Down
34 changes: 34 additions & 0 deletions docs/hosting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,40 @@ is set; the server passes the key through to the brain CLI. Without it the
sync takes the conservative defaults. See
[configuration.md](../configuration.md#sync).

## GitHub tools

A hosted turn reads and files GitHub issues and pull requests through four
host tools: `brain_github_issue_read`, `brain_github_issue_search`,
`brain_github_issue_create` and `brain_github_issue_comment`. The host holds
the token. Workers never get a GitHub credential, so `gh` inside a turn stays
unauthenticated.

1. In GitHub's **Settings → Developer settings → Fine-grained tokens**,
create a token. Restrict it to the repositories a turn may use; choose
**Only select repositories**.
2. Give it read access to **Issues**, **Pull requests**, **Checks** and
**Commit statuses**. GitHub adds **Metadata** read on its own. A pull
request's checks summary reads check runs and commit statuses. If one of
those permissions is missing, the summary comes back `null` (not
reported, which is different from zero), and GitHub's `X-Accepted-GitHub-Permissions` response header names the
missing permission.
3. If turns should file issues or comment, add **Issues** write access as
well.
4. Set it as `BRAIN_UI_GITHUB_TOOLS_TOKEN` in the server's environment and
recreate the container. No other token stands in for it: without this one
the tools answer `unavailable`.
5. To allow writes, list the repositories under `outward.github.repositories`
in the brain's governance policy (`owner/repo`, or `owner/*` for every
repository of one owner). A write anywhere else is refused before any card
is shown. Every allowed write still asks for its own approval.

Reads see only what the token can see. Their results count as untrusted
input for the session. A command that calls GitHub's API directly, such as a
script or a compound `curl` line, waits on a `Network` approval card rather
than reaching GitHub. Without a credential it could not act as you anyway.
See [the decision](../decisions/governed-writable-workers.md#outward-actions-g5)
and [the tool contract](../integration-contract/mcp.md#host-github-tools-additive-0450-3797).

## Recovery and partial availability

The UI server permits one HTTP sync at a time per canonical brain root.
Expand Down
17 changes: 17 additions & 0 deletions docs/integration-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ governance event (`gh_write`) that the turn journal lists as irreversible.
and [supported inputs](supported-inputs.md#governance-policy).
This ships in a minor.

## Raw GitHub API connections keep their Network card (additive, 0.45.0, #3799)

This records shipped behaviour; its only new surface is the brief input
below. When a shell command connects to an outward GitHub host (`api.github.com`, `uploads.github.com`)
and the classifier cannot read it, the connection waits on the existing
per-use `Network` card. The card names method, host and port. Allowing it
admits the connection. Declining it refuses with `outward_not_approved`.
Stopping the turn cancels the connection. A card raised with no client
connected is sent to the next client that connects. Both backends' fixed
system brief names the host GitHub tools under their visible names, tells the
model not to fall back to `gh`, `curl` or WebFetch, and says what to do when
the tools are unavailable. Sessions retained before it keep their earlier
append. `buildSystemPromptAppend` gains the optional `githubTools` input for
it ([package API](integration-contract/package-api.md#github-tools-system-brief-additive-0450-3799)). See
[the MCP component](integration-contract/mcp.md#raw-connections-to-githubs-api-0450-3799)
and [the decision](decisions/governed-writable-workers.md#outward-actions-g5).

## GitHub detail-page types (additive, 0.45.0, #3796)

`@schlessera/brain-ui-sdk/tool-contracts` adds the detail-page part list,
Expand Down
33 changes: 33 additions & 0 deletions docs/integration-contract/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,39 @@ false`, `rule: null` and `decision` `refused`, `declined` or `approved`. The
approval is recorded before the request is sent; if it cannot be recorded,
nothing is sent. The turn journal lists every one as irreversible.

### Raw connections to GitHub's API (0.45.0, #3799)

The worker holds no GitHub credential, and the four tools above are the
supported way to reach GitHub. A shell command that reaches GitHub's API
directly is not refused outright. The default outward hosts include
`api.github.com` and `uploads.github.com`. If the turn's running calls are not
all visible reads, or approved outward actions naming that host, a connection
to either host waits on the existing `Network` approval card. That covers an
opaque script, or a compound command the classifier cannot read. The card is
a per-use `tool_approval_request` with `toolName: "Network"`,
`kind: "command"`, `input: { host, port, method }` and the description
`<METHOD> to <host>:<port>`, for example `CONNECT to api.github.com:443`. It
is never remembered.

- Allowing it admits the held connection.
- Declining it refuses the connection with
`403 Forbidden - outward connection not approved` and the body `Blocked: a
connection to <host> acts outside the brain in the user's name, and it was
not approved. Do not retry it; say what you needed it for.` The decision is
recorded as `egress_connection` with `outcome: "denied"` and
`reason: "outward_not_approved"`.
- Stopping the turn while the card waits cancels the connection and withdraws
the card. A late answer admits nothing.
- A card raised while no client is connected is held and sent to the next
client that connects. Only the turn's own timeout bounds that wait.

Voice turns have no grant surface and are refused without a card. Both
backends' fixed system brief, the append each interactive session retains
once, tells the model to use the GitHub tools and not `gh`, `curl` or
WebFetch. When the tools answer `unavailable` or `policy_denied`, the model is
to tell the user what they said and stop. A session retained before #3799
keeps its earlier append. No wire shape changes.

## Host-owned web tools (additive, 0.45.0, #3685)

The pi backend's ordinary governed and strict interactive sessions list four
Expand Down
13 changes: 13 additions & 0 deletions docs/integration-contract/package-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5674,3 +5674,16 @@ before classifying its refusal. `JournalRecoveryStatus` and optional
object reservations from boot. The journal host adds `recoveryStatus()` returning
that summary. Fields and recovery semantics are in the
[HTTP contract](http.md#staging-refusal-and-unresolved-journal-recovery-additive-3826).

## GitHub tools system brief (additive, 0.45.0, #3799)

`buildSystemPromptAppend` in `@schlessera/brain-ui-sdk/server` accepts
optional `githubTools`, of the type `GithubToolsBrief`
(`{ read, search, create, comment }`, the visible tool names) that its
signature reaches.
With it, the brief gains one fixed bullet that sends GitHub through those
tools; without it, the output is unchanged. Both first-party backends pass it
for every interactive session, so a new session's retained append contains
the bullet. A session retained earlier keeps its append byte for byte. The
same-commit API report records the additive types. See
[the MCP component](mcp.md#raw-connections-to-githubs-api-0450-3799).
Loading
Loading