Token Stats Reporter
Use this skill to produce a single, consistent token line at the end of every user-facing message.
Workflow
- 1. Run the bundled reporter script:
-
python3 /home/admin/.openclaw/workspace/skills/token-stats-reporter/scripts/token-show.py
- 2. Append exactly one returned line to the end of the reply.
- Do not modify numbers manually.
Output format (exact)
INLINECODE1
Algorithm guarantees (must preserve)
- - Data source: INLINECODE2
- Valid rows only:
-
type=message
-
message.role=assistant
- has text content
- has
usage
- - Deduplication: by
message.id (fallback composite key only if id missing) - Monthly bucket: by message timestamp in local timezone (
Asia/Shanghai) - Aggregation strategy: snapshot + incremental replay
- Persisted state file:
memory/token-agg-state.json
- Per-file offset tracking for incremental scans
- Truncation/reset-safe fallback (
offset reset when file shrinks)
- - Cost source: INLINECODE10
- Model source: latest valid message INLINECODE11
Reliability rules
- - Run token collection immediately before final delivery.
- In long, multi-step tasks, refresh once again right before sending.
- Keep exactly one token line per outgoing message.
- If script fails, fallback to
session_status and explicitly label as fallback.
v1.2.0 Send Gate (fail-closed)
Use this mandatory gate to avoid hand-written token lines:
- 1. Build token line first (must run script):
-
python3 /home/admin/.openclaw/workspace/skills/token-stats-reporter/scripts/token-show.py
- 2. Validate token line before sending:
- must contain
📊 Token:
- must contain
模型:
- model must NOT be
delivery-mirror
- 3. Append token line to message body, then send.
- If step 1 or 2 fails: block sending (do not handwrite numbers).
- Allowed fallback text only when blocked:
- INLINECODE17
Portability rule (for other assistants)
When installing on another assistant instance, use this skill's bundled script path as the source of truth. Do not depend on external ad-hoc scripts with unknown local modifications.
Token Stats Reporter
使用此技能在每条面向用户的消息末尾生成一条统一、一致的token统计行。
工作流程
- 1. 运行捆绑的报告脚本:
- python3 /home/admin/.openclaw/workspace/skills/token-stats-reporter/scripts/token-show.py
- 2. 将返回的一行内容精确追加到回复末尾。
- 请勿手动修改数字。
输出格式(精确)
📊 Token: in / out | cacheRead: | 本次总消耗: total> | 本次计费token: billable> | 本月: 次 | 月累计总消耗: total> | 本次费用: cost> | 本月费用: | 模型:
算法保证(必须保留)
- - 数据来源:~/.openclaw/agents/main/sessions/.jsonl
- 仅有效行:
- type=message
- message.role=assistant
- 包含文本内容
- 包含 usage
- - 去重:按 message.id(若id缺失则回退到复合键)
- 月度桶:按消息时间戳(本地时区 Asia/Shanghai)
- 聚合策略:快照 + 增量回放
- 持久化状态文件:memory/token-agg-state.json
- 每个文件的偏移量跟踪用于增量扫描
- 截断/重置安全回退(文件缩小时重置 offset)
- - 费用来源:usage.cost.total
- 模型来源:最新有效消息 message.model
可靠性规则
- - 在最终交付前立即运行token收集。
- 在长流程、多步骤任务中,在发送前再次刷新一次。
- 每条外发消息仅保留一行token统计。
- 如果脚本失败,回退到 session_status 并明确标记为回退。
v1.2.0 发送门控(故障关闭)
使用此强制性门控避免手写token统计行:
- 1. 首先生成token统计行(必须运行脚本):
- python3 /home/admin/.openclaw/workspace/skills/token-stats-reporter/scripts/token-show.py
- 2. 发送前验证token统计行:
- 必须包含 📊 Token:
- 必须包含 模型:
- 模型不能是 delivery-mirror
- 3. 将token统计行追加到消息正文,然后发送。
- 如果步骤1或2失败:阻止发送(请勿手写数字)。
- 仅在阻止时允许的回退文本:
- 📊 Token: 统计暂不可用(脚本失败,已拦截手填)
可移植性规则(适用于其他助手)
在另一个助手实例上安装时,请使用此技能捆绑的脚本路径作为权威来源。不要依赖外部临时脚本,这些脚本可能存在未知的本地修改。