Describe the need
Context
- On 2026-02-26, @edburns met with @SteveSandersonMS regarding the initial state of divergence between the reference implementations and the then-private Java SDK.
- One important aspect of divergence: the reference implementations had recently switched to using classical code gen from the Zod schema for the RPC handler layers.
- The Java implementation, by contrast, uses the agentic workflow to reduce toil in keeping the Java SDK in synch with the .NET and TypeScript reference implementations (See agentic workflow).
In other words, the Java implementation relies on the fact that the reference implementation on which the agentic workflow operates has already had its code-gen run.
Work in this work-item endeavors to develop and deploy an analogous code-gen system to the one used in the reference implementations.
Requirements
-
The source data on which the code gen operates are two JSON Schema files produced by the copilot-agent-runtime repo and distributed via the @github/copilot npm package:
session-events.schema.json — generated from the Zod schemas in src/core/sessionEvent.ts. Defines the session event type hierarchy.
api.schema.json — generated from the Zod schemas in src/core/sharedApi/ (~30 files defining the JSON-RPC API surface). Defines RPC method signatures, request/response types, and handler interfaces.
The Java codegen consumes these two JSON Schema files (not the Zod sources directly), matching the approach used by the dotnet, nodejs, and python codegen scripts in copilot-sdk/scripts/codegen/.
-
There is a CI/CD workflow in copilot-sdk-java that supports an analogous flow to the following flow in copilot-sdk:
- Someone changes the Zod schemas in
copilot-agent-runtime → a new version of @github/copilot is published.
- A human triggers the new "Update @github/copilot Dependency" workflow, based on
copilot-sdk with the new version.
- The workflow regenerates code and opens a PR automatically to
copilot-sdk-java.
- A new workflow based on the
codegen-check CI job in copilot-sdk validates the generated files match on that PR (and on main).
Copilot advice
High level advice
-
Do this work on a topic branch that includes the string dd-2751554-code-gen.
-
Derive it entirely from the way it's done for the dotnet and nodejs reference implementations in https://github.com/github/copilot-sdk .
-
It is acceptable to make breaking changes in copilot-sdk-java to make it so the named classes generated by the code-gen match, as closely as possible modulo Java naming conventions, the names of the corresponding classes in the dotnet and nodejs in the reference implementations.
Generated file placement and packaging
-
Place all generated Java source files under src/generated/java, separate from hand-authored code in java.
-
Organize generated files into sub-packages based on their schema source:
| Schema source |
Java package |
Directory |
session-events.schema.json |
com.github.copilot.sdk.generated |
src/generated/java/com/github/copilot/sdk/generated/ |
api.schema.json |
com.github.copilot.sdk.generated.rpc |
src/generated/java/com/github/copilot/sdk/generated/rpc/ |
Indicators that files are code-generated
Apply all of the following markers to generated files, consistent with the patterns used by the dotnet, nodejs, and python SDKs in the reference repo:
| Indicator |
Detail |
| Source root |
Files reside under src/generated/java, not java |
| Package name |
com.github.copilot.sdk.generated (session events) and com.github.copilot.sdk.generated.rpc (RPC types) |
| File header comment |
// AUTO-GENERATED FILE - DO NOT EDIT followed by // Generated from: session-events.schema.json or // Generated from: api.schema.json |
| .gitattributes |
src/generated/java/** eol=lf linguist-generated=true |
| Linting/formatting exclusion |
Exclude src/generated/java/** from Checkstyle and Spotless plugins |
@Generated annotation |
Apply @javax.annotation.processing.Generated("copilot-sdk-codegen") to each generated class |
Maven configuration
Add src/generated/java as an additional source root using the build-helper-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.1</version>
<executions>
<execution>
<id>add-generated-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/generated/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
SDK Version
0.2.1-java.1
Relevant log output
Code of Conduct
Internal issue
https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2751554
Describe the need
Context
In other words, the Java implementation relies on the fact that the reference implementation on which the agentic workflow operates has already had its code-gen run.
Work in this work-item endeavors to develop and deploy an analogous code-gen system to the one used in the reference implementations.
Requirements
The source data on which the code gen operates are two JSON Schema files produced by the
copilot-agent-runtimerepo and distributed via the@github/copilotnpm package:session-events.schema.json— generated from the Zod schemas insrc/core/sessionEvent.ts. Defines the session event type hierarchy.api.schema.json— generated from the Zod schemas insrc/core/sharedApi/(~30 files defining the JSON-RPC API surface). Defines RPC method signatures, request/response types, and handler interfaces.The Java codegen consumes these two JSON Schema files (not the Zod sources directly), matching the approach used by the dotnet, nodejs, and python codegen scripts in
copilot-sdk/scripts/codegen/.There is a CI/CD workflow in
copilot-sdk-javathat supports an analogous flow to the following flow incopilot-sdk:copilot-agent-runtime→ a new version of@github/copilotis published.copilot-sdkwith the new version.copilot-sdk-java.codegen-checkCI job incopilot-sdkvalidates the generated files match on that PR (and onmain).Copilot advice
High level advice
Do this work on a topic branch that includes the string
dd-2751554-code-gen.Derive it entirely from the way it's done for the
dotnetandnodejsreference implementations in https://github.com/github/copilot-sdk .It is acceptable to make breaking changes in
copilot-sdk-javato make it so the named classes generated by the code-gen match, as closely as possible modulo Java naming conventions, the names of the corresponding classes in thedotnetandnodejsin the reference implementations.Generated file placement and packaging
Place all generated Java source files under
src/generated/java, separate from hand-authored code in java.Organize generated files into sub-packages based on their schema source:
session-events.schema.jsoncom.github.copilot.sdk.generatedsrc/generated/java/com/github/copilot/sdk/generated/api.schema.jsoncom.github.copilot.sdk.generated.rpcsrc/generated/java/com/github/copilot/sdk/generated/rpc/Indicators that files are code-generated
Apply all of the following markers to generated files, consistent with the patterns used by the dotnet, nodejs, and python SDKs in the reference repo:
src/generated/java, not javacom.github.copilot.sdk.generated(session events) andcom.github.copilot.sdk.generated.rpc(RPC types)// AUTO-GENERATED FILE - DO NOT EDITfollowed by// Generated from: session-events.schema.jsonor// Generated from: api.schema.jsonsrc/generated/java/** eol=lf linguist-generated=truesrc/generated/java/**from Checkstyle and Spotless plugins@Generatedannotation@javax.annotation.processing.Generated("copilot-sdk-codegen")to each generated classMaven configuration
Add
src/generated/javaas an additional source root using thebuild-helper-maven-plugin:SDK Version
0.2.1-java.1
Relevant log output
Code of Conduct
Internal issue
https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2751554