cc-pets 2.2.0 → 2.3.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.
Files changed (173) hide show
  1. package/CC_BRIDGE.md +5 -2
  2. package/CC_BRIDGE.zh-CN.md +4 -2
  3. package/CHANGELOG.md +85 -0
  4. package/CHANGELOG.zh-CN.md +85 -0
  5. package/CONTRIBUTING.md +28 -11
  6. package/CONTRIBUTING.zh-CN.md +23 -11
  7. package/README.md +127 -27
  8. package/README.zh-CN.md +104 -30
  9. package/Resources/zh-Hans.lproj/Localizable.strings +573 -17
  10. package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
  11. package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +89 -31
  12. package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
  13. package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +18 -4
  14. package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +90 -21
  15. package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
  16. package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
  17. package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +269 -0
  18. package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +13 -7
  19. package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +71 -47
  20. package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
  21. package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +16 -2
  22. package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +110 -12
  23. package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
  24. package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
  25. package/Sources/CCPets/{main.m → App/main.m} +68 -1
  26. package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
  27. package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +32 -17
  28. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
  29. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +792 -0
  30. package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +60 -0
  31. package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +558 -0
  32. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
  33. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +501 -0
  34. package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +103 -0
  35. package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +779 -0
  36. package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
  37. package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
  38. package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
  39. package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
  40. package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
  41. package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
  42. package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
  43. package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
  44. package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +42 -12
  45. package/Sources/CCPets/Pet/CCPetsImageLoader.h +5 -0
  46. package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +10 -2
  47. package/Sources/CCPets/Pet/CCPetsPetSize.h +10 -0
  48. package/Sources/CCPets/Pet/CCPetsPetSize.m +21 -0
  49. package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
  50. package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
  51. package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +18 -2
  52. package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +53 -22
  53. package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +42 -2
  54. package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
  55. package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
  56. package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
  57. package/Sources/CCPets/Pet/PetView+Private.h +81 -0
  58. package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
  59. package/Sources/CCPets/Pet/PetView.m +635 -0
  60. package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
  61. package/Sources/CCPets/Support/CCPetsDoctor.m +632 -0
  62. package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
  63. package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
  64. package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
  65. package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
  66. package/Sources/CCPets/Support/CCPetsPreferences.h +31 -0
  67. package/Sources/CCPets/Support/CCPetsPreferences.m +85 -0
  68. package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
  69. package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
  70. package/Sources/CCPets/UI/CCPetsFormBuilder.h +42 -0
  71. package/Sources/CCPets/UI/CCPetsFormBuilder.m +268 -0
  72. package/Sources/CCPets/{CCPetsGlassView.h → UI/CCPetsGlassView.h} +5 -1
  73. package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +25 -7
  74. package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
  75. package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
  76. package/Sources/CCPets/UI/CCPetsSettingsPage.h +62 -0
  77. package/Sources/CCPets/UI/CCPetsSettingsPage.m +917 -0
  78. package/Sources/CCPets/UI/CCPetsUIStyle.h +132 -0
  79. package/Sources/CCPets/UI/CCPetsUIStyle.m +816 -0
  80. package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
  81. package/Sources/CCPets/UI/CCPetsUsageChartView.m +284 -0
  82. package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
  83. package/Sources/CCPets/UI/CCPetsUsagePage.m +717 -0
  84. package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
  85. package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
  86. package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
  87. package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
  88. package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
  89. package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
  90. package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
  91. package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +3 -0
  92. package/Sources/CCPets/UI/MenuPetSizeView.h +5 -0
  93. package/Sources/CCPets/UI/MenuPetSizeView.m +73 -0
  94. package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
  95. package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
  96. package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
  97. package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
  98. package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
  99. package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
  100. package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
  101. package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
  102. package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +96 -0
  103. package/Sources/CCPets/Usage/CCPetsUsage+Models.m +285 -0
  104. package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
  105. package/Sources/CCPets/Usage/CCPetsUsage.h +57 -0
  106. package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
  107. package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
  108. package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
  109. package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
  110. package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +163 -6
  111. package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
  112. package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
  113. package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +616 -0
  114. package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
  115. package/Sources/CCPets/Usage/QuotaDashboardView.m +587 -0
  116. package/THIRD_PARTY_NOTICES.md +1 -1
  117. package/THIRD_PARTY_NOTICES.zh-CN.md +1 -1
  118. package/bin/cc-pets +8 -6
  119. package/bin/claude-with-pet +10 -2
  120. package/bin/codex-with-pet +13 -5
  121. package/package.json +1 -1
  122. package/scripts/build.sh +7 -3
  123. package/scripts/i18n.zsh +9 -52
  124. package/scripts/install-app.sh +4 -0
  125. package/scripts/install-shell-integration.sh +17 -10
  126. package/scripts/uninstall-shell-integration.sh +6 -1
  127. package/Sources/CCPets/CCPetsAppDelegate+Settings.m +0 -226
  128. package/Sources/CCPets/CCPetsEvents.h +0 -10
  129. package/Sources/CCPets/CCPetsImageLoader.h +0 -4
  130. package/Sources/CCPets/CCPetsUsage.h +0 -36
  131. package/Sources/CCPets/CCPetsUsage.m +0 -2069
  132. package/Sources/CCPets/PetView.m +0 -1806
  133. package/Sources/CCPets/QuotaDashboardView.m +0 -1145
  134. package/scripts/bridge/cli.mjs +0 -237
  135. package/scripts/bridge/core.mjs +0 -228
  136. package/scripts/bridge/hook.mjs +0 -150
  137. package/scripts/bridge/install.mjs +0 -311
  138. package/scripts/bridge/mcp-server.mjs +0 -308
  139. package/scripts/bridge/options.mjs +0 -87
  140. package/scripts/bridge/process.mjs +0 -151
  141. package/scripts/bridge/reservations.mjs +0 -248
  142. package/scripts/bridge/store.mjs +0 -433
  143. package/scripts/bridge/watch.mjs +0 -69
  144. package/scripts/check-l10n.mjs +0 -168
  145. package/scripts/configure-updater.mjs +0 -43
  146. package/scripts/detect-cli.mjs +0 -68
  147. package/scripts/doctor.mjs +0 -470
  148. package/scripts/i18n.mjs +0 -122
  149. package/scripts/install-claude-hooks.mjs +0 -253
  150. package/scripts/install-codex-hooks.mjs +0 -78
  151. package/scripts/integration-markers.mjs +0 -51
  152. package/scripts/locales/zh-Hans.json +0 -366
  153. package/scripts/pet-store.mjs +0 -415
  154. package/scripts/uninstall-integrations.mjs +0 -205
  155. /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
  156. /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
  157. /package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +0 -0
  158. /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
  159. /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
  160. /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
  161. /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
  162. /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
  163. /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
  164. /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
  165. /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
  166. /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
  167. /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
  168. /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
  169. /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
  170. /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
  171. /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
  172. /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
  173. /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
