Documentation
¶
Overview ¶
Package sessions discovers and defensively parses Codex rollout files.
Codex stores each session as a JSONL rollout file under ~/.codex/sessions/YYYY/MM/DD/. Files may be plain (.jsonl) or zstd-compressed (.jsonl.zst). The JSONL format is Codex's durable, canonical record; SQLite is only an index. cct therefore treats these rollout files as the source of truth and never touches SQLite.
The Codex on-disk format can change. All parsing here is best-effort and defensive: unknown fields are ignored, invalid lines are reported as warnings rather than fatal errors, and a single bad file never aborts a whole scan.
Index ¶
Constants ¶
const ( // FilePrefix is the rollout filename prefix. FilePrefix = "rollout-" // PlainExt is the uncompressed rollout extension. PlainExt = ".jsonl" // CompressedExt is the zstd-compressed rollout extension. CompressedExt = ".jsonl.zst" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ScanOptions ¶
type ScanOptions struct {
// IncludeArchived also scans the archived_sessions/ directory. By default
// (false) only active sessions are scanned.
IncludeArchived bool
// DecompressCompressed, when true, attempts to recover metadata (cwd, thread
// id, preview, ...) from .jsonl.zst rollout files by decompressing their head
// with the external `zstd` tool. It is opt-in and degrades gracefully: when
// `zstd` is not installed or a file cannot be decompressed, the compressed
// file is reported as metadata-unknown exactly as when this is false. The
// compressed files themselves are only read, never modified.
DecompressCompressed bool
}
ScanOptions controls how a Codex home is scanned.
type ScanResult ¶
type ScanResult struct {
Sessions []Session
// Files is the total number of rollout files detected (valid or not).
Files int
// Valid is the number of sessions whose SessionMeta parsed successfully.
Valid int
// Invalid is the number of files that produced no usable SessionMeta.
Invalid int
// Compressed is the number of .jsonl.zst files detected (regardless of whether
// their metadata was recovered via zstd).
Compressed int
// Warnings are scan-level warnings (e.g. unreadable directories).
Warnings []string
}
ScanResult aggregates the outcome of scanning a Codex home for sessions.
func Scan ¶
func Scan(home codexhome.Home, opts ScanOptions) (ScanResult, error)
Scan discovers rollout files under the given Codex home. It walks the active sessions directory (and, if requested, the archived sessions directory), detecting both .jsonl and .jsonl.zst files. Plain files are parsed for metadata; compressed files are detected and, when ScanOptions.DecompressCompressed is set and the external `zstd` tool is available, decompressed read-only to recover their metadata (otherwise reported as metadata-unknown).
Scan is defensive: an unreadable directory or a single unparseable file produces a warning and is otherwise skipped, never aborting the whole scan. Results are sorted by most-recently-updated first.
type Session ¶
type Session struct {
// File location.
Path string // absolute path on this device
RelPath string // path relative to the sessions root (e.g. 2026/06/13/rollout-...jsonl)
FileName string
// File-level facts (always populated).
Compressed bool // true for .jsonl.zst
Archived bool // true if found under archived_sessions/
SizeBytes int64
ModTime time.Time // file modification time; used as updated_at
// Best-effort metadata parsed from the rollout contents.
ThreadID string
CWD string
Originator string
CLIVersion string
Source string // e.g. "cli", "appServer"
ModelProvider string
GitBranch string
GitSHA string
GitOriginURL string
CreatedAt string // SessionMeta timestamp, or derived from filename
FirstUserMessage string
Preview string
// Parsing status.
Parsed bool // true if a SessionMeta line was found and parsed
Warnings []string // non-fatal parsing warnings
}
Session is a single discovered rollout file plus any metadata that could be extracted from it. Metadata fields are best-effort and may be empty when a file is compressed (and zstd-based recovery was unavailable) or when parsing was incomplete.