icmd-cli 0.1.0__py3-none-any.whl

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/__init__.py ADDED
File without changes
icmd/executor.py ADDED
@@ -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)
icmd/llm.py ADDED
@@ -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"]
icmd/main.py ADDED
@@ -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
+
icmd/safety.py ADDED
@@ -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
icmd/utils.py ADDED
@@ -0,0 +1,2 @@
1
+ def clean(command):
2
+ return command.replace("```bash","").replace("```","").strip()
@@ -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,11 @@
1
+ icmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ icmd/executor.py,sha256=9zLIffCqRECiDIux_tDredCbLaUP5i0HS3hUX4mkS30,336
3
+ icmd/llm.py,sha256=zGuq_MesSNkv7BR9v6fpSCITH5Ll9m0IGw0iBhdwX7M,1559
4
+ icmd/main.py,sha256=xPWlEiOAm8wYxRstrH7EgE41b-RM2SszALMq85TNhSk,585
5
+ icmd/safety.py,sha256=QTfaBU25PDCQJjYaGNJZLSwSn4V6PXezLgJUdngG5IM,498
6
+ icmd/utils.py,sha256=f5by9hEEMtBueV9SN8bLJZdQn1SCSkBhGBKm8zKv7Ls,86
7
+ icmd_cli-0.1.0.dist-info/METADATA,sha256=zvGbYxd4slN7FBIPXRQdUWVgMS2e3OHAJ32bw9-7-Eo,334
8
+ icmd_cli-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
9
+ icmd_cli-0.1.0.dist-info/entry_points.txt,sha256=TJVEpIQe2iVfW9xJxRhkH2qTNqItzqB6_XkDzSU9_GY,39
10
+ icmd_cli-0.1.0.dist-info/top_level.txt,sha256=olzM6Z_QEwg7RrFVOnkgO0I2Ps2m7vhSqYQZYeiawcw,5
11
+ icmd_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ icmd = icmd.main:run
@@ -0,0 +1 @@
1
+ icmd