kob-cli 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.
package/AGENTS.md ADDED
@@ -0,0 +1,351 @@
1
+ # AGENTS.md - KOB CLI Agent Specification
2
+
3
+ ## Overview
4
+
5
+ This document provides comprehensive specifications for AI agents working on the KOB CLI project. It covers architecture, development guidelines, and best practices.
6
+
7
+ ## Architecture
8
+
9
+ ### High-Level Design
10
+
11
+ ```
12
+ ┌─────────────────────────────────────────────┐
13
+ │ CLI Entry Point │
14
+ │ (src/index.ts) │
15
+ └──────────────┬──────────────────────────────┘
16
+
17
+ │ Commander.js
18
+
19
+ ┌─────────────────────────────────────────────┐
20
+ │ Command Layer │
21
+ │ (src/commands/*.ts) │
22
+ │ - auth.ts, chat.ts, stream.ts │
23
+ │ - models.ts, projects.ts, rules.ts │
24
+ │ - credits.ts │
25
+ └──────────────┬──────────────────────────────┘
26
+
27
+ │ Business Logic
28
+
29
+ ┌─────────────────────────────────────────────┐
30
+ │ Utility Layer │
31
+ │ (src/utils/*.ts) │
32
+ │ - api.ts (HTTP Client) │
33
+ │ - config.ts (Configuration) │
34
+ │ - format.ts (Output Formatting) │
35
+ │ - errors.ts (Error Handling) │
36
+ └──────────────┬──────────────────────────────┘
37
+
38
+ │ Fetch API
39
+
40
+ ┌─────────────────────────────────────────────┐
41
+ │ KOB AI API Server │
42
+ │ https://www.kob-ai.dev/api/* │
43
+ └─────────────────────────────────────────────┘
44
+ ```
45
+
46
+ ### Module Responsibilities
47
+
48
+ #### 1. Entry Point (`src/index.ts`)
49
+ - Initialize Commander.js program
50
+ - Register all commands
51
+ - Display help text
52
+ - Parse command-line arguments
53
+
54
+ #### 2. Command Layer (`src/commands/`)
55
+
56
+ **auth.ts**
57
+ - `auth:verify` - Verify API credentials
58
+ - `balance` - Check credit balance
59
+
60
+ **chat.ts**
61
+ - `chat` - Single message to AI
62
+ - `chat:interactive` - REPL mode for conversation
63
+
64
+ **stream.ts**
65
+ - `stream` - Real-time streaming AI responses
66
+
67
+ **models.ts**
68
+ - `models` - List available AI models
69
+
70
+ **projects.ts**
71
+ - `projects:list` - List all projects
72
+ - `projects:create` - Create new project
73
+ - `projects:update` - Update existing project
74
+ - `projects:delete` - Delete project
75
+
76
+ **rules.ts**
77
+ - `rules:list` - List project rules
78
+ - `rules:create` - Create new rule
79
+ - `rules:update` - Update existing rule
80
+ - `rules:delete` - Delete rule
81
+
82
+ **credits.ts**
83
+ - `credits:history` - View credit top-up history
84
+
85
+ #### 3. Utility Layer (`src/utils/`)
86
+
87
+ **api.ts**
88
+ - `KobApiClient` class
89
+ - HTTP methods: GET, POST, PATCH, DELETE
90
+ - Streaming support with async generators
91
+ - Automatic authentication injection
92
+ - Error handling
93
+
94
+ **config.ts**
95
+ - `getConfig()` - Load environment variables
96
+ - `validateConfig()` - Validate configuration
97
+ - Fallback to default values
98
+
99
+ **format.ts**
100
+ - `formatDate()` - Format timestamps
101
+ - `formatProjects()` - Format project list
102
+ - `formatRules()` - Format rules list
103
+ - `formatCreditHistory()` - Format credit history
104
+ - `formatUsage()` - Format usage statistics
105
+
106
+ **errors.ts**
107
+ - `ApiError` class - Custom error type
108
+ - `handleApiError()` - User-friendly error messages
109
+ - `validateRequired()` - Input validation
110
+
111
+ #### 4. Type Definitions (`src/types/index.ts`)
112
+ - All TypeScript interfaces
113
+ - API response types
114
+ - Request/Response schemas
115
+
116
+ ## Development Guidelines
117
+
118
+ ### Adding New Commands
119
+
120
+ 1. **Create Command File**
121
+ ```typescript
122
+ // src/commands/mycommand.ts
123
+ import { Command } from 'commander';
124
+ import { KobApiClient } from '../utils/api.js';
125
+ import { getConfig } from '../utils/config.js';
126
+
127
+ export const myCommand = new Command('mycommand')
128
+ .description('My new command')
129
+ .action(async () => {
130
+ // Implementation
131
+ });
132
+ ```
133
+
134
+ 2. **Register in Entry Point**
135
+ ```typescript
136
+ // src/index.ts
137
+ import { myCommand } from './commands/mycommand.js';
138
+ program.addCommand(myCommand);
139
+ ```
140
+
141
+ ### API Client Usage
142
+
143
+ ```typescript
144
+ const config = getConfig();
145
+ const client = new KobApiClient(config);
146
+
147
+ // POST request
148
+ const data = await client.post<ResponseType>('/api/endpoint', {
149
+ key: 'value'
150
+ });
151
+
152
+ // GET request
153
+ const data = await client.get<ResponseType>('/api/endpoint', {
154
+ param: 'value'
155
+ });
156
+
157
+ // Streaming
158
+ for await (const event of client.stream('/api/stream', body)) {
159
+ if (event.type === 'chunk') {
160
+ // Handle chunk
161
+ }
162
+ }
163
+ ```
164
+
165
+ ### Error Handling Pattern
166
+
167
+ ```typescript
168
+ try {
169
+ const spinner = ora('Loading...').start();
170
+
171
+ // API call
172
+ const data = await client.post('/api/endpoint', body);
173
+
174
+ spinner.succeed('Success!');
175
+ console.log(data);
176
+ } catch (error) {
177
+ spinner.fail('Failed');
178
+ handleApiError(error);
179
+ }
180
+ ```
181
+
182
+ ### Type Safety
183
+
184
+ Always use TypeScript types:
185
+ ```typescript
186
+ import type { ChatResponse } from '../types/index.js';
187
+
188
+ const data = await client.post<ChatResponse>('/api/ai/chat', body);
189
+ // data is properly typed
190
+ ```
191
+
192
+ ## Testing Strategy
193
+
194
+ ### Manual Testing Checklist
195
+
196
+ 1. **Authentication**
197
+ - [ ] `auth:verify` with valid credentials
198
+ - [ ] `auth:verify` with invalid credentials
199
+ - [ ] `balance` command
200
+
201
+ 2. **Chat**
202
+ - [ ] `chat` with different providers
203
+ - [ ] `chat:interactive` mode
204
+ - [ ] Chat with project rules
205
+
206
+ 3. **Streaming**
207
+ - [ ] `stream` with different models
208
+ - [ ] Stream error handling
209
+
210
+ 4. **Models**
211
+ - [ ] `models` list all
212
+ - [ ] `models --provider` filter
213
+ - [ ] `models --format json`
214
+
215
+ 5. **Projects**
216
+ - [ ] Create, list, update, delete
217
+
218
+ 6. **Rules**
219
+ - [ ] Create, list, update, delete
220
+ - [ ] Different rule types
221
+
222
+ 7. **Credits**
223
+ - [ ] `credits:history` with pagination
224
+
225
+ ### Common Test Scenarios
226
+
227
+ ```bash
228
+ # Test authentication
229
+ bun dev auth:verify
230
+
231
+ # Test chat
232
+ bun dev chat "Hello" --provider DeepSeek --model deepseek-chat
233
+
234
+ # Test streaming
235
+ bun dev stream "Tell me a story" --model deepseek-chat
236
+
237
+ # Test projects
238
+ bun dev projects:create "Test Project"
239
+ bun dev projects:list
240
+ ```
241
+
242
+ ## Best Practices
243
+
244
+ ### Code Style
245
+
246
+ 1. **Use async/await** - Not promises or callbacks
247
+ 2. **Type everything** - No `any` types unless necessary
248
+ 3. **Error handling** - Always use try/catch with handleApiError
249
+ 4. **User feedback** - Use ora spinners for loading states
250
+ 5. **Output formatting** - Use chalk for colors, format functions for consistency
251
+
252
+ ### Performance
253
+
254
+ 1. **Lazy loading** - Import only what's needed
255
+ 2. **Connection reuse** - Single API client instance per command
256
+ 3. **Streaming** - Use for long responses to improve UX
257
+
258
+ ### Security
259
+
260
+ 1. **Environment variables** - Never hardcode credentials
261
+ 2. **Validation** - Validate all user inputs
262
+ 3. **Error messages** - Don't expose sensitive info in errors
263
+
264
+ ## Common Issues & Solutions
265
+
266
+ ### Issue: Type import errors
267
+ **Solution:** Use `import type` for types
268
+ ```typescript
269
+ import type { ChatResponse } from '../types/index.js';
270
+ ```
271
+
272
+ ### Issue: Undefined content in streams
273
+ **Solution:** Check for undefined before using
274
+ ```typescript
275
+ if (event.content) {
276
+ process.stdout.write(event.content);
277
+ }
278
+ ```
279
+
280
+ ### Issue: Missing environment variables
281
+ **Solution:** Check .env file or export variables
282
+ ```bash
283
+ export KOB_API_KEY=xxx
284
+ export KOB_API_KEY=xxx
285
+ ```
286
+
287
+ ## Future Enhancements
288
+
289
+ ### Potential Features
290
+
291
+ 1. **Conversation Export**
292
+ - Export chat history to file
293
+ - Multiple formats (JSON, Markdown, TXT)
294
+
295
+ 2. **Batch Operations**
296
+ - Process multiple messages from file
297
+ - Bulk project/rule management
298
+
299
+ 3. **Configuration File**
300
+ - Save default provider/model preferences
301
+ - Multiple profile support
302
+
303
+ 4. **Plugin System**
304
+ - Custom command plugins
305
+ - Third-party integrations
306
+
307
+ 5. **Advanced Formatting**
308
+ - Markdown rendering in terminal
309
+ - Syntax highlighting for code
310
+
311
+ 6. **Caching**
312
+ - Cache model list
313
+ - Cache frequently accessed data
314
+
315
+ ## Dependencies
316
+
317
+ ### Production
318
+ - `commander` - CLI framework
319
+ - `chalk` - Terminal styling
320
+ - `ora` - Loading spinners
321
+
322
+ ### Development
323
+ - `@types/bun` - Bun type definitions
324
+ - `typescript` - TypeScript compiler
325
+
326
+ ## Build & Deployment
327
+
328
+ ### Development
329
+ ```bash
330
+ bun dev <command>
331
+ ```
332
+
333
+ ### Production Build
334
+ ```bash
335
+ bun run build
336
+ # Creates kob-cli.exe
337
+ ```
338
+
339
+ ### Global Installation
340
+ ```bash
341
+ bun install -g .
342
+ # or
343
+ bun link
344
+ ```
345
+
346
+ ## Reference
347
+
348
+ - **API Documentation**: See `/my-app/docs/` directory
349
+ - **Type Definitions**: `src/types/index.ts`
350
+ - **API Client**: `src/utils/api.ts`
351
+ - **Commands**: `src/commands/*.ts`
package/INSTALL.md ADDED
@@ -0,0 +1,84 @@
1
+ # 🎯 Installation Guide
2
+
3
+ ## ติดตั้ง KOB CLI เพื่อใช้คำสั่ง `kob`
4
+
5
+ ### ขั้นตอนที่ 1: ติดตั้ง Dependencies
6
+
7
+ ```bash
8
+ cd kob-cli
9
+ bun install
10
+ ```
11
+
12
+ ### ขั้นตอนที่ 2: ลงทะเบียนคำสั่ง `kob`
13
+
14
+ ```bash
15
+ bun link
16
+ ```
17
+
18
+ คำสั่งนี้จะสร้าง symlink ให้คุณสามารถใช้ `kob` ได้จากทุกที่!
19
+
20
+ ### ขั้นตอนที่ 3: ตั้งค่า API Credentials
21
+
22
+ สร้างไฟล์ `.env` ในโฟลเดอร์ `kob-cli`:
23
+
24
+ ```env
25
+ KOB_API_BASE_URL=https://www.kob-ai.dev
26
+ KOB_API_KEY=kob_YOUR_API_KEY
27
+ ```
28
+
29
+ **วิธีรับ API Key:**
30
+ 1. เข้า https://www.kob-ai.dev
31
+ 2. ไปที่ "Token Keys"
32
+ 3. สร้าง Key ใหม่
33
+ 4. คัดลอก `api_key` มาใส่ใน `.env`
34
+
35
+ ### ขั้นตอนที่ 4: ทดสอบ
36
+
37
+ ```bash
38
+ kob --version
39
+ # ควรแสดง: 1.0.0
40
+
41
+ kob auth:verify
42
+ # ควรแสดงข้อมูลผู้ใช้ของคุณ
43
+ ```
44
+
45
+ ## ✅ พร้อมใช้งาน!
46
+
47
+ ตอนนี้คุณสามารถใช้คำสั่ง `kob` แทน `bun run src/index.ts` ได้แล้ว
48
+
49
+ **ตัวอย่าง:**
50
+ ```bash
51
+ # แทนที่จะพิมพ์:
52
+ bun run src/index.ts chat "Hello"
53
+
54
+ # พิมพ์แค่:
55
+ kob chat "Hello"
56
+ ```
57
+
58
+ ## 📝 หมายเหตุ
59
+
60
+ - คำสั่ง `bun link` ต้องรันเพียงครั้งเดียว
61
+ - หากอัปเดตโค้ด ไม่ต้อง link ใหม่
62
+ - หากต้องการลบการ link: `bun unlink kob-cli`
63
+
64
+ ## ❓ ปัญหาที่พบบ่อย
65
+
66
+ ### "kob: command not found"
67
+
68
+ **วิธีแก้:**
69
+ ```bash
70
+ cd kob-cli
71
+ bun link
72
+ ```
73
+
74
+ ### Permission denied (Linux/Mac)
75
+
76
+ ```bash
77
+ chmod +x src/index.ts
78
+ ```
79
+
80
+ ### Windows PowerShell Execution Policy
81
+
82
+ ```powershell
83
+ Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
84
+ ```
package/LICENSE ADDED
@@ -0,0 +1,34 @@
1
+ KOB AI CLI - Non-Commercial Open Source License
2
+
3
+ Copyright (c) 2025 KOB AI Project Owner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, subject to the following conditions:
10
+
11
+ 1. **Non-Commercial Use Only**
12
+ The Software may only be used for non-commercial purposes. Commercial use,
13
+ including but not limited to using the Software as part of a commercial
14
+ product or service, selling the Software, or using the Software for
15
+ commercial gain, is strictly prohibited without prior written permission
16
+ from the copyright holder.
17
+
18
+ 2. **Attribution**
19
+ Any use of the Software must retain the above copyright notice, this list
20
+ of conditions, and the following disclaimer.
21
+
22
+ 3. **Open Contribution**
23
+ Contributions to the Software are welcome and encouraged. By contributing,
24
+ you agree that your contributions will be licensed under the same terms.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
33
+
34
+ For commercial licensing inquiries, please contact the project owner.