Proactive doctor, setup wizard, and TUI fixes
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 3s
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 3s
BREAKING CHANGES / KNOWN ISSUES:
- 8 skills have syntax errors causing loader warnings:
org-skill-bouncer, org-skill-config-manager, org-skill-credentials-vault,
org-skill-engineering-standards, org-skill-gardener, org-skill-homoiconic-memory,
org-skill-peripheral-vision, org-skill-policy
- These skills fail to load but don't block system operation
- TUI works despite these errors
FEATURES ADDED:
1. Proactive Doctor System
- Doctor runs automatically on daemon startup
- Health check runs before accepting connections
- Adds /health endpoint for health status queries
- *system-health* variable tracks: :healthy, :degraded, :unhealthy, :unknown
2. Error Handling (Option B - Debugger Hook)
- TUI and CLI now run doctor diagnostics on errors
- Shows "Run opencortex doctor" message on crash
- Suggests repair commands after failures
3. Interactive Setup Wizard (org-skill-config-manager)
- Full wizard implemented in config-manager skill:
* LLM provider configuration (OpenAI, Anthropic, OpenRouter, Groq, Gemini, Ollama)
* Gateway linking (Slack, Discord)
* Memory settings (auto-save interval, history retention)
* Network settings (timeout, proxy)
- Saves to ~/.config/opencortex/.env (KEY=VALUE format)
- CLI integration: opencortex setup, setup --add-provider, setup --link
4. CLI Enhancements
- doctor --watch: Background health monitoring (60s interval)
- doctor --fix: Interactive repair (falls back to full setup if core files missing)
- setup command runs wizard or delegates to setup_system
5. TUI Fixes
- Inlined message formatting to avoid dependency issues
- Added error handling in handle-return
- Cleaner error messages
6. Thin Harness Compliance
- Removed doctor from harness (now in org-skill-diagnostics skill)
- XDG directories: only .lisp in harness, .org kept in skills for loader
This commit is contained in:
248
opencortex.sh
248
opencortex.sh
@@ -32,6 +32,32 @@ if [ -f "$OC_CONFIG_DIR/.env" ]; then
|
||||
source "$OC_CONFIG_DIR/.env"
|
||||
fi
|
||||
|
||||
# --- Dependency Checker ---
|
||||
check_dependencies() {
|
||||
local missing=()
|
||||
for dep in sbcl emacs git curl socat nc; do
|
||||
if ! command_exists "$dep"; then
|
||||
missing+=("$dep")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#missing[@]} -gt 0 ]; then
|
||||
echo -e "${YELLOW}--- Missing dependencies: ${missing[*]} ---${NC}"
|
||||
if command_exists apt-get; then
|
||||
echo "Attempting to install missing dependencies..."
|
||||
if sudo apt-get update && sudo apt-get install -y sbcl emacs-nox rlwrap netcat-openbsd curl git socat libssl-dev libncurses-dev libffi-dev zlib1g-dev libsqlite3-dev 2>/dev/null; then
|
||||
echo -e "${GREEN}✓ Dependencies installed successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Could not install dependencies. Please run with sudo or install manually:${NC}"
|
||||
echo " sudo apt-get install sbcl emacs-nox rlwrap netcat-openbsd curl git socat"
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}✗ Cannot auto-install: apt-get not available${NC}"
|
||||
echo "Please install manually: sbcl emacs git curl socat netcat-openbsd"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# --- 2. SETUP ---
|
||||
setup_system() {
|
||||
NON_INTERACTIVE=false
|
||||
@@ -60,25 +86,32 @@ setup_system() {
|
||||
cp "$SCRIPT_DIR/opencortex.asd" "$OC_DATA_DIR/"
|
||||
cp "$SCRIPT_DIR/harness"/*.org "$OC_DATA_DIR/harness/"
|
||||
cp "$SCRIPT_DIR/skills"/*.org "$OC_DATA_DIR/skills/"
|
||||
|
||||
# Create tests directory before tangling (some org files write to tests/)
|
||||
mkdir -p "$OC_DATA_DIR/tests"
|
||||
|
||||
export INSTALL_DIR="$OC_DATA_DIR"
|
||||
|
||||
# Critical: Tangle manifest first to establish system structure (into root)
|
||||
echo "Tangling harness/manifest.org..."
|
||||
(cd "$OC_DATA_DIR" && emacs -Q --batch --eval "(require 'org)" --eval "(setq org-confirm-babel-evaluate nil)" --eval "(org-babel-tangle-file \"$OC_DATA_DIR/harness/manifest.org\")" >/dev/null 2>&1) || true
|
||||
(cd "$OC_DATA_DIR" && emacs -Q --batch --eval "(require 'org)" --eval "(setq org-confirm-babel-evaluate nil)" --eval "(org-babel-tangle-file \"harness/manifest.org\")") >/dev/null 2>&1 || true
|
||||
|
||||
# Tangle harness files into harness/
|
||||
for f in harness/*.org; do
|
||||
if [ "$f" != "harness/manifest.org" ]; then
|
||||
echo "Tangling $f..."
|
||||
(cd "$OC_DATA_DIR/harness" && emacs -Q --batch --eval "(require 'org)" --eval "(setq org-confirm-babel-evaluate nil)" --eval "(org-babel-tangle-file \"$OC_DATA_DIR/$f\")" >/dev/null 2>&1) || true
|
||||
for f in "$SCRIPT_DIR/harness"/*.org; do
|
||||
fname=$(basename "$f" .org)
|
||||
if [ "$fname" != "manifest" ]; then
|
||||
echo "Tangling harness/$fname.org..."
|
||||
(cd "$OC_DATA_DIR/harness" && emacs -Q --batch --eval "(require 'org)" --eval "(setq org-confirm-babel-evaluate nil)" --eval "(org-babel-tangle-file \"${fname}.org\")") >/dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
|
||||
# Tangle skill files into skills/
|
||||
for f in skills/*.org; do
|
||||
echo "Tangling $f..."
|
||||
(cd "$OC_DATA_DIR/skills" && emacs -Q --batch --eval "(require 'org)" --eval "(setq org-confirm-babel-evaluate nil)" --eval "(org-babel-tangle-file \"$OC_DATA_DIR/$f\")" >/dev/null 2>&1) || true
|
||||
for f in "$SCRIPT_DIR/skills"/*.org; do
|
||||
fname=$(basename "$f" .org)
|
||||
echo "Tangling skills/$fname.org..."
|
||||
# Copy org to XDG first (skills need to be loaded from XDG path)
|
||||
cp "$f" "$OC_DATA_DIR/skills/"
|
||||
(cd "$OC_DATA_DIR/skills" && emacs -Q --batch --eval "(require 'org)" --eval "(setq org-confirm-babel-evaluate nil)" --eval "(org-babel-tangle-file \"${fname}.org\")") >/dev/null 2>&1 || true
|
||||
done
|
||||
|
||||
# Special handling for tests that need to go into tests/
|
||||
@@ -88,6 +121,11 @@ setup_system() {
|
||||
|
||||
# Also move run-all-tests.lisp if it landed in the wrong place
|
||||
[ -f "$OC_DATA_DIR/run-all-tests.lisp" ] && mv "$OC_DATA_DIR/run-all-tests.lisp" "$OC_DATA_DIR/harness/"
|
||||
|
||||
# Cleanup: Remove .org files from XDG harness only (skills need .org for loader)
|
||||
echo "Cleaning up .org files from XDG harness..."
|
||||
rm -f "$OC_DATA_DIR/harness"/*.org
|
||||
|
||||
cd "$SCRIPT_DIR" # Create the bin shim
|
||||
echo -e "${YELLOW}--- Creating Bin Shim in $OC_BIN_DIR/opencortex ---${NC}"
|
||||
ln -sf "$SCRIPT_DIR/opencortex.sh" "$OC_BIN_DIR/opencortex"
|
||||
@@ -107,6 +145,66 @@ setup_system() {
|
||||
--eval '(funcall (find-symbol "RUN-SETUP-WIZARD" :opencortex))'
|
||||
}
|
||||
|
||||
# --- Doctor Repair (Lightweight Fix) ---
|
||||
doctor_repair() {
|
||||
echo -e "${BLUE}=== OpenCortex: Repair Mode ===${NC}"
|
||||
|
||||
# 1. Fix system dependencies
|
||||
echo -e "${YELLOW}--- Fixing System Dependencies ---${NC}"
|
||||
check_dependencies
|
||||
|
||||
# 2. Ensure XDG directories exist
|
||||
echo -e "${YELLOW}--- Fixing XDG Directories ---${NC}"
|
||||
mkdir -p "$OC_CONFIG_DIR" "$OC_DATA_DIR" "$OC_STATE_DIR" "$OC_BIN_DIR"
|
||||
mkdir -p "$OC_DATA_DIR/harness" "$OC_DATA_DIR/tests" "$OC_DATA_DIR/skills" "$OC_DATA_DIR/library"
|
||||
|
||||
# 3. Re-tangle harness files that may be broken
|
||||
echo -e "${YELLOW}--- Re-tangling Harness Files ---${NC}"
|
||||
for f in "$SCRIPT_DIR/harness"/*.org; do
|
||||
if [ -f "$f" ]; then
|
||||
fname=$(basename "$f" .org)
|
||||
echo " Checking harness/$fname..."
|
||||
# Try to load each harness file - if it fails, re-tangle
|
||||
if ! sbcl --non-interactive \
|
||||
--eval "(load \"$OC_DATA_DIR/harness/${fname}.lisp\")" \
|
||||
--eval "(format t \"OK~%\")" 2>/dev/null | grep -q "OK"; then
|
||||
echo " Re-tangling $fname.org..."
|
||||
(cd "$OC_DATA_DIR/harness" && emacs -Q --batch \
|
||||
--eval "(require 'org)" \
|
||||
--eval "(setq org-confirm-babel-evaluate nil)" \
|
||||
--eval "(org-babel-tangle-file \"$f\")" >/dev/null 2>&1) || true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# 4. Re-tangle skill files that may be broken
|
||||
echo -e "${YELLOW}--- Re-tangling Skill Files ---${NC}"
|
||||
for f in "$SCRIPT_DIR/skills"/*.org; do
|
||||
if [ -f "$f" ]; then
|
||||
fname=$(basename "$f" .org)
|
||||
echo " Checking skill/$fname..."
|
||||
# Copy .org to XDG temporarily for tangle, then remove
|
||||
cp "$f" "$OC_DATA_DIR/skills/"
|
||||
if ! sbcl --non-interactive \
|
||||
--eval "(load \"$OC_DATA_DIR/skills/${fname}.lisp\")" \
|
||||
--eval "(format t \"OK~%\")" 2>/dev/null | grep -q "OK"; then
|
||||
echo " Re-tangling $fname.org..."
|
||||
(cd "$OC_DATA_DIR/skills" && emacs -Q --batch \
|
||||
--eval "(require 'org)" \
|
||||
--eval "(setq org-confirm-babel-evaluate nil)" \
|
||||
--eval "(org-babel-tangle-file \"$OC_DATA_DIR/skills/${fname}.org\")" >/dev/null 2>&1) || true
|
||||
fi
|
||||
rm -f "$OC_DATA_DIR/skills/${fname}.org"
|
||||
fi
|
||||
done
|
||||
|
||||
# 5. Cleanup .org files
|
||||
rm -f "$OC_DATA_DIR/harness"/*.org "$OC_DATA_DIR/skills"/*.org 2>/dev/null || true
|
||||
|
||||
echo -e "${GREEN}--- Repair Complete ---${NC}"
|
||||
echo "Run 'opencortex doctor' to verify the system."
|
||||
}
|
||||
|
||||
# --- 3. COMMAND ROUTER ---
|
||||
COMMAND=$1
|
||||
[ -z "$COMMAND" ] && COMMAND="cli"
|
||||
@@ -116,23 +214,82 @@ case "$COMMAND" in
|
||||
link)
|
||||
PLATFORM=$1
|
||||
TOKEN=$2
|
||||
check_dependencies
|
||||
exec sbcl --non-interactive --eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' --eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" --eval '(ql:quickload :opencortex)' --eval '(opencortex:initialize-all-skills)' --eval "(funcall (find-symbol \"GATEWAY-MANAGER-MAIN\" :opencortex) \"$PLATFORM\" \"$TOKEN\")"
|
||||
;;
|
||||
|
||||
doctor)
|
||||
exec sbcl --non-interactive \
|
||||
--eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' \
|
||||
--eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" \
|
||||
--eval '(ql:quickload :opencortex)' \
|
||||
--eval '(opencortex:initialize-all-skills)' \
|
||||
--eval '(funcall (find-symbol "DOCTOR-MAIN" :opencortex))'
|
||||
check_dependencies
|
||||
if [ "$1" = "--watch" ]; then
|
||||
echo "Starting background health monitor (60s interval)..."
|
||||
echo "Press Ctrl+C to stop."
|
||||
echo ""
|
||||
while true; do
|
||||
echo "--- $(date '+%Y-%m-%d %H:%M:%S') ---"
|
||||
sbcl --non-interactive \
|
||||
--eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' \
|
||||
--eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" \
|
||||
--eval '(ql:quickload :opencortex)' \
|
||||
--eval '(opencortex:initialize-all-skills)' \
|
||||
--eval '(funcall (find-symbol "DOCTOR-RUN-ALL" :opencortex))' \
|
||||
--eval '(uiop:quit 0)' 2>&1 | grep -E "(HEALTH|OK|FAIL|WARN|SYSTEM|===)" || true
|
||||
sleep 60
|
||||
done
|
||||
elif [ "$1" = "--fix" ]; then
|
||||
# Check if major harness files exist - if not, run full setup
|
||||
if [ ! -f "$OC_DATA_DIR/harness/package.lisp" ] || [ ! -f "$OC_DATA_DIR/harness/skills.lisp" ]; then
|
||||
echo "Core files missing. Running full setup..."
|
||||
setup_system "$@"
|
||||
else
|
||||
echo "Repairing system..."
|
||||
doctor_repair
|
||||
fi
|
||||
else
|
||||
exec sbcl --non-interactive \
|
||||
--eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' \
|
||||
--eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" \
|
||||
--eval '(ql:quickload :opencortex)' \
|
||||
--eval '(opencortex:initialize-all-skills)' \
|
||||
--eval '(funcall (find-symbol "DOCTOR-MAIN" :opencortex))'
|
||||
fi
|
||||
;;
|
||||
|
||||
setup)
|
||||
setup_system "$@"
|
||||
check_dependencies
|
||||
if [ "$1" = "--add-provider" ]; then
|
||||
echo "Adding LLM provider..."
|
||||
sbcl --non-interactive \
|
||||
--eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' \
|
||||
--eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" \
|
||||
--eval '(ql:quickload :opencortex)' \
|
||||
--eval '(opencortex:initialize-all-skills)' \
|
||||
--eval '(funcall (find-symbol "SETUP-ADD-PROVIDER" :opencortex))'
|
||||
elif [ "$1" = "--link" ]; then
|
||||
PLATFORM=$2
|
||||
TOKEN=$3
|
||||
if [ -z "$PLATFORM" ] || [ -z "$TOKEN" ]; then
|
||||
echo "Usage: opencortex setup --link <platform> <token>"
|
||||
echo " platforms: slack, discord"
|
||||
exit 1
|
||||
fi
|
||||
echo "Linking $PLATFORM gateway..."
|
||||
$0 link "$PLATFORM" "$TOKEN"
|
||||
elif [ "$1" = "--non-interactive" ]; then
|
||||
setup_system "$@"
|
||||
else
|
||||
# Run interactive setup wizard
|
||||
echo "Starting interactive setup wizard..."
|
||||
sbcl --non-interactive \
|
||||
--eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' \
|
||||
--eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" \
|
||||
--eval '(ql:quickload :opencortex)' \
|
||||
--eval '(opencortex:initialize-all-skills)' \
|
||||
--eval '(funcall (find-symbol "RUN-SETUP-WIZARD" :opencortex))'
|
||||
fi
|
||||
;;
|
||||
|
||||
boot|--boot)
|
||||
check_dependencies
|
||||
exec sbcl --non-interactive \
|
||||
--eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' \
|
||||
--eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" \
|
||||
@@ -140,16 +297,71 @@ case "$COMMAND" in
|
||||
--eval '(opencortex:main)'
|
||||
;;
|
||||
|
||||
daemon)
|
||||
check_dependencies
|
||||
echo "Starting OpenCortex daemon in background..."
|
||||
nohup sbcl --non-interactive \
|
||||
--eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' \
|
||||
--eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" \
|
||||
--eval "(ql:quickload '(:opencortex :croatoan))" \
|
||||
--eval '(opencortex:main)' \
|
||||
> "$OC_STATE_DIR/daemon.log" 2>&1 &
|
||||
echo "Daemon started. Waiting for port 9105..."
|
||||
for i in {1..20}; do
|
||||
if ss -tln | grep -q 9105; then
|
||||
echo "✓ Daemon ready on port 9105"
|
||||
exit 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo "✗ Daemon failed to start. Check $OC_STATE_DIR/daemon.log"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
tui)
|
||||
exec sbcl \
|
||||
check_dependencies
|
||||
if ! ss -tln | grep -q 9105; then
|
||||
echo "Daemon not running. Starting daemon first..."
|
||||
$0 daemon
|
||||
fi
|
||||
if sbcl --non-interactive \
|
||||
--eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' \
|
||||
--eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" \
|
||||
--eval '(ql:quickload :opencortex/tui)' \
|
||||
--eval '(opencortex.tui:main)'
|
||||
--eval '(opencortex.tui:main)'; then
|
||||
true
|
||||
else
|
||||
EXIT_CODE=$?
|
||||
echo ""
|
||||
echo "TUI exited with error. Running diagnostics..."
|
||||
$0 doctor
|
||||
echo ""
|
||||
echo "Run 'opencortex doctor --fix' to repair, or 'opencortex setup' to reconfigure."
|
||||
exit $EXIT_CODE
|
||||
fi
|
||||
;;
|
||||
|
||||
cli|boot)
|
||||
check_dependencies
|
||||
if sbcl --non-interactive \
|
||||
--eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' \
|
||||
--eval "(push (truename \"$OC_DATA_DIR/\") asdf:*central-registry*)" \
|
||||
--eval "(ql:quickload '(:opencortex :croatoan))" \
|
||||
--eval '(opencortex:main)'; then
|
||||
true
|
||||
else
|
||||
EXIT_CODE=$?
|
||||
echo ""
|
||||
echo "CLI exited with error. Running diagnostics..."
|
||||
$0 doctor
|
||||
echo ""
|
||||
echo "Run 'opencortex doctor --fix' to repair, or 'opencortex setup' to reconfigure."
|
||||
exit $EXIT_CODE
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Available commands: setup, link, doctor, boot, tui"
|
||||
echo "Available commands: setup, link, doctor, boot, tui, cli, daemon"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user