feat (cli): helix sync command#831
Merged
Merged
Conversation
…cluster to pull queries from.
Comment on lines
+171
to
+180
| for (filename, content) in &sync_response.hx_files { | ||
| let file_path = queries_dir.join(filename); | ||
| if file_path.exists() { | ||
| if let Ok(local_content) = std::fs::read_to_string(&file_path) { | ||
| if local_content != *content { | ||
| differing_files.push(filename.clone()); | ||
| } | ||
| } | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
New files from remote aren't added to differing_files list, so users won't see them in the confirmation prompt. Only existing files that differ are tracked.
Suggested change
| for (filename, content) in &sync_response.hx_files { | |
| let file_path = queries_dir.join(filename); | |
| if file_path.exists() { | |
| if let Ok(local_content) = std::fs::read_to_string(&file_path) { | |
| if local_content != *content { | |
| differing_files.push(filename.clone()); | |
| } | |
| } | |
| } | |
| } | |
| // Collect files that differ from local | |
| let mut differing_files: Vec<String> = Vec::new(); | |
| for (filename, content) in &sync_response.hx_files { | |
| let file_path = queries_dir.join(filename); | |
| if file_path.exists() { | |
| if let Ok(local_content) = std::fs::read_to_string(&file_path) { | |
| if local_content != *content { | |
| differing_files.push(filename.clone()); | |
| } | |
| } | |
| } else { | |
| // New file from remote | |
| differing_files.push(filename.clone()); | |
| } | |
| } |
…e `SyncResponse` struct in `sync.rs`.
Contributor
|
@greptileai update the sequence diagram |
Contributor
|
Looking at the sync command implementation, here's an updated sequence diagram that better reflects the actual flow: sequenceDiagram
participant User
participant CLI as helix sync
participant Cloud as Helix Cloud
participant FS as File System
User->>CLI: helix sync [instance_name]
alt Has instance_name
CLI->>FS: Load ProjectContext
FS-->>CLI: Project config
CLI->>CLI: Get instance config
CLI->>CLI: Validate instance type (Helix Cloud only)
CLI->>Cloud: GET /api/clusters/{cluster_id}/sync
else No instance_name (interactive)
alt Project exists
CLI->>FS: Load ProjectContext
FS-->>CLI: Project config with instances
CLI->>User: Select instance from helix.toml
User-->>CLI: Selected instance
else No project
CLI->>User: Select workspace and cluster
CLI->>Cloud: GET /api/cli/workspaces (fetch workspaces)
Cloud-->>CLI: List of workspaces
CLI->>User: Select workspace
User-->>CLI: Selected workspace
CLI->>Cloud: GET /api/cli/workspaces/{workspace_id}/clusters
Cloud-->>CLI: List of clusters
CLI->>User: Select cluster
User-->>CLI: Selected cluster
end
CLI->>Cloud: GET /api/clusters/{cluster_id}/sync
end
alt Success Response
Cloud-->>CLI: SyncResponse{helix_toml, hx_files}
CLI->>FS: Check existing files for differences
FS-->>CLI: List of differing files
alt Files differ
CLI->>User: Show differing files list
CLI->>User: Confirm overwrite?
User-->>CLI: Yes/No confirmation
alt User confirms
CLI->>FS: Write .hx files to queries directory
CLI->>FS: Merge remote helix.toml with local config
Note over CLI,FS: Preserves local instances,<br/>updates project & cloud sections
CLI->>User: Success message with file count
else User declines
CLI->>User: "Sync aborted by user"
end
else No differences or new files
CLI->>FS: Write all files directly
CLI->>FS: Merge helix.toml (if provided)
CLI->>User: Success message with file count
end
else Error Response
alt 404 Not Found
CLI->>User: "No source files found. Deploy first with helix push"
else 401 Unauthorized
CLI->>User: "Authentication failed. Run helix auth login"
else 403 Forbidden
CLI->>User: "Access denied to cluster"
else Other Error
CLI->>User: Generic error message
end
end
Key updates from the original diagram:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Greptile Overview
Greptile Summary
Implements
helix synccommand to pull source files and configuration from deployed Helix Cloud instances back to local projects, replacing the unimplementedhelix pullcommand.Key Changes:
pullcommand tosyncwith full implementation for Helix Cloud instances.hxsource files andhelix.tomlconfig from cloud via new/syncAPI endpointhelix.tomlwith local config (preserves local instances, updates project and cloud sections)WorkspaceConfigstruct andinput_workspace_idprompt (unused, likely for future features)helix.tomlto cloud for storage and later retrievalIssues Found:
differing_fileslistImportant Files Changed
Sequence Diagram
sequenceDiagram participant User participant CLI as helix sync participant Cloud as Helix Cloud participant FS as File System User->>CLI: helix sync instance_name CLI->>FS: Load ProjectContext FS-->>CLI: Project config CLI->>CLI: Validate instance type Note over CLI: Only Helix Cloud supported CLI->>Cloud: GET /sync endpoint alt Success Cloud-->>CLI: SyncResponse with files CLI->>FS: Check for file differences FS-->>CLI: List of differing files alt Files differ CLI->>User: Show differing files CLI->>User: Confirm overwrite? User-->>CLI: Confirmation alt User confirms CLI->>FS: Write files to queries dir CLI->>FS: Merge helix.toml config FS-->>CLI: Done CLI->>User: Success message else User declines CLI->>User: Sync aborted end else No differences CLI->>FS: Write files CLI->>User: Success message end else Error Cloud-->>CLI: Error response CLI->>User: Error message end