From 2c74ffad891b3315274998ae730d1878145ea135 Mon Sep 17 00:00:00 2001 From: Ed Burns Date: Tue, 16 Jun 2026 19:27:51 -0400 Subject: [PATCH] Generate package-info.java for generated packages Fixes #1694 ## java/scripts/codegen/java.ts - Added `generateGeneratedPackageInfo()` to emit `package-info.java` for the `com.github.copilot.generated` package. Includes Javadoc describing session event types, key classes (`SessionEvent`, `UnknownSessionEvent`), a usage example, and cross-references to related packages. - Added `generateRpcPackageInfo()` to emit `package-info.java` for the `com.github.copilot.generated.rpc` package. Includes Javadoc describing RPC parameter/result types, key classes (`RpcCaller`, `ServerRpc`, `SessionRpc`), and cross-references. - Updated `main()` to call both new functions after existing generation steps. The files are regenerated on each run since the output directory is cleaned first. ## java/src/generated/java/com/github/copilot/generated/package-info.java - New auto-generated file. Provides package-level Javadoc for the session event types package, following the same style as the hand-written `com.github.copilot` package-info. ## java/src/generated/java/com/github/copilot/generated/rpc/package-info.java - New auto-generated file. Provides package-level Javadoc for the RPC types package, following the same style as the hand-written `com.github.copilot` package-info. --- java/scripts/codegen/java.ts | 101 ++++++++++++++++++ .../copilot/generated/package-info.java | 45 ++++++++ .../copilot/generated/rpc/package-info.java | 38 +++++++ 3 files changed, 184 insertions(+) create mode 100644 java/src/generated/java/com/github/copilot/generated/package-info.java create mode 100644 java/src/generated/java/com/github/copilot/generated/rpc/package-info.java diff --git a/java/scripts/codegen/java.ts b/java/scripts/codegen/java.ts index 842ba772e..89fea8930 100644 --- a/java/scripts/codegen/java.ts +++ b/java/scripts/codegen/java.ts @@ -2053,6 +2053,101 @@ async function generateRpcWrappers(schemaPath: string): Promise { console.log(`✅ RPC wrapper classes generated`); } +// ── Package-info generation ────────────────────────────────────────────────── + +async function generateGeneratedPackageInfo(packageDir: string): Promise { + const lines: string[] = []; + lines.push(COPYRIGHT); + lines.push(""); + lines.push(AUTO_GENERATED_HEADER); + lines.push(GENERATED_FROM_SESSION_EVENTS); + lines.push(""); + lines.push(`/**`); + lines.push(` * Auto-generated session event types for the GitHub Copilot SDK.`); + lines.push(` *`); + lines.push(` *

`); + lines.push(` * This package contains Java classes generated from the Copilot CLI's`); + lines.push(` * {@code session-events.schema.json}. Each event type corresponds to a`); + lines.push(` * notification emitted during a {@link com.github.copilot.CopilotSession}`); + lines.push(` * interaction.`); + lines.push(` *`); + lines.push(` *

Key Classes

`); + lines.push(` *
    `); + lines.push(` *
  • {@link com.github.copilot.generated.SessionEvent} - Abstract sealed base`); + lines.push(` * class for all session events. Deserialized polymorphically via the`); + lines.push(` * {@code type} discriminator.
  • `); + lines.push(` *
  • {@link com.github.copilot.generated.UnknownSessionEvent} - Fallback for`); + lines.push(` * event types not yet known to this SDK version, preserving forward`); + lines.push(` * compatibility.
  • `); + lines.push(` *
`); + lines.push(` *`); + lines.push(` *

Example Usage

`); + lines.push(` *`); + lines.push(` *
{@code`);
+    lines.push(` * session.on(AssistantMessageEvent.class, msg -> {`);
+    lines.push(` *     System.out.println(msg.getData().content());`);
+    lines.push(` * });`);
+    lines.push(` * }
`); + lines.push(` *`); + lines.push(` *

Related Packages

`); + lines.push(` *
    `); + lines.push(` *
  • {@link com.github.copilot} - Core SDK classes
  • `); + lines.push(` *
  • {@link com.github.copilot.generated.rpc} - Auto-generated RPC`); + lines.push(` * parameter and result types
  • `); + lines.push(` *
`); + lines.push(` *`); + lines.push(` * @see com.github.copilot.CopilotSession`); + lines.push(` * @see com.github.copilot.generated.SessionEvent`); + lines.push(` */`); + lines.push(`package com.github.copilot.generated;`); + lines.push(""); + + await writeGeneratedFile(`${packageDir}/package-info.java`, lines.join("\n")); +} + +async function generateRpcPackageInfo(packageDir: string): Promise { + const lines: string[] = []; + lines.push(COPYRIGHT); + lines.push(""); + lines.push(AUTO_GENERATED_HEADER); + lines.push(GENERATED_FROM_API); + lines.push(""); + lines.push(`/**`); + lines.push(` * Auto-generated RPC parameter and result types for the GitHub Copilot SDK.`); + lines.push(` *`); + lines.push(` *

`); + lines.push(` * This package contains Java records and classes generated from the Copilot`); + lines.push(` * CLI's {@code api.schema.json}. These types represent the request parameters`); + lines.push(` * and response payloads for all JSON-RPC methods exposed by the CLI.`); + lines.push(` *`); + lines.push(` *

Key Classes

`); + lines.push(` *
    `); + lines.push(` *
  • {@link com.github.copilot.generated.rpc.RpcCaller} - Functional interface`); + lines.push(` * for invoking JSON-RPC methods with typed responses.
  • `); + lines.push(` *
  • {@link com.github.copilot.generated.rpc.ServerRpc} - Typed client for`); + lines.push(` * server-level RPC methods (session management, model listing, etc.).
  • `); + lines.push(` *
  • {@link com.github.copilot.generated.rpc.SessionRpc} - Typed client for`); + lines.push(` * session-scoped RPC methods (send messages, manage tools, etc.). Automatically`); + lines.push(` * injects the {@code sessionId} into every call.
  • `); + lines.push(` *
`); + lines.push(` *`); + lines.push(` *

Related Packages

`); + lines.push(` *
    `); + lines.push(` *
  • {@link com.github.copilot} - Core SDK classes
  • `); + lines.push(` *
  • {@link com.github.copilot.generated} - Auto-generated session event`); + lines.push(` * types
  • `); + lines.push(` *
`); + lines.push(` *`); + lines.push(` * @see com.github.copilot.CopilotClient`); + lines.push(` * @see com.github.copilot.generated.rpc.ServerRpc`); + lines.push(` * @see com.github.copilot.generated.rpc.SessionRpc`); + lines.push(` */`); + lines.push(`package com.github.copilot.generated.rpc;`); + lines.push(""); + + await writeGeneratedFile(`${packageDir}/package-info.java`, lines.join("\n")); +} + // ── Main entry point ────────────────────────────────────────────────────────── async function main(): Promise { @@ -2074,6 +2169,12 @@ async function main(): Promise { await generateRpcTypes(apiSchemaPath); await generateRpcWrappers(apiSchemaPath); + // Generate package-info.java for each generated package + const generatedPkgDir = `src/generated/java/com/github/copilot/generated`; + const rpcPkgDir = `src/generated/java/com/github/copilot/generated/rpc`; + await generateGeneratedPackageInfo(generatedPkgDir); + await generateRpcPackageInfo(rpcPkgDir); + console.log("\n✅ Java code generation complete!"); } diff --git a/java/src/generated/java/com/github/copilot/generated/package-info.java b/java/src/generated/java/com/github/copilot/generated/package-info.java new file mode 100644 index 000000000..f2bfcd269 --- /dev/null +++ b/java/src/generated/java/com/github/copilot/generated/package-info.java @@ -0,0 +1,45 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------------------------------------------*/ + +// AUTO-GENERATED FILE - DO NOT EDIT +// Generated from: session-events.schema.json + +/** + * Auto-generated session event types for the GitHub Copilot SDK. + * + *

+ * This package contains Java classes generated from the Copilot CLI's + * {@code session-events.schema.json}. Each event type corresponds to a + * notification emitted during a {@link com.github.copilot.CopilotSession} + * interaction. + * + *

Key Classes

+ *
    + *
  • {@link com.github.copilot.generated.SessionEvent} - Abstract sealed base + * class for all session events. Deserialized polymorphically via the + * {@code type} discriminator.
  • + *
  • {@link com.github.copilot.generated.UnknownSessionEvent} - Fallback for + * event types not yet known to this SDK version, preserving forward + * compatibility.
  • + *
+ * + *

Example Usage

+ * + *
{@code
+ * session.on(AssistantMessageEvent.class, msg -> {
+ *     System.out.println(msg.getData().content());
+ * });
+ * }
+ * + *

Related Packages

+ *
    + *
  • {@link com.github.copilot} - Core SDK classes
  • + *
  • {@link com.github.copilot.generated.rpc} - Auto-generated RPC + * parameter and result types
  • + *
+ * + * @see com.github.copilot.CopilotSession + * @see com.github.copilot.generated.SessionEvent + */ +package com.github.copilot.generated; diff --git a/java/src/generated/java/com/github/copilot/generated/rpc/package-info.java b/java/src/generated/java/com/github/copilot/generated/rpc/package-info.java new file mode 100644 index 000000000..8248ee188 --- /dev/null +++ b/java/src/generated/java/com/github/copilot/generated/rpc/package-info.java @@ -0,0 +1,38 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------------------------------------------*/ + +// AUTO-GENERATED FILE - DO NOT EDIT +// Generated from: api.schema.json + +/** + * Auto-generated RPC parameter and result types for the GitHub Copilot SDK. + * + *

+ * This package contains Java records and classes generated from the Copilot + * CLI's {@code api.schema.json}. These types represent the request parameters + * and response payloads for all JSON-RPC methods exposed by the CLI. + * + *

Key Classes

+ *
    + *
  • {@link com.github.copilot.generated.rpc.RpcCaller} - Functional interface + * for invoking JSON-RPC methods with typed responses.
  • + *
  • {@link com.github.copilot.generated.rpc.ServerRpc} - Typed client for + * server-level RPC methods (session management, model listing, etc.).
  • + *
  • {@link com.github.copilot.generated.rpc.SessionRpc} - Typed client for + * session-scoped RPC methods (send messages, manage tools, etc.). Automatically + * injects the {@code sessionId} into every call.
  • + *
+ * + *

Related Packages

+ *
    + *
  • {@link com.github.copilot} - Core SDK classes
  • + *
  • {@link com.github.copilot.generated} - Auto-generated session event + * types
  • + *
+ * + * @see com.github.copilot.CopilotClient + * @see com.github.copilot.generated.rpc.ServerRpc + * @see com.github.copilot.generated.rpc.SessionRpc + */ +package com.github.copilot.generated.rpc;