isutra-0.2.1 is not a library.
Sutra
Sutra is a common command suggestor for your terminal.
When you type a wrong command (e.g. gti stats), Sutra looks at:
- a default catalog of known commands/subcommands
- executables available in your PATH
- your command history (optional under smriti flag)
…and shows clickable-style numbered suggestions (1/2/3). You pick one and Sutra runs it.
Smriti Mode makes Sutra smarter by using your history with frequency + recency boosting.
Features
- Typo correction using edit-distance (Damerau–Levenshtein)
- Token-aware suggestions (command + subcommand)
- Smriti Mode (history priors: frequency + recency + optional cwd affinity)
- Defaults catalog (
~/.sutra/defaults.json) for curated command families/subcommands - PATH discovery for real environment-aware suggestions
- Plugin subcommands:
git-foo→ suggestsgit foo,kubectl-foo→ suggestskubectl foo - Fast retrieval using a BK-tree (edit-distance radius search)
- Shell hooks (bash/zsh) to trigger automatically on
command not found
Install
Install from upstream
Build from source
Verify:
Quick Start
1) Suggest for a typo (interactive)
Example output:
Sutra: I couldn't run: "gti stats"
Did you mean:
1) git status [defaults | 0.88]
2) git stash [defaults | 0.71]
3) git [PATH | 0.62]
0) cancel
Pick 1-3 (0 to cancel):
2) Run through Sutra
If the command succeeds, Sutra appends it to Smriti history.
Smriti Mode (history learning)
Smriti Mode boosts suggestions based on:
- frequency (what you run often)
- recency (what you ran recently)
- cwd affinity (optional, lightweight boost if used in the same directory)
Enable it using:
History file:
~/.sutra/history.jsonl(JSON lines)
Defaults Catalog
Create:
~/.sutra/defaults.json
Example:
Notes:
basebecomes a candidate (git)- each
base + subcommandbecomes a candidate (git status) aliasesbecome matching keys (g status)patternsare used as soft match keys (help ranking), but the executed suggestion is still a real command candidate
Shell Hooks (bash/zsh)
To auto-run Sutra on unknown commands:
Print hooks
Bash
Add to ~/.bashrc:
Zsh
Add to ~/.zshrc:
Reload your shell:
Now try a typo:
How it works (high level)
-
Candidate generation
- PATH executables (
git,docker, ...) - Defaults catalog families + subcommands
- Smriti-mined commands/subcommands from history
- Plugin expansion (
git-foo→git foo,kubectl-foo→kubectl foo)
- PATH executables (
-
Fast shortlist retrieval
- Build a BK-tree over candidate keys
- Query with edit-distance radius (default
2)
-
Scoring
- Typo similarity (normalized edit distance)
- Token-aware similarity
- Smriti prior (freq + recency + cwd boost) if enabled
- Context boost (light heuristics, e.g. git repo → boost
git)
-
Diversification
- Avoid near-duplicate suggestions
-
Selection
- User picks
1/2/3to execute
- User picks
CLI Reference
Suggest
Run
Hooks
Flags:
--smriti: enable history priors--topk: number of suggestions (default: 3)--radius: BK-tree edit-distance radius (default: 2)
Roadmap
- SLM model training to do this better.
- PATH scan caching for faster startup
- Argument-shape fixing (keep args, only correct command/subcommand tokens)
- Better diversification per command family
- Optional TUI selector (arrows/enter)