Skip to content

feat(config): automatically define platform environments (auto_env)#10316

Merged
jdx merged 6 commits into
mainfrom
claude/elastic-shtern-c24d3d
Jun 11, 2026
Merged

feat(config): automatically define platform environments (auto_env)#10316
jdx merged 6 commits into
mainfrom
claude/elastic-shtern-c24d3d

Conversation

@jdx

@jdx jdx commented Jun 11, 2026

Copy link
Copy Markdown
Owner

What

Adds a new tri-state auto_env early-init setting (MISE_AUTO_ENV env var or auto_env in .miserc.toml). When enabled, mise automatically treats platform-derived names as active config environments:

  • unix (os family, unix platforms only)
  • {os}linux / macos / windows
  • {os}-{arch} — e.g. windows-x64, macos-arm64 (using mise's remapped arch names)

so config files like mise.windows.toml, mise/config.macos-arm64.toml, or mise.unix.toml (and their .local.toml variants, plus global/system config.{env}.toml) load automatically, and matching mise.<env>.lock lockfiles are selected.

Precedence is unix < {os} < {os}-{arch} < explicit MISE_ENV entries, with dedupe when a user explicitly lists a platform name. The platform envs are deliberately not added to MISE_ENV itself: the {{ mise_env }} template variable and MISE_ENV propagation to subprocesses/tasks only reflect explicit environments.

Phased rollout

  • Now: off by default, no warning. Opt in with auto_env = true.
  • 2026.12.0: still off by default, but if a config file exists that would be newly loaded, warn once per process (names the files; silenced by setting auto_env either way). The check is skipped for shims and hook-env so the per-prompt path pays nothing.
  • 2027.6.0: default flips on via compile-time version comparison — no code change needed at release time; the warning disappears naturally because the files now load. auto_env = false still opts out. A debug_assert (same pattern as deprecated_at!) reminds us to delete the transitional warning code then.

Reviewer notes

  • The enable decision must be early-init (rc = true) because settings loading itself depends on config discovery (Settings::try_get()ALL_TOML_CONFIG_FILESDEFAULT_CONFIG_FILENAMESMISE_ENV) — same constraint and docs caveat as the existing env/ceiling_paths rc settings.
  • Single source of truth lives in src/env.rs (AUTO_ENV_NAMES / MISE_ENV_WITH_AUTO); consumers are DEFAULT_CONFIG_FILENAMES, the global/system CONFIG_FILENAMES, and lockfile read order in src/lockfile.rs (explicit env locks still beat auto ones).
  • Tests: unit tests cover the version-gated logic (compile-time version can't be faked in e2e); new e2e tests cover opt-in/out, precedence, dedupe, .miserc.toml, global config dir, and lockfile selection.
  • Docs: new "Platform environments" section in docs/configuration/environments.md (the phase-2 warning links to its anchor), pointer in docs/configuration.md, and the settings reference renders from settings.toml.

🤖 Generated with Claude Code


Note

Medium Risk
Changes which config and lockfiles load for projects that already have platform-named files; rollout is gated and opt-out exists, but mistaken enablement could shift tool versions and env vars.

Overview
Adds auto_env, an early-init setting (MISE_AUTO_ENV or .miserc.toml) that, when enabled, automatically loads platform-specific config environments (unix, {os}, {os}-{arch}) so files like mise.windows.toml and matching mise.<env>.lock files participate in discovery without setting MISE_ENV. Precedence is platform envs first (least → most specific), then explicit MISE_ENV; auto envs are not reflected in MISE_ENV or {{ mise_env }}.

Config filename enumeration is centralized via env_config_patterns and MISE_ENV_WITH_AUTO; lockfile reads include auto platform locks after explicit env locks. Phased rollout: off by default now; version-gated one-time warning (2026.12.0–2027.5.x) when unset platform configs exist; default-on at 2027.6.0.

Docs, JSON schemas, settings.toml, e2e tests for config/lockfile behavior, and unit tests for warning/version logic accompany the Rust changes in env.rs, miserc.rs, config/mod.rs, and lockfile.rs.

Reviewed by Cursor Bugbot for commit 3da8ce1. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features

    • Added auto_env to automatically detect and apply platform-specific environments with explicit env precedence and opt-in/opt-out controls.
  • Documentation

    • Expanded docs detailing platform environment discovery, precedence rules, rollout/warning behavior, and how to control auto-loading.
  • Tests

    • Added end-to-end tests covering discovery, precedence, lockfile selection, opt-in/opt-out, and config-dir behavior.
  • Chores

    • Added settings/schema entries and a rollout warning to surface newly detected platform-specific config files.

Adds a new tri-state auto_env early-init setting (MISE_AUTO_ENV /
.miserc.toml) that activates platform-derived config environments —
unix (os family), {os}, and {os}-{arch} (e.g. windows-x64,
macos-arm64) — for config file discovery and lockfile selection.
Explicit MISE_ENV entries keep higher precedence, and the platform
envs are deliberately not added to MISE_ENV itself, so {{ mise_env }}
templates and MISE_ENV propagation to subprocesses are unaffected.

Phased rollout:
- now: off by default; opt in with auto_env=true
- 2026.12.0: warn when a platform config file exists that would be
  newly loaded (silence with auto_env=false, adopt with auto_env=true)
- 2027.6.0: on by default; auto_env=false opts out

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3bba61c5-3773-4bc7-b289-debb1b5bbb09

📥 Commits

Reviewing files that changed from the base of the PR and between 5a85acb and 3da8ce1.

📒 Files selected for processing (2)
  • e2e/config/test_config_auto_env
  • src/config/mod.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • e2e/config/test_config_auto_env
  • src/config/mod.rs

📝 Walkthrough

Walkthrough

This PR implements platform-based automatic environment detection (unix, {os}, {os}-{arch}) for configuration and lockfile selection in mise. The feature enables version-gated defaults with migration warnings, allowing users to opt in via MISE_AUTO_ENV or .miserc.toml before auto-enabling in version 2027.6.0.

Changes

Auto-env platform environment discovery and selection

Layer / File(s) Summary
Platform environment name computation
src/env.rs
auto_env_setting() resolves tri-state enablement from MISE_AUTO_ENV or miserc; auto_env_default_for_version() applies version gating; platform_env_names() generates deduplicated platform identifiers; AUTO_ENV_NAMES and MISE_ENV_WITH_AUTO statics combine auto-derived and explicit environments for downstream consumption.
Configuration schema and early-init setting
schema/mise.json, schema/miserc.json, settings.toml, src/config/miserc.rs
JSON schemas add auto_env boolean property; settings.toml defines [auto_env] block with MISE_AUTO_ENV environment variable wiring; miserc implements get_auto_env() accessor and merge logic for the early-init setting.
Config filename discovery and rollout warning
src/config/mod.rs, e2e/config/test_config_auto_env
env_config_patterns() centralizes per-environment filename patterns using MISE_ENV_WITH_AUTO; config discovery includes both base and .local variants; should_warn_auto_env() implements conditional rollout warning logic (version threshold, user setting, candidate files); warn_if_auto_env_files_exist() integrates into Config::load startup path; unit and e2e tests validate filename patterns, warning eligibility, default/off behavior, enablement, precedence, explicit override, miserc setting, and config-dir loading.
Lockfile selection with platform environments
src/lockfile.rs, e2e/lockfile/test_lockfile_auto_env
read_all_lockfiles() iterates reversed AUTO_ENV_NAMES with MISE_ENV for most-specific-first precedence; e2e tests verify auto platform lockfile selection and explicit MISE_ENV precedence.
User documentation
docs/configuration.md, docs/configuration/environments.md
Clarifies that config filename list excludes environment-specific files; documents platform environment auto-detection with OS/architecture mapping table, precedence rules, scope (discovery and lockfile only), and version-gated rollout with configuration examples.

🎯 3 (Moderate) | ⏱️ ~25 minutes

sequenceDiagram
  participant Client as CLI
  participant Env as src::env
  participant Config as src::config::Config::load
  participant FS as Filesystem
  participant Lockfile as src::lockfile::read_all_lockfiles
  Client->>Env: compute MISE_ENV_WITH_AUTO (AUTO_ENV_NAMES + MISE_ENV)
  Client->>Config: load using DEFAULT_CONFIG_FILENAMES (with auto envs)
  Config->>FS: discover files via env_config_patterns
  FS->>Config: return candidate files
  Config->>Config: should_warn_auto_env -> warn_if_auto_env_files_exist
  Client->>Lockfile: read_all_lockfiles (uses AUTO_ENV_NAMES + MISE_ENV)
  Lockfile->>FS: probe mise.<env>.lock / .local.lock in precedence
Loading

🐰 Platform environments hop into view,
Auto-detected from OS clues,
Config files and lockfiles align,
Version gates the magic line,
Users migrate with time to choose! 🔧

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main feature: automatically detecting and loading platform-specific configuration environments via the new auto_env setting.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@src/config/mod.rs`:
- Around line 1254-1283: The function detect_auto_env_candidate_files may return
duplicate PathBufs (e.g., same user config found via all_dirs() and
dirs::CONFIG); update detect_auto_env_candidate_files to deduplicate before
returning/using the list by collecting found into a HashSet<PathBuf> (or call
sort_unstable() then dedup()) and then produce a Vec<PathBuf> from that set;
modify the code around variable found (and any subsequent warning output) to use
the deduplicated collection so the one-time warning no longer shows repeated
paths.

In `@src/lockfile.rs`:
- Around line 1647-1649: The loop over
env::MISE_ENV.iter().chain(env::AUTO_ENV_NAMES.iter().rev()) can yield the same
env_name twice and cause duplicate Lockfile::read(&p) disk reads; fix by
deduplicating the combined iterator before constructing paths: create a mutable
HashSet (or similar) named e.g. seen and iterate the chained iterator, skipping
any env_name already in seen (insert when first seen) so
root.join(format!("mise.{env_name}.local.lock")) and the Lockfile::read(&p) call
only run once per unique env name; apply the same dedupe approach to the other
loop that also constructs lockfile paths.
🪄 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 Plus

Run ID: 8f94068a-4395-4ff0-b725-eca06b8e2285

📥 Commits

Reviewing files that changed from the base of the PR and between 7048974 and 4e9eff6.

📒 Files selected for processing (11)
  • docs/configuration.md
  • docs/configuration/environments.md
  • e2e/config/test_config_auto_env
  • e2e/lockfile/test_lockfile_auto_env
  • schema/mise.json
  • schema/miserc.json
  • settings.toml
  • src/config/miserc.rs
  • src/config/mod.rs
  • src/env.rs
  • src/lockfile.rs

Comment thread src/config/mod.rs
Comment thread src/lockfile.rs
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread src/config/mod.rs Outdated
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7eb4f2a. Configure here.

Comment thread src/config/mod.rs Outdated
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a tri-state auto_env early-init setting that automatically activates platform-derived config environments (unix, {os}, {os}-{arch}) for config file discovery and lockfile selection. The default is off today, with a version-gated warning window (2026.12.0–2027.5.x) before the default flips to on at 2027.6.0.

  • AUTO_ENV_NAMES / MISE_ENV_WITH_AUTO in env.rs are the single source of truth; DEFAULT_CONFIG_FILENAMES, CONFIG_FILENAMES, and the lockfile read loop all consume them. Platform envs are deliberately excluded from MISE_ENV itself, so {{ mise_env }} and subprocess propagation remain unaffected.
  • The phase-2 warning path in config/mod.rs scans for would-be-loaded files only in non-shim, non-hook-env contexts and is guarded by warn_once!. A debug_assert! in that function fires in debug builds once the default flips, reminding developers to remove the transitional code.
  • Full e2e coverage for opt-in/out, precedence, deduplication, .miserc.toml, global config dir, and lockfile selection; unit tests cover the version-boundary matrix for should_warn_auto_env and auto_env_default_for_version.

Confidence Score: 5/5

Safe to merge. The feature is off by default, has explicit opt-in/opt-out, and the rollout path is fully gated by version comparisons.

The lazy-static initialization chain is correct (miserc is always read before DEFAULT_CONFIG_FILENAMES is evaluated), the dedupe logic between auto and explicit MISE_ENV entries is consistent across config loading and lockfile reading, and the warning window path is guarded to not affect shims or hook-env. No logic errors were found across the changed files.

No files require special attention.

Important Files Changed

Filename Overview
src/env.rs Adds AUTO_ENV_NAMES and MISE_ENV_WITH_AUTO lazy statics, auto_env_setting(), auto_env_default_for_version(), and platform_env_names(). Initialization chain is correct: MISE_ENV_WITH_AUTO depends on AUTO_ENV_NAMES which depends on MISE_ENV and miserc; lazy evaluation ensures miserc is read first. Unit tests cover all version boundary cases.
src/config/mod.rs Extracts env_config_patterns() helper, switches DEFAULT_CONFIG_FILENAMES and CONFIG_FILENAMES to MISE_ENV_WITH_AUTO, and adds the phase-2 warning path (should_warn_auto_env + warn_if_auto_env_files_exist + detect_auto_env_candidate_files). Logic is sound; warning window is correctly gated; unit tests cover the version-boundary matrix.
src/lockfile.rs Adds auto platform env lockfiles to the read chain (AUTO_ENV_NAMES reversed for most-specific-first ordering). Explicit MISE_ENV locks still precede auto-env locks. Priority is consistent with config loading semantics.
src/config/miserc.rs Adds get_auto_env() accessor and merge_settings handling for auto_env. Follows the existing pattern for other rc settings exactly.
e2e/config/test_config_auto_env New e2e test covers opt-in/opt-out, precedence, deduplication, .miserc.toml, global config dir, and template isolation. The previous concern about version-gated warning assertions is resolved; no-warning assertions now use explicit MISE_AUTO_ENV=true/false.
e2e/lockfile/test_lockfile_auto_env New e2e test for auto-env lockfile selection and explicit-env lockfile precedence. Correct use of MISE_LOCKFILE=1 and relies on real tool version pinning.
settings.toml Adds auto_env setting with rc=true, optional=true, MISE_AUTO_ENV env var. Docs clearly describe precedence, early-init constraint, and rollout timeline.
docs/configuration/environments.md Adds Platform environments section with table, precedence rules, rollout timeline, and .miserc.toml configuration examples. Accurate and well-organized.
schema/mise.json Adds auto_env boolean property. No default specified (correct for a tri-state optional setting).
schema/miserc.json Adds auto_env to the miserc schema. Consistent with mise.json treatment.
docs/configuration.md Adds a pointer to the new Platform environments section in the config filename reference note.

Reviews (4): Last reviewed commit: "fix(config): simplify boolean expression..." | Re-trigger Greptile

Comment thread e2e/config/test_config_auto_env
Comment thread src/config/mod.rs
Jeff Dickey and others added 2 commits June 11, 2026 14:58
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

Hyperfine Performance

mise x -- echo

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.6.2 x -- echo 23.2 ± 1.9 18.5 30.2 1.00
mise x -- echo 25.1 ± 2.9 19.9 66.3 1.08 ± 0.15

mise env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.6.2 env 23.2 ± 1.7 19.9 30.8 1.00
mise env 23.9 ± 1.8 19.3 29.6 1.03 ± 0.11

mise hook-env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.6.2 hook-env 23.2 ± 1.6 19.7 29.3 1.00
mise hook-env 24.7 ± 1.9 20.4 31.6 1.06 ± 0.11

mise ls

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.6.2 ls 18.5 ± 1.4 15.8 24.5 1.00
mise ls 21.6 ± 2.3 16.0 31.9 1.17 ± 0.15
⚠️ Inconclusive: ls measured 17% slower, but the relative uncertainty overlaps the 10% threshold.

xtasks/test/perf

Command mise-2026.6.2 mise Variance
install (cached) 155ms 160ms -3%
ls (cached) 73ms 73ms +0%
bin-paths (cached) 86ms 85ms +1%
task-ls (cached) 165ms 165ms +0%

@jdx jdx merged commit aefd221 into main Jun 11, 2026
35 checks passed
@jdx jdx deleted the claude/elastic-shtern-c24d3d branch June 11, 2026 20:46
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