/** * The window: one terminal, and however many sessions are opened in it. * * This split did not have to exist while a launch drove exactly one session for * the life of the process — the plugin fiber and the session were the same * lifetime, so `ctx.effect` was the right owner for everything. `/sessions` can * retire one agent and attach another, which separates the two: * * ``` * window terminal, key routing, model route, reader preferences * ↓ attaches * attachment one Agent, its log projection, its adapters, its views * ``` * * Key routing in particular belongs here. `ctrl-d` must quit from everywhere — * including the session browser that runs before any agent exists, and the gap * between two attachments where no session owns input — and only something * outliving the session can promise that. The previous launch picker had to * re-implement quitting, painting, and key reading precisely because there was * nothing above it to inherit them from. * @module dshline/window */ import type { Context } from '@deepseek-ai/cordis'; import type { Agent, ModelSelectionRef, ResumeAgentOptions } from '@deepseek-ai/dsh-agent'; import type { LlmModelReasoningInfo, ModelModality } from '@deepseek-ai/dsh-llm'; import type { ColorDepth, Key, Palette, Terminal } from '@dshline/renderer'; import type { BusyEnter } from './delivery.ts'; import type { DshlineSettings, PreferenceSetting } from './settings.ts'; import type { CardDetail } from './cards.ts'; import type { LocalCommandChoice } from './local-commands.ts'; import { ModelCompletionCatalog } from './model-completion.ts'; import type { SetupOutcome } from './setup/index.ts'; import type { AttachTarget } from './sessions/reopen.ts'; import type { TuiStartupOptions } from './startup.ts'; import type { PeakWindow, PricingTable, UsageMode } from './usage.ts'; /** * Mutable presentation preferences that outlive one session. * * The reader's settings are not facts about a session: reopening one should not * silently put the usage meter back to cost or re-expand tool cards they had * folded away. The model route is not here because it already has an owner — * {@link ModelSelectionRef} — which the agent reads per step. */ export interface WindowPrefs { /** What the status line reports. */ usageMode: UsageMode; /** Whether the persistent live timing panel is shown. */ timing: boolean; /** How much of a tool card is drawn. */ cardDetail: CardDetail; /** Whether model reasoning is shown in this terminal window. */ reasoningVisible: boolean; /** * What plain `enter` means while a turn is running. * * The one pref here with an authority behind it. It is seeded from the * `dshline` settings namespace and re-seeded from its change feed, so a choice * made in `settings.yaml` or by another surface arrives here — but the live * value is still held in the window, for the reason the palette is: a profile * that mounts no settings provider must still be able to change it for this * process, and reading the resolved section per submission would silently * refuse that. */ busyEnter: BusyEnter; } /** * Model metadata resolved once per selection, for the views that read it. * * Held on the window rather than per session because it describes the ROUTE, and * the route survives reopening a session. One resolve answers three questions: * the context bar's denominator, what `/reasoning` may offer, and whether the * status line should name the level at all. */ export interface ModelInfo { /** The model's context window, when the adapter reported one. */ contextWindow: number | undefined; /** The route's reasoning capability, when it has one. */ reasoning: LlmModelReasoningInfo | undefined; /** Accepted request modalities; undefined means the adapter does not know. */ inputModalities: readonly ModelModality[] | undefined; } /** What a deployment configured, gathered before the window exists. */ export interface WindowOptions { /** Rates for the usage meter, already validated. */ readonly pricing: PricingTable; /** When those rates charge the standard price. */ readonly peakHours: readonly PeakWindow[]; /** Version reported in each attachment's banner. */ readonly version: string; /** The settings namespace this frontend registered; the authority for its preferences. */ readonly settings: DshlineSettings; } /** One terminal, and the state every session opened in it shares. */ export interface Window { /** Context with the slot registry and the harness services. */ readonly ctx: Context; /** The terminal this window owns. */ readonly terminal: Terminal; /** Emit terminal BEL when the live reader preference permits it. */ readonly bell: () => void; /** The launcher's exit request, when it provided one. */ readonly exit: ((code: number) => void) | undefined; /** This invocation's parsed arguments. */ readonly startup: TuiStartupOptions; /** Rates for the usage meter, already validated. */ readonly pricing: PricingTable; /** When those rates charge the standard price. */ readonly peakHours: readonly PeakWindow[]; /** Version reported in each attachment's banner. */ readonly version: string; /** * The live model selection. `current` is the selected route; Harness's * `installModelSelection` captures it when a step's `system-prompt/assemble` * starts, publishes it into `assembled` after the downstream assembly * returns, and routes that step's request from `assembled`. */ readonly selection: ModelSelectionRef; /** Metadata for that route, refreshed when it changes. */ readonly modelInfo: ModelInfo; /** * The `/model` argument's completion values. * * A derived snapshot of the Harness LLM registry and the settings its * adapters read, so it belongs to the WINDOW: a `/sessions` switch changes * neither input, and rebuilding it per attachment would re-read every * provider for nothing. One catalog is created with the window and disposed * with it; a Harness event discards the snapshot and the next call rebuilds * it, so this is never the authority on what a route offers. * @returns each route and model, in the order the picker lists them. */ readonly modelCompletionValues: () => Promise; /** Reader preferences that survive reopening a session. */ readonly prefs: WindowPrefs; /** The theme facet, for reading the current choice and storing a new one. */ readonly themeSettings: PreferenceSetting; /** The busy-`enter` facet, for storing a choice the window already applied. */ readonly busyEnterSettings: PreferenceSetting; /** What this terminal can actually show, resolved once when it opened. */ readonly colorDepth: ColorDepth; /** * The palette in force. * * This is PRESENTATION state — what the renderer is drawing with. The chosen * theme itself has one authority, {@link Window.themeSettings}, and the two * agree except in the one documented case: a switch whose write failed has * already changed the terminal, and is not put back. `/theme` reports that * rather than hiding it, and picking the same theme again retries the write. */ readonly palette: () => Palette; /** * Install a palette for this window. * * Replaces rather than stacks: the previous one is released first, so a * reader trying five themes leaves one live registration and not five. * @param next - the palette to make current. */ readonly setPalette: (next: Palette) => void; /** * The launch task, consumed by the first attachment. * * Cleared once submitted: a session reopened from inside the window must not * replay the command line's opening prompt. */ pendingTask: string | undefined; /** * Repaint the live region. * * Requests coalesce: however many arrive in one event-loop turn, one paint * runs at the turn's end and reads the state as it then stands, so a burst * costs one frame instead of one frame per request. See * {@link RedrawScheduler} for why that stays inside the input's own turn. */ readonly draw: () => void; /** * Repaint the live region synchronously, outside the turn's coalescing. * * The one frame that cannot wait for the check phase: a resumed session's * transcript replay takes one stable snapshot of the Session it already owns * and then projects the whole historical log in one event-loop block. That * projection is synchronous but can be slow on a large transcript, so a * coalesced paint scheduled around it has no guaranteed slot of its own. This * repaint is issued at the moment the replay begins — the composer and status * are on screen before the projection, and stay behind the flood when it * commits. */ readonly paintNow: () => void; /** Write finished rows into the terminal's own scrollback. */ readonly commit: (lines: readonly string[]) => void; /** Clear the display, then redraw the live region into the emptied screen. */ readonly clear: () => void; /** Re-resolve {@link ModelInfo} after the route changes. */ readonly refreshModelInfo: () => void; /** Route decoded keys to the attached session, or to nothing between two. */ readonly setDispatch: (handler: ((key: Key) => void) | undefined) => void; /** Request process exit through this window's one-shot global boundary. */ readonly requestExit: () => void; /** Install the attached session's cancellation-aware exit handler. */ readonly setExit: (handler: (() => void) | undefined) => void; } /** * Route one decoded key through the window's global quit boundary. * * Kept as the small policy seam under the one terminal subscription: `ctrl-d` * never belongs to an overlay or attachment, while every other key may be * delegated to the current attachment. * @param key - the decoded terminal key. * @param requestExit - the window exit request, possibly attachment-aware. * @param dispatch - the current attachment's key handler, when one exists. * @returns nothing; the chosen handler receives the key synchronously. */ export declare function routeWindowKey(key: Key, requestExit: () => void, dispatch: ((key: Key) => void) | undefined): void; /** * Create the window's one-shot exit request. * * The closure belongs to one Window instance, not to an attachment: an * attachment handler may disappear during the first request, but a later global * `ctrl-d` must not fall through to a second launcher request. * @param appExit - Harness's final shutdown request, when available. * @param attachmentExit - read the current attachment-aware handler. * @returns a one-shot request function for the window's global quit boundary. */ export declare function createWindowExitRequest(appExit: ((code: number) => void) | undefined, attachmentExit: () => (() => void) | undefined): () => void; /** * Create the window's one derived `/model` completion catalog. * * Owned and disposed with the WINDOW, not an attachment: its inputs are the * Harness LLM registry and the settings its adapters read, and a `/sessions` * switch changes neither. Registration and disposal ride the plugin fiber, so * the invalidation subscriptions and the snapshot go away exactly once at * window teardown. It stays reconstructible entirely from Harness. * @param ctx - context carrying the llm registry and the invalidation events. * @returns the catalog the window exposes to every attachment. */ export declare function createModelCompletionCatalog(ctx: Context): ModelCompletionCatalog; /** * Take the terminal and wait for the Loader, before any agent exists. * * The Loader mounts siblings concurrently, so this waits for the whole tree * before an attachment creates an Agent — a row that had not activated yet would * otherwise be missing from the agent's registries. * @param ctx - context with the slot registry available. * @param options - deployment configuration for every attachment. * @returns the window, ready to attach a session. */ export declare function createWindow(ctx: Context, options: WindowOptions): Promise; /** * Route and setup for the next agent this window attaches. * * Read at attach time rather than once, because `/model` writes the selection * and the session opened after it must use what is selected now. * @param w - the window attaching a session. * @returns the per-agent options shared by the create and resume paths. */ export declare function attachOptions(w: Window): Omit; /** * Compose this agent from its resolved Harness preset, when a preset roster * is mounted. * * Three cases, in order: * * 1. Harness's `agentPreset` Session projection names one — it folds the * creation header with every later `agent-preset/selected` — and that * recorded choice always wins. This is every session created since * presets existed here (a new one's header is stamped before `create`; * see `sessions/reopen.ts`), and any session an explicit `/plugins` * switch touched. The projection is the same authority `/plugins` reads * and `AgentPresets.select` writes, so a resume and a switch can never * disagree about which preset a session runs. * 2. Nothing is recorded AND the session has already produced a turn: a * session from before this frontend adopted presets. Resuming it under * TODAY's default would silently rebuild history that was actually * produced under the old flat `dsh-base` composition, so it prefers * {@link LEGACY_SESSION_PRESET} instead — a real preset id, not a * fallback that pretends nothing changed. A non-stock deployment that * ships no usable `standard` falls back to the roster's default and SAYS * so (see {@link legacyPresetId}): refusing the resume outright would * leave that deployment unable to open its own history at all, which * protects a composition record by withholding the transcript it belongs * to. * 3. Nothing is recorded and the session is still blank: there is no * history to protect, so the roster's current default applies, exactly * like any other new session. * * The Agent is passed in rather than read off the context, and it is required. * Harness mints it — including a resumed session's already-reconstructed log — * before calling `setup(agentCtx, agent)`, and that parameter is the only * association the adopted generation publishes: there is no ambient * `Context.agent` to consult, nothing here reconstructs one, and there is no * supported call of `setup` that arrives without an Agent. So this reads the * real session facts off the Agent being composed rather than guessing from * context. * * A profile that mounts no `agentPresets` seam at all leaves this a no-op. * That restores dshline's old flat behavior only for a composition that * never applied dshline's own agent-plane disable list in the first place * (a custom deployment mounting dshline's plugin code over its own already- * flat host plane) — the STOCK `cordis.patch.yml` disables those `dsh-base` * rows unconditionally, so simply removing the `agent-presets` row from an * otherwise-stock dshline composition leaves an agent with no tools at all, * not the old flat set back. * @param agentCtx - the unpublished agent's own scope context. * @param agent - the unpublished Agent being composed, exactly as `setup` * receives it; only its session is read. * @param report - where to say that a legacy session could not be placed on * {@link LEGACY_SESSION_PRESET}; called only after the substitute preset has * actually mounted, so a failed resume never claims to have run under one. * Omitted stays silent, which is what the unit tests and a headless embedder * want. */ export declare function mountAgentPreset(agentCtx: Context, agent: Pick, report?: (lines: readonly string[]) => void): Promise; /** * Offer the guided first run, while no agent is attached. * * Placed here rather than inside an attachment for the same reason * {@link chooseTarget} is: it runs in the gap where the window holds a * terminal and no session owns input, and it is a fact about the WINDOW's * environment — which provider routes exist — not about any session. * * The generation gate runs on EVERY launch, not only when setup would open. * A launch that could send a turn is still unsafe on a Host built for a * different Harness generation: dshline supports only its adopted generation, * and a Host of another one is not guaranteed to provide the APIs dshline * calls after startup, which is not a fact the launch decision can see. The * comparison is the one {@link "./setup/harness.ts"}'s report already trusts, * so the gate and the report cannot disagree; only a confirmed `mismatch` * blocks, and an `unknown` version stays the diagnostic it has always been. * * The condition for the rest is Harness's own registry, the selection this * window already holds, and — only when those look complete — whether Connect * can positively say the selected route's credential is missing. A launch that * can send a turn never sees the flow; one that cannot opens on it rather than * a composer that will fail. There is no first-run marker anywhere: the * question is re-asked from live state every launch, so configuring a working * provider and model is the only thing that stops it appearing, and losing any * part of that is enough to bring it back. * @param w - the window whose input routing the flow borrows. * @returns `continued` when the reader may go on to a session, or `blocked` * when a confirmed generation mismatch forbids one from starting. */ export declare function offerSetup(w: Window): Promise; /** * Ask which session to open, while no agent is attached. * * Runs before the first attachment, and again whenever reopening one failed: * both are moments where the window holds a terminal and no session, and the * useful question is the same one. Nothing for the resume plan to refuse, since * there is no session to leave. * * It needs no keyboard of its own. The window's routing is already installed and * already redraws on `tui/render`, so pushing the overlay paints it and `ctrl-d` * still leaves. * @param w - the window whose input routing the browser borrows. * @returns the chosen resume target, or undefined when the reader cancelled. */ export declare function chooseTarget(w: Window): Promise | undefined>; //# sourceMappingURL=window.d.ts.map