cc-pets 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +19 -0
- package/CC_BRIDGE.zh-CN.md +15 -0
- package/CHANGELOG.md +51 -0
- package/CHANGELOG.zh-CN.md +51 -0
- package/CONTRIBUTING.md +22 -0
- package/CONTRIBUTING.zh-CN.md +17 -0
- package/README.md +117 -26
- package/README.zh-CN.md +92 -22
- package/Resources/AgentIcons/claude.png +0 -0
- package/Resources/AgentIcons/codex.icns +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.vsix +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.zip +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +155 -27
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +12 -6
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +1 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +3 -6
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +113 -47
- package/Sources/CCPets/App/CCPetsAppDelegate.h +2 -2
- package/Sources/CCPets/App/main.m +6 -0
- package/Sources/CCPets/Bridge/CCPetsBridge.m +11 -6
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +78 -38
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +2 -3
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +50 -32
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +46 -40
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +9 -6
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +171 -53
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.h +21 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.m +503 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +367 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +2 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +107 -25
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.m +64 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.h +23 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.m +475 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +2 -2
- package/Sources/CCPets/Support/CCPetsDoctor.m +26 -12
- package/Sources/CCPets/Support/CCPetsPreferences.h +2 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +34 -2
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +2 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +18 -7
- package/Sources/CCPets/UI/CCPetsGlassView.h +26 -4
- package/Sources/CCPets/UI/CCPetsGlassView.m +40 -9
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +2 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +561 -66
- package/Sources/CCPets/UI/CCPetsUIStyle.h +5 -2
- package/Sources/CCPets/UI/CCPetsUIStyle.m +57 -8
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +4 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +23 -28
- package/Sources/CCPets/UI/CCPetsUsageStore.m +2 -2
- package/Sources/CCPets/Usage/CCPetsUsage+CodexBackground.m +193 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +1 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +49 -11
- package/Sources/CCPets/Usage/CCPetsUsage.h +3 -2
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +15 -17
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +11 -29
- package/Sources/CCPets/Usage/QuotaDashboardView.m +128 -2
- package/THIRD_PARTY_NOTICES.md +7 -3
- package/THIRD_PARTY_NOTICES.zh-CN.md +5 -1
- package/bin/claude-with-pet +2 -0
- package/bin/codex-with-pet +2 -0
- package/package.json +5 -1
- package/plugins/jetbrains/README.md +62 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalBridge.java +379 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalIdentity.java +24 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalStartup.java +12 -0
- package/plugins/jetbrains/src/main/resources/META-INF/plugin.xml +23 -0
- package/plugins/jetbrains/src/main/resources/META-INF/pluginIcon.svg +380 -0
- package/plugins/vscode/README.md +63 -0
- package/plugins/vscode/extension.js +210 -0
- package/plugins/vscode/package.json +18 -0
- package/scripts/build-idea-plugin.sh +101 -0
- package/scripts/build-vscode-extension.sh +112 -0
- package/scripts/build.sh +24 -2
- package/scripts/compile-cached.zsh +133 -0
|
@@ -44,7 +44,8 @@ NSDictionary *UsageByRemovingExpiredQuotaWindows(NSDictionary *usage);
|
|
|
44
44
|
// models: @{模型名: counts} 区间合计
|
|
45
45
|
// daily: @[@{timestamp: 日零点, models: @{模型名: counts}}] 每天一项,没数据的天 models 为空
|
|
46
46
|
// counts 的键:input(非缓存输入)/ cacheRead / cacheWrite / output / reasoning(output 的子集)/
|
|
47
|
-
// requests
|
|
47
|
+
// requests / background(后台请求的总 Token,缺少分类明细)。
|
|
48
|
+
// input + cacheRead + cacheWrite + output + background 互不重叠,等于总 Token。
|
|
48
49
|
// 用自己的缓存和按日归档(Claude Code 默认约 30 天后清理转录,归档里留得更久),
|
|
49
50
|
// 不碰桌宠悬停面板用的那套缓存。
|
|
50
51
|
// 每次调用都会把缓存清理到只剩 [start, end) 涉及的会话文件,所以调用方应固定用同一个最长区间,
|
|
@@ -52,6 +53,6 @@ NSDictionary *UsageByRemovingExpiredQuotaWindows(NSDictionary *usage);
|
|
|
52
53
|
NSDictionary *CCPetsModelUsage(NSString *provider, NSTimeInterval start, NSTimeInterval end);
|
|
53
54
|
NSDictionary *CCPetsModelUsageAtHome(NSString *provider, NSString *home,
|
|
54
55
|
NSTimeInterval start, NSTimeInterval end);
|
|
55
|
-
//
|
|
56
|
+
// 总 Token = input + cacheRead + cacheWrite + output + background(reasoning 不另加)。
|
|
56
57
|
// 数据层归档取大和 UI 的合计共用这一个口径。
|
|
57
58
|
unsigned long long CCPetsTotalTokens(NSDictionary *counts);
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
@property NSMutableDictionary<NSString *, NSDictionary *> *codexProfileLiveUsages;
|
|
31
31
|
@property NSMutableDictionary<NSString *, NSString *> *profileReaderHomes;
|
|
32
32
|
@property NSDictionary *codexLiveUsage;
|
|
33
|
-
@property NSTimeInterval codexLiveUsageUpdatedAt;
|
|
34
33
|
@property FSEventStreamRef codexStream;
|
|
35
34
|
@property dispatch_source_t claudeSource;
|
|
36
35
|
@property unsigned long long claudeSize;
|
|
@@ -47,6 +46,18 @@
|
|
|
47
46
|
// 失败时不能让一次旧的受限结论一直挂着。
|
|
48
47
|
static const NSTimeInterval CodexLiveUsageTTL = 5 * 60.0;
|
|
49
48
|
|
|
49
|
+
// 默认账号、自定义 Home、缓存恢复和实时回调共用同一条合并路径。
|
|
50
|
+
// 用采样时间计龄,轮询旧缓存不会延长受限标记的寿命;窗口百分比仍按新旧快照择优。
|
|
51
|
+
static NSDictionary *ApplyLiveCodexUsage(NSDictionary *sessionUsage, NSDictionary *live) {
|
|
52
|
+
if (live[@"exhaustedAt"] && NSDate.date.timeIntervalSince1970 -
|
|
53
|
+
[live[@"sampledAt"] doubleValue] > CodexLiveUsageTTL) {
|
|
54
|
+
NSMutableDictionary *withoutExhaustion = [live mutableCopy];
|
|
55
|
+
[withoutExhaustion removeObjectForKey:@"exhaustedAt"];
|
|
56
|
+
live = withoutExhaustion;
|
|
57
|
+
}
|
|
58
|
+
return UsageByRemovingExpiredQuotaWindows(CodexUsageByApplyingLiveUsage(sessionUsage, live));
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
static BOOL HasRegisteredDefaultProfile(NSString *provider) {
|
|
51
62
|
NSString *target = ([provider isEqualToString:CCPetsProfileProviderClaude]
|
|
52
63
|
? DefaultClaudeConfigDirectory() : DefaultCodexHomeDirectory()).stringByStandardizingPath;
|
|
@@ -140,14 +151,12 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
140
151
|
// 桌宠随最后一个客户端退出,下次启动时 App Server 要几秒才回话。这段时间先用上次
|
|
141
152
|
// 存下的实时值,否则面板会先显示会话日志里可能已经过时十几个小时的快照。
|
|
142
153
|
_codexLiveUsage = LoadCodexLiveUsage();
|
|
143
|
-
_codexLiveUsageUpdatedAt = [_codexLiveUsage[@"sampledAt"] doubleValue];
|
|
144
154
|
__weak typeof(self) weakSelf = self;
|
|
145
155
|
_codexRateLimitsReader.liveUsageHandler = ^(NSDictionary *liveUsage) {
|
|
146
156
|
dispatch_async(weakSelf.queue, ^{
|
|
147
157
|
typeof(self) strongSelf = weakSelf;
|
|
148
158
|
if (!strongSelf || !strongSelf.started) return;
|
|
149
159
|
strongSelf.codexLiveUsage = liveUsage;
|
|
150
|
-
strongSelf.codexLiveUsageUpdatedAt = NSDate.date.timeIntervalSince1970;
|
|
151
160
|
SaveCodexLiveUsage(liveUsage);
|
|
152
161
|
strongSelf.codexUsage = [strongSelf usageByApplyingLiveCodexUsage:
|
|
153
162
|
strongSelf.codexReader.usage ?: strongSelf.codexUsage];
|
|
@@ -159,16 +168,7 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
159
168
|
}
|
|
160
169
|
|
|
161
170
|
- (NSDictionary *)usageByApplyingLiveCodexUsage:(NSDictionary *)sessionUsage {
|
|
162
|
-
|
|
163
|
-
if (!live) return sessionUsage;
|
|
164
|
-
if (live[@"exhaustedAt"] && NSDate.date.timeIntervalSince1970 -
|
|
165
|
-
self.codexLiveUsageUpdatedAt > CodexLiveUsageTTL) {
|
|
166
|
-
NSMutableDictionary *withoutExhaustion = [live mutableCopy];
|
|
167
|
-
[withoutExhaustion removeObjectForKey:@"exhaustedAt"];
|
|
168
|
-
live = withoutExhaustion;
|
|
169
|
-
}
|
|
170
|
-
// 存下来的实时值可能是好几个小时前的,窗口早已翻篇,合并后要再按 resets_at 过一遍。
|
|
171
|
-
return UsageByRemovingExpiredQuotaWindows(CodexUsageByApplyingLiveUsage(sessionUsage, live));
|
|
171
|
+
return ApplyLiveCodexUsage(sessionUsage, self.codexLiveUsage);
|
|
172
172
|
}
|
|
173
173
|
// 回调交给主线程:下游全是 UI(面板重排、气泡定位、系统通知)。
|
|
174
174
|
- (void)publishChange {
|
|
@@ -249,8 +249,7 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
249
249
|
}
|
|
250
250
|
usage = [reader refreshWithFullDiscovery];
|
|
251
251
|
NSDictionary *live = self.codexProfileLiveUsages[profileID];
|
|
252
|
-
|
|
253
|
-
CodexUsageByApplyingLiveUsage(usage, live));
|
|
252
|
+
usage = ApplyLiveCodexUsage(usage, live);
|
|
254
253
|
CCPetsCodexRateLimitsReader *rateReader = self.codexProfileRateReaders[profileID];
|
|
255
254
|
if (!rateReader) {
|
|
256
255
|
rateReader = [[CCPetsCodexRateLimitsReader alloc] initWithCodexHome:home];
|
|
@@ -263,8 +262,7 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
263
262
|
strongSelf.codexProfileLiveUsages[capturedID] = liveUsage;
|
|
264
263
|
NSMutableDictionary *updated = [strongSelf.profileUsages mutableCopy] ?: [NSMutableDictionary dictionary];
|
|
265
264
|
NSDictionary *session = strongSelf.codexProfileReaders[capturedID].usage;
|
|
266
|
-
|
|
267
|
-
CodexUsageByApplyingLiveUsage(session, liveUsage));
|
|
265
|
+
updated[capturedID] = ApplyLiveCodexUsage(session, liveUsage);
|
|
268
266
|
strongSelf.profileUsages = updated;
|
|
269
267
|
[strongSelf publishChange];
|
|
270
268
|
});
|
|
@@ -198,46 +198,28 @@
|
|
|
198
198
|
dotColor:tokenComparison[@"color"]];
|
|
199
199
|
|
|
200
200
|
CGFloat trendX = NSMinX(card) + 574;
|
|
201
|
-
//
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (self.usesLiquidGlass) {
|
|
206
|
-
[self drawText:L(@"Daily tokens") inRect:NSMakeRect(trendX + 62, NSMinY(card) + 114, 84, 20)
|
|
207
|
-
size:11 weight:NSFontWeightSemibold color:color dotColor:color];
|
|
208
|
-
} else {
|
|
209
|
-
NSDictionary *pillAttributes = [self textAttributesWithSize:11 color:color
|
|
210
|
-
weight:NSFontWeightSemibold];
|
|
211
|
-
NSRect pill = NSMakeRect(trendX + 59, NSMinY(card) + 113, 76, 22);
|
|
212
|
-
[self fillRoundedRect:pill radius:11 color:[color colorWithAlphaComponent:0.14]];
|
|
213
|
-
[L(@"Daily tokens") drawInRect:NSInsetRect(pill, 9, 3) withAttributes:pillAttributes];
|
|
214
|
-
}
|
|
215
|
-
NSRect curveRect = NSMakeRect(trendX, NSMinY(card) + 62, 135, 38);
|
|
201
|
+
// 今日用量和记录天数各占一行,峰值放进悬浮提示。
|
|
202
|
+
[self drawText:L(@"Month") inRect:NSMakeRect(trendX, NSMinY(card) + 114, 145, 20)
|
|
203
|
+
size:13 weight:NSFontWeightRegular color:secondary dotColor:nil];
|
|
204
|
+
NSRect curveRect = NSMakeRect(trendX, NSMinY(card) + 66, 135, 34);
|
|
216
205
|
[self drawMonthlyTokenCurve:monthDaily inRect:curveRect color:color];
|
|
217
|
-
double peak = 0;
|
|
218
206
|
NSDictionary *todayTotals = nil;
|
|
219
207
|
for (NSDictionary *day in monthDaily) {
|
|
220
208
|
if ([day[@"timestamp"] doubleValue] > now) break;
|
|
221
209
|
NSDictionary *totals = [day[@"totals"] isKindOfClass:NSDictionary.class]
|
|
222
210
|
? day[@"totals"] : nil;
|
|
223
|
-
peak = fmax(peak, [totals[@"total_tokens"] doubleValue]);
|
|
224
211
|
todayTotals = totals;
|
|
225
212
|
}
|
|
226
|
-
NSString *peakText = recordedDays > 0
|
|
227
|
-
? [NSString stringWithFormat:L(@"Peak %@"), [self formattedTokenValue:peak]] : L(@"Peak --");
|
|
228
213
|
NSString *todayText = todayTotals
|
|
229
214
|
? [NSString stringWithFormat:L(@"Today %@"),
|
|
230
215
|
[self formattedTokenValue:[todayTotals[@"total_tokens"] doubleValue]]] : L(@"Today --");
|
|
231
|
-
[
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
(unsigned long)recordedDays, (unsigned long)monthDaily.count]
|
|
239
|
-
drawInRect:NSMakeRect(trendX, NSMinY(card) + 22, 145, 18)
|
|
240
|
-
withAttributes:[self textAttributesWithSize:11 color:color weight:NSFontWeightMedium]];
|
|
216
|
+
[self drawText:todayText inRect:NSMakeRect(trendX, NSMinY(card) + 44, 145, 18)
|
|
217
|
+
size:11 weight:NSFontWeightRegular color:secondary dotColor:nil];
|
|
218
|
+
// 记录天数与左侧两列的月同比脚注保持相同基线和字号。
|
|
219
|
+
NSString *recordedText = [NSString stringWithFormat:L(@"%lu / %lu days recorded"),
|
|
220
|
+
(unsigned long)recordedDays, (unsigned long)monthDaily.count];
|
|
221
|
+
[self drawText:recordedText inRect:NSMakeRect(trendX, NSMinY(card) + 22, 145, 18)
|
|
222
|
+
size:11 weight:NSFontWeightMedium color:color dotColor:nil];
|
|
241
223
|
[NSGraphicsContext restoreGraphicsState];
|
|
242
224
|
return;
|
|
243
225
|
}
|
|
@@ -12,6 +12,60 @@ CGFloat QuotaLogicalHeightForProviderCount(NSUInteger count) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
// 各家图标的透明边距不同。加载时按不透明主体裁切,再放进相同的留白画布,
|
|
16
|
+
// 避免每次重绘扫描像素,也避免 ICNS 的阴影影响视觉尺寸。
|
|
17
|
+
static NSImage *NormalizedAgentIcon(NSImage *image) {
|
|
18
|
+
const size_t side = 256;
|
|
19
|
+
CGImageRef source = [image CGImageForProposedRect:NULL context:nil hints:nil];
|
|
20
|
+
if (!source) return image;
|
|
21
|
+
unsigned char *pixels = calloc(side * side, 4);
|
|
22
|
+
if (!pixels) return image;
|
|
23
|
+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
24
|
+
CGContextRef context = CGBitmapContextCreate(pixels, side, side, 8, side * 4,
|
|
25
|
+
colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
|
|
26
|
+
CGColorSpaceRelease(colorSpace);
|
|
27
|
+
if (!context) { free(pixels); return image; }
|
|
28
|
+
CGFloat width = CGImageGetWidth(source), height = CGImageGetHeight(source);
|
|
29
|
+
CGFloat scale = MIN(side / width, side / height);
|
|
30
|
+
CGContextDrawImage(context, CGRectMake((side - width * scale) / 2,
|
|
31
|
+
(side - height * scale) / 2, width * scale, height * scale), source);
|
|
32
|
+
size_t minX = side, minY = side, maxX = 0, maxY = 0;
|
|
33
|
+
for (size_t y = 0; y < side; y++) {
|
|
34
|
+
for (size_t x = 0; x < side; x++) {
|
|
35
|
+
if (pixels[(y * side + x) * 4 + 3] < 128) continue;
|
|
36
|
+
minX = MIN(minX, x); minY = MIN(minY, y);
|
|
37
|
+
maxX = MAX(maxX, x); maxY = MAX(maxY, y);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
CGImageRef raster = CGBitmapContextCreateImage(context);
|
|
41
|
+
CGContextRelease(context);
|
|
42
|
+
free(pixels);
|
|
43
|
+
if (!raster || minX == side) {
|
|
44
|
+
if (raster) CGImageRelease(raster);
|
|
45
|
+
return image;
|
|
46
|
+
}
|
|
47
|
+
CGImageRef cropped = CGImageCreateWithImageInRect(raster,
|
|
48
|
+
CGRectMake(minX, minY, maxX - minX + 1, maxY - minY + 1));
|
|
49
|
+
CGImageRelease(raster);
|
|
50
|
+
if (!cropped) return image;
|
|
51
|
+
NSSize size = NSMakeSize(CGImageGetWidth(cropped), CGImageGetHeight(cropped));
|
|
52
|
+
NSImage *content = [[NSImage alloc] initWithCGImage:cropped size:size];
|
|
53
|
+
CGImageRelease(cropped);
|
|
54
|
+
return [NSImage imageWithSize:NSMakeSize(side, side) flipped:NO drawingHandler:^BOOL(NSRect bounds) {
|
|
55
|
+
NSRect available = NSInsetRect(bounds, 16, 16);
|
|
56
|
+
CGFloat fit = MIN(NSWidth(available) / size.width, NSHeight(available) / size.height);
|
|
57
|
+
NSRect target = NSMakeRect(NSMidX(bounds) - size.width * fit / 2,
|
|
58
|
+
NSMidY(bounds) - size.height * fit / 2, size.width * fit, size.height * fit);
|
|
59
|
+
[NSGraphicsContext saveGraphicsState];
|
|
60
|
+
CGFloat radius = MIN(NSWidth(target), NSHeight(target)) * 18 / 70;
|
|
61
|
+
[[NSBezierPath bezierPathWithRoundedRect:target xRadius:radius yRadius:radius] addClip];
|
|
62
|
+
[content drawInRect:target fromRect:NSZeroRect operation:NSCompositingOperationSourceOver
|
|
63
|
+
fraction:1 respectFlipped:YES hints:@{NSImageHintInterpolation: @(NSImageInterpolationHigh)}];
|
|
64
|
+
[NSGraphicsContext restoreGraphicsState];
|
|
65
|
+
return YES;
|
|
66
|
+
}];
|
|
67
|
+
}
|
|
68
|
+
|
|
15
69
|
NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
16
70
|
NSURL *appURL = [NSWorkspace.sharedWorkspace URLForApplicationWithBundleIdentifier:bundleIdentifier];
|
|
17
71
|
NSMutableArray<NSString *> *paths = [NSMutableArray array];
|
|
@@ -28,9 +82,28 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
28
82
|
[applicationName stringByAppendingPathComponent:[@"Contents/Resources" stringByAppendingPathComponent:resourceName]]]];
|
|
29
83
|
for (NSString *path in paths) {
|
|
30
84
|
NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
|
|
31
|
-
if (image) return image;
|
|
85
|
+
if (image) return NormalizedAgentIcon(image);
|
|
32
86
|
}
|
|
33
|
-
|
|
87
|
+
if (appURL && [NSFileManager.defaultManager fileExistsAtPath:appURL.path]) {
|
|
88
|
+
NSImage *image = [NSWorkspace.sharedWorkspace iconForFile:appURL.path];
|
|
89
|
+
if (image) return NormalizedAgentIcon(image);
|
|
90
|
+
}
|
|
91
|
+
// 没装官方桌面端(例如只装 CLI)时,从发布包读取备用图标。
|
|
92
|
+
NSString *fallback = [bundleIdentifier isEqualToString:@"com.anthropic.claudefordesktop"]
|
|
93
|
+
? @"claude.png" : ([bundleIdentifier isEqualToString:@"com.openai.codex"] ? @"codex.icns" : nil);
|
|
94
|
+
if (!fallback) return nil;
|
|
95
|
+
NSArray<NSString *> *directories = @[
|
|
96
|
+
NSBundle.mainBundle.resourcePath ?: @"",
|
|
97
|
+
NSBundle.mainBundle.executablePath.stringByDeletingLastPathComponent ?: @""
|
|
98
|
+
];
|
|
99
|
+
for (NSString *directory in directories) {
|
|
100
|
+
if (directory.length == 0) continue;
|
|
101
|
+
NSString *path = [[directory stringByAppendingPathComponent:@"AgentIcons"]
|
|
102
|
+
stringByAppendingPathComponent:fallback];
|
|
103
|
+
NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
|
|
104
|
+
if (image) return NormalizedAgentIcon(image);
|
|
105
|
+
}
|
|
106
|
+
return nil;
|
|
34
107
|
}
|
|
35
108
|
|
|
36
109
|
|
|
@@ -206,6 +279,59 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
206
279
|
return NSZeroRect;
|
|
207
280
|
}
|
|
208
281
|
|
|
282
|
+
- (NSRect)logicalTrendRectForProvider:(NSString *)provider {
|
|
283
|
+
NSRect card = [self logicalCardRectForProvider:provider];
|
|
284
|
+
CGFloat contentOffset = (NSHeight(card) - QuotaBaseCardHeight) / 2;
|
|
285
|
+
return NSMakeRect(NSMinX(card) + 574, NSMinY(card) + contentOffset + 22, 145, 112);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
- (void)updateTrackingAreas {
|
|
289
|
+
[super updateTrackingAreas];
|
|
290
|
+
[self removeAllToolTips];
|
|
291
|
+
for (NSString *provider in [self visibleProviders]) {
|
|
292
|
+
NSRect rect = [self logicalTrendRectForProvider:provider];
|
|
293
|
+
rect.origin.x *= QuotaScale;
|
|
294
|
+
rect.origin.y *= QuotaScale;
|
|
295
|
+
rect.size.width *= QuotaScale;
|
|
296
|
+
rect.size.height *= QuotaScale;
|
|
297
|
+
[self addToolTipRect:rect owner:self userData:NULL];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag
|
|
302
|
+
point:(NSPoint)point userData:(void *)data {
|
|
303
|
+
// 在显示时读取当前账号,轮播或刷新数据后不会留下上一账号的统计。
|
|
304
|
+
if (self.animatingCarouselProvider.length > 0) return nil;
|
|
305
|
+
NSPoint logicalPoint = NSMakePoint(point.x / QuotaScale, point.y / QuotaScale);
|
|
306
|
+
for (NSString *provider in [self visibleProviders]) {
|
|
307
|
+
if (!NSPointInRect(logicalPoint, [self logicalTrendRectForProvider:provider])) continue;
|
|
308
|
+
NSDictionary *usage = [self usageForProvider:provider];
|
|
309
|
+
NSDictionary *state = [self accountStateForProvider:provider
|
|
310
|
+
profile:[self selectedProfileForProvider:provider] usage:usage];
|
|
311
|
+
if (![state[@"apiMode"] boolValue]) return nil;
|
|
312
|
+
NSDictionary *tokenUsage = [usage[@"tokenUsage"] isKindOfClass:NSDictionary.class]
|
|
313
|
+
? usage[@"tokenUsage"] : nil;
|
|
314
|
+
NSArray<NSDictionary *> *days = [tokenUsage[@"monthDaily"] isKindOfClass:NSArray.class]
|
|
315
|
+
? tokenUsage[@"monthDaily"] : @[];
|
|
316
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
317
|
+
NSUInteger recordedDays = 0;
|
|
318
|
+
double peak = 0;
|
|
319
|
+
for (NSDictionary *day in days) {
|
|
320
|
+
if ([day[@"timestamp"] doubleValue] > now) continue;
|
|
321
|
+
NSDictionary *totals = [day[@"totals"] isKindOfClass:NSDictionary.class]
|
|
322
|
+
? day[@"totals"] : nil;
|
|
323
|
+
peak = fmax(peak, [totals[@"total_tokens"] doubleValue]);
|
|
324
|
+
recordedDays += 1;
|
|
325
|
+
}
|
|
326
|
+
NSString *peakText = recordedDays > 0
|
|
327
|
+
? [NSString stringWithFormat:L(@"Peak %@"), [self formattedTokenValue:peak]] : L(@"Peak --");
|
|
328
|
+
NSString *recordedText = [NSString stringWithFormat:L(@"%lu / %lu days recorded"),
|
|
329
|
+
(unsigned long)recordedDays, (unsigned long)days.count];
|
|
330
|
+
return [NSString stringWithFormat:@"%@\n%@\n%@", L(@"Daily tokens"), peakText, recordedText];
|
|
331
|
+
}
|
|
332
|
+
return nil;
|
|
333
|
+
}
|
|
334
|
+
|
|
209
335
|
- (NSString *)providerAtEvent:(NSEvent *)event includeArrowGutters:(BOOL)includeArrowGutters
|
|
210
336
|
logicalPoint:(NSPoint *)outPoint {
|
|
211
337
|
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -8,9 +8,13 @@ is unrelated to any existing anime, game, or commercial mascot and is distribute
|
|
|
8
8
|
with the project code under the MIT License.
|
|
9
9
|
|
|
10
10
|
At runtime, the app may read locally installed Codex/ChatGPT and Claude application
|
|
11
|
-
icons for interface identification.
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
icons for interface identification. If unavailable, it uses bundled fallback assets
|
|
12
|
+
in `Resources/AgentIcons`: `claude.png` from https://claude.ai/apple-touch-icon.png
|
|
13
|
+
and `codex.icns` from the locally installed ChatGPT.app resource `icon-chatgpt.icns`.
|
|
14
|
+
These assets retain their respective owners' copyrights and trademarks; they are
|
|
15
|
+
not original CC Pets artwork and are not covered by this project's MIT License.
|
|
16
|
+
Attribution does not grant redistribution permission or imply endorsement by
|
|
17
|
+
Anthropic or OpenAI. Distribution must comply with the rights holders' terms.
|
|
14
18
|
|
|
15
19
|
Assets installed by users from PetDex or other sources are managed by those users
|
|
16
20
|
and are not part of this project distribution. Follow the applicable author,
|
|
@@ -6,7 +6,11 @@ CC Pets 发布包不捆绑 PetDex 下载的角色素材。内置的 `ByteMochi.w
|
|
|
6
6
|
原创默认素材,与任何现有动漫、游戏或商业吉祥物无关,并与项目代码一同按 MIT License 分发。
|
|
7
7
|
|
|
8
8
|
程序会在运行时尝试读取用户本机已安装的 Codex/ChatGPT 和 Claude 应用图标,仅用于界面识别;
|
|
9
|
-
|
|
9
|
+
读取失败时使用 `Resources/AgentIcons` 中随包分发的备用素材:`claude.png` 来自
|
|
10
|
+
https://claude.ai/apple-touch-icon.png,`codex.icns` 来自本机 ChatGPT.app 的
|
|
11
|
+
`icon-chatgpt.icns` 资源。这些素材的商标和版权归各自权利人所有,不是 CC Pets 原创素材,
|
|
12
|
+
也不适用本项目的 MIT License。标注来源不代表获得再分发授权,也不代表 Anthropic 或
|
|
13
|
+
OpenAI 为本项目背书;分发时仍须遵守权利人的使用条款。
|
|
10
14
|
|
|
11
15
|
用户通过 PetDex 或其他来源安装的素材由用户自行管理,不属于本项目发布内容。使用和再分发
|
|
12
16
|
此类素材时,请遵守对应作者、平台和权利人的许可证及使用条款。
|
package/bin/claude-with-pet
CHANGED
package/bin/codex-with-pet
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-pets",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "A native macOS desktop pet for Codex CLI and Claude Code",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Sunnyshiny",
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"scripts",
|
|
35
35
|
"Resources/Info.plist",
|
|
36
36
|
"Resources/AppIcon.icns",
|
|
37
|
+
"Resources/AgentIcons",
|
|
38
|
+
"Resources/IDEPlugins",
|
|
39
|
+
"plugins/jetbrains",
|
|
40
|
+
"plugins/vscode",
|
|
37
41
|
"Resources/phrases.default.*.txt",
|
|
38
42
|
"Resources/*.lproj/*",
|
|
39
43
|
"Sources/CCPets",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# CC Pets Terminal for JetBrains IDEs
|
|
2
|
+
|
|
3
|
+
本地 macOS 插件,支持基于 IntelliJ 平台的 JetBrains IDE 2026.2 / 2026.3 的 **Reworked** 终端
|
|
4
|
+
(IntelliJ IDEA、PyCharm、WebStorm、GoLand、CLion、PhpStorm、RubyMine、Rider 等)。
|
|
5
|
+
Android Studio 的平台版本通常落后,需其基线达到 262 后才能安装。
|
|
6
|
+
Classic 终端、远程开发和分屏内子终端暂不作为支持范围。
|
|
7
|
+
|
|
8
|
+
## 安装
|
|
9
|
+
|
|
10
|
+
1. 在 Pet 的「设置 → 通用 → 终端跳转」找到对应 IDE,点「安装」并确认。
|
|
11
|
+
Pet 把随包 ZIP 解压到该 IDE 的插件目录 `<配置目录>/plugins/cc-pets-terminal`。
|
|
12
|
+
2. IDE 正在运行时该行显示「需要重启」,重启后加载。
|
|
13
|
+
3. 打开一个项目。Pet 会自动检测连接;无需填写端口或手动配对。
|
|
14
|
+
4. 在 Reworked 终端中启动 Agent 并触发新的 Hook 卡片,点击卡片跳转。
|
|
15
|
+
|
|
16
|
+
只在用户确认后写入,且只写 `cc-pets-terminal` 一个目录:先解压到同目录下的临时文件夹,
|
|
17
|
+
校验 jar 后再改名替换,失败时恢复旧版本。目标目录必须属于当前用户且不是符号链接;
|
|
18
|
+
IDE 从未启动过(配置目录不存在)或 `idea.properties` 自定义了 `idea.config.path` /
|
|
19
|
+
`idea.plugins.path` 时不自动安装,改为手动:Settings → Plugins → ⚙ → Install Plugin from Disk。
|
|
20
|
+
已连接过的 IDE 使用插件上报的真实插件目录。用户在 IDE 中禁用的插件保持禁用。
|
|
21
|
+
|
|
22
|
+
随 CC Pets 更新的 ZIP 版本更高时,该行显示「更新」,流程同安装。卸载或禁用通过 IDE 的
|
|
23
|
+
Plugins 设置完成。ZIP 尚未发布到 JetBrains Marketplace。
|
|
24
|
+
每个 IDE、稳定版和 EAP 的插件配置独立,需要分别安装。
|
|
25
|
+
|
|
26
|
+
## 工作方式
|
|
27
|
+
|
|
28
|
+
每个 IDE 进程注册独立的本机端点。新终端通过 `LocalTerminalCustomizer`
|
|
29
|
+
得到 `CC_PETS_IDE_INSTANCE_ID` 和 `CC_PETS_IDE_TERMINAL_ID`;Pet 的 Hook 记录保留
|
|
30
|
+
这两个值。插件按标识查找终端,范围包括终端工具窗口的标签页和「作为编辑器标签页打开」后
|
|
31
|
+
位于编辑器区(含拆出的独立窗口)的终端,再前置项目窗口、选择标签页并聚焦输入组件。
|
|
32
|
+
已打开的终端没有这些标识时,使用其启动 PID 的控制 TTY 精确匹配;不按标题或工作目录猜测。
|
|
33
|
+
若 PID 不可用、终端已关闭、匹配不唯一或 IDE 正显示模态对话框,返回失败并提示用户。
|
|
34
|
+
|
|
35
|
+
Codex 使用共享后台时,会话与终端的配对由 Pet 完成。多个客户端在同目录启动时,
|
|
36
|
+
Pet 参考本机 `logs_2.sqlite` 中 TUI 的就绪时刻与进程身份,避免网络初始化延迟导致串台。
|
|
37
|
+
它只查询启动元数据;该日志格式是 Codex 内部实现,缺失、变更或同时就绪造成歧义时
|
|
38
|
+
不会按“最近启动”猜测。显式 `codex resume <会话 ID>` 可直接按参数匹配。
|
|
39
|
+
|
|
40
|
+
注册文件位于 `~/Library/Application Support/CC Pets/ide-instances/`。
|
|
41
|
+
目录权限为 `0700`,文件为 `0600`,每个进程使用独立随机令牌。
|
|
42
|
+
通信仅监听 `127.0.0.1`,要求带 Bearer 令牌的 POST,并拒绝浏览器 Origin 请求。
|
|
43
|
+
仅提供状态查询和聚焦操作,不读取终端输出,不向终端输入命令。
|
|
44
|
+
Pet 不跟随重定向、不使用代理;过期注册通过进程路径和认证查询排除。
|
|
45
|
+
正常卸载/退出会清除注册,异常退出留下的文件不会被视为有效连接。
|
|
46
|
+
|
|
47
|
+
## 构建
|
|
48
|
+
|
|
49
|
+
使用 zsh、macOS 自带的 XML/ZIP 工具,以及已安装 IDEA 自带的 Java 25 编译模块,
|
|
50
|
+
无需 Python、Gradle 或下载依赖:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
./scripts/build-idea-plugin.sh --ide '/Applications/IntelliJ IDEA.app'
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
输出为 `Resources/IDEPlugins/cc-pets-terminal.zip`,随 npm 包及 Pet 应用一起分发。
|
|
57
|
+
普通用户安装 Pet 时不需要 JDK;修改插件源码后,开发者需要重新生成此 ZIP。
|
|
58
|
+
可通过 `--output` 指定临时输出,例如检查另一个 IDEA SDK 的编译兼容性。
|
|
59
|
+
发布插件时同时更新 `plugin.xml` 和桥接状态中的版本号。
|
|
60
|
+
|
|
61
|
+
已在 IntelliJ IDEA 2026.2.3 和 2026.3 EAP 中完成 SDK 编译、静态检查,以及插件安装和
|
|
62
|
+
卡片跳转的人工验收。该项目默认不执行自动化测试。
|