From b562b25e9ab9fef1ca3898f690f90131283e890b Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Fri, 17 Apr 2026 17:00:53 -0400 Subject: [PATCH] fix: Robust brain health verification in setup and improved Lisp error logging --- literate/setup.org | 36 +++++++++++++++++++++++++++++++----- opencortex.sh | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/literate/setup.org b/literate/setup.org index 0625463..8757101 100644 --- a/literate/setup.org +++ b/literate/setup.org @@ -30,7 +30,7 @@ setup_system() { echo -e "${BLUE}=== OpenCortex: Initializing System ===${NC}" echo -e "${YELLOW}--- Installing System Dependencies ---${NC}" if command_exists apt-get; then - sudo apt-get update && sudo apt-get install -y sbcl emacs-nox rlwrap netcat-openbsd curl git socat + sudo apt-get update && sudo apt-get install -y sbcl emacs-nox rlwrap netcat-openbsd curl git socat libssl-dev libncurses5-dev fi if [ ! -d "$HOME/quicklisp" ]; then curl -O https://beta.quicklisp.org/quicklisp.lisp @@ -98,7 +98,32 @@ setup_system() { done mkdir -p "$HOME/.local/bin" ln -sf "$SCRIPT_DIR/opencortex.sh" "$HOME/.local/bin/opencortex" - echo -e "${GREEN}✓ Setup complete. You can now run 'opencortex tui'.${NC}" + + echo -e "${YELLOW}--- Finalizing: Awakening the Brain for the first time ---${NC}" + # Nuke any existing brain logs + > "$SCRIPT_DIR/brain.log" + "$SCRIPT_DIR/opencortex.sh" --boot > "$SCRIPT_DIR/brain.log" 2>&1 & + + local success=false + for i in {1..30}; do + if nc -z localhost $PORT 2>/dev/null; then + success=true + break + fi + sleep 2 + echo -n "." + done + + if [ "$success" = true ]; then + echo -e "\n${GREEN}✓ Brain is alive and responsive on port $PORT.${NC}" + echo -e "${GREEN}✓ Setup complete. You can now run 'opencortex tui'.${NC}" + else + echo -e "\n${RED}✗ Brain failed to wake up. Error Log from brain.log:${NC}" + cat "$SCRIPT_DIR/brain.log" + # Kill the background process if it exists + pkill -f "sbcl.*opencortex" || true + exit 1 + fi } if [ ! -f "$SCRIPT_DIR/src/package.lisp" ] || [ ! -f "$SCRIPT_DIR/.env" ]; then @@ -116,9 +141,10 @@ if [[ "$1" == "--boot" ]]; then done < "$SCRIPT_DIR/.env" fi exec sbcl --non-interactive \ - --eval "(load \"~/quicklisp/setup.lisp\")" \ - --eval "(push \"$SCRIPT_DIR/\" asdf:*central-registry*)" \ - --eval "(ql:quickload :opencortex)" \ + --eval "(load (merge-pathnames \"quicklisp/setup.lisp\" (user-homedir-pathname)))" \ + --eval "(setf *debugger-hook* (lambda (c h) (declare (ignore h)) (format t \"~a~%\" c) (uiop:quit 1)))" \ + --eval "(push (truename \"$SCRIPT_DIR/\") asdf:*central-registry*)" \ + --eval "(ql:quickload :opencortex :silent t)" \ --eval "(opencortex:main)" fi diff --git a/opencortex.sh b/opencortex.sh index 5e55d7a..bd8e107 100755 --- a/opencortex.sh +++ b/opencortex.sh @@ -21,7 +21,7 @@ setup_system() { echo -e "${BLUE}=== OpenCortex: Initializing System ===${NC}" echo -e "${YELLOW}--- Installing System Dependencies ---${NC}" if command_exists apt-get; then - sudo apt-get update && sudo apt-get install -y sbcl emacs-nox rlwrap netcat-openbsd curl git socat + sudo apt-get update && sudo apt-get install -y sbcl emacs-nox rlwrap netcat-openbsd curl git socat libssl-dev libncurses5-dev fi if [ ! -d "$HOME/quicklisp" ]; then curl -O https://beta.quicklisp.org/quicklisp.lisp @@ -89,7 +89,32 @@ setup_system() { done mkdir -p "$HOME/.local/bin" ln -sf "$SCRIPT_DIR/opencortex.sh" "$HOME/.local/bin/opencortex" - echo -e "${GREEN}✓ Setup complete. You can now run 'opencortex tui'.${NC}" + + echo -e "${YELLOW}--- Finalizing: Awakening the Brain for the first time ---${NC}" + # Nuke any existing brain logs + > "$SCRIPT_DIR/brain.log" + "$SCRIPT_DIR/opencortex.sh" --boot > "$SCRIPT_DIR/brain.log" 2>&1 & + + local success=false + for i in {1..30}; do + if nc -z localhost $PORT 2>/dev/null; then + success=true + break + fi + sleep 2 + echo -n "." + done + + if [ "$success" = true ]; then + echo -e "\n${GREEN}✓ Brain is alive and responsive on port $PORT.${NC}" + echo -e "${GREEN}✓ Setup complete. You can now run 'opencortex tui'.${NC}" + else + echo -e "\n${RED}✗ Brain failed to wake up. Error Log from brain.log:${NC}" + cat "$SCRIPT_DIR/brain.log" + # Kill the background process if it exists + pkill -f "sbcl.*opencortex" || true + exit 1 + fi } if [ ! -f "$SCRIPT_DIR/src/package.lisp" ] || [ ! -f "$SCRIPT_DIR/.env" ]; then @@ -107,9 +132,10 @@ if [[ "$1" == "--boot" ]]; then done < "$SCRIPT_DIR/.env" fi exec sbcl --non-interactive \ - --eval "(load \"~/quicklisp/setup.lisp\")" \ - --eval "(push \"$SCRIPT_DIR/\" asdf:*central-registry*)" \ - --eval "(ql:quickload :opencortex)" \ + --eval "(load (merge-pathnames \"quicklisp/setup.lisp\" (user-homedir-pathname)))" \ + --eval "(setf *debugger-hook* (lambda (c h) (declare (ignore h)) (format t \"~a~%\" c) (uiop:quit 1)))" \ + --eval "(push (truename \"$SCRIPT_DIR/\") asdf:*central-registry*)" \ + --eval "(ql:quickload :opencortex :silent t)" \ --eval "(opencortex:main)" fi