cc-pets 2.0.0 → 2.0.1
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/CHANGELOG.md +47 -30
- package/CHANGELOG.zh-CN.md +64 -0
- package/CONTRIBUTING.md +18 -15
- package/CONTRIBUTING.zh-CN.md +22 -0
- package/LICENSE +1 -1
- package/PROVIDER_PROTOCOL.md +50 -41
- package/PROVIDER_PROTOCOL.zh-CN.md +58 -0
- package/README.md +220 -502
- package/README.zh-CN.md +601 -0
- package/Resources/phrases.default.txt +48 -49
- package/SECURITY.md +13 -10
- package/SECURITY.zh-CN.md +18 -0
- package/Sources/CCPets/CCPetsAppDelegate.m +0 -9
- package/Sources/CCPets/CCPetsCodexRateLimits.h +13 -0
- package/Sources/CCPets/CCPetsCodexRateLimits.m +383 -0
- package/Sources/CCPets/CCPetsPhrases.h +1 -24
- package/Sources/CCPets/CCPetsPhrases.m +1 -82
- package/Sources/CCPets/CCPetsPhrasesEditor.m +0 -28
- package/Sources/CCPets/CCPetsQuotaHistory.m +4 -4
- package/Sources/CCPets/CCPetsUsage.m +135 -14
- package/Sources/CCPets/CCPetsUsageMonitor.m +41 -3
- package/Sources/CCPets/PetView.m +17 -10
- package/Sources/CCPets/QuotaDashboardView.m +23 -14
- package/THIRD_PARTY_NOTICES.md +13 -7
- package/THIRD_PARTY_NOTICES.zh-CN.md +12 -0
- package/package.json +14 -5
- package/scripts/pet-store.mjs +1 -1
|
@@ -118,26 +118,6 @@ NSString *PetPhrasesCurrentPetFilePath(void) {
|
|
|
118
118
|
return PetPhrasesFilePathForPetID(PetPhrasesCurrentPet);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
NSString *PetPhrasesLegacyFilePath(void) {
|
|
122
|
-
NSString *override = NSProcessInfo.processInfo.environment[@"CC_PETS_PHRASES_LEGACY_FILE"];
|
|
123
|
-
if (override.length > 0) return override.stringByStandardizingPath;
|
|
124
|
-
return [NSHomeDirectory() stringByAppendingPathComponent:@".cc-pets/phrases.txt"];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
BOOL PetPhrasesLegacyFileExists(void) {
|
|
128
|
-
return [NSFileManager.defaultManager fileExistsAtPath:PetPhrasesLegacyFilePath()];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
BOOL PetPhrasesArchiveLegacyFile(void) {
|
|
132
|
-
NSFileManager *manager = NSFileManager.defaultManager;
|
|
133
|
-
NSString *source = PetPhrasesLegacyFilePath();
|
|
134
|
-
if (![manager fileExistsAtPath:source]) return YES;
|
|
135
|
-
NSString *target = [source stringByAppendingPathExtension:@"bak"];
|
|
136
|
-
// 已经有一份更早的备份就顶掉:它比这份更旧,留着只会让人分不清哪份是哪份。
|
|
137
|
-
if ([manager fileExistsAtPath:target]) [manager removeItemAtPath:target error:nil];
|
|
138
|
-
return [manager moveItemAtPath:source toPath:target error:nil];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
121
|
NSString *PetPhrasesDefaultFilePath(void) {
|
|
142
122
|
NSString *override = NSProcessInfo.processInfo.environment[@"CC_PETS_PHRASES_DEFAULT_FILE"];
|
|
143
123
|
if (override.length > 0) return override.stringByStandardizingPath;
|
|
@@ -159,17 +139,7 @@ BOOL PetPhrasesEnsureFileExists(void) {
|
|
|
159
139
|
if (defaultText.length == 0) return NO;
|
|
160
140
|
[manager createDirectoryAtPath:path.stringByDeletingLastPathComponent
|
|
161
141
|
withIntermediateDirectories:YES attributes:nil error:nil];
|
|
162
|
-
|
|
163
|
-
// 老用户:启动时就把老词库合并过来,不等他打开编辑器。
|
|
164
|
-
//
|
|
165
|
-
// 拖到编辑器里再迁移的话,从升级到他第一次打开编辑器这段时间,桌宠说的会是默认
|
|
166
|
-
// 台词而不是他自己写的——没人会把这件事和"我该去点一下编辑台词"联系起来。
|
|
167
|
-
// 老文件这一步不删,等编辑器里问过用户再删。
|
|
168
|
-
NSString *legacyText = [NSString stringWithContentsOfFile:PetPhrasesLegacyFilePath()
|
|
169
|
-
encoding:NSUTF8StringEncoding error:nil];
|
|
170
|
-
NSString *text = legacyText.length > 0 ?
|
|
171
|
-
PetPhraseTextMergedFromLegacy(legacyText, defaultText) : defaultText;
|
|
172
|
-
return [text writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
|
142
|
+
return [defaultText writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
|
173
143
|
}
|
|
174
144
|
|
|
175
145
|
// 标签清单。顺序就是默认模板里的顺序,校验提示按这个顺序报,
|
|
@@ -552,57 +522,6 @@ static BOOL IsDamagedHeaderLine(NSString *rawLine, NSString *tag) {
|
|
|
552
522
|
return [comment isEqualToString:PetPhraseTagDescription(tag)];
|
|
553
523
|
}
|
|
554
524
|
|
|
555
|
-
NSString *PetPhraseTextMergedFromLegacy(NSString *legacyText, NSString *defaultText) {
|
|
556
|
-
if (legacyText.length == 0) return defaultText;
|
|
557
|
-
|
|
558
|
-
NSDictionary<NSString *, NSArray<NSString *> *> *legacy = ParsePhrasesText(legacyText, nil);
|
|
559
|
-
// 老文件里独立成行的 replace 表示"只说我写的"。这个写法在新版里已经没有了,
|
|
560
|
-
// 但迁移时必须认——不认的话,用过它的人升级后会突然多出一堆他当初特意关掉的话。
|
|
561
|
-
BOOL replaceMode = NO;
|
|
562
|
-
for (NSString *rawLine in [legacyText componentsSeparatedByCharactersInSet:
|
|
563
|
-
NSCharacterSet.newlineCharacterSet]) {
|
|
564
|
-
NSString *line = PetLineWithoutTrailingComment([rawLine
|
|
565
|
-
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet]);
|
|
566
|
-
if ([line isEqualToString:@"replace"]) { replaceMode = YES; break; }
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
// 拿默认模板当骨架,逐节把内容换掉。注释、分节说明全都用新模板的,
|
|
570
|
-
// 老文件里的注释一概不搬。
|
|
571
|
-
NSMutableArray<NSString *> *output = [NSMutableArray array];
|
|
572
|
-
NSArray<NSString *> *lines = [defaultText componentsSeparatedByString:@"\n"];
|
|
573
|
-
NSSet<NSString *> *known = [NSSet setWithArray:PetPhraseAllTags()];
|
|
574
|
-
NSString *current = nil;
|
|
575
|
-
for (NSString *rawLine in lines) {
|
|
576
|
-
NSString *line = PetLineWithoutTrailingComment([rawLine
|
|
577
|
-
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet]);
|
|
578
|
-
BOOL isHeader = [line hasPrefix:@"["] && [line hasSuffix:@"]"] &&
|
|
579
|
-
[known containsObject:[line substringWithRange:NSMakeRange(1, line.length - 2)]];
|
|
580
|
-
if (isHeader) {
|
|
581
|
-
current = [line substringWithRange:NSMakeRange(1, line.length - 2)];
|
|
582
|
-
[output addObject:rawLine];
|
|
583
|
-
NSArray<NSString *> *userLines = legacy[current];
|
|
584
|
-
NSMutableArray<NSString *> *merged = [NSMutableArray array];
|
|
585
|
-
// 默认在前、用户的追加在后,顺序稳定,用户一眼能看出哪几句是自己写的。
|
|
586
|
-
//
|
|
587
|
-
// replace 模式只覆盖用户**写过**的那些小节,没写过的仍旧用默认内容。
|
|
588
|
-
// 照搬老语义(没写的一律清空)会让 15 个 state_ 小节全空:老版那些小节空了
|
|
589
|
-
// 还有一层兜底文案顶着,新版把兜底删了,状态卡副行会直接残掉。
|
|
590
|
-
if (!replaceMode || userLines.count == 0) {
|
|
591
|
-
[merged addObjectsFromArray:ParsePhrasesText(defaultText, nil)[current] ?: @[]];
|
|
592
|
-
}
|
|
593
|
-
for (NSString *text in userLines) {
|
|
594
|
-
if (![merged containsObject:text]) [merged addObject:text];
|
|
595
|
-
}
|
|
596
|
-
[output addObjectsFromArray:merged];
|
|
597
|
-
continue;
|
|
598
|
-
}
|
|
599
|
-
// 小节内的原有台词由上面一次性写完,这里跳过;注释和空行照抄,骨架才立得住。
|
|
600
|
-
if (current != nil && line.length > 0) continue;
|
|
601
|
-
[output addObject:rawLine];
|
|
602
|
-
}
|
|
603
|
-
return [output componentsJoinedByString:@"\n"];
|
|
604
|
-
}
|
|
605
|
-
|
|
606
525
|
// 找 tag 的小节头在第几行,没有返回 -1。
|
|
607
526
|
static NSInteger HeaderIndex(NSArray<NSString *> *lines, NSString *tag) {
|
|
608
527
|
for (NSUInteger index = 0; index < lines.count; index++) {
|
|
@@ -45,34 +45,6 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
|
|
|
45
45
|
[NSApp activateIgnoringOtherApps:YES];
|
|
46
46
|
[controller.window makeKeyAndOrderFront:nil];
|
|
47
47
|
[controller.window makeFirstResponder:controller.textView];
|
|
48
|
-
[controller offerToRemoveLegacyFile];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 老词库在启动时已经合并进新文件了(见 PetPhrasesEnsureFileExists),但老文件还留着。
|
|
52
|
-
// 在这里问一次要不要收起来:合并是我们替用户做的,动他的文件必须他自己点头。
|
|
53
|
-
//
|
|
54
|
-
// 他选"先留着"的话下次打开还会问。留着原名不动有两个坑:改它不会有任何效果;
|
|
55
|
-
// 而且哪天 speech.txt 丢了,启动时会再从它合并一遍,把迁移之后写的台词全冲掉。
|
|
56
|
-
- (void)offerToRemoveLegacyFile {
|
|
57
|
-
if (!PetPhrasesLegacyFileExists()) return;
|
|
58
|
-
|
|
59
|
-
NSString *legacy = PetPhrasesLegacyFilePath();
|
|
60
|
-
NSAlert *alert = [NSAlert new];
|
|
61
|
-
alert.messageText = @"旧的台词文件已更新";
|
|
62
|
-
alert.informativeText = [NSString stringWithFormat:
|
|
63
|
-
@"正在使用的台词全部保留并合并到 %@。\n\n"
|
|
64
|
-
"旧文件 %@ 已经失效,后续修改不会有任何效果。"
|
|
65
|
-
"可以把它改名成 %@.bak 收起来,内容还留在原地。",
|
|
66
|
-
PetPhrasesFilePath(), legacy, legacy.lastPathComponent];
|
|
67
|
-
[alert addButtonWithTitle:@"改名收起来"];
|
|
68
|
-
[alert addButtonWithTitle:@"先留着"];
|
|
69
|
-
if ([alert runModal] != NSAlertFirstButtonReturn) return;
|
|
70
|
-
if (PetPhrasesArchiveLegacyFile()) {
|
|
71
|
-
[self showStatus:[NSString stringWithFormat:@"旧文件已改名成 %@.bak。",
|
|
72
|
-
legacy.lastPathComponent] warning:NO];
|
|
73
|
-
} else {
|
|
74
|
-
[self showStatus:@"旧文件改名失败,可以手动改。" warning:YES];
|
|
75
|
-
}
|
|
76
48
|
}
|
|
77
49
|
|
|
78
50
|
#pragma mark - 界面
|
|
@@ -23,11 +23,11 @@ NSDictionary *QuotaHistoryDocument(void) {
|
|
|
23
23
|
static NSDictionary *HistoryProviderSample(NSDictionary *usage, NSString *usedKey) {
|
|
24
24
|
NSNumber *fiveHour = RemainingValue(usage, @"fiveHour", usedKey);
|
|
25
25
|
NSNumber *week = RemainingValue(usage, @"week", usedKey);
|
|
26
|
-
//
|
|
27
|
-
//
|
|
26
|
+
// usage_limit_exceeded 没有窗口归属,既不能证明两个窗口都归零,也不能证明上次快照
|
|
27
|
+
// 仍代表当前额度。受限期间不写历史点,等任意会话拿到更新的官方快照后再继续记录。
|
|
28
28
|
if ([usage[@"exhaustedAt"] isKindOfClass:NSNumber.class]) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
fiveHour = nil;
|
|
30
|
+
week = nil;
|
|
31
31
|
}
|
|
32
32
|
NSMutableDictionary *sample = [NSMutableDictionary dictionary];
|
|
33
33
|
if (fiveHour) sample[@"fiveHourRemaining"] = fiveHour;
|
|
@@ -15,14 +15,60 @@ static const double SevenDayWindowMinutes = 10080;
|
|
|
15
15
|
// 把一份本来正常的快照判死。
|
|
16
16
|
static const NSTimeInterval QuotaResetSkewSeconds = 600.0;
|
|
17
17
|
|
|
18
|
+
// 一条限额错误刚发生、手上却一个可用窗口都没有时的保留时长。见 ExhaustionStillHolds。
|
|
19
|
+
static const NSTimeInterval RecentExhaustionGraceSeconds = 300.0;
|
|
20
|
+
|
|
18
21
|
// 一份快照要么描述当前窗口,要么就没有任何用处:resets_at 落在过去说明这个窗口早就翻篇,
|
|
19
22
|
// 落在一个窗长之外则根本不可能是它的重置时刻。2026-08-19 实测被顶进来的坏快照正是后者
|
|
20
23
|
// ——5 小时窗口的 resets_at 报到了十几小时之后。两种都在入口就拒绝,别让它进文件。
|
|
21
|
-
static BOOL
|
|
24
|
+
static BOOL ResetLooksCurrentAt(double reset, double windowMinutes, NSTimeInterval sampledAt) {
|
|
25
|
+
if (reset <= 0 || windowMinutes <= 0) return NO;
|
|
26
|
+
return reset > sampledAt && reset <= sampledAt + windowMinutes * 60.0 + QuotaResetSkewSeconds;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static BOOL QuotaWindowLooksCurrentAt(NSDictionary *quota, double windowMinutes,
|
|
30
|
+
NSTimeInterval sampledAt) {
|
|
22
31
|
NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class] ? quota[@"resets_at"] : nil;
|
|
23
|
-
if (!reset
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
if (!reset) return NO;
|
|
33
|
+
return ResetLooksCurrentAt(reset.doubleValue, windowMinutes, sampledAt);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static BOOL QuotaWindowLooksCurrent(NSDictionary *quota, double windowMinutes, NSTimeInterval now) {
|
|
37
|
+
return QuotaWindowLooksCurrentAt(quota, windowMinutes, now);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Codex 的 rate_limits 是一份会话快照,不会在窗口自然重置时自行刷新。一个快照里的
|
|
41
|
+
// 5 小时和 7 天窗口因此可能处于不同状态:例如 5 小时的 resets_at 已过去几天,但 7 天
|
|
42
|
+
// 的仍在未来。不能因为后者还活着,就把前者的旧百分比继续当成当前额度展示。
|
|
43
|
+
//
|
|
44
|
+
// 缺 resets_at 的旧版记录暂时保留,兼容历史会话和只提供百分比的上游版本;只要服务端给了
|
|
45
|
+
// 重置时间,就必须用它校验窗口。这个函数放在读取层而不是绘制层,状态栏、历史曲线和气泡
|
|
46
|
+
// 台词才能使用同一份已校正的数据。
|
|
47
|
+
static NSDictionary *UsageByRemovingInactiveQuotaWindows(NSDictionary *usage) {
|
|
48
|
+
if (![usage isKindOfClass:NSDictionary.class]) return usage;
|
|
49
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
50
|
+
NSDictionary<NSString *, NSNumber *> *windows = @{
|
|
51
|
+
@"fiveHour": @(FiveHourWindowMinutes),
|
|
52
|
+
@"week": @(SevenDayWindowMinutes)
|
|
53
|
+
};
|
|
54
|
+
NSMutableDictionary *result = nil;
|
|
55
|
+
NSMutableDictionary *expired = nil;
|
|
56
|
+
for (NSString *key in windows) {
|
|
57
|
+
NSDictionary *quota = [usage[key] isKindOfClass:NSDictionary.class] ? usage[key] : nil;
|
|
58
|
+
NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class]
|
|
59
|
+
? quota[@"resets_at"] : nil;
|
|
60
|
+
if (!reset || QuotaWindowLooksCurrent(quota, windows[key].doubleValue, now)) continue;
|
|
61
|
+
if (!result) result = [usage mutableCopy];
|
|
62
|
+
result[key] = NSNull.null;
|
|
63
|
+
// 百分比不再展示,但 resets_at 必须留下。窗口一旦被清空,"这个窗口已经重置过"
|
|
64
|
+
// 就再也无从得知——而缺失的窗口本来就用 NSNull 表示(官方没给),两者混在一起
|
|
65
|
+
// 分不开。ExhaustionStillHolds 要靠这份记录让受限标记按时失效,否则只剩一个
|
|
66
|
+
// 未到期的 7 天窗口时,一次限流会让卡片永久挂着"额度受限"。
|
|
67
|
+
if (!expired) expired = [NSMutableDictionary dictionary];
|
|
68
|
+
expired[key] = reset;
|
|
69
|
+
}
|
|
70
|
+
if (expired) result[@"expiredWindowResets"] = expired;
|
|
71
|
+
return result ?: usage;
|
|
26
72
|
}
|
|
27
73
|
|
|
28
74
|
// 同一个账号下的每个 Claude 会话都会把自己那次响应里的 rate_limits 抄到同一个文件上,
|
|
@@ -343,10 +389,68 @@ static NSDictionary *UsageFromCodexLine(NSData *lineData) {
|
|
|
343
389
|
};
|
|
344
390
|
}
|
|
345
391
|
|
|
346
|
-
//
|
|
392
|
+
// 受限事件没有窗口归属,只能给它一个有效期:快照里最短窗口的 resets_at 一过,那个窗口
|
|
393
|
+
// 必然已经重置,再挂着"额度受限"就是在声称一件我们已经不知道的事——而受限期间官方常年
|
|
394
|
+
// 只回 primary/secondary 全 null(见 UsageFromCodexLine),等"更新的快照"来推翻可能等不到。
|
|
395
|
+
// 真正用尽的是 7 天窗口时,5 小时窗口重置后仍会被拒,届时会写下新的 usage_limit_exceeded,
|
|
396
|
+
// 标记自己会贴回来。
|
|
397
|
+
static BOOL ExhaustionStillHolds(NSDictionary *usage, NSTimeInterval exhaustedAt) {
|
|
398
|
+
if (![usage isKindOfClass:NSDictionary.class] || exhaustedAt <= 0) return NO;
|
|
399
|
+
if (exhaustedAt < [usage[@"sampledAt"] doubleValue]) return NO;
|
|
400
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
401
|
+
NSTimeInterval earliestReset = 0;
|
|
402
|
+
BOOL foundReset = NO;
|
|
403
|
+
BOOL foundQuotaWithoutReset = NO;
|
|
404
|
+
NSDictionary<NSString *, NSNumber *> *windows = @{
|
|
405
|
+
@"fiveHour": @(FiveHourWindowMinutes),
|
|
406
|
+
@"week": @(SevenDayWindowMinutes)
|
|
407
|
+
};
|
|
408
|
+
NSDictionary *expired = [usage[@"expiredWindowResets"] isKindOfClass:NSDictionary.class]
|
|
409
|
+
? usage[@"expiredWindowResets"] : nil;
|
|
410
|
+
for (NSString *key in windows) {
|
|
411
|
+
NSDictionary *quota = [usage[key] isKindOfClass:NSDictionary.class] ? usage[key] : nil;
|
|
412
|
+
NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class] ? quota[@"resets_at"] : nil;
|
|
413
|
+
// 关键是“限额错误发生时”这个 reset 是否还属于当前窗口,而不是它现在是否已过期。
|
|
414
|
+
// 例如错误发生后 5 小时窗口自然重置,标记应当清掉;反过来,数天前就过期的
|
|
415
|
+
// 5 小时快照不能让一条刚发生的错误立即失效。
|
|
416
|
+
if (!quota) {
|
|
417
|
+
// 窗口被 UsageByRemovingInactiveQuotaWindows 清掉了,用它留下的 resets_at 继续
|
|
418
|
+
// 判断。少了这一支,5 小时窗口重置后标记就再也没有失效的依据。
|
|
419
|
+
NSNumber *expiredReset = [expired[key] isKindOfClass:NSNumber.class] ? expired[key] : nil;
|
|
420
|
+
if (!expiredReset) continue;
|
|
421
|
+
foundReset = YES;
|
|
422
|
+
double value = expiredReset.doubleValue;
|
|
423
|
+
if (!ResetLooksCurrentAt(value, windows[key].doubleValue, exhaustedAt)) continue;
|
|
424
|
+
if (earliestReset == 0 || value < earliestReset) earliestReset = value;
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
if (!reset) {
|
|
428
|
+
foundQuotaWithoutReset = YES;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
foundReset = YES;
|
|
432
|
+
if (!QuotaWindowLooksCurrentAt(quota, windows[key].doubleValue, exhaustedAt)) continue;
|
|
433
|
+
double value = reset.doubleValue;
|
|
434
|
+
if (earliestReset == 0 || value < earliestReset) earliestReset = value;
|
|
435
|
+
}
|
|
436
|
+
if (earliestReset > now) return YES;
|
|
437
|
+
// 有一个属于当前窗口的 reset 且它已经过去,说明额度确实重置了,标记必须清掉。
|
|
438
|
+
if (earliestReset > 0) return NO;
|
|
439
|
+
// 走到这里说明一个可用窗口都没有,推不出有效期。这恰恰是最需要受限提示的时刻——
|
|
440
|
+
// 上面注释里说的"受限期间官方常年只回 primary/secondary 全 null"就落在这个分支,
|
|
441
|
+
// app-server 也拿不到实时额度时更是如此。所以刚发生的错误先无条件保留一小段时间,
|
|
442
|
+
// 别让面板在用户正撞限额的当口显示一切正常。
|
|
443
|
+
if (now - exhaustedAt < RecentExhaustionGraceSeconds) return YES;
|
|
444
|
+
// 老版会话只给百分比、没有 resets_at 时无法推断受限状态的有效期;沿用之前的保守
|
|
445
|
+
// 行为,等更新的额度快照来清掉它。只要至少有一个明确的 reset,就以它为准。
|
|
446
|
+
return !foundReset && foundQuotaWithoutReset;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// 受限事件仍然成立时,把标记贴到 usage 上。事件本身没有窗口归属,面板只能提示"额度受限"
|
|
450
|
+
// 并把已有百分比标为快照,不能据此把 5 小时和 7 天窗口都判成 0。
|
|
347
451
|
static NSDictionary *UsageByMarkingExhaustion(NSDictionary *usage, NSTimeInterval exhaustedAt) {
|
|
348
|
-
if (![usage isKindOfClass:NSDictionary.class]
|
|
349
|
-
if (
|
|
452
|
+
if (![usage isKindOfClass:NSDictionary.class]) return usage;
|
|
453
|
+
if (!ExhaustionStillHolds(usage, exhaustedAt)) return usage;
|
|
350
454
|
NSMutableDictionary *result = [usage mutableCopy];
|
|
351
455
|
result[@"exhaustedAt"] = @(exhaustedAt);
|
|
352
456
|
return result;
|
|
@@ -514,10 +618,13 @@ static NSData *SessionTailData(NSURL *url) {
|
|
|
514
618
|
|
|
515
619
|
static BOOL UsageHasLiveWindow(NSDictionary *usage) {
|
|
516
620
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
517
|
-
|
|
621
|
+
NSDictionary<NSString *, NSNumber *> *windows = @{
|
|
622
|
+
@"fiveHour": @(FiveHourWindowMinutes),
|
|
623
|
+
@"week": @(SevenDayWindowMinutes)
|
|
624
|
+
};
|
|
625
|
+
for (NSString *key in windows) {
|
|
518
626
|
NSDictionary *quota = [usage[key] isKindOfClass:NSDictionary.class] ? usage[key] : nil;
|
|
519
|
-
|
|
520
|
-
if (reset && reset.doubleValue > now) return YES;
|
|
627
|
+
if (QuotaWindowLooksCurrent(quota, windows[key].doubleValue, now)) return YES;
|
|
521
628
|
}
|
|
522
629
|
return NO;
|
|
523
630
|
}
|
|
@@ -1222,6 +1329,7 @@ NSDictionary *LatestUsage(void) {
|
|
|
1222
1329
|
NSNumber *exhaustedAt = nil;
|
|
1223
1330
|
NSDictionary *usage = LatestUsageInData(tail, &exhaustedAt)
|
|
1224
1331
|
?: LatestQuotaInRecentSessions(sessions, newest);
|
|
1332
|
+
usage = UsageByRemovingInactiveQuotaWindows(usage);
|
|
1225
1333
|
// --status 这类一次性调用不带缓存也不写归档:它只需要当下这一份数字。
|
|
1226
1334
|
usage = UsageByAddingTokenTotals(usage, sessions, newest ? @[newest] : nil,
|
|
1227
1335
|
[NSMutableDictionary dictionary],
|
|
@@ -1285,6 +1393,7 @@ static const NSTimeInterval TokenCacheSaveInterval = 60.0;
|
|
|
1285
1393
|
}
|
|
1286
1394
|
- (NSDictionary *)usageWithTokenTotals:(NSDictionary *)usage {
|
|
1287
1395
|
if (![usage isKindOfClass:NSDictionary.class]) usage = @{};
|
|
1396
|
+
usage = UsageByRemovingInactiveQuotaWindows(usage);
|
|
1288
1397
|
NSString *identity = TokenWindowIdentity(usage);
|
|
1289
1398
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
1290
1399
|
BOOL reusable = !self.forcesTokenAggregation && self.tokenUsage &&
|
|
@@ -1293,7 +1402,7 @@ static const NSTimeInterval TokenCacheSaveInterval = 60.0;
|
|
|
1293
1402
|
if (reusable) {
|
|
1294
1403
|
NSMutableDictionary *result = [usage mutableCopy];
|
|
1295
1404
|
result[@"tokenUsage"] = self.tokenUsage;
|
|
1296
|
-
return
|
|
1405
|
+
return [self usageByApplyingExhaustion:result];
|
|
1297
1406
|
}
|
|
1298
1407
|
BOOL archiveChanged = NO;
|
|
1299
1408
|
// 正在增量读取的会话永远排在钉住列表最前面:它是最不该被漏掉的那一个,而漏掉它
|
|
@@ -1311,12 +1420,24 @@ static const NSTimeInterval TokenCacheSaveInterval = 60.0;
|
|
|
1311
1420
|
self.tokenWindowIdentity = identity;
|
|
1312
1421
|
self.tokenComputedAt = now;
|
|
1313
1422
|
self.forcesTokenAggregation = NO;
|
|
1314
|
-
return
|
|
1423
|
+
return [self usageByApplyingExhaustion:result];
|
|
1315
1424
|
}
|
|
1316
|
-
// 耗尽事件只往前走:额度恢复由"更新的额度快照"
|
|
1425
|
+
// 耗尽事件只往前走:额度恢复由"更新的额度快照"或窗口重置表达(见 ExhaustionStillHolds)。
|
|
1317
1426
|
- (void)noteExhaustion:(NSNumber *)timestamp {
|
|
1318
1427
|
if (timestamp.doubleValue > self.exhaustedAt) self.exhaustedAt = timestamp.doubleValue;
|
|
1319
1428
|
}
|
|
1429
|
+
// 标记失效时把记下的时刻一并清掉:留着它只会在下一轮再比一次同样的大小,而窗口一旦重置,
|
|
1430
|
+
// 这个时刻就永远不该再让任何快照被判成受限了。
|
|
1431
|
+
- (NSDictionary *)usageByApplyingExhaustion:(NSDictionary *)usage {
|
|
1432
|
+
if (![usage isKindOfClass:NSDictionary.class]) return usage;
|
|
1433
|
+
if (!ExhaustionStillHolds(usage, self.exhaustedAt)) {
|
|
1434
|
+
// 快照只会向前走(NewerUsageSnapshot),所以失效一次就是永久失效;真再撞上限流,
|
|
1435
|
+
// noteExhaustion: 会记下新的时刻。
|
|
1436
|
+
self.exhaustedAt = 0;
|
|
1437
|
+
return usage;
|
|
1438
|
+
}
|
|
1439
|
+
return UsageByMarkingExhaustion(usage, self.exhaustedAt);
|
|
1440
|
+
}
|
|
1320
1441
|
// 最近被写过的会话,最新的排在前面。并发会话不会太多,留 8 个足够覆盖一批 FSEvents;
|
|
1321
1442
|
// 更早的那些反正也会被目录扫描按 mtime 捞回来,钉住它们只是白读文件。
|
|
1322
1443
|
static const NSUInteger MaximumPinnedSessions = 8;
|
|
@@ -1495,7 +1616,7 @@ static const NSUInteger MaximumPinnedSessions = 8;
|
|
|
1495
1616
|
if (!chosen) chosen = currentSession;
|
|
1496
1617
|
// 一个候选都没选中就不会再走到 usageWithTokenTotals,刚记下的耗尽标记得在这里贴上。
|
|
1497
1618
|
if (!chosen) {
|
|
1498
|
-
self.usage =
|
|
1619
|
+
self.usage = [self usageByApplyingExhaustion:self.usage];
|
|
1499
1620
|
return self.usage;
|
|
1500
1621
|
}
|
|
1501
1622
|
if (![chosen.path isEqualToString:self.sessionURL.path]) [self selectSessionURL:chosen];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#import "CCPetsUsageMonitor.h"
|
|
2
2
|
#import "CCPetsUsage.h"
|
|
3
|
+
#import "CCPetsCodexRateLimits.h"
|
|
3
4
|
#import "CCPetsPaths.h"
|
|
4
5
|
#import <CoreServices/CoreServices.h>
|
|
5
6
|
#import <fcntl.h>
|
|
@@ -14,9 +15,12 @@
|
|
|
14
15
|
@interface CCPetsUsageMonitor ()
|
|
15
16
|
@property dispatch_queue_t queue;
|
|
16
17
|
@property CodexUsageReader *codexReader;
|
|
18
|
+
@property CCPetsCodexRateLimitsReader *codexRateLimitsReader;
|
|
17
19
|
@property ClaudeUsageReader *claudeReader;
|
|
18
20
|
@property(readwrite) NSDictionary *codexUsage;
|
|
19
21
|
@property(readwrite) NSDictionary *claudeUsage;
|
|
22
|
+
@property NSDictionary *codexLiveUsage;
|
|
23
|
+
@property NSTimeInterval codexLiveUsageUpdatedAt;
|
|
20
24
|
@property FSEventStreamRef codexStream;
|
|
21
25
|
@property dispatch_source_t claudeSource;
|
|
22
26
|
@property unsigned long long claudeSize;
|
|
@@ -24,8 +28,13 @@
|
|
|
24
28
|
@property BOOL started;
|
|
25
29
|
- (void)publishChange;
|
|
26
30
|
- (void)startClaudeSource;
|
|
31
|
+
- (NSDictionary *)usageByApplyingLiveCodexUsage:(NSDictionary *)sessionUsage;
|
|
27
32
|
@end
|
|
28
33
|
|
|
34
|
+
// App Server 是服务端当前额度的权威源;会话日志只在成功响应落盘时才更新。短暂失败时
|
|
35
|
+
// 留出一小段缓存寿命,既不因一次网络抖动闪回旧日志,也不会把实时值永久钉在界面上。
|
|
36
|
+
static const NSTimeInterval CodexLiveUsageTTL = 5 * 60.0;
|
|
37
|
+
|
|
29
38
|
static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
30
39
|
void *clientCallBackInfo, size_t numEvents, void *eventPaths,
|
|
31
40
|
const FSEventStreamEventFlags eventFlags[],
|
|
@@ -54,11 +63,13 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
65
|
if (requiresFullDiscovery) {
|
|
57
|
-
monitor.codexUsage = [monitor
|
|
66
|
+
monitor.codexUsage = [monitor usageByApplyingLiveCodexUsage:
|
|
67
|
+
[monitor.codexReader refreshWithFullDiscovery]];
|
|
58
68
|
} else if (changedSessions.count > 0) {
|
|
59
69
|
NSMutableArray<NSURL *> *urls = [NSMutableArray arrayWithCapacity:changedSessions.count];
|
|
60
70
|
for (NSString *path in changedSessions) [urls addObject:[NSURL fileURLWithPath:path]];
|
|
61
|
-
monitor.codexUsage = [monitor
|
|
71
|
+
monitor.codexUsage = [monitor usageByApplyingLiveCodexUsage:
|
|
72
|
+
[monitor.codexReader refreshForSessionURLs:urls]];
|
|
62
73
|
}
|
|
63
74
|
if (requiresFullDiscovery || changedSessions.count > 0) [monitor publishChange];
|
|
64
75
|
}
|
|
@@ -70,13 +81,37 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
70
81
|
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL,
|
|
71
82
|
QOS_CLASS_UTILITY, 0));
|
|
72
83
|
_codexReader = [CodexUsageReader new];
|
|
84
|
+
_codexRateLimitsReader = [CCPetsCodexRateLimitsReader new];
|
|
73
85
|
_claudeReader = [ClaudeUsageReader new];
|
|
74
86
|
// 桌宠是唯一的常驻读取者,摘要缓存由它维护并落盘。
|
|
75
87
|
_codexReader.persistsCache = YES;
|
|
76
88
|
_claudeReader.persistsCache = YES;
|
|
89
|
+
__weak typeof(self) weakSelf = self;
|
|
90
|
+
_codexRateLimitsReader.liveUsageHandler = ^(NSDictionary *liveUsage) {
|
|
91
|
+
dispatch_async(weakSelf.queue, ^{
|
|
92
|
+
typeof(self) strongSelf = weakSelf;
|
|
93
|
+
if (!strongSelf || !strongSelf.started) return;
|
|
94
|
+
strongSelf.codexLiveUsage = liveUsage;
|
|
95
|
+
strongSelf.codexLiveUsageUpdatedAt = NSDate.date.timeIntervalSince1970;
|
|
96
|
+
strongSelf.codexUsage = [strongSelf usageByApplyingLiveCodexUsage:
|
|
97
|
+
strongSelf.codexReader.usage ?: strongSelf.codexUsage];
|
|
98
|
+
[strongSelf publishChange];
|
|
99
|
+
});
|
|
100
|
+
};
|
|
77
101
|
}
|
|
78
102
|
return self;
|
|
79
103
|
}
|
|
104
|
+
|
|
105
|
+
- (NSDictionary *)usageByApplyingLiveCodexUsage:(NSDictionary *)sessionUsage {
|
|
106
|
+
if (self.codexLiveUsage && NSDate.date.timeIntervalSince1970 -
|
|
107
|
+
self.codexLiveUsageUpdatedAt > CodexLiveUsageTTL) {
|
|
108
|
+
self.codexLiveUsage = nil;
|
|
109
|
+
self.codexLiveUsageUpdatedAt = 0;
|
|
110
|
+
}
|
|
111
|
+
return self.codexLiveUsage
|
|
112
|
+
? CodexUsageByApplyingLiveUsage(sessionUsage, self.codexLiveUsage)
|
|
113
|
+
: sessionUsage;
|
|
114
|
+
}
|
|
80
115
|
// 回调交给主线程:下游全是 UI(面板重排、气泡定位、系统通知)。
|
|
81
116
|
- (void)publishChange {
|
|
82
117
|
void (^handler)(NSDictionary *, NSDictionary *) = self.changeHandler;
|
|
@@ -171,7 +206,9 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
171
206
|
- (void)refreshOnQueue {
|
|
172
207
|
if (!self.started) return;
|
|
173
208
|
// 手动刷新、面板打开和 120 秒兜底都走全量路径,Token 聚合的节流只约束 FSEvents 热路径。
|
|
174
|
-
self.codexUsage = [self
|
|
209
|
+
self.codexUsage = [self usageByApplyingLiveCodexUsage:
|
|
210
|
+
[self.codexReader refreshWithFullDiscovery]];
|
|
211
|
+
[self.codexRateLimitsReader refresh];
|
|
175
212
|
self.claudeUsage = [self readClaudeUsageChanged:NO forcingAggregation:YES];
|
|
176
213
|
if (!self.codexStream) [self startCodexStream];
|
|
177
214
|
if (!self.claudeSource) [self startClaudeSource];
|
|
@@ -186,6 +223,7 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
186
223
|
dispatch_sync(self.queue, ^{ [unsafeSelf teardownSources]; });
|
|
187
224
|
}
|
|
188
225
|
- (void)teardownSources {
|
|
226
|
+
[self.codexRateLimitsReader stop];
|
|
189
227
|
if (self.codexStream) {
|
|
190
228
|
FSEventStreamStop(self.codexStream);
|
|
191
229
|
FSEventStreamInvalidate(self.codexStream);
|
package/Sources/CCPets/PetView.m
CHANGED
|
@@ -376,12 +376,17 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
376
376
|
CGFloat dy = (point.y - centerY) / (NSHeight(self.bounds) * 0.16);
|
|
377
377
|
return dx * dx + dy * dy <= 1.0;
|
|
378
378
|
}
|
|
379
|
-
- (
|
|
380
|
-
[self noteActivity];
|
|
379
|
+
- (BOOL)updatePocketHoverForPoint:(NSPoint)point {
|
|
381
380
|
BOOL overPocket = [self isPocketPoint:point];
|
|
382
381
|
if (self.pocketHoverChanged) self.pocketHoverChanged(overPocket);
|
|
382
|
+
if (overPocket) [NSCursor.pointingHandCursor set];
|
|
383
|
+
else [NSCursor.arrowCursor set];
|
|
384
|
+
return overPocket;
|
|
385
|
+
}
|
|
386
|
+
- (void)updateHoverForPoint:(NSPoint)point {
|
|
387
|
+
[self noteActivity];
|
|
388
|
+
BOOL overPocket = [self updatePocketHoverForPoint:point];
|
|
383
389
|
if (overPocket) {
|
|
384
|
-
[NSCursor.pointingHandCursor set];
|
|
385
390
|
[self playRow:5 throughFrame:7 oneShot:NO];
|
|
386
391
|
} else if (point.y >= NSHeight(self.bounds) * 0.58) {
|
|
387
392
|
[NSCursor.pointingHandCursor set];
|
|
@@ -400,14 +405,16 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
400
405
|
[self playRow:0 throughFrame:5 oneShot:NO];
|
|
401
406
|
}
|
|
402
407
|
}
|
|
408
|
+
- (void)mouseEntered:(NSEvent *)event {
|
|
409
|
+
[self mouseMoved:event];
|
|
410
|
+
}
|
|
403
411
|
- (void)mouseMoved:(NSEvent *)event {
|
|
404
|
-
if (self.draggingPet
|
|
412
|
+
if (self.draggingPet) return;
|
|
405
413
|
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
else [NSCursor.arrowCursor set];
|
|
414
|
+
// 一次性动作只锁定动画,不应锁住面板热区。否则鼠标在动作期间进入后停住,
|
|
415
|
+
// oneShot 结束时不会再收到 mouseMoved,额度面板就一直没有机会展示。
|
|
416
|
+
if (self.oneShot || self.agentActive) {
|
|
417
|
+
[self updatePocketHoverForPoint:point];
|
|
411
418
|
return;
|
|
412
419
|
}
|
|
413
420
|
[self updateHoverForPoint:point];
|
|
@@ -416,7 +423,7 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
416
423
|
if (self.draggingPet) return;
|
|
417
424
|
if (self.pocketHoverChanged) self.pocketHoverChanged(NO);
|
|
418
425
|
[NSCursor.arrowCursor set];
|
|
419
|
-
if (self.agentActive) return;
|
|
426
|
+
if (self.agentActive || self.oneShot) return;
|
|
420
427
|
[self playRow:0 throughFrame:5 oneShot:NO];
|
|
421
428
|
}
|
|
422
429
|
- (void)nextFrame:(NSTimer *)timer {
|
|
@@ -551,8 +551,9 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
551
551
|
? self.codexShowsAPIUsage : self.claudeShowsAPIUsage;
|
|
552
552
|
NSNumber *fiveUsed = [self usedForQuota:five usedKey:usedKey];
|
|
553
553
|
NSNumber *weekUsed = [self usedForQuota:week usedKey:usedKey];
|
|
554
|
-
//
|
|
555
|
-
//
|
|
554
|
+
// usage_limit_exceeded 只能说明某次请求被额度限制,不能说明耗尽的是 5 小时还是
|
|
555
|
+
// 7 天窗口;切到 credits 后请求还能继续成功,但 rate_limits 可能一直为空。因此把它
|
|
556
|
+
// 作为独立的“额度受限”状态,不再拿一个无窗口归属的事件覆盖两个官方百分比。
|
|
556
557
|
BOOL exhausted = [usage[@"exhaustedAt"] isKindOfClass:NSNumber.class];
|
|
557
558
|
BOOL hasData = apiMode ? (monthTokens != nil)
|
|
558
559
|
: (fiveUsed || weekUsed || fiveTokens || weekTokens || exhausted);
|
|
@@ -590,9 +591,9 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
590
591
|
}
|
|
591
592
|
[name drawInRect:NSMakeRect(NSMinX(card) + 94, NSMinY(card) + 84, 88, 30)
|
|
592
593
|
withAttributes:[self textAttributesWithSize:22 color:primary weight:NSFontWeightBold]];
|
|
593
|
-
// 四态:额度被拒 →
|
|
594
|
-
//
|
|
595
|
-
NSString *statusText = (!apiMode && exhausted) ? @"
|
|
594
|
+
// 四态:额度被拒 → 额度受限(百分比仍是上次官方快照);没有任何额度数据 → 等待数据;
|
|
595
|
+
// 有数据但客户端已退出 → 离线;两者都有 → 在线。
|
|
596
|
+
NSString *statusText = (!apiMode && exhausted) ? @"额度受限"
|
|
596
597
|
: (!hasData ? @"等待数据" : (online ? @"● 在线" : @"离线"));
|
|
597
598
|
NSColor *statusColor = (!apiMode && exhausted) ? NSColor.systemOrangeColor
|
|
598
599
|
: (online && hasData ? NSColor.systemGreenColor : secondary);
|
|
@@ -708,19 +709,18 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
708
709
|
NSArray<NSDictionary *> *windows = @[
|
|
709
710
|
@{@"x": @(NSMinX(card) + 214), @"title": @"官方 5 小时窗口", @"quota": five ?: @{},
|
|
710
711
|
@"tokens": fiveTokens ?: @{}, @"used": fiveUsed ?: NSNull.null,
|
|
711
|
-
@"rolling": @"
|
|
712
|
+
@"rolling": @"官方额度待刷新"},
|
|
712
713
|
@{@"x": @(NSMinX(card) + 394), @"title": @"官方 7 天窗口", @"quota": week ?: @{},
|
|
713
714
|
@"tokens": weekTokens ?: @{}, @"used": weekUsed ?: NSNull.null,
|
|
714
|
-
@"rolling": @"
|
|
715
|
+
@"rolling": @"官方额度待刷新"}
|
|
715
716
|
];
|
|
716
717
|
for (NSDictionary *window in windows) {
|
|
717
718
|
CGFloat x = [window[@"x"] doubleValue];
|
|
718
719
|
[window[@"title"] drawInRect:NSMakeRect(x, NSMinY(card) + 114, 130, 20)
|
|
719
720
|
withAttributes:[self textAttributesWithSize:13 color:secondary weight:NSFontWeightRegular]];
|
|
720
721
|
NSNumber *used = [window[@"used"] isKindOfClass:NSNumber.class] ? window[@"used"] : nil;
|
|
721
|
-
double remaining =
|
|
722
|
-
NSString *official =
|
|
723
|
-
? [NSString stringWithFormat:@"%.0f%%", remaining] : @"--";
|
|
722
|
+
double remaining = used ? 100.0 - used.doubleValue : 0;
|
|
723
|
+
NSString *official = used ? [NSString stringWithFormat:@"%.0f%%", remaining] : @"--";
|
|
724
724
|
// 百分比是"剩余"、Token 是"已用",方向相反。后缀直接贴在数字右侧、
|
|
725
725
|
// 前缀写进 Token 行,否则两个数字并排看会被当成同一口径。
|
|
726
726
|
NSDictionary *valueAttributes = [self textAttributesWithSize:25
|
|
@@ -729,8 +729,14 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
729
729
|
CGFloat valueWidth = ceil([official sizeWithAttributes:valueAttributes].width);
|
|
730
730
|
[official drawInRect:NSMakeRect(x, NSMinY(card) + 74, valueWidth + 4, 34)
|
|
731
731
|
withAttributes:valueAttributes];
|
|
732
|
-
|
|
733
|
-
|
|
732
|
+
// 没有数字可标时不给口径标签:"-- 剩余"看起来像一个真实的 0 值,而实际上是
|
|
733
|
+
// 官方快照待刷新。下方的状态文字会说明它为何不可用。
|
|
734
|
+
NSString *valueLabel = !used ? @"" : (exhausted ? @"快照" : @"剩余");
|
|
735
|
+
if (valueLabel.length > 0) {
|
|
736
|
+
[valueLabel drawInRect:NSMakeRect(x + valueWidth + 7, NSMinY(card) + 78, 60, 20)
|
|
737
|
+
withAttributes:[self textAttributesWithSize:12 color:secondary
|
|
738
|
+
weight:NSFontWeightRegular]];
|
|
739
|
+
}
|
|
734
740
|
// 官方窗口拿不到时(账号没有这个窗口、或响应里没带),Token 走的是本机滚动窗口。
|
|
735
741
|
// 说清楚这一行的口径,比留一个 `--` 让人以为是渲染坏了要好。
|
|
736
742
|
NSString *resetValue = [self resetText:window[@"quota"]];
|
|
@@ -750,9 +756,12 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
750
756
|
withAttributes:[self textAttributesWithSize:13 color:secondary weight:NSFontWeightRegular]];
|
|
751
757
|
NSArray<NSDictionary *> *history = [name isEqualToString:@"Codex"]
|
|
752
758
|
? self.codexHistory : self.claudeHistory;
|
|
753
|
-
NSNumber *currentUsed =
|
|
759
|
+
NSNumber *currentUsed = weekUsed;
|
|
754
760
|
NSArray<NSDictionary *> *points = [self curvePointsFromHistory:history currentUsed:currentUsed];
|
|
755
|
-
NSDictionary *pace =
|
|
761
|
+
NSDictionary *pace = exhausted
|
|
762
|
+
? @{ @"label": @"待刷新", @"tip": @"等待新的官方额度快照",
|
|
763
|
+
@"color": NSColor.systemOrangeColor }
|
|
764
|
+
: [self paceStatusForQuota:week currentUsed:currentUsed color:color];
|
|
756
765
|
NSColor *paceColor = pace[@"color"];
|
|
757
766
|
NSDictionary *pillAttributes = [self textAttributesWithSize:11 color:paceColor
|
|
758
767
|
weight:NSFontWeightSemibold];
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Third-Party Notices
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
原创默认素材,与任何现有动漫、游戏或商业吉祥物无关,并与项目代码一同按 MIT License 分发。
|
|
3
|
+
English | [简体中文](./THIRD_PARTY_NOTICES.zh-CN.md)
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
The CC Pets distribution does not bundle character assets downloaded from PetDex.
|
|
6
|
+
The built-in `默认.webp` is an original default asset created for this project. It
|
|
7
|
+
is unrelated to any existing anime, game, or commercial mascot and is distributed
|
|
8
|
+
with the project code under the MIT License.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
At runtime, the app may read locally installed Codex/ChatGPT and Claude application
|
|
11
|
+
icons for interface identification. Those icons are not copied into this repository
|
|
12
|
+
or the npm package. Their trademarks and copyrights belong to their respective
|
|
13
|
+
owners.
|
|
11
14
|
|
|
15
|
+
Assets installed by users from PetDex or other sources are managed by those users
|
|
16
|
+
and are not part of this project distribution. Follow the applicable author,
|
|
17
|
+
platform, and rights-holder licenses and terms when using or redistributing them.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# 第三方声明
|
|
2
|
+
|
|
3
|
+
[English](./THIRD_PARTY_NOTICES.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
CC Pets 发布包不捆绑 PetDex 下载的角色素材。内置的 `默认.webp` 是专为本项目创建的
|
|
6
|
+
原创默认素材,与任何现有动漫、游戏或商业吉祥物无关,并与项目代码一同按 MIT License 分发。
|
|
7
|
+
|
|
8
|
+
程序会在运行时尝试读取用户本机已安装的 Codex/ChatGPT 和 Claude 应用图标,仅用于界面识别;
|
|
9
|
+
这些图标不会复制进仓库或 npm 发布包,其商标和版权归各自权利人所有。
|
|
10
|
+
|
|
11
|
+
用户通过 PetDex 或其他来源安装的素材由用户自行管理,不属于本项目发布内容。使用和再分发
|
|
12
|
+
此类素材时,请遵守对应作者、平台和权利人的许可证及使用条款。
|