Executor-Tyrant-Framework commited on
Commit
22a43ad
Β·
verified Β·
1 Parent(s): 95d6a65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -20
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  """
2
  Clawdbot Unified Command Center
3
 
@@ -672,36 +674,50 @@ import zipfile
672
  import shutil
673
 
674
  def process_uploaded_file(file) -> str:
675
- """WHY: Physically extracts ZIPs so tools like shell_execute can see them."""
676
- if file is None: return ""
677
-
 
 
 
 
 
678
  file_path = file.name if hasattr(file, 'name') else str(file)
679
  file_name = os.path.basename(file_path)
680
- # This path is where Clawdbot looks for extracted files
681
- upload_dir = Path("/workspace/uploads")
682
- upload_dir.mkdir(parents=True, exist_ok=True)
683
-
684
- if file_name.lower().endswith('.zip'):
685
- extract_path = upload_dir / file_name.replace('.zip', '')
686
- extract_path.mkdir(parents=True, exist_ok=True)
687
  try:
688
- with zipfile.ZipFile(file_path, 'r') as z:
689
- z.extractall(extract_path)
690
- return f"πŸ“¦ **ZIP Extracted to:** `{extract_path}`\nFiles are now available for your tools to read/modify."
 
 
 
 
 
 
 
 
 
 
 
691
  except Exception as e:
692
- return f"❌ ZIP Error: {e}"
693
-
694
- # Standard text file handling
695
- suffix = os.path.splitext(file_name)[1].lower()
696
  if suffix in TEXT_EXTENSIONS or suffix == '':
697
  try:
698
  with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
699
  content = f.read()
700
- if len(content) > 50000: content = content[:50000] + "\n... (truncated)"
 
701
  return f"πŸ“Ž **Uploaded: {file_name}**\n```\n{content}\n```"
702
  except Exception as e:
703
- return f"πŸ“Ž **Uploaded: {file_name}** (Error reading: {e})"
704
- return f"πŸ“Ž **Uploaded: {file_name}** (Binary file ignored)"
 
705
 
706
 
707
  # die Standard file handling remains the same...
 
1
+ import zipfile
2
+ import shutil
3
  """
4
  Clawdbot Unified Command Center
5
 
 
674
  import shutil
675
 
676
  def process_uploaded_file(file) -> str:
677
+ """
678
+ Read an uploaded file.
679
+ If it's text, read it into context.
680
+ If it's a ZIP, extract it so the agent can see the files inside.
681
+ """
682
+ if file is None:
683
+ return ""
684
+
685
  file_path = file.name if hasattr(file, 'name') else str(file)
686
  file_name = os.path.basename(file_path)
687
+ suffix = os.path.splitext(file_name)[1].lower()
688
+
689
+ # NEW: Handle ZIP files
690
+ if suffix == '.zip':
 
 
 
691
  try:
692
+ # Create a directory to unzip into
693
+ extract_to = Path(REPO_PATH) / "uploaded_assets" / file_name.replace(".zip", "")
694
+ extract_to.mkdir(parents=True, exist_ok=True)
695
+
696
+ import zipfile
697
+ with zipfile.ZipFile(file_path, 'r') as zip_ref:
698
+ zip_ref.extractall(extract_to)
699
+
700
+ # List what we found so the AI knows what's there
701
+ file_list = [f.name for f in extract_to.glob('*')]
702
+ return (f"πŸ“¦ **Unzipped: {file_name}**\n"
703
+ f"Location: `{extract_to}`\n"
704
+ f"Contents: {', '.join(file_list)[:200]}...\n"
705
+ f"SYSTEM NOTE: Use list_files('{extract_to.name}') to explore these files.")
706
  except Exception as e:
707
+ return f"⚠️ Failed to unzip {file_name}: {e}"
708
+
709
+ # EXISTING: Handle Text files
 
710
  if suffix in TEXT_EXTENSIONS or suffix == '':
711
  try:
712
  with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
713
  content = f.read()
714
+ if len(content) > 50000:
715
+ content = content[:50000] + f"\n\n... (truncated)"
716
  return f"πŸ“Ž **Uploaded: {file_name}**\n```\n{content}\n```"
717
  except Exception as e:
718
+ return f"πŸ“Ž **Uploaded: {file_name}** (error reading: {e})"
719
+ else:
720
+ return f"πŸ“Ž **Uploaded: {file_name}** (binary file, {os.path.getsize(file_path):,} bytes)"
721
 
722
 
723
  # die Standard file handling remains the same...