@@ -196,7 +196,7 @@ function isRecoverableConnectionError(err: unknown): boolean {
196196 )
197197}
198198
199- function isNoteNotFoundError ( err : unknown ) : boolean {
199+ function _isNoteNotFoundError ( err : unknown ) : boolean {
200200 const msg = getErrorMessage ( err ) . toLowerCase ( )
201201 return (
202202 msg . includes ( "entity not found" ) ||
@@ -830,10 +830,6 @@ export class BmClient {
830830 return payload as unknown as MetadataSearchResult
831831 }
832832
833- private isNoteNotFoundError ( err : unknown ) : boolean {
834- return isNoteNotFoundError ( err )
835- }
836-
837833 async indexConversation (
838834 userMessage : string ,
839835 assistantResponse : string ,
@@ -855,22 +851,33 @@ export class BmClient {
855851 "---" ,
856852 ] . join ( "\n" )
857853
854+ // Try append first — if it fails for ANY reason, fall through to create
858855 try {
859856 await this . editNote ( title , "append" , entry )
860857 log . debug ( `appended conversation to: ${ title } ` )
858+ return
861859 } catch ( err ) {
862- if ( ! this . isNoteNotFoundError ( err ) ) {
863- log . error ( "conversation append failed" , err )
864- return
865- }
860+ log . debug ( `append failed, will create: ${ getErrorMessage ( err ) } ` )
861+ }
866862
867- const content = [ `# Conversations ${ dateStr } ` , "" , entry ] . join ( "\n" )
868- try {
869- await this . writeNote ( title , content , "conversations" )
870- log . debug ( `created conversation note: ${ title } ` )
871- } catch ( createErr ) {
872- log . error ( "conversation index failed" , createErr )
873- }
863+ // Create the note with frontmatter and first entry
864+ const content = [
865+ "---" ,
866+ `title: Conversations ${ dateStr } ` ,
867+ "type: Conversation" ,
868+ `date: "${ dateStr } "` ,
869+ "---" ,
870+ "" ,
871+ `# Conversations ${ dateStr } ` ,
872+ "" ,
873+ entry ,
874+ ] . join ( "\n" )
875+
876+ try {
877+ await this . writeNote ( title , content , "conversations" )
878+ log . debug ( `created conversation note: ${ title } ` )
879+ } catch ( err ) {
880+ log . error ( "conversation index failed" , err )
874881 }
875882 }
876883
0 commit comments