cc-pets 2.3.0 → 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.
Files changed (76) hide show
  1. package/CC_BRIDGE.md +19 -0
  2. package/CC_BRIDGE.zh-CN.md +15 -0
  3. package/CHANGELOG.md +51 -0
  4. package/CHANGELOG.zh-CN.md +51 -0
  5. package/CONTRIBUTING.md +22 -0
  6. package/CONTRIBUTING.zh-CN.md +17 -0
  7. package/README.md +117 -26
  8. package/README.zh-CN.md +92 -22
  9. package/Resources/AgentIcons/claude.png +0 -0
  10. package/Resources/AgentIcons/codex.icns +0 -0
  11. package/Resources/IDEPlugins/cc-pets-terminal.vsix +0 -0
  12. package/Resources/IDEPlugins/cc-pets-terminal.zip +0 -0
  13. package/Resources/zh-Hans.lproj/Localizable.strings +155 -27
  14. package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +12 -6
  15. package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +1 -1
  16. package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +3 -6
  17. package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +113 -47
  18. package/Sources/CCPets/App/CCPetsAppDelegate.h +2 -2
  19. package/Sources/CCPets/App/main.m +6 -0
  20. package/Sources/CCPets/Bridge/CCPetsBridge.m +11 -6
  21. package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +78 -38
  22. package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +2 -3
  23. package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +50 -32
  24. package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +46 -40
  25. package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +9 -6
  26. package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +171 -53
  27. package/Sources/CCPets/Integrations/CCPetsIDEIntegration.h +21 -0
  28. package/Sources/CCPets/Integrations/CCPetsIDEIntegration.m +503 -0
  29. package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.h +5 -0
  30. package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +367 -0
  31. package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +2 -1
  32. package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +107 -25
  33. package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.h +17 -0
  34. package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.m +64 -0
  35. package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.h +23 -0
  36. package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.m +475 -0
  37. package/Sources/CCPets/Pet/PetView+Menu.m +2 -2
  38. package/Sources/CCPets/Support/CCPetsDoctor.m +26 -12
  39. package/Sources/CCPets/Support/CCPetsPreferences.h +2 -0
  40. package/Sources/CCPets/Support/CCPetsPreferences.m +34 -2
  41. package/Sources/CCPets/UI/CCPetsFormBuilder.h +2 -0
  42. package/Sources/CCPets/UI/CCPetsFormBuilder.m +18 -7
  43. package/Sources/CCPets/UI/CCPetsGlassView.h +26 -4
  44. package/Sources/CCPets/UI/CCPetsGlassView.m +40 -9
  45. package/Sources/CCPets/UI/CCPetsSettingsPage.h +2 -0
  46. package/Sources/CCPets/UI/CCPetsSettingsPage.m +561 -66
  47. package/Sources/CCPets/UI/CCPetsUIStyle.h +5 -2
  48. package/Sources/CCPets/UI/CCPetsUIStyle.m +57 -8
  49. package/Sources/CCPets/UI/CCPetsUsageChartView.m +4 -0
  50. package/Sources/CCPets/UI/CCPetsUsagePage.m +23 -28
  51. package/Sources/CCPets/UI/CCPetsUsageStore.m +2 -2
  52. package/Sources/CCPets/Usage/CCPetsUsage+CodexBackground.m +193 -0
  53. package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +1 -0
  54. package/Sources/CCPets/Usage/CCPetsUsage+Models.m +49 -11
  55. package/Sources/CCPets/Usage/CCPetsUsage.h +3 -2
  56. package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +15 -17
  57. package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +11 -29
  58. package/Sources/CCPets/Usage/QuotaDashboardView.m +128 -2
  59. package/THIRD_PARTY_NOTICES.md +7 -3
  60. package/THIRD_PARTY_NOTICES.zh-CN.md +5 -1
  61. package/bin/claude-with-pet +2 -0
  62. package/bin/codex-with-pet +2 -0
  63. package/package.json +5 -1
  64. package/plugins/jetbrains/README.md +62 -0
  65. package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalBridge.java +379 -0
  66. package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalIdentity.java +24 -0
  67. package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalStartup.java +12 -0
  68. package/plugins/jetbrains/src/main/resources/META-INF/plugin.xml +23 -0
  69. package/plugins/jetbrains/src/main/resources/META-INF/pluginIcon.svg +380 -0
  70. package/plugins/vscode/README.md +63 -0
  71. package/plugins/vscode/extension.js +210 -0
  72. package/plugins/vscode/package.json +18 -0
  73. package/scripts/build-idea-plugin.sh +101 -0
  74. package/scripts/build-vscode-extension.sh +112 -0
  75. package/scripts/build.sh +24 -2
  76. package/scripts/compile-cached.zsh +133 -0
