| description | Weekly upstream sync workflow. Checks for new commits in the official Copilot SDK (github/copilot-sdk), analyzes changes, ports them to the Java SDK, runs tests, and creates a pull request with the ported changes. | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| true |
|
||||||||||||||||||||
| permissions |
|
||||||||||||||||||||
| network |
|
||||||||||||||||||||
| steps |
|
||||||||||||||||||||
| tools |
|
||||||||||||||||||||
| safe-outputs |
|
You are an expert Java developer. Your job is to check the official Copilot SDK (github/copilot-sdk) for new changes and port them to this Java SDK.
The current design and architecture of the Java SDK is the priority. When porting:
- Adapt, don't copy — Translate features to fit Java patterns, naming conventions, and architecture
- Preserve Java idioms — The SDK should feel natural to Java developers, not like a C# port
- Maintain consistency — New code must match the existing codebase style
- Evaluate before porting — Not every upstream change applies; some may conflict with Java SDK design
Before making any changes, read and understand the existing Java SDK implementation.
Run this to detect new commits:
LAST_MERGE=$(cat .lastmerge)
echo "Last merged commit: $LAST_MERGE"
git clone --depth=200 https://github.com/github/copilot-sdk.git /tmp/upstream-sdk
cd /tmp/upstream-sdk
UPSTREAM_HEAD=$(git rev-parse HEAD)
echo "Upstream HEAD: $UPSTREAM_HEAD"
if [ "$LAST_MERGE" = "$UPSTREAM_HEAD" ]; then
echo "NO_CHANGES=true"
else
COMMIT_COUNT=$(git rev-list --count "$LAST_MERGE".."$UPSTREAM_HEAD")
echo "Found $COMMIT_COUNT new upstream commits"
git log --oneline "$LAST_MERGE".."$UPSTREAM_HEAD"
fiIf there are NO new changes: Call the noop safe output with a message like "No new upstream changes detected. The Java SDK is up to date with commit <hash>." and stop.
Examine the upstream diff grouped by area:
cd /tmp/upstream-sdk
LAST_MERGE=$(cat $GITHUB_WORKSPACE/.lastmerge)
echo "=== .NET Source (primary reference) ==="
git diff --stat "$LAST_MERGE"..HEAD -- dotnet/src/
echo "=== .NET Tests ==="
git diff --stat "$LAST_MERGE"..HEAD -- dotnet/test/
echo "=== Test Snapshots ==="
git diff --stat "$LAST_MERGE"..HEAD -- test/snapshots/
echo "=== Documentation ==="
git diff --stat "$LAST_MERGE"..HEAD -- docs/
echo "=== Protocol / Config ==="
git diff --stat "$LAST_MERGE"..HEAD -- sdk-protocol-version.jsonFor each area with changes, read the full diffs:
git diff "$LAST_MERGE"..HEAD -- dotnet/src/
git diff "$LAST_MERGE"..HEAD -- dotnet/test/
git diff "$LAST_MERGE"..HEAD -- docs/For each upstream change, determine:
- New Features: New methods, classes, or capabilities
- Bug Fixes: Corrections to existing functionality
- API Changes: Changes to public interfaces
- Protocol Updates: JSON-RPC message type changes
- Test Updates: New or modified test cases
Use this mapping to locate the Java equivalents:
| Upstream (.NET) | Java SDK Equivalent |
|---|---|
dotnet/src/Client.cs |
src/main/java/com/github/copilot/sdk/CopilotClient.java |
dotnet/src/Session.cs |
src/main/java/com/github/copilot/sdk/CopilotSession.java |
dotnet/src/Types.cs |
src/main/java/com/github/copilot/sdk/types/*.java |
dotnet/src/Generated/*.cs |
src/main/java/com/github/copilot/sdk/types/*.java |
dotnet/test/*.cs |
src/test/java/com/github/copilot/sdk/*Test.java |
docs/getting-started.md |
README.md and src/site/markdown/*.md |
Read the existing Java implementation before modifying anything. Apply these conventions:
Type mappings:
string→String,Task<T>→CompletableFuture<T>,JsonElement→JsonNode(Jackson)- C# PascalCase → Java camelCase for methods/variables
- C#
async/await→CompletableFuture - C# properties → Java getters/setters or fluent setters
- C# nullable
?→@NullableorOptional<T>
Code style:
- 4-space indentation (enforced by Spotless with Eclipse formatter)
- Fluent setter pattern for configuration classes
- Jackson for JSON serialization (
ObjectMapper,@JsonProperty) @JsonInclude(JsonInclude.Include.NON_NULL)on DTOs- Public APIs require Javadoc (except
jsonandeventspackages)
Commit incrementally as you work:
git add <changed-files>
git commit -m "Port <feature/fix> from upstream"For each new or modified test in dotnet/test/:
- Create or update the corresponding Java test class in
src/test/java/com/github/copilot/sdk/ - Follow existing test patterns (look at
PermissionsTest.java,HooksTest.java) - Use
E2ETestContextfor tests requiring the test harness - If the test harness doesn't support new RPC methods yet, mark with
@Disabled("Requires test harness update")
Check the CLI version:
copilot --version 2>/dev/null || echo "CLI not available in CI"If the CLI version changed, update requirements in both README.md and src/site/markdown/index.md.
For each new feature ported:
README.md— Update if there are user-facing changessrc/site/markdown/documentation.md— New basic usage patternssrc/site/markdown/advanced.md— New advanced features- Javadoc — All new/changed public APIs
src/site/site.xml— Update if new pages added
mvn spotless:apply
mvn clean verifyIf tests fail:
- Read the error output carefully
- Fix the issue in the Java code
- Re-run
mvn clean verify - Repeat until all tests pass
Update .lastmerge with the upstream HEAD commit:
cd /tmp/upstream-sdk
UPSTREAM_HEAD=$(git rev-parse HEAD)
cd $GITHUB_WORKSPACE
echo "$UPSTREAM_HEAD" > .lastmerge
git add .lastmerge
git commit -m "Update .lastmerge to $(cat .lastmerge | cut -c1-12)"Create a pull request with your changes using the create-pull-request safe output. The PR body should include:
- Title:
Merge upstream SDK changes (YYYY-MM-DD) - Summary: Number of upstream commits analyzed with commit range
- Changes ported: Table of commit hash + description
- Not ported: List with reasons (if any)
- Verification: Test count, build status
- SECURITY: Never commit secrets, tokens, or credentials
- Use
try-with-resourcesfor streams and readers - Use
StandardCharsets.UTF_8when creating InputStreamReader/OutputStreamWriter - Prefer existing Java SDK abstractions over upstream .NET patterns
- When in doubt, match the style of surrounding Java code