repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(footer): show overflowing LLM segments

6ec7adc2cbaf43778861eaffaea5b90db0e46d1c

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (3)

extensions/footer/README.md

Modified
27 27 Owns the Pi footer through `ctx.ui.setFooter()`.
29 -Visible footer has a stable two-line height:
29 +Visible footer has two lines normally and adds a third under LLM-segment pressure:
31 31 - line 0: `workspace` segments plus current session name on the left, with extension statuses via `ctx.ui.setStatus()` right-aligned in the remaining space.
32 -- line 1: the first `llm` flow row; overflow is not shown.
32 +- line 1: the first `llm` flow row.
33 +- line 2: the second `llm` flow row, shown only when content overflows line 1.
34 35 `footer:segment` payloads use `id`, `text`, and `zone` (`workspace` or `llm`).
35 36 Optional fields: `variants`, `icon`, `color`, `bar`, `suffix`, `group`, `separator`, and `order`.

extensions/footer/__tests__/harness.test.ts

Modified
1 1 import path from "node:path";
2 +import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2 3 import { visibleWidth } from "@earendil-works/pi-tui";
3 4 import { afterEach, describe, expect, it } from "vitest";
4 5 import { createTestSession, type TestSession } from "../../../test/harness";
5 -import { __test } from "../index.ts";
6 +import footerExtension, { __test } from "../index.ts";
7 8 describe("footer pi-test-harness", () => {
8 9 let t: TestSession | undefined;
20 21 expect(t.session.extensionRunner.extensions[0].path).toBe(extensionPath);
24 + it("keeps later LLM components visible as earlier values grow", async () => {
25 + let emitSegment: ((segment: unknown) => void) | undefined;
26 + const producer = (pi: ExtensionAPI) => {
27 + emitSegment = (segment) => pi.events.emit("footer:segment", segment);
28 + };
29 + t = await createTestSession({
30 + extensionFactories: [footerExtension, producer],
31 + });
33 + const factory = t.events.uiCallsFor("setFooter").at(-1)?.args[0] as
34 + | ((
35 + tui: { requestRender(): void },
36 + theme: { fg(style: string, text: string): string },
37 + data: {
38 + onBranchChange(callback: () => void): () => void;
39 + getExtensionStatuses(): ReadonlyMap<string, string>;
40 + },
41 + ) => {
42 + render(width: number): string[];
43 + dispose(): void;
44 + })
45 + | undefined;
46 + expect(factory).toBeTypeOf("function");
47 + const component = factory?.(
48 + { requestRender() {} },
49 + { fg: (_style, text) => text },
50 + {
51 + onBranchChange: () => () => {},
52 + getExtensionStatuses: () => new Map(),
53 + },
54 + );
55 + expect(component).toBeDefined();
57 + emitSegment?.({ id: "model", text: "sol:medium", zone: "llm", order: 0 });
58 + emitSegment?.({ id: "tokens", text: "↑0", zone: "llm", order: 2 });
59 + emitSegment?.({ id: "tps", text: "50.0/s", zone: "llm", order: 4 });
60 + const initial = component?.render(32) ?? [];
61 + expect(initial).toHaveLength(2);
62 + expect(initial.join("\n")).toContain("50.0/s");
64 + emitSegment?.({
65 + id: "tokens",
66 + text: "↑12k ↓3.4k",
67 + zone: "llm",
68 + order: 2,
69 + });
70 + const grown = component?.render(32) ?? [];
71 + expect(grown).toHaveLength(3);
72 + expect(grown.join("\n")).toContain("50.0/s");
73 + expect(grown.every((line) => visibleWidth(line) <= 32)).toBe(true);
75 + emitSegment?.({ id: "tokens", text: "↑0", zone: "llm", order: 2 });
76 + const shrunk = component?.render(32) ?? [];
77 + expect(shrunk).toHaveLength(2);
78 + expect(shrunk.join("\n")).toContain("50.0/s");
79 + component?.dispose();
80 + });
23 82 it("right-aligns statuses beside the workspace row", () => {
24 83 expect(__test.alignLeftAndRight("workspace", "busy", 16)).toBe(
25 84 "workspace busy",

extensions/footer/index.ts

Modified
3 3 * Footer renderer extension.
5 5 * Listens for "footer:segment" events from producer extensions and renders
6 - * a 2-line footer with stable height:
6 + * a compact footer:
7 7 * line 0 = workspace zone left-aligned, extension statuses right-aligned
8 8 * line 1 = llm zone (model, thinking, context, tokens, cost, timing)
9 + * line 2 = llm overflow, present only when needed
10 11 * Producers use semantic zones ("workspace" | "llm"). Footer decides row mapping.
11 12 * Publishes a process-global capability flag so producers can choose footer
333 334 ): string[] {
334 335 const contentWidth = Math.max(0, width - 2);
335 336 const workspaceLine = renderWorkspaceLine(theme, contentWidth, ctx);
336 - const [llmLine] = renderLlmLines(theme, contentWidth);
337 + const [llmLine, llmOverflowLine] = renderLlmLines(theme, contentWidth);
337 338 const statusLine = renderStatusLine(theme, statuses);
338 339 const topLine = alignLeftAndRight(workspaceLine, statusLine, contentWidth);
340 - return [padLine(topLine, width), padLine(llmLine, width)];
340 + const lines = [padLine(topLine, width), padLine(llmLine, width)];
341 + if (llmOverflowLine) lines.push(padLine(llmOverflowLine, width));
342 + return lines;
343 345 // ── Mounting ──────────────────────────────────────────────────