codesavant 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +610 -0
  2. package/dist/cli.js +30199 -0
  3. package/package.json +77 -0
package/README.md ADDED
@@ -0,0 +1,610 @@
1
+ # CodeSavant
2
+
3
+ <div align="center">
4
+
5
+ ```
6
+ ██████╗ ██████╗ ██████╗ ███████╗███████╗ █████╗ ██╗ ██╗ █████╗ ███╗ ██╗████████╗
7
+ ██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔════╝██╔══██╗██║ ██║██╔══██╗████╗ ██║╚══██╔══╝
8
+ ██║ ██║ ██║██║ ██║█████╗ ███████╗███████║██║ ██║███████║██╔██╗ ██║ ██║
9
+ ██║ ██║ ██║██║ ██║██╔══╝ ╚════██║██╔══██║╚██╗ ██╔╝██╔══██║██║╚██╗██║ ██║
10
+ ╚██████╗╚██████╔╝██████╔╝███████╗███████║██║ ██║ ╚████╔╝ ██║ ██║██║ ╚████║ ██║
11
+ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝
12
+ ```
13
+
14
+ **Multi-Provider AI Coding Assistant for Your Terminal**
15
+
16
+ [![npm version](https://badge.fury.io/js/codesavant.svg)](https://www.npmjs.com/package/codesavant)
17
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
18
+ [![Node.js Version](https://img.shields.io/node/v/codesavant.svg)](https://nodejs.org)
19
+
20
+ </div>
21
+
22
+ ---
23
+
24
+ ## What is CodeSavant?
25
+
26
+ CodeSavant is a powerful AI coding assistant that runs directly in your terminal. Unlike cloud-based solutions, CodeSavant gives you the flexibility to choose from multiple AI providers (DeepSeek, Groq, Gemini, OpenAI, Anthropic, or local Ollama) while keeping your code and conversations private.
27
+
28
+ **Key Benefits:**
29
+ - **Cost Effective**: Use providers like DeepSeek at $0.14/1M tokens vs $15/1M for GPT-4
30
+ - **Provider Choice**: Switch between 7+ AI providers based on your needs
31
+ - **Privacy First**: Run locally with Ollama, or use any cloud provider
32
+ - **Full Tooling**: Read, write, edit files, run commands, search codebases
33
+ - **Session Persistence**: Continue conversations across terminal sessions
34
+
35
+ ---
36
+
37
+ ## Table of Contents
38
+
39
+ - [Installation](#installation)
40
+ - [Quick Start](#quick-start)
41
+ - [Supported Providers](#supported-providers)
42
+ - [Usage](#usage)
43
+ - [Interactive Mode](#interactive-mode)
44
+ - [Commands](#commands)
45
+ - [Multi-line Input](#multi-line-input)
46
+ - [Configuration](#configuration)
47
+ - [Project Memory (SAVANT.md)](#project-memory-savantmd)
48
+ - [Tools](#tools)
49
+ - [Permission System](#permission-system)
50
+ - [Skills](#skills)
51
+ - [MCP Integration](#mcp-integration)
52
+ - [VS Code Extension](#vs-code-extension)
53
+ - [Environment Variables](#environment-variables)
54
+ - [Troubleshooting](#troubleshooting)
55
+ - [License](#license)
56
+
57
+ ---
58
+
59
+ ## Installation
60
+
61
+ ### Prerequisites
62
+
63
+ - Node.js 18.0.0 or higher
64
+ - At least one AI provider API key (or Ollama installed locally)
65
+
66
+ ### Install via npm
67
+
68
+ ```bash
69
+ npm install -g codesavant
70
+ ```
71
+
72
+ ### Verify Installation
73
+
74
+ ```bash
75
+ codesavant --version
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Quick Start
81
+
82
+ ### 1. Set up an API key
83
+
84
+ Choose at least one provider and set the API key:
85
+
86
+ ```bash
87
+ # DeepSeek (Recommended - Best cost/performance ratio)
88
+ export DEEPSEEK_API_KEY="your-api-key"
89
+
90
+ # Groq (Fastest response times)
91
+ export GROQ_API_KEY="your-api-key"
92
+
93
+ # Google Gemini (Large context window)
94
+ export GEMINI_API_KEY="your-api-key"
95
+
96
+ # OpenAI
97
+ export OPENAI_API_KEY="your-api-key"
98
+
99
+ # Anthropic
100
+ export ANTHROPIC_API_KEY="your-api-key"
101
+
102
+ # Or use Ollama locally (no API key needed)
103
+ # Just ensure Ollama is running: ollama serve
104
+ ```
105
+
106
+ ### 2. Start CodeSavant
107
+
108
+ ```bash
109
+ codesavant
110
+ ```
111
+
112
+ ### 3. Start Coding!
113
+
114
+ ```
115
+ > Explain the structure of this codebase
116
+
117
+ > Create a function to validate email addresses
118
+
119
+ > Fix the bug in src/utils.ts
120
+
121
+ > Write tests for the authentication module
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Supported Providers
127
+
128
+ | Provider | Cost (per 1M tokens) | Speed | Best For | API Key Variable |
129
+ |----------|---------------------|-------|----------|------------------|
130
+ | **DeepSeek** | $0.14 in / $0.28 out | Medium | Primary coding tasks | `DEEPSEEK_API_KEY` |
131
+ | **Groq** | $0.59 in / $0.79 out | Fastest | Quick queries, chat | `GROQ_API_KEY` |
132
+ | **Gemini** | $0.15 in / $0.60 out | Fast | Large context tasks | `GEMINI_API_KEY` |
133
+ | **OpenAI** | $5.00 in / $15.00 out | Medium | Complex reasoning | `OPENAI_API_KEY` |
134
+ | **Anthropic** | $3.00 in / $15.00 out | Medium | Code review, analysis | `ANTHROPIC_API_KEY` |
135
+ | **Vertex AI** | Varies | Medium | Enterprise/GCP users | `GOOGLE_APPLICATION_CREDENTIALS` |
136
+ | **Ollama** | Free (local) | Variable | Offline, privacy | None (local) |
137
+
138
+ **Estimated Monthly Cost**: $2-10 for typical individual usage with DeepSeek/Groq.
139
+
140
+ ### Smart Routing
141
+
142
+ CodeSavant automatically routes requests to the best available provider based on:
143
+ - Task complexity
144
+ - Provider availability
145
+ - Cost optimization
146
+ - Response speed requirements
147
+
148
+ ---
149
+
150
+ ## Usage
151
+
152
+ ### Interactive Mode
153
+
154
+ ```bash
155
+ # Start a new session
156
+ codesavant
157
+
158
+ # Continue the last session
159
+ codesavant -c
160
+ codesavant --continue
161
+
162
+ # Resume a specific session
163
+ codesavant -r <session-id>
164
+ codesavant --resume <session-id>
165
+
166
+ # Start with an initial prompt
167
+ codesavant "Explain this codebase"
168
+
169
+ # Use a specific provider
170
+ codesavant --provider deepseek
171
+ codesavant --provider groq
172
+
173
+ # Use a specific model
174
+ codesavant --model gpt-4o
175
+ ```
176
+
177
+ ### Commands
178
+
179
+ Inside the CodeSavant REPL, use these slash commands:
180
+
181
+ | Command | Description |
182
+ |---------|-------------|
183
+ | `/help` | Show all available commands |
184
+ | `/clear` | Clear conversation history |
185
+ | `/history` | Show conversation history |
186
+ | `/session` | Show current session ID |
187
+ | `/sessions` | List all saved sessions |
188
+ | `/providers` | Show available AI providers |
189
+ | `/stats` | Show token usage and cost statistics |
190
+ | `/compact` | Manually compact conversation context |
191
+ | `/export` | Export conversation to file |
192
+ | `/config` | Show current configuration |
193
+ | `/doctor` | Diagnose configuration issues |
194
+ | `/init` | Initialize CodeSavant in current project |
195
+ | `/exit` | Exit CodeSavant |
196
+
197
+ ### Multi-line Input
198
+
199
+ Use triple quotes `"""` to enter multi-line input:
200
+
201
+ ```
202
+ > """
203
+ Create a React component that:
204
+ - Displays a list of users
205
+ - Supports pagination
206
+ - Has a search filter
207
+ - Shows loading states
208
+ """
209
+ ```
210
+
211
+ Press Enter after the closing `"""` to submit.
212
+
213
+ ---
214
+
215
+ ## Configuration
216
+
217
+ ### Configuration File
218
+
219
+ CodeSavant stores configuration in `~/.codesavant/config.json`:
220
+
221
+ ```json
222
+ {
223
+ "provider": "deepseek",
224
+ "model": "deepseek-coder",
225
+ "maxTokens": 4096,
226
+ "temperature": 0.7,
227
+ "permissions": {
228
+ "mode": "default",
229
+ "allowedPaths": ["."],
230
+ "deniedPaths": ["node_modules", ".git", ".env"]
231
+ }
232
+ }
233
+ ```
234
+
235
+ ### Configuration Commands
236
+
237
+ ```bash
238
+ # View all configuration
239
+ codesavant config
240
+
241
+ # View specific setting
242
+ codesavant config get provider
243
+
244
+ # Set a value
245
+ codesavant config set provider deepseek
246
+ codesavant config set maxTokens 8192
247
+
248
+ # Show available providers
249
+ codesavant config --providers
250
+ ```
251
+
252
+ ### Directory Structure
253
+
254
+ ```
255
+ ~/.codesavant/
256
+ ├── config.json # Global configuration
257
+ ├── sessions/ # Saved conversation sessions
258
+ ├── skills/ # Custom skills
259
+ └── SAVANT.md # Global project memory
260
+ ```
261
+
262
+ ---
263
+
264
+ ## Project Memory (SAVANT.md)
265
+
266
+ Create a `SAVANT.md` file in your project root to give CodeSavant context about your project. This file is automatically read when you start CodeSavant in that directory.
267
+
268
+ ### Example SAVANT.md
269
+
270
+ ```markdown
271
+ # Project: MyApp
272
+
273
+ ## Overview
274
+ E-commerce platform built with Next.js and PostgreSQL.
275
+
276
+ ## Tech Stack
277
+ - Frontend: Next.js 14, React 18, TailwindCSS
278
+ - Backend: Node.js, Express, Prisma ORM
279
+ - Database: PostgreSQL
280
+ - Testing: Jest, Playwright
281
+
282
+ ## Project Structure
283
+ - `/src/app` - Next.js app router pages
284
+ - `/src/components` - Reusable React components
285
+ - `/src/lib` - Utility functions and helpers
286
+ - `/src/api` - API route handlers
287
+ - `/prisma` - Database schema and migrations
288
+
289
+ ## Coding Conventions
290
+ - Use TypeScript strict mode
291
+ - Prefer functional components with hooks
292
+ - Use async/await over promises
293
+ - Run `npm run lint` before committing
294
+
295
+ ## Common Commands
296
+ - `npm run dev` - Start development server
297
+ - `npm run build` - Build for production
298
+ - `npm run test` - Run test suite
299
+ - `npm run db:migrate` - Run database migrations
300
+
301
+ ## Important Notes
302
+ - Never commit .env files
303
+ - Always run tests before pushing
304
+ - Use conventional commits format
305
+ ```
306
+
307
+ ---
308
+
309
+ ## Tools
310
+
311
+ CodeSavant has access to powerful tools for interacting with your codebase:
312
+
313
+ ### File Operations
314
+
315
+ | Tool | Description |
316
+ |------|-------------|
317
+ | **Read** | Read file contents |
318
+ | **Write** | Create or overwrite files |
319
+ | **Edit** | Make precise edits with search/replace |
320
+ | **Glob** | Find files using glob patterns |
321
+ | **Grep** | Search file contents with regex |
322
+
323
+ ### System Operations
324
+
325
+ | Tool | Description |
326
+ |------|-------------|
327
+ | **Bash** | Execute shell commands |
328
+ | **ListDir** | List directory contents |
329
+
330
+ ### Examples
331
+
332
+ ```
333
+ > Read the package.json file
334
+
335
+ > Find all TypeScript files in src/
336
+
337
+ > Search for "TODO" comments in the codebase
338
+
339
+ > Run the test suite
340
+
341
+ > Create a new component file at src/components/Button.tsx
342
+ ```
343
+
344
+ ---
345
+
346
+ ## Permission System
347
+
348
+ CodeSavant asks for permission before potentially dangerous operations to keep your system safe.
349
+
350
+ ### Permission Modes
351
+
352
+ | Mode | Description |
353
+ |------|-------------|
354
+ | `default` | Ask for dangerous operations, auto-allow safe ones |
355
+ | `strict` | Ask for all file writes and commands |
356
+ | `permissive` | Auto-allow most operations (use with caution) |
357
+
358
+ ### Auto-Allowed Operations
359
+ - Reading files
360
+ - Searching with glob/grep
361
+ - Git status, log, diff commands
362
+ - npm/yarn info commands
363
+
364
+ ### Auto-Denied Operations
365
+ - `rm -rf /` and similar destructive commands
366
+ - `sudo` commands
367
+ - Writing to `.env` files
368
+ - Commands with shell injection risks
369
+
370
+ ### Interactive Prompts
371
+
372
+ When prompted for permission, you can respond:
373
+ - `y` or `yes` - Allow this once
374
+ - `n` or `no` - Deny this once
375
+ - `a` or `always` - Allow for this session
376
+ - `never` - Deny for this session
377
+
378
+ ---
379
+
380
+ ## Skills
381
+
382
+ Skills are pre-built prompt templates for common tasks. Use them with the `/` prefix:
383
+
384
+ | Skill | Description |
385
+ |-------|-------------|
386
+ | `/commit` | Generate a git commit message |
387
+ | `/review` | Review code for issues |
388
+ | `/test` | Generate tests for code |
389
+ | `/explain` | Explain how code works |
390
+ | `/refactor` | Suggest refactoring improvements |
391
+
392
+ ### Using Skills
393
+
394
+ ```
395
+ > /commit
396
+
397
+ > /review src/auth.ts
398
+
399
+ > /test src/utils/validation.ts
400
+ ```
401
+
402
+ ---
403
+
404
+ ## MCP Integration
405
+
406
+ CodeSavant supports the Model Context Protocol (MCP) for extending functionality with external tools.
407
+
408
+ ### Configure MCP Servers
409
+
410
+ Create `.codesavant/mcp.json` in your project:
411
+
412
+ ```json
413
+ {
414
+ "servers": {
415
+ "filesystem": {
416
+ "command": "npx",
417
+ "args": ["-y", "@anthropic/mcp-server-filesystem", "/path/to/allowed/dir"]
418
+ },
419
+ "github": {
420
+ "command": "npx",
421
+ "args": ["-y", "@anthropic/mcp-server-github"],
422
+ "env": {
423
+ "GITHUB_TOKEN": "${GITHUB_TOKEN}"
424
+ }
425
+ }
426
+ }
427
+ }
428
+ ```
429
+
430
+ ### View MCP Status
431
+
432
+ ```bash
433
+ codesavant mcp status
434
+ ```
435
+
436
+ ---
437
+
438
+ ## VS Code Extension
439
+
440
+ CodeSavant includes a VS Code extension for integrated development.
441
+
442
+ ### Features
443
+ - Start CodeSavant chat from VS Code
444
+ - Explain selected code
445
+ - Fix code issues
446
+ - Generate tests
447
+ - Code review
448
+
449
+ ### Installation
450
+
451
+ ```bash
452
+ cd vscode-extension
453
+ npm install
454
+ npm run compile
455
+ ```
456
+
457
+ Then press F5 in VS Code to launch in debug mode.
458
+
459
+ ---
460
+
461
+ ## Environment Variables
462
+
463
+ ### API Keys
464
+
465
+ | Variable | Description |
466
+ |----------|-------------|
467
+ | `DEEPSEEK_API_KEY` | DeepSeek API key |
468
+ | `GROQ_API_KEY` | Groq API key |
469
+ | `GEMINI_API_KEY` | Google Gemini API key |
470
+ | `OPENAI_API_KEY` | OpenAI API key |
471
+ | `ANTHROPIC_API_KEY` | Anthropic API key |
472
+ | `GOOGLE_APPLICATION_CREDENTIALS` | Path to GCP credentials for Vertex AI |
473
+
474
+ ### Configuration
475
+
476
+ | Variable | Description |
477
+ |----------|-------------|
478
+ | `CODESAVANT_PROVIDER` | Default AI provider |
479
+ | `CODESAVANT_MODEL` | Default model to use |
480
+ | `CODESAVANT_CONFIG_PATH` | Custom config file path |
481
+
482
+ ### Shell Configuration
483
+
484
+ Add to your `~/.bashrc` or `~/.zshrc`:
485
+
486
+ ```bash
487
+ # API Keys
488
+ export DEEPSEEK_API_KEY="your-key-here"
489
+
490
+ # Aliases
491
+ alias cs="codesavant"
492
+ alias csc="codesavant -c"
493
+ ```
494
+
495
+ ---
496
+
497
+ ## Troubleshooting
498
+
499
+ ### Common Issues
500
+
501
+ #### "No AI providers available"
502
+
503
+ ```bash
504
+ # Check which providers are configured
505
+ codesavant config --providers
506
+
507
+ # Verify API key is set
508
+ echo $DEEPSEEK_API_KEY
509
+ ```
510
+
511
+ #### "Permission denied" errors
512
+
513
+ ```bash
514
+ # Run the doctor command
515
+ codesavant doctor
516
+
517
+ # Check file permissions
518
+ ls -la ~/.codesavant/
519
+ ```
520
+
521
+ #### Session not persisting
522
+
523
+ ```bash
524
+ # Check sessions directory exists
525
+ ls ~/.codesavant/sessions/
526
+
527
+ # List available sessions
528
+ codesavant --list-sessions
529
+ ```
530
+
531
+ #### Slow responses
532
+
533
+ - Try a faster provider like Groq
534
+ - Reduce `maxTokens` in config
535
+ - Use `/compact` to reduce context size
536
+
537
+ ### Debug Mode
538
+
539
+ ```bash
540
+ # Run with verbose logging
541
+ DEBUG=codesavant* codesavant
542
+ ```
543
+
544
+ ### Reset Configuration
545
+
546
+ ```bash
547
+ # Remove config and start fresh
548
+ rm -rf ~/.codesavant/config.json
549
+ codesavant
550
+ ```
551
+
552
+ ---
553
+
554
+ ## CLI Reference
555
+
556
+ ```
557
+ Usage: codesavant [options] [prompt]
558
+
559
+ Options:
560
+ -V, --version Output version number
561
+ -c, --continue Continue last session
562
+ -r, --resume <id> Resume specific session
563
+ -p, --provider <name> Use specific provider
564
+ -m, --model <name> Use specific model
565
+ --list-sessions List all saved sessions
566
+ --no-memory Disable project memory (SAVANT.md)
567
+ -h, --help Display help
568
+
569
+ Commands:
570
+ config Manage configuration
571
+ doctor Diagnose issues
572
+ init Initialize project
573
+ mcp Manage MCP servers
574
+ ```
575
+
576
+ ---
577
+
578
+ ## Contributing
579
+
580
+ Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
581
+
582
+ 1. Fork the repository
583
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
584
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
585
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
586
+ 5. Open a Pull Request
587
+
588
+ ---
589
+
590
+ ## License
591
+
592
+ MIT License - see the [LICENSE](LICENSE) file for details.
593
+
594
+ ---
595
+
596
+ ## Acknowledgments
597
+
598
+ - Built with [Commander.js](https://github.com/tj/commander.js/)
599
+ - Terminal UI powered by [Chalk](https://github.com/chalk/chalk) and [Ink](https://github.com/vadimdemedes/ink)
600
+ - AI integrations via [OpenAI SDK](https://github.com/openai/openai-node) and [Google Generative AI](https://github.com/google/generative-ai-js)
601
+
602
+ ---
603
+
604
+ <div align="center">
605
+
606
+ **Made with love by [Vishal Aggarwal](https://github.com/burnisback)**
607
+
608
+ [Report Bug](https://github.com/burnisback/code-savant-ai/issues) · [Request Feature](https://github.com/burnisback/code-savant-ai/issues)
609
+
610
+ </div>