Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb4033eafe
|
||
|
|
e245e355b9
|
No files matched your search
@@ -6,6 +6,44 @@ All notable changes to LLeMbas CLI. The format follows
|
||||
|
||||
## Unreleased
|
||||
|
||||
## [2.0.0-beta.22] — 2026-12-04
|
||||
|
||||
### Changed
|
||||
|
||||
- **A new look for the conversation.** The prompt is a shaded block with a bar in the prompt's
|
||||
colour; each piece of the reply starts with a leaf mark (`◆`, `responseMark` in a theme's
|
||||
`branding`); the tools sit indented under them in quieter colours. Prompt, reply and tools
|
||||
are told apart at a glance.
|
||||
- **A round of tool calls is one line, in the full transcript and the compact one alike.** While
|
||||
it runs the line follows it — a spinner, the call running now and its title (for a subagent,
|
||||
what it is doing itself), how many calls the round has made; once it is done it says what the
|
||||
round did: `✓ 7 tools · read ×3 · bash ×2 · edit ×2 · +12 −3 in 2 files · 14.0s`. A thought
|
||||
that led to a call is folded into its round instead of standing as a line of its own. Each
|
||||
failure and refusal still gets a line under the round. The full transcript adds each change's
|
||||
diff under its round; the compact one leaves it to the display. Ctrl+O opens a round into its
|
||||
calls, every one in full, as before.
|
||||
- **Your prompt is drawn as markdown**, as a reply is: `**bold**` and `` `code` `` no longer show
|
||||
their marks. A paste or image placeholder keeps its brackets.
|
||||
- **The status bar**: the mode is a coloured chip, and a view chip at its end shows whether the
|
||||
display stands beside the conversation (`◧`) or the transcript is alone (`▤`, with `full` or
|
||||
`compact` and the key on a wide terminal). **Clicking it switches the display**, as alt+d does.
|
||||
- The welcome box carries the mark, the version beside the name, and its labels in one column.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **A reply no longer flickers while it streams.** Markdown read halfway was drawn as it stood: an
|
||||
unclosed `**`, `` ` `` or `*` showed its marks until the closing one came and then lost them, a
|
||||
heading showed its `##`, a fence's first backtick stood alone and the block below blanked for a
|
||||
moment, and a table showed its pipes before turning into a table — every one a jump of the
|
||||
text. The reply is now drawn steady while it streams: what is open is closed, and what may
|
||||
still become something else (a fence, a table header, a heading) waits for the line that
|
||||
decides it. What is copied and stored is the text as it came.
|
||||
- A reply that holds a page block rebuilt every one of its pieces on every redraw while it
|
||||
streamed; the pieces are now updated in place.
|
||||
- **Square brackets that are not a link keep them**: `[1]`, `[Image 2]`, `[Pasted text 40 lines]`
|
||||
were drawn without their brackets (the markdown renderer reads them as links with nowhere to
|
||||
go). They are drawn as code now; links, references and task boxes (`- [ ]`) are as before.
|
||||
|
||||
## [2.0.0-beta.21] — 2026-12-03
|
||||
|
||||
### Security
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lembas-cli",
|
||||
"version": "2.0.0-beta.21",
|
||||
"version": "2.0.0-beta.22",
|
||||
"description": "LLeMbas CLI: a terminal coding agent and project manager for a LLeMbas server — OpenTUI, memory, skills, MCP, git-native.",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
]
|
||||
},
|
||||
"transcript": {
|
||||
"description": "How the conversation is drawn: full — every tool call on its own line, a change with its diff; compact — a round of tool calls as one line (count, kinds, time; failures and refusals always said), a change as a stat line, the detail in the display pane; auto (default) — compact while the display pane stands beside it, full otherwise. Alt+T or /transcript switches.",
|
||||
"description": "How the conversation is drawn: both draw a round of tool calls as one line that follows the call running and then says what the round did (count, kinds, changes, time; failures and refusals always said, each on a line of its own); full adds each change's diff under its round, compact leaves the detail to the display pane; auto (default) — compact while the display pane stands beside it, full otherwise. Alt+T or /transcript switches.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"auto",
|
||||
|
||||
+7
-6
@@ -140,7 +140,7 @@ for (const [cols, rows] of [
|
||||
`firstRun=${firstRun} drawn=${drawn} asked=${asked} answered=${answered} file=${JSON.stringify(file)} exit=${code}\n${screen.join("\n")}`,
|
||||
)
|
||||
check(`TUI ${cols}x${rows}: nothing wider than the terminal`, wrapped.length === 0, `wrapped rows: ${wrapped.join(", ")}`)
|
||||
check(`TUI ${cols}x${rows}: status bar on the last row`, (screen[rows - 1] ?? "").includes("manual · fake/coder"), screen[rows - 1] ?? "")
|
||||
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
|
||||
@@ -164,7 +164,7 @@ for (const [cols, rows] of [
|
||||
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 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"))
|
||||
@@ -201,14 +201,15 @@ for (const [cols, rows] of [
|
||||
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))
|
||||
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"))
|
||||
// The full transcript draws the round as one line too (it adds diffs, and these calls have none).
|
||||
const full = left().some((l) => l.includes("✓ 2 tools · read · grep")) && !left().some((l) => /read +hello\.txt/.test(l))
|
||||
const fullScreen = d.screen()
|
||||
await d.key("\x1bt")
|
||||
const again = await d.waitFor("▸ 2 tools · read · grep")
|
||||
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.")
|
||||
@@ -225,7 +226,7 @@ for (const [cols, rows] of [
|
||||
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",
|
||||
"TUI 120x40: a tool round is one line beside the display and, after alt+t, in the full transcript too; and back",
|
||||
answered && compact && full && again,
|
||||
`answered=${answered} compact=${compact} full=${full} again=${again}\n${fullScreen.join("\n")}`,
|
||||
)
|
||||
|
||||
@@ -249,7 +249,7 @@ export const Config = z.strictObject({
|
||||
icons: z.enum(["emoji", "plain"]).optional().describe("emoji (default), or plain: one-column symbols for a terminal font that has no emoji."),
|
||||
displays: z.boolean().optional().describe("The display pane: live agent activity, files read, diffs, command output and pictures, at the right over the terminal's full height from 80 columns; on a narrower terminal Alt+D opens it in the transcript's place. Default true; Alt+D or /display toggles it."),
|
||||
images: z.enum(["auto", "on", "off"]).optional().describe("Pictures in the display's images tab (what view_image viewed, what was shown, what you attached): auto (default) — drawn the best way the terminal is found to support: the kitty graphics protocol (kitty, Ghostty), sixel, else coloured blocks; on — the kitty graphics protocol whatever was detected (a multiplexer with passthrough); off — never drawn: the name, size and path only."),
|
||||
transcript: z.enum(["auto", "full", "compact"]).optional().describe("How the conversation is drawn: full — every tool call on its own line, a change with its diff; compact — a round of tool calls as one line (count, kinds, time; failures and refusals always said), a change as a stat line, the detail in the display pane; auto (default) — compact while the display pane stands beside it, full otherwise. Alt+T or /transcript switches."),
|
||||
transcript: z.enum(["auto", "full", "compact"]).optional().describe("How the conversation is drawn: both draw a round of tool calls as one line that follows the call running and then says what the round did (count, kinds, changes, time; failures and refusals always said, each on a line of its own); full adds each change's diff under its round, compact leaves the detail to the display pane; auto (default) — compact while the display pane stands beside it, full otherwise. Alt+T or /transcript switches."),
|
||||
personality: z
|
||||
.enum(PERSONALITIES)
|
||||
.or(z.literal(""))
|
||||
|
||||
+5
-2
@@ -162,8 +162,9 @@ export function Root(p: { app: Runtime; view: View; theme: Theme; onQuit: () =>
|
||||
if (!bottom) {
|
||||
const top = box.content.getChildren().find((r) => r.id.startsWith("row-") && r.height > 0 && r.y + r.height > box.viewport.y)
|
||||
const id = top?.id.slice(4)
|
||||
// A call inside a round is found again as its round, and a round as its first call.
|
||||
if (id) target = toCompact ? (rowIdOf(groupRounds(view.state.items, { showReasoning: view.state.showReasoning })).get(id) ?? id) : id
|
||||
// Both transcripts draw the same rows (a round's id is its first call's): the row is found
|
||||
// again by its id, a call folded into a round as its round.
|
||||
if (id) target = rowIdOf(groupRounds(view.state.items, { showReasoning: view.state.showReasoning })).get(id) ?? id
|
||||
}
|
||||
}
|
||||
setCompact(toCompact)
|
||||
@@ -873,6 +874,8 @@ export function Root(p: { app: Runtime; view: View; theme: Theme; onQuit: () =>
|
||||
mcp={() => (rev(), mcpWord(app.mcp.servers.values()))}
|
||||
short={() => placement().left < STATUS_FULL_WIDTH}
|
||||
hint={() => (placement().mode === "tucked" ? "alt+d display" : "")}
|
||||
view={() => ({ display: showDisplays(), transcript: compact() ? "compact" : "full" })}
|
||||
onView={() => flash(toggleDisplay())}
|
||||
/>
|
||||
</box>
|
||||
</box>
|
||||
|
||||
+3
-3
@@ -95,8 +95,8 @@ const HELP_KEYS = [
|
||||
"esc stop the model · ctrl+g continue (after a stop, or to keep going) · ctrl+c clear, twice to quit · ctrl+d (empty box) quit",
|
||||
"/jobs background jobs: enter opens one (a subagent: esc back, type to message it), k stops it · ctrl+b moves the running command to the background",
|
||||
"shift+tab cycle mode (manual → edit → plan) · ctrl+r show reasoning · ctrl+o expand tool output",
|
||||
"alt+d the display (beside the conversation; on a narrow terminal in its place) · alt+↑/↓ its tab (live/files/changes/bash/images) · alt+←/→ entry · alt+pgup/pgdn scroll it · click a tab, wheel over it",
|
||||
"alt+t transcript full ↔ compact (compact: a round of tool calls is one line, the detail in the display)",
|
||||
"alt+d (or a click on the view chip at the status bar's end) the display (beside the conversation; on a narrow terminal in its place) · alt+↑/↓ its tab (live/files/changes/bash/images) · alt+←/→ entry · alt+pgup/pgdn scroll it · click a tab, wheel over it",
|
||||
"alt+t transcript full ↔ compact (a round of tool calls is one line in both; full adds each change's diff, compact leaves it to the display)",
|
||||
"pgup/pgdn scroll half a screen · ctrl+↑/↓ three lines · the mouse wheel · ↑ in an empty box takes back a message waiting to go in",
|
||||
]
|
||||
|
||||
@@ -221,7 +221,7 @@ export const COMMANDS: Command[] = [
|
||||
{
|
||||
name: "transcript",
|
||||
args: "[auto|full|compact]",
|
||||
description: "the conversation in full, or compact (a round of tool calls as one line) — auto: compact beside the display",
|
||||
description: "the conversation in full (each change's diff under its round) or compact (the diffs in the display) — auto: compact beside the display",
|
||||
run(c, arg) {
|
||||
if (!c.setTranscript) return c.view.info("the transcript cannot be switched here", "warn")
|
||||
const a = arg.trim().toLowerCase()
|
||||
|
||||
+175
-139
@@ -1,16 +1,17 @@
|
||||
import { TextAttributes } from "@opentui/core"
|
||||
import { createEffect, createMemo, createSignal, For, Match, onCleanup, Show, Switch } from "solid-js"
|
||||
import { createEffect, createMemo, createSignal, For, Index, Match, onCleanup, Show, Switch } from "solid-js"
|
||||
import { duration } from "../../duration.ts"
|
||||
import { estimateTokens } from "../../provider/tokens.ts"
|
||||
import { useTui } from "../context.ts"
|
||||
import type { Item } from "../state.ts"
|
||||
import { clipDiff } from "../diffclip.ts"
|
||||
import { callTitle } from "../../session/display.ts"
|
||||
import { callTitle, diffCounts } from "../../session/display.ts"
|
||||
import { num } from "../locale.ts"
|
||||
import { NOTICES } from "../notices.ts"
|
||||
import { pageNote, splitPages } from "../../pages/fence.ts"
|
||||
import { callAfter, groupRounds, patchStats, roundLine, roundTrouble, summarize, undrawn, type Round } from "../transcript.ts"
|
||||
import { callAfter, groupRounds, liveCall, patchStats, roundLine, roundTrouble, summarize, undrawn, type Round } from "../transcript.ts"
|
||||
import { clipEnd } from "../layout.ts"
|
||||
import { keepBrackets, steadyMarkdown } from "../steady.ts"
|
||||
|
||||
/** A row's id in the scrollbox, so the same place can be found again when the view changes. */
|
||||
export const rowId = (id: string) => `row-${id}`
|
||||
@@ -18,51 +19,65 @@ export const rowId = (id: string) => `row-${id}`
|
||||
const FILETYPES: Record<string, string> = { ts: "typescript", tsx: "typescript", js: "javascript", jsx: "javascript", mjs: "javascript", md: "markdown", zig: "zig" }
|
||||
export const filetypeOf = (diff: string) => FILETYPES[/^\+\+\+ \S*\.(\w+)/m.exec(diff)?.[1] ?? ""]
|
||||
|
||||
const BAR = { vertical: "▎", topLeft: "", topRight: "", bottomLeft: "", bottomRight: "", horizontal: "", topT: "", bottomT: "", leftT: "", rightT: "", cross: "" }
|
||||
|
||||
/** What the person sent: a shaded block with a bar in the prompt's colour, drawn as markdown as a
|
||||
* reply is — the prompt and the reply are told apart by the block, never by one showing its marks. */
|
||||
function UserMessage(p: { item: Extract<Item, { kind: "user" }> }) {
|
||||
const { theme } = useTui()
|
||||
const { theme, md } = useTui()
|
||||
const c = () => theme().colors
|
||||
return (
|
||||
<box border={["left"]} borderColor={theme().colors.userBar} customBorderChars={{ vertical: "┃", topLeft: "", topRight: "", bottomLeft: "", bottomRight: "", horizontal: "", topT: "", bottomT: "", leftT: "", rightT: "", cross: "" } as never} paddingLeft={1} marginTop={1}>
|
||||
<box flexDirection="column">
|
||||
<Show when={p.item.mid}>
|
||||
<text fg={theme().colors.dim} wrapMode="none" truncate>
|
||||
↳ sent while it worked
|
||||
</text>
|
||||
</Show>
|
||||
<text fg={theme().colors.text} wrapMode="word">
|
||||
{p.item.text}
|
||||
<box marginTop={1} flexShrink={0} border={["left"]} borderColor={c().userBar} customBorderChars={BAR as never} backgroundColor={c().panel} paddingLeft={1} paddingRight={1} flexDirection="column">
|
||||
<Show when={p.item.mid}>
|
||||
<text fg={c().dim} wrapMode="none" truncate>
|
||||
↳ sent while it worked
|
||||
</text>
|
||||
</box>
|
||||
</Show>
|
||||
<markdown content={keepBrackets(p.item.text.trim())} syntaxStyle={md()} fg={c().text} bg={c().panel} conceal />
|
||||
</box>
|
||||
)
|
||||
}
|
||||
|
||||
/** A reply as markdown — except a finished page fence (harness pages.md): a terminal cannot show
|
||||
* a page, so the note stands in its place, with where the page was saved (state.ts); while it
|
||||
* still streams it is the code block it is so far. */
|
||||
/** A reply as markdown, after the reply's mark — except a finished page fence (harness pages.md):
|
||||
* a terminal cannot show a page, so the note stands in its place, with where the page was saved
|
||||
* (state.ts); while it still streams it is the code block it is so far. While it streams it is
|
||||
* drawn steady (steady.ts): nothing half-read shows marks that would vanish a moment later. */
|
||||
function AssistantMessage(p: { item: Extract<Item, { kind: "assistant" }> }) {
|
||||
const { theme, md } = useTui()
|
||||
const c = () => theme().colors
|
||||
const drawn = (text: string, streaming: boolean) => keepBrackets(streaming ? steadyMarkdown(text) : text).trim()
|
||||
const segments = () => (p.item.text.includes("```") || p.item.text.includes("~~~") ? splitPages(p.item.text) : [])
|
||||
const whole = () => !segments().some((s) => s.kind === "page")
|
||||
return (
|
||||
<box paddingLeft={2} marginTop={1} flexDirection="column">
|
||||
<Show when={!whole()} fallback={<markdown content={p.item.text.trim()} syntaxStyle={md()} streaming={p.item.streaming} fg={theme().colors.text} conceal />}>
|
||||
<For each={segments()}>
|
||||
{(seg, i) => {
|
||||
const saved = () => (seg.kind === "page" && seg.closed ? (p.item.pages?.[seg.start] ?? { title: seg.title }) : undefined)
|
||||
const last = () => i() === segments().length - 1
|
||||
return (
|
||||
<Show
|
||||
when={saved()}
|
||||
fallback={<markdown content={(seg.kind === "text" ? seg.text : seg.raw).trim()} syntaxStyle={md()} streaming={p.item.streaming && last()} fg={theme().colors.text} conceal />}
|
||||
>
|
||||
<text fg={theme().colors.muted} wrapMode="word">
|
||||
{`${pageNote(saved()!.title)}${saved()!.path ? ` — saved to ${saved()!.path}` : ""}`}
|
||||
</text>
|
||||
</Show>
|
||||
)
|
||||
}}
|
||||
</For>
|
||||
</Show>
|
||||
<box marginTop={1} flexDirection="row" flexShrink={0}>
|
||||
<text fg={c().title} width={2} flexShrink={0} wrapMode="none">
|
||||
{theme().branding.responseMark}
|
||||
</text>
|
||||
<box flexDirection="column" flexGrow={1} flexShrink={1}>
|
||||
<Show when={!whole()} fallback={<markdown content={drawn(p.item.text, p.item.streaming)} syntaxStyle={md()} streaming={p.item.streaming} fg={c().text} conceal />}>
|
||||
{/* By place, not by object: the segments are made anew on every flush, and a keyed list
|
||||
would build every block again thirty times a second. */}
|
||||
<Index each={segments()}>
|
||||
{(seg, i) => {
|
||||
const saved = () => {
|
||||
const s = seg()
|
||||
return s.kind === "page" && s.closed ? (p.item.pages?.[s.start] ?? { title: s.title }) : undefined
|
||||
}
|
||||
const streaming = () => p.item.streaming && i === segments().length - 1
|
||||
return (
|
||||
<Show
|
||||
when={saved()}
|
||||
fallback={<markdown content={drawn(seg().kind === "text" ? (seg() as { text: string }).text : (seg() as { raw: string }).raw, streaming())} syntaxStyle={md()} streaming={streaming()} fg={c().text} conceal />}
|
||||
>
|
||||
<text fg={c().muted} wrapMode="word">
|
||||
{`${pageNote(saved()!.title)}${saved()!.path ? ` — saved to ${saved()!.path}` : ""}`}
|
||||
</text>
|
||||
</Show>
|
||||
)
|
||||
}}
|
||||
</Index>
|
||||
</Show>
|
||||
</box>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
@@ -88,13 +103,13 @@ function Reasoning(p: { item: Extract<Item, { kind: "reasoning" }>; tight?: bool
|
||||
const dots = () => ".".repeat(1 + (Math.floor((now() - p.item.started) / 400) % 3))
|
||||
const line = () => (p.item.streaming ? `Thinking${dots()}` : p.item.ms !== undefined ? `Thought for ${duration(p.item.ms)} · ${tokens()}` : `Thought · ${tokens()}`)
|
||||
return (
|
||||
<box paddingLeft={2} marginTop={p.tight ? 0 : 1} flexDirection="column">
|
||||
<box paddingLeft={2} marginTop={1} flexDirection="column">
|
||||
<text fg={theme().colors.reasoning} attributes={TextAttributes.ITALIC} wrapMode="none" truncate>
|
||||
{line()}
|
||||
</text>
|
||||
<Show when={view.state.showReasoning && !p.item.streaming}>
|
||||
<box paddingLeft={2}>
|
||||
<code filetype="markdown" content={p.item.text.trim()} syntaxStyle={thought()} drawUnstyledText conceal />
|
||||
<code filetype="markdown" content={keepBrackets(p.item.text.trim())} syntaxStyle={thought()} drawUnstyledText conceal />
|
||||
</box>
|
||||
</Show>
|
||||
</box>
|
||||
@@ -108,7 +123,7 @@ export function jobWords(j: { state: string; started: number; ended?: number; ex
|
||||
return `${j.state}${j.state !== "lost" && j.exit !== undefined && j.exit !== null && j.exit !== 0 ? ` (exit ${j.exit})` : ""} · ${took}`
|
||||
}
|
||||
|
||||
/** `brief` (the compact transcript): the call's line alone — no diff and no output under it
|
||||
/** One call in full (a round opened with ctrl+o). `brief`: the call's line alone — no diff and no output under it
|
||||
* unless ctrl+o opened them, and of a subagent's lines only the newest. */
|
||||
function ToolLine(p: { item: Extract<Item, { kind: "tool" }>; brief?: boolean }) {
|
||||
const { theme, view } = useTui()
|
||||
@@ -125,7 +140,7 @@ function ToolLine(p: { item: Extract<Item, { kind: "tool" }>; brief?: boolean })
|
||||
// Short in the transcript, whole with ctrl+o; always a diff the renderer can parse.
|
||||
const shown = () => (view.state.expandTools ? { diff: p.item.diff ?? "", hidden: 0 } : clipDiff(p.item.diff ?? "", 24))
|
||||
return (
|
||||
<box flexDirection="column" paddingLeft={1}>
|
||||
<box flexDirection="column" paddingLeft={2}>
|
||||
<text wrapMode="none" truncate>
|
||||
<span style={{ fg: c().dim }}>{theme().branding.toolPrefix} </span>
|
||||
{emoji()}{" "}
|
||||
@@ -238,7 +253,7 @@ function Notice(p: { item: Extract<Item, { kind: "notice" }> }) {
|
||||
// One table says what each kind of line looks like (tui/notices.ts).
|
||||
const kind = () => NOTICES[p.item.level]
|
||||
return (
|
||||
<box paddingLeft={1}>
|
||||
<box paddingLeft={2}>
|
||||
<text fg={theme().colors[kind().color]} wrapMode="word">
|
||||
{kind().glyph} {p.item.text}
|
||||
</text>
|
||||
@@ -249,7 +264,7 @@ function Notice(p: { item: Extract<Item, { kind: "notice" }> }) {
|
||||
function ErrorLine(p: { item: Extract<Item, { kind: "error" }> }) {
|
||||
const { theme } = useTui()
|
||||
return (
|
||||
<box paddingLeft={1} marginTop={1}>
|
||||
<box paddingLeft={2} marginTop={1}>
|
||||
<text fg={theme().colors[NOTICES.error.color]} wrapMode="word">
|
||||
{NOTICES.error.glyph} {p.item.text}
|
||||
</text>
|
||||
@@ -262,7 +277,7 @@ function EndLine(p: { item: Extract<Item, { kind: "end" }> }) {
|
||||
const { theme } = useTui()
|
||||
const fg = () => (p.item.failed ? theme().colors.error : theme().colors.muted)
|
||||
return (
|
||||
<box paddingLeft={1} marginTop={p.item.failed ? 1 : 0} flexDirection="column">
|
||||
<box paddingLeft={2} marginTop={p.item.failed ? 1 : 0} flexDirection="column">
|
||||
<text fg={fg()} wrapMode="word">
|
||||
{p.item.failed ? `${NOTICES.error.glyph} ` : "■ "}
|
||||
{p.item.line}
|
||||
@@ -315,7 +330,7 @@ export function ItemRow(p: { item: Item; compact?: boolean }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** A multi-file diff in the compact transcript: its title and a stat line per file. */
|
||||
/** A multi-file diff (/diff) in the compact transcript: its title and a stat line per file. */
|
||||
function DiffStats(p: { item: Extract<Item, { kind: "diff" }> }) {
|
||||
const { theme } = useTui()
|
||||
const c = () => theme().colors
|
||||
@@ -330,12 +345,12 @@ function DiffStats(p: { item: Extract<Item, { kind: "diff" }> }) {
|
||||
}
|
||||
|
||||
/** `path +12 −3`: a change without its diff (display.md §2's facts; the minus is U+2212). */
|
||||
function StatLine(p: { path: string; added: number; removed: number }) {
|
||||
function StatLine(p: { path: string; added: number; removed: number; indent?: string }) {
|
||||
const { theme } = useTui()
|
||||
const c = () => theme().colors
|
||||
return (
|
||||
<text wrapMode="none" truncate>
|
||||
<span style={{ fg: c().dim }}>{" "}</span>
|
||||
<span style={{ fg: c().dim }}>{p.indent ?? " "}</span>
|
||||
<span style={{ fg: c().text }}>{p.path}</span>
|
||||
<span style={{ fg: c().diffAddedSign }}>{` +${num(p.added)}`}</span>
|
||||
<span style={{ fg: c().diffRemovedSign }}>{` −${num(p.removed)}`}</span>
|
||||
@@ -343,86 +358,130 @@ function StatLine(p: { path: string; added: number; removed: number }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** The most stat lines a round shows before it says how many more there are. */
|
||||
const ROUND_CHANGES = 4
|
||||
|
||||
/** A tool round in the compact transcript. One call is its own line. Several are one line —
|
||||
* `▸ 7 tools · read ×3 · bash ×2 · edit ×2 · 14.0s` — and under it only what must not be missed:
|
||||
* every failure and every refusal with its first line, every call still running, each change as
|
||||
* a stat line. Ctrl+O opens the round into its calls as the full transcript draws them. */
|
||||
function RoundRow(p: { round: () => Round | undefined }) {
|
||||
/** A tool round: one line, in both transcripts. While it runs the line follows it — a spinner,
|
||||
* the call running now and what it is doing, how many calls the round has made — and once it is
|
||||
* done it says what the round did: `✓ 7 tools · read ×3 · bash ×2 · edit ×2 · +12 −3 in 2 files ·
|
||||
* 14.0s`; a round of one call is that call's own line (`✓ read src/app.ts · 1–40 of 120 · 0.1s`).
|
||||
* Under it only what must not be missed: each failure and refusal with its first line, and a
|
||||
* background job still running. `full` (the full transcript, where nothing stands beside it) adds
|
||||
* each change's diff, clipped. Ctrl+O opens the round into its calls, every one in full. */
|
||||
function RoundRow(p: { round: () => Round | undefined; full?: boolean }) {
|
||||
const { theme, view, dims } = useTui()
|
||||
const c = () => theme().colors
|
||||
/** The columns a line of the row has: the column it stands in, less the transcript's own
|
||||
* padding and scrollbar and the row's indent — known, so nothing is cut in the middle. */
|
||||
const width = () => Math.max(8, dims().width - 3)
|
||||
const trouble = () => roundTrouble(sum())
|
||||
const troubleWidth = () => (trouble().failed ? trouble().failed.length + 3 : 0) + (trouble().denied ? trouble().denied.length + 3 : 0)
|
||||
const tools = () => p.round()?.tools ?? []
|
||||
const sum = createMemo(() => summarize({ tools: tools() }))
|
||||
const running = () => sum().running.length > 0
|
||||
const [tick, setTick] = createSignal(0)
|
||||
createEffect(() => {
|
||||
if (!running()) return
|
||||
const t = setInterval(() => setTick((n) => n + 1), 100)
|
||||
onCleanup(() => clearInterval(t))
|
||||
})
|
||||
/** The columns the line has: the column it stands in, less the transcript's padding and
|
||||
* scrollbar, the row's indent and its mark — known, so nothing is cut in the middle. */
|
||||
const width = () => Math.max(8, dims().width - 6)
|
||||
const trouble = () => roundTrouble(sum())
|
||||
const troubleText = () => `${trouble().failed ? ` · ${trouble().failed}` : ""}${trouble().denied ? ` · ${trouble().denied}` : ""}`
|
||||
const title = (t: Extract<Item, { kind: "tool" }>) => t.title ?? callTitle(t.args) ?? ""
|
||||
const one = () => (tools().length === 1 ? tools()[0] : undefined)
|
||||
const mark = () => {
|
||||
const s = sum()
|
||||
if (s.running.length) return { glyph: theme().spinner.frames[tick() % theme().spinner.frames.length] ?? "…", fg: c().accent }
|
||||
if (s.failed.length) return { glyph: NOTICES.error.glyph, fg: c().error }
|
||||
if (s.denied.length === s.count) return { glyph: "⊘", fg: c().warn }
|
||||
return { glyph: NOTICES.success.glyph, fg: c().ok }
|
||||
}
|
||||
/** The line in three parts — a tool's name, what it works on, the facts — fitted to the width:
|
||||
* the words give way first, from their end. */
|
||||
const line = createMemo(() => {
|
||||
const s = sum()
|
||||
const w = width()
|
||||
if (s.running.length) {
|
||||
const live = liveCall({ tools: tools() })
|
||||
const facts = s.count > 1 ? `${s.count} tools` : ""
|
||||
const words = [live?.title, live?.child].filter(Boolean).join(" · ")
|
||||
const name = live?.name ?? ""
|
||||
return { name, words: clipEnd(words, w - Bun.stringWidth(name) - 1 - (facts ? facts.length + 3 : 0)), facts, trouble: "" }
|
||||
}
|
||||
const t = one()
|
||||
if (t) {
|
||||
// A failure's or refusal's first line is in the facts already: nothing under the line.
|
||||
const facts = callAfter(t)
|
||||
const room = w - Bun.stringWidth(t.name) - 1 - (facts ? Bun.stringWidth(facts) + 3 : 0)
|
||||
return { name: t.name, words: clipEnd(title(t), Math.max(8, room)), facts, trouble: "" }
|
||||
}
|
||||
return { name: "", words: roundLine(s, w - troubleText().length), facts: "", trouble: troubleText() }
|
||||
})
|
||||
const open = () => view.state.expandTools
|
||||
const jobs = () => tools().filter((t) => t.job && t.job.state === "running")
|
||||
/** Under a round of several calls: each that failed or was refused, with its first line. */
|
||||
const troubled = () => (one() ? [] : [...sum().failed, ...sum().denied])
|
||||
const changed = () => tools().filter((t) => t.diff && t.status === "done")
|
||||
return (
|
||||
<Show when={tools().length > 1} fallback={<For each={tools()}>{(t) => <ToolLine item={t} brief />}</For>}>
|
||||
<box flexDirection="column" paddingLeft={1}>
|
||||
<text wrapMode="none" truncate>
|
||||
<span style={{ fg: sum().running.length ? c().accent : c().dim }}>{sum().running.length ? "◐ " : "▸ "}</span>
|
||||
<span style={{ fg: c().label }}>{roundLine(sum(), width() - 2 - troubleWidth())}</span>
|
||||
<span style={{ fg: c().error }}>{trouble().failed ? ` · ${trouble().failed}` : ""}</span>
|
||||
<span style={{ fg: c().warn }}>{trouble().denied ? ` · ${trouble().denied}` : ""}</span>
|
||||
</text>
|
||||
<Show
|
||||
when={!view.state.expandTools}
|
||||
fallback={
|
||||
<box flexDirection="column" paddingLeft={1}>
|
||||
<For each={tools()}>{(t) => <ToolLine item={t} />}</For>
|
||||
</box>
|
||||
}
|
||||
>
|
||||
<For each={sum().changes.slice(0, ROUND_CHANGES)}>{(ch) => <StatLine path={ch.path} added={ch.added} removed={ch.removed} />}</For>
|
||||
<Show when={sum().changes.length > ROUND_CHANGES}>
|
||||
<text fg={c().muted} wrapMode="none" truncate>
|
||||
{` … ${sum().changes.length - ROUND_CHANGES} more change${sum().changes.length - ROUND_CHANGES === 1 ? "" : "s"} (ctrl+o)`}
|
||||
<box flexDirection="column" paddingLeft={2} marginTop={1} flexShrink={0}>
|
||||
<text wrapMode="none" truncate>
|
||||
<span style={{ fg: mark().fg }}>{`${mark().glyph} `}</span>
|
||||
<span style={{ fg: running() ? c().label : one()?.status === "denied" ? c().warn : c().muted, attributes: one()?.status === "denied" ? TextAttributes.STRIKETHROUGH : 0 }}>{line().name}</span>
|
||||
<span style={{ fg: running() ? c().text : one()?.status === "error" ? c().error : c().dim }}>{`${line().name && line().words ? " " : ""}${line().words}`}</span>
|
||||
<span style={{ fg: one()?.status === "error" ? c().error : one()?.status === "denied" ? c().warn : c().dim }}>{line().facts ? ` · ${line().facts}` : ""}</span>
|
||||
<span style={{ fg: trouble().failed ? c().error : c().warn }}>{line().trouble}</span>
|
||||
</text>
|
||||
<Show
|
||||
when={!open()}
|
||||
fallback={
|
||||
<box flexDirection="column">
|
||||
<For each={tools()}>{(t) => <ToolLine item={t} />}</For>
|
||||
</box>
|
||||
}
|
||||
>
|
||||
<For each={troubled()}>
|
||||
{(t) => (
|
||||
<text wrapMode="none">
|
||||
<span style={{ fg: t.status === "denied" ? c().warn : c().error }}>{t.status === "denied" ? " ⊘ " : ` ${NOTICES.error.glyph} `}</span>
|
||||
<span style={{ fg: c().muted }}>{t.name}</span>
|
||||
<span style={{ fg: t.status === "denied" ? c().warn : c().error }}>{clipEnd(`${title(t) ? ` ${title(t)}` : ""}${callAfter(t) ? ` · ${callAfter(t)}` : ""}`, width() - 4 - t.name.length)}</span>
|
||||
</text>
|
||||
</Show>
|
||||
<For each={[...sum().failed, ...sum().denied]}>
|
||||
{(t) => (
|
||||
<text wrapMode="none">
|
||||
<span style={{ fg: t.status === "denied" ? c().warn : c().error }}>{t.status === "denied" ? " ⊘ " : " ✗ "}</span>
|
||||
<span style={{ fg: c().label }}>{t.name}</span>
|
||||
<span style={{ fg: t.status === "denied" ? c().warn : c().error }}>{clipEnd(`${title(t) ? ` ${title(t)}` : ""}${callAfter(t) ? ` · ${callAfter(t)}` : ""}`, width() - 6 - t.name.length)}</span>
|
||||
</text>
|
||||
)}
|
||||
</For>
|
||||
<For each={sum().running}>
|
||||
{(t) => (
|
||||
<text wrapMode="none" truncate>
|
||||
<span style={{ fg: c().accent }}>{" ◐ "}</span>
|
||||
<span style={{ fg: c().label }}>{t.name}</span>
|
||||
<span style={{ fg: c().text }}>{title(t) ? ` ${title(t)}` : ""}</span>
|
||||
<span style={{ fg: c().dim }}>{t.children?.length ? ` · ${t.children[t.children.length - 1]!.name} ${t.children[t.children.length - 1]!.title}` : " …"}</span>
|
||||
</text>
|
||||
)}
|
||||
</For>
|
||||
<For each={jobs()}>
|
||||
{(t) => (
|
||||
<text wrapMode="none" truncate>
|
||||
<span style={{ fg: c().dim }}>{" → "}</span>
|
||||
<span style={{ fg: c().label }}>{t.job!.id}</span>
|
||||
<span style={{ fg: c().muted }}>{` (${t.job!.agent ? `${t.job!.agent}: ` : ""}${t.job!.description})`}</span>
|
||||
<span style={{ fg: c().accent }}>{` ${jobWords(t.job!)}`}</span>
|
||||
</text>
|
||||
)}
|
||||
)}
|
||||
</For>
|
||||
<For each={jobs()}>
|
||||
{(t) => (
|
||||
<text wrapMode="none" truncate>
|
||||
<span style={{ fg: c().dim }}>{" → "}</span>
|
||||
<span style={{ fg: c().label }}>{t.job!.id}</span>
|
||||
<span style={{ fg: c().muted }}>{` (${t.job!.agent ? `${t.job!.agent}: ` : ""}${t.job!.description})`}</span>
|
||||
<span style={{ fg: c().accent }}>{` ${jobWords(t.job!)}`}</span>
|
||||
</text>
|
||||
)}
|
||||
</For>
|
||||
<Show when={p.full}>
|
||||
<For each={changed()}>
|
||||
{(t) => {
|
||||
const shown = () => clipDiff(t.diff ?? "", 24)
|
||||
return (
|
||||
<box flexDirection="column" paddingLeft={2} paddingRight={1}>
|
||||
<Show when={!one()}>
|
||||
<StatLine path={title(t) || t.name} added={diffCounts(t.diff!).added} removed={diffCounts(t.diff!).removed} indent="" />
|
||||
</Show>
|
||||
<WrappedDiff patch={shown().diff} filetype={filetypeOf(t.diff!)} />
|
||||
<Show when={shown().hidden > 0}>
|
||||
<text fg={c().muted}>{`… ${shown().hidden} more line${shown().hidden === 1 ? "" : "s"} (ctrl+o)`}</text>
|
||||
</Show>
|
||||
</box>
|
||||
)
|
||||
}}
|
||||
</For>
|
||||
</Show>
|
||||
</box>
|
||||
</Show>
|
||||
</Show>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
|
||||
/** The compact transcript: the same items, tool rounds grouped (transcript.ts). */
|
||||
function CompactMessages() {
|
||||
const { view } = useTui()
|
||||
/** The conversation (`compact` of the context: the `transcript` setting, and whether the display
|
||||
* pane stands beside it). Both transcripts draw the same rows — a tool round is one line in
|
||||
* each; the full one adds each change's diff under its round, which the compact one leaves to
|
||||
* the display. */
|
||||
export function Messages() {
|
||||
const { view, compact } = useTui()
|
||||
const rows = createMemo(() => groupRounds(view.state.items, { showReasoning: view.state.showReasoning }))
|
||||
const rounds = createMemo(() => new Map(rows().flatMap((r) => (r.kind === "round" ? [[r.id, r] as const] : []))))
|
||||
// One object per round for as long as it exists, so a round that grows is updated, not redrawn.
|
||||
@@ -437,43 +496,20 @@ function CompactMessages() {
|
||||
return ref
|
||||
})
|
||||
})
|
||||
const full = () => !compact?.()
|
||||
return (
|
||||
<For each={list()}>
|
||||
{(row) =>
|
||||
"round" in row ? (
|
||||
<box id={rowId(row.round)} flexDirection="column" flexShrink={0}>
|
||||
<RoundRow round={() => rounds().get(row.round)} />
|
||||
<RoundRow round={() => rounds().get(row.round)} full={full()} />
|
||||
</box>
|
||||
) : (
|
||||
<box id={rowId(row.id)} flexDirection="column" flexShrink={0}>
|
||||
<ItemRow item={row} compact />
|
||||
<ItemRow item={row} compact={!full()} />
|
||||
</box>
|
||||
)
|
||||
}
|
||||
</For>
|
||||
)
|
||||
}
|
||||
|
||||
function FullMessages() {
|
||||
const { view } = useTui()
|
||||
return (
|
||||
<For each={view.state.items}>
|
||||
{(item) => (
|
||||
<box id={rowId(item.id)} flexDirection="column" flexShrink={0}>
|
||||
<ItemRow item={item} />
|
||||
</box>
|
||||
)}
|
||||
</For>
|
||||
)
|
||||
}
|
||||
|
||||
/** The conversation, full or compact (`compact` of the context: the `transcript` setting, and
|
||||
* whether the display pane stands beside it). Both are views over the same items. */
|
||||
export function Messages() {
|
||||
const { compact } = useTui()
|
||||
return (
|
||||
<Show when={compact?.()} fallback={<FullMessages />}>
|
||||
<CompactMessages />
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
@@ -70,7 +70,7 @@ export function Spinner() {
|
||||
return "waiting for the model"
|
||||
}
|
||||
return (
|
||||
<box paddingLeft={1} height={1}>
|
||||
<box paddingLeft={2} height={1}>
|
||||
<text wrapMode="none" truncate>
|
||||
<span style={{ fg: theme().colors.accent }}>{pick(sp().frames, 1)} </span>
|
||||
<span style={{ fg: theme().colors.muted }}>{what()}{view.state.now ? " · " : "… "}</span>
|
||||
@@ -91,7 +91,7 @@ export function Queued() {
|
||||
return (
|
||||
<For each={view.state.queued.texts}>
|
||||
{(text) => (
|
||||
<box paddingLeft={1} height={1}>
|
||||
<box paddingLeft={2} height={1}>
|
||||
<text wrapMode="none" truncate>
|
||||
<span style={{ fg: theme().colors.accent }}>↳ queued </span>
|
||||
<span style={{ fg: theme().colors.text }}>{text.split("\n")[0]}</span>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { basename } from "node:path"
|
||||
import { TextAttributes } from "@opentui/core"
|
||||
import { Show } from "solid-js"
|
||||
import { isLocal } from "../../config/paths.ts"
|
||||
import { useTui } from "../context.ts"
|
||||
@@ -40,13 +41,25 @@ export function contextWords(state: { usage?: { input: number; output: number; e
|
||||
* keeps what must stay in sight (the jobs, how full the context is, `local`) and leaves the rest
|
||||
* to the pane's header and the welcome box. `hint`: a word of the display's (a narrow terminal:
|
||||
* that there is one, and the key that opens it). */
|
||||
export function StatusBar(p: { mode: () => string; model: () => string; effort: () => string; branch?: string; voice?: () => string; flash?: () => string | undefined; remote?: () => string; spend?: () => string; team?: () => string; mcp?: () => { text: string; warn: boolean }; short?: () => boolean; hint?: () => string }) {
|
||||
/** From this many columns inside the bar, the view chip says its view and key in words. */
|
||||
export const CHIP_WORDS_WIDTH = 118
|
||||
|
||||
/** The view chip at the bar's end: which view is drawn — the display beside the transcript, or
|
||||
* the transcript alone, full or compact — and, clicked, the other (alt+d). */
|
||||
export function viewChip(o: { display: boolean; transcript: "full" | "compact"; short: boolean }): string {
|
||||
const what = o.display ? "◧ display" : `▤ ${o.transcript}`
|
||||
return o.short ? (o.display ? "◧" : "▤") : `${what} · alt+d`
|
||||
}
|
||||
|
||||
export function StatusBar(p: { mode: () => string; model: () => string; effort: () => string; branch?: string; voice?: () => string; flash?: () => string | undefined; remote?: () => string; spend?: () => string; team?: () => string; mcp?: () => { text: string; warn: boolean }; short?: () => boolean; hint?: () => string; view?: () => { display: boolean; transcript: "full" | "compact" }; onView?: () => void }) {
|
||||
const { theme, view, app, dims } = useTui()
|
||||
const c = () => theme().colors
|
||||
/** The bar's columns inside its padding. A flash never runs past them, and takes the whole bar
|
||||
* when the two sides would not both fit. */
|
||||
const room = () => Math.max(1, dims().width - 2)
|
||||
const flashOnly = () => !!p.flash?.() && Bun.stringWidth(p.flash()!) + 22 > room()
|
||||
// Its words only where the bar has room to spare: at 80 columns they would cut the model's name.
|
||||
const chip = () => (p.view ? viewChip({ ...p.view(), short: short() || room() < CHIP_WORDS_WIDTH }) : "")
|
||||
const modeColor = () => ({ manual: c().statusText, edit: c().statusGood, auto: c().statusCritical, plan: c().info })[p.mode() as keyof typeof MODE_LABEL] ?? c().statusText
|
||||
const short = () => p.short?.() === true
|
||||
const ctx = () => {
|
||||
@@ -57,13 +70,15 @@ export function StatusBar(p: { mode: () => string; model: () => string; effort:
|
||||
return (
|
||||
<box height={1} flexDirection="row" justifyContent="space-between" backgroundColor={c().panel} paddingLeft={1} paddingRight={1}>
|
||||
<text wrapMode="none" truncate visible={!flashOnly()}>
|
||||
<span style={{ fg: modeColor() }}>{MODE_LABEL[p.mode() as keyof typeof MODE_LABEL] ?? p.mode()}</span>
|
||||
<span style={{ fg: c().statusDim }}> · </span>
|
||||
{/* The mode as a chip: the one word on the bar that changes what the agent may do. */}
|
||||
<span style={{ fg: c().panel, bg: modeColor(), attributes: TextAttributes.BOLD }}>{` ${MODE_LABEL[p.mode() as keyof typeof MODE_LABEL] ?? p.mode()} `}</span>
|
||||
<span style={{ fg: c().statusDim }}> </span>
|
||||
<span style={{ fg: c().statusStrong }}>{p.model()}</span>
|
||||
<span style={{ fg: c().statusDim }}>{p.effort() ? ` · ${p.effort()}` : ""}</span>
|
||||
<span style={{ fg: p.voice?.().startsWith("●") ? c().statusCritical : c().statusText }}>{p.voice?.() ? ` · ${p.voice()}` : ""}</span>
|
||||
<span style={{ fg: c().info }}>{p.remote?.() ? ` · ${p.remote()}` : ""}</span>
|
||||
</text>
|
||||
<box flexDirection="row" flexShrink={0}>
|
||||
<Show
|
||||
when={p.flash?.()}
|
||||
fallback={
|
||||
@@ -84,6 +99,15 @@ export function StatusBar(p: { mode: () => string; model: () => string; effort:
|
||||
{clipEnd(p.flash?.() ?? "", room())}
|
||||
</text>
|
||||
</Show>
|
||||
<Show when={chip() && !flashOnly()}>
|
||||
{/* Clicked: the other view, as alt+d. */}
|
||||
<box flexShrink={0} marginLeft={1} onMouseDown={() => p.onView?.()}>
|
||||
<text wrapMode="none">
|
||||
<span style={{ fg: p.view?.().display ? c().panel : c().statusText, bg: p.view?.().display ? c().accent : c().selection }}>{` ${chip()} `}</span>
|
||||
</text>
|
||||
</box>
|
||||
</Show>
|
||||
</box>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,17 +10,19 @@ export function Welcome() {
|
||||
const c = () => theme().colors
|
||||
return (
|
||||
<box border borderStyle="rounded" borderColor={c().border} flexDirection="column" paddingLeft={1} paddingRight={1} marginTop={1} flexShrink={0}>
|
||||
<text fg={c().title} attributes={TextAttributes.BOLD}>
|
||||
{theme().branding.agentName} <span style={{ fg: c().dim, attributes: 0 }}>{VERSION}</span>
|
||||
<text fg={c().title} attributes={TextAttributes.BOLD} wrapMode="none" truncate>
|
||||
{theme().branding.responseMark} {theme().branding.agentName}
|
||||
<span style={{ fg: c().dim, attributes: 0 }}>{` ${VERSION}`}</span>
|
||||
</text>
|
||||
{/* The labels in one column: known widths, so the values line up whatever they say. */}
|
||||
<text fg={c().text} wrapMode="none" truncate>
|
||||
<span style={{ fg: c().label }}>model </span>
|
||||
<span style={{ fg: c().dim }}>{"model "}</span>
|
||||
{app.engine.model.ref}
|
||||
</text>
|
||||
<text fg={c().text} wrapMode="none" truncate>
|
||||
<span style={{ fg: c().label }}>project </span>
|
||||
<span style={{ fg: c().dim }}>{"project "}</span>
|
||||
{app.project.root}
|
||||
<span style={{ fg: c().dim }}>{app.project.gitRoot ? " (git)" : " (no git)"}</span>
|
||||
<span style={{ fg: c().dim }}>{app.project.gitRoot ? " · git" : " · no git"}</span>
|
||||
</text>
|
||||
<Show when={!app.trusted}>
|
||||
<text fg={c().warn} wrapMode="word">
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ export interface Ctx {
|
||||
/** Terminal size, from ONE resize subscription in Root: per-item subscriptions leaked listeners
|
||||
* (and Node's warning about them printed over the screen). */
|
||||
dims: () => { width: number; height: number }
|
||||
/** The compact transcript is drawn (tool rounds grouped); unset: the full one. */
|
||||
/** The compact transcript is drawn (the diffs left to the display); unset: the full one. */
|
||||
compact?: () => boolean
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -60,7 +60,8 @@ export interface Theme {
|
||||
type: string
|
||||
comment: string
|
||||
}
|
||||
branding: { agentName: string; responseLabel: string; promptSymbol: string; toolPrefix: string }
|
||||
/** `responseMark`: the mark before each of the reply's blocks, which sets it apart from the prompt and the tools. */
|
||||
branding: { agentName: string; responseLabel: string; responseMark: string; promptSymbol: string; toolPrefix: string }
|
||||
/** The line while the model works: a frame every tick, a verb while it thinks. */
|
||||
spinner: { verbs: string[]; frames: string[] }
|
||||
toolEmoji: Record<string, string>
|
||||
@@ -111,7 +112,7 @@ export const HERMES: Theme = {
|
||||
type: "#DAA520",
|
||||
comment: "#C0C0C0",
|
||||
},
|
||||
branding: { agentName: "LLeMbas", responseLabel: " LLeMbas ", promptSymbol: "❯", toolPrefix: "┊" },
|
||||
branding: { agentName: "LLeMbas", responseLabel: " LLeMbas ", responseMark: "◆", promptSymbol: "❯", toolPrefix: "┊" },
|
||||
spinner: {
|
||||
verbs: ["pondering", "contemplating", "musing", "cogitating", "ruminating", "deliberating", "mulling", "reflecting", "reasoning", "analyzing", "synthesizing", "formulating"],
|
||||
frames: ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
// A reply that is still streaming, as it is drawn. Markdown read halfway is not the markdown it
|
||||
// will be: `**bo` is two asterisks until the closing pair arrives, a lone backtick may become a
|
||||
// fence, `| a | b |` is a paragraph until the line under it makes it a table. Drawn as they come,
|
||||
// such pieces show their marks, then lose them — the line jumps, a block blanks and comes back.
|
||||
// So the text drawn while it streams is a steady one: what is open is closed, what may still turn
|
||||
// into something else waits for the line that decides it. Only the drawing: the reply itself,
|
||||
// what is copied and what is stored are the text as it came. Pure.
|
||||
|
||||
const FENCE_OPEN = /^ {0,3}(`{3,}|~{3,})(.*)$/
|
||||
/** A line that may still become a fence: only backticks or tildes so far, three or fewer. */
|
||||
const FENCE_START = /^ {0,3}(`{1,3}|~{1,3})$/
|
||||
/** A table's delimiter row: `|---|:--:|`, with or without the outer pipes. */
|
||||
const DELIMITER = /^ {0,3}\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/
|
||||
const TABLE_ROW = /^ {0,3}\|/
|
||||
/** A data row whose first cell is complete: `| 1 |`. */
|
||||
const FIRST_CELL = /^ {0,3}\|?\s*[^|\s][^|]*\|/
|
||||
/** A heading being written: `#`, `## Pl`. */
|
||||
const HEADING = /^ {0,3}#{1,6}(\s|$)/
|
||||
/** A list or quote mark with nothing after it yet. */
|
||||
const BARE_MARK = /^ {0,3}([-*+]|\d{1,9}[.)]|>)\s*$/
|
||||
|
||||
const isFenceClose = (line: string, fence: string) => new RegExp(`^ {0,3}${fence[0] === "`" ? "`" : "~"}{${fence.length},}\\s*$`).test(line)
|
||||
|
||||
/** The streaming text made steady (see above). `text` as it is when nothing in it is open. */
|
||||
export function steadyMarkdown(text: string): string {
|
||||
const lines = text.split("\n")
|
||||
// The line being written: the last one (complete lines end with "\n", so after one it is "").
|
||||
const last = lines.pop() ?? ""
|
||||
// Where the complete lines leave the reader: inside a fence (which one) or not.
|
||||
let fence: string | undefined
|
||||
for (const line of lines) {
|
||||
if (fence) {
|
||||
if (isFenceClose(line, fence)) fence = undefined
|
||||
continue
|
||||
}
|
||||
const open = FENCE_OPEN.exec(line)
|
||||
if (open && !(open[1]![0] === "`" && open[2]!.includes("`"))) fence = open[1]!
|
||||
}
|
||||
if (fence) {
|
||||
// In a code block: it is closed for the drawing. A line that may be its closing fence waits.
|
||||
const body = isFencePrefix(last, fence) ? lines : [...lines, last]
|
||||
return `${body.join("\n")}\n${fence}`
|
||||
}
|
||||
// A fence being opened (its marks so far, or its info string before the newline): it waits for
|
||||
// the newline, and is drawn from then on as a closed block.
|
||||
if (FENCE_START.test(last) || FENCE_OPEN.test(last)) return trimEnd(lines).join("\n")
|
||||
// A table: its rows wait until the delimiter row under the header is complete.
|
||||
const table = pendingTable(lines, last)
|
||||
if (table !== undefined) return trimEnd(lines.slice(0, table)).join("\n")
|
||||
// A heading is drawn whole, once its line is: its marks would show until it is read as one.
|
||||
if (HEADING.test(last) || BARE_MARK.test(last)) return trimEnd(lines).join("\n")
|
||||
return [...lines, closeInline(last)].join("\n")
|
||||
}
|
||||
|
||||
/** Square brackets that are not a link, kept as they are written. The markdown renderer reads
|
||||
* `[Pasted text 40 lines]`, `[Image 2]` or `[1]` as a link with nowhere to go and draws it
|
||||
* without its brackets (its grammar conceals them; an escape's backslash it would show). In a
|
||||
* code span they stay. Code — fenced or in backticks — is left alone, and so is a real link or
|
||||
* image (`[words](url)`), a reference and its definition, and a task's `[ ]` / `[x]`. */
|
||||
export function keepBrackets(text: string): string {
|
||||
if (!text.includes("[")) return text
|
||||
let fence: string | undefined
|
||||
return text
|
||||
.split("\n")
|
||||
.map((line) => {
|
||||
if (fence) {
|
||||
if (isFenceClose(line, fence)) fence = undefined
|
||||
return line
|
||||
}
|
||||
const open = FENCE_OPEN.exec(line)
|
||||
if (open && !(open[1]![0] === "`" && open[2]!.includes("`"))) {
|
||||
fence = open[1]!
|
||||
return line
|
||||
}
|
||||
// Outside code spans only: the odd pieces between backtick runs are code.
|
||||
return line
|
||||
.split(/(`+[^`]*`+)/)
|
||||
.map((part, i, parts) =>
|
||||
i % 2
|
||||
? part
|
||||
: part.replace(/(?<![\\!\]])\[([^[\]\n`]+)\](?![([:])/g, (m: string, _label: string, at: number) => {
|
||||
// A task's box: `- [ ] …` at the start of a list item.
|
||||
const before = parts.slice(0, i).join("") + part.slice(0, at)
|
||||
if (/^\s*([-*+]|\d{1,9}[.)])\s+$/.test(before) && /^\[[ xX]\]$/.test(m)) return m
|
||||
return `\`${m}\``
|
||||
}),
|
||||
)
|
||||
.join("")
|
||||
})
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
/** A partial line that may become `fence`'s closing line. */
|
||||
function isFencePrefix(line: string, fence: string): boolean {
|
||||
const t = line.trimStart()
|
||||
return line.length - t.length <= 3 && t.length > 0 && [...t].every((ch) => ch === fence[0])
|
||||
}
|
||||
|
||||
/** Blank lines at the end go: what follows them is not drawn yet, and a gap would open and close. */
|
||||
function trimEnd(lines: string[]): string[] {
|
||||
let n = lines.length
|
||||
while (n > 0 && !lines[n - 1]!.trim()) n--
|
||||
return lines.slice(0, n)
|
||||
}
|
||||
|
||||
/** Where a table whose delimiter row is not complete yet starts (an index into `lines`, the
|
||||
* complete ones), or undefined when there is no such table at the end. */
|
||||
function pendingTable(lines: string[], last: string): number | undefined {
|
||||
// The rows at the end that look like a table's, the line being written included.
|
||||
// (Right after a newline the line being written is empty, and the table ends above it.)
|
||||
const rows = last === "" ? lines : [...lines, last]
|
||||
let start = rows.length
|
||||
while (start > 0 && TABLE_ROW.test(rows[start - 1]!)) start--
|
||||
if (start === rows.length) return undefined
|
||||
const block = rows.slice(start)
|
||||
// The delimiter row is the second; the table is drawn once the first cell of data under it is
|
||||
// closed — before that it has no row, and is drawn as text for a moment, then as a table.
|
||||
if (block.length >= 3 && DELIMITER.test(block[1]!) && FIRST_CELL.test(block[2]!)) return undefined
|
||||
return Math.min(start, lines.length)
|
||||
}
|
||||
|
||||
type Mark = "**" | "__" | "*" | "_" | "~~"
|
||||
|
||||
/** The line being written with what is open in it closed: emphasis, strong, strikethrough and a
|
||||
* code span. A mark with nothing after it yet is left out instead; so is a link whose `](…)`
|
||||
* has not arrived (its words come with it). */
|
||||
export function closeInline(line: string): string {
|
||||
let out = ""
|
||||
const open: { mark: Mark; at: number }[] = []
|
||||
let code: { ticks: number; at: number } | undefined
|
||||
let link: number | undefined
|
||||
for (let i = 0; i < line.length; ) {
|
||||
const ch = line[i]!
|
||||
if (ch === "\\" && i + 1 < line.length) {
|
||||
out += line.slice(i, i + 2)
|
||||
i += 2
|
||||
continue
|
||||
}
|
||||
if (ch === "`") {
|
||||
let n = 1
|
||||
while (line[i + n] === "`") n++
|
||||
if (!code) code = { ticks: n, at: out.length }
|
||||
else if (code.ticks === n) code = undefined
|
||||
out += "`".repeat(n)
|
||||
i += n
|
||||
continue
|
||||
}
|
||||
if (code) {
|
||||
out += ch
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if (ch === "[" && link === undefined) {
|
||||
link = out.length
|
||||
out += ch
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if (ch === "]" && link !== undefined) {
|
||||
// `[words](url)` complete on this line: it is a link; anything else was text all along.
|
||||
const m = /^\]\(([^)\s]*)\)/.exec(line.slice(i))
|
||||
if (m) {
|
||||
out += m[0]
|
||||
i += m[0].length
|
||||
link = undefined
|
||||
continue
|
||||
}
|
||||
if (/^\]\([^)]*$/.test(line.slice(i)) || i === line.length - 1) {
|
||||
// The url still coming: wait for it.
|
||||
out += line.slice(i)
|
||||
break
|
||||
}
|
||||
link = undefined
|
||||
out += ch
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if (ch === "*" || ch === "_" || ch === "~") {
|
||||
let n = 1
|
||||
while (line[i + n] === ch) n++
|
||||
const run = line.slice(i, i + n)
|
||||
const before = i > 0 ? line[i - 1]! : " "
|
||||
const after = line[i + n] ?? ""
|
||||
out += run
|
||||
i += n
|
||||
if (ch === "~" && n !== 2) continue
|
||||
// An underscore inside a word is a letter (snake_case).
|
||||
if (ch === "_" && /[\p{L}\p{N}]/u.test(before) && /[\p{L}\p{N}]/u.test(after)) continue
|
||||
// A run opens when a word follows it (or nothing yet: the word is coming), closes when one
|
||||
// precedes it. A bullet, or a `*` between spaces, does neither.
|
||||
const canOpen = after === "" || !/\s/.test(after)
|
||||
const canClose = !/\s/.test(before)
|
||||
let left = n
|
||||
// `***` is strong and emphasis together: read as a pair and one.
|
||||
while (left > 0) {
|
||||
const want: Mark = ch === "~" ? "~~" : left >= 2 ? (`${ch}${ch}` as Mark) : (ch as Mark)
|
||||
const at = open.map((o) => o.mark).lastIndexOf(want)
|
||||
if (canClose && at >= 0) open.splice(at)
|
||||
else if (canOpen) open.push({ mark: want, at: out.length - left })
|
||||
left -= want.length
|
||||
}
|
||||
} else {
|
||||
out += ch
|
||||
i++
|
||||
}
|
||||
}
|
||||
// A link still coming is left out from its `[`, and so is every mark opened inside it.
|
||||
const cut = link ?? Infinity
|
||||
if (code && code.at < cut) {
|
||||
// A code span with nothing in it yet: its backticks wait; otherwise it is closed.
|
||||
if (!out.slice(code.at).replace(/`/g, "").trim()) return closers(open.filter((o) => o.at < code!.at), out.slice(0, code.at))
|
||||
return closers(open.filter((o) => o.at < code!.at), out + "`".repeat(code.ticks))
|
||||
}
|
||||
return closers(open.filter((o) => o.at < cut), out.slice(0, cut))
|
||||
}
|
||||
|
||||
/** `out` with the open marks closed, innermost first; one with nothing after it is dropped. */
|
||||
function closers(open: { mark: Mark; at: number }[], out: string): string {
|
||||
let text = out
|
||||
for (let k = open.length - 1; k >= 0; k--) {
|
||||
const o = open[k]!
|
||||
if (o.at >= text.length) continue
|
||||
const inner = text.slice(o.at + o.mark.length)
|
||||
if (!inner.trim()) {
|
||||
text = text.slice(0, o.at).trimEnd()
|
||||
continue
|
||||
}
|
||||
// A closing mark must touch a word: trailing spaces stay outside it.
|
||||
const body = text.trimEnd()
|
||||
text = `${body}${o.mark}`
|
||||
}
|
||||
return text
|
||||
}
|
||||
+34
-11
@@ -1,9 +1,10 @@
|
||||
// The compact transcript: the same items as the full one, grouped. A tool round — the calls
|
||||
// between two pieces of text — is one row; what the calls returned is in the display pane.
|
||||
// The transcript's rows: the items, grouped. A tool round — the calls
|
||||
// between two pieces of text — is one row, in the full transcript and the compact one alike.
|
||||
// Pure: a view over the items, which it never changes.
|
||||
import { duration } from "../duration.ts"
|
||||
import { blockOf, callDuration, callTitle, diffCounts, drawnBlock } from "../session/display.ts"
|
||||
import type { Item } from "./state.ts"
|
||||
import { num } from "./locale.ts"
|
||||
|
||||
export type ToolItem = Extract<Item, { kind: "tool" }>
|
||||
export type ReasoningItem = Extract<Item, { kind: "reasoning" }>
|
||||
@@ -23,14 +24,15 @@ export interface Round {
|
||||
|
||||
export type Row = { kind: "item"; item: Item } | Round
|
||||
|
||||
/** The items as rows. Consecutive drawn calls are one round; a finished thought between two calls
|
||||
* of a round is folded into it. A thought still streaming, one before the round's first call, and
|
||||
/** The items as rows. Consecutive drawn calls are one round; a finished thought right before a
|
||||
* call — between two calls of a round, or just before its first — is folded into it (the round's
|
||||
* line is what the thinking led to). A thought still streaming, one that no call follows, and
|
||||
* every thought while `showReasoning` is on, is a row of its own — and ends the round before it.
|
||||
* Undrawn calls are no row and end nothing. */
|
||||
export function groupRounds(items: readonly Item[], o: { showReasoning?: boolean } = {}): Row[] {
|
||||
const rows: Row[] = []
|
||||
let round: Round | undefined
|
||||
// Thoughts after the round's last call so far: folded in only if another call follows.
|
||||
// Finished thoughts since the last call or row: folded into a round only if a call follows.
|
||||
let trailing: ReasoningItem[] = []
|
||||
const close = () => {
|
||||
for (const t of trailing) rows.push({ kind: "item", item: t })
|
||||
@@ -49,7 +51,7 @@ export function groupRounds(items: readonly Item[], o: { showReasoning?: boolean
|
||||
round.tools.push(item)
|
||||
continue
|
||||
}
|
||||
if (item.kind === "reasoning" && round && !item.streaming && !o.showReasoning) {
|
||||
if (item.kind === "reasoning" && !item.streaming && !o.showReasoning) {
|
||||
trailing.push(item)
|
||||
continue
|
||||
}
|
||||
@@ -82,6 +84,9 @@ export interface RoundSummary {
|
||||
denied: ToolItem[]
|
||||
/** Finished changes, one per call that has a diff: `path`, `+added −removed`. */
|
||||
changes: { id: string; path: string; added: number; removed: number }[]
|
||||
/** The changes' lines together. */
|
||||
added: number
|
||||
removed: number
|
||||
}
|
||||
|
||||
const titleOf = (t: ToolItem) => t.title ?? callTitle(t.args) ?? ""
|
||||
@@ -108,6 +113,8 @@ export function summarize(round: Pick<Round, "tools">): RoundSummary {
|
||||
failed: round.tools.filter((t) => t.status === "error"),
|
||||
denied: round.tools.filter((t) => t.status === "denied"),
|
||||
changes,
|
||||
added: changes.reduce((n, c) => n + c.added, 0),
|
||||
removed: changes.reduce((n, c) => n + c.removed, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,17 +123,24 @@ export function roundTrouble(s: RoundSummary): { failed: string; denied: string
|
||||
return { failed: s.failed.length ? `${s.failed.length} failed` : "", denied: s.denied.length ? `${s.denied.length} denied` : "" }
|
||||
}
|
||||
|
||||
/** The round's one line, without its mark: `7 tools · read ×3 · bash ×2 · edit ×2 · 14.0s`.
|
||||
* Failures and refusals are not in it: they are said beside it (`roundTrouble`), and each gets a
|
||||
* line of its own under it — never only a number. `width`: the columns the line may take; the
|
||||
* count and the time always stay, and of the kinds as many as fit, then `…`. */
|
||||
/** The changes of a round together, `+12 −3 in 2 files` (the minus is U+2212); "" when nothing
|
||||
* changed. */
|
||||
export const changeWords = (s: Pick<RoundSummary, "changes" | "added" | "removed">) =>
|
||||
s.changes.length ? `+${num(s.added)} −${num(s.removed)}${s.changes.length > 1 ? ` in ${s.changes.length} files` : ""}` : ""
|
||||
|
||||
/** The round's one line, without its mark: `7 tools · read ×3 · bash ×2 · edit ×2 · +12 −3 in 2
|
||||
* files · 14.0s`. Failures and refusals are not in it: they are said beside it (`roundTrouble`),
|
||||
* and each gets a line of its own under it — never only a number. `width`: the columns the line
|
||||
* may take; the count, the changes and the time always stay, and of the kinds as many as fit,
|
||||
* then `…`. */
|
||||
export function roundLine(s: RoundSummary, width = Infinity): string {
|
||||
const sep = " · "
|
||||
const count = `${s.count} tool${s.count === 1 ? "" : "s"}`
|
||||
// The same writing as a single call's time (display.md §2): durations are not locale numbers.
|
||||
const took = s.ms !== undefined && !s.running.length ? duration(s.ms) : ""
|
||||
const kinds = s.kinds.map((k) => (k.n > 1 ? `${k.name} ×${k.n}` : k.name))
|
||||
const line = (shown: string[], more: boolean) => [count, ...shown, ...(more ? ["…"] : []), took].filter(Boolean).join(sep)
|
||||
const changed = changeWords(s)
|
||||
const line = (shown: string[], more: boolean) => [count, ...shown, ...(more ? ["…"] : []), changed, took].filter(Boolean).join(sep)
|
||||
for (let n = kinds.length; n > 0; n--) {
|
||||
const text = line(kinds.slice(0, n), n < kinds.length)
|
||||
if (Bun.stringWidth(text) <= width) return text
|
||||
@@ -142,6 +156,15 @@ export function callAfter(t: ToolItem): string {
|
||||
return [...(t.facts ?? []), ...(t.note ? [t.note] : []), ...[callDuration(state, t.ms)].filter((x): x is string => !!x)].join(" · ")
|
||||
}
|
||||
|
||||
/** What a round is doing, for its one line while it runs: the newest call still running (between
|
||||
* two calls, the newest call), its title, and — for a subagent — what that is doing itself. */
|
||||
export function liveCall(round: Pick<Round, "tools">): { name: string; title: string; child?: string } | undefined {
|
||||
const t = [...round.tools].reverse().find((x) => x.status === "running") ?? round.tools[round.tools.length - 1]
|
||||
if (!t) return undefined
|
||||
const ch = t.children?.[t.children.length - 1]
|
||||
return { name: t.name, title: titleOf(t), ...(ch ? { child: `${ch.name} ${ch.title}`.trim() } : {}) }
|
||||
}
|
||||
|
||||
/** A multi-file patch (/diff) as stat lines, one per file. */
|
||||
export function patchStats(patch: string): { path: string; added: number; removed: number }[] {
|
||||
return patch
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { closeInline, keepBrackets, steadyMarkdown } from "../src/tui/steady.ts"
|
||||
|
||||
describe("closeInline: the line being written, what is open in it closed", () => {
|
||||
test.each([
|
||||
["I read **three fi", "I read **three fi**"],
|
||||
["I read **three ", "I read **three**"],
|
||||
["I read **", "I read"],
|
||||
["the bug in `st", "the bug in `st`"],
|
||||
["the bug in `", "the bug in "],
|
||||
["at *30 fp", "at *30 fp*"],
|
||||
["**bold *both", "**bold *both***"],
|
||||
["**see `sta", "**see `sta`**"],
|
||||
["~~gone", "~~gone~~"],
|
||||
["see [the docs](https://exa", "see "],
|
||||
["see [the do", "see "],
|
||||
["see [the docs](https://example.org) and **mo", "see [the docs](https://example.org) and **mo**"],
|
||||
["- [ ] a task", "- [ ] a task"],
|
||||
])("%p → %p", (line, want) => expect(closeInline(line)).toBe(want))
|
||||
|
||||
test("what is not a mark stays text", () => {
|
||||
expect(closeInline("a * b and snake_case_name")).toBe("a * b and snake_case_name")
|
||||
expect(closeInline("* a bullet")).toBe("* a bullet")
|
||||
expect(closeInline("2 * 3 = 6")).toBe("2 * 3 = 6")
|
||||
expect(closeInline("**done** and `x` and _y_")).toBe("**done** and `x` and _y_")
|
||||
expect(closeInline("an escaped \\*star")).toBe("an escaped \\*star")
|
||||
expect(closeInline("`a ** b")).toBe("`a ** b`")
|
||||
})
|
||||
})
|
||||
|
||||
describe("keepBrackets: brackets that are not a link stay", () => {
|
||||
test.each([
|
||||
["fix it [Pasted text 40 lines]", "fix it `[Pasted text 40 lines]`"],
|
||||
["see [Image 2] and [t1]", "see `[Image 2]` and `[t1]`"],
|
||||
["- [ ] open\n- [x] done\n1. [ ] numbered", "- [ ] open\n- [x] done\n1. [ ] numbered"],
|
||||
["a [link](https://example.org) here", "a [link](https://example.org) here"],
|
||||
["an ", "an "],
|
||||
["[ref][1] and\n[1]: https://example.org", "[ref][1] and\n[1]: https://example.org"],
|
||||
["code `a[0]` stays", "code `a[0]` stays"],
|
||||
["```ts\nconst a = b[0]\n```\nafter [x]", "```ts\nconst a = b[0]\n```\nafter `[x]`"],
|
||||
["already \\[kept\\]", "already \\[kept\\]"],
|
||||
])("%p", (text, want) => expect(keepBrackets(text)).toBe(want))
|
||||
})
|
||||
|
||||
describe("steadyMarkdown: a streaming reply as it is drawn", () => {
|
||||
test("text with nothing open is itself", () => {
|
||||
const t = "## Plan\n\nI read **three files**.\n\n- one\n- two\n"
|
||||
expect(steadyMarkdown(t)).toBe(t)
|
||||
})
|
||||
|
||||
test("a fence being opened waits for its newline; then it is drawn closed", () => {
|
||||
expect(steadyMarkdown("text\n\n`")).toBe("text")
|
||||
expect(steadyMarkdown("text\n\n``")).toBe("text")
|
||||
expect(steadyMarkdown("text\n\n```t")).toBe("text")
|
||||
expect(steadyMarkdown("text\n\n```ts\nconst x")).toBe("text\n\n```ts\nconst x\n```")
|
||||
expect(steadyMarkdown("text\n\n```ts\nconst x = 1\n")).toBe("text\n\n```ts\nconst x = 1\n\n```")
|
||||
})
|
||||
|
||||
test("a line that may be the closing fence waits", () => {
|
||||
expect(steadyMarkdown("```ts\nconst x = 1\n`")).toBe("```ts\nconst x = 1\n```")
|
||||
expect(steadyMarkdown("```ts\nconst x = 1\n```\n\nDone")).toBe("```ts\nconst x = 1\n```\n\nDone")
|
||||
})
|
||||
|
||||
test("a longer or tilde fence holds shorter backtick lines as content", () => {
|
||||
expect(steadyMarkdown("~~~md\n```\ninside")).toBe("~~~md\n```\ninside\n~~~")
|
||||
expect(steadyMarkdown("````\n```\nx")).toBe("````\n```\nx\n````")
|
||||
})
|
||||
|
||||
test("a table waits for its delimiter row", () => {
|
||||
expect(steadyMarkdown("Here:\n\n| a | b")).toBe("Here:")
|
||||
expect(steadyMarkdown("Here:\n\n| a | b |\n|--")).toBe("Here:")
|
||||
expect(steadyMarkdown("Here:\n\n| a | b |\n|---|---|")).toBe("Here:")
|
||||
expect(steadyMarkdown("Here:\n\n| a | b |\n|---|---|\n")).toBe("Here:")
|
||||
expect(steadyMarkdown("Here:\n\n| a | b |\n|---|---|\n|")).toBe("Here:")
|
||||
expect(steadyMarkdown("Here:\n\n| a | b |\n|---|---|\n| 1")).toBe("Here:")
|
||||
expect(steadyMarkdown("Here:\n\n| a | b |\n|---|---|\n| 1 |")).toBe("Here:\n\n| a | b |\n|---|---|\n| 1 |")
|
||||
})
|
||||
|
||||
test("a heading waits for its line; a bare list mark for its words", () => {
|
||||
expect(steadyMarkdown("Intro\n\n## Pla")).toBe("Intro")
|
||||
expect(steadyMarkdown("Intro\n\n## Plan\n")).toBe("Intro\n\n## Plan\n")
|
||||
expect(steadyMarkdown("#hashtag")).toBe("#hashtag")
|
||||
expect(steadyMarkdown("Intro\n\n##")).toBe("Intro")
|
||||
expect(steadyMarkdown("Intro\n\n## ")).toBe("Intro")
|
||||
expect(steadyMarkdown("Intro\n\n- one\n-")).toBe("Intro\n\n- one")
|
||||
expect(steadyMarkdown("Intro\n\n1.")).toBe("Intro")
|
||||
})
|
||||
|
||||
test("every prefix of a reply draws without a mark showing that will vanish", () => {
|
||||
const reply = "## Plan\n\nI read **three files** and found it in `state.ts`:\n\n- at *30 fps*\n- [docs](https://example.org)\n\n```ts\nconst x = 1\n```\n\n| a | b |\n|---|---|\n| 1 | 2 |\n\nDone."
|
||||
for (let i = 1; i <= reply.length; i++) {
|
||||
const s = steadyMarkdown(reply.slice(0, i))
|
||||
// Marks only ever come in pairs, a fence only ever closed.
|
||||
expect((s.match(/\*\*/g) ?? []).length % 2).toBe(0)
|
||||
expect((s.match(/^```/gm) ?? []).length % 2).toBe(0)
|
||||
expect(s).not.toMatch(/\[docs\]\([^)]*$/)
|
||||
}
|
||||
expect(steadyMarkdown(reply)).toBe(reply)
|
||||
})
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
// The compact transcript's grouping (src/tui/transcript.ts): a pure view over the items.
|
||||
// The transcript's grouping (src/tui/transcript.ts): a pure view over the items.
|
||||
import { expect, test } from "bun:test"
|
||||
import type { Item } from "../src/tui/state.ts"
|
||||
import { groupRounds, patchStats, roundLine, roundTrouble, rowIdOf, summarize, type Round } from "../src/tui/transcript.ts"
|
||||
import { changeWords, groupRounds, liveCall, patchStats, roundLine, roundTrouble, rowIdOf, summarize, type Round } from "../src/tui/transcript.ts"
|
||||
|
||||
const tool = (id: string, name: string, o: Partial<Extract<Item, { kind: "tool" }>> = {}): Item => ({ kind: "tool", id, name, args: {}, status: "done", ...o })
|
||||
const text = (id: string): Item => ({ kind: "assistant", id, text: "words", streaming: false })
|
||||
@@ -17,8 +17,10 @@ test("the calls between two pieces of text are one round; text, a prompt, a noti
|
||||
expect(JSON.stringify(items)).toBe(before)
|
||||
})
|
||||
|
||||
test("a finished thought between two calls is folded into the round; one before it, after it, or still streaming is a row", () => {
|
||||
expect(shape([thought("r0"), tool("t1", "read"), thought("r1"), tool("t2", "bash"), thought("r2"), text("a1")])).toEqual(["r0", "[t1,t2|r1]", "r2", "a1"])
|
||||
test("a finished thought before a call is folded into its round; one after the last call, or still streaming, is a row", () => {
|
||||
expect(shape([thought("r0"), tool("t1", "read"), thought("r1"), tool("t2", "bash"), thought("r2"), text("a1")])).toEqual(["[t1,t2|r0,r1]", "r2", "a1"])
|
||||
// Text between ends the round: a thought after it opens the next.
|
||||
expect(shape([tool("t1", "read"), text("a1"), thought("r1"), tool("t2", "bash")])).toEqual(["[t1]", "a1", "[t2|r1]"])
|
||||
// Thinking now: the round ends where the thought begins, and the thought shows.
|
||||
expect(shape([tool("t1", "read"), thought("r1", true)])).toEqual(["[t1]", "r1"])
|
||||
// Opened with ctrl+r, every thought is a row of its own.
|
||||
@@ -41,7 +43,7 @@ const DIFF = "--- a/src/a.ts\n+++ b/src/a.ts\n@@ -1,1 +1,2 @@\n-old\n+new\n+more
|
||||
|
||||
test("a round's line: the count, the kinds in order with ×n, the time together", () => {
|
||||
const s = summarize(round([tool("1", "read", { ms: 400 }), tool("2", "bash", { ms: 9000 }), tool("3", "read", { ms: 100 }), tool("4", "edit", { ms: 2500, diff: DIFF, title: "src/a.ts" }), tool("5", "read", { ms: 0 }), tool("6", "bash", { ms: 1000 }), tool("7", "edit", { ms: 1000, diff: DIFF, title: "src/b.ts" })]))
|
||||
expect(roundLine(s)).toBe("7 tools · read ×3 · bash ×2 · edit ×2 · 14.0s")
|
||||
expect(roundLine(s)).toBe("7 tools · read ×3 · bash ×2 · edit ×2 · +4 −2 in 2 files · 14.0s")
|
||||
expect(s.changes).toEqual([
|
||||
{ id: "4", path: "src/a.ts", added: 2, removed: 1 },
|
||||
{ id: "7", path: "src/b.ts", added: 2, removed: 1 },
|
||||
@@ -76,6 +78,24 @@ test("the line fits the columns it is given: the count and the time stay, the ki
|
||||
for (let width = 16; width <= 80; width++) expect(Bun.stringWidth(roundLine(s, width))).toBeLessThanOrEqual(width)
|
||||
})
|
||||
|
||||
test("a running round's line follows the call running now, and a subagent's own step", () => {
|
||||
const r = round([tool("1", "read", { title: "a.ts" }), tool("2", "bash", { title: "bun test", status: "running" }), tool("3", "grep", { title: "x" })])
|
||||
expect(liveCall(r)).toEqual({ name: "bash", title: "bun test" })
|
||||
// Between two calls (none running): the newest.
|
||||
expect(liveCall(round([tool("1", "read", { title: "a.ts" }), tool("2", "grep", { title: "x" })]))).toEqual({ name: "grep", title: "x" })
|
||||
const sub = tool("1", "task", { title: "find the bug", status: "running", children: [{ name: "read", title: "src/a.ts" }] as never })
|
||||
expect(liveCall(round([sub]))).toEqual({ name: "task", title: "find the bug", child: "read src/a.ts" })
|
||||
expect(liveCall(round([]))).toBeUndefined()
|
||||
})
|
||||
|
||||
test("a round's changes together: +added −removed, the files counted when more than one", () => {
|
||||
expect(changeWords(summarize(round([tool("1", "read")])))).toBe("")
|
||||
expect(changeWords(summarize(round([tool("1", "edit", { diff: DIFF, title: "src/a.ts" })])))).toBe("+2 −1")
|
||||
expect(changeWords(summarize(round([tool("1", "edit", { diff: DIFF, title: "a" }), tool("2", "edit", { diff: DIFF, title: "b" })])))).toBe("+4 −2 in 2 files")
|
||||
// A change that failed changed nothing.
|
||||
expect(changeWords(summarize(round([tool("1", "edit", { diff: DIFF, status: "error" })])))).toBe("")
|
||||
})
|
||||
|
||||
test("a multi-file patch as stat lines", () => {
|
||||
const patch = `diff --git a/a.txt b/a.txt\n--- a/a.txt\n+++ b/a.txt\n@@ -1,1 +1,2 @@\n-x\n+y\n+z\ndiff --git a/d/b.txt b/d/b.txt\n--- a/d/b.txt\n+++ b/d/b.txt\n@@ -1,2 +1,1 @@\n-one\n-two\n+one\n`
|
||||
expect(patchStats(patch)).toEqual([
|
||||
|
||||
+14
-10
@@ -31,9 +31,9 @@ test("a prompt runs; a bash call asks; y allows it; the answer renders as markdo
|
||||
expect(await t.until("Wrote out.txt.")).toBe(true)
|
||||
const f = t.frame()
|
||||
expect(f).toContain("❯ Ask") // the y that answered did not also land in the prompt
|
||||
expect(f).toContain("┃ make a file")
|
||||
expect(f).toContain("▎ make a file")
|
||||
// The call's one title — the command — and, finished, how long it took (spec 3.7.0 display.md).
|
||||
expect(f).toMatch(/┊ 💻 bash echo hi > out\.txt · \d+\.\ds/)
|
||||
expect(f).toMatch(/✓ bash echo hi > out\.txt · \d+\.\ds/)
|
||||
expect(f).not.toContain("## Done") // heading marker concealed
|
||||
expect(f).toContain("ctx 12k/33k 37%")
|
||||
expect(await Bun.file(`${t.cwd}/out.txt`).text()).toBe("hi\n")
|
||||
@@ -41,12 +41,12 @@ test("a prompt runs; a bash call asks; y allows it; the answer renders as markdo
|
||||
|
||||
test("shift+tab cycles manual → edit → plan → manual; the status bar follows", async () => {
|
||||
t = await tui([])
|
||||
expect(t.frame()).toContain(" manual · fake/coder · low")
|
||||
expect(t.frame()).toContain(" manual fake/coder · low")
|
||||
for (const want of ["edit", "plan", "manual"] as const) {
|
||||
t.input.pressTab({ shift: true })
|
||||
await t.settle()
|
||||
expect(t.app.engine.mode).toBe(want)
|
||||
expect(t.frame()).toContain(` ${want} · fake/coder`)
|
||||
expect(t.frame()).toContain(` ${want} fake/coder`)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -64,7 +64,8 @@ test("deny with a reason sends the reason to the model", async () => {
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("Leaving it.")).toBe(true)
|
||||
expect(t.fake.requests[1].messages.at(-1).content).toContain("keep the file")
|
||||
expect(t.frame()).toContain("⛔")
|
||||
// Refused: its own mark and colour, the name struck through (display.md §2).
|
||||
expect(t.frame()).toContain("⊘ bash rm hello.txt")
|
||||
})
|
||||
|
||||
test("e edits the command before allowing it: the edited line runs, and the model is told", async () => {
|
||||
@@ -292,7 +293,7 @@ test("/ fuzzy-lists commands; a custom command sends its expanded body", async (
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("A greeting.")).toBe(true)
|
||||
expect(t.fake.requests[0].messages.at(-1).content).toContain("Explain hello.txt in one line.")
|
||||
expect(t.frame()).toContain("┃ /explain hello.txt")
|
||||
expect(t.frame()).toContain("▎ /explain hello.txt")
|
||||
})
|
||||
|
||||
test("!command runs at once and its output goes with the next prompt", async () => {
|
||||
@@ -353,10 +354,10 @@ test("the plan card: the plan shown with its ids; a approves and the status bar
|
||||
expect(card).toContain("Two changes.")
|
||||
expect(card).toContain("p1 Changes (pending)")
|
||||
expect(card).toContain("[t1] [ ] one thing")
|
||||
expect(f).toContain(" plan · fake/coder")
|
||||
expect(f).toContain(" plan fake/coder")
|
||||
await t.input.typeText("a")
|
||||
expect(await t.until("Implementing now.")).toBe(true)
|
||||
expect(t.frame()).toContain(" edit · fake/coder")
|
||||
expect(t.frame()).toContain(" edit fake/coder")
|
||||
})
|
||||
|
||||
test("thinking is one line — its text is not shown; the provider's count of it is; ctrl+r opens it", async () => {
|
||||
@@ -447,7 +448,7 @@ test("/review sends the session's diff with the review brief in plan mode, then
|
||||
expect(user).toContain("<session-note>\nThe permission mode is now plan:\nPermission mode: plan.")
|
||||
expect(user).toContain("Findings first, ordered by severity")
|
||||
expect(user).toContain("+hello there")
|
||||
expect(t.frame()).toContain("┃ /review")
|
||||
expect(t.frame()).toContain("▎ /review")
|
||||
expect(t.app.engine.mode).toBe("edit")
|
||||
})
|
||||
|
||||
@@ -536,7 +537,7 @@ test("MCP: a server's prompt is a /server:prompt command; /mcp lists the server;
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("Greeted.")).toBe(true)
|
||||
expect(t.fake.requests[0].messages.at(-1).content).toContain("Say hello to Jaro.")
|
||||
expect(t.frame()).toContain("🔌")
|
||||
expect(t.frame()).toMatch(/✓ mcp__fix__echo · echo: hi · \d+\.\ds/)
|
||||
for (const line of t.frame().split("\n")) expect(Bun.stringWidth(line)).toBeLessThanOrEqual(80)
|
||||
await t.input.typeText("/mcp")
|
||||
t.input.pressEnter()
|
||||
@@ -692,6 +693,9 @@ test("/icons plain swaps every picture for a one-column symbol, and is saved", a
|
||||
expect(await t.until("icons: plain")).toBe(true)
|
||||
await t.input.typeText("go")
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("ok")).toBe(true)
|
||||
// The round is one line; opened, each call has its picture — now the plain one.
|
||||
t.input.pressKey("o", { ctrl: true })
|
||||
expect(await t.until("┊ » read")).toBe(true)
|
||||
expect(t.frame()).not.toContain("📖")
|
||||
const { readFileSync } = await import("node:fs")
|
||||
|
||||
@@ -26,17 +26,25 @@ test("a call keeps one title; done shows its facts and how long it took, failed
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("All done.")).toBe(true)
|
||||
const f = t.frame()
|
||||
// A search is titled by its pattern, and says its hits.
|
||||
expect(f).toMatch(/grep hello · 1 hit · \d+\.\ds/)
|
||||
// An edit: the path, +added −removed, the time.
|
||||
expect(f).toMatch(/edit hello\.txt · \+2 −1 · \d+\.\ds/)
|
||||
// A command that failed: its own line as the title (not its description), the exit code.
|
||||
expect(f).toMatch(/bash exit 3 · exit 3 · \d+\.\ds ✗/)
|
||||
// The round is one line — its calls, its change, its time, and what went wrong said beside it.
|
||||
expect(f).toMatch(/✗ 4 tools · bash ×2 · grep · edit · \+2 −1 · \d+\.\ds · 1 failed · 1 denied/)
|
||||
// A command that failed: a line of its own, its own line as the title (not its description),
|
||||
// the exit code, the time.
|
||||
expect(f).toMatch(/✗ bash exit 3 · exit 3 · \d+\.\ds/)
|
||||
// Denied: the same title, the reason, and no duration — it never ran.
|
||||
const denied = f.split("\n").find((l) => l.includes("git push origin main"))!
|
||||
expect(denied).toContain("git push origin main · ")
|
||||
expect(denied).toContain("⊘ bash git push origin main · ")
|
||||
expect(denied).not.toMatch(/\d+\.\ds/)
|
||||
expect(denied).not.toContain("✗")
|
||||
// Opened, every call in its state.
|
||||
t.input.pressKey("o", { ctrl: true })
|
||||
await t.settle(200)
|
||||
const o = t.frame()
|
||||
// A search is titled by its pattern, and says its hits.
|
||||
expect(o).toMatch(/grep hello · 1 hit · \d+\.\ds/)
|
||||
// An edit: the path, +added −removed, the time.
|
||||
expect(o).toMatch(/edit hello\.txt · \+2 −1 · \d+\.\ds/)
|
||||
expect(o).toMatch(/bash exit 3 · exit 3 · \d+\.\ds ✗/)
|
||||
})
|
||||
|
||||
test("a reply that fails ends with the spec's line, once; one stopped by esc says Stopped: by you", async () => {
|
||||
@@ -123,7 +131,7 @@ test("a call whose result never came is drawn failed when the session is shown a
|
||||
["c1", "error", "make all"],
|
||||
["c2", "done", "a.txt"],
|
||||
])
|
||||
expect(t.frame()).toMatch(/bash make all.*✗/)
|
||||
expect(t.frame()).toMatch(/✗ bash make all/)
|
||||
// A `!` command still running when a turn ends stays running: it was never part of the turn.
|
||||
const own = t.view.shellStart("sleep 30")
|
||||
await t.input.typeText("go")
|
||||
|
||||
+16
-14
@@ -43,7 +43,7 @@ test("the pane stands at the right over the terminal's full height — beside th
|
||||
expect(borderOnEveryRow(at)).toBe(true)
|
||||
// The session header at the top, the key line on the last row — beside the status bar.
|
||||
expect(rows[0]!.slice(at)).toContain("fake/coder · manual · low")
|
||||
expect(rows[34]!.slice(0, at)).toContain("manual · fake/coder")
|
||||
expect(rows[34]!.slice(0, at)).toContain("manual fake/coder")
|
||||
expect(rows[34]!.slice(at)).toContain("alt+d hide")
|
||||
expect(rows[33]!.slice(0, at)).toContain("Ask · / commands")
|
||||
expect(t.frame()).toContain("Files (1)")
|
||||
@@ -72,7 +72,7 @@ test("at 80 columns the pane is still beside the conversation, and each column h
|
||||
expect(borderOnEveryRow(45)).toBe(true)
|
||||
// The tab bar in its narrow form, every tab there; the short status bar keeps mode, model, context.
|
||||
expect(rows.some((r) => / L +F1 +C1 +B2 +I /.test(r.slice(45)))).toBe(true)
|
||||
expect(rows[23]!.slice(0, 45)).toMatch(/AUTO · fake\/coder · low +ctx 37% $/)
|
||||
expect(rows[23]!.slice(0, 45)).toMatch(/AUTO fake\/coder · low +ctx 37% +◧ *$/)
|
||||
expect(rows[23]!.slice(45)).toContain("d hide")
|
||||
// The prompt box is one row: nothing of it wrapped in the narrow column.
|
||||
expect(rows[22]!.slice(0, 45)).toContain("❯ Ask")
|
||||
@@ -99,7 +99,7 @@ test("too narrow for two columns: the status bar says there is a display, alt+d
|
||||
expect(rows[0]).toContain("fake/coder · auto · low")
|
||||
expect(rows.some((r) => r.includes("alt+d transcript"))).toBe(true)
|
||||
expect(rows[22]).toContain("❯ Ask")
|
||||
expect(rows[23]).toContain("AUTO · fake/coder")
|
||||
expect(rows[23]).toContain("AUTO fake/coder")
|
||||
|
||||
t.input.pressKey("d", { meta: true })
|
||||
expect(await t.until("Let me look.")).toBe(true)
|
||||
@@ -124,43 +124,45 @@ test("beside the display the transcript is compact: a round is one line, failure
|
||||
await t.settle(200)
|
||||
const left = () => lines().map((r) => r.slice(0, 68)).join("\n")
|
||||
// One line for the round: count, kinds, time — the failures and the refusal counted beside it…
|
||||
expect(left()).toMatch(/▸ 5 tools · bash ×2 · grep · .*\d+\.\ds · 1 failed · 1 denied/)
|
||||
// (the kinds give way first: the count, the change, the time and the trouble stay)
|
||||
expect(left()).toMatch(/✗ 5 tools · bash ×2 · .*\+2 −1 · \d+\.\ds · 1 failed · 1 denied/)
|
||||
// …and each said in a line of its own; the change that went through as its stat.
|
||||
expect(left()).toMatch(/✗ bash exit 3 · exit 3 · \d+\.\ds/)
|
||||
expect(left()).toMatch(/⊘ bash git push origin main · Denied/)
|
||||
expect(left()).toMatch(/ hello\.txt \+2 −1/)
|
||||
expect(left()).toMatch(/✗ 5 tools · .*\+2 −1/)
|
||||
expect(left()).not.toContain("hello there")
|
||||
// No call that went well has a line of its own.
|
||||
expect(left()).not.toMatch(/grep +hello · 1 hit/)
|
||||
|
||||
// alt+t: the full transcript, every call on its line.
|
||||
// alt+t: the full transcript — the round still one line, the change's diff under it.
|
||||
t.input.pressKey("t", { meta: true })
|
||||
expect(await t.until("transcript: full")).toBe(true)
|
||||
await t.settle(200)
|
||||
expect(left()).toMatch(/grep +hello · 1 hit · \d+\.\ds/)
|
||||
expect(left()).toMatch(/bash +exit 3 · exit 3 · \d+\.\ds ✗/)
|
||||
expect(left()).not.toContain("5 tools")
|
||||
expect(left()).toContain("✗ 5 tools")
|
||||
expect(left()).toContain("hello there")
|
||||
expect(left()).toMatch(/✗ bash exit 3 · exit 3 · \d+\.\ds/)
|
||||
expect(left()).not.toMatch(/grep +hello · 1 hit/)
|
||||
|
||||
// /transcript auto: compact again, since the display is beside it.
|
||||
await t.input.typeText("/transcript auto")
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("transcript: auto — compact now")).toBe(true)
|
||||
await t.settle(200)
|
||||
expect(left()).toContain("▸ 5 tools")
|
||||
expect(left()).toContain("✗ 5 tools")
|
||||
|
||||
// ctrl+o opens the round into its calls.
|
||||
t.input.pressKey("o", { ctrl: true })
|
||||
await t.settle(200)
|
||||
expect(left()).toContain("▸ 5 tools")
|
||||
expect(left()).toContain("✗ 5 tools")
|
||||
expect(left()).toMatch(/grep +hello · 1 hit · \d+\.\ds/)
|
||||
t.input.pressKey("o", { ctrl: true })
|
||||
await t.settle(200)
|
||||
|
||||
// The display hidden: auto is the full transcript.
|
||||
// The display hidden: auto is the full transcript — the change's diff under the round.
|
||||
t.input.pressKey("d", { meta: true })
|
||||
await t.settle(300)
|
||||
expect(t.frame()).not.toContain("5 tools")
|
||||
expect(t.frame()).toMatch(/grep +hello · 1 hit · \d+\.\ds/)
|
||||
expect(t.frame()).toContain("✗ 5 tools")
|
||||
expect(t.frame()).toContain("hello there")
|
||||
// Nothing ran again for any of it.
|
||||
expect(t.fake.requests.length).toBe(2)
|
||||
})
|
||||
|
||||
@@ -56,7 +56,7 @@ test("first run: read-only skips the project dir; a file named .agent sends it t
|
||||
setup!.mockInput.pressEnter()
|
||||
const f = await b.frame()
|
||||
expect(f).toContain("opened read-only")
|
||||
expect(f).toContain(" plan · fake/m")
|
||||
expect(f).toContain(" plan fake/m")
|
||||
expect(existsSync(join(cwd, ".lembas"))).toBe(false)
|
||||
b.fake.stop()
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ test("ctrl+b moves the foreground command to the background: the call returns, t
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("Allow once")).toBe(true)
|
||||
await t.input.typeText("y")
|
||||
expect(await t.until("echo early; sleep 20; echo late …")).toBe(true)
|
||||
expect(await t.until("bash echo early; sleep 20; echo late")).toBe(true)
|
||||
await Bun.sleep(300)
|
||||
t.input.pressKey("b", { ctrl: true })
|
||||
expect(await t.until("Moved on.")).toBe(true)
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// How a turn looks: the prompt a shaded block drawn as markdown, the reply after its mark, a round
|
||||
// of tool calls one line in both transcripts — live while it runs, a summary once done.
|
||||
import { afterEach, expect, test } from "bun:test"
|
||||
import { delta, toolCall, usage } from "../fake-provider.ts"
|
||||
import { tui } from "./harness.tsx"
|
||||
|
||||
let t: Awaited<ReturnType<typeof tui>> | undefined
|
||||
afterEach(() => t?.stop())
|
||||
|
||||
const script = () => [
|
||||
{ chunks: [delta({ content: "I'll look at **hello.txt** first." }), toolCall(0, "c1", "read", '{"path":"hello.txt"}'), toolCall(1, "c2", "grep", '{"pattern":"world"}')] },
|
||||
{ chunks: [toolCall(0, "c3", "edit", JSON.stringify({ path: "hello.txt", old: "world", new: "there" })), toolCall(1, "c4", "bash", '{"command":"cat hello.txt","description":"Show the file"}')] },
|
||||
{ chunks: [delta({ content: "## Done\n\nChanged `hello.txt`: it says **there** now.\n\n- [ ] a task left\n- see [1]\n" }), usage(9000, 120)] },
|
||||
]
|
||||
|
||||
const prompt = "change the **greeting** in `hello.txt` [Pasted text 3 lines]"
|
||||
|
||||
test("full transcript: the prompt as markdown, the reply after its mark, the round one line with its diff", async () => {
|
||||
t = await tui(script(), { width: 90, height: 40 })
|
||||
t.app.engine.mode = "edit"
|
||||
await t.input.typeText(prompt)
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("a task left")).toBe(true)
|
||||
await t.settle(200)
|
||||
const f = t.frame()
|
||||
// The prompt: its marks drawn, not shown; a placeholder keeps its brackets.
|
||||
expect(f).toContain("▎ change the greeting in hello.txt [Pasted text 3 lines]")
|
||||
expect(f).toContain("◆ I'll look at hello.txt first.")
|
||||
expect(f).toContain("◆ Done")
|
||||
// Brackets that are not a link stay; a task's box stays a task's box.
|
||||
expect(f).toContain("- [ ] a task left")
|
||||
expect(f).toContain("see [1]")
|
||||
// One line for the four calls; the change's diff under it.
|
||||
expect(f).toMatch(/✓ 4 tools · read · grep · edit · bash · \+1 −1 · \d+\.\ds/)
|
||||
expect(f).toContain("1 + hello there")
|
||||
expect(f).not.toContain("┊")
|
||||
// The view chip: at 90 columns its glyph alone (its words would cut the model's name).
|
||||
expect(f).toMatch(/ ▤ +$/m)
|
||||
})
|
||||
|
||||
test("compact transcript beside the display: the round one line, the diff left to the display", async () => {
|
||||
t = await tui(script(), { width: 130, height: 40 }, "displays: true\n")
|
||||
t.app.engine.mode = "edit"
|
||||
await t.input.typeText(prompt)
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("a task left")).toBe(true)
|
||||
await t.settle(200)
|
||||
const left = t
|
||||
.frame()
|
||||
.split("\n")
|
||||
.map((l) => l.split("│ ")[0] ?? "")
|
||||
.join("\n")
|
||||
expect(left).toMatch(/✓ 4 tools · read · grep · edit · bash · \+1 −1 · \d+\.\ds/)
|
||||
expect(left).not.toContain("1 + hello there")
|
||||
expect(left).toContain("◧")
|
||||
// ctrl+o opens the round into its calls.
|
||||
t.input.pressKey("o", { ctrl: true })
|
||||
await t.settle(200)
|
||||
expect(t.frame()).toMatch(/read\s+hello\.txt/)
|
||||
expect(t.frame()).toMatch(/grep\s+world/)
|
||||
})
|
||||
|
||||
test("a running round is one line that follows the call running", async () => {
|
||||
t = await tui(
|
||||
[
|
||||
{ chunks: [toolCall(0, "c1", "read", '{"path":"hello.txt"}'), toolCall(1, "c2", "grep", '{"pattern":"world"}')] },
|
||||
{ chunks: [toolCall(0, "c3", "bash", '{"command":"sleep 2 && echo ok","description":"Wait"}')] },
|
||||
{ chunks: [delta({ content: "Waited." })] },
|
||||
],
|
||||
{ width: 90, height: 24 },
|
||||
)
|
||||
t.app.engine.mode = "edit"
|
||||
await t.input.typeText("wait a bit")
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("needs approval")).toBe(true)
|
||||
t.input.pressKey("y")
|
||||
expect(await t.until("bash sleep 2 && echo ok · 3 tools")).toBe(true)
|
||||
expect(t.frame()).not.toMatch(/read\s+hello\.txt/)
|
||||
expect(await t.until("Waited.", 10_000)).toBe(true)
|
||||
expect(t.frame()).toMatch(/✓ 3 tools · read · grep · bash · \d+\.\ds/)
|
||||
}, 30_000)
|
||||
@@ -41,7 +41,7 @@ test("a long paste shows as a placeholder; the text itself is sent, and the tran
|
||||
expect(await t.until("Read it.")).toBe(true)
|
||||
expect(sent()).toContain("look: first line\\nsecond line\\nthird line\\nfourth line thanks")
|
||||
expect(sent()).not.toContain("[Pasted text")
|
||||
expect(t.frame()).toContain("┃ look: [Pasted text 4 lines] thanks")
|
||||
expect(t.frame()).toContain("▎ look: [Pasted text 4 lines] thanks")
|
||||
expect(a.plainText).toBe("")
|
||||
})
|
||||
|
||||
@@ -209,7 +209,7 @@ test("a pasted path to an image is [Image N], numbered after the highest in the
|
||||
expect(a.plainText).toBe("[Image 2] [Image 3] ")
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("Seen.")).toBe(true)
|
||||
expect(t.frame()).toContain("┃ [Image 2] [Image 3]")
|
||||
expect(t.frame()).toContain("▎ [Image 2] [Image 3]")
|
||||
expect(sent()).toContain(`@${two} @${one.replace(/ /g, "\\\\ ")}`)
|
||||
expect(t.frame()).toContain("attached")
|
||||
})
|
||||
@@ -451,7 +451,7 @@ test("a session whose first prompt is a paste is titled by its words, and the pr
|
||||
t.input.pressEnter()
|
||||
expect(await t.until("ok")).toBe(true)
|
||||
await t.settle(200)
|
||||
expect(t.frame()).toContain("┃ [Pasted text 4 lines]")
|
||||
expect(t.frame()).toContain("▎ [Pasted text 4 lines]")
|
||||
expect(prompts[0]!.text).toBe(pasted)
|
||||
const title = t.app.store!.session(t.app.engine.sessionId!)!.title
|
||||
expect(title).toStartWith("Please review this function carefully")
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// A reply as it streams, frame by frame, the way the transcript draws it (steady.ts): nothing
|
||||
// drawn is taken back. Raw, the same stream showed `**`, `` ` ``, `## ` and table pipes that
|
||||
// vanished a frame later, and a code block that blanked — nine such frames in sixty.
|
||||
import { expect, test } from "bun:test"
|
||||
import { testRender } from "@opentui/solid"
|
||||
import { createSignal } from "solid-js"
|
||||
import { DEFAULT_THEME, markdownStyle } from "../../src/tui/theme.ts"
|
||||
import { steadyMarkdown } from "../../src/tui/steady.ts"
|
||||
|
||||
const REPLY = `## Plan
|
||||
|
||||
I read **three files** and found the bug in \`state.ts\`:
|
||||
|
||||
- the flush runs at *30 fps*
|
||||
- each flush re-parses
|
||||
|
||||
\`\`\`ts
|
||||
const x = 1
|
||||
function f() { return x }
|
||||
\`\`\`
|
||||
|
||||
| a | b |
|
||||
|---|---|
|
||||
| 1 | 2 |
|
||||
|
||||
### Next
|
||||
|
||||
Done.`
|
||||
|
||||
test("a streaming reply is drawn without a frame that takes back what was shown", async () => {
|
||||
const [text, setText] = createSignal("")
|
||||
const [streaming, setStreaming] = createSignal(true)
|
||||
const md = markdownStyle(DEFAULT_THEME)
|
||||
const s = await testRender(
|
||||
() => (
|
||||
<box flexDirection="column">
|
||||
<markdown content={streaming() ? steadyMarkdown(text()) : text()} syntaxStyle={md} streaming={streaming()} fg={DEFAULT_THEME.colors.text} conceal />
|
||||
</box>
|
||||
),
|
||||
{ width: 60, height: 24 },
|
||||
)
|
||||
try {
|
||||
// The markdown grammar loads on first use — once per process, not per reply.
|
||||
setText("# warm\n\n**x** `y`")
|
||||
for (let k = 0; k < 10; k++) (await Bun.sleep(30), await s.renderOnce())
|
||||
setText("")
|
||||
await s.renderOnce()
|
||||
const frames: string[] = []
|
||||
// Four characters a flush, at the transcript's own pace (state.ts: 33 ms).
|
||||
for (let i = 4; i <= REPLY.length + 4; i += 4) {
|
||||
setText(REPLY.slice(0, i))
|
||||
await Bun.sleep(33)
|
||||
await s.renderOnce()
|
||||
frames.push(s.captureCharFrame())
|
||||
}
|
||||
setStreaming(false)
|
||||
for (let k = 0; k < 6; k++) (await Bun.sleep(30), await s.renderOnce(), frames.push(s.captureCharFrame()))
|
||||
const flat = (f: string) => f.replace(/\s+/g, " ").trim()
|
||||
const takenBack: string[] = []
|
||||
for (let i = 1; i < frames.length; i++) {
|
||||
const a = flat(frames[i - 1]!)
|
||||
const b = flat(frames[i]!)
|
||||
// A table fills its cells in place: its box is the one thing that may change as it grows.
|
||||
if (!b.startsWith(a) && !/[┌│└]/.test(a.slice(-80))) takenBack.push(`${i}: «${a.slice(-40)}» → «${b.slice(-40)}»`)
|
||||
}
|
||||
expect(takenBack).toEqual([])
|
||||
const last = flat(frames[frames.length - 1]!)
|
||||
expect(last).toContain("I read three files and found the bug in state.ts:")
|
||||
expect(last).toContain("const x = 1")
|
||||
expect(last).toMatch(/│1\s+│2\s+│/)
|
||||
expect(last).not.toContain("**")
|
||||
expect(last).not.toContain("##")
|
||||
} finally {
|
||||
s.renderer.destroy()
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user