xonecas.io
64875
Mc

mini-coder / commit 7c721f8

feat(ui): improve session and input history picker labels

xonecas2026-04-08 7c721f8e7e5ca18ef0a0fb3d247187f8cd715c8d parent 498eb73

5 files changed

TODO.md+2−1
@@ -11,7 +11,9 @@ The spec.md and code are the sources of truth, not this file, don't assume anyth
1111
1212 ## Low priority (deffered until further notice)
1313
14+- [ ] **Reduce duplicate edit rendering in the conversation log** (`ui/conversation.ts`) — large edits currently appear twice in a row (tool-call preview and tool-result diff), which adds a lot of vertical noise.
1415 - [ ] **Prevent `/session` from switching sessions mid-run** (`ui/commands.ts`, `ui/agent.ts`) — selecting a session while a turn is active can desync UI state from the session the loop is still writing to.
16+- [ ] **Compact reasoning-heavy turns a bit better when `/reasoning` is on** (`ui/conversation.ts`) — for trivial prompts, visible reasoning can dominate the screen and bury the actual answer.
1517 - [ ] **XML-escape generated skill catalog fields** (`skills.ts`) — skill names, descriptions, and paths containing XML metacharacters can break the `<available_skills>` prompt block.
1618
1719 ## Plugin related (documented only, no plugin related work is planned right now)
@@ -24,7 +26,6 @@ The spec.md and code are the sources of truth, not this file, don't assume anyth
2426 ## Future ideas
2527
2628 - [ ] Headless one-shot CLI mode for non-interactive runs and benchmark harnesses like Harbor/Terminal-Bench (https://www.tbench.ai/)
27-- [ ] Session list preview — show first user message snippet in `/session` selector
2829 - [ ] Use dark/cold to warm/bright gradient for the statusbar backgrounds, the model info based on the thinking effort, and the session stats based on context percentage.
2930 - [ ] Divider theme plugin — customizable divider animations (scanning pulse, breathing, flowing dots, wave)
3031 - [ ] Backward-compatibility and migration policy for 1.0 (session/app data versioning, explicit migration strategy)
src/session.test.ts+32−0
@@ -147,6 +147,38 @@ describe("session persistence", () => {
147147 db.close();
148148 });
149149
150+ test("listSessions_firstUserPreview_ignoresLeadingUiMessagesAndUsesTheFirstTurn", () => {
151+ const db = openDatabase(":memory:");
152+ const session = createSession(db, {
153+ cwd: "/tmp/test",
154+ model: "test/beta",
155+ });
156+
157+ appendMessage(db, session.id, makeUiMessage("Help output"));
158+ const firstTurn = appendMessage(db, session.id, {
159+ role: "user",
160+ content: " first\n\n prompt\tpreview ",
161+ timestamp: 1,
162+ });
163+ appendMessage(db, session.id, makeAssistant("reply"), firstTurn);
164+ appendMessage(db, session.id, makeUser("later prompt"));
165+
166+ const [entry] = listSessions(db, "/tmp/test");
167+
168+ expect(entry?.firstUserPreview).toBe("first prompt preview");
169+ db.close();
170+ });
171+
172+ test("listSessions_firstUserPreview_returnsNullWhenTheSessionHasNoMessages", () => {
173+ const db = openDatabase(":memory:");
174+ createSession(db, { cwd: "/tmp/test" });
175+
176+ const [entry] = listSessions(db, "/tmp/test");
177+
178+ expect(entry?.firstUserPreview).toBeNull();
179+ db.close();
180+ });
181+
150182 test("deleteSession removes session and cascades to messages", () => {
151183 const db = openDatabase(":memory:");
152184 const session = createSession(db, { cwd: "/tmp/test" });
src/session.ts+68−5
@@ -41,6 +41,12 @@ export interface Session {
4141 updatedAt: number;
4242 }
4343
44+/** Session row used by the `/session` picker. */
45+export interface SessionListEntry extends Session {
46+ /** First conversational user message collapsed into a single-line preview, or `null` when none exists. */
47+ firstUserPreview: string | null;
48+}
49+
4450 /**
4551 * Cumulative input/output token and cost statistics for a session.
4652 *
@@ -123,6 +129,11 @@ type SessionRow = {
123129 updated_at: number;
124130 };
125131
132+/** Row shape returned by the `/session` picker query. */
133+type SessionListRow = SessionRow & {
134+ first_user_message_data: string | null;
135+};
136+
126137 /** Row shape for `SELECT MAX(turn)` queries. */
127138 type MaxTurnRow = { max_turn: number | null };
128139
@@ -143,8 +154,20 @@ type PromptHistoryRow = {
143154 // ---------------------------------------------------------------------------
144155
145156 const SQL = {
146- listSessions:
147- "SELECT * FROM sessions WHERE cwd = ? ORDER BY updated_at DESC, rowid DESC",
157+ listSessions: `
158+ SELECT
159+ sessions.*,
160+ (
161+ SELECT data
162+ FROM messages
163+ WHERE session_id = sessions.id AND turn IS NOT NULL
164+ ORDER BY id
165+ LIMIT 1
166+ ) AS first_user_message_data
167+ FROM sessions
168+ WHERE cwd = ?
169+ ORDER BY updated_at DESC, rowid DESC
170+ `,
148171 maxTurn: "SELECT MAX(turn) as max_turn FROM messages WHERE session_id = ?",
149172 loadMessages: "SELECT data FROM messages WHERE session_id = ? ORDER BY id",
150173 listPromptHistory:
@@ -271,15 +294,54 @@ export function getSession(db: Database, id: string): Session | null {
271294 };
272295 }
273296
297+/** Collapse preview text into a single readable line. */
298+function collapsePreviewText(text: string): string | null {
299+ const collapsed = text.replace(/\s+/g, " ").trim();
300+ return collapsed.length > 0 ? collapsed : null;
301+}
302+
303+function getMultipartUserPreview(
304+ content: Extract<Message, { role: "user" }>["content"],
305+): string | null {
306+ if (typeof content === "string") {
307+ return collapsePreviewText(content);
308+ }
309+
310+ const text = content
311+ .filter(
312+ (block): block is Extract<(typeof content)[number], { type: "text" }> => {
313+ return block.type === "text";
314+ },
315+ )
316+ .map((block) => block.text)
317+ .join(" ");
318+
319+ return collapsePreviewText(text);
320+}
321+
322+/** Read the first-user preview cached by the session-list query. */
323+function readFirstUserPreview(messageData: string | null): string | null {
324+ if (!messageData) {
325+ return null;
326+ }
327+
328+ const message = JSON.parse(messageData) as PersistedMessage;
329+ if (message.role !== "user") {
330+ return null;
331+ }
332+
333+ return getMultipartUserPreview(message.content);
334+}
335+
274336 /**
275337 * List sessions for a working directory, most recently updated first.
276338 *
277339 * @param db - Open database handle.
278340 * @param cwd - Working directory to filter by.
279- * @returns An array of {@link Session} records ordered by `updatedAt` descending.
341+ * @returns Session rows ordered by `updatedAt` descending, enriched with the first-user preview.
280342 */
281-export function listSessions(db: Database, cwd: string): Session[] {
282- const rows = db.query<SessionRow, [string]>(SQL.listSessions).all(cwd);
343+export function listSessions(db: Database, cwd: string): SessionListEntry[] {
344+ const rows = db.query<SessionListRow, [string]>(SQL.listSessions).all(cwd);
283345 return rows.map((row) => ({
284346 id: row.id,
285347 cwd: row.cwd,
@@ -288,6 +350,7 @@ export function listSessions(db: Database, cwd: string): Session[] {
288350 forkedFrom: row.forked_from,
289351 createdAt: row.created_at,
290352 updatedAt: row.updated_at,
353+ firstUserPreview: readFirstUserPreview(row.first_user_message_data),
291354 }));
292355 }
293356
src/ui/commands.test.ts+95−0
@@ -15,8 +15,10 @@ import { loadSettings } from "../settings.ts";
1515 import { DEFAULT_THEME } from "../theme.ts";
1616 import {
1717 createCommandController,
18+ formatPromptHistoryLabel,
1819 formatPromptHistoryPreview,
1920 formatRelativeDate,
21+ formatSessionLabel,
2022 } from "./commands.ts";
2123 import type { ActiveOverlay } from "./overlay.ts";
2224
@@ -224,6 +226,71 @@ describe("ui/commands", () => {
224226 }
225227 });
226228
229+ test("handleCommand('session') overlay includes the first user preview for disambiguation", () => {
230+ const state = createTestState();
231+ const runtimeState = { overlay: null as ActiveOverlay | null };
232+ const controller = createCommandController({
233+ openOverlay: (nextOverlay) => {
234+ runtimeState.overlay = nextOverlay;
235+ },
236+ dismissOverlay: () => {
237+ runtimeState.overlay = null;
238+ },
239+ setInputValue: () => {},
240+ appendInfoMessage: () => {},
241+ scrollConversationToBottom: () => {},
242+ render: () => {},
243+ reloadPromptContext: async () => {},
244+ openInBrowser: () => {},
245+ });
246+ const session = createSession(state.db, {
247+ cwd: state.canonicalCwd,
248+ model: "test/beta",
249+ effort: "high",
250+ });
251+
252+ state.db.run(
253+ "INSERT INTO messages (session_id, turn, data, created_at) VALUES (?, ?, ?, ?)",
254+ [
255+ session.id,
256+ null,
257+ JSON.stringify({
258+ role: "ui",
259+ kind: "info",
260+ content: "Help output",
261+ timestamp: 1,
262+ }),
263+ 1,
264+ ],
265+ );
266+ state.db.run(
267+ "INSERT INTO messages (session_id, turn, data, created_at) VALUES (?, ?, ?, ?)",
268+ [
269+ session.id,
270+ 1,
271+ JSON.stringify({
272+ role: "user",
273+ content: "Investigate\nthis session label",
274+ timestamp: 2,
275+ }),
276+ 2,
277+ ],
278+ );
279+
280+ try {
281+ expect(controller.handleCommand("session", state)).toBe(true);
282+
283+ const overlay = expectOverlay(runtimeState.overlay);
284+ const text = collectText(renderSelect(overlay));
285+
286+ expect(
287+ text.some((line) => line.includes("Investigate this session")),
288+ ).toBe(true);
289+ } finally {
290+ state.db.close();
291+ }
292+ });
293+
227294 test("handleCommand('session') restores the selected session and recomputes stats", () => {
228295 const state = createTestState();
229296 const runtimeState = { overlay: null as ActiveOverlay | null };
@@ -512,4 +579,32 @@ describe("ui/commands", () => {
512579 "first second third",
513580 );
514581 });
582+
583+ test("formatPromptHistoryLabel_longPromptAndCwd_returnsATruncatedSingleLineLabel", () => {
584+ expect(
585+ formatPromptHistoryLabel(
586+ " Investigate\n\n this prompt history row because it is much too wide for the overlay ",
587+ "/tmp/projects/very/deeply/nested/mini-coder-audit",
588+ "5m ago",
589+ ),
590+ ).toBe(
591+ "Investigate this prompt history… · …/mini-coder-audit · 5m ago",
592+ );
593+ });
594+
595+ test("formatSessionLabel_longPreviewAndModel_returnsATruncatedReadableLabel", () => {
596+ expect(
597+ formatSessionLabel(
598+ {
599+ model: "openai-codex/gpt-5.4-super-long-variant",
600+ firstUserPreview:
601+ "Audit the session selector because every entry looks identical in real usage",
602+ },
603+ "just now",
604+ true,
605+ ),
606+ ).toBe(
607+ "Audit the session selector… · openai-codex/gpt… · just now · current",
608+ );
609+ });
515610 });
src/ui/commands.ts+82−5
@@ -23,6 +23,7 @@ import {
2323 listPromptHistory,
2424 listSessions,
2525 loadMessages,
26+ type SessionListEntry,
2627 undoLastTurn,
2728 } from "../session.ts";
2829 import { updateSettings } from "../settings.ts";
@@ -135,6 +136,80 @@ export function formatPromptHistoryPreview(text: string): string {
135136 return text.replace(/\s+/g, " ").trim();
136137 }
137138
139+const HISTORY_PREVIEW_MAX_CHARS = 32;
140+const HISTORY_CWD_MAX_CHARS = 18;
141+const SESSION_PREVIEW_MAX_CHARS = 27;
142+const SESSION_MODEL_MAX_CHARS = 17;
143+
144+function truncateTrailingText(text: string, maxChars: number): string {
145+ if (text.length <= maxChars) {
146+ return text;
147+ }
148+ if (maxChars <= 1) {
149+ return "…";
150+ }
151+ return `${text.slice(0, maxChars - 1)}…`;
152+}
153+
154+function truncateLeadingText(text: string, maxChars: number): string {
155+ if (text.length <= maxChars) {
156+ return text;
157+ }
158+ if (maxChars <= 1) {
159+ return "…";
160+ }
161+ return `…${text.slice(text.length - (maxChars - 1))}`;
162+}
163+
164+/**
165+ * Format a prompt-history row for the Select overlay.
166+ *
167+ * @param text - Raw prompt text.
168+ * @param cwd - Prompt working directory.
169+ * @param date - Relative date label.
170+ * @returns A single-line prompt-history label with stable metadata suffixes.
171+ */
172+export function formatPromptHistoryLabel(
173+ text: string,
174+ cwd: string,
175+ date: string,
176+): string {
177+ const preview = truncateTrailingText(
178+ formatPromptHistoryPreview(text),
179+ HISTORY_PREVIEW_MAX_CHARS,
180+ );
181+ const displayCwd = truncateLeadingText(
182+ abbreviatePath(cwd),
183+ HISTORY_CWD_MAX_CHARS,
184+ );
185+ return `${preview} · ${displayCwd} · ${date}`;
186+}
187+
188+/**
189+ * Format a session-picker row for the Select overlay.
190+ *
191+ * @param session - Session metadata and first-user preview.
192+ * @param date - Relative date label.
193+ * @param isCurrent - Whether this is the active session.
194+ * @returns A single-line session label with readable preview and metadata.
195+ */
196+export function formatSessionLabel(
197+ session: Pick<SessionListEntry, "model" | "firstUserPreview">,
198+ date: string,
199+ isCurrent: boolean,
200+): string {
201+ const preview = truncateTrailingText(
202+ session.firstUserPreview ?? "No messages yet",
203+ SESSION_PREVIEW_MAX_CHARS,
204+ );
205+ const model = truncateTrailingText(
206+ session.model ?? "no model",
207+ SESSION_MODEL_MAX_CHARS,
208+ );
209+ const current = isCurrent ? " · current" : "";
210+ return `${preview} · ${model} · ${date}${current}`;
211+}
212+
138213 /** Lightweight item shape used by the shared Select-overlay helper. */
139214 interface OverlayItem {
140215 /** Label shown in the Select list. */
@@ -201,10 +276,9 @@ export function createCommandController(
201276 }
202277
203278 const items = history.map((entry) => {
204- const preview = formatPromptHistoryPreview(entry.text);
205279 const date = formatRelativeDate(new Date(entry.createdAt));
206280 return {
207- label: `${preview} · ${abbreviatePath(entry.cwd)} · ${date}`,
281+ label: formatPromptHistoryLabel(entry.text, entry.cwd, date),
208282 value: String(entry.id),
209283 filterText: `${entry.text} ${entry.cwd}`,
210284 };
@@ -293,11 +367,14 @@ export function createCommandController(
293367 const items = sessions.map((session) => {
294368 const dateStr = formatRelativeDate(new Date(session.updatedAt));
295369 const model = session.model ?? "no model";
296- const current = session.id === currentSessionId ? " (current)" : "";
297370 return {
298- label: `${dateStr} ${model}${current}`,
371+ label: formatSessionLabel(
372+ session,
373+ dateStr,
374+ session.id === currentSessionId,
375+ ),
299376 value: session.id,
300- filterText: `${dateStr} ${model}`,
377+ filterText: `${session.firstUserPreview ?? ""} ${model} ${dateStr}`,
301378 };
302379 });