cc-pets 1.0.6 → 1.0.7
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
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
- Token 聚合改为增量跟读并按额度窗口节流,事件驱动的高频刷新不再重复扫描近 7 天会话;
|
|
11
11
|
过期日期目录按目录名剪枝,无 Token 数据的会话文件缓存失败结果不再反复重读。
|
|
12
12
|
- 新开 Codex 会话时不再因为尚无 `rate_limits` 而清空面板上已知的额度。
|
|
13
|
+
- 应用内更新遇到暂时性故障时自动重试一次,不再直接弹"更新失败"。刚发布的版本存在
|
|
14
|
+
registry 传播竞态:`/latest` 已经报出新版本,而同一时刻 `npm install cc-pets@<新版本>`
|
|
15
|
+
解析到的包元数据可能还是旧的并报 `ETARGET`。重试改用一次性缓存目录强制冷取
|
|
16
|
+
(`--prefer-online` 命中 304 时仍会拿到旧元数据),不影响用户真正的 npm 缓存。
|
|
17
|
+
权限、磁盘、脚本失败等真实故障不重试,照常上报。
|
|
13
18
|
- 修复状态气泡在任务完成后被打回"正在思考":`Stop` 之后仍会飘来 `SubagentStop` /
|
|
14
19
|
`PostToolUse` 等尾巴事件,它们与 `UserPromptSubmit` 归一成同一个状态,现按事件名拦截,
|
|
15
20
|
终态只能被新一轮真实动作解除。
|
|
@@ -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;
|
|
@@ -17,6 +17,7 @@ extern NSString *const StatusBubblePreferenceV2Key;
|
|
|
17
17
|
extern const NSTimeInterval AgentStatusInactivityInterval;
|
|
18
18
|
extern const NSTimeInterval AgentStatusOrphanInterval;
|
|
19
19
|
extern const NSTimeInterval AgentStartingGraceInterval;
|
|
20
|
+
extern const NSTimeInterval UpdateRetryDelay;
|
|
20
21
|
extern const NSTimeInterval UsageRefreshIntervalVisible;
|
|
21
22
|
extern const NSTimeInterval UsageRefreshIntervalHidden;
|
|
22
23
|
extern const NSTimeInterval ClientLifecycleInterval;
|
|
@@ -41,6 +41,8 @@ const NSTimeInterval AgentStatusOrphanInterval = 10.0;
|
|
|
41
41
|
// "正在启动"只在会话拉起的一瞬间成立。超过这段还没有任何后续事件,说明会话已经就绪、
|
|
42
42
|
// 正在等用户输入,气泡应当落到"待机中",否则启动态和空闲态看起来完全一样。
|
|
43
43
|
const NSTimeInterval AgentStartingGraceInterval = 8.0;
|
|
44
|
+
// 刚发布的版本存在 registry 传播竞态,更新失败后等这么久再自动重试一次。
|
|
45
|
+
const NSTimeInterval UpdateRetryDelay = 5.0;
|
|
44
46
|
// 额度变化由 FSEvents/VNODE 主动推送;定时器只保留为监听不可用时的 120 秒兜底。
|
|
45
47
|
// 打开面板和手动刷新仍会立即读取一次。
|
|
46
48
|
const NSTimeInterval UsageRefreshIntervalVisible = 120.0;
|
|
@@ -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
|
+
}
|