Documentation
¶
Overview ¶
bridge.go carries the control-plane delivery policy every UI surface and the ACP server share: how long a prompt may take to be accepted, how long the user may take to answer it, and what happens when either bound is hit.
The transport is the one part that genuinely differs per surface — the TUI pushes onto a channel drained by the tview loop, the web UI serializes to SSE, ACP speaks JSON-RPC — so it is the one part a surface implements (Surface). Question and approval handling then live here once instead of being re-derived, with divergent timeouts, on each surface.
Package control defines the control-plane message types sent from tool handlers and session infrastructure to a UI consumer (TUI, REPL, web, ACP). These are distinct from the provider wire-format types in internal/types — they carry UI-level concerns (questions, approvals, status updates, todo lists, context info) rather than LLM request/response shapes.
Extracting these from internal/types breaks the types → todo dependency, allowing the provider wire-format package to remain dependency-free.
bridge.go, question.go and approval.go carry the delivery policy those consumers share — how long a prompt may take to be accepted, how long the user may take to answer it, and what a surface that cannot ask falls back to — so the TUI, the web UI and ACP cannot each re-derive (and drift from) it.
Index ¶
- Constants
- func Approve(ctx context.Context, s Surface, callID, name, args string) bool
- func ApproveWithin(ctx context.Context, s Surface, timeout time.Duration, ...) bool
- func AskEach(entries []tools.QuestionEntry, askEntry AskFunc, ...) []string
- func AskQuestions(ctx context.Context, s Surface, entries []tools.QuestionEntry) []string
- func FirstOptionAnswer(e tools.QuestionEntry) string
- func FormatAnswer(header, answer string) string
- type Approval
- type AskFunc
- type CompactionSummary
- type ContextInfo
- type Continue
- type Done
- type Error
- type Fallback
- type ModelList
- type Msg
- type Option
- type Question
- type Status
- type Surface
- type Todos
- type Usage
- type UsageInfo
Constants ¶
const ( // SendTimeout bounds how long a tool goroutine waits for a surface to // accept one control-plane prompt. It keeps a stalled or detached // consumer from parking the tool goroutine that is running the turn. SendTimeout = 30 * time.Second // AnswerTimeout bounds how long a tool goroutine waits for the user to // answer a question or decide a tool approval. It is the single decision // timeout in the program: questions and approvals on the TUI and web // surfaces, and the default of ACP's session/request_permission and // elicitation/create waits. AnswerTimeout = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func Approve ¶ added in v0.129.5
Approve asks the surface to allow one tool call and waits AnswerTimeout for the decision, which is the same bound the surfaces give a question. It returns as soon as ctx is cancelled, so an aborted run does not leave the tool goroutine parked on a prompt nobody is going to answer.
Every failure — a prompt that cannot be delivered, a surface that goes away, a run that is abandoned, a decision that never arrives — denies. Denying is the safe direction for a call that may mutate the workspace, and it keeps the turn moving instead of parking it on a surface nobody is answering.
callID is the provider's tool_call id when the loop has one (empty for asks that carry no call, such as an out-of-workspace path decision); it travels with the prompt so a surface can correlate the decision with the tool row it belongs to.
func ApproveWithin ¶ added in v0.129.5
func ApproveWithin(ctx context.Context, s Surface, timeout time.Duration, callID, name, args string) bool
ApproveWithin is Approve with an explicit decision timeout. Production surfaces use Approve and therefore AnswerTimeout; the parameter exists so a test can exercise the timeout branch without waiting minutes for it.
func AskEach ¶ added in v0.129.5
func AskEach( entries []tools.QuestionEntry, askEntry AskFunc, fallback func(tools.QuestionEntry) string, ) []string
AskEach drives one question-tool call for any surface: every entry goes to askEntry, a decision is rendered with FormatAnswer, and an entry that could not be presented gets fallback's answer. It always returns one answer per entry, so a shorter result can only come from a caller whose input ended.
func AskQuestions ¶ added in v0.129.5
AskQuestions is the shared question-tool handler for the control-plane surfaces (TUI, web): each entry is sent to the surface and the answer is waited for under the shared timeout policy. An entry the surface cannot present, one the user does not answer in time, and one whose run is abandoned mid-ask fall back to the first option instead of blocking the turn.
func FirstOptionAnswer ¶ added in v0.129.5
func FirstOptionAnswer(e tools.QuestionEntry) string
FirstOptionAnswer is the fallback for an entry that could not be put to the user: the first declared option, or an empty answer when the entry offers none. Answering beats blocking the turn on a surface that is gone.
func FormatAnswer ¶ added in v0.129.5
FormatAnswer renders one answered entry for the tool result.
Types ¶
type Approval ¶
type Approval struct {
// CallID is the provider's tool_call id for the call awaiting a decision,
// so a surface can correlate the prompt with the tool row it belongs to.
// Empty when the ask carries no call (an out-of-workspace path decision).
CallID string
Name string
Args string
ApproveCh chan<- bool
}
Approval carries a tool approval prompt.
type AskFunc ¶ added in v0.129.5
type AskFunc func(e tools.QuestionEntry) (answer string, answered bool)
AskFunc answers one question-tool entry. answered is false when the surface could not put the entry to the user at all, which is when the caller's fallback supplies the answer instead.
type CompactionSummary ¶ added in v0.106.0
type CompactionSummary struct {
Summary string
Method string // "single", "chunked", or "trim"
Before int
After int
Window int
}
CompactionSummary carries the summary a completed compaction produced so surfaces can render it in the conversation stream (yaah-v378.5). It is render-only: the summary already lives in the system message, so it must never be persisted as a chat message. Summary is empty when every summarizer attempt failed and the pass fell back to trimming.
func (*CompactionSummary) Header ¶ added in v0.106.0
func (m *CompactionSummary) Header() string
Header renders the one-line outcome shared by every surface: which path ran and how the token count moved. Surfaces append the summary (or their own no-summary notice) after it.
type ContextInfo ¶
type ContextInfo struct {
Tokens int
Window int
LastPromptTokens int // provider-shaped prompt tokens (last turn)
LastPromptTokensInclusive int // cache-inclusive provider prompt size (last turn)
}
ContextInfo carries context window usage statistics.
type Continue ¶
Continue asks the host to prompt whether to continue after reaching the maximum number of agent iterations. Write true (continue) or false (stop) to AnswerCh.
type Done ¶
type Done struct{}
Done is a sentinel sent once when the session closes. The goroutine forwarding from controlCh to prog.Send must detect this type and return to avoid a leaked goroutine after the TUI exits.
type Fallback ¶
Fallback is sent when the LLM client falls back to an alternative provider. The TUI should update its header to reflect the new provider.
type Msg ¶
type Msg interface {
// contains filtered or unexported methods
}
Msg is the sealed interface for control-plane messages sent from tool handlers and session infrastructure to a UI consumer (TUI, REPL, etc.). Each concrete type implements marker().
type Question ¶
type Question struct {
Header string
Question string
Options []Option
Multiple bool
AnswerCh chan<- string
}
Question carries an interactive question to display.
func NewQuestion ¶ added in v0.129.5
func NewQuestion(e tools.QuestionEntry, ch chan<- string) *Question
NewQuestion maps one question-tool entry onto the control-plane message a surface renders, wiring the channel the answer is returned on.
type Surface ¶ added in v0.129.5
type Surface interface {
// Send hands one prompt to the surface, waiting at most SendTimeout for
// it to be accepted, and reports whether the user will ever see it.
// False means the prompt could not be delivered — no consumer attached,
// the surface stalled, or it went away — and the caller supplies its
// fallback rather than waiting for an answer that cannot arrive.
//
// The returned channel is closed when an answer to *this* prompt can no
// longer arrive: the lane that accepted it was torn down, the run behind
// it was abandoned, the UI exited. A nil channel means the prompt stays
// answerable for the surface's lifetime, which is the TUI's case — its
// channel is consumed until the process ends.
//
// The channel is bound at delivery time on purpose. A surface whose lane
// can be replaced (the web's SSE stream) must report the lane it actually
// used, not re-read current state when the caller starts waiting: by then
// a successor lane may own the surface, and waiting on the successor's
// channel parks the caller for the full answer timeout on a prompt that
// was already orphaned.
Send(msg Msg) (gone <-chan struct{}, ok bool)
}
Surface is the transport half of the bridge: the part each UI supplies.
Implementations are called from tool goroutines (the agent runs tools concurrently) and must not block for longer than SendTimeout.
type Usage ¶ added in v0.130.0
Usage is a token-count snapshot for one side of the usage split. It is a local type so the control protocol stays independent of the provider wire-format types in internal/types (see the package doc).
type UsageInfo ¶ added in v0.130.0
UsageInfo carries the session-cumulative usage split so a view can render orchestrator and sub-agent spend separately. Agent is the orchestrator's own spend (the session total minus the sub-agent share); Sub is the sub-agent share (foreground and background dispatches), already folded into the session totals.