Compare commits

...

4 Commits

21 changed files with 124 additions and 114 deletions

View File

@ -60,7 +60,7 @@ git: check-remote
@git config user.email $(GIT_EMAIL)
@git rev-parse --abbrev-ref HEAD >/dev/null 2>&1 || true
@git add -A
@git commit -m "$(COMMIT_MSG)" || echo "Nenhuma modificação para commitar."
@git commit -m "$$(echo '$(COMMIT_MSG)')" || echo "Nenhuma modificação para commitar."
@git push $(GIT_REMOTE) $(GIT_BRANCH)
# ===========================

View File

@ -32,6 +32,6 @@ AM_PATH_PYTHON([3.0])
AC_CONFIG_FILES([
Makefile
src/Makefile
src/manager/Makefile
src/builder/Makefile
])
AC_OUTPUT

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
SUBDIRS = manager
SUBDIRS = builder
bin_SCRIPTS = neoricalex
CLEANFILES = $(bin_SCRIPTS)

View File

@ -15,25 +15,25 @@ class Application(object):
def run(self):
self._ensure_venv()
self.launch_welcome()
self.launch_neoricalex()
def _ensure_venv(self):
"""Cria e ativa o ambiente virtual, caso ainda não exista."""
"""Cria e ativa o ambiente Python, caso ainda não exista."""
base_path = Path(__file__).resolve().parents[1]
venv_path = base_path / "venv"
os.chdir(base_path)
if not venv_path.exists():
print("[+] Criando ambiente virtual...")
print("[+] Criando ambiente Python...")
subprocess.run([sys.executable, "-m", "venv", str(venv_path)], check=True)
else:
print("[=] Ambiente virtual já existente.")
print("[=] Ambiente Python já existente.")
def launch_welcome(self):
"""Lança o gestor de módulos."""
def launch_neoricalex(self):
"""Lança o neoricalex."""
base_path = Path(__file__).resolve().parent
manager = base_path / "manager" / "manager_main.py"
subprocess.run(["python3", str(manager)])
neoricalex = base_path / "builder" / "__main__.py"
subprocess.run(["python3", str(neoricalex)])

View File

@ -1,5 +1,5 @@
# ===========================
# Módulos Python do Manager
# Módulos Python do neoricalex
# ===========================
# Diretório de instalação Python
@ -7,10 +7,7 @@ neoricalexdir = $(pythondir)
# Fontes do manager
dist_neoricalex_PYTHON = \
manager_main.py \
manifest_parser.py \
module_loader.py \
tui_manager.py \
__main__.py \
__init__.py
# Inclui o bootstrap (nível acima) como parte deste pacote

31
src/builder/__main__.py Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
from core.agent import NeuronAgent
from system.env import ensure_ollama, ensure_ollama_serve, ensure_model
from system.requirements import ensure_requirements
def main():
print("🧠 NEORICALEX — Inicialização do neurónio cognitivo...\n")
# 1. Dependências Python
ensure_requirements()
# 2. Ollama
ensure_ollama()
# 3. Ollama serve
ensure_ollama_serve()
# 4. Modelo
ensure_model("deepseek-r1:1.5b")
# 5. Agente
agent = NeuronAgent(model="deepseek-r1:1.5b")
agent.run_once() # apenas um ciclo para checkpoint
if __name__ == "__main__":
main()

20
src/builder/core/agent.py Normal file
View File

@ -0,0 +1,20 @@
import subprocess
class NeuronAgent:
def __init__(self, model: str):
self.model = model
def run_once(self):
print("\n🧪 Teste cognitivo inicial\n")
prompt = "Hello DeepSeek. Identify yourself in one sentence."
result = subprocess.run(
["ollama", "run", self.model, prompt],
capture_output=True,
text=True,
)
print("🧠 Resposta do neurónio:\n")
print(result.stdout.strip())

View File

59
src/builder/system/env.py Normal file
View File

