Skip to content

backends: the bridge-tool availability refusal for voice and no-grant-surface turns is implemented twice #2490

Open

Description

@schlessera

Context

Before any remembered grant or permission card, each backend decides whether a bridge tool is available in the current turn at all. On a voice or no-grant-surface turn this refusal is what keeps visual and interactive tools from running (docs/decisions/voice-permission.md). The logic is written twice:

  • Claude: toolAvailabilityRefusal, packages/ui-backend-claude/src/tool-availability.ts:3-27. Called from packages/ui-backend-claude/src/permission-hooks.ts:202, :283, :378 and from the tool roster in packages/ui-backend-claude/src/sdk-options.ts:265.
  • Pi: piToolAvailabilityRefusal, packages/ui-backend-pi/src/permission-gate.ts:59-74. Called from the production worker admission decidePiToolPermission (packages/ui-backend-pi/src/permission-gate.ts:133, used by packages/ui-backend-pi/src/worker-session.ts:19), the in-process gate (:104) and the prompt context (packages/ui-backend-pi/src/session-pool.ts:51).

Both copies hold the same "visual" set, the same "interactive" set, the same tool → bridge-handler table and the same refusal strings. git grep -n "typed grant surface" -- packages finds exactly these two sources. They are already maintained separately: the tables are ordered differently, and Claude's handler table also maps the six application tools to applyBrain (tool-availability.ts:9-10) where pi's does not. That difference may be intended, because pi without applyBrain falls back to its own writers (packages/ui-backend-pi/src/tools.ts:600). Today, though, nothing records it. A new interactive bridge tool added to one table and not the other would run on voice or no-grant-surface turns of one backend only.

Under the #1345 ruling (docs/decisions/backend-authoring-toolkit.md:10-22), logic both shipped backends need for the same security posture belongs in the public backend toolkit, @schlessera/brain-ui-sdk/server.

Scope

  • Add bridgeToolAvailabilityRefusal(turn, sharedToolName) to @schlessera/brain-ui-sdk/server (@experimental), together with the shared visual/interactive sets and the shared bridge-handler table. Input is the turn facts both backends have: autonomous, noGrantSurface, posture, bridge.
  • Make both backends call it. Each keeps only its own extras next to the call: Claude's native Write/Edit/NotebookEdit rule and its application-tool → applyBrain entries.
  • Write in the toolkit decision record why the application-tool entries are backend-specific.
  • Add the new export to api-report/ui-sdk.txt and the contract.

Out of scope

  • Changing which tools are refused on which posture.
  • The application tool-name and policy duplication (filed separately from the same review).
  • Other permission-gate logic (command policy, outward plans, confirm patterns).
  • The pi in-process test-only gate.

Acceptance criteria

  • git grep -n "typed grant surface" -- packages ':!**/CHANGELOG.md' returns a single source file, in packages/ui-sdk/src/server/.
  • A ui-sdk unit test covers every shared visual and interactive tool on voice, no-grant-surface, autonomous and ordinary turns, and a tool whose bridge handler is missing.
  • The existing Claude and pi availability tests pass unchanged. One extra test per backend shows that a tool added only to the shared interactive set is refused on a voice turn by that backend, and a mutation that removes the shared call is recorded failing it.
  • api-report/ui-sdk.txt and the backend toolkit decision record list the new export.

Verification

bun run test packages/ui-sdk packages/ui-backend-claude packages/ui-backend-pi
bun run api-report
bun run typecheck

Contract impact

Additive @experimental export on @schlessera/brain-ui-sdk/server: CONTRACT: commit, with the API report and contract updated. No wire or behaviour change.

Found by a repository review on 2026-10-22.

Activity

  1. added
    type: refactor
    area: ui-sdk
    area: backends
    priority: p2
    agent-ready
    contract
    security
    on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: backendsarea: ui-sdkcontractpriority: p2securitytype: refactor

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions