diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..8de80b9 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include README.md +recursive-include src/neurotron *.py +recursive-include src/neurotron/data * \ No newline at end of file diff --git a/Setup.py b/Setup.py new file mode 100644 index 0000000..8799de1 --- /dev/null +++ b/Setup.py @@ -0,0 +1,6 @@ +from setuptools import setup + +setup( + package_dir={"": "src"}, + packages=["neurotron"], +) diff --git a/autom4te.cache/requests b/autom4te.cache/requests index 879a5d7..cbf639f 100644 --- a/autom4te.cache/requests +++ b/autom4te.cache/requests @@ -35,49 +35,49 @@ 'configure.ac' ], { - '_AM_DEPENDENCIES' => 1, - 'AM_PROG_INSTALL_STRIP' => 1, - 'include' => 1, - 'AM_SET_DEPDIR' => 1, - '_AC_AM_CONFIG_HEADER_HOOK' => 1, - 'AU_DEFUN' => 1, - '_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1, - 'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1, - 'AM_RUN_LOG' => 1, - 'AM_INIT_AUTOMAKE' => 1, - 'AM_SUBST_NOTMAKE' => 1, - '_AM_AUTOCONF_VERSION' => 1, - 'AM_CONDITIONAL' => 1, - 'AC_CONFIG_MACRO_DIR_TRACE' => 1, - 'AC_CONFIG_MACRO_DIR' => 1, - 'm4_include' => 1, + '_AM_SET_OPTIONS' => 1, + 'AM_MISSING_PROG' => 1, '_AM_IF_OPTION' => 1, - 'AM_PROG_CC_C_O' => 1, + 'AM_PROG_INSTALL_SH' => 1, + 'm4_pattern_forbid' => 1, + 'AM_SILENT_RULES' => 1, + '_AM_PROG_TAR' => 1, + 'AM_SET_LEADING_DOT' => 1, + 'AM_PROG_INSTALL_STRIP' => 1, + 'AM_AUTOMAKE_VERSION' => 1, + '_AM_SET_OPTION' => 1, '_AM_SUBST_NOTMAKE' => 1, 'AM_MISSING_HAS_RUN' => 1, - 'AM_SET_LEADING_DOT' => 1, - 'AC_DEFUN' => 1, - 'AC_DEFUN_ONCE' => 1, - 'AM_PATH_PYTHON' => 1, - 'AM_SILENT_RULES' => 1, - 'AM_AUX_DIR_EXPAND' => 1, - 'AM_DEP_TRACK' => 1, - '_AM_CONFIG_MACRO_DIRS' => 1, - 'AM_AUTOMAKE_VERSION' => 1, - '_m4_warn' => 1, + '_AM_AUTOCONF_VERSION' => 1, 'AM_SANITY_CHECK' => 1, - 'AM_OUTPUT_DEPENDENCY_COMMANDS' => 1, + 'AU_DEFUN' => 1, + '_AM_CONFIG_MACRO_DIRS' => 1, + 'AC_DEFUN_ONCE' => 1, + 'AM_AUX_DIR_EXPAND' => 1, + '_m4_warn' => 1, + '_AM_DEPENDENCIES' => 1, 'm4_pattern_allow' => 1, - '_AM_SET_OPTION' => 1, - 'AM_PROG_INSTALL_SH' => 1, - 'AM_MISSING_PROG' => 1, + 'AC_CONFIG_MACRO_DIR' => 1, + 'AM_CONDITIONAL' => 1, + 'AC_DEFUN' => 1, '_AM_PROG_CC_C_O' => 1, - 'AM_PYTHON_CHECK_VERSION' => 1, - '_AM_SET_OPTIONS' => 1, + 'AM_PROG_CC_C_O' => 1, + 'AM_OUTPUT_DEPENDENCY_COMMANDS' => 1, + 'AC_CONFIG_MACRO_DIR_TRACE' => 1, + '_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1, + '_AC_AM_CONFIG_HEADER_HOOK' => 1, '_AM_MANGLE_OPTION' => 1, + 'AM_SUBST_NOTMAKE' => 1, + 'AM_PATH_PYTHON' => 1, + 'AM_RUN_LOG' => 1, + 'AM_SET_DEPDIR' => 1, + 'include' => 1, 'AM_MAKE_INCLUDE' => 1, - 'm4_pattern_forbid' => 1, - '_AM_PROG_TAR' => 1 + 'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1, + 'm4_include' => 1, + 'AM_DEP_TRACK' => 1, + 'AM_INIT_AUTOMAKE' => 1, + 'AM_PYTHON_CHECK_VERSION' => 1 } ], 'Autom4te::Request' ), bless( [ @@ -92,65 +92,65 @@ 'configure.ac' ], { - 'm4_sinclude' => 1, + 'AM_MAKEFILE_INCLUDE' => 1, + 'AC_INIT' => 1, + '_AM_SUBST_NOTMAKE' => 1, + 'AM_AUTOMAKE_VERSION' => 1, + 'AC_LIBSOURCE' => 1, + '_m4_warn' => 1, + 'AC_CONFIG_SUBDIRS' => 1, + 'AM_PROG_F77_C_O' => 1, + 'AC_DEFINE_TRACE_LITERAL' => 1, + 'AC_CANONICAL_BUILD' => 1, + 'm4_pattern_allow' => 1, + 'AM_POT_TOOLS' => 1, + 'AC_CONFIG_FILES' => 1, + 'AM_GNU_GETTEXT_INTL_SUBDIR' => 1, + 'AC_CANONICAL_SYSTEM' => 1, + 'AC_FC_SRCEXT' => 1, + 'AM_XGETTEXT_OPTION' => 1, + 'LT_INIT' => 1, + 'AM_CONDITIONAL' => 1, + '_AM_COND_ELSE' => 1, + 'AC_FC_PP_SRCEXT' => 1, + '_LT_AC_TAGCONFIG' => 1, + '_AM_COND_IF' => 1, + '_AM_MAKEFILE_INCLUDE' => 1, + 'AM_PROG_CC_C_O' => 1, + 'AC_FC_FREEFORM' => 1, + 'LT_CONFIG_LTDL_DIR' => 1, 'AM_INIT_AUTOMAKE' => 1, - 'AC_CANONICAL_HOST' => 1, + 'm4_include' => 1, + 'AC_CONFIG_AUX_DIR' => 1, + 'include' => 1, + 'AC_SUBST_TRACE' => 1, + '_AM_COND_ENDIF' => 1, + 'AM_SILENT_RULES' => 1, + 'm4_pattern_forbid' => 1, + 'AC_CANONICAL_TARGET' => 1, + 'AC_CONFIG_LIBOBJ_DIR' => 1, + 'm4_sinclude' => 1, + 'AM_GNU_GETTEXT' => 1, + 'AC_CONFIG_HEADERS' => 1, + 'AM_PROG_CXX_C_O' => 1, + 'AM_MAINTAINER_MODE' => 1, + 'AM_PROG_AR' => 1, + 'AM_EXTRA_RECURSIVE_TARGETS' => 1, 'AH_OUTPUT' => 1, 'AM_NLS' => 1, - '_AM_MAKEFILE_INCLUDE' => 1, - 'include' => 1, - 'AM_GNU_GETTEXT_INTL_SUBDIR' => 1, - 'AM_XGETTEXT_OPTION' => 1, 'AM_PROG_MKDIR_P' => 1, - 'LT_SUPPORTED_TAG' => 1, - 'AC_CONFIG_AUX_DIR' => 1, - '_AM_COND_ENDIF' => 1, - 'AM_PATH_GUILE' => 1, - 'AM_PROG_CC_C_O' => 1, - 'AM_CONDITIONAL' => 1, - 'm4_include' => 1, - 'LT_INIT' => 1, - 'AM_MAINTAINER_MODE' => 1, - 'AC_CANONICAL_TARGET' => 1, - 'AC_INIT' => 1, - '_AM_COND_ELSE' => 1, - '_m4_warn' => 1, - 'AM_ENABLE_MULTILIB' => 1, - 'AM_SILENT_RULES' => 1, - 'AM_PROG_AR' => 1, - 'AM_PROG_F77_C_O' => 1, - 'AC_CONFIG_LINKS' => 1, - '_AM_SUBST_NOTMAKE' => 1, - 'AC_FC_FREEFORM' => 1, - 'm4_pattern_forbid' => 1, - 'AC_CONFIG_SUBDIRS' => 1, - 'AC_FC_SRCEXT' => 1, - '_AM_COND_IF' => 1, - 'AM_PROG_FC_C_O' => 1, - 'AC_SUBST_TRACE' => 1, 'sinclude' => 1, - 'LT_CONFIG_LTDL_DIR' => 1, - '_LT_AC_TAGCONFIG' => 1, - 'AC_CONFIG_HEADERS' => 1, - 'AC_FC_PP_SRCEXT' => 1, - 'AC_DEFINE_TRACE_LITERAL' => 1, - 'AM_POT_TOOLS' => 1, - 'AC_FC_PP_DEFINE' => 1, - 'AC_CANONICAL_BUILD' => 1, - 'AM_AUTOMAKE_VERSION' => 1, - 'AC_CONFIG_FILES' => 1, - 'AC_CONFIG_LIBOBJ_DIR' => 1, - 'AC_REQUIRE_AUX_FILE' => 1, - 'AC_LIBSOURCE' => 1, + 'AC_CANONICAL_HOST' => 1, + 'AM_PATH_GUILE' => 1, 'AC_PROG_LIBTOOL' => 1, - 'AC_CANONICAL_SYSTEM' => 1, - 'AM_PROG_CXX_C_O' => 1, 'AC_SUBST' => 1, - 'AM_EXTRA_RECURSIVE_TARGETS' => 1, - 'm4_pattern_allow' => 1, - 'AM_MAKEFILE_INCLUDE' => 1, - 'AM_GNU_GETTEXT' => 1, - 'AM_PROG_MOC' => 1 + 'AC_CONFIG_LINKS' => 1, + 'AM_ENABLE_MULTILIB' => 1, + 'AC_REQUIRE_AUX_FILE' => 1, + 'AC_FC_PP_DEFINE' => 1, + 'LT_SUPPORTED_TAG' => 1, + 'AM_PROG_MOC' => 1, + 'AM_PROG_FC_C_O' => 1 } ], 'Autom4te::Request' ) ); diff --git a/neurotron b/neurotron index e3cff04..ede0585 100755 --- a/neurotron +++ b/neurotron @@ -1,7 +1,14 @@ #!/bin/sh -# Neurotron launcher - autogerado pelo autotools -NEUROTRON_HOME="/usr/lib/neurotron" -PYTHON="/usr/bin/python" +PYTHON="/usr/bin/python3" +NEUROTRON_HOME="/opt/kernel/neurotron" +SRC="$NEUROTRON_HOME/src" -exec "$PYTHON" "$NEUROTRON_HOME/src/__main__.py" "$@" +export PYTHONHOME="/usr" +export PYTHONPATH="$SRC:/usr/lib/python3.13:/usr/lib/python3.13/site-packages" + +# Inicializar hipocampo físico como módulo do package +"$PYTHON" -m neurotron.disk_init + +# Arrancar o cérebro principal como módulo do package +exec "$PYTHON" -m neurotron "$@" \ No newline at end of file diff --git a/neurotron.in b/neurotron.in index 337b782..ede0585 100644 --- a/neurotron.in +++ b/neurotron.in @@ -1,7 +1,14 @@ #!/bin/sh -# Neurotron launcher - autogerado pelo autotools -NEUROTRON_HOME="@NEUROTRON_DIR@" -PYTHON="@PYTHON@" +PYTHON="/usr/bin/python3" +NEUROTRON_HOME="/opt/kernel/neurotron" +SRC="$NEUROTRON_HOME/src" -exec "$PYTHON" "$NEUROTRON_HOME/src/__main__.py" "$@" +export PYTHONHOME="/usr" +export PYTHONPATH="$SRC:/usr/lib/python3.13:/usr/lib/python3.13/site-packages" + +# Inicializar hipocampo físico como módulo do package +"$PYTHON" -m neurotron.disk_init + +# Arrancar o cérebro principal como módulo do package +exec "$PYTHON" -m neurotron "$@" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c9961a5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,19 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "neurotron" +version = "0.2.0" +description = "Neurotron — Kernel Cognitivo do NFDOS" +authors = [{ name = "Neo & Trinity" }] +readme = "README.md" +requires-python = ">=3.10" + +dependencies = [ + "rich>=13.0" +] + +[project.scripts] +neurotron = "neurotron.__main__:main" +neurotron-disk-init = "neurotron.disk_init:initialize_persistence" diff --git a/src/__init__.py b/src/neurotron/__init__.py similarity index 100% rename from src/__init__.py rename to src/neurotron/__init__.py diff --git a/src/__main__.py b/src/neurotron/__main__.py similarity index 93% rename from src/__main__.py rename to src/neurotron/__main__.py index 74276c0..33605ca 100644 --- a/src/__main__.py +++ b/src/neurotron/__main__.py @@ -287,13 +287,26 @@ class NeurotronDashboard: def _draw_footer(self, width, height): """ Rodapé com placeholder para input futuro e legenda de teclas. + Protegido contra terminais muito pequenos. """ footer_text = "[ Futuro: comandos do utilizador aparecerão aqui ]" keys_text = "[q] sair | dashboard Neurotron" - y_footer = height - 2 - self.stdscr.addnstr(y_footer, 0, footer_text.ljust(width), width) - self.stdscr.addnstr(y_footer + 1, 0, keys_text.ljust(width), width) + lines = [footer_text, keys_text] + footer_lines = len(lines) + + # Se o terminal for demasiado pequeno, encolhe ou só mostra o essencial + start_row = max(0, height - footer_lines) + + for i, text in enumerate(lines): + y = start_row + i + if 0 <= y < height: + try: + self.stdscr.addnstr(y, 0, text.ljust(width), width) + except curses.error: + # Em última instância, ignoramos erros de desenho + pass + # ------------------------------------------------------------------ # Loop principal da UI @@ -315,9 +328,13 @@ class NeurotronDashboard: header_height = 2 footer_height = 2 - self._draw_header(height, width) - self._draw_log_window(header_height, footer_height, width, height) - self._draw_footer(width, height) + try: + self._draw_header(height, width) + self._draw_log_window(header_height, footer_height, width, height) + self._draw_footer(width, height) + except curses.error: + # Em terminais muito pequenos ou estados estranhos, evitamos crash + pass self.stdscr.refresh() @@ -389,7 +406,7 @@ def cognitive_loop(cortex: Cortex, ui: NeurotronDashboard): try: cortex.fatal(e) finally: - break + ui.stop_event.set() finally: ui.stop_event.set() diff --git a/src/autodiagnostic.py b/src/neurotron/autodiagnostic.py similarity index 100% rename from src/autodiagnostic.py rename to src/neurotron/autodiagnostic.py diff --git a/src/cortex.py b/src/neurotron/cortex.py similarity index 96% rename from src/cortex.py rename to src/neurotron/cortex.py index 8102e77..acc4510 100644 --- a/src/cortex.py +++ b/src/neurotron/cortex.py @@ -5,10 +5,10 @@ from pathlib import Path from time import sleep from rich.console import Console -from neuron import Neuron -from hippocampus import Hippocampus -from perception import Perception -from motor import Motor +from .neuron import Neuron +from .hippocampus import Hippocampus +from .perception import Perception +from .motor import Motor from .neurotron_config import ( NEUROTRON_MODE, NEUROTRON_TICK, NEUROTRON_TICK_MIN, NEUROTRON_TICK_MAX, NEUROTRON_TICK_STEP, @@ -78,8 +78,8 @@ class Cortex: self.console.print("[bold cyan]🧠 Neurotron[/] — boot") self.memory.remember("boot", {"version": "0.1", "tick": self.tick}) self._booted = True - state, _ = self.diagnostic.run_exam() - self._apply_homeostasis(state) + #state, _ = self.diagnostic.run_exam() + #self._apply_homeostasis(state) def _apply_homeostasis(self, state): if state == "CRITICAL": @@ -131,8 +131,9 @@ class Cortex: self._tick_count += 1 if self._tick_count % NEUROTRON_DIAG_EVERY_TICKS == 0: - state, _ = self.diagnostic.run_exam() - self._apply_homeostasis(state) + #state, _ = self.diagnostic.run_exam() + #self._apply_homeostasis(state) + pass if self._tick_count % TELEMETRY_FLUSH_EVERY_TICKS == 0: self._flush_telemetry() diff --git a/src/disk_init.py b/src/neurotron/disk_init.py similarity index 97% rename from src/disk_init.py rename to src/neurotron/disk_init.py index 13683ab..c973822 100644 --- a/src/disk_init.py +++ b/src/neurotron/disk_init.py @@ -12,13 +12,8 @@ import os import subprocess from pathlib import Path from rich.console import Console -if __name__ == "__main__" and __package__ is None: - import sys - from pathlib import Path - sys.path.append(str(Path(__file__).resolve().parents[1])) - __package__ = "neurotron_core" -from .neurotron_config import ( +from neurotron.neurotron_config import ( MOUNT_POINT, DISK_CANDIDATES ) diff --git a/src/hippocampus.py b/src/neurotron/hippocampus.py similarity index 100% rename from src/hippocampus.py rename to src/neurotron/hippocampus.py diff --git a/src/main_waiting.py b/src/neurotron/main_waiting.py similarity index 100% rename from src/main_waiting.py rename to src/neurotron/main_waiting.py diff --git a/src/motor.py b/src/neurotron/motor.py similarity index 100% rename from src/motor.py rename to src/neurotron/motor.py diff --git a/src/neuron.py b/src/neurotron/neuron.py similarity index 100% rename from src/neuron.py rename to src/neurotron/neuron.py diff --git a/src/neurotron_config.py b/src/neurotron/neurotron_config.py similarity index 100% rename from src/neurotron_config.py rename to src/neurotron/neurotron_config.py diff --git a/src/perception.py b/src/neurotron/perception.py similarity index 100% rename from src/perception.py rename to src/neurotron/perception.py diff --git a/src/telemetry_tail.py b/src/neurotron/telemetry_tail.py similarity index 100% rename from src/telemetry_tail.py rename to src/neurotron/telemetry_tail.py