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: tui终端样式优化
openJiuwen-bot18be4b485bd3
diff --git a/jiuwenclaw/cli/src/app-state.ts b/jiuwenclaw/cli/src/app-state.tsindex c29e31a72b..265c9ff604 100644--- a/jiuwenclaw/cli/src/app-state.ts+++ b/jiuwenclaw/cli/src/app-state.ts@@ -65,6 +65,7 @@ export interface AppSnapshot {teamMessageEvents: TeamMessageEvent[];evolutionStatus: "idle" | "running";contextCompression: ContextCompressionStats | null;+ modelInfo: { provider: string; model: string; version: string };}export class CliPiAppState {@@ -108,6 +109,11 @@ export class CliPiAppState {private historyRequestToken = 0;private unlistenStatus: (() => void) | null = null;private unlistenFrames: (() => void) | null = null;+ private modelInfo: { provider: string; model: string; version: string } = {+ provider: "",+ model: "",+ version: "",+ };private readonly eventDelegate: AppEventDelegate = {getConnectionStatus: () => this.connectionStatus,getSessionId: () => this.sessionId,@@ -180,9 +186,12 @@ export class CliPiAppState {}start(): void {- this.unlistenStatus = this.wsClient.onStatusChange((status) => {+ this.unlistenStatus = this.wsClient.onStatusChange(async (status) => {this.connectionStatus = status;this.emitChange();+ if (status === "connected") {+ await this.fetchModelInfo();+ }});this.unlistenFrames = this.wsClient.onFrame((frame) => {@@ -212,6 +221,23 @@ export class CliPiAppState {this.wsClient.disconnect();}+ private async fetchModelInfo(): Promise<void> {+ try {+ const payload = await this.request("config.get", {});+ if (payload && typeof payload === "object") {+ const config = payload as Record<string, unknown>;+ this.modelInfo = {+ provider: String(config.model_provider ?? ""),+ model: String(config.model ?? ""),+ version: String(config.app_version ?? ""),+ };+ this.emitChange();+ }+ } catch {+ // ignore error, use defaults+ }+ }+onChange(listener: () => void): () => void {this.listeners.add(listener);return () => {@@ -256,6 +282,7 @@ export class CliPiAppState {teamMessageEvents: [...this.teamMessageEvents],evolutionStatus: this.evolutionStatus,contextCompression: this.contextCompression ? { ...this.contextCompression } : null,+ modelInfo: this.modelInfo,};}diff --git a/jiuwenclaw/cli/src/core/commands/registry.ts b/jiuwenclaw/cli/src/core/commands/registry.tsindex 04bbc6fbb0..8d0b92e7cc 100644--- a/jiuwenclaw/cli/src/core/commands/registry.ts+++ b/jiuwenclaw/cli/src/core/commands/registry.ts@@ -17,7 +17,6 @@ import { createPlanCommand } from "./builtins/plan.js";import { createResumeCommand } from "./builtins/resume.js";import { createSessionCommand } from "./builtins/session.js";import { createSkillsCommand } from "./builtins/skills.js";-import { createSwitchCommand } from "./builtins/switch.js";import { createThemeCommand } from "./builtins/theme.js";export function createBuiltinCommands(): SlashCommand[] {@@ -34,7 +33,6 @@ export function createBuiltinCommands(): SlashCommand[] {createExitCommand(),createModelCommand(),createModeCommand(),- createSwitchCommand(),createPlanCommand(),createResumeCommand(),createSessionCommand(),diff --git a/jiuwenclaw/cli/src/ui/transcript-renderer.ts b/jiuwenclaw/cli/src/ui/transcript-renderer.tsindex 4da726b490..f9fb7021ce 100644--- a/jiuwenclaw/cli/src/ui/transcript-renderer.ts+++ b/jiuwenclaw/cli/src/ui/transcript-renderer.ts@@ -30,7 +30,7 @@ export function buildTranscriptLines(): string[] {const { entries: displayEntries, latestThinkingId } = selectTranscriptEntries(snapshot);- const allLines: string[] = [...buildWelcomeLines(width, snapshot.connectionStatus)];+ const allLines: string[] = [...buildWelcomeLines(width, snapshot.connectionStatus, snapshot.modelInfo, snapshot.mode)];const showPendingInput =typeof pendingInput === "string" &&pendingInput.length > 0 &&diff --git a/jiuwenclaw/cli/src/ui/welcome.ts b/jiuwenclaw/cli/src/ui/welcome.tsindex c0cbaebe83..9f601e2187 100644--- a/jiuwenclaw/cli/src/ui/welcome.ts+++ b/jiuwenclaw/cli/src/ui/welcome.ts@@ -1,19 +1,45 @@import { visibleWidth } from "@mariozechner/pi-tui";import type { ConnectionStatus } from "../core/ws-client.js";import { padToWidth } from "./rendering/text.js";-import { palette } from "./theme.js";+import { chalk } from "./theme.js";-const ART_TITLE = [- "╔════╗ ╔════╗ ╔════╗",- "║ ║ ║ ║ ║ ║",- "║ 九 ║ ║ 纹 ║ ║ 爪 ║",- "║ ║ ║ ║ ║ ║",- "╚════╝ ╚════╝ ╚════╝",+const ART_TITLE_RAW = [+ "",+ " ██╗██╗██╗ ██╗██╗ ██╗███████╗███╗ ██╗ ██████╗██╗ █████╗ ██╗ ██╗",+ " ██║██║██║ ██║██║ ██║██╔════╝████╗ ██║ ██╔════╝██║ ██╔══██╗██║ ██║",+ " ██║██║██║ ██║██║ █╗ ██║█████╗ ██╔██╗ ██║ ██║ ██║ ███████║██║ █╗ ██║",+ "██ ██║██║██║ ██║██║███╗██║██╔══╝ ██║╚██╗██║ ██║ ██║ ██╔══██║██║███╗██║",+ "╚█████╔╝██║╚██████╔╝╚███╔███╔╝███████╗██║ ╚████║ ╚██████╗███████╗██║ ██║╚███╔███╔╝",+ " ╚════╝ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═╝ ╚═╝ ╚══╝╚══╝ ",] as const;+const BG_MAGENTA = "#2E0B23";+const GRADIENT_COLORS = [+ "#FFD700",+ "#FFD000",+ "#FFC000",+ "#FFB000",+ "#FFA000",+ "#FF9000",+ "#FF8000",+ "#FF7000",+ "#FF6000",+ "#FF5000",+ "#FF4500",+ "#FF3D00",+];++function applyGradient(line: string, colorIndex: number): string {+ const color = GRADIENT_COLORS[Math.min(colorIndex, GRADIENT_COLORS.length - 1)] ?? "#FFD700";+ return chalk.hex(color)(line);+}+function centerLine(line: string, width: number): string {- const padding = Math.max(0, Math.floor((width - visibleWidth(line)) / 2));- return padToWidth(`${" ".repeat(padding)}${line}`, width);+ const lineWidth = visibleWidth(line);+ const totalPadding = Math.max(0, width - lineWidth);+ const leftPadding = Math.floor(totalPadding / 2);+ const rightPadding = totalPadding - leftPadding;+ return " ".repeat(leftPadding) + line + " ".repeat(rightPadding);}function connectionHint(status: ConnectionStatus): string | null {@@ -32,22 +58,69 @@ function connectionHint(status: ConnectionStatus): string | null {}}-export function buildWelcomeLines(width: number, connectionStatus: ConnectionStatus): string[] {- const artWidth = Math.max(...ART_TITLE.map((line) => visibleWidth(line)));+export function buildWelcomeLines(+ width: number,+ connectionStatus: ConnectionStatus,+ modelInfo: { provider: string; model: string; version: string } = { provider: "", model: "", version: "" },+ mode: string = ""+): string[] {+ const artWidth = Math.max(...ART_TITLE_RAW.map((line) => visibleWidth(line)));const hint = connectionHint(connectionStatus);+ const version = modelInfo.version || "0.1.0";+ const provider = modelInfo.provider || "";+ const model = modelInfo.model || "";if (width >= artWidth + 6) {+ const coloredArt = ART_TITLE_RAW.map((line, index) => {+ const coloredLine = applyGradient(line, index);+ return centerLine(coloredLine, width);+ });+ const subtitle = chalk.hex("#FFFFFF")(`v${version} | Provider: ${provider} | Model: ${model} | Mode: ${mode}`);+ const poweredBy = chalk.hex("#FFFFFF")("Powered by ") + chalk.hex("#655795")("openJiuwen SDK") + chalk.hex("#FFFFFF")(` v${version} (`) + chalk.hex("#3a7378")("https://gitcode.com/openJiuwen/agent-core") + chalk.hex("#FFFFFF")(")");+ const cmdBoxWidth = 80;+ const cmdBoxLine = (content: string) => {+ const lineWidth = visibleWidth(content);+ const padding = Math.max(0, cmdBoxWidth - 4 - lineWidth);+ const left = Math.floor(padding / 2);+ 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 titleWithBorder = "───────" + shortCmdTitle + "───────";+ const titleLineWidth = visibleWidth(titleWithBorder);+ const topPadding = Math.max(0, cmdBoxWidth - 2 - titleLineWidth);+ const topLeft = Math.floor(topPadding / 2);+ 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 - 退出 ";return [- ...ART_TITLE.map((line) => centerLine(palette.text.dim(line), width)),- centerLine(palette.text.subtle("/resume to continue · /help for commands"), width),- ...(hint ? [centerLine(palette.text.subtle(hint), width)] : []),- " ".repeat(width),+ ...coloredArt,+ "",+ centerLine(subtitle, width),+ centerLine(poweredBy, width),+ "",+ centerLine(cmdTop, width),+ centerLine(cmdBoxLine(commands), width),+ centerLine(cmdBottom, width),+ ...(hint ? [centerLine(chalk.hex("#FFFFFF")(hint), width)] : []),];}return [- padToWidth(palette.text.dim("九纹爪"), width),- padToWidth(palette.text.subtle("/resume to continue · /help for commands"), width),- ...(hint ? [padToWidth(palette.text.subtle(hint), width)] : []),- " ".repeat(width),+ padToWidth(chalk.hex("#FFD700")("JIUWEN CLAW"), width),+ "",+ padToWidth(chalk.hex("#FFFFFF")(`v${version} | Provider: ${provider} | Model: ${model} | Mode: ${mode}`), width),+ padToWidth(chalk.hex("#FFFFFF")("Powered by ") + chalk.hex("#655795")("openJiuwen SDK") + chalk.hex("#FFFFFF")(` v${version}`), width),+ 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")("├────────────────────────────────────────────────────────────┤"), 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),+ padToWidth(chalk.hex("#FFFFFF")("└────────────────────────────────────────────────────────────┘"), width),+ ...(hint ? [padToWidth(chalk.hex("#FFFFFF")(hint), width)] : []),];}