cc-pets 2.2.1 → 2.4.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.
- package/CC_BRIDGE.md +24 -2
- package/CC_BRIDGE.zh-CN.md +19 -2
- package/CHANGELOG.md +111 -0
- package/CHANGELOG.zh-CN.md +111 -0
- package/CONTRIBUTING.md +35 -10
- package/CONTRIBUTING.zh-CN.md +28 -10
- package/README.md +212 -32
- package/README.zh-CN.md +167 -36
- package/Resources/AgentIcons/claude.png +0 -0
- package/Resources/AgentIcons/codex.icns +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.vsix +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.zip +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +699 -20
- package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
- package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +90 -25
- package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
- package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +17 -3
- package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +71 -23
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
- package/Sources/CCPets/{CCPetsAppDelegate+Settings.m → App/CCPetsAppDelegate+Settings.m} +87 -102
- package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +121 -51
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
- package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +17 -2
- package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +107 -11
- package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
- package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
- package/Sources/CCPets/{main.m → App/main.m} +74 -1
- package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
- package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +43 -23
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +832 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +59 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +576 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +507 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +106 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +897 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
- package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.h +21 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.m +503 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +367 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
- package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +2 -1
- package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +148 -36
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.m +64 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.h +23 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.m +475 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
- package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +11 -2
- package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +19 -2
- package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +4 -1
- package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
- package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
- package/Sources/CCPets/Pet/PetView+Private.h +81 -0
- package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
- package/Sources/CCPets/Pet/PetView.m +635 -0
- package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
- package/Sources/CCPets/Support/CCPetsDoctor.m +646 -0
- package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
- package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
- package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
- package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
- package/Sources/CCPets/Support/CCPetsPreferences.h +33 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +117 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +44 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +279 -0
- package/Sources/CCPets/UI/CCPetsGlassView.h +57 -0
- package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +60 -11
- package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
- package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +64 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +1412 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +135 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +865 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +288 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +712 -0
- package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
- package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
- package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
- package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
- package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
- package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexBackground.m +193 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +97 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +323 -0
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
- package/Sources/CCPets/Usage/CCPetsUsage.h +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +174 -19
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +598 -0
- package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
- package/Sources/CCPets/Usage/QuotaDashboardView.m +713 -0
- package/THIRD_PARTY_NOTICES.md +8 -4
- package/THIRD_PARTY_NOTICES.zh-CN.md +6 -2
- package/bin/cc-pets +8 -6
- package/bin/claude-with-pet +12 -2
- package/bin/codex-with-pet +15 -5
- package/package.json +5 -1
- package/plugins/jetbrains/README.md +62 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalBridge.java +379 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalIdentity.java +24 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalStartup.java +12 -0
- package/plugins/jetbrains/src/main/resources/META-INF/plugin.xml +23 -0
- package/plugins/jetbrains/src/main/resources/META-INF/pluginIcon.svg +380 -0
- package/plugins/vscode/README.md +63 -0
- package/plugins/vscode/extension.js +210 -0
- package/plugins/vscode/package.json +18 -0
- package/scripts/build-idea-plugin.sh +101 -0
- package/scripts/build-vscode-extension.sh +112 -0
- package/scripts/build.sh +31 -5
- package/scripts/compile-cached.zsh +133 -0
- package/scripts/i18n.zsh +9 -52
- package/scripts/install-app.sh +4 -0
- package/scripts/install-shell-integration.sh +17 -10
- package/scripts/uninstall-shell-integration.sh +6 -1
- package/Sources/CCPets/CCPetsEvents.h +0 -10
- package/Sources/CCPets/CCPetsGlassView.h +0 -31
- package/Sources/CCPets/CCPetsUsage.h +0 -36
- package/Sources/CCPets/CCPetsUsage.m +0 -2069
- package/Sources/CCPets/PetView.m +0 -1839
- package/Sources/CCPets/QuotaDashboardView.m +0 -1145
- package/scripts/bridge/cli.mjs +0 -237
- package/scripts/bridge/core.mjs +0 -228
- package/scripts/bridge/hook.mjs +0 -150
- package/scripts/bridge/install.mjs +0 -311
- package/scripts/bridge/mcp-server.mjs +0 -308
- package/scripts/bridge/options.mjs +0 -87
- package/scripts/bridge/process.mjs +0 -151
- package/scripts/bridge/reservations.mjs +0 -248
- package/scripts/bridge/store.mjs +0 -433
- package/scripts/bridge/watch.mjs +0 -69
- package/scripts/check-l10n.mjs +0 -168
- package/scripts/configure-updater.mjs +0 -43
- package/scripts/detect-cli.mjs +0 -68
- package/scripts/doctor.mjs +0 -470
- package/scripts/i18n.mjs +0 -122
- package/scripts/install-claude-hooks.mjs +0 -253
- package/scripts/install-codex-hooks.mjs +0 -78
- package/scripts/integration-markers.mjs +0 -51
- package/scripts/locales/zh-Hans.json +0 -366
- package/scripts/pet-store.mjs +0 -415
- package/scripts/uninstall-integrations.mjs +0 -205
- /package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.h → Pet/CCPetsImageLoader.h} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.h → Pet/CCPetsPetSize.h} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.m → Pet/CCPetsPetSize.m} +0 -0
- /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
- /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +0 -0
- /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.h → UI/MenuPetSizeView.h} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.m → UI/MenuPetSizeView.m} +0 -0
- /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
#import "CCPetsProfiles.h"
|
|
2
|
+
#import "CCPetsBridge.h"
|
|
3
|
+
#import "CCPetsBridgeSetup.h"
|
|
4
|
+
#import "CCPetsCLISupport.h"
|
|
5
|
+
#import "CCPetsIntegrations.h"
|
|
6
|
+
#import "CCPetsJSON.h"
|
|
7
|
+
#import "CCPetsL10n.h"
|
|
8
|
+
#import <sys/stat.h>
|
|
9
|
+
|
|
10
|
+
NSString *const CCPetsProfileProviderClaude = @"claude";
|
|
11
|
+
NSString *const CCPetsProfileProviderCodex = @"codex";
|
|
12
|
+
NSNotificationName const CCPetsProfilesDidChangeNotification = @"CCPetsProfilesDidChange";
|
|
13
|
+
NSString *const CCPetsProfileStateIntegrated = @"integrated";
|
|
14
|
+
NSString *const CCPetsProfileStateRepair = @"repair";
|
|
15
|
+
NSString *const CCPetsProfileStateUnavailable = @"unavailable";
|
|
16
|
+
|
|
17
|
+
static NSString *ProfilesDirectory(void) {
|
|
18
|
+
return [CCPetsHomeDirectory() stringByAppendingPathComponent:@".cc-pets"];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
NSString *CCPetsProfilesPath(void) {
|
|
22
|
+
return [ProfilesDirectory() stringByAppendingPathComponent:@"agent-profiles.json"];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static BOOL ValidProvider(NSString *provider) {
|
|
26
|
+
return [provider isEqualToString:CCPetsProfileProviderClaude] ||
|
|
27
|
+
[provider isEqualToString:CCPetsProfileProviderCodex];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static NSString *CanonicalHome(NSString *home) {
|
|
31
|
+
if (![home isKindOfClass:NSString.class] || home.length == 0) return nil;
|
|
32
|
+
NSString *expanded = [home stringByExpandingTildeInPath];
|
|
33
|
+
NSString *resolved = CCPetsRealPath(expanded);
|
|
34
|
+
return resolved ?: CCPetsResolvePath(expanded);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static uint64_t StablePathHash(NSString *text) {
|
|
38
|
+
uint64_t hash = 1469598103934665603ULL;
|
|
39
|
+
const unsigned char *bytes = (const unsigned char *)text.UTF8String;
|
|
40
|
+
for (const unsigned char *cursor = bytes; cursor && *cursor; cursor++) {
|
|
41
|
+
hash ^= (uint64_t)*cursor;
|
|
42
|
+
hash *= 1099511628211ULL;
|
|
43
|
+
}
|
|
44
|
+
return hash;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
NSString *CCPetsProfileID(NSString *provider, NSString *home) {
|
|
48
|
+
NSString *canonical = CanonicalHome(home);
|
|
49
|
+
if (!ValidProvider(provider) || canonical.length == 0) return nil;
|
|
50
|
+
NSString *source = [NSString stringWithFormat:@"%@:%@", provider, canonical];
|
|
51
|
+
return [NSString stringWithFormat:@"%@:%016llx", provider,
|
|
52
|
+
(unsigned long long)StablePathHash(source)];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
NSString *CCPetsProfileSlug(NSString *home) {
|
|
56
|
+
NSString *name = CanonicalHome(home).lastPathComponent ?: @"";
|
|
57
|
+
while ([name hasPrefix:@"."]) name = [name substringFromIndex:1];
|
|
58
|
+
return name.length > 0 ? name : @"profile";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static NSString *LegacyFriendlyDisplayName(NSString *provider, NSString *home) {
|
|
62
|
+
NSString *slug = CCPetsProfileSlug(home);
|
|
63
|
+
NSMutableArray<NSString *> *words = [NSMutableArray array];
|
|
64
|
+
for (NSString *part in [slug componentsSeparatedByCharactersInSet:
|
|
65
|
+
[NSCharacterSet characterSetWithCharactersInString:@"-_ "]]) {
|
|
66
|
+
if (part.length == 0) continue;
|
|
67
|
+
if ([part.lowercaseString isEqualToString:@"claude"]) [words addObject:@"Claude"];
|
|
68
|
+
else if ([part.lowercaseString isEqualToString:@"codex"]) [words addObject:@"Codex"];
|
|
69
|
+
else [words addObject:part.uppercaseString];
|
|
70
|
+
}
|
|
71
|
+
if (words.count == 0) {
|
|
72
|
+
return [provider isEqualToString:CCPetsProfileProviderClaude] ? @"Claude" : @"Codex";
|
|
73
|
+
}
|
|
74
|
+
return [words componentsJoinedByString:@" "];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
NSString *CCPetsProfileDefaultDisplayName(NSString *provider, NSString *home) {
|
|
78
|
+
(void)provider;
|
|
79
|
+
return CCPetsProfileSlug(home);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
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]);
|
|
88
|
+
return official.length > 0 && [CanonicalHome(profile[@"home"]) isEqualToString:official];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// sessions/ 不能当 Codex 的特征:Claude Code 也会建 <Home>/sessions/<pid>.json,靠它判定时
|
|
92
|
+
// 选错的 Claude Home 会被当成 Codex 登记,集成步骤再把 Codex 的 config.toml / hooks.json 写进去。
|
|
93
|
+
static NSArray<NSString *> *ProfileHomeMarkers(NSString *provider) {
|
|
94
|
+
return [provider isEqualToString:CCPetsProfileProviderClaude]
|
|
95
|
+
? @[@"settings.json", @".claude.json", @"projects"]
|
|
96
|
+
: @[@"config.toml", @"hooks.json", @"auth.json", @"version.json"];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 另一家独有、只会由 Agent 自己写出的文件。settings.json / config.toml / hooks.json 不算:
|
|
100
|
+
// CC Pets 集成时会写它们,装错过一次的 Home 会因此被永久挡在外面。
|
|
101
|
+
static NSArray<NSString *> *ProfileHomeExclusiveMarkers(NSString *provider) {
|
|
102
|
+
return [provider isEqualToString:CCPetsProfileProviderClaude]
|
|
103
|
+
? @[@".claude.json", @"projects"]
|
|
104
|
+
: @[@"auth.json", @"version.json"];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static BOOL HomeContainsAny(NSString *home, NSArray<NSString *> *names) {
|
|
108
|
+
for (NSString *name in names) {
|
|
109
|
+
if ([NSFileManager.defaultManager fileExistsAtPath:[home stringByAppendingPathComponent:name]]) return YES;
|
|
110
|
+
}
|
|
111
|
+
return NO;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
BOOL CCPetsProfileHomeMatchesProvider(NSString *provider, NSString *home) {
|
|
115
|
+
if (!ValidProvider(provider) || home.length == 0) return NO;
|
|
116
|
+
NSString *other = [provider isEqualToString:CCPetsProfileProviderClaude]
|
|
117
|
+
? CCPetsProfileProviderCodex : CCPetsProfileProviderClaude;
|
|
118
|
+
return HomeContainsAny(home, ProfileHomeMarkers(provider)) &&
|
|
119
|
+
!HomeContainsAny(home, ProfileHomeExclusiveMarkers(other));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static NSDictionary *EmptyDocument(void) {
|
|
123
|
+
return @{@"schemaVersion": @1, @"profiles": @[]};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static NSDictionary *ReadDocument(void) {
|
|
127
|
+
NSData *data = [NSData dataWithContentsOfFile:CCPetsProfilesPath()];
|
|
128
|
+
NSDictionary *document = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
129
|
+
if (![document isKindOfClass:NSDictionary.class] || [document[@"schemaVersion"] integerValue] != 1 ||
|
|
130
|
+
![document[@"profiles"] isKindOfClass:NSArray.class]) return EmptyDocument();
|
|
131
|
+
return document;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static BOOL WriteProfiles(NSArray<NSDictionary *> *profiles, NSString **errorMessage) {
|
|
135
|
+
[NSFileManager.defaultManager createDirectoryAtPath:ProfilesDirectory()
|
|
136
|
+
withIntermediateDirectories:YES attributes:@{NSFilePosixPermissions: @0700} error:nil];
|
|
137
|
+
NSDictionary *document = @{@"schemaVersion": @1, @"profiles": profiles ?: @[]};
|
|
138
|
+
NSData *data = [NSJSONSerialization dataWithJSONObject:document
|
|
139
|
+
options:NSJSONWritingPrettyPrinted | NSJSONWritingSortedKeys | NSJSONWritingWithoutEscapingSlashes error:nil];
|
|
140
|
+
if (!data) {
|
|
141
|
+
if (errorMessage) *errorMessage = @"Unable to encode agent profile registry.";
|
|
142
|
+
return NO;
|
|
143
|
+
}
|
|
144
|
+
NSString *text = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]
|
|
145
|
+
stringByAppendingString:@"\n"];
|
|
146
|
+
return CCPetsWriteFileAtomically(CCPetsProfilesPath(), text, 0600, errorMessage);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
NSArray<NSDictionary *> *CCPetsProfiles(void) {
|
|
150
|
+
NSMutableArray<NSDictionary *> *valid = [NSMutableArray array];
|
|
151
|
+
for (id entry in ReadDocument()[@"profiles"]) {
|
|
152
|
+
if (![entry isKindOfClass:NSDictionary.class]) continue;
|
|
153
|
+
NSString *profileID = entry[@"id"], *provider = entry[@"provider"], *home = entry[@"home"];
|
|
154
|
+
if (![profileID isKindOfClass:NSString.class] || !ValidProvider(provider) ||
|
|
155
|
+
![home isKindOfClass:NSString.class] || home.length == 0) continue;
|
|
156
|
+
NSMutableDictionary *profile = [entry mutableCopy];
|
|
157
|
+
NSString *rawName = CCPetsProfileDefaultDisplayName(provider, home);
|
|
158
|
+
NSString *storedName = [entry[@"displayName"] isKindOfClass:NSString.class]
|
|
159
|
+
? entry[@"displayName"] : nil;
|
|
160
|
+
NSNumber *customName = [entry[@"customName"] isKindOfClass:NSNumber.class]
|
|
161
|
+
? entry[@"customName"] : nil;
|
|
162
|
+
// 早期手动添加流程把自动生成的文件夹名也误记成了“自定义”。两者完全相同
|
|
163
|
+
// 时恢复为自动名称,重新定位 Home 后才能自然跟随新的文件夹名。
|
|
164
|
+
if ([customName boolValue] && [storedName isEqualToString:rawName]) customName = @NO;
|
|
165
|
+
if (!customName) {
|
|
166
|
+
NSString *legacyName = LegacyFriendlyDisplayName(provider, home);
|
|
167
|
+
BOOL wasCustomized = storedName.length > 0 &&
|
|
168
|
+
![storedName isEqualToString:legacyName] && ![storedName isEqualToString:rawName];
|
|
169
|
+
customName = @(wasCustomized);
|
|
170
|
+
}
|
|
171
|
+
profile[@"customName"] = customName;
|
|
172
|
+
if (![customName boolValue]) profile[@"displayName"] = rawName;
|
|
173
|
+
else if (storedName.length == 0) profile[@"displayName"] = rawName;
|
|
174
|
+
profile[@"slug"] = CCPetsProfileSlug(home);
|
|
175
|
+
[valid addObject:profile];
|
|
176
|
+
}
|
|
177
|
+
return valid;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
NSArray<NSDictionary *> *CCPetsProfilesForProvider(NSString *provider) {
|
|
181
|
+
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(NSDictionary *profile, NSDictionary *bindings) {
|
|
182
|
+
return [profile[@"provider"] isEqualToString:provider];
|
|
183
|
+
}];
|
|
184
|
+
return [CCPetsProfiles() filteredArrayUsingPredicate:predicate];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
NSDictionary *CCPetsProfileWithID(NSString *profileID) {
|
|
188
|
+
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
189
|
+
if ([profile[@"id"] isEqualToString:profileID]) return profile;
|
|
190
|
+
}
|
|
191
|
+
return nil;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
NSDictionary *CCPetsProfileForHome(NSString *provider, NSString *home) {
|
|
195
|
+
NSString *canonical = CanonicalHome(home);
|
|
196
|
+
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
197
|
+
if ([profile[@"provider"] isEqualToString:provider] &&
|
|
198
|
+
[profile[@"home"] isEqualToString:canonical]) return profile;
|
|
199
|
+
}
|
|
200
|
+
return nil;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
NSDictionary *CCPetsRegisterProfile(NSString *provider, NSString *home,
|
|
204
|
+
NSString *displayName, NSString *existingID, NSString **errorMessage) {
|
|
205
|
+
if (!ValidProvider(provider)) {
|
|
206
|
+
if (errorMessage) *errorMessage = @"Provider must be claude or codex.";
|
|
207
|
+
return nil;
|
|
208
|
+
}
|
|
209
|
+
NSString *canonical = CanonicalHome(home);
|
|
210
|
+
BOOL isDirectory = NO;
|
|
211
|
+
if (canonical.length == 0 || ![NSFileManager.defaultManager fileExistsAtPath:canonical isDirectory:&isDirectory] || !isDirectory) {
|
|
212
|
+
if (errorMessage) *errorMessage = [NSString stringWithFormat:@"Profile Home is not a directory: %@", home ?: @""];
|
|
213
|
+
return nil;
|
|
214
|
+
}
|
|
215
|
+
NSString *profileID = existingID.length > 0 ? existingID : CCPetsProfileID(provider, canonical);
|
|
216
|
+
NSString *slug = CCPetsProfileSlug(canonical);
|
|
217
|
+
NSString *name = [displayName stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
218
|
+
BOOL customName = name.length > 0;
|
|
219
|
+
if (!customName) name = CCPetsProfileDefaultDisplayName(provider, canonical);
|
|
220
|
+
NSMutableArray<NSDictionary *> *profiles = [CCPetsProfiles() mutableCopy];
|
|
221
|
+
NSUInteger replacement = NSNotFound;
|
|
222
|
+
for (NSUInteger index = 0; index < profiles.count; index++) {
|
|
223
|
+
NSDictionary *candidate = profiles[index];
|
|
224
|
+
if (existingID.length > 0 && ![candidate[@"id"] isEqualToString:existingID] &&
|
|
225
|
+
[candidate[@"provider"] isEqualToString:provider] &&
|
|
226
|
+
[candidate[@"home"] isEqualToString:canonical]) {
|
|
227
|
+
if (errorMessage) *errorMessage = @"That Agent Home is already registered.";
|
|
228
|
+
return nil;
|
|
229
|
+
}
|
|
230
|
+
if ([candidate[@"id"] isEqualToString:profileID] ||
|
|
231
|
+
([candidate[@"provider"] isEqualToString:provider] && [candidate[@"home"] isEqualToString:canonical])) {
|
|
232
|
+
replacement = index;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
NSNumber *addedAt = replacement == NSNotFound ? @(NSDate.date.timeIntervalSince1970) : profiles[replacement][@"addedAt"];
|
|
237
|
+
NSMutableDictionary *profile = [@{
|
|
238
|
+
@"id": profileID,
|
|
239
|
+
@"provider": provider,
|
|
240
|
+
@"home": canonical,
|
|
241
|
+
@"slug": slug,
|
|
242
|
+
@"displayName": name,
|
|
243
|
+
@"customName": @(customName),
|
|
244
|
+
@"bridgePolicy": @"followGlobal",
|
|
245
|
+
@"addedAt": addedAt ?: @(NSDate.date.timeIntervalSince1970)
|
|
246
|
+
} mutableCopy];
|
|
247
|
+
if (replacement != NSNotFound && [profiles[replacement][@"needsRepair"] boolValue]) {
|
|
248
|
+
profile[@"needsRepair"] = @YES;
|
|
249
|
+
}
|
|
250
|
+
if (replacement == NSNotFound) [profiles addObject:profile]; else profiles[replacement] = profile;
|
|
251
|
+
if (!WriteProfiles(profiles, errorMessage)) return nil;
|
|
252
|
+
return profile;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
BOOL CCPetsForgetProfile(NSString *profileID, NSString **errorMessage) {
|
|
256
|
+
NSMutableArray<NSDictionary *> *profiles = [CCPetsProfiles() mutableCopy];
|
|
257
|
+
NSIndexSet *matches = [profiles indexesOfObjectsPassingTest:^BOOL(NSDictionary *profile, NSUInteger index, BOOL *stop) {
|
|
258
|
+
return [profile[@"id"] isEqualToString:profileID];
|
|
259
|
+
}];
|
|
260
|
+
if (matches.count == 0) return YES;
|
|
261
|
+
[profiles removeObjectsAtIndexes:matches];
|
|
262
|
+
return WriteProfiles(profiles, errorMessage);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
BOOL CCPetsSetProfileNeedsRepair(NSString *profileID, BOOL needsRepair, NSString **errorMessage) {
|
|
266
|
+
NSMutableArray<NSDictionary *> *profiles = [CCPetsProfiles() mutableCopy];
|
|
267
|
+
BOOL found = NO;
|
|
268
|
+
for (NSUInteger index = 0; index < profiles.count; index++) {
|
|
269
|
+
if (![profiles[index][@"id"] isEqualToString:profileID]) continue;
|
|
270
|
+
NSMutableDictionary *updated = [profiles[index] mutableCopy];
|
|
271
|
+
if (needsRepair) updated[@"needsRepair"] = @YES;
|
|
272
|
+
else [updated removeObjectForKey:@"needsRepair"];
|
|
273
|
+
profiles[index] = updated;
|
|
274
|
+
found = YES;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
return !found || WriteProfiles(profiles, errorMessage);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static BOOL FileContainsMarker(NSString *path, NSString *marker) {
|
|
281
|
+
NSString *text = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
|
282
|
+
return text.length > 0 && [text containsString:marker];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
NSDictionary *CCPetsProfileStatus(NSDictionary *profile) {
|
|
286
|
+
NSString *provider = profile[@"provider"], *home = profile[@"home"];
|
|
287
|
+
BOOL available = CCPetsDirectoryExists(home);
|
|
288
|
+
if (!available) return @{@"state": CCPetsProfileStateUnavailable, @"available": @NO,
|
|
289
|
+
@"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]);
|
|
301
|
+
BOOL bridgeExpected = CCBridgeEnabled();
|
|
302
|
+
BOOL healthy = petHooks && (!bridgeExpected || bridge) && ![profile[@"needsRepair"] boolValue];
|
|
303
|
+
return @{@"state": healthy ? CCPetsProfileStateIntegrated : CCPetsProfileStateRepair,
|
|
304
|
+
@"available": @YES, @"petHooks": @(petHooks), @"bridge": @(bridge)};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
NSString *CCPetsProfileStateTitle(NSString *state) {
|
|
308
|
+
if ([state isEqualToString:CCPetsProfileStateIntegrated]) return L(@"Integrated");
|
|
309
|
+
if ([state isEqualToString:CCPetsProfileStateUnavailable]) return L(@"Home unavailable");
|
|
310
|
+
return L(@"Needs repair");
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
BOOL CCPetsMigrateManagedDefaultProfiles(NSString **errorMessage) {
|
|
314
|
+
NSArray<NSDictionary *> *candidates = @[
|
|
315
|
+
@{@"provider": CCPetsProfileProviderClaude,
|
|
316
|
+
@"home": [CCPetsHomeDirectory() stringByAppendingPathComponent:@".claude"],
|
|
317
|
+
@"file": @"settings.json", @"marker": CCPetsClaudeHookMarker},
|
|
318
|
+
@{@"provider": CCPetsProfileProviderCodex,
|
|
319
|
+
@"home": [CCPetsHomeDirectory() stringByAppendingPathComponent:@".codex"],
|
|
320
|
+
@"file": @"hooks.json", @"marker": CCPetsCodexHookMarker}
|
|
321
|
+
];
|
|
322
|
+
for (NSDictionary *candidate in candidates) {
|
|
323
|
+
NSString *home = candidate[@"home"];
|
|
324
|
+
NSString *file = [home stringByAppendingPathComponent:candidate[@"file"]];
|
|
325
|
+
if (!FileContainsMarker(file, candidate[@"marker"])) continue;
|
|
326
|
+
if (CCPetsProfileForHome(candidate[@"provider"], home)) continue;
|
|
327
|
+
if (!CCPetsRegisterProfile(candidate[@"provider"], home, nil, nil, errorMessage)) return NO;
|
|
328
|
+
}
|
|
329
|
+
return YES;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
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"];
|
|
342
|
+
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();
|
|
347
|
+
// 官方 Home 是唯一允许自动发现的目录:已有目录直接登记;CLI 已安装但首次尚未
|
|
348
|
+
// 生成目录时创建它。其他任何相似目录都只能由用户从菜单手动添加。
|
|
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;
|
|
355
|
+
}
|
|
356
|
+
if (!CCPetsRegisterProfile(provider, home, nil, nil, errorMessage)) return NO;
|
|
357
|
+
}
|
|
358
|
+
return YES;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
static NSString *ValueAfter(NSArray<NSString *> *arguments, NSString *flag) {
|
|
362
|
+
NSUInteger index = [arguments indexOfObject:flag];
|
|
363
|
+
return index != NSNotFound && index + 1 < arguments.count ? arguments[index + 1] : nil;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
static int AdaptProfile(NSDictionary *profile) {
|
|
367
|
+
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;
|
|
375
|
+
}
|
|
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;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
CCPetsPrintLine(stdout, @"stage=verify");
|
|
396
|
+
CCPetsSetProfileNeedsRepair(profile[@"id"], NO, NULL);
|
|
397
|
+
return 0;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
int CCPetsProfileCommandMain(NSArray<NSString *> *arguments) {
|
|
401
|
+
@try {
|
|
402
|
+
NSString *command = arguments.firstObject;
|
|
403
|
+
if ([command isEqualToString:@"list"]) {
|
|
404
|
+
NSData *json = [NSJSONSerialization dataWithJSONObject:CCPetsProfiles()
|
|
405
|
+
options:NSJSONWritingPrettyPrinted | NSJSONWritingWithoutEscapingSlashes error:nil];
|
|
406
|
+
fwrite(json.bytes, 1, json.length, stdout); fputc('\n', stdout);
|
|
407
|
+
return 0;
|
|
408
|
+
}
|
|
409
|
+
if ([command isEqualToString:@"resolve"]) {
|
|
410
|
+
NSDictionary *profile = CCPetsProfileForHome(ValueAfter(arguments, @"--provider"),
|
|
411
|
+
ValueAfter(arguments, @"--home"));
|
|
412
|
+
if (!profile) return 1;
|
|
413
|
+
NSString *field = ValueAfter(arguments, @"--field");
|
|
414
|
+
CCPetsPrintLine(stdout, [field isEqualToString:@"name"]
|
|
415
|
+
? (profile[@"displayName"] ?: profile[@"slug"] ?: @"") : profile[@"id"]);
|
|
416
|
+
return 0;
|
|
417
|
+
}
|
|
418
|
+
if ([command isEqualToString:@"migrate"]) {
|
|
419
|
+
NSString *error = nil;
|
|
420
|
+
if (!CCPetsMigrateManagedDefaultProfiles(&error)) {
|
|
421
|
+
CCPetsPrintLine(stderr, error); return 1;
|
|
422
|
+
}
|
|
423
|
+
return 0;
|
|
424
|
+
}
|
|
425
|
+
if ([command isEqualToString:@"ensure-defaults"]) {
|
|
426
|
+
NSString *error = nil;
|
|
427
|
+
if (!CCPetsEnsureOfficialDefaultProfiles(&error)) {
|
|
428
|
+
CCPetsPrintLine(stderr, error); return 1;
|
|
429
|
+
}
|
|
430
|
+
return 0;
|
|
431
|
+
}
|
|
432
|
+
if ([command isEqualToString:@"add"]) {
|
|
433
|
+
NSString *provider = ValueAfter(arguments, @"--provider");
|
|
434
|
+
NSString *home = ValueAfter(arguments, @"--home");
|
|
435
|
+
NSString *name = ValueAfter(arguments, @"--name");
|
|
436
|
+
NSString *error = nil;
|
|
437
|
+
NSDictionary *profile = CCPetsRegisterProfile(provider, home, name, nil, &error);
|
|
438
|
+
if (!profile) { CCPetsPrintLine(stderr, error); return 1; }
|
|
439
|
+
CCPetsPrintLine(stdout, @"stage=registered");
|
|
440
|
+
return AdaptProfile(profile);
|
|
441
|
+
}
|
|
442
|
+
if ([command isEqualToString:@"repair"]) {
|
|
443
|
+
NSDictionary *profile = CCPetsProfileWithID(ValueAfter(arguments, @"--id"));
|
|
444
|
+
if (!profile) { CCPetsPrintLine(stderr, @"Profile not found."); return 1; }
|
|
445
|
+
return AdaptProfile(profile);
|
|
446
|
+
}
|
|
447
|
+
if ([command isEqualToString:@"repair-all"]) {
|
|
448
|
+
BOOL failed = NO;
|
|
449
|
+
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
450
|
+
CCPetsPrintLine(stdout, [NSString stringWithFormat:@"profile=%@", profile[@"displayName"]]);
|
|
451
|
+
if (AdaptProfile(profile) != 0) failed = YES;
|
|
452
|
+
}
|
|
453
|
+
return failed ? 1 : 0;
|
|
454
|
+
}
|
|
455
|
+
if ([command isEqualToString:@"update"]) {
|
|
456
|
+
NSString *profileID = ValueAfter(arguments, @"--id");
|
|
457
|
+
NSDictionary *oldProfile = CCPetsProfileWithID(profileID);
|
|
458
|
+
if (!oldProfile) { CCPetsPrintLine(stderr, @"Profile not found."); return 1; }
|
|
459
|
+
NSString *home = ValueAfter(arguments, @"--home") ?: oldProfile[@"home"];
|
|
460
|
+
NSString *requestedName = ValueAfter(arguments, @"--name");
|
|
461
|
+
NSString *name = requestedName ?: ([oldProfile[@"customName"] boolValue]
|
|
462
|
+
? oldProfile[@"displayName"] : nil);
|
|
463
|
+
NSString *error = nil;
|
|
464
|
+
NSDictionary *profile = CCPetsRegisterProfile(oldProfile[@"provider"], home,
|
|
465
|
+
name, profileID, &error);
|
|
466
|
+
if (!profile) { CCPetsPrintLine(stderr, error); return 1; }
|
|
467
|
+
CCPetsPrintLine(stdout, @"stage=registered");
|
|
468
|
+
int status = AdaptProfile(profile);
|
|
469
|
+
if (status != 0) return status;
|
|
470
|
+
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"]);
|
|
477
|
+
}
|
|
478
|
+
return status;
|
|
479
|
+
}
|
|
480
|
+
if ([command isEqualToString:@"remove"]) {
|
|
481
|
+
NSString *profileID = ValueAfter(arguments, @"--id");
|
|
482
|
+
NSDictionary *profile = CCPetsProfileWithID(profileID);
|
|
483
|
+
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"]);
|
|
492
|
+
if (status != 0) return status;
|
|
493
|
+
if (bridgeFailed) {
|
|
494
|
+
CCPetsSetProfileNeedsRepair(profileID, YES, NULL);
|
|
495
|
+
return 1;
|
|
496
|
+
}
|
|
497
|
+
NSString *error = nil;
|
|
498
|
+
if (!CCPetsForgetProfile(profileID, &error)) {
|
|
499
|
+
CCPetsPrintLine(stderr, error); return 1;
|
|
500
|
+
}
|
|
501
|
+
return 0;
|
|
502
|
+
}
|
|
503
|
+
if ([command isEqualToString:@"forget"]) {
|
|
504
|
+
NSString *error = nil;
|
|
505
|
+
if (!CCPetsForgetProfile(ValueAfter(arguments, @"--id"), &error)) {
|
|
506
|
+
CCPetsPrintLine(stderr, error); return 1;
|
|
507
|
+
}
|
|
508
|
+
return 0;
|
|
509
|
+
}
|
|
510
|
+
CCPetsPrintLine(stderr, @"Usage: cc-pets profile list|resolve|migrate|ensure-defaults|add|update|repair|repair-all|remove");
|
|
511
|
+
return 2;
|
|
512
|
+
} @catch (NSException *exception) {
|
|
513
|
+
CCPetsPrintLine(stderr, exception.reason ?: exception.name);
|
|
514
|
+
return 1;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
@@ -16,7 +16,8 @@ BOOL RegisterCodexLaunchForProcess(pid_t pid, NSString *cwd, NSDictionary *termi
|
|
|
16
16
|
NSTimeInterval launchedAt);
|
|
17
17
|
NSDictionary *CodexLaunchTerminalForThread(NSString *thread, NSDictionary *payload);
|
|
18
18
|
|
|
19
|
-
// Terminal / iTerm2 按 TTY
|
|
19
|
+
// Terminal / iTerm2 / Ghostty 按 TTY 精确选择;JetBrains IDE 和 VS Code 家族通过插件/扩展
|
|
20
|
+
// 异步聚焦。YES 表示已执行或已交给插件处理,其他终端在无扩展模式下激活应用。
|
|
20
21
|
BOOL ActivateTerminalFocusTarget(NSDictionary *target);
|
|
21
22
|
|
|
22
23
|
// 回跳目标的候选 bundle ID,按优先级排列,已去重去空。
|