scai 0.1.94 → 0.1.96
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 +16 -9
- package/dist/commands/ResetDbCmd.js +2 -1
- package/dist/config.js +1 -1
- package/dist/context.js +60 -0
- package/dist/index.js +19 -10
- package/package.json +1 -1
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,25 +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
|
-
|
|
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
262
|
---
|
|
256
263
|
|
|
257
264
|
## ⚙️ Configuration
|
|
@@ -4,6 +4,7 @@ import lockfile from 'proper-lockfile';
|
|
|
4
4
|
import readline from 'readline';
|
|
5
5
|
import { backupScaiFolder } from '../db/backup.js';
|
|
6
6
|
import { getDbPathForRepo, getDbForRepo } from '../db/client.js';
|
|
7
|
+
import chalk from 'chalk';
|
|
7
8
|
export async function resetDatabase() {
|
|
8
9
|
const dbPath = getDbPathForRepo();
|
|
9
10
|
console.log(`⚠️ You are about to delete the database at: ${dbPath}`);
|
|
@@ -74,5 +75,5 @@ export async function resetDatabase() {
|
|
|
74
75
|
console.warn('⚠️ Failed to remove lock directory:', err instanceof Error ? err.message : err);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
console.log('✅ Database has been reset. You can now re-run: scai index');
|
|
78
|
+
console.log('✅ Database has been reset.' + chalk.yellow('You can now re-run: scai index'));
|
|
78
79
|
}
|
package/dist/config.js
CHANGED
package/dist/context.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// context.ts
|
|
2
|
+
import { readConfig, writeConfig } from "./config.js";
|
|
3
|
+
import { normalizePath } from "./utils/normalizePath.js";
|
|
4
|
+
import { getHashedRepoKey } from "./utils/repoKey.js";
|
|
5
|
+
import { getDbForRepo } from "./db/client.js";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
export async function updateContext() {
|
|
10
|
+
const cwd = normalizePath(process.cwd());
|
|
11
|
+
const cfg = readConfig();
|
|
12
|
+
// 🔑 Find repoKey by matching indexDir to cwd
|
|
13
|
+
let repoKey = Object.keys(cfg.repos || {}).find((key) => normalizePath(cfg.repos[key]?.indexDir || "") === cwd);
|
|
14
|
+
// Fail if no repoKey & no indexDir
|
|
15
|
+
if (!repoKey) {
|
|
16
|
+
repoKey = getHashedRepoKey(cwd);
|
|
17
|
+
if (!cfg.repos[repoKey])
|
|
18
|
+
cfg.repos[repoKey] = {};
|
|
19
|
+
cfg.repos[repoKey].indexDir = cwd;
|
|
20
|
+
console.log(chalk.yellow(`ℹ️ Initializing new repo config for: ${cwd}`));
|
|
21
|
+
}
|
|
22
|
+
// Always set this as active repo
|
|
23
|
+
cfg.activeRepo = repoKey;
|
|
24
|
+
writeConfig(cfg);
|
|
25
|
+
const repoCfg = cfg.repos[repoKey];
|
|
26
|
+
let ok = true;
|
|
27
|
+
console.log(chalk.yellow("\n🔁 Updating context...\n"));
|
|
28
|
+
console.log(`✅ Active repo: ${chalk.green(repoKey)}`);
|
|
29
|
+
console.log(`✅ Index dir: ${chalk.cyan(repoCfg.indexDir || cwd)}`);
|
|
30
|
+
// GitHub token is optional
|
|
31
|
+
const token = repoCfg.githubToken || cfg.githubToken;
|
|
32
|
+
if (!token) {
|
|
33
|
+
console.log(`ℹ️ No GitHub token found. You can set one with the: ${chalk.bold(chalk.bgGreen("scai auth set"))} command`);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.log(`✅ GitHub token present`);
|
|
37
|
+
}
|
|
38
|
+
// Ensure DB exists
|
|
39
|
+
const scaiRepoRoot = path.join(path.dirname(repoCfg.indexDir || cwd), repoKey);
|
|
40
|
+
const dbPath = path.join(scaiRepoRoot, "db.sqlite");
|
|
41
|
+
if (!fs.existsSync(dbPath)) {
|
|
42
|
+
console.log(chalk.yellow(`📦 Initializing DB at ${dbPath}`));
|
|
43
|
+
try {
|
|
44
|
+
getDbForRepo();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
ok = false; // DB init failed
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.log(chalk.green("✅ Database present"));
|
|
52
|
+
}
|
|
53
|
+
if (ok) {
|
|
54
|
+
console.log(chalk.bold.green("\n✅ Context OK\n"));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.log(chalk.bold.red("\n⚠️ Context incomplete\n"));
|
|
58
|
+
}
|
|
59
|
+
return ok;
|
|
60
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ import { generateTestsModule } from './pipeline/modules/generateTestsModule.js';
|
|
|
32
32
|
import { preserveCodeModule } from './pipeline/modules/preserveCodeModule.js';
|
|
33
33
|
import { runInteractiveDelete } from './commands/DeleteIndex.js';
|
|
34
34
|
import { resolveTargetsToFiles } from './utils/resolveTargetsToFiles.js';
|
|
35
|
+
import { updateContext } from './context.js';
|
|
35
36
|
// 🎛️ CLI Setup
|
|
36
37
|
const cmd = new Command('scai')
|
|
37
38
|
.version(version)
|
|
@@ -147,16 +148,18 @@ config
|
|
|
147
148
|
Config.show();
|
|
148
149
|
});
|
|
149
150
|
config
|
|
150
|
-
.command(
|
|
151
|
-
.option(
|
|
152
|
-
.description(
|
|
153
|
-
.action((options) => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
151
|
+
.command("show")
|
|
152
|
+
.option("--raw", "Show full raw config")
|
|
153
|
+
.description("Display current configuration")
|
|
154
|
+
.action(async (options) => {
|
|
155
|
+
await withContext(async () => {
|
|
156
|
+
if (options.raw) {
|
|
157
|
+
console.log(JSON.stringify(Config.getRaw(), null, 2));
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
Config.show();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
160
163
|
});
|
|
161
164
|
const index = cmd.command('index').description('index operations');
|
|
162
165
|
index
|
|
@@ -269,3 +272,9 @@ if (opts.model)
|
|
|
269
272
|
Config.setModel(opts.model);
|
|
270
273
|
if (opts.lang)
|
|
271
274
|
Config.setLanguage(opts.lang);
|
|
275
|
+
async function withContext(action) {
|
|
276
|
+
const ok = await updateContext();
|
|
277
|
+
if (!ok)
|
|
278
|
+
process.exit(1);
|
|
279
|
+
await action();
|
|
280
|
+
}
|