Auto-commit via make git (triggered by NFDOS)
This commit is contained in:
parent
b0cffc94c8
commit
88fc91b330
@ -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
|
||||
|
||||
@ -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
|
||||
5
src/neurotron/dashboard/panes/chat.py
Normal file
5
src/neurotron/dashboard/panes/chat.py
Normal file
@ -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)")
|
||||
6
src/neurotron/dashboard/panes/kernel.py
Normal file
6
src/neurotron/dashboard/panes/kernel.py
Normal file
@ -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)")
|
||||
5
src/neurotron/dashboard/panes/memory.py
Normal file
5
src/neurotron/dashboard/panes/memory.py
Normal file
@ -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)")
|
||||
18
src/neurotron/dashboard/panes/status.py
Normal file
18
src/neurotron/dashboard/panes/status.py
Normal file
@ -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]}")
|
||||
5
src/neurotron/dashboard/panes/trm.py
Normal file
5
src/neurotron/dashboard/panes/trm.py
Normal file
@ -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)")
|
||||
52
src/neurotron/dashboard/renderer.py
Normal file
52
src/neurotron/dashboard/renderer.py
Normal file
@ -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)
|
||||
Loading…
Reference in New Issue
Block a user