| 42 | |
| 43 | /** Serialize a key→value map back to env-file text (sorted for stable diffs). */ |
| 44 | export function serializeEnvFile(vars: Record<string, string>): string { |
| 45 | const header = |
| 46 | '# QodeX API keys — loaded automatically at startup.\n' + |
| 47 | '# Managed by `qodex provider add`. You can edit by hand, one KEY=value per line.\n' + |
| 48 | '# This file is chmod 600 and is NOT your config.yaml — keep it private, never commit it.\n\n'; |
| 49 | const lines = Object.keys(vars) |
| 50 | .sort() |
| 51 | .map(k => `${k}=${vars[k]}`); |
| 52 | return header + lines.join('\n') + '\n'; |
| 53 | } |
| 54 | |
| 55 | /** Read the current ~/.qodex/.env into a map (empty if absent/unreadable). */ |
| 56 | export async function readEnvFile(): Promise<Record<string, string>> { |