# Korbit

Korbit mentor CLI will allow you to analyze any local files.

## Installation

### Pip

To install Korbit, you can use pip:

```
pip install korbit-mentor
```

### Binary

#### Linux - MacOS

1. Automatically installation

```sh
curl https://mentor-resources.korbit.ai/cli/installer.sh | bash
```

1. Linux and Macos x86

```sh
wget https://mentor-resources.korbit.ai/cli/korbit-x86_64 -O /usr/bin/local/korbit
```

1. MacOS arm64

```sh
wget https://mentor-resources.korbit.ai/cli/korbit-aarch64 -O /usr/bin/local/korbit
```

#### Windows

```sh
wget https://mentor-resources.korbit.ai/cli/korbit-win.exe -O korbit.exe
```

## Usage

To use Korbit, simply run the `korbit` command followed by the path of the file or folder you want to zip. For example, to zip the current folder, you can run:

```
korbit scan example/subfolder
```

This will create a zip file containing all the files and folders in the current directory.

## Development

### Set environment variables

Fill the missing values.

```sh
cp .env.example .env
```

### Create env

```
conda env update -f environment.yml -n korbit-cli
```

### Run

If you don't have the environment variables set you can use the login command and export at least `KORBIT_HOST` to use dev server for testing.

```sh
python korbit.py login

export KORBIT_HOST=https://oracle.korbit.ai:8000
python korbit.py scan example/subfolder


# Or
KORBIT_HOST=https://oracle.korbit.ai:8000 python korbit.py scan example/subfolder
```

#### Output

We introduce the ability to run a scan headless, meaning that there will be no output in the terminal. But in the following default path:

```sh
# In the working directory where the korbit scan command has been executed.
cat .korbit/scan.log
```

If Korbit AI mentor find issues the command will exit with a specific code number (see `--headless` option documentation).

```sh
korbit scan --help
```

This `korbit scan --headless` flag option will be used mainly in CI/CD pipelines, to automatically stop it.
Along with the --headless command you can specify certain thresholds for only 2 metrics at the moment:

1. confidence (scale 1-10): represents how confident Korbit AI Mentor is that a particular issue is real. A higher confidence score indicates a greater level of certainty that the identified issue is valid and requires attention.
1. priority (scale 1-10): represents the level of importance or urgency assigned by Korbit AI Mentor to a particular issue. A higher priority score indicates a greater sense of urgency and the need for immediate attention to address the identified issue.

```sh
korbit scan --headless
```

**Note**: You can use the `--thresholds-*` even if the scan isn't in headless mode, this will filter the issue found and display only the one that matters for you.

#### Progress view

After you start to run a `korbit scan` command and that our system accepted the request (might take some time regarding load on our server), you will see in your terminal the progress of the scan. Each files will be updated in real time with their status.

```sh
Analysis in progress (1/1)
├── afile.js ⏳
└── afile.py ✅
Analyzing files (2)... ━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━  50% -:--:--
```

#### Result

At the end when every file will be analyzed you will see in your terminal different tables containing the issues' descriptions and their placement in the given file. Along that will see the priority and confidence about that issue.

```sh
                                         Category: Critical Errors
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Error Description                                  ┃ File Path                  ┃ Confidence ┃ Priority ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ There is an error on the line X, because...        │ folder/afile.js            │ 10         │ 9        │
└────────────────────────────────────────────────────┴────────────────────────────┴────────────┴──────────┘
```

### Troubleshooting

We are using Python=3.11.3 because Python=3.11.4 and pyinstaller are causing a crash on execution of the script.

https://stackoverflow.com/a/76731974

<details>
<summary>Exception on python==3.11.4</summary>

```
❯ dist/korbit example/subfolder
[8650] Module object for pyimod02_importers is NULL!
Traceback (most recent call last):
  File "PyInstaller/loader/pyimod02_importers.py", line 22, in <module>
  File "pathlib.py", line 14, in <module>
  File "urllib/parse.py", line 40, in <module>
ModuleNotFoundError: No module named 'ipaddress'
Traceback (most recent call last):
  File "PyInstaller/loader/pyiboot01_bootstrap.py", line 17, in <module>
ModuleNotFoundError: No module named 'pyimod02_importers'
[8650] Failed to execute script 'pyiboot01_bootstrap' due to unhandled exception!
```

</details>

## Contributing

Contributions are welcome! If you have any bug reports, feature requests, or suggestions, please open an issue or submit a pull request.

## Contact

If you have any questions or need further assistance, feel free to reach out to us at [support@korbit.ai](mailto:support@korbit.ai).

You can also open new Issue tickets on this repository.
