initial COM2 system snapshot

This commit is contained in:
gitea
2026-03-06 15:22:40 +00:00
commit 9c0fa49baf
4377 changed files with 273033 additions and 0 deletions

View File

@@ -0,0 +1,228 @@
#!/usr/bin/env bash
set -euo pipefail
echo "=== HX-KI Homepage Setup (Falkenstein) ==="
########################################
# 0. PARAMETER
########################################
# Falls dein Next.js-Projekt woanders liegt: HIER anpassen.
WEB_ROOT="/opt/hx-ki/web/nextjs"
WORKSPACE="/opt/hx-ki/workspaces/homepage"
AGENT_DIR="/opt/hx-ki/agents"
API_DIR="$WEB_ROOT/app/api/homepage"
echo "WEB_ROOT: $WEB_ROOT"
echo "WORKSPACE: $WORKSPACE"
echo "AGENT_DIR: $AGENT_DIR"
echo "API_DIR: $API_DIR"
echo
########################################
# 1. VERZEICHNISSE ANLEGEN
########################################
mkdir -p "$WORKSPACE"
mkdir -p "$AGENT_DIR"
mkdir -p "$API_DIR"
echo "✔ Verzeichnisse angelegt."
########################################
# 2. BASIS-HOMEPAGE.JSON ANLEGEN (FALLS NICHT VORHANDEN)
########################################
HOMEPAGE_JSON="$WORKSPACE/homepage.json"
if [[ ! -f "$HOMEPAGE_JSON" ]]; then
cat > "$HOMEPAGE_JSON" <<EOF
{
"hero_title": "HX-KI Cognitive Clarity",
"hero_sub": "Vom Chaos zur Klarheit. Falkenstein liefert nur aus dem Workspace.",
"sections": [
{
"title": "Status",
"text": "Die Homepage wird jetzt aus /opt/hx-ki/workspaces/homepage/homepage.json versorgt."
},
{
"title": "Architektur",
"text": "Falkenstein greift NICHT auf Gehirn oder Motor zu. Nur Workspace."
}
]
}
EOF
echo "✔ Default homepage.json erstellt: $HOMEPAGE_JSON"
else
echo "✔ homepage.json existiert bereits wird NICHT überschrieben."
fi
########################################
# 3. JSON-AGENT ANLEGEN (ERZEUGT/ÜBERSCHREIBT HOMEPAGE.JSON)
########################################
AGENT_SCRIPT="$AGENT_DIR/json_homepage_agent.py"
cat > "$AGENT_SCRIPT" <<'EOF'
#!/usr/bin/env python3
import json
import os
WORKSPACE = "/opt/hx-ki/workspaces/homepage"
FILE = os.path.join(WORKSPACE, "homepage.json")
os.makedirs(WORKSPACE, exist_ok=True)
content = {
"hero_title": "HX-KI Dynamischer JSON-Agent",
"hero_sub": "Content kommt aus dem Workspace auf Falkenstein kein Zugriff auf Gehirn oder Motor.",
"sections": [
{
"title": "Agent-Status",
"text": "Dieser JSON-Agent kann von Events, Cron, KI oder Mautic getriggert werden."
},
{
"title": "Architektur-Sicherheit",
"text": "Falkenstein liest nur den Workspace. Nürnberg & Helsinki bleiben intern."
}
]
}
with open(FILE, "w") as f:
json.dump(content, f, indent=2)
print(f"✔ homepage.json durch json_homepage_agent.py erzeugt/aktualisiert: {FILE}")
EOF
chmod +x "$AGENT_SCRIPT"
echo "✔ JSON-Agent angelegt: $AGENT_SCRIPT"
########################################
# 4. SELBSTHEILUNG FÜR HOMEPAGE.JSON
########################################
REPAIR_SCRIPT="$WORKSPACE/repair_homepage_json.sh"
cat > "$REPAIR_SCRIPT" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
FILE="/opt/hx-ki/workspaces/homepage/homepage.json"
echo "=== Repair homepage.json ==="
if [[ ! -f "$FILE" ]]; then
echo "✘ homepage.json fehlt wird neu erstellt."
cat > "$FILE" <<EOF2
{
"hero_title": "HX-KI Repair Mode",
"hero_sub": "homepage.json war weg und wurde automatisch neu erstellt.",
"sections": [
{
"title": "Hinweis",
"text": "Dies ist ein Fallback-Content aus repair_homepage_json.sh."
}
]
}
EOF2
echo "✔ homepage.json neu angelegt."
exit 0
fi
# JSON grob prüfen (ohne jq, über Python)
python3 - <<PYEOF
import json, sys
try:
json.load(open("$FILE", "r"))
except Exception as e:
sys.exit(1)
PYEOF
if [[ $? -eq 0 ]]; then
echo "✔ homepage.json ist gültiges JSON."
else
echo "✘ homepage.json ist defekt wird repariert."
cat > "$FILE" <<EOF3
{
"hero_title": "HX-KI Repair Mode",
"hero_sub": "homepage.json war defekt und wurde automatisch repariert.",
"sections": [
{
"title": "Hinweis",
"text": "Der vorherige Inhalt war ungültig. Dies ist ein Fallback."
}
]
}
EOF3
echo "✔ homepage.json repariert."
fi
EOF
chmod +x "$REPAIR_SCRIPT"
echo "✔ Repair-Skript angelegt: $REPAIR_SCRIPT"
########################################
# 5. CRONJOB FÜR SELBSTHEILUNG (ALLE 5 MINUTEN)
########################################
CRON_LINE="*/5 * * * * $REPAIR_SCRIPT >/dev/null 2>&1"
# Cron nur hinzufügen, wenn noch nicht vorhanden
( crontab -l 2>/dev/null | grep -v "$REPAIR_SCRIPT" || true; echo "$CRON_LINE" ) | crontab -
echo "✔ Cronjob für Repair installiert (alle 5 Minuten)."
########################################
# 6. NEXT.JS API-ROUTE FÜR /api/homepage
########################################
ROUTE_FILE="$API_DIR/route.ts"
cat > "$ROUTE_FILE" <<'EOF'
import { NextResponse } from "next/server";
import fs from "fs";
export async function GET() {
const path = "/opt/hx-ki/workspaces/homepage/homepage.json";
try {
const raw = fs.readFileSync(path, "utf-8");
const data = JSON.parse(raw);
return NextResponse.json(data);
} catch (err) {
console.error("Error reading homepage.json:", err);
return NextResponse.json(
{
error: "Homepage content not available",
details: "Check /opt/hx-ki/workspaces/homepage/homepage.json on Falkenstein."
},
{ status: 500 }
);
}
}
EOF
echo "✔ Next.js API-Route erstellt: $ROUTE_FILE"
########################################
# 7. ERSTEN LAUF DES JSON-AGENTEN AUSFÜHREN
########################################
echo "=== Erster Lauf des JSON-Agents ==="
"$AGENT_SCRIPT" || echo "Warnung: JSON-Agent konnte nicht ausgeführt werden."
echo
echo "=== Fertig. Schritte als Nächstes: ==="
echo "1) Stelle sicher, dass WEB_ROOT korrekt ist (aktuell: $WEB_ROOT)."
echo "2) Baue/Starte dein hxki-web / Next.js-Container neu."
echo "3) Rufe im Browser /api/homepage auf dort sollte JSON kommen."
echo "4) Binde in app/page.tsx o.ä. fetch('https://DEINE-DOMAIN/api/homepage') ein."
echo
echo "=== HX-KI Homepage Setup (Falkenstein) COMPLETE ==="