@@ -3959,42 +3959,6 @@ function cwdToCliProjectName(cwd) {
39593959 return cwd . replace ( / [ / _ ] / g, '-' ) ;
39603960}
39613961
3962- function parseJsonlToMessages ( jsonlPath ) {
3963- try {
3964- const lines = fs . readFileSync ( jsonlPath , 'utf8' ) . trim ( ) . split ( '\n' ) . filter ( Boolean ) ;
3965- const msgs = [ ] ;
3966- let idCounter = 1 ;
3967- for ( const line of lines ) {
3968- let d ; try { d = JSON . parse ( line ) ; } catch { continue ; }
3969- const ts = d . timestamp || null ;
3970- if ( d . type === 'user' ) {
3971- const mc = d . message ?. content ;
3972- if ( ! Array . isArray ( mc ) ) {
3973- if ( typeof mc === 'string' && mc . trim ( ) )
3974- msgs . push ( { id : idCounter ++ , role : 'user' , type : 'text' , content : mc , tool_name : null , agent_id : null , created_at : ts } ) ;
3975- continue ;
3976- }
3977- // Only show text blocks; tool_result entries are system responses to tool calls
3978- // (not user-written messages) — showing them clutters history with "Read result" etc.
3979- const textBlocks = mc . filter ( b => b . type === 'text' && b . text ?. trim ( ) ) ;
3980- if ( textBlocks . length > 0 )
3981- msgs . push ( { id : idCounter ++ , role : 'user' , type : 'text' , content : textBlocks . map ( b => b . text ) . join ( '\n' ) , tool_name : null , agent_id : null , created_at : ts } ) ;
3982- } else if ( d . type === 'assistant' ) {
3983- const mc = d . message ?. content ;
3984- if ( ! Array . isArray ( mc ) ) continue ;
3985- for ( const b of mc ) {
3986- if ( b . type === 'thinking' && b . thinking )
3987- msgs . push ( { id : idCounter ++ , role : 'assistant' , type : 'thinking' , content : b . thinking , tool_name : null , agent_id : null , created_at : ts } ) ;
3988- else if ( b . type === 'tool_use' && b . name )
3989- msgs . push ( { id : idCounter ++ , role : 'assistant' , type : 'tool' , content : ( typeof b . input === 'string' ? b . input : JSON . stringify ( b . input || { } ) ) . substring ( 0 , 2000 ) , tool_name : b . name , agent_id : null , created_at : ts } ) ;
3990- else if ( b . type === 'text' && b . text )
3991- msgs . push ( { id : idCounter ++ , role : 'assistant' , type : 'text' , content : b . text , tool_name : null , agent_id : null , created_at : ts } ) ;
3992- }
3993- }
3994- }
3995- return msgs ;
3996- } catch { return [ ] ; }
3997- }
39983962
39993963app . get ( '/api/sessions/cli-list' , ( req , res ) => {
40003964 const workdir = String ( req . query . workdir || WORKDIR || '' ) ;
@@ -4134,25 +4098,7 @@ app.get('/api/sessions/:id', (req,res) => {
41344098 const s = stmts . getSession . get ( req . params . id ) ;
41354099 if ( ! s ) return res . status ( 404 ) . json ( { error : 'Not found' } ) ;
41364100
4137- // Try JSONL-first serving if session has CLI session ID and workdir
4138- let messages = null ;
4139- if ( s . claude_session_id && s . workdir ) {
4140- const homeDir = os . homedir ( ) ;
4141- const safeBase = path . resolve ( path . join ( homeDir , '.claude' , 'projects' ) ) ;
4142- const projectDir = path . resolve ( path . join ( safeBase , cwdToCliProjectName ( s . workdir ) ) ) ;
4143- const jsonlPath = path . join ( projectDir , s . claude_session_id + '.jsonl' ) ;
4144- if ( fs . existsSync ( jsonlPath ) ) {
4145- const parsed = parseJsonlToMessages ( jsonlPath ) ;
4146- if ( parsed . length > 0 ) messages = parsed ;
4147- }
4148- }
4149-
4150- // Fallback to SQLite
4151- if ( ! messages ) {
4152- messages = stmts . getMsgsLite . all ( req . params . id ) ;
4153- }
4154-
4155- s . messages = messages ;
4101+ s . messages = stmts . getMsgsLite . all ( req . params . id ) ;
41564102 s . hasRunningTask = ! ! stmts . hasRunningTask . get ( req . params . id ) ;
41574103 s . isChatRunning = activeTasks . has ( req . params . id ) ;
41584104 const chainTasks = stmts . getChainTasks . all ( req . params . id ) ;
0 commit comments