@@ -46,12 +46,15 @@ export function isInScheduleWindow(schedule: string, now: Date = new Date()): bo
4646 return currentMinutes >= window . startMinutes || currentMinutes < window . endMinutes ;
4747}
4848
49- /** Find projects that have memory updates since their per-project last dream time. */
49+ /** Find projects that have memory updates or pending smart notes since their per-project last dream time. */
5050export function findProjectsNeedingDream ( db : Database ) : string [ ] {
51- // Get all active project paths
51+ // Get all active project paths from memories and smart notes
5252 const projectRows = db
5353 . query < { project_path : string } , [ ] > (
54- `SELECT DISTINCT project_path FROM memories WHERE status = 'active' ORDER BY project_path` ,
54+ `SELECT DISTINCT project_path FROM memories WHERE status = 'active'
55+ UNION
56+ SELECT DISTINCT project_path FROM smart_notes WHERE status = 'pending'
57+ ORDER BY project_path` ,
5558 )
5659 . all ( ) ;
5760
@@ -62,14 +65,24 @@ export function findProjectsNeedingDream(db: Database): string[] {
6265 const fallbackStr = ! lastDreamAtStr ? getDreamState ( db , "last_dream_at" ) : null ;
6366 const lastDreamAt = Number ( lastDreamAtStr ?? fallbackStr ?? "0" ) || 0 ;
6467
65- const updated = db
68+ const updatedMemories = db
6669 . query < { cnt : number } , [ string , number ] > (
6770 `SELECT COUNT(*) as cnt FROM memories
6871 WHERE project_path = ? AND status = 'active' AND updated_at > ?` ,
6972 )
7073 . get ( row . project_path , lastDreamAt ) ;
7174
72- if ( updated && updated . cnt > 0 ) {
75+ const pendingSmartNotes = db
76+ . query < { cnt : number } , [ string ] > (
77+ `SELECT COUNT(*) as cnt FROM smart_notes
78+ WHERE project_path = ? AND status = 'pending'` ,
79+ )
80+ . get ( row . project_path ) ;
81+
82+ if (
83+ ( updatedMemories && updatedMemories . cnt > 0 ) ||
84+ ( pendingSmartNotes && pendingSmartNotes . cnt > 0 )
85+ ) {
7386 projects . push ( row . project_path ) ;
7487 }
7588 }
0 commit comments