Skip to content

Add userPromptTransformed hook to all SDKs - #2254

Merged
SteveSandersonMS merged 5 commits into
mainfrom
copilot/user-prompt-transformed-hook
Aug 4, 2026
Merged

Add userPromptTransformed hook to all SDKs#2254
SteveSandersonMS merged 5 commits into
mainfrom
copilot/user-prompt-transformed-hook

Conversation

@SteveSandersonMS

Copy link
Copy Markdown
Contributor

Summary

  • add typed userPromptTransformed hook APIs and dispatch across Node.js, Python, Go, .NET, Java, and Rust
  • expose the runtime-transformed prompt and support replacing the model-facing content before persistence
  • add shared replay E2E coverage for all six SDKs, focused serialization/unit coverage, and cross-language documentation

Implements SDK support for github/copilot-agent-runtime#12791. Supersedes the older Node-only approach in #1774 with the shipped hook contract.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SteveSandersonMS
SteveSandersonMS requested a review from a team as a code owner August 4, 2026 15:48
Copilot AI balanced review requested due to automatic review settings August 4, 2026 15:48
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds the userPromptTransformed hook across all six SDKs, enabling inspection and replacement of model-facing prompts before persistence.

Changes:

  • Adds typed hook APIs and dispatch.
  • Adds shared E2E and serialization coverage.
  • Adds cross-language hook documentation.
Show a summary per file
File Description
test/snapshots/hooks_extended/should_invoke_userprompttransformed_hook_and_modify_transformed_prompt.yaml Adds shared replay fixture.
rust/tests/e2e/hooks_extended.rs Adds Rust E2E coverage.
rust/src/hooks.rs Implements the Rust hook API and dispatch.
python/e2e/test_hooks_extended_e2e.py Adds Python E2E coverage.
python/copilot/session.py Adds Python types and dispatch.
python/copilot/__init__.py Exports Python hook types.
nodejs/test/e2e/hooks_extended.e2e.test.ts Adds Node.js E2E coverage.
nodejs/src/types.ts Defines Node.js hook types.
nodejs/src/session.ts Dispatches the Node.js hook.
nodejs/src/index.ts Exports Node.js hook types.
java/src/test/java/com/github/copilot/SessionHandlerTest.java Tests Java dispatch.
java/src/test/java/com/github/copilot/HooksTest.java Adds Java E2E coverage.
java/src/main/java/com/github/copilot/rpc/UserPromptTransformedHookOutput.java Defines Java hook output.
java/src/main/java/com/github/copilot/rpc/UserPromptTransformedHookInput.java Defines Java hook input.
java/src/main/java/com/github/copilot/rpc/UserPromptTransformedHandler.java Defines Java handler API.
java/src/main/java/com/github/copilot/rpc/SessionHooks.java Registers the Java handler.
java/src/main/java/com/github/copilot/CopilotSession.java Dispatches the Java hook.
go/types.go Defines Go hook types.
go/types_test.go Tests empty replacement serialization.
go/session.go Dispatches the Go hook.
go/internal/e2e/hooks_extended_e2e_test.go Adds Go E2E coverage.
go/client.go Registers Go hooks for create and resume.
dotnet/test/E2E/HookLifecycleAndOutputE2ETests.cs Adds .NET E2E coverage.
dotnet/src/Types.cs Defines .NET hook APIs.
dotnet/src/Session.cs Dispatches and serializes the .NET hook.
dotnet/src/Client.cs Registers .NET hooks for create and resume.
docs/README.md Links the new hook guide.
docs/hooks/user-prompt-transformed.md Documents the hook across languages.
docs/hooks/README.md Adds the hook to the documentation index.
docs/hooks/hooks-overview.md Adds the hook to the API overview.
docs/features/hooks.md Updates lifecycle and reference documentation.

Review details

Suppressed comments (4)

docs/hooks/user-prompt-transformed.md:39

  • The docs validator extracts this Python block and type-checks it as a standalone file, where client and redact are undefined. Mark the conceptual snippet as skipped (or provide hidden validation scaffolding).
```python

docs/hooks/user-prompt-transformed.md:54

  • This block is compiled standalone by docs validation, but it has no imports or declarations for client, ctx, and redact, so validation fails. Mark the conceptual snippet as skipped (or provide hidden compilable scaffolding).
```go

docs/hooks/user-prompt-transformed.md:71

  • Docs validation compiles this C# block independently; client and Redact are not declared, so the new article fails validation. Mark the conceptual snippet as skipped (or add hidden compilable scaffolding).
```csharp

docs/hooks/user-prompt-transformed.md:90

  • The Java docs validator wraps and compiles this block, but no redact method is defined. Mark the conceptual snippet as skipped (or add hidden compilable scaffolding) to keep docs validation passing.
```java
  • Files reviewed: 31/31 changed files
  • Comments generated: 7
  • Review effort level: Balanced

Comment thread docs/hooks/user-prompt-transformed.md
Comment thread docs/hooks/user-prompt-transformed.md Outdated
Comment thread rust/src/hooks.rs
Comment thread java/src/main/java/com/github/copilot/rpc/SessionHooks.java
Copilot AI added 2 commits August 4, 2026 16:27
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 4, 2026 16:30
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

Suppressed comments (2)

docs/hooks/user-prompt-transformed.md:108

  • This tab defines MyHooks but never installs it on a session, so the documented callback will not run. Add session creation with with_hooks(...) to cover the same registration flow shown by the other language tabs.
#[async_trait]
impl SessionHooks for MyHooks {

docs/hooks/user-prompt-transformed.md:98

  • Unlike the other language tabs, this snippet only constructs a SessionHooks value and never attaches it to a session, so copying it does not register the hook. Create the session with that hooks value so this tab demonstrates the same operation as the other examples.

This issue also appears on line 107 of the same file.

var hooks = new SessionHooks().setOnUserPromptTransformed((input, invocation) ->
    CompletableFuture.completedFuture(
        new UserPromptTransformedHookOutput(redact(input.transformedPrompt()))));
  • Files reviewed: 32/32 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 4, 2026 16:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

Suppressed comments (1)

go/internal/e2e/hooks_extended_e2e_test.go:84

  • The hook callback is executed on a separate goroutine (go/internal/jsonrpc2/jsonrpc2.go:450-472), but this new test appends to and later reads inputs without synchronization. This can trigger a data race under go test -race; protect both the callback write and the assertions with the mutex pattern used by the surrounding hook tests, or pass the input through a channel.
		var inputs []copilot.UserPromptTransformedHookInput
		session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
			OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
			Hooks: &copilot.SessionHooks{
				OnUserPromptTransformed: func(input copilot.UserPromptTransformedHookInput, invocation copilot.HookInvocation) (*copilot.UserPromptTransformedHookOutput, error) {
					inputs = append(inputs, input)
  • Files reviewed: 32/32 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@github-actions

This comment has been minimized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 4, 2026 16:42
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review ✅

This PR adds the onUserPromptTransformed / on_user_prompt_transformed / OnUserPromptTransformed hook to all six SDK implementations:

SDK Files Modified Status
Node.js/TypeScript nodejs/src/types.ts, session.ts, index.ts
Python python/copilot/session.py, __init__.py
Go go/types.go, session.go, client.go
.NET dotnet/src/Types.cs, Session.cs, Client.cs
Java CopilotSession.java, SessionHooks.java + 3 new files
Rust rust/src/hooks.rs

The API surface is consistent across all languages:

  • Input fields: sessionId, timestamp, cwd/workingDirectory, prompt, transformedPrompt — all present in every SDK
  • Output: modifiedTransformedPrompt optional field in all SDKs
  • Naming: follows each language's conventions (camelCase for TS/Java, snake_case for Python/Rust, PascalCase for .NET/Go exports)
  • E2E tests: added in Node.js, Python, Go, .NET, and Java

No cross-SDK consistency issues found. 🎉

Generated by SDK Consistency Review Agent for #2254 · sonnet46 20.7 AIC · ⌖ 5.42 AIC · ⊞ 6.6K ·

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 32/32 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@SteveSandersonMS
SteveSandersonMS merged commit 2b050d7 into main Aug 4, 2026
66 checks passed
@SteveSandersonMS
SteveSandersonMS deleted the copilot/user-prompt-transformed-hook branch August 4, 2026 17:20
edburns pushed a commit that referenced this pull request Aug 5, 2026
* Add user prompt transformed hook to all SDKs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address user prompt hook review feedback

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Complete hook registration examples

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Synchronize transformed hook test inputs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants