Skip to content

fix(cli): map .env.local to development environment - #4

Merged
NicolasRitouet merged 5 commits into
mainfrom
fix/env-local-mapping
Mar 5, 2026
Merged

fix(cli): map .env.local to development environment#4
NicolasRitouet merged 5 commits into
mainfrom
fix/env-local-mapping

Conversation

@NicolasRitouet

@NicolasRitouet NicolasRitouet commented Mar 5, 2026

Copy link
Copy Markdown
Member

Summary

  • .env.local was mapped to environment "local" which doesn't exist in vaults (only development, staging, production), causing keyway push to fail after keyway init
  • Added alias mapping for common env file suffixes: .local → development, .dev → development, .prod → production, .stage → staging, plus *.local variants
  • Updated tests accordingly

Test plan

  • go test ./internal/env/... — all pass
  • Manual test: keyway init in a repo with .env.local should map to development

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added comprehensive self-hosting guide with deployment, configuration, and troubleshooting.
    • Expanded MCP docs with new tools for secret generation, environment comparison, code scanning, and secret validation.
  • Improvements

    • Environment file handling now normalizes aliases (e.g., treating common suffixes consistently, .env.local defaults to development).
    • Clarified MCP tool descriptions, parameters, and security notes.

NicolasRitouet and others added 4 commits February 15, 2026 22:19
Remove keyway_get_secret (no longer exists), add keyway_generate,
keyway_diff, keyway_scan, and keyway_validate with parameter tables
and example prompts. Also update docs CLAUDE.md directory listing
with 3 missing pages (installation, ai-agents, organizations).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Complete documentation for deploying Keyway on your own infrastructure
with Docker Compose, including DNS setup, GitHub App creation,
environment configuration, architecture diagram, optional services,
GitHub Enterprise support, and troubleshooting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add language identifiers to fenced code blocks (MD040)
- Fix EMAIL_FROM_NAME/EMAIL_FROM_ADDRESS example values
- Capitalize GitHub.com per official branding

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
.env.local (Next.js/Vite convention) was mapped to "local" which
doesn't exist as a vault environment, causing push to fail. Add
alias mapping for common env file suffixes (.local, .dev, .prod,
.stage, .*.local) to standard vault environments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Mar 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
keyway-dashboard Ready Ready Preview, Comment Mar 5, 2026 8:58pm

Request Review

@coderabbitai

coderabbitai Bot commented Mar 5, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 33c2a7ce-32b8-4951-a1e1-d57596ad2355

📥 Commits

Reviewing files that changed from the base of the PR and between dade58f and 2c5624c.

📒 Files selected for processing (3)
  • packages/cli/internal/cmd/diff.go
  • packages/cli/internal/env/discover.go
  • packages/cli/internal/env/discover_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/cli/internal/env/discover.go

📝 Walkthrough

Walkthrough

Adds environment-name canonicalization for .env suffixes via a new exported function NormalizeEnvName(name string) and updates CLI code/tests to use it; also expands documentation (MCP tooling, self-hosting guide) and adjusts docs navigation.

Changes

Cohort / File(s) Summary
CLI env normalization
packages/cli/internal/env/discover.go, packages/cli/internal/env/discover_test.go, packages/cli/internal/cmd/diff.go
Adds NormalizeEnvName(name string) and an envAliases mapping; DeriveEnvFromFile and tests updated to use canonicalized env names (e.g., .env.localdevelopment). diff.go now delegates normalization to the env package and uses envpkg.Parse calls.
Documentation pages
packages/docs/CLAUDE.md, packages/docs/docs/intro.md, packages/docs/docs/mcp.md, packages/docs/docs/self-hosting.md, packages/docs/sidebars.ts
Adds a comprehensive self-hosting guide, expands MCP tooling docs (new keyway_* tools and examples), updates intro navigation, adds docs pages to CLAUDE.md, and includes self-hosting in the docs sidebar.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble through aliases bright,
.env.dev now hops to the right,
Docs sprout shelter for self-hosting cheer,
New tools appear — I twitch my ear,
🐇 code and docs, a springtime sight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: mapping .env.local to the development environment, which directly addresses the core issue preventing keyway push after keyway init.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/env-local-mapping

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
packages/cli/internal/env/discover.go (1)

68-73: Prefer a shared env normalization function to prevent alias drift.

Derivation here and CLI-arg normalization (packages/cli/internal/cmd/diff.go:244-256) are now separate rule sets. Centralizing normalization in one helper would prevent mismatches (e.g., aliases supported in args but not in file-derived envs).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/internal/env/discover.go` around lines 68 - 73, The env name
derivation in discover.go (the strings.TrimPrefix(base, ".env.") + envAliases
lookup) is diverging from the CLI-arg normalization logic in diff.go; add a
single exported helper like normalizeEnvName (or normalizeEnvAlias) that
encapsulates the TrimPrefix + envAliases mapping and any other alias rules,
replace the inline logic in discover.go (the suffix/envAliases branch) with a
call to that helper, and update the CLI arg normalization in
packages/cli/internal/cmd/diff.go to call the same helper so both file-derived
and arg-derived env names use the exact same rules.
packages/cli/internal/env/discover_test.go (1)

223-231: Add regression cases for shorthand local aliases.

Please add ".env.dev.local", ".env.prod.local", and ".env.stage.local" to lock expected canonical mapping and prevent future regressions.

Suggested test additions
 		{".env.development.local", "development"}, // Next.js local override
 		{".env.production.local", "production"},   // Next.js local override
 		{".env.staging.local", "staging"},         // Next.js local override
+		{".env.dev.local", "development"},         // shorthand + local
+		{".env.prod.local", "production"},         // shorthand + local
+		{".env.stage.local", "staging"},           // shorthand + local
 		{".env.test.local", "development"},        // Next.js local override
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/internal/env/discover_test.go` around lines 223 - 231, Update
the alias mappings in the test data inside discover_test.go to include the
missing shorthand local aliases so the canonical mapping is locked: add entries
for ".env.dev.local" -> "development", ".env.prod.local" -> "production", and
".env.stage.local" -> "staging" to the existing alias mappings slice used by the
tests (the list shown in the diff that contains ".env.local", ".env.dev",
".env.stage", etc.) so the test asserts cover these regression cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/cli/internal/env/discover.go`:
- Around line 45-54: The envAliases map in discover.go is missing shorthand keys
for suffixes like "dev.local" and "prod.local", causing names like "prod.local"
to be returned unmapped; update the envAliases map to include shorthand
"*.local" entries (e.g., "dev.local" -> "development", "prod.local" ->
"production", "stage.local" -> "staging", "test.local" -> "development") so that
lookups using the envAliases symbol normalize ".env.X.local" suffixes to the
canonical environment names.

In `@packages/docs/docs/intro.md`:
- Line 141: Replace the absolute docs link "/self-hosting" with a relative
internal docs link for the "Self-Hosting" entry; update the Markdown link text
"[Self-Hosting](/self-hosting)" to use the repo convention (e.g.,
"[Self-Hosting](./self-hosting)") so the entry in intro.md uses a relative path
consistent with other docs.

---

Nitpick comments:
In `@packages/cli/internal/env/discover_test.go`:
- Around line 223-231: Update the alias mappings in the test data inside
discover_test.go to include the missing shorthand local aliases so the canonical
mapping is locked: add entries for ".env.dev.local" -> "development",
".env.prod.local" -> "production", and ".env.stage.local" -> "staging" to the
existing alias mappings slice used by the tests (the list shown in the diff that
contains ".env.local", ".env.dev", ".env.stage", etc.) so the test asserts cover
these regression cases.

In `@packages/cli/internal/env/discover.go`:
- Around line 68-73: The env name derivation in discover.go (the
strings.TrimPrefix(base, ".env.") + envAliases lookup) is diverging from the
CLI-arg normalization logic in diff.go; add a single exported helper like
normalizeEnvName (or normalizeEnvAlias) that encapsulates the TrimPrefix +
envAliases mapping and any other alias rules, replace the inline logic in
discover.go (the suffix/envAliases branch) with a call to that helper, and
update the CLI arg normalization in packages/cli/internal/cmd/diff.go to call
the same helper so both file-derived and arg-derived env names use the exact
same rules.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 494ff81c-f7b8-4a33-8fa6-d482ef99d052

📥 Commits

Reviewing files that changed from the base of the PR and between 4b08209 and dade58f.

📒 Files selected for processing (7)
  • packages/cli/internal/env/discover.go
  • packages/cli/internal/env/discover_test.go
  • packages/docs/CLAUDE.md
  • packages/docs/docs/intro.md
  • packages/docs/docs/mcp.md
  • packages/docs/docs/self-hosting.md
  • packages/docs/sidebars.ts

Comment thread packages/cli/internal/env/discover.go
- [API](/api) - REST API and API keys
- [Organizations](/organizations) - Team billing and management
- [Security](/security) - Permissions and activity logs
- [Self-Hosting](/self-hosting) - Deploy on your own infrastructure

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use a relative internal link for the new Self-Hosting entry.

Line [141] uses /self-hosting; use a relative docs link to match repo docs conventions.

Suggested fix
-- [Self-Hosting](/self-hosting) - Deploy on your own infrastructure
+- [Self-Hosting](./self-hosting) - Deploy on your own infrastructure

As per coding guidelines, packages/docs/docs/**/*.md: Use relative paths for internal links in Markdown files (e.g., [API Reference](./api) instead of absolute paths).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- [Self-Hosting](/self-hosting) - Deploy on your own infrastructure
- [Self-Hosting](./self-hosting) - Deploy on your own infrastructure
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/docs/docs/intro.md` at line 141, Replace the absolute docs link
"/self-hosting" with a relative internal docs link for the "Self-Hosting" entry;
update the Markdown link text "[Self-Hosting](/self-hosting)" to use the repo
convention (e.g., "[Self-Hosting](./self-hosting)") so the entry in intro.md
uses a relative path consistent with other docs.

- Add missing shorthand *.local aliases (dev.local, prod.local, stage.local)
- Export NormalizeEnvName in env package and reuse it in diff.go
  to centralize env name normalization
- Add stg alias for staging
- Normalize env names to lowercase

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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