Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f7d66d8
CONTRACT: feat(ui-server): deliver immutable reference ranges through…
schlessera Nov 17, 2026
3278128
Merge remote-tracking branch 'origin/main' into feat/3613-read-delive…
schlessera Nov 17, 2026
9d54c7d
refactor(ui-server): keep reference read records internal
schlessera Nov 17, 2026
a994424
test(ui-sdk): include immutable reads in declared tool inventory
schlessera Nov 17, 2026
5dae0ea
fix(ui-server): preserve clone locations for immutable reference reads
schlessera Nov 17, 2026
d4fe2e4
test: record immutable reference reads in backend tool inventories
schlessera Nov 17, 2026
c5674ce
Merge remote-tracking branch 'origin/main' into feat/3613-read-delive…
schlessera Nov 17, 2026
b75fb11
Merge remote-tracking branch 'origin/main' into feat/3613-read-delive…
schlessera Nov 17, 2026
d32d197
test: isolate tool inventory fixtures on every repetition
schlessera Nov 17, 2026
eda2d17
Merge remote-tracking branch 'origin/main' into feat/3613-read-delive…
schlessera Nov 17, 2026
fb2f7ad
fix(ui-server): invalidate read evidence for rejected results
schlessera Nov 17, 2026
0256212
Merge remote-tracking branch 'origin/main' into feat/3613-read-delive…
schlessera Nov 17, 2026
1683785
fix(ui-server): keep incomplete reference deliveries unknown
schlessera Nov 17, 2026
edf3235
test: include immutable reads in the shared measurement roster
schlessera Nov 17, 2026
b12fbb6
fix(pi): qualify reads against final tool result state
schlessera Nov 18, 2026
e0b0fe3
Merge remote-tracking branch 'origin/main' into feat/3613-read-delive…
schlessera Nov 18, 2026
dd57360
fix(pi): retain read loss before protocol rejection
schlessera Nov 18, 2026
8378c7b
Merge remote-tracking branch 'origin/main' into feat/3613-read-delive…
schlessera Nov 18, 2026
f31f119
Merge remote-tracking branch 'origin/main' into feat/3613-read-delive…
schlessera Nov 18, 2026
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/immutable-reference-delivery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
"@schlessera/brain-backend-claude": minor
"@schlessera/brain-backend-pi": minor
---

