Skip to content

CONTRACT: feat(ui-server,backends,common): GitHub write tools behind a policy repository allow-list and approval cards - #4076

Merged
schlessera merged 4 commits into
mainfrom
feat/3798-github-write-tools
Nov 16, 2026
Merged

schlessera merged 4 commits into
mainfrom
feat/3798-github-write-tools

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #3798

What changed

A hosted turn can now file a GitHub issue (brain_github_issue_create) or comment on one (brain_github_issue_comment) through the host tools slice 1 (#3797) declared. Both backends register the two write tools in every interactive session's fixed roster, after the reads and in the contract's order, and in no autonomous roster. The governance policy gains outward.github.repositories: owner/repo exactly or owner/*, using GitHub's name grammar and compared without case. A malformed entry or an unknown key makes the policy invalid. When the list is absent or empty, no write is admitted. The host checks the turn's admitted policy first, and a repository outside the list is refused with policy_denied / repository_not_allowed before any card, with the policy key named in the message. Voice is refused before the card. Inside the list, the turn's own approval surface shows one per-use command card whose input is exactly what will be sent. The write is sent once on an unedited allow, and is never retried or redirected. A denial, an edited approval, or a turn that ended or lost authority while the card was open sends nothing. Each refusal, answer and approval is an outward_action (gh_write) governance event, which the turn journal already lists as irreversible. The approval is recorded (awaited) before the request goes out, so an approval whose record fails sends nothing.

Why this shape

  • Host-side decision and card, as compute and Apify do. The host holds the policy, the credential and the exact request body, so it is the one place that can refuse before a card and show exactly what is sent. Both runtimes auto-allow the writes only in a typed turn with a grant surface and a handler, so the user sees one card, not two, and no rememberable "always allow" grant exists. In voice or no-grant turns, the runtime boundary (toolAvailabilityRefusal, piToolAvailabilityRefusal) refuses the tool before the host is reached, and the host refuses voice again.
  • An edited approval is refused, not sent as edited. The model has to make the call again, and the new call goes through the allow-list and a fresh card. This is the backends: ask before an agent acts outside the brain in the user's name, unless the policy allows it #1664 recheck carried to its strict end, and it satisfies "a changed input after approval sends nothing".
  • Repository names compare without case, owner and repository alike. GitHub resolves names that way, and so does the contract's own githubDirectUrl scope. A case-sensitive repository match would only refuse a differently spelled name for the same repository.
  • The existing gh_write action with rule: null. The governance event schema is unchanged.
  • Out of scope. The decision-record text is ui-server, docs: prove the Network card for raw GitHub API connections and document the GitHub tools #3799's slice. G2 provider-policy routing for these tools is ui-server: apply provider-policy data routing (G2) to the host GitHub tools #4029 (needs: decision).

Proof

New and updated tests:

  • packages/ui-server/tests/github-write-tools.test.ts (15 cases, loopback stand-in). One card with the exact repository, title, body and labels; Allow files exactly one issue, with the body sent as shown; the comment path; deny, edited and aborted or revoked approvals send nothing; an unrecorded approval sends nothing; a failed or redirected write is sent once. Outside the list it is refused before any card, with no request. The exact and owner/* forms are accepted, case-insensitively, and nothing that is not listed gets through. An absent or empty list refuses every write. No credential means no card. Voice is refused before the card. A turn without a write surface (autonomous) is refused.
  • packages/ui-server/tests/ws-github.test.ts: real createApp turns on pi and Claude. The turn's governance policy file opens odysseus/ithaca: circe/aiaia is refused before any card, and the allowed write raises one tool_approval_request with the exact input, sends one POST, and records refused then approved outward_action events bound to the session. With no policy, writes are refused and nothing is sent.
  • packages/core/tests/governance-policy.test.ts: the default is [], valid forms are accepted, 17 malformed entries are refused, a mixed list is refused (not skipped), unknown keys are refused, and the list is bounded. githubWriteAllowance is covered for exact, wildcard and case matches and for non-matches.
  • Rosters: Claude sdk-options-mcp.test.ts and pi github-tools.test.ts pin all four names, schemas and order, byte-identical across typed, no-grant and voice, with or without a handler, and absent from autonomous rosters. They also pin that writes are auto-allowed only in a typed turn with a handler. github-write-availability.test.ts covers the Claude permission boundary. The SDK-options snapshot is re-recorded: the two names and the schema digest change in the four interactive modes, and nothing else moves.

Mutation receipts. Each mutation was run against github-write-tools.test.ts or governance-policy.test.ts, and the source was restored and checked byte-identical with cmp:

  • Skip the allow-list check (if (false && !allowance)): GITHUB_OUTSIDE_LIST_REFUSED brain_github_issue_create fails, receiving "ok": true, along with GITHUB_NOT_ALLOWED and GITHUB_NO_LIST_REFUSED (3 fail, 12 pass).
  • Accept an edited approval (drop || edited): GITHUB_EDITED_REFUSED another repository fails.
  • Skip the voice refusal: GITHUB_VOICE_REFUSED brain_github_issue_create fails.
  • Drop the entry grammar from the policy schema: GITHUB_WRITES_MALFORMED_REFUSED: odysseus fails.

bun run build, tsc --noEmit and bun run lint are clean. bun run api-report changes only the two new common exports and the outward.github type.

bun run check:pr --base origin/main
{"version":1,"kind":"brain-check-pr-receipt","head":"c8366a75d0f80c4511930b1a488759979c45b16c","base":"origin/main","mode":"focused","startedAt":"2026-11-16T00:58:14.246Z","finishedAt":"2026-11-16T00:59:43.864Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12646.895675},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":106.37779999999839},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":69.4120780000012},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":19.319226999999955},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":76760.072913}]}

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof. (Local receipt above. Hosted proof runs at confirmation.)
  • 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/integration-contract.md, mcp.md#github-writes-additive-0450-3798, cli.md policy check, supported-inputs.md#governance-policy.)
  • 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: tool definitions are fixed per session across posture, profile and handler (roster tests), and nothing new enters the conversation besides the tool result.

Proportionate-containment checklist (the allow-list and approval guard)

  • What triggers it, and which failures it does not cover: a GitHub write tool call whose repository is not in the admitted policy's outward.github.repositories; a voice or surface-less turn; a declined, edited or stale approval; an unrecorded approval. It does not cover raw curl/gh connections (those keep the Network card, ui-server, docs: prove the Network card for raw GitHub API connections and document the GitHub tools #3799) or G2 data routing (ui-server: apply provider-policy data routing (G2) to the host GitHub tools #4029).
  • What it restricts: one call. Other GitHub calls, reads included, and the rest of the turn and session keep working. Nothing narrower than one call exists.
  • Restricted mode considered: writes to unlisted repositories can't be run in any narrower form, and per-call approval is already the mode for listed ones. Refusing the call is the restricted mode.
  • How it clears: with no human step beyond the policy itself. An owner adds the repository to the policy (an outside-turn edit, or the approved policy-proposal route), and the next turn admits it. An edited or declined approval clears when the call is made again.
  • Where the cause is recorded: the refusal carries a coded reason that names the policy key and is returned to the model. Every decision is an outward_action governance event in the turn journal's irreversible list.
  • Which test shows one scope failing leaves another usable: github-write-tools.test.ts "a write outside the list is refused…" refuses circe/aiaia while the same host files odysseus/ithaca. ws-github.test.ts refuses one write and admits the next in the same turn.

Anything left open

🤖 Generated with Claude Code

…a policy repository allow-list and approval cards

Both backends register `brain_github_issue_create` and
`brain_github_issue_comment` in every interactive session's fixed roster,
after the two read tools and in the contract's order, whatever the host's
configuration or the turn's posture; no autonomous roster lists them.

The governance policy gains `outward.github.repositories`: entries are
`owner/repo` exactly or `owner/*`, with GitHub's name grammar, compared
without case. A malformed entry or an unknown key invalidates the policy;
absent or empty, no write is admitted (`githubWriteAllowance`,
`packages/common/src/governance-policy.ts`).

The host (`packages/ui-server/src/github/host.ts`) decides each write from
the turn's admitted policy: outside the list it refuses `policy_denied`
(`repository_not_allowed`, naming the key) before any card; voice refuses
before the card; without the credential it answers `unavailable`. Inside
the list it raises one per-use command card on the turn's own approval
surface whose input is exactly the request body plus the repository (and
number), sends it once on an unedited allow, and never retries or follows
a redirect. A denial, an edited approval, or a turn that ended or lost its
authority while the card was open sends nothing. Each refusal, answer and
approval is an `outward_action` (`gh_write`) governance event, so the turn
journal lists it as irreversible; the approval is recorded before the
request, and an unrecorded approval sends nothing.

Both backends auto-allow the writes only in a typed turn with a grant
surface and a host handler, so the host's card is the only one; voice and
no-grant turns refuse them at the runtime's permission boundary.

The integration-contract index, the MCP component, the CLI policy check
envelope (`effective.outward.github.repositories`), the supported-inputs
policy reference and the Claude SDK-options snapshot (two roster names and
the schema digest in the four interactive modes) are updated here.

Closes #3798

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-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
@schlessera

Copy link
Copy Markdown
Owner Author

Collision check at head d995b9be1db78a9ba1322314dad2604dee6570b0 (bun scripts/collisions.ts --json --pr 4076):

@schlessera
schlessera marked this pull request as ready for review November 16, 2026 00:05
@schlessera
schlessera marked this pull request as draft November 16, 2026 00:33
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 00:33
schlessera and others added 2 commits November 16, 2026 00:58
…and the stable bridge roster

The installed Claude CLI request now carries 45 brain-ui tools: the two
host GitHub write tools (#3798) join the reads. The turn-surface fixture's
independently written stable roster lists them too.

Refs #3798

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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-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-server: GitHub write tools behind a policy repository allow-list and approval cards

1 participant