Skip to content

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

Closed
RachelXiaolan wants to merge 2 commits into
better-world-ai:mainfrom
RachelXiaolan:fix/cli-consistency-improvements
Closed

fix: add Status() health check and SilenceUsage for baidu-cli and google-cli#10
RachelXiaolan wants to merge 2 commits into
better-world-ai:mainfrom
RachelXiaolan:fix/cli-consistency-improvements

Conversation

@RachelXiaolan

@RachelXiaolan RachelXiaolan commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Two consistency fixes for baidu-cli and google-cli. Timestamp changes have been moved to a separate PR (#16).

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.

Changes from previous version

Testing

All affected CLIs compile successfully:

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

…amps

Bug 1: baidu-cli missing SilenceUsage/SilenceErrors
- All other CLIs (google, nanobanana, chatgpt) 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 like 'daemon not running' or 'extension not connected'.
- baidu-cli and google-cli just jumped into operations, producing
  confusing 'daemon unreachable' errors with no guidance.
- Added browser.Status struct and Status() method to both CLIs, matching
  the existing pattern from nanobanana/chatgpt.
- Added pre-flight checks to baidu-cli search, google-cli search, and
  google-cli result commands.

Bug 3: second-precision timestamps cause silent file overwrites
- nanobanana-cli and chatgpt-image-cli used time.Format("20060102-150405")
  (second precision) for output filenames.
- Two calls within the same second would silently overwrite the first file.
- Changed to "20060102-150405.000" (millisecond precision).
@xpzouying

Copy link
Copy Markdown
Collaborator

谢谢 @RachelXiaolan 的 PR!整体方向很好,都是不错的一致性改进。合入前有几个点想和你一起讨论一下:

想确认 / 调整的点

  1. baidu-cli 的 Navigate 签名可能不匹配。 当前 baidu-cli/browser/client.go 里的 Navigate(url string) 是一个参数,baidu/search.go:60 也是按一个参数调的。如果你这次新 client 把 Navigate 改成了 (url string, newTab bool)(对齐 chatgpt-image-cli / nanobanana-cli 的模式),那原本的调用点会编不过。麻烦在分支上跑一下 cd baidu-cli && go build ./... 确认一下 ✓

  2. 时间戳格式分隔符建议改一下。 "20060102-150405.000" 生成的文件名长这样:nanobanana-20260519-143022.123.png。中间那个 .123 看起来像个伪扩展名,可能会影响 shell glob 匹配,也容易让按时间戳解析文件名的下游脚本出问题。建议换成 -"20060102-150405-000"nanobanana-20260519-143022-123.png。另外这个改动其实只影响 chatgpt-image-cli / nanobanana-cli(写文件的两个 CLI),baidu-cli / google-cli 输出里没有时间戳——所以 PR 描述里"4 个 CLI 一致性"这个说法可以稍微调整一下。

  3. google-cli 的 SilenceUsage 其实已经有了——在 google-cli/cmd/search.go:19google-cli/cmd/result.go:17(两个子命令都设置了 SilenceUsage: trueSilenceErrors: true)。rebase 到最新 main 之后,diff 里这部分会自然消失,能更清楚地看到真正净新增的部分。

一个建议:拆成两个 PR

这个 PR 其实打包了三件正交的事:

  • Status() 健康检查(功能新增 + fail-fast 模式)
  • SilenceUsage(Cobra 配置一致性)
  • 毫秒精度时间戳(输出格式变更)

前两个是安全的一致性改进,可以保持在一起。第三个是文件名格式的破坏性变更,建议单独发一个 PR,描述里明确写上"breaking change"。这样万一有下游用户报告文件名问题,回滚也方便,review 也更快。

觉得做得好的地方

期待 v2!

The dot in '20060102-150405.000' looks like a file extension
(e.g. '20260519-143022.123-full.png'), which can confuse shell
glob patterns and downstream scripts. Changed to hyphen:
'20060102-150405-000' → '20260519-143022-123-full.png'.
@RachelXiaolan

Copy link
Copy Markdown
Contributor Author

感谢详细的 review!逐条回复:

1. Navigate 签名

确认过了,我没有改动 Navigate() 的签名——它仍然是 Navigate(url string) error,和 baidu/search.go 的调用一致。cd baidu-cli && go build ./... 编译通过 ✓

2. 时间戳分隔符

同意,已改为 - 分隔:"20060102-150405-000"20260519-143022-123-full.png。刚推上来了。

3. google-cli SilenceUsage

你说得对,google-cli 两个子命令已经设了 SilenceUsage。rebase 后 diff 会更干净。等时间戳 PR 拆出去后我会 rebase。

拆分 PR

同意你的建议。我准备:

  • 这个 PR 只保留 Status() 健康检查 + baidu-cli SilenceUsage(两个安全的一致性改进)
  • 时间戳改动单独开一个 PR,标注 breaking change

马上拆。

@RachelXiaolan RachelXiaolan deleted the fix/cli-consistency-improvements branch May 20, 2026 21:56
@RachelXiaolan RachelXiaolan changed the title fix: add Status() health check, SilenceUsage, and ms-precision timestamps fix: add Status() health check and SilenceUsage for baidu-cli and google-cli May 20, 2026
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