Skip to content

Commit

Permalink
Merge pull request #90 from SaintsSec/edge
Browse files Browse the repository at this point in the history
Code cleanup and improvements
  • Loading branch information
AlexKollar authored Jul 26, 2024
2 parents 6302c6c + 335e4af commit 2b5955a
Show file tree
Hide file tree
Showing 14 changed files with 420 additions and 375 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<h1> Navi | CLI - An innovation in cybersec AI</h1>
<h1>v0.5 - "Integral"</h1>
<h1>v0.6.0 - "Dissidence"</h1>
</div>

## 🤝 Sponsors / Endorsements: Thank you so much!
Expand All @@ -13,28 +13,32 @@
#### If you have a previous copy of Navi it is a good idea to do a clean install so the automatic updater works properly going forward.
`sudo rm -rf /opt/Navi` should do the trick!

## **Key Features of Navi v0.5**
## **Key Features of Navi v0.6.0**

- **Upgraded Navi Shell** - The shell can now execute system commands, without breaking the flow of conversation. See more below!
- **Navi Scripts Upgrade** - The new alias variable within the custom scripts allow for Navi to execute scripts right from the chat. Once again not disrupting the flow.
- **Navi Cryptex Chip** - Thats right you heared it here. Cryptex is officially part of the Navi chip ecosystem as an example of how powerful its chips can be.
- **Navi chips Upgrade** - The new alias variable within the custom scripts allow for Navi to execute scripts right from the chat. Once again not disrupting the flow.
- **Navi Cryptex Chip** - Thats right you heared it here. Cryptex is officially part of the Navi chip ecosystem as an example of how powerful its chips can be.
- **Wiki Re-write** - With new power comes new documentation
- **Llama3 Integration** - We made the leap from GPT to the open source Llama AI on the backend - we also customized it giving Navi her own personality and lore.
- **A ton of backend fixes** - This one more or less speaks for itself.
- **Llama3.1 Integration** - We made the leap from GPT to the open source Llama AI on the backend - we also customized it giving Navi her own personality and lore.
- **Complete overhaul of core systems** - One of the major things we wanted to do with this release was give developers the ability to make use of Navi's core features when building out custom chips. So we made it EASIER than ever with Navi now being its own class.
- **A ton of backend fixes** - This one more or less speaks for itself.

### **Commands**

