Skip to content

Show OpenCode Go usage from browser sessions - #14

Merged
ygpark80 merged 1 commit into
mainfrom
feat/opencode-go-usage
Aug 10, 2026
Merged

Show OpenCode Go usage from browser sessions#14
ygpark80 merged 1 commit into
mainfrom
feat/opencode-go-usage

Conversation

@ygpark80

@ygpark80 ygpark80 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

User description

Summary

  • add prism opencode-go usage using authenticated local browser sessions on macOS
  • discover Chrome, Chromium, Comet, Arc, Edge, Brave, and Firefox profiles without persisting cookies
  • show rolling, weekly, and monthly reset times with the existing pace projection

Verification

  • go test -mod=vendor -race ./...
  • go vet -mod=vendor ./...
  • CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor ./...
  • CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -mod=vendor ./...
  • local browser-backed prism opencode-go usage returned all three limits

CodeAnt-AI Description

Show OpenCode Go usage from existing browser sessions

What Changed

  • Adds prism opencode-go usage to display rolling, weekly, and monthly OpenCode Go limits, remaining percentages, reset times, and usage-limit status.
  • Uses existing authenticated sessions from supported browsers on macOS without saving or printing browser cookies.
  • Detects multiple OpenCode workspaces and reports each separately, with clear errors for missing, expired, unreadable, or invalid sessions.
  • Documents the new command and supported browsers; other platforms report that browser session reading is unavailable.

Impact

✅ View OpenCode Go usage without adding credentials
✅ See all rolling, weekly, and monthly reset times
✅ Clearer errors when browser sessions cannot be used

💡 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.

Summary by CodeRabbit

  • New Features

    • Added the opencode-go usage command to display OpenCode Go usage and reset information by workspace.
    • Supports retrieving usage through local browser sessions on macOS, including Chrome, Chromium, Firefox, Arc, Edge, Brave, Comet, and other supported browsers.
    • Shows rolling, weekly, and monthly usage limits, with clear handling for authentication, expired sessions, and unavailable data.
  • Documentation

    • Added usage instructions, supported browser details, session handling, and privacy information to the README.

@codeant-ai

codeant-ai Bot commented Aug 10, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR f166541 Aug 10, 2026 · 01:47 01:49

@codeant-ai

codeant-ai Bot commented Aug 10, 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 Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e09f4fff-9fb1-4dd1-8f5c-3a2f83bac8fc

📥 Commits

Reviewing files that changed from the base of the PR and between 76ac2dd and f166541.

📒 Files selected for processing (8)
  • README.md
  • internal/cli/run.go
  • internal/cli/run_test.go
  • internal/opencodego/session_darwin.go
  • internal/opencodego/session_darwin_test.go
  • internal/opencodego/session_other.go
  • internal/opencodego/usage.go
  • internal/opencodego/usage_test.go

📝 Walkthrough

Walkthrough

Adds prism opencode-go usage support. The implementation reads existing macOS browser sessions, retrieves authenticated OpenCode Go workspace data, parses usage limits, and displays the results without Circles credentials.

Changes

OpenCode Go usage

Layer / File(s) Summary
Browser session scanning
internal/opencodego/session_*.go, internal/opencodego/session_darwin_test.go
Discovers supported Chromium and Firefox profiles, reads authentication cookies, decrypts Chromium cookies, handles SQLite sidecar files, and reports scan results.
Authenticated usage retrieval
internal/opencodego/usage.go, internal/opencodego/usage_test.go
Fetches authenticated OpenCode pages, discovers workspaces, parses rolling, weekly, and monthly usage windows, and returns api.ProviderUsage with account-level errors.
CLI command integration
internal/cli/run.go, internal/cli/run_test.go, README.md
Adds the opencode-go usage route, validation, help text, tests, and browser-based usage documentation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Fetch
  participant BrowserSessions
  participant OpenCode
  CLI->>Fetch: Request OpenCode Go usage
  Fetch->>BrowserSessions: Scan authenticated browser sessions
  BrowserSessions-->>Fetch: Return cookies and scan results
  Fetch->>OpenCode: Request authenticated workspace pages
  OpenCode-->>Fetch: Return workspace and usage data
  Fetch-->>CLI: Display ProviderUsage
Loading

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/opencode-go-usage

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:XXL This PR changes 1000+ lines, ignoring generated files label Aug 10, 2026
@ygpark80
ygpark80 merged commit 7ca641c into main Aug 10, 2026
1 check passed
@ygpark80
ygpark80 deleted the feat/opencode-go-usage branch August 10, 2026 01:48
Comment thread internal/cli/run.go
Comment on lines +87 to +94
if command == "usage" && providerName == "opencode-go" {
usage, err := fetchOpenCodeGoUsage(ctx)
if err != nil {
return err
}
printUsage(stdout, usage)
return 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: The local-browser path ignores options.profile, even though usage validation accepts --profile and provider usage help advertises it. Consequently, prism opencode-go usage --profile <name> silently scans and reports every supported local browser session instead of honoring the selected profile. Either pass the profile through to the browser-session fetcher and scope the scan, or reject --profile for this provider. [api mismatch]

Severity Level: Major ⚠️
-`opencode-go usage --profile` can display usage from unintended browser sessions.
- ⚠️ Provider usage help advertises `--profile` through `internal/cli/run.go:618-620`.
- ⚠️ Multiple local browser accounts can produce ambiguous or incorrect output.

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:** 87:94
**Comment:**
	*Api Mismatch: The local-browser path ignores `options.profile`, even though usage validation accepts `--profile` and provider usage help advertises it. Consequently, `prism opencode-go usage --profile <name>` silently scans and reports every supported local browser session instead of honoring the selected profile. Either pass the profile through to the browser-session fetcher and scope the scan, or reject `--profile` for this provider.

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 on lines +354 to +361
for _, suffix := range []string{"", "-wal", "-shm"} {
if err := copyFile(source+suffix, destination+suffix); err != nil {
if suffix != "" && os.IsNotExist(err) {
continue
}
cleanup()
return "", func() {}, err
}

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: The database, WAL, and shared-memory files are copied in separate operations while the browser can write them concurrently. This can produce a main database paired with an unrelated WAL or shared-memory generation, causing SQLite to reject the snapshot or read an inconsistent state and report the browser store as unreadable. Create the snapshot through a SQLite-consistent backup mechanism or otherwise coordinate the files as one snapshot. [race condition]

Severity Level: Major ⚠️
- ⚠️ Active browser writes can make cookie snapshots unreadable.
- ❌ OpenCode usage fails during browser-backed session discovery.
- ⚠️ Failure affects macOS Chromium-family users.

Fix in Cursor Fix in VSCode Claude

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

**Path:** internal/opencodego/session_darwin.go
**Line:** 354:361
**Comment:**
	*Race Condition: The database, WAL, and shared-memory files are copied in separate operations while the browser can write them concurrently. This can produce a main database paired with an unrelated WAL or shared-memory generation, causing SQLite to reject the snapshot or read an inconsistent state and report the browser store as unreadable. Create the snapshot through a SQLite-consistent backup mechanism or otherwise coordinate the files as one snapshot.

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
👍 | 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant