[建议 / Feature] SSH 远程工作区的 token 消耗未计入「使用统计」面板,建议聚合远程工作区用量
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
提交前确认 · Pre-submission checklist
- 我已搜索过现有 issue,确认这不是重复提议 / I searched existing issues and confirmed this isn't a duplicate.
- 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
问题类别 · Category
计费 / 配额 · Billing / Quota
涉及的 Agent 框架 · Agent framework
ZCode Agent(自研)
使用场景 · Use case
通过 SSH 远程工作区功能连接到远程 Linux 服务器(ssh://user@host:22)开发项目时,
所有模型请求都在远程机器上执行,token 消耗也记录在远程机器的
~/.zcode/cli/db/db.sqlite(model_usage/turn_usage)中——数据本身是完整、正确的。
但「设置 → 使用统计」面板(App 级)只查询本地 host(local-1)的 usage-stats 通道,
聚合的是本地 CLI 的 session 库;远程 host 虽然也注册了 usage-stats 通道(转发到远程
agent 的 v4/usage/stats,查询远程库),前端却从未调用过它,也没有任何把远程
model_usage 同步回本地库的逻辑。
结果:远程项目消耗的 token 永远不出现在使用统计里,我无法审计/核对远程工作区的
真实用量。例如今天(08-12)远程库记录了 114 次调用、约 677 万 token,统计面板
只显示本地 59 次、约 321 万 token。
建议方案 · Proposal
在 App 级使用统计中纳入远程工作区的用量,任选其一(或组合):
- 聚合查询:usage-stats.getAppUsageSnapshot 时,除本地 host 外,同时遍历所有
已连接远程工作区的 host 通道(其 usage-stats 已转发到远程 agent 的
v4/usage/stats),按天/按项目合并后返回; - 增量同步:远程会话结束(或定期)时,将远程 CLI 库中的 model_usage/turn_usage
增量同步回本地 CLI 的 session 库(注意 id 冲突,并用 workspace 标识区分
remote:ssh:... 归属); - 兜底方案:至少在远程工作区视图内提供独立的用量面板(数据源直连远程 host),
设置页面板则明确标注「仅统计本地用量」。
另外建议在使用统计中展示每项的 workspace 归属(本地 / ssh:host:path),便于核对。
预期价值 · Expected value
用量可审计:用户能在一处看到本地 + 所有 SSH 远程工作区的真实 token 消耗,
核对成本从「逐台 SSH 查 sqlite」降为「打开统计面板」,每次核对约节省 5-10 分钟;
对按量计费/限额用户尤其重要,可避免远程用量被遗漏导致的预算失控。
你认为的优先级 · Your perceived priority
中 · Medium
你使用的 ZCode 版本 / 环境 · ZCode version / environment
ZCode 3.7.6 / Mac OS / model: deepseek-v4-flash
补充材料 · Additional context
证据链(已核实,v3.7.6):
- 远程用量确实有记录:远程机 ~/.zcode/cli/db/db.sqlite 的 model_usage 共 454 行
(main_turn 237 / subagent 212 / session_title 5),最后一条 2026-08-12 14:33:30,
今日 114 次调用、约 677 万 token;本地库仅本地会话(今日 59 次、约 321 万 token)。 - 统计面板只查本地 host:当日日志中 usage-stats.getAppUsageSnapshot 13 次、
getEntitlementSnapshot 18 次,全部由 local-1 应答;远程 host
(remote-workspace-ssh-172.16.50.51)的 usage-stats 通道收到 0 次调用,
只有一条 channel 注册日志。 - 架构:
本地 Mac: ZCode.app → zcode-host-local-1 → zcode-cli → 本地 db.sqlite
远程 Linux: zcode-server.cjs → zcode-cli → 远程 ~/.zcode/cli/db/db.sqlite
远程会话的模型请求全部在远程执行,用量只落远程库。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing usage-stats.getAppUsageSnapshot in the App usage statistics flow and the remote v4/usage/stats channel. Compare the local and remote model_usage/turn_usage data sources, then determine how connected SSH workspaces and workspace ownership should be represented. Done means remote usage is included or clearly surfaced without losing local totals or attribution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, sqlite
- Domain
- analytics, backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100