@ -0,0 +1,59 @@
import shutil
import subprocess
import threading
import time
def ensure_ollama():
if shutil.which("ollama"):
print("[=] Ollama encontrado.")
return
print("[+] Ollama não encontrado. A instalar...")
subprocess.run(
["bash", "-c", "curl -fsSL https://ollama.com/install.sh | sh"],
check=True
)
def _ollama_running():
try:
subprocess.run(
["ollama", "list"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
timeout=2,
)
return True
except Exception:
return False
def ensure_ollama_serve():
if _ollama_running():
print("[=] Ollama serve já ativo.")
return
print("[+] A iniciar ollama serve...")
def _serve():
subprocess.run(["ollama", "serve"])
t = threading.Thread(target=_serve, daemon=True)
t.start()
time.sleep(2)
def ensure_model(model):
result = subprocess.run(
["ollama", "list"],
capture_output=True,
text=True,
)
if model in result.stdout:
print(f"[=] Modelo {model} disponível.")
return
print(f"[+] A obter modelo {model}...")
subprocess.run(["ollama", "pull", model], check=True)

View File

View File

@ -1,81 +0,0 @@
from rich.console import Console
from rich.table import Table
from pathlib import Path
import os, subprocess, json
console = Console()
BASE_DIR = Path(__file__).resolve().parents[2]
MODULES_FILE = BASE_DIR / "src" / "modules.json"
MODULES_DIR = BASE_DIR / "src" / "modules"
def load_modules():
if MODULES_FILE.exists():
with open(MODULES_FILE) as f:
data = json.load(f)
return data.get("modules", [])
return []
def clone_module(mod):
path = Path(mod["path"])
if not path.exists():
console.print(f"[cyan]📦 Clonando {mod['name']}...[/cyan]")
subprocess.run(["git", "clone", mod["repo"], str(path)], check=True)
else:
console.print(f"[yellow]✔ {mod['name']} já existe localmente.[/yellow]")
def update_module(mod):
path = Path(mod["path"])
if path.exists():
console.print(f"[blue]🔄 Atualizando {mod['name']}...[/blue]")
subprocess.run(["git", "-C", str(path), "pull"], check=True)
else:
console.print(f"[red]⚠ Módulo {mod['name']} não encontrado![/red]")
def run_module(mod):
path = Path(mod["path"])
if not path.exists():
console.print(f"[red]❌ Módulo {mod['name']} não encontrado.[/red]")
return
console.print(f"[green]🚀 Executando {mod['name']}...[/green]")
subprocess.run(mod["entrypoint"], cwd=path, shell=True)
def menu():
modules = load_modules()
while True:
console.clear()
table = Table(title="NEORICALEX System Manager")
table.add_column("ID", justify="center")
table.add_column("Módulo")
table.add_column("Ação")
for i, mod in enumerate(modules, start=1):
table.add_row(str(i), mod["name"], mod["repo"])
table.add_row("0", "Sair", "")
console.print(table)
choice = console.input("[cyan]\nSelecione um módulo> [/cyan]")
if choice == "0":
break
if not choice.isdigit() or int(choice) > len(modules):
continue
mod = modules[int(choice)-1]
console.print(f"[bold yellow]Selecionado:[/bold yellow] {mod['name']}")
console.print("[1] Executar [2] Atualizar [3] Reinstalar [0] Voltar")
sub = console.input("[cyan]> [/cyan]")
if sub == "1":
run_module(mod)
elif sub == "2":
update_module(mod)
elif sub == "3":
if Path(mod["path"]).exists():
subprocess.run(["rm", "-rf", mod["path"]])
clone_module(mod)
else:
continue
if __name__ == "__main__":
os.makedirs(MODULES_DIR, exist_ok=True)
menu()

View File

@ -1,16 +0,0 @@
{
"modules": [
{
"name": "my_os",
"repo": "https://gitea.neoricalex.com/neo/my_os.git",
"path": "src/modules/my_os",
"entrypoint": "python3 tui/menu_main.py"
},
{
"name": "my_distro",
"repo": "https://gitea.neoricalex.com/neo/my_distro.git",
"path": "src/modules/my_distro",
"entrypoint": "bash build.sh"
}
]
}

View File

@ -6,6 +6,6 @@ sys.path.insert(1, '/usr/local/local/lib/python3.12/dist-packages')
from bootstrap import Application
if __name__ == "__main__":
app = Application(package="neoricalex", version="b6961cd-dirty")
app = Application(package="neoricalex", version="2dfd2c1-dirty-2-gb2f1b14-dirty")
app.run()

0
src/requirements.lock Normal file
View File