Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .cursor/rules/ai-output-variants.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
description:
globs:
alwaysApply: false
---
Examples of correct responses. Use these program responses as a reference to understand that it's working correctly.

1.
```
> npx ai my ip

┌ AI Shell
◇ Your script:
│ curl ipinfo.io/ip
◇ Explanation:
│ Request to a public service that returns your IP address.
◆ Run this script?
│ ● ✅ Yes (Lets go!)
│ ○ 📝 Revise
│ ○ ❌ Cancel
```

2.
```
> npx ai 'what is the weather in New York'

┌ AI Shell
◇ Your script:
│ curl wttr.in/NewYork
◇ Explanation:
│ Popular weather service that prints weather in a beautiful format with ASCII graphics.
◆ Run this script?
│ ● ✅ Yes (Lets go!)
│ ○ 📝 Revise
│ ○ ❌ Cancel
```

3.
```
> npx ai find all log files

┌ AI Shell
◇ Your script:
│ find . -type f -name '*.log'
◇ Explanation:
│ Searches for log files in the current directory
◆ Run this script?
│ ● ✅ Yes (Lets go!)
│ ○ 📝 Revise
│ ○ ❌ Cancel
```
22 changes: 22 additions & 0 deletions .cursor/rules/change-build-run-repeat.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
description:
globs:
alwaysApply: true
---
## Development Instructions (Always Apply)

1. Install dependencies ($1): `npm install` - only if a new dependency was used and/or an old one was removed.
2. Build ($2): `npm run build` - if code was changed and needs to be rebuilt.
3. Run ($3): `npx ai 'description of what needs to be done'` - for functionality testing (for understanding how it should work, see `.cursor/rules/ai-output-variants.mdc`).
4. Fix, log, debug, change dependencies ($1), rebuild ($2), and run ($3) as needed until the task is completed.

p.s. For convenience, you can run commands ^2 and ^3 together using `$1 && $2` at once.

## Additional (if required)

Log ONLY using `src/helpers/logger.ts` (methods). Do not use `console.log`. Code snippets for use:
- Import: `import { logger } from './logger';`
- Call: `logger.debug(message: string, data?: any);` (as well as `info`, `error`)
- See logs here: `./logs/ai-shell.log`

If you need to understand the project structure, see `.cursor/rules/project-files-description.mdc`.
72 changes: 72 additions & 0 deletions .cursor/rules/project-files-description.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
description:
globs:
alwaysApply: false
---
## Project Structure

1. **Main files:**
- `src/cli.ts` - Entry point of the CLI application, handles user commands
- `src/prompt.ts` - Responsible for the beautiful animated interface and response display

2. **AI engines (`src/helpers/engines/`):**
- `engine-api.ts` - Abstract interface for all AI engines
- `engine-factory.ts` - Factory for creating AI engine instances
- `config-platform.ts` - Configuration for AI engines

3. **Helper modules (`src/helpers/`):**
- `completion.ts` - **Key file!** Implementation of OpenAI API integration, response generation and processing (should be in `src/helpers/engines/`, but left here for better git-diff)
- `logger.ts` - Logging system with file rotation support and debug/info/error levels
- `config.ts` - Application settings and configuration management
- `error.ts` - Error handling and exceptions
- `i18n.ts` - Internationalization and interface translations
- `shell-history.ts` - Shell command history management
- `constants.ts` - Application constants
- `os-detect.ts` - Operating system and shell detection
- `stream-to-iterable.ts` - Utility for converting streams to iterable objects
- `stream-to-string.ts` - Utility for converting streams to strings
- `strip-regex-patterns.ts` - Utility for cleaning text from regex patterns
- `replace-all-polyfill.ts` - Polyfill for the replaceAll method

4. **Commands (`src/commands/`):**
- `chat.ts` - Interactive AI chat implementation
- `config.ts` - Application configuration via CLI interface
- `update.ts` - Automatic application updates

5. **Localization (`src/locales/`):**
- Translation files in JSON format for different languages:
- `en.json` - English
- `ru.json` - Russian
- `de.json` - German
- `fr.json` - French
- `es.json` - Spanish
- `pt.json` - Portuguese
- `zh-Hans.json`, `zh-Hant.json` - Chinese (Simplified and Traditional)
- `jp.json` - Japanese
- `ko.json` - Korean
- `ar.json` - Arabic
- `tr.json` - Turkish
- `uk.json` - Ukrainian
- `vi.json` - Vietnamese
- `id.json` - Indonesian

6. **Configuration files (project root):**
- `package.json` - Package description and npm dependencies
- `tsconfig.json` - TypeScript compiler settings
- `.eslintrc.cjs` - ESLint settings for code checking
- `.prettierrc.json` - Code formatting settings
- `.nvmrc` - Node.js version for the project

7. **Documentation:**
- `README.md` - Main project documentation
- `README-zh-Hans.md` - Documentation in Chinese
- `CHANGELOG.md` - Version change list
- `CONTRIBUTING.md` - Contributor guide
- `GIGACHAT_TZ.md` - Technical specification for GigaChat integration
- `LICENSE` - Project license

8. **Working directories:**
- `dist/` - Compiled files for production
- `logs/` - Application log files
- `node_modules/` - Installed npm dependencies
- `gigachat-js/` - Repository with source code of the module for working with GigaChat API
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
.DS_Store
dist
dist
gigachat-js/
logs/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## dev

- **NEW ENGINE**: Added support for GigaChat
- **BREAKING**: Renamed `MODEL` config to `OPENAI_MODEL` for clarity
- **DEFAULT**: Changed default OpenAI model to `gpt-4.1-nano` (most cost-effective)
- **FEATURE**: Added ability to change default config file path via `AI_SHELL_CONFIG_PATH` environment variable
- **FEATURE**: Added Proxy PAC URL configuration support (`PROXY_PAC_URL`)
- **FEATURE**: Added separate `ALL_PROXY` configuration for each AI engine (`OPENAI_ALLPROXY`, `GIGACHAT_ALLPROXY`)

## 1.0.12

- Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion README-zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ai config
│ ○ OpenAI Key
│ ○ OpenAI API Endpoint
│ ○ Silent Mode
│ ● Model (gpt-4o-mini)
│ ● Model (gpt-4.1-nano)
│ ○ Language
│ ○ Cancel
Expand Down
96 changes: 83 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,36 @@
npm install -g @builder.io/ai-shell
```

2. Retrieve your API key from [OpenAI](https://platform.openai.com/account/api-keys)
2. Choose and configure your AI engine:

### Option A: OpenAI (default)

1. Retrieve your API key from [OpenAI](https://platform.openai.com/account/api-keys)

> Note: If you haven't already, you'll have to create an account and set up billing.

3. Set the key so ai-shell can use it:
2. Set the key so ai-shell can use it:

```sh
ai config set OPENAI_KEY=<your openai token>
```

> The default model is `gpt-4.1-nano` (most cost-effective). You can change it using `ai config set OPENAI_MODEL=<model_name>`

### Option B: GigaChat

1. Get your GigaChat API credentials from [AI Platform](https://developers.sber.ru/docs/ru/gigachat/individuals-quickstart)

2. Configure GigaChat as your AI engine:

```sh
ai config set OPENAI_KEY=<your token>
ai config set AI_ENGINE=GigaChat
ai config set GIGACHAT_KEY=<your gigachat api key>
```

This will create a `.ai-shell` file in your home directory.
---

This will create a `.ai-shell` file in your home directory. You can change the path to the config file by setting the `AI_SHELL_CONFIG_PATH` environment variable.

## Usage

Expand All @@ -63,15 +82,18 @@ Then you will get an output like this, where you can choose to run the suggested
```bash
◇ Your script:
find . -name "*.log"
│ find . -name "*.log"
◇ Explanation:
│ 1. Searches for all files with the extension ".log" in the current directory and any subdirectories.
│ 1. Search current directory and subdirectories
│ 2. Find files ending with ".log"
◆ Run this script?
│ ● ✅ Yes (Lets go!)
│ ○ 📝 Revise
│ ○ 📝 Edit
│ ○ 🔁 Revise
│ ○ 📋 Copy
│ ○ ❌ Cancel
```
Expand Down Expand Up @@ -127,14 +149,38 @@ or save the option as a preference using this command:
ai config set SILENT_MODE=true
```

### Custom API endpoint
### Custom API endpoints

You can custom OpenAI API endpoint to set OPENAI_API_ENDPOINT(default: `https://api.openai.com/v1`)
You can customize API endpoints for both engines:

**For OpenAI** (default: `https://api.openai.com/v1`):
```sh
ai config set OPENAI_API_ENDPOINT=<your proxy endpoint>
```

**For GigaChat**:
```sh
ai config set GIGACHAT_API_ENDPOINT=<your gigachat endpoint>
```

### Proxy Configuration

The application supports advanced proxy settings for both engines:

**ALL_PROXY settings** (separate for each engine):
```sh
# For OpenAI
ai config set OPENAI_ALLPROXY=<your_proxy_url>

# For GigaChat
ai config set GIGACHAT_ALLPROXY=<your_proxy_url>
```

**Proxy PAC URL** (common setting):
```sh
ai config set PROXY_PAC_URL=<your_pac_url>
```

### Set Language

![Language UI](https://user-images.githubusercontent.com/1784873/235330029-0a3b394c-d797-41d6-8717-9a6b487f1ae8.gif)
Expand Down Expand Up @@ -178,10 +224,17 @@ To get an interactive UI like below:

```bash
◆ Set config:
│ ○ OpenAI Key
│ ○ OpenAI API Endpoint
│ ● AI Engine (OpenAI)
│ ○ [OpenAI] Key
│ ○ [OpenAI] Model
│ ○ [OpenAI] API Endpoint
│ ○ [OpenAI] ALL_PROXY
│ ○ [GigaChat] Key
│ ○ [GigaChat] Model
│ ○ [GigaChat] API Endpoint
│ ○ [GigaChat] ALL_PROXY
│ ○ [Common] Proxy PAC URL
│ ○ Silent Mode
│ ● Model (gpt-4o-mini)
│ ○ Language
│ ○ Cancel
Expand Down Expand Up @@ -209,12 +262,29 @@ ai update

## Common Issues

### 429 error
### OpenAI Issues

#### 429 error

Some users are reporting a 429 from OpenAI. This is due to incorrect billing setup or excessive quota usage. Please follow [this guide](https://help.openai.com/en/articles/6891831-error-code-429-you-exceeded-your-current-quota-please-check-your-plan-and-billing-details) to fix it.

You can activate billing at [this link](https://platform.openai.com/account/billing/overview). Make sure to add a payment method if not under an active grant from OpenAI.

### GigaChat Issues

#### Authentication errors

If you encounter authentication issues with GigaChat:
1. Verify your API key is correct
2. Ensure your GigaChat account has proper access rights
3. Check that your credentials haven't expired

#### Rate limiting

GigaChat has its own rate limiting. If you encounter 429 errors:
1. Wait a few moments before retrying
2. Check your usage quotas in the Developer Console

## Motivation

I am not a bash wizard, and am dying for access to the copilot CLI, and got impatient.
Expand Down
Loading