fix(tui): Definitive syntax repair and case-insensitive handling
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 3s

This commit is contained in:
2026-04-19 18:37:15 -04:00
parent 21c2d4b8bb
commit e1ce366130
4 changed files with 91 additions and 7 deletions

48
fix_all.py Normal file
View File

@@ -0,0 +1,48 @@
import os, re
def rewrite_gateway():
path = 'skills/org-skill-llm-gateway.org'
with open(path, 'r') as f: content = f.read()
# Force OpenRouter as the only internal provider for auto-thoughts
content = content.replace(':openai', ':openrouter')
content = content.replace('openrouter/auto', 'google/gemini-2.0-flash-001')
with open(path, 'w') as f: f.write(content)
def rewrite_tui():
path = 'literate/tui-client.org'
# Complete, balanced listener that handles events, status, and chat
new_listener = """(defun listen-thread ()
(loop while *is-running* do
(handler-case
(when (and *stream* (open-stream-p *stream*))
(let ((raw-msg (opencortex:read-framed-message *stream*)))
(unless (member raw-msg '(:eof :error))
(let* ((msg (clean-keywords raw-msg))
(type (or (getf msg :TYPE) (getf msg :type)))
(payload (or (getf msg :PAYLOAD) (getf msg :payload))))
(cond ((eq type :EVENT)
(let ((action (or (getf payload :ACTION) (getf payload :action)))
(sensor (or (getf payload :SENSOR) (getf payload :sensor)))
(text (or (getf payload :TEXT) (getf payload :text) (getf payload :MESSAGE) (getf payload :message))))
(cond ((eq action :handshake) (setf *status-text* "Ready"))
(text (enqueue-msg (format nil "SYSTEM: ~a" text))))))
((eq type :STATUS)
(setf *status-text* (format nil "[Scribe: ~a] [Gardener: ~a]"
(or (getf msg :SCRIBE) (getf msg :scribe))
(or (getf msg :GARDENER) (getf msg :gardener)))))
((eq type :CHAT)
(enqueue-msg (or (getf msg :TEXT) (getf msg :text))))
(t (harness-log "TUI: Ignored unknown type ~a" type))))))
(when (eq raw-msg :eof) (setf *is-running* nil))
(when (eq raw-msg :error) (setf *status-text* "Protocol Error"))))
(error (c) (setf *status-text* (format nil "Net Error: ~a" c)) (setf *is-running* nil)))
(sleep 0.05)))"""
with open(path, 'r') as f: content = f.read()
# Replace the old listener function cleanly
content = re.sub(r'\(defun listen-thread \(.*?\)\)\)\)', new_listener, content, flags=re.DOTALL)
with open(path, 'w') as f: f.write(content)
rewrite_gateway()
rewrite_tui()
print("Rewrite complete.")

View File

@@ -54,7 +54,25 @@ The OpenCortex TUI Client is a standalone Common Lisp application built on **Cro
(let ((raw-msg (opencortex:read-framed-message *stream*)))
(unless (member raw-msg '(:eof :error))
(let* ((msg (clean-keywords raw-msg))
(type (or (getf msg :TYPE) (getf msg :type))))
(type (or (getf msg :TYPE) (getf msg :type)))
(payload (or (getf msg :PAYLOAD) (getf msg :payload))))
(cond ((eq type :EVENT)
(let ((action (or (getf payload :ACTION) (getf payload :action)))
(sensor (or (getf payload :SENSOR) (getf payload :sensor)))
(text (or (getf payload :TEXT) (getf payload :text) (getf payload :MESSAGE) (getf payload :message))))
(cond ((eq action :handshake) (setf *status-text* "Ready"))
(text (enqueue-msg (format nil "SYSTEM: ~a" text))))))
((eq type :STATUS)
(setf *status-text* (format nil "[Scribe: ~a] [Gardener: ~a]"
(or (getf msg :SCRIBE) (getf msg :scribe))
(or (getf msg :GARDENER) (getf msg :gardener)))))
((eq type :CHAT)
(enqueue-msg (or (getf msg :TEXT) (getf msg :text))))
(t (harness-log "TUI: Ignored unknown type ~a" type))))))
(when (eq raw-msg :eof) (setf *is-running* nil))
(when (eq raw-msg :error) (setf *status-text* "Protocol Error"))))
(error (c) (setf *status-text* (format nil "Net Error: ~a" c)) (setf *is-running* nil)))
(sleep 0.05)))
(cond ((eq type :EVENT)
(let ((payload (or (getf msg :PAYLOAD) (getf msg :payload))))
(when (eq (or (getf payload :ACTION) (getf payload :action)) :handshake)

View File

@@ -115,7 +115,7 @@ This is the primary actuator for neural reasoning. It handles the specific JSON
(:anthropic "https://api.anthropic.com/v1/messages")
(:gemini-api (format nil "https://generativelanguage.googleapis.com/v1/models/~a:generateContent" (or model "gemini-1.5-flash-latest")))
(:groq "https://api.groq.com/openai/v1/chat/completions")
(:openai "https://api.openai.com/v1/chat/completions")
(:openrouter "https://api.openai.com/v1/chat/completions")
(:openrouter "https://openrouter.ai/api/v1/chat/completions")))
(headers (case provider
(:anthropic `(("Content-Type" . "application/json") ("x-api-key" . ,api-key) ("anthropic-version" . "2023-06-01")))
@@ -126,7 +126,7 @@ This is the primary actuator for neural reasoning. It handles the specific JSON
(body (case provider
(:anthropic (cl-json:encode-json-to-string `((model . ,(or model "claude-3-5-sonnet-20240620")) (max_tokens . 4096) (system . ,system-prompt) (messages . (( (role . "user") (content . ,prompt) ))))))
(:gemini-api (cl-json:encode-json-to-string `((contents . (((parts . (((text . ,full-prompt))))))))))
(t (cl-json:encode-json-to-string `((model . ,(or model (case provider (:groq "llama-3.3-70b-versatile") (:openai "gpt-4o") (t "google/gemini-2.0-flash-001"))))
(t (cl-json:encode-json-to-string `((model . ,(or model (case provider (:groq "llama-3.3-70b-versatile") (:openrouter "gpt-4o") (t "google/gemini-2.0-flash-001"))))
(messages . (( (role . "system") (content . ,system-prompt) ) ( (role . "user") (content . ,prompt) )))))))))
(handler-case
(let* ((response (progn
@@ -154,7 +154,7 @@ Register the unified gateway as a cognitive tool.
"Queries an LLM provider via the unified gateway."
((:prompt :type :string :description "The user prompt.")
(:system-prompt :type :string :description "The system instructions.")
(:provider :type :keyword :description "The provider (e.g., :gemini-api, :anthropic, :groq, :openai, :openrouter, :ollama, :gemini-web).")
(:provider :type :keyword :description "The provider (e.g., :gemini-api, :anthropic, :groq, :openrouter, :openrouter, :ollama, :gemini-web).")
(:model :type :string :description "Optional specific model ID."))
:body (lambda (args)
(execute-llm-request (getf args :prompt)
@@ -167,7 +167,7 @@ Register each supported provider with the harness's neural registry.
#+begin_src lisp
(let* ((env-cascade (uiop:getenv "PROVIDER_CASCADE"))
(default-list '(:openrouter :openai :anthropic :groq :gemini-api :ollama))
(default-list '(:openrouter :openrouter :anthropic :groq :gemini-api :ollama))
(final-list (if (and env-cascade (not (string= env-cascade "")))
(mapcar (lambda (s) (intern (string-upcase (string-trim '(#\Space) s)) :keyword))
(uiop:split-string env-cascade :separator '(#\,)))
@@ -175,7 +175,7 @@ Register each supported provider with the harness's neural registry.
(setf opencortex::*provider-cascade* final-list)
(opencortex:harness-log "PROBABILISTIC: Neural Cascade Initialized -> ~a" final-list))
(dolist (p '(:anthropic :gemini-api :gemini-web :groq :ollama :openai :openrouter))
(dolist (p '(:anthropic :gemini-api :gemini-web :groq :ollama :openrouter :openrouter))
(opencortex:register-probabilistic-backend p (lambda (prompt system-prompt &key model)
(execute-llm-request prompt system-prompt :provider p :model model))))
#+end_src

View File

@@ -41,7 +41,25 @@
(let ((raw-msg (opencortex:read-framed-message *stream*)))
(unless (member raw-msg '(:eof :error))
(let* ((msg (clean-keywords raw-msg))
(type (or (getf msg :TYPE) (getf msg :type))))
(type (or (getf msg :TYPE) (getf msg :type)))
(payload (or (getf msg :PAYLOAD) (getf msg :payload))))
(cond ((eq type :EVENT)
(let ((action (or (getf payload :ACTION) (getf payload :action)))
(sensor (or (getf payload :SENSOR) (getf payload :sensor)))
(text (or (getf payload :TEXT) (getf payload :text) (getf payload :MESSAGE) (getf payload :message))))
(cond ((eq action :handshake) (setf *status-text* "Ready"))
(text (enqueue-msg (format nil "SYSTEM: ~a" text))))))
((eq type :STATUS)
(setf *status-text* (format nil "[Scribe: ~a] [Gardener: ~a]"
(or (getf msg :SCRIBE) (getf msg :scribe))
(or (getf msg :GARDENER) (getf msg :gardener)))))
((eq type :CHAT)
(enqueue-msg (or (getf msg :TEXT) (getf msg :text))))
(t (harness-log "TUI: Ignored unknown type ~a" type))))))
(when (eq raw-msg :eof) (setf *is-running* nil))
(when (eq raw-msg :error) (setf *status-text* "Protocol Error"))))
(error (c) (setf *status-text* (format nil "Net Error: ~a" c)) (setf *is-running* nil)))
(sleep 0.05)))
(cond ((eq type :EVENT)
(let ((payload (or (getf msg :PAYLOAD) (getf msg :payload))))
(when (eq (or (getf payload :ACTION) (getf payload :action)) :handshake)