Render assistant text as markdown in the chat transcript
Add a dependency-free CommonMark-subset parser/renderer (ui/chat/Markdown.kt): paragraphs, headings, fenced code, block quotes, bullet/ordered lists, tables, thematic rules and inline code/bold/italic/links/autolinks. The renderer turns blocks into themed, selectable Compose content: fenced code reuses the shared CodeBlock (existing whole-block copy action), tables are a bordered grid with a bold header, links use LinkAnnotation.Url, and inline code/headings use the shared type roles. ChatScreen.MessagePart now calls MarkdownText(part.text) for PART_TEXT instead of a single plain Text; the assistant message stays one SelectionContainer, so all of it remains selectable and long content stays inside the bubble. Geometry reuses the chat tokens (CHAT_ITEM_GAP promoted private -> internal). Add MarkdownTest with 10 unit tests covering fences/language, unterminated fences, soft-wrap joining, headings/rules, lists, tables, inline spans, bare-URL autolinks and snake_case non-emphasis. Document the change in android/README.md.
This commit is contained in:
@@ -2359,3 +2359,64 @@ Evidence (macOS, JDK 17, Gradle 9.7.1 `--offline`,
|
||||
|
||||
Still not verified: the live brokered server (separate lane), streaming against
|
||||
real OpenCode, and attachments — unchanged from the pass above.
|
||||
|
||||
## Conversation markdown rendering (16 Oct 2026)
|
||||
|
||||
The assistant's `text` part was rendered as one plain `Text`; it is now rendered
|
||||
as markdown, matching the reference experience (research report Part 1 §1.2).
|
||||
`android/` only; no new dependency (still just the declared
|
||||
`material-icons-extended`), no Pipelines server/Go/installer/Docker file touched,
|
||||
no run started from the app, and `emulator-5556` only (lane A's `emulator-5554`
|
||||
was never addressed).
|
||||
|
||||
- **Parser.** `ui/chat/Markdown.kt` adds a small, dependency-free CommonMark
|
||||
subset. It is pure Kotlin (no Compose, no transport) so it is unit-testable:
|
||||
paragraphs (soft-wrapped lines join with a space), `#`..`######` headings,
|
||||
fenced code (``` ``` / `~~~`, with the info string as the language), block
|
||||
quotes, bullet and ordered lists, `|` tables (with a `---` delimiter row),
|
||||
thematic rules, and inline code / bold / italic / `[label](url)` /
|
||||
bare-`http(s)://` autolinks. Underscore emphasis needs word boundaries so
|
||||
`snake_case` is never italicised. Anything outside the subset renders as plain
|
||||
text, never dropped.
|
||||
- **Renderer.** The same file turns the blocks into themed, selectable Compose
|
||||
content: fenced code reuses the shared `CodeBlock`, so the whole-block copy
|
||||
action is the existing one (label = the fence language, `code` when absent);
|
||||
tables are a bordered grid with a bold header and equal-weight wrapping cells;
|
||||
links use `LinkAnnotation.Url`, so they are tap-openable and styled from the
|
||||
scheme; inline code and headings use the shared type roles
|
||||
(`pipelinesText()`), not ad-hoc sizes. `ChatScreen.MessagePart` now calls
|
||||
`MarkdownText(part.text)` for `PART_TEXT`; the assistant message stays one
|
||||
`SelectionContainer`, so all of it remains selectable and the bounded code
|
||||
block/table keep long content inside the bubble. Geometry reuses the chat
|
||||
tokens (`CHAT_ITEM_GAP`, promoted from `private` to `internal`); only the
|
||||
quote-bar width and table border, which had no token, are new named constants.
|
||||
|
||||
Evidence (macOS, JDK 17, Gradle 9.7.1 `--offline`,
|
||||
`ANDROID_HOME=/Users/alan/Library/Android/sdk`):
|
||||
|
||||
- `gradle :app:assembleDebug :app:testDebugUnitTest --offline` → `BUILD
|
||||
SUCCESSFUL`; the JUnit XML totals **243 tests, 0 failures, 0 errors, 0
|
||||
skipped** (new `MarkdownTest`: fences keep their language, an unterminated
|
||||
fence still yields code, soft-wrapped paragraphs join, headings/rules parse by
|
||||
level, bullet/ordered lists, table header/rows, inline code/bold/italic/link,
|
||||
bare-URL autolink trims trailing punctuation, `snake_case` is not emphasis,
|
||||
empty source → no blocks).
|
||||
- The debug APK was installed on `emulator-5556` only and driven against a
|
||||
stdlib `/connect` WebSocket double serving a fixed history; capture was
|
||||
validated with `android/scripts/capture_png.sh -s emulator-5556`:
|
||||
`chat_markdown_conversation.png` shows the bottom-anchored transcript with the
|
||||
user bubble, the secondary reasoning line, body markdown with inline code and
|
||||
an underlined link, a `kotlin` fenced code block with its copy action, and the
|
||||
bordered `Surface | Role` table. `adb -s emulator-5556 logcat -d` held 0
|
||||
`FATAL EXCEPTION` and 0 `E AndroidRuntime` during the sweep.
|
||||
- **APK publish.** `app-debug.apk` (18,076,412 bytes, sha256
|
||||
`bb290a7f42a3b28e613098dfffea438c34a5332081cffc6a2fbc0d275c207f68`) copied to
|
||||
`~/.local/share/pipelines/data/artifacts/124/1/pipelines-debug-wip-0718f5b.apk`;
|
||||
`HEAD` is `0718f5b` and a streamed `curl | shasum -a 256` of
|
||||
`http://10.0.0.249:8080/artifacts/124/1/pipelines-debug-wip-0718f5b.apk`
|
||||
matched.
|
||||
|
||||
Not verified: the live brokered server (separate lane), streaming against real
|
||||
OpenCode, and attachments — unchanged from the passes above. The markdown subset
|
||||
is intentionally smaller than full CommonMark (no HTML, no reference links, no
|
||||
nested lists, no strikethrough).
|
||||
|
||||
Reference in New Issue
Block a user