feat(mctx)!: configure separate state and cache directories - #292
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe PR splits Config's single minimal directory into two bases: minimal_state_dir (state paths) and minimal_cache_dir (cache paths). Builder, Config, path helpers, Context cache initialization/accessor, a test, and a doc comment are updated to use the new layout. ChangesDirectory Layout Split
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/mctx/src/config.rs (1)
163-179:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix the fallback path: tilde won't expand in PathBuf.
The fallback
PathBuf::from("~/.cache")(lines 165-166, 177-178) creates a path with a literal~character, not the user's home directory. Shell tilde expansion doesn't occur inPathBuf::from(). This will create a directory named~relative to the current directory, causing unexpected behavior.The TODO comments at lines 159 and 171 show the correct approach using
dirs::home_dir().🐛 Proposed fix using dirs::home_dir()
minimal_state_dir: self.minimal_state_dir.unwrap_or_else(|| { dirs::cache_dir() - .unwrap_or_else(|| PathBuf::from("~/.cache")) + .unwrap_or_else(|| dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")).join(".cache")) .join("minimal") }),minimal_cache_dir: self.minimal_cache_dir.unwrap_or_else(|| { dirs::cache_dir() - .unwrap_or_else(|| PathBuf::from("~/.cache")) + .unwrap_or_else(|| dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")).join(".cache")) .join("minimal") }),Note: Added a final fallback to
.(current directory) in case bothdirs::cache_dir()anddirs::home_dir()returnNone, which can happen in unusual environments.🤖 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 `@crates/mctx/src/config.rs` around lines 163 - 179, The fallback PathBuf::from("~/.cache") used when building minimal_state_dir and minimal_cache_dir is incorrect because tilde isn't expanded; replace that fallback with logic that uses dirs::home_dir() to construct home_dir.join(".cache") and, if both dirs::cache_dir() and dirs::home_dir() are None, fall back to PathBuf::from(".") (current directory); update the expressions for minimal_state_dir and minimal_cache_dir (referencing minimal_state_dir, minimal_cache_dir, dirs::cache_dir(), dirs::home_dir(), and the existing unwrap_or_else closures) to build the cache path via home_dir instead of the literal "~/.cache".
🤖 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.
Outside diff comments:
In `@crates/mctx/src/config.rs`:
- Around line 163-179: The fallback PathBuf::from("~/.cache") used when building
minimal_state_dir and minimal_cache_dir is incorrect because tilde isn't
expanded; replace that fallback with logic that uses dirs::home_dir() to
construct home_dir.join(".cache") and, if both dirs::cache_dir() and
dirs::home_dir() are None, fall back to PathBuf::from(".") (current directory);
update the expressions for minimal_state_dir and minimal_cache_dir (referencing
minimal_state_dir, minimal_cache_dir, dirs::cache_dir(), dirs::home_dir(), and
the existing unwrap_or_else closures) to build the cache path via home_dir
instead of the literal "~/.cache".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: da113a19-145b-4c1c-80c2-4f09c992a6ca
📒 Files selected for processing (2)
crates/mctx/src/config.rscrates/mctx/src/lib.rs
f79d700 to
a77c944
Compare
Under Minimal One, we are going to have minimal state (like sandboxes, sessions etc) live in one directory (typically
$XDG_STATE_DIR/minimalor$HOME/.local/state/minimal) and cached objects (like the artifact cache, fetched sources etc) live in another ($XDG_CACHE_DIR/minimalor$HOME/.local/cache/minimal). This separation better follows the XDG specification.The default remains the same when the directories are not specified via the
mctx::ConfigBuilder. We should pick a date in the future to make a hard switch.Summary by CodeRabbit