Skip to content

[FEAT]: Add classical code-gen to workflow #69

@edburns

Description

@edburns

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:

    1. session-events.schema.json — generated from the Zod schemas in src/core/sessionEvent.ts. Defines the session event type hierarchy.
    2. 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:

    1. Someone changes the Zod schemas in copilot-agent-runtime → a new version of @github/copilot is published.
    2. A human triggers the new "Update @github/copilot Dependency" workflow, based oncopilot-sdk with the new version.
    3. The workflow regenerates code and opens a PR automatically to copilot-sdk-java.
    4. 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

  • I agree to follow this project's Code of Conduct

Internal issue

https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2751554

Metadata

Metadata

Labels

No labels
No labels

Type

No fields configured for Epic.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions