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,238 @@
|
|
|
1
|
+
#import "CCPetsAppDelegate+Private.h"
|
|
2
|
+
#import "CCPetsCLISupport.h"
|
|
3
|
+
|
|
4
|
+
@implementation AppDelegate (Profiles)
|
|
5
|
+
|
|
6
|
+
- (void)addClaudeProfile:(id)sender {
|
|
7
|
+
[self chooseProfileHomeForProvider:CCPetsProfileProviderClaude];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
- (void)addCodexProfile:(id)sender {
|
|
11
|
+
[self chooseProfileHomeForProvider:CCPetsProfileProviderCodex];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// 设置页的按钮在命令执行期间仍可点,被挡下时要告诉用户,不能悄悄什么都不做。
|
|
15
|
+
- (BOOL)rejectWhileProfileCommandRunning {
|
|
16
|
+
if (!self.profileCommandRunning) return NO;
|
|
17
|
+
[self showAlertWithTitle:L(@"Agent Profile Setup") message:L(@"Another Agent profile is still being configured.")];
|
|
18
|
+
return YES;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
- (void)chooseProfileHomeForProvider:(NSString *)provider {
|
|
22
|
+
if ([self rejectWhileProfileCommandRunning]) return;
|
|
23
|
+
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
|
24
|
+
panel.canChooseDirectories = YES;
|
|
25
|
+
panel.canChooseFiles = NO;
|
|
26
|
+
panel.allowsMultipleSelection = NO;
|
|
27
|
+
panel.canCreateDirectories = NO;
|
|
28
|
+
panel.showsHiddenFiles = YES;
|
|
29
|
+
panel.prompt = L(@"Choose Home");
|
|
30
|
+
panel.message = [provider isEqualToString:CCPetsProfileProviderClaude]
|
|
31
|
+
? L(@"Choose an existing Claude Home folder, such as ~/.claude-work.")
|
|
32
|
+
: L(@"Choose an existing Codex Home folder, such as ~/.codex-work.");
|
|
33
|
+
panel.directoryURL = [NSURL fileURLWithPath:CCPetsHomeDirectory() isDirectory:YES];
|
|
34
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
35
|
+
if ([panel runModal] != NSModalResponseOK) return;
|
|
36
|
+
NSString *home = panel.URL.path;
|
|
37
|
+
if (!CCPetsProfileHomeMatchesProvider(provider, home)) {
|
|
38
|
+
[self showAlertWithTitle:L(@"This folder doesn't look like an Agent Home")
|
|
39
|
+
message:[provider isEqualToString:CCPetsProfileProviderClaude]
|
|
40
|
+
? L(@"Choose a folder containing Claude settings, state, or projects.")
|
|
41
|
+
: L(@"Choose a folder containing Codex config, hooks, or sign-in state.")];
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
NSString *name = CCPetsProfileDefaultDisplayName(provider, home);
|
|
45
|
+
NSAlert *confirm = [NSAlert new];
|
|
46
|
+
confirm.messageText = [NSString stringWithFormat:L(@"Integrate %@?"), name];
|
|
47
|
+
NSString *bridge = CCBridgeEnabled()
|
|
48
|
+
? L(@"Pet Hooks, usage collection, CC Bridge Hooks, permissions, and MCP will be configured.")
|
|
49
|
+
: L(@"Pet Hooks and usage collection will be configured. CC Bridge will be added automatically if you enable it later.");
|
|
50
|
+
confirm.informativeText = [NSString stringWithFormat:@"%@\n\n%@", CCPetsTildePath(home), bridge];
|
|
51
|
+
[confirm addButtonWithTitle:L(@"Start Setup")];
|
|
52
|
+
[confirm addButtonWithTitle:L(@"Cancel")];
|
|
53
|
+
if ([confirm runModal] != NSAlertFirstButtonReturn) return;
|
|
54
|
+
// 首次名称只是 Home 文件夹名,不算用户自定义;这样以后重新定位 Home 时,
|
|
55
|
+
// 未主动重命名的账号名称仍会跟随新的文件夹名。
|
|
56
|
+
[self runProfileCommand:@[@"add", @"--provider", provider, @"--home", home]
|
|
57
|
+
title:[NSString stringWithFormat:L(@"Configuring %@"), name]
|
|
58
|
+
completionMessage:[provider isEqualToString:CCPetsProfileProviderClaude]
|
|
59
|
+
? L(@"The Claude Home is integrated. Restart Claude to load newly registered MCP tools.")
|
|
60
|
+
: L(@"The Codex Home is integrated. Restart Codex, then trust the CC Pets hooks in /hooks.")];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
- (void)repairAgentProfile:(NSMenuItem *)sender {
|
|
64
|
+
NSString *profileID = [sender.representedObject isKindOfClass:NSString.class] ? sender.representedObject : nil;
|
|
65
|
+
NSDictionary *profile = CCPetsProfileWithID(profileID);
|
|
66
|
+
if (!profile || [self rejectWhileProfileCommandRunning]) return;
|
|
67
|
+
[self runProfileCommand:@[@"repair", @"--id", profileID]
|
|
68
|
+
title:[NSString stringWithFormat:L(@"Repairing %@"), profile[@"displayName"]]
|
|
69
|
+
completionMessage:L(@"The Agent profile integration was repaired.")];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
- (void)renameAgentProfile:(NSMenuItem *)sender {
|
|
73
|
+
NSString *profileID = [sender.representedObject isKindOfClass:NSString.class] ? sender.representedObject : nil;
|
|
74
|
+
NSDictionary *profile = CCPetsProfileWithID(profileID);
|
|
75
|
+
if (!profile || [self rejectWhileProfileCommandRunning]) return;
|
|
76
|
+
NSAlert *alert = [NSAlert new];
|
|
77
|
+
alert.messageText = L(@"Rename Agent Profile");
|
|
78
|
+
alert.informativeText = L(@"This changes only the name shown in CC Pets.");
|
|
79
|
+
NSTextField *field = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
|
|
80
|
+
field.stringValue = profile[@"displayName"] ?: @"";
|
|
81
|
+
alert.accessoryView = field;
|
|
82
|
+
[alert addButtonWithTitle:L(@"Save")];
|
|
83
|
+
[alert addButtonWithTitle:L(@"Cancel")];
|
|
84
|
+
if ([alert runModal] != NSAlertFirstButtonReturn) return;
|
|
85
|
+
NSString *name = [field.stringValue stringByTrimmingCharactersInSet:
|
|
86
|
+
NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
87
|
+
if (name.length == 0) return;
|
|
88
|
+
[self runProfileCommand:@[@"update", @"--id", profileID, @"--name", name]
|
|
89
|
+
title:[NSString stringWithFormat:L(@"Updating %@"), name]
|
|
90
|
+
completionMessage:L(@"The Agent profile name was updated.")];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
- (void)relocateAgentProfile:(NSMenuItem *)sender {
|
|
94
|
+
NSString *profileID = [sender.representedObject isKindOfClass:NSString.class] ? sender.representedObject : nil;
|
|
95
|
+
NSDictionary *profile = CCPetsProfileWithID(profileID);
|
|
96
|
+
if (!profile || [self rejectWhileProfileCommandRunning]) return;
|
|
97
|
+
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
|
98
|
+
panel.canChooseDirectories = YES;
|
|
99
|
+
panel.canChooseFiles = NO;
|
|
100
|
+
panel.allowsMultipleSelection = NO;
|
|
101
|
+
panel.canCreateDirectories = NO;
|
|
102
|
+
panel.showsHiddenFiles = YES;
|
|
103
|
+
panel.prompt = L(@"Choose Home");
|
|
104
|
+
panel.message = L(@"Choose the new location for this Agent Home.");
|
|
105
|
+
panel.directoryURL = [NSURL fileURLWithPath:profile[@"home"] isDirectory:YES];
|
|
106
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
107
|
+
if ([panel runModal] != NSModalResponseOK) return;
|
|
108
|
+
NSString *home = panel.URL.path;
|
|
109
|
+
if (!CCPetsProfileHomeMatchesProvider(profile[@"provider"], home)) {
|
|
110
|
+
[self showAlertWithTitle:L(@"This folder doesn't look like an Agent Home")
|
|
111
|
+
message:L(@"Choose a folder containing the selected Agent's settings or state.")];
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
[self runProfileCommand:@[@"update", @"--id", profileID, @"--home", home]
|
|
115
|
+
title:[NSString stringWithFormat:L(@"Relocating %@"), profile[@"displayName"]]
|
|
116
|
+
completionMessage:L(@"The Agent Home was relocated and its integration was updated.")];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (void)removeAgentProfile:(NSMenuItem *)sender {
|
|
120
|
+
NSString *profileID = [sender.representedObject isKindOfClass:NSString.class] ? sender.representedObject : nil;
|
|
121
|
+
NSDictionary *profile = CCPetsProfileWithID(profileID);
|
|
122
|
+
if (!profile || [self rejectWhileProfileCommandRunning]) return;
|
|
123
|
+
NSAlert *confirm = [NSAlert new];
|
|
124
|
+
confirm.alertStyle = NSAlertStyleWarning;
|
|
125
|
+
confirm.messageText = [NSString stringWithFormat:L(@"Remove integration for %@?"), profile[@"displayName"]];
|
|
126
|
+
confirm.informativeText = L(@"Only CC Pets-managed Hooks, usage integration, Bridge settings, and the profile card will be removed. The Agent Home, login, and session history will be kept.");
|
|
127
|
+
[confirm addButtonWithTitle:L(@"Remove Integration")];
|
|
128
|
+
[confirm addButtonWithTitle:L(@"Cancel")];
|
|
129
|
+
if ([confirm runModal] != NSAlertFirstButtonReturn) return;
|
|
130
|
+
[self runProfileCommand:@[@"remove", @"--id", profileID]
|
|
131
|
+
title:[NSString stringWithFormat:L(@"Removing %@"), profile[@"displayName"]]
|
|
132
|
+
completionMessage:L(@"The CC Pets integration was removed. The Agent Home and its data were kept.")];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
- (void)showProfileProgressWithTitle:(NSString *)title {
|
|
136
|
+
NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 360, 112)
|
|
137
|
+
styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:NO];
|
|
138
|
+
window.title = L(@"Agent Profile Setup");
|
|
139
|
+
window.releasedWhenClosed = NO;
|
|
140
|
+
NSTextField *label = [NSTextField labelWithString:title ?: L(@"Configuring Agent profile…")];
|
|
141
|
+
label.frame = NSMakeRect(24, 57, 312, 24);
|
|
142
|
+
label.font = [NSFont systemFontOfSize:13 weight:NSFontWeightMedium];
|
|
143
|
+
label.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
|
144
|
+
NSProgressIndicator *indicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(24, 28, 312, 16)];
|
|
145
|
+
indicator.style = NSProgressIndicatorStyleBar;
|
|
146
|
+
indicator.indeterminate = YES;
|
|
147
|
+
[window.contentView addSubview:label];
|
|
148
|
+
[window.contentView addSubview:indicator];
|
|
149
|
+
[indicator startAnimation:nil];
|
|
150
|
+
[window center];
|
|
151
|
+
[window makeKeyAndOrderFront:nil];
|
|
152
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
153
|
+
self.profileProgressWindow = window;
|
|
154
|
+
self.profileProgressLabel = label;
|
|
155
|
+
self.profileProgressIndicator = indicator;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
- (void)updateProfileProgressForText:(NSString *)text fallback:(NSString *)fallback {
|
|
159
|
+
NSDictionary<NSString *, NSString *> *stages = @{
|
|
160
|
+
@"stage=registered": L(@"Profile registered…"),
|
|
161
|
+
@"stage=hooks": L(@"Installing Pet Hooks and usage collection…"),
|
|
162
|
+
@"stage=bridge": L(@"Configuring CC Bridge and MCP…"),
|
|
163
|
+
@"stage=verify": L(@"Verifying integration…")
|
|
164
|
+
};
|
|
165
|
+
__block NSString *message = fallback;
|
|
166
|
+
[stages enumerateKeysAndObjectsUsingBlock:^(NSString *stage, NSString *label, BOOL *stop) {
|
|
167
|
+
if ([text containsString:stage]) message = label;
|
|
168
|
+
}];
|
|
169
|
+
dispatch_async(dispatch_get_main_queue(), ^{ self.profileProgressLabel.stringValue = message; });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
- (void)runProfileCommand:(NSArray<NSString *> *)arguments
|
|
173
|
+
title:(NSString *)title completionMessage:(NSString *)completionMessage {
|
|
174
|
+
if (self.profileCommandRunning) return;
|
|
175
|
+
self.profileCommandRunning = YES;
|
|
176
|
+
[self showProfileProgressWithTitle:title];
|
|
177
|
+
NSTask *task = [NSTask new];
|
|
178
|
+
task.executableURL = [NSURL fileURLWithPath:CCPetsExecutablePath()];
|
|
179
|
+
task.arguments = [@[@"profile"] arrayByAddingObjectsFromArray:arguments];
|
|
180
|
+
NSMutableDictionary<NSString *, NSString *> *environment = [NSProcessInfo.processInfo.environment mutableCopy];
|
|
181
|
+
NSDictionary *locator = CCBridgeCLILocator();
|
|
182
|
+
NSString *path = locator[@"path"];
|
|
183
|
+
if (path.length == 0) path = CCPetsLoginShellPath();
|
|
184
|
+
if (path.length > 0) environment[@"PATH"] = path;
|
|
185
|
+
task.environment = environment;
|
|
186
|
+
NSPipe *pipe = [NSPipe pipe];
|
|
187
|
+
task.standardOutput = pipe;
|
|
188
|
+
task.standardError = pipe;
|
|
189
|
+
__block NSMutableData *captured = [NSMutableData data];
|
|
190
|
+
__weak typeof(self) weakSelf = self;
|
|
191
|
+
pipe.fileHandleForReading.readabilityHandler = ^(NSFileHandle *handle) {
|
|
192
|
+
NSData *data = handle.availableData;
|
|
193
|
+
if (data.length == 0) return;
|
|
194
|
+
@synchronized (captured) { [captured appendData:data]; }
|
|
195
|
+
NSString *chunk = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ?: @"";
|
|
196
|
+
[weakSelf updateProfileProgressForText:chunk fallback:title];
|
|
197
|
+
};
|
|
198
|
+
task.terminationHandler = ^(NSTask *finished) {
|
|
199
|
+
pipe.fileHandleForReading.readabilityHandler = nil;
|
|
200
|
+
NSData *tail = [pipe.fileHandleForReading readDataToEndOfFile];
|
|
201
|
+
@synchronized (captured) { if (tail.length > 0) [captured appendData:tail]; }
|
|
202
|
+
NSString *output = [[NSString alloc] initWithData:captured encoding:NSUTF8StringEncoding] ?: @"";
|
|
203
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
204
|
+
typeof(self) strongSelf = weakSelf;
|
|
205
|
+
if (!strongSelf) return;
|
|
206
|
+
[strongSelf.profileProgressIndicator stopAnimation:nil];
|
|
207
|
+
[strongSelf.profileProgressWindow close];
|
|
208
|
+
strongSelf.profileProgressWindow = nil;
|
|
209
|
+
strongSelf.profileProgressLabel = nil;
|
|
210
|
+
strongSelf.profileProgressIndicator = nil;
|
|
211
|
+
strongSelf.profileTask = nil;
|
|
212
|
+
strongSelf.profileCommandRunning = NO;
|
|
213
|
+
// 子进程即使适配失败也可能已经更新注册表,让打开的设置页同步账号。
|
|
214
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsProfilesDidChangeNotification object:nil];
|
|
215
|
+
if (finished.terminationStatus == EXIT_SUCCESS) {
|
|
216
|
+
[strongSelf refreshUsage:nil];
|
|
217
|
+
[strongSelf showAlertWithTitle:L(@"Agent Profile Ready") message:completionMessage];
|
|
218
|
+
} else {
|
|
219
|
+
NSString *detail = [output stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
220
|
+
[strongSelf showAlertWithTitle:L(@"Agent Profile Setup Failed")
|
|
221
|
+
message:detail.length > 0 ? detail : L(@"The command failed.")];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
NSError *error = nil;
|
|
226
|
+
if (![task launchAndReturnError:&error]) {
|
|
227
|
+
pipe.fileHandleForReading.readabilityHandler = nil;
|
|
228
|
+
self.profileCommandRunning = NO;
|
|
229
|
+
[self.profileProgressIndicator stopAnimation:nil];
|
|
230
|
+
[self.profileProgressWindow close];
|
|
231
|
+
self.profileProgressWindow = nil;
|
|
232
|
+
[self showAlertWithTitle:L(@"Agent Profile Setup Failed") message:error.localizedDescription];
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
self.profileTask = task;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@end
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
// 额度面板、用量刷新与系统指标。
|
|
2
2
|
#import "CCPetsAppDelegate+Private.h"
|
|
3
|
-
|
|
4
|
-
// 额度字典"非空"不等于"这家真的在用"。Claude 的 reader 刻意永不返回 nil(见
|
|
5
|
-
// CCPetsUsage.m 里 -[ClaudeUsageReader refresh] 的注释:Token 是本机从转录数出来的,
|
|
6
|
-
// 不能被缺失的官方额度一票否决),什么都没有时照样返回
|
|
7
|
-
// {fiveHour: NSNull, week: NSNull, tokenUsage: 全 0},count 恒为 3。
|
|
8
|
-
// 拿 count > 0 当证据,Claude 就永远算"检测到",卡片再也去不掉。这里只认实质证据:
|
|
9
|
-
// 官方额度块真实存在,或者本机统计出过非零 Token。Codex 侧同一套判据也成立。
|
|
10
|
-
static BOOL UsageShowsProviderInUse(NSDictionary *usage) {
|
|
11
|
-
if (usage.count == 0) return NO;
|
|
12
|
-
for (NSString *key in @[@"fiveHour", @"week"]) {
|
|
13
|
-
if ([usage[key] isKindOfClass:NSDictionary.class]) return YES;
|
|
14
|
-
}
|
|
15
|
-
NSDictionary *tokenUsage = [usage[@"tokenUsage"] isKindOfClass:NSDictionary.class]
|
|
16
|
-
? usage[@"tokenUsage"] : nil;
|
|
17
|
-
for (NSString *key in @[@"fiveHour", @"week", @"today", @"recentWeek"]) {
|
|
18
|
-
NSDictionary *totals = [tokenUsage[key] isKindOfClass:NSDictionary.class]
|
|
19
|
-
? tokenUsage[key] : nil;
|
|
20
|
-
if ([totals[@"total_tokens"] doubleValue] > 0) return YES;
|
|
21
|
-
}
|
|
22
|
-
return NO;
|
|
23
|
-
}
|
|
3
|
+
#import "CCPetsWorkbench.h"
|
|
24
4
|
|
|
25
5
|
@implementation AppDelegate (Quota)
|
|
26
6
|
- (void)rescheduleUsageTimer {
|
|
@@ -149,19 +129,44 @@ static BOOL UsageShowsProviderInUse(NSDictionary *usage) {
|
|
|
149
129
|
// 还要挂满一整个静默窗口。额度数据本身不是在线信号——它一直缓存着,用它判定会恒亮。
|
|
150
130
|
- (void)updateQuotaLiveState {
|
|
151
131
|
NSMutableSet<NSString *> *online = [self.liveClientProviders mutableCopy] ?: [NSMutableSet set];
|
|
132
|
+
NSMutableSet<NSString *> *onlineProfiles = [self.liveClientProfileIDs mutableCopy]
|
|
133
|
+
?: [NSMutableSet set];
|
|
134
|
+
NSMutableSet<NSString *> *unscopedProviders = [self.liveUnscopedClientProviders mutableCopy]
|
|
135
|
+
?: [NSMutableSet set];
|
|
136
|
+
NSMutableSet<NSString *> *approvalProfiles = [NSMutableSet set];
|
|
152
137
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
153
138
|
for (NSString *provider in self.providerActivityAt) {
|
|
154
139
|
NSTimeInterval last = [self.providerActivityAt[provider] doubleValue];
|
|
155
140
|
if (now - last < AgentStatusInactivityInterval) [online addObject:provider];
|
|
156
141
|
}
|
|
142
|
+
for (NSDictionary *record in self.agentSessionRecords.allValues) {
|
|
143
|
+
NSString *profileID = [record[@"profileId"] isKindOfClass:NSString.class]
|
|
144
|
+
? record[@"profileId"] : nil;
|
|
145
|
+
if (![self isAgentSessionRecordLive:record]) continue;
|
|
146
|
+
if (profileID.length > 0) {
|
|
147
|
+
[onlineProfiles addObject:profileID];
|
|
148
|
+
if ([record[@"state"] isEqualToString:@"approval"]) [approvalProfiles addObject:profileID];
|
|
149
|
+
} else {
|
|
150
|
+
NSString *provider = [record[@"provider"] isKindOfClass:NSString.class]
|
|
151
|
+
? record[@"provider"] : nil;
|
|
152
|
+
if (provider.length > 0) [unscopedProviders addObject:provider];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
157
155
|
NSInteger count = MAX(self.liveClientCount, (NSInteger)online.count);
|
|
158
156
|
if (self.quotaView.activeAgentCount == count &&
|
|
159
157
|
[self.quotaView.liveProviders isEqualToSet:online] &&
|
|
158
|
+
[self.quotaView.liveProfileIDs isEqualToSet:onlineProfiles] &&
|
|
159
|
+
[self.quotaView.liveUnscopedProviders isEqualToSet:unscopedProviders] &&
|
|
160
|
+
[self.quotaView.pendingApprovalProfileIDs isEqualToSet:approvalProfiles] &&
|
|
160
161
|
self.quotaView.hasUnlabeledClient == self.hasUnlabeledClient) return;
|
|
161
162
|
self.quotaView.activeAgentCount = count;
|
|
162
163
|
self.quotaView.liveProviders = online;
|
|
164
|
+
self.quotaView.liveProfileIDs = onlineProfiles;
|
|
165
|
+
self.quotaView.liveUnscopedProviders = unscopedProviders;
|
|
166
|
+
self.quotaView.pendingApprovalProfileIDs = approvalProfiles;
|
|
163
167
|
self.quotaView.hasUnlabeledClient = self.hasUnlabeledClient;
|
|
164
168
|
self.quotaView.needsDisplay = YES;
|
|
169
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
|
|
165
170
|
}
|
|
166
171
|
// 面板高度取决于渲染几张额度卡。调整玻璃容器后,内部内容随 autoresizingMask 铺满。
|
|
167
172
|
- (void)resizeQuotaDashboard {
|
|
@@ -178,19 +183,21 @@ static BOOL UsageShowsProviderInUse(NSDictionary *usage) {
|
|
|
178
183
|
self.quotaView.needsDisplay = YES;
|
|
179
184
|
if (self.quotaPanel.isVisible) [self positionQuotaDashboard];
|
|
180
185
|
}
|
|
181
|
-
//
|
|
182
|
-
//
|
|
186
|
+
// 卡片来自自动登记的官方 Home 与用户明确登记的自定义 Home。自定义目录不会被扫描;
|
|
187
|
+
// 目录暂时不可用时 profile 仍留在注册表,所以卡片也不会抖动消失。
|
|
183
188
|
- (void)refreshDetectedProviders {
|
|
189
|
+
// 运行期间后来安装 CLI、或首次生成官方 Home 时也应自动出现卡片;只检查两个
|
|
190
|
+
// 官方路径,自定义 Home 仍必须从主窗口的多账号页手动添加。
|
|
191
|
+
NSString *profileError = nil;
|
|
192
|
+
if (!CCPetsEnsureOfficialDefaultProfiles(&profileError) && profileError.length > 0) {
|
|
193
|
+
fprintf(stderr, "%s\n", profileError.UTF8String);
|
|
194
|
+
}
|
|
184
195
|
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
185
|
-
NSMutableSet<NSString *> *detected = [NSMutableSet
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// 把一个正在工作、或者明明有额度的 provider 藏起来。
|
|
191
|
-
if (self.liveClientProviders.count > 0) [detected unionSet:self.liveClientProviders];
|
|
192
|
-
if (UsageShowsProviderInUse(self.quotaView.codexUsage)) [detected addObject:@"Codex"];
|
|
193
|
-
if (UsageShowsProviderInUse(self.quotaView.claudeUsage)) [detected addObject:@"Claude"];
|
|
196
|
+
NSMutableSet<NSString *> *detected = [NSMutableSet set];
|
|
197
|
+
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
198
|
+
if ([profile[@"provider"] isEqualToString:CCPetsProfileProviderCodex]) [detected addObject:@"Codex"];
|
|
199
|
+
if ([profile[@"provider"] isEqualToString:CCPetsProfileProviderClaude]) [detected addObject:@"Claude"];
|
|
200
|
+
}
|
|
194
201
|
if (self.quotaView.detectedProviders &&
|
|
195
202
|
[detected isEqualToSet:self.quotaView.detectedProviders]) return;
|
|
196
203
|
self.quotaView.detectedProviders = detected;
|
|
@@ -204,10 +211,18 @@ static BOOL UsageShowsProviderInUse(NSDictionary *usage) {
|
|
|
204
211
|
[self refreshDetectedProviders];
|
|
205
212
|
NSDictionary *history = RecordQuotaHistory(self.quotaView.codexUsage,
|
|
206
213
|
self.quotaView.claudeUsage);
|
|
214
|
+
history = RecordProfileQuotaHistory(self.usageMonitor.profileUsages, self.usageMonitor.profiles);
|
|
215
|
+
NSMutableDictionary *profileHistories = [NSMutableDictionary dictionary];
|
|
216
|
+
for (NSDictionary *profile in self.usageMonitor.profiles) {
|
|
217
|
+
NSString *profileID = profile[@"id"];
|
|
218
|
+
if (profileID.length > 0) profileHistories[profileID] = QuotaHistorySeriesForProfile(history, profileID);
|
|
219
|
+
}
|
|
220
|
+
self.quotaView.profileHistories = profileHistories;
|
|
207
221
|
self.quotaView.codexHistory = QuotaHistorySeries(history, @"codex");
|
|
208
222
|
self.quotaView.claudeHistory = QuotaHistorySeries(history, @"claude");
|
|
209
223
|
self.quotaView.lastUpdatedAt = NSDate.date.timeIntervalSince1970;
|
|
210
224
|
self.quotaView.needsDisplay = YES;
|
|
225
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
|
|
211
226
|
}
|
|
212
227
|
- (void)refreshUsage:(id)sender {
|
|
213
228
|
self.lastUsageRefreshAt = NSDate.date.timeIntervalSince1970;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
// 右键菜单里的各项设置开关。
|
|
2
|
+
//
|
|
3
|
+
// 每项分两层:菜单控件的 action(setXxx: / toggleXxx:)只从 sender 上取值、回写勾选状态;
|
|
4
|
+
// 真正写设置并让界面生效的是 updateXxx:,不认识任何菜单控件,主窗口设置页直接调它。
|
|
5
|
+
// 写 defaults 一律经过 CCPetsPreferences,两边才拿得到同一套钳制和变更广播。
|
|
2
6
|
#import "CCPetsAppDelegate+Private.h"
|
|
3
|
-
#import
|
|
7
|
+
#import "CCPetsUsageMode.h"
|
|
8
|
+
#import "CCPetsWorkbench.h"
|
|
4
9
|
|
|
5
10
|
@implementation AppDelegate (Settings)
|
|
6
11
|
- (void)setPetSizeFromSlider:(NSSlider *)sender {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
[self updatePetScale:sender.doubleValue];
|
|
13
|
+
sender.doubleValue = CCPetsPetScalePreference();
|
|
14
|
+
}
|
|
15
|
+
- (void)updatePetScale:(double)scale {
|
|
16
|
+
if (!CCPetsPrefSetObject(CCPetsPetScaleKey, @(scale))) return;
|
|
12
17
|
[self applyPetSizePreference];
|
|
13
18
|
}
|
|
14
19
|
- (void)applyPetSizePreference {
|
|
@@ -33,12 +38,6 @@
|
|
|
33
38
|
[self.speechPanel.contentView displayIfNeeded];
|
|
34
39
|
[self petWindowDidMove:nil];
|
|
35
40
|
}
|
|
36
|
-
- (NSString *)systemMetricKeyForTag:(NSInteger)tag {
|
|
37
|
-
if (tag == 1) return SystemCPUEnabledKey;
|
|
38
|
-
if (tag == 2) return SystemTemperatureEnabledKey;
|
|
39
|
-
if (tag == 3) return SystemMemoryEnabledKey;
|
|
40
|
-
return nil;
|
|
41
|
-
}
|
|
42
41
|
- (void)applySystemMetricPreferences {
|
|
43
42
|
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
44
43
|
self.quotaView.systemCPUEnabled = [defaults boolForKey:SystemCPUEnabledKey];
|
|
@@ -56,32 +55,50 @@
|
|
|
56
55
|
self.quotaView.needsDisplay = YES;
|
|
57
56
|
}
|
|
58
57
|
- (void)setUsageDisplayModeFromControl:(NSButton *)sender {
|
|
58
|
+
if (sender.identifier.length > 0) {
|
|
59
|
+
NSDictionary *profile = CCPetsProfileWithID(sender.identifier);
|
|
60
|
+
if (!profile) { sender.enabled = NO; return; }
|
|
61
|
+
[self updateUsageDisplayMode:CCPetsProfileShowsAPIUsage(profile) ? @"subscription" : @"api"
|
|
62
|
+
forProfileID:sender.identifier];
|
|
63
|
+
sender.state = CCPetsProfileShowsAPIUsage(profile) ? NSControlStateValueOn : NSControlStateValueOff;
|
|
64
|
+
sender.enabled = CCPetsProfileCanSwitchUsageMode(profile);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
59
67
|
NSString *key = sender.tag == 1 ? CodexUsageDisplayModeKey
|
|
60
68
|
: (sender.tag == 2 ? ClaudeUsageDisplayModeKey : nil);
|
|
61
69
|
NSString *mode = sender.state == NSControlStateValueOn ? @"api" : @"subscription";
|
|
62
70
|
if (!key) return;
|
|
63
|
-
[
|
|
71
|
+
[self updateUsageDisplayMode:mode forKey:key];
|
|
72
|
+
}
|
|
73
|
+
- (void)updateUsageDisplayMode:(NSString *)mode forKey:(NSString *)key {
|
|
74
|
+
if (![@[CodexUsageDisplayModeKey, ClaudeUsageDisplayModeKey] containsObject:key] ||
|
|
75
|
+
![@[@"api", @"subscription"] containsObject:mode]) return;
|
|
76
|
+
CCPetsPrefSetObject(key, mode);
|
|
64
77
|
[self applyUsageDisplayModePreferences];
|
|
65
78
|
// 展示模式决定了会话要回溯多远(订阅 8 天 / API 到上月月初),切换之后必须重新聚合,
|
|
66
79
|
// 否则刚打开 API 视图时手里只有一段按 8 天窗口扫出来的数据。
|
|
67
80
|
[self refreshUsage:nil];
|
|
81
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
|
|
68
82
|
}
|
|
69
|
-
- (void)
|
|
70
|
-
|
|
71
|
-
if (!
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
- (void)updateUsageDisplayMode:(NSString *)mode forProfileID:(NSString *)profileID {
|
|
84
|
+
NSDictionary *profile = CCPetsProfileWithID(profileID);
|
|
85
|
+
if (!profile || !CCPetsProfileCanSwitchUsageMode(profile) ||
|
|
86
|
+
![@[@"api", @"subscription"] containsObject:mode]) return;
|
|
87
|
+
CCPetsPrefSetObject(CCPetsUsageModePreferenceKey(profile), mode);
|
|
88
|
+
self.quotaView.needsDisplay = YES;
|
|
89
|
+
[self refreshUsage:nil];
|
|
90
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
|
|
91
|
+
}
|
|
92
|
+
- (void)updateSystemMetric:(NSString *)key enabled:(BOOL)enabled {
|
|
93
|
+
if (![@[SystemCPUEnabledKey, SystemTemperatureEnabledKey, SystemMemoryEnabledKey]
|
|
94
|
+
containsObject:key]) return;
|
|
95
|
+
CCPetsPrefSetBool(key, enabled);
|
|
76
96
|
[self applySystemMetricPreferences];
|
|
77
97
|
[self updateSystemMetricsTimer];
|
|
78
98
|
}
|
|
79
99
|
// 开关打开时立刻导入一次,不用等下次启动——用户点开关就是想现在看到那些素材。
|
|
80
|
-
- (void)
|
|
81
|
-
|
|
82
|
-
BOOL enabled = ![defaults boolForKey:ImportCodexPetsKey];
|
|
83
|
-
[defaults setBool:enabled forKey:ImportCodexPetsKey];
|
|
84
|
-
sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
100
|
+
- (void)updateImportCodexPets:(BOOL)enabled {
|
|
101
|
+
CCPetsPrefSetBool(ImportCodexPetsKey, enabled);
|
|
85
102
|
if (!enabled) return;
|
|
86
103
|
NSUInteger imported = ImportCodexPets();
|
|
87
104
|
if (imported == 0) return;
|
|
@@ -95,18 +112,13 @@
|
|
|
95
112
|
[alert addButtonWithTitle:L(@"OK")];
|
|
96
113
|
[alert runModal];
|
|
97
114
|
}
|
|
98
|
-
- (NSString *)notificationKeyForTag:(NSInteger)tag {
|
|
99
|
-
if (tag == 1) return NotificationCompletionKey;
|
|
100
|
-
if (tag == 2) return NotificationFailureKey;
|
|
101
|
-
if (tag == 3) return NotificationApprovalKey;
|
|
102
|
-
if (tag == 4) return NotificationStallKey;
|
|
103
|
-
return nil;
|
|
104
|
-
}
|
|
105
115
|
// sender 是菜单里的 MenuChoiceRowView,勾选状态由它自己更新。
|
|
106
116
|
- (void)setPanelTheme:(MenuChoiceRowView *)sender {
|
|
107
|
-
|
|
117
|
+
[self updatePanelTheme:sender.representedObject];
|
|
118
|
+
}
|
|
119
|
+
- (void)updatePanelTheme:(NSString *)theme {
|
|
108
120
|
if (![@[@"classic", @"liquid"] containsObject:theme]) return;
|
|
109
|
-
|
|
121
|
+
CCPetsPrefSetObject(CCPetsPanelThemeKey, theme);
|
|
110
122
|
[self.statusGlass applyTheme];
|
|
111
123
|
[self.speechGlass applyTheme];
|
|
112
124
|
[self.quotaGlass applyTheme];
|
|
@@ -123,10 +135,7 @@
|
|
|
123
135
|
// 状态卡和说话气泡原来是浅色磨砂配深色字;换成原生清透玻璃后背景是任意壁纸加一层
|
|
124
136
|
// 压暗,深色字会看不见,改成白字加贴字形的投影,和额度面板一致。
|
|
125
137
|
- (void)applyBubbleTextStyle {
|
|
126
|
-
NSShadow *shadow =
|
|
127
|
-
shadow.shadowColor = [NSColor colorWithWhite:0 alpha:0.45];
|
|
128
|
-
shadow.shadowBlurRadius = 2;
|
|
129
|
-
shadow.shadowOffset = NSMakeSize(0, -0.5);
|
|
138
|
+
NSShadow *shadow = CCPetsGlassTextShadow();
|
|
130
139
|
BOOL statusLiquid = self.statusGlass.usesLiquidGlass;
|
|
131
140
|
self.statusTitleLabel.textColor = statusLiquid ? [NSColor colorWithWhite:1 alpha:0.78]
|
|
132
141
|
: [NSColor colorWithWhite:0.42 alpha:0.90];
|
|
@@ -141,9 +150,14 @@
|
|
|
141
150
|
[self applyUpdateBadgeStyle];
|
|
142
151
|
}
|
|
143
152
|
- (void)setGlassDimLevel:(MenuChoiceRowView *)sender {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
[self updateGlassDimLevel:sender.representedObject];
|
|
154
|
+
}
|
|
155
|
+
- (void)updateGlassDimLevel:(NSNumber *)level {
|
|
156
|
+
// 主窗口的滑块是连续值,菜单是四档;两边都传 0–100 的展示强度,取整后换算成实际的 0–45 存下。
|
|
157
|
+
if (![level isKindOfClass:NSNumber.class] || isnan(level.doubleValue)) return;
|
|
158
|
+
double value = CCPetsGlassDimLevelForPercent(lround(level.doubleValue));
|
|
159
|
+
if ([[NSUserDefaults.standardUserDefaults objectForKey:CCPetsGlassDimKey] isEqual:@(value)]) return;
|
|
160
|
+
CCPetsPrefSetObject(CCPetsGlassDimKey, @(value));
|
|
147
161
|
[self.quotaGlass applyDimLevel];
|
|
148
162
|
[self.statusGlass applyDimLevel];
|
|
149
163
|
[self.speechGlass applyDimLevel];
|
|
@@ -151,55 +165,34 @@
|
|
|
151
165
|
self.quotaView.cardScrimAlpha = CCPetsGlassCardScrimAlpha();
|
|
152
166
|
self.quotaView.needsDisplay = YES;
|
|
153
167
|
}
|
|
154
|
-
- (void)
|
|
155
|
-
|
|
156
|
-
id current = [defaults objectForKey:@"CCPetsSpeechEnabled"];
|
|
157
|
-
BOOL enabled = current == nil ? YES : [current boolValue];
|
|
158
|
-
[defaults setBool:!enabled forKey:@"CCPetsSpeechEnabled"];
|
|
159
|
-
sender.state = !enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
168
|
+
- (void)updateSpeechEnabled:(BOOL)enabled {
|
|
169
|
+
CCPetsPrefSetBool(PetSpeechEnabledKey, enabled);
|
|
160
170
|
// 更新提示不算碎碎念,关掉碎碎念时不收它。
|
|
161
|
-
if (enabled && !self.updateBubbleVisible) [self hideSpeechBubble];
|
|
171
|
+
if (!enabled && !self.updateBubbleVisible) [self hideSpeechBubble];
|
|
162
172
|
}
|
|
163
|
-
- (void)
|
|
164
|
-
|
|
165
|
-
BOOL enabled = ![defaults boolForKey:PetInteractionEnabledKey];
|
|
166
|
-
[defaults setBool:enabled forKey:PetInteractionEnabledKey];
|
|
167
|
-
sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
173
|
+
- (void)updatePetInteractionEnabled:(BOOL)enabled {
|
|
174
|
+
CCPetsPrefSetBool(PetInteractionEnabledKey, enabled);
|
|
168
175
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
- (void)setPetInteractionAnnoyedThreshold:(MenuChoiceRowView *)sender {
|
|
176
|
-
NSNumber *value = [sender.representedObject isKindOfClass:NSNumber.class] ?
|
|
177
|
-
sender.representedObject : @10;
|
|
178
|
-
NSInteger heart = MAX((NSInteger)2, [NSUserDefaults.standardUserDefaults
|
|
179
|
-
integerForKey:PetInteractionHeartThresholdKey]);
|
|
180
|
-
[NSUserDefaults.standardUserDefaults setInteger:MAX(heart + 1, value.integerValue)
|
|
181
|
-
forKey:PetInteractionAnnoyedThresholdKey];
|
|
182
|
-
}
|
|
183
|
-
- (void)setPetInteractionInterval:(MenuChoiceRowView *)sender {
|
|
184
|
-
NSNumber *value = [sender.representedObject isKindOfClass:NSNumber.class] ?
|
|
185
|
-
sender.representedObject : @1.2;
|
|
186
|
-
[NSUserDefaults.standardUserDefaults setDouble:MAX(0.4, MIN(3.0, value.doubleValue))
|
|
187
|
-
forKey:PetInteractionIntervalKey];
|
|
176
|
+
// 阈值和间隔都是点击时现读的,写进去即生效;范围钳制在 CCPetsPrefNormalizedValue。
|
|
177
|
+
- (void)updatePetInteractionValue:(NSNumber *)value forKey:(NSString *)key {
|
|
178
|
+
if (![@[PetInteractionHeartThresholdKey, PetInteractionAnnoyedThresholdKey,
|
|
179
|
+
PetInteractionIntervalKey] containsObject:key]) return;
|
|
180
|
+
CCPetsPrefSetObject(key, value);
|
|
188
181
|
}
|
|
189
182
|
// 频率档位。改完立刻生效——四道闸都是现读的,不缓存。
|
|
190
183
|
// 顺手把冷却清掉,否则刚调高档位还要等完上一档的冷却才见效,会让人以为没生效。
|
|
191
|
-
- (void)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
184
|
+
- (void)updateSpeechFrequency:(NSString *)value {
|
|
185
|
+
if (![@[PetSpeechFrequencyLow, PetSpeechFrequencyNormal, PetSpeechFrequencyHigh,
|
|
186
|
+
PetSpeechFrequencyChatty] containsObject:value]) value = PetSpeechFrequencyNormal;
|
|
187
|
+
CCPetsPrefSetObject(PetSpeechFrequencyKey, value);
|
|
195
188
|
self.speechCooldownUntil = 0;
|
|
196
189
|
self.lastIdleSpeechCheck = 0;
|
|
197
190
|
}
|
|
198
|
-
- (void)
|
|
199
|
-
NSString *source = sender.representedObject;
|
|
191
|
+
- (void)updatePhrasesSource:(NSString *)source {
|
|
200
192
|
if (![@[PetPhrasesSourcePet, PetPhrasesSourceDefault] containsObject:source] ||
|
|
201
193
|
[source isEqualToString:PetPhrasesSource()]) return;
|
|
202
194
|
PetPhrasesSetSource(source);
|
|
195
|
+
CCPetsPrefPostChange(PetPhrasesSourceKey);
|
|
203
196
|
NSString *tag = self.lastPetVoiceTag;
|
|
204
197
|
self.lastPetVoiceTag = nil;
|
|
205
198
|
self.lastPetVoiceText = nil;
|
|
@@ -232,42 +225,34 @@
|
|
|
232
225
|
}];
|
|
233
226
|
[PetPhrasesEditorController present];
|
|
234
227
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if ([
|
|
240
|
-
|
|
241
|
-
|
|
228
|
+
// 系统通知四项和 CC Bridge 送达通知共用:打开前先向系统申请通知权限,没拿到就保持关闭并说明
|
|
229
|
+
// 原因。completion 在主线程回调,参数是最终是否开启,调用方据此回写自己的开关。
|
|
230
|
+
- (void)updateNotification:(NSString *)key enabled:(BOOL)enabled
|
|
231
|
+
completion:(void (^)(BOOL enabled))completion {
|
|
232
|
+
if (![@[NotificationCompletionKey, NotificationFailureKey, NotificationApprovalKey,
|
|
233
|
+
NotificationStallKey, BridgeNotificationKey] containsObject:key]) return;
|
|
234
|
+
if (!enabled) {
|
|
235
|
+
CCPetsPrefSetBool(key, NO);
|
|
236
|
+
if (completion) completion(NO);
|
|
242
237
|
return;
|
|
243
238
|
}
|
|
244
239
|
[UNUserNotificationCenter.currentNotificationCenter
|
|
245
240
|
requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionSound
|
|
246
241
|
completionHandler:^(BOOL granted, NSError *error) {
|
|
247
242
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
248
|
-
if (granted)
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
L(@"Allow notifications in System Settings → Notifications → CC Pets, then try again.");
|
|
255
|
-
[self showAlertWithTitle:L(@"Can't Enable Notifications") message:message];
|
|
256
|
-
}
|
|
243
|
+
if (granted) CCPetsPrefSetBool(key, YES);
|
|
244
|
+
if (completion) completion(granted);
|
|
245
|
+
if (granted) return;
|
|
246
|
+
NSString *message = error.localizedDescription ?:
|
|
247
|
+
L(@"Allow notifications in System Settings → Notifications → CC Pets, then try again.");
|
|
248
|
+
[self showAlertWithTitle:L(@"Can't Enable Notifications") message:message];
|
|
257
249
|
});
|
|
258
250
|
}];
|
|
259
251
|
}
|
|
260
|
-
// 菜单每次右键现建,切换后下次打开就是新语言;这里只刷新常驻的界面。
|
|
261
|
-
- (void)setLanguagePreferenceFromMenu:(NSMenuItem *)sender {
|
|
262
|
-
NSString *preference = [sender.representedObject isKindOfClass:NSString.class] ?
|
|
263
|
-
sender.representedObject : CCPetsLanguageSystem;
|
|
264
|
-
if ([preference isEqualToString:CCPetsLanguagePreference()]) return;
|
|
265
|
-
CCPetsSetLanguagePreference(preference);
|
|
266
|
-
}
|
|
267
252
|
- (void)languageDidChange:(NSNotification *)notification {
|
|
268
253
|
PetPhrasesAdoptLanguageDefaults();
|
|
269
254
|
NSApp.mainMenu = nil;
|
|
270
|
-
[self
|
|
255
|
+
[self installMainMenu];
|
|
271
256
|
self.quotaView.needsDisplay = YES;
|
|
272
257
|
// 状态卡标题和副行都是按状态现算的,按最后的状态重排一遍。工具名没留,
|
|
273
258
|
// 工具态会暂时退成"正在使用工具",下一条事件就会补回来。
|