UNPKG

@prdpspkt/g-coder

Version:

AI-powered CLI coding assistant supporting Ollama, OpenAI, Claude, DeepSeek and more

363 lines (260 loc) โ€ข 8.85 kB
# G-Coder ๐Ÿš€ **AI-powered CLI coding assistant with multi-provider support and intelligent automation** [![npm version](https://img.shields.io/npm/v/@prdpspkt/g-coder.svg)](https://www.npmjs.com/package/@prdpspkt/g-coder) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Node.js](https://img.shields.io/badge/node-%3E%3D16.0.0-brightgreen.svg)](https://nodejs.org/) ## Why G-Coder? โœ… **Universal Provider Support** - Use ANY OpenAI-compatible API (Ollama, DeepSeek, OpenAI, Groq, Together AI, etc.) โœ… **100% Free Option** - Run locally with Ollama (no API costs) โœ… **Smart Project Memory** - Persistent conversation history per project โœ… **Auto Token Management** - Seamless continuation when limits hit โœ… **Advanced Security** - OS-aware risk detection and approval system โœ… **Highly Customizable** - Custom commands, hooks, and configurations --- ## ๐Ÿ“ฆ Installation ```bash npm install -g @prdpspkt/g-coder ``` --- ## ๐Ÿš€ Quick Start ### 1. Run G-Coder (Auto Setup) ```bash g-coder ``` First run creates default config with Ollama (local, free). If you need API providers, interactive setup will guide you. ### 2. Manual Setup (Optional) **For Ollama (Free, Local):** ```bash # Install Ollama brew install ollama # macOS # or: https://ollama.ai/download # Start and pull model ollama serve ollama pull codellama # G-Coder default config already set for Ollama! ``` **For API Providers (DeepSeek, OpenAI, etc.):** Edit `~/.g-coder/config.json`: ```json { "provider": "deepseek", "model": "deepseek-chat", "baseUrl": "https://api.deepseek.com/v1", "apiKeyName": "DEEPSEEK_API_KEY" } ``` Add API key to `~/.g-coder/.env`: ```bash echo "DEEPSEEK_API_KEY=sk-your-key" >> ~/.g-coder/.env ``` --- ## โš™๏ธ Configuration ### Supported Providers G-Coder works with **ANY OpenAI-compatible API**: | Provider | baseUrl | Model Example | |----------|---------|---------------| | **Ollama** | `http://localhost:11434/v1` | `codellama`, `deepseek-coder` | | **DeepSeek** | `https://api.deepseek.com/v1` | `deepseek-chat`, `deepseek-reasoner` | | **OpenAI** | `https://api.openai.com/v1` | `gpt-4`, `gpt-3.5-turbo` | | **Groq** | `https://api.groq.com/openai/v1` | `llama-3.1-70b-versatile` | | **Together AI** | `https://api.together.xyz/v1` | `meta-llama/Llama-3-70b` | | **Custom** | `https://your-api.com/v1` | Any model name | > **Note:** Anthropic Claude uses its own API format: `https://api.anthropic.com/v1` ### Configuration Structure `~/.g-coder/config.json`: ```json { "provider": "your-provider-name", "model": "model-name", "baseUrl": "https://api.example.com/v1", "apiKeyName": "YOUR_API_KEY_ENV_VAR", "temperature": 0.7, "maxTokens": 8192, "approval": { "enabled": true, "toolsRequiringApproval": { "Bash": true, "Write": true, "Edit": true } } } ``` `~/.g-coder/.env`: ```bash YOUR_API_KEY_ENV_VAR=your-actual-api-key ``` **๐Ÿ“˜ See [CONFIGURATION.md](./CONFIGURATION.md) for detailed examples** --- ## ๐Ÿ“š Usage ### Start Interactive Session ```bash g-coder # Start with default config g-coder start # Explicit start g-coder start -v # Verbose logging g-coder setup # Run setup wizard ``` ### In-Session Commands **Basic:** - `/help` - Show help - `/clear` - Clear conversation - `/tools` - List available tools - `/exit` - Exit application **Configuration:** - `/config` - Show configuration - `/model` - Change model - `/approval` - Manage approval settings **History & Sessions:** - `/history` - View conversation history - `/save <name>` - Save current session - `/load <name>` - Load saved session - `/sessions` - List all sessions --- ## ๐Ÿ› ๏ธ Available Tools G-Coder provides intelligent tools for coding tasks: ### File Operations - **Read** - Read file contents - **Write** - Create/overwrite files (approval required) - **Edit** - Smart file editing with fuzzy matching (approval required) - **NotebookEdit** - Edit Jupyter notebooks (approval required) ### Search - **Glob** - Find files by pattern (`**/*.ts`) - **Grep** - Search code with regex ### Execution - **Bash** - Run shell commands (approval required) - **BashOutput** - Read background process output - **KillShell** - Stop background processes ### Git - **GitStatus**, **GitDiff** - View changes - **GitCommit**, **GitPush** - Create commits and push (approval required) ### Web - **WebFetch** - Fetch web content (approval required) --- ## ๐Ÿ”’ Security & Approval ### Risk-Based Approval System Operations are categorized by risk: - ๐ŸŸข **Safe** (no approval): Read, Glob, Grep, GitStatus, GitDiff - ๐ŸŸก **Medium** (approval): Write, Edit, WebFetch - ๐ŸŸ  **High** (approval): Bash, GitCommit - ๐Ÿ”ด **Critical** (approval): GitPush, destructive operations ### OS-Aware Security Automatically detects dangerous patterns: **Windows:** `del /s`, `format`, registry modifications **Linux/Mac:** `rm -rf /`, `sudo rm`, root operations ### Auto-Approve When approving, choose "auto-approve similar" to skip future prompts for the same operation. --- ## ๐Ÿง  Project Intelligence ### Automatic Features - **Project Detection** - Recognizes Node.js, Python, Go, Rust, etc. - **Persistent History** - Last 50 interactions saved per project - **Context Restoration** - Previous conversations loaded on startup - **Smart Scanning** - Understands project structure automatically ### Startup Context Example ``` ๐Ÿ“š Previous Conversation Context: Previous session: 2025-01-15 10:30 Total interactions: 42 messages Recent topics: Implemented auth; Fixed DB connection Loaded 5 interactions for context ``` --- ## โ™พ๏ธ Token Management G-Coder handles token limits automatically: **90% Warning:** ``` โš ๏ธ Approaching limit: 7200/8000 tokens (90%) ``` **100% Auto-Save:** ``` โš ๏ธ Token Limit Exceeded Auto-saving and continuing... โœ“ Saved: auto-save-2025-01-15T10-30-45 Session ID: abc123 Load with: /load abc123 โœ“ Ready to continue! ``` **No manual intervention needed!** --- ## ๐ŸŽจ Customization ### Custom Slash Commands Create `~/.g-coder/commands/review.md`: ```markdown --- description: Review code for best practices --- Review this project for: 1. Code quality 2. Potential bugs 3. Security issues ``` Usage: `/review` ### Event Hooks Create `~/.g-coder/hooks.json`: ```json { "enabled": true, "hooks": { "session_start": ["git fetch"], "session_end": ["git status"] } } ``` --- ## ๐Ÿ†š G-Coder vs Claude Code | Feature | G-Coder | Claude Code | |---------|---------|-------------| | **Multi-Provider** | โœ… Ollama, DeepSeek, OpenAI, Groq, etc. | โŒ Claude only | | **Free Option** | โœ… Ollama (local, free) | โŒ Requires API | | **Project History** | โœ… Persistent per-project | โŒ Session only | | **Auto Token Mgmt** | โœ… Auto-save & continue | โŒ Manual | | **OS-Aware Security** | โœ… Risk detection | โš ๏ธ Basic | | **Customization** | โœ… Commands, hooks, configs | โŒ Limited | **Choose G-Coder if you want:** - ๐Ÿ†“ Free local models - ๐Ÿ”„ Provider flexibility - ๐Ÿ“š Project memory - โ™พ๏ธ Automatic continuation - ๐Ÿ”’ Advanced security - ๐ŸŽจ Full customization --- ## ๐Ÿ“– Documentation - **[CONFIGURATION.md](./CONFIGURATION.md)** - Detailed provider setup (7+ examples) - **[config.examples.json](./config.examples.json)** - Ready-to-use configs - **[MINIMAL_SYSTEM_PROMPT.md](./MINIMAL_SYSTEM_PROMPT.md)** - System prompt guide - **[TOOLS_REFERENCE.md](./TOOLS_REFERENCE.md)** - Complete tool documentation --- ## ๐Ÿ› Troubleshooting **Ollama not connecting:** ```bash ollama serve # Start Ollama ollama pull codellama # Pull model g-coder test # Test connection ``` **API key not found:** ```bash cat ~/.g-coder/.env # Check API key g-coder config --show # Verify config ``` **Config corrupted:** - G-Coder auto-creates backup and fresh config - Check `~/.g-coder/config.json.backup.*` --- ## ๐Ÿค Contributing Contributions welcome! Please submit PRs. ```bash git clone https://github.com/prdpspkt/g-coder.git cd g-coder npm install npm run build ``` --- ## ๐Ÿ“ License MIT License - see [LICENSE](LICENSE) --- ## ๐Ÿ“ฌ Support - **Issues:** https://github.com/prdpspkt/g-coder/issues - **NPM:** https://www.npmjs.com/package/@prdpspkt/g-coder --- **Made with ๐Ÿš€ by developers, for developers** เคถเฅเคฐเฅ€ เค—เคฃเฅ‡เคถเคพเคฏ เคจเคฎ: