nl-sh: Natural Language Shell

Overview

nl-sh: Natural Language Shell

Introduction

nl-sh stands for Natural Language Shell, a novel approach to interacting with POSIX systems through natural language understanding through LLMs. This project aims to bridge the gap between traditional shell command execution and natural language interpretation, providing a user-friendly interface for executing complex system commands using simple English prompts. This is functional proof-of-concept. nl-sh makes working in terminals more accessible and intuitive, as the shell accepts both traditional POSIX commands as well as human-language instructions for system operations; the best command sequence satisfying that human prompt is provided back to the user for verification before execution.

The point of this shell is to eliminate the tedious manual tasks of googling Stack Overflow or grepping through man pages to figure out the right combination of commands, arguments, pipes and flags to complete complex operations from the command line. This provides a human-centered CLI experience, for those who spend time on *NIX variants but are poorly-versed in the entire command vocabulary.

This is discussed a little further here

Key Features:

  • Can use in any window-based or remote terminal setting, as an overlay on top of the current envionment's shell
  • Accepts either direct system commands, or expressive language-based commands, which are interpreted by an LLM
  • Loads prior shell history (bash, ksh, tcsh, zsh), allows history navigation and updates underlying shell history with executed commands
  • Supports GPT 3.5 Turbo, GPT 4, Claude 2.1, and any locally-available open-source GGUF formatted LLM

In particular, I've had success with Mistral 7B Instruct, and CodeLlama 7B. Some other OS models, such as raw Llama2 do not work as well; often because they're a little too chatty and helpful =)

nl-sh is best demonstrated with some examples (default behavior is to use GPT4 and assume OPENAI_API_KEY is available):

scp -r log-server:/home/mike/log_data log-server-data Yes mike@log-server's password: > [nl-sh] /Users/mike/code/nl-sh $ list the contents of the "log-server-data" directory with human-readable file sizes > ls -lh log-server-data Yes total 953984 -rw-r--r-- 1 mike staff 82M Feb 13 09:08 0.log -rw-r--r-- 1 mike staff 82M Feb 13 09:08 1.log -rw-r--r-- 1 mike staff 82M Feb 13 09:08 2.log -rw-r--r-- 1 mike staff 163M Feb 13 09:08 3.log > [nl-sh] /Users/mike/code/nl-sh $ Which 3 running processes on this machine have consumed the most CPU resources? > ps -arx -o pid,ppid,%cpu,comm | head -n 4 Yes PID PPID %CPU COMM 564 1 31.1 /System/Library/PrivateFrameworks/SkyLight.framework/Resources/WindowServer 17422 1 13.8 /System/Library/Frameworks/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.WebContent.xpc/Contents/MacOS/com.apple.WebKit.WebContent 1295 1 10.0 /System/Volumes/Preboot/Cryptexes/App/System/Applications/Safari.app/Contents/MacOS/Safari">
  ~/code/nl-sh ~>> ./target/release/nl-sh --help 
  A natural language shell for *NIX systems

  Usage: nl-sh [OPTIONS]

  Options:
      --gpt4          Use the GPT4 API as a backend, reading from the OPENAI_API_KEY environment variable. Default behavior.
      --gpt35         Use the GPT3.5 Turbo API as a backend, reading from the OPENAI_API_KEY environment variable
      --claude        Use the Anthropic Claude API as a backend, reading from the CLAUDE_API_KEY environment variable
      --local   Use a local GGUF-based model as a backend, located at the provided path
      --stateless     Disable update of external shell history (default: false)

  ~/code/nl-sh ~>> ./target/release/nl-sh 
  > [nl-sh] /Users/mike/code/nl-sh $ whoami
  mike
  
  > [nl-sh] /Users/mike/code/nl-sh $ pwd
  /Users/mike/code/nl-sh
  
  > [nl-sh] /Users/mike/code/nl-sh $ ps aux |grep git
  mike             30936   0.0  0.0 408490720    656 s008  R+    9:01AM   0:00.00 grep git
  mike             30934   0.0  0.0 408636976   2416 s008  S+    9:01AM   0:00.01 /bin/zsh -c ps aux |grep git

  > [nl-sh] /Users/mike/code/nl-sh $ copy remote directory /home/mike/log_data on remote host "log-server" to the local machine; store the data in a new directory called "log-server-data"
  > scp -r log-server:/home/mike/log_data log-server-data Yes
  mike@log-server's password: 

  > [nl-sh] /Users/mike/code/nl-sh $ list the contents of the "log-server-data" directory with human-readable file sizes
  > ls -lh log-server-data Yes
  total 953984
  -rw-r--r--  1 mike  staff    82M Feb 13 09:08 0.log
  -rw-r--r--  1 mike  staff    82M Feb 13 09:08 1.log
  -rw-r--r--  1 mike  staff    82M Feb 13 09:08 2.log
  -rw-r--r--  1 mike  staff   163M Feb 13 09:08 3.log

  > [nl-sh] /Users/mike/code/nl-sh $ Which 3 running processes on this machine have consumed the most CPU resources?
  > ps -arx -o pid,ppid,%cpu,comm | head -n 4 Yes
    PID  PPID  %CPU COMM
    564     1  31.1 /System/Library/PrivateFrameworks/SkyLight.framework/Resources/WindowServer
  17422     1  13.8 /System/Library/Frameworks/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.WebContent.xpc/Contents/MacOS/com.apple.WebKit.WebContent
   1295     1  10.0 /System/Volumes/Preboot/Cryptexes/App/System/Applications/Safari.app/Contents/MacOS/Safari

Now with a local model:

  ~/code/nl-sh ~>> ./target/release/nl-sh --local ./mistral-7b-instruct-v0.2.Q8_0.gguf
  > [nl-sh] /Users/mike/code/nl-sh $ show me the top 3 largest files in the current directory, in human-readable size format
  > du -ah | grep gguf | sort -rh | head -n 3 Yes
   32G	./gemma-7b.gguf
  9.3G	./gemma-2b.gguf
  8.5G	./gemma-7b-it-Q8_0.gguf (Y/n)

Here's a video demonstration:

nl-sh

How does this work?

nl-sh acts like a (minimal) shell by wrapping the underlying shell with a prompt which accepts and executes text inputs from the user. Inputs which seem like actual POSIX commands are directly executed; otherwise the input is directed to an LLM to interpret the input and provide a command sequence satisfying the request, customized for the local system powering the shell. This shell collects some environmental data such as kernel and OS version details to try and generate the most accurate command-line sequence for the given POSIX variant.

Any commands suggested by the backing LLM and then executed through nl-sh are written to the user's underlying shell command-history file.

You might also like...
A very opinionated, zero-configuration shell prompt
A very opinionated, zero-configuration shell prompt

A very opinionated, zero-configuration shell prompt

An interactive shell environment for exploring the p2panda protocol
An interactive shell environment for exploring the p2panda protocol

An interactive shell environment for exploring the p2panda protocol. Uses a mock node and clients to simulate network logic.

Self-contained template system with Handlebars and inline shell scripts

Handlematters Self-contained template system with Handlebars and inline shell scripts Introduction Handlematters is a template system that combines Ha

A shell Made in rust 🦀

vsh A Blazingly fast shell made in Rust 🦀 Why make another shell? Because the current leading rust shell is very opinionated, atleast to me. As it br

dye is a tool to easily color text in shell.
dye is a tool to easily color text in shell.

Dye dye is a tool to easily color text in shell. Usage See the gif below to see these commands in action. echo $(dye --red WARN) This tool will knock

A Unix shell written and implemented in rust 🦀

vsh A Blazingly fast shell made in Rust 🦀 Installation Copy and paste the following command and choose the appropriate installtion method for you. Yo

Shellcheck - a static analysis tool for shell scripts
Shellcheck - a static analysis tool for shell scripts

ShellCheck - A shell script static analysis tool ShellCheck is a GPLv3 tool that gives warnings and suggestions for bash/sh shell scripts: The goals o

Application microframework with command-line option parsing, configuration, error handling, logging, and shell interactions
Application microframework with command-line option parsing, configuration, error handling, logging, and shell interactions

Abscissa is a microframework for building Rust applications (either CLI tools or network/web services), aiming to provide a large number of features w

☄🌌️  The minimal, blazing-fast, and infinitely customizable prompt for any shell
☄🌌️ The minimal, blazing-fast, and infinitely customizable prompt for any shell

☄🌌️ The minimal, blazing-fast, and infinitely customizable prompt for any shell

Releases(v0.1)
  • v0.1(Mar 11, 2024)

    • Added support for ingesting, navigating and writing native shell command history, via a forked inquire repository.
    • Updated llama flags to local and tested with a few new models - codellama and mistral-instruct work well
    • Added support for GPT3.5 Turbo
    Source code(tar.gz)
    Source code(zip)
Owner
Mike Cvet
Mike Cvet
🦞 Rust library of natural language dictionaries using character-wise double-array tries.

?? Crawdad: ChaRActer-Wise Double-Array Dictionary Overview Crawdad is a library of natural language dictionaries using character-wise double-array tr

null 18 Dec 15, 2022
Shell scripting that will knock your socks off

atom Shell scripting that will knock your socks off. NOTE: Click the image above for a video demonstration.

adam mcdaniel 256 Dec 14, 2022
A new type of shell

A new type of shell

Nushell Project 22.5k Jan 8, 2023
🐢 Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands

Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands. Additionally, it provides optional and fully encrypted synchronisation of your history between machines, via an Atuin server.

Ellie Huxtable 4.6k Jan 1, 2023
a cute shell thingy that written in rust

a cute shell thingy that written in rust

奥田 龍馬 12 Dec 29, 2021
A shell for research papers

Reason: A Shell for Research Papers Did I ever read this paper? Which OSDI 2021 papers did I read? Which ones have the word 'Distributed' in their tit

Jae-Won Chung 121 Nov 27, 2022
Explore from the safety of your shell

turtlescan Explore from the safety of your shell Installation: cargo install turtlescan tui Starts a little tui which connects to your JSON-RPC server

Brian Cloutier 4 Sep 13, 2022
dune - A shell by the beach!

dune - A shell by the beach!

adam mcdaniel 640 Dec 29, 2022
A command-line shell like fish, but POSIX compatible.

A command-line shell like fish, but POSIX compatible.

Seiya Nuta 813 Dec 29, 2022
Zash - A Zuper Awesome Shell

Zash - A Zuper Awesome Shell Welcome to zash, its activily being developed and is not near a stable release. Installation Arch: yay -S zash Paru seem

Robiot 27 May 22, 2022