Skip to content

feat: optimize CLI channel to replace Claude Code/Codex#376

Merged
CjiW merged 9 commits intomasterfrom
feat/cli-channel-optimize
Mar 31, 2026
Merged

feat: optimize CLI channel to replace Claude Code/Codex#376
CjiW merged 9 commits intomasterfrom
feat/cli-channel-optimize

Conversation

@Chronostasys
Copy link
Copy Markdown
Collaborator

Summary

CLI channel 全面优化,对标 Claude Code / Codex 终端体验。基于 feat/cli-channel 分支增量改进。

Changes

文件 改动
channel/cli.go +717/-164 — 增量渲染、工具可视化、/model /context 命令、Tab 补全、Ctrl+K 上下文编辑
channel/cli_test.go -18 — 删除冗余 TestMaxInt(Go 内置 max())
cmd/cli/main.go +204 — --resume/--new 会话恢复、非交互流式输出增强
agent/engine_wire.go gofmt 修复
channel/web.go gofmt 修复

核心特性

  1. 增量渲染cachedHistory 分离 + dirty 标记 + 流式只渲染最后一条,长对话不卡顿
  2. 工具调用可视化 — 完成工具的摘要卡片(名称、耗时),折叠显示
  3. /model 命令 — 切换模型(别名 /set-model)
  4. /context 命令 — 透传 agent 层管理压缩模式
  5. Tab 补全 — 9 个已知命令,循环选择
  6. Ctrl+K — 交互式删除最近 N 条消息
  7. 会话恢复--resume 默认恢复、--new 强制新会话
  8. 非交互流式 — diff 差量输出,逐 token 打印到 stdout

Verification

  • go build ./... — 编译通过
  • go vet — 无警告
  • golangci-lint — 0 issues
  • go test -race ./... — 全量测试通过

xbot and others added 5 commits March 31, 2026 05:04
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
- Incremental rendering: cached history + dirty flag + streaming fast path
- Tool call visualization: completed tools summary cards
- /model command: alias for /set-model
- /context command: passthrough to agent layer
- Non-interactive streaming: diff-based stdout output
- Session resume: --resume/--new flags
- Tab completion: 9 known commands with cycle selection
- Ctrl+K: interactive context editing (delete last N messages)
- maxInt() replaced with Go builtin max()
- inputReady field restored for test compatibility
@Chronostasys Chronostasys force-pushed the feat/cli-channel-optimize branch from b8b515a to cec41f8 Compare March 31, 2026 05:09
Boxiu Li added 4 commits March 31, 2026 17:34
- Updated `bubbletea` to v1.3.10 and `lipgloss` to v1.1.0 for improved performance.
- Replaced `charmbracelet/x/ansi` with v0.10.1 and added `charmbracelet/x/cellbuf` for better rendering support.
- Enhanced `compactMessages` function to include a new `maxContextTokens` parameter, optimizing message handling and token budget management.
- Introduced `formatCompactLine` function to format messages for compaction history, ensuring clarity and consistency in output.
- Added tests for CLI progress rendering and message handling to ensure robustness and prevent regressions.
…ummary

- Add HistoryLoader callback to CLIChannelConfig for session restore on restart
- Reconstruct tool_summary messages from IterationHistory JSON (Detail field)
- Display thinking + tools grouped by iteration in bordered panel
- Filter intermediate assistant/tool messages from history
- Runtime and restored history now render identically
- Remove automatic /context info on startup
- Fix S1016 staticcheck and remove unused syncWriter
…pinner fix

- Ctrl+Enter/Ctrl+J for newline in textarea (Enter sends)
- ChatID uses absWorkDir for per-directory session isolation
- Spinner animation fixed: spinner.TickMsg now triggers viewport refresh
- Status bar: show 'processing' instead of 'thinking' when no progress
  event; show active tool name or phase-specific hints
- Full-width message rendering: removed narrow bubble borders,
  glamour renderer uses terminal width
- Logger: new LogDir field (priority over WorkDir), CLI logs to xbotHome
- cmd/cli renamed to cmd/xbot-cli (go install produces xbot-cli binary)
- main.go refactored: extract cliApp for shared init between modes
- Inject SetDirectSend/SetChannelFinder for structured progress events
- config.go refactored: file+env+defaults three-layer config loading
@CjiW CjiW merged commit ae68708 into master Mar 31, 2026
3 checks passed
@CjiW CjiW deleted the feat/cli-channel-optimize branch March 31, 2026 13:29
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.

2 participants