Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

feat(cli): improve CLI transcript UI and scrolling

gallonHb123603a9ba5
diff --git a/jiuwenclaw/cli/src/core/commands/builtins/resume.ts b/jiuwenclaw/cli/src/core/commands/builtins/resume.ts
index d2defdee4b..4f98bb977d 100644
--- a/jiuwenclaw/cli/src/core/commands/builtins/resume.ts
+++ b/jiuwenclaw/cli/src/core/commands/builtins/resume.ts
@@ -24,12 +24,6 @@ interface ResumeResumePayload {
preview?: string;
}
-type ResumePayload = SessionListPayload | ResumeResumePayload;
-
-function isListPayload(payload: ResumePayload): payload is SessionListPayload {
- return Array.isArray((payload as SessionListPayload).sessions);
-}
-
export function createResumeCommand(): SlashCommand {
return {
name: "resume",
diff --git a/jiuwenclaw/cli/src/core/commands/builtins/team.ts b/jiuwenclaw/cli/src/core/commands/builtins/team.ts
index 4026590c9a..6f420945d3 100644
--- a/jiuwenclaw/cli/src/core/commands/builtins/team.ts
+++ b/jiuwenclaw/cli/src/core/commands/builtins/team.ts
@@ -11,7 +11,12 @@ export function createTeamCommand(): SlashCommand {
kind: CommandKind.BUILT_IN,
action: async (ctx) => {
if (ctx.isProcessing) {
- ctx.addItem(addError(ctx.sessionId, "session is busy; stop the current run before switching team mode"));
+ ctx.addItem(
+ addError(
+ ctx.sessionId,
+ "session is busy; stop the current run before switching team mode",
+ ),
+ );
return;
}
diff --git a/jiuwenclaw/cli/src/core/event-handlers.ts b/jiuwenclaw/cli/src/core/event-handlers.ts
index ec998edbce..e4dccfe321 100644
--- a/jiuwenclaw/cli/src/core/event-handlers.ts
+++ b/jiuwenclaw/cli/src/core/event-handlers.ts
@@ -101,7 +101,9 @@ function normalizePendingQuestion(payload: Record<string, unknown>): PendingQues
question: typeof item.question === "string" ? item.question : "",
options: Array.isArray(item.options)
? item.options
- .filter((option): option is Record<string, unknown> => Boolean(option && typeof option === "object"))
+ .filter((option): option is Record<string, unknown> =>
+ Boolean(option && typeof option === "object"),
+ )
.map((option) => ({
label: typeof option.label === "string" ? option.label : "",
description: typeof option.description === "string" ? option.description : undefined,
@@ -146,27 +148,13 @@ function handleDelta(
const entries = delegate.getEntries();
if (payload.source_chunk_type === "llm_reasoning") {
- const existingIndex = findLastIndex(entries, (entry) => entry.kind === "thinking");
- if (existingIndex === -1) {
- delegate.setEntries([
- ...entries,
- {
- kind: "thinking",
- id: createId("reasoning"),
- sessionId: activeSessionId,
- content,
- at: new Date().toISOString(),
- },
- ]);
- return true;
- }
- delegate.setEntries(
- entries.map((entry, index) =>
- index === existingIndex && entry.kind === "thinking"
- ? { ...entry, content: `${entry.content}${content}` }
- : entry,
- ),
- );
+ appendEntry(delegate, {
+ kind: "thinking",
+ id: createId("reasoning"),
+ sessionId: activeSessionId,
+ content,
+ at: new Date().toISOString(),
+ });
return true;
}
@@ -208,14 +196,32 @@ function handleFinal(
): boolean {
const content = typeof payload.content === "string" ? payload.content : "";
const entries = delegate.getEntries();
- const hasStreaming = entries.some((entry) => entry.kind === "assistant" && entry.streaming);
+ const streamingIndex = findLastIndex(
+ entries,
+ (entry) => entry.kind === "assistant" && entry.streaming === true,
+ );
delegate.setEntries(
- hasStreaming
- ? entries.map((entry) =>
- entry.kind === "assistant" && entry.streaming
- ? { ...entry, content: content || entry.content, streaming: false }
- : entry,
- )
+ streamingIndex !== -1
+ ? [
+ ...entries.filter(
+ (entry, index) => !(index === streamingIndex && entry.kind === "assistant"),
+ ),
+ {
+ ...(entries[streamingIndex] as Extract<HistoryItem, { kind: "assistant" }>),
+ content:
+ content ||
+ (entries[streamingIndex]?.kind === "assistant"
+ ? entries[streamingIndex].content
+ : ""),
+ requestId:
+ typeof payload.request_id === "string"
+ ? payload.request_id
+ : entries[streamingIndex]?.kind === "assistant"
+ ? entries[streamingIndex].requestId
+ : undefined,
+ streaming: false,
+ },
+ ]
: [
...entries,
{
diff --git a/jiuwenclaw/cli/src/ui/app-screen.ts b/jiuwenclaw/cli/src/ui/app-screen.ts
index edf25e9848..df8aa56216 100644
--- a/jiuwenclaw/cli/src/ui/app-screen.ts
+++ b/jiuwenclaw/cli/src/ui/app-screen.ts
@@ -17,6 +17,88 @@ import { padToWidth } from "./rendering/text.js";
import { editorTheme, palette, selectListTheme } from "./theme.js";
const END_CURSOR = "\x1b[7m \x1b[0m";
+const PERMISSION_TOOL_RE = /工具\s+`([^`]+)`\s+需要授权/;
+const PERMISSION_RISK_RE = /安全风险评估:\**\s*([^\s*]+)?\s*\**([^*\n]+?风险)\**/m;
+const PERMISSION_QUOTE_RE = /^>\s*(.+)$/gm;
+const PERMISSION_JSON_BLOCK_RE = /```json\s*([\s\S]*?)\s*```/i;
+
+type PermissionSummary = {
+ tool?: string;
+ risk?: string;
+ reason?: string;
+ command?: string;
+ description?: string;
+};
+
+function isPermissionRequest(source: string | undefined, questionText: string): boolean {
+ return source === "permission" || PERMISSION_TOOL_RE.test(questionText);
+}
+
+function parsePermissionSummary(questionText: string): PermissionSummary {
+ const tool = PERMISSION_TOOL_RE.exec(questionText)?.[1]?.trim();
+ const riskMatch = PERMISSION_RISK_RE.exec(questionText);
+ const risk = riskMatch
+ ? `${(riskMatch[1] ?? "").trim()} ${riskMatch[2].trim()}`.trim()
+ : undefined;
+ const reason = [...questionText.matchAll(PERMISSION_QUOTE_RE)]
+ .map((match) => match[1]?.trim() ?? "")
+ .find(Boolean);
+
+ let command: string | undefined;
+ let description: string | undefined;
+ const jsonBlock = PERMISSION_JSON_BLOCK_RE.exec(questionText)?.[1]?.trim();
+ if (jsonBlock) {
+ try {
+ const parsed = JSON.parse(jsonBlock) as Record<string, unknown>;
+ command =
+ typeof parsed.command === "string"
+ ? parsed.command.trim()
+ : typeof parsed.cmd === "string"
+ ? parsed.cmd.trim()
+ : undefined;
+ description = typeof parsed.description === "string" ? parsed.description.trim() : undefined;
+ } catch {
+ // Ignore malformed JSON blocks in permission prompts.
+ }
+ }
+
+ return {
+ tool,
+ risk,
+ reason,
+ command,
+ description,
+ };
+}
+
+function wrapPlainText(text: string, width: number): string[] {
+ const maxWidth = Math.max(12, width - 1);
+ const source = text.replace(/\r/g, "").split("\n");
+ const lines: string[] = [];
+ for (const rawLine of source) {
+ const words = rawLine.split(/\s+/).filter((word) => word.length > 0);
+ if (words.length === 0) {
+ lines.push("");
+ continue;
+ }
+ let current = "";
+ for (const word of words) {
+ const next = current ? `${current} ${word}` : word;
+ if (next.length <= maxWidth) {
+ current = next;
+ continue;
+ }
+ if (current) {
+ lines.push(current);
+ }
+ current = word.length <= maxWidth ? word : word.slice(0, maxWidth);
+ }
+ if (current) {
+ lines.push(current);
+ }
+ }
+ return lines.length > 0 ? lines : [text.slice(0, maxWidth)];
+}
export class AppScreen implements Component, Focusable {
private readonly editor: Editor;
@@ -27,7 +109,7 @@ export class AppScreen implements Component, Focusable {
private draftBeforeQuestion = "";
private pendingQuestionAnswers = new Map<number, string>();
private questionList: SelectList | null = null;
- private showFullThinking = false;
+ private showFullThinking = true;
private showToolDetails = false;
private showShortcutHelp = false;
private exitArmedUntil = 0;
@@ -134,7 +216,6 @@ export class AppScreen implements Component, Focusable {
const questionLines = this.buildPendingQuestionLines(snapshot, width);
return buildAppScreenLines(snapshot, {
width,
- terminalRows: this.tui.terminal.rows,
questionLines,
editorLines,
showFullThinking: this.showFullThinking,
@@ -287,29 +368,68 @@ export class AppScreen implements Component, Focusable {
}));
}
- private buildPendingQuestionLines(snapshot: ReturnType<CliPiAppState["getSnapshot"]>, width: number): string[] {
+ private buildPendingQuestionLines(
+ snapshot: ReturnType<CliPiAppState["getSnapshot"]>,
+ width: number,
+ ): string[] {
const pendingQuestion = snapshot.pendingQuestion;
if (!pendingQuestion) {
return [];
}
- const question = pendingQuestion.questions[this.activeQuestionIndex] ?? pendingQuestion.questions[0];
+ const question =
+ pendingQuestion.questions[this.activeQuestionIndex] ?? pendingQuestion.questions[0];
if (!question) {
return [];
}
const total = pendingQuestion.questions.length;
const progress = total > 1 ? ` (${this.activeQuestionIndex + 1}/${total})` : "";
- const lines = this.wrapQuestionText(`[${question.header || "Question"}${progress}] ${question.question}`, width).map(
- (line) => padToWidth(palette.status.warning(line), width),
- );
+ const permissionRequest = isPermissionRequest(pendingQuestion.source, question.question);
+ const lines: string[] = [];
+
+ if (permissionRequest) {
+ const summary = parsePermissionSummary(question.question);
+ lines.push(
+ padToWidth(
+ palette.status.warning(
+ `Permission${progress ? ` ${this.activeQuestionIndex + 1}/${total}` : ""}`,
+ ),
+ width,
+ ),
+ );
+ if (summary.tool) {
+ lines.push(padToWidth(palette.text.assistant(`${summary.tool} wants to run`), width));
+ }
+ const primaryDetail = summary.command ?? summary.description ?? summary.reason;
+ if (primaryDetail) {
+ lines.push(
+ ...wrapPlainText(primaryDetail, width)
+ .slice(0, 2)
+ .map((line) =>
+ padToWidth(summary.command ? palette.text.tool(line) : palette.text.dim(line), width),
+ ),
+ );
+ }
+ } else {
+ lines.push(
+ ...wrapPlainText(
+ `[${question.header || "Question"}${progress}] ${question.question}`,
+ width,
+ ).map((line) => padToWidth(palette.status.warning(line), width)),
+ );
+ }
if (this.questionList !== null) {
lines.push(" ".repeat(width));
lines.push(...this.questionList.render(width));
lines.push(
padToWidth(
- palette.text.dim("Use ↑/↓ to choose, Enter to confirm, Esc to reject"),
+ palette.text.dim(
+ permissionRequest
+ ? "Use ↑/↓ to review options, Enter to approve, Esc to reject"
+ : "Use ↑/↓ to choose, Enter to confirm, Esc to reject",
+ ),
width,
),
);
@@ -319,35 +439,6 @@ export class AppScreen implements Component, Focusable {
return lines;
}
- private wrapQuestionText(text: string, width: number): string[] {
- const maxWidth = Math.max(12, width - 1);
- const source = text.replace(/\r/g, "").split("\n");
- const lines: string[] = [];
- for (const rawLine of source) {
- const words = rawLine.split(/\s+/).filter((word) => word.length > 0);
- if (words.length === 0) {
- lines.push("");
- continue;
- }
- let current = "";
- for (const word of words) {
- const next = current ? `${current} ${word}` : word;
- if (next.length <= maxWidth) {
- current = next;
- continue;
- }
- if (current) {
- lines.push(current);
- }
- current = word.length <= maxWidth ? word : word.slice(0, maxWidth);
- }
- if (current) {
- lines.push(current);
- }
- }
- return lines.length > 0 ? lines : [text.slice(0, maxWidth)];
- }
-
private syncQuestionList(snapshot: ReturnType<CliPiAppState["getSnapshot"]>): void {
const pendingQuestion = snapshot.pendingQuestion;
if (!pendingQuestion) {
diff --git a/jiuwenclaw/cli/src/ui/components/messages/basic-message-components.ts b/jiuwenclaw/cli/src/ui/components/messages/basic-message-components.ts
index fbc802d4fb..a6c94762a8 100644
--- a/jiuwenclaw/cli/src/ui/components/messages/basic-message-components.ts
+++ b/jiuwenclaw/cli/src/ui/components/messages/basic-message-components.ts
@@ -1,6 +1,6 @@
import { truncateToWidth, type Component } from "@mariozechner/pi-tui";
import type { HistoryItem } from "../../../core/types.js";
-import { palette } from "../../theme.js";
+import { chalk, palette } from "../../theme.js";
import {
prefixedLines,
renderMarkdownLines,
@@ -26,7 +26,7 @@ export class UserMessageComponent implements Component {
1,
1,
);
- return prefixedLines(lines, width, "> ", palette.text.accent);
+ return prefixedLines(lines, width, "> ", palette.text.user, "│ ");
}
}
@@ -40,15 +40,15 @@ export class AssistantMessageComponent implements Component {
if (!body) {
return [];
}
- const lines = renderMarkdownLines(Math.max(1, width - 2), body, 1, 0);
+ const lines = renderMarkdownLines(width, body, 0, 0);
if (this.entry.streaming && lines.length > 0) {
const lastIndex = lines.length - 1;
lines[lastIndex] = truncateToWidth(
- lines[lastIndex] + palette.status.warning(" [streaming]"),
- Math.max(1, width - 2),
+ lines[lastIndex] + palette.status.warning(" …"),
+ Math.max(1, width),
);
}
- return prefixedLines(lines, width, "• ", palette.text.dim);
+ return lines;
}
}
@@ -62,18 +62,13 @@ export class ThinkingMessageComponent implements Component {
render(width: number): string[] {
if (!this.expanded) {
- const lines = renderStyledMarkdownLines(
- Math.max(1, width - 2),
- "Thinking...",
- {
- color: palette.text.dim,
- italic: true,
- },
- 1,
- 0,
+ return renderWrappedText(width, "thinking", (value) =>
+ chalk.italic(palette.text.thinking(value)),
);
- return prefixedLines(lines, width, "• ", palette.status.success);
}
+ const lines = renderWrappedText(width, "thinking", (value) =>
+ chalk.italic(palette.text.thinking(value)),
+ );
const wrapped = renderStyledMarkdownLines(
Math.max(1, width - 2),
this.entry.content,
@@ -81,10 +76,10 @@ export class ThinkingMessageComponent implements Component {
color: palette.text.dim,
italic: true,
},
- 1,
+ 0,
0,
);
- return prefixedLines(wrapped, width, "• ", palette.status.success);
+ return [...lines, ...prefixedLines(wrapped, width, "│ ", palette.text.dim, "│ ")];
}
}
@@ -94,12 +89,7 @@ export class SystemMessageComponent implements Component {
invalidate(): void {}
render(width: number): string[] {
- return prefixedLines(
- renderWrappedText(Math.max(1, width - 2), this.entry.content, palette.text.dim),
- width,
- "· ",
- palette.text.dim,
- );
+ return renderWrappedText(width, `· ${this.entry.content}`, palette.text.system);
}
}
@@ -114,6 +104,7 @@ export class ErrorMessageComponent implements Component {
width,
"! ",
palette.status.error,
+ " ",
);
}
}
@@ -126,17 +117,19 @@ export class InfoMessageComponent implements Component {
render(width: number): string[] {
const meta = this.entry.meta;
const lines: string[] = [];
- const innerWidth = Math.max(1, width - 2);
+ const innerWidth = Math.max(1, width);
const title = meta?.title ?? this.entry.content;
- lines.push(...renderWrappedText(innerWidth, title, palette.status.info));
+ lines.push(...renderWrappedText(innerWidth, `· ${title}`, palette.text.info));
for (const item of meta?.items ?? []) {
const value = item.value ? `: ${item.value}` : "";
- lines.push(...renderWrappedText(innerWidth, ` ${item.label}${value}`, palette.text.primary));
+ lines.push(
+ ...renderWrappedText(innerWidth, ` ${item.label}${value}`, palette.text.assistant),
+ );
if (item.description) {
lines.push(...renderWrappedText(innerWidth, ` ${item.description}`, palette.text.dim));
}
}
- return prefixedLines(lines, width, "· ", palette.text.dim);
+ return lines;
}
}
@@ -160,18 +153,22 @@ export class CompactMessageComponent implements Component {
: this.entry.content;
const prefix =
this.entry.kind === "assistant" || this.entry.kind === "thinking"
- ? "[a] "
+ ? ""
: this.entry.kind === "user"
? "> "
: this.entry.kind === "error"
? "! "
- : "- ";
+ : "· ";
const color =
this.entry.kind === "error"
? palette.status.error
: this.entry.kind === "assistant"
- ? palette.text.primary
- : palette.text.dim;
+ ? palette.text.assistant
+ : this.entry.kind === "user"
+ ? palette.text.user
+ : this.entry.kind === "thinking"
+ ? palette.text.thinking
+ : palette.text.dim;
return renderWrappedText(width, `${prefix}${content}`, color);
}
}
diff --git a/jiuwenclaw/cli/src/ui/components/todo-list.ts b/jiuwenclaw/cli/src/ui/components/todo-list.ts
index 1dfe9a1994..88a17b5763 100644
--- a/jiuwenclaw/cli/src/ui/components/todo-list.ts
+++ b/jiuwenclaw/cli/src/ui/components/todo-list.ts
@@ -8,18 +8,8 @@ function todoLabel(todo: TodoItem): string {
return `${prefix} ${todo.activeForm || todo.content}`;
}
-function todoDescription(todo: TodoItem): string {
- if (todo.status === "in_progress") {
- return "in progress";
- }
- if (todo.status === "completed") {
- return "completed";
- }
- return "pending";
-}
-
export function renderTodoList(todos: TodoItem[], width: number): string[] {
- if (todos.length === 0) {
+ if (todos.every((todo) => todo.status === "completed")) {
return [];
}
@@ -33,7 +23,6 @@ export function renderTodoList(todos: TodoItem[], width: number): string[] {
ordered.map((todo) => ({
value: todo.id,
label: todoLabel(todo),
- description: todoDescription(todo),
})),
Math.min(Math.max(ordered.length, 1), 8),
selectListTheme,
diff --git a/jiuwenclaw/cli/src/ui/components/tools/tool-group-message.ts b/jiuwenclaw/cli/src/ui/components/tools/tool-group-message.ts
index 92219089a1..57a6eb8564 100644
--- a/jiuwenclaw/cli/src/ui/components/tools/tool-group-message.ts
+++ b/jiuwenclaw/cli/src/ui/components/tools/tool-group-message.ts
@@ -1,12 +1,15 @@
import type { Component } from "@mariozechner/pi-tui";
import type { HistoryItem, ToolCallDisplay } from "../../../core/types.js";
import { palette } from "../../theme.js";
-import {
- prefixedLines,
- renderIndentedBlock,
- renderWrappedText,
- summarize,
-} from "../../rendering/text.js";
+import { prefixedLines, renderWrappedText, summarize } from "../../rendering/text.js";
+
+const TOOL_BODY_PREFIX = "│ ";
+const TOOL_BODY_CONTINUATION = "│ ";
+const TOOL_TAIL_PREFIX = "└ ";
+const TOOL_TAIL_CONTINUATION = " ";
+const TOOL_EXPAND_HINT = "ctrl+o to expand";
+const MAX_STRUCTURED_LINES_COLLAPSED = 6;
+const MAX_STRUCTURED_LINES_EXPANDED = 18;
function summarizePath(value: unknown): string | undefined {
if (typeof value !== "string") return undefined;
@@ -14,6 +17,232 @@ function summarizePath(value: unknown): string | undefined {
return parts.slice(-3).join("/");
}
+function normalizePythonLiteralToJson(value: string): string {
+ return value
+ .replace(/\bNone\b/g, "null")
+ .replace(/\bTrue\b/g, "true")
+ .replace(/\bFalse\b/g, "false")
+ .replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, (_match, content: string) => {
+ const normalized = content.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
+ return `"${normalized}"`;
+ });
+}
+
+function parseLiteralFragment(value: string): unknown {
+ const trimmed = value.trim();
+ if (!trimmed || trimmed === "None") {
+ return null;
+ }
+ try {
+ return JSON.parse(trimmed);
+ } catch {
+ // Fall through.
+ }
+ try {
+ return JSON.parse(normalizePythonLiteralToJson(trimmed));
+ } catch {
+ return trimmed;
+ }
+}
+
+function parseProtocolWrapper(value: string): unknown | undefined {
+ if (!value.includes("data=") && !value.includes("success=") && !value.includes("error=")) {
+ return undefined;
+ }
+
+ let working = value.trim();
+ let errorValue: unknown = undefined;
+ const errorIndex = working.lastIndexOf(" error=");
+ if (errorIndex >= 0) {
+ errorValue = parseLiteralFragment(working.slice(errorIndex + " error=".length));
+ working = working.slice(0, errorIndex);
+ }
+
+ let dataValue: unknown = undefined;
+ const dataIndex = working.indexOf(" data=");
+ if (dataIndex >= 0) {
+ dataValue = parseLiteralFragment(working.slice(dataIndex + " data=".length));
+ working = working.slice(0, dataIndex);
+ }
+
+ const successMatch = /\bsuccess=(True|False|true|false)\b/.exec(working);
+ const successValue =
+ successMatch?.[1] !== undefined ? successMatch[1].toLowerCase() === "true" : undefined;
+
+ if (isPlainObject(dataValue)) {
+ return {
+ ...dataValue,
+ ...(successValue !== undefined ? { success: successValue } : {}),
+ ...(errorValue !== undefined ? { error: errorValue } : {}),
+ };
+ }
+ if (Array.isArray(dataValue)) {
+ return {
+ items: dataValue,
+ count: dataValue.length,
+ ...(successValue !== undefined ? { success: successValue } : {}),
+ ...(errorValue !== undefined ? { error: errorValue } : {}),
+ };
+ }
+ if (dataValue !== undefined || successValue !== undefined || errorValue !== undefined) {
+ return {
+ ...(successValue !== undefined ? { success: successValue } : {}),
+ ...(errorValue !== undefined ? { error: errorValue } : {}),
+ ...(dataValue !== undefined ? { result: dataValue } : {}),
+ };
+ }
+ return undefined;
+}
+
+function tryParseStructuredText(value: string): unknown {
+ const trimmed = value.trim();
+ if (!trimmed) {
+ return value;
+ }
+ const wrapped = parseProtocolWrapper(trimmed);
+ if (wrapped !== undefined) {
+ return wrapped;
+ }
+ if (!["{", "["].includes(trimmed[0] ?? "")) {
+ return value;
+ }
+ try {
+ return JSON.parse(trimmed);
+ } catch {
+ try {
+ return JSON.parse(normalizePythonLiteralToJson(trimmed));
+ } catch {
+ return value;
+ }
+ }
+}
+
+function isPlainObject(value: unknown): value is Record<string, unknown> {
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
+}
+
+function isPrimitive(value: unknown): value is string | number | boolean | null {
+ return (
+ value === null ||
+ typeof value === "string" ||
+ typeof value === "number" ||
+ typeof value === "boolean"
+ );
+}
+
+function formatLeafValue(value: unknown): string {
+ if (value === null) return "null";
+ if (typeof value === "string") {
+ const compact = value.replace(/\s+/g, " ").trim();
+ return compact ? summarize(compact, 96) : '""';
+ }
+ if (typeof value === "number" || typeof value === "boolean") {
+ return String(value);
+ }
+ return summarize(JSON.stringify(value), 96);
+}
+
+function formatStructuredValue(
+ value: unknown,
+ maxLines: number,
+ maxDepth: number,
+): { lines: string[]; truncated: number } {
+ const output: string[] = [];
+
+ const append = (line: string): boolean => {
+ if (output.length >= maxLines) {
+ return false;
+ }
+ output.push(line);
+ return true;
+ };
+
+ const visit = (current: unknown, indent: string, label?: string, depth = 0): void => {
+ if (output.length >= maxLines) return;
+ const parsed = typeof current === "string" ? tryParseStructuredText(current) : current;
+
+ if (isPrimitive(parsed)) {
+ if (typeof parsed === "string" && parsed.includes("\n")) {
+ const compactLines = parsed
+ .split("\n")
+ .map((line) => line.trimEnd())
+ .filter((line) => line.length > 0);
+ if (label) {
+ if (!append(`${indent}${label}:`)) return;
+ }
+ const visible = compactLines.slice(0, Math.max(1, maxLines - output.length));
+ for (const line of visible) {
+ if (!append(`${indent} ${summarize(line, 96)}`)) return;
+ }
+ return;
+ }
+ append(`${indent}${label ? `${label}: ` : ""}${formatLeafValue(parsed)}`);
+ return;
+ }
+
+ if (depth >= maxDepth) {
+ append(`${indent}${label ? `${label}: ` : ""}${Array.isArray(parsed) ? "[…]" : "{…}"}`);
+ return;
+ }
+
+ if (Array.isArray(parsed)) {
+ if (label) {
+ if (!append(`${indent}${label}:`)) return;
+ }
+ if (parsed.length === 0) {
+ append(`${indent}${label ? " " : ""}[]`);
+ return;
+ }
+ const childIndent = indent + (label ? " " : "");
+ for (const item of parsed) {
+ if (output.length >= maxLines) return;
+ if (isPrimitive(item)) {
+ append(`${childIndent}- ${formatLeafValue(item)}`);
+ continue;
+ }
+ if (!append(`${childIndent}-`)) return;
+ visit(item, `${childIndent} `, undefined, depth + 1);
+ }
+ return;
+ }
+
+ if (isPlainObject(parsed)) {
+ const entries = Object.entries(parsed).filter(([, item]) => item !== undefined);
+ if (label) {
+ if (!append(`${indent}${label}:`)) return;
+ }
+ if (entries.length === 0) {
+ append(`${indent}${label ? " " : ""}{}`);
+ return;
+ }
+ const childIndent = indent + (label ? " " : "");
+ for (const [key, item] of entries) {
+ visit(item, childIndent, key, depth + 1);
+ if (output.length >= maxLines) return;
+ }
+ return;
+ }
+
+ append(`${indent}${label ? `${label}: ` : ""}${summarize(String(parsed), 96)}`);
+ };
+
+ visit(value, "");
+ const truncated = Math.max(0, output.length - maxLines);
+ return { lines: output.slice(0, maxLines), truncated };
+}
+
+function summarizeStructuredPayload(value: string): string | undefined {
+ const parsed = tryParseStructuredText(value);
+ if (Array.isArray(parsed)) {
+ return `${parsed.length} item${parsed.length === 1 ? "" : "s"}`;
+ }
+ if (isPlainObject(parsed)) {
+ const keys = Object.keys(parsed);
+ return `${keys.length} field${keys.length === 1 ? "" : "s"}`;
+ }
+ return undefined;
+}
+
function summarizeToolArguments(name: string, args: unknown): string | undefined {
if (!args || typeof args !== "object") {
return typeof args === "string" ? summarize(args, 72) : undefined;
@@ -48,7 +277,11 @@ function summarizeToolArguments(name: string, args: unknown): string | undefined
? summarize(obj.command, 72)
: undefined;
}
- return summarize(JSON.stringify(args), 72);
+ if (typeof obj.path === "string") {
+ return summarizePath(obj.path);
+ }
+ const keys = Object.keys(obj).filter((key) => obj[key] !== undefined);
+ return keys.length > 0 ? `${keys.length} field${keys.length === 1 ? "" : "s"}` : undefined;
}
export function summarizeToolResultByKind(name: string, result: string): string | undefined {
@@ -66,7 +299,7 @@ export function summarizeToolResultByKind(name: string, result: string): string
) {
return summarize(result.split("\n")[0] ?? "", 88);
}
- return undefined;
+ return summarizeStructuredPayload(result);
}
function countLogicalLines(text: string): number {
@@ -86,6 +319,26 @@ function getToolFilePath(args: Record<string, unknown>): string | undefined {
return typeof value === "string" && value ? (summarizePath(value) ?? value) : undefined;
}
+function getStringArg(args: Record<string, unknown>, ...keys: string[]): string | undefined {
+ for (const key of keys) {
+ const value = args[key];
+ if (typeof value === "string" && value.trim()) {
+ return value;
+ }
+ }
+ return undefined;
+}
+
+function getNumericArg(args: Record<string, unknown>, ...keys: string[]): number | undefined {
+ for (const key of keys) {
+ const value = args[key];
+ if (typeof value === "number" && Number.isFinite(value)) {
+ return value;
+ }
+ }
+ return undefined;
+}
+
function isReadTool(name: string): boolean {
const normalized = name.toLowerCase();
return normalized === "read" || normalized === "read_file";
@@ -106,6 +359,106 @@ function isEditTool(name: string): boolean {
return normalized === "edit" || normalized === "edit_file";
}
+function isRunTool(name: string): boolean {
+ const normalized = name.toLowerCase();
+ return (
+ normalized === "bash" ||
+ normalized === "shell" ||
+ normalized === "sh" ||
+ normalized === "powershell" ||
+ normalized === "command" ||
+ normalized === "exec" ||
+ normalized === "run"
+ );
+}
+
+function isGlobTool(name: string): boolean {
+ const normalized = name.toLowerCase();
+ return normalized === "glob" || normalized === "glob_files";
+}
+
+function isSearchTool(name: string): boolean {
+ const normalized = name.toLowerCase();
+ return (
+ normalized === "search" ||
+ normalized === "grep" ||
+ normalized === "rg" ||
+ normalized === "ripgrep" ||
+ normalized === "memory_search"
+ );
+}
+
+function isMcpTool(name: string): boolean {
+ const normalized = name.toLowerCase();
+ return normalized.startsWith("mcp_") || normalized.startsWith("mcp.");
+}
+
+function isToolRunning(tool: ToolCallDisplay): boolean {
+ return tool.status === "running" && !tool.result;
+}
+
+function toolPrefix(tool: ToolCallDisplay): string {
+ if (tool.isError || tool.status === "error") return "! ";
+ if (isToolRunning(tool)) return "◉ ";
+ return "● ";
+}
+
+function toolPrefixColor(tool: ToolCallDisplay): (value: string) => string {
+ if (tool.isError || tool.status === "error") return palette.status.error;
+ if (isToolRunning(tool)) return palette.text.tool;
+ return palette.status.success;
+}
+
+function toolLineColor(tool: ToolCallDisplay): (value: string) => string {
+ if (tool.isError || tool.status === "error") return palette.status.error;
+ if (isToolRunning(tool)) return palette.text.tool;
+ return palette.text.assistant;
+}
+
+function toolStateColor(tool: ToolCallDisplay): (value: string) => string {
+ if (tool.isError || tool.status === "error") return palette.status.error;
+ if (isToolRunning(tool)) return palette.text.tool;
+ return palette.status.success;
+}
+
+function renderToolTitle(width: number, tool: ToolCallDisplay, text: string): string[] {
+ return prefixedLines(
+ renderWrappedText(Math.max(1, width - 2), text, toolLineColor(tool)),
+ width,
+ toolPrefix(tool),
+ toolPrefixColor(tool),
+ " ",
+ );
+}
+
+function renderToolBranch(
+ width: number,
+ text: string,
+ colorFn: (value: string) => string,
+): string[] {
+ return prefixedLines(
+ renderWrappedText(Math.max(1, width - 2), text, colorFn),
+ width,
+ TOOL_BODY_PREFIX,
+ palette.text.subtle,
+ TOOL_BODY_CONTINUATION,
+ );
+}
+
+function renderToolBranchAnsi(width: number, text: string): string[] {
+ return renderToolBranch(width, text, (value) => value);
+}
+
+function renderToolTail(width: number, text: string, colorFn: (value: string) => string): string[] {
+ return prefixedLines(
+ renderWrappedText(Math.max(1, width - 2), text, colorFn),
+ width,
+ TOOL_TAIL_PREFIX,
+ palette.text.subtle,
+ TOOL_TAIL_CONTINUATION,
+ );
+}
+
function renderDiffRow(
width: number,
sign: " " | "+" | "-",
@@ -120,7 +473,7 @@ function renderSimpleDiff(width: number, beforeText: string, afterText: string):
const afterLines = afterText.split("\n");
const total = Math.max(beforeLines.length, afterLines.length);
const lines: string[] = [];
- for (let i = 0; i < total; i++) {
+ for (let i = 0; i < total; i += 1) {
const before = beforeLines[i];
const after = afterLines[i];
if (before === after && before !== undefined) {
@@ -163,6 +516,147 @@ function extractTrailingBracketNotices(text: string): { mainLines: string[]; not
};
}
+function toolDisplayName(tool: ToolCallDisplay): string {
+ const name = tool.name.toLowerCase();
+ if (name in { bash: true, shell: true, sh: true, powershell: true, command: true, exec: true }) {
+ return "Run";
+ }
+ if (name in { glob: true, glob_files: true }) {
+ return "Glob";
+ }
+ if (name.startsWith("mcp_")) {
+ return `Query ${name
+ .split("_")
+ .slice(1)
+ .filter(Boolean)
+ .map((part) => part[0]?.toUpperCase() + part.slice(1))
+ .join(" ")}`;
+ }
+ if (name.startsWith("mcp.")) {
+ return `Query ${name
+ .split(".")
+ .slice(1)
+ .filter(Boolean)
+ .map((part) => part[0]?.toUpperCase() + part.slice(1))
+ .join(" ")}`;
+ }
+ if (name in { read: true, read_file: true, read_memory: true, memory_get: true, view: true }) {
+ return "Read";
+ }
+ if (name in { ls: true, list_files: true }) {
+ return "List";
+ }
+ if (name === "memory_search") {
+ return "Search memories";
+ }
+ if (name in { write: true, write_file: true, write_memory: true }) {
+ return "Write";
+ }
+ if (name in { edit: true, edit_file: true, edit_memory: true }) {
+ return "Edit";
+ }
+ if (name === "session") {
+ return "Run session";
+ }
+ return tool.name
+ .split(/[_\-.]+/)
+ .filter(Boolean)
+ .map((part) => part[0]?.toUpperCase() + part.slice(1))
+ .join(" ");
+}
+
+function renderStructuredBranch(
+ width: number,
+ value: unknown,
+ showDetails: boolean,
+ colorFn: (value: string) => string,
+): string[] {
+ const maxLines = showDetails ? MAX_STRUCTURED_LINES_EXPANDED : MAX_STRUCTURED_LINES_COLLAPSED;
+ const { lines } = formatStructuredValue(value, maxLines, showDetails ? 4 : 2);
+ return lines.flatMap((line) => renderToolBranch(width, line, colorFn));
+}
+
+function renderSearchMatchBranch(width: number, line: string): string[] {
+ const trimmed = line.trim();
+ const match = /^(.+?):(\d+)(?::(\d+))?(?:(:|\s+-\s+|\s+)(.*))?$/.exec(trimmed);
+ if (!match) {
+ return renderToolBranch(width, line, palette.text.assistant);
+ }
+ const [, filePath, lineNumber, columnNumber, separatorRaw, remainderRaw] = match;
+ if (!filePath || (!filePath.includes("/") && !filePath.includes("."))) {
+ return renderToolBranch(width, line, palette.text.assistant);
+ }
+ const separator = separatorRaw ?? "";
+ const remainder = remainderRaw ?? "";
+ const location = `${filePath}:${lineNumber}${columnNumber ? `:${columnNumber}` : ""}`;
+ const formatted = `${palette.text.tool(filePath)}${palette.text.dim(`:${lineNumber}${columnNumber ? `:${columnNumber}` : ""}`)}${separator}${remainder ? palette.text.assistant(remainder) : ""}`;
+ return renderToolBranchAnsi(width, formatted || location);
+}
+
+function parseToolResultPayload(tool: ToolCallDisplay): Record<string, unknown> | undefined {
+ if (!tool.result) return undefined;
+ const parsed = tryParseStructuredText(tool.result);
+ return isPlainObject(parsed) ? parsed : undefined;
+}
+
+function parseToolResultValue(tool: ToolCallDisplay): unknown {
+ if (!tool.result) return undefined;
+ return tryParseStructuredText(tool.result);
+}
+
+function getStringList(payload: Record<string, unknown>, ...keys: string[]): string[] {
+ for (const key of keys) {
+ const value = payload[key];
+ if (Array.isArray(value)) {
+ const list = value.filter(
+ (item): item is string => typeof item === "string" && item.length > 0,
+ );
+ if (list.length > 0) {
+ return list;
+ }
+ }
+ }
+ return [];
+}
+
+function getStringListFromValue(value: unknown): string[] {
+ if (!Array.isArray(value)) {
+ return [];
+ }
+ return value.filter((item): item is string => typeof item === "string" && item.length > 0);
+}
+
+function nonEmptyLines(value: unknown): string[] {
+ if (typeof value !== "string") return [];
+ return value
+ .split("\n")
+ .map((line) => line.trimEnd())
+ .filter((line) => line.trim().length > 0);
+}
+
+function renderPreviewLines(
+ width: number,
+ lines: string[],
+ colorFn: (value: string) => string,
+ expandedLimit: number,
+ collapsedLimit: number,
+ showDetails: boolean,
+ noun: string,
+): string[] {
+ const limit = showDetails ? expandedLimit : collapsedLimit;
+ const shown = lines.slice(0, limit);
+ const rendered = shown.flatMap((line) => renderToolBranch(width, line, colorFn));
+ if (lines.length > shown.length) {
+ rendered.push(
+ ...renderToolBranch(width, `+ ${lines.length - shown.length} more ${noun}`, palette.text.dim),
+ );
+ }
+ if (!showDetails && lines.length > 0) {
+ rendered.push(...renderToolBranch(width, TOOL_EXPAND_HINT, palette.text.dim));
+ }
+ return rendered;
+}
+
export class ToolGroupMessageComponent implements Component {
constructor(
private readonly entry: Extract<HistoryItem, { kind: "tool_group" }>,
@@ -180,57 +674,37 @@ export class ToolGroupMessageComponent implements Component {
const description =
typeof args.description === "string" && args.description
? args.description
- : (tool.description ?? "会话任务");
+ : (tool.description ?? "session task");
const index = typeof args.index === "number" ? args.index : undefined;
const total = typeof args.total === "number" ? args.total : undefined;
- const status = tool.isError ? "error" : tool.status === "running" ? "running" : "completed";
-
- const lines: string[] = [];
- const headerParts = ["[session]"];
- if (index !== undefined && total !== undefined) {
- headerParts.push(`${index}/${total}`);
- }
- headerParts.push(status);
- headerParts.push(description);
- lines.push(
- ...renderWrappedText(
- width,
- headerParts.join(" | "),
- tool.isError ? palette.status.error : palette.status.info,
- ),
- );
+ const label =
+ index !== undefined && total !== undefined
+ ? `Run session ${index}/${total} · ${description}`
+ : `Run session · ${description}`;
+ const lines = renderToolTitle(width, tool, label);
if (tool.result) {
- if (!this.showDetails) {
- lines.push(
- ...renderWrappedText(
- width,
- ` ${tool.summary ?? summarize(tool.result, 120)}`,
- tool.isError ? palette.status.error : palette.text.dim,
- ),
- );
- lines.push(...renderIndentedBlock(width, "ctrl+g to expand", palette.text.dim));
- return lines;
- }
const previewLines = tool.result.split("\n").filter(Boolean);
- const shown = previewLines.slice(0, 6);
- for (const line of shown) {
- lines.push(
- ...renderWrappedText(
- width,
- ` ${line}`,
- tool.isError ? palette.status.error : palette.text.primary,
- ),
- );
- }
- if (previewLines.length > shown.length) {
- lines.push(
- ...renderWrappedText(
- width,
- ` ... ${previewLines.length - shown.length} more lines`,
- palette.text.dim,
- ),
- );
+ lines.push(
+ ...renderToolTail(
+ width,
+ tool.summary ??
+ summarizeToolResultByKind(tool.name, tool.result) ??
+ summarize(tool.result, 120),
+ toolStateColor(tool),
+ ),
+ );
+ if (this.showDetails) {
+ for (const line of previewLines.slice(0, 6)) {
+ lines.push(...renderToolBranch(width, line, palette.text.assistant));
+ }
+ if (previewLines.length > 6) {
+ lines.push(
+ ...renderToolBranch(width, `+ ${previewLines.length - 6} more lines`, palette.text.dim),
+ );
+ }
+ } else if (previewLines.length > 0) {
+ lines.push(...renderToolBranch(width, TOOL_EXPAND_HINT, palette.text.dim));
}
}
@@ -242,40 +716,54 @@ export class ToolGroupMessageComponent implements Component {
tool.arguments && typeof tool.arguments === "object"
? (tool.arguments as Record<string, unknown>)
: {};
- const path = getToolFilePath(args);
+ const payload = parseToolResultPayload(tool);
+ const path = getToolFilePath(args) ?? getStringArg(payload ?? {}, "path", "file_path", "file");
const offset = typeof args.offset === "number" ? args.offset : undefined;
const limit = typeof args.limit === "number" ? args.limit : undefined;
- const lines: string[] = [];
- const header = `[read] ${path ?? tool.description ?? tool.name}${offset !== undefined || limit !== undefined ? `:${offset ?? 1}${limit !== undefined ? `-${(offset ?? 1) + limit - 1}` : ""}` : ""}`;
- lines.push(...renderWrappedText(width, header, palette.text.secondary));
+ const rangeSuffix =
+ offset !== undefined || limit !== undefined
+ ? `:${offset ?? 1}${limit !== undefined ? `-${(offset ?? 1) + limit - 1}` : ""}`
+ : "";
+ const lines = renderToolTitle(
+ width,
+ tool,
+ `Read ${path ?? tool.description ?? tool.name}${rangeSuffix}`,
+ );
+
if (tool.result) {
- const { mainLines, notices } = extractTrailingBracketNotices(tool.result);
- const shown = mainLines.slice(0, this.showDetails ? 10 : 4);
+ const content = getStringArg(payload ?? {}, "content", "result", "data") ?? tool.result;
+ const { mainLines, notices } = extractTrailingBracketNotices(content);
+ const totalLines =
+ getNumericArg(payload ?? {}, "totalLines", "total_lines") ?? countLogicalLines(content);
+ const startLine = getNumericArg(payload ?? {}, "start_line", "startLine");
+ const endLine = getNumericArg(payload ?? {}, "end_line", "endLine");
+ const truncated = typeof payload?.truncated === "boolean" ? payload.truncated : undefined;
if (path) {
- const meta = `${countLogicalLines(tool.result)} lines${isCodeLikePath(path) ? " | code" : ""}`;
- lines.push(...renderIndentedBlock(width, meta, palette.text.dim));
+ const lineRange =
+ startLine !== undefined && endLine !== undefined ? ` · ${startLine}-${endLine}` : "";
+ const meta = `${totalLines} lines${lineRange}${isCodeLikePath(path) ? " · code" : ""}`;
+ lines.push(...renderToolBranch(width, meta, palette.text.dim));
}
if (this.showDetails) {
- for (const line of shown) {
- lines.push(...renderIndentedBlock(width, line, palette.text.primary));
+ for (const line of mainLines.slice(0, 10)) {
+ lines.push(...renderToolBranch(width, line, palette.text.assistant));
}
- if (mainLines.length > shown.length) {
+ if (mainLines.length > 10) {
lines.push(
- ...renderIndentedBlock(
- width,
- `... ${mainLines.length - shown.length} more lines`,
- palette.text.dim,
- ),
+ ...renderToolBranch(width, `+ ${mainLines.length - 10} more lines`, palette.text.dim),
);
}
} else {
- lines.push(...renderIndentedBlock(width, "content hidden", palette.text.dim));
- lines.push(...renderIndentedBlock(width, "ctrl+g to expand", palette.text.dim));
+ lines.push(...renderToolBranch(width, TOOL_EXPAND_HINT, palette.text.dim));
+ }
+ if (truncated) {
+ lines.push(...renderToolBranch(width, "result truncated", palette.status.warning));
}
for (const notice of notices) {
- lines.push(...renderIndentedBlock(width, notice, palette.status.warning));
+ lines.push(...renderToolBranch(width, notice, palette.status.warning));
}
}
+
return lines;
}
@@ -286,37 +774,47 @@ export class ToolGroupMessageComponent implements Component {
: {};
const path = getToolFilePath(args) ?? ".";
const limit = typeof args.limit === "number" ? args.limit : undefined;
- const lines: string[] = [];
- lines.push(
- ...renderWrappedText(
- width,
- `[list] ${path}${limit !== undefined ? ` (limit ${limit})` : ""}`,
- palette.text.secondary,
- ),
+ const lines = renderToolTitle(
+ width,
+ tool,
+ `List ${path}${limit !== undefined ? ` (limit ${limit})` : ""}`,
);
+
if (tool.result) {
+ const payload = parseToolResultPayload(tool);
+ const files = getStringList(payload ?? {}, "files");
+ const dirs = getStringList(payload ?? {}, "dirs").map((dir) => `${dir}/`);
+ const payloadEntries = [...files, ...dirs];
const { mainLines, notices } = extractTrailingBracketNotices(tool.result);
- const shown = mainLines.slice(0, this.showDetails ? 12 : 6);
- lines.push(...renderIndentedBlock(width, `${mainLines.length} entries`, palette.text.dim));
+ const visibleEntries = payloadEntries.length > 0 ? payloadEntries : mainLines;
+ const shown = visibleEntries.slice(0, this.showDetails ? 12 : 6);
+ lines.push(
+ ...renderToolTail(
+ width,
+ `${visibleEntries.length} entr${visibleEntries.length === 1 ? "y" : "ies"}`,
+ palette.text.dim,
+ ),
+ );
for (const entry of shown) {
- lines.push(...renderIndentedBlock(width, entry, palette.text.primary));
+ lines.push(...renderToolBranch(width, entry, palette.text.assistant));
}
- if (mainLines.length > shown.length) {
+ if (visibleEntries.length > shown.length) {
lines.push(
- ...renderIndentedBlock(
+ ...renderToolBranch(
width,
- `... ${mainLines.length - shown.length} more entries`,
+ `+ ${visibleEntries.length - shown.length} more entries`,
palette.text.dim,
),
);
}
- if (!this.showDetails && mainLines.length > 0) {
- lines.push(...renderIndentedBlock(width, "ctrl+g to expand", palette.text.dim));
+ if (!this.showDetails && visibleEntries.length > 0) {
+ lines.push(...renderToolBranch(width, TOOL_EXPAND_HINT, palette.text.dim));
}
for (const notice of notices) {
- lines.push(...renderIndentedBlock(width, notice, palette.status.warning));
+ lines.push(...renderToolBranch(width, notice, palette.status.warning));
}
}
+
return lines;
}
@@ -327,45 +825,43 @@ export class ToolGroupMessageComponent implements Component {
: {};
const path = getToolFilePath(args);
const content = typeof args.content === "string" ? args.content : "";
- const lines: string[] = [];
- lines.push(
- ...renderWrappedText(
- width,
- `[write] ${path ?? tool.description ?? tool.name}`,
- tool.isError ? palette.status.error : palette.text.secondary,
- ),
- );
+ const lines = renderToolTitle(width, tool, `Write ${path ?? tool.description ?? tool.name}`);
+
if (content) {
lines.push(
- ...renderIndentedBlock(
+ ...renderToolBranch(
width,
- `${countLogicalLines(content)} lines | ${content.length} chars`,
+ `${countLogicalLines(content)} lines · ${content.length} chars`,
palette.text.dim,
),
);
- const diffLines = renderAddedLines(width, content);
+ const diffLines = renderAddedLines(Math.max(1, width - 2), content);
const shown = this.showDetails ? diffLines : diffLines.slice(0, 6);
- lines.push(...shown);
+ lines.push(...shown.flatMap((line) => renderToolBranch(width, line, (value) => value)));
if (!this.showDetails && diffLines.length > shown.length) {
lines.push(
- ...renderIndentedBlock(
+ ...renderToolBranch(
width,
- `... ${diffLines.length - shown.length} more diff lines`,
+ `+ ${diffLines.length - shown.length} more diff lines`,
palette.text.dim,
),
);
- lines.push(...renderIndentedBlock(width, "ctrl+g to expand", palette.text.dim));
+ lines.push(...renderToolBranch(width, TOOL_EXPAND_HINT, palette.text.dim));
}
}
+
if (tool.result) {
lines.push(
- ...renderIndentedBlock(
+ ...renderToolTail(
width,
- tool.summary ?? summarize(tool.result, 120),
- tool.isError ? palette.status.error : palette.status.success,
+ tool.summary ??
+ summarizeToolResultByKind(tool.name, tool.result) ??
+ summarize(tool.result, 120),
+ toolStateColor(tool),
),
);
}
+
return lines;
}
@@ -375,14 +871,7 @@ export class ToolGroupMessageComponent implements Component {
? (tool.arguments as Record<string, unknown>)
: {};
const path = getToolFilePath(args);
- const lines: string[] = [];
- lines.push(
- ...renderWrappedText(
- width,
- `[edit] ${path ?? tool.description ?? tool.name}`,
- tool.isError ? palette.status.error : palette.text.secondary,
- ),
- );
+ const lines = renderToolTitle(width, tool, `Edit ${path ?? tool.description ?? tool.name}`);
const oldString =
typeof args.old_string === "string"
@@ -398,157 +887,493 @@ export class ToolGroupMessageComponent implements Component {
: undefined;
if (oldString !== undefined && newString !== undefined) {
- const diffLines = renderSimpleDiff(width, oldString, newString);
+ const diffLines = renderSimpleDiff(Math.max(1, width - 2), oldString, newString);
const shown = this.showDetails ? diffLines : diffLines.slice(0, 6);
- lines.push(...shown);
+ lines.push(...shown.flatMap((line) => renderToolBranch(width, line, (value) => value)));
if (!this.showDetails && diffLines.length > shown.length) {
lines.push(
- ...renderIndentedBlock(
+ ...renderToolBranch(
width,
- `... ${diffLines.length - shown.length} more diff lines`,
+ `+ ${diffLines.length - shown.length} more diff lines`,
palette.text.dim,
),
);
- lines.push(...renderIndentedBlock(width, "ctrl+g to expand", palette.text.dim));
+ lines.push(...renderToolBranch(width, TOOL_EXPAND_HINT, palette.text.dim));
}
} else if (Array.isArray(args.edits)) {
- lines.push(
- ...renderIndentedBlock(width, `${args.edits.length} edit block(s)`, palette.text.dim),
- );
+ lines.push(...renderToolTail(width, `${args.edits.length} edit block(s)`, palette.text.dim));
const shownEdits = args.edits.slice(0, this.showDetails ? 3 : 1);
for (const edit of shownEdits) {
- if (!edit || typeof edit !== "object") continue;
- const item = edit as Record<string, unknown>;
+ if (!isPlainObject(edit)) continue;
const before =
- typeof item.oldText === "string"
- ? item.oldText
- : typeof item.old_string === "string"
- ? item.old_string
+ typeof edit.oldText === "string"
+ ? edit.oldText
+ : typeof edit.old_string === "string"
+ ? edit.old_string
: "";
const after =
- typeof item.newText === "string"
- ? item.newText
- : typeof item.new_string === "string"
- ? item.new_string
+ typeof edit.newText === "string"
+ ? edit.newText
+ : typeof edit.new_string === "string"
+ ? edit.new_string
: "";
if (!before && !after) continue;
- const diffLines = renderSimpleDiff(width, before, after);
- lines.push(...diffLines.slice(0, this.showDetails ? 6 : 2));
+ const diffLines = renderSimpleDiff(Math.max(1, width - 2), before, after);
+ lines.push(
+ ...diffLines
+ .slice(0, this.showDetails ? 6 : 2)
+ .flatMap((line) => renderToolBranch(width, line, (value) => value)),
+ );
}
if (args.edits.length > shownEdits.length) {
lines.push(
- ...renderIndentedBlock(
+ ...renderToolBranch(
width,
- `... ${args.edits.length - shownEdits.length} more edit blocks`,
+ `+ ${args.edits.length - shownEdits.length} more edit blocks`,
palette.text.dim,
),
);
}
if (!this.showDetails && args.edits.length > 0) {
- lines.push(...renderIndentedBlock(width, "ctrl+g to expand", palette.text.dim));
+ lines.push(...renderToolBranch(width, TOOL_EXPAND_HINT, palette.text.dim));
}
}
if (tool.result) {
lines.push(
- ...renderIndentedBlock(
+ ...renderToolTail(
width,
- tool.summary ?? summarize(tool.result, 120),
- tool.isError ? palette.status.error : palette.status.success,
+ tool.summary ??
+ summarizeToolResultByKind(tool.name, tool.result) ??
+ summarize(tool.result, 120),
+ toolStateColor(tool),
),
);
}
+
return lines;
}
- render(width: number): string[] {
- const lines: string[] = [];
- const innerWidth = Math.max(1, width - 2);
- const tools = this.collapsed ? this.entry.tools.slice(-1) : this.entry.tools;
- for (const tool of tools) {
- if (tool.name === "session") {
- lines.push(
- ...prefixedLines(this.renderSessionTool(tool, innerWidth), width, "· ", palette.text.dim),
+ private renderRunTool(tool: ToolCallDisplay, width: number): string[] {
+ const args =
+ tool.arguments && typeof tool.arguments === "object"
+ ? (tool.arguments as Record<string, unknown>)
+ : {};
+ const payload = parseToolResultPayload(tool);
+ const command =
+ getStringArg(args, "command", "cmd", "script", "input") ??
+ getStringArg(payload ?? {}, "command", "cmd") ??
+ tool.description ??
+ tool.name;
+ const lines = renderToolTitle(width, tool, `Run ${summarize(command, 120)}`);
+
+ const cwd = getStringArg(args, "cwd", "path", "workdir");
+ if (cwd) {
+ lines.push(...renderToolBranch(width, `cwd: ${summarizePath(cwd) ?? cwd}`, palette.text.dim));
+ }
+
+ if (tool.result) {
+ const exitCode =
+ getNumericArg(payload ?? {}, "exit_code", "exitCode", "code") ??
+ getNumericArg(args, "exit_code", "exitCode", "code");
+ const stdoutLines =
+ nonEmptyLines(payload?.stdout) ||
+ nonEmptyLines(payload?.output) ||
+ nonEmptyLines(payload?.content) ||
+ nonEmptyLines(payload?.result);
+ const stderrLines = nonEmptyLines(payload?.stderr);
+
+ const summaryParts: string[] = [];
+ if (exitCode !== undefined) {
+ summaryParts.push(`exit ${exitCode}`);
+ }
+ if (stdoutLines.length > 0) {
+ summaryParts.push(`${stdoutLines.length} line${stdoutLines.length === 1 ? "" : "s"}`);
+ } else if (stderrLines.length > 0) {
+ summaryParts.push(
+ `${stderrLines.length} stderr line${stderrLines.length === 1 ? "" : "s"}`,
);
- continue;
}
- if (isReadTool(tool.name)) {
+
+ lines.push(
+ ...renderToolTail(
+ width,
+ tool.summary ?? (summaryParts.join(" | ") || summarize(tool.result, 120)),
+ toolStateColor(tool),
+ ),
+ );
+
+ if (stdoutLines.length > 0 || stderrLines.length > 0) {
lines.push(
- ...prefixedLines(this.renderReadTool(tool, innerWidth), width, "· ", palette.text.dim),
+ ...renderPreviewLines(
+ width,
+ stdoutLines,
+ palette.text.assistant,
+ 8,
+ 4,
+ this.showDetails,
+ "lines",
+ ),
);
- continue;
- }
- if (isListTool(tool.name)) {
lines.push(
- ...prefixedLines(this.renderListTool(tool, innerWidth), width, "· ", palette.text.dim),
+ ...renderPreviewLines(
+ width,
+ stderrLines,
+ palette.status.warning,
+ 8,
+ 2,
+ this.showDetails,
+ "stderr lines",
+ ),
);
- continue;
- }
- if (isWriteTool(tool.name)) {
+ } else if (payload && this.showDetails) {
lines.push(
- ...prefixedLines(this.renderWriteTool(tool, innerWidth), width, "· ", palette.text.dim),
+ ...renderStructuredBranch(
+ width,
+ payload,
+ this.showDetails,
+ tool.isError ? palette.status.error : palette.text.assistant,
+ ),
);
- continue;
- }
- if (isEditTool(tool.name)) {
+ } else if (!payload && this.showDetails) {
lines.push(
- ...prefixedLines(this.renderEditTool(tool, innerWidth), width, "· ", palette.text.dim),
+ ...renderPreviewLines(
+ width,
+ nonEmptyLines(tool.result),
+ tool.isError ? palette.status.error : palette.text.assistant,
+ 8,
+ 4,
+ this.showDetails,
+ "lines",
+ ),
);
- continue;
}
- const status = tool.status === "running" ? "[run]" : tool.isError ? "[err]" : "[ok]";
- const detail = tool.description ?? summarizeToolArguments(tool.name, tool.arguments);
+ }
+
+ return lines;
+ }
+
+ private renderGlobTool(tool: ToolCallDisplay, width: number): string[] {
+ const args =
+ tool.arguments && typeof tool.arguments === "object"
+ ? (tool.arguments as Record<string, unknown>)
+ : {};
+ const payload = parseToolResultPayload(tool);
+ const parsedValue = parseToolResultValue(tool);
+ const pattern =
+ getStringArg(args, "glob", "pattern", "path", "file_path") ??
+ getStringArg(payload ?? {}, "glob", "pattern") ??
+ tool.description ??
+ tool.name;
+ const lines = renderToolTitle(width, tool, `Glob ${summarize(pattern, 120)}`);
+ const root = getStringArg(args, "root", "cwd", "dir_path");
+ if (root) {
lines.push(
- ...prefixedLines(
- renderWrappedText(
- innerWidth,
- `${status} ${tool.name}${detail ? ` - ${detail}` : ""}`,
- tool.isError ? palette.status.error : palette.text.secondary,
+ ...renderToolBranch(width, `root: ${summarizePath(root) ?? root}`, palette.text.dim),
+ );
+ }
+
+ if (tool.result) {
+ const payloadMatchLines = getStringList(payload ?? {}, "matching_files", "files");
+ const valueMatchLines = getStringListFromValue(parsedValue);
+ const matchLines = payloadMatchLines.length > 0 ? payloadMatchLines : valueMatchLines;
+ const count = getNumericArg(payload ?? {}, "count") ?? matchLines.length;
+ lines.push(
+ ...renderToolTail(
+ width,
+ tool.summary ?? `${count} file${count === 1 ? "" : "s"}`,
+ toolStateColor(tool),
+ ),
+ );
+ if (matchLines.length > 0) {
+ lines.push(
+ ...renderPreviewLines(
+ width,
+ matchLines,
+ palette.text.assistant,
+ 8,
+ 4,
+ this.showDetails,
+ "files",
),
+ );
+ } else if (payload && this.showDetails) {
+ lines.push(
+ ...renderStructuredBranch(width, payload, this.showDetails, palette.text.assistant),
+ );
+ } else if (parsedValue !== undefined && this.showDetails) {
+ lines.push(
+ ...renderStructuredBranch(width, parsedValue, this.showDetails, palette.text.assistant),
+ );
+ }
+ }
+
+ return lines;
+ }
+
+ private renderSearchTool(tool: ToolCallDisplay, width: number): string[] {
+ const args =
+ tool.arguments && typeof tool.arguments === "object"
+ ? (tool.arguments as Record<string, unknown>)
+ : {};
+ const payload = parseToolResultPayload(tool);
+ const parsedValue = parseToolResultValue(tool);
+ const query =
+ getStringArg(args, "pattern", "query", "q", "prompt", "glob") ??
+ getStringArg(payload ?? {}, "pattern", "query", "q") ??
+ tool.description ??
+ tool.name;
+ const root =
+ getStringArg(args, "path", "cwd", "root", "dir_path") ??
+ getStringArg(payload ?? {}, "path", "cwd", "root");
+ const title = root
+ ? `Search ${summarize(query, 96)} in ${summarizePath(root) ?? root}`
+ : `Search ${summarize(query, 120)}`;
+ const lines = renderToolTitle(width, tool, title);
+
+ if (tool.result) {
+ const payloadResultLines = getStringList(
+ payload ?? {},
+ "matches",
+ "results",
+ "items",
+ "hits",
+ "files",
+ );
+ const valueResultLines = getStringListFromValue(parsedValue);
+ const resultLines = payloadResultLines.length > 0 ? payloadResultLines : valueResultLines;
+ const fallbackLines = nonEmptyLines(tool.result);
+ const visibleLines = resultLines.length > 0 ? resultLines : fallbackLines;
+ const count =
+ getNumericArg(payload ?? {}, "count", "match_count", "matches_count", "total") ??
+ visibleLines.length;
+ lines.push(
+ ...renderToolTail(
width,
- "· ",
- palette.text.dim,
+ tool.summary ?? `${count} match${count === 1 ? "" : "es"}`,
+ toolStateColor(tool),
),
);
- if (!this.collapsed && tool.result) {
- const summary =
+ if (visibleLines.length > 0) {
+ const limit = this.showDetails ? 8 : 4;
+ const shown = visibleLines.slice(0, limit);
+ for (const line of shown) {
+ lines.push(
+ ...(tool.isError
+ ? renderToolBranch(width, line, palette.status.error)
+ : renderSearchMatchBranch(width, line)),
+ );
+ }
+ if (visibleLines.length > shown.length) {
+ lines.push(
+ ...renderToolBranch(
+ width,
+ `+ ${visibleLines.length - shown.length} more matches`,
+ palette.text.dim,
+ ),
+ );
+ }
+ if (!this.showDetails && visibleLines.length > 0) {
+ lines.push(...renderToolBranch(width, TOOL_EXPAND_HINT, palette.text.dim));
+ }
+ } else if (payload && this.showDetails) {
+ lines.push(
+ ...renderStructuredBranch(
+ width,
+ payload,
+ this.showDetails,
+ tool.isError ? palette.status.error : palette.text.assistant,
+ ),
+ );
+ } else if (parsedValue !== undefined && this.showDetails) {
+ lines.push(
+ ...renderStructuredBranch(
+ width,
+ parsedValue,
+ this.showDetails,
+ tool.isError ? palette.status.error : palette.text.assistant,
+ ),
+ );
+ }
+ }
+
+ return lines;
+ }
+
+ private renderMcpTool(tool: ToolCallDisplay, width: number): string[] {
+ const args =
+ tool.arguments && typeof tool.arguments === "object"
+ ? (tool.arguments as Record<string, unknown>)
+ : {};
+ const title = toolDisplayName(tool);
+ const detail =
+ getStringArg(args, "query", "q", "prompt", "url", "path", "file_path", "file") ??
+ tool.description ??
+ summarizeToolArguments(tool.name, args);
+ const lines = renderToolTitle(
+ width,
+ tool,
+ `${title}${detail ? ` · ${summarize(detail, 120)}` : ""}`,
+ );
+
+ if (isPlainObject(tool.arguments)) {
+ lines.push(
+ ...renderStructuredBranch(width, tool.arguments, this.showDetails, palette.text.dim),
+ );
+ }
+
+ if (tool.result) {
+ const payload = parseToolResultPayload(tool);
+ const parsedValue = parseToolResultValue(tool);
+ lines.push(
+ ...renderToolTail(
+ width,
tool.summary ??
- summarizeToolResultByKind(tool.name, tool.result) ??
- summarize(tool.result, 120);
+ summarizeToolResultByKind(tool.name, tool.result) ??
+ summarize(tool.result, 120),
+ toolStateColor(tool),
+ ),
+ );
+ if (payload) {
lines.push(
- ...prefixedLines(
- renderWrappedText(
- innerWidth,
- ` ${summary}`,
- tool.isError ? palette.status.error : palette.text.dim,
- ),
+ ...renderStructuredBranch(
+ width,
+ payload,
+ this.showDetails,
+ tool.isError ? palette.status.error : palette.text.assistant,
+ ),
+ );
+ } else if (parsedValue !== undefined && this.showDetails) {
+ lines.push(
+ ...renderStructuredBranch(
+ width,
+ parsedValue,
+ this.showDetails,
+ tool.isError ? palette.status.error : palette.text.assistant,
+ ),
+ );
+ } else if (this.showDetails) {
+ lines.push(
+ ...renderPreviewLines(
+ width,
+ nonEmptyLines(tool.result),
+ tool.isError ? palette.status.error : palette.text.assistant,
+ 8,
+ 4,
+ this.showDetails,
+ "lines",
+ ),
+ );
+ }
+ }
+
+ return lines;
+ }
+
+ private renderGenericTool(tool: ToolCallDisplay, width: number): string[] {
+ const title = toolDisplayName(tool);
+ const detail = tool.description ?? summarizeToolArguments(tool.name, tool.arguments);
+ const separator = title.startsWith("Query ") ? " · " : " ";
+ const lines = renderToolTitle(width, tool, `${title}${detail ? `${separator}${detail}` : ""}`);
+
+ if (isPlainObject(tool.arguments)) {
+ const structuredArgs = renderStructuredBranch(
+ width,
+ tool.arguments,
+ this.showDetails,
+ palette.text.dim,
+ );
+ lines.push(...structuredArgs);
+ }
+
+ if (tool.result) {
+ const summary =
+ tool.summary ??
+ summarizeToolResultByKind(tool.name, tool.result) ??
+ summarize(tool.result, 120);
+ lines.push(...renderToolTail(width, summary, toolStateColor(tool)));
+
+ const parsedResult = tryParseStructuredText(tool.result);
+ if (parsedResult !== tool.result) {
+ lines.push(
+ ...renderStructuredBranch(
width,
- " ",
- (value) => value,
+ parsedResult,
+ this.showDetails,
+ tool.isError ? palette.status.error : palette.text.assistant,
),
);
- if (this.showDetails) {
- const preview = tool.result
- .split("\n")
- .slice(0, tool.isError ? 2 : 4)
- .join("\n");
- for (const line of preview.split("\n").filter(Boolean)) {
- lines.push(
- ...prefixedLines(
- renderWrappedText(
- innerWidth,
- ` ${line}`,
- tool.isError ? palette.status.error : palette.text.primary,
- ),
- width,
- " ",
- (value) => value,
- ),
- );
- }
+ } else if (this.showDetails) {
+ const previewLines = tool.result.split("\n").filter(Boolean);
+ const shown = previewLines.slice(0, tool.isError ? 2 : 4);
+ for (const line of shown) {
+ lines.push(
+ ...renderToolBranch(
+ width,
+ line,
+ tool.isError ? palette.status.error : palette.text.assistant,
+ ),
+ );
+ }
+ if (previewLines.length > shown.length) {
+ lines.push(
+ ...renderToolBranch(
+ width,
+ `+ ${previewLines.length - shown.length} more lines`,
+ palette.text.dim,
+ ),
+ );
}
}
}
+
+ return lines;
+ }
+
+ render(width: number): string[] {
+ const lines: string[] = [];
+ const tools = this.collapsed ? this.entry.tools.slice(-1) : this.entry.tools;
+
+ for (const tool of tools) {
+ if (tool.name === "session") {
+ lines.push(...this.renderSessionTool(tool, width));
+ continue;
+ }
+ if (isReadTool(tool.name)) {
+ lines.push(...this.renderReadTool(tool, width));
+ continue;
+ }
+ if (isListTool(tool.name)) {
+ lines.push(...this.renderListTool(tool, width));
+ continue;
+ }
+ if (isWriteTool(tool.name)) {
+ lines.push(...this.renderWriteTool(tool, width));
+ continue;
+ }
+ if (isEditTool(tool.name)) {
+ lines.push(...this.renderEditTool(tool, width));
+ continue;
+ }
+ if (isRunTool(tool.name)) {
+ lines.push(...this.renderRunTool(tool, width));
+ continue;
+ }
+ if (isGlobTool(tool.name)) {
+ lines.push(...this.renderGlobTool(tool, width));
+ continue;
+ }
+ if (isSearchTool(tool.name)) {
+ lines.push(...this.renderSearchTool(tool, width));
+ continue;
+ }
+ if (isMcpTool(tool.name)) {
+ lines.push(...this.renderMcpTool(tool, width));
+ continue;
+ }
+ lines.push(...this.renderGenericTool(tool, width));
+ }
+
return lines;
}
}
diff --git a/jiuwenclaw/cli/src/ui/rendering/text.ts b/jiuwenclaw/cli/src/ui/rendering/text.ts
index 0e07a6b6e3..3b6f72abda 100644
--- a/jiuwenclaw/cli/src/ui/rendering/text.ts
+++ b/jiuwenclaw/cli/src/ui/rendering/text.ts
@@ -28,11 +28,14 @@ export function prefixedLines(
width: number,
prefix: string,
prefixFn: (value: string) => string,
+ continuationPrefix?: string,
): string[] {
- const bodyWidth = Math.max(1, width - prefix.length);
- const prefixPad = " ".repeat(prefix.length);
+ const activeContinuationPrefix =
+ continuationPrefix === undefined ? " ".repeat(prefix.length) : continuationPrefix;
+ const bodyWidth = Math.max(1, width - Math.max(prefix.length, activeContinuationPrefix.length));
return lines.map(
- (line, index) => prefixFn(index === 0 ? prefix : prefixPad) + padToWidth(line, bodyWidth),
+ (line, index) =>
+ prefixFn(index === 0 ? prefix : activeContinuationPrefix) + padToWidth(line, bodyWidth),
);
}
diff --git a/jiuwenclaw/cli/src/ui/screen-layout.ts b/jiuwenclaw/cli/src/ui/screen-layout.ts
index b36d5ac027..849e3225f8 100644
--- a/jiuwenclaw/cli/src/ui/screen-layout.ts
+++ b/jiuwenclaw/cli/src/ui/screen-layout.ts
@@ -1,4 +1,5 @@
import type { AppSnapshot } from "../app-state.js";
+import type { HistoryItem, ToolCallDisplay } from "../core/types.js";
import { renderHistoryEntry } from "./components/messages/index.js";
import { renderTodoList } from "./components/todo-list.js";
import { APP_SCREEN_KEY_BINDINGS } from "./keymap.js";
@@ -8,7 +9,6 @@ import { buildWelcomeLines } from "./welcome.js";
export interface ScreenLayoutOptions {
width: number;
- terminalRows: number;
questionLines: string[];
editorLines: string[];
showFullThinking: boolean;
@@ -72,17 +72,6 @@ function buildStatusLines(
} else if (snapshot.evolutionStatus === "running") {
lines.push(padToWidth(palette.text.dim("evolution | running"), width));
}
- if (snapshot.contextCompression) {
- const { beforeCompressed, afterCompressed, rate } = snapshot.contextCompression;
- const parts = ["context"];
- if (beforeCompressed !== null && afterCompressed !== null) {
- parts.push(`${beforeCompressed} -> ${afterCompressed}`);
- }
- if (rate) {
- parts.push(`${rate.toFixed(1)}%`);
- }
- lines.push(padToWidth(palette.text.dim(parts.join(" | ")), width));
- }
return lines;
}
@@ -98,6 +87,22 @@ function buildShortcutLines(width: number): string[] {
return lines;
}
+function isTodoTool(tool: ToolCallDisplay): boolean {
+ const normalized = tool.name.trim().toLowerCase();
+ return normalized === "todo" || normalized.startsWith("todo_");
+}
+
+function filterTodoToolEntry(entry: HistoryItem): HistoryItem | null {
+ if (entry.kind !== "tool_group") {
+ return entry;
+ }
+ const tools = entry.tools.filter((tool) => !isTodoTool(tool));
+ if (tools.length === 0) {
+ return null;
+ }
+ return tools.length === entry.tools.length ? entry : { ...entry, tools };
+}
+
function buildTranscriptLines(
snapshot: AppSnapshot,
width: number,
@@ -129,6 +134,10 @@ function buildTranscriptLines(
);
}
+ displayEntries = displayEntries
+ .map((entry) => filterTodoToolEntry(entry))
+ .filter((entry): entry is HistoryItem => entry !== null);
+
const allLines: string[] = [];
if (displayEntries.length === 0) {
allLines.push(...buildWelcomeLines(width));
@@ -159,7 +168,6 @@ export function buildAppScreenLines(snapshot: AppSnapshot, options: ScreenLayout
options.showToolDetails,
);
const todoLines = renderTodoList(snapshot.todos, options.width);
-
return [
...transcriptLines,
...todoLines,
diff --git a/jiuwenclaw/cli/src/ui/theme.ts b/jiuwenclaw/cli/src/ui/theme.ts
index c6b8bd9cd2..c0afd49b22 100644
--- a/jiuwenclaw/cli/src/ui/theme.ts
+++ b/jiuwenclaw/cli/src/ui/theme.ts
@@ -21,7 +21,14 @@ type ThemeDefinition = {
textPrimary: string;
textSecondary: string;
textDim: string;
+ textSubtle: string;
textAccent: string;
+ textUser: string;
+ textAssistant: string;
+ textThinking: string;
+ textSystem: string;
+ textInfo: string;
+ textTool: string;
statusSuccess: string;
statusError: string;
statusWarning: string;
@@ -43,50 +50,64 @@ type ThemeDefinition = {
const THEME_DEFINITIONS: Record<"light" | "dark", ThemeDefinition> = {
light: {
- textPrimary: "#1f2937",
- textSecondary: "#0f766e",
- textDim: "#6b7280",
- textAccent: "#2563eb",
- statusSuccess: "#15803d",
- statusError: "#dc2626",
- statusWarning: "#ca8a04",
- statusInfo: "#0891b2",
- borderPanel: "#94a3b8",
- borderQuestion: "#d97706",
- surfaceUserBg: "#e8e8e8",
- surfaceUserFg: "#111827",
- markdownHeading: "#0f766e",
- markdownCode: "#a16207",
- markdownCodeBlock: "#111827",
- diffAddBg: "#dcfce7",
- diffAddFg: "#14532d",
- diffRemoveBg: "#fee2e2",
- diffRemoveFg: "#7f1d1d",
- diffContextBg: "#f3f4f6",
- diffContextFg: "#6b7280",
+ textPrimary: "#000000",
+ textSecondary: "#d77757",
+ textDim: "#666666",
+ textSubtle: "#afafaf",
+ textAccent: "#5769f7",
+ textUser: "#2563eb",
+ textAssistant: "#000000",
+ textThinking: "#966c1e",
+ textSystem: "#666666",
+ textInfo: "#5769f7",
+ textTool: "#5769f7",
+ statusSuccess: "#2c7a39",
+ statusError: "#ab2b3f",
+ statusWarning: "#966c1e",
+ statusInfo: "#5769f7",
+ borderPanel: "#999999",
+ borderQuestion: "#966c1e",
+ surfaceUserBg: "#f0f0f0",
+ surfaceUserFg: "#000000",
+ markdownHeading: "#d77757",
+ markdownCode: "#5769f7",
+ markdownCodeBlock: "#000000",
+ diffAddBg: "#c7e1cb",
+ diffAddFg: "#2f9d44",
+ diffRemoveBg: "#fdd2d8",
+ diffRemoveFg: "#d1454b",
+ diffContextBg: "#f0f0f0",
+ diffContextFg: "#666666",
},
dark: {
- textPrimary: "#e5e7eb",
- textSecondary: "#67e8f9",
- textDim: "#94a3b8",
- textAccent: "#60a5fa",
- statusSuccess: "#4ade80",
- statusError: "#f87171",
- statusWarning: "#fbbf24",
- statusInfo: "#22d3ee",
- borderPanel: "#475569",
- borderQuestion: "#f59e0b",
- surfaceUserBg: "#1f2937",
- surfaceUserFg: "#f9fafb",
- markdownHeading: "#67e8f9",
- markdownCode: "#fbbf24",
- markdownCodeBlock: "#f3f4f6",
- diffAddBg: "#14532d",
- diffAddFg: "#dcfce7",
- diffRemoveBg: "#7f1d1d",
- diffRemoveFg: "#fee2e2",
- diffContextBg: "#1f2937",
- diffContextFg: "#94a3b8",
+ textPrimary: "#ffffff",
+ textSecondary: "#d77757",
+ textDim: "#999999",
+ textSubtle: "#505050",
+ textAccent: "#b1b9f9",
+ textUser: "#7ab4e8",
+ textAssistant: "#ffffff",
+ textThinking: "#ffc107",
+ textSystem: "#999999",
+ textInfo: "#b1b9f9",
+ textTool: "#b1b9f9",
+ statusSuccess: "#4eba65",
+ statusError: "#ff6b80",
+ statusWarning: "#ffc107",
+ statusInfo: "#b1b9f9",
+ borderPanel: "#888888",
+ borderQuestion: "#ffc107",
+ surfaceUserBg: "#373737",
+ surfaceUserFg: "#ffffff",
+ markdownHeading: "#d77757",
+ markdownCode: "#b1b9f9",
+ markdownCodeBlock: "#ffffff",
+ diffAddBg: "#47584a",
+ diffAddFg: "#38a660",
+ diffRemoveBg: "#69484d",
+ diffRemoveFg: "#b3596b",
+ diffContextBg: "#373737",
+ diffContextFg: "#999999",
},
};
@@ -161,6 +182,13 @@ export const palette = {
secondary: (value: string) => chalk.hex(getThemeDefinition().textSecondary)(value),
accent: (value: string) => chalk.hex(getAccentHex())(value),
dim: (value: string) => chalk.hex(getThemeDefinition().textDim)(value),
+ subtle: (value: string) => chalk.hex(getThemeDefinition().textSubtle)(value),
+ user: (value: string) => chalk.hex(getThemeDefinition().textUser)(value),
+ assistant: (value: string) => chalk.hex(getThemeDefinition().textAssistant)(value),
+ thinking: (value: string) => chalk.hex(getThemeDefinition().textThinking)(value),
+ system: (value: string) => chalk.hex(getThemeDefinition().textSystem)(value),
+ info: (value: string) => chalk.hex(getThemeDefinition().textInfo)(value),
+ tool: (value: string) => chalk.hex(getThemeDefinition().textTool)(value),
},
surface: {
user: (value: string) =>