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 {
ModalID string
Class string
Title string
Prompt string
Options []protocol.ModalOption
DefaultOptionID string
}
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).
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 (*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 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 it onto the payload, records the Outstanding under that id, and returns the id-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.
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.