@@ -85,7 +85,9 @@ export namespace Storage {
8585 const session = await Bun . file ( sessionFile ) . json ( )
8686 await Bun . write ( dest , JSON . stringify ( session ) )
8787 log . info ( `migrating messages for session ${ session . id } ` )
88- for await ( const msgFile of new Bun . Glob ( `storage/session/message/${ session . id } /*.json` ) . scan ( {
88+ for await ( const msgFile of new Bun . Glob (
89+ `storage/session/message/${ session . id } /*.json` ,
90+ ) . scan ( {
8991 cwd : fullProjectDir ,
9092 absolute : true ,
9193 } ) ) {
@@ -98,12 +100,12 @@ export namespace Storage {
98100 await Bun . write ( dest , JSON . stringify ( message ) )
99101
100102 log . info ( `migrating parts for message ${ message . id } ` )
101- for await ( const partFile of new Bun . Glob ( `storage/session/part/ ${ session . id } / ${ message . id } /*.json` ) . scan (
102- {
103- cwd : fullProjectDir ,
104- absolute : true ,
105- } ,
106- ) ) {
103+ for await ( const partFile of new Bun . Glob (
104+ `storage/session/part/ ${ session . id } / ${ message . id } /*.json` ,
105+ ) . scan ( {
106+ cwd : fullProjectDir ,
107+ absolute : true ,
108+ } ) ) {
107109 const dest = path . join ( dir , "part" , message . id , path . basename ( partFile ) )
108110 const part = await Bun . file ( partFile ) . json ( )
109111 log . info ( "copying" , {
@@ -117,6 +119,29 @@ export namespace Storage {
117119 }
118120 }
119121 } ,
122+ async ( dir ) => {
123+ for await ( const item of new Bun . Glob ( "session/*/*.json" ) . scan ( {
124+ cwd : dir ,
125+ absolute : true ,
126+ } ) ) {
127+ const session = await Bun . file ( item ) . json ( )
128+ if ( ! session . projectID ) continue
129+ if ( ! session . summary ?. diffs ) continue
130+ const { diffs } = session . summary
131+ await Bun . file ( path . join ( dir , "session_diff" , session . id + ".json" ) ) . write (
132+ JSON . stringify ( diffs ) ,
133+ )
134+ await Bun . file ( path . join ( dir , "session" , session . projectID , session . id + ".json" ) ) . write (
135+ JSON . stringify ( {
136+ ...session ,
137+ summary : {
138+ additions : diffs . reduce ( ( sum : any , x : any ) => sum + x . additions , 0 ) ,
139+ deletions : diffs . reduce ( ( sum : any , x : any ) => sum + x . deletions , 0 ) ,
140+ } ,
141+ } ) ,
142+ )
143+ }
144+ } ,
120145 ]
121146
122147 const state = lazy ( async ( ) => {
@@ -128,9 +153,7 @@ export namespace Storage {
128153 for ( let index = migration ; index < MIGRATIONS . length ; index ++ ) {
129154 log . info ( "running migration" , { index } )
130155 const migration = MIGRATIONS [ index ]
131- await migration ( dir ) . catch ( ( e ) => {
132- log . error ( "failed to run migration" , { error : e , index } )
133- } )
156+ await migration ( dir ) . catch ( ( ) => log . error ( "failed to run migration" , { index } ) )
134157 await Bun . write ( path . join ( dir , "migration" ) , ( index + 1 ) . toString ( ) )
135158 }
136159 return {
0 commit comments