Skip to content

desktop/src-tauri/crates/core/src/copilot_quota.rs

Comment 1, line 1

desktop/src-tauri/crates/core/src/copilot_quota.rs:1

//! Read local GitHub Copilot quota records from copilot-user-cache.json.

Comment 2, line 2

desktop/src-tauri/crates/core/src/copilot_quota.rs:2

//!

Comment 3, line 3

desktop/src-tauri/crates/core/src/copilot_quota.rs:3

//! References: 2026-10-01 local checks and the official CLI cache-directory reference.

Comment 4, line 4

desktop/src-tauri/crates/core/src/copilot_quota.rs:4

//! VS Code Copilot Chat and Copilot CLI share an account quota cache:

Comment 5, line 5

desktop/src-tauri/crates/core/src/copilot_quota.rs:5

//! copilot-user-cache.json under Windows %LOCALAPPDATA%/copilot/,

Comment 6, line 6

desktop/src-tauri/crates/core/src/copilot_quota.rs:6

//! macOS ~/Library/Caches/copilot/, or Linux $XDG_CACHE_HOME/copilot

Comment 7, line 7

desktop/src-tauri/crates/core/src/copilot_quota.rs:7

//! with ~/.cache/copilot/ fallback. JSON follows comment lines.

Comment 8, line 8

desktop/src-tauri/crates/core/src/copilot_quota.rs:8

//! Quota fields live at copilotUserCache.<hash>.response.quota_snapshots.<quota_id>.

Comment 9, line 9

desktop/src-tauri/crates/core/src/copilot_quota.rs:9

//!

Comment 10, line 10

desktop/src-tauri/crates/core/src/copilot_quota.rs:10

//! These account premium-request quotas span devices/interfaces. The observed sample had

Comment 11, line 11

desktop/src-tauri/crates/core/src/copilot_quota.rs:11

//! an allowance of 1500, not a universal limit. Display native requests separately, without token conversion.

Comment 12, line 12

desktop/src-tauri/crates/core/src/copilot_quota.rs:12

//! timestamp_utc is the service snapshot time. The 2026-10-01 conclusion about absent

Comment 13, line 13

desktop/src-tauri/crates/core/src/copilot_quota.rs:13

//! per-call tokens applied to the inspected chronicle session-store.db. Native VS Code

Comment 14, line 14

desktop/src-tauri/crates/core/src/copilot_quota.rs:14

//! chatSessions/*.jsonl usage/round records are read by copilot_chat; quotas remain separate.

Comment 15, line 19

desktop/src-tauri/crates/core/src/copilot_quota.rs:19

/// Account quota snapshot in request units, separate from tokens.

Comment 16, line 22

desktop/src-tauri/crates/core/src/copilot_quota.rs:22

/// Quota ID: premium_interactions, chat or completions.

Comment 17, line 24

desktop/src-tauri/crates/core/src/copilot_quota.rs:24

/// Billing-window allowance; zero is an unlimited placeholder.

Comment 18, line 26

desktop/src-tauri/crates/core/src/copilot_quota.rs:26

/// Remaining allowance in milli-requests; missing/inexact values stay unknown.

Comment 19, line 28

desktop/src-tauri/crates/core/src/copilot_quota.rs:28

/// Used = allowance - remaining only for a positive, non-unlimited allowance.

Comment 20, line 30

desktop/src-tauri/crates/core/src/copilot_quota.rs:30

/// Native remaining percentage.

Comment 21, line 32

desktop/src-tauri/crates/core/src/copilot_quota.rs:32

/// Unlimited flag; chat/completions are usually unlimited and have no derived used count.

Comment 22, line 34

desktop/src-tauri/crates/core/src/copilot_quota.rs:34

/// Service snapshot timestamp from timestamp_utc, in milliseconds.

Comment 23, line 38

desktop/src-tauri/crates/core/src/copilot_quota.rs:38

/// Parsed account plan label and quota snapshots.

Comment 24, line 45

desktop/src-tauri/crates/core/src/copilot_quota.rs:45

/// Strip comment lines before parsing copilot-user-cache.json.

Comment 25, line 47

desktop/src-tauri/crates/core/src/copilot_quota.rs:47

// Remove lines starting with // after whitespace, preserving the JSON body.

Comment 26, line 56

desktop/src-tauri/crates/core/src/copilot_quota.rs:56

// Select the greatest retrievedAt; missing timestamps sort before known timestamps.

Comment 27, line 75

desktop/src-tauri/crates/core/src/copilot_quota.rs:75

// Emit quota IDs in stable lexical order.

Comment 28, line 81

desktop/src-tauri/crates/core/src/copilot_quota.rs:81

// has_quota=false means this account lacks the quota; skip it.

Comment 29, line 89

desktop/src-tauri/crates/core/src/copilot_quota.rs:89

// Preserve fractional premium requests as integer milli-requests without whole-request rounding.

Comment 30, line 110

desktop/src-tauri/crates/core/src/copilot_quota.rs:110

// Derive used only for a positive limited allowance; otherwise leave it unknown.

Comment 31, line 146

desktop/src-tauri/crates/core/src/copilot_quota.rs:146

/// Resolve platform cache paths with COPILOT_CACHE_HOME override.

Comment 32, line 147

desktop/src-tauri/crates/core/src/copilot_quota.rs:147

/// Accept an explicit environment map for isolated tests, without process-environment reads.

Comment 33, line 174

desktop/src-tauri/crates/core/src/copilot_quota.rs:174

// Linux/other platforms prefer XDG_CACHE_HOME, then ~/.cache.

Comment 34, line 184

desktop/src-tauri/crates/core/src/copilot_quota.rs:184

/// Read the local cache; missing/unparseable files return None.

Comment 35, line 204

desktop/src-tauri/crates/core/src/copilot_quota.rs:204

// Map to Agent-independent quota_history.

Comment 36, line 210

desktop/src-tauri/crates/core/src/copilot_quota.rs:210

/// Agent name used in statistics.

Comment 37, line 213

desktop/src-tauri/crates/core/src/copilot_quota.rs:213

/// Map parsed snapshots to generic QuotaObservation.

Comment 38, line 214

desktop/src-tauri/crates/core/src/copilot_quota.rs:214

/// Include positive limited quotas such as premium_interactions;

Comment 39, line 215

desktop/src-tauri/crates/core/src/copilot_quota.rs:215

/// account quotas span devices, so locality_verified=false; retain request units rather than tokens.

Comment 40, line 238

desktop/src-tauri/crates/core/src/copilot_quota.rs:238

// An account quota does not establish local-device usage; locality_verified=false.

Comment 41, line 248

desktop/src-tauri/crates/core/src/copilot_quota.rs:248

/// Read and store local-cache observations in quota_history; return the number recorded.

Comment 42, line 301

desktop/src-tauri/crates/core/src/copilot_quota.rs:301

// Parse timestamp_utc with its -07:00 offset into UTC milliseconds.