fix(env): stop claiming ~/.env; read from ~/.config/PAI/.env instead#1066
Open
MHoroszowski wants to merge 1 commit intodanielmiessler:mainfrom
Open
fix(env): stop claiming ~/.env; read from ~/.config/PAI/.env instead#1066MHoroszowski wants to merge 1 commit intodanielmiessler:mainfrom
MHoroszowski wants to merge 1 commit intodanielmiessler:mainfrom
Conversation
PAI currently owns the user's ~/.env file via a symlink created during install. This is a home-directory namespace grab: ~/.env is a conventional, user-owned file that many shells and tools look for. If the user installs any other tool that expects to read ~/.env, it either collides with PAI's secrets or is silently overwritten on the next PAI install. This is the wrong shape. The cause is that VoiceServer hardcodes `join(homedir(), '.env')` as the only place it looks for ELEVENLABS_API_KEY. The installer created the ~/.env symlink to make that hardcoded read resolve to the real secrets file at ~/.config/PAI/.env (which is already the XDG-compliant, correct canonical location). This change: - VoiceServer/server.ts: load ~/.config/PAI/.env first (XDG canonical location), then optionally overlay from ~/.env if the user has chosen to put PAI-relevant keys there. Values in ~/.env win on key collisions, preserving the "explicit user override" mental model. The error message when ELEVENLABS_API_KEY is missing now points at the canonical path. - PAI-Install/engine/actions.ts: stop creating the ~/.env symlink. ~/.claude/.env stays symlinked (that path is PAI's own namespace, so the symlink is safe and the hooks' existing reads continue working unchanged). The new comment explains why we no longer touch ~/.env. Backward compatibility: - Existing installs that already have the ~/.env symlink continue to work — both paths point at the same real file, so loading both is a no-op. - Existing installs that already have a real ~/.env with PAI values in it continue to work — loadEnvFile() reads both paths and either one (or both) can contain the keys. - New installs after this change will have a real file at ~/.config/PAI/.env and will NOT touch ~/.env. Users own ~/.env. Related to the VoiceServer cross-platform audio work in danielmiessler#1061 and the Pushcut notification channel in danielmiessler#1062.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PAI currently writes its managed secrets to `
/.config/PAI/.env` (the XDG-compliant canonical location — correct choice) but then creates a symlink at `/.env` pointing at it. That symlink is a home-directory namespace grab: `/.env` is a conventional, user-owned file that many shells and tools look for. If a user installs any other tool that expects `/.env`, it either collides with PAI's secrets or silently overwrites PAI on the next install. The user loses control of a file they should own.The cause is that `VoiceServer/server.ts` hardcodes `join(homedir(), '.env')` as the only place it looks for `ELEVENLABS_API_KEY`. The installer created the `~/.env` symlink purely to satisfy that hardcoded read — not as a considered design decision.
This PR removes the `
/.env` symlink and teaches VoiceServer to read from the canonical XDG path directly, with `/.env` preserved as an optional user overlay for anyone who wants to put PAI-relevant keys there.Changes
`VoiceServer/server.ts`
Refactored the env-loading block:
Before:
```ts
// Load .env from user home directory
const envPath = join(homedir(), '.env');
if (existsSync(envPath)) {
const envContent = await Bun.file(envPath).text();
envContent.split('\n').forEach(line => { /* parse */ });
}
```
After:
```ts
async function loadEnvFile(path: string): Promise { /* parse if exists */ }
const xdgEnvPath = join(homedir(), '.config', 'PAI', '.env');
const homeEnvPath = join(homedir(), '.env');
await loadEnvFile(xdgEnvPath); // PAI's managed secrets (canonical)
await loadEnvFile(homeEnvPath); // optional user overlay — wins on collisions
```
The error message when `ELEVENLABS_API_KEY` is missing now points at the canonical path rather than hardcoding `~/.env`.
`PAI-Install/engine/actions.ts`
Removed the creation of the `
/.env` symlink. The `/.claude/.env` symlink is preserved — that path is PAI's own namespace, so the symlink is safe and hooks that already read it continue working unchanged.Backward compatibility
This is fully backward-compatible with existing installs:
/.config/PAI/.env` (if it exists) and `/.env`, so any of the three configurations (XDG only, home only, or both) keeps working./.config/PAI/.env` and creates only the `/.claude/.env` symlink. `~/.env` is left untouched — the user owns it./.env`, so users who reclaimed their `/.env` between installs are already safe. This PR simply extends that safety by not creating the symlink at all.Test plan
/.claude/.env` symlink is created, `/.env` is untouched.Why this matters
`
/.env` is a conventional, user-owned file. A well-behaved application writes to its own scoped location (`/.config/PAI/` ✓) and teaches its dependencies to read from the right place. It should not reach into the home directory and colonize a generic file — especially not as an implicit side effect of one hardcoded line in one component.PAI's installer already knows the right pattern (the XDG file is already the canonical location). This PR just finishes the job: makes the runtime read from the right place so the symlink shim isn't needed.
Related