# neurotron/vitalsigns_agent.py

from neurotron.neuron import Neuron
from neurotron.logbus import logbus

class VitalSigns(Neuron):
    name = "VitalSigns"

    def __init__(self, ctx):
        super().__init__(ctx)
        self.last = None

    def think(self):
        snap = self.ctx.perception.snapshot()

        cpu = snap.get("cpu_percent")
        mem = snap.get("mem_percent")
        load = snap.get("loadavg") or ["?", "?", "?"]

        cpu_str = f"{cpu}" if isinstance(cpu, (int, float)) else str(cpu)
        mem_str = f"{mem}" if isinstance(mem, (int, float)) else str(mem)
        load1 = load[0]

        msg = f"Vitals CPU={cpu_str}% MEM={mem_str}% load1={load1}"

        # evita spam
        if msg != self.last:
            logbus.debug(msg)
            self.last = msg

