Skip to content

feat(mobile): 在任务菜单展示配额与用量摘要 - #3979

Merged
MagicLizi merged 7 commits into
mainfrom
dash/mobile-task-usage-summary
Sep 6, 2026
Merged

feat(mobile): 在任务菜单展示配额与用量摘要#3979
MagicLizi merged 7 commits into
mainfrom
dash/mobile-task-usage-summary

Conversation

@dashhuang

@dashhuang dashhuang commented Sep 5, 2026

Copy link
Copy Markdown
Member

这次改了什么

摘要

手机任务菜单打开后即可查看账号配额、任务价值/费用和上下文占用。摘要卡片统一作为「任务信息」入口,点击整卡进入详情,箭头位于整卡右侧居中,移除下方重复入口。

配额和任务价值复用现有远程查询。Codex 优先读取官方控制面,旧工作端按既有规则回退账号快照;同时保留通用配额和当前模型专属配额,专属行注明模型名称。ChatGPT bridge 仅在来源明确为 OpenAI 时读取 web 槽;明确的 Gateway 来源读取周期和今日用量;Pi/Claude Code 来源未解析时保持未知,不套用 Gateway 或 OpenAI web 账号。估算价值与实际费用分开呈现,不合并不同币种。

变更类型

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

范围

  • 关联 Issue / 需求:手机任务菜单补齐用量信息并统一任务信息入口。
  • 本 PR 包含:手机摘要与详情、已有接口的读取与兼容、五语文案、相关测试;共享合同只登记已有的历史估值查询。
  • 明确不包含:新增工作端接口、远程白名单放宽、Claude/xAI 订阅及个人余额远程能力扩展、原生配置与依赖变更。
  • 用户可见变化:一级菜单可直接读摘要;打开时刷新、可见期间每 30 秒重读,关闭后停止;断线保留成功快照并标注更新时间。
  • 是否存在 breaking change:无。未知配额不显示为零;账号级配额不冒充已确认的任务套餐。

UI 变化

  • 平台:React Native 手机任务菜单。最终版本尚无实机截图/录屏。
  • 引用的设计规范:docs/design-rules/DESIGN.md §2 Color Palette & Roles、§3 Typography Rules、§4 Cards & Containers、§5 Spacing System。复用 Light/Dark 的 sheet 语义颜色、字体与间距 token;整卡最小点击高度 44,箭头为装饰元素,无障碍名称为「任务信息」。

怎么验证的

自动验证

pnpm test:unit:related
pnpm test:unit(初始提交 f52fc4c,经 git skill 的 run-unit-gate.sh 执行)
pnpm --filter mobile run --if-present typecheck
pnpm --filter @cindy/maker-shared run --if-present typecheck
pnpm --filter mobile test:scope
pnpm check:i18n
pnpm check:i18n-glossary
git diff HEAD --check

相关检查通过。测试覆盖官方接口与旧快照回退、账号变化禁止旧数据兜底、模型桶选择、web/CLI 配额隔离、Gateway 币种、数据缺失、请求迟到、任务切换和断线保留。共享包没有独立 typecheck script,该步骤按命令约定跳过。

账号生命周期定向测试 8/8 通过;上下文归属与菜单入口测试 12/12 通过,覆盖运行配置切换、A→B→A 迟到回包、刷新失败与关闭,以及详情关闭后重开一级菜单不触发引擎读取。本次重跑根 pnpm test:unit:related 与 mobile typecheck 均通过。覆盖通用/模型配额同时呈现、未知来源、显式 OpenAI/Gateway、来源切换与迟到响应,以及未初始化上下文窗口回退、旧字段别名和实时零值优先。

早期双桶修复的相关门禁曾遇到未改动的 Pi 集成用例超时及紧随其后的断言失败;干净主干 47ef43edd 定向复核两项通过,完整相关门禁重跑一次后通过。未修改 Pi 源码或测试。

新增文件通过 Prettier 检查;10 份修改过的存量文件存在整文件格式提示,逐一核对主干 47ef43edd 也有相同问题,本 PR 保持周边格式,未做整文件重排。

手工验证

最终接口复用版本尚未完成手工验证,不将组件测试等同于 Light/Dark 实机目检。

未执行的验证

最终版本未重跑 iOS Simulator、Android 和真实远程配额端到端测试。目标分支为 dash/mobile-task-usage-summary;未取得最终版本的 Metro 归属和 build label 证据。

风险

风险分类

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

影响与回滚

  • 影响范围:手机任务菜单及其打开期间的只读请求。账号与估值独立成功/失败;effect 按设备、任务及运行配置划定归属,关闭或切换后忽略迟到结果,身份变化错误清除旧账号快照。
  • 兼容边界:工作端接口及白名单保持现状。旧端无法证明任务实际鉴权路由时显示账号级说明;无法读取的来源保持空态,SSH/自定义 provider 不套用本机其他账号配额。
  • 回滚/降级方式:回退本 PR 即恢复旧菜单;无数据库、凭证或持久配置迁移。

