Skip to content

Proposal: more context for Java in copilot-instructions. #1390

Description

@edburns

Since the addition of Java to the monorepo, I judge it might be useful to add some more Java changes to the copilot-instructions file, above and beyond those already there.

Here's what I'd add, section by section. The Boundaries is super important, based on my experience in maintaining https://github.com/github/copilot-sdk-java primarily with a low-toil agentic process.


Developer workflows — after the existing Java testing note, add individual test commands:

  - Java single test: `cd java && mvn test -Dtest=CopilotClientTest` | single method: `mvn test -Dtest=ToolsTest#testToolInvocation`
  - Java format check only: `mvn spotless:check` | Build without tests: `mvn clean package -DskipTests`

Testing & E2E tips — append a bullet about Java snapshot naming:

- Java test method names are converted to lowercase snake_case for snapshot filenames (avoids case collisions on macOS/Windows).

Project-specific conventions & patterns — add two bullets:

- Java code style: 4-space indent (Spotless + Eclipse formatter), fluent setter pattern for config classes, Javadoc required on public APIs (enforced by Checkstyle, except `json`/`events` packages).
- Java handlers return `CompletableFuture` (the Java equivalent of C# `async/await`). When porting from .NET: convert properties → getters/fluent setters, use Jackson (`ObjectMapper`, `@JsonProperty`) for serialization.

Integration & environment notes — add a bullet about pre-commit hooks:

- Java pre-commit hook runs `mvn spotless:check`. Enable with `git config core.hooksPath .githooks` (auto-enabled in Copilot coding agent environment via `copilot-setup-steps.yml`).

New section — add a "Boundaries / DO NOT modify" section (this applies cross-language and currently doesn't exist):

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

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

Summary of rationale:

Addition Why
Single-test commands Agents frequently need to run one test; saves a README lookup
Snapshot naming convention Prevents agents from creating CamelCase snapshot files that break on macOS
Code style bullet Prevents agents from using 2-space indent or skipping Javadoc
Porting hint Key context when an agent is asked to port .NET features
Pre-commit hook Avoids mysterious commit failures
Boundaries section The single highest-value addition — prevents agents from hand-editing generated code across all languages

These are all short, bullet-level additions that match the existing file's style. The detailed code examples (handler patterns, event hierarchy, tool definitions) belong in README.md or a future java/.copilot-instructions.md, not the top-level file.

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions