feat(core): extract agent_config module for config R/W - #494
Merged
Conversation
Extract config read/write/merge logic from install.rs into a standalone agent_config module with comprehensive edge-case handling. Changes: - New src/commands/agent_config.rs module - String-aware JSONC comment stripping (state machine, not regex) - String-aware trailing comma removal (state machine) - BOM (UTF-8/16) stripping for cross-platform configs - Public API: read/write/add/remove for JSON, JSONC, YAML formats - Format-agnostic dispatch: read_config(), write_config() - Refactored install.rs to delegate to agent_config (removed duplication) - 21 unit tests covering all edge cases Closes #432
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extract config read/write/merge logic from
install.rsinto a standalone, testableagent_configmodule.Why
The config handling logic (JSONC comment stripping, BOM handling, trailing comma tolerance, mcpServers injection) was buried inside
install.rswith no unit tests. Issue #432 asks for a proper module so that:cora uninstall,cora config check) can reuse the same R/W logic//or,}are not corrupted during read-modify-writeHow
src/commands/agent_config.rswith public API:read_json_config()/write_json_config()— JSON/JSONC read+writeread_yaml_config()/write_yaml_config()— YAML read+writejson_has_cora()/json_add_cora()/json_remove_cora()— mcpServers CRUDyaml_has_cora()/yaml_add_cora()/yaml_remove_cora()— YAML equivalentsread_config()/write_config()— format-agnostic dispatchstrip_bom()— UTF-8/16 BOM strippingstrip_jsonc_comments()— string-aware state machine (not regex)strip_trailing_commas()— string-aware state machine (not regex)install.rsto delegate toagent_config, removing ~120 lines of duplicated logicString-aware comment stripping
Previous regex approach (
//.*) would corrupt URLs in config values like"https://example.com". The new state machine tracks string context to avoid this.Testing
cargo test --features tree-sitter— 893 pass, 0 failcargo clippy --all-targets --features tree-sitter -- -D warnings— 0 warningscargo fmt --all -- --check— cleanRelated Issues
Closes #432
Checklist