feat: add environment configuration loader

This commit is contained in:
2026-06-09 18:21:33 +01:00
parent d8672377fc
commit d7e9d1122a
6 changed files with 3251 additions and 7 deletions
+58
View File
@@ -23,4 +23,62 @@ Status: ✅ Complete
Add `package.json` with MCP SDK, OpenAI SDK, Zod, Vitest.
Status: ✅ Complete
---
## Phase 1 - Core Utilities
### Task 1.1 - Configuration loader
Create `src/config/env.js`.
Requirements:
- Read environment variables and validate OPENAI_API_KEY exists.
- Apply defaults from ARCHITECTURE.md section 13.
- Return a structured config object.
- Throw clear configuration errors for missing or invalid values.
- Use plain JavaScript validation (no Zod yet).
- Single exported `loadConfig()` function.
Create `test/config/env.test.js`.
Requirements:
- Test all default values.
- Test all custom overrides (strings, numbers, booleans).
- Test error cases: missing API key, invalid numbers, invalid booleans.
- No external dependencies in the loader.
Status: ✅ Complete
### Task 1.2 - Secret redaction utility
Create `src/utils/redact.js`.
Requirements:
- Detect likely secrets (API keys, tokens, passwords, Bearer tokens, private keys, SSH keys, PEM blocks, DB URLs with credentials).
- Replace detected secrets with `[REDACTED]`.
- Return the redacted string.
Status: ⏳ Pending
### Task 1.3 - Context budget utility
Create `src/utils/context-budget.js`.
Requirements:
- Character limit checks (max total, per file, max files).
- Priority-based trimming when limits exceeded.
- Reject oversized input with safe message.
Status: ⏳ Pending
### Task 1.4 - Error formatting utility
Create `src/utils/errors.js` and `src/utils/logging.js`.
Requirements:
- Safe error message formatting (no stack traces).
- Minimal logging to stderr only.
Status: ⏳ Pending