ui

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 28 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 ui is the human terminal UI (`smif ui`): a Bubble Tea program that polls the daemon socket with the human token and draws the overview. It is a client of the human-only RPC methods; it adds no path through which an agent could read inbound mail (RFC D4).

Index

Constants

View Source
const DigestLimit = 500

DigestLimit is how many unread items per agent the digest screen loads.

View Source
const EventKeep = 200

EventKeep is how many audit events the overview keeps for the EVENTS panel.

View Source
const InboxLimit = 200

InboxLimit is how many messages the inbox screen loads.

View Source
const TranscriptTailBytes = 256 << 10

TranscriptTailBytes caps how much of a transcript the run screen reads.

Variables

View Source
var MessageStates = []string{"accepted", "queued", "running", "retry_wait", "needs_human", "done", "rejected", "expired", "dead_letter"}

MessageStates are the message states in lifecycle order (store.AllStates).

Functions

func EventDetail

func EventDetail(ev api.AuditEvent) string

EventDetail is the detail of an event in short form: the state change first for message.transition, then key=value pairs in key order. Each value is on one line and at most 80 characters.

func FormatEvent

func FormatEvent(ev api.AuditEvent) string

FormatEvent is one audit event on one line, as `smif watch --events` prints it:

13:10:05 #42 message.transition cafe msg 0000000001 queued→running

func NoColor

func NoColor(getenv func(string) string) bool

NoColor reports whether the NO_COLOR variable asks for no colours: it is set and not empty (https://no-color.org).

func RenderDiff

func RenderDiff(diff string, w int) []string

RenderDiff colours a unified diff: file headers bold, + green, - red, hunk headers cyan. Lines are cut, not wrapped, at w cells.

func RenderTranscript

func RenderTranscript(data []byte, w int) []string

RenderTranscript turns stream-JSON lines into readable lines of at most w cells: the init event, assistant text, tool uses with their main argument, tool results (first line), and the final result with turns, cost and tokens. A line that is not JSON shows as it is, dimmed.

func SetupColor

func SetupColor(getenv func(string) string) bool

SetupColor prepares the styles before `smif ui` starts. With NO_COLOR the styles keep only text attributes (bold, faint, underline, reverse). Bubble Tea v2 downsamples what is left to the terminal's own profile, so a terminal without styles (TERM=dumb) gets plain text. It reports whether colours are off.

func Short

func Short(id string) string

Short is the last 10 characters of an id, as the CLI prints it.

func WatchSummary

func WatchSummary(s Snapshot, now time.Time, interval time.Duration, events int) string

WatchSummary is the compact plain-text summary `smif watch` prints every interval: one header line, the agents table, then one line per running run, needs-you item, dead letter and each of the last events (newest last). It has no colours and no cursor movement, so it works in a pipe, a tmux pane or over ssh.

Types

type Actions

type Actions interface {
	// Thread is thread.get for a message or thread id.
	Thread(ctx context.Context, id string) (*api.ThreadView, error)
	// Reply is message.reply on a needs_human item.
	Reply(ctx context.Context, messageID, text string) (*api.SendResult, error)
	// Cancel is message.cancel. The result holds the state after the
	// call: rejected at once, or cancelling while a worker stops.
	Cancel(ctx context.Context, messageID string) (*api.CancelResult, error)
	// Retry is message.retry on a dead letter.
	Retry(ctx context.Context, messageID string) error
}

Actions are the human-only writes and the thread read the item screens use. DaemonSource implements them; a Source without them gives a read-only UI.

type ApplyResult

type ApplyResult struct {
	RunID  string `json:"run_id"`
	Branch string `json:"branch"`
	Repo   string `json:"repo"`
	Head   string `json:"head"`
}

ApplyResult is the run.apply result.

type Caller

type Caller interface {
	Call(method string, params, out any, timeout time.Duration) error
	Close() error
}

Caller is the part of *api.Client the daemon source needs.

type DaemonSource

type DaemonSource struct {
	// Dial opens a connection with the human token.
	Dial func() (Caller, error)
	// Timeout caps each call (default 3 s).
	Timeout time.Duration
	// RecentLimit is how many recent messages to load (default 20).
	RecentLimit int
	// Now is the clock (default time.Now).
	Now func() time.Time
	// contains filtered or unexported fields
}

DaemonSource polls the daemon over one connection and redials after an error, so the UI survives a daemon restart.

func (*DaemonSource) Apply

func (s *DaemonSource) Apply(ctx context.Context, runID string) (*ApplyResult, error)

Apply merges the worker branch (run.apply). The daemon refuses on a dirty tree. The call gets 60 s, like `smif apply`.

func (*DaemonSource) Cancel

func (s *DaemonSource) Cancel(ctx context.Context, messageID string) (*api.CancelResult, error)

Cancel cancels a queued, waiting, needs_human or running item.

func (*DaemonSource) Close

func (s *DaemonSource) Close()

Close drops the connection.

func (*DaemonSource) Diff

func (s *DaemonSource) Diff(ctx context.Context, runID string) (*DiffView, error)

Diff reads the worker branch diff (run.diff). git can take a while on a big repo, so the call gets 30 s.

func (*DaemonSource) Digest

Digest reads the digest (digest.get). With p.Advance it marks the items read: it moves each agent's read cursor.

func (*DaemonSource) EventCursor

func (s *DaemonSource) EventCursor() int64

EventCursor is the seq of the newest event PollEvents returned.

func (*DaemonSource) Fetch

func (s *DaemonSource) Fetch(ctx context.Context) Snapshot

Fetch reads agent.status and three thread.list views. A transport error on a reused connection (the daemon restarted) gets one fresh dial before Fetch reports the daemon down.

func (*DaemonSource) FocusSession

func (s *DaemonSource) FocusSession(ctx context.Context, sessionID string) error

FocusSession brings the session's Terminal tab to the front.

func (*DaemonSource) Messages

func (s *DaemonSource) Messages(ctx context.Context, p api.ListParams) ([]api.MessageView, error)

Messages lists messages (thread.list).

func (*DaemonSource) NewSession

func (s *DaemonSource) NewSession(ctx context.Context, dir, name, term string) error

NewSession opens a new terminal tab that runs claude in dir.

func (*DaemonSource) PollEvents

func (s *DaemonSource) PollEvents(ctx context.Context, backlog int) ([]api.AuditEvent, bool, error)

PollEvents is EventFeed.Poll on the source's connection, for `smif watch --events`. It shares the feed with Fetch, so use one or the other.

func (*DaemonSource) Prompt

func (s *DaemonSource) Prompt(ctx context.Context, sessionID, text string) (*api.SessionPromptResult, error)

Prompt types text into an idle session and presses Enter.

func (*DaemonSource) Reply

func (s *DaemonSource) Reply(ctx context.Context, messageID, text string) (*api.SendResult, error)

Reply answers a needs_human item (message.reply).

func (*DaemonSource) Retry

func (s *DaemonSource) Retry(ctx context.Context, messageID string) error

Retry requeues a dead letter.

func (*DaemonSource) Run

func (s *DaemonSource) Run(ctx context.Context, id string) (*api.RunView, error)

Run reads one run record (run.get).

func (*DaemonSource) Send

func (s *DaemonSource) Send(ctx context.Context, method string, d envelope.Draft) (*api.SendResult, error)

Send sends an ask or a tell as the human (the `:` prompt).

func (*DaemonSource) SendSession

func (s *DaemonSource) SendSession(ctx context.Context, sessionID, text string) (*api.SessionSendResult, error)

Send writes text to a session.

func (*DaemonSource) SessionTail

func (s *DaemonSource) SessionTail(ctx context.Context, sessionID string) (*api.SessionTail, error)

SessionTail reads the last turns of one session.

func (*DaemonSource) Thread

func (s *DaemonSource) Thread(ctx context.Context, id string) (*api.ThreadView, error)

Thread reads one thread with bodies (thread.get).

func (*DaemonSource) Transcript

func (s *DaemonSource) Transcript(ctx context.Context, r api.RunView) (*TranscriptTail, error)

Transcript reads the last TranscriptTailBytes of the transcript file that run.get names. The daemon and the UI share the host (the socket is local), so this is the same file `smif run --transcript` prints.

type DiffView

type DiffView struct {
	RunID  string `json:"run_id"`
	Branch string `json:"branch"`
	Repo   string `json:"repo"`
	Diff   string `json:"diff"`
}

DiffView is the run.diff result.

type Digester

type Digester interface {
	Digest(ctx context.Context, p api.DigestParams) (*api.DigestResult, error)
}

Digester is digest.get. DaemonSource implements it.

type EventFeed

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

EventFeed follows the audit table through audit.since (ADR-0008). It keeps only a cursor: the daemon holds the rows.

func (*EventFeed) Cursor

func (f *EventFeed) Cursor() int64

Cursor is the seq of the newest event the feed returned.

func (*EventFeed) Poll

func (f *EventFeed) Poll(call func(method string, params, out any) error, backlog int) (evs []api.AuditEvent, reset bool, err error)

Poll returns the events after the cursor, oldest first. The first poll returns the newest backlog events and puts the cursor at the head. reset is true when the daemon's head is behind the cursor (a new database); the feed then starts again from the head.

type Inspector

type Inspector interface {
	// Messages is thread.list with an agent and state filter.
	Messages(ctx context.Context, p api.ListParams) ([]api.MessageView, error)
	// Run is run.get.
	Run(ctx context.Context, id string) (*api.RunView, error)
	// Diff is run.diff: the worker branch against the main checkout.
	Diff(ctx context.Context, runID string) (*DiffView, error)
	// Transcript reads the tail of the run's stream-JSON transcript.
	Transcript(ctx context.Context, r api.RunView) (*TranscriptTail, error)
	// Apply is run.apply: merge the worker branch into the main checkout.
	Apply(ctx context.Context, runID string) (*ApplyResult, error)
}

Inspector is the read side of the thread, run and inbox screens plus run.apply. DaemonSource implements it with existing human-only methods.

type Model

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

Model is the Bubble Tea model of `smif ui`.

func New

func New(src Source, o Options) *Model

New returns a model that polls src.

func (*Model) DigestOpen

func (m *Model) DigestOpen() (open bool, items int)

DigestOpen reports whether the digest screen is open and how many unread items it shows (-1 before the first load).

func (*Model) Down

func (m *Model) Down() bool

Down reports whether the last poll failed.

func (*Model) Focus

func (m *Model) Focus() Panel

Focus returns the focused panel.

func (*Model) HomeAgent

func (m *Model) HomeAgent() string

HomeAgent is the agent tab of the home screen ("" = all).

func (*Model) HomeSelected

func (m *Model) HomeSelected() string

HomeSelected is the id of the selected message on the home screen.

func (*Model) InboxOpen

func (m *Model) InboxOpen() (open bool, agent, state string)

InboxOpen reports whether the inbox screen is open, and its filter.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init starts the first poll.

func (*Model) ItemOpen

func (m *Model) ItemOpen() string

ItemOpen reports the id of the open item screen, or "".

func (*Model) Render

func (m *Model) Render() string

Render draws the screen as text (tests read it with ansi.Strip).

func (*Model) RunOpen

func (m *Model) RunOpen() string

RunOpen reports the id of the open run screen, or "".

func (*Model) RunTab

func (m *Model) RunTab() string

RunTab reports the open tab of the run screen: RECORD, TRANSCRIPT, DIFF.

func (*Model) Selected

func (m *Model) Selected() string

Selected returns the id under the cursor of the focused panel: an agent, run or message id, or "" when the panel is empty.

func (*Model) Status

func (m *Model) Status() string

Status returns the last action result line ("" when none).

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles keys, window sizes, ticks and poll results.

func (*Model) View

func (m *Model) View() tea.View

View renders the screen. View is the Bubble Tea v2 view: the screen on the alternate screen.

type Options

type Options struct {
	// Interval between polls (default 1 s).
	Interval time.Duration
	// Now is the clock for elapsed times (default time.Now).
	Now func() time.Time
	// Dashboard starts on the six-panel overview instead of the home
	// screen (`v` switches between them).
	Dashboard bool
	// SeenFile keeps which session answers the human has seen, across
	// restarts ("" = in memory only, as in tests).
	SeenFile string
	// PartsDir keeps the parts of a prompt, in a path with no spaces
	// (ADR-0020; "" = the system's temp folder).
	PartsDir string
}

Options configure a Model.

type Panel

type Panel int

Panel is one section of the overview.

const (
	PanelAgents Panel = iota
	PanelRunning
	PanelNeedsYou
	PanelDLQ
	PanelRecent
	PanelEvents
)

The overview panels, in tab order.

func (Panel) String

func (p Panel) String() string

type Prompter

type Prompter interface {
	Prompt(ctx context.Context, sessionID, text string) (*api.SessionPromptResult, error)
}

Prompter types the human's prompt into an idle session (session.prompt, ADR-0012). DaemonSource implements it.

type Sender

type Sender interface {
	Send(ctx context.Context, method string, d envelope.Draft) (*api.SendResult, error)
}

Sender sends a message as the human (message.ask or message.send).

type SessionFocuser

type SessionFocuser interface {
	FocusSession(ctx context.Context, sessionID string) error
}

SessionFocuser brings a session's terminal tab to the front (session.focus). DaemonSource implements it.

type SessionOpener

type SessionOpener interface {
	NewSession(ctx context.Context, dir, name, term string) error
}

SessionOpener opens a new session in a terminal tab (session.new).

type SessionSender

type SessionSender interface {
	SendSession(ctx context.Context, sessionID, text string) (*api.SessionSendResult, error)
}

SessionSender writes to a session: typed in when idle, else to a worker with its context (session.send, ADR-0013). DaemonSource implements it.

type SessionTailer

type SessionTailer interface {
	SessionTail(ctx context.Context, sessionID string) (*api.SessionTail, error)
}

SessionTailer reads a session's conversation (session.tail). DaemonSource implements it.

type Snapshot

type Snapshot struct {
	At       time.Time
	Err      error
	Status   api.StatusView
	NeedsYou []api.MessageView
	DLQ      []api.MessageView
	Recent   []api.MessageView
	// The home screen's groups beyond NeedsYou and DLQ: messages a worker
	// runs, waiting ones (queued, retry_wait), and the newest done ones.
	Running []api.MessageView
	Waiting []api.MessageView
	Done    []api.MessageView
	// Unread holds the ids of handled items not yet marked read (the
	// digest, peeked without advancing), and DigestCursor bounds a mark.
	Unread       map[string]bool
	DigestCursor int64
	// Sessions are the live interactive sessions (session.list, ADR-0012).
	Sessions []api.SessionView
	// Prompts are the human's saved prompts (prompts.list, ADR-0015).
	Prompts []api.SavedPrompt
	// Events are the newest audit events (audit.since), oldest first, at
	// most EventKeep.
	Events []api.AuditEvent
	// EventsErr is set when audit.since failed with an RPC error (an
	// older daemon); the rest of the snapshot is still good.
	EventsErr error
}

Snapshot is one poll of the daemon. Err is set when the daemon could not be reached or a call failed; the other fields are then empty.

type SnapshotMsg

type SnapshotMsg Snapshot

SnapshotMsg delivers a poll result.

type Source

type Source interface {
	Fetch(ctx context.Context) Snapshot
}

Source produces snapshots. The model calls Fetch from a Bubble Tea command, never two at a time.

type TranscriptTail

type TranscriptTail struct {
	Path string
	Size int64 // the whole file
	Data []byte
	// Cut is true when Data starts after the beginning of the file.
	Cut bool
}

TranscriptTail is the end of a transcript file.

func ReadTranscriptTail

func ReadTranscriptTail(path string, max int64) (*TranscriptTail, error)

ReadTranscriptTail reads up to max bytes from the end of path, starting at a line boundary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL