Repository navigation
Conversation
This was referenced Nov 17, 2026
This was referenced Nov 17, 2026
rumpl
force-pushed
the
rumpl/markdown-transform-hooks
branch
from
November 17, 2026 22:47
dd8736f to
334b07c
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Status markers inside multiline Markdown code spans can be incorrectly replaced, and images added or rewritten by transformers fail to render inline.
2 open issues
What changed in this PR
Adds configurable, display-only Markdown transformers to the full TUI. Assistant replies can be rewritten for presentation without changing stored messages, model context, exports, or whole-message copying.
Changes:
- Introduces persistent JSON-RPC transformer processes with timeouts, restart handling, ordered execution, and background scheduling.
- Integrates transformed rendering, batched refreshes, and reply-completion tracking across TUI tabs.
- Adds user settings, protocol documentation, a Python example, and lifecycle tests.
| File | Description |
|---|---|
pkg/userconfig/userconfig.go |
Adds transformer settings. |
pkg/userconfig/userconfig_test.go |
Tests settings serialization. |
pkg/tui/tui.go |
Owns the shared display and its lifecycle. |
pkg/tui/streamcontent/streams.go |
Tracks active streams per session. |
pkg/tui/streamcontent/streams_test.go |
Tests nested-stream completion tracking. |
pkg/tui/page/chat/runtime_events.go |
Completes replies when session streams stop. |
pkg/tui/page/chat/chat.go |
Wires display configuration and stream resets. |
pkg/tui/messages/messages.go |
Adds transform-completion notifications. |
pkg/tui/markdown_display.go |
Batches transform refreshes across tabs. |
pkg/tui/image_support.go |
Reuses the shared chat broadcast helper. |
pkg/tui/dispatch.go |
Extracts all-tab message dispatch. |
pkg/tui/components/messages/transform_test.go |
Tests completion and transcript refresh behavior. |
pkg/tui/components/messages/messages.go |
Refreshes transformed items and creates streaming replies. |
pkg/tui/components/messages/assistant_content.go |
Completes logical replies and session segments. |
pkg/tui/components/message/transform_test.go |
Tests display isolation, styling, and copy behavior. |
pkg/tui/components/message/message.go |
Renders transformed snapshots with trusted styling. |
pkg/markdowntransform/transformer.go |
Implements request timeouts and restart policy. |
pkg/markdowntransform/transformer_test.go |
Tests process reuse, failures, and chains. |
pkg/markdowntransform/rpc.go |
Implements newline-delimited JSON-RPC calls. |
pkg/markdowntransform/rpc_test.go |
Tests responses, errors, and timeouts. |
pkg/markdowntransform/markdowntransform.go |
Defines configuration, inputs, and ordered execution. |
pkg/markdowntransform/main_test.go |
Provides subprocess test helpers. |
pkg/markdowntransform/display.go |
Schedules snapshots and versions completed results. |
pkg/markdowntransform/display_test.go |
Tests scheduling, throttling, and notifications. |
pkg/markdowntransform/command.go |
Manages process pipes and diagnostic logging. |
examples/markdown-transform/settings.yaml.example |
Shows transformer configuration. |
examples/markdown-transform/emphasis.py |
Demonstrates status-marker styling. |
docs/configuration/user-settings/index.md |
Documents configuration, protocol, and display behavior. |
Review effort: Balanced
Comment on lines
+11
to
+31
| TOKEN = re.compile(r"(`+)(.*?)\1|\[\[(Done|Passed|Failed|Blocked|Needs you)\]\]") | ||
| FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})") | ||
|
|
||
|
|
||
| def decorate(markdown): | ||
| lines = [] | ||
| fence = None | ||
| for line in markdown.splitlines(keepends=True): | ||
| match = FENCE.match(line) | ||
| if fence: | ||
| if match and match[1][0] == fence[0] and len(match[1]) >= len(fence): | ||
| fence = None | ||
| elif match: | ||
| fence = match[1] | ||
| else: | ||
| line = TOKEN.sub( | ||
| lambda m: m[0] if m[1] else f"\033[{COLORS[m[3]]};7m {m[3]} \033[27;39m", | ||
| line, | ||
| ) | ||
| lines.append(line) | ||
| return "".join(lines) |
|
|
||
| innerRenderWidth := width - messageStyle.GetHorizontalFrameSize() | ||
| content, imagePlaceholders := mv.markdownImagePlaceholders(msg.Content, innerRenderWidth) | ||
| content, imagePlaceholders := mv.markdownImagePlaceholders(mv.displayMarkdown(innerRenderWidth), innerRenderWidth) |
Add settings.markdown_transformers: external commands that rewrite assistant Markdown before the TUI renders it, like Pi's registerMarkdownTransformer. Stored messages, model context, copies and exports keep the original Markdown. Each command runs as one long-lived process speaking newline-delimited JSON-RPC 2.0 (markdown/transform). Requests carry the full Markdown and are served by one background worker, so rendering never waits on a process: a message shows its source until its first result, then its latest result. Newest renders are transformed first, streaming replies at most once per 50 ms, and failing processes restart at most once per second. Replies report is_streaming until their saved message arrives or the last stream of their session stops. Signed-off-by: Djordje Lukic <[email protected]>
rumpl
force-pushed
the
rumpl/markdown-transform-hooks
branch
from
November 17, 2026 22:58
334b07c to
210ef18
Compare
Comment on lines
+1004
to
+1006
| mv.markdownVersion = version | ||
| mv.renderCache.valid = false | ||
| return true |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
Adds
settings.markdown_transformers: display-only rewriting of assistant Markdown in the TUI, modeled on Pi'sregisterMarkdownTransformer. Stored messages, model context, exports, and the copy-message action keep the original Markdown; mouse selection copies what is displayed.Each transformer is a long-lived process speaking newline-delimited JSON-RPC 2.0 on stdio. The TUI sends
markdown/transformwith the complete Markdown snapshot, plusmessage_type,is_streaming,available_width, and message identity; the reply'sresult.markdownis rendered. Transformers run in order, and a failing one leaves the preceding Markdown in place.Third of a stack, split to keep reviews focused. Replaces #4943, which has the earlier review history.
Design
pkg/markdowntransformhas independent layers:command.go: starts the process and exposes stdin plus stdout lines. It has no protocol knowledge.rpc.go: JSON-RPC 2.0 over any writer and line stream. It has no process knowledge.transformer.go: themarkdown/transformmethod, the per-request timeout, and the restart policy. Error replies keep the process running. Malformed output, timeouts, and exits restart it, at most once per second. Transformers must exit when stdin closes.display.go: one background worker for the program. Each rendered message owns aSurface.Sending the full Markdown keeps transformers stateless, as in Pi, where the transformer runs synchronously once per frame. The rate limit bounds the cost of resending long replies over a pipe.
TUI integration:
is_streaminguntil their saved message arrives or the last stream of their session stops, including segments split at tool or reasoning boundaries. A nested stream completes its own replies but not the parent's, even when it shares the parent's session.AllowSGR(feat(markdown): render trusted SGR styling and replay it across wraps #4949).RefreshInterval. The live reply is spliced in, and other changes share one rebuild.Known limitation: replies of a remote nested stream that shares its parent's session complete when that session's last stream stops, because runtime events carry no stream identity. Tracked in #4951.
A Go implementation of Pi Emphasis using this protocol is at https://github.com/rumpl/markdown-emphasis.
Validation
task buildpasses.pkg/markdowntransform,pkg/tui/..., andpkg/userconfig. They include real subprocess tests for process reuse, error replies, timeout and exit restarts, and ordered chains.golangci-lint run --new-from-revand the project cops report no issues. Windowsgo vetpasses for the affected packages.task testfails only on the existingTestACPRuntimeConfig_ModelSwitchingIsSessionOwned.