VSCode Extension Cuenv Integration Env Tasks Panels And More
Introduction
Hey guys! Today, we're diving deep into the exciting world of VSCode extensions, specifically focusing on the integration of cuenv. This official cuenv VSCode extension aims to provide feature parity with the Direnv VSCode extension, while also adding some killer developer experience enhancements. Think Env panel, Tasks panel, and even CodeLens “Run” links right above each task definition. We're talking about a serious workflow boost! This extension won't handle language features like syntax highlighting – that's the CUE team's domain – but everything else? Buckle up; it's going to be awesome.
Scope of the Extension
Explicit Inclusions
This extension is packed with features designed to streamline your development process. Let's break down what's included:
- Auto-detect env.cue: The extension will automatically detect the
env.cue
file in each workspace folder, making it multi-root aware. This is super handy for projects with multiple components or microservices. - Load and apply environment variables: Using cuenv, the extension will load and apply environment variables, ensuring your environment is always correctly configured.
- Display status: Keep tabs on the status with clear indicators – loaded, pending reload, error, or not found. No more guessing if your environment is set up correctly!
- Env and Tasks side bar views: Dedicated panels for environment variables and tasks. Imagine having all your config and runnable scripts right at your fingertips.
- CodeLens integration: Run tasks directly from your
env.cue
files with CodeLens “Run” links. Talk about convenience! - Integrated terminal: Tasks run in the integrated terminal with the correct environment applied, so you can see your output without switching windows.
- Basic configuration: Configure binary paths, auto-load toggles, and masking patterns to suit your workflow.
- Safe handling of secrets: Optionally mask sensitive information to keep your secrets safe and sound. This is crucial for security-conscious developers.
- Graceful degradation: The extension will handle situations where the cuenv binary is unavailable, ensuring a smooth experience even if something's not quite right.
Out of Scope
To keep things focused, certain features are out of scope for this initial version:
- Language server/syntax highlighting/schema completion: These are handled by the CUE team.
- Debug adapter integration: This might come in the future but isn’t a priority for now.
- Telemetry: No usage data collection in this version, but it’s an option for the future.
- Problem matcher enrichment: Enhanced error parsing is a future consideration.
- Persisted environment caching: No caching of environment variables on disk in this version.
Key Definitions
Let's clarify some terms to ensure we're all on the same page:
env.cue
: The root file where you define your environment variables and tasks. This is the heart of your configuration.- Task: A named, executable unit defined in
env.cue
. Think of these as scripts or commands you can run. - Environment Load: The process of executing cuenv to produce a set of key-value pairs that are then applied in new terminals.
Assumptions
Before diving too deep, let's validate some key assumptions about cuenv:
- JSON output for environment variables: cuenv can output environment variables in a machine-readable JSON format (e.g.,
cuenv export --json
). - JSON output for tasks: cuenv can list tasks and their metadata in JSON format (e.g.,
cuenv tasks --json
). - Task definition structure: Tasks are defined under a top-level field
tasks: { <name>: { command: string, (optional) args: [...], (optional) description: string } }
. This structure may need adjustment based on the actual schema.
If these assumptions don't hold true, we'll need to create follow-up issues in cuenv to add:
export --json
tasks --json
run <taskName>
(already present?) ortasks run <taskName>
It's also crucial that cuenv provides consistent exit codes (0 for success, non-zero for error) and uses stderr
for errors.
High-Level Architecture
To manage complexity, the extension uses a per-workspace folder controller structure:
Per Workspace Folder Controllers
- EnvironmentManager
load()
,reload()
,detectChanges()
: Methods for loading, reloading, and detecting changes in the environment.- Watches
env.cue
with debouncing to avoid excessive reloads. - Emits events:
loaded
,error
,pendingReload
to signal state changes.
- TaskManager
fetchTasks()
: Fetches tasks fromenv.cue
.runTask(name)
: Runs a specific task.- Emits events:
taskStarted
,taskFinished
,taskError
to track task execution.
Shared Services
- CLIAdapter: Executes cuenv commands with timeouts and parses JSON output. This is our interface to the cuenv CLI.
- ConfigurationService: Reads VSCode settings (
cuenv.*
). Centralizes configuration management. - StatusBarService: Updates the status item per active folder. Keeps the user informed.
- View Providers:
EnvTreeDataProvider
,TasksTreeDataProvider
. Provides the data for the Env and Tasks panels. - CodeLensProvider: Adds “Run Task” CodeLenses in
env.cue
files. - Logger: Wraps the VSCode OutputChannel “cuenv” for logging.
User-Facing Features in Detail
Let's walk through the features you'll actually interact with:
1. Auto Environment Load
- Trigger: On extension activation or when a folder is added to the workspace.
- Searches for
env.cue
at the root. (Future: configurable patterns.) - If found and auto-load is enabled, runs
cuenv export --json
. - Stores the hash of the file contents to detect changes later.
- Searches for
- Acceptance Criteria:
- Opening a workspace with
env.cue
triggers a load (visible in the status bar). - Errors (missing binary, parse errors) show in the output channel and status bar.
- Opening a workspace with
2. Status Bar Item
- States: Uses icons and text to indicate status:
- Loaded (âś“)
- Pending Reload (↺)
- Error (âš )
- Binary Not Found (â›”)
- Disabled (⏹ if auto-load is disabled)
- Click Actions: Opens a quick pick menu:
- Reload Environment
- Open cuenv Output
- Toggle Auto Load
- Reveal
env.cue
- Acceptance: Each state should be reachable under simulated conditions.
3. Commands (Command Palette)
The extension adds several commands to the VSCode command palette:
cuenv.reload
: Reload the environment.cuenv.viewOutput
: Open the cuenv output channel.cuenv.toggleAutoLoad
: Toggle auto-loading of the environment.cuenv.runTask
: (Internal) Run a task.cuenv.refreshEnvPanel
: Refresh the Env panel.cuenv.refreshTasksPanel
: Refresh the Tasks panel.
4. Env Panel (Tree View)
- Display: Shows environment variables in a tree view as
VARIABLE = value
(values are masked if they match masking patterns). - Toolbar: Includes:
- Refresh button
- Toggle Masking (if implemented in Milestone 3)
- Filter input to narrow the view.
- Context Menu (Right-Click):
- Copy Name
- Copy Value (unmasked)
- Acceptance:
- Refresh updates values after a reload.
- Masking applies based on regex patterns (e.g.,
.*SECRET.*
,.*TOKEN.*
by default, configurable).
5. Tasks Panel
- List: Displays tasks with:
- Label: Task name
- Description (if provided)
- Run action (â–¶)
- Context menu: Run, Run in New Terminal, Reveal Definition
- On Run:
- Opens (or reuses) a terminal named
cuenv: <folder>
(default) or creates a new terminal if configured. - Executes
cuenv run <taskName>
(adjust if CLI differs).
- Opens (or reuses) a terminal named
- Acceptance:
- Running a task shows the command in the terminal.
- Errors propagate to the Output channel.
- Reveal Definition opens
env.cue
and selects the task definition's line range.
6. CodeLens in env.cue
- Appearance: Appears above each task block definition.
- Text: “Run Task
” - Action: Executes the same run command as the panel.
- Acceptance: Adding/removing a task updates CodeLens after the file is saved.
7. Configuration (Settings)
The extension provides several configurable settings:
cuenv.executablePath
(string, default: “cuenv”): Path to the cuenv executable.cuenv.autoLoad.enabled
(boolean, default: true): Enable or disable auto-loading.cuenv.env.maskPatterns
(string[], default:["(?i)(secret|token|password|key)"]
): Regex patterns for masking environment variable values.cuenv.tasks.terminal.strategy
(enum: “shared” | “new”, default: “shared”): Terminal strategy for running tasks.cuenv.watch.debounceMs
(number, default: 300): Debounce time for file watcher events.- Acceptance: Changing settings should trigger appropriate behavior without requiring a reload (where practical).
8. Reload / Change Detection
- Mechanism: A file watcher on
env.cue
sets the state to Pending Reload if the contents have changed since the last load. - Prompt: A notification appears with actions: Reload Now, Dismiss.
- Acceptance: Editing the file triggers the pending state within the debounce interval.
9. Secrets Masking (Milestone 3)
- Display: Mask values with ••••• (length preserved or constant) unless the user toggles “Reveal” per variable (temporary until view refresh).
- Acceptance: Copy Value copies the real value even if it's masked.
Error Handling Guidelines
The extension provides clear error messages to help users troubleshoot issues:
- Missing Binary: