Skip to content

Add support for text_editor_code_execution and pause_turn stop reason#7

Merged
PederHP merged 2 commits into
skills_support_messagesfrom
copilot/support-code-execution-tools
Oct 17, 2025
Merged

Add support for text_editor_code_execution and pause_turn stop reason#7
PederHP merged 2 commits into
skills_support_messagesfrom
copilot/support-code-execution-tools

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 17, 2025

Overview

This PR adds support for Anthropic's text_editor_code_execution server tool and the pause_turn stop reason. These new API features allow Claude to perform file operations (view, create, edit) and signal when it needs to pause during long-running turns.

Changes

New Content Types

Added three new content types to the ContentType enum:

  • text_editor_code_execution_tool_result - Top-level container for tool results
  • text_editor_code_execution_result - Successful operation results
  • text_editor_code_execution_tool_result_error - Error responses

Content Classes

TextEditorCodeExecutionResultContent supports multiple operation types:

  • Create operations: Returns is_file_update (boolean indicating if file already existed)
  • View operations: Returns file_type, content, numLines, startLine, totalLines
  • Edit operations (str_replace): Returns diff information with oldStart, oldLines, newStart, newLines, and lines array

Example edit operation response:

{
  "type": "text_editor_code_execution_tool_result",
  "tool_use_id": "srvtoolu_01E6F7G8H9I0J1K2L3M4N5O6",
  "content": {
    "type": "text_editor_code_execution_result",
    "oldStart": 3,
    "oldLines": 1,
    "newStart": 3,
    "newLines": 1,
    "lines": ["-  \"debug\": true", "+  \"debug\": false"]
  }
}

ServerToolInput Enhancement

Extended ServerToolInput to support text editor parameters:

  • command - Operation type (str_replace, create, view)
  • path - File path
  • old_str, new_str - For string replacement
  • file_text - For file creation

Stop Reason Support

The existing StopReason property (a string) already supports the new pause_turn value without requiring code changes. When Claude pauses a long-running turn, applications can provide the response back as-is in a subsequent request to let Claude continue.

Deserialization

Updated ContentConverter to handle all three new content types, following the same pattern as the existing bash_code_execution types.

Testing

Added comprehensive test suite in TextEditorCodeExecutionTests.cs:

  • ✅ Text editor tool use deserialization (str_replace command)
  • ✅ Tool result with diff deserialization
  • ✅ Create operation result deserialization
  • ✅ Error result deserialization
  • ✅ Pause turn stop reason handling

All 10 tests pass successfully on both net8.0 and net9.0 target frameworks.

Design Decisions

The implementation follows the established pattern of the existing bash_code_execution support, using ContentBase for polymorphic content to maintain consistency with the codebase architecture. This approach allows the JSON deserializer to handle multiple result types (success or error) in the same content field.

Original prompt

We need to support the "text_editor_code_execution_tool_result" and "text_editor_code_execution".

Example return possibilities:

{
  "type": "server_tool_use",
  "id": "srvtoolu_01E6F7G8H9I0J1K2L3M4N5O6",
  "name": "text_editor_code_execution",
  "input": {
    "command": "str_replace",
    "path": "config.json",
    "old_str": "\"debug\": true",
    "new_str": "\"debug\": false"
  }
},
{
  "type": "text_editor_code_execution_tool_result",
  "tool_use_id": "srvtoolu_01E6F7G8H9I0J1K2L3M4N5O6",
  "content": {
    "type": "text_editor_code_execution_result",
    "oldStart": 3,
    "oldLines": 1,
    "newStart": 3,
    "newLines": 1,
    "lines": ["-  \"debug\": true", "+  \"debug\": false"]
  }
}
{
  "type": "server_tool_use",
  "id": "srvtoolu_01B3C4D5E6F7G8H9I0J1K2L3",
  "name": "bash_code_execution",
  "input": {
    "command": "ls -la | head -5"
  }
},
{
  "type": "bash_code_execution_tool_result",
  "tool_use_id": "srvtoolu_01B3C4D5E6F7G8H9I0J1K2L3",
  "content": {
    "type": "bash_code_execution_result",
    "stdout": "total 24\ndrwxr-xr-x 2 user user 4096 Jan 1 12:00 .\ndrwxr-xr-x 3 user user 4096 Jan 1 11:00 ..\n-rw-r--r-- 1 user user  220 Jan 1 12:00 data.csv\n-rw-r--r-- 1 user user  180 Jan 1 12:00 config.json",
    "stderr": "",
    "return_code": 0
  }
}
{
  "type": "server_tool_use",
  "id": "srvtoolu_01D5E6F7G8H9I0J1K2L3M4N5",
  "name": "text_editor_code_execution",
  "input": {
    "command": "create",
    "path": "new_file.txt",
    "file_text": "Hello, World!"
  }
},
{
  "type": "text_editor_code_execution_tool_result",
  "tool_use_id": "srvtoolu_01D5E6F7G8H9I0J1K2L3M4N5",
  "content": {
    "type": "text_editor_code_execution_result",
    "is_file_update": false
  }
}

These are new server_tool tools similar to web_search. They'll just be in the response and shouldn't be executed by the client.

All execution results include:
stdout: Output from successful execution
stderr: Error messages if execution fails
return_code: 0 for success, non-zero for failure

Additional fields for file operations:
View: file_type, content, numLines, startLine, totalLines
Create: is_file_update (whether file already existed)
Edit: oldStart, oldLines, newStart, newLines, lines (diff format)

Errors
Each tool type can return specific errors:
Common errors (all tools):

Copy
{
"type": "bash_code_execution_tool_result",
"tool_use_id": "srvtoolu_01VfmxgZ46TiHbmXgy928hQR",
"content": {
"type": "bash_code_execution_tool_result_error",
"error_code": "unavailable"
}
}


We also need to support pause_turn (and do the as-is continue by default):

pause_turn stop reason
The response may include a pause_turn stop reason, which indicates that the API paused a long-running turn. You may provide the response back as-is in a subsequent request to let Claude continue its turn, or modify the content if you wish to interrupt the conversation.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: PederHP <127606677+PederHP@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for text editor code execution tools Add support for text_editor_code_execution and pause_turn stop reason Oct 17, 2025
Copilot AI requested a review from PederHP October 17, 2025 20:56
@PederHP PederHP marked this pull request as ready for review October 17, 2025 20:57
@PederHP PederHP merged commit 4cddfce into skills_support_messages Oct 17, 2025
@PederHP PederHP deleted the copilot/support-code-execution-tools branch November 14, 2025 19:09
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.

2 participants