Skip to content

LineSense is an intelligent shell assistant that provides context-aware command suggestions and explanations.

License

Notifications You must be signed in to change notification settings

Traves-Theberge/LineSense

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

56 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

LineSense

   __   _            ____                       
  / /  (_)_ __   ___/ ___|  ___ _ __  ___  ___  
 / /   | | '_ \ / _ \___ \ / _ \ '_ \/ __|/ _ \ 
/ /___ | | | | |  __/___) |  __/ | | \__ \  __/ 
\____/ |_|_| |_|\___|____/ \___|_| |_|___/\___| 

AI-Powered Shell Assistant (v0.6.6)

CI Tests Coverage Go Version License Go Report Card

Overview

LineSense is an intelligent shell assistant that provides context-aware command suggestions and explanations. It integrates seamlessly with bash and zsh, learning from your usage patterns.

Features

  • ๐ŸŽฏ OS-Aware Suggestions (NEW in v0.5.2): Automatically detects your OS, distribution, and package manager
    • Get brew install on macOS, apt install on Ubuntu, pacman -S on Arch
    • Smart command suggestions tailored to your system
    • Zero configuration required
  • ๐ŸŽจ Beautiful Terminal UI: Styled output with colors, borders, and dynamic width adjustment
  • ๐Ÿ”„ Dual Output Modes: Pretty format for humans, JSON for scripting (--format flag)
  • ๐ŸŒ Global Instructions: Define personal rules that apply everywhere (e.g., "Always use bat")
  • ๐Ÿ“ Project Context: Add .linesense_context files for directory-specific AI knowledge
  • โšก Loading Indicators: Animated spinner while AI processes your request
  • ๐Ÿง  Context-Aware Suggestions: Uses git info, shell history, environment, and OS context
  • ๐Ÿ›ก๏ธ Safety First: Risk classification and configurable denylists
  • ๐Ÿš Multi-Shell Support: Works with bash and zsh
  • ๐Ÿš€ OpenRouter Integration: Powered by state-of-the-art LLMs via OpenRouter
  • ๐Ÿ“ Responsive Design: Output automatically adapts to terminal width
  • ๐Ÿ’ก Smart Explanations: Each suggestion includes a brief 5-10 word explanation
  • ๐Ÿ”ข Multiple Suggestions: Get 3-5 alternative command options for every request

Project Structure

.
โ”œโ”€โ”€ cmd/
โ”‚   โ””โ”€โ”€ linesense/          # Main CLI binary
โ”‚       โ”œโ”€โ”€ main.go         # CLI entry point
โ”‚       โ””โ”€โ”€ ui.go           # Terminal UI (Lipgloss/Bubbletea)
โ”œโ”€โ”€ internal/
โ”‚   โ”œโ”€โ”€ config/             # Configuration loading
โ”‚   โ”‚   โ”œโ”€โ”€ config.go       # Global config
โ”‚   โ”‚   โ””โ”€โ”€ providers.go    # Provider/model config
โ”‚   โ”œโ”€โ”€ core/               # Core engine
โ”‚   โ”‚   โ”œโ”€โ”€ context.go      # Context gathering
โ”‚   โ”‚   โ”œโ”€โ”€ engine.go       # Main suggest/explain engine
โ”‚   โ”‚   โ”œโ”€โ”€ git.go          # Git integration
โ”‚   โ”‚   โ”œโ”€โ”€ history.go      # Shell history
โ”‚   โ”‚   โ”œโ”€โ”€ osdetect.go     # OS & package manager detection
โ”‚   โ”‚   โ”œโ”€โ”€ safety.go       # Safety filters
โ”‚   โ”‚   โ””โ”€โ”€ usage.go        # Usage logging
โ”‚   โ””โ”€โ”€ ai/                 # AI provider implementations
โ”‚       โ”œโ”€โ”€ provider.go     # Provider factory
โ”‚       โ”œโ”€โ”€ prompts.go      # AI prompts & parsing
โ”‚       โ””โ”€โ”€ openrouter.go   # OpenRouter implementation
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ linesense.bash      # Bash integration
โ”‚   โ””โ”€โ”€ linesense.zsh       # Zsh integration
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ config.toml         # Example global config
โ”‚   โ””โ”€โ”€ providers.toml      # Example providers config
โ”œโ”€โ”€ docs/                   # Comprehensive documentation
โ”‚   โ”œโ”€โ”€ INSTALLATION.md     # Installation guide
โ”‚   โ”œโ”€โ”€ CONFIGURATION.md    # Configuration reference
โ”‚   โ”œโ”€โ”€ SECURITY.md         # Security features
โ”‚   โ”œโ”€โ”€ API.md              # CLI reference
โ”‚   โ”œโ”€โ”€ TESTING.md          # Testing guide
โ”‚   โ””โ”€โ”€ CI_CD.md            # CI/CD and release process
โ””โ”€โ”€ docs/               # Documentation (including PRD)

Quick Start

Automated Installation (Recommended)

The easiest way to install LineSense is using the automated installation script:

# Download and run the installer
curl -fsSL https://raw.githubusercontent.com/traves-theberge/LineSense/main/install.sh | bash

This will:

  • โœ… Build and install LineSense
  • โœ… Set up shell integration (bash/zsh)
  • โœ… Initialize configuration
  • โœ… Guide you through API key setup

Then restart your shell and set your API key:

# Restart your shell or reload config
source ~/.bashrc  # or ~/.zshrc

# Set your OpenRouter API key (interactive)
linesense config set-key

Manual Installation

If you prefer to install manually or want more control:

Prerequisites

Install from Source

