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
4 changes: 4 additions & 0 deletions .changeset/untrusted-file-marks-ui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@schlessera/brain-ui-react": minor
---
Files can mark a file untrusted (#2673). The viewer toolbar gains `Mark untrusted` between Copy path and Share. The owner sees a pressed `Untrusted: clear mark` control, and every reader sees a purple `untrusted` cue on the file and its tree row. A `Marked untrusted` list replaces the disabled `Untrusted only` filter: the owner's list shows retained marks on moved or deleted files, and readers see only present files they can open, with no marker identity. Every change waits for the host's reply. Races, refusals and uncertain replies use the approved copy, and focus follows the approved table.
5 changes: 5 additions & 0 deletions .changeset/untrusted-file-marks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-server": minor
"@schlessera/brain-ui-sdk": patch
---
Let a user mark a brain file untrusted (#2673). Any principal that can read a file may mark it, and only the owner may clear a mark. A chat that then opens the file with its file tools records `taint` with `source: "user_marked"` and runs under the tainted session's outward and egress rules. Marks live in the UI database, survive a restart and `brain index --force`, and stay with their old path when a file moves, where only the owner sees them as missing. The capabilities note now names marked files among the untrusted sources.
2 changes: 1 addition & 1 deletion docs/decisions/async-collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ suppressed-per-model Action; unknown usage cannot become a guessed zero.
Subscription billing moves the turn counter even when spend is zero. The activity
sum exposes unpriced runs (`sumEffectiveCost`,
`packages/ui-server/src/activity/store.ts:179-194`) and settles only after execution
(`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:746`).
(`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:756`).
Retrospective totals alone cannot enforce admission.

The maintainer's [2026-10-01 ruling on #678](https://github.com/schlessera/brain-kit/issues/678#issuecomment-5926691626)
Expand Down
50 changes: 48 additions & 2 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,7 @@ limits from the same policy inputs and states independent hard limits.

**What exists.** The audit trail is the Activity span record: tool name, the
full input up to its cap, output and approval decisions
(`"tool_input"`, `packages/ui-server/src/activity/recorder.ts:334`).
(`"tool_input"`, `packages/ui-server/src/activity/recorder.ts:344`).

**What changes:**

Expand Down Expand Up @@ -3792,7 +3792,7 @@ document reader whose normalized path is under `.brain-ui/inbox/` or
outside the brain and the strict area root counts any such segment); a
fetching or unclassified Bash call; and any MCP tool whose server is not
brain-kit's own `brain` or `brain-ui`
(`inputTaintSource`, `packages/ui-server/src/activity/ingestion-taint.ts:51-61`).
(`inputTaintSource`, `packages/ui-server/src/activity/ingestion-taint.ts:82-92`).
The fixed list of external-content MCP sources is therefore "every other MCP
server", following the rule above that erring towards taint costs only tighter
rules (maintainer ruling, 2026-10-22). The first source is the session's one
Expand Down Expand Up @@ -3828,6 +3828,52 @@ widens: deny and `allowlist` mode still apply first (`prepareTurnEgress`,
native storage have no proxy, so the Bash classifier remains their shell rule
and nothing narrows their egress.

**Files the user marks untrusted — 2026-11-02
([#2673](https://github.com/schlessera/brain-kit/issues/2673)).** A user can
mark a brain file untrusted from Files, and the recorder above then treats an
admitted file-tool read of it as untrusted input: a `Read`, `Edit`, `Grep`,
`Glob`, pi `read_file`, `edit_file` or `grep`, or brain-kit's own document
reader, whose normalized brain-relative path is marked, or a search whose
output names it, records `taint` with `source: "user_marked"` as the session's
first source (`fileSource`,
`packages/ui-server/src/activity/ingestion-taint.ts:74-79`). An untrusted area
still names its own source first, and an absolute path outside the brain's
host path is not matched against marks. A mark is looked up when the call
completes; a lookup that fails counts as marked
(`const marked: MarkedLookup`, `packages/ui-server/src/activity/recorder.ts:236-242`).
Shell reads are covered only by the Bash rules above, reads are never
blocked, and a session that read the file before it was marked is not
tainted retroactively.

The marks are host records in the UI database, never `brain.db` or
frontmatter, so they survive a restart and `brain index --force`
(`untrustedMarkOperations`, `packages/ui-server/src/files/untrusted-marks.ts:51-63`).
The maintainer settled five rules on 2026-10-23, and the host enforces each of
them on direct requests (`mountUntrustedMarks`,
`packages/ui-server/src/routes/files.ts:317-383`):

- **Rename and move (B).** A mark is keyed by its brain-relative path. A file
that moves or disappears keeps its old-path record, which is listed as
missing so the owner can recover by marking the new path. Nothing follows
the rename, so the new path stays unmarked until it is marked, and the
old-path mark applies again if a file returns to that path.
- **Authority (B).** Any authenticated principal that can already read the
file may mark it; marking grants no further access. Only the owner may clear
a mark, including a retained missing one. The owner is the human owner the
storage and history routes already admit, an `owner` or `ambient` principal
(`isHumanOwner`, `packages/ui-server/src/routes/files.ts:145-147`); no
role is added. Clearing stops new sessions being tainted by that file and
never removes a session's recorded taint.
- **Visible scope (A).** Files views only: a toolbar control, viewer and tree
cues and a `Marked untrusted` list of user marks. Chat links and attachment
rows carry no cue.
- **Missing records (A).** Only the owner may list or inspect a retained
record whose file is gone. Every other principal sees only marks on files it
can currently read, even a mark it made itself; the host leaves the rest out
of rows and counts.
- **Marker identity (A).** The owner may see the marking principal's label.
Other principals' responses carry the marking date and no identity field.

**The runtime's own traffic — 2026-11-02
([#3244](https://github.com/schlessera/brain-kit/issues/3244)).** The Claude
runtime's own calls to its vendor were worker connections too. Its first-party
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/module-renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Rejected:
`<img>`.** This was the first proposal. It cannot print white from the
browser, it cannot theme on WebKit, and it cannot inherit the app's fonts:
the raw-file CSP is `default-src 'none'` (`img-src 'self' data:`,
`packages/ui-server/src/routes/files.ts:160`) and an image may not fetch
`packages/ui-server/src/routes/files.ts:206`) and an image may not fetch
fonts. It also leaves the figure an opaque, undiffable file beside markdown
that is supposed to be the source of truth.
- **Phase the work, files first and renderers later.** Rejected by the
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/session-principals.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ credentials, not people.
(`upsertRollup`, `activity/sql.ts:19-24`) — the rollup is what survives span
pruning, so cost-by-actor dies at prune time without it. The precedent is
profile/billing: a root-span attr that the rollup reads (`spanId: rootSpanId`,
`activity/recorder.ts:243-258`). Nullable for cron (`origin: "cron"`,
`activity/recorder.ts:253-268`). Nullable for cron (`origin: "cron"`,
`activity/span-sink.ts:102`, `cron/run-job.ts:113`) and for pre-migration rows;
nothing is backfilled.

Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/voice-permission.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ An approval given by voice must be as reviewable afterwards as one given by
tapping a card. Most of that already exists: every decision is written as an
append-only `approval_decision` event carrying the principal, the decision and
the request kind, and it patches the span
(`onApprovalDecision`, `packages/ui-server/src/activity/recorder.ts:674-689`),
(`onApprovalDecision`, `packages/ui-server/src/activity/recorder.ts:684-699`),
fed from the bridge's
`recorded()` wrapper
(`const recorded`, `packages/ui-server/src/ws/bridge.ts:414-429`).
Expand Down
37 changes: 35 additions & 2 deletions docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ compatibility guarantee. Authentication requirements are a separate property.
A public liveness probe can be supported; an authenticated settings route can
be internal.

The inventory includes the additive Queue intake, poke, scheduled-task, session-draft, session-recovery interactive HTML preview, saved-audio transcription, human-started hygiene-review, governance-event, roadblock-report, reference-grant and retained-journal/user-revert routes mounted by `createApp`: 159 unique declared
The inventory includes the additive Queue intake, poke, scheduled-task, session-draft, session-recovery interactive HTML preview, saved-audio transcription, human-started hygiene-review, governance-event, roadblock-report, reference-grant and retained-journal/user-revert and untrusted-mark routes mounted by `createApp`: 163 unique declared
method/path pairs, plus the conditional SPA fallback. It describes the current
implementation, including limitations, rather than a proposed redesign.
Unknown response fields must be tolerated. There is no HTTP API revision
Expand Down Expand Up @@ -92,6 +92,10 @@ client code has a gap. Source owners are listed after the table.
| GET | `/api/files/resolve` | I | Resolve ancestor navigation and existence | React file browser; view/navigation helpers are paired UI transport. |
| GET | `/api/files/tree` | I | List browsable directory entries | React file browser; view/navigation helpers are paired UI transport. |
| GET | `/api/files/wikilinks` | I | Read or refresh cached slug-to-path map | React file browser; view/navigation helpers are paired UI transport. |
| GET | `/api/files/untrusted` | I | Read one path's untrusted mark as this principal may see it | React Files toolbar (#2673); paired UI transport. Its authority and disclosure rules are specified below. |
| PUT | `/api/files/untrusted` | I | Mark a readable file untrusted | React Files toolbar (#2673); paired UI transport. Its authority and disclosure rules are specified below. |
| DELETE | `/api/files/untrusted` | I | Clear a present or retained mark (owner only) | React Files toolbar and `Marked untrusted` list (#2673); paired UI transport. Its authority rules are specified below. |
| GET | `/api/files/untrusted/list` | I | List the marks this principal may see | React `Marked untrusted` list (#2673); paired UI transport. Its disclosure rules are specified below. |
| GET | `/api/geo/coastline` | S | Read attributed map geometry for a bounding box | Independent map clients; preserve show_block map HTTP promise and graceful geometry degradation. |
| GET | `/api/governance/roadblocks` | I | Retained roadblock rankings for the paired activity bridge | #1672; authenticated and local-only. The additive `query_activity` scope is the supported agent contract. |
| GET | `/api/governance/events` | S | Read the governance events kept with session history | Independent diagnostics and the roadblock report; additive #1651 ([contract](integration-contract/http.md#governance-events-additive-1651)). Versioned per kind; never renders to the user. |
Expand Down Expand Up @@ -192,7 +196,7 @@ Authentication factories live in [auth.ts](../packages/ui-server/src/middleware/
[passkeys.ts](../packages/ui-server/src/middleware/passkeys.ts) and
[principals.ts](../packages/ui-server/src/middleware/principals.ts).
[app.ts](../packages/ui-server/src/app.ts) owns prefixing and middleware order.
All 159 declared endpoints are mounted regardless of backend, renderer or
All 163 declared endpoints are mounted regardless of backend, renderer or
speech-provider availability: unavailable capabilities return the responses
below rather than removing their handlers. Only static serving is conditional.

Expand Down Expand Up @@ -1073,6 +1077,35 @@ asserts the isolation and both accepted behaviours. In a split topology, where
the client is served from another origin, `frame-ancestors 'self'` refuses the
preview frame; the new-tab link is not subject to framing rules.

## Untrusted file marks (internal, #2673)

The four `/api/files/untrusted` operations are protected, internal UI
transport: their payloads carry no independent-client guarantee, but their
authority and disclosure rules are security properties and are pinned by
`packages/ui-server/tests/untrusted-marks.test.ts`.

- A mark is a host record in the UI database keyed by the normalized
brain-relative path, never a `brain.db` row or frontmatter key, so it
survives a restart and `brain index --force`. A moved or deleted file keeps
its old-path record; nothing follows a rename.
- `PUT` with JSON `{ path }` needs the read access `GET /api/files/content`
already grants and a regular file at the path: a missing path or directory
is 404 `not_found`, invalid path syntax 400 `invalid_path`. It answers
`{ status: "marked" | "already_marked", mark }`. Marking grants nothing else.
- `DELETE ?path=` is the human owner's alone (an `owner` or `ambient`
principal, the storage routes' rule); any other principal gets 403
`owner_required`. It clears present and retained missing records and answers
`{ status: "cleared" | "already_cleared" }`. It never removes a session's
recorded taint.
- `GET ?path=` answers `{ path, marked: false, canClear }` or
`{ path, marked: true, markedAt, missing, markedBy?, canClear }`. A reader
asking about a path with no readable file gets 404 `not_found`, whether or
not a record is retained there.
- `GET /list` answers `{ marks, canClear }`, missing records first and then
newest first. The owner sees every record; any other principal sees only
records whose file it can currently read. Only the owner's rows and details
carry `markedBy: { label, you }`; other principals' responses omit the field.

## Saved-audio transcription

The protected `GET /api/voice/capabilities` returns `VoiceCapabilitiesResponse`
Expand Down
11 changes: 11 additions & 0 deletions docs/integration-contract/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ hash directly. Missing/expired raw details never grant a download bypass.
links use the embedding root's configured API base.
Those read helpers do not execute mutations.

<a id="untrusted-file-marks-additive-2673"></a>

### Untrusted file marks (additive, #2673)

Four internal `/api/files/untrusted` operations mark a readable brain file
untrusted, read one path's mark, list the marks a principal may see and let the
owner clear one. They are paired UI transport, specified with their authority
and disclosure rules in [the HTTP inventory](../http-api.md#untrusted-file-marks-internal-2673).
The `taint` governance event's shape is unchanged: its reserved
`source: "user_marked"` value is now produced.

<a id="brain-wide-configuration-coverage-additive-3257"></a>

### Brain-wide configuration coverage (additive, #3257)
Expand Down
4 changes: 2 additions & 2 deletions docs/plans/async-collaboration-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ Stated before the requirements because five of them derive from it.
`persistSession: false`; pi provides `SessionManager.inMemory`. Drive this mode
with a synthetic checkpoint bridge and server-selected authority; the
recorder accepts autonomous origin and keeps runtime identity separate from an interactive session
(`export function createTurnRecorder(`, `packages/ui-server/src/activity/recorder.ts:125-203`).
(`export function createTurnRecorder(`, `packages/ui-server/src/activity/recorder.ts:126-204`).
- R25. **Autonomous work gets its own pool** (`MAX_AUTONOMOUS_RUNS`, default 2) — but a second
counter alone does not deliver "interactive always wins". The host cap applies only when
starting WS sessions (`const cap = host.maxConcurrentSessions();`, `packages/ui-server/src/ws/run-session.ts:1336-1348`), and an autonomous
Expand Down Expand Up @@ -343,7 +343,7 @@ Stated before the requirements because five of them derive from it.
policy proposals, and discuss-session digest construction when those v2 features ship. Revision 1's "T2 is the entire
bill" was false.
- R41. **Budgets are enforced by reservation at claim time, not by summing history.**
`rollupRun` runs in `finish()` (`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:746`), so cost exists only after a
`rollupRun` runs in `finish()` (`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:756`), so cost exists only after a
run ends: two runs can both start under the cap and finish over it, and unknown effective
costs are excluded from the sum (`export function sumEffectiveCost(`, `packages/ui-server/src/activity/store.ts:179-194`) so the query **fails open**.
Required: transactional reservations on claim, in-flight reservations counted, settlement at
Expand Down
4 changes: 2 additions & 2 deletions docs/plans/async-collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ system gate. It is not a prerequisite to rebuild or a new independent package.
- **Pi resources and extension gate:** (`export function createSessionResources(`, `packages/ui-backend-pi/src/session-resources.ts:29-152`) and
(`export function createPermissionGate(`, `packages/ui-backend-pi/src/permission-gate.ts:96-125`). Built-ins are disabled,
but ambient resources/extensions and in-process execution still need containment.
- **Cost timing:** (`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:746`) settles after execution;
- **Cost timing:** (`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:756`) settles after execution;
(`export function sumEffectiveCost(`, `packages/ui-server/src/activity/store.ts:179-194`) explicitly counts unpriced runs.
Reservations must cover in-flight work, not only this retrospective sum.
- **Notifications:** (`CREATE TABLE IF NOT EXISTS notification_intents (`, `packages/ui-server/migrations/007_activity.sql:99-114`),
Expand Down Expand Up @@ -1193,7 +1193,7 @@ and a server-selected tool policy.
- Modify: `packages/ui-backend-claude/src/backend.ts` (`persistSession: false`, synthetic
bridge)
- Modify: `packages/ui-server/src/activity/recorder.ts` (server-selected
origin defaults to `"session"` at (`export function createTurnRecorder(`, `packages/ui-server/src/activity/recorder.ts:125-203`))
origin defaults to `"session"` at (`export function createTurnRecorder(`, `packages/ui-server/src/activity/recorder.ts:126-204`))
- Test: `packages/ui-backend-claude/tests/autonomous-turn.test.ts`

**Approach:** an autonomous request carrying persistence, tool policy, origin, and prompt
Expand Down
2 changes: 1 addition & 1 deletion docs/plans/navigation-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ implementation. Any PR moving these lines owns their citation repairs.

- Session summary shape: (`export interface ChatSession {`, `packages/ui-sdk/src/protocol.ts:1576-1592`).

- Run identity: (`const runId = turn.turnId;`, `packages/ui-server/src/activity/recorder.ts:154-155`).
- Run identity: (`const runId = turn.turnId;`, `packages/ui-server/src/activity/recorder.ts:155-156`).

- Outcome vocabulary: (`export type ActivitySpanOutcome =`, `packages/ui-sdk/src/protocol.ts:2983-3006`).

Expand Down
Loading
Loading