Address review feedback

- 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
This commit is contained in:
Bruno Borges
2026-04-06 14:12:08 -04:00
parent 57b2799408
commit 0f06f346be
4 changed files with 32 additions and 38 deletions

View File

@@ -23,35 +23,35 @@ import com.github.copilot.sdk.json.*;
public class MultipleSessions { public class MultipleSessions {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
var client = new CopilotClient(); try (var client = new CopilotClient()) {
client.start().get(); client.start().get();
// Create multiple independent sessions // Create multiple independent sessions
var session1 = client.createSession(new SessionConfig() var session1 = client.createSession(new SessionConfig()
.setModel("gpt-5") .setModel("gpt-5")
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get(); .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
var session2 = client.createSession(new SessionConfig() var session2 = client.createSession(new SessionConfig()
.setModel("gpt-5") .setModel("gpt-5")
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get(); .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
var session3 = client.createSession(new SessionConfig() var session3 = client.createSession(new SessionConfig()
.setModel("claude-sonnet-4.5") .setModel("claude-sonnet-4.5")
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get(); .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
// Each session maintains its own conversation history // Each session maintains its own conversation history
session1.sendAndWait(new MessageOptions().setPrompt("You are helping with a Python project")).get(); session1.sendAndWait(new MessageOptions().setPrompt("You are helping with a Python project")).get();
session2.sendAndWait(new MessageOptions().setPrompt("You are helping with a TypeScript project")).get(); session2.sendAndWait(new MessageOptions().setPrompt("You are helping with a TypeScript project")).get();
session3.sendAndWait(new MessageOptions().setPrompt("You are helping with a Go project")).get(); session3.sendAndWait(new MessageOptions().setPrompt("You are helping with a Go project")).get();
// Follow-up messages stay in their respective contexts // Follow-up messages stay in their respective contexts
session1.sendAndWait(new MessageOptions().setPrompt("How do I create a virtual environment?")).get(); session1.sendAndWait(new MessageOptions().setPrompt("How do I create a virtual environment?")).get();
session2.sendAndWait(new MessageOptions().setPrompt("How do I set up tsconfig?")).get(); session2.sendAndWait(new MessageOptions().setPrompt("How do I set up tsconfig?")).get();
session3.sendAndWait(new MessageOptions().setPrompt("How do I initialize a module?")).get(); session3.sendAndWait(new MessageOptions().setPrompt("How do I initialize a module?")).get();
// Clean up all sessions // Clean up all sessions
session1.destroy().get(); session1.destroy().get();
session2.destroy().get(); session2.destroy().get();
session3.destroy().get(); session3.destroy().get();
client.stop().get(); }
} }
} }
``` ```

View File

@@ -118,10 +118,7 @@ public class PRVisualization {
Finally, summarize the PR health - average age, oldest PR, and how many might be considered stale. Finally, summarize the PR health - average age, oldest PR, and how many might be considered stale.
""", owner, repoName); """, owner, repoName);
session.send(new MessageOptions().setPrompt(prompt)); session.sendAndWait(new MessageOptions().setPrompt(prompt)).get();
// Wait a bit for initial processing
Thread.sleep(10000);
// Interactive loop // Interactive loop
System.out.println("\n💡 Ask follow-up questions or type \"exit\" to quit.\n"); System.out.println("\n💡 Ask follow-up questions or type \"exit\" to quit.\n");
@@ -145,8 +142,7 @@ public class PRVisualization {
break; break;
} }
session.send(new MessageOptions().setPrompt(input)); session.sendAndWait(new MessageOptions().setPrompt(input)).get();
Thread.sleep(2000); // Give time for response
} }
} }

View File

@@ -93,10 +93,7 @@ public class PRVisualization {
Finally, summarize the PR health - average age, oldest PR, and how many might be considered stale. Finally, summarize the PR health - average age, oldest PR, and how many might be considered stale.
""", owner, repoName); """, owner, repoName);
session.send(new MessageOptions().setPrompt(prompt)); session.sendAndWait(new MessageOptions().setPrompt(prompt)).get();
// Wait a bit for initial processing
Thread.sleep(10000);
// Interactive loop // Interactive loop
System.out.println("\n💡 Ask follow-up questions or type \"exit\" to quit.\n"); System.out.println("\n💡 Ask follow-up questions or type \"exit\" to quit.\n");
@@ -120,8 +117,7 @@ public class PRVisualization {
break; break;
} }
session.send(new MessageOptions().setPrompt(input)); session.sendAndWait(new MessageOptions().setPrompt(input)).get();
Thread.sleep(2000); // Give time for response
} }
} }

View File

@@ -54,8 +54,10 @@ jbang PRVisualization.java github/copilot-sdk
jbang ManagingLocalFiles.java /path/to/your/folder jbang ManagingLocalFiles.java /path/to/your/folder
``` ```
**Ralph Loop with a prompt file:** **Ralph Loop with a custom prompt file:**
```bash
jbang RalphLoop.java PROMPT_build.md 20
``` ```
## Why JBang? ## Why JBang?