Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
logging.getLogger("camel.base_model").setLevel(logging.WARNING)
logging.getLogger("camel.agents").setLevel(logging.WARNING)
logging.getLogger("camel.societies").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
logging.getLogger("httpcore").setLevel(logging.WARNING)

from app import api
from app.component.environment import env
Expand Down
133 changes: 69 additions & 64 deletions electron/main/fileReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface FileInfo {
relativePath: string;
task_id?: string;
project_id?: string;
source?: 'project_output' | 'camel_log';
}

export class FileReader {
Expand Down Expand Up @@ -658,20 +659,23 @@ export class FileReader {
}
}

public getFileList(
private resolveTaskPaths(
email: string,
taskId: string,
projectId?: string
): FileInfo[] {
): {
dirPath: string;
logPath: string;
} {
const safeEmail = email
.split('@')[0]
.replace(/[\\/*?:"<>|\s]/g, '_')
.replace(/^\.+|\.+$/g, '');
const userHome = app.getPath('home');

let dirPath: string;
let logPath: string;

// Check if projectId is provided for new project-based structure
if (projectId) {
dirPath = path.join(
userHome,
Expand All @@ -680,25 +684,72 @@ export class FileReader {
`project_${projectId}`,
`task_${taskId}`
);
} else {
// First try project-based structure (scan for existing projects)
const userDir = path.join(userHome, 'eigent', safeEmail);
const projectBasedPath = this.findTaskInProjects(userDir, taskId);
logPath = path.join(
userHome,
'.eigent',
safeEmail,
`project_${projectId}`,
`task_${taskId}`
);
return { dirPath, logPath };
}

if (projectBasedPath) {
dirPath = projectBasedPath;
const userDir = path.join(userHome, 'eigent', safeEmail);
const projectBasedPath = this.findTaskInProjects(userDir, taskId);

if (projectBasedPath) {
dirPath = projectBasedPath;
const projectMatch = projectBasedPath.match(/project_([^\\\/]+)/);
if (projectMatch) {
logPath = path.join(
userHome,
'.eigent',
safeEmail,
projectMatch[0],
`task_${taskId}`
);
} else {
// Fallback to legacy direct task structure
dirPath = path.join(userHome, 'eigent', safeEmail, `task_${taskId}`);
logPath = path.join(userHome, '.eigent', safeEmail, `task_${taskId}`);
}
return { dirPath, logPath };
}

dirPath = path.join(userHome, 'eigent', safeEmail, `task_${taskId}`);
logPath = path.join(userHome, '.eigent', safeEmail, `task_${taskId}`);
return { dirPath, logPath };
}

public getFileList(
email: string,
taskId: string,
projectId?: string
): FileInfo[] {
const { dirPath, logPath } = this.resolveTaskPaths(
email,
taskId,
projectId
);
const camelLogPath = path.join(logPath, 'camel_logs');

try {
if (!fs.existsSync(dirPath)) {
const projectFiles = fs.existsSync(dirPath)
? this.getFilesRecursive(dirPath, dirPath).map((file) => ({
...file,
source: 'project_output' as const,
}))
: [];
const camelLogFiles = fs.existsSync(camelLogPath)
? this.getFilesRecursive(camelLogPath, camelLogPath).map((file) => ({
...file,
source: 'camel_log' as const,
}))
: [];

if (projectFiles.length === 0 && camelLogFiles.length === 0) {
return [];
}

return this.getFilesRecursive(dirPath, dirPath);
return [...projectFiles, ...camelLogFiles];
} catch (err) {
console.error('Load file failed:', err);
return [];
Expand All @@ -713,57 +764,11 @@ export class FileReader {
success: boolean;
path: { dirPath: string; logPath: string };
} {
const safeEmail = email
.split('@')[0]
.replace(/[\\/*?:"<>|\s]/g, '_')
.replace(/^\.+|\.+$/g, '');
const userHome = app.getPath('home');

let dirPath: string;
let logPath: string;

// Check if projectId is provided for new project-based structure
if (projectId) {
dirPath = path.join(
userHome,
'eigent',
safeEmail,
`project_${projectId}`,
`task_${taskId}`
);
logPath = path.join(
userHome,
'.eigent',
safeEmail,
`project_${projectId}`,
`task_${taskId}`
);
} else {
// First try project-based structure
const userDir = path.join(userHome, 'eigent', safeEmail);
const projectBasedPath = this.findTaskInProjects(userDir, taskId);

if (projectBasedPath) {
dirPath = projectBasedPath;
// Extract project from path to construct log path
const projectMatch = projectBasedPath.match(/project_([^\\\/]+)/);
if (projectMatch) {
logPath = path.join(
userHome,
'.eigent',
safeEmail,
projectMatch[0],
`task_${taskId}`
);
} else {
logPath = path.join(userHome, '.eigent', safeEmail, `task_${taskId}`);
}
} else {
// Fallback to legacy direct task structure
dirPath = path.join(userHome, 'eigent', safeEmail, `task_${taskId}`);
logPath = path.join(userHome, '.eigent', safeEmail, `task_${taskId}`);
}
}
const { dirPath, logPath } = this.resolveTaskPaths(
email,
taskId,
projectId
);

try {
let success = false;
Expand Down
2 changes: 1 addition & 1 deletion electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,7 @@ function registerIpcHandlers() {

// Read file content
const fileContent = await fsp.readFile(filePath);
log.info('File read successfully:', filePath);
// log.info('File read successfully:', filePath);

return {
success: true,
Expand Down
Loading
Loading