/** * Bash tool output for the one-line tool rows: separate what pi appended to the text (exit status, * truncation notice) from what the command printed, clean the printed lines for the screen, and * fold them. Pure functions with no pi imports, so tests run standalone. * * pi adds its notices at the END of the text, after a blank line: * * * * [Showing lines 1001-3000 of 3000. Full output: /tmp/pi-bash-x.log] (only when truncated) * * Command exited with code 3 (only on failure) * * Only that trailing position is read, so output that merely contains those words is never * mistaken for a notice. */ export type BashStatus = "ok" | "failed" | "aborted" | "timeout" | "no-exit"; /** How long a command runs before its live output appears under the row. */ export declare const LIVE_DELAY_MS = 500; /** Lines of live output shown under a running row. */ export declare const LIVE_TAIL_LINES = 5; /** Lines of a finished command's output left under its row until the row is expanded. */ export declare const PEEK_LINES = 3; export interface BashOutput { /** What the command printed, cleaned for display, without pi's notices. */ lines: string[]; status: BashStatus; /** The exit code, when pi reported one. */ exitCode?: number; timeoutSecs?: number; /** pi cut the output; `lines` holds only the part it kept (the end). */ truncated: boolean; /** Lines the command printed, counting those pi cut. Equals `lines.length` when not truncated. */ totalLines: number; fullOutputPath?: string; } export interface BashOutputHints { /** Whether pi reports this result as an error. */ isError: boolean; /** `result.details.truncation` */ truncation?: { truncated?: boolean; totalLines?: number; }; /** `result.details.fullOutputPath` */ fullOutputPath?: string; } /** * One output line as plain text: every escape sequence removed (colour, cursor movement, titles, * hyperlinks), a progress line that was redrawn with carriage returns reduced to its last state, * tabs widened, other control characters dropped. */ export declare function cleanLine(line: string): string; /** A line longer than this is cut, like OpenCode's character cap: no terminal shows more. */ export declare const MAX_LINE_CHARS = 1000; /** Split pi's bash result text into the command's output and the status pi attached. */ export declare function parseBashOutput(raw: string, hints: BashOutputHints): BashOutput; /** The first or last `keep` lines, and how many of the given lines were left out. */ export declare function foldLines(lines: string[], keep: number, from: "head" | "tail"): { shown: string[]; hidden: number; }; /** "2.1s" for a run of a second or more, else undefined (a 0.0s tag is noise). */ export declare function formatWallTime(seconds: unknown): string | undefined; /** * The live output of a command that is still running, from the partial result pi sends while it * runs (the text so far, cut to its last lines by pi). Returns the last `keep` lines, cleaned for * the screen, and how many earlier lines are not shown. There is no status to read yet, so nothing * is removed from the end: a line that looks like a notice is just a line. */ export declare function liveTail(raw: string, keep?: number): { lines: string[]; earlier: number; }; /** * Whether a running row should show its live output yet: it has waited `LIVE_DELAY_MS` since it * first appeared, and there is something to show. */ export declare function liveVisible(firstSeenAt: number | undefined, now: number, hasOutput: boolean): boolean; /** Milliseconds until a row that is not yet visible should look again, or undefined if it never will. */ export declare function liveWaitMs(firstSeenAt: number | undefined, now: number): number | undefined; /** * What stays visible under a finished row: the last `keep` lines (an error is usually at the end), * and how many lines are not shown, counting those pi cut from a very long output. */ export declare function bashPeek(out: BashOutput, keep?: number): { lines: string[]; hidden: number; };