Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/kimi_cli/ui/shell/slash.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from kimi_cli.session import Session
from kimi_cli.soul.kimisoul import KimiSoul
from kimi_cli.ui.shell.console import console
from kimi_cli.utils.changelog import CHANGELOG
from kimi_cli.utils.changelog import get_changelog
from kimi_cli.utils.datetime import format_relative_time
from kimi_cli.utils.slashcmd import SlashCommand, SlashCommandRegistry

Expand Down Expand Up @@ -366,7 +366,7 @@ def changelog(app: Shell, args: str):
from kimi_cli.utils.rich.columns import BulletColumns

renderables: list[RenderableType] = []
for ver, entry in CHANGELOG.items():
for ver, entry in get_changelog().items():
title = f"[bold]{ver}[/bold]"
if entry.description:
title += f": {entry.description}"
Expand Down
20 changes: 16 additions & 4 deletions src/kimi_cli/utils/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def commit():
norm_entries = [
line.strip()[2:].strip() for line in bullet_lines if line.strip().startswith("- ")
]
result[current_ver] = ReleaseEntry(description=description, entries=norm_entries)
result[current_ver] = ReleaseEntry(
description=description, entries=norm_entries)

for raw in lines:
line = raw.rstrip()
Expand Down Expand Up @@ -103,6 +104,17 @@ def format_release_notes(changelog: dict[str, ReleaseEntry], include_lib_changes
return "\n".join(parts).strip()


CHANGELOG = parse_changelog(
(Path(__file__).parent.parent / "CHANGELOG.md").read_text(encoding="utf-8")
)
_cached_changelog: dict[str, ReleaseEntry] | None = None


def get_changelog() -> dict[str, ReleaseEntry]:
"""Lazily load and parse the changelog on first access."""
global _cached_changelog
if _cached_changelog is None:
path = Path(__file__).parent.parent / "CHANGELOG.md"
try:
_cached_changelog = parse_changelog(
path.read_text(encoding="utf-8"))
except FileNotFoundError:
_cached_changelog = {}
return _cached_changelog
Comment on lines +109 to +119
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

The new lazy loading mechanism lacks test coverage. While the existing test for parse_changelog will continue to work, there's no test that verifies the lazy loading behavior, the caching mechanism, or the FileNotFoundError handling. Consider adding a test that verifies: 1) the changelog is only loaded once (caching works), 2) calling get_changelog multiple times returns the same cached result, and 3) graceful handling when CHANGELOG.md is missing.

Copilot uses AI. Check for mistakes.
Loading