/** * src/extension/fleet.ts — FleetView widget (B6): persistent visibility of * active delegation runs. * * Renders a live footer widget listing active runs (agent / status / tokens / * cost / duration), refreshes on a bounded timer (which catches completion and * failure transitions) plus an explicit `onLocalChange()` hook, supports a * BOUNDED transcript peek (reads the run's session jsonl, capped by lines and * bytes), and a `stop` action that aborts a run via the engine monitor. * * Safe string[] widget form only (Pi wraps each line in a Text component and * truncates itself). Transient — nothing is persisted. * * Zero @earendil-works/* imports. */ import { type DelegationRunStatus, type DelegationRunView } from "../engine/runs.js"; import type { GetRuntime } from "./tools.js"; import { type WidgetTicker } from "./widget-refresh.js"; import type { SessionContext, WidgetContent, WidgetKey } from "./pi-types.js"; export declare const FLEET_WIDGET_ID: WidgetKey; export declare const FLEET_STATUS_ID = "subagents-fleet"; export declare const FLEET_MAX_RUNS = 8; export declare const PEEK_MAX_LINES = 20; export declare const PEEK_MAX_BYTES = 4000; /** One rendered fleet row (pure data, injectable for tests). */ export interface FleetRunLine { id: string; agent: string; status: DelegationRunStatus; tokens: number; cost: number; durationMs: number; /** True while `tokens` is the LIVE context snapshot (mid-run estimate ≈). */ live: boolean; /** Live model when the turn feed carried one (settled runs read run.model). */ model?: string; } /** * Extract the token + cost summary from a run's usage. Settled usage * (input+output > 0) wins; an ACTIVE run with a live turn snapshot falls * back to `liveUsage.contextTokens` (marked live — cost unknown mid-run); * a settled usage with zero in/out but a context snapshot shows the snapshot. */ export declare function runUsageSummary(run: DelegationRunView): { tokens: number; cost: number; live: boolean; }; /** Build the active-run rows for the fleet widget (bounded to FLEET_MAX_RUNS). */ export declare function fleetRunLines(getRuntime: GetRuntime, now?: number): FleetRunLine[]; /** Pure renderer — returns the widget lines for a runtime (injectable now). */ export declare function renderFleetLines(getRuntime: GetRuntime, now?: number): WidgetContent; /** * Bounded transcript peek: read the run's session jsonl, capped by both a max * line count and a max byte count. Never throws — returns a short message on * any read failure or when no session path is recorded. */ export declare function peekTranscript(run: DelegationRunView | undefined, maxLines?: number, maxBytes?: number): string; /** * Stop a run via the engine monitor abort. Marks a queued/running run as * aborted; returns a short status message. No-op for unknown or already * terminal runs. */ export declare function stopRun(getRuntime: GetRuntime, runId: string): string; /** Small FleetView owner: diffed refresh on the shared ticker (anti-flicker). */ export declare class FleetView { private readonly getRuntime; private readonly ticker; private unsubscribe?; private readonly ctx; private readonly painter; constructor(ctx: SessionContext, getRuntime: GetRuntime, ticker?: WidgetTicker); attach(): void; detach(): void; /** Refresh immediately when a run completes/fails (event hook). */ onLocalChange(): void; private refresh; }