cc-pets 2.3.0 → 2.5.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 +63 -7
- package/CC_BRIDGE.zh-CN.md +43 -5
- package/CHANGELOG.md +106 -0
- package/CHANGELOG.zh-CN.md +106 -0
- package/CONTRIBUTING.md +23 -1
- package/CONTRIBUTING.zh-CN.md +18 -1
- package/PROVIDER_PROTOCOL.md +5 -1
- package/PROVIDER_PROTOCOL.zh-CN.md +4 -1
- package/README.md +177 -33
- package/README.zh-CN.md +137 -32
- 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 +187 -35
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +47 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +121 -20
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +8 -6
- package/Sources/CCPets/App/CCPetsAppDelegate+MenuBar.m +86 -0
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +14 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +6 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +3 -6
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +118 -50
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +4 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +4 -0
- package/Sources/CCPets/App/CCPetsAppDelegate.h +12 -2
- package/Sources/CCPets/App/CCPetsAppDelegate.m +4 -2
- package/Sources/CCPets/App/main.m +6 -0
- package/Sources/CCPets/Bridge/CCPetsBridge.m +45 -18
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +175 -68
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +14 -6
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +356 -110
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +0 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +247 -126
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +37 -9
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +385 -80
- package/Sources/CCPets/Integrations/CCPetsEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.m +68 -12
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.h +21 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.m +503 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +1 -1
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +367 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +8 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +156 -25
- 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/CCPetsPhrasesEditor.m +7 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +11 -3
- package/Sources/CCPets/Pet/PetView.h +7 -0
- package/Sources/CCPets/Pet/PetView.m +12 -1
- package/Sources/CCPets/Support/CCPetsDoctor.m +26 -12
- package/Sources/CCPets/Support/CCPetsPreferences.h +12 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +52 -2
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +2 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +18 -7
- package/Sources/CCPets/UI/CCPetsGlassView.h +26 -4
- package/Sources/CCPets/UI/CCPetsGlassView.m +40 -9
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.h +16 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.m +70 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.h +18 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +528 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.h +51 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +95 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +6 -1
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +577 -66
- package/Sources/CCPets/UI/CCPetsStatusItem.h +28 -0
- package/Sources/CCPets/UI/CCPetsStatusItem.m +147 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +5 -2
- package/Sources/CCPets/UI/CCPetsUIStyle.m +57 -8
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +4 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +23 -28
- package/Sources/CCPets/UI/CCPetsUsageStore.m +2 -2
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +5 -3
- package/Sources/CCPets/Usage/CCPetsUsage+CodexBackground.m +193 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +1 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +49 -11
- package/Sources/CCPets/Usage/CCPetsUsage.h +3 -2
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +15 -17
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +11 -29
- package/Sources/CCPets/Usage/QuotaDashboardView.m +128 -2
- package/THIRD_PARTY_NOTICES.md +7 -3
- package/THIRD_PARTY_NOTICES.zh-CN.md +5 -1
- package/bin/claude-with-pet +2 -0
- package/bin/codex-with-pet +2 -0
- 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 +24 -2
- package/scripts/compile-cached.zsh +133 -0
|
@@ -1,9 +1,34 @@
|
|
|
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
34
|
// 缺省开启;用户可在右键菜单里关掉。
|
|
@@ -45,7 +70,8 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
45
70
|
return ![self.lastStatusState isEqualToString:@"idle"];
|
|
46
71
|
}
|
|
47
72
|
- (BOOL)canSpeakNow {
|
|
48
|
-
|
|
73
|
+
// 「仅菜单栏」时没有地方放这句话,也不占预算和冷却。
|
|
74
|
+
if (![self speechEnabled] || ![self petVisible]) return NO;
|
|
49
75
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
50
76
|
if (now < self.speechCooldownUntil) return NO;
|
|
51
77
|
if (!self.speechTimestamps) self.speechTimestamps = [NSMutableArray array];
|
|
@@ -60,6 +86,9 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
60
86
|
return [self speechSlotsWithTool:self.lastSpeechTool];
|
|
61
87
|
}
|
|
62
88
|
- (NSDictionary<NSString *, NSString *> *)speechSlotsWithTool:(NSString *)tool {
|
|
89
|
+
return [self speechSlotsWithTool:tool usage:[self speechQuotaUsage]];
|
|
90
|
+
}
|
|
91
|
+
- (NSDictionary<NSString *, NSString *> *)speechSlotsWithTool:(NSString *)tool usage:(NSDictionary *)usage {
|
|
63
92
|
NSMutableDictionary<NSString *, NSString *> *slots = [NSMutableDictionary dictionary];
|
|
64
93
|
NSCalendar *calendar = NSCalendar.currentCalendar;
|
|
65
94
|
slots[@"hour"] = [@([calendar component:NSCalendarUnitHour fromDate:NSDate.date]) stringValue];
|
|
@@ -71,11 +100,11 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
71
100
|
self.sessionStartedAt) / 60.0);
|
|
72
101
|
if (minutes > 0) slots[@"sessionMin"] = [@(minutes) stringValue];
|
|
73
102
|
}
|
|
74
|
-
NSInteger remaining =
|
|
103
|
+
NSInteger remaining = SpeechQuotaRemaining(usage);
|
|
75
104
|
if (remaining >= 0) {
|
|
76
105
|
slots[@"quota5h"] = [NSString stringWithFormat:@"%ld%%", (long)remaining];
|
|
77
106
|
}
|
|
78
|
-
NSString *reset =
|
|
107
|
+
NSString *reset = SpeechQuotaResetTime(usage);
|
|
79
108
|
if (reset.length > 0) slots[@"resetTime"] = reset;
|
|
80
109
|
// 工具名此前从来没被填过,导致 "{toolName} 这货不靠谱。" 这类台词永远被跳过。
|
|
81
110
|
NSString *trimmed = [tool stringByTrimmingCharactersInSet:
|
|
@@ -83,54 +112,90 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
83
112
|
if (trimmed.length > 0 && trimmed.length <= 24) slots[@"toolName"] = trimmed;
|
|
84
113
|
return slots;
|
|
85
114
|
}
|
|
86
|
-
//
|
|
115
|
+
// 普通台词的额度槽位选剩余最少的订阅账号;低额度播报会显式传入触发账号。
|
|
116
|
+
- (NSDictionary *)speechQuotaUsage {
|
|
117
|
+
NSDictionary *selected = nil;
|
|
118
|
+
NSInteger lowest = 101;
|
|
119
|
+
NSDictionary *usages = self.quotaView.profileUsages;
|
|
120
|
+
for (NSDictionary *profile in self.quotaView.profiles) {
|
|
121
|
+
if (CCPetsProfileShowsAPIUsage(profile)) continue;
|
|
122
|
+
NSDictionary *usage = usages[profile[@"id"]];
|
|
123
|
+
NSInteger remaining = SpeechQuotaRemaining(usage);
|
|
124
|
+
if (remaining >= 0 && remaining < lowest) {
|
|
125
|
+
lowest = remaining;
|
|
126
|
+
selected = usage;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return selected;
|
|
130
|
+
}
|
|
87
131
|
- (NSInteger)remainingFiveHourQuotaPercent {
|
|
88
|
-
|
|
89
|
-
NSDictionary *fiveHour = [usage[@"fiveHour"] isKindOfClass:NSDictionary.class]
|
|
90
|
-
? usage[@"fiveHour"] : nil;
|
|
91
|
-
id used = fiveHour[@"used_percentage"] ?: fiveHour[@"used_percent"];
|
|
92
|
-
if (![used isKindOfClass:NSNumber.class]) return -1;
|
|
93
|
-
NSInteger remaining = 100 - [used integerValue];
|
|
94
|
-
return MAX((NSInteger)0, MIN((NSInteger)100, remaining));
|
|
132
|
+
return SpeechQuotaRemaining([self speechQuotaUsage]);
|
|
95
133
|
}
|
|
96
|
-
// 回血时间,按本机时区格式化。没有这个槽位的话,带 {resetTime} 的词条会被整条跳过。
|
|
97
134
|
- (NSString *)fiveHourResetTimeText {
|
|
98
|
-
|
|
99
|
-
NSDictionary *fiveHour = [usage[@"fiveHour"] isKindOfClass:NSDictionary.class]
|
|
100
|
-
? usage[@"fiveHour"] : nil;
|
|
101
|
-
id resets = fiveHour[@"resets_at"];
|
|
102
|
-
if (![resets isKindOfClass:NSNumber.class]) return nil;
|
|
103
|
-
NSTimeInterval at = [resets doubleValue];
|
|
104
|
-
if (at <= NSDate.date.timeIntervalSince1970) return nil;
|
|
105
|
-
NSDateFormatter *formatter = [NSDateFormatter new];
|
|
106
|
-
formatter.dateFormat = @"HH:mm";
|
|
107
|
-
formatter.timeZone = NSTimeZone.systemTimeZone;
|
|
108
|
-
return [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:at]];
|
|
135
|
+
return SpeechQuotaResetTime([self speechQuotaUsage]);
|
|
109
136
|
}
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
// 只在向下穿档时说一次:低于 20%% 就一直念叨会变成唠叨,而额度刷新是每分钟级别的,
|
|
113
|
-
// 不设档位的话一小时预算瞬间就被烧光。回血(档位回升)时把标记还回去,
|
|
114
|
-
// 下个周期才能再触发。
|
|
137
|
+
// 每个账号独立记档,首次采样只初始化。冷却期间排队,避免同时跨档时只播报第一个账号。
|
|
115
138
|
- (void)considerQuotaSpeech {
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
139
|
+
if (!self.quotaSpeechStates) self.quotaSpeechStates = [NSMutableDictionary dictionary];
|
|
140
|
+
if (!self.pendingQuotaSpeechProfileIDs) self.pendingQuotaSpeechProfileIDs = [NSMutableOrderedSet orderedSet];
|
|
141
|
+
NSArray<NSDictionary *> *profiles = self.quotaView.profiles;
|
|
142
|
+
NSDictionary *usages = self.quotaView.profileUsages;
|
|
143
|
+
NSMutableSet<NSString *> *liveIDs = [NSMutableSet set];
|
|
144
|
+
for (NSDictionary *profile in profiles) {
|
|
145
|
+
NSString *profileID = profile[@"id"];
|
|
146
|
+
if (profileID.length == 0 || CCPetsProfileShowsAPIUsage(profile)) continue;
|
|
147
|
+
[liveIDs addObject:profileID];
|
|
148
|
+
NSString *home = profile[@"home"] ?: @"";
|
|
149
|
+
NSDictionary *previous = self.quotaSpeechStates[profileID];
|
|
150
|
+
if (previous && ![previous[@"home"] isEqualToString:home]) {
|
|
151
|
+
[self.quotaSpeechStates removeObjectForKey:profileID];
|
|
152
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
153
|
+
previous = nil;
|
|
154
|
+
}
|
|
155
|
+
NSInteger remaining = SpeechQuotaRemaining(usages[profileID]);
|
|
156
|
+
if (remaining < 0) {
|
|
157
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
NSInteger tier = remaining <= 5 ? 0 : remaining <= 10 ? 1 : remaining <= 20 ? 2 : 3;
|
|
161
|
+
self.quotaSpeechStates[profileID] = @{@"home": home, @"tier": @(tier)};
|
|
162
|
+
if (!previous || tier > [previous[@"tier"] integerValue]) {
|
|
163
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
164
|
+
} else if (tier < [previous[@"tier"] integerValue]) {
|
|
165
|
+
[self.pendingQuotaSpeechProfileIDs addObject:profileID];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (NSString *profileID in self.quotaSpeechStates.allKeys) {
|
|
169
|
+
if (![liveIDs containsObject:profileID]) {
|
|
170
|
+
[self.quotaSpeechStates removeObjectForKey:profileID];
|
|
171
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// 用户关闭说话时不积攒提醒;更新气泡、冷却和预算只延后播报。
|
|
175
|
+
if (![self speechEnabled]) {
|
|
176
|
+
[self.pendingQuotaSpeechProfileIDs removeAllObjects];
|
|
130
177
|
return;
|
|
131
178
|
}
|
|
132
|
-
if (
|
|
133
|
-
|
|
179
|
+
if (self.updateBubbleVisible || ![self canSpeakNow]) return;
|
|
180
|
+
for (NSString *profileID in self.pendingQuotaSpeechProfileIDs.array) {
|
|
181
|
+
NSDictionary *profile = nil;
|
|
182
|
+
for (NSDictionary *candidate in profiles) {
|
|
183
|
+
if ([candidate[@"id"] isEqualToString:profileID]) { profile = candidate; break; }
|
|
184
|
+
}
|
|
185
|
+
[self.pendingQuotaSpeechProfileIDs removeObject:profileID];
|
|
186
|
+
if (!profile) continue;
|
|
187
|
+
NSDictionary *slots = [self speechSlotsWithTool:self.lastSpeechTool usage:usages[profileID]];
|
|
188
|
+
NSString *text = PetPhraseForTag(PetPhraseTagQuotaLow, slots);
|
|
189
|
+
if (text.length == 0) continue;
|
|
190
|
+
NSString *provider = [profile[@"provider"] isEqualToString:CCPetsProfileProviderCodex] ? @"Codex" : @"Claude";
|
|
191
|
+
NSString *name = profile[@"displayName"] ?: profile[@"slug"] ?: provider;
|
|
192
|
+
text = [NSString stringWithFormat:@"%@ · %@: %@", provider, name, text];
|
|
193
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
194
|
+
[self.speechTimestamps addObject:@(now)];
|
|
195
|
+
self.speechCooldownUntil = now + [self speechCooldownSeconds];
|
|
196
|
+
[self presentSpeechText:text];
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
134
199
|
}
|
|
135
200
|
- (void)buildSpeechPanelIfNeeded {
|
|
136
201
|
if (self.speechPanel) return;
|
|
@@ -155,14 +220,14 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
155
220
|
initWithFrame:NSMakeRect(6, 6, glassSize.width, glassSize.height)
|
|
156
221
|
material:NSVisualEffectMaterialPopover appearance:NSAppearanceNameAqua
|
|
157
222
|
cornerRadius:glassSize.height / 2.0];
|
|
158
|
-
self.speechGlass.edgeShadeHeight =
|
|
159
|
-
self.speechGlass.edgeShadeAlpha =
|
|
223
|
+
self.speechGlass.edgeShadeHeight = CCPetsSpeechBubbleEdgeShadeHeight;
|
|
224
|
+
self.speechGlass.edgeShadeAlpha = CCPetsSpeechBubbleEdgeShadeAlpha;
|
|
160
225
|
self.speechGlass.usesWidgetGlass = YES;
|
|
161
226
|
|
|
162
227
|
self.speechLabel = [NSTextField labelWithString:@""];
|
|
163
228
|
self.speechLabel.frame = NSMakeRect(14, 10, glassSize.width - 28, 18);
|
|
164
229
|
// 独立气泡里这句话是唯一元素,不与标题争,比并入状态卡时大半档。
|
|
165
|
-
self.speechLabel.font = [NSFont systemFontOfSize:
|
|
230
|
+
self.speechLabel.font = [NSFont systemFontOfSize:CCPetsSpeechBubbleFontSize weight:NSFontWeightMedium];
|
|
166
231
|
self.speechLabel.textColor = [NSColor colorWithWhite:0.10 alpha:0.96];
|
|
167
232
|
self.speechLabel.alignment = NSTextAlignmentCenter;
|
|
168
233
|
self.speechLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
@@ -217,7 +282,7 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
217
282
|
// 话往哪儿显示只在这一处决定:有状态卡就并进它的副行,没有才起独立气泡。
|
|
218
283
|
// 调试触发也必须走这里——否则看到的是现实中不会出现的画面(两个泡叠着)。
|
|
219
284
|
- (void)presentSpeechText:(NSString *)text {
|
|
220
|
-
if (text.length == 0) return;
|
|
285
|
+
if (text.length == 0 || ![self petVisible]) return;
|
|
221
286
|
if (self.statusPanel.isVisible) {
|
|
222
287
|
self.statusDetailLabel.stringValue = text;
|
|
223
288
|
[self resizeStatusCardToFitText];
|
|
@@ -286,7 +351,8 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
286
351
|
// 被更新气泡临时收起的状态卡还回去(会话已结束或用户关了状态卡就不还)。
|
|
287
352
|
if (self.updateBubbleSuppressedStatus) {
|
|
288
353
|
self.updateBubbleSuppressedStatus = NO;
|
|
289
|
-
if (self.hasAgentStatus && self.statusBubbleExpanded &&
|
|
354
|
+
if (self.hasAgentStatus && self.statusBubbleExpanded && [self petVisible] &&
|
|
355
|
+
!self.statusPanel.isVisible) {
|
|
290
356
|
[self positionAgentStatus];
|
|
291
357
|
[self.statusPanel orderFrontRegardless];
|
|
292
358
|
}
|
|
@@ -307,6 +373,8 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
307
373
|
// 挂在已有的客户端存活定时器上,不新起 timer——常驻唤醒一个都不该多。
|
|
308
374
|
- (void)considerIdleSpeech {
|
|
309
375
|
[self consumeSpeechDebugTrigger];
|
|
376
|
+
// 复用存活定时器消费待播报账号,不等待下一次额度刷新,也不额外唤醒。
|
|
377
|
+
if (self.pendingQuotaSpeechProfileIDs.count > 0) [self considerQuotaSpeech];
|
|
310
378
|
if (self.updateBubbleDeferred && ![self agentBusyForSpeech]) [self showUpdateBubble];
|
|
311
379
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
312
380
|
// 真正的判断最多 30 秒做一次,3 秒一跳的定时器上不必每次都算。
|
|
@@ -385,7 +453,7 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
385
453
|
// 独立气泡:左右各 16 内边距,没有图标。
|
|
386
454
|
- (void)resizeSpeechBubbleToFitText {
|
|
387
455
|
if (!self.speechPanel) return;
|
|
388
|
-
const CGFloat padding =
|
|
456
|
+
const CGFloat padding = CCPetsSpeechBubblePadding;
|
|
389
457
|
CGFloat width = padding * 2 + PetMeasuredLabelWidth(self.speechLabel);
|
|
390
458
|
width = fmax(96.0, fmin(width, 300.0));
|
|
391
459
|
NSSize panelSize = NSMakeSize(width + 12, PetSpeechBodyHeight + 12);
|
|
@@ -445,7 +445,9 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
445
445
|
// agent 在忙就先记下来,等它闲下来(considerIdleSpeech 每 3 秒一跳)再冒;
|
|
446
446
|
// 状态卡只是在待命时,临时把它收起让位,气泡消失后再放回来。
|
|
447
447
|
- (void)showUpdateBubble {
|
|
448
|
-
|
|
448
|
+
// 「仅菜单栏」时更新入口是菜单栏菜单里的「更新到 x.y.z…」,不排队等气泡。
|
|
449
|
+
if (self.pendingUpdateVersion.length == 0 || self.updating || self.updateReminderSnoozed ||
|
|
450
|
+
![self petVisible]) {
|
|
449
451
|
self.updateBubbleDeferred = NO;
|
|
450
452
|
return;
|
|
451
453
|
}
|
|
@@ -468,6 +470,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
468
470
|
stringByReplacingOccurrencesOfString:@"{version}" withString:self.pendingUpdateVersion];
|
|
469
471
|
}
|
|
470
472
|
- (void)showUpdateBubbleWithText:(NSString *)text dwell:(NSTimeInterval)dwell {
|
|
473
|
+
if (![self petVisible]) return;
|
|
471
474
|
if (self.statusPanel.isVisible) {
|
|
472
475
|
[self.statusPanel orderOut:nil];
|
|
473
476
|
self.updateBubbleSuppressedStatus = YES;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// 不新增任何采集。
|
|
3
3
|
#import "CCPetsAppDelegate+Private.h"
|
|
4
4
|
#import "CCPetsBridge.h"
|
|
5
|
+
#import "CCPetsBridgeStore.h"
|
|
5
6
|
#import "CCPetsDiagnosticsPage.h"
|
|
6
7
|
#import "CCPetsUsageMode.h"
|
|
7
8
|
|
|
@@ -34,6 +35,7 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
|
|
|
34
35
|
session[@"updatedAt"] = record[@"timestamp"] ?: @0;
|
|
35
36
|
NSDictionary *bridge = [self bridgeSessionEntryForRecord:record];
|
|
36
37
|
if ([bridge[@"name"] isKindOfClass:NSString.class]) session[@"name"] = bridge[@"name"];
|
|
38
|
+
session[@"displayName"] = CCBridgeSessionDisplayName(bridge);
|
|
37
39
|
NSString *bridgeID = [self bridgeSessionIdForRecord:record];
|
|
38
40
|
session[@"pendingMessages"] = bridgeID ? (pending[bridgeID] ?: @0) : @0;
|
|
39
41
|
[sessions addObject:session];
|
|
@@ -54,7 +56,9 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
|
|
|
54
56
|
NSMutableArray<NSDictionary *> *pending = [NSMutableArray array];
|
|
55
57
|
[self.bridgePendingCounts enumerateKeysAndObjectsUsingBlock:^(NSString *session, NSNumber *count, BOOL *stop) {
|
|
56
58
|
NSString *name = self.bridgeSessions[session][@"name"];
|
|
59
|
+
NSString *displayName = CCBridgeSessionDisplayName(self.bridgeSessions[session]);
|
|
57
60
|
[pending addObject:@{@"session": session, @"name": [name isKindOfClass:NSString.class] ? name : session,
|
|
61
|
+
@"displayName": displayName.length > 0 ? displayName : session,
|
|
58
62
|
@"count": count}];
|
|
59
63
|
}];
|
|
60
64
|
[pending sortUsingComparator:^NSComparisonResult(NSDictionary *left, NSDictionary *right) {
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
#import "CCPetsSystemMonitor.h"
|
|
7
7
|
#import "CCPetsGlassView.h"
|
|
8
8
|
|
|
9
|
+
@class CCPetsStatusItemController;
|
|
10
|
+
|
|
9
11
|
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
|
10
12
|
@property NSPanel *panel;
|
|
11
13
|
@property NSPanel *quotaPanel;
|
|
@@ -26,8 +28,8 @@
|
|
|
26
28
|
// 最近一次 agent 事件的工具名,供 {toolName} 槽位使用。
|
|
27
29
|
@property(copy) NSString *lastSpeechTool;
|
|
28
30
|
// 上次播报额度时剩余百分比落在哪一档。只在向下穿档时说,不是"低于阈值就一直说"。
|
|
29
|
-
@property
|
|
30
|
-
@property
|
|
31
|
+
@property NSMutableDictionary<NSString *, NSDictionary *> *quotaSpeechStates;
|
|
32
|
+
@property NSMutableOrderedSet<NSString *> *pendingQuotaSpeechProfileIDs;
|
|
31
33
|
@property NSPanel *statusPanel;
|
|
32
34
|
@property CCPetsGlassView *statusGlass;
|
|
33
35
|
@property CCPetsGlassView *quotaGlass;
|
|
@@ -65,10 +67,14 @@
|
|
|
65
67
|
@property NSInteger liveClientCount;
|
|
66
68
|
@property NSString *lastStatusState;
|
|
67
69
|
@property NSString *lastStatusProvider;
|
|
70
|
+
// 当前卡片所属会话的短标签(目录名.动物)和悬停提示;语言切换、回落待机时重排标题要用。
|
|
71
|
+
@property NSString *lastStatusSessionLabel;
|
|
72
|
+
@property NSString *lastStatusSessionTooltip;
|
|
68
73
|
// lastStatusProvider 是卡片标题(有账号名时显示账号名),不能拿去对 pid 文件里的
|
|
69
74
|
// "Claude"/"Codex";在线判定用原始 provider,判断“是不是同一账号”用 provider|profileId。
|
|
70
75
|
@property NSString *lastStatusAgentProvider;
|
|
71
76
|
@property NSString *lastStatusIdentity;
|
|
77
|
+
@property NSDictionary *lastStatusRecord;
|
|
72
78
|
@property NSDictionary *lastTerminalFocusTarget;
|
|
73
79
|
@property NSTimeInterval lastStatusTimestamp;
|
|
74
80
|
@property NSSet<NSString *> *liveClientProviders;
|
|
@@ -77,6 +83,8 @@
|
|
|
77
83
|
@property NSSet<NSString *> *liveUnscopedClientProviders;
|
|
78
84
|
// 包装脚本仍存活的精确 Agent 会话,键为 provider + TTY。
|
|
79
85
|
@property NSSet<NSString *> *liveAgentSessionKeys;
|
|
86
|
+
// 曾由包装器管理的会话身份(包含 session ID),不把复用同一 tty 的新会话认成旧会话。
|
|
87
|
+
@property NSMutableSet<NSString *> *managedAgentSessionKeys;
|
|
80
88
|
// 每个 provider 最近一次事件的时间。不经包装脚本启动的客户端没有 pid 文件,
|
|
81
89
|
// 只能靠"最近还在发事件"证明自己活着。
|
|
82
90
|
@property NSMutableDictionary<NSString *, NSNumber *> *providerActivityAt;
|
|
@@ -126,4 +134,6 @@
|
|
|
126
134
|
@property NSTimer *quotaClockTimer;
|
|
127
135
|
@property NSTimer *systemMetricsTimer;
|
|
128
136
|
@property CCPetsSystemMonitor *systemMonitor;
|
|
137
|
+
// 菜单栏图标。显示位置为「仅桌宠」时为 nil。
|
|
138
|
+
@property CCPetsStatusItemController *statusItemController;
|
|
129
139
|
@end
|
|
@@ -482,7 +482,8 @@
|
|
|
482
482
|
[self applyPetSizePreference];
|
|
483
483
|
size = self.panel.frame.size;
|
|
484
484
|
[self.panel setFrameOrigin:NSMakePoint(NSMaxX(visible) - size.width - 24, NSMinY(visible) + 18)];
|
|
485
|
-
|
|
485
|
+
// 按显示位置决定桌宠窗口和菜单栏图标谁出现。
|
|
486
|
+
[self applyDisplayMode];
|
|
486
487
|
self.usageMonitor = [CCPetsUsageMonitor new];
|
|
487
488
|
self.systemMonitor = [CCPetsSystemMonitor new];
|
|
488
489
|
self.agentEventPartialLine = [NSMutableData data];
|
|
@@ -549,7 +550,8 @@
|
|
|
549
550
|
[self.petView setAnimationSuspended:YES];
|
|
550
551
|
}
|
|
551
552
|
- (void)screensDidWake:(NSNotification *)notification {
|
|
552
|
-
|
|
553
|
+
// 「仅菜单栏」时宠物藏着,醒来也别恢复逐帧动画。
|
|
554
|
+
if ([self petVisible]) [self.petView setAnimationSuspended:NO];
|
|
553
555
|
}
|
|
554
556
|
- (void)petWindowDidMove:(NSNotification *)notification {
|
|
555
557
|
if (self.quotaPanel.isVisible) [self positionQuotaDashboard];
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
#import "CCPetsCLISupport.h"
|
|
18
18
|
#import "CCPetsTerminalFocus.h"
|
|
19
19
|
#import "CCPetsProfiles.h"
|
|
20
|
+
#import "CCPetsLaunchPreflight.h"
|
|
20
21
|
#import <sys/file.h>
|
|
21
22
|
#import <sys/stat.h>
|
|
22
23
|
#import <fcntl.h>
|
|
@@ -26,6 +27,11 @@ int main(int argc, const char *argv[]) {
|
|
|
26
27
|
@autoreleasepool {
|
|
27
28
|
// 下面这些都是命令行入口,输出语言跟终端走;真正启动桌宠前再切回 App 的语言规则。
|
|
28
29
|
CCPetsUseCommandLineLanguage(YES);
|
|
30
|
+
if (argc > 1 && strcmp(argv[1], "--launch-preflight") == 0) {
|
|
31
|
+
NSMutableArray<NSString *> *arguments = [NSMutableArray array];
|
|
32
|
+
for (int index = 3; index < argc; index++) [arguments addObject:@(argv[index])];
|
|
33
|
+
return CCPetsLaunchPreflight(argc >= 3 ? @(argv[2]) : @"", arguments);
|
|
34
|
+
}
|
|
29
35
|
if (argc > 1 && (strcmp(argv[1], "doctor") == 0 || strcmp(argv[1], "paths") == 0)) {
|
|
30
36
|
NSMutableArray<NSString *> *arguments = [NSMutableArray array];
|
|
31
37
|
for (int index = 1; index < argc; index++) [arguments addObject:@(argv[index])];
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#import "CCPetsBridge.h"
|
|
2
|
+
#import "CCPetsBridgeStore.h"
|
|
2
3
|
#import "CCPetsPaths.h"
|
|
3
|
-
#import <errno.h>
|
|
4
|
-
#import <signal.h>
|
|
5
4
|
#import <unistd.h>
|
|
6
5
|
|
|
7
6
|
NSString *const BridgeBadgeEnabledKey = @"CCPetsBridgeBadgeEnabled";
|
|
8
7
|
NSString *const BridgeNotificationKey = @"CCPetsBridgeNotification";
|
|
9
8
|
|
|
10
|
-
//
|
|
9
|
+
// 一次最多读这么多文件。回执保留 48 小时,正常使用远到不了这个量;
|
|
11
10
|
// 真到了说明有东西在刷消息,宁可少显示几条也不让桌宠主线程卡在读盘上。
|
|
12
11
|
static const NSUInteger BridgeFileScanLimit = 500;
|
|
13
12
|
|
|
@@ -87,6 +86,29 @@ static NSArray<NSString *> *JSONFilesInDirectory(NSString *directory) {
|
|
|
87
86
|
return files;
|
|
88
87
|
}
|
|
89
88
|
|
|
89
|
+
// 回执每次状态变化都是"临时文件 + rename",修改时间就是最后一次更新的时间,比 ID(创建时间)更准:
|
|
90
|
+
// 排了很久的消息也可能刚刚送达。比 since 早的文件里不可能有新送达,不用打开;
|
|
91
|
+
// 其余的按新到旧取,文件数超过上限时丢掉的才是最旧的。
|
|
92
|
+
static NSArray<NSString *> *ReceiptFilesUpdatedSince(NSString *directory, NSTimeInterval since) {
|
|
93
|
+
NSArray<NSURL *> *entries = [NSFileManager.defaultManager contentsOfDirectoryAtURL:[NSURL fileURLWithPath:directory]
|
|
94
|
+
includingPropertiesForKeys:@[NSURLContentModificationDateKey] options:0 error:nil];
|
|
95
|
+
NSMutableArray<NSDictionary *> *candidates = [NSMutableArray array];
|
|
96
|
+
for (NSURL *entry in entries) {
|
|
97
|
+
if (![entry.lastPathComponent hasSuffix:@".json"]) continue;
|
|
98
|
+
NSDate *modified = nil;
|
|
99
|
+
[entry getResourceValue:&modified forKey:NSURLContentModificationDateKey error:nil];
|
|
100
|
+
if (modified.timeIntervalSince1970 < since) continue;
|
|
101
|
+
[candidates addObject:@{@"path": entry.path, @"modified": modified}];
|
|
102
|
+
}
|
|
103
|
+
[candidates sortUsingComparator:^NSComparisonResult(NSDictionary *left, NSDictionary *right) {
|
|
104
|
+
return [right[@"modified"] compare:left[@"modified"]];
|
|
105
|
+
}];
|
|
106
|
+
if (candidates.count > BridgeFileScanLimit) {
|
|
107
|
+
[candidates removeObjectsInRange:NSMakeRange(BridgeFileScanLimit, candidates.count - BridgeFileScanLimit)];
|
|
108
|
+
}
|
|
109
|
+
return [candidates valueForKey:@"path"];
|
|
110
|
+
}
|
|
111
|
+
|
|
90
112
|
static NSDictionary *ReadJSONObject(NSString *path) {
|
|
91
113
|
NSData *data = [NSData dataWithContentsOfFile:path];
|
|
92
114
|
if (data.length == 0) return nil;
|
|
@@ -140,13 +162,6 @@ NSUInteger CCBridgeActiveReservationCount(NSSet<NSString *> *sessionIds) {
|
|
|
140
162
|
return count;
|
|
141
163
|
}
|
|
142
164
|
|
|
143
|
-
static BOOL ProcessAlive(id pidValue) {
|
|
144
|
-
if (![pidValue isKindOfClass:NSNumber.class]) return YES; // 没记 pid 的会话交给 bridge 端判定
|
|
145
|
-
pid_t pid = [pidValue intValue];
|
|
146
|
-
if (pid <= 1) return YES;
|
|
147
|
-
return kill(pid, 0) == 0 || errno == EPERM;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
165
|
NSDictionary<NSString *, NSDictionary *> *CCBridgeSessions(void) {
|
|
151
166
|
NSString *directory = [CCBridgeStateDirectory() stringByAppendingPathComponent:@"sessions"];
|
|
152
167
|
NSMutableDictionary<NSString *, NSDictionary *> *sessions = [NSMutableDictionary dictionary];
|
|
@@ -154,12 +169,19 @@ NSDictionary<NSString *, NSDictionary *> *CCBridgeSessions(void) {
|
|
|
154
169
|
NSDictionary *record = ReadJSONObject(path);
|
|
155
170
|
NSString *session = BridgeSafeString(record[@"session"], 128);
|
|
156
171
|
NSString *name = BridgeSafeString(record[@"name"], 40);
|
|
157
|
-
|
|
172
|
+
// 与 CLI 用同一条规则,否则菜单里的在线会话和 list_agents 对不上。
|
|
173
|
+
if (session.length == 0 || name.length == 0 || !CCBridgeSessionLive(record)) continue;
|
|
158
174
|
NSMutableDictionary *entry = [@{
|
|
159
175
|
@"name": name,
|
|
160
176
|
@"ref": BridgeSafeString(record[@"ref"], 6),
|
|
161
177
|
@"provider": BridgeSafeString(record[@"provider"], 16)
|
|
162
178
|
} mutableCopy];
|
|
179
|
+
NSString *nameSource = [record[@"nameSource"] isKindOfClass:NSString.class] ? record[@"nameSource"] : nil;
|
|
180
|
+
if ([nameSource isEqualToString:@"generated"] || [nameSource isEqualToString:@"custom"]) {
|
|
181
|
+
entry[@"nameSource"] = nameSource;
|
|
182
|
+
}
|
|
183
|
+
NSString *profileID = BridgeSafeString(record[@"profileId"], 128);
|
|
184
|
+
if (profileID.length > 0) entry[@"profileId"] = profileID;
|
|
163
185
|
NSString *tty = BridgeSafeString(record[@"tty"], 32);
|
|
164
186
|
if (tty.length > 0) entry[@"tty"] = tty;
|
|
165
187
|
sessions[session] = entry;
|
|
@@ -170,7 +192,7 @@ NSDictionary<NSString *, NSDictionary *> *CCBridgeSessions(void) {
|
|
|
170
192
|
NSArray<NSDictionary *> *CCBridgeRecentDeliveries(NSTimeInterval since, NSUInteger limit) {
|
|
171
193
|
NSString *directory = [CCBridgeStateDirectory() stringByAppendingPathComponent:@"sent"];
|
|
172
194
|
NSMutableArray<NSDictionary *> *deliveries = [NSMutableArray array];
|
|
173
|
-
for (NSString *path in
|
|
195
|
+
for (NSString *path in ReceiptFilesUpdatedSince(directory, since)) {
|
|
174
196
|
NSDictionary *receipt = ReadJSONObject(path);
|
|
175
197
|
if (![receipt[@"status"] isEqual:@"delivered"]) continue;
|
|
176
198
|
NSDictionary *from = [receipt[@"from"] isKindOfClass:NSDictionary.class] ? receipt[@"from"] : nil;
|
|
@@ -189,7 +211,10 @@ NSArray<NSDictionary *> *CCBridgeRecentDeliveries(NSTimeInterval since, NSUInteg
|
|
|
189
211
|
@"id": BridgeSafeString(receipt[@"id"], 64),
|
|
190
212
|
@"from": fromName,
|
|
191
213
|
@"to": toName,
|
|
214
|
+
@"fromIdentity": @{@"name": fromName, @"nameSource": BridgeSafeString(from[@"nameSource"], 16)},
|
|
215
|
+
@"toIdentity": @{@"name": toName, @"nameSource": BridgeSafeString(to[@"nameSource"], 16)},
|
|
192
216
|
@"toSession": toSession,
|
|
217
|
+
@"fromSession": BridgeSafeString(from[@"session"], 128),
|
|
193
218
|
@"at": @(at)
|
|
194
219
|
}];
|
|
195
220
|
}
|
|
@@ -201,13 +226,15 @@ NSArray<NSDictionary *> *CCBridgeRecentDeliveries(NSTimeInterval since, NSUInteg
|
|
|
201
226
|
}
|
|
202
227
|
|
|
203
228
|
NSDictionary<NSString *, NSNumber *> *CCBridgePendingCounts(void) {
|
|
204
|
-
NSString *inbox = [CCBridgeStateDirectory() stringByAppendingPathComponent:@"inbox"];
|
|
205
229
|
NSMutableDictionary<NSString *, NSNumber *> *counts = [NSMutableDictionary dictionary];
|
|
206
|
-
for (NSString *
|
|
207
|
-
NSString *
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
230
|
+
for (NSString *kind in @[@"inbox", @"claimed"]) {
|
|
231
|
+
NSString *directory = [CCBridgeStateDirectory() stringByAppendingPathComponent:kind];
|
|
232
|
+
for (NSString *name in [NSFileManager.defaultManager contentsOfDirectoryAtPath:directory error:nil]) {
|
|
233
|
+
NSString *session = BridgeSafeString(name, 128);
|
|
234
|
+
if (session.length == 0 || ![session isEqualToString:name]) continue;
|
|
235
|
+
NSUInteger count = JSONFilesInDirectory([directory stringByAppendingPathComponent:name]).count;
|
|
236
|
+
if (count > 0) counts[session] = @([counts[session] unsignedIntegerValue] + count);
|
|
237
|
+
}
|
|
211
238
|
}
|
|
212
239
|
return counts;
|
|
213
240
|
}
|