Documentation
¶
Overview ¶
Package status keeps the work state of every tab: what its agent is doing (idle, busy, waiting for an answer, done), learnt from the agent's hooks, its transcript, its screen and its process tree, and pushed to every status socket.
Index ¶
- Constants
- type AgentSessions
- type AgentSource
- type Broadcaster
- type ChatState
- type ClientEntry
- type ClientView
- type Deps
- type Entry
- type HookMeta
- type LastEvent
- type Layouts
- type Manager
- func (m *Manager) Ack(tabID string, seq float64)
- func (m *Manager) AckCurrent(tabID string)
- func (m *Manager) AdoptSession(tabID, sessionID string)
- func (m *Manager) AgentSources() []AgentSource
- func (m *Manager) ApplyHookMeta(providerID, session string, meta HookMeta) (tabID, cliState string, ok bool)
- func (m *Manager) Background() any
- func (m *Manager) Broadcast(v any)
- func (m *Manager) ClientViews() []ClientView
- func (m *Manager) Dismiss(tabID string, exclude *sockets.Client)
- func (m *Manager) EntryOfSession(session string) (string, Entry, bool)
- func (m *Manager) ForeignHook(providerID, session string, ev agents.Event) bool
- func (m *Manager) HandleProviderEvent(providerID, session string, ev agents.Event, firedAt *float64) bool
- func (m *Manager) History() any
- func (m *Manager) HooksMissing(tabID string) bool
- func (m *Manager) Interrupt(tabID string) bool
- func (m *Manager) Interrupted(session string)
- func (m *Manager) IsSessionBusy(session string) bool
- func (m *Manager) LaunchFailed(tabID string)
- func (m *Manager) MarkAgentGone(tabID string, endLaunch bool)
- func (m *Manager) MarkAgentLaunch(tabID string, reset bool)
- func (m *Manager) MarkNeedsInputFromScreen(tabID string) bool
- func (m *Manager) MirrorChat(session string, s ChatState)
- func (m *Manager) NotifyLastUserMessage(session, message string)
- func (m *Manager) Poll()
- func (m *Manager) Queues() any
- func (m *Manager) RateLimits() any
- func (m *Manager) RateLimitsChanged(data any)
- func (m *Manager) RecheckStuck(tabID string) string
- func (m *Manager) ReconcileWorkspaceTabs(wsID string, valid []string)
- func (m *Manager) RecoverSession(tabID string) bool
- func (m *Manager) RecoverUnknown(tabID string) (bool, string)
- func (m *Manager) RegisterTab(tabID string, e Entry)
- func (m *Manager) RemoveTab(tabID string)
- func (m *Manager) RemoveWorkspaceTabs(wsID string)
- func (m *Manager) Rescan()
- func (m *Manager) Start(ctx context.Context)
- func (m *Manager) SynthesizeEvent(session, event string)
- func (m *Manager) Tab(tabID string) (TabInfo, bool)
- func (m *Manager) TabOfSession(session string) string
- func (m *Manager) Tabs() any
- func (m *Manager) Warn(msg string)
- type Mismatch
- type Opt
- type Procs
- type Provider
- type Pusher
- type Queue
- type Tab
- type TabInfo
- type Tmux
- type Workspace
Constants ¶
const ( Idle = "idle" Busy = "busy" Inactive = "inactive" ReadyForReview = "ready-for-review" NeedsInput = "needs-input" Cancelled = "cancelled" Unknown = "unknown" )
Work states of a tab.
const ( EventSessionStart = "session-start" EventPromptSubmit = "prompt-submit" EventNotification = "notification" EventStop = "stop" EventStopFailure = "stop-failure" EventInterrupt = "interrupt" EventPreCompact = "pre-compact" EventPostCompact = "post-compact" )
Event names that move the state.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentSessions ¶ added in v0.16.86
AgentSessions is a provider that can tell which sessions the agent a pane runs goes by (Claude: by its pid file), nil when it cannot. The keeper asks it to tell a hook of the tab's agent from one of an agent started inside it.
type AgentSource ¶
type AgentSource struct {
TabID, TmuxSession, Transcript, Provider, PanelType, CliState, LastEventName, AgentSessionID string
EventSeq int
LastEventAt, LastStartedAt *float64
}
AgentSource is an agent tab as idle sleep and background activity read it.
type Broadcaster ¶
Broadcaster is where status messages go: the status sockets.
type ChatState ¶
ChatState is where a chat's actor stands, in the keeper's words: CliState empty leaves the state as it is, Event names the hook the change stands for ("" none).
type ClientEntry ¶
type ClientEntry json.RawMessage
ClientEntry is an entry ready to be written as JSON.
func (ClientEntry) MarshalJSON ¶
func (c ClientEntry) MarshalJSON() ([]byte, error)
type ClientView ¶
type ClientView struct {
TabID, PanelType, CliState, AgentSummary, TabName, WorkspaceID, TmuxSession, Transcript string
// LastEventAt is 0 when the tab has seen no event.
LastEventAt float64
}
ClientView is what a page reads of a tab: its kind, state, names and workspace.
type Deps ¶
type Deps struct {
Layouts Layouts
Tmux Tmux
Procs Procs
Providers map[string]Provider
Queue Queue
History *history.Store
Push Pusher
// ChatSession says the tab's tmux session is a chat's, which follows its agent's transcript itself (convo): the
// poll reads no transcript and no process tree for such a tab once it knows it, and the keeper neither watches its
// transcript nor pushes nor snapshots its folder at a turn's end: the chat's actor does (convo.Notice). nil: no
// tab is.
ChatSession func(session string) bool
// TurnEnd snapshots the session folder for rewinding once a turn ended.
TurnEnd func(tabID, cwd string)
// AskFolderTrust leaves an agent's folder trust dialog to the person; by default the keeper answers yes for the
// folder the tab was started in, since the dialog is not on the page.
AskFolderTrust bool
// AgentLaunched hears of every agent the platform starts or resumes in a tab, before the keeper marks it.
AgentLaunched func(tabID string)
// Mismatch reports a corrected state.
Mismatch func(Mismatch)
// TabRemoved: the keeper forgot a closed tab (its prompt queue goes with it).
TabRemoved func(tabID string)
// PromptEnter takes the time since the runtime's last Enter in a pane (ms), once.
PromptEnter func(session string, now float64) (float64, bool)
// CodexRateLimits caches the limits a Codex transcript carries.
CodexRateLimits func(transcript string)
// BackgroundTasks reads a Claude transcript's background work; ForgetTranscript drops what it remembers of one.
BackgroundTasks func(transcript string) []background.Task
ForgetTranscript func(transcript string)
// BackgroundTimings are the feed's; zero for production.
BackgroundTimings background.Timings
Log func(level, msg string, kv ...any)
Now func() time.Time
NewID func() string
}
Deps are everything the keeper reads and drives.
type Entry ¶
type Entry struct {
CliState string
WorkspaceID string
TabName string
CurrentProcess Opt[string]
PaneTitle Opt[string]
TmuxSession string
PanelType Opt[string]
TerminalStatus Opt[string]
ListeningPorts Opt[[]int]
AgentProviderID Opt[string]
AgentSummary Opt[string]
LastUserMessage Opt[string]
LastAssistantMessage Opt[string]
CurrentAction Opt[agents.CurrentAction]
ReadyForReviewAt Opt[float64]
BusySince Opt[float64]
DismissedAt Opt[float64]
AgentSessionID Opt[string]
CompactingSince Opt[float64]
PermissionRequest Opt[json.RawMessage]
LastEvent Opt[LastEvent]
EventSeq int
LaunchingSince *float64
LaunchFailed bool
HooksMissing bool
// Kept on the server only.
JSONLPath string
ProcessRetries int
StuckCheckedAt float64
StuckBackoffMs float64
LastHookFiredAt *float64
HooksCheckedFor *string
HooksCheckedAt *float64
GoneSince *float64
LastInterruptTs float64
LastResumeOrStartedAt *float64
// contains filtered or unexported fields
}
Entry is everything the keeper knows about one tab.
type HookMeta ¶
type HookMeta struct {
SessionID, JSONLPath, LastUserMessage, AgentSummary *Opt[string]
PermissionRequest *json.RawMessage
ClearMessages bool
}
HookMeta is what a Codex hook says about the conversation; a nil field is not mentioned.
type Layouts ¶
type Layouts interface {
Workspaces() []Workspace
// Tabs are a workspace's tabs in tree order; ok false when it has no readable layout.
Tabs(wsID string) ([]Tab, bool)
UpdateTabCliStatus(session, cliState string, dismissedAt Opt[float64], lastEventName string) error
// UpdateTabAgentState stores what is set; a set Opt with a nil value stores null.
UpdateTabAgentState(session, provider string, sessionID, jsonlPath, summary, lastUserMessage Opt[string]) error
// RecoverSession gives a Claude tab that lost its session id the one its transcript or history shows, stored.
RecoverSession(session string) (sessionID string, ok bool)
}
Layouts is the layout and workspace store.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps the work state of every tab and tells the status sockets.
func New ¶
func New(d Deps, hub Broadcaster) *Manager
New makes a keeper broadcasting on hub (a *sockets.Hub).
func (*Manager) AckCurrent ¶
AckCurrent acknowledges the tab's current question, whatever its number (the shadow mirrors the person's answer).
func (*Manager) AdoptSession ¶
AdoptSession gives the tab's entry the agent session its layout tab took from the chat's record; an entry that keeps a session keeps it.
func (*Manager) AgentSources ¶
func (m *Manager) AgentSources() []AgentSource
AgentSources are the agent tabs.
func (*Manager) ApplyHookMeta ¶
func (m *Manager) ApplyHookMeta(providerID, session string, meta HookMeta) (tabID, cliState string, ok bool)
ApplyHookMeta takes a Codex hook's conversation details; ok false for an unknown session.
func (*Manager) Background ¶
Background is every tab with background work (background:sync).
func (*Manager) Broadcast ¶
Broadcast sends any message to every status socket (queue and pane-intent updates).
func (*Manager) ClientViews ¶
func (m *Manager) ClientViews() []ClientView
ClientViews are all tabs, in the keeper's order.
func (*Manager) Dismiss ¶
Dismiss: the person opened the finished answer. A page's own socket gets no echo of it; the relay does.
func (*Manager) EntryOfSession ¶
EntryOfSession is the tab of a tmux session and a copy of its entry; false when the keeper has none.
func (*Manager) ForeignHook ¶ added in v0.16.86
ForeignHook tells a hook to drop: one of an agent the tab's agent (or a script in its terminal) started, which inherits the tab's tmux session and its hooks — its SessionStart and Stop would end the turn of the tab's agent The hook names its agent session; it is the tab's when it is the one the keeper knows, or one the agent running in the pane goes by now (after /clear the pid file names the new session before its SessionStart fires). A hook naming no session, a provider that cannot tell, or a pane with no agent seen: not foreign, as before.
func (*Manager) HandleProviderEvent ¶
func (m *Manager) HandleProviderEvent(providerID, session string, ev agents.Event, firedAt *float64) bool
HandleProviderEvent is a hook's event. firedAt (ms) is when it fired on the machine: the hook reports in the background, so two reports can arrive out of order, and one fired before the last applied one is dropped.
func (*Manager) HooksMissing ¶
HooksMissing is whether the agent of a tab runs without the platform's hooks.
func (*Manager) Interrupt ¶
Interrupt is the Stop button: Escape, then the state settles at once (an agent interrupted before its first output writes nothing to its transcript).
func (*Manager) Interrupted ¶
Interrupted settles the state of a Stop whose Escape was already sent (by the prompt routes): an interrupt hook, so the tab goes idle and its queue goes out 700 ms later.
func (*Manager) IsSessionBusy ¶
IsSessionBusy: whether the agent in a tmux session is working (the timeline reads its live reply only then).
func (*Manager) LaunchFailed ¶
LaunchFailed: a launch the queue asked for cannot come up (nothing to resume); the composer shows it.
func (*Manager) MarkAgentGone ¶
MarkAgentGone: the agent was killed from the platform; say so now instead of waiting for the poll.
func (*Manager) MarkAgentLaunch ¶
MarkAgentLaunch: a launch or resume line was typed into the tab. reset clears the conversation the tab showed.
func (*Manager) MarkNeedsInputFromScreen ¶
MarkNeedsInputFromScreen: after a command left a menu open, the agent waits for an answer whatever state it was in.
func (*Manager) MirrorChat ¶
MirrorChat puts the tab of a chat's tmux session where the chat's actor is, with the side effects a change of state has (the turn's history, the queue, the background feed); the tab of a session that is no chat's is left alone.
func (*Manager) NotifyLastUserMessage ¶
NotifyLastUserMessage: the timeline saw a new prompt in the tab of a tmux session.
func (*Manager) Poll ¶
func (m *Manager) Poll()
Poll looks at every tab once. A poll asked for while one runs runs once more after it, instead of being lost.
func (*Manager) RateLimits ¶
RateLimits is the last limits content.
func (*Manager) RateLimitsChanged ¶
RateLimitsChanged: the limits file got a new measurement.
func (*Manager) RecheckStuck ¶
RecheckStuck runs the watchdog on a tab now, whatever its quiet time (after a command ran in it).
func (*Manager) ReconcileWorkspaceTabs ¶
ReconcileWorkspaceTabs forgets the tabs of a workspace its layout no longer has.
func (*Manager) RecoverSession ¶
RecoverSession is recoverEntrySession for the queue.
func (*Manager) RecoverUnknown ¶
RecoverUnknown: an unknown tab whose screen shows a permission prompt is waiting for an answer.
func (*Manager) RegisterTab ¶
RegisterTab adds a tab a route just created.
func (*Manager) RemoveTab ¶
RemoveTab forgets a closed tab; a turn cut short goes to the history as cancelled.
func (*Manager) RemoveWorkspaceTabs ¶
RemoveWorkspaceTabs forgets every tab of a removed workspace.
func (*Manager) Rescan ¶
func (m *Manager) Rescan()
Rescan rebuilds every entry (after a tmux reset).
func (*Manager) SynthesizeEvent ¶
SynthesizeEvent applies an event the runtime inferred itself (a resumed agent whose SessionStart hook never came) the way a hook's event is applied, without what only a real hook proves (the hook order, the hooks being there).
func (*Manager) TabOfSession ¶
TabOfSession is the agent tab of a tmux session ("" when none).
type Opt ¶
Opt is a field the page tells apart in three ways: absent, null, or a value. The old runtime built its entries differently on different paths, and the page reads an absent key and a null key differently.
type Procs ¶
type Procs interface {
Children(pid int) []int
// ListeningPorts are the TCP ports the pane's descendants listen on, sorted.
ListeningPorts(pid int) []int
// Unreadable: the process exists but a look cannot tell what it runs now (waits on a hung file system, or shows an
// empty command line on its way out). A look that met one decides nothing about the agent.
Unreadable(pid int) bool
}
Procs reads the process table.
type Provider ¶
type Provider interface {
ID() string
Running(panePID int, children []int) bool
Detect(panePID int, children []int) agents.SessionInfo
Snapshot(transcript string, force bool) (agents.Snapshot, error)
HistoryStats(transcript string) (*agents.HistoryStats, error)
// LastConversationAt is unused here; sleep reads it.
ParsePaneTitle(title string) *string
SessionIDFromPath(transcript string) string
ReadSessionID(t agents.TabAgent) string
ReadJSONLPath(t agents.TabAgent) string
ReadSummary(t agents.TabAgent) string
// FindSession is a session's transcript by its id (Codex); "" when not found or not supported.
FindSession(sessionID string) string
// TranscriptIn is a session's transcript in a folder's project directory (Claude); "" when missing.
TranscriptIn(cwd, sessionID string) string
// RunsWithHooks: whether the agent among children runs with the platform's hooks; found false when none runs yet.
RunsWithHooks(children []int) (hooked, found bool)
}
Provider is an agent CLI: Claude Code or Codex.
type Queue ¶
type Queue interface {
// Schedule looks at the tab's queue after delay (a turn just ended, a launch ended, a restart).
Schedule(tabID string, delay time.Duration)
// Tabs are the tabs with something queued.
Tabs() []string
Pending(tabID string) bool
Snapshot() any
}
Queue is the prompt queue as the keeper drives it.
type Tab ¶
type Tab struct {
ID string
SessionName string
Name string
PanelType Opt[string]
CliState string
LastEventName string
DismissedAt Opt[float64]
LastUserMessage Opt[string]
Agent agents.TabAgent
}
Tab is a layout tab as the keeper reads it.
func TabFromLayout ¶
TabFromLayout reads a tab object of a layout file.
type TabInfo ¶
type TabInfo struct {
CliState, Provider, PanelType, TmuxSession, Transcript, AgentSessionID string
Launching, LaunchFailed bool
}
TabInfo is what the prompt queue reads of a tab.
type Tmux ¶
type Tmux interface {
ReadAllPanes() (map[string]tmux.PaneInfo, bool)
PaneTitle(session string) string
PaneDetail(session string) tmux.PaneDetail
PanePID(session string) int
Capture(session string) (string, bool)
// CaptureAtWidth may pause and resize the attached terminal (Codex readiness, recovery of an unknown tab).
CaptureAtWidth(session string, cols, rows int) (string, bool)
SessionCwd(session string) string
SendRawKeys(session, keys string) error
ParseSessionName(name string) (wsID, paneID, tabID string, ok bool)
}
Tmux is what the keeper asks tmux.