Working on the gemini CLI

This commit is contained in:
2026-06-03 15:10:27 -07:00
parent 8d9fe389c6
commit a0412541a8
+11 -5
View File
@@ -34,7 +34,6 @@ def main():
client = genai.Client() client = genai.Client()
context_data = {"file_ids": [], "cache_id": None} context_data = {"file_ids": [], "cache_id": None}
# Load existing context if a context file is specified and exists
if args.context and os.path.exists(args.context): if args.context and os.path.exists(args.context):
try: try:
with open(args.context, "r") as f: with open(args.context, "r") as f:
@@ -68,11 +67,11 @@ def main():
print("Cleanup complete.") print("Cleanup complete.")
return return
# Wrap the main execution in a try/finally to guarantee cleanup on transient runs
try: try:
# --------------------------------------------------------- # ---------------------------------------------------------
# UPLOAD LOGIC # UPLOAD LOGIC
# --------------------------------------------------------- # ---------------------------------------------------------
new_files_added = False
if args.files: if args.files:
for file_path in args.files: for file_path in args.files:
if not os.path.exists(file_path): if not os.path.exists(file_path):
@@ -85,6 +84,7 @@ def main():
if uploaded_file.name not in context_data["file_ids"]: if uploaded_file.name not in context_data["file_ids"]:
context_data["file_ids"].append(uploaded_file.name) context_data["file_ids"].append(uploaded_file.name)
new_files_added = True
if args.context: if args.context:
with open(args.context, "w") as f: with open(args.context, "w") as f:
@@ -94,15 +94,21 @@ def main():
# CACHE CREATION LOGIC # CACHE CREATION LOGIC
# --------------------------------------------------------- # ---------------------------------------------------------
system_instruction = ( system_instruction = (
# "You are a strict data extraction tool. Output exactly what is requested "
# "(e.g., CSV). Never use markdown formatting blocks (like ```csv). "
# "Never include conversational text, greetings, or explanations. Output raw data only."
"You are a hybrid data extraction tool. If a specific format or file format output is requested " "You are a hybrid data extraction tool. If a specific format or file format output is requested "
"(e.g., CSV), then output exactly what was requested and never use markdown formatting blocks (like ```csv). " "(e.g., CSV), then output exactly what was requested and never use markdown formatting blocks (like ```csv). "
"If a specific format was requested, never include conversational text, greetings, or explanations; " "If a specific format was requested, never include conversational text, greetings, or explanations; "
"and output raw data only. If not specific data format is suggested, you can answer with conversational text." "and output raw data only. If not specific data format is suggested, you can answer with conversational text."
) )
# If new files were added but a cache already exists, we must destroy the stale cache.
if new_files_added and context_data.get("cache_id"):
print("New files detected. Destroying stale cache to rebuild...")
try:
client.caches.delete(name=context_data["cache_id"])
except Exception as e:
print(f"Warning: Could not delete stale cache. {e}", file=sys.stderr)
context_data["cache_id"] = None
cache_too_small = False cache_too_small = False
file_objects = [] file_objects = []