From b097b7653509e9940624478daa20ee84713dafc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Tue, 1 Dec 2026 20:30:37 +0000 Subject: [PATCH] WIP: display round, work in progress saved when the session was interrupted --- CHANGELOG.md | 45 +++++++++++ scripts/drive.ts | 6 +- scripts/smoke.ts | 119 ++++++++++++++++++++++++++-- src/tui/app.tsx | 4 +- src/tui/components/display_pane.tsx | 9 ++- src/tui/state.ts | 10 ++- tests/displays.test.ts | 15 +++- 7 files changed, 195 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 896027f..475f1c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,51 @@ All notable changes to LLeMbas CLI. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses [Semantic Versioning](https://semver.org/). +## Unreleased + +### Added + +- **Pictures in the display, by themselves.** A new **Images** tab shows what the agent views + with `view_image`, what `show` shows when it is a picture, and the images you attach or paste + (`@shot.png`) — the newest first, `Alt+←/→` through the others. The pane goes to a picture a + tool has just viewed without being asked (unless you pinned a tab) and back to Live when the + agent moves on. Pictures are drawn with the **kitty graphics protocol** where the terminal is + found to support it (kitty, Ghostty — the terminal is asked, nothing is configured), with sixel + where that is what it has, and as coloured blocks anywhere else, inside tmux included. Setting + `images: auto | on | off` (default `auto`; `on` asks for kitty graphics whatever was detected, + `off` shows the name, size and path only). +- **Two transcripts: full and compact.** Compact groups a round of tool calls into one line — + `▸ 7 tools · read ×3 · bash ×2 · edit ×2 · 14.0s` — with every failure and every refusal still + on a line of its own, a running call in sight while it runs, and a change as a stat line + (`src/a.ts +12 −3`) instead of its diff: the detail is in the display. Setting + `transcript: auto | full | compact`; `auto` (the default) is compact while the display stands + beside the conversation and full when it does not. `Alt+T` or `/transcript [auto|full|compact]` + switches; `Ctrl+O` opens the rounds. Switching keeps your place and runs nothing again. +- **The display has a header and a mouse.** Its first rows say the session's model, mode and + effort, how full the context is, the rate, the month's spend and the project. A click on a tab + opens it, the wheel over the pane scrolls the pane, and every list tab counts its entries + (`3/12`). Files that `show` showed are listed under Files. + +### Changed + +- **The display pane is the full height of the terminal.** It stands at the right from the first + row to the last, beside the prompt and the status bar, instead of ending above them. +- **The display no longer needs a wide terminal.** It stands beside the conversation from 80 + columns (it needed 100, and below that showed nothing and said nothing). On a narrower terminal + the status bar says `alt+d display`, and `Alt+D` — or `/display` — puts the display in the + transcript's place and brings the transcript back; the prompt and the status bar stay. +- The status bar has a short form for a narrow column (mode, model, jobs, context); what it + leaves out is in the display's header. + +### Fixed + +- The display's tab bar, title line and key line no longer run past a narrow pane or lose their + middle: each takes the longest form that fits its row. +- The welcome box's key hints and the prompt box's placeholder no longer break in the middle of a + phrase in a narrow column; a placeholder that wrapped left the prompt box two rows high. +- A word in the status bar that is longer than the bar is cut to it instead of running over the + mode and the model. + ## [2.0.0-beta.17] — 2026-11-27 ### Fixed diff --git a/scripts/drive.ts b/scripts/drive.ts index 0f4e9e5..6eebd1b 100644 --- a/scripts/drive.ts +++ b/scripts/drive.ts @@ -10,6 +10,9 @@ import { delta, fakeProvider, toolCall, usage } from "../tests/fake-provider.ts" export interface Driver { screen(): string[] + /** What is in one cell, by column and row — where a row's text cannot say (a wide character + * before it shifts every index after it). */ + cell(x: number, y: number): string /** Rows that are continuations of the row above: something was wider than the terminal. */ wrapped(): number[] type(s: string): Promise @@ -42,6 +45,7 @@ export async function drive(opts: { cols: number; rows: number; bin?: string; ho } return { screen, + cell: (x, y) => term.buffer.active.getLine(y)?.getCell(x)?.getChars() ?? "", wrapped: () => Array.from({ length: opts.rows }, (_, y) => y).filter((y) => term.buffer.active.getLine(y)?.isWrapped), async type(s) { for (const ch of s) { @@ -93,7 +97,7 @@ if (import.meta.main) { ]) const d = await drive({ cols, rows, home, cwd, bin: binAt > 0 ? process.argv[binAt + 1] : undefined }) const show = (label: string) => console.log(`\n=== ${label}\n` + d.screen().map((l) => l.trimEnd()).join("\n")) - await d.waitFor("shift+tab mode · /help") + await d.waitFor("shift+tab mode") show("start") await d.type("greet me") await d.key("\r") diff --git a/scripts/smoke.ts b/scripts/smoke.ts index d9f99e8..959ed54 100644 --- a/scripts/smoke.ts +++ b/scripts/smoke.ts @@ -6,7 +6,9 @@ import { existsSync, mkdirSync, mkdtempSync, readdirSync, writeFileSync } from " import { tmpdir } from "node:os" import { join, resolve } from "node:path" import { delta, fakeProvider, toolCall, usage } from "../tests/fake-provider.ts" -import { drive, fakeHome } from "./drive.ts" +import { placeDisplay } from "../src/tui/layout.ts" +import { png } from "../tests/png.ts" +import { drive, fakeHome, type Driver } from "./drive.ts" const bin = resolve(process.argv[2] ?? "dist/lembas") const home = mkdtempSync(join(tmpdir(), "lembas-smoke-")) @@ -21,6 +23,10 @@ const run = (args: string[], cwd = home) => { return { code: r.exitCode, out: r.stdout.toString(), err: r.stderr.toString() } } +/** Whether the display pane's border is in column `x` on every row of the terminal. */ +const borderOnEveryRow = (d: Driver, x: number, rows: number) => Array.from({ length: rows }, (_, y) => d.cell(x, y)).every((c) => c === "│") +const BLOCKS = /[▀▄█▌▐▖▗▘▙▚▛▜▝▞▟]/ + // 1. --version const v = run(["--version"]) check("--version", v.code === 0 && /^\d+\.\d+\.\d+/.test(v.out), v.err) @@ -103,7 +109,7 @@ for (const [cols, rows] of [ // A fresh directory opens with the first-run question; trust it (the default), then work. const firstRun = await d.waitFor("Trust this directory?") await d.key("\r") - const drawn = await d.waitFor("shift+tab mode · /help") + const drawn = await d.waitFor("shift+tab mode") await d.type("make a file") await d.key("\r") const asked = await d.waitFor("Allow once") @@ -112,11 +118,21 @@ for (const [cols, rows] of [ await Bun.sleep(200) const screen = d.screen() const wrapped = d.wrapped() + // The display pane: a column at the right over every row — beside the prompt and the status bar. + const place = placeDisplay({ width: cols, enabled: true, zoomed: false }) + const fullHeight = place.mode === "side" && borderOnEveryRow(d, place.left, rows) + const keyLine = Array.from({ length: cols - place.left }, (_, i) => d.cell(place.left + i, rows - 1) || " ").join("") + const promptRow = Array.from({ length: place.left }, (_, i) => d.cell(i, rows - 2) || " ").join("") await d.key("\x03") await d.key("\x03") const code = await d.close() f.stop() const file = await Bun.file(join(cwd, "out.txt")).text().catch(() => "") + check( + `TUI ${cols}x${rows}: the display pane stands beside the conversation, the prompt and the status bar, over the full height`, + fullHeight && keyLine.includes("hide") && promptRow.includes("❯") && screen.some((l) => l.includes("Recent activity")), + `placement=${JSON.stringify(place)} fullHeight=${fullHeight} keyLine=${JSON.stringify(keyLine)} promptRow=${JSON.stringify(promptRow)}\n${screen.join("\n")}`, + ) check( `TUI ${cols}x${rows}: first run → prompt → approval → answer → quit`, firstRun && drawn && asked && answered && file === "smoke\n" && code === 0, @@ -126,6 +142,99 @@ for (const [cols, rows] of [ check(`TUI ${cols}x${rows}: status bar on the last row`, (screen[rows - 1] ?? "").includes("manual · fake/coder"), screen[rows - 1] ?? "") } +// 3a. too narrow for two columns (70×24): the display is not silently absent — the status bar +// names the key, alt+d puts it in the transcript's place (the prompt and the status bar stay) and +// alt+d again brings the transcript back. +{ + const { fake: f, home: h, cwd } = fakeHome([ + { chunks: [delta({ content: "Reading it." }), toolCall(0, "c1", "read", '{"path":"hello.txt"}'), usage(900, 40)] }, + { chunks: [delta({ content: "It says hello." }), usage(1200, 20)] }, + ]) + const d = await drive({ cols: 70, rows: 24, bin, home: h, cwd }) + await d.waitFor("Trust this directory?") + await d.key("\r") + await d.waitFor("shift+tab mode") + await d.type("read it") + await d.key("\r") + const answered = await d.waitFor("It says hello.") + const named = await d.waitFor("alt+d display") + const tucked = !d.screen().some((l) => l.includes("Recent activity")) + await d.key("\x1bd") + const opened = (await d.waitFor("Recent activity")) && (await d.waitFor("alt+d transcript")) + await Bun.sleep(200) + const zoom = d.screen() + const inPlace = !zoom.some((l) => l.includes("It says hello.")) && (zoom[22] ?? "").includes("❯") && (zoom[23] ?? "").includes("manual · fake/coder") && d.cell(0, 0) !== "│" + const wrapped = d.wrapped() + await d.key("\x1bd") + const back = (await d.waitFor("It says hello.")) && !d.screen().some((l) => l.includes("Recent activity")) + await d.key("\x03") + await d.key("\x03") + const code = await d.close() + f.stop() + check( + "TUI 70x24: no room beside the conversation — the status bar names the display, alt+d opens it in the transcript's place and back", + answered && named && tucked && opened && inPlace && back && code === 0, + `answered=${answered} named=${named} tucked=${tucked} opened=${opened} inPlace=${inPlace} back=${back} exit=${code}\n${zoom.join("\n")}`, + ) + check("TUI 70x24: the display in the transcript's place is no wider than the terminal", wrapped.length === 0, `wrapped rows: ${wrapped.join(", ")}`) +} + +// 3c. compact and full, and a picture, at 120×40: beside the display a round of calls is one line; +// alt+t shows every call on its own line and back; a picture attached with @ is drawn in the +// images tab — OpenTUI's native image decoder inside the compiled binary (blocks: this terminal +// has no graphics protocol). +{ + const { fake: f, home: h, cwd } = fakeHome([ + { chunks: [delta({ content: "Looking." }), toolCall(0, "c1", "read", '{"path":"hello.txt"}'), toolCall(1, "c2", "grep", '{"pattern":"hello","path":"."}'), usage(900, 40)] }, + { chunks: [delta({ content: "Both say hello." }), usage(1200, 20)] }, + // Twice: the session's title is asked of the model too. + { chunks: [delta({ content: "A picture, noted." }), usage(1300, 20)] }, + { chunks: [delta({ content: "A picture, noted." }), usage(1300, 20)] }, + ]) + writeFileSync(join(cwd, "shot.png"), png(64, 32)) + const d = await drive({ cols: 120, rows: 40, bin, home: h, cwd }) + await d.waitFor("Trust this directory?") + await d.key("\r") + await d.waitFor("shift+tab mode") + await d.type("look") + await d.key("\r") + const answered = await d.waitFor("Both say hello.") + const left = () => d.screen().map((l) => l.slice(0, 68)) + const compact = (await d.waitFor("▸ 2 tools · read · grep")) && !left().some((l) => /read +hello\.txt/.test(l)) + await d.key("\x1bt") + await d.waitFor("transcript: full") + await Bun.sleep(300) + const full = left().some((l) => /read +hello\.txt/.test(l)) && left().some((l) => /grep +hello/.test(l)) && !left().some((l) => l.includes("2 tools")) + const fullScreen = d.screen() + await d.key("\x1bt") + const again = await d.waitFor("▸ 2 tools · read · grep") + await d.type("@shot.png what is this ") + await d.key("\r") + const noted = await d.waitFor("A picture, noted.") + await d.type("/display images") + await d.key("\r") + const listed = await d.waitFor("shot.png · attached") + await Bun.sleep(500) + const picture = d.screen() + const drawn = picture.some((l) => BLOCKS.test(l.slice(68))) && picture.some((l) => l.includes("64×32")) + const wrapped = d.wrapped() + await d.key("\x03") + await d.key("\x03") + const code = await d.close() + const modes = d.modes() + f.stop() + check( + "TUI 120x40: beside the display a tool round is one line; alt+t shows every call and back", + answered && compact && full && again, + `answered=${answered} compact=${compact} full=${full} again=${again}\n${fullScreen.join("\n")}`, + ) + check( + "TUI 120x40: an attached picture is drawn in the images tab (the native decoder inside the binary)", + noted && listed && drawn && wrapped.length === 0 && code === 0 && modes.mouse === "none" && !modes.altScreen, + `noted=${noted} listed=${listed} drawn=${drawn} wrapped=${wrapped.join(",")} exit=${code} modes=${JSON.stringify(modes)}\n${picture.join("\n")}`, + ) +} + // 3b. jobs, at 80×24: a command the model starts in the background is counted in the status bar; // /jobs opens the list (the row fits the terminal) and esc closes it; quitting with it running asks // first, and y stops it and leaves. @@ -137,7 +246,7 @@ for (const [cols, rows] of [ const d = await drive({ cols: 80, rows: 24, bin, home: h, cwd }) await d.waitFor("Trust this directory?") await d.key("\r") - await d.waitFor("shift+tab mode · /help") + await d.waitFor("shift+tab mode") await d.type("start a server") await d.key("\r") const asked = await d.waitFor("Allow once") @@ -218,7 +327,7 @@ for (const [cols, rows] of [ await d.key("\r") // The new program draws its welcome box again, with the conversation loaded under it. await Bun.sleep(300) - const back = await d.waitFor("shift+tab mode · /help") + const back = await d.waitFor("shift+tab mode") // The new program's next request carries the conversation from before the reload. await d.type("again") await d.key("\r") @@ -252,7 +361,7 @@ for (const [cols, rows] of [ const d = await drive({ cols: 100, rows: 30, bin, home: h, cwd, args: ["-l"], env: { HOME: h, TMPDIR: tmp, XDG_CONFIG_HOME: join(h, ".config"), XDG_DATA_HOME: join(h, ".local/share"), XDG_STATE_HOME: join(h, ".local/state") } }) const firstRun = await d.waitFor("Trust this directory?") await d.key("\r") - const drawn = await d.waitFor("shift+tab mode · /help", 15000) + const drawn = await d.waitFor("shift+tab mode", 15000) await d.type("make a file") await d.key("\r") const asked = await d.waitFor("Allow once") diff --git a/src/tui/app.tsx b/src/tui/app.tsx index ea08044..af56d1d 100644 --- a/src/tui/app.tsx +++ b/src/tui/app.tsx @@ -685,8 +685,8 @@ export function Root(p: { app: Runtime; view: View; theme: Theme; onQuit: () => } if (key.name === "pageup" || key.name === "pagedown" || key.name === "[" || key.name === "]") { const up = key.name === "pageup" || key.name === "[" - const step = Math.max(1, Math.floor((displayScroll?.height || 10) / 2)) - displayScroll?.scrollBy(up ? -step : step) + // The images tab has nothing to scroll, and the box of the tab before it is gone. + if (displayScroll && !displayScroll.isDestroyed) displayScroll.scrollBy(up ? -Math.max(1, Math.floor((displayScroll.height || 10) / 2)) : Math.max(1, Math.floor((displayScroll.height || 10) / 2))) return key.preventDefault() } } diff --git a/src/tui/components/display_pane.tsx b/src/tui/components/display_pane.tsx index 10a532a..cccf4e9 100644 --- a/src/tui/components/display_pane.tsx +++ b/src/tui/components/display_pane.tsx @@ -1,5 +1,5 @@ import { readFileSync, statSync } from "node:fs" -import { basename } from "node:path" +import { basename, relative } from "node:path" import { TextAttributes, type ScrollBoxRenderable } from "@opentui/core" import { useRenderer } from "@opentui/solid" import { createEffect, createMemo, createSignal, For, Match, onCleanup, Show, Switch } from "solid-js" @@ -208,6 +208,11 @@ export function DisplayPane(p: { const px = pic && "bytes" in pic ? pic.px : undefined return px ? fitImage(px, inner(), Math.max(1, bodyRows() - 3), cellAspect()) : { width: inner(), height: Math.max(1, bodyRows() - 3) } } + /** A path as it reads from the project: inside it, from its root. */ + const shownPath = (path: string) => { + const rel = relative(app.project.root, path) + return rel && !rel.startsWith("..") ? rel : path + } const pictureWords = () => { const pic = picture() if (!pic) return "" @@ -276,7 +281,7 @@ export function DisplayPane(p: { } > - {picture()!.entry.title} + {shownPath(picture()!.entry.path)} {clipEnd(pictureWords(), inner()) || " "} diff --git a/src/tui/state.ts b/src/tui/state.ts index b839fc1..c39a20f 100644 --- a/src/tui/state.ts +++ b/src/tui/state.ts @@ -146,6 +146,8 @@ export interface ViewState { // What the model was given beside the words typed — attachments, and a session note // (session/prefix.ts) — is not shown as typed. const ATTACHMENT = { test: (t: string) => /^<(file|directory|shell|image) /.test(t) || t.startsWith("\n") || isNote(t) } +/** An attached picture as the model was told of it: ``, the whole part. */ +const IMAGE_ATTACHMENT = /^$/gm /** Running first, then by start — the registry's order. */ const byRunning = (a: JobInfo, b: JobInfo) => Number(b.state === "running") - Number(a.state === "running") || a.started - b.started let seq = 0 @@ -536,9 +538,13 @@ export function createView(bus: Bus) { else if (m.role === "user" && m.parts[0]?.type === "text" && stripMark(m.parts[0].text).mark) // A job's note given mid-turn: without its mark, as a steer is shown. items.push({ kind: "user", id: nextId(), text: stripMark(m.parts[0].text).body.trim(), mid: true, machine: true }) - else if (m.role === "user") + else if (m.role === "user") { // What was typed; attachments (@files, ! output) went to the model but are not shown again. - items.push({ kind: "user", id: nextId(), text: m.parts.filter((p, i) => p.type === "text" && (i === 0 || !ATTACHMENT.test(p.text))).map((p) => (p.type === "text" ? p.text : "")).join("\n") }) + // A picture that was attached is remembered by its path, as the attachment named it + // (project/attach.ts), for the display's images tab. + const images = m.parts.flatMap((p) => (p.type === "text" ? [...p.text.matchAll(IMAGE_ATTACHMENT)].map((x) => x[1]!) : [])) + items.push({ kind: "user", id: nextId(), text: m.parts.filter((p, i) => p.type === "text" && (i === 0 || !ATTACHMENT.test(p.text))).map((p) => (p.type === "text" ? p.text : "")).join("\n"), ...(images.length ? { images } : {}) }) + } else if (m.role === "assistant") { for (const p of m.parts) { if (p.type === "text" && p.text.trim()) { diff --git a/tests/displays.test.ts b/tests/displays.test.ts index f1e4e76..1444760 100644 --- a/tests/displays.test.ts +++ b/tests/displays.test.ts @@ -15,7 +15,8 @@ import { resolveIndex, stepEntry, } from "../src/tui/displays.ts" -import type { Item, Pending, ViewState } from "../src/tui/state.ts" +import { Bus } from "../src/bus/index.ts" +import { createView, type Item, type Pending, type ViewState } from "../src/tui/state.ts" function baseState(overrides: Partial = {}): ViewState { return { @@ -196,3 +197,15 @@ test("a picture's box keeps its aspect inside the cells it is given", () => { } expect(fitImage({ width: 0, height: 10 }, 10, 10)).toEqual({ width: 0, height: 0 }) }) + +test("a stored session's attached pictures are found again by the path the attachment named", () => { + const view = createView(new Bus()) + view.load([ + { role: "user", parts: [{ type: "text", text: "what is this @shots/a.png" }, { type: "text", text: '' }, { type: "image", mime: "image/png", data: "" }, { type: "text", text: '(not attached: this model has no vision)' }] }, + { role: "assistant", parts: [{ type: "text", text: "A cat." }] }, + ] as never) + expect(extractImages(view.state.items, (p) => `/work/${p}`)).toEqual([{ id: expect.any(String) as never, title: "shots/a.png", path: "/work/shots/a.png", source: "attached" }]) + // What the person typed is shown as before: the attachment's text is not. + const user = view.state.items[0]! + expect(user.kind === "user" && user.text).toBe("what is this @shots/a.png") +})