cc-pets 2.1.2 → 2.2.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/CHANGELOG.zh-CN.md +42 -0
  3. package/CONTRIBUTING.md +68 -0
  4. package/CONTRIBUTING.zh-CN.md +56 -0
  5. package/README.md +47 -31
  6. package/README.zh-CN.md +39 -20
  7. package/Resources/Info.plist +3 -1
  8. package/Resources/en.lproj/InfoPlist.strings +1 -0
  9. package/Resources/phrases.default.en.txt +182 -0
  10. package/Resources/zh-Hans.lproj/InfoPlist.strings +1 -0
  11. package/Resources/zh-Hans.lproj/Localizable.strings +337 -0
  12. package/Sources/CCPets/CCPetsAppDelegate+AgentStatus.m +35 -36
  13. package/Sources/CCPets/CCPetsAppDelegate+Bridge.m +16 -14
  14. package/Sources/CCPets/CCPetsAppDelegate+Pets.m +8 -10
  15. package/Sources/CCPets/CCPetsAppDelegate+Private.h +33 -9
  16. package/Sources/CCPets/CCPetsAppDelegate+Settings.m +84 -8
  17. package/Sources/CCPets/CCPetsAppDelegate+Speech.m +7 -5
  18. package/Sources/CCPets/CCPetsAppDelegate+Update.m +104 -79
  19. package/Sources/CCPets/CCPetsAppDelegate.h +1 -2
  20. package/Sources/CCPets/CCPetsAppDelegate.m +23 -15
  21. package/Sources/CCPets/CCPetsCleanup.m +9 -6
  22. package/Sources/CCPets/CCPetsEvents.m +4 -3
  23. package/Sources/CCPets/CCPetsImageLoader.h +2 -1
  24. package/Sources/CCPets/CCPetsImageLoader.m +10 -2
  25. package/Sources/CCPets/CCPetsL10n.h +55 -0
  26. package/Sources/CCPets/CCPetsL10n.m +219 -0
  27. package/Sources/CCPets/CCPetsPetSize.h +10 -0
  28. package/Sources/CCPets/CCPetsPetSize.m +21 -0
  29. package/Sources/CCPets/CCPetsPhrases.h +14 -1
  30. package/Sources/CCPets/CCPetsPhrases.m +107 -38
  31. package/Sources/CCPets/CCPetsPhrasesEditor.m +100 -65
  32. package/Sources/CCPets/CCPetsPreviews.m +7 -6
  33. package/Sources/CCPets/CCPetsVersion.h +7 -4
  34. package/Sources/CCPets/CCPetsVersion.m +14 -6
  35. package/Sources/CCPets/MenuChoiceRow.m +3 -0
  36. package/Sources/CCPets/MenuPetSizeView.h +5 -0
  37. package/Sources/CCPets/MenuPetSizeView.m +73 -0
  38. package/Sources/CCPets/MenuToggleSwitch.m +3 -2
  39. package/Sources/CCPets/PetView.m +156 -94
  40. package/Sources/CCPets/QuotaDashboardView.m +122 -85
  41. package/Sources/CCPets/main.m +3 -1
  42. package/bin/cc-pets +21 -22
  43. package/bin/claude-with-pet +2 -1
  44. package/bin/codex-with-pet +2 -1
  45. package/package.json +3 -2
  46. package/scripts/bridge/cli.mjs +39 -38
  47. package/scripts/bridge/core.mjs +27 -26
  48. package/scripts/bridge/hook.mjs +7 -6
  49. package/scripts/bridge/install.mjs +24 -23
  50. package/scripts/bridge/mcp-server.mjs +79 -71
  51. package/scripts/bridge/options.mjs +7 -6
  52. package/scripts/bridge/reservations.mjs +6 -5
  53. package/scripts/bridge/store.mjs +10 -9
  54. package/scripts/build.sh +24 -5
  55. package/scripts/check-l10n.mjs +168 -0
  56. package/scripts/configure-updater.mjs +4 -3
  57. package/scripts/doctor.mjs +93 -79
  58. package/scripts/i18n.mjs +122 -0
  59. package/scripts/i18n.zsh +66 -0
  60. package/scripts/install-app.sh +3 -2
  61. package/scripts/install-claude-hooks.mjs +10 -9
  62. package/scripts/install-codex-hooks.mjs +7 -6
  63. package/scripts/install-shell-integration.sh +6 -5
  64. package/scripts/locales/zh-Hans.json +366 -0
  65. package/scripts/pet-store.mjs +45 -44
  66. package/scripts/uninstall-app.sh +4 -3
  67. package/scripts/uninstall-integrations.mjs +8 -7
  68. package/scripts/uninstall-shell-integration.sh +8 -7
  69. /package/Resources/{phrases.default.txt → phrases.default.zh-Hans.txt} +0 -0
