cc-pets 2.2.1 → 2.3.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 (171) hide show
  1. package/CC_BRIDGE.md +5 -2
  2. package/CC_BRIDGE.zh-CN.md +4 -2
  3. package/CHANGELOG.md +60 -0
  4. package/CHANGELOG.zh-CN.md +60 -0
  5. package/CONTRIBUTING.md +13 -10
  6. package/CONTRIBUTING.zh-CN.md +11 -10
  7. package/README.md +113 -24
  8. package/README.zh-CN.md +89 -28
  9. package/Resources/zh-Hans.lproj/Localizable.strings +568 -17
  10. package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
  11. package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +82 -23
  12. package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
  13. package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +17 -3
  14. package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +70 -22
  15. package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
  16. package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
  17. package/Sources/CCPets/{CCPetsAppDelegate+Settings.m → App/CCPetsAppDelegate+Settings.m} +86 -98
  18. package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +8 -4
  19. package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
  20. package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +15 -0
  21. package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +107 -11
  22. package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
  23. package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
  24. package/Sources/CCPets/{main.m → App/main.m} +68 -1
  25. package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
  26. package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +32 -17
  27. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
  28. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +792 -0
  29. package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +60 -0
  30. package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +558 -0
  31. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
  32. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +501 -0
  33. package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +103 -0
  34. package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +779 -0
  35. package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
  36. package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
  37. package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
  38. package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
  39. package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
  40. package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
  41. package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
  42. package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
  43. package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +42 -12
  44. package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
  45. package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
  46. package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +11 -2
  47. package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +19 -2
  48. package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +4 -1
  49. package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
  50. package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
  51. package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
  52. package/Sources/CCPets/Pet/PetView+Private.h +81 -0
  53. package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
  54. package/Sources/CCPets/Pet/PetView.m +635 -0
  55. package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
  56. package/Sources/CCPets/Support/CCPetsDoctor.m +632 -0
  57. package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
  58. package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
  59. package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
  60. package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
  61. package/Sources/CCPets/Support/CCPetsPreferences.h +31 -0
  62. package/Sources/CCPets/Support/CCPetsPreferences.m +85 -0
  63. package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
  64. package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
  65. package/Sources/CCPets/UI/CCPetsFormBuilder.h +42 -0
  66. package/Sources/CCPets/UI/CCPetsFormBuilder.m +268 -0
  67. package/Sources/CCPets/{CCPetsGlassView.h → UI/CCPetsGlassView.h} +5 -1
  68. package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +25 -7
  69. package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
  70. package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
  71. package/Sources/CCPets/UI/CCPetsSettingsPage.h +62 -0
  72. package/Sources/CCPets/UI/CCPetsSettingsPage.m +917 -0
  73. package/Sources/CCPets/UI/CCPetsUIStyle.h +132 -0
  74. package/Sources/CCPets/UI/CCPetsUIStyle.m +816 -0
  75. package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
  76. package/Sources/CCPets/UI/CCPetsUsageChartView.m +284 -0
  77. package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
  78. package/Sources/CCPets/UI/CCPetsUsagePage.m +717 -0
  79. package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
  80. package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
  81. package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
  82. package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
  83. package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
  84. package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
  85. package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
  86. package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
  87. package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
  88. package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
  89. package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
  90. package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
  91. package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
  92. package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
  93. package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
  94. package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +96 -0
  95. package/Sources/CCPets/Usage/CCPetsUsage+Models.m +285 -0
  96. package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
  97. package/Sources/CCPets/Usage/CCPetsUsage.h +57 -0
  98. package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
  99. package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
  100. package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
  101. package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
  102. package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +163 -6
  103. package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
  104. package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
  105. package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +616 -0
  106. package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
  107. package/Sources/CCPets/Usage/QuotaDashboardView.m +587 -0
  108. package/THIRD_PARTY_NOTICES.md +1 -1
  109. package/THIRD_PARTY_NOTICES.zh-CN.md +1 -1
  110. package/bin/cc-pets +8 -6
  111. package/bin/claude-with-pet +10 -2
  112. package/bin/codex-with-pet +13 -5
  113. package/package.json +1 -1
  114. package/scripts/build.sh +7 -3
  115. package/scripts/i18n.zsh +9 -52
  116. package/scripts/install-app.sh +4 -0
  117. package/scripts/install-shell-integration.sh +17 -10
  118. package/scripts/uninstall-shell-integration.sh +6 -1
  119. package/Sources/CCPets/CCPetsEvents.h +0 -10
  120. package/Sources/CCPets/CCPetsUsage.h +0 -36
  121. package/Sources/CCPets/CCPetsUsage.m +0 -2069
  122. package/Sources/CCPets/PetView.m +0 -1839
  123. package/Sources/CCPets/QuotaDashboardView.m +0 -1145
  124. package/scripts/bridge/cli.mjs +0 -237
  125. package/scripts/bridge/core.mjs +0 -228
  126. package/scripts/bridge/hook.mjs +0 -150
  127. package/scripts/bridge/install.mjs +0 -311
  128. package/scripts/bridge/mcp-server.mjs +0 -308
  129. package/scripts/bridge/options.mjs +0 -87
  130. package/scripts/bridge/process.mjs +0 -151
  131. package/scripts/bridge/reservations.mjs +0 -248
  132. package/scripts/bridge/store.mjs +0 -433
  133. package/scripts/bridge/watch.mjs +0 -69
  134. package/scripts/check-l10n.mjs +0 -168
  135. package/scripts/configure-updater.mjs +0 -43
  136. package/scripts/detect-cli.mjs +0 -68
  137. package/scripts/doctor.mjs +0 -470
  138. package/scripts/i18n.mjs +0 -122
  139. package/scripts/install-claude-hooks.mjs +0 -253
  140. package/scripts/install-codex-hooks.mjs +0 -78
  141. package/scripts/integration-markers.mjs +0 -51
  142. package/scripts/locales/zh-Hans.json +0 -366
  143. package/scripts/pet-store.mjs +0 -415
  144. package/scripts/uninstall-integrations.mjs +0 -205
  145. /package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +0 -0
  146. /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
  147. /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
  148. /package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +0 -0
  149. /package/Sources/CCPets/{CCPetsImageLoader.h → Pet/CCPetsImageLoader.h} +0 -0
  150. /package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +0 -0
  151. /package/Sources/CCPets/{CCPetsPetSize.h → Pet/CCPetsPetSize.h} +0 -0
  152. /package/Sources/CCPets/{CCPetsPetSize.m → Pet/CCPetsPetSize.m} +0 -0
  153. /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
  154. /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
  155. /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
  156. /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
  157. /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
  158. /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
  159. /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
  160. /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
  161. /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
  162. /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
  163. /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
  164. /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
  165. /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
  166. /package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +0 -0
  167. /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
  168. /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
  169. /package/Sources/CCPets/{MenuPetSizeView.h → UI/MenuPetSizeView.h} +0 -0
  170. /package/Sources/CCPets/{MenuPetSizeView.m → UI/MenuPetSizeView.m} +0 -0
  171. /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
