Skip to content

fix: add Status() health check and SilenceUsage for baidu-cli and google-cli#17

Merged
xpzouying merged 1 commit into
better-world-ai:mainfrom
RachelXiaolan:fix/cli-consistency-improvements
May 21, 2026
Merged

fix: add Status() health check and SilenceUsage for baidu-cli and google-cli#17
xpzouying merged 1 commit into
better-world-ai:mainfrom
RachelXiaolan:fix/cli-consistency-improvements

Conversation

@RachelXiaolan

Copy link
Copy Markdown
Contributor

Summary

Two consistency fixes for baidu-cli and google-cli. Timestamp changes are in a separate PR (#16).

This replaces #10 (closed due to branch re-creation after splitting out the timestamp changes).

Fix 1: baidu-cli missing SilenceUsage / SilenceErrors

All other CLIs (google-cli, nanobanana-cli, chatgpt-image-cli) set SilenceUsage = true and SilenceErrors = true on their cobra commands so that cobra doesn't print usage text alongside the structured JSON error output. baidu-cli was the only one missing these flags, causing it to print an extra Usage: block on every error.

Fix: Added SilenceUsage and SilenceErrors to baidu-cli's search command.

Fix 2: baidu-cli and google-cli missing Status() health check

nanobanana-cli and chatgpt-image-cli call client.Status() before operations to verify that the kimi-webbridge daemon is running and the Chrome extension is connected. This gives users friendly, actionable error messages like:

{"ok":false,"error":{"code":"daemon_not_running","message":"kimi-webbridge daemon is not running (open the Kimi Desktop App)"}}

baidu-cli and google-cli skipped this check entirely. When the daemon wasn't running, they produced a raw "daemon unreachable" error with no guidance on what to do.

Fix:

  • Added Status struct and Status() method to baidu-cli/browser/client.go and google-cli/browser/client.go (matching the existing implementation in nanobanana/chatgpt).
  • Added pre-flight health checks to: baidu-cli search, google-cli search, google-cli result.

Testing

All affected CLIs compile successfully:

cd baidu-cli && go build -o /dev/null .    # OK
cd google-cli && go build -o /dev/null .   # OK

…gle-cli

Bug 1: baidu-cli missing SilenceUsage / SilenceErrors
- All other CLIs set these flags so cobra doesn't print usage text
  on error, which would pollute the JSON output.
- baidu-cli was the only one missing it.

Bug 2: baidu-cli and google-cli missing Status() health check
- nanobanana-cli and chatgpt-image-cli call client.Status() before
  operations to check daemon + extension readiness, giving friendly
  error messages.
- baidu-cli and google-cli just jumped into operations, producing
  confusing errors with no guidance.
- Added Status struct and Status() method to both CLIs.
- Added pre-flight checks to baidu-cli search, google-cli search,
  and google-cli result commands.
@xpzouying

Copy link
Copy Markdown
Collaborator

PR Review — ✅ 高质量一致性 fix,可以合入

这个 PR 做了什么(我的理解)

把 baidu-cli 和 google-cli 拉齐到 nanobanana-cli / chatgpt-image-cli 已有的两个习惯:

  1. SilenceUsage / SilenceErrors(只 baidu-cli 缺)—— 让 cobra 不再在结构化 JSON 错误旁边打印 Usage:
  2. Status() pre-flight 健康检查 —— daemon 没起或扩展没连时给出可操作的错误码(daemon_not_running / extension_not_connected),代替原来神秘的 daemon unreachable

替换被关掉的 #10(拆出 timestamp 改动到 #16 后重建分支)。

Code review

做得好的地方

  • 完全对齐既有模板:新加的 Status struct 和 Status() 方法在 baidu-cli 和 google-cli 里逐字对齐 nanobanana-cli/chatgpt-image-cli。一致性是这个 PR 的核心价值。
  • 错误信息可操作"kimi-webbridge daemon is not running (open the Kimi Desktop App)" + "see https://www.kimi.com/features/webbridge" —— 用户一看就知道下一步做什么,不需要去翻文档
  • 错误码命名语义化daemon_unreachable / daemon_not_running / extension_not_connected)—— 上游 skill / agent 可以根据 code 字段做条件分支
  • 作用域克制:只动这一处一致性问题,其他不碰。fix: 该有的样子
  • PR 描述写得非常清楚:分点说明问题、引用对照 CLI、给出 go build 验证命令、并交代了与 fix: add Status() health check and SilenceUsage for baidu-cli and google-cli #10fix!: use millisecond-precision timestamps for output filenames #16 的关系

