catalog

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 11 Imported by: 0

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

View Source
const (
	StateIdle           = "idle"             // can be continued from here
	StateOpenInTerminal = "open_in_terminal" // follow only
	StateBusy           = "busy"             // aimux is running a turn
	// StateUnavailable: created here, but its first prompt failed before the
	// 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

type BusyReader interface {
	Busy(id string) bool
}

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

func (c *Catalog) DefaultProvider() string

DefaultProvider is NewProvider, or the first provider's name when unset, so a session created here never carries provider ""; "" without providers.

func (*Catalog) Exists

func (c *Catalog) Exists(id string) bool

Exists reports a session aimux knows: one with a file, or one created here. It reads no history scan.

func (*Catalog) File

func (c *Catalog) File(id string) (string, Store)

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

func (c *Catalog) Get(id string) (Entry, bool)

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

func (c *Catalog) ListWith(o history.VisibleOpts, open Open) ([]Entry, error)

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

func (c *Catalog) Lookup(id string) (history.Session, bool)

Lookup is a session's history record from the latest scan, without scanning again.

func (*Catalog) Open

func (c *Catalog) Open() 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

func (c *Catalog) Projects(o history.VisibleOpts, max int) ([]Project, error)

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

func (c *Catalog) Refresh(id string) (Entry, bool)

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

func (c *Catalog) RegistryStatus(id string) string

RegistryStatus is the session's status in its harness's registry ("busy", "idle" or ""), "" when no terminal process holds it.

func (*Catalog) Scan

func (c *Catalog) Scan() ([]history.Session, error)

Scan lists every provider's sessions and remembers the result for Lookup.

func (*Catalog) Searchable

func (c *Catalog) Searchable(id string, automated bool) (string, bool)

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) State

func (c *Catalog) State(id string) string

State is StateOf with a fresh read of the open sessions.

func (*Catalog) StateOf

func (c *Catalog) StateOf(id string, open Open) string

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

func (c *Catalog) TerminalPID(id string) (int, bool)

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

func (c *Catalog) TerminalPIDs() map[string]int

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

type Open map[string]harness.Holder

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 Project

type Project struct {
	Path       string
	Name       string
	LastActive time.Time
}

Project is a folder recent sessions ran in.

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

func ProvidersOf[P any](ps []P, ttl time.Duration) []Provider

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

type Rereader interface {
	Reread(s history.Session) (history.Session, error)
}

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.

Jump to

Keyboard shortcuts

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