Skip to content
This repository was archived by the owner on Oct 8, 2026. It is now read-only.

feat: add --json output to prism usage - #35

Merged
ygpark80 merged 1 commit into
mainfrom
feat/usage-json
Sep 17, 2026
Merged

ygpark80 merged 1 commit into
mainfrom
feat/usage-json

Conversation

@ygpark80

@ygpark80 ygpark80 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

User description

Summary

  • prism usage --json prints a machine-readable document: generated_at plus a providers array in the same order as the table. Each entry has provider, display_name, accounts (the API UsageAccount objects as returned; nil limits normalized to []) and error (usage_unavailable when that provider could not be fetched, otherwise null). When every provider fails the JSON is still printed and the exit code stays non-zero as today.
  • prism <provider> usage --json prints one provider object with the same shape, including the self-parsed cursor and gemini usage paths.
  • --json on any other command is rejected with a clear error. Help text and README updated.

This is the data contract consumed by the Prism menu bar app (circlesac/prism-v2 app/).

Verification

  • gofmt -l ., go vet -mod=vendor ./..., go test -mod=vendor -race ./... all pass.
  • Live prism usage --json against all six providers decodes in the app and renders in the menu bar.

🤖 Generated with Claude Code


CodeAnt-AI Description

Add machine-readable usage output for every supported provider

What Changed

  • prism usage --json now returns a timestamped JSON document containing all providers in table order, their accounts, and provider-specific errors
  • prism <provider> usage --json returns the selected provider's usage as JSON, including Cursor and Gemini
  • Failed providers produce an empty accounts list and a usage_unavailable error while successful providers remain available; JSON is still printed when all providers fail
  • --json is rejected for non-usage commands, with help and README examples updated

Impact

✅ Machine-readable usage for menu bar and automation clients
✅ Provider failures remain visible without hiding successful usage
✅ Consistent account and error data across all usage commands

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

prism usage --json prints a machine-readable document with generated_at and a
providers array in table order; each provider carries provider, display_name,
accounts (the API UsageAccount objects as-is, nil limits normalized to []) and
error. prism <provider> usage --json prints one provider object, including the
self-parsed cursor and gemini usage paths. --json is rejected on other commands.

Verified with go test -mod=vendor -race ./... and a live prism usage --json run
against all six providers.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@codeant-ai

codeant-ai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 4f37374 Sep 17, 2026 · 08:59 09:02

@codeant-ai

codeant-ai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: af7d40d6-a769-441b-bfa5-9ed244bdf111


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Sep 17, 2026
@@ -34,11 +34,14 @@ type antigravityUsageEnvelope struct {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: With --json, fetch failures return before JSON encoding, so callers receive no provider object or structured usage_unavailable error.

Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Api mismatch

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** internal/cli/gemini_usage.go
**Line:** 34:34
**Comment:**
	*Api Mismatch: With `--json`, fetch failures return before JSON encoding, so callers receive no provider object or structured `usage_unavailable` error.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment thread internal/cli/run.go
Comment on lines +149 to +151
if options.json {
return printUsageJSON(stdout, usageJSONProviderFor(providerName, usage, nil))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: When the provider fetch fails, this JSON branch is never reached because the preceding error return emits no machine-readable provider object.

Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Api mismatch

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** internal/cli/run.go
**Line:** 149:151
**Comment:**
	*Api Mismatch: When the provider fetch fails, this JSON branch is never reached because the preceding error return emits no machine-readable provider object.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment thread internal/cli/run.go
Comment on lines +879 to +880
case argument == "--json":
options.json = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: --json is accepted by the shared parser, but prism claude login --json bypasses validateCommand and proceeds with login instead of rejecting the flag.

Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Api mismatch

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** internal/cli/run.go
**Line:** 879:880
**Comment:**
	*Api Mismatch: `--json` is accepted by the shared parser, but `prism claude login --json` bypasses `validateCommand` and proceeds with login instead of rejecting the flag.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@ygpark80
ygpark80 merged commit 78e26fe into main Sep 17, 2026
1 check passed
@ygpark80
ygpark80 deleted the feat/usage-json branch September 17, 2026 09:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant