Repository navigation
fix(server): Claude can show the user mid-turn text in full #36384
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
Merged
+297
−12
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9702895
fix(server): Claude can show the user mid-turn text in full
juliusmarminge 9e31afd
Merge remote-tracking branch 'origin/main' into t3/claude-send-to-user
juliusmarminge 16e4e1d
fix(server): sent messages stay in long turns and Code Mode
juliusmarminge d51c6ec
refactor(server): send_to_user relies on actsAsCaller for its thread …
juliusmarminge 3dc3bbb
Merge remote-tracking branch 'origin/t3/claude-send-to-user' into t3/…
juliusmarminge 261f266
fix(server): Code Mode sent messages stay inline in long turns
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import * as Effect from "effect/Effect"; | ||
|
|
||
| import * as McpInvocationContext from "../../McpInvocationContext.ts"; | ||
| import * as McpToolAccess from "../../McpToolAccess.ts"; | ||
| import { MessageToolkit } from "./tools.ts"; | ||
|
|
||
| const handlers = { | ||
| send_to_user: McpToolAccess.actsAsCaller((input) => | ||
| Effect.gen(function* () { | ||
| const scope = yield* McpInvocationContext.McpInvocationContext; | ||
| yield* McpInvocationContext.requireThreadScope(scope, "send_to_user"); | ||
| return { | ||
| sentMessage: input.message, | ||
| message: "Shown to the user. Don't repeat it.", | ||
| }; | ||
| }), | ||
| ), | ||
| } satisfies McpToolAccess.Handlers<typeof MessageToolkit.tools>; | ||
|
|
||
| export const layer = McpToolAccess.toLayer(MessageToolkit, handlers); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { OrchestratorMcpFailure } from "@t3tools/contracts"; | ||
| import { SEND_TO_USER_MAX_LENGTH, SEND_TO_USER_TOOL_NAME } from "@t3tools/shared/toolOutput"; | ||
| import * as Schema from "effect/Schema"; | ||
| import { Tool, Toolkit } from "effect/ai"; | ||
|
|
||
| import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts"; | ||
| import * as McpInvocationContext from "../../McpInvocationContext.ts"; | ||
|
|
||
| // Claude 5.1+ returns text written before a tool call only as a short summary; tool input arrives intact. | ||
| // It affects only the caller's thread, so read-only sandboxes and plan mode may use it. | ||
| const SendToUserTool = Tool.make(SEND_TO_USER_TOOL_NAME, { | ||
| description: | ||
| "Show the user a Markdown message in this thread, exactly as written, before your turn ends. Use it for content the user must read in full mid-turn, such as a draft, a code block, or what a question you are about to ask refers to. Don't repeat it in your reply.", | ||
| parameters: Schema.Struct({ | ||
| message: Schema.String.check( | ||
| Schema.isMinLength(1), | ||
| Schema.isMaxLength(SEND_TO_USER_MAX_LENGTH), | ||
| ).annotate({ description: "Markdown, shown verbatim." }), | ||
| }), | ||
| success: Schema.Struct({ | ||
| sentMessage: Schema.String, | ||
| message: Schema.String, | ||
| }), | ||
| failure: OrchestratorMcpFailure, | ||
| failureMode: "return", | ||
| dependencies: [ | ||
| McpInvocationContext.McpInvocationContext, | ||
| ThreadManagementService.ThreadManagementService, | ||
| ], | ||
| }) | ||
| .annotate(Tool.Title, "Send a message to the user") | ||
| .annotate(Tool.Readonly, true) | ||
| .annotate(Tool.Destructive, false) | ||
| .annotate(Tool.Idempotent, false) | ||
| .annotate(Tool.OpenWorld, false) | ||
| // Claude Code defers MCP tools behind ToolSearch; Anthropic says to declare this from the first request. | ||
| .annotate(Tool.Meta, { "anthropic/alwaysLoad": true }); | ||
|
|
||
| export const MessageToolkit = Toolkit.make(SendToUserTool); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "claudeSystemAppendBytes": 5594, | ||
| "claudeSystemAppendBytes": 5930, | ||
| "codexAdditionalContextBytes": 7324, | ||
| "mcpToolListJsonBytes": 48094 | ||
| "mcpToolListJsonBytes": 48566 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.