gitarsenal-cli 1.6.2 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitarsenal-cli",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "CLI tool for creating Modal sandboxes with GitHub repositories",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -187,4 +187,37 @@ class CredentialsManager:
187
187
 
188
188
  def clear_all_credentials(self):
189
189
  """Clear all saved credentials"""
190
- return self.save_credentials({})
190
+ return self.save_credentials({})
191
+
192
+ def cleanup_security_files(self):
193
+ """Clean up all security-related files including legacy files"""
194
+ try:
195
+ # Clear all credentials from the main file
196
+ self.clear_all_credentials()
197
+
198
+ # Remove legacy OpenAI key file
199
+ openai_key_file = self.config_dir / "openai_key"
200
+ if openai_key_file.exists():
201
+ openai_key_file.unlink()
202
+ print("✅ Removed legacy OpenAI API key file")
203
+
204
+ # Remove environment variables
205
+ import os
206
+ security_vars = [
207
+ "OPENAI_API_KEY",
208
+ "HUGGINGFACE_TOKEN",
209
+ "WANDB_API_KEY",
210
+ "MODAL_TOKEN_ID",
211
+ "MODAL_TOKEN",
212
+ "MODAL_TOKEN_SECRET"
213
+ ]
214
+
215
+ for var in security_vars:
216
+ if var in os.environ:
217
+ del os.environ[var]
218
+
219
+ print("✅ Security cleanup completed successfully")
220
+ return True
221
+ except Exception as e:
222
+ print(f"❌ Error during security cleanup: {e}")
223
+ return False
@@ -210,23 +210,22 @@ def setup_modal_auth():
210
210
  logger.error(f"Error setting up Modal authentication: {e}")
211
211
  return False
212
212
 
213
- def cleanup_modal_token():
214
- """Delete Modal token files and environment variables after SSH container is started"""
215
- logger.info("🧹 Cleaning up Modal token for security...")
213
+ def cleanup_security_tokens():
214
+ """Delete all security tokens and API keys after SSH container is started"""
215
+ logger.info("🧹 Cleaning up security tokens and API keys...")
216
216
 
217
217
  try:
218
- # Remove token from environment variables
219
- if "MODAL_TOKEN_ID" in os.environ:
220
- del os.environ["MODAL_TOKEN_ID"]
221
- logger.info("✅ Removed MODAL_TOKEN_ID from environment")
222
-
223
- if "MODAL_TOKEN" in os.environ:
224
- del os.environ["MODAL_TOKEN"]
225
- logger.info("✅ Removed MODAL_TOKEN from environment")
226
-
227
- if "MODAL_TOKEN_SECRET" in os.environ:
228
- del os.environ["MODAL_TOKEN_SECRET"]
229
- logger.info("✅ Removed MODAL_TOKEN_SECRET from environment")
218
+ # Remove Modal tokens from environment variables
219
+ modal_env_vars = ["MODAL_TOKEN_ID", "MODAL_TOKEN", "MODAL_TOKEN_SECRET"]
220
+ for var in modal_env_vars:
221
+ if var in os.environ:
222
+ del os.environ[var]
223
+ logger.info(f" Removed {var} from environment")
224
+
225
+ # Remove OpenAI API key from environment
226
+ if "OPENAI_API_KEY" in os.environ:
227
+ del os.environ["OPENAI_API_KEY"]
228
+ logger.info("✅ Removed OpenAI API key from environment")
230
229
 
231
230
  # Delete ~/.modal.toml file
232
231
  from pathlib import Path
@@ -235,9 +234,20 @@ def cleanup_modal_token():
235
234
  modal_toml.unlink()
236
235
  logger.info(f"✅ Deleted Modal token file at {modal_toml}")
237
236
 
238
- logger.info("✅ Modal token cleanup completed successfully")
237
+ # Delete ~/.gitarsenal/openai_key file
238
+ openai_key_file = Path.home() / ".gitarsenal" / "openai_key"
239
+ if openai_key_file.exists():
240
+ openai_key_file.unlink()
241
+ logger.info(f"✅ Deleted OpenAI API key file at {openai_key_file}")
242
+
243
+ logger.info("✅ Security cleanup completed successfully")
239
244
  except Exception as e:
