cc-pets 1.2.5 → 1.2.6
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/Sources/CCPets/CCPetsAppDelegate.m +1 -1
- package/Sources/CCPets/CCPetsPreviews.m +20 -2
- package/Sources/CCPets/CCPetsQuotaHistory.h +2 -1
- package/Sources/CCPets/CCPetsQuotaHistory.m +7 -3
- package/Sources/CCPets/QuotaDashboardView.h +2 -2
- package/Sources/CCPets/QuotaDashboardView.m +157 -28
- package/package.json +1 -1
|
@@ -372,7 +372,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
372
372
|
- (NSString *)statusDetailForState:(NSString *)state {
|
|
373
373
|
if ([state isEqualToString:@"starting"]) return @"正在准备当前会话…";
|
|
374
374
|
if ([state isEqualToString:@"idle"]) return @"会话已就绪,等待你的下一条指令。";
|
|
375
|
-
if ([state isEqualToString:@"thinking"]) return @"
|
|
375
|
+
if ([state isEqualToString:@"thinking"]) return @"正在分析需求…";
|
|
376
376
|
if ([state isEqualToString:@"auto_review"]) return @"正在由 Auto-review 审核,无需手动操作。";
|
|
377
377
|
if ([state isEqualToString:@"approval"]) return @"请回到终端确认操作。";
|
|
378
378
|
if ([state isEqualToString:@"subagent"]) return @"正在协调子 Agent。";
|
|
@@ -33,8 +33,26 @@ int RenderQuotaDashboard(NSString *path) {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
view.historyEnabled = YES;
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
37
|
+
NSTimeInterval day = 24 * 60 * 60;
|
|
38
|
+
view.codexHistory = @[
|
|
39
|
+
@{@"timestamp": @(now - 6.5 * day), @"remaining": @88},
|
|
40
|
+
@{@"timestamp": @(now - 5.5 * day), @"remaining": @81},
|
|
41
|
+
@{@"timestamp": @(now - 4.5 * day), @"remaining": @75},
|
|
42
|
+
@{@"timestamp": @(now - 3.5 * day), @"remaining": @68},
|
|
43
|
+
@{@"timestamp": @(now - 2.5 * day), @"remaining": @62},
|
|
44
|
+
@{@"timestamp": @(now - 1.5 * day), @"remaining": @55},
|
|
45
|
+
@{@"timestamp": @(now - 0.5 * day), @"remaining": @49}
|
|
46
|
+
];
|
|
47
|
+
view.claudeHistory = @[
|
|
48
|
+
@{@"timestamp": @(now - 6.5 * day), @"remaining": @92},
|
|
49
|
+
@{@"timestamp": @(now - 5.5 * day), @"remaining": @86},
|
|
50
|
+
@{@"timestamp": @(now - 4.5 * day), @"remaining": @78},
|
|
51
|
+
@{@"timestamp": @(now - 3.5 * day), @"remaining": @72},
|
|
52
|
+
@{@"timestamp": @(now - 2.5 * day), @"remaining": @64},
|
|
53
|
+
@{@"timestamp": @(now - 1.5 * day), @"remaining": @58},
|
|
54
|
+
@{@"timestamp": @(now - 0.5 * day), @"remaining": @51}
|
|
55
|
+
];
|
|
38
56
|
view.activeAgentCount = 1;
|
|
39
57
|
// 预览里刻意只让一家在线,好把"有额度数据但客户端已退出"的离线态也画出来。
|
|
40
58
|
view.liveProviders = [NSSet setWithObject:@"Claude"];
|
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
// RecordQuotaHistory 返回当前文档,调用方直接复用,避免一轮刷新里重复读盘。
|
|
5
5
|
NSDictionary *QuotaHistoryDocument(void);
|
|
6
6
|
NSDictionary *RecordQuotaHistory(NSDictionary *codexUsage, NSDictionary *claudeUsage);
|
|
7
|
-
|
|
7
|
+
// 每个点保留 timestamp 与 weekRemaining,绘图层才能按真实时间轴展示缺口和重置。
|
|
8
|
+
NSArray<NSDictionary *> *QuotaHistorySeries(NSDictionary *document, NSString *provider);
|
|
@@ -75,15 +75,19 @@ NSDictionary *RecordQuotaHistory(NSDictionary *codexUsage, NSDictionary *claudeU
|
|
|
75
75
|
return updated;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
NSArray<
|
|
79
|
-
NSMutableArray<
|
|
78
|
+
NSArray<NSDictionary *> *QuotaHistorySeries(NSDictionary *document, NSString *provider) {
|
|
79
|
+
NSMutableArray<NSDictionary *> *series = [NSMutableArray array];
|
|
80
80
|
for (NSDictionary *sample in document[@"samples"]) {
|
|
81
81
|
if (![sample isKindOfClass:NSDictionary.class]) continue;
|
|
82
|
+
NSNumber *timestamp = [sample[@"timestamp"] isKindOfClass:NSNumber.class]
|
|
83
|
+
? sample[@"timestamp"] : nil;
|
|
82
84
|
NSDictionary *providerSample = [sample[provider] isKindOfClass:NSDictionary.class]
|
|
83
85
|
? sample[provider] : nil;
|
|
84
86
|
NSNumber *remaining = [providerSample[@"weekRemaining"] isKindOfClass:NSNumber.class]
|
|
85
87
|
? providerSample[@"weekRemaining"] : nil;
|
|
86
|
-
if (remaining)
|
|
88
|
+
if (timestamp && remaining) {
|
|
89
|
+
[series addObject:@{@"timestamp": timestamp, @"remaining": remaining}];
|
|
90
|
+
}
|
|
87
91
|
}
|
|
88
92
|
return series;
|
|
89
93
|
}
|
|
@@ -10,8 +10,8 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName);
|
|
|
10
10
|
@interface QuotaDashboardView : NSView
|
|
11
11
|
@property NSDictionary *codexUsage;
|
|
12
12
|
@property NSDictionary *claudeUsage;
|
|
13
|
-
@property NSArray<
|
|
14
|
-
@property NSArray<
|
|
13
|
+
@property NSArray<NSDictionary *> *codexHistory;
|
|
14
|
+
@property NSArray<NSDictionary *> *claudeHistory;
|
|
15
15
|
@property BOOL historyEnabled;
|
|
16
16
|
@property NSInteger activeAgentCount;
|
|
17
17
|
// 仍在运行的客户端所属的 provider("Codex" / "Claude")。卡片的在线徽章据此判定,
|
|
@@ -226,21 +226,132 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
226
226
|
[color setFill];
|
|
227
227
|
[[NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius] fill];
|
|
228
228
|
}
|
|
229
|
-
- (
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
229
|
+
- (NSArray<NSDictionary *> *)curvePointsFromHistory:(NSArray<NSDictionary *> *)history
|
|
230
|
+
currentUsed:(NSNumber *)currentUsed {
|
|
231
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
232
|
+
NSTimeInterval cutoff = now - 7 * 24 * 60 * 60;
|
|
233
|
+
NSMutableArray<NSDictionary *> *points = [NSMutableArray array];
|
|
234
|
+
if (self.historyEnabled) {
|
|
235
|
+
for (NSDictionary *sample in history) {
|
|
236
|
+
if (![sample isKindOfClass:NSDictionary.class]) continue;
|
|
237
|
+
NSNumber *timestamp = [sample[@"timestamp"] isKindOfClass:NSNumber.class]
|
|
238
|
+
? sample[@"timestamp"] : nil;
|
|
239
|
+
NSNumber *remaining = [sample[@"remaining"] isKindOfClass:NSNumber.class]
|
|
240
|
+
? sample[@"remaining"] : nil;
|
|
241
|
+
if (!timestamp || !remaining || timestamp.doubleValue < cutoff) continue;
|
|
242
|
+
double used = 100.0 - fmax(0, fmin(100, remaining.doubleValue));
|
|
243
|
+
[points addObject:@{@"timestamp": timestamp, @"used": @(used)}];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// 终点必须和卡片上的当前官方额度同源;历史落盘最多会慢 15 分钟,不能直接拿它
|
|
247
|
+
// 冒充“当前”,否则同一张卡里会出现两个不同百分比。
|
|
248
|
+
if (currentUsed) {
|
|
249
|
+
[points addObject:@{@"timestamp": @(now), @"used": currentUsed}];
|
|
250
|
+
}
|
|
251
|
+
return points;
|
|
252
|
+
}
|
|
253
|
+
- (void)appendCurveFromPoint:(NSPoint)from toPoint:(NSPoint)to path:(NSBezierPath *)path {
|
|
254
|
+
CGFloat controlOffset = (to.x - from.x) / 3.0;
|
|
255
|
+
[path curveToPoint:to
|
|
256
|
+
controlPoint1:NSMakePoint(from.x + controlOffset, from.y)
|
|
257
|
+
controlPoint2:NSMakePoint(to.x - controlOffset, to.y)];
|
|
258
|
+
}
|
|
259
|
+
- (void)drawCurveSegment:(NSArray<NSValue *> *)segment inRect:(NSRect)rect color:(NSColor *)color {
|
|
260
|
+
if (segment.count == 0) return;
|
|
261
|
+
NSBezierPath *line = [NSBezierPath bezierPath];
|
|
262
|
+
NSPoint first = segment.firstObject.pointValue;
|
|
263
|
+
[line moveToPoint:first];
|
|
264
|
+
NSPoint previous = first;
|
|
265
|
+
for (NSUInteger index = 1; index < segment.count; index++) {
|
|
266
|
+
NSPoint point = segment[index].pointValue;
|
|
267
|
+
[self appendCurveFromPoint:previous toPoint:point path:line];
|
|
268
|
+
previous = point;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
NSBezierPath *fill = [line copy];
|
|
272
|
+
[fill lineToPoint:NSMakePoint(previous.x, NSMinY(rect))];
|
|
273
|
+
[fill lineToPoint:NSMakePoint(first.x, NSMinY(rect))];
|
|
274
|
+
[fill closePath];
|
|
275
|
+
[NSGraphicsContext saveGraphicsState];
|
|
276
|
+
[fill addClip];
|
|
277
|
+
NSGradient *area = [[NSGradient alloc]
|
|
278
|
+
initWithStartingColor:[color colorWithAlphaComponent:0.34]
|
|
279
|
+
endingColor:[color colorWithAlphaComponent:0.025]];
|
|
280
|
+
[area drawFromPoint:NSMakePoint(NSMidX(rect), NSMaxY(rect))
|
|
281
|
+
toPoint:NSMakePoint(NSMidX(rect), NSMinY(rect)) options:0];
|
|
282
|
+
[NSGraphicsContext restoreGraphicsState];
|
|
283
|
+
|
|
284
|
+
[[color colorWithAlphaComponent:0.95] setStroke];
|
|
285
|
+
line.lineWidth = 2;
|
|
286
|
+
[line stroke];
|
|
287
|
+
}
|
|
288
|
+
- (void)drawUsageCurve:(NSArray<NSDictionary *> *)points inRect:(NSRect)rect
|
|
289
|
+
color:(NSColor *)color {
|
|
290
|
+
[[NSColor colorWithWhite:1 alpha:0.08] setStroke];
|
|
291
|
+
[NSBezierPath strokeLineFromPoint:NSMakePoint(NSMinX(rect), NSMinY(rect))
|
|
292
|
+
toPoint:NSMakePoint(NSMaxX(rect), NSMinY(rect))];
|
|
293
|
+
if (points.count == 0) return;
|
|
294
|
+
|
|
295
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
296
|
+
NSTimeInterval cutoff = now - 7 * 24 * 60 * 60;
|
|
297
|
+
// 曲线始终连成一段:采样缺口只代表桌宠当时没在运行,不代表没有消耗,
|
|
298
|
+
// 缺口两端直接插值比断开更接近真实轨迹;窗口重置带来的回落本身也是真实变化。
|
|
299
|
+
NSMutableArray<NSValue *> *allPoints = [NSMutableArray arrayWithCapacity:points.count];
|
|
300
|
+
for (NSDictionary *sample in points) {
|
|
301
|
+
NSTimeInterval timestamp = [sample[@"timestamp"] doubleValue];
|
|
302
|
+
double used = fmax(0, fmin(100, [sample[@"used"] doubleValue]));
|
|
303
|
+
CGFloat x = NSMinX(rect) + NSWidth(rect) * (timestamp - cutoff) / (now - cutoff);
|
|
304
|
+
CGFloat y = NSMinY(rect) + NSHeight(rect) * used / 100.0;
|
|
305
|
+
[allPoints addObject:[NSValue valueWithPoint:NSMakePoint(
|
|
306
|
+
fmax(NSMinX(rect), fmin(NSMaxX(rect), x)), y)]];
|
|
243
307
|
}
|
|
308
|
+
[self drawCurveSegment:allPoints inRect:rect color:color];
|
|
309
|
+
}
|
|
310
|
+
- (NSDictionary *)paceStatusForQuota:(NSDictionary *)quota currentUsed:(NSNumber *)currentUsed
|
|
311
|
+
color:(NSColor *)providerColor {
|
|
312
|
+
if (!currentUsed) {
|
|
313
|
+
return @{@"label": @"数据不足", @"tip": @"等待官方额度数据",
|
|
314
|
+
@"color": self.secondaryColor};
|
|
315
|
+
}
|
|
316
|
+
NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class]
|
|
317
|
+
? quota[@"resets_at"] : nil;
|
|
318
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
319
|
+
const NSTimeInterval sevenDaySeconds = 7 * 24 * 60 * 60;
|
|
320
|
+
NSTimeInterval start = reset ? reset.doubleValue - sevenDaySeconds : 0;
|
|
321
|
+
NSTimeInterval elapsed = now - start;
|
|
322
|
+
double projectedRemaining = NAN;
|
|
323
|
+
const NSTimeInterval paceObservationSeconds = 24 * 60 * 60;
|
|
324
|
+
if (reset && reset.doubleValue > now && elapsed >= paceObservationSeconds) {
|
|
325
|
+
double projectedUsed = currentUsed.doubleValue * sevenDaySeconds / elapsed;
|
|
326
|
+
projectedRemaining = 100.0 - projectedUsed;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
double remaining = 100.0 - currentUsed.doubleValue;
|
|
330
|
+
NSString *label = remaining >= 70 ? @"充足"
|
|
331
|
+
: (remaining >= 40 ? @"平稳" : (remaining >= 15 ? @"需关注" : @"高风险"));
|
|
332
|
+
NSString *tip = remaining >= 70 ? @"当前额度余量充足"
|
|
333
|
+
: (remaining >= 40 ? @"当前额度余量平稳"
|
|
334
|
+
: (remaining >= 15 ? @"建议关注额度余量" : @"当前额度余量较低"));
|
|
335
|
+
NSColor *statusColor = remaining >= 70 ? NSColor.systemGreenColor
|
|
336
|
+
: (remaining >= 40 ? providerColor
|
|
337
|
+
: (remaining >= 15 ? NSColor.systemOrangeColor : NSColor.systemRedColor));
|
|
338
|
+
// 当前窗口开始满 24 小时后再按消耗节奏预测。此前只看真实剩余额度,避免把
|
|
339
|
+
// 开窗头几个小时的突发任务线性外推到整整 7 天,造成“高风险”误报。
|
|
340
|
+
if (!isnan(projectedRemaining) &&
|
|
341
|
+
(remaining <= 5 || projectedRemaining < 0)) {
|
|
342
|
+
label = @"高风险";
|
|
343
|
+
tip = @"预计重置前额度用尽";
|
|
344
|
+
statusColor = NSColor.systemRedColor;
|
|
345
|
+
} else if (!isnan(projectedRemaining) && projectedRemaining < 10) {
|
|
346
|
+
label = @"需关注";
|
|
347
|
+
tip = @"建议减少高消耗任务";
|
|
348
|
+
statusColor = NSColor.systemOrangeColor;
|
|
349
|
+
} else if (!isnan(projectedRemaining) && projectedRemaining >= 30) {
|
|
350
|
+
label = @"充足";
|
|
351
|
+
tip = @"按当前节奏额度充足";
|
|
352
|
+
statusColor = NSColor.systemGreenColor;
|
|
353
|
+
}
|
|
354
|
+
return @{@"label": label, @"tip": tip, @"color": statusColor};
|
|
244
355
|
}
|
|
245
356
|
- (void)drawProvider:(NSString *)name usage:(NSDictionary *)usage usedKey:(NSString *)usedKey
|
|
246
357
|
color:(NSColor *)color cardRect:(NSRect)card {
|
|
@@ -308,10 +419,10 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
308
419
|
NSArray<NSDictionary *> *windows = @[
|
|
309
420
|
@{@"x": @(NSMinX(card) + 214), @"title": @"官方 5 小时窗口", @"quota": five ?: @{},
|
|
310
421
|
@"tokens": fiveTokens ?: @{}, @"used": fiveUsed ?: NSNull.null,
|
|
311
|
-
@"rolling": @"
|
|
422
|
+
@"rolling": @"无限制"},
|
|
312
423
|
@{@"x": @(NSMinX(card) + 394), @"title": @"官方 7 天窗口", @"quota": week ?: @{},
|
|
313
424
|
@"tokens": weekTokens ?: @{}, @"used": weekUsed ?: NSNull.null,
|
|
314
|
-
@"rolling": @"
|
|
425
|
+
@"rolling": @"无限制"}
|
|
315
426
|
];
|
|
316
427
|
for (NSDictionary *window in windows) {
|
|
317
428
|
CGFloat x = [window[@"x"] doubleValue];
|
|
@@ -339,24 +450,42 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
339
450
|
// 说清楚这一行的口径,比留一个 `--` 让人以为是渲染坏了要好。
|
|
340
451
|
NSString *resetValue = [self resetText:window[@"quota"]];
|
|
341
452
|
NSString *reset = [resetValue isEqualToString:@"--"]
|
|
342
|
-
? window[@"rolling"] : [NSString stringWithFormat:@"
|
|
453
|
+
? window[@"rolling"] : [NSString stringWithFormat:@"重置时间 %@", resetValue];
|
|
343
454
|
[reset drawInRect:NSMakeRect(x, NSMinY(card) + 22, 150, 18)
|
|
344
455
|
withAttributes:[self textAttributesWithSize:11 color:secondary weight:NSFontWeightRegular]];
|
|
345
456
|
}
|
|
346
457
|
|
|
347
458
|
CGFloat trendX = NSMinX(card) + 564;
|
|
348
|
-
[@"
|
|
459
|
+
[@"使用趋势" drawInRect:NSMakeRect(trendX, NSMinY(card) + 114, 145, 20)
|
|
349
460
|
withAttributes:[self textAttributesWithSize:13 color:secondary weight:NSFontWeightRegular]];
|
|
350
|
-
NSArray<
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
[
|
|
359
|
-
|
|
461
|
+
NSArray<NSDictionary *> *history = [name isEqualToString:@"Codex"]
|
|
462
|
+
? self.codexHistory : self.claudeHistory;
|
|
463
|
+
NSNumber *currentUsed = exhausted ? @100 : weekUsed;
|
|
464
|
+
NSArray<NSDictionary *> *points = [self curvePointsFromHistory:history currentUsed:currentUsed];
|
|
465
|
+
NSDictionary *pace = [self paceStatusForQuota:week currentUsed:currentUsed color:color];
|
|
466
|
+
NSColor *paceColor = pace[@"color"];
|
|
467
|
+
NSDictionary *pillAttributes = [self textAttributesWithSize:11 color:paceColor
|
|
468
|
+
weight:NSFontWeightSemibold];
|
|
469
|
+
CGFloat pillWidth = ceil([pace[@"label"] sizeWithAttributes:pillAttributes].width) + 18;
|
|
470
|
+
NSRect pill = NSMakeRect(trendX, NSMinY(card) + 88, pillWidth, 22);
|
|
471
|
+
[self fillRoundedRect:pill radius:11 color:[paceColor colorWithAlphaComponent:0.14]];
|
|
472
|
+
[pace[@"label"] drawInRect:NSInsetRect(pill, 9, 3) withAttributes:pillAttributes];
|
|
473
|
+
|
|
474
|
+
NSRect curveRect = NSMakeRect(trendX, NSMinY(card) + 43, 135, 38);
|
|
475
|
+
[self drawUsageCurve:points inRect:curveRect color:color];
|
|
476
|
+
double peak = 0;
|
|
477
|
+
for (NSDictionary *point in points) peak = fmax(peak, [point[@"used"] doubleValue]);
|
|
478
|
+
NSString *peakText = points.count > 0
|
|
479
|
+
? [NSString stringWithFormat:@"最高 %.0f%%", peak] : @"最高 --";
|
|
480
|
+
NSString *currentText = currentUsed
|
|
481
|
+
? [NSString stringWithFormat:@"当前 %.0f%%", currentUsed.doubleValue] : @"当前 --";
|
|
482
|
+
[peakText drawInRect:NSMakeRect(trendX, NSMinY(card) + 25, 72, 16)
|
|
483
|
+
withAttributes:[self textAttributesWithSize:10 color:secondary weight:NSFontWeightRegular]];
|
|
484
|
+
[currentText drawInRect:NSMakeRect(trendX + 66, NSMinY(card) + 25, 69, 16)
|
|
485
|
+
withAttributes:[self rightAlignedTextAttributesWithSize:10 color:secondary
|
|
486
|
+
weight:NSFontWeightRegular]];
|
|
487
|
+
[pace[@"tip"] drawInRect:NSMakeRect(trendX, NSMinY(card) + 7, 145, 16)
|
|
488
|
+
withAttributes:[self textAttributesWithSize:10 color:paceColor weight:NSFontWeightMedium]];
|
|
360
489
|
}
|
|
361
490
|
- (void)drawRect:(NSRect)dirtyRect {
|
|
362
491
|
[NSGraphicsContext saveGraphicsState];
|