Skip to content

feat(adapter): add JetBrains Copilot adapter#327

Open
murataslan1 wants to merge 15 commits intomksglu:nextfrom
murataslan1:feat/jetbrains-copilot-adapter
Open

feat(adapter): add JetBrains Copilot adapter#327
murataslan1 wants to merge 15 commits intomksglu:nextfrom
murataslan1:feat/jetbrains-copilot-adapter

Conversation

@murataslan1
Copy link
Copy Markdown

@murataslan1 murataslan1 commented Apr 22, 2026

Closes #321

Summary

  • Adds src/adapters/jetbrains-copilot/ with hooks.ts, index.ts, config.ts — mirrors the vscode-copilot adapter pattern
  • Detects JetBrains 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
  • Adds configs/jetbrains-copilot/mcp.json example config using npx -y context-mode
  • Adds docs/jetbrains-copilot.md setup guide

Session Report

Full implementation notes: https://gist.github.com/murataslan1/048277ac524e7e042a10dd2aca8ebdb1

Test plan

  • npm run build exits 0 with no TypeScript errors
  • context-mode doctor in a JetBrains project reports adapter detected
  • .idea/mcp.json with npx -y context-mode registers the MCP server correctly
  • Hook scripts resolve to hooks/jetbrains-copilot/*.mjs

Copilot AI review requested due to automatic review settings April 22, 2026 19:16
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.
@murataslan1 murataslan1 force-pushed the feat/jetbrains-copilot-adapter branch from df55be1 to d60b073 Compare April 22, 2026 19:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-copilot adapter 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.json config.

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.

Comment on lines 17 to +20
"Visual-Studio-Code": "vscode-copilot",
"JetBrains Client": "jetbrains-copilot",
"IntelliJ IDEA": "jetbrains-copilot",
"PyCharm": "jetbrains-copilot",
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +81
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()}`;
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread docs/jetbrains-copilot.md
Comment on lines +29 to +33
## 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`.
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
## 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.

Copilot uses AI. Check for mistakes.
Comment thread src/adapters/detect.ts
Comment on lines +129 to +139
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",
};
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@mksglu mksglu changed the base branch from main to next April 22, 2026 19:36
@mksglu
Copy link
Copy Markdown
Owner

mksglu commented Apr 22, 2026

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: add instructions for using context-mode with Jetbrains Copilot plugin

3 participants