scai 0.1.95 → 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/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
|
@@ -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
|
+
}
|