cc-pets 1.4.8 → 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 +41 -280
- 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 +221 -526
- 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 +2 -11
- package/Sources/CCPets/CCPetsCodexRateLimits.h +13 -0
- package/Sources/CCPets/CCPetsCodexRateLimits.m +383 -0
- package/Sources/CCPets/CCPetsPhrases.h +3 -26
- package/Sources/CCPets/CCPetsPhrases.m +4 -85
- package/Sources/CCPets/CCPetsPhrasesEditor.m +22 -50
- 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/build.sh +1 -1
- package/scripts/install-git-hooks.sh +2 -3
- package/scripts/pet-store.mjs +21 -2
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
|
+
此类素材时,请遵守对应作者、平台和权利人的许可证及使用条款。
|
package/package.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-pets",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A native macOS desktop pet for Codex CLI and Claude Code",
|
|
5
|
-
"author":
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Sunnyshiny",
|
|
7
|
+
"url": "https://github.com/Sunnyshinnny776"
|
|
8
|
+
},
|
|
6
9
|
"license": "MIT",
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
|
-
"url": "git+https://
|
|
12
|
+
"url": "git+https://github.com/Sunnyshinnny776/cc-pets.git"
|
|
10
13
|
},
|
|
11
|
-
"homepage": "https://
|
|
14
|
+
"homepage": "https://github.com/Sunnyshinnny776/cc-pets",
|
|
12
15
|
"bugs": {
|
|
13
|
-
"url": "https://
|
|
16
|
+
"url": "https://github.com/Sunnyshinnny776/cc-pets/issues"
|
|
14
17
|
},
|
|
15
18
|
"keywords": [
|
|
16
19
|
"codex",
|
|
@@ -34,11 +37,17 @@
|
|
|
34
37
|
"Resources/phrases.default.txt",
|
|
35
38
|
"Sources/CCPets",
|
|
36
39
|
"README.md",
|
|
40
|
+
"README.zh-CN.md",
|
|
37
41
|
"PROVIDER_PROTOCOL.md",
|
|
42
|
+
"PROVIDER_PROTOCOL.zh-CN.md",
|
|
38
43
|
"CHANGELOG.md",
|
|
44
|
+
"CHANGELOG.zh-CN.md",
|
|
39
45
|
"CONTRIBUTING.md",
|
|
46
|
+
"CONTRIBUTING.zh-CN.md",
|
|
40
47
|
"SECURITY.md",
|
|
48
|
+
"SECURITY.zh-CN.md",
|
|
41
49
|
"THIRD_PARTY_NOTICES.md",
|
|
50
|
+
"THIRD_PARTY_NOTICES.zh-CN.md",
|
|
42
51
|
"LICENSE"
|
|
43
52
|
],
|
|
44
53
|
"bin": {
|
package/scripts/build.sh
CHANGED
|
@@ -51,7 +51,7 @@ if (( ${#SPRITES[@]} > 0 )); then
|
|
|
51
51
|
cp "${SPRITES[@]}" "${BUILD_DIR}/"
|
|
52
52
|
cp "${SPRITES[@]}" "${APP_RESOURCES_DIR}/"
|
|
53
53
|
fi
|
|
54
|
-
#
|
|
54
|
+
# 默认台词。代码里不再留内置词库,这个文件就是默认台词的唯一来源,
|
|
55
55
|
# 首次启动时被拷到 ~/.cc-pets/phrases.txt。
|
|
56
56
|
# 裸二进制旁边也放一份:直接跑 .build/release/cc-pets 时没有 app bundle。
|
|
57
57
|
cp "${PROJECT_DIR}/Resources/phrases.default.txt" "${APP_RESOURCES_DIR}/phrases.default.txt"
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
#!/bin/zsh
|
|
2
2
|
set -eu
|
|
3
3
|
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# 起作用的"CI":推送前强制跑一遍 npm test。
|
|
4
|
+
# GitHub Actions 已经在 macOS runner 上跑完整测试,本地 pre-push 钩子是它的前哨:
|
|
5
|
+
# 推送前先在本机强制跑一遍 npm test,避免把编译不过的提交推上去。
|
|
7
6
|
#
|
|
8
7
|
# 用法:./scripts/install-git-hooks.sh
|
|
9
8
|
# 跳过单次检查:git push --no-verify
|
package/scripts/pet-store.mjs
CHANGED
|
@@ -25,6 +25,20 @@ const SOURCES = {
|
|
|
25
25
|
homepage: "https://petdex.dev"
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
+
// 请求素材源时自报家门:对方运维从日志里能看出流量来自 CC Pets 而不是一串默认 UA,
|
|
29
|
+
// 想联系或限流都有个明确的对象。版本号跟着 package.json 走,不另外维护一份。
|
|
30
|
+
const USER_AGENT = (() => {
|
|
31
|
+
let version = "0.0.0";
|
|
32
|
+
try {
|
|
33
|
+
version = JSON.parse(
|
|
34
|
+
fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")
|
|
35
|
+
).version;
|
|
36
|
+
} catch {
|
|
37
|
+
// 版本读不到不该让下载失败,退回占位版本号即可。
|
|
38
|
+
}
|
|
39
|
+
return `cc-pets/${version} (+https://github.com/Sunnyshinnny776/cc-pets)`;
|
|
40
|
+
})();
|
|
41
|
+
|
|
28
42
|
// 不能 add、只会出现在已装素材里的来源。桌宠的"导入 Codex 素材"开关会写 source: "codex"。
|
|
29
43
|
const LOCAL_SOURCE_LABELS = { codex: "Codex(导入)" };
|
|
30
44
|
const DEFAULT_SOURCE = process.env.CC_PETS_SOURCE || "petdex";
|
|
@@ -89,7 +103,10 @@ async function fetchManifest(sourceName, { refresh }) {
|
|
|
89
103
|
// 缓存缺失或损坏都当作没有缓存,直接回源。
|
|
90
104
|
}
|
|
91
105
|
}
|
|
92
|
-
const response = await fetch(manifestUrlFor(sourceName), {
|
|
106
|
+
const response = await fetch(manifestUrlFor(sourceName), {
|
|
107
|
+
redirect: "follow",
|
|
108
|
+
headers: { "User-Agent": USER_AGENT }
|
|
109
|
+
});
|
|
93
110
|
if (!response.ok) fail(`拉取 ${SOURCES[sourceName].label} 素材清单失败: HTTP ${response.status}`);
|
|
94
111
|
const body = await response.json();
|
|
95
112
|
if (!Array.isArray(body?.pets)) fail(`${SOURCES[sourceName].label} 素材清单格式不符合预期`);
|
|
@@ -108,7 +125,9 @@ async function download(url, source) {
|
|
|
108
125
|
if (parsed.protocol !== "https:" || !source.assetHosts.includes(parsed.hostname)) {
|
|
109
126
|
throw new Error(`不受信任的素材来源: ${parsed.hostname || url}`);
|
|
110
127
|
}
|
|
111
|
-
const response = await fetch(parsed, {
|
|
128
|
+
const response = await fetch(parsed, {
|
|
129
|
+
headers: { Referer: source.referer, "User-Agent": USER_AGENT }
|
|
130
|
+
});
|
|
112
131
|
if (!response.ok) throw new Error(`下载失败 ${parsed.pathname} -> HTTP ${response.status}`);
|
|
113
132
|
return Buffer.from(await response.arrayBuffer());
|
|
114
133
|
}
|