cc-pets 2.0.3 → 2.1.1
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 +239 -0
- package/CC_BRIDGE.zh-CN.md +210 -0
- package/CHANGELOG.md +49 -0
- package/CHANGELOG.zh-CN.md +49 -0
- package/PROVIDER_PROTOCOL.md +6 -0
- package/PROVIDER_PROTOCOL.zh-CN.md +5 -0
- package/README.md +17 -1
- package/README.zh-CN.md +18 -2
- package/Sources/CCPets/CCPetsAppDelegate.h +17 -2
- package/Sources/CCPets/CCPetsAppDelegate.m +478 -56
- package/Sources/CCPets/CCPetsBridge.h +43 -0
- package/Sources/CCPets/CCPetsBridge.m +198 -0
- package/Sources/CCPets/CCPetsCleanup.m +3 -1
- package/Sources/CCPets/CCPetsCodexRateLimits.h +1 -0
- package/Sources/CCPets/CCPetsCodexRateLimits.m +7 -0
- package/Sources/CCPets/CCPetsEvents.m +1 -1
- package/Sources/CCPets/CCPetsGlassMenu.h +10 -0
- package/Sources/CCPets/CCPetsGlassMenu.m +196 -0
- package/Sources/CCPets/CCPetsGlassView.h +31 -0
- package/Sources/CCPets/CCPetsGlassView.m +246 -0
- package/Sources/CCPets/CCPetsPaths.h +7 -0
- package/Sources/CCPets/CCPetsPaths.m +14 -0
- package/Sources/CCPets/CCPetsTerminalFocus.h +15 -0
- package/Sources/CCPets/CCPetsTerminalFocus.m +306 -15
- package/Sources/CCPets/CCPetsUsage.h +2 -0
- package/Sources/CCPets/CCPetsUsage.m +69 -18
- package/Sources/CCPets/CCPetsUsageMonitor.m +43 -8
- package/Sources/CCPets/MenuChoiceRow.h +19 -0
- package/Sources/CCPets/MenuChoiceRow.m +96 -0
- package/Sources/CCPets/MenuHintView.h +15 -0
- package/Sources/CCPets/MenuHintView.m +128 -0
- package/Sources/CCPets/PetView.m +143 -3
- package/Sources/CCPets/QuotaDashboardView.h +3 -4
- package/Sources/CCPets/QuotaDashboardView.m +222 -143
- package/Sources/CCPets/main.m +16 -0
- package/bin/cc-pets +38 -1
- package/bin/codex-with-pet +2 -0
- package/package.json +3 -1
- package/scripts/bridge/cli.mjs +229 -0
- package/scripts/bridge/core.mjs +227 -0
- package/scripts/bridge/hook.mjs +149 -0
- package/scripts/bridge/install.mjs +288 -0
- package/scripts/bridge/mcp-server.mjs +300 -0
- package/scripts/bridge/options.mjs +86 -0
- package/scripts/bridge/process.mjs +129 -0
- package/scripts/bridge/reservations.mjs +247 -0
- package/scripts/bridge/store.mjs +432 -0
- package/scripts/bridge/watch.mjs +69 -0
- package/scripts/install-shell-integration.sh +3 -0
- package/scripts/uninstall-integrations.mjs +10 -0
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
#import "CCPetsPhrasesEditor.h"
|
|
9
9
|
#import "CCPetsUsage.h"
|
|
10
10
|
#import "CCPetsTerminalFocus.h"
|
|
11
|
+
#import "MenuChoiceRow.h"
|
|
12
|
+
#import "CCPetsGlassMenu.h"
|
|
13
|
+
#import "CCPetsBridge.h"
|
|
11
14
|
#import "MenuToggleSwitch.h"
|
|
12
15
|
#import <UserNotifications/UserNotifications.h>
|
|
13
16
|
#import <signal.h>
|
|
@@ -23,6 +26,10 @@ static const NSUInteger PendingApprovalLimit = 100;
|
|
|
23
26
|
static const NSUInteger AgentSessionRecordLimit = 20;
|
|
24
27
|
static const NSUInteger AgentSessionMenuLimit = 8;
|
|
25
28
|
static const CGFloat PetApprovalBadgeSize = 17.0;
|
|
29
|
+
// CC Bridge:轮询间隔、"最近消息"的时间窗、菜单里最多列几条。
|
|
30
|
+
static const NSTimeInterval BridgeRefreshInterval = 3.0;
|
|
31
|
+
static const NSTimeInterval BridgeRecentWindow = 30 * 60;
|
|
32
|
+
static const NSUInteger BridgeMenuDeliveryLimit = 5;
|
|
26
33
|
static const unsigned long long UpdateLogSizeLimit = 1024 * 1024;
|
|
27
34
|
static NSString *const PetInteractionPhrasesV1MigratedKey =
|
|
28
35
|
@"CCPetsInteractionPhrasesV1Migrated";
|
|
@@ -43,6 +50,8 @@ static NSString *const PetInteractionPhrasesV1MigratedKey =
|
|
|
43
50
|
// 不见的地方。角标把这个数字单独拎出来常驻。
|
|
44
51
|
@interface CCPetsApprovalBadgeView : NSView
|
|
45
52
|
@property(nonatomic) NSUInteger count;
|
|
53
|
+
// 默认审批红;CC Bridge 消息角标复用同一个视图,换成蓝色 / 橙色。
|
|
54
|
+
@property(nonatomic) NSColor *fillColor;
|
|
46
55
|
@end
|
|
47
56
|
|
|
48
57
|
@implementation CCPetsApprovalBadgeView
|
|
@@ -52,6 +61,11 @@ static NSString *const PetInteractionPhrasesV1MigratedKey =
|
|
|
52
61
|
self.hidden = count == 0;
|
|
53
62
|
self.needsDisplay = YES;
|
|
54
63
|
}
|
|
64
|
+
- (void)setFillColor:(NSColor *)fillColor {
|
|
65
|
+
if ([_fillColor isEqual:fillColor]) return;
|
|
66
|
+
_fillColor = fillColor;
|
|
67
|
+
self.needsDisplay = YES;
|
|
68
|
+
}
|
|
55
69
|
// 角标压在圆形状态图标的右上角,但不能把那颗按钮的点击吃掉。
|
|
56
70
|
- (NSView *)hitTest:(NSPoint)point { return nil; }
|
|
57
71
|
- (void)drawRect:(NSRect)dirtyRect {
|
|
@@ -59,7 +73,7 @@ static NSString *const PetInteractionPhrasesV1MigratedKey =
|
|
|
59
73
|
// 描边是给玻璃卡片准备的:审批色和卡片背景都偏亮,没有这圈白边角标会糊在一起。
|
|
60
74
|
NSRect circle = NSInsetRect(self.bounds, 1.0, 1.0);
|
|
61
75
|
NSBezierPath *fill = [NSBezierPath bezierPathWithOvalInRect:circle];
|
|
62
|
-
[[NSColor colorWithRed:0.86 green:0.24 blue:0.24 alpha:1] setFill];
|
|
76
|
+
[(self.fillColor ?: [NSColor colorWithRed:0.86 green:0.24 blue:0.24 alpha:1]) setFill];
|
|
63
77
|
[fill fill];
|
|
64
78
|
fill.lineWidth = 1.5;
|
|
65
79
|
[[NSColor colorWithWhite:1 alpha:0.92] setStroke];
|
|
@@ -291,6 +305,30 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
291
305
|
message:[NSString stringWithFormat:@"正在下载并安装 CC Pets %@。完成后桌宠会自动重启。", version]];
|
|
292
306
|
}
|
|
293
307
|
}
|
|
308
|
+
// 系统标准关于面板:图标取自 Info.plist,版本号用构建时注入的 CC_PETS_VERSION(与检查更新
|
|
309
|
+
// 同一口径)。桌宠是 LSUIElement,不先激活的话面板会开在其他 App 后面。
|
|
310
|
+
- (void)showAboutPanel:(id)sender {
|
|
311
|
+
NSMutableAttributedString *credits = [[NSMutableAttributedString alloc]
|
|
312
|
+
initWithString:@"Claude Code / Codex CLI 的多功能桌面宠物。\n\n"
|
|
313
|
+
attributes:@{NSFontAttributeName: [NSFont systemFontOfSize:11],
|
|
314
|
+
NSForegroundColorAttributeName: NSColor.secondaryLabelColor}];
|
|
315
|
+
NSString *homepage = @"https://github.com/Sunnyshinnny776/cc-pets";
|
|
316
|
+
[credits appendAttributedString:[[NSAttributedString alloc] initWithString:homepage
|
|
317
|
+
attributes:@{NSFontAttributeName: [NSFont systemFontOfSize:11],
|
|
318
|
+
NSLinkAttributeName: [NSURL URLWithString:homepage]}]];
|
|
319
|
+
NSMutableParagraphStyle *centered = [NSMutableParagraphStyle new];
|
|
320
|
+
centered.alignment = NSTextAlignmentCenter;
|
|
321
|
+
[credits addAttribute:NSParagraphStyleAttributeName value:centered
|
|
322
|
+
range:NSMakeRange(0, credits.length)];
|
|
323
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
324
|
+
[NSApp orderFrontStandardAboutPanelWithOptions:@{
|
|
325
|
+
NSAboutPanelOptionApplicationName: @"CC Pets",
|
|
326
|
+
NSAboutPanelOptionApplicationVersion: @CC_PETS_VERSION,
|
|
327
|
+
// 空字符串才能去掉版本号后面括号里的 CFBundleVersion(Info.plist 里没有这一项)。
|
|
328
|
+
NSAboutPanelOptionVersion: @"",
|
|
329
|
+
NSAboutPanelOptionCredits: credits
|
|
330
|
+
}];
|
|
331
|
+
}
|
|
294
332
|
- (void)checkForUpdates:(id)sender {
|
|
295
333
|
if (self.checkingForUpdate || self.updating) return;
|
|
296
334
|
self.checkingForUpdate = YES;
|
|
@@ -406,6 +444,52 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
406
444
|
if (tag == 4) return NotificationStallKey;
|
|
407
445
|
return nil;
|
|
408
446
|
}
|
|
447
|
+
// sender 是菜单里的 MenuChoiceRowView,勾选状态由它自己更新。
|
|
448
|
+
- (void)setPanelTheme:(MenuChoiceRowView *)sender {
|
|
449
|
+
NSString *theme = sender.representedObject;
|
|
450
|
+
if (![@[@"classic", @"liquid"] containsObject:theme]) return;
|
|
451
|
+
[NSUserDefaults.standardUserDefaults setObject:theme forKey:CCPetsPanelThemeKey];
|
|
452
|
+
[self.statusGlass applyTheme];
|
|
453
|
+
[self.speechGlass applyTheme];
|
|
454
|
+
[self.quotaGlass applyTheme];
|
|
455
|
+
self.statusShadowView.hidden = self.statusGlass.usesLiquidGlass;
|
|
456
|
+
self.quotaView.usesLiquidGlass = self.quotaGlass.usesLiquidGlass;
|
|
457
|
+
self.quotaView.cardScrimAlpha = CCPetsGlassCardScrimAlpha();
|
|
458
|
+
self.quotaView.needsDisplay = YES;
|
|
459
|
+
[self applyBubbleTextStyle];
|
|
460
|
+
// quotaView 换了父视图,mouseExited 不一定会送达;切主题是在宠物右键菜单里点的,
|
|
461
|
+
// 鼠标此刻不在面板上,直接复位,免得面板一直当作"悬停中"不收起。
|
|
462
|
+
self.dashboardHovering = NO;
|
|
463
|
+
}
|
|
464
|
+
// 状态卡和说话气泡原来是浅色磨砂配深色字;换成原生清透玻璃后背景是任意壁纸加一层
|
|
465
|
+
// 压暗,深色字会看不见,改成白字加贴字形的投影,和额度面板一致。
|
|
466
|
+
- (void)applyBubbleTextStyle {
|
|
467
|
+
NSShadow *shadow = [NSShadow new];
|
|
468
|
+
shadow.shadowColor = [NSColor colorWithWhite:0 alpha:0.45];
|
|
469
|
+
shadow.shadowBlurRadius = 2;
|
|
470
|
+
shadow.shadowOffset = NSMakeSize(0, -0.5);
|
|
471
|
+
BOOL statusLiquid = self.statusGlass.usesLiquidGlass;
|
|
472
|
+
self.statusTitleLabel.textColor = statusLiquid ? [NSColor colorWithWhite:1 alpha:0.78]
|
|
473
|
+
: [NSColor colorWithWhite:0.42 alpha:0.90];
|
|
474
|
+
self.statusDetailLabel.textColor = statusLiquid ? [NSColor colorWithWhite:1 alpha:0.97]
|
|
475
|
+
: [NSColor colorWithWhite:0.12 alpha:0.96];
|
|
476
|
+
self.statusTitleLabel.shadow = statusLiquid ? shadow : nil;
|
|
477
|
+
self.statusDetailLabel.shadow = statusLiquid ? shadow : nil;
|
|
478
|
+
BOOL speechLiquid = self.speechGlass.usesLiquidGlass;
|
|
479
|
+
self.speechLabel.textColor = speechLiquid ? [NSColor colorWithWhite:1 alpha:0.97]
|
|
480
|
+
: [NSColor colorWithWhite:0.10 alpha:0.96];
|
|
481
|
+
self.speechLabel.shadow = speechLiquid ? shadow : nil;
|
|
482
|
+
}
|
|
483
|
+
- (void)setGlassDimLevel:(MenuChoiceRowView *)sender {
|
|
484
|
+
NSNumber *level = sender.representedObject;
|
|
485
|
+
if (![CCPetsGlassDimLevels() containsObject:level]) return;
|
|
486
|
+
[NSUserDefaults.standardUserDefaults setObject:level forKey:CCPetsGlassDimKey];
|
|
487
|
+
[self.quotaGlass applyDimLevel];
|
|
488
|
+
[self.statusGlass applyDimLevel];
|
|
489
|
+
[self.speechGlass applyDimLevel];
|
|
490
|
+
self.quotaView.cardScrimAlpha = CCPetsGlassCardScrimAlpha();
|
|
491
|
+
self.quotaView.needsDisplay = YES;
|
|
492
|
+
}
|
|
409
493
|
- (void)toggleSpeech:(NSButton *)sender {
|
|
410
494
|
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
411
495
|
id current = [defaults objectForKey:@"CCPetsSpeechEnabled"];
|
|
@@ -647,6 +731,7 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
647
731
|
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
648
732
|
selector:@selector(enterIdleStatus) object:nil];
|
|
649
733
|
[self.statusPanel orderOut:nil];
|
|
734
|
+
[CCPetsGlassMenu dismiss];
|
|
650
735
|
self.hasAgentStatus = NO;
|
|
651
736
|
[self refreshApprovalBadge];
|
|
652
737
|
}
|
|
@@ -676,6 +761,7 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
676
761
|
[self.statusPanel orderFrontRegardless];
|
|
677
762
|
} else {
|
|
678
763
|
[self.statusPanel orderOut:nil];
|
|
764
|
+
[CCPetsGlassMenu dismiss];
|
|
679
765
|
}
|
|
680
766
|
}
|
|
681
767
|
// Stop 之后还会飘来 SubagentStop / PostToolUse / TaskCompleted 这类"仍在工作"的尾巴事件
|
|
@@ -715,6 +801,7 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
715
801
|
if (self.speechPanel.isVisible) [self hideSpeechBubble];
|
|
716
802
|
} else {
|
|
717
803
|
[self.statusPanel orderOut:nil];
|
|
804
|
+
[CCPetsGlassMenu dismiss];
|
|
718
805
|
}
|
|
719
806
|
}
|
|
720
807
|
// "正在启动"只在会话拉起的一瞬间成立。之后如果没有任何后续事件,真实情况是会话已就绪、
|
|
@@ -959,6 +1046,10 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
959
1046
|
6 + NSMaxX(icon) - PetApprovalBadgeSize + 4,
|
|
960
1047
|
6 + NSMaxY(icon) - PetApprovalBadgeSize + 4,
|
|
961
1048
|
PetApprovalBadgeSize, PetApprovalBadgeSize);
|
|
1049
|
+
self.bridgeBadgeView.frame = NSMakeRect(
|
|
1050
|
+
6 + NSMaxX(icon) - PetApprovalBadgeSize + 4,
|
|
1051
|
+
6 + NSMinY(icon) - 4,
|
|
1052
|
+
PetApprovalBadgeSize, PetApprovalBadgeSize);
|
|
962
1053
|
}
|
|
963
1054
|
- (void)refreshApprovalBadge {
|
|
964
1055
|
CCPetsApprovalBadgeView *badge = (CCPetsApprovalBadgeView *)self.approvalBadgeView;
|
|
@@ -1003,8 +1094,22 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1003
1094
|
}
|
|
1004
1095
|
- (void)showAgentSessionsMenu:(NSButton *)sender {
|
|
1005
1096
|
NSArray<NSDictionary *> *records = [self recentAgentSessionRecords];
|
|
1006
|
-
|
|
1097
|
+
[self refreshBridgeState:nil];
|
|
1098
|
+
NSArray<NSDictionary *> *deliveries = self.bridgeRecentDeliveries ?: @[];
|
|
1099
|
+
NSDictionary<NSString *, NSNumber *> *pending = self.bridgePendingCounts ?: @{};
|
|
1100
|
+
if (records.count == 0 && deliveries.count == 0 && pending.count == 0) return;
|
|
1007
1101
|
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"最近 Agent 会话"];
|
|
1102
|
+
if (deliveries.count > 0 || pending.count > 0) {
|
|
1103
|
+
[self addBridgeItemsToMenu:menu deliveries:deliveries pending:pending];
|
|
1104
|
+
[menu addItem:NSMenuItem.separatorItem];
|
|
1105
|
+
}
|
|
1106
|
+
// 菜单打开即视为看过:角标清零,下一条新消息再亮。
|
|
1107
|
+
self.bridgeSeenAt = NSDate.date.timeIntervalSince1970;
|
|
1108
|
+
[self refreshBridgeBadge];
|
|
1109
|
+
if (records.count == 0) {
|
|
1110
|
+
[self popUpAgentSessionsMenu:menu from:sender];
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1008
1113
|
NSMenuItem *heading = [menu addItemWithTitle:@"最近 Agent 会话" action:nil keyEquivalent:@""];
|
|
1009
1114
|
heading.enabled = NO;
|
|
1010
1115
|
[menu addItem:NSMenuItem.separatorItem];
|
|
@@ -1023,19 +1128,330 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1023
1128
|
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[record[@"timestamp"] doubleValue]];
|
|
1024
1129
|
NSString *time = [NSDateFormatter localizedStringFromDate:date
|
|
1025
1130
|
dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle];
|
|
1026
|
-
|
|
1131
|
+
// 开启 CC Bridge 时带上会话名:用户和 Agent 之间就是用这个名字互相指代的。
|
|
1132
|
+
NSDictionary *bridge = [self bridgeSessionEntryForRecord:record];
|
|
1133
|
+
NSString *bridgeName = bridge.count > 0
|
|
1134
|
+
? [NSString stringWithFormat:@"(%@)", bridge[@"name"]] : @"";
|
|
1135
|
+
NSUInteger waiting = [pending[[self bridgeSessionIdForRecord:record] ?: @""] unsignedIntegerValue];
|
|
1136
|
+
NSString *title = [NSString stringWithFormat:@"%@%@%@ · %@ · %@ · %@%@",
|
|
1027
1137
|
approval ? @"⚠️ " : @"",
|
|
1028
|
-
provider.length > 0 ? provider : @"Agent",
|
|
1029
|
-
[self statusTextForState:state tool:tool], [self terminalNameForTarget:target], time
|
|
1138
|
+
provider.length > 0 ? provider : @"Agent", bridgeName,
|
|
1139
|
+
[self statusTextForState:state tool:tool], [self terminalNameForTarget:target], time,
|
|
1140
|
+
waiting > 0 ? [NSString stringWithFormat:@" · 📬 %lu", (unsigned long)waiting] : @""];
|
|
1030
1141
|
NSMenuItem *item = [menu addItemWithTitle:title
|
|
1031
1142
|
action:@selector(focusAgentSessionRecord:) keyEquivalent:@""];
|
|
1032
1143
|
item.target = self;
|
|
1033
1144
|
item.representedObject = record;
|
|
1034
1145
|
if ([target isEqual:self.lastTerminalFocusTarget]) item.state = NSControlStateValueOn;
|
|
1035
1146
|
}
|
|
1147
|
+
[self popUpAgentSessionsMenu:menu from:sender];
|
|
1148
|
+
}
|
|
1149
|
+
// Liquid Glass 主题下用玻璃面板展示,和旁边的玻璃状态卡保持一致;经典主题仍是系统菜单。
|
|
1150
|
+
// 玻璃面板不抢焦点,所以不支持方向键选择,Esc 只在本 App 处于前台时有效。
|
|
1151
|
+
- (void)popUpAgentSessionsMenu:(NSMenu *)menu from:(NSButton *)sender {
|
|
1152
|
+
if (self.statusGlass.usesLiquidGlass) {
|
|
1153
|
+
[CCPetsGlassMenu showMenu:menu belowView:self.statusGlass alignRightTo:self.statusGlass];
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1036
1156
|
[menu popUpMenuPositioningItem:nil
|
|
1037
1157
|
atLocation:NSMakePoint(0, NSHeight(sender.bounds) + 4) inView:sender];
|
|
1038
1158
|
}
|
|
1159
|
+
#pragma mark - CC Bridge
|
|
1160
|
+
|
|
1161
|
+
// 菜单开关 → cc-pets bridge enable / disable / configure。逻辑全在 CLI 里,桌宠只负责调用,
|
|
1162
|
+
// 命令行与菜单两条路的行为才一致。enable 要跑 claude / codex mcp add,要几秒,所以异步执行;
|
|
1163
|
+
// 执行期间忽略新的切换,结束后按实际状态刷新(菜单下次打开时现读)。
|
|
1164
|
+
- (void)runBridgeCommand:(NSArray<NSString *> *)arguments sender:(NSButton *)sender
|
|
1165
|
+
successMessage:(NSString *)successMessage {
|
|
1166
|
+
NSDictionary<NSString *, NSString *> *locator = CCBridgeCLILocator();
|
|
1167
|
+
if (!locator) {
|
|
1168
|
+
[self showUpdateAlertWithTitle:@"无法修改 CC Bridge 设置"
|
|
1169
|
+
message:@"没有找到 cc-pets 的命令行程序。请在终端执行一次 cc-pets install 后重试。"];
|
|
1170
|
+
[self syncBridgeSwitch:sender];
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
if (self.bridgeCommandRunning) {
|
|
1174
|
+
[self syncBridgeSwitch:sender];
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
self.bridgeCommandRunning = YES;
|
|
1178
|
+
NSTask *task = [NSTask new];
|
|
1179
|
+
task.executableURL = [NSURL fileURLWithPath:locator[@"node"]];
|
|
1180
|
+
task.arguments = [@[locator[@"cli"]] arrayByAddingObjectsFromArray:arguments];
|
|
1181
|
+
NSMutableDictionary<NSString *, NSString *> *environment =
|
|
1182
|
+
[NSProcessInfo.processInfo.environment mutableCopy];
|
|
1183
|
+
NSString *existingPath = environment[@"PATH"].length > 0 ? environment[@"PATH"] : @"/usr/bin:/bin:/usr/sbin:/sbin";
|
|
1184
|
+
// claude / codex 常装在 node 同目录(nvm),桌宠的 PATH 里未必有。
|
|
1185
|
+
environment[@"PATH"] = [NSString stringWithFormat:@"%@:%@",
|
|
1186
|
+
[locator[@"node"] stringByDeletingLastPathComponent], existingPath];
|
|
1187
|
+
task.environment = environment;
|
|
1188
|
+
NSPipe *output = [NSPipe pipe];
|
|
1189
|
+
task.standardOutput = output;
|
|
1190
|
+
task.standardError = output;
|
|
1191
|
+
__weak typeof(self) weakSelf = self;
|
|
1192
|
+
task.terminationHandler = ^(NSTask *finished) {
|
|
1193
|
+
NSData *data = [output.fileHandleForReading readDataToEndOfFile];
|
|
1194
|
+
NSString *text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ?: @"";
|
|
1195
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1196
|
+
typeof(self) strongSelf = weakSelf;
|
|
1197
|
+
if (!strongSelf) return;
|
|
1198
|
+
strongSelf.bridgeCommandRunning = NO;
|
|
1199
|
+
[strongSelf refreshBridgeState:nil];
|
|
1200
|
+
if (finished.terminationStatus == EXIT_SUCCESS) {
|
|
1201
|
+
if (successMessage.length > 0) {
|
|
1202
|
+
[strongSelf sendNotificationWithTitle:@"CC Bridge" body:successMessage];
|
|
1203
|
+
}
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
[strongSelf syncBridgeSwitch:sender];
|
|
1207
|
+
NSString *detail = [text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
1208
|
+
[strongSelf showUpdateAlertWithTitle:@"CC Bridge 设置失败"
|
|
1209
|
+
message:detail.length > 0 ? detail : @"命令执行失败。"];
|
|
1210
|
+
});
|
|
1211
|
+
};
|
|
1212
|
+
NSError *error = nil;
|
|
1213
|
+
if (![task launchAndReturnError:&error]) {
|
|
1214
|
+
self.bridgeCommandRunning = NO;
|
|
1215
|
+
[self syncBridgeSwitch:sender];
|
|
1216
|
+
[self showUpdateAlertWithTitle:@"CC Bridge 设置失败" message:error.localizedDescription];
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
// 与其他菜单开关一致:目标状态按"实际存储的状态取反"算,不信任开关视图自己翻转后的 state——
|
|
1220
|
+
// 菜单停留期间状态可能已被命令行改过。命令没执行成功时再把开关翻回实际状态。
|
|
1221
|
+
- (BOOL)currentBridgeStateForSwitch:(NSButton *)sender {
|
|
1222
|
+
NSDictionary *options = CCBridgeOptions();
|
|
1223
|
+
if (sender.action == @selector(toggleBridgeEnabled:)) return CCBridgeEnabled();
|
|
1224
|
+
if (sender.action == @selector(toggleBridgeWake:)) return [options[@"wake"] boolValue];
|
|
1225
|
+
if (sender.action == @selector(toggleBridgeEditGuard:)) return [options[@"editGuard"] boolValue];
|
|
1226
|
+
if (sender.action == @selector(toggleBridgeApproval:)) {
|
|
1227
|
+
NSSet *tools = [NSSet setWithArray:CCBridgeToolGroup([self bridgeApprovalGroupForTag:sender.tag])];
|
|
1228
|
+
return tools.count > 0 && [tools isSubsetOfSet:[NSSet setWithArray:options[@"codexApprove"]]] &&
|
|
1229
|
+
[tools isSubsetOfSet:[NSSet setWithArray:options[@"claudeAllow"]]];
|
|
1230
|
+
}
|
|
1231
|
+
return NO;
|
|
1232
|
+
}
|
|
1233
|
+
- (void)syncBridgeSwitch:(NSButton *)sender {
|
|
1234
|
+
if (!sender) return;
|
|
1235
|
+
sender.state = [self currentBridgeStateForSwitch:sender] ? NSControlStateValueOn : NSControlStateValueOff;
|
|
1236
|
+
}
|
|
1237
|
+
// 返回目标状态,并先把开关视图摆到目标状态上(命令失败时 syncBridgeSwitch 再翻回来)。
|
|
1238
|
+
- (BOOL)targetBridgeStateForSwitch:(NSButton *)sender {
|
|
1239
|
+
BOOL target = ![self currentBridgeStateForSwitch:sender];
|
|
1240
|
+
sender.state = target ? NSControlStateValueOn : NSControlStateValueOff;
|
|
1241
|
+
return target;
|
|
1242
|
+
}
|
|
1243
|
+
- (NSString *)bridgeApprovalGroupForTag:(NSInteger)tag {
|
|
1244
|
+
NSArray<NSString *> *groups = CCBridgeToolGroupNames();
|
|
1245
|
+
return tag >= 1 && tag <= (NSInteger)groups.count ? groups[tag - 1] : @"";
|
|
1246
|
+
}
|
|
1247
|
+
- (void)toggleBridgeEnabled:(NSButton *)sender {
|
|
1248
|
+
BOOL enable = [self targetBridgeStateForSwitch:sender];
|
|
1249
|
+
[self runBridgeCommand:@[enable ? @"enable" : @"disable"] sender:sender
|
|
1250
|
+
successMessage:enable
|
|
1251
|
+
? @"已开启。已在运行的 Codex 会话需重启并在 /hooks 中信任;Claude 会话重启后才有 cc-bridge 工具。"
|
|
1252
|
+
: @"已关闭,相关 hooks 与 MCP 注册已移除。"];
|
|
1253
|
+
}
|
|
1254
|
+
// 一个分组同时作用于 Codex 免审批与 Claude 免确认:菜单上只有一组开关,两边保持一致。
|
|
1255
|
+
- (void)toggleBridgeApproval:(NSButton *)sender {
|
|
1256
|
+
NSArray<NSString *> *tools = CCBridgeToolGroup([self bridgeApprovalGroupForTag:sender.tag]);
|
|
1257
|
+
if (tools.count == 0) return;
|
|
1258
|
+
BOOL allow = [self targetBridgeStateForSwitch:sender];
|
|
1259
|
+
NSDictionary *options = CCBridgeOptions();
|
|
1260
|
+
NSString *(^apply)(NSArray<NSString *> *) = ^NSString *(NSArray<NSString *> *current) {
|
|
1261
|
+
NSMutableOrderedSet<NSString *> *next = [NSMutableOrderedSet orderedSetWithArray:current];
|
|
1262
|
+
if (allow) [next addObjectsFromArray:tools]; else [next removeObjectsInArray:tools];
|
|
1263
|
+
return [next.array componentsJoinedByString:@","];
|
|
1264
|
+
};
|
|
1265
|
+
[self runBridgeCommand:@[@"configure",
|
|
1266
|
+
[@"--codex-approve=" stringByAppendingString:apply(options[@"codexApprove"])],
|
|
1267
|
+
[@"--claude-allow=" stringByAppendingString:apply(options[@"claudeAllow"])]]
|
|
1268
|
+
sender:sender successMessage:nil];
|
|
1269
|
+
}
|
|
1270
|
+
- (void)toggleBridgeWake:(NSButton *)sender {
|
|
1271
|
+
[self runBridgeCommand:@[@"configure",
|
|
1272
|
+
[self targetBridgeStateForSwitch:sender] ? @"--wake=on" : @"--wake=off"] sender:sender successMessage:nil];
|
|
1273
|
+
}
|
|
1274
|
+
- (void)toggleBridgeEditGuard:(NSButton *)sender {
|
|
1275
|
+
[self runBridgeCommand:@[@"configure",
|
|
1276
|
+
[self targetBridgeStateForSwitch:sender] ? @"--edit-guard=on" : @"--edit-guard=off"]
|
|
1277
|
+
sender:sender successMessage:nil];
|
|
1278
|
+
}
|
|
1279
|
+
- (void)toggleBridgeBadge:(NSButton *)sender {
|
|
1280
|
+
BOOL enabled = ![NSUserDefaults.standardUserDefaults boolForKey:BridgeBadgeEnabledKey];
|
|
1281
|
+
[NSUserDefaults.standardUserDefaults setBool:enabled forKey:BridgeBadgeEnabledKey];
|
|
1282
|
+
sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
1283
|
+
[self refreshBridgeBadge];
|
|
1284
|
+
}
|
|
1285
|
+
// 与"系统通知"那组开关同一套授权流程:第一次打开时向系统申请通知权限。
|
|
1286
|
+
- (void)toggleBridgeNotification:(NSButton *)sender {
|
|
1287
|
+
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
1288
|
+
if ([defaults boolForKey:BridgeNotificationKey]) {
|
|
1289
|
+
[defaults setBool:NO forKey:BridgeNotificationKey];
|
|
1290
|
+
sender.state = NSControlStateValueOff;
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
[UNUserNotificationCenter.currentNotificationCenter
|
|
1294
|
+
requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionSound
|
|
1295
|
+
completionHandler:^(BOOL granted, NSError *error) {
|
|
1296
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1297
|
+
[defaults setBool:granted forKey:BridgeNotificationKey];
|
|
1298
|
+
sender.state = granted ? NSControlStateValueOn : NSControlStateValueOff;
|
|
1299
|
+
if (!granted) {
|
|
1300
|
+
[self showUpdateAlertWithTitle:@"无法启用系统通知" message:error.localizedDescription ?:
|
|
1301
|
+
@"请在“系统设置 → 通知 → CC Pets”中允许通知后重试。"];
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
}];
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
// 读 bridge 状态(会话名、最近送达、信箱积压),刷新角标。bridge 未开启时清空并隐藏。
|
|
1308
|
+
// 回执目录没变就不重读文件,只按时间窗重新过滤缓存——回执状态一变,写入端的
|
|
1309
|
+
// "临时文件 + rename" 必然改动目录的修改时间。
|
|
1310
|
+
- (void)refreshBridgeState:(NSTimer *)timer {
|
|
1311
|
+
if (!CCBridgeEnabled()) {
|
|
1312
|
+
self.bridgeSessions = nil;
|
|
1313
|
+
self.bridgeRecentDeliveries = nil;
|
|
1314
|
+
self.bridgePendingCounts = nil;
|
|
1315
|
+
self.bridgeSentStamp = nil;
|
|
1316
|
+
[self refreshBridgeBadge];
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
1320
|
+
NSString *directory = CCBridgeStateDirectory();
|
|
1321
|
+
self.bridgeSessions = CCBridgeSessions();
|
|
1322
|
+
NSDate *stamp = [NSFileManager.defaultManager attributesOfItemAtPath:
|
|
1323
|
+
[directory stringByAppendingPathComponent:@"sent"] error:nil].fileModificationDate;
|
|
1324
|
+
if (!stamp || ![stamp isEqualToDate:self.bridgeSentStamp] || !self.bridgeDeliveryCache) {
|
|
1325
|
+
self.bridgeDeliveryCache = CCBridgeRecentDeliveries(now - BridgeRecentWindow, 50);
|
|
1326
|
+
self.bridgeSentStamp = stamp;
|
|
1327
|
+
}
|
|
1328
|
+
NSMutableArray<NSDictionary *> *recent = [NSMutableArray array];
|
|
1329
|
+
for (NSDictionary *delivery in self.bridgeDeliveryCache) {
|
|
1330
|
+
if ([delivery[@"at"] doubleValue] >= now - BridgeRecentWindow) [recent addObject:delivery];
|
|
1331
|
+
}
|
|
1332
|
+
self.bridgeRecentDeliveries = recent;
|
|
1333
|
+
// 只算仍在线的会话:已退出会话的积压已经投不出去,提醒也无从处理。
|
|
1334
|
+
NSMutableDictionary<NSString *, NSNumber *> *pending = [NSMutableDictionary dictionary];
|
|
1335
|
+
[CCBridgePendingCounts() enumerateKeysAndObjectsUsingBlock:^(NSString *session, NSNumber *count, BOOL *stop) {
|
|
1336
|
+
if (self.bridgeSessions[session]) pending[session] = count;
|
|
1337
|
+
}];
|
|
1338
|
+
self.bridgePendingCounts = pending;
|
|
1339
|
+
[self notifyNewBridgeDeliveries];
|
|
1340
|
+
[self refreshBridgeBadge];
|
|
1341
|
+
}
|
|
1342
|
+
// 新送达的跨会话消息发系统通知:只含谁发给谁,不含正文。一次刷新里来了多条时合并成一条。
|
|
1343
|
+
- (void)notifyNewBridgeDeliveries {
|
|
1344
|
+
NSMutableArray<NSDictionary *> *fresh = [NSMutableArray array];
|
|
1345
|
+
for (NSDictionary *delivery in self.bridgeRecentDeliveries) {
|
|
1346
|
+
if ([delivery[@"at"] doubleValue] > self.bridgeNotifiedAt) [fresh addObject:delivery];
|
|
1347
|
+
}
|
|
1348
|
+
if (fresh.count == 0) return;
|
|
1349
|
+
for (NSDictionary *delivery in fresh) {
|
|
1350
|
+
self.bridgeNotifiedAt = MAX(self.bridgeNotifiedAt, [delivery[@"at"] doubleValue]);
|
|
1351
|
+
}
|
|
1352
|
+
if (![NSUserDefaults.standardUserDefaults boolForKey:BridgeNotificationKey]) return;
|
|
1353
|
+
NSDictionary *latest = fresh.firstObject;
|
|
1354
|
+
NSString *body = fresh.count == 1
|
|
1355
|
+
? [NSString stringWithFormat:@"%@ → %@", latest[@"from"], latest[@"to"]]
|
|
1356
|
+
: [NSString stringWithFormat:@"%@ → %@ 等 %lu 条", latest[@"from"], latest[@"to"],
|
|
1357
|
+
(unsigned long)fresh.count];
|
|
1358
|
+
[self sendNotificationWithTitle:@"CC Bridge 新消息" body:body];
|
|
1359
|
+
}
|
|
1360
|
+
// 蓝色 = 有新的跨会话消息送达;橙色 = 有消息卡在某个会话的信箱里(那个 Claude 会话长时间空闲、
|
|
1361
|
+
// 唤醒 watcher 已退出,要等用户在那个终端开口才会送进去),需要用户过去看一眼。
|
|
1362
|
+
- (void)refreshBridgeBadge {
|
|
1363
|
+
CCPetsApprovalBadgeView *badge = (CCPetsApprovalBadgeView *)self.bridgeBadgeView;
|
|
1364
|
+
if (!badge) return;
|
|
1365
|
+
if (![NSUserDefaults.standardUserDefaults boolForKey:BridgeBadgeEnabledKey]) {
|
|
1366
|
+
badge.count = 0;
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
NSUInteger unseen = 0;
|
|
1370
|
+
for (NSDictionary *delivery in self.bridgeRecentDeliveries) {
|
|
1371
|
+
if ([delivery[@"at"] doubleValue] > self.bridgeSeenAt) unseen++;
|
|
1372
|
+
}
|
|
1373
|
+
NSUInteger waiting = 0;
|
|
1374
|
+
for (NSNumber *count in self.bridgePendingCounts.allValues) waiting += count.unsignedIntegerValue;
|
|
1375
|
+
badge.fillColor = waiting > 0
|
|
1376
|
+
? [NSColor colorWithRed:0.92 green:0.58 blue:0.12 alpha:1]
|
|
1377
|
+
: [NSColor colorWithRed:0.20 green:0.47 blue:0.90 alpha:1];
|
|
1378
|
+
badge.count = unseen + waiting;
|
|
1379
|
+
[self layoutApprovalBadge];
|
|
1380
|
+
}
|
|
1381
|
+
- (NSString *)bridgeSessionIdForRecord:(NSDictionary *)record {
|
|
1382
|
+
NSString *session = SanitizedShortString(record[@"session"], 128);
|
|
1383
|
+
if (session.length > 0 && self.bridgeSessions[session]) return session;
|
|
1384
|
+
// 事件里没有 session id 的记录,退回按 provider + tty 对上 bridge 注册表。
|
|
1385
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class] ? record[@"terminal"] : nil;
|
|
1386
|
+
NSString *tty = SanitizedShortString([terminal[@"tty"] lastPathComponent], 64);
|
|
1387
|
+
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
1388
|
+
if (tty.length == 0) return nil;
|
|
1389
|
+
__block NSString *match = nil;
|
|
1390
|
+
[self.bridgeSessions enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *entry, BOOL *stop) {
|
|
1391
|
+
if ([entry[@"tty"] isEqualToString:tty] && [entry[@"provider"] isEqualToString:provider]) {
|
|
1392
|
+
match = key;
|
|
1393
|
+
*stop = YES;
|
|
1394
|
+
}
|
|
1395
|
+
}];
|
|
1396
|
+
return match;
|
|
1397
|
+
}
|
|
1398
|
+
- (NSDictionary *)bridgeSessionEntryForRecord:(NSDictionary *)record {
|
|
1399
|
+
NSString *session = [self bridgeSessionIdForRecord:record];
|
|
1400
|
+
return session ? self.bridgeSessions[session] : nil;
|
|
1401
|
+
}
|
|
1402
|
+
// 收件会话的终端:优先用桌宠自己记录的该会话终端信息(带宿主应用),其次按 tty 对上任一
|
|
1403
|
+
// 已知终端,最后借用最近一次的宿主应用配上 bridge 记录的 tty。
|
|
1404
|
+
- (NSDictionary *)terminalTargetForBridgeSession:(NSString *)sessionId {
|
|
1405
|
+
NSString *tty = self.bridgeSessions[sessionId][@"tty"];
|
|
1406
|
+
NSDictionary *byTty = nil;
|
|
1407
|
+
for (NSDictionary *record in self.agentSessionRecords.allValues) {
|
|
1408
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class] ? record[@"terminal"] : nil;
|
|
1409
|
+
if (terminal.count == 0) continue;
|
|
1410
|
+
if ([SanitizedShortString(record[@"session"], 128) isEqualToString:sessionId]) return terminal;
|
|
1411
|
+
if (tty.length > 0 && [[terminal[@"tty"] lastPathComponent] isEqualToString:tty]) byTty = terminal;
|
|
1412
|
+
}
|
|
1413
|
+
if (byTty) return byTty;
|
|
1414
|
+
if (tty.length > 0 && self.lastTerminalFocusTarget.count > 0) {
|
|
1415
|
+
NSMutableDictionary *target = [self.lastTerminalFocusTarget mutableCopy];
|
|
1416
|
+
target[@"tty"] = tty;
|
|
1417
|
+
[target removeObjectForKey:@"session"];
|
|
1418
|
+
return target;
|
|
1419
|
+
}
|
|
1420
|
+
return nil;
|
|
1421
|
+
}
|
|
1422
|
+
- (void)focusBridgeSession:(NSMenuItem *)sender {
|
|
1423
|
+
NSString *sessionId = [sender.representedObject isKindOfClass:NSString.class] ? sender.representedObject : nil;
|
|
1424
|
+
NSDictionary *target = sessionId ? [self terminalTargetForBridgeSession:sessionId] : nil;
|
|
1425
|
+
if (target.count > 0) ActivateTerminalFocusTarget(target);
|
|
1426
|
+
}
|
|
1427
|
+
- (void)addBridgeItemsToMenu:(NSMenu *)menu deliveries:(NSArray<NSDictionary *> *)deliveries
|
|
1428
|
+
pending:(NSDictionary<NSString *, NSNumber *> *)pending {
|
|
1429
|
+
NSMenuItem *heading = [menu addItemWithTitle:@"CC Bridge 消息" action:nil keyEquivalent:@""];
|
|
1430
|
+
heading.enabled = NO;
|
|
1431
|
+
[pending enumerateKeysAndObjectsUsingBlock:^(NSString *session, NSNumber *count, BOOL *stop) {
|
|
1432
|
+
NSString *name = self.bridgeSessions[session][@"name"] ?: session;
|
|
1433
|
+
NSString *title = [NSString stringWithFormat:@"📬 %@ 有 %lu 条消息待投递(去那个终端说句话即可送达)",
|
|
1434
|
+
name, count.unsignedLongValue];
|
|
1435
|
+
NSMenuItem *item = [menu addItemWithTitle:title action:@selector(focusBridgeSession:) keyEquivalent:@""];
|
|
1436
|
+
item.target = self;
|
|
1437
|
+
item.representedObject = session;
|
|
1438
|
+
}];
|
|
1439
|
+
NSUInteger shown = 0;
|
|
1440
|
+
for (NSDictionary *delivery in deliveries) {
|
|
1441
|
+
if (shown++ >= BridgeMenuDeliveryLimit) break;
|
|
1442
|
+
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[delivery[@"at"] doubleValue]];
|
|
1443
|
+
NSString *time = [NSDateFormatter localizedStringFromDate:date
|
|
1444
|
+
dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle];
|
|
1445
|
+
BOOL unseen = [delivery[@"at"] doubleValue] > self.bridgeSeenAt;
|
|
1446
|
+
NSString *title = [NSString stringWithFormat:@"%@%@ → %@ · %@",
|
|
1447
|
+
unseen ? @"✉️ " : @"", delivery[@"from"], delivery[@"to"], time];
|
|
1448
|
+
NSMenuItem *item = [menu addItemWithTitle:title action:@selector(focusBridgeSession:) keyEquivalent:@""];
|
|
1449
|
+
item.target = self;
|
|
1450
|
+
item.representedObject = delivery[@"toSession"];
|
|
1451
|
+
item.toolTip = [NSString stringWithFormat:@"跳到 %@ 所在的终端", delivery[@"to"]];
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1039
1455
|
- (BOOL)focusLatestAgentTerminal {
|
|
1040
1456
|
// 只有 Hook 状态气泡上的透明按钮会调用这里;桌宠本体继续负责原有互动。
|
|
1041
1457
|
if (!self.hasAgentStatus || self.lastTerminalFocusTarget.count == 0) return NO;
|
|
@@ -1261,7 +1677,9 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1261
1677
|
PetInteractionEnabledKey: @YES,
|
|
1262
1678
|
PetInteractionHeartThresholdKey: @3,
|
|
1263
1679
|
PetInteractionAnnoyedThresholdKey: @10,
|
|
1264
|
-
PetInteractionIntervalKey: @1.2
|
|
1680
|
+
PetInteractionIntervalKey: @1.2,
|
|
1681
|
+
BridgeBadgeEnabledKey: @YES,
|
|
1682
|
+
BridgeNotificationKey: @NO
|
|
1265
1683
|
}];
|
|
1266
1684
|
if (![defaults boolForKey:StatusBubblePreferenceV2Key]) {
|
|
1267
1685
|
[defaults setBool:YES forKey:StatusBubbleExpandedKey];
|
|
@@ -1354,8 +1772,8 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1354
1772
|
NSView *statusShadow = [[NSView alloc] initWithFrame:NSMakeRect(
|
|
1355
1773
|
6, 6, statusGlassSize.width, statusGlassSize.height)];
|
|
1356
1774
|
self.statusShadowView = statusShadow;
|
|
1357
|
-
statusShadow.layer.cornerRadius = statusGlassSize.height / 2.0;
|
|
1358
1775
|
statusShadow.wantsLayer = YES;
|
|
1776
|
+
statusShadow.layer.cornerRadius = statusGlassSize.height / 2.0;
|
|
1359
1777
|
statusShadow.layer.backgroundColor = [NSColor colorWithWhite:0 alpha:0.01].CGColor;
|
|
1360
1778
|
statusShadow.layer.cornerCurve = kCACornerCurveContinuous;
|
|
1361
1779
|
statusShadow.layer.shadowColor = NSColor.blackColor.CGColor;
|
|
@@ -1369,18 +1787,14 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1369
1787
|
CGPathRelease(statusShadowPath);
|
|
1370
1788
|
[statusRoot addSubview:statusShadow];
|
|
1371
1789
|
|
|
1372
|
-
self.statusGlass = [[
|
|
1373
|
-
initWithFrame:NSMakeRect(6, 6, statusGlassSize.width, statusGlassSize.height)
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
self.statusGlass.
|
|
1378
|
-
self.statusGlass.
|
|
1379
|
-
self.statusGlass.
|
|
1380
|
-
self.statusGlass.layer.cornerCurve = kCACornerCurveContinuous;
|
|
1381
|
-
self.statusGlass.layer.masksToBounds = YES;
|
|
1382
|
-
self.statusGlass.layer.borderWidth = 1;
|
|
1383
|
-
self.statusGlass.layer.borderColor = [NSColor colorWithWhite:1 alpha:0.48].CGColor;
|
|
1790
|
+
self.statusGlass = [[CCPetsGlassView alloc]
|
|
1791
|
+
initWithFrame:NSMakeRect(6, 6, statusGlassSize.width, statusGlassSize.height)
|
|
1792
|
+
material:NSVisualEffectMaterialPopover appearance:NSAppearanceNameAqua
|
|
1793
|
+
cornerRadius:statusGlassSize.height / 2.0];
|
|
1794
|
+
// 胶囊比面板矮,边缘高光占比更大;10pt / 0.6 是对照截图里深色背景下刚好压住的值。
|
|
1795
|
+
self.statusGlass.edgeShadeHeight = 10;
|
|
1796
|
+
self.statusGlass.edgeShadeAlpha = 0.6;
|
|
1797
|
+
self.statusGlass.usesWidgetGlass = YES;
|
|
1384
1798
|
|
|
1385
1799
|
self.statusTitleLabel = [NSTextField labelWithString:@""];
|
|
1386
1800
|
// 层级是反的:宠物是主角,事实退成眉标。
|
|
@@ -1389,14 +1803,14 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1389
1803
|
self.statusTitleLabel.font = [NSFont systemFontOfSize:11 weight:NSFontWeightMedium];
|
|
1390
1804
|
self.statusTitleLabel.textColor = [NSColor colorWithWhite:0.42 alpha:0.90];
|
|
1391
1805
|
self.statusTitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
1392
|
-
[self.statusGlass addSubview:self.statusTitleLabel];
|
|
1806
|
+
[self.statusGlass.contentView addSubview:self.statusTitleLabel];
|
|
1393
1807
|
|
|
1394
1808
|
self.statusDetailLabel = [NSTextField labelWithString:@""];
|
|
1395
1809
|
self.statusDetailLabel.frame = NSMakeRect(20, 10, statusGlassSize.width - 80, 22);
|
|
1396
1810
|
self.statusDetailLabel.font = [NSFont systemFontOfSize:14 weight:NSFontWeightMedium];
|
|
1397
1811
|
self.statusDetailLabel.textColor = [NSColor colorWithWhite:0.12 alpha:0.96];
|
|
1398
1812
|
self.statusDetailLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
1399
|
-
[self.statusGlass addSubview:self.statusDetailLabel];
|
|
1813
|
+
[self.statusGlass.contentView addSubview:self.statusDetailLabel];
|
|
1400
1814
|
|
|
1401
1815
|
self.statusIconButton = [[CCPetsStatusClickButton alloc] initWithFrame:NSMakeRect(
|
|
1402
1816
|
statusGlassSize.width - 48, 12, 34, 34)];
|
|
@@ -1405,11 +1819,14 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1405
1819
|
self.statusIconButton.wantsLayer = YES;
|
|
1406
1820
|
self.statusIconButton.layer.cornerRadius = 17;
|
|
1407
1821
|
self.statusIconButton.layer.masksToBounds = YES;
|
|
1408
|
-
self.statusIconButton.toolTip = @"查看最近 Agent
|
|
1822
|
+
self.statusIconButton.toolTip = @"查看最近 Agent 会话与 CC Bridge 消息";
|
|
1409
1823
|
self.statusIconButton.target = self;
|
|
1410
1824
|
self.statusIconButton.action = @selector(showAgentSessionsMenu:);
|
|
1411
|
-
[self.statusGlass addSubview:self.statusIconButton];
|
|
1825
|
+
[self.statusGlass.contentView addSubview:self.statusIconButton];
|
|
1826
|
+
// 原生玻璃自带阴影,再叠手工阴影会糊成两层。
|
|
1827
|
+
self.statusShadowView.hidden = self.statusGlass.usesLiquidGlass;
|
|
1412
1828
|
[statusRoot addSubview:self.statusGlass];
|
|
1829
|
+
[self applyBubbleTextStyle];
|
|
1413
1830
|
CCPetsStatusClickButton *statusClick = [[CCPetsStatusClickButton alloc]
|
|
1414
1831
|
initWithFrame:NSMakeRect(6, 6, statusGlassSize.width - 56, statusGlassSize.height)];
|
|
1415
1832
|
statusClick.bordered = NO;
|
|
@@ -1421,13 +1838,21 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1421
1838
|
statusClick.action = @selector(focusLatestAgentTerminal:);
|
|
1422
1839
|
self.statusClickButton = statusClick;
|
|
1423
1840
|
[statusRoot addSubview:statusClick];
|
|
1424
|
-
// 角标挂在 statusRoot
|
|
1841
|
+
// 角标挂在 statusRoot 而不是玻璃内容里:玻璃卡片会按胶囊形状裁切,
|
|
1425
1842
|
// 右上角正好落在圆角外面,放进去会被裁掉一半。
|
|
1426
1843
|
CCPetsApprovalBadgeView *badge = [[CCPetsApprovalBadgeView alloc]
|
|
1427
1844
|
initWithFrame:NSMakeRect(0, 0, PetApprovalBadgeSize, PetApprovalBadgeSize)];
|
|
1428
1845
|
badge.hidden = YES;
|
|
1429
1846
|
self.approvalBadgeView = badge;
|
|
1430
1847
|
[statusRoot addSubview:badge];
|
|
1848
|
+
// CC Bridge 消息角标压在图标右下角,与右上角的审批角标错开。点击同样穿透到图标,
|
|
1849
|
+
// 打开的会话菜单里列出最近的跨会话消息。
|
|
1850
|
+
CCPetsApprovalBadgeView *bridgeBadge = [[CCPetsApprovalBadgeView alloc]
|
|
1851
|
+
initWithFrame:NSMakeRect(0, 0, PetApprovalBadgeSize, PetApprovalBadgeSize)];
|
|
1852
|
+
bridgeBadge.hidden = YES;
|
|
1853
|
+
bridgeBadge.fillColor = [NSColor colorWithRed:0.20 green:0.47 blue:0.90 alpha:1];
|
|
1854
|
+
self.bridgeBadgeView = bridgeBadge;
|
|
1855
|
+
[statusRoot addSubview:bridgeBadge];
|
|
1431
1856
|
[self layoutApprovalBadge];
|
|
1432
1857
|
self.statusPanel.contentView = statusRoot;
|
|
1433
1858
|
|
|
@@ -1444,17 +1869,15 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1444
1869
|
self.quotaPanel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorFullScreenAuxiliary;
|
|
1445
1870
|
self.quotaPanel.hidesOnDeactivate = NO;
|
|
1446
1871
|
NSView *quotaRoot = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, quotaSize.width, quotaSize.height)];
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
glass.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
|
|
1453
|
-
glass.wantsLayer = YES;
|
|
1454
|
-
glass.layer.cornerRadius = 13;
|
|
1455
|
-
glass.layer.masksToBounds = YES;
|
|
1456
|
-
[quotaRoot addSubview:glass];
|
|
1872
|
+
self.quotaGlass = [[CCPetsGlassView alloc] initWithFrame:quotaRoot.bounds
|
|
1873
|
+
material:NSVisualEffectMaterialUnderWindowBackground
|
|
1874
|
+
appearance:NSAppearanceNameDarkAqua cornerRadius:13];
|
|
1875
|
+
self.quotaGlass.usesWidgetGlass = YES;
|
|
1876
|
+
[quotaRoot addSubview:self.quotaGlass];
|
|
1457
1877
|
self.quotaView = [[QuotaDashboardView alloc] initWithFrame:NSMakeRect(0, 0, quotaSize.width, quotaSize.height)];
|
|
1878
|
+
self.quotaView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
1879
|
+
self.quotaView.usesLiquidGlass = self.quotaGlass.usesLiquidGlass;
|
|
1880
|
+
self.quotaView.cardScrimAlpha = CCPetsGlassCardScrimAlpha();
|
|
1458
1881
|
[self applySystemMetricPreferences];
|
|
1459
1882
|
[self applyUsageDisplayModePreferences];
|
|
1460
1883
|
self.quotaView.codexLogo = OfficialAppIcon(@"com.openai.codex", @"icon-chatgpt.icns");
|
|
@@ -1463,10 +1886,7 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1463
1886
|
weakSelf.dashboardHovering = hovering;
|
|
1464
1887
|
if (!hovering) [weakSelf scheduleQuotaDashboardHide];
|
|
1465
1888
|
};
|
|
1466
|
-
self.
|
|
1467
|
-
[weakSelf refreshUsage:nil];
|
|
1468
|
-
};
|
|
1469
|
-
[quotaRoot addSubview:self.quotaView];
|
|
1889
|
+
[self.quotaGlass.contentView addSubview:self.quotaView];
|
|
1470
1890
|
self.quotaPanel.contentView = quotaRoot;
|
|
1471
1891
|
// 先探测再第一次显示:否则面板会先按两张卡的高度弹出来再收缩一下。
|
|
1472
1892
|
[self refreshDetectedProviders];
|
|
@@ -1498,6 +1918,13 @@ static NSString *const PetSpeechFrequencyChatty = @"chatty";
|
|
|
1498
1918
|
NSTimer *readerTimer = [NSTimer scheduledTimerWithTimeInterval:AgentEventReaderCheckInterval
|
|
1499
1919
|
target:self selector:@selector(ensureAgentEventReader:) userInfo:nil repeats:YES];
|
|
1500
1920
|
readerTimer.tolerance = AgentEventReaderCheckInterval * 0.3;
|
|
1921
|
+
// 启动前的消息不算"未读":角标只提示桌宠运行期间新发生的跨会话往来。通知同理。
|
|
1922
|
+
self.bridgeSeenAt = NSDate.date.timeIntervalSince1970;
|
|
1923
|
+
self.bridgeNotifiedAt = self.bridgeSeenAt;
|
|
1924
|
+
[self refreshBridgeState:nil];
|
|
1925
|
+
NSTimer *bridgeTimer = [NSTimer scheduledTimerWithTimeInterval:BridgeRefreshInterval
|
|
1926
|
+
target:self selector:@selector(refreshBridgeState:) userInfo:nil repeats:YES];
|
|
1927
|
+
bridgeTimer.tolerance = BridgeRefreshInterval * 0.3;
|
|
1501
1928
|
// 这里刻意不使用 occlusionState / NSWindowDidChangeOcclusionStateNotification:
|
|
1502
1929
|
// 桌宠是置顶的(NSFloatingWindowLevel + FullScreenAuxiliary),全屏应用也压不住它,
|
|
1503
1930
|
// 所以“被遮挡”几乎不会真实发生,收益接近零;而实测中 occlusionState 会在
|
|
@@ -1797,20 +2224,13 @@ static const CGFloat PetStatusSingleLineHeight = 40.0;
|
|
|
1797
2224
|
self.speechPanel.ignoresMouseEvents = YES;
|
|
1798
2225
|
|
|
1799
2226
|
NSView *root = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, size.width, size.height)];
|
|
1800
|
-
self.speechGlass = [[
|
|
1801
|
-
initWithFrame:NSMakeRect(6, 6, glassSize.width, glassSize.height)
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
self.speechGlass.
|
|
1805
|
-
self.speechGlass.
|
|
1806
|
-
self.speechGlass.
|
|
1807
|
-
// 圆角交给 layer 自己:cornerRadius 是 GPU 端矢量裁切,配 continuous 曲率就是
|
|
1808
|
-
// macOS 那个 squircle。位图 maskImage 换不来这个质感。
|
|
1809
|
-
self.speechGlass.layer.cornerRadius = glassSize.height / 2.0;
|
|
1810
|
-
self.speechGlass.layer.cornerCurve = kCACornerCurveContinuous;
|
|
1811
|
-
self.speechGlass.layer.masksToBounds = YES;
|
|
1812
|
-
self.speechGlass.layer.borderWidth = 1;
|
|
1813
|
-
self.speechGlass.layer.borderColor = [NSColor colorWithWhite:1 alpha:0.48].CGColor;
|
|
2227
|
+
self.speechGlass = [[CCPetsGlassView alloc]
|
|
2228
|
+
initWithFrame:NSMakeRect(6, 6, glassSize.width, glassSize.height)
|
|
2229
|
+
material:NSVisualEffectMaterialPopover appearance:NSAppearanceNameAqua
|
|
2230
|
+
cornerRadius:glassSize.height / 2.0];
|
|
2231
|
+
self.speechGlass.edgeShadeHeight = 9;
|
|
2232
|
+
self.speechGlass.edgeShadeAlpha = 0.6;
|
|
2233
|
+
self.speechGlass.usesWidgetGlass = YES;
|
|
1814
2234
|
|
|
1815
2235
|
self.speechLabel = [NSTextField labelWithString:@""];
|
|
1816
2236
|
self.speechLabel.frame = NSMakeRect(14, 10, glassSize.width - 28, 18);
|
|
@@ -1819,8 +2239,9 @@ static const CGFloat PetStatusSingleLineHeight = 40.0;
|
|
|
1819
2239
|
self.speechLabel.textColor = [NSColor colorWithWhite:0.10 alpha:0.96];
|
|
1820
2240
|
self.speechLabel.alignment = NSTextAlignmentCenter;
|
|
1821
2241
|
self.speechLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
1822
|
-
[self.speechGlass addSubview:self.speechLabel];
|
|
2242
|
+
[self.speechGlass.contentView addSubview:self.speechLabel];
|
|
1823
2243
|
[root addSubview:self.speechGlass];
|
|
2244
|
+
[self applyBubbleTextStyle];
|
|
1824
2245
|
self.speechPanel.contentView = root;
|
|
1825
2246
|
}
|
|
1826
2247
|
// 独立气泡只在没有状态卡时出现(有状态卡时话并进它的副行),所以固定放宠物头顶即可,
|
|
@@ -2027,7 +2448,9 @@ static CGFloat PetMeasuredLabelWidth(NSTextField *label) {
|
|
|
2027
2448
|
[self.statusPanel setContentSize:panelSize];
|
|
2028
2449
|
self.statusPanel.contentView.frame = NSMakeRect(0, 0, panelSize.width, panelSize.height);
|
|
2029
2450
|
self.statusGlass.frame = NSMakeRect(6, 6, glassWidth, height);
|
|
2451
|
+
self.statusGlass.cornerRadius = height / 2.0;
|
|
2030
2452
|
self.statusShadowView.frame = NSMakeRect(6, 6, glassWidth, height);
|
|
2453
|
+
self.statusShadowView.layer.cornerRadius = height / 2.0;
|
|
2031
2454
|
// shadowPath 是按旧尺寸算死的,卡片变宽后不重算,阴影会留在原来的形状上。
|
|
2032
2455
|
CGPathRef path = CGPathCreateWithRoundedRect(self.statusShadowView.bounds,
|
|
2033
2456
|
height / 2.0, height / 2.0, NULL);
|
|
@@ -2056,7 +2479,7 @@ static CGFloat PetMeasuredLabelWidth(NSTextField *label) {
|
|
|
2056
2479
|
[self.speechPanel setContentSize:panelSize];
|
|
2057
2480
|
self.speechPanel.contentView.frame = NSMakeRect(0, 0, panelSize.width, panelSize.height);
|
|
2058
2481
|
self.speechGlass.frame = NSMakeRect(6, 6, width, PetSpeechBodyHeight);
|
|
2059
|
-
self.speechGlass.
|
|
2482
|
+
self.speechGlass.cornerRadius = PetSpeechBodyHeight / 2.0;
|
|
2060
2483
|
self.speechLabel.frame = NSMakeRect(padding, 10, width - padding * 2, 18);
|
|
2061
2484
|
}
|
|
2062
2485
|
|
|
@@ -2363,8 +2786,7 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
|
|
|
2363
2786
|
// Codex/Claude 客户端,也不应被转成 CLI 托管模式并随客户端退出。
|
|
2364
2787
|
if (liveClients == 0 && self.managedByCLI) [NSApp terminate:nil];
|
|
2365
2788
|
}
|
|
2366
|
-
//
|
|
2367
|
-
// 没有 autoresizingMask,所以统一在这里按 contentView 的 subviews 铺一遍,避免漏掉一层。
|
|
2789
|
+
// 面板高度取决于渲染几张额度卡。调整玻璃容器后,内部内容随 autoresizingMask 铺满。
|
|
2368
2790
|
- (void)resizeQuotaDashboard {
|
|
2369
2791
|
NSSize size = NSMakeSize(QuotaLogicalWidth * QuotaScale,
|
|
2370
2792
|
QuotaLogicalHeightForProviderCount([self.quotaView visibleProviders].count) * QuotaScale);
|