Make GLOBAL_ROOT configurable with env vars#83
Make GLOBAL_ROOT configurable with env vars#83hannesknoll wants to merge 2 commits intoRyandonofrio3:mainfrom
Conversation
Support configurable global home directory via: 1. $OSGREP_HOME env var (highest priority) 2. $XDG_CACHE_HOME/osgrep (if XDG var set) 3. ~/.cache/osgrep (default fallback) Replaces hardcoded ~/.osgrep for global resources (models, grammars).
- model-loader.ts: use PATHS.models instead of hardcoded path - download-worker.ts: use PATHS.models instead of hardcoded path - grammar-loader.ts: use PATHS.grammars instead of hardcoded path - index.ts: use PATHS.globalRoot for legacy data detection
WalkthroughThis pull request consolidates path computation logic into a centralized configuration module. A new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/config.ts (1)
49-57: LGTM! Well-implemented priority system.The
getOsgrepHome()function correctly implements the documented priority:
OSGREP_HOME(if set, resolved to absolute path)XDG_CACHE_HOME/osgrep(if XDG var set)~/.cache/osgrep(default)The use of
path.resolve()forOSGREP_HOMEproperly handles relative paths.📝 Optional: Add inline comment for clarity
Consider adding a brief comment above the function to document the priority order:
+// Priority: $OSGREP_HOME → $XDG_CACHE_HOME/osgrep → ~/.cache/osgrep function getOsgrepHome(): string { if (process.env.OSGREP_HOME) { return path.resolve(process.env.OSGREP_HOME); } // XDG compliance: $XDG_CACHE_HOME/osgrep or ~/.cache/osgrep const xdgCache = process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache"); return path.join(xdgCache, "osgrep"); }
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to data retention organization setting
📒 Files selected for processing (5)
src/config.tssrc/index.tssrc/lib/index/grammar-loader.tssrc/lib/setup/model-loader.tssrc/lib/workers/download-worker.ts
🧰 Additional context used
🧬 Code graph analysis (4)
src/lib/workers/download-worker.ts (1)
src/config.ts (1)
PATHS(61-65)
src/lib/index/grammar-loader.ts (1)
src/config.ts (1)
PATHS(61-65)
src/index.ts (1)
src/config.ts (1)
PATHS(61-65)
src/lib/setup/model-loader.ts (1)
src/config.ts (2)
PATHS(61-65)MODEL_IDS(4-7)
🔇 Additional comments (8)
src/index.ts (2)
19-19: LGTM! Centralized path configuration.The import of
PATHSaligns with the PR's goal of consolidating path resolution into a single, configurable source.
35-45: LGTM! Proper legacy migration handling.The legacy data path check correctly uses
PATHS.globalRootand provides clear guidance to users migrating from the old global database structure to the new per-project approach.src/lib/setup/model-loader.ts (2)
4-4: LGTM! Consistent with centralized configuration.Adding
PATHSto the imports aligns with the PR's refactoring to use centralized path management.
59-65: LGTM! Correctly migrated to PATHS.models.The function now uses
PATHS.modelsinstead of the hardcoded cache directory, maintaining the same logic while adopting the configurable path system.src/lib/index/grammar-loader.ts (1)
3-6: LGTM! Clean migration to centralized paths.The grammar directory now uses
PATHS.grammars, eliminating the hardcoded dependency onos.homedir()and adopting the configurable path system introduced in this PR.src/config.ts (1)
61-65: LGTM! Clean PATHS API.The
PATHSobject provides a clean, centralized API for all global path references. The structure (globalRoot, models, grammars) is intuitive and well-organized.src/lib/workers/download-worker.ts (2)
5-8: LGTM! Correct migration to PATHS.The worker now uses
PATHS.modelsfor the cache directory, eliminating the hardcoded dependency onos.homedir()and adopting the configurable path system.
65-69: LGTM! Consistent path construction.The destination directory correctly uses
PATHS.modelsas the base for model storage. The comment on line 67 provides a helpful example of the resulting path structure.
Currently osgrep uses the directory
~/.osgrepfor its cache. I don't like it when programs use my home dir directly for their cache.Therefore this PR adds the OSGREP_HOME environment variable to override the global osgrep directory location
This default to the XDG compliant path ($XDG_CACHE_HOME/osgrep or ~/.cache/osgrep) instead of ~/.osgrep
The path selection priority order is
For testing I ran
Note: Project-local .osgrep/ directories (for per-repo index data) remain unchanged.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.