Documentation
¶
Overview ¶
Package agent is the serial coordinator for autonomous TUI agent requests and the presentation of their transcripts. Each request owns the provider/model selected when it was submitted, but at most one adapter is ever running. The queue records transcripts and outcomes for presentation; it never reads or writes task data itself.
Go port of Ruby's lib/tui/agent_queue.rb and lib/tui/agent_activity.rb. Unlike Ruby's single-threaded original, every operation takes a mutex, so the FIFO order Marcus relies on holds even when submissions arrive from a background reader.
Index ¶
- Constants
- Variables
- type Adapter
- type Content
- type Entry
- type Event
- type EventType
- type Options
- type ProcessStatus
- type Queue
- func (q *Queue) Active() bool
- func (q *Queue) ActiveOutput() string
- func (q *Queue) ActiveRequest() (Snapshot, bool)
- func (q *Queue) Any() bool
- func (q *Queue) CancelActive() Event
- func (q *Queue) CancelPending() []Snapshot
- func (q *Queue) Enqueue(prompt string, entry Entry) Submission
- func (q *Queue) LatestFinished() (Snapshot, bool)
- func (q *Queue) Now() float64
- func (q *Queue) Pending() bool
- func (q *Queue) PendingCount() int
- func (q *Queue) Pump() Event
- func (q *Queue) Requests() []Snapshot
- func (q *Queue) Shutdown() []Snapshot
- func (q *Queue) StartNext() Event
- func (q *Queue) SubmittedCount() int
- func (q *Queue) Work() bool
- type SimpleEntry
- type Snapshot
- type Status
- type Submission
Constants ¶
const ( // MaxPending is how many requests may wait behind the running one. MaxPending = 100 // HistoryLimit is how many finished requests are retained. HistoryLimit = 50 )
Variables ¶
var Glyphs = map[Status]string{
Queued: "○",
Running: "⠸",
Succeeded: "✓",
Failed: "✗",
Cancelled: "–",
}
Glyphs is the status marker shown against each request.
var Slots = map[Status]theme.Slot{
Queued: "muted",
Running: "accent",
Succeeded: "accent",
Failed: "error",
Cancelled: "warning",
}
Slots is the theme slot each status paints with.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter interface {
// Available re-checks the provider at start time.
Available() bool
Start(prompt, model string) error
// Pump drains one readable chunk; done reports that the process finished.
Pump() (done bool, err error)
Cancel() error
Output() string
Success() bool
// ExitStatus reports the process exit code, if one is known.
ExitStatus() (int, bool)
ProcessStatus() ProcessStatus
}
Adapter is one live agent process. Only one is ever running per queue.
type Content ¶
Content is the rendered agent-activity modal body. FilterGroups is parallel to Lines and names the request each line belongs to, so filtering a line keeps its whole request block together.
type Entry ¶
type Entry interface {
Provider() string
Model() string
// UILabel is the short "provider:model" form the activity view shows.
UILabel() string
}
Entry names the provider/model a request was submitted with. The LLM layer supplies the real implementation; the queue only reads it.
type Options ¶
type Options struct {
// Factory builds a fresh adapter for an entry, with the current system
// context, only when a request actually starts.
Factory func(Entry) (Adapter, error)
// Availability is a lightweight probe run at enqueue so an unavailable
// provider is rejected immediately without building the (context-bearing,
// possibly failing) adapter. A nil probe means "assume available";
// StartNext's re-check is the backstop either way.
Availability func(Entry) bool
// Clock returns monotonic seconds. Defaults to process-monotonic time.
Clock func() float64
MaxPending int
HistoryLimit int
}
Options configures a queue.
type ProcessStatus ¶
type ProcessStatus struct {
// Present is false when the adapter never produced a process status.
Present bool
Exited bool
ExitStatus int
Signaled bool
Signal int
}
ProcessStatus describes how an adapter's process ended.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is the serial request coordinator.
func (*Queue) ActiveOutput ¶
ActiveOutput is the live transcript of the running request.
func (*Queue) ActiveRequest ¶
ActiveRequest snapshots the running request, if any.
func (*Queue) CancelActive ¶
CancelActive stops the running request, preserving its partial output.
func (*Queue) CancelPending ¶
CancelPending discards everything waiting without touching the live adapter.
func (*Queue) Enqueue ¶
func (q *Queue) Enqueue(prompt string, entry Entry) Submission
Enqueue submits a prompt. A full queue or an unavailable provider is a rejection, and no request is recorded.
func (*Queue) LatestFinished ¶
LatestFinished is the most recently completed request.
func (*Queue) Now ¶
Now samples the queue's own monotonic clock. Activity rendering must use the same clock domain as queuedAt/startedAt.
func (*Queue) PendingCount ¶
func (*Queue) Pump ¶
Pump drains one readable chunk. A finished adapter is recorded, but the next request is deliberately not started here: the application first reloads task state, then advances the queue, to preserve a visible checkpoint between runs.
func (*Queue) Shutdown ¶
Shutdown is the exit path: stop everything without advancing to another request.
func (*Queue) StartNext ¶
StartNext attempts exactly one queued request. A start-time availability/spawn failure is a finished event so the caller can report it and call again; a successful start returns Started and owns the single live adapter.
func (*Queue) SubmittedCount ¶
SubmittedCount is how many requests have ever been accepted.
type SimpleEntry ¶
SimpleEntry is a provider/model pair with no label mapping — enough for callers and tests that do not need the LLM registry's display names.
func (SimpleEntry) Model ¶
func (e SimpleEntry) Model() string
func (SimpleEntry) Provider ¶
func (e SimpleEntry) Provider() string
func (SimpleEntry) UILabel ¶
func (e SimpleEntry) UILabel() string
type Snapshot ¶
type Snapshot struct {
ID int
Prompt string
Entry Entry
Status Status
QueuedAt float64
StartedAt *float64
FinishedAt *float64
Output string
ExitStatus *int
Error string
}
Snapshot is an immutable view of one request.
type Submission ¶
Submission is the outcome of an enqueue attempt.
func (Submission) Accepted ¶
func (s Submission) Accepted() bool
Accepted reports whether the request joined the queue.