Skip to content
Draft
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
20 changes: 17 additions & 3 deletions src-tauri/src/commands/claude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ fn get_project_path_from_sessions(project_dir: &PathBuf) -> Result<String, Strin
// Read the JSONL file and find the first line with a valid cwd
if let Ok(file) = fs::File::open(&path) {
let reader = BufReader::new(file);
// Check first few lines instead of just the first line
// Some session files may have null cwd in the first line
for line in reader.lines().take(10) {
// Some session files may start with metadata entries before cwd appears.
for line in reader.lines() {
if let Ok(line_content) = line {
// Parse the JSON and extract cwd
if let Ok(json) =
Expand Down Expand Up @@ -2273,6 +2272,21 @@ mod tests {
assert_eq!(result.unwrap(), "/Users/test/project");
}

#[test]
fn test_get_project_path_from_sessions_scans_past_ten_lines() {
let temp_dir = TempDir::new().unwrap();
let project_dir = temp_dir.path().to_path_buf();

let mut lines = vec![r#"{"type":"permission-mode"}"#; 12];
lines.push(r#"{"type":"system","cwd":"/Users/test/deep-project"}"#);
let content = lines.join("\n");
create_test_session_file(&project_dir, "session1.jsonl", &content).unwrap();

let result = get_project_path_from_sessions(&project_dir);
assert!(result.is_ok());
assert_eq!(result.unwrap(), "/Users/test/deep-project");
}

#[test]
fn test_get_project_path_from_sessions_empty_dir() {
let temp_dir = TempDir::new().unwrap();
Expand Down