@@ -1,514 +0,0 @@
1-#!/usr/bin/env bun
2-/**
3- * Manual one-shot UI test: renders example scenarios to stdout
4- * so you can visually inspect the console output.
5- *
6- * Usage: bun scripts/ui-oneshot.ts
7- */
8-import type { TurnEvent } from "../src/llm-api/types.ts";
9-import { renderBanner, renderError, renderUserMessage, writeln } from "../src/cli/output.ts";
10-import { Spinner } from "../src/cli/spinner.ts";
11-import { renderTurn } from "../src/cli/stream-render.ts";
12-import { renderToolCall, renderToolResult } from "../src/cli/tool-render.ts";
13-
14-function eventsFrom(events: TurnEvent[]): AsyncIterable<TurnEvent> {
15- return (async function* () {
16- for (const event of events) {
17- yield event;
18- }
19- })();
20-}
21-
22-function done(): TurnEvent {
23- return {
24- type: "turn-complete",
25- inputTokens: 1234,
26- outputTokens: 567,
27- contextTokens: 50000,
28- messages: [],
29- };
30-}
31-
32-function shell(opts: {
33- stdout?: string;
34- stderr?: string;
35- exitCode?: number;
36- success?: boolean;
37-}) {
38- return {
39- stdout: opts.stdout ?? "",
40- stderr: opts.stderr ?? "",
41- exitCode: opts.exitCode ?? 0,
42- success: opts.success ?? true,
43- timedOut: false,
44- };
45-}
46-
47-function separator(title: string) {
48- writeln(`\n${"─".repeat(60)}`);
49- writeln(` ${title}`);
50- writeln(`${"─".repeat(60)}\n`);
51-}
52-
53-async function main() {
54- // ── Banner ──────────────────────────────────────────────
55- separator("1. Banner");
56- renderBanner("claude-sonnet-4-20250514", "~/projects/my-app");
57-
58- // ── User message ───────────────────────────────────────
59- separator("2. User message (single line)");
60- renderUserMessage("Fix the failing tests in src/utils.ts");
61-
62- separator("3. User message (multi-line)");
63- renderUserMessage(
64- "Please review these files:\n- src/index.ts\n- src/utils.ts\n- src/config.ts",
65- );
66-
67- // ── Simple text reply ──────────────────────────────────
68- separator("4. Simple text reply (no reasoning)");
69- await renderTurn(
70- eventsFrom([
71- { type: "text-delta", delta: "I'll take a look at those files for you." },
72- done(),
73- ]),
74- new Spinner(),
75- );
76-
77- // ── Reasoning + text reply ─────────────────────────────
78- separator("5. Reasoning → text reply");
79- await renderTurn(
80- eventsFrom([
81- {
82- type: "reasoning-delta",
83- delta:
84- "The user wants me to fix failing tests. Let me check the test file first to understand the failures.",
85- },
86- {
87- type: "text-delta",
88- delta:
89- "I'll start by examining the test file to understand what's failing.",
90- },
91- done(),
92- ]),
93- new Spinner(),
94- );
95-
96- // ── Single tool call ───────────────────────────────────
97- separator("6. Single tool call (shell)");
98- await renderTurn(
99- eventsFrom([
100- {
101- type: "tool-call-start",
102- toolName: "shell",
103- toolCallId: "t1",
104- args: { command: "bun test src/utils.test.ts 2>&1 | tail -20" },
105- },
106- {
107- type: "tool-result",
108- toolName: "shell",
109- toolCallId: "t1",
110- isError: false,
111- result: shell({
112- stdout:
113- "src/utils.test.ts:\n(pass) parseConfig > handles defaults\n(fail) parseConfig > validates required fields\n(pass) parseConfig > merges overrides\n\n 2 pass\n 1 fail\n 5 expect() calls",
114- exitCode: 1,
115- success: false,
116- }),
117- },
118- {
119- type: "text-delta",
120- delta:
121- "I can see one test is failing. Let me look at the test to understand the expected behavior.",
122- },
123- done(),
124- ]),
125- new Spinner(),
126- );
127-
128- // ── Parallel tool calls ────────────────────────────────
129- separator("7. Parallel tool calls (2 shells)");
130- await renderTurn(
131- eventsFrom([
132- {
133- type: "reasoning-delta",
134- delta: "I need to read both the source and test file to understand the issue.",
135- },
136- {
137- type: "tool-call-start",
138- toolName: "shell",
139- toolCallId: "p1",
140- args: { command: "cat src/utils.ts" },
141- },
142- {
143- type: "tool-call-start",
144- toolName: "shell",
145- toolCallId: "p2",
146- args: { command: "cat src/utils.test.ts" },
147- },
148- {
149- type: "tool-result",
150- toolName: "shell",
151- toolCallId: "p1",
152- isError: false,
153- result: shell({
154- stdout:
155- 'export function parseConfig(raw: unknown): Config {\n if (typeof raw !== "object" || raw === null) {\n throw new Error("invalid config");\n }\n return { ...defaults, ...raw };\n}',
156- }),
157- },
158- {
159- type: "tool-result",
160- toolName: "shell",
161- toolCallId: "p2",
162- isError: false,
163- result: shell({
164- stdout:
165- 'test("validates required fields", () => {\n expect(() => parseConfig(null)).toThrow("invalid config");\n expect(() => parseConfig({})).toThrow("missing required");\n});',
166- }),
167- },
168- {
169- type: "text-delta",
170- delta:
171- "Found the issue! The test expects `parseConfig({})` to throw `\"missing required\"`, but the function only throws for non-objects.",
172- },
173- done(),
174- ]),
175- new Spinner(),
176- );
177-
178- // ── Parallel mixed tools ───────────────────────────────
179- separator("8. Parallel mixed tools (shell + readSkill)");
180- await renderTurn(
181- eventsFrom([
182- {
183- type: "tool-call-start",
184- toolName: "shell",
185- toolCallId: "m1",
186- args: { command: "wc -l src/**/*.ts" },
187- },
188- {
189- type: "tool-call-start",
190- toolName: "readSkill",
191- toolCallId: "m3",
192- args: { name: "testing" },
193- },
194- {
195- type: "tool-result",
196- toolName: "shell",
197- toolCallId: "m1",
198- isError: false,
199- result: shell({
200- stdout: " 142 src/index.ts\n 87 src/utils.ts\n 45 src/config.ts\n 274 total",
201- }),
202- },
203- {
204- type: "tool-result",
205- toolName: "readSkill",
206- toolCallId: "m3",
207- isError: false,
208- result: {
209- skill: { name: "testing", description: "Testing best practices", source: "local" },
210- },
211- },
212- {
213- type: "text-delta",
214- delta: "Based on the code review and testing guidelines, here are my recommendations.",
215- },
216- done(),
217- ]),
218- new Spinner(),
219- );
220-
221- // ── Tool error ─────────────────────────────────────────
222- separator("9. Tool call with error");
223- await renderTurn(
224- eventsFrom([
225- {
226- type: "tool-call-start",
227- toolName: "shell",
228- toolCallId: "e1",
229- args: { command: "rm -rf /protected" },
230- },
231- {
232- type: "tool-result",
233- toolName: "shell",
234- toolCallId: "e1",
235- isError: true,
236- result: "permission denied: /protected",
237- },
238- {
239- type: "text-delta",
240- delta: "I don't have permission to modify that directory.",
241- },
242- done(),
243- ]),
244- new Spinner(),
245- );
246-
247- // ── Parallel with mixed success/error ──────────────────
248- separator("10. Parallel calls: one success, one error");
249- await renderTurn(
250- eventsFrom([
251- {
252- type: "tool-call-start",
253- toolName: "shell",
254- toolCallId: "x1",
255- args: { command: "cat README.md" },
256- },
257- {
258- type: "tool-call-start",
259- toolName: "shell",
260- toolCallId: "x2",
261- args: { command: "cat MISSING.md" },
262- },
263- {
264- type: "tool-result",
265- toolName: "shell",
266- toolCallId: "x1",
267- isError: false,
268- result: shell({ stdout: "# My Project\n\nA cool project." }),
269- },
270- {
271- type: "tool-result",
272- toolName: "shell",
273- toolCallId: "x2",
274- isError: false,
275- result: shell({
276- stderr: "cat: MISSING.md: No such file or directory",
277- exitCode: 1,
278- success: false,
279- }),
280- },
281- {
282- type: "text-delta",
283- delta: "README exists but MISSING.md doesn't. Let me create it.",
284- },
285- done(),
286- ]),
287- new Spinner(),
288- );
289-
290- // ── Context pruned ─────────────────────────────────────
291- separator("11. Context pruned event");
292- await renderTurn(
293- eventsFrom([
294- {
295- type: "context-pruned",
296- mode: "balanced",
297- beforeMessageCount: 120,
298- afterMessageCount: 80,
299- removedMessageCount: 40,
300- beforeTotalBytes: 65536,
301- afterTotalBytes: 40960,
302- removedBytes: 24576,
303- },
304- {
305- type: "text-delta",
306- delta: "I've been working on this for a while. Let me continue where I left off.",
307- },
308- done(),
309- ]),
310- new Spinner(),
311- );
312-
313- // ── Error rendering ────────────────────────────────────
314- separator("12. Error messages");
315- renderError("API rate limit exceeded. Retrying in 30s...");
316- writeln("");
317- renderError("Connection timed out after 60s");
318-
319- // ── Full realistic session ─────────────────────────────
320- separator("13. Realistic multi-turn snippet");
321- renderUserMessage("Fix the type error in src/config.ts");
322- writeln("");
323- await renderTurn(
324- eventsFrom([
325- {
326- type: "reasoning-delta",
327- delta: "Let me look at the file to find the type error.",
328- },
329- {
330- type: "tool-call-start",
331- toolName: "shell",
332- toolCallId: "r1",
333- args: { command: "bun run typecheck 2>&1 | grep 'config.ts'" },
334- },
335- {
336- type: "tool-result",
337- toolName: "shell",
338- toolCallId: "r1",
339- isError: false,
340- result: shell({
341- stdout:
342- "src/config.ts(12,5): error TS2322: Type 'string' is not assignable to type 'number'.",
343- exitCode: 1,
344- success: false,
345- }),
346- },
347- {
348- type: "reasoning-delta",
349- delta:
350- "Line 12 has a type mismatch. The port should be a number but is being set as a string.",
351- },
352- {
353- type: "tool-call-start",
354- toolName: "shell",
355- toolCallId: "r2",
356- args: { command: "sed -n '10,15p' src/config.ts" },
357- },
358- {
359- type: "tool-result",
360- toolName: "shell",
361- toolCallId: "r2",
362- isError: false,
363- result: shell({
364- stdout:
365- ' const config = {\n host: env.HOST ?? "localhost",\n port: env.PORT ?? "3000",\n debug: env.DEBUG === "true",\n };',
366- }),
367- },
368- {
369- type: "tool-call-start",
370- toolName: "shell",
371- toolCallId: "r3",
372- args: {
373- command:
374- 'mc-edit src/config.ts --old \'port: env.PORT ?? "3000"\' --new \'port: Number(env.PORT ?? "3000")\'',
375- },
376- },
377- {
378- type: "tool-result",
379- toolName: "shell",
380- toolCallId: "r3",
381- isError: false,
382- result: shell({ stdout: "ok: true\npath: src/config.ts\nchanged: true" }),
383- },
384- {
385- type: "tool-call-start",
386- toolName: "shell",
387- toolCallId: "r4",
388- args: { command: "bun run typecheck 2>&1" },
389- },
390- {
391- type: "tool-result",
392- toolName: "shell",
393- toolCallId: "r4",
394- isError: false,
395- result: shell({ stdout: "" }),
396- },
397- {
398- type: "text-delta",
399- delta:
400- 'Fixed the type error on line 12 of `src/config.ts`. The `port` field was being assigned a string from `env.PORT ?? "3000"` — wrapped it in `Number()` to coerce to the expected `number` type. Typecheck passes now.',
401- },
402- done(),
403- ]),
404- new Spinner(),
405- );
406-
407- // ── Web search ──────────────────────────────────────────
408- separator("14. Web search results");
409- await renderTurn(
410- eventsFrom([
411- {
412- type: "tool-call-start",
413- toolName: "webSearch",
414- toolCallId: "ws1",
415- args: { query: "bun test runner docs" },
416- },
417- {
418- type: "tool-result",
419- toolName: "webSearch",
420- toolCallId: "ws1",
421- isError: false,
422- result: {
423- results: [
424- {
425- title: "Bun Test Runner Documentation",
426- url: "https://bun.sh/docs/cli/test",
427- score: 0.95,
428- },
429- {
430- title: "Testing with Bun - Getting Started",
431- url: "https://bun.sh/guides/test/getting-started",
432- score: 0.87,
433- },
434- ],
435- },
436- },
437- {
438- type: "text-delta",
439- delta: "Found the relevant documentation.",
440- },
441- done(),
442- ]),
443- new Spinner(),
444- );
445-
446- // ── Web content ─────────────────────────────────────────
447- separator("16. Web content fetch");
448- await renderTurn(
449- eventsFrom([
450- {
451- type: "tool-call-start",
452- toolName: "webContent",
453- toolCallId: "wc1",
454- args: { urls: ["https://bun.sh/docs/cli/test"] },
455- },
456- {
457- type: "tool-result",
458- toolName: "webContent",
459- toolCallId: "wc1",
460- isError: false,
461- result: {
462- results: [
463- {
464- title: "Bun Test Runner Documentation",
465- url: "https://bun.sh/docs/cli/test",
466- text: "Bun ships with a fast built-in test runner. Tests are written in TypeScript or JavaScript using a familiar Jest-like API.",
467- },
468- ],
469- },
470- },
471- {
472- type: "text-delta",
473- delta: "The docs confirm Bun uses a Jest-like API.",
474- },
475- done(),
476- ]),
477- new Spinner(),
478- );
479-
480- // ── List skills ─────────────────────────────────────────
481- separator("17. List skills");
482- await renderTurn(
483- eventsFrom([
484- {
485- type: "tool-call-start",
486- toolName: "listSkills",
487- toolCallId: "ls1",
488- args: {},
489- },
490- {
491- type: "tool-result",
492- toolName: "listSkills",
493- toolCallId: "ls1",
494- isError: false,
495- result: {
496- skills: [
497- { name: "mini-coder", description: "How to use the mc CLI coding agent", source: "local" },
498- { name: "deploy", description: "Deployment guidelines", source: "global" },
499- ],
500- },
501- },
502- {
503- type: "text-delta",
504- delta: "Found 2 available skills.",
505- },
506- done(),
507- ]),
508- new Spinner(),
509- );
510-
511- writeln("");
512-}
513-
514-main();