Skip to content

898 cli auto detect existing env files and suggest a schema#904

Merged
yamcodes merged 11 commits into
mainfrom
898-cli-auto-detect-existing-env-files-and-suggest-a-schema
May 9, 2026
Merged

898 cli auto detect existing env files and suggest a schema#904
yamcodes merged 11 commits into
mainfrom
898-cli-auto-detect-existing-env-files-and-suggest-a-schema

Conversation

@yamcodes
Copy link
Copy Markdown
Owner

@yamcodes yamcodes commented May 9, 2026

Closes #898

Summary by CodeRabbit

Release Notes

  • New Features

    • Auto-detects .env.example files and suggests schema keys during CLI initialization
    • Displays CLI version in help output and at startup
    • Generates dynamic environment variable schemas from detected keys
  • Bug Fixes

    • Fixed duplicated terminal output during dependency installation
    • Resolved Node.js deprecation warning in scaffolding
  • Documentation

    • Updated CLI documentation with .env.example detection details and post-scaffold guidance
  • Improvements

    • Enhanced dependency installation feedback with cleaner output display

Review Change Stack

yamcodes added 2 commits May 9, 2026 22:44
- Introduced automatic detection of `.env.example` files during the `arkenv init` process to improve user onboarding.
- Added functionality to extract environment variable keys from `.env.example`.
- Implemented dynamic key integration for schema templates (`arktype`, `zod`, `valibot`).
- Updated prompts to allow users to accept or decline `.env.example`-based scaffolding.
@yamcodes yamcodes linked an issue May 9, 2026 that may be closed by this pull request
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 9, 2026

🦋 Changeset detected

Latest commit: d3726b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@arkenv/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

Warning

Rate limit exceeded

@yamcodes has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 46 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e34dca05-733c-4f6d-8cf7-5095abff3652

📥 Commits

Reviewing files that changed from the base of the PR and between 2a86729 and d3726b9.

📒 Files selected for processing (5)
  • openspec/changes/cli-auto-detect-env-example/design.md
  • openspec/changes/cli-auto-detect-env-example/proposal.md
  • openspec/changes/cli-auto-detect-env-example/specs/cli-schema-suggestion/spec.md
  • packages/cli/src/env-parser.test.ts
  • packages/cli/src/scaffold.ts

Walkthrough

This PR implements automatic detection of .env.example files in the ArkEnv CLI scaffolding flow. The implementation adds a parser for extracting environment variable keys, integrates detection into the interactive prompt wizard with user confirmation, refactors all template generators to accept dynamic keys, separates installation command generation from execution, and improves CLI messaging and versioning.

Changes

Environment Example Detection & Schema Scaffolding

Layer / File(s) Summary
Environment Parser & Key Extraction
packages/cli/src/env-parser.ts, packages/cli/src/env-parser.test.ts
Adds parseEnvExample() and getEnvExampleKeys() to extract deduplicated environment variable keys from .env.example via regex-based line parsing; includes comprehensive test coverage for key extraction, comment handling, deduplication, and whitespace tolerance.
Prompt Wizard Integration
packages/cli/src/prompts.ts, packages/cli/src/prompts.test.ts
Extends ProjectOptions with optional envKeys field; integrates .env.example detection into interactive wizard with useEnvExample confirmation prompt; includes test mocks, temporary directory setup, and verification of key detection flows in isYes mode and interactive mode.
Dynamic Template Schema Generation
packages/cli/src/env-template.ts, packages/cli/src/templates/arktype.ts, packages/cli/src/templates/zod.ts, packages/cli/src/templates/valibot.ts, packages/cli/src/env-template.test.ts
Refactors all template functions to accept optional envKeys instead of frameworkNote; dynamically generates schema fields from provided keys with fallback to default NODE_ENV and PORT; removes framework-note comment generation; updates tests to verify dynamic schema generation without framework notes.
Scaffold Install Command Separation
packages/cli/src/scaffold.ts, packages/cli/src/scaffold.test.ts
Refactors scaffold() to return { tsConfigResult, installCmd, packageManager } instead of executing installation; constructs dependency list and install command; enables CLI to manage install process independently; updates tests to validate returned values for vite, bun, and arktype configurations.
CLI Main Loop & Installation Execution
packages/cli/src/index.ts, packages/cli/src/visuals.ts
Displays versioned banner (ArkEnv CLI v<version>); executes returned installCmd via child_process.spawn with inherited stdio; adds symbol export for styled output; improves terminal messaging with symbol and dim "Happy coding!" text; handles user cancellation via cancel() with graceful exit.
Dependencies & Workspace Configuration
packages/cli/package.json, pnpm-workspace.yaml
Updates @clack/prompts from ^0.9.1 to ^1.3.0; adds @arkenv/cli catalog entry set to ^0.0.2.
Documentation, Specifications & Examples
.changeset/, openspec/changes/cli-auto-detect-env-example/, apps/www/content/docs/cli/index.mdx, apps/playgrounds/arkenv-cli/src/env.ts, .idea/vcs.xml
Adds OpenSpec design document, proposal, task checklist, and two requirement specifications for .env.example detection and schema suggestion; updates CLI documentation to describe .env.example detection step; documents changes in changesets; updates playground schema to use Vite environment variables; adds IDE VCS configuration mapping.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yamcodes/arkenv#897: Implements the initial @arkenv/cli scaffolding foundation; this PR extends that with environment example detection and template customization.

Suggested labels

example, arkenv

Poem

🐰 A rabbit hops through dotfiles with glee,
Finding examples to scaffold with ease,
Keys spring to life from .env.example near,
The CLI wizard makes choices clear,
Dynamic schemas bloom without fear! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly references the main objective of auto-detecting .env.example files and suggesting a schema, matching the primary changes in the changeset.
Linked Issues check ✅ Passed The PR implements all core requirements: parsing .env.example files for variable keys, prompting users to accept/decline detection, injecting extracted keys into templates with fallbacks, and ensuring .env.example-only access for security.
Out of Scope Changes check ✅ Passed Additional changes beyond core scope include CLI UI improvements (version display, symbol), dependency installation automation, deprecated warning fixes, and template simplification; these align with improving the overall init workflow.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 898-cli-auto-detect-existing-env-files-and-suggest-a-schema

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.

@github-actions github-actions Bot added the docs Improvements or additions to documentation label May 9, 2026
…Env CLI

- Added `.env.example` parser utility to extract environment variable keys.
- Updated `arktype`, `zod`, and `valibot` templates to render dynamic schema keys.
- Enhanced CLI prompts for `.env.example` detection and user confirmation.
- Integrated extracted keys into schema scaffolding with fallback defaults.
- Added comprehensive tests for parsing, prompts, and template scaffolding.
@github-actions github-actions Bot added tests This issue or PR is about adding, removing or changing tests @arkenv/cli Issues or Pull Requests involving the ArkEnv CLI playground Issues or Pull Requests concerning a playground. (Found in the `apps/playgrounds/` directory) labels May 9, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 9, 2026

Open in StackBlitz

arkenv

npm i https://pkg.pr.new/arkenv@904

@arkenv/bun-plugin

npm i https://pkg.pr.new/@arkenv/bun-plugin@904

@arkenv/cli

npm i https://pkg.pr.new/@arkenv/cli@904

@arkenv/fumadocs-ui

npm i https://pkg.pr.new/@arkenv/fumadocs-ui@904

@arkenv/vite-plugin

npm i https://pkg.pr.new/@arkenv/vite-plugin@904

commit: d3726b9

@arkenv-bot
Copy link
Copy Markdown
Contributor

arkenv-bot Bot commented May 9, 2026

📦 Bundle Size Report

No results found

All size limits passed!

yamcodes added 3 commits May 9, 2026 23:57
…ne CLI visuals

- Removed the `frameworkNote` parameter from `arktype`, `zod`, and `valibot` templates for simplicity.
- Updated CLI output to display ArkEnv version and improved visual formatting with a new symbol.
- Bumped `@clack/prompts` dependency to v1.3.0 for updated features and stability.
…in ArkEnv CLI

- Added robust parsing of `.env.example` to extract variable keys.
- Updated `init` wizard to suggest extracted keys for schema scaffolding.
- Refined scaffolding templates by removing introductory comments.
- Updated documentation to include `.env.example` detection and key extraction.
- Refined `init` command steps to highlight enhanced schema scaffolding workflow.
@github-actions github-actions Bot added the www Improvements or additions to arkenv.js.org label May 9, 2026
yamcodes added 4 commits May 10, 2026 00:09
…stallation

- Enhanced CLI visuals: display version in help page and intro.
- Updated `env.ts` to support refined variable definitions and schema types.
- Resolved Node.js DEP0190 deprecation warning in scaffolding logic.
- Fixed duplicate output during dependency installation by piping process logs.
…ing output

- Added support for automatic dependency installation using detected package manager.
- Updated scaffolding output to reflect streamlined process and improved messaging.
- Enhanced CLI prompts with recommended options for `.env.example` key usage.
- Refactored scaffolding logic to return installation command details.
…olding

- Consolidated `@clack/prompts` imports into a single line.
- Simplified logging message for dependency installation output.
- Removed color formatting redundancy for package manager output.
- Removed framework-specific notes from scaffolding templates for clarity.
- Updated CLI output with live dependency installation progress and simplified messaging.
- Streamlined tests by eliminating checks for framework-specific notes.
@yamcodes yamcodes marked this pull request as ready for review May 9, 2026 19:32
@arkenv-bot
Copy link
Copy Markdown
Contributor

arkenv-bot Bot commented May 9, 2026

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

Project Deployment Review Updated (Asia/Almaty)
arkenv Ready Ready Preview, Comment May 10 2026, 12:35 AM (Asia/Almaty)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (3)
packages/cli/src/env-parser.test.ts (1)

37-44: ⚡ Quick win

Rename this test to match the asserted behavior.

Line 37 says “case-insensitive,” but the assertion on Line 43 verifies lowercase keys are preserved. A title like “should preserve lowercase keys” would be clearer.

As per coding guidelines, “Unit tests should focus on individual function logic and edge cases.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/src/env-parser.test.ts` around lines 37 - 44, Rename the test
title to match the asserted behavior: change the it(...) description currently
"should handle lowercase keys (case-insensitive)" to something like "should
preserve lowercase keys" so the test name reflects that parseEnvExample returns
lowercase keys unchanged; only update the string description in the test around
the it(...) that calls parseEnvExample, no code logic changes required.
openspec/changes/cli-auto-detect-env-example/specs/cli-schema-suggestion/spec.md (1)

20-21: ⚡ Quick win

Tighten this acceptance criterion to be deterministic.

Line 21’s “or appropriate default validators” is ambiguous for compliance testing. Consider listing exact expected mappings (or linking to a canonical rule table) so implementations and tests converge.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@openspec/changes/cli-auto-detect-env-example/specs/cli-schema-suggestion/spec.md`
around lines 20 - 21, The acceptance criterion is ambiguous because "or
appropriate default validators" is not deterministic; update the THEN clause for
the keys PORT and DATABASE_URL to state exact expected schema mappings (e.g.,
PORT: "string" or "integer" and DATABASE_URL: "string" — pick the canonical
validators your spec uses) or replace that phrase with a link/reference to the
canonical validator table; specifically edit the sentence referencing keys PORT
and DATABASE_URL to list the precise validator strings (or a clear authoritative
rule link) so tests can assert exact values.
packages/cli/src/scaffold.ts (1)

1-1: ⚡ Quick win

Remove unused spawn import.

The spawn import is no longer used in this file after refactoring the install execution to index.ts.

♻️ Proposed fix
-import { spawn } from "node:child_process";
 import { existsSync } from "node:fs";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/src/scaffold.ts` at line 1, Remove the unused import "spawn"
from the top of the file: delete the import specifier `spawn` from the import
statement `import { spawn } from "node:child_process";` in
packages/cli/src/scaffold.ts since the install execution was moved to index.ts
and no code in this file references `spawn`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.idea/vcs.xml:
- Line 51: Remove the JetBrains-local VCS mapping entry from .idea/vcs.xml by
deleting the <mapping directory="$PROJECT_DIR$/app" vcs="Git" /> element so
IDE-specific config isn't committed; leave other project-wide VCS mappings
intact and ensure the file no longer contains that local "$PROJECT_DIR$/app"
mapping before committing.

In `@openspec/changes/cli-auto-detect-env-example/design.md`:
- Around line 30-31: The design doc uses `keys: string[]` in the
Decision/Rationale but the rest of the change set uses `envKeys`; update the doc
to use `envKeys` consistently by replacing `keys: string[]` with `envKeys:
string[]` and adjust the explanatory text to refer to `envKeys` (including
mentions of template functions that accept an optional envKeys array and the
fallback to `NODE_ENV` and `PORT`) so all sections (Decision, Rationale,
tasks/tests/implementation) use the same identifier.

In `@openspec/changes/cli-auto-detect-env-example/proposal.md`:
- Line 10: Replace the inconsistent generated filename in the proposal so it
matches the implementation/docs: change the mention of `arkenv.ts` to the
canonical `env.ts` (or vice versa if you prefer that as the canonical name)
throughout the proposal text and any examples, ensuring all references (e.g.,
the sentence about generating a starter arkenv.ts/env.ts and any subsequent
example filenames) use the same single filename (`env.ts`) to remove ambiguity.

---

Nitpick comments:
In
`@openspec/changes/cli-auto-detect-env-example/specs/cli-schema-suggestion/spec.md`:
- Around line 20-21: The acceptance criterion is ambiguous because "or
appropriate default validators" is not deterministic; update the THEN clause for
the keys PORT and DATABASE_URL to state exact expected schema mappings (e.g.,
PORT: "string" or "integer" and DATABASE_URL: "string" — pick the canonical
validators your spec uses) or replace that phrase with a link/reference to the
canonical validator table; specifically edit the sentence referencing keys PORT
and DATABASE_URL to list the precise validator strings (or a clear authoritative
rule link) so tests can assert exact values.

In `@packages/cli/src/env-parser.test.ts`:
- Around line 37-44: Rename the test title to match the asserted behavior:
change the it(...) description currently "should handle lowercase keys
(case-insensitive)" to something like "should preserve lowercase keys" so the
test name reflects that parseEnvExample returns lowercase keys unchanged; only
update the string description in the test around the it(...) that calls
parseEnvExample, no code logic changes required.

In `@packages/cli/src/scaffold.ts`:
- Line 1: Remove the unused import "spawn" from the top of the file: delete the
import specifier `spawn` from the import statement `import { spawn } from
"node:child_process";` in packages/cli/src/scaffold.ts since the install
execution was moved to index.ts and no code in this file references `spawn`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 70e9ad96-926c-4b51-9a77-21db2ca320f6

📥 Commits

Reviewing files that changed from the base of the PR and between 2f1c283 and 2a86729.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (27)
  • .changeset/clean-cli-install-output.md
  • .changeset/cool-rivers-remain.md
  • .idea/vcs.xml
  • apps/playgrounds/arkenv-cli/src/env.ts
  • apps/www/content/docs/cli/index.mdx
  • gh-issue-workflow.skill
  • openspec/changes/cli-auto-detect-env-example/.openspec.yaml
  • openspec/changes/cli-auto-detect-env-example/design.md
  • openspec/changes/cli-auto-detect-env-example/proposal.md
  • openspec/changes/cli-auto-detect-env-example/specs/cli-env-example-detection/spec.md
  • openspec/changes/cli-auto-detect-env-example/specs/cli-schema-suggestion/spec.md
  • openspec/changes/cli-auto-detect-env-example/tasks.md
  • packages/cli/package.json
  • packages/cli/src/env-parser.test.ts
  • packages/cli/src/env-parser.ts
  • packages/cli/src/env-template.test.ts
  • packages/cli/src/env-template.ts
  • packages/cli/src/index.ts
  • packages/cli/src/prompts.test.ts
  • packages/cli/src/prompts.ts
  • packages/cli/src/scaffold.test.ts
  • packages/cli/src/scaffold.ts
  • packages/cli/src/templates/arktype.ts
  • packages/cli/src/templates/valibot.ts
  • packages/cli/src/templates/zod.ts
  • packages/cli/src/visuals.ts
  • pnpm-workspace.yaml
💤 Files with no reviewable changes (1)
  • packages/cli/src/env-template.test.ts

Comment thread .idea/vcs.xml Outdated
Comment thread openspec/changes/cli-auto-detect-env-example/design.md Outdated
Comment thread openspec/changes/cli-auto-detect-env-example/proposal.md Outdated
- Updated test to clarify and preserve lowercase key behavior.
- Adjusted template parameter naming for consistency (`keys` → `envKeys`).
- Improved schema generation example in docs to reflect updated validator usage (`a.string()`).
- Removed unused import in scaffolding logic for cleanup.
@yamcodes yamcodes merged commit ef17a38 into main May 9, 2026
20 checks passed
@yamcodes yamcodes deleted the 898-cli-auto-detect-existing-env-files-and-suggest-a-schema branch May 9, 2026 19:49
@arkenv-bot arkenv-bot Bot mentioned this pull request May 9, 2026
yamcodes pushed a commit that referenced this pull request May 9, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @arkenv/cli@0.0.3

### Patch Changes

- #### Improve CLI UI and fix installation output
_[`#904`](#904)
[`ef17a38`](ef17a38)
[@yamcodes](https://github.com/yamcodes)_

    -   Display CLI version on the help page and at startup
- Fix "doubling up" of terminal output during dependency installation by
piping process output
    -   Resolve Node.js DEP0190 deprecation warning in scaffolding logic

- #### Auto-detect `.env.example` keys during init and suggest schema
_[`#904`](#904)
[`ef17a38`](ef17a38)
[@yamcodes](https://github.com/yamcodes)_

    -   Robust parsing of `.env.example` to extract variable keys
- Integration with the `init` wizard to suggest keys for scaffolding
- Minimal scaffolding templates without introductory comments or
platform notes
    -   Simplified CLI output with live dependency installation progress
- Updated CLI documentation and added post-scaffold guidance to refine
types

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@arkenv-bot arkenv-bot Bot mentioned this pull request May 9, 2026
@coderabbitai coderabbitai Bot mentioned this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@arkenv/cli Issues or Pull Requests involving the ArkEnv CLI docs Improvements or additions to documentation playground Issues or Pull Requests concerning a playground. (Found in the `apps/playgrounds/` directory) tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: Auto-detect existing .env.example files and suggest a schema

1 participant