/** * Reading Harness's preset roster and one preset's composition, on demand. * * One pass reads the whole browser: the roster (`list()`), the active * session's actual preset (from the `agentPreset` Session projection Harness * maintains), the default a new session would get (`defaultId`), and the * composition of whichever preset is currently being BROWSED — which starts as * the session's own preset but can move without touching the session, so a * declaration's rows can be inspected before anything is switched. Between * passes this class holds a rendered snapshot and nothing else, the same * discipline `connect/catalog.ts` keeps: no preset list, no composition cache, * and no session mirror to fall out of date. `list()` and `readDocument()` are * unmemoized on the Harness side for exactly this reason — a roster is a live * set of declarations, and holding a private copy of it is how a frontend * disagrees with a composition someone just edited outside it. * @module dshline/plugins/catalog */ import type { CompositionTree } from './composition.ts'; import type { PluginsSeams, PluginsSessionFacts } from './harness.ts'; import type { HostCapabilities } from './health.ts'; import type { PresetRow } from './model.ts'; /** Which of the two optional seams this deployment mounts, joined with what the roster allows. */ export interface PluginsCapabilities { /** Whether `ctx.get('agentPresets')` is mounted at all. */ readonly agentPresets: boolean; /** Whether `ctx.get('settings')` is mounted, needed to write the default. */ readonly settings: boolean; /** Whether `ctx.get('configEditor')` is mounted, needed to edit a composition. */ readonly configEditor: boolean; } /** One preset's composition, as the browser currently reads it. */ export type BrowsedComposition = /** Parsed successfully. */ { readonly kind: 'rows'; readonly presetId: string; readonly tree: Extract; } /** The preset's file could not be read or parsed as an entry list. */ | { readonly kind: 'broken'; readonly presetId: string; readonly reason: string; }; /** What one gathering pass produced. */ export type PluginsState = /** The first read has not landed yet. */ { readonly kind: 'loading'; } /** This profile mounts no `agentPresets` seam; there is nothing to browse. */ | { readonly kind: 'unavailable'; readonly message: string; } /** Harness could not answer. */ | { readonly kind: 'failed'; readonly message: string; } /** A complete reading. */ | { readonly kind: 'ready'; readonly capabilities: PluginsCapabilities; readonly presets: readonly PresetRow[]; readonly defaultId: string; readonly sessionPresetId: string | undefined; readonly blank: boolean; readonly browsing: BrowsedComposition; /** * What the Host's own capability registries report, for the rows whose * backing can be proven. Read per pass, never held — see `health.ts`. */ readonly host: HostCapabilities; }; /** What the catalog needs from its owner. */ export interface PluginsCatalogSpec { /** The Harness seams to read. */ readonly seams: PluginsSeams; /** * Read the Host's capability registries. A function, not a snapshot: a * provider can register while the browser is open, and a pass that reused * an old list would keep reporting a row as unbacked after its backing * arrived. */ readonly host: () => HostCapabilities; /** The active agent's scope context, for `composedPreset`. */ readonly agentCtx: object; /** * Read the active session's current projected facts. A live accessor, not a * snapshot taken once at construction: the session this agent runs keeps * growing while `/plugins` may stay open across a `ctrl-r` refresh, so a * stale copy could go on reporting a session as blank after it had already * started. */ readonly session: () => PluginsSessionFacts; /** Redraw after a pass lands. */ readonly invalidate: () => void; } /** Reads Harness's preset roster and one preset's composition, on demand. */ export declare class PluginsCatalog { private readonly spec; private current; private generation; private disposed; private browsingOverride; /** * @param spec - the seams, agent, and session to read, and the redraw to call. */ constructor(spec: PluginsCatalogSpec); /** The most recent complete reading, or what is standing in for one. */ state(): PluginsState; /** * Browse a different preset's composition without touching the session. * * This is how a system preset gets copied and then edited in the same * browser session: the copy changes what a NEW preset id resolves to, and * this is what points the browser at it, entirely independent of whether * the active session ever recomposes. * @param presetId - the preset to browse from the next pass on. */ browse(presetId: string): void; /** * Start a fresh pass over the roster and the browsed preset's composition. * * Never awaited by the caller, matching `connect/catalog.ts`: the browser * is already on screen, and a read that has not landed shows the previous * reading rather than a blank frame. */ refresh(): void; /** Abandon in-flight passes; their results would repaint a closed browser. */ dispose(): void; /** * Adopt a pass's result when it is still the newest one. * @param generation - the pass's stamp. * @param next - what it read. */ private settle; /** * Read the roster and one preset's composition once, and join them. * @returns the complete reading. */ private gather; /** * Read and parse one preset's composition, reporting a broken read rather * than throwing out of the pass. * * The roster's own `broken` is authoritative and checked FIRST: if Harness * already knows this preset cannot be mounted, that reason is reported * as-is, without dshline's own parser getting a vote — a declaration this * parser happens to accept is not proof of health, only that this module can * make presentational sense of it. Harness decides preset health; this only * decides what a healthy declaration's rows look like. * @param agentPresets - the preset seam. * @param presetId - the preset to read. * @param rosterEntry - this preset's own roster row, when it is still listed. * @returns the browsed composition, parsed or broken. */ private readComposition; } /** * A message for a failure, without leaking an object's shape into the UI. * @param error - whatever was thrown. * @returns the sentence to show. */ export declare function messageOf(error: unknown): string; //# sourceMappingURL=catalog.d.ts.map