refactor: consolidate agent-config path + JSON read/write helpers - #231
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
📝 WalkthroughWalkthroughThe PR centralizes Claude and OpenCode configuration paths and JSONC object handling. Component, initialization, and uninstall flows now use shared readers and pretty writers, with tests covering fallback behavior, JSONC parsing, and newline-terminated output. ChangesConfiguration persistence standardization
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/uninstall.rs`:
- Around line 105-111: Update clean_opencode to replace the serde_json::from_str
read of opencode_config_path() with the shared JSONC-aware object reader.
Preserve the existing cleanup behavior while allowing comments and trailing
commas in opencode.jsonc so instructions are removed successfully.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 7e07467c-9665-4cd5-986c-330d12bbac87
📒 Files selected for processing (5)
src/components.rssrc/init.rssrc/jsonc.rssrc/paths.rssrc/uninstall.rs
| fn clean_opencode(dry_run: bool) { | ||
| let rules_dir = home().join(".config").join("opencode").join("rules"); | ||
| let rules_dir = opencode_rules_dir(); | ||
| for f in &["exa.md", "git.md", "lean-ctx.md"] { | ||
| remove_file(&rules_dir.join(f), dry_run); | ||
| } | ||
|
|
||
| let config_path = home() | ||
| .join(".config") | ||
| .join("opencode") | ||
| .join("opencode.jsonc"); | ||
| let config_path = opencode_config_path(); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use the JSONC-aware reader for OpenCode cleanup.
opencode_config_path() targets opencode.jsonc, but the subsequent read still uses serde_json::from_str (Lines 113–117). Any valid config containing comments or trailing commas will fail parsing, so uninstall silently leaves its instructions behind. Replace this read with the shared JSONC object reader.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/uninstall.rs` around lines 105 - 111, Update clean_opencode to replace
the serde_json::from_str read of opencode_config_path() with the shared
JSONC-aware object reader. Preserve the existing cleanup behavior while allowing
comments and trailing commas in opencode.jsonc so instructions are removed
successfully.
…, #233) (#290) * skill CLI: add skill crate dep, migrate serde_yaml→serde_yml, wire skill subcommand Agentflare-Agent: 1 Agentflare-Branch: skill-detect-worktree * skill CLI: wire skill subcommand into command dispatch (#233) Agentflare-Agent: claude-code_2-1-216_agent Agentflare-Branch: skill-detect-worktree * skill-detect: intent classifier, MCP skill_detect tool, session/prompt injection hooks (#231) Agentflare-Agent: claude-code_2-1-216_agent Agentflare-Branch: skill-detect-worktree * skill CLI: use crate::paths::home() for testability, add install/registry tests (#233) Agentflare-Agent: claude-code_2-1-216_agent Agentflare-Branch: skill-detect-worktree * skill-detect: semantic re-rank via MiniLM ONNX pipeline, per-turn skill injection, clippy cleanup (#231) Agentflare-Agent: claude-code_2-1-216_agent Agentflare-Branch: skill-detect-worktree * fix(skill-registry): drop unsound serde_yml, run cargo fmt serde_yml has an unsound RUSTSEC-2025-0068 advisory (segfault risk in its Serializer) and its upstream project is archived; cargo-deny flags the 0.0.13 this crate's unconstrained "0.0" requirement resolved to. Switched to serde_yaml_ng, a maintained drop-in fork, for frontmatter parsing. Also applies the cargo fmt fix CI flagged on types.rs. Agentflare-Agent: claude-code_2-1-216_agent Agentflare-Branch: item-231-233-skill-detect
Summary
The agent-config code (
init.rs,components.rs,uninstall.rs) had repeated the same three inline idioms all over the place. This PR extracts them into shared helpers and routes the call sites through them — no behavior change other than reads becoming JSONC-tolerant (see below).1. Config path construction —
home().join(".claude").join("settings.json"),~/.claude.json,~/.claude/rules, and the~/.config/opencode/{opencode.jsonc,rules}triple were hand-built at ~30 sites. New helpers inpaths.rs:2. Read-config-as-object — every
wire_*/merge_*did:Collapsed to
jsonc::read_json_object(&p, || json!({})), which reads, falls back todefault()on missing/unreadable/invalid/non-object, and guarantees an object.3. Write-pretty-JSON-config —
fs::write(&p, serde_json::to_string_pretty(&v).unwrap() + "\n")(8+ copies, mixedunwrap()/unwrap_or_default()) →jsonc::write_json_pretty(&p, &v), keeping the exact 2-space-indent + trailing-\nbyte format in one place.Net: -142 / +156 lines, but the +156 is mostly the four new documented helpers and their tests; the duplicated call sites shrink substantially.
Test plan
cargo test(581 unit tests pass; newjsonchelper tests added. Thecaveman_cliintegration test is flaky under compile load on bothmasterand this branch — broken pipe writing to a stubbed CLI's stdin — unrelated to this change.)cargo clippy --locked --workspace --all-targets --all-features -- -D warnings -A unsafe_code -A clippy::pedanticcargo fmt --checkNotes for reviewers
read_json_objectreads via the existingread_jsonc, so~/.claude/settings.json,~/.codex/hooks.json, and.cursor/hooks.jsonreads now tolerate JSONC (comments / trailing commas) instead of silently falling back to an empty object onserde_json::from_strfailure. JSONC is a strict superset of JSON (seepure_json_passthroughtest), so any previously-parsing input parses identically; this only adds tolerance and is aligned with the reasonjsonc.rsexists (avoid clobbering a user's comment-bearing config).merge_json/merge_opencode_mcpsignatures changed from&PathBufto&Path(satisfiesclippy::ptr_arg; callers coerce automatically).Link to Devin session: https://app.devin.ai/sessions/19a419ad0c9e458e8fcfeef00b82d066
Requested by: @getappz
Summary by CodeRabbit
Bug Fixes
Refactor
Tests