110 lines
4.8 KiB
Bash
Executable File
110 lines
4.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Doctrine 162 v2: Rolling UX enrichment - clean version with pipe stdin
|
|
set -u
|
|
TS=$(date +%Y%m%d-%H%M%S)
|
|
|
|
HUBS_DEFAULT=("wevia-master" "all-ia-hub" "wevia-orchestrator" "wevia-chat-v2" "wevia-cortex" "sovereign-monitor" "wevia-audit" "wevia-console" "wevia-autonomy-dashboard" "wevia-business-visual-studio")
|
|
HUBS=("${@:-${HUBS_DEFAULT[@]}}")
|
|
|
|
KC_ALL=$(grep -oE "csk-[a-z0-9]+" /opt/wevads/vault/credentials.php 2>/dev/null); KEY_IDX=0
|
|
KC=""
|
|
# check moved inside loop
|
|
|
|
RESULTS=()
|
|
|
|
for HUB in "${HUBS[@]}"; do
|
|
HUB_FILE="$HUB"
|
|
[[ "$HUB" != *.* ]] && HUB_FILE="${HUB}.html"
|
|
F="/var/www/html/$HUB_FILE"
|
|
|
|
if [ ! -f "$F" ]; then RESULTS+=("{\"hub\":\"$HUB\",\"status\":\"missing\"}"); continue; fi
|
|
if grep -q "DOCTRINE-60-UX-ENRICH" "$F" 2>/dev/null; then RESULTS+=("{\"hub\":\"$HUB\",\"status\":\"already\"}"); continue; fi
|
|
|
|
SIZE_BEFORE=$(stat -c%s "$F")
|
|
[ "$SIZE_BEFORE" -gt 200000 ] && { RESULTS+=("{\"hub\":\"$HUB\",\"status\":\"too_large\"}"); continue; }
|
|
MD5_BEFORE=$(md5sum "$F" | cut -c1-10)
|
|
|
|
# GOLD backup
|
|
BACKUP="/var/www/html/vault-gold/opus/${HUB_FILE}.doctrine162v2-enrich-${TS}.bak"
|
|
sudo cp "$F" "$BACKUP"
|
|
|
|
# Build payload via Python stdin (clean escape)
|
|
PROMPT="Génère UNIQUEMENT CSS + JS pour UX doctrine 60 hub $HUB WEVAL. Format strict: marqueurs 'CSS_START' ... 'CSS_END' puis 'JS_START' ... 'JS_END'. Inclure: entrance staggered (opacity 0->1 + translateY 20px->0 sur .card .panel .btn .kpi, delay staggered par IntersectionObserver), hover glow (box-shadow + border accent transition 0.3s), activity pulse (keyframe 3s ease-in-out infinite sur .pulse .live-indicator .active .online), ambient radial (radial-gradient body::before circle 50% 50% rgba couleur soft alpha 0.12), backdrop blur speech (backdrop-filter blur(12px) sur .chat .speech .modal .overlay). CSS sans conflits, classes génériques. JS vanilla minimal IntersectionObserver. Max 1800 chars total. Raw code sans markdown."
|
|
|
|
PAYLOAD=$(python3 -c 'import json, sys; p=sys.stdin.read(); print(json.dumps({"model":"qwen-3-235b-a22b-instruct-2507","messages":[{"role":"user","content":p}],"temperature":0.2,"max_tokens":2200}))' <<< "$PROMPT")
|
|
|
|
KC=$(echo "$KC_ALL" | sed -n "$((KEY_IDX % 2 + 1))p"); KEY_IDX=$((KEY_IDX+1))
|
|
RESP=$(curl -sk -m 30 -X POST "https://api.cerebras.ai/v1/chat/completions" \
|
|
-H "Authorization: Bearer $KC" -H "Content-Type: application/json" \
|
|
-d "$PAYLOAD" 2>&1)
|
|
|
|
CONTENT=$(echo "$RESP" | python3 -c '
|
|
import sys, json
|
|
try: d=json.loads(sys.stdin.read()); print(d["choices"][0]["message"]["content"])
|
|
except Exception as e: print(f"ERR:{e}")
|
|
')
|
|
|
|
if [[ "$CONTENT" == ERR:* ]] || [ -z "$CONTENT" ]; then
|
|
RESULTS+=("{\"hub\":\"$HUB\",\"status\":\"cerebras_failed\",\"err\":$(echo "$CONTENT" | head -c 100 | python3 -c 'import sys,json;print(json.dumps(sys.stdin.read()))')}")
|
|
sleep 3
|
|
continue
|
|
fi
|
|
|
|
# Extract CSS and JS
|
|
CSS=$(echo "$CONTENT" | python3 -c '
|
|
import sys, re
|
|
t = sys.stdin.read()
|
|
m = re.search(r"CSS_START(.*?)CSS_END", t, re.DOTALL)
|
|
print(m.group(1).strip() if m else "")
|
|
')
|
|
JS=$(echo "$CONTENT" | python3 -c '
|
|
import sys, re
|
|
t = sys.stdin.read()
|
|
m = re.search(r"JS_START(.*?)JS_END", t, re.DOTALL)
|
|
print(m.group(1).strip() if m else "")
|
|
')
|
|
|
|
if [ -z "$CSS" ]; then
|
|
RESULTS+=("{\"hub\":\"$HUB\",\"status\":\"parsing_failed\"}")
|
|
sleep 3
|
|
continue
|
|
fi
|
|
|
|
# Unlock + inject + relock via Python (safer)
|
|
sudo chattr -i "$F" 2>/dev/null
|
|
CSS_B64=$(echo "$CSS" | base64 -w0)
|
|
JS_B64=$(echo "$JS" | base64 -w0)
|
|
python3 << PYEOF > /dev/null
|
|
import base64
|
|
with open("$F","r",encoding="utf-8",errors="replace") as fp:
|
|
html = fp.read()
|
|
css = base64.b64decode("$CSS_B64").decode("utf-8","replace")
|
|
js = base64.b64decode("$JS_B64").decode("utf-8","replace")
|
|
block_css = f"<!-- DOCTRINE-60-UX-ENRICH cerebras-qwen235b $TS -->\n<style id=\"doctrine60-ux-$HUB\">\n{css}\n</style>"
|
|
block_js = f"<!-- DOCTRINE-60-UX-JS -->\n<script id=\"doctrine60-ux-js-$HUB\">\n{js}\n</script>"
|
|
if "</head>" in html:
|
|
html = html.replace("</head>", block_css + "\n</head>", 1)
|
|
else:
|
|
html = block_css + "\n" + html
|
|
if "</body>" in html:
|
|
html = html.replace("</body>", block_js + "\n</body>", 1)
|
|
else:
|
|
html = html + "\n" + block_js
|
|
with open("$F","w",encoding="utf-8") as fp:
|
|
fp.write(html)
|
|
PYEOF
|
|
sudo chattr +i "$F" 2>/dev/null
|
|
|
|
SIZE_AFTER=$(stat -c%s "$F")
|
|
MD5_AFTER=$(md5sum "$F" | cut -c1-10)
|
|
HTTP=$(curl -sk -m 5 "https://weval-consulting.com/$HUB_FILE" -o /dev/null -w "%{http_code}")
|
|
|
|
RESULTS+=("{\"hub\":\"$HUB\",\"status\":\"enriched\",\"size_before\":$SIZE_BEFORE,\"size_after\":$SIZE_AFTER,\"size_delta\":$((SIZE_AFTER-SIZE_BEFORE)),\"md5_before\":\"$MD5_BEFORE\",\"md5_after\":\"$MD5_AFTER\",\"http\":\"$HTTP\"}")
|
|
sleep 8
|
|
done
|
|
|
|
echo -n "{\"doctrine\":\"162v2\",\"ts\":\"$(date -Iseconds)\",\"hubs_count\":${#HUBS[@]},\"results\":["
|
|
FIRST=1
|
|
for r in "${RESULTS[@]}"; do [ $FIRST -eq 1 ] && FIRST=0 || echo -n ","; echo -n "$r"; done
|
|
echo "]}"
|