Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions .changeset/chat-store-slices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-react": patch
---

The chat store is now built from separate slices for sessions, session status, messages, streaming, approvals, ask-user questions and transcript replay. It behaves as before: the store's state, actions, hooks and selectors are unchanged.
5 changes: 5 additions & 0 deletions .changeset/claude-permission-sdk-assembly-split.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-backend-claude": patch
---

The Claude backend now builds a turn's permission wiring and SDK options in separate steps. Permission wiring is split into its native-file guards, enforcement hook, `canUseTool` callback, mutating hook and rewrite hooks. SDK options are split into the tool roster, the turn environment, the sandbox note and the prompt context. Permission decisions, the tool list and its order, and the system prompt are unchanged.
5 changes: 5 additions & 0 deletions .changeset/claude-turn-runner-split.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-backend-claude": patch
---

The Claude backend's turn runner is now split into its terminal state, host inference relay, prompt gate, runtime reporting and stream loop. Turns behave as before: frames, outcomes, refusals and cleanup are unchanged.
5 changes: 5 additions & 0 deletions .changeset/client-message-handler-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-server": patch
---

WebSocket client messages are now dispatched through a per-message handler table. Behaviour and the wire protocol are unchanged.
5 changes: 5 additions & 0 deletions .changeset/pi-worker-session-tools-split.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-backend-pi": patch
---

The pi backend's worker session is now split into worker launch, a table of RPC handlers with one per method, receipt persistence and the protocol reader. Its curated tools are now one named factory per tool, grouped into file tools, brain tools and the routing for application tools. Turns behave as before: tool names, schemas, results, permission decisions and the worker protocol are unchanged.
5 changes: 5 additions & 0 deletions .changeset/retained-session-stages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-server": patch
---

A session's turns now run through named lifecycle stages: slot setup, host and governed admission, backend entry, outcome classification and teardown. Turn behaviour, ordering and the wire protocol are unchanged.
5 changes: 5 additions & 0 deletions .changeset/turn-coordinator-ownership.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-server": patch
---

Closing the host now rejects every pending location and mask request and denies every pending approval or question, including ones whose turn had already stopped. Previously those requests could stay unsettled. Turn state is now owned by the coordinator; the ask-user duplicate-id rules are unchanged.
5 changes: 5 additions & 0 deletions .changeset/websocket-client-parts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-react": patch
---

The WebSocket client is now composed from separately tested parts: the socket lease, the gated outbound path, inbound routing, reconnect healing, session restoration, turn retries and account services. Retry and answer receipts and session queue reports are handled through the typed frame handler map. Behaviour and the wire protocol are unchanged.
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ on, links to or describes them.
declared with `defineModule({ name, configSchema, setup })`. Run
`brain module lint` before submitting one.
- Cite code from docs and source comments as an anchor followed by its range:
(`enforcementHook`, `packages/ui-backend-claude/src/permission-hooks.ts:200-229`),
(`enforcementHook`, `packages/ui-backend-claude/src/permission-hooks.ts:289-330`),
starting on the anchor's line. A PR that moves lines under a citation should
fix it when it can (`git grep -n '<file>.ts:' -- docs packages`), but drift
never blocks a merge or turns main red: it is a **release check**.
Expand Down
24 changes: 10 additions & 14 deletions api-report/ui-react.txt
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,8 @@ signatures (every public export and the types it is made of)
}): ShareOption[];
cancel (packages/ui-react/src/lib/answer-delivery/manager.ts)
function cancel(requestId: string): Promise<void>;
checkRetryDelivery (packages/ui-react/src/connection.ts)
function checkRetryDelivery(sessionId: string): boolean;
checkDelivery (packages/ui-react/src/ws-client/turn-retry.ts)
function checkDelivery(sessionId: string): boolean;
commit (packages/ui-react/src/voice/conversation-client.ts)
function commit(own: number): boolean;
configureBrainUi (packages/ui-react/src/config.ts)
Expand Down Expand Up @@ -1378,15 +1378,15 @@ signatures (every public export and the types it is made of)
discard(): void;
dispose(): void;
enter(): void;
frame: (message: ServerMessage) => ServerMessage | null;
frame: (message: import("@schlessera/brain-ui-sdk").ServerMessage) => import("@schlessera/brain-ui-sdk").ServerMessage | null;
historyOwnerFor: (key: string) => string | undefined;
leave: () => void;
loadDialogue: (key: string, older?: boolean) => void;
mute(): void;
permissions: {
clear(): void;
dispose(): void;
frame: (message: ServerMessage) => void;
frame: (message: import("@schlessera/brain-ui-sdk").ServerMessage) => void;
input: (event: Extract<import("@schlessera/brain-ui-sdk").ConversationWireEvent, {
kind: "input_fragment";
}>) => boolean;
Expand All @@ -1412,10 +1412,10 @@ signatures (every public export and the types it is made of)
resend: (requestId: string) => boolean;
};
flushChatDeltas: () => void;
handleServerMessage: (msg: ServerMessage) => void;
handleServerMessage: (msg: import("@schlessera/brain-ui-sdk").ServerMessage) => void;
reconnectNow: () => void;
retryTurn: (failedTurnId: string) => "pending" | "refused" | "sent";
send: (msg: ClientMessage) => boolean;
send: (message: ClientMessage) => boolean;
};
detectLocalCaptureSupport (packages/ui-react/src/voice/local-capture.ts)
export function detectLocalCaptureSupport(env?: LocalCaptureEnvironment & {
Expand All @@ -1428,13 +1428,11 @@ signatures (every public export and the types it is made of)
function dismissed(requestId: string): void;
edit (packages/ui-react/src/lib/answer-delivery/manager.ts)
function edit(requestId: string): void;
flushChatDeltas (packages/ui-react/src/connection.ts)
function flushChatDeltas(): void;
frame (packages/ui-react/src/voice/conversation-client.ts)
function frame(message: ServerMessage): ServerMessage | null;
frame (packages/ui-react/src/voice/conversation-permissions.ts)
function frame(message: ServerMessage): void;
handleServerMessage (packages/ui-react/src/connection.ts)
handleServerMessage (packages/ui-react/src/ws-client/inbound.ts)
function handleServerMessage(msg: ServerMessage): void;
hasPendingShare (packages/ui-react/src/stores/share-state.ts)
export function hasPendingShare(state: ShareShellState): boolean;
Expand All @@ -1458,8 +1456,6 @@ signatures (every public export and the types it is made of)
function quiet(): void;
receipt (packages/ui-react/src/lib/answer-delivery/manager.ts)
function receipt(frame: ServerAskAnswerReceipt): void;
reconnectWebSocketNow (packages/ui-react/src/connection.ts)
function reconnectWebSocketNow(): void;
registerContentRendererPack (packages/ui-react/src/content-renderers/register.ts)
export function registerContentRendererPack(pack: ContentRendererPack, module: {
name: string;
Expand All @@ -1471,12 +1467,12 @@ signatures (every public export and the types it is made of)
export function renderBlockHtml(block: Block, trackDisplay?: TrackDisplay): Promise<string>;
retry (packages/ui-react/src/lib/answer-delivery/manager.ts)
function retry(requestId: string): Promise<void>;
retryTurn (packages/ui-react/src/connection.ts)
retryTurn (packages/ui-react/src/ws-client/turn-retry.ts)
function retryTurn(failedTurnId: string): "sent" | "pending" | "refused";
runStats (packages/ui-react/src/components/chat/use-chat-commands.ts)
export function runStats(root: BrainUiRoot, sessionId: string | null): Promise<void>;
sendClientMessage (packages/ui-react/src/connection.ts)
function sendClientMessage(msg: ClientMessage): boolean;
send (packages/ui-react/src/connection.ts)
function send(message: ClientMessage): boolean;
shareMarkdown (packages/ui-react/src/components/chat/share-document.tsx)
export function shareMarkdown(message: Pick<ChatMessage, "content" | "parts" | "toolCalls" | "blocks">, deps: ShareDeps): Promise<string>;
softwareDetails (packages/ui-react/src/lib/stats/software.ts)
Expand Down
1 change: 1 addition & 0 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ export "./internal" (./src/internal.ts)
type ClassificationAnswers
type ClassificationPlan
type ClassificationRequest
type CompiledWorkerCommandPolicy
DEFAULT_MAINTENANCE_TEMP_BUDGET_BYTES
DEFAULT_MAINTENANCE_TEMP_BYTES
DEFAULT_OUTPUT_STAGING_BYTES
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ it is told something confidently wrong. So name what you point at, and let the
range follow it:

```md
(`enforcementHook`, `packages/ui-backend-claude/src/permission-hooks.ts:200-229`)
(`enforcementHook`, `packages/ui-backend-claude/src/permission-hooks.ts:289-330`)
```

- **The anchor** is the code span immediately before the citation, joined to it
Expand Down
8 changes: 4 additions & 4 deletions docs/decisions/answer-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ manufacture an identity, and it was not needed.
## One card per request

The store updates a request it already holds and never appends it again
(`addExchange`, `packages/ui-react/src/stores/chat-state.ts:289-320`). A
(`addExchange`, `packages/ui-react/src/stores/chat-slices/ask-user.ts:32-63`). A
settled card stays settled, so a late or replayed frame cannot revive a
dismissed or answered question. A pending card keeps its payload and the
exchange object it is keyed by, so a draft in progress survives a re-send.
Expand All @@ -82,7 +82,7 @@ carries, no longer by position.

The host also re-sends a session's pending questions after `session_resume`
(`resendPendingAsks(host, ws, msg.sessionId)`,
`packages/ui-server/src/ws/dispatch.ts:678`). Before this, a resume replaced
`packages/ui-server/src/ws/handlers/session-resume.ts:37`). Before this, a resume replaced
the transcript and left only a history card behind, which was the second
symptom.

Expand All @@ -91,7 +91,7 @@ symptom.
Each answer carries a client-minted `submissionId`, reused for every retry of
that answer. The host settles the request at most once, records the outcome,
and answers the sender with `ask_answer_receipt` (`handleAskAnswer`,
`packages/ui-server/src/ws/ask-answers.ts:105-181`). A repeat of the same
`packages/ui-server/src/ws/ask-answers.ts:84-138`). A repeat of the same
submission gets the same receipt and settles nothing.

Revision 3's echo is negotiated per connection: a client that declares
Expand Down Expand Up @@ -320,7 +320,7 @@ in both themes, using the keyboard.
The late stored-principal race has one native `ask_user` representative.
All four ChatPage adapters enter `submitAnswer`; the first host frame calls
`answers.connected()` without selecting an answer kind (`answersReady = true`,
`packages/ui-react/src/connection.ts:398-399`). The shared restore path must
`packages/ui-react/src/ws-client/account.ts:74-75`). The shared restore path must
preserve that newer principal. Repeating this browser race for list, rank and
form adds no separate startup path. Their online and offline/reload native
cases remain: input adapters, `answerFrame` serialization and host dispatch
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/claude-2.1.287-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ call, including when settings or a rewrite could otherwise auto-approve it.
The backend builds the actual turn options and production permission handlers
(`createClaudeSdkTurn`, `packages/ui-backend-claude/src/sdk-options.ts:122-511`).
The explicit ask lives in
(`enforcementHook`, `packages/ui-backend-claude/src/permission-hooks.ts:200-229`)
(`enforcementHookFor`, `packages/ui-backend-claude/src/permission-hooks.ts:289-330`)
and is registered under enforcement in
(`...(enforced ?`, `packages/ui-backend-claude/src/permission-hooks.ts:575-578`).
(`...(enforced ?`, `packages/ui-backend-claude/src/permission-hooks.ts:646-649`).

`scripts/measure-claude-enforcement.ts` runs `createClaudeBackend().startTurn()`
and forwards to the SDK resolved from that backend. Its query wrapper only
Expand Down
10 changes: 5 additions & 5 deletions docs/decisions/claude-code-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ a permission boundary:
- **A refusal would not buy what it appears to.** The measured version is not
known-safe either: the list of mechanisms that skip `canUseTool` is what has
been measured, not a closed set (`AT LEAST three`,
`permission-hooks.ts:168-171`). A version gate would separate "probed" from "not
`permission-hooks.ts:257-260`). A version gate would separate "probed" from "not
probed", not "safe" from "unsafe", and it would say the second thing to
whoever reads it.
- **It would block the path a CLI fix takes.** The built-in binary moves only
Expand Down Expand Up @@ -356,7 +356,7 @@ so it holds itself to these rules:
about another.
- **Composition, not only parts.** The enforcement hook's `ask` must leave
another hook's `updatedInput` intact (`An explicit "ask" beats all three`,
`permission-hooks.ts:195-197`; `(e) a hook's`,
`permission-hooks.ts:284-286`; `(e) a hook's`,
`allowlist-enforcement.test.ts:18-21`). That is its own case: a rewrite, an
`ask` and a `canUseTool` decision in one call, asserting the input the
callback saw and the input that executed.
Expand All @@ -383,7 +383,7 @@ until re-measured.

| Site | What it asserts | Re-checked by |
| --- | --- | --- |
| `DO NOT WEAKEN THIS INTO A FALLTHROUGH`, `packages/ui-backend-claude/src/permission-hooks.ts:167-198` | Three things admit a tool before `canUseTool` — the safe-command classifier (`echo hi` with an empty allowlist), a built-in tool's own check (`ToolSearch`), a project-settings `PreToolUse` hook returning `allow` — and an explicit `ask` beats all three. `permissions.allow` rules and `defaultMode: "bypassPermissions"` do not bypass. | Probe cases for each of the three, each with and without the `ask`, plus the two negative controls. |
| `DO NOT WEAKEN THIS INTO A FALLTHROUGH`, `packages/ui-backend-claude/src/permission-hooks.ts:256-288` | Three things admit a tool before `canUseTool` — the safe-command classifier (`echo hi` with an empty allowlist), a built-in tool's own check (`ToolSearch`), a project-settings `PreToolUse` hook returning `allow` — and an explicit `ask` beats all three. `permissions.allow` rules and `defaultMode: "bypassPermissions"` do not bypass. | Probe cases for each of the three, each with and without the `ask`, plus the two negative controls. |
| `Both hooks exist to rewrite`, `packages/ui-backend-claude/src/input-rewrite-hooks.ts:7-14` | A hook's `updatedInput` applies with no decision, and the permission path sees the rewritten input. | Probe case: rewrite with no decision; assert the executed input and the `canUseTool` input. |
| `The runtime precedence modelled by`, `packages/ui-backend-claude/tests/allowlist-enforcement.test.ts:11-20` | The precedence `runToolCall` models, (a)–(e). The test cannot re-measure it. | The cases above plus the composition case. A changed result changes the model in the test in the same PR. |
| `the one answer that beats`, `packages/ui-backend-claude/tests/no-grant-surface.test.ts:13-18` | The same three opinions, and that `ask` is what forces the decision. | Same probe cases. |
Expand All @@ -409,7 +409,7 @@ brain-hosting-template.

