cc-pets 1.1.0 → 1.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/README.md CHANGED
@@ -129,6 +129,31 @@ Hooks、shell alias 和 `~/Applications/CC Pets.app` 的安装;`--prefer-onlin
129
129
  cc-pets install
130
130
  ```
131
131
 
132
+ #### 关于安装脚本白名单
133
+
134
+ 新版 npm(12 起默认)引入了安装脚本白名单:不在白名单里的包,`postinstall` 一律不执行。
135
+ 它只打印一行 `warn install-scripts`,进程仍然以成功退出,所以**安装看起来是成功的**,
136
+ 但原生应用、Hooks 和 shell alias 都不会被安装 —— 表现为敲 `codex` / `claude` 时桌宠不出现。
137
+
138
+ 不想每次都带 `--allow-scripts` 参数的话,可以配置一次持久白名单:
139
+
140
+ ```bash
141
+ npm config set allow-scripts=cc-pets --location=user
142
+ ```
143
+
144
+ 这个机制作用于所有带 `postinstall` 的包,不限于 CC Pets。常见的一个例子是 Claude Code 自身:
145
+ 它的原生二进制正是由 `postinstall` 铺开的,被拦下时执行 `claude` 会提示
146
+ `claude native binary not installed`,而重装并不能修好 —— 因为每次重装都会被同样拦下。
147
+ 这类情况可以按需把多个包一起加进白名单:
148
+
149
+ ```bash
150
+ npm config set allow-scripts=cc-pets,@anthropic-ai/claude-code --location=user
151
+ ```
152
+
153
+ 怀疑某个 CLI 装完后行为异常时,可以在 `~/.npm/_logs/` 最近的日志里搜 `install-scripts`,
154
+ 确认是不是同一个原因。注意白名单只对之后的安装生效,不会回头补跑已经被拦下的脚本,
155
+ 所以配置完还需要重装一次对应的包。
156
+
132
157
  ### 本地源码安装
133
158
 
134
159
  ```bash
@@ -162,6 +187,7 @@ Codex/Claude Hooks 和 shell 集成,并自动重启正在运行的桌宠。自
162
187
 
163
188
  ```bash
164
189
  npm install -g cc-pets@latest \
190
+ --allow-scripts=cc-pets \
165
191
  --prefer-online