@@ -0,0 +1,57 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ // Codex 与 Claude 的额度读取。
4
+ int RecordClaudeUsage(void);
5
+ NSDictionary *ClaudeRateLimits(void);
6
+ NSDictionary *ClaudeRateLimitsForConfigDirectory(NSString *configDirectory);
7
+ NSDictionary *LatestClaudeUsage(void);
8
+ NSDictionary *LatestUsage(void);
9
+ // 清掉 resets_at 已经翻篇(或不可能属于当前窗口)的额度窗口,缺 resets_at 的保留。
10
+ NSDictionary *UsageByRemovingExpiredQuotaWindows(NSDictionary *usage);
11
+
12
+ // 增量跟读 ~/.claude/projects 下的会话转录,按官方 5 小时 / 7 天窗口聚合本地 Token。
13
+ @interface ClaudeUsageReader : NSObject
14
+ @property NSURL *projectsURL;
15
+ // 只有常驻的桌宠进程写摘要缓存。--status / --hook 这类一次性命令照样读它(省下冷解析),
16
+ // 但绝不能写:它们按各自当时的窗口把缓存剪一遍再存回去,等于把桌宠攒下的月度条目清掉。
17
+ @property BOOL persistsCache;
18
+ - (instancetype)initWithConfigDirectory:(NSString *)configDirectory;
19
+ - (NSDictionary *)refresh;
20
+ - (NSDictionary *)refreshWithFullAggregation;
21
+ @end
22
+
23
+ // 增量跟读当前 Codex 会话文件:只在会话切换时做一次冷读,之后按偏移追读。
24
+ @interface CodexUsageReader : NSObject
25
+ @property NSURL *sessionsURL;
26
+ // 见 ClaudeUsageReader.persistsCache。
27
+ @property BOOL persistsCache;
28
+ @property NSURL *sessionURL;
29
+ @property NSDictionary *usage;
30
+ @property unsigned long long offset;
31
+ @property NSMutableData *partialLine;
32
+ @property NSTimeInterval lastFullDiscovery;
33
+ - (instancetype)initWithCodexHome:(NSString *)codexHome;
34
+ - (NSDictionary *)refresh;
35
+ - (NSDictionary *)refreshWithFullDiscovery;
36
+ // 一批 FSEvents 里可能有多个会话文件同时变更(并发会话)。谁的额度采样更晚要读过才知道,
37
+ // 不能取遍历到的最后一个,详见实现处注释。
38
+ - (NSDictionary *)refreshForSessionURLs:(NSArray<NSURL *> *)urls;
39
+ @end
40
+
41
+ // 按模型的用量,provider 为 "claude" 或 "codex"(别的返回 nil)。统计 [start, end) 之间的自然日
42
+ // (start / end 应是日零点),数据来自本机会话日志,不联网。会读整段区间的会话文件,首次可能耗时
43
+ // 数百毫秒到数秒,只在后台队列调用。结果:
44
+ // models: @{模型名: counts} 区间合计
45
+ // daily: @[@{timestamp: 日零点, models: @{模型名: counts}}] 每天一项,没数据的天 models 为空
46
+ // counts 的键:input(非缓存输入)/ cacheRead / cacheWrite / output / reasoning(output 的子集)/
47
+ // requests。四栏 input + cacheRead + cacheWrite + output 互不重叠,等于总 Token。
48
+ // 用自己的缓存和按日归档(Claude Code 默认约 30 天后清理转录,归档里留得更久),
49
+ // 不碰桌宠悬停面板用的那套缓存。
50
+ // 每次调用都会把缓存清理到只剩 [start, end) 涉及的会话文件,所以调用方应固定用同一个最长区间,
51
+ // 短区间在结果里自己截取;区间来回切会让较早会话的缓存被删了又整篇重读。
52
+ NSDictionary *CCPetsModelUsage(NSString *provider, NSTimeInterval start, NSTimeInterval end);
53
+ NSDictionary *CCPetsModelUsageAtHome(NSString *provider, NSString *home,
54
+ NSTimeInterval start, NSTimeInterval end);
55
+ // 一份 counts 的总 Token = input + cacheRead + cacheWrite + output(reasoning 是 output 的子集,不另加)。
56
+ // 数据层归档取大和 UI 的合计共用这一个口径。
57
+ unsigned long long CCPetsTotalTokens(NSDictionary *counts);
@@ -0,0 +1,225 @@
1
+ #import "CCPetsUsage+Internal.h"
2
+ #import "CCPetsPaths.h"
3
+ #import <sys/file.h>
4
+ #import <sys/stat.h>
5
+ #import <errno.h>
6
+ #import <fcntl.h>
7
+ #import <unistd.h>
8
+
9
+ // 时钟偏差与整分对齐的余量。resets_at 本身是整分的,这点余量只是不想让几秒的偏差
10
+ // 把一份本来正常的快照判死。
11
+ static const NSTimeInterval QuotaResetSkewSeconds = 600.0;
12
+
13
+ // 一份快照要么描述当前窗口,要么就没有任何用处:resets_at 落在过去说明这个窗口早就翻篇,
14
+ // 落在一个窗长之外则根本不可能是它的重置时刻。2026-08-19 实测被顶进来的坏快照正是后者
15
+ // ——5 小时窗口的 resets_at 报到了十几小时之后。两种都在入口就拒绝,别让它进文件。
16
+ BOOL ResetLooksCurrentAt(double reset, double windowMinutes, NSTimeInterval sampledAt) {
17
+ if (reset <= 0 || windowMinutes <= 0) return NO;
18
+ return reset > sampledAt && reset <= sampledAt + windowMinutes * 60.0 + QuotaResetSkewSeconds;
19
+ }
20
+
21
+ BOOL QuotaWindowLooksCurrentAt(NSDictionary *quota, double windowMinutes,
22
+ NSTimeInterval sampledAt) {
23
+ NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class] ? quota[@"resets_at"] : nil;
24
+ if (!reset) return NO;
25
+ return ResetLooksCurrentAt(reset.doubleValue, windowMinutes, sampledAt);
26
+ }
27
+
28
+ BOOL QuotaWindowLooksCurrent(NSDictionary *quota, double windowMinutes, NSTimeInterval now) {
29
+ return QuotaWindowLooksCurrentAt(quota, windowMinutes, now);
30
+ }
31
+
32
+ // Codex 的 rate_limits 是一份会话快照,不会在窗口自然重置时自行刷新。一个快照里的
33
+ // 5 小时和 7 天窗口因此可能处于不同状态:例如 5 小时的 resets_at 已过去几天,但 7 天
34
+ // 的仍在未来。不能因为后者还活着,就把前者的旧百分比继续当成当前额度展示。
35
+ //
36
+ // 缺 resets_at 的旧版记录暂时保留,兼容历史会话和只提供百分比的上游版本;只要服务端给了
37
+ // 重置时间,就必须用它校验窗口。这个函数放在读取层而不是绘制层,状态栏、历史曲线和气泡
38
+ // 台词才能使用同一份已校正的数据。
39
+ NSDictionary *UsageByRemovingInactiveQuotaWindows(NSDictionary *usage) {
40
+ if (![usage isKindOfClass:NSDictionary.class]) return usage;
41
+ NSTimeInterval now = NSDate.date.timeIntervalSince1970;
42
+ NSDictionary<NSString *, NSNumber *> *windows = @{
43
+ @"fiveHour": @(FiveHourWindowMinutes),
44
+ @"week": @(SevenDayWindowMinutes)
45
+ };
46
+ NSMutableDictionary *result = nil;
47
+ NSMutableDictionary *expired = nil;
48
+ for (NSString *key in windows) {
49
+ NSDictionary *quota = [usage[key] isKindOfClass:NSDictionary.class] ? usage[key] : nil;
50
+ NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class]
51
+ ? quota[@"resets_at"] : nil;
52
+ if (!reset || QuotaWindowLooksCurrent(quota, windows[key].doubleValue, now)) continue;
53
+ if (!result) result = [usage mutableCopy];
54
+ result[key] = NSNull.null;
55
+ // 百分比不再展示,但 resets_at 必须留下。窗口一旦被清空,"这个窗口已经重置过"
56
+ // 就再也无从得知——而缺失的窗口本来就用 NSNull 表示(官方没给),两者混在一起
57
+ // 分不开。ExhaustionStillHolds 要靠这份记录让受限标记按时失效,否则只剩一个
58
+ // 未到期的 7 天窗口时,一次限流会让卡片永久挂着"额度受限"。
59
+ if (!expired) expired = [NSMutableDictionary dictionary];
60
+ expired[key] = reset;
61
+ }
62
+ if (expired) result[@"expiredWindowResets"] = expired;
63
+ return result ?: usage;
64
+ }
65
+
66
+ NSDictionary *UsageByRemovingExpiredQuotaWindows(NSDictionary *usage) {
67
+ return UsageByRemovingInactiveQuotaWindows(usage);
68
+ }
69
+
70
+ // 同一个账号下的每个 Claude 会话都会把自己那次响应里的 rate_limits 抄到同一个文件上,
71
+ // 而"响应更早、落盘更晚"在并发会话下完全正常。无条件覆盖时旧快照会盖掉新快照,面板上
72
+ // 的剩余额度于是来回跳(实测 99% → 94% → 又回 99%)。同一窗口内官方用量只增不减,
73
+ // 据此逐窗口丢弃倒退的快照。
74
+ //
75
+ // 判据刻意**不比较两份快照的 resets_at**。7 天窗口是滚动的,resets_at 随着旧用量滑出
76
+ // 窗口不断前移,前后两次上报差出十几个小时都算正常;原先写的"resets_at 变了就当窗口
77
+ // 滚动、无条件接受归零"于是对 7 天窗口几乎每次都成立,这道防线等同于从未生效——
78
+ // 2026-08-19 实测面板被一份 used=2% 的旧快照顶成剩余 98%,就是从这条分支进来的。
79
+ // 真正的窗口滚动只可能发生在旧窗口到期之后,拿 now 和 storedReset 判断就够了。
80
+ //
81
+ // 用量真的下降(官方口径调整、临时提额)时单调性不成立,只能靠"这份快照来自更新的响应"
82
+ // 放行。freshSince / storedSince 就是两份快照各自对应响应的时刻(见 QuotaValueSince)。
83
+ // 原先这里是"上次接受已过 10 分钟就无条件放行",但 statusline 配了 refreshInterval 时,
84
+ // 每个开着的空闲会话每分钟都会把自己最后一次响应里的旧额度重报一遍:活跃会话一关,
85
+ // 10 分钟后面板就被某个空闲会话的旧值顶掉(2026-09-29 实测剩余 18% → 跳回 70%)。
86
+ static BOOL ShouldAcceptQuotaWindow(id storedValue, NSDictionary *fresh, double windowMinutes,
87
+ NSTimeInterval freshSince, NSTimeInterval storedSince, NSTimeInterval now) {
88
+ if (!QuotaWindowLooksCurrent(fresh, windowMinutes, now)) return NO;
89
+ NSDictionary *stored = [storedValue isKindOfClass:NSDictionary.class] ? storedValue : nil;
90
+ if (!stored) return YES;
91
+ // 旧窗口确实到期了:新周期里用量归零是真的。
92
+ if (now >= [stored[@"resets_at"] doubleValue]) return YES;
93
+ if ([fresh[@"used_percentage"] doubleValue] >= [stored[@"used_percentage"] doubleValue]) return YES;
94
+ return freshSince > storedSince;
95
+ }
96
+
97
+ // 一份快照对应的响应是什么时候拿到的。statusline 的 payload 不带这个时刻,只能按会话推断:
98
+ // 同一个会话重报的值和它上次一模一样,说明它没有拿到新响应,时刻沿用上次记下的;值变了
99
+ // 才是新响应,记为现在。第一次见到的会话记 0(未知)——它可能是早就开着的空闲会话,
100
+ // 不能凭"刚被看到"就当成最新;它下一次真的变了自然会拿到时刻。
101
+ static NSTimeInterval QuotaValueSince(NSDictionary *previous, NSDictionary *fresh, NSTimeInterval now) {
102
+ if (![previous isKindOfClass:NSDictionary.class]) return 0;
103
+ BOOL unchanged = [previous[@"used_percentage"] isEqual:fresh[@"used_percentage"]] &&
104
+ [previous[@"resets_at"] isEqual:fresh[@"resets_at"]];
105
+ return unchanged ? [previous[@"since"] doubleValue] : now;
106
+ }
107
+
108
+ // 会话记录只为判断"值有没有变",一天没再上报的会话早就关了;上限防止异常情况下无限增长。
109
+ static const NSTimeInterval QuotaSessionRecordTTL = 24 * 60 * 60;
110
+ static const NSUInteger QuotaSessionRecordLimit = 64;
111
+
112
+ // 拿锁的重试上限。拿不到就放弃这次写入:并发写者手里的数据同样新鲜,跳过一次不丢信息,
113
+ // 而无锁写入正是要避免的读改写交错。阻塞版 flock 没有超时,一个被 SIGSTOP 或卡在慢速
114
+ // 卷上的写者会把之后每一次 statusline 渲染永久挂住,那是比丢一次采样糟得多的故障。
115
+ static const int QuotaLockAttempts = 50;
116
+ static const useconds_t QuotaLockRetryMicroseconds = 20 * 1000;
117
+
118
+ static int AcquireQuotaLock(NSString *lockPath) {
119
+ int descriptor = open(lockPath.fileSystemRepresentation, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR);
120
+ if (descriptor < 0) return -1;
121
+ for (int attempt = 0; attempt < QuotaLockAttempts; attempt++) {
122
+ if (flock(descriptor, LOCK_EX | LOCK_NB) == 0) return descriptor;
123
+ if (errno != EWOULDBLOCK) break;
124
+ usleep(QuotaLockRetryMicroseconds);
125
+ }
126
+ close(descriptor);
127
+ return -1;
128
+ }
129
+
130
+ int RecordClaudeUsage(void) {
131
+ NSData *input = [NSFileHandle.fileHandleWithStandardInput readDataToEndOfFile];
132
+ NSDictionary *payload = input.length > 0 ? [NSJSONSerialization JSONObjectWithData:input options:0 error:nil] : nil;
133
+ NSDictionary *limits = [payload[@"rate_limits"] isKindOfClass:NSDictionary.class] ? payload[@"rate_limits"] : nil;
134
+ if (!limits) return EXIT_SUCCESS;
135
+
136
+ NSString *path = ClaudeUsagePath();
137
+ // 判据要先读后写,多个会话同时跑就会读改写交错,所以整段必须在锁里。
138
+ int lockDescriptor = AcquireQuotaLock(ClaudeUsageLockPath());
139
+ if (lockDescriptor < 0) return EXIT_SUCCESS;
140
+
141
+ NSData *existing = [NSData dataWithContentsOfFile:path];
142
+ id storedValue = existing.length > 0
143
+ ? [NSJSONSerialization JSONObjectWithData:existing options:0 error:nil] : nil;
144
+ NSDictionary *stored = [storedValue isKindOfClass:NSDictionary.class] ? storedValue : nil;
145
+ NSTimeInterval now = NSDate.date.timeIntervalSince1970;
146
+ NSDictionary *storedSinceValue = [stored[@"value_since"] isKindOfClass:NSDictionary.class]
147
+ ? stored[@"value_since"] : @{};
148
+ NSMutableDictionary *sessions = [stored[@"sessions"] isKindOfClass:NSDictionary.class]
149
+ ? [stored[@"sessions"] mutableCopy] : [NSMutableDictionary dictionary];
150
+ // 没有 session_id 的 payload 无法区分"空闲重报"和"新响应",只按单调性判。
151
+ NSString *sessionID = [payload[@"session_id"] isKindOfClass:NSString.class] &&
152
+ [payload[@"session_id"] length] > 0 ? payload[@"session_id"] : nil;
153
+ NSDictionary *previousRecord = [sessions[sessionID] isKindOfClass:NSDictionary.class]
154
+ ? sessions[sessionID] : nil;
155
+ NSMutableDictionary *sessionRecord = [@{@"seen_at": @(now)} mutableCopy];
156
+
157
+ NSMutableDictionary *merged = stored ? [stored mutableCopy] : [NSMutableDictionary dictionary];
158
+ [merged removeObjectForKey:@"accepted_at"]; // 上一版的逃生阀字段,已不再使用。
159
+ NSMutableDictionary *mergedSince = [storedSinceValue mutableCopy];
160
+ NSDictionary *windowMinutes = @{@"five_hour": @(FiveHourWindowMinutes),
161
+ @"seven_day": @(SevenDayWindowMinutes)};
162
+ for (NSString *key in @[@"five_hour", @"seven_day"]) {
163
+ NSDictionary *fresh = [limits[key] isKindOfClass:NSDictionary.class] ? limits[key] : nil;
164
+ if (!fresh) continue; // 这次响应没带某个窗口时保留旧的:整体覆盖会让面板凭空少掉一个窗口。
165
+ NSTimeInterval freshSince = sessionID ? QuotaValueSince(previousRecord[key], fresh, now) : 0;
166
+ if (sessionID) {
167
+ sessionRecord[key] = @{@"used_percentage": fresh[@"used_percentage"] ?: NSNull.null,
168
+ @"resets_at": fresh[@"resets_at"] ?: NSNull.null,
169
+ @"since": @(freshSince)};
170
+ }
171
+ NSTimeInterval storedSince = [storedSinceValue[key] doubleValue];
172
+ if (!ShouldAcceptQuotaWindow(stored[key], fresh, [windowMinutes[key] doubleValue],
173
+ freshSince, storedSince, now)) continue;
174
+ merged[key] = fresh;
175
+ // 按单调性收下的旧响应不能把时刻往回拨,否则更旧的快照就能借它反超。
176
+ mergedSince[key] = @(fmax(freshSince, storedSince));
177
+ }
178
+ merged[@"value_since"] = mergedSince;
179
+
180
+ if (sessionID) sessions[sessionID] = sessionRecord;
181
+ for (NSString *key in sessions.allKeys) {
182
+ NSDictionary *record = [sessions[key] isKindOfClass:NSDictionary.class] ? sessions[key] : nil;
183
+ if (!record || now - [record[@"seen_at"] doubleValue] > QuotaSessionRecordTTL) {
184
+ [sessions removeObjectForKey:key];
185
+ }
186
+ }
187
+ if (sessions.count > QuotaSessionRecordLimit) {
188
+ NSArray *oldestFirst = [sessions keysSortedByValueUsingComparator:^NSComparisonResult(id left, id right) {
189
+ return [left[@"seen_at"] compare:right[@"seen_at"]];
190
+ }];
191
+ [sessions removeObjectsForKeys:[oldestFirst subarrayWithRange:
192
+ NSMakeRange(0, sessions.count - QuotaSessionRecordLimit)]];
193
+ }
194
+ merged[@"sessions"] = sessions;
195
+ // 最后一次写盘时间。不再参与任何判据,只留给排查用。
196
+ merged[@"written_at"] = @(now);
197
+
198
+ NSData *json = [NSJSONSerialization dataWithJSONObject:merged options:0 error:nil];
199
+ if (json && [json writeToFile:path options:NSDataWritingAtomic error:nil]) {
200
+ chmod(path.fileSystemRepresentation, S_IRUSR | S_IWUSR);
201
+ }
202
+ flock(lockDescriptor, LOCK_UN);
203
+ close(lockDescriptor);
204
+ return EXIT_SUCCESS;
205
+ }
206
+
207
+ NSDictionary *ClaudeRateLimits(void) {
208
+ return ClaudeRateLimitsForConfigDirectory(DefaultClaudeConfigDirectory());
209
+ }
210
+
211
+ NSDictionary *ClaudeRateLimitsForConfigDirectory(NSString *configDirectory) {
212
+ NSData *data = [NSData dataWithContentsOfFile:
213
+ ClaudeUsagePathForConfigDirectory(configDirectory)];
214
+ NSDictionary *limits = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
215
+ if (![limits isKindOfClass:NSDictionary.class]) return nil;
216
+ id fiveHour = [limits[@"five_hour"] isKindOfClass:NSDictionary.class] ? limits[@"five_hour"] : NSNull.null;
217
+ id week = [limits[@"seven_day"] isKindOfClass:NSDictionary.class] ? limits[@"seven_day"] : NSNull.null;
218
+ // 快照只在有会话上报时更新。窗口到期后没人再报,旧百分比会一直挂着(实测 5 小时窗口
219
+ // 重置后面板仍显示剩余 0%),与 Codex 同样按 resets_at 清掉已经翻篇的窗口。
220
+ return UsageByRemovingInactiveQuotaWindows(@{@"fiveHour": fiveHour, @"week": week});
221
+ }
222
+
223
+ NSDictionary *LatestClaudeUsage(void) {
224
+ return [[ClaudeUsageReader new] refreshWithFullAggregation];
225
+ }
@@ -0,0 +1,10 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ extern NSNotificationName const CCPetsAuthenticationModesDidChangeNotification;
4
+ // 只缓存认证类型,不缓存或输出密钥。必须在后台调用;按账号 Home 隔离,最多每分钟探测一次。
5
+ void CCPetsRefreshProfileAuthenticationModes(NSArray<NSDictionary *> *profiles);
6
+ // api / subscription / unknown。UI 只读内存快照,不启动 CLI。
7
+ NSString *CCPetsProfileAuthenticationMode(NSDictionary *profile);
8
+ NSString *CCPetsUsageModePreferenceKey(NSDictionary *profile);
9
+ BOOL CCPetsProfileShowsAPIUsage(NSDictionary *profile);
10
+ BOOL CCPetsProfileCanSwitchUsageMode(NSDictionary *profile);
@@ -0,0 +1,163 @@
1
+ #import "CCPetsUsageMode.h"
2
+ #import "CCPetsCLISupport.h"
3
+ #import "CCPetsJSON.h"
4
+ #import "CCPetsPaths.h"
5
+
6
+ NSNotificationName const CCPetsAuthenticationModesDidChangeNotification = @"CCPetsAuthenticationModesDidChange";
7
+ static NSMutableDictionary<NSString *, NSDictionary *> *AuthenticationModes;
8
+
9
+ static NSString *ProfileCacheKey(NSDictionary *profile) {
10
+ return [NSString stringWithFormat:@"%@:%@", profile[@"provider"] ?: @"", profile[@"home"] ?: @""];
11
+ }
12
+
13
+ static BOOL HasString(id value) { return [value isKindOfClass:NSString.class] && [value length] > 0; }
14
+
15
+ static NSDictionary *ReadJSONObject(NSString *path) {
16
+ NSData *data = [NSData dataWithContentsOfFile:path];
17
+ id object = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
18
+ return [object isKindOfClass:NSDictionary.class] ? object : nil;
19
+ }
20
+
21
+ static NSString *ClaudeConfiguredMode(NSString *home) {
22
+ id settings = CCPetsReadConfig([home stringByAppendingPathComponent:@"settings.json"], NULL);
23
+ if (![settings isKindOfClass:CCPetsJSONObject.class]) return @"unknown";
24
+ id env = settings[@"env"];
25
+ if (![env isKindOfClass:CCPetsJSONObject.class]) env = nil;
26
+ for (NSString *key in @[@"ANTHROPIC_API_KEY", @"ANTHROPIC_AUTH_TOKEN"]) {
27
+ if (HasString(env[key])) return @"api";
28
+ }
29
+ for (NSString *key in @[@"CLAUDE_CODE_USE_BEDROCK", @"CLAUDE_CODE_USE_VERTEX", @"CLAUDE_CODE_USE_FOUNDRY"]) {
30
+ id value = env[key];
31
+ if ([value respondsToSelector:@selector(boolValue)] && [value boolValue]) return @"api";
32
+ }
33
+ if (HasString(settings[@"apiKeyHelper"])) return @"api";
34
+ if (HasString(env[@"CLAUDE_CODE_OAUTH_TOKEN"])) return @"subscription";
35
+ return @"unknown";
36
+ }
37
+
38
+ // 不能把第三方推理服务的 ChatGPT 登录身份等同于订阅计费。
39
+ // 只识别简单、明确的顶层配置;复杂 TOML 或第三方路由保持 unknown。
40
+ static BOOL CodexHasCustomProvider(NSString *home) {
41
+ NSString *config = [NSString stringWithContentsOfFile:[home stringByAppendingPathComponent:@"config.toml"]
42
+ encoding:NSUTF8StringEncoding error:nil];
43
+ __block BOOL custom = NO;
44
+ NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:
45
+ @"^(?:[\"']?)(model_provider|profile)(?:[\"']?)\\s*=\\s*['\"]([^'\"]+)['\"]\\s*(?:#.*)?$"
46
+ options:0 error:nil];
47
+ [config enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) {
48
+ NSString *trimmed = [line stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
49
+ if ([trimmed hasPrefix:@"["]) { *stop = YES; return; }
50
+ if ([trimmed hasPrefix:@"#"]) return;
51
+ NSTextCheckingResult *match = [expression firstMatchInString:trimmed options:0 range:NSMakeRange(0, trimmed.length)];
52
+ if (match) {
53
+ custom = [[trimmed substringWithRange:[match rangeAtIndex:1]] isEqualToString:@"profile"] ||
54
+ ![[trimmed substringWithRange:[match rangeAtIndex:2]] isEqualToString:@"openai"];
55
+ *stop = YES;
56
+ }
57
+ }];
58
+ return custom;
59
+ }
60
+
61
+ static NSString *ProbeAuthenticationMode(NSDictionary *profile, NSString *searchPath) {
62
+ NSString *provider = profile[@"provider"], *home = profile[@"home"];
63
+ if (!CCPetsDirectoryExists(home)) return @"unknown";
64
+ BOOL claude = [provider isEqualToString:@"claude"];
65
+ NSString *fallback = claude ? ClaudeConfiguredMode(home) : @"unknown";
66
+ if (!claude) {
67
+ // https://github.com/openai/codex/blob/main/codex-rs/login/src/auth/storage.rs
68
+ // 显式 auth_mode 优先于文件里残留的其他凭据。
69
+ NSDictionary *auth = ReadJSONObject([home stringByAppendingPathComponent:@"auth.json"]);
70
+ NSString *mode = HasString(auth[@"auth_mode"]) ? auth[@"auth_mode"] : nil;
71
+ if ([@[@"apikey", @"bedrockApiKey", @"bedrockAccessKeys"] containsObject:mode ?: @""]) return @"api";
72
+ BOOL key = HasString(auth[@"OPENAI_API_KEY"]);
73
+ BOOL tokens = [auth[@"tokens"] isKindOfClass:NSDictionary.class] &&
74
+ HasString(auth[@"tokens"][@"access_token"]);
75
+ if (!mode && key && !tokens) return @"api";
76
+ if (CodexHasCustomProvider(home)) return @"unknown";
77
+ if ([@[@"chatgpt", @"chatgptAuthTokens"] containsObject:mode ?: @""]) return @"subscription";
78
+ if (!mode && key != tokens) return key ? @"api" : @"subscription";
79
+ }
80
+ NSString *executable = CCPetsFindRealExecutableInPath(provider,
81
+ claude ? @"CLAUDE_REAL_BIN" : @"CODEX_REAL_BIN", searchPath);
82
+ if (!executable) return fallback;
83
+ NSMutableDictionary *environment = [NSProcessInfo.processInfo.environment mutableCopy];
84
+ // 常驻 App 不能把拉起它的第一个客户端的凭据套给其他账号。每份 Home 自己提供认证配置。
85
+ for (NSString *key in @[@"ANTHROPIC_API_KEY", @"ANTHROPIC_AUTH_TOKEN", @"ANTHROPIC_BASE_URL",
86
+ @"ANTHROPIC_CUSTOM_HEADERS", @"ANTHROPIC_PROFILE",
87
+ @"CLAUDE_CODE_OAUTH_TOKEN", @"CLAUDE_CODE_USE_BEDROCK", @"CLAUDE_CODE_USE_VERTEX",
88
+ @"CLAUDE_CODE_USE_FOUNDRY", @"OPENAI_API_KEY", @"OPENAI_BASE_URL", @"CODEX_API_KEY", @"CODEX_ACCESS_TOKEN"]) {
89
+ [environment removeObjectForKey:key];
90
+ }
91
+ environment[claude ? @"CLAUDE_CONFIG_DIR" : @"CODEX_HOME"] = home;
92
+ if (searchPath.length > 0) environment[@"PATH"] = searchPath;
93
+ NSString *output = nil, *errors = nil;
94
+ int status = CCPetsRun(executable, claude ? @[@"auth", @"status"] : @[@"login", @"status"],
95
+ home, environment, 5, &output, &errors);
96
+ if (status != 0) return fallback;
97
+ if (claude) {
98
+ // https://code.claude.com/docs/en/cli-reference#cli-commands
99
+ // JSON 只取 authMethod;邮箱、订阅细节及 CLI 输出均不保留。
100
+ NSData *data = [output dataUsingEncoding:NSUTF8StringEncoding];
101
+ id auth = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
102
+ if (![auth isKindOfClass:NSDictionary.class]) return fallback;
103
+ NSString *reportedHome = auth[@"configDirectory"];
104
+ if (HasString(reportedHome) && ![reportedHome.stringByResolvingSymlinksInPath
105
+ isEqualToString:home.stringByResolvingSymlinksInPath]) return fallback;
106
+ NSString *method = auth[@"authMethod"];
107
+ if ([@[@"api_key", @"api_key_helper", @"third_party"] containsObject:method ?: @""]) return @"api";
108
+ if ([@[@"claude.ai", @"oauth_token"] containsObject:method ?: @""]) return @"subscription";
109
+ } else {
110
+ // login status 支持 Keychain 存储;输出可能包含密钥片段,只在此处匹配固定认证名称。
111
+ NSString *text = [[NSString stringWithFormat:@"%@\n%@", output ?: @"", errors ?: @""] lowercaseString];
112
+ if ([text containsString:@"logged in using an api key"]) return @"api";
113
+ if ([text containsString:@"logged in using chatgpt"]) return @"subscription";
114
+ }
115
+ return fallback;
116
+ }
117
+
118
+ void CCPetsRefreshProfileAuthenticationModes(NSArray<NSDictionary *> *profiles) {
119
+ NSTimeInterval now = NSDate.date.timeIntervalSince1970;
120
+ NSString *searchPath = nil;
121
+ BOOL changed = NO;
122
+ for (NSDictionary *profile in profiles) {
123
+ NSString *key = ProfileCacheKey(profile);
124
+ NSDictionary *previous;
125
+ @synchronized(CCPetsAuthenticationModesDidChangeNotification) { previous = AuthenticationModes[key]; }
126
+ if (previous && now - [previous[@"checkedAt"] doubleValue] < 60) continue;
127
+ if (!searchPath) searchPath = CCPetsLoginShellPath() ?: @"";
128
+ NSString *mode = ProbeAuthenticationMode(profile, searchPath);
129
+ @synchronized(CCPetsAuthenticationModesDidChangeNotification) {
130
+ if (!AuthenticationModes) AuthenticationModes = [NSMutableDictionary dictionary];
131
+ AuthenticationModes[key] = @{@"mode": mode, @"checkedAt": @(now)};
132
+ }
133
+ if (![mode isEqualToString:previous[@"mode"] ?: @"unknown"]) changed = YES;
134
+ }
135
+ if (changed) dispatch_async(dispatch_get_main_queue(), ^{
136
+ [NSNotificationCenter.defaultCenter postNotificationName:CCPetsAuthenticationModesDidChangeNotification object:nil];
137
+ });
138
+ }
139
+
140
+ NSString *CCPetsProfileAuthenticationMode(NSDictionary *profile) {
141
+ @synchronized(CCPetsAuthenticationModesDidChangeNotification) {
142
+ return AuthenticationModes[ProfileCacheKey(profile)][@"mode"] ?: @"unknown";
143
+ }
144
+ }
145
+
146
+ NSString *CCPetsUsageModePreferenceKey(NSDictionary *profile) {
147
+ NSString *profileID = profile[@"id"];
148
+ if (profileID.length > 0) return [@"CCPetsUsageDisplayMode." stringByAppendingString:profileID];
149
+ return [profile[@"provider"] isEqualToString:@"codex"] ? CodexUsageDisplayModeKey : ClaudeUsageDisplayModeKey;
150
+ }
151
+
152
+ BOOL CCPetsProfileCanSwitchUsageMode(NSDictionary *profile) {
153
+ return ![CCPetsProfileAuthenticationMode(profile) isEqualToString:@"api"];
154
+ }
155
+
156
+ BOOL CCPetsProfileShowsAPIUsage(NSDictionary *profile) {
157
+ if (!CCPetsProfileCanSwitchUsageMode(profile)) return YES;
158
+ NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
159
+ NSString *mode = [defaults stringForKey:CCPetsUsageModePreferenceKey(profile)];
160
+ if (!mode) mode = [defaults stringForKey:[profile[@"provider"] isEqualToString:@"codex"]
161
+ ? CodexUsageDisplayModeKey : ClaudeUsageDisplayModeKey];
162
+ return [mode isEqualToString:@"api"];
163
+ }
@@ -4,6 +4,9 @@
4
4
  @property(copy) void (^changeHandler)(NSDictionary *codexUsage, NSDictionary *claudeUsage);
5
5
  @property(readonly) NSDictionary *codexUsage;
6
6
  @property(readonly) NSDictionary *claudeUsage;
7
+ // profileId → 当前用量;profiles 保持用户添加顺序。默认账号同时保留在旧属性中以兼容现有调用方。
8
+ @property(readonly) NSDictionary<NSString *, NSDictionary *> *profileUsages;
9
+ @property(readonly) NSArray<NSDictionary *> *profiles;
7
10
  - (void)start;
8
11
  - (void)refreshNow;
9
12
  - (void)stop;