cc-pets 2.2.0 → 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 (173) hide show
  1. package/CC_BRIDGE.md +5 -2
  2. package/CC_BRIDGE.zh-CN.md +4 -2
  3. package/CHANGELOG.md +85 -0
  4. package/CHANGELOG.zh-CN.md +85 -0
  5. package/CONTRIBUTING.md +28 -11
  6. package/CONTRIBUTING.zh-CN.md +23 -11
  7. package/README.md +127 -27
  8. package/README.zh-CN.md +104 -30
  9. package/Resources/zh-Hans.lproj/Localizable.strings +573 -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} +89 -31
  12. package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
  13. package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +18 -4
  14. package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +90 -21
  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/App/CCPetsAppDelegate+Settings.m +269 -0
  18. package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +13 -7
  19. package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +71 -47
  20. package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
  21. package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +16 -2
  22. package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +110 -12
  23. package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
  24. package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
  25. package/Sources/CCPets/{main.m → App/main.m} +68 -1
  26. package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
  27. package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +32 -17
  28. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
  29. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +792 -0
  30. package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +60 -0
  31. package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +558 -0
  32. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
  33. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +501 -0
  34. package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +103 -0
  35. package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +779 -0
  36. package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
  37. package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
  38. package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
  39. package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
  40. package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
  41. package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
  42. package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
  43. package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
  44. package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +42 -12
  45. package/Sources/CCPets/Pet/CCPetsImageLoader.h +5 -0
  46. package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +10 -2
  47. package/Sources/CCPets/Pet/CCPetsPetSize.h +10 -0
  48. package/Sources/CCPets/Pet/CCPetsPetSize.m +21 -0
  49. package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
  50. package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
  51. package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +18 -2
  52. package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +53 -22
  53. package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +42 -2
  54. package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
  55. package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
  56. package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
  57. package/Sources/CCPets/Pet/PetView+Private.h +81 -0
  58. package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
  59. package/Sources/CCPets/Pet/PetView.m +635 -0
  60. package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
  61. package/Sources/CCPets/Support/CCPetsDoctor.m +632 -0
  62. package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
  63. package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
  64. package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
  65. package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
  66. package/Sources/CCPets/Support/CCPetsPreferences.h +31 -0
  67. package/Sources/CCPets/Support/CCPetsPreferences.m +85 -0
  68. package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
  69. package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
  70. package/Sources/CCPets/UI/CCPetsFormBuilder.h +42 -0
  71. package/Sources/CCPets/UI/CCPetsFormBuilder.m +268 -0
  72. package/Sources/CCPets/{CCPetsGlassView.h → UI/CCPetsGlassView.h} +5 -1
  73. package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +25 -7
  74. package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
  75. package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
  76. package/Sources/CCPets/UI/CCPetsSettingsPage.h +62 -0
  77. package/Sources/CCPets/UI/CCPetsSettingsPage.m +917 -0
  78. package/Sources/CCPets/UI/CCPetsUIStyle.h +132 -0
  79. package/Sources/CCPets/UI/CCPetsUIStyle.m +816 -0
  80. package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
  81. package/Sources/CCPets/UI/CCPetsUsageChartView.m +284 -0
  82. package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
  83. package/Sources/CCPets/UI/CCPetsUsagePage.m +717 -0
  84. package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
  85. package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
  86. package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
  87. package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
  88. package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
  89. package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
  90. package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
  91. package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +3 -0
  92. package/Sources/CCPets/UI/MenuPetSizeView.h +5 -0
  93. package/Sources/CCPets/UI/MenuPetSizeView.m +73 -0
  94. package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
  95. package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
  96. package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
  97. package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
  98. package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
  99. package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
  100. package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
  101. package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
  102. package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +96 -0
  103. package/Sources/CCPets/Usage/CCPetsUsage+Models.m +285 -0
  104. package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
  105. package/Sources/CCPets/Usage/CCPetsUsage.h +57 -0
  106. package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
  107. package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
  108. package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
  109. package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
  110. package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +163 -6
  111. package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
  112. package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
  113. package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +616 -0
  114. package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
  115. package/Sources/CCPets/Usage/QuotaDashboardView.m +587 -0
  116. package/THIRD_PARTY_NOTICES.md +1 -1
  117. package/THIRD_PARTY_NOTICES.zh-CN.md +1 -1
  118. package/bin/cc-pets +8 -6
  119. package/bin/claude-with-pet +10 -2
  120. package/bin/codex-with-pet +13 -5
  121. package/package.json +1 -1
  122. package/scripts/build.sh +7 -3
  123. package/scripts/i18n.zsh +9 -52
  124. package/scripts/install-app.sh +4 -0
  125. package/scripts/install-shell-integration.sh +17 -10
  126. package/scripts/uninstall-shell-integration.sh +6 -1
  127. package/Sources/CCPets/CCPetsAppDelegate+Settings.m +0 -226
  128. package/Sources/CCPets/CCPetsEvents.h +0 -10
  129. package/Sources/CCPets/CCPetsImageLoader.h +0 -4
  130. package/Sources/CCPets/CCPetsUsage.h +0 -36
  131. package/Sources/CCPets/CCPetsUsage.m +0 -2069
  132. package/Sources/CCPets/PetView.m +0 -1806
  133. package/Sources/CCPets/QuotaDashboardView.m +0 -1145
  134. package/scripts/bridge/cli.mjs +0 -237
  135. package/scripts/bridge/core.mjs +0 -228
  136. package/scripts/bridge/hook.mjs +0 -150
  137. package/scripts/bridge/install.mjs +0 -311
  138. package/scripts/bridge/mcp-server.mjs +0 -308
  139. package/scripts/bridge/options.mjs +0 -87
  140. package/scripts/bridge/process.mjs +0 -151
  141. package/scripts/bridge/reservations.mjs +0 -248
  142. package/scripts/bridge/store.mjs +0 -433
  143. package/scripts/bridge/watch.mjs +0 -69
  144. package/scripts/check-l10n.mjs +0 -168
  145. package/scripts/configure-updater.mjs +0 -43
  146. package/scripts/detect-cli.mjs +0 -68
  147. package/scripts/doctor.mjs +0 -470
  148. package/scripts/i18n.mjs +0 -122
  149. package/scripts/install-claude-hooks.mjs +0 -253
  150. package/scripts/install-codex-hooks.mjs +0 -78
  151. package/scripts/integration-markers.mjs +0 -51
  152. package/scripts/locales/zh-Hans.json +0 -366
  153. package/scripts/pet-store.mjs +0 -415
  154. package/scripts/uninstall-integrations.mjs +0 -205
  155. /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
  156. /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
  157. /package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +0 -0
  158. /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
  159. /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
  160. /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
  161. /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
  162. /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
  163. /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
  164. /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
  165. /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
  166. /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
  167. /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
  168. /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
  169. /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
  170. /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
  171. /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
  172. /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
  173. /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
@@ -7,6 +7,10 @@
7
7
  #import "CCPetsEvents.h"
8
8
  #import "CCPetsQuotaHistory.h"
9
9
  #import "CCPetsImageLoader.h"
10
+ #import "CCPetsPetSize.h"
11
+ #import "CCPetsPreferences.h"
12
+ #import "CCPetsMainWindow.h"
13
+ #import "CCPetsWorkbench.h"
10
14
  #import "CCPetsPhrases.h"
11
15
  #import "CCPetsPhrasesEditor.h"
12
16
  #import "CCPetsUsage.h"
@@ -14,6 +18,7 @@
14
18
  #import "MenuChoiceRow.h"
15
19
  #import "CCPetsGlassMenu.h"
16
20
  #import "CCPetsBridge.h"
21
+ #import "CCPetsProfiles.h"
17
22
  #import "MenuToggleSwitch.h"
18
23
  #import <UserNotifications/UserNotifications.h>
19
24
  #import <signal.h>
@@ -102,6 +107,34 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
102
107
  return ceil(label.fittingSize.width) + 2;
103
108
  }
104
109
 
110
+ // 窗口的 contentView 由 AppKit 管理尺寸,不能直接拿它的 bounds 做缩放。
111
+ // 外壳保持窗口坐标,内部视图独立保留逻辑坐标,统一缩放绘制和命中区域。
112
+ @interface CCPetsBubbleContainerView : NSView
113
+ @end
114
+
115
+ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
116
+ if (!panel) return;
117
+ CGFloat scale = CCPetsBubbleScalePreference();
118
+ NSSize size = NSMakeSize(logicalSize.width * scale, logicalSize.height * scale);
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;
131
+ root.autoresizesSubviews = NO;
132
+ [panel setContentSize:size];
133
+ root.frame = NSMakeRect(0, 0, size.width, size.height);
134
+ root.bounds = NSMakeRect(0, 0, logicalSize.width, logicalSize.height);
135
+ root.needsDisplay = YES;
136
+ }
137
+
105
138
  @interface CCPetsStatusClickButton : NSButton
106
139
  @end
107
140
 
@@ -114,10 +147,13 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
114
147
  @property(nonatomic) NSColor *fillColor;
115
148
  @end
116
149
 
117
- @interface AppDelegate ()
150
+ // 主窗口侧边栏的宠物名片从这里取数据,见 CCPetsMainWindow.h。
151
+ @interface AppDelegate () <CCPetsPetCardSource>
118
152
  - (NSString *)applicationSupportDirectory;
153
+ - (void)notePetCardChanged;
119
154
  - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message;
120
- - (void)installEditMenu;
155
+ - (void)installMainMenu;
156
+ - (void)openMainWindow:(id)sender;
121
157
  - (void)applicationDidFinishLaunching:(NSNotification *)notification;
122
158
  - (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag;
123
159
  - (void)screensDidSleep:(NSNotification *)notification;
@@ -126,29 +162,34 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
126
162
  - (void)applicationWillTerminate:(NSNotification *)notification;
127
163
  @end
128
164
 
129
- // 右键菜单里的各项设置开关
165
+ // 右键菜单里的各项设置开关。setXxx: / toggleXxx: 是菜单控件的 action;updateXxx: 不依赖
166
+ // 控件,写设置并让界面生效,主窗口设置页直接调用。
130
167
  @interface AppDelegate (Settings)
131
- - (void)toggleSystemMetric:(NSButton *)sender;
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;
182
+ - (void)applyPetSizePreference;
183
+ - (void)setPetSizeFromSlider:(NSSlider *)sender;
132
184
  - (void)setUsageDisplayModeFromControl:(NSButton *)sender;
133
- - (NSString *)systemMetricKeyForTag:(NSInteger)tag;
134
185
  - (void)applySystemMetricPreferences;
135
186
  - (void)applyUsageDisplayModePreferences;
136
- - (void)toggleImportCodexPets:(NSButton *)sender;
137
187
  - (void)showImportedCodexPetsAlert:(NSUInteger)imported;
138
- - (NSString *)notificationKeyForTag:(NSInteger)tag;
139
188
  - (void)setPanelTheme:(MenuChoiceRowView *)sender;
140
189
  - (void)applyBubbleTextStyle;
141
190
  - (void)setGlassDimLevel:(MenuChoiceRowView *)sender;
142
- - (void)toggleSpeech:(NSButton *)sender;
143
- - (void)togglePetInteraction:(NSButton *)sender;
144
- - (void)setPetInteractionHeartThreshold:(NSMenuItem *)sender;
145
- - (void)setPetInteractionAnnoyedThreshold:(NSMenuItem *)sender;
146
- - (void)setPetInteractionInterval:(NSMenuItem *)sender;
147
- - (void)setSpeechFrequency:(NSMenuItem *)sender;
148
191
  - (void)editPhrasesFile:(id)sender;
149
- - (void)setLanguagePreferenceFromMenu:(NSMenuItem *)sender;
150
192
  - (void)languageDidChange:(NSNotification *)notification;
151
- - (void)toggleNotification:(NSButton *)sender;
152
193
  @end
153
194
 
154
195
  // Agent 状态卡、会话列表、审批与卡住提醒、终端回跳、系统通知
@@ -157,6 +198,7 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
157
198
  - (void)showAgentStatusForRecord:(NSDictionary *)record;
158
199
  - (void)prunePendingApprovalRecords;
159
200
  - (void)toggleStatusBubbleFromMenu:(NSButton *)sender;
201
+ - (void)updateStatusBubbleExpanded:(BOOL)expanded;
160
202
  - (void)sendNotificationWithTitle:(NSString *)title body:(NSString *)body;
161
203
  - (void)notifyForRecord:(NSDictionary *)record;
162
204
  - (NSString *)statusTextForState:(NSString *)state tool:(NSString *)tool;
@@ -175,7 +217,6 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
175
217
  - (NSString *)approvalKeyForRecord:(NSDictionary *)record;
176
218
  - (void)displayAgentRecord:(NSDictionary *)record notify:(BOOL)shouldNotify;
177
219
  - (NSString *)agentSessionKeyForRecord:(NSDictionary *)record;
178
- - (NSString *)onlineAgentSessionKeyForProvider:(NSString *)provider tty:(NSString *)tty;
179
220
  - (NSString *)onlineAgentSessionKeyForRecord:(NSDictionary *)record;
180
221
  - (BOOL)isAgentSessionRecordLive:(NSDictionary *)record;
181
222
  - (void)pruneOfflineAgentSessionRecords;
@@ -210,6 +251,7 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
210
251
  - (void)toggleBridgeWake:(NSButton *)sender;
211
252
  - (void)toggleBridgeEditGuard:(NSButton *)sender;
212
253
  - (void)toggleBridgeBadge:(NSButton *)sender;
254
+ - (void)updateBridgeBadgeEnabled:(BOOL)enabled;
213
255
  - (void)toggleBridgeNotification:(NSButton *)sender;
214
256
  - (void)refreshBridgeState:(NSTimer *)timer;
215
257
  - (void)notifyNewBridgeDeliveries;
@@ -222,9 +264,34 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
222
264
  pending:(NSDictionary<NSString *, NSNumber *> *)pending;
223
265
  @end
224
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
+
225
290
  // 宠物素材发现、切换与删除
226
291
  @interface AppDelegate (Pets)
227
292
  - (void)switchPetToID:(NSString *)petID;
293
+ - (NSArray<NSDictionary *> *)petPickerOptions;
294
+ - (NSString *)currentPetID;
228
295
  - (BOOL)deletePetWithID:(NSString *)petID;
229
296
  - (NSDictionary *)petManifestInDirectory:(NSString *)directory;
230
297
  - (NSInteger)spriteVersionInDirectory:(NSString *)directory fallbackDirectory:(NSString *)fallbackDirectory;
@@ -287,6 +354,7 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
287
354
  - (void)positionSpeechPanel;
288
355
  - (void)speakWithTag:(NSString *)tag;
289
356
  - (void)presentSpeechText:(NSString *)text;
357
+ - (NSString *)sampleSpeechLine;
290
358
  - (void)restoreStatusDetail;
291
359
  - (void)showSpeechBubbleWithText:(NSString *)text;
292
360
  - (void)showSpeechBubbleWithText:(NSString *)text dwell:(NSTimeInterval)dwell;
@@ -305,16 +373,17 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
305
373
  - (void)retryUpdate:(NSArray *)context;
306
374
  - (void)startUpdateToVersion:(NSString *)version attempt:(NSInteger)attempt;
307
375
  - (void)showAboutPanel:(id)sender;
308
- - (void)fetchLatestReleaseWithCompletion:(void (^)(NSString *version, NSArray<NSString *> *highlights,
309
- BOOL highlightsTruncated, NSString *errorMessage))completion;
376
+ - (void)fetchLatestReleaseWithCompletion:(void (^)(NSString *version, NSString *notes,
377
+ NSString *errorMessage))completion;
378
+ - (void)fetchReleaseNotesForVersion:(NSString *)version sourceIndex:(NSUInteger)index
379
+ completion:(void (^)(NSString *body))completion;
310
380
  - (void)checkForUpdates:(id)sender;
311
381
  - (void)showPendingUpdate:(id)sender;
312
382
  - (void)silentCheckForUpdate;
313
- - (void)rememberPendingUpdate:(NSString *)version highlights:(NSArray<NSString *> *)highlights
314
- truncated:(BOOL)truncated;
383
+ - (void)rememberPendingUpdate:(NSString *)version notes:(NSString *)notes;
315
384
  - (void)refreshUpdateBadge;
316
385
  - (void)clearPendingUpdate;
317
- - (NSView *)updateHighlightsAccessoryView;
386
+ - (NSView *)updateHighlightsAccessoryView:(NSArray<NSString *> *)highlights truncated:(BOOL)truncated;
318
387
  - (void)showUpdateDialog;
319
388
  - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
320
389
  - (void)applyUpdateBadgeStyle;
@@ -0,0 +1,238 @@
1
+ #import "CCPetsAppDelegate+Private.h"
2
+ #import "CCPetsCLISupport.h"
3
+
4
+ @implementation AppDelegate (Profiles)
5
+
6
+ - (void)addClaudeProfile:(id)sender {
7
+ [self chooseProfileHomeForProvider:CCPetsProfileProviderClaude];
8
+ }
9
+
10
+ - (void)addCodexProfile:(id)sender {
11
+ [self chooseProfileHomeForProvider:CCPetsProfileProviderCodex];
12
+ }
13
+
14
+ // 设置页的按钮在命令执行期间仍可点,被挡下时要告诉用户,不能悄悄什么都不做。
15
+ - (BOOL)rejectWhileProfileCommandRunning {
16
+ if (!self.profileCommandRunning) return NO;
17
+ [self showAlertWithTitle:L(@"Agent Profile Setup") message:L(@"Another Agent profile is still being configured.")];
18
+ return YES;
19
+ }
20
+
21
+ - (void)chooseProfileHomeForProvider:(NSString *)provider {
22
+ if ([self rejectWhileProfileCommandRunning]) return;
23
+ NSOpenPanel *panel = [NSOpenPanel openPanel];
24
+ panel.canChooseDirectories = YES;
25
+ panel.canChooseFiles = NO;
26
+ panel.allowsMultipleSelection = NO;
27
+ panel.canCreateDirectories = NO;
28
+ panel.showsHiddenFiles = YES;
29
+ panel.prompt = L(@"Choose Home");
30
+ panel.message = [provider isEqualToString:CCPetsProfileProviderClaude]
31
+ ? L(@"Choose an existing Claude Home folder, such as ~/.claude-work.")
32
+ : L(@"Choose an existing Codex Home folder, such as ~/.codex-work.");
33
+ panel.directoryURL = [NSURL fileURLWithPath:CCPetsHomeDirectory() isDirectory:YES];
34
+ [NSApp activateIgnoringOtherApps:YES];
35
+ if ([panel runModal] != NSModalResponseOK) return;
36
+ NSString *home = panel.URL.path;
37
+ if (!CCPetsProfileHomeMatchesProvider(provider, home)) {
38
+ [self showAlertWithTitle:L(@"This folder doesn't look like an Agent Home")
39
+ message:[provider isEqualToString:CCPetsProfileProviderClaude]
40
+ ? L(@"Choose a folder containing Claude settings, state, or projects.")
41
+ : L(@"Choose a folder containing Codex config, hooks, or sign-in state.")];
42
+ return;
43
+ }
44
+ NSString *name = CCPetsProfileDefaultDisplayName(provider, home);
45
+ NSAlert *confirm = [NSAlert new];
46
+ confirm.messageText = [NSString stringWithFormat:L(@"Integrate %@?"), name];
47
+ NSString *bridge = CCBridgeEnabled()
48
+ ? L(@"Pet Hooks, usage collection, CC Bridge Hooks, permissions, and MCP will be configured.")
49
+ : L(@"Pet Hooks and usage collection will be configured. CC Bridge will be added automatically if you enable it later.");
50
+ confirm.informativeText = [NSString stringWithFormat:@"%@\n\n%@", CCPetsTildePath(home), bridge];
51
+ [confirm addButtonWithTitle:L(@"Start Setup")];
52
+ [confirm addButtonWithTitle:L(@"Cancel")];
53
+ if ([confirm runModal] != NSAlertFirstButtonReturn) return;
54
+ // 首次名称只是 Home 文件夹名,不算用户自定义;这样以后重新定位 Home 时,
55
+ // 未主动重命名的账号名称仍会跟随新的文件夹名。
56
+ [self runProfileCommand:@[@"add", @"--provider", provider, @"--home", home]
57
+ title:[NSString stringWithFormat:L(@"Configuring %@"), name]
58
+ completionMessage:[provider isEqualToString:CCPetsProfileProviderClaude]
59
+ ? L(@"The Claude Home is integrated. Restart Claude to load newly registered MCP tools.")
60
+ : L(@"The Codex Home is integrated. Restart Codex, then trust the CC Pets hooks in /hooks.")];
61
+ }
62
+
63
+ - (void)repairAgentProfile:(NSMenuItem *)sender {
64
+ NSString *profileID = [sender.representedObject isKindOfClass:NSString.class] ? sender.representedObject : nil;
65
+ NSDictionary *profile = CCPetsProfileWithID(profileID);
66
+ if (!profile || [self rejectWhileProfileCommandRunning]) return;
67
+ [self runProfileCommand:@[@"repair", @"--id", profileID]
68
+ title:[NSString stringWithFormat:L(@"Repairing %@"), profile[@"displayName"]]
69
+ completionMessage:L(@"The Agent profile integration was repaired.")];
70
+ }
71
+
72
+ - (void)renameAgentProfile:(NSMenuItem *)sender {
73
+ NSString *profileID = [sender.representedObject isKindOfClass:NSString.class] ? sender.representedObject : nil;
74
+ NSDictionary *profile = CCPetsProfileWithID(profileID);
75
+ if (!profile || [self rejectWhileProfileCommandRunning]) return;
76
+ NSAlert *alert = [NSAlert new];
77
+ alert.messageText = L(@"Rename Agent Profile");
78
+ alert.informativeText = L(@"This changes only the name shown in CC Pets.");
79
+ NSTextField *field = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
80
+ field.stringValue = profile[@"displayName"] ?: @"";
81
+ alert.accessoryView = field;
82
+ [alert addButtonWithTitle:L(@"Save")];
83
+ [alert addButtonWithTitle:L(@"Cancel")];
84
+ if ([alert runModal] != NSAlertFirstButtonReturn) return;
85
+ NSString *name = [field.stringValue stringByTrimmingCharactersInSet:
86
+ NSCharacterSet.whitespaceAndNewlineCharacterSet];
87
+ if (name.length == 0) return;
88
+ [self runProfileCommand:@[@"update", @"--id", profileID, @"--name", name]
89
+ title:[NSString stringWithFormat:L(@"Updating %@"), name]
90
+ completionMessage:L(@"The Agent profile name was updated.")];
91
+ }
92
+
93
+ - (void)relocateAgentProfile:(NSMenuItem *)sender {
94
+ NSString *profileID = [sender.representedObject isKindOfClass:NSString.class] ? sender.representedObject : nil;
95
+ NSDictionary *profile = CCPetsProfileWithID(profileID);
96
+ if (!profile || [self rejectWhileProfileCommandRunning]) return;
97
+ NSOpenPanel *panel = [NSOpenPanel openPanel];
98
+ panel.canChooseDirectories = YES;
99
+ panel.canChooseFiles = NO;
100
+ panel.allowsMultipleSelection = NO;
101
+ panel.canCreateDirectories = NO;
102
+ panel.showsHiddenFiles = YES;
103
+ panel.prompt = L(@"Choose Home");
104
+ panel.message = L(@"Choose the new location for this Agent Home.");
105
+ panel.directoryURL = [NSURL fileURLWithPath:profile[@"home"] isDirectory:YES];
106
+ [NSApp activateIgnoringOtherApps:YES];
107
+ if ([panel runModal] != NSModalResponseOK) return;
108
+ NSString *home = panel.URL.path;
109
+ if (!CCPetsProfileHomeMatchesProvider(profile[@"provider"], home)) {
110
+ [self showAlertWithTitle:L(@"This folder doesn't look like an Agent Home")
111
+ message:L(@"Choose a folder containing the selected Agent's settings or state.")];
112
+ return;
113
+ }
114
+ [self runProfileCommand:@[@"update", @"--id", profileID, @"--home", home]
115
+ title:[NSString stringWithFormat:L(@"Relocating %@"), profile[@"displayName"]]
116
+ completionMessage:L(@"The Agent Home was relocated and its integration was updated.")];
117
+ }
118
+
119
+ - (void)removeAgentProfile:(NSMenuItem *)sender {
120
+ NSString *profileID = [sender.representedObject isKindOfClass:NSString.class] ? sender.representedObject : nil;
121
+ NSDictionary *profile = CCPetsProfileWithID(profileID);
122
+ if (!profile || [self rejectWhileProfileCommandRunning]) return;
123
+ NSAlert *confirm = [NSAlert new];
124
+ confirm.alertStyle = NSAlertStyleWarning;
125
+ confirm.messageText = [NSString stringWithFormat:L(@"Remove integration for %@?"), profile[@"displayName"]];
126
+ confirm.informativeText = L(@"Only CC Pets-managed Hooks, usage integration, Bridge settings, and the profile card will be removed. The Agent Home, login, and session history will be kept.");
127
+ [confirm addButtonWithTitle:L(@"Remove Integration")];
128
+ [confirm addButtonWithTitle:L(@"Cancel")];
129
+ if ([confirm runModal] != NSAlertFirstButtonReturn) return;
130
+ [self runProfileCommand:@[@"remove", @"--id", profileID]
131
+ title:[NSString stringWithFormat:L(@"Removing %@"), profile[@"displayName"]]
132
+ completionMessage:L(@"The CC Pets integration was removed. The Agent Home and its data were kept.")];
133
+ }
134
+
135
+ - (void)showProfileProgressWithTitle:(NSString *)title {
136
+ NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 360, 112)
137
+ styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:NO];
138
+ window.title = L(@"Agent Profile Setup");
139
+ window.releasedWhenClosed = NO;
140
+ NSTextField *label = [NSTextField labelWithString:title ?: L(@"Configuring Agent profile…")];
141
+ label.frame = NSMakeRect(24, 57, 312, 24);
142
+ label.font = [NSFont systemFontOfSize:13 weight:NSFontWeightMedium];
143
+ label.lineBreakMode = NSLineBreakByTruncatingMiddle;
144
+ NSProgressIndicator *indicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(24, 28, 312, 16)];
145
+ indicator.style = NSProgressIndicatorStyleBar;
146
+ indicator.indeterminate = YES;
147
+ [window.contentView addSubview:label];
148
+ [window.contentView addSubview:indicator];
149
+ [indicator startAnimation:nil];
150
+ [window center];
151
+ [window makeKeyAndOrderFront:nil];
152
+ [NSApp activateIgnoringOtherApps:YES];
153
+ self.profileProgressWindow = window;
154
+ self.profileProgressLabel = label;
155
+ self.profileProgressIndicator = indicator;
156
+ }
157
+
158
+ - (void)updateProfileProgressForText:(NSString *)text fallback:(NSString *)fallback {
159
+ NSDictionary<NSString *, NSString *> *stages = @{
160
+ @"stage=registered": L(@"Profile registered…"),
161
+ @"stage=hooks": L(@"Installing Pet Hooks and usage collection…"),
162
+ @"stage=bridge": L(@"Configuring CC Bridge and MCP…"),
163
+ @"stage=verify": L(@"Verifying integration…")
164
+ };
165
+ __block NSString *message = fallback;
166
+ [stages enumerateKeysAndObjectsUsingBlock:^(NSString *stage, NSString *label, BOOL *stop) {
167
+ if ([text containsString:stage]) message = label;
168
+ }];
169
+ dispatch_async(dispatch_get_main_queue(), ^{ self.profileProgressLabel.stringValue = message; });
170
+ }
171
+
172
+ - (void)runProfileCommand:(NSArray<NSString *> *)arguments
173
+ title:(NSString *)title completionMessage:(NSString *)completionMessage {
174
+ if (self.profileCommandRunning) return;
175
+ self.profileCommandRunning = YES;
176
+ [self showProfileProgressWithTitle:title];
177
+ NSTask *task = [NSTask new];
178
+ task.executableURL = [NSURL fileURLWithPath:CCPetsExecutablePath()];
179
+ task.arguments = [@[@"profile"] arrayByAddingObjectsFromArray:arguments];
180
+ NSMutableDictionary<NSString *, NSString *> *environment = [NSProcessInfo.processInfo.environment mutableCopy];
181
+ NSDictionary *locator = CCBridgeCLILocator();
182
+ NSString *path = locator[@"path"];
183
+ if (path.length == 0) path = CCPetsLoginShellPath();
184
+ if (path.length > 0) environment[@"PATH"] = path;
185
+ task.environment = environment;
186
+ NSPipe *pipe = [NSPipe pipe];
187
+ task.standardOutput = pipe;
188
+ task.standardError = pipe;
189
+ __block NSMutableData *captured = [NSMutableData data];
190
+ __weak typeof(self) weakSelf = self;
191
+ pipe.fileHandleForReading.readabilityHandler = ^(NSFileHandle *handle) {
192
+ NSData *data = handle.availableData;
193
+ if (data.length == 0) return;
194
+ @synchronized (captured) { [captured appendData:data]; }
195
+ NSString *chunk = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ?: @"";
196
+ [weakSelf updateProfileProgressForText:chunk fallback:title];
197
+ };
198
+ task.terminationHandler = ^(NSTask *finished) {
199
+ pipe.fileHandleForReading.readabilityHandler = nil;
200
+ NSData *tail = [pipe.fileHandleForReading readDataToEndOfFile];
201
+ @synchronized (captured) { if (tail.length > 0) [captured appendData:tail]; }
202
+ NSString *output = [[NSString alloc] initWithData:captured encoding:NSUTF8StringEncoding] ?: @"";
203
+ dispatch_async(dispatch_get_main_queue(), ^{
204
+ typeof(self) strongSelf = weakSelf;
205
+ if (!strongSelf) return;
206
+ [strongSelf.profileProgressIndicator stopAnimation:nil];
207
+ [strongSelf.profileProgressWindow close];
208
+ strongSelf.profileProgressWindow = nil;
209
+ strongSelf.profileProgressLabel = nil;
210
+ strongSelf.profileProgressIndicator = nil;
211
+ strongSelf.profileTask = nil;
212
+ strongSelf.profileCommandRunning = NO;
213
+ // 子进程即使适配失败也可能已经更新注册表,让打开的设置页同步账号。
214
+ [NSNotificationCenter.defaultCenter postNotificationName:CCPetsProfilesDidChangeNotification object:nil];
215
+ if (finished.terminationStatus == EXIT_SUCCESS) {
216
+ [strongSelf refreshUsage:nil];
217
+ [strongSelf showAlertWithTitle:L(@"Agent Profile Ready") message:completionMessage];
218
+ } else {
219
+ NSString *detail = [output stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
220
+ [strongSelf showAlertWithTitle:L(@"Agent Profile Setup Failed")
221
+ message:detail.length > 0 ? detail : L(@"The command failed.")];
222
+ }
223
+ });
224
+ };
225
+ NSError *error = nil;
226
+ if (![task launchAndReturnError:&error]) {
227
+ pipe.fileHandleForReading.readabilityHandler = nil;
228
+ self.profileCommandRunning = NO;
229
+ [self.profileProgressIndicator stopAnimation:nil];
230
+ [self.profileProgressWindow close];
231
+ self.profileProgressWindow = nil;
232
+ [self showAlertWithTitle:L(@"Agent Profile Setup Failed") message:error.localizedDescription];
233
+ return;
234
+ }
235
+ self.profileTask = task;
236
+ }
237
+
238
+ @end
@@ -1,26 +1,6 @@
1
1
  // 额度面板、用量刷新与系统指标。
2
2
  #import "CCPetsAppDelegate+Private.h"
3
-
4
- // 额度字典"非空"不等于"这家真的在用"。Claude 的 reader 刻意永不返回 nil(见
5
- // CCPetsUsage.m 里 -[ClaudeUsageReader refresh] 的注释:Token 是本机从转录数出来的,
6
- // 不能被缺失的官方额度一票否决),什么都没有时照样返回
7
- // {fiveHour: NSNull, week: NSNull, tokenUsage: 全 0},count 恒为 3。
8
- // 拿 count > 0 当证据,Claude 就永远算"检测到",卡片再也去不掉。这里只认实质证据:
9
- // 官方额度块真实存在,或者本机统计出过非零 Token。Codex 侧同一套判据也成立。
10
- static BOOL UsageShowsProviderInUse(NSDictionary *usage) {
11
- if (usage.count == 0) return NO;
12
- for (NSString *key in @[@"fiveHour", @"week"]) {
13
- if ([usage[key] isKindOfClass:NSDictionary.class]) return YES;
14
- }
15
- NSDictionary *tokenUsage = [usage[@"tokenUsage"] isKindOfClass:NSDictionary.class]
16
- ? usage[@"tokenUsage"] : nil;
17
- for (NSString *key in @[@"fiveHour", @"week", @"today", @"recentWeek"]) {
18
- NSDictionary *totals = [tokenUsage[key] isKindOfClass:NSDictionary.class]
19
- ? tokenUsage[key] : nil;
20
- if ([totals[@"total_tokens"] doubleValue] > 0) return YES;
21
- }
22
- return NO;
23
- }
3
+ #import "CCPetsWorkbench.h"
24
4
 
25
5
  @implementation AppDelegate (Quota)
26
6
  - (void)rescheduleUsageTimer {
@@ -149,19 +129,44 @@ static BOOL UsageShowsProviderInUse(NSDictionary *usage) {
149
129
  // 还要挂满一整个静默窗口。额度数据本身不是在线信号——它一直缓存着,用它判定会恒亮。
150
130
  - (void)updateQuotaLiveState {
151
131
  NSMutableSet<NSString *> *online = [self.liveClientProviders mutableCopy] ?: [NSMutableSet set];
132
+ NSMutableSet<NSString *> *onlineProfiles = [self.liveClientProfileIDs mutableCopy]
133
+ ?: [NSMutableSet set];
134
+ NSMutableSet<NSString *> *unscopedProviders = [self.liveUnscopedClientProviders mutableCopy]
135
+ ?: [NSMutableSet set];
136
+ NSMutableSet<NSString *> *approvalProfiles = [NSMutableSet set];
152
137
  NSTimeInterval now = NSDate.date.timeIntervalSince1970;
153
138
  for (NSString *provider in self.providerActivityAt) {
154
139
  NSTimeInterval last = [self.providerActivityAt[provider] doubleValue];
155
140
  if (now - last < AgentStatusInactivityInterval) [online addObject:provider];
156
141
  }
142
+ for (NSDictionary *record in self.agentSessionRecords.allValues) {
143
+ NSString *profileID = [record[@"profileId"] isKindOfClass:NSString.class]
144
+ ? record[@"profileId"] : nil;
145
+ if (![self isAgentSessionRecordLive:record]) continue;
146
+ if (profileID.length > 0) {
147
+ [onlineProfiles addObject:profileID];
148
+ if ([record[@"state"] isEqualToString:@"approval"]) [approvalProfiles addObject:profileID];
149
+ } else {
150
+ NSString *provider = [record[@"provider"] isKindOfClass:NSString.class]
151
+ ? record[@"provider"] : nil;
152
+ if (provider.length > 0) [unscopedProviders addObject:provider];
153
+ }
154
+ }
157
155
  NSInteger count = MAX(self.liveClientCount, (NSInteger)online.count);
158
156
  if (self.quotaView.activeAgentCount == count &&
159
157
  [self.quotaView.liveProviders isEqualToSet:online] &&
158
+ [self.quotaView.liveProfileIDs isEqualToSet:onlineProfiles] &&
159
+ [self.quotaView.liveUnscopedProviders isEqualToSet:unscopedProviders] &&
160
+ [self.quotaView.pendingApprovalProfileIDs isEqualToSet:approvalProfiles] &&
160
161
  self.quotaView.hasUnlabeledClient == self.hasUnlabeledClient) return;
161
162
  self.quotaView.activeAgentCount = count;
162
163
  self.quotaView.liveProviders = online;
164
+ self.quotaView.liveProfileIDs = onlineProfiles;
165
+ self.quotaView.liveUnscopedProviders = unscopedProviders;
166
+ self.quotaView.pendingApprovalProfileIDs = approvalProfiles;
163
167
  self.quotaView.hasUnlabeledClient = self.hasUnlabeledClient;
164
168
  self.quotaView.needsDisplay = YES;
169
+ [NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
165
170
  }
166
171
  // 面板高度取决于渲染几张额度卡。调整玻璃容器后,内部内容随 autoresizingMask 铺满。
167
172
  - (void)resizeQuotaDashboard {
@@ -178,19 +183,21 @@ static BOOL UsageShowsProviderInUse(NSDictionary *usage) {
178
183
  self.quotaView.needsDisplay = YES;
179
184
  if (self.quotaPanel.isVisible) [self positionQuotaDashboard];
180
185
  }
181
- // "这台机器上有哪几家 CLI"。只增不减,并持久化:探测会瞬时失败(配置目录被改名、
182
- // 外置盘没挂上),卡片当着用户的面消失比多留一张更像 bug。
186
+ // 卡片来自自动登记的官方 Home 与用户明确登记的自定义 Home。自定义目录不会被扫描;
187
+ // 目录暂时不可用时 profile 仍留在注册表,所以卡片也不会抖动消失。
183
188
  - (void)refreshDetectedProviders {
189
+ // 运行期间后来安装 CLI、或首次生成官方 Home 时也应自动出现卡片;只检查两个
190
+ // 官方路径,自定义 Home 仍必须从主窗口的多账号页手动添加。
191
+ NSString *profileError = nil;
192
+ if (!CCPetsEnsureOfficialDefaultProfiles(&profileError) && profileError.length > 0) {
193
+ fprintf(stderr, "%s\n", profileError.UTF8String);
194
+ }
184
195
  NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
185
- NSMutableSet<NSString *> *detected = [NSMutableSet setWithArray:
186
- [defaults arrayForKey:DetectedProvidersKey] ?: @[]];
187
- if (CodexCLIDetected()) [detected addObject:@"Codex"];
188
- if (ClaudeCLIDetected()) [detected addObject:@"Claude"];
189
- // 正在跑的客户端和已经拿到的额度数据都是比目录探测更硬的证据:探测漏判也不能
190
- // 把一个正在工作、或者明明有额度的 provider 藏起来。
191
- if (self.liveClientProviders.count > 0) [detected unionSet:self.liveClientProviders];
192
- if (UsageShowsProviderInUse(self.quotaView.codexUsage)) [detected addObject:@"Codex"];
193
- if (UsageShowsProviderInUse(self.quotaView.claudeUsage)) [detected addObject:@"Claude"];
196
+ NSMutableSet<NSString *> *detected = [NSMutableSet set];
197
+ for (NSDictionary *profile in CCPetsProfiles()) {
198
+ if ([profile[@"provider"] isEqualToString:CCPetsProfileProviderCodex]) [detected addObject:@"Codex"];
199
+ if ([profile[@"provider"] isEqualToString:CCPetsProfileProviderClaude]) [detected addObject:@"Claude"];
200
+ }
194
201
  if (self.quotaView.detectedProviders &&
195
202
  [detected isEqualToSet:self.quotaView.detectedProviders]) return;
196
203
  self.quotaView.detectedProviders = detected;
@@ -204,10 +211,18 @@ static BOOL UsageShowsProviderInUse(NSDictionary *usage) {
204
211
  [self refreshDetectedProviders];
205
212
  NSDictionary *history = RecordQuotaHistory(self.quotaView.codexUsage,
206
213
  self.quotaView.claudeUsage);
214
+ history = RecordProfileQuotaHistory(self.usageMonitor.profileUsages, self.usageMonitor.profiles);
215
+ NSMutableDictionary *profileHistories = [NSMutableDictionary dictionary];
216
+ for (NSDictionary *profile in self.usageMonitor.profiles) {
217
+ NSString *profileID = profile[@"id"];
218
+ if (profileID.length > 0) profileHistories[profileID] = QuotaHistorySeriesForProfile(history, profileID);
219
+ }
220
+ self.quotaView.profileHistories = profileHistories;
207
221
  self.quotaView.codexHistory = QuotaHistorySeries(history, @"codex");
208
222
  self.quotaView.claudeHistory = QuotaHistorySeries(history, @"claude");
209
223
  self.quotaView.lastUpdatedAt = NSDate.date.timeIntervalSince1970;
210
224
  self.quotaView.needsDisplay = YES;
225
+ [NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
211
226
  }
212
227
  - (void)refreshUsage:(id)sender {
213
228
  self.lastUsageRefreshAt = NSDate.date.timeIntervalSince1970;