questionbridge

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 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 parses clarifying-question tool calls into bounded outbound payloads and records surfaced batches under daemon-minted identities. Parse takes a tool name and input rather than an approval request, so it holds no approval correlation and depends only on protocol and the standard library.

Batches are rejected whole rather than truncated: this control-frame family has no truncated_fields marker, so clipped text would appear complete. Raw input is bounded before decode; encoded payloads reserve space for the full envelope and daemon metadata. Unknown input keys remain tolerated.

The package is log-free. Question content stays inert text, and Parse leaves both daemon-asserted IDs unset for Registry.Record to assign.

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: the batch is accepted or rejected as a whole.

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