Documentation
¶
Overview ¶
Package sessions follows the coding-agent sessions the app launches, from the item each was launched on, while they run in the user's own terminal.
Every launch is recorded in a ledger, the agent_sessions table this package owns, under an ID the app mints before the launch: one on a pull request or an issue with its item, and a repository's launch, such as an upgrade of its dependencies, with none, in the worktree it made (Record.IsRepo). A Watcher then reconciles what each agent reports through its own supported interface into the ledger, as a controller does: an Observer per agent (the observe/claude and observe/codex packages) turns the agent's own shapes into one State, and the Watcher stores each change, tells the window, and hands the moments that need the user to an AttentionSink. It observes only while some session has not ended, and it reconciles every session that has not ended when the app starts again, so it survives restarts.
Following is read-only. The app never sends a session input, never answers its approvals, and never writes into an agent's config or conversation, apart from the session ID a Claude Code launch passes. Everything stays on this Mac: nothing here talks to GitHub or to any network.
Index ¶
- Constants
- Variables
- func TTY(ctx context.Context, run execpath.Runner, pid int) (string, error)
- type AttentionSink
- type Change
- type Config
- type Focuser
- type GitHubEvent
- type GitHubNote
- type Ledger
- func (l *Ledger) AgentProcesses(ctx context.Context) (map[int]agent.ID, error)
- func (l *Ledger) ByRun(ctx context.Context, runID int64) (Record, error)
- func (l *Ledger) ConversationLive(ctx context.Context, agentSessionID string) (bool, error)
- func (l *Ledger) Get(ctx context.Context, id string) (Record, error)
- func (l *Ledger) NoteGitHub(ctx context.Context, notes []GitHubNote) error
- func (l *Ledger) RunState(ctx context.Context, id string, u RunUpdate) error
- func (l *Ledger) Running(ctx context.Context, dir string) ([]Session, error)
- func (l *Ledger) Start(ctx context.Context, r Record) error
- func (l *Ledger) Waiting(ctx context.Context) ([]Session, error)
- type Observation
- type Observer
- type Record
- type Rereader
- type Revealer
- type RunTokens
- type RunUpdate
- type Service
- func (s *Service) Focus(ctx context.Context, id string) error
- func (s *Service) Forget(ctx context.Context, id string) error
- func (s *Service) LastWords(ctx context.Context, id string) (Words, error)
- func (s *Service) List(ctx context.Context) (Snapshot, error)
- func (s *Service) ShowFolder(ctx context.Context, id string) error
- func (s *Service) Usage(ctx context.Context, id string) (Usage, error)
- type Session
- type Snapshot
- type State
- type Store
- func (s *Store) Apply(ctx context.Context, now time.Time, observed []Observation) ([]Change, error)
- func (s *Store) ByRun(ctx context.Context, runID int64) (Record, error)
- func (s *Store) ConversationLive(ctx context.Context, agentSessionID string) (bool, error)
- func (s *Store) EndedSince(ctx context.Context, since time.Time) ([]Record, error)
- func (s *Store) Forget(ctx context.Context, id string) error
- func (s *Store) Get(ctx context.Context, id string) (Record, error)
- func (s *Store) Insert(ctx context.Context, r Record) error
- func (s *Store) InsertUnlessLive(ctx context.Context, r Record) (bool, error)
- func (s *Store) KeptItems(ctx context.Context) ([]int64, error)
- func (s *Store) Live(ctx context.Context) ([]Record, error)
- func (s *Store) NoteGitHub(ctx context.Context, n GitHubNote) (bool, error)
- func (s *Store) Prune(ctx context.Context, now time.Time) (int64, error)
- func (s *Store) Recent(ctx context.Context, since time.Time) ([]Record, error)
- func (s *Store) SetRunState(ctx context.Context, id string, u RunUpdate, now time.Time) (Change, bool, error)
- type Switch
- type Usage
- type UsageReader
- type Watcher
- type WatcherConfig
- type Words
- type WordsReader
- type WorktreeAction
Constants ¶
const ( // KeepEnded is how long an ended session is kept. KeepEnded = 30 * 24 * time.Hour // KeepPerItem is how many sessions of each item are kept, the newest; one still // running is always kept. KeepPerItem = 20 // RecentWindow is how far back the window's list reaches for sessions that ended. RecentWindow = 7 * 24 * time.Hour )
Retention: the sessions the ledger keeps.
const ( // DefaultTick is how often the Watcher asks the observers while a session runs. Each // observer decides itself how often it asks its agent; most ticks cost a few file // stats. DefaultTick = time.Second // DefaultDebounce is how long a session must wait for the user before the // AttentionSink hears of it, so a prompt answered at once never shows a banner. DefaultDebounce = 5 * time.Second // ReviveWindow is how long after it ended a session is watched for being resumed // outside the app, as `claude --resume <id>` in a terminal resumes it. ReviveWindow = 24 * time.Hour // ReviveTick is how often the Watcher looks for a resumed session while none runs. ReviveTick = 20 * time.Second // ActedGap is the least time between two reads of one item that its sessions' commands // asked for while they still work (Observation.Acted): the first is read at once, and // any more within the gap once more at its end, so an approval then a merge both reach // the card, at most a point each gap. The read once a session stops working is apart. ActedGap = 30 * time.Second )
The Watcher's pace.
const MaxMessageRunes = 500
MaxMessageRunes caps the last message a session keeps.
const MaxWordsRunes = 20000
MaxWordsRunes caps a session's last message as LastWords reads it in full.
Variables ¶
var ( // ErrEnded is returned by Focus for a session that has ended. ErrEnded = errors.New("the session has ended") // ErrNoTerminal is returned by Focus for a session whose terminal cannot be found. ErrNoTerminal = errors.New("the session's terminal is not known") // ErrNoFolder is returned by ShowFolder for a session whose folder is gone. ErrNoFolder = errors.New("the session's folder is gone") // ErrNoFinder is returned by ShowFolder where there is no Finder to show it in. ErrNoFinder = errors.New("no file manager to show the folder in") )
var ( // ErrNotFound is returned for a session the ledger does not hold. ErrNotFound = errors.New("the session is no longer recorded") // ErrInvalidRecord is returned for a session record missing what storing it needs. ErrInvalidRecord = errors.New("invalid session record") // ErrLive is returned by Forget for a session that has not ended. ErrLive = errors.New("the session is still running") )
var ErrNoUsage = errors.New("the session's token counts can't be read")
ErrNoUsage is returned by a UsageReader that finds no token counts for the session: no file of its own, or one that reports none.
var ErrNoWords = errors.New("the session's last message can't be read")
ErrNoWords is returned by a WordsReader that finds nothing the session said.
Functions ¶
Types ¶
type AttentionSink ¶
type AttentionSink interface {
// NeedsYou says a session has waited for the user for the debounce.
NeedsYou(ctx context.Context, s Session)
// Finished says a session finished a turn it was working on.
Finished(ctx context.Context, s Session)
}
AttentionSink hears the moments a session needs the user: it has waited for them a while, or it finished a turn. The notify package's banners implement it.
type Change ¶
Change is a session whose record an observation changed: as it was, and as it is.
func (Change) StateChanged ¶
StateChanged reports a change of state.
type Config ¶
type Config struct {
Store *Store
// Watcher is woken when a launch records a session. Optional.
Watcher *Watcher
// Switch is the user's master switch; without it, sessions are always followed.
Switch Switch
// Focuser shows a session's terminal; without it, Focus fails.
Focuser Focuser
// PS runs ps, which names the terminal a session's process runs in.
PS execpath.Runner
// Reveal shows a session's folder in Finder; without it, ShowFolder fails.
Reveal Revealer
// Home shows home as ~.
Home string
// Events hears an event.SessionsUpdated when a launch records a session, and when the
// user forgets one.
Events event.Sink
// Words reads each agent's sessions' last messages in full, for LastWords; an agent
// with none falls back to the start the ledger keeps.
Words map[agent.ID]WordsReader
// Rereader hears the item of a background run's session that stops working, as the
// Watcher's does of a session in the terminal. Optional.
Rereader Rereader
// Usage reads each agent's sessions' token counts, for Usage; an agent with none
// reports none.
Usage map[agent.ID]UsageReader
// RunTokens reads what a background run's session used, as its run reported it, for
// Usage, in place of the agent's own files. Optional: without it such a session
// reports none.
RunTokens RunTokens
Clock clock.Clock
Logger *slog.Logger
}
Config holds a Service's and a Ledger's dependencies. Store is required.
type Focuser ¶
type Focuser interface {
// Focus selects the tab, in the terminal named by its settings ID, whose tty is
// tty, such as /dev/ttys004, and brings its window forward.
Focus(ctx context.Context, terminal, tty string) error
}
Focuser brings a terminal's tab that runs on a tty forward. The app adapts the launcher's terminal drivers to it.
type GitHubEvent ¶ added in v0.4.0
type GitHubEvent string
GitHubEvent is what came of a session's item on GitHub while the session ran, as the inbox learned it from the reads it makes anyway: the newest of a review of the user's that decided, a merge, or a close. It says nothing of who did it: the agent with gh, the user in a browser, or the user from the app.
const ( // GitHubNone is nothing learned yet. GitHubNone GitHubEvent = "" // GitHubApproved is a review of the user's that approved the pull request. GitHubApproved GitHubEvent = "approved" // GitHubChangesRequested is a review of the user's that requested changes. GitHubChangesRequested GitHubEvent = "changes_requested" // GitHubMerged is the pull request merged. GitHubMerged GitHubEvent = "merged" // GitHubClosed is the pull request or issue closed without a merge. GitHubClosed GitHubEvent = "closed" )
What came of a session's item on GitHub.
func (GitHubEvent) Valid ¶ added in v0.4.0
func (e GitHubEvent) Valid() bool
Valid reports whether e is one of the events, GitHubNone included.
type GitHubNote ¶ added in v0.4.0
GitHubNote is something that came of an item on GitHub, as the inbox learned it: the item, the event, the commit a review was left on ("" for none), and GitHub's time for it.
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
Ledger records the sessions launches start, and the background runs' sessions, and reads them for the launcher and the menu bar. It is not bound to the window.
func (*Ledger) AgentProcesses ¶
AgentProcesses returns the coding agent of each running session's process, by PID, or none while the app does not follow sessions, when the processes it knows may be stale.
func (*Ledger) ByRun ¶ added in v0.4.0
ByRun returns the session of the background run runID, or ErrNotFound.
func (*Ledger) ConversationLive ¶
ConversationLive reports whether a session that has not ended carries on the agent's conversation agentSessionID, as one resumed does; false while the app does not follow sessions, when what it knows may be stale.
func (*Ledger) NoteGitHub ¶ added in v0.4.0
func (l *Ledger) NoteGitHub(ctx context.Context, notes []GitHubNote) error
NoteGitHub records on the sessions of each note's item what came of it on GitHub while they ran (see Store.NoteGitHub), and tells the window once when any session changed. It records every note it can, and returns what failed.
func (*Ledger) RunState ¶ added in v0.4.0
RunState records what a background run's own stream says of its session id: working, then idle, ended, or failed. The Watcher never asks an observer of it. It tells the window when the session changed, and hands the Rereader the session's item once it stops working, as the Watcher does for a session in the terminal. A session that isn't a run's, or has ended, is left as it is.
func (*Ledger) Running ¶
Running returns the sessions that have not ended running in the folder dir, whichever item each was started on, newest first, or none while the app does not follow sessions. Folders are compared with their symbolic links resolved.
type Observation ¶
type Observation struct {
// ID is the app's ID of the session observed.
ID string
// AgentSessionID is the agent's own ID, once found.
AgentSessionID string
// State is what the session is doing, and Detail says more, or is "".
State State
Detail string
// PID is the agent's process, once found.
PID int
// LastMessage is what the agent last said.
LastMessage string
// Seen reports that the agent itself listed the session as running, rather than its
// process or its folder suggesting so.
Seen bool
// Relinked reports that the session's own process moved on to the conversation
// AgentSessionID, as Claude Code's /clear starts a new one, so the session follows it
// in place of the one it was linked to.
Relinked bool
// Acted reports that, since the session was last observed, its agent finished a
// command that changes something on GitHub (fence.ChangesGitHub) without an error, so
// its item may have changed while it still works. It is never stored: the Watcher
// reads the item again (see Watcher.heedActed).
Acted bool
}
Observation is what an Observer saw of one session. A zero field keeps what is stored.
type Observer ¶
type Observer interface {
// Observe reports what each of live, the agent's sessions that have not ended, is
// doing as of now, with an observation for every one it has news of. The Watcher
// calls it about once a Tick while any runs; the observer decides how often it asks
// the agent, and answers from what it learned last in between. It never fails: an
// agent it cannot ask makes the sessions StateUnknown, or StateEnded once their
// process is gone.
Observe(ctx context.Context, now time.Time, live []Record) []Observation
// Close releases what the observer keeps between calls, such as a connection. The
// next Observe starts again.
Close()
}
Observer reports what one agent's sessions are doing, through the agent's own supported interface.
type Record ¶
type Record struct {
// ID is the app's own ID, AgentSessionID the agent's, or "", and ResumedFrom the ID
// of the session this one resumed, or "".
ID string
AgentSessionID string
ResumedFrom string
// Agent, Profile, and ConfigDir are what it runs with: ConfigDir is the profile's
// config directory, or "" for the agent's default.
Agent agent.ID
Profile string
ConfigDir string
// Prompt is the nickname of the prompt it was started with, and PromptHead the start
// of the prompt.
Prompt string
PromptHead string
// Terminal is the terminal it runs in.
Terminal string
// ItemID, Owner, Name, Kind, Number, Title, and URL are the item. A session a
// repository's launch started has none (IsRepo): ItemID 0, Kind "", and Number 0, its
// Title the prompt's name, its URL the repository's page, and its Worktree the one its
// launch made.
ItemID int64
Owner string
Name string
Kind item.Kind
Number int
Title string
URL string
// Dir is the absolute folder it runs in; ClonePath and Worktree say whose worktree
// that is, when it is one.
Dir string
ClonePath string
Worktree string
// WorktreeAction is what the launch did to that worktree, Permission summarizes the
// permissions it started with, and Notice says what the launch worked around; each is
// "" when there is nothing to say or it was recorded before they were kept.
WorktreeAction WorktreeAction
Permission string
Notice string
// PID is the agent's process, or 0 while unknown.
PID int
// State, Detail, and LastMessage are what it last reported.
State State
Detail string
LastMessage string
// LaunchedAt is when it was launched; LinkedAt when its agent's ID was found, StateAt
// when it came to its state, and EndedAt when it ended, each zero when not yet.
LaunchedAt time.Time
LinkedAt time.Time
StateAt time.Time
EndedAt time.Time
// RunID is the script_runs ID of the background run whose session this is, or 0 for a
// session in the user's terminal. Its state comes from its run (RunState), and the
// Watcher leaves it alone.
RunID int64
// GitHubEvent is the newest thing that came of the item on GitHub while the session
// ran, as the inbox learned it (Ledger.NoteGitHub), GitHubEventCommit the commit a
// review was left on, and GitHubEventAt GitHub's time for it; GitHubNone, "", and zero
// before any.
GitHubEvent GitHubEvent
GitHubEventCommit string
GitHubEventAt time.Time
}
Record is one session as the ledger stores it.
type Rereader ¶
type Rereader interface{ Reread(itemID int64) }
Rereader hears the item a session worked on once the session stops working, so the item is read again from GitHub: the agent may have reviewed, commented, or pushed. Reread must not block. The inbox implements it, through core.
type RunTokens ¶ added in v0.4.0
RunTokens reads the tokens a background run reported so far, by the run engine's run (Record.RunID), as Autopilot's ledger records them; core adapts it. False when the run is recorded nowhere.
type RunUpdate ¶ added in v0.4.0
type RunUpdate struct {
// State is what it does now, Detail says more, and LastMessage is the start of what
// the agent last said, "" to keep the one stored.
State State
Detail string
LastMessage string
// PID is the agent's process, 0 to keep the one stored.
PID int
// AgentSessionID is the agent's own ID of the conversation, once the run's stream names
// it (Codex picks its thread's), "" to keep the one stored. It links a session not yet
// linked, as an observation does.
AgentSessionID string
}
RunUpdate is what a background run's own stream says of its session.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the sessions as the window binds them.
func (*Service) Forget ¶
Forget forgets a session that has ended, on the user's click, so it leaves the card and the panel, and tells the window. A session already forgotten counts as done, and one still running is refused and kept.
func (*Service) LastWords ¶
LastWords returns what the session with id last said, in full, read from the agent's own files, so the review sheet can show a whole verdict where a card shows its start. When the agent's files can't be read, it returns the start the ledger keeps, marked Partial; a session that said nothing has empty Words.
func (*Service) List ¶
List returns every session still running and the others launched in the last week, newest first, and whether the app follows sessions.
func (*Service) ShowFolder ¶
ShowFolder shows the folder a session runs in, its worktree or the clone, in Finder, whether or not the session still runs.
func (*Service) Usage ¶ added in v0.4.0
Usage returns how many tokens the session with id used: a background run's as its run reported them, any other's read from the agent's own files. Known false, with no error, for a session the agent hasn't named yet, an agent with no reader, a run that reported none, or files that report none.
type Session ¶
type Session struct {
// ID is the app's own ID of the session.
ID string `json:"id"`
// AgentSessionID is the agent's own ID of it, or "" until the agent reports it.
AgentSessionID string `json:"agentSessionId"`
// ResumedFrom is the ID of the session this one resumed, or "".
ResumedFrom string `json:"resumedFrom"`
// Agent is the agent, with the profile it ran with, and the nickname of the prompt
// it was started with, or "" for a session resumed.
Agent agent.ID `json:"agent"`
Profile string `json:"profile"`
Prompt string `json:"prompt"`
// Terminal is the terminal it runs in.
Terminal string `json:"terminal"`
// ItemID is the item's local ID, Repo is "owner/name", and Kind, Number, Title, and
// URL are the item. A session a repository's launch started has no item (IsRepo):
// ItemID 0, Kind "", and Number 0, its Title the prompt's name and its URL the
// repository's page.
ItemID int64 `json:"itemId"`
Repo string `json:"repo"`
Kind item.Kind `json:"kind"`
Number int `json:"number"`
Title string `json:"title"`
URL string `json:"url"`
// Dir is the folder it runs in, with ~ for home, and Worktree the item's worktree
// there, or "" when it runs in the clone.
Dir string `json:"dir"`
Worktree string `json:"worktree"`
// WorktreeAction is what its launch did to that worktree, or "" in the clone or when
// not known.
WorktreeAction WorktreeAction `json:"worktreeAction"`
// Permission summarizes the permissions it started with, such as "full access", and
// Notice says what its launch worked around; each is "" when not known.
Permission string `json:"permission"`
Notice string `json:"notice"`
// State is what it is doing, Detail says more where the agent did, and StateAt is
// when it came to that state, as RFC 3339.
State State `json:"state"`
Detail string `json:"detail"`
StateAt string `json:"stateAt"`
// LastMessage is the start of what the agent last said, or "".
LastMessage string `json:"lastMessage"`
// LaunchedAt is when it was launched, and EndedAt when it ended, or "", as RFC 3339.
LaunchedAt string `json:"launchedAt"`
EndedAt string `json:"endedAt"`
// CanFocus reports a session whose terminal can be shown: it runs, and its process
// is known. CanResume reports one that can be resumed: it ended, and the agent named
// its conversation.
CanFocus bool `json:"canFocus"`
CanResume bool `json:"canResume"`
// RunID is the run of an agent working in the background, whose session this is, or 0
// for a session in the terminal: it has no terminal to show, and stops from Autopilot.
RunID int64 `json:"runId"`
// GitHubEvent is the newest thing that came of the item on GitHub while it ran, as the
// inbox learned it, or "": GitHubEventCommit is the commit a review was left on, or "",
// and GitHubEventAt GitHub's time for it, as RFC 3339, or "".
GitHubEvent GitHubEvent `json:"githubEvent"`
GitHubEventCommit string `json:"githubEventCommit"`
GitHubEventAt string `json:"githubEventAt"`
}
Session is one session as the window shows it. Every field is a plain value.
func (Session) FullLabel ¶
FullLabel is Label with the repository's whole name, as in "acme-org/example-repo #7".
func (Session) IsRepo ¶
IsRepo reports a session a repository's launch started, which has no item: no kind, and number 0.
func (Session) Label ¶
Label names what the session works on, as the menu bar and the banners show it: the repository's name and the item's number, as in "example-repo #7", or, for a session a repository's launch started, the repository's name and the session's title, its prompt's name, as in "example-repo · Upgrade dependencies".
type Snapshot ¶
type Snapshot struct {
// Following reports whether the app follows sessions; the window shows none while
// it does not.
Following bool `json:"following"`
Sessions []Session `json:"sessions"`
}
Snapshot is the sessions the window shows: every one still running, and the others launched in the last week, newest first.
type State ¶
type State string
State is what a session is doing, as its agent last reported it.
const ( // StateStarting is a session launched whose agent has not reported it yet. StateStarting State = "starting" // StateWorking is an agent working on its turn. StateWorking State = "working" // StateNeedsApproval is an agent waiting for the user to allow an action. StateNeedsApproval State = "needs_approval" // StateNeedsInput is an agent waiting for the user to answer it. StateNeedsInput State = "needs_input" // StateIdle is an agent that finished its turn and waits for the next message. StateIdle State = "idle" // StateEnded is a session whose agent has quit. It is the only state that ends. StateEnded State = "ended" // StateFailed is an agent that reported an error it could not get past. StateFailed State = "failed" // StateUnknown is a session still running whose agent could not be asked how it is. StateUnknown State = "unknown" )
The states of a session.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes the ledger.
func (*Store) Apply ¶
Apply stores what was observed at now, in one transaction, and returns the sessions it changed. An ended session is left as it ended, and an observation of a session the ledger no longer holds is dropped.
func (*Store) ByRun ¶ added in v0.4.0
ByRun returns the session of the background run runID, or ErrNotFound.
func (*Store) ConversationLive ¶
ConversationLive reports whether a session that has not ended carries on the agent's conversation agentSessionID. It is false for "".
func (*Store) EndedSince ¶
EndedSince returns the sessions the agent named that ended since a time, the last to end first.
func (*Store) Forget ¶
Forget forgets one session that has ended. A session the ledger does not hold is ErrNotFound, and one that has not ended is ErrLive and kept.
func (*Store) Insert ¶
Insert records a session just launched. A session the agent already named is linked at once.
func (*Store) InsertUnlessLive ¶
InsertUnlessLive records r, as Insert does, unless a session that has not ended already carries on r's conversation, in one transaction, so two writers never both follow it. It reports whether it recorded r.
func (*Store) KeptItems ¶ added in v0.4.0
KeptItems returns each inbox item a session was launched for, once, which the inbox's prune of old items keeps while the ledger names it (inbox.ItemKeeper): a record's item_id has no foreign key.
func (*Store) NoteGitHub ¶ added in v0.4.0
NoteGitHub records n on the sessions of its item that ran at n.At: launched by then and not ended before, give or take noteSkew. A session holding a later event keeps it. It reports whether it changed any session; a note with no event or no time changes none.
func (*Store) Prune ¶
Prune forgets, as of now, the sessions that ended more than KeepEnded ago, and each item's ended sessions past its newest KeepPerItem. It returns how many it forgot.
func (*Store) Recent ¶
Recent returns every session that has not ended, and those launched since, newest first.
func (*Store) SetRunState ¶ added in v0.4.0
func (s *Store) SetRunState(ctx context.Context, id string, u RunUpdate, now time.Time) (Change, bool, error)
SetRunState stores at now what a background run says of its session id, and returns the change it made, if it made one. Only a run's session is changed, and only while it hasn't ended: a session ended stays as it ended.
type Usage ¶ added in v0.4.0
type Usage struct {
// Known reports counts read; false, every count is 0.
Known bool `json:"known"`
// FromRun reports counts a background run reported, which its record keeps, rather
// than the agent's files.
FromRun bool `json:"fromRun"`
Input int64 `json:"input"`
Output int64 `json:"output"`
CacheRead int64 `json:"cacheRead"`
CacheWrite int64 `json:"cacheWrite"`
Total int64 `json:"total"`
// Partial reports counts read from only part of the files, which were too long to
// read whole: the session used at least that many.
Partial bool `json:"partial"`
}
Usage is how many tokens an agent session used, read on demand for the session panel: as the agent's own files on this Mac report them, or, for a background run's session, as its run reported them. The four parts add up to Total: Input is the input not read from the cache, CacheRead what was, CacheWrite what was written to it, and Output what the agent wrote, its reasoning included. A run reports what it wrote to the cache within Input, so its CacheWrite is 0.
type UsageReader ¶ added in v0.4.0
UsageReader reads the token counts of one agent's session from the agent's own files on this Mac. It never reaches the network. Each agent's observer package provides one.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher reconciles what the agents report into the ledger: a desktop.Worker that runs while the app is open. It observes only while some session has not ended, reconciles every one when it starts, and wakes at once when a launch records a new one.
func NewWatcher ¶
func NewWatcher(cfg WatcherConfig) *Watcher
NewWatcher returns a Watcher over cfg that has not started.
func (*Watcher) Reconcile ¶
Reconcile asks the observers about every session that has not ended, stores what changed, tells the window, and hands the AttentionSink the sessions that need the user. It returns how long to wait before the next, or 0 to wait to be woken.
type WatcherConfig ¶
type WatcherConfig struct {
Store *Store
// Observers holds each agent's Observer. An agent without one has its sessions left
// as they are.
Observers map[agent.ID]Observer
// Switch is the user's master switch; without it, sessions are always followed.
Switch Switch
// Optional: the moments a session needs the user are handed to Attention.
Attention AttentionSink
// Optional: the item of a session that stops working is handed to Rereader.
Rereader Rereader
// Events hears an event.SessionsUpdated whenever a session changes.
Events event.Sink
// Clock stamps every change; it defaults to the system clock.
Clock clock.Clock
// Home shows home as ~ in the sessions the AttentionSink hears of.
Home string
Logger *slog.Logger
// Tick and Debounce default to DefaultTick and DefaultDebounce.
Tick time.Duration
Debounce time.Duration
// ReviveTick and ReviveWindow default to the ReviveTick and ReviveWindow constants.
ReviveTick time.Duration
ReviveWindow time.Duration
// NewID mints the ID of a session resumed outside the app; it defaults to a random
// UUID.
NewID func() string
}
WatcherConfig holds a Watcher's dependencies. Store is required.
type Words ¶
type Words struct {
// Text is the message, as the agent wrote it, as markdown.
Text string `json:"text"`
// Partial reports that Text is not the whole message: it was cut to MaxWordsRunes, or
// it is the start the ledger keeps, because the agent's own files could not be read.
Partial bool `json:"partial"`
}
Words is what an agent session last said, read in full on demand.
type WordsReader ¶
WordsReader reads the whole last message of one agent's session from the agent's own files on this Mac. It never reaches the network. Each agent's observer package provides one.
type WorktreeAction ¶
type WorktreeAction string
WorktreeAction is what a session's launch did to its item's worktree.
const ( // WorktreeNone is a session in the clone, or one recorded before the action was kept. WorktreeNone WorktreeAction = "" // WorktreeResume reused the item's worktree. WorktreeResume WorktreeAction = "resume" // WorktreeAdopt took over a worktree found on the item's branch somewhere else. WorktreeAdopt WorktreeAction = "adopt" // WorktreeAttach made a worktree again on the item's branch left from an earlier one. WorktreeAttach WorktreeAction = "attach" // WorktreeCreate made a new worktree. WorktreeCreate WorktreeAction = "create" )
What a launch did to give its item a worktree, as the launcher names it.
func (WorktreeAction) Valid ¶
func (a WorktreeAction) Valid() bool
Valid reports whether a is one of the actions, WorktreeNone included.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
observe
|
|
|
claude
Package claude observes Claude Code sessions through `claude agents --json`, which Claude Code documents as the supported way to read session state from outside it, and reads a session's last message from the transcript it keeps.
|
Package claude observes Claude Code sessions through `claude agents --json`, which Claude Code documents as the supported way to read session state from outside it, and reads a session's last message from the transcript it keeps. |
|
codex
Package codex observes OpenAI Codex sessions through the local app-server daemon's JSON-RPC protocol, the one Codex's own IDE and desktop clients use, reached through `codex app-server proxy`.
|
Package codex observes OpenAI Codex sessions through the local app-server daemon's JSON-RPC protocol, the one Codex's own IDE and desktop clients use, reached through `codex app-server proxy`. |