@@ -0,0 +1,379 @@
1
+ package com.ccpets.terminal;
2
+
3
+ import com.google.gson.Gson;
4
+ import com.google.gson.JsonObject;
5
+ import com.google.gson.JsonParser;
6
+ import com.intellij.ide.plugins.IdeaPluginDescriptor;
7
+ import com.intellij.ide.plugins.PluginManagerCore;
8
+ import com.intellij.openapi.Disposable;
9
+ import com.intellij.openapi.application.ApplicationInfo;
10
+ import com.intellij.openapi.application.ApplicationManager;
11
+ import com.intellij.openapi.application.ModalityState;
12
+ import com.intellij.openapi.application.PathManager;
13
+ import com.intellij.openapi.diagnostic.Logger;
14
+ import com.intellij.openapi.fileEditor.FileEditorManager;
15
+ import com.intellij.openapi.fileEditor.OpenFileDescriptor;
16
+ import com.intellij.openapi.extensions.PluginId;
17
+ import com.intellij.openapi.project.Project;
18
+ import com.intellij.openapi.project.ProjectManager;
19
+ import com.intellij.openapi.vfs.VirtualFile;
20
+ import com.intellij.openapi.wm.IdeFocusManager;
21
+ import com.intellij.openapi.wm.ToolWindow;
22
+ import com.intellij.openapi.wm.ToolWindowManager;
23
+ import com.intellij.openapi.wm.WindowManager;
24
+ import com.intellij.platform.eel.provider.EelProviderUtil;
25
+ import com.intellij.platform.eel.provider.LocalEelDescriptor;
26
+ import com.intellij.terminal.frontend.editor.TerminalViewVirtualFile;
27
+ import com.intellij.terminal.frontend.toolwindow.TerminalToolWindowTab;
28
+ import com.intellij.terminal.frontend.toolwindow.TerminalToolWindowTabsManager;
29
+ import com.intellij.terminal.frontend.toolwindow.TerminalToolWindowTabsManagerKt;
30
+ import com.intellij.terminal.frontend.view.TerminalView;
31
+ import com.intellij.ui.AppIcon;
32
+ import com.intellij.ui.content.Content;
33
+ import com.sun.net.httpserver.HttpExchange;
34
+ import com.sun.net.httpserver.HttpServer;
35
+ import org.jetbrains.plugins.terminal.session.TerminalStartupOptions;
36
+
37
+ import java.io.IOException;
38
+ import java.net.InetAddress;
39
+ import java.net.InetSocketAddress;
40
+ import java.nio.charset.StandardCharsets;
41
+ import java.nio.file.Files;
42
+ import java.nio.file.Path;
43
+ import java.nio.file.StandardCopyOption;
44
+ import java.nio.file.attribute.PosixFilePermissions;
45
+ import java.security.MessageDigest;
46
+ import java.util.ArrayList;
47
+ import java.util.HashSet;
48
+ import java.util.List;
49
+ import java.util.Map;
50
+ import java.util.Set;
51
+ import java.util.UUID;
52
+ import java.util.concurrent.ArrayBlockingQueue;
53
+ import java.util.concurrent.CompletableFuture;
54
+ import java.util.concurrent.ThreadPoolExecutor;
55
+ import java.util.concurrent.TimeUnit;
56
+
57
+ /** One authenticated loopback endpoint per IDE process; disposed on plugin unload. */
58
+ public final class TerminalBridge implements Disposable {
59
+ private static final Logger LOG = Logger.getInstance(TerminalBridge.class);
60
+ private static final Gson JSON = new Gson();
61
+ public final String instanceID = UUID.randomUUID().toString();
62
+ private final String token = UUID.randomUUID() + "-" + UUID.randomUUID();
63
+ private HttpServer server;
64
+ private ThreadPoolExecutor workers;
65
+ private Path registration;
66
+ private volatile boolean disposed;
67
+
68
+ public static TerminalBridge getInstance() {
69
+ return ApplicationManager.getApplication().getService(TerminalBridge.class);
70
+ }
71
+
72
+ public synchronized boolean start() {
73
+ if (disposed || !System.getProperty("os.name", "").startsWith("Mac")) return false;
74
+ if (server != null) return true;
75
+ try {
76
+ Path directory = Path.of(System.getProperty("user.home"), "Library", "Application Support",
77
+ "CC Pets", "ide-instances");
78
+ Files.createDirectories(directory);
79
+ if (Files.isSymbolicLink(directory)) throw new IOException("Invalid bridge directory");
80
+ Files.setPosixFilePermissions(directory, PosixFilePermissions.fromString("rwx------"));
81
+ server = HttpServer.create(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0), 8);
82
+ workers = new ThreadPoolExecutor(1, 2, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(16), task -> {
83
+ Thread thread = new Thread(task, "CC Pets Terminal Bridge");
84
+ thread.setDaemon(true);
85
+ return thread;
86
+ });
87
+ server.setExecutor(workers);
88
+ server.createContext("/", this::handle);
89
+ server.start();
90
+ JsonObject record = status();
91
+ record.addProperty("port", server.getAddress().getPort());
92
+ record.addProperty("token", token);
93
+ record.addProperty("appPath", Path.of(PathManager.getHomePath()).getParent().toString());
94
+ record.addProperty("configPath", PathManager.getConfigPath());
95
+ record.addProperty("pluginsPath", PathManager.getPluginsPath());
96
+ registration = directory.resolve(instanceID + ".json");
97
+ Path temporary = Files.createTempFile(directory, ".registration-", ".tmp",
98
+ PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-------")));
99
+ try {
100
+ Files.writeString(temporary, JSON.toJson(record));
101
+ Files.move(temporary, registration, StandardCopyOption.ATOMIC_MOVE);
102
+ } finally {
103
+ Files.deleteIfExists(temporary);
104
+ }
105
+ return true;
106
+ } catch (Exception error) {
107
+ LOG.warn("Could not start CC Pets terminal bridge", error);
108
+ stop();
109
+ return false;
110
+ }
111
+ }
112
+
113
+ /** CC Pets compares this with the version on disk to detect a pending restart. */
114
+ private static String pluginVersion() {
115
+ IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("com.ccpets.terminal"));
116
+ return descriptor != null && descriptor.getVersion() != null ? descriptor.getVersion() : "unknown";
117
+ }
118
+
119
+ private JsonObject status() {
120
+ JsonObject record = new JsonObject();
121
+ record.addProperty("schemaVersion", 1);
122
+ record.addProperty("pluginVersion", pluginVersion());
123
+ record.addProperty("instanceID", instanceID);
124
+ record.addProperty("pid", ProcessHandle.current().pid());
125
+ record.addProperty("ideVersion", ApplicationInfo.getInstance().getFullVersion());
126
+ return record;
127
+ }
128
+
129
+ private void handle(HttpExchange exchange) throws IOException {
130
+ try (exchange) {
131
+ String authorization = exchange.getRequestHeaders().getFirst("Authorization");
132
+ if (!"POST".equals(exchange.getRequestMethod()) ||
133
+ exchange.getRequestHeaders().containsKey("Origin") || authorization == null ||
134
+ !MessageDigest.isEqual(("Bearer " + token).getBytes(StandardCharsets.UTF_8),
135
+ authorization.getBytes(StandardCharsets.UTF_8))) {
136
+ reply(exchange, 403, Map.of("error", "unauthorized"));
137
+ return;
138
+ }
139
+ String path = exchange.getRequestURI().getPath();
140
+ if ("/status".equals(path)) {
141
+ reply(exchange, 200, status());
142
+ return;
143
+ }
144
+ if (!"/focus".equals(path)) {
145
+ reply(exchange, 404, Map.of("error", "unknown_route"));
146
+ return;
147
+ }
148
+ byte[] body = exchange.getRequestBody().readNBytes(4097);
149
+ if (body.length > 4096) {
150
+ reply(exchange, 413, Map.of("error", "request_too_large"));
151
+ return;
152
+ }
153
+ try {
154
+ JsonObject request = JsonParser.parseString(new String(body, StandardCharsets.UTF_8)).getAsJsonObject();
155
+ String terminalID = string(request, "terminalID");
156
+ String tty = string(request, "tty").replaceFirst("^/dev/", "");
157
+ if (!(terminalID.matches("[a-fA-F0-9-]{36}") || tty.matches("ttys[0-9]{1,8}"))) {
158
+ reply(exchange, 400, Map.of("error", "invalid_target"));
159
+ return;
160
+ }
161
+ long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(3);
162
+ List<Target> targets = snapshot();
163
+ List<Target> matches = new ArrayList<>();
164
+ for (Target target : targets) {
165
+ if (System.nanoTime() > deadline) throw new java.util.concurrent.TimeoutException();
166
+ if (!terminalID.isEmpty()) {
167
+ if (terminalID.equals(target.terminalID)) matches.add(target);
168
+ } else if (tty.equals(ttyForProcess(target.pid))) {
169
+ matches.add(target);
170
+ }
171
+ }
172
+ if (matches.size() != 1) {
173
+ reply(exchange, matches.isEmpty() ? 404 : 409,
174
+ Map.of("error", matches.isEmpty() ? "terminal_not_found" : "ambiguous_target"));
175
+ return;
176
+ }
177
+ long remaining = deadline - System.nanoTime();
178
+ if (remaining <= 0) throw new java.util.concurrent.TimeoutException();
179
+ boolean focused = focus(matches.getFirst(), deadline).get(remaining, TimeUnit.NANOSECONDS);
180
+ reply(exchange, focused ? 200 : 409, Map.of("focused", focused));
181
+ } catch (java.util.concurrent.TimeoutException error) {
182
+ reply(exchange, 503, Map.of("error", "ide_busy"));
183
+ } catch (IllegalArgumentException | IllegalStateException error) {
184
+ reply(exchange, 400, Map.of("error", "invalid_request"));
185
+ } catch (Exception error) {
186
+ LOG.warn("CC Pets terminal focus failed", error);
187
+ reply(exchange, 500, Map.of("error", "focus_failed"));
188
+ }
189
+ }
190
+ }
191
+
192
+ private static String string(JsonObject object, String key) {
193
+ return object.has(key) && object.get(key).isJsonPrimitive() ? object.get(key).getAsString() : "";
194
+ }
195
+
196
+ /** Exactly one of tab (Terminal tool window) or file (moved to an editor tab) is set. */
197
+ private record Target(Project project, TerminalToolWindowTab tab, VirtualFile file, TerminalView view,
198
+ Long pid, String terminalID) {}
199
+
200
+ private static void addTarget(List<Target> targets, Project project, TerminalToolWindowTab tab,
201
+ VirtualFile file, TerminalView view) {
202
+ var options = view.getStartupOptionsDeferred();
203
+ if (!options.isCompleted() || options.isCancelled()) return;
204
+ TerminalStartupOptions startup = options.getCompleted();
205
+ targets.add(new Target(project, tab, file, view, startup.getPid(),
206
+ startup.getEnvVariables().getOrDefault("CC_PETS_IDE_TERMINAL_ID", "")));
207
+ }
208
+
209
+ /**
210
+ * Terminals shown in the editor area. Two mechanisms exist:
211
+ * - "Move to Editor" (2026.2+) opens a TerminalViewVirtualFile.
212
+ * - "Open as Editor Tab" (2026.3+) moves the tool window Content itself into a platform
213
+ * editor tab. The Content is read through editorContent() and mapped back with
214
+ * getTerminalTab(Content).
215
+ */
216
+ private static void addEditorTargets(List<Target> targets, Project project) {
217
+ FileEditorManager editors = FileEditorManager.getInstance(project);
218
+ for (VirtualFile file : editors.getOpenFiles()) {
219
+ try {
220
+ if (file instanceof TerminalViewVirtualFile terminal) {
221
+ addTarget(targets, project, null, file, terminal.getTab().getView());
222
+ continue;
223
+ }
224
+ Content content = editorContent(project, file);
225
+ TerminalToolWindowTab tab = content == null ? null : TerminalToolWindowTabsManagerKt.getTerminalTab(content);
226
+ if (tab != null) addTarget(targets, project, null, file, tab.getView());
227
+ } catch (LinkageError | RuntimeException error) {
228
+ // Internal editor-tab API changed: tool window terminals keep working.
229
+ LOG.debug("Terminal editor tab skipped", error);
230
+ }
231
+ }
232
+ }
233
+
234
+ private static final String EDITOR_TAB_FILE = "com.intellij.openapi.wm.impl.tabInEditor.ToolWindowEditorTabFile";
235
+ private static final String EDITOR_TAB_MANAGER = "com.intellij.openapi.wm.impl.tabInEditor.ToolWindowEditorTabManager";
236
+
237
+ /**
238
+ * The tool window Content shown by a 2026.3 "Open as Editor Tab" file:
239
+ * ToolWindowEditorTabManager.getInstance(project).getSession(file).getContent().
240
+ * All three are public, but the classes only exist from 2026.3, hence reflection.
241
+ */
242
+ private static Content editorContent(Project project, VirtualFile file) {
243
+ if (!EDITOR_TAB_FILE.equals(file.getClass().getName())) return null;
244
+ try {
245
+ Class<?> managerClass = Class.forName(EDITOR_TAB_MANAGER, false, file.getClass().getClassLoader());
246
+ Object manager = managerClass.getMethod("getInstance", Project.class).invoke(null, project);
247
+ Object session = managerClass.getMethod("getSession", file.getClass()).invoke(manager, file);
248
+ if (session == null) return null;
249
+ Object content = session.getClass().getMethod("getContent").invoke(session);
250
+ return content instanceof Content value ? value : null;
251
+ } catch (ReflectiveOperationException | LinkageError error) {
252
+ LOG.debug("Terminal editor tab content unavailable", error);
253
+ return null;
254
+ }
255
+ }
256
+
257
+ private List<Target> snapshot() throws Exception {
258
+ CompletableFuture<List<Target>> result = new CompletableFuture<>();
259
+ ApplicationManager.getApplication().invokeLater(() -> {
260
+ if (disposed || result.isDone()) return;
261
+ try {
262
+ List<Target> targets = new ArrayList<>();
263
+ for (Project project : ProjectManager.getInstance().getOpenProjects()) {
264
+ if (project.isDisposed() ||
265
+ !(EelProviderUtil.getEelDescriptor(project) instanceof LocalEelDescriptor)) continue;
266
+ // Editor-area terminals first; a moved tab must not also match as a tool window tab.
267
+ int firstEditorTarget = targets.size();
268
+ addEditorTargets(targets, project);
269
+ Set<TerminalView> inEditor = new HashSet<>();
270
+ for (Target target : targets.subList(firstEditorTarget, targets.size())) inEditor.add(target.view);
271
+ for (TerminalToolWindowTab tab : TerminalToolWindowTabsManager.getInstance(project).getTabs()) {
272
+ if (!inEditor.contains(tab.getView())) addTarget(targets, project, tab, null, tab.getView());
273
+ }
274
+ }
275
+ result.complete(targets);
276
+ } catch (Throwable error) {
277
+ result.completeExceptionally(error);
278
+ }
279
+ }, ModalityState.nonModal());
280
+ try {
281
+ return result.get(800, TimeUnit.MILLISECONDS);
282
+ } finally {
283
+ result.cancel(false);
284
+ }
285
+ }
286
+
287
+ private static String ttyForProcess(Long pid) throws Exception {
288
+ if (pid == null || pid <= 0) return "";
289
+ Process process = new ProcessBuilder("/bin/ps", "-p", Long.toString(pid), "-o", "tty=").start();
290
+ try {
291
+ if (!process.waitFor(150, TimeUnit.MILLISECONDS)) return "";
292
+ return new String(process.getInputStream().readNBytes(128), StandardCharsets.UTF_8).trim();
293
+ } finally {
294
+ if (process.isAlive()) process.destroyForcibly();
295
+ }
296
+ }
297
+
298
+ private CompletableFuture<Boolean> focus(Target target, long deadline) {
299
+ CompletableFuture<Boolean> result = new CompletableFuture<>();
300
+ ApplicationManager.getApplication().invokeLater(() -> {
301
+ try {
302
+ if (disposed || target.project.isDisposed() || System.nanoTime() > deadline) {
303
+ result.complete(false);
304
+ return;
305
+ }
306
+ if (target.file != null) {
307
+ result.complete(focusEditor(target));
308
+ return;
309
+ }
310
+ Content content = target.tab.getContent();
311
+ ToolWindow window = ToolWindowManager.getInstance(target.project).getToolWindow("Terminal");
312
+ if (content.getManager() == null || window == null ||
313
+ !TerminalToolWindowTabsManager.getInstance(target.project).getTabs().contains(target.tab)) {
314
+ result.complete(false);
315
+ return;
316
+ }
317
+ var frame = WindowManager.getInstance().getFrame(target.project);
318
+ if (frame != null) AppIcon.getInstance().requestFocus(frame);
319
+ window.activate(() -> {
320
+ try {
321
+ if (disposed || target.project.isDisposed() || content.getManager() == null ||
322
+ System.nanoTime() > deadline) {
323
+ result.complete(false);
324
+ return;
325
+ }
326
+ content.getManager().setSelectedContent(content, true);
327
+ IdeFocusManager.getInstance(target.project)
328
+ .requestFocus(target.tab.getView().getPreferredFocusableComponent(), true);
329
+ result.complete(true);
330
+ } catch (RuntimeException error) {
331
+ result.completeExceptionally(error);
332
+ }
333
+ }, true, true);
334
+ } catch (RuntimeException error) {
335
+ result.completeExceptionally(error);
336
+ }
337
+ }, ModalityState.nonModal());
338
+ return result;
339
+ }
340
+
341
+ /** Runs on the EDT. Selects the editor tab (in whichever window holds it) and focuses its input. */
342
+ private static boolean focusEditor(Target target) {
343
+ FileEditorManager editors = FileEditorManager.getInstance(target.project);
344
+ if (!editors.isFileOpen(target.file)) return false;
345
+ var frame = WindowManager.getInstance().getFrame(target.project);
346
+ if (frame != null) AppIcon.getInstance().requestFocus(frame);
347
+ // Reuses the tab wherever it is open, including a detached editor window.
348
+ new OpenFileDescriptor(target.project, target.file).navigate(true);
349
+ var component = target.view.getPreferredFocusableComponent();
350
+ var window = javax.swing.SwingUtilities.getWindowAncestor(component);
351
+ if (window != null) window.toFront();
352
+ IdeFocusManager.getInstance(target.project).requestFocus(component, true);
353
+ return true;
354
+ }
355
+
356
+ private static void reply(HttpExchange exchange, int code, Object body) throws IOException {
357
+ byte[] bytes = JSON.toJson(body).getBytes(StandardCharsets.UTF_8);
358
+ exchange.getResponseHeaders().set("Content-Type", "application/json; charset=utf-8");
359
+ exchange.getResponseHeaders().set("Cache-Control", "no-store");
360
+ exchange.sendResponseHeaders(code, bytes.length);
361
+ exchange.getResponseBody().write(bytes);
362
+ }
363
+
364
+ private synchronized void stop() {
365
+ if (server != null) server.stop(0);
366
+ server = null;
367
+ if (workers != null) workers.shutdownNow();
368
+ workers = null;
369
+ if (registration != null) {
370
+ try { Files.deleteIfExists(registration); }
371
+ catch (IOException error) { LOG.warn("Could not remove CC Pets registration", error); }
372
+ }
373
+ }
374
+
375
+ @Override public void dispose() {
376
+ disposed = true;
377
+ stop();
378
+ }
379
+ }
@@ -0,0 +1,24 @@
1
+ package com.ccpets.terminal;
2
+
3
+ import com.intellij.openapi.project.Project;
4
+ import com.intellij.platform.eel.EelDescriptor;
5
+ import com.intellij.platform.eel.provider.LocalEelDescriptor;
6
+ import org.jetbrains.plugins.terminal.LocalTerminalCustomizer;
7
+ import java.util.List;
8
+ import java.util.Map;
9
+ import java.util.UUID;
10
+
11
+ /** Identity belongs to a terminal, not its title, working directory, or active window. */
12
+ @SuppressWarnings("deprecation")
13
+ public final class TerminalIdentity extends LocalTerminalCustomizer {
14
+ @Override public List<String> customizeCommandAndEnvironment(Project project, String directory,
15
+ List<String> command, Map<String, String> environment, EelDescriptor descriptor) {
16
+ if (!(descriptor instanceof LocalEelDescriptor)) return command;
17
+ TerminalBridge bridge = TerminalBridge.getInstance();
18
+ if (bridge.start()) {
19
+ environment.put("CC_PETS_IDE_INSTANCE_ID", bridge.instanceID);
20
+ environment.put("CC_PETS_IDE_TERMINAL_ID", UUID.randomUUID().toString());
21
+ }
22
+ return command;
23
+ }
24
+ }
@@ -0,0 +1,12 @@
1
+ package com.ccpets.terminal;
2
+
3
+ import com.intellij.openapi.project.Project;
4
+ import com.intellij.openapi.startup.StartupActivity;
5
+
6
+ /** Also starts the bridge for terminals opened before this plugin was installed. */
7
+ @SuppressWarnings("deprecation")
8
+ public final class TerminalStartup implements StartupActivity.DumbAware {
9
+ @Override public void runActivity(Project project) {
10
+ TerminalBridge.getInstance().start();
11
+ }
12
+ }
@@ -0,0 +1,23 @@
1
+ <idea-plugin>
2
+ <id>com.ccpets.terminal</id>
3
+ <name>CC Pets Terminal</name>
4
+ <version>0.1.0</version>
5
+ <vendor url="https://github.com/Sunnyshinnny776/cc-pets">CC Pets</vendor>
6
+ <description><![CDATA[
7
+ Jump from a CC Pets agent card to its JetBrains IDE terminal tab.
8
+ Supports local Reworked terminals on macOS in IntelliJ-based IDEs 2026.2 and 2026.3
9
+ (IntelliJ IDEA, PyCharm, WebStorm, GoLand, CLion, PhpStorm, RubyMine, Rider, etc.).
10
+ Connects automatically to CC Pets over authenticated localhost communication.
11
+ Does not read terminal output or execute shell commands in your sessions.
12
+ ]]></description>
13
+ <idea-version since-build="262" until-build="263.*"/>
14
+ <depends>com.intellij.modules.platform</depends>
15
+ <depends>org.jetbrains.plugins.terminal</depends>
16
+ <extensions defaultExtensionNs="com.intellij">
17
+ <applicationService serviceImplementation="com.ccpets.terminal.TerminalBridge"/>
18
+ <postStartupActivity implementation="com.ccpets.terminal.TerminalStartup"/>
19
+ </extensions>
20
+ <extensions defaultExtensionNs="org.jetbrains.plugins.terminal">
21
+ <localTerminalCustomizer implementation="com.ccpets.terminal.TerminalIdentity"/>
22
+ </extensions>
23
+ </idea-plugin>