feat(tasks): Add environment variable directives for mise tasks#5638
feat(tasks): Add environment variable directives for mise tasks#5638
Conversation
Co-authored-by: cursor <cursor@jdx.dev>
adf1be9 to
ccb37cb
Compare
- Add Serialize trait to TaskEnvList, EnvDirective, and EnvDirectiveOptions - Implement is_empty() method for TaskEnvList - Refactor task env parsing to properly convert from BTreeMap to TaskEnvList - Clean up unused imports and variables - Reuse existing env directive parsing logic from config system - Fix type mismatch between parse_env return type and TaskEnvList This resolves compilation errors while maintaining full compatibility with existing task environment variable functionality and serialization. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Hyperfine Performance
|
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2025.8.3 x -- echo |
19.2 ± 0.3 | 18.6 | 22.8 | 1.04 ± 0.03 |
mise x -- echo |
18.4 ± 0.5 | 17.6 | 22.7 | 1.00 |
mise env
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2025.8.3 env |
18.8 ± 0.6 | 18.0 | 23.6 | 1.04 ± 0.05 |
mise env |
18.0 ± 0.7 | 17.0 | 25.1 | 1.00 |
mise hook-env
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2025.8.3 hook-env |
18.0 ± 0.2 | 17.6 | 18.6 | 1.05 ± 0.02 |
mise hook-env |
17.2 ± 0.2 | 16.7 | 18.4 | 1.00 |
mise ls
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2025.8.3 ls |
15.8 ± 0.2 | 15.4 | 19.0 | 1.00 |
mise ls |
15.9 ± 0.2 | 15.5 | 18.6 | 1.01 ± 0.02 |
xtasks/test/perf
| Command | mise-2025.8.3 | mise | Variance |
|---|---|---|---|
| install (cached) | 190ms | ✅ 126ms | +50% |
| ls (cached) | 80ms | 80ms | +0% |
| bin-paths (cached) | 64ms | 64ms | +0% |
| task-ls (cached) | 500ms | 468ms | +6% |
✅ Performance improvement: install cached is 50%
|
bugbot run |
|
bugbot run |
…t-variable-support-for-mise-tasks-a132
…zation The task environment parsing was using serde::Deserialize::deserialize(env_value.clone()) with a oml::Value, which doesn't work correctly. This caused parsing to silently fail with a warning instead of properly handling environment directives. Fixed by converting the toml::Value back to a string and using oml::from_str::<EnvList>() which properly uses the EnvList deserializer designed for the task environment format. This ensures that task environment directives like _.file, _.path, _.source work correctly and boolean false values properly unset variables instead of being ignored.
Replace the custom parse_task_env function with a proper parse_env method on TomlParser, making it consistent with other parsing methods like parse_array and parse_table. This provides a cleaner API and better separation of concerns.
Add parsing support for _.file, _.path, and _.source syntax in task
environment sections, matching the syntax used in global environments.
Previously only the nested syntax (_ = { file = "...", path = "..." })
was supported in tasks, but the e2e tests expect the flat syntax to work.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Changed EnvDirective Display implementation to show the original directive syntax: - _.file = "path" instead of dotenv path - _.path = "path" instead of path_add path - _.source = "path" instead of source path This makes task info output match the expected TOML directive format, making it easier for users to understand and copy the syntax. Fixes task info display format for environment directives. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…gression - Replace boolean `tools` field with `ToolsFilter` enum for flexible filtering - Add Default implementations for ToolsFilter and EnvResolveOptions - Fix global environment loading regression (vars: false) - Ensure consistent ToolsFilter usage across all modules - Fix venv test to use new ToolsFilter::ToolsOnly This ensures that both global environment directives and task environment directives work correctly with proper filtering capabilities. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
EnvResolveOptions should be explicitly constructed rather than using defaults to ensure intentional specification of vars and tools filtering behavior. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
… snapshots - Fixed path.rs test that was still using EnvResolveOptions::default() - Updated all snapshot tests to reflect new flat syntax display format - Unit tests now pass: 233 passed; 0 failed - E2E tests for task environment directives still pass - All features working correctly with proper flat syntax support 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Updated the task JSON output to consistently represent empty environment objects as `[]` instead of `{}`. This change ensures uniformity across the task environment directives and aligns with the expected output format.
…ation - Added handling for flat directive syntax (e.g., _.file, _.path, _.source) in the EnvList deserialization process. - Improved parsing for path directives to support both string and array formats, ensuring robust error handling for invalid values. - Removed redundant PATH processing in Toolset, as it is now managed by PathEnv::from_iter(), preventing duplication of paths. This update ensures that the environment directives are processed correctly and consistently, aligning with the expected TOML format.
| if redact { | ||
| r.redactions.push(k.clone()); | ||
| } | ||
| r.env_remove.insert(k.clone()); |
There was a problem hiding this comment.
no idea why this was set but seems like it was wrong
### 🚀 Features - **(tasks)** **breaking** Add environment variable directives for mise tasks by [@jdx](https://github.com/jdx) in [#5638](#5638)
|
This appears to cause a regression using |
|
I believe this also causes a regression for
As a workaround, adding |
|
@jdx I think that this change introduced a regression that breaks even the documentation example from https://mise.jdx.dev/environments/ for loading multiple env files. [env]
_.file = [
# Load env from the json file relative to this config file
'.env.json',
# Load env from the dotenv file at an absolute path
'/User/bob/.env',
# Load env from the yaml file relative to this config file and redacts the values
{ path = ".secrets.yaml", redact = true }
]> mise config
mise ERROR TOML parse error at line 19, column 5
|
19 | { path = ".env.secrets", redact = true }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
invalid type: map, expected a string
I have no idea how to make it work now. I only want to redact only entries from one of the env files. |
Fixed in #6148 |
### 📦 Registry - remove deprecated virtualos by @jdx in [166379f](166379f) - add trufflehog ([aqua:trufflesecurity/trufflehog](https://github.com/trufflesecurity/trufflehog)) by @risu729 in [#6316](#6316) ### 🚀 Features - **(aqua)** integrate native sigstore-verification for security verification by @jdx in [#6332](#6332) - **(docs)** improve search result readability with lighter teal background by @jdx in [#6328](#6328) - **(ui)** update logo as favicon and fix hover transitions by @jdx in [#6325](#6325) - **(vfox)** add file.read lua function by @malept in [#6333](#6333) - add documentation for "Environment in tasks" #5134 #5638 by @Its-Just-Nans in [#6329](#6329) ### 🐛 Bug Fixes - **(github)** correctly paginate releases/tags for private repos by @malept in [#6318](#6318) - **(hk)** exclude aqua-registry from prettier linting by @jdx in [#6327](#6327) - **(ui)** improve GitHub star badge layout and alignment by @jdx in [#6326](#6326) ### 📚 Documentation - change 'hello.py' to 'main.py' in python.md by @my1e5 in [#6319](#6319) - customize VitePress theme with unique branding by @jdx in [#6324](#6324) ### 📦️ Dependency Updates - update taiki-e/install-action digest to 0aa4f22 by @renovate[bot] in [#6334](#6334) - update rust crate comfy-table to v7.2.1 by @renovate[bot] in [#6335](#6335) - update rust crate console to v0.16.1 by @renovate[bot] in [#6336](#6336) - update rust crate indexmap to v2.11.4 by @renovate[bot] in [#6337](#6337) ### Chore - fixing typos by @Its-Just-Nans in [#6331](#6331) ### New Contributors - @Its-Just-Nans made their first contribution in [#6331](#6331) - @my1e5 made their first contribution in [#6319](#6319) --------- Co-authored-by: mise-en-dev <release@mise.jdx.dev> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Add support for
_.file,_.path,_.sourcedirectives andfalsevalue for removal in[tasks.<name>.env]configurations.This feature allows loading environment variables from files directly within task definitions, making it easier to synchronize mise tasks with IDE configurations as requested in #4762.
BREAKING CHANGE: there is a minor breaking change. The internal structure of the
envkey in tasks has to change from an object to array. Unfortunately I don't see a way around this because directives can be specified multiple times so it has to be an array. This is only exposed viamise task info --jsonso you are only affected if using theenvkey in that command. If this is an issue for you, please let me know, perhaps we can brainstorm on a solution.