feat(config): migrate config file from json to toml#498
Conversation
Signed-off-by: Richard Chien <stdrc@outlook.com>
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
Signed-off-by: Richard Chien <stdrc@outlook.com>
Related Issue
Resolve #(issue_number)
Description