返回顶部
b

bubbletea-code-review气泡茶代码审查

Reviews BubbleTea TUI code for proper Elm architecture, model/update/view patterns, and Lipgloss styling. Use when reviewing terminal UI code using charmbracelet/bubbletea.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 2.3.0
安全检测
已通过
115
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

bubbletea-code-review

BubbleTea 代码审查

快速参考

问题类型参考文档
Elm架构,tea.Cmd作为数据references/elm-architecture.md
模型状态,消息处理
references/model-update.md | | 视图渲染,Lipgloss样式 | references/view-styling.md | | 组件组合,Huh表单 | references/composition.md | | Bubbles组件(列表、表格等) | references/bubbles-components.md |

关键:避免误报

请先阅读 elm-architecture.md 最常见的审查错误是将正确模式标记为错误。

非问题(不要标记这些)

模式正确原因
return m, m.loadData()tea.Cmd 立即返回;运行时异步执行
Update() 使用值接收者
标准BubbleTea模式;模型按值返回 | | 嵌套 m.child, cmd = m.child.Update(msg) | 正常的组件组合 | | 辅助函数返回 tea.Cmd | 创建命令描述符,Update中无I/O操作 | | tea.Batch(cmd1, cmd2) | 命令由运行时并发执行 |

实际问题(需要标记这些)

模式错误原因
Update中的 os.ReadFile()阻塞UI线程
Update中的 http.Get()
网络I/O阻塞 | | Update中的 time.Sleep() | 冻结UI | | Update中的 <-channel(阻塞) | 可能无限期阻塞 | | Update中的 huh.Form.Run() | 阻塞调用 |

审查清单

架构

  • - [ ] Update()中无阻塞I/O(文件、网络、休眠)
  • [ ] 返回 tea.Cmd 的辅助函数不被标记为阻塞
  • [ ] 所有异步操作使用命令

模型与更新

  • - [ ] 模型不可变(Update返回新模型,不修改原模型)
  • [ ] Init返回正确的初始命令(或nil)
  • [ ] Update处理所有预期的消息类型
  • [ ] 处理WindowSizeMsg以实现响应式布局
  • [ ] 多个命令使用tea.Batch
  • [ ] 正确使用tea.Quit退出

视图与样式

  • - [ ] View是纯函数(无副作用)
  • [ ] Lipgloss样式定义一次,不在View中定义
  • [ ] 按键绑定使用key.Matches配合help.KeyMap

组件

  • - [ ] 子组件更新正确传播
  • [ ] Bubbles组件使用尺寸初始化
  • [ ] Huh表单通过Update循环嵌入(不使用Run())

关键模式

模型必须不可变

go
// 错误 - 修改模型
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.items = append(m.items, newItem) // 修改!
return m, nil
}

// 正确 - 返回新模型
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
newItems := make([]Item, len(m.items)+1)
copy(newItems, m.items)
newItems[len(m.items)] = newItem
m.items = newItems
return m, nil
}

异步/IO的命令

go
// 错误 - Update中阻塞
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
data, _ := os.ReadFile(config.json) // 阻塞UI!
m.config = parse(data)
return m, nil
}

// 正确 - 使用命令
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, loadConfigCmd()
}

func loadConfigCmd() tea.Cmd {
return func() tea.Msg {
data, err := os.ReadFile(config.json)
if err != nil {
return errMsg{err}
}
return configLoadedMsg{parse(data)}
}
}

样式定义一次

go
// 错误 - 每次渲染创建新样式
func (m Model) View() string {
style := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(205))
return style.Render(Hello)
}

// 正确 - 在包级别或模型中定义样式
var titleStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(205))

func (m Model) View() string {
return titleStyle.Render(Hello)
}

何时加载参考文档

审查问题

  1. 1. Update()是否没有阻塞I/O?(注意:不是cmd辅助函数是否阻塞?)
  2. Update中的模型是否不可变?
  3. Lipgloss样式是否定义一次,不在View中定义?
  4. 是否处理了WindowSizeMsg以实现调整大小?
  5. 按键绑定是否使用help.KeyMap记录?
  6. Bubbles组件尺寸是否正确?

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 bubbletea-code-review-1776097458 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 bubbletea-code-review-1776097458 技能

通过命令行安装

skillhub install bubbletea-code-review-1776097458

下载

⬇ 下载 bubbletea-code-review v2.3.0(免费)

文件大小: 15.9 KB | 发布时间: 2026-4-14 10:31

v2.3.0 最新 2026-4-14 10:31
- Added comprehensive skill documentation (SKILL.md) with patterns, reference links, and a detailed review checklist for BubbleTea TUI code reviews.
- Clarified critical patterns to avoid common false positives when reviewing Elm architecture, model/update/view patterns, and Lipgloss styling.
- Included tables distinguishing correct (NOT issues) and incorrect (DO flag) usage patterns.
- Provided code examples and targeted review questions to assist reviewers in identifying best practices.

Archiver·手机版·闲社网·闲社论坛·智能体自动化市场· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部