Skip to content

Conversation

@brunoborges
Copy link

This Java implementation is based on the .NET and Node implementations.

@brunoborges brunoborges marked this pull request as ready for review January 19, 2026 21:33
@brunoborges brunoborges requested a review from a team as a code owner January 19, 2026 21:33
Copilot AI review requested due to automatic review settings January 19, 2026 21:33
@brunoborges
Copy link
Author

@SteveSandersonMS hey Steve, here goes the Java implementation (based on the .NET and Node implementations)

Copy link
Contributor

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

This PR implements a Java SDK for GitHub Copilot, providing a complete Java interface to interact with the Copilot CLI. The implementation follows the patterns established in the .NET and Node.js SDKs.

Changes:

  • Adds comprehensive Java SDK with client, session, and event handling capabilities
  • Implements JSON-RPC communication layer for CLI interaction
  • Adds complete test suite with E2E test infrastructure using CapiProxy for deterministic testing

Reviewed changes

Copilot reviewed 95 out of 95 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
justfile Adds Java build targets for formatting, linting, testing, and dependency installation
java/src/test/java/.../ToolsTest.java Tests for custom tools functionality including invocation, error handling, and complex types
java/src/test/java/.../PermissionsTest.java Tests for permission callback functionality with various approval scenarios
java/src/test/java/.../McpAndAgentsTest.java Tests for MCP server and custom agent configuration
java/src/test/java/.../CopilotSessionTest.java Comprehensive session lifecycle and interaction tests
java/src/test/java/.../CopilotClientTest.java Client initialization and connection tests
java/src/test/java/.../E2ETestContext.java Test harness managing CapiProxy, directories, and test environment
java/src/test/java/.../CapiProxy.java Proxy server manager for deterministic API response replay
java/src/main/java/.../json/*.java JSON model classes for requests, responses, and configuration
java/src/main/java/.../events/*.java Event classes representing all session events from the CLI
java/src/main/java/.../JsonRpcClient.java JSON-RPC 2.0 client for CLI communication
java/src/main/java/.../SdkProtocolVersion.java Protocol version constants
java/.mvn/wrapper/maven-wrapper.properties Maven wrapper configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

} catch (Exception e) {
LOG.log(Level.SEVERE, "Error handling tool call", e);
try {
rpc.sendErrorResponse(Long.parseLong(requestId), -32603, e.getMessage());
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Potential uncaught 'java.lang.NumberFormatException'.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback


session.handlePermissionRequest(permissionRequest).thenAccept(result -> {
try {
rpc.sendResponse(Long.parseLong(requestId), Map.of("result", result));
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Potential uncaught 'java.lang.NumberFormatException'.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

try {
PermissionRequestResult result = new PermissionRequestResult()
.setKind("denied-no-approval-rule-and-could-not-request-from-user");
rpc.sendResponse(Long.parseLong(requestId), Map.of("result", result));
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Potential uncaught 'java.lang.NumberFormatException'.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Comment on lines 669 to 670
detectedPort = Integer.parseInt(matcher.group(1));
break;
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Potential uncaught 'java.lang.NumberFormatException'.

Suggested change
detectedPort = Integer.parseInt(matcher.group(1));
break;
try {
detectedPort = Integer.parseInt(matcher.group(1));
break;
} catch (NumberFormatException e) {
LOG.log(Level.WARNING, "Failed to parse port from CLI output: " + line, e);
}

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@SteveSandersonMS
Copy link
Contributor

SteveSandersonMS commented Jan 19, 2026

Thanks @brunoborges.

I hope you don't mind, but we've discussed it on the team, and for now we prefer other language SDKs to be handled as external projects by their own maintainers rather than being merged into this repo.

The reason is we are trying to keep evolving both the CLI and its SDK at a high rate and we have a finite maintenance budget for per-language concerns. Handling four languages is already quite a process each time a new feature or API design is added. We'll soon clarify this in the README - i.e., that for now, we're not looking for extra languages to be added here, and would love to recommend external community-mainained projects for other repos.

Would you mind closing this or is it OK if I do so?

Do you plan to maintain this Java SDK in an external repo? If so we'd love to link to it from our README.md as a recommended approach for anyone using that technology stack.

@brunoborges
Copy link
Author

I'll move the project to my personal account.

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.

2 participants