@@ -76,9 +76,10 @@ static void TrimUpdateLog(NSString *path) {
76
76
  BOOL npmCliExists = npmCliPath.isAbsolutePath &&
77
77
  [NSFileManager.defaultManager isReadableFileAtPath:npmCliPath];
78
78
  if (!nodeExecutable || !npmCliExists) {
79
- [self showAlertWithTitle:@"无法自动更新"
80
- message:@"没有找到安装 CC Pets 时使用的 Node.js/npm。请先手动执行一次:\n\n"
81
- "npm install -g cc-pets@latest --allow-scripts=cc-pets"];
79
+ [self showAlertWithTitle:L(@"Can't Update Automatically")
80
+ message:L(@"The Node.js/npm used to install CC Pets wasn't found. Run this once manually:\n"
81
+ "\n"
82
+ "npm install -g cc-pets@latest --allow-scripts=cc-pets")];
82
83
  return;
83
84
  }
84
85
 
@@ -87,7 +88,7 @@ static void TrimUpdateLog(NSString *path) {
87
88
  [NSFileManager.defaultManager createDirectoryAtPath:supportDirectory
88
89
  withIntermediateDirectories:YES attributes:nil error:&directoryError];
89
90
  if (directoryError) {
90
- [self showAlertWithTitle:@"无法自动更新" message:directoryError.localizedDescription];
91
+ [self showAlertWithTitle:L(@"Can't Update Automatically") message:directoryError.localizedDescription];
91
92
  return;
92
93
  }
93
94
  NSString *logPath = [supportDirectory stringByAppendingPathComponent:@"update.log"];
@@ -95,7 +96,7 @@ static void TrimUpdateLog(NSString *path) {
95
96
  chmod(logPath.fileSystemRepresentation, S_IRUSR | S_IWUSR);
96
97
  NSFileHandle *logHandle = [NSFileHandle fileHandleForWritingAtPath:logPath];
97
98
  if (!logHandle) {
98
- [self showAlertWithTitle:@"无法自动更新" message:@"无法创建更新日志。"];
99
+ [self showAlertWithTitle:L(@"Can't Update Automatically") message:L(@"Couldn't create the update log.")];
99
100
  return;
100
101
  }
101
102
 
@@ -142,8 +143,8 @@ static void TrimUpdateLog(NSString *path) {
142
143
  strongSelf.updating = NO;
143
144
  [strongSelf refreshUpdateBadge];
144
145
  if ([strongSelf restartAfterUpdateToVersion:version configuration:configuration]) return;
145
- [strongSelf showAlertWithTitle:@"更新完成"
146
- message:@"CC Pets 已更新,但没有找到可自动启动的新版应用,请手动重新启动一次。"];
146
+ [strongSelf showAlertWithTitle:L(@"Update Complete")
147
+ message:L(@"CC Pets was updated, but the new app couldn't be relaunched automatically. Please restart it manually.")];
147
148
  return;
148
149
  }
149
150
  // 暂时性故障(典型是刚发布的版本报 ETARGET)自动重试一次再说,
@@ -160,11 +161,11 @@ static void TrimUpdateLog(NSString *path) {
160
161
  [strongSelf refreshUpdateBadge];
161
162
  [NSApp activateIgnoringOtherApps:YES];
162
163
  NSAlert *alert = [NSAlert new];
163
- alert.messageText = @"更新失败";
164
+ alert.messageText = L(@"Update Failed");
164
165
  alert.informativeText = [NSString stringWithFormat:
165
- @"旧版本仍可继续使用。错误详情已写入:\n%@", logPath];
166
- [alert addButtonWithTitle:@"打开日志"];
167
- [alert addButtonWithTitle:@"关闭"];
166
+ L(@"You can keep using the current version. Details were written to:\n%@"), logPath];
167
+ [alert addButtonWithTitle:L(@"Open Log")];
168
+ [alert addButtonWithTitle:L(@"Close")];
168
169
  if ([alert runModal] == NSAlertFirstButtonReturn) {
169
170
  [NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:logPath]];
170
171
  }
@@ -176,13 +177,13 @@ static void TrimUpdateLog(NSString *path) {
176
177
  [self refreshUpdateBadge];
177
178
  self.updateTask = nil;
178
179
  [logHandle closeFile];
179
- [self showAlertWithTitle:@"无法启动更新" message:launchError.localizedDescription];
180
+ [self showAlertWithTitle:L(@"Can't Start Update") message:launchError.localizedDescription];
180
181
  return;
181
182
  }
182
183
  // 重试是静默的:第一次已经弹过"正在更新",再弹一次只会让人以为出了两回事。
183
184
  if (attempt == 0) {
184
- [self showAlertWithTitle:@"正在更新"
185
- message:[NSString stringWithFormat:@"正在下载并安装 CC Pets %@。完成后桌宠会自动重启。", version]];
185
+ [self showAlertWithTitle:L(@"Updating")
186
+ message:[NSString stringWithFormat:L(@"Downloading and installing CC Pets %@. The pet will restart when it's done."), version]];
186
187
  }
187
188
  }
188
189
  // 关于弹窗与检查更新同用 NSAlert,保持样式一致;版本号用构建时注入的 CC_PETS_VERSION(与检查更新
@@ -192,18 +193,18 @@ static void TrimUpdateLog(NSString *path) {
192
193
  NSAlert *alert = [NSAlert new];
193
194
  alert.messageText = @"CC Pets";
194
195
  alert.informativeText = [NSString stringWithFormat:
195
- @"当前版本:%@\n\nClaude Code / Codex CLI 的多功能桌面宠物。", @CC_PETS_VERSION];
196
- [alert addButtonWithTitle:@"好"];
197
- [alert addButtonWithTitle:@"访问主页"];
196
+ L(@"Version %@\n\nA desktop pet for Claude Code and Codex CLI."), @CC_PETS_VERSION];
197
+ [alert addButtonWithTitle:L(@"OK")];
198
+ [alert addButtonWithTitle:L(@"Visit Homepage")];
198
199
  if ([alert runModal] == NSAlertSecondButtonReturn) {
199
200
  [NSWorkspace.sharedWorkspace openURL:
200
201
  [NSURL URLWithString:[@"https://github.com/" stringByAppendingString:CCPetsRepositorySlug]]];
201
202
  }
202
203
  }
