/** * The chrome: a banner, a framed composer, and a status line. * * All of it is ordinary slot registrations with no privileged access to the * runner, so a deployment that wants different chrome disables these and * registers its own. * @module dshline/views */ import type { Composer, Role } from '@dshline/renderer'; import type { CardDetail } from './cards.ts'; import type { ActivityWord } from './activity.ts'; import type { AttentionNotice } from './attention.ts'; import type { BusyEnter } from './delivery.ts'; import type { TuiSlotView } from './slots.ts'; import type { GoalReading } from './goals/model.ts'; import type { PendingUserInput } from './steering.ts'; /** What the status line reports; the runner owns the values. */ export interface StatusState { /** Whether the agent is running, which animates the activity word. */ busy: boolean; /** Heartbeat tick, advanced by the runner's timer while busy or compacting. */ tick: number; /** Milliseconds since the current turn started, or undefined when idle. */ elapsedMs: number | undefined; /** Presentation-only semantic phase or tool activity; the base never drops it. */ activityWord: ActivityWord; /** * A transient fact replacing the ready/idle reading while a resumed session's * transcript is still being replayed into the window. Present only during * that replay window, so the status never claims `ready` before the history * the reader asked to reopen is actually on screen. */ replay: string | undefined; /** * Whether a model-free maintenance operation is compacting context while the * agent itself remains idle. This is separate from `busy`: it must not change * what ctrl-c means or claim that a model turn is running. */ compacting?: boolean; /** * The tool calls still awaiting results, when any are outstanding: the newest * one's presentation title, and how many others are running beside it. */ activity: { title: string; others: number; } | undefined; /** * A short-lived emphasis for a consequential state change that just happened, * or undefined when nothing needs attention. * * While it stands it occupies the ordinary activity position, so the reader * sees what changed rather than which tool is running, and it is never drawn * beside the activity title. It is presentation only: an authority — a Harness * event, the applied selection, or the status line itself — already * established the fact, and the notice yields to the busy/ready/compacting * base and to plan or goal modes. */ attention: AttentionNotice | undefined; /** * The route-qualified identity of the live selection — `selection.current`, * the same mutable ref `/model` writes, and the model selected for subsequent * model work. It is deliberately only the selected configuration: the route a * model step in progress has privately captured is Harness execution state * that this public ref cannot prove atomically, so the footer does not claim * it. Route-qualified because two provider routes can advertise the same * model id, and a bare id would make them one reading here; one indivisible * segment, so the body ladder drops or keeps it whole. The banner's * attachment-time identity is deliberately a different fact. */ model: string | undefined; /** Reasoning level, only when it differs from the route's default. */ effort: string | undefined; /** * The attached Session's effective Harness permission: the raw * `permissions.currentValue`, already one whole segment. A configured preset * id, `auto`, or derived `custom` — opaque, so it is painted as-is and never * resolved through the process catalog, which answers what is selectable * rather than what is in force. Undefined when the optional capability or its * projection is absent, which omits the segment entirely. */ permission?: string | undefined; /** * Cumulative session usage, already formatted, or undefined when the reader * has switched it off. Pre-formatted because pricing is not a layout concern: * this module decides where the segment goes and when to give it up, and knows * nothing about tokens costing money. */ usage: string | undefined; /** * Share of the prompt tokens served from the provider's cache, already * formatted as one whole segment, or undefined when there is nothing true to * report. Folded from its own authority rather than from the totals in * {@link StatusState.usage}, so it is not a breakdown of them. * * Convenience information rather than a status fact: it is the first thing * this line gives up, and it is never shortened, because a cut ratio is a * different number rather than a smaller one. */ cacheRead: string | undefined; /** Current context pressure in tokens, when the meter is mounted. */ tokens: number | undefined; /** The model's context window, when the adapter reported one. */ contextWindow: number | undefined; /** How much of a tool card is drawn, cycled with `ctrl-o`. */ detail: CardDetail; /** Active generic Harness work, already formatted as whole count segments. */ work: string | undefined; /** * User input pending on each of Harness's boundary lists. Zero on both, or * undefined, reports nothing. */ pending: PendingUserInput | undefined; /** Current Harness Todo completion count, as one indivisible segment. */ todo: string | undefined; /** Whether plan mode is in force, so the agent will propose rather than act. */ plan: boolean; /** One whole goal state/progress segment; `/goal` owns objective inspection. */ goal: GoalReading | undefined; } /** * Project untrusted text to characters whose width a terminal cannot draw wider * than the model counts. * * `displayWidth` follows East Asian Width with Ambiguous code points measured * narrow. A terminal in ambiguous-width mode draws them two columns wide, so * untrusted text carrying one and placed into width-critical chrome — the * composer's frame label above all — makes the measured row shorter than the * drawn one, and the border wraps a physical row the redraw arithmetic never * counts; the stale border then survives every erase. The invariant here is * one-directional: the terminal must not draw MORE than the model counts. * Drawing less only shortens the row, which is safe. * * The alternative, treating every East Asian Ambiguous code point as two columns * globally, would move geometry for every terminal that keeps them narrow and for * the box drawing and punctuation the chrome cannot give up. So the projection * is per code point and only where the width is in doubt: an Ambiguous letter is * kept when its canonical decomposition is stable (`café` renders as `cafe` + * U+0301), and a narrow script no terminal widens is kept whole. A code point * that is Ambiguous with no stable decomposition, a text-default pictograph a * terminal may draw as a picture, a format character whose advance the renderer * deliberately leaves measured one, and the multi-code-point sequences no * per-code-point rule can see — a keycap, a VS15/VS16 presentation, a ZWJ * sequence, a skin-tone modifier — are projected to `placeholder`. * * The label is composed with NFC first, so a canonically decomposed Hangul * syllable is drawn as its single wide syllable rather than as a run of Jamo * whose widths terminals disagree about. The projection is LOSSY and not * injective; identity survives because the committed banner prints the full, * unprojected workspace name, and this frame's right title is the only consumer. * @param text - plain text; the caller has already neutralized controls. * @param placeholder - the width-stable character substituted one for one. * @returns text the model can hold to a bounded number of physical cells. */ export declare function widthStableLabel(text: string, placeholder?: string): string; /** * What the composer frame should say about the reader's shell, as two facts. * * Deliberately one object with two fields rather than two callbacks: they are two * answers to ONE question — which mode is the input surface in — and a frame that * has to combine them has to combine them somewhere. Doing it here means the * precedence is written down once, next to the frame it affects, and cannot * depend on the order two callbacks happened to be called in. */ export interface ComposerShellState { /** * A submitted foreground human shell operation currently owns shell interaction. * * That is an ownership claim, and it is the same claim `ctrl-c` acts on: while * this is true an interrupt belongs to the shell rather than to the model, an * overlay, or a quit. */ readonly shellActive: boolean; /** * The draft being edited will be executed locally if it is submitted. * * True from the moment the first meaningful `!` is typed, with nothing running * and nothing submitted — the state a fast command would otherwise never be * seen in. It says what ENTER WILL DO, which is not a claim about the text's * appearance: the draft itself stays ordinary editable input. */ readonly shellInput: boolean; } /** * The framed input line. * * The cursor is reported relative to this view because the frame means the * composer is no longer the region's last row, and the runner should not have to * know how tall a border is. * @param composer - the buffer being edited. * @param workspace - session workspace, whose basename titles the frame. * @param rowsBelow - fixed live rows the composer must leave beneath itself. * @param hint - what the empty composer should say about right now. Read per * paint, because both halves of it change while the frame stands. The default * is the idle answer, which is what a caller with no agent to ask — every * layout test here — is entitled to. * @param shell - what the reader's shell is doing, as a presentation fact. Read * per paint and presentation only: the runner owns both fields, and this view * never learns what a shell gesture is, what runs one, or what it will print. * Defaults to "neither", so a caller with no shell at all is unaffected. * @returns the slot view. */ export declare function createComposerView(composer: Composer, workspace: string, rowsBelow?: () => number, hint?: () => ComposerHint, shell?: () => ComposerShellState): TuiSlotView; /** What the empty composer's hint answers about right now. */ export interface ComposerHint { /** Whether a turn is in flight, which is what changes the answer. */ readonly busy: boolean; /** What plain `enter` means while one is. */ readonly busyEnter: BusyEnter; /** Unsent session-scoped image count, when any are staged. */ readonly images?: number; /** Unsent session-scoped generic file count, when any are staged. */ readonly files?: number; /** Whether this profile provides the optional human-shell capability. */ readonly shell?: boolean; } /** * The empty composer's hint, as ONE row that always fits. * * Three questions, answered in the order they are asked: can I type here (the * prompt, which never goes), what does enter do right now (the first segment), * and how do I find more (the second, idle only). * * This is presentation and nothing else. It is produced from the agent's state * at paint time and handed straight to the frame, so it is never in the buffer, * the history, the undo stacks, a submission, or a completion's input — the * empty branch that draws it cannot reach any of those. * * **Whole segments, and exactly one row.** Both halves of that matter, and the * second is the one that used to be wrong. Segments shed by the status line's * rule — `› ask anything · / me` reads as a rendering fault, not as help — but * the older code fitted this text with `chunkToWidth`, which WRAPS: below * nineteen columns the empty composer already drew five rows instead of four, * and on a short terminal that pushed the live region past the screen, where * rows that have scrolled off can neither be reached nor erased. The empty * branch was the one view in the region that spent none of its own budget, and * a longer hint would have moved that cliff into ordinary split-pane widths. So * the ladder returns a single row by construction, and the frame is handed one. * * Nothing here advertises `ctrl-enter`. It is decodable only where the terminal * implements an enhanced encoding, is byte-identical to `enter` everywhere else, * and cannot be probed for — so naming it would tell most readers to press a key * that silently does the other thing. `docs/usage.md` teaches it instead, which * is the same call this interface already made about `shift-enter`. * @param hint - whether a turn is running, and what enter means while one is. * @param inner - the framed composer's content width, from {@link composerInner}. * The narrow unframed fallback does not call this helper. * @returns one row, prompt included, painted and ready for the frame. */ export declare function composerHintRow(hint: ComposerHint, inner: number): string; /** * Display columns of the composer's content area, including its gutter. * * The width is shared by the view that draws the cursor and the router that moves * it. Below the frame floor it becomes the physical terminal width, because the * unframed fallback has no border cells to subtract. * @param columns - the terminal's current width. * @returns the content width the composer draws and moves within. */ export declare function composerInner(columns: number): number; /** * The gutter preceding each logical line of the composer. * * Line zero carries the prompt; continuation lines an indent of the same width, * so the wrapped text lines up under the prompt. The optional terminal width is * used by the unframed narrow fallback, where the gutter itself may not fit. * @param line - zero-based logical line index. * @param columns - the terminal's current width, when the gutter must be bounded. * @returns the line's leading gutter. */ export declare function composerGutter(line: number, columns?: number): string; /** * Colour for a context reading: quiet until the window is most of the way full, * then warning, then alarm — so the number is ignorable until it matters. * @param tokens - current pressure. * @param window - the model's context window, when known. * @returns the role to apply. */ export declare function pressureStyle(tokens: number, window: number | undefined): Role; /** * A bar for context pressure, or nothing when there is nothing to report. * * Measured in eighths of a cell rather than whole cells, which is what makes it * appear at all. A DeepSeek window is a million tokens: in whole cells the first one * fills at 12.5%, so a bar drawn that way stayed invisible through every session * anyone really has — and a feature nobody ever sees is indistinguishable from one * that is broken. In eighths the same eight columns resolve to 64 steps. * * The scale stays strictly linear — a curve would fill sooner and would misreport * proportion — with one rule at each end, both of the same kind: never show a state * the reader has not reached. Any use at all rounds UP to the first visible mark, * because a bar reading empty while the window is in use is the failure this * function exists to avoid. The fill is otherwise rounded DOWN, so the bar is not * full until the window is. * * Nothing is drawn before the first token, when there is genuinely nothing to see. * @param tokens - current pressure. * @param window - the model's context window, when known. * @param cells - width of the bar in columns; the status line's is the default. * @returns the styled bar, or undefined when it would carry no information. */ export declare function pressureBar(tokens: number, window: number | undefined, cells?: number): string | undefined; /** * The status line under the composer. * @param state - a getter for the current values, read at render time. * @returns the slot view. */ export declare function createStatusView(state: () => StatusState): TuiSlotView; /** * The opening banner, committed once above the live region rather than * registered as a slot: it belongs to scrollback, not to the redrawn area. * @param workspace - the session workspace. * @param model - provider route and model id, when a selection exists. * @param version - this bundle's version. * @param columns - the terminal's current width. * @returns lines to commit. */ export declare function bannerLines(workspace: string, model: string | undefined, version: string, columns: number): string[]; //# sourceMappingURL=views.d.ts.map