Skip to content

Add Java SDK cookbook with 7 recipes#1313

Merged
brunoborges merged 3 commits intogithub:mainfrom
brunoborges:cookbook/java
Apr 6, 2026
Merged

Add Java SDK cookbook with 7 recipes#1313
brunoborges merged 3 commits intogithub:mainfrom
brunoborges:cookbook/java

Conversation

@brunoborges
Copy link
Copy Markdown
Contributor

Summary

Adds a complete Java cookbook to the Copilot SDK cookbook collection, matching the structure and coverage of the existing .NET, Go, Node.js, and Python cookbooks.

What's included

7 recipe documentation files (cookbook/copilot-sdk/java/*.md)

Recipe Description
Ralph Loop Autonomous AI task loops with fresh context per iteration
Error Handling try-with-resources, ExecutionException unwrapping, timeouts
Multiple Sessions Parallel sessions with CompletableFuture.allOf
Managing Local Files AI-powered file organization with event handlers
PR Visualization Interactive PR age charts via GitHub MCP Server
Persisting Sessions Save/resume sessions with custom IDs
Accessibility Report WCAG reports via Playwright MCP server

7 runnable recipe files (cookbook/copilot-sdk/java/recipe/*.java)

All examples are standalone JBang scripts — no project setup required:

jbang ErrorHandling.java
jbang PRVisualization.java github/copilot-sdk
jbang RalphLoop.java plan 5

README updates

  • cookbook/copilot-sdk/java/README.md — Language README with recipe index
  • cookbook/copilot-sdk/java/recipe/README.md — Runnable examples guide
  • cookbook/copilot-sdk/README.md — Added Java section + updated language count
  • cookbook/README.md — Added Java to language list

Java SDK specifics

  • Uses com.github:copilot-sdk-java:0.2.1-java.1 (Maven coordinates)
  • All code uses Java 17+ features (text blocks, var, pattern matching)
  • JBang for zero-setup execution (//DEPS inline dependency declaration)
  • Java idioms: try-with-resources, CompletableFuture, CountDownLatch, shutdown hooks

Stats

  • 18 files changed, +2,216 lines
  • 7 recipe .md files + 7 recipe .java files + 2 README files + 2 updated READMEs

Add complete Java cookbook matching the pattern of existing .NET, Go,
Node.js, and Python cookbooks. All 7 recipes included:

- Ralph Loop: Autonomous AI task loops with JBang
- Error Handling: try-with-resources, ExecutionException, timeouts
- Multiple Sessions: Parallel sessions with CompletableFuture
- Managing Local Files: AI-powered file organization
- PR Visualization: Interactive PR age charts
- Persisting Sessions: Save/resume with custom IDs
- Accessibility Report: WCAG reports via Playwright MCP

Each recipe includes both markdown documentation and a standalone
JBang-runnable Java file in recipe/.
@brunoborges brunoborges requested a review from aaronpowell as a code owner April 6, 2026 17:52
Copilot AI review requested due to automatic review settings April 6, 2026 17:52
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This PR targets main, but PRs should target staged.

The main branch is auto-published from staged and should not receive direct PRs.
Please close this PR and re-open it against the staged branch.

You can change the base branch using the Edit button at the top of this PR,
or run: gh pr edit 1313 --base staged

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Java section to the Copilot SDK cookbook, including Java-language recipe docs and runnable JBang-based examples, to align Java coverage with the existing .NET/Go/Node.js/Python cookbooks.

Changes:

  • Added a full Java cookbook section with 7 recipe markdown docs under cookbook/copilot-sdk/java/.
  • Added 7 runnable JBang Java scripts under cookbook/copilot-sdk/java/recipe/.
  • Updated top-level cookbook READMEs to include Java and updated language count.
Show a summary per file
File Description
cookbook/README.md Adds Java to the cookbook language list for the Copilot SDK cookbook.
cookbook/copilot-sdk/README.md Adds Java recipe links + Java “Running Examples” instructions + updates supported language count.
cookbook/copilot-sdk/java/README.md New Java cookbook landing page with recipe index.
cookbook/copilot-sdk/java/recipe/README.md New guide for running Java examples via JBang.
cookbook/copilot-sdk/java/ralph-loop.md New Java Ralph Loop recipe documentation.
cookbook/copilot-sdk/java/error-handling.md New Java error handling patterns documentation.
cookbook/copilot-sdk/java/multiple-sessions.md New Java multi-session patterns documentation.
cookbook/copilot-sdk/java/managing-local-files.md New Java local file organization recipe documentation.
cookbook/copilot-sdk/java/pr-visualization.md New Java PR visualization recipe documentation.
cookbook/copilot-sdk/java/persisting-sessions.md New Java session persistence documentation.
cookbook/copilot-sdk/java/accessibility-report.md New Java accessibility reporting recipe documentation.
cookbook/copilot-sdk/java/recipe/RalphLoop.java Runnable JBang script implementing a basic Ralph loop.
cookbook/copilot-sdk/java/recipe/ErrorHandling.java Runnable JBang script demonstrating basic error handling.
cookbook/copilot-sdk/java/recipe/MultipleSessions.java Runnable JBang script demonstrating parallel sessions.
cookbook/copilot-sdk/java/recipe/ManagingLocalFiles.java Runnable JBang script demonstrating file grouping (dry-run style).
cookbook/copilot-sdk/java/recipe/PRVisualization.java Runnable JBang script for PR-age visualization using MCP tools.
cookbook/copilot-sdk/java/recipe/PersistingSessions.java Runnable JBang script for creating a session with a stable ID.
cookbook/copilot-sdk/java/recipe/AccessibilityReport.java Runnable JBang script using Playwright MCP for WCAG reporting + optional test generation.

Copilot's findings

  • Files reviewed: 18/18 changed files
  • Comments generated: 9

Comment thread cookbook/copilot-sdk/README.md Outdated
Comment thread cookbook/copilot-sdk/java/multiple-sessions.md Outdated
Comment thread cookbook/copilot-sdk/java/multiple-sessions.md Outdated
Comment thread cookbook/copilot-sdk/java/recipe/MultipleSessions.java Outdated
Comment thread cookbook/copilot-sdk/java/recipe/AccessibilityReport.java Outdated
Comment on lines +96 to +101
session.send(new MessageOptions().setPrompt(prompt));

// Wait a bit for initial processing
Thread.sleep(10000);

// Interactive loop
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This recipe uses fixed Thread.sleep(...) delays after sending messages. That makes the CLI behavior timing-dependent (responses can take longer or shorter than the sleep), and can lead to missing/partial output or awkward interleaving. Prefer waiting on SessionIdleEvent (like the other Java recipes do with a CountDownLatch) or using sendAndWait(...) for requests where you need completion before continuing.

Copilot uses AI. Check for mistakes.
Comment thread cookbook/copilot-sdk/java/recipe/ErrorHandling.java Outdated
Comment thread cookbook/copilot-sdk/java/recipe/README.md Outdated
Comment thread cookbook/copilot-sdk/java/accessibility-report.md Outdated
brunoborges and others added 2 commits April 6, 2026 14:09
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Replace Thread.sleep with sendAndWait in PRVisualization
- Fix top-level statements in multiple-sessions.md (wrap in class)
- Fix .getMessage() → .getData().content() in MultipleSessions.java
- Guard against null readLine() in AccessibilityReport.java
- Add null-safe getCause() + InterruptedException handling in ErrorHandling.java
- Fix paths: jbang commands now include recipe/ prefix
- Fix root README path: cd java/recipe (not java/cookbook/recipe)
- Fix recipe/README.md ralph-loop CLI example
@brunoborges brunoborges merged commit 7c6c0be into github:main Apr 6, 2026
6 checks passed
brunoborges added a commit that referenced this pull request Apr 6, 2026
This reverts commit 7c6c0be, reversing
changes made to 0c3c5bb.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants