Skip to main content

Module session_catalog

Module session_catalog 

Source
Expand description

Past-sessions catalog: the UI-free engine behind the /sessions Past tab.

Everything here is synchronous and pure over injected paths, so callers run it on spawn_blocking (or a plain thread) and never on a draw loop:

  • load_catalog — every session header joined with index.jsonl (cwd / profile / turns / duration). Headers only, never message history.
  • PreviewCache — sidecar cache of first/last user message + true message count, keyed by id + (mtime, bytes), refreshed incrementally.
  • Query / parse_query — free text + power tokens.
  • build_view — noise hiding, facets with counts, sorting; plus day_groups for the day headers.
  • deep_search — cancellable streaming full-text scan of bodies.
  • rename_past_session — rename under the session’s own .lock.

Nothing in this module ever deletes a session (owner decision).

Structs§

Catalog
The loaded catalog. entries is in no particular order — use build_view for display order.
CatalogEntry
One past session as the Past tab sees it.
CatalogPaths
Where the catalog reads and writes. Every path is injectable so tests and benches never touch the real ~/.synaps-cli.
Clock
“Now” plus the zone used for calendar maths.
DateBound
A resolved date token: the local day and its UTC start instant.
DayGroup
A run of consecutive rows sharing a local day.
DeepHit
DeepSearchOptions
DeepSummary
FacetCount
One sidebar row.
FacetSelection
Active facet choices from the sidebar (all None/false = no filter).
Facets
Facet counts. Each group is counted with the query, noise filter and the OTHER groups’ selections applied — never its own — so picking a project still shows how many sessions each other project has.
NoiseCounts
Per-rule counts of hidden entries (“hiding N (sandbox, <3 msgs)”). total counts each entry once even when several rules match.
NoiseReasons
Why an entry is hidden by default. Several can apply at once.
Preview
Cached facts for one session.
PreviewCache
Query
RefreshStats
What a PreviewCache::refresh did.
View
Rows to render plus the sidebar/header numbers.

Enums§

DateKey
DeepEvent
DeepRole
RenameError
Sort
Sort orders. All descending (biggest / newest first).
When
The When facet.

Constants§

DEEP_HIT_CAP
Hard stop: the scan ends once this many hits were delivered.
MIN_MESSAGES
Sessions with fewer messages than this are noise (when the count is known).
PREVIEW_MAX_CHARS
Preview text cap (characters, after whitespace collapse).

Functions§

build_view
Filter, facet and sort. O(n) over the catalog plus the sort; cheap enough to rerun on every keystroke for thousands of entries.
day_groups
Split already-sorted rows into day groups by key (use Sort::date_key). Rows sorted by something else just yield more, smaller groups — callers should skip headers when date_key is None.
deep_search
Scan targets (in the given order — pass the current view order so newest sessions report first) for phrase. Hits and progress stream through on_event on the calling thread; set cancel from anywhere to stop (checked per message). A blank phrase returns immediately. Blocking — run it on spawn_blocking and forward events over a channel.
is_session_id
YYYYMMDD-HHMMSS-<hex> (4+ hex chars) — the shape Session::new mints.
load_catalog
Load every past session header in paths.sessions_dir, joined with paths.index_path. Pure + blocking: run it on spawn_blocking. A missing dir or index is empty, not an error.
model_key
Strip a provider/ prefix: anthropic/claude-opus-4-6 → claude-opus-4-6.
model_label
Short label: claude-opus-4-6 → opus-4-6; others unchanged.
noise_reasons
Noise classification for one entry.
parse_query
Parse a query string. Total: bad tokens become free text.
rename_past_session
Set (Some) or clear (None) the name of past session id in dir. Blocking. Idempotent: setting the current name is Ok without a write.
tilde
$HOME → ~, $HOME/x → ~/x.