scai 0.1.93 → 0.1.94
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 +110 -43
- package/dist/CHANGELOG.md +7 -1
- package/dist/commands/ResetDbCmd.js +17 -1
- package/dist/index.js +11 -12
- package/dist/scripts/dbcheck.js +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -252,7 +252,6 @@ You can also pipe file content directly:
|
|
|
252
252
|
cat src/utils/math.ts | scai gen summ
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
-
|
|
256
255
|
---
|
|
257
256
|
|
|
258
257
|
## ⚙️ Configuration
|
|
@@ -275,22 +274,12 @@ scai stores settings in `~/.scai/config.json`. You can override or view them:
|
|
|
275
274
|
scai config
|
|
276
275
|
```
|
|
277
276
|
|
|
278
|
-
|
|
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>
|
|
277
|
+
---
|
|
289
278
|
|
|
290
279
|
## Commands
|
|
291
280
|
|
|
292
281
|
### `index`
|
|
293
|
-
The `index` command is used to manage and perform operations on the indexed files and repositories.
|
|
282
|
+
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
283
|
|
|
295
284
|
#### `scai index start`
|
|
296
285
|
|
|
@@ -300,6 +289,12 @@ Index supported files in the configured index directory.
|
|
|
300
289
|
scai index set <dir>
|
|
301
290
|
```
|
|
302
291
|
|
|
292
|
+
Or just this for cwd (current working dir)
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
scai index set
|
|
296
|
+
```
|
|
297
|
+
|
|
303
298
|
Set and activate the index directory.
|
|
304
299
|
```bash
|
|
305
300
|
scai index list
|
|
@@ -323,6 +318,104 @@ scai index delete
|
|
|
323
318
|
|
|
324
319
|
---
|
|
325
320
|
|
|
321
|
+
## 🛍️ Maintenance & Utilities
|
|
322
|
+
# Database Commands
|
|
323
|
+
|
|
324
|
+
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.
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
### 📋 Available Commands
|
|
329
|
+
|
|
330
|
+
#### 🔍 Check Database
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
scai db check
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Runs the **dbcheck** script to verify the database status.
|
|
337
|
+
|
|
338
|
+
* Useful for quickly checking if the database is healthy.
|
|
339
|
+
* Prints detailed output directly in the console.
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
#### ♻️ Reset Database
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
scai db reset
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Deletes and resets the SQLite database.
|
|
350
|
+
|
|
351
|
+
* Will ask for confirmation before proceeding.
|
|
352
|
+
* Respond with `y` or `Y` to confirm.
|
|
353
|
+
* Any other key (including `n`, `N`, or just pressing **Enter**) will cancel the reset.
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
#### 📦 Run Migrations
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
scai db migrate
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Executes all database migration scripts.
|
|
364
|
+
|
|
365
|
+
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.
|
|
366
|
+
|
|
367
|
+
If you're upgrading from an earlier version, please run the following commands to avoid indexing issues:
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
scai db reset
|
|
371
|
+
scai index
|
|
372
|
+
```
|
|
373
|
+
</br>
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
### ✅ Example Workflow
|
|
378
|
+
|
|
379
|
+
1. **Check** current database state:
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
scai db check
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
2. Confirm you're in the correct repo.
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
scai index list
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Use the switch command to switch if necessary.
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
scai index switch
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
2. If necessary, **reset** the database:
|
|
398
|
+
|
|
399
|
+
```bash
|
|
400
|
+
scai db reset
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
→ Confirm with `y` when prompted.
|
|
404
|
+
|
|
405
|
+
</br>
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## 🔁 Background Daemon and Indexing ⚠️ ALPHA Notice
|
|
410
|
+
|
|
411
|
+
These features are experimental and subject to change:
|
|
412
|
+
|
|
413
|
+
* `find`, `ask`
|
|
414
|
+
* `daemon`, `stop-daemon`
|
|
415
|
+
* `gen tests` (test generation)
|
|
416
|
+
|
|
417
|
+
<br>
|
|
418
|
+
|
|
326
419
|
> **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
420
|
|
|
328
421
|
The `scai index` command **automatically** starts a background daemon that continuously:
|
|
@@ -335,8 +428,6 @@ You won't gain much value from the index unless you scope it to one repository.
|
|
|
335
428
|
|
|
336
429
|
---
|
|
337
430
|
|
|
338
|
-
### 🔍 Codebase Search & Ask (ALPHA)
|
|
339
|
-
|
|
340
431
|
> **Important:** You must `index` a **code repository** first or `find` and `ask` have no context to work with.
|
|
341
432
|
|
|
342
433
|
1. **Set index directory:**
|
|
@@ -400,40 +491,16 @@ You can run it in two ways:
|
|
|
400
491
|
|
|
401
492
|
---
|
|
402
493
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
If you're upgrading from an earlier version, please run the following commands to avoid indexing issues:
|
|
494
|
+
### Backup only of `~/.scai`:**
|
|
406
495
|
|
|
407
|
-
|
|
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`:**
|
|
496
|
+
Creates a backup of the .scai folder in the user root dir.
|
|
423
497
|
|
|
424
498
|
```bash
|
|
425
499
|
scai backup
|
|
426
500
|
```
|
|
427
501
|
|
|
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
|
-
```
|
|
502
|
+
Results in this:
|
|
503
|
+
~/.scai_backup_2025-08-12T06-58-00-227Z/
|
|
437
504
|
---
|
|
438
505
|
|
|
439
506
|
## 🔐 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
|
-
|
|
192
|
-
|
|
193
|
-
.command('check
|
|
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')
|
package/dist/scripts/dbcheck.js
CHANGED
|
@@ -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
|
|
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
|
|
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🧾
|
|
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
|
|
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
|
|
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
|
|
210
|
-
console.log('\n📊 Table View:
|
|
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
|
|
215
|
+
LIMIT 50
|
|
216
216
|
`).all();
|
|
217
217
|
console.table(fileRows);
|
|
218
|
-
// === Column View of
|
|
219
|
-
console.log('\n📊 Table View:
|
|
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
|
|
224
|
+
LIMIT 50
|
|
225
225
|
`).all();
|
|
226
226
|
console.table(functionRows);
|