xonecas.io
64875
Mc

mini-coder / commit fcb7284

fix: resolve UI-REPORT issues — tilde paths, openai cache crash, error message extraction, spinner in non-TTY, token summary on one-shot

xonecas2026-03-14 fcb7284b3e586364528b98d90475d637c83312c5 parent 9bb2522

12 files changed

TODO.md+1−0
@@ -1,5 +1,6 @@
11 # TODO
22
3+- Remove markdown rendering from reasoning blocks. render raw in dimmed color. Remove the leading | character but keep the ident. Could we make it italic easily?
34 - Investigate db lock issues with spawning parallel subagents:
45
56 ```
src/agent/tools.test.ts+19−1
@@ -1,8 +1,9 @@
11 import { afterEach, beforeEach, describe, expect, test } from "bun:test";
22 import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3-import { tmpdir } from "node:os";
3+import { homedir, tmpdir } from "node:os";
44 import { join } from "node:path";
55 import { hashLine } from "../tools/hashline.ts";
6+import { resolvePath } from "../tools/shared.ts";
67 import { buildToolSet } from "./tools.ts";
78
89 let cwd = "";
@@ -119,3 +120,20 @@ describe("skills tools registration", () => {
119120 expect(names).toContain("readSkill");
120121 });
121122 });
123+
124+describe("resolvePath", () => {
125+ test("expands ~ to home directory", () => {
126+ const { filePath } = resolvePath("/any/cwd", "~/foo/bar");
127+ expect(filePath).toBe(join(homedir(), "foo/bar"));
128+ });
129+
130+ test("resolves absolute path as-is", () => {
131+ const { filePath } = resolvePath("/any/cwd", "/tmp/foo");
132+ expect(filePath).toBe("/tmp/foo");
133+ });
134+
135+ test("resolves relative path against cwd", () => {
136+ const { filePath } = resolvePath("/my/cwd", "foo/bar");
137+ expect(filePath).toBe("/my/cwd/foo/bar");
138+ });
139+});
src/cli/error-parse.test.ts+10−0
@@ -165,3 +165,13 @@ test("parseAppError - fallback", () => {
165165 headline: "Something went wrong",
166166 });
167167 });
168+
169+test("parseAppError - nested error object (SSE stream error payload)", () => {
170+ const err = { type: "error", error: { message: "model_not_found" } };
171+ expect(parseAppError(err)).toEqual({ headline: "model_not_found" });
172+});
173+
174+test("parseAppError - nested error object with empty message falls back", () => {
175+ const err = { type: "error", error: { message: "" } };
176+ expect(parseAppError(err)).toEqual({ headline: "[object Object]" });
177+});
src/cli/error-parse.ts+15−0
@@ -76,6 +76,21 @@ export function parseAppError(err: unknown): {
7676
7777 const isObj = typeof err === "object" && err !== null;
7878 const code = isObj && "code" in err ? String(err.code) : undefined;
79+
80+ // Handle streaming API error events, e.g. { type: "error", error: { message: "..." } }
81+ // from the OpenAI responses API or similar SSE error payloads.
82+ if (
83+ isObj &&
84+ "error" in err &&
85+ typeof (err as { error: unknown }).error === "object" &&
86+ (err as { error: unknown }).error !== null
87+ ) {
88+ const inner = (err as { error: { message?: unknown } }).error;
89+ if (typeof inner.message === "string" && inner.message) {
90+ return { headline: inner.message };
91+ }
92+ }
93+
7994 const message = isObj && "message" in err ? String(err.message) : String(err);
8095
8196 if (code === "ECONNREFUSED" || message.includes("ECONNREFUSED")) {
src/cli/error-render.ts+13−0
@@ -3,6 +3,19 @@ import { logError } from "./error-log.ts";
33 import { parseAppError } from "./error-parse.ts";
44 import { G, writeln } from "./output.ts";
55
6+/**
7+ * Thrown after an error has already been rendered to the terminal.
8+ * Outer catch blocks can check for this to avoid re-displaying the same error.
9+ */
10+export class RenderedError extends Error {
11+ public readonly cause: unknown;
12+ constructor(cause: unknown) {
13+ super("already rendered");
14+ this.name = "RenderedError";
15+ this.cause = cause;
16+ }
17+}
18+
619 export function renderError(err: unknown, context = "render"): void {
720 logError(err, context);
821 const parsed = parseAppError(err);
src/cli/spinner.test.ts+5−0
@@ -19,11 +19,14 @@ describe("SPINNER_FRAMES", () => {
1919 describe("Spinner", () => {
2020 test("clears the spinner line and shows cursor without advancing to a new line", () => {
2121 const originalWrite = process.stderr.write;
22+ const originalIsTTY = process.stderr.isTTY;
2223 let stderr = "";
2324 process.stderr.write = ((text: string) => {
2425 stderr += text;
2526 return true;
2627 }) as typeof process.stderr.write;
28+ // @ts-expect-error override read-only for test
29+ process.stderr.isTTY = true;
2730
2831 try {
2932 const spinner = new Spinner();
@@ -34,6 +37,8 @@ describe("Spinner", () => {
3437 expect(stderr).not.toContain("\n");
3538 } finally {
3639 process.stderr.write = originalWrite;
40+ // @ts-expect-error override read-only for test
41+ process.stderr.isTTY = originalIsTTY;
3742 }
3843 });
3944 });
src/cli/spinner.ts+1−0
@@ -8,6 +8,7 @@ export class Spinner {
88 private label = "";
99
1010 start(label = ""): void {
11+ if (!process.stderr.isTTY) return;
1112 this.label = label;
1213 if (this.timer) return;
1314 process.stderr.write("\x1B[?25l");
src/cli/stream-render.ts+3−1
@@ -4,6 +4,8 @@ import type { CoreMessage } from "../llm-api/turn.ts";
44 import type { TurnEvent } from "../llm-api/types.ts";
55 import { logError } from "./error-log.ts";
66 import { parseAppError } from "./error-parse.ts";
7+import { RenderedError } from "./error-render.ts";
8+
79 import { renderLine } from "./markdown.ts";
810 import { G, write, writeln } from "./output.ts";
911 import {
@@ -430,7 +432,7 @@ export async function renderTurn(
430432 if (parsed.hint) {
431433 writeln(` ${c.dim(parsed.hint)}`);
432434 }
433- throw event.error;
435+ throw new RenderedError(event.error);
434436 }
435437 break;
436438 }
src/index.ts+11−2
@@ -7,6 +7,7 @@ import { loadAgents } from "./cli/agents.ts";
77 import { parseArgs, printHelp } from "./cli/args.ts";
88 import { bootstrapGlobalDefaults } from "./cli/bootstrap.ts";
99 import { initErrorLog } from "./cli/error-log.ts";
10+import { RenderedError } from "./cli/error-render.ts";
1011 import { resolveFileRefs } from "./cli/file-refs.ts";
1112 import { HeadlessReporter } from "./cli/headless-reporter.ts";
1213 import { runInputLoop } from "./cli/input-loop.ts";
@@ -16,6 +17,7 @@ import {
1617 renderError,
1718 writeln,
1819 } from "./cli/output.ts";
20+
1921 import { CliReporter } from "./cli/output-reporter.ts";
2022 import { initApiLog } from "./llm-api/api-log.ts";
2123 import {
@@ -171,6 +173,9 @@ async function main(): Promise<void> {
171173 args.cwd,
172174 );
173175 await runner.processUserInput(resolvedText, refImages);
176+ writeln(
177+ ` ${c.dim(`${runner.totalIn.toLocaleString()} in / ${runner.totalOut.toLocaleString()} out tokens`)}`,
178+ );
174179 return;
175180 }
176181
@@ -181,12 +186,16 @@ async function main(): Promise<void> {
181186 runner,
182187 });
183188 } catch (err) {
184- renderError(err, "agent");
189+ if (!(err instanceof RenderedError)) {
190+ renderError(err, "agent");
191+ }
185192 process.exit(1);
186193 }
187194 }
188195
189196 main().catch((err) => {
190- renderError(err, "main");
197+ if (!(err instanceof RenderedError)) {
198+ renderError(err, "main");
199+ }
191200 process.exit(1);
192201 });
src/llm-api/providers.test.ts+8−8
@@ -46,11 +46,13 @@ describe("getCacheFamily", () => {
4646 expect(getCacheFamily("anthropic/claude-3-opus")).toBe("anthropic");
4747 expect(getCacheFamily("zen/claude-sonnet-4-6")).toBe("anthropic");
4848 });
49- test("identifies openai family", () => {
50- expect(getCacheFamily("openai/gpt-4")).toBe("openai");
51- expect(getCacheFamily("zen/gpt-4o")).toBe("openai");
52- expect(getCacheFamily("zen/o1")).toBe("openai");
49+ test("openai and zen/gpt-* return none (caching is automatic, no client hint needed)", () => {
50+ expect(getCacheFamily("openai/gpt-4")).toBe("none");
51+ expect(getCacheFamily("zen/gpt-4o")).toBe("none");
52+ expect(getCacheFamily("zen/o1")).toBe("none");
53+ expect(getCacheFamily("zen/gpt-5-nano")).toBe("none");
5354 });
55+
5456 test("identifies google family", () => {
5557 expect(getCacheFamily("google/gemini-2.0-flash")).toBe("google");
5658 expect(getCacheFamily("zen/gemini-2.5-pro")).toBe("google");
@@ -67,15 +69,13 @@ describe("getCachingProviderOptions", () => {
6769 ).toBeNull();
6870 });
6971
70- test("returns openai prompt cache retention", () => {
72+ test("returns null for openai (caching is automatic, no hint sent)", () => {
7173 expect(
7274 getCachingProviderOptions("openai/gpt-4", {
7375 enabled: true,
7476 openaiRetention: "24h",
7577 }),
76- ).toEqual({
77- openai: { promptCacheRetention: "24h" },
78- });
78+ ).toBeNull();
7979 });
8080
8181 test("returns google cached content when explicit caching is compatible", () => {
src/llm-api/providers.ts+0−8
@@ -306,14 +306,6 @@ export function getCacheFamily(modelString: string): CacheFamily {
306306 return "anthropic";
307307 }
308308
309- if (
310- provider === "openai" ||
311- (provider === "zen" &&
312- (modelId.startsWith("gpt-") || modelId.startsWith("o")))
313- ) {
314- return "openai";
315- }
316-
317309 if (
318310 provider === "google" ||
319311 (provider === "zen" && modelId.startsWith("gemini-"))
src/tools/shared.ts+8−1
@@ -1,8 +1,15 @@
1+import { homedir } from "node:os";
12 import { join, relative } from "node:path";
23
34 export function resolvePath(cwdInput: string | undefined, pathInput: string) {
45 const cwd = cwdInput ?? process.cwd();
5- const filePath = pathInput.startsWith("/") ? pathInput : join(cwd, pathInput);
6+ const expanded = pathInput.startsWith("~/")
7+ ? join(homedir(), pathInput.slice(2))
8+ : pathInput === "~"
9+ ? homedir()
10+ : pathInput;
11+ const filePath = expanded.startsWith("/") ? expanded : join(cwd, expanded);
12+
613 const relPath = relative(cwd, filePath);
714 return { cwd, filePath, relPath };
815 }