203
- // 版本号以 npm Registry 为准(自动更新装的就是它),更新说明取同版本 tag 的 GitHub Release
204
- // 描述。Release 没写、没建、或 GitHub 请求失败都只是没有说明,不影响提示更新本身。
205
- - (void)fetchLatestReleaseWithCompletion:(void (^)(NSString *version, NSArray<NSString *> *highlights,
206
- BOOL highlightsTruncated, NSString *errorMessage))completion {
204
+ // 版本号以 npm Registry 为准(自动更新装的就是它),更新说明取同版本 tag 里的
205
+ // release notes 文件。说明没写、或请求全部失败都只是没有说明,不影响提示更新本身。
206
+ - (void)fetchLatestReleaseWithCompletion:(void (^)(NSString *version, NSString *notes,
207
+ NSString *errorMessage))completion {
207
208
  NSURL *url = [NSURL URLWithString:@"https://registry.npmjs.org/cc-pets/latest"];
208
209
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
209
210
  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15];
@@ -219,36 +220,60 @@ static void TrimUpdateLog(NSString *path) {
219
220
  BOOL valid = NO;
220
221
  NSComparisonResult comparison = CompareStableVersions(@CC_PETS_VERSION, latestVersion, &valid);
221
222
  if (error || httpResponse.statusCode != 200 || !valid) {
222
- NSString *message = error.localizedDescription ?: @"npm Registry 返回了无效的版本信息,请稍后重试。";
223
- dispatch_async(dispatch_get_main_queue(), ^{ completion(nil, nil, NO, message); });
223
+ NSString *message = error.localizedDescription ?: L(@"The npm registry returned invalid version info. Please try again later.");
224
+ dispatch_async(dispatch_get_main_queue(), ^{ completion(nil, nil, message); });
224
225
  return;
225
226
  }
226
227
  if (comparison != NSOrderedAscending) {
227
- dispatch_async(dispatch_get_main_queue(), ^{ completion(latestVersion, nil, NO, nil); });
228
+ dispatch_async(dispatch_get_main_queue(), ^{ completion(latestVersion, nil, nil); });
228
229
  return;
229
230
  }
230
- NSString *releaseURL = [NSString stringWithFormat:
231
- @"https://api.github.com/repos/%@/releases/tags/v%@", CCPetsRepositorySlug, latestVersion];
232
- NSMutableURLRequest *releaseRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:releaseURL]
233
- cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
234
- [releaseRequest setValue:@"application/vnd.github+json" forHTTPHeaderField:@"Accept"];
235
- [releaseRequest setValue:@"cc-pets/" CC_PETS_VERSION forHTTPHeaderField:@"User-Agent"];
236
- NSURLSessionDataTask *releaseTask = [NSURLSession.sharedSession dataTaskWithRequest:releaseRequest
237
- completionHandler:^(NSData *releaseData, NSURLResponse *releaseResponse, NSError *releaseError) {
238
- NSInteger status = [releaseResponse isKindOfClass:NSHTTPURLResponse.class]
239
- ? ((NSHTTPURLResponse *)releaseResponse).statusCode : 0;
240
- NSDictionary *release = !releaseError && status == 200 && releaseData
241
- ? [NSJSONSerialization JSONObjectWithData:releaseData options:0 error:nil] : nil;
242
- NSString *body = [release isKindOfClass:NSDictionary.class] &&
243
- [release[@"body"] isKindOfClass:NSString.class] ? release[@"body"] : nil;
244
- BOOL truncated = NO;
245
- NSArray<NSString *> *highlights = ReleaseNoteHighlights(body,
246
- UpdateHighlightLimit, UpdateHighlightMaxLength, &truncated);
247
- dispatch_async(dispatch_get_main_queue(), ^{
248
- completion(latestVersion, highlights, truncated, nil);
249
- });
231
+ [self fetchReleaseNotesForVersion:latestVersion sourceIndex:0 completion:^(NSString *body) {
232
+ dispatch_async(dispatch_get_main_queue(), ^{ completion(latestVersion, body, nil); });
250
233
  }];
251
- [releaseTask resume];
234
+ }];
235
+ [task resume];
236
+ }
237
+ // 更新说明按顺序尝试:tag 里的 docs/release-notes-vX.Y.Z.md(raw.githubusercontent.com,
238
+ // 再退到 jsDelivr),最后才是 GitHub Release API。未认证的 API 按出口 IP 每小时只给 60 次,
239
+ // 走共享代理时很容易被别人用光,所以只当兜底。全部失败时 body 为 nil。
240
+ - (void)fetchReleaseNotesForVersion:(NSString *)version sourceIndex:(NSUInteger)index
241
+ completion:(void (^)(NSString *body))completion {
242
+ NSString *notesPath = [NSString stringWithFormat:@"v%@/docs/release-notes-v%@.md", version, version];
243
+ NSArray<NSString *> *sources = @[
244
+ [NSString stringWithFormat:@"https://raw.githubusercontent.com/%@/%@", CCPetsRepositorySlug, notesPath],
245
+ [NSString stringWithFormat:@"https://cdn.jsdelivr.net/gh/%@@%@", CCPetsRepositorySlug, notesPath],
246
+ [NSString stringWithFormat:@"https://api.github.com/repos/%@/releases/tags/v%@",
247
+ CCPetsRepositorySlug, version],
248
+ ];
249
+ if (index >= sources.count) {
250
+ completion(nil);
251
+ return;
252
+ }
253
+ BOOL fromAPI = index == sources.count - 1;
254
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:sources[index]]
255
+ cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
256
+ if (fromAPI) [request setValue:@"application/vnd.github+json" forHTTPHeaderField:@"Accept"];
257
+ [request setValue:@"cc-pets/" CC_PETS_VERSION forHTTPHeaderField:@"User-Agent"];
258
+ NSURLSessionDataTask *task = [NSURLSession.sharedSession dataTaskWithRequest:request
259
+ completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
260
+ NSInteger status = [response isKindOfClass:NSHTTPURLResponse.class]
261
+ ? ((NSHTTPURLResponse *)response).statusCode : 0;
262
+ NSString *body = nil;
263
+ if (!error && status == 200 && data) {
264
+ if (fromAPI) {
265
+ NSDictionary *release = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
266
+ body = [release isKindOfClass:NSDictionary.class] &&
267
+ [release[@"body"] isKindOfClass:NSString.class] ? release[@"body"] : nil;
268
+ } else {
269
+ body = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
270
+ }
271
+ }
272
+ if (body.length > 0) {
273
+ completion(body);
274
+ return;
275
+ }
276
+ [self fetchReleaseNotesForVersion:version sourceIndex:index + 1 completion:completion];
252
277
  }];
253
278
  [task resume];
254
279
  }
@@ -256,23 +281,22 @@ static void TrimUpdateLog(NSString *path) {
256
281
  if (self.checkingForUpdate || self.updating) return;
257
282
  self.checkingForUpdate = YES;
258
283
  __weak typeof(self) weakSelf = self;
259
- [self fetchLatestReleaseWithCompletion:^(NSString *version, NSArray<NSString *> *highlights,
260
- BOOL truncated, NSString *errorMessage) {
284
+ [self fetchLatestReleaseWithCompletion:^(NSString *version, NSString *notes, NSString *errorMessage) {
261
285
  typeof(self) strongSelf = weakSelf;
262
286
  if (!strongSelf) return;
263
287
  strongSelf.checkingForUpdate = NO;
264
288
  if (errorMessage) {
265
- [strongSelf showAlertWithTitle:@"检查更新失败" message:errorMessage];
289
+ [strongSelf showAlertWithTitle:L(@"Update Check Failed") message:errorMessage];
266
290
  return;
267
291
  }
268
292
  BOOL valid = NO;
269
293
  if (CompareStableVersions(@CC_PETS_VERSION, version, &valid) != NSOrderedAscending) {
270
294
  [strongSelf clearPendingUpdate];
271
- [strongSelf showAlertWithTitle:@"已是最新版本"
272
- message:[NSString stringWithFormat:@"当前版本:%@", @CC_PETS_VERSION]];
295
+ [strongSelf showAlertWithTitle:L(@"You're Up to Date")
296
+ message:[NSString stringWithFormat:L(@"Version %@"), @CC_PETS_VERSION]];
273
297
  return;
274
298
  }
275
- [strongSelf rememberPendingUpdate:version highlights:highlights truncated:truncated];
299
+ [strongSelf rememberPendingUpdate:version notes:notes];
276
300
  [strongSelf showUpdateDialog];
277
301
  }];
278
302
  }
@@ -289,8 +313,7 @@ static void TrimUpdateLog(NSString *path) {
289
313
  self.lastSilentUpdateCheckAt = now;
290
314
  self.checkingForUpdate = YES;
291
315
  __weak typeof(self) weakSelf = self;
292
- [self fetchLatestReleaseWithCompletion:^(NSString *version, NSArray<NSString *> *highlights,
293
- BOOL truncated, NSString *errorMessage) {
316
+ [self fetchLatestReleaseWithCompletion:^(NSString *version, NSString *notes, NSString *errorMessage) {
294
317
  typeof(self) strongSelf = weakSelf;
295
318
  if (!strongSelf) return;
296
319
  strongSelf.checkingForUpdate = NO;
@@ -300,40 +323,39 @@ static void TrimUpdateLog(NSString *path) {
300
323
  [strongSelf clearPendingUpdate];
301
324
  return;
302
325
  }
303
- [strongSelf rememberPendingUpdate:version highlights:highlights truncated:truncated];
326
+ [strongSelf rememberPendingUpdate:version notes:notes];
304
327
  [strongSelf showUpdateBubble];
305
328
  }];
306
329
  }
307
- - (void)rememberPendingUpdate:(NSString *)version highlights:(NSArray<NSString *> *)highlights
308
- truncated:(BOOL)truncated {
330
+ // 存的是说明原文,弹窗时再按当时的界面语言解析:切换语言后不用重新联网,要点也跟着换。
331
+ - (void)rememberPendingUpdate:(NSString *)version notes:(NSString *)notes {
309
332
  // 「稍后」只针对当时那个版本;又出了更新的版本就重新提醒。
310
333
  if (![version isEqualToString:self.pendingUpdateVersion]) self.updateReminderSnoozed = NO;
311
334
  self.pendingUpdateVersion = version;
312
- self.pendingUpdateHighlights = highlights ?: @[];
313
- self.pendingUpdateHighlightsTruncated = truncated;
335
+ self.pendingUpdateNotes = notes;
314
336
  [self refreshUpdateBadge];
315
337
  }
316
338
  - (void)refreshUpdateBadge {
317
339
  BOOL show = self.pendingUpdateVersion.length > 0 && !self.updating;
318
340
  self.updateBadgeView.hidden = !show;
319
341
  self.updateBadgeButton.toolTip = show
320
- ? [NSString stringWithFormat:@"发现新版本 %@,点击查看", self.pendingUpdateVersion] : nil;
342
+ ? [NSString stringWithFormat:L(@"Version %@ is available. Click to view."), self.pendingUpdateVersion] : nil;
321
343
  }
322
344
  - (void)clearPendingUpdate {
323
345
  self.pendingUpdateVersion = nil;
324
- self.pendingUpdateHighlights = nil;
325
- self.pendingUpdateHighlightsTruncated = NO;
346
+ self.pendingUpdateNotes = nil;
326
347
  [self refreshUpdateBadge];
327
348
  if (self.updateBubbleVisible) [self hideSpeechBubble];
328
349
  }
329
350
  // 更新要点放进 accessoryView 而不是 informativeText:后者是一整段纯文本,列表项折行后
330
351
  // 第二行会顶到「•」下面,几条长说明挤成一坨。这里用悬挂缩进让折行对齐到文字起点。
331
- - (NSView *)updateHighlightsAccessoryView {
332
- if (self.pendingUpdateHighlights.count == 0) return nil;
352
+ - (NSView *)updateHighlightsAccessoryView:(NSArray<NSString *> *)highlights truncated:(BOOL)truncated {
353
+ if (highlights.count == 0) return nil;
333
354
  const CGFloat width = 300;
334
355
  NSFont *bodyFont = [NSFont systemFontOfSize:12];
335
356
  NSString *bullet = @"•\t";
336
- CGFloat indent = ceil([bullet sizeWithAttributes:@{NSFontAttributeName: bodyFont}].width) + 4;
357
+ // 只量「•」本身:连 \t 一起量会按默认 28pt 制表位展开,符号和文字之间空出一大截。
358
+ CGFloat indent = ceil([@"•" sizeWithAttributes:@{NSFontAttributeName: bodyFont}].width) + 6;
337
359
  NSMutableParagraphStyle *itemStyle = [NSMutableParagraphStyle new];
338
360
  itemStyle.tabStops = @[[[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentLeft
339
361
  location:indent options:@{}]];
@@ -343,22 +365,22 @@ static void TrimUpdateLog(NSString *path) {
343
365
  NSMutableParagraphStyle *headerStyle = [NSMutableParagraphStyle new];
344
366
  headerStyle.paragraphSpacing = 6;
345
367
 
346
- NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"更新内容\n"
368
+ NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:L(@"What's New\n")
347
369
  attributes:@{NSFontAttributeName: [NSFont systemFontOfSize:12 weight:NSFontWeightSemibold],
348
370
  NSForegroundColorAttributeName: NSColor.labelColor,
349
371
  NSParagraphStyleAttributeName: headerStyle}];
350
372
  NSDictionary *itemAttributes = @{NSFontAttributeName: bodyFont,
351
373
  NSForegroundColorAttributeName: NSColor.secondaryLabelColor,
352
374
  NSParagraphStyleAttributeName: itemStyle};
353
- [self.pendingUpdateHighlights enumerateObjectsUsingBlock:^(NSString *item, NSUInteger index, BOOL *stop) {
375
+ [highlights enumerateObjectsUsingBlock:^(NSString *item, NSUInteger index, BOOL *stop) {
354
376
  NSString *line = [NSString stringWithFormat:@"%@%@%@", bullet, item,
355
- index + 1 < self.pendingUpdateHighlights.count || self.pendingUpdateHighlightsTruncated
377
+ index + 1 < highlights.count || truncated
356
378
  ? @"\n" : @""];
357
379
  [text appendAttributedString:[[NSAttributedString alloc] initWithString:line
358
380
  attributes:itemAttributes]];
359
381
  }];
360
- if (self.pendingUpdateHighlightsTruncated) {
361
- [text appendAttributedString:[[NSAttributedString alloc] initWithString:@"还有更多更新,完整说明见 GitHub Release"
382
+ if (truncated) {
383
+ [text appendAttributedString:[[NSAttributedString alloc] initWithString:L(@"More changes in the full GitHub release notes")
362
384
  attributes:@{NSFontAttributeName: [NSFont systemFontOfSize:11],
363
385
  NSForegroundColorAttributeName: NSColor.tertiaryLabelColor,
364
386
  NSParagraphStyleAttributeName: itemStyle}]];
@@ -376,12 +398,15 @@ static void TrimUpdateLog(NSString *path) {
376
398
  if (self.updateBubbleVisible) [self hideSpeechBubble];
377
399
  [NSApp activateIgnoringOtherApps:YES];
378
400
  NSAlert *alert = [NSAlert new];
379
- alert.messageText = [NSString stringWithFormat:@"发现新版本 %@", version];
380
- alert.informativeText = [NSString stringWithFormat:@"当前版本 %@", @CC_PETS_VERSION];
381
- alert.accessoryView = [self updateHighlightsAccessoryView];
382
- [alert addButtonWithTitle:@"立即更新"];
383
- [alert addButtonWithTitle:@"稍后"];
384
- if (self.pendingUpdateHighlights.count > 0) [alert addButtonWithTitle:@"完整说明"];
401
+ alert.messageText = [NSString stringWithFormat:L(@"CC Pets %@ Is Available"), version];
402
+ alert.informativeText = [NSString stringWithFormat:L(@"Current version %@"), @CC_PETS_VERSION];
403
+ BOOL truncated = NO;
404
+ NSArray<NSString *> *highlights = ReleaseNoteHighlightsForLanguage(self.pendingUpdateNotes,
405
+ CCPetsCurrentLanguage(), UpdateHighlightLimit, UpdateHighlightMaxLength, &truncated);
406
+ alert.accessoryView = [self updateHighlightsAccessoryView:highlights truncated:truncated];
407
+ [alert addButtonWithTitle:L(@"Update Now")];
408
+ [alert addButtonWithTitle:L(@"Later")];
409
+ if (highlights.count > 0) [alert addButtonWithTitle:L(@"Release Notes")];
385
410
  NSModalResponse response = [alert runModal];
386
411
  if (response == NSAlertFirstButtonReturn) {
387
412
  [self startUpdateToVersion:version];
@@ -429,15 +454,15 @@ static void TrimUpdateLog(NSString *path) {
429
454
  return;
430
455
  }
431
456
  self.updateBubbleDeferred = NO;
432
- [self showUpdateBubbleWithText:[NSString stringWithFormat:@"CC Pets 发布新版本 v%@ 啦,点击更新",
457
+ [self showUpdateBubbleWithText:[NSString stringWithFormat:L(@"CC Pets v%@ is out! Click to update"),
433
458
  self.pendingUpdateVersion] dwell:UpdateBubbleDwell];
434
459
  }
435
460
  // 碎碎念时机里的更新提醒,几句轮换,免得每次都是同一句。
436
461
  - (NSString *)updateReminderText {
437
462
  NSArray<NSString *> *lines = @[
438
- @"新版本 {version} 还在等你哦,点我更新",
439
- @"{version} 已经发布啦,点我看看更新了啥",
440
- @"要不要升级到 {version}?点我",
463
+ L(@"{version} is still waiting. Click me!"),
464
+ L(@"{version} is out. See what's new!"),
465
+ L(@"Upgrade to {version}? Click me"),
441
466
  ];
442
467
  return [lines[arc4random_uniform((uint32_t)lines.count)]
443
468
  stringByReplacingOccurrencesOfString:@"{version}" withString:self.pendingUpdateVersion];
@@ -93,8 +93,7 @@
93
93
  @property BOOL checkingForUpdate;
94
94
  @property BOOL updating;
95
95
  @property(copy) NSString *pendingUpdateVersion;
96
- @property(copy) NSArray<NSString *> *pendingUpdateHighlights;
97
- @property BOOL pendingUpdateHighlightsTruncated;
96
+ @property(copy) NSString *pendingUpdateNotes;
98
97
  @property NSTimeInterval lastSilentUpdateCheckAt;
99
98
  @property BOOL updateBubbleVisible;
100
99
  @property BOOL updateBubbleDeferred;
@@ -58,7 +58,7 @@
58
58
  NSAlert *alert = [NSAlert new];
59
59
  alert.messageText = title;
60
60
  alert.informativeText = message;
61
- [alert addButtonWithTitle:@"好"];
61
+ [alert addButtonWithTitle:L(@"OK")];
62
62
  [alert runModal];
63
63
  }
64
64
  // 建一个只有"编辑"的主菜单。
@@ -76,19 +76,19 @@
76
76
  - (void)installEditMenu {
77
77
  if (NSApp.mainMenu) return;
78
78
  NSMenu *mainMenu = [NSMenu new];
79
- NSMenuItem *editItem = [mainMenu addItemWithTitle:@"编辑" action:nil keyEquivalent:@""];
80
- NSMenu *editMenu = [[NSMenu alloc] initWithTitle:@"编辑"];
79
+ NSMenuItem *editItem = [mainMenu addItemWithTitle:L(@"Edit") action:nil keyEquivalent:@""];
80
+ NSMenu *editMenu = [[NSMenu alloc] initWithTitle:L(@"Edit")];
81
81
 
82
82
  NSArray<NSArray *> *entries = @[
83
- @[@"撤销", NSStringFromSelector(@selector(undo:)), @"z", @(NSEventModifierFlagCommand)],
84
- @[@"重做", NSStringFromSelector(@selector(redo:)), @"z",
83
+ @[L(@"Undo"), NSStringFromSelector(@selector(undo:)), @"z", @(NSEventModifierFlagCommand)],
84
+ @[L(@"Redo"), NSStringFromSelector(@selector(redo:)), @"z",
85
85
  @(NSEventModifierFlagCommand | NSEventModifierFlagShift)],
86
86
  @[@"-", @"", @"", @0],
87
- @[@"剪切", NSStringFromSelector(@selector(cut:)), @"x", @(NSEventModifierFlagCommand)],
88
- @[@"拷贝", NSStringFromSelector(@selector(copy:)), @"c", @(NSEventModifierFlagCommand)],
89
- @[@"粘贴", NSStringFromSelector(@selector(paste:)), @"v", @(NSEventModifierFlagCommand)],
90
- @[@"删除", NSStringFromSelector(@selector(delete:)), @"", @0],
91
- @[@"全选", NSStringFromSelector(@selector(selectAll:)), @"a", @(NSEventModifierFlagCommand)],
87
+ @[L(@"Cut"), NSStringFromSelector(@selector(cut:)), @"x", @(NSEventModifierFlagCommand)],
88
+ @[L(@"Copy"), NSStringFromSelector(@selector(copy:)), @"c", @(NSEventModifierFlagCommand)],
89
+ @[L(@"Paste"), NSStringFromSelector(@selector(paste:)), @"v", @(NSEventModifierFlagCommand)],
90
+ @[L(@"Delete"), NSStringFromSelector(@selector(delete:)), @"", @0],
91
+ @[L(@"Select All"), NSStringFromSelector(@selector(selectAll:)), @"a", @(NSEventModifierFlagCommand)],
92
92
  ];
93
93
  for (NSArray *entry in entries) {
94
94
  if ([entry[0] isEqualToString:@"-"]) {
@@ -108,6 +108,12 @@
108
108
  // 台词全在这个文件里,代码里没有第二份。首次启动先从默认词库拷一份出来,
109
109
  // 否则新装的桌宠一句话都不会说。
110
110
  PetPhrasesEnsureFileExists();
111
+ // 没改过的默认台词跟着界面语言走(例如英文系统上从旧版升级上来的用户)。
112
+ PetPhrasesAdoptLanguageDefaults();
113
+ // Node 端(cc-pets、hook、CC Bridge)读这个文件决定输出语言。
114
+ CCPetsWriteLanguageFile();
115
+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(languageDidChange:)
116
+ name:CCPetsLanguageDidChangeNotification object:nil];
111
117
  if (![NSUserDefaults.standardUserDefaults boolForKey:PetInteractionPhrasesV1MigratedKey] &&
112
118
  PetPhrasesEnsureInteractionSections()) {
113
119
  [NSUserDefaults.standardUserDefaults setBool:YES
@@ -153,10 +159,10 @@
153
159
  NSDictionary *selectedOption = [self petOptionWithID:selected inOptions:petOptions] ?: petOptions.firstObject;
154
160
  selected = selectedOption[@"id"];
155
161
  NSString *spritePath = selectedOption[@"path"];
156
- NSImage *image = LoadPetSpriteImage(spritePath, NSMakeSize(140, 150),
162
+ NSImage *image = LoadPetSpriteImage(spritePath, CCPetsPetDecodeCellSize(),
157
163
  [selectedOption[@"spriteRowCount"] integerValue] ?: 9);
158
164
  if (!image) {
159
- fprintf(stderr, "无法读取桌宠素材: %s\n", spritePath.UTF8String);
165
+ fprintf(stderr, "%s\n", [NSString stringWithFormat:L(@"Can't read the pet sprite: %@"), spritePath].UTF8String);
160
166
  [NSApp terminate:nil];
161
167
  return;
162
168
  }
@@ -234,7 +240,7 @@
234
240
  self.updateBadgeArrow = [[NSImageView alloc] initWithFrame:updateBadge.bounds];
235
241
  self.updateBadgeArrow.imageScaling = NSImageScaleNone;
236
242
  self.updateBadgeArrow.image = [[NSImage imageWithSystemSymbolName:@"arrow.up"
237
- accessibilityDescription:@"有新版本"] imageWithSymbolConfiguration:
243
+ accessibilityDescription:L(@"Update available")] imageWithSymbolConfiguration:
238
244
  [NSImageSymbolConfiguration configurationWithPointSize:11 weight:NSFontWeightBold]];
239
245
  [updateBadge addSubview:self.updateBadgeArrow];
240
246
  CCPetsStatusClickButton *updateClick = [[CCPetsStatusClickButton alloc]
@@ -316,7 +322,7 @@
316
322
  self.statusIconButton.wantsLayer = YES;
317
323
  self.statusIconButton.layer.cornerRadius = 17;
318
324
  self.statusIconButton.layer.masksToBounds = YES;
319
- self.statusIconButton.toolTip = @"查看最近 Agent 会话与 CC Bridge 消息";
325
+ self.statusIconButton.toolTip = L(@"Recent Agent sessions and CC Bridge messages");
320
326
  self.statusIconButton.target = self;
321
327
  self.statusIconButton.action = @selector(showAgentSessionsMenu:);
322
328
  [self.statusGlass.contentView addSubview:self.statusIconButton];
@@ -330,7 +336,7 @@
330
336
  statusClick.transparent = YES;
331
337
  statusClick.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
332
338
  statusClick.title = @"";
333
- statusClick.toolTip = @"返回触发此状态的 Agent 终端";
339
+ statusClick.toolTip = L(@"Go back to the Agent's terminal");
334
340
  statusClick.target = self;
335
341
  statusClick.action = @selector(focusLatestAgentTerminal:);
336
342
  self.statusClickButton = statusClick;
@@ -390,6 +396,8 @@
390
396
 
391
397
  NSScreen *screen = NSScreen.mainScreen;
392
398
  NSRect visible = screen.visibleFrame;
399
+ [self applyPetSizePreference];
400
+ size = self.panel.frame.size;
393
401
  [self.panel setFrameOrigin:NSMakePoint(NSMaxX(visible) - size.width - 24, NSMinY(visible) + 18)];
394
402
  [self.panel orderFrontRegardless];
395
403
  self.usageMonitor = [CCPetsUsageMonitor new];
@@ -1,3 +1,4 @@
1
+ #import "CCPetsL10n.h"
1
2
  #import "CCPetsCleanup.h"
2
3
  #import "CCPetsPaths.h"
3
4
  #import <sys/file.h>
@@ -147,13 +148,13 @@ int CleanCCPetsData(BOOL purge) {
147
148
  NSString *supportDirectory = ApplicationSupportDirectory();
148
149
  NSString *buildCache = BuildCacheDirectory();
149
150
  if (!IsSafeSupportDirectory(supportDirectory)) {
150
- fprintf(stderr, "清理失败:应用数据目录不属于 CC Pets:%s\n",
151
- supportDirectory.UTF8String);
151
+ fprintf(stderr, "%s\n", [NSString stringWithFormat:
152
+ L(@"Clean failed: the app data directory doesn't belong to CC Pets: %@"), supportDirectory].UTF8String);
152
153
  return 3;
153
154
  }
154
155
  if (buildCache.length > 0 && !IsSafeBuildCacheDirectory(buildCache)) {
155
- fprintf(stderr, "清理失败:构建缓存目录不属于 CC Pets:%s\n",
156
- buildCache.UTF8String);
156
+ fprintf(stderr, "%s\n", [NSString stringWithFormat:
157
+ L(@"Clean failed: the build cache directory doesn't belong to CC Pets: %@"), buildCache].UTF8String);
157
158
  return 3;
158
159
  }
159
160
  NSUInteger removed = 0;
@@ -174,8 +175,10 @@ int CleanCCPetsData(BOOL purge) {
174
175
  [NSUserDefaults.standardUserDefaults removePersistentDomainForName:domain];
175
176
  [NSUserDefaults.standardUserDefaults synchronize];
176
177
  }
177
- printf("%s完成,共移除 %lu 项。\n", purge ? "完整数据清理" : "缓存清理",
178
- (unsigned long)removed);
178
+ NSString *format = purge
179
+ ? (removed != 1 ? L(@"Full cleanup done. Removed %lu items.") : L(@"Full cleanup done. Removed %lu item."))
180
+ : (removed != 1 ? L(@"Cache cleanup done. Removed %lu items.") : L(@"Cache cleanup done. Removed %lu item."));
181
+ printf("%s\n", [NSString stringWithFormat:format, (unsigned long)removed].UTF8String);
179
182
  return EXIT_SUCCESS;
180
183
  }
181
184
 
@@ -1,3 +1,4 @@
1
+ #import "CCPetsL10n.h"
1
2
  #import "CCPetsEvents.h"
2
3
  #import "CCPetsPaths.h"
3
4
  #import "CCPetsTerminalFocus.h"
@@ -210,7 +211,7 @@ int RecordProviderEvent(void) {
210
211
  if (![payload isKindOfClass:NSDictionary.class] ||
211
212
  ![payload[@"schemaVersion"] isKindOfClass:NSNumber.class] ||
212
213
  [payload[@"schemaVersion"] integerValue] != 1) {
213
- fprintf(stderr, "provider-event 需要 schemaVersion 为 1 的 JSON 对象。\n");
214
+ fprintf(stderr, "%s\n", L(@"provider-event needs a JSON object with schemaVersion 1.").UTF8String);
214
215
  return 2;
215
216
  }
216
217
  NSString *provider = SanitizedShortString(payload[@"provider"], 32);
@@ -221,7 +222,7 @@ int RecordProviderEvent(void) {
221
222
  @"tool_completed", @"tool_failed", @"completed", @"failed", @"notification"
222
223
  ]];
223
224
  if (provider.length == 0 || ![states containsObject:state]) {
224
- fprintf(stderr, "provider-event 的 provider 或 state 无效。\n");
225
+ fprintf(stderr, "%s\n", L(@"provider-event has an invalid provider or state.").UTF8String);
225
226
  return 2;
226
227
  }
227
228
  NSDictionary<NSString *, NSString *> *events = @{
@@ -247,7 +248,7 @@ int RecordProviderEvent(void) {
247
248
  NSDictionary *terminal = TerminalFocusTargetFromEnvironment();
248
249
  if (terminal.count > 0) record[@"terminal"] = terminal;
249
250
  if (!AppendAgentEventRecord(record)) {
250
- fprintf(stderr, "无法写入 Provider 事件。\n");
251
+ fprintf(stderr, "%s\n", L(@"Couldn't write the provider event.").UTF8String);
251
252
  return EXIT_FAILURE;
252
253
  }
253
254
  return EXIT_SUCCESS;
@@ -1,4 +1,5 @@
1
1
  #import <Cocoa/Cocoa.h>
2
2
 
3
- // 按桌宠实际绘制尺寸解码精灵图,避免让超大外部素材长期占用完整 RGBA 内存。
3
+ // cellSize 使用逻辑点;按至少 2x 及当前屏幕最高倍率解码,保留 Retina 细节,
4
+ // 同时限制超大外部素材的 RGBA 内存占用。无需降采样时保留原图。
4
5
  NSImage *LoadPetSpriteImage(NSString *path, NSSize cellSize, NSInteger rowCount);
@@ -10,8 +10,16 @@ NSImage *LoadPetSpriteImage(NSString *path, NSSize cellSize, NSInteger rowCount)
10
10
  CGImageSourceCopyPropertiesAtIndex(source, 0, NULL));
11
11
  CGFloat sourceWidth = [properties[(NSString *)kCGImagePropertyPixelWidth] doubleValue];
12
12
  CGFloat sourceHeight = [properties[(NSString *)kCGImagePropertyPixelHeight] doubleValue];
13
- CGFloat desiredWidth = MAX(1.0, cellSize.width) * 8.0;
14
- CGFloat desiredHeight = MAX(1.0, cellSize.height) * rowCount;
13
+ // cellSize 是逻辑点,ImageIO 的缩略尺寸是物理像素。按 1x 解码再画入
14
+ // Retina 的 2x 帧缓存,只会放大已经丢掉细节的缩略图。
15
+ // 加载发生在窗口创建前,取所有屏幕的最高倍率,并至少保留 2x,避免
16
+ // 从普通屏移到 Retina 时源图不足。标准 Codex 精灵图因此直接保留原图。
17
+ CGFloat backingScale = 2.0;
18
+ for (NSScreen *screen in NSScreen.screens) {
19
+ backingScale = MAX(backingScale, screen.backingScaleFactor);
20
+ }
21
+ CGFloat desiredWidth = MAX(1.0, cellSize.width) * backingScale * 8.0;
22
+ CGFloat desiredHeight = MAX(1.0, cellSize.height) * backingScale * rowCount;
15
23
  CGFloat scale = MIN(1.0, MAX(desiredWidth / MAX(1.0, sourceWidth),
16
24
  desiredHeight / MAX(1.0, sourceHeight)));
17
25
  if (scale >= 0.98) {
@@ -0,0 +1,55 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ // 界面多语言。
4
+ //
5
+ // 源码里直接写英文原文,它同时就是查表的 key(gettext 的做法):
6
+ // - 英文界面不查表,原样返回;
7
+ // - 其他语言查 <语言>.lproj/Localizable.strings,查不到就退回英文原文。
8
+ // 英文是源语言:漏翻的条目显示英文,比让别的语言用户看到某种第三语言好接受;
9
+ // 新语言也从英文译。代价是改了英文原文要同步改各语言表的 key,
10
+ // scripts/check-l10n.mjs 会把漏掉的报出来。
11
+ //
12
+ // 带参数的文案照常写 %@ / %ld;参数顺序和译文语序不同时,两边都用 %1$@ / %2$@ 标位置。
13
+ //
14
+ // 支持哪些语言不写在代码里:英文之外,有 <语言>.lproj/Localizable.strings 的就算支持。
15
+ // 新增一种语言只需加文件,见 CONTRIBUTING.md 的「多语言」一节。每张表除了界面文案,
16
+ // 还要带两条约定的元信息(键见下方常量):语言自己的名字、Release 说明里对应段落的标题。
17
+
18
+ // 语言偏好(NSUserDefaults):system 或某个支持的语言标识(en、zh-Hans…)。
19
+ extern NSString *const CCPetsLanguageKey;
20
+ extern NSString *const CCPetsLanguageSystem;
21
+ // 源语言,也是什么都匹配不上时的兜底。
22
+ extern NSString *const CCPetsSourceLanguage;
23
+ // 表里的元信息键。"Language Name" 的值是菜单里显示的语言名(用该语言自己的写法);
24
+ // "Release Notes Section" 是 GitHub Release 里该语言段落的标题,有多种写法时用 | 隔开。
25
+ extern NSString *const CCPetsLanguageNameKey;
26
+ extern NSString *const CCPetsReleaseNotesSectionKey;
27
+ // 切换语言后发出;常驻的界面(状态卡、额度面板、编辑器)收到后重绘。菜单每次现建,不用管。
28
+ extern NSNotificationName const CCPetsLanguageDidChangeNotification;
29
+
30
+ // 支持的语言:源语言在最前,其余按标识排序。
31
+ NSArray<NSString *> *CCPetsSupportedLanguages(void);
32
+ // 菜单里显示的语言名。
33
+ NSString *CCPetsLanguageDisplayName(NSString *language);
34
+ // Release 说明里该语言段落可能的标题。
35
+ NSArray<NSString *> *CCPetsReleaseNotesSectionTitles(NSString *language);
36
+
37
+ NSString *CCPetsLanguagePreference(void);
38
+ void CCPetsSetLanguagePreference(NSString *preference);
39
+ // 实际生效的语言,一定在 CCPetsSupportedLanguages() 里。
40
+ // 环境变量 CC_PETS_LANGUAGE 优先(测试用,也方便临时切换),其次是偏好,最后跟随系统:
41
+ // 系统首选语言里第一个能匹配上的说了算,都匹配不上就用源语言。
42
+ NSString *CCPetsCurrentLanguage(void);
43
+ BOOL CCPetsLanguageIsSource(void);
44
+ // 按给定的支持列表解析,不读任何全局状态,测试用。匹配规则:先找完全一致或前缀一致的
45
+ // (zh-Hans-CN → zh-Hans),再退到只比主语言(zh-Hant → zh-Hans、ja_JP → ja)。
46
+ NSString *CCPetsResolveLanguageAmong(NSString *preference, NSArray<NSString *> *systemLanguages,
47
+ NSArray<NSString *> *supported);
48
+
49
+ NSString *CCPetsLocalized(NSString *text) NS_FORMAT_ARGUMENT(1);
50
+ #define L(text) CCPetsLocalized(text)
51
+
52
+ // ~/.cc-pets/language(可用 CC_PETS_HOME 覆盖)。桌宠把实际生效的语言写在这里,
53
+ // Node 端的 cc-pets / hook / CC Bridge 据此输出同一种语言。
54
+ NSString *CCPetsLanguageFilePath(void);
55
+ void CCPetsWriteLanguageFile(void);