cc-pets 2.4.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 (111) hide show
  1. package/CC_BRIDGE.md +93 -14
  2. package/CC_BRIDGE.zh-CN.md +71 -11
  3. package/CHANGELOG.md +55 -0
  4. package/CHANGELOG.zh-CN.md +56 -1
  5. package/CONTRIBUTING.md +1 -1
  6. package/CONTRIBUTING.zh-CN.md +1 -1
  7. package/PROVIDER_PROTOCOL.md +5 -1
  8. package/PROVIDER_PROTOCOL.zh-CN.md +4 -1
  9. package/README.md +116 -34
  10. package/README.zh-CN.md +99 -35
  11. package/Resources/AgentIcons/antigravity.icns +0 -0
  12. package/Resources/zh-Hans.lproj/Localizable.strings +99 -26
  13. package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +51 -4
  14. package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +120 -17
  15. package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +24 -11
  16. package/Sources/CCPets/App/CCPetsAppDelegate+MenuBar.m +86 -0
  17. package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +24 -1
  18. package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +21 -11
  19. package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +33 -17
  20. package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +43 -7
  21. package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +7 -4
  22. package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +7 -4
  23. package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +24 -22
  24. package/Sources/CCPets/App/CCPetsAppDelegate.h +10 -0
  25. package/Sources/CCPets/App/CCPetsAppDelegate.m +18 -8
  26. package/Sources/CCPets/App/CCPetsVersion.h +4 -0
  27. package/Sources/CCPets/App/CCPetsVersion.m +34 -0
  28. package/Sources/CCPets/App/main.m +11 -0
  29. package/Sources/CCPets/Bridge/CCPetsBridge.m +41 -17
  30. package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.h +4 -0
  31. package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.m +119 -0
  32. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +3 -1
  33. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +272 -50
  34. package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +12 -3
  35. package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +341 -95
  36. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +0 -2
  37. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +227 -95
  38. package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +35 -5
  39. package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +310 -42
  40. package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.h +12 -0
  41. package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.m +105 -0
  42. package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.h +17 -0
  43. package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.m +462 -0
  44. package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.h +5 -0
  45. package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.m +180 -0
  46. package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.h +3 -0
  47. package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.m +463 -0
  48. package/Sources/CCPets/Integrations/CCPetsEvents.h +5 -0
  49. package/Sources/CCPets/Integrations/CCPetsEvents.m +68 -12
  50. package/Sources/CCPets/Integrations/CCPetsIntegrations.h +1 -1
  51. package/Sources/CCPets/Integrations/CCPetsIntegrations.m +38 -8
  52. package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +15 -5
  53. package/Sources/CCPets/Integrations/CCPetsProfiles.h +2 -1
  54. package/Sources/CCPets/Integrations/CCPetsProfiles.m +112 -81
  55. package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +11 -1
  56. package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +217 -45
  57. package/Sources/CCPets/Pet/CCPetsPhrasesEditor.m +7 -0
  58. package/Sources/CCPets/Pet/CCPetsPreviews.m +16 -8
  59. package/Sources/CCPets/Pet/PetView+Menu.m +64 -5
  60. package/Sources/CCPets/Pet/PetView.h +7 -0
  61. package/Sources/CCPets/Pet/PetView.m +12 -1
  62. package/Sources/CCPets/Support/CCPetsDoctor.m +126 -37
  63. package/Sources/CCPets/Support/CCPetsPaths.h +5 -0
  64. package/Sources/CCPets/Support/CCPetsPaths.m +15 -0
  65. package/Sources/CCPets/Support/CCPetsPreferences.h +14 -1
  66. package/Sources/CCPets/Support/CCPetsPreferences.m +36 -0
  67. package/Sources/CCPets/UI/CCPetsMenuBarIcon.h +16 -0
  68. package/Sources/CCPets/UI/CCPetsMenuBarIcon.m +70 -0
  69. package/Sources/CCPets/UI/CCPetsMenuBarPanel.h +18 -0
  70. package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +533 -0
  71. package/Sources/CCPets/UI/CCPetsMenuBarSummary.h +51 -0
  72. package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +98 -0
  73. package/Sources/CCPets/UI/CCPetsSettingsPage.h +7 -1
  74. package/Sources/CCPets/UI/CCPetsSettingsPage.m +205 -8
  75. package/Sources/CCPets/UI/CCPetsStatusItem.h +28 -0
  76. package/Sources/CCPets/UI/CCPetsStatusItem.m +147 -0
  77. package/Sources/CCPets/UI/CCPetsUIStyle.m +3 -1
  78. package/Sources/CCPets/UI/CCPetsUsagePage.h +4 -3
  79. package/Sources/CCPets/UI/CCPetsUsagePage.m +69 -43
  80. package/Sources/CCPets/UI/CCPetsUsageStore.m +11 -1
  81. package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +6 -4
  82. package/Sources/CCPets/Usage/CCPetsAntigravityQuota.m +115 -0
  83. package/Sources/CCPets/Usage/CCPetsNormalizedUsage.h +5 -0
  84. package/Sources/CCPets/Usage/CCPetsNormalizedUsage.m +43 -0
  85. package/Sources/CCPets/Usage/CCPetsProviderRegistry+Testing.h +13 -0
  86. package/Sources/CCPets/Usage/CCPetsProviderRegistry.h +25 -0
  87. package/Sources/CCPets/Usage/CCPetsProviderRegistry.m +94 -0
  88. package/Sources/CCPets/Usage/CCPetsQuotaHistory.h +1 -1
  89. package/Sources/CCPets/Usage/CCPetsQuotaHistory.m +11 -8
  90. package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +2 -0
  91. package/Sources/CCPets/Usage/CCPetsUsage+Models.m +206 -14
  92. package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +4 -4
  93. package/Sources/CCPets/Usage/CCPetsUsage.h +7 -2
  94. package/Sources/CCPets/Usage/CCPetsUsageMode.h +2 -0
  95. package/Sources/CCPets/Usage/CCPetsUsageMode.m +29 -4
  96. package/Sources/CCPets/Usage/CCPetsUsageMonitor.h +4 -4
  97. package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +90 -7
  98. package/Sources/CCPets/Usage/QuotaDashboardView+CompactRow.m +81 -0
  99. package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +5 -8
  100. package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +26 -4
  101. package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +99 -99
  102. package/Sources/CCPets/Usage/QuotaDashboardView.h +9 -10
  103. package/Sources/CCPets/Usage/QuotaDashboardView.m +232 -79
  104. package/THIRD_PARTY_NOTICES.md +5 -4
  105. package/THIRD_PARTY_NOTICES.zh-CN.md +6 -5
  106. package/bin/agy-with-pet +82 -0
  107. package/bin/cc-pets +1 -1
  108. package/bin/claude-with-pet +15 -0
  109. package/bin/codex-with-pet +17 -2
  110. package/package.json +5 -3
  111. package/scripts/install-shell-integration.sh +5 -0
@@ -20,6 +20,47 @@ NSString *SanitizedShortString(id value, NSUInteger maximumLength) {
20
20
  return [safe stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
21
21
  }
22
22
 
23
+ NSString *NormalizedAgentProfileID(id value) {
24
+ if (![value isKindOfClass:NSString.class]) return @"";
25
+ NSString *identifier = [value stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
26
+ NSCharacterSet *allowed = [NSCharacterSet characterSetWithCharactersInString:
27
+ @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-:"];
28
+ // 拒绝非法标识,不能删除字符后误认成另一个账号。
29
+ if (identifier.length == 0 || identifier.length > 128 ||
30
+ [identifier rangeOfCharacterFromSet:allowed.invertedSet].location != NSNotFound) return @"";
31
+ NSRegularExpression *legacy = [NSRegularExpression regularExpressionWithPattern:
32
+ @"\\A(codex|claude)([0-9a-f]{16})\\z" options:0 error:nil];
33
+ return [legacy stringByReplacingMatchesInString:identifier options:0
34
+ range:NSMakeRange(0, identifier.length) withTemplate:@"$1:$2"];
35
+ }
36
+
37
+ // 工作目录只用于状态卡上的会话标签和悬停提示。路径里可以有中文和空格,所以不走
38
+ // SanitizedShortString 的白名单;只收绝对路径,挡掉控制字符和离谱的长度。
39
+ NSString *SanitizedWorkingDirectory(id value) {
40
+ if (![value isKindOfClass:NSString.class]) return @"";
41
+ NSString *path = [(NSString *)value stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
42
+ if (path.length == 0 || path.length > 1024 || ![path hasPrefix:@"/"]) return @"";
43
+ if ([path rangeOfCharacterFromSet:NSCharacterSet.controlCharacterSet].location != NSNotFound) return @"";
44
+ return path;
45
+ }
46
+
47
+ // 状态卡标题里的会话标签:有 CC Bridge 短名(目录名.动物)就用它,否则退回目录名。
48
+ // 卡片很窄,超过 20 个字符时截掉中间,保留末尾的动物后缀——同目录的多个会话全靠它区分。
49
+ NSString *StatusSessionLabel(NSString *bridgeName, NSString *cwd) {
50
+ static const NSUInteger limit = 20;
51
+ NSString *label = bridgeName.length > 0 ? bridgeName : cwd.lastPathComponent;
52
+ if (label.length == 0 || [label isEqualToString:@"/"]) return @"";
53
+ if (label.length <= limit) return label;
54
+ NSRange dot = [label rangeOfString:@"." options:NSBackwardsSearch];
55
+ NSString *suffix = dot.location != NSNotFound && dot.location > 0 && label.length - dot.location <= 9
56
+ ? [label substringFromIndex:dot.location] : @"";
57
+ NSUInteger keep = limit - 1 - suffix.length;
58
+ // 按完整字符截断,免得把中文目录名或 emoji 切成半个。
59
+ NSRange head = [label rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, keep)];
60
+ if (head.length > keep) head = [label rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, keep - 1)];
61
+ return [NSString stringWithFormat:@"%@…%@", [label substringWithRange:head], suffix];
62
+ }
63
+
23
64
  NSString *ProviderFromEnvironment(void) {
24
65
  NSDictionary<NSString *, NSString *> *environment = NSProcessInfo.processInfo.environment;
25
66
  if ([environment[@"CC_PETS_CODEX_AGENT_HOOK"] boolValue]) return @"Codex";
@@ -91,7 +132,7 @@ NSString *NormalizedStateForEvent(NSString *event, BOOL failed) {
91
132
 
92
133
  NSString *OnlineAgentSessionKey(id provider, id profileID, id tty) {
93
134
  NSString *providerName = SanitizedShortString(provider, 32);
94
- NSString *profile = SanitizedShortString(profileID, 128);
135
+ NSString *profile = NormalizedAgentProfileID(profileID);
95
136
  // 先取末段再清洗:清洗会去掉 "/","/dev/ttys003" 就成了 "devttys003"。
96
137
  NSString *ttyName = [tty isKindOfClass:NSString.class]
97
138
  ? SanitizedShortString([(NSString *)tty lastPathComponent], 64) : @"";
@@ -189,19 +230,18 @@ int RecordHookEvent(void) {
189
230
  if (![payload isKindOfClass:NSDictionary.class]) return EXIT_SUCCESS;
190
231
  NSString *event = payload[@"hook_event_name"];
191
232
  if (![event isKindOfClass:NSString.class] || event.length == 0) return EXIT_SUCCESS;
192
- // Claude Agent SDK / ACP 也会执行用户级 Hooks。IDE 或终端仅仅创建、销毁这类
193
- // 后台会话时就会发 SessionStart / SessionEnd,但它们不代表用户启动了 Agent
194
- // 任务或完成了一轮工作。真实 CLI 的启动状态由包装脚本显式写入,任务完成则由
195
- // Stop 表示,因此这里忽略纯会话生命周期事件,避免普通终端开关触发误报。
196
- if ([event isEqualToString:@"SessionStart"] || [event isEqualToString:@"SessionEnd"]) {
197
- return EXIT_SUCCESS;
198
- }
233
+ NSString *provider = ProviderFromEnvironment();
234
+ NSDictionary *terminal = TerminalFocusTargetForHook(payload, provider);
235
+ BOOL lifecycle = [event isEqualToString:@"SessionStart"] || [event isEqualToString:@"SessionEnd"];
236
+ // 桌面会话不经过 CLI 包装器,必须记录生命周期,但消费端不播报任务完成。
237
+ // Codex 的结束事件即使缺少回跳目标也要保留,以 session_id 清理记录。
238
+ if (lifecycle && !([provider isEqualToString:@"Codex"] &&
239
+ (IsCodexDesktopFocusTarget(terminal) || [event isEqualToString:@"SessionEnd"]))) return EXIT_SUCCESS;
199
240
  NSString *tool = [payload[@"tool_name"] isKindOfClass:NSString.class] ? payload[@"tool_name"] : @"";
200
241
  NSString *session = SanitizedShortString(payload[@"session_id"], 128);
201
242
  id toolResult = payload[@"tool_response"] ?: payload[@"tool_result"];
202
243
  BOOL failed = [event isEqualToString:@"PostToolUseFailure"] ||
203
244
  [event isEqualToString:@"StopFailure"] || HookValueIndicatesFailure(toolResult);
204
- NSString *provider = ProviderFromEnvironment();
205
245
  BOOL autoReview = [provider isEqualToString:@"Codex"] &&
206
246
  [event isEqualToString:@"PermissionRequest"] && CodexAutoReviewEnabled();
207
247
  NSMutableDictionary *record = [@{
@@ -213,12 +253,24 @@ int RecordHookEvent(void) {
213
253
  @"timestamp": @([NSDate.date timeIntervalSince1970])
214
254
  } mutableCopy];
215
255
  if (session.length > 0) record[@"session"] = session;
216
- NSString *profileID = SanitizedShortString(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_ID"], 128);
256
+ NSString *cwd = SanitizedWorkingDirectory(payload[@"cwd"]);
257
+ if (cwd.length > 0) record[@"cwd"] = cwd;
258
+ NSString *profileID = NormalizedAgentProfileID(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_ID"]);
217
259
  NSString *profileName = SanitizedShortString(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_NAME"], 64);
218
260
  if (profileID.length > 0) record[@"profileId"] = profileID;
219
261
  if (profileName.length > 0) record[@"profileName"] = profileName;
220
- NSDictionary *terminal = TerminalFocusTargetForHook(payload, provider);
221
262
  if (terminal.count > 0) record[@"terminal"] = terminal;
263
+ if ([provider isEqualToString:@"Codex"]) {
264
+ // 不记录 prompt;只保存会话是否有转录,区分桌面后台临时任务与真实聊天。
265
+ id transcript = payload[@"transcript_path"];
266
+ if (transcript == NSNull.null) record[@"transient"] = @YES;
267
+ else if ([transcript isKindOfClass:NSString.class] && [transcript length] > 0) {
268
+ record[@"transcriptPath"] = transcript;
269
+ }
270
+ NSString *home = NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_HOME"]
271
+ ?: NSProcessInfo.processInfo.environment[@"CODEX_HOME"] ?: DefaultCodexHomeDirectory();
272
+ if (home.isAbsolutePath) record[@"codexHome"] = home;
273
+ }
222
274
  AppendAgentEventRecord(record);
223
275
  return EXIT_SUCCESS;
224
276
  }
@@ -264,7 +316,11 @@ int RecordProviderEvent(void) {
264
316
  @"state": state,
265
317
  @"timestamp": @([NSDate.date timeIntervalSince1970])
266
318
  } mutableCopy];
267
- NSString *profileID = SanitizedShortString(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_ID"], 128);
319
+ // 包装脚本的启动事件没有 Hook payload,从调用进程继承的目录补齐会话标签。
320
+ NSString *cwd = SanitizedWorkingDirectory(payload[@"cwd"]);
321
+ if (cwd.length == 0) cwd = SanitizedWorkingDirectory(NSFileManager.defaultManager.currentDirectoryPath);
322
+ if (cwd.length > 0) record[@"cwd"] = cwd;
323
+ NSString *profileID = NormalizedAgentProfileID(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_ID"]);
268
324
  NSString *profileName = SanitizedShortString(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_NAME"], 64);
269
325
  if (profileID.length > 0) record[@"profileId"] = profileID;
270
326
  if (profileName.length > 0) record[@"profileName"] = profileName;
@@ -1,6 +1,6 @@
1
1
  #import <Foundation/Foundation.h>
2
2
 
3
- // CC Pets 在 Claude Code / Codex 配置和 shell 里留下的集成:Agent Hooks、Claude status line
3
+ // CC Pets 在 Claude Code / Codex / Antigravity CLI 配置和 shell 里留下的集成:Agent Hooks、Claude status line
4
4
  // 额度采集、.zshrc 里的 shim 段落与 shim 软链。原先是 scripts/install-claude-hooks.mjs、
5
5
  // install-codex-hooks.mjs 和 uninstall-integrations.mjs,改成原生实现后安装和卸载都不再依赖 Node。
6
6
  // CC Bridge 的集成不在这里,仍由 scripts/bridge 负责。
@@ -1,5 +1,6 @@
1
1
  #import "CCPetsL10n.h"
2
2
  #import "CCPetsIntegrations.h"
3
+ #import "CCPetsAntigravityConfig.h"
3
4
  #import "CCPetsJSON.h"
4
5
  #import "CCPetsProfiles.h"
5
6
  #import "CCPetsCLISupport.h"
@@ -391,7 +392,7 @@ int InstallCodexHooksAtHome(NSString *binary, NSString *codexHome) {
391
392
  CCPetsShellQuote(codexHome), CCPetsShellQuote(binary)];
392
393
  ReplaceManagedHooks(config, @[@[CCPetsCodexHookMarker, @"cc-pets"], @[CCPetsLegacyCodexHookMarker, @"codex-pet"]], command, @[
393
394
  @"SessionStart", @"UserPromptSubmit", @"PreToolUse", @"PermissionRequest", @"PostToolUse",
394
- @"SubagentStart", @"SubagentStop", @"Stop"
395
+ @"SubagentStart", @"SubagentStop", @"Stop", @"SessionEnd"
395
396
  ]);
396
397
 
397
398
  NSString *text = [CCPetsJSONStringify(config) stringByAppendingString:@"\n"];
@@ -492,7 +493,7 @@ static BOOL RemoveShims(void) {
492
493
  [CCPetsHomeDirectory() stringByAppendingPathComponent:@".cc-pets/shims"];
493
494
  if (![NSFileManager.defaultManager fileExistsAtPath:directory]) return NO;
494
495
  BOOL changed = NO;
495
- for (NSString *name in @[@"codex", @"claude"]) {
496
+ for (NSString *name in @[@"codex", @"claude", @"agy"]) {
496
497
  NSString *shim = [directory stringByAppendingPathComponent:name];
497
498
  // lstat:目标包被 npm uninstall 删掉后软链是断的,但仍然要清掉。
498
499
  struct stat info;
@@ -569,27 +570,53 @@ int UninstallCodexHooksAtHome(NSString *codexHome) {
569
570
  return failed ? 1 : 0;
570
571
  }
571
572
 
573
+ static BOOL RemoveAntigravityHooksForUninstall(NSDictionary *profile, BOOL *failed) {
574
+ BOOL installed = CCPetsAntigravityPetHooksInstalled(profile);
575
+ @try {
576
+ if (CCPetsRemoveAntigravityPetHooks(profile)) return installed;
577
+ } @catch (NSException *exception) {
578
+ CCPetsPrintLine(stderr, exception.reason ?: exception.name);
579
+ }
580
+ *failed = YES;
581
+ return NO;
582
+ }
583
+
572
584
  int UninstallIntegrations(BOOL preparingInstall, NSString *shellRC) {
573
585
  BOOL failed = NO;
574
586
  // 安装/卸载的隐式范围只包含官方默认 Home;环境变量指向的自定义 Home 必须先显式登记。
575
587
  NSString *defaultCodexHome = [CCPetsHomeDirectory() stringByAppendingPathComponent:@".codex"];
576
588
  NSString *defaultClaudeHome = [CCPetsHomeDirectory() stringByAppendingPathComponent:@".claude"];
589
+ NSString *defaultAntigravityHome = [CCPetsHomeDirectory() stringByAppendingPathComponent:@".gemini"];
577
590
  NSString *codexHooksPath = [defaultCodexHome stringByAppendingPathComponent:@"hooks.json"];
578
591
  BOOL codexChanged = RemoveCodexHooksAtHome(defaultCodexHome, preparingInstall, &failed);
579
592
  NSString *claudeSettingsPath = [defaultClaudeHome stringByAppendingPathComponent:@"settings.json"];
580
593
  BOOL claudeChanged = RemoveClaudeHooksAtHome(defaultClaudeHome, preparingInstall, &failed);
594
+ BOOL antigravityChanged = NO;
595
+ if (!preparingInstall) {
596
+ NSDictionary *profile = CCPetsProfileForHome(CCPetsProfileProviderAntigravity, defaultAntigravityHome) ?:
597
+ @{@"provider": CCPetsProfileProviderAntigravity, @"home": defaultAntigravityHome,
598
+ @"id": CCPetsProfileID(CCPetsProfileProviderAntigravity, defaultAntigravityHome)};
599
+ antigravityChanged = RemoveAntigravityHooksForUninstall(profile, &failed);
600
+ }
581
601
  BOOL profileChanged = NO;
582
602
 
583
603
  // 显式登记的 Home 也属于安装范围。默认 Home 已迁移进注册表时按规范化路径去重。
584
604
  NSMutableSet<NSString *> *handledHomes = [NSMutableSet setWithObjects:
585
- CCPetsResolvePath(defaultCodexHome), CCPetsResolvePath(defaultClaudeHome), nil];
605
+ CCPetsResolvePath(defaultCodexHome), CCPetsResolvePath(defaultClaudeHome),
606
+ CCPetsRealPath(defaultAntigravityHome) ?: CCPetsResolvePath(defaultAntigravityHome), nil];
586
607
  for (NSDictionary *profile in CCPetsProfiles()) {
587
608
  NSString *home = CCPetsResolvePath(profile[@"home"]);
588
609
  if (home.length == 0 || [handledHomes containsObject:home]) continue;
589
610
  [handledHomes addObject:home];
590
- BOOL changed = [profile[@"provider"] isEqualToString:CCPetsProfileProviderClaude]
591
- ? RemoveClaudeHooksAtHome(home, preparingInstall, &failed)
592
- : RemoveCodexHooksAtHome(home, preparingInstall, &failed);
611
+ NSString *provider = profile[@"provider"];
612
+ BOOL changed;
613
+ if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
614
+ changed = !preparingInstall && RemoveAntigravityHooksForUninstall(profile, &failed);
615
+ } else if ([provider isEqualToString:CCPetsProfileProviderClaude]) {
616
+ changed = RemoveClaudeHooksAtHome(home, preparingInstall, &failed);
617
+ } else {
618
+ changed = RemoveCodexHooksAtHome(home, preparingInstall, &failed);
619
+ }
593
620
  if (changed) {
594
621
  profileChanged = YES;
595
622
  CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the CC Pets hooks in %2$@."),
@@ -609,15 +636,18 @@ int UninstallIntegrations(BOOL preparingInstall, NSString *shellRC) {
609
636
  CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the CC Pets hooks in %2$@ and restored the original status line."),
610
637
  action, claudeSettingsPath]);
611
638
  }
639
+ if (antigravityChanged) {
640
+ CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"Removed the CC Pets hooks in %@."), defaultAntigravityHome]);
641
+ }
612
642
  if (shellChanged) {
613
643
  CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the CC Pets shell integration in %2$@."), action, shellRC]);
614
644
  }
615
645
  if (shimChanged) {
616
646
  NSString *directory = CCPetsEnvironmentValue(@"CC_PETS_SHIM_DIR") ?:
617
647
  [CCPetsHomeDirectory() stringByAppendingPathComponent:@".cc-pets/shims"];
618
- CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the codex / claude shims in %2$@."), action, directory]);
648
+ CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the codex / claude / agy shims in %2$@."), action, directory]);
619
649
  }
620
- if (!codexChanged && !claudeChanged && !profileChanged && !shellChanged && !shimChanged && !preparingInstall) {
650
+ if (!codexChanged && !claudeChanged && !antigravityChanged && !profileChanged && !shellChanged && !shimChanged && !preparingInstall && !failed) {
621
651
  CCPetsPrintLine(stdout, L(@"No CC Pets integrations to remove."));
622
652
  }
623
653
  return failed ? 1 : 0;
@@ -7,7 +7,10 @@
7
7
  static int BlockLaunch(NSString *provider, NSString *reason) {
8
8
  CCPetsPrintLine(stderr, CCPetsInterpolate(
9
9
  L(@"CC Pets blocked {provider}: {reason}"), @{@"provider": provider, @"reason": reason}));
10
- CCPetsPrintLine(stderr, L(@"Connect Shadowrocket and select an exit outside mainland China / Hong Kong, then check routing and DNS settings. You can turn off this check in Main menu → Settings → Launch Protection."));
10
+ NSString *hint = [provider isEqualToString:@"Antigravity"]
11
+ ? L(@"Connect Shadowrocket to continue. You can turn off this check in Main menu → Settings → Launch Protection.")
12
+ : L(@"Connect Shadowrocket and select an exit outside mainland China / Hong Kong, then check routing and DNS settings. You can turn off this check in Main menu → Settings → Launch Protection.");
13
+ CCPetsPrintLine(stderr, hint);
11
14
  return 1;
12
15
  }
13
16
 
@@ -333,14 +336,21 @@ static BOOL HasLocalNetworkOverrides(NSString *provider, NSString *directory) {
333
336
  }
334
337
 
335
338
  int CCPetsLaunchPreflight(NSString *provider, NSArray<NSString *> *arguments) {
336
- if (![@[@"claude", @"codex"] containsObject:provider]) {
337
- CCPetsPrintLine(stderr, L(@"Launch check expects claude or codex."));
339
+ if (![@[@"claude", @"codex", @"agy"] containsObject:provider]) {
340
+ CCPetsPrintLine(stderr, L(@"Launch check expects claude, codex or agy."));
338
341
  return 2;
339
342
  }
340
343
  if (!CCPetsPrefBool(CCPetsShadowrocketLaunchCheckKey)) return 0;
341
- NSString *name = [provider isEqualToString:@"claude"] ? @"Claude" : @"Codex";
342
- CCPetsPrintLine(stderr, L(@"CC Pets: checking Shadowrocket and service exit regions ..."));
344
+ NSString *name = [provider isEqualToString:@"claude"] ? @"Claude"
345
+ : ([provider isEqualToString:@"codex"] ? @"Codex" : @"Antigravity");
343
346
  NSString *reason = nil;
347
+ if ([provider isEqualToString:@"agy"]) {
348
+ CCPetsPrintLine(stderr, L(@"CC Pets: checking Shadowrocket ..."));
349
+ if (!ShadowrocketConnected(&reason)) return BlockLaunch(name, reason);
350
+ CCPetsPrintLine(stderr, L(@"CC Pets: Shadowrocket is connected."));
351
+ return 0;
352
+ }
353
+ CCPetsPrintLine(stderr, L(@"CC Pets: checking Shadowrocket and service exit regions ..."));
344
354
  if (!ShadowrocketConnected(&reason)) return BlockLaunch(name, reason);
345
355
 
346
356
  NSString *profile = nil, *directory = NSFileManager.defaultManager.currentDirectoryPath;
@@ -2,6 +2,7 @@
2
2
 
3
3
  extern NSString *const CCPetsProfileProviderClaude;
4
4
  extern NSString *const CCPetsProfileProviderCodex;
5
+ extern NSString *const CCPetsProfileProviderAntigravity;
5
6
  extern NSNotificationName const CCPetsProfilesDidChangeNotification;
6
7
 
7
8
  NSString *CCPetsProfilesPath(void);
@@ -31,7 +32,7 @@ BOOL CCPetsSetProfileNeedsRepair(NSString *profileID, BOOL needsRepair, NSString
31
32
 
32
33
  // 只迁移已经存在 CC Pets 管理标记的默认配置,不扫描任何其他目录。
33
34
  BOOL CCPetsMigrateManagedDefaultProfiles(NSString **errorMessage);
34
- // 自动发现官方 ~/.claude / ~/.codex(目录已存在或 CLI 已安装);不发现任何自定义 Home。
35
+ // 自动发现官方 Claude、Codex 和 Antigravity CLI 的默认目录;不发现任何自定义 Home。
35
36
  BOOL CCPetsEnsureOfficialDefaultProfiles(NSString **errorMessage);
36
37
 
37
38
  // profile CLI:list/ensure-defaults/add/repair/remove。add/repair 会执行实际集成适配。
@@ -1,4 +1,5 @@
1
1
  #import "CCPetsProfiles.h"
2
+ #import "CCPetsAntigravityConfig.h"
2
3
  #import "CCPetsBridge.h"
3
4
  #import "CCPetsBridgeSetup.h"
4
5
  #import "CCPetsCLISupport.h"
@@ -9,6 +10,7 @@
9
10
 
10
11
  NSString *const CCPetsProfileProviderClaude = @"claude";
11
12
  NSString *const CCPetsProfileProviderCodex = @"codex";
13
+ NSString *const CCPetsProfileProviderAntigravity = @"antigravity";
12
14
  NSNotificationName const CCPetsProfilesDidChangeNotification = @"CCPetsProfilesDidChange";
13
15
  NSString *const CCPetsProfileStateIntegrated = @"integrated";
14
16
  NSString *const CCPetsProfileStateRepair = @"repair";
@@ -23,8 +25,14 @@ NSString *CCPetsProfilesPath(void) {
23
25
  }
24
26
 
25
27
  static BOOL ValidProvider(NSString *provider) {
26
- return [provider isEqualToString:CCPetsProfileProviderClaude] ||
27
- [provider isEqualToString:CCPetsProfileProviderCodex];
28
+ return [provider isKindOfClass:NSString.class] &&
29
+ [@[CCPetsProfileProviderClaude, CCPetsProfileProviderCodex, CCPetsProfileProviderAntigravity] containsObject:provider];
30
+ }
31
+
32
+ static NSString *OfficialHome(NSString *provider) {
33
+ if (!ValidProvider(provider)) return nil;
34
+ NSString *leaf = [provider isEqualToString:CCPetsProfileProviderAntigravity] ? @"gemini" : provider;
35
+ return [CCPetsHomeDirectory() stringByAppendingPathComponent:[@"." stringByAppendingString:leaf]];
28
36
  }
29
37
 
30
38
  static NSString *CanonicalHome(NSString *home) {
@@ -80,11 +88,7 @@ NSString *CCPetsProfileDefaultDisplayName(NSString *provider, NSString *home) {
80
88
  }
81
89
 
82
90
  BOOL CCPetsProfileIsOfficialDefault(NSDictionary *profile) {
83
- NSString *provider = profile[@"provider"];
84
- NSString *leaf = [provider isEqualToString:CCPetsProfileProviderClaude] ? @".claude"
85
- : ([provider isEqualToString:CCPetsProfileProviderCodex] ? @".codex" : nil);
86
- if (!leaf) return NO;
87
- NSString *official = CanonicalHome([CCPetsHomeDirectory() stringByAppendingPathComponent:leaf]);
91
+ NSString *official = CanonicalHome(OfficialHome(profile[@"provider"]));
88
92
  return official.length > 0 && [CanonicalHome(profile[@"home"]) isEqualToString:official];
89
93
  }
90
94
 
@@ -113,6 +117,11 @@ static BOOL HomeContainsAny(NSString *home, NSArray<NSString *> *names) {
113
117
 
114
118
  BOOL CCPetsProfileHomeMatchesProvider(NSString *provider, NSString *home) {
115
119
  if (!ValidProvider(provider) || home.length == 0) return NO;
120
+ if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
121
+ return CCPetsDirectoryExists([home stringByAppendingPathComponent:@"antigravity-cli"]) ||
122
+ ([CanonicalHome(home) isEqual:CanonicalHome(OfficialHome(provider))] &&
123
+ CCPetsDirectoryExists([home stringByAppendingPathComponent:@"antigravity"]));
124
+ }
116
125
  NSString *other = [provider isEqualToString:CCPetsProfileProviderClaude]
117
126
  ? CCPetsProfileProviderCodex : CCPetsProfileProviderClaude;
118
127
  return HomeContainsAny(home, ProfileHomeMarkers(provider)) &&
@@ -203,7 +212,7 @@ NSDictionary *CCPetsProfileForHome(NSString *provider, NSString *home) {
203
212
  NSDictionary *CCPetsRegisterProfile(NSString *provider, NSString *home,
204
213
  NSString *displayName, NSString *existingID, NSString **errorMessage) {
205
214
  if (!ValidProvider(provider)) {
206
- if (errorMessage) *errorMessage = @"Provider must be claude or codex.";
215
+ if (errorMessage) *errorMessage = L(@"Provider must be claude, codex, or antigravity.");
207
216
  return nil;
208
217
  }
209
218
  NSString *canonical = CanonicalHome(home);
@@ -212,6 +221,11 @@ NSDictionary *CCPetsRegisterProfile(NSString *provider, NSString *home,
212
221
  if (errorMessage) *errorMessage = [NSString stringWithFormat:@"Profile Home is not a directory: %@", home ?: @""];
213
222
  return nil;
214
223
  }
224
+ if ([provider isEqualToString:CCPetsProfileProviderAntigravity] &&
225
+ !CCPetsProfileHomeMatchesProvider(provider, canonical)) {
226
+ if (errorMessage) *errorMessage = L(@"Choose a Gemini root folder containing the antigravity-cli directory.");
227
+ return nil;
228
+ }
215
229
  NSString *profileID = existingID.length > 0 ? existingID : CCPetsProfileID(provider, canonical);
216
230
  NSString *slug = CCPetsProfileSlug(canonical);
217
231
  NSString *name = [displayName stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
@@ -287,17 +301,22 @@ NSDictionary *CCPetsProfileStatus(NSDictionary *profile) {
287
301
  BOOL available = CCPetsDirectoryExists(home);
288
302
  if (!available) return @{@"state": CCPetsProfileStateUnavailable, @"available": @NO,
289
303
  @"petHooks": @NO, @"bridge": @NO};
290
- NSString *config = [home stringByAppendingPathComponent:
291
- [provider isEqualToString:CCPetsProfileProviderClaude] ? @"settings.json" : @"hooks.json"];
292
- NSString *petMarker = [provider isEqualToString:CCPetsProfileProviderClaude]
293
- ? CCPetsClaudeHookMarker : CCPetsCodexHookMarker;
294
- NSString *configText = [NSString stringWithContentsOfFile:config
295
- encoding:NSUTF8StringEncoding error:nil] ?: @"";
296
- NSString *profileID = [profile[@"id"] isKindOfClass:NSString.class] ? profile[@"id"] : @"";
297
- BOOL petHooks = [configText containsString:petMarker] &&
298
- (profileID.length == 0 || [configText containsString:profileID]);
299
- BOOL bridge = [configText containsString:CCBridgeHookMarker] &&
300
- (profileID.length == 0 || [configText containsString:profileID]);
304
+ BOOL petHooks, bridge;
305
+ if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
306
+ petHooks = CCPetsAntigravityPetHooksInstalled(profile);
307
+ bridge = CCPetsAntigravityBridgeInstalled(profile);
308
+ } else {
309
+ BOOL claude = [provider isEqualToString:CCPetsProfileProviderClaude];
310
+ NSString *config = [home stringByAppendingPathComponent:claude ? @"settings.json" : @"hooks.json"];
311
+ NSString *petMarker = claude ? CCPetsClaudeHookMarker : CCPetsCodexHookMarker;
312
+ NSString *configText = [NSString stringWithContentsOfFile:config
313
+ encoding:NSUTF8StringEncoding error:nil] ?: @"";
314
+ NSString *profileID = [profile[@"id"] isKindOfClass:NSString.class] ? profile[@"id"] : @"";
315
+ petHooks = [configText containsString:petMarker] &&
316
+ (profileID.length == 0 || [configText containsString:profileID]);
317
+ bridge = [configText containsString:CCBridgeHookMarker] &&
318
+ (profileID.length == 0 || [configText containsString:profileID]);
319
+ }
301
320
  BOOL bridgeExpected = CCBridgeEnabled();
302
321
  BOOL healthy = petHooks && (!bridgeExpected || bridge) && ![profile[@"needsRepair"] boolValue];
303
322
  return @{@"state": healthy ? CCPetsProfileStateIntegrated : CCPetsProfileStateRepair,
@@ -326,32 +345,36 @@ BOOL CCPetsMigrateManagedDefaultProfiles(NSString **errorMessage) {
326
345
  if (CCPetsProfileForHome(candidate[@"provider"], home)) continue;
327
346
  if (!CCPetsRegisterProfile(candidate[@"provider"], home, nil, nil, errorMessage)) return NO;
328
347
  }
348
+ NSString *home = OfficialHome(CCPetsProfileProviderAntigravity);
349
+ NSDictionary *antigravity = @{@"provider": CCPetsProfileProviderAntigravity, @"home": home,
350
+ @"id": CCPetsProfileID(CCPetsProfileProviderAntigravity, home)};
351
+ if (!CCPetsProfileForHome(CCPetsProfileProviderAntigravity, home) &&
352
+ CCPetsAntigravityPetHooksInstalled(antigravity)) {
353
+ return CCPetsRegisterProfile(CCPetsProfileProviderAntigravity, home, nil, nil, errorMessage) != nil;
354
+ }
329
355
  return YES;
330
356
  }
331
357
 
332
358
  BOOL CCPetsEnsureOfficialDefaultProfiles(NSString **errorMessage) {
333
- NSArray<NSDictionary *> *candidates = @[
334
- @{ @"provider": CCPetsProfileProviderClaude,
335
- @"home": [CCPetsHomeDirectory() stringByAppendingPathComponent:@".claude"] },
336
- @{ @"provider": CCPetsProfileProviderCodex,
337
- @"home": [CCPetsHomeDirectory() stringByAppendingPathComponent:@".codex"] }
338
- ];
339
- for (NSDictionary *candidate in candidates) {
340
- NSString *provider = candidate[@"provider"];
341
- NSString *home = candidate[@"home"];
359
+ for (NSString *provider in @[CCPetsProfileProviderClaude, CCPetsProfileProviderCodex, CCPetsProfileProviderAntigravity]) {
360
+ NSString *home = OfficialHome(provider);
342
361
  if (CCPetsProfileForHome(provider, home)) continue;
343
- BOOL isDirectory = NO;
344
- BOOL homeExists = [NSFileManager.defaultManager fileExistsAtPath:home isDirectory:&isDirectory] && isDirectory;
345
- BOOL cliInstalled = [provider isEqualToString:CCPetsProfileProviderClaude]
346
- ? CCPetsClaudeCLIInstalled() : CCPetsCodexCLIInstalled();
362
+ BOOL antigravity = [provider isEqualToString:CCPetsProfileProviderAntigravity];
363
+ NSString *dataHome = antigravity ? [home stringByAppendingPathComponent:@"antigravity-cli"] : home;
347
364
  // 官方 Home 是唯一允许自动发现的目录:已有目录直接登记;CLI 已安装但首次尚未
348
365
  // 生成目录时创建它。其他任何相似目录都只能由用户从菜单手动添加。
349
- if (!homeExists && !cliInstalled) continue;
350
- NSError *directoryError = nil;
351
- if (!homeExists && ![NSFileManager.defaultManager createDirectoryAtPath:home
352
- withIntermediateDirectories:YES attributes:nil error:&directoryError]) {
353
- if (errorMessage) *errorMessage = directoryError.localizedDescription;
354
- return NO;
366
+ if (!CCPetsDirectoryExists(dataHome) && !(antigravity && CCPetsProfileHomeMatchesProvider(provider, home))) {
367
+ BOOL cliInstalled;
368
+ if (antigravity) cliInstalled = CCPetsFindRealExecutable(@"agy", @"AGY_REAL_BIN") != nil;
369
+ else if ([provider isEqualToString:CCPetsProfileProviderClaude]) cliInstalled = CCPetsClaudeCLIInstalled();
370
+ else cliInstalled = CCPetsCodexCLIInstalled();
371
+ if (!cliInstalled) continue;
372
+ NSError *directoryError = nil;
373
+ if (![NSFileManager.defaultManager createDirectoryAtPath:dataHome
374
+ withIntermediateDirectories:YES attributes:nil error:&directoryError]) {
375
+ if (errorMessage) *errorMessage = directoryError.localizedDescription;
376
+ return NO;
377
+ }
355
378
  }
356
379
  if (!CCPetsRegisterProfile(provider, home, nil, nil, errorMessage)) return NO;
357
380
  }
@@ -363,38 +386,55 @@ static NSString *ValueAfter(NSArray<NSString *> *arguments, NSString *flag) {
363
386
  return index != NSNotFound && index + 1 < arguments.count ? arguments[index + 1] : nil;
364
387
  }
365
388
 
366
- static int AdaptProfile(NSDictionary *profile) {
389
+ static BOOL PrintReport(NSArray<NSString *> *report) {
390
+ BOOL succeeded = YES;
391
+ for (NSString *line in report) {
392
+ BOOL failed = [line hasPrefix:@"ERROR: "];
393
+ CCPetsPrintLine(failed ? stderr : stdout, line);
394
+ if (failed) succeeded = NO;
395
+ }
396
+ return succeeded;
397
+ }
398
+
399
+ static int InstallProfileHooks(NSDictionary *profile) {
367
400
  NSString *provider = profile[@"provider"], *home = profile[@"home"];
368
- CCPetsPrintLine(stdout, @"stage=hooks");
369
- int status = [provider isEqualToString:CCPetsProfileProviderClaude]
370
- ? InstallClaudeHooksAtHome(CCPetsExecutablePath(), home)
371
- : InstallCodexHooksAtHome(CCPetsExecutablePath(), home);
372
- if (status != 0) {
373
- CCPetsSetProfileNeedsRepair(profile[@"id"], YES, NULL);
374
- return status;
401
+ if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
402
+ return PrintReport(CCPetsInstallAntigravityPetHooks(profile)) ? 0 : 1;
375
403
  }
376
- if (CCBridgeEnabled()) {
377
- CCPetsPrintLine(stdout, @"stage=bridge");
378
- NSArray<NSString *> *report = nil;
379
- @try {
380
- report = CCBridgeInstallForProfile(profile, CCBridgeOptions(), YES);
381
- } @catch (NSException *exception) {
382
- CCPetsSetProfileNeedsRepair(profile[@"id"], YES, NULL);
383
- @throw;
384
- }
385
- BOOL bridgeFailed = NO;
386
- for (NSString *line in report) {
387
- CCPetsPrintLine([line hasPrefix:@"ERROR: "] ? stderr : stdout, line);
388
- if ([line hasPrefix:@"ERROR: "]) bridgeFailed = YES;
389
- }
390
- if (bridgeFailed) {
391
- CCPetsSetProfileNeedsRepair(profile[@"id"], YES, NULL);
392
- return 1;
404
+ if ([provider isEqualToString:CCPetsProfileProviderClaude]) {
405
+ return InstallClaudeHooksAtHome(CCPetsExecutablePath(), home);
406
+ }
407
+ return InstallCodexHooksAtHome(CCPetsExecutablePath(), home);
408
+ }
409
+
410
+ static int UninstallProfileHooks(NSDictionary *profile) {
411
+ NSString *provider = profile[@"provider"], *home = profile[@"home"];
412
+ if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
413
+ BOOL installed = CCPetsAntigravityPetHooksInstalled(profile);
414
+ if (!CCPetsRemoveAntigravityPetHooks(profile)) return 1;
415
+ if (installed) CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"Removed the CC Pets hooks in %@."), home]);
416
+ return 0;
417
+ }
418
+ if ([provider isEqualToString:CCPetsProfileProviderClaude]) return UninstallClaudeHooksAtHome(home);
419
+ return UninstallCodexHooksAtHome(home);
420
+ }
421
+
422
+ static int AdaptProfile(NSDictionary *profile) {
423
+ CCPetsPrintLine(stdout, @"stage=hooks");
424
+ int status;
425
+ @try {
426
+ status = InstallProfileHooks(profile);
427
+ if (status == 0 && CCBridgeEnabled()) {
428
+ CCPetsPrintLine(stdout, @"stage=bridge");
429
+ if (!PrintReport(CCBridgeInstallForProfile(profile, CCBridgeOptions(), YES))) status = 1;
393
430
  }
431
+ } @catch (NSException *exception) {
432
+ CCPetsSetProfileNeedsRepair(profile[@"id"], YES, NULL);
433
+ @throw;
394
434
  }
395
- CCPetsPrintLine(stdout, @"stage=verify");
396
- CCPetsSetProfileNeedsRepair(profile[@"id"], NO, NULL);
397
- return 0;
435
+ if (status == 0) CCPetsPrintLine(stdout, @"stage=verify");
436
+ CCPetsSetProfileNeedsRepair(profile[@"id"], status != 0, NULL);
437
+ return status;
398
438
  }
399
439
 
400
440
  int CCPetsProfileCommandMain(NSArray<NSString *> *arguments) {
@@ -468,12 +508,9 @@ int CCPetsProfileCommandMain(NSArray<NSString *> *arguments) {
468
508
  int status = AdaptProfile(profile);
469
509
  if (status != 0) return status;
470
510
  if (![oldProfile[@"home"] isEqualToString:profile[@"home"]]) {
471
- for (NSString *line in CCBridgeUninstallForProfile(oldProfile, CCBridgeShouldTouchMCP())) {
472
- CCPetsPrintLine(stdout, line);
473
- }
474
- status = [oldProfile[@"provider"] isEqualToString:CCPetsProfileProviderClaude]
475
- ? UninstallClaudeHooksAtHome(oldProfile[@"home"])
476
- : UninstallCodexHooksAtHome(oldProfile[@"home"]);
511
+ BOOL bridgeRemoved = PrintReport(CCBridgeUninstallForProfile(oldProfile, CCBridgeShouldTouchMCP()));
512
+ status = UninstallProfileHooks(oldProfile);
513
+ if (!bridgeRemoved && status == 0) status = 1;
477
514
  }
478
515
  return status;
479
516
  }
@@ -481,16 +518,10 @@ int CCPetsProfileCommandMain(NSArray<NSString *> *arguments) {
481
518
  NSString *profileID = ValueAfter(arguments, @"--id");
482
519
  NSDictionary *profile = CCPetsProfileWithID(profileID);
483
520
  if (!profile) { CCPetsPrintLine(stderr, @"Profile not found."); return 1; }
484
- BOOL bridgeFailed = NO;
485
- for (NSString *line in CCBridgeUninstallForProfile(profile, CCBridgeShouldTouchMCP())) {
486
- CCPetsPrintLine([line hasPrefix:@"ERROR: "] ? stderr : stdout, line);
487
- if ([line hasPrefix:@"ERROR: "]) bridgeFailed = YES;
488
- }
489
- int status = [profile[@"provider"] isEqualToString:CCPetsProfileProviderClaude]
490
- ? UninstallClaudeHooksAtHome(profile[@"home"])
491
- : UninstallCodexHooksAtHome(profile[@"home"]);
521
+ BOOL bridgeRemoved = PrintReport(CCBridgeUninstallForProfile(profile, CCBridgeShouldTouchMCP()));
522
+ int status = UninstallProfileHooks(profile);
492
523
  if (status != 0) return status;
493
- if (bridgeFailed) {
524
+ if (!bridgeRemoved) {
494
525
  CCPetsSetProfileNeedsRepair(profileID, YES, NULL);
495
526
  return 1;
496
527
  }
@@ -5,16 +5,26 @@
5
5
  // 由 Codex 共享服务(app-server --managed-daemon)拉起的 hook 返回空目标,见实现处注释。
6
6
  NSDictionary *TerminalFocusTargetFromEnvironment(void);
7
7
  BOOL TerminalFocusRunsUnderSharedAgentHost(void);
8
+ // 桌面宿主不使用终端 TTY;事件时间必须属于当前应用实例,避免重启后复活旧会话。
9
+ BOOL IsCodexDesktopFocusTarget(NSDictionary *target);
10
+ BOOL CodexDesktopFocusTargetIsLive(NSDictionary *target, NSTimeInterval eventTime);
11
+ BOOL CodexDesktopApplicationIsRunning(void);
12
+ BOOL AntigravityDesktopApplicationIsRunning(void);
13
+ // Antigravity App 会话的回跳目标只有 bundleID,没有 TTY。
14
+ extern NSString *const CCPetsAntigravityAppBundleIdentifier;
15
+ BOOL IsAntigravityDesktopFocusTarget(NSDictionary *target);
16
+ // 只读本地聊天索引;YES 为已持久化聊天,NO 为未收录/已归档,nil 为无法确认。
17
+ NSNumber *CodexPersistentThreadStatus(NSString *thread, NSString *codexHome);
8
18
 
9
19
  // hook 用:普通情况同 TerminalFocusTargetFromEnvironment;Codex 共享服务下按会话 ID 找
10
20
  // codex-with-pet 登记的终端,找不到返回空目标。
11
21
  NSDictionary *TerminalFocusTargetForHook(NSDictionary *payload, NSString *provider);
12
22
  // cc-pets --codex-launch:codex-with-pet 在 exec 真正的 codex 之前登记自己的终端。
13
23
  int RegisterCodexLaunch(void);
14
- // 以下两个供测试直接驱动。
15
24
  BOOL RegisterCodexLaunchForProcess(pid_t pid, NSString *cwd, NSDictionary *terminal,
16
25
  NSTimeInterval launchedAt);
17
26
  NSDictionary *CodexLaunchTerminalForThread(NSString *thread, NSDictionary *payload);
27
+ BOOL CodexHasTerminalTitleLaunch(NSString *cwd);
18
28
 
19
29
  // Terminal / iTerm2 / Ghostty 按 TTY 精确选择;JetBrains IDE 和 VS Code 家族通过插件/扩展
20
30
  // 异步聚焦。YES 表示已执行或已交给插件处理,其他终端在无扩展模式下激活应用。