cc-pets 1.0.6 → 1.0.8
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 +10 -0
- package/README.md +11 -2
- package/Sources/CCPets/CCPetsAppDelegate.m +35 -6
- package/Sources/CCPets/CCPetsPaths.h +6 -0
- package/Sources/CCPets/CCPetsPaths.m +45 -2
- package/Sources/CCPets/CCPetsPreviews.m +1 -1
- package/Sources/CCPets/CCPetsUsage.m +9 -4
- package/Sources/CCPets/CCPetsUsageMonitor.m +3 -2
- package/Sources/CCPets/CCPetsVersion.h +3 -0
- package/Sources/CCPets/CCPetsVersion.m +20 -0
- package/bin/cc-pets +3 -1
- package/bin/claude-with-pet +3 -1
- package/bin/codex-with-pet +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,16 @@
|
|
|
10
10
|
- Token 聚合改为增量跟读并按额度窗口节流,事件驱动的高频刷新不再重复扫描近 7 天会话;
|
|
11
11
|
过期日期目录按目录名剪枝,无 Token 数据的会话文件缓存失败结果不再反复重读。
|
|
12
12
|
- 新开 Codex 会话时不再因为尚无 `rate_limits` 而清空面板上已知的额度。
|
|
13
|
+
- 修复存在多个 Claude 配置目录时统计错账号:桌宠是被客户端启动的常驻进程,会一直带着
|
|
14
|
+
启动时的 `CLAUDE_CONFIG_DIR`,等于永久绑定到"第一个拉起它的账号"。现固定只统计
|
|
15
|
+
`~/.claude`(可用 `CC_PETS_CLAUDE_CONFIG_DIR` 覆盖),包装脚本启动桌宠时也不再透传该
|
|
16
|
+
变量。额度文件改为按配置目录分开存放,多个配置目录的 status line 不再互相覆盖——此前
|
|
17
|
+
面板可能把一个账号的剩余百分比配上另一个账号的用量。
|
|
18
|
+
- 应用内更新遇到暂时性故障时自动重试一次,不再直接弹"更新失败"。刚发布的版本存在
|
|
19
|
+
registry 传播竞态:`/latest` 已经报出新版本,而同一时刻 `npm install cc-pets@<新版本>`
|
|
20
|
+
解析到的包元数据可能还是旧的并报 `ETARGET`。重试改用一次性缓存目录强制冷取
|
|
21
|
+
(`--prefer-online` 命中 304 时仍会拿到旧元数据),不影响用户真正的 npm 缓存。
|
|
22
|
+
权限、磁盘、脚本失败等真实故障不重试,照常上报。
|
|
13
23
|
- 修复状态气泡在任务完成后被打回"正在思考":`Stop` 之后仍会飘来 `SubagentStop` /
|
|
14
24
|
`PostToolUse` 等尾巴事件,它们与 `UserPromptSubmit` 归一成同一个状态,现按事件名拦截,
|
|
15
25
|
终态只能被新一轮真实动作解除。
|
package/README.md
CHANGED
|
@@ -252,8 +252,7 @@ Claude 用量来自官方 status line 输入中的 `rate_limits.five_hour` 与
|
|
|
252
252
|
`rate_limits.seven_day`。其中的 `used_percentage` 会换算为剩余百分比。该字段仅面向
|
|
253
253
|
Claude.ai Pro/Max 订阅账号,并在会话完成首次 API 响应后出现;字段尚不可用时显示 `--`。
|
|
254
254
|
|
|
255
|
-
Claude Code 本地 Token 来自 `~/.claude/projects`
|
|
256
|
-
影响):
|
|
255
|
+
Claude Code 本地 Token 来自 `~/.claude/projects` 下的会话转录:
|
|
257
256
|
|
|
258
257
|
- 每条 `type = assistant` 的记录带 `message.usage`,是**单次请求的增量**,与 Codex 的
|
|
259
258
|
会话累计值不同,因此按时间戳逐条落窗口累加
|
|
@@ -264,6 +263,16 @@ Claude Code 本地 Token 来自 `~/.claude/projects` 下的会话转录(受 `C
|
|
|
264
263
|
- 统计包含输入、缓存读取、缓存写入、输出与总量;Claude 的思考 token 已计入
|
|
265
264
|
`output_tokens`,不单列推理项
|
|
266
265
|
|
|
266
|
+
Claude Code 支持用 `CLAUDE_CONFIG_DIR` 把配置目录指到别处,同一台机器因此可能存在多个
|
|
267
|
+
配置目录(不同账号、各自独立的额度周期)。桌宠**固定只统计 `~/.claude`**,不读
|
|
268
|
+
`CLAUDE_CONFIG_DIR`:桌宠是被某个客户端启动的常驻进程,会一直带着启动时的环境,用它选
|
|
269
|
+
目录等于永久绑定到"第一个拉起桌宠的账号"。确实把配置目录整体搬走的用户可以设
|
|
270
|
+
`CC_PETS_CLAUDE_CONFIG_DIR`(与 `CC_PETS_STATE_DIR` 等覆盖变量同一套约定),正常使用下
|
|
271
|
+
不需要设置。
|
|
272
|
+
|
|
273
|
+
额度文件按配置目录分开存放,因此多个配置目录的 status line 不会互相覆盖——否则面板会
|
|
274
|
+
把一个账号的剩余百分比配上另一个账号的用量。
|
|
275
|
+
|
|
267
276
|
本地 Token 是 CLI 会话事件的原始计数,不等同于订阅额度。官方额度可能受模型、缓存和
|
|
268
277
|
请求复杂度等因素影响,应始终以服务端返回的百分比为准。
|
|
269
278
|
|
|
@@ -84,6 +84,13 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
84
84
|
}
|
|
85
85
|
- (void)startUpdateToVersion:(NSString *)version {
|
|
86
86
|
if (self.updating) return;
|
|
87
|
+
[self startUpdateToVersion:version attempt:0];
|
|
88
|
+
}
|
|
89
|
+
- (void)retryUpdate:(NSArray *)context {
|
|
90
|
+
self.updating = NO;
|
|
91
|
+
[self startUpdateToVersion:context[0] attempt:[context[1] integerValue]];
|
|
92
|
+
}
|
|
93
|
+
- (void)startUpdateToVersion:(NSString *)version attempt:(NSInteger)attempt {
|
|
87
94
|
NSDictionary *configuration = [self updaterConfiguration];
|
|
88
95
|
NSString *nodePath = [configuration[@"nodePath"] isKindOfClass:NSString.class]
|
|
89
96
|
? [configuration[@"nodePath"] stringByStandardizingPath] : nil;
|
|
@@ -119,14 +126,22 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
119
126
|
|
|
120
127
|
NSTask *task = [NSTask new];
|
|
121
128
|
task.executableURL = [NSURL fileURLWithPath:nodePath];
|
|
122
|
-
|
|
129
|
+
NSMutableArray<NSString *> *arguments = [@[
|
|
123
130
|
npmCliPath,
|
|
124
131
|
@"install",
|
|
125
132
|
@"--global",
|
|
126
133
|
[@"cc-pets@" stringByAppendingString:version],
|
|
127
134
|
@"--allow-scripts=cc-pets",
|
|
128
135
|
@"--prefer-online"
|
|
129
|
-
];
|
|
136
|
+
] mutableCopy];
|
|
137
|
+
if (attempt > 0) {
|
|
138
|
+
// 重试走一个一次性缓存目录:ETARGET 的成因就是本机缓存里的包元数据还没有这个
|
|
139
|
+
// 版本,--prefer-online 只是允许重新校验,命中 304 时依然拿到旧元数据。
|
|
140
|
+
// 换缓存目录能强制冷取,又不动用户真正的 npm 缓存。
|
|
141
|
+
[arguments addObjectsFromArray:@[@"--cache",
|
|
142
|
+
[supportDirectory stringByAppendingPathComponent:@"update-retry-cache"]]];
|
|
143
|
+
}
|
|
144
|
+
task.arguments = arguments;
|
|
130
145
|
NSMutableDictionary<NSString *, NSString *> *environment =
|
|
131
146
|
[NSProcessInfo.processInfo.environment mutableCopy];
|
|
132
147
|
NSString *nodeDirectory = nodePath.stringByDeletingLastPathComponent;
|
|
@@ -146,14 +161,25 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
146
161
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
147
162
|
typeof(self) strongSelf = weakSelf;
|
|
148
163
|
if (!strongSelf) return;
|
|
149
|
-
strongSelf.updating = NO;
|
|
150
164
|
strongSelf.updateTask = nil;
|
|
151
165
|
if (finishedTask.terminationStatus == EXIT_SUCCESS) {
|
|
166
|
+
strongSelf.updating = NO;
|
|
152
167
|
if ([strongSelf restartAfterUpdateToVersion:version configuration:configuration]) return;
|
|
153
168
|
[strongSelf showUpdateAlertWithTitle:@"更新完成"
|
|
154
169
|
message:@"CC Pets 已更新,但没有找到可自动启动的新版应用,请手动重新启动一次。"];
|
|
155
170
|
return;
|
|
156
171
|
}
|
|
172
|
+
// 暂时性故障(典型是刚发布的版本报 ETARGET)自动重试一次再说,
|
|
173
|
+
// 别把一个重试就能过的问题弹成"更新失败"。updating 保持为 YES,
|
|
174
|
+
// 等待期间不接受新的更新请求。
|
|
175
|
+
NSString *log = [NSString stringWithContentsOfFile:logPath
|
|
176
|
+
encoding:NSUTF8StringEncoding error:nil];
|
|
177
|
+
if (attempt == 0 && UpdateFailureIsTransient(log)) {
|
|
178
|
+
[strongSelf performSelector:@selector(retryUpdate:)
|
|
179
|
+
withObject:@[version, @1] afterDelay:UpdateRetryDelay];
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
strongSelf.updating = NO;
|
|
157
183
|
[NSApp activateIgnoringOtherApps:YES];
|
|
158
184
|
NSAlert *alert = [NSAlert new];
|
|
159
185
|
alert.messageText = @"更新失败";
|
|
@@ -174,8 +200,11 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
174
200
|
[self showUpdateAlertWithTitle:@"无法启动更新" message:launchError.localizedDescription];
|
|
175
201
|
return;
|
|
176
202
|
}
|
|
177
|
-
|
|
178
|
-
|
|
203
|
+
// 重试是静默的:第一次已经弹过"正在更新",再弹一次只会让人以为出了两回事。
|
|
204
|
+
if (attempt == 0) {
|
|
205
|
+
[self showUpdateAlertWithTitle:@"正在更新"
|
|
206
|
+
message:[NSString stringWithFormat:@"正在下载并安装 CC Pets %@。完成后桌宠会自动重启。", version]];
|
|
207
|
+
}
|
|
179
208
|
}
|
|
180
209
|
- (void)checkForUpdates:(id)sender {
|
|
181
210
|
if (self.checkingForUpdate || self.updating) return;
|
|
@@ -331,7 +360,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
331
360
|
if ([state isEqualToString:@"tool"]) return @"正在调用工具…";
|
|
332
361
|
if ([state isEqualToString:@"tool_completed"]) return @"工具调用已完成。";
|
|
333
362
|
if ([state isEqualToString:@"tool_failed"]) return @"工具执行失败,请查看终端。";
|
|
334
|
-
if ([state isEqualToString:@"completed"]) return @"
|
|
363
|
+
if ([state isEqualToString:@"completed"]) return @"当前任务已经完成。";
|
|
335
364
|
if ([state isEqualToString:@"failed"]) return @"任务失败,请回到终端查看详情。";
|
|
336
365
|
if ([state isEqualToString:@"notification"]) return @"有一条状态需要你关注。";
|
|
337
366
|
return @"正在处理当前任务。";
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
// 状态文件与配置目录。所有路径都可以通过环境变量覆盖,测试依赖这一点做隔离。
|
|
4
4
|
NSString *PetStateDirectory(void);
|
|
5
5
|
NSString *AgentEventPath(void);
|
|
6
|
+
// 记录端用:解析当前会话的 CLAUDE_CONFIG_DIR。
|
|
6
7
|
NSString *ClaudeUsagePath(void);
|
|
8
|
+
// 桌宠端用:只看主账号,不受继承来的 CLAUDE_CONFIG_DIR 影响。
|
|
9
|
+
NSString *DefaultClaudeConfigDirectory(void);
|
|
10
|
+
NSString *CurrentClaudeConfigDirectory(void);
|
|
11
|
+
NSString *ClaudeUsagePathForConfigDirectory(NSString *configDirectory);
|
|
7
12
|
NSString *ApplicationSupportDirectory(void);
|
|
8
13
|
NSString *QuotaHistoryPath(void);
|
|
9
14
|
|
|
@@ -17,6 +22,7 @@ extern NSString *const StatusBubblePreferenceV2Key;
|
|
|
17
22
|
extern const NSTimeInterval AgentStatusInactivityInterval;
|
|
18
23
|
extern const NSTimeInterval AgentStatusOrphanInterval;
|
|
19
24
|
extern const NSTimeInterval AgentStartingGraceInterval;
|
|
25
|
+
extern const NSTimeInterval UpdateRetryDelay;
|
|
20
26
|
extern const NSTimeInterval UsageRefreshIntervalVisible;
|
|
21
27
|
extern const NSTimeInterval UsageRefreshIntervalHidden;
|
|
22
28
|
extern const NSTimeInterval ClientLifecycleInterval;
|
|
@@ -11,11 +11,52 @@ NSString *AgentEventPath(void) {
|
|
|
11
11
|
return [PetStateDirectory() stringByAppendingPathComponent:name];
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// 桌宠只认这一个配置目录。刻意不用 CLAUDE_CONFIG_DIR:那是会话级的,桌宠作为常驻进程
|
|
15
|
+
// 会把拉起它的那个客户端的值一直带着。真的把配置目录搬过家的人可以设 CC_PETS_CLAUDE_
|
|
16
|
+
// CONFIG_DIR——正常使用下没有任何东西会设它,所以不存在被意外继承的问题。
|
|
17
|
+
NSString *DefaultClaudeConfigDirectory(void) {
|
|
18
|
+
NSString *override = NSProcessInfo.processInfo.environment[@"CC_PETS_CLAUDE_CONFIG_DIR"];
|
|
19
|
+
if (override.length > 0) return override.stringByStandardizingPath;
|
|
20
|
+
return [NSHomeDirectory() stringByAppendingPathComponent:@".claude"];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 记录端(statusline / hook)跑在 CLI 会话里,CLAUDE_CONFIG_DIR 指向那一次会话真正
|
|
24
|
+
// 使用的配置目录。桌宠端不能用它:桌宠是被某个客户端 open 起来的常驻进程,会把当时的
|
|
25
|
+
// 环境变量一直带着,等于永久绑定到"第一个拉起它的账号"。
|
|
26
|
+
NSString *CurrentClaudeConfigDirectory(void) {
|
|
27
|
+
NSString *override = NSProcessInfo.processInfo.environment[@"CLAUDE_CONFIG_DIR"];
|
|
28
|
+
if (override.length > 0) return override.stringByStandardizingPath;
|
|
29
|
+
return DefaultClaudeConfigDirectory();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 额度是按账号的。一台机器上可以有多个配置目录(例如 ~/.claude 和 ~/.claude-nw),
|
|
33
|
+
// 各自是不同账号、不同额度周期。共用一个文件的话两边的 statusline 会互相覆盖,
|
|
34
|
+
// 面板就会把 A 账号的剩余百分比配上 B 账号的用量。因此按配置目录分文件。
|
|
35
|
+
NSString *ClaudeUsagePathForConfigDirectory(NSString *configDirectory) {
|
|
36
|
+
NSString *suffix = @"";
|
|
37
|
+
NSString *resolved = configDirectory.stringByStandardizingPath;
|
|
38
|
+
if (resolved.length > 0 &&
|
|
39
|
+
![resolved isEqualToString:DefaultClaudeConfigDirectory().stringByStandardizingPath]) {
|
|
40
|
+
NSCharacterSet *allowed = [NSCharacterSet characterSetWithCharactersInString:
|
|
41
|
+
@"abcdefghijklmnopqrstuvwxyz0123456789-"];
|
|
42
|
+
NSMutableString *name = [NSMutableString string];
|
|
43
|
+
for (NSString *unit in @[resolved.lastPathComponent.lowercaseString]) {
|
|
44
|
+
for (NSUInteger index = 0; index < unit.length && name.length < 24; index++) {
|
|
45
|
+
unichar character = [unit characterAtIndex:index];
|
|
46
|
+
if ([allowed characterIsMember:character]) [name appendFormat:@"%C", character];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
suffix = name.length > 0 ? [@"-" stringByAppendingString:name] : @"-alt";
|
|
50
|
+
}
|
|
51
|
+
NSString *name = [NSString stringWithFormat:@"cc-pets-%u-claude-usage%@.json",
|
|
52
|
+
getuid(), suffix];
|
|
16
53
|
return [PetStateDirectory() stringByAppendingPathComponent:name];
|
|
17
54
|
}
|
|
18
55
|
|
|
56
|
+
NSString *ClaudeUsagePath(void) {
|
|
57
|
+
return ClaudeUsagePathForConfigDirectory(CurrentClaudeConfigDirectory());
|
|
58
|
+
}
|
|
59
|
+
|
|
19
60
|
NSString *ApplicationSupportDirectory(void) {
|
|
20
61
|
NSString *override = NSProcessInfo.processInfo.environment[@"CC_PETS_APPLICATION_SUPPORT_DIR"];
|
|
21
62
|
if (override.length > 0) return override.stringByStandardizingPath;
|
|
@@ -41,6 +82,8 @@ const NSTimeInterval AgentStatusOrphanInterval = 10.0;
|
|
|
41
82
|
// "正在启动"只在会话拉起的一瞬间成立。超过这段还没有任何后续事件,说明会话已经就绪、
|
|
42
83
|
// 正在等用户输入,气泡应当落到"待机中",否则启动态和空闲态看起来完全一样。
|
|
43
84
|
const NSTimeInterval AgentStartingGraceInterval = 8.0;
|
|
85
|
+
// 刚发布的版本存在 registry 传播竞态,更新失败后等这么久再自动重试一次。
|
|
86
|
+
const NSTimeInterval UpdateRetryDelay = 5.0;
|
|
44
87
|
// 额度变化由 FSEvents/VNODE 主动推送;定时器只保留为监听不可用时的 120 秒兜底。
|
|
45
88
|
// 打开面板和手动刷新仍会立即读取一次。
|
|
46
89
|
const NSTimeInterval UsageRefreshIntervalVisible = 120.0;
|
|
@@ -102,7 +102,7 @@ int RenderAgentStatusCard(NSString *path) {
|
|
|
102
102
|
title.font = [NSFont systemFontOfSize:13 weight:NSFontWeightSemibold];
|
|
103
103
|
title.textColor = [NSColor colorWithWhite:0.10 alpha:0.96];
|
|
104
104
|
[glass addSubview:title];
|
|
105
|
-
NSTextField *detail = [NSTextField labelWithString:@"
|
|
105
|
+
NSTextField *detail = [NSTextField labelWithString:@"当前任务已经完成。"];
|
|
106
106
|
detail.frame = NSMakeRect(20, 12, glassSize.width - 80, 17);
|
|
107
107
|
detail.font = [NSFont systemFontOfSize:12 weight:NSFontWeightRegular];
|
|
108
108
|
detail.textColor = [NSColor colorWithWhite:0.34 alpha:0.88];
|
|
@@ -16,7 +16,10 @@ int RecordClaudeUsage(void) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
NSDictionary *ClaudeRateLimits(void) {
|
|
19
|
-
|
|
19
|
+
// 只读主账号那一份。桌宠继承的 CLAUDE_CONFIG_DIR 属于"第一个拉起它的客户端",
|
|
20
|
+
// 拿它选文件会让面板显示另一个账号的额度。
|
|
21
|
+
NSData *data = [NSData dataWithContentsOfFile:
|
|
22
|
+
ClaudeUsagePathForConfigDirectory(DefaultClaudeConfigDirectory())];
|
|
20
23
|
NSDictionary *limits = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
21
24
|
if (![limits isKindOfClass:NSDictionary.class]) return nil;
|
|
22
25
|
id fiveHour = [limits[@"five_hour"] isKindOfClass:NSDictionary.class] ? limits[@"five_hour"] : NSNull.null;
|
|
@@ -775,10 +778,12 @@ static BOOL ClaudeRecordFromLine(NSData *lineData, ClaudeTokenRecord *record) {
|
|
|
775
778
|
return YES;
|
|
776
779
|
}
|
|
777
780
|
|
|
781
|
+
// 桌宠只统计主账号 ~/.claude。刻意不读 CLAUDE_CONFIG_DIR:桌宠是被某个客户端 open
|
|
782
|
+
// 起来的常驻进程,会一直带着当时的环境变量。用 claude-nw 启动过一次,桌宠就会永久
|
|
783
|
+
// 只统计那个账号,主账号的用量一条都进不来——实测差了 26 倍(156.8M vs 5.96M)。
|
|
778
784
|
static NSURL *ClaudeProjectsURL(void) {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
return [NSURL fileURLWithPath:[home stringByAppendingPathComponent:@"projects"]];
|
|
785
|
+
return [NSURL fileURLWithPath:
|
|
786
|
+
[DefaultClaudeConfigDirectory() stringByAppendingPathComponent:@"projects"]];
|
|
782
787
|
}
|
|
783
788
|
|
|
784
789
|
// 只看 mtime 落在窗口内的转录文件。本机 76 个文件里近 7 天只有 44 个,目录遍历约 3ms。
|
|
@@ -64,7 +64,7 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
64
64
|
// changed=YES 表示额度文件确实变了(VNODE 事件),跳过 stat 比较;
|
|
65
65
|
// aggregate=YES 表示这是手动刷新/面板打开/兜底轮询,Token 聚合要绕过节流立即重算。
|
|
66
66
|
- (NSDictionary *)readClaudeUsageChanged:(BOOL)changed forcingAggregation:(BOOL)aggregate {
|
|
67
|
-
NSString *path =
|
|
67
|
+
NSString *path = ClaudeUsagePathForConfigDirectory(DefaultClaudeConfigDirectory());
|
|
68
68
|
NSDictionary *attributes = [NSFileManager.defaultManager attributesOfItemAtPath:path error:nil];
|
|
69
69
|
unsigned long long size = [attributes[NSFileSize] unsignedLongLongValue];
|
|
70
70
|
NSTimeInterval modifiedAt = [attributes[NSFileModificationDate] timeIntervalSince1970];
|
|
@@ -98,7 +98,8 @@ static void CodexEventsCallback(ConstFSEventStreamRef streamRef,
|
|
|
98
98
|
}
|
|
99
99
|
- (void)startClaudeSource {
|
|
100
100
|
if (self.claudeSource || !self.started) return;
|
|
101
|
-
|
|
101
|
+
// 只监听主账号那一份;其他配置目录写的是各自的文件。
|
|
102
|
+
NSString *path = ClaudeUsagePathForConfigDirectory(DefaultClaudeConfigDirectory());
|
|
102
103
|
[NSFileManager.defaultManager createDirectoryAtPath:path.stringByDeletingLastPathComponent
|
|
103
104
|
withIntermediateDirectories:YES attributes:nil error:nil];
|
|
104
105
|
if (![NSFileManager.defaultManager fileExistsAtPath:path]) {
|
|
@@ -8,3 +8,6 @@
|
|
|
8
8
|
// 自动更新会把比较结果作为是否升级的唯一依据,所以这里刻意不接受预发布号。
|
|
9
9
|
NSComparisonResult CompareStableVersions(NSString *left, NSString *right, BOOL *valid);
|
|
10
10
|
int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed);
|
|
11
|
+
|
|
12
|
+
// npm 安装日志里是否只是暂时性故障(值得自动重试一次),而不是真的装不上。
|
|
13
|
+
BOOL UpdateFailureIsTransient(NSString *log);
|
|
@@ -60,3 +60,23 @@ int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed) {
|
|
|
60
60
|
[task waitUntilExit];
|
|
61
61
|
return task.terminationStatus == EXIT_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
// 刚发布的版本存在 packument 传播与本机 npm 缓存的竞态:registry 的 /latest 已经报出
|
|
65
|
+
// 新版本,而同一时刻 `npm install cc-pets@<新版本>` 解析到的包元数据可能还是旧的,
|
|
66
|
+
// 直接报 ETARGET。这类失败重试一次通常就好,不该当成"装不上"弹错误框。
|
|
67
|
+
// 网络类错误同理。真正的失败(EACCES、ENOSPC、脚本报错等)不在此列,必须如实上报。
|
|
68
|
+
BOOL UpdateFailureIsTransient(NSString *log) {
|
|
69
|
+
if (log.length == 0) return NO;
|
|
70
|
+
static NSArray<NSString *> *markers;
|
|
71
|
+
static dispatch_once_t once;
|
|
72
|
+
dispatch_once(&once, ^{
|
|
73
|
+
markers = @[@"ETARGET", @"ENOTFOUND", @"EAI_AGAIN", @"ETIMEDOUT", @"ECONNRESET",
|
|
74
|
+
@"ERR_SOCKET_TIMEOUT", @"ECONNREFUSED", @"ERR_SSL", @"429", @"503"];
|
|
75
|
+
});
|
|
76
|
+
for (NSString *marker in markers) {
|
|
77
|
+
if ([log rangeOfString:marker options:NSCaseInsensitiveSearch].location != NSNotFound) {
|
|
78
|
+
return YES;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return NO;
|
|
82
|
+
}
|
package/bin/cc-pets
CHANGED
|
@@ -37,7 +37,9 @@ if [[ $# -eq 0 ]]; then
|
|
|
37
37
|
if [[ -d "${INSTALLED_APP}" ]]; then
|
|
38
38
|
PET_APP="${INSTALLED_APP}"
|
|
39
39
|
fi
|
|
40
|
-
|
|
40
|
+
# 桌宠是常驻进程,会一直带着这里的环境。CLAUDE_CONFIG_DIR 是会话级的(claude-nw
|
|
41
|
+
# 之类的别名会设它),泄漏过去会让桌宠永久只统计"第一个拉起它的账号"。
|
|
42
|
+
env -u CLAUDE_CONFIG_DIR open -g "${PET_APP}"
|
|
41
43
|
exit 0
|
|
42
44
|
fi
|
|
43
45
|
|
package/bin/claude-with-pet
CHANGED
|
@@ -33,5 +33,7 @@ print -r -- 'Claude' > "${CLIENT_FILE}"
|
|
|
33
33
|
|
|
34
34
|
print -rn -- '{"schemaVersion":1,"provider":"Claude","state":"starting"}' | \
|
|
35
35
|
"${PET_BIN}" --provider-event >/dev/null 2>&1 || true
|
|
36
|
-
|
|
36
|
+
# 桌宠是常驻进程,会一直带着这里的环境。CLAUDE_CONFIG_DIR 是会话级的(claude-nw
|
|
37
|
+
# 之类的别名会设它),泄漏过去会让桌宠永久只统计"第一个拉起它的账号"。
|
|
38
|
+
env -u CLAUDE_CONFIG_DIR open -g "${PET_APP}" --args --managed
|
|
37
39
|
exec "${REAL_CLAUDE}" "$@"
|
package/bin/codex-with-pet
CHANGED
|
@@ -34,5 +34,7 @@ print -r -- 'Codex' > "${CLIENT_FILE}"
|
|
|
34
34
|
|
|
35
35
|
print -rn -- '{"schemaVersion":1,"provider":"Codex","state":"starting"}' | \
|
|
36
36
|
"${PET_BIN}" --provider-event >/dev/null 2>&1 || true
|
|
37
|
-
|
|
37
|
+
# 桌宠是常驻进程,会一直带着这里的环境。CLAUDE_CONFIG_DIR 是会话级的(claude-nw
|
|
38
|
+
# 之类的别名会设它),泄漏过去会让桌宠永久只统计"第一个拉起它的账号"。
|
|
39
|
+
env -u CLAUDE_CONFIG_DIR open -g "${PET_APP}" --args --managed
|
|
38
40
|
exec "${REAL_CODEX}" "$@"
|