Fix critical bugs in export/import feature (PR #225)

Addressed all 6 bugs identified in code reviews:

CRITICAL FIXES:
1. SessionStore.ts: Fixed concepts filter bug - removed empty params.push()
   that was breaking SQL parameter alignment (line 849)

2. import-memories.ts: Removed worker_port and prompt_counter fields from
   sdk_sessions insert to fix schema mismatch with fresh databases

3. export-memories.ts: Fixed hardcoded port - now reads from settings via
   SettingsDefaultsManager.loadFromFile()

HIGH PRIORITY:
4. export-memories.ts: Added database existence check with clear error
   message before opening database connection

5. export-memories.ts: Fixed variable shadowing - renamed local 'query'
   variable to 'sessionQuery' (line 90)

MEDIUM PRIORITY:
6. export-memories.ts: Improved type safety - added ObservationRecord,
   SdkSessionRecord, SessionSummaryRecord, UserPromptRecord interfaces

All fixes tested and verified:
- Export script successfully exports with project filtering
- Import script works on existing database with duplicate prevention
- Port configuration read from settings.json
- Type safety improvements prevent compile-time errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2025-12-10 20:15:26 -05:00
parent a8b84fa7b6
commit 4e7ed75fa9
5 changed files with 91 additions and 24 deletions

View File

@@ -305,7 +305,7 @@ ${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let r=Obje
SELECT *
FROM observations
WHERE id = ?
`).get(e)||null}getObservationsByIds(e,r={}){if(e.length===0)return[];let{orderBy:t="date_desc",limit:s,project:i,type:n,concepts:o,files:l}=r,c=t==="date_asc"?"ASC":"DESC",u=s?`LIMIT ${s}`:"",p=e.map(()=>"?").join(","),m=[...e],d=[];if(i&&(d.push("project = ?"),m.push(i)),n)if(Array.isArray(n)){let f=n.map(()=>"?").join(",");d.push(`type IN (${f})`),m.push(...n)}else d.push("type = ?"),m.push(n);if(o){let f=Array.isArray(o)?o:[o],y=f.map(()=>(m.push(),"EXISTS (SELECT 1 FROM json_each(concepts) WHERE value = ?)"));m.push(...f),d.push(`(${y.join(" OR ")})`)}if(l){let f=Array.isArray(l)?l:[l],y=f.map(()=>"(EXISTS (SELECT 1 FROM json_each(files_read) WHERE value LIKE ?) OR EXISTS (SELECT 1 FROM json_each(files_modified) WHERE value LIKE ?))");f.forEach(g=>{m.push(`%${g}%`,`%${g}%`)}),d.push(`(${y.join(" OR ")})`)}let v=d.length>0?`WHERE id IN (${p}) AND ${d.join(" AND ")}`:`WHERE id IN (${p})`;return this.db.prepare(`
`).get(e)||null}getObservationsByIds(e,r={}){if(e.length===0)return[];let{orderBy:t="date_desc",limit:s,project:i,type:n,concepts:o,files:l}=r,c=t==="date_asc"?"ASC":"DESC",u=s?`LIMIT ${s}`:"",p=e.map(()=>"?").join(","),m=[...e],d=[];if(i&&(d.push("project = ?"),m.push(i)),n)if(Array.isArray(n)){let f=n.map(()=>"?").join(",");d.push(`type IN (${f})`),m.push(...n)}else d.push("type = ?"),m.push(n);if(o){let f=Array.isArray(o)?o:[o],y=f.map(()=>"EXISTS (SELECT 1 FROM json_each(concepts) WHERE value = ?)");m.push(...f),d.push(`(${y.join(" OR ")})`)}if(l){let f=Array.isArray(l)?l:[l],y=f.map(()=>"(EXISTS (SELECT 1 FROM json_each(files_read) WHERE value LIKE ?) OR EXISTS (SELECT 1 FROM json_each(files_modified) WHERE value LIKE ?))");f.forEach(g=>{m.push(`%${g}%`,`%${g}%`)}),d.push(`(${y.join(" OR ")})`)}let v=d.length>0?`WHERE id IN (${p}) AND ${d.join(" AND ")}`:`WHERE id IN (${p})`;return this.db.prepare(`
SELECT *
FROM observations
${v}