config: replace dotenv with varlock for env validation#8
Conversation
Greptile SummaryReplaced dotenv with Varlock for environment variable validation at startup, adding fail-fast validation for misconfigurations and type checking with prefix validation (e.g., Key changes:
All changes maintain backward compatibility with graceful fallback to plain Confidence Score: 5/5
Important Files Changed
Flowchartflowchart TD
A[Admin runs deploy.sh] --> B[Deploy .env.schema to ~/.config/]
B --> C[User runs start.sh]
C --> D{varlock installed?}
D -->|Yes| E[varlock load --path ~/.config/]
D -->|No| F[source ~/.config/.env]
E --> G{Validation passed?}
G -->|Yes| H[Export vars to process.env]
G -->|No| I[Exit with error message]
F --> H
H --> J[Run harden-permissions.sh]
J --> K[Start control-agent]
K --> L[startup-cleanup.sh runs]
L --> M{varlock installed?}
M -->|Yes| N[varlock run -- node bridge.mjs]
M -->|No| O[source .env && node bridge.mjs]
N --> P[bridge.mjs starts with validated env]
O --> P
P --> Q[Bridge validates required vars]
Q --> R[Bridge operational]
Last reviewed commit: d714e4a |
4698f85 to
651e743
Compare
651e743 to
8e2afcd
Compare
8e2afcd to
5a192b4
Compare
- Add .env.schema with types, @required, @sensitive decorators for all env vars - Remove dotenv from slack-bridge, env vars now injected via varlock run - start.sh validates with `varlock load` before launching - startup-cleanup.sh uses `varlock run` for bridge tmux session - deploy.sh deploys .env.schema to ~/.config/.env.schema - setup.sh installs varlock binary - Update CONFIGURATION.md with schema validation docs Replaces blind dotenv loading with schema-validated startup. Catches wrong token prefixes, missing required vars, and invalid emails before any connections are attempted.
5a192b4 to
c53ee4c
Compare
| varlock load --path ~/.config/ || { | ||
| echo "❌ Environment validation failed — check ~/.config/.env against .env.schema" | ||
| exit 1 | ||
| } |
There was a problem hiding this comment.
Bug: The script introduces a hard dependency on varlock. If varlock is not installed, the agent and Slack bridge will fail to start, contrary to the promised graceful fallback.
Severity: HIGH
Suggested Fix
Before calling varlock, check if the command exists using command -v varlock >/dev/null. If it exists, use varlock. Otherwise, fall back to the plain source ~/.config/.env command. This will implement the graceful fallback described in the pull request description.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: start.sh#L20-L23
Potential issue: The scripts `start.sh` and `startup-cleanup.sh` directly call `varlock`
without first checking if it is installed or available in the `PATH`. If the `varlock`
command is not found, `start.sh` will exit with an error instead of falling back to
`source ~/.config/.env`. Similarly, the `tmux` session for the Slack bridge in
`startup-cleanup.sh` will fail to start. This contradicts the PR's goal of providing a
graceful fallback and will cause startup failures if the `varlock` installation fails
for any reason.
Replaces dotenv with Varlock for environment variable management. Adds a committed
.env.schemathat defines types, required/optional status, and sensitivity for every env var.What changed
.env.schema— new schema file with@required,@sensitive,@typedecorators for all 20 env vars. Deployed to~/.config/.env.schemaalongside secrets.start.sh— runsvarlock load --path ~/.config/to validate env before launching. Falls back to plainsourceif varlock isn't installed.startup-cleanup.sh— bridge tmux session usesvarlock run --path ~/.config/to inject validated env vars. Falls back tosourceif varlock isn't installed.slack-bridge/bridge.mjs— removedimport "dotenv/config". Env vars are now inprocess.envbefore Node starts (viavarlock runor shellsource).slack-bridge/package.json— removeddotenvdependency.bin/deploy.sh— deploys.env.schemato~/.config/.env.schema(644 perms).CONFIGURATION.md— documents schema validation.Why
xoxb-,ghp_, etc.) fail fast with clear errors instead of crashing deep in a code pathredact-logs.shregex approach.env.schemais a single source of truth that stays in sync (unlike.env.examplefiles)sourcepath is preserved)Tests
All 172 JS tests pass. No behavior changes for existing code paths.