Skip to content

feat: 状态栏支持 refreshInterval 定时刷新#423

Merged
claude-code-best merged 1 commit intoclaude-code-best:mainfrom
znygugeyx-ctrl:feat/statusline-refresh-interval
May 6, 2026
Merged

feat: 状态栏支持 refreshInterval 定时刷新#423
claude-code-best merged 1 commit intoclaude-code-best:mainfrom
znygugeyx-ctrl:feat/statusline-refresh-interval

Conversation

@znygugeyx-ctrl
Copy link
Copy Markdown
Contributor

@znygugeyx-ctrl znygugeyx-ctrl commented May 6, 2026

Summary

  • Zod schema 补齐 statusLine.refreshInterval 字段(反编译版缺失,导致 settings.json 里写这个字段被静默忽略)
  • StatusLine.tsx 新增 Time-driven useEffect,经 scheduleUpdate 复用 300ms debounce,event/settings/time 三路触发单飞
  • 新增 docs/features/status-line.mdx 深度调研文档:渲染管线、Input/Output 协议、三种触发源、安全网关、已知缺口与本次修复

Background

settings.json"refreshInterval": 1 在本仓库原本静默失效——Zod schema 没声明这个字段,StatusLine.tsx 也没有 setInterval。现象:TTL/时钟类状态栏脚本只在新助手回复出现时才重算,秒级倒计时永远卡住。

Changes

src/utils/settings/types.ts — statusLine schema 增加 refreshInterval: z.number().optional()

src/components/StatusLine.tsx — 新增定时器 effect:

```tsx
const refreshIntervalMs = (settings?.statusLine?.refreshInterval ?? 0) * 1000;
useEffect(() => {
if (refreshIntervalMs <= 0) return;
const id = setInterval(() => scheduleUpdate(), refreshIntervalMs);
return () => clearInterval(id);
}, [refreshIntervalMs, scheduleUpdate]);
```

设计要点:

  • scheduleUpdate(非 doUpdate)复用已有 300ms debounce,interval + event 双触发不会双跑
  • refreshIntervalMs <= 0 时不启定时器,对未启用该字段的用户零开销
  • 依赖数组含 refreshIntervalMs,settings 热重载会自动清理旧 interval 重建新的
  • doUpdate 内部的 AbortController 保证 single-flight:上一次 shell 没跑完,新 tick 会 abort 它,不会堆积

docs/features/status-line.mdx — 完整调研文档,含整体管线图、Input 字段表、Output 协议、三种触发源对比、安全网关三层拦截、自定义脚本 8 条要点、示例(Cache 命中率 + TTL 倒计时)、已知缺口对比表。

Test plan

  • bun run precheck 通过(typecheck + lint + 4076 tests pass;1 个 flaky 集成测试独立重跑通过)
  • 本地 bun run dev 验证 refreshInterval: 1 时 TTL 秒级倒计时正确显示
  • 未配置 refreshInterval 时无新定时器创建(代码路径 early return)

View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

Summary by CodeRabbit

  • New Features

    • StatusLine component now supports periodic refresh based on a configurable time interval setting.
  • Documentation

    • Comprehensive expansion of StatusLine documentation covering configuration, rendering pipeline, triggering mechanisms, custom script guidance, and troubleshooting details.

- Zod schema 补齐 refreshInterval 字段
- 通过 scheduleUpdate 复用 300ms debounce,event/settings/time 三路触发单飞
- 新增 docs/features/status-line.mdx 调研文档
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

This PR adds time-driven refresh capability to StatusLine. A new optional refreshInterval field is added to the settings schema, a useEffect hook in the StatusLine component establishes a periodic timer to trigger updates at that interval, and comprehensive documentation describes the feature alongside patch notes.

Changes

StatusLine Time-Driven Refresh

Layer / File(s) Summary
Data Shape
src/utils/settings/types.ts
statusLine config in SettingsSchema gains an optional refreshInterval?: number field for controlling update frequency in seconds.
Core Implementation
src/components/StatusLine.tsx
New useEffect hook sets up a periodic timer based on settings.statusLine.refreshInterval to call scheduleUpdate, with cleanup on unmount or interval change.
Documentation
docs/features/status-line.mdx
Comprehensive feature documentation added covering rendering pipeline, input/output protocols, three triggering sources (event, settings, time), debounce/abort behavior, security gates, rendering details, built-in slash command, custom script guidance, cache TTL example, and 2026-05-06 patch notes documenting the refreshInterval field and time-driven trigger.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes


🐰 A timer ticks, the status line glows bright,
Time-driven updates, now refreshing right!
With intervals set, no more stale display—
The rabbit hops faster each tick of the day! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title in Chinese accurately describes the main feature: StatusLine component now supports refreshInterval for periodic/timed refresh, which matches the primary changes across all three modified files (settings type, component logic, and documentation).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@znygugeyx-ctrl
Copy link
Copy Markdown
Contributor Author

修复前:无法定时刷新

修复后效果如下:

stateline.mov

@claude-code-best claude-code-best merged commit c7efac6 into claude-code-best:main May 6, 2026
3 checks passed
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.

3 participants