MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / setEnvKey

Function setEnvKey

src/setup/env-writer.ts:69–81  ·  view source on GitHub ↗
(key: string, value: string)

Source from the content-addressed store, hash-verified

67 * Returns the path written. The directory is created if needed; the file is chmod 600.
68 */
69export async function setEnvKey(key: string, value: string): Promise<string> {
70 const trimmedKey = key.trim();
71 if (!trimmedKey) throw new Error('env key name is required');
72 await fs.mkdir(QODEX_HOME, { recursive: true });
73 // Lock the whole read→merge→write so concurrent `provider add` runs can't clobber each other's key.
74 return withLock(QODEX_ENV_FILE + '.lock', async () => {
75 const vars = await readEnvFile();
76 vars[trimmedKey] = value;
77 // Atomic temp+fsync+rename; mode 0o600 is applied at create, so no separate chmod is needed.
78 await writeFileAtomic(QODEX_ENV_FILE, serializeEnvFile(vars), { mode: 0o600, encoding: 'utf-8' });
79 return QODEX_ENV_FILE;
80 });
81}
82
83/**
84 * Load ~/.qodex/.env into process.env at startup. Existing process.env values WIN (so an explicit

Callers 2

executeMethod · 0.85
interactiveAddProviderFunction · 0.85

Calls 4

withLockFunction · 0.85
readEnvFileFunction · 0.85
writeFileAtomicFunction · 0.85
serializeEnvFileFunction · 0.85

Tested by

no test coverage detected