Repository navigation
Moved config to .config - #50
BenediktChlopik wants to merge 21 commits into
Conversation
….config/free-llm-proxy-router Update all config search paths, default paths, and test expectations to use the XDG-compliant ~/.config/free-llm-proxy-router directory instead of the legacy ~/.free-llm-proxy-router location.
…roxy-router Update free-llm-proxy, free-llm-bench, and free-llm-scan to reference the new XDG-compliant config directory for config files, usage data, reliability data, and catalog files.
…router Update .secrets.example and config.example.yaml to reference the new XDG-compliant config directory for secrets, catalog, and enriched catalog paths.
…proxy-router Update documentation to reflect the new XDG-compliant config directory for config files, secrets, and deployment instructions.
…m-proxy-router Update the setup script's target directory and the cron refresh script's catalog source and log file paths to the new XDG-compliant location.
Update the comment about where usage/reliability state and scanned catalogs are stored to reflect the new XDG-compliant config directory.
Update the comment about where usage/reliability state and scanned catalogs are stored to reflect the new XDG-compliant config directory.
|
Thanks a lot for this, Benedikt! Moving to Before we merge, two things:
Small one: in the README Happy to merge as soon as the fallback is in. Thanks again, and tell me if you'd rather split this up! 🙏 |
…roxy-router Add XDG-compliant config directory support with legacy fallback: - pkg/config: add OldConfigDir(), NewConfigDir(), ExpandHome(), FileExists() - pkg/config: check legacy location for data files, dotenv, and config.yaml - cmd/*: add stateFilePath() helper to read from new location, fall back to legacy - cmd/proxy: write state files (usage.json, reliability.json) to new location - cmd/proxy, cmd/scan: fallback to legacy catalog.json if new one missing - cmd/proxy: log hint when only legacy config.yaml exists
Use os.UserConfigDir() (which respects $XDG_CONFIG_HOME on Linux, ~/Library/Application Support on macOS, %APPDATA% on Windows) instead of hardcoding ~/.config/free-llm-proxy-router. - NewConfigDir() now uses os.UserConfigDir() with fallback to ~/.config - Updated all references in config loading, defaults, data file search, dotenv paths, and documentation - Updated scripts/setup.sh and scripts/cron-refresh.sh to respect XDG_CONFIG_HOME - Updated test to use XDG_CONFIG_HOME for deterministic behavior
kaiser-data
left a comment
There was a problem hiding this comment.
Thank you so much for this, Benedikt, and for coming back so quickly with the legacy fallback and the XDG_CONFIG_HOME support. The fallback order in FindDataFile and defaultEnvPaths (new dir first, then legacy) is exactly what we hoped for, an explicit -c still wins, and writing state to the new location while reading from the old one migrates people without them noticing. go vet and go test -race ./... pass locally.
While testing, I found three things that would break existing setups, plus two smaller ones:
-
macOS uses a different directory than the docs and scripts.
NewConfigDir()callsos.UserConfigDir(), which returns~/Library/Application Supporton macOS (and%APPDATA%on Windows).setup.sh,cron-refresh.shand the README all write to~/.config/free-llm-proxy-router, so on a Mac the binary never finds the config thatsetup.shjust created. CouldNewConfigDir()follow XDG directly on every platform:$XDG_CONFIG_HOME/free-llm-proxy-routerif it is set, otherwise~/.config/free-llm-proxy-router? That matches the scripts and the PR title. -
$XDG_CONFIG_HOMEinconfig.example.yamlis never expanded. Nothing in the code expands env vars incatalog.path, so loading the example config gives the literal relative path$XDG_CONFIG_HOME/free-llm-proxy-router/catalog.json.setup.shcopies that file, so a scan would write into a directory named$XDG_CONFIG_HOMEunder the current working directory. Using~/.config/free-llm-proxy-router/...in the example (whichexpandHomehandles) fixes it. Another option is to leavecatalog.pathout of the example so the default fromsetDefaultsapplies. -
The legacy catalog fallback overrides an explicit path. In
free-llm-scan'sloadConfigand inrunProxy, anycatalog.paththat does not exist yet is swapped for~/.free-llm-proxy-router/catalog.jsonwhen that file exists. Sofree-llm-scan --catalog /tmp/new.json scan(or a customcatalog.pathin the config) quietly writes to the legacy file, and a scan never moves the catalog to the new location. Could the legacy fallback apply only whencatalog.pathis the default one, and only on the read side (proxy start, and the scan's merge with the existing catalog), while the scan always writes to the configured path? Reading still needs your check:FindDataFilelooks in./configs/before the legacy dir, so without it a source checkout would pick the bundled catalog over the user's scanned one. -
stateFilePathis copied into all threecmd/*/main.gofiles. Could it move topkg/config(e.g.config.StateFilePath(name)) next toNewConfigDir/OldConfigDir? Then there is one place to fix if the lookup changes. The exportedExpandHome/FileExistswrappers may then no longer be needed. -
A test for the fallback. In
pkg/config, withHOMEandXDG_CONFIG_HOMEpointed at temp dirs: only legacyconfig.yamlpresent → it is loaded; both present → the new one wins;XDG_CONFIG_HOMEset → it is used. Something like that would protect against all three bugs above.
Happy to help with any of these if useful. Thanks again for sticking with this one!
…back - Resolve cherry-pick conflicts in favor of XDG_CONFIG_HOME approach - NewConfigDir() follows XDG directly on every platform ($XDG_CONFIG_HOME or ~/.config) - config.example.yaml uses ~/.config/... paths (expandHome-compatible) - Legacy catalog fallback only applies to default path, read-side only - stateFilePath moved to config.StateFilePath() in pkg/config - Add fallback test covering legacy-only, both-present, and XDG_CONFIG_HOME cases
|
Thanks for the detailed review! I’ve hopefully addressed everything:
I also resolved the merge conflicts and restored |
Remove conflict markers and duplicate function definitions in: - config.go: drop duplicate OldConfigDir/NewConfigDir/StateFilePath at top - datafile.go: remove legacy path from FindDataFile (CatalogReadPath handles it) - dotenv.go: clean up defaultEnvPaths formatting Fixes compilation errors in all three main commands.
2ec1f2d to
8c757a3
Compare
kaiser-data
left a comment
There was a problem hiding this comment.
Thank you so much for the quick and thorough revision, @BenediktChlopik! The macOS directory, the example config, the centralized StateFilePath and the new fallback test are all exactly what we hoped for, and go vet + go test -race ./... pass locally for me too. We're very close. A few things I found while testing the upgrade path (someone who only has ~/.free-llm-proxy-router/):
-
free-llm-scanstill writes to the legacy catalog.loadConfig()incmd/free-llm-scan/main.gosetscfg.Catalog.Path = legacyPathwhen the default path is missing, andupdate/refresh-llmthencatalog.Savetocfg.Catalog.Path. I checked it with a throwaway test (HOME=temp dir with only a legacycatalog.json, no config): the write target is~/.free-llm-proxy-router/catalog.json. Because the proxy watches the new path, a scan never hot-reloads into a running proxy for upgraders. Could you drop that block fromloadConfig()?loadCatalogForRead→CatalogReadPathalready covers the read side, so writes would land in the new dir and migrate the user naturally. -
The same block in
cmd/free-llm-proxy/main.gois redundant.CatalogReadPathalready does the legacy fallback for the default path, so the proxy can go back to the singlecatPath := config.CatalogReadPath(cfg.Catalog.Path, cfgFile). That keeps the fallback logic in one place (and letsExpandHome/FileExistsstay unexported, plusdefaultCatalogPathvsDefaultCatalogPathand the unusedDefaultEnrichedPathcan collapse to one). -
usage.json/reliability.jsonhave no legacy read fallback. The comments say "new location with legacy fallback", butStateFilePathonly returns the new dir, so on first start after upgrading the daily quota counters and reliability history start from zero. A smallStateReadPath(name)(new path if it exists, else legacy, else new) for the twoLoadcalls would fix it; saving toStateFilePathas you do now is right. -
README
scpline:~/free-llm-proxy-router/there is the install directory on the board (binary +configs/next to it), not the config dir, so it should stay as it was. Also, sinceXDG_CONFIG_HOMEis unset on most systems, could the README say~/.config/free-llm-proxy-router/(or$XDG_CONFIG_HOME/…if set)? Otherwise people copy a path that expands to/free-llm-proxy-router. -
Small one: the double blank lines added after the imports in the three
cmd/*/main.gofiles makecmd/free-llm-scan/main.gofailgofmt -l(it was clean on main). Agofmt -won those three would fix it.
With 1–3 in place I'd be happy to merge. Thanks again for sticking with this, it's a really nice improvement for everyone on Linux!
Add StateReadPath() that checks the new XDG config location first, then falls back to the legacy ~/.free-llm-proxy-router location, returning the new path if neither exists so writers create files in the new directory.
Replace inline legacy-fallback logic in runProxy with calls to config.CatalogReadPath() and config.StateReadPath(), which handle the XDG-to-legacy fallback centrally. Remove the now-unused path/filepath import.
Drop the legacy-path fallback from loadConfig(); writers always write to the configured path and CatalogReadPath handles read-side fallback. Remove unused path/filepath import and extra blank lines.
Use ${XDG_CONFIG_HOME:-~/.config} instead of bare $XDG_CONFIG_HOME
in the example scp command so it works when XDG_CONFIG_HOME is unset.
Drop two stray blank lines after the import block in main.go.
Later, I want to create a PKGBUILD for Arch Linux so that
free-llm-proxy-routercan be made available through the AUR. To make the installation cleaner, I propose moving the configuration files to~/.config.