Skip to content

feat(desktop): 优化用量历史时间筛选与热力图 - #3802

Open
dashhuang wants to merge 12 commits into
mainfrom
cindy/thoughtful-torvalds
Open

feat(desktop): 优化用量历史时间筛选与热力图#3802
dashhuang wants to merge 12 commits into
mainfrom
cindy/thoughtful-torvalds

Conversation

@dashhuang

Copy link
Copy Markdown
Member

这次改了什么

摘要

为 Desktop 用量历史增加可切换的时间范围,并支持从活跃热力图与每日 Token 图直接选中某一天查看明细;同时扩展热力图的历史展示宽度与数据范围。

变更类型

  • feat 新功能
  • fix 缺陷修复
  • refactor / perf 重构或性能优化
  • docs / test / chore 文档、测试或工程维护
  • 其他:

范围

  • 关联 Issue / 需求:无(来自用量历史产品需求)
  • 本 PR 包含:
    • 顶部时间筛选:所有时间、最近 30 天、最近 7 天、今天,以及选中日期。
    • 热力图和每日 Token 柱状图按日期点击后联动到当天数据。
    • 其他统计卡片、Agent/模型明细表按所选范围更新。
    • 热力图至少显示 20 周;有更早数据时按可用宽度扩展,并修复月份标签换行。
    • 增补历史用量 IPC、状态派生和相关测试覆盖。
  • 明确不包含:聊天记录导入或聊天内容展示。
  • 用户可见变化:用量历史可以按范围和单日钻取,历史热力图更充分利用横向空间。
  • 是否存在 breaking change:无。

UI 变化

  • 引用的设计规范:docs/design-rules/DESIGN.md 的双模式交付门槛、语义 Token、布局与交互规范;新增控件和图表交互均复用现有语义 Token,并同时适配 Light/Dark。

怎么验证的

自动验证

bash /Users/dash/Code/XD/dash/Skills/git/scripts/run-unit-gate.sh /Users/dash/Code/Cindy/cindy/.cindy-worktrees/thoughtful-torvalds
结果:通过;apps/desktop、apps/mobile 及相关 packages unit 全部 PASS。

pnpm --filter desktop run --if-present typecheck
结果:通过。

pnpm check:design-inventory
结果:通过;34 个 surface 的 GENERATED 区块已同步。

pnpm check:dco
结果:通过;2 个 commit 均带 DCO 签名。

手工验证

在 macOS Desktop 开发版的设置 → 用量历史中验证时间范围筛选、热力图日期点击、每日 Token 日期点击、单日筛选标签及明细联动。

未执行的验证

无。

风险

风险分类

  • 无已知风险
  • SQLite / migration
  • system prompt
  • 协议兼容
  • 权限 / 安全 / 用户数据
  • 存量插件兼容(批准状态 / 指纹 / manifest 校验 / 安装布局 / 包格式)
  • 原生层 / fingerprint / OTA
  • 跨平台差异
  • 其他:

影响与回滚

  • 影响范围:仅 Desktop 用量历史展示与读取参数;不改变数据库 schema、聊天数据或计费记录。
  • 回滚 / 降级方式:回滚本 PR 的两个 commit 即可恢复原有用量历史展示。

提交前检查

  • 已 review 完整 diff
  • 每个 commit 都带 DCO 签名(git commit -s,见 DCO
  • UI 改动已在「UI 变化」注明引用的设计规范章节
  • 未提交凭证、令牌或授权文件
  • 已补充必要文档
  • 已确认测试结果或说明未执行原因

@dashhuang
dashhuang requested a review from a team as a code owner September 2, 2026 09:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-02T14:27:46.944453Z cabf424 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown

Greptile Summary

此 PR 为 Desktop 用量历史新增所有时间、近 30 天、近 7 天、今天及单日筛选,并让热力图和每日 Token 图支持日期下钻。

  • 扩展 main、preload 与 renderer 之间的历史查询参数,支持独立的用量与模型聚合窗口
  • 在 renderer 中按选定范围重新派生概览、Agent、模型和任务数据
  • 将热力图改为至少 20 周并按可用宽度扩展,同时增加图表日期选择状态
  • 补充多语言文案、类型声明与相关单元测试

Confidence Score: 5/5

未发现需要阻止合并的具体问题,此 PR 看起来可以安全合并。

查询窗口在 main、preload 和 renderer 之间保持一致,范围派生、账户作用域缓存、日期交互和旧快照兼容路径均未发现可达的错误行为。

Important Files Changed

Filename Overview
apps/desktop/src/main/usage/usageHistory.ts 增加独立的 days/modelDays 窗口、全量查询支持及 modelDaily token 分项,未发现可发布的正确性问题。
apps/desktop/src/renderer/hooks/useUsageHistory.ts 按用户与查询窗口隔离缓存、请求和刷新订阅,并保留账户切换时的迟到结果防护。
apps/desktop/src/renderer/components/settings/usage/usageHistoryStats.ts 新增范围判断、单日选择和客户端重聚合,并兼容旧快照缺少 token 分项的情况。
apps/desktop/src/renderer/components/settings/usage/UsageHistorySection.tsx 接入范围选择器、日期下钻以及按范围派生的概览和明细数据。
apps/desktop/src/renderer/components/new-chat/UsageHeatmap.tsx 热力图改为自适应周数、可滚动布局和可访问的日期按钮,并保持未来占位不可交互。
apps/desktop/src/renderer/components/settings/usage/UsageTaskTable.tsx 任务列表改为按照选定本地日历范围筛选,同时继续按会话累计 token 排序。

Sequence Diagram

sequenceDiagram
    participant U as 用户
    participant UI as 用量历史界面
    participant H as useUsageHistory
    participant P as Preload / IPC
    participant M as Main 用量聚合
    U->>UI: 打开用量历史
    UI->>H: "请求 days=all, modelDays=all"
    H->>P: getHistory(options)
    P->>M: maker:usage:history
    M-->>P: 全量 days 与 modelDaily
    P-->>H: UsageHistoryPayload
    H-->>UI: 缓存并发布历史数据
    U->>UI: 选择范围或点击日期
    UI->>UI: 过滤并重新聚合统计与明细
    UI-->>U: 展示所选范围结果
Loading

Reviews (1): Last reviewed commit: "chore(design): refresh usage history sur..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2eeb0d098

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/renderer/components/new-chat/UsageHeatmap.tsx
Comment thread apps/desktop/src/renderer/components/new-chat/UsageHeatmap.tsx
Comment thread apps/desktop/src/renderer/components/settings/usage/UsageTaskTable.tsx Outdated
@MagicLizi

Copy link
Copy Markdown
Contributor

@dashhuang 👋 这个 PR 还有 3 条 review conversation 没 resolve(apps/desktop/src/renderer/components/new-chat/UsageHeatmap.tsx / apps/desktop/src/renderer/components/settings/usage/UsageTaskTable.tsx),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

@MagicLizi MagicLizi added status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示) touches:rules 改动碰到规则 / 规范文档(review-pr 自动维护,仅展示) and removed status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) labels Sep 2, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 980221e259

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/main/usage/usageHistory.ts Outdated
@MagicLizi

Copy link
Copy Markdown
Contributor

命中 UI 路径(apps/desktop/src/renderer/components/new-chat/UsageHeatmap.tsx / apps/desktop/src/renderer/components/settings/usage/UsageBreakdownTables.tsx / apps/desktop/src/renderer/components/settings/usage/UsageHistorySection.tsx 等)但 description 未附界面效果证据——建议补充改动后效果:截图/录屏,或改动后界面的 HTML 页面(```html 代码块、.html 附件或在线预览链接),便于确认界面符合 DESIGN.md 设计规范

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb707b07b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/main/localDb/ipc/sessions.ts
Comment thread apps/desktop/src/renderer/components/settings/usage/UsageTaskTable.tsx Outdated
Comment thread apps/desktop/src/renderer/components/new-chat/UsageHeatmap.tsx Outdated
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
@dashhuang
dashhuang force-pushed the cindy/thoughtful-torvalds branch from bb707b0 to 217ee8e Compare September 2, 2026 11:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 217ee8e832

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/main/maker-ipc/usageHandlers.ts Outdated
@MagicLizi MagicLizi added the status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) label Sep 2, 2026
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9397e9a44b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/renderer/components/settings/usage/UsageTaskTable.tsx Outdated
Comment thread apps/desktop/src/renderer/components/new-chat/UsageHeatmap.tsx
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
@MagicLizi MagicLizi removed the status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) label Sep 2, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e870511e79

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/renderer/components/settings/usage/UsageHistorySection.tsx Outdated
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
@MagicLizi MagicLizi added the status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) label Sep 2, 2026
…alds

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

# Conflicts:
#	docs/design-rules/design-inventory.md

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ce4ded2f9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/renderer/components/settings/usage/UsageTaskTable.tsx Outdated
@MagicLizi

Copy link
Copy Markdown
Contributor

@dashhuang 👋 这个 PR 还有 1 条 review conversation 没 resolve(apps/desktop/src/renderer/components/settings/usage/UsageTaskTable.tsx),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cabf4245d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +107 to +109
<th className={TH_CLASS}>
{todayLabel ?? t('usageHistory.byAgent.col.today')}
</th>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 在单日范围隐藏重复的 Agent 今日列

当范围为 todayday:* 时,filterUsageHistoryPayload 已将 modelDaily 限定为同一天,并把 todayKey 设为该日,因此 buildAgentRows 生成的 row.tokensrow.todayTokens 完全相同;这里仍同时渲染“Tokens (Today/日期)”和 Today/日期两列,导致每个 Agent 的同一数值重复出现。概览卡对单日重复项的隐藏没有覆盖这张表,应在单日范围隐藏今日列,或让两列保持不同语义。

Useful? React with 👍 / 👎.

Comment on lines +138 to +142
const sessions = useMemo(() => {
if (!usageSessions) return recentSessions;
const byId = new Map(usageSessions.map((session) => [session.id, session]));
// 当前列表快照包含最近的实时 token/status patch,优先覆盖全量查询的旧行。
for (const session of recentSessions) byId.set(session.id, session);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 全量查询就绪前不要展示截断的任务排名

当用户有超过 1000 个任务且专用 IPC 尚未返回或读取失败时,这里仍以 recentSessions 作为候选;失败分支将状态设为 [] 后又在下面无条件把 recentSessions 合回,所以页面会先短暂、失败时永久显示侧栏 1000 条窗口内的 Top 8,却仍标成所选范围的完整排名。此前“完整候选集”评论之后的新证据是当前 head 的 catch → [] 与这段 fallback/merge 路径;全量结果未知时应保持加载或隐藏卡片,失败时显示错误,而不是回退到截断候选。

Useful? React with 👍 / 👎.

@MagicLizi

Copy link
Copy Markdown
Contributor

@dashhuang 👋 这个 PR 还有 2 条 review conversation 没 resolve(apps/desktop/src/renderer/components/settings/usage/UsageBreakdownTables.tsx / apps/desktop/src/renderer/components/settings/usage/UsageTaskTable.tsx),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

@MagicLizi MagicLizi added status:ci-failed CI 失败(review-pr 自动维护,仅展示) and removed status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:ci-failed CI 失败(review-pr 自动维护,仅展示) touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示) touches:rules 改动碰到规则 / 规范文档(review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants