Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.
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
44 changes: 9 additions & 35 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,44 +1,18 @@
# Build artifacts
target/
*.o
*.so
*.a

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# Git
# Ignore build artifacts and development files
.git/
.gitignore
.gitattributes

# CI/CD
.github/

# Documentation (not needed in runtime)
target/
docs/
*.md
!README.md

# Test files
datasets/
LICENSE
tests/
benches/
scripts/
test_data/

# Model files (should be mounted as volumes)
*.onnx
*.gguf
tokenizer.json
model.bin

# Config files (user-specific)
eidos.toml

# Misc
datasets/
.vscode/
.idea/
*.swp
.env
.DS_Store
Thumbs.db
62 changes: 62 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Changelog

All notable changes to the Eidos project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0-beta] - 2025-11-17

### Added
- User config file support (`~/.config/eidos/eidos.toml`)
- Comprehensive command validation module with 7 test suites
- HTTP client timeouts (30s request, 10s connection) to prevent hanging
- Shared tokio runtime in lib_translate for better performance
- Error propagation throughout the application for proper exit codes
- Enhanced documentation and code quality improvements

### Changed
- Config loading priority: env vars > local config > user config > defaults
- Chat and Translate `run()` methods now return `Result` types
- Improved model caching with better Arc usage (no unwrap)
- Extracted validation logic to dedicated module (eliminated duplication)

### Removed
- Dangerous `execute_command()` method from Core (security improvement)
- Duplicate validation tests
- Unimplemented test stubs

### Fixed
- Version number consistency across all files (tests, Dockerfile, docs)
- Config validation now properly returns errors instead of swallowing them
- RwLock usage with proper pattern matching (no unwrap calls)
- Double-check pattern in model cache simplified
- Translation runtime inefficiency (was creating new runtime per request)

### Security
- Removed command execution capability - now display-only
- Enhanced validation prevents shell injection attempts
- Blocks 60+ dangerous command patterns
- Path traversal protection
- IFS manipulation detection

### Performance
- Model caching saves ~2-4 seconds per subsequent request
- Shared runtime saves ~10-50ms per async operation
- Minimal tokio features reduce binary size

## [0.1.0] - 2024

### Added
- Initial release
- Natural language to shell command translation
- AI chat integration (OpenAI, Ollama, custom providers)
- Language detection and translation (75+ languages)
- Docker deployment support
- Comprehensive test suite (38 tests)
- Full documentation

### Security
- Whitelist-based command validation
- Shell injection prevention
- No automatic command execution
16 changes: 14 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "eidos"
version = "0.2.0-beta"
edition = "2021"
rust-version = "1.70"

[dependencies]
clap = { workspace = true }
Expand Down Expand Up @@ -41,7 +42,7 @@ members = [
clap = { version = "4.5.4", features = ["derive"] }
thiserror = "1.0.61"
anyhow = "1.0.75"
tokio = { version = "1.37.0", features = ["full"] }
tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] }
reqwest = { version = "0.12.4", features = ["json", "rustls-tls"] }
serde = { version = "1.0.197", features = ["derive"]}
serde_json = "1.0.115"
Expand All @@ -55,12 +56,23 @@ candle-transformers = "0.9.1"
tokenizers = "0.20"

[profile.release]
opt-level = 2
opt-level = 3
lto = "thin"
codegen-units = 1
panic = "abort"
strip = true

# Maximum performance profile (slower build, ~15% faster runtime)
[profile.release-max]
inherits = "release"
lto = "fat"

# Minimal binary size profile
[profile.release-compact]
inherits = "release"
opt-level = "z"
lto = "fat"

[profile.dev]
opt-level = 0
debug = true
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ ENV EIDOS_TOKENIZER_PATH=/home/eidos/tokenizer.json
# Create volume mount points for models
VOLUME ["/home/eidos/models"]

# Health check to ensure the binary is functional
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD eidos --version || exit 1

ENTRYPOINT ["eidos"]
CMD ["--help"]

# Labels
LABEL org.opencontainers.image.title="Eidos" \
org.opencontainers.image.description="AI-powered CLI for Linux command generation" \
org.opencontainers.image.version="0.1.0" \
org.opencontainers.image.version="0.2.0-beta" \
org.opencontainers.image.authors="EIDOS Team" \
org.opencontainers.image.source="https://github.com/Ru1vly/eidos"
20 changes: 7 additions & 13 deletions benches/core_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use lib_core::Core;
use std::path::PathBuf;

