feat(adapter): add JetBrains Copilot adapter#327
feat(adapter): add JetBrains Copilot adapter#327murataslan1 wants to merge 15 commits intomksglu:nextfrom
Conversation
Implements JetBrains Copilot adapter with detection via IDEA_INITIAL_DIRECTORY, IDEA_HOME, JETBRAINS_CLIENT_ID env vars and ~/.config/JetBrains/ config dir. Config stored in .idea/mcp.json; session storage in ~/.config/JetBrains/context-mode/sessions/. Registers IntelliJ IDEA, PyCharm, and JetBrains Client in the client map.
df55be1 to
d60b073
Compare
There was a problem hiding this comment.
Pull request overview
Adds a new JetBrains Copilot platform adapter to the adapters layer, enabling platform detection/config/doctor/upgrade flows for running context-mode hooks from JetBrains IDEs.
Changes:
- Adds
jetbrains-copilotadapter implementation (hooks/config/index) and registers the platform ID. - Extends platform detection and MCP client-name mapping to recognize JetBrains IDEs.
- Adds JetBrains-specific setup documentation and an example
.idea/mcp.jsonconfig.
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/adapters/types.ts | Adds jetbrains-copilot to the PlatformId union. |
| src/adapters/jetbrains-copilot/index.ts | Implements the JetBrains HookAdapter (parse/format/config/doctor/upgrade). |
| src/adapters/jetbrains-copilot/hooks.ts | Defines JetBrains hook types + command builder for hook invocation. |
| src/adapters/jetbrains-copilot/config.ts | Re-exports adapter + hook constants for compatibility. |
| src/adapters/detect.ts | Adds JetBrains env-var and config-dir based platform detection + adapter loader branch. |
| src/adapters/client-map.ts | Maps JetBrains MCP clientInfo.name values to jetbrains-copilot. |
| docs/jetbrains-copilot.md | Adds JetBrains setup guide. |
| configs/jetbrains-copilot/mcp.json | Provides example MCP server configuration for JetBrains projects. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "Visual-Studio-Code": "vscode-copilot", | ||
| "JetBrains Client": "jetbrains-copilot", | ||
| "IntelliJ IDEA": "jetbrains-copilot", | ||
| "PyCharm": "jetbrains-copilot", |
There was a problem hiding this comment.
New clientInfo.name mappings were added for JetBrains, but tests/adapters/client-map.test.ts currently only asserts a subset of mappings. Please add test cases for the new JetBrains keys (e.g., "JetBrains Client", "IntelliJ IDEA", "PyCharm") to prevent regressions in zero-config detection.
| export function buildHookCommand(hookType: HookType, pluginRoot?: string): string { | ||
| const scriptName = HOOK_SCRIPTS[hookType]; | ||
| if (!scriptName) { | ||
| throw new Error(`No script defined for hook type: ${hookType}`); | ||
| } | ||
| if (pluginRoot) { | ||
| return `node "${pluginRoot}/hooks/jetbrains-copilot/${scriptName}"`; | ||
| } | ||
| return `context-mode hook jetbrains-copilot ${hookType.toLowerCase()}`; | ||
| } |
There was a problem hiding this comment.
buildHookCommand generates (a) pluginRoot-based commands referencing ${pluginRoot}/hooks/jetbrains-copilot/<script>.mjs and (b) a CLI dispatcher command context-mode hook jetbrains-copilot .... Currently the repo has no hooks/jetbrains-copilot/ wrappers, and the CLI hook dispatcher (src/cli.ts HOOK_MAP) does not register jetbrains-copilot, so either command form will fail at runtime. To make this adapter usable, add JetBrains hook wrapper scripts (similar to hooks/vscode-copilot/*), register them in the CLI hook map, and ensure hook response formatting/tool naming is wired for jetbrains-copilot (e.g., hooks/core/formatters + hooks/core/tool-naming).
| ## 3) Verify | ||
|
|
||
| - Restart the IDE after creating `.idea/mcp.json`. | ||
| - Run `context-mode doctor` in the project directory. | ||
| - Confirm MCP registration reports `context-mode found in .idea/mcp.json`. |
There was a problem hiding this comment.
The setup guide only configures the MCP server, but context-mode doctor for this adapter also validates that .idea/mcp.json contains hooks.PreToolUse and hooks.SessionStart entries. As written, following this doc will likely produce failing hook diagnostics. Add a step to run context-mode upgrade (or document the required hooks JSON entries) so the guide results in a passing doctor output.
| ## 3) Verify | |
| - Restart the IDE after creating `.idea/mcp.json`. | |
| - Run `context-mode doctor` in the project directory. | |
| - Confirm MCP registration reports `context-mode found in .idea/mcp.json`. | |
| ## 3) Upgrade the project config | |
| Run `context-mode upgrade` in the project directory to add any required entries, including the `hooks.PreToolUse` and `hooks.SessionStart` configuration that `context-mode doctor` validates for this adapter. | |
| ## 4) Verify | |
| - Restart the IDE after creating or upgrading `.idea/mcp.json`. | |
| - Run `context-mode doctor` in the project directory. | |
| - Confirm doctor reports `context-mode found in .idea/mcp.json` and that the hook diagnostics pass. |
| if ( | ||
| process.env.IDEA_INITIAL_DIRECTORY | ||
| || process.env.IDEA_HOME | ||
| || process.env.JETBRAINS_CLIENT_ID | ||
| ) { | ||
| return { | ||
| platform: "jetbrains-copilot", | ||
| confidence: "high", | ||
| reason: "IDEA_INITIAL_DIRECTORY, IDEA_HOME, or JETBRAINS_CLIENT_ID env var set", | ||
| }; | ||
| } |
There was a problem hiding this comment.
Platform detection logic was extended for JetBrains, but the repository has thorough adapter detection tests (tests/adapters/detect.test.ts). Add/extend tests to cover IDEA_INITIAL_DIRECTORY / IDEA_HOME / JETBRAINS_CLIENT_ID env var detection and the ~/.config/JetBrains fallback so this behavior is exercised in CI.
|
Let's resolve conflicts, add Unit Tests, update Readme and the other docs. Did you test that also? Is that support that fully hooks? Is that same with exist Copilot? |
Closes #321
Summary
src/adapters/jetbrains-copilot/withhooks.ts,index.ts,config.ts— mirrors thevscode-copilotadapter patternIDEA_INITIAL_DIRECTORY,IDEA_HOME,JETBRAINS_CLIENT_IDenv vars and~/.config/JetBrains/config dir.idea/mcp.json; session storage in~/.config/JetBrains/context-mode/sessions/IntelliJ IDEA,PyCharm, andJetBrains Clientin the client mapconfigs/jetbrains-copilot/mcp.jsonexample config usingnpx -y context-modedocs/jetbrains-copilot.mdsetup guideSession Report
Full implementation notes: https://gist.github.com/murataslan1/048277ac524e7e042a10dd2aca8ebdb1
Test plan
npm run buildexits 0 with no TypeScript errorscontext-mode doctorin a JetBrains project reports adapter detected.idea/mcp.jsonwithnpx -y context-moderegisters the MCP server correctlyhooks/jetbrains-copilot/*.mjs