cost-summary

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cost Summary

成本汇总

A stable single-call interface that other plugins / scripts / dashboards can shell out to and parse. ADR-0002 considered exposing
cost_report
/
cost_summary
as proper MCP tools but deferred that — adding MCP tools requires modifying
@claude-flow/cli
source, out of scope for plugin-local work. This script is the equivalent: same data, exposed via a stdout JSON contract.
一个稳定的单次调用接口,其他插件/脚本/仪表板可以调用并解析。ADR-0002曾考虑将
cost_report
/
cost_summary
作为正式的MCP工具暴露,但推迟了该计划——添加MCP工具需要修改
@claude-flow/cli
源码,这超出了插件本地工作的范围。本脚本可实现等效功能:提供相同的数据,通过标准输出的JSON协议暴露。

When to use

使用场景

  • Another plugin needs a snapshot of cost state — it shells out to
    summary.mjs --format json
    and parses.
  • A dashboard / Slackbot fetches a one-line cost rollup.
  • Quick "where am I right now?" view that pulls from every cost-tracker source (cost-tracking + federation-spend).
  • 其他插件需要获取成本状态快照时——可调用
    summary.mjs --format json
    并解析结果。
  • 仪表板/Slack机器人获取单行成本汇总数据。
  • 快速查看当前成本状态,汇总所有成本追踪源(成本追踪+联合支出)的数据。

Output contract (JSON, stable)

输出协议(JSON,稳定)

json
{
  "exportedAt": "<ISO>",
  "total_cost_usd": 1546.36,
  "sessionCount": 1,
  "conversationCount": 1,
  "byTier": { "haiku": 0, "sonnet": 0, "opus": 1546.36, "unknown": 0 },
  "byModel": {
    "claude-opus-4-7": {
      "tier": "opus",
      "cost_usd": 1546.36,
      "messages": 1597,
      "input_tokens": 3090,
      "output_tokens": 3295940,
      "cache_creation_input_tokens": 10659599,
      "cache_read_input_tokens": 732833690
    }
  },
  "topSession": {
    "sessionId": "1dba3b8c-...",
    "total_cost_usd": 1546.36,
    "messageCount": 1597
  },
  "budget": {
    "budget_usd": 2500.00,
    "setAt": "<ISO>",
    "spent_usd": 1546.36,
    "utilization": 0.6185,
    "level": "INFO"
  },
  "federation": {
    "eventCount": 0,
    "peerCount": 0,
    "totalUsd24h": 0
  }
}
json
{
  "exportedAt": "<ISO>",
  "total_cost_usd": 1546.36,
  "sessionCount": 1,
  "conversationCount": 1,
  "byTier": { "haiku": 0, "sonnet": 0, "opus": 1546.36, "unknown": 0 },
  "byModel": {
    "claude-opus-4-7": {
      "tier": "opus",
      "cost_usd": 1546.36,
      "messages": 1597,
      "input_tokens": 3090,
      "output_tokens": 3295940,
      "cache_creation_input_tokens": 10659599,
      "cache_read_input_tokens": 732833690
    }
  },
  "topSession": {
    "sessionId": "1dba3b8c-...",
    "total_cost_usd": 1546.36,
    "messageCount": 1597
  },
  "budget": {
    "budget_usd": 2500.00,
    "setAt": "<ISO>",
    "spent_usd": 1546.36,
    "utilization": 0.6185,
    "level": "INFO"
  },
  "federation": {
    "eventCount": 0,
    "peerCount": 0,
    "totalUsd24h": 0
  }
}

Steps

使用步骤

bash
undefined
bash
undefined

Markdown (default)

Markdown格式(默认)

node plugins/ruflo-cost-tracker/scripts/summary.mjs
node plugins/ruflo-cost-tracker/scripts/summary.mjs

JSON for programmatic consumption

JSON格式(供程序调用)

node plugins/ruflo-cost-tracker/scripts/summary.mjs --format json

Optional env: `SUMMARY_NAMESPACE=cost-tracking`, `SUMMARY_FED_NAMESPACE=federation-spend`, `SUMMARY_FORMAT=json`.
node plugins/ruflo-cost-tracker/scripts/summary.mjs --format json

可选环境变量:`SUMMARY_NAMESPACE=cost-tracking`、`SUMMARY_FED_NAMESPACE=federation-spend`、`SUMMARY_FORMAT=json`。

Cross-references

交叉引用

  • cost-report
    — narrative report (per-agent / per-model lens; uses same data)
  • cost-export
    — pushes to Prometheus / webhook (this skill is pull-style; export is push-style)
  • ADR-0002 §"Decision" — explicitly defers proper MCP-tool registration to a future ADR
  • cost-report
    ——叙述性报告(按Agent/模型维度;使用相同数据)
  • cost-export
    ——推送数据至Prometheus/ webhook(本工具为拉取式;export为推送式)
  • ADR-0002 §"Decision"——明确将正式MCP工具注册推迟至未来的ADR中