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(TUI): Support English TUI status text
chensheng12345dcd24799c955
diff --git a/jiuwenswarm/channels/tui/frontend/src/app-state.ts b/jiuwenswarm/channels/tui/frontend/src/app-state.tsindex c9158e2b0a..74658220dd 100644--- a/jiuwenswarm/channels/tui/frontend/src/app-state.ts+++ b/jiuwenswarm/channels/tui/frontend/src/app-state.ts@@ -1,5 +1,5 @@import { addError, addInfo } from "./core/commands/helpers.js";-import type { CommandContext } from "./core/commands/types.js";+import type { CommandContext, PreferredLanguage } from "./core/commands/types.js";import {computeTimeoutAt,isIgnorableHistoryRestoreError,@@ -119,6 +119,7 @@ export interface AppSnapshot {contextWindowLimit: number | null;contextUsedPercentage: number | null;modelInfo: { provider: string; model: string; version: string };+ preferredLanguage: PreferredLanguage;sessionTitle: string;statusLineText: string | null;memoryWarnings: {@@ -140,6 +141,10 @@ function formatElapsed(ms: number): string {return minutes > 0 ? `${minutes}m ${seconds}s` : `${seconds}s`;}+function normalizePreferredLanguage(value: unknown): PreferredLanguage {+ return typeof value === "string" && value.trim().toLowerCase() === "en" ? "en" : "zh";+}+const LOCAL_FILE_SEARCH_TOOL_NAMES = new Set(["grep","rg",@@ -217,6 +222,7 @@ export class CliPiAppState {model: "",version: "",};+ private preferredLanguage: PreferredLanguage = "zh";private memoryWarnings: {path: string;kind: string;@@ -251,6 +257,7 @@ export class CliPiAppState {this.mode = mode;},getMode: () => this.mode,+ getPreferredLanguage: () => this.preferredLanguage,getEntries: () => this.entries,setEntries: (entries) => {this.entries = entries;@@ -475,6 +482,7 @@ export class CliPiAppState {const activeModel = activeModelName? models.find((m) => m.model_name === activeModelName): models[0];+ this.preferredLanguage = normalizePreferredLanguage(config.preferred_language);this.modelInfo = {provider: String(activeModel?.model_provider ?? config.model_provider ?? ""),model: activeModelName || String(config.model ?? ""),@@ -607,6 +615,7 @@ export class CliPiAppState {contextWindowLimit: this.contextWindowLimit,contextUsedPercentage: this.contextUsedPercentage,modelInfo: this.modelInfo,+ preferredLanguage: this.preferredLanguage,sessionTitle: this.sessionTitle,statusLineText: this.statusLineText,memoryWarnings: [...this.memoryWarnings],@@ -645,6 +654,7 @@ export class CliPiAppState {askQuestions: this.askQuestions,sendMessage: this.sendMessage,sessionId: snapshot.sessionId,+ preferredLanguage: snapshot.preferredLanguage,entries: snapshot.entries,themeName: snapshot.themeName,accentColor: snapshot.accentColor,@@ -664,6 +674,7 @@ export class CliPiAppState {mode: snapshot.mode,setMode: this.setMode,setModel: this.setModel,+ setPreferredLanguage: this.setPreferredLanguage,setThemeName: this.setThemeName,setAccentColor: this.setAccentColor,transcriptMode: snapshot.transcriptMode,@@ -849,6 +860,13 @@ export class CliPiAppState {}};+ readonly setPreferredLanguage = (language: PreferredLanguage): void => {+ if (this.preferredLanguage !== language) {+ this.preferredLanguage = language;+ this.emitChange();+ }+ };+readonly setThemeName = (theme: ThemeName): void => {if (this.themeName !== theme) {this.themeName = theme;@@ -1894,6 +1912,7 @@ export class CliPiAppState {model: snapshot.modelInfo.model,provider: snapshot.modelInfo.provider,version: snapshot.modelInfo.version,+ preferred_language: snapshot.preferredLanguage,connection: snapshot.connectionStatus,theme: snapshot.themeName,accent_color: snapshot.accentColor,diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.tsindex 7cdb5323c5..8c14528f4c 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts@@ -127,6 +127,9 @@ async function applyConfigSet(},),);+ if (key === "preferred_language" && (value === "en" || value === "zh")) {+ ctx.setPreferredLanguage(value);+ }} catch (error) {const message = error instanceof Error ? error.message : String(error);ctx.addItem(addError(ctx.sessionId, `config.set failed: ${message}`));@@ -559,4 +562,4 @@ export function createConfigCommand(): SlashCommand {emitConfigGetDisplay(ctx, key, payload as Record<string, unknown> & { schema?: ConfigItemSchema[] });},};-}\ No newline at end of file+}diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/init.prompts.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/init.prompts.tsindex fc659b5fa0..8d8ffe83a3 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/init.prompts.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/init.prompts.ts@@ -23,8 +23,10 @@ export interface BuildInitPromptArgs {// Language resolution// ----------------------------------------------------------------------------export function resolveLanguage(_ctx: CommandContext): "zh" | "en" {- // 当前方案:best-effort from LANG env; 后续可读 config.+export function resolveLanguage(ctx: CommandContext): "zh" | "en" {+ if (ctx.preferredLanguage === "en" || ctx.preferredLanguage === "zh") {+ return ctx.preferredLanguage;+ }const lang =typeof process !== "undefined" ? (process.env.LANG ?? "") : "";return /^zh/i.test(lang) || /CN$/i.test(lang) ? "zh" : "en";diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/types.tsindex fafb842a27..4926887db6 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts@@ -8,6 +8,8 @@ import type { SessionUsageSummary } from "../../app-state.js";export type ConnectionStatus = "idle" | "connecting" | "connected" | "reconnecting" | "auth_failed" | "message_too_big";+export type PreferredLanguage = "zh" | "en";+export type StatusViewTab = "status" | "usage" | "config";export enum CommandKind {@@ -42,6 +44,7 @@ export interface CommandContext {options?: { logAsUser?: boolean },) => string | null;sessionId: string;+ preferredLanguage: PreferredLanguage;entries: HistoryItem[];themeName: ThemeName;accentColor: AccentColorName;@@ -59,6 +62,7 @@ export interface CommandContext {mode: ClientMode;setMode: (mode: ClientMode) => void;setModel: (name: string) => void;+ setPreferredLanguage: (language: PreferredLanguage) => void;setThemeName: (theme: ThemeName) => void;setAccentColor: (color: AccentColorName) => void;transcriptMode: "compact" | "detailed";diff --git a/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts b/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.tsindex 31828bfb4d..d4a7ca87ae 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts@@ -27,6 +27,8 @@ import type { ConnectionStatus } from "./ws-client.js";import { createId, findLastIndex, isIgnorableHistoryRestoreError } from "./app-state-helpers.js";import { isClientMode, type ClientMode } from "./modes.js";+type PreferredLanguage = "zh" | "en";+export interface PendingQuestion {requestId: string;source?: string;@@ -84,6 +86,7 @@ export interface AppEventDelegate {setSessionId(sessionId: string): void;setMode(mode: ClientMode): void;getMode(): ClientMode;+ getPreferredLanguage(): PreferredLanguage;getEntries(): HistoryItem[];setEntries(entries: HistoryItem[]): void;setStreamingState(state: StreamingState): void;@@ -322,6 +325,35 @@ function appendEntry(delegate: AppEventDelegate, entry: HistoryItem): void {delegate.setEntries([...delegate.getEntries(), entry]);}+function formatInterruptResultMessage(language: PreferredLanguage, intent: string, success: boolean, payloadMessage: unknown): string {+ const rawMessage = typeof payloadMessage === "string" ? payloadMessage.trim() : "";+ if (language !== "en") {+ if (rawMessage) return rawMessage;+ return success ? "当前会话任务已终止" : "当前会话任务终止失败";+ }+ const englishDefaults: Record<string, { success: string; failure: string }> = {+ cancel: { success: "Task cancelled", failure: "Failed to cancel task" },+ pause: { success: "Task paused", failure: "Failed to pause task" },+ resume: { success: "Task resumed", failure: "Failed to resume task" },+ switch: { success: "Task switched", failure: "Failed to switch task" },+ };+ const defaults = englishDefaults[intent] ?? englishDefaults.cancel!;+ if (!rawMessage) return success ? defaults.success : defaults.failure;+ const knownChineseMessages: Record<string, string> = {+ "任务已取消": "Task cancelled",+ "当前会话任务已终止": "Task cancelled",+ "当前会话任务终止失败": "Failed to cancel task",+ "任务中断失败": "Failed to interrupt task",+ "任务暂停失败": "Failed to pause task",+ "任务恢复失败": "Failed to resume task",+ "任务切换失败": "Failed to switch task",+ "已切换到新任务": "Switched to new task",+ };+ if (knownChineseMessages[rawMessage]) return knownChineseMessages[rawMessage];+ if (/[\u4e00-\u9fff]/.test(rawMessage)) return success ? defaults.success : defaults.failure;+ return rawMessage;+}+function appendThinkingChunk(delegate: AppEventDelegate,activeSessionId: string,@@ -1059,12 +1091,7 @@ export function handleIncomingFrame(delegate: AppEventDelegate, frame: EventFramreturn true;}const success = payload.success !== false;- const message =- typeof payload.message === "string" && payload.message.trim()- ? payload.message- : success- ? "当前会话任务已终止"- : "当前会话任务终止失败";+ const message = formatInterruptResultMessage(delegate.getPreferredLanguage(), intent, success, payload.message);if (success) {delegate.setStreamingState(StreamingState.Interrupted);delegate.getActiveSubtasks().clear();diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/transcript-renderer.ts b/jiuwenswarm/channels/tui/frontend/src/ui/transcript-renderer.tsindex eb46347caf..af0b987b93 100644--- a/jiuwenswarm/channels/tui/frontend/src/ui/transcript-renderer.ts+++ b/jiuwenswarm/channels/tui/frontend/src/ui/transcript-renderer.ts@@ -73,7 +73,7 @@ export function buildTranscriptLines(): string[] {const { entries: displayEntries, latestThinkingId } = selectTranscriptEntries(snapshot);- const allLines: string[] = [...buildWelcomeLines(width, snapshot.connectionStatus, snapshot.modelInfo, snapshot.mode, snapshot.memoryWarnings)];+ const allLines: string[] = [...buildWelcomeLines(width, snapshot.connectionStatus, snapshot.modelInfo, snapshot.mode, snapshot.memoryWarnings, snapshot.preferredLanguage)];const showPendingInput =typeof pendingInput === "string" &&pendingInput.length > 0 &&diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/welcome.ts b/jiuwenswarm/channels/tui/frontend/src/ui/welcome.tsindex 199abf0196..5152d635dc 100644--- a/jiuwenswarm/channels/tui/frontend/src/ui/welcome.ts+++ b/jiuwenswarm/channels/tui/frontend/src/ui/welcome.ts@@ -3,6 +3,8 @@ import type { ConnectionStatus } from "../core/ws-client.js";import { padToWidth } from "./rendering/text.js";import { chalk } from "./theme.js";+type PreferredLanguage = "zh" | "en";+const ART_TITLE_RAW = [""," ██╗██╗██╗ ██╗██╗ ██╗███████╗███╗ ██╗ ███████╗██╗ ██╗ █████╗ ██████╗ ███╗ ███╗",@@ -42,7 +44,7 @@ function centerLine(line: string, width: number): string {return " ".repeat(leftPadding) + line + " ".repeat(rightPadding);}-function connectionHint(status: ConnectionStatus): string | null {+function connectionHint(status: ConnectionStatus, language: PreferredLanguage): string | null {switch (status) {case "connecting":return "Connecting to backend…";@@ -53,22 +55,32 @@ function connectionHint(status: ConnectionStatus): string | null {case "auth_failed":return "Authentication failed · check --token";case "message_too_big":- return "消息过大,连接被断开 · 请缩短输入后重试";+ return language === "en"+ ? "Message too large; connection closed · shorten the input and retry"+ : "消息过大,连接被断开 · 请缩短输入后重试";case "connected":default:return null;}}+function narrowCommandLine(label: string, width: number): string {+ const content = ` ${label}`;+ const padding = Math.max(0, 60 - visibleWidth(content));+ return padToWidth(chalk.hex("#FFFFFF")("│") + chalk.hex("#FFFFFF")(content) + " ".repeat(padding) + chalk.hex("#FFFFFF")("│"), width);+}+export function buildWelcomeLines(width: number,connectionStatus: ConnectionStatus,modelInfo: { provider: string; model: string; version: string } = { provider: "", model: "", version: "" },mode: string = "",memoryWarnings: { path: string; kind: string; char_count: number; threshold: number; message: string }[] = [],+ preferredLanguage: PreferredLanguage = "zh",): string[] {const artWidth = Math.max(...ART_TITLE_RAW.map((line) => visibleWidth(line)));- const hint = connectionHint(connectionStatus);+ const hint = connectionHint(connectionStatus, preferredLanguage);+ const isEnglish = preferredLanguage === "en";const version = modelInfo.version || "0.1.0";const provider = modelInfo.provider || "";const model = modelInfo.model || "";@@ -87,7 +99,7 @@ export function buildWelcomeLines(const right = padding - left;return chalk.hex("#FFFFFF")("│") + " ".repeat(left) + chalk.hex("#FFFFFF")(content) + " ".repeat(right) + chalk.hex("#FFFFFF")(" │");};- const shortCmdTitle = chalk.hex("#FFFFFF")(" 快捷命令 ");+ const shortCmdTitle = chalk.hex("#FFFFFF")(isEnglish ? " Shortcuts " : " 快捷命令 ");const titleWithBorder = "───────" + shortCmdTitle + "───────";const titleLineWidth = visibleWidth(titleWithBorder);const topPadding = Math.max(0, cmdBoxWidth - 2 - titleLineWidth);@@ -95,7 +107,9 @@ export function buildWelcomeLines(const topRight = topPadding - topLeft;const cmdTop = chalk.hex("#FFFFFF")("┌") + "─".repeat(topLeft) + titleWithBorder + "─".repeat(topRight) + chalk.hex("#FFFFFF")("┐");const cmdBottom = chalk.hex("#FFFFFF")("└") + "─".repeat(cmdBoxWidth - 2) + chalk.hex("#FFFFFF")("┘");- const commands = " /help - 查看帮助 /mode - 切换模式 /skills - 可用技能 /exit - 退出 ";+ const commands = isEnglish+ ? " /help - Help /mode - Switch mode /skills - Skills /exit - Exit "+ : " /help - 查看帮助 /mode - 切换模式 /skills - 可用技能 /exit - 退出 ";return [...coloredArt,"",@@ -112,6 +126,9 @@ export function buildWelcomeLines(];}+ const narrowTitle = isEnglish+ ? "│ Shortcuts │"+ : "│ 快捷命令 │";return [padToWidth(chalk.hex("#FFD700")("JIUWEN SWARM"), width),"",@@ -120,12 +137,12 @@ export function buildWelcomeLines(padToWidth(chalk.hex("#3a7378")("https://gitcode.com/openJiuwen/agent-core"), width),"",padToWidth(chalk.hex("#FFFFFF")("┌────────────────────────────────────────────────────────────┐"), width),- padToWidth(chalk.hex("#FFFFFF")("│ ") + chalk.hex("#FFFFFF")(" 快捷命令 ") + chalk.hex("#FFFFFF")(" │"), width),+ padToWidth(chalk.hex("#FFFFFF")(narrowTitle), width),padToWidth(chalk.hex("#FFFFFF")("├────────────────────────────────────────────────────────────┤"), width),- padToWidth(chalk.hex("#FFFFFF")("│ ") + chalk.hex("#FFFFFF")("/help - 查看帮助 ") + chalk.hex("#FFFFFF")("│"), width),- padToWidth(chalk.hex("#FFFFFF")("│ ") + chalk.hex("#FFFFFF")("/mode - 切换模式 ") + chalk.hex("#FFFFFF")("│"), width),- padToWidth(chalk.hex("#FFFFFF")("│ ") + chalk.hex("#FFFFFF")("/skills - 可用技能 ") + chalk.hex("#FFFFFF")("│"), width),- padToWidth(chalk.hex("#FFFFFF")("│ ") + chalk.hex("#FFFFFF")("/exit - 退出 ") + chalk.hex("#FFFFFF")("│"), width),+ narrowCommandLine(isEnglish ? "/help - Help" : "/help - 查看帮助", width),+ narrowCommandLine(isEnglish ? "/mode - Switch mode" : "/mode - 切换模式", width),+ narrowCommandLine(isEnglish ? "/skills - Skills" : "/skills - 可用技能", width),+ narrowCommandLine(isEnglish ? "/exit - Exit" : "/exit - 退出", width),padToWidth(chalk.hex("#FFFFFF")("└────────────────────────────────────────────────────────────┘"), width),...(hint ? [padToWidth(chalk.hex("#FFFFFF")(hint), width)] : []),...(memoryWarnings.length > 0