Skip to content

Commit d9a6fab

Browse files
edburnsCopilotgithub-actions[bot]
authored
[java] Add linux-x64 implementation of in process Copilot CLI (#2301)
* feat(java): embed Rust CLI runtime as native module Squashed from PR #2295 (branch edburns/…-review-02). Includes Java multi-module Maven restructure, copilot-native submodule for bundling the Rust CLI runtime, codegen updates, and related workflow changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 90cbda40-cda3-4ecd-b381-9f9ba0573d0a * java: add flatten-maven-plugin to produce self-contained deployed POMs Child modules (copilot-sdk-java, copilot-sdk-java-runtime) inherit from copilot-sdk-java-parent, which is not published to Maven Central. Without flattening, consumers resolving a child artifact would fail to resolve the parent POM. The flatten-maven-plugin (ossrh mode) inlines all inherited metadata so the deployed POM is fully self-contained. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * java: only release callback GC root after successful connection_close Previously the tracked callback was removed in a finally block, releasing its GC root even when native connection_close failed or threw. Native code could still retain and invoke the stale function pointer, crashing the JVM after JNA collected the callback. Now the callback reference is only removed from trackedCallbacks when the native call succeeds, ensuring the function pointer stays rooted while native code may still hold it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * java: remove spike test library references, use real native runtime Remove CallbackTestLib interface and all tests that depended on the spike libcallback_test.so from the removed 1917-java-embed-rust-cli-runtime-remove-before-merge directory. Rewrite the 3 duplicate-load guard tests to use NativeRuntimeLoader.resolve() to locate the real runtime.node binary instead of the spike library. Remove the startWithSpikeLibrarySupportsLifecycleAndDataFlow integration test from FfiRuntimeHostTest — this functionality is covered by E2E tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * docs: add JNA dependency to in-process mode README snippet JNA is declared optional in the SDK POM so subprocess-mode users don't pull it transitively. The in-process mode section was missing this required third dependency, which would cause NoClassDefFoundError at runtime. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * java: add empty javadoc and sources JARs for copilot-native module Maven Central requires javadoc and sources classifier JARs for every non-POM artifact. Since copilot-native has no Java sources, the parent's maven-javadoc-plugin produced nothing. Add explicit empty-archive executions to maven-jar-plugin so the module passes Central validation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * java: use size_t-width type for native length parameters The C ABI declares all buffer-length parameters as size_t (8 bytes on 64-bit), but the Java FFI layer was using int (always 4 bytes). While harmless for current JSON-RPC payloads, this is incorrect on 64-bit platforms and would be wrong on Windows x64 where NativeLong (C long) is also only 4 bytes. Introduce SizeT, a minimal IntegerType subclass sized via Native.SIZE_T_SIZE, and use it in CopilotRuntimeLibrary and OutboundCallback. The NativeBinding Java abstraction layer keeps int parameters; JnaNativeBinding converts at the boundary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * java: remove global JNA callback exception handler The process-wide Native.setCallbackExceptionHandler was redundant: the local catch (Throwable) in createOutboundCallback() already prevents any exception from escaping across the FFI boundary. The global mutation affected unrelated JNA callbacks in the same process and was never restored. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * ci: make java-sdk-inprocess test job blocking Remove continue-on-error so FFI regressions in the in-process transport block PRs. The in-process transport is now production code and must not silently regress. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * fix: update jbang-example.java path after move to sdk/ submodule The JBang example moved from java/jbang-example.java to java/sdk/jbang-example.java but two references were not updated: the runnable JBang URL in README.md and the release workflow's update-documentation-versions script invocation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * docs: fix ADR relative links in README The ADRs are at java/docs/adr/, not java/sdk/docs/adr/. Fix the relative links for ADR-006 and ADR-004. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c * Regenerate Java codegen output Auto-committed by java-codegen-check workflow. * fix(java): retain JNA callbacks for process lifetime Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 108d08d4-0724-4414-bed8-2771b12b58de * fix(java): publish executable CLI atomically Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 108d08d4-0724-4414-bed8-2771b12b58de * docs(java): align native runtime ADR Document strict in-process selection, the implemented runtime resolution order, current artifact contents, and the intentionally narrow PATH compatibility fallback. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 108d08d4-0724-4414-bed8-2771b12b58de * fix(java): key native cache by runtime version Read the packaged native version before cache lookup so mutable SDK snapshot builds cannot reuse stale runtime and CLI artifacts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 108d08d4-0724-4414-bed8-2771b12b58de * fix(java): validate staged native artifacts Include the bundled CLI digest in the incremental staging stamp, require complete platform metadata, and verify the classifier JAR contains the CLI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 108d08d4-0724-4414-bed8-2771b12b58de * fix(java): complete Maven module migration Restore pre-migration dependency and plugin versions, publish correct child project metadata, and update repository consumers to the moved SDK paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 108d08d4-0724-4414-bed8-2771b12b58de --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Copilot-Session: 90cbda40-cda3-4ecd-b381-9f9ba0573d0a Copilot-Session: 3a69f33e-eea6-4b8c-9ef0-8b4d56d53a9c Copilot-Session: 108d08d4-0724-4414-bed8-2771b12b58de
1 parent a6d3ed1 commit d9a6fab

1,607 files changed

Lines changed: 7019 additions & 982 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.githooks/pre-commit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/sh
22
#
33
# Pre-commit hook that runs Spotless check on the Java SDK when Java source
4-
# files are staged. Only triggers if changes exist under java/src/.
4+
# files are staged. Only triggers if changes exist under java/sdk/src/.
55
#
66
# To install this hook, run from the repository root:
77
# git config core.hooksPath .githooks
88
#
99

10-
# Only run Spotless if staged changes include Java source files under java/src/
11-
if ! git diff --cached --name-only | grep -q '^java/src/'; then
10+
# Only run Spotless if staged changes include Java source files under java/sdk/src/
11+
if ! git diff --cached --name-only | grep -q '^java/sdk/src/'; then
1212
exit 0
1313
fi
1414

.github/actions/java-test-report/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ inputs:
44
report-path:
55
description: "Path to the test report XML files (glob pattern)"
66
required: false
7-
default: "java/target/{surefire-reports*,failsafe-reports}/TEST-*.xml"
7+
default: "java/sdk/target/{surefire-reports*,failsafe-reports}/TEST-*.xml"
88
jacoco-path:
99
description: "Path to the JaCoCo XML report"
1010
required: false
11-
default: "java/target/site/jacoco-coverage/jacoco.xml"
11+
default: "java/sdk/target/site/jacoco-coverage/jacoco.xml"
1212
jacoco-csv-path:
1313
description: "Path to the JaCoCo CSV report"
1414
required: false
15-
default: "java/target/site/jacoco-coverage/jacoco.csv"
15+
default: "java/sdk/target/site/jacoco-coverage/jacoco.csv"
1616
check-name:
1717
description: "Name for the check run"
1818
required: false

.github/copilot-instructions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
- Top-level: `README.md` (architecture + quick start)
1313
- Language entry points: `nodejs/src/client.ts`, `python/README.md`, `go/README.md`, `dotnet/README.md`
14-
- Java: `java/README.md`, `java/pom.xml`
14+
- Java: `java/README.md`, `java/pom.xml`, `java/sdk/pom.xml`, `java/copilot-native/pom.xml`
1515
- Test harness & E2E: `test/harness/*`, Python harness wrapper `python/e2e/testharness/proxy.py`
1616
- Schemas & type generation: `nodejs/scripts/generate-session-types.ts`
1717
- Session snapshots used by E2E: `test/snapshots/` (used by the replay proxy)
@@ -39,7 +39,7 @@
3939
- E2E runs against a local **replaying CAPI proxy** (see `test/harness/server.ts`). Most language E2E harnesses spawn that server automatically (see `python/e2e/testharness/proxy.py`).
4040
- Tests rely on YAML snapshot exchanges under `test/snapshots/` — to add test scenarios, add or edit the appropriate YAML files and update tests.
4141
- The harness prints `Listening: http://...` — tests parse this URL to configure CLI or proxy.
42-
- Java E2E tests use `E2ETestContext` which manages a `CapiProxy` (Node.js replaying proxy). The harness is cloned during Maven's `generate-test-resources` phase to `java/target/copilot-sdk/`.
42+
- Java E2E tests use `E2ETestContext` which manages a `CapiProxy` (Node.js replaying proxy). The harness is cloned during Maven's `generate-test-resources` phase to `java/sdk/target/copilot-sdk/`.
4343
- Java test method names are converted to lowercase snake_case for snapshot filenames (avoids case collisions on macOS/Windows).
4444

4545
## Project-specific conventions & patterns ✅
@@ -61,13 +61,13 @@
6161

6262
## Where to add new code or tests 🧭
6363

64-
- SDK code: `nodejs/src`, `python/copilot`, `go`, `dotnet/src`, `rust/src`, `java/src/main/java`
65-
- Unit tests: `nodejs/test`, `python/*`, `go/*`, `dotnet/test`, `rust/tests`, `java/src/test/java`
66-
- E2E tests: `*/e2e/` folders that use the shared replay proxy and `test/snapshots/`, `java/src/test/java/**/e2e/`
67-
- Generated types: update schema in `@github/copilot` then run `cd nodejs && npm run generate:session-types` and commit generated files in `src/generated` or language generated location. Java generated types: `java/src/generated/java`
64+
- SDK code: `nodejs/src`, `python/copilot`, `go`, `dotnet/src`, `rust/src`, `java/sdk/src/main/java`
65+
- Unit tests: `nodejs/test`, `python/*`, `go/*`, `dotnet/test`, `rust/tests`, `java/sdk/src/test/java`
66+
- E2E tests: `*/e2e/` folders that use the shared replay proxy and `test/snapshots/`, `java/sdk/src/test/java/**/e2e/`
67+
- Generated types: update schema in `@github/copilot` then run `cd nodejs && npm run generate:session-types` and commit generated files in `src/generated` or language generated location. Java generated types: `java/sdk/src/generated/java`
6868

6969
## Boundaries — files you must NOT hand-edit ⛔
7070

71-
- `java/src/generated/java/` — auto-generated by `scripts/codegen/java.ts`; regenerate with `cd java && mvn generate-sources -Pcodegen`.
71+
- `java/sdk/src/generated/java/` — auto-generated by `scripts/codegen/java.ts`; regenerate with `cd java && mvn generate-sources -Pcodegen`.
7272
- `nodejs/src/generated/` — auto-generated by `npm run generate:session-types`.
7373
- `test/snapshots/` — authoritative test fixtures; add/edit YAML here to change E2E behavior, but don't delete without understanding downstream impact.

.github/skills/new-java-e2e-test-yaml-and-test/SKILL.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ conversations:
5454

5555
### Step 3: Create the Java IT test class
5656

57-
Place it in `java/src/test/java/com/github/copilot/` with an `IT` suffix
57+
Place it in `java/sdk/src/test/java/com/github/copilot/` with an `IT` suffix
5858
(e.g., `MyFeatureIT.java`). The failsafe plugin picks up `*IT.java` files.
5959

6060
**Template:**
@@ -141,12 +141,12 @@ mvn clean verify
141141

142142
| What | Where |
143143
|------|-------|
144-
| Test context (manages proxy, workDir, CLI) | `java/src/test/java/com/github/copilot/E2ETestContext.java` |
145-
| Java proxy wrapper | `java/src/test/java/com/github/copilot/CapiProxy.java` |
144+
| Test context (manages proxy, workDir, CLI) | `java/sdk/src/test/java/com/github/copilot/E2ETestContext.java` |
145+
| Java proxy wrapper | `java/sdk/src/test/java/com/github/copilot/CapiProxy.java` |
146146
| Replay proxy (TypeScript) | `test/harness/replayingCapiProxy.ts` |
147147
| Proxy server entry point | `test/harness/server.ts` |
148148
| Snapshot files | `test/snapshots/<category>/<name>.yaml` |
149-
| Existing IT tests for reference | `java/src/test/java/com/github/copilot/*IT.java` |
149+
| Existing IT tests for reference | `java/sdk/src/test/java/com/github/copilot/*IT.java` |
150150

151151
## How the Proxy Matches Requests
152152

.github/workflows/codegen-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
- 'go/rpc/**'
1616
- 'rust/src/generated/**'
1717
- 'sdk-protocol-version.json'
18-
- 'java/src/main/java/com/github/copilot/SdkProtocolVersion.java'
18+
- 'java/sdk/src/main/java/com/github/copilot/SdkProtocolVersion.java'
1919
- '.github/workflows/codegen-check.yml'
2020
workflow_dispatch:
2121

@@ -84,7 +84,7 @@ jobs:
8484
- name: Verify Java protocol version matches
8585
run: |
8686
EXPECTED=$(jq -r '.version' sdk-protocol-version.json)
87-
ACTUAL=$(grep -oP 'LATEST\(\K[0-9]+' java/src/main/java/com/github/copilot/SdkProtocolVersion.java)
87+
ACTUAL=$(grep -oP 'LATEST\(\K[0-9]+' java/sdk/src/main/java/com/github/copilot/SdkProtocolVersion.java)
8888
if [ "$EXPECTED" != "$ACTUAL" ]; then
8989
echo "::error::Java SDK protocol version ($ACTUAL) does not match sdk-protocol-version.json ($EXPECTED). Java manages its own SdkProtocolVersion.java via java/scripts/codegen/. Update it to match."
9090
exit 1

.github/workflows/docs-validation.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ on:
99
- 'python/copilot/**'
1010
- 'go/**/*.go'
1111
- 'dotnet/src/**'
12-
- 'java/src/**'
12+
- 'java/sdk/src/**'
1313
- 'java/pom.xml'
14+
- 'java/sdk/pom.xml'
1415
- 'scripts/docs-validation/**'
1516
- '.github/workflows/docs-validation.yml'
1617
workflow_dispatch:

.github/workflows/java-adapt-handwritten-code-to-accept-upgrade-changes.lock.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/java-adapt-handwritten-code-to-accept-upgrade-changes.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ You are an automation agent that fixes handwritten Java SDK source and test code
5151

5252
- The branch `${{ inputs.branch }}` already has:
5353
- Updated `java/scripts/codegen/package.json` with the new version
54-
- Regenerated `java/src/generated/java/` code that compiles successfully
54+
- Regenerated `java/sdk/src/generated/java/` code that compiles successfully
5555
- Updated the Java POM CLI/version pin property
5656
- Your job is ONLY to fix **handwritten** code, NOT generated code.
5757

5858
## Boundaries
5959

60-
- ❌ Do NOT edit anything under `java/src/generated/java/`
60+
- ❌ Do NOT edit anything under `java/sdk/src/generated/java/`
6161
- ❌ Do NOT edit `java/scripts/codegen/java.ts`
62-
- ❌ Do NOT create or modify tests in the `com.github.copilot.generated` test package (`java/src/test/java/com/github/copilot/sdk/generated/`)
63-
- ✅ DO edit `java/src/main/java/com/github/copilot/sdk/**`
64-
- ✅ DO edit `java/src/test/java/com/github/copilot/sdk/**` (excluding the `generated` subpackage)
62+
- ❌ Do NOT create or modify tests in the `com.github.copilot.generated` test package (`java/sdk/src/test/java/com/github/copilot/sdk/generated/`)
63+
- ✅ DO edit `java/sdk/src/main/java/com/github/copilot/sdk/**`
64+
- ✅ DO edit `java/sdk/src/test/java/com/github/copilot/sdk/**` (excluding the `generated` subpackage)
6565
- ✅ DO add new test methods or test classes if new user-facing API surface is introduced
6666

6767
## Instructions
@@ -146,7 +146,7 @@ mvn verify -Dskip.test.harness=true
146146
If this passes, commit and push:
147147

148148
```bash
149-
git add java/src/main/java java/src/test/java
149+
git add java/sdk/src/main/java java/sdk/src/test/java
150150
git commit -m "Fix handwritten Java code for @github/copilot schema changes
151151
152152
Adapt constructor calls, enum references, and test assertions to match

.github/workflows/java-codegen-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ on:
66
- main
77
paths:
88
- 'java/scripts/codegen/**'
9-
- 'java/src/generated/**'
9+
- 'java/sdk/src/generated/**'
1010
- '.github/workflows/java-codegen-check.yml'
1111
pull_request:
1212
paths:
1313
- 'java/scripts/codegen/**'
14-
- 'java/src/generated/**'
14+
- 'java/sdk/src/generated/**'
1515
- '.github/workflows/java-codegen-check.yml'
1616
workflow_dispatch:
1717

.github/workflows/java-codegen-fix.lock.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)