smart-linux-assistant 0.7.0__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {smart_linux_assistant-0.7.0/smart_linux_assistant.egg-info → smart_linux_assistant-0.8.0}/PKG-INFO +46 -46
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/README.md +45 -45
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/cli/main.py +51 -3
- smart_linux_assistant-0.8.0/linux_assistant/core/safety.py +26 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/pyproject.toml +1 -1
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0/smart_linux_assistant.egg-info}/PKG-INFO +46 -46
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/smart_linux_assistant.egg-info/SOURCES.txt +2 -0
- smart_linux_assistant-0.8.0/tests/test_safety.py +18 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/LICENSE +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/__init__.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/cli/__init__.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/config/__init__.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/config/settings.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/core/__init__.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/exceptions/__init__.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/exceptions/base.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/models/__init__.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/models/command_result.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/models/history_entry.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/repositories/__init__.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/repositories/history_repository.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/services/__init__.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/services/command_executor.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/services/explainer.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/services/search.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/utils/__init__.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/utils/groq_client.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/utils/logger.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/utils/redactor.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/utils/shell.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/setup.cfg +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/smart_linux_assistant.egg-info/dependency_links.txt +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/smart_linux_assistant.egg-info/entry_points.txt +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/smart_linux_assistant.egg-info/requires.txt +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/smart_linux_assistant.egg-info/top_level.txt +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/tests/test_cli.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/tests/test_command_executor.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/tests/test_explainer.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/tests/test_groq_client.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/tests/test_history_repository.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/tests/test_redactor.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/tests/test_search.py +0 -0
- {smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/tests/test_shell.py +0 -0
{smart_linux_assistant-0.7.0/smart_linux_assistant.egg-info → smart_linux_assistant-0.8.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: smart-linux-assistant
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: An AI-powered Linux productivity assistant for command analysis, troubleshooting, and knowledge management.
|
|
5
5
|
Author: Shubham Kumar Jha
|
|
6
6
|
License: MIT
|
|
@@ -29,26 +29,22 @@ Dynamic: license-file
|
|
|
29
29
|
|
|
30
30
|
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.
|
|
31
31
|
|
|
32
|
-

|
|
33
|
-

|
|
34
|
-
[](https://github.com/shubham-k-jha-dev/smart-linux-assistant/actions/workflows/ci.yml)
|
|
35
|
-
|
|
36
32
|
## Project Overview
|
|
37
33
|
|
|
38
34
|
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.
|
|
39
35
|
|
|
40
36
|
## System Architecture
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
* CLI (`linux_assistant.cli.main`) accepts user commands and options and delegates execution to `CommandExecutor`.
|
|
39
|
+
* `CommandExecutor` runs shell commands using `subprocess.run` and returns a `CommandResult` dataclass describing the outcome.
|
|
40
|
+
* Centralized logging is provided by `linux_assistant.utils.logger`, writing to `logs/smart_linux_assistant.log` with rotation.
|
|
41
|
+
* Runtime paths and directories are managed by `linux_assistant.config.settings` and can be initialized with `initialize_app_filesystem()`.
|
|
46
42
|
|
|
47
43
|
## Tech Stack
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
* Python 3.11+
|
|
46
|
+
* Typer (CLI)
|
|
47
|
+
* Standard library: `subprocess`, `logging`, `shutil`, `dataclasses`, `pathlib`, `datetime`
|
|
52
48
|
|
|
53
49
|
## Prerequisites
|
|
54
50
|
|
|
@@ -101,7 +97,7 @@ initialize_app_filesystem()
|
|
|
101
97
|
This project does not require any environment variables for its core CLI functionality. The repository includes an empty `.env.example` placeholder.
|
|
102
98
|
|
|
103
99
|
| Variable | Description | Example |
|
|
104
|
-
|
|
100
|
+
| --- | --- | --- |
|
|
105
101
|
| (none) | No required environment variables for CLI execution | - |
|
|
106
102
|
|
|
107
103
|
## Usage / API Reference
|
|
@@ -114,56 +110,57 @@ By default, the CLI stays quiet — internal logs are written only to the log fi
|
|
|
114
110
|
smart-linux --verbose run "echo hello"
|
|
115
111
|
```
|
|
116
112
|
|
|
117
|
-
|
|
113
|
+
* Run a shell command:
|
|
118
114
|
|
|
119
115
|
```bash
|
|
120
116
|
smart-linux run "echo hello"
|
|
121
117
|
```
|
|
122
118
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
* Options:
|
|
120
|
+
* `--timeout <seconds>` — maximum seconds to allow command to run (default: 30)
|
|
121
|
+
* `--check` — treat non-zero exit codes as errors and exit with that code
|
|
122
|
+
* `--suggest-fix` — if the command fails, use AI to suggest a corrected version (requires `--check`; requires `GROQ_API_KEY`, same as `explain`/`fix`/`search`)
|
|
123
|
+
|
|
127
124
|
|
|
128
|
-
|
|
125
|
+
* Doctor command (checks common tools):
|
|
129
126
|
|
|
130
127
|
```bash
|
|
131
128
|
smart-linux doctor
|
|
132
129
|
```
|
|
133
|
-
|
|
130
|
+
|
|
131
|
+
* Get an AI-powered explanation of a command or error message:
|
|
134
132
|
|
|
135
133
|
```bash
|
|
136
134
|
smart-linux explain "permission denied when running ./script.sh"
|
|
137
135
|
```
|
|
138
136
|
|
|
139
|
-
|
|
137
|
+
Requires a free Groq API key set as an environment variable:
|
|
140
138
|
|
|
141
139
|
```bash
|
|
142
140
|
export GROQ_API_KEY="your-key-here"
|
|
143
141
|
```
|
|
144
142
|
|
|
145
|
-
|
|
143
|
+
Get a free key at [console.groq.com](https://console.groq.com).
|
|
146
144
|
|
|
147
|
-
|
|
145
|
+
* Fix a failing command:
|
|
148
146
|
|
|
149
147
|
```bash
|
|
150
148
|
smart-linux fix "ls /nonexistent"
|
|
151
149
|
```
|
|
152
150
|
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
* Options:
|
|
152
|
+
* `--timeout <seconds>` — maximum seconds to allow the command to run (default: 30)
|
|
155
153
|
|
|
156
|
-
- This runs the command and, if it fails, uses the AI to suggest a corrected version. Requires the same `GROQ_API_KEY` environment variable as the `explain` command.
|
|
157
154
|
|
|
158
|
-
|
|
155
|
+
* This runs the command and, if it fails, uses the AI to suggest a corrected version, then **interactively prompts you to execute the fix safely**. Requires the same `GROQ_API_KEY` environment variable as the `explain` command.
|
|
156
|
+
* Search for a Linux task in plain language:
|
|
159
157
|
|
|
160
158
|
```bash
|
|
161
159
|
smart-linux search "find the 10 largest files in the current directory"
|
|
162
160
|
```
|
|
163
161
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
- View or manage recorded command history:
|
|
162
|
+
* This returns a concrete command and brief explanation for the requested task, and **interactively prompts you to execute the command directly**. Requires the same `GROQ_API_KEY` environment variable as the `explain` command.
|
|
163
|
+
* View or manage recorded command history:
|
|
167
164
|
|
|
168
165
|
```bash
|
|
169
166
|
smart-linux history
|
|
@@ -171,7 +168,7 @@ smart-linux history --failures-only
|
|
|
171
168
|
smart-linux history clear
|
|
172
169
|
```
|
|
173
170
|
|
|
174
|
-
|
|
171
|
+
Every `run` invocation (success or failure) is recorded locally in a SQLite database, storing the command text, exit code, duration, working directory, and — only for failed commands — a truncated snippet of stderr. `stdout` is never stored. History is capped at 5,000 entries (oldest entries are pruned automatically) and can be disabled entirely by setting `SMART_LINUX_NO_HISTORY=1`.
|
|
175
172
|
|
|
176
173
|
### Example output
|
|
177
174
|
|
|
@@ -205,26 +202,29 @@ Suggested fix:
|
|
|
205
202
|
|
|
206
203
|
## Roadmap / Current Status
|
|
207
204
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
-
|
|
205
|
+
* Core CLI: implemented — `run` and `doctor` commands are provided in `linux_assistant.cli.main`.
|
|
206
|
+
* Command execution: implemented using `linux_assistant.services.command_executor.CommandExecutor` which returns `CommandResult` instances.
|
|
207
|
+
* Logging & configuration: implemented via `linux_assistant.utils.logger` and `linux_assistant.config.settings`.
|
|
208
|
+
* Packaging: console script entry points are declared in `pyproject.toml`.
|
|
209
|
+
* AI-powered explanations: implemented — `smart-linux explain` uses the Groq API (`llama-3.3-70b-versatile`) to generate plain-language explanations of commands and error messages, via `linux_assistant.services.explainer.Explainer`. Requires a user-supplied `GROQ_API_KEY` environment variable.
|
|
210
|
+
* AI-powered fix suggestions: implemented — `smart-linux fix` runs a failing command and suggests a corrected version; `smart-linux run --check --suggest-fix` offers the same suggestion inline as part of normal command execution. Both use `linux_assistant.services.explainer.Explainer.suggest_fix()`.
|
|
211
|
+
* AI-powered search: implemented — `smart-linux search` answers natural-language questions about Linux tasks via `linux_assistant.services.search.Searcher`.
|
|
212
|
+
* Production hardening & Safety: implemented — API timeouts, retry logic, rate-limit-specific handling, input truncation, regex-based secret redaction, and a **Heuristic Safety Interceptor (`linux_assistant.core.safety`)** to detect and block destructive commands (like `rm -rf`, `mkfs`, `dd`) before execution.
|
|
213
|
+
* Agentic Execution: implemented — `smart-linux fix` and `smart-linux search` now feature interactive confirmation prompts (`_prompt_and_execute`), allowing users to review AI-suggested commands and execute them instantly with safety guardrails.
|
|
214
|
+
* Command history: implemented — `smart-linux run` records every invocation locally via `linux_assistant.repositories.history_repository.HistoryRepository` (SQLite-backed, FIFO-capped at 5,000 rows). View with `smart-linux history` (supports `--failures-only`), erase with `smart-linux history clear`, or disable entirely via `SMART_LINUX_NO_HISTORY=1`. AI Context Injection is implemented: `explain` and `fix` commands dynamically fetch the last 5 chronological commands to give the LLM workflow awareness, protected by graceful degradation if the database is locked.
|
|
215
|
+
* Additional AI features (documentation lookup) are planned but not yet implemented.
|
|
218
216
|
|
|
219
217
|
## Known Limitations
|
|
220
218
|
|
|
221
|
-
|
|
219
|
+
* 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.
|
|
222
220
|
|
|
223
221
|
## Privacy Note
|
|
224
222
|
|
|
225
|
-
The `explain`, `fix`, and `search` commands send the command text, error output, or your query to Groq's API for processing.
|
|
223
|
+
The `explain`, `fix`, and `search` commands send the command text, error output, or your query to Groq's API for processing. The explain, fix, and search commands send your terminal queries to Groq's API for processing. Starting in v0.7.0, `explain` and `fix` also securely read your recent local command history to provide context-aware solutions.
|
|
224
|
+
|
|
225
|
+
Security First: Before any history leaves your machine, it passes through a local Regex Redactor `(linux_assistant.utils.redactor)` which automatically scrubs standard environment variables, inline passwords, and Bearer tokens, replacing them with [REDACTED]. However, you should still exercise caution and avoid running these commands on highly sensitive plaintext data.
|
|
226
226
|
|
|
227
|
-
Separately, `smart-linux run` records
|
|
227
|
+
Separately, `smart-linux run` records your command invocations (command text, exit code, duration, working directory, and truncated stderr) in a local SQLite database. `stdout` is never recorded. To disable history recording entirely, set `SMART_LINUX_NO_HISTORY=1`. To view or erase recorded history, use `smart-linux history` and `smart-linux history clear`.
|
|
228
228
|
|
|
229
229
|
## Install from PyPI
|
|
230
230
|
|
|
@@ -248,5 +248,5 @@ MIT License — see `LICENSE`.
|
|
|
248
248
|
|
|
249
249
|
## Contributing
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
251
|
+
* Run tests with `pytest` before opening a pull request.
|
|
252
|
+
* Follow standard Python packaging best practices.
|
|
@@ -2,26 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
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.
|
|
4
4
|
|
|
5
|
-

|
|
6
|
-

|
|
7
|
-
[](https://github.com/shubham-k-jha-dev/smart-linux-assistant/actions/workflows/ci.yml)
|
|
8
|
-
|
|
9
5
|
## Project Overview
|
|
10
6
|
|
|
11
7
|
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.
|
|
12
8
|
|
|
13
9
|
## System Architecture
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
* CLI (`linux_assistant.cli.main`) accepts user commands and options and delegates execution to `CommandExecutor`.
|
|
12
|
+
* `CommandExecutor` runs shell commands using `subprocess.run` and returns a `CommandResult` dataclass describing the outcome.
|
|
13
|
+
* Centralized logging is provided by `linux_assistant.utils.logger`, writing to `logs/smart_linux_assistant.log` with rotation.
|
|
14
|
+
* Runtime paths and directories are managed by `linux_assistant.config.settings` and can be initialized with `initialize_app_filesystem()`.
|
|
19
15
|
|
|
20
16
|
## Tech Stack
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
* Python 3.11+
|
|
19
|
+
* Typer (CLI)
|
|
20
|
+
* Standard library: `subprocess`, `logging`, `shutil`, `dataclasses`, `pathlib`, `datetime`
|
|
25
21
|
|
|
26
22
|
## Prerequisites
|
|
27
23
|
|
|
@@ -74,7 +70,7 @@ initialize_app_filesystem()
|
|
|
74
70
|
This project does not require any environment variables for its core CLI functionality. The repository includes an empty `.env.example` placeholder.
|
|
75
71
|
|
|
76
72
|
| Variable | Description | Example |
|
|
77
|
-
|
|
73
|
+
| --- | --- | --- |
|
|
78
74
|
| (none) | No required environment variables for CLI execution | - |
|
|
79
75
|
|
|
80
76
|
## Usage / API Reference
|
|
@@ -87,56 +83,57 @@ By default, the CLI stays quiet — internal logs are written only to the log fi
|
|
|
87
83
|
smart-linux --verbose run "echo hello"
|
|
88
84
|
```
|
|
89
85
|
|
|
90
|
-
|
|
86
|
+
* Run a shell command:
|
|
91
87
|
|
|
92
88
|
```bash
|
|
93
89
|
smart-linux run "echo hello"
|
|
94
90
|
```
|
|
95
91
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
* Options:
|
|
93
|
+
* `--timeout <seconds>` — maximum seconds to allow command to run (default: 30)
|
|
94
|
+
* `--check` — treat non-zero exit codes as errors and exit with that code
|
|
95
|
+
* `--suggest-fix` — if the command fails, use AI to suggest a corrected version (requires `--check`; requires `GROQ_API_KEY`, same as `explain`/`fix`/`search`)
|
|
96
|
+
|
|
100
97
|
|
|
101
|
-
|
|
98
|
+
* Doctor command (checks common tools):
|
|
102
99
|
|
|
103
100
|
```bash
|
|
104
101
|
smart-linux doctor
|
|
105
102
|
```
|
|
106
|
-
|
|
103
|
+
|
|
104
|
+
* Get an AI-powered explanation of a command or error message:
|
|
107
105
|
|
|
108
106
|
```bash
|
|
109
107
|
smart-linux explain "permission denied when running ./script.sh"
|
|
110
108
|
```
|
|
111
109
|
|
|
112
|
-
|
|
110
|
+
Requires a free Groq API key set as an environment variable:
|
|
113
111
|
|
|
114
112
|
```bash
|
|
115
113
|
export GROQ_API_KEY="your-key-here"
|
|
116
114
|
```
|
|
117
115
|
|
|
118
|
-
|
|
116
|
+
Get a free key at [console.groq.com](https://console.groq.com).
|
|
119
117
|
|
|
120
|
-
|
|
118
|
+
* Fix a failing command:
|
|
121
119
|
|
|
122
120
|
```bash
|
|
123
121
|
smart-linux fix "ls /nonexistent"
|
|
124
122
|
```
|
|
125
123
|
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
* Options:
|
|
125
|
+
* `--timeout <seconds>` — maximum seconds to allow the command to run (default: 30)
|
|
128
126
|
|
|
129
|
-
- This runs the command and, if it fails, uses the AI to suggest a corrected version. Requires the same `GROQ_API_KEY` environment variable as the `explain` command.
|
|
130
127
|
|
|
131
|
-
|
|
128
|
+
* This runs the command and, if it fails, uses the AI to suggest a corrected version, then **interactively prompts you to execute the fix safely**. Requires the same `GROQ_API_KEY` environment variable as the `explain` command.
|
|
129
|
+
* Search for a Linux task in plain language:
|
|
132
130
|
|
|
133
131
|
```bash
|
|
134
132
|
smart-linux search "find the 10 largest files in the current directory"
|
|
135
133
|
```
|
|
136
134
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
- View or manage recorded command history:
|
|
135
|
+
* This returns a concrete command and brief explanation for the requested task, and **interactively prompts you to execute the command directly**. Requires the same `GROQ_API_KEY` environment variable as the `explain` command.
|
|
136
|
+
* View or manage recorded command history:
|
|
140
137
|
|
|
141
138
|
```bash
|
|
142
139
|
smart-linux history
|
|
@@ -144,7 +141,7 @@ smart-linux history --failures-only
|
|
|
144
141
|
smart-linux history clear
|
|
145
142
|
```
|
|
146
143
|
|
|
147
|
-
|
|
144
|
+
Every `run` invocation (success or failure) is recorded locally in a SQLite database, storing the command text, exit code, duration, working directory, and — only for failed commands — a truncated snippet of stderr. `stdout` is never stored. History is capped at 5,000 entries (oldest entries are pruned automatically) and can be disabled entirely by setting `SMART_LINUX_NO_HISTORY=1`.
|
|
148
145
|
|
|
149
146
|
### Example output
|
|
150
147
|
|
|
@@ -178,26 +175,29 @@ Suggested fix:
|
|
|
178
175
|
|
|
179
176
|
## Roadmap / Current Status
|
|
180
177
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
-
|
|
178
|
+
* Core CLI: implemented — `run` and `doctor` commands are provided in `linux_assistant.cli.main`.
|
|
179
|
+
* Command execution: implemented using `linux_assistant.services.command_executor.CommandExecutor` which returns `CommandResult` instances.
|
|
180
|
+
* Logging & configuration: implemented via `linux_assistant.utils.logger` and `linux_assistant.config.settings`.
|
|
181
|
+
* Packaging: console script entry points are declared in `pyproject.toml`.
|
|
182
|
+
* AI-powered explanations: implemented — `smart-linux explain` uses the Groq API (`llama-3.3-70b-versatile`) to generate plain-language explanations of commands and error messages, via `linux_assistant.services.explainer.Explainer`. Requires a user-supplied `GROQ_API_KEY` environment variable.
|
|
183
|
+
* AI-powered fix suggestions: implemented — `smart-linux fix` runs a failing command and suggests a corrected version; `smart-linux run --check --suggest-fix` offers the same suggestion inline as part of normal command execution. Both use `linux_assistant.services.explainer.Explainer.suggest_fix()`.
|
|
184
|
+
* AI-powered search: implemented — `smart-linux search` answers natural-language questions about Linux tasks via `linux_assistant.services.search.Searcher`.
|
|
185
|
+
* Production hardening & Safety: implemented — API timeouts, retry logic, rate-limit-specific handling, input truncation, regex-based secret redaction, and a **Heuristic Safety Interceptor (`linux_assistant.core.safety`)** to detect and block destructive commands (like `rm -rf`, `mkfs`, `dd`) before execution.
|
|
186
|
+
* Agentic Execution: implemented — `smart-linux fix` and `smart-linux search` now feature interactive confirmation prompts (`_prompt_and_execute`), allowing users to review AI-suggested commands and execute them instantly with safety guardrails.
|
|
187
|
+
* Command history: implemented — `smart-linux run` records every invocation locally via `linux_assistant.repositories.history_repository.HistoryRepository` (SQLite-backed, FIFO-capped at 5,000 rows). View with `smart-linux history` (supports `--failures-only`), erase with `smart-linux history clear`, or disable entirely via `SMART_LINUX_NO_HISTORY=1`. AI Context Injection is implemented: `explain` and `fix` commands dynamically fetch the last 5 chronological commands to give the LLM workflow awareness, protected by graceful degradation if the database is locked.
|
|
188
|
+
* Additional AI features (documentation lookup) are planned but not yet implemented.
|
|
191
189
|
|
|
192
190
|
## Known Limitations
|
|
193
191
|
|
|
194
|
-
|
|
192
|
+
* 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.
|
|
195
193
|
|
|
196
194
|
## Privacy Note
|
|
197
195
|
|
|
198
|
-
The `explain`, `fix`, and `search` commands send the command text, error output, or your query to Groq's API for processing.
|
|
196
|
+
The `explain`, `fix`, and `search` commands send the command text, error output, or your query to Groq's API for processing. The explain, fix, and search commands send your terminal queries to Groq's API for processing. Starting in v0.7.0, `explain` and `fix` also securely read your recent local command history to provide context-aware solutions.
|
|
197
|
+
|
|
198
|
+
Security First: Before any history leaves your machine, it passes through a local Regex Redactor `(linux_assistant.utils.redactor)` which automatically scrubs standard environment variables, inline passwords, and Bearer tokens, replacing them with [REDACTED]. However, you should still exercise caution and avoid running these commands on highly sensitive plaintext data.
|
|
199
199
|
|
|
200
|
-
Separately, `smart-linux run` records
|
|
200
|
+
Separately, `smart-linux run` records your command invocations (command text, exit code, duration, working directory, and truncated stderr) in a local SQLite database. `stdout` is never recorded. To disable history recording entirely, set `SMART_LINUX_NO_HISTORY=1`. To view or erase recorded history, use `smart-linux history` and `smart-linux history clear`.
|
|
201
201
|
|
|
202
202
|
## Install from PyPI
|
|
203
203
|
|
|
@@ -221,5 +221,5 @@ MIT License — see `LICENSE`.
|
|
|
221
221
|
|
|
222
222
|
## Contributing
|
|
223
223
|
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
* Run tests with `pytest` before opening a pull request.
|
|
225
|
+
* Follow standard Python packaging best practices.
|
|
@@ -14,6 +14,7 @@ from linux_assistant.utils.logger import get_logger, set_verbose
|
|
|
14
14
|
from linux_assistant.utils.shell import command_exists
|
|
15
15
|
from linux_assistant.services.search import Searcher
|
|
16
16
|
from linux_assistant.models.history_entry import HistoryEntry
|
|
17
|
+
from linux_assistant.core.safety import is_dangerous_command
|
|
17
18
|
|
|
18
19
|
logger = get_logger(__name__)
|
|
19
20
|
|
|
@@ -133,6 +134,11 @@ def run(
|
|
|
133
134
|
else:
|
|
134
135
|
typer.secho("Suggested fix:", fg=typer.colors.CYAN)
|
|
135
136
|
typer.echo(f" {suggestion}")
|
|
137
|
+
# Capture or pass through, but keep original exit code
|
|
138
|
+
try:
|
|
139
|
+
_prompt_and_execute(suggestion)
|
|
140
|
+
except typer.Exit:
|
|
141
|
+
pass
|
|
136
142
|
|
|
137
143
|
raise typer.Exit(code=exc.result.exit_code)
|
|
138
144
|
|
|
@@ -230,7 +236,7 @@ def fix(
|
|
|
230
236
|
timeout: int = typer.Option(30, help="Timeout in seconds."),
|
|
231
237
|
) -> None:
|
|
232
238
|
"""
|
|
233
|
-
Run a command, and if it fails, suggest a corrected version.
|
|
239
|
+
Run a command, and if it fails, suggest a corrected version and prompt for execution.
|
|
234
240
|
"""
|
|
235
241
|
executor = CommandExecutor()
|
|
236
242
|
|
|
@@ -281,8 +287,8 @@ def fix(
|
|
|
281
287
|
typer.secho("Suggested fix:", fg=typer.colors.CYAN)
|
|
282
288
|
typer.echo(f" {suggestion}")
|
|
283
289
|
typer.echo()
|
|
284
|
-
typer.echo(f'Run it manually, or try: smart-linux run "{suggestion}"')
|
|
285
290
|
|
|
291
|
+
_prompt_and_execute(suggestion)
|
|
286
292
|
raise typer.Exit(code=1)
|
|
287
293
|
|
|
288
294
|
@app.command()
|
|
@@ -292,7 +298,7 @@ def search(
|
|
|
292
298
|
),
|
|
293
299
|
) -> None:
|
|
294
300
|
"""
|
|
295
|
-
Search for how to accomplish a Linux task in plain language.
|
|
301
|
+
Search for how to accomplish a Linux task in plain language and prompt for execution.
|
|
296
302
|
"""
|
|
297
303
|
if not query.strip():
|
|
298
304
|
typer.secho("Invalid input: Search query cannot be empty.", fg=typer.colors.RED, err=True)
|
|
@@ -315,6 +321,9 @@ def search(
|
|
|
315
321
|
raise typer.Exit(code=1)
|
|
316
322
|
|
|
317
323
|
typer.echo(result)
|
|
324
|
+
|
|
325
|
+
if hasattr(result, "command") and result.command:
|
|
326
|
+
_prompt_and_execute(result.command)
|
|
318
327
|
|
|
319
328
|
|
|
320
329
|
history_app = typer.Typer(help="View and manage recorded command history.")
|
|
@@ -378,6 +387,45 @@ def history_clear() -> None:
|
|
|
378
387
|
raise typer.Exit(code=1)
|
|
379
388
|
|
|
380
389
|
typer.secho("Command history cleared.", fg=typer.colors.GREEN)
|
|
390
|
+
|
|
391
|
+
def _prompt_and_execute(command: str) -> None:
|
|
392
|
+
"""
|
|
393
|
+
Helper to safely prompt the user and execute an AI-suggested command.
|
|
394
|
+
Applies safety guardrails to destructive commands.
|
|
395
|
+
"""
|
|
396
|
+
# If running inside a non-interactive test runner (like CliRunner),
|
|
397
|
+
# skip the interactive prompt to preserve the parent command's exit code flow.
|
|
398
|
+
if not sys.stdin.isatty():
|
|
399
|
+
return
|
|
400
|
+
|
|
401
|
+
try:
|
|
402
|
+
if is_dangerous_command(command):
|
|
403
|
+
typer.secho(
|
|
404
|
+
"\n[WARNING] This command contains potentially destructive operations.",
|
|
405
|
+
fg=typer.colors.RED, bold=True
|
|
406
|
+
)
|
|
407
|
+
if not typer.confirm("Are you ABSOLUTELY sure you want to execute this?"):
|
|
408
|
+
typer.secho("Execution cancelled.", fg=typer.colors.YELLOW)
|
|
409
|
+
return
|
|
410
|
+
else:
|
|
411
|
+
if not typer.confirm("\nExecute this command now?"):
|
|
412
|
+
typer.secho("Execution cancelled.", fg=typer.colors.YELLOW)
|
|
413
|
+
return
|
|
414
|
+
except (SystemExit, typer.Exit):
|
|
415
|
+
typer.secho("Execution cancelled.", fg=typer.colors.YELLOW)
|
|
416
|
+
return
|
|
417
|
+
|
|
418
|
+
typer.secho(f"Executing: {command}\n", fg=typer.colors.CYAN)
|
|
419
|
+
|
|
420
|
+
executor = CommandExecutor()
|
|
421
|
+
result = executor.execute(command)
|
|
422
|
+
|
|
423
|
+
if result.succeeded:
|
|
424
|
+
if result.stdout:
|
|
425
|
+
typer.echo(result.stdout)
|
|
426
|
+
else:
|
|
427
|
+
if result.stderr:
|
|
428
|
+
typer.secho(result.stderr, fg=typer.colors.RED)
|
|
381
429
|
|
|
382
430
|
|
|
383
431
|
def main() -> None:
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Safety heuristics and guardrails for command execution.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
# Regex patterns for highly destructive Linux commands
|
|
8
|
+
DANGEROUS_PATTERNS = [
|
|
9
|
+
r"rm\s+-r?[fF]", # rm -rf, rm -f
|
|
10
|
+
r"dd\s+if=", # destructive disk copies
|
|
11
|
+
r"mkfs\.", # formatting partitions
|
|
12
|
+
r"chmod\s+-R\s+777", # recursive full permissions
|
|
13
|
+
r"chown\s+-R", # recursive chown
|
|
14
|
+
r">\s*/dev/sda", # redirecting output directly to disk
|
|
15
|
+
r"mv\s+.*?\s+/dev/null" # moving files to null
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
def is_dangerous_command(command: str) -> bool:
|
|
19
|
+
"""
|
|
20
|
+
Scans a command string for known destructive patterns.
|
|
21
|
+
Returns True if a dangerous pattern is detected, False otherwise.
|
|
22
|
+
"""
|
|
23
|
+
for pattern in DANGEROUS_PATTERNS:
|
|
24
|
+
if re.search(pattern, command, re.IGNORECASE):
|
|
25
|
+
return True
|
|
26
|
+
return False
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "smart-linux-assistant"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.8.0"
|
|
8
8
|
description = "An AI-powered Linux productivity assistant for command analysis, troubleshooting, and knowledge management."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0/smart_linux_assistant.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: smart-linux-assistant
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: An AI-powered Linux productivity assistant for command analysis, troubleshooting, and knowledge management.
|
|
5
5
|
Author: Shubham Kumar Jha
|
|
6
6
|
License: MIT
|
|
@@ -29,26 +29,22 @@ Dynamic: license-file
|
|
|
29
29
|
|
|
30
30
|
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.
|
|
31
31
|
|
|
32
|
-

|
|
33
|
-

|
|
34
|
-
[](https://github.com/shubham-k-jha-dev/smart-linux-assistant/actions/workflows/ci.yml)
|
|
35
|
-
|
|
36
32
|
## Project Overview
|
|
37
33
|
|
|
38
34
|
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.
|
|
39
35
|
|
|
40
36
|
## System Architecture
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
* CLI (`linux_assistant.cli.main`) accepts user commands and options and delegates execution to `CommandExecutor`.
|
|
39
|
+
* `CommandExecutor` runs shell commands using `subprocess.run` and returns a `CommandResult` dataclass describing the outcome.
|
|
40
|
+
* Centralized logging is provided by `linux_assistant.utils.logger`, writing to `logs/smart_linux_assistant.log` with rotation.
|
|
41
|
+
* Runtime paths and directories are managed by `linux_assistant.config.settings` and can be initialized with `initialize_app_filesystem()`.
|
|
46
42
|
|
|
47
43
|
## Tech Stack
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
* Python 3.11+
|
|
46
|
+
* Typer (CLI)
|
|
47
|
+
* Standard library: `subprocess`, `logging`, `shutil`, `dataclasses`, `pathlib`, `datetime`
|
|
52
48
|
|
|
53
49
|
## Prerequisites
|
|
54
50
|
|
|
@@ -101,7 +97,7 @@ initialize_app_filesystem()
|
|
|
101
97
|
This project does not require any environment variables for its core CLI functionality. The repository includes an empty `.env.example` placeholder.
|
|
102
98
|
|
|
103
99
|
| Variable | Description | Example |
|
|
104
|
-
|
|
100
|
+
| --- | --- | --- |
|
|
105
101
|
| (none) | No required environment variables for CLI execution | - |
|
|
106
102
|
|
|
107
103
|
## Usage / API Reference
|
|
@@ -114,56 +110,57 @@ By default, the CLI stays quiet — internal logs are written only to the log fi
|
|
|
114
110
|
smart-linux --verbose run "echo hello"
|
|
115
111
|
```
|
|
116
112
|
|
|
117
|
-
|
|
113
|
+
* Run a shell command:
|
|
118
114
|
|
|
119
115
|
```bash
|
|
120
116
|
smart-linux run "echo hello"
|
|
121
117
|
```
|
|
122
118
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
* Options:
|
|
120
|
+
* `--timeout <seconds>` — maximum seconds to allow command to run (default: 30)
|
|
121
|
+
* `--check` — treat non-zero exit codes as errors and exit with that code
|
|
122
|
+
* `--suggest-fix` — if the command fails, use AI to suggest a corrected version (requires `--check`; requires `GROQ_API_KEY`, same as `explain`/`fix`/`search`)
|
|
123
|
+
|
|
127
124
|
|
|
128
|
-
|
|
125
|
+
* Doctor command (checks common tools):
|
|
129
126
|
|
|
130
127
|
```bash
|
|
131
128
|
smart-linux doctor
|
|
132
129
|
```
|
|
133
|
-
|
|
130
|
+
|
|
131
|
+
* Get an AI-powered explanation of a command or error message:
|
|
134
132
|
|
|
135
133
|
```bash
|
|
136
134
|
smart-linux explain "permission denied when running ./script.sh"
|
|
137
135
|
```
|
|
138
136
|
|
|
139
|
-
|
|
137
|
+
Requires a free Groq API key set as an environment variable:
|
|
140
138
|
|
|
141
139
|
```bash
|
|
142
140
|
export GROQ_API_KEY="your-key-here"
|
|
143
141
|
```
|
|
144
142
|
|
|
145
|
-
|
|
143
|
+
Get a free key at [console.groq.com](https://console.groq.com).
|
|
146
144
|
|
|
147
|
-
|
|
145
|
+
* Fix a failing command:
|
|
148
146
|
|
|
149
147
|
```bash
|
|
150
148
|
smart-linux fix "ls /nonexistent"
|
|
151
149
|
```
|
|
152
150
|
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
* Options:
|
|
152
|
+
* `--timeout <seconds>` — maximum seconds to allow the command to run (default: 30)
|
|
155
153
|
|
|
156
|
-
- This runs the command and, if it fails, uses the AI to suggest a corrected version. Requires the same `GROQ_API_KEY` environment variable as the `explain` command.
|
|
157
154
|
|
|
158
|
-
|
|
155
|
+
* This runs the command and, if it fails, uses the AI to suggest a corrected version, then **interactively prompts you to execute the fix safely**. Requires the same `GROQ_API_KEY` environment variable as the `explain` command.
|
|
156
|
+
* Search for a Linux task in plain language:
|
|
159
157
|
|
|
160
158
|
```bash
|
|
161
159
|
smart-linux search "find the 10 largest files in the current directory"
|
|
162
160
|
```
|
|
163
161
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
- View or manage recorded command history:
|
|
162
|
+
* This returns a concrete command and brief explanation for the requested task, and **interactively prompts you to execute the command directly**. Requires the same `GROQ_API_KEY` environment variable as the `explain` command.
|
|
163
|
+
* View or manage recorded command history:
|
|
167
164
|
|
|
168
165
|
```bash
|
|
169
166
|
smart-linux history
|
|
@@ -171,7 +168,7 @@ smart-linux history --failures-only
|
|
|
171
168
|
smart-linux history clear
|
|
172
169
|
```
|
|
173
170
|
|
|
174
|
-
|
|
171
|
+
Every `run` invocation (success or failure) is recorded locally in a SQLite database, storing the command text, exit code, duration, working directory, and — only for failed commands — a truncated snippet of stderr. `stdout` is never stored. History is capped at 5,000 entries (oldest entries are pruned automatically) and can be disabled entirely by setting `SMART_LINUX_NO_HISTORY=1`.
|
|
175
172
|
|
|
176
173
|
### Example output
|
|
177
174
|
|
|
@@ -205,26 +202,29 @@ Suggested fix:
|
|
|
205
202
|
|
|
206
203
|
## Roadmap / Current Status
|
|
207
204
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
-
|
|
205
|
+
* Core CLI: implemented — `run` and `doctor` commands are provided in `linux_assistant.cli.main`.
|
|
206
|
+
* Command execution: implemented using `linux_assistant.services.command_executor.CommandExecutor` which returns `CommandResult` instances.
|
|
207
|
+
* Logging & configuration: implemented via `linux_assistant.utils.logger` and `linux_assistant.config.settings`.
|
|
208
|
+
* Packaging: console script entry points are declared in `pyproject.toml`.
|
|
209
|
+
* AI-powered explanations: implemented — `smart-linux explain` uses the Groq API (`llama-3.3-70b-versatile`) to generate plain-language explanations of commands and error messages, via `linux_assistant.services.explainer.Explainer`. Requires a user-supplied `GROQ_API_KEY` environment variable.
|
|
210
|
+
* AI-powered fix suggestions: implemented — `smart-linux fix` runs a failing command and suggests a corrected version; `smart-linux run --check --suggest-fix` offers the same suggestion inline as part of normal command execution. Both use `linux_assistant.services.explainer.Explainer.suggest_fix()`.
|
|
211
|
+
* AI-powered search: implemented — `smart-linux search` answers natural-language questions about Linux tasks via `linux_assistant.services.search.Searcher`.
|
|
212
|
+
* Production hardening & Safety: implemented — API timeouts, retry logic, rate-limit-specific handling, input truncation, regex-based secret redaction, and a **Heuristic Safety Interceptor (`linux_assistant.core.safety`)** to detect and block destructive commands (like `rm -rf`, `mkfs`, `dd`) before execution.
|
|
213
|
+
* Agentic Execution: implemented — `smart-linux fix` and `smart-linux search` now feature interactive confirmation prompts (`_prompt_and_execute`), allowing users to review AI-suggested commands and execute them instantly with safety guardrails.
|
|
214
|
+
* Command history: implemented — `smart-linux run` records every invocation locally via `linux_assistant.repositories.history_repository.HistoryRepository` (SQLite-backed, FIFO-capped at 5,000 rows). View with `smart-linux history` (supports `--failures-only`), erase with `smart-linux history clear`, or disable entirely via `SMART_LINUX_NO_HISTORY=1`. AI Context Injection is implemented: `explain` and `fix` commands dynamically fetch the last 5 chronological commands to give the LLM workflow awareness, protected by graceful degradation if the database is locked.
|
|
215
|
+
* Additional AI features (documentation lookup) are planned but not yet implemented.
|
|
218
216
|
|
|
219
217
|
## Known Limitations
|
|
220
218
|
|
|
221
|
-
|
|
219
|
+
* 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.
|
|
222
220
|
|
|
223
221
|
## Privacy Note
|
|
224
222
|
|
|
225
|
-
The `explain`, `fix`, and `search` commands send the command text, error output, or your query to Groq's API for processing.
|
|
223
|
+
The `explain`, `fix`, and `search` commands send the command text, error output, or your query to Groq's API for processing. The explain, fix, and search commands send your terminal queries to Groq's API for processing. Starting in v0.7.0, `explain` and `fix` also securely read your recent local command history to provide context-aware solutions.
|
|
224
|
+
|
|
225
|
+
Security First: Before any history leaves your machine, it passes through a local Regex Redactor `(linux_assistant.utils.redactor)` which automatically scrubs standard environment variables, inline passwords, and Bearer tokens, replacing them with [REDACTED]. However, you should still exercise caution and avoid running these commands on highly sensitive plaintext data.
|
|
226
226
|
|
|
227
|
-
Separately, `smart-linux run` records
|
|
227
|
+
Separately, `smart-linux run` records your command invocations (command text, exit code, duration, working directory, and truncated stderr) in a local SQLite database. `stdout` is never recorded. To disable history recording entirely, set `SMART_LINUX_NO_HISTORY=1`. To view or erase recorded history, use `smart-linux history` and `smart-linux history clear`.
|
|
228
228
|
|
|
229
229
|
## Install from PyPI
|
|
230
230
|
|
|
@@ -248,5 +248,5 @@ MIT License — see `LICENSE`.
|
|
|
248
248
|
|
|
249
249
|
## Contributing
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
251
|
+
* Run tests with `pytest` before opening a pull request.
|
|
252
|
+
* Follow standard Python packaging best practices.
|
|
@@ -7,6 +7,7 @@ linux_assistant/cli/main.py
|
|
|
7
7
|
linux_assistant/config/__init__.py
|
|
8
8
|
linux_assistant/config/settings.py
|
|
9
9
|
linux_assistant/core/__init__.py
|
|
10
|
+
linux_assistant/core/safety.py
|
|
10
11
|
linux_assistant/exceptions/__init__.py
|
|
11
12
|
linux_assistant/exceptions/base.py
|
|
12
13
|
linux_assistant/models/__init__.py
|
|
@@ -35,5 +36,6 @@ tests/test_explainer.py
|
|
|
35
36
|
tests/test_groq_client.py
|
|
36
37
|
tests/test_history_repository.py
|
|
37
38
|
tests/test_redactor.py
|
|
39
|
+
tests/test_safety.py
|
|
38
40
|
tests/test_search.py
|
|
39
41
|
tests/test_shell.py
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for the safety interceptor.
|
|
3
|
+
"""
|
|
4
|
+
from linux_assistant.core.safety import is_dangerous_command
|
|
5
|
+
|
|
6
|
+
def test_safe_commands():
|
|
7
|
+
assert not is_dangerous_command("ls -la /var/log")
|
|
8
|
+
assert not is_dangerous_command("echo 'hello world'")
|
|
9
|
+
assert not is_dangerous_command("git status")
|
|
10
|
+
assert not is_dangerous_command("cat /etc/os-release")
|
|
11
|
+
|
|
12
|
+
def test_dangerous_commands():
|
|
13
|
+
assert is_dangerous_command("rm -rf /")
|
|
14
|
+
assert is_dangerous_command("sudo rm -f /var/log/syslog")
|
|
15
|
+
assert is_dangerous_command("dd if=/dev/zero of=/dev/nvme0n1")
|
|
16
|
+
assert is_dangerous_command("mkfs.ext4 /dev/sda1")
|
|
17
|
+
assert is_dangerous_command("chmod -R 777 /var/www/html")
|
|
18
|
+
assert is_dangerous_command("echo 'wipe' > /dev/sda")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/config/__init__.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/config/settings.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/core/__init__.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/exceptions/__init__.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/exceptions/base.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/models/__init__.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/models/command_result.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/models/history_entry.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/repositories/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/services/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/services/explainer.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/services/search.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/utils/__init__.py
RENAMED
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/utils/groq_client.py
RENAMED
|
File without changes
|
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/linux_assistant/utils/redactor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{smart_linux_assistant-0.7.0 → smart_linux_assistant-0.8.0}/tests/test_history_repository.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|