Skip to content

Improve JSON-RPC message rendering in markdown logs#162

Merged
pelikhan merged 6 commits into
mainfrom
copilot/update-jsonrpc-rendering
Jan 11, 2026
Merged

Improve JSON-RPC message rendering in markdown logs#162
pelikhan merged 6 commits into
mainfrom
copilot/update-jsonrpc-rendering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 11, 2026

Plan: Improve JSON-RPC Markdown Rendering

  • Update formatRPCMessageMarkdown in rpc_logger.go to:
    • Remove jsonrpc and method fields from JSON payload
    • Format JSON with proper indentation (2 spaces)
    • Use code block (~~~) instead of inline backticks
    • Change max length from 120 to 512 chars
    • Handle invalid JSON gracefully (use inline backticks)
    • Add empty line before code block for proper markdown rendering
    • Compress JSON by removing newlines after opening { and before closing }
  • Update tests in rpc_logger_test.go to verify new format
  • Run tests to validate changes
  • Manual verification of output format
  • Format code and pass linting
  • Run agent-finished checks

Summary

Successfully improved the JSON-RPC message markdown rendering with proper invalid JSON handling and compact formatting:

Valid JSON (compact code blocks with proper markdown):

- 🔍 rpc **safeoutputs**`tools/call` 

~~~
{ "params": {
    "arguments": {
      "body": "..."
    }
  } }
~~~

Invalid JSON (inline backticks to avoid malformed markdown):

- 🔍 rpc **github**`tools/call` `{invalid json syntax}`

Changes Made:

  1. Modified formatJSONWithoutFields() to return (string, bool) indicating JSON validity
  2. Updated formatRPCMessageMarkdown() to use inline backticks for invalid JSON
  3. Added empty line before code block opening (~~~) for proper markdown rendering
  4. Compressed JSON by removing newline after opening { and before closing }
  5. Added comprehensive tests for invalid JSON handling
  6. All existing tests pass with the new implementation
Original prompt

The markdown pretty rendering of JSON rpc messages should:

  • remote jsonrpc, method field
  • use code region
  • indented JSON, 2chars,
  • up to 512 chars

Current

  • 🔍 rpc safeoutputs→tools/call {"jsonrpc":"2.0","method":"tools/call","params":{"arguments":{"body":"## Smoke Test Results (Claude)\n\nLast 2 Merged ...

Updated

  • 🔍 rpc safeoutputs→tools/call
{...,"params":{"arguments":{"body":"## Smoke Test Results (Claude)\n\nLast 2 Merged ...

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 11, 2026 18:37
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update markdown rendering for JSON RPC messages Improve JSON-RPC message rendering in markdown logs Jan 11, 2026
Copilot AI requested a review from pelikhan January 11, 2026 18:42
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot Handle invalid JSON syntax gracefully

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 11, 2026

@copilot Handle invalid JSON syntax gracefully

Done in 6a0c921. Invalid JSON now uses inline backticks instead of code blocks to avoid malformed markdown. The function returns a boolean indicating JSON validity, and the formatter chooses the appropriate markdown style accordingly.

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot remove the first and last new line to compress rendering of JSON in markdown

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 11, 2026

@copilot remove the first and last new line to compress rendering of JSON in markdown

Done in c4b77a1. Removed the newline before the opening ~~~ to compress the rendering.

Before:

- 🔍 rpc **github**→`tools/call` 
~~~
{json}
~~~

After:

- 🔍 rpc **github**→`tools/call` ~~~
{json}
~~~

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot fix these:

Remove new line after the first { in json
Remove new line before the last } in JSON

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 11, 2026

@copilot fix these:

Done in 3e8e39b. All three formatting requirements applied:

  1. ~~~ on new line after empty line
  2. ✅ Removed newline after opening {
  3. ✅ Removed newline before closing }

Output:

- 🔍 rpc **safeoutputs**`tools/call` 

~~~
{ "params": {
    "arguments": {
      "body": "..."
    }
  } }
~~~

@pelikhan pelikhan marked this pull request as ready for review January 11, 2026 19:07
@pelikhan pelikhan merged commit b4ae445 into main Jan 11, 2026
3 checks passed
@pelikhan pelikhan deleted the copilot/update-jsonrpc-rendering branch January 11, 2026 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