fix: Robust .env loader in entrypoint
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 4s

This commit is contained in:
2026-04-16 15:38:16 -04:00
parent 8ca8faf1de
commit 90ddcdff43
3 changed files with 28 additions and 76 deletions

View File

@@ -24,53 +24,47 @@ command_exists() { command -v "$1" >/dev/null 2>&1; }
# --- Bootstrap Mode --- # --- Bootstrap Mode ---
bootstrap_opencortex() { bootstrap_opencortex() {
echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}" echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}"
if [ -d ".git" ]; then if [ -d ".git" ]; then return; fi
return
fi
TARGET_DIR="opencortex" TARGET_DIR="opencortex"
if [ ! -d "$TARGET_DIR" ]; then if [ ! -d "$TARGET_DIR" ]; then
echo -e "${BLUE}Cloning repository into $TARGET_DIR...${NC}" echo -e "${BLUE}Cloning repository into $TARGET_DIR...${NC}"
git clone http://10.10.10.201:3001/amr/opencortex.git "$TARGET_DIR" git clone http://10.10.10.201:3001/amr/opencortex.git "$TARGET_DIR"
fi fi
cd "$TARGET_DIR" cd "$TARGET_DIR"
git submodule update --init --recursive git submodule update --init --recursive
echo -e "${GREEN}✓ Repository prepared.${NC}" echo -e "${GREEN}✓ Repository prepared.${NC}"
./scripts/onboard-baremetal.sh
if [ -t 0 ]; then
./scripts/onboard-baremetal.sh
else
./scripts/onboard-baremetal.sh < /dev/tty 2>/dev/null || ./scripts/onboard-baremetal.sh < /dev/null
fi
echo -e "${GREEN}✓ Setup phase complete.${NC}" echo -e "${GREEN}✓ Setup phase complete.${NC}"
exit 0 exit 0
} }
if [ ! -d ".git" ]; then if [ ! -d ".git" ]; then bootstrap_opencortex; fi
bootstrap_opencortex
# 1. Try to drop straight into the CLI chat
if command_exists socat && socat - TCP:$HOST:$PORT,connect-timeout=1 2>/dev/null; then
echo -e "${BLUE}Connected to autonomous brain at $HOST:$PORT...${NC}"
socat READLINE,history=$HOME/.org_agent_history TCP:$HOST:$PORT
exit 0
fi fi
# ... (Local Mode) # 2. Launch
if [ -f "opencortex.asd" ] || [ -d "literate" ]; then if [ -f "opencortex.asd" ]; then
if [ ! -f .env ]; then ./scripts/onboard-baremetal.sh; fi if [ -f .env ]; then
export SKILLS_DIR="$(grep "^SKILLS_DIR=" .env | cut -d"\"" -f2)" export \$(grep -v '^#' .env | xargs)
while read -r line; do if [[ ! "$line" =~ ^# ]] && [[ "$line" =~ = ]]; then export "$line"; fi; done < .env fi
echo -e "${BLUE}Starting OpenCortex via SBCL...${NC}" echo -e "${BLUE}Starting OpenCortex Brain...${NC}"
sbcl --non-interactive \ sbcl --non-interactive \
--eval "(load \"~/quicklisp/setup.lisp\")" \ --eval "(load \"~/quicklisp/setup.lisp\")" \
--eval "(push "$(pwd)/" asdf:*central-registry*) (ql:quickload :opencortex)" \ --eval "(push \"\$(pwd)/\" asdf:*central-registry*)" \
--eval "(ql:quickload :opencortex)" \
--eval "(opencortex:main)" --eval "(opencortex:main)"
fi fi
#+end_src #+end_src
* 2. The Baremetal Path (onboard-baremetal.sh) * 2. The Baremetal Path (onboard-baremetal.sh)
#+begin_src bash :tangle ../scripts/onboard-baremetal.sh :shebang "#!/bin/bash" #+begin_src bash :tangle ../scripts/onboard-baremetal.sh :shebang "#!/bin/bash"
# OpenCortex Final-Mile Installer (Bulletproof Edition) # OpenCortex Final-Mile Installer
RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[0;33m'; NC='\033[0m' RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[0;33m'; NC='\033[0m'
echo -e "${BLUE}=== OpenCortex: Baremetal Power-User Setup ===${NC}" echo -e "${BLUE}=== OpenCortex: Baremetal Power-User Setup ===${NC}"
prompt_user() { prompt_user() {
@@ -84,34 +78,22 @@ prompt_user() {
eval "$var_name=\"$val\"" eval "$var_name=\"$val\""
} }
# 1. Dependencies
if ! command -v sbcl >/dev/null 2>&1; then if ! command -v sbcl >/dev/null 2>&1; then
echo -e "${BLUE}Installing dependencies...${NC}"
sudo apt-get update && sudo apt-get install -y sbcl emacs git curl socat || true sudo apt-get update && sudo apt-get install -y sbcl emacs git curl socat || true
fi fi
# 2. Quicklisp
if [ ! -d "$HOME/quicklisp" ]; then if [ ! -d "$HOME/quicklisp" ]; then
curl -O https://beta.quicklisp.org/quicklisp.lisp curl -O https://beta.quicklisp.org/quicklisp.lisp
sbcl --non-interactive --load quicklisp.lisp --eval "(quicklisp-quickstart:install)" --eval "(ql-util:without-prompting (ql:add-to-init-file))" sbcl --non-interactive --load quicklisp.lisp --eval "(quicklisp-quickstart:install)" --eval "(ql-util:without-prompting (ql:add-to-init-file))"
rm quicklisp.lisp rm quicklisp.lisp
fi fi
# 3. Tangling
echo -e "${BLUE}Tangling source files...${NC}" echo -e "${BLUE}Tangling source files...${NC}"
mkdir -p src mkdir -p src
for f in literate/*.org; do for f in literate/*.org; do
echo " - Tangling $f"
emacs --batch --eval "(require 'org)" --eval "(org-babel-tangle-file \"$f\")" >/dev/null 2>&1 emacs --batch --eval "(require 'org)" --eval "(org-babel-tangle-file \"$f\")" >/dev/null 2>&1
done done
if [ -f "src/package.lisp" ]; then
echo -e "${GREEN}✓ Core tangled successfully.${NC}"
else
echo -e "${RED}✗ Tangle failed!${NC}"
fi
# 4. Config
if [ ! -f .env ]; then cp .env.example .env; fi if [ ! -f .env ]; then cp .env.example .env; fi
prompt_user "What is your name?" "User" "USER_NAME" prompt_user "What is your name?" "User" "USER_NAME"
prompt_user "What shall we name your Assistant?" "OpenCortex" "AGENT_NAME" prompt_user "What shall we name your Assistant?" "OpenCortex" "AGENT_NAME"
@@ -120,7 +102,6 @@ prompt_user "Select provider (1:Gemini, 2:OpenRouter)" "1" "LLM_CHOICE"
sed -i "s/MEMEX_USER=.*/MEMEX_USER=\"$USER_NAME\"/g" .env sed -i "s/MEMEX_USER=.*/MEMEX_USER=\"$USER_NAME\"/g" .env
sed -i "s/MEMEX_ASSISTANT=.*/MEMEX_ASSISTANT=\"$AGENT_NAME\"/g" .env sed -i "s/MEMEX_ASSISTANT=.*/MEMEX_ASSISTANT=\"$AGENT_NAME\"/g" .env
# Final Path Alignment
ROOT_DIR=$(pwd) ROOT_DIR=$(pwd)
sed -i "s|MEMEX_DIR=.*|MEMEX_DIR=\"$(dirname $ROOT_DIR)\"|g" .env sed -i "s|MEMEX_DIR=.*|MEMEX_DIR=\"$(dirname $ROOT_DIR)\"|g" .env
sed -i "s|SKILLS_DIR=.*|SKILLS_DIR=\"$ROOT_DIR/skills\"|g" .env sed -i "s|SKILLS_DIR=.*|SKILLS_DIR=\"$ROOT_DIR/skills\"|g" .env

View File

@@ -15,34 +15,21 @@ command_exists() { command -v "$1" >/dev/null 2>&1; }
# --- Bootstrap Mode --- # --- Bootstrap Mode ---
bootstrap_opencortex() { bootstrap_opencortex() {
echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}" echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}"
if [ -d ".git" ]; then if [ -d ".git" ]; then return; fi
return
fi
TARGET_DIR="opencortex" TARGET_DIR="opencortex"
if [ ! -d "$TARGET_DIR" ]; then if [ ! -d "$TARGET_DIR" ]; then
echo -e "${BLUE}Cloning repository into $TARGET_DIR...${NC}" echo -e "${BLUE}Cloning repository into $TARGET_DIR...${NC}"
git clone http://10.10.10.201:3001/amr/opencortex.git "$TARGET_DIR" git clone http://10.10.10.201:3001/amr/opencortex.git "$TARGET_DIR"
fi fi
cd "$TARGET_DIR" cd "$TARGET_DIR"
git submodule update --init --recursive git submodule update --init --recursive
echo -e "${GREEN}✓ Repository prepared.${NC}" echo -e "${GREEN}✓ Repository prepared.${NC}"
./scripts/onboard-baremetal.sh
if [ -t 0 ]; then
./scripts/onboard-baremetal.sh
else
./scripts/onboard-baremetal.sh < /dev/tty 2>/dev/null || ./scripts/onboard-baremetal.sh < /dev/null
fi
echo -e "${GREEN}✓ Setup phase complete.${NC}" echo -e "${GREEN}✓ Setup phase complete.${NC}"
exit 0 exit 0
} }
if [ ! -d ".git" ]; then if [ ! -d ".git" ]; then bootstrap_opencortex; fi
bootstrap_opencortex
fi
# 1. Try to drop straight into the CLI chat # 1. Try to drop straight into the CLI chat
if command_exists socat && socat - TCP:$HOST:$PORT,connect-timeout=1 2>/dev/null; then if command_exists socat && socat - TCP:$HOST:$PORT,connect-timeout=1 2>/dev/null; then
@@ -51,17 +38,15 @@ if command_exists socat && socat - TCP:$HOST:$PORT,connect-timeout=1 2>/dev/null
exit 0 exit 0
fi fi
# 2. Local repository detection and launch # 2. Launch
if [ -f "opencortex.asd" ] || [ -d "literate" ]; then if [ -f "opencortex.asd" ]; then
if [ ! -f .env ]; then if [ -f .env ]; then
./scripts/onboard-baremetal.sh export \$(grep -v '^#' .env | xargs)
fi fi
echo -e "${BLUE}Starting OpenCortex Brain...${NC}"
echo -e "${BLUE}Starting OpenCortex via SBCL...${NC}"
# EXPLICITLY push current directory to ASDF registry
sbcl --non-interactive \ sbcl --non-interactive \
--eval "(load \"~/quicklisp/setup.lisp\")" \ --eval "(load \"~/quicklisp/setup.lisp\")" \
--eval "(push \"$(pwd)/\" asdf:*central-registry*)" \ --eval "(push \"\$(pwd)/\" asdf:*central-registry*)" \
--eval "(ql:quickload :opencortex)" \ --eval "(ql:quickload :opencortex)" \
--eval "(opencortex:main)" --eval "(opencortex:main)"
fi fi

View File

@@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
# OpenCortex Final-Mile Installer (Bulletproof Edition) # OpenCortex Final-Mile Installer
RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[0;33m'; NC='\033[0m' RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[0;33m'; NC='\033[0m'
echo -e "${BLUE}=== OpenCortex: Baremetal Power-User Setup ===${NC}" echo -e "${BLUE}=== OpenCortex: Baremetal Power-User Setup ===${NC}"
prompt_user() { prompt_user() {
@@ -15,34 +14,22 @@ prompt_user() {
eval "$var_name=\"$val\"" eval "$var_name=\"$val\""
} }
# 1. Dependencies
if ! command -v sbcl >/dev/null 2>&1; then if ! command -v sbcl >/dev/null 2>&1; then
echo -e "${BLUE}Installing dependencies...${NC}"
sudo apt-get update && sudo apt-get install -y sbcl emacs git curl socat || true sudo apt-get update && sudo apt-get install -y sbcl emacs git curl socat || true
fi fi
# 2. Quicklisp
if [ ! -d "$HOME/quicklisp" ]; then if [ ! -d "$HOME/quicklisp" ]; then
curl -O https://beta.quicklisp.org/quicklisp.lisp curl -O https://beta.quicklisp.org/quicklisp.lisp
sbcl --non-interactive --load quicklisp.lisp --eval "(quicklisp-quickstart:install)" --eval "(ql-util:without-prompting (ql:add-to-init-file))" sbcl --non-interactive --load quicklisp.lisp --eval "(quicklisp-quickstart:install)" --eval "(ql-util:without-prompting (ql:add-to-init-file))"
rm quicklisp.lisp rm quicklisp.lisp
fi fi
# 3. Tangling
echo -e "${BLUE}Tangling source files...${NC}" echo -e "${BLUE}Tangling source files...${NC}"
mkdir -p src mkdir -p src
for f in literate/*.org; do for f in literate/*.org; do
echo " - Tangling $f"
emacs --batch --eval "(require 'org)" --eval "(org-babel-tangle-file \"$f\")" >/dev/null 2>&1 emacs --batch --eval "(require 'org)" --eval "(org-babel-tangle-file \"$f\")" >/dev/null 2>&1
done done
if [ -f "src/package.lisp" ]; then
echo -e "${GREEN}✓ Core tangled successfully.${NC}"
else
echo -e "${RED}✗ Tangle failed!${NC}"
fi
# 4. Config
if [ ! -f .env ]; then cp .env.example .env; fi if [ ! -f .env ]; then cp .env.example .env; fi
prompt_user "What is your name?" "User" "USER_NAME" prompt_user "What is your name?" "User" "USER_NAME"
prompt_user "What shall we name your Assistant?" "OpenCortex" "AGENT_NAME" prompt_user "What shall we name your Assistant?" "OpenCortex" "AGENT_NAME"
@@ -51,7 +38,6 @@ prompt_user "Select provider (1:Gemini, 2:OpenRouter)" "1" "LLM_CHOICE"
sed -i "s/MEMEX_USER=.*/MEMEX_USER=\"$USER_NAME\"/g" .env sed -i "s/MEMEX_USER=.*/MEMEX_USER=\"$USER_NAME\"/g" .env
sed -i "s/MEMEX_ASSISTANT=.*/MEMEX_ASSISTANT=\"$AGENT_NAME\"/g" .env sed -i "s/MEMEX_ASSISTANT=.*/MEMEX_ASSISTANT=\"$AGENT_NAME\"/g" .env
# Final Path Alignment
ROOT_DIR=$(pwd) ROOT_DIR=$(pwd)
sed -i "s|MEMEX_DIR=.*|MEMEX_DIR=\"$(dirname $ROOT_DIR)\"|g" .env sed -i "s|MEMEX_DIR=.*|MEMEX_DIR=\"$(dirname $ROOT_DIR)\"|g" .env
sed -i "s|SKILLS_DIR=.*|SKILLS_DIR=\"$ROOT_DIR/skills\"|g" .env sed -i "s|SKILLS_DIR=.*|SKILLS_DIR=\"$ROOT_DIR/skills\"|g" .env