Skip to content

feat: add CLI channel with TUI support#371

Open
CjiW wants to merge 4 commits intomasterfrom
feat/cli-channel
Open

feat: add CLI channel with TUI support#371
CjiW wants to merge 4 commits intomasterfrom
feat/cli-channel

Conversation

@CjiW
Copy link
Copy Markdown
Owner

@CjiW CjiW commented Mar 30, 2026

功能概述

为 xbot 添加 CLI Channel,- 支持 TUI 交互式终端界面

  • 基于 Bubble Tea 框架构建
  • 提供流式输出、Markdown 渲染、进度显示等功能

核心特性

  • 实时流式输出 - Agent 思考过程实时显示
  • Markdown 渲染 - 代码高亮、表格、列表支持
  • 多行输入 - 支持 Enter 换行,Ctrl+Enter 发送
  • 工具进度 - 实时显示工具执行状态
  • SubAgent 状态 - 树状展示子代理进度
  • 优雅退出 - SIGINT/SIGTERM 处理
  • 窗口自适应 - 动态 resize 响应

技术栈

组件 技术
TUI 框架 Bubble Tea
样式引擎 lipgloss
Markdown glamour
输入组件 bubbles/textarea

测试

  • 测试用例: 67 个
  • 覆盖率: 91.38%
  • CI 状态: ✅ Build / ✅ Lint / ✅ Test

使用方式

# 直接运行
go run ./cmd/cli

# 编译后运行
go build -o xbot-cli ./cmd/cli
./xbot-cli

文档

详细使用文档见: docs/cli-channel.md

变更文件

新增:

  • channel/cli.go - CLI Channel 核心实现
  • channel/cli_test.go - 单元测试
  • channel/card_converter.go - Feishu Card 转换器
  • cmd/cli/main.go - CLI 独立入口
  • docs/cli-channel.md - 用户文档

修改:

  • go.mod - 添加 Bubble Tea 等依赖
  • bus/bus.go - 添加 IsPartial 字段
  • channel/web.go - 使用共享 Card 转换器
  • README.md - 添加 CLI Channel 说明

Co-authored-by: xbot xbot@example.com

xbot and others added 4 commits March 30, 2026 12:27
When SandboxRouter has docker enabled, inject a built-in docker sandbox
entry (named __docker__) into the runner list so users can see and switch
to it from both the web UI and Feishu settings card.

Changes:
- tools/sandbox_router.go: add HasDocker(), DockerImage(), SetTokenStore();
  SandboxForUser now reads user_settings.active_runner to respect user choice
- tools/docker_sandbox.go: add Image() method
- tools/sandbox_runner.go: SetRunnerTokenDB also sets router's tokenStore
- main.go: RunnerList callback injects docker entry when router has docker
- channel/web_api.go: reject DELETE for built-in docker sandbox
- channel/feishu_settings.go: show docker as 'Docker Sandbox (内置)',
  hide delete button, guard against deletion
- web/src/components/RunnerPanel.tsx: special handling for __docker__
  (no delete, no connect command, always online)
- Add channel/cli.go: CLI Channel implementation with Bubble Tea TUI
- Add cmd/cli/main.go: Standalone CLI entry point
- Add channel/card_converter.go: Shared Feishu Card converter
- Add docs/cli-channel.md: User documentation
- Update go.mod: Add Bubble Tea, Lipgloss, Glamour dependencies
- Add bus.IsPartial field for streaming support
- Update channel/web.go to use shared card converter
- Update README.md with CLI Channel usage

Features:
- Real-time streaming output with progress indicators
- Markdown rendering with syntax highlighting
- Multi-line input with keyboard shortcuts
- Tool progress and SubAgent status display
- Graceful shutdown handling
- Window resize support

Testing:
- 67 test cases with 91.38% coverage
- All CI checks passed (Build/Lint/Test)

Co-authored-by: xbot <xbot@example.com>
glamour.WithAutoStyle() queries terminal background color via OSC 11,
the response (e.g. ]11;rgb:1e1e/1e1e/1e1e\) leaks into textarea stdin
and gets displayed as garbled text.

Fix:
- Replace glamour.WithAutoStyle() with glamour.WithStandardStyle("dark")
- Clear textarea in Init() to absorb any residual OSC responses
termenv.DefaultOutput() queries terminal background color by sending
OSC 11 (\x1b]11;?\x1b\). The terminal response leaks into textarea
stdin and displays as garbled text (e.g. ]11;rgb:1e1e/1e1e/1e1e\).

Fix: Set termenv default output with WithTTY(false) in init() to
prevent any terminal queries. Combined with previous fix:
- glamour.WithStandardStyle("dark") instead of WithAutoStyle()
- textarea.Reset() in Init() as safety net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant