Skip to content

chore: walk up from cwd to find .env#21

Merged
I-am-nothing merged 1 commit into
mainfrom
chore/env-upward-search
May 5, 2026
Merged

chore: walk up from cwd to find .env#21
I-am-nothing merged 1 commit into
mainfrom
chore/env-upward-search

Conversation

@I-am-nothing

Copy link
Copy Markdown
Contributor

Summary

Replaces the cwd-only `dotenvy::dotenv()` with an upward search from cwd to the filesystem root. The first `.env` found gets loaded.

Why

Devs run `mirrorstack` from many places inside the workspace:

  • meta-repo root: `~/Documents/MirrorStack-AI-V2/`
  • CLI repo: `~/Documents/MirrorStack-AI-V2/mirrorstack-cli/`
  • A scaffolded module: `~/Documents/MirrorStack-AI-V2//`

Previously, only the `.env` directly in cwd loaded — so a workspace `.env` at `MirrorStack-AI-V2/.env` was silently missed when running from a module subdirectory. Users hit this when login URLs pointed at production while their `.env` had localhost overrides.

Behavior

  • Process env vars still win over `.env` (dotenvy's default is non-overriding) — per-invocation `MIRRORSTACK_API_URL=...` works as before.
  • No `.env` anywhere on the path is silently fine (the common case for installed users).
  • Stops at the first `.env` found — no merging across multiple files.

Test plan

  • `cargo test` clean (28 tests)
  • `cargo clippy --all-targets -- -D warnings` clean
  • `cargo fmt --all -- --check` clean
  • Manual: from any subdir of the workspace, `mirrorstack login` should print a localhost URL instead of `account.mirrorstack.ai`

🤖 Generated with Claude Code

Devs run \`mirrorstack\` from many places inside the workspace — the
meta-repo root, a module subdirectory, a scaffold target. The previous
\`dotenvy::dotenv()\` only checked cwd, so workspace-level .env files at
\`MirrorStack-AI-V2/.env\` or \`mirrorstack-cli/.env\` were silently
missed when invoked from sibling dirs.

This walks from cwd upward to the filesystem root and loads the first
.env it finds. Process env vars still take precedence (dotenvy's default
is non-overriding), so per-invocation \`MIRRORSTACK_API_URL=...\` still
works.

Silently ignored when no .env exists anywhere on the path (the common
case for installed users).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@I-am-nothing I-am-nothing merged commit ce1e859 into main May 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant