# .agent/tools/scaffold_maker.py import sys import os import json def create_structure(json_input): """Lê arquivo JSON e cria estrutura de pastas/arquivos.""" if not os.path.exists(json_input): return "❌ Arquivo JSON não encontrado." try: with open(json_input, 'r', encoding='utf-8') as f: structure = json.load(f) except Exception as e: return f"❌ Erro ao ler JSON: {e}" log = [] def build(base, items): for name, content in items.items(): path = os.path.join(base, name) if isinstance(content, dict): os.makedirs(path, exist_ok=True) log.append(f"📁 Pasta: {path}") build(path, content) elif isinstance(content, str): parent = os.path.dirname(path) if parent and not os.path.exists(parent): os.makedirs(parent, exist_ok=True) mode = 'w' if not os.path.exists(path) else 'w' # Sobrescreve se existir with open(path, mode, encoding='utf-8') as f: f.write(content) log.append(f"📄 Arquivo: {path}") try: build('.', structure) return "✅ Estrutura criada:\n" + "\n".join(log) except Exception as e: return f"❌ Falha: {e}" if __name__ == "__main__": if len(sys.argv) < 2: print("Uso: python scaffold_maker.py estrutura.json") else: print(create_structure(sys.argv[1]))