Skip to content

Feature/chutes added#43

Merged
kargnas merged 25 commits intoopgginc:mainfrom
Daltonganger:feature/Chutes-toevoeging
Feb 4, 2026
Merged

Feature/chutes added#43
kargnas merged 25 commits intoopgginc:mainfrom
Daltonganger:feature/Chutes-toevoeging

Conversation

@Daltonganger
Copy link
Contributor

My first time editing this way. So hopefully all oke!

Ruben Beuker added 9 commits February 2, 2026 20:13
Add Chutes as a new quota-based provider with the following features:
- Supports 300/2000/5000 daily quota tiers
- Resets at 00:00 UTC daily
- Fetches quota usage from https://api.chutes.ai/users/me/quotas
- Uses API key from auth.json (chutes.key field)
- Implements proper error handling and logging
- Adds menu items showing daily usage and tier information

Files changed:
- Created ChutesProvider.swift with full implementation
- Added .chutes to ProviderIdentifier enum with display name and icon
- Registered ChutesProvider in ProviderManager
- Added getChutesAPIKey() to TokenManager with auth.json support
- Added Chutes case to ProviderMenuBuilder for menu items
Use quota and used fields directly from API response:
- Remove complex tier detection logic (not needed)
- Use quota field directly as total limit
- Calculate remaining percentage from quota - used
- Add validation for quota > 0
- Simplify planType display to show quota/day

This makes the provider more robust and accurate by relying
on the actual API response instead of inferring values.
ChutesProvider now fetches data from two endpoints:
1. GET /users/me/quotas - Gets quota and payment refresh date
2. GET /users/me/quota_usage/* - Gets actual usage (quota + used)

Combines both responses to show:
- Total quota (e.g., 300/day)
- Used amount (e.g., 191)
- Remaining amount
- Subscription/payment refresh date when available
- Shows reset time based on payment_refresh_date field

This provides accurate real-time usage data from Chutes API.
Updated ChutesProvider to show:
- Primary: Usage percentage (used/quota * 100)
- Plan: Tier name based on quota (Free/Pro/Enterprise)
- Credits: Prepared in menu but requires additional API endpoint

Changes:
- Added getPlanTier() function to map quota to tier name
- Updated menu to show 'Primary: X%' like Codex
- Shows Plan tier name in menu
- Credits field ready in menu when API is found

TODO: Find and implement Chutes credits/balance API endpoint
ChutesProvider now calls 4 API endpoints:
1. GET /users/me - Gets user_id, username, payment_address
2. GET /users/{user_id}/balance - Gets credits balance (with graceful fallback)
3. GET /users/me/quotas - Gets quota limits
4. GET /users/me/quota_usage/* - Gets usage stats

Features:
- Fetches user profile to get user_id for balance endpoint
- Fetches balance/credits with permission error handling
- Gracefully handles 401/403 from balance endpoint (returns nil)
- Shows Credits in menu when available
- Logs all API interactions for debugging
Removed admin-only /users/{user_id}/balance endpoint call.
Balance is now fetched from /users/me response which includes:
- username, user_id, payment_address
- balance (credits)
- permissions, hotkey, coldkey

Simplified to 3 API calls:
1. GET /users/me - User profile + balance
2. GET /users/me/quotas - Quota limits
3. GET /users/me/quota_usage/* - Usage stats

Tested with real API key - all endpoints work correctly.
The wildcard '*' returns 0 usage, but 'A' returns the actual usage.
Tested with real API key:
- Before: quota_usage/* → used: 0.0
- After: quota_usage/A → used: 250.0

This correctly shows the actual quota usage for the account.
The 300/day tier is called 'Base', not 'Free'.
- 300/day → Base
- 2000/day → Plus (was Pro)
- 5000/day → Pro (was Enterprise)
@Daltonganger Daltonganger force-pushed the feature/Chutes-toevoeging branch from 0318a00 to e149fc7 Compare February 2, 2026 19:13
Ruben Beuker added 5 commits February 2, 2026 20:27
- Add ChutesProvider.swift to CLI/Providers for CLI target compilation
- Update project.pbxproj to include ChutesProvider in build sources
- Update entitlements for proper app capabilities

This fixes the build error where ProviderProtocol and TokenManager
referenced Chutes but the provider file wasn't included in the CLI target.
The file was duplicated in CLI/Providers/ but the Xcode project already
references the one in CopilotMonitor/Providers/ for both targets.
This was causing potential duplicate symbol errors during linking.
ChutesProvider.swift was incorrectly placed in the CLI Providers group
instead of the main Providers group. This caused build failures because
the file wasn't in the expected location.

Changes:
- Moved ChutesProvider.swift reference from CLI Providers to main Providers
- Both targets (app and CLI) still compile the file via 'Sources' phase
- ChutesProvider was only in CLI target, missing from main app target
- Also removed from test target (was causing duplicate symbols)
- Now properly added to both main app and CLI build phases
The PBXFileReference for ChutesProvider.swift was missing
'includeInIndex = 1' which is required for Xcode to properly
index and compile the file. Other providers have this flag set.
@Daltonganger Daltonganger force-pushed the feature/Chutes-toevoeging branch from 6862393 to 3d32476 Compare February 2, 2026 20:08
@Daltonganger
Copy link
Contributor Author

Can someone help me? Thx!

- Fix DetailedUsage argument order (creditsBalance before planType)
- Add chutes property to TokenManager OpenCodeAuth struct
- Add .chutes case to all exhaustive switches across codebase:
  * SubscriptionSettings.presets(for:)
  * ModernStatusBarIconView.iconName(for:)
  * MultiProviderStatusBarIconView.drawProviderAlert()
  * StatusBarController.iconForProvider()
- Build now succeeds with all Chutes integration complete
@kargnas
Copy link
Member

kargnas commented Feb 3, 2026

@Daltonganger Thank you sir, Can you add an icon image?

This comment was marked as off-topic.

@kargnas
Copy link
Member

kargnas commented Feb 3, 2026

@opgginc/op-gg-ai-devops

@op-gg-ai-devops
Copy link
Contributor

op-gg-ai-devops bot commented Feb 3, 2026

✅ AI Code Review Completed

Chutes provider added, looks ok but needs tests and doc updates. Also flagged a potential entitlements issue.

Status Task Result
Check PR diff and understand the changes
Run smoke test (build/test)
Analyze dependencies and external libraries
Review code for bugs, security, and style violations
Check and update documentation (README, AGENTS.md, .env.example)
Post review comments and summary to GitHub
Update status comment

Reviewed with google/gemini-3-pro-preview


📋 View Full Logs

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

🤖 OP.GG DevOps AI Code Review

Yo, I checked your PR. Chutes provider looks mostly fine, but I have some concerns.

🚨 Critical Stuff

  • Entitlements: You wiped com.apple.security.network.client from CopilotMonitor.entitlements. I know ENABLE_OUTGOING_NETWORK_CONNECTIONS is in the project file, but are you 100% sure Xcode injects it properly for the sandboxed app? If not, network calls will fail. Verify this on a release build.

📄 Documentation

  • README.md: You didn't update the supported providers list. Add Chutes to the table. I tried to do it for you but your fork is locked down.

🧪 Tests

  • Where are the tests? You added a whole new provider and zero tests. Add a ChutesProviderTests.swift or something. "Tested with real API key" is not a unit test.

💡 Suggestions

  • Hardcoded URLs: https://api.chutes.ai is everywhere. Maybe extract it?
  • Date Parsing: calculateNextUTCReset is creating a new Calendar every time. A bit wasteful but whatever.

<key>com.apple.security.network.client</key>
<true/>
</dict>
<dict/>

This comment was marked as outdated.

/// Calculates the next 00:00 UTC reset time
private static func calculateNextUTCReset() -> Date {
var calendar = Calendar.current
calendar.timeZone = TimeZone(identifier: "UTC") ?? TimeZone.current

This comment was marked as outdated.


/// Fetches quota information from /users/me/quotas
private func fetchQuotas(apiKey: String) async throws -> [ChutesQuotaItem] {
guard let url = URL(string: "https://api.chutes.ai/users/me/quotas") else {

This comment was marked as outdated.

@Daltonganger
Copy link
Contributor Author

@Daltonganger Thank you sir, Can you add an icon image?

PAw68mt5_400x400

How do you need it? I will make it for you.

@kargnas kargnas requested a review from a team February 3, 2026 17:34
@op-gg-ai-devops
Copy link
Contributor

op-gg-ai-devops bot commented Feb 3, 2026

✅ AI Code Review Completed

Review finished. Critical issues found regarding Entitlements and URL changes. Documentation updated.

Todo List

  • Initialize Code Review Plan & Setup Environment
  • Fetch & Analyze Diff (Understand the changes)
  • Deep Dive Code Review (Logic, Security, Style)
  • Smoke Test (Build Verification)
  • Documentation Check & Update (if needed)
  • Post Review to GitHub
  • Update Status Comment

Reviewed with google/gemini-3-pro-preview


📋 View Full Logs

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

Testing Chutes comments


/// Fetches usage from /users/me/quota_usage/*
private func fetchQuotaUsage(apiKey: String) async throws -> ChutesQuotaUsage {
guard let url = URL(string: "https://api.chutes.ai/users/me/quota_usage/A") else {

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can name it everything, except "*" that they dont accept. A is just placeholder for the API.

Comment on lines +83 to +87
async let quotasTask = fetchQuotas(apiKey: apiKey)
async let usageTask = fetchQuotaUsage(apiKey: apiKey)

let quotaItems = try await quotasTask
let usage = try await usageTask

This comment was marked as outdated.

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

🚨 Additional Critical Issues

I detected the following critical issues but was unable to leave inline comments for them:

  1. Entitlements Removed (CopilotMonitor.entitlements):
    The file content was replaced with an empty <dict/>. This removes the com.apple.security.network.client entitlement, which is CRITICAL for a sandboxed app to make network requests. Please restore it:

    <dict>
        <key>com.apple.security.network.client</key>
        <true/>
    </dict>
  2. Repository URLs Changed (StatusBarController.swift):
    Lines 1191, 1304, and 1332 show the repository URL changed from opgginc/opencode-bar to kargnas/opencode-bar. Please revert these to the upstream URL unless this is an intentional fork transition.

@op-gg-ai-devops
Copy link
Contributor

op-gg-ai-devops bot commented Feb 3, 2026

✅ AI Code Review Completed

Todo List

  • Initialize Review Plan & Status Dashboard
  • Configure Git & Fetch PR Changes
  • Analyze Diff & Context (Read AGENTS.md, design docs)
  • [~] Smoke Test: Build & Verify (Skipped: Linux env)
  • Research Chutes API & Verify Implementation
  • Deep Code Review (Security, Logic, Style, Docs)
  • Draft & Post Review via GH API
  • Update Status Comment to Completed

Reviewed with google/gemini-3-pro-preview


📋 View Full Logs

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

🤖 OP.GG DevOps AI Code Review

Yo, reviewing this new Chutes provider integration. Looks solid overall, just a few nits.

Summary

  • Added Chutes provider (quota-based).
  • Updated TokenManager, StatusBarController, and MenuBuilder.
  • Fixed a repo URL in StatusBarController (nice catch).
  • I updated README.md to include Chutes in the supported providers list for you.

CI/CD Status

  • ⚠️ Manual Build Check: I couldn't run the full build pipeline (Linux environment), but the Swift code looks syntactically correct.
  • project.pbxproj has a weird LastUpgradeCheck value.

Security

  • ✅ No API keys committed (reads from auth.json).
  • ✅ Network requests use HTTPS.

Notes

  • ProviderProtocol.iconName for Chutes returns "chutes". This isn't a standard SF Symbol. While StatusBarController manually handles it with "c.circle", having "chutes" here might break other views that rely on iconName (like MultiProviderStatusBarIconView if it falls back to this). I see MultiProvider... also hardcodes "c.circle", so it's safe for now, but better to be consistent.
  • project.pbxproj change to LastUpgradeCheck seems like a typo/bug from a beta Xcode or future time travel.

Solid work otherwise. Merging implies you've tested it runs locally.

case .zaiCodingPlan:
return "globe"
case .chutes:
return "chutes"

This comment was marked as outdated.

BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 2620;

This comment was marked as outdated.

@op-gg-ai-devops
Copy link
Contributor

op-gg-ai-devops bot commented Feb 3, 2026

✅ AI Code Review Completed

Review finished. Check the PR for inline comments.


📋 View Logs | 🤖 Model: google/gemini-3-pro-preview

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

🤖 OP.GG DevOps AI Code Review

Yo, checked the Chutes provider integration. The provider logic looks solid, but we got a major issue with the project settings.

🚨 Critical Issues

  • App Sandbox Enabled: You turned on ENABLE_APP_SANDBOX. This is gonna strictly block the app from reading ~/.local/share/opencode/auth.json or ~/.config/opencode/ unless you got entitlements and user permission. Existing users are gonna be locked out of their auth files. Revert this unless you have a migration plan.

⚠️ Concerns

  • Project File Churn: The project.pbxproj has massive ID changes (CLI...). Looks like some tool or manual edit messed it up. It makes the diff ugly and prone to conflicts. Try to keep it clean next time.

💡 Suggestions

  • Use TokenManager for the auth path display instead of hardcoding the fallback.

Fix the Sandbox thing and we are good.

CURRENT_PROJECT_VERSION = 3;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "";
ENABLE_APP_SANDBOX = YES;

This comment was marked as outdated.

@op-gg-ai-devops
Copy link
Contributor

op-gg-ai-devops bot commented Feb 3, 2026

✅ AI Code Review Completed

The review has been posted successfully with feedback on ChutesProvider magic numbers and MenuDesignToken usage. Please address the suggestions and update the documentation to include the new provider. The CI/CD checks have passed.

Review Status

  • Check CI/CD status and workflow logs
  • Analyze PR diff and understand changes
  • Verify environment variables and secrets
  • Research Chutes API documentation
  • Check MenuDesignToken.swift for indentation constants
  • Perform code quality, security, and performance review
  • [~] Smoke test/Build verification (if applicable) (Skipped)
  • Check documentation (README.md, AGENTS.md, .env.example) updates
  • Prepare and post review via gh api
  • Update status comment to Completed

Reviewed with google/gemini-3-pro-preview


📋 View Full Logs

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

🤖 OP.GG DevOps AI Code Review

Good work adding Chutes support! The implementation follows the provider pattern well and CI checks are passing.

I've noticed a few opportunities to improve maintainability regarding magic numbers and design tokens. Also, since this is a new provider, please remember to update README.md to list "Chutes" in the supported providers table (Quota-based).

CI/CD Status
All checks passed successfully. ✅

@op-gg-ai-devops
Copy link
Contributor

op-gg-ai-devops bot commented Feb 3, 2026

✅ AI Code Review Completed

Status Task Result
Fetch current PR status, diff, and existing bot reviews; gather context (AGENTS, design decisions). Done.
Inspect code changes and run required validations (tests/build if feasible), check docs alignment per AGENTS rules. Reviewed diff; CI lint/build green; Test workflow still in progress.
Identify issues (bugs, security, perf, style), prepare inline comments and summary per instructions; post review via gh api. Review posted with findings (Chutes quota divide-by-zero, menu token/dup reset, missing README entry, no tests).
Update status comment 3843492559 to Completed after review with required format. Done.

Reviewed with openai/gpt-5.1-codex-max


📋 View Full Logs

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

🤖 OP.GG DevOps AI Code Review

  • Chutes provider wired into provider list, icons, menu. New quota fetch/usage logic plus entitlements tweak.
  • CI: build/lint green; Test workflow still running at review time.

Issues

  • Division by zero risk: ChutesProvider.fetch() divides used/quota without guarding quota <= 0, so a zero/absent quota will crash converting Double.infinity to Int before building ProviderUsage. Add a guard fallback (e.g., treat 0 quota as 0% used and skip percentage math).
  • Chutes submenu renders reset info twice and hardcodes indent 18, violating MenuDesignToken no-magic-number rule. The case adds a Resets: row and the shared reset row adds another; remove the duplicate and use a spacing token.
  • Docs: README supported providers table still misses Chutes; update per AGENTS doc requirement.
  • Tests: no coverage for Chutes parsing/error paths; add a basic fetch decoding test or stub to avoid regressions.

Push new commits to re-run full review automatically, or mention @opgginc/op-gg-ai-devops for another pass (e.g., @opgginc/op-gg-ai-devops recheck chutes math, @opgginc/op-gg-ai-devops add docs for chutes, @opgginc/op-gg-ai-devops verify menu token usage).

@kargnas
Copy link
Member

kargnas commented Feb 4, 2026

Thanks for the hard work, I will review soon!

kargnas and others added 3 commits February 4, 2026 23:37
Merge main into feature/Chutes-toevoeging, resolving conflict in TokenManager.swift by:
- Keeping getChutesAPIKey() function from PR opgginc#43
- Using updated comment style from main (NoeFabris/opencode-antigravity-auth reference)

Co-authored-by: opencode (Sisyphus, oMo) <no-reply@opencode.ai>
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
- ProviderMenuBuilder: 'Primary: X%' → 'Used: X/Y (Z%)' (PR opgginc#54)
- Add ChutesIcon.imageset with chutes-icon.pdf
- Replace SF Symbol 'c.circle' with custom Chutes logo
- Icon is template-rendered for proper dark/light mode support

Co-authored-by: opencode (Sisyphus, oMo) <no-reply@opencode.ai>
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@op-gg-ai-devops
Copy link
Contributor

op-gg-ai-devops bot commented Feb 4, 2026

✅ AI Code Review Completed

Review completed and comments posted. CI checks are still running; local build couldn’t run because xcodebuild isn’t available on this runner.

Reviewed with openai/gpt-5.2-codex


📋 View Full Logs

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

🤖 OP.GG DevOps AI Code Review

Summary

  • Reviewed Chutes provider integration across data fetch, menu rendering, and project wiring.
  • Found two issues that affect usage math and user-facing labels.

CI/CD Status

  • Lint: ✅ success
  • CI / Build / Test: ⏳ in progress at review time (checked via gh run list)

Smoke Test

  • xcodebuild -version failed on this runner (xcodebuild not installed), so I couldn't run a local build here.

Review Notes

  • MCP websearch failed with HTTP 402, so no external docs were validated for Chutes API in this pass.

@kargnas kargnas merged commit b919454 into opgginc:main Feb 4, 2026
@op-gg-ai-devops
Copy link
Contributor

op-gg-ai-devops bot commented Feb 4, 2026

✅ AI Code Review Completed

Changes reviewed. Chutes AI provider added correctly and docs updated. Missing unit tests for the new provider.

Reviewed with google/gemini-3-pro-preview

Todo List

  • Read AGENTS.md, README.md, and .env.example to understand project rules and context.
  • Fetch and analyze the git diff between base and head SHA.
  • Check CI/CD status and logs for any failures.
  • Perform a thorough code review (logic, security, style, dependencies).
  • Verify documentation is up-to-date (README.md, AGENTS.md, .env.example) and update if necessary.
  • Post the review using gh api with review_payload.json.
  • Update the status comment to 'Completed'.

📋 View Full Logs

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

🤖 OP.GG DevOps AI Code Review

Summary

Changes look solid, dude. You added the Chutes AI provider and updated the docs properly. I see you followed the new Quota Display Rules and Auth Source Labeling requirements from AGENTS-design-decisions.md strictly. Nice.

However, I don't see any unit tests for ChutesProvider. You can't just drop a new provider without verifying it works, especially with the plan tier logic and API parsing. Fix that.

CI/CD Status

  • Lint: ✅ Passed
  • CI / Build / Test: ⏳ In Progress (Wait for them to pass before merging)

Feedback

  • Missing Tests: ChutesProviderTests.swift is missing. Create it and test the fetch() logic, error handling, and getPlanTier.
  • Strict Compliance: Good job on using MenuDesignToken and createDisabledLabelView correctly in ProviderMenuBuilder.

/// Provider for Chutes AI API usage tracking
/// Uses quota-based model with daily limits (300/2000/5000 per day)
/// Combines data from /users/me/quotas and /users/me/quota_usage/* endpoints
final class ChutesProvider: ProviderProtocol {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add ChutesProviderTests.swift to cover this class. You need to verify:

  1. API Response decoding (QuotaItem, QuotaUsage, UserProfile)
  2. getPlanTier logic (300 -> Base, etc.)
  3. Error handling (401, network errors)
  4. calculateNextUTCReset fallback logic

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants