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
- Variables
- func EventDetail(ev api.AuditEvent) string
- func FormatEvent(ev api.AuditEvent) string
- func NoColor(getenv func(string) string) bool
- func RenderDiff(diff string, w int) []string
- func RenderTranscript(data []byte, w int) []string
- func SetupColor(getenv func(string) string) bool
- func Short(id string) string
- func WatchSummary(s Snapshot, now time.Time, interval time.Duration, events int) string
- type Actions
- type ApplyResult
- type Caller
- type DaemonSource
- func (s *DaemonSource) Apply(ctx context.Context, runID string) (*ApplyResult, error)
- func (s *DaemonSource) AttachSession(ctx context.Context, sessionID, term string) error
- func (s *DaemonSource) Cancel(ctx context.Context, messageID string) (*api.CancelResult, error)
- func (s *DaemonSource) CancelQueued(ctx context.Context, id int64) error
- func (s *DaemonSource) Close()
- func (s *DaemonSource) Diff(ctx context.Context, runID string) (*DiffView, error)
- func (s *DaemonSource) Digest(ctx context.Context, p api.DigestParams) (*api.DigestResult, error)
- func (s *DaemonSource) EventCursor() int64
- func (s *DaemonSource) Fetch(ctx context.Context) Snapshot
- func (s *DaemonSource) FocusSession(ctx context.Context, sessionID string) error
- func (s *DaemonSource) Messages(ctx context.Context, p api.ListParams) ([]api.MessageView, error)
- func (s *DaemonSource) NewSession(ctx context.Context, dir, name, term, harness string) error
- func (s *DaemonSource) PollEvents(ctx context.Context, backlog int) ([]api.AuditEvent, bool, error)
- func (s *DaemonSource) Prompt(ctx context.Context, sessionID, text string) (*api.SessionPromptResult, error)
- func (s *DaemonSource) QueueSession(ctx context.Context, sessionID, text string) (*api.SessionQueueResult, error)
- func (s *DaemonSource) ReopenSessions(ctx context.Context, term string) (*api.SessionReopenResult, error)
- func (s *DaemonSource) Reply(ctx context.Context, messageID, text string) (*api.SendResult, error)
- func (s *DaemonSource) ResumeSession(ctx context.Context, id, term string) error
- func (s *DaemonSource) Retry(ctx context.Context, messageID string) error
- func (s *DaemonSource) Run(ctx context.Context, id string) (*api.RunView, error)
- func (s *DaemonSource) SearchSessions(ctx context.Context, query string) (*api.SessionSearchResult, error)
- func (s *DaemonSource) Send(ctx context.Context, method string, d envelope.Draft) (*api.SendResult, error)
- func (s *DaemonSource) SendSession(ctx context.Context, sessionID, text string) (*api.SessionSendResult, error)
- func (s *DaemonSource) SessionHistory(ctx context.Context) ([]api.HistoryRow, error)
- func (s *DaemonSource) SessionTail(ctx context.Context, sessionID string) (*api.SessionTail, error)
- func (s *DaemonSource) Thread(ctx context.Context, id string) (*api.ThreadView, error)
- func (s *DaemonSource) Transcript(ctx context.Context, r api.RunView) (*TranscriptTail, error)
- type DiffView
- type Digester
- type EventFeed
- type Inspector
- type Model
- func (m *Model) DigestOpen() (open bool, items int)
- func (m *Model) Down() bool
- func (m *Model) Focus() Panel
- func (m *Model) HomeAgent() string
- func (m *Model) HomeSelected() string
- func (m *Model) InboxOpen() (open bool, agent, state string)
- func (m *Model) Init() tea.Cmd
- func (m *Model) ItemOpen() string
- func (m *Model) Render() string
- func (m *Model) RunOpen() string
- func (m *Model) RunTab() string
- func (m *Model) Selected() string
- func (m *Model) Status() string
- func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m *Model) View() tea.View
- type Options
- type Panel
- type Prompter
- type Sender
- type SessionAttacher
- type SessionFocuser
- type SessionHistorian
- type SessionOpener
- type SessionQueuer
- type SessionSender
- type SessionTailer
- type Snapshot
- type SnapshotMsg
- type Source
- type TranscriptTail
Constants ¶
const DigestLimit = 500
DigestLimit is how many unread items per agent the digest screen loads.
const EventKeep = 200
EventKeep is how many audit events the overview keeps for the EVENTS panel.
const InboxLimit = 200
InboxLimit is how many messages the inbox screen loads.
const TranscriptTailBytes = 256 << 10
TranscriptTailBytes caps how much of a transcript the run screen reads.
Variables ¶
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 ¶
NoColor reports whether the NO_COLOR variable asks for no colours: it is set and not empty (https://no-color.org).
func RenderDiff ¶
RenderDiff colours a unified diff: file headers bold, + green, - red, hunk headers cyan. Lines are cut, not wrapped, at w cells.
func RenderTranscript ¶
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 ¶
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 WatchSummary ¶
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) AttachSession ¶ added in v0.2.0
func (s *DaemonSource) AttachSession(ctx context.Context, sessionID, term string) error
AttachSession opens claude attach for the session.
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) CancelQueued ¶ added in v0.2.0
func (s *DaemonSource) CancelQueued(ctx context.Context, id int64) error
CancelQueued removes one queued item.
func (*DaemonSource) Diff ¶
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 ¶
func (s *DaemonSource) Digest(ctx context.Context, p api.DigestParams) (*api.DigestResult, error)
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, harness string) error
NewSession opens a new terminal tab that runs a harness in dir ("" = claude). The daemon builds the command from the harness's name.
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) QueueSession ¶ added in v0.2.0
func (s *DaemonSource) QueueSession(ctx context.Context, sessionID, text string) (*api.SessionQueueResult, error)
QueueSession puts text in the session's queue.
func (*DaemonSource) ReopenSessions ¶ added in v0.2.0
func (s *DaemonSource) ReopenSessions(ctx context.Context, term string) (*api.SessionReopenResult, error)
ReopenSessions starts reopening the restore list.
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) ResumeSession ¶ added in v0.2.0
func (s *DaemonSource) ResumeSession(ctx context.Context, id, term string) error
ResumeSession opens claude --resume for the session in a new tab.
func (*DaemonSource) Retry ¶
func (s *DaemonSource) Retry(ctx context.Context, messageID string) error
Retry requeues a dead letter.
func (*DaemonSource) SearchSessions ¶ added in v0.2.0
func (s *DaemonSource) SearchSessions(ctx context.Context, query string) (*api.SessionSearchResult, error)
SearchSessions looks for words in the text of past sessions.
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) SessionHistory ¶ added in v0.2.0
func (s *DaemonSource) SessionHistory(ctx context.Context) ([]api.HistoryRow, error)
SessionHistory lists the past sessions, newest first.
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) 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 (*Model) DigestOpen ¶
DigestOpen reports whether the digest screen is open and how many unread items it shows (-1 before the first load).
func (*Model) HomeSelected ¶
HomeSelected is the id of the selected message on the home screen.
func (*Model) Selected ¶
Selected returns the id under the cursor of the focused panel: an agent, run or message id, or "" when the panel is empty.
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.
The overview panels, in tab order.
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 SessionAttacher ¶ added in v0.2.0
SessionAttacher opens `claude attach` for a background session in a new tab (session.attach, ADR-0021). DaemonSource implements it.
type SessionFocuser ¶
SessionFocuser brings a session's terminal tab to the front (session.focus). DaemonSource implements it.
type SessionHistorian ¶ added in v0.2.0
type SessionHistorian interface {
SessionHistory(ctx context.Context) ([]api.HistoryRow, error)
SearchSessions(ctx context.Context, query string) (*api.SessionSearchResult, error)
ResumeSession(ctx context.Context, id, term string) error
ReopenSessions(ctx context.Context, term string) (*api.SessionReopenResult, error)
}
SessionHistorian reads past sessions and reopens them. DaemonSource implements it.
type SessionOpener ¶
type SessionOpener interface {
NewSession(ctx context.Context, dir, name, term, harness string) error
}
SessionOpener opens a new session in a terminal tab (session.new).
type SessionQueuer ¶ added in v0.2.0
type SessionQueuer interface {
QueueSession(ctx context.Context, sessionID, text string) (*api.SessionQueueResult, error)
CancelQueued(ctx context.Context, id int64) error
}
SessionQueuer keeps a prompt until its session is idle (session.queue, session.queue.cancel, ADR-0021). DaemonSource implements it.
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
// Harnesses are the agents n can start, claude first
// (session.harnesses, ADR-0021).
Harnesses []string
// Closed is the restore list (session.closed, ADR-0021).
Closed api.ClosedList
// 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 Source ¶
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.