cc-pets 2.2.1 → 2.4.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 +24 -2
- package/CC_BRIDGE.zh-CN.md +19 -2
- package/CHANGELOG.md +111 -0
- package/CHANGELOG.zh-CN.md +111 -0
- package/CONTRIBUTING.md +35 -10
- package/CONTRIBUTING.zh-CN.md +28 -10
- package/README.md +212 -32
- package/README.zh-CN.md +167 -36
- 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 +699 -20
- package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
- package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +90 -25
- package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
- package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +17 -3
- package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +71 -23
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
- package/Sources/CCPets/{CCPetsAppDelegate+Settings.m → App/CCPetsAppDelegate+Settings.m} +87 -102
- package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +121 -51
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
- package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +17 -2
- package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +107 -11
- package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
- package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
- package/Sources/CCPets/{main.m → App/main.m} +74 -1
- package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
- package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +43 -23
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +832 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +59 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +576 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +507 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +106 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +897 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
- package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.h +21 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.m +503 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +367 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
- package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +2 -1
- package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +148 -36
- 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/CCPetsPetStore.h +12 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
- package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +11 -2
- package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +19 -2
- package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +4 -1
- package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
- package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
- package/Sources/CCPets/Pet/PetView+Private.h +81 -0
- package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
- package/Sources/CCPets/Pet/PetView.m +635 -0
- package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
- package/Sources/CCPets/Support/CCPetsDoctor.m +646 -0
- package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
- package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
- package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
- package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
- package/Sources/CCPets/Support/CCPetsPreferences.h +33 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +117 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +44 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +279 -0
- package/Sources/CCPets/UI/CCPetsGlassView.h +57 -0
- package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +60 -11
- package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
- package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +64 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +1412 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +135 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +865 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +288 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +712 -0
- package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
- package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
- package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
- package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
- package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
- package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexBackground.m +193 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +97 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +323 -0
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
- package/Sources/CCPets/Usage/CCPetsUsage.h +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +174 -19
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +598 -0
- package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
- package/Sources/CCPets/Usage/QuotaDashboardView.m +713 -0
- package/THIRD_PARTY_NOTICES.md +8 -4
- package/THIRD_PARTY_NOTICES.zh-CN.md +6 -2
- package/bin/cc-pets +8 -6
- package/bin/claude-with-pet +12 -2
- package/bin/codex-with-pet +15 -5
- 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 +31 -5
- package/scripts/compile-cached.zsh +133 -0
- package/scripts/i18n.zsh +9 -52
- package/scripts/install-app.sh +4 -0
- package/scripts/install-shell-integration.sh +17 -10
- package/scripts/uninstall-shell-integration.sh +6 -1
- package/Sources/CCPets/CCPetsEvents.h +0 -10
- package/Sources/CCPets/CCPetsGlassView.h +0 -31
- package/Sources/CCPets/CCPetsUsage.h +0 -36
- package/Sources/CCPets/CCPetsUsage.m +0 -2069
- package/Sources/CCPets/PetView.m +0 -1839
- package/Sources/CCPets/QuotaDashboardView.m +0 -1145
- package/scripts/bridge/cli.mjs +0 -237
- package/scripts/bridge/core.mjs +0 -228
- package/scripts/bridge/hook.mjs +0 -150
- package/scripts/bridge/install.mjs +0 -311
- package/scripts/bridge/mcp-server.mjs +0 -308
- package/scripts/bridge/options.mjs +0 -87
- package/scripts/bridge/process.mjs +0 -151
- package/scripts/bridge/reservations.mjs +0 -248
- package/scripts/bridge/store.mjs +0 -433
- package/scripts/bridge/watch.mjs +0 -69
- package/scripts/check-l10n.mjs +0 -168
- package/scripts/configure-updater.mjs +0 -43
- package/scripts/detect-cli.mjs +0 -68
- package/scripts/doctor.mjs +0 -470
- package/scripts/i18n.mjs +0 -122
- package/scripts/install-claude-hooks.mjs +0 -253
- package/scripts/install-codex-hooks.mjs +0 -78
- package/scripts/integration-markers.mjs +0 -51
- package/scripts/locales/zh-Hans.json +0 -366
- package/scripts/pet-store.mjs +0 -415
- package/scripts/uninstall-integrations.mjs +0 -205
- /package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.h → Pet/CCPetsImageLoader.h} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.h → Pet/CCPetsPetSize.h} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.m → Pet/CCPetsPetSize.m} +0 -0
- /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
- /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +0 -0
- /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.h → UI/MenuPetSizeView.h} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.m → UI/MenuPetSizeView.m} +0 -0
- /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m}
RENAMED
|
@@ -162,13 +162,15 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
|
|
|
162
162
|
NSArray<NSString *> *entries = [NSFileManager.defaultManager contentsOfDirectoryAtPath:clientDirectory error:nil] ?: @[];
|
|
163
163
|
NSInteger liveClients = 0;
|
|
164
164
|
NSMutableSet<NSString *> *providers = [NSMutableSet set];
|
|
165
|
+
NSMutableSet<NSString *> *profileIDs = [NSMutableSet set];
|
|
166
|
+
NSMutableSet<NSString *> *unscopedProviders = [NSMutableSet set];
|
|
165
167
|
NSMutableSet<NSString *> *sessionKeys = [NSMutableSet set];
|
|
166
168
|
BOOL unlabeled = NO;
|
|
167
169
|
for (NSString *entry in entries) {
|
|
168
170
|
pid_t pid = (pid_t)entry.intValue;
|
|
169
171
|
NSString *path = [clientDirectory stringByAppendingPathComponent:entry];
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
+
// 包装脚本依次写 provider、TTY、profileId。旧版只有前两行,1.0.2 及更早
|
|
173
|
+
// 只 touch 出空文件;升级后仍在运行的老客户端按缺失层级逐级回退,避免
|
|
172
174
|
// “身份不明”,只要还有一个就不清场,避免把仍然活着的会话误判成已退出。
|
|
173
175
|
NSString *contents = [NSString stringWithContentsOfFile:path
|
|
174
176
|
encoding:NSUTF8StringEncoding error:nil] ?: @"";
|
|
@@ -178,14 +180,20 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
|
|
|
178
180
|
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
179
181
|
NSString *tty = lines.count > 1 ? [lines[1]
|
|
180
182
|
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] : @"";
|
|
183
|
+
NSString *profileID = lines.count > 2 ? [lines[2]
|
|
184
|
+
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] : @"";
|
|
181
185
|
if (!ClientProcessAlive(pid, tty)) {
|
|
182
186
|
[NSFileManager.defaultManager removeItemAtPath:path error:nil];
|
|
183
187
|
continue;
|
|
184
188
|
}
|
|
185
189
|
liveClients += 1;
|
|
186
|
-
if (label.length > 0 && label.length <= 32)
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
if (label.length > 0 && label.length <= 32) {
|
|
191
|
+
[providers addObject:label];
|
|
192
|
+
if (profileID.length > 0 && profileID.length <= 128) [profileIDs addObject:profileID];
|
|
193
|
+
else [unscopedProviders addObject:label];
|
|
194
|
+
} else unlabeled = YES;
|
|
195
|
+
NSString *sessionKey = OnlineAgentSessionKey(label,
|
|
196
|
+
profileID.length <= 128 ? profileID : nil, tty);
|
|
189
197
|
if (sessionKey.length > 0) [sessionKeys addObject:sessionKey];
|
|
190
198
|
}
|
|
191
199
|
// 包装脚本启动的客户端有精确的退出信号:pid 文件被回收。这一段不该被为"直接跑
|
|
@@ -195,6 +203,8 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
|
|
|
195
203
|
NSSet<NSString *> *previousProviders = self.liveClientProviders;
|
|
196
204
|
self.liveClientCount = liveClients;
|
|
197
205
|
self.liveClientProviders = providers;
|
|
206
|
+
self.liveClientProfileIDs = profileIDs;
|
|
207
|
+
self.liveUnscopedClientProviders = unscopedProviders;
|
|
198
208
|
self.liveAgentSessionKeys = sessionKeys;
|
|
199
209
|
self.hasUnlabeledClient = unlabeled;
|
|
200
210
|
[self pruneOfflineAgentSessionRecords];
|
package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m}
RENAMED
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
// 会不断把这 60 秒重置掉——用户关掉所有 Codex 窗口后仍然看到“Codex 正在启动”。
|
|
137
137
|
- (void)hideAgentStatusIfClientGone {
|
|
138
138
|
if (!self.hasAgentStatus || self.hasUnlabeledClient) return;
|
|
139
|
-
NSString *provider = self.
|
|
139
|
+
NSString *provider = self.lastStatusAgentProvider;
|
|
140
140
|
if (provider.length == 0 || [self.liveClientProviders containsObject:provider]) return;
|
|
141
141
|
// 不经包装脚本启动的客户端(直接跑 claude / codex)没有 pid 文件,只能靠
|
|
142
142
|
// “最近还在发事件”证明自己活着,所以这里必须留一段静默宽限再清。
|
|
@@ -171,21 +171,24 @@
|
|
|
171
171
|
if (record.count == 0) return;
|
|
172
172
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
173
173
|
? record[@"terminal"] : nil;
|
|
174
|
-
|
|
175
|
-
NSString *
|
|
174
|
+
self.lastTerminalFocusTarget = terminal.count > 0 ? terminal : nil;
|
|
175
|
+
NSString *identity = [self statusIdentityForRecord:record];
|
|
176
176
|
NSString *tool = [record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @"";
|
|
177
177
|
if ([self.lastStatusState isEqualToString:@"approval"] &&
|
|
178
|
-
[self.
|
|
178
|
+
[self.lastStatusIdentity isEqualToString:identity]) return;
|
|
179
|
+
[self noteStatusIdentityForRecord:record];
|
|
179
180
|
[self applyStatusPresentationForState:@"approval"
|
|
180
|
-
provider:
|
|
181
|
+
provider:[self statusPresentationNameForRecord:record] tool:tool];
|
|
181
182
|
}
|
|
182
183
|
// 勾选 = 显示气泡。没有 agent 状态时也允许改,这样用户可以提前设好偏好,
|
|
183
184
|
// 而不必等下一次会话开始。
|
|
184
185
|
- (void)toggleStatusBubbleFromMenu:(NSButton *)sender {
|
|
185
|
-
self
|
|
186
|
-
[NSUserDefaults.standardUserDefaults setBool:self.statusBubbleExpanded
|
|
187
|
-
forKey:StatusBubbleExpandedKey];
|
|
186
|
+
[self updateStatusBubbleExpanded:!self.statusBubbleExpanded];
|
|
188
187
|
sender.state = self.statusBubbleExpanded ? NSControlStateValueOn : NSControlStateValueOff;
|
|
188
|
+
}
|
|
189
|
+
- (void)updateStatusBubbleExpanded:(BOOL)expanded {
|
|
190
|
+
self.statusBubbleExpanded = expanded;
|
|
191
|
+
CCPetsPrefSetBool(StatusBubbleExpandedKey, expanded);
|
|
189
192
|
if (self.statusBubbleExpanded && self.hasAgentStatus) {
|
|
190
193
|
[self positionAgentStatus];
|
|
191
194
|
[self.statusPanel orderFrontRegardless];
|
|
@@ -204,6 +207,28 @@
|
|
|
204
207
|
return [event isEqualToString:@"SubagentStop"] || [event isEqualToString:@"PostToolUse"] ||
|
|
205
208
|
[event isEqualToString:@"TaskCompleted"];
|
|
206
209
|
}
|
|
210
|
+
// 标题优先显示账号名;身份比较使用 profileId 和会话身份,不按显示名合并终端。
|
|
211
|
+
- (NSString *)statusPresentationNameForRecord:(NSDictionary *)record {
|
|
212
|
+
NSString *profileName = SanitizedShortString(record[@"profileName"], 64);
|
|
213
|
+
if (profileName.length > 0) return profileName;
|
|
214
|
+
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
215
|
+
return provider.length > 0 ? provider : @"Agent";
|
|
216
|
+
}
|
|
217
|
+
- (NSString *)statusIdentityForRecord:(NSDictionary *)record {
|
|
218
|
+
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
219
|
+
NSString *profileID = SanitizedShortString(record[@"profileId"], 128);
|
|
220
|
+
NSString *session = SanitizedShortString(record[@"session"], 128);
|
|
221
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class] ? record[@"terminal"] : nil;
|
|
222
|
+
NSString *terminalID = SanitizedShortString(terminal[@"ideTerminal"], 64);
|
|
223
|
+
NSString *tty = SanitizedShortString(terminal[@"tty"], 64);
|
|
224
|
+
// 同一个账号的不同会话也必须分开;未配对的新卡片不能借用上一张卡片的终端。
|
|
225
|
+
NSString *identity = session.length ? session : (terminalID.length ? terminalID : tty);
|
|
226
|
+
return [NSString stringWithFormat:@"%@|%@|%@", provider ?: @"", profileID ?: @"", identity ?: @""];
|
|
227
|
+
}
|
|
228
|
+
- (void)noteStatusIdentityForRecord:(NSDictionary *)record {
|
|
229
|
+
self.lastStatusAgentProvider = SanitizedShortString(record[@"provider"], 32);
|
|
230
|
+
self.lastStatusIdentity = [self statusIdentityForRecord:record];
|
|
231
|
+
}
|
|
207
232
|
- (void)applyStatusPresentationForState:(NSString *)state provider:(NSString *)provider
|
|
208
233
|
tool:(NSString *)tool {
|
|
209
234
|
self.lastStatusState = state;
|
|
@@ -225,6 +250,7 @@
|
|
|
225
250
|
[self resizeStatusCardToFitText];
|
|
226
251
|
[self layoutApprovalBadge];
|
|
227
252
|
[self positionAgentStatus];
|
|
253
|
+
[self notePetCardChanged];
|
|
228
254
|
if (self.statusBubbleExpanded) {
|
|
229
255
|
[self.statusPanel orderFrontRegardless];
|
|
230
256
|
// 卡片一出现就收掉独立气泡:两者都是宠物在说话,同时挂着就是重影。
|
|
@@ -245,6 +271,8 @@
|
|
|
245
271
|
- (void)showAgentStatusForRecord:(NSDictionary *)record notify:(BOOL)shouldNotify {
|
|
246
272
|
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
247
273
|
if (provider.length == 0) provider = @"Agent";
|
|
274
|
+
NSString *presentationName = [self statusPresentationNameForRecord:record];
|
|
275
|
+
NSString *identity = [self statusIdentityForRecord:record];
|
|
248
276
|
NSString *state = [record[@"state"] isKindOfClass:NSString.class]
|
|
249
277
|
? record[@"state"] : NormalizedStateForEvent(record[@"event"], [record[@"failed"] boolValue]);
|
|
250
278
|
NSString *tool = [record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @"";
|
|
@@ -253,19 +281,32 @@
|
|
|
253
281
|
if (!self.providerActivityAt) self.providerActivityAt = [NSMutableDictionary dictionary];
|
|
254
282
|
self.providerActivityAt[provider] = @(self.lastStatusTimestamp);
|
|
255
283
|
[self updateQuotaLiveState];
|
|
256
|
-
|
|
284
|
+
// 额外 Home 没有共用默认配置的文件监听;Hook 事件是最准确的变更信号。按 15 秒合并,
|
|
285
|
+
// 既让隐藏卡片及时更新,也避免工具密集执行时反复全量聚合。
|
|
286
|
+
if ([record[@"profileId"] isKindOfClass:NSString.class] &&
|
|
287
|
+
self.lastStatusTimestamp - self.lastUsageRefreshAt >= 15.0) {
|
|
288
|
+
[self refreshUsage:nil];
|
|
289
|
+
}
|
|
290
|
+
if (self.hasAgentStatus && [identity isEqualToString:self.lastStatusIdentity] &&
|
|
257
291
|
[self isTrailingRecord:record afterState:self.lastStatusState]) return;
|
|
258
292
|
|
|
259
293
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
260
294
|
? record[@"terminal"] : nil;
|
|
261
|
-
|
|
295
|
+
// Codex 的共享后台偶尔会先送到事件、稍后才完成会话与终端配对。无目标事件不能
|
|
296
|
+
// 把上一条已确认的回跳目标清空,否则卡片仍可见却会突然点不动。
|
|
297
|
+
if (terminal.count > 0) self.lastTerminalFocusTarget = terminal;
|
|
298
|
+
else if (![identity isEqualToString:self.lastStatusIdentity]) {
|
|
299
|
+
// 换成另一个会话且仍无法解析终端时,不能误跳到上一张卡片的终端。
|
|
300
|
+
self.lastTerminalFocusTarget = nil;
|
|
301
|
+
}
|
|
262
302
|
|
|
263
303
|
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
264
304
|
selector:@selector(hideAgentStatus) object:nil];
|
|
265
305
|
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
266
306
|
selector:@selector(enterIdleStatus) object:nil];
|
|
267
307
|
self.hasAgentStatus = YES;
|
|
268
|
-
[self
|
|
308
|
+
[self noteStatusIdentityForRecord:record];
|
|
309
|
+
[self applyStatusPresentationForState:state provider:presentationName tool:tool];
|
|
269
310
|
[self.panel orderFrontRegardless];
|
|
270
311
|
[self performSelector:@selector(hideAgentStatus)
|
|
271
312
|
withObject:nil afterDelay:AgentStatusInactivityInterval];
|
|
@@ -324,27 +365,23 @@
|
|
|
324
365
|
}
|
|
325
366
|
- (NSString *)agentSessionKeyForRecord:(NSDictionary *)record {
|
|
326
367
|
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
368
|
+
NSString *profileID = SanitizedShortString(record[@"profileId"], 128);
|
|
369
|
+
NSString *identity = profileID.length > 0 ? [NSString stringWithFormat:@"%@|%@", provider, profileID] : provider;
|
|
327
370
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
328
371
|
? record[@"terminal"] : nil;
|
|
329
372
|
NSString *tty = SanitizedShortString(terminal[@"tty"], 64);
|
|
330
373
|
NSString *bundleID = SanitizedShortString(terminal[@"bundleID"], 128);
|
|
331
374
|
if (tty.length > 0) {
|
|
332
|
-
return [NSString stringWithFormat:@"%@|%@|%@",
|
|
375
|
+
return [NSString stringWithFormat:@"%@|%@|%@", identity, bundleID, tty];
|
|
333
376
|
}
|
|
334
377
|
NSString *session = SanitizedShortString(record[@"session"], 128);
|
|
335
|
-
if (session.length > 0) return [NSString stringWithFormat:@"%@|%@",
|
|
336
|
-
return terminal.count > 0 ? [NSString stringWithFormat:@"%@|%@",
|
|
337
|
-
}
|
|
338
|
-
- (NSString *)onlineAgentSessionKeyForProvider:(NSString *)provider tty:(NSString *)tty {
|
|
339
|
-
provider = SanitizedShortString(provider, 32);
|
|
340
|
-
tty = SanitizedShortString(tty.lastPathComponent, 64);
|
|
341
|
-
if (provider.length == 0 || tty.length == 0) return nil;
|
|
342
|
-
return [NSString stringWithFormat:@"%@|%@", provider, tty];
|
|
378
|
+
if (session.length > 0) return [NSString stringWithFormat:@"%@|%@", identity, session];
|
|
379
|
+
return terminal.count > 0 ? [NSString stringWithFormat:@"%@|%@", identity, bundleID] : nil;
|
|
343
380
|
}
|
|
344
381
|
- (NSString *)onlineAgentSessionKeyForRecord:(NSDictionary *)record {
|
|
345
382
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
346
383
|
? record[@"terminal"] : nil;
|
|
347
|
-
return [
|
|
384
|
+
return OnlineAgentSessionKey(record[@"provider"], record[@"profileId"], terminal[@"tty"]);
|
|
348
385
|
}
|
|
349
386
|
// 在线判定优先用包装脚本写出的 pid 文件:它给出精确的退出信号,会话一关列表就更新。
|
|
350
387
|
// 但直接跑 claude / codex(或终端窗口早于 shim 安装就已打开)的会话根本没有 pid 文件,
|
|
@@ -354,6 +391,11 @@
|
|
|
354
391
|
- (BOOL)isAgentSessionRecordLive:(NSDictionary *)record {
|
|
355
392
|
NSString *onlineKey = [self onlineAgentSessionKeyForRecord:record];
|
|
356
393
|
if (onlineKey.length > 0 && [self.liveAgentSessionKeys containsObject:onlineKey]) return YES;
|
|
394
|
+
// 老版本包装脚本的 pid 文件不带账号,只能按 provider + tty 认领。
|
|
395
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
396
|
+
? record[@"terminal"] : nil;
|
|
397
|
+
NSString *unscopedKey = OnlineAgentSessionKey(record[@"provider"], nil, terminal[@"tty"]);
|
|
398
|
+
if (unscopedKey.length > 0 && [self.liveAgentSessionKeys containsObject:unscopedKey]) return YES;
|
|
357
399
|
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
358
400
|
if (provider.length > 0 && [self.liveClientProviders containsObject:provider]) return NO;
|
|
359
401
|
return NSDate.date.timeIntervalSince1970 - [record[@"timestamp"] doubleValue]
|
|
@@ -363,14 +405,35 @@
|
|
|
363
405
|
for (NSString *key in self.agentSessionRecords.allKeys) {
|
|
364
406
|
if (![self isAgentSessionRecordLive:self.agentSessionRecords[key]]) {
|
|
365
407
|
[self.agentSessionRecords removeObjectForKey:key];
|
|
408
|
+
[self notePetCardChanged];
|
|
366
409
|
}
|
|
367
410
|
}
|
|
368
411
|
}
|
|
412
|
+
- (NSString *)terminalSlotKeyForRecord:(NSDictionary *)record {
|
|
413
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
414
|
+
? record[@"terminal"] : nil;
|
|
415
|
+
NSString *tty = SanitizedShortString(terminal[@"tty"], 64);
|
|
416
|
+
if (tty.length == 0) return nil;
|
|
417
|
+
return [NSString stringWithFormat:@"%@|%@|%@", SanitizedShortString(record[@"provider"], 32),
|
|
418
|
+
SanitizedShortString(terminal[@"bundleID"], 128), tty];
|
|
419
|
+
}
|
|
369
420
|
- (void)trackAgentSessionRecord:(NSDictionary *)record {
|
|
370
421
|
NSString *key = [self agentSessionKeyForRecord:record];
|
|
371
422
|
if (key.length == 0) return;
|
|
372
423
|
if (!self.agentSessionRecords) self.agentSessionRecords = [NSMutableDictionary dictionary];
|
|
424
|
+
// 一个终端前台同时只跑一个客户端。同一终端里新起的会话(可能换了账号)说明之前那个
|
|
425
|
+
// 已经退出;它退出时不会补发结束事件,不在这里清掉就会在列表里留一行"正在启动"。
|
|
426
|
+
if ([record[@"event"] isEqual:@"SessionStart"]) {
|
|
427
|
+
NSString *ttyKey = [self terminalSlotKeyForRecord:record];
|
|
428
|
+
for (NSString *otherKey in self.agentSessionRecords.allKeys) {
|
|
429
|
+
if ([otherKey isEqualToString:key] || ttyKey.length == 0) continue;
|
|
430
|
+
if ([[self terminalSlotKeyForRecord:self.agentSessionRecords[otherKey]] isEqualToString:ttyKey]) {
|
|
431
|
+
[self.agentSessionRecords removeObjectForKey:otherKey];
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
373
435
|
self.agentSessionRecords[key] = record;
|
|
436
|
+
[self notePetCardChanged];
|
|
374
437
|
if (self.agentSessionRecords.count <= AgentSessionRecordLimit) return;
|
|
375
438
|
NSArray<NSDictionary *> *oldestFirst = [self.agentSessionRecords.allValues
|
|
376
439
|
sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *left, NSDictionary *right) {
|
|
@@ -455,14 +518,14 @@
|
|
|
455
518
|
- (void)presentStalledRecord:(NSDictionary *)record {
|
|
456
519
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
457
520
|
? record[@"terminal"] : nil;
|
|
458
|
-
|
|
459
|
-
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
521
|
+
self.lastTerminalFocusTarget = terminal.count > 0 ? terminal : nil;
|
|
460
522
|
NSString *state = [record[@"state"] isKindOfClass:NSString.class] ? record[@"state"] : @"";
|
|
461
523
|
self.hasAgentStatus = YES;
|
|
462
524
|
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
463
525
|
selector:@selector(hideAgentStatus) object:nil];
|
|
526
|
+
[self noteStatusIdentityForRecord:record];
|
|
464
527
|
[self applyStatusPresentationForState:state
|
|
465
|
-
provider:
|
|
528
|
+
provider:[self statusPresentationNameForRecord:record]
|
|
466
529
|
tool:[record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @""];
|
|
467
530
|
[self.panel orderFrontRegardless];
|
|
468
531
|
[self performSelector:@selector(hideAgentStatus) withObject:nil
|
|
@@ -483,6 +546,8 @@
|
|
|
483
546
|
PetApprovalBadgeSize, PetApprovalBadgeSize);
|
|
484
547
|
}
|
|
485
548
|
- (void)refreshApprovalBadge {
|
|
549
|
+
// 收起状态卡(hideAgentStatus)也走这里,名片要跟着回到待机,放在角标判空之前。
|
|
550
|
+
[self notePetCardChanged];
|
|
486
551
|
CCPetsApprovalBadgeView *badge = (CCPetsApprovalBadgeView *)self.approvalBadgeView;
|
|
487
552
|
if (!badge) return;
|
|
488
553
|
badge.count = [self pendingApprovalSessionRecords].count;
|
|
@@ -536,7 +601,7 @@
|
|
|
536
601
|
}
|
|
537
602
|
// 菜单打开即视为看过:角标清零,下一条新消息再亮。
|
|
538
603
|
self.bridgeSeenAt = NSDate.date.timeIntervalSince1970;
|
|
539
|
-
[self
|
|
604
|
+
[self refreshBridgeState:nil];
|
|
540
605
|
if (records.count == 0) {
|
|
541
606
|
[self popUpAgentSessionsMenu:menu from:sender];
|
|
542
607
|
return;
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
}
|
|
21
21
|
self.bridgeCommandRunning = YES;
|
|
22
22
|
NSTask *task = [NSTask new];
|
|
23
|
-
task.executableURL = [NSURL fileURLWithPath:locator[@"
|
|
24
|
-
task.arguments = [@[
|
|
23
|
+
task.executableURL = [NSURL fileURLWithPath:locator[@"binary"]];
|
|
24
|
+
task.arguments = [@[@"bridge"] arrayByAddingObjectsFromArray:arguments];
|
|
25
25
|
NSMutableDictionary<NSString *, NSString *> *environment =
|
|
26
26
|
[NSProcessInfo.processInfo.environment mutableCopy];
|
|
27
27
|
NSString *existingPath = environment[@"PATH"].length > 0 ? environment[@"PATH"] : @"/usr/bin:/bin:/usr/sbin:/sbin";
|
|
28
|
-
// claude / codex 常装在
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
// claude / codex 常装在 nvm 之类的目录里,从 Finder 启动的桌宠 PATH 里没有;
|
|
29
|
+
// 用 cc-pets 上次在终端里运行时记下的 PATH。
|
|
30
|
+
NSString *terminalPath = locator[@"path"];
|
|
31
|
+
environment[@"PATH"] = terminalPath.length > 0 ? [NSString stringWithFormat:@"%@:%@", terminalPath, existingPath] : existingPath;
|
|
31
32
|
task.environment = environment;
|
|
32
33
|
NSPipe *output = [NSPipe pipe];
|
|
33
34
|
task.standardOutput = output;
|
|
@@ -41,6 +42,8 @@
|
|
|
41
42
|
if (!strongSelf) return;
|
|
42
43
|
strongSelf.bridgeCommandRunning = NO;
|
|
43
44
|
[strongSelf refreshBridgeState:nil];
|
|
45
|
+
// 开关 Bridge 会改各账号是否算"已集成",让打开的多账号页重读。
|
|
46
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsProfilesDidChangeNotification object:nil];
|
|
44
47
|
if (finished.terminationStatus == EXIT_SUCCESS) {
|
|
45
48
|
if (successMessage.length > 0) {
|
|
46
49
|
[strongSelf sendNotificationWithTitle:@"CC Bridge" body:successMessage];
|
|
@@ -121,30 +124,19 @@
|
|
|
121
124
|
sender:sender successMessage:nil];
|
|
122
125
|
}
|
|
123
126
|
- (void)toggleBridgeBadge:(NSButton *)sender {
|
|
124
|
-
BOOL enabled = !
|
|
125
|
-
[
|
|
127
|
+
BOOL enabled = !CCPetsPrefBool(BridgeBadgeEnabledKey);
|
|
128
|
+
[self updateBridgeBadgeEnabled:enabled];
|
|
126
129
|
sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
130
|
+
}
|
|
131
|
+
- (void)updateBridgeBadgeEnabled:(BOOL)enabled {
|
|
132
|
+
CCPetsPrefSetBool(BridgeBadgeEnabledKey, enabled);
|
|
127
133
|
[self refreshBridgeBadge];
|
|
128
134
|
}
|
|
129
135
|
// 与"系统通知"那组开关同一套授权流程:第一次打开时向系统申请通知权限。
|
|
130
136
|
- (void)toggleBridgeNotification:(NSButton *)sender {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
sender.state = NSControlStateValueOff;
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
[UNUserNotificationCenter.currentNotificationCenter
|
|
138
|
-
requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionSound
|
|
139
|
-
completionHandler:^(BOOL granted, NSError *error) {
|
|
140
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
141
|
-
[defaults setBool:granted forKey:BridgeNotificationKey];
|
|
142
|
-
sender.state = granted ? NSControlStateValueOn : NSControlStateValueOff;
|
|
143
|
-
if (!granted) {
|
|
144
|
-
[self showAlertWithTitle:L(@"Can't Enable Notifications") message:error.localizedDescription ?:
|
|
145
|
-
L(@"Allow notifications in System Settings → Notifications → CC Pets, then try again.")];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
137
|
+
[self updateNotification:BridgeNotificationKey enabled:!CCPetsPrefBool(BridgeNotificationKey)
|
|
138
|
+
completion:^(BOOL enabled) {
|
|
139
|
+
sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
148
140
|
}];
|
|
149
141
|
}
|
|
150
142
|
// 读 bridge 状态(会话名、最近送达、信箱积压),刷新角标。bridge 未开启时清空并隐藏。
|
|
@@ -156,6 +148,8 @@
|
|
|
156
148
|
self.bridgeRecentDeliveries = nil;
|
|
157
149
|
self.bridgePendingCounts = nil;
|
|
158
150
|
self.bridgeSentStamp = nil;
|
|
151
|
+
self.quotaView.bridgeActivityProfileIDs = [NSSet set];
|
|
152
|
+
self.quotaView.needsDisplay = YES;
|
|
159
153
|
[self refreshBridgeBadge];
|
|
160
154
|
return;
|
|
161
155
|
}
|
|
@@ -179,6 +173,23 @@
|
|
|
179
173
|
if (self.bridgeSessions[session]) pending[session] = count;
|
|
180
174
|
}];
|
|
181
175
|
self.bridgePendingCounts = pending;
|
|
176
|
+
NSMutableSet<NSString *> *bridgeProfiles = [NSMutableSet set];
|
|
177
|
+
for (NSString *session in pending) {
|
|
178
|
+
NSString *profileID = self.bridgeSessions[session][@"profileId"];
|
|
179
|
+
if (profileID.length > 0) [bridgeProfiles addObject:profileID];
|
|
180
|
+
}
|
|
181
|
+
for (NSDictionary *delivery in recent) {
|
|
182
|
+
if ([delivery[@"at"] doubleValue] <= self.bridgeSeenAt) continue;
|
|
183
|
+
for (NSString *key in @[@"toSession", @"fromSession"]) {
|
|
184
|
+
NSString *session = [delivery[key] isKindOfClass:NSString.class] ? delivery[key] : nil;
|
|
185
|
+
NSString *profileID = session.length > 0 ? self.bridgeSessions[session][@"profileId"] : nil;
|
|
186
|
+
if (profileID.length > 0) [bridgeProfiles addObject:profileID];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (![self.quotaView.bridgeActivityProfileIDs isEqualToSet:bridgeProfiles]) {
|
|
190
|
+
self.quotaView.bridgeActivityProfileIDs = bridgeProfiles;
|
|
191
|
+
self.quotaView.needsDisplay = YES;
|
|
192
|
+
}
|
|
182
193
|
[self notifyNewBridgeDeliveries];
|
|
183
194
|
[self refreshBridgeBadge];
|
|
184
195
|
}
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
[NSApp activateIgnoringOtherApps:YES];
|
|
124
124
|
NSAlert *alert = [NSAlert new];
|
|
125
125
|
alert.messageText = L(@"No Pet Sprites Found");
|
|
126
|
-
alert.informativeText = L(@"Download one with `cc-pets pet add <name>`, or put a PNG / WebP sprite sheet in ~/.cc-pets/pets/<name>/. CC Pets doesn't read ~/.petdex/pets/ or ~/.codex/pets/; to use Codex pets, turn on “Import Codex
|
|
126
|
+
alert.informativeText = L(@"Download one with `cc-pets pet add <name>`, or put a PNG / WebP sprite sheet in ~/.cc-pets/pets/<name>/. CC Pets doesn't read ~/.petdex/pets/ or ~/.codex/pets/; to use Codex pets, turn on “Import Codex Pets” on the Pet page of the Main menu. Then click “Rescan”.");
|
|
127
127
|
[alert addButtonWithTitle:L(@"Rescan")];
|
|
128
128
|
[alert addButtonWithTitle:L(@"Open Pets Folder")];
|
|
129
129
|
[alert addButtonWithTitle:L(@"Quit")];
|
|
@@ -147,7 +147,21 @@
|
|
|
147
147
|
if (!image) return;
|
|
148
148
|
[self.petView applySheet:image petID:petID rowCount:spriteRowCount];
|
|
149
149
|
PetPhrasesSetCurrentPetID(petID);
|
|
150
|
-
[NSUserDefaults.standardUserDefaults setObject:petID forKey
|
|
150
|
+
[NSUserDefaults.standardUserDefaults setObject:petID forKey:PetSelectedSpriteKey];
|
|
151
|
+
[self notePetCardChanged];
|
|
152
|
+
}
|
|
153
|
+
// 主窗口宠物页的选择列表:只给展示要的字段,素材由页面在后台解码。
|
|
154
|
+
- (NSArray<NSDictionary *> *)petPickerOptions {
|
|
155
|
+
NSMutableArray<NSDictionary *> *options = [NSMutableArray array];
|
|
156
|
+
for (NSDictionary *option in [self petOptions]) {
|
|
157
|
+
[options addObject:@{@"id": option[@"id"], @"name": option[@"name"] ?: @"", @"path": option[@"path"] ?: @"",
|
|
158
|
+
@"rowCount": option[@"spriteRowCount"] ?: @9,
|
|
159
|
+
@"builtin": @([option[@"id"] hasPrefix:@"builtin:"])}];
|
|
160
|
+
}
|
|
161
|
+
return options;
|
|
162
|
+
}
|
|
163
|
+
- (NSString *)currentPetID {
|
|
164
|
+
return self.petView.currentPetID;
|
|
151
165
|
}
|
|
152
166
|
- (BOOL)deletePetWithID:(NSString *)petID {
|
|
153
167
|
if (![petID hasPrefix:@"external:"]) return NO;
|
|
@@ -177,7 +191,7 @@
|
|
|
177
191
|
if (fallback) [self switchPetToID:fallback[@"id"]];
|
|
178
192
|
else {
|
|
179
193
|
PetPhrasesSetCurrentPetID(nil);
|
|
180
|
-
[NSUserDefaults.standardUserDefaults removeObjectForKey
|
|
194
|
+
[NSUserDefaults.standardUserDefaults removeObjectForKey:PetSelectedSpriteKey];
|
|
181
195
|
}
|
|
182
196
|
}
|
|
183
197
|
return YES;
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
#import "CCPetsQuotaHistory.h"
|
|
9
9
|
#import "CCPetsImageLoader.h"
|
|
10
10
|
#import "CCPetsPetSize.h"
|
|
11
|
+
#import "CCPetsPreferences.h"
|
|
12
|
+
#import "CCPetsMainWindow.h"
|
|
13
|
+
#import "CCPetsWorkbench.h"
|
|
11
14
|
#import "CCPetsPhrases.h"
|
|
12
15
|
#import "CCPetsPhrasesEditor.h"
|
|
13
16
|
#import "CCPetsUsage.h"
|
|
@@ -15,6 +18,7 @@
|
|
|
15
18
|
#import "MenuChoiceRow.h"
|
|
16
19
|
#import "CCPetsGlassMenu.h"
|
|
17
20
|
#import "CCPetsBridge.h"
|
|
21
|
+
#import "CCPetsProfiles.h"
|
|
18
22
|
#import "MenuToggleSwitch.h"
|
|
19
23
|
#import <UserNotifications/UserNotifications.h>
|
|
20
24
|
#import <signal.h>
|
|
@@ -64,7 +68,7 @@ static const NSTimeInterval PetSpeechDwell = 4.5;
|
|
|
64
68
|
// layer.cornerRadius + kCACornerCurveContinuous 改用位图 maskImage 裁形,
|
|
65
69
|
// squircle 和 GPU 端矢量裁切的质感一起丢了,得不偿失。
|
|
66
70
|
// 结论:保持药丸 + 原生圆角,靠贴近宠物来表达归属。
|
|
67
|
-
static const CGFloat PetSpeechBodyHeight =
|
|
71
|
+
static const CGFloat PetSpeechBodyHeight = CCPetsSpeechBubbleHeight;
|
|
68
72
|
static const CGFloat PetStatusBodyHeight = 58.0;
|
|
69
73
|
// 副行没东西可显示时的高度,只放得下标题一行。
|
|
70
74
|
static const CGFloat PetStatusSingleLineHeight = 40.0;
|
|
@@ -103,19 +107,31 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
|
|
|
103
107
|
return ceil(label.fittingSize.width) + 2;
|
|
104
108
|
}
|
|
105
109
|
|
|
106
|
-
//
|
|
107
|
-
//
|
|
110
|
+
// 窗口的 contentView 由 AppKit 管理尺寸,不能直接拿它的 bounds 做缩放。
|
|
111
|
+
// 外壳保持窗口坐标,内部视图独立保留逻辑坐标,统一缩放绘制和命中区域。
|
|
112
|
+
@interface CCPetsBubbleContainerView : NSView
|
|
113
|
+
@end
|
|
114
|
+
|
|
108
115
|
static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
109
116
|
if (!panel) return;
|
|
110
117
|
CGFloat scale = CCPetsBubbleScalePreference();
|
|
111
118
|
NSSize size = NSMakeSize(logicalSize.width * scale, logicalSize.height * scale);
|
|
112
|
-
NSView *
|
|
113
|
-
|
|
119
|
+
NSView *container = panel.contentView;
|
|
120
|
+
NSView *root;
|
|
121
|
+
if ([container isKindOfClass:CCPetsBubbleContainerView.class]) {
|
|
122
|
+
root = container.subviews.firstObject;
|
|
123
|
+
} else {
|
|
124
|
+
root = container;
|
|
125
|
+
container = [[CCPetsBubbleContainerView alloc] initWithFrame:root.frame];
|
|
126
|
+
container.autoresizesSubviews = NO;
|
|
127
|
+
panel.contentView = container;
|
|
128
|
+
[container addSubview:root];
|
|
129
|
+
}
|
|
130
|
+
root.autoresizingMask = NSViewNotSizable;
|
|
114
131
|
root.autoresizesSubviews = NO;
|
|
115
132
|
[panel setContentSize:size];
|
|
116
133
|
root.frame = NSMakeRect(0, 0, size.width, size.height);
|
|
117
134
|
root.bounds = NSMakeRect(0, 0, logicalSize.width, logicalSize.height);
|
|
118
|
-
root.autoresizesSubviews = autoresizes;
|
|
119
135
|
root.needsDisplay = YES;
|
|
120
136
|
}
|
|
121
137
|
|
|
@@ -131,10 +147,13 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
|
131
147
|
@property(nonatomic) NSColor *fillColor;
|
|
132
148
|
@end
|
|
133
149
|
|
|
134
|
-
|
|
150
|
+
// 主窗口侧边栏的宠物名片从这里取数据,见 CCPetsMainWindow.h。
|
|
151
|
+
@interface AppDelegate () <CCPetsPetCardSource>
|
|
135
152
|
- (NSString *)applicationSupportDirectory;
|
|
153
|
+
- (void)notePetCardChanged;
|
|
136
154
|
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message;
|
|
137
|
-
- (void)
|
|
155
|
+
- (void)installMainMenu;
|
|
156
|
+
- (void)openMainWindow:(id)sender;
|
|
138
157
|
- (void)applicationDidFinishLaunching:(NSNotification *)notification;
|
|
139
158
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag;
|
|
140
159
|
- (void)screensDidSleep:(NSNotification *)notification;
|
|
@@ -143,32 +162,34 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
|
143
162
|
- (void)applicationWillTerminate:(NSNotification *)notification;
|
|
144
163
|
@end
|
|
145
164
|
|
|
146
|
-
//
|
|
165
|
+
// 右键菜单里的各项设置开关。setXxx: / toggleXxx: 是菜单控件的 action;updateXxx: 不依赖
|
|
166
|
+
// 控件,写设置并让界面生效,主窗口设置页直接调用。
|
|
147
167
|
@interface AppDelegate (Settings)
|
|
168
|
+
- (void)updatePetScale:(double)scale;
|
|
169
|
+
- (void)updateSystemMetric:(NSString *)key enabled:(BOOL)enabled;
|
|
170
|
+
- (void)updateUsageDisplayMode:(NSString *)mode forKey:(NSString *)key;
|
|
171
|
+
- (void)updateUsageDisplayMode:(NSString *)mode forProfileID:(NSString *)profileID;
|
|
172
|
+
- (void)updateImportCodexPets:(BOOL)enabled;
|
|
173
|
+
- (void)updatePanelTheme:(NSString *)theme;
|
|
174
|
+
- (void)updateGlassDimLevel:(NSNumber *)level;
|
|
175
|
+
- (void)updateSpeechEnabled:(BOOL)enabled;
|
|
176
|
+
- (void)updatePetInteractionEnabled:(BOOL)enabled;
|
|
177
|
+
- (void)updatePetInteractionValue:(NSNumber *)value forKey:(NSString *)key;
|
|
178
|
+
- (void)updateSpeechFrequency:(NSString *)value;
|
|
179
|
+
- (void)updatePhrasesSource:(NSString *)source;
|
|
180
|
+
- (void)updateNotification:(NSString *)key enabled:(BOOL)enabled
|
|
181
|
+
completion:(void (^)(BOOL enabled))completion;
|
|
148
182
|
- (void)applyPetSizePreference;
|
|
149
183
|
- (void)setPetSizeFromSlider:(NSSlider *)sender;
|
|
150
|
-
- (void)toggleSystemMetric:(NSButton *)sender;
|
|
151
184
|
- (void)setUsageDisplayModeFromControl:(NSButton *)sender;
|
|
152
|
-
- (NSString *)systemMetricKeyForTag:(NSInteger)tag;
|
|
153
185
|
- (void)applySystemMetricPreferences;
|
|
154
186
|
- (void)applyUsageDisplayModePreferences;
|
|
155
|
-
- (void)toggleImportCodexPets:(NSButton *)sender;
|
|
156
187
|
- (void)showImportedCodexPetsAlert:(NSUInteger)imported;
|
|
157
|
-
- (NSString *)notificationKeyForTag:(NSInteger)tag;
|
|
158
188
|
- (void)setPanelTheme:(MenuChoiceRowView *)sender;
|
|
159
189
|
- (void)applyBubbleTextStyle;
|
|
160
190
|
- (void)setGlassDimLevel:(MenuChoiceRowView *)sender;
|
|
161
|
-
- (void)toggleSpeech:(NSButton *)sender;
|
|
162
|
-
- (void)togglePetInteraction:(NSButton *)sender;
|
|
163
|
-
- (void)setPetInteractionHeartThreshold:(MenuChoiceRowView *)sender;
|
|
164
|
-
- (void)setPetInteractionAnnoyedThreshold:(MenuChoiceRowView *)sender;
|
|
165
|
-
- (void)setPetInteractionInterval:(MenuChoiceRowView *)sender;
|
|
166
|
-
- (void)setSpeechFrequency:(MenuChoiceRowView *)sender;
|
|
167
|
-
- (void)setPhrasesSource:(MenuChoiceRowView *)sender;
|
|
168
191
|
- (void)editPhrasesFile:(id)sender;
|
|
169
|
-
- (void)setLanguagePreferenceFromMenu:(NSMenuItem *)sender;
|
|
170
192
|
- (void)languageDidChange:(NSNotification *)notification;
|
|
171
|
-
- (void)toggleNotification:(NSButton *)sender;
|
|
172
193
|
@end
|
|
173
194
|
|
|
174
195
|
// Agent 状态卡、会话列表、审批与卡住提醒、终端回跳、系统通知
|
|
@@ -177,6 +198,7 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
|
177
198
|
- (void)showAgentStatusForRecord:(NSDictionary *)record;
|
|
178
199
|
- (void)prunePendingApprovalRecords;
|
|
179
200
|
- (void)toggleStatusBubbleFromMenu:(NSButton *)sender;
|
|
201
|
+
- (void)updateStatusBubbleExpanded:(BOOL)expanded;
|
|
180
202
|
- (void)sendNotificationWithTitle:(NSString *)title body:(NSString *)body;
|
|
181
203
|
- (void)notifyForRecord:(NSDictionary *)record;
|
|
182
204
|
- (NSString *)statusTextForState:(NSString *)state tool:(NSString *)tool;
|
|
@@ -195,7 +217,6 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
|
195
217
|
- (NSString *)approvalKeyForRecord:(NSDictionary *)record;
|
|
196
218
|
- (void)displayAgentRecord:(NSDictionary *)record notify:(BOOL)shouldNotify;
|
|
197
219
|
- (NSString *)agentSessionKeyForRecord:(NSDictionary *)record;
|
|
198
|
-
- (NSString *)onlineAgentSessionKeyForProvider:(NSString *)provider tty:(NSString *)tty;
|
|
199
220
|
- (NSString *)onlineAgentSessionKeyForRecord:(NSDictionary *)record;
|
|
200
221
|
- (BOOL)isAgentSessionRecordLive:(NSDictionary *)record;
|
|
201
222
|
- (void)pruneOfflineAgentSessionRecords;
|
|
@@ -230,6 +251,7 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
|
230
251
|
- (void)toggleBridgeWake:(NSButton *)sender;
|
|
231
252
|
- (void)toggleBridgeEditGuard:(NSButton *)sender;
|
|
232
253
|
- (void)toggleBridgeBadge:(NSButton *)sender;
|
|
254
|
+
- (void)updateBridgeBadgeEnabled:(BOOL)enabled;
|
|
233
255
|
- (void)toggleBridgeNotification:(NSButton *)sender;
|
|
234
256
|
- (void)refreshBridgeState:(NSTimer *)timer;
|
|
235
257
|
- (void)notifyNewBridgeDeliveries;
|
|
@@ -242,9 +264,34 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
|
242
264
|
pending:(NSDictionary<NSString *, NSNumber *> *)pending;
|
|
243
265
|
@end
|
|
244
266
|
|
|
267
|
+
// 用户显式添加、修复或移除 Claude/Codex Home。
|
|
268
|
+
@interface AppDelegate (Profiles)
|
|
269
|
+
- (void)addClaudeProfile:(id)sender;
|
|
270
|
+
- (void)addCodexProfile:(id)sender;
|
|
271
|
+
- (void)repairAgentProfile:(NSMenuItem *)sender;
|
|
272
|
+
- (void)renameAgentProfile:(NSMenuItem *)sender;
|
|
273
|
+
- (void)relocateAgentProfile:(NSMenuItem *)sender;
|
|
274
|
+
- (void)removeAgentProfile:(NSMenuItem *)sender;
|
|
275
|
+
- (void)chooseProfileHomeForProvider:(NSString *)provider;
|
|
276
|
+
- (void)runProfileCommand:(NSArray<NSString *> *)arguments
|
|
277
|
+
title:(NSString *)title completionMessage:(NSString *)completionMessage;
|
|
278
|
+
@end
|
|
279
|
+
|
|
280
|
+
// 主窗口工作台几页的数据快照,见 CCPetsWorkbench.h。
|
|
281
|
+
@interface AppDelegate (Workbench)
|
|
282
|
+
- (NSArray<NSDictionary *> *)workbenchSessions;
|
|
283
|
+
- (NSDictionary *)workbenchMessages;
|
|
284
|
+
- (NSArray<NSDictionary *> *)workbenchQuotas;
|
|
285
|
+
- (void)focusWorkbenchSessionWithID:(NSString *)sessionID;
|
|
286
|
+
- (void)focusBridgeSessionWithID:(NSString *)sessionID;
|
|
287
|
+
- (void)markWorkbenchMessagesSeen;
|
|
288
|
+
@end
|
|
289
|
+
|
|
245
290
|
// 宠物素材发现、切换与删除
|
|
246
291
|
@interface AppDelegate (Pets)
|
|
247
292
|
- (void)switchPetToID:(NSString *)petID;
|
|
293
|
+
- (NSArray<NSDictionary *> *)petPickerOptions;
|
|
294
|
+
- (NSString *)currentPetID;
|
|
248
295
|
- (BOOL)deletePetWithID:(NSString *)petID;
|
|
249
296
|
- (NSDictionary *)petManifestInDirectory:(NSString *)directory;
|
|
250
297
|
- (NSInteger)spriteVersionInDirectory:(NSString *)directory fallbackDirectory:(NSString *)fallbackDirectory;
|
|
@@ -307,6 +354,7 @@ static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
|
307
354
|
- (void)positionSpeechPanel;
|
|
308
355
|
- (void)speakWithTag:(NSString *)tag;
|
|
309
356
|
- (void)presentSpeechText:(NSString *)text;
|
|
357
|
+
- (NSString *)sampleSpeechLine;
|
|
310
358
|
- (void)restoreStatusDetail;
|
|
311
359
|
- (void)showSpeechBubbleWithText:(NSString *)text;
|
|
312
360
|
- (void)showSpeechBubbleWithText:(NSString *)text dwell:(NSTimeInterval)dwell;
|