-
Notifications
You must be signed in to change notification settings - Fork 684
feat: add hooks and user input handlers to all SDKs with e2e tests #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
friggeri
commented
Jan 29, 2026
- Add preToolUse, postToolUse, and other hook callbacks to Node.js, Python, Go, .NET SDKs
- Add requestUserInput callback (ask_user) to all SDKs
- Fix .NET SDK bug: StreamJsonRpc requires explicit = null defaults for optional parameters
- Add e2e tests for hooks (4 tests) and ask-user (3 tests) in all SDKs
- Create shared test snapshots for consistent LLM responses across SDKs
…ients Enable SDK clients to customize authentication when spawning the CLI server. Node.js: - Add githubToken and useLoggedInUser options to CopilotClientOptions - Set COPILOT_SDK_AUTH_TOKEN env var and pass --auth-token-env flag - Pass --no-auto-login when useLoggedInUser is false - Default useLoggedInUser to false when githubToken is provided Python: - Add github_token and use_logged_in_user options - Same behavior as Node.js SDK Go: - Add GithubToken and UseLoggedInUser fields to ClientOptions - Same behavior as Node.js SDK .NET: - Add GithubToken and UseLoggedInUser properties to CopilotClientOptions - Same behavior as Node.js SDK All SDKs include validation to prevent use with cliUrl (external server) and tests for the new options.
- Add preToolUse, postToolUse, and other hook callbacks to Node.js, Python, Go, .NET SDKs - Add requestUserInput callback (ask_user) to all SDKs - Fix .NET SDK bug: StreamJsonRpc requires explicit = null defaults for optional parameters - Add e2e tests for hooks (4 tests) and ask-user (3 tests) in all SDKs - Create shared test snapshots for consistent LLM responses across SDKs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds comprehensive hooks and user input handling capabilities across all Copilot SDKs (Python, Node.js, Go, and .NET), enabling developers to intercept and customize session lifecycle events and implement interactive user input flows via the ask_user tool.
Changes:
- Adds six hook types (preToolUse, postToolUse, userPromptSubmitted, sessionStart, sessionEnd, errorOccurred) to all SDKs
- Adds user input handler (ask_user tool) support to all SDKs
- Includes comprehensive e2e tests (4 hooks tests + 3 ask_user tests) for each SDK
- Creates shared test snapshots for consistent LLM response mocking
- Updates @github/copilot dependency from 0.0.394 to 0.0.399
- Fixes .NET StreamJsonRpc bug requiring explicit
= nulldefaults for optional parameters - Adds workingDirectory and disableResume configuration options
Reviewed changes
Copilot reviewed 41 out of 43 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| python/copilot/{types,session,client}.py | Adds hook handler types, user input types, and handler registration/invocation logic |
| nodejs/src/{types,session,client}.ts | Adds TypeScript interfaces for hooks and user input with handler registration |
| go/{types,session,client}.go | Adds Go structs and handlers for hooks and user input functionality |
| dotnet/src/{Types,Session,Client}.cs | Adds C# types with StreamJsonRpc-compatible optional parameters |
| python/e2e/test_{hooks,ask_user}.py | Python e2e tests verifying hook invocations and user input flows |
| nodejs/test/e2e/{hooks,ask-user}.test.ts | Node.js e2e tests with Vitest assertions |
| go/e2e/{hooks,ask_user}_test.go | Go e2e tests using standard testing package |
| dotnet/test/{Hooks,AskUser}Tests.cs | .NET xUnit tests for hooks and user input |
| test/snapshots/{hooks,askuser,ask_user,ask-user}/*.yaml | Shared test snapshots with LLM responses (has duplicate/inconsistent files) |
| {nodejs,test/harness}/package*.json | Dependency updates to copilot 0.0.399 |
| .vscode/settings.json | Adds Ruff as Python formatter |
Files not reviewed (2)
- nodejs/package-lock.json: Language not supported
- test/harness/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
test/snapshots/askuser/should_receive_choices_in_user_input_request.yaml
Show resolved
Hide resolved
test/snapshots/hooks/invoke_pre_tool_use_hook_when_model_runs_a_tool.yaml
Show resolved
Hide resolved
✅ Cross-SDK Consistency Review: PASSEDI've reviewed this PR for consistency across all four SDK implementations (Node.js/TypeScript, Python, Go, and .NET), and I'm pleased to report that the changes demonstrate excellent cross-SDK consistency. Summary of ChangesThis PR adds two major features to all SDKs:
Consistency Findings ✅1. API Naming Conventions - ConsistentAll SDKs follow their respective language conventions properly:
2. Type Definitions - ConsistentAll SDKs define the same hook types with equivalent fields:
3. Session Configuration - ConsistentAll SDKs expose hooks and user input handlers through
4. E2E Test Coverage - ConsistentAll four SDKs include identical test scenarios: Hooks Tests (4 tests each):
Ask User Tests (3 tests each):
5. Implementation Architecture - ConsistentAll SDKs follow the same architectural pattern:
6. Documentation - ConsistentAll SDKs include proper JSDoc/docstring comments with:
Minor Observations (Not Issues)
ConclusionThis PR maintains 100% feature parity across all four SDKs. The naming follows language conventions, types are equivalent, tests are comprehensive and parallel, and the implementation architecture is consistent. This is a model example of how multi-language SDK features should be implemented. No action items or changes needed. 🎉 Reviewed by SDK Consistency Review Agent
|
Update all SDK documentation with new features from PRs #237 and #269: - Add githubToken and useLoggedInUser client options for authentication - Add onUserInputRequest handler for enabling ask_user tool - Add hooks configuration for session lifecycle events - Add User Input Requests section with examples - Add Session Hooks section documenting all available hooks: - onPreToolUse, onPostToolUse, onUserPromptSubmitted - onSessionStart, onSessionEnd, onErrorOccurred
Update all SDK documentation with new features from PRs #237 and #269: - Add githubToken and useLoggedInUser client options for authentication - Add onUserInputRequest handler for enabling ask_user tool - Add hooks configuration for session lifecycle events - Add User Input Requests section with examples - Add Session Hooks section documenting all available hooks: - onPreToolUse, onPostToolUse, onUserPromptSubmitted - onSessionStart, onSessionEnd, onErrorOccurred