cc-pets 2.1.1 → 2.2.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.
Files changed (74) hide show
  1. package/CC_BRIDGE.md +5 -0
  2. package/CC_BRIDGE.zh-CN.md +4 -0
  3. package/CHANGELOG.md +40 -1
  4. package/CHANGELOG.zh-CN.md +40 -1
  5. package/CONTRIBUTING.md +54 -0
  6. package/CONTRIBUTING.zh-CN.md +45 -0
  7. package/README.md +57 -14
  8. package/README.zh-CN.md +56 -14
  9. package/Resources/Info.plist +3 -1
  10. package/Resources/en.lproj/InfoPlist.strings +1 -0
  11. package/Resources/phrases.default.en.txt +182 -0
  12. package/Resources/zh-Hans.lproj/InfoPlist.strings +1 -0
  13. package/Resources/zh-Hans.lproj/Localizable.strings +332 -0
  14. package/Sources/CCPets/CCPetsAppDelegate+AgentEvents.m +215 -0
  15. package/Sources/CCPets/CCPetsAppDelegate+AgentStatus.m +660 -0
  16. package/Sources/CCPets/CCPetsAppDelegate+Bridge.m +299 -0
  17. package/Sources/CCPets/CCPetsAppDelegate+Pets.m +185 -0
  18. package/Sources/CCPets/CCPetsAppDelegate+Private.h +325 -0
  19. package/Sources/CCPets/CCPetsAppDelegate+Quota.m +216 -0
  20. package/Sources/CCPets/CCPetsAppDelegate+Settings.m +226 -0
  21. package/Sources/CCPets/CCPetsAppDelegate+Speech.m +392 -0
  22. package/Sources/CCPets/CCPetsAppDelegate+Update.m +459 -0
  23. package/Sources/CCPets/CCPetsAppDelegate.h +13 -14
  24. package/Sources/CCPets/CCPetsAppDelegate.m +68 -2466
  25. package/Sources/CCPets/CCPetsCleanup.h +4 -0
  26. package/Sources/CCPets/CCPetsCleanup.m +41 -7
  27. package/Sources/CCPets/CCPetsEvents.m +4 -3
  28. package/Sources/CCPets/CCPetsL10n.h +55 -0
  29. package/Sources/CCPets/CCPetsL10n.m +219 -0
  30. package/Sources/CCPets/CCPetsPaths.h +0 -1
  31. package/Sources/CCPets/CCPetsPaths.m +0 -1
  32. package/Sources/CCPets/CCPetsPhrases.h +7 -1
  33. package/Sources/CCPets/CCPetsPhrases.m +86 -31
  34. package/Sources/CCPets/CCPetsPhrasesEditor.m +62 -64
  35. package/Sources/CCPets/CCPetsPreviews.m +7 -6
  36. package/Sources/CCPets/CCPetsUsage.h +0 -1
  37. package/Sources/CCPets/CCPetsUsage.m +0 -3
  38. package/Sources/CCPets/CCPetsVersion.h +10 -0
  39. package/Sources/CCPets/CCPetsVersion.m +92 -2
  40. package/Sources/CCPets/MenuToggleSwitch.m +3 -2
  41. package/Sources/CCPets/PetView.h +2 -0
  42. package/Sources/CCPets/PetView.m +115 -74
  43. package/Sources/CCPets/QuotaDashboardView.m +122 -88
  44. package/Sources/CCPets/main.m +16 -1
  45. package/bin/cc-pets +25 -20
  46. package/bin/claude-with-pet +2 -1
  47. package/bin/codex-with-pet +2 -1
  48. package/package.json +5 -3
  49. package/scripts/bridge/cli.mjs +47 -39
  50. package/scripts/bridge/core.mjs +28 -27
  51. package/scripts/bridge/hook.mjs +7 -6
  52. package/scripts/bridge/install.mjs +42 -19
  53. package/scripts/bridge/mcp-server.mjs +79 -71
  54. package/scripts/bridge/options.mjs +7 -6
  55. package/scripts/bridge/process.mjs +22 -0
  56. package/scripts/bridge/reservations.mjs +6 -5
  57. package/scripts/bridge/store.mjs +10 -9
  58. package/scripts/build.sh +24 -5
  59. package/scripts/check-l10n.mjs +168 -0
  60. package/scripts/configure-updater.mjs +4 -3
  61. package/scripts/doctor.mjs +470 -0
  62. package/scripts/i18n.mjs +122 -0
  63. package/scripts/i18n.zsh +66 -0
  64. package/scripts/install-app.sh +3 -2
  65. package/scripts/install-claude-hooks.mjs +22 -27
  66. package/scripts/install-codex-hooks.mjs +10 -15
  67. package/scripts/install-shell-integration.sh +6 -5
  68. package/scripts/integration-markers.mjs +51 -0
  69. package/scripts/locales/zh-Hans.json +366 -0
  70. package/scripts/pet-store.mjs +47 -45
  71. package/scripts/uninstall-app.sh +4 -3
  72. package/scripts/uninstall-integrations.mjs +24 -51
  73. package/scripts/uninstall-shell-integration.sh +8 -7
  74. /package/Resources/{phrases.default.txt → phrases.default.zh-Hans.txt} +0 -0