@@ -162,13 +162,15 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
162
162
  NSArray<NSString *> *entries = [NSFileManager.defaultManager contentsOfDirectoryAtPath:clientDirectory error:nil] ?: @[];
163
163
  NSInteger liveClients = 0;
164
164
  NSMutableSet<NSString *> *providers = [NSMutableSet set];
165
+ NSMutableSet<NSString *> *profileIDs = [NSMutableSet set];
166
+ NSMutableSet<NSString *> *unscopedProviders = [NSMutableSet set];
165
167
  NSMutableSet<NSString *> *sessionKeys = [NSMutableSet set];
166
168
  BOOL unlabeled = NO;
167
169
  for (NSString *entry in entries) {
168
170
  pid_t pid = (pid_t)entry.intValue;
169
171
  NSString *path = [clientDirectory stringByAppendingPathComponent:entry];
170
- // 包装脚本会把 provider 名写进 pid 文件第一行、TTY 写进第二行。1.0.2 及更早
171
- // 的版本只 touch 出空文件,升级后仍在运行的老客户端读出来是空的:这类当作
172
+ // 包装脚本依次写 provider、TTY、profileId。旧版只有前两行,1.0.2 及更早
173
+ // 只 touch 出空文件;升级后仍在运行的老客户端按缺失层级逐级回退,避免
172
174
  // “身份不明”,只要还有一个就不清场,避免把仍然活着的会话误判成已退出。
173
175
  NSString *contents = [NSString stringWithContentsOfFile:path
174
176
  encoding:NSUTF8StringEncoding error:nil] ?: @"";
@@ -178,14 +180,20 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
178
180
  stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
179
181
  NSString *tty = lines.count > 1 ? [lines[1]
180
182
  stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] : @"";
183
+ NSString *profileID = lines.count > 2 ? [lines[2]
184
+ stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] : @"";
181
185
  if (!ClientProcessAlive(pid, tty)) {
182
186
  [NSFileManager.defaultManager removeItemAtPath:path error:nil];
183
187
  continue;
184
188
  }
185
189
  liveClients += 1;
186
- if (label.length > 0 && label.length <= 32) [providers addObject:label];
187
- else unlabeled = YES;
188
- NSString *sessionKey = [self onlineAgentSessionKeyForProvider:label tty:tty];
190
+ if (label.length > 0 && label.length <= 32) {
191
+ [providers addObject:label];
192
+ if (profileID.length > 0 && profileID.length <= 128) [profileIDs addObject:profileID];
193
+ else [unscopedProviders addObject:label];
194
+ } else unlabeled = YES;
195
+ NSString *sessionKey = OnlineAgentSessionKey(label,
196
+ profileID.length <= 128 ? profileID : nil, tty);
189
197
  if (sessionKey.length > 0) [sessionKeys addObject:sessionKey];
190
198
  }
191
199
  // 包装脚本启动的客户端有精确的退出信号:pid 文件被回收。这一段不该被为"直接跑
@@ -195,6 +203,8 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
195
203
  NSSet<NSString *> *previousProviders = self.liveClientProviders;
196
204
  self.liveClientCount = liveClients;
197
205
  self.liveClientProviders = providers;
206
+ self.liveClientProfileIDs = profileIDs;
207
+ self.liveUnscopedClientProviders = unscopedProviders;
198
208
  self.liveAgentSessionKeys = sessionKeys;
199
209
  self.hasUnlabeledClient = unlabeled;
200
210
  [self pruneOfflineAgentSessionRecords];
@@ -136,7 +136,7 @@
136
136
  // 会不断把这 60 秒重置掉——用户关掉所有 Codex 窗口后仍然看到“Codex 正在启动”。
137
137
  - (void)hideAgentStatusIfClientGone {
138
138
  if (!self.hasAgentStatus || self.hasUnlabeledClient) return;
139
- NSString *provider = self.lastStatusProvider;
139
+ NSString *provider = self.lastStatusAgentProvider;
140
140
  if (provider.length == 0 || [self.liveClientProviders containsObject:provider]) return;
141
141
  // 不经包装脚本启动的客户端(直接跑 claude / codex)没有 pid 文件,只能靠
142
142
  // “最近还在发事件”证明自己活着,所以这里必须留一段静默宽限再清。
@@ -172,20 +172,23 @@
172
172
  NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
173
173
  ? record[@"terminal"] : nil;
174
174
  if (terminal.count > 0) self.lastTerminalFocusTarget = terminal;
175
- NSString *provider = SanitizedShortString(record[@"provider"], 32);
175
+ NSString *identity = [self statusIdentityForRecord:record];
176
176
  NSString *tool = [record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @"";
177
177
  if ([self.lastStatusState isEqualToString:@"approval"] &&
178
- [self.lastStatusProvider isEqualToString:provider]) return;
178
+ [self.lastStatusIdentity isEqualToString:identity]) return;
179
+ [self noteStatusIdentityForRecord:record];
179
180
  [self applyStatusPresentationForState:@"approval"
180
- provider:provider.length > 0 ? provider : @"Agent" tool:tool];
181
+ provider:[self statusPresentationNameForRecord:record] tool:tool];
181
182
  }