# 1. Clone the repository
git clone https://github.com/Traves-Theberge/LineSense.git
cd LineSense

# 2. Build and install
go install ./cmd/linesense

# 3. Initialize configuration
linesense config init

# 4. Set your OpenRouter API key
linesense config set-key

# 5. Set up shell integration
# For bash, add to ~/.bashrc:
echo '[ -f "$HOME/.config/linesense/shell/linesense.bash" ] && source "$HOME/.config/linesense/shell/linesense.bash"' >> ~/.bashrc

# For zsh, add to ~/.zshrc:
echo '[ -f "$HOME/.config/linesense/shell/linesense.zsh" ] && source "$HOME/.config/linesense/shell/linesense.zsh"' >> ~/.zshrc

# 6. Reload your shell
source ~/.bashrc  # or ~/.zshrc

Alternative: Go Install

Install directly from the repository:

go install github.com/Traves-Theberge/LineSense/cmd/linesense@latest
linesense config init
linesense config set-key

Verify Installation

# Check version
linesense --version

# View configuration
linesense config show

# Try it out!
linesense suggest --line "list files sorted by size"
linesense explain --line "docker ps -a"

Usage

CLI Commands

LineSense provides two main commands:

Suggest Command

Generate command suggestions based on natural language input:

# Pretty output (default) - beautiful terminal UI
linesense suggest --line "list files"

# JSON output for scripting
linesense suggest --line "list files" --format json

# Advanced options
linesense suggest --line "find large files" --cwd /var/log
linesense suggest --line "git com" --model openai/gpt-4o

Pretty Output (default):

๐Ÿ’ก Command Suggestions
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

1. ls -lhS
   โœ“ Risk: low
   List files sorted by size in human-readable format

2. find . -type f -exec du -h {} + | sort -rh | head -20
   โœ“ Risk: low
   Find and display 20 largest files

3. du -ah . | sort -rh | head -20
   โœ“ Risk: low
   Show disk usage sorted by size

OS-Aware Examples:

Ubuntu user types "install nginx":

1. sudo apt install nginx
   โš  Risk: medium
   Install nginx web server using apt

2. sudo apt install nginx-full
   โš  Risk: medium
   Install nginx with all available modules

macOS user types "install nginx":

1. brew install nginx
   โœ“ Risk: low
   Install nginx web server using Homebrew

2. brew install nginx --with-pcre
   โœ“ Risk: low
   Install nginx with PCRE support

JSON Output (--format json):

{
  "suggestions": [
    {
      "command": "ls -al",
      "risk": "low",
      "explanation": "Suggested based on: list files",
      "source": "llm"
    }
  ]
}

Explain Command

Get detailed explanations of commands:

# Pretty output (default) - beautiful terminal UI
linesense explain --line "docker ps -a"

# JSON output for scripting
linesense explain --line "docker ps -a" --format json

Pretty Output (default):

๐Ÿ“– Command Explanation
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Summary                                                                      โ”‚
โ”‚                                                                              โ”‚
โ”‚ Lists all Docker containers (running and stopped) with their details        โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โœ“ Risk Level: low                                                           โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Details

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ What it does                                                                 โ”‚
โ”‚ - Shows container ID, image, command, status, ports, and names              โ”‚
โ”‚ - The -a flag includes stopped containers                                   โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

JSON Output (--format json):

{
  "summary": "Lists all Docker containers (running and stopped)...",
  "risk": "low",
  "notes": [
    "What it does",
    "- Shows container ID, image, command..."
  ]
}

Shell Integration

LineSense provides interactive shell integration for both bash and zsh. The integration loads silently in the background - no startup messages or notifications.

Default Keybindings:

  • Press Ctrl+Space to get AI-powered command suggestions
  • Press Ctrl+X to get an explanation of the current command

Customization: You can customize keybindings by setting environment variables before sourcing the script:

# In your ~/.bashrc or ~/.zshrc
export LINESENSE_SUGGEST_KEY="\C-t"      # Change suggest to Ctrl+T
export LINESENSE_EXPLAIN_KEY="\C-x\C-h"  # Change explain to Ctrl+X Ctrl+H
source ~/.config/linesense/shell/linesense.bash

Features:

  • ๐Ÿ’ก Smart suggestions - handles typos and provides intent-based alternatives
  • ๐Ÿ“– Detailed explanations - comprehensive command breakdowns with risk assessment
  • ๐Ÿง  Context-aware - uses current directory, git status, and shell history
  • ๐Ÿ–ฅ๏ธ OS-aware - detects your operating system, distribution, and package manager for tailored suggestions

Configuration

LineSense uses a TOML configuration file located at ~/.config/linesense/config.toml.

Global Instructions

You can define global rules that the AI should always follow. This is useful for enforcing personal preferences or tools.

To edit your configuration, run:

linesense config edit

Then add your instructions to the [context] section:

[context]
global_instructions = """
- Always prefer 'bat' over 'cat'
- Use 'podman' instead of 'docker'
- When suggesting git commands, always include '--verbose'
"""

Project-Specific Context

For project-specific rules, create a .linesense_context file in your project's root directory. LineSense will automatically read this file when you are working in that directory.

You can easily create this file using the CLI:

linesense config init-project

Example .linesense_context:

This project uses a custom CLI tool called 'ops-cli'.
- To build: ops-cli build --env=prod
- To deploy: ops-cli deploy --region=us-east-1
- Never use 'kubectl' directly, always use 'ops-cli k8s' wrapper.

About

LineSense is an intelligent shell assistant that provides context-aware command suggestions and explanations.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Contributors 2

  •  
  •