dsh-terminal-render
Render DSH headless / CLI final output as readable terminal Markdown.
dsh --profile headless "task" currently prints the final assistant message as
raw Markdown source (**bold**, | tables |, # headings, …), which is
unreadable in a terminal. This plugin wraps process.stdout.write once at tree
mount so any Markdown-looking write is rendered to ANSI (CJK-aware) before it
reaches the terminal — with zero changes to the harness.
Why this works without touching DSH
The headless bundle (@deepseek-ai/dsh-headless) builds its IO as
{ stdout: internals.stdout, ... } where internals.stdout is the
process.stdout object, captured by reference. The final message is written
through process.stdout.write(outcome.text). Wrapping that method therefore
intercepts the output regardless of plugin load order.
CJK compatibility (the point of this plugin)
CommonMark's flanking rules and byte-oriented parsers mis-handle CJK prose,
which has no spaces between words:
**加粗**,中文— strong must close before a fullwidth comma / CJK char
(same rule as DSH web'scjkFriendlyStrongmicromark extension).中文**加粗**— emphasis must open/close with CJK neighbors.- CJK chars are 2 display cells: table columns are aligned by display width
(unicode-widthsemantics), not byte count. - Only
~~…~~is strikethrough; single~text~stays literal so LLM output
like~**10%**("approximately") is not struck (grok-build strategy).
Usage
# After wiring into the headless profile (see below):
dsh --profile headless "list my todos" # rendered, when stdout is a TTY
dsh --profile headless "…" | cat # passthrough (not a TTY)
Env controls:
| Variable | Effect |
|---|---|
NO_COLOR |
Disable rendering entirely (plain passthrough). |
DSH_TERMINAL_RENDER=0 |
Force plain passthrough even for Markdown text (piping). |
DSH_TERMINAL_RENDER=1 |
Force rendering even without a TTY. |
DSH_TERMINAL_LINKS=0 |
Disable OSC 8 hyperlinks. |
Rendering capabilities
- Headings
#–######(colored + bold),---rules - strong, emphasis,
inline code,strike(double-tilde only) [text](https://github.com/LosEcher/dsh-terminal-render/blob/main/url)links with OSC 8 hyperlinks (plain(url)suffix fallback)- Tables with box borders, display-width-aligned columns, per-cell alignment
(:---:,---:,:---), CJK-aware wrapping - Unordered/ordered/task lists (
- [x]), blockquotes - Fenced code blocks (language tag in the header, body in reverse video)
- LaTeX-friendly literals: no KaTeX, but single-tilde demotion avoids
strike-through surprises
Wiring into the headless profile
Add to ~/.dsh/profiles/headless/cordis.patch.yml:
- insert:
- id: terminal-render
name: dsh-terminal-render
and to ~/.dsh/profiles/headless/package.json dependencies:
"dsh-terminal-render": "github:LosEcher/dsh-terminal-render#main"
(During local development use "link:/absolute/path/to/dsh-terminal-render" instead,
then pnpm install in the profile and run a headless task.)
Wiring into the web profile
Same pattern in ~/.dsh/profiles/web/cordis.patch.yml and
~/.dsh/profiles/web/package.json; restart the web host afterwards.
Development
node --check lib/render.js
node --check lib/index.js
node test/run.mjs # 27 assertions: widths, inline, blocks, detection
License
MIT