Add bounded immutable GitHub reference-file reads on both backends. Keep acquisition, returned-range digests and exact tool-result observations in host storage, with live authority and sealed-root checks across waits. Repository reads remain untrusted input.
72 changes: 70 additions & 2 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,9 @@ export "./client" (./src/client/index.ts)
READ_ATTACHMENT_DESCRIPTION
READ_ATTACHMENT_INPUT_SCHEMA
READ_ATTACHMENT_TOOL_NAME
REFERENCE_READ_CONTRACT
REFERENCE_READ_INPUT_SCHEMA
REFERENCE_READ_TOOL_NAME
REFERENCE_SOURCE_CONTRACT
REFERENCE_SOURCE_INPUT_SCHEMA
REFERENCE_SOURCE_TOOL_NAME
Expand All @@ -1062,6 +1065,8 @@ export "./client" (./src/client/index.ts)
RESOLVE_ACTION_INPUT_SCHEMA
type ReadAttachmentInput
type RecordingTranscription
type ReferenceReadInput
type ReferenceReadView
type ReferenceSourceInput
type ReferenceSourceView
type ReferenceToolCall
Expand Down Expand Up @@ -2945,6 +2950,9 @@ export "./server" (./src/server/index.ts)
READ_ATTACHMENT_DESCRIPTION
READ_ATTACHMENT_INPUT_SCHEMA
READ_ATTACHMENT_TOOL_NAME
REFERENCE_READ_CONTRACT
REFERENCE_READ_INPUT_SCHEMA
REFERENCE_READ_TOOL_NAME
REFERENCE_SOURCE_CONTRACT
REFERENCE_SOURCE_INPUT_SCHEMA
REFERENCE_SOURCE_TOOL_NAME
Expand All @@ -2968,6 +2976,8 @@ export "./server" (./src/server/index.ts)
type ReadAttachmentInput
type RecordingTranscription
type RecoverableTranscriptStore
type ReferenceReadInput
type ReferenceReadView
type ReferenceSourceInput
type ReferenceSourceView
type ReferenceToolCall
Expand Down Expand Up @@ -3613,6 +3623,9 @@ export "./tool-contracts" (./src/tool-contracts/index.ts)
READ_ATTACHMENT_DESCRIPTION
READ_ATTACHMENT_INPUT_SCHEMA
READ_ATTACHMENT_TOOL_NAME
REFERENCE_READ_CONTRACT
REFERENCE_READ_INPUT_SCHEMA
REFERENCE_READ_TOOL_NAME
REFERENCE_SOURCE_CONTRACT
REFERENCE_SOURCE_INPUT_SCHEMA
REFERENCE_SOURCE_TOOL_NAME
Expand All @@ -3634,6 +3647,8 @@ export "./tool-contracts" (./src/tool-contracts/index.ts)
RESOLVE_ACTION_CONTRACT
RESOLVE_ACTION_INPUT_SCHEMA
type ReadAttachmentInput
type ReferenceReadInput
type ReferenceReadView
type ReferenceSourceInput
type ReferenceSourceView
type ReferenceToolCall
Expand Down Expand Up @@ -6332,6 +6347,12 @@ signatures (every public export and the types it is made of)
repository: z.ZodOptional<z.ZodString>;
revision: z.ZodOptional<z.ZodString>;
worktreeId: z.ZodOptional<z.ZodString>;
}, z.core.$strict>>, import("./contract.js").ToolContract<"reference_read", z.ZodObject<{
maximum: z.ZodDefault<z.ZodNumber>;
offset: z.ZodDefault<z.ZodNumber>;
path: z.ZodString;
repository: z.ZodString;
revision: z.ZodString;
}, z.core.$strict>>, import("./contract.js").ToolContract<"brain_compute_health", z.ZodObject<{
provider: z.ZodOptional<z.ZodString>;
}, z.core.$strict>>, import("./contract.js").ToolContract<"brain_compute_plan", z.ZodObject<{
Expand Down Expand Up @@ -6369,7 +6390,7 @@ signatures (every public export and the types it is made of)
const BRIDGE_TOOL_POSTURE: Readonly<{
allowedTools(adapter: BridgeToolAdapter): readonly string[];
claudePrefix: "mcp__brain-ui__";
names: readonly ("ask_user" | "ask_user_form" | "ask_user_list" | "ask_user_rank" | "brain_compute_cancel" | "brain_compute_collect" | "brain_compute_health" | "brain_compute_plan" | "brain_compute_run" | "brain_compute_status" | "complete_share" | "get_current_location" | "inbox_add" | "inbox_get" | "inbox_list" | "query_activity" | "reference_source" | "reference_worktree" | "request_image_markup" | "request_image_mask" | "resolve_action" | "show_block" | "turn_temp")[];
names: readonly ("ask_user" | "ask_user_form" | "ask_user_list" | "ask_user_rank" | "brain_compute_cancel" | "brain_compute_collect" | "brain_compute_health" | "brain_compute_plan" | "brain_compute_run" | "brain_compute_status" | "complete_share" | "get_current_location" | "inbox_add" | "inbox_get" | "inbox_list" | "query_activity" | "reference_read" | "reference_source" | "reference_worktree" | "request_image_markup" | "request_image_mask" | "resolve_action" | "show_block" | "turn_temp")[];
visibleName(name: BridgeToolName, adapter: BridgeToolAdapter): string;
}>;
BackendActivityEvent (packages/ui-sdk/src/server/backend.ts)
Expand Down Expand Up @@ -11544,6 +11565,24 @@ signatures (every public export and the types it is made of)
}, z.core.$strict>;
READ_ATTACHMENT_TOOL_NAME (packages/ui-sdk/src/tool-contracts/attachment.ts)
const READ_ATTACHMENT_TOOL_NAME: "read_attachment";
REFERENCE_READ_CONTRACT (packages/ui-sdk/src/tool-contracts/reference.ts)
const REFERENCE_READ_CONTRACT: import("./contract.js").ToolContract<"reference_read", z.ZodObject<{
maximum: z.ZodDefault<z.ZodNumber>;
offset: z.ZodDefault<z.ZodNumber>;
path: z.ZodString;
repository: z.ZodString;
revision: z.ZodString;
}, z.core.$strict>>;
REFERENCE_READ_INPUT_SCHEMA (packages/ui-sdk/src/tool-contracts/reference.ts)
const REFERENCE_READ_INPUT_SCHEMA: z.ZodObject<{
maximum: z.ZodDefault<z.ZodNumber>;
offset: z.ZodDefault<z.ZodNumber>;
path: z.ZodString;
repository: z.ZodString;
revision: z.ZodString;
}, z.core.$strict>;
REFERENCE_READ_TOOL_NAME (packages/ui-sdk/src/tool-contracts/reference.ts)
const REFERENCE_READ_TOOL_NAME: "reference_read";
REFERENCE_SOURCE_CONTRACT (packages/ui-sdk/src/tool-contracts/reference.ts)
const REFERENCE_SOURCE_CONTRACT: import("./contract.js").ToolContract<"reference_source", z.ZodObject<{
repository: z.ZodString;
Expand Down Expand Up @@ -11571,6 +11610,12 @@ signatures (every public export and the types it is made of)
repository: z.ZodOptional<z.ZodString>;
revision: z.ZodOptional<z.ZodString>;
worktreeId: z.ZodOptional<z.ZodString>;
}, z.core.$strict>>, import("./contract.js").ToolContract<"reference_read", z.ZodObject<{
maximum: z.ZodDefault<z.ZodNumber>;
offset: z.ZodDefault<z.ZodNumber>;
path: z.ZodString;
repository: z.ZodString;
revision: z.ZodString;
}, z.core.$strict>>];
REFERENCE_WORKTREE_ACTIONS (packages/ui-sdk/src/tool-contracts/reference.ts)
const REFERENCE_WORKTREE_ACTIONS: readonly ["request", "access", "renew", "release", "list"];
Expand Down Expand Up @@ -11692,6 +11737,20 @@ signatures (every public export and the types it is made of)
sourceVersion: string;
}): string;
}
ReferenceReadInput (packages/ui-sdk/src/tool-contracts/reference.ts)
export type ReferenceReadInput = z.infer<typeof REFERENCE_READ_INPUT_SCHEMA>;
ReferenceReadView (packages/ui-sdk/src/tool-contracts/reference.ts)
export interface ReferenceReadView {
repository: string;
revision: string;
commit: string;
path: string;
offset: number;
length: number;
totalBytes: number;
encoding: "utf8" | "base64";
content: string;
}
ReferenceSourceInput (packages/ui-sdk/src/tool-contracts/reference.ts)
export type ReferenceSourceInput = z.infer<typeof REFERENCE_SOURCE_INPUT_SCHEMA>;
ReferenceSourceView (packages/ui-sdk/src/tool-contracts/reference.ts)
Expand All @@ -11713,6 +11772,10 @@ signatures (every public export and the types it is made of)
} | {
tool: typeof REFERENCE_WORKTREE_TOOL_NAME;
input: ReferenceWorktreeInput;
} | {
tool: typeof REFERENCE_READ_TOOL_NAME;
input: ReferenceReadInput;
toolCallId?: string;
};
ReferenceToolName (packages/ui-sdk/src/server/bridge-tools/reference.ts)
export type ReferenceToolName = (typeof REFERENCE_TOOL_CONTRACTS)[number]["name"];
Expand All @@ -11723,6 +11786,10 @@ signatures (every public export and the types it is made of)
ok: true;
source: ReferenceSourceView;
guidance: string;
} | {
ok: true;
read: ReferenceReadView;
guidance: string;
} | {
ok: true;
action: Exclude<ReferenceWorktreeAction, "list">;
Expand Down Expand Up @@ -14628,6 +14695,7 @@ signatures (every public export and the types it is made of)
turnTemp?: string | false;
referenceSource?: string | false;
referenceWorktree?: string | false;
referenceRead?: string | false;
computeHealth?: string | false;
computePlan?: string | false;
computeRun?: string | false;
Expand Down Expand Up @@ -16943,7 +17011,7 @@ signatures (every public export and the types it is made of)
isError: boolean;
}>;
handleReferenceTool (packages/ui-sdk/src/server/bridge-tools/reference.ts)
export function handleReferenceTool(name: ReferenceToolName, input: unknown, bridge: Pick<BackendBridge, "referenceAccess">): Promise<{
export function handleReferenceTool(name: ReferenceToolName, input: unknown, bridge: Pick<BackendBridge, "referenceAccess">, toolCallId?: string): Promise<{
text: string;
isError: boolean;
}>;
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/answer-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Claude Code sends `_meta["claudecode/toolUseId"]` on every MCP `tools/call`,
and the Agent SDK's in-process server hands a request's `_meta` to the tool
handler as `extra._meta`. The SDK types that argument as `unknown`, so the
field is read defensively, with a minted id as the fallback (`askRequestId`,
`packages/ui-backend-claude/src/tool-use-id.ts:20-25`). This was measured
`packages/ui-backend-claude/src/tool-use-id.ts:28-33`). This was measured
before anything was built on it: a keyless run of the bundled CLI 2.1.283
against a scripted model on loopback delivered exactly the scripted
`tool_use` id. `packages/ui-backend-claude/tests/ask-tool-request-id.test.ts`
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/claude-code-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ into them.
A turn's environment is the filtered agent environment plus the profile's
additions (`export function turnEnv`, `packages/ui-backend-claude/src/sdk-options.ts:86-92`,
`envSnapshot`, `packages/ui-backend-claude/src/config/env.ts:201-209`), handed to the SDK
whole (`sdkOptions.env = childEnv`, `sdk-options.ts:461`). A declared bearer-token profile clears both
whole (`sdkOptions.env = childEnv`, `sdk-options.ts:514`). A declared bearer-token profile clears both
ambient credentials (`input.authTokenEnv !== undefined`, `profiles.ts:116-122`); a declared API-key profile sets
the key on purpose (`input.apiKeyEnv !== undefined`, `profiles.ts:123-125`).
- **Billing originally relied on ambient credential classification.** The
Expand Down Expand Up @@ -607,7 +607,7 @@ subscription authenticates.
environment is necessary, whether or not a subscription credential is
present. It is not sufficient: the CLI also takes an API key from an
`apiKeyHelper` in settings — the backend loads the brain repo's project
settings (`settingSources: ["project"]`, `sdk-options.ts:329`) — and from a stored Console login, reported
settings (`settingSources: ["project"]`, `sdk-options.ts:438`) — and from a stored Console login, reported
as `/login managed key` (`sdk.d.ts:5585`). So the turn has to check which
credential the CLI selected **before the prompt is sent**, and end the turn
if it is not a subscription. The check reads the account from the SDK's
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/design-kit/answer-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ turns the complete roster the model reached for was `bash`, `show_block`,
`brain_read`, `grep`, `brain_search`, `read_file`, `brain_list`, `brain_graph`:
no search-then-load round trip, ever. The brief is in the prompt on every turn
unconditionally (`block: "show_block"`,
`packages/ui-backend-pi/src/session-resources.ts:213`, not behind a capability
`packages/ui-backend-pi/src/session-resources.ts:214`, not behind a capability
check like the four bridge tools beside it). So pi is the structural twin of
D43's `--always-load` arm and has never run any other configuration.

Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/design-kit/show-block-brief.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ is in the prompt on every pi turn by construction. That makes pi's shipping
configuration the structural equivalent of this record's `--always-load`
**brief** arm — and only that one. pi has no no-brief arm and no supported way
to have one: `block: "show_block"`,
`packages/ui-backend-pi/src/session-resources.ts:213` passes the
`packages/ui-backend-pi/src/session-resources.ts:214` passes the
block brief unconditionally, where the four lines above it gate their briefs on
a capability. So pi can corroborate the loaded *rate* and can say nothing at
all about whether the brief matters; the 77%/77% here and #148's 76%/77% are
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/design-kit/tool-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Two things stop that residue being read as a like-for-like gap, and both cut
against reading pi as a second replication of the brief result. pi is on a
different harness driving the model directly, and — this is the one that matters
— **pi has no no-brief arm and no supported way to have one.**
`block: "show_block"`, `packages/ui-backend-pi/src/session-resources.ts:213`
`block: "show_block"`, `packages/ui-backend-pi/src/session-resources.ts:214`
passes the block brief into `buildSystemPromptAppend` unconditionally, not
behind a capability check like `askUser`, `location`, `activity` and `mask` on
the lines above it. So every pi number was measured with the brief present. The
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ worker does:
- **Only interactive turns are journaled, and they load project
configuration.** Evidence is wired only into the session-run turn request
for a governed turn with a journal (`export function turnRequest`,
`packages/ui-server/src/ws/session-run/backend-entry.ts:217-232`). That turn
`packages/ui-server/src/ws/session-run/backend-entry.ts:218-233`). That turn
is never a restricted autonomous one. It runs with `settingSources:
["project"]` and without `strictMcpConfig`
(`const sdkOptions: Options`, `packages/ui-backend-claude/src/sdk-options.ts:406-422`).
Expand Down
10 changes: 5 additions & 5 deletions docs/decisions/managed-worktrees.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ opened
A call carries only a repository, a revision or a worktree identity. The bridge
adds the turn's own principal, and a call for a turn the host did not prepare,
or under another principal, refuses
(`async call(turnId: string`, `packages/ui-server/src/brain/reference-tools.ts:155-204`).
(`async call(turnId: string`, `packages/ui-server/src/brain/reference-tools.ts:160-209`).
Every operation then runs through the acquisition and worktree services, which
check grants, validation and ownership again; a tool never repeats or skips
their rules. Once the turn ends, its record is gone and its bridge holds
Expand All @@ -234,7 +234,7 @@ public view and their principal's private view whole and read-only at
(`// Shared reference source (#2432)`, `packages/ui-sdk/src/server/worker-launcher.ts:898-909`).
A view the domain has not published to yet is opened empty first, so the turn
sees its own first acquisition
(`async bindable(principalId: string`, `packages/ui-server/src/brain/reference-source.ts:1209-1240`).
(`async bindable(principalId: string`, `packages/ui-server/src/brain/reference-source.ts:1212-1243`).
A refresh renames the name a later lookup resolves, so reads stay live and
nothing pins a revision. A view is the domain's authorized cache: its names are
published under that domain's authority and withdrawn when the authority is
Expand Down Expand Up @@ -277,7 +277,7 @@ source. Managed GitHub sources are withheld without network access: their
validation needs an explicit request on the new turn's proxy and budget.
These rules cover sources a running turn reads; a running reader keeps its
existing mount
(`async function settleView`, `packages/ui-server/src/brain/reference-source.ts:976-1014`):
(`async function settleView`, `packages/ui-server/src/brain/reference-source.ts:979-1017`):

- a source with less than the bind margin of validation left counts as
lapsed: a minute, or half of a shorter configured lifetime, so it does not
Expand All @@ -291,7 +291,7 @@ existing mount
one kept only for a worktree or staging whose publication reply was lost.

Withholding takes a source's name and roots out of the view
(`function suspendSource`, `packages/ui-server/src/brain/reference-source.ts:873-890`).
(`function suspendSource`, `packages/ui-server/src/brain/reference-source.ts:876-893`).
Its cache and charge stay, and the next request that validates it publishes it
again. A running reader keeps its bind of the view and the files it has open;
its later lookups of a withheld name fail until a request validates the source.
Expand All @@ -310,7 +310,7 @@ withheld rather than checked again; withholding takes only short pool calls,
so the bind converges whatever the cache size. A bind that still cannot be
admitted, because a pool change stays unconfirmed, refuses, and the turn runs
without shared source views
(`function admissible`, `packages/ui-server/src/brain/reference-source.ts:1038-1047`).
(`function admissible`, `packages/ui-server/src/brain/reference-source.ts:1041-1050`).
The margin covers the moments between admission and the workers' mounts.

Suspension, restoration, withdrawal and publication of one source run one at a
Expand Down
38 changes: 37 additions & 1 deletion docs/decisions/reference-source-acquisition.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,49 @@ that durable acquisition/read correlation and approved-owner matching remain
necessary for a source-trust decision. Ordinary file reads keep their existing
workspace restrictions, and no directory, credential or hostname grants trust.