### **Commands**
Commands have been completely reworked in this version. Allowing for a feature we have been waiting for. **Chat Execution**, through this new system
Navi is able to use ML to take user input and execute system commands based on user provided context. Here its better to just show you.
![image](https://github.com/SaintsSec/Navi/assets/89718570/4cdfb719-4bb5-48e4-9da0-e8d255a13ec8)

### **Work In Progress**
### **Work In Progress**

- **[Navi Roadmap](https://github.com/orgs/SaintsSec/projects/7)**
- **[Navi Issues](https://github.com/SaintsSec/Navi/issues)**

## 🚀 About Navi
## 🚀 About Navi

[![Codacy Badge](https://app.codacy.com/project/badge/Grade/63a04af9b14f41179b567637c4ab77a6)](https://app.codacy.com/gh/SSGorg/Navi/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)

Navi was conceptualized by Alex during his formative years, with its foundational ideas rooted in the complexities of the game, Megaman Battle Network 3. From a humble beginning as a basic AI chatbot governed by rudimentary logic, Navi has matured into an advanced platform, now integrated with state-of-the-art models utilized in various digital domains.
Navi was conceptualized by Alex during his formative years, with its foundational ideas rooted in the complexities of the game, Megaman Battle Network 3. From a humble beginning as a basic AI chatbot governed by rudimentary logic, Navi has matured into an advanced platform, now integrated with state-of-the-art models utilized in various digital domains.

### 🌍 The Imperative of Open Source in AI & Cybersecurity

Expand All @@ -61,5 +65,3 @@ We value your input! Whether it's contributions, feedback, or bug reports, we're
Your invaluable contributions propel the boundaries of innovation. Thank you!

[![Contributors Image](https://contrib.rocks/image?repo=SaintsSec/Navi)](https://github.com/SaintsSec/Navi/graphs/contributors)


10 changes: 6 additions & 4 deletions commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def load_module(name):
datefmt="%Y-%m-%d %H:%M:%S",
filename=join(logs_dir, "error.log"),
)
logging.error(f"Module '{name}' not found: {e}")
# exit(1)
logging.error(f"Chip '{name}' not found: {e}")
except Exception as generic:
logging.error(f"Issue loading Chip '{name}': {generic}")
return
else:
return module

Expand All @@ -59,9 +61,9 @@ def load_module(name):
if use:
command_usage[mod.command] = use
else:
print(f"Warning: The module '{module_name}' is not installed correctly. Ignoring module.")
print(f"Warning: The Chip '{module_name}' is not installed correctly. Ignoring module.")
else:
print(f"Module '{module_name}' could not be loaded.")
print(f"Chip '{module_name}' could not be loaded.")

# Export modules, alias_to_command, and command_usage for use in other scripts
__all__.extend(['modules', 'alias_to_command', 'command_usage'])
54 changes: 33 additions & 21 deletions commands/navi_chip_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
import requests
import zipfile
import shutil
import subprocess
import subprocess # nosec
import uuid
import navi_internal

from colorama import Fore
from navi import get_parameters
from navi_shell import print_message, restart_navi
from navi_shell import restart_navi

command = "chips"
use = "Manage Navi chips"
aliases = ['chip']
navi = None


def get_latest_release(owner, repo):
Expand All @@ -34,7 +36,7 @@ def search_for_chips(name=None, per_page=10, page=1):

def search(command):
try:
_, name, page_size, page_num = command + [None, 10, 1][len(command)-1:]
_, name, page_size, page_num = command + [None, 10, 1][len(command) - 1:]
page_size = int(page_size)
page_num = int(page_num)
except ValueError:
Expand All @@ -59,6 +61,7 @@ def search(command):
if available_repos == 0:
print("No Navi Chips found with releases.")


def download_and_extract(download_url):
download_guid = str(uuid.uuid4())
zip_path = f"{download_guid}.zip"
Expand All @@ -84,7 +87,7 @@ def copy_files_to_install_path(extracted_dir, install_path="/commands"):
installed_files = []
try:
for item in os.listdir(extracted_dir):
if item == "LICENSE" or item.endswith(".md"):
if item == "LICENSE" or item.endswith(".md") or item == ".gitignore":
continue
s, d = os.path.join(extracted_dir, item), os.path.join(install_path, item)
if os.path.isdir(s):
Expand All @@ -100,8 +103,14 @@ def copy_files_to_install_path(extracted_dir, install_path="/commands"):
def install_requirements(extracted_dir):
requirements_path = os.path.join(extracted_dir, "chip-requirements.txt")
if os.path.exists(requirements_path):
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "-r", requirements_path])
try:
result = subprocess.run(
[sys.executable, "-m", "pip", "install", "-r", requirements_path],
check=True, capture_output=True, text=True) # nosec
print(result.stdout)
except subprocess.CalledProcessError as e:
print(f"Error occurred: {e}") # Prevent the program from crashing from pip install errors
print(e.stderr)
os.remove(requirements_path)


Expand Down Expand Up @@ -129,14 +138,14 @@ def log_installation(repo, installed_files, version):
log_file.write(log_entry)


def is_installed(repo_name):
def is_installed(repo_name: str) -> bool | str:
if not os.path.exists("installed_chips.txt"):
return False
with open("installed_chips.txt", 'r') as log_file:
return repo_name in log_file.read()


def install_chip(name, restart_app=True):
def install_chip(name: str, restart_app: bool = True) -> None:
repos = search_for_chips(name)
if not repos:
print("No repositories found.")
Expand All @@ -159,7 +168,7 @@ def install_chip(name, restart_app=True):
restart_navi()


def uninstall_chip(name, restart_app=True):
def uninstall_chip(name: str, restart_app: bool = True) -> None:
if not os.path.exists("installed_chips.txt"):
print(f"{Fore.RED}No chips installed.{Fore.RESET}")
return
Expand Down Expand Up @@ -191,24 +200,21 @@ def uninstall_chip(name, restart_app=True):
restart_navi()


def list_installed_chips():
def get_installed_chips() -> list[dict[str, str]] | None:
log_file_path = "installed_chips.txt"

if not os.path.exists(log_file_path):
print("No chips are installed.")
return

with open(log_file_path, 'r') as log_file:
lines = log_file.readlines()

if not lines:
print("No chips are installed.")
return

modules = []
module_info = {}
i = 0

while i < len(lines):
line = lines[i].strip()
if line.startswith("Repo Name:"):
Expand All @@ -227,16 +233,20 @@ def list_installed_chips():
}
modules.append(module_info)
i += 1
return modules


if modules:
def list_installed_chips() -> None:
chips = get_installed_chips()
if chips:
print("Installed Chips:")
for module in modules:
for module in chips:
print(f"- {module['name']} (Owner: {module['owner']}, Version: {module['version']})")
else:
print("No chips are installed.")


def about_chip(name):
def about_chip(name) -> dict[str, str] | None:
log_file_path = "installed_chips.txt"

if not os.path.exists(log_file_path):
Expand All @@ -246,7 +256,7 @@ def about_chip(name):
with open(log_file_path, 'r') as log_file:
lines = log_file.readlines()

for i in range(len(lines)):
for i, _ in enumerate(lines):
if lines[i].startswith("Repo Name:") and lines[i].split(": ")[1].strip() == name:
module_name = lines[i].split(": ")[1].strip()
description = lines[i + 1].split(": ")[1].strip()
Expand Down Expand Up @@ -284,7 +294,7 @@ def about_chip(name):
return None


def update_chip(chip_name):
def update_chip(chip_name: str) -> None:
chip_info = about_chip(chip_name)
if not chip_info:
print(f"The chip '{chip_name}' is not installed.")
Expand All @@ -298,14 +308,16 @@ def update_chip(chip_name):
restart_navi()


def help_text():
print_message("Chip Manager\n"
def help_text() -> None:
navi.print_message("Chip Manager\n"
"chips [install | uninstall | search | update] [app/query]\n\n"
"List currently installed chips\n"
"chips list")


def run(arguments=None):
def run(arguments=None) -> None:
global navi
navi = navi_internal.navi_instance
argv = get_parameters(arguments.text)
argv.pop(0)

Expand Down
7 changes: 4 additions & 3 deletions commands/navi_clear.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/python3
from navi_shell import get_user, clear_terminal, print_message
import navi_internal

command = "clear"
use = "Clear the screen"
aliases = ['cls']


def run(arguments=None):
clear_terminal()
print_message(f"How can I help you, {get_user()}?")
navi_instance = navi_internal.navi_instance
navi_instance.clear_terminal()
navi_instance.print_message(f"How can I help you, {navi_instance.get_user()}?")
6 changes: 3 additions & 3 deletions commands/navi_exit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/python3
from navi_shell import get_user, print_message
import os
import navi_internal

command = "exit"
use = "Exit Navi"
aliases = ['quit', 'exit', 'goodbye']


def run(arguments=None):
print_message(f"Thank you for stopping by! {get_user()}")
navi_instance = navi_internal.navi_instance
navi_instance.print_message(f"Thank you for stopping by! {navi_instance.get_user()}")
exit(0)
47 changes: 22 additions & 25 deletions commands/navi_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import psutil
import requests
import socket
import navi_internal
from datetime import datetime

from navi_shell import print_message, llm_chat

# Navi Command System Variables
command = "navi_specs"
use = "Prints out system information"
Expand Down Expand Up @@ -69,43 +68,41 @@ def get_local_ip():


def run(arguments=None):
navi_instance = navi_internal.navi_instance
# setup variables
public_ip = get_public_ip()
local_ip = get_local_ip()
system_info = get_system_info()
memory_info = get_memory_info()
disk_info = get_disk_info()
uptime_info = get_uptime_info()

# Main functions
response_message = llm_chat(
"Give me a really simple quip about getting my systems specs. Dont include commands or references to operating systems.")
response_message = navi_instance.llm_chat(
"Give me a really simple quip about getting my systems specs. Dont include commands or references to operating systems.", True)
clean_text = str(response_message).replace("(", "").replace(")", "").replace(", 200", "").replace("\"", "").replace(
"\\n", "")
tr(clean_text)

print(breakline)
print_message(f"System Information:\n")
output = clean_text + "\n"
output += breakline
output += "System Information:\n"
for key, value in system_info.items():
print_message(f"{key}: {value}")
output += f"{key}: {value}\n"

print(breakline)
print_message(f"Memory Information:\n")
output += breakline
output += "Memory Information:\n"
for key, value in memory_info.items():
print_message(f"{key}: {value}")
output += f"{key}: {value}\n"

print(breakline)
print_message(f"Disk Space Information:\n")
output += breakline
output += "Disk Space Information:\n"
for key, value in disk_info.items():
print_message(f"{key}: {value}")
output += f"{key}: {value}\n"

print(breakline)
print_message(f"Uptime Information:\n")
output += breakline
output += "Uptime Information:\n"
for key, value in uptime_info.items():
print_message(f"{key}: {value}")

print(breakline)
print_message(f"Network Information: \n")
print_message(f"Your local ip is: {local_ip}")
print_message(f"Your public ip is: redacted -- Nice try")
print(breakline)
output += f"{key}: {value}\n"
output += breakline
output += "Network Information: \n"
output += f"Your local ip is: {local_ip}\n"
output += "Your public ip is: redacted -- Nice try\n"
navi_instance.print_message(output)
Loading

0 comments on commit 2b5955a

Please sign in to comment.