modalbridge

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package modalbridge turns a detected tui-driver permission/trust modal into a typed, phone-facing protocol.ModalShownPayload and records it in an outstanding-modal registry keyed by a one-time modal_id nonce. The registry is the seam #717's inbound resolution half consumes to map an inbound option_id back to a surfaced modal and to reject stale/replayed answers.

It is relay-free by construction. #717 intercepts modal_answer inside internal/relay and looks the nonce up here, so internal/relay imports this package — therefore this package MUST NOT import internal/relay (it would cycle). It imports only internal/protocol, internal/turnevent, and pkg/tuidriver (the typed ModalClass API only — never a raw-byte surface), so no claude-screen substrate literal enters this package and cmd/substrate-guard stays green; screenText arrives already rendered to plain text by the caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PermissionRequestForClass

func PermissionRequestForClass(class tuidriver.ModalClass, screenText string) (turnevent.PermissionRequest, string, bool)

PermissionRequestForClass maps a detected modal class to the internal PermissionRequest the producer surfaces (AC1's "build an internal PermissionRequest"), the wire class string, and ok. ok is false for every class that is not permission/trust (AC1: those produce no modal_shown).

This is the minimal fixed-option-set mapping (design option (a)): claude's permission options align with the four PermissionOptionKinds; trust maps to proceed/exit. Options are in claude's display order (allow-first). The rendered modal body (screenText, trimmed) becomes PermissionRequest.Title ("human-readable prompt text"); RequestID/ToolCallID stay empty — the modal_id minted in Record is the sole wire correlation key.

Types

type Outstanding

type Outstanding struct {
	ConversationID  string
	ModalID         string
	Class           string
	Title           string
	Prompt          string
	Options         []protocol.ModalOption
	DefaultOptionID string
	Reason          json.RawMessage
	ReasonType      string
	BlockedPath     string
	Description     string
	DefaultToNo     bool
	AlwaysAllow     permbridge.AlwaysAllow
}

Outstanding is one recorded surfaced modal. It holds at least the option list so #717 can map an inbound option_id against it; it carries no secret (the modal_id is an opaque correlation nonce, not a credential).

ConversationID is the outbound scoping key (#1065): stored alongside the rest of the entry so Snapshot re-emits it, scoping a reconnect reconcile replay identically to the initial broadcast.

type PermissionContext added in v0.16.0

type PermissionContext struct {
	Reason      json.RawMessage
	ReasonType  string
	BlockedPath string
	Description string
	DefaultToNo bool
	AlwaysAllow permbridge.AlwaysAllow
}

PermissionContext is optional Claude-authored display context attached to a permission modal. Each field is passed through independently; none is derived from the tool input or used to decide the permission verdict.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is the in-memory outstanding-modal store, keyed by modal_id. It is the one piece touched by two real goroutines — the surfacer goroutine (Record) and, in #717, the relay dispatch goroutine (Lookup/Resolve) — so it carries a sync.Mutex; it is NOT confined to one goroutine by convention. The mutex is a leaf lock: held only around O(1) map ops, never nested with any other lock.

func New

func New() *Registry

New returns an empty Registry ready for use.

func (*Registry) Lookup

func (r *Registry) Lookup(modalID string) (Outstanding, bool)

Lookup returns the Outstanding for modalID without removing it. It is #717's read seam (defined now, exercised by #717).

func (*Registry) Record

func (r *Registry) Record(req turnevent.PermissionRequest, wireClass, convID string) (protocol.ModalShownPayload, error)

Record is the single nonce mint site (AC2). It builds the marshal-ready ModalShownPayload from req + wireClass, mints exactly one fresh modal_id, stamps the routing keys (modal_id and the #1065 conversation_id scoping key) onto the payload, records the Outstanding under that id, and returns the stamped payload. The only error path is RNG failure (the caller drops the modal — never push an id-less payload). The payload build and the registry write are the one place a final payload is produced, honouring single-writer- nonce; the conversation_id is written into the Outstanding in the SAME critical section, so there is no window where a stored modal is Snapshot-able without its scope key.

func (*Registry) RecordWithContext added in v0.16.0

func (r *Registry) RecordWithContext(req turnevent.PermissionRequest, wireClass, convID string, context PermissionContext) (protocol.ModalShownPayload, error)

RecordWithContext records a modal with optional Claude-authored permission context. Record remains the zero-context path for existing modal producers.

func (*Registry) Resolve

func (r *Registry) Resolve(modalID string) (Outstanding, bool)

Resolve returns the Outstanding for modalID and removes it — the one-shot consumption #717 uses to answer-and-retire a modal. Defined now; #716 only needs Record/Lookup, but it belongs with the type's contract.

func (*Registry) Snapshot added in v0.16.0

func (r *Registry) Snapshot() []protocol.ModalShownPayload

Snapshot returns a marshal-ready ModalShownPayload for every currently- outstanding modal, each stamped with its original modal_id. It is the current-truth read seam #877's connect-time producer consumes to reconcile a reconnecting client to the daemon's live control state.

Pure read: it mints no id (newModalID is never touched), retires nothing, and mutates no registry state — a still-pending modal remains Lookup/Resolve-able after a call. Each payload's Options is cloned so a mutating consumer cannot corrupt the stored Outstanding (mirroring Record's clone-on-write). Map-walk order is unspecified; callers reconcile by modal_id, never by position. An empty registry yields a non-nil, zero-length slice.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL