feat: add custom environment variable configuration to rover.json #231
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for custom environment variable configuration in rover.json, enabling projects to inject additional environment variables into AI agent containers. This feature introduces two optional properties:
envsfor explicit environment variable definitions and passthroughs, andenvsFilefor loading variables from dotenv files.The custom environment variables are merged with agent-specific defaults and passed to Docker containers during task execution.
It closes #225
Changes
envsandenvsFileoptional properties toProjectConfigSchemawith appropriate getters1.0to1.1to support new configuration fieldsparseCustomEnvironmentVariables()utility function supporting both passthrough (ENV_NAME) and explicit value (ENV_NAME=VALUE) formatsloadEnvsFile()utility function with path traversal validation and dotenv file parsingstartDockerExecution()in task command to load, parse, and merge custom environment variables with agent defaultsdotenvpackage as a dependency for parsing dotenv filesNotes
Custom environment variables are appended after agent defaults when passed to Docker. When the same variable appears multiple times, Docker uses the last occurrence, allowing custom variables to override agent defaults.
Path traversal protection ensures
envsFilepaths are validated to stay within the project root directory. Invalid paths and missing files are silently skipped to maintain backwards compatibility.Demo
I updated the project
rover.jsonfile to:{ "version": "1.1", "languages": [ "javascript" ], "packageManagers": [ "npm" ], "taskManagers": [], "attribution": true, "envs": [ "STARSHIP_SHELL", "CUSTOM_VAR=test" ], "envsFile": ".env.rover" }Inside the container:
$ docker exec -it rover-task-74-1 bash d04ab61b998a:/workspace$ env CUSTOM_VAR=test STARSHIP_SHELL=bash ANOTHER_TEST=bye THIS_IS_A_TEST=hello ...