cc-pets 1.2.8 → 1.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.
package/README.md CHANGED
@@ -326,7 +326,11 @@ Codex 侧同理:桌宠固定只统计 `~/.codex`,不读继承来的 `CODEX_H
326
326
  分别展示 Codex、Claude 的「今日」与「最近 7 天」Token,并显示最近刷新时间。统计用的是与订阅无关的
327
327
  自然日窗口(今日 = 本机零点至今,最近 7 天 = 含今天在内的 7 个自然日),因为两家的
328
328
  `resets_at` 并不一致,按各自订阅窗口算出的数不在同一区间上,相加没有意义。每个 Agent 卡片按 5 小时和 7 天两列
329
- 展示官方剩余百分比(主值)、本机 Token 用量和重置时间,右侧是近 7 天额度趋势。某个窗口
329
+ 展示官方剩余百分比(主值)、本机 Token 用量和重置时间,右侧是近 7 天额度趋势。右键菜单的
330
+ “用量展示模式”可分别为 Codex、Claude 选择“订阅额度”或“API 用量”;API 用量模式只替换对应
331
+ 卡片内部,展示本月调用次数、本月输入/输出 Token、较上月同期变化和本月按日 Token 趋势。
332
+ “调用次数”来自本机会话记录:Claude 按请求标识去重,Codex 按去重后的累计 Token 快照计数。
333
+ 某个窗口
330
334
  当前没有额度数据时该列标注"当前无活跃窗口"。卡片上的在线徽章表示该 Provider 是否还有
331
335
  运行中的客户端(包装脚本写出的 pid 文件,或该 Provider 最近 60 秒内仍在发事件),与是否
332
336
  已采集到额度数据无关;客户端退出后显示"离线",从未采集到数据时显示"等待数据"。经
@@ -45,6 +45,8 @@
45
45
  @property BOOL updating;
46
46
  @property NSTask *updateTask;
47
47
  @property NSTimer *usageTimer;
48
+ // 上一次全量聚合的时刻:面板由悬停触发,短时间内反复进出热区不必每次重算。
49
+ @property NSTimeInterval lastUsageRefreshAt;
48
50
  @property NSTimer *quotaClockTimer;
49
51
  @property NSTimer *systemMetricsTimer;
50
52
  @property CCPetsSystemMonitor *systemMonitor;
@@ -58,6 +60,7 @@
58
60
  - (void)toggleStatusBubbleFromMenu:(NSButton *)sender;
59
61
  - (void)refreshUsage:(id)sender;
60
62
  - (void)toggleSystemMetric:(NSButton *)sender;
63
+ - (void)setUsageDisplayModeFromControl:(NSButton *)sender;
61
64
  - (void)applyCodexUsage:(NSDictionary *)codexUsage claudeUsage:(NSDictionary *)claudeUsage;
62
65
  - (void)switchPetToID:(NSString *)petID;
63
66
  @end
@@ -266,6 +266,25 @@ static void TrimUpdateLog(NSString *path) {
266
266
  self.quotaView.systemMemoryEnabled = [defaults boolForKey:SystemMemoryEnabledKey];
267
267
  self.quotaView.needsDisplay = YES;
268
268
  }
269
+ - (void)applyUsageDisplayModePreferences {
270
+ NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
271
+ self.quotaView.codexShowsAPIUsage =
272
+ [[defaults stringForKey:CodexUsageDisplayModeKey] isEqualToString:@"api"];
273
+ self.quotaView.claudeShowsAPIUsage =
274
+ [[defaults stringForKey:ClaudeUsageDisplayModeKey] isEqualToString:@"api"];
275
+ self.quotaView.needsDisplay = YES;
276
+ }
277
+ - (void)setUsageDisplayModeFromControl:(NSButton *)sender {
278
+ NSString *key = sender.tag == 1 ? CodexUsageDisplayModeKey
279
+ : (sender.tag == 2 ? ClaudeUsageDisplayModeKey : nil);
280
+ NSString *mode = sender.state == NSControlStateValueOn ? @"api" : @"subscription";
281
+ if (!key) return;
282
+ [NSUserDefaults.standardUserDefaults setObject:mode forKey:key];
283
+ [self applyUsageDisplayModePreferences];
284
+ // 展示模式决定了会话要回溯多远(订阅 8 天 / API 到上月月初),切换之后必须重新聚合,
285
+ // 否则刚打开 API 视图时手里只有一段按 8 天窗口扫出来的数据。
286
+ [self refreshUsage:nil];
287
+ }
269
288
  - (void)toggleSystemMetric:(NSButton *)sender {
270
289
  NSString *key = [self systemMetricKeyForTag:sender.tag];
271
290
  if (!key) return;
@@ -727,7 +746,9 @@ static void TrimUpdateLog(NSString *path) {
727
746
  return;
728
747
  }
729
748
  NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
730
- [defaults registerDefaults:@{StatusBubbleExpandedKey: @YES}];
749
+ [defaults registerDefaults:@{StatusBubbleExpandedKey: @YES,
750
+ CodexUsageDisplayModeKey: @"subscription",
751
+ ClaudeUsageDisplayModeKey: @"subscription"}];
731
752
  [defaults registerDefaults:@{
732
753
  SystemCPUEnabledKey: @YES,
733
754
  SystemTemperatureEnabledKey: @YES,
@@ -900,6 +921,7 @@ static void TrimUpdateLog(NSString *path) {
900
921
  [quotaRoot addSubview:glass];
901
922
  self.quotaView = [[QuotaDashboardView alloc] initWithFrame:NSMakeRect(0, 0, quotaSize.width, quotaSize.height)];
902
923
  [self applySystemMetricPreferences];
924
+ [self applyUsageDisplayModePreferences];
903
925
  self.quotaView.codexLogo = OfficialAppIcon(@"com.openai.codex", @"icon-chatgpt.icns");
904
926
  self.quotaView.claudeLogo = OfficialAppIcon(@"com.anthropic.claudefordesktop", @"electron.icns");
905
927
  self.quotaView.hoverChanged = ^(BOOL hovering) {
@@ -911,6 +933,8 @@ static void TrimUpdateLog(NSString *path) {
911
933
  };
912
934
  [quotaRoot addSubview:self.quotaView];
913
935
  self.quotaPanel.contentView = quotaRoot;
936
+ // 先探测再第一次显示:否则面板会先按两张卡的高度弹出来再收缩一下。
937
+ [self refreshDetectedProviders];
914
938
 
915
939
  NSScreen *screen = NSScreen.mainScreen;
916
940
  NSRect visible = screen.visibleFrame;
@@ -963,9 +987,20 @@ static void TrimUpdateLog(NSString *path) {
963
987
  selector:@selector(refreshUsage:) userInfo:nil repeats:YES];
964
988
  self.usageTimer.tolerance = interval * 0.2;
965
989
  }
990
+ // 全量聚合是同步的主线程活儿(本机实测数十毫秒,会话目录越大越久),而面板恰好由"鼠标
991
+ // 停在口袋上"触发——那正是用户可能马上按下并拖动的时刻。事件被这几十毫秒挡住,mouseDown
992
+ // 和 mouseDragged 就会成批迟到,手感上像是"鼠标走远了宠物才跟上"。
993
+ // 因此:左键按着的时候不刷(拖动期间没人看数字),刚刷过的也不重刷(进出热区会反复触发)。
994
+ static const NSTimeInterval UsageRefreshCoalesceWindow = 2.0;
995
+ - (BOOL)shouldRefreshUsageForDashboard {
996
+ if (CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState, kCGMouseButtonLeft)) {
997
+ return NO;
998
+ }
999
+ return NSDate.date.timeIntervalSince1970 - self.lastUsageRefreshAt >= UsageRefreshCoalesceWindow;
1000
+ }
966
1001
  - (void)showQuotaDashboard {
967
1002
  [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideQuotaDashboardIfNeeded) object:nil];
968
- [self refreshUsage:nil];
1003
+ if ([self shouldRefreshUsageForDashboard]) [self refreshUsage:nil];
969
1004
  [self positionQuotaDashboard];
970
1005
  [self.quotaPanel orderFrontRegardless];
971
1006
  [self.panel orderFrontRegardless];
@@ -1293,14 +1328,72 @@ static void TrimUpdateLog(NSString *path) {
1293
1328
  }
1294
1329
  }
1295
1330
  [self updateQuotaLiveState];
1331
+ [self refreshDetectedProviders];
1296
1332
  [self hideAgentStatusIfClientGone];
1297
1333
  // 启动模式在应用生命周期内保持不变。手动启动的桌宠即使后来检测到
1298
1334
  // Codex/Claude 客户端,也不应被转成 CLI 托管模式并随客户端退出。
1299
1335
  if (liveClients == 0 && self.managedByCLI) [NSApp terminate:nil];
1300
1336
  }
1337
+ // 面板高度取决于渲染几张额度卡。quotaRoot / 毛玻璃 / quotaView 三层都是固定 frame、
1338
+ // 没有 autoresizingMask,所以统一在这里按 contentView 的 subviews 铺一遍,避免漏掉一层。
1339
+ - (void)resizeQuotaDashboard {
1340
+ NSSize size = NSMakeSize(QuotaLogicalWidth * QuotaScale,
1341
+ QuotaLogicalHeightForProviderCount([self.quotaView visibleProviders].count) * QuotaScale);
1342
+ if (NSEqualSizes(self.quotaPanel.frame.size, size)) return;
1343
+ // 只改 size 不动 origin:窗口 frame 的原点在左下,面板会朝上收缩,底边保持贴着宠物。
1344
+ NSRect frame = self.quotaPanel.frame;
1345
+ frame.size = size;
1346
+ [self.quotaPanel setFrame:frame display:NO];
1347
+ NSRect bounds = NSMakeRect(0, 0, size.width, size.height);
1348
+ self.quotaPanel.contentView.frame = bounds;
1349
+ for (NSView *subview in self.quotaPanel.contentView.subviews) subview.frame = bounds;
1350
+ self.quotaView.needsDisplay = YES;
1351
+ if (self.quotaPanel.isVisible) [self positionQuotaDashboard];
1352
+ }
1353
+ // 额度字典"非空"不等于"这家真的在用"。Claude 的 reader 刻意永不返回 nil(见
1354
+ // CCPetsUsage.m 里 -[ClaudeUsageReader refresh] 的注释:Token 是本机从转录数出来的,
1355
+ // 不能被缺失的官方额度一票否决),什么都没有时照样返回
1356
+ // {fiveHour: NSNull, week: NSNull, tokenUsage: 全 0},count 恒为 3。
1357
+ // 拿 count > 0 当证据,Claude 就永远算"检测到",卡片再也去不掉。这里只认实质证据:
1358
+ // 官方额度块真实存在,或者本机统计出过非零 Token。Codex 侧同一套判据也成立。
1359
+ static BOOL UsageShowsProviderInUse(NSDictionary *usage) {
1360
+ if (usage.count == 0) return NO;
1361
+ for (NSString *key in @[@"fiveHour", @"week"]) {
1362
+ if ([usage[key] isKindOfClass:NSDictionary.class]) return YES;
1363
+ }
1364
+ NSDictionary *tokenUsage = [usage[@"tokenUsage"] isKindOfClass:NSDictionary.class]
1365
+ ? usage[@"tokenUsage"] : nil;
1366
+ for (NSString *key in @[@"fiveHour", @"week", @"today", @"recentWeek"]) {
1367
+ NSDictionary *totals = [tokenUsage[key] isKindOfClass:NSDictionary.class]
1368
+ ? tokenUsage[key] : nil;
1369
+ if ([totals[@"total_tokens"] doubleValue] > 0) return YES;
1370
+ }
1371
+ return NO;
1372
+ }
1373
+ // "这台机器上有哪几家 CLI"。只增不减,并持久化:探测会瞬时失败(配置目录被改名、
1374
+ // 外置盘没挂上),卡片当着用户的面消失比多留一张更像 bug。
1375
+ - (void)refreshDetectedProviders {
1376
+ NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
1377
+ NSMutableSet<NSString *> *detected = [NSMutableSet setWithArray:
1378
+ [defaults arrayForKey:DetectedProvidersKey] ?: @[]];
1379
+ if (CodexCLIDetected()) [detected addObject:@"Codex"];
1380
+ if (ClaudeCLIDetected()) [detected addObject:@"Claude"];
1381
+ // 正在跑的客户端和已经拿到的额度数据都是比目录探测更硬的证据:探测漏判也不能
1382
+ // 把一个正在工作、或者明明有额度的 provider 藏起来。
1383
+ if (self.liveClientProviders.count > 0) [detected unionSet:self.liveClientProviders];
1384
+ if (UsageShowsProviderInUse(self.quotaView.codexUsage)) [detected addObject:@"Codex"];
1385
+ if (UsageShowsProviderInUse(self.quotaView.claudeUsage)) [detected addObject:@"Claude"];
1386
+ if (self.quotaView.detectedProviders &&
1387
+ [detected isEqualToSet:self.quotaView.detectedProviders]) return;
1388
+ self.quotaView.detectedProviders = detected;
1389
+ [defaults setObject:detected.allObjects forKey:DetectedProvidersKey];
1390
+ [self resizeQuotaDashboard];
1391
+ self.quotaView.needsDisplay = YES;
1392
+ }
1301
1393
  - (void)applyCodexUsage:(NSDictionary *)codexUsage claudeUsage:(NSDictionary *)claudeUsage {
1302
1394
  self.quotaView.codexUsage = codexUsage;
1303
1395
  self.quotaView.claudeUsage = claudeUsage;
1396
+ [self refreshDetectedProviders];
1304
1397
  NSDictionary *history = RecordQuotaHistory(self.quotaView.codexUsage,
1305
1398
  self.quotaView.claudeUsage);
1306
1399
  self.quotaView.codexHistory = QuotaHistorySeries(history, @"codex");
@@ -1309,6 +1402,7 @@ static void TrimUpdateLog(NSString *path) {
1309
1402
  self.quotaView.needsDisplay = YES;
1310
1403
  }
1311
1404
  - (void)refreshUsage:(id)sender {
1405
+ self.lastUsageRefreshAt = NSDate.date.timeIntervalSince1970;
1312
1406
  [self.usageMonitor refreshNow];
1313
1407
  }
1314
1408
  - (void)applicationWillTerminate:(NSNotification *)notification {
@@ -14,12 +14,23 @@ NSString *CurrentClaudeConfigDirectory(void);
14
14
  // 桌宠端用:只看主账号的 Codex 目录,不受继承来的 CODEX_HOME 影响。
15
15
  NSString *DefaultCodexHomeDirectory(void);
16
16
  NSString *ClaudeUsagePathForConfigDirectory(NSString *configDirectory);
17
+ // Token 会话摘要缓存的落盘位置,按 provider 与数据源目录分文件。
18
+ NSString *TokenSummaryCachePath(NSString *provider, NSString *sourceDirectory);
19
+ // 已结束自然月的用量归档,同样按 provider 与数据源目录分文件。
20
+ NSString *MonthlyUsageArchivePath(NSString *provider, NSString *sourceDirectory);
17
21
  NSString *ApplicationSupportDirectory(void);
18
22
  NSString *QuotaHistoryPath(void);
19
23
  // 桌宠只认这一个素材目录。~/.petdex/pets 和 ~/.codex/pets 由别的工具写入,
20
24
  // 永远不直接扫描,只在开关打开时由 ImportCodexPets 复制进来。
21
25
  NSString *OwnPetsDirectory(void);
22
26
  NSString *CodexPetsDirectory(void);
27
+
28
+ // 这台机器上有没有这家 CLI。面板据此决定渲染几张额度卡:判据是"装没装",不是"此刻在不在线"。
29
+ // 在线信号(liveProviders)会随 CLI 退出而消失,拿它控制卡片显隐会让面板在用户眼前抖动,
30
+ // 而 CLI 刚退出恰恰是用户最想看剩余额度的时候。安装器已经不再凭空创建这两个配置目录,
31
+ // 所以"目录存在"是干净信号。参见 scripts/detect-cli.mjs 里同一套判据的 Node 实现。
32
+ BOOL CodexCLIDetected(void);
33
+ BOOL ClaudeCLIDetected(void);
23
34
  // 把 ~/.codex/pets 里的素材复制进 OwnPetsDirectory(),返回新导入的数量。
24
35
  // 已存在的同名目录一律跳过,不覆盖。
25
36
  NSUInteger ImportCodexPets(void);
@@ -34,6 +45,12 @@ extern NSString *const ImportCodexPetsKey;
34
45
  extern NSString *const SystemCPUEnabledKey;
35
46
  extern NSString *const SystemTemperatureEnabledKey;
36
47
  extern NSString *const SystemMemoryEnabledKey;
48
+ // 每个 Provider 独立保存额度卡展示模式,值为 "subscription" 或 "api"。
49
+ extern NSString *const CodexUsageDisplayModeKey;
50
+ extern NSString *const ClaudeUsageDisplayModeKey;
51
+ // 曾经检测到过的 provider 集合。只增不减:探测有可能瞬时失败(配置目录被临时改名、
52
+ // 外置盘没挂上),而卡片突然消失比多显示一张空卡更像 bug。
53
+ extern NSString *const DetectedProvidersKey;
37
54
 
38
55
  extern const NSTimeInterval AgentStatusInactivityInterval;
39
56
  extern const NSTimeInterval AgentStatusOrphanInterval;
@@ -80,6 +80,29 @@ NSString *ClaudeUsagePath(void) {
80
80
  return ClaudeUsagePathForConfigDirectory(CurrentClaudeConfigDirectory());
81
81
  }
82
82
 
83
+ // Token 聚合的会话摘要缓存。摘要只依赖会话文件里已经写死的内容,进程退出后仍然有效,
84
+ // 但原先只存在内存里,于是每次启动都要把整个窗口的会话重新解析一遍。落盘之后启动只需
85
+ // stat 一遍文件,只有长大了的会话才追读新增字节。
86
+ // 按数据源目录分文件:同一台机器可以有多份 CODEX_HOME / 配置目录,缓存键是绝对路径,
87
+ // 混在一个文件里只会让彼此的条目每轮被当成过期项清掉。
88
+ // 放 Application Support 而不是 PetStateDirectory():后者默认是 NSTemporaryDirectory(),
89
+ // 系统会清理长期没被访问的文件,桌宠停开几天回来就又要重新解析一整个月。
90
+ NSString *TokenSummaryCachePath(NSString *provider, NSString *sourceDirectory) {
91
+ NSString *resolved = sourceDirectory.stringByStandardizingPath ?: @"";
92
+ NSString *name = [NSString stringWithFormat:@"%@-token-cache-%016llx.plist",
93
+ provider, (unsigned long long)StablePathHash(resolved)];
94
+ return [ApplicationSupportDirectory() stringByAppendingPathComponent:name];
95
+ }
96
+
97
+ // 已经结束的自然月,用量再也不会变。归档下来之后上个月的会话文件就一次都不用再打开,
98
+ // 稳态下的扫描范围收窄到"本月"。
99
+ NSString *MonthlyUsageArchivePath(NSString *provider, NSString *sourceDirectory) {
100
+ NSString *resolved = sourceDirectory.stringByStandardizingPath ?: @"";
101
+ NSString *name = [NSString stringWithFormat:@"%@-monthly-usage-%016llx.plist",
102
+ provider, (unsigned long long)StablePathHash(resolved)];
103
+ return [ApplicationSupportDirectory() stringByAppendingPathComponent:name];
104
+ }
105
+
83
106
  NSString *ClaudeUsageLockPath(void) {
84
107
  return [ClaudeUsagePath() stringByAppendingPathExtension:@"lock"];
85
108
  }
@@ -106,6 +129,30 @@ NSString *CodexPetsDirectory(void) {
106
129
  return [DefaultCodexHomeDirectory() stringByAppendingPathComponent:@"pets"];
107
130
  }
108
131
 
132
+ static BOOL DirectoryExistsAtPath(NSString *path) {
133
+ BOOL isDirectory = NO;
134
+ return path.length > 0 &&
135
+ [NSFileManager.defaultManager fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory;
136
+ }
137
+
138
+ BOOL CodexCLIDetected(void) {
139
+ return DirectoryExistsAtPath(DefaultCodexHomeDirectory());
140
+ }
141
+
142
+ BOOL ClaudeCLIDetected(void) {
143
+ if (DirectoryExistsAtPath(DefaultClaudeConfigDirectory())) return YES;
144
+ // 把配置目录搬过家、又没设 CC_PETS_CLAUDE_CONFIG_DIR 的用户:statusline 写出的额度
145
+ // 缓存同样能证明这家在用。有额度数据却不给卡片,是比多一张卡糟糕得多的失败方式。
146
+ //
147
+ // 但只判"文件存在"不行:CCPetsUsageMonitor 为了挂 VNODE 监听,会先把这个文件
148
+ // 创建成 0 字节占位(见 CCPetsUsageMonitor.m 里 createFileAtPath: 那处)。那样桌宠
149
+ // 一启动就把自己造的占位文件当成"用过 Claude",探测永远为真——和安装器凭空创建
150
+ // ~/.claude 是同一类自证。必须要求文件真的有内容。
151
+ NSDictionary *attributes = [NSFileManager.defaultManager
152
+ attributesOfItemAtPath:ClaudeUsagePath() error:nil];
153
+ return attributes != nil && [attributes[NSFileSize] unsignedLongLongValue] > 0;
154
+ }
155
+
109
156
  // 素材目录里认哪些文件算"有图"。和 CCPetsAppDelegate 的 spritePathInDirectory 保持一致,
110
157
  // 但这里只做存在性判断,不需要读 pet.json 里的 spritesheetPath。
111
158
  static BOOL DirectoryHasSprite(NSString *directory) {
@@ -172,6 +219,9 @@ NSString *const ImportCodexPetsKey = @"CCPetsImportCodexPets";
172
219
  NSString *const SystemCPUEnabledKey = @"CCPetsSystemCPUEnabled";
173
220
  NSString *const SystemTemperatureEnabledKey = @"CCPetsSystemTemperatureEnabled";
174
221
  NSString *const SystemMemoryEnabledKey = @"CCPetsSystemMemoryEnabled";
222
+ NSString *const CodexUsageDisplayModeKey = @"CCPetsCodexUsageDisplayMode";
223
+ NSString *const ClaudeUsageDisplayModeKey = @"CCPetsClaudeUsageDisplayMode";
224
+ NSString *const DetectedProvidersKey = @"CCPetsDetectedProviders";
175
225
  const NSTimeInterval AgentStatusInactivityInterval = 60.0;
176
226
  // 客户端进程已经消失、但状态气泡还停在它最后一条事件上时,多等这么久再清场。
177
227
  // 留这段宽限是因为不经包装脚本启动的客户端(直接跑 claude / codex)没有 pid
@@ -8,6 +8,10 @@ int RenderQuotaDashboard(NSString *path) {
8
8
  [NSApplication sharedApplication];
9
9
  QuotaDashboardView *view = [[QuotaDashboardView alloc] initWithFrame:NSMakeRect(0, 0,
10
10
  QuotaLogicalWidth * QuotaScale, QuotaLogicalHeight * QuotaScale)];
11
+ // 本地视觉验收可用 CC_PETS_PREVIEW_API=1 渲染 API 用量态,不改用户偏好。
12
+ BOOL previewsAPIUsage = [NSProcessInfo.processInfo.environment[@"CC_PETS_PREVIEW_API"] boolValue];
13
+ view.codexShowsAPIUsage = previewsAPIUsage;
14
+ view.claudeShowsAPIUsage = previewsAPIUsage;
11
15
  view.codexLogo = OfficialAppIcon(@"com.openai.codex", @"icon-chatgpt.icns");
12
16
  view.claudeLogo = OfficialAppIcon(@"com.anthropic.claudefordesktop", @"electron.icns");
13
17
  view.codexUsage = LatestUsage() ?: @{
@@ -55,6 +59,9 @@ int RenderQuotaDashboard(NSString *path) {
55
59
  view.activeAgentCount = 1;
56
60
  // 预览里刻意只让一家在线,好把"有额度数据但客户端已退出"的离线态也画出来。
57
61
  view.liveProviders = [NSSet setWithObject:@"Claude"];
62
+ // 预览图始终画完整的两张卡:它是 README 里的样张,不该受这台机器装了几家 CLI 影响。
63
+ // 尺寸也因此固定在 QuotaLogicalHeight(tests/test.sh 断言的 441 x 343)。
64
+ view.detectedProviders = [NSSet setWithObjects:@"Codex", @"Claude", nil];
58
65
  view.lastUpdatedAt = NSDate.date.timeIntervalSince1970 - 12;
59
66
  NSInteger pixelWidth = (NSInteger)ceil(NSWidth(view.bounds));
60
67
  NSInteger pixelHeight = (NSInteger)ceil(NSHeight(view.bounds));
@@ -9,6 +9,9 @@ NSDictionary *LatestUsage(void);
9
9
  // 增量跟读 ~/.claude/projects 下的会话转录,按官方 5 小时 / 7 天窗口聚合本地 Token。
10
10
  @interface ClaudeUsageReader : NSObject
11
11
  @property NSURL *projectsURL;
12
+ // 只有常驻的桌宠进程写摘要缓存。--status / --hook 这类一次性命令照样读它(省下冷解析),
13
+ // 但绝不能写:它们按各自当时的窗口把缓存剪一遍再存回去,等于把桌宠攒下的月度条目清掉。
14
+ @property BOOL persistsCache;
12
15
  - (NSDictionary *)refresh;
13
16
  - (NSDictionary *)refreshWithFullAggregation;
14
17
  @end
@@ -16,6 +19,8 @@ NSDictionary *LatestUsage(void);
16
19
  // 增量跟读当前 Codex 会话文件:只在会话切换时做一次冷读,之后按偏移追读。
17
20
  @interface CodexUsageReader : NSObject
18
21
  @property NSURL *sessionsURL;
22
+ // 见 ClaudeUsageReader.persistsCache。
23
+ @property BOOL persistsCache;
19
24
  @property NSURL *sessionURL;
20
25
  @property NSDictionary *usage;
21
26
  @property unsigned long long offset;