182
183
  // 勾选 = 显示气泡。没有 agent 状态时也允许改,这样用户可以提前设好偏好,
183
184
  // 而不必等下一次会话开始。
184
185
  - (void)toggleStatusBubbleFromMenu:(NSButton *)sender {
185
- self.statusBubbleExpanded = !self.statusBubbleExpanded;
186
- [NSUserDefaults.standardUserDefaults setBool:self.statusBubbleExpanded
187
- forKey:StatusBubbleExpandedKey];
186
+ [self updateStatusBubbleExpanded:!self.statusBubbleExpanded];
188
187
  sender.state = self.statusBubbleExpanded ? NSControlStateValueOn : NSControlStateValueOff;
188
+ }
189
+ - (void)updateStatusBubbleExpanded:(BOOL)expanded {
190
+ self.statusBubbleExpanded = expanded;
191
+ CCPetsPrefSetBool(StatusBubbleExpandedKey, expanded);
189
192
  if (self.statusBubbleExpanded && self.hasAgentStatus) {
190
193
  [self positionAgentStatus];
191
194
  [self.statusPanel orderFrontRegardless];
@@ -204,6 +207,22 @@
204
207
  return [event isEqualToString:@"SubagentStop"] || [event isEqualToString:@"PostToolUse"] ||
205
208
  [event isEqualToString:@"TaskCompleted"];
206
209
  }
210
+ // 标题优先显示账号名;同名账号(不同目录下都叫 claude)只影响展示,身份比较走 profileId。
211
+ - (NSString *)statusPresentationNameForRecord:(NSDictionary *)record {
212
+ NSString *profileName = SanitizedShortString(record[@"profileName"], 64);
213
+ if (profileName.length > 0) return profileName;
214
+ NSString *provider = SanitizedShortString(record[@"provider"], 32);
215
+ return provider.length > 0 ? provider : @"Agent";
216
+ }
217
+ - (NSString *)statusIdentityForRecord:(NSDictionary *)record {
218
+ NSString *provider = SanitizedShortString(record[@"provider"], 32);
219
+ NSString *profileID = SanitizedShortString(record[@"profileId"], 128);
220
+ return profileID.length > 0 ? [NSString stringWithFormat:@"%@|%@", provider, profileID] : provider;
221
+ }
222
+ - (void)noteStatusIdentityForRecord:(NSDictionary *)record {
223
+ self.lastStatusAgentProvider = SanitizedShortString(record[@"provider"], 32);
224
+ self.lastStatusIdentity = [self statusIdentityForRecord:record];
225
+ }
207
226
  - (void)applyStatusPresentationForState:(NSString *)state provider:(NSString *)provider
208
227
  tool:(NSString *)tool {
209
228
  self.lastStatusState = state;
@@ -225,6 +244,7 @@
225
244
  [self resizeStatusCardToFitText];
226
245
  [self layoutApprovalBadge];
227
246
  [self positionAgentStatus];
247
+ [self notePetCardChanged];
228
248
  if (self.statusBubbleExpanded) {
229
249
  [self.statusPanel orderFrontRegardless];
230
250
  // 卡片一出现就收掉独立气泡:两者都是宠物在说话,同时挂着就是重影。
@@ -245,6 +265,8 @@
245
265
  - (void)showAgentStatusForRecord:(NSDictionary *)record notify:(BOOL)shouldNotify {
246
266
  NSString *provider = SanitizedShortString(record[@"provider"], 32);
247
267
  if (provider.length == 0) provider = @"Agent";
268
+ NSString *presentationName = [self statusPresentationNameForRecord:record];
269
+ NSString *identity = [self statusIdentityForRecord:record];
248
270
  NSString *state = [record[@"state"] isKindOfClass:NSString.class]
249
271
  ? record[@"state"] : NormalizedStateForEvent(record[@"event"], [record[@"failed"] boolValue]);
250
272
  NSString *tool = [record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @"";
@@ -253,19 +275,32 @@
253
275
  if (!self.providerActivityAt) self.providerActivityAt = [NSMutableDictionary dictionary];
254
276
  self.providerActivityAt[provider] = @(self.lastStatusTimestamp);
255
277
  [self updateQuotaLiveState];
256
- if (self.hasAgentStatus && [provider isEqualToString:self.lastStatusProvider] &&
278
+ // 额外 Home 没有共用默认配置的文件监听;Hook 事件是最准确的变更信号。按 15 秒合并,
279
+ // 既让隐藏卡片及时更新,也避免工具密集执行时反复全量聚合。
280
+ if ([record[@"profileId"] isKindOfClass:NSString.class] &&
281
+ self.lastStatusTimestamp - self.lastUsageRefreshAt >= 15.0) {
282
+ [self refreshUsage:nil];
283
+ }
284
+ if (self.hasAgentStatus && [identity isEqualToString:self.lastStatusIdentity] &&
257
285
  [self isTrailingRecord:record afterState:self.lastStatusState]) return;
258
286
 
259
287
  NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
260
288
  ? record[@"terminal"] : nil;
261
- self.lastTerminalFocusTarget = terminal.count > 0 ? terminal : nil;
289
+ // Codex 的共享后台偶尔会先送到事件、稍后才完成会话与终端配对。无目标事件不能
290
+ // 把上一条已确认的回跳目标清空,否则卡片仍可见却会突然点不动。
291
+ if (terminal.count > 0) self.lastTerminalFocusTarget = terminal;
292
+ else if (self.hasAgentStatus && ![identity isEqualToString:self.lastStatusIdentity]) {
293
+ // 换成另一个账号且仍无法解析终端时,不能误跳到上一家账号。
294
+ self.lastTerminalFocusTarget = nil;
295
+ }
262
296
 
263
297
  [NSObject cancelPreviousPerformRequestsWithTarget:self
264
298
  selector:@selector(hideAgentStatus) object:nil];
265
299
  [NSObject cancelPreviousPerformRequestsWithTarget:self
266
300
  selector:@selector(enterIdleStatus) object:nil];
267
301
  self.hasAgentStatus = YES;
268
- [self applyStatusPresentationForState:state provider:provider tool:tool];
302
+ [self noteStatusIdentityForRecord:record];
303
+ [self applyStatusPresentationForState:state provider:presentationName tool:tool];
269
304
  [self.panel orderFrontRegardless];
270
305
  [self performSelector:@selector(hideAgentStatus)
271
306
  withObject:nil afterDelay:AgentStatusInactivityInterval];
@@ -324,27 +359,23 @@
324
359
  }
325
360
  - (NSString *)agentSessionKeyForRecord:(NSDictionary *)record {
326
361
  NSString *provider = SanitizedShortString(record[@"provider"], 32);
362
+ NSString *profileID = SanitizedShortString(record[@"profileId"], 128);
363
+ NSString *identity = profileID.length > 0 ? [NSString stringWithFormat:@"%@|%@", provider, profileID] : provider;
327
364
  NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
328
365
  ? record[@"terminal"] : nil;
329
366
  NSString *tty = SanitizedShortString(terminal[@"tty"], 64);
330
367
  NSString *bundleID = SanitizedShortString(terminal[@"bundleID"], 128);
331
368
  if (tty.length > 0) {
332
- return [NSString stringWithFormat:@"%@|%@|%@", provider, bundleID, tty];
369
+ return [NSString stringWithFormat:@"%@|%@|%@", identity, bundleID, tty];
333
370
  }
334
371
  NSString *session = SanitizedShortString(record[@"session"], 128);
335
- if (session.length > 0) return [NSString stringWithFormat:@"%@|%@", provider, session];
336
- return terminal.count > 0 ? [NSString stringWithFormat:@"%@|%@", provider, bundleID] : nil;
337
- }
338
- - (NSString *)onlineAgentSessionKeyForProvider:(NSString *)provider tty:(NSString *)tty {
339
- provider = SanitizedShortString(provider, 32);
340
- tty = SanitizedShortString(tty.lastPathComponent, 64);
341
- if (provider.length == 0 || tty.length == 0) return nil;
342
- return [NSString stringWithFormat:@"%@|%@", provider, tty];
372
+ if (session.length > 0) return [NSString stringWithFormat:@"%@|%@", identity, session];
373
+ return terminal.count > 0 ? [NSString stringWithFormat:@"%@|%@", identity, bundleID] : nil;
343
374
  }
344
375
  - (NSString *)onlineAgentSessionKeyForRecord:(NSDictionary *)record {
345
376
  NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
346
377
  ? record[@"terminal"] : nil;
347
- return [self onlineAgentSessionKeyForProvider:record[@"provider"] tty:terminal[@"tty"]];
378
+ return OnlineAgentSessionKey(record[@"provider"], record[@"profileId"], terminal[@"tty"]);
348
379
  }
349
380
  // 在线判定优先用包装脚本写出的 pid 文件:它给出精确的退出信号,会话一关列表就更新。
350
381
  // 但直接跑 claude / codex(或终端窗口早于 shim 安装就已打开)的会话根本没有 pid 文件,
@@ -354,6 +385,11 @@
354
385
  - (BOOL)isAgentSessionRecordLive:(NSDictionary *)record {
355
386
  NSString *onlineKey = [self onlineAgentSessionKeyForRecord:record];
356
387
  if (onlineKey.length > 0 && [self.liveAgentSessionKeys containsObject:onlineKey]) return YES;
388
+ // 老版本包装脚本的 pid 文件不带账号,只能按 provider + tty 认领。
389
+ NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
390
+ ? record[@"terminal"] : nil;
391
+ NSString *unscopedKey = OnlineAgentSessionKey(record[@"provider"], nil, terminal[@"tty"]);
392
+ if (unscopedKey.length > 0 && [self.liveAgentSessionKeys containsObject:unscopedKey]) return YES;
357
393
  NSString *provider = SanitizedShortString(record[@"provider"], 32);
358
394
  if (provider.length > 0 && [self.liveClientProviders containsObject:provider]) return NO;
359
395
  return NSDate.date.timeIntervalSince1970 - [record[@"timestamp"] doubleValue]
@@ -363,14 +399,35 @@
363
399
  for (NSString *key in self.agentSessionRecords.allKeys) {
364
400
  if (![self isAgentSessionRecordLive:self.agentSessionRecords[key]]) {
365
401
  [self.agentSessionRecords removeObjectForKey:key];
402
+ [self notePetCardChanged];
366
403
  }
367
404
  }
368
405
  }
406
+ - (NSString *)terminalSlotKeyForRecord:(NSDictionary *)record {
407
+ NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
408
+ ? record[@"terminal"] : nil;
409
+ NSString *tty = SanitizedShortString(terminal[@"tty"], 64);
410
+ if (tty.length == 0) return nil;
411
+ return [NSString stringWithFormat:@"%@|%@|%@", SanitizedShortString(record[@"provider"], 32),
412
+ SanitizedShortString(terminal[@"bundleID"], 128), tty];
413
+ }
369
414
  - (void)trackAgentSessionRecord:(NSDictionary *)record {
370
415
  NSString *key = [self agentSessionKeyForRecord:record];
371
416
  if (key.length == 0) return;
372
417
  if (!self.agentSessionRecords) self.agentSessionRecords = [NSMutableDictionary dictionary];
418
+ // 一个终端前台同时只跑一个客户端。同一终端里新起的会话(可能换了账号)说明之前那个
419
+ // 已经退出;它退出时不会补发结束事件,不在这里清掉就会在列表里留一行"正在启动"。
420
+ if ([record[@"event"] isEqual:@"SessionStart"]) {
421
+ NSString *ttyKey = [self terminalSlotKeyForRecord:record];
422
+ for (NSString *otherKey in self.agentSessionRecords.allKeys) {
423
+ if ([otherKey isEqualToString:key] || ttyKey.length == 0) continue;
424
+ if ([[self terminalSlotKeyForRecord:self.agentSessionRecords[otherKey]] isEqualToString:ttyKey]) {
425
+ [self.agentSessionRecords removeObjectForKey:otherKey];
426
+ }
427
+ }
428
+ }
373
429
  self.agentSessionRecords[key] = record;
430
+ [self notePetCardChanged];
374
431
  if (self.agentSessionRecords.count <= AgentSessionRecordLimit) return;
375
432
  NSArray<NSDictionary *> *oldestFirst = [self.agentSessionRecords.allValues
376
433
  sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *left, NSDictionary *right) {
@@ -456,13 +513,13 @@
456
513
  NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
457
514
  ? record[@"terminal"] : nil;
458
515
  if (terminal.count > 0) self.lastTerminalFocusTarget = terminal;
459
- NSString *provider = SanitizedShortString(record[@"provider"], 32);
460
516
  NSString *state = [record[@"state"] isKindOfClass:NSString.class] ? record[@"state"] : @"";
461
517
  self.hasAgentStatus = YES;
462
518
  [NSObject cancelPreviousPerformRequestsWithTarget:self
463
519
  selector:@selector(hideAgentStatus) object:nil];
520
+ [self noteStatusIdentityForRecord:record];
464
521
  [self applyStatusPresentationForState:state
465
- provider:provider.length > 0 ? provider : @"Agent"
522
+ provider:[self statusPresentationNameForRecord:record]
466
523
  tool:[record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @""];
467
524
  [self.panel orderFrontRegardless];
468
525
  [self performSelector:@selector(hideAgentStatus) withObject:nil
@@ -483,6 +540,8 @@
483
540
  PetApprovalBadgeSize, PetApprovalBadgeSize);
484
541
  }
485
542
  - (void)refreshApprovalBadge {
543
+ // 收起状态卡(hideAgentStatus)也走这里,名片要跟着回到待机,放在角标判空之前。
544
+ [self notePetCardChanged];
486
545
  CCPetsApprovalBadgeView *badge = (CCPetsApprovalBadgeView *)self.approvalBadgeView;
487
546
  if (!badge) return;
488
547
  badge.count = [self pendingApprovalSessionRecords].count;
@@ -536,7 +595,7 @@
536
595
  }
537
596
  // 菜单打开即视为看过:角标清零,下一条新消息再亮。
538
597
  self.bridgeSeenAt = NSDate.date.timeIntervalSince1970;
539
- [self refreshBridgeBadge];
598
+ [self refreshBridgeState:nil];
540
599
  if (records.count == 0) {
541
600
  [self popUpAgentSessionsMenu:menu from:sender];
542
601
  return;
@@ -20,14 +20,15 @@
20
20
  }
21
21
  self.bridgeCommandRunning = YES;
22
22
  NSTask *task = [NSTask new];
23
- task.executableURL = [NSURL fileURLWithPath:locator[@"node"]];
24
- task.arguments = [@[locator[@"cli"]] arrayByAddingObjectsFromArray:arguments];
23
+ task.executableURL = [NSURL fileURLWithPath:locator[@"binary"]];
24
+ task.arguments = [@[@"bridge"] arrayByAddingObjectsFromArray:arguments];
25
25
  NSMutableDictionary<NSString *, NSString *> *environment =
26
26
  [NSProcessInfo.processInfo.environment mutableCopy];
27
27
  NSString *existingPath = environment[@"PATH"].length > 0 ? environment[@"PATH"] : @"/usr/bin:/bin:/usr/sbin:/sbin";
28
- // claude / codex 常装在 node 同目录(nvm),桌宠的 PATH 里未必有。
29
- environment[@"PATH"] = [NSString stringWithFormat:@"%@:%@",
30
- [locator[@"node"] stringByDeletingLastPathComponent], existingPath];
28
+ // claude / codex 常装在 nvm 之类的目录里,从 Finder 启动的桌宠 PATH 里没有;
29
+ // 用 cc-pets 上次在终端里运行时记下的 PATH。
30
+ NSString *terminalPath = locator[@"path"];
31
+ environment[@"PATH"] = terminalPath.length > 0 ? [NSString stringWithFormat:@"%@:%@", terminalPath, existingPath] : existingPath;
31
32
  task.environment = environment;
32
33
  NSPipe *output = [NSPipe pipe];
33
34
  task.standardOutput = output;
@@ -41,6 +42,8 @@
41
42
  if (!strongSelf) return;
42
43
  strongSelf.bridgeCommandRunning = NO;
43
44
  [strongSelf refreshBridgeState:nil];
45
+ // 开关 Bridge 会改各账号是否算"已集成",让打开的多账号页重读。
46
+ [NSNotificationCenter.defaultCenter postNotificationName:CCPetsProfilesDidChangeNotification object:nil];
44
47
  if (finished.terminationStatus == EXIT_SUCCESS) {
45
48
  if (successMessage.length > 0) {
46
49
  [strongSelf sendNotificationWithTitle:@"CC Bridge" body:successMessage];
@@ -121,30 +124,19 @@
121
124
  sender:sender successMessage:nil];
122
125
  }
123
126
  - (void)toggleBridgeBadge:(NSButton *)sender {
124
- BOOL enabled = ![NSUserDefaults.standardUserDefaults boolForKey:BridgeBadgeEnabledKey];
125
- [NSUserDefaults.standardUserDefaults setBool:enabled forKey:BridgeBadgeEnabledKey];
127
+ BOOL enabled = !CCPetsPrefBool(BridgeBadgeEnabledKey);
128
+ [self updateBridgeBadgeEnabled:enabled];
126
129
  sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
130
+ }
131
+ - (void)updateBridgeBadgeEnabled:(BOOL)enabled {
132
+ CCPetsPrefSetBool(BridgeBadgeEnabledKey, enabled);
127
133
  [self refreshBridgeBadge];
128
134
  }
129
135
  // 与"系统通知"那组开关同一套授权流程:第一次打开时向系统申请通知权限。
130
136
  - (void)toggleBridgeNotification:(NSButton *)sender {
131
- NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
132
- if ([defaults boolForKey:BridgeNotificationKey]) {
133
- [defaults setBool:NO forKey:BridgeNotificationKey];
134
- sender.state = NSControlStateValueOff;
135
- return;
136
- }
137
- [UNUserNotificationCenter.currentNotificationCenter
138
- requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionSound
139
- completionHandler:^(BOOL granted, NSError *error) {
140
- dispatch_async(dispatch_get_main_queue(), ^{
141
- [defaults setBool:granted forKey:BridgeNotificationKey];
142
- sender.state = granted ? NSControlStateValueOn : NSControlStateValueOff;
143
- if (!granted) {
144
- [self showAlertWithTitle:L(@"Can't Enable Notifications") message:error.localizedDescription ?:
145
- L(@"Allow notifications in System Settings → Notifications → CC Pets, then try again.")];
146
- }
147
- });
137
+ [self updateNotification:BridgeNotificationKey enabled:!CCPetsPrefBool(BridgeNotificationKey)
138
+ completion:^(BOOL enabled) {
139
+ sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
148
140
  }];
149
141
  }
150
142
  // 读 bridge 状态(会话名、最近送达、信箱积压),刷新角标。bridge 未开启时清空并隐藏。
@@ -156,6 +148,8 @@
156
148
  self.bridgeRecentDeliveries = nil;
157
149
  self.bridgePendingCounts = nil;
158
150
  self.bridgeSentStamp = nil;
151
+ self.quotaView.bridgeActivityProfileIDs = [NSSet set];
152
+ self.quotaView.needsDisplay = YES;
159
153
  [self refreshBridgeBadge];
160
154
  return;
161
155
  }
@@ -179,6 +173,23 @@
179
173
  if (self.bridgeSessions[session]) pending[session] = count;
180
174
  }];
181
175
  self.bridgePendingCounts = pending;
176
+ NSMutableSet<NSString *> *bridgeProfiles = [NSMutableSet set];
177
+ for (NSString *session in pending) {
178
+ NSString *profileID = self.bridgeSessions[session][@"profileId"];
179
+ if (profileID.length > 0) [bridgeProfiles addObject:profileID];
180
+ }
181
+ for (NSDictionary *delivery in recent) {
182
+ if ([delivery[@"at"] doubleValue] <= self.bridgeSeenAt) continue;
183
+ for (NSString *key in @[@"toSession", @"fromSession"]) {
184
+ NSString *session = [delivery[key] isKindOfClass:NSString.class] ? delivery[key] : nil;
185
+ NSString *profileID = session.length > 0 ? self.bridgeSessions[session][@"profileId"] : nil;
186
+ if (profileID.length > 0) [bridgeProfiles addObject:profileID];
187
+ }
188
+ }
189
+ if (![self.quotaView.bridgeActivityProfileIDs isEqualToSet:bridgeProfiles]) {
190
+ self.quotaView.bridgeActivityProfileIDs = bridgeProfiles;
191
+ self.quotaView.needsDisplay = YES;
192
+ }
182
193
  [self notifyNewBridgeDeliveries];
183
194
  [self refreshBridgeBadge];
184
195
  }
@@ -123,7 +123,7 @@
123
123
  [NSApp activateIgnoringOtherApps:YES];
124
124
  NSAlert *alert = [NSAlert new];
125
125
  alert.messageText = L(@"No Pet Sprites Found");
126
- alert.informativeText = L(@"Download one with `cc-pets pet add <name>`, or put a PNG / WebP sprite sheet in ~/.cc-pets/pets/<name>/. CC Pets doesn't read ~/.petdex/pets/ or ~/.codex/pets/; to use Codex pets, turn on “Import Codex pets” in the right-click menu. Then click “Rescan”.");
126
+ alert.informativeText = L(@"Download one with `cc-pets pet add <name>`, or put a PNG / WebP sprite sheet in ~/.cc-pets/pets/<name>/. CC Pets doesn't read ~/.petdex/pets/ or ~/.codex/pets/; to use Codex pets, turn on “Import Codex Pets” on the Pet page of the Main menu. Then click “Rescan”.");
127
127
  [alert addButtonWithTitle:L(@"Rescan")];
128
128
  [alert addButtonWithTitle:L(@"Open Pets Folder")];
129
129
  [alert addButtonWithTitle:L(@"Quit")];
@@ -147,7 +147,21 @@
147
147
  if (!image) return;
148
148
  [self.petView applySheet:image petID:petID rowCount:spriteRowCount];
149
149
  PetPhrasesSetCurrentPetID(petID);
150
- [NSUserDefaults.standardUserDefaults setObject:petID forKey:@"CCPetsSelectedSprite"];
150
+ [NSUserDefaults.standardUserDefaults setObject:petID forKey:PetSelectedSpriteKey];
151
+ [self notePetCardChanged];
152
+ }
153
+ // 主窗口宠物页的选择列表:只给展示要的字段,素材由页面在后台解码。
154
+ - (NSArray<NSDictionary *> *)petPickerOptions {
155
+ NSMutableArray<NSDictionary *> *options = [NSMutableArray array];
156
+ for (NSDictionary *option in [self petOptions]) {
157
+ [options addObject:@{@"id": option[@"id"], @"name": option[@"name"] ?: @"", @"path": option[@"path"] ?: @"",
158
+ @"rowCount": option[@"spriteRowCount"] ?: @9,
159
+ @"builtin": @([option[@"id"] hasPrefix:@"builtin:"])}];
160
+ }
161
+ return options;
162
+ }
163
+ - (NSString *)currentPetID {
164
+ return self.petView.currentPetID;
151
165
  }
152
166
  - (BOOL)deletePetWithID:(NSString *)petID {
153
167
  if (![petID hasPrefix:@"external:"]) return NO;
@@ -177,7 +191,7 @@
177
191
  if (fallback) [self switchPetToID:fallback[@"id"]];
178
192
  else {
179
193
  PetPhrasesSetCurrentPetID(nil);
180
- [NSUserDefaults.standardUserDefaults removeObjectForKey:@"CCPetsSelectedSprite"];
194
+ [NSUserDefaults.standardUserDefaults removeObjectForKey:PetSelectedSpriteKey];
181
195
  }
182
196
  }
183
197
  return YES;
@@ -8,6 +8,9 @@
8
8
  #import "CCPetsQuotaHistory.h"
9
9
  #import "CCPetsImageLoader.h"
10
10
  #import "CCPetsPetSize.h"
11
+ #import "CCPetsPreferences.h"
12
+ #import "CCPetsMainWindow.h"
13
+ #import "CCPetsWorkbench.h"
11
14
  #import "CCPetsPhrases.h"
12
15
  #import "CCPetsPhrasesEditor.h"
13
16
  #import "CCPetsUsage.h"
@@ -15,6 +18,7 @@
15
18
  #import "MenuChoiceRow.h"
16
19
  #import "CCPetsGlassMenu.h"
17
20
  #import "CCPetsBridge.h"
21
+ #import "CCPetsProfiles.h"
18
22
  #import "MenuToggleSwitch.h"
19
23
  #import <UserNotifications/UserNotifications.h>
20
24
  #import <signal.h>
@@ -103,19 +107,31 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
103
107
  return ceil(label.fittingSize.width) + 2;
104
108
  }
105
109
 
106
- // 文案、玻璃与按钮仍使用原来的逻辑坐标,只缩小窗口与根视图的 frame。
107
- // bounds 保留原尺寸,AppKit 会同步转换绘制和命中坐标,避免文字被小外壳裁掉。
110
+ // 窗口的 contentView 由 AppKit 管理尺寸,不能直接拿它的 bounds 做缩放。
111
+ // 外壳保持窗口坐标,内部视图独立保留逻辑坐标,统一缩放绘制和命中区域。
112
+ @interface CCPetsBubbleContainerView : NSView
113
+ @end
114
+
108
115
  static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
109
116
  if (!panel) return;
110
117
  CGFloat scale = CCPetsBubbleScalePreference();
111
118
  NSSize size = NSMakeSize(logicalSize.width * scale, logicalSize.height * scale);
112
- NSView *root = panel.contentView;
113
- BOOL autoresizes = root.autoresizesSubviews;
119
+ NSView *container = panel.contentView;
120
+ NSView *root;
121
+ if ([container isKindOfClass:CCPetsBubbleContainerView.class]) {
122
+ root = container.subviews.firstObject;
123
+ } else {
124
+ root = container;
125
+ container = [[CCPetsBubbleContainerView alloc] initWithFrame:root.frame];
126
+ container.autoresizesSubviews = NO;
127
+ panel.contentView = container;
128
+ [container addSubview:root];
129
+ }
130
+ root.autoresizingMask = NSViewNotSizable;
114
131
  root.autoresizesSubviews = NO;
115
132
  [panel setContentSize:size];
116
133
  root.frame = NSMakeRect(0, 0, size.width, size.height);
117
134
  root.bounds = NSMakeRect(0, 0, logicalSize.width, logicalSize.height);
118
- root.autoresizesSubviews = autoresizes;
119
135
  root.needsDisplay = YES;
120
136
  }
121
137
 
@@ -131,10 +147,13 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
131
147
  @property(nonatomic) NSColor *fillColor;
132
148
  @end
133
149
 
134
- @interface AppDelegate ()
150
+ // 主窗口侧边栏的宠物名片从这里取数据,见 CCPetsMainWindow.h。
151
+ @interface AppDelegate () <CCPetsPetCardSource>
135
152
  - (NSString *)applicationSupportDirectory;
153
+ - (void)notePetCardChanged;
136
154
  - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message;
137
- - (void)installEditMenu;
155
+ - (void)installMainMenu;
156
+ - (void)openMainWindow:(id)sender;
138
157
  - (void)applicationDidFinishLaunching:(NSNotification *)notification;
139
158
  - (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag;
140
159
  - (void)screensDidSleep:(NSNotification *)notification;
@@ -143,32 +162,34 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
143
162
  - (void)applicationWillTerminate:(NSNotification *)notification;
144
163
  @end
145
164
 
146
- // 右键菜单里的各项设置开关
165
+ // 右键菜单里的各项设置开关。setXxx: / toggleXxx: 是菜单控件的 action;updateXxx: 不依赖
166
+ // 控件,写设置并让界面生效,主窗口设置页直接调用。
147
167
  @interface AppDelegate (Settings)
168
+ - (void)updatePetScale:(double)scale;
169
+ - (void)updateSystemMetric:(NSString *)key enabled:(BOOL)enabled;
170
+ - (void)updateUsageDisplayMode:(NSString *)mode forKey:(NSString *)key;
171
+ - (void)updateUsageDisplayMode:(NSString *)mode forProfileID:(NSString *)profileID;
172
+ - (void)updateImportCodexPets:(BOOL)enabled;
173
+ - (void)updatePanelTheme:(NSString *)theme;
174
+ - (void)updateGlassDimLevel:(NSNumber *)level;
175
+ - (void)updateSpeechEnabled:(BOOL)enabled;
176
+ - (void)updatePetInteractionEnabled:(BOOL)enabled;
177
+ - (void)updatePetInteractionValue:(NSNumber *)value forKey:(NSString *)key;
178
+ - (void)updateSpeechFrequency:(NSString *)value;
179
+ - (void)updatePhrasesSource:(NSString *)source;
180
+ - (void)updateNotification:(NSString *)key enabled:(BOOL)enabled
181
+ completion:(void (^)(BOOL enabled))completion;
148
182
  - (void)applyPetSizePreference;
149
183
  - (void)setPetSizeFromSlider:(NSSlider *)sender;
150
- - (void)toggleSystemMetric:(NSButton *)sender;
151
184
  - (void)setUsageDisplayModeFromControl:(NSButton *)sender;
152
- - (NSString *)systemMetricKeyForTag:(NSInteger)tag;
153
185
  - (void)applySystemMetricPreferences;
154
186
  - (void)applyUsageDisplayModePreferences;
155
- - (void)toggleImportCodexPets:(NSButton *)sender;
156
187
  - (void)showImportedCodexPetsAlert:(NSUInteger)imported;
157
- - (NSString *)notificationKeyForTag:(NSInteger)tag;
158
188
  - (void)setPanelTheme:(MenuChoiceRowView *)sender;
159
189
  - (void)applyBubbleTextStyle;
160
190
  - (void)setGlassDimLevel:(MenuChoiceRowView *)sender;
161
- - (void)toggleSpeech:(NSButton *)sender;
162
- - (void)togglePetInteraction:(NSButton *)sender;
163
- - (void)setPetInteractionHeartThreshold:(MenuChoiceRowView *)sender;
164
- - (void)setPetInteractionAnnoyedThreshold:(MenuChoiceRowView *)sender;
165
- - (void)setPetInteractionInterval:(MenuChoiceRowView *)sender;
166
- - (void)setSpeechFrequency:(MenuChoiceRowView *)sender;
167
- - (void)setPhrasesSource:(MenuChoiceRowView *)sender;
168
191
  - (void)editPhrasesFile:(id)sender;
169
- - (void)setLanguagePreferenceFromMenu:(NSMenuItem *)sender;
170
192
  - (void)languageDidChange:(NSNotification *)notification;
171
- - (void)toggleNotification:(NSButton *)sender;
172
193
  @end
173
194
 
174
195
  // Agent 状态卡、会话列表、审批与卡住提醒、终端回跳、系统通知
@@ -177,6 +198,7 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
177
198
  - (void)showAgentStatusForRecord:(NSDictionary *)record;
178
199
  - (void)prunePendingApprovalRecords;
179
200
  - (void)toggleStatusBubbleFromMenu:(NSButton *)sender;
201
+ - (void)updateStatusBubbleExpanded:(BOOL)expanded;
180
202
  - (void)sendNotificationWithTitle:(NSString *)title body:(NSString *)body;
181
203
  - (void)notifyForRecord:(NSDictionary *)record;
182
204
  - (NSString *)statusTextForState:(NSString *)state tool:(NSString *)tool;
@@ -195,7 +217,6 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
195
217
  - (NSString *)approvalKeyForRecord:(NSDictionary *)record;
196
218
  - (void)displayAgentRecord:(NSDictionary *)record notify:(BOOL)shouldNotify;
197
219
  - (NSString *)agentSessionKeyForRecord:(NSDictionary *)record;
198
- - (NSString *)onlineAgentSessionKeyForProvider:(NSString *)provider tty:(NSString *)tty;
199
220
  - (NSString *)onlineAgentSessionKeyForRecord:(NSDictionary *)record;
200
221
  - (BOOL)isAgentSessionRecordLive:(NSDictionary *)record;
201
222
  - (void)pruneOfflineAgentSessionRecords;
@@ -230,6 +251,7 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
230
251
  - (void)toggleBridgeWake:(NSButton *)sender;
231
252
  - (void)toggleBridgeEditGuard:(NSButton *)sender;
232
253
  - (void)toggleBridgeBadge:(NSButton *)sender;
254
+ - (void)updateBridgeBadgeEnabled:(BOOL)enabled;
233
255
  - (void)toggleBridgeNotification:(NSButton *)sender;
234
256
  - (void)refreshBridgeState:(NSTimer *)timer;
235
257
  - (void)notifyNewBridgeDeliveries;
@@ -242,9 +264,34 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
242
264
  pending:(NSDictionary<NSString *, NSNumber *> *)pending;
243
265
  @end
244
266
 
267
+ // 用户显式添加、修复或移除 Claude/Codex Home。
268
+ @interface AppDelegate (Profiles)
269
+ - (void)addClaudeProfile:(id)sender;
270
+ - (void)addCodexProfile:(id)sender;
271
+ - (void)repairAgentProfile:(NSMenuItem *)sender;
272
+ - (void)renameAgentProfile:(NSMenuItem *)sender;
273
+ - (void)relocateAgentProfile:(NSMenuItem *)sender;
274
+ - (void)removeAgentProfile:(NSMenuItem *)sender;
275
+ - (void)chooseProfileHomeForProvider:(NSString *)provider;
276
+ - (void)runProfileCommand:(NSArray<NSString *> *)arguments
277
+ title:(NSString *)title completionMessage:(NSString *)completionMessage;
278
+ @end
279
+
280
+ // 主窗口工作台几页的数据快照,见 CCPetsWorkbench.h。
281
+ @interface AppDelegate (Workbench)
282
+ - (NSArray<NSDictionary *> *)workbenchSessions;
283
+ - (NSDictionary *)workbenchMessages;
284
+ - (NSArray<NSDictionary *> *)workbenchQuotas;
285
+ - (void)focusWorkbenchSessionWithID:(NSString *)sessionID;
286
+ - (void)focusBridgeSessionWithID:(NSString *)sessionID;
287
+ - (void)markWorkbenchMessagesSeen;
288
+ @end
289
+
245
290
  // 宠物素材发现、切换与删除
246
291
  @interface AppDelegate (Pets)
247
292
  - (void)switchPetToID:(NSString *)petID;
293
+ - (NSArray<NSDictionary *> *)petPickerOptions;
294
+ - (NSString *)currentPetID;
248
295
  - (BOOL)deletePetWithID:(NSString *)petID;
249
296
  - (NSDictionary *)petManifestInDirectory:(NSString *)directory;
250
297
  - (NSInteger)spriteVersionInDirectory:(NSString *)directory fallbackDirectory:(NSString *)fallbackDirectory;
@@ -307,6 +354,7 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
307
354
  - (void)positionSpeechPanel;
308
355
  - (void)speakWithTag:(NSString *)tag;
309
356
  - (void)presentSpeechText:(NSString *)text;
357
+ - (NSString *)sampleSpeechLine;
310
358
  - (void)restoreStatusDetail;
311
359
  - (void)showSpeechBubbleWithText:(NSString *)text;
312
360
  - (void)showSpeechBubbleWithText:(NSString *)text dwell:(NSTimeInterval)dwell;