fix(kernel): Definitive quote stripping and env detection
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
This commit is contained in:
42
fix_context.py
Normal file
42
fix_context.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
filepath = 'literate/context.org'
|
||||||
|
with open(filepath, 'r') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
out = []
|
||||||
|
skip = False
|
||||||
|
for line in lines:
|
||||||
|
if '(defun context-resolve-path (path-string)' in line:
|
||||||
|
out.append('(defun context-resolve-path (path-string)\n')
|
||||||
|
out.append(' "Expands environment variables and strips literal quotes from a path string."\n')
|
||||||
|
out.append(' (let ((path (if (stringp path-string) \n')
|
||||||
|
out.append(' (string-trim \'(#\\" #\\\' #\\Space) path-string)\n')
|
||||||
|
out.append(' path-string)))\n')
|
||||||
|
out.append(' (if (and (stringp path) (search "$" path))\n')
|
||||||
|
out.append(' (let ((result path))\n')
|
||||||
|
out.append(' (ppcre:do-register-groups (var-name) ("\\\\$([A-Za-z0-9_]+)" path)\n')
|
||||||
|
out.append(' (let ((var-val (uiop:getenv var-name)))\n')
|
||||||
|
out.append(' (when var-val\n')
|
||||||
|
out.append(' (setf result (ppcre:regex-replace (format nil "\\\\$~a" var-name) result var-val)))))\n')
|
||||||
|
out.append(' result)\n')
|
||||||
|
out.append(' path)))\n')
|
||||||
|
skip = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
if skip:
|
||||||
|
if 'path-string))' in line:
|
||||||
|
skip = False
|
||||||
|
continue
|
||||||
|
|
||||||
|
out.append(line)
|
||||||
|
|
||||||
|
with open(filepath, 'w') as f:
|
||||||
|
f.writelines(out)
|
||||||
|
|
||||||
|
# 2. Fix opencortex.sh
|
||||||
|
with open('opencortex.sh', 'r') as f:
|
||||||
|
sh = f.read()
|
||||||
|
sh = sh.replace('[ ! -f "$SCRIPT_DIR/.env" ]', '[ ! -f "$SCRIPT_DIR/.env" ] && [ ! -f "$HOME/.local/share/opencortex/.env" ]')
|
||||||
|
with open('opencortex.sh', 'w') as f:
|
||||||
|
f.write(sh)
|
||||||
@@ -179,8 +179,18 @@ A utility function that expands environment variables (like ~$HOME~ or ~$MEMEX_R
|
|||||||
|
|
||||||
#+begin_src lisp :tangle ../src/context.lisp
|
#+begin_src lisp :tangle ../src/context.lisp
|
||||||
(defun context-resolve-path (path-string)
|
(defun context-resolve-path (path-string)
|
||||||
"Expands all environment variables ($VAR) within a path string."
|
"Expands environment variables and strips literal quotes from a path string."
|
||||||
(if (and (stringp path-string) (search "$" path-string))
|
(let ((path (if (stringp path-string)
|
||||||
|
(string-trim '(#\" #\' #\Space) path-string)
|
||||||
|
path-string)))
|
||||||
|
(if (and (stringp path) (search "$" path))
|
||||||
|
(let ((result path))
|
||||||
|
(ppcre:do-register-groups (var-name) ("\\$([A-Za-z0-9_]+)" path)
|
||||||
|
(let ((var-val (uiop:getenv var-name)))
|
||||||
|
(when var-val
|
||||||
|
(setf result (ppcre:regex-replace (format nil "\\$~a" var-name) result var-val)))))
|
||||||
|
result)
|
||||||
|
path)))
|
||||||
(let ((result path-string))
|
(let ((result path-string))
|
||||||
(ppcre:do-register-groups (var-name) ("\\$([A-Za-z0-9_]+)" path-string)
|
(ppcre:do-register-groups (var-name) ("\\$([A-Za-z0-9_]+)" path-string)
|
||||||
(let ((var-val (uiop:getenv var-name)))
|
(let ((var-val (uiop:getenv var-name)))
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ setup_system() {
|
|||||||
|
|
||||||
echo -e "${YELLOW}--- Finalizing: Awakening the Brain as a background daemon ---${NC}"
|
echo -e "${YELLOW}--- Finalizing: Awakening the Brain as a background daemon ---${NC}"
|
||||||
> "$SCRIPT_DIR/brain.log"
|
> "$SCRIPT_DIR/brain.log"
|
||||||
bash "$SCRIPT_DIR/opencortex.sh" --boot > "$SCRIPT_DIR/brain.log" 2>&1 &
|
"$SCRIPT_DIR/opencortex.sh" --boot > "$SCRIPT_DIR/brain.log" 2>&1 &
|
||||||
|
|
||||||
local success=false
|
local success=false
|
||||||
for i in {1..30}; do
|
for i in {1..30}; do
|
||||||
@@ -157,7 +157,7 @@ setup_system() {
|
|||||||
COMMAND=${1:-"cli"}
|
COMMAND=${1:-"cli"}
|
||||||
|
|
||||||
# However, if the system is completely uninitialized, we force the 'setup' command.
|
# However, if the system is completely uninitialized, we force the 'setup' command.
|
||||||
if [ ! -f "$SCRIPT_DIR/src/package.lisp" ] || [ ! -f "$SCRIPT_DIR/.env" ]; then
|
if [ ! -f "$SCRIPT_DIR/src/package.lisp" ] || [ ! -f "$SCRIPT_DIR/.env" ] && [ ! -f "$HOME/.local/share/opencortex/.env" ]; then
|
||||||
COMMAND="setup"
|
COMMAND="setup"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -169,13 +169,13 @@ case "$COMMAND" in
|
|||||||
--boot|boot)
|
--boot|boot)
|
||||||
export SKILLS_DIR="${SCRIPT_DIR}/skills"
|
export SKILLS_DIR="${SCRIPT_DIR}/skills"
|
||||||
[ -z "$MEMEX_DIR" ] && export MEMEX_DIR="$HOME/memex"
|
[ -z "$MEMEX_DIR" ] && export MEMEX_DIR="$HOME/memex"
|
||||||
exec sbcl --disable-debugger --eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' --eval '(setf *debugger-hook* (lambda (c h) (declare (ignore h)) (format *error-output* "FATAL LISP ERROR: ~a~%" c) (uiop:print-backtrace :stream *error-output*) (uiop:quit 1)))' --eval '(push (truename (uiop:getenv "SCRIPT_DIR")) asdf:*central-registry*)' --eval '(format t "--- Quickloading OpenCortex ---~%")' --eval "(ql:quickload '(:opencortex :croatoan))" --eval '(opencortex:main)'
|
exec sbcl --eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' --eval '(setf *debugger-hook* (lambda (c h) (declare (ignore h)) (format *error-output* "FATAL LISP ERROR: ~a~%" c) (uiop:print-backtrace :stream *error-output*) (uiop:quit 1)))' --eval '(push (truename (uiop:getenv "SCRIPT_DIR")) asdf:*central-registry*)' --eval '(format t "--- Quickloading OpenCortex ---~%")' --eval "(ql:quickload '(:opencortex :croatoan))" --eval '(opencortex:main)'
|
||||||
;;
|
;;
|
||||||
|
|
||||||
tui)
|
tui)
|
||||||
if ! nc -z $HOST $PORT 2>/dev/null; then
|
if ! nc -z $HOST $PORT 2>/dev/null; then
|
||||||
echo -e "Brain is offline. Awakening..."
|
echo -e "Brain is offline. Awakening..."
|
||||||
bash "$SCRIPT_DIR/opencortex.sh" --boot > "$SCRIPT_DIR/brain.log" 2>&1 &
|
"$SCRIPT_DIR/opencortex.sh" --boot > "$SCRIPT_DIR/brain.log" 2>&1 &
|
||||||
for i in {1..15}; do
|
for i in {1..15}; do
|
||||||
sleep 2
|
sleep 2
|
||||||
if nc -z $HOST $PORT 2>/dev/null; then break; fi
|
if nc -z $HOST $PORT 2>/dev/null; then break; fi
|
||||||
@@ -186,13 +186,13 @@ case "$COMMAND" in
|
|||||||
echo -e "Launching Croatoan TUI..."
|
echo -e "Launching Croatoan TUI..."
|
||||||
export SKILLS_DIR="${SCRIPT_DIR}/skills"
|
export SKILLS_DIR="${SCRIPT_DIR}/skills"
|
||||||
[ -z "$MEMEX_DIR" ] && export MEMEX_DIR="$HOME/memex"
|
[ -z "$MEMEX_DIR" ] && export MEMEX_DIR="$HOME/memex"
|
||||||
exec sbcl --disable-debugger --eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' --eval '(push (truename (uiop:getenv "SCRIPT_DIR")) asdf:*central-registry*)' --eval '(ql:quickload :opencortex/tui)' --eval '(opencortex.tui:main)'
|
exec sbcl --eval '(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))' --eval '(push (truename (uiop:getenv "SCRIPT_DIR")) asdf:*central-registry*)' --eval '(ql:quickload :opencortex/tui)' --eval '(opencortex.tui:main)'
|
||||||
;;
|
;;
|
||||||
|
|
||||||
cli)
|
cli)
|
||||||
if ! nc -z $HOST $PORT 2>/dev/null; then
|
if ! nc -z $HOST $PORT 2>/dev/null; then
|
||||||
echo -e "Brain is offline. Awakening..."
|
echo -e "Brain is offline. Awakening..."
|
||||||
bash "$SCRIPT_DIR/opencortex.sh" --boot > "$SCRIPT_DIR/brain.log" 2>&1 &
|
"$SCRIPT_DIR/opencortex.sh" --boot > "$SCRIPT_DIR/brain.log" 2>&1 &
|
||||||
for i in {1..15}; do
|
for i in {1..15}; do
|
||||||
sleep 2
|
sleep 2
|
||||||
if nc -z $HOST $PORT 2>/dev/null; then break; fi
|
if nc -z $HOST $PORT 2>/dev/null; then break; fi
|
||||||
|
|||||||
@@ -91,8 +91,18 @@
|
|||||||
output))
|
output))
|
||||||
|
|
||||||
(defun context-resolve-path (path-string)
|
(defun context-resolve-path (path-string)
|
||||||
"Expands all environment variables ($VAR) within a path string."
|
"Expands environment variables and strips literal quotes from a path string."
|
||||||
(if (and (stringp path-string) (search "$" path-string))
|
(let ((path (if (stringp path-string)
|
||||||
|
(string-trim '(#\" #\' #\Space) path-string)
|
||||||
|
path-string)))
|
||||||
|
(if (and (stringp path) (search "$" path))
|
||||||
|
(let ((result path))
|
||||||
|
(ppcre:do-register-groups (var-name) ("\\$([A-Za-z0-9_]+)" path)
|
||||||
|
(let ((var-val (uiop:getenv var-name)))
|
||||||
|
(when var-val
|
||||||
|
(setf result (ppcre:regex-replace (format nil "\\$~a" var-name) result var-val)))))
|
||||||
|
result)
|
||||||
|
path)))
|
||||||
(let ((result path-string))
|
(let ((result path-string))
|
||||||
(ppcre:do-register-groups (var-name) ("\\$([A-Za-z0-9_]+)" path-string)
|
(ppcre:do-register-groups (var-name) ("\\$([A-Za-z0-9_]+)" path-string)
|
||||||
(let ((var-val (uiop:getenv var-name)))
|
(let ((var-val (uiop:getenv var-name)))
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
;; --- communication protocol ---
|
;; --- communication protocol ---
|
||||||
#:frame-message
|
#:frame-message
|
||||||
#:read-framed-message
|
#:read-framed-message
|
||||||
#:*VAULT-MEMORY*
|
|
||||||
#:COSINE-SIMILARITY
|
|
||||||
#:VAULT-MASK-STRING
|
|
||||||
#:parse-message
|
#:parse-message
|
||||||
#:make-hello-message
|
#:make-hello-message
|
||||||
#:validate-communication-protocol-schema
|
#:validate-communication-protocol-schema
|
||||||
|
|||||||
@@ -151,7 +151,7 @@
|
|||||||
(harness-log "HARNESS: Jailing skill '~a' in package ~a" skill-base-name pkg-name)
|
(harness-log "HARNESS: Jailing skill '~a' in package ~a" skill-base-name pkg-name)
|
||||||
(unless (find-package pkg-name)
|
(unless (find-package pkg-name)
|
||||||
(let ((new-pkg (make-package pkg-name :use '(:cl))))
|
(let ((new-pkg (make-package pkg-name :use '(:cl))))
|
||||||
(do-external-symbols (sym (find-package :opencortex)) (import sym new-pkg))))
|
(do-external-symbols (sym (find-package :opencortex)) (shadowing-import sym new-pkg))))
|
||||||
(let ((*read-eval* nil) (*package* (find-package pkg-name)))
|
(let ((*read-eval* nil) (*package* (find-package pkg-name)))
|
||||||
(eval (read-from-string (format nil "(progn ~a)" lisp-code))))
|
(eval (read-from-string (format nil "(progn ~a)" lisp-code))))
|
||||||
(setf (skill-entry-status entry) :ready)
|
(setf (skill-entry-status entry) :ready)
|
||||||
|
|||||||
Reference in New Issue
Block a user