Documentation
¶
Overview ¶
Package catalog is this machine's session catalog: every registered provider's sessions joined with their shown title, visibility, provider and live state. The remote API (internal/remoteapi) and the MCP server (internal/sessionmcp) read sessions through it; it knows no HTTP or contract types.
Index ¶
- Constants
- type BusyReader
- type Cache
- type Catalog
- func (c *Catalog) DefaultProvider() string
- func (c *Catalog) Exists(id string) bool
- func (c *Catalog) File(id string) (string, Store)
- func (c *Catalog) Get(id string) (Entry, bool)
- func (c *Catalog) List(o history.VisibleOpts) ([]Entry, error)
- func (c *Catalog) ListWith(o history.VisibleOpts, open Open) ([]Entry, error)
- func (c *Catalog) ListableIDs(o history.VisibleOpts) []string
- func (c *Catalog) Lookup(id string) (history.Session, bool)
- func (c *Catalog) Open() Open
- func (c *Catalog) Projects(o history.VisibleOpts, max int) ([]Project, error)
- func (c *Catalog) Refresh(id string) (Entry, bool)
- func (c *Catalog) RegistryStatus(id string) string
- func (c *Catalog) Scan() ([]history.Session, error)
- func (c *Catalog) Searchable(id string, automated bool) (string, bool)
- func (c *Catalog) State(id string) string
- func (c *Catalog) StateOf(id string, open Open) string
- func (c *Catalog) TerminalPID(id string) (int, bool)
- func (c *Catalog) TerminalPIDs() map[string]int
- type CreatedSession
- type CreatedStore
- type Entry
- type LiveSource
- type Open
- type Project
- type Provider
- type Rereader
- type Store
Constants ¶
const ( StateIdle = "idle" // can be continued from here StateOpenInTerminal = "open_in_terminal" // follow only StateBusy = "busy" // aimux is running a turn // agent wrote a file; nothing to continue. StateUnavailable = "unavailable" )
A session's live state; the remote API sends these values as they are.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BusyReader ¶
BusyReader reports whether aimux is running a turn of a session (the remote API's Broker).
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache holds the latest scan, by session id, for Lookup. The zero value is ready to use.
type Catalog ¶
type Catalog struct {
// Providers are the harnesses listed, in order.
Providers []Provider
// NewProvider is the Provider of sessions created here (Created
// records without a file yet). "": the first provider's name.
NewProvider string
// Busy reports aimux's own running turns. Nil: none.
Busy BusyReader
// Owned reports aimux's own adapter processes, which hold a session in
// a harness's registry without it being open in a terminal.
Owned func(pid int) bool
// Created is the sessions aimux started; they are listed although the
// agent SDK marks them automated. Nil: none.
Created *CreatedStore
// Running reports whether aimux has a run for a session: a created
// session without a file is usable only while it does. Nil: none.
Running func(id string) bool
// Cache keeps the latest scan for Lookup; nil: the Catalog's own.
Cache *Cache
// contains filtered or unexported fields
}
Catalog lists and describes the sessions of the registered providers. Every session listed belongs to the first provider whose store has its file; records a store gives for another provider are dropped.
func (*Catalog) DefaultProvider ¶
DefaultProvider is NewProvider, or the first provider's name when unset, so a session created here never carries provider ""; "" without providers.
func (*Catalog) Exists ¶
Exists reports a session aimux knows: one with a file, or one created here. It reads no history scan.
func (*Catalog) File ¶
File is a session's transcript and the store that has it, the first in order (the first store wins when two providers report the same id); "" and nil when none has.
func (*Catalog) Get ¶
Get is one session, freshly scanned, whatever its visibility: its record, or a session created here that has no file yet (unavailable unless it has a live run). false when the catalog has neither.
func (*Catalog) List ¶
func (c *Catalog) List(o history.VisibleOpts) ([]Entry, error)
List is the sessions a list with options o shows, most recently active first: the scanned sessions Visible admits, then the sessions created here that have no file yet but a live run.
func (*Catalog) ListWith ¶
ListWith is List with the open sessions given (an Open read the caller shares, e.g. with the session state service), so State and Working agree with what the caller derives from the same read.
func (*Catalog) ListableIDs ¶
func (c *Catalog) ListableIDs(o history.VisibleOpts) []string
ListableIDs are the sessions a list with options o shows: the visible scanned sessions, and sessions created here that have a live run. A failed scan leaves only the latter.
func (*Catalog) Lookup ¶
Lookup is a session's history record from the latest scan, without scanning again.
func (*Catalog) Open ¶
Open reads which sessions are open (harness.OpenSessions over every provider's Live). A registry is optional, so an error reads as no session open.
func (*Catalog) Projects ¶
Projects lists the folders of recent sessions a list with options o shows, most recent first, at most max: the recorded working directory (else Project), existing folders only.
func (*Catalog) Refresh ¶
Refresh is Get for one session without a full scan: the record from the last scan, read again by its store (a /rename or a .meta.json title change shows) and put back in the cache. A session the last scan does not have, a store without Reread, or a failed reread fall back to Get.
func (*Catalog) RegistryStatus ¶
RegistryStatus is the session's status in its harness's registry ("busy", "idle" or ""), "" when no terminal process holds it.
func (*Catalog) Searchable ¶
Searchable reports a search hit the user can open and continue, and its provider: not automated (unless aimux created it), and it still has a session file or, created here, a live run.
func (*Catalog) StateOf ¶
StateOf is a session's state given open: busy while aimux runs a turn, open_in_terminal while a terminal holds it, idle otherwise.
func (*Catalog) TerminalPID ¶
TerminalPID is the pid of the terminal process holding the session, by the same rule that makes a session open_in_terminal.
func (*Catalog) TerminalPIDs ¶
TerminalPIDs maps every session open in a terminal to the pid holding it.
type CreatedSession ¶
type CreatedSession struct {
Cwd string `json:"cwd"`
Prompt string `json:"prompt"` // its first message, the title until the agent names it
Created time.Time `json:"created"`
}
CreatedSession is a session started through the remote API.
type CreatedStore ¶
type CreatedStore struct {
Path string
// contains filtered or unexported fields
}
CreatedStore remembers the sessions aimux started, in an owner-only JSON file. The agent SDK marks them automated, which would hide them, and the agent writes a session's file only on its first prompt.
func (*CreatedStore) Add ¶
func (s *CreatedStore) Add(id, cwd, prompt string) error
Add records a new session and saves the store.
func (*CreatedStore) All ¶
func (s *CreatedStore) All() map[string]CreatedSession
All returns every created session by id.
func (*CreatedStore) Get ¶
func (s *CreatedStore) Get(id string) (CreatedSession, bool)
Get returns a created session, if this store has it.
type Entry ¶
type Entry struct {
ID string
Provider string
// Title is the shown title (history.DisplayTitle), or the first
// message of a session created here that has no file yet.
Title string
Project string
Cwd string // the recorded working directory, "" when unknown
LastActive time.Time
State string // one of the State constants
// Working: a terminal process holds the session and its registry
// says busy.
Working bool
// Record is the history record; nil for a session created here that
// has no file yet.
Record *history.Session
}
Entry is one session as the catalog lists it.
type LiveSource ¶
type LiveSource interface {
LiveSessions(ttl time.Duration) harness.LiveSessions
}
LiveSource is a provider that reports which of its sessions a process holds open (provider.LiveSource).
type Open ¶
Open is the sessions a live process that is not aimux's own holds, by session id: one read of every provider's Live.
type Provider ¶
type Provider struct {
Store Store
// Live is the sessions a process of this harness holds open. Nil: none.
Live harness.LiveSessions
}
Provider is one harness the catalog serves: its sessions and the processes holding them open.
func ProvidersOf ¶
ProvidersOf is every provider of ps, in order, that implements Store and LiveSource, its Live read with ttl. Callers pass the registry's providers (provider.Registry Local), so a new harness implements those two and needs no change here. Today that is Claude only; the first is the default (DefaultProvider). The catalog takes them as values so that it does not import the provider registry and everything it builds.
type Rereader ¶
Rereader is a Store that can read one session's record again, as its Sessions would give it now (provider.Claude: history.Reread).
type Store ¶
type Store interface {
harness.SessionStore
// Name is the harness's provider name, the Provider of its sessions.
Name() string
// Sessions lists the harness's sessions; records of another provider
// are left out of the catalog.
Sessions(opts history.DiscoverOpts) ([]history.Session, error)
// ParseTail returns at least the last n turns of the transcript at
// path, reading only the end of the file.
ParseTail(path string, n int) ([]trace.Turn, error)
}
Store is a harness's sessions as the catalog reads them: the harness.SessionStore capability plus the list of its sessions and the latest turns of a transcript. provider.Claude implements it.