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,5 +1,6 @@
|
|
|
1
1
|
// Agent 状态卡、会话列表、审批与卡住提醒、终端回跳、系统通知。
|
|
2
2
|
#import "CCPetsAppDelegate+Private.h"
|
|
3
|
+
#import "CCPetsBridgeStore.h"
|
|
3
4
|
|
|
4
5
|
@implementation AppDelegate (AgentStatus)
|
|
5
6
|
- (void)sendNotificationWithTitle:(NSString *)title body:(NSString *)body {
|
|
@@ -171,7 +172,7 @@
|
|
|
171
172
|
if (record.count == 0) return;
|
|
172
173
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
173
174
|
? record[@"terminal"] : nil;
|
|
174
|
-
|
|
175
|
+
self.lastTerminalFocusTarget = terminal.count > 0 ? terminal : nil;
|
|
175
176
|
NSString *identity = [self statusIdentityForRecord:record];
|
|
176
177
|
NSString *tool = [record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @"";
|
|
177
178
|
if ([self.lastStatusState isEqualToString:@"approval"] &&
|
|
@@ -189,7 +190,7 @@
|
|
|
189
190
|
- (void)updateStatusBubbleExpanded:(BOOL)expanded {
|
|
190
191
|
self.statusBubbleExpanded = expanded;
|
|
191
192
|
CCPetsPrefSetBool(StatusBubbleExpandedKey, expanded);
|
|
192
|
-
if (self.statusBubbleExpanded && self.hasAgentStatus) {
|
|
193
|
+
if (self.statusBubbleExpanded && self.hasAgentStatus && [self petVisible]) {
|
|
193
194
|
[self positionAgentStatus];
|
|
194
195
|
[self.statusPanel orderFrontRegardless];
|
|
195
196
|
} else {
|
|
@@ -207,7 +208,7 @@
|
|
|
207
208
|
return [event isEqualToString:@"SubagentStop"] || [event isEqualToString:@"PostToolUse"] ||
|
|
208
209
|
[event isEqualToString:@"TaskCompleted"];
|
|
209
210
|
}
|
|
210
|
-
//
|
|
211
|
+
// 标题优先显示账号名;身份比较使用 profileId 和会话身份,不按显示名合并终端。
|
|
211
212
|
- (NSString *)statusPresentationNameForRecord:(NSDictionary *)record {
|
|
212
213
|
NSString *profileName = SanitizedShortString(record[@"profileName"], 64);
|
|
213
214
|
if (profileName.length > 0) return profileName;
|
|
@@ -216,19 +217,43 @@
|
|
|
216
217
|
}
|
|
217
218
|
- (NSString *)statusIdentityForRecord:(NSDictionary *)record {
|
|
218
219
|
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
219
|
-
NSString *profileID =
|
|
220
|
-
|
|
220
|
+
NSString *profileID = NormalizedAgentProfileID(record[@"profileId"]);
|
|
221
|
+
NSString *session = SanitizedShortString(record[@"session"], 128);
|
|
222
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class] ? record[@"terminal"] : nil;
|
|
223
|
+
NSString *terminalID = SanitizedShortString(terminal[@"ideTerminal"], 64);
|
|
224
|
+
NSString *tty = SanitizedShortString(terminal[@"tty"], 64);
|
|
225
|
+
// 同一个账号的不同会话也必须分开;未配对的新卡片不能借用上一张卡片的终端。
|
|
226
|
+
NSString *identity = session.length ? session : (terminalID.length ? terminalID : tty);
|
|
227
|
+
return [NSString stringWithFormat:@"%@|%@|%@", provider ?: @"", profileID ?: @"", identity ?: @""];
|
|
221
228
|
}
|
|
222
229
|
- (void)noteStatusIdentityForRecord:(NSDictionary *)record {
|
|
230
|
+
self.lastStatusRecord = record;
|
|
223
231
|
self.lastStatusAgentProvider = SanitizedShortString(record[@"provider"], 32);
|
|
224
232
|
self.lastStatusIdentity = [self statusIdentityForRecord:record];
|
|
233
|
+
// Bridge 注册表是定时刷新的:新会话的头一两条事件可能还对不上名字,先显示目录名,
|
|
234
|
+
// 下一条事件自然补成"目录名.动物"。
|
|
235
|
+
NSDictionary *bridge = [self bridgeSessionEntryForRecord:record];
|
|
236
|
+
NSString *cwd = SanitizedWorkingDirectory(record[@"cwd"]);
|
|
237
|
+
if (cwd.length == 0) cwd = SanitizedWorkingDirectory(bridge[@"cwd"]);
|
|
238
|
+
self.lastStatusSessionLabel = StatusSessionLabel(CCBridgeSessionShortName(bridge), cwd);
|
|
239
|
+
NSMutableArray<NSString *> *lines = [NSMutableArray array];
|
|
240
|
+
NSString *name = [bridge[@"name"] isKindOfClass:NSString.class] ? bridge[@"name"] : @"";
|
|
241
|
+
[lines addObject:name.length > 0 ? name : [self statusPresentationNameForRecord:record]];
|
|
242
|
+
if (cwd.length > 0) [lines addObject:cwd.stringByAbbreviatingWithTildeInPath];
|
|
243
|
+
[lines addObject:L(@"Go back to the Agent's terminal")];
|
|
244
|
+
self.lastStatusSessionTooltip = [lines componentsJoinedByString:@"\n"];
|
|
225
245
|
}
|
|
226
246
|
- (void)applyStatusPresentationForState:(NSString *)state provider:(NSString *)provider
|
|
227
247
|
tool:(NSString *)tool {
|
|
228
248
|
self.lastStatusState = state;
|
|
229
249
|
self.lastStatusProvider = provider;
|
|
250
|
+
// 标题优先显示会话标签:多个会话同时在跑时,"Claude"分不出是哪一个,目录名.动物可以。
|
|
251
|
+
// 是哪家 Agent、完整路径放进悬停提示。
|
|
230
252
|
self.statusTitleLabel.stringValue = [NSString stringWithFormat:@"%@ · %@",
|
|
231
|
-
|
|
253
|
+
self.lastStatusSessionLabel.length > 0 ? self.lastStatusSessionLabel : provider,
|
|
254
|
+
[self statusTextForState:state tool:tool]];
|
|
255
|
+
self.statusClickButton.toolTip = self.lastStatusSessionTooltip.length > 0
|
|
256
|
+
? self.lastStatusSessionTooltip : L(@"Go back to the Agent's terminal");
|
|
232
257
|
self.statusDetailLabel.stringValue = [self statusDetailForState:state tool:tool];
|
|
233
258
|
// 上一句碎碎念借走的副行已经被新状态覆盖,取消那次归还,否则它会把旧文案写回来。
|
|
234
259
|
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
@@ -245,7 +270,7 @@
|
|
|
245
270
|
[self layoutApprovalBadge];
|
|
246
271
|
[self positionAgentStatus];
|
|
247
272
|
[self notePetCardChanged];
|
|
248
|
-
if (self.statusBubbleExpanded) {
|
|
273
|
+
if (self.statusBubbleExpanded && [self petVisible]) {
|
|
249
274
|
[self.statusPanel orderFrontRegardless];
|
|
250
275
|
// 卡片一出现就收掉独立气泡:两者都是宠物在说话,同时挂着就是重影。
|
|
251
276
|
// 更新气泡也一样让开:agent 有新动静时状态卡优先,更新入口还有角标和菜单。
|
|
@@ -289,8 +314,8 @@
|
|
|
289
314
|
// Codex 的共享后台偶尔会先送到事件、稍后才完成会话与终端配对。无目标事件不能
|
|
290
315
|
// 把上一条已确认的回跳目标清空,否则卡片仍可见却会突然点不动。
|
|
291
316
|
if (terminal.count > 0) self.lastTerminalFocusTarget = terminal;
|
|
292
|
-
else if (
|
|
293
|
-
//
|
|
317
|
+
else if (![identity isEqualToString:self.lastStatusIdentity]) {
|
|
318
|
+
// 换成另一个会话且仍无法解析终端时,不能误跳到上一张卡片的终端。
|
|
294
319
|
self.lastTerminalFocusTarget = nil;
|
|
295
320
|
}
|
|
296
321
|
|
|
@@ -301,7 +326,7 @@
|
|
|
301
326
|
self.hasAgentStatus = YES;
|
|
302
327
|
[self noteStatusIdentityForRecord:record];
|
|
303
328
|
[self applyStatusPresentationForState:state provider:presentationName tool:tool];
|
|
304
|
-
[self.panel orderFrontRegardless];
|
|
329
|
+
if ([self petVisible]) [self.panel orderFrontRegardless];
|
|
305
330
|
[self performSelector:@selector(hideAgentStatus)
|
|
306
331
|
withObject:nil afterDelay:AgentStatusInactivityInterval];
|
|
307
332
|
if ([state isEqualToString:@"starting"]) {
|
|
@@ -325,7 +350,8 @@
|
|
|
325
350
|
NSTimeInterval cutoff = NSDate.date.timeIntervalSince1970 - PendingApprovalTTL;
|
|
326
351
|
for (NSString *key in self.pendingApprovalRecords.allKeys) {
|
|
327
352
|
NSDictionary *record = self.pendingApprovalRecords[key];
|
|
328
|
-
|
|
353
|
+
BOOL desktop = [record[@"provider"] isEqual:@"Codex"] && IsCodexDesktopFocusTarget(record[@"terminal"]);
|
|
354
|
+
if ([record[@"timestamp"] doubleValue] < cutoff || (desktop && ![self isAgentSessionRecordLive:record])) {
|
|
329
355
|
[self.pendingApprovalRecords removeObjectForKey:key];
|
|
330
356
|
}
|
|
331
357
|
}
|
|
@@ -359,7 +385,7 @@
|
|
|
359
385
|
}
|
|
360
386
|
- (NSString *)agentSessionKeyForRecord:(NSDictionary *)record {
|
|
361
387
|
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
362
|
-
NSString *profileID =
|
|
388
|
+
NSString *profileID = NormalizedAgentProfileID(record[@"profileId"]);
|
|
363
389
|
NSString *identity = profileID.length > 0 ? [NSString stringWithFormat:@"%@|%@", provider, profileID] : provider;
|
|
364
390
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
365
391
|
? record[@"terminal"] : nil;
|
|
@@ -377,21 +403,72 @@
|
|
|
377
403
|
? record[@"terminal"] : nil;
|
|
378
404
|
return OnlineAgentSessionKey(record[@"provider"], record[@"profileId"], terminal[@"tty"]);
|
|
379
405
|
}
|
|
406
|
+
- (NSNumber *)desktopSessionPersistenceForRecord:(NSDictionary *)record {
|
|
407
|
+
if (![record[@"provider"] isEqual:@"Codex"] || !IsCodexDesktopFocusTarget(record[@"terminal"])) return nil;
|
|
408
|
+
if ([record[@"transient"] boolValue]) return @NO;
|
|
409
|
+
// 新会话的路径可能先于索引落盘;明确提供转录路径时不因索引延迟而丢掉首条事件。
|
|
410
|
+
if ([record[@"transcriptPath"] isKindOfClass:NSString.class] && [record[@"transcriptPath"] length] > 0) return @YES;
|
|
411
|
+
NSString *home = [record[@"codexHome"] isKindOfClass:NSString.class] ? record[@"codexHome"] : nil;
|
|
412
|
+
NSString *profile = NormalizedAgentProfileID(record[@"profileId"]);
|
|
413
|
+
if (home.length == 0 && profile.length > 0) home = CCPetsProfileWithID(profile)[@"home"];
|
|
414
|
+
if (home.length == 0 && profile.length == 0) home = DefaultCodexHomeDirectory();
|
|
415
|
+
return CodexPersistentThreadStatus(SanitizedShortString(record[@"session"], 128), home);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
- (void)finishAgentSessionPresentation:(NSDictionary *)record {
|
|
419
|
+
NSString *session = SanitizedShortString(record[@"session"], 128);
|
|
420
|
+
if (!self.hasAgentStatus || session.length == 0 ||
|
|
421
|
+
![self.lastStatusRecord[@"session"] isEqual:session] ||
|
|
422
|
+
![self.lastStatusRecord[@"provider"] isEqual:record[@"provider"]]) return;
|
|
423
|
+
// 内部记录已删除后,屏幕也必须同步切换,不能把已结束会话的“思考”留到超时。
|
|
424
|
+
NSDictionary *replacement = nil;
|
|
425
|
+
for (NSDictionary *candidate in self.agentSessionRecords.allValues) {
|
|
426
|
+
if (![self isAgentSessionRecordLive:candidate]) continue;
|
|
427
|
+
if (!replacement || [candidate[@"timestamp"] doubleValue] > [replacement[@"timestamp"] doubleValue]) {
|
|
428
|
+
replacement = candidate;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideAgentStatus) object:nil];
|
|
432
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(enterIdleStatus) object:nil];
|
|
433
|
+
if (replacement) {
|
|
434
|
+
if ([replacement[@"state"] isEqual:@"idle"]) {
|
|
435
|
+
[self.petView resetAgentToIdle];
|
|
436
|
+
} else {
|
|
437
|
+
[self.petView handleAgentEvent:replacement[@"event"] tool:replacement[@"tool"]
|
|
438
|
+
failed:[replacement[@"failed"] boolValue]];
|
|
439
|
+
}
|
|
440
|
+
[self showAgentStatusForRecord:replacement notify:NO];
|
|
441
|
+
} else {
|
|
442
|
+
[self.petView resetAgentToIdle];
|
|
443
|
+
[self hideAgentStatus];
|
|
444
|
+
self.lastStatusRecord = nil;
|
|
445
|
+
self.lastTerminalFocusTarget = nil;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
380
448
|
// 在线判定优先用包装脚本写出的 pid 文件:它给出精确的退出信号,会话一关列表就更新。
|
|
381
449
|
// 但直接跑 claude / codex(或终端窗口早于 shim 安装就已打开)的会话根本没有 pid 文件,
|
|
382
450
|
// 只按 pid 文件判定会把它们当场判死,列表里永远看不到——哪怕它们的 Hook 正在正常发事件。
|
|
383
|
-
//
|
|
384
|
-
//
|
|
451
|
+
// 桌面会话按应用实例判断;未经过包装器的终端退回活跃度宽限。
|
|
452
|
+
// 只能用精确的账号 + tty 判断某个包装器是否已退出,不能用整个 provider 排除其他会话。
|
|
385
453
|
- (BOOL)isAgentSessionRecordLive:(NSDictionary *)record {
|
|
454
|
+
if ([record[@"event"] isEqual:@"SessionEnd"]) return NO;
|
|
455
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
456
|
+
? record[@"terminal"] : nil;
|
|
457
|
+
if ([record[@"provider"] isEqual:@"Codex"] && IsCodexDesktopFocusTarget(terminal)) {
|
|
458
|
+
if ([record[@"transient"] boolValue]) return NO;
|
|
459
|
+
if (![record[@"desktopPersistent"] boolValue]) {
|
|
460
|
+
// 无法证明是真实聊天的旧事件只给短暂宽限,不能靠宿主进程永久保活。
|
|
461
|
+
return NSDate.date.timeIntervalSince1970 - [record[@"timestamp"] doubleValue]
|
|
462
|
+
< AgentStatusInactivityInterval;
|
|
463
|
+
}
|
|
464
|
+
return CodexDesktopFocusTargetIsLive(terminal, [record[@"timestamp"] doubleValue]);
|
|
465
|
+
}
|
|
386
466
|
NSString *onlineKey = [self onlineAgentSessionKeyForRecord:record];
|
|
387
467
|
if (onlineKey.length > 0 && [self.liveAgentSessionKeys containsObject:onlineKey]) return YES;
|
|
388
468
|
// 老版本包装脚本的 pid 文件不带账号,只能按 provider + tty 认领。
|
|
389
|
-
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
390
|
-
? record[@"terminal"] : nil;
|
|
391
469
|
NSString *unscopedKey = OnlineAgentSessionKey(record[@"provider"], nil, terminal[@"tty"]);
|
|
392
470
|
if (unscopedKey.length > 0 && [self.liveAgentSessionKeys containsObject:unscopedKey]) return YES;
|
|
393
|
-
|
|
394
|
-
if (provider.length > 0 && [self.liveClientProviders containsObject:provider]) return NO;
|
|
471
|
+
if ([self.managedAgentSessionKeys containsObject:[self statusIdentityForRecord:record]]) return NO;
|
|
395
472
|
return NSDate.date.timeIntervalSince1970 - [record[@"timestamp"] doubleValue]
|
|
396
473
|
< AgentStatusInactivityInterval;
|
|
397
474
|
}
|
|
@@ -412,8 +489,32 @@
|
|
|
412
489
|
SanitizedShortString(terminal[@"bundleID"], 128), tty];
|
|
413
490
|
}
|
|
414
491
|
- (void)trackAgentSessionRecord:(NSDictionary *)record {
|
|
492
|
+
if ([record[@"event"] isEqual:@"SessionEnd"]) {
|
|
493
|
+
// 结束事件可能拿不到终端,用稳定的会话身份清理;不能清掉同账号的其他聊天。
|
|
494
|
+
NSString *session = SanitizedShortString(record[@"session"], 128);
|
|
495
|
+
if (session.length == 0) return;
|
|
496
|
+
for (NSString *existingKey in self.agentSessionRecords.allKeys) {
|
|
497
|
+
NSDictionary *existing = self.agentSessionRecords[existingKey];
|
|
498
|
+
if ([existing[@"session"] isEqual:session] && [existing[@"provider"] isEqual:record[@"provider"]]) {
|
|
499
|
+
[self.agentSessionRecords removeObjectForKey:existingKey];
|
|
500
|
+
[self notePetCardChanged];
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
415
505
|
NSString *key = [self agentSessionKeyForRecord:record];
|
|
416
506
|
if (key.length == 0) return;
|
|
507
|
+
NSDictionary *previous = self.agentSessionRecords[key];
|
|
508
|
+
if ([[self statusIdentityForRecord:previous] isEqual:[self statusIdentityForRecord:record]] &&
|
|
509
|
+
[self isTrailingRecord:record afterState:previous[@"state"]]) return;
|
|
510
|
+
NSString *onlineKey = [self onlineAgentSessionKeyForRecord:record];
|
|
511
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class] ? record[@"terminal"] : nil;
|
|
512
|
+
NSString *legacyKey = OnlineAgentSessionKey(record[@"provider"], nil, terminal[@"tty"]);
|
|
513
|
+
if ((onlineKey && [self.liveAgentSessionKeys containsObject:onlineKey]) ||
|
|
514
|
+
(legacyKey && [self.liveAgentSessionKeys containsObject:legacyKey])) {
|
|
515
|
+
if (!self.managedAgentSessionKeys) self.managedAgentSessionKeys = [NSMutableSet set];
|
|
516
|
+
[self.managedAgentSessionKeys addObject:[self statusIdentityForRecord:record]];
|
|
517
|
+
}
|
|
417
518
|
if (!self.agentSessionRecords) self.agentSessionRecords = [NSMutableDictionary dictionary];
|
|
418
519
|
// 一个终端前台同时只跑一个客户端。同一终端里新起的会话(可能换了账号)说明之前那个
|
|
419
520
|
// 已经退出;它退出时不会补发结束事件,不在这里清掉就会在列表里留一行"正在启动"。
|
|
@@ -512,7 +613,7 @@
|
|
|
512
613
|
- (void)presentStalledRecord:(NSDictionary *)record {
|
|
513
614
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
514
615
|
? record[@"terminal"] : nil;
|
|
515
|
-
|
|
616
|
+
self.lastTerminalFocusTarget = terminal.count > 0 ? terminal : nil;
|
|
516
617
|
NSString *state = [record[@"state"] isKindOfClass:NSString.class] ? record[@"state"] : @"";
|
|
517
618
|
self.hasAgentStatus = YES;
|
|
518
619
|
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
@@ -521,7 +622,7 @@
|
|
|
521
622
|
[self applyStatusPresentationForState:state
|
|
522
623
|
provider:[self statusPresentationNameForRecord:record]
|
|
523
624
|
tool:[record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @""];
|
|
524
|
-
[self.panel orderFrontRegardless];
|
|
625
|
+
if ([self petVisible]) [self.panel orderFrontRegardless];
|
|
525
626
|
[self performSelector:@selector(hideAgentStatus) withObject:nil
|
|
526
627
|
afterDelay:AgentStatusInactivityInterval];
|
|
527
628
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// CC Bridge 开关、消息角标与菜单。
|
|
2
2
|
#import "CCPetsAppDelegate+Private.h"
|
|
3
|
+
#import "CCPetsBridgeStore.h"
|
|
3
4
|
|
|
4
5
|
@implementation AppDelegate (Bridge)
|
|
5
6
|
// 菜单开关 → cc-pets bridge enable / disable / configure。逻辑全在 CLI 里,桌宠只负责调用,
|
|
@@ -206,9 +207,9 @@
|
|
|
206
207
|
if (![NSUserDefaults.standardUserDefaults boolForKey:BridgeNotificationKey]) return;
|
|
207
208
|
NSDictionary *latest = fresh.firstObject;
|
|
208
209
|
NSString *body = fresh.count == 1
|
|
209
|
-
? [NSString stringWithFormat:@"%@ → %@", latest[@"
|
|
210
|
-
: [NSString stringWithFormat:L(@"%1$@ → %2$@ and %3$lu more"), latest[@"
|
|
211
|
-
(unsigned long)fresh.count];
|
|
210
|
+
? [NSString stringWithFormat:@"%@ → %@", CCBridgeSessionDisplayName(latest[@"fromIdentity"]), CCBridgeSessionDisplayName(latest[@"toIdentity"])]
|
|
211
|
+
: [NSString stringWithFormat:L(@"%1$@ → %2$@ and %3$lu more"), CCBridgeSessionDisplayName(latest[@"fromIdentity"]), CCBridgeSessionDisplayName(latest[@"toIdentity"]),
|
|
212
|
+
(unsigned long)fresh.count - 1];
|
|
212
213
|
[self sendNotificationWithTitle:L(@"New CC Bridge Message") body:body];
|
|
213
214
|
}
|
|
214
215
|
// 蓝色 = 有新的跨会话消息送达;橙色 = 有消息卡在某个会话的信箱里(那个 Claude 会话长时间空闲、
|
|
@@ -283,7 +284,8 @@
|
|
|
283
284
|
NSMenuItem *heading = [menu addItemWithTitle:L(@"CC Bridge Messages") action:nil keyEquivalent:@""];
|
|
284
285
|
heading.enabled = NO;
|
|
285
286
|
[pending enumerateKeysAndObjectsUsingBlock:^(NSString *session, NSNumber *count, BOOL *stop) {
|
|
286
|
-
NSString *name = self.bridgeSessions[session]
|
|
287
|
+
NSString *name = CCBridgeSessionDisplayName(self.bridgeSessions[session]);
|
|
288
|
+
if (name.length == 0) name = session;
|
|
287
289
|
NSString *title = [NSString stringWithFormat:count.unsignedLongValue != 1
|
|
288
290
|
? L(@"📬 %1$@ has %2$lu undelivered messages (say anything in that terminal to deliver)")
|
|
289
291
|
: L(@"📬 %1$@ has %2$lu undelivered message (say anything in that terminal to deliver)"),
|
|
@@ -300,11 +302,11 @@
|
|
|
300
302
|
dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle];
|
|
301
303
|
BOOL unseen = [delivery[@"at"] doubleValue] > self.bridgeSeenAt;
|
|
302
304
|
NSString *title = [NSString stringWithFormat:@"%@%@ → %@ · %@",
|
|
303
|
-
unseen ? @"✉️ " : @"", delivery[@"
|
|
305
|
+
unseen ? @"✉️ " : @"", CCBridgeSessionDisplayName(delivery[@"fromIdentity"]), CCBridgeSessionDisplayName(delivery[@"toIdentity"]), time];
|
|
304
306
|
NSMenuItem *item = [menu addItemWithTitle:title action:@selector(focusBridgeSession:) keyEquivalent:@""];
|
|
305
307
|
item.target = self;
|
|
306
308
|
item.representedObject = delivery[@"toSession"];
|
|
307
|
-
item.toolTip = [NSString stringWithFormat:L(@"Jump to %@'s terminal"), delivery[@"
|
|
309
|
+
item.toolTip = [NSString stringWithFormat:L(@"Jump to %@'s terminal"), CCBridgeSessionDisplayName(delivery[@"toIdentity"])];
|
|
308
310
|
}
|
|
309
311
|
}
|
|
310
312
|
@end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// 显示位置:仅桌宠 / 桌宠 + 菜单栏 / 仅菜单栏。
|
|
2
|
+
//
|
|
3
|
+
// 「仅菜单栏」只关掉桌面上看得见的东西:桌宠窗口、状态卡、说话气泡、悬停面板和更新气泡。
|
|
4
|
+
// 事件读取、会话记录、额度采集、系统通知照常运行,菜单栏图标和主窗口都靠它们。
|
|
5
|
+
// 浮层各自的显示入口在 petVisible 为 NO 时直接不弹,不在这里逐个追着关。
|
|
6
|
+
#import "CCPetsAppDelegate+Private.h"
|
|
7
|
+
|
|
8
|
+
@implementation AppDelegate (MenuBar)
|
|
9
|
+
|
|
10
|
+
- (BOOL)petVisible {
|
|
11
|
+
return ![CCPetsDisplayMode() isEqualToString:CCPetsDisplayModeMenuBar];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
- (BOOL)menuBarVisible {
|
|
15
|
+
return ![CCPetsDisplayMode() isEqualToString:CCPetsDisplayModePet];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
- (void)updateDisplayMode:(NSString *)mode {
|
|
19
|
+
if (CCPetsPrefSetObject(CCPetsDisplayModeKey, mode)) [self applyDisplayMode];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 菜单栏图标自己监听设置变更,改完数字当场刷新。
|
|
23
|
+
- (void)updateMenuBarShowsPercent:(BOOL)enabled {
|
|
24
|
+
CCPetsPrefSetBool(CCPetsMenuBarShowsPercentKey, enabled);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
- (void)applyDisplayMode {
|
|
28
|
+
if ([self menuBarVisible] && !self.statusItemController) {
|
|
29
|
+
[self installStatusItem];
|
|
30
|
+
} else if (![self menuBarVisible] && self.statusItemController) {
|
|
31
|
+
[self.statusItemController invalidate];
|
|
32
|
+
self.statusItemController = nil;
|
|
33
|
+
}
|
|
34
|
+
if ([self petVisible]) [self showPetWindows];
|
|
35
|
+
else [self hidePetWindows];
|
|
36
|
+
[self.statusItemController refresh];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (void)installStatusItem {
|
|
40
|
+
CCPetsStatusItemController *controller = [[CCPetsStatusItemController alloc] initWithSource:(id)self];
|
|
41
|
+
__weak typeof(self) weakSelf = self;
|
|
42
|
+
controller.petVisibleProvider = ^BOOL { return [weakSelf petVisible]; };
|
|
43
|
+
controller.stateColorProvider = ^NSColor *(NSString *state) { return [weakSelf statusColorForState:state]; };
|
|
44
|
+
// 菜单栏图标只在「桌宠 + 菜单栏」和「仅菜单栏」下存在,勾选项就在这两者之间切换。
|
|
45
|
+
controller.togglePetVisible = ^{
|
|
46
|
+
[weakSelf updateDisplayMode:[weakSelf petVisible] ? CCPetsDisplayModeMenuBar : CCPetsDisplayModeBoth];
|
|
47
|
+
};
|
|
48
|
+
controller.pendingUpdateVersionProvider = ^NSString * {
|
|
49
|
+
return weakSelf.updating ? nil : weakSelf.pendingUpdateVersion;
|
|
50
|
+
};
|
|
51
|
+
controller.showPendingUpdate = ^{ [weakSelf showPendingUpdate:nil]; };
|
|
52
|
+
// 右键和桌宠右键同一份菜单:启用 CC Bridge、免审批这些只在那里,仅菜单栏时不能没有入口。
|
|
53
|
+
controller.contextMenuProvider = ^NSMenu * { return [weakSelf.petView buildContextMenu]; };
|
|
54
|
+
controller.contextMenuFinished = ^{ [weakSelf.petView finishContextMenu]; };
|
|
55
|
+
self.statusItemController = controller;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
- (void)showPetWindows {
|
|
59
|
+
[self.panel orderFrontRegardless];
|
|
60
|
+
[self.petView setAnimationSuspended:NO];
|
|
61
|
+
// 状态卡按原来的偏好还原;没有活跃会话时 updateStatusBubbleExpanded: 自己会保持隐藏。
|
|
62
|
+
[self updateStatusBubbleExpanded:self.statusBubbleExpanded];
|
|
63
|
+
[self refreshUpdateBadge];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
- (void)hidePetWindows {
|
|
67
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
68
|
+
selector:@selector(hideQuotaDashboardIfNeeded) object:nil];
|
|
69
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
70
|
+
selector:@selector(hideSpeechBubble) object:nil];
|
|
71
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
72
|
+
selector:@selector(restoreStatusDetail) object:nil];
|
|
73
|
+
self.pocketHovering = NO;
|
|
74
|
+
self.dashboardHovering = NO;
|
|
75
|
+
self.updateBubbleVisible = NO;
|
|
76
|
+
self.updateBubbleSuppressedStatus = NO;
|
|
77
|
+
[self.quotaPanel orderOut:nil];
|
|
78
|
+
[self.speechPanel orderOut:nil];
|
|
79
|
+
[self.statusPanel orderOut:nil];
|
|
80
|
+
[CCPetsGlassMenu dismiss];
|
|
81
|
+
[self.panel orderOut:nil];
|
|
82
|
+
// 看不见的宠物不必逐帧动画,和屏幕睡眠走同一个开关。
|
|
83
|
+
[self.petView setAnimationSuspended:YES];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@end
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
#import "CCPetsBridge.h"
|
|
21
21
|
#import "CCPetsProfiles.h"
|
|
22
22
|
#import "MenuToggleSwitch.h"
|
|
23
|
+
#import "CCPetsStatusItem.h"
|
|
23
24
|
#import <UserNotifications/UserNotifications.h>
|
|
24
25
|
#import <signal.h>
|
|
25
26
|
#import <sys/stat.h>
|
|
@@ -68,7 +69,7 @@ static const NSTimeInterval PetSpeechDwell = 4.5;
|
|
|
68
69
|
// layer.cornerRadius + kCACornerCurveContinuous 改用位图 maskImage 裁形,
|
|
69
70
|
// squircle 和 GPU 端矢量裁切的质感一起丢了,得不偿失。
|
|
70
71
|
// 结论:保持药丸 + 原生圆角,靠贴近宠物来表达归属。
|
|
71
|
-
static const CGFloat PetSpeechBodyHeight =
|
|
72
|
+
static const CGFloat PetSpeechBodyHeight = CCPetsSpeechBubbleHeight;
|
|
72
73
|
static const CGFloat PetStatusBodyHeight = 58.0;
|
|
73
74
|
// 副行没东西可显示时的高度,只放得下标题一行。
|
|
74
75
|
static const CGFloat PetStatusSingleLineHeight = 40.0;
|
|
@@ -218,6 +219,9 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
|
218
219
|
- (void)displayAgentRecord:(NSDictionary *)record notify:(BOOL)shouldNotify;
|
|
219
220
|
- (NSString *)agentSessionKeyForRecord:(NSDictionary *)record;
|
|
220
221
|
- (NSString *)onlineAgentSessionKeyForRecord:(NSDictionary *)record;
|
|
222
|
+
- (NSString *)statusIdentityForRecord:(NSDictionary *)record;
|
|
223
|
+
- (NSNumber *)desktopSessionPersistenceForRecord:(NSDictionary *)record;
|
|
224
|
+
- (void)finishAgentSessionPresentation:(NSDictionary *)record;
|
|
221
225
|
- (BOOL)isAgentSessionRecordLive:(NSDictionary *)record;
|
|
222
226
|
- (void)pruneOfflineAgentSessionRecords;
|
|
223
227
|
- (void)trackAgentSessionRecord:(NSDictionary *)record;
|
|
@@ -264,6 +268,15 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
|
264
268
|
pending:(NSDictionary<NSString *, NSNumber *> *)pending;
|
|
265
269
|
@end
|
|
266
270
|
|
|
271
|
+
// 显示位置:桌宠窗口与菜单栏图标的显隐。「仅菜单栏」时桌宠和它的浮层(状态卡、气泡、
|
|
272
|
+
// 悬停面板)都不出现,状态机照常运行,供菜单栏和系统通知使用。
|
|
273
|
+
@interface AppDelegate (MenuBar)
|
|
274
|
+
- (BOOL)petVisible;
|
|
275
|
+
- (void)applyDisplayMode;
|
|
276
|
+
- (void)updateDisplayMode:(NSString *)mode;
|
|
277
|
+
- (void)updateMenuBarShowsPercent:(BOOL)enabled;
|
|
278
|
+
@end
|
|
279
|
+
|
|
267
280
|
// 用户显式添加、修复或移除 Claude/Codex Home。
|
|
268
281
|
@interface AppDelegate (Profiles)
|
|
269
282
|
- (void)addClaudeProfile:(id)sender;
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
return NSDate.date.timeIntervalSince1970 - self.lastUsageRefreshAt >= UsageRefreshCoalesceWindow;
|
|
20
20
|
}
|
|
21
21
|
- (void)showQuotaDashboard {
|
|
22
|
+
if (![self petVisible]) return;
|
|
22
23
|
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideQuotaDashboardIfNeeded) object:nil];
|
|
23
24
|
if ([self shouldRefreshUsageForDashboard]) [self refreshUsage:nil];
|
|
24
25
|
[self positionQuotaDashboard];
|
|
@@ -134,6 +135,7 @@
|
|
|
134
135
|
NSMutableSet<NSString *> *unscopedProviders = [self.liveUnscopedClientProviders mutableCopy]
|
|
135
136
|
?: [NSMutableSet set];
|
|
136
137
|
NSMutableSet<NSString *> *approvalProfiles = [NSMutableSet set];
|
|
138
|
+
NSInteger desktopSessions = 0;
|
|
137
139
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
138
140
|
for (NSString *provider in self.providerActivityAt) {
|
|
139
141
|
NSTimeInterval last = [self.providerActivityAt[provider] doubleValue];
|
|
@@ -143,6 +145,9 @@
|
|
|
143
145
|
NSString *profileID = [record[@"profileId"] isKindOfClass:NSString.class]
|
|
144
146
|
? record[@"profileId"] : nil;
|
|
145
147
|
if (![self isAgentSessionRecordLive:record]) continue;
|
|
148
|
+
NSString *provider = [record[@"provider"] isKindOfClass:NSString.class] ? record[@"provider"] : nil;
|
|
149
|
+
if (provider.length > 0) [online addObject:provider];
|
|
150
|
+
if ([provider isEqual:@"Codex"] && IsCodexDesktopFocusTarget(record[@"terminal"])) desktopSessions += 1;
|
|
146
151
|
if (profileID.length > 0) {
|
|
147
152
|
[onlineProfiles addObject:profileID];
|
|
148
153
|
if ([record[@"state"] isEqualToString:@"approval"]) [approvalProfiles addObject:profileID];
|
|
@@ -152,7 +157,7 @@
|
|
|
152
157
|
if (provider.length > 0) [unscopedProviders addObject:provider];
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
|
-
NSInteger count = MAX(self.liveClientCount, (NSInteger)online.count);
|
|
160
|
+
NSInteger count = MAX(self.liveClientCount + desktopSessions, (NSInteger)online.count);
|
|
156
161
|
if (self.quotaView.activeAgentCount == count &&
|
|
157
162
|
[self.quotaView.liveProviders isEqualToSet:online] &&
|
|
158
163
|
[self.quotaView.liveProfileIDs isEqualToSet:onlineProfiles] &&
|
|
@@ -135,10 +135,7 @@
|
|
|
135
135
|
// 状态卡和说话气泡原来是浅色磨砂配深色字;换成原生清透玻璃后背景是任意壁纸加一层
|
|
136
136
|
// 压暗,深色字会看不见,改成白字加贴字形的投影,和额度面板一致。
|
|
137
137
|
- (void)applyBubbleTextStyle {
|
|
138
|
-
NSShadow *shadow =
|
|
139
|
-
shadow.shadowColor = [NSColor colorWithWhite:0 alpha:0.45];
|
|
140
|
-
shadow.shadowBlurRadius = 2;
|
|
141
|
-
shadow.shadowOffset = NSMakeSize(0, -0.5);
|
|
138
|
+
NSShadow *shadow = CCPetsGlassTextShadow();
|
|
142
139
|
BOOL statusLiquid = self.statusGlass.usesLiquidGlass;
|
|
143
140
|
self.statusTitleLabel.textColor = statusLiquid ? [NSColor colorWithWhite:1 alpha:0.78]
|
|
144
141
|
: [NSColor colorWithWhite:0.42 alpha:0.90];
|
|
@@ -156,9 +153,9 @@
|
|
|
156
153
|
[self updateGlassDimLevel:sender.representedObject];
|
|
157
154
|
}
|
|
158
155
|
- (void)updateGlassDimLevel:(NSNumber *)level {
|
|
159
|
-
//
|
|
156
|
+
// 主窗口的滑块是连续值,菜单是四档;两边都传 0–100 的展示强度,取整后换算成实际的 0–45 存下。
|
|
160
157
|
if (![level isKindOfClass:NSNumber.class] || isnan(level.doubleValue)) return;
|
|
161
|
-
|
|
158
|
+
double value = CCPetsGlassDimLevelForPercent(lround(level.doubleValue));
|
|
162
159
|
if ([[NSUserDefaults.standardUserDefaults objectForKey:CCPetsGlassDimKey] isEqual:@(value)]) return;
|
|
163
160
|
CCPetsPrefSetObject(CCPetsGlassDimKey, @(value));
|
|
164
161
|
[self.quotaGlass applyDimLevel];
|