240
- logger.error(f"❌ Error during Modal token cleanup: {e}")
245
+ logger.error(f"❌ Error during security cleanup: {e}")
246
+
247
+ # Keep the old function for backward compatibility
248
+ def cleanup_modal_token():
249
+ """Legacy function - now calls the comprehensive cleanup"""
250
+ cleanup_security_tokens()
241
251
 
242
252
  @app.route('/api/health', methods=['GET'])
243
253
  def health_check():
@@ -1640,15 +1640,6 @@ def create_modal_ssh_container(gpu_type, repo_url=None, repo_name=None, setup_co
1640
1640
  print(f"❌ Error running container: {e}")
1641
1641
  return None
1642
1642
 
1643
- def is_local_server_running(url, timeout=2):
1644
- """Check if a local server is running by attempting a connection."""
1645
- import requests
1646
- try:
1647
- response = requests.get(url, timeout=timeout)
1648
- return True
1649
- except requests.exceptions.RequestException:
1650
- return False
1651
-
1652
1643
  def fetch_setup_commands_from_api(repo_url):
1653
1644
  """Fetch setup commands from the GitIngest API using real repository analysis."""
1654
1645
  import tempfile
@@ -2258,74 +2249,6 @@ def find_entry_point(repo_dir):
2258
2249
 
2259
2250
  return None
2260
2251
 
2261
- def analyze_directory_navigation_with_llm(current_dir, target_dir, current_contents, target_contents, api_key=None):
2262
- """Use LLM to analyze if directory navigation makes sense"""
2263
- if not api_key:
2264
- # Try to get API key from environment
2265
- api_key = os.environ.get("OPENAI_API_KEY")
2266
-
2267
- if not api_key:
2268
- print("⚠️ No OpenAI API key available for directory analysis")
2269
- return None
2270
-
2271
- # Create analysis prompt
2272
- analysis_prompt = f"""
2273
- I'm trying to determine if a 'cd {target_dir}' command makes sense.
2274
-
2275
- CURRENT DIRECTORY: {current_dir}
2276
- Current directory contents:
2277
- {current_contents}
2278
-
2279
- TARGET DIRECTORY: {target_dir}
2280
- Target directory contents:
2281
- {target_contents}
2282
-
2283
- Please analyze if navigating to the target directory makes sense by considering:
2284
- 1. Are the contents significantly different?
2285
- 2. Does the target directory contain important files (like source code, config files, etc.)?
2286
- 3. Is this likely a nested project directory or just a duplicate?
2287
- 4. Would navigating provide access to different functionality or files?
2288
-
2289
- Respond with only 'NAVIGATE' if navigation makes sense, or 'SKIP' if it's redundant.
2290
- """
2291
-
2292
- # Prepare the API request
2293
- headers = {
2294
- "Content-Type": "application/json",
2295
- "Authorization": f"Bearer {api_key}"
2296
- }
2297
-
2298
- payload = {
2299
- "model": "gpt-4",
2300
- "messages": [
2301
- {"role": "system", "content": "You are a directory navigation assistant. Analyze if navigating to a target directory makes sense based on the contents of both directories. Respond with only 'NAVIGATE' or 'SKIP'."},
2302
- {"role": "user", "content": analysis_prompt}
2303
- ],
2304
- "temperature": 0.1,
2305
- "max_tokens": 50
2306
- }
2307
-
2308
- try:
2309
- print("🤖 Calling OpenAI for directory navigation analysis...")
2310
- response = requests.post(
2311
- "https://api.openai.com/v1/chat/completions",
2312
- headers=headers,
2313
- json=payload,
2314
- timeout=30
2315
- )
2316
-
2317
- if response.status_code == 200:
2318
- result = response.json()
2319
- llm_response = result["choices"][0]["message"]["content"].strip()
2320
- print(f"🤖 LLM Response: {llm_response}")
2321
- return llm_response
2322
- else:
2323
- print(f"❌ OpenAI API error: {response.status_code} - {response.text}")
2324
- return None
2325
- except Exception as e:
2326
- print(f"❌ Error calling OpenAI API: {e}")
2327
- return None
2328
-
2329
2252
  def cleanup_modal_token():
2330
2253
  """Delete token files and environment variables after SSH container is started"""
2331
2254
  print("🧹 Cleaning up tokens for security...")
@@ -2355,6 +2278,45 @@ def cleanup_modal_token():
2355
2278
  except Exception as e:
2356
2279
  print(f"❌ Error during token cleanup: {e}")
2357
2280
 
2281
+ def cleanup_security_tokens():
2282
+ """Delete all security tokens and API keys after SSH container is started"""
2283
+ print("🧹 Cleaning up security tokens and API keys...")
2284
+
2285
+ try:
2286
+ # Remove Modal tokens from environment variables
2287
+ modal_env_vars = ["MODAL_TOKEN_ID", "MODAL_TOKEN", "MODAL_TOKEN_SECRET"]
2288
+ for var in modal_env_vars:
2289
+ if var in os.environ:
2290
+ del os.environ[var]
2291
+ # print(f"✅ Removed {var} from environment")
2292
+
2293
+ # Remove OpenAI API key from environment
2294
+ if "OPENAI_API_KEY" in os.environ:
2295
+ del os.environ["OPENAI_API_KEY"]
2296
+ # print("✅ Removed OpenAI API key from environment")
2297
+
2298
+ # Delete ~/.modal.toml file
2299
+ home_dir = os.path.expanduser("~")
2300
+ modal_toml = os.path.join(home_dir, ".modal.toml")
2301
+ if os.path.exists(modal_toml):
2302
+ os.remove(modal_toml)
2303
+ # print(f"✅ Deleted Modal token file at {modal_toml}")
2304
+
2305
+ # Delete ~/.gitarsenal/openai_key file
2306
+ openai_key_file = os.path.join(home_dir, ".gitarsenal", "openai_key")
2307
+ if os.path.exists(openai_key_file):
2308
+ os.remove(openai_key_file)
2309
+ # print(f"✅ Deleted OpenAI API key file at {openai_key_file}")
2310
+
2311
+ # print("✅ Security cleanup completed successfully")
2312
+ except Exception as e:
2313
+ print(f"❌ Error during security cleanup: {e}")
2314
+
2315
+ # Keep the old function for backward compatibility
2316
+ def cleanup_modal_token():
2317
+ """Legacy function - now calls the comprehensive cleanup"""
2318
+ cleanup_security_tokens()
2319
+
2358
2320
  def show_usage_examples():
2359
2321
  """Display usage examples for the script."""
2360
2322
  print("Usage Examples\n")
@@ -1640,15 +1640,6 @@ def create_modal_ssh_container(gpu_type, repo_url=None, repo_name=None, setup_co
1640
1640
  print(f"❌ Error running container: {e}")
1641
1641
  return None
1642
1642
 
1643
- def is_local_server_running(url, timeout=2):
1644
- """Check if a local server is running by attempting a connection."""
1645
- import requests
1646
- try:
1647
- response = requests.get(url, timeout=timeout)
1648
- return True
1649
- except requests.exceptions.RequestException:
1650
- return False
1651
-
1652
1643
  def fetch_setup_commands_from_api(repo_url):
1653
1644
  """Fetch setup commands from the GitIngest API using real repository analysis."""
1654
1645
  import tempfile
@@ -2258,74 +2249,6 @@ def find_entry_point(repo_dir):
2258
2249
 
2259
2250
  return None
2260
2251
 
2261
- def analyze_directory_navigation_with_llm(current_dir, target_dir, current_contents, target_contents, api_key=None):
2262
- """Use LLM to analyze if directory navigation makes sense"""
2263
- if not api_key:
2264
- # Try to get API key from environment
2265
- api_key = os.environ.get("OPENAI_API_KEY")
2266
-
2267
- if not api_key:
2268
- print("⚠️ No OpenAI API key available for directory analysis")
2269
- return None
2270
-
2271
- # Create analysis prompt
2272
- analysis_prompt = f"""
2273
- I'm trying to determine if a 'cd {target_dir}' command makes sense.
2274
-
2275
- CURRENT DIRECTORY: {current_dir}
2276
- Current directory contents:
2277
- {current_contents}
2278
-
2279
- TARGET DIRECTORY: {target_dir}
2280
- Target directory contents:
2281
- {target_contents}
2282
-
2283
- Please analyze if navigating to the target directory makes sense by considering:
2284
- 1. Are the contents significantly different?
2285
- 2. Does the target directory contain important files (like source code, config files, etc.)?
2286
- 3. Is this likely a nested project directory or just a duplicate?
2287
- 4. Would navigating provide access to different functionality or files?
2288
-
2289
- Respond with only 'NAVIGATE' if navigation makes sense, or 'SKIP' if it's redundant.
2290
- """
2291
-
2292
- # Prepare the API request
2293
- headers = {
2294
- "Content-Type": "application/json",
2295
- "Authorization": f"Bearer {api_key}"
2296
- }
2297
-
2298
- payload = {
2299
- "model": "gpt-4",
2300
- "messages": [
2301
- {"role": "system", "content": "You are a directory navigation assistant. Analyze if navigating to a target directory makes sense based on the contents of both directories. Respond with only 'NAVIGATE' or 'SKIP'."},
2302
- {"role": "user", "content": analysis_prompt}
2303
- ],
2304
- "temperature": 0.1,
2305
- "max_tokens": 50
2306
- }
2307
-
2308
- try:
2309
- print("🤖 Calling OpenAI for directory navigation analysis...")
2310
- response = requests.post(
2311
- "https://api.openai.com/v1/chat/completions",
2312
- headers=headers,
2313
- json=payload,
2314
- timeout=30
2315
- )
2316
-
2317
- if response.status_code == 200:
2318
- result = response.json()
2319
- llm_response = result["choices"][0]["message"]["content"].strip()
2320
- print(f"🤖 LLM Response: {llm_response}")
2321
- return llm_response
2322
- else:
2323
- print(f"❌ OpenAI API error: {response.status_code} - {response.text}")
2324
- return None
2325
- except Exception as e:
2326
- print(f"❌ Error calling OpenAI API: {e}")
2327
- return None
2328
-
2329
2252
  def cleanup_modal_token():
2330
2253
  """Delete token files and environment variables after SSH container is started"""
2331
2254
  print("🧹 Cleaning up tokens for security...")
@@ -2355,6 +2278,45 @@ def cleanup_modal_token():
2355
2278
  except Exception as e:
2356
2279
  print(f"❌ Error during token cleanup: {e}")
2357
2280
 
2281
+ def cleanup_security_tokens():
2282
+ """Delete all security tokens and API keys after SSH container is started"""
2283
+ print("🧹 Cleaning up security tokens and API keys...")
2284
+
2285
+ try:
2286
+ # Remove Modal tokens from environment variables
2287
+ modal_env_vars = ["MODAL_TOKEN_ID", "MODAL_TOKEN", "MODAL_TOKEN_SECRET"]
2288
+ for var in modal_env_vars:
2289
+ if var in os.environ:
2290
+ del os.environ[var]
2291
+ # print(f"✅ Removed {var} from environment")
2292
+
2293
+ # Remove OpenAI API key from environment
2294
+ if "OPENAI_API_KEY" in os.environ:
2295
+ del os.environ["OPENAI_API_KEY"]
2296
+ # print("✅ Removed OpenAI API key from environment")
2297
+
2298
+ # Delete ~/.modal.toml file
2299
+ home_dir = os.path.expanduser("~")
2300
+ modal_toml = os.path.join(home_dir, ".modal.toml")
2301
+ if os.path.exists(modal_toml):
2302
+ os.remove(modal_toml)
2303
+ # print(f"✅ Deleted Modal token file at {modal_toml}")
2304
+
2305
+ # Delete ~/.gitarsenal/openai_key file
2306
+ openai_key_file = os.path.join(home_dir, ".gitarsenal", "openai_key")
2307
+ if os.path.exists(openai_key_file):
2308
+ os.remove(openai_key_file)
2309
+ # print(f"✅ Deleted OpenAI API key file at {openai_key_file}")
2310
+
2311
+ # print("✅ Security cleanup completed successfully")
2312
+ except Exception as e:
2313
+ print(f"❌ Error during security cleanup: {e}")
2314
+
2315
+ # Keep the old function for backward compatibility
2316
+ def cleanup_modal_token():
2317
+ """Legacy function - now calls the comprehensive cleanup"""
2318
+ cleanup_security_tokens()
2319
+
2358
2320
  def show_usage_examples():
2359
2321
  """Display usage examples for the script."""
2360
2322
  print("Usage Examples\n")