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
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
// 说话气泡与碎碎念。
|
|
2
2
|
#import "CCPetsAppDelegate+Private.h"
|
|
3
|
+
#import "CCPetsUsageMode.h"
|
|
3
4
|
|
|
4
5
|
// 档位写进 defaults 的键;PetView 的右键菜单也要读它。
|
|
5
6
|
NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
6
7
|
|
|
8
|
+
// 两个 Provider 的字段名不同;已过期的窗口不能触发提醒或填入台词。
|
|
9
|
+
static NSDictionary *SpeechFiveHourQuota(NSDictionary *usage) {
|
|
10
|
+
NSDictionary *quota = [usage[@"fiveHour"] isKindOfClass:NSDictionary.class] ? usage[@"fiveHour"] : nil;
|
|
11
|
+
NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class] ? quota[@"resets_at"] : nil;
|
|
12
|
+
if (reset && reset.doubleValue <= NSDate.date.timeIntervalSince1970) return nil;
|
|
13
|
+
return quota;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static NSInteger SpeechQuotaRemaining(NSDictionary *usage) {
|
|
17
|
+
NSDictionary *quota = SpeechFiveHourQuota(usage);
|
|
18
|
+
id used = quota[@"used_percentage"] ?: quota[@"used_percent"];
|
|
19
|
+
if (![used isKindOfClass:NSNumber.class]) return -1;
|
|
20
|
+
return MAX((NSInteger)0, MIN((NSInteger)100, 100 - [used integerValue]));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static NSString *SpeechQuotaResetTime(NSDictionary *usage) {
|
|
24
|
+
id reset = SpeechFiveHourQuota(usage)[@"resets_at"];
|
|
25
|
+
if (![reset isKindOfClass:NSNumber.class]) return nil;
|
|
26
|
+
NSDateFormatter *formatter = [NSDateFormatter new];
|
|
27
|
+
formatter.dateFormat = @"HH:mm";
|
|
28
|
+
formatter.timeZone = NSTimeZone.systemTimeZone;
|
|
29
|
+
return [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[reset doubleValue]]];
|
|
30
|
+
}
|
|
31
|
+
|
|
7
32
|
@implementation AppDelegate (Speech)
|
|
8
33
|
- (BOOL)speechEnabled {
|
|
9
|
-
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
10
34
|
// 缺省开启;用户可在右键菜单里关掉。
|
|
11
|
-
|
|
12
|
-
return value == nil ? YES : [value boolValue];
|
|
35
|
+
return CCPetsPrefBool(PetSpeechEnabledKey);
|
|
13
36
|
}
|
|
14
37
|
// 当前档位。现读,右键菜单里改完立刻生效不用重启。
|
|
15
38
|
- (PetSpeechRate)speechRate {
|
|
@@ -62,6 +85,9 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
62
85
|
return [self speechSlotsWithTool:self.lastSpeechTool];
|
|
63
86
|
}
|
|
64
87
|
- (NSDictionary<NSString *, NSString *> *)speechSlotsWithTool:(NSString *)tool {
|
|
88
|
+
return [self speechSlotsWithTool:tool usage:[self speechQuotaUsage]];
|
|
89
|
+
}
|
|
90
|
+
- (NSDictionary<NSString *, NSString *> *)speechSlotsWithTool:(NSString *)tool usage:(NSDictionary *)usage {
|
|
65
91
|
NSMutableDictionary<NSString *, NSString *> *slots = [NSMutableDictionary dictionary];
|
|
66
92
|
NSCalendar *calendar = NSCalendar.currentCalendar;
|
|
67
93
|
slots[@"hour"] = [@([calendar component:NSCalendarUnitHour fromDate:NSDate.date]) stringValue];
|
|
@@ -73,11 +99,11 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
73
99
|
self.sessionStartedAt) / 60.0);
|
|
74
100
|
if (minutes > 0) slots[@"sessionMin"] = [@(minutes) stringValue];
|
|
75
101
|
}
|
|
76
|
-
NSInteger remaining =
|
|
102
|
+
NSInteger remaining = SpeechQuotaRemaining(usage);
|
|
77
103
|
if (remaining >= 0) {
|
|
78
104
|
slots[@"quota5h"] = [NSString stringWithFormat:@"%ld%%", (long)remaining];
|
|
79
105
|
}
|
|
80
|
-
NSString *reset =
|
|
106
|
+
NSString *reset = SpeechQuotaResetTime(usage);
|
|
81
107
|
if (reset.length > 0) slots[@"resetTime"] = reset;
|
|
82
108
|
// 工具名此前从来没被填过,导致 "{toolName} 这货不靠谱。" 这类台词永远被跳过。
|
|
83
109
|
NSString *trimmed = [tool stringByTrimmingCharactersInSet:
|
|
@@ -85,54 +111,90 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
85
111
|
if (trimmed.length > 0 && trimmed.length <= 24) slots[@"toolName"] = trimmed;
|
|
86
112
|
return slots;
|
|
87
113
|
}
|
|
88
|
-
//
|
|
114
|
+
// 普通台词的额度槽位选剩余最少的订阅账号;低额度播报会显式传入触发账号。
|
|
115
|
+
- (NSDictionary *)speechQuotaUsage {
|
|
116
|
+
NSDictionary *selected = nil;
|
|
117
|
+
NSInteger lowest = 101;
|
|
118
|
+
NSDictionary *usages = self.quotaView.profileUsages;
|
|
119
|
+
for (NSDictionary *profile in self.quotaView.profiles) {
|
|
120
|
+
if (CCPetsProfileShowsAPIUsage(profile)) continue;
|
|
121
|
+
NSDictionary *usage = usages[profile[@"id"]];
|
|
122
|
+
NSInteger remaining = SpeechQuotaRemaining(usage);
|
|
123
|
+
if (remaining >= 0 && remaining < lowest) {
|
|
124
|
+
lowest = remaining;
|
|
125
|
+
selected = usage;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return selected;
|
|
129
|
+
}
|
|
89
130
|
- (NSInteger)remainingFiveHourQuotaPercent {
|
|
90
|
-
|
|
91
|
-
NSDictionary *fiveHour = [usage[@"fiveHour"] isKindOfClass:NSDictionary.class]
|
|
92
|
-
? usage[@"fiveHour"] : nil;
|
|
93
|
-
id used = fiveHour[@"used_percentage"] ?: fiveHour[@"used_percent"];
|
|
94
|
-
if (![used isKindOfClass:NSNumber.class]) return -1;
|
|
95
|
-
NSInteger remaining = 100 - [used integerValue];
|
|
96
|
-
return MAX((NSInteger)0, MIN((NSInteger)100, remaining));
|
|
131
|
+
return SpeechQuotaRemaining([self speechQuotaUsage]);
|
|
97
132
|
}
|
|
98
|
-
// 回血时间,按本机时区格式化。没有这个槽位的话,带 {resetTime} 的词条会被整条跳过。
|
|
99
133
|
- (NSString *)fiveHourResetTimeText {
|
|
100
|
-
|
|
101
|
-
NSDictionary *fiveHour = [usage[@"fiveHour"] isKindOfClass:NSDictionary.class]
|
|
102
|
-
? usage[@"fiveHour"] : nil;
|
|
103
|
-
id resets = fiveHour[@"resets_at"];
|
|
104
|
-
if (![resets isKindOfClass:NSNumber.class]) return nil;
|
|
105
|
-
NSTimeInterval at = [resets doubleValue];
|
|
106
|
-
if (at <= NSDate.date.timeIntervalSince1970) return nil;
|
|
107
|
-
NSDateFormatter *formatter = [NSDateFormatter new];
|
|
108
|
-
formatter.dateFormat = @"HH:mm";
|
|
109
|
-
formatter.timeZone = NSTimeZone.systemTimeZone;
|
|
110
|
-
return [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:at]];
|
|
134
|
+
return SpeechQuotaResetTime([self speechQuotaUsage]);
|
|
111
135
|
}
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
// 只在向下穿档时说一次:低于 20%% 就一直念叨会变成唠叨,而额度刷新是每分钟级别的,
|
|
115
|
-
// 不设档位的话一小时预算瞬间就被烧光。回血(档位回升)时把标记还回去,
|
|
116
|
-
// 下个周期才能再触发。
|
|
136
|
+
// 每个账号独立记档,首次采样只初始化。冷却期间排队,避免同时跨档时只播报第一个账号。
|
|
117
137
|
- (void)considerQuotaSpeech {
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
138
|
+
if (!self.quotaSpeechStates) self.quotaSpeechStates = [NSMutableDictionary dictionary];
|
|
139
|
+
if (!self.pendingQuotaSpeechProfileIDs) self.pendingQuotaSpeechProfileIDs = [NSMutableOrderedSet orderedSet];
|
|
140
|
+
NSArray<NSDictionary *> *profiles = self.quotaView.profiles;
|
|
141
|
+
NSDictionary *usages = self.quotaView.profileUsages;
|
|
142
|
+
NSMutableSet<NSString *> *liveIDs = [NSMutableSet set];
|
|
143
|
+
for (NSDictionary *profile in profiles) {
|
|
144
|
+
NSString *profileID = profile[@"id"];
|
|
145
|
+
if (profileID.length == 0 || CCPetsProfileShowsAPIUsage(profile)) continue;
|
|
146
|
+
[liveIDs addObject:profileID];
|
|
147
|
+
NSString *home = profile[@"home"] ?: @"";
|
|
148
|
+
NSDictionary *previous = self.quotaSpeechStates[profileID];
|
|
149
|
+
if (previous && ![previous[@"home"] isEqualToString:home]) {
|
|
150
|
+
[self.quotaSpeechStates removeObjectForKey:profileID];
|
|
151
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
152
|
+
previous = nil;
|
|
153
|
+
}
|
|
154
|
+
NSInteger remaining = SpeechQuotaRemaining(usages[profileID]);
|
|
155
|
+
if (remaining < 0) {
|
|
156
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
NSInteger tier = remaining <= 5 ? 0 : remaining <= 10 ? 1 : remaining <= 20 ? 2 : 3;
|
|
160
|
+
self.quotaSpeechStates[profileID] = @{@"home": home, @"tier": @(tier)};
|
|
161
|
+
if (!previous || tier > [previous[@"tier"] integerValue]) {
|
|
162
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
163
|
+
} else if (tier < [previous[@"tier"] integerValue]) {
|
|
164
|
+
[self.pendingQuotaSpeechProfileIDs addObject:profileID];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for (NSString *profileID in self.quotaSpeechStates.allKeys) {
|
|
168
|
+
if (![liveIDs containsObject:profileID]) {
|
|
169
|
+
[self.quotaSpeechStates removeObjectForKey:profileID];
|
|
170
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// 用户关闭说话时不积攒提醒;更新气泡、冷却和预算只延后播报。
|
|
174
|
+
if (![self speechEnabled]) {
|
|
175
|
+
[self.pendingQuotaSpeechProfileIDs removeAllObjects];
|
|
132
176
|
return;
|
|
133
177
|
}
|
|
134
|
-
if (
|
|
135
|
-
|
|
178
|
+
if (self.updateBubbleVisible || ![self canSpeakNow]) return;
|
|
179
|
+
for (NSString *profileID in self.pendingQuotaSpeechProfileIDs.array) {
|
|
180
|
+
NSDictionary *profile = nil;
|
|
181
|
+
for (NSDictionary *candidate in profiles) {
|
|
182
|
+
if ([candidate[@"id"] isEqualToString:profileID]) { profile = candidate; break; }
|
|
183
|
+
}
|
|
184
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
185
|
+
if (!profile) continue;
|
|
186
|
+
NSDictionary *slots = [self speechSlotsWithTool:self.lastSpeechTool usage:usages[profileID]];
|
|
187
|
+
NSString *text = PetPhraseForTag(PetPhraseTagQuotaLow, slots);
|
|
188
|
+
if (text.length == 0) continue;
|
|
189
|
+
NSString *provider = [profile[@"provider"] isEqualToString:CCPetsProfileProviderCodex] ? @"Codex" : @"Claude";
|
|
190
|
+
NSString *name = profile[@"displayName"] ?: profile[@"slug"] ?: provider;
|
|
191
|
+
text = [NSString stringWithFormat:@"%@ · %@: %@", provider, name, text];
|
|
192
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
193
|
+
[self.speechTimestamps addObject:@(now)];
|
|
194
|
+
self.speechCooldownUntil = now + [self speechCooldownSeconds];
|
|
195
|
+
[self presentSpeechText:text];
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
136
198
|
}
|
|
137
199
|
- (void)buildSpeechPanelIfNeeded {
|
|
138
200
|
if (self.speechPanel) return;
|
|
@@ -147,6 +209,8 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
147
209
|
self.speechPanel.level = NSFloatingWindowLevel;
|
|
148
210
|
self.speechPanel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces |
|
|
149
211
|
NSWindowCollectionBehaviorFullScreenAuxiliary;
|
|
212
|
+
// 和桌宠、状态卡一样不随 App 失焦隐藏。主窗口打开期间 App 是 Regular,会频繁失焦。
|
|
213
|
+
self.speechPanel.hidesOnDeactivate = NO;
|
|
150
214
|
// 气泡不抢焦点、不接受点击:它是纯播报,挡住宠物就本末倒置了。
|
|
151
215
|
self.speechPanel.ignoresMouseEvents = YES;
|
|
152
216
|
|
|
@@ -155,14 +219,14 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
155
219
|
initWithFrame:NSMakeRect(6, 6, glassSize.width, glassSize.height)
|
|
156
220
|
material:NSVisualEffectMaterialPopover appearance:NSAppearanceNameAqua
|
|
157
221
|
cornerRadius:glassSize.height / 2.0];
|
|
158
|
-
self.speechGlass.edgeShadeHeight =
|
|
159
|
-
self.speechGlass.edgeShadeAlpha =
|
|
222
|
+
self.speechGlass.edgeShadeHeight = CCPetsSpeechBubbleEdgeShadeHeight;
|
|
223
|
+
self.speechGlass.edgeShadeAlpha = CCPetsSpeechBubbleEdgeShadeAlpha;
|
|
160
224
|
self.speechGlass.usesWidgetGlass = YES;
|
|
161
225
|
|
|
162
226
|
self.speechLabel = [NSTextField labelWithString:@""];
|
|
163
227
|
self.speechLabel.frame = NSMakeRect(14, 10, glassSize.width - 28, 18);
|
|
164
228
|
// 独立气泡里这句话是唯一元素,不与标题争,比并入状态卡时大半档。
|
|
165
|
-
self.speechLabel.font = [NSFont systemFontOfSize:
|
|
229
|
+
self.speechLabel.font = [NSFont systemFontOfSize:CCPetsSpeechBubbleFontSize weight:NSFontWeightMedium];
|
|
166
230
|
self.speechLabel.textColor = [NSColor colorWithWhite:0.10 alpha:0.96];
|
|
167
231
|
self.speechLabel.alignment = NSTextAlignmentCenter;
|
|
168
232
|
self.speechLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
@@ -210,6 +274,10 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
210
274
|
|
|
211
275
|
[self presentSpeechText:text];
|
|
212
276
|
}
|
|
277
|
+
// 设置页"试说一句"和预览台用:只取词,不记预算、不进冷却,说不说由调用方决定。
|
|
278
|
+
- (NSString *)sampleSpeechLine {
|
|
279
|
+
return PetPhraseForTag(PetPhraseTagIdle, [self speechSlots]);
|
|
280
|
+
}
|
|
213
281
|
// 话往哪儿显示只在这一处决定:有状态卡就并进它的副行,没有才起独立气泡。
|
|
214
282
|
// 调试触发也必须走这里——否则看到的是现实中不会出现的画面(两个泡叠着)。
|
|
215
283
|
- (void)presentSpeechText:(NSString *)text {
|
|
@@ -303,6 +371,8 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
303
371
|
// 挂在已有的客户端存活定时器上,不新起 timer——常驻唤醒一个都不该多。
|
|
304
372
|
- (void)considerIdleSpeech {
|
|
305
373
|
[self consumeSpeechDebugTrigger];
|
|
374
|
+
// 复用存活定时器消费待播报账号,不等待下一次额度刷新,也不额外唤醒。
|
|
375
|
+
if (self.pendingQuotaSpeechProfileIDs.count > 0) [self considerQuotaSpeech];
|
|
306
376
|
if (self.updateBubbleDeferred && ![self agentBusyForSpeech]) [self showUpdateBubble];
|
|
307
377
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
308
378
|
// 真正的判断最多 30 秒做一次,3 秒一跳的定时器上不必每次都算。
|
|
@@ -381,7 +451,7 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
381
451
|
// 独立气泡:左右各 16 内边距,没有图标。
|
|
382
452
|
- (void)resizeSpeechBubbleToFitText {
|
|
383
453
|
if (!self.speechPanel) return;
|
|
384
|
-
const CGFloat padding =
|
|
454
|
+
const CGFloat padding = CCPetsSpeechBubblePadding;
|
|
385
455
|
CGFloat width = padding * 2 + PetMeasuredLabelWidth(self.speechLabel);
|
|
386
456
|
width = fmax(96.0, fmin(width, 300.0));
|
|
387
457
|
NSSize panelSize = NSMakeSize(width + 12, PetSpeechBodyHeight + 12);
|
|
@@ -389,6 +459,6 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
389
459
|
self.speechGlass.frame = NSMakeRect(6, 6, width, PetSpeechBodyHeight);
|
|
390
460
|
self.speechGlass.cornerRadius = PetSpeechBodyHeight / 2.0;
|
|
391
461
|
self.speechLabel.frame = NSMakeRect(padding, 10, width - padding * 2, 18);
|
|
392
|
-
self.speechClickButton.frame =
|
|
462
|
+
self.speechClickButton.frame = NSMakeRect(0, 0, panelSize.width, panelSize.height);
|
|
393
463
|
}
|
|
394
464
|
@end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// 主窗口工作台几页的数据快照(见 CCPetsWorkbench.h)。只读:整理现有的会话、Bridge、额度状态,
|
|
2
|
+
// 不新增任何采集。
|
|
3
|
+
#import "CCPetsAppDelegate+Private.h"
|
|
4
|
+
#import "CCPetsBridge.h"
|
|
5
|
+
#import "CCPetsDiagnosticsPage.h"
|
|
6
|
+
#import "CCPetsUsageMode.h"
|
|
7
|
+
|
|
8
|
+
NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWorkbenchQuotasDidChange";
|
|
9
|
+
|
|
10
|
+
@implementation AppDelegate (Workbench)
|
|
11
|
+
|
|
12
|
+
- (NSArray<NSDictionary *> *)workbenchSessions {
|
|
13
|
+
[self pruneOfflineAgentSessionRecords];
|
|
14
|
+
NSDictionary<NSString *, NSNumber *> *pending = self.bridgePendingCounts ?: @{};
|
|
15
|
+
NSMutableArray<NSDictionary *> *sessions = [NSMutableArray array];
|
|
16
|
+
for (NSString *key in self.agentSessionRecords) {
|
|
17
|
+
NSDictionary *record = self.agentSessionRecords[key];
|
|
18
|
+
NSString *provider = SanitizedShortString(record[@"provider"], 32).lowercaseString;
|
|
19
|
+
// 和状态气泡一致:启动后一直没有后续事件,说明会话已就绪、在等输入。
|
|
20
|
+
NSString *state = SessionDisplayState([record[@"state"] isKindOfClass:NSString.class]
|
|
21
|
+
? record[@"state"] : @"", [record[@"timestamp"] doubleValue], NSDate.date.timeIntervalSince1970);
|
|
22
|
+
NSString *tool = [record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @"";
|
|
23
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class] ? record[@"terminal"] : nil;
|
|
24
|
+
NSMutableDictionary *session = [NSMutableDictionary dictionary];
|
|
25
|
+
session[@"id"] = key;
|
|
26
|
+
session[@"provider"] = [provider isEqualToString:@"claude"] ? @"Claude"
|
|
27
|
+
: ([provider isEqualToString:@"codex"] ? @"Codex" : (provider.length > 0 ? provider : @"Agent"));
|
|
28
|
+
if ([record[@"profileId"] isKindOfClass:NSString.class]) session[@"profileId"] = record[@"profileId"];
|
|
29
|
+
if ([record[@"profileName"] isKindOfClass:NSString.class]) session[@"profileName"] = record[@"profileName"];
|
|
30
|
+
session[@"state"] = state;
|
|
31
|
+
session[@"status"] = [self statusTextForState:state tool:tool];
|
|
32
|
+
session[@"tool"] = SanitizedShortString(tool, 64) ?: @"";
|
|
33
|
+
session[@"terminal"] = terminal.count > 0 ? [self terminalNameForTarget:terminal] : @"";
|
|
34
|
+
session[@"updatedAt"] = record[@"timestamp"] ?: @0;
|
|
35
|
+
NSDictionary *bridge = [self bridgeSessionEntryForRecord:record];
|
|
36
|
+
if ([bridge[@"name"] isKindOfClass:NSString.class]) session[@"name"] = bridge[@"name"];
|
|
37
|
+
NSString *bridgeID = [self bridgeSessionIdForRecord:record];
|
|
38
|
+
session[@"pendingMessages"] = bridgeID ? (pending[bridgeID] ?: @0) : @0;
|
|
39
|
+
[sessions addObject:session];
|
|
40
|
+
}
|
|
41
|
+
// 和右键会话菜单同一个次序:等审批的置顶,其余新的在前。
|
|
42
|
+
[sessions sortUsingComparator:^NSComparisonResult(NSDictionary *left, NSDictionary *right) {
|
|
43
|
+
BOOL leftApproval = [left[@"state"] isEqualToString:@"approval"];
|
|
44
|
+
BOOL rightApproval = [right[@"state"] isEqualToString:@"approval"];
|
|
45
|
+
if (leftApproval != rightApproval) return leftApproval ? NSOrderedAscending : NSOrderedDescending;
|
|
46
|
+
return [right[@"updatedAt"] compare:left[@"updatedAt"]];
|
|
47
|
+
}];
|
|
48
|
+
return sessions;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
- (NSDictionary *)workbenchMessages {
|
|
52
|
+
if (!CCBridgeEnabled()) return @{@"enabled": @NO, @"pending": @[], @"deliveries": @[]};
|
|
53
|
+
[self refreshBridgeState:nil];
|
|
54
|
+
NSMutableArray<NSDictionary *> *pending = [NSMutableArray array];
|
|
55
|
+
[self.bridgePendingCounts enumerateKeysAndObjectsUsingBlock:^(NSString *session, NSNumber *count, BOOL *stop) {
|
|
56
|
+
NSString *name = self.bridgeSessions[session][@"name"];
|
|
57
|
+
[pending addObject:@{@"session": session, @"name": [name isKindOfClass:NSString.class] ? name : session,
|
|
58
|
+
@"count": count}];
|
|
59
|
+
}];
|
|
60
|
+
[pending sortUsingComparator:^NSComparisonResult(NSDictionary *left, NSDictionary *right) {
|
|
61
|
+
return [left[@"name"] localizedStandardCompare:right[@"name"]];
|
|
62
|
+
}];
|
|
63
|
+
NSMutableArray<NSDictionary *> *deliveries = [NSMutableArray array];
|
|
64
|
+
for (NSDictionary *delivery in self.bridgeRecentDeliveries) {
|
|
65
|
+
NSMutableDictionary *entry = [delivery mutableCopy];
|
|
66
|
+
entry[@"unseen"] = @([delivery[@"at"] doubleValue] > self.bridgeSeenAt);
|
|
67
|
+
[deliveries addObject:entry];
|
|
68
|
+
}
|
|
69
|
+
return @{@"enabled": @YES, @"pending": pending, @"deliveries": deliveries};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
- (NSArray<NSDictionary *> *)workbenchQuotas {
|
|
73
|
+
NSMutableArray<NSDictionary *> *quotas = [NSMutableArray array];
|
|
74
|
+
// 平台次序和悬停面板一致,但概览同时列出全部账号,不跟随轮播选择。
|
|
75
|
+
for (NSString *provider in [self.quotaView visibleProviders]) {
|
|
76
|
+
NSMutableArray<NSDictionary *> *profiles = [NSMutableArray array];
|
|
77
|
+
for (NSDictionary *profile in self.quotaView.profiles ?: CCPetsProfiles()) {
|
|
78
|
+
if ([profile[@"provider"] isEqualToString:provider.lowercaseString]) [profiles addObject:profile];
|
|
79
|
+
}
|
|
80
|
+
// 未登记账号时保留旧版的平台卡片。
|
|
81
|
+
if (profiles.count == 0) [profiles addObject:@{}];
|
|
82
|
+
for (NSDictionary *profile in profiles) {
|
|
83
|
+
NSString *profileID = profile[@"id"];
|
|
84
|
+
NSMutableDictionary *quota = [[self.quotaView accountSnapshotForProvider:provider
|
|
85
|
+
profile:profile.count > 0 ? profile : nil] mutableCopy];
|
|
86
|
+
NSDictionary *usage = quota[@"usage"];
|
|
87
|
+
NSString *usedKey = [provider isEqualToString:@"Claude"] ? @"used_percentage" : @"used_percent";
|
|
88
|
+
NSNumber *weekUsed = nil;
|
|
89
|
+
for (NSArray<NSString *> *window in @[@[@"fiveHour", @"five"], @[@"week", @"week"]]) {
|
|
90
|
+
NSDictionary *limit = [usage[window[0]] isKindOfClass:NSDictionary.class] ? usage[window[0]] : nil;
|
|
91
|
+
NSNumber *used = [limit[usedKey] isKindOfClass:NSNumber.class] ? limit[usedKey] : nil;
|
|
92
|
+
if (used) {
|
|
93
|
+
double clamped = fmax(0, fmin(100, used.doubleValue));
|
|
94
|
+
quota[[window[1] stringByAppendingString:@"Remaining"]] = @(100 - clamped);
|
|
95
|
+
if ([window[1] isEqualToString:@"week"]) weekUsed = @(clamped);
|
|
96
|
+
}
|
|
97
|
+
if ([limit[@"resets_at"] isKindOfClass:NSNumber.class]) {
|
|
98
|
+
quota[[window[1] stringByAppendingString:@"Reset"]] = limit[@"resets_at"];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (![quota[@"apiMode"] boolValue]) {
|
|
102
|
+
NSDictionary *week = [usage[@"week"] isKindOfClass:NSDictionary.class] ? usage[@"week"] : nil;
|
|
103
|
+
NSDictionary *pace = [self.quotaView paceStatusForQuota:week currentUsed:weekUsed color:NSColor.systemTealColor];
|
|
104
|
+
if (pace[@"level"]) {
|
|
105
|
+
quota[@"pace"] = pace[@"label"];
|
|
106
|
+
quota[@"paceLevel"] = pace[@"level"];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (NSDictionary *section in CCPetsDiagnosticsStore.sections) {
|
|
110
|
+
if (!profileID) continue;
|
|
111
|
+
for (NSDictionary *result in section[@"results"]) {
|
|
112
|
+
if (![section[@"profileID"] isEqualToString:profileID] &&
|
|
113
|
+
![result[@"profileID"] isEqualToString:profileID]) continue;
|
|
114
|
+
if ([@[@"warn", @"fail"] containsObject:result[@"level"]]) quota[@"hasDiagnosticIssues"] = @YES;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
[quotas addObject:quota];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return quotas;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
- (void)focusWorkbenchSessionWithID:(NSString *)sessionID {
|
|
124
|
+
NSDictionary *record = sessionID ? self.agentSessionRecords[sessionID] : nil;
|
|
125
|
+
NSDictionary *target = [record[@"terminal"] isKindOfClass:NSDictionary.class] ? record[@"terminal"] : nil;
|
|
126
|
+
if (target.count > 0) ActivateTerminalFocusTarget(target);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
- (void)focusBridgeSessionWithID:(NSString *)sessionID {
|
|
130
|
+
NSDictionary *target = sessionID ? [self terminalTargetForBridgeSession:sessionID] : nil;
|
|
131
|
+
if (target.count > 0) ActivateTerminalFocusTarget(target);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
- (void)markWorkbenchMessagesSeen {
|
|
135
|
+
self.bridgeSeenAt = NSDate.date.timeIntervalSince1970;
|
|
136
|
+
[self refreshBridgeState:nil];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@end
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
// 最近一次 agent 事件的工具名,供 {toolName} 槽位使用。
|
|
27
27
|
@property(copy) NSString *lastSpeechTool;
|
|
28
28
|
// 上次播报额度时剩余百分比落在哪一档。只在向下穿档时说,不是"低于阈值就一直说"。
|
|
29
|
-
@property
|
|
30
|
-
@property
|
|
29
|
+
@property NSMutableDictionary<NSString *, NSDictionary *> *quotaSpeechStates;
|
|
30
|
+
@property NSMutableOrderedSet<NSString *> *pendingQuotaSpeechProfileIDs;
|
|
31
31
|
@property NSPanel *statusPanel;
|
|
32
32
|
@property CCPetsGlassView *statusGlass;
|
|
33
33
|
@property CCPetsGlassView *quotaGlass;
|
|
@@ -51,6 +51,12 @@
|
|
|
51
51
|
@property NSDictionary<NSString *, NSNumber *> *bridgePendingCounts;
|
|
52
52
|
// 菜单开关触发的 cc-pets bridge 命令正在执行时为 YES,期间忽略新的切换,避免并发改配置。
|
|
53
53
|
@property BOOL bridgeCommandRunning;
|
|
54
|
+
// 手动 Agent Home 适配任务与其非阻塞进度窗口。
|
|
55
|
+
@property BOOL profileCommandRunning;
|
|
56
|
+
@property NSTask *profileTask;
|
|
57
|
+
@property NSWindow *profileProgressWindow;
|
|
58
|
+
@property NSTextField *profileProgressLabel;
|
|
59
|
+
@property NSProgressIndicator *profileProgressIndicator;
|
|
54
60
|
// 已为哪个时间点之前的送达发过系统通知。
|
|
55
61
|
@property NSTimeInterval bridgeNotifiedAt;
|
|
56
62
|
@property BOOL statusBubbleExpanded;
|
|
@@ -59,9 +65,16 @@
|
|
|
59
65
|
@property NSInteger liveClientCount;
|
|
60
66
|
@property NSString *lastStatusState;
|
|
61
67
|
@property NSString *lastStatusProvider;
|
|
68
|
+
// lastStatusProvider 是卡片标题(有账号名时显示账号名),不能拿去对 pid 文件里的
|
|
69
|
+
// "Claude"/"Codex";在线判定用原始 provider,判断“是不是同一账号”用 provider|profileId。
|
|
70
|
+
@property NSString *lastStatusAgentProvider;
|
|
71
|
+
@property NSString *lastStatusIdentity;
|
|
62
72
|
@property NSDictionary *lastTerminalFocusTarget;
|
|
63
73
|
@property NSTimeInterval lastStatusTimestamp;
|
|
64
74
|
@property NSSet<NSString *> *liveClientProviders;
|
|
75
|
+
// 新版包装器在 pid 文件中同时记录 profileId;旧文件没有该行,按 provider 级在线兜底。
|
|
76
|
+
@property NSSet<NSString *> *liveClientProfileIDs;
|
|
77
|
+
@property NSSet<NSString *> *liveUnscopedClientProviders;
|
|
65
78
|
// 包装脚本仍存活的精确 Agent 会话,键为 provider + TTY。
|
|
66
79
|
@property NSSet<NSString *> *liveAgentSessionKeys;
|
|
67
80
|
// 每个 provider 最近一次事件的时间。不经包装脚本启动的客户端没有 pid 文件,
|
|
@@ -76,6 +89,8 @@
|
|
|
76
89
|
@property NSMutableSet<NSString *> *stallNotifiedSessionKeys;
|
|
77
90
|
@property QuotaDashboardView *quotaView;
|
|
78
91
|
@property BOOL managedByCLI;
|
|
92
|
+
// 启动参数 --open-window [page] 带来的:启动完成后打开主窗口。nil 表示不开;空串表示开上次看的页面。
|
|
93
|
+
@property(copy) NSString *launchWindowPage;
|
|
79
94
|
@property BOOL pocketHovering;
|
|
80
95
|
@property BOOL dashboardHovering;
|
|
81
96
|
@property BOOL petDragging;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// AppDelegate 主干:启动、退出、窗口跟随。各功能模块在 CCPetsAppDelegate+<模块>.m 里,
|
|
2
2
|
// 共享常量和跨文件的方法声明见 CCPetsAppDelegate+Private.h。
|
|
3
3
|
#import "CCPetsAppDelegate+Private.h"
|
|
4
|
+
#import "CCPetsOpenCommand.h"
|
|
5
|
+
|
|
6
|
+
@implementation CCPetsBubbleContainerView
|
|
7
|
+
@end
|
|
4
8
|
|
|
5
9
|
@implementation CCPetsStatusClickButton
|
|
6
10
|
- (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; }
|
|
@@ -61,24 +65,34 @@
|
|
|
61
65
|
[alert addButtonWithTitle:L(@"OK")];
|
|
62
66
|
[alert runModal];
|
|
63
67
|
}
|
|
64
|
-
//
|
|
68
|
+
// 主菜单:应用、编辑、窗口三项。
|
|
65
69
|
//
|
|
66
70
|
// ⌘C/⌘V/⌘A/⌘Z 不是 NSTextView 自己处理的:按键先走 NSApp.mainMenu 的
|
|
67
71
|
// performKeyEquivalent:,命中菜单项之后才沿响应者链发 copy: / paste: 这些消息。
|
|
68
|
-
// 这个 app 是 LSUIElement
|
|
72
|
+
// 这个 app 是 LSUIElement,以前没设主菜单时,台词编辑器里这些快捷键全部落空。
|
|
69
73
|
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
74
|
+
// 平时是 Accessory,菜单栏不显示,这份菜单只是一张快捷键路由表;主窗口打开期间切成 Regular,
|
|
75
|
+
// 它就是用户看到的菜单栏。第一项按 AppKit 约定当作应用菜单,标题不显示,显示的是 App 名。
|
|
76
|
+
// 桌宠面板是 NSNonactivatingPanel,点它根本不激活 app,碰不到这里。
|
|
73
77
|
//
|
|
74
|
-
// action 一律留给响应者链(target 为 nil),谁是第一响应者谁处理——写死 target 的话
|
|
75
|
-
//
|
|
76
|
-
- (void)
|
|
78
|
+
// 编辑项的 action 一律留给响应者链(target 为 nil),谁是第一响应者谁处理——写死 target 的话
|
|
79
|
+
// 编辑器之外的文本框就用不上了。没有「隐藏」:hide: 会把桌宠浮窗一起藏起来。
|
|
80
|
+
- (void)installMainMenu {
|
|
77
81
|
if (NSApp.mainMenu) return;
|
|
78
82
|
NSMenu *mainMenu = [NSMenu new];
|
|
83
|
+
|
|
84
|
+
NSMenuItem *appItem = [mainMenu addItemWithTitle:@"CC Pets" action:nil keyEquivalent:@""];
|
|
85
|
+
NSMenu *appMenu = [[NSMenu alloc] initWithTitle:@"CC Pets"];
|
|
86
|
+
[appMenu addItemWithTitle:L(@"About CC Pets") action:@selector(showAboutPanel:) keyEquivalent:@""].target = self;
|
|
87
|
+
[appMenu addItem:NSMenuItem.separatorItem];
|
|
88
|
+
[appMenu addItemWithTitle:L(@"Settings…") action:@selector(openMainWindow:) keyEquivalent:@","].target = self;
|
|
89
|
+
[appMenu addItemWithTitle:L(@"Multi-Account") action:@selector(openAccountsPage:) keyEquivalent:@""].target = self;
|
|
90
|
+
[appMenu addItem:NSMenuItem.separatorItem];
|
|
91
|
+
[appMenu addItemWithTitle:L(@"Quit CC Pets") action:@selector(terminate:) keyEquivalent:@"q"].target = NSApp;
|
|
92
|
+
appItem.submenu = appMenu;
|
|
93
|
+
|
|
79
94
|
NSMenuItem *editItem = [mainMenu addItemWithTitle:L(@"Edit") action:nil keyEquivalent:@""];
|
|
80
95
|
NSMenu *editMenu = [[NSMenu alloc] initWithTitle:L(@"Edit")];
|
|
81
|
-
|
|
82
96
|
NSArray<NSArray *> *entries = @[
|
|
83
97
|
@[L(@"Undo"), NSStringFromSelector(@selector(undo:)), @"z", @(NSEventModifierFlagCommand)],
|
|
84
98
|
@[L(@"Redo"), NSStringFromSelector(@selector(redo:)), @"z",
|
|
@@ -100,11 +114,79 @@
|
|
|
100
114
|
item.keyEquivalentModifierMask = (NSEventModifierFlags)[entry[3] unsignedIntegerValue];
|
|
101
115
|
}
|
|
102
116
|
editItem.submenu = editMenu;
|
|
117
|
+
|
|
118
|
+
NSMenuItem *windowItem = [mainMenu addItemWithTitle:L(@"Window") action:nil keyEquivalent:@""];
|
|
119
|
+
NSMenu *windowMenu = [[NSMenu alloc] initWithTitle:L(@"Window")];
|
|
120
|
+
[windowMenu addItemWithTitle:L(@"Minimize") action:@selector(performMiniaturize:) keyEquivalent:@"m"];
|
|
121
|
+
[windowMenu addItemWithTitle:L(@"Close") action:@selector(performClose:) keyEquivalent:@"w"];
|
|
122
|
+
windowItem.submenu = windowMenu;
|
|
123
|
+
NSApp.windowsMenu = windowMenu;
|
|
124
|
+
|
|
103
125
|
NSApp.mainMenu = mainMenu;
|
|
104
126
|
}
|
|
127
|
+
- (void)openMainWindow:(id)sender {
|
|
128
|
+
[CCPetsMainWindowController presentPage:nil];
|
|
129
|
+
}
|
|
130
|
+
- (void)openAccountsPage:(id)sender {
|
|
131
|
+
[CCPetsMainWindowController presentPage:CCPetsMainWindowPageAccounts];
|
|
132
|
+
}
|
|
133
|
+
- (void)openWindowRequested:(NSNotification *)notification {
|
|
134
|
+
NSString *page = notification.userInfo[@"page"];
|
|
135
|
+
[CCPetsMainWindowController presentPage:[page isKindOfClass:NSString.class] && page.length > 0 ? page : nil];
|
|
136
|
+
}
|
|
137
|
+
- (NSDictionary *)petCardSnapshot {
|
|
138
|
+
NSMutableDictionary *snapshot = [NSMutableDictionary dictionary];
|
|
139
|
+
snapshot[@"sheet"] = self.petView.sheet;
|
|
140
|
+
snapshot[@"rowCount"] = @(self.petView.spriteRowCount);
|
|
141
|
+
NSDictionary *option = [self petOptionWithID:self.petView.currentPetID inOptions:[self petOptions]];
|
|
142
|
+
snapshot[@"name"] = [option[@"name"] isKindOfClass:NSString.class] ? option[@"name"] : nil;
|
|
143
|
+
NSString *state = self.hasAgentStatus && self.lastStatusState.length > 0 ? self.lastStatusState : @"idle";
|
|
144
|
+
snapshot[@"state"] = state;
|
|
145
|
+
// 和状态卡标题同一句("Claude · 思考中"),没有会话时就是待机。
|
|
146
|
+
snapshot[@"status"] = self.hasAgentStatus && self.statusTitleLabel.stringValue.length > 0
|
|
147
|
+
? self.statusTitleLabel.stringValue : L(@"Idle");
|
|
148
|
+
snapshot[@"statusColor"] = [self statusColorForState:state];
|
|
149
|
+
// 宠物口吻的那句(状态卡副行),概览页拿来当宠物头上的气泡。
|
|
150
|
+
if (self.hasAgentStatus && self.statusDetailLabel.stringValue.length > 0) {
|
|
151
|
+
snapshot[@"detail"] = self.statusDetailLabel.stringValue;
|
|
152
|
+
}
|
|
153
|
+
snapshot[@"approvals"] = @([self pendingApprovalSessionRecords].count);
|
|
154
|
+
NSUInteger sessions = 0;
|
|
155
|
+
for (NSDictionary *record in self.agentSessionRecords.allValues) {
|
|
156
|
+
if ([self isAgentSessionRecordLive:record]) sessions++;
|
|
157
|
+
}
|
|
158
|
+
snapshot[@"sessions"] = @(sessions);
|
|
159
|
+
return snapshot;
|
|
160
|
+
}
|
|
161
|
+
// 合并到下一轮 runloop 再发:一条 Agent 事件会同时改状态、会话和审批,没必要让名片刷三遍;
|
|
162
|
+
// 而且取快照时会顺带清理离线会话,清理又会走到这里,同步发会在刷新途中再触发刷新。
|
|
163
|
+
- (void)notePetCardChanged {
|
|
164
|
+
static BOOL pending;
|
|
165
|
+
if (pending) return;
|
|
166
|
+
pending = YES;
|
|
167
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
168
|
+
pending = NO;
|
|
169
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsPetCardDidChangeNotification
|
|
170
|
+
object:nil];
|
|
171
|
+
});
|
|
172
|
+
}
|
|
105
173
|
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
|
106
174
|
// 没有主菜单的话,台词编辑器里 ⌘C/⌘V/⌘A/⌘Z 全部没反应。
|
|
107
|
-
[self
|
|
175
|
+
[self installMainMenu];
|
|
176
|
+
// 迁移旧集成,并自动登记官方 ~/.claude / ~/.codex。其他目录永远不自动扫描。
|
|
177
|
+
NSString *profileMigrationError = nil;
|
|
178
|
+
if (!CCPetsMigrateManagedDefaultProfiles(&profileMigrationError) && profileMigrationError.length > 0) {
|
|
179
|
+
fprintf(stderr, "%s\n", profileMigrationError.UTF8String);
|
|
180
|
+
}
|
|
181
|
+
profileMigrationError = nil;
|
|
182
|
+
if (!CCPetsEnsureOfficialDefaultProfiles(&profileMigrationError) && profileMigrationError.length > 0) {
|
|
183
|
+
fprintf(stderr, "%s\n", profileMigrationError.UTF8String);
|
|
184
|
+
}
|
|
185
|
+
// `cc-pets open` 在桌宠已运行时靠这条通知开窗,不走 reopen 事件:每个终端启动 CLI 都会
|
|
186
|
+
// `open -g` 一次桌宠,借 reopen 开窗会让每开一个终端就弹一次主窗口。
|
|
187
|
+
[NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(openWindowRequested:)
|
|
188
|
+
name:CCPetsOpenWindowNotificationName() object:nil
|
|
189
|
+
suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
|
|
108
190
|
// 台词全在这个文件里,代码里没有第二份。首次启动先从默认词库拷一份出来,
|
|
109
191
|
// 否则新装的桌宠一句话都不会说。
|
|
110
192
|
PetPhrasesEnsureFileExists();
|
|
@@ -154,7 +236,8 @@
|
|
|
154
236
|
[defaults setBool:YES forKey:StatusBubblePreferenceV2Key];
|
|
155
237
|
}
|
|
156
238
|
self.statusBubbleExpanded = [defaults boolForKey:StatusBubbleExpandedKey];
|
|
157
|
-
|
|
239
|
+
PetMigrateRenamedBuiltinSprite(defaults);
|
|
240
|
+
NSString *selected = [defaults stringForKey:PetSelectedSpriteKey];
|
|
158
241
|
if (selected.length > 0 && ![selected containsString:@":"]) selected = [@"builtin:" stringByAppendingString:selected];
|
|
159
242
|
NSDictionary *selectedOption = [self petOptionWithID:selected inOptions:petOptions] ?: petOptions.firstObject;
|
|
160
243
|
selected = selectedOption[@"id"];
|
|
@@ -406,6 +489,8 @@
|
|
|
406
489
|
self.pendingApprovalRecords = [NSMutableDictionary dictionary];
|
|
407
490
|
self.stallNotifiedSessionKeys = [NSMutableSet set];
|
|
408
491
|
self.usageMonitor.changeHandler = ^(NSDictionary *codexUsage, NSDictionary *claudeUsage) {
|
|
492
|
+
weakSelf.quotaView.profiles = weakSelf.usageMonitor.profiles;
|
|
493
|
+
weakSelf.quotaView.profileUsages = weakSelf.usageMonitor.profileUsages;
|
|
409
494
|
[weakSelf applyCodexUsage:codexUsage claudeUsage:claudeUsage];
|
|
410
495
|
[weakSelf considerQuotaSpeech];
|
|
411
496
|
};
|
|
@@ -442,11 +527,22 @@
|
|
|
442
527
|
name:NSWorkspaceScreensDidWakeNotification object:nil];
|
|
443
528
|
// 启动先让界面和事件流就位,再联网检查更新,别和启动抢时间。
|
|
444
529
|
[self performSelector:@selector(silentCheckForUpdate) withObject:nil afterDelay:5.0];
|
|
530
|
+
if (self.launchWindowPage) {
|
|
531
|
+
[CCPetsMainWindowController presentPage:self.launchWindowPage.length > 0 ? self.launchWindowPage : nil];
|
|
532
|
+
}
|
|
445
533
|
}
|
|
446
534
|
// CLI 启动时桌宠若已在运行,`open -g` 不会重新启动它,只会发一个 reopen 事件过来。
|
|
447
535
|
// 借这个时机同样静默检查一次更新(silentCheckForUpdate 自己做节流)。
|
|
536
|
+
//
|
|
537
|
+
// 主窗口最小化后点 Dock 图标,来的也是 reopen。要把窗口恢复出来,但不能对 `open -g` 这么做:
|
|
538
|
+
// 每开一个终端都会发一次,窗口会被反复弹出来。两者的区别是点 Dock 会激活 App、`open -g` 不会,
|
|
539
|
+
// 所以等到下一轮 runloop(激活已经完成)再看 App 是否在前台。返回 NO:系统默认的处理会去开
|
|
540
|
+
// "新窗口",桌宠没有那种窗口。
|
|
448
541
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag {
|
|
449
542
|
[self silentCheckForUpdate];
|
|
543
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
544
|
+
if (NSApp.isActive) [CCPetsMainWindowController restoreFromDock];
|
|
545
|
+
});
|
|
450
546
|
return NO;
|
|
451
547
|
}
|
|
452
548
|
- (void)screensDidSleep:(NSNotification *)notification {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
// `cc-pets open [page]`:从终端打开主窗口并定位到页面。
|
|
4
|
+
//
|
|
5
|
+
// 桌宠已在运行:发分布式通知,由它开窗。不能借 reopen 事件——每个终端启动 CLI 都会
|
|
6
|
+
// `open -g` 一次桌宠,借它开窗会让每开一个终端就弹一次主窗口。
|
|
7
|
+
// 桌宠没在运行:不带 -g 地启动 App 并传 `--open-window [page]`,起来后自己开窗。
|
|
8
|
+
//
|
|
9
|
+
// arguments 是 "open" 之后的参数。返回进程退出码。
|
|
10
|
+
int CCPetsOpenMain(NSArray<NSString *> *arguments);
|
|
11
|
+
|
|
12
|
+
// 通知名带 uid:同一台机器上多个用户会话各有各的桌宠,别互相开窗。userInfo 的 page 为空串表示上次的页面。
|
|
13
|
+
NSString *CCPetsOpenWindowNotificationName(void);
|