Skip to content

feat(core): extract agent_config module for config R/W - #494

Merged
ajianaz merged 1 commit into
developfrom
feat/agent-config-module-432
Aug 5, 2026
Merged

feat(core): extract agent_config module for config R/W#494
ajianaz merged 1 commit into
developfrom
feat/agent-config-module-432

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

What

Extract config read/write/merge logic from install.rs into a standalone, testable agent_config module.

Why

The config handling logic (JSONC comment stripping, BOM handling, trailing comma tolerance, mcpServers injection) was buried inside install.rs with no unit tests. Issue #432 asks for a proper module so that:

  1. Future features (cora uninstall, cora config check) can reuse the same R/W logic
  2. Edge cases (BOM, JSONC comments, trailing commas) are handled correctly
  3. String values containing // or ,} are not corrupted during read-modify-write

How

  • New module src/commands/agent_config.rs with public API:
    • read_json_config() / write_json_config() — JSON/JSONC read+write
    • read_yaml_config() / write_yaml_config() — YAML read+write
    • json_has_cora() / json_add_cora() / json_remove_cora() — mcpServers CRUD
    • yaml_has_cora() / yaml_add_cora() / yaml_remove_cora() — YAML equivalents
    • read_config() / write_config() — format-agnostic dispatch
    • strip_bom() — UTF-8/16 BOM stripping
    • strip_jsonc_comments()string-aware state machine (not regex)
    • strip_trailing_commas()string-aware state machine (not regex)
  • Refactored install.rs to delegate to agent_config, removing ~120 lines of duplicated logic
  • 21 unit tests covering: comment stripping, BOM, trailing commas, string corruption edge cases, add/remove/has for both JSON and YAML

String-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 fail
  • cargo clippy --all-targets --features tree-sitter -- -D warnings — 0 warnings
  • cargo fmt --all -- --check — clean
  • Cora review — passed (fixed string-corruption finding before commit)

Related Issues

Closes #432

Checklist

  • Tests pass
  • No clippy warnings
  • Formatted
  • PR description follows template
  • Commit messages follow conventional commits
  • Linked to relevant issues

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
@ajianaz ajianaz added enhancement New feature or request scope:core Core review engine labels Aug 5, 2026
@ajianaz
ajianaz merged commit 0b187be into develop Aug 5, 2026
13 checks passed
@ajianaz
ajianaz deleted the feat/agent-config-module-432 branch August 5, 2026 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request scope:core Core review engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent config read/write module (JSON, JSONC, YAML)

1 participant