cc-pets 2.5.0 → 2.6.0-beta.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 (92) hide show
  1. package/CC_BRIDGE.md +47 -5
  2. package/CC_BRIDGE.zh-CN.md +42 -5
  3. package/CONTRIBUTING.md +1 -1
  4. package/CONTRIBUTING.zh-CN.md +1 -1
  5. package/README.md +48 -19
  6. package/README.zh-CN.md +46 -17
  7. package/Resources/AgentIcons/antigravity.icns +0 -0
  8. package/Resources/zh-Hans.lproj/Localizable.strings +64 -15
  9. package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +7 -3
  10. package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +11 -3
  11. package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +16 -5
  12. package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +11 -1
  13. package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +21 -11
  14. package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +27 -16
  15. package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +43 -7
  16. package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +2 -1
  17. package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +3 -3
  18. package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +20 -22
  19. package/Sources/CCPets/App/CCPetsAppDelegate.m +14 -6
  20. package/Sources/CCPets/App/CCPetsVersion.h +4 -0
  21. package/Sources/CCPets/App/CCPetsVersion.m +34 -0
  22. package/Sources/CCPets/App/main.m +11 -0
  23. package/Sources/CCPets/Bridge/CCPetsBridge.m +7 -5
  24. package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.h +4 -0
  25. package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.m +119 -0
  26. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +3 -1
  27. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +172 -17
  28. package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +25 -7
  29. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +17 -0
  30. package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +7 -2
  31. package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +92 -11
  32. package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.h +12 -0
  33. package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.m +105 -0
  34. package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.h +17 -0
  35. package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.m +462 -0
  36. package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.h +5 -0
  37. package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.m +180 -0
  38. package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.h +3 -0
  39. package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.m +463 -0
  40. package/Sources/CCPets/Integrations/CCPetsIntegrations.h +1 -1
  41. package/Sources/CCPets/Integrations/CCPetsIntegrations.m +37 -7
  42. package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +15 -5
  43. package/Sources/CCPets/Integrations/CCPetsProfiles.h +2 -1
  44. package/Sources/CCPets/Integrations/CCPetsProfiles.m +112 -81
  45. package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +5 -1
  46. package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +163 -40
  47. package/Sources/CCPets/Pet/CCPetsPreviews.m +16 -8
  48. package/Sources/CCPets/Pet/PetView+Menu.m +56 -5
  49. package/Sources/CCPets/Support/CCPetsDoctor.m +126 -37
  50. package/Sources/CCPets/Support/CCPetsPaths.h +5 -0
  51. package/Sources/CCPets/Support/CCPetsPaths.m +15 -0
  52. package/Sources/CCPets/Support/CCPetsPreferences.h +4 -1
  53. package/Sources/CCPets/Support/CCPetsPreferences.m +18 -0
  54. package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +10 -5
  55. package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +9 -6
  56. package/Sources/CCPets/UI/CCPetsSettingsPage.h +3 -0
  57. package/Sources/CCPets/UI/CCPetsSettingsPage.m +189 -8
  58. package/Sources/CCPets/UI/CCPetsUIStyle.m +3 -1
  59. package/Sources/CCPets/UI/CCPetsUsagePage.h +4 -3
  60. package/Sources/CCPets/UI/CCPetsUsagePage.m +69 -43
  61. package/Sources/CCPets/UI/CCPetsUsageStore.m +11 -1
  62. package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +1 -1
  63. package/Sources/CCPets/Usage/CCPetsAntigravityQuota.m +115 -0
  64. package/Sources/CCPets/Usage/CCPetsNormalizedUsage.h +5 -0
  65. package/Sources/CCPets/Usage/CCPetsNormalizedUsage.m +43 -0
  66. package/Sources/CCPets/Usage/CCPetsProviderRegistry+Testing.h +13 -0
  67. package/Sources/CCPets/Usage/CCPetsProviderRegistry.h +25 -0
  68. package/Sources/CCPets/Usage/CCPetsProviderRegistry.m +94 -0
  69. package/Sources/CCPets/Usage/CCPetsQuotaHistory.h +1 -1
  70. package/Sources/CCPets/Usage/CCPetsQuotaHistory.m +11 -8
  71. package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +2 -0
  72. package/Sources/CCPets/Usage/CCPetsUsage+Models.m +206 -14
  73. package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +4 -4
  74. package/Sources/CCPets/Usage/CCPetsUsage.h +7 -2
  75. package/Sources/CCPets/Usage/CCPetsUsageMode.h +2 -0
  76. package/Sources/CCPets/Usage/CCPetsUsageMode.m +29 -4
  77. package/Sources/CCPets/Usage/CCPetsUsageMonitor.h +4 -4
  78. package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +90 -7
  79. package/Sources/CCPets/Usage/QuotaDashboardView+CompactRow.m +81 -0
  80. package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +5 -8
  81. package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +26 -4
  82. package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +99 -99
  83. package/Sources/CCPets/Usage/QuotaDashboardView.h +9 -10
  84. package/Sources/CCPets/Usage/QuotaDashboardView.m +232 -79
  85. package/THIRD_PARTY_NOTICES.md +5 -4
  86. package/THIRD_PARTY_NOTICES.zh-CN.md +6 -5
  87. package/bin/agy-with-pet +82 -0
  88. package/bin/cc-pets +1 -1
  89. package/bin/claude-with-pet +15 -0
  90. package/bin/codex-with-pet +17 -2
  91. package/package.json +5 -3
  92. package/scripts/install-shell-integration.sh +5 -0
@@ -1,6 +1,8 @@
1
1
  // 额度面板、用量刷新与系统指标。
2
2
  #import "CCPetsAppDelegate+Private.h"
3
+ #import "CCPetsBridgeStore.h"
3
4
  #import "CCPetsWorkbench.h"
5
+ #import "CCPetsProviderRegistry.h"
4
6
 
5
7
  @implementation AppDelegate (Quota)
6
8
  - (void)rescheduleUsageTimer {
@@ -125,9 +127,7 @@
125
127
  [self updateSystemMetricsTimer];
126
128
  }
