scai 0.1.28 → 0.1.29
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/AskCmd.js +34 -10
- package/package.json +1 -1
package/dist/commands/AskCmd.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import readline from 'readline';
|
|
2
|
-
import
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { searchFiles, queryFiles } from "../db/fileIndex.js";
|
|
4
|
+
import { sanitizeQueryForFts } from "../utils/sanitizeQuery.js";
|
|
3
5
|
import { generate } from "../lib/generate.js";
|
|
4
6
|
export async function runAskCommand(query) {
|
|
5
7
|
if (!query) {
|
|
@@ -12,21 +14,43 @@ export async function runAskCommand(query) {
|
|
|
12
14
|
}
|
|
13
15
|
console.log(`🔍 Searching for: "${query}"\n`);
|
|
14
16
|
const start = Date.now();
|
|
15
|
-
const
|
|
17
|
+
const semanticResults = await searchFiles(query, 5);
|
|
16
18
|
const duration = Date.now() - start;
|
|
17
|
-
console.log(`⏱️ searchFiles took ${duration}ms and returned ${
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
console.log(`⏱️ searchFiles took ${duration}ms and returned ${semanticResults.length} result(s)`);
|
|
20
|
+
// Also run fallback keyword search
|
|
21
|
+
const safeQuery = sanitizeQueryForFts(query);
|
|
22
|
+
const fallbackResults = queryFiles(safeQuery, 10);
|
|
23
|
+
// Merge semantic and fallback results
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
const combinedResults = [];
|
|
26
|
+
for (const file of semanticResults) {
|
|
27
|
+
const resolved = path.resolve(file.path);
|
|
28
|
+
seen.add(resolved);
|
|
29
|
+
combinedResults.push(file); // Already scored
|
|
30
|
+
}
|
|
31
|
+
for (const file of fallbackResults) {
|
|
32
|
+
const resolved = path.resolve(file.path);
|
|
33
|
+
if (!seen.has(resolved)) {
|
|
34
|
+
seen.add(resolved);
|
|
35
|
+
combinedResults.push({
|
|
36
|
+
path: file.path,
|
|
37
|
+
summary: file.summary,
|
|
38
|
+
score: 0.0, // fallback score
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (combinedResults.length > 0) {
|
|
43
|
+
console.log('📊 Closest files based on semantic + keyword match:');
|
|
44
|
+
combinedResults.forEach((file, i) => {
|
|
45
|
+
console.log(` ${i + 1}. 📄 Path: ${file.path} | Score: ${file.score?.toFixed(3) ?? 'fallback'}`);
|
|
22
46
|
});
|
|
23
47
|
}
|
|
24
48
|
else {
|
|
25
|
-
console.log('⚠️ No similar
|
|
49
|
+
console.log('⚠️ No similar files found. Asking the model for context only...');
|
|
26
50
|
}
|
|
27
|
-
//
|
|
51
|
+
// Aggregate summaries
|
|
28
52
|
let allSummaries = '';
|
|
29
|
-
for (const file of
|
|
53
|
+
for (const file of combinedResults) {
|
|
30
54
|
if (!file?.summary) {
|
|
31
55
|
console.warn(`⚠️ No summary available for file: ${file?.path}`);
|
|
32
56
|
continue;
|