Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Sentinel is a multi-language static analysis tool that detects patterns indicati
- **Fast & Lightweight** - Single binary, no dependencies. Built with Go for exceptional performance and minimal resource footprint
- **Multi-Language** - Python, Java, JavaScript, TypeScript, Go, Rust, C/C++, Ruby, PHP, C#, Kotlin, Swift (early support - actively improving)
- **Detailed Reporting** - JSON and human-readable output formats
- **Heuristic-Driven Analysis:** Sentinel currently relies on heuristic-based checking (predefined "hard-coded" logic). I am actively working and learning on integrating Machine Learning models to enhance detection.
- **Hybrid Detection:** Sentinel utilizes a dual-layer verification pipeline, merging **Heuristics-Driven Analysis** with **Machine Learning (ONNX)**.

## Sample Output

Expand Down Expand Up @@ -90,6 +90,7 @@ sudo mv sentinel.exe /usr/local/bin/
```bash
./sentinel

# Heuristics Only
# Scan current directory
./sentinel scan --path .

Expand All @@ -109,14 +110,17 @@ sudo mv sentinel.exe /usr/local/bin/
./sentinel scan --path ./examples/ai --collect --label ai
./sentinel scan --path ./examples/human --collect --label human

# Use ML + heuristics (MACHINE LEARNING MODEL IS REQUIRED!)
./sentinel scan --path . --hybrid --ml-weight 0.7 --verbose
# Hybrid Mode (Default when --model is provided)
# Blends ML probability with heuristic patterns using a weighted average.
./sentinel scan --path . --model ./model/model.onnx --ml-weight 0.7 --verbose

# Heuristics only (no ML)
# Heuristics Only
# Ignores the ML model entirely and looks for raw code patterns.
./sentinel scan --path . --no-ml --verbose

# ML only (MACHINE LEARNING MODEL IS REQUIRED!)
./sentinel scan --path . --ml-only --verbose
# ML Only
# Forces the detector to rely primarily on the model.
./sentinel scan --path . --ml-only --model ./model/model.onnx --verbose
```

**Flags:**
Expand All @@ -134,13 +138,6 @@ sudo mv sentinel.exe /usr/local/bin/
- `--ml-only` - Use ML only (fail if model not available)
- `--ml-weight` - Weight given to ML score (0.0-1.0)

## Git Diff Scanning

```bash
# Scan only files changed in PR
./sentinel scan --git-diff origin/main --threshold 0.75
```

# CI/CD Integration

## GitHub Actions
Expand Down Expand Up @@ -198,6 +195,13 @@ pipeline {
}
```

## Git Diff Scanning

```bash
# Scan only files changed in PR
./sentinel scan --git-diff origin/main --threshold 0.75
```

---

# License
Expand Down
40 changes: 29 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,41 @@ import (

var cfgFile string

const banner = `
▄████████ ▄████████ ███▄▄▄▄ ███ ▄█ ███▄▄▄▄ ▄████████ ▄█
███ ███ ███ ███ ███▀▀▀██▄ ▀█████████▄ ███ ███▀▀▀██▄ ███ ███ ███
███ █▀ ███ █▀ ███ ███ ▀███▀▀██ ███▌ ███ ███ ███ █▀ ███
███ ▄███▄▄▄ ███ ███ ███ ▀ ███▌ ███ ███ ▄███▄▄▄ ███
▀███████████ ▀▀███▀▀▀ ███ ███ ███ ███▌ ███ ███ ▀▀███▀▀▀ ███
███ ███ █▄ ███ ███ ███ ███ ███ ███ ███ █▄ ███
▄█ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▌ ▄
▄████████▀ ██████████ ▀█ █▀ ▄████▀ █▀ ▀█ █▀ ██████████ █████▄▄██
⌀ The vigilant guard for code authenticity
`

var rootCmd = &cobra.Command{
Use: "./sentinel",
Use: "sentinel",
Short: "⌀ Sentinel - The vigilant guard for code authenticity.",
Long: `⌀ Sentinel - The vigilant guard for code authenticity.
Long: banner + `
Sentinel uses a hybrid approach (Heuristics + Machine Learning) to
detect patterns indicative of AI-generated source code.

` + "── LANGUAGES SUPPORTED ──────────────────────────────────────────" + `
Python, Java, JavaScript, TypeScript, Go, Rust, C++, Ruby, PHP,
C#, Kotlin, Swift

SUPPORTED LANGUAGES (early support):
Python, Java, JavaScript, TypeScript, Go, Rust, C/C++, Ruby, PHP, C#, Kotlin, Swift
` + "── QUICK START ──────────────────────────────────────────────────" + `
# Scan current directory with default settings
$ ./sentinel scan

QUICK START:
# Scan current directory
./sentinel scan --path .
# Scan with high strictness
$ ./sentinel scan --path ./src --threshold 0.85 --verbose

# Scan with treshold specified
./sentinel scan --path ./your-target-dir --threshold 0.8
# CI/CD: Scan only changed files and fail on detection
$ ./sentinel scan --git-diff main --fail-on-detection

# CI/CD integration that cancel build if an AI-slop is detected
./sentinel scan --git-diff main --fail-on-detection`,
` + "──────────────────────────────────────────────────────────────────",
}

func Execute() {
Expand Down
6 changes: 3 additions & 3 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ func runScan(cmd *cobra.Command, args []string) error {
}
}

det := detector.New(detector.Config{
det := detector.New(detector.DetectorConfiguration{
Threshold: threshold,
Languages: languages,
ExcludePaths: excludePaths,
Verbose: verbose,
IsVerbose: verbose,
ModelPath: modelPath,
UseML: !noML && modelPath != "",
MLWeight: mlWeight,
MLOnly: mlOnly,
IsMLOnly: mlOnly,
})

var files []string
Expand Down
21 changes: 21 additions & 0 deletions examples/ai/python/ai_generated_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def calculate_area(radius):
"""
Calculates the area of a circle given its radius. ✨
"""
import math

# Check if the radius is a positive number 🚀
if radius < 0:
# Raise an error if radius is negative
raise ValueError("The radius cannot be negative. ✅")

# Calculate the area using the formula: PI * r squared
area = math.pi * (radius**2)

# Return the calculated area to the caller
return area


# Example usage of the calculate_area function
if __name__ == "__main__":
print(f"Area: {calculate_area(5)}") # Output the result
20 changes: 20 additions & 0 deletions examples/ai/python/ai_generated_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# System Configuration Constants
# All variables are sorted alphabetically for clarity 🤖
API_KEY = "your_api_key_here"
DATABASE_HOST = "localhost"
DATABASE_NAME = "sentinel_db"
DATABASE_PORT = 5432
DEBUG_MODE = True
LOG_LEVEL = "INFO"
RETRY_ATTEMPTS = 3
TIMEOUT_SECONDS = 30


def initialize_system():
# Initialize the system settings ✨
print("System is initializing with the provided configuration...")
return True


if __name__ == "__main__":
initialize_system()
32 changes: 32 additions & 0 deletions examples/ai/python/ai_generated_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def get_user_data(user_id):
# Ensure user_id is provided
if user_id is None:
return None

# Ensure user_id is an integer
if not isinstance(user_id, int):
return None

try:
# Simulate a database lookup
db_connection = connect_to_db()

if db_connection is None:
return None

data = db_connection.fetch(user_id)

if not data:
return None

return data

except Exception as e:
# Log the exception for debugging
print(f"An unexpected error occurred: {e}")
return None


def connect_to_db():
# Helper to simulate connection
return None
Binary file added model/model.onnx
Binary file not shown.
Loading
Loading