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

fix: Style TUI todo statuses

chensheng1234582a17d3d3228
diff --git a/jiuwenswarm/channels/tui/frontend/src/app-state.ts b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
index d74a31d109..14d3cfb068 100644
--- a/jiuwenswarm/channels/tui/frontend/src/app-state.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
@@ -2281,9 +2281,17 @@ export class CliPiAppState {
) {
return null;
}
- if (status === "in_progress" || status === "completed" || status === "pending") {
+ if (
+ status === "in_progress" ||
+ status === "completed" ||
+ status === "pending" ||
+ status === "error"
+ ) {
return status;
}
+ if (status === "failed") {
+ return "error";
+ }
return undefined;
}
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts b/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts
index 6470e12733..3ef2ef9b87 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts
@@ -907,9 +907,12 @@ function normalizeTodoStatus(status: unknown): TodoItem["status"] | null {
if (status === "deleted" || status === "cancelled" || status === "canceled") {
return null;
}
- if (status === "in_progress" || status === "completed") {
+ if (status === "in_progress" || status === "completed" || status === "error") {
return status;
}
+ if (status === "failed") {
+ return "error";
+ }
return "pending";
}
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/types.ts b/jiuwenswarm/channels/tui/frontend/src/core/types.ts
index 837c5fccb4..d32f6825ff 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/types.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/types.ts
@@ -88,7 +88,7 @@ export interface ContextCompressionStats {
trigger?: "manual" | "auto";
}
-export type TodoStatus = "pending" | "in_progress" | "completed";
+export type TodoStatus = "pending" | "in_progress" | "completed" | "error";
export interface TodoItem {
id: string;
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/components/todo-list.ts b/jiuwenswarm/channels/tui/frontend/src/ui/components/todo-list.ts
index ada12e3ccc..eb8c8e0d59 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/components/todo-list.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/components/todo-list.ts
@@ -1,7 +1,6 @@
-import { SelectList } from "@mariozechner/pi-tui";
import type { TodoItem } from "../../core/types.js";
import { padToWidth } from "../rendering/text.js";
-import { palette, selectListTheme } from "../theme.js";
+import { chalk, palette } from "../theme.js";
function normalizeTodoText(text: string): string {
const trimmed = text.trim();
@@ -27,8 +26,20 @@ function normalizeTodoText(text: string): string {
function todoLabel(todo: TodoItem, animationPhase: number = 0): string {
const spinner = ["◐", "◓", "◑", "◒"][animationPhase % 4]!;
- const prefix = todo.status === "in_progress" ? spinner : todo.status === "completed" ? "✓" : "○";
- return `${prefix} ${normalizeTodoText(todo.activeForm || todo.content)}`;
+ const text = normalizeTodoText(todo.activeForm || todo.content);
+ if (todo.status === "completed") {
+ return `${palette.status.success("✓")} ${chalk.strikethrough(palette.text.dim(text))}`;
+ }
+ if (todo.status === "error") {
+ return `${palette.status.error("✗")} ${text}`;
+ }
+ const prefix = todo.status === "in_progress" ? spinner : "○";
+ return `${prefix} ${text}`;
+}
+
+function todoLine(todo: TodoItem, index: number, width: number, animationPhase: number): string {
+ const prefix = index === 0 ? palette.text.accent("→ ") : " ";
+ return padToWidth(prefix + todoLabel(todo, animationPhase), width);
}
export function renderTodoList(
@@ -41,16 +52,14 @@ export function renderTodoList(
return [];
}
- if (todos.every((todo) => todo.status === "completed")) {
- return [];
- }
-
const pendingCount = todos.filter((t) => t.status === "pending").length;
const inProgressCount = todos.filter((t) => t.status === "in_progress").length;
const completedCount = todos.filter((t) => t.status === "completed").length;
+ const errorCount = todos.filter((t) => t.status === "error").length;
const statusText = [
inProgressCount > 0 ? `${inProgressCount} in progress` : "",
+ errorCount > 0 ? `${errorCount} error` : "",
pendingCount > 0 ? `${pendingCount} pending` : "",
completedCount > 0 ? `${completedCount} completed` : "",
]
@@ -67,18 +76,16 @@ export function renderTodoList(
const ordered = [
...todos.filter((todo) => todo.status === "in_progress"),
+ ...todos.filter((todo) => todo.status === "error"),
...todos.filter((todo) => todo.status === "pending"),
...todos.filter((todo) => todo.status === "completed"),
];
- const list = new SelectList(
- ordered.map((todo) => ({
- value: todo.id,
- label: todoLabel(todo, animationPhase),
- })),
- Math.min(Math.max(ordered.length, 1), 8),
- selectListTheme,
- );
+ const visibleTodos = ordered.slice(0, 8);
+ const todoLines = visibleTodos.map((todo, index) => todoLine(todo, index, width, animationPhase));
+ if (ordered.length > visibleTodos.length) {
+ todoLines.push(padToWidth(palette.text.dim(` (1-${visibleTodos.length}/${ordered.length})`), width));
+ }
- return [padToWidth(headerLine, width), ...list.render(width), " ".repeat(width)];
+ return [padToWidth(headerLine, width), ...todoLines, " ".repeat(width)];
}