None of the live sites is accepted as unverifiable. What stays unverifiable is
the absence of a *fourth* mechanism — `AT LEAST three`,
`permission-hooks.ts:168-171` already says three is what has been measured, not a
`permission-hooks.ts:257-260` already says three is what has been measured, not a
closed set — and no probe can close that.

## Where the work goes
Expand Down Expand Up @@ -1311,7 +1311,7 @@ profile's `baseUrl` from `BRAIN_UI_CLAUDE_PROFILES`, else the server's
`ANTHROPIC_BASE_URL`, else first-party inference. The relay forwards to that
route, keeping its base path. Before the prompt is sent, the runner refuses a
route whose origin is neither first-party nor listed
(`const selectedUpstream`, `packages/ui-backend-claude/src/turn-runner.ts:441-456`).
(`qualify(settings`, `packages/ui-backend-claude/src/turn-inference-relay.ts:108-133`).
Each dispatch checks the same list again before the credential is read. Native
settings may repeat the server's route, compared as a canonical origin and base
path, but never replace it. A discovered profile never carries a route or a
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 @@ -38,7 +38,7 @@ Four rules decide what counts, and each of them changed a number:
frames a subagent produced, and the chat adapter keeps those off the surface.
- **The turn budget is enforced, not just advertised.** Production aborts a
turn at `turnTimeoutMs` (`timeoutHandle = setTimeout`,
`packages/ui-server/src/ws/run-session.ts:388`), so
`packages/ui-server/src/ws/session-run/admission.ts:47`), so
the harness aborts at the same 180 s. Without it an answer no reader could
have received still scored: an earlier run had five turns of 190–306 s.
- **A turn that did not complete is excluded from every rate**, in both
Expand Down
Loading
Loading