ai-cmds 0.0.1 → 0.1.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/README.md CHANGED
@@ -1,17 +1,401 @@
1
- # Typed Fetch
1
+ # ai-cmds
2
2
 
3
- [![npm version](https://badge.fury.io/js/%40ls-stack%2Ftyped-fetch.svg)](https://badge.fury.io/js/%40ls-stack%2Ftyped-fetch)
4
-
5
- A cli tool
3
+ AI-powered CLI tool that uses OpenAI and Google Gemini models to review code changes and create PRs with AI-generated descriptions.
6
4
 
7
5
  ## Features
8
6
 
9
- - ...
7
+ - Multiple AI models: GPT-5, GPT-5-mini, GPT-4o-mini, Gemini 2.5 Pro, Gemini 2.0 Flash
8
+ - Configurable review setups from very light to heavy
9
+ - Custom setups with full control over reviewer, validator, and formatter models
10
+ - Three commands: `review-code-changes` for local development, `review-pr` for CI, `create-pr` for PR creation
11
+ - Parallel reviews with validation pass for higher accuracy
12
+ - AI-generated PR titles and descriptions
13
+ - Automatic filtering of import-only changes
14
+ - Custom review instructions support
15
+ - Token usage tracking and cost awareness
10
16
 
11
17
  ## Installation
12
18
 
13
19
  ```bash
14
- npm install @ls-stack/ai-cli
20
+ npm install ai-cmds
15
21
  # or
16
- yarn add @ls-stack/ai-cli
22
+ pnpm add ai-cmds
23
+ ```
24
+
25
+ ## Requirements
26
+
27
+ - Node.js >= 25.0.0
28
+ - `gh` CLI for GitHub PR operations
29
+ - `OPENAI_API_KEY` environment variable (for OpenAI setups)
30
+ - `GOOGLE_GENERATIVE_AI_API_KEY` environment variable (for Google setups)
31
+
32
+ ## Commands
33
+
34
+ ### `review-code-changes` - Local Development
35
+
36
+ Review local code changes (staged or all changes vs base branch). Best for local development workflow.
37
+
38
+ ```bash
39
+ # Review staged changes
40
+ ai-cmds review-code-changes --scope staged
41
+
42
+ # Review all changes against base branch
43
+ ai-cmds review-code-changes --scope all
44
+
45
+ # Use a specific review setup
46
+ ai-cmds review-code-changes --setup light
47
+
48
+ # Specify base branch
49
+ ai-cmds review-code-changes --scope all --base-branch develop
50
+ ```
51
+
52
+ **Arguments:**
53
+ - `--scope` - Review scope: `all`, `staged`, `globs`, `unViewed`, or custom scope id
54
+ - `--setup` - Review setup: `light`, `medium`, `heavy`, or custom setup id
55
+ - `--base-branch` - Base branch for diff comparison (if not specified, prompts for selection)
56
+
57
+ ### `review-pr` - CI/PR Review
58
+
59
+ Review a specific GitHub PR. Designed for CI environments (GitHub Actions) but can also be used locally.
60
+
61
+ ```bash
62
+ # Review PR #123
63
+ ai-cmds review-pr --pr 123
64
+
65
+ # Review PR without posting comment (test mode)
66
+ ai-cmds review-pr --pr 123 --test
67
+
68
+ # Heavy review of a PR
69
+ ai-cmds review-pr --pr 123 --setup heavy
70
+ ```
71
+
72
+ **Arguments:**
73
+ - `--pr` - PR number to review (**required**)
74
+ - `--setup` - Review setup: `light`, `medium`, `heavy`, or custom setup label
75
+ - `--test` - Test mode: skip posting review to PR, just save to file
76
+ - `--skip-previous-check` - Skip checking if previous review issues are still present
77
+
78
+ **Behavior:**
79
+ - In GitHub Actions (`GITHUB_ACTIONS` env set): Posts review as PR comment
80
+ - With `--test` flag or locally: Saves review to `pr-review-test.md`
81
+
82
+ **Previous Review Check:**
83
+
84
+ When running in GitHub Actions mode, the tool automatically checks if there's a previous AI review on the PR. If issues were found in a previous review, it verifies whether those issues are still present in the current code. This helps track if feedback has been addressed without requiring a full re-review.
85
+
86
+ - Only runs in `gh-actions` mode (not in `--test` mode)
87
+ - Looks for previous reviews posted by `github-actions[bot]`
88
+ - Only reports issues that are still present (fixed issues are not mentioned)
89
+ - Runs in parallel with regular reviews for efficiency
90
+ - Use `--skip-previous-check` to disable this feature
91
+
92
+ ### `create-pr` - Create PR with AI Description
93
+
94
+ Create a GitHub PR with an AI-generated title and description based on your changes.
95
+
96
+ ```bash
97
+ # Create PR with AI-generated description
98
+ ai-cmds create-pr
99
+
100
+ # Create PR against a specific base branch
101
+ ai-cmds create-pr --base develop
102
+
103
+ # Skip AI generation, use template only
104
+ ai-cmds create-pr --no-ai
105
+
106
+ # Preview without opening browser
107
+ ai-cmds create-pr --dry-run
108
+
109
+ # Override the PR title
110
+ ai-cmds create-pr --title "Fix login validation"
17
111
  ```
112
+
113
+ **Arguments:**
114
+ - `--base` - Base branch for the PR (if not specified, uses config or prompts)
115
+ - `--no-ai` - Skip AI generation and use template only
116
+ - `--dry-run` - Preview PR content without opening browser
117
+ - `--title` - Override the AI-generated PR title
118
+
119
+ **Behavior:**
120
+ - Checks if a PR already exists for the current branch
121
+ - Automatically pushes the branch if not already pushed
122
+ - Uses PR template from `.github/pull_request_template.md` (configurable)
123
+ - Supports `<!-- AI_DESCRIPTION -->` marker in templates for AI content placement
124
+ - Opens GitHub compare URL with pre-filled title and body
125
+
126
+ ## Review Setups
127
+
128
+ | Setup | Reviewers | Description |
129
+ |-------|-----------|-------------|
130
+ | `veryLight` | 1× GPT-5-mini | Fastest, lowest cost |
131
+ | `light` | 1× GPT-5 | Balanced |
132
+ | `medium` | 2× GPT-5 (high reasoning) | More thorough |
133
+ | `heavy` | 4× GPT-5 (high reasoning) | Most comprehensive |
134
+ | `lightGoogle` | 1× Gemini 2.5 Pro | Google alternative |
135
+ | `mediumGoogle` | 2× Gemini 2.5 Pro | Google thorough |
136
+
137
+ ## Review Scopes
138
+
139
+ | Scope | Description |
140
+ |-------|-------------|
141
+ | `all` | All changes compared to base branch |
142
+ | `staged` | Only staged changes |
143
+ | `globs` | Interactive glob pattern selection (use `!pattern` to exclude) |
144
+ | `unViewed` | Unviewed files in PR (requires open PR for current branch) |
145
+
146
+ ### Using the `globs` Scope
147
+
148
+ The `globs` scope allows you to select files using glob patterns interactively:
149
+
150
+ ```bash
151
+ ai-cmds review-code-changes --scope globs
152
+ # Then enter patterns like: src/**/*.ts !**/*.test.ts
153
+ ```
154
+
155
+ Pattern syntax:
156
+ - `src/**/*.ts` - Include all TypeScript files in src
157
+ - `!**/*.test.ts` - Exclude test files
158
+ - `components` - Simple folder names are expanded to `**/components/**`
159
+
160
+ ### Using the `unViewed` Scope
161
+
162
+ The `unViewed` scope reviews only files you haven't marked as "viewed" in the GitHub PR interface:
163
+
164
+ ```bash
165
+ ai-cmds review-code-changes --scope unViewed
166
+ ```
167
+
168
+ This requires an open PR for the current branch. It uses the GitHub GraphQL API to fetch the viewed state of each file.
169
+
170
+ ## Configuration
171
+
172
+ Create `ai-cli.config.ts` in your project root:
173
+
174
+ ```typescript
175
+ import { defineConfig } from 'ai-cmds';
176
+
177
+ export default defineConfig({
178
+ codeReview: {
179
+ baseBranch: 'main',
180
+ codeReviewDiffExcludePatterns: ['pnpm-lock.yaml', '**/*.svg', '**/*.test.ts'],
181
+ reviewInstructionsPath: '.github/PR_REVIEW_AGENT.md',
182
+ },
183
+ createPR: {
184
+ baseBranch: 'main',
185
+ diffExcludePatterns: ['pnpm-lock.yaml'],
186
+ descriptionInstructions: 'Always mention Jira ticket if present in branch name',
187
+ },
188
+ });
189
+ ```
190
+
191
+ ### Environment Variables
192
+
193
+ The CLI automatically loads environment variables from `.env` files in your project root. You can customize this behavior with the `loadDotEnv` option:
194
+
195
+ ```typescript
196
+ export default defineConfig({
197
+ // Load additional env files (later files override earlier ones)
198
+ loadDotEnv: ['.env.local', '.env.development'],
199
+
200
+ // Or load a single additional file
201
+ loadDotEnv: '.env.local',
202
+
203
+ // Or disable automatic .env loading
204
+ loadDotEnv: false,
205
+ });
206
+ ```
207
+
208
+ By default, `.env` is loaded automatically before the config file is imported, allowing you to reference environment variables in your config.
209
+
210
+ ### Configuration Options
211
+
212
+ #### Root Options
213
+
214
+ | Option | Description |
215
+ |--------|-------------|
216
+ | `loadDotEnv` | Controls `.env` file loading. `true` (default): load `.env`, `false`: skip, `string`: additional file path, `string[]`: multiple files (later override earlier) |
217
+ | `codeReview` | Configuration for the review commands (see below) |
218
+ | `createPR` | Configuration for the create-pr command (see below) |
219
+
220
+ #### `codeReview` Options
221
+
222
+ | Option | Description |
223
+ |--------|-------------|
224
+ | `baseBranch` | Base branch for diff comparison. Can be a string or function `(currentBranch) => string`. If not set, prompts for selection |
225
+ | `codeReviewDiffExcludePatterns` | Glob patterns for files to exclude from review |
226
+ | `reviewInstructionsPath` | Path to custom review instructions markdown file |
227
+ | `setup` | Array of custom named setups (see below) |
228
+ | `scope` | Array of custom named scopes (see below) |
229
+ | `defaultValidator` | Default validator model for custom setups |
230
+ | `defaultFormatter` | Default formatter model for custom setups |
231
+ | `logsDir` | Directory for logs (can also use `AI_CLI_LOGS_DIR` env var) |
232
+
233
+ #### `createPR` Options
234
+
235
+ | Option | Description |
236
+ |--------|-------------|
237
+ | `templatePath` | Path to PR template file (default: `.github/pull_request_template.md`) |
238
+ | `baseBranch` | Base branch for the PR. Can be a string or function `(currentBranch) => string` |
239
+ | `preferredProvider` | Preferred AI provider: `'openai'` or `'google'` (auto-detects if not set) |
240
+ | `descriptionInstructions` | Custom instructions for AI description generation |
241
+ | `diffExcludePatterns` | Glob patterns for files to exclude from diff |
242
+ | `maxDiffTokens` | Maximum tokens from diff to include in AI prompt (default: 50000) |
243
+
244
+ ### Dynamic Base Branch
245
+
246
+ The `baseBranch` option can be a function that receives the current branch name:
247
+
248
+ ```typescript
249
+ export default defineConfig({
250
+ codeReview: {
251
+ baseBranch: (currentBranch) =>
252
+ currentBranch.startsWith('release/') ? 'main' : 'develop',
253
+ },
254
+ });
255
+ ```
256
+
257
+ ### Custom Setups
258
+
259
+ Define custom named setups with full control over which models are used. **When custom setups are configured, they replace built-in options** (veryLight, light, medium, heavy).
260
+
261
+ ```typescript
262
+ import { defineConfig } from 'ai-cmds';
263
+ import { openai } from '@ai-sdk/openai';
264
+ import { google } from '@ai-sdk/google';
265
+
266
+ export default defineConfig({
267
+ codeReview: {
268
+ setup: [
269
+ {
270
+ label: 'myCustomSetup',
271
+ reviewers: [
272
+ { label: 'GPT-5', model: openai('gpt-5.2'), providerOptions: { reasoningEffort: 'high' } },
273
+ { model: google('gemini-2.5-pro') },
274
+ ],
275
+ validator: { model: openai('gpt-5.2') },
276
+ formatter: { model: openai('gpt-5-mini') },
277
+ },
278
+ {
279
+ label: 'fastReview',
280
+ reviewers: [{ model: openai('gpt-5-mini') }],
281
+ // validator and formatter use defaults
282
+ },
283
+ ],
284
+
285
+ // Defaults for custom setups that don't specify validator/formatter
286
+ defaultValidator: { model: openai('gpt-5.2'), providerOptions: { reasoningEffort: 'high' } },
287
+ defaultFormatter: { model: openai('gpt-5-mini') },
288
+ },
289
+ });
290
+ ```
291
+
292
+ To include built-in options alongside your custom setups, use `BUILT_IN_SETUP_OPTIONS`:
293
+
294
+ ```typescript
295
+ import { defineConfig, BUILT_IN_SETUP_OPTIONS } from 'ai-cmds';
296
+
297
+ export default defineConfig({
298
+ codeReview: {
299
+ setup: [
300
+ ...BUILT_IN_SETUP_OPTIONS, // includes light, medium, heavy
301
+ { id: 'myCustomSetup', label: 'My Custom Setup', reviewers: [...] },
302
+ ],
303
+ },
304
+ });
305
+ ```
306
+
307
+ Use custom setups via CLI:
308
+
309
+ ```bash
310
+ ai-cmds review-code-changes --setup myCustomSetup
311
+ ai-cmds review-pr --pr 123 --setup myCustomSetup
312
+ ```
313
+
314
+ ### Custom Scopes
315
+
316
+ Define custom scopes to control which files are included in the review. **When custom scopes are configured, they replace built-in options** (all, staged).
317
+
318
+ ```typescript
319
+ import { defineConfig } from 'ai-cmds';
320
+
321
+ export default defineConfig({
322
+ codeReview: {
323
+ scope: [
324
+ {
325
+ id: 'src-only',
326
+ label: 'Source files only',
327
+ getFiles: (ctx) => ctx.allFiles.filter((f) => f.startsWith('src/')),
328
+ },
329
+ {
330
+ id: 'no-tests',
331
+ label: 'Exclude tests',
332
+ getFiles: (ctx) => ctx.allFiles.filter((f) => !f.includes('.test.')),
333
+ },
334
+ ],
335
+ },
336
+ });
337
+ ```
338
+
339
+ The `getFiles` function receives a context object with:
340
+ - `stagedFiles`: Files currently staged for commit
341
+ - `allFiles`: All files changed compared to base branch
342
+
343
+ To include built-in options alongside your custom scopes, use `BUILT_IN_SCOPE_OPTIONS`:
344
+
345
+ ```typescript
346
+ import { defineConfig, BUILT_IN_SCOPE_OPTIONS } from 'ai-cmds';
347
+
348
+ export default defineConfig({
349
+ codeReview: {
350
+ scope: [
351
+ ...BUILT_IN_SCOPE_OPTIONS, // includes all, staged, globs, unViewed
352
+ { id: 'src-only', label: 'Source files only', getFiles: (ctx) => ctx.allFiles.filter((f) => f.startsWith('src/')) },
353
+ ],
354
+ },
355
+ });
356
+ ```
357
+
358
+ Use custom scopes via CLI:
359
+
360
+ ```bash
361
+ ai-cmds review-code-changes --scope src-only
362
+ ```
363
+
364
+ ## GitHub Actions Integration
365
+
366
+ Example workflow for running PR reviews in CI:
367
+
368
+ ```yaml
369
+ name: AI Code Review
370
+
371
+ on:
372
+ pull_request:
373
+ types: [opened, synchronize]
374
+
375
+ jobs:
376
+ review:
377
+ runs-on: ubuntu-latest
378
+ steps:
379
+ - uses: actions/checkout@v4
380
+ with:
381
+ fetch-depth: 0
382
+
383
+ - uses: pnpm/action-setup@v4
384
+
385
+ - uses: actions/setup-node@v4
386
+ with:
387
+ node-version: '25'
388
+ cache: 'pnpm'
389
+
390
+ - run: pnpm install
391
+
392
+ - name: Run AI Review
393
+ run: pnpm ai-cmds review-pr --pr ${{ github.event.pull_request.number }}
394
+ env:
395
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
396
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
397
+ ```
398
+
399
+ ## License
400
+
401
+ MIT