RELEASE: Finalize Semantic Restructuring v0.1.0
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
- Folders: literate->harness, src->library, system->environment, scripts->interfaces. - Synchronized all :tangle paths and system definitions. - Hardened .gitignore for binary and log artifacts. - Consolidated all documentation into docs/.
This commit is contained in:
BIN
interfaces/__pycache__/ui_driver.cpython-313.pyc
Normal file
BIN
interfaces/__pycache__/ui_driver.cpython-313.pyc
Normal file
Binary file not shown.
54
interfaces/browser-bridge.py
Normal file
54
interfaces/browser-bridge.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import json
|
||||
import base64
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
def run_bridge():
|
||||
# Read command from stdin
|
||||
try:
|
||||
raw_input = sys.stdin.read()
|
||||
if not raw_input:
|
||||
print(json.dumps({"status": "error", "message": "No input provided"}))
|
||||
return
|
||||
|
||||
args = json.loads(raw_input)
|
||||
except Exception as e:
|
||||
print(json.dumps({"status": "error", "message": f"Invalid JSON input: {str(e)}"}))
|
||||
return
|
||||
|
||||
url = args.get("url")
|
||||
action = args.get("action", "extract_text")
|
||||
selector = args.get("selector", "body")
|
||||
|
||||
if not url:
|
||||
print(json.dumps({"status": "error", "message": "No URL provided"}))
|
||||
return
|
||||
|
||||
try:
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
page = browser.new_page()
|
||||
|
||||
# Navigate and wait for network to be idle
|
||||
page.goto(url, wait_until="networkidle")
|
||||
|
||||
result = {"status": "success", "url": url}
|
||||
|
||||
if action == "extract_text":
|
||||
result["content"] = page.inner_text(selector)
|
||||
elif action == "screenshot":
|
||||
screenshot_bytes = page.screenshot()
|
||||
result["screenshot_base64"] = base64.b64encode(screenshot_bytes).decode("utf-8")
|
||||
else:
|
||||
result["status"] = "error"
|
||||
result["message"] = f"Unknown action: {action}"
|
||||
|
||||
browser.close()
|
||||
print(json.dumps(result))
|
||||
|
||||
except Exception as e:
|
||||
print(json.dumps({"status": "error", "message": f"Playwright Error: {str(e)}"}))
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_bridge()
|
||||
39
interfaces/opencortex-chat.sh
Executable file
39
interfaces/opencortex-chat.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
# opencortex-chat: The terminal mouthpiece for the Autonomous Brain.
|
||||
PORT=9105
|
||||
HOST=${1:-localhost}
|
||||
|
||||
# Check for socat (preferred)
|
||||
if command -v socat >/dev/null 2>&1; then
|
||||
# Use socat with READLINE for history and arrow-key support.
|
||||
# It establishes a persistent bidirectional connection.
|
||||
# Note: socat READLINE doesn't handle hex-length framing automatically for input.
|
||||
# We use a wrapper to frame the message.
|
||||
|
||||
echo "Connected to OpenCortex on $HOST:$PORT (Channel: CLI)"
|
||||
while true; do
|
||||
read -p "User: " MESSAGE
|
||||
if [ -z "$MESSAGE" ]; then continue; fi
|
||||
if [ "$MESSAGE" = "/exit" ]; then break; fi
|
||||
|
||||
# Frame the message: (:TYPE :EVENT :META (:SOURCE :CLI) :PAYLOAD (:SENSOR :USER-INPUT :TEXT "msg"))
|
||||
PAYLOAD="(:TYPE :EVENT :META (:SOURCE :CLI) :PAYLOAD (:SENSOR :USER-INPUT :TEXT \"$MESSAGE\"))"
|
||||
LEN=$(printf "%s" "$PAYLOAD" | wc -c)
|
||||
HEXLEN=$(printf "%06x" $LEN)
|
||||
|
||||
# Send and read response
|
||||
(printf "%s%s" "$HEXLEN" "$PAYLOAD" | nc -N $HOST $PORT) | while read -r LINE; do
|
||||
# The line will have the 6-char hex length prefix.
|
||||
# We strip it and look for the response.
|
||||
CLEAN=$(echo "$LINE" | sed 's/^......//')
|
||||
if [[ "$CLEAN" == *":TEXT"* ]]; then
|
||||
# Extract the text content (simple grep-like extraction for CLI fallback)
|
||||
TEXT=$(echo "$CLEAN" | sed -n 's/.*:TEXT "\([^"]*\)".*/\1/p')
|
||||
echo "Agent: $TEXT"
|
||||
fi
|
||||
done
|
||||
done
|
||||
else
|
||||
echo "Error: socat or nc required."
|
||||
exit 1
|
||||
fi
|
||||
85
interfaces/ui_driver.py
Executable file
85
interfaces/ui_driver.py
Executable file
@@ -0,0 +1,85 @@
|
||||
import pty
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import select
|
||||
import re
|
||||
|
||||
class VirtualTerminal:
|
||||
def __init__(self, rows=24, cols=80):
|
||||
self.rows = rows
|
||||
self.cols = cols
|
||||
self.buffer = [[' ' for _ in range(cols)] for _ in range(rows)]
|
||||
self.cursor_y = 0
|
||||
self.cursor_x = 0
|
||||
|
||||
def _strip_ansi(self, text):
|
||||
# Very basic ANSI parser for cursor moves and clears
|
||||
# CSI n ; m H (cursor move)
|
||||
# CSI J (clear screen)
|
||||
# CSI K (clear line)
|
||||
|
||||
# This is a simplified state machine
|
||||
parts = re.split(r'(\x1b\[[0-9;?]*[a-zA-Z])', text)
|
||||
for part in parts:
|
||||
if part.startswith('\x1b['):
|
||||
cmd = part[-1]
|
||||
params = part[2:-1].split(';')
|
||||
if cmd == 'H' or cmd == 'f': # Move cursor
|
||||
self.cursor_y = int(params[0]) - 1 if params[0] else 0
|
||||
self.cursor_x = int(params[1]) - 1 if (len(params) > 1 and params[1]) else 0
|
||||
elif cmd == 'J': # Clear
|
||||
mode = int(params[0]) if params[0] else 0
|
||||
if mode == 2: # Full clear
|
||||
self.buffer = [[' ' for _ in range(self.cols)] for _ in range(self.rows)]
|
||||
elif cmd == 'm': # Attributes - ignore for now
|
||||
pass
|
||||
else:
|
||||
for char in part:
|
||||
if char == '\n':
|
||||
self.cursor_y += 1
|
||||
self.cursor_x = 0
|
||||
elif char == '\r':
|
||||
self.cursor_x = 0
|
||||
elif 0 <= self.cursor_y < self.rows and 0 <= self.cursor_x < self.cols:
|
||||
self.buffer[self.cursor_y][self.cursor_x] = char
|
||||
self.cursor_x += 1
|
||||
|
||||
def get_screen(self):
|
||||
return "\n".join(["".join(row) for row in self.buffer])
|
||||
|
||||
def run_test(command, input_sequence, wait_time=5):
|
||||
pid, fd = pty.fork()
|
||||
if pid == 0:
|
||||
os.environ["TERM"] = "xterm"
|
||||
os.environ["COLUMNS"] = "80"
|
||||
os.environ["LINES"] = "24"
|
||||
os.execvp(command[0], command)
|
||||
else:
|
||||
vt = VirtualTerminal()
|
||||
start_time = time.time()
|
||||
input_sent = False
|
||||
|
||||
while time.time() - start_time < wait_time:
|
||||
r, w, e = select.select([fd], [], [], 0.1)
|
||||
if fd in r:
|
||||
try:
|
||||
data = os.read(fd, 8192).decode(errors='ignore')
|
||||
vt._strip_ansi(data)
|
||||
except OSError:
|
||||
break
|
||||
|
||||
if not input_sent and time.time() - start_time > 2:
|
||||
os.write(fd, input_sequence.encode())
|
||||
input_sent = True
|
||||
|
||||
os.kill(pid, 9)
|
||||
os.waitpid(pid, 0)
|
||||
return vt
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Example usage: python3 ui_driver.py sbcl --eval ...
|
||||
vt = run_test(sys.argv[1:], "Hi\r", wait_time=10)
|
||||
print("--- VIRTUAL SCREEN SNAPSHOT ---")
|
||||
print(vt.get_screen())
|
||||
print(f"--- CURSOR POSITION: ({vt.cursor_y}, {vt.cursor_x}) ---")
|
||||
Reference in New Issue
Block a user