/** * Generation-safe reads of the Harness-owned session corpus. * * Listing and exact relationship reads use concrete query-engine services. * Full-text session and event search remain optional backend capabilities. No * persistence scan or frontend index exists here: Harness owns corpus order, * filtering, search ranking, cursor validity, and lineage. * @module dshline/sessions/catalog */ import type { SessionId, SessionSeq } from '@deepseek-ai/dsh-session'; import type { SessionEventRecord, SessionRecord, SessionResultFilter, SessionSearchExecContext, SessionSearchHit, SessionSearchPage, SessionSearchRequest, SessionTitleObservationResult } from '@deepseek-ai/dsh-session-query'; import { type SessionFiltersValue, type SessionWorkspace } from './filters.ts'; import { type SessionNavigationReads } from './navigator.ts'; export { CONTENT_SEARCH_LIMIT, EVENT_CONTEXT_AFTER, EVENT_CONTEXT_BEFORE } from './navigator.ts'; import type { CatalogState, ContentState, EventContextState, EventSearchState, LineageState, SessionDetail, SessionEntry, SessionTitleHint } from './model.ts'; /** * The exact `ctx.sessionQuery` read surface consumed by the Sessions catalog. */ export interface SessionQueryReads extends SessionNavigationReads { /** The complete logical corpus, newest first. */ listSessions(signal?: AbortSignal): Promise; /** The complete matching logical corpus in Harness order. */ filterSessions(filters: readonly SessionResultFilter[], signal?: AbortSignal): Promise; /** * Folded titles and live-preferred headers in first-occurrence id order. * Harness isolates operational failures as per-id rejected settlements; * cancellation rejects the batch with the signal's reason. */ readTitleSnapshots(sessionIds: readonly SessionId[], signal?: AbortSignal): Promise; /** Lightweight per-event records for one session. */ listEvents(sessionId: SessionId): Promise; /** Full-text search across the corpus; an abstract backend surface. */ searchSessions(request: SessionSearchRequest, exec?: SessionSearchExecContext): Promise>; } /** What the catalog needs from its owner. */ export interface SessionCatalogSpec { /** The mounted session-query engine, or undefined in a profile without one. */ readonly query: SessionQueryReads | undefined; /** Redraw after catalog state changes. */ readonly invalidate: () => void; /** * Rows to keep from one listing; omitted, {@link CATALOG_LIMIT} applies. * * A non-negative safe integer. This is internal presentation configuration, * not corpus data, so an unusable value is rejected before any Harness read * rather than coerced by `Math.min`/`slice` into a fractional or `NaN` * truncation count. The same value is validated once for every origin mode. */ readonly limit?: number; /** * The exact corpus scope the `current` workspace filter narrows to. * * An arbitrary scope rather than "this window's directory": `/sessions` * supplies the attached session's own workspace and `/worktrees` supplies * the workspace a reader selected, and both reach the same * `filterSessions` translation. Omitted, nothing narrows by workspace. */ readonly workspace?: SessionWorkspace; /** Current time source; omitted, `Date.now` applies. */ readonly now?: () => number; /** * Optional Harness projection title hints, keyed by the listed record. * * A hint is provisional by contract: it may describe a durable prefix that * predates the current log. The catalog still requests exact titles for * visible rows, but a hit gives the picker something useful before that * request settles. A callback is used instead of a dshline-owned cache so * the projection service remains Harness's authority. */ readonly titleHints?: (record: SessionRecord) => SessionTitleHint | undefined; } /** Maximum rows retained from the authoritative listing corpus. */ export declare const CATALOG_LIMIT = 200; /** Maximum exact title observations requested by one visible-row batch. */ export declare const TITLE_BATCH_SIZE = 20; /** * Maximum exact title observations once a query makes the whole retained title * set relevant. * * Deliberately the presentation cap rather than the visible batch: the pinned * Harness title API repeats a full persistence listing inside every call, so * ten small batches would add ten directory scans. The first visible batch has * already opened the list before a query can arrive; one remaining bounded batch * preserves exact filtering without turning a title search back into repeated * full-corpus enumeration. */ export declare const EXHAUSTIVE_TITLE_BATCH_SIZE = 200; /** The generation-safe data source behind the Sessions browser. */ export declare class SessionCatalog { private readonly spec; private base; private contentState; private readonly navigator; private filterValue; /** * The application-time anchor for the current filter's age windows. * * Captured when the filters are applied and reused by every listing and * content search until the filters change again, so "today" means the same * range in list mode and content mode even when local midnight passes while * the browser stays open. Untouched by query edits or mode switches; only * applying the filters again captures a new anchor. */ private filterAnchor; private readonly details; private readonly detailsInFlight; private listingGeneration; private titleGeneration; private filterGeneration; private searchGeneration; private listingAbort; private titleAbort; /** Exact title ids waiting for a bounded demand-driven batch. */ private titleQueue; /** Whether queued work was made relevant by a local title query. */ private exhaustiveTitlesQueued; /** Ids already queued or being read, so a redraw never duplicates work. */ private readonly titleRequested; /** Ids in the currently running exact-title batch. */ private titleInFlightIds; /** Whether the current batch was queued by an exhaustive local query. */ private titleInFlightExhaustive; private searchAbort; private contentChain; /** * Settled-page counter for the full-text scopes. * * The views use a revision change — not a row count — to notice that a page * landed, because an empty page settles without appending anything. */ private pageRevision; private disposed; /** * The validated listing limit shared by every request and origin mode. * * Resolved once at construction so no listing path can reach * {@link retainListing} with an unusable value. */ private readonly limit; constructor(spec: SessionCatalogSpec); /** The current listing state. */ listing(): CatalogState; /** The active filter value. */ filters(): SessionFiltersValue; /** The optional content search's current state. */ content(): ContentState; /** The within-session event search's current state. */ events(): EventSearchState; /** * @param sessionId - the hit's owning session. * @param seq - the hit's event sequence number. * @returns context only when it belongs to that exact hit. */ eventContext(sessionId: SessionId, seq: SessionSeq): EventContextState; /** * @param sessionId - the currently selected session. * @returns lineage only when it belongs to that selected session. */ lineage(sessionId: SessionId): LineageState; /** * The bounded detail already read for one session. * @param sessionId - the session. * @returns its detail, or undefined until {@link requestDetail} has landed. */ detail(sessionId: SessionId): SessionDetail | undefined; /** * Prioritize exact title observations for rows the reader can see. * * The overlay calls this with the current viewport and selected row. A * non-empty local query asks for the whole retained corpus because an * unresolved title could become a match; an empty query never causes the * remaining 200 rows to be opened just because the browser exists. * The caller's order IS the priority order, and it applies to an id that is * ALREADY QUEUED as much as to a new one. Treating `titleRequested` as final * is what made the row the reader just moved onto wait behind every row they * scrolled past: those rows entered the queue first and nothing ever moved * the reader's actual choice to the front, so a 150-row traversal could put * the selected row 140 cold log reads deep. Re-queueing a queued id costs * nothing — no second read is issued, the id simply leads the next batch. * * An id that is already being read is left alone instead: it is being opened * regardless of where the cursor is, and cancelling a useful batch because * the cursor moved one row would trade a bounded wait for work thrown away. * @param entries - visible or selected entries, in reader priority order. * @param exhaustive - whether unresolved rows outside `entries` matter too. */ prioritizeTitles(entries: readonly SessionEntry[], exhaustive?: boolean): void; /** * Tell the catalog that the local metadata/title query changed. * * A non-empty query keeps unresolved retained titles relevant, including * while its text is edited. Clearing it makes queued exhaustive work no * longer useful; an already-running exhaustive batch is aborted and its ids * become eligible for a later visible request. A visible batch is allowed to * finish because its titles remain useful to the current viewport. * @param query - the new local query text. */ titleQueryChanged(query: string): void; /** Load the unfiltered newest-first listing for backward-compatible callers. */ refresh(): void; /** * Store and apply one filter value to the complete logical corpus. * * A filter change also resigns the active content search: its pages answered * a request with the PREVIOUS clauses, so the retained rows and cursor are * simply discarded rather than left labelled by a request that no longer * exists. The view starts a fresh search under the new clauses. * * The application-time anchor is captured here, so age windows freeze at the * moment the reader applied them and stay comparable across list and content * modes until they are applied again. * @param filters - the complete replacement filter value. */ applyFilters(filters: SessionFiltersValue): void; /** * Re-observe titles for every live projection after a rename. * * A rename appends a log event; every projection that displays this title — * the bounded base listing, the active content-search chain, and any cached * lineage tree — is patched from ONE authoritative batch observation rather * than rebuilt. Nothing stored locally ever claims a title Harness did not * fold, and a projection replaced by a newer request while the batch was in * flight is left to its own generation. */ refreshTitles(): void; /** * Start a fresh cursorless content search under the current filters. * @param text - the query, interpreted by the backend as data. */ search(text: string): void; /** Append the next content page when the stored opaque cursor is still usable. */ loadMoreContent(): void; /** Restart the current content query without replaying its cursor. */ restartContentSearch(): void; /** * @param sessionId - the selected session. * @param text - the backend-interpreted query text. */ searchEvents(sessionId: SessionId, text: string): void; /** Append the next within-session event page. */ loadMoreEvents(): void; /** * @param sessionId - the hit's owning session. * @param seq - the hit's event sequence number. */ requestEventContext(sessionId: SessionId, seq: SessionSeq): void; /** * @param sessionId - the selected session. */ requestLineage(sessionId: SessionId): void; /** * Ask for one session's bounded detail, at most once per session. * @param sessionId - the selected session. */ requestDetail(sessionId: SessionId): void; /** Invalidate and abort every asynchronous tier owned by this catalog. */ dispose(): void; /** * Start a fresh authoritative listing under one filter value. * * The Harness call is chosen by the TRANSLATED CLAUSES, not by whether the * browser's filter value differs from the default. Origin has no Harness * predicate, so an origin-only filter translates to zero clauses and is a * plain listing; `filterSessions([])` would ask the engine to re-derive the * whole corpus under an empty predicate and then have the frontend discard * it down to the same rows. The origin choice still applies below, as it * always did, because {@link retainListing} scans presentation-only. * @param filters - the complete filter value to apply. */ private requestListing; /** Start the next bounded exact-title batch, if demand has queued one. */ private drainTitleQueue; private requestContentPage; private currentContentChain; private now; private stale; } //# sourceMappingURL=catalog.d.ts.map