questionbridge

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 6 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 questionbridge recognises claude's clarifying-question tool call, parses its batch into the outbound wire payload, and records the surfaced batch under a one-time nonce it mints (Registry). It is named after its two neighbours, internal/permbridge and internal/modalbridge, and sits beside them rather than inside internal/protocol, which enforces no bound by design, or inside modalbridge, whose whole argument (TypeQuestionShown's doc block) is that a question is a distinct frame family rather than a grown modal.

The input is a tool name and the opaque tool input claude blocks on across the mcp-approve bridge — permbridge.Request's ToolName and Input. The parse takes the PAIR rather than the Request, so it never holds a ToolUseID it has no business reading and depends on internal/protocol and the standard library alone.

FAIL-CLOSED, AND REJECT RATHER THAN TRUNCATE. The result becomes a control frame, and control frames are never dropped by the push queue (soft-overflow admit), so an un-droppable frame must not be inflatable — modalbridge's maxPromptBytes posture. Its MECHANISM does not carry over: boundPrompt silently truncates, and this family has no truncated_fields to report a cut in, so a cut would present claude's clipped text to a client as complete. docs/protocol-mobile.md's Question (v2) section forbids exactly that. The cap is therefore taken once, over the whole raw input, and rejects it whole.

Fail-closed means BOUNDS, NOT UNKNOWN KEYS. The decode is a plain json.Unmarshal: a claude release adding a field — the vendor docs already describe an optional per-option preview, emitted only when toolConfig.askUserQuestion's previewFormat is set, which pyry never sets — must not turn every question into a dropped frame.

LOG-FREE, deliberately and structurally: this package does not import log/slog, so no question text, header, option label or description, and no other byte of claude's tool input, can reach a log from here. permbridge carries the same property for the same reason. Content-free decision logging belongs at the call site, where a conversation id is in hand.

NOTHING CALLS THIS YET. #1973 is the consumer: it wires the discriminant into the stream approval surfacer, then hands the parsed batch and its conversation id to Registry.Record, which mints QuestionBatchID from crypto/rand and stamps both ids on. Parse leaves the pair deliberately zero because they are daemon-asserted and never come from claude's tool input.

Index

Constants

View Source
const ToolName = "AskUserQuestion"

ToolName is claude's clarifying-question tool, and the discriminant that tells this call apart from a permission prompt on the shared approval bridge. The name is the agent SDK's; the committed capture at internal/e2e/realclaude/testdata/ask_user_question_v2.1.239.json is the authority on what claude actually sends, and agrees.

Variables

This section is empty.

Functions

func Parse

func Parse(toolName string, input json.RawMessage) (protocol.QuestionShownPayload, bool)

Parse reports whether toolName is claude's question tool AND input is a well-formed, in-bounds batch, returning that batch as the outbound payload with its questions and their options in claude's own array order — which is the canonical display order.

Every rejection yields the ZERO payload and false, never a partial or a truncated one: nothing is built until every check has passed.

The two negative outcomes — not the question tool, and the question tool rejected — are deliberately NOT distinguished. A caller that needs to tell them apart compares against ToolName itself, which is exported for exactly that; minting an error or a sentinel here would be API nothing consumes.

ConversationID and QuestionBatchID are left unset: both are daemon-asserted, and a parse that filled either would be asserting daemon state out of claude's tool input.

Types

type Registry

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

Registry is the in-memory store of surfaced-but-unretired question batches, keyed by question_batch_id. It is the seam three tickets share without any of them owning it: the producer (#1973) records and broadcasts, the answer path (#1907) resolves an inbound answer against the daemon's own parked copy rather than a client echo, and the connect-time reconcile (#1928) reads current truth while minting and retiring nothing.

It carries a sync.Mutex because two real goroutines touch it — the surfacer that records and the relay dispatch that looks up and resolves — so it is NOT confined to one goroutine by convention. The mutex is a leaf lock: held only around O(1) map ops and the clone, never nested with any other lock.

THERE IS NO SEPARATE STORED-ENTRY TYPE, which is the one place modalbridge.Registry is deliberately not mirrored. That package needs one because its entry and its wire payload genuinely differ (its payload is assembled from a rendered prompt and a fail-safe default); here the parked thing IS the stamped payload, so a second type would buy a field-by-field copy in and a field-by-field rebuild out and nothing else.

func New

func New() *Registry

New returns an empty Registry ready for use.

func (*Registry) Lookup

func (r *Registry) Lookup(batchID string) (protocol.QuestionShownPayload, bool)

Lookup returns the outstanding batch for batchID without retiring it, so the one-shot consume stays Resolve's alone. The returned batch is cloned.

func (*Registry) Record

Record is the single nonce mint site. It mints one fresh question_batch_id, stamps it and convID onto p, parks the batch under that id, and returns the stamped payload — the frame the producer broadcasts.

BOTH IDS ARE ASSERTED, NEVER ADOPTED. p arrives from Parse, which fills neither because both are daemon-owned, but an id that did arrive on p is overwritten rather than trusted: p's ultimate source is claude's tool call, and a batch parked under a caller-supplied id would be resolvable by whoever supplied it. The mint and the write happen in the same call, so a parked batch is never Snapshot-able without its scope key.

The only error path is RNG failure: nothing is stored and the zero payload comes back, so the caller drops the batch rather than broadcasting an id-less one. That branch mirrors modalbridge.Registry.Record's and is untested for its reason — crypto/rand.Read does not fail on a supported platform, and an injectable RNG seam would be API nothing consumes.

Clone-on-write: the parked copy owns its own questions and options, so what this returns — the caller's own slice, stamped — shares no backing storage with it at either nesting level.

func (*Registry) Resolve

func (r *Registry) Resolve(batchID string) (protocol.QuestionShownPayload, bool)

Resolve returns the batch for batchID and retires it — the one-shot consumption that makes "exactly one broadcaster" structural rather than an agreement between the answer path (#1907) and the retire backstop (#1973): whichever calls Resolve first gets the batch, and every later call reports absent. A retired batch resolves nothing (docs/protocol-mobile.md § question_dismissed's question_batch_id row).

The read and the delete are one critical section, which is what makes the guarantee hold under concurrent callers.

It does NOT clone, unlike Lookup and Snapshot, and the asymmetry is the point: the entry is gone by the time this returns, so there is no kept copy left for a mutating consumer to reach.

func (*Registry) Snapshot

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

Snapshot returns every currently-outstanding batch, each re-emitting the nonce and conversation id Record stamped on it. It is the current-truth read #1928's connect-time reconcile consumes, so a reconnecting client is scoped exactly as the initial broadcast was.

Pure read: it mints nothing, retires nothing, and mutates no registry state — an outstanding batch stays Lookup-able and Resolve-able after a call. Each batch is cloned. Map-walk order is unspecified; callers reconcile by question_batch_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