Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Only write entries that are worth mentioning to users.

## Unreleased

- Shell: Fix black background on inline code and code blocks in Markdown rendering — `NEUTRAL_MARKDOWN_THEME` now overrides all Rich default `markdown.*` styles to `"none"`, preventing Rich's built-in `"cyan on black"` from leaking through on non-black terminals

## 1.30.0 (2026-04-02)

- Shell: Refine idle background completion auto-trigger — resumed shell sessions no longer auto-start a foreground turn from stale pending background notifications before the user sends a message, and fresh background completions now wait briefly while the user is actively typing to avoid stealing the prompt or breaking CJK IME composition
Expand Down
2 changes: 2 additions & 0 deletions docs/en/release-notes/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This page documents the changes in each Kimi Code CLI release.

## Unreleased

- Shell: Fix black background on inline code and code blocks in Markdown rendering — `NEUTRAL_MARKDOWN_THEME` now overrides all Rich default `markdown.*` styles to `"none"`, preventing Rich's built-in `"cyan on black"` from leaking through on non-black terminals

## 1.30.0 (2026-04-02)

- Shell: Refine idle background completion auto-trigger — resumed shell sessions no longer auto-start a foreground turn from stale pending background notifications before the user sends a message, and fresh background completions now wait briefly while the user is actively typing to avoid stealing the prompt or breaking CJK IME composition
Expand Down
2 changes: 2 additions & 0 deletions docs/zh/release-notes/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## 未发布

- Shell:修复 Markdown 渲染中行内代码和代码块出现黑色背景的问题——`NEUTRAL_MARKDOWN_THEME` 现在将所有 Rich 默认的 `markdown.*` 样式覆盖为 `"none"`,防止 Rich 内置的 `"cyan on black"` 在非黑色背景终端上泄露

## 1.30.0 (2026-04-02)

- Shell:细化空闲时后台完成的自动触发行为——恢复的 Shell 会话在用户发送消息前,不会因为历史遗留的后台通知而自动启动新的前景轮次;当用户正在输入时,新的后台完成事件也会短暂延后触发,避免抢占提示符或打断 CJK 输入法组合态
Expand Down
5 changes: 5 additions & 0 deletions src/kimi_cli/ui/shell/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"markdown.paragraph": "none",
"markdown.block_quote": "none",
"markdown.hr": "none",
"markdown.list": "none",
"markdown.item": "none",
Comment on lines 13 to 17
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added overrides markdown.list, markdown.h7, and markdown.emph don’t appear to be referenced anywhere else in the codebase (search only finds them in this theme). If they’re intended purely as a defensive override against Rich internals, it would help to add a brief comment explaining why these keys are needed here; otherwise consider dropping unused keys to keep the theme definition aligned with actual style names we render.

Copilot uses AI. Check for mistakes.
"markdown.item.bullet": "none",
"markdown.item.number": "none",
Expand All @@ -25,9 +26,13 @@
"markdown.h4": "none",
"markdown.h5": "none",
"markdown.h6": "none",
"markdown.h7": "none",
"markdown.em": "none",
"markdown.emph": "none",
"markdown.strong": "none",
"markdown.s": "none",
"markdown.code": "none",
"markdown.code_block": "none",
"status.spinner": "none",
},
inherit=True,
Expand Down
53 changes: 53 additions & 0 deletions tests/ui/test_console_theme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Tests for NEUTRAL_MARKDOWN_THEME style overrides."""

from __future__ import annotations

from kimi_cli.ui.shell.console import NEUTRAL_MARKDOWN_THEME


class TestNeutralMarkdownThemeNoBgColor:
"""markdown.code and markdown.code_block must not inherit Rich's default
black background (``"cyan on black"`` / ``"bold cyan on black"``).

Rich's built-in default theme defines::

"markdown.code": "bold cyan on black"
"markdown.code_block": "cyan on black"

Because NEUTRAL_MARKDOWN_THEME uses ``inherit=True``, any style key NOT
explicitly listed inherits the Rich default. If we forget to override
``markdown.code`` and ``markdown.code_block``, inline code and fenced code
blocks will render with an opaque black background that looks wrong on
non-black terminals (the "black code block" bug, see issue #1681).
"""

def test_markdown_code_has_no_background(self) -> None:
style = NEUTRAL_MARKDOWN_THEME.styles.get("markdown.code")
assert style is not None, "markdown.code must be explicitly set in NEUTRAL_MARKDOWN_THEME"
assert style.bgcolor is None, (
f"markdown.code should have no background color, got bgcolor={style.bgcolor}"
)

def test_markdown_code_block_has_no_background(self) -> None:
style = NEUTRAL_MARKDOWN_THEME.styles.get("markdown.code_block")
assert style is not None, (
"markdown.code_block must be explicitly set in NEUTRAL_MARKDOWN_THEME"
)
assert style.bgcolor is None, (
f"markdown.code_block should have no background color, got bgcolor={style.bgcolor}"
)

def test_all_markdown_styles_have_no_background(self) -> None:
"""No markdown.* style in NEUTRAL_MARKDOWN_THEME should carry a background color.

Rich's default theme may assign background colors to markdown styles
(e.g. ``"cyan on black"`` for code). Since NEUTRAL_MARKDOWN_THEME uses
``inherit=True``, any key we forget to override will inherit the Rich
default. This test catches that for ALL markdown styles, not just the
ones we know about today.
"""
for name, style in NEUTRAL_MARKDOWN_THEME.styles.items():
if name.startswith("markdown."):
assert style.bgcolor is None, (
f"{name} should have no background color, got bgcolor={style.bgcolor}"
)
Comment on lines +49 to +53
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_all_markdown_styles_have_no_background() only iterates over NEUTRAL_MARKDOWN_THEME.styles, which contains only explicitly-defined overrides. This won’t catch cases where a markdown.* key is missing and a background color is inherited from Rich’s defaults (the main failure mode described in the docstring). Consider enumerating the markdown style names you rely on (e.g., from kimi_cli.utils.rich.markdown._FALLBACK_STYLES and any other markdown.* names used via markup) and asserting Console(theme=NEUTRAL_MARKDOWN_THEME).get_style(name).bgcolor is None for each, so missing overrides fail the test.

Copilot uses AI. Check for mistakes.
Loading