Repository navigation
[FEAT]: Add classical code-gen to workflow #69
Description
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.
- 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).
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:- Someone changes the Zod schemas in
copilot-agent-runtime→ a new version of@github/copilotis published. - A human triggers the new "Update @github/copilot Dependency" workflow, based on
copilot-sdkwith the new version. - The workflow regenerates code and opens a PR automatically to
copilot-sdk-java. - A new workflow based on the
codegen-checkCI job incopilot-sdkvalidates the generated files match on that PR (and onmain).
- Someone changes the Zod schemas in
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:
Schema source Java package Directory 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:
| 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
- I agree to follow this project's Code of Conduct
Internal issue
https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2751554
Activity
brunoborges commentedon Apr 14, 2026
@edburns is the goal to replace the Copilot-generated types?
Add @JsonInclude(NON_NULL) to all generated event classes and warn on…
edburns commentedon Apr 14, 2026
@brunoborges the goal is to use the schema artifacts shipped in the
@github/copilotnpm package in the same manner as thedotnetandnodejsuses them, andgit rmas much of our existing code as possible in the process.edburns commentedon Apr 14, 2026
Saving these work prompts here.
69-02-enhance-java-ts-to-generate-typed-rpc-wrappers.md
69-03-wire-the-generated-wrappers-into-sdk.md
69-01-replace-events-with-generated.md