ci / check (push) Waiting to run
- The prompt is a shaded block drawn as markdown; each piece of the reply starts with the leaf mark (branding.responseMark); tools sit indented under them. - A round of tool calls is one line in both transcripts: live while it runs (spinner, the call running now, how many calls), a summary once done (count, kinds, +added -removed, time); failures and refusals keep their own line. Full adds each change's diff; compact leaves it to the display. A thought that led to a call folds into its round. - Status bar: the mode as a chip; a view chip at the end, clicked = alt+d. - Fixed: streaming markdown was drawn half-read (marks shown then hidden, a fence or table header flashing). tui/steady.ts draws it steady; a frame-by- frame test fails on any frame that takes back what the last one showed. - Fixed: [1], [Image 2], [Pasted text N lines] lost their brackets. - Page segments are updated in place (Index), not rebuilt every flush. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
7.4 KiB
TypeScript
106 lines
7.4 KiB
TypeScript
// 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 { 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 })
|
||
const thought = (id: string, streaming = false): Item => ({ kind: "reasoning", id, text: "hm", streaming, started: 0, ms: 100 })
|
||
const shape = (items: Item[], o?: { showReasoning?: boolean }) => groupRounds(items, o).map((r) => (r.kind === "round" ? `[${r.tools.map((t) => t.id).join(",")}${r.thoughts.length ? `|${r.thoughts.map((t) => t.id).join(",")}` : ""}]` : r.item.id))
|
||
|
||
test("the calls between two pieces of text are one round; text, a prompt, a notice end it", () => {
|
||
const items: Item[] = [{ kind: "user", id: "u1", text: "go" }, text("a1"), tool("t1", "read"), tool("t2", "read"), tool("t3", "bash"), text("a2"), tool("t4", "edit"), { kind: "notice", id: "n1", text: "x", level: "info" }, tool("t5", "bash"), text("a3")]
|
||
expect(shape(items)).toEqual(["u1", "a1", "[t1,t2,t3]", "a2", "[t4]", "n1", "[t5]", "a3"])
|
||
// The items are not changed, and grouping twice gives the same rows.
|
||
const before = JSON.stringify(items)
|
||
expect(shape(items)).toEqual(shape(items))
|
||
expect(JSON.stringify(items)).toBe(before)
|
||
})
|
||
|
||
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.
|
||
expect(shape([tool("t1", "read"), thought("r1"), tool("t2", "bash")], { showReasoning: true })).toEqual(["[t1]", "r1", "[t2]"])
|
||
})
|
||
|
||
test("a call the transcript does not draw is no row and ends no round", () => {
|
||
expect(shape([tool("t1", "read"), tool("p1", "plan_update"), tool("t2", "bash")])).toEqual(["[t1,t2]"])
|
||
expect(shape([tool("p1", "plan_write")])).toEqual([])
|
||
})
|
||
|
||
test("every item is found again in its row: itself, or its round", () => {
|
||
const rows = groupRounds([text("a1"), tool("t1", "read"), thought("r1"), tool("t2", "bash"), text("a2")])
|
||
const map = rowIdOf(rows)
|
||
expect([...map]).toEqual([["a1", "a1"], ["t1", "t1"], ["t2", "t1"], ["r1", "t1"], ["a2", "a2"]])
|
||
})
|
||
|
||
const round = (tools: Item[]): Pick<Round, "tools"> => ({ tools: tools as Round["tools"] })
|
||
const DIFF = "--- a/src/a.ts\n+++ b/src/a.ts\n@@ -1,1 +1,2 @@\n-old\n+new\n+more\n"
|
||
|
||
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 · +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 },
|
||
])
|
||
expect(roundTrouble(s)).toEqual({ failed: "", denied: "" })
|
||
expect(roundLine(summarize(round([tool("1", "bash", { ms: 61_000 })])))).toBe("1 tool · bash · 1m 01s")
|
||
// A stored session kept no durations: none is made up.
|
||
expect(roundLine(summarize(round([tool("1", "read"), tool("2", "read")])))).toBe("2 tools · read ×2")
|
||
})
|
||
|
||
test("a failure and a refusal are never inside a number only: each is counted beside the line and listed", () => {
|
||
const s = summarize(round([tool("1", "read", { ms: 10 }), tool("2", "bash", { status: "error", ms: 20, note: "exit 3" }), tool("3", "bash", { status: "denied", note: "denied by a rule" }), tool("4", "edit", { status: "error", ms: 5, diff: DIFF })]))
|
||
expect(roundTrouble(s)).toEqual({ failed: "2 failed", denied: "1 denied" })
|
||
expect(s.failed.map((t) => t.id)).toEqual(["2", "4"])
|
||
expect(s.denied.map((t) => t.id)).toEqual(["3"])
|
||
// A change that failed is not a change.
|
||
expect(s.changes).toEqual([])
|
||
})
|
||
|
||
test("a running call stays in sight, and the round has no total until it ends", () => {
|
||
const s = summarize(round([tool("1", "read", { ms: 10 }), tool("2", "bash", { status: "running" })]))
|
||
expect(s.running.map((t) => t.id)).toEqual(["2"])
|
||
expect(roundLine(s)).toBe("2 tools · read · bash")
|
||
})
|
||
|
||
test("the line fits the columns it is given: the count and the time stay, the kinds give way", () => {
|
||
const s = summarize(round([tool("1", "read", { ms: 400 }), tool("2", "bash", { ms: 9000 }), tool("3", "grep", { ms: 100 }), tool("4", "edit", { ms: 2500 }), tool("5", "web_fetch", { ms: 2000 })]))
|
||
expect(roundLine(s, 80)).toBe("5 tools · read · bash · grep · edit · web_fetch · 14.0s")
|
||
expect(roundLine(s, 40)).toBe("5 tools · read · bash · grep · … · 14.0s")
|
||
expect(roundLine(s, 20)).toBe("5 tools · … · 14.0s")
|
||
expect(roundLine(s, 16)).toBe("5 tools · 14.0s")
|
||
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([
|
||
{ path: "a.txt", added: 2, removed: 1 },
|
||
{ path: "d/b.txt", added: 1, removed: 2 },
|
||
])
|
||
})
|