@@ -31,6 +31,7 @@ interface FileInfo {
3131 relativePath : string ;
3232 task_id ?: string ;
3333 project_id ?: string ;
34+ source ?: 'project_output' | 'camel_log' ;
3435}
3536
3637export class FileReader {
@@ -658,20 +659,23 @@ export class FileReader {
658659 }
659660 }
660661
661- public getFileList (
662+ private resolveTaskPaths (
662663 email : string ,
663664 taskId : string ,
664665 projectId ?: string
665- ) : FileInfo [ ] {
666+ ) : {
667+ dirPath : string ;
668+ logPath : string ;
669+ } {
666670 const safeEmail = email
667671 . split ( '@' ) [ 0 ]
668672 . replace ( / [ \\ / * ? : " < > | \s ] / g, '_' )
669673 . replace ( / ^ \. + | \. + $ / g, '' ) ;
670674 const userHome = app . getPath ( 'home' ) ;
671675
672676 let dirPath : string ;
677+ let logPath : string ;
673678
674- // Check if projectId is provided for new project-based structure
675679 if ( projectId ) {
676680 dirPath = path . join (
677681 userHome ,
@@ -680,25 +684,72 @@ export class FileReader {
680684 `project_${ projectId } ` ,
681685 `task_${ taskId } `
682686 ) ;
683- } else {
684- // First try project-based structure (scan for existing projects)
685- const userDir = path . join ( userHome , 'eigent' , safeEmail ) ;
686- const projectBasedPath = this . findTaskInProjects ( userDir , taskId ) ;
687+ logPath = path . join (
688+ userHome ,
689+ '.eigent' ,
690+ safeEmail ,
691+ `project_${ projectId } ` ,
692+ `task_${ taskId } `
693+ ) ;
694+ return { dirPath, logPath } ;
695+ }
687696
688- if ( projectBasedPath ) {
689- dirPath = projectBasedPath ;
697+ const userDir = path . join ( userHome , 'eigent' , safeEmail ) ;
698+ const projectBasedPath = this . findTaskInProjects ( userDir , taskId ) ;
699+
700+ if ( projectBasedPath ) {
701+ dirPath = projectBasedPath ;
702+ const projectMatch = projectBasedPath . match ( / p r o j e c t _ ( [ ^ \\ \/ ] + ) / ) ;
703+ if ( projectMatch ) {
704+ logPath = path . join (
705+ userHome ,
706+ '.eigent' ,
707+ safeEmail ,
708+ projectMatch [ 0 ] ,
709+ `task_${ taskId } `
710+ ) ;
690711 } else {
691- // Fallback to legacy direct task structure
692- dirPath = path . join ( userHome , 'eigent' , safeEmail , `task_${ taskId } ` ) ;
712+ logPath = path . join ( userHome , '.eigent' , safeEmail , `task_${ taskId } ` ) ;
693713 }
714+ return { dirPath, logPath } ;
694715 }
695716
717+ dirPath = path . join ( userHome , 'eigent' , safeEmail , `task_${ taskId } ` ) ;
718+ logPath = path . join ( userHome , '.eigent' , safeEmail , `task_${ taskId } ` ) ;
719+ return { dirPath, logPath } ;
720+ }
721+
722+ public getFileList (
723+ email : string ,
724+ taskId : string ,
725+ projectId ?: string
726+ ) : FileInfo [ ] {
727+ const { dirPath, logPath } = this . resolveTaskPaths (
728+ email ,
729+ taskId ,
730+ projectId
731+ ) ;
732+ const camelLogPath = path . join ( logPath , 'camel_logs' ) ;
733+
696734 try {
697- if ( ! fs . existsSync ( dirPath ) ) {
735+ const projectFiles = fs . existsSync ( dirPath )
736+ ? this . getFilesRecursive ( dirPath , dirPath ) . map ( ( file ) => ( {
737+ ...file ,
738+ source : 'project_output' as const ,
739+ } ) )
740+ : [ ] ;
741+ const camelLogFiles = fs . existsSync ( camelLogPath )
742+ ? this . getFilesRecursive ( camelLogPath , camelLogPath ) . map ( ( file ) => ( {
743+ ...file ,
744+ source : 'camel_log' as const ,
745+ } ) )
746+ : [ ] ;
747+
748+ if ( projectFiles . length === 0 && camelLogFiles . length === 0 ) {
698749 return [ ] ;
699750 }
700751
701- return this . getFilesRecursive ( dirPath , dirPath ) ;
752+ return [ ... projectFiles , ... camelLogFiles ] ;
702753 } catch ( err ) {
703754 console . error ( 'Load file failed:' , err ) ;
704755 return [ ] ;
@@ -713,57 +764,11 @@ export class FileReader {
713764 success : boolean ;
714765 path : { dirPath : string ; logPath : string } ;
715766 } {
716- const safeEmail = email
717- . split ( '@' ) [ 0 ]
718- . replace ( / [ \\ / * ? : " < > | \s ] / g, '_' )
719- . replace ( / ^ \. + | \. + $ / g, '' ) ;
720- const userHome = app . getPath ( 'home' ) ;
721-
722- let dirPath : string ;
723- let logPath : string ;
724-
725- // Check if projectId is provided for new project-based structure
726- if ( projectId ) {
727- dirPath = path . join (
728- userHome ,
729- 'eigent' ,
730- safeEmail ,
731- `project_${ projectId } ` ,
732- `task_${ taskId } `
733- ) ;
734- logPath = path . join (
735- userHome ,
736- '.eigent' ,
737- safeEmail ,
738- `project_${ projectId } ` ,
739- `task_${ taskId } `
740- ) ;
741- } else {
742- // First try project-based structure
743- const userDir = path . join ( userHome , 'eigent' , safeEmail ) ;
744- const projectBasedPath = this . findTaskInProjects ( userDir , taskId ) ;
745-
746- if ( projectBasedPath ) {
747- dirPath = projectBasedPath ;
748- // Extract project from path to construct log path
749- const projectMatch = projectBasedPath . match ( / p r o j e c t _ ( [ ^ \\ \/ ] + ) / ) ;
750- if ( projectMatch ) {
751- logPath = path . join (
752- userHome ,
753- '.eigent' ,
754- safeEmail ,
755- projectMatch [ 0 ] ,
756- `task_${ taskId } `
757- ) ;
758- } else {
759- logPath = path . join ( userHome , '.eigent' , safeEmail , `task_${ taskId } ` ) ;
760- }
761- } else {
762- // Fallback to legacy direct task structure
763- dirPath = path . join ( userHome , 'eigent' , safeEmail , `task_${ taskId } ` ) ;
764- logPath = path . join ( userHome , '.eigent' , safeEmail , `task_${ taskId } ` ) ;
765- }
766- }
767+ const { dirPath, logPath } = this . resolveTaskPaths (
768+ email ,
769+ taskId ,
770+ projectId
771+ ) ;
767772
768773 try {
769774 let success = false ;
0 commit comments