Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📝 g023's Code Completer

In-terminal code editor with AI-powered code completion
Powered by DeepSeek V4 & Textual

Code Completer Screenshot

✨ Overview

g023's Code Completer is a terminal-based text editor that brings AI-assisted coding directly into your command line. Built with Python and the Textual TUI framework, it provides a lightweight, distraction-free editing environment with deep integration of DeepSeek's state-of-the-art language model to help you write code faster.

Whether you're editing configuration files, writing Python scripts, or tweaking HTML/CSS, the editor offers syntax highlighting, smooth keyboard navigation, and on-demand AI completions – all without leaving your terminal.

Note: This is work in progress. Feel free to test with me.

🎯 Features

Feature Description
Syntax Highlighting Supports Python, JavaScript, HTML, CSS, JSON, and many more languages
AI Code Completion Trigger intelligent completions with Alt+G
Non‑blocking Async Completions run in the background – your workflow never pauses
File Management Open (Ctrl+O) and save (Ctrl+S) files easily
Modal File Browser Visually browse and select files from anywhere in your home directory
Smart Indentation Tab inserts 4 spaces; type‑aware and consistent
Status Bar Real‑time feedback and messages about file operations and completions
Mouse Support Fully interactive with your terminal mouse (if supported)

🚀 Requirements

  • Python 3.8+
  • Textual – the modern TUI framework
  • A DeepSeek API key – get one from DeepSeek Platform

📦 Installation

# Clone the repository
git clone https://github.com/g023/code_completer.git
cd code_completer

# Install the required dependency
pip install textual

🔑 Configuration

The editor needs your DeepSeek API key to work. You can provide it in two ways:

Option 1: Environment Variable (recommended)

export DEEPSEEK_API_KEY="your-api-key-here"

Option 2: Key File

Place a file named K.dat one directory above the project root. The file should contain your API key as a single line.

💡 The key resolution logic looks for ../K.dat relative to the script location. This keeps your key out of the repository while still working across environments.

🎮 Usage

Starting the Editor

python code_completer.py

To open a specific file on launch:

python code_completer.py path/to/your/file.py

Keyboard Shortcuts

Shortcut Action
Ctrl+O Open a file
Ctrl+S Save the current file
Ctrl+Q Quit the editor
Alt+G Request AI completion at cursor position
Tab Insert 4 spaces (indent)
Mouse Click to move cursor, navigate file browser

🧠 How It Works

The editor is split into two main components:

1. The Editor Frontend (code_completer.py)

  • Built with Textual – a reactive TUI framework with CSS-like styling
  • Manages the main editing area, file browser modal, and status updates
  • Handles user input, syntax highlighting, and file I/O

2. The AI Backend (_ds4.py)

  • A minimal, zero‑dependency DeepSeek client
  • Implements rate limiting, retry logic, and automatic API key resolution
  • Supports chat_prefix_complete() – DeepSeek V4’s efficient prefix completion API

Completion Pipeline

  1. When you press Alt+G, the current code and cursor position are captured.
  2. The code is split into prefix (text before cursor) and suffix (text after cursor).
  3. A structured prompt is sent to DeepSeek V4 using the chat_prefix_complete endpoint – this tells the model to only return raw completion text (no greetings, no markdown, no explanations).
  4. The response is then cleaned:
    • Meta‑phrases like "Here's the completion:" are stripped.
    • Lines ending with a question mark are removed (when enabled).
    • Short or empty completions are filtered out.
  5. The cleaned completion is inserted at the cursor – asynchronously, so the editor never freezes.

All heavy API calls run in a dedicated thread; UI updates are safely posted back to the main thread.

⚙️ Tunable Parameters

The behaviour of the AI completion can be adjusted by editing the constants at the top of code_completer.py:

Parameter Default Description
COMPLETION_TEMPERATURE 0.15 Lower = more deterministic, higher = more creative
COMPLETION_MAX_TOKENS 512 Maximum length of the completion response
MIN_COMPLETION_LENGTH 3 Drop completions shorter than this (filters stray characters)
MAX_COMPLETION_LENGTH 2000 Hard cap on returned characters
STRIP_QUESTION_LINES True Remove lines that look like clarifying questions
STRIP_META_LINES True Remove conversational filler (e.g., "Sure, here's...")

🔧 Troubleshooting

"DeepSeek API key not found"

  • Make sure you’ve set the DEEPSEEK_API_KEY environment variable, or created ../K.dat relative to the project folder.
  • Verify the key is valid and has sufficient credits.

"DeepSeek init error"

  • Check your internet connection.
  • Ensure you’ve installed textual (pip install textual).
  • Try running the script from outside a virtual environment if you suspect dependency conflicts.

Completions are empty or very short

  • The built‑in cleaning logic may be filtering out legitimate output. Try setting STRIP_META_LINES = False and MIN_COMPLETION_LENGTH = 1 temporarily to see the raw response.
  • DeepSeek V4 works best with clear context. Make sure your code is well‑structured and the cursor is placed logically.

The editor feels sluggish

  • Completions run asynchronously, so they shouldn’t block typing. If you experience lag, check your terminal emulator settings or try a different terminal (e.g., Alacritty, Kitty, iTerm2).

📜 License

MIT – feel free to use, modify, and distribute.

🙏 Acknowledgments

  • DeepSeek for their powerful and affordable language models.
  • Textual for making terminal UI development a joy.
  • The open‑source community for endless inspiration.

About

g023's Code Completer - In-terminal code editor with ai completion powered by DeepSeek V4 and Textual

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages