berget 1.3.0 → 1.4.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.
@@ -0,0 +1,56 @@
1
+ name: Publish to NPM
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ release:
8
+ types: [published]
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Checkout code
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Setup Node.js
18
+ uses: actions/setup-node@v4
19
+ with:
20
+ node-version: '18'
21
+ cache: 'npm'
22
+
23
+ - name: Install dependencies
24
+ run: npm ci
25
+
26
+ - name: Run tests
27
+ run: npm run test:run
28
+
29
+ - name: Build project
30
+ run: npm run build
31
+
32
+ publish:
33
+ needs: test
34
+ runs-on: ubuntu-latest
35
+ if: github.ref == 'refs/heads/main' || github.event_name == 'release'
36
+ steps:
37
+ - name: Checkout code
38
+ uses: actions/checkout@v4
39
+
40
+ - name: Setup Node.js
41
+ uses: actions/setup-node@v4
42
+ with:
43
+ node-version: '18'
44
+ registry-url: 'https://registry.npmjs.org'
45
+ cache: 'npm'
46
+
47
+ - name: Install dependencies
48
+ run: npm ci
49
+
50
+ - name: Build project
51
+ run: npm run build
52
+
53
+ - name: Publish to NPM
54
+ run: npm publish
55
+ env:
56
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,38 @@
1
+ name: Test
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - main
7
+ push:
8
+ branches:
9
+ - main
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ node-version: [18, 20]
17
+
18
+ steps:
19
+ - name: Checkout code
20
+ uses: actions/checkout@v4
21
+
22
+ - name: Setup Node.js ${{ matrix.node-version }}
23
+ uses: actions/setup-node@v4
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+ cache: 'npm'
27
+
28
+ - name: Install dependencies
29
+ run: npm ci
30
+
31
+ - name: Run tests
32
+ run: npm run test:run
33
+
34
+ - name: Build project
35
+ run: npm run build
36
+
37
+ - name: Check TypeScript
38
+ run: npx tsc --noEmit
package/README.md CHANGED
@@ -1,33 +1,193 @@
1
1
  # Berget CLI
2
2
 
3
- A command-line interface for interacting with the Berget AI infrastructure.
3
+ A command-line tool for interacting with Berget AI's infrastructure and AI models.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
8
  npm install -g berget
9
+ # or use directly with npx
10
+ npx berget --help
9
11
  ```
10
12
 
11
13
  ## Authentication
12
14
 
13
- The CLI uses OAuth-based authentication with automatic token refresh.
15
+ Before you can use the CLI, you need to authenticate:
14
16
 
15
- ### Login
17
+ ```bash
18
+ # Login with OAuth
19
+ npx berget auth login
20
+
21
+ # Create an API key
22
+ npx berget api-keys create --name "My CLI Key"
23
+
24
+ # Or use environment variable
25
+ export BERGET_API_KEY=sk_ber_your_api_key_here
26
+ ```
27
+
28
+ ## Chat Command
29
+
30
+ ### Basic Usage
31
+
32
+ ```bash
33
+ # Interactive chat session
34
+ npx berget chat run
35
+
36
+ # Use specific model
37
+ npx berget chat run openai/gpt-oss
38
+
39
+ # Send direct message
40
+ npx berget chat run openai/gpt-oss "Explain what Docker is"
41
+
42
+ # Use pipe for input
43
+ echo "What is Kubernetes?" | npx berget chat run openai/gpt-oss
44
+ ```
45
+
46
+ ### Practical Use Cases
47
+
48
+ #### 1. Git Commit Messages
16
49
 
17
50
  ```bash
18
- berget auth login
51
+ # Generate commit message from git diff
52
+ git diff | npx berget chat run openai/gpt-oss "Create a conventional commit message for this diff. Reply with only the message:"
53
+
54
+ # Use as alias
55
+ alias gitcommit='git diff | npx berget chat run openai/gpt-oss "Generate a conventional commit message for this diff. Reply with only the commit message, nothing else:"'
19
56
  ```
20
57
 
21
- This will open a browser window to authenticate with Berget. After successful authentication, your access token and refresh token will be stored securely in `~/.berget/auth.json`.
58
+ #### 2. Code Review and Explanations
22
59
 
23
- ### Token Refresh
60
+ ```bash
61
+ # Explain code
62
+ cat src/main.js | npx berget chat run openai/gpt-oss "Explain what this code does:"
24
63
 
25
- The CLI automatically handles token refresh when:
64
+ # Find bugs
65
+ cat problematic-file.py | npx berget chat run openai/gpt-oss "Analyze this code and find potential bugs:"
26
66
 
27
- 1. The access token is about to expire (within 10 minutes of expiration)
28
- 2. A request returns a 401 Unauthorized error
67
+ # Improvement suggestions
68
+ git diff | npx berget chat run openai/gpt-oss "Give suggestions for improvements to this code change:"
69
+ ```
29
70
 
30
- The refresh mechanism uses the stored refresh token to obtain a new access token without requiring you to log in again. If the refresh token itself is expired or invalid, you'll be prompted to log in again.
71
+ #### 3. Documentation
72
+
73
+ ```bash
74
+ # Generate README
75
+ ls -la | npx berget chat run openai/gpt-oss "Create a README.md for this project based on the file structure:"
76
+
77
+ # Comment code
78
+ cat uncommented-code.js | npx berget chat run openai/gpt-oss "Add JSDoc comments to this code:"
79
+ ```
80
+
81
+ #### 4. System Administration
82
+
83
+ ```bash
84
+ # Analyze logs
85
+ tail -n 100 /var/log/nginx/error.log | npx berget chat run openai/gpt-oss "Analyze these error logs and suggest solutions:"
86
+
87
+ # Explain commands
88
+ npx berget chat run openai/gpt-oss "Explain what this bash command does: find . -name '*.js' -exec grep -l 'TODO' {} \;"
89
+ ```
90
+
91
+ ## Useful Bash/Zsh Aliases
92
+
93
+ Add these to your `~/.bashrc`, `~/.zshrc` or similar:
94
+
95
+ ```bash
96
+ # Git-related aliases
97
+ alias gai='git diff | npx berget chat run openai/gpt-oss "Generate a conventional commit message for this diff. Reply with only the commit message, nothing else:"'
98
+ alias gexplain='git log --oneline -10 | npx berget chat run openai/gpt-oss "Explain what these commits do:"'
99
+ alias gsec='~/bin/security-check'
100
+
101
+ # Code-related aliases
102
+ alias explain='npx berget chat run openai/gpt-oss "Explain this code:"'
103
+ alias review='npx berget chat run openai/gpt-oss "Review this code and give improvement suggestions:"'
104
+ alias debug='npx berget chat run openai/gpt-oss "Find and explain potential bugs in this code:"'
105
+
106
+ # Documentation aliases
107
+ alias docgen='npx berget chat run openai/gpt-oss "Generate documentation for this code:"'
108
+ alias readme='ls -la | npx berget chat run openai/gpt-oss "Create a README.md for this project:"'
109
+
110
+ # System aliases
111
+ alias loganalyze='npx berget chat run openai/gpt-oss "Analyze these logs and suggest solutions:"'
112
+ alias cmdexplain='npx berget chat run openai/gpt-oss "Explain this command:"'
113
+
114
+ # Quick AI assistant
115
+ alias ai='npx berget chat run openai/gpt-oss'
116
+ alias ask='npx berget chat run openai/gpt-oss'
117
+ ```
118
+
119
+ ## Advanced Examples
120
+
121
+ See the `examples/` folder for complete scripts:
122
+
123
+ - **smart-commit.sh** - Automatic generation of conventional commit messages
124
+ - **ai-review.sh** - AI-driven code review
125
+ - **security-check.sh** - Security review of commits
126
+
127
+ ```bash
128
+ # Copy example scripts
129
+ cp examples/*.sh ~/bin/
130
+ chmod +x ~/bin/*.sh
131
+
132
+ # Use them
133
+ ~/bin/smart-commit.sh
134
+ ~/bin/ai-review.sh src/main.js
135
+ ~/bin/security-check.sh
136
+ ```
137
+
138
+ ## Environment Variables
139
+
140
+ ```bash
141
+ # API key (recommended)
142
+ export BERGET_API_KEY=sk_ber_your_api_key_here
143
+
144
+ # Debug mode
145
+ export LOG_LEVEL=debug
146
+
147
+ # Custom API base URL (if using your own instance)
148
+ export API_BASE_URL=https://your-custom-api.example.com
149
+ ```
150
+
151
+ ## Tips and Tricks
152
+
153
+ 1. **Use pipes**: Combine with other Unix tools for powerful workflows
154
+ 2. **Short prompts**: Be specific but concise in your prompts for best results
155
+ 3. **Streaming**: Streaming is enabled by default for faster responses
156
+ 4. **Model selection**: Experiment with different models for different tasks
157
+ 5. **Aliases**: Create aliases for common use cases to save time
158
+
159
+ ## Command Reference
160
+
161
+ - `auth login` - Login to Berget
162
+ - `auth logout` - Logout from Berget
163
+ - `auth whoami` - Show current user information
164
+ - `api-keys list` - List API keys
165
+ - `api-keys create` - Create a new API key
166
+ - `models list` - List available AI models
167
+ - `chat run` - Start a chat session with an AI model
168
+ - `chat list` - List available chat models
169
+
170
+ For a complete list of commands, run:
171
+
172
+ ```bash
173
+ npx berget --help
174
+ ```
175
+
176
+ ## Troubleshooting
177
+
178
+ ```bash
179
+ # Enable debug mode
180
+ npx berget --debug chat run openai/gpt-oss "test"
181
+
182
+ # Check authentication
183
+ npx berget auth whoami
184
+
185
+ # List available models
186
+ npx berget chat list
187
+
188
+ # Check API key status
189
+ npx berget api-keys list
190
+ ```
31
191
 
32
192
  ## Development
33
193
 
@@ -36,12 +196,12 @@ The refresh mechanism uses the stored refresh token to obtain a new access token
36
196
  Clone the repository and install dependencies:
37
197
 
38
198
  ```bash
39
- git clone https://github.com/berget/cli.git
199
+ git clone https://github.com/berget-ai/cli.git
40
200
  cd cli
41
201
  npm install
42
202
  ```
43
203
 
44
- ### Testing Locally
204
+ ### Test Locally
45
205
 
46
206
  Use the `start` script to test the CLI locally with the `--local` flag:
47
207
 
@@ -62,31 +222,10 @@ npm start -- auth whoami
62
222
  npm start -- auth whoami --debug
63
223
  ```
64
224
 
65
- The `--debug` flag provides detailed information about token refresh attempts and API responses.
66
-
67
- ### Testing Token Refresh
68
-
69
- To test the token refresh mechanism:
225
+ ## Contributing
70
226
 
71
- 1. Log in with `npm start -- auth login`
72
- 2. Make a request that requires authentication, like `npm start -- auth whoami`
73
- 3. To force a token refresh, you can:
74
- - Wait until the token is close to expiration
75
- - Manually edit `~/.berget/auth.json` and set `expires_at` to a past timestamp
76
- - Use the `--debug` flag to see the token refresh process in action
227
+ Berget CLI is open source. Contributions are welcome!
77
228
 
78
- ## Commands
79
-
80
- - `auth login` - Log in to Berget
81
- - `auth logout` - Log out from Berget
82
- - `auth whoami` - Show current user information
83
- - `api-keys list` - List API keys
84
- - `api-keys create` - Create a new API key
85
- - `models list` - List available AI models
86
- - `chat run` - Start a chat session with an AI model
87
-
88
- For a complete list of commands, run:
89
-
90
- ```bash
91
- berget --help
92
- ```
229
+ - GitHub: [berget-ai/cli](https://github.com/berget-ai/cli)
230
+ - Issues: [Report bugs](https://github.com/berget-ai/cli/issues)
231
+ - Documentation: [docs.berget.ai](https://docs.berget.ai)
package/dist/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "berget",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "berget": "dist/index.js"
7
7
  },
8
8
  "private": false,
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
9
12
  "scripts": {
10
13
  "start": "node --import tsx ./index.ts --local",
11
14
  "login": "node --import tsx ./index.ts --local auth login",
12
15
  "logout": "node --import tsx ./index.ts --local auth logout",
13
16
  "whoami": "node --import tsx ./index.ts --local auth whoami",
14
17
  "build": "tsc",
18
+ "test": "vitest",
19
+ "test:run": "vitest run",
15
20
  "prepublishOnly": "npm run build",
16
21
  "generate-types": "openapi-typescript https://api.berget.ai/openapi.json -o src/types/api.d.ts"
17
22
  },
@@ -19,14 +24,19 @@
19
24
  "license": "MIT",
20
25
  "description": "This is a cli command for interacting with the AI infrastructure provider Berget",
21
26
  "devDependencies": {
27
+ "@types/marked": "^5.0.2",
28
+ "@types/marked-terminal": "^6.1.1",
22
29
  "@types/node": "^20.11.20",
23
30
  "tsx": "^4.19.3",
24
- "typescript": "^5.3.3"
31
+ "typescript": "^5.3.3",
32
+ "vitest": "^1.0.0"
25
33
  },
26
34
  "dependencies": {
27
35
  "chalk": "^4.1.2",
28
36
  "commander": "^12.0.0",
29
37
  "fs-extra": "^11.3.0",
38
+ "marked": "^9.1.6",
39
+ "marked-terminal": "^6.2.0",
30
40
  "open": "^9.1.0",
31
41
  "openapi-fetch": "^0.9.1",
32
42
  "openapi-typescript": "^6.7.4",