Skip to content

Moved config to .config - #50

Open
BenediktChlopik wants to merge 21 commits into
kaiser-data:mainfrom
BenediktChlopik:moved-config-to-.config
Open

BenediktChlopik wants to merge 21 commits into
kaiser-data:mainfrom
BenediktChlopik:moved-config-to-.config

Conversation

@BenediktChlopik

Copy link
Copy Markdown
Contributor

Later, I want to create a PKGBUILD for Arch Linux so that free-llm-proxy-router can be made available through the AUR. To make the installation cleaner, I propose moving the configuration files to ~/.config.

Bene added 7 commits November 22, 2026 09:27
….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.
@kaiser-data

Copy link
Copy Markdown
Owner

Thanks a lot for this, Benedikt! Moving to ~/.config is the right call, and packaging for the AUR would be great for the project. You caught every place the path appears (Go code, scripts, Dockerfile, README, examples), which makes this easy to review.

Before we merge, two things:

  1. Keep the old folder working. Right now anyone who upgrades loses their config.yaml, .secrets, usage.json, reliability.json and scanned catalog without any message, because the proxy only looks in the new folder. Could you keep ~/.free-llm-proxy-router as a fallback in the search paths (pkg/config/config.go, pkg/config/datafile.go, pkg/config/dotenv.go) and log a one-line hint to move it when only the old folder exists? State files (usage/reliability/catalog) should also be read from the old place if they aren't in the new one yet.
  2. Respect $XDG_CONFIG_HOME. Since the goal is XDG-friendly packaging, it would help to use os.UserConfigDir() (or $XDG_CONFIG_HOME, falling back to ~/.config) instead of hardcoding ~/.config.

Small one: in the README scp example, the binary is now copied into the config folder. It's probably clearer to keep the binary where it was and only copy configs/ there.

Happy to merge as soon as the fallback is in. Thanks again, and tell me if you'd rather split this up! 🙏

BenediktChlopik and others added 3 commits November 28, 2026 07:17
…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 kaiser-data left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. macOS uses a different directory than the docs and scripts. NewConfigDir() calls os.UserConfigDir(), which returns ~/Library/Application Support on macOS (and %APPDATA% on Windows). setup.sh, cron-refresh.sh and the README all write to ~/.config/free-llm-proxy-router, so on a Mac the binary never finds the config that setup.sh just created. Could NewConfigDir() follow XDG directly on every platform: $XDG_CONFIG_HOME/free-llm-proxy-router if it is set, otherwise ~/.config/free-llm-proxy-router? That matches the scripts and the PR title.

  2. $XDG_CONFIG_HOME in config.example.yaml is never expanded. Nothing in the code expands env vars in catalog.path, so loading the example config gives the literal relative path $XDG_CONFIG_HOME/free-llm-proxy-router/catalog.json. setup.sh copies that file, so a scan would write into a directory named $XDG_CONFIG_HOME under the current working directory. Using ~/.config/free-llm-proxy-router/... in the example (which expandHome handles) fixes it. Another option is to leave catalog.path out of the example so the default from setDefaults applies.

  3. The legacy catalog fallback overrides an explicit path. In free-llm-scan's loadConfig and in runProxy, any catalog.path that does not exist yet is swapped for ~/.free-llm-proxy-router/catalog.json when that file exists. So free-llm-scan --catalog /tmp/new.json scan (or a custom catalog.path in 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 when catalog.path is 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: FindDataFile looks in ./configs/ before the legacy dir, so without it a source checkout would pick the bundled catalog over the user's scanned one.

  4. stateFilePath is copied into all three cmd/*/main.go files. Could it move to pkg/config (e.g. config.StateFilePath(name)) next to NewConfigDir/OldConfigDir? Then there is one place to fix if the lookup changes. The exported ExpandHome/FileExists wrappers may then no longer be needed.

  5. A test for the fallback. In pkg/config, with HOME and XDG_CONFIG_HOME pointed at temp dirs: only legacy config.yaml present → it is loaded; both present → the new one wins; XDG_CONFIG_HOME set → 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!

Bene added 5 commits November 30, 2026 10:29
…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
@BenediktChlopik

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review! I’ve hopefully addressed everything:

  • NewConfigDir() now follows $XDG_CONFIG_HOME directly on every platform, falling back to ~/.config/free-llm-proxy-router, so it stays consistent with the scripts and documentation.
  • config.example.yaml now uses ~/.config/... paths, which are handled by expandHome, instead of the unexpanded $XDG_CONFIG_HOME placeholder.
  • The legacy catalog fallback now only applies to the default catalog path and on the read side. Explicit catalog.path values and scan writes always use the configured location.
  • stateFilePath has been moved into pkg/config as config.StateFilePath(), so the lookup logic is centralized.
  • I added a fallback test covering legacy-only config, both legacy and new config present, and $XDG_CONFIG_HOME being set.

I also resolved the merge conflicts and restored .env.example, which had been accidentally removed. go vet and go test -race ./... should now pass. Let me know if anything else needs adjusting!

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.
@BenediktChlopik
BenediktChlopik force-pushed the moved-config-to-.config branch from 2ec1f2d to 8c757a3 Compare December 1, 2026 06:22

@kaiser-data kaiser-data left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/):

  1. free-llm-scan still writes to the legacy catalog. loadConfig() in cmd/free-llm-scan/main.go sets cfg.Catalog.Path = legacyPath when the default path is missing, and update/refresh-llm then catalog.Save to cfg.Catalog.Path. I checked it with a throwaway test (HOME=temp dir with only a legacy catalog.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 from loadConfig()? loadCatalogForRead → CatalogReadPath already covers the read side, so writes would land in the new dir and migrate the user naturally.

  2. The same block in cmd/free-llm-proxy/main.go is redundant. CatalogReadPath already does the legacy fallback for the default path, so the proxy can go back to the single catPath := config.CatalogReadPath(cfg.Catalog.Path, cfgFile). That keeps the fallback logic in one place (and lets ExpandHome / FileExists stay unexported, plus defaultCatalogPath vs DefaultCatalogPath and the unused DefaultEnrichedPath can collapse to one).

  3. usage.json / reliability.json have no legacy read fallback. The comments say "new location with legacy fallback", but StateFilePath only returns the new dir, so on first start after upgrading the daily quota counters and reliability history start from zero. A small StateReadPath(name) (new path if it exists, else legacy, else new) for the two Load calls would fix it; saving to StateFilePath as you do now is right.

  4. README scp line: ~/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, since XDG_CONFIG_HOME is 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.

  5. Small one: the double blank lines added after the imports in the three cmd/*/main.go files make cmd/free-llm-scan/main.go fail gofmt -l (it was clean on main). A gofmt -w on 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!

Bene added 5 commits December 1, 2026 12:32
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants