Skip to content

Fix command log output using pformat instead of json.dumps#90

Merged
0xba1a merged 4 commits intomainfrom
copilot/fix-anthropic-text-editor-output
Dec 30, 2025
Merged

Fix command log output using pformat instead of json.dumps#90
0xba1a merged 4 commits intomainfrom
copilot/fix-anthropic-text-editor-output

Conversation

Copy link
Contributor

Copilot AI commented Dec 30, 2025

Command execution logs were unreadable due to json.dumps() escaping quotes and newlines. This is particularly problematic for JSON-heavy commands like anthropic-text-editor.

Before:

 ➡️  LLM tool call : "echo '{\"input\": {\"command\": \"view\", \"path\": \"/tmp/test.txt\"}}' | anthropic-text-editor"

After:

 ➡️  LLM tool call : 'echo \'{"input": {"command": "view", "path": "/tmp/test.txt"}}\' | anthropic-text-editor'

Changes

  • Replace json.dumps() with pformat() from pprint for command logging in MicroBot.py
  • Remove unused json import
  • Add unit test test_pformat_produces_readable_output validating the formatting behavior
Original prompt

This section details on the original issue you should resolve

<issue_title>Fix output of anthropic-text-editor command using pformat</issue_title>
<issue_description>The command execution output from anthropic-text-editor when used as an additional tool, is being printed with escape sequences. It is making the logs unreadable. Also, probably, the llm response is also with unescaped messages.

First write a test case by defining a custom Tool class as following,

from microbots.tools.tool import Tool

anthropic_text_editor: Tool = Tool(
    name="anthropic-text-editor",
    description="edit_anthropic tool from Anthropic",
    parameters=None,
    usage_instructions_to_llm="""
You have access to a tool called 'anthropic-text-editor'.
This tool allows you to view, create, replace strings, insert, and delete lines in files.
It communicates through JSON over stdin/stdout.

Usage:
echo '{"input": <JSON_INPUT>}' | anthropic-text-editor

<JSON_INPUT> format:
{
  "command": "view|create|str_replace|insert|delete",
  "path": "/absolute/path/to/file",
  "view_range": [start_line, end_line], // Optional for view
  "old_str": "text to replace", // Required for str_replace
  "new_str": "replacement text", // Optional for str_replace, required for insert
  "insert_line": line_number, // Required for insert
  "delete_range": [start_line, end_line], // Required for delete
  "file_text": "content" // Required for create
}
""",
    install_commands=[
        "apt-get update && apt-get install -y curl build-essential",
        "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y",
        "export PATH=$HOME/.cargo/bin:$PATH && cargo install --locked anthropic-text-editor",
        "ln -s /root/.cargo/bin/anthropic-text-editor /usr/local/bin/anthropic-text-editor"
    ],
    verify_commands=[
        'echo \'{"input": {"command": "view", "path": "' + DOCKER_PATCH_FILE_PATH + '", "view_range": [1, 5]}}\' | anthropic-text-editor'
    ],
    uninstall_commands=[
        "export PATH=$HOME/.cargo/bin:$PATH && cargo uninstall anthropic-text-editor"
    ],
    env_variables=[],
    files_to_copy=[],
)

See the output and based on that fix the log output. I think pformat from pprint will help here. But check it before using.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI self-assigned this Dec 30, 2025
Copilot AI and others added 2 commits December 30, 2025 15:34
…e logs

Co-authored-by: 0xba1a <2942888+0xba1a@users.noreply.github.com>
Co-authored-by: 0xba1a <2942888+0xba1a@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix output of anthropic-text-editor command using pformat Fix command log output using pformat instead of json.dumps Dec 30, 2025
Copilot AI requested a review from 0xba1a December 30, 2025 15:38
@codecov-commenter
Copy link

codecov-commenter commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.01%. Comparing base (167ed59) to head (c861d5c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #90      +/-   ##
==========================================
+ Coverage   91.89%   92.01%   +0.12%     
==========================================
  Files          21       21              
  Lines         814      814              
==========================================
+ Hits          748      749       +1     
+ Misses         66       65       -1     
Flag Coverage Δ
integration 59.95% <100.00%> (ø)
ollama_local 65.35% <100.00%> (-0.13%) ⬇️
slow-browser 54.91% <100.00%> (+0.12%) ⬆️
slow-other 70.39% <100.00%> (-1.23%) ⬇️
unit 65.35% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/microbots/MicroBot.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@0xba1a 0xba1a marked this pull request as ready for review December 30, 2025 16:16
@0xba1a 0xba1a merged commit cf9de5e into main Dec 30, 2025
6 checks passed
@0xba1a 0xba1a deleted the copilot/fix-anthropic-text-editor-output branch March 3, 2026 08:05
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.

Fix output of anthropic-text-editor command using pformat

4 participants