scai 0.1.93 → 0.1.95

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
@@ -3,9 +3,9 @@
3
3
  > AI-powered CLI tool for commit messages **and** pull request reviews — using local models.
4
4
 
5
5
  **scai** is your AI pair‑programmer in the terminal. Focus on coding while scai:
6
-
7
- - 🤖 **Reviews open pull requests** and provides AI‑driven feedback (BETA)
6
+
8
7
  - 💬 **Suggests intelligent Git commit messages** based on your staged diff
8
+ - 🤖 **Reviews open pull requests** and provides AI‑driven feedback (BETA)
9
9
  - 📝 Summarizes files in plain English
10
10
  - 📜 Auto‑updates your changelog
11
11
  - 🔍 (ALPHA) Search & ask questions across your codebase
@@ -233,26 +233,32 @@ scai gen tests <file>
233
233
 
234
234
  * `summ`: Summarize a file
235
235
 
236
+ You can also pipe file content directly:
237
+
238
+ ```bash
239
+ cat src/utils/math.ts | scai gen summ
240
+ ```
241
+
242
+ </br>
243
+
236
244
  * `comm`: Add comments to one or more files, or to all matching files in a folder (recursive).
237
- **Example:**
245
+
246
+ </br>
238
247
 
239
248
  ```bash
240
249
  scai gen comm src/ utils/helpers.ts
241
250
  ```
242
251
 
252
+ </br>
253
+
243
254
  This will add comments to all `.ts` and `.js` files under `src/` and to `utils/helpers.ts`.
244
255
 
256
+ </br>
257
+
245
258
  * `changelog`: Update or create `CHANGELOG.md` from Git diff
246
259
 
247
260
  * `tests`: Create Jest test stubs (ALPHA)
248
261
 
249
- You can also pipe file content directly:
250
-
251
- ```bash
252
- cat src/utils/math.ts | scai gen summ
253
- ```
254
-
255
-
256
262
  ---
257
263
 
258
264
  ## ⚙️ Configuration
@@ -275,22 +281,12 @@ scai stores settings in `~/.scai/config.json`. You can override or view them:
275
281
  scai config
276
282
  ```
277
283
 
278
- <br>
279
-
280
- ## 🔁 Background Daemon and Indexing ⚠️ ALPHA Notice
281
-
282
- These features are experimental and subject to change:
283
-
284
- * `index`, `find`, `ask`
285
- * `daemon`, `stop-daemon`
286
- * `gen tests` (test generation)
287
-
288
- <br>
284
+ ---
289
285
 
290
286
  ## Commands
291
287
 
292
288
  ### `index`
293
- The `index` command is used to manage and perform operations on the indexed files and repositories.
289
+ The `index` command is used to manage and perform operations on the indexed files and repositories. It allows you to control which repository you're working with and have indexed.
294
290
 
295
291
  #### `scai index start`
296
292
 
@@ -300,6 +296,12 @@ Index supported files in the configured index directory.
300
296
  scai index set <dir>
301
297
  ```
302
298
 
299
+ Or just this for cwd (current working dir)
300
+
301
+ ```bash
302
+ scai index set
303
+ ```
304
+
303
305
  Set and activate the index directory.
