feat: 实现 TUI 组件系统

- 添加 blessed 终端 UI 库
- 创建 ChatView 组件:支持消息列表和流式输出
- 创建 SessionList 组件:会话管理和快捷键
- 创建 StatusBar 组件:连接状态显示
- 创建 TUIApp 主应用整合所有组件
- 更新 attach 命令支持 --tui/--no-tui 选项
- 添加 CLAUDE.md 项目规范文件
- 修复 Web 前端 CSS prose 类缺失问题
This commit is contained in:
2025-12-12 11:47:24 +08:00
parent 168996a475
commit da1773b950
12 changed files with 1145 additions and 17 deletions
+28 -15
View File
@@ -16,8 +16,10 @@ export function registerAttachCommand(program: Command): void {
.argument('<url>', 'Server URL (e.g., http://192.168.1.100:3000)')
.option('-t, --token <token>', 'Authentication token')
.option('-s, --session <id>', 'Session ID to connect to')
.option('--tui', 'Use TUI mode (default)', true)
.option('--no-tui', 'Use simple CLI mode')
.action(async (url: string, options) => {
const { token, session: sessionId } = options;
const { token, session: sessionId, tui } = options;
const spinner = ora('Connecting to server...').start();
@@ -32,21 +34,32 @@ export function registerAttachCommand(program: Command): void {
const health = await client.health();
spinner.succeed(`Connected to server at ${url}`);
console.log(chalk.gray('─'.repeat(50)));
console.log(chalk.bold('Server Status:'));
console.log(` Status: ${chalk.green(health.status)}`);
console.log(` Agent: ${health.agent.coreAvailable ? chalk.green('Available') : chalk.yellow('Not available')}`);
console.log(` Auth: ${health.auth.enabled ? chalk.yellow('Enabled') : chalk.gray('Disabled')}`);
console.log(` Sessions: ${health.stats.sessions}`);
console.log(` WebSocket: ${health.stats.websocket.connections} connections`);
console.log(chalk.gray('─'.repeat(50)));
// 如果指定了 session,连接到该 session
if (sessionId) {
await connectToSession(client, sessionId);
if (tui) {
// TUI 模式
const { TUIApp } = await import('../tui/index.js');
const app = new TUIApp({
client,
sessionId,
});
await app.start();
} else {
// 显示可用 sessions 或创建新的
await showSessionMenu(client);
// 简单 CLI 模式
console.log(chalk.gray('─'.repeat(50)));
console.log(chalk.bold('Server Status:'));
console.log(` Status: ${chalk.green(health.status)}`);
console.log(` Agent: ${health.agent.coreAvailable ? chalk.green('Available') : chalk.yellow('Not available')}`);
console.log(` Auth: ${health.auth.enabled ? chalk.yellow('Enabled') : chalk.gray('Disabled')}`);
console.log(` Sessions: ${health.stats.sessions}`);
console.log(` WebSocket: ${health.stats.websocket.connections} connections`);
console.log(chalk.gray('─'.repeat(50)));
// 如果指定了 session,连接到该 session
if (sessionId) {
await connectToSession(client, sessionId);
} else {
// 显示可用 sessions 或创建新的
await showSessionMenu(client);
}
}
} catch (error) {
spinner.fail('Failed to connect to server');