### Turn-bound content delivery

The `reference_read` tool composes the fixed reader with a fresh managed
acquisition request. Its repository/ref/path/range are model input; principal,
turn, network budget and actual backend tool-call identity are independent host
context. Missing or reused call identity refuses. The selected lease pins the
source while native sealing and immutable reading wait, and the service checks
both native root generation and live authority after those waits.

Before returning content, the shared SQLite writer records an acquisition
snapshot and regular blob/path/range/digest, detector version, the selected
read grant and digest of the exact content result. The transaction rechecks
the acquisition mapping, durable authority fence and current private grant.
The caller checks live turn/principal/source authority again after the writer
returns. These records remain outside source files and provider history and
survive eviction of the acquisition. The selected grant for a new read may
differ from the original acquisition's grant; both facts retain their own
meaning.

The awaited input-safety result hook observes a read only when one finalized
text segment exactly matches its prepared result at that turn/call identity.
An absent hook leaves `prepared`, and altered, mixed or unfinished results
become sticky `unknown`. Observation is evidence of that backend result,
not proof of a later provider request. Every read still records workspace
input; ordinary file marks keep their independent signals. Approved-owner
matching and the full qualified source-trust route remain separate work.

Observation compares the complete plain-text result or the fixed tool's
single-text MCP envelope with that segment. Extra content, structured payloads
and error envelopes cannot borrow a matching text part. Pi omits qualified
segments for a mixed reference result instead of filtering away its non-text
parts. Reports lost before the collector's result method, including malformed
or replayed worker RPCs, invalidate that call before failure containment.
An earlier loss also fences a read prepared afterward; another call's known
observation remains independent.

## Admission

At most `BRAIN_UI_REFERENCE_ACQUISITIONS` (default two) acquisitions or
refreshes run across the host
(`admit`, `packages/ui-server/src/brain/reference-source.ts:326-341`). Requests
for the same legacy source in the same domain join one operation
(`function join`, `packages/ui-server/src/brain/reference-source.ts:344-369`).
(`function join`, `packages/ui-server/src/brain/reference-source.ts:346-371`).
Each principal's private source is its own domain, so two principals requesting
the same private repository at once run two operations, each with its own
credential and view. Admitted operations finish independently: a stalled one
Expand Down
Loading
Loading