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

Đang mở
#1,093 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cli
Lĩnh vực
api, cli

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
4.2k
Fork
377
Merge trung bình
1 ngày 17 phút
Pull request đã merge (30 ngày)
7

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CommandCodeAI/command-code

Tất cả issue của CommandCodeAI/command-code

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.