forked from colbymchenry/codegraph
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(installer): add Antigravity CLI target #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+198
−3
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| use crate::{ | ||
| targets::jsonutil, AgentTarget, DetectStatus, InstallOpts, InstallReport, INSTRUCTIONS_MD, | ||
| }; | ||
| use anyhow::Result; | ||
| use camino::Utf8PathBuf; | ||
| use serde_json::{json, Value}; | ||
|
|
||
| pub struct AntigravityTarget; | ||
|
|
||
| impl AntigravityTarget { | ||
| fn config_paths(&self, _opts: &InstallOpts) -> Vec<Utf8PathBuf> { | ||
| let mut paths = Vec::new(); | ||
| if let Some(home) = dirs::home_dir() { | ||
| if let Ok(p) = Utf8PathBuf::from_path_buf(home.join(".gemini").join("antigravity-cli").join("mcp_config.json")) { | ||
| paths.push(p); | ||
| } | ||
| if let Ok(p) = Utf8PathBuf::from_path_buf(home.join(".gemini").join("config").join("mcp_config.json")) { | ||
| paths.push(p); | ||
| } | ||
| } | ||
| if let Some(config) = dirs::config_dir() { | ||
| if let Ok(p) = Utf8PathBuf::from_path_buf(config.join("gemini").join("antigravity-cli").join("mcp_config.json")) { | ||
| paths.push(p); | ||
| } | ||
| if let Ok(p) = Utf8PathBuf::from_path_buf(config.join("gemini").join("config").join("mcp_config.json")) { | ||
| paths.push(p); | ||
| } | ||
| } | ||
| paths | ||
| } | ||
|
|
||
| fn instructions_paths(&self, _opts: &InstallOpts) -> Vec<Utf8PathBuf> { | ||
| let mut paths = Vec::new(); | ||
| if let Some(home) = dirs::home_dir() { | ||
| if let Ok(p) = Utf8PathBuf::from_path_buf(home.join(".gemini").join("antigravity-cli").join("ANTIGRAVITY.md")) { | ||
| paths.push(p); | ||
| } | ||
| if let Ok(p) = Utf8PathBuf::from_path_buf(home.join(".gemini").join("config").join("ANTIGRAVITY.md")) { | ||
| paths.push(p); | ||
| } | ||
| } | ||
| if let Some(config) = dirs::config_dir() { | ||
| if let Ok(p) = Utf8PathBuf::from_path_buf(config.join("gemini").join("antigravity-cli").join("ANTIGRAVITY.md")) { | ||
| paths.push(p); | ||
| } | ||
| if let Ok(p) = Utf8PathBuf::from_path_buf(config.join("gemini").join("config").join("ANTIGRAVITY.md")) { | ||
| paths.push(p); | ||
| } | ||
| } | ||
| paths | ||
| } | ||
| } | ||
|
|
||
| impl AgentTarget for AntigravityTarget { | ||
| fn id(&self) -> &'static str { | ||
| "antigravity" | ||
| } | ||
| fn label(&self) -> &'static str { | ||
| "Antigravity CLI" | ||
| } | ||
|
|
||
| fn detect(&self, opts: &InstallOpts) -> DetectStatus { | ||
| let paths = self.config_paths(opts); | ||
| if paths.is_empty() { | ||
| return DetectStatus::NotFound; | ||
| } | ||
|
|
||
| let mut all_not_found = true; | ||
| let mut any_configured = false; | ||
|
|
||
| for p in &paths { | ||
| if !p.exists() { | ||
| if let Some(parent) = p.parent() { | ||
| if parent.exists() { | ||
| all_not_found = false; | ||
| } | ||
| } | ||
| } else { | ||
| all_not_found = false; | ||
| if let Ok(v) = jsonutil::read_or_default(p) { | ||
| if v.pointer("/mcpServers/codegraph").is_some() { | ||
| any_configured = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if any_configured { | ||
| DetectStatus::AlreadyConfigured | ||
| } else if all_not_found { | ||
| DetectStatus::NotFound | ||
| } else { | ||
| DetectStatus::Found | ||
| } | ||
| } | ||
|
|
||
| fn install(&self, opts: &InstallOpts) -> Result<InstallReport> { | ||
| let paths = self.config_paths(opts); | ||
| if paths.is_empty() { | ||
| return Err(anyhow::anyhow!("no settings paths")); | ||
| } | ||
|
|
||
| let mut written = Vec::new(); | ||
| let mcp_entry = json!({ | ||
| "command": opts.binary_path.as_str(), | ||
| "args": serve_args(opts), | ||
| }); | ||
|
|
||
| for settings in &paths { | ||
| if let Some(parent) = settings.parent() { | ||
| if !parent.exists() { | ||
| std::fs::create_dir_all(parent.as_std_path())?; | ||
| } | ||
| } | ||
|
|
||
| let mut v = jsonutil::read_or_default(settings)?; | ||
| let mut changed = false; | ||
| { | ||
| if !v.is_object() { | ||
| v = Value::Object(Default::default()); | ||
| } | ||
| let obj = v.as_object_mut().unwrap(); | ||
| let servers = obj | ||
| .entry("mcpServers") | ||
| .or_insert_with(|| Value::Object(Default::default())); | ||
| let servers = servers | ||
| .as_object_mut() | ||
| .ok_or_else(|| anyhow::anyhow!("mcpServers not an object"))?; | ||
| if servers.get("codegraph") != Some(&mcp_entry) { | ||
| servers.insert("codegraph".into(), mcp_entry.clone()); | ||
| changed = true; | ||
| } | ||
| } | ||
|
|
||
| if changed { | ||
| jsonutil::write_pretty(settings, &v)?; | ||
| written.push(settings.clone()); | ||
| } | ||
| } | ||
|
|
||
| for md in self.instructions_paths(opts) { | ||
| let want = INSTRUCTIONS_MD; | ||
| let existing = std::fs::read_to_string(md.as_std_path()).ok(); | ||
| if existing.as_deref() != Some(want) { | ||
| if let Some(parent) = md.parent() { | ||
| std::fs::create_dir_all(parent.as_std_path())?; | ||
| } | ||
| std::fs::write(md.as_std_path(), want)?; | ||
| written.push(md); | ||
| } | ||
| } | ||
|
|
||
| if written.is_empty() { | ||
| Ok(InstallReport::Unchanged) | ||
| } else { | ||
| Ok(InstallReport::Installed(written)) | ||
| } | ||
| } | ||
|
|
||
| fn uninstall(&self, opts: &InstallOpts) -> Result<InstallReport> { | ||
| let mut removed = Vec::new(); | ||
| for settings in self.config_paths(opts) { | ||
| if settings.exists() { | ||
| let mut v = jsonutil::read_or_default(&settings)?; | ||
| let mut changed = false; | ||
| if let Some(servers) = v.pointer_mut("/mcpServers").and_then(|s| s.as_object_mut()) | ||
| { | ||
| if servers.remove("codegraph").is_some() { | ||
| changed = true; | ||
| } | ||
| } | ||
| if changed { | ||
| jsonutil::write_pretty(&settings, &v)?; | ||
| removed.push(settings); | ||
| } | ||
| } | ||
| } | ||
| if removed.is_empty() { | ||
| Ok(InstallReport::Unchanged) | ||
| } else { | ||
| Ok(InstallReport::Updated(removed)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn serve_args(opts: &InstallOpts) -> Value { | ||
| let mut args = vec![Value::String("serve".into()), Value::String("--mcp".into())]; | ||
| if let Some(root) = &opts.project_root { | ||
| args.push(Value::String("--path".into())); | ||
| args.push(Value::String(root.to_string())); | ||
| } | ||
| Value::Array(args) | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub mod antigravity; | ||
| pub mod claude; | ||
| pub mod codex; | ||
| pub mod cursor; | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated