UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

145 lines • 7.41 kB
import { Container, type TuiMouseDispatchResult, type TuiMouseEvent } from "@earendil-works/pi-tui"; /** * Tunables for progressive transcript hydration. * * `tailBudget` is the number of trailing children painted on the first frame: * enough to fill the visible viewport, never the whole persisted history. * `warmChunkSize` bounds how many earlier children are rendered per macrotask * so hydration never blocks input handling. */ export type ProgressiveTranscriptOptions = { readonly tailBudget: number; readonly warmChunkSize: number; readonly requestRender: () => void; /** Line shown above the kept history on the main screen; `hidden` counts the earlier messages left out. */ readonly historyMarker?: (hidden: number) => string; }; /** The main-screen marker above kept history, unstyled. */ export declare function defaultHistoryMarker(hidden: number): string; /** Trailing children painted on the first frame; roughly two tall viewports of messages. */ export declare const DEFAULT_TAIL_BUDGET: 60; /** Earlier children warmed per macrotask during background hydration. */ export declare const DEFAULT_WARM_CHUNK_SIZE: 100; /** * A transcript container that paints a bounded, fully-styled tail on its first * frame and warms the earlier history in bounded `setImmediate` chunks. * * Resuming a long session used to Markdown-render every persisted message * before the first paint, so `/resume` blocked for hundreds of milliseconds on * work the user could not see. Children are still the real message and tool * components and are still rendered by their own `render(width)`, so the * visible tail is pixel-identical to the eager path; only the render *order* * changes. Once hydration completes the container behaves exactly like its * `Container` base, which keeps scrolling, history, and full-transcript output * unchanged. */ export declare class ProgressiveTranscriptContainer extends Container { private readonly tailBudget; private readonly warmChunkSize; private readonly requestRender; /** * Index of the first child published to the TUI. It stays at the first * frame's tail boundary until the deferred head is fully warmed, then drops * to zero in one atomic completion repaint. */ private visibleFrom; /** Index of the first child whose render cache is warmed. */ private warmedFrom; private hydrationScheduled; private hydrationGeneration; /** * Deliberately NOT named `disposed`: `Container` keeps a private `disposed` * own-property guard, and a same-named subclass field lands in the same slot, * so setting it before `super.dispose()` would make the base early-return and * silently skip disposing every child. */ private hydrationHalted; /** Width of the last painted frame, reused to warm the head at the real render width. */ private lastRenderWidth; private readonly childRenders; /** Last painted output and frame row of each live child, for rows already in native scrollback. */ private readonly scrolledLiveRows; /** Bumped by `invalidate()` (theme change): every cached render from before is stale. */ private generation; private stablePrefix; private paintedLayout; private readonly historyMarker; /** * First child kept on the main screen. Earlier children stay mounted (and in the session file, * `/tree` and fullscreen) but are not written to the terminal, so resume and full repaints cost * O(kept history) instead of O(session). Moves forward only in steps, see `HISTORY_SLACK`. */ private historyStart; /** Non-spacer children before `start`; `anchor` is the child just before `start` when counted. */ private hiddenMessages; /** Children below this index are not warmed: the main screen will never paint them. */ private hydrationFloor; private readonly childHeights; constructor(options: ProgressiveTranscriptOptions); /** True when every child has been rendered at least once and no work is pending. */ get isFullyHydrated(): boolean; render(width: number): string[]; /** Children `[from, total)`, preceded by the marker line when earlier history is left out. */ private paint; /** * Appends below the window never change the hidden count, and a window move only adds the * children it passed, so this stays O(moved children) unless earlier children were replaced. */ private hiddenMessageCount; /** * Index of the first child kept on the main screen. The kept window holds at least the history * budget of lines and may grow to `HISTORY_SLACK` times it before its top jumps forward, so * ordinary appends never change rows above the screen. */ private keptHistoryStart; /** * Children that moved above the kept window are never painted on the main screen again; their * cached lines (here and inside the component) would otherwise grow with every message of a long * run. Fullscreen and a width or theme change render them again on demand. */ private releaseRenders; private heightOf; /** Drop every cached child render, e.g. after a theme change reached children outside this container. */ invalidateCache(): void; invalidate(): void; handleMouse(event: TuiMouseEvent): TuiMouseDispatchResult | undefined; clear(): void; detachAll(): void; /** * Reuse re-arms hydration. `clear()` and `detachAll()` declare that this * container is being repopulated with new content, so the watermark AND the * teardown halt both have to return to their pre-first-paint state. Resetting * only the watermark left a disposed-then-reused container silently inert: it * painted its bounded tail forever and never warmed the deferred head, because * `scheduleHydration()` and `warmNextChunk()` both early-return on the halt. * * Deliberately not folded into `cancelHydration()`: `dispose()` calls that * immediately after setting the halt, so re-arming there would undo teardown. */ private rearmHydration; dispose(): void; /** * Render children `[from, to)`. A child that reports a render revision is rendered once per * (width, capabilities, theme generation, revision) and its lines are reused afterwards; the * leading run of such children is reused as one joined block while it is unchanged. Children * without a revision (streaming, animating, unknown) render every frame exactly as before. */ private renderRange; /** * The longest leading part of last frame's stable prefix whose children are still the same objects * at the same revisions. While the render revision clock has not moved no revisioned component * changed, so only identities are compared. */ private reusablePrefix; private renderChild; private scheduleHydration; /** * Warm one bounded chunk of the deferred head. Each child is actually rendered * here so its own line cache is populated off the critical path; the eventual * full-history frame then pays for cache hits instead of one burst of Markdown * work. Without this the deferred cost would merely be moved, not spread. */ private warmNextChunk; private cancelHydration; } //# sourceMappingURL=progressive-transcript-container.d.ts.map