feat(ai): finalize Gemini CLI integration with telemetry polish and cleanup

This commit is contained in:
2026-02-25 14:30:21 -05:00
parent d187a6c8d9
commit 1e5b43ebcd
4 changed files with 30 additions and 23 deletions

View File

@@ -1,17 +1,20 @@
import subprocess
import json
import sys
import time
class GeminiCliAdapter:
def __init__(self, binary_path="gemini"):
self.binary_path = binary_path
self.last_usage = None
self.session_id = None
self.last_latency = 0.0
def send(self, message):
"""
Sends a message to the Gemini CLI and processes the streaming JSON output.
"""
start_time = time.time()
# On Windows, using shell=True allows executing .cmd/.bat files and
# handles command strings with arguments more gracefully.
# We pass the message via stdin to avoid command-line length limits.
@@ -19,7 +22,6 @@ class GeminiCliAdapter:
if self.session_id:
command += f' --resume {self.session_id}'
print(f"[DEBUG] GeminiCliAdapter: Executing command: {command}")
accumulated_text = ""
process = subprocess.Popen(
@@ -41,7 +43,6 @@ class GeminiCliAdapter:
line = line.strip()
if not line:
continue
print(f"[DEBUG] GeminiCliAdapter stdout: {line}")
try:
data = json.loads(line)
@@ -66,12 +67,10 @@ class GeminiCliAdapter:
continue
process.wait()
if process.returncode != 0:
err = process.stderr.read()
print(f"[DEBUG] GeminiCliAdapter failed with exit code {process.returncode}. stderr: {err}")
except Exception as e:
process.kill()
print(f"[DEBUG] GeminiCliAdapter exception: {e}")
raise e
finally:
self.last_latency = time.time() - start_time
return accumulated_text