import os
import shutil
import logging
from pathlib import Path
# --- Configuration ---
SOURCE_DIR = Path("C:/path/to/your/GemAssist/folder") # Replace with the actual
path to your GemAssist folder
DEST_DIR = Path("C:/GemAssist_Alt") # Destination directory for the reorganized
structure
LOG_FILE = Path("gemassist_reorganize.log")
# --- Setup Logging ---
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler(LOG_FILE),
        logging.StreamHandler()
    ]
)
logger = logging.getLogger("reorganizer")
# --- Mapping of Files to New Locations ---
FILE_MAPPING = {
    "__init__.py": "core/",
    "ai_engine.py": "core/ai_engine.py",
    "state_utils.py": "core/state_utils.py",
    "execution_types.py": "core/execution_types.py",
    "dynamic_tools.py": "tools/dynamic_tool_generator.py",
    "tool_registry.py": "tools/tool_registry.py",
    "tool_factory.py": "tools/tool_factory.py",
    "tool_definition.py": "tools/tool_definition.py",
    "tool_runtime.py": "tools/tool_runtime.py",
    "tool_testing.py": "tools/tool_testing.py",
    "tool_composition.py": "tools/tool_composition.py",
    "tool_learning.py": "tools/tool_learning.py",
    "ai_orchestrator.py": "ai/ai_orchestrator.py",
    "avatar_ui.py": "frontend/ui/avatar_ui.py",
    "execution.py": "core/execution.py",
    "reasoning_engine.py": "core/reasoning/engine.py",
    "supreme_backend_system.py": "backend/excellence/backend_excellence.py",
    "instructions.json": "config/instructions.json",
    "execution_system.py": "core/execution_system.py",
    "state_management.py": "core/state_management.py",
    "supreme_trainer.py": "ai/training_system.py",
    "consolidated_enhanced_ai.py": "core/consolidated_ai.py",
    "autonomous_system.py": "core/agent/autonomous_system.py",
    "state_utils.py": "core/state_utils.py",
    "aienhanced_execution_manager_original.py":
"core/aienhanced_execution_manager.py",
    "__init__.py": "core/__init__.py",
    "schema.json": "config/schema.json",
    "websocket_handler.py": "ai/websocket_handler.py",
    "models.py": "ai/models/models.py",
    "utils.py": "core/utils/utils.py",
    "aienhanced_execution_manager.py": "core/aienhanced_execution_manager.py",
    "autonomous_agent.py": "core/agent/autonomous_agent.py",
    "command_execution.py": "core/agent/command_execution.py",
    "file_operations.py": "core/agent/file_operations.py",
    "memory_system.py": "core/agent/memory_system.py",
    "network_operations.py": "core/agent/network_operations.py",
    "metrics.py": "core/utils/metrics.py",
    "tool_system.py": "tools/tool_system.py",
    "tool_documentation.py": "tools/tool_documentation.py",
    "supreme.py": "core/excellence/supreme.py",
    "mandatory_excellence_procedure.py":
"core/excellence/mandatory_excellence_procedure.py",
    "self_correcting_excellence.py":
"core/excellence/self_correcting_excellence.py",
    "creative_excellence.py": "core/excellence/creative_excellence.py",
    "absolute_excellence_enforcer.py":
"core/excellence/absolute_excellence_enforcer.py",
    "config.py": "core/config/config.py",
    "base_service.py": "core/base/base_service.py",
    "base_controller.py": "core/base/base_controller.py",
    "base_manager.py": "core/base/base_manager.py",
    "base_component.py": "core/base/base_component.py",
    "base_view.py": "core/base/base_view.py",
    "base_presenter.py": "core/base/base_presenter.py",
    "exceptions.py": "core/base/exceptions.py",
    "state_utils.py": "core/state_utils.py",
    "execution_types.py": "core/execution_types.py",
    "security.py": "core/security/security.py",
    "splash_screen.py": "frontend/ui/splash_screen.py",
    "ai_planner.py": "ai/ai_planner.py",
    "aienhanced_tool_orchestrator_original.py":
"backend/tools/aienhanced_tool_orchestrator.py",
    "autonomous_agent.py": "core/agent/autonomous_agent.py",
    "command_execution.py": "core/agent/command_execution.py",
    "file_operations.py": "core/agent/file_operations.py",
    "memory_system.py": "core/agent/memory_system.py",
    "network_operations.py": "core/agent/network_operations.py",
    "ai_orchestrator.py": "ai/ai_orchestrator.py",
    "tool_runtime.py": "tools/tool_runtime.py",
    "tool_testing.py": "tools/tool_testing.py",
    "tool_composition.py": "tools/tool_composition.py",
    "tool_learning.py": "tools/tool_learning.py",
    "dynamic_tool_generator.py": "tools/dynamic_tool_generator.py",
    "tool_factory.py": "tools/tool_factory.py",
    "tool_definition.py": "tools/tool_definition.py",
    "tool_registry.py": "tools/tool_registry.py",
    "state_management.py": "core/state_management.py",
    "execution.py": "core/execution.py",
    "reasoning_engine.py": "core/reasoning/engine.py",
    "supreme_backend_system.py": "backend/excellence/backend_excellence.py",
    "consolidated_enhanced_ai.py": "core/consolidated_enhanced_ai.py",
    "avatar_ui.py": "frontend/ui/avatar_ui.py",
    "execution_system.py": "core/execution_system.py",
    "state_utils.py": "core/state_utils.py",
    "aienhanced_execution_manager.py": "core/aienhanced_execution_manager.py",
    "execution_types.py": "core/execution_types.py",
    "__init__.py": "__init__.py",
    "schema.json": "schema.json",
    "websocket_handler.py": "ai/websocket_handler.py",
    "models.py": "ai/models/models.py",
    "utils.py": "core/utils/utils.py",
    "aienhanced_execution_manager_original.py":
"core/aienhanced_execution_manager_original.py",
    "autonomous_agent.py": "core/agent/autonomous_agent.py",
    "command_execution.py": "core/agent/command_execution.py",
    "file_operations.py": "core/agent/file_operations.py",
    "memory_system.py": "core/agent/memory_system.py",
    "network_operations.py": "core/agent/network_operations.py",
    "metrics.py": "core/utils/metrics.py",
    "tool_system.py": "tools/tool_system.py",
    "tool_documentation.py": "tools/tool_documentation.py",
    "supreme.py": "core/excellence/supreme.py",
    "mandatory_excellence_procedure.py":
"core/excellence/mandatory_excellence_procedure.py",
    "self_correcting_excellence.py":
"core/excellence/self_correcting_excellence.py",
    "creative_excellence.py": "core/excellence/creative_excellence.py",
    "absolute_excellence_enforcer.py":
"core/excellence/absolute_excellence_enforcer.py",
    "config.py": "core/config/config.py",
    "base_service.py": "core/base/base_service.py",
    "base_controller.py": "core/base/base_controller.py",
    "base_manager.py": "core/base/base_manager.py",
    "base_component.py": "core/base/base_component.py",
    "base_view.py": "core/base/base_view.py",
    "base_presenter.py": "core/base/base_presenter.py",
    "exceptions.py": "core/base/exceptions.py",
    "state_utils.py": "core/state_utils.py",
    "execution_types.py": "core/execution_types.py",
    "security.py": "core/security/security.py",
    "splash_screen.py": "frontend/ui/splash_screen.py",
    "ai_planner.py": "ai/ai_planner.py",
    "aienhanced_tool_orchestrator_original.py":
"backend/tools/aienhanced_tool_orchestrator.py"
}
# --- Main Reorganization Function ---
async def reorganize_gemassist():
    """Main function to reorganize the GemAssist folder."""
    try:
         logger.info("Starting GemAssist folder reorganization...")
        # 1. Create Destination Directory
        shutil.rmtree(DEST_DIR, ignore_errors=True)
        DEST_DIR.mkdir(parents=True, exist_ok=True)
        logger.info(f"Created destination directory at {DEST_DIR}")
        # 2. Copy and Reorganize Files
        for file_name, dest_path in FILE_MAPPING.items():
            source_file = SOURCE_DIR / file_name
            if source_file.exists():
                dest_file = DEST_DIR / dest_path
                dest_file.parent.mkdir(parents=True, exist_ok=True)
                shutil.copy2(source_file, dest_file)
                logger.info(f"Copied {file_name} to {dest_path}")
            else:
                logger.warning(f"File not found: {source_file}")
        # 3. Create Placeholder requirements.txt
        requirements_file = DEST_DIR / "requirements.txt"
        requirements_file.write_text("requests\naiohttp")
          # 4. Create Placeholder config.json
          config_file = DEST_DIR / "config.json"
          config_data = {
              "gemini_api_key": "YOUR_GEMINI_API_KEY", # Replace with your actual API
key
              "log_level": "INFO",
              "max_threads": 16,
              "memory_db_path": str(DEST_DIR / "memory.db"),
              "embedding_dim": 768,
              "max_tokens": 2048
          }
          create_config_file(config_file, config_data)
        # 5. Create Startup Script
        startup_script = DEST_DIR / "run_gemassist.py"
        startup_script.write_text(f"""
import asyncio
import sys
sys.path.insert(0, r'{DEST_DIR}')
from consolidated_enhanced_ai import CascadeExcellenceSystem
system = CascadeExcellenceSystem()
asyncio.run(system.run())
        """)
          logger.info("GemAssist folder reorganization completed successfully.")
      except Exception as e:
          logger.error(f"GemAssist folder reorganization failed: {str(e)}")
if __name__ == "__main__":
    asyncio.run(reorganize_gemassist())