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
@@ -4,6 +4,7 @@
4
4
  #import "CCPetsCLISupport.h"
5
5
  #import "CCPetsJSON.h"
6
6
  #import <CommonCrypto/CommonDigest.h>
7
+ #import <libproc.h>
7
8
  #import <sys/sysctl.h>
8
9
  #import <sys/stat.h>
9
10
  #import <sys/file.h>
@@ -16,6 +17,8 @@
16
17
 
17
18
  const NSUInteger CCBridgeMessageBodyLimit = 16 * 1024;
18
19
  const long long CCBridgeMessageTTL = 24LL * 60 * 60 * 1000;
20
+ NSString *const CCBridgeAntigravityProvider = @"Antigravity";
21
+ NSString *const CCBridgeAntigravityAppProvider = @"Antigravity App";
19
22
  // 同一对会话 10 分钟内来回超过这个数,基本可以断定是两个 Agent 在互相自动回复。
20
23
  static const long long PairLimitWindow = 10LL * 60 * 1000;
21
24
  const NSUInteger CCBridgePairLimitCount = 20;
@@ -87,7 +90,7 @@ void CCBridgeSetEnabled(BOOL enabled, NSDictionary *options) {
87
90
  EnsureHomeDirectory();
88
91
  NSDictionary *normalized = CCBridgeNormalizeOptions(options);
89
92
  CCPetsJSONObject *document = [CCPetsJSONObject new];
90
- for (NSString *key in @[@"codexApprove", @"claudeAllow", @"wake", @"editGuard"]) document[key] = normalized[key];
93
+ for (NSString *key in @[@"codexApprove", @"claudeAllow", @"antigravityAllow", @"antigravityApp", @"tabTitle", @"wake", @"editGuard"]) document[key] = normalized[key];
91
94
  NSISO8601DateFormatter *formatter = [NSISO8601DateFormatter new];
92
95
  formatter.formatOptions = NSISO8601DateFormatWithInternetDateTime | NSISO8601DateFormatWithFractionalSeconds;
93
96
  document[@"enabledAt"] = [formatter stringFromDate:NSDate.date];
@@ -164,6 +167,21 @@ NSDictionary *CCBridgeMergeOptionFlags(NSDictionary *base, NSDictionary<NSString
164
167
  if (!tools) return nil;
165
168
  next[@"claudeAllow"] = tools;
166
169
  }
170
+ if (flags[@"antigravityAllow"]) {
171
+ NSArray *tools = CCBridgeParseToolList(flags[@"antigravityAllow"], @"--agy-allow", error);
172
+ if (!tools) return nil;
173
+ next[@"antigravityAllow"] = tools;
174
+ }
175
+ if (flags[@"antigravityApp"]) {
176
+ NSNumber *value = CCBridgeParseSwitch(flags[@"antigravityApp"], @"--agy-app", error);
177
+ if (!value) return nil;
178
+ next[@"antigravityApp"] = value;
179
+ }
180
+ if (flags[@"tabTitle"]) {
181
+ NSNumber *value = CCBridgeParseSwitch(flags[@"tabTitle"], @"--tab-title", error);
182
+ if (!value) return nil;
183
+ next[@"tabTitle"] = value;
184
+ }
167
185
  if (flags[@"wake"]) {
168
186
  NSNumber *value = CCBridgeParseSwitch(flags[@"wake"], @"--wake", error);
169
187
  if (!value) return nil;
@@ -180,9 +198,13 @@ NSDictionary *CCBridgeMergeOptionFlags(NSDictionary *base, NSDictionary<NSString
180
198
  NSArray<NSString *> *CCBridgeDescribeOptions(NSDictionary *options) {
181
199
  NSArray *codex = options[@"codexApprove"];
182
200
  NSArray *claude = options[@"claudeAllow"];
201
+ NSArray *agy = options[@"antigravityAllow"];
183
202
  return @[
184
203
  LF(L(@"Codex auto-approve: {codexApprove}"), (@{@"codexApprove": codex.count > 0 ? [codex componentsJoinedByString:@", "] : L(@"none")})),
185
204
  LF(L(@"Claude allow without asking: {claudeAllow}"), (@{@"claudeAllow": claude.count > 0 ? [claude componentsJoinedByString:@", "] : L(@"none")})),
205
+ LF(L(@"Antigravity allow without asking: {agyAllow}"), (@{@"agyAllow": agy.count > 0 ? [agy componentsJoinedByString:@", "] : L(@"none")})),
206
+ LF(L(@"Antigravity App integration: {agyApp}"), (@{@"agyApp": [options[@"antigravityApp"] isEqual:@YES] ? L(@"on") : L(@"off")})),
207
+ LF(L(@"Bridge nicknames in tab titles: {tabTitle}"), (@{@"tabTitle": [options[@"tabTitle"] boolValue] ? L(@"on") : L(@"off")})),
186
208
  LF(L(@"Wake idle sessions: {wake}"), (@{@"wake": [options[@"wake"] boolValue] ? L(@"on") : L(@"off")})),
187
209
  LF(L(@"Pause edits on reserved files: {editGuard}"), (@{@"editGuard": [options[@"editGuard"] boolValue] ? L(@"on") : L(@"off")}))
188
210
  ];
@@ -299,6 +321,17 @@ NSArray<NSDictionary *> *CCBridgeListSessions(void) {
299
321
  return sessions;
300
322
  }
301
323
 
324
+ static BOOL UsesBridgeHostPID(id provider) {
325
+ return [provider isEqual:CCBridgeAntigravityProvider] || [provider isEqual:CCBridgeAntigravityAppProvider];
326
+ }
327
+
328
+ NSNumber *CCBridgeSessionHostPID(NSDictionary *session) {
329
+ id hostPID = session[@"hostPid"];
330
+ if (UsesBridgeHostPID(session[@"provider"]) && [hostPID isKindOfClass:NSNumber.class]) return hostPID;
331
+ id pid = session[@"pid"];
332
+ return [pid isKindOfClass:NSNumber.class] ? pid : nil;
333
+ }
334
+
302
335
  void CCBridgeRemoveSession(id sessionId) {
303
336
  NSString *safe = CCBridgeSafeSessionId(sessionId);
304
337
  if (!safe) return;
@@ -480,7 +513,17 @@ static NSDictionary *UpsertSession(NSString *sessionId, NSString *provider, NSNu
480
513
  if (provider) record[@"provider"] = provider;
481
514
  }
482
515
  if (provider) record[@"provider"] = provider;
483
- if (pid && pid.intValue > 1) record[@"pid"] = pid;
516
+ if (pid.intValue > 1) {
517
+ if (UsesBridgeHostPID(record[@"provider"])) {
518
+ // Older Bridge clients treat an unknown provider with a pid as offline and may
519
+ // remove the record. They can still address it via the legacy activity timestamp.
520
+ record[@"hostPid"] = pid;
521
+ [record removeObjectForKey:@"pid"];
522
+ } else {
523
+ record[@"pid"] = pid;
524
+ [record removeObjectForKey:@"hostPid"];
525
+ }
526
+ }
484
527
  if (cwd.length > 0) record[@"cwd"] = cwd;
485
528
  if (tty.length > 0) record[@"tty"] = tty;
486
529
  if (profileID.length > 0) record[@"profileId"] = profileID;
@@ -712,6 +755,20 @@ static NSString *SessionDirectory(NSString *kind, NSString *sessionId) {
712
755
  return [[CCBridgeStateDirectory() stringByAppendingPathComponent:kind] stringByAppendingPathComponent:sessionId];
713
756
  }
714
757
 
758
+ NSString *CCBridgeOldestPendingMessageName(id sessionId) {
759
+ NSString *safe = CCBridgeSafeSessionId(sessionId);
760
+ if (!safe) return nil;
761
+ NSString *oldest = nil;
762
+ for (NSString *kind in @[@"inbox", @"claimed"]) {
763
+ for (NSString *name in ListJSON(SessionDirectory(kind, safe))) {
764
+ if (!IsMessageId(name.stringByDeletingPathExtension)) continue;
765
+ if (!oldest || [name compare:oldest] == NSOrderedAscending) oldest = name;
766
+ break;
767
+ }
768
+ }
769
+ return oldest;
770
+ }
771
+
715
772
  // 调用方持有该信箱的锁。空目录一并删掉,否则已退出的会话会在状态目录里留下痕迹。
716
773
  static void AbandonInboxLocked(NSString *sessionId, NSString *reason) {
717
774
  for (NSString *kind in @[@"inbox", @"claimed"]) {
@@ -1003,8 +1060,22 @@ static BOOL Matches(NSString *pattern, NSString *text) {
1003
1060
  return [expression firstMatchInString:text options:0 range:NSMakeRange(0, text.length)] != nil;
1004
1061
  }
1005
1062
 
1006
- // 只看可执行文件本身和脚本路径,不看其余参数:参数里出现 "claude" / "codex" 的进程太多了
1007
- // (比如 tmux new-session "codex …"、编辑器打开的某个路径)。
1063
+ static BOOL NativeAntigravityArguments(NSArray<NSString *> *arguments) {
1064
+ NSString *name = arguments.firstObject.lastPathComponent;
1065
+ NSString *configured = [CCPetsEnvironmentValue(@"AGY_REAL_BIN") lastPathComponent];
1066
+ return [name isEqualToString:@"agy"] || (configured.length > 0 && [name isEqualToString:configured]);
1067
+ }
1068
+
1069
+ static BOOL AntigravityAppExecutable(NSString *path) {
1070
+ return [path hasPrefix:@"/"] && [path hasSuffix:@"/Antigravity.app/Contents/Resources/bin/language_server"];
1071
+ }
1072
+
1073
+ static BOOL AntigravityAppHost(pid_t pid) {
1074
+ char path[PROC_PIDPATHINFO_MAXSIZE];
1075
+ // Hooks and MCP share the App backend. Use the kernel's executable path, not its argv.
1076
+ return proc_pidpath(pid, path, sizeof path) > 0 && AntigravityAppExecutable(@(path));
1077
+ }
1078
+
1008
1079
  BOOL CCBridgeArgumentsMatchProvider(NSString *provider, NSArray<NSString *> *arguments) {
1009
1080
  NSString *executable = arguments.firstObject ?: @"";
1010
1081
  NSString *second = arguments.count > 1 ? arguments[1] : @"";
@@ -1017,6 +1088,10 @@ BOOL CCBridgeArgumentsMatchProvider(NSString *provider, NSArray<NSString *> *arg
1017
1088
  return [executable.lastPathComponent isEqualToString:@"claude"] ||
1018
1089
  Matches(@"@anthropic-ai/claude-code/", executable) || Matches(@"@anthropic-ai/claude-code/", second);
1019
1090
  }
1091
+ if ([provider isEqualToString:CCBridgeAntigravityProvider]) {
1092
+ return NativeAntigravityArguments(arguments);
1093
+ }
1094
+ if ([provider isEqualToString:CCBridgeAntigravityAppProvider]) return AntigravityAppExecutable(executable);
1020
1095
  return NO;
1021
1096
  }
1022
1097
 
@@ -1037,8 +1112,9 @@ NSDictionary *CCBridgeFindAgentAncestor(pid_t startPid) {
1037
1112
  for (int depth = 0; depth < 12 && pid > 1; depth++) {
1038
1113
  pid_t parent = 0;
1039
1114
  if (!ProcessParent(pid, &parent, NULL)) return nil;
1115
+ if (AntigravityAppHost(pid)) return @{@"provider": CCBridgeAntigravityAppProvider, @"pid": @(pid)};
1040
1116
  NSArray<NSString *> *arguments = CCBridgeProcessArguments(pid);
1041
- for (NSString *provider in @[@"Claude", @"Codex"]) {
1117
+ for (NSString *provider in @[@"Claude", @"Codex", CCBridgeAntigravityProvider]) {
1042
1118
  if (CCBridgeArgumentsMatchProvider(provider, arguments)) return @{@"provider": provider, @"pid": @(pid)};
1043
1119
  }
1044
1120
  pid = parent;
@@ -1048,13 +1124,18 @@ NSDictionary *CCBridgeFindAgentAncestor(pid_t startPid) {
1048
1124
 
1049
1125
  BOOL CCBridgeSessionLive(NSDictionary *session) {
1050
1126
  if (![session isKindOfClass:NSDictionary.class] || [session[@"status"] isEqual:@"gone"]) return NO;
1051
- id pid = session[@"pid"];
1052
- if ([pid isKindOfClass:NSNumber.class]) {
1053
- if (!CCBridgeProcessAlive([pid intValue])) return NO;
1054
- NSArray<NSString *> *arguments = CCBridgeProcessArguments([pid intValue]);
1055
- return arguments == nil || CCBridgeArgumentsMatchProvider(session[@"provider"], arguments);
1127
+ NSString *provider = session[@"provider"];
1128
+ NSNumber *pid = CCBridgeSessionHostPID(session);
1129
+ if ([provider isEqual:CCBridgeAntigravityAppProvider]) {
1130
+ return pid.intValue > 1 && [CCBridgeOptions()[@"antigravityApp"] isEqual:@YES] && AntigravityAppHost(pid.intValue);
1131
+ }
1132
+ if (pid) {
1133
+ if (!CCBridgeProcessAlive(pid.intValue)) return NO;
1134
+ NSArray<NSString *> *arguments = CCBridgeProcessArguments(pid.intValue);
1135
+ return arguments == nil || CCBridgeArgumentsMatchProvider(provider, arguments);
1056
1136
  }
1057
- return CCPetsMilliseconds() - NumberValue(session[@"updatedAt"]) < StaleWithoutPid;
1137
+ return !UsesBridgeHostPID(provider) &&
1138
+ CCPetsMilliseconds() - NumberValue(session[@"updatedAt"]) < StaleWithoutPid;
1058
1139
  }
1059
1140
 
1060
1141
  // `codex queue` 是较新的 Codex 才有的子命令。旧版本把不认识的子命令当成交互式启动参数,
@@ -0,0 +1,12 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <sys/types.h>
3
+
4
+ BOOL CCBridgeTerminalTitleEnabled(void);
5
+ // The launch token binds a local terminal to the exact conversation registered by its hook.
6
+ void CCBridgeBindTerminalTitle(NSString *launchToken, NSString *provider, NSString *sessionID);
7
+ void CCBridgeBindTerminalTitleIfUnbound(NSString *launchToken, NSString *provider, NSString *sessionID);
8
+ void CCBridgeClearTerminalTitleBinding(NSString *launchToken);
9
+ NSString *CCBridgeTerminalTitleName(NSString *provider, NSString *launchToken, pid_t childPID);
10
+ NSString *CCBridgeTerminalTitleNameForSession(NSString *sessionID, NSString *provider);
11
+ NSString *CCBridgeComposeTerminalTitle(NSString *base, NSString *nickname);
12
+ int CCBridgePrintAntigravityTitle(NSString *originalTitle);
@@ -0,0 +1,105 @@
1
+ #import "CCPetsBridgeTerminalTitle.h"
2
+ #import "CCPetsBridge.h"
3
+ #import "CCPetsBridgeStore.h"
4
+ #import "CCPetsCLISupport.h"
5
+ #import <unistd.h>
6
+
7
+ static NSString *StringValue(id value) {
8
+ return [value isKindOfClass:NSString.class] ? value : nil;
9
+ }
10
+
11
+ static NSString *BindingPath(NSString *launchToken, BOOL createDirectory) {
12
+ NSString *rawToken = StringValue(launchToken);
13
+ NSUUID *token = rawToken.length == 36 ? [[NSUUID alloc] initWithUUIDString:rawToken] : nil;
14
+ if (!token) return nil;
15
+ NSString *directory = createDirectory ? CCBridgeSubdirectory(@[@"terminal-titles"])
16
+ : [CCBridgeStateDirectory() stringByAppendingPathComponent:@"terminal-titles"];
17
+ return [directory stringByAppendingPathComponent:[token.UUIDString.lowercaseString stringByAppendingString:@".json"]];
18
+ }
19
+
20
+ BOOL CCBridgeTerminalTitleEnabled(void) {
21
+ return CCBridgeEnabled() && [CCBridgeOptions()[@"tabTitle"] boolValue];
22
+ }
23
+
24
+ static void BindTerminalTitle(NSString *launchToken, NSString *provider, NSString *sessionID, BOOL replace) {
25
+ if (!provider.length || !CCBridgeSafeSessionId(sessionID)) return;
26
+ NSString *path = BindingPath(launchToken, YES);
27
+ if (!path) return;
28
+ CCBridgeWithLock(@"terminal-title-bindings", ^id {
29
+ NSDictionary *binding = CCBridgeReadJSON(path);
30
+ if (!binding || (replace && ![binding[@"session"] isEqual:sessionID])) {
31
+ CCBridgeWriteJSON(path, @{@"provider": provider, @"session": sessionID});
32
+ }
33
+ return nil;
34
+ });
35
+ }
36
+
37
+ void CCBridgeBindTerminalTitle(NSString *launchToken, NSString *provider, NSString *sessionID) {
38
+ BindTerminalTitle(launchToken, provider, sessionID, YES);
39
+ }
40
+
41
+ void CCBridgeBindTerminalTitleIfUnbound(NSString *launchToken, NSString *provider, NSString *sessionID) {
42
+ BindTerminalTitle(launchToken, provider, sessionID, NO);
43
+ }
44
+
45
+ void CCBridgeClearTerminalTitleBinding(NSString *launchToken) {
46
+ NSString *path = BindingPath(launchToken, NO);
47
+ if (path) unlink(path.fileSystemRepresentation);
48
+ }
49
+
50
+ NSString *CCBridgeTerminalTitleNameForSession(NSString *sessionID, NSString *provider) {
51
+ if (!CCBridgeTerminalTitleEnabled() || !CCBridgeSafeSessionId(sessionID)) return nil;
52
+ NSDictionary *record = CCBridgeReadSession(sessionID);
53
+ if (![record[@"provider"] isEqual:provider] || !CCBridgeSessionLive(record)) return nil;
54
+ NSString *alias = CCBridgeSessionAnimalAlias(record);
55
+ if (alias.length > 0) return alias;
56
+ NSString *name = CCBridgeNormalizeSessionName(record[@"name"]);
57
+ if ([record[@"nameSource"] isEqual:@"generated"]) {
58
+ NSArray<NSString *> *parts = [name componentsSeparatedByString:@"."];
59
+ if (parts.count == 3) return parts.lastObject;
60
+ }
61
+ return name;
62
+ }
63
+
64
+ NSString *CCBridgeTerminalTitleName(NSString *provider, NSString *launchToken, pid_t childPID) {
65
+ if (!CCBridgeProcessAlive(childPID)) return nil;
66
+ NSString *path = BindingPath(launchToken, NO);
67
+ id binding = path ? CCBridgeReadJSON(path) : nil;
68
+ if (![binding isKindOfClass:NSDictionary.class] || ![binding[@"provider"] isEqual:provider]) return nil;
69
+ return CCBridgeTerminalTitleNameForSession(StringValue(binding[@"session"]), provider);
70
+ }
71
+
72
+ static NSString *PlainTitle(NSString *value) {
73
+ if (!value.length) return @"";
74
+ NSString *line = [[value componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet] componentsJoinedByString:@" "];
75
+ NSArray<NSString *> *parts = [line componentsSeparatedByCharactersInSet:NSCharacterSet.controlCharacterSet];
76
+ return [[parts componentsJoinedByString:@""] stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
77
+ }
78
+
79
+ NSString *CCBridgeComposeTerminalTitle(NSString *base, NSString *nickname) {
80
+ NSString *title = PlainTitle(base);
81
+ NSString *name = PlainTitle(nickname);
82
+ if (!name.length) return title;
83
+ return title.length > 0 ? [NSString stringWithFormat:@"%@ · %@", title, name] : name;
84
+ }
85
+
86
+ int CCBridgePrintAntigravityTitle(NSString *originalTitle) {
87
+ @try {
88
+ NSData *input = [NSFileHandle.fileHandleWithStandardInput readDataToEndOfFile];
89
+ id state = input.length > 0 ? [NSJSONSerialization JSONObjectWithData:input options:0 error:nil] : nil;
90
+ if (![state isKindOfClass:NSDictionary.class]) state = @{};
91
+ NSString *sessionID = StringValue(state[@"conversation_id"]) ?: StringValue(state[@"session_id"]);
92
+ NSString *nickname = CCBridgeTerminalTitleNameForSession(sessionID, CCBridgeAntigravityProvider);
93
+ NSString *base = originalTitle;
94
+ if (base == nil) {
95
+ NSString *title = PlainTitle(StringValue(state[@"conversation_title"]));
96
+ NSString *project = StringValue(state[@"cwd"]).lastPathComponent;
97
+ base = title.length > 0 && project.length > 0 ? [NSString stringWithFormat:@"%@ | %@", title, project]
98
+ : (title.length > 0 ? title : project);
99
+ }
100
+ CCPetsPrintLine(stdout, CCBridgeComposeTerminalTitle(base, nickname));
101
+ } @catch (NSException *exception) {
102
+ if (originalTitle) CCPetsPrintLine(stdout, PlainTitle(originalTitle));
103
+ }
104
+ return 0;
105
+ }
@@ -0,0 +1,17 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @class CCPetsJSONObject;
4
+
5
+ // Missing or blank files have no configuration. Malformed nonblank files report an error.
6
+ CCPetsJSONObject *CCPetsReadAntigravityConfig(NSString *path, NSString **errorMessage);
7
+ NSArray<NSString *> *CCPetsInstallAntigravityPetHooks(NSDictionary *profile);
8
+ BOOL CCPetsRemoveAntigravityPetHooks(NSDictionary *profile);
9
+ BOOL CCPetsAntigravityPetHooksInstalled(NSDictionary *profile);
10
+ BOOL CCPetsAntigravityBridgeInstalled(NSDictionary *profile);
11
+ NSArray<NSString *> *CCPetsInstallAntigravityBridge(NSDictionary *profile, NSArray<NSString *> *allowed, BOOL registerMcp);
12
+ NSArray<NSString *> *CCPetsRemoveAntigravityBridge(NSDictionary *profile, BOOL unregisterMcp);
13
+ // Wrap or restore the terminal title command in this native CLI profile only.
14
+ void CCPetsConfigureAntigravityBridgeTitle(NSDictionary *profile, BOOL enabled);
15
+ // Desktop Sidecars are scoped to the default Gemini root. Custom CLI Homes are ignored.
16
+ NSArray<NSString *> *CCPetsConfigureAntigravityAppSidecar(NSDictionary *profile, BOOL enabled);
17
+ BOOL CCPetsAntigravityAppSidecarInstalled(NSDictionary *profile);