cc-pets 2.4.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.
Files changed (53) hide show
  1. package/CC_BRIDGE.md +46 -9
  2. package/CC_BRIDGE.zh-CN.md +29 -6
  3. package/CHANGELOG.md +55 -0
  4. package/CHANGELOG.zh-CN.md +56 -1
  5. package/CONTRIBUTING.md +1 -1
  6. package/CONTRIBUTING.zh-CN.md +1 -1
  7. package/PROVIDER_PROTOCOL.md +5 -1
  8. package/PROVIDER_PROTOCOL.zh-CN.md +4 -1
  9. package/README.md +69 -16
  10. package/README.zh-CN.md +54 -19
  11. package/Resources/zh-Hans.lproj/Localizable.strings +35 -11
  12. package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +47 -4
  13. package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +109 -14
  14. package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +8 -6
  15. package/Sources/CCPets/App/CCPetsAppDelegate+MenuBar.m +86 -0
  16. package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +13 -0
  17. package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +6 -1
  18. package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +5 -3
  19. package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +4 -1
  20. package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +4 -0
  21. package/Sources/CCPets/App/CCPetsAppDelegate.h +10 -0
  22. package/Sources/CCPets/App/CCPetsAppDelegate.m +4 -2
  23. package/Sources/CCPets/Bridge/CCPetsBridge.m +34 -12
  24. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +100 -33
  25. package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +12 -3
  26. package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +317 -89
  27. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +0 -2
  28. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +210 -95
  29. package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +28 -3
  30. package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +222 -35
  31. package/Sources/CCPets/Integrations/CCPetsEvents.h +5 -0
  32. package/Sources/CCPets/Integrations/CCPetsEvents.m +68 -12
  33. package/Sources/CCPets/Integrations/CCPetsIntegrations.m +1 -1
  34. package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +6 -0
  35. package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +54 -5
  36. package/Sources/CCPets/Pet/CCPetsPhrasesEditor.m +7 -0
  37. package/Sources/CCPets/Pet/PetView+Menu.m +9 -1
  38. package/Sources/CCPets/Pet/PetView.h +7 -0
  39. package/Sources/CCPets/Pet/PetView.m +12 -1
  40. package/Sources/CCPets/Support/CCPetsPreferences.h +10 -0
  41. package/Sources/CCPets/Support/CCPetsPreferences.m +18 -0
  42. package/Sources/CCPets/UI/CCPetsMenuBarIcon.h +16 -0
  43. package/Sources/CCPets/UI/CCPetsMenuBarIcon.m +70 -0
  44. package/Sources/CCPets/UI/CCPetsMenuBarPanel.h +18 -0
  45. package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +528 -0
  46. package/Sources/CCPets/UI/CCPetsMenuBarSummary.h +51 -0
  47. package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +95 -0
  48. package/Sources/CCPets/UI/CCPetsSettingsPage.h +4 -1
  49. package/Sources/CCPets/UI/CCPetsSettingsPage.m +16 -0
  50. package/Sources/CCPets/UI/CCPetsStatusItem.h +28 -0
  51. package/Sources/CCPets/UI/CCPetsStatusItem.m +147 -0
  52. package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +5 -3
  53. package/package.json +1 -1
@@ -23,6 +23,8 @@
23
23
  - (void)updateNotification:(NSString *)key enabled:(BOOL)enabled
24
24
  completion:(void (^)(BOOL enabled))completion;
25
25
  - (void)updateBridgeBadgeEnabled:(BOOL)enabled;
26
+ - (void)updateDisplayMode:(NSString *)mode;
27
+ - (void)updateMenuBarShowsPercent:(BOOL)enabled;
26
28
  - (void)editPhrasesFile:(id)sender;
27
29
  // 按当前台词来源抽一句闲话,不说出来、不占碎碎念的预算和冷却。
28
30
  - (NSString *)sampleSpeechLine;
@@ -59,6 +61,7 @@
59
61
  @interface CCPetsAlertsPage : CCPetsSettingsPageBase
60
62
  @end
61
63
 
62
- // 通用:语言、主窗口外观(跟随系统 / 浅色 / 深色)、浮层外观(主题、玻璃压暗)、悬停面板显示什么、数据文件夹。
64
+ // 通用:语言、主窗口外观(跟随系统 / 浅色 / 深色)、显示位置(桌宠 / 菜单栏)、浮层外观(主题、玻璃压暗)、
65
+ // 悬停面板显示什么、数据文件夹。
63
66
  @interface CCPetsGeneralPage : CCPetsSettingsPageBase
64
67
  @end
@@ -1318,6 +1318,22 @@ static NSString *TerminalJumpShortState(NSDictionary *item, BOOL vscode) {
1318
1318
  subtitle:L(@"Only this window; the pet's panels follow Panel Appearance above") controls:@[appearance]],
1319
1319
  ] footer:nil];
1320
1320
 
1321
+ // 显示位置:桌宠、菜单栏图标或两者都要。仅菜单栏时状态卡、气泡和悬停面板都不出现。
1322
+ NSSegmentedControl *displayMode = [self segmentedWithOptions:@[
1323
+ @[L(@"Desktop Pet"), CCPetsDisplayModePet], @[L(@"Pet + Menu Bar"), CCPetsDisplayModeBoth],
1324
+ @[L(@"Menu Bar Only"), CCPetsDisplayModeMenuBar]]
1325
+ selected:^id { return CCPetsDisplayMode(); }
1326
+ action:^(NSString *value) { [weakSelf.actions updateDisplayMode:value]; }];
1327
+ [self.form addGroupWithTitle:L(@"Show In") rows:@[
1328
+ [CCPetsFormBuilder rowWithTitle:L(@"Display")
1329
+ subtitle:L(@"Menu bar only hides the pet, its status card, speech and hover panel; notifications still work")
1330
+ controls:@[displayMode]],
1331
+ [self switchRowWithTitle:L(@"Quota in Menu Bar")
1332
+ subtitle:L(@"Lowest 5-hour quota left; orange at 20% or below, red at 10%")
1333
+ key:CCPetsMenuBarShowsPercentKey
1334
+ apply:^(id<CCPetsSettingsActions> actions, BOOL enabled) { [actions updateMenuBarShowsPercent:enabled]; }],
1335
+ ] footer:nil];
1336
+
1321
1337
  [self.form addGroupWithTitle:L(@"Launch Protection") rows:@[
1322
1338
  [self switchRowWithTitle:@"Shadowrocket"
1323
1339
  subtitle:L(@"Block Claude / Codex when Shadowrocket is disconnected or the exit is in an unsupported region")
@@ -0,0 +1,28 @@
1
+ #import <Cocoa/Cocoa.h>
2
+ #import "CCPetsMainWindow.h"
3
+ #import "CCPetsWorkbench.h"
4
+
5
+ // 菜单栏图标:左键弹出玻璃面板(宠物状态、会话、各账号额度、今日用量,见 CCPetsMenuBarPanel),
6
+ // 右键是和桌宠同一份右键菜单。
7
+ //
8
+ // 数据全部来自现有快照(workbenchSessions / workbenchQuotas / petCardSnapshot),这里不采集、
9
+ // 不起定时器:标题和开着的面板只在宠物名片、额度或设置变了的时候重算。
10
+ // 和主窗口各页一样只认协议,不 import AppDelegate 的私有头。
11
+ @interface CCPetsStatusItemController : NSObject
12
+ - (instancetype)initWithSource:(id<CCPetsWorkbenchSource, CCPetsPetCardSource>)source;
13
+ @property(nonatomic, weak, readonly) id<CCPetsWorkbenchSource, CCPetsPetCardSource> source;
14
+ // 会话状态对应的颜色,和状态卡图标同一套(AppDelegate 的 statusColorForState:)。
15
+ @property(nonatomic, copy) NSColor *(^stateColorProvider)(NSString *state);
16
+ // 右键菜单。由桌宠那边现建;菜单收起后调 contextMenuFinished 收拾预览浮窗和说明。
17
+ @property(nonatomic, copy) NSMenu *(^contextMenuProvider)(void);
18
+ @property(nonatomic, copy) void (^contextMenuFinished)(void);
19
+ // 「显示桌宠」勾选项:读当前状态、切换。
20
+ @property(nonatomic, copy) BOOL (^petVisibleProvider)(void);
21
+ @property(nonatomic, copy) void (^togglePetVisible)(void);
22
+ // 有可安装的新版本时返回版本号;「仅菜单栏」下没有更新气泡和角标,入口只剩面板底部。
23
+ @property(nonatomic, copy) NSString *(^pendingUpdateVersionProvider)(void);
24
+ @property(nonatomic, copy) void (^showPendingUpdate)(void);
25
+ - (void)refresh;
26
+ // 从菜单栏移除并停止监听。之后这个对象不再可用。
27
+ - (void)invalidate;
28
+ @end
@@ -0,0 +1,147 @@
1
+ #import "CCPetsStatusItem.h"
2
+ #import "CCPetsMenuBarSummary.h"
3
+ #import "CCPetsPreferences.h"
4
+ #import "CCPetsL10n.h"
5
+ #import "CCPetsMenuBarPanel.h"
6
+ #import "CCPetsMenuBarIcon.h"
7
+
8
+ static NSColor *LevelColor(CCPetsMenuBarLevel level) {
9
+ switch (level) {
10
+ case CCPetsMenuBarLevelCritical: return NSColor.systemRedColor;
11
+ case CCPetsMenuBarLevelWarning: return NSColor.systemOrangeColor;
12
+ default: return nil;
13
+ }
14
+ }
15
+
16
+ @interface CCPetsStatusItemController ()
17
+ @property(nonatomic, weak, readwrite) id<CCPetsWorkbenchSource, CCPetsPetCardSource> source;
18
+ @property(nonatomic) NSStatusItem *item;
19
+ @property(nonatomic) CCPetsMenuBarPanel *panel;
20
+ // 各色调的菜单栏图标(见 CCPetsMenuBarIcon),每种只生成一次。
21
+ @property(nonatomic) NSMutableDictionary<NSNumber *, NSImage *> *iconImages;
22
+ @end
23
+
24
+ @implementation CCPetsStatusItemController
25
+
26
+ - (instancetype)initWithSource:(id<CCPetsWorkbenchSource, CCPetsPetCardSource>)source {
27
+ if (!(self = [super init])) return nil;
28
+ _source = source;
29
+ _panel = [[CCPetsMenuBarPanel alloc] initWithOwner:self];
30
+ _item = [NSStatusBar.systemStatusBar statusItemWithLength:NSVariableStatusItemLength];
31
+ _iconImages = [NSMutableDictionary dictionary];
32
+ _item.button.image = [self imageForTone:CCPetsMenuBarIconToneNone];
33
+ _item.button.toolTip = @"CC Pets";
34
+ _item.button.target = self;
35
+ _item.button.action = @selector(statusItemClicked:);
36
+ // 左右键松开都要回调,才能在 action 里分流两种菜单。和桌宠拖动无关(tests/test.sh 对拖动
37
+ // 实现的回归检查会拦 NSEventMask 常量的写法,所以这里按事件类型组掩码)。
38
+ [_item.button sendActionOn:NSEventMaskFromType(NSEventTypeLeftMouseUp) |
39
+ NSEventMaskFromType(NSEventTypeRightMouseUp)];
40
+ NSNotificationCenter *center = NSNotificationCenter.defaultCenter;
41
+ for (NSNotificationName name in @[CCPetsPetCardDidChangeNotification,
42
+ CCPetsWorkbenchQuotasDidChangeNotification,
43
+ CCPetsPreferencesDidChangeNotification,
44
+ CCPetsLanguageDidChangeNotification]) {
45
+ [center addObserver:self selector:@selector(sourceDidChange:) name:name object:nil];
46
+ }
47
+ [self refresh];
48
+ return self;
49
+ }
50
+
51
+ - (void)dealloc {
52
+ [NSNotificationCenter.defaultCenter removeObserver:self];
53
+ }
54
+
55
+ - (void)invalidate {
56
+ [NSNotificationCenter.defaultCenter removeObserver:self];
57
+ [self.panel dismiss];
58
+ if (self.item) [NSStatusBar.systemStatusBar removeStatusItem:self.item];
59
+ self.item = nil;
60
+ }
61
+
62
+ - (void)sourceDidChange:(NSNotification *)notification {
63
+ [self refresh];
64
+ }
65
+
66
+ - (void)refresh {
67
+ NSStatusBarButton *button = self.item.button;
68
+ if (!button) return;
69
+ NSDictionary *snapshot = [self.source petCardSnapshot];
70
+ NSUInteger approvals = [snapshot[@"approvals"] unsignedIntegerValue];
71
+ NSDictionary *parts = CCPetsMenuBarTitleParts([self.source workbenchQuotas], approvals,
72
+ CCPetsPrefBool(CCPetsMenuBarShowsPercentKey));
73
+ NSFont *font = [NSFont monospacedDigitSystemFontOfSize:NSFont.systemFontSize weight:NSFontWeightMedium];
74
+ NSMutableAttributedString *title = [NSMutableAttributedString new];
75
+ if (parts[@"percent"]) {
76
+ NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
77
+ NSColor *color = LevelColor([parts[@"level"] integerValue]);
78
+ if (color) attributes[NSForegroundColorAttributeName] = color;
79
+ [title appendAttributedString:[[NSAttributedString alloc]
80
+ initWithString:[@" " stringByAppendingString:parts[@"percent"]] attributes:attributes]];
81
+ }
82
+ if (parts[@"approvals"]) {
83
+ // U+FE0E 让 ⚠ 按文字字形绘制,颜色才跟得上前景色;否则会是一枚彩色 emoji。
84
+ [title appendAttributedString:[[NSAttributedString alloc]
85
+ initWithString:[NSString stringWithFormat:@" ⚠︎%@", parts[@"approvals"]]
86
+ attributes:@{NSFontAttributeName: font, NSForegroundColorAttributeName: NSColor.systemRedColor}]];
87
+ }
88
+ button.attributedTitle = title;
89
+ button.imagePosition = title.length > 0 ? NSImageLeft : NSImageOnly;
90
+ // 图标跟着状态卡走:同一条快照、同一套归类(工作中蓝、审批橙、完成绿、失败红),
91
+ // 状态卡回落待机时换回待机图。
92
+ NSString *state = [snapshot[@"state"] isKindOfClass:NSString.class] ? snapshot[@"state"] : nil;
93
+ CCPetsMenuBarIconTone tone = CCPetsMenuBarIconToneForState(state);
94
+ BOOL tinted = tone != CCPetsMenuBarIconToneNone;
95
+ button.image = [self imageForTone:tone];
96
+ NSMutableArray<NSString *> *description = [NSMutableArray arrayWithObject:@"CC Pets"];
97
+ if (tinted && [snapshot[@"status"] isKindOfClass:NSString.class]) [description addObject:snapshot[@"status"]];
98
+ if (parts[@"percent"]) [description addObject:parts[@"percent"]];
99
+ if (parts[@"approvals"]) {
100
+ [description addObject:[NSString stringWithFormat:L(@"%@ awaiting approval"), parts[@"approvals"]]];
101
+ }
102
+ [button setAccessibilityLabel:[description componentsJoinedByString:@", "]];
103
+ // 等审批时左键会直接跳转,提示里说清楚,免得用户以为面板打不开。
104
+ button.toolTip = approvals > 0 ? L(@"Click to jump to the session awaiting approval (⌥-click for the panel)") : @"CC Pets";
105
+ [self.panel reload];
106
+ }
107
+
108
+ - (NSImage *)imageForTone:(CCPetsMenuBarIconTone)tone {
109
+ NSImage *cached = self.iconImages[@(tone)];
110
+ if (cached) return cached;
111
+ NSImage *image = CCPetsMenuBarIconImage(tone);
112
+ self.iconImages[@(tone)] = image;
113
+ return image;
114
+ }
115
+
116
+ // 左右键共用一个 action。左键开关玻璃面板(有会话等审批时直接跳到那个终端);
117
+ // 右键临时挂上菜单交给按钮弹出,弹完摘掉——
118
+ // 一直挂着 item.menu 的话左键也会直接弹它。
119
+ - (void)statusItemClicked:(NSStatusBarButton *)sender {
120
+ NSEvent *event = NSApp.currentEvent;
121
+ BOOL secondary = event.type == NSEventTypeRightMouseUp ||
122
+ (event.modifierFlags & NSEventModifierFlagControl) != 0;
123
+ if (!secondary) {
124
+ if (self.panel.isShown) {
125
+ [self.panel dismiss];
126
+ return;
127
+ }
128
+ // 有会话在等审批:直接跳到那个终端,这是此刻唯一需要用户动手的事。按住 ⌥ 仍然打开面板。
129
+ BOOL option = (event.modifierFlags & NSEventModifierFlagOption) != 0;
130
+ NSString *approval = option ? nil : CCPetsMenuBarApprovalSessionID([self.source workbenchSessions]);
131
+ if (approval) {
132
+ [self.source focusWorkbenchSessionWithID:approval];
133
+ return;
134
+ }
135
+ [self.panel showBelowButton:sender];
136
+ return;
137
+ }
138
+ [self.panel dismiss];
139
+ NSMenu *menu = self.contextMenuProvider ? self.contextMenuProvider() : nil;
140
+ if (!menu) return;
141
+ self.item.menu = menu;
142
+ [sender performClick:nil];
143
+ self.item.menu = nil;
144
+ if (self.contextMenuFinished) self.contextMenuFinished();
145
+ }
146
+
147
+ @end
@@ -1,4 +1,5 @@
1
1
  #import "CCPetsWorkbenchPages.h"
2
+ #import "CCPetsBridgeStore.h"
2
3
  #import "CCPetsDiagnosticsPage.h"
3
4
  #import "CCPetsFormBuilder.h"
4
5
  #import "CCPetsL10n.h"
@@ -632,7 +633,7 @@ static const CGFloat SessionStateWidth = 92, SessionTimeWidth = 72, SessionActio
632
633
  kind:CCPetsStatusKindForAgentState(state)];
633
634
  [chip.widthAnchor constraintLessThanOrEqualToConstant:SessionStateWidth].active = YES;
634
635
 
635
- NSString *title = [session[@"name"] length] > 0 ? session[@"name"] : session[@"provider"];
636
+ NSString *title = [session[@"displayName"] length] > 0 ? session[@"displayName"] : session[@"provider"];
636
637
  NSTextField *name = CCPetsLabel(title, 13, NSFontWeightSemibold, CCPetsInkColor());
637
638
  NSMutableArray<NSString *> *parts = [NSMutableArray arrayWithObject:session[@"provider"]];
638
639
  if ([session[@"terminal"] length] > 0) [parts addObject:session[@"terminal"]];
@@ -746,7 +747,7 @@ static const CGFloat SessionStateWidth = 92, SessionTimeWidth = 72, SessionActio
746
747
  NSString *session = entry[@"session"];
747
748
  NSUInteger count = [entry[@"count"] unsignedIntegerValue];
748
749
  NSTextField *icon = CCPetsLabel(@"", 12, NSFontWeightRegular, CCPetsTertiaryInkColor());
749
- NSTextField *name = CCPetsLabel(entry[@"name"], 12, NSFontWeightSemibold, CCPetsInkColor());
750
+ NSTextField *name = CCPetsLabel(entry[@"displayName"] ?: entry[@"name"], 12, NSFontWeightSemibold, CCPetsInkColor());
750
751
  NSTextField *detail = CCPetsLabel(count == 1 ? L(@"1 message waiting. Say anything in that terminal to deliver it.")
751
752
  : [NSString stringWithFormat:L(@"%lu messages waiting. Say anything in that terminal to deliver them."),
752
753
  (unsigned long)count], 12, NSFontWeightRegular, CCPetsSecondaryInkColor());
@@ -762,7 +763,8 @@ static const CGFloat SessionStateWidth = 92, SessionTimeWidth = 72, SessionActio
762
763
  NSTextField *time = CCPetsNumberLabel([NSDateFormatter localizedStringFromDate:date
763
764
  dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle], 12, NSFontWeightRegular,
764
765
  CCPetsTertiaryInkColor());
765
- NSTextField *route = [self routeFrom:delivery[@"from"] to:delivery[@"to"]];
766
+ NSTextField *route = [self routeFrom:CCBridgeSessionDisplayName(delivery[@"fromIdentity"])
767
+ to:CCBridgeSessionDisplayName(delivery[@"toIdentity"])];
766
768
  NSTextField *detail = CCPetsLabel(@"", 12, NSFontWeightRegular, CCPetsSecondaryInkColor());
767
769
  BOOL unseen = [delivery[@"unseen"] boolValue];
768
770
  CCPetsChipView *chip = [[CCPetsChipView alloc] initWithText:unseen ? L(@"Unread") : L(@"Delivered")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-pets",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "A native macOS desktop pet for Codex CLI and Claude Code",
5
5
  "author": {
6
6
  "name": "Sunnyshiny",