Skip to content

Prettify markdown RPC message rendering with proper JSON indentation#168

Merged
pelikhan merged 2 commits intomainfrom
copilot/prettify-markdown-rendering
Jan 11, 2026
Merged

Prettify markdown RPC message rendering with proper JSON indentation#168
pelikhan merged 2 commits intomainfrom
copilot/prettify-markdown-rendering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 11, 2026

RPC messages in markdown logs were using compressed single-line JSON format and showing empty payloads. This makes logs harder to read when debugging message flows.

Changes

JSON formatting (internal/logger/rpc_logger.go)

  • Removed compression logic that collapsed JSON to single-line format with { ... }
  • Now uses json.MarshalIndent with 2-space indentation for proper pretty printing

Empty payload handling

  • Added isEffectivelyEmpty() to detect when only params: null or empty objects remain after field removal
  • Modified formatJSONWithoutFields() to return isEmpty boolean alongside formatted output
  • Updated formatRPCMessageMarkdown() to omit JSON code blocks when payload is effectively empty

Before:

**serena**`tools/list`

~~~
{ "params": null }
~~~

After:

**serena**`tools/list`

With content - Before:

**serena**`tools/list`

~~~
{ "id": 1, "params": { "arg": "value" } }
~~~

With content - After:

**serena**`tools/list`

~~~
{
  "id": 1,
  "params": {
    "arg": "value"
  }
}
~~~

Test updates

  • Updated TestFormatJSONWithoutFields for new 3-value return signature
  • Added test cases for params: null and empty object edge cases
  • Added test cases verifying empty JSON blocks are not rendered
Original prompt

Prettify the markdown rendering of read and write RPC messages see below:

  • 🔍 rpc serena←resp {"jsonrpc":"2.0","id":1,"result":{"tools":[{"annotations":{"destructiveHint":false,"readOnlyHint":true,"title":"List Dir"},"description":"Lists files and directories in the given directory (optionally with recursion). Returns a JSON object with the names of directories and files within the given directory.","inputSchema":{"properties":{"max_answer_chars":{"default":-1,"description":"If the output is longer than this number of characters,\nno content will be returned. -1 means the default value from the conf...

Apply JSON pretty printing.

If a JSON message only has param: null after removing field, don't show.


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

- Remove JSON compression logic to enable proper pretty printing with 2-space indentation
- Add logic to hide JSON blocks when only params:null or empty object remains after field removal
- Update formatJSONWithoutFields to return isEmpty boolean
- Add new test cases for params:null and empty object scenarios
- All tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Prettify markdown rendering for RPC messages Prettify markdown RPC message rendering with proper JSON indentation Jan 11, 2026
Copilot AI requested a review from pelikhan January 11, 2026 20:34
@pelikhan pelikhan marked this pull request as ready for review January 11, 2026 20:34
@pelikhan pelikhan merged commit ecfe792 into main Jan 11, 2026
3 checks passed
@pelikhan pelikhan deleted the copilot/prettify-markdown-rendering branch January 11, 2026 20:37
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