cc-pets 2.1.1 → 2.1.2
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 +5 -0
- package/CC_BRIDGE.zh-CN.md +4 -0
- package/CHANGELOG.md +23 -1
- package/CHANGELOG.zh-CN.md +23 -1
- package/README.md +50 -12
- package/README.zh-CN.md +49 -13
- package/Sources/CCPets/CCPetsAppDelegate+AgentEvents.m +215 -0
- package/Sources/CCPets/CCPetsAppDelegate+AgentStatus.m +660 -0
- package/Sources/CCPets/CCPetsAppDelegate+Bridge.m +297 -0
- package/Sources/CCPets/CCPetsAppDelegate+Pets.m +187 -0
- package/Sources/CCPets/CCPetsAppDelegate+Private.h +322 -0
- package/Sources/CCPets/CCPetsAppDelegate+Quota.m +216 -0
- package/Sources/CCPets/CCPetsAppDelegate+Settings.m +205 -0
- package/Sources/CCPets/CCPetsAppDelegate+Speech.m +392 -0
- package/Sources/CCPets/CCPetsAppDelegate+Update.m +458 -0
- package/Sources/CCPets/CCPetsAppDelegate.h +13 -14
- package/Sources/CCPets/CCPetsAppDelegate.m +49 -2453
- package/Sources/CCPets/CCPetsCleanup.h +4 -0
- package/Sources/CCPets/CCPetsCleanup.m +32 -1
- package/Sources/CCPets/CCPetsPaths.h +0 -1
- package/Sources/CCPets/CCPetsPaths.m +0 -1
- package/Sources/CCPets/CCPetsUsage.h +0 -1
- package/Sources/CCPets/CCPetsUsage.m +0 -3
- package/Sources/CCPets/CCPetsVersion.h +7 -0
- package/Sources/CCPets/CCPetsVersion.m +82 -0
- package/Sources/CCPets/PetView.h +2 -0
- package/Sources/CCPets/PetView.m +16 -4
- package/Sources/CCPets/QuotaDashboardView.m +0 -3
- package/Sources/CCPets/main.m +13 -0
- package/bin/cc-pets +7 -1
- package/package.json +3 -2
- package/scripts/bridge/cli.mjs +9 -2
- package/scripts/bridge/core.mjs +1 -1
- package/scripts/bridge/install.mjs +23 -1
- package/scripts/bridge/process.mjs +22 -0
- package/scripts/doctor.mjs +456 -0
- package/scripts/install-claude-hooks.mjs +12 -18
- package/scripts/install-codex-hooks.mjs +3 -9
- package/scripts/integration-markers.mjs +51 -0
- package/scripts/pet-store.mjs +2 -1
- package/scripts/uninstall-integrations.mjs +16 -44
- package/scripts/uninstall-shell-integration.sh +3 -3
|
@@ -5,3 +5,7 @@ void PruneStaleRuntimeState(void);
|
|
|
5
5
|
|
|
6
6
|
// clean 删除可重建缓存;purge 额外删除历史、更新配置和用户偏好。
|
|
7
7
|
int CleanCCPetsData(BOOL purge);
|
|
8
|
+
|
|
9
|
+
// cc-pets paths / doctor 用:各类数据的实际路径(已套用环境变量覆盖)与桌宠是否在运行。
|
|
10
|
+
// 台词路径在 CCPetsPhrases 里,由 main.m 补上,免得只链接清理模块的测试也得带上整个词库。
|
|
11
|
+
NSDictionary<NSString *, id> *CCPetsDataPaths(void);
|
|
@@ -19,6 +19,14 @@ static NSString *ClientStateDirectory(void) {
|
|
|
19
19
|
return [PetStateDirectory() stringByAppendingPathComponent:name];
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// pet-store 的素材源清单缓存(~/.cc-pets/cache,可用 CC_PETS_HOME 覆盖)。过期会自动重拉,
|
|
23
|
+
// 属于纯缓存;~/.cc-pets 下其余内容(素材、台词)是用户数据,clean 和 purge 都不碰。
|
|
24
|
+
static NSString *PetStoreCacheDirectory(void) {
|
|
25
|
+
NSString *home = NSProcessInfo.processInfo.environment[@"CC_PETS_HOME"];
|
|
26
|
+
if (home.length == 0) home = [NSHomeDirectory() stringByAppendingPathComponent:@".cc-pets"];
|
|
27
|
+
return [home.stringByStandardizingPath stringByAppendingPathComponent:@"cache"];
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
static BOOL RemoveIfPresent(NSString *path) {
|
|
23
31
|
if (path.length == 0 || ![NSFileManager.defaultManager fileExistsAtPath:path]) return NO;
|
|
24
32
|
return [NSFileManager.defaultManager removeItemAtPath:path error:nil];
|
|
@@ -151,7 +159,7 @@ int CleanCCPetsData(BOOL purge) {
|
|
|
151
159
|
NSUInteger removed = 0;
|
|
152
160
|
if (RemoveClaudeUsageIfUnlocked()) removed += 1;
|
|
153
161
|
for (NSString *path in @[AgentEventPath(), CodexLiveUsagePath(), CodexLaunchRegistryPath(), RuntimeLockPath(),
|
|
154
|
-
ClientStateDirectory(), buildCache ?: @""]) {
|
|
162
|
+
ClientStateDirectory(), PetStoreCacheDirectory(), buildCache ?: @""]) {
|
|
155
163
|
if (RemoveIfPresent(path)) removed += 1;
|
|
156
164
|
}
|
|
157
165
|
// Token 摘要缓存也是纯缓存(丢了只是重新解析一遍会话文件),原先漏在清理之外,
|
|
@@ -170,3 +178,26 @@ int CleanCCPetsData(BOOL purge) {
|
|
|
170
178
|
(unsigned long)removed);
|
|
171
179
|
return EXIT_SUCCESS;
|
|
172
180
|
}
|
|
181
|
+
|
|
182
|
+
// 路径全部取自运行时真正使用的函数,Node 侧的 doctor 只负责展示,不再自己拼一套。
|
|
183
|
+
NSDictionary<NSString *, id> *CCPetsDataPaths(void) {
|
|
184
|
+
NSString *domain = NSProcessInfo.processInfo.environment[@"CC_PETS_PREFERENCES_DOMAIN"];
|
|
185
|
+
if (domain.length == 0) domain = PreferencesDomain;
|
|
186
|
+
NSString *preferences = [[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Preferences"]
|
|
187
|
+
stringByAppendingPathComponent:domain] stringByAppendingPathExtension:@"plist"];
|
|
188
|
+
return @{
|
|
189
|
+
@"running": @(RuntimeIsActive()),
|
|
190
|
+
@"preferences": preferences,
|
|
191
|
+
@"applicationSupport": ApplicationSupportDirectory(),
|
|
192
|
+
@"quotaHistory": QuotaHistoryPath(),
|
|
193
|
+
@"stateDirectory": PetStateDirectory(),
|
|
194
|
+
@"agentEvents": AgentEventPath(),
|
|
195
|
+
@"claudeUsage": ClaudeUsagePath(),
|
|
196
|
+
@"codexLiveUsage": CodexLiveUsagePath(),
|
|
197
|
+
@"codexLaunches": CodexLaunchRegistryPath(),
|
|
198
|
+
@"runtimeLock": RuntimeLockPath(),
|
|
199
|
+
@"clients": ClientStateDirectory(),
|
|
200
|
+
@"pets": OwnPetsDirectory(),
|
|
201
|
+
@"petStoreCache": PetStoreCacheDirectory(),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -42,7 +42,6 @@ BOOL ClaudeCLIDetected(void);
|
|
|
42
42
|
// 已存在的同名目录一律跳过,不覆盖。
|
|
43
43
|
NSUInteger ImportCodexPets(void);
|
|
44
44
|
|
|
45
|
-
extern NSString *const HistoryEnabledKey;
|
|
46
45
|
extern NSString *const NotificationCompletionKey;
|
|
47
46
|
extern NSString *const NotificationFailureKey;
|
|
48
47
|
extern NSString *const NotificationApprovalKey;
|
|
@@ -223,7 +223,6 @@ NSUInteger ImportCodexPets(void) {
|
|
|
223
223
|
return imported;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
NSString *const HistoryEnabledKey = @"CCPetsQuotaHistoryEnabled";
|
|
227
226
|
NSString *const NotificationCompletionKey = @"CCPetsNotifyCompletion";
|
|
228
227
|
NSString *const NotificationFailureKey = @"CCPetsNotifyFailure";
|
|
229
228
|
NSString *const NotificationApprovalKey = @"CCPetsNotifyApproval";
|
|
@@ -30,7 +30,6 @@ NSDictionary *UsageByRemovingExpiredQuotaWindows(NSDictionary *usage);
|
|
|
30
30
|
@property NSTimeInterval lastFullDiscovery;
|
|
31
31
|
- (NSDictionary *)refresh;
|
|
32
32
|
- (NSDictionary *)refreshWithFullDiscovery;
|
|
33
|
-
- (NSDictionary *)refreshForSessionURL:(NSURL *)url;
|
|
34
33
|
// 一批 FSEvents 里可能有多个会话文件同时变更(并发会话)。谁的额度采样更晚要读过才知道,
|
|
35
34
|
// 不能取遍历到的最后一个,详见实现处注释。
|
|
36
35
|
- (NSDictionary *)refreshForSessionURLs:(NSArray<NSURL *> *)urls;
|
|
@@ -1625,9 +1625,6 @@ static const NSUInteger MaximumPinnedSessions = 8;
|
|
|
1625
1625
|
NSString *prefix = [sessionsPath stringByAppendingString:@"/"];
|
|
1626
1626
|
return [url.path.stringByResolvingSymlinksInPath hasPrefix:prefix];
|
|
1627
1627
|
}
|
|
1628
|
-
- (NSDictionary *)refreshForSessionURL:(NSURL *)url {
|
|
1629
|
-
return [self refreshForSessionURLs:url ? @[url] : @[]];
|
|
1630
|
-
}
|
|
1631
1628
|
// 并发会话下一批事件里会有多个会话文件同时变更,而"文件更晚被写"和"额度采样更晚"是两回事:
|
|
1632
1629
|
// 会话拿到 rate_limits 之后还会继续追加别的行。取遍历到的最后一个就会切到采样偏旧的会话,
|
|
1633
1630
|
// 面板上的百分比于是在两个会话之间来回跳。这里读各自的尾巴,按 sampledAt 挑,与
|
|
@@ -11,3 +11,10 @@ int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed);
|
|
|
11
11
|
|
|
12
12
|
// npm 安装日志里是否只是暂时性故障(值得自动重试一次),而不是真的装不上。
|
|
13
13
|
BOOL UpdateFailureIsTransient(NSString *log);
|
|
14
|
+
|
|
15
|
+
// 从 GitHub Release 描述里摘出更新要点,给更新弹窗用。有「简体中文」标题段就只看那一段
|
|
16
|
+
// (Release 是中英双语的,菜单是中文),只取列表项,去掉 Markdown 标记,代码块整段跳过。
|
|
17
|
+
// 每条超过 maxLength 个字符截断加「…」;超过 limit 条时只返回前 limit 条并把 *truncated 置 YES。
|
|
18
|
+
// 没有列表项返回空数组——没写说明就不展示,不去猜正文。
|
|
19
|
+
NSArray<NSString *> *ReleaseNoteHighlights(NSString *body, NSUInteger limit, NSUInteger maxLength,
|
|
20
|
+
BOOL *truncated);
|
|
@@ -80,3 +80,85 @@ BOOL UpdateFailureIsTransient(NSString *log) {
|
|
|
80
80
|
}
|
|
81
81
|
return NO;
|
|
82
82
|
}
|
|
83
|
+
|
|
84
|
+
static NSString *StripReleaseNoteMarkdown(NSString *text) {
|
|
85
|
+
static NSRegularExpression *link, *image;
|
|
86
|
+
static dispatch_once_t once;
|
|
87
|
+
dispatch_once(&once, ^{
|
|
88
|
+
image = [NSRegularExpression regularExpressionWithPattern:@"!\\[[^\\]]*\\]\\([^)]*\\)"
|
|
89
|
+
options:0 error:nil];
|
|
90
|
+
link = [NSRegularExpression regularExpressionWithPattern:@"\\[([^\\]]*)\\]\\([^)]*\\)"
|
|
91
|
+
options:0 error:nil];
|
|
92
|
+
});
|
|
93
|
+
NSMutableString *result = [text mutableCopy];
|
|
94
|
+
[image replaceMatchesInString:result options:0 range:NSMakeRange(0, result.length) withTemplate:@""];
|
|
95
|
+
[link replaceMatchesInString:result options:0 range:NSMakeRange(0, result.length) withTemplate:@"$1"];
|
|
96
|
+
for (NSString *marker in @[@"**", @"__", @"`"]) {
|
|
97
|
+
[result replaceOccurrencesOfString:marker withString:@"" options:0
|
|
98
|
+
range:NSMakeRange(0, result.length)];
|
|
99
|
+
}
|
|
100
|
+
return [result stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
NSArray<NSString *> *ReleaseNoteHighlights(NSString *body, NSUInteger limit, NSUInteger maxLength,
|
|
104
|
+
BOOL *truncated) {
|
|
105
|
+
if (truncated) *truncated = NO;
|
|
106
|
+
if (![body isKindOfClass:NSString.class] || body.length == 0 || limit == 0) return @[];
|
|
107
|
+
NSArray<NSString *> *lines = [[body stringByReplacingOccurrencesOfString:@"\r" withString:@""]
|
|
108
|
+
componentsSeparatedByString:@"\n"];
|
|
109
|
+
|
|
110
|
+
// 有「简体中文」段就只取这一段:从它的标题开始,到下一个同级或更高级标题为止。
|
|
111
|
+
NSRange section = NSMakeRange(0, lines.count);
|
|
112
|
+
for (NSUInteger index = 0; index < lines.count; index++) {
|
|
113
|
+
NSString *line = [lines[index] stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
|
|
114
|
+
if (![line hasPrefix:@"#"]) continue;
|
|
115
|
+
NSUInteger level = 0;
|
|
116
|
+
while (level < line.length && [line characterAtIndex:level] == '#') level++;
|
|
117
|
+
NSString *title = [[line substringFromIndex:level]
|
|
118
|
+
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
|
|
119
|
+
if (![title isEqualToString:@"简体中文"] && ![title isEqualToString:@"中文"]) continue;
|
|
120
|
+
NSUInteger end = lines.count;
|
|
121
|
+
for (NSUInteger next = index + 1; next < lines.count; next++) {
|
|
122
|
+
NSString *candidate = lines[next];
|
|
123
|
+
if (![candidate hasPrefix:@"#"]) continue;
|
|
124
|
+
NSUInteger nextLevel = 0;
|
|
125
|
+
while (nextLevel < candidate.length && [candidate characterAtIndex:nextLevel] == '#') nextLevel++;
|
|
126
|
+
if (nextLevel <= level) { end = next; break; }
|
|
127
|
+
}
|
|
128
|
+
section = NSMakeRange(index + 1, end - index - 1);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static NSRegularExpression *bullet;
|
|
133
|
+
static dispatch_once_t once;
|
|
134
|
+
dispatch_once(&once, ^{
|
|
135
|
+
// 只认顶层列表项(行首不缩进),嵌套的子项是补充说明,挤不进三条要点。
|
|
136
|
+
bullet = [NSRegularExpression regularExpressionWithPattern:@"^(?:[-*+]|\\d+[.)])\\s+(.+)$"
|
|
137
|
+
options:0 error:nil];
|
|
138
|
+
});
|
|
139
|
+
NSMutableArray<NSString *> *items = [NSMutableArray array];
|
|
140
|
+
BOOL inFence = NO;
|
|
141
|
+
for (NSUInteger index = section.location; index < NSMaxRange(section); index++) {
|
|
142
|
+
NSString *line = lines[index];
|
|
143
|
+
if ([[line stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet] hasPrefix:@"```"]) {
|
|
144
|
+
inFence = !inFence;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (inFence) continue;
|
|
148
|
+
NSTextCheckingResult *match = [bullet firstMatchInString:line options:0
|
|
149
|
+
range:NSMakeRange(0, line.length)];
|
|
150
|
+
if (!match) continue;
|
|
151
|
+
NSString *text = StripReleaseNoteMarkdown([line substringWithRange:[match rangeAtIndex:1]]);
|
|
152
|
+
if (text.length == 0) continue;
|
|
153
|
+
if (items.count == limit) {
|
|
154
|
+
if (truncated) *truncated = YES;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (maxLength > 0 && text.length > maxLength) {
|
|
158
|
+
NSRange keep = [text rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, maxLength)];
|
|
159
|
+
text = [[text substringWithRange:keep] stringByAppendingString:@"…"];
|
|
160
|
+
}
|
|
161
|
+
[items addObject:text];
|
|
162
|
+
}
|
|
163
|
+
return items;
|
|
164
|
+
}
|
package/Sources/CCPets/PetView.h
CHANGED
|
@@ -30,6 +30,8 @@ extern NSString *const PetInteractionIntervalKey;
|
|
|
30
30
|
@property(copy) void (^dragStateChanged)(BOOL dragging);
|
|
31
31
|
@property(copy) void (^interactionPhraseRequested)(NSString *tag);
|
|
32
32
|
@property(copy) NSArray<NSDictionary *> *(^petOptionsRequested)(void);
|
|
33
|
+
// 有可安装的新版本时返回版本号,否则 nil。右键菜单据此决定要不要在顶层放「更新到 x.y.z…」。
|
|
34
|
+
@property(copy) NSString *(^pendingUpdateVersionRequested)(void);
|
|
33
35
|
@property(copy) void (^switchPetRequested)(NSString *petID);
|
|
34
36
|
@property(copy) BOOL (^deletePetRequested)(NSString *petID);
|
|
35
37
|
@property NSCache<NSString *, NSImage *> *petMenuPreviewCache;
|
package/Sources/CCPets/PetView.m
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
#import "CCPetsGlassView.h"
|
|
9
9
|
#import "MenuChoiceRow.h"
|
|
10
10
|
|
|
11
|
-
// 碎碎念频率档位的 defaults 键。定义在 CCPetsAppDelegate.m,这里只读不写;
|
|
11
|
+
// 碎碎念频率档位的 defaults 键。定义在 CCPetsAppDelegate+Speech.m,这里只读不写;
|
|
12
12
|
// 单独 extern 而不 import 那个头文件,是因为它反过来 import 了 PetView.h。
|
|
13
13
|
extern NSString *const PetSpeechFrequencyKey;
|
|
14
14
|
|
|
@@ -1750,10 +1750,22 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
1750
1750
|
action:@selector(editPhrasesFile:) keyEquivalent:@""];
|
|
1751
1751
|
editPhrases.target = NSApp.delegate;
|
|
1752
1752
|
speechItem.submenu = speechMenu;
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1753
|
+
// 检查更新和关于收进「帮助」;有新版本时在顶层临时多一项「更新到 x.y.z…」,一步就能更新,
|
|
1754
|
+
// 不必展开子菜单。气泡和角标错过了,这里仍是醒目的入口。
|
|
1755
|
+
NSString *pendingVersion = self.pendingUpdateVersionRequested ? self.pendingUpdateVersionRequested() : nil;
|
|
1756
|
+
if (pendingVersion.length > 0) {
|
|
1757
|
+
NSMenuItem *installItem = [menu addItemWithTitle:
|
|
1758
|
+
[NSString stringWithFormat:@"更新到 %@…", pendingVersion]
|
|
1759
|
+
action:@selector(showPendingUpdate:) keyEquivalent:@""];
|
|
1760
|
+
installItem.target = NSApp.delegate;
|
|
1761
|
+
}
|
|
1762
|
+
NSMenuItem *helpItem = [menu addItemWithTitle:@"帮助" action:nil keyEquivalent:@""];
|
|
1763
|
+
NSMenu *helpMenu = [NSMenu new];
|
|
1764
|
+
NSMenuItem *updateItem = [helpMenu addItemWithTitle:@"检查更新…" action:@selector(checkForUpdates:) keyEquivalent:@""];
|
|
1756
1765
|
updateItem.target = NSApp.delegate;
|
|
1766
|
+
NSMenuItem *aboutItem = [helpMenu addItemWithTitle:@"关于 CC Pets" action:@selector(showAboutPanel:) keyEquivalent:@""];
|
|
1767
|
+
aboutItem.target = NSApp.delegate;
|
|
1768
|
+
helpItem.submenu = helpMenu;
|
|
1757
1769
|
[menu addItem:NSMenuItem.separatorItem];
|
|
1758
1770
|
NSMenuItem *quitItem = [menu addItemWithTitle:@"退出桌宠" action:@selector(terminate:) keyEquivalent:@"q"];
|
|
1759
1771
|
quitItem.target = NSApp;
|
|
@@ -266,9 +266,6 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
|
266
266
|
CGFloat width = ceil(statusLine.size.width);
|
|
267
267
|
[statusLine drawInRect:NSMakeRect(rightEdge - width, y, width + 1, 20)];
|
|
268
268
|
}
|
|
269
|
-
- (NSString *)formattedTokenCountForUsage:(NSDictionary *)usage key:(NSString *)key {
|
|
270
|
-
return [self formattedTokenCount:[self tokenTotals:usage key:key] ?: @{}];
|
|
271
|
-
}
|
|
272
269
|
- (NSString *)formattedTokenSplitForUsage:(NSDictionary *)usage key:(NSString *)key
|
|
273
270
|
wantsOutput:(BOOL)wantsOutput {
|
|
274
271
|
return [self formattedTokenSplit:[self tokenTotals:usage key:key] ?: @{}
|
package/Sources/CCPets/main.m
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#import "CCPetsAppDelegate.h"
|
|
3
3
|
#import "CCPetsEvents.h"
|
|
4
4
|
#import "CCPetsPaths.h"
|
|
5
|
+
#import "CCPetsPhrases.h"
|
|
5
6
|
#import "CCPetsPreviews.h"
|
|
6
7
|
#import "CCPetsQuotaHistory.h"
|
|
7
8
|
#import "CCPetsUsage.h"
|
|
@@ -48,6 +49,18 @@ int main(int argc, const char *argv[]) {
|
|
|
48
49
|
if (argc > 1 && strcmp(argv[1], "--codex-launch") == 0) return RegisterCodexLaunch();
|
|
49
50
|
if (argc > 1 && strcmp(argv[1], "--clean") == 0) return CleanCCPetsData(NO);
|
|
50
51
|
if (argc > 1 && strcmp(argv[1], "--purge-data") == 0) return CleanCCPetsData(YES);
|
|
52
|
+
if (argc > 1 && strcmp(argv[1], "--paths") == 0) {
|
|
53
|
+
NSMutableDictionary *paths = [CCPetsDataPaths() mutableCopy];
|
|
54
|
+
paths[@"phrases"] = PetPhrasesFilePath();
|
|
55
|
+
paths[@"petPhrases"] = PetPhrasesPetDirectory();
|
|
56
|
+
NSData *json = [NSJSONSerialization dataWithJSONObject:paths
|
|
57
|
+
options:NSJSONWritingPrettyPrinted | NSJSONWritingSortedKeys | NSJSONWritingWithoutEscapingSlashes
|
|
58
|
+
error:nil];
|
|
59
|
+
if (!json) return EXIT_FAILURE;
|
|
60
|
+
fwrite(json.bytes, 1, json.length, stdout);
|
|
61
|
+
fputc('\n', stdout);
|
|
62
|
+
return EXIT_SUCCESS;
|
|
63
|
+
}
|
|
51
64
|
if (argc > 1 && strcmp(argv[1], "--history") == 0) {
|
|
52
65
|
NSData *json = [NSJSONSerialization dataWithJSONObject:QuotaHistoryDocument()
|
|
53
66
|
options:NSJSONWritingPrettyPrinted error:nil];
|
package/bin/cc-pets
CHANGED
|
@@ -16,10 +16,12 @@ print_usage() {
|
|
|
16
16
|
cc-pets 启动桌宠(优先使用 ~/Applications 里安装的版本)
|
|
17
17
|
cc-pets install 安装或修复 shell / Claude Code / Codex 集成
|
|
18
18
|
cc-pets uninstall 移除集成并恢复 status line
|
|
19
|
-
cc-pets uninstall --purge 同时删除 App
|
|
19
|
+
cc-pets uninstall --purge 同时删除 App、应用数据和偏好(会先确认;保留 ~/.cc-pets 的素材与台词)
|
|
20
20
|
cc-pets uninstall-app 只删除 ~/Applications/CC Pets.app
|
|
21
21
|
cc-pets build 重新构建
|
|
22
22
|
cc-pets clean 清理缓存(需先退出桌宠)
|
|
23
|
+
cc-pets doctor 检查安装与各项集成是否正常,并给出修复建议
|
|
24
|
+
cc-pets paths [--json] 列出配置、缓存与数据的存放位置和大小
|
|
23
25
|
cc-pets pet <命令> 管理桌宠素材,详见 cc-pets pet help
|
|
24
26
|
cc-pets bridge <命令> CC Bridge 跨会话消息,详见 cc-pets bridge --help
|
|
25
27
|
cc-pets --status 输出 Codex 当前额度
|
|
@@ -51,6 +53,10 @@ if [[ "${1:-}" == "bridge" ]]; then
|
|
|
51
53
|
exec node "${PROJECT_DIR}/scripts/bridge/cli.mjs" "$@"
|
|
52
54
|
fi
|
|
53
55
|
|
|
56
|
+
if [[ "${1:-}" == "doctor" || "${1:-}" == "paths" ]]; then
|
|
57
|
+
exec node "${PROJECT_DIR}/scripts/doctor.mjs" "$@"
|
|
58
|
+
fi
|
|
59
|
+
|
|
54
60
|
if [[ "${1:-}" == "uninstall" ]]; then
|
|
55
61
|
shift
|
|
56
62
|
# --purge / --yes 要传下去;原先这里吞掉了参数,README 里的 uninstall --purge 实际不生效。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-pets",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "A native macOS desktop pet for Codex CLI and Claude Code",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Sunnyshiny",
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
"test": "./tests/test.sh",
|
|
63
63
|
"version": "npm test",
|
|
64
64
|
"postinstall": "./scripts/install-shell-integration.sh",
|
|
65
|
-
"prepack": "npm test"
|
|
65
|
+
"prepack": "npm test",
|
|
66
|
+
"prepublish:check": "npm whoami && if npm view $npm_package_name@$npm_package_version version 2>/dev/null | grep -q .; then echo \"error: $npm_package_name@$npm_package_version is already published; bump the version first\" >&2; exit 1; fi && npm publish --dry-run"
|
|
66
67
|
},
|
|
67
68
|
"publishConfig": {
|
|
68
69
|
"access": "public"
|
package/scripts/bridge/cli.mjs
CHANGED
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
describeSession, identifySelf, liveSessions, receiptSummary, resolveTarget, sendIdleNotices,
|
|
9
9
|
sendMessage, formatEnvelope
|
|
10
10
|
} from "./core.mjs";
|
|
11
|
-
import { install, uninstall } from "./install.mjs";
|
|
11
|
+
import { describeCodexQueue, install, uninstall } from "./install.mjs";
|
|
12
|
+
import { probeCodexQueue } from "./process.mjs";
|
|
13
|
+
import { detectCodexCLI } from "../detect-cli.mjs";
|
|
12
14
|
import { DEFAULT_OPTIONS, currentOptions, describeOptions, mergeOptionFlags, normalizeOptions } from "./options.mjs";
|
|
13
15
|
import { fileURLToPath } from "node:url";
|
|
14
16
|
import { activeReservations, describeReservation } from "./reservations.mjs";
|
|
@@ -127,7 +129,12 @@ const commands = {
|
|
|
127
129
|
|
|
128
130
|
async status() {
|
|
129
131
|
console.log(`CC Bridge:${isBridgeEnabled() ? "已开启" : "未开启"}`);
|
|
130
|
-
if (isBridgeEnabled())
|
|
132
|
+
if (isBridgeEnabled()) {
|
|
133
|
+
for (const line of describeOptions(currentOptions())) console.log(` ${line}`);
|
|
134
|
+
if (currentOptions().wake && detectCodexCLI()) {
|
|
135
|
+
console.log(` ${describeCodexQueue(probeCodexQueue()) ?? "Codex 支持 codex queue,可自动唤醒。"}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
131
138
|
console.log(`状态目录:${bridgeDirectory()}`);
|
|
132
139
|
printSessions();
|
|
133
140
|
const reservations = activeReservations();
|
package/scripts/bridge/core.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// CC Bridge 的业务逻辑:身份识别、目标解析、消息封装、按目标 CLI 选择投递方式。
|
|
2
2
|
//
|
|
3
|
-
//
|
|
3
|
+
// 投递路径(均为官方公开机制):
|
|
4
4
|
// - 目标是 Codex:`codex queue --thread <id> --message <text>`。空闲时立即唤醒,忙碌时
|
|
5
5
|
// 排到当前回合之后。发给已关闭会话的消息会被 Codex 持久化并在 resume 时自动执行,
|
|
6
6
|
// 所以投递前必须确认目标在线。
|
|
@@ -13,7 +13,7 @@ import path from "node:path";
|
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { detectClaudeCLI, detectCodexCLI } from "../detect-cli.mjs";
|
|
15
15
|
import { DEFAULT_OPTIONS, normalizeOptions } from "./options.mjs";
|
|
16
|
-
import { resolveRealExecutable } from "./process.mjs";
|
|
16
|
+
import { probeCodexQueue, resolveRealExecutable } from "./process.mjs";
|
|
17
17
|
|
|
18
18
|
export const HOOK_MARKER = "CC_BRIDGE_HOOK=";
|
|
19
19
|
export const MCP_NAME = "cc-bridge";
|
|
@@ -221,6 +221,23 @@ const setCodexApproval = (tools) => {
|
|
|
221
221
|
|
|
222
222
|
// ---------------------------------------------------------------------------
|
|
223
223
|
|
|
224
|
+
// 自动唤醒 Codex 依赖 `codex queue`。不支持时 CC Bridge 照样能用(消息进信箱),只是对方要
|
|
225
|
+
// check_inbox 或等下次输入才收到,开启时就说清楚,免得用户以为"发了没反应"。
|
|
226
|
+
export const describeCodexQueue = (probe) => {
|
|
227
|
+
const version = probe.version ? `(${probe.version})` : "";
|
|
228
|
+
switch (probe.status) {
|
|
229
|
+
case "supported":
|
|
230
|
+
return null;
|
|
231
|
+
case "unsupported":
|
|
232
|
+
return `当前 Codex${version} 不支持 codex queue:发给 Codex 的消息无法自动唤醒对方,会先进信箱,` +
|
|
233
|
+
"由对方调用 check_inbox 或在下次输入时带入。升级 Codex 后即可自动唤醒,无需重新开启。";
|
|
234
|
+
case "missing":
|
|
235
|
+
return "未找到 codex 可执行文件,发给 Codex 的消息只能进信箱;可设置 CODEX_REAL_BIN 后执行 cc-pets bridge enable。";
|
|
236
|
+
default:
|
|
237
|
+
return "无法确认 Codex 是否支持 codex queue;投递失败时会自动退回信箱。";
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
224
241
|
// registerMcp=false 用于只改选项(桌宠开关、cc-pets bridge configure):不必重跑 claude / codex mcp add。
|
|
225
242
|
export const install = ({ options: rawOptions = DEFAULT_OPTIONS, registerMcp = process.env.CC_BRIDGE_SKIP_MCP !== "1" } = {}) => {
|
|
226
243
|
const options = normalizeOptions(rawOptions);
|
|
@@ -256,6 +273,11 @@ export const install = ({ options: rawOptions = DEFAULT_OPTIONS, registerMcp = p
|
|
|
256
273
|
report.push(ok
|
|
257
274
|
? `Codex MCP 已注册:${MCP_NAME}`
|
|
258
275
|
: `Codex MCP 注册失败,请手动执行:codex ${codexMcpAddArgs().map(shellQuote).join(" ")}`);
|
|
276
|
+
// 只在 enable / refresh 时探测:configure 由桌宠菜单开关触发,不值得每次多拉起两次 codex。
|
|
277
|
+
if (options.wake) {
|
|
278
|
+
const queueNotice = describeCodexQueue(probeCodexQueue(codex));
|
|
279
|
+
if (queueNotice) report.push(queueNotice);
|
|
280
|
+
}
|
|
259
281
|
}
|
|
260
282
|
setCodexApproval(options.codexApprove);
|
|
261
283
|
report.push(options.codexApprove.length > 0
|
|
@@ -127,3 +127,25 @@ export const resolveRealExecutable = (name, realBinVariable) => {
|
|
|
127
127
|
}
|
|
128
128
|
return null;
|
|
129
129
|
};
|
|
130
|
+
|
|
131
|
+
// `codex queue` 是较新的 Codex 才有的子命令。旧版本把不认识的子命令当成交互式启动参数,
|
|
132
|
+
// `--help` 打出的是总帮助而不是报错,所以按帮助里有没有 --thread / --message 判断。
|
|
133
|
+
// 结果只用于提前提示:投递时 queue 失败本来就会退回信箱(core.mjs 的 deliver),
|
|
134
|
+
// 探测失败(超时、找不到 codex)一律算 unknown,不能因此拒绝开启 CC Bridge。
|
|
135
|
+
export const probeCodexQueue = (executable = resolveRealExecutable("codex", "CODEX_REAL_BIN")) => {
|
|
136
|
+
if (!executable || !fs.existsSync(executable)) return { status: "missing", executable: executable ?? null, version: null };
|
|
137
|
+
const run = (args) => {
|
|
138
|
+
try {
|
|
139
|
+
return execFileSync(executable, args,
|
|
140
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 10_000 });
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error.code === "ETIMEDOUT" || error.code === "ENOENT" || error.code === "EACCES") return null;
|
|
143
|
+
return `${error.stdout || ""}${error.stderr || ""}`;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const version = (run(["--version"]) || "").trim().split("\n")[0] || null;
|
|
147
|
+
const help = run(["queue", "--help"]);
|
|
148
|
+
if (help === null) return { status: "unknown", executable, version };
|
|
149
|
+
const supported = help.includes("--thread") && help.includes("--message");
|
|
150
|
+
return { status: supported ? "supported" : "unsupported", executable, version };
|
|
151
|
+
};
|