From 5da0dff0de620e07c385fbc0323f142b509c43fa Mon Sep 17 00:00:00 2001 From: Claudio <257189482+claudio-pi@users.noreply.github.com> Date: Mon, 9 Feb 2026 00:10:35 -0600 Subject: [PATCH 1/3] Preserve unmanaged env vars across claudio_save_env calls claudio_save_env previously overwrote the entire service.env with only its hardcoded list of managed variables, silently deleting any extra vars (like HASS_TOKEN, ALEXA_SKILL_ID) that were added manually or by other integrations. Now it reads and preserves unmanaged variables. --- lib/config.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/config.sh b/lib/config.sh index 5ad6c2e..3d505e7 100644 --- a/lib/config.sh +++ b/lib/config.sh @@ -81,6 +81,29 @@ _env_quote() { } claudio_save_env() { + # Managed variables (written by this function) + local -a managed_keys=( + PORT MODEL TELEGRAM_BOT_TOKEN TELEGRAM_CHAT_ID + WEBHOOK_URL TUNNEL_NAME TUNNEL_HOSTNAME WEBHOOK_SECRET + WEBHOOK_RETRY_DELAY ELEVENLABS_API_KEY ELEVENLABS_VOICE_ID + ELEVENLABS_MODEL ELEVENLABS_STT_MODEL MEMORY_ENABLED + MEMORY_EMBEDDING_MODEL MEMORY_CONSOLIDATION_MODEL MAX_HISTORY_LINES + ) + + # Collect extra (unmanaged) lines from existing file before overwriting + local extra_lines="" + if [ -f "$CLAUDIO_ENV_FILE" ]; then + local managed_pattern + managed_pattern=$(printf '%s|' "${managed_keys[@]}") + managed_pattern="^(${managed_pattern%|})=" + while IFS= read -r line || [ -n "$line" ]; do + [[ -z "$line" || "$line" == \#* ]] && continue + if [[ ! "$line" =~ $managed_pattern ]]; then + extra_lines+="$line"$'\n' + fi + done < "$CLAUDIO_ENV_FILE" + fi + # Use restrictive permissions for file with secrets ( umask 077 @@ -103,6 +126,10 @@ claudio_save_env() { printf 'MEMORY_EMBEDDING_MODEL="%s"\n' "$(_env_quote "$MEMORY_EMBEDDING_MODEL")" printf 'MEMORY_CONSOLIDATION_MODEL="%s"\n' "$(_env_quote "$MEMORY_CONSOLIDATION_MODEL")" printf 'MAX_HISTORY_LINES="%s"\n' "$(_env_quote "$MAX_HISTORY_LINES")" + # Preserve unmanaged variables (e.g. HASS_TOKEN, ALEXA_SKILL_ID) + if [ -n "$extra_lines" ]; then + printf '%s' "$extra_lines" + fi } > "$CLAUDIO_ENV_FILE" ) } From 7080ddc5fd8d68bfd47a25dd4bc9d98e984e095d Mon Sep 17 00:00:00 2001 From: Claudio <257189482+claudio-pi@users.noreply.github.com> Date: Mon, 9 Feb 2026 01:56:24 -0600 Subject: [PATCH 2/3] Preserve comments and blank lines from unmanaged env section Also filter only managed key assignments; keep all other content (comments, blank lines, custom variables) intact. --- lib/config.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/config.sh b/lib/config.sh index 3d505e7..cb20863 100644 --- a/lib/config.sh +++ b/lib/config.sh @@ -97,8 +97,9 @@ claudio_save_env() { managed_pattern=$(printf '%s|' "${managed_keys[@]}") managed_pattern="^(${managed_pattern%|})=" while IFS= read -r line || [ -n "$line" ]; do - [[ -z "$line" || "$line" == \#* ]] && continue - if [[ ! "$line" =~ $managed_pattern ]]; then + # Skip lines that set managed variables; keep everything else + # (comments, blank lines, unmanaged vars) + if [[ -z "$line" || "$line" == \#* || ! "$line" =~ $managed_pattern ]]; then extra_lines+="$line"$'\n' fi done < "$CLAUDIO_ENV_FILE" From e6e43f01adc1d006f3b5fb233c8e04dbe5d627d9 Mon Sep 17 00:00:00 2001 From: Claudio <257189482+claudio-pi@users.noreply.github.com> Date: Mon, 9 Feb 2026 03:00:18 -0600 Subject: [PATCH 3/3] =?UTF-8?q?Simplify=20unmanaged=20line=20filter=20?= =?UTF-8?q?=E2=80=94=20regex=20alone=20is=20sufficient?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pattern ^(PORT|MODEL|...)= already excludes empty lines and comments, so the explicit checks for those are redundant. --- lib/config.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/config.sh b/lib/config.sh index cb20863..fde216a 100644 --- a/lib/config.sh +++ b/lib/config.sh @@ -97,9 +97,8 @@ claudio_save_env() { managed_pattern=$(printf '%s|' "${managed_keys[@]}") managed_pattern="^(${managed_pattern%|})=" while IFS= read -r line || [ -n "$line" ]; do - # Skip lines that set managed variables; keep everything else - # (comments, blank lines, unmanaged vars) - if [[ -z "$line" || "$line" == \#* || ! "$line" =~ $managed_pattern ]]; then + # Keep everything except managed variable assignments + if [[ ! "$line" =~ $managed_pattern ]]; then extra_lines+="$line"$'\n' fi done < "$CLAUDIO_ENV_FILE"