From 88fc91b3309632adcecb6f25f71802903fdcc326 Mon Sep 17 00:00:00 2001 From: neoricalex Date: Fri, 26 Dec 2025 02:39:10 +0100 Subject: [PATCH] Auto-commit via make git (triggered by NFDOS) --- src/neurotron/__main__.py | 67 ++----------------------- src/neurotron/cortex.py | 27 ++++++++++ src/neurotron/dashboard/panes/chat.py | 5 ++ src/neurotron/dashboard/panes/kernel.py | 6 +++ src/neurotron/dashboard/panes/memory.py | 5 ++ src/neurotron/dashboard/panes/status.py | 18 +++++++ src/neurotron/dashboard/panes/trm.py | 5 ++ src/neurotron/dashboard/renderer.py | 52 +++++++++++++++++++ 8 files changed, 123 insertions(+), 62 deletions(-) create mode 100644 src/neurotron/dashboard/panes/chat.py create mode 100644 src/neurotron/dashboard/panes/kernel.py create mode 100644 src/neurotron/dashboard/panes/memory.py create mode 100644 src/neurotron/dashboard/panes/status.py create mode 100644 src/neurotron/dashboard/panes/trm.py create mode 100644 src/neurotron/dashboard/renderer.py diff --git a/src/neurotron/__main__.py b/src/neurotron/__main__.py index 6a1b70d..85b9c73 100644 --- a/src/neurotron/__main__.py +++ b/src/neurotron/__main__.py @@ -13,6 +13,7 @@ from pathlib import Path from neurotron.logbus import logbus from neurotron.cortex import Cortex +from neurotron.dashboard.renderer import Renderer # ============================================================================= @@ -20,69 +21,11 @@ from neurotron.cortex import Cortex # ============================================================================= def dashboard_loop(ctx: Cortex): - """ - Dashboard com scroll “real”. - Mantém: - - Linha 1: estado - - Linha 2: separador - - Linhas 3..102: janela de 100 linhas do logbus - """ - start = time.time() + renderer = Renderer() - MAX_LINES = 40 # janela visível - LOG_START_ROW = 3 # linha onde os logs começam - - # limpar ecrã e esconder cursor - sys.stdout.write("\033[2J\033[H\033[?25l") - sys.stdout.flush() - - try: - while True: - uptime = int(time.time() - start) - h = uptime // 3600 - m = (uptime % 3600) // 60 - s = uptime % 60 - - mode = (ctx.mode or "").upper() - tick = ctx.tick - - if mode == "PERSISTENT": - mode_str = "\033[1;34mPERSISTENT\033[0m" - elif mode == "DIAGNOSTIC": - mode_str = "\033[1;33mDIAGNOSTIC\033[0m" - else: - mode_str = mode - - header = ( - f"UP: {h:02}:{m:02}:{s:02} " - f"TICK: {tick:0.2f}s " - f"MODO: {mode_str}" - ) - - # Header - sys.stdout.write("\033[1;1H" + header + "\033[K") - sys.stdout.write("\033[2;1H" + "─" * 80 + "\033[K") - - # ---------------------------------------------- - # SCROLL WINDOW (esta é a magia ✨) - # ---------------------------------------------- - logs = logbus.tail(MAX_LINES) - row = LOG_START_ROW - - for line in logs: - truncated = line[:256] - sys.stdout.write(f"\033[{row};1H{truncated}\033[K") - row += 1 - - # Limpar linhas abaixo caso sobrem - # sys.stdout.write(f"\033[{row};1H\033[J") - # sys.stdout.flush() - - time.sleep(0.1) - - finally: - sys.stdout.write("\033[?25h") - sys.stdout.flush() + while True: + renderer.render(ctx) + time.sleep(0.1) # ============================================================================= # CICLO COGNITIVO diff --git a/src/neurotron/cortex.py b/src/neurotron/cortex.py index 7763211..d3b8199 100644 --- a/src/neurotron/cortex.py +++ b/src/neurotron/cortex.py @@ -259,4 +259,31 @@ class Cortex: def bus_consume(self, ch): q = self.bus[ch] return q.popleft() if q else None + + # ---------------------------------------- + # snapshot cognitivo (para dashboard / observadores) + # ---------------------------------------- + def cognitive_snapshot(self): + snap = { + "cog_state": "unknown", + "depth": 0, + "valence": 0.0, + "energy": None, + "trm_mode": "idle", + "system_mode": self.mode, + } + if self.trm: + try: + s = self.trm.state + snap.update({ + "cog_state": getattr(s, "cog_state", "unknown"), + "depth": getattr(s, "depth", 0), + "valence": getattr(s, "valence", 0.0), + "energy": getattr(s, "energy", None), + "trm_mode": getattr(s, "mode", "idle"), + }) + except Exception: + pass + + return snap \ No newline at end of file diff --git a/src/neurotron/dashboard/panes/chat.py b/src/neurotron/dashboard/panes/chat.py new file mode 100644 index 0000000..e6b2dbf --- /dev/null +++ b/src/neurotron/dashboard/panes/chat.py @@ -0,0 +1,5 @@ +import sys + +class ChatPane: + def render(self, ctx, x, y, w, h): + sys.stdout.write(f"\033[{y};{x}HCHAT MESSAGES (placeholder)") \ No newline at end of file diff --git a/src/neurotron/dashboard/panes/kernel.py b/src/neurotron/dashboard/panes/kernel.py new file mode 100644 index 0000000..fcbc201 --- /dev/null +++ b/src/neurotron/dashboard/panes/kernel.py @@ -0,0 +1,6 @@ +# panes/kernel.py +import sys + +class KernelPane: + def render(self, ctx, x, y, w, h): + sys.stdout.write(f"\033[{y};{x}HKERNEL MESSAGES (placeholder)") diff --git a/src/neurotron/dashboard/panes/memory.py b/src/neurotron/dashboard/panes/memory.py new file mode 100644 index 0000000..18b1440 --- /dev/null +++ b/src/neurotron/dashboard/panes/memory.py @@ -0,0 +1,5 @@ +import sys + +class MemoryPane: + def render(self, ctx, x, y, w, h): + sys.stdout.write(f"\033[{y};{x}HMEMORY MESSAGES (placeholder)") \ No newline at end of file diff --git a/src/neurotron/dashboard/panes/status.py b/src/neurotron/dashboard/panes/status.py new file mode 100644 index 0000000..342efe8 --- /dev/null +++ b/src/neurotron/dashboard/panes/status.py @@ -0,0 +1,18 @@ +# neurotron/dashboard/panes/status.py + +import sys + +class StatusPane: + def render(self, ctx, x, y, w, h): + snap = ctx.cognitive_snapshot() + + line1 = f"MODE: {snap['system_mode'].upper()} TRM: {snap['trm_mode'].upper()}" + line2 = ( + f"CogState: {snap['cog_state'].upper()} " + f"Depth: {snap['depth']} " + f"Valence: {snap['valence']:+.2f} " + f"Energy: {snap['energy']:.1f}" + ) + + sys.stdout.write(f"\033[{y};{x}H{line1[:w]}") + sys.stdout.write(f"\033[{y+1};{x}H{line2[:w]}") diff --git a/src/neurotron/dashboard/panes/trm.py b/src/neurotron/dashboard/panes/trm.py new file mode 100644 index 0000000..20f7970 --- /dev/null +++ b/src/neurotron/dashboard/panes/trm.py @@ -0,0 +1,5 @@ +import sys + +class TRMPane: + def render(self, ctx, x, y, w, h): + sys.stdout.write(f"\033[{y};{x}HTRM MESSAGES (placeholder)") \ No newline at end of file diff --git a/src/neurotron/dashboard/renderer.py b/src/neurotron/dashboard/renderer.py new file mode 100644 index 0000000..e620f01 --- /dev/null +++ b/src/neurotron/dashboard/renderer.py @@ -0,0 +1,52 @@ +# neurotron/dashboard/renderer.py + +import sys +import time + +from neurotron.dashboard.panes.status import StatusPane +from neurotron.dashboard.panes.kernel import KernelPane +from neurotron.dashboard.panes.memory import MemoryPane +from neurotron.dashboard.panes.trm import TRMPane +from neurotron.dashboard.panes.chat import ChatPane + + +class Renderer: + WIDTH = 80 + HEIGHT = 45 + + def __init__(self): + self.status = StatusPane() + self.kernel = KernelPane() + self.memory = MemoryPane() + self.trm = TRMPane() + self.chat = ChatPane() + + # limpar ecrã e esconder cursor + sys.stdout.write("\033[2J\033[H\033[?25l") + sys.stdout.flush() + + def render(self, ctx): + # HEADER + self.status.render(ctx, 1, 1, 80, 3) + + self._hline(4) + + # KERNEL + self.kernel.render(ctx, 1, 5, 80, 8) + self._hline(13) + + # NEUROTRON / MEMORY + self.memory.render(ctx, 1, 14, 80, 8) + self._hline(22) + + # TRM + self.trm.render(ctx, 1, 23, 80, 8) + self._hline(31) + + # CHAT + self.chat.render(ctx, 1, 32, 80, 12) + + sys.stdout.flush() + + def _hline(self, y): + sys.stdout.write(f"\033[{y};1H" + "─" * self.WIDTH)