* refactor(tray): return std::optional from fetch_server_state
* feat(tray): add --spawn-server to natively supervise a local lemond
Lets lemonade-tray spawn and supervise a local lemond when none is
running. POSIX uses posix_spawn (avoiding macOS fork() crashes from
inherited ggml-metal state) plus a pipe-EOF watchdog: the tray passes
--watchdog-fd <FD> to the child and keeps the pipe write end, so when
the tray exits for any reason the OS closes it and lemond shuts itself
down, leaving no orphan. The write end is closed in the child so its
blocking read sees EOF.
Supervised mode only fires when the server is unreachable; otherwise the
tray keeps its existing client-only behavior. On a dead server it runs a
POSIX refresh thread that recovers the menu and notifies when the server
comes back, and handles SIGINT/SIGTERM via an async-signal-safe flag
instead of std::exit. Adds --launch-app/--open and wires the watchdog
contract into test/ and CI.
Introduce thread-safe log rotation via RotatingFileSink and transition direct lemond executions to console-first logging with optional rotating file logging.
- Implement RotatingFileSink with size-triggered rotation, max_files backup retention, excess backup pruning, backup slot fallback, and in-place truncation for max_files=0.
- Add configuration settings log_max_file_size_mb (1..2048) and log_max_files (0..100) with 64-bit validation across CLI, RuntimeConfig, and config.json.
- Support --log-file, --log-max-size-mb, and --log-max-files CLI overrides as in-memory runtime parameters without mutating persistent config.
- Add comprehensive C++ unit test suite (test_log_rotation) and Python integration suite (test/server_log_rotation.py).
* feat: migrate persistent JSON state from .cache to .config
Lemonade was persisting configuration (config.json, user_models.json,
recipe_options.json, mcp_servers.json, jobs.json) under ~/.cache/lemonade,
mixing it with runtime artifacts. This change moves persistent state to
platform config directories and adds automatic migration on startup.
**Directory layout changes:**
- Linux user: ~/.cache/lemonade → ~/.config/lemonade (XDG_CONFIG_HOME)
- Linux systemd: /var/lib/lemonade (StateDirectory, replaces cache dir for config)
- macOS: ~/Library/Application Support/lemonade/.cache → .config
- Windows: unchanged (AppData/Local/lemonade)
- Desktop app: ~/.cache/lemonade/app_settings.json → ~/.config/lemonade/
**Systemd integration (Linux):**
- StateDirectory=lemonade for persistent config (/var/lib/lemonade)
- CacheDirectory=lemonade for downloads/models (/var/cache/lemonade)
- RuntimeDirectory=lemonade for ephemeral state (/run/lemonade)
- EnvironmentFile changed from wildcard /etc/lemonade/conf.d/*.conf to single
/etc/default/lemond with GROUP_WRITE for multi-admin setups
- postinst migrates split conf.d files to merged /etc/default/lemond
**Migration behavior:**
- Automatic on first startup after upgrade
- Legacy JSON files moved from cache_dir to config_dir
- Logged errors/warnings for migration failures (permissions, disk full)
- Idempotent (safe to run multiple times)
- Custom cache/config dirs keep files together (portable installs)
**Runtime changes:**
- CLI accepts second positional arg: lemond [cache_dir] [config_dir]
- ConfigFile, ModelManager, McpClientManager, JobManager read/write via config_dir
- Migration runs once at startup in main.cpp (removed redundant calls)
- CLI overrides (--port, --host) saved before logging setup
- --broadcast flag preserved (process-only override, not persisted)
**Backward compatibility:**
- Migration preserves all user data
- Explicit custom directories bypass migration
- User service: EnvironmentFile=-%E/lemonade/lemond.conf (XDG config)
Fixes#3027
* fix: update test_mcp_client_config and test_config_discovery for new ConfigFile::load signature
- test_mcp_client_config: link against lemonade-server-core instead of compiling mcp_client.cpp directly
- test_config_discovery: update ConfigFile::load() calls to pass both cache_dir and config_dir parameters
Co-Authored-By: Claude <[email protected]>
* fix: remove GROUP_WRITE from /etc/default/lemond for secure-by-default permissions
Reduces permissions from 0664 to 0640 (owner rw, group r, no world access).
Co-Authored-By: Claude <[email protected]>
* Add test coverage
---------
Co-authored-by: Mario Limonciello <[email protected]>
Co-authored-by: Claude <[email protected]>