feat(env): add tools variable to tera template context#8108
Conversation
Add a `tools` map to the tera context so users can reference tool
versions and install paths in templates, e.g. `{{ tools.node.version }}`
and `{{ tools.node.path }}`. Available in task templates and env
directives with `tools = true`.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @jdx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to the templating system by exposing detailed information about installed tools directly within Tera templates. This change simplifies the process of referencing tool versions and paths in environment variables and task scripts, making configurations more declarative and less reliant on external command execution. It streamlines how users can interact with their managed tool versions within the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Pull request overview
Adds a tools map into the Tera template context so templates/env directives can access installed tool metadata (e.g., tools.node.version, tools.node.path) without shelling out.
Changes:
- Inject
toolsinto Tera context used for env rendering and general template context. - Implement
build_tools_tera_mapto construct a{ tool_name -> {version, path} }map (including short-name aliases). - Add e2e coverage and update docs to describe the new
toolsvariable.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/toolset/toolset_env.rs | Inserts tools into the env rendering Tera context. |
| src/toolset/mod.rs | Adds helper to build the tools map; injects it into the cached Tera context. |
| e2e/env/test_env_tools | Adds an e2e test case using tools.<name>.version/path in env templates. |
| docs/templates.md | Documents the new tools template variable. |
| docs/environments/index.md | Adds an example using tools.node.version in env configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - `xdg_config_home: PathBuf` - Points to the directory of XDG config home | ||
| - `xdg_data_home: PathBuf` - Points to the directory of XDG data home | ||
| - `xdg_state_home: PathBuf` - Points to the directory of XDG state home | ||
| - `tools: HashMap<String, ToolInfo>` – Maps installed tool names to their info. |
There was a problem hiding this comment.
The docs describe tools as HashMap<String, ToolInfo>, but the implementation inserts a nested map (HashMap<String, HashMap<String, String>> with version/path keys). Please update the documentation type/signature to match the actual Tera shape (e.g., tools: Map<String, { version: String, path: String }>), or introduce a real ToolInfo struct that matches what the docs claim.
| - `tools: HashMap<String, ToolInfo>` – Maps installed tool names to their info. | |
| - `tools: Map<String, { version: String, path: String }>` – Maps installed tool names to an object containing their version and install path. |
e2e/env/test_env_tools
Outdated
| assert_contains "mise hook-env -s bash" "export TINY_V=" | ||
| assert_contains "mise hook-env -s bash" "export TINY_P=" |
There was a problem hiding this comment.
These assertions only verify that the variables are exported, not that templating actually resolved tools.tiny.version / tools.tiny.path to non-empty values. This can still pass if the template renders an empty string. Strengthen the test to assert TINY_V is non-empty (or matches an expected version format) and TINY_P contains a plausible install path (e.g., includes the tool name or a known install root).
src/toolset/mod.rs
Outdated
| pub fn build_tools_tera_map( | ||
| &self, | ||
| config: &Arc<Config>, | ||
| ) -> HashMap<String, HashMap<String, String>> { | ||
| let mut tools_map: HashMap<String, HashMap<String, String>> = HashMap::new(); | ||
| for (_, tv) in self.list_current_installed_versions(config) { | ||
| let tool_name = tv.ba().tool_name.clone(); | ||
| let short = tv.ba().short.clone(); | ||
| let version = tv.version.clone(); | ||
| let path = tv.install_path().to_string_lossy().to_string(); | ||
| let inner = | ||
| HashMap::from([("version".to_string(), version), ("path".to_string(), path)]); | ||
| tools_map.entry(tool_name.clone()).or_insert(inner.clone()); | ||
| if short != tool_name { | ||
| tools_map.entry(short).or_insert(inner); | ||
| } | ||
| } | ||
| tools_map | ||
| } |
There was a problem hiding this comment.
Returning HashMap<String, HashMap<String, String>> as a public API is brittle and hard to reason about/document (stringly-typed inner keys like \"version\"/\"path\"). Consider introducing a small serializable ToolInfo { version: String, path: String } and returning HashMap<String, ToolInfo> (which also aligns with the docs), then let Tera/Serde serialize it.
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable tools map to the Tera template context, enabling templates to access information about installed tools like their version and path. This is a great enhancement that simplifies configurations by avoiding exec workarounds. The implementation is well-rounded, including updates to the toolset, environment building, documentation, and tests. I have a couple of suggestions to enhance the new test case's robustness and to refactor a new function for improved efficiency and clarity. Overall, this is a well-executed feature addition.
e2e/env/test_env_tools
Outdated
| assert_contains "mise hook-env -s bash" "export TINY_V=" | ||
| assert_contains "mise hook-env -s bash" "export TINY_P=" |
There was a problem hiding this comment.
The current assertions for TINY_V and TINY_P are a bit weak, as they would pass even if the variables were exported with empty values (e.g., export TINY_V=). To make the test more robust, it's better to verify that the variables are set to their expected, non-empty values. A good approach is to capture the actual version and path using mise commands and then assert against those dynamic values.
TINY_VERSION=$(mise latest tiny)
TINY_PATH=$(mise where tiny)
assert_contains "mise hook-env -s bash" "export TINY_V=$TINY_VERSION"
assert_contains "mise hook-env -s bash" "export TINY_P=$TINY_PATH"
src/toolset/mod.rs
Outdated
| pub fn build_tools_tera_map( | ||
| &self, | ||
| config: &Arc<Config>, | ||
| ) -> HashMap<String, HashMap<String, String>> { | ||
| let mut tools_map: HashMap<String, HashMap<String, String>> = HashMap::new(); | ||
| for (_, tv) in self.list_current_installed_versions(config) { | ||
| let tool_name = tv.ba().tool_name.clone(); | ||
| let short = tv.ba().short.clone(); | ||
| let version = tv.version.clone(); | ||
| let path = tv.install_path().to_string_lossy().to_string(); | ||
| let inner = | ||
| HashMap::from([("version".to_string(), version), ("path".to_string(), path)]); | ||
| tools_map.entry(tool_name.clone()).or_insert(inner.clone()); | ||
| if short != tool_name { | ||
| tools_map.entry(short).or_insert(inner); | ||
| } | ||
| } | ||
| tools_map | ||
| } |
There was a problem hiding this comment.
The build_tools_tera_map function can be made more efficient and clearer. The current implementation creates the inner HashMap and clones it on every iteration, even if the tool_name entry already exists in the map. By using the entry API with or_insert_with, we can lazily create the inner map only when it's actually needed, which improves performance and readability.
pub fn build_tools_tera_map(
&self,
config: &Arc<Config>,
) -> HashMap<String, HashMap<String, String>> {
let mut tools_map: HashMap<String, HashMap<String, String>> = HashMap::new();
for (_, tv) in self.list_current_installed_versions(config) {
let tool_name = tv.ba().tool_name.clone();
let short = tv.ba().short.clone();
let inner_val = tools_map.entry(tool_name).or_insert_with(|| {
HashMap::from([
("version".to_string(), tv.version.clone()),
("path".to_string(), tv.install_path().to_string_lossy().to_string()),
])
});
if short != tool_name {
tools_map.entry(short).or_insert_with(|| inner_val.clone());
}
}
tools_map
}Address PR feedback: - Replace nested HashMap with a proper ToolInfo struct for type safety - Verify actual tool version and path values in e2e test assertions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Hyperfine Performance
|
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.2.9 x -- echo |
22.3 ± 0.3 | 21.6 | 23.5 | 1.00 |
mise x -- echo |
23.2 ± 0.3 | 22.4 | 24.2 | 1.04 ± 0.02 |
mise env
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.2.9 env |
21.9 ± 1.0 | 21.2 | 36.5 | 1.00 |
mise env |
22.7 ± 0.3 | 21.8 | 24.3 | 1.04 ± 0.05 |
mise hook-env
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.2.9 hook-env |
22.4 ± 0.4 | 21.8 | 27.8 | 1.00 |
mise hook-env |
23.4 ± 0.3 | 22.5 | 24.8 | 1.05 ± 0.02 |
mise ls
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.2.9 ls |
20.4 ± 0.3 | 19.8 | 21.8 | 1.00 |
mise ls |
21.0 ± 0.4 | 20.1 | 22.9 | 1.03 ± 0.02 |
xtasks/test/perf
| Command | mise-2026.2.9 | mise | Variance |
|---|---|---|---|
| install (cached) | 121ms | 121ms | +0% |
| ls (cached) | 74ms | 74ms | +0% |
| bin-paths (cached) | 78ms | 81ms | -3% |
| task-ls (cached) | 539ms | -31% |
### 🚀 Features - **(activate)** add shims directory as fallback when auto-install is enabled by @ctaintor in [#8106](#8106) - **(env)** add `tools` variable to tera template context by @jdx in [#8108](#8108) - **(set)** add --stdin flag for multiline environment variables by @jdx in [#8110](#8110) ### 🐛 Bug Fixes - **(backend)** improve conda patchelf and dependency resolution for complex packages by @jdx in [#8087](#8087) - **(ci)** fix validate-new-tools grep pattern for test field by @jdx in [#8100](#8100) - **(config)** make MISE_OFFLINE work correctly by gracefully skipping network calls by @jdx in [#8109](#8109) - **(github)** skip v prefix for "latest" version by @jdx in [#8105](#8105) - **(gitlab)** resolve tool options from config for aliased tools by @jdx in [#8084](#8084) - **(install)** use version_expr for Flutter to fix version resolution by @jdx in [#8081](#8081) - **(registry)** add Linux support for tuist by @fortmarek in [#8102](#8102) - **(release)** write release notes to file instead of capturing stdout by @jdx in [#8086](#8086) - **(upgrade)** tools are not uninstalled properly due to outdated symlink by @roele in [#8099](#8099) - **(upgrade)** ensure uninstallation failure does not leave invalid symlinks by @roele in [#8101](#8101) - SLSA for in-toto statement with no signatures by @gerhard in [#8094](#8094) - Vfox Plugin Auto-Installation for Environment Directives by @pose in [#8035](#8035) ### 📚 Documentation - use mise activate for PowerShell in getting-started by @rileychh in [#8112](#8112) ### 📦 Registry - add conda backend for mysql by @jdx in [#8080](#8080) - add conda backends for 10 asdf-only tools by @jdx in [#8083](#8083) - added podman-tui by @tony-sol in [#8098](#8098) ### Chore - sort settings.toml alphabetically and add test by @jdx in [#8111](#8111) ### New Contributors - @ctaintor made their first contribution in [#8106](#8106) - @rileychh made their first contribution in [#8112](#8112) - @fortmarek made their first contribution in [#8102](#8102) - @pose made their first contribution in [#8035](#8035) - @gerhard made their first contribution in [#8094](#8094) ## 📦 Aqua Registry Updates #### New Packages (2) - [`entireio/cli`](https://github.com/entireio/cli) - [`rmitchellscott/reManager`](https://github.com/rmitchellscott/reManager) #### Updated Packages (1) - [`atuinsh/atuin`](https://github.com/atuinsh/atuin)
### 🚀 Features - **(activate)** add shims directory as fallback when auto-install is enabled by @ctaintor in [#8106](#8106) - **(env)** add `tools` variable to tera template context by @jdx in [#8108](#8108) - **(set)** add --stdin flag for multiline environment variables by @jdx in [#8110](#8110) ### 🐛 Bug Fixes - **(backend)** improve conda patchelf and dependency resolution for complex packages by @jdx in [#8087](#8087) - **(ci)** fix validate-new-tools grep pattern for test field by @jdx in [#8100](#8100) - **(config)** make MISE_OFFLINE work correctly by gracefully skipping network calls by @jdx in [#8109](#8109) - **(github)** skip v prefix for "latest" version by @jdx in [#8105](#8105) - **(gitlab)** resolve tool options from config for aliased tools by @jdx in [#8084](#8084) - **(install)** use version_expr for Flutter to fix version resolution by @jdx in [#8081](#8081) - **(registry)** add Linux support for tuist by @fortmarek in [#8102](#8102) - **(release)** write release notes to file instead of capturing stdout by @jdx in [#8086](#8086) - **(upgrade)** tools are not uninstalled properly due to outdated symlink by @roele in [#8099](#8099) - **(upgrade)** ensure uninstallation failure does not leave invalid symlinks by @roele in [#8101](#8101) - SLSA for in-toto statement with no signatures by @gerhard in [#8094](#8094) - Vfox Plugin Auto-Installation for Environment Directives by @pose in [#8035](#8035) ### 📚 Documentation - use mise activate for PowerShell in getting-started by @rileychh in [#8112](#8112) ### 📦 Registry - add conda backend for mysql by @jdx in [#8080](#8080) - add conda backends for 10 asdf-only tools by @jdx in [#8083](#8083) - added podman-tui by @tony-sol in [#8098](#8098) ### Chore - sort settings.toml alphabetically and add test by @jdx in [#8111](#8111) ### New Contributors - @ctaintor made their first contribution in [#8106](#8106) - @rileychh made their first contribution in [#8112](#8112) - @fortmarek made their first contribution in [#8102](#8102) - @pose made their first contribution in [#8035](#8035) - @gerhard made their first contribution in [#8094](#8094) ## 📦 Aqua Registry Updates #### New Packages (2) - [`entireio/cli`](https://github.com/entireio/cli) - [`rmitchellscott/reManager`](https://github.com/rmitchellscott/reManager) #### Updated Packages (1) - [`atuinsh/atuin`](https://github.com/atuinsh/atuin)
## Summary
- Adds a `tools` map to the tera template context, enabling `{{
tools.node.version }}` and `{{ tools.node.path }}` in templates
- Available in task templates and env directives with `tools = true`,
removing the need for `exec(command='node --version')` workarounds
- Keys include both `tool_name` and `short` name for flexibility; only
installed versions are included
## Test plan
- [x] `mise run build` compiles successfully
- [x] `mise run test:e2e test_env_tools` passes with new test cases
verifying `tools.tiny.version` and `tools.tiny.path`
- [x] `mise run lint` passes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Medium risk because it changes template context construction for env
resolution and tasks, and introduces new serialized data derived from
installed tool state; errors could impact env rendering in multiple
commands.
>
> **Overview**
> Adds a new `tools` map to the Tera template context so templates can
reference installed tool metadata (e.g. `{{ tools.node.version }}` and
`{{ tools.node.path }}`), including both tool and short names.
>
> Updates env resolution and cached Tera context creation to populate
this map from currently installed tool versions, adds e2e coverage for
`tools.<name>.version/path`, and documents the new template variable and
a lazy-eval env example.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
411378c. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
### 🚀 Features - **(activate)** add shims directory as fallback when auto-install is enabled by @ctaintor in [jdx#8106](jdx#8106) - **(env)** add `tools` variable to tera template context by @jdx in [jdx#8108](jdx#8108) - **(set)** add --stdin flag for multiline environment variables by @jdx in [jdx#8110](jdx#8110) ### 🐛 Bug Fixes - **(backend)** improve conda patchelf and dependency resolution for complex packages by @jdx in [jdx#8087](jdx#8087) - **(ci)** fix validate-new-tools grep pattern for test field by @jdx in [jdx#8100](jdx#8100) - **(config)** make MISE_OFFLINE work correctly by gracefully skipping network calls by @jdx in [jdx#8109](jdx#8109) - **(github)** skip v prefix for "latest" version by @jdx in [jdx#8105](jdx#8105) - **(gitlab)** resolve tool options from config for aliased tools by @jdx in [jdx#8084](jdx#8084) - **(install)** use version_expr for Flutter to fix version resolution by @jdx in [jdx#8081](jdx#8081) - **(registry)** add Linux support for tuist by @fortmarek in [jdx#8102](jdx#8102) - **(release)** write release notes to file instead of capturing stdout by @jdx in [jdx#8086](jdx#8086) - **(upgrade)** tools are not uninstalled properly due to outdated symlink by @roele in [jdx#8099](jdx#8099) - **(upgrade)** ensure uninstallation failure does not leave invalid symlinks by @roele in [jdx#8101](jdx#8101) - SLSA for in-toto statement with no signatures by @gerhard in [jdx#8094](jdx#8094) - Vfox Plugin Auto-Installation for Environment Directives by @pose in [jdx#8035](jdx#8035) ### 📚 Documentation - use mise activate for PowerShell in getting-started by @rileychh in [jdx#8112](jdx#8112) ### 📦 Registry - add conda backend for mysql by @jdx in [jdx#8080](jdx#8080) - add conda backends for 10 asdf-only tools by @jdx in [jdx#8083](jdx#8083) - added podman-tui by @tony-sol in [jdx#8098](jdx#8098) ### Chore - sort settings.toml alphabetically and add test by @jdx in [jdx#8111](jdx#8111) ### New Contributors - @ctaintor made their first contribution in [jdx#8106](jdx#8106) - @rileychh made their first contribution in [jdx#8112](jdx#8112) - @fortmarek made their first contribution in [jdx#8102](jdx#8102) - @pose made their first contribution in [jdx#8035](jdx#8035) - @gerhard made their first contribution in [jdx#8094](jdx#8094) ## 📦 Aqua Registry Updates #### New Packages (2) - [`entireio/cli`](https://github.com/entireio/cli) - [`rmitchellscott/reManager`](https://github.com/rmitchellscott/reManager) #### Updated Packages (1) - [`atuinsh/atuin`](https://github.com/atuinsh/atuin)
### 🚀 Features - **(activate)** add shims directory as fallback when auto-install is enabled by @ctaintor in [jdx#8106](jdx#8106) - **(env)** add `tools` variable to tera template context by @jdx in [jdx#8108](jdx#8108) - **(set)** add --stdin flag for multiline environment variables by @jdx in [jdx#8110](jdx#8110) ### 🐛 Bug Fixes - **(backend)** improve conda patchelf and dependency resolution for complex packages by @jdx in [jdx#8087](jdx#8087) - **(ci)** fix validate-new-tools grep pattern for test field by @jdx in [jdx#8100](jdx#8100) - **(config)** make MISE_OFFLINE work correctly by gracefully skipping network calls by @jdx in [jdx#8109](jdx#8109) - **(github)** skip v prefix for "latest" version by @jdx in [jdx#8105](jdx#8105) - **(gitlab)** resolve tool options from config for aliased tools by @jdx in [jdx#8084](jdx#8084) - **(install)** use version_expr for Flutter to fix version resolution by @jdx in [jdx#8081](jdx#8081) - **(registry)** add Linux support for tuist by @fortmarek in [jdx#8102](jdx#8102) - **(release)** write release notes to file instead of capturing stdout by @jdx in [jdx#8086](jdx#8086) - **(upgrade)** tools are not uninstalled properly due to outdated symlink by @roele in [jdx#8099](jdx#8099) - **(upgrade)** ensure uninstallation failure does not leave invalid symlinks by @roele in [jdx#8101](jdx#8101) - SLSA for in-toto statement with no signatures by @gerhard in [jdx#8094](jdx#8094) - Vfox Plugin Auto-Installation for Environment Directives by @pose in [jdx#8035](jdx#8035) ### 📚 Documentation - use mise activate for PowerShell in getting-started by @rileychh in [jdx#8112](jdx#8112) ### 📦 Registry - add conda backend for mysql by @jdx in [jdx#8080](jdx#8080) - add conda backends for 10 asdf-only tools by @jdx in [jdx#8083](jdx#8083) - added podman-tui by @tony-sol in [jdx#8098](jdx#8098) ### Chore - sort settings.toml alphabetically and add test by @jdx in [jdx#8111](jdx#8111) ### New Contributors - @ctaintor made their first contribution in [jdx#8106](jdx#8106) - @rileychh made their first contribution in [jdx#8112](jdx#8112) - @fortmarek made their first contribution in [jdx#8102](jdx#8102) - @pose made their first contribution in [jdx#8035](jdx#8035) - @gerhard made their first contribution in [jdx#8094](jdx#8094) ## 📦 Aqua Registry Updates #### New Packages (2) - [`entireio/cli`](https://github.com/entireio/cli) - [`rmitchellscott/reManager`](https://github.com/rmitchellscott/reManager) #### Updated Packages (1) - [`atuinsh/atuin`](https://github.com/atuinsh/atuin)
Summary
toolsmap to the tera template context, enabling{{ tools.node.version }}and{{ tools.node.path }}in templatestools = true, removing the need forexec(command='node --version')workaroundstool_nameandshortname for flexibility; only installed versions are includedTest plan
mise run buildcompiles successfullymise run test:e2e test_env_toolspasses with new test cases verifyingtools.tiny.versionandtools.tiny.pathmise run lintpasses🤖 Generated with Claude Code
Note
Medium Risk
Medium risk because it changes template context construction for env resolution and tasks, and introduces new serialized data derived from installed tool state; errors could impact env rendering in multiple commands.
Overview
Adds a new
toolsmap to the Tera template context so templates can reference installed tool metadata (e.g.{{ tools.node.version }}and{{ tools.node.path }}), including both tool and short names.Updates env resolution and cached Tera context creation to populate this map from currently installed tool versions, adds e2e coverage for
tools.<name>.version/path, and documents the new template variable and a lazy-eval env example.Written by Cursor Bugbot for commit 411378c. This will update automatically on new commits. Configure here.