Commit 5a5c21d
authored
impr (cli): adding support for loading env variables & selecting embedding model, also made docker auto start (#703)
## Description
This PR adds three major improvements to the CLI: automatic cleanup on
init/add failures, Docker auto-start functionality, and support for
loading environment variables (API keys) and selecting embedding models.
**Key Changes:**
- Added `CleanupTracker` to rollback filesystem and config changes when
init/add operations fail
- Docker daemon now auto-starts on macOS/Windows/Linux with user
confirmation
- Environment variables (`.env` file) now loaded and passed to
containers for `OPENAI_API_KEY` and `GEMINI_API_KEY`
- `embedding_model` field added to config with `text-embedding-ada-002`
as default
- Install script checks for Docker Desktop on macOS and offers homebrew
installation
- Improved null-safety in HQL analyzer to prevent panics
**Critical Issues:**
- In `init.rs`, config backup is called after save instead of before,
breaking rollback functionality
- In `docker.rs`, `dotenvy::dotenv()` is called repeatedly in
`environment_variables()`, polluting process environment state
<details><summary><h3>Important Files Changed</h3></summary>
File Analysis
| Filename | Score | Overview |
|----------|-------|----------|
| helix-cli/src/cleanup.rs | 5/5 | added new cleanup tracker for
rollback on init/add failures - well-structured with tests |
| helix-cli/src/commands/init.rs | 2/5 | integrated cleanup tracker but
backup timing is incorrect - backup called after save instead of before
|
| helix-cli/src/docker.rs | 2/5 | added auto-start docker functionality
and env loading - dotenvy called repeatedly causing environment
pollution |
| helix-cli/src/config.rs | 5/5 | added embedding model selection with
proper defaults and serialization handling |
</details>
</details>
<details><summary><h3>Sequence Diagram</h3></summary>
```mermaid
sequenceDiagram
participant User
participant CLI as Helix CLI
participant Cleanup as CleanupTracker
participant Docker as DockerManager
participant Env as .env File
participant Config as helix.toml
Note over User,Config: Init Command Flow
User->>CLI: helix init [options]
CLI->>Cleanup: Create CleanupTracker
CLI->>Env: dotenvy::dotenv() (load env vars)
CLI->>Config: Create helix.toml
Cleanup->>Cleanup: Track created file
CLI->>Cleanup: Track directories/files
alt Cloud deployment selected
CLI->>Cleanup: backup_config()
CLI->>Config: Save cloud config
end
alt Error occurs
CLI->>Cleanup: cleanup()
Cleanup->>Config: Restore backup
Cleanup->>Cleanup: Remove tracked files/dirs
Cleanup-->>User: Cleanup summary
end
Note over User,Config: Docker Auto-Start Flow
User->>CLI: helix build/run
CLI->>Docker: check_docker_available()
alt Docker not running
Docker->>User: Prompt to start Docker
alt User accepts
Docker->>Docker: start_docker_daemon()
Docker->>Docker: wait_for_docker(15s)
Docker->>Docker: Verify running
end
end
Docker->>Env: dotenvy::dotenv()
Docker->>Docker: environment_variables()
Note right of Docker: Loads OPENAI_API_KEY,<br/>GEMINI_API_KEY from env
Docker->>Config: Generate docker-compose.yml
Note right of Config: Includes dynamic env vars
```
</details>
<!-- greptile_other_comments_section -->
**Context used:**
- Rule from `dashboard` - When using OnceLock::new() in Rust code, wrap
it in a `const { ... }` block to satisfy clippy lints....
([source](https://app.greptile.com/review/custom-context?memory=7f3c5d9b-5a5e-41cd-9e7e-1992245f637c))
<!-- /greptile_comment -->File tree
35 files changed
+1771
-514
lines changed- .github/workflows
- helix-cli
- src
- commands
- integrations
- tests
- helix-db
- src
- helix_gateway/mcp
- helixc
- analyzer/methods
- generator
- hql-tests
- tests/cloud_queries_2
35 files changed
+1771
-514
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
0 commit comments