lov-codex-thread-usage
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCodex 用量账本 · Codex Usage Ledger
Codex 用量账本 · Codex Usage Ledger
把一个本地 Codex deeplink 解析成 thread ID,以只读方式检查 SQLite 快照和
rollout JSONL,给出整个线程、最新计数段和 token 类型的可核验统计。
把一个本地 Codex deeplink 解析成 thread ID,以只读方式检查 SQLite 快照和
rollout JSONL,给出整个线程、最新计数段和 token 类型的可核验统计。
Triggers
触发条件
Activate when
激活条件
- 用户说“查这个 Codex 任务消耗”“这个 deeplink 用了多少 token”或“统计 thread tokens”。
- The user asks to “inspect Codex thread usage” or “calculate tokens for this Codex deeplink”.
- 输入是 或 Codex thread UUID,并要求 token 明细或统计口径。
codex://threads/<uuid>
- 用户说“查这个 Codex 任务消耗”“这个 deeplink 用了多少 token”或“统计 thread tokens”。
- 用户要求“检查 Codex 线程用量”或“计算这个 Codex deeplink 的 token 数”。
- 输入是 或 Codex thread UUID,并要求 token 明细或统计口径。
codex://threads/<uuid>
Do not activate when
不应激活的情况
- 用户询问账户订阅额度、五小时/周限额或 reset credits;这些是账户 rate limit,不是单线程 token 统计。
- 用户要求估算 API 账单金额;本 Skill 不内置会变化的模型价格,也不把 cached token 当作免费 token。
- 用户只想打开或导航到 deeplink;应使用宿主的任务导航能力。
- 用户询问账户订阅额度、五小时/周限额或 reset credits;这些是账户 rate limit,不是单线程 token 统计。
- 用户要求估算 API 账单金额;本 Skill 不内置会变化的模型价格,也不把 cached token 当作免费 token。
- 用户只想打开或导航到 deeplink;应使用宿主的任务导航能力。
User Profile (cross-session)
用户配置(跨会话)
Read on every run and resolve the shared context.
Current request and explicit flags take precedence over Skill records and shared
preferences. Persist only direct durable user statements through
; never persist thread IDs, transcripts, credentials,
or inferred private paths.
skill.yamluser-profile/v1scripts/profile_store.py每次运行时都要读取 ,并解析共享的 上下文。
当前请求和显式参数优先于 Skill 记录和共享偏好。仅通过
持久保存用户直接且持久有效的陈述;绝不持久保存
thread ID、对话记录、凭据或推断出的私有路径。
skill.yamluser-profile/v1scripts/profile_store.pySkill Group Composition
Skill 组构成
Read before composing adjacent capabilities.
This Skill owns the local deeplink-to-usage result and has no required sibling
Skill dependency.
references/skill-composition.md组合相邻能力前,读取 。
本 Skill 负责生成本地 deeplink 到用量统计的结果,无必需的同级 Skill 依赖。
references/skill-composition.mdWorkflow (MANDATORY)
工作流(必须执行)
Step 0: Resolve runtime
第 0 步:解析运行环境
- Resolve from the active Skill context.
SKILL_DIR - Read ,
skill.yaml, andreferences/token-semantics.mdcompletely.references/skill-composition.md - Confirm Python 3.9+ and are available.
scripts/codex_thread_usage.py
- 从当前 Skill 上下文解析 。
SKILL_DIR - 完整读取 、
skill.yaml和references/token-semantics.md。references/skill-composition.md - 确认 Python 3.9+ 和 可用。
scripts/codex_thread_usage.py
Step 1: Restate the requested metric
第 1 步:重述所请求的指标
Distinguish these values before reporting:
- : processed input plus output across all detected monotonic counter segments in the rollout.
historical.total_tokens - : the most recent SQLite cumulative snapshot; it can reset after resume or a new Codex process.
state_snapshot.tokens_used - : a subset of input, not an additional quantity.
cached_input_tokens - : a subset of output, not an additional quantity.
reasoning_output_tokens - : non-cached input plus output; useful for parity with the Codex TUI display, but not a billing estimate.
tui_style_total_tokens
报告前区分以下数值:
- :rollout 中所有检测到的单调递增计数段的已处理输入 token 与输出 token 之和。
historical.total_tokens - :最新的 SQLite 累计快照; 它可能在恢复会话或启动新的 Codex 进程后重置。
state_snapshot.tokens_used - :输入 token 的子集,不是额外数量。
cached_input_tokens - :输出 token 的子集,不是额外数量。
reasoning_output_tokens - :非缓存输入 token 与输出 token 之和;适用于与 Codex TUI 显示结果对齐,但不能作为计费估算。
tui_style_total_tokens
Step 2: Run the deterministic inspector
第 2 步:运行确定性检查器
Text report:
bash
python3 "$SKILL_DIR/scripts/codex_thread_usage.py" \
'codex://threads/<uuid>' --detailsMachine-readable report:
bash
python3 "$SKILL_DIR/scripts/codex_thread_usage.py" \
'<thread-uuid>' --jsonUse only when the user explicitly supplies a
non-default Codex data directory. The script reads message envelopes and token
fields but never emits message bodies.
--codex-home <directory>文本报告:
bash
python3 "$SKILL_DIR/scripts/codex_thread_usage.py" \
'codex://threads/<uuid>' --details机器可读报告:
bash
python3 "$SKILL_DIR/scripts/codex_thread_usage.py" \
'<thread-uuid>' --json仅当用户明确提供非默认 Codex 数据目录时,才使用 。
脚本会读取消息信封和 token 字段,但绝不会输出消息正文。
--codex-home <directory>Step 3: Evaluate evidence and boundaries
第 3 步:评估证据与边界
- Verify the rollout matches the deeplink UUID.
session_meta.payload.id - Compare with the last segment total.
state_snapshot.tokens_used - If there is more than one segment, explain that the SQLite value is only the latest counter, while the historical value sums segment terminals.
- If is nonzero, label the total as accumulated or estimated rather than exact billing usage.
estimated_segments - If is nonzero, report it separately; it is exact per event but may be incomplete for older or provider-specific runs.
raw_response_completed.events
- 验证 rollout 的 是否与 deeplink UUID 匹配。
session_meta.payload.id - 将 与最后一个计数段的总量进行比较。
state_snapshot.tokens_used - 如果存在多个计数段,说明 SQLite 值仅代表最新计数器,而历史值是各计数段终值的总和。
- 如果 不为零,应将总量标记为累计值或估算值,而不是精确计费用量。
estimated_segments - 如果 不为零,应单独报告;它对每个事件而言都是精确值, 但对于较旧或特定提供商的运行可能并不完整。
raw_response_completed.events
Step 4: Answer concisely
第 4 步:简洁回答
Lead with historical processed tokens, then show input, cached input, output,
reasoning output, the latest SQLite snapshot, segment/reset count, and quality.
Never add cached or reasoning subsets to . Do not infer money or
subscription quota from these fields.
total_tokens首先给出历史已处理 token 总量,然后依次展示输入、缓存输入、输出、
推理输出、最新 SQLite 快照、计数段/重置次数和数据质量。
绝不将缓存或推理子集加到 中。也不根据这些字段推断金额或
订阅配额。
total_tokensValidation
验证
bash
PYTHONDONTWRITEBYTECODE=1 python3 "$SKILL_DIR/scripts/test_codex_thread_usage.py"
python3 "$SKILL_DIR/scripts/validate_skill.py" "$SKILL_DIR"The documented activation phrase must route here; “查看 Codex 账户剩余额度”
must remain outside this Skill.
bash
PYTHONDONTWRITEBYTECODE=1 python3 "$SKILL_DIR/scripts/test_codex_thread_usage.py"
python3 "$SKILL_DIR/scripts/validate_skill.py" "$SKILL_DIR"文档中记录的激活短语必须路由至此;“查看 Codex 账户剩余额度”
必须仍位于本 Skill 的适用范围之外。
Dependencies
依赖项
- Python 3.9+ standard library only.
- Read access to the local Codex data directory.
- No credentials, network access, , or SQLite CLI required at runtime.
jq
- 仅需 Python 3.9+ 标准库。
- 需要对本地 Codex 数据目录的读取权限。
- 运行时不需要凭据、网络访问、或 SQLite CLI。
jq