An AI-powered Linux productivity assistant for command analysis, troubleshooting, and knowledge management.
Project description
Smart Linux Assistant
Smart Linux Assistant is an AI-powered Linux operations assistant that understands natural language, safely executes shell commands, retrieves Linux knowledge, explains errors, and assists users with troubleshooting. The current version implements the core command execution engine and foundational architecture for future AI capabilities.
Project Overview
Smart Linux Assistant is a command-line utility that executes shell commands and returns structured outcomes. The tool captures the command, exit code, stdout, stderr, execution timestamp, and duration to make downstream automation and logging straightforward.
System Architecture
- CLI (
linux_assistant.cli.main) accepts user commands and options and delegates execution toCommandExecutor. CommandExecutorruns shell commands usingsubprocess.runand returns aCommandResultdataclass describing the outcome.- Centralized logging is provided by
linux_assistant.utils.logger, writing tologs/smart_linux_assistant.logwith rotation. - Runtime paths and directories are managed by
linux_assistant.config.settingsand can be initialized withinitialize_app_filesystem().
Tech Stack
- Python 3.11+
- Typer (CLI)
- Standard library:
subprocess,logging,shutil,dataclasses,pathlib,datetime
Prerequisites
- Python 3.11 or newer.
- Optional: a virtual environment tool (
venv). - No Dockerfile or docker-compose are included in this repository.
Local Setup & Installation
- Clone the repository:
git clone https://github.com/shubham-k-jha-dev/smart-linux-assistant
cd smart-linux-assistant
- Create and activate a virtual environment:
# Linux/macOS
python3 -m venv .venv
source .venv/bin/activate
# Windows (PowerShell)
python -m venv .venv
.venv\\Scripts\\Activate.ps1
- Install development dependencies:
pip install -r requirements-dev.txt
- (Optional) Install the package in editable mode to enable the
smart-linuxCLI entrypoint:
pip install -e .
- (Optional) Ensure runtime directories exist from Python:
from linux_assistant.config.settings import initialize_app_filesystem
initialize_app_filesystem()
Environment Variables
This project does not require any environment variables for its core CLI functionality. The repository includes an empty .env.example placeholder.
| Variable | Description | Example |
|---|---|---|
| (none) | No required environment variables for CLI execution | - |
Usage / API Reference
The project exposes the console scripts smart-linux and sla (configured in pyproject.toml).
- Run a shell command:
smart-linux run "echo hello"
-
Options:
--timeout <seconds>— maximum seconds to allow command to run (default: 30)--check— treat non-zero exit codes as errors and exit with that code--suggest-fix— if the command fails, use AI to suggest a corrected version (requires--check; requiresGROQ_API_KEY, same asexplain/fix/search)
-
Doctor command (checks common tools):
smart-linux doctor
- Get an AI-powered explanation of a command or error message:
smart-linux explain "permission denied when running ./script.sh"
Requires a free Groq API key set as an environment variable:
export GROQ_API_KEY="your-key-here"
Get a free key at console.groq.com.
- Fix a failing command:
smart-linux fix "ls /nonexistent"
-
Options:
--timeout <seconds>— maximum seconds to allow the command to run (default: 30)
-
This runs the command and, if it fails, uses the AI to suggest a corrected version. Requires the same
GROQ_API_KEYenvironment variable as theexplaincommand. -
Search for a Linux task in plain language:
smart-linux search "find the 10 largest files in the current directory"
- This returns a concrete command and brief explanation for the requested task. Requires the same
GROQ_API_KEYenvironment variable as theexplaincommand.
Example output
Successful command:
$ smart-linux run "echo hello"
hello
Failed command (example):
$ smart-linux run "ls nonexistent" --check
ls: cannot access 'nonexistent': No such file or directory
These outputs reflect the CLI behaviour: standard output is printed for successful commands; standard error is printed for failures and, when --check is used, the CLI exits with the command's exit code.
Failed command with an AI-suggested fix:
$ smart-linux run "gti status" --check --suggest-fix
gti: command not found
Suggested fix:
git status
--suggest-fix requires --check (fix suggestions only apply to command failures detected via --check); calling it without --check exits immediately with an error.
Roadmap / Current Status
- Core CLI: implemented —
runanddoctorcommands are provided inlinux_assistant.cli.main. - Command execution: implemented using
linux_assistant.services.command_executor.CommandExecutorwhich returnsCommandResultinstances. - Logging & configuration: implemented via
linux_assistant.utils.loggerandlinux_assistant.config.settings. - Packaging: console script entry points are declared in
pyproject.toml. - AI-powered explanations: implemented —
smart-linux explainuses the Groq API (llama-3.3-70b-versatile) to generate plain-language explanations of commands and error messages, vialinux_assistant.services.explainer.Explainer. Requires a user-suppliedGROQ_API_KEYenvironment variable. - AI-powered fix suggestions: implemented —
smart-linux fixruns a failing command and suggests a corrected version;smart-linux run --check --suggest-fixoffers the same suggestion inline as part of normal command execution. Both uselinux_assistant.services.explainer.Explainer.suggest_fix(). - AI-powered search: implemented —
smart-linux searchanswers natural-language questions about Linux tasks vialinux_assistant.services.search.Searcher. - Production hardening: implemented — API timeouts, retry logic, rate-limit-specific handling, input truncation, and documented OS/privacy limitations across all AI-backed commands.
- Additional AI features (command history awareness, documentation lookup) are planned but not yet implemented.
Known Limitations
- Tested and verified on Linux (native and WSL). Not yet tested on macOS or native Windows Python — behavior on those platforms is currently unverified, though the codebase avoids Linux-only APIs where possible.
Privacy Note
The explain, fix, and search commands send the command text, error output, or your query to Groq's API for processing. Avoid running these commands on text that contains secrets, passwords, or sensitive data, since that content leaves your machine.
Install from PyPI
If this package is published to PyPI, it can be installed with:
pip install smart-linux-assistant
Testing
Run the test suite with pytest:
pytest
License
MIT License — see LICENSE.
Contributing
- Run tests with
pytestbefore opening a pull request. - Follow standard Python packaging best practices.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smart_linux_assistant-0.5.0.tar.gz.
File metadata
- Download URL: smart_linux_assistant-0.5.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59d5659feb7cd6c31997a53a868fef211bcb13dfcd52b0b02cedf517aa64d7d8
|
|
| MD5 |
f5baabe68ca0ba4ac9345dc2463845a7
|
|
| BLAKE2b-256 |
377747cffd2f239826a5b2c17230753a2885bd433712c7515a78aa2e909bb122
|
File details
Details for the file smart_linux_assistant-0.5.0-py3-none-any.whl.
File metadata
- Download URL: smart_linux_assistant-0.5.0-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
555ec8cc60dc80d3c31abe68a42b82bbc26852ecf87ae24519468e7fc640472f
|
|
| MD5 |
ef0264c9f9d240ed7e92554a3cdb6dbb
|
|
| BLAKE2b-256 |
65332c5c9e6c9fb5b4cca4f0b0e938fd36611d942e455399bbde5a122372be69
|