来源与上下文的不变量

账号读取只使用工作端下发的有效选择;未解析的来源不推断为 OpenAI web 或 Gateway。来源判据集中在 readSessionMenuAccountUsage;账号状态由既有 useSessionMenuUsage effect 写入,按设备/任务/运行配置隔离。

输入状态 读取与展示
SSH 不套用本机账号
本地 Codex 订阅控制可用 官方控制查询;既有错误规则允许时回退旧账号快照,始终注明账号级信息
Pi/Claude Code + chatgpt/* + 明确 openai 只读 OpenAI web 槽,不取 CLI 槽
明确 xd,或既有 Codex codex/* 网关命名空间 读取现有 Gateway 用量
未明确来源或其它来源 不从模型名称猜测账号,不请求无关账号配额
来源切换/关闭后旧响应返回 由原 effect 的取消标记丢弃,不能覆盖新来源;同一来源暂时失败保留旧快照并注明状态

上下文优先使用有效的实时计数;窗口必须有限且大于 0,未初始化值回退到详情快照的既有字段;计数允许真实 0。来源交错测试覆盖 OpenAI 请求未完成 → 未明确来源 → Gateway → 旧 OpenAI 响应返回 → 未明确来源;上下文测试覆盖未初始化 → 有效详情 → 实时零值。没有新增工作端接口或重试。

上下文快照归属收敛

上下文快照只属于当前设备、任务和运行配置,旧窗口不得与新运行配置的计数混算。缓存从页面收拢到菜单的 useSessionMenuContextUsage:同一个 effect 负责详情读取、loading、成功/失败和取消;移除页面缓存及 /context 命令对菜单缓存的旁路写入。命令卡片仍使用自己的原始查询结果。与账号摘要复用已有 scope 判据,账号控制和重置流程保持现状。

事件 × 状态 上下文行为
一级菜单/关闭状态 不发起上下文查询,不初始化引擎;仅使用当前归属的缓存或任务实时计数
进入详情/详情中手动刷新 调用既有上下文接口,同一归属刷新失败保留快照并结束 loading,不自动重试
详情打开时换模型、provider、agent、设备、任务、远端、清空时间或运行代次 立即隐藏旧快照并重新读取;成功写入新归属,失败保持未知
只更新实时计数 不重新查询,摘要采用有效实时值
A→B→A,或关闭后旧请求成功/失败 scope 生命周期身份不复用,旧 effect 取消;迟到回包不能改写快照、结束新 loading 或报告旧错误
关闭详情后重开一级菜单 视图在 effect 前恢复为一级菜单,不因残留 info 状态触发读取

这次收敛移除了跨入口共享缓存的责任混用,没有加入缓存基础设施、重试调度或新远程接口。交错测试同时覆盖迟到成功和失败,并保留现有未初始化窗口、旧字段别名及实时零值测试。

配额刷新不变量

父级继续拥有 Codex 控制快照和原有重置流程;摘要账号状态仍只有原读取 effect 写入。重置或控制刷新返回新快照时,摘要立即重读并使旧读取失效,不能等待轮询后才更新。

事件 摘要行为
重置返回额度快照,或无内嵌快照后读取完成 已有 codexRateLimits prop 更新,触发同一个 effect 重新读取
取消确认、普通失败且快照不变 不把操作当作成功,不额外触发快照刷新
失效 offer/身份变更触发控制快照清除或刷新 重新读取,沿用既有身份错误禁止旧账号回退的规则
重置前响应迟到/重复返回 原 effect 取消标记阻止覆盖新配额
关闭期间快照变化/切任务 关闭不读,打开再读;切任务沿用原 scope 隔离

测试覆盖“耗尽快照 → 旧读取挂起 → 重置后快照 → 新读取完成 → 旧读取迟到”,以及关闭期间变化、重新打开与相同快照不重复读取。未修改重置确认、幂等键或错误处理,没有新增状态或刷新调度器。

提交前检查

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

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
@dashhuang
dashhuang requested a review from a team as a code owner September 5, 2026 12:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 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-05T15:43:53.159572Z b2143c6 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 5, 2026

Copy link
Copy Markdown

Greptile Summary

此 PR 为手机端任务菜单增加账号配额、任务价值/费用和上下文占用摘要,并通过既有 Device Link 查询在菜单可见期间定时刷新。

  • 新增一级任务信息摘要卡和二级用量明细。
  • 复用 Codex、ChatGPT bridge、Gateway 账号用量及历史任务估值查询。
  • 增加五种语言文案以及读取、生命周期、展示和传输合同测试。
  • 当前 Codex 多桶投影只保留单个桶,可能隐藏仍会阻止任务运行的整体配额。

Confidence Score: 4/5

当前不建议直接合并,因为模型专属 Codex 配额可能遮蔽已耗尽的整体配额并向用户展示错误的可用状态。

配额读取把多桶数据缩减为单个模型匹配桶,而展示需求明确要求整体桶与模型专属桶共同呈现;需要先修正投影并增加覆盖真实读取链路的测试。

Files Needing Attention: apps/mobile/src/session/readSessionMenuAccountUsage.ts

Important Files Changed

Filename Overview
apps/mobile/src/session/readSessionMenuAccountUsage.ts 新增多来源账号用量投影,但模型专属 Codex 桶会替代而非补充通用配额桶。
apps/mobile/src/session/useSessionMenuUsage.ts 新增按设备、任务和运行配置划分的读取、轮询、失败保留及迟到结果隔离。
apps/mobile/src/session/SessionUsageSummary.tsx 新增摘要与明细卡片;展示层支持多个配额窗口,但依赖读取层提供完整窗口集合。
apps/mobile/src/session/SessionMenuSheet.tsx 将新摘要卡接入一级菜单和任务信息详情,并统一刷新入口。
apps/mobile/src/device-link/mobileMakerTransport.ts 在移动传输层登记并调用已有的会话估值远程查询。
packages/maker-shared/src/deviceLinkContract.ts 将已有历史估值查询加入移动端允许调用的共享通道集合。

Sequence Diagram

sequenceDiagram
  participant U as 手机任务菜单
  participant H as useSessionMenuUsage
  participant T as Device Link
  participant D as 桌面端
  participant DB as 本地数据库
  U->>H: 打开菜单
  par 读取账号配额
    H->>T: getCodexRateLimits / getAccountUsage
    T->>D: 远程调用
    D-->>T: 配额桶或账号快照
    T-->>H: 账号用量
  and 读取任务估值
    H->>T: getSessionEstimatedValue(sessionId)
    T->>D: 历史估值查询
    D->>DB: 汇总估算轮次
    DB-->>D: 估值金额
    D-->>H: 任务估值
  end
  H-->>U: 展示配额、价值/费用和上下文
  loop 菜单可见期间每 30 秒
    H->>T: 重新读取
  end
Loading
Prompt To Fix All With AI
### Issue 1
apps/mobile/src/session/readSessionMenuAccountUsage.ts:160-167
**隐藏整体配额**

当账号同时存在通用配额桶和当前模型的专属配额桶时,`selectCodexUsageForModel` 只返回一个桶,后续也只读取该桶的窗口。例如通用周限额已经耗尽、Spark 专属限额仍剩 80% 时,菜单只会展示后者,让用户误以为任务仍可继续。这里需要同时保留通用桶和匹配当前模型的专属桶;现有组件测试虽然覆盖了两类窗口的展示,但没有经过这条实际读取路径。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "feat(mobile): 在任务菜单展示配额与用量摘要" | Re-trigger Greptile

Comment thread apps/mobile/src/session/readSessionMenuAccountUsage.ts Outdated
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: 0892ddf9d1

ℹ️ 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/mobile/src/session/SessionUsageSummary.tsx Outdated
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: 4638250eb0

ℹ️ 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/mobile/src/session/readSessionMenuAccountUsage.ts Outdated
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: c4cc4ea2af

ℹ️ 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/mobile/src/session/readSessionMenuAccountUsage.ts
Comment thread apps/mobile/src/session/SessionUsageSummary.tsx Outdated
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: abecd1df41

ℹ️ 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/mobile/src/session/SessionMenuSheet.tsx
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: fe64245c08

ℹ️ 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/mobile/src/session/SessionUsageSummary.tsx
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
@MagicLizi MagicLizi added touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示) touches:large-diff 改动量较大(review-pr 自动维护,仅展示) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示) labels Sep 6, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

命中 UI 路径(apps/mobile/app/sessions/[sessionId].tsx / apps/mobile/src/device-link/mobileMakerTransport.ts / apps/mobile/src/session/SessionMenuSheet.tsx 等)但 description 未附界面效果证据——建议补充改动后效果:截图/录屏,或改动后界面的 HTML 页面(```html 代码块、.html 附件或在线预览链接),便于确认界面符合 DESIGN.md 设计规范

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

代码重审通过:任务菜单配额/用量只走已有 local-db 通道,未知渠道不会编造 OpenAI/Gateway。当前 head 没有 P0/P1。

@MagicLizi
MagicLizi merged commit a5e724d into main Sep 6, 2026
19 checks passed
@MagicLizi
MagicLizi deleted the dash/mobile-task-usage-summary branch September 6, 2026 04:15
@MagicLizi

Copy link
Copy Markdown
Contributor

合了。手机任务菜单终于能看见配额和用量,还不会拿错账号的数。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示) touches:large-diff 改动量较大(review-pr 自动维护,仅展示) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants