xonecas.io
64875
Mc

mini-coder / commit 9081e32

fix: session loading with new TUIMessages

xonecas2026-05-25 9081e32d958bdf54c7ce42afebd271e457b058cf parent e055805

5 files changed

package.json+1−1
@@ -1,6 +1,6 @@
11 {
22 "name": "mini-coder",
3- "version": "0.6.4",
3+ "version": "0.6.5",
44 "type": "module",
55 "packageManager": "bun@1.3.12",
66 "bin": {
src/tui-components.ts+1−1
@@ -88,7 +88,7 @@ export function Spinner() {
8888 }
8989
9090 export function ActivityPill(state: TUIState, spinnerFrame: string) {
91- let label = "idle";
91+ let label = "";
9292 const frame = state.streaming ? spinnerFrame : "";
9393
9494 if (frame) {
src/tui-conversation.ts+23−5
@@ -68,23 +68,32 @@ function ConversationMessageToolCall(call: TUIToolCall) {
6868 outputNode = Text(call.output, { wrap: "word" });
6969 }
7070
71- return VStack({}, [
72- TextPill(call.tool, theme.black, theme.bwhite),
71+ let argumentNodes: Node[] = [];
7372
74- ...Object.entries(call.args).map(([key, value]) => {
73+ if (call.tool === "edit") {
74+ argumentNodes = [
75+ Text(`Writing... ~${estimateTokens(JSON.stringify(call.args))} tokens`),
76+ ];
77+ } else {
78+ argumentNodes = Object.entries(call.args).map(([key, value]) => {
7579 let node: Node | null = Text(String(value));
7680
7781 // Syntax highlight bash args
7882 if (call.tool === "bash") {
7983 node = SyntaxHighlight(String(value), "bash");
84+ return node;
8085 }
8186
8287 return HStack({ gap: 1 }, [
8388 Text(`${key}`, { italic: true, fgColor: theme.white }),
8489 node,
8590 ]);
86- }),
91+ });
92+ }
8793
94+ return VStack({}, [
95+ TextPill(call.tool, theme.black, theme.bwhite),
96+ ...argumentNodes,
8897 outputNode,
8998 ]);
9099 }
@@ -109,7 +118,7 @@ function ConversationMessage(message: TUIMessage) {
109118 {
110119 width: "100%",
111120 bgColor: message.role === "user" ? theme.bblack : undefined,
112- padding: { y: 1, x: 1 },
121+ padding: { y: 1, x: message.role === "user" ? 1 : 0 },
113122 },
114123 [SyntaxHighlight(message.text, "markdown")],
115124 ),
@@ -122,6 +131,15 @@ function ConversationMessage(message: TUIMessage) {
122131 );
123132 }
124133
134+ if (!message.thinking && !message.text.length && !message.toolCalls?.length) {
135+ blocks.push(
136+ Text(`Loading...`, {
137+ wrap: "word",
138+ fgColor: theme.bblack,
139+ }),
140+ );
141+ }
142+
125143 // Msg footer:
126144 blocks.push(
127145 Text(`on ${message.timestamp} by ${message.role}`, {
src/tui-overlay.ts+64−2
@@ -1,10 +1,14 @@
11 import { HStack, Text, TextInput, VStack } from "@cel-tui/core";
2-import { getModels, type ThinkingLevel } from "@earendil-works/pi-ai";
2+import {
3+ getModels,
4+ type Message,
5+ type ThinkingLevel,
6+} from "@earendil-works/pi-ai";
37 import { getOAuthProviders } from "@earendil-works/pi-ai/oauth";
48 import { saveSettings } from "./args";
59 import { getAvailableProviders } from "./oauth";
610 import { listSessionsForCwd } from "./session";
7-import { estimateTokens } from "./shared";
11+import { estimateTokens, formatTimestamp } from "./shared";
812 import { TextPill, theme } from "./tui-components";
913 import type { SelectOptions, SelectState, Session, TUIState } from "./types";
1014
@@ -302,6 +306,61 @@ export function mainMenu(state: TUIState) {
302306 state.overlay = false;
303307 };
304308
309+ const toTUIMessage = (msg: Message) => {
310+ const textFromContent = (
311+ content: string | { type: string; text?: string }[],
312+ ) =>
313+ typeof content === "string"
314+ ? content
315+ : content
316+ .filter((c) => c.type === "text")
317+ .map((c) => c.text ?? "")
318+ .join("")
319+ .trim();
320+
321+ if (msg.role === "user") {
322+ return {
323+ timestamp: formatTimestamp(msg.timestamp),
324+ role: "user" as const,
325+ text: textFromContent(msg.content)
326+ .replaceAll(/<system-reminder>[\s\S]*?<\/system-reminder>/g, "")
327+ .trim(),
328+ };
329+ } else {
330+ const text = msg.content
331+ .filter((c) => c.type === "text")
332+ .map((c) => c.text)
333+ .join("")
334+ .trim();
335+ const thinking = msg.content
336+ .filter((c) => c.type === "thinking")
337+ .map((c) => c.thinking)
338+ .join("")
339+ .trim();
340+ const toolCalls = msg.content
341+ .filter((c) => c.type === "toolCall")
342+ .map((c) => {
343+ const toolResult = state.messages.find(
344+ (m) => m.role === "toolResult" && m.toolCallId === c.id,
345+ );
346+ return {
347+ id: c.id,
348+ tool: c.name,
349+ args: c.arguments,
350+ output: toolResult ? textFromContent(toolResult.content) : "",
351+ };
352+ });
353+
354+ return {
355+ timestamp: formatTimestamp(msg.timestamp),
356+ role: "assistant" as const,
357+ text,
358+ thinking,
359+ toolCalls,
360+ };
361+ }
362+ };
363+
305364 const select = useSelectOverlay({
306365 ...mainPane,
307366 onSelect: (s) => {
@@ -331,6 +390,9 @@ export function mainMenu(state: TUIState) {
331390
332391 state.sessionId = session.id;
333392 state.messages = session.messages;
393+ state.tuiMessages = session.messages
394+ .filter((message) => message.role !== "toolResult")
395+ .map(toTUIMessage);
334396 state.prompt = "";
335397 state.contextSize = estimateTokens(JSON.stringify(state.messages));
336398 state.scrollOffset = 0;
src/tui.ts+1−0
@@ -89,6 +89,7 @@ export function initTUI(state: TUIState, leave: (s: string) => void) {
8989 if (state.prompt === ":n" || state.prompt === "/new") {
9090 state.sessionId = undefined;
9191 state.messages = [];
92+ state.tuiMessages = [];
9293 state.prompt = "";
9394 state.contextSize = 0;
9495 state.scrollOffset = 0;