JEDI / jedi_cortex.py
FerrellSyntheticIntelligence's picture
Upload jedi_cortex.py with huggingface_hub
03ec45b verified
Raw
History Blame Contribute Delete
10.3 kB
#!/usr/bin/env python3
"""
JEDI x Vitalis Cortex β€” Unified CLI
Wires JEDI nanobot framework into Vitalis Cortex LFM2.5 engine.
Runs the full cognitive pipeline:
Quadruflow β†’ Memory β†’ Amplifier β†’ LFM2.5 β†’ Attestation β†’ JEDI modules β†’ Output
"""
import os
import sys
import textwrap
# Paths
BASE = os.path.dirname(os.path.abspath(__file__))
CORTEX = os.path.join(BASE, "Vitalis_LFM2.5_Cortex.GGUF")
JEDI = BASE
sys.path.insert(0, CORTEX)
sys.path.insert(0, JEDI)
from src.brain.inference import InferenceEngine
from jedi.core.engine import JEDIEngine, ThreatLevel
from jedi.core.nanobot import Nanobot, NanobotType
from jedi.core.mission import Mission
from jedi.legal.gate import LegalGate, AuthorizationLevel
from jedi.swarm.coordinator import SwarmCoordinator
from jedi.command.control import MissionControl
from jedi.comms.channel import CommsChannel
from jedi.memory.helix import HelixMemoryStore
from jedi.nanobots.black.ghost import GhostNanobot
from jedi.nanobots.blue.guardian import GuardianNanobot
from jedi.nanobots.red.striker import StrikerNanobot
from jedi.nanobots.green.architect import ArchitectNanobot
from jedi.nanobots.yellow.auditor import AuditorNanobot
from jedi.nanobots.purple.synapse import SynapseNanobot
BANNER = r"""
β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—
β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β• β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β• β•šβ•β•β•β•β•β•β•
β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•
β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
β•šβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β•šβ•β•β•β•β–ˆβ–ˆβ•‘
β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘
β•šβ•β•β•β• β•šβ•β• β•šβ•β• β•šβ•β• β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•šβ•β•β•β•β•β•β•
JEDI x Vitalis Cortex Hybrid
Nanobot Defense Intelligence | LFM2.5 Cognitive Core
Ferrell Synthetic Intelligence
"""
def main():
print(BANNER)
print(" Booting JEDI x Vitalis Cortex...\n")
# Initialize JEDI systems
engine = JEDIEngine()
gate = LegalGate()
mc = MissionControl(engine)
swarm = SwarmCoordinator("jedi-swarm")
comms = CommsChannel("jedi-comms")
memory = HelixMemoryStore()
# Initialize Vitalis Cortex with LFM2.5
try:
cortex = InferenceEngine(model_path=os.path.join(CORTEX, "model", "LFM2.5-1.2B-Instruct-Q4_K_M.gguf"))
print("\n βœ“ Vitalis Cortex online β€” LFM2.5 1.2B cognitive core loaded")
cortex_online = True
except Exception as e:
print(f"\n βœ— Cortex load: {e}")
cortex_online = False
print(" βœ“ JEDI Engine online β€” nanobot framework armed")
print(" βœ“ Legal Gate active β€” all ops require authorization")
print(" βœ“ Ledger initialized β€” immutable audit trail")
print(" βœ“ Swarm Coordinator ready")
print()
print(" Type 'help' for commands. Type 'quit' to exit.\n")
memory.record_episode({"type": "session_start", "cortex_online": cortex_online})
# Chat loop
while True:
try:
prompt = input("\033[96m JEDI β–Έ \033[0m").strip()
except (EOFError, KeyboardInterrupt):
print("\n\n Shutdown. All nanobots self-destructed.")
break
if not prompt:
continue
if prompt.lower() in ["quit", "exit", "bye"]:
print("\n JEDI offline. Ledger sealed. Goodbye.\n")
break
if prompt.lower() == "clear":
os.system("clear")
print(BANNER)
continue
# Route to appropriate system
response = route(prompt, cortex if cortex_online else None, engine, gate, mc, swarm, comms, memory)
# Format output
print()
for line in response.split("\n"):
wrapped = textwrap.fill(line, width=80, initial_indent=" ", subsequent_indent=" ")
print(wrapped)
# Log
engine.ledger.log("cli_interaction", {"input": prompt[:80]})
print()
def route(prompt, cortex, engine, gate, mc, swarm, comms, memory):
"""Route prompt to appropriate handler."""
p = prompt.lower()
# === JEDI COMMANDS ===
if any(w in p for w in ["threat", "risk", "assess"]):
return threat_handler(p, engine)
if p.startswith("deploy") or p.startswith("deploy nanobot"):
return deploy_handler(prompt)
if p.startswith("mission"):
return mission_handler(prompt, mc)
if "swarm" in p.split() and len(p.split()) < 4:
return swarm_handler(swarm)
if "scan" in p:
return "═══ SCAN PROTOCOL ═══\nTarget and auth needed. Example:\n mission create recon 10.0.0.0/24\n Then I'll deploy a Scout nanobot swarm."
if p in ["help", "/help", "-h", "--help"]:
return help_text()
if p in ["status", "screenshot"]:
return status_handler(mc)
if p == "clear":
return ""
# Use LLM for anything else
if cortex:
# Inject JEDI context into the cognitive pipeline
context_prompt = f"[JEDI CONTEXT] You are JEDI β€” Joint Entity Defense Infrastructure. A cybersecurity nanobot command AI. Respond as a tactical cybersecurity operations specialist.\n\nUser: {prompt}"
result = cortex.think(context_prompt, verbose=False)
return result["response"]
return rule_based(prompt)
def help_text():
return ("═══ JEDI COMMANDS ═══\n"
" help β€” This message\n"
" status β€” System situation report\n"
" threat <info> β€” Assess a threat\n"
" mission create β€” Create a new mission\n"
" deploy <type> β€” Deploy a nanobot\n"
" swarm β€” Swarm status\n"
" scan <target> β€” Scan a target\n"
" audit <framework> β€” Compliance check\n"
" quit β€” Exit\n\n"
"Ask anything else and JEDI uses the LFM2.5 cognitive core.")
def status_handler(mc):
d = mc.dashboard()
return (f"═══ JEDI STATUS ═══\n"
f" Engine: {d['engine_state']}\n"
f" Threat: {d['threat_level']}\n"
f" Missions: {d['active_missions']}\n"
f" Nanobots: {d['deployed_nanobots']}\n"
f" Uptime: {d['uptime_hours']}h")
def threat_handler(p, engine):
ind = []
if any(w in p for w in ["apt", "nation", "state"]):
ind.append({"type": "nation_state_attribution", "severity": 40})
if any(w in p for w in ["ransom", "malware"]):
ind.append({"type": "ransomware", "severity": 30})
if "phish" in p:
ind.append({"type": "social_engineering", "severity": 15})
if any(w in p for w in ["exfil", "leak"]):
ind.append({"type": "data_exfiltration", "severity": 25})
if "lateral" in p:
ind.append({"type": "lateral_movement", "severity": 15})
if not ind:
ind.append({"type": "suspicious_process", "severity": 5})
level = engine.assess_threat({"indicators": ind, "confidence": 0.7})
lines = [f"═══ THREAT ASSESSMENT ═══", f" Level: {level.name}"]
if level.value >= 4:
lines.extend([" ⚠ CRITICAL β€” Immediate containment", " Deploy Guardian + Sentinel swarm", " Activate emergency ROE"])
elif level.value >= 3:
lines.extend([" ⚠ HIGH β€” Enhanced monitoring", " Deploy Guardian nanobot"])
elif level.value >= 2:
lines.extend([" β–² MEDIUM β€” Active monitoring"])
else:
lines.extend([" βœ“ LOW β€” Normal ops"])
return "\n".join(lines)
def deploy_handler(prompt):
bot_types = {
"striker": "πŸ”΄ STRIKER β€” Offensive penetration testing",
"guardian": "πŸ”΅ GUARDIAN β€” Defensive monitoring",
"ghost": "⚫ GHOST β€” Covert/attribution (Gov use)",
"synapse": "🟣 SYNAPSE β€” Combined ops coordination",
"auditor": "🟑 AUDITOR β€” Compliance checking",
"architect": "🟒 ARCHITECT β€” Secure code review",
"scout": "🟠 SCOUT β€” Reconnaissance",
"sentinel": "🟀 SENTINEL β€” Perimeter watch",
}
return (f"═══ NANOBOTS ═══\n" +
"\n".join(f" {v}" for v in bot_types.values()) +
"\n\nUsage: deploy ghost to 10.0.0.1\nOr just ask the LLM to set up a mission.")
def mission_handler(prompt, mc):
return ("═══ MISSION CONTROL ═══\n"
"Create: mission create <type> <target>\n"
"Types: recon, defense, pentest, attribution, sweep\n\n"
"Example:\n mission create recon 10.0.0.0/24\n mission create pentet webapp.example.com")
def swarm_handler(swarm):
s = swarm.get_swarm_status()
return (f"═══ SWARM STATUS ═══\n"
f" ID: {s['swarm_id']}\n"
f" Members: {s['active_members']}/{s['total_members']}\n"
f" Tasks queued: {s['tasks_queued']}\n"
f" Wisom: {s.get('wisdom_size', {'intel_entries': 0})['intel_entries']} intel entries\n"
f" Decisions: {s['consensus_reached']}\n"
f"\nTo deploy a swarm: create a mission first.")
def rule_based(prompt):
return ("JEDI operational. Your query goes through the LFM2.5 cognitive core\n"
"with Quadruflow routing, memory retrieval, and attestation gating.\n"
"Type 'help' for commands or ask me anything about cybersecurity.\n"
"(Full LLM mode available when the model loads successfully.)")
if __name__ == "__main__":
main()