scai 0.1.40 → 0.1.41

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.
@@ -21,9 +21,9 @@ async function lockDb() {
21
21
  export async function runDaemonBatch() {
22
22
  log('🟡 Starting daemon batch...');
23
23
  const rows = db.prepare(`
24
- SELECT path, type, processing_status FROM files
25
- WHERE (summary IS NULL OR summary = '')
26
- OR processing_status = 'unprocessed'
24
+ SELECT id, path, type, summary, indexed_at, last_modified, processing_status
25
+ FROM files
26
+ WHERE processing_status = 'unprocessed' OR summary IS NULL OR summary = ''
27
27
  ORDER BY last_modified DESC
28
28
  LIMIT ?
29
29
  `).all(MAX_FILES_PER_BATCH);
@@ -47,32 +47,42 @@ export async function runDaemonBatch() {
47
47
  }
48
48
  try {
49
49
  const content = await fs.readFile(row.path, 'utf-8');
50
- const fileResult = db.prepare(`SELECT id FROM files WHERE path = @path`).get({ path: row.path });
51
- const fileId = fileResult?.id;
52
- if (fileId) {
53
- await indexFunctionsForFile(row.path, fileId);
54
- // Update processing_status to 'extracted' after function extraction attempt
55
- db.prepare(`UPDATE files SET processing_status = 'extracted' WHERE id = @id`).run({ id: fileId });
50
+ // 🧠 Only re-generate summary if it's missing or outdated
51
+ const needsResummary = !row.summary ||
52
+ !row.indexed_at ||
53
+ (row.last_modified && new Date(row.last_modified) > new Date(row.indexed_at));
54
+ if (needsResummary) {
55
+ log(`📝 Generating summary for ${row.path}...`);
56
+ const summaryResult = await summaryModule.run({ content, filepath: row.path });
57
+ const summary = summaryResult?.summary?.trim() || null;
58
+ let embedding = null;
59
+ if (summary) {
60
+ const vector = await generateEmbedding(summary);
61
+ if (vector) {
62
+ embedding = JSON.stringify(vector);
63
+ }
64
+ }
65
+ db.prepare(`
66
+ UPDATE files
67
+ SET summary = @summary,
68
+ embedding = @embedding,
69
+ indexed_at = datetime('now')
70
+ WHERE path = @path
71
+ `).run({ summary, embedding, path: row.path });
72
+ log(`✅ Updated summary & embedding for ${row.path}`);
56
73
  }
57
74
  else {
58
- log(`⚠️ Could not find fileId for ${row.path}`);
59
- }
60
- log(`📝 Generating summary for ${row.path}...`);
61
- const summaryResult = await summaryModule.run({ content, filepath: row.path });
62
- const summary = summaryResult?.summary?.trim() || null;
63
- let embedding = null;
64
- if (summary) {
65
- const vector = await generateEmbedding(summary);
66
- if (vector) {
67
- embedding = JSON.stringify(vector);
68
- }
75
+ log(`⚡ Skipped summary (up-to-date) for ${row.path}`);
69
76
  }
77
+ // 🧩 Extract functions and update processing status
78
+ await indexFunctionsForFile(row.path, row.id);
70
79
  db.prepare(`
71
80
  UPDATE files
72
- SET summary = @summary, embedding = @embedding, indexed_at = datetime('now')
73
- WHERE path = @path
74
- `).run({ summary, embedding, path: row.path });
75
- log(`✅ Updated summary & embedding for ${row.path}\n`);
81
+ SET processing_status = 'extracted',
82
+ functions_extracted_at = datetime('now')
83
+ WHERE id = @id
84
+ `).run({ id: row.id });
85
+ log(`✅ Function extraction complete for ${row.path}\n`);
76
86
  }
77
87
  catch (err) {
78
88
  log(`❌ Failed: ${row.path}: ${err instanceof Error ? err.message : String(err)}\n`);
package/dist/db/schema.js CHANGED
@@ -9,7 +9,8 @@ export function initSchema() {
9
9
  indexed_at TEXT,
10
10
  last_modified TEXT,
11
11
  embedding TEXT,
12
- processing_status TEXT
12
+ processing_status TEXT,
13
+ functions_extracted_at TEXT
13
14
  );
14
15
 
15
16
  CREATE VIRTUAL TABLE IF NOT EXISTS files_fts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scai",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "scai": "./dist/index.js"