fn benchmark_core_creation(c: &mut Criterion) {
c.bench_function("core_new", |b| {
b.iter(|| {
// Note: This will fail without valid model files, but demonstrates the benchmark structure
// In a real scenario, you'd have test fixtures
let _ = Core::new(
black_box("model.onnx"),
black_box("tokenizer.json"),
);
let _ = Core::new(black_box("model.onnx"), black_box("tokenizer.json"));
})
});
}
Expand All @@ -22,13 +18,7 @@ fn benchmark_command_validation(c: &mut Criterion) {
b.iter(|| {
// This benchmarks the validation logic indirectly
// by attempting to validate various commands
let commands = vec![
"ls -la",
"pwd",
"echo hello",
"cd ..",
"mkdir test",
];
let commands = vec!["ls -la", "pwd", "echo hello", "cd ..", "mkdir test"];

for cmd in commands {
// Just time the validation part
Expand All @@ -38,5 +28,9 @@ fn benchmark_command_validation(c: &mut Criterion) {
});
}

criterion_group!(benches, benchmark_core_creation, benchmark_command_validation);
criterion_group!(
benches,
benchmark_core_creation,
benchmark_command_validation
);
criterion_main!(benches);
152 changes: 152 additions & 0 deletions docs/SAFETY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Safety & Security Model

This document explains Eidos' security philosophy and the rationale behind command validation decisions.

## Core Principle: Display-Only, Never Execute

**Eidos NEVER executes commands automatically.** All generated commands are displayed for user review before execution. This is the foundational security layer.

## Command Validation Strategy

### Defense-in-Depth Layers

1. **Whitelist-Only Base Commands**
- Only 23 read-only commands are allowed
- Commands cannot modify system state
- Examples: `ls`, `pwd`, `cat`, `grep`, `find`

2. **Dangerous Command Blocking**
- 60+ destructive commands explicitly blocked
- Includes: `rm`, `dd`, `chmod`, `sudo`, network tools, etc.

3. **Shell Injection Prevention**
- All shell metacharacters rejected: `|`, `&`, `;`, `$()`, backticks
- Quotes blocked (prevents string arguments with malicious content)
- Redirects blocked: `>`, `>>`, `<`

4. **Path Traversal Protection**
- Blocks `../` patterns
- Blocks sensitive directories: `/dev/`, `/proc/`, `/sys/`, `~/.ssh/`

5. **Encoding Attack Prevention**
- Hex-encoded characters blocked: `\\x`
- Octal-encoded characters blocked: `\\0`
- IFS manipulation blocked

### Why This Approach?

**False Positives > False Negatives**

We intentionally reject many legitimate commands to ensure no dangerous commands pass through. Examples:

- ❌ `cat "my file.txt"` - Rejected (contains quotes)
- ❌ `ls *.txt` - Rejected (contains wildcard)
- ✅ `cat file.txt` - Allowed (simple arguments)

This is acceptable because:
1. Users can still execute any command manually
2. The tool is for **generating** commands, not executing them
3. Better to be overly cautious than risk system damage

## Whitelisted Commands

### Information Gathering (11)
- `ls` - List directory contents
- `pwd` - Print working directory
- `whoami` - Show current user
- `hostname` - Show hostname
- `uname` - Show system information
- `date` - Show date/time
- `which` - Show command location
- `whereis` - Locate binary/source/manual
- `file` - Determine file type
- `stat` - Display file status
- `free` - Show memory usage

### File Reading (4)
- `cat` - Concatenate and display files
- `head` - Show first lines of file
- `tail` - Show last lines of file
- `grep` - Search file contents

### File Analysis (2)
- `wc` - Word/line/character count
- `find` - Search for files (NOTE: `-exec` is blocked)

### System Monitoring (3)
- `df` - Show disk usage
- `du` - Show directory size
- `top` - Show processes
- `ps` - Show process status

### File Operations (Read-Only) (2)
- `touch` - Update timestamp (allowed for creating empty files)
- `mkdir` - Create directory (allowed as non-destructive)

## Blocked Command Categories

### Destructive Operations
- File deletion: `rm`, `rmdir`
- Disk operations: `dd`, `mkfs`, `fdisk`
- Permission changes: `chmod`, `chown`, `chgrp`

### System Control
- Power: `shutdown`, `reboot`, `halt`, `poweroff`
- Process: `kill`, `killall`, `pkill`
- Init: `init`, `systemctl`

### Privilege Escalation
- `sudo`, `su`, `doas`
- User management: `useradd`, `userdel`, `passwd`

### Network Operations
- Download: `curl`, `wget`
- Transfer: `scp`, `sftp`, `rsync`
- Connection: `ssh`, `telnet`, `nc`, `netcat`

### Filesystem Operations
- Mounting: `mount`, `umount`, `mkswap`, `swapon`
- Firewall: `iptables`, `ip6tables`, `nft`

## Security Testing

All 60+ dangerous patterns are tested in:
- `lib_core/src/validation.rs` (8 test suites)
- Continuous integration verifies all tests pass

## Adding New Commands

To add a new whitelisted command:

1. **Verify it's read-only** - Must not modify system state
2. **Add to whitelist** in `lib_core/src/validation.rs`
3. **Add tests** for the new command
4. **Update this document** with rationale
5. **Security review** - Get approval from maintainers

## Future Enhancements

Considered for future releases:

1. **Configurable validation levels**
- Conservative (current)
- Balanced (allow quoted arguments)
- Permissive (allow more commands)

2. **Command-specific validators**
- `find` with `-exec` blocked
- `grep` with specific flag whitelist

3. **Machine learning classification**
- Train on dangerous command corpus
- Probabilistic scoring

## References

- OWASP Command Injection: https://owasp.org/www-community/attacks/Command_Injection
- CWE-78: https://cwe.mitre.org/data/definitions/78.html

---

Last updated: 2025-11-17
Version: 0.2.0-beta
Loading
Loading