cc-pets 2.5.0 → 2.6.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +47 -5
- package/CC_BRIDGE.zh-CN.md +42 -5
- package/CONTRIBUTING.md +1 -1
- package/CONTRIBUTING.zh-CN.md +1 -1
- package/README.md +48 -19
- package/README.zh-CN.md +46 -17
- package/Resources/AgentIcons/antigravity.icns +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +64 -15
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +7 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +11 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +16 -5
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +11 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +21 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +27 -16
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +43 -7
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +2 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +3 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +20 -22
- package/Sources/CCPets/App/CCPetsAppDelegate.m +14 -6
- package/Sources/CCPets/App/CCPetsVersion.h +4 -0
- package/Sources/CCPets/App/CCPetsVersion.m +34 -0
- package/Sources/CCPets/App/main.m +11 -0
- package/Sources/CCPets/Bridge/CCPetsBridge.m +7 -5
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.h +4 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.m +119 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +3 -1
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +172 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +25 -7
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +17 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +7 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +92 -11
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.h +12 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.m +105 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.m +462 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.m +180 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.h +3 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.m +463 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +1 -1
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +37 -7
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +15 -5
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +2 -1
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +112 -81
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +5 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +163 -40
- package/Sources/CCPets/Pet/CCPetsPreviews.m +16 -8
- package/Sources/CCPets/Pet/PetView+Menu.m +56 -5
- package/Sources/CCPets/Support/CCPetsDoctor.m +126 -37
- package/Sources/CCPets/Support/CCPetsPaths.h +5 -0
- package/Sources/CCPets/Support/CCPetsPaths.m +15 -0
- package/Sources/CCPets/Support/CCPetsPreferences.h +4 -1
- package/Sources/CCPets/Support/CCPetsPreferences.m +18 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +10 -5
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +9 -6
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +3 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +189 -8
- package/Sources/CCPets/UI/CCPetsUIStyle.m +3 -1
- package/Sources/CCPets/UI/CCPetsUsagePage.h +4 -3
- package/Sources/CCPets/UI/CCPetsUsagePage.m +69 -43
- package/Sources/CCPets/UI/CCPetsUsageStore.m +11 -1
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +1 -1
- package/Sources/CCPets/Usage/CCPetsAntigravityQuota.m +115 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.h +5 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.m +43 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry+Testing.h +13 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.h +25 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.m +94 -0
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.h +1 -1
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.m +11 -8
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +206 -14
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +4 -4
- package/Sources/CCPets/Usage/CCPetsUsage.h +7 -2
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +29 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.h +4 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +90 -7
- package/Sources/CCPets/Usage/QuotaDashboardView+CompactRow.m +81 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +5 -8
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +26 -4
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +99 -99
- package/Sources/CCPets/Usage/QuotaDashboardView.h +9 -10
- package/Sources/CCPets/Usage/QuotaDashboardView.m +232 -79
- package/THIRD_PARTY_NOTICES.md +5 -4
- package/THIRD_PARTY_NOTICES.zh-CN.md +6 -5
- package/bin/agy-with-pet +82 -0
- package/bin/cc-pets +1 -1
- package/bin/claude-with-pet +15 -0
- package/bin/codex-with-pet +17 -2
- package/package.json +5 -3
- package/scripts/install-shell-integration.sh +5 -0
|
@@ -11,7 +11,7 @@ static NSTimeInterval LineTimestamp(NSData *line) {
|
|
|
11
11
|
// 按块切行喂给 consume,返回消费掉的字节数(截止最后一个换行)。返回值就是下一次可以
|
|
12
12
|
// 安全续读的偏移:结尾那半行还没写完,不能算进去。includeTail=YES 时残行照样交给
|
|
13
13
|
// consume(一次性整篇扫描的调用方要它,最后一行未必有换行结尾)。
|
|
14
|
-
|
|
14
|
+
unsigned long long EnumerateUsageLines(NSFileHandle *handle, BOOL includeTail,
|
|
15
15
|
void (^consume)(NSData *)) {
|
|
16
16
|
NSMutableData *pending = [NSMutableData data];
|
|
17
17
|
unsigned long long consumed = 0;
|
|
@@ -181,7 +181,7 @@ NSDictionary *TokenSessionSummaryTracking(NSURL *url, NSMutableDictionary *cache
|
|
|
181
181
|
NSFileHandle *handle = [NSFileHandle fileHandleForReadingFromURL:url error:nil];
|
|
182
182
|
if (!handle) return nil;
|
|
183
183
|
if (offset > 0) [handle seekToFileOffset:offset];
|
|
184
|
-
unsigned long long consumed =
|
|
184
|
+
unsigned long long consumed = EnumerateUsageLines(handle, NO, ^(NSData *line) {
|
|
185
185
|
// 会话起点取文件第一条带 timestamp 的行,不限于 token_count:它决定这个会话算不算
|
|
186
186
|
// 整段落在窗口内。找到之后就不再对普通行做 JSON 解析。
|
|
187
187
|
if (!start) {
|
|
@@ -307,7 +307,7 @@ static NSDictionary *PartialTokenTotals(NSURL *url, NSTimeInterval start, NSTime
|
|
|
307
307
|
baseline = nil;
|
|
308
308
|
inside = nil;
|
|
309
309
|
};
|
|
310
|
-
|
|
310
|
+
EnumerateUsageLines(handle, YES, ^(NSData *line) {
|
|
311
311
|
NSDictionary *record = TokenRecordFromLine(line);
|
|
312
312
|
NSDictionary *total = record[@"total"];
|
|
313
313
|
if (!total) return;
|
|
@@ -603,7 +603,7 @@ NSMutableDictionary *LoadMonthlyUsageArchive(NSString *path) {
|
|
|
603
603
|
// heap-buffer-overflow, WRITE of size 48, 0 bytes after 6640-byte region
|
|
604
604
|
// 分配点 __CFBinaryPlistCreateObjectFiltered <- LoadTokenSummaryCache
|
|
605
605
|
// 越界写破坏堆之后进程不会当场死,而是在之后任意一次内存操作上倒下,因此崩溃点看起来
|
|
606
|
-
// 和这里毫无关系(实际报告里落在
|
|
606
|
+
// 和这里毫无关系(实际报告里落在 EnumerateUsageLines 和 SaveTokenSummaryCache 上)。
|
|
607
607
|
//
|
|
608
608
|
// 可靠的做法只有一条:落盘缓存一读回来就把 records 换成本进程创建的可变副本,
|
|
609
609
|
// 之后 ClaudeRecordsForFile 的原地追加才成立。只替换 records,其余字段原样保留——
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#import <Foundation/Foundation.h>
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// Agent CLI 的额度读取。
|
|
4
4
|
int RecordClaudeUsage(void);
|
|
5
5
|
NSDictionary *ClaudeRateLimits(void);
|
|
6
6
|
NSDictionary *ClaudeRateLimitsForConfigDirectory(NSString *configDirectory);
|
|
7
7
|
NSDictionary *LatestClaudeUsage(void);
|
|
8
8
|
NSDictionary *LatestUsage(void);
|
|
9
|
+
NSDictionary *AntigravityRateLimitsForConfigDirectory(NSString *configDirectory);
|
|
10
|
+
NSDictionary *AntigravityTokenUsageForConfigDirectory(NSString *configDirectory);
|
|
11
|
+
NSDictionary *AntigravityAppTokenUsageForConfigDirectory(NSString *configDirectory);
|
|
12
|
+
BOOL CCPetsAntigravityAppUsageAvailable(void);
|
|
9
13
|
// 清掉 resets_at 已经翻篇(或不可能属于当前窗口)的额度窗口,缺 resets_at 的保留。
|
|
10
14
|
NSDictionary *UsageByRemovingExpiredQuotaWindows(NSDictionary *usage);
|
|
11
15
|
|
|
@@ -38,7 +42,8 @@ NSDictionary *UsageByRemovingExpiredQuotaWindows(NSDictionary *usage);
|
|
|
38
42
|
- (NSDictionary *)refreshForSessionURLs:(NSArray<NSURL *> *)urls;
|
|
39
43
|
@end
|
|
40
44
|
|
|
41
|
-
// 按模型的用量,provider 为 "claude"
|
|
45
|
+
// 按模型的用量,provider 为 "claude"、"codex"、"antigravity"(CLI)或 "antigravity-app"。
|
|
46
|
+
// 统计 [start, end) 之间的自然日
|
|
42
47
|
// (start / end 应是日零点),数据来自本机会话日志,不联网。会读整段区间的会话文件,首次可能耗时
|
|
43
48
|
// 数百毫秒到数秒,只在后台队列调用。结果:
|
|
44
49
|
// models: @{模型名: counts} 区间合计
|
|
@@ -8,3 +8,5 @@ NSString *CCPetsProfileAuthenticationMode(NSDictionary *profile);
|
|
|
8
8
|
NSString *CCPetsUsageModePreferenceKey(NSDictionary *profile);
|
|
9
9
|
BOOL CCPetsProfileShowsAPIUsage(NSDictionary *profile);
|
|
10
10
|
BOOL CCPetsProfileCanSwitchUsageMode(NSDictionary *profile);
|
|
11
|
+
BOOL CCPetsAntigravityUsesGeminiAPI(NSString *configDirectory);
|
|
12
|
+
BOOL CCPetsAntigravityQuotaReportEnabled(NSString *configDirectory);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#import "CCPetsCLISupport.h"
|
|
3
3
|
#import "CCPetsJSON.h"
|
|
4
4
|
#import "CCPetsPaths.h"
|
|
5
|
+
#import "CCPetsProfiles.h"
|
|
5
6
|
|
|
6
7
|
NSNotificationName const CCPetsAuthenticationModesDidChangeNotification = @"CCPetsAuthenticationModesDidChange";
|
|
7
8
|
static NSMutableDictionary<NSString *, NSDictionary *> *AuthenticationModes;
|
|
@@ -18,6 +19,21 @@ static NSDictionary *ReadJSONObject(NSString *path) {
|
|
|
18
19
|
return [object isKindOfClass:NSDictionary.class] ? object : nil;
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
static NSDictionary *AntigravitySettings(NSString *configDirectory) {
|
|
23
|
+
return configDirectory.length > 0 ? ReadJSONObject(
|
|
24
|
+
[configDirectory stringByAppendingPathComponent:@"antigravity-cli/settings.json"]) : nil;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
BOOL CCPetsAntigravityUsesGeminiAPI(NSString *configDirectory) {
|
|
28
|
+
return [AntigravitySettings(configDirectory)[@"modelProvider"] isEqual:@"gemini"];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
BOOL CCPetsAntigravityQuotaReportEnabled(NSString *configDirectory) {
|
|
32
|
+
NSDictionary *settings = AntigravitySettings(configDirectory);
|
|
33
|
+
// A disabled slash command can turn /usage into an ordinary model prompt.
|
|
34
|
+
return ![settings[@"modelProvider"] isEqual:@"gemini"] && ![settings[@"disableSlashCommands"] isEqual:@YES];
|
|
35
|
+
}
|
|
36
|
+
|
|
21
37
|
static NSString *ClaudeConfiguredMode(NSString *home) {
|
|
22
38
|
id settings = CCPetsReadConfig([home stringByAppendingPathComponent:@"settings.json"], NULL);
|
|
23
39
|
if (![settings isKindOfClass:CCPetsJSONObject.class]) return @"unknown";
|
|
@@ -61,6 +77,9 @@ static BOOL CodexHasCustomProvider(NSString *home) {
|
|
|
61
77
|
static NSString *ProbeAuthenticationMode(NSDictionary *profile, NSString *searchPath) {
|
|
62
78
|
NSString *provider = profile[@"provider"], *home = profile[@"home"];
|
|
63
79
|
if (!CCPetsDirectoryExists(home)) return @"unknown";
|
|
80
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
|
|
81
|
+
return CCPetsAntigravityUsesGeminiAPI(home) ? @"api" : @"unknown";
|
|
82
|
+
}
|
|
64
83
|
BOOL claude = [provider isEqualToString:@"claude"];
|
|
65
84
|
NSString *fallback = claude ? ClaudeConfiguredMode(home) : @"unknown";
|
|
66
85
|
if (!claude) {
|
|
@@ -124,7 +143,9 @@ void CCPetsRefreshProfileAuthenticationModes(NSArray<NSDictionary *> *profiles)
|
|
|
124
143
|
NSDictionary *previous;
|
|
125
144
|
@synchronized(CCPetsAuthenticationModesDidChangeNotification) { previous = AuthenticationModes[key]; }
|
|
126
145
|
if (previous && now - [previous[@"checkedAt"] doubleValue] < 60) continue;
|
|
127
|
-
if (!searchPath
|
|
146
|
+
if (!searchPath && ![profile[@"provider"] isEqualToString:CCPetsProfileProviderAntigravity]) {
|
|
147
|
+
searchPath = CCPetsLoginShellPath() ?: @"";
|
|
148
|
+
}
|
|
128
149
|
NSString *mode = ProbeAuthenticationMode(profile, searchPath);
|
|
129
150
|
@synchronized(CCPetsAuthenticationModesDidChangeNotification) {
|
|
130
151
|
if (!AuthenticationModes) AuthenticationModes = [NSMutableDictionary dictionary];
|
|
@@ -143,10 +164,15 @@ NSString *CCPetsProfileAuthenticationMode(NSDictionary *profile) {
|
|
|
143
164
|
}
|
|
144
165
|
}
|
|
145
166
|
|
|
167
|
+
static NSString *ProviderUsageModePreferenceKey(NSString *provider) {
|
|
168
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) return AntigravityUsageDisplayModeKey;
|
|
169
|
+
return [provider isEqualToString:CCPetsProfileProviderCodex] ? CodexUsageDisplayModeKey : ClaudeUsageDisplayModeKey;
|
|
170
|
+
}
|
|
171
|
+
|
|
146
172
|
NSString *CCPetsUsageModePreferenceKey(NSDictionary *profile) {
|
|
147
173
|
NSString *profileID = profile[@"id"];
|
|
148
174
|
if (profileID.length > 0) return [@"CCPetsUsageDisplayMode." stringByAppendingString:profileID];
|
|
149
|
-
return
|
|
175
|
+
return ProviderUsageModePreferenceKey(profile[@"provider"]);
|
|
150
176
|
}
|
|
151
177
|
|
|
152
178
|
BOOL CCPetsProfileCanSwitchUsageMode(NSDictionary *profile) {
|
|
@@ -157,7 +183,6 @@ BOOL CCPetsProfileShowsAPIUsage(NSDictionary *profile) {
|
|
|
157
183
|
if (!CCPetsProfileCanSwitchUsageMode(profile)) return YES;
|
|
158
184
|
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
159
185
|
NSString *mode = [defaults stringForKey:CCPetsUsageModePreferenceKey(profile)];
|
|
160
|
-
if (!mode) mode = [defaults stringForKey:
|
|
161
|
-
? CodexUsageDisplayModeKey : ClaudeUsageDisplayModeKey];
|
|
186
|
+
if (!mode) mode = [defaults stringForKey:ProviderUsageModePreferenceKey(profile[@"provider"])];
|
|
162
187
|
return [mode isEqualToString:@"api"];
|
|
163
188
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#import <Foundation/Foundation.h>
|
|
2
2
|
|
|
3
3
|
@interface CCPetsUsageMonitor : NSObject
|
|
4
|
-
@property(copy) void (^changeHandler)(NSDictionary
|
|
5
|
-
@property(readonly) NSDictionary *
|
|
6
|
-
|
|
7
|
-
//
|
|
4
|
+
@property(copy) void (^changeHandler)(NSDictionary<NSString *, NSDictionary *> *usageByProvider);
|
|
5
|
+
@property(readonly, copy) NSDictionary<NSString *, NSDictionary *> *usageByProvider;
|
|
6
|
+
// profileId → 当前用量;profiles 保持用户添加顺序。默认账号同时保留在 usageByProvider 中。
|
|
7
|
+
// 默认 Antigravity 账号的 appTokenUsage 单独记录 App 的本机用量。
|
|
8
8
|
@property(readonly) NSDictionary<NSString *, NSDictionary *> *profileUsages;
|
|
9
9
|
@property(readonly) NSArray<NSDictionary *> *profiles;
|
|
10
10
|
- (void)start;
|
|
@@ -17,17 +17,22 @@
|
|
|
17
17
|
// 会让桌宠窗口迟迟不出现、切换展示模式时整个界面卡死。
|
|
18
18
|
@interface CCPetsUsageMonitor ()
|
|
19
19
|
@property dispatch_queue_t queue;
|
|
20
|
+
@property dispatch_queue_t antigravityQueue;
|
|
20
21
|
@property CodexUsageReader *codexReader;
|
|
21
22
|
@property CCPetsCodexRateLimitsReader *codexRateLimitsReader;
|
|
22
23
|
@property ClaudeUsageReader *claudeReader;
|
|
23
|
-
@property(readwrite) NSDictionary *
|
|
24
|
-
|
|
24
|
+
@property(readwrite, copy) NSDictionary<NSString *, NSDictionary *> *usageByProvider;
|
|
25
|
+
// Reader 内部仍使用具名入口,外部统一读取 usageByProvider。
|
|
26
|
+
@property NSDictionary *codexUsage;
|
|
27
|
+
@property NSDictionary *claudeUsage;
|
|
25
28
|
@property(readwrite) NSDictionary<NSString *, NSDictionary *> *profileUsages;
|
|
26
29
|
@property(readwrite) NSArray<NSDictionary *> *profiles;
|
|
27
30
|
@property NSMutableDictionary<NSString *, ClaudeUsageReader *> *claudeProfileReaders;
|
|
28
31
|
@property NSMutableDictionary<NSString *, CodexUsageReader *> *codexProfileReaders;
|
|
29
32
|
@property NSMutableDictionary<NSString *, CCPetsCodexRateLimitsReader *> *codexProfileRateReaders;
|
|
30
33
|
@property NSMutableDictionary<NSString *, NSDictionary *> *codexProfileLiveUsages;
|
|
34
|
+
@property NSMutableDictionary<NSString *, NSDictionary *> *antigravityProfileUsages;
|
|
35
|
+
@property NSMutableDictionary<NSString *, NSObject *> *antigravityPendingRequests;
|
|
31
36
|
@property NSMutableDictionary<NSString *, NSString *> *profileReaderHomes;
|
|
32
37
|
@property NSDictionary *codexLiveUsage;
|
|
33
38
|
@property FSEventStreamRef codexStream;
|
|
@@ -45,6 +50,12 @@
|
|
|
45
50
|
// 窗口翻篇由 resets_at 兜底。只有"额度受限"标记有寿命——它没有窗口归属,实时查询连续
|
|
46
51
|
// 失败时不能让一次旧的受限结论一直挂着。
|
|
47
52
|
static const NSTimeInterval CodexLiveUsageTTL = 5 * 60.0;
|
|
53
|
+
static const NSTimeInterval AntigravityQuotaUsageTTL = 5 * 60.0;
|
|
54
|
+
|
|
55
|
+
static BOOL AntigravityHomeMatches(NSString *home, NSString *other) {
|
|
56
|
+
return [home.stringByStandardizingPath.stringByResolvingSymlinksInPath isEqualToString:
|
|
57
|
+
other.stringByStandardizingPath.stringByResolvingSymlinksInPath];
|
|
58
|
+
}
|
|
48
59
|
|
|
49
60
|
// 默认账号、自定义 Home、缓存恢复和实时回调共用同一条合并路径。
|
|
50
61
|
// 用采样时间计龄,轮询旧缓存不会延长受限标记的寿命;窗口百分比仍按新旧快照择优。
|
|
@@ -132,11 +143,23 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
132
143
|
}
|
|
133
144
|
|
|
134
145
|
@implementation CCPetsUsageMonitor
|
|
146
|
+
- (NSDictionary *)codexUsage { return self.usageByProvider[@"Codex"]; }
|
|
147
|
+
- (NSDictionary *)claudeUsage { return self.usageByProvider[@"Claude"]; }
|
|
148
|
+
- (void)setCodexUsage:(NSDictionary *)usage { [self setUsage:usage forProvider:@"Codex"]; }
|
|
149
|
+
- (void)setClaudeUsage:(NSDictionary *)usage { [self setUsage:usage forProvider:@"Claude"]; }
|
|
150
|
+
- (void)setUsage:(NSDictionary *)usage forProvider:(NSString *)name {
|
|
151
|
+
NSMutableDictionary *updated = [self.usageByProvider mutableCopy] ?: [NSMutableDictionary dictionary];
|
|
152
|
+
updated[name] = usage;
|
|
153
|
+
self.usageByProvider = updated;
|
|
154
|
+
}
|
|
135
155
|
- (instancetype)init {
|
|
136
156
|
if ((self = [super init])) {
|
|
157
|
+
_usageByProvider = @{};
|
|
137
158
|
_queue = dispatch_queue_create("com.universewang.cc-pets.usage",
|
|
138
159
|
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL,
|
|
139
160
|
QOS_CLASS_UTILITY, 0));
|
|
161
|
+
_antigravityQueue = dispatch_queue_create("com.universewang.cc-pets.usage.antigravity",
|
|
162
|
+
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, 0));
|
|
140
163
|
_codexReader = [CodexUsageReader new];
|
|
141
164
|
_codexRateLimitsReader = [CCPetsCodexRateLimitsReader new];
|
|
142
165
|
_claudeReader = [ClaudeUsageReader new];
|
|
@@ -144,6 +167,8 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
144
167
|
_codexProfileReaders = [NSMutableDictionary dictionary];
|
|
145
168
|
_codexProfileRateReaders = [NSMutableDictionary dictionary];
|
|
146
169
|
_codexProfileLiveUsages = [NSMutableDictionary dictionary];
|
|
170
|
+
_antigravityProfileUsages = [NSMutableDictionary dictionary];
|
|
171
|
+
_antigravityPendingRequests = [NSMutableDictionary dictionary];
|
|
147
172
|
_profileReaderHomes = [NSMutableDictionary dictionary];
|
|
148
173
|
// 桌宠是唯一的常驻读取者,摘要缓存由它维护并落盘。
|
|
149
174
|
_codexReader.persistsCache = YES;
|
|
@@ -173,11 +198,10 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
173
198
|
// 回调交给主线程:下游全是 UI(面板重排、气泡定位、系统通知)。
|
|
174
199
|
- (void)publishChange {
|
|
175
200
|
[self syncDefaultProfileUsages];
|
|
176
|
-
void (^handler)(NSDictionary *, NSDictionary *) = self.changeHandler;
|
|
201
|
+
void (^handler)(NSDictionary<NSString *, NSDictionary *> *) = self.changeHandler;
|
|
177
202
|
if (!handler) return;
|
|
178
|
-
NSDictionary *
|
|
179
|
-
|
|
180
|
-
dispatch_async(dispatch_get_main_queue(), ^{ handler(codex, claude); });
|
|
203
|
+
NSDictionary<NSString *, NSDictionary *> *usages = self.usageByProvider;
|
|
204
|
+
dispatch_async(dispatch_get_main_queue(), ^{ handler(usages); });
|
|
181
205
|
}
|
|
182
206
|
|
|
183
207
|
// 默认账号的卡片读的是 profileUsages,但 FSEvents、statusline 监听和 App Server 回调
|
|
@@ -206,12 +230,58 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
206
230
|
}
|
|
207
231
|
if (changed) self.profileUsages = usages;
|
|
208
232
|
}
|
|
233
|
+
|
|
234
|
+
- (void)requestAntigravityUsageForProfile:(NSString *)profileID home:(NSString *)home {
|
|
235
|
+
if (self.antigravityPendingRequests[profileID]) return;
|
|
236
|
+
NSObject *request = [NSObject new];
|
|
237
|
+
self.antigravityPendingRequests[profileID] = request;
|
|
238
|
+
dispatch_queue_t destination = self.queue;
|
|
239
|
+
BOOL defaultCLI = AntigravityHomeMatches(home, DefaultAntigravityConfigDirectory());
|
|
240
|
+
BOOL includesApp = AntigravityHomeMatches(home, DefaultAntigravityAppConfigDirectory());
|
|
241
|
+
__weak typeof(self) weakSelf = self;
|
|
242
|
+
dispatch_async(self.antigravityQueue, ^{
|
|
243
|
+
NSDictionary *quota = AntigravityRateLimitsForConfigDirectory(home);
|
|
244
|
+
NSDictionary *tokens = AntigravityTokenUsageForConfigDirectory(home);
|
|
245
|
+
NSDictionary *appTokens = includesApp && CCPetsAntigravityAppUsageAvailable()
|
|
246
|
+
? AntigravityAppTokenUsageForConfigDirectory(home) : nil;
|
|
247
|
+
dispatch_async(destination, ^{
|
|
248
|
+
typeof(self) strongSelf = weakSelf;
|
|
249
|
+
if (!strongSelf || !strongSelf.started ||
|
|
250
|
+
strongSelf.antigravityPendingRequests[profileID] != request) return;
|
|
251
|
+
[strongSelf.antigravityPendingRequests removeObjectForKey:profileID];
|
|
252
|
+
if (![strongSelf.profileReaderHomes[profileID] isEqualToString:home]) return;
|
|
253
|
+
|
|
254
|
+
NSDictionary *effectiveQuota = quota;
|
|
255
|
+
NSDictionary *previous = strongSelf.antigravityProfileUsages[profileID];
|
|
256
|
+
if (!quota && !CCPetsAntigravityUsesGeminiAPI(home) && [previous[@"sampledAt"] isKindOfClass:NSNumber.class] &&
|
|
257
|
+
NSDate.date.timeIntervalSince1970 - [previous[@"sampledAt"] doubleValue] < AntigravityQuotaUsageTTL) {
|
|
258
|
+
effectiveQuota = UsageByRemovingExpiredQuotaWindows(previous);
|
|
259
|
+
}
|
|
260
|
+
NSMutableDictionary *snapshot = [effectiveQuota mutableCopy] ?: [NSMutableDictionary dictionary];
|
|
261
|
+
snapshot[@"tokenUsage"] = tokens;
|
|
262
|
+
snapshot[@"appTokenUsage"] = appTokens;
|
|
263
|
+
NSDictionary *usage = snapshot.count > 0 ? [snapshot copy] : nil;
|
|
264
|
+
strongSelf.antigravityProfileUsages[profileID] = usage;
|
|
265
|
+
NSMutableDictionary *updated = [strongSelf.profileUsages mutableCopy];
|
|
266
|
+
updated[profileID] = usage;
|
|
267
|
+
strongSelf.profileUsages = updated;
|
|
268
|
+
if (defaultCLI) [strongSelf setUsage:usage forProvider:@"Antigravity"];
|
|
269
|
+
if (includesApp) {
|
|
270
|
+
[strongSelf setUsage:appTokens ? @{@"tokenUsage": appTokens} : nil forProvider:@"Antigravity App"];
|
|
271
|
+
}
|
|
272
|
+
[strongSelf publishChange];
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
209
277
|
- (void)refreshProfileUsages {
|
|
210
278
|
NSArray<NSDictionary *> *profiles = CCPetsProfiles();
|
|
211
279
|
NSMutableDictionary<NSString *, NSDictionary *> *usages = [NSMutableDictionary dictionary];
|
|
212
280
|
NSMutableSet<NSString *> *liveIDs = [NSMutableSet set];
|
|
213
281
|
NSString *defaultClaude = DefaultClaudeConfigDirectory().stringByStandardizingPath;
|
|
214
282
|
NSString *defaultCodex = DefaultCodexHomeDirectory().stringByStandardizingPath;
|
|
283
|
+
NSDictionary *defaultAntigravityUsage = nil;
|
|
284
|
+
NSDictionary *appTokens = nil;
|
|
215
285
|
for (NSDictionary *profile in profiles) {
|
|
216
286
|
NSString *profileID = profile[@"id"], *provider = profile[@"provider"];
|
|
217
287
|
NSString *home = [profile[@"home"] stringByStandardizingPath];
|
|
@@ -224,6 +294,8 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
224
294
|
[self.codexProfileRateReaders[profileID] stop];
|
|
225
295
|
[self.codexProfileRateReaders removeObjectForKey:profileID];
|
|
226
296
|
[self.codexProfileLiveUsages removeObjectForKey:profileID];
|
|
297
|
+
[self.antigravityProfileUsages removeObjectForKey:profileID];
|
|
298
|
+
[self.antigravityPendingRequests removeObjectForKey:profileID];
|
|
227
299
|
}
|
|
228
300
|
self.profileReaderHomes[profileID] = home;
|
|
229
301
|
NSDictionary *usage = nil;
|
|
@@ -271,6 +343,11 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
271
343
|
}
|
|
272
344
|
[rateReader refresh];
|
|
273
345
|
}
|
|
346
|
+
} else if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
|
|
347
|
+
usage = self.antigravityProfileUsages[profileID];
|
|
348
|
+
if (AntigravityHomeMatches(home, DefaultAntigravityConfigDirectory())) defaultAntigravityUsage = usage;
|
|
349
|
+
if (AntigravityHomeMatches(home, DefaultAntigravityAppConfigDirectory())) appTokens = usage[@"appTokenUsage"];
|
|
350
|
+
[self requestAntigravityUsageForProfile:profileID home:home];
|
|
274
351
|
}
|
|
275
352
|
if (usage) usages[profileID] = usage;
|
|
276
353
|
}
|
|
@@ -287,8 +364,13 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
287
364
|
}
|
|
288
365
|
}
|
|
289
366
|
for (NSString *profileID in self.profileReaderHomes.allKeys.copy) {
|
|
290
|
-
if (
|
|
367
|
+
if ([liveIDs containsObject:profileID]) continue;
|
|
368
|
+
[self.profileReaderHomes removeObjectForKey:profileID];
|
|
369
|
+
[self.antigravityProfileUsages removeObjectForKey:profileID];
|
|
370
|
+
[self.antigravityPendingRequests removeObjectForKey:profileID];
|
|
291
371
|
}
|
|
372
|
+
[self setUsage:defaultAntigravityUsage forProvider:@"Antigravity"];
|
|
373
|
+
[self setUsage:appTokens ? @{@"tokenUsage": appTokens} : nil forProvider:@"Antigravity App"];
|
|
292
374
|
self.profiles = profiles;
|
|
293
375
|
self.profileUsages = usages;
|
|
294
376
|
}
|
|
@@ -424,6 +506,7 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
424
506
|
dispatch_source_cancel(self.claudeSource);
|
|
425
507
|
self.claudeSource = nil;
|
|
426
508
|
}
|
|
509
|
+
[self.antigravityPendingRequests removeAllObjects];
|
|
427
510
|
}
|
|
428
511
|
- (void)dealloc {
|
|
429
512
|
[self stop];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#import "QuotaDashboardView+Private.h"
|
|
2
|
+
|
|
3
|
+
@implementation QuotaDashboardView (CompactRow)
|
|
4
|
+
- (void)drawCompactRowForProvider:(NSString *)name usage:(NSDictionary *)normalized rect:(NSRect)rect {
|
|
5
|
+
CGFloat x = NSMinX(rect), mid = NSMidY(rect), right = NSMaxX(rect);
|
|
6
|
+
NSRect row = NSMakeRect(x, mid - 22, NSWidth(rect), 44);
|
|
7
|
+
NSColor *color = [self colorForProvider:name];
|
|
8
|
+
NSBezierPath *background = [NSBezierPath bezierPathWithRoundedRect:row xRadius:10 yRadius:10];
|
|
9
|
+
if (self.usesLiquidGlass) [self fillLiquidScrim:background];
|
|
10
|
+
else [self fillRoundedRect:row radius:10 color:[NSColor colorWithWhite:1 alpha:0.075]];
|
|
11
|
+
|
|
12
|
+
NSRect icon = NSMakeRect(x + 10, mid - 14, 28, 28);
|
|
13
|
+
NSString *displayName = [self displayNameForProvider:name];
|
|
14
|
+
NSImage *logo = self.logoByProvider[name];
|
|
15
|
+
if (logo) {
|
|
16
|
+
[NSGraphicsContext saveGraphicsState];
|
|
17
|
+
[[NSBezierPath bezierPathWithRoundedRect:icon xRadius:7 yRadius:7] addClip];
|
|
18
|
+
[logo drawInRect:icon fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1];
|
|
19
|
+
[NSGraphicsContext restoreGraphicsState];
|
|
20
|
+
} else {
|
|
21
|
+
[self fillRoundedRect:icon radius:7 color:color];
|
|
22
|
+
NSString *initial = displayName.length
|
|
23
|
+
? [displayName substringWithRange:[displayName rangeOfComposedCharacterSequenceAtIndex:0]] : @"";
|
|
24
|
+
[initial drawInRect:NSInsetRect(icon, 1, 4) withAttributes:
|
|
25
|
+
[self centeredTextAttributesWithSize:15 color:NSColor.whiteColor weight:NSFontWeightBold]];
|
|
26
|
+
}
|
|
27
|
+
[self drawText:displayName inRect:NSMakeRect(x + 48, mid - 10, 116, 20)
|
|
28
|
+
size:15 weight:NSFontWeightSemibold color:self.primaryColor dotColor:nil];
|
|
29
|
+
NSDictionary *state = [self accountStateForProvider:name profile:[self selectedProfileForProvider:name] normalized:normalized];
|
|
30
|
+
NSColor *statusColor = [self statusColorForState:state];
|
|
31
|
+
NSString *status = [state[@"status"] stringByReplacingOccurrencesOfString:@"● " withString:@""];
|
|
32
|
+
if (!self.usesLiquidGlass) {
|
|
33
|
+
CGFloat width = [status sizeWithAttributes:[self textAttributesWithSize:12 color:statusColor
|
|
34
|
+
weight:NSFontWeightMedium]].width + 24;
|
|
35
|
+
[self fillRoundedRect:NSMakeRect(x + 168, mid - 10, width, 20)
|
|
36
|
+
radius:10 color:[statusColor colorWithAlphaComponent:0.13]];
|
|
37
|
+
}
|
|
38
|
+
[statusColor setFill];
|
|
39
|
+
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(x + 174, mid - 3, 6, 6)] fill];
|
|
40
|
+
[self drawText:status inRect:NSMakeRect(x + 185, mid - 9, 126, 18)
|
|
41
|
+
size:12 weight:NSFontWeightMedium color:statusColor dotColor:nil];
|
|
42
|
+
|
|
43
|
+
NSDictionary *tokens = normalized[@"tokens"];
|
|
44
|
+
NSString *today = [self formattedTokenCount:[self quota:tokens key:@"today"]];
|
|
45
|
+
[self drawText:[NSString stringWithFormat:L(@"Today %@"), today] inRect:NSMakeRect(x + 316, mid - 9, 134, 18)
|
|
46
|
+
size:13 weight:NSFontWeightMedium color:self.secondaryColor dotColor:nil];
|
|
47
|
+
|
|
48
|
+
NSString *billing = normalized[@"billing"];
|
|
49
|
+
NSRect metric = NSMakeRect(x + 456, mid - 9, right - (x + 456) - 32, 18);
|
|
50
|
+
if ([billing isEqualToString:@"subscription"]) {
|
|
51
|
+
NSDictionary *tightest = nil;
|
|
52
|
+
for (NSDictionary *window in normalized[@"windows"]) {
|
|
53
|
+
NSNumber *used = window[@"used"];
|
|
54
|
+
if (used && (!tightest || used.doubleValue > [tightest[@"used"] doubleValue])) tightest = window;
|
|
55
|
+
}
|
|
56
|
+
if (tightest) {
|
|
57
|
+
double remaining = 100 - [tightest[@"used"] doubleValue];
|
|
58
|
+
[self drawText:L(tightest[@"titleKey"]) inRect:NSMakeRect(NSMinX(metric), mid - 9, 96, 18)
|
|
59
|
+
size:12 weight:NSFontWeightMedium color:self.secondaryColor dotColor:nil];
|
|
60
|
+
NSRect bar = NSMakeRect(NSMinX(metric) + 102, mid - 3, 48, 6);
|
|
61
|
+
[self fillRoundedRect:bar radius:3 color:[color colorWithAlphaComponent:0.2]];
|
|
62
|
+
bar.size.width *= remaining / 100;
|
|
63
|
+
if (bar.size.width > 0) [self fillRoundedRect:bar radius:3 color:color];
|
|
64
|
+
metric.origin.x += 156;
|
|
65
|
+
metric.size.width -= 156;
|
|
66
|
+
[self drawText:[NSString stringWithFormat:@"%.0f%%", remaining] inRect:metric
|
|
67
|
+
size:13 weight:NSFontWeightSemibold color:self.primaryColor dotColor:nil];
|
|
68
|
+
} else {
|
|
69
|
+
[self drawText:@"--" inRect:metric size:13 weight:NSFontWeightMedium color:self.secondaryColor dotColor:nil];
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
NSString *text = L(@"No quota data");
|
|
73
|
+
NSString *month = [self formattedTokenCount:[self quota:tokens key:@"month"]];
|
|
74
|
+
if ([billing isEqualToString:@"api"]) text = [NSString stringWithFormat:L(@"API · This month %@"), month];
|
|
75
|
+
if ([billing isEqualToString:@"credits"]) text = [NSString stringWithFormat:L(@"Credits · This month %@"), month];
|
|
76
|
+
[self drawText:text inRect:metric size:13 weight:NSFontWeightMedium color:self.primaryColor dotColor:nil];
|
|
77
|
+
}
|
|
78
|
+
[self drawText:@"›" inRect:NSMakeRect(right - 21, mid - 12, 14, 24)
|
|
79
|
+
size:18 weight:NSFontWeightMedium color:self.secondaryColor dotColor:nil];
|
|
80
|
+
}
|
|
81
|
+
@end
|
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
// 没有深色底托着时,0.68 的灰在亮壁纸上会发虚。
|
|
9
9
|
return [NSColor colorWithWhite:self.usesLiquidGlass ? 0.84 : 0.68 alpha:1];
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
- (NSColor *)colorForProvider:(NSString *)name {
|
|
12
|
+
CCPetsProviderDescriptor *provider = CCPetsProviderForName(name);
|
|
13
|
+
NSArray<NSNumber *> *rgb = self.usesLiquidGlass ? provider.glassColorRGB : provider.standardColorRGB;
|
|
14
|
+
if (rgb.count != 3) return self.secondaryColor;
|
|
15
|
+
return [NSColor colorWithRed:rgb[0].doubleValue green:rgb[1].doubleValue blue:rgb[2].doubleValue alpha:1];
|
|
15
16
|
}
|
|
16
17
|
- (NSColor *)accentColor { return [NSColor colorWithRed:0.30 green:0.82 blue:0.90 alpha:1]; }
|
|
17
18
|
// 有 Agent 在线才用绿色,否则整块转灰,避免"暂无 Agent 在线"配一个绿点。
|
|
@@ -89,10 +90,6 @@
|
|
|
89
90
|
return [self formattedTokenSplit:[self tokenTotals:usage key:key] ?: @{}
|
|
90
91
|
wantsOutput:wantsOutput];
|
|
91
92
|
}
|
|
92
|
-
- (NSNumber *)usedForQuota:(NSDictionary *)quota usedKey:(NSString *)usedKey {
|
|
93
|
-
NSNumber *used = [quota[usedKey] isKindOfClass:NSNumber.class] ? quota[usedKey] : nil;
|
|
94
|
-
return used ? @(fmax(0, fmin(100, used.doubleValue))) : nil;
|
|
95
|
-
}
|
|
96
93
|
- (NSString *)refreshAgeText {
|
|
97
94
|
if (self.lastUpdatedAt <= 0) return L(@"Waiting for data");
|
|
98
95
|
NSTimeInterval age = fmax(0, NSDate.date.timeIntervalSince1970 - self.lastUpdatedAt);
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
#import "QuotaDashboardView.h"
|
|
3
3
|
#import "CCPetsL10n.h"
|
|
4
4
|
#import "CCPetsUsageMode.h"
|
|
5
|
+
#import "CCPetsNormalizedUsage.h"
|
|
5
6
|
|
|
6
7
|
// 面板高度按"检测到几家 CLI"变化,所以纵向布局不再是一堆绝对坐标,而是自上而下的分段:
|
|
7
8
|
// 标题区 → 汇总条 → N × 额度卡,块之间统一留 QuotaBlockGap。
|
|
8
9
|
// QuotaLogicalHeight 保留为两家都装时的高度(590),既是历史默认值,也是预览图尺寸。
|
|
9
10
|
static const CGFloat QuotaHeaderHeight = 106;
|
|
10
11
|
static const CGFloat QuotaSummaryHeight = 112;
|
|
12
|
+
static const CGFloat QuotaSummaryRowHeight = 38;
|
|
13
|
+
static const NSUInteger QuotaSummaryRowsPerPage = 2;
|
|
14
|
+
static const NSUInteger QuotaCollapsedCardCount = 2;
|
|
15
|
+
static const CGFloat QuotaCardsDisclosureHeight = 20;
|
|
11
16
|
static const CGFloat QuotaBaseCardHeight = 152;
|
|
12
17
|
static const CGFloat QuotaBlockGap = 12;
|
|
13
18
|
// 原脚注区占用 44px;保留 12px 外边距,其余空间平均分给可见卡片。
|
|
@@ -31,6 +36,9 @@ static inline CGFloat QuotaCardHeightForProviderCount(NSUInteger count) {
|
|
|
31
36
|
@property(copy) NSString *animatingCarouselProvider;
|
|
32
37
|
@property NSTimeInterval carouselAnimationStartedAt;
|
|
33
38
|
@property NSInteger carouselAnimationDirection;
|
|
39
|
+
@property(copy) NSArray<NSString *> *animatingCardOrder;
|
|
40
|
+
@property NSUInteger selectedSummaryPage;
|
|
41
|
+
@property BOOL quotaCardsExpanded;
|
|
34
42
|
@property(copy) NSString *dragCarouselProvider;
|
|
35
43
|
@property NSPoint dragCarouselStartPoint;
|
|
36
44
|
@property BOOL dragCarouselDidSwitch;
|
|
@@ -41,10 +49,19 @@ static inline CGFloat QuotaCardHeightForProviderCount(NSUInteger count) {
|
|
|
41
49
|
// 主文件里实现、绘图 category 也要用的方法。
|
|
42
50
|
- (NSArray<NSDictionary *> *)profilesForProvider:(NSString *)name;
|
|
43
51
|
- (NSDictionary *)summaryUsageForProvider:(NSString *)name;
|
|
52
|
+
- (NSDictionary *)summaryUsageForAntigravityApp;
|
|
44
53
|
- (NSString *)displayNameForProvider:(NSString *)name;
|
|
45
54
|
- (NSUInteger)selectedIndexForProvider:(NSString *)name;
|
|
55
|
+
- (NSUInteger)summaryPageCount;
|
|
56
|
+
- (NSUInteger)summaryPageIndex;
|
|
57
|
+
- (NSRect)logicalSummaryPageArrowRectForDirection:(NSInteger)direction;
|
|
58
|
+
- (NSRect)logicalSummaryPageDotRectAtIndex:(NSUInteger)index;
|
|
46
59
|
- (NSRect)logicalSummaryRect;
|
|
47
60
|
- (NSRect)logicalSummaryCellRectAtIndex:(NSUInteger)index;
|
|
61
|
+
- (NSArray<NSString *> *)displayedCardProviders;
|
|
62
|
+
- (BOOL)areQuotaCardsExpanded;
|
|
63
|
+
- (NSRect)logicalCardsDisclosureRect;
|
|
64
|
+
- (NSRect)logicalCardRectForProvider:(NSString *)target;
|
|
48
65
|
- (NSDictionary *)quota:(NSDictionary *)usage key:(NSString *)key;
|
|
49
66
|
- (NSDictionary *)tokenTotals:(NSDictionary *)usage key:(NSString *)key;
|
|
50
67
|
- (NSString *)formattedTokenValue:(double)value;
|
|
@@ -55,20 +72,21 @@ static inline CGFloat QuotaCardHeightForProviderCount(NSUInteger count) {
|
|
|
55
72
|
- (NSString *)formattedTokenSplit:(NSDictionary *)totals wantsOutput:(BOOL)wantsOutput;
|
|
56
73
|
- (NSString *)resetText:(NSDictionary *)quota showDate:(BOOL)showDate;
|
|
57
74
|
- (NSString *)recentWeekUsageLabel;
|
|
58
|
-
- (NSDictionary *)
|
|
75
|
+
- (NSDictionary *)normalizedUsageForProvider:(NSString *)name profile:(NSDictionary *)profile usage:(NSDictionary *)usage;
|
|
76
|
+
- (NSDictionary *)accountStateForProvider:(NSString *)name profile:(NSDictionary *)profile normalized:(NSDictionary *)normalized;
|
|
77
|
+
- (NSColor *)statusColorForState:(NSDictionary *)state;
|
|
59
78
|
@end
|
|
60
79
|
|
|
61
80
|
// 绘图基础:配色、文字排版、系统指标、圆角块和用量曲线。
|
|
62
81
|
@interface QuotaDashboardView (Primitives)
|
|
63
82
|
- (NSColor *)primaryColor;
|
|
64
83
|
- (NSColor *)secondaryColor;
|
|
65
|
-
- (NSColor *)claudeColor;
|
|
66
84
|
- (NSColor *)accentColor;
|
|
85
|
+
- (NSColor *)colorForProvider:(NSString *)name;
|
|
67
86
|
- (NSColor *)agentStatusColor;
|
|
68
87
|
- (void)drawSystemMetricsEndingAtX:(CGFloat)rightEdge y:(CGFloat)y;
|
|
69
88
|
- (NSString *)formattedTokenSplitForUsage:(NSDictionary *)usage key:(NSString *)key
|
|
70
89
|
wantsOutput:(BOOL)wantsOutput;
|
|
71
|
-
- (NSNumber *)usedForQuota:(NSDictionary *)quota usedKey:(NSString *)usedKey;
|
|
72
90
|
- (NSString *)refreshAgeText;
|
|
73
91
|
- (NSFont *)fontWithSize:(CGFloat)size weight:(NSFontWeight)weight;
|
|
74
92
|
- (void)drawText:(NSString *)text inRect:(NSRect)rect size:(CGFloat)size
|
|
@@ -96,8 +114,12 @@ static inline CGFloat QuotaCardHeightForProviderCount(NSUInteger count) {
|
|
|
96
114
|
// 卡片、汇总条和整块面板的绘制。
|
|
97
115
|
@interface QuotaDashboardView (Rendering)
|
|
98
116
|
- (void)drawProvider:(NSString *)name displayName:(NSString *)displayName
|
|
99
|
-
usage:(NSDictionary *)usage
|
|
117
|
+
usage:(NSDictionary *)usage color:(NSColor *)color
|
|
100
118
|
cardRect:(NSRect)card profileCount:(NSUInteger)profileCount selectedIndex:(NSUInteger)selectedIndex;
|
|
101
119
|
- (void)drawSummaryForProviders:(NSArray<NSString *> *)providers primary:(NSColor *)primary
|
|
102
120
|
secondary:(NSColor *)secondary accent:(NSColor *)cyan;
|
|
103
121
|
@end
|
|
122
|
+
|
|
123
|
+
@interface QuotaDashboardView (CompactRow)
|
|
124
|
+
- (void)drawCompactRowForProvider:(NSString *)name usage:(NSDictionary *)normalized rect:(NSRect)rect;
|
|
125
|
+
@end
|