A CLI tool to register and retrieve terminal commands using natural language and semantic search
Project description
cmdrun
Remember terminal commands using natural language and semantic search — entirely offline.
cmdrun "show all pods"
╭─ Best match ────────────────────────────────╮
│ kubectl get pods -A │
╰─ similarity 0.87 ───────────────────────────╯
Table of contents
Installation
pip install cmdrun
Requires Python 3.9+. All data is stored locally under ~/.cmdrun/ — nothing leaves your machine.
Quick start
1. Register a command
$ cmdrun register
Register a new command
Description: list all kubernetes pods
Command: kubectl get pods -A
✓ Registered: 'list all kubernetes pods' → kubectl get pods -A
2. Retrieve it with natural language
$ cmdrun "show pods"
╭─ Best match ────────────────────────────────╮
│ kubectl get pods -A │
╰─ similarity 0.87 ───────────────────────────╯
3. Run it immediately
$ cmdrun --run "show pods"
Running: kubectl get pods -A
NAME READY STATUS RESTARTS AGE
...
Commands
| Command | Description |
|---|---|
cmdrun register |
Interactively register a new description → command mapping |
cmdrun "query" |
Retrieve the best-matching command for a natural language query |
cmdrun --run "query" |
Retrieve and execute the best-matching command |
cmdrun list |
Show all registered commands in a table |
cmdrun remove |
Remove a registered command by list index |
cmdrun rebuild |
Rebuild the FAISS index from commands.json |
Options
| Flag | Description |
|---|---|
--run / -r |
Execute the matched command after displaying it |
--verbose / -v |
Enable debug-level logging |
Architecture
cmdrun "show all pods"
│
▼
cli.py (Typer + Rich)
│
▼
embeddings.py — sentence-transformers/all-MiniLM-L6-v2 (384d, lazy-loaded)
│
▼
vector_store.py — FAISS IndexFlatIP (cosine similarity via normalised vectors)
│
▼
matcher.py — top-k search, threshold filtering, MatchResponse
│
▼
storage.py — commands.json (source of truth, Pydantic models)
Data files
All data lives in ~/.cmdrun/:
| File | Purpose |
|---|---|
commands.json |
Human-readable list of description → command pairs |
index.faiss |
FAISS binary index (vector search) |
metadata.pkl |
Maps FAISS vector positions back to CommandEntry objects |
Similarity search
- Query text is embedded with
all-MiniLM-L6-v2(384 dimensions, L2-normalised). - FAISS
IndexFlatIPperforms an inner-product search (≡ cosine similarity for unit vectors). - The top-k (default 3) candidates are returned.
- If the best candidate's similarity is below 0.60 the tool reports "No command found".
Configuration
The following constants in cmdrun/config.py can be adjusted:
| Constant | Default | Description |
|---|---|---|
SIMILARITY_THRESHOLD |
0.60 |
Minimum cosine similarity to accept a match |
TOP_K |
3 |
Number of candidates to surface |
EMBEDDING_MODEL |
sentence-transformers/all-MiniLM-L6-v2 |
HuggingFace model ID |
Development
# Clone / enter the project
cd cmdrun
# Install in editable mode with dev extras
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=cmdrun --cov-report=term-missing
# Lint
ruff check cmdrun tests
# Type-check
mypy cmdrun
Project layout
cmdrun/
├── __init__.py Package metadata
├── cli.py Typer app — all user-facing commands
├── config.py Paths, model name, thresholds
├── storage.py commands.json read/write (Pydantic models)
├── embeddings.py Lazy-loaded sentence-transformers wrapper
├── vector_store.py FAISS index management
└── matcher.py High-level matching pipeline
tests/
└── test_matcher.py pytest suite (embeddings, vector store, matcher, storage)
data/
└── commands.json Seed/example data (empty by default)
pyproject.toml
README.md
Examples
Register a handful of commands
cmdrun register
Description: list all kubernetes pods across namespaces
Command: kubectl get pods -A
cmdrun register
Description: list running docker containers
Command: docker ps
cmdrun register
Description: show disk usage human readable
Command: df -h
cmdrun register
Description: find large files in current directory
Command: find . -type f -size +100M
cmdrun register
Description: tail application logs
Command: tail -f /var/log/app.log
Query examples
cmdrun "pods in kubernetes"
cmdrun "docker running"
cmdrun "how much disk space"
cmdrun "big files"
cmdrun "follow logs"
Execute directly
cmdrun --run "show disk usage"
Manage your catalogue
cmdrun list # view all entries with their index numbers
cmdrun remove # choose an entry to delete by number
cmdrun rebuild # re-sync index after manually editing commands.json
Performance
| Operation | Typical latency |
|---|---|
| Cold start (first query, model load) | ~1–2 s |
| Subsequent queries (model cached) | < 50 ms |
| Index rebuild (100 entries) | ~2 s |
License
MIT
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 cmdrun-0.1.0.tar.gz.
File metadata
- Download URL: cmdrun-0.1.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c2bd0fcce75aa50b998972170108cada45b8ea8eb29ffb6c9ce583379699071
|
|
| MD5 |
7e8a37bd34090b6ef9e0b76b60f5884c
|
|
| BLAKE2b-256 |
fc761eb5e1143413abc5e5ee005eb8b23c6774aa6ff5a31a3ace8892cc5d82a6
|
File details
Details for the file cmdrun-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cmdrun-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b529365b026b56f98756530a875eeec326d5e288a66218390ee4b5540c0cbdbc
|
|
| MD5 |
b0bea66857620d7ed45bb565b6e1ab95
|
|
| BLAKE2b-256 |
4415ca69a9e6e43a45838ff147eb13da4b145ce1d1ff0a0f02370ab662aff932
|