Commit 0b9f760
Yogthos
refactor(ui): single render pipeline for agent chat with base-color parameter
User wants reasoning + content streams to share ONE rendering engine
while keeping their distinct colors (reasoning = thinking voice,
content = response voice). All highlights need to remain visible
across whichever color a stream picks.
## Single engine: `render_agent_stream`
New helper in `src/ui/mod.rs` is the sole rendering path for both
Reasoning and Token events:
```rust
fn render_agent_stream(
buf: &str,
start_line: &mut Option<usize>,
base_color: Color,
renderer: &mut Renderer,
) -> anyhow::Result<()>
```
- Parses `buf` via `markdown_to_styled` so bold / italics / inline
code / headings / code blocks / blockquotes stay styled.
- `base_color` sets the body / paragraph color — each stream picks
its own register without forking the engine.
- Replaces in place at the stream's `start_line` anchor so successive
chunks update the same buffer region.
Reasoning handler now calls `render_agent_stream(reasoning_buf,
reasoning_start_line, Color::DarkMagenta, renderer)`. Token handler
calls the same with `c_agent()`. No duplicated rendering logic.
## Theme-driven highlights
`markdown_to_styled` gains a `base_color: Color` parameter. Internal
`theme::agent()` hardcoding is gone; body text uses the passed
`base_color`. Highlights still go through their dedicated theme
accessors:
- Headings → `theme::header()`
- Code blocks → `theme::tool()`
- Inline emphasis / accents → `theme::accent()`
- Blockquotes / trailers → `theme::dim()`
Swap the theme, all highlights shift in one place. Swap the
`base_color` (per stream), only the body shifts.
## Call sites updated
All 4 production callers of `markdown_to_styled` pass an explicit
base color:
- `ui/mod.rs` Token handler → `c_agent()` (theme-configurable)
- `ui/mod.rs` Done / Interjected handlers → `c_agent()`
- `ui/events.rs` (history replay) → `line_color` (per-role)
- `ui/slash.rs` btw_query → `c_agent()`
Plus 3 test sites in `markdown.rs` for `render_table` and the
existing markdown tests — all pass explicit `theme::agent()`.
## Why not unify the colors
The user asked first about unifying, then reconsidered: reasoning
and content carry semantically distinct meanings (model's thinking
vs its reply) and a different color communicates that distinction.
The shared engine + parameterized base color gives us "single
implementation, distinct visual register" cleanly.
## Test
1208/1215 pass (1 pre-existing Clojure failure unchanged; the
other 6 are pre-existing apply_patch/memory test flakiness under
concurrent execution — they all pass with `--test-threads=1`).
Binary at ~/bin/dirge.1 parent 306f11f commit 0b9f760
4 files changed
Lines changed: 127 additions & 100 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| |||
261 | 262 | | |
262 | 263 | | |
263 | 264 | | |
264 | | - | |
| 265 | + | |
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
269 | | - | |
| 270 | + | |
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
273 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
274 | 287 | | |
275 | 288 | | |
276 | 289 | | |
| |||
315 | 328 | | |
316 | 329 | | |
317 | 330 | | |
318 | | - | |
| 331 | + | |
319 | 332 | | |
320 | 333 | | |
321 | 334 | | |
322 | 335 | | |
323 | 336 | | |
324 | | - | |
| 337 | + | |
325 | 338 | | |
326 | 339 | | |
327 | 340 | | |
| |||
330 | 343 | | |
331 | 344 | | |
332 | 345 | | |
333 | | - | |
| 346 | + | |
334 | 347 | | |
335 | 348 | | |
336 | 349 | | |
| |||
339 | 352 | | |
340 | 353 | | |
341 | 354 | | |
342 | | - | |
| 355 | + | |
343 | 356 | | |
344 | 357 | | |
345 | 358 | | |
346 | 359 | | |
347 | 360 | | |
348 | | - | |
| 361 | + | |
349 | 362 | | |
350 | 363 | | |
351 | 364 | | |
| |||
402 | 415 | | |
403 | 416 | | |
404 | 417 | | |
405 | | - | |
| 418 | + | |
406 | 419 | | |
407 | 420 | | |
408 | 421 | | |
| |||
428 | 441 | | |
429 | 442 | | |
430 | 443 | | |
431 | | - | |
| 444 | + | |
432 | 445 | | |
433 | 446 | | |
434 | 447 | | |
| |||
467 | 480 | | |
468 | 481 | | |
469 | 482 | | |
470 | | - | |
| 483 | + | |
471 | 484 | | |
472 | 485 | | |
473 | 486 | | |
| |||
500 | 513 | | |
501 | 514 | | |
502 | 515 | | |
503 | | - | |
| 516 | + | |
504 | 517 | | |
505 | 518 | | |
506 | 519 | | |
507 | 520 | | |
508 | 521 | | |
509 | 522 | | |
510 | | - | |
| 523 | + | |
511 | 524 | | |
512 | 525 | | |
513 | 526 | | |
| |||
554 | 567 | | |
555 | 568 | | |
556 | 569 | | |
557 | | - | |
| 570 | + | |
558 | 571 | | |
559 | 572 | | |
560 | 573 | | |
561 | 574 | | |
562 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
563 | 582 | | |
564 | 583 | | |
565 | 584 | | |
| |||
648 | 667 | | |
649 | 668 | | |
650 | 669 | | |
651 | | - | |
| 670 | + | |
652 | 671 | | |
653 | 672 | | |
654 | 673 | | |
| |||
657 | 676 | | |
658 | 677 | | |
659 | 678 | | |
660 | | - | |
| 679 | + | |
661 | 680 | | |
662 | 681 | | |
663 | 682 | | |
| |||
688 | 707 | | |
689 | 708 | | |
690 | 709 | | |
691 | | - | |
| 710 | + | |
692 | 711 | | |
693 | 712 | | |
694 | 713 | | |
| |||
734 | 753 | | |
735 | 754 | | |
736 | 755 | | |
737 | | - | |
| 756 | + | |
738 | 757 | | |
739 | 758 | | |
740 | 759 | | |
| |||
750 | 769 | | |
751 | 770 | | |
752 | 771 | | |
753 | | - | |
| 772 | + | |
754 | 773 | | |
755 | 774 | | |
756 | 775 | | |
| |||
765 | 784 | | |
766 | 785 | | |
767 | 786 | | |
768 | | - | |
| 787 | + | |
769 | 788 | | |
770 | 789 | | |
771 | 790 | | |
| |||
788 | 807 | | |
789 | 808 | | |
790 | 809 | | |
791 | | - | |
| 810 | + | |
792 | 811 | | |
793 | 812 | | |
794 | 813 | | |
| |||
802 | 821 | | |
803 | 822 | | |
804 | 823 | | |
805 | | - | |
| 824 | + | |
806 | 825 | | |
807 | 826 | | |
808 | 827 | | |
| |||
816 | 835 | | |
817 | 836 | | |
818 | 837 | | |
819 | | - | |
| 838 | + | |
820 | 839 | | |
821 | 840 | | |
822 | 841 | | |
| |||
833 | 852 | | |
834 | 853 | | |
835 | 854 | | |
836 | | - | |
| 855 | + | |
| 856 | + | |
837 | 857 | | |
838 | 858 | | |
839 | 859 | | |
| |||
0 commit comments