@@ -1,4 +1,5 @@
1
1
  #import "CCPetsPhrasesEditor.h"
2
+ #import "CCPetsL10n.h"
2
3
  #import "CCPetsPhrases.h"
3
4
 
4
5
  static void (^PetPhrasesSpeakHandler)(NSString *);
@@ -56,7 +57,7 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
56
57
  styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
57
58
  NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable
58
59
  backing:NSBackingStoreBuffered defer:NO];
59
- window.title = @"桌宠台词";
60
+ window.title = L(@"Pet Lines");
60
61
  window.releasedWhenClosed = NO;
61
62
  window.minSize = NSMakeSize(460, 400);
62
63
  [window center];
@@ -101,37 +102,37 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
101
102
  NSPopUpButton *picker = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO];
102
103
  picker.translatesAutoresizingMaskIntoConstraints = NO;
103
104
  for (NSString *tag in PetPhraseAllTags()) {
104
- [picker addItemWithTitle:[NSString stringWithFormat:@"%@(%@)",
105
+ [picker addItemWithTitle:[NSString stringWithFormat:L(@"%1$@ (%2$@)"),
105
106
  PetPhraseTagDescription(tag), tag]];
106
107
  picker.lastItem.representedObject = tag;
107
108
  }
108
109
  self.tagPicker = picker;
109
110
 
110
- NSButton *speak = [NSButton buttonWithTitle:@"试说一句" target:self
111
+ NSButton *speak = [NSButton buttonWithTitle:L(@"Try a Line") target:self
111
112
  action:@selector(speakSample:)];
112
113
  speak.translatesAutoresizingMaskIntoConstraints = NO;
113
114
 
114
- NSButton *save = [NSButton buttonWithTitle:@"保存" target:self action:@selector(save:)];
115
+ NSButton *save = [NSButton buttonWithTitle:L(@"Save") target:self action:@selector(save:)];
115
116
  // ⌘S 而不是回车:这是个多行文本编辑器,回车要用来换行。
116
117
  save.keyEquivalent = @"s";
117
118
  save.keyEquivalentModifierMask = NSEventModifierFlagCommand;
118
119
  save.translatesAutoresizingMaskIntoConstraints = NO;
119
120
  self.saveButton = save;
120
121
 
121
- NSButton *saveAndClose = [NSButton buttonWithTitle:@"保存并关闭" target:self
122
+ NSButton *saveAndClose = [NSButton buttonWithTitle:L(@"Save & Close") target:self
122
123
  action:@selector(saveAndClose:)];
123
124
  saveAndClose.keyEquivalent = @"\r";
124
125
  saveAndClose.translatesAutoresizingMaskIntoConstraints = NO;
125
126
  self.saveAndCloseButton = saveAndClose;
126
127
 
127
- NSButton *revert = [NSButton buttonWithTitle:@"恢复默认台词…" target:self
128
+ NSButton *revert = [NSButton buttonWithTitle:L(@"Restore Defaults…") target:self
128
129
  action:@selector(revertToDefault:)];
129
130
  revert.translatesAutoresizingMaskIntoConstraints = NO;
130
131
  self.revertButton = revert;
131
132
 
132
133
  // 两段式而不是下拉菜单:一共就两个去处,而且"我现在改的是哪一份"必须一眼可见——
133
134
  // 藏进下拉里的话,用户很容易把只想给一只宠物写的台词存进通用词库。
134
- NSSegmentedControl *scope = [NSSegmentedControl segmentedControlWithLabels:@[@"通用", @"当前宠物"]
135
+ NSSegmentedControl *scope = [NSSegmentedControl segmentedControlWithLabels:@[L(@"Shared"), L(@"This Pet")]
135
136
  trackingMode:NSSegmentSwitchTrackingSelectOne target:self action:@selector(scopeChanged:)];
136
137
  scope.translatesAutoresizingMaskIntoConstraints = NO;
137
138
  scope.selectedSegment = 0;
@@ -140,7 +141,7 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
140
141
  // 专属页初次打开是空白的——空白在语义上是对的(全部回落到通用),但一个空白文本框
141
142
  // 不告诉任何人该往里写什么。这个按钮就是那个起点:把默认台词整份填进来,
142
143
  // 用户在上面改字、删掉不想接管的小节即可。
143
- NSButton *fill = [NSButton buttonWithTitle:@"填入默认模板" target:self
144
+ NSButton *fill = [NSButton buttonWithTitle:L(@"Insert Template") target:self
144
145
  action:@selector(fillFromDefault:)];
145
146
  fill.translatesAutoresizingMaskIntoConstraints = NO;
146
147
  fill.hidden = YES;
@@ -206,8 +207,8 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
206
207
  NSString *petID = PetPhrasesCurrentPetID();
207
208
  BOOL hasPet = petID.length > 0;
208
209
  [self.scopeControl setLabel:hasPet ?
209
- [NSString stringWithFormat:@"当前宠物 · %@", [self displayNameForPetID:petID]] :
210
- @"当前宠物" forSegment:1];
210
+ [NSString stringWithFormat:L(@"This Pet · %@"), [self displayNameForPetID:petID]] :
211
+ L(@"This Pet") forSegment:1];
211
212
  [self.scopeControl setEnabled:hasPet forSegment:1];
212
213
 
213
214
  // 宠物变了(或没了)而这一页正停在专属范围上:跟着走,但别把用户没存的东西冲掉。
@@ -226,7 +227,7 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
226
227
 
227
228
  - (void)syncRevertButtonTitle {
228
229
  // 专属词库没有"默认"这一说,它的默认状态就是空文件(全部回落到通用)。
229
- self.revertButton.title = self.petScope ? @"清空这一页…" : @"恢复默认台词…";
230
+ self.revertButton.title = self.petScope ? L(@"Clear Page…") : L(@"Restore Defaults…");
230
231
  // 通用页不需要这个按钮:它本来就是从默认台词拷出来的,不存在空白无从下手的问题,
231
232
  // 想拿回默认内容有"恢复默认台词…"。
232
233
  self.fillButton.hidden = !self.petScope;
@@ -256,10 +257,10 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
256
257
 
257
258
  - (BOOL)confirmDiscardChanges {
258
259
  NSAlert *alert = [NSAlert new];
259
- alert.messageText = @"这一页还没保存";
260
- alert.informativeText = @"切换之后,没保存的改动会丢掉。";
261
- [alert addButtonWithTitle:@"丢弃改动"];
262
- [alert addButtonWithTitle:@"留在这一页"];
260
+ alert.messageText = L(@"This Page Isn't Saved");
261
+ alert.informativeText = L(@"Unsaved changes will be lost if you switch.");
262
+ [alert addButtonWithTitle:L(@"Discard Changes")];
263
+ [alert addButtonWithTitle:L(@"Stay")];
263
264
  return [alert runModal] == NSAlertFirstButtonReturn;
264
265
  }
265
266
 
@@ -278,8 +279,7 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
278
279
  error:nil][NSFileModificationDate];
279
280
  if (self.petScope && text.length == 0) {
280
281
  [self showStatus:[NSString stringWithFormat:
281
- @"%@ · 还是空的,这只宠物现在说的全是通用台词。"
282
- "只写想改的小节即可,或点右上角「填入默认模板」看看能写些什么。", path]
282
+ L(@"%@ · Still empty, so this pet uses the shared lines. Only write the sections you want to change, or click “Insert Template” at the top right to see what's possible."), path]
283
283
  warning:NO];
284
284
  return;
285
285
  }
@@ -337,7 +337,7 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
337
337
 
338
338
  NSString *path = [self currentFilePath];
339
339
  if (path.length == 0) {
340
- [self showStatus:@"没有选中的宠物,无法保存专属台词。" warning:YES];
340
+ [self showStatus:L(@"No pet is selected, so pet-specific lines can't be saved.") warning:YES];
341
341
  return NO;
342
342
  }
343
343
  NSError *error = nil;
@@ -347,8 +347,8 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
347
347
  [NSFileManager.defaultManager createDirectoryAtPath:path.stringByDeletingLastPathComponent
348
348
  withIntermediateDirectories:YES attributes:nil error:nil];
349
349
  if (![normalized writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error]) {
350
- [self showStatus:[NSString stringWithFormat:@"保存失败:%@",
351
- error.localizedDescription ?: @"未知原因"] warning:YES];
350
+ [self showStatus:[NSString stringWithFormat:L(@"Save failed: %@"),
351
+ error.localizedDescription ?: L(@"unknown error")] warning:YES];
352
352
  return NO;
353
353
  }
354
354
  self.loadedStamp = [NSFileManager.defaultManager attributesOfItemAtPath:path
@@ -357,11 +357,12 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
357
357
 
358
358
  if (issues.count > 0) {
359
359
  [self presentIssues:issues blocking:NO restored:nil];
360
- [self showStatus:[NSString stringWithFormat:@"已保存,有 %lu 处提示",
360
+ [self showStatus:[NSString stringWithFormat:issues.count != 1
361
+ ? L(@"Saved, with %lu notices") : L(@"Saved, with %lu notice"),
361
362
  (unsigned long)issues.count] warning:YES];
362
363
  return YES;
363
364
  }
364
- [self showStatus:@"已保存,立刻生效。" warning:NO];
365
+ [self showStatus:L(@"Saved. Takes effect now.") warning:NO];
365
366
  return YES;
366
367
  }
367
368
 
@@ -372,12 +373,11 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
372
373
  if (!current || !self.loadedStamp || [current isEqualToDate:self.loadedStamp]) return YES;
373
374
 
374
375
  NSAlert *alert = [NSAlert new];
375
- alert.messageText = @"文件在外部被改过";
376
- alert.informativeText = @"打开编辑器之后,台词文件被别的程序修改了。"
377
- "继续保存会覆盖掉那些改动。";
378
- [alert addButtonWithTitle:@"覆盖"];
379
- [alert addButtonWithTitle:@"取消"];
380
- [alert addButtonWithTitle:@"重新载入"];
376
+ alert.messageText = L(@"File Changed on Disk");
377
+ alert.informativeText = L(@"Another app changed the lines file after the editor opened it. Saving will overwrite those changes.");
378
+ [alert addButtonWithTitle:L(@"Overwrite")];
379
+ [alert addButtonWithTitle:L(@"Cancel")];
380
+ [alert addButtonWithTitle:L(@"Reload")];
381
381
  NSModalResponse response = [alert runModal];
382
382
  if (response == NSAlertSecondButtonReturn) return NO;
383
383
  if (response == NSAlertThirdButtonReturn) {
@@ -394,41 +394,41 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
394
394
  if (restored.count > 0) {
395
395
  NSMutableArray<NSString *> *names = [NSMutableArray array];
396
396
  for (NSString *tag in restored) {
397
- [names addObject:[NSString stringWithFormat:@"[%@](%@)", tag,
397
+ [names addObject:[NSString stringWithFormat:L(@"[%1$@] (%2$@)"), tag,
398
398
  PetPhraseTagDescription(tag)]];
399
399
  }
400
400
  [lines addObject:[NSString stringWithFormat:
401
- @"标签不能删,已经帮你把 %@ 加回原位了(⌘Z 可撤销)。",
401
+ L(@"Tags can't be deleted, so %@ was put back in place (⌘Z to undo)."),
402
402
  [names componentsJoinedByString:@"、"]]];
403
- if (blocking) [lines addObject:@"本次没有保存,请检查恢复位置后再保存一次。"];
403
+ if (blocking) [lines addObject:L(@"Nothing was saved. Check the restored tags, then save again.")];
404
404
  [lines addObject:@""];
405
405
  }
406
406
  for (PetPhraseIssue *issue in issues) {
407
- NSString *prefix = issue.level == PetPhraseIssueLevelError ? @"必须改:" : @"提示:";
407
+ NSString *prefix = issue.level == PetPhraseIssueLevelError ? L(@"Must fix: ") : L(@"Note: ");
408
408
  NSString *where = issue.line > 0 ?
409
- [NSString stringWithFormat:@"第 %ld 行 ", (long)issue.line] : @"";
409
+ [NSString stringWithFormat:L(@"Line %ld "), (long)issue.line] : @"";
410
410
  [lines addObject:[NSString stringWithFormat:@"%@%@%@", prefix, where, issue.message]];
411
411
  // 一屏放不下就没人看了,剩下的等改完这批再报。
412
412
  if (lines.count >= 12) {
413
- [lines addObject:[NSString stringWithFormat:@"…另有 %lu 条",
413
+ [lines addObject:[NSString stringWithFormat:L(@"…and %lu more"),
414
414
  (unsigned long)(issues.count - lines.count + 1)]];
415
415
  break;
416
416
  }
417
417
  }
418
418
  NSAlert *alert = [NSAlert new];
419
419
  if (blocking) {
420
- alert.messageText = @"还不能保存";
420
+ alert.messageText = L(@"Can't Save Yet");
421
421
  } else {
422
- alert.messageText = issues.count > 0 ? @"已保存,但有几处不会生效" : @"已保存";
422
+ alert.messageText = issues.count > 0 ? L(@"Saved, but Some Lines Won't Be Used") : L(@"Saved");
423
423
  }
424
424
  alert.informativeText = [lines componentsJoinedByString:@"\n"];
425
425
  alert.alertStyle = blocking ? NSAlertStyleWarning : NSAlertStyleInformational;
426
- [alert addButtonWithTitle:@"好"];
426
+ [alert addButtonWithTitle:L(@"OK")];
427
427
  [alert runModal];
428
428
  if (blocking) {
429
429
  [self showStatus:restored.count > 0 ?
430
- @"标签已恢复,本次未保存;请检查后再保存一次。" :
431
- @"有必须改的地方,还没保存。" warning:YES];
430
+ L(@"Tags restored, nothing saved yet. Check and save again.") :
431
+ L(@"Some problems must be fixed before saving.") warning:YES];
432
432
  }
433
433
  }
434
434
 
@@ -448,12 +448,12 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
448
448
  }
449
449
  NSString *text = PetPhraseForTagInText(tag, draft, [self sampleSlots]);
450
450
  if (text.length == 0) {
451
- [self showStatus:[NSString stringWithFormat:@"[%@] 里没有能说的句子。", tag] warning:YES];
451
+ [self showStatus:[NSString stringWithFormat:L(@"[%@] has no usable lines."), tag] warning:YES];
452
452
  return;
453
453
  }
454
454
  if (PetPhrasesSpeakHandler) PetPhrasesSpeakHandler(text);
455
- [self showStatus:[NSString stringWithFormat:@"试说:%@%@", text,
456
- fellBack ? @"(这一节来自通用台词)" : @""] warning:NO];
455
+ [self showStatus:[NSString stringWithFormat:L(@"Trying: %1$@%2$@"), text,
456
+ fellBack ? L(@" (from the shared lines)") : @""] warning:NO];
457
457
  }
458
458
 
459
459
  // 预览用的假数据。用真实数据的话,没在跑 agent 时 {toolName} 之类全是空的,
@@ -484,14 +484,14 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
484
484
  if (defaults.length == 0) return nil;
485
485
 
486
486
  NSString *petName = self.scopePetID.length > 0 ?
487
- [self displayNameForPetID:self.scopePetID] : @"这只宠物";
487
+ [self displayNameForPetID:self.scopePetID] : L(@"this pet");
488
488
  NSMutableString *text = [NSMutableString stringWithFormat:
489
- @"# ↓↓↓ %@ 的专属台词。下面整份都是注释行,未生效状态 ↓↓↓\n"
489
+ L(@"# ↓↓↓ Lines just for %1$@. Everything below is commented out and inactive ↓↓↓\n"
490
490
  "#\n"
491
- "# 想让某个情境归 %@ 自己说:把对应标签取消注释后配置对应台词即可\n"
492
- "# 开启标签但无台词配置则没有任何台词互动\n"
493
- "# 未开启标签则会命中通用台词\n"
494
- "\n", petName, petName];
491
+ "# To give %1$@ its own lines for a situation, uncomment that tag and write lines under it\n"
492
+ "# An uncommented tag with no lines keeps the pet quiet in that situation\n"
493
+ "# Tags left commented out fall back to the shared lines\n"
494
+ "\n"), petName];
495
495
 
496
496
  for (NSString *line in [defaults componentsSeparatedByString:@"\n"]) {
497
497
  // 已经是注释的行不再叠一层 #,双井号只是噪音。空行保持空行,
@@ -505,17 +505,16 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
505
505
  - (void)fillFromDefault:(id)sender {
506
506
  NSString *text = [self commentedDefaultText];
507
507
  if (text.length == 0) {
508
- [self showStatus:@"找不到默认台词文件。" warning:YES];
508
+ [self showStatus:L(@"Default lines file not found.") warning:YES];
509
509
  return;
510
510
  }
511
511
  // 空白页直接填,不打断——那正是这个按钮存在的理由。已经写了东西才问一句。
512
512
  if ((self.textView.string ?: @"").length > 0) {
513
513
  NSAlert *alert = [NSAlert new];
514
- alert.messageText = @"覆盖这一页?";
515
- alert.informativeText = @"这一页现在的内容会被整份默认台词替换(全部是注释状态)。"
516
- "还没保存,可以按 ⌘Z 撤销。";
517
- [alert addButtonWithTitle:@"覆盖"];
518
- [alert addButtonWithTitle:@"取消"];
514
+ alert.messageText = L(@"Overwrite This Page?");
515
+ alert.informativeText = L(@"This page will be replaced with the full default lines (all commented out). Nothing is saved yet; ⌘Z undoes it.");
516
+ [alert addButtonWithTitle:L(@"Overwrite")];
517
+ [alert addButtonWithTitle:L(@"Cancel")];
519
518
  if ([alert runModal] != NSAlertFirstButtonReturn) return;
520
519
  }
521
520
  // 走 shouldChangeTextInRange: 而不是直接设 string,这样这一步能被 ⌘Z 撤销。
@@ -523,8 +522,7 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
523
522
  if (![self.textView shouldChangeTextInRange:all replacementString:text]) return;
524
523
  [self.textView.textStorage replaceCharactersInRange:all withString:text];
525
524
  [self.textView didChangeText];
526
- [self showStatus:@"已填入默认台词,整份都是注释、还不生效。"
527
- "把想改的那一节行首的 # 去掉,它才归这只宠物管。" warning:NO];
525
+ [self showStatus:L(@"Default lines inserted, all commented out and inactive. Remove the # in front of a section to make it this pet's own.") warning:NO];
528
526
  }
529
527
 
530
528
  #pragma mark - 恢复默认 / 清空
@@ -533,12 +531,12 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
533
531
  NSAlert *alert = [NSAlert new];
534
532
  // 专属词库的"默认状态"就是空白:清空 = 这只宠物全部回落到通用台词。
535
533
  // 拿默认词库去填它是错的——那等于把 22 个小节全部标成"专属接管",再也不会回落。
536
- alert.messageText = self.petScope ? @"清空这只宠物的专属台词?" : @"恢复默认台词?";
534
+ alert.messageText = self.petScope ? L(@"Clear This Pet's Lines?") : L(@"Restore Default Lines?");
537
535
  alert.informativeText = self.petScope ?
538
- @"清空之后,这只宠物说的全部回到通用台词。还没保存,可以按 ⌘Z 撤销。" :
539
- @"编辑器里的内容会被默认台词替换。还没保存,可以按 ⌘Z 撤销。";
540
- [alert addButtonWithTitle:self.petScope ? @"清空" : @"恢复"];
541
- [alert addButtonWithTitle:@"取消"];
536
+ L(@"After clearing, this pet goes back to the shared lines. Nothing is saved yet; ⌘Z undoes it.") :
537
+ L(@"The editor content will be replaced with the default lines. Nothing is saved yet; ⌘Z undoes it.");
538
+ [alert addButtonWithTitle:self.petScope ? L(@"Clear") : L(@"Restore")];
539
+ [alert addButtonWithTitle:L(@"Cancel")];
542
540
  if ([alert runModal] != NSAlertFirstButtonReturn) return;
543
541
 
544
542
  NSString *text = @"";
@@ -546,7 +544,7 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
546
544
  text = [NSString stringWithContentsOfFile:PetPhrasesDefaultFilePath()
547
545
  encoding:NSUTF8StringEncoding error:nil];
548
546
  if (text.length == 0) {
549
- [self showStatus:@"找不到默认台词文件。" warning:YES];
547
+ [self showStatus:L(@"Default lines file not found.") warning:YES];
550
548
  return;
551
549
  }
552
550
  }
@@ -555,8 +553,8 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
555
553
  if (![self.textView shouldChangeTextInRange:all replacementString:text]) return;
556
554
  [self.textView.textStorage replaceCharactersInRange:all withString:text];
557
555
  [self.textView didChangeText];
558
- [self showStatus:self.petScope ? @"已清空,按保存才会写进文件。" :
559
- @"已填入默认台词,按保存才会写进文件。" warning:NO];
556
+ [self showStatus:self.petScope ? L(@"Cleared. Click Save to write it to the file.") :
557
+ L(@"Default lines inserted. Click Save to write them to the file.") warning:NO];
560
558
  }
561
559
 
562
560
  @end
@@ -1,4 +1,5 @@
1
1
  #import "CCPetsPreviews.h"
2
+ #import "CCPetsL10n.h"
2
3
  #import "QuotaDashboardView.h"
3
4
  #import "MenuToggleSwitch.h"
4
5
  #import "CCPetsUsage.h"
@@ -123,12 +124,12 @@ int RenderAgentStatusCard(NSString *path) {
123
124
  glass.layer.borderColor = [NSColor colorWithWhite:1 alpha:0.48].CGColor;
124
125
  [root addSubview:glass];
125
126
 
126
- NSTextField *title = [NSTextField labelWithString:@"Codex · 任务已完成"];
127
+ NSTextField *title = [NSTextField labelWithString:L(@"Codex · Task completed")];
127
128
  title.frame = NSMakeRect(20, 30, glassSize.width - 80, 18);
128
129
  title.font = [NSFont systemFontOfSize:13 weight:NSFontWeightSemibold];
129
130
  title.textColor = [NSColor colorWithWhite:0.10 alpha:0.96];
130
131
  [glass addSubview:title];
131
- NSTextField *detail = [NSTextField labelWithString:@"当前任务已经完成。"];
132
+ NSTextField *detail = [NSTextField labelWithString:L(@"The current task is done.")];
132
133
  detail.frame = NSMakeRect(20, 12, glassSize.width - 80, 17);
133
134
  detail.font = [NSFont systemFontOfSize:12 weight:NSFontWeightRegular];
134
135
  detail.textColor = [NSColor colorWithWhite:0.34 alpha:0.88];
@@ -143,7 +144,7 @@ int RenderAgentStatusCard(NSString *path) {
143
144
  NSColor *green = [NSColor colorWithRed:0.18 green:0.68 blue:0.35 alpha:1];
144
145
  icon.layer.backgroundColor = [green colorWithAlphaComponent:0.28].CGColor;
145
146
  NSImage *image = [NSImage imageWithSystemSymbolName:@"checkmark"
146
- accessibilityDescription:@"任务已完成"];
147
+ accessibilityDescription:L(@"Task completed")];
147
148
  icon.image = [image imageWithSymbolConfiguration:
148
149
  [NSImageSymbolConfiguration configurationWithPointSize:15 weight:NSFontWeightBold]];
149
150
  icon.contentTintColor = [green blendedColorWithFraction:0.18
@@ -173,8 +174,8 @@ int RenderMenuSwitches(NSString *path) {
173
174
  view.wantsLayer = YES;
174
175
  view.layer.backgroundColor = [NSColor colorWithWhite:0.86 alpha:1].CGColor;
175
176
  NSArray<NSDictionary *> *rows = @[
176
- @{@"title": @"任务完成", @"state": @YES, @"y": @40},
177
- @{@"title": @"任务失败", @"state": @NO, @"y": @10}
177
+ @{@"title": L(@"Task done"), @"state": @YES, @"y": @40},
178
+ @{@"title": L(@"Task failed"), @"state": @NO, @"y": @10}
178
179
  ];
179
180
  for (NSDictionary *row in rows) {
180
181
  CGFloat y = [row[@"y"] doubleValue];
@@ -213,7 +214,7 @@ int RenderPetSheet(NSString *path, NSString *sheetPath, NSInteger rowCount) {
213
214
  if (rowCount <= 0) rowCount = 9;
214
215
  NSImage *sheet = LoadPetSpriteImage(sheetPath, NSMakeSize(140, 150), rowCount);
215
216
  if (!sheet) {
216
- fprintf(stderr, "无法装载素材: %s\n", sheetPath.UTF8String);
217
+ fprintf(stderr, "%s\n", [NSString stringWithFormat:L(@"Can't load the sprite: %@"), sheetPath].UTF8String);
217
218
  return EXIT_FAILURE;
218
219
  }
219
220
 
@@ -30,7 +30,6 @@ NSDictionary *UsageByRemovingExpiredQuotaWindows(NSDictionary *usage);
30
30
  @property NSTimeInterval lastFullDiscovery;
31
31
  - (NSDictionary *)refresh;
32
32
  - (NSDictionary *)refreshWithFullDiscovery;
33
- - (NSDictionary *)refreshForSessionURL:(NSURL *)url;
34
33
  // 一批 FSEvents 里可能有多个会话文件同时变更(并发会话)。谁的额度采样更晚要读过才知道,
35
34
  // 不能取遍历到的最后一个,详见实现处注释。
36
35
  - (NSDictionary *)refreshForSessionURLs:(NSArray<NSURL *> *)urls;
@@ -1625,9 +1625,6 @@ static const NSUInteger MaximumPinnedSessions = 8;
1625
1625
  NSString *prefix = [sessionsPath stringByAppendingString:@"/"];
1626
1626
  return [url.path.stringByResolvingSymlinksInPath hasPrefix:prefix];
1627
1627
  }
1628
- - (NSDictionary *)refreshForSessionURL:(NSURL *)url {
1629
- return [self refreshForSessionURLs:url ? @[url] : @[]];
1630
- }
1631
1628
  // 并发会话下一批事件里会有多个会话文件同时变更,而"文件更晚被写"和"额度采样更晚"是两回事:
1632
1629
  // 会话拿到 rate_limits 之后还会继续追加别的行。取遍历到的最后一个就会切到采样偏旧的会话,
1633
1630
  // 面板上的百分比于是在两个会话之间来回跳。这里读各自的尾巴,按 sampledAt 挑,与
@@ -11,3 +11,13 @@ int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed);
11
11
 
12
12
  // npm 安装日志里是否只是暂时性故障(值得自动重试一次),而不是真的装不上。
13
13
  BOOL UpdateFailureIsTransient(NSString *log);
14
+
15
+ // 从 GitHub Release 描述里摘出更新要点,给更新弹窗用。Release 是多语言的:
16
+ // 只读取标题完全匹配当前语言的段落(英文是「English」,其他语言见各自表里的
17
+ // "Release Notes Section");没有对应段落时返回空数组,绝不读取全文。只取列表项,
18
+ // 去掉 Markdown 标记,代码块整段跳过。
19
+ // 每条超过 maxLength 个字符截断加「…」;超过 limit 条时只返回前 limit 条并把 *truncated 置 YES。
20
+ // 没有列表项返回空数组——没写说明就不展示,不去猜正文。
21
+ // language 是 CCPetsSupportedLanguages() 里的某一种(见 CCPetsL10n.h)。
22
+ NSArray<NSString *> *ReleaseNoteHighlightsForLanguage(NSString *body, NSString *language,
23
+ NSUInteger limit, NSUInteger maxLength, BOOL *truncated);
@@ -1,3 +1,4 @@
1
+ #import "CCPetsL10n.h"
1
2
  #import "CCPetsVersion.h"
2
3
  #import <signal.h>
3
4
  #import <unistd.h>
@@ -41,7 +42,7 @@ int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed) {
41
42
  usleep(100000);
42
43
  }
43
44
  if (pid > 1 && (kill(pid, 0) == 0 || errno == EPERM)) {
44
- fprintf(stderr, "等待旧版 CC Pets 退出超时。\n");
45
+ fprintf(stderr, "%s\n", L(@"Timed out waiting for the old CC Pets to quit.").UTF8String);
45
46
  return EXIT_FAILURE;
46
47
  }
47
48
 
@@ -54,7 +55,8 @@ int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed) {
54
55
  task.arguments = arguments;
55
56
  NSError *error = nil;
56
57
  if (![task launchAndReturnError:&error]) {
57
- fprintf(stderr, "无法重新启动 CC Pets: %s\n", error.localizedDescription.UTF8String);
58
+ fprintf(stderr, "%s\n", [NSString stringWithFormat:L(@"Couldn't restart CC Pets: %@"),
59
+ error.localizedDescription].UTF8String);
58
60
  return EXIT_FAILURE;
59
61
  }
60
62
  [task waitUntilExit];
@@ -80,3 +82,91 @@ BOOL UpdateFailureIsTransient(NSString *log) {
80
82
  }
81
83
  return NO;
82
84
  }
85
+
86
+ static NSString *StripReleaseNoteMarkdown(NSString *text) {
87
+ static NSRegularExpression *link, *image;
88
+ static dispatch_once_t once;
89
+ dispatch_once(&once, ^{
90
+ image = [NSRegularExpression regularExpressionWithPattern:@"!\\[[^\\]]*\\]\\([^)]*\\)"
91
+ options:0 error:nil];
92
+ link = [NSRegularExpression regularExpressionWithPattern:@"\\[([^\\]]*)\\]\\([^)]*\\)"
93
+ options:0 error:nil];
94
+ });
95
+ NSMutableString *result = [text mutableCopy];
96
+ [image replaceMatchesInString:result options:0 range:NSMakeRange(0, result.length) withTemplate:@""];
97
+ [link replaceMatchesInString:result options:0 range:NSMakeRange(0, result.length) withTemplate:@"$1"];
98
+ for (NSString *marker in @[@"**", @"__", @"`"]) {
99
+ [result replaceOccurrencesOfString:marker withString:@"" options:0
100
+ range:NSMakeRange(0, result.length)];
101
+ }
102
+ return [result stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
103
+ }
104
+
105
+ NSArray<NSString *> *ReleaseNoteHighlightsForLanguage(NSString *body, NSString *language,
106
+ NSUInteger limit, NSUInteger maxLength, BOOL *truncated) {
107
+ if (truncated) *truncated = NO;
108
+ if (![body isKindOfClass:NSString.class] || body.length == 0 || limit == 0) return @[];
109
+ NSArray<NSString *> *lines = [[body stringByReplacingOccurrencesOfString:@"\r" withString:@""]
110
+ componentsSeparatedByString:@"\n"];
111
+
112
+ // 只取标题完全匹配当前语言的段落:从标题开始,到下一个同级或更高级标题为止。
113
+ // 段落标题来自各语言表里的 "Release Notes Section",见 CCPetsL10n.h。
114
+ NSArray<NSString *> *sectionTitles = CCPetsReleaseNotesSectionTitles(language);
115
+ NSRange section = NSMakeRange(0, lines.count);
116
+ BOOL sectionFound = NO;
117
+ for (NSUInteger index = 0; index < lines.count; index++) {
118
+ NSString *line = [lines[index] stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
119
+ if (![line hasPrefix:@"#"]) continue;
120
+ NSUInteger level = 0;
121
+ while (level < line.length && [line characterAtIndex:level] == '#') level++;
122
+ NSString *title = [[line substringFromIndex:level]
123
+ stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
124
+ if (![sectionTitles containsObject:title]) continue;
125
+ NSUInteger end = lines.count;
126
+ for (NSUInteger next = index + 1; next < lines.count; next++) {
127
+ NSString *candidate = lines[next];
128
+ if (![candidate hasPrefix:@"#"]) continue;
129
+ NSUInteger nextLevel = 0;
130
+ while (nextLevel < candidate.length && [candidate characterAtIndex:nextLevel] == '#') nextLevel++;
131
+ if (nextLevel <= level) { end = next; break; }
132
+ }
133
+ section = NSMakeRange(index + 1, end - index - 1);
134
+ sectionFound = YES;
135
+ break;
136
+ }
137
+ // Release 必须明确写出当前语言段落;缺失时不读取全文,避免把其他语言展示给用户。
138
+ if (!sectionFound) return @[];
139
+
140
+ static NSRegularExpression *bullet;
141
+ static dispatch_once_t once;
142
+ dispatch_once(&once, ^{
143
+ // 只认顶层列表项(行首不缩进),嵌套的子项是补充说明,挤不进三条要点。
144
+ bullet = [NSRegularExpression regularExpressionWithPattern:@"^(?:[-*+]|\\d+[.)])\\s+(.+)$"
145
+ options:0 error:nil];
146
+ });
147
+ NSMutableArray<NSString *> *items = [NSMutableArray array];
148
+ BOOL inFence = NO;
149
+ for (NSUInteger index = section.location; index < NSMaxRange(section); index++) {
150
+ NSString *line = lines[index];
151
+ if ([[line stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet] hasPrefix:@"```"]) {
152
+ inFence = !inFence;
153
+ continue;
154
+ }
155
+ if (inFence) continue;
156
+ NSTextCheckingResult *match = [bullet firstMatchInString:line options:0
157
+ range:NSMakeRange(0, line.length)];
158
+ if (!match) continue;
159
+ NSString *text = StripReleaseNoteMarkdown([line substringWithRange:[match rangeAtIndex:1]]);
160
+ if (text.length == 0) continue;
161
+ if (items.count == limit) {
162
+ if (truncated) *truncated = YES;
163
+ break;
164
+ }
165
+ if (maxLength > 0 && text.length > maxLength) {
166
+ NSRange keep = [text rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, maxLength)];
167
+ text = [[text substringWithRange:keep] stringByAppendingString:@"…"];
168
+ }
169
+ [items addObject:text];
170
+ }
171
+ return items;
172
+ }
@@ -1,4 +1,5 @@
1
1
  #import "MenuToggleSwitch.h"
2
+ #import "CCPetsL10n.h"
2
3
 
3
4
  @implementation MenuToggleSwitch
4
5
  - (instancetype)initWithFrame:(NSRect)frameRect {
@@ -62,7 +63,7 @@
62
63
 
63
64
  - (void)setState:(NSControlStateValue)value {
64
65
  [super setState:value];
65
- [self setAccessibilityValue:value == NSControlStateValueOn ? @"用量" : @"订阅"];
66
+ [self setAccessibilityValue:value == NSControlStateValueOn ? L(@"API") : L(@"Plan")];
66
67
  self.needsDisplay = YES;
67
68
  }
68
69
 
@@ -80,7 +81,7 @@
80
81
  pillPath.lineWidth = 0.8;
81
82
  [pillPath stroke];
82
83
 
83
- NSString *title = usesAPI ? @"用量" : @"订阅";
84
+ NSString *title = usesAPI ? L(@"API") : L(@"Plan");
84
85
  NSDictionary<NSAttributedStringKey, id> *attributes = @{
85
86
  NSFontAttributeName: [NSFont systemFontOfSize:11 weight:NSFontWeightSemibold],
86
87
  NSForegroundColorAttributeName: NSColor.whiteColor,
@@ -30,6 +30,8 @@ extern NSString *const PetInteractionIntervalKey;
30
30
  @property(copy) void (^dragStateChanged)(BOOL dragging);
31
31
  @property(copy) void (^interactionPhraseRequested)(NSString *tag);
32
32
  @property(copy) NSArray<NSDictionary *> *(^petOptionsRequested)(void);
33
+ // 有可安装的新版本时返回版本号,否则 nil。右键菜单据此决定要不要在顶层放「更新到 x.y.z…」。
34
+ @property(copy) NSString *(^pendingUpdateVersionRequested)(void);
33
35
  @property(copy) void (^switchPetRequested)(NSString *petID);
34
36
  @property(copy) BOOL (^deletePetRequested)(NSString *petID);
35
37
  @property NSCache<NSString *, NSImage *> *petMenuPreviewCache;