166
192
  ```
167
193
 
@@ -48,7 +48,6 @@
48
48
  - (void)positionAgentStatus;
49
49
  - (void)showAgentStatusForRecord:(NSDictionary *)record;
50
50
  - (void)prunePendingApprovalRecords;
51
- - (void)toggleAgentStatusBubble:(id)sender;
52
51
  - (void)toggleStatusBubbleFromMenu:(NSButton *)sender;
53
52
  - (void)refreshUsage:(id)sender;
54
53
  - (void)applyCodexUsage:(NSDictionary *)codexUsage claudeUsage:(NSDictionary *)claudeUsage;
@@ -405,20 +405,8 @@ static void TrimUpdateLog(NSString *path) {
405
405
  [self.statusPanel orderOut:nil];
406
406
  self.hasAgentStatus = NO;
407
407
  }
408
- - (void)toggleAgentStatusBubble:(id)sender {
409
- if (!self.hasAgentStatus) return;
410
- self.statusBubbleExpanded = !self.statusBubbleExpanded;
411
- [NSUserDefaults.standardUserDefaults setBool:self.statusBubbleExpanded
412
- forKey:StatusBubbleExpandedKey];
413
- if (self.statusBubbleExpanded) {
414
- [self positionAgentStatus];
415
- [self.statusPanel orderFrontRegardless];
416
- } else {
417
- [self.statusPanel orderOut:nil];
418
- }
419
- }
420
- // 菜单开关的语义和点击宠物相反:勾选 = 显示气泡。没有 agent 状态时也允许改,
421
- // 这样用户可以提前设好偏好,而不必等下一次会话开始。
408
+ // 勾选 = 显示气泡。没有 agent 状态时也允许改,这样用户可以提前设好偏好,
409
+ // 而不必等下一次会话开始。
422
410
  - (void)toggleStatusBubbleFromMenu:(NSButton *)sender {
423
411
  self.statusBubbleExpanded = !self.statusBubbleExpanded;
424
412
  [NSUserDefaults.standardUserDefaults setBool:self.statusBubbleExpanded
@@ -757,9 +745,6 @@ static void TrimUpdateLog(NSString *path) {
757
745
  weakSelf.petDragging = dragging;
758
746
  if (!dragging) [weakSelf scheduleQuotaDashboardHide];
759
747
  };
760
- self.petView.statusToggleRequested = ^{
761
- [weakSelf toggleAgentStatusBubble:nil];
762
- };
763
748
  // 附属面板的跟随必须挂在窗口自身的移动通知上,不能只挂 PetView 的拖动回调:
764
749
  // panel 开了 movableByWindowBackground,按在 PetView 之外的透明边上时由 AppKit
765
750
  // 直接搬窗口,PetView 的 mouseDragged 根本不触发,气泡就会留在原地。
@@ -17,7 +17,6 @@
17
17
  @property id localMouseMonitor;
18
18
  @property(copy) void (^pocketHoverChanged)(BOOL hovering);
19
19
  @property(copy) void (^dragStateChanged)(BOOL dragging);
20
- @property(copy) void (^statusToggleRequested)(void);
21
20
  @property(copy) NSArray<NSDictionary *> *(^petOptionsRequested)(void);
22
21
  @property(copy) void (^switchPetRequested)(NSString *petID);
23
22
  @property NSCache<NSString *, NSImage *> *petMenuPreviewCache;
@@ -305,7 +305,6 @@ static const CGFloat PetDragThreshold = 3.0;
305
305
  // 就说明本次按下没有拖动过,不需要额外的标志来区分。
306
306
  - (void)mouseUp:(NSEvent *)event {
307
307
  [self playRow:7 throughFrame:5 oneShot:YES];
308
- if (self.statusToggleRequested) self.statusToggleRequested();
309
308
  }
310
309
  - (void)drawRect:(NSRect)dirtyRect {
311
310
  CGFloat cellWidth = self.sheet.size.width / 8.0;
@@ -494,7 +493,6 @@ static const CGFloat PetDragThreshold = 3.0;
494
493
  [menu addItem:NSMenuItem.separatorItem];
495
494
  NSMenuItem *refreshItem = [menu addItemWithTitle:@"刷新用量" action:@selector(refreshUsage:) keyEquivalent:@"r"];
496
495
  refreshItem.target = NSApp.delegate;
497
- // 点击宠物本体也能折叠气泡,但那个交互没有任何视觉提示。这里留一个可发现的入口。
498
496
  [self addPersistentSwitchToMenu:menu
499
497
  title:@"显示消息气泡"
500
498
  checked:[NSUserDefaults.standardUserDefaults boolForKey:StatusBubbleExpandedKey]
@@ -57,14 +57,13 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
57
57
  - (NSRect)logicalSummaryRect {
58
58
  return NSMakeRect(20, 372, QuotaLogicalWidth - 40, 86);
59
59
  }
60
+ // 刷新时间挪去了右上角,这一版块整宽留给两个统计格,各占一半。
60
61
  - (NSRect)logicalSummaryCellRectAtIndex:(NSUInteger)index {
61
62
  NSRect summary = [self logicalSummaryRect];
62
- const CGFloat widths[] = {280, 280, 160};
63
- CGFloat x = NSMinX(summary);
64
- for (NSUInteger current = 0; current < MIN(index, (NSUInteger)3); current++) {
65
- x += widths[current];
66
- }
67
- return index < 3 ? NSMakeRect(x, NSMinY(summary), widths[index], NSHeight(summary)) : NSZeroRect;
63
+ CGFloat width = NSWidth(summary) / 2;
64
+ return index < 2
65
+ ? NSMakeRect(NSMinX(summary) + index * width, NSMinY(summary), width, NSHeight(summary))
66
+ : NSZeroRect;
68
67
  }
69
68
  - (void)mouseMoved:(NSEvent *)event {
70
69
  NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
@@ -109,16 +108,31 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
109
108
  ? usage[@"tokenUsage"] : nil;
110
109
  return [tokenUsage[key] isKindOfClass:NSDictionary.class] ? tokenUsage[key] : nil;
111
110
  }
112
- - (NSString *)formattedTokenCount:(NSDictionary *)totals {
113
- NSNumber *number = [totals[@"total_tokens"] isKindOfClass:NSNumber.class]
114
- ? totals[@"total_tokens"] : nil;
115
- if (!number) return @"--";
116
- double value = number.doubleValue;
111
+ - (NSString *)formattedTokenValue:(double)value {
117
112
  if (value >= 1000000000) return [NSString stringWithFormat:@"%.2fB", value / 1000000000.0];
118
113
  if (value >= 1000000) return [NSString stringWithFormat:@"%.2fM", value / 1000000.0];
119
114
  if (value >= 1000) return [NSString stringWithFormat:@"%.1fK", value / 1000.0];
120
115
  return [NSString stringWithFormat:@"%.0f", value];
121
116
  }
117
+ - (NSString *)formattedTokenCount:(NSDictionary *)totals {
118
+ NSNumber *number = [totals[@"total_tokens"] isKindOfClass:NSNumber.class]
119
+ ? totals[@"total_tokens"] : nil;
120
+ return number ? [self formattedTokenValue:number.doubleValue] : @"--";
121
+ }
122
+ // 输入取 total - output,而不是把几个 input_* 字段加起来:两家的包含关系是相反的。
123
+ // Codex 的 cached_input_tokens 是 input_tokens 的子集(实测 input+output == total),
124
+ // 相加会把缓存部分算两遍;Claude 的 input_tokens 不含缓存读写,两者是并列项,不加又会漏。
125
+ // total - output 对两家都成立,也保证"输入 + 输出"正好等于卡片上那个已用 Token。
126
+ - (NSString *)formattedTokenSplit:(NSDictionary *)totals wantsOutput:(BOOL)wantsOutput {
127
+ NSNumber *total = [totals[@"total_tokens"] isKindOfClass:NSNumber.class]
128
+ ? totals[@"total_tokens"] : nil;
129
+ if (!total) return @"--";
130
+ NSNumber *output = [totals[@"output_tokens"] isKindOfClass:NSNumber.class]
131
+ ? totals[@"output_tokens"] : nil;
132
+ double outputValue = output ? output.doubleValue : 0;
133
+ return [self formattedTokenValue:
134
+ wantsOutput ? outputValue : fmax(0, total.doubleValue - outputValue)];
135
+ }
122
136
  // 两个窗口共用。resets_at 是整分对齐的,带秒只会多占宽度。
123
137
  - (NSString *)clockText:(NSTimeInterval)value {
124
138
  NSDateFormatter *formatter = [NSDateFormatter new];
@@ -146,6 +160,11 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
146
160
  - (NSString *)formattedTokenCountForUsage:(NSDictionary *)usage key:(NSString *)key {
147
161
  return [self formattedTokenCount:[self tokenTotals:usage key:key] ?: @{}];
148
162
  }
163
+ - (NSString *)formattedTokenSplitForUsage:(NSDictionary *)usage key:(NSString *)key
164
+ wantsOutput:(BOOL)wantsOutput {
165
+ return [self formattedTokenSplit:[self tokenTotals:usage key:key] ?: @{}
166
+ wantsOutput:wantsOutput];
167
+ }
149
168
  - (NSNumber *)usedForQuota:(NSDictionary *)quota usedKey:(NSString *)usedKey {
150
169
  NSNumber *used = [quota[usedKey] isKindOfClass:NSNumber.class] ? quota[usedKey] : nil;
151
170
  return used ? @(fmax(0, fmin(100, used.doubleValue))) : nil;
@@ -162,6 +181,14 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
162
181
  return @{NSFontAttributeName: [NSFont systemFontOfSize:size weight:weight],
163
182
  NSForegroundColorAttributeName: color};
164
183
  }
184
+ - (NSDictionary *)rightAlignedTextAttributesWithSize:(CGFloat)size color:(NSColor *)color
185
+ weight:(NSFontWeight)weight {
186
+ NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
187
+ style.alignment = NSTextAlignmentRight;
188
+ return @{NSFontAttributeName: [NSFont systemFontOfSize:size weight:weight],
189
+ NSForegroundColorAttributeName: color,
190
+ NSParagraphStyleAttributeName: style};
191
+ }
165
192
  - (NSDictionary *)centeredTextAttributesWithSize:(CGFloat)size color:(NSColor *)color weight:(NSFontWeight)weight {
166
193
  NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
167
194
  style.alignment = NSTextAlignmentCenter;
@@ -363,6 +390,12 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
363
390
  [self fillRoundedRect:refreshRect radius:10 color:[NSColor colorWithWhite:1 alpha:buttonAlpha]];
364
391
  [recentlyRefreshed ? @"✓" : @"↻" drawInRect:NSInsetRect(refreshRect, 8, 4)
365
392
  withAttributes:[self textAttributesWithSize:19 color:[NSColor colorWithWhite:0.9 alpha:1] weight:NSFontWeightRegular]];
393
+ // 贴着刷新按钮左侧右对齐:它说明的正是这个按钮上次生效的时间,挨着放才不用再标一遍
394
+ // "数据刷新"是什么意思。放回汇总条里会挤掉一整格 Provider 数据。
395
+ [[NSString stringWithFormat:@"数据刷新 %@", [self refreshAgeText]]
396
+ drawInRect:NSMakeRect(NSMinX(logicalRefreshRect) - 206, NSMinY(logicalRefreshRect) + 7, 200, 18)
397
+ withAttributes:[self rightAlignedTextAttributesWithSize:11 color:secondary
398
+ weight:NSFontWeightRegular]];
366
399
 
367
400
  NSRect summary = [self logicalSummaryRect];
368
401
  NSBezierPath *summaryPath = [NSBezierPath bezierPathWithRoundedRect:summary xRadius:18 yRadius:18];
@@ -373,12 +406,16 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
373
406
 
374
407
  // 今日与最近 7 天都按 Provider 分开展示。底层本来就是两套独立的自然日统计,
375
408
  // 不在展示层相加,避免用户无法判断 Token 来自 Codex 还是 Claude。
376
- // 两个统计格各占 280pt,刷新格压缩为 160pt,把主要空间留给双 Provider 数据。
409
+ // 每格内是一张 2×2 表:行是 Provider,列是输入/输出,列头与格标题共用一行 —— 86pt
410
+ // 高度只够三行,再单开一行列头就得把格子拔高,挤掉下面两张 Provider 卡片。
377
411
  NSArray<NSDictionary *> *cells = @[
378
412
  @{@"icon": @"◔", @"key": @"today", @"label": @"今日已用 Token"},
379
- @{@"icon": @"◉", @"key": @"recentWeek", @"label": @"近 7 天已用 Token"},
380
- @{@"icon": @"◷", @"tint": NSColor.systemPurpleColor, @"value": [self refreshAgeText],
381
- @"label": @"数据刷新"}
413
+ @{@"icon": @"◉", @"key": @"recentWeek", @"label": @"近 7 天已用 Token"}
414
+ ];
415
+ NSColor *claudeColor = [NSColor colorWithRed:0.66 green:0.43 blue:0.94 alpha:1];
416
+ NSArray<NSDictionary *> *rows = @[
417
+ @{@"name": @"Codex", @"usage": self.codexUsage ?: @{}, @"color": cyan, @"y": @35},
418
+ @{@"name": @"Claude", @"usage": self.claudeUsage ?: @{}, @"color": claudeColor, @"y": @12}
382
419
  ];
383
420
  [[NSColor colorWithWhite:1 alpha:0.10] setStroke];
384
421
  for (NSUInteger index = 1; index < cells.count; index++) {
@@ -388,36 +425,32 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
388
425
  }
389
426
  for (NSUInteger index = 0; index < cells.count; index++) {
390
427
  NSDictionary *cell = cells[index];
391
- NSRect cellRect = [self logicalSummaryCellRectAtIndex:index];
392
- CGFloat x = NSMinX(cellRect);
393
- BOOL isTokenWindow = [cell[@"key"] isKindOfClass:NSString.class];
394
- NSColor *tint = isTokenWindow ? cyan : cell[@"tint"];
395
- CGFloat iconX = x + (isTokenWindow ? 26 : 16);
396
- [cell[@"icon"] drawInRect:NSMakeRect(iconX, NSMinY(summary) + 23, 42, 42)
397
- withAttributes:[self textAttributesWithSize:30 color:tint
398
- weight:NSFontWeightRegular]];
399
- if (isTokenWindow) {
400
- NSString *key = cell[@"key"];
401
- NSColor *claudeColor = [NSColor colorWithRed:0.66 green:0.43 blue:0.94 alpha:1];
402
- [cell[@"label"] drawInRect:NSMakeRect(x + 74, NSMinY(summary) + 59, 180, 18)
403
- withAttributes:[self textAttributesWithSize:11 color:secondary
404
- weight:NSFontWeightRegular]];
405
- [@"Codex" drawInRect:NSMakeRect(x + 74, NSMinY(summary) + 35, 54, 20)
406
- withAttributes:[self textAttributesWithSize:12 color:cyan weight:NSFontWeightMedium]];
407
- [[self formattedTokenCountForUsage:self.codexUsage key:key]
408
- drawInRect:NSMakeRect(x + 126, NSMinY(summary) + 33, 92, 23)
409
- withAttributes:[self textAttributesWithSize:16 color:primary weight:NSFontWeightBold]];
410
- [@"Claude" drawInRect:NSMakeRect(x + 74, NSMinY(summary) + 12, 54, 20)
411
- withAttributes:[self textAttributesWithSize:12 color:claudeColor weight:NSFontWeightMedium]];
412
- [[self formattedTokenCountForUsage:self.claudeUsage key:key]
413
- drawInRect:NSMakeRect(x + 126, NSMinY(summary) + 10, 92, 23)
414
- withAttributes:[self textAttributesWithSize:16 color:primary weight:NSFontWeightBold]];
415
- } else {
416
- [cell[@"value"] drawInRect:NSMakeRect(x + 56, NSMinY(summary) + 40, 96, 28)
417
- withAttributes:[self textAttributesWithSize:20 color:primary weight:NSFontWeightBold]];
418
- [cell[@"label"] drawInRect:NSMakeRect(x + 56, NSMinY(summary) + 17, 96, 20)
419
- withAttributes:[self textAttributesWithSize:11 color:secondary
420
- weight:NSFontWeightRegular]];
428
+ NSString *key = cell[@"key"];
429
+ CGFloat x = NSMinX([self logicalSummaryCellRectAtIndex:index]);
430
+ const CGFloat inputX = x + 176;
431
+ const CGFloat outputX = x + 266;
432
+ [cell[@"icon"] drawInRect:NSMakeRect(x + 24, NSMinY(summary) + 23, 42, 42)
433
+ withAttributes:[self textAttributesWithSize:30 color:cyan weight:NSFontWeightRegular]];
434
+ NSDictionary *headerAttributes = [self textAttributesWithSize:11 color:secondary
435
+ weight:NSFontWeightRegular];
436
+ [cell[@"label"] drawInRect:NSMakeRect(x + 72, NSMinY(summary) + 59, 100, 18)
437
+ withAttributes:headerAttributes];
438
+ [@"输入" drawInRect:NSMakeRect(inputX, NSMinY(summary) + 59, 86, 18)
439
+ withAttributes:headerAttributes];
440
+ [@"输出" drawInRect:NSMakeRect(outputX, NSMinY(summary) + 59, 86, 18)
441
+ withAttributes:headerAttributes];
442
+ for (NSDictionary *row in rows) {
443
+ CGFloat y = NSMinY(summary) + [row[@"y"] doubleValue];
444
+ NSDictionary *usage = row[@"usage"];
445
+ [row[@"name"] drawInRect:NSMakeRect(x + 72, y, 60, 20)
446
+ withAttributes:[self textAttributesWithSize:12 color:row[@"color"]
447
+ weight:NSFontWeightMedium]];
448
+ NSDictionary *valueAttributes = [self textAttributesWithSize:16 color:primary
449
+ weight:NSFontWeightBold];
450
+ [[self formattedTokenSplitForUsage:usage key:key wantsOutput:NO]
451
+ drawInRect:NSMakeRect(inputX, y - 2, 86, 23) withAttributes:valueAttributes];
452
+ [[self formattedTokenSplitForUsage:usage key:key wantsOutput:YES]
453
+ drawInRect:NSMakeRect(outputX, y - 2, 86, 23) withAttributes:valueAttributes];
421
454
  }
422
455
  }
423
456
 
@@ -426,7 +459,7 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
426
459
  [self drawProvider:@"Claude" usage:self.claudeUsage usedKey:@"used_percentage"
427
460
  color:[NSColor colorWithRed:0.66 green:0.43 blue:0.94 alpha:1]
428
461
  cardRect:NSMakeRect(20, 44, QuotaLogicalWidth - 40, 152)];
429
- NSString *footer = @"ⓘ 百分比 = 官方订阅额度的剩余比例;Token = 本机统计的已用量,两者口径不同";
462
+ NSString *footer = @"ⓘ 百分比 = 官方订阅额度的剩余比例;Token = 本机统计的已用量(输入含缓存读写),两者口径不同";
430
463
  // 卡片底边在 y=44,原来 footer 顶到 44 完全没有间隙。下移到与卡片留约 8pt,
431
464
  // 同时底部留白 16pt,和顶部标题的留白大致对称。
432
465
  [footer drawInRect:NSMakeRect(28, 16, 650, 20)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-pets",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A native macOS desktop pet for Codex CLI and Claude Code",
5
5
  "author": "wangxinyusqn",
6
6
  "license": "MIT",