scai 0.1.36 → 0.1.37
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.
|
@@ -44,28 +44,33 @@ export async function runDaemonBatch() {
|
|
|
44
44
|
}
|
|
45
45
|
try {
|
|
46
46
|
const content = await fs.readFile(row.path, 'utf-8');
|
|
47
|
-
// 1.
|
|
47
|
+
// 1. Lookup file ID in the database using its path
|
|
48
48
|
const fileResult = db
|
|
49
|
-
.prepare(`SELECT id FROM files WHERE path =
|
|
50
|
-
.get(row.path);
|
|
49
|
+
.prepare(`SELECT id FROM files WHERE path = @path`) // Replaced `?` with `@path`
|
|
50
|
+
.get({ path: row.path });
|
|
51
51
|
const fileId = fileResult?.id;
|
|
52
|
-
if (
|
|
53
|
-
|
|
52
|
+
if (fileId) {
|
|
53
|
+
// 2. Extract and index functions for this file
|
|
54
|
+
await indexFunctionsForFile(row.path, fileId);
|
|
55
|
+
// 3. Mark the file as having functions extracted in the database
|
|
56
|
+
db.prepare(`UPDATE files SET functions_extracted = 1 WHERE id = @id`).run({ id: fileId });
|
|
54
57
|
}
|
|
55
58
|
else {
|
|
56
|
-
|
|
59
|
+
log(`⚠️ Could not find fileId for ${row.path}`);
|
|
57
60
|
}
|
|
58
|
-
//
|
|
61
|
+
// 4. Summarize the file content
|
|
59
62
|
log(`📝 Generating summary for ${row.path}...`);
|
|
60
63
|
const summaryResult = await summaryModule.run({ content, filepath: row.path });
|
|
61
64
|
const summary = summaryResult?.summary?.trim() || null;
|
|
62
65
|
let embedding = null;
|
|
63
66
|
if (summary) {
|
|
67
|
+
// 5. Generate embedding for the summary
|
|
64
68
|
const vector = await generateEmbedding(summary);
|
|
65
69
|
if (vector) {
|
|
66
70
|
embedding = JSON.stringify(vector);
|
|
67
71
|
}
|
|
68
72
|
}
|
|
73
|
+
// 6. Save the summary and embedding in the database
|
|
69
74
|
db.prepare(`
|
|
70
75
|
UPDATE files
|
|
71
76
|
SET summary = @summary, embedding = @embedding, indexed_at = datetime('now')
|
|
@@ -74,8 +79,10 @@ export async function runDaemonBatch() {
|
|
|
74
79
|
log(`✅ Updated summary & embedding for ${row.path}\n`);
|
|
75
80
|
}
|
|
76
81
|
catch (err) {
|
|
82
|
+
// 7. Error handling: Log the error message if the process fails
|
|
77
83
|
log(`❌ Failed: ${row.path}: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
78
84
|
}
|
|
85
|
+
// 8. Optional delay between file processing to reduce load on the system
|
|
79
86
|
await new Promise(resolve => setTimeout(resolve, 200));
|
|
80
87
|
}
|
|
81
88
|
await release();
|
|
@@ -9,7 +9,7 @@ import { extractFromXML } from './extractFromXML.js';
|
|
|
9
9
|
export async function extractFunctionsFromFile(filePath, content, fileId) {
|
|
10
10
|
const type = detectFileType(filePath).trim().toLowerCase();
|
|
11
11
|
;
|
|
12
|
-
if (type === 'js' || type === 'ts') {
|
|
12
|
+
if (type === 'js' || type === 'ts' || type === 'javascript' || type === 'typescript') {
|
|
13
13
|
log(`✅ Attempting to extract JS functions from ${filePath}\n`);
|
|
14
14
|
await extractFromJS(filePath, content, fileId);
|
|
15
15
|
return true;
|