@@ -2,8 +2,8 @@
22 * Shared helpers for benchmark tree construction.
33 */
44
5-import type { Node, ContainerNode } from "@cel-tui/types";
6-import { VStack, HStack, Text, TextInput } from "@cel-tui/core";
5+import type { ContainerNode, Node, StyleProps } from "@cel-tui/types";
6+import { HStack, Text, TextInput, VStack } from "@cel-tui/core";
77
88 /** Build a flat VStack with N Text children. */
99 export function flatTree(n: number): ContainerNode {
@@ -129,6 +129,212 @@ export function appTree(messageCount: number): ContainerNode {
129129 ]);
130130 }
131131
132+const TOKEN_TEXT = [
133+ "const",
134+ " ",
135+ "result",
136+ " ",
137+ "=",
138+ " ",
139+ "await",
140+ " ",
141+ "agent",
142+ ".",
143+ "run",
144+ "(",
145+ "{",
146+ " cwd",
147+ ": ",
148+ "projectRoot",
149+ ", ",
150+ "prompt",
151+ ": ",
152+ "message",
153+ " }",
154+ ")",
155+ ";",
156+ " // stream tool output",
157+];
158+
159+const TOKEN_STYLES: StyleProps[] = [
160+ { fgColor: "color05", bold: true },
161+ { fgColor: "color07" },
162+ { fgColor: "color06" },
163+ { fgColor: "color07" },
164+ { fgColor: "color08" },
165+ { fgColor: "color07" },
166+ { fgColor: "color05", bold: true },
167+ { fgColor: "color07" },
168+ { fgColor: "color02" },
169+ { fgColor: "color08" },
170+ { fgColor: "color04" },
171+ { fgColor: "color08" },
172+ { fgColor: "color03" },
173+ { fgColor: "color06" },
174+ { fgColor: "color08" },
175+ { fgColor: "color02" },
176+ { fgColor: "color08" },
177+ { fgColor: "color06" },
178+ { fgColor: "color08" },
179+ { fgColor: "color02" },
180+ { fgColor: "color03" },
181+ { fgColor: "color08" },
182+ { fgColor: "color08" },
183+ { fgColor: "color08", italic: true },
184+];
185+
186+const MESSAGE_BODIES = [
187+ "I'll inspect the rendering pipeline and then patch the benchmark helpers.",
188+ "Please add a regression case for wide token rows and scrollback-heavy conversations.",
189+ "tool: grep completed with 14 matches across packages/core/src/layout.ts and paint.ts",
190+ "The fix preserves controlled scroll offsets while keeping the cursor visible.",
191+];
192+
193+const MESSAGE_KINDS = ["user", "assistant", "tool"] as const;
194+
195+/** Build one wrapping HStack row with many styled Text token children. */
196+export function hstackTokenRow(tokenCount: number): ContainerNode {
197+ const children: Node[] = [];
198+ for (let i = 0; i < tokenCount; i++) {
199+ const index = i % TOKEN_TEXT.length;
200+ children.push(Text(TOKEN_TEXT[index], TOKEN_STYLES[index]));
201+ }
202+ return HStack({ flexWrap: "wrap" }, children);
203+}
204+
205+/** Build a syntax-highlight-like block without depending on clew. */
206+export function syntaxLikeBlock(
207+ lines: number,
208+ tokensPerLine: number,
209+): ContainerNode {
210+ const children: Node[] = [];
211+ for (let i = 0; i < lines; i++) {
212+ children.push(
213+ HStack({ flexWrap: "wrap" }, [
214+ Text(`${String(i + 1).padStart(3, " ")} │ `, { fgColor: "color08" }),
215+ ...hstackTokenRow(tokensPerLine).children,
216+ ]),
217+ );
218+ }
219+ return VStack({ gap: 0 }, children);
220+}
221+
222+function miniCoderMessage(index: number): ContainerNode {
223+ const kind = MESSAGE_KINDS[index % MESSAGE_KINDS.length];
224+ const isUser = kind === "user";
225+ const isTool = kind === "tool";
226+ const title = isUser ? "user" : isTool ? "tool" : "assistant";
227+ const color = isUser ? "color04" : isTool ? "color03" : "color02";
228+ const children: Node[] = [
229+ HStack({ gap: 1 }, [
230+ Text(title, { bold: true, fgColor: color }),
231+ Text(`#${index}`, { fgColor: "color08" }),
232+ Text(isTool ? "shell" : "chat", { fgColor: "color08" }),
233+ ]),
234+ Text(MESSAGE_BODIES[index % MESSAGE_BODIES.length], { wrap: "word" }),
235+ ];
236+
237+ if (!isUser) {
238+ children.push(syntaxLikeBlock(isTool ? 3 : 5, isTool ? 10 : 16));
239+ }
240+
241+ children.push(
242+ HStack({ gap: 1, flexWrap: "wrap" }, [
243+ HStack({ padding: { x: 1 }, bgColor: "color08" }, [
244+ Text(isTool ? "tool-call" : "tokens", { fgColor: "color00" }),
245+ ]),
246+ HStack({ padding: { x: 1 }, bgColor: "color00" }, [
247+ Text(isTool ? "exit 0" : `${800 + (index % 400)} tok`, {
248+ fgColor: "color07",
249+ }),
250+ ]),
251+ Text("cached", { fgColor: "color08" }),
252+ ]),
253+ );
254+
255+ return VStack(
256+ {
257+ gap: 1,
258+ padding: { x: 1, y: 1 },
259+ bgColor: isUser ? "color00" : undefined,
260+ fgColor: "color07",
261+ },
262+ children,
263+ );
264+}
265+
266+function miniCoderRoot(messages: Node[], totalMessages: number): ContainerNode {
267+ return VStack({ height: "100%", gap: 1, padding: { x: 1, y: 1 } }, [
268+ VStack(
269+ { flex: 1, gap: 1, overflow: "scroll", scrollOffset: Infinity },
270+ messages,
271+ ),
272+ HStack({ height: 1, gap: 1 }, [
273+ Text("mini-coder", { bold: true, fgColor: "color02" }),
274+ Text(`${totalMessages} messages`, { fgColor: "color08" }),
275+ Text("model: sonnet", { fgColor: "color08" }),
276+ ]),
277+ TextInput({
278+ height: 3,
279+ value: "Summarize the benchmark bottleneck and propose the next patch.",
280+ onChange: () => {},
281+ placeholder: Text("message mini-coder", { fgColor: "color08" }),
282+ bgColor: "color00",
283+ fgColor: "color07",
284+ }),
285+ ]);
286+}
287+
288+/** Build a mini-coder-next-like unvirtualized conversation tree. */
289+export function miniCoderNextConversationTree(
290+ messageCount: number,
291+): ContainerNode {
292+ const messages: Node[] = [];
293+ for (let i = 0; i < messageCount; i++) {
294+ messages.push(miniCoderMessage(i));
295+ }
296+ return miniCoderRoot(messages, messageCount);
297+}
298+
299+/**
300+ * Build a mini-coder-like virtualized conversation tree.
301+ * Only a visible slice is rendered; fixed-height spacers represent the rest.
302+ */
303+export function miniCoderVirtualizedConversationTree(
304+ totalMessages: number,
305+ visibleMessages: number,
306+): ContainerNode {
307+ const start = Math.max(0, totalMessages - visibleMessages);
308+ const hiddenBefore = start;
309+ const hiddenAfter = Math.max(0, totalMessages - start - visibleMessages);
310+ const messages: Node[] = [];
311+
312+ if (hiddenBefore > 0) {
313+ messages.push(VStack({ height: hiddenBefore * 8 }, []));
314+ }
315+ for (
316+ let i = start;
317+ i < Math.min(totalMessages, start + visibleMessages);
318+ i++
319+ ) {
320+ messages.push(miniCoderMessage(i));
321+ }
322+ if (hiddenAfter > 0) {
323+ messages.push(VStack({ height: hiddenAfter * 8 }, []));
324+ }
325+
326+ return miniCoderRoot(messages, totalMessages);
327+}
328+
329+/** Representative mini-coder-next message nodes for content-height measurement. */
330+export function miniCoderNextMeasureNodes(count: number): Node[] {
331+ const nodes: Node[] = [];
332+ for (let i = 0; i < count; i++) {
333+ nodes.push(miniCoderMessage(i));
334+ }
335+ return nodes;
336+}
337+
132338 /** Pure ASCII string for width benchmarking. */
133339 export const ASCII_STRING =
134340 "The quick brown fox jumps over the lazy dog. 0123456789!@#$%^&*()";