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
9 changes: 9 additions & 0 deletions .changeset/3798-github-write-tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@schlessera/brain-common": minor
"@schlessera/brain": minor
"@schlessera/brain-ui-server": minor
"@schlessera/brain-backend-claude": minor
"@schlessera/brain-backend-pi": minor
---

Hosted chat turns can file GitHub issues and comment on them through the two host write tools, `brain_github_issue_create` and `brain_github_issue_comment` (#3798). Both backends now list them in every interactive session's fixed roster, after the read tools, and in no autonomous roster. A write goes only to a repository the governance policy lists under the new key `outward.github.repositories`, as `owner/repo` or `owner/*` (compared without case); any other repository is refused before an approval card is shown, and an absent or empty list allows no writes. A malformed entry makes the policy invalid. Inside the list, the user approves each write on one card showing exactly what will be sent, and it is sent once; a denial, an edited approval or a voice turn sends nothing. Every decision is recorded as an outward action and listed as irreversible in the turn journal. `brain policy check --json` reports the new key under `effective.outward.github.repositories`.
2 changes: 2 additions & 0 deletions api-report/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export "./internal/governance-policy" (./src/governance-policy.ts)
type ApifyLimits
BUILTIN_GOVERNANCE_POLICY
type EffectiveGovernancePolicy
GITHUB_WRITE_REPOSITORIES_MAX
GOVERNANCE_POLICY_MAX_BYTES
GOVERNANCE_POLICY_PATH
type GovernanceCommandRuleIndices
Expand All @@ -202,6 +203,7 @@ export "./internal/governance-policy" (./src/governance-policy.ts)
TrustedSourcesSchema
canonicalTrustHost
checkGovernancePolicy
githubWriteAllowance
matchTrustRules
openGovernancePolicyAnchored
parseGovernancePolicy
Expand Down
6 changes: 6 additions & 0 deletions api-report/ui-server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,9 @@ signatures (every public export and the types it is made of)
command: string;
remotes: string[];
}[]>>>;
github: z.ZodOptional<z.ZodObject<{
repositories: z.ZodOptional<z.ZodArray<z.ZodString>>;
}, z.core.$strict>>;
hosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
}, z.core.$strict>>;
profiles: z.ZodOptional<z.ZodObject<{
Expand Down Expand Up @@ -2677,6 +2680,9 @@ signatures (every public export and the types it is made of)
command: string;
remotes: string[];
}>;
github: {
repositories: string[];
};
hosts: string[];
};
profiles: {
Expand Down
22 changes: 21 additions & 1 deletion docs/integration-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,33 @@ shape changes. See
[the package API](integration-contract/package-api.md#start-card-persona-choice-3698).
This ships in a minor.

## Host GitHub writes and their repository allow-list (additive, 0.45.0, #3798)

Both first-party backends register `brain_github_issue_create` and
`brain_github_issue_comment` in every interactive session's fixed roster,
after the two reads, whatever the host's configuration or the turn's
posture; no autonomous roster lists them. A write goes only to a repository
the new governance policy key `outward.github.repositories` lists, exactly as
`owner/repo` or as `owner/*`, compared without case; anything else is
refused with `policy_denied` (`repository_not_allowed`) before any card, and
an absent or empty list refuses every write. Inside the list, the host shows
one per-use card with exactly what will be sent and sends it once on an
unedited approval; a denial, an edited approval or a voice turn
(`approval_declined`) sends nothing. Each decision is an `outward_action`
governance event (`gh_write`) that the turn journal lists as irreversible.
`brain policy check --json` reports `effective.outward.github.repositories`
(default `[]`). Claude's SDK-options roster gains the two names. See
[the MCP component](integration-contract/mcp.md#github-writes-additive-0450-3798)
and [supported inputs](supported-inputs.md#governance-policy).
This ships in a minor.

## Host GitHub tools (additive, 0.45.0, #3797)

Both first-party backends' interactive sessions gain two host-executed read
tools in their fixed roster: `brain_github_issue_read` and
`brain_github_issue_search` (`mcp__brain-ui__*` on Claude, plain on pi). Two
write tools, `brain_github_issue_create` and `brain_github_issue_comment`, are
declared with their schemas and payloads and registered by #3798. Results are
declared with their schemas and payloads, and registered since #3798. Results are
typed payloads for an issue, a pull request and a search, with bounded lists
carrying `total_count` and `has_more`, untrusted text marked in the schema,
and direct links that pass the exported `githubDirectUrl` and
Expand Down
3 changes: 3 additions & 0 deletions docs/integration-contract/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ the file enables it. Since #3160 (additive) `apify` also carries
`expires_at` normalized to an ISO 8601 UTC instant. Since #3161 (additive)
`apify` also carries `limits`, `null` unless the file sets the complete
[limits object](../supported-inputs.md#governance-policy).
Since #3798 (additive), `effective.outward` also includes
`github: { repositories: [] }` by default, or the file's validated
`outward.github.repositories` entries in their order and spelling.
Since #3607 (additive), `effective.taint` also includes `trusted_sources: []`
by default, or the complete validated canonical trust entries from the
[supported input](../supported-inputs.md#prospective-trust-policy-data-additive-3607),
Expand Down
67 changes: 62 additions & 5 deletions docs/integration-contract/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -1365,15 +1365,16 @@ UI bridge: Claude names them `mcp__brain-ui__<name>` and loads them eagerly;
pi attaches plain names. They are in every interactive session's fixed roster
(typed, voice and no-grant-surface), after `read_attachment`, whether or not
the host holds a credential, and auto-allowed. Restricted autonomous rosters
do not include them. The two write tools are declared here and registered,
with their approval cards and repository allow-list, by #3798.
do not include them. Since #3798 (additive) both backends also attach the two
write tools, after the reads, in the same roster and order and under the same
conditions; see [Writes](#github-writes-additive-0450-3798).

| Tool | Input | Registered |
|---|---|---|
| `brain_github_issue_read` | `repository` (`owner/repo`), `number` (integer 1–2147483647) | 0.45.0 (#3797) |
| `brain_github_issue_search` | `repository`, `query` (1–256 characters; `repo:`, `org:`, `user:` and `owner:` qualifiers refused), `kind?` (`issue`, `pull_request`, `any`; default `any`), `state?` (`open`, `closed`, `any`; default `any`), `limit?` (1–30, default 10) | 0.45.0 (#3797) |
| `brain_github_issue_create` | `repository`, `title` (1–256), `body?` (up to 65,536), `labels?` (up to 10 names) | #3798 |
| `brain_github_issue_comment` | `repository`, `number`, `body` (1–65,536) | #3798 |
| `brain_github_issue_create` | `repository`, `title` (1–256), `body?` (up to 65,536), `labels?` (up to 10 names) | 0.45.0 (#3798) |
| `brain_github_issue_comment` | `repository`, `number`, `body` (1–65,536) | 0.45.0 (#3798) |

`repository` follows GitHub's name grammar: owner `[A-Za-z0-9-]{1,39}`,
repository `[A-Za-z0-9._-]{1,100}` and not `.` or `..`. Inputs are strict
Expand All @@ -1384,7 +1385,9 @@ Each result is one JSON document, `{ ok: true, tool, result }` or
`rate_limited`, `upstream_error`, `policy_denied` or `approval_declined`.
`unavailable` carries `reason` `no_credential` (the host has no
`BRAIN_UI_GITHUB_TOOLS_TOKEN`), `credential_rejected`, `no_host` (no host
handler in this turn) or `not_registered` (a write tool before #3798).
handler in this turn), `recording_unavailable` (a write's approval could not
be recorded) or, before #3798 only, `not_registered`. The write reasons are
listed under [Writes](#github-writes-additive-0450-3798).

**Payloads.** `result` is typed data, never formatted text
(`GITHUB_RESULT_SCHEMAS`). A read returns `kind: "issue"` or
Expand Down Expand Up @@ -1449,6 +1452,60 @@ any GitHub text returns, the session's taint is recorded with the new source
`github_result` ([governance events](../http-api.md)); if that record cannot
be written, the text is withheld.

### GitHub writes (additive, 0.45.0, #3798)

`brain_github_issue_create` files one issue and `brain_github_issue_comment`
posts one comment, through the same credential and API origin. A write goes
only to a repository the turn's admitted governance policy lists under
[`outward.github.repositories`](../supported-inputs.md#governance-policy).
The host decides each call in this order, and nothing reaches GitHub before
the last step:

1. **Allow-list.** A repository the list does not open is refused with
`policy_denied`, `reason: "repository_not_allowed"`, and a message naming
`outward.github.repositories`. No card is shown. An absent or empty list,
or a turn under no governance policy, refuses every write.
2. **Posture.** A voice turn is refused with `approval_declined`,
`reason: "voice_posture"`, before any card: voice can refuse a write but
never approve one. A turn with no write surface, such as any autonomous
turn, is refused with `policy_denied`, `reason: "no_write_surface"`.
3. **Credential.** Without `BRAIN_UI_GITHUB_TOOLS_TOKEN`, `unavailable`
(`no_credential`), before any card.
4. **Card.** One per-use command card on the turn's own approval surface,
named with the backend's visible tool name. Its input is exactly what is
sent: `{ repository, title, body?, labels? }` for an issue and
`{ repository, number, body }` for a comment, after the schema's trimming,
with an absent field neither shown nor sent. Its description says the
write is sent once, in the user's name, and cannot be undone, and notes a
session that has read untrusted input. The card is never remembered.
5. **Answer.** A denial is `approval_declined`, `reason: "declined"`. An
approval that comes back with a changed input is `approval_declined`,
`reason: "edited"`, and sends nothing; the model must make the call again,
which runs every step for the new input. A turn that ended or lost its
authority while the card was open sends nothing (`upstream_error`,
`reason: "cancelled"`).
6. **Send.** One `POST` to the fixed API origin, never retried and never
redirected. A failure that GitHub answered says nothing was written; a
timeout or network failure says the write may still have been made.

Both backends auto-allow the write tools in a typed turn with a grant surface
and a host handler, so the host's card is the only one. In a voice or
no-grant turn the runtime's own permission boundary refuses them before the
host is reached, and the roster is unchanged.

A success returns `kind: "issue_created"` (`repository`, `number`, `title`,
`labels`, `created_at`, `html_url`) or `kind: "comment_created"`
(`repository`, `number`, `comment_id`, `created_at`, `html_url`); `html_url`
passes `githubDirectUrl` for the created issue or comment, or is null. A
write's own result does not taint the session.

Each refusal at steps 1, 2 and 5, each answer and each approval is recorded as an `outward_action` governance
event with `action: "gh_write"`, `target` `owner/repo` (an issue) or
`owner/repo#n` (a comment), the card's input, `tainted`, `historyRewrite:
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.

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

The pi backend's ordinary governed and strict interactive sessions list four
Expand Down
2 changes: 1 addition & 1 deletion docs/supported-inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ objects merge per field. No value grants authority to autonomous turns.
| `scope` | `max_files_changed`, `max_minutes`, `max_tool_calls`, `max_bytes_written` | Nonnegative safe integers, except finite minutes. Defaults: 1,000 paths, 120 minutes, 500 calls, 4 GiB. `max_files_changed` counts changed paths outside `workspaces/`; `max_bytes_written` counts workspace writes too. Path/byte defaults are provisional approved values, not measured distributions. |
| `commands` | `deny`, `confirm`: arrays of `{ pattern: string, reason?: string }` | Additions to existing permissions, default `[]`. Regex sources preserve their literal anchors and compile case-insensitively under [confirmation rules](decisions/confirm-patterns.md). Mixed lists retain valid entries in order and report skipped sources; nonempty entirely invalid lists refuse. |
| `egress` | `mode`: `record`/`allowlist`; `allow`, `deny`: string arrays; `max_bytes_per_turn`: nonnegative safe integer | `record`, empty lists and no byte cap by default. This reader does not establish network enforcement. |
| `outward` | `allow`: array of `{ command: string, remotes: string[] }`; `hosts`: string array | Default empty additions to the existing outward-action rules and built-in destination list. Parsing grants no action. |
| `outward` | `allow`: array of `{ command: string, remotes: string[] }`; `hosts`: string array; `github`: `{ repositories: string[] }` (at most 256) | Default empty additions to the existing outward-action rules and built-in destination list. Parsing grants no action. `github.repositories` (additive, #3798) lists the repositories the host GitHub write tools may write to: each entry is `owner/repo` exactly or `owner/*` for every repository of one owner, with GitHub's name grammar (owner `[A-Za-z0-9-]{1,39}`, repository `[A-Za-z0-9._-]{1,100}`, not `.` or `..`). Owner and repository compare without case. No other pattern exists, and one malformed entry, or an unknown key in `github`, makes the policy invalid rather than being skipped. Absent or empty, the default, no GitHub write is admitted. A listed repository still needs a per-use approval card for each write; see [the MCP contract](integration-contract/mcp.md#github-writes-additive-0450-3798). |
| `taint` | `egress: { allow: string[] }`, `trusted_sources: TrustRule[]` | Both lists default to `[]`; trust data and pure candidate matching are described below (#3607). No runtime trust capability is enabled. Default empty egress additions; session-derived hosts/inference relay and taint enforcement remain their owning guardrail's responsibility. Validated provider-relay requests are outside taint narrowing and create no taint ([#3246](integration-contract.md#provider-relay-requests-and-session-taint-breaking-before-10-3246)); this list never needs a provider host for them. |
| `providers` | Array of `{ paths?: string[], types?: string[], allow: string[] }` | Default `[]`. At least one selector is present. Paths use canonical brain-relative Bun glob patterns; types are exact runtime taxonomy names. Either selector matches; every matching rule must allow the actual recipient. Unknown recipients cannot authorize matching content. |
| `apify` | `enabled`: boolean; `discovery`, `actors`: `deny`, `ask` or `allow`; `actor_grants`: array of `{ account_id, actor_id, build_number, profile_id, schema_sha256, pricing_sha256, origins, expires_at, max_run_usd }` (at most 64); `limits`: `{ run_usd, turn_usd, session_usd, day_usd, max_runs_per_turn, max_requests_per_turn, max_concurrent_runs, max_runtime_seconds, max_result_items, max_result_bytes, max_retention_seconds }` | Default `{ enabled: false, discovery: ask, actors: ask, actor_grants: [], limits: null }` (additive, #3159, #3160 and #3161). Only `enabled: true` lets the server use its host-only `APIFY_TOKEN`; until then it contacts no Apify endpoint, whatever credential exists. An invalid policy file disables Apify rather than keeping an earlier enablement. `discovery` governs catalog searches and Actor inspection, which send the query or the chosen Actor's identifier to Apify; it never permits a run. `actors: deny` refuses every run; both `ask` and `allow` require an Actor's first approval. Approve once authorizes one prepared invocation; approve always persists approval by brain, principal, account and immutable Actor id across sessions, inputs and builds. Historical `actor_grants` entries remain parseable and revocable but do not become Actor-wide approvals. Their legacy fields and expiry syntax are unchanged. `limits` is the only spending entitlement: without it no run is admitted. With it, every field is required. Amounts are USD from 0 to 1,000,000. Counts are whole numbers up to 1,000,000. `max_runtime_seconds` is at most 7 days, `max_result_items` at most 1,000,000, `max_result_bytes` at most 1 GiB and `max_retention_seconds` at most 30 days. Legacy `max_result_items` and `max_result_bytes` remain parseable but do not truncate Actor content (#3580). Zero refuses the remaining allowances. `run_usd` bounds a run's whole reservation: its cap plus its reserved lifecycle requests and remote storage. `turn_usd`, `session_usd` and `day_usd` count pending reservations as spent and apply alongside, never above, `budgets`. `day_usd` and `max_concurrent_runs` are account-wide across brains. `max_requests_per_turn` counts every Apify request in a turn. Results stay readable for `max_retention_seconds` after a run ends, which never shortens Apify's own storage retention. See the [current Apify decision](decisions/apify-actor-approval.md). |
Expand Down
Loading
Loading