cc-pets 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +63 -7
- package/CC_BRIDGE.zh-CN.md +43 -5
- package/CHANGELOG.md +106 -0
- package/CHANGELOG.zh-CN.md +106 -0
- package/CONTRIBUTING.md +23 -1
- package/CONTRIBUTING.zh-CN.md +18 -1
- package/PROVIDER_PROTOCOL.md +5 -1
- package/PROVIDER_PROTOCOL.zh-CN.md +4 -1
- package/README.md +177 -33
- package/README.zh-CN.md +137 -32
- package/Resources/AgentIcons/claude.png +0 -0
- package/Resources/AgentIcons/codex.icns +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.vsix +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.zip +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +187 -35
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +47 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +121 -20
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +8 -6
- package/Sources/CCPets/App/CCPetsAppDelegate+MenuBar.m +86 -0
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +14 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +6 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +3 -6
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +118 -50
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +4 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +4 -0
- package/Sources/CCPets/App/CCPetsAppDelegate.h +12 -2
- package/Sources/CCPets/App/CCPetsAppDelegate.m +4 -2
- package/Sources/CCPets/App/main.m +6 -0
- package/Sources/CCPets/Bridge/CCPetsBridge.m +45 -18
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +175 -68
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +14 -6
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +356 -110
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +0 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +247 -126
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +37 -9
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +385 -80
- package/Sources/CCPets/Integrations/CCPetsEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.m +68 -12
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.h +21 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.m +503 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +1 -1
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +367 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +8 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +156 -25
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.m +64 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.h +23 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.m +475 -0
- package/Sources/CCPets/Pet/CCPetsPhrasesEditor.m +7 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +11 -3
- package/Sources/CCPets/Pet/PetView.h +7 -0
- package/Sources/CCPets/Pet/PetView.m +12 -1
- package/Sources/CCPets/Support/CCPetsDoctor.m +26 -12
- package/Sources/CCPets/Support/CCPetsPreferences.h +12 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +52 -2
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +2 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +18 -7
- package/Sources/CCPets/UI/CCPetsGlassView.h +26 -4
- package/Sources/CCPets/UI/CCPetsGlassView.m +40 -9
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.h +16 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.m +70 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.h +18 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +528 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.h +51 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +95 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +6 -1
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +577 -66
- package/Sources/CCPets/UI/CCPetsStatusItem.h +28 -0
- package/Sources/CCPets/UI/CCPetsStatusItem.m +147 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +5 -2
- package/Sources/CCPets/UI/CCPetsUIStyle.m +57 -8
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +4 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +23 -28
- package/Sources/CCPets/UI/CCPetsUsageStore.m +2 -2
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +5 -3
- package/Sources/CCPets/Usage/CCPetsUsage+CodexBackground.m +193 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +1 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +49 -11
- package/Sources/CCPets/Usage/CCPetsUsage.h +3 -2
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +15 -17
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +11 -29
- package/Sources/CCPets/Usage/QuotaDashboardView.m +128 -2
- package/THIRD_PARTY_NOTICES.md +7 -3
- package/THIRD_PARTY_NOTICES.zh-CN.md +5 -1
- package/bin/claude-with-pet +2 -0
- package/bin/codex-with-pet +2 -0
- package/package.json +5 -1
- package/plugins/jetbrains/README.md +62 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalBridge.java +379 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalIdentity.java +24 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalStartup.java +12 -0
- package/plugins/jetbrains/src/main/resources/META-INF/plugin.xml +23 -0
- package/plugins/jetbrains/src/main/resources/META-INF/pluginIcon.svg +380 -0
- package/plugins/vscode/README.md +63 -0
- package/plugins/vscode/extension.js +210 -0
- package/plugins/vscode/package.json +18 -0
- package/scripts/build-idea-plugin.sh +101 -0
- package/scripts/build-vscode-extension.sh +112 -0
- package/scripts/build.sh +24 -2
- package/scripts/compile-cached.zsh +133 -0
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
// Agent 事件的记录与状态归一化,同时是 --hook / --provider-event 两个子命令的实现。
|
|
4
4
|
NSString *SanitizedShortString(id value, NSUInteger maximumLength);
|
|
5
|
+
// 账号 ID 是标识符而非展示文字:保留冒号,并修复旧事件中 provider:hash 丢失冒号的格式。
|
|
6
|
+
NSString *NormalizedAgentProfileID(id value);
|
|
7
|
+
NSString *SanitizedWorkingDirectory(id value);
|
|
8
|
+
// 状态卡标题里的会话标签:优先 CC Bridge 短名,其次目录名;过长时保留末尾的动物后缀。
|
|
9
|
+
NSString *StatusSessionLabel(NSString *bridgeName, NSString *cwd);
|
|
5
10
|
NSString *ProviderFromEnvironment(void);
|
|
6
11
|
NSString *NormalizedStateForEvent(NSString *event, BOOL failed);
|
|
7
12
|
// 在线会话的 key:provider + 账号 + tty。同一个终端先后跑过两个账号时,只看 provider + tty
|
|
@@ -20,6 +20,47 @@ NSString *SanitizedShortString(id value, NSUInteger maximumLength) {
|
|
|
20
20
|
return [safe stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
NSString *NormalizedAgentProfileID(id value) {
|
|
24
|
+
if (![value isKindOfClass:NSString.class]) return @"";
|
|
25
|
+
NSString *identifier = [value stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
26
|
+
NSCharacterSet *allowed = [NSCharacterSet characterSetWithCharactersInString:
|
|
27
|
+
@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-:"];
|
|
28
|
+
// 拒绝非法标识,不能删除字符后误认成另一个账号。
|
|
29
|
+
if (identifier.length == 0 || identifier.length > 128 ||
|
|
30
|
+
[identifier rangeOfCharacterFromSet:allowed.invertedSet].location != NSNotFound) return @"";
|
|
31
|
+
NSRegularExpression *legacy = [NSRegularExpression regularExpressionWithPattern:
|
|
32
|
+
@"\\A(codex|claude)([0-9a-f]{16})\\z" options:0 error:nil];
|
|
33
|
+
return [legacy stringByReplacingMatchesInString:identifier options:0
|
|
34
|
+
range:NSMakeRange(0, identifier.length) withTemplate:@"$1:$2"];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 工作目录只用于状态卡上的会话标签和悬停提示。路径里可以有中文和空格,所以不走
|
|
38
|
+
// SanitizedShortString 的白名单;只收绝对路径,挡掉控制字符和离谱的长度。
|
|
39
|
+
NSString *SanitizedWorkingDirectory(id value) {
|
|
40
|
+
if (![value isKindOfClass:NSString.class]) return @"";
|
|
41
|
+
NSString *path = [(NSString *)value stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
42
|
+
if (path.length == 0 || path.length > 1024 || ![path hasPrefix:@"/"]) return @"";
|
|
43
|
+
if ([path rangeOfCharacterFromSet:NSCharacterSet.controlCharacterSet].location != NSNotFound) return @"";
|
|
44
|
+
return path;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 状态卡标题里的会话标签:有 CC Bridge 短名(目录名.动物)就用它,否则退回目录名。
|
|
48
|
+
// 卡片很窄,超过 20 个字符时截掉中间,保留末尾的动物后缀——同目录的多个会话全靠它区分。
|
|
49
|
+
NSString *StatusSessionLabel(NSString *bridgeName, NSString *cwd) {
|
|
50
|
+
static const NSUInteger limit = 20;
|
|
51
|
+
NSString *label = bridgeName.length > 0 ? bridgeName : cwd.lastPathComponent;
|
|
52
|
+
if (label.length == 0 || [label isEqualToString:@"/"]) return @"";
|
|
53
|
+
if (label.length <= limit) return label;
|
|
54
|
+
NSRange dot = [label rangeOfString:@"." options:NSBackwardsSearch];
|
|
55
|
+
NSString *suffix = dot.location != NSNotFound && dot.location > 0 && label.length - dot.location <= 9
|
|
56
|
+
? [label substringFromIndex:dot.location] : @"";
|
|
57
|
+
NSUInteger keep = limit - 1 - suffix.length;
|
|
58
|
+
// 按完整字符截断,免得把中文目录名或 emoji 切成半个。
|
|
59
|
+
NSRange head = [label rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, keep)];
|
|
60
|
+
if (head.length > keep) head = [label rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, keep - 1)];
|
|
61
|
+
return [NSString stringWithFormat:@"%@…%@", [label substringWithRange:head], suffix];
|
|
62
|
+
}
|
|
63
|
+
|
|
23
64
|
NSString *ProviderFromEnvironment(void) {
|
|
24
65
|
NSDictionary<NSString *, NSString *> *environment = NSProcessInfo.processInfo.environment;
|
|
25
66
|
if ([environment[@"CC_PETS_CODEX_AGENT_HOOK"] boolValue]) return @"Codex";
|
|
@@ -91,7 +132,7 @@ NSString *NormalizedStateForEvent(NSString *event, BOOL failed) {
|
|
|
91
132
|
|
|
92
133
|
NSString *OnlineAgentSessionKey(id provider, id profileID, id tty) {
|
|
93
134
|
NSString *providerName = SanitizedShortString(provider, 32);
|
|
94
|
-
NSString *profile =
|
|
135
|
+
NSString *profile = NormalizedAgentProfileID(profileID);
|
|
95
136
|
// 先取末段再清洗:清洗会去掉 "/","/dev/ttys003" 就成了 "devttys003"。
|
|
96
137
|
NSString *ttyName = [tty isKindOfClass:NSString.class]
|
|
97
138
|
? SanitizedShortString([(NSString *)tty lastPathComponent], 64) : @"";
|
|
@@ -189,19 +230,18 @@ int RecordHookEvent(void) {
|
|
|
189
230
|
if (![payload isKindOfClass:NSDictionary.class]) return EXIT_SUCCESS;
|
|
190
231
|
NSString *event = payload[@"hook_event_name"];
|
|
191
232
|
if (![event isKindOfClass:NSString.class] || event.length == 0) return EXIT_SUCCESS;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
233
|
+
NSString *provider = ProviderFromEnvironment();
|
|
234
|
+
NSDictionary *terminal = TerminalFocusTargetForHook(payload, provider);
|
|
235
|
+
BOOL lifecycle = [event isEqualToString:@"SessionStart"] || [event isEqualToString:@"SessionEnd"];
|
|
236
|
+
// 桌面会话不经过 CLI 包装器,必须记录生命周期,但消费端不播报任务完成。
|
|
237
|
+
// Codex 的结束事件即使缺少回跳目标也要保留,以 session_id 清理记录。
|
|
238
|
+
if (lifecycle && !([provider isEqualToString:@"Codex"] &&
|
|
239
|
+
(IsCodexDesktopFocusTarget(terminal) || [event isEqualToString:@"SessionEnd"]))) return EXIT_SUCCESS;
|
|
199
240
|
NSString *tool = [payload[@"tool_name"] isKindOfClass:NSString.class] ? payload[@"tool_name"] : @"";
|
|
200
241
|
NSString *session = SanitizedShortString(payload[@"session_id"], 128);
|
|
201
242
|
id toolResult = payload[@"tool_response"] ?: payload[@"tool_result"];
|
|
202
243
|
BOOL failed = [event isEqualToString:@"PostToolUseFailure"] ||
|
|
203
244
|
[event isEqualToString:@"StopFailure"] || HookValueIndicatesFailure(toolResult);
|
|
204
|
-
NSString *provider = ProviderFromEnvironment();
|
|
205
245
|
BOOL autoReview = [provider isEqualToString:@"Codex"] &&
|
|
206
246
|
[event isEqualToString:@"PermissionRequest"] && CodexAutoReviewEnabled();
|
|
207
247
|
NSMutableDictionary *record = [@{
|
|
@@ -213,12 +253,24 @@ int RecordHookEvent(void) {
|
|
|
213
253
|
@"timestamp": @([NSDate.date timeIntervalSince1970])
|
|
214
254
|
} mutableCopy];
|
|
215
255
|
if (session.length > 0) record[@"session"] = session;
|
|
216
|
-
NSString *
|
|
256
|
+
NSString *cwd = SanitizedWorkingDirectory(payload[@"cwd"]);
|
|
257
|
+
if (cwd.length > 0) record[@"cwd"] = cwd;
|
|
258
|
+
NSString *profileID = NormalizedAgentProfileID(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_ID"]);
|
|
217
259
|
NSString *profileName = SanitizedShortString(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_NAME"], 64);
|
|
218
260
|
if (profileID.length > 0) record[@"profileId"] = profileID;
|
|
219
261
|
if (profileName.length > 0) record[@"profileName"] = profileName;
|
|
220
|
-
NSDictionary *terminal = TerminalFocusTargetForHook(payload, provider);
|
|
221
262
|
if (terminal.count > 0) record[@"terminal"] = terminal;
|
|
263
|
+
if ([provider isEqualToString:@"Codex"]) {
|
|
264
|
+
// 不记录 prompt;只保存会话是否有转录,区分桌面后台临时任务与真实聊天。
|
|
265
|
+
id transcript = payload[@"transcript_path"];
|
|
266
|
+
if (transcript == NSNull.null) record[@"transient"] = @YES;
|
|
267
|
+
else if ([transcript isKindOfClass:NSString.class] && [transcript length] > 0) {
|
|
268
|
+
record[@"transcriptPath"] = transcript;
|
|
269
|
+
}
|
|
270
|
+
NSString *home = NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_HOME"]
|
|
271
|
+
?: NSProcessInfo.processInfo.environment[@"CODEX_HOME"] ?: DefaultCodexHomeDirectory();
|
|
272
|
+
if (home.isAbsolutePath) record[@"codexHome"] = home;
|
|
273
|
+
}
|
|
222
274
|
AppendAgentEventRecord(record);
|
|
223
275
|
return EXIT_SUCCESS;
|
|
224
276
|
}
|
|
@@ -264,7 +316,11 @@ int RecordProviderEvent(void) {
|
|
|
264
316
|
@"state": state,
|
|
265
317
|
@"timestamp": @([NSDate.date timeIntervalSince1970])
|
|
266
318
|
} mutableCopy];
|
|
267
|
-
|
|
319
|
+
// 包装脚本的启动事件没有 Hook payload,从调用进程继承的目录补齐会话标签。
|
|
320
|
+
NSString *cwd = SanitizedWorkingDirectory(payload[@"cwd"]);
|
|
321
|
+
if (cwd.length == 0) cwd = SanitizedWorkingDirectory(NSFileManager.defaultManager.currentDirectoryPath);
|
|
322
|
+
if (cwd.length > 0) record[@"cwd"] = cwd;
|
|
323
|
+
NSString *profileID = NormalizedAgentProfileID(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_ID"]);
|
|
268
324
|
NSString *profileName = SanitizedShortString(NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_NAME"], 64);
|
|
269
325
|
if (profileID.length > 0) record[@"profileId"] = profileID;
|
|
270
326
|
if (profileName.length > 0) record[@"profileName"] = profileName;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#import <Cocoa/Cocoa.h>
|
|
2
|
+
|
|
3
|
+
// Snapshot (disk + authenticated loopback queries): call off the main thread.
|
|
4
|
+
// state: connected / installed / pendingRestart / outdated / missing / disabled / unsupported.
|
|
5
|
+
// autoInstall is YES when the plugin folder is known well enough to install into it.
|
|
6
|
+
NSArray<NSDictionary *> *CCPetsIDEIntegrationSnapshot(void);
|
|
7
|
+
// Installs or updates the bundled plugin into one snapshot row's plugin folder. Blocking.
|
|
8
|
+
BOOL CCPetsInstallIDEPlugin(NSDictionary *ide, NSError **error);
|
|
9
|
+
// Confirms, installs in the background and reports failures; falls back to the manual
|
|
10
|
+
// installer when autoInstall is NO. completion runs on the main thread.
|
|
11
|
+
void CCPetsPromptInstallIDEPlugin(NSDictionary *ide, void (^completion)(void));
|
|
12
|
+
// Schedules exact focus without blocking AppKit. NO means this is not a JetBrains IDE target.
|
|
13
|
+
BOOL CCPetsRequestIDETerminalFocus(NSDictionary *target);
|
|
14
|
+
// Reveals the bundled ZIP and explains the IDE's own install-from-disk workflow.
|
|
15
|
+
void CCPetsShowIDEPluginInstaller(void);
|
|
16
|
+
|
|
17
|
+
// Shared with other IDE bridges (VS Code). Registrations live in
|
|
18
|
+
// ~/Library/Application Support/CC Pets/ide-instances/; accept filters validated records
|
|
19
|
+
// whose pid belongs to a running app at record[@"appPath"]. Both block: call off main.
|
|
20
|
+
NSArray<NSDictionary *> *CCPetsIDEBridgeInstances(BOOL (^accept)(NSDictionary *record, NSRunningApplication *app));
|
|
21
|
+
NSDictionary *CCPetsIDEBridgeRequest(NSDictionary *instance, NSString *route, NSDictionary *body);
|