Headless plan/usage query: expose /usage data (e.g. cmd usage --json)

未關閉
#1,093 0 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
cli
領域
api, cli

研究方向

The payload names no source files. Start by finding where the /usage slash command gets its window and credit data in the interactive TUI, and where the existing status subcommand is defined. Confirm whether a server endpoint for this data is already in use, since the issue rules out probing undocumented ones. Done means cmd usage and cmd usage --json print the proposed shape, with exit code 0 on success and the existing auth and network error codes preserved.

由索引模型根據 Issue 內容生成。

描述

Summary

/usage shows the 5-hour and weekly usage windows (percent used, reset time) plus the credit balance, but it is only available in the interactive TUI. There is no headless/scriptable way to read the same data.

Problem

  • cmd -p "/usage" does not run the slash command (it is treated as a prompt).
  • cmd status reports authentication only.
  • Automation (status bars, desktop widgets, dashboards) therefore has to approximate window usage from local transcripts (~/.commandcode/projects/**/*.jsonl via costUsd + timestamps, simulating the anchored windows). That cannot match server-side credit accounting, especially on plans where credits are not exactly $1 of usage.

Proposal

Add a headless command with the same content as /usage:

cmd usage            # human-readable
cmd usage --json     # machine-readable

Suggested JSON shape:

{
  "plan": "GOAT",
  "credits": { "monthly_cap": 100.0, "remaining": 74.5 },
  "windows": {
    "5h": { "used": 4.2, "cap": 20.0, "percent": 21, "resets_at": "2026-10-31T17:20:00Z" },
    "7d": { "used": 8.8, "cap": 50.0, "percent": 18, "resets_at": "2026-11-04T21:00:00Z" }
  }
}

Exit code 0 on success; keep the existing exit-code conventions for auth/network errors.

Alternatives considered

  • Parsing an internal endpoint: undocumented and brittle; the docs advise against probing endpoints/auth.
  • Local transcript approximation: cannot reproduce server-side credit accounting or window anchoring reliably.

Additional context

Use case: a Wayland bar / desktop widget polling usage every minute so the user sees the same meters as /usage without opening the TUI.

主要語言
沒有語言資料
星號
4.2k
分支
377
平均合併
1 天 17 分鐘
30 天內合併 PR
7

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

CommandCodeAI/command-code 的其他 Issue

查看 CommandCodeAI/command-code 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。