127
129
  }
128
- // 在线判定合并两个信号:包装脚本写出的客户端 pid 文件,以及该 provider 最近是否还在
129
- // 发事件。只看前者会把直接跑 claude / codex 的会话误判成离线;只看后者则在客户端退出后
130
- // 还要挂满一整个静默窗口。额度数据本身不是在线信号——它一直缓存着,用它判定会恒亮。
130
+ // 在线判定合并托管 CLI 进程、最近的 Agent 事件和桌面端运行状态。额度缓存不参与判定。
131
131
  - (void)updateQuotaLiveState {
132
132
  NSMutableSet<NSString *> *online = [self.liveClientProviders mutableCopy] ?: [NSMutableSet set];
133
133
  NSMutableSet<NSString *> *onlineProfiles = [self.liveClientProfileIDs mutableCopy]
@@ -136,6 +136,13 @@
136
136
  ?: [NSMutableSet set];
137
137
  NSMutableSet<NSString *> *approvalProfiles = [NSMutableSet set];
138
138
  NSInteger desktopSessions = 0;
139
+ if (AntigravityDesktopApplicationIsRunning()) {
140
+ [online addObject:CCBridgeAntigravityAppProvider];
141
+ desktopSessions += 1;
142
+ NSDictionary *profile = CCPetsProfileForHome(CCPetsProfileProviderAntigravity, DefaultAntigravityAppConfigDirectory());
143
+ NSString *profileID = profile[@"id"];
144
+ if (profileID.length > 0) [onlineProfiles addObject:profileID];
145
+ }
139
146
  NSTimeInterval now = NSDate.date.timeIntervalSince1970;
140
147
  for (NSString *provider in self.providerActivityAt) {
141
148
  NSTimeInterval last = [self.providerActivityAt[provider] doubleValue];
@@ -175,9 +182,11 @@
175
182
  }
176
183
  // 面板高度取决于渲染几张额度卡。调整玻璃容器后,内部内容随 autoresizingMask 铺满。
177
184
  - (void)resizeQuotaDashboard {
178
- NSSize size = NSMakeSize(QuotaLogicalWidth * QuotaScale,
179
- QuotaLogicalHeightForProviderCount([self.quotaView visibleProviders].count) * QuotaScale);
180
- if (NSEqualSizes(self.quotaPanel.frame.size, size)) return;
185
+ NSSize size = NSMakeSize(QuotaLogicalWidth * QuotaScale, [self.quotaView logicalHeight] * QuotaScale);
186
+ if (NSEqualSizes(self.quotaPanel.frame.size, size)) {
187
+ [self.quotaView refreshQuotaCardLayout];
188
+ return;
189
+ }
181
190
  // 只改 size 不动 origin:窗口 frame 的原点在左下,面板会朝上收缩,底边保持贴着宠物。
182
191
  NSRect frame = self.quotaPanel.frame;
183
192
  frame.size = size;
@@ -185,7 +194,7 @@
185
194
  NSRect bounds = NSMakeRect(0, 0, size.width, size.height);
186
195
  self.quotaPanel.contentView.frame = bounds;
187
196
  for (NSView *subview in self.quotaPanel.contentView.subviews) subview.frame = bounds;
188
- self.quotaView.needsDisplay = YES;
197
+ [self.quotaView refreshQuotaCardLayout];
189
198
  if (self.quotaPanel.isVisible) [self positionQuotaDashboard];
190
199
  }
191
200
  // 卡片来自自动登记的官方 Home 与用户明确登记的自定义 Home。自定义目录不会被扫描;
@@ -200,8 +209,8 @@
200
209
  NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
201
210
  NSMutableSet<NSString *> *detected = [NSMutableSet set];
202
211
  for (NSDictionary *profile in CCPetsProfiles()) {
203
- if ([profile[@"provider"] isEqualToString:CCPetsProfileProviderCodex]) [detected addObject:@"Codex"];
204
- if ([profile[@"provider"] isEqualToString:CCPetsProfileProviderClaude]) [detected addObject:@"Claude"];
212
+ CCPetsProviderDescriptor *provider = CCPetsProviderForProfileProvider(profile[@"provider"]);
213
+ if (provider) [detected addObject:provider.name];
205
214
  }
206
215
  if (self.quotaView.detectedProviders &&
207
216
  [detected isEqualToSet:self.quotaView.detectedProviders]) return;
@@ -210,12 +219,11 @@
210
219
  [self resizeQuotaDashboard];
211
220
  self.quotaView.needsDisplay = YES;
212
221
  }
213
- - (void)applyCodexUsage:(NSDictionary *)codexUsage claudeUsage:(NSDictionary *)claudeUsage {
214
- self.quotaView.codexUsage = codexUsage;
215
- self.quotaView.claudeUsage = claudeUsage;
222
+ - (void)applyUsageByProvider:(NSDictionary<NSString *, NSDictionary *> *)usageByProvider {
223
+ self.quotaView.usageByProvider = usageByProvider;
216
224
  [self refreshDetectedProviders];
217
- NSDictionary *history = RecordQuotaHistory(self.quotaView.codexUsage,
218
- self.quotaView.claudeUsage);
225
+ [self resizeQuotaDashboard];
226
+ NSDictionary *history = RecordQuotaHistory(self.quotaView.usageByProvider);
219
227
  history = RecordProfileQuotaHistory(self.usageMonitor.profileUsages, self.usageMonitor.profiles);
220
228
  NSMutableDictionary *profileHistories = [NSMutableDictionary dictionary];
221
229
  for (NSDictionary *profile in self.usageMonitor.profiles) {
@@ -223,8 +231,11 @@
223
231
  if (profileID.length > 0) profileHistories[profileID] = QuotaHistorySeriesForProfile(history, profileID);
224
232
  }
225
233
  self.quotaView.profileHistories = profileHistories;
226
- self.quotaView.codexHistory = QuotaHistorySeries(history, @"codex");
227
- self.quotaView.claudeHistory = QuotaHistorySeries(history, @"claude");
234
+ NSMutableDictionary *historyByProvider = [NSMutableDictionary dictionary];
235
+ for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
236
+ historyByProvider[provider.name] = QuotaHistorySeries(history, provider.key);
237
+ }
238
+ self.quotaView.historyByProvider = historyByProvider;
228
239
  self.quotaView.lastUpdatedAt = NSDate.date.timeIntervalSince1970;
229
240
  self.quotaView.needsDisplay = YES;
230
241
  [NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
@@ -6,6 +6,7 @@
6
6
  #import "CCPetsAppDelegate+Private.h"
7
7
  #import "CCPetsUsageMode.h"
8
8
  #import "CCPetsWorkbench.h"
9
+ #import "CCPetsProviderRegistry.h"
9
10
 
10
11
  @implementation AppDelegate (Settings)
11
12
  - (void)setPetSizeFromSlider:(NSSlider *)sender {
@@ -48,12 +49,43 @@
48
49
  }
49
50
  - (void)applyUsageDisplayModePreferences {
50
51
  NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
51
- self.quotaView.codexShowsAPIUsage =
52
- [[defaults stringForKey:CodexUsageDisplayModeKey] isEqualToString:@"api"];
53
- self.quotaView.claudeShowsAPIUsage =
54
- [[defaults stringForKey:ClaudeUsageDisplayModeKey] isEqualToString:@"api"];
52
+ NSMutableDictionary *showsAPIUsageByProvider = [NSMutableDictionary dictionary];
53
+ for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
54
+ showsAPIUsageByProvider[provider.name] =
55
+ @([[defaults stringForKey:provider.usageDisplayModeDefaultsKey] isEqualToString:@"api"]);
56
+ }
57
+ self.quotaView.showsAPIUsageByProvider = showsAPIUsageByProvider;
55
58
  self.quotaView.needsDisplay = YES;
56
59
  }
60
+ - (NSArray<NSString *> *)quotaCardOrderForSettings {
61
+ return [self.quotaView orderedQuotaProviderKeys] ?: @[];
62
+ }
63
+ - (void)updateQuotaCardOrder:(NSArray<NSString *> *)order {
64
+ if (order.count == 0) {
65
+ CCPetsPrefSetObject(CCPetsQuotaCardOrderKey, nil);
66
+ [self.quotaView refreshQuotaCardLayout];
67
+ return;
68
+ }
69
+ NSArray<NSString *> *visible = [self quotaCardOrderForSettings];
70
+ NSSet<NSString *> *visibleKeys = [NSSet setWithArray:visible];
71
+ NSArray<NSString *> *requested = CCPetsPrefNormalizedValue(CCPetsQuotaCardOrderKey, order);
72
+ if (requested.count == 0) return;
73
+ NSMutableOrderedSet<NSString *> *reordered = [NSMutableOrderedSet orderedSetWithArray:requested];
74
+ [reordered intersectSet:visibleKeys];
75
+ [reordered addObjectsFromArray:visible];
76
+ if ([reordered.array isEqualToArray:visible]) return;
77
+
78
+ // Keep the previous slots for known cards that are absent from the current panel.
79
+ NSSet<NSString *> *knownKeys = [NSSet setWithArray:[CCPetsProviderDescriptors() valueForKey:@"key"]];
80
+ NSMutableArray<NSString *> *saved = [NSMutableArray array];
81
+ NSUInteger next = 0;
82
+ for (NSString *key in CCPetsQuotaCardOrder()) {
83
+ if (![knownKeys containsObject:key]) continue;
84
+ [saved addObject:[visibleKeys containsObject:key] ? reordered[next++] : key];
85
+ }
86
+ while (next < reordered.count) [saved addObject:reordered[next++]];
87
+ if (CCPetsPrefSetObject(CCPetsQuotaCardOrderKey, saved)) [self.quotaView refreshQuotaCardLayout];
88
+ }
57
89
  - (void)setUsageDisplayModeFromControl:(NSButton *)sender {
58
90
  if (sender.identifier.length > 0) {
59
91
  NSDictionary *profile = CCPetsProfileWithID(sender.identifier);
@@ -65,14 +97,18 @@
65
97
  return;
66
98
  }
67
99
  NSString *key = sender.tag == 1 ? CodexUsageDisplayModeKey
68
- : (sender.tag == 2 ? ClaudeUsageDisplayModeKey : nil);
100
+ : (sender.tag == 2 ? ClaudeUsageDisplayModeKey
101
+ : (sender.tag == 3 ? AntigravityUsageDisplayModeKey : nil));
69
102
  NSString *mode = sender.state == NSControlStateValueOn ? @"api" : @"subscription";
70
103
  if (!key) return;
71
104
  [self updateUsageDisplayMode:mode forKey:key];
72
105
  }
73
106
  - (void)updateUsageDisplayMode:(NSString *)mode forKey:(NSString *)key {
74
- if (![@[CodexUsageDisplayModeKey, ClaudeUsageDisplayModeKey] containsObject:key] ||
75
- ![@[@"api", @"subscription"] containsObject:mode]) return;
107
+ NSMutableSet<NSString *> *providerKeys = [NSMutableSet set];
108
+ for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
109
+ if (provider.usageDisplayModeDefaultsKey.length > 0) [providerKeys addObject:provider.usageDisplayModeDefaultsKey];
110
+ }
111
+ if (![providerKeys containsObject:key] || ![@[@"api", @"subscription"] containsObject:mode]) return;
76
112
  CCPetsPrefSetObject(key, mode);
77
113
  [self applyUsageDisplayModePreferences];
78
114
  // 展示模式决定了会话要回溯多远(订阅 8 天 / API 到上月月初),切换之后必须重新聚合,
@@ -1,5 +1,6 @@
1
1
  // 说话气泡与碎碎念。
2
2
  #import "CCPetsAppDelegate+Private.h"
3
+ #import "CCPetsProviderRegistry.h"
3
4
  #import "CCPetsUsageMode.h"
4
5
 
5
6
  // 档位写进 defaults 的键;PetView 的右键菜单也要读它。
@@ -187,7 +188,7 @@ static NSString *SpeechQuotaResetTime(NSDictionary *usage) {
187
188
  NSDictionary *slots = [self speechSlotsWithTool:self.lastSpeechTool usage:usages[profileID]];
188
189
  NSString *text = PetPhraseForTag(PetPhraseTagQuotaLow, slots);
189
190
  if (text.length == 0) continue;
190
- NSString *provider = [profile[@"provider"] isEqualToString:CCPetsProfileProviderCodex] ? @"Codex" : @"Claude";
191
+ NSString *provider = CCPetsProviderForProfileProvider(profile[@"provider"]).name ?: profile[@"provider"];
191
192
  NSString *name = profile[@"displayName"] ?: profile[@"slug"] ?: provider;
192
193
  text = [NSString stringWithFormat:@"%@ · %@: %@", provider, name, text];
193
194
  NSTimeInterval now = NSDate.date.timeIntervalSince1970;
@@ -218,7 +218,7 @@ static void TrimUpdateLog(NSString *path) {
218
218
  NSString *latestVersion = [metadata isKindOfClass:NSDictionary.class] &&
219
219
  [metadata[@"version"] isKindOfClass:NSString.class] ? metadata[@"version"] : nil;
220
220
  BOOL valid = NO;
221
- NSComparisonResult comparison = CompareStableVersions(@CC_PETS_VERSION, latestVersion, &valid);
221
+ NSComparisonResult comparison = CompareInstalledVersionToRelease(@CC_PETS_VERSION, latestVersion, &valid);
222
222
  if (error || httpResponse.statusCode != 200 || !valid) {
223
223
  NSString *message = error.localizedDescription ?: L(@"The npm registry returned invalid version info. Please try again later.");
224
224
  dispatch_async(dispatch_get_main_queue(), ^{ completion(nil, nil, message); });
@@ -290,7 +290,7 @@ static void TrimUpdateLog(NSString *path) {
290
290
  return;
291
291
  }
292
292
  BOOL valid = NO;
293
- if (CompareStableVersions(@CC_PETS_VERSION, version, &valid) != NSOrderedAscending) {
293
+ if (CompareInstalledVersionToRelease(@CC_PETS_VERSION, version, &valid) != NSOrderedAscending) {
294
294
  [strongSelf clearPendingUpdate];
295
295
  [strongSelf showAlertWithTitle:L(@"You're Up to Date")
296
296
  message:[NSString stringWithFormat:L(@"Version %@"), @CC_PETS_VERSION]];
@@ -319,7 +319,7 @@ static void TrimUpdateLog(NSString *path) {
319
319
  strongSelf.checkingForUpdate = NO;
320
320
  if (errorMessage || strongSelf.updating) return;
321
321
  BOOL valid = NO;
322
- if (CompareStableVersions(@CC_PETS_VERSION, version, &valid) != NSOrderedAscending) {
322
+ if (CompareInstalledVersionToRelease(@CC_PETS_VERSION, version, &valid) != NSOrderedAscending) {
323
323
  [strongSelf clearPendingUpdate];
324
324
  return;
325
325
  }
@@ -5,6 +5,7 @@
5
5
  #import "CCPetsBridgeStore.h"
6
6
  #import "CCPetsDiagnosticsPage.h"
7
7
  #import "CCPetsUsageMode.h"
8
+ #import "CCPetsProviderRegistry.h"
8
9
 
9
10
  NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWorkbenchQuotasDidChange";
10
11
 
@@ -16,7 +17,8 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
16
17
  NSMutableArray<NSDictionary *> *sessions = [NSMutableArray array];
17
18
  for (NSString *key in self.agentSessionRecords) {
18
19
  NSDictionary *record = self.agentSessionRecords[key];
19
- NSString *provider = SanitizedShortString(record[@"provider"], 32).lowercaseString;
20
+ NSString *provider = SanitizedShortString(record[@"provider"], 32);
21
+ NSString *providerKey = provider.lowercaseString;
20
22
  // 和状态气泡一致:启动后一直没有后续事件,说明会话已就绪、在等输入。
21
23
  NSString *state = SessionDisplayState([record[@"state"] isKindOfClass:NSString.class]
22
24
  ? record[@"state"] : @"", [record[@"timestamp"] doubleValue], NSDate.date.timeIntervalSince1970);
@@ -24,8 +26,8 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
24
26
  NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class] ? record[@"terminal"] : nil;
25
27
  NSMutableDictionary *session = [NSMutableDictionary dictionary];
26
28
  session[@"id"] = key;
27
- session[@"provider"] = [provider isEqualToString:@"claude"] ? @"Claude"
28
- : ([provider isEqualToString:@"codex"] ? @"Codex" : (provider.length > 0 ? provider : @"Agent"));
29
+ session[@"provider"] = [providerKey isEqualToString:@"claude"] ? @"Claude"
30
+ : ([providerKey isEqualToString:@"codex"] ? @"Codex" : (provider.length > 0 ? provider : @"Agent"));
29
31
  if ([record[@"profileId"] isKindOfClass:NSString.class]) session[@"profileId"] = record[@"profileId"];
30
32
  if ([record[@"profileName"] isKindOfClass:NSString.class]) session[@"profileName"] = record[@"profileName"];
31
33
  session[@"state"] = state;
@@ -75,11 +77,13 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
75
77
 
76
78
  - (NSArray<NSDictionary *> *)workbenchQuotas {
77
79
  NSMutableArray<NSDictionary *> *quotas = [NSMutableArray array];
78
- // 平台次序和悬停面板一致,但概览同时列出全部账号,不跟随轮播选择。
79
- for (NSString *provider in [self.quotaView visibleProviders]) {
80
+ // 工作台展示已检测的平台和全部账号,也包含不进入悬停面板的平台。
81
+ for (CCPetsProviderDescriptor *descriptor in CCPetsProviderDescriptors()) {
82
+ NSString *provider = descriptor.name;
83
+ if (self.quotaView.detectedProviders && ![self.quotaView.detectedProviders containsObject:provider]) continue;
80
84
  NSMutableArray<NSDictionary *> *profiles = [NSMutableArray array];
81
85
  for (NSDictionary *profile in self.quotaView.profiles ?: CCPetsProfiles()) {
82
- if ([profile[@"provider"] isEqualToString:provider.lowercaseString]) [profiles addObject:profile];
86
+ if ([profile[@"provider"] isEqualToString:descriptor.profileProvider]) [profiles addObject:profile];
83
87
  }
84
88
  // 未登记账号时保留旧版的平台卡片。
85
89
  if (profiles.count == 0) [profiles addObject:@{}];
@@ -87,24 +91,18 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
87
91
  NSString *profileID = profile[@"id"];
88
92
  NSMutableDictionary *quota = [[self.quotaView accountSnapshotForProvider:provider
89
93
  profile:profile.count > 0 ? profile : nil] mutableCopy];
90
- NSDictionary *usage = quota[@"usage"];
91
- NSString *usedKey = [provider isEqualToString:@"Claude"] ? @"used_percentage" : @"used_percent";
92
- NSNumber *weekUsed = nil;
93
- for (NSArray<NSString *> *window in @[@[@"fiveHour", @"five"], @[@"week", @"week"]]) {
94
- NSDictionary *limit = [usage[window[0]] isKindOfClass:NSDictionary.class] ? usage[window[0]] : nil;
95
- NSNumber *used = [limit[usedKey] isKindOfClass:NSNumber.class] ? limit[usedKey] : nil;
96
- if (used) {
97
- double clamped = fmax(0, fmin(100, used.doubleValue));
98
- quota[[window[1] stringByAppendingString:@"Remaining"]] = @(100 - clamped);
99
- if ([window[1] isEqualToString:@"week"]) weekUsed = @(clamped);
100
- }
101
- if ([limit[@"resets_at"] isKindOfClass:NSNumber.class]) {
102
- quota[[window[1] stringByAppendingString:@"Reset"]] = limit[@"resets_at"];
103
- }
94
+ NSArray *windows = quota[@"normalized"][@"windows"];
95
+ for (NSDictionary *window in windows) {
96
+ NSString *key = window[@"key"];
97
+ NSString *prefix = [key isEqualToString:@"fiveHour"] ? @"five" : key;
98
+ NSNumber *used = window[@"used"];
99
+ if (used) quota[[prefix stringByAppendingString:@"Remaining"]] = @(100 - used.doubleValue);
100
+ NSNumber *reset = window[@"quota"][@"resets_at"];
101
+ if ([reset isKindOfClass:NSNumber.class]) quota[[prefix stringByAppendingString:@"Reset"]] = reset;
104
102
  }
105
103
  if (![quota[@"apiMode"] boolValue]) {
106
- NSDictionary *week = [usage[@"week"] isKindOfClass:NSDictionary.class] ? usage[@"week"] : nil;
107
- NSDictionary *pace = [self.quotaView paceStatusForQuota:week currentUsed:weekUsed color:NSColor.systemTealColor];
104
+ NSDictionary *pace = [self.quotaView paceStatusForWindow:CCPetsTrendWindow(windows)
105
+ color:NSColor.systemTealColor];
108
106
  if (pace[@"level"]) {
109
107
  quota[@"pace"] = pace[@"label"];
110
108
  quota[@"paceLevel"] = pace[@"level"];
@@ -2,6 +2,7 @@
2
2
  // 共享常量和跨文件的方法声明见 CCPetsAppDelegate+Private.h。
3
3
  #import "CCPetsAppDelegate+Private.h"
4
4
  #import "CCPetsOpenCommand.h"
5
+ #import "CCPetsProviderRegistry.h"
5
6
 
6
7
  @implementation CCPetsBubbleContainerView
7
8
  @end
@@ -219,7 +220,8 @@
219
220
  NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
220
221
  [defaults registerDefaults:@{StatusBubbleExpandedKey: @YES,
221
222
  CodexUsageDisplayModeKey: @"subscription",
222
- ClaudeUsageDisplayModeKey: @"subscription"}];
223
+ ClaudeUsageDisplayModeKey: @"subscription",
224
+ AntigravityUsageDisplayModeKey: @"subscription"}];
223
225
  [defaults registerDefaults:@{
224
226
  SystemCPUEnabledKey: @YES,
225
227
  SystemTemperatureEnabledKey: @YES,
@@ -258,7 +260,8 @@
258
260
  self.panel.backgroundColor = NSColor.clearColor;
259
261
  self.panel.hasShadow = NO;
260
262
  self.panel.level = NSFloatingWindowLevel;
261
- self.panel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorFullScreenAuxiliary;
263
+ self.panel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces |
264
+ NSWindowCollectionBehaviorFullScreenAuxiliary | NSWindowCollectionBehaviorCanJoinAllApplications;
262
265
  // 与 1.0 一致:透明背景交给 AppKit 原生拖动;PetView 通过
263
266
  // mouseDownCanMoveWindow=NO 保留自己的点击和奔跑动画拖动,两条路径按命中区隔离。
264
267
  self.panel.movableByWindowBackground = YES;
@@ -466,12 +469,17 @@
466
469
  self.quotaView.cardScrimAlpha = CCPetsGlassCardScrimAlpha();
467
470
  [self applySystemMetricPreferences];
468
471
  [self applyUsageDisplayModePreferences];
469
- self.quotaView.codexLogo = OfficialAppIcon(@"com.openai.codex", @"icon-chatgpt.icns");
470
- self.quotaView.claudeLogo = OfficialAppIcon(@"com.anthropic.claudefordesktop", @"electron.icns");
472
+ NSMutableDictionary *logoByProvider = [NSMutableDictionary dictionary];
473
+ for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
474
+ NSImage *logo = OfficialAppIcon(provider.logoBundleIdentifier, provider.logoResourceName);
475
+ if (logo) logoByProvider[provider.name] = logo;
476
+ }
477
+ self.quotaView.logoByProvider = logoByProvider;
471
478
  self.quotaView.hoverChanged = ^(BOOL hovering) {
472
479
  weakSelf.dashboardHovering = hovering;
473
480
  if (!hovering) [weakSelf scheduleQuotaDashboardHide];
474
481
  };
482
+ self.quotaView.layoutChanged = ^{ [weakSelf resizeQuotaDashboard]; };
475
483
  [self.quotaGlass.contentView addSubview:self.quotaView];
476
484
  self.quotaPanel.contentView = quotaRoot;
477
485
  // 先探测再第一次显示:否则面板会先按两张卡的高度弹出来再收缩一下。
@@ -489,10 +497,10 @@
489
497
  self.agentEventPartialLine = [NSMutableData data];
490
498
  self.pendingApprovalRecords = [NSMutableDictionary dictionary];
491
499
  self.stallNotifiedSessionKeys = [NSMutableSet set];
492
- self.usageMonitor.changeHandler = ^(NSDictionary *codexUsage, NSDictionary *claudeUsage) {
500
+ self.usageMonitor.changeHandler = ^(NSDictionary<NSString *, NSDictionary *> *usageByProvider) {
493
501
  weakSelf.quotaView.profiles = weakSelf.usageMonitor.profiles;
494
502
  weakSelf.quotaView.profileUsages = weakSelf.usageMonitor.profileUsages;
495
- [weakSelf applyCodexUsage:codexUsage claudeUsage:claudeUsage];
503
+ [weakSelf applyUsageByProvider:usageByProvider];
496
504
  [weakSelf considerQuotaSpeech];
497
505
  };
498
506
  [self.usageMonitor start];
@@ -7,6 +7,10 @@
7
7
  // 只接受严格的三段纯数字版本号;valid 为 NO 时返回值无意义。
8
8
  // 自动更新会把比较结果作为是否升级的唯一依据,所以这里刻意不接受预发布号。
9
9
  NSComparisonResult CompareStableVersions(NSString *left, NSString *right, BOOL *valid);
10
+ // 应用内更新用:本机版本可以是预览版(X.Y.Z-beta.0 这类 semver 预发布号),npm 的 latest
11
+ // 仍必须是严格的正式版,误发成 latest 的预发布号会被当作无效,不会推给正式版用户。
12
+ // 预览版低于同号正式版:2.6.0-beta.0 < 2.6.0。
13
+ NSComparisonResult CompareInstalledVersionToRelease(NSString *installed, NSString *release, BOOL *valid);
10
14
  int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed);
11
15
 
12
16
  // npm 安装日志里是否只是暂时性故障(值得自动重试一次),而不是真的装不上。
@@ -36,6 +36,40 @@ NSComparisonResult CompareStableVersions(NSString *left, NSString *right, BOOL *
36
36
  return NSOrderedSame;
37
37
  }
38
38
 
39
+ // semver 预发布号:点分隔的标识符,只含字母数字和连字符;纯数字标识符不许有前导零。
40
+ static BOOL ValidPrerelease(NSString *prerelease) {
41
+ if (prerelease.length == 0 || prerelease.length > 64) return NO;
42
+ NSCharacterSet *allowed = [NSCharacterSet characterSetWithCharactersInString:
43
+ @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"];
44
+ NSCharacterSet *nonDigits = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"].invertedSet;
45
+ for (NSString *identifier in [prerelease componentsSeparatedByString:@"."]) {
46
+ if (identifier.length == 0 || [identifier rangeOfCharacterFromSet:allowed.invertedSet].location != NSNotFound) return NO;
47
+ BOOL numeric = [identifier rangeOfCharacterFromSet:nonDigits].location == NSNotFound;
48
+ if (numeric && identifier.length > 1 && [identifier hasPrefix:@"0"]) return NO;
49
+ }
50
+ return YES;
51
+ }
52
+
53
+ NSComparisonResult CompareInstalledVersionToRelease(NSString *installed, NSString *release, BOOL *valid) {
54
+ BOOL parsed = NO;
55
+ if (valid) *valid = NO;
56
+ if (![installed isKindOfClass:NSString.class]) return NSOrderedSame;
57
+ NSString *core = installed;
58
+ NSString *prerelease = nil;
59
+ NSRange dash = [installed rangeOfString:@"-"];
60
+ if (dash.location != NSNotFound) {
61
+ core = [installed substringToIndex:dash.location];
62
+ prerelease = [installed substringFromIndex:NSMaxRange(dash)];
63
+ if (!ValidPrerelease(prerelease)) return NSOrderedSame;
64
+ }
65
+ NSComparisonResult comparison = CompareStableVersions(core, release, &parsed);
66
+ if (!parsed) return NSOrderedSame;
67
+ if (valid) *valid = YES;
68
+ // latest 只会是正式版,预览版只需和同号正式版分出先后。
69
+ if (comparison == NSOrderedSame && prerelease) return NSOrderedAscending;
70
+ return comparison;
71
+ }
72
+
39
73
  int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed) {
40
74
  for (NSUInteger attempt = 0; attempt < 300; attempt++) {
41
75
  if (pid <= 1 || (kill(pid, 0) != 0 && errno == ESRCH)) break;
@@ -2,6 +2,7 @@
2
2
  #import <Cocoa/Cocoa.h>
3
3
  #import "CCPetsAppDelegate.h"
4
4
  #import "CCPetsEvents.h"
5
+ #import "CCPetsAntigravityEvents.h"
5
6
  #import "CCPetsPaths.h"
6
7
  #import "CCPetsPhrases.h"
7
8
  #import "CCPetsPreviews.h"
@@ -11,6 +12,7 @@
11
12
  #import "CCPetsCleanup.h"
12
13
  #import "CCPetsIntegrations.h"
13
14
  #import "CCPetsBridgeCLI.h"
15
+ #import "CCPetsBridgeTerminalTitle.h"
14
16
  #import "CCPetsDoctor.h"
15
17
  #import "CCPetsOpenCommand.h"
16
18
  #import "CCPetsPetStore.h"
@@ -27,6 +29,9 @@ int main(int argc, const char *argv[]) {
27
29
  @autoreleasepool {
28
30
  // 下面这些都是命令行入口,输出语言跟终端走;真正启动桌宠前再切回 App 的语言规则。
29
31
  CCPetsUseCommandLineLanguage(YES);
32
+ if (argc > 1 && strcmp(argv[1], "--agy-bridge-title") == 0) {
33
+ return CCBridgePrintAntigravityTitle(argc > 2 ? @(argv[2]) : nil);
34
+ }
30
35
  if (argc > 1 && strcmp(argv[1], "--launch-preflight") == 0) {
31
36
  NSMutableArray<NSString *> *arguments = [NSMutableArray array];
32
37
  for (int index = 3; index < argc; index++) [arguments addObject:@(argv[index])];
@@ -93,6 +98,12 @@ int main(int argc, const char *argv[]) {
93
98
  return RestartAfterPID(pid, appPath, managed);
94
99
  }
95
100
  if (argc > 1 && strcmp(argv[1], "--hook") == 0) return RecordHookEvent();
101
+ if (argc == 3 && strcmp(argv[1], "--agy-hook") == 0) return CCPetsRecordAntigravityHook(@(argv[2]));
102
+ if (argc == 2 && strcmp(argv[1], "--agy-status-line") == 0) return CCPetsRecordAntigravityStatusLine();
103
+ if (argc == 2 && strcmp(argv[1], "--agy-launch") == 0) {
104
+ CCPetsRegisterAntigravityTerminalClient(getppid());
105
+ return EXIT_SUCCESS;
106
+ }
96
107
  if (argc > 1 && strcmp(argv[1], "--frontmost-bundle-id") == 0) {
97
108
  puts(FrontmostApplicationBundleIdentifier().UTF8String);
98
109
  return EXIT_SUCCESS;
@@ -116,10 +116,9 @@ static NSDictionary *ReadJSONObject(NSString *path) {
116
116
  return [object isKindOfClass:NSDictionary.class] ? object : nil;
117
117
  }
118
118
 
119
- // 只有 JSON 里明确写着 false 才算关;0、缺省、其他类型都按开处理。
120
- static BOOL IsJSONFalse(id value) {
119
+ static BOOL IsJSONBoolean(id value, BOOL expected) {
121
120
  return [value isKindOfClass:NSNumber.class] &&
122
- CFGetTypeID((__bridge CFTypeRef)value) == CFBooleanGetTypeID() && ![value boolValue];
121
+ CFGetTypeID((__bridge CFTypeRef)value) == CFBooleanGetTypeID() && [value boolValue] == expected;
123
122
  }
124
123
 
125
124
  NSDictionary *CCBridgeNormalizeOptions(NSDictionary *raw) {
@@ -127,9 +126,12 @@ NSDictionary *CCBridgeNormalizeOptions(NSDictionary *raw) {
127
126
  return @{
128
127
  @"codexApprove": KnownTools(raw[@"codexApprove"]),
129
128
  @"claudeAllow": KnownTools(raw[@"claudeAllow"]),
129
+ @"antigravityAllow": KnownTools(raw[@"antigravityAllow"]),
130
+ @"antigravityApp": IsJSONBoolean(raw[@"antigravityApp"], YES) ? @YES : @NO,
131
+ @"tabTitle": IsJSONBoolean(raw[@"tabTitle"], YES) ? @YES : @NO,
130
132
  // 必须是 @YES / @NO(CFBoolean):写回开关文件时要落成 JSON 的 true / false,而不是 1 / 0。
131
- @"wake": IsJSONFalse(raw[@"wake"]) ? @NO : @YES,
132
- @"editGuard": IsJSONFalse(raw[@"editGuard"]) ? @NO : @YES
133
+ @"wake": IsJSONBoolean(raw[@"wake"], NO) ? @NO : @YES,
134
+ @"editGuard": IsJSONBoolean(raw[@"editGuard"], NO) ? @NO : @YES
133
135
  };
134
136
  }
135
137
 
@@ -0,0 +1,4 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ extern NSString *const CCBridgeAntigravityAppWakePrompt;
4
+ int CCBridgeRunAntigravityAppSidecar(void);
@@ -0,0 +1,119 @@
1
+ #import "CCPetsBridgeAntigravityApp.h"
2
+
3
+ #import "CCPetsBridge.h"
4
+ #import "CCPetsBridgeStore.h"
5
+ #import "CCPetsCLISupport.h"
6
+ #import <signal.h>
7
+ #import <stdio.h>
8
+ #import <unistd.h>
9
+
10
+ NSString *const CCBridgeAntigravityAppWakePrompt = @"[cc-bridge inbox] A teammate message is waiting in the local CC Bridge inbox. Read the message context supplied by the hook and handle it within this session’s permissions. If there is no supplied message, stop without taking any action.";
11
+
12
+ static volatile sig_atomic_t SidecarStopping;
13
+
14
+ static void StopSidecar(int signalNumber) {
15
+ (void)signalNumber;
16
+ SidecarStopping = 1;
17
+ }
18
+
19
+ static BOOL WakeEnabled(void) {
20
+ NSDictionary *options = CCBridgeOptions();
21
+ return [options[@"antigravityApp"] boolValue] && [options[@"wake"] boolValue];
22
+ }
23
+
24
+ static BOOL IsHostedConversation(NSDictionary *session, NSNumber *hostPID) {
25
+ return [session[@"provider"] isEqual:CCBridgeAntigravityAppProvider] &&
26
+ [CCBridgeSessionHostPID(session) isEqual:hostPID] && ![session[@"status"] isEqual:@"gone"];
27
+ }
28
+
29
+ // The oldest pending ID remains unchanged as later messages arrive. After Antigravity
30
+ // accepts a nudge, leave that batch to its hook and allow a new nudge only after it advances.
31
+ static void WakeIdleConversations(NSString *agentAPI, NSNumber *hostPID,
32
+ NSMutableDictionary<NSString *, NSDictionary *> *attempts) {
33
+ NSMutableSet<NSString *> *active = [NSMutableSet set];
34
+ for (NSDictionary *session in CCBridgeListSessions()) {
35
+ if (SidecarStopping) return;
36
+ if (!IsHostedConversation(session, hostPID)) continue;
37
+ NSString *sessionID = CCBridgeSafeSessionId(session[@"session"]);
38
+ if (!sessionID || ![[NSUUID alloc] initWithUUIDString:sessionID]) continue;
39
+
40
+ NSString *firstPending = CCBridgeOldestPendingMessageName(sessionID);
41
+ if (!firstPending) continue;
42
+ [active addObject:sessionID];
43
+ if (![session[@"status"] isEqual:@"idle"]) continue;
44
+
45
+ NSDictionary *previous = attempts[sessionID];
46
+ BOOL sameBatch = [firstPending isEqual:previous[@"firstPending"]];
47
+ if (sameBatch && [previous[@"accepted"] boolValue]) continue;
48
+ NSTimeInterval now = NSProcessInfo.processInfo.systemUptime;
49
+ if (sameBatch && now < [previous[@"retryAt"] doubleValue]) continue;
50
+
51
+ // A human prompt may have started after listing sessions. Recheck immediately
52
+ // before calling App's transport and leave inbox claims to PreInvocation.
53
+ NSDictionary *target = CCBridgeReadSession(sessionID);
54
+ if (!IsHostedConversation(target, hostPID) || ![target[@"status"] isEqual:@"idle"] ||
55
+ !CCBridgeSessionLive(target) || ![firstPending isEqual:CCBridgeOldestPendingMessageName(sessionID)] ||
56
+ SidecarStopping || !WakeEnabled()) continue;
57
+
58
+ int status = CCPetsRun(agentAPI, @[@"send-message", sessionID, CCBridgeAntigravityAppWakePrompt],
59
+ nil, nil, 5, nil, nil);
60
+ if (status == 0) {
61
+ attempts[sessionID] = @{@"firstPending": firstPending, @"accepted": @YES};
62
+ } else {
63
+ NSTimeInterval delay = sameBatch ? MIN(60, 2 * [previous[@"delay"] doubleValue]) : 2;
64
+ // A timeout may have happened after acceptance. Give the hook time to
65
+ // consume the batch before retrying an unconfirmed call.
66
+ if (status == CCPetsRunTimedOut) delay = 60;
67
+ attempts[sessionID] = @{@"firstPending": firstPending, @"delay": @(delay),
68
+ @"retryAt": @(NSProcessInfo.processInfo.systemUptime + delay)};
69
+ }
70
+ }
71
+ for (NSString *sessionID in attempts.allKeys) {
72
+ if (![active containsObject:sessionID]) [attempts removeObjectForKey:sessionID];
73
+ }
74
+ }
75
+
76
+ int CCBridgeRunAntigravityAppSidecar(void) {
77
+ pid_t parent = getppid();
78
+ NSDictionary *ancestor = CCBridgeFindAgentAncestor(parent);
79
+ NSNumber *hostPID = ancestor[@"pid"];
80
+ NSString *dataDirectory = CCPetsEnvironmentValue(@"ANTIGRAVITY_EXECUTABLE_DATA_DIR");
81
+ NSString *agentAPI = CCPetsFindRealExecutable(@"agentapi", nil);
82
+ if (![ancestor[@"provider"] isEqual:CCBridgeAntigravityAppProvider] || hostPID.intValue <= 1 ||
83
+ !dataDirectory.isAbsolutePath || !agentAPI.isAbsolutePath) {
84
+ fputs("cc-pets: agy-app-sidecar requires an Antigravity App-managed Sidecar and agentapi.\n", stderr);
85
+ return 0;
86
+ }
87
+
88
+ NSString *lock = nil;
89
+ struct sigaction action = {0};
90
+ struct sigaction previousInterrupt = {0}, previousTerminate = {0}, previousHangup = {0};
91
+ action.sa_handler = StopSidecar;
92
+ sigemptyset(&action.sa_mask);
93
+ SidecarStopping = 0;
94
+ sigaction(SIGINT, &action, &previousInterrupt);
95
+ sigaction(SIGTERM, &action, &previousTerminate);
96
+ sigaction(SIGHUP, &action, &previousHangup);
97
+ @try {
98
+ NSString *lockName = [NSString stringWithFormat:@"agy-app-sidecar-%@", hostPID];
99
+ NSMutableDictionary<NSString *, NSDictionary *> *attempts = [NSMutableDictionary dictionary];
100
+ while (!SidecarStopping && getppid() == parent && CCBridgeProcessAlive(hostPID.intValue)) {
101
+ @autoreleasepool {
102
+ if (WakeEnabled()) {
103
+ if (!lock) lock = CCBridgeAcquireLock(lockName);
104
+ if (lock) WakeIdleConversations(agentAPI, hostPID, attempts);
105
+ }
106
+ }
107
+ if (!SidecarStopping) sleep(1);
108
+ }
109
+ return 0;
110
+ } @catch (NSException *exception) {
111
+ fputs("cc-pets: Antigravity App Sidecar could not access the CC Bridge state.\n", stderr);
112
+ return 1;
113
+ } @finally {
114
+ CCBridgeReleaseLock(lock);
115
+ sigaction(SIGINT, &previousInterrupt, NULL);
116
+ sigaction(SIGTERM, &previousTerminate, NULL);
117
+ sigaction(SIGHUP, &previousHangup, NULL);
118
+ }
119
+ }
@@ -2,9 +2,11 @@
2
2
 
3
3
  // `cc-pets bridge <子命令>` 的入口。
4
4
  //
5
- // 面向用户:enable / configure / disable / status / list / send / name / inbox
5
+ // 面向用户:enable / configure / disable / status / list / send / name / inbox / agy
6
6
  // 面向 CLI 集成(由 hooks / MCP 配置调用):hook / watch / mcp / notify-idle
7
7
  // 面向安装流程:refresh / teardown
8
8
  //
9
9
  // arguments 不含 "bridge" 本身。返回进程退出码。
10
10
  int CCBridgeCommandMain(NSArray<NSString *> *arguments);
11
+ NSDictionary *CCBridgeHandleAntigravityHook(NSString *event, NSDictionary *payload);
12
+ void CCBridgeFinishAntigravityHook(BOOL written);