ghosttype

command module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README ΒΆ

ghosttype

⌨️ Terminal Command Prediction

Ghosttype is your AI-powered command assistant for the terminal.
It learns how you work β€” from your command history, project context, and shell configuration β€” and predicts what you're most likely to type next.

Using a hybrid of traditional and AI-enhanced models, Ghosttype intelligently suggests your next move with:

  • πŸ” Markov chains – learning the flow of your typical command sequences
  • πŸ“Š Frequency analysis – surfacing your most common commands quickly
  • 🧠 LLM-based embeddings – understanding semantic similarity via vector search
  • πŸ’Ύ Shell aliases – integrating your custom shortcuts
  • πŸ“¦ Project context awareness – reading from Makefile, package.json, pom.xml, and more

It’s like having autocomplete β€” but for the way you use the terminal.

🚧 Status: Active Development

Ghosttype is still under active development. Expect occasional breaking changes. Contributions and issue reports are welcome!

πŸ“Š Performance & Benchmarks

Current Performance vs. Popular Tools

We regularly benchmark Ghosttype against established command-line tools to track our progress:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Tool        β”‚ Top-1   β”‚ Top-10  β”‚ Avg Timeβ”‚ P95 Time  β”‚ Errors   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ πŸ‘‘ ghosttype β”‚   16.0% β”‚   31.0% β”‚ 158.483ms β”‚ 255.674ms β”‚     0.5% β”‚
β”‚ fzf         β”‚    7.5% β”‚   13.5% β”‚ 10.846ms β”‚  15.67ms β”‚    41.5% β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ₯‡ WINNERS BY METRIC:
  Best Top-1 Accuracy: ghosttype
  Best Top-10 Accuracy: ghosttype
  Fastest Average Response: fzf
  Best P95 Latency: fzf
  Most Reliable: ghosttype

πŸ’‘ GHOSTTYPE ADVANTAGES:
  βœ… 2x more accurate than fzf (16.0% vs 7.5%)

What we're doing well:

  • 2x more accurate command predictions than traditional fuzzy finders
  • Zero errors vs 54% error rate in string-based matching
  • Better semantic understanding of command intent

What we're working on:

  • Latency optimization: Current ~800ms response time needs improvement for real-time use
  • Model efficiency: Exploring lighter models and caching strategies
  • Progressive loading: Show fast results immediately, then enhance with AI suggestions
  • Hybrid approach: Instant prefix matching for short inputs, AI for complex queries
  • Deeper contextual understanding: Providing more relevant suggestions by analyzing the current directory's files, git status, and recently executed commands.
  • Intelligent error correction: Suggesting corrections for typos or common errors (e.g., correcting gti status to git status).

πŸš€ Demo

$ git ch▍    # Press Ctrl+P (zsh Integration)

> git checkout main                                       
  git checkout add-slim-version                           
  git checkout hoge                                       

✨ Features

  • πŸ“š Learns from ~/.zsh_history or ~/.bash_history
  • πŸ€– Embeds historical commands via LLM-powered vector search
  • 🧠 Predicts likely next commands using multiple models (Markov, freq, embedding, etc.)
  • πŸ“‚ Context-aware suggestions from Makefile, package.json, pom.xml, etc.
  • ⚑ Zsh keybinding integration

πŸ›  Installation

1. Install ghosttype
go install github.com/trknhr/ghosttype@latest

This will install the ghosttype command to your $GOBIN (usually ~/go/bin).

πŸ–₯️ Zsh Integration

Add the following to your .zshrc:

# Predict a command using ghosttype + TUI, then replace current shell input with the selection
function ghosttype_predict() {
  local result=$(ghosttype "$BUFFER")
  if [[ -n "$result" ]]; then
    BUFFER="$result"
    CURSOR=${#BUFFER}
    zle reset-prompt
  fi
}
zle -N ghosttype_predict
bindkey '^p' ghosttype_predict

Then reload your shell:

source ~/.zshrc

Now press Ctrl+P in your terminal to trigger Ghosttype suggestions.

🧠 Enable LLM-Powered Suggestions (via Ollama)

Ghosttype supports LLM-based predictions and vector embeddings powered by Ollama.

To use these features, follow the steps below:

1. Install Ollama

Download and install from the official site:
πŸ‘‰ https://ollama.com/download

Verify installation:

ollama --version
2. Pull required models

Ghosttype uses the following models:

llama3.2 β€” for next-command prediction

nomic-embed-text β€” for semantic similarity via embedding

Download the models:

ollama run llama3.2:1b           # Starts and downloads the LLM model
ollama pull nomic-embed-text  # Downloads the embedding model

ℹ️ ollama run llama3.2:1b must be running in the background to enable LLM-powered suggestions.

You can run it in a separate terminal window: Once Ollama is running and the models are downloaded, Ghosttype will automatically use them to enhance prediction accuracy.

🧠 Architecture

Ghosttype uses an ensemble of models:

  • markov: Lightweight transition-based predictor
  • freq: Frequency-based suggestion engine
  • alias: Shell aliases from .zshrc/.bashrc
  • context: Targets from Makefile, package.json, pom.xml, etc.
  • embedding: LLM-generated vector search powered by ollama

All models implement a unified SuggestModel interface and are combined via ensemble.Model.

πŸ—‚ Project Structure

.
β”œβ”€β”€ cmd/            # CLI (tui, suggest, root)
β”œβ”€β”€ history/        # Loaders for bash/zsh history
β”œβ”€β”€ model/          # All prediction models
β”œβ”€β”€ internal/       # Logging, utils, alias sync
β”œβ”€β”€ ollama/         # LLM/embedding interface
β”œβ”€β”€ parser/         # RC and alias parsing
β”œβ”€β”€ script/         # Shell helper scripts
β”œβ”€β”€ main.go
└── go.mod

πŸ“œ License

Apache-2.0 See LICENSE for full terms.

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
cmd
history
Package history is a generated GoMock package.
Package history is a generated GoMock package.
ollama
Package ollama is a generated GoMock package.
Package ollama is a generated GoMock package.
store
Package store is a generated GoMock package.
Package store is a generated GoMock package.
tui

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL