/** * Grouping the authoritative session corpus by working directory, for as long * as the picker is open. * * One authority, and it is the one that is already shared across terminals: * * ```text * ctx.sessionQuery.listSessions() the logical corpus — a fresh * sessionPersistence.list() merged with this * process's live sessions, newest first * ↓ group by exact header.cwd * worktree rows transient, never persisted * ↓ select one * SessionCatalog { kind: 'cwd', cwd } the same catalog /sessions uses * ``` * * The corpus was chosen over a durable workspace registry deliberately, and * the reason is a property of the adopted Harness generation rather than a * preference. `/worktrees` exists to serve several dshline processes working * in several directories at once, and at this generation the durable * domain-storage stack is single-process by its own documentation: * `dsh-storage-domain` states that memory is authoritative for an open domain * and that `domain/changed` is in-process, so "a second host process observes * no changes"; `dsh-storage-json` states there is "no cross-process write * locking" and that concurrent writers to one unit are last-completion-wins. * A feature whose whole point is several simultaneous terminals cannot be * built on shared mutable state with those properties. Session persistence is * the opposite shape: one artifact per session, one live writer per session, * and a fresh listing on every corpus read — so distinct sessions in distinct * directories are exactly what it already models well. * * The second view is NOT a second session browser. It is the very * `SessionCatalog` `/sessions` uses, scoped to the selected cwd, so corpus * order, title folding, filtering, and cancellation stay in dshline's one * implementation of them. Because a row is DEFINED as "sessions whose header * records exactly this cwd", the count in the first view and the rows in the * second are the same relationship read twice, not two authorities compared. * @module dshline/worktrees/catalog */ import type { SessionCatalogSpec, SessionQueryReads } from '../sessions/catalog.ts'; import type { SessionEntry } from '../sessions/model.ts'; import type { WorktreeListing, WorktreeSelection } from './model.ts'; /** What the catalog needs from its owner. */ export interface WorktreeCatalogSpec { /** The mounted session-query engine, or undefined in a profile without one. */ readonly query: SessionQueryReads | undefined; /** Redraw after catalog state changes. */ readonly invalidate: () => void; /** * The attached session's own `SessionHeader.cwd`, when its header records one. * * Exactly that, and nothing substituted for it. The launch directory is * deliberately NOT a fallback here: a session whose header names no * directory belongs to no group, and marking the group that happens to match * the process's startup cwd would claim the current conversation is rooted * somewhere its own header never said. Undefined means no row is current, * which is the honest answer. * * This is narrower than the attachment's effective workspace (`header.cwd ?? * startup.cwd`), which tools, skills, and the composer correctly keep using * — an operational directory has to resolve to something, while this * presentation fact does not. */ readonly currentCwd?: string; /** Current time source, passed through to the session catalog. */ readonly now?: () => number; /** Optional Harness projection title hints, passed to the nested catalog. */ readonly titleHints?: SessionCatalogSpec['titleHints']; } /** The transient cwd grouping behind the `/worktrees` picker. */ export declare class WorktreeCatalog { private readonly spec; private listingState; private selectedCwd; private sessions; private generation; private abort; private disposed; constructor(spec: WorktreeCatalogSpec); /** The current worktree listing. */ listing(): WorktreeListing; /** * Read the corpus and regroup it. * * One `listSessions()` and nothing else: the whole corpus is needed because * the grouping is over every stored cwd, and a bounded listing would make a * directory's presence depend on how many sessions happen to be newer than * it. No titles are read here — a row's label is derived from its path, so * the batched title observation the session browser pays for is not needed * until a directory is actually opened. */ refresh(): void; /** * Open one directory's sessions, or close the one that is open. * * Selecting starts one `filterSessions` listing and then uses the same * demand-driven title hydration as `/sessions`; it does not open every row in * the selected directory. Selecting a different directory abandons the * previous catalog rather than keeping both alive: its results would repaint a * view that has moved on. * @param cwd - the stored cwd to open, or undefined to go back. */ select(cwd: string | undefined): void; /** * Everything the second view draws, or undefined when nothing is open. * * The row is re-read from the current listing so a refresh that landed * while a directory was open cannot leave a stale count on screen. A * selected cwd the listing no longer holds keeps a synthesized row with no * sessions rather than closing the view: the reader is standing in a place * they chose, and `+ New session` there is still exactly as valid — the * directory is only ever used as the new session's cwd, which Harness * validates itself. * @returns the selection, including a listing state of its own. */ selection(): WorktreeSelection | undefined; /** * Prioritize exact titles for the selected directory's current session rows. * * The second view deliberately has no title query, so this forwards only the * visible/selected entries and never creates an exhaustive title pass. The * nested catalog remains the sole scheduler. * @param entries - the session rows currently useful to the view. */ prioritizeTitles(entries: readonly SessionEntry[]): void; /** Abandon every in-flight read; their results would repaint a closed view. */ dispose(): void; /** * The listed row for one cwd, or a fresh-directory stand-in. * @param cwd - the selected cwd. * @returns the row to draw. */ private row; /** * Whether a read has been superseded or the catalog is gone. * @param generation - the read's own generation. * @returns whether its result should be dropped. */ private stale; } //# sourceMappingURL=catalog.d.ts.map