可选优化(不阻塞合入)

🟢 Nit 1:16 行 pre-flight 检查重复 3 次(baidu-cli/cmd/root.go、google-cli/cmd/search.go、google-cli/cmd/result.go)。后续可以考虑抽到 browser.Client 上,比如:

// browser/client.go
func (c *Client) RequireReady() error {
    st, err := c.Status()
    if err != nil { return fmt.Errorf("daemon_unreachable: %w", err) }
    if !st.Running { return errors.New("daemon_not_running") }
    if !st.ExtensionConnected { return errors.New("extension_not_connected") }
    return nil
}

然后调用点变成 3 行处理 if err := client.RequireReady(); err != nil { output.Error(...); os.Exit(1) }

不过现在的样子和 nanobanana / chatgpt-image 一致,本 PR 的目标是"对齐"而不是"提炼",所以这条建议属于跨 CLI 的后续重构,不应该让这个 PR 背。如果未来要做,建议是另开一个 PR,把 4 个 CLI 一起改。

🟢 Nit 2:Status struct 重复定义在两个 CLI。同理,这是已有模式 —— 现状 4 个 CLI 各自定义同样的 struct。属于 monorepo 共享包的优化空间,本 PR 不应处理。

🟢 Nit 3:body, _ := io.ReadAll(resp.Body) 丢弃了 ReadAll 的 error。本地 loopback 上几乎不会失败,且后续 json.Unmarshal 会兜住任何坏数据,所以实际无害。但如果想严谨可以显式忽略 _ = ... 或处理一下。

End-to-end 验证

通过 kimi-webbridge 真实 Chrome 会话跑:

Command 预期 实际 结论
baidu-cli search "claude code" --limit 3 3 条百度结果 + 健康检查在 daemon 健康时透传 Claude Code(编程助手) - 百度百科 / 百家号 / GitHub Issue#74,结构化 JSON 正常输出
google-cli search "kimi webbridge" --limit 3 3 条 Google 结果 + 健康检查在 daemon 健康时透传 WebBridge - Let Kimi Agent Drive Your Browser / Chrome Web Store / Help Center,结构化 JSON 正常输出

不健康路径(daemon down / extension disconnected)没有实际模拟(需要关掉用户的 WebBridge App,过于侵入),但代码路径明确、和 nanobanana/chatgpt 同款,无理由怀疑。

baidu-cli search "claude code" 浏览器渲染(与 CLI 返回的 3 条结果一一对应):

baidu.com 搜索 claude code 的结果页

google-cli search "kimi webbridge" 浏览器渲染(与 CLI 返回的 3 条结果一一对应):

google.com 搜索 kimi webbridge 的结果页

结论

Approve —— 0 blocker,3 个 🟢 nit 都是跨 CLI 的后续优化(不属于本 PR 范围)

这是个干净利落的一致性修复 PR,质量很高。可以合入。

After merge

合入后 @RachelXiaolan 已是常驻贡献者(在 .all-contributorsrc 里有 entry 的话),建议补一个 review 类型(因为她在 PR#9 也给了高质量 review),可以一并处理。说一句 update contributors for PR 17 就行。

@xpzouying xpzouying merged commit 4b6c2fc into better-world-ai:main May 21, 2026
xpzouying added a commit that referenced this pull request May 21, 2026
Recognizing @RachelXiaolan for code contributions (PR #17 — Status() health
check + SilenceUsage for baidu-cli/google-cli) and pull-request reviews
(detailed technical review on PR #9, plus follow-up PR #16).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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