/** * The `/tasks` panel: one overlay over every task in the session, list and detail. * * It is a plain pi-tui `Component` with no state of its own beyond keys and * pixels: records and processes belong to the store, and the panel reaches them * only through `PanelSource`. Nothing here signals a process or touches a file. * * Both kinds share one table and one key set. A loop task opens onto its * iterations, newest first; an iteration opens onto the tool calls that turn * made, in order — the panel only renders records the loop store already kept. * * @author mystery4f <40482524+mystery4f@users.noreply.github.com> */ import type { Theme } from "@earendil-works/pi-coding-agent"; import { type Component } from "@earendil-works/pi-tui"; import type { CmdLoopTask, FireRecord, PromptLoopTask, Task } from "../../tasks/base/task.js"; import type { Iteration } from "../../tasks/loop/iteration.js"; import { type PanelFilter, type PanelMode, type PanelSource, type PanelTab, type PanelTaskView, type PanelTerminal, type TasksPanelOptions } from "./model.js"; import { type RowMatch } from "./query.js"; import type { PanelView } from "./view.js"; export * from "./format.js"; export * from "./keys.js"; export * from "./model.js"; export * from "./query.js"; export * from "./row-filter.js"; /** The page a new panel opens on. */ export declare function lastPanelTab(): PanelTab; /** Put the remembered page back; a test resets it, and only a tab key changes it. */ export declare function rememberPanelTab(tab: PanelTab): void; export declare class TasksPanel implements Component, PanelView { readonly tui: PanelTerminal; readonly theme: Theme; readonly done: () => void; readonly source: PanelSource; readonly now: () => number; readonly timer: ReturnType | undefined; mode: PanelMode; /** Width of the frame being drawn; field values are cut against it. */ renderWidth: number; /** * Rows the pane leaves the panel, measured on every render. A caller without a * terminal falls back to a tall default, so a test and a headless view keep * every field instead of drawing into a pane that may not exist. */ renderHeight: number; /** What the reader may open: the filter has already been applied. */ rows: readonly PanelTaskView[]; /** Every row of the session, so the counts never depend on the filters. */ allRows: readonly PanelTaskView[]; /** The page being read; a reopened panel starts on the remembered one (ADR-0012). */ tab: PanelTab; /** The status filter `f` cycles, applied inside the open page. */ filter: PanelFilter; /** * Whether `o` has brought in the other sessions working in this checkout. Their * rows are read-only and tagged, and the counts above never include them. */ showOthers: boolean; /** Roots of the other sessions, loaded on demand and merged into the page. */ otherRows: PanelTaskView[]; /** * What each page had selected when the reader left it, keyed by page. Reopening a * page lands where it was left rather than at the top (ADR-0012 keeps selection by id). */ readonly selectedByTab: Record; selectedId: string | undefined; listTop: number; /** `/` turns keys into a query instead of navigation; `alt+q` leaves it. */ searching: boolean; /** The query outlives search mode: leaving keeps it, and the header keeps showing it. */ query: string; /** Where each shown row's query landed; empty when there is no query. */ readonly matchScores: Map; detailId: string | undefined; detailLines: readonly string[]; detailTruncated: boolean; detailError: string | undefined; /** Lines the reader has scrolled up from the newest; 0 follows the tail. */ scrollBack: number; /** False while scrolled up: the buffer stays frozen so the view does not move. */ following: boolean; /** Which iteration of the open loop is selected, by fire number. */ iterationFire: number | undefined; /** First iteration row drawn in the loop detail's newest-first list. */ iterationTop: number; /** First call drawn in the iteration view, counted from the oldest call. */ callTop: number; notice: string | undefined; /** Bytes each task had at the previous refresh, so the list can show `+4.1KB ↑`. */ readonly lastBytes: Map; readonly recentGrowth: Map; /** Serialises async work so a keypress never races the refresh it started. */ pending: Promise; constructor(options: TasksPanelOptions); /** Resolves once every queued action has finished; a seam for deterministic tests. */ settle(): Promise; /** Reload rows, and the detail tail while it is being followed. */ refresh(): Promise; /** * Recompute what the reader may open: the page's roots, then the status filter, * then the query. A child record is never a row, so a fire or a step can never * pull its parent in (ADR-0014); the counts stay over every record and never * follow either narrowing (ADR-0012). */ applyFilters(): void; /** * Where the query lands on a row, or undefined when it misses. A chain row * displays its step names, so those are matchable words; nothing a row does not * display — a step's command, a fire's id — can bring a row back (ticket #27). */ matchField(task: Task): RowMatch | undefined; /** * Hold the selected task across a refresh or a narrower query, or fall back to * the first row. Ranking can lift the held task above the scroll window, so the * window follows it; a query never hides the row a reader is standing on. */ keepSelection(): void; /** * Remember how much each task grew since the last look, so a list row can say * `+4.1KB ↑` the way a file manager shows a download. A finished task keeps its * final size and shows no arrow. */ trackGrowth(): void; /** The `+size ↑` a still-growing task shows for a few seconds after a refresh. */ growthText(row: PanelTaskView): string; render(width: number): string[]; /** The keyboard model lives in `input.ts`; this is the component's one entry. */ handleInput(data: string): void; /** Remember the open page for the next panel; only a tab key changes it. */ remember(tab: PanelTab): void; invalidate(): void; dispose(): void; /** Say something in the notice line: the answer to a key that could not act. */ notify(text: string | undefined): void; /** `/` — the next keystrokes are a query, not a command. */ beginSearch(): void; /** `alt+q` in search — the query stays on screen, the keys go back to commands. */ endSearch(): void; /** Re-filter on a new query and paint; every record is already in hand. */ enterQuery(query: string): void; /** Move the list cursor by `delta`, keeping the selected row on screen. */ moveCursor(delta: number): void; /** Point the list at one row, without moving the window. */ selectRow(id: string | undefined): void; /** Keep row `index` inside the list window. */ private scrollListTo; /** Enter on the list: open the selected record, or say there is nothing to open. */ openPage(): void; /** Enter on a fire: the process record it left behind, at its own tail. */ openProcessPage(taskId: string, fire: number): void; /** `←` from a fire: the record it was started by, without leaving the detail. */ showDetailOf(id: string | undefined): void; /** Enter on an iteration: the calls of one turn. */ openIterationPage(fire: number): void; /** `←` out of a detail: back to the list the reader came from. */ backToList(): void; /** `←` out of an iteration: back to the detail of the loop it belongs to. */ backToLoopPage(): void; /** `←` out of a loop detail: the fire cursor has no meaning in the list. */ clearFireCursor(): void; /** `←` out of an iteration detail: the next one opens at its own top. */ clearCallCursor(): void; /** Walk the newest-first history, keeping the picked fire and its window. */ showFire(fire: number, index: number): void; /** Two new lines come from the reader scrolling back through the output. */ scrollTail(delta: number): void; /** `r`, or scrolling back to the newest line: read the tail again and follow it. */ followTail(): void; /** Move the call cursor inside one iteration, never past its oldest call. */ scrollCalls(delta: number, calls: number): void; /** A page key: take the whole keyboard to that page and drop the detail behind it. */ selectPage(next: PanelTab): void; /** `f` walks all → running → failed → done inside the open page, and round again. */ cycleFilter(): void; /** `o`: add or drop the rows another session started, read-only (ticket #27). */ toggleOthers(): void; detailRow(): PanelTaskView | undefined; /** The iteration under the cursor, or the newest one when the store trimmed the pick. */ currentIteration(task: PromptLoopTask): Iteration | undefined; /** The fire under the cursor, or the newest one when the history cap trimmed it. */ currentFire(task: CmdLoopTask): FireRecord | undefined; readTail(): Promise; enqueue(work: () => Promise): void; paint(): void; /** * The box the whole panel lives in: a border, a tinted title band carrying the * counts, the body, then the keys. It mirrors the panel this plugin replaces so * the eye lands in the same place; colours still come from theme tokens. */ frame(title: string, subtitle: string, body: string[], footer: string, width: number): string[]; }