Documentation
¶
Overview ¶
Package sessions finds the coding-agent sessions recorded for a repository on this machine and maps each into the normalised session.Graph.
Claude Code, Codex and Cursor sessions are read from their stores in the home directory; Entire sessions from the checkpoint branch in the clone. Each vendor's parser lives in its own package; this one only decides which stores to read and which trees are trustworthy enough to return.
Index ¶
- Constants
- Variables
- func Fuller(a, b Session) bool
- func HasTranscript(graph *session.Graph) bool
- func HoldMappings() (release func())
- func IsGenerationRun(graph *session.Graph) bool
- func Load(ctx context.Context, dir string, opts Options) ([]Session, Report, error)
- func Map(s collector.Session) (*session.Graph, []string, error)
- func ParseSource(name string) (vendors.Slug, error)
- func Root(graph *session.Graph) *session.Session
- func SetCheckpointCacheLimit(limit int64)
- func SetMapCacheLimit(limit int64)
- func SetTailCacheLimit(limit int64)
- func WithBackground(ctx context.Context) context.Context
- type Checkpoints
- func (c *Checkpoints) Close()
- func (c *Checkpoints) Load(ctx context.Context, id string) ([]Session, []Failure, error)
- func (c *Checkpoints) Located(ctx context.Context, ids []string) (map[string]bool, error)
- func (c *Checkpoints) Sessions(ctx context.Context, ids []string) (map[string][]string, error)
- type Discovery
- func (d *Discovery) Checkpoints(ctx context.Context) (*Checkpoints, error)
- func (d *Discovery) Fingerprint() (string, bool)
- func (d *Discovery) Load(ctx context.Context) ([]Session, Report, error)
- func (d *Discovery) LoadReusing(ctx context.Context, reuse Reuse) ([]Session, Report, error)
- func (d *Discovery) ShareRepo(repo *gitlocal.Repo)
- func (d *Discovery) Worktrees() []string
- type Failure
- type Options
- type Report
- type Reuse
- type Session
Constants ¶
const BackgroundParallel = 2
BackgroundParallel is how many sessions a background pass decodes at once. A pass is not latency-sensitive, so it trades speed for memory.
const DefaultCheckpointCacheBytes = 64 << 20
DefaultCheckpointCacheBytes bounds the estimated memory (graphBytes) of the mapped sessions the checkpoint cache keeps, the same measure and size as DefaultMapCacheBytes. The estimate is closer to a lower bound than to the heap, so the cache's resident cost is somewhat above this.
const DefaultDecodeBudgetBytes = 256 << 20
DefaultDecodeBudgetBytes bounds the transcript bytes decoded at once across the process. A decode holds the whole transcript and its decoded lines, so this is a few times its resident cost. Sessions wait for budget; one larger than the whole budget runs alone. It sits beside DefaultMapCacheBytes, which bounds what is kept after decoding.
const DefaultMapCacheBytes = 64 << 20
DefaultMapCacheBytes bounds the estimated memory of the mapped graphs Map keeps (graphBytes). A graph takes about a sixth of its transcript's size, so this holds the graphs of several hundred MB of transcripts.
const DefaultTailCacheBytes = 64 << 20
DefaultTailCacheBytes bounds the estimated memory of the decoded lines Map keeps so it can read only what a transcript appended. Kept Claude Code lines take about a third of their transcript's size, so this holds the lines of a 150 MB transcript, the largest seen growing.
const Entire vendors.Slug = "entire"
Entire is the source slug of sessions read from Entire checkpoints. It is a recorder rather than an agent, so vendors does not list it; Session.Vendor names the agent that ran.
const GenerationRunMarker = "<!-- baum:generation-run -->"
GenerationRunMarker starts the prompt of every agent run baum itself starts to generate a review. Such a run is recorded in the same stores as the developer's own sessions, in a worktree of the same clone, so the marker is what keeps it from being taken as evidence about the pull request it reviews.
const HeldMapCacheBytes = 256 << 20
HeldMapCacheBytes is the cache's limit while HoldMappings holds it.
Variables ¶
var ErrUnbalanced = errors.New("mapper did not account for every record")
ErrUnbalanced reports a tree whose mapper could not account for every record it read. Such a tree understates what happened and is not returned.
var Sources = []vendors.Slug{vendors.ClaudeCode, vendors.Codex, vendors.Cursor, Entire}
Sources lists every source Load reads, in the order it reads them.
Functions ¶
func Fuller ¶
Fuller reports whether a is a better reading of a session than b: one with a transcript over one without, and otherwise the one written later.
func HasTranscript ¶
HasTranscript reports whether a graph records anything the agent did: a model call, an assistant message or a tool use. A snapshot Entire wrote with only its metadata and the prompt has none.
func HoldMappings ¶ added in v0.2.0
func HoldMappings() (release func())
HoldMappings lets the cache keep up to HeldMapCacheBytes until release is called, then trims it back to its limit. A caller about to load the same sessions several times in a row, such as a background pass refreshing several pull requests of one clone, holds it so each session is decoded once in the pass, at the cost of that memory for the pass's duration.
func IsGenerationRun ¶
IsGenerationRun reports whether graph is one of baum's own generation runs: a user input of its top-level session begins with GenerationRunMarker. A prompt that only mentions the marker further in does not count.
func Load ¶
Load returns every session recorded for the git repository containing dir, mapped and ordered by modification time.
A session belongs to the repository when it was recorded in any of the clone's working trees, the main checkout or a linked worktree, whichever of them dir is in; git's own list of worktrees says which those are. Each Entire session is returned once, from the newest checkpoint that recorded it, and not at all when the agent's own store holds it.
func Map ¶
Map turns one discovered session into its graph. The notes are the mapper's remarks; an error means the tree must not be used.
A session whose files have not changed since it was last mapped is not read again: the graph comes from a process-wide cache (see mapCache) and is shared with every other caller that mapped the same files, so callers must not change it.
func ParseSource ¶
ParseSource accepts a source slug as typed on the command line.
func SetCheckpointCacheLimit ¶ added in v0.2.0
func SetCheckpointCacheLimit(limit int64)
SetCheckpointCacheLimit changes how many estimated bytes of mapped sessions the checkpoint cache keeps; zero or less turns it off and empties it.
func SetMapCacheLimit ¶ added in v0.2.0
func SetMapCacheLimit(limit int64)
SetMapCacheLimit changes the estimated memory of the mapped graphs Map keeps; zero or less turns the cache off and empties it.
func SetTailCacheLimit ¶ added in v0.2.0
func SetTailCacheLimit(limit int64)
SetTailCacheLimit changes the estimated memory of the decoded lines Map keeps; zero or less turns that off and empties it, so every transcript is decoded whole each time it is mapped.
func WithBackground ¶ added in v0.2.0
WithBackground marks ctx as a background pass: loads under it decode at most BackgroundParallel sessions at once. A context value is used because the pass reaches Discovery.Load through several packages that already pass the context down, so no signature changes.
Types ¶
type Checkpoints ¶
type Checkpoints struct {
// contains filtered or unexported fields
}
Checkpoints is the checkpoints of a clone, opened once for several lookups. It reads the per-checkpoint refs (refs/entire/checkpoints/*) and the local checkpoint branch or a remote-tracking copy of it, a checkpoint in both being read from its ref, in a private repository, and never fetches. Close releases it.
func OpenCheckpoints ¶
func OpenCheckpoints(ctx context.Context, dir string) (*Checkpoints, error)
OpenCheckpoints opens the checkpoints of the clone containing dir. It returns nil and no error when the clone has neither checkpoint refs nor a checkpoint branch.
func (*Checkpoints) Close ¶
func (c *Checkpoints) Close()
Close releases the private repository, unless it was shared (Discovery.ShareRepo).
func (*Checkpoints) Load ¶
Load maps the sessions one checkpoint in the clone records, as Load maps an Entire session, with no Since applied. A session that cannot be mapped is a Failure; an error is a checkpoint that could not be read at all.
func (*Checkpoints) Located ¶
Located reports which of ids the clone holds, by canonical id, whether or not its metadata can be read: a checkpoint Sessions leaves out that Located reports is unreadable, and one it does not report is not in the clone.
func (*Checkpoints) Sessions ¶
Sessions returns, for each of ids that is a checkpoint in the clone, keyed by its canonical id (entirecheckpoint.CanonicalID), the ids of the sessions it records, each once, in the order it lists them. It reads checkpoint metadata only. A checkpoint the clone does not hold, or whose metadata cannot be read, is absent from the result.
type Discovery ¶ added in v0.2.0
type Discovery struct {
// contains filtered or unexported fields
}
Discovery is what Load finds before it reads any session: the clone's worktrees, the session files recorded in them and the checkpoint store's branch commit and refs. Finding them reads directories, file metadata and git refs, never a transcript, so a caller can tell from Fingerprint whether anything Load reads changed before paying for it.
func Discover ¶ added in v0.2.0
Discover finds what Load would read for the repository containing dir.
func (*Discovery) Checkpoints ¶ added in v0.2.0
func (d *Discovery) Checkpoints(ctx context.Context) (*Checkpoints, error)
Checkpoints opens the checkpoints of the clone as Discover found them, for several lookups. It returns nil and no error when the clone has neither checkpoint refs nor a checkpoint branch. The caller closes it.
func (*Discovery) Fingerprint ¶ added in v0.2.0
Fingerprint describes everything Load would read: the worktrees, each session file's path, size and modification time (or the hash of generated content), and the Entire store's branch commit and refs. Two discoveries with the same fingerprint load the same sessions. ok is false when a file cannot be described, and nothing should be assumed unchanged.
func (*Discovery) Load ¶ added in v0.2.0
Load maps the discovered sessions and reads the Entire checkpoints, as Load does.
func (*Discovery) LoadReusing ¶ added in v0.2.0
LoadReusing is Load, except that a session whose Key reuse accepts is not mapped: it is returned Unmapped, without its graph or mapper notes (its discovery warnings are kept), and an Entire checkpoint is not read when what Load needs from it is already known. Which sessions are returned, their order and every other field are what Load returns. A nil reuse maps everything.
type Failure ¶
Failure is one session discovery found but could not map. It never costs its siblings: Load returns the sessions it could map alongside these.
type Options ¶
type Options struct {
// PreviousPaths are directories the repository used to live at, so
// sessions recorded there still count.
PreviousPaths []string
// Sources restricts the stores read; empty means Sources.
Sources []vendors.Slug
// Since drops sessions last modified before it.
Since time.Time
// StartedBefore drops sessions their agent's own store says began after
// it. A session whose start discovery does not know (Cursor) is kept,
// and Entire checkpoints are not filtered by it.
StartedBefore time.Time
// SessionIDs, when not empty, keeps only the sessions whose own ID (the
// agent's native session ID, Session.ID) is listed. The others are never
// mapped, and Entire sessions with other IDs are dropped.
SessionIDs []string
// Store overrides, mainly for tests. Empty means the vendor default.
ClaudeProjectsDir string
CodexSessionsDir string
CursorStorePaths []string
}
Options narrows what Load reads. Zero values mean everything.
type Report ¶
type Report struct {
// Skipped are files discovery could not read.
Skipped []model.SkippedFile
// Failures are sessions that were found but did not map.
Failures []Failure
// EntireCommit is the checkpoint branch commit read, empty when the clone
// has none (checkpoints held only in refs/entire/checkpoints/* leave it
// empty).
EntireCommit string
}
Report is what Load dropped along the way.
type Reuse ¶ added in v0.2.0
Reuse tells LoadReusing which sessions it need not map. Given a session's Key, ok says the caller already holds everything it needs from the graph that Key names, and transcript whether that graph has a transcript (HasTranscript). It is called from one goroutine at a time.
type Session ¶
type Session struct {
// Source is the store the session was read from; Vendor the agent that
// ran. They differ for Entire, which records other agents' sessions.
Source vendors.Slug
Vendor string
ID string
// Path is the transcript file, the Cursor store plus composer id, or the
// Entire checkpoint id.
Path string
RepoRoot string
WorktreeRoot string
ModifiedAt time.Time
Graph *session.Graph
// Notes are the mapper's remarks about the tree: a subagent nothing
// spawned, a rollout that could not be read.
Notes []string
// CreatedCommits is independent, durable Git-hook evidence supplied by
// the local resolver. It never changes the mapped transcript graph.
CreatedCommits []string
// Key identifies what the graph is mapped from: the session's files as
// they stood (see mapKey), or the content of the Entire checkpoint it was
// read from and the session's id there. Two sessions with the same Key
// map to the same graph. It is empty when that cannot be described.
Key string
// Unmapped is set on a session LoadReusing did not map because its
// caller already holds what it needs from the graph Key names. Graph is
// then nil, and Transcript says whether that graph has a transcript.
Unmapped bool
Transcript bool
}
Session is one mapped session tree.
func (Session) HasTranscript ¶ added in v0.2.0
HasTranscript reports whether the session's graph records anything the agent did, as HasTranscript does; for an unmapped session, whether the graph its Key names does.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claudetranscript reads Claude Code transcripts as typed, classified lines.
|
Package claudetranscript reads Claude Code transcripts as typed, classified lines. |
|
entire
Package entire finds Entire checkpoints in the user's own clone.
|
Package entire finds Entire checkpoints in the user's own clone. |
|
entirearchive
Package entirearchive reads bounded checkpoint archives independently of Git transport.
|
Package entirearchive reads bounded checkpoint archives independently of Git transport. |
|
Package cursorsession maps Cursor's typed SQLite records into the shared session model.
|
Package cursorsession maps Cursor's typed SQLite records into the shared session model. |
|
Package cursortranscript reads Cursor's global SQLite conversation store as typed records.
|
Package cursortranscript reads Cursor's global SQLite conversation store as typed records. |
|
Package entirecheckpoint reads one Entire checkpoint tree without assigning session-model meaning to its records.
|
Package entirecheckpoint reads one Entire checkpoint tree without assigning session-model meaning to its records. |
|
Package entiresession maps Entire checkpoint snapshots into shared session graphs, delegating native transcripts where a mapper exists.
|
Package entiresession maps Entire checkpoint snapshots into shared session graphs, delegating native transcripts where a mapper exists. |
|
Package prompttext decides what part of a recorded user turn is a prompt somebody actually typed.
|
Package prompttext decides what part of a recorded user turn is a prompt somebody actually typed. |
|
Package session defines the vendor-agnostic session model.
|
Package session defines the vendor-agnostic session model. |
|
Package sessionimages reads retained images from native coding transcripts.
|
Package sessionimages reads retained images from native coding transcripts. |
|
Package sourcepath handles filesystem paths recorded on a machine whose OS may differ from the process reading them.
|
Package sourcepath handles filesystem paths recorded on a machine whose OS may differ from the process reading them. |
|
Package sqliteread reads local SQLite stores that agents keep their session data in — today, Cursor's `state.vscdb` chat store.
|
Package sqliteread reads local SQLite stores that agents keep their session data in — today, Cursor's `state.vscdb` chat store. |
|
Package vendors holds the canonical agent slugs the platform stores and groups by.
|
Package vendors holds the canonical agent slugs the platform stores and groups by. |