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.
@@ -1,5 +1,7 @@
1
1
  import readline from 'readline';
2
- import { searchFiles } from "../db/fileIndex.js";
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 results = await searchFiles(query, 5);
17
+ const semanticResults = await searchFiles(query, 5);
16
18
  const duration = Date.now() - start;
17
- console.log(`⏱️ searchFiles took ${duration}ms and returned ${results.length} result(s)`);
18
- if (results.length > 0) {
19
- console.log('📊 Closest files based on semantic similarity:');
20
- results.forEach((file, i) => {
21
- console.log(` ${i + 1}. 📄 Path: ${file?.path} | Score: ${file?.score?.toFixed(3)}`);
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 embeddings found. Asking the model for context instead...');
49
+ console.log('⚠️ No similar files found. Asking the model for context only...');
26
50
  }
27
- // 🧠 Use stored summaries directly
51
+ // Aggregate summaries
28
52
  let allSummaries = '';
29
- for (const file of results) {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scai",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "scai": "./dist/index.js"