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
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
#import "CCPetsTerminalFocus.h"
|
|
2
2
|
#import "CCPetsEvents.h"
|
|
3
3
|
#import "CCPetsPaths.h"
|
|
4
|
+
#import "CCPetsIDEIntegration.h"
|
|
5
|
+
#import "CCPetsVSCodeIntegration.h"
|
|
4
6
|
#import <fcntl.h>
|
|
5
7
|
#import <sys/file.h>
|
|
6
8
|
#import <sys/sysctl.h>
|
|
7
9
|
#import <sys/stat.h>
|
|
8
10
|
#import <stdlib.h>
|
|
9
11
|
#import <unistd.h>
|
|
12
|
+
#import <sqlite3.h>
|
|
10
13
|
|
|
11
14
|
static BOOL ProcessInfoForPID(pid_t pid, struct kinfo_proc *info) {
|
|
12
15
|
if (pid <= 0) return NO;
|
|
@@ -97,11 +100,13 @@ NSDictionary *TerminalFocusTargetFromEnvironment(void) {
|
|
|
97
100
|
NSString *program = TerminalTargetValue(environment, @"CC_PETS_TERMINAL_PROGRAM", 64);
|
|
98
101
|
NSString *session = TerminalTargetValue(environment, @"CC_PETS_TERMINAL_SESSION", 128);
|
|
99
102
|
NSString *bundleID = TerminalTargetValue(environment, @"CC_PETS_TERMINAL_BUNDLE_ID", 128);
|
|
103
|
+
NSString *ideInstance = TerminalTargetValue(environment, @"CC_PETS_IDE_INSTANCE_ID", 64);
|
|
104
|
+
NSString *ideTerminal = TerminalTargetValue(environment, @"CC_PETS_IDE_TERMINAL_ID", 64);
|
|
100
105
|
if (tty.length == 0) tty = SanitizedShortString(ControllingTerminalName(), 64);
|
|
101
106
|
if (bundleID.length == 0) {
|
|
102
107
|
bundleID = SanitizedShortString(HostApplicationBundleIdentifier(), 128);
|
|
103
108
|
}
|
|
104
|
-
if (tty.length == 0 && program.length == 0 && session.length == 0 && bundleID.length == 0) {
|
|
109
|
+
if (tty.length == 0 && program.length == 0 && session.length == 0 && bundleID.length == 0 && ideInstance.length == 0) {
|
|
105
110
|
return @{};
|
|
106
111
|
}
|
|
107
112
|
NSMutableDictionary *target = [NSMutableDictionary dictionary];
|
|
@@ -109,6 +114,10 @@ NSDictionary *TerminalFocusTargetFromEnvironment(void) {
|
|
|
109
114
|
if (program.length > 0) target[@"program"] = program;
|
|
110
115
|
if (session.length > 0) target[@"session"] = session;
|
|
111
116
|
if (bundleID.length > 0) target[@"bundleID"] = bundleID;
|
|
117
|
+
if (ideInstance.length > 0 && ideTerminal.length > 0) {
|
|
118
|
+
target[@"ideInstance"] = ideInstance;
|
|
119
|
+
target[@"ideTerminal"] = ideTerminal;
|
|
120
|
+
}
|
|
112
121
|
return target;
|
|
113
122
|
}
|
|
114
123
|
|
|
@@ -152,11 +161,37 @@ static BOOL RunTerminalSelectionScript(NSString *bundleID, NSString *ttyName) {
|
|
|
152
161
|
"end repeat\n"
|
|
153
162
|
"end tell\n"
|
|
154
163
|
"return false", tty];
|
|
164
|
+
} else if ([bundleID isEqualToString:@"com.mitchellh.ghostty"]) {
|
|
165
|
+
// Ghostty 1.4 起暴露 tty。先选中所属标签页并激活应用,再聚焦分屏;
|
|
166
|
+
// 不只依赖 focus 内部异步的窗口前置,状态卡本身是 NonactivatingPanel。
|
|
167
|
+
source = [NSString stringWithFormat:
|
|
168
|
+
@"tell application \"Ghostty\"\n"
|
|
169
|
+
"repeat with terminalWindow in windows\n"
|
|
170
|
+
"repeat with terminalTab in tabs of terminalWindow\n"
|
|
171
|
+
"repeat with terminalSurface in terminals of terminalTab\n"
|
|
172
|
+
"if (tty of terminalSurface) is \"%@\" then\n"
|
|
173
|
+
"set targetID to id of terminalSurface\n"
|
|
174
|
+
"select tab terminalTab\n"
|
|
175
|
+
"activate\n"
|
|
176
|
+
"focus (terminal id targetID)\n"
|
|
177
|
+
"return true\n"
|
|
178
|
+
"end if\n"
|
|
179
|
+
"end repeat\n"
|
|
180
|
+
"end repeat\n"
|
|
181
|
+
"end repeat\n"
|
|
182
|
+
"end tell\n"
|
|
183
|
+
"return false", tty];
|
|
155
184
|
}
|
|
156
185
|
if (!source) return NO;
|
|
157
186
|
NSDictionary *error = nil;
|
|
158
187
|
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source];
|
|
159
188
|
NSAppleEventDescriptor *result = [script executeAndReturnError:&error];
|
|
189
|
+
if (error) {
|
|
190
|
+
NSLog(@"Terminal focus failed: bundle=%@ tty=%@ error=%@", bundleID, tty, error);
|
|
191
|
+
} else {
|
|
192
|
+
NSLog(@"Terminal focus: bundle=%@ tty=%@ matched=%@", bundleID, tty,
|
|
193
|
+
result.booleanValue ? @"yes" : @"no");
|
|
194
|
+
}
|
|
160
195
|
return result.booleanValue && error == nil;
|
|
161
196
|
}
|
|
162
197
|
|
|
@@ -197,7 +232,30 @@ NSArray<NSString *> *TerminalFocusBundleCandidates(NSDictionary *target) {
|
|
|
197
232
|
return candidates;
|
|
198
233
|
}
|
|
199
234
|
|
|
235
|
+
// 没有脚本或插件接口的宿主(如 Warp、未装扩展的 VS Code)退回激活应用。activateWithOptions:
|
|
236
|
+
// 在 macOS 14 起走协作式激活:状态卡是 NonactivatingPanel,桌宠自己不在前台,请求可能
|
|
237
|
+
// 被系统拒绝,窗口在别的桌面时更是不会切过去。改走和点 Dock 图标同一条路,让系统负责
|
|
238
|
+
// 切到应用窗口所在的桌面;拿不到 bundleURL 时才退回旧接口。
|
|
239
|
+
static BOOL ActivateApplicationAcrossSpaces(NSRunningApplication *application) {
|
|
240
|
+
NSURL *bundleURL = application.bundleURL;
|
|
241
|
+
if (bundleURL) {
|
|
242
|
+
NSWorkspaceOpenConfiguration *configuration = [NSWorkspaceOpenConfiguration configuration];
|
|
243
|
+
configuration.activates = YES;
|
|
244
|
+
configuration.addsToRecentItems = NO;
|
|
245
|
+
[NSWorkspace.sharedWorkspace openApplicationAtURL:bundleURL configuration:configuration
|
|
246
|
+
completionHandler:nil];
|
|
247
|
+
return YES;
|
|
248
|
+
}
|
|
249
|
+
#pragma clang diagnostic push
|
|
250
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
251
|
+
return [application activateWithOptions:
|
|
252
|
+
NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps];
|
|
253
|
+
#pragma clang diagnostic pop
|
|
254
|
+
}
|
|
255
|
+
|
|
200
256
|
BOOL ActivateTerminalFocusTarget(NSDictionary *target) {
|
|
257
|
+
if (CCPetsRequestIDETerminalFocus(target)) return YES;
|
|
258
|
+
if (CCPetsRequestVSCodeTerminalFocus(target)) return YES;
|
|
201
259
|
NSString *tty = SanitizedShortString(target[@"tty"], 64);
|
|
202
260
|
// 候选按优先级往下试,没在运行的直接跳过:映射值和捕获值总有一个指向真正承载
|
|
203
261
|
// 会话的那个应用,卡在第一个候选上就会白白丢掉一次可用的回跳。
|
|
@@ -206,11 +264,7 @@ BOOL ActivateTerminalFocusTarget(NSDictionary *target) {
|
|
|
206
264
|
NSRunningApplication *application =
|
|
207
265
|
[NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID].firstObject;
|
|
208
266
|
if (!application) continue;
|
|
209
|
-
|
|
210
|
-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
211
|
-
return [application activateWithOptions:
|
|
212
|
-
NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps];
|
|
213
|
-
#pragma clang diagnostic pop
|
|
267
|
+
return ActivateApplicationAcrossSpaces(application);
|
|
214
268
|
}
|
|
215
269
|
return NO;
|
|
216
270
|
}
|
|
@@ -219,11 +273,11 @@ BOOL ActivateTerminalFocusTarget(NSDictionary *target) {
|
|
|
219
273
|
|
|
220
274
|
// Codex 共享服务拉起的 hook 不知道会话在哪个终端(见 TerminalFocusRunsUnderSharedAgentHost)。
|
|
221
275
|
// 能确定的只有两头:codex-with-pet 启动时知道自己的终端、工作目录和时刻;hook 知道会话 ID,
|
|
222
|
-
// 会话记录(rollout
|
|
223
|
-
//
|
|
224
|
-
//
|
|
276
|
+
// 会话记录(rollout)的第一行又记着会话的工作目录和创建时刻。CLI 启动后可能还要等网络
|
|
277
|
+
// 初始化,不能按包装脚本的启动先后猜测归属。多个候选时读取本机 TUI 就绪日志的 PID,
|
|
278
|
+
// 仅在会话创建前的一秒内存在唯一就绪候选时配对;信息不足就留空,之后的 Hook 可再试。
|
|
225
279
|
static const NSUInteger CodexLaunchThreadLimit = 32;
|
|
226
|
-
static const NSTimeInterval
|
|
280
|
+
static const NSTimeInterval CodexClientReadyWindow = 1.0;
|
|
227
281
|
|
|
228
282
|
static NSTimeInterval ProcessStartTime(pid_t pid) {
|
|
229
283
|
struct kinfo_proc info;
|
|
@@ -311,8 +365,9 @@ int RegisterCodexLaunch(void) {
|
|
|
311
365
|
|
|
312
366
|
// 会话记录按 sessions/YYYY/MM/DD/rollout-<时间>-<会话 ID>.jsonl 存放,目录名字典序即时间序。
|
|
313
367
|
// 刚开始收事件的会话一定在最近几天的目录里;resume 的旧会话找不到也没关系,按工作目录兜底。
|
|
314
|
-
static NSString *CodexRolloutPathForThread(NSString *thread) {
|
|
315
|
-
NSString *sessions = [DefaultCodexHomeDirectory()
|
|
368
|
+
static NSString *CodexRolloutPathForThread(NSString *thread, NSString *codexHome) {
|
|
369
|
+
NSString *sessions = [(codexHome.length > 0 ? codexHome : DefaultCodexHomeDirectory())
|
|
370
|
+
stringByAppendingPathComponent:@"sessions"];
|
|
316
371
|
NSFileManager *files = NSFileManager.defaultManager;
|
|
317
372
|
NSString *suffix = [NSString stringWithFormat:@"-%@.jsonl", thread];
|
|
318
373
|
NSUInteger examinedDays = 0;
|
|
@@ -337,10 +392,12 @@ static NSString *CodexRolloutPathForThread(NSString *thread) {
|
|
|
337
392
|
}
|
|
338
393
|
|
|
339
394
|
// 第一行是 session_meta,带 cwd 和创建时刻;它里面有完整的系统提示词,可能很长,读到换行为止。
|
|
340
|
-
static NSDictionary *CodexThreadMeta(NSString *thread, NSDictionary *payload) {
|
|
395
|
+
static NSDictionary *CodexThreadMeta(NSString *thread, NSDictionary *payload, NSString *codexHome) {
|
|
341
396
|
NSString *path = [payload[@"transcript_path"] isKindOfClass:NSString.class]
|
|
342
397
|
? payload[@"transcript_path"] : nil;
|
|
343
|
-
if (![NSFileManager.defaultManager fileExistsAtPath:path])
|
|
398
|
+
if (![NSFileManager.defaultManager fileExistsAtPath:path]) {
|
|
399
|
+
path = CodexRolloutPathForThread(thread, codexHome);
|
|
400
|
+
}
|
|
344
401
|
NSFileHandle *handle = path ? [NSFileHandle fileHandleForReadingAtPath:path] : nil;
|
|
345
402
|
NSMutableData *line = [NSMutableData data];
|
|
346
403
|
while (handle && line.length < 8 * 1024 * 1024) {
|
|
@@ -376,35 +433,81 @@ static NSDictionary *CodexThreadMeta(NSString *thread, NSDictionary *payload) {
|
|
|
376
433
|
return result;
|
|
377
434
|
}
|
|
378
435
|
|
|
379
|
-
//
|
|
380
|
-
//
|
|
381
|
-
//
|
|
436
|
+
// Codex 0.166 的本机日志记录每个 TUI 的就绪时刻和带 PID 的 process_uuid。
|
|
437
|
+
// 只读这一类元数据,不读取提示词、输出或 HTTP 日志。内部日志格式改变、日志尚未落盘、
|
|
438
|
+
// 多个客户端同时就绪时都不能猜测;sqlite 的读锁等待和返回条数也有上限。
|
|
439
|
+
static int CodexLogQueryExpired(void *context) {
|
|
440
|
+
return CFAbsoluteTimeGetCurrent() > *(CFAbsoluteTime *)context;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
static NSString *ReadyCodexLaunch(NSDictionary<NSString *, NSDictionary *> *launches,
|
|
444
|
+
NSArray<NSString *> *candidates, NSNumber *createdAt, NSString *codexHome) {
|
|
445
|
+
if (!createdAt || createdAt.doubleValue <= 0) return nil;
|
|
446
|
+
NSString *path = [(codexHome.length ? codexHome : DefaultCodexHomeDirectory())
|
|
447
|
+
stringByAppendingPathComponent:@"logs_2.sqlite"];
|
|
448
|
+
sqlite3 *database = NULL;
|
|
449
|
+
if (sqlite3_open_v2(path.fileSystemRepresentation, &database, SQLITE_OPEN_READONLY | SQLITE_OPEN_NOMUTEX, NULL) != SQLITE_OK) {
|
|
450
|
+
if (database) sqlite3_close(database);
|
|
451
|
+
return nil;
|
|
452
|
+
}
|
|
453
|
+
sqlite3_busy_timeout(database, 50);
|
|
454
|
+
CFAbsoluteTime deadline = CFAbsoluteTimeGetCurrent() + 0.15;
|
|
455
|
+
sqlite3_progress_handler(database, 1000, CodexLogQueryExpired, &deadline);
|
|
456
|
+
sqlite3_stmt *statement = NULL;
|
|
457
|
+
const char *query = "SELECT ts, ts_nanos, process_uuid FROM logs "
|
|
458
|
+
"WHERE ts BETWEEN ? AND ? AND target = 'codex_tui::app::startup' "
|
|
459
|
+
"AND feedback_log_body LIKE 'tui startup initial frame scheduled%' LIMIT 128";
|
|
460
|
+
NSMutableSet<NSString *> *matches = [NSMutableSet set];
|
|
461
|
+
BOOL complete = NO;
|
|
462
|
+
if (sqlite3_prepare_v2(database, query, -1, &statement, NULL) == SQLITE_OK) {
|
|
463
|
+
sqlite3_bind_int64(statement, 1, (sqlite3_int64)floor(createdAt.doubleValue - CodexClientReadyWindow));
|
|
464
|
+
sqlite3_bind_int64(statement, 2, (sqlite3_int64)ceil(createdAt.doubleValue));
|
|
465
|
+
int result;
|
|
466
|
+
NSUInteger rows = 0;
|
|
467
|
+
while ((result = sqlite3_step(statement)) == SQLITE_ROW) {
|
|
468
|
+
rows++;
|
|
469
|
+
double readyAt = sqlite3_column_int64(statement, 0) + sqlite3_column_int64(statement, 1) / 1e9;
|
|
470
|
+
if (readyAt > createdAt.doubleValue || readyAt < createdAt.doubleValue - CodexClientReadyWindow) continue;
|
|
471
|
+
const unsigned char *value = sqlite3_column_text(statement, 2);
|
|
472
|
+
NSString *process = value ? @((const char *)value) : @"";
|
|
473
|
+
for (NSString *key in candidates) {
|
|
474
|
+
NSDictionary *entry = launches[key];
|
|
475
|
+
NSString *prefix = [NSString stringWithFormat:@"pid:%d:", [entry[@"pid"] intValue]];
|
|
476
|
+
if ([process hasPrefix:prefix] && readyAt >= [entry[@"processStartedAt"] doubleValue] &&
|
|
477
|
+
readyAt >= [entry[@"launchedAt"] doubleValue]) [matches addObject:key];
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
complete = result == SQLITE_DONE && rows < 128;
|
|
481
|
+
}
|
|
482
|
+
if (statement) sqlite3_finalize(statement);
|
|
483
|
+
sqlite3_close(database);
|
|
484
|
+
return complete && matches.count == 1 ? matches.anyObject : nil;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// 显式 resume 优先按会话 ID;新会话用客户端就绪证据。多个同目录客户端时不能用
|
|
488
|
+
// “最新未绑定的进程”兜底:网络启动延迟和首次发消息的顺序都可能与启动顺序不同。
|
|
382
489
|
static NSString *ChooseCodexLaunch(NSDictionary<NSString *, NSDictionary *> *launches,
|
|
383
|
-
NSString *cwd, NSNumber *createdAt) {
|
|
490
|
+
NSString *cwd, NSNumber *createdAt, NSString *thread, NSString *codexHome) {
|
|
384
491
|
NSMutableArray<NSString *> *sameDirectory = [NSMutableArray array];
|
|
385
|
-
NSMutableArray<NSString *> *
|
|
492
|
+
NSMutableArray<NSString *> *resumed = [NSMutableArray array];
|
|
386
493
|
for (NSString *key in launches) {
|
|
387
494
|
NSDictionary *entry = launches[key];
|
|
388
495
|
if (![entry[@"cwd"] isEqualToString:cwd]) continue;
|
|
389
496
|
[sameDirectory addObject:key];
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
return [launches[a][@"launchedAt"] compare:launches[b][@"launchedAt"]];
|
|
395
|
-
}];
|
|
396
|
-
if (createdAt) {
|
|
397
|
-
NSString *preceding = nil;
|
|
398
|
-
for (NSString *key in byLaunch) {
|
|
399
|
-
if ([launches[key][@"launchedAt"] doubleValue] <=
|
|
400
|
-
createdAt.doubleValue + CodexThreadCreationSlack) preceding = key;
|
|
497
|
+
NSArray *arguments = ProcessArguments([entry[@"pid"] intValue]);
|
|
498
|
+
NSUInteger resume = [arguments indexOfObject:@"resume"];
|
|
499
|
+
if (resume != NSNotFound && resume + 1 < arguments.count && [arguments[resume + 1] isEqual:thread]) {
|
|
500
|
+
[resumed addObject:key];
|
|
401
501
|
}
|
|
402
|
-
if (preceding) return preceding;
|
|
403
502
|
}
|
|
404
|
-
return
|
|
503
|
+
if (resumed.count > 0) return resumed.count == 1 ? resumed.firstObject : nil;
|
|
504
|
+
NSString *ready = ReadyCodexLaunch(launches, sameDirectory, createdAt, codexHome);
|
|
505
|
+
if (ready) return ready;
|
|
506
|
+
return sameDirectory.count == 1 ? sameDirectory.firstObject : nil;
|
|
405
507
|
}
|
|
406
508
|
|
|
407
|
-
NSDictionary *
|
|
509
|
+
static NSDictionary *CodexLaunchTerminalForThreadAtHome(NSString *thread, NSDictionary *payload,
|
|
510
|
+
NSString *codexHome) {
|
|
408
511
|
if (thread.length == 0) return @{};
|
|
409
512
|
int lock = LockCodexLaunchRegistry();
|
|
410
513
|
if (lock < 0) return @{};
|
|
@@ -417,8 +520,8 @@ NSDictionary *CodexLaunchTerminalForThread(NSString *thread, NSDictionary *paylo
|
|
|
417
520
|
}
|
|
418
521
|
}
|
|
419
522
|
if (!terminal) {
|
|
420
|
-
NSDictionary *meta = CodexThreadMeta(thread, payload);
|
|
421
|
-
NSString *key = meta[@"cwd"] ? ChooseCodexLaunch(launches, meta[@"cwd"], meta[@"createdAt"]) : nil;
|
|
523
|
+
NSDictionary *meta = CodexThreadMeta(thread, payload, codexHome);
|
|
524
|
+
NSString *key = meta[@"cwd"] ? ChooseCodexLaunch(launches, meta[@"cwd"], meta[@"createdAt"], thread, codexHome) : nil;
|
|
422
525
|
if (key) {
|
|
423
526
|
NSMutableDictionary *entry = [launches[key] mutableCopy];
|
|
424
527
|
NSMutableArray *threads = [entry[@"threads"] mutableCopy] ?: [NSMutableArray array];
|
|
@@ -434,8 +537,17 @@ NSDictionary *CodexLaunchTerminalForThread(NSString *thread, NSDictionary *paylo
|
|
|
434
537
|
return [terminal isKindOfClass:NSDictionary.class] ? terminal : @{};
|
|
435
538
|
}
|
|
436
539
|
|
|
540
|
+
NSDictionary *CodexLaunchTerminalForThread(NSString *thread, NSDictionary *payload) {
|
|
541
|
+
return CodexLaunchTerminalForThreadAtHome(thread, payload, DefaultCodexHomeDirectory());
|
|
542
|
+
}
|
|
543
|
+
|
|
437
544
|
NSDictionary *TerminalFocusTargetForHook(NSDictionary *payload, NSString *provider) {
|
|
438
545
|
if (!TerminalFocusRunsUnderSharedAgentHost()) return TerminalFocusTargetFromEnvironment();
|
|
439
546
|
if (![provider isEqualToString:@"Codex"]) return @{};
|
|
440
|
-
|
|
547
|
+
// 是路径,不能走 SanitizedShortString:它会删掉 `/`,拼出一个不存在的目录。
|
|
548
|
+
NSString *profileHome = NSProcessInfo.processInfo.environment[@"CC_PETS_PROFILE_HOME"];
|
|
549
|
+
profileHome = [profileHome isKindOfClass:NSString.class] && profileHome.isAbsolutePath
|
|
550
|
+
? profileHome.stringByStandardizingPath : nil;
|
|
551
|
+
return CodexLaunchTerminalForThreadAtHome(
|
|
552
|
+
SanitizedShortString(payload[@"session_id"], 128), payload, profileHome);
|
|
441
553
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#import <Cocoa/Cocoa.h>
|
|
2
|
+
|
|
3
|
+
// AppleScript 精确跳转的终端(终端 / iTerm2 / Ghostty)在设置页的检测结果。
|
|
4
|
+
// 每行:name、bundleID、version、group(@"apple" 或 @"ghostty")、state:
|
|
5
|
+
// granted 已允许 CC Pets 自动化控制
|
|
6
|
+
// notDetermined 尚未询问;首次跳转时系统会弹窗
|
|
7
|
+
// denied 已拒绝;跳转只能激活应用
|
|
8
|
+
// notRunning 应用未运行,无法查询授权
|
|
9
|
+
// unsupported 版本过低,不支持按 TTY 定位(Ghostty < 1.4)
|
|
10
|
+
// 未安装的终端不出现;系统自带的终端始终在。查询不会弹授权窗口,但可能短暂阻塞,在后台线程调用。
|
|
11
|
+
NSArray<NSDictionary *> *CCPetsTerminalIntegrationSnapshot(void);
|
|
12
|
+
|
|
13
|
+
// 主动请求自动化授权(应用需在运行,会弹系统窗口)。在后台执行,完成后在主线程回调。
|
|
14
|
+
void CCPetsRequestTerminalAutomation(NSString *bundleID, void (^completion)(void));
|
|
15
|
+
|
|
16
|
+
// 打开 系统设置 → 隐私与安全性 → 自动化。
|
|
17
|
+
void CCPetsOpenAutomationSettings(void);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#import "CCPetsTerminalIntegration.h"
|
|
2
|
+
#import <CoreServices/CoreServices.h>
|
|
3
|
+
|
|
4
|
+
static NSString *const GhosttyBundleID = @"com.mitchellh.ghostty";
|
|
5
|
+
// Ghostty 1.4 起在 AppleScript 字典里暴露 terminal 的 tty。
|
|
6
|
+
static NSString *const GhosttyMinimumVersion = @"1.4";
|
|
7
|
+
|
|
8
|
+
static NSString *AutomationState(NSString *bundleID, BOOL askUserIfNeeded) {
|
|
9
|
+
NSAppleEventDescriptor *target = [NSAppleEventDescriptor descriptorWithBundleIdentifier:bundleID];
|
|
10
|
+
OSStatus status = AEDeterminePermissionToAutomateTarget(target.aeDesc, typeWildCard, typeWildCard, askUserIfNeeded);
|
|
11
|
+
switch (status) {
|
|
12
|
+
case noErr: return @"granted";
|
|
13
|
+
case errAEEventNotPermitted: return @"denied";
|
|
14
|
+
case errAEEventWouldRequireUserConsent: return @"notDetermined";
|
|
15
|
+
case procNotFound: return @"notRunning";
|
|
16
|
+
default: return @"notDetermined";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static BOOL ApplicationIsRunning(NSString *bundleID) {
|
|
21
|
+
return [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID].count > 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
NSArray<NSDictionary *> *CCPetsTerminalIntegrationSnapshot(void) {
|
|
25
|
+
NSArray<NSArray<NSString *> *> *terminals = @[
|
|
26
|
+
@[@"com.apple.Terminal", @"apple"],
|
|
27
|
+
@[@"com.googlecode.iterm2", @"apple"],
|
|
28
|
+
@[GhosttyBundleID, @"ghostty"],
|
|
29
|
+
];
|
|
30
|
+
NSMutableArray *rows = [NSMutableArray array];
|
|
31
|
+
for (NSArray<NSString *> *terminal in terminals) {
|
|
32
|
+
NSString *bundleID = terminal[0];
|
|
33
|
+
NSURL *url = [NSWorkspace.sharedWorkspace URLForApplicationWithBundleIdentifier:bundleID];
|
|
34
|
+
if (!url) continue;
|
|
35
|
+
NSBundle *bundle = [NSBundle bundleWithURL:url];
|
|
36
|
+
NSString *name = [NSFileManager.defaultManager displayNameAtPath:url.path].stringByDeletingPathExtension;
|
|
37
|
+
NSString *version = [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
|
38
|
+
if (![version isKindOfClass:NSString.class]) version = @"";
|
|
39
|
+
NSString *state;
|
|
40
|
+
if ([bundleID isEqualToString:GhosttyBundleID] && version.length &&
|
|
41
|
+
[version compare:GhosttyMinimumVersion options:NSNumericSearch] == NSOrderedAscending) {
|
|
42
|
+
state = @"unsupported";
|
|
43
|
+
} else if (!ApplicationIsRunning(bundleID)) {
|
|
44
|
+
state = @"notRunning";
|
|
45
|
+
} else {
|
|
46
|
+
state = AutomationState(bundleID, NO);
|
|
47
|
+
}
|
|
48
|
+
[rows addObject:@{@"name": name ?: bundleID, @"bundleID": bundleID, @"version": version,
|
|
49
|
+
@"group": terminal[1], @"state": state}];
|
|
50
|
+
}
|
|
51
|
+
return rows;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void CCPetsRequestTerminalAutomation(NSString *bundleID, void (^completion)(void)) {
|
|
55
|
+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
|
|
56
|
+
if (ApplicationIsRunning(bundleID)) AutomationState(bundleID, YES);
|
|
57
|
+
if (completion) dispatch_async(dispatch_get_main_queue(), completion);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void CCPetsOpenAutomationSettings(void) {
|
|
62
|
+
NSURL *url = [NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Automation"];
|
|
63
|
+
[NSWorkspace.sharedWorkspace openURL:url];
|
|
64
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#import <Cocoa/Cocoa.h>
|
|
2
|
+
|
|
3
|
+
// VS Code and its forks (Cursor, Windsurf, VSCodium, …) via the bundled CC Pets Terminal
|
|
4
|
+
// extension. A fork is recognised by Contents/Resources/app/product.json, not by bundle ID.
|
|
5
|
+
|
|
6
|
+
// YES for an installed app of the VS Code family. Cheap enough for the main thread.
|
|
7
|
+
BOOL CCPetsBundleIsVSCodeFamily(NSString *bundleID);
|
|
8
|
+
|
|
9
|
+
// Snapshot (disk + authenticated loopback queries): call off the main thread.
|
|
10
|
+
// state: connected / installed / pendingRestart / outdated / missing / disabled / unsupported.
|
|
11
|
+
// autoInstall is YES when the app ships its command line tool, which does the install.
|
|
12
|
+
NSArray<NSDictionary *> *CCPetsVSCodeIntegrationSnapshot(void);
|
|
13
|
+
// Installs or updates the bundled VSIX through the app's own CLI. Blocking.
|
|
14
|
+
BOOL CCPetsInstallVSCodeExtension(NSDictionary *app, NSError **error);
|
|
15
|
+
// Confirms, installs in the background and reports failures; falls back to the manual
|
|
16
|
+
// installer when autoInstall is NO. completion runs on the main thread.
|
|
17
|
+
void CCPetsPromptInstallVSCodeExtension(NSDictionary *app, void (^completion)(void));
|
|
18
|
+
// Reveals the bundled VSIX and explains "Install from VSIX…".
|
|
19
|
+
void CCPetsShowVSCodeExtensionInstaller(NSString *appName);
|
|
20
|
+
|
|
21
|
+
// Exact focus for a VS Code family target. NO when no connected window of that app could
|
|
22
|
+
// own the terminal, so the caller falls back to bringing the app forward.
|
|
23
|
+
BOOL CCPetsRequestVSCodeTerminalFocus(NSDictionary *target);
|