icmd-cli 0.1.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.
- icmd_cli-0.1.0/PKG-INFO +17 -0
- icmd_cli-0.1.0/README.md +8 -0
- icmd_cli-0.1.0/icmd/__init__.py +0 -0
- icmd_cli-0.1.0/icmd/executor.py +15 -0
- icmd_cli-0.1.0/icmd/llm.py +53 -0
- icmd_cli-0.1.0/icmd/main.py +23 -0
- icmd_cli-0.1.0/icmd/safety.py +19 -0
- icmd_cli-0.1.0/icmd/utils.py +2 -0
- icmd_cli-0.1.0/icmd_cli.egg-info/PKG-INFO +17 -0
- icmd_cli-0.1.0/icmd_cli.egg-info/SOURCES.txt +14 -0
- icmd_cli-0.1.0/icmd_cli.egg-info/dependency_links.txt +1 -0
- icmd_cli-0.1.0/icmd_cli.egg-info/entry_points.txt +2 -0
- icmd_cli-0.1.0/icmd_cli.egg-info/requires.txt +1 -0
- icmd_cli-0.1.0/icmd_cli.egg-info/top_level.txt +1 -0
- icmd_cli-0.1.0/pyproject.toml +18 -0
- icmd_cli-0.1.0/setup.cfg +4 -0
icmd_cli-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: icmd-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI-powered command line tool using local LLM
|
|
5
|
+
Author: Deepak Karthick
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: requests
|
|
9
|
+
|
|
10
|
+
# iCMD
|
|
11
|
+
|
|
12
|
+
An AI-powered command line tool using local LLM (qwen2.5-coder).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install icmd
|
icmd_cli-0.1.0/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
|
|
3
|
+
def execute(command):
|
|
4
|
+
try:
|
|
5
|
+
result = subprocess.run(
|
|
6
|
+
command.split(),
|
|
7
|
+
capture_output=True,
|
|
8
|
+
text=True,
|
|
9
|
+
timeout=5
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
return result.stdout if result.returncode == 0 else result.stderr
|
|
13
|
+
|
|
14
|
+
except Exception as e:
|
|
15
|
+
return str(e)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import subprocess
|
|
3
|
+
|
|
4
|
+
MODEL = "qwen2.5-coder"
|
|
5
|
+
OLLAMA_URL = 'http://localhost:11434'
|
|
6
|
+
|
|
7
|
+
def ensure_ollama():
|
|
8
|
+
try:
|
|
9
|
+
requests.get(OLLAMA_URL)
|
|
10
|
+
res = requests.get(f"{OLLAMA_URL}/api/tags").json()
|
|
11
|
+
models = [m["name"] for m in res.get("models",[])]
|
|
12
|
+
|
|
13
|
+
if MODEL not in models:
|
|
14
|
+
print(f"Pulling model: {MODEL}...")
|
|
15
|
+
subprocess.run(["ollama", "pull", MODEL])
|
|
16
|
+
except:
|
|
17
|
+
print("Ollama is not installed or running.")
|
|
18
|
+
print("Install from: https://ollama.com")
|
|
19
|
+
exit()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def llm(input):
|
|
23
|
+
ensure_ollama()
|
|
24
|
+
PROMPT = f"""
|
|
25
|
+
You are a advanced linux terminal assistant.
|
|
26
|
+
For every user query you will return corresponding linux bash command as response.
|
|
27
|
+
You only return commands and should not explain using comments.
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
query: "list me all the files"
|
|
31
|
+
reponse: "ls"
|
|
32
|
+
|
|
33
|
+
query: "print the working directory"
|
|
34
|
+
response: "pwd"
|
|
35
|
+
|
|
36
|
+
(MUST!!!) Ensure the command does not involve any critical system operations
|
|
37
|
+
- Deleting a file/folder
|
|
38
|
+
- Accessing root user
|
|
39
|
+
- Accessing important system files, etc.
|
|
40
|
+
If so return "Cannot process this request" as response
|
|
41
|
+
|
|
42
|
+
Now return bash command for this query with out any quotes:
|
|
43
|
+
'{input}'
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
data = {
|
|
47
|
+
"model": "qwen2.5-coder",
|
|
48
|
+
"prompt": PROMPT,
|
|
49
|
+
"stream": False
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
response = requests.post(f"{OLLAMA_URL}/api/tags",json=data)
|
|
53
|
+
return response.json()["response"]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from icmd.llm import llm
|
|
3
|
+
from icmd.executor import execute
|
|
4
|
+
from icmd.safety import is_dangerous
|
|
5
|
+
from icmd.utils import clean
|
|
6
|
+
|
|
7
|
+
def run():
|
|
8
|
+
if len(sys.argv) < 2:
|
|
9
|
+
print("Usage: icmd \"your query\"")
|
|
10
|
+
return
|
|
11
|
+
query = " ".join(sys.argv[1:])
|
|
12
|
+
command = llm(query)
|
|
13
|
+
cleaned = clean(command)
|
|
14
|
+
if cleaned.lower() == "cannot process this request":
|
|
15
|
+
print("cannot process this request")
|
|
16
|
+
return
|
|
17
|
+
if is_dangerous(cleaned):
|
|
18
|
+
print("Unsafe command to execute")
|
|
19
|
+
return
|
|
20
|
+
result = execute(cleaned)
|
|
21
|
+
print(result)
|
|
22
|
+
|
|
23
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
CRITICAL_COMMANDS = [
|
|
2
|
+
"rm", "rmdir", "mv", "dd", "mkfs",
|
|
3
|
+
"shutdown", "reboot", "init", "poweroff",
|
|
4
|
+
"kill", "killall", "chmod", "chown",
|
|
5
|
+
"sudo", "su", "mount", "umount",
|
|
6
|
+
"wget", "curl", "scp", "ssh"
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
DANGEROUS_SYMBOLS = [";", "|", "&", ">", ">>"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def is_dangerous(command):
|
|
13
|
+
parts = command.strip().split()
|
|
14
|
+
if parts[0] in CRITICAL_COMMANDS:
|
|
15
|
+
return True
|
|
16
|
+
for symbol in DANGEROUS_SYMBOLS:
|
|
17
|
+
if symbol in command:
|
|
18
|
+
return True
|
|
19
|
+
return False
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: icmd-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI-powered command line tool using local LLM
|
|
5
|
+
Author: Deepak Karthick
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: requests
|
|
9
|
+
|
|
10
|
+
# iCMD
|
|
11
|
+
|
|
12
|
+
An AI-powered command line tool using local LLM (qwen2.5-coder).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install icmd
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
icmd/__init__.py
|
|
4
|
+
icmd/executor.py
|
|
5
|
+
icmd/llm.py
|
|
6
|
+
icmd/main.py
|
|
7
|
+
icmd/safety.py
|
|
8
|
+
icmd/utils.py
|
|
9
|
+
icmd_cli.egg-info/PKG-INFO
|
|
10
|
+
icmd_cli.egg-info/SOURCES.txt
|
|
11
|
+
icmd_cli.egg-info/dependency_links.txt
|
|
12
|
+
icmd_cli.egg-info/entry_points.txt
|
|
13
|
+
icmd_cli.egg-info/requires.txt
|
|
14
|
+
icmd_cli.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
icmd
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "icmd-cli"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "AI-powered command line tool using local LLM"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{name = "Deepak Karthick"}
|
|
12
|
+
]
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"requests"
|
|
16
|
+
]
|
|
17
|
+
[project.scripts]
|
|
18
|
+
icmd = "icmd.main:run"
|
icmd_cli-0.1.0/setup.cfg
ADDED