lov-codex-thread-usage

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Codex 用量账本 · 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://threads/<uuid>
    或 Codex thread UUID,并要求 token 明细或统计口径。
  • 用户说“查这个 Codex 任务消耗”“这个 deeplink 用了多少 token”或“统计 thread tokens”。
  • 用户要求“检查 Codex 线程用量”或“计算这个 Codex deeplink 的 token 数”。
  • 输入是
    codex://threads/<uuid>
    或 Codex thread UUID,并要求 token 明细或统计口径。

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
skill.yaml
on every run and resolve the shared
user-profile/v1
context. Current request and explicit flags take precedence over Skill records and shared preferences. Persist only direct durable user statements through
scripts/profile_store.py
; never persist thread IDs, transcripts, credentials, or inferred private paths.
每次运行时都要读取
skill.yaml
,并解析共享的
user-profile/v1
上下文。 当前请求和显式参数优先于 Skill 记录和共享偏好。仅通过
scripts/profile_store.py
持久保存用户直接且持久有效的陈述;绝不持久保存 thread ID、对话记录、凭据或推断出的私有路径。

Skill Group Composition

Skill 组构成

Read
references/skill-composition.md
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 依赖。

Workflow (MANDATORY)

工作流(必须执行)

Step 0: Resolve runtime

第 0 步:解析运行环境

  1. Resolve
    SKILL_DIR
    from the active Skill context.
  2. Read
    skill.yaml
    ,
    references/token-semantics.md
    , and
    references/skill-composition.md
    completely.
  3. Confirm Python 3.9+ and
    scripts/codex_thread_usage.py
    are available.
  1. 从当前 Skill 上下文解析
    SKILL_DIR
    。
  2. 完整读取
    skill.yaml
    、
    references/token-semantics.md
    和
    references/skill-composition.md
    。
  3. 确认 Python 3.9+ 和
    scripts/codex_thread_usage.py
    可用。

Step 1: Restate the requested metric

第 1 步:重述所请求的指标

Distinguish these values before reporting:
  • historical.total_tokens
    : processed input plus output across all detected monotonic counter segments in the rollout.
  • state_snapshot.tokens_used
    : the most recent SQLite cumulative snapshot; it can reset after resume or a new Codex process.
  • cached_input_tokens
    : a subset of input, not an additional quantity.
  • reasoning_output_tokens
    : a subset of output, not an additional quantity.
  • tui_style_total_tokens
    : non-cached input plus output; useful for parity with the Codex TUI display, but not a billing estimate.
报告前区分以下数值:
  • historical.total_tokens
    :rollout 中所有检测到的单调递增计数段的已处理输入 token 与输出 token 之和。
  • state_snapshot.tokens_used
    :最新的 SQLite 累计快照; 它可能在恢复会话或启动新的 Codex 进程后重置。
  • cached_input_tokens
    :输入 token 的子集,不是额外数量。
  • reasoning_output_tokens
    :输出 token 的子集,不是额外数量。
  • tui_style_total_tokens
    :非缓存输入 token 与输出 token 之和;适用于与 Codex TUI 显示结果对齐,但不能作为计费估算。

Step 2: Run the deterministic inspector

第 2 步:运行确定性检查器

Text report:
bash
python3 "$SKILL_DIR/scripts/codex_thread_usage.py" \
  'codex://threads/<uuid>' --details
Machine-readable report:
bash
python3 "$SKILL_DIR/scripts/codex_thread_usage.py" \
  '<thread-uuid>' --json
Use
--codex-home <directory>
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.
文本报告:
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 数据目录时,才使用
--codex-home <directory>
。 脚本会读取消息信封和 token 字段,但绝不会输出消息正文。

Step 3: Evaluate evidence and boundaries

第 3 步:评估证据与边界

  1. Verify the rollout
    session_meta.payload.id
    matches the deeplink UUID.
  2. Compare
    state_snapshot.tokens_used
    with the last segment total.
  3. If there is more than one segment, explain that the SQLite value is only the latest counter, while the historical value sums segment terminals.
  4. If
    estimated_segments
    is nonzero, label the total as accumulated or estimated rather than exact billing usage.
  5. If
    raw_response_completed.events
    is nonzero, report it separately; it is exact per event but may be incomplete for older or provider-specific runs.
  1. 验证 rollout 的
    session_meta.payload.id
    是否与 deeplink UUID 匹配。
  2. 将
    state_snapshot.tokens_used
    与最后一个计数段的总量进行比较。
  3. 如果存在多个计数段,说明 SQLite 值仅代表最新计数器,而历史值是各计数段终值的总和。
  4. 如果
    estimated_segments
    不为零,应将总量标记为累计值或估算值,而不是精确计费用量。
  5. 如果
    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
total_tokens
. Do not infer money or subscription quota from these fields.
首先给出历史已处理 token 总量,然后依次展示输入、缓存输入、输出、 推理输出、最新 SQLite 快照、计数段/重置次数和数据质量。 绝不将缓存或推理子集加到
total_tokens
中。也不根据这些字段推断金额或 订阅配额。

Validation

验证

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,
    jq
    , or SQLite CLI required at runtime.
  • 仅需 Python 3.9+ 标准库。
  • 需要对本地 Codex 数据目录的读取权限。
  • 运行时不需要凭据、网络访问、
    jq
    或 SQLite CLI。