Skip to content

feat(config): migrate config file from json to toml#498

Merged
stdrc merged 2 commits intomainfrom
rc/toml-config
Dec 18, 2025
Merged

feat(config): migrate config file from json to toml#498
stdrc merged 2 commits intomainfrom
rc/toml-config

Conversation

@stdrc
Copy link
Copy Markdown
Contributor

@stdrc stdrc commented Dec 18, 2025

Related Issue

Resolve #(issue_number)

Description

Signed-off-by: Richard Chien <stdrc@outlook.com>
Copilot AI review requested due to automatic review settings December 18, 2025 07:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the configuration file format from JSON to TOML, updating the default config file path from ~/.kimi/config.json to ~/.kimi/config.toml. The migration includes automatic conversion of existing JSON configs to TOML format with a backup mechanism.

Key changes:

  • Default config file format changed from JSON to TOML
  • Added automatic migration from legacy JSON configs with backup
  • Both JSON and TOML formats now supported for backward compatibility

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pyproject.toml Added tomlkit dependency version 0.13.3
uv.lock Added tomlkit package with dependencies
src/kimi_cli/config.py Implemented TOML support, migration logic, and backward compatibility for both formats
tests/test_config.py Updated test to use model_dump() instead of model_dump_json()
AGENTS.md Updated documentation to reference config.toml instead of config.json
CHANGELOG.md Added changelog entry for the config migration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +198 to +226
def _migrate_json_config_to_toml() -> None:
old_json_config_file = get_share_dir() / "config.json"
new_toml_config_file = get_share_dir() / "config.toml"

if not old_json_config_file.exists():
return
if new_toml_config_file.exists():
return

logger.info(
"Migrating legacy config file from {old} to {new}",
old=old_json_config_file,
new=new_toml_config_file,
)

try:
with open(old_json_config_file, encoding="utf-8") as f:
data = json.load(f)
config = Config.model_validate(data)
except json.JSONDecodeError as e:
raise ConfigError(f"Invalid JSON in legacy configuration file: {e}") from e
except ValidationError as e:
raise ConfigError(f"Invalid legacy configuration file: {e}") from e

# Write new TOML config, then keep a backup of the original JSON file.
save_config(config, new_toml_config_file)
backup_path = old_json_config_file.with_name("config.json.bak")
old_json_config_file.replace(backup_path)
logger.info("Legacy config backed up to {file}", file=backup_path)
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

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

The migration function and the new TOML config format lack test coverage. Consider adding tests to verify: 1) migration from JSON to TOML works correctly with various config structures, 2) TOML files are loaded and saved correctly, 3) the backup file is created properly, and 4) the migration is idempotent (running it multiple times doesn't cause issues). This is especially important since this is a breaking change that affects user data.

Copilot uses AI. Check for mistakes.
Signed-off-by: Richard Chien <stdrc@outlook.com>
@stdrc stdrc merged commit a75a51b into main Dec 18, 2025
5 checks passed
@stdrc stdrc deleted the rc/toml-config branch December 18, 2025 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants