/** * Where the current or most recently measured turn's time went. * * Finished durations come from timestamps carried by the live session events, * not from clock reads taken while drawing. An open turn has no closing event, * so its wall clock and any running tools advance against the current clock; * once they finish, their event timestamps replace that provisional reading. * * The one thing this deliberately does NOT claim is that the parts add up to the * whole. Tool calls in a step run concurrently and reasoning interleaves with * them across steps, so these are overlapping spans: their sum can exceed the * turn, and the difference is not idle time. That is why the bars are scaled * against the LARGEST span rather than against the turn's wall clock. * @module dshline/timing */ import type { AssistantStreamFrame } from '@deepseek-ai/dsh-agent'; import type { SessionEvent } from '@deepseek-ai/dsh-session'; import type { TuiSlotView } from './slots.ts'; /** One measured span within a turn. */ export interface TurnSpan { /** What was running: `reasoning`, `output`, or a tool's name. */ readonly label: string; /** Milliseconds the span covered. */ readonly ms: number; /** Whether at least one call represented by this row is still open. */ readonly running: boolean; /** * Presentation-only reveal fraction for a freshly arrived live span, 0 just * arrived through 1 settled; absent means fully revealed. Derived from the * redraw count, never from a clock, and never written back into a * measurement. */ readonly reveal?: number; } /** A live or finished turn, as the panel draws it. */ export interface TurnTiming { /** The turn's number, as the session log counts it. */ readonly turn: number; /** Wall clock from `turn/start` to the current or closing timestamp. */ readonly totalMs: number; /** Whether the closing `turn/end` has not arrived yet. */ readonly running: boolean; /** Spans worth drawing, longest first. */ readonly spans: readonly TurnSpan[]; } /** * Presentation steps a freshly arrived live bar spends growing to its target. * * Three heartbeats keep the ease at the edge of notice while the working * spinner redraws the live area anyway. It counts heartbeat ticks, never time * and never renders, so nothing here can alter what a duration says. */ export declare const REVEAL_TICKS = 3; /** * Presentation-only tracker easing newly appeared bars into their scale. * * A bar fed purely by measurement announces itself at full width whenever it * is the only span so far, which reads as a flash rather than an arrival. This * tracker lets such a bar grow over the next few working heartbeats. Progress * follows those heartbeat ticks, never render counts and never time: streamed * chunks redraw the panel many times inside one heartbeat, and measurement * must react to every one of them while the ease spends nothing until the * heartbeat itself moves. The tracker holds no state outside the view that * owns it. Spans that were already folded when the panel appeared — a * preference toggled on mid-turn, a retained finished turn — draw at their * final width at once, because decoration must never replay history. */ export declare class SpanReveal { private readonly tick; /** Birth tick per label; a label absent here is history, born unbounded past. */ private readonly born; private armed; private armedAtPreviousRender; private rendered; /** * @param tick - reads the attachment's working-heartbeat counter, the one * cadence reveal progress is allowed to follow. */ constructor(tick: () => number); /** * Mirror the display preference. * * Going hidden also cancels decorative reveal state: a span that arrives * while the panel is off never arrived in front of a visible panel, so the * next enabled render must treat it as settled history. Leaving pending * reveals or the previous armed marker standing would ease such a span in * on re-enable, replaying an arrival nobody saw. * @param on - whether the timing view is currently contributing rows. */ setArmed(on: boolean): void; /** * Discard every pending reveal. * * Called when a measurement becomes history: a finished turn stops the * working heartbeat that would otherwise age its bars to full width, so a * partially revealed span could freeze mid-reveal forever in the retained * panel. Clearing here also hands the next turn's arrivals a clean tracker, * whatever labels they share with the turn just ended. */ reset(): void; /** * Report each span's reveal fraction for this render. * * Renders sharing one heartbeat tick report identical fractions: only the * tick moving ages a span toward its final width. * @param labels - labels currently measured, longest first. * @returns fraction per label, 0 just arrived through 1 fully revealed. */ progress(labels: readonly string[]): Map; } /** * Collects timings for the live turn and retains the most recent finished one. * * Two authorities, each measured from the timestamps its own contract carries. * Turn boundaries and tool call/result pairs are durable session events, so * their spans are exact and never move once logged. Model stream time exists * only in the live `agent/assistant-stream` frames, so it is measured from the * timestamp each chunk frame supplies — the same one the durable settlement * embeds — rather than from a clock read while drawing. * * That split is also why a reopened session shows `no turn measured yet` rather * than a reconstructed panel. Live frames are process-local: a resumed log * carries its Assistant streams compacted inside settlements, and expanding * them to chart a past turn is history dshline never promised and the memory * cost session format v2 exists to avoid. */ export declare class TurnTimer { /** When the open turn began, or undefined when no turn is being measured. */ private startedAt; private turn; /** * First and last chunk of one kind within one attempt, keyed `kind:attempt`. * * Keyed by ATTEMPT rather than by step: a retried attempt streams its * reasoning again, and merging both into one span would measure the gap * between them — the failure, the retry decision — as time the model spent * thinking. Each attempt's own span is real, and {@link reading} sums them. */ private readonly streams; /** Calls awaiting their result, keyed by call id. */ private readonly pending; /** Finished milliseconds for each tool name in the open turn. */ private readonly tools; /** The last complete measurement, retained while the attachment is idle. */ private finished; /** Forget only the open turn; a completed panel remains useful while idle. */ private resetOpen; /** * Fold one committed session event into the current measurement. * * Observation is intentionally not gated by the display preference. Toggling * a presentation should not fabricate a partial turn beginning at the toggle, * and the event fold is cheap enough to keep the view immediately truthful. * @param event - one committed live session event. * @returns nothing; read the current result through {@link snapshot}. */ observe(event: SessionEvent): void; /** * Fold one live assistant-stream frame into the current measurement. * * The frame carries its own timestamp, which is the same value the durable * settlement embeds for that chunk, so the reasoning and output spans are * measured against the model stream rather than against the redraw clock. * Only chunk frames measure anything: an attempt's opening and terminal * markers say when it existed, not how long it produced. * @param frame - one ordered frame for the attached agent's current attempt. * @returns nothing; read the current result through {@link snapshot}. */ observeFrame(frame: AssistantStreamFrame): void; /** * Current live measurement, or the most recent completed turn while idle. * @param now - current wall clock, used only for values whose closing event has * not arrived; defaults to the clock at render time. * @returns the current or retained measurement, or undefined in a fresh attachment. */ snapshot(now?: number): TurnTiming | undefined; /** Build one immutable reading without mutating the fold. */ private reading; } /** * The bounded timing panel as live-region lines. * @param profile - current or retained timing, or undefined before a live turn. * @param columns - the terminal's current width. * @param rows - maximum rows this panel may spend. * @returns lines for the live region, including a placeholder when no turn exists. */ export declare function timingLines(profile: TurnTiming | undefined, columns: number, rows?: number): string[]; /** * Create the persistent timing slot. * * The slot owns the reveal tracker, so easing a new bar in is presentation * state of this view alone: it ages on the heartbeat ticks read from * `getTick`, adds no timer, and never reaches Harness or session state. * @param timer - live event fold owned by this attachment. * @param enabled - window preference deciding whether the view contributes rows. * @param getTick - reads the working spinner's heartbeat counter, which is the * only thing allowed to advance a reveal. * @returns a view that leaves the fixed status row beneath it. */ export declare function createTimingView(timer: TurnTimer, enabled: () => boolean, getTick: () => number): TuiSlotView; //# sourceMappingURL=timing.d.ts.map