From 22177a28a1f5b627165c0a9b4b82989f32d73e8a Mon Sep 17 00:00:00 2001 From: Nikketryhard Date: Wed, 18 Feb 2026 02:50:47 -0600 Subject: [PATCH] chore: fix all clippy warnings and add Cargo.toml metadata --- Cargo.toml | 4 ++++ src/api/completions.rs | 45 +++++++++++++++++++----------------------- src/api/responses.rs | 2 ++ src/api/util.rs | 2 +- src/mitm/intercept.rs | 7 +------ src/mitm/modify.rs | 9 ++------- src/mitm/proxy.rs | 2 +- src/mitm/store.rs | 2 ++ src/platform.rs | 1 + src/trace.rs | 5 +++++ 10 files changed, 39 insertions(+), 40 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5d50040..aa33f72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,10 @@ name = "zerogravity" version = "1.0.0" edition = "2021" +license = "MIT" +description = "OpenAI-compatible proxy for Google Antigravity" +repository = "https://github.com/NikkeTryHard/zerogravity" +authors = ["NikkeTryHard"] [[bin]] name = "zerogravity" diff --git a/src/api/completions.rs b/src/api/completions.rs index bb1ba90..762e4be 100644 --- a/src/api/completions.rs +++ b/src/api/completions.rs @@ -401,7 +401,7 @@ pub(crate) async fn handle_completions( ); } - let n = (body.n.max(1)).min(5); // Cap at 5 to prevent abuse + let n = body.n.clamp(1, 5); // Cap at 5 to prevent abuse if n > 1 && body.stream { warn!("n={n} requested with streaming — streaming only supports n=1, ignoring n"); } @@ -594,31 +594,25 @@ pub(crate) async fn handle_completions( // n > 1: fire additional (n-1) parallel cascades let mut extra_cascade_ids = Vec::with_capacity((n - 1) as usize); for _ in 1..n { - match state.backend.create_cascade().await { - Ok(cid) => { - // Send the same message on each extra cascade - match state - .backend - .send_message_with_image( - &cid, - &format!(".", cid), - model.model_enum, - image.as_ref(), - ) - .await - { - Ok((200, _)) => { - let bg = Arc::clone(&state.backend); - let cid2 = cid.clone(); - tokio::spawn(async move { - let _ = bg.update_annotations(&cid2).await; - }); - extra_cascade_ids.push(cid); - } - _ => {} // Skip failed cascades - } + if let Ok(cid) = state.backend.create_cascade().await { + // Send the same message on each extra cascade + if let Ok((200, _)) = state + .backend + .send_message_with_image( + &cid, + &format!(".", cid), + model.model_enum, + image.as_ref(), + ) + .await + { + let bg = Arc::clone(&state.backend); + let cid2 = cid.clone(); + tokio::spawn(async move { + let _ = bg.update_annotations(&cid2).await; + }); + extra_cascade_ids.push(cid); } - Err(_) => {} // Skip failed cascade creation } } @@ -714,6 +708,7 @@ pub(crate) async fn handle_completions( // ─── Streaming ─────────────────────────────────────────────────────────────── /// Streaming output in Chat Completions format. +#[allow(clippy::too_many_arguments)] async fn chat_completions_stream( state: Arc, completion_id: String, diff --git a/src/api/responses.rs b/src/api/responses.rs index 6d6df42..1e8d587 100644 --- a/src/api/responses.rs +++ b/src/api/responses.rs @@ -639,6 +639,7 @@ async fn usage_from_poll( // ─── Sync response ─────────────────────────────────────────────────────────── +#[allow(clippy::too_many_arguments)] async fn handle_responses_sync( state: Arc, response_id: String, @@ -1034,6 +1035,7 @@ async fn handle_responses_sync( // ─── Streaming response ───────────────────────────────────────────────────── +#[allow(clippy::too_many_arguments)] async fn handle_responses_stream( state: Arc, response_id: String, diff --git a/src/api/util.rs b/src/api/util.rs index 42fcd37..3d8c923 100644 --- a/src/api/util.rs +++ b/src/api/util.rs @@ -158,7 +158,7 @@ pub(crate) fn parse_data_uri(url: &str) -> Option { /// Supports: /// - Chat Completions: `{"type": "image_url", "image_url": {"url": "data:..."}}` /// - Responses API: `{"type": "input_image", "image_url": "data:..."}` or -/// `{"type": "input_image", "url": "data:..."}` +/// `{"type": "input_image", "url": "data:..."}` pub(crate) fn extract_image_from_content(item: &serde_json::Value) -> Option { let item_type = item["type"].as_str().unwrap_or(""); diff --git a/src/mitm/intercept.rs b/src/mitm/intercept.rs index 507c93f..e66e927 100644 --- a/src/mitm/intercept.rs +++ b/src/mitm/intercept.rs @@ -38,12 +38,7 @@ pub fn parse_streaming_chunk(chunk: &str, accumulator: &mut StreamingAccumulator // Extract and process all complete lines (terminated by \n). // Leave any trailing partial line in the buffer for the next read. - loop { - let pos = match accumulator.pending_data.find('\n') { - Some(p) => p, - None => break, - }; - + while let Some(pos) = accumulator.pending_data.find('\n') { let line = accumulator.pending_data[..pos] .trim_end_matches('\r') .to_string(); diff --git a/src/mitm/modify.rs b/src/mitm/modify.rs index 28b0ddf..2a154d0 100644 --- a/src/mitm/modify.rs +++ b/src/mitm/modify.rs @@ -1431,7 +1431,7 @@ mod tests { fn rewrite_function_calls_in_response(json: &mut Value) -> bool { let mut changed = false; - fn rewrite_candidates(candidates: &mut Vec) -> bool { + fn rewrite_candidates(candidates: &mut [Value]) -> bool { let mut changed = false; for candidate in candidates.iter_mut() { if let Some(parts) = candidate @@ -1504,12 +1504,7 @@ impl ResponseRewriter { let mut output = String::new(); // Extract all complete lines (terminated by \n) - loop { - let pos = match self.pending.find('\n') { - Some(p) => p, - None => break, - }; - + while let Some(pos) = self.pending.find('\n') { // Include the \n in the extracted line let line = self.pending[..=pos].to_string(); self.pending = self.pending[pos + 1..].to_string(); diff --git a/src/mitm/proxy.rs b/src/mitm/proxy.rs index 68789c6..07f6676 100644 --- a/src/mitm/proxy.rs +++ b/src/mitm/proxy.rs @@ -962,7 +962,7 @@ async fn resolve_upstream(domain: &str) -> String { } // 2. Try cached IPs file - if let Ok(contents) = tokio::fs::read_to_string("/tmp/antigravity-mitm-real-ips").await { + if let Ok(contents) = tokio::fs::read_to_string("/tmp/zerogravity-real-ips").await { for line in contents.lines() { if let Some((d, ip)) = line.split_once('=') { if d == domain { diff --git a/src/mitm/store.rs b/src/mitm/store.rs index 51c2d54..15e4697 100644 --- a/src/mitm/store.rs +++ b/src/mitm/store.rs @@ -215,8 +215,10 @@ pub struct RequestContext { /// API handlers wait on this with a timeout to detect match failures. pub gate: Arc, /// Debug trace handle (if tracing is enabled). + #[allow(dead_code)] pub trace_handle: Option, /// Current turn index in the trace (for multi-turn tracking). + #[allow(dead_code)] pub trace_turn: usize, } diff --git a/src/platform.rs b/src/platform.rs index bbda10e..d1141b5 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -257,6 +257,7 @@ fn default_os_name() -> &'static str { // ── Platform queries ── +#[allow(dead_code)] /// Returns true if running on Linux. pub fn is_linux() -> bool { cfg!(target_os = "linux") diff --git a/src/trace.rs b/src/trace.rs index 5a7bab6..55e9a2a 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -28,6 +28,7 @@ impl TraceCollector { } /// Whether tracing is enabled. + #[allow(dead_code)] pub fn enabled(&self) -> bool { self.enabled } @@ -141,6 +142,7 @@ impl TraceHandle { } /// Record MITM modify summary for a turn. + #[allow(dead_code)] pub async fn record_modify(&self, turn: usize, summary: String, original: u64, modified: u64) { let mut data = self.inner.lock().await; if let Some(t) = data.turns.get_mut(turn) { @@ -150,6 +152,7 @@ impl TraceHandle { } /// Record upstream wait time. + #[allow(dead_code)] pub async fn record_upstream_wait(&self, turn: usize, wait_ms: u64) { let mut data = self.inner.lock().await; if let Some(t) = data.turns.get_mut(turn) { @@ -166,6 +169,7 @@ impl TraceHandle { } /// Record an event sent via channel. + #[allow(dead_code)] pub async fn record_event(&self, turn: usize, event_name: &str) { let mut data = self.inner.lock().await; if let Some(t) = data.turns.get_mut(turn) { @@ -174,6 +178,7 @@ impl TraceHandle { } /// Record the handler action for a turn. + #[allow(dead_code)] pub async fn record_action(&self, turn: usize, action: &str) { let mut data = self.inner.lock().await; if let Some(t) = data.turns.get_mut(turn) {