@@ -51,7 +51,7 @@ export const sector_configs: Record<string, sector_cfg> = {
5151 decay_lambda : 0.015 ,
5252 weight : 1.2 ,
5353 patterns : [
54- / \b ( t o d a y | y e s t e r d a y | l a s t \s + w e e k | r e m e m b e r \s + w h e n | t h a t \s + t i m e ) \b / i,
54+ / \b ( t o d a y | y e s t e r d a y | l a s t \s + w e e k | r e m e m b e r \s + w h e n | r e c a l l | t h a t \s + t i m e ) \b / i,
5555 / \b ( I \s + ( d i d | w e n t | s a w | m e t | f e l t ) ) \b / i,
5656 / \b ( a t \s + \d + : \d + | o n \s + \w + d a y | i n \s + \d { 4 } ) \b / i,
5757 / \b ( h a p p e n e d | o c c u r r e d | e x p e r i e n c e | e v e n t | m o m e n t ) \b / i,
@@ -77,7 +77,7 @@ export const sector_configs: Record<string, sector_cfg> = {
7777 / \b ( f i r s t | t h e n | n e x t | f i n a l l y | a f t e r w a r d s ) \b / i,
7878 / \b ( i n s t a l l | c o n f i g u r e | s e t u p | r u n | e x e c u t e ) \b / i,
7979 / \b ( t u t o r i a l | g u i d e | i n s t r u c t i o n s | m a n u a l ) \b / i,
80- / \b ( c l i c k | p r e s s | t y p e | e n t e r | s e l e c t ) \b / i,
80+ / \b ( c l i c k | p r e s s | t y p e | e n t e r | s e l e c t | d e f | f u n c t i o n | c l a s s | r e t u r n | i m p o r t | c o n s t | v a r | l e t ) \b / i,
8181 ] ,
8282 } ,
8383 emotional : {
@@ -331,8 +331,9 @@ export function extract_essence(
331331 max_len : number ,
332332) : string {
333333 if ( ! env . use_summary_only || raw . length <= max_len ) return raw ;
334+ // Split on sentence boundaries (punctuation followed by whitespace) to avoid breaking filenames
334335 const sents = raw
335- . split ( / [ . ! ? ] + / )
336+ . split ( / (?< = [ . ! ? ] ) \s + / )
336337 . map ( ( s ) => s . trim ( ) )
337338 . filter ( ( s ) => s . length > 10 ) ;
338339 if ( sents . length === 0 ) return raw . slice ( 0 , max_len ) ;
@@ -368,44 +369,32 @@ export function extract_essence(
368369 return sc ;
369370 } ;
370371 const scored = sents . map ( ( s , idx ) => ( { text : s , score : score_sent ( s , idx ) , idx } ) ) ;
372+ // Sort by score to pick the best sentences
371373 scored . sort ( ( a , b ) => b . score - a . score ) ;
372- // Build result, ensuring first sentence is always included if space permits
373- let comp = "" ;
374- const firstSent = sents [ 0 ] ;
375- if ( firstSent && firstSent . length <= max_len * 0.5 ) {
376- comp = firstSent ;
377- const remaining = scored . filter ( ( item ) => item . idx !== 0 ) ;
378- for ( const item of remaining ) {
379- const cand = comp ? `${ comp } . ${ item . text } ` : item . text ;
380- if ( cand . length <= max_len ) {
381- comp = cand ;
382- } else if ( comp . length < max_len * 0.7 ) {
383- const rem = max_len - comp . length - 2 ;
384- if ( rem > 20 ) {
385- comp += ". " + item . text . slice ( 0 , rem ) ;
386- }
387- break ;
388- } else {
389- break ;
390- }
391- }
392- } else {
393- for ( const item of scored ) {
394- const cand = comp ? `${ comp } . ${ item . text } ` : item . text ;
395- if ( cand . length <= max_len ) {
396- comp = cand ;
397- } else if ( comp . length < max_len * 0.7 ) {
398- const rem = max_len - comp . length - 2 ;
399- if ( rem > 20 ) {
400- comp += ". " + item . text . slice ( 0 , rem ) ;
401- }
402- break ;
403- } else {
404- break ;
405- }
374+
375+ // Select top sentences until we hit max_len
376+ const selected : typeof scored = [ ] ;
377+ let current_len = 0 ;
378+
379+ // Always include the first sentence if it fits
380+ const firstSent = scored . find ( s => s . idx === 0 ) ;
381+ if ( firstSent && firstSent . text . length < max_len ) {
382+ selected . push ( firstSent ) ;
383+ current_len += firstSent . text . length ;
384+ }
385+
386+ for ( const item of scored ) {
387+ if ( item . idx === 0 ) continue ; // Already handled
388+ if ( current_len + item . text . length + 2 <= max_len ) {
389+ selected . push ( item ) ;
390+ current_len += item . text . length + 2 ; // +2 for ". "
406391 }
407392 }
408- return comp || raw . slice ( 0 , max_len ) ;
393+
394+ // Sort selected sentences by their original index to restore context flow
395+ selected . sort ( ( a , b ) => a . idx - b . idx ) ;
396+
397+ return selected . map ( s => s . text ) . join ( " " ) ;
409398}
410399export function compute_token_overlap (
411400 q_toks : Set < string > ,
@@ -750,8 +739,12 @@ const get_sal = async (id: string, def_sal: number): Promise<number> => {
750739export async function hsg_query (
751740 qt : string ,
752741 k = 10 ,
753- f ?: { sectors ?: string [ ] ; minSalience ?: number ; user_id ?: string } ,
742+ f ?: { sectors ?: string [ ] ; minSalience ?: number ; user_id ?: string ; startTime ?: number ; endTime ?: number } ,
754743) : Promise < hsg_q_result [ ] > {
744+ // ... (omitted lines to keep context correct, targeting start of function signature change)
745+ // Actually I'll target the signature and the logic inside the loop.
746+ // Split into two edits or use multi_replace.
747+ // Let's use multi_replace.
755748 if ( active_queries >= env . max_active ) {
756749 throw new Error (
757750 `Rate limit: ${ active_queries } active queries (max ${ env . max_active } )` ,
@@ -839,6 +832,8 @@ export async function hsg_query(
839832 const m = await q . get_mem . get ( mid ) ;
840833 if ( ! m || ( f ?. minSalience && m . salience < f . minSalience ) ) continue ;
841834 if ( f ?. user_id && m . user_id !== f . user_id ) continue ;
835+ if ( f ?. startTime && m . created_at < f . startTime ) continue ;
836+ if ( f ?. endTime && m . created_at > f . endTime ) continue ;
842837 const mvf = await calc_multi_vec_fusion_score ( mid , qe , w ) ;
843838 const csr = await calculateCrossSectorResonanceScore (
844839 m . primary_sector ,
0 commit comments