304
306
  ```bash
305
307
  scai index list
@@ -323,6 +325,104 @@ scai index delete
323
325
 
324
326
  ---
325
327
 
328
+ ## 🛍️ Maintenance & Utilities
329
+ # Database Commands
330
+
331
+ Your CLI now supports a set of **database management commands** under the `db` namespace. These commands allow you to check the status of the database, reset it, or run migrations.
332
+
333
+ ---
334
+
335
+ ### 📋 Available Commands
336
+
337
+ #### 🔍 Check Database
338
+
339
+ ```bash
340
+ scai db check
341
+ ```
342
+
343
+ Runs the **dbcheck** script to verify the database status.
344
+
345
+ * Useful for quickly checking if the database is healthy.
346
+ * Prints detailed output directly in the console.
347
+
348
+ ---
349
+
350
+ #### ♻️ Reset Database
351
+
352
+ ```bash
353
+ scai db reset
354
+ ```
355
+
356
+ Deletes and resets the SQLite database.
357
+
358
+ * Will ask for confirmation before proceeding.
359
+ * Respond with `y` or `Y` to confirm.
360
+ * Any other key (including `n`, `N`, or just pressing **Enter**) will cancel the reset.
361
+
362
+ ---
363
+
364
+ #### 📦 Run Migrations
365
+
366
+ ```bash
367
+ scai db migrate
368
+ ```
369
+
370
+ Executes all database migration scripts.
371
+
372
+ Note the **Migrate** command is for **internal use only**. Do **not** run it unless explicitly instructed, as it may delete existing data or corrupt your local database.
373
+
374
+ If you're upgrading from an earlier version, please run the following commands to avoid indexing issues:
375
+
376
+ ```bash
377
+ scai db reset
378
+ scai index
379
+ ```
380
+ </br>
381
+
382
+ ---
383
+
384
+ ### ✅ Example Workflow
385
+
386
+ 1. **Check** current database state:
387
+
388
+ ```bash
389
+ scai db check
390
+ ```
391
+
392
+ 2. Confirm you're in the correct repo.
393
+
394
+ ```bash
395
+ scai index list
396
+ ```
397
+
398
+ Use the switch command to switch if necessary.
399
+
400
+ ```bash
401
+ scai index switch
402
+ ```
403
+
404
+ 2. If necessary, **reset** the database:
405
+
406
+ ```bash
407
+ scai db reset
408
+ ```
409
+
410
+ → Confirm with `y` when prompted.
411
+
412
+ </br>
413
+
414
+ ---
415
+
416
+ ## 🔁 Background Daemon and Indexing ⚠️ ALPHA Notice
417
+
418
+ These features are experimental and subject to change:
419
+
420
+ * `find`, `ask`
421
+ * `daemon`, `stop-daemon`
422
+ * `gen tests` (test generation)
423
+
424
+ <br>
425
+
326
426
  > **Note:** Indexing very large repositories (millions of lines) may take **hours or days**. Please be patient, and only index huge codebases if you are ok with some extra processing taking place on your computer.
327
427
 
328
428
  The `scai index` command **automatically** starts a background daemon that continuously:
@@ -335,8 +435,6 @@ You won't gain much value from the index unless you scope it to one repository.
335
435
 
336
436
  ---
337
437
 
338
- ### 🔍 Codebase Search & Ask (ALPHA)
339
-
340
438
  > **Important:** You must `index` a **code repository** first or `find` and `ask` have no context to work with.
341
439
 
342
440
  1. **Set index directory:**
@@ -400,40 +498,16 @@ You can run it in two ways:
400
498
 
401
499
  ---
402
500
 
403
- Note the **Migrate** command is for **internal use only**. Do **not** run it unless explicitly instructed, as it may delete existing data or corrupt your local database.
404
-
405
- If you're upgrading from an earlier version, please run the following commands to avoid indexing issues:
501
+ ### Backup only of `~/.scai`:**
406
502
 
407
- ```bash
408
- scai reset-db
409
- scai index
410
- ```
411
- </br>
412
-
413
- ---
414
-
415
- ## 🛍️ Maintenance & Utilities
416
-
417
- * **Reset database (w/ backup):**
418
-
419
- ```bash
420
- scai reset-db
421
- ```
422
- * **Backup only of `~/.scai`:**
503
+ Creates a backup of the .scai folder in the user root dir.
423
504
 
424
505
  ```bash
425
506
  scai backup
426
507
  ```
427
508
 
428
- ---
429
-
430
- ## 🧺 Module Pipeline Mode
431
-
432
- For custom pipelines on a single file:
433
-
434
- ```bash
435
- scai src/file.ts -m summary,comments
436
- ```
509
+ Results in this:
510
+ ~/.scai_backup_2025-08-12T06-58-00-227Z/
437
511
  ---
438
512
 
439
513
  ## 🔐 License & Fair Use
package/dist/CHANGELOG.md CHANGED
@@ -125,4 +125,10 @@ Type handling with the module pipeline
125
125
 
126
126
  ## 2025-08-19
127
127
 
128
- • Update `gen` command's `comm` subcommand to allow targeting files or folders
128
+ • Update `gen` command's `comm` subcommand to allow targeting files or folders
129
+
130
+ ## 2025-08-20
131
+
132
+ • Add DB-related commands to db subcommand (check, reset, migrate)
133
+ • Update table view limits for files and functions in dbcheck.ts
134
+ • Improved resetDatabase command with confirmation prompt before deleting database
@@ -1,12 +1,28 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import lockfile from 'proper-lockfile';
4
+ import readline from 'readline';
4
5
  import { backupScaiFolder } from '../db/backup.js';
5
6
  import { getDbPathForRepo, getDbForRepo } from '../db/client.js';
6
7
  export async function resetDatabase() {
8
+ const dbPath = getDbPathForRepo();
9
+ console.log(`⚠️ You are about to delete the database at: ${dbPath}`);
10
+ const rl = readline.createInterface({
11
+ input: process.stdin,
12
+ output: process.stdout,
13
+ });
14
+ const confirm = await new Promise((resolve) => {
15
+ rl.question('Are you sure you want to proceed? (y/N): ', (answer) => {
16
+ rl.close();
17
+ resolve(answer.trim().toLowerCase() === 'y');
18
+ });
19
+ });
20
+ if (!confirm) {
21
+ console.log('❌ Reset aborted. Database was not deleted.');
22
+ return;
23
+ }
7
24
  console.log('🔁 Backing up existing .scai folder...');
8
25
  await backupScaiFolder();
9
- const dbPath = getDbPathForRepo();
10
26
  // Close the DB connection
11
27
  try {
12
28
  const db = getDbForRepo();
package/dist/index.js CHANGED
@@ -188,14 +188,13 @@ index
188
188
  .action(() => {
189
189
  runInteractiveDelete();
190
190
  });
191
- // This will help resolve the current directory in an ES Module
192
- cmd
193
- .command('check-db')
191
+ const db = cmd.command('db').description('Database operations');
192
+ db
193
+ .command('check')
194
194
  .description('Run the dbcheck script to check the database status')
195
195
  .action(() => {
196
196
  const __filename = fileURLToPath(import.meta.url);
197
197
  const __dirname = dirname(__filename);
198
- // Go up two levels from dist/commands → dist → then into dist/scripts/dbcheck.js
199
198
  const scriptPath = resolve(__dirname, '..', 'dist/scripts', 'dbcheck.js');
200
199
  console.log(`🚀 Running database check script: ${scriptPath}`);
201
200
  try {
@@ -205,6 +204,14 @@ cmd
205
204
  console.error('❌ Error running dbcheck script:', err instanceof Error ? err.message : err);
206
205
  }
207
206
  });
207
+ db
208
+ .command('reset')
209
+ .description('Delete and reset the SQLite database')
210
+ .action(() => resetDatabase());
211
+ db
212
+ .command('migrate')
213
+ .description('Run DB migration scripts')
214
+ .action(runMigrateCommand);
208
215
  cmd
209
216
  .command('backup')
210
217
  .description('Backup the current .scai folder')
@@ -230,10 +237,6 @@ cmd
230
237
  .command('stop-daemon')
231
238
  .description('Stop the background summarizer daemon')
232
239
  .action(runStopDaemonCommand);
233
- cmd
234
- .command('migrate')
235
- .description('Run DB migration scripts')
236
- .action(runMigrateCommand);
237
240
  cmd
238
241
  .command('inspect')
239
242
  .argument('<filepath>', 'Path to the file to inspect')
@@ -241,10 +244,6 @@ cmd
241
244
  .action(async (filepath) => {
242
245
  await runInspectCommand(filepath);
243
246
  });
244
- cmd
245
- .command('reset-db')
246
- .description('Delete and reset the SQLite database')
247
- .action(() => resetDatabase());
248
247
  cmd
249
248
  .command('pipe')
250
249
  .description('Run a module pipeline on a given file')
@@ -50,7 +50,7 @@ const summaries = db.prepare(`
50
50
  SELECT id, substr(summary, 1, 50) || '...' AS short_summary
51
51
  FROM files
52
52
  WHERE summary IS NOT NULL AND summary != ''
53
- LIMIT 10
53
+ LIMIT 5
54
54
  `).all();
55
55
  summaries.forEach(row => {
56
56
  console.log(`${row.id.toString().padEnd(4)} ${row.short_summary}`);
@@ -60,7 +60,7 @@ const embeddings = db.prepare(`
60
60
  SELECT id, substr(embedding, 1, 50) || '...' AS short_embedding
61
61
  FROM files
62
62
  WHERE embedding IS NOT NULL AND embedding != ''
63
- LIMIT 10
63
+ LIMIT 5
64
64
  `).all();
65
65
  embeddings.forEach(row => {
66
66
  console.log(`${row.id.toString().padEnd(4)} ${row.short_embedding}`);
@@ -181,14 +181,14 @@ catch (err) {
181
181
  console.error('❌ Error accessing function_calls table:', err.message);
182
182
  }
183
183
  // === Random Summary Samples ===
184
- console.log('\n🧾 10 Random Summaries (ID + Preview):');
184
+ console.log('\n🧾 Random Summaries (ID + Preview):');
185
185
  console.log('-------------------------------------------');
186
186
  const randomSummaries = db.prepare(`
187
187
  SELECT id, filename, substr(summary, 1, 1000) || '...' AS preview
188
188
  FROM files
189
189
  WHERE summary IS NOT NULL AND summary != ''
190
190
  ORDER BY RANDOM()
191
- LIMIT 10
191
+ LIMIT 5
192
192
  `).all();
193
193
  randomSummaries.forEach(row => {
194
194
  console.log(`📄 [${row.id}] ${row.filename}: ${row.preview}`);
@@ -200,27 +200,27 @@ const randomFunctions = db.prepare(`
200
200
  SELECT id, name, file_id, substr(content, 1, 100) || '...' AS preview
201
201
  FROM functions
202
202
  ORDER BY RANDOM()
203
- LIMIT 20
203
+ LIMIT 5
204
204
  `).all();
205
205
  randomFunctions.forEach(row => {
206
206
  console.log(`🔹 [${row.id}] ${row.name} (file_id: ${row.file_id})`);
207
207
  console.log(` ${row.preview}\n`);
208
208
  });
209
- // === Column View of 100 Files ===
210
- console.log('\n📊 Table View: First 500 Files');
209
+ // === Column View of Files ===
210
+ console.log('\n📊 Table View: Files');
211
211
  console.log('-------------------------------------------');
212
212
  const fileRows = db.prepare(`
213
213
  SELECT id, filename, type, processing_status, functions_extracted_at, length(summary) AS summary_len
214
214
  FROM files
215
- LIMIT 500
215
+ LIMIT 50
216
216
  `).all();
217
217
  console.table(fileRows);
218
- // === Column View of 100 Functions ===
219
- console.log('\n📊 Table View: First 500 Functions');
218
+ // === Column View of Functions ===
219
+ console.log('\n📊 Table View: Functions');
220
220
  console.log('-------------------------------------------');
221
221
  const functionRows = db.prepare(`
222
222
  SELECT id, file_id, name, start_line, end_line, length(content) AS length
223
223
  FROM functions
224
- LIMIT 500
224
+ LIMIT 50
225
225
  `).all();
226
226
  console.table(functionRows);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scai",
3
- "version": "0.1.93",
3
+ "version": "0.1.95",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "scai": "./dist/index.js"