Port exit-plan-mode and auto-mode-switch handler APIs from reference implementation#185
Conversation
…implementation Adds ExitPlanModeHandler and AutoModeSwitchHandler support matching the reference implementation commit 671b50a (Restore mode handler APIs across SDKs). New types: - ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExitPlanModeInvocation - AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AutoModeSwitchInvocation Updated: - SessionConfig/ResumeSessionConfig: onExitPlanMode, onAutoModeSwitch fields - CreateSessionRequest/ResumeSessionRequest: requestExitPlanMode, requestAutoModeSwitch flags - CopilotSession: handler registration and dispatch methods - RpcHandlerDispatcher: exitPlanMode.request, autoModeSwitch.request handlers - SessionRequestBuilder: wiring for new handlers and capability flags Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
…om.xml CLI version, and update scripts/codegen @github/copilot version Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Auto-committed by codegen-check workflow.
|
Warning The Codegen Fix Applied ✅Fixed 3 compilation errors in
All three constructor call sites in the test were updated to pass the correct number of Warning
|
…cross all RPC handlers Prompted by github-code-quality review comments on PR #185 (#185 (comment)). The bot flagged four instances of uncaught `NumberFormatException` from `Long.parseLong(requestId)` in the new `handleExitPlanModeRequest` and `handleAutoModeSwitchRequest` handlers. The recommended fix was to parse `requestId` once, catch `NumberFormatException`, and reuse the parsed `long`. Assessment: The `NumberFormatException` comments (r3221146107, r3221146111, r3221146120, r3221146133) are fully addressed and exceeded — the fix applies the pattern to ALL seven handlers in the class, not just the two new ones. A shared `parseRequestId(String, String)` utility method replaces both the flagged inline calls and an existing ad-hoc try/catch in `handleSystemMessageTransform`. Two additional comments (r3221146142, r3221146149) flagged the `invocation` parameter as unused in `AutoModeSwitchHandler` and `ExitPlanModeHandler`. These are intentionally not addressed: the parameter is part of the consistent two-arg handler API contract shared by all handler functional interfaces in the SDK. --- Per-file manifest --- `src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java` - Add `private static parseRequestId(String, String)` utility that wraps `Long.parseLong` in a try/catch for `NumberFormatException`, logs on failure, and returns `-1` as a sentinel. - `handleToolCall`: parse `requestId` upfront via `parseRequestId`; replace five `Long.parseLong(requestId)` call sites with `requestIdLong`. - `handlePermissionRequest`: same pattern; replace three call sites. - `handleUserInputRequest`: same pattern; replace three call sites. - `handleExitPlanModeRequest`: same pattern; replace three call sites. (Directly addresses the linked review comment.) - `handleAutoModeSwitchRequest`: same pattern; replace three call sites. - `handleHooksInvoke`: same pattern; replace three call sites. - `handleSystemMessageTransform`: replace existing inline try/catch NFE block with the shared `parseRequestId` call, removing duplicated logic. `src/site/markdown/advanced.md` - Add `.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)` to the exit-plan-mode and auto-mode-switch code examples so they compile and run without a missing-handler error. `src/test/java/com/github/copilot/sdk/ModeHandlersTest.java` - Parameterize `configureAuthenticatedUser(String testName)` to call `ctx.configureForTest("mode_handlers", testName)` with per-test snapshot names. - `shouldInvokeAutoModeSwitchHandlerWhenRateLimited`: switch from `sendAndWait` to `send`, add assertions on the returned `messageId`. `src/test/java/com/github/copilot/sdk/SessionEventHandlingTest.java` - Update `SessionStartEventData` constructor calls (arity 10 -> 11) for new `detachedFromSpawningParentSessionId` field. - Update `AssistantMessageEventData` constructor calls (arity 12 -> 15) for new `anthropicAdvisorModel`, `turnId`, `parentToolCallId` fields; adjust positional `null` arguments accordingly. Signed-off-by: Ed Burns <edburns@microsoft.com>
…cross all RPC handlers Prompted by github-code-quality review comments on PR #185 (#185 (comment)). The bot flagged four instances of uncaught `NumberFormatException` from `Long.parseLong(requestId)` in the new `handleExitPlanModeRequest` and `handleAutoModeSwitchRequest` handlers. The recommended fix was to parse `requestId` once, catch `NumberFormatException`, and reuse the parsed `long`. Assessment: The `NumberFormatException` comments (r3221146107, r3221146111, r3221146120, r3221146133) are fully addressed and exceeded — the fix applies the pattern to ALL seven handlers in the class, not just the two new ones. A shared `parseRequestId(String, String)` utility method replaces both the flagged inline calls and an existing ad-hoc try/catch in `handleSystemMessageTransform`. Two additional comments (r3221146142, r3221146149) flagged the `invocation` parameter as unused in `AutoModeSwitchHandler` and `ExitPlanModeHandler`. These are intentionally not addressed: the parameter is part of the consistent two-arg handler API contract shared by all handler functional interfaces in the SDK. --- Per-file manifest --- `src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java` - Add `private static parseRequestId(String, String)` utility that wraps `Long.parseLong` in a try/catch for `NumberFormatException`, logs on failure, and returns `-1` as a sentinel. - `handleToolCall`: parse `requestId` upfront via `parseRequestId`; replace five `Long.parseLong(requestId)` call sites with `requestIdLong`. - `handlePermissionRequest`: same pattern; replace three call sites. - `handleUserInputRequest`: same pattern; replace three call sites. - `handleExitPlanModeRequest`: same pattern; replace three call sites. (Directly addresses the linked review comment.) - `handleAutoModeSwitchRequest`: same pattern; replace three call sites. - `handleHooksInvoke`: same pattern; replace three call sites. - `handleSystemMessageTransform`: replace existing inline try/catch NFE block with the shared `parseRequestId` call, removing duplicated logic. `src/site/markdown/advanced.md` - Add `.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)` to the exit-plan-mode and auto-mode-switch code examples so they compile and run without a missing-handler error. `src/test/java/com/github/copilot/sdk/ModeHandlersTest.java` - Parameterize `configureAuthenticatedUser(String testName)` to call `ctx.configureForTest("mode_handlers", testName)` with per-test snapshot names. - `shouldInvokeAutoModeSwitchHandlerWhenRateLimited`: switch from `sendAndWait` to `send`, add assertions on the returned `messageId`. `src/test/java/com/github/copilot/sdk/SessionEventHandlingTest.java` - Update `SessionStartEventData` constructor calls (arity 10 -> 11) for new `detachedFromSpawningParentSessionId` field. - Update `AssistantMessageEventData` constructor calls (arity 12 -> 15) for new `anthropicAdvisorModel`, `turnId`, `parentToolCallId` fields; adjust positional `null` arguments accordingly. Signed-off-by: Ed Burns <edburns@microsoft.com>
There was a problem hiding this comment.
Pull request overview
Ports the reference implementation’s “mode handler” callback APIs into the Java SDK, wiring them through session configuration, JSON-RPC dispatch, and session lifecycle handling so Java hosts can respond to exitPlanMode and autoModeSwitch requests.
Changes:
- Added
ExitPlanMode*andAutoModeSwitch*handler/request/response/invocation types and exposed them onSessionConfig/ResumeSessionConfig. - Wired new RPC callbacks (
exitPlanMode.request,autoModeSwitch.request) throughRpcHandlerDispatcher,SessionRequestBuilder, andCopilotSession. - Updated docs and tests, plus synced reference-impl metadata and codegen inputs/outputs.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/github/copilot/sdk/CopilotSession.java | Stores/clears mode handlers and dispatches requests with default behaviors when absent. |
| src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java | Registers and handles the new incoming RPC request methods for mode handlers. |
| src/main/java/com/github/copilot/sdk/SessionRequestBuilder.java | Sets capability flags and registers handlers when present in session configs. |
| src/main/java/com/github/copilot/sdk/json/SessionConfig.java | Adds onExitPlanMode / onAutoModeSwitch config hooks and clones them. |
| src/main/java/com/github/copilot/sdk/json/ResumeSessionConfig.java | Adds onExitPlanMode / onAutoModeSwitch config hooks and clones them. |
| src/main/java/com/github/copilot/sdk/json/CreateSessionRequest.java | Adds requestExitPlanMode / requestAutoModeSwitch request flags. |
| src/main/java/com/github/copilot/sdk/json/ResumeSessionRequest.java | Adds requestExitPlanMode / requestAutoModeSwitch request flags. |
| src/main/java/com/github/copilot/sdk/json/ExitPlanModeHandler.java | New functional interface for exit-plan-mode requests. |
| src/main/java/com/github/copilot/sdk/json/ExitPlanModeInvocation.java | New invocation context for exit-plan-mode handlers. |
| src/main/java/com/github/copilot/sdk/json/ExitPlanModeRequest.java | New request DTO for exit-plan-mode callbacks. |
| src/main/java/com/github/copilot/sdk/json/ExitPlanModeResult.java | New result DTO returned to the CLI for exit-plan-mode decisions. |
| src/main/java/com/github/copilot/sdk/json/AutoModeSwitchHandler.java | New functional interface for auto-mode-switch requests. |
| src/main/java/com/github/copilot/sdk/json/AutoModeSwitchInvocation.java | New invocation context for auto-mode-switch handlers. |
| src/main/java/com/github/copilot/sdk/json/AutoModeSwitchRequest.java | New request DTO for auto-mode-switch callbacks. |
| src/main/java/com/github/copilot/sdk/json/AutoModeSwitchResponse.java | New wire enum for auto-mode-switch decisions. |
| src/test/java/com/github/copilot/sdk/ModeHandlersTest.java | New E2E coverage for both handler APIs. |
| src/test/java/com/github/copilot/sdk/SessionRequestBuilderTest.java | Unit tests ensuring capability flags are set/omitted and serializable. |
| src/test/java/com/github/copilot/sdk/ConfigCloneTest.java | Verifies handler fields are preserved by config cloning. |
| src/test/java/com/github/copilot/sdk/SessionEventHandlingTest.java | Updates test event construction to match regenerated event record shapes. |
| src/site/markdown/advanced.md | Documents both mode handler APIs with examples and default behavior. |
| src/generated/java/com/github/copilot/sdk/generated/AssistantMessageEvent.java | Regenerated event type with additional fields. |
| src/generated/java/com/github/copilot/sdk/generated/SessionStartEvent.java | Regenerated event type with an additional field. |
| src/generated/java/com/github/copilot/sdk/generated/rpc/SessionCommandsApi.java | Regenerated RPC API including respondToQueuedCommand. |
| src/generated/java/com/github/copilot/sdk/generated/rpc/SessionCommandsRespondToQueuedCommandParams.java | New generated params record. |
| src/generated/java/com/github/copilot/sdk/generated/rpc/SessionCommandsRespondToQueuedCommandResult.java | New generated result record. |
| src/generated/java/com/github/copilot/sdk/generated/rpc/SessionTasksApi.java | Regenerated RPC API including sendMessage. |
| src/generated/java/com/github/copilot/sdk/generated/rpc/SessionTasksSendMessageParams.java | New generated params record. |
| src/generated/java/com/github/copilot/sdk/generated/rpc/SessionTasksSendMessageResult.java | New generated result record. |
| src/generated/java/com/github/copilot/sdk/generated/rpc/SessionWorkspacesGetWorkspaceResult.java | Regenerated schema removing fields/types no longer present. |
| scripts/codegen/package.json | Bumps the @github/copilot dependency range used for schema/codegen. |
| scripts/codegen/package-lock.json | Updates locked Node dependencies for code generation. |
| pom.xml | Updates the recorded reference-impl @github/copilot version range. |
| .lastmerge | Advances the recorded reference implementation sync commit. |
Copilot's findings
Files not reviewed (1)
- scripts/codegen/package-lock.json: Language not supported
- Files reviewed: 23/33 changed files
- Comments generated: 0
Resolves #179
Before the change?
066a69c..4a0437b)exitPlanModeorautoModeSwitchhandler APIs (added in ref-impl671b50a)@github/copilotpinned at previous versionAfter the change?
ExitPlanModeHandler,AutoModeSwitchHandlerfollowing existing@FunctionalInterfacepatterns (8 new files: handler, request, result/response, invocation for each)SessionConfig/ResumeSessionConfiggainonExitPlanModeandonAutoModeSwitchfields;CopilotSessionhandles registration, dispatch, and cleanupRpcHandlerDispatcherregistersexitPlanMode.requestandautoModeSwitch.request;SessionRequestBuildersetsrequestExitPlanMode/requestAutoModeSwitchcapability flags when handlers are presentapproved=true), decline auto mode switch (NO).lastmerge→4a0437bb, pom.xml and codegen synced to@github/copilot@^1.0.44-3Skipped commits (not applicable to Java): Rust SDK (4a0437b, 8794594, 55b3b1c, b0d1c8e), Go SDK (d5c8db4, 30a76a5, 4901dff), CI workflows (97f505c, 299ea21), .NET enums (e759700), E2E snapshots (f625779), doc typos (ce56eb8 — no matches in Java docs), Maven badge (f72bf0f — already present), Node pkg update (ac55e9a — handled by finish script).
Pull request checklist
mvn spotless:applyhas been run to format the codemvn clean verifypasses locallyDoes this introduce a breaking change?