From 485117f1a1f663995ef3bd57abf0132c4c8a6992 Mon Sep 17 00:00:00 2001 From: LHaghfoss Date: Tue, 24 Nov 2026 11:31:09 +0100 Subject: [PATCH 1/2] fix(engine): show pictures saved in the repository's worktrees --- rustcode/engine/src/controller/attachments.rs | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/rustcode/engine/src/controller/attachments.rs b/rustcode/engine/src/controller/attachments.rs index 9176a1af4..6f07f5039 100644 --- a/rustcode/engine/src/controller/attachments.rs +++ b/rustcode/engine/src/controller/attachments.rs @@ -183,10 +183,45 @@ pub fn read_thread_image_chunk( crate::harness::native_artifact_dir(&record.harness, &native, home) })); } - let path = thread_image_in(path_or_uri, &roots, &scratch_roots(), home.as_deref())?; + let scratch = scratch_roots(); + let path = match thread_image_in(path_or_uri, &roots, &scratch, home.as_deref()) { + // A worktree the agent added with git itself (`git worktree add`) is a + // checkout of the thread's repository too, so its screenshots show. Git + // is asked only when the cheaper check fails. + Err(error) if error == OUTSIDE_THREAD_FOLDERS => { + let checkouts = roots + .first() + .map(|cwd| repository_checkouts(cwd)) + .unwrap_or_default(); + if checkouts.is_empty() { + return Err(error); + } + roots.extend(checkouts); + thread_image_in(path_or_uri, &roots, &scratch, home.as_deref())? + } + other => other?, + }; read_chunk(&path, offset, true) } +const OUTSIDE_THREAD_FOLDERS: &str = + "outside the thread's folders, its repository's worktrees and the temporary folders"; + +/// Every checkout of `dir`'s repository: the main one and its worktrees. +fn repository_checkouts(dir: &Path) -> Vec { + crate::worktrees::git(dir, &["worktree", "list", "--porcelain"]) + .map(|listed| checkouts_in_porcelain(&listed)) + .unwrap_or_default() +} + +fn checkouts_in_porcelain(porcelain: &str) -> Vec { + porcelain + .lines() + .filter_map(|line| line.strip_prefix("worktree ")) + .map(PathBuf::from) + .collect() +} + /// The OS scratch folders a thread's pictures may also be in. fn scratch_roots() -> Vec { let mut roots = vec![std::env::temp_dir()]; @@ -233,7 +268,7 @@ fn thread_image_in( .filter_map(|root| fs::canonicalize(root).ok()) .any(|root| real.starts_with(root)); if !inside { - return Err("outside the thread's folders and the temporary folders".to_owned()); + return Err(OUTSIDE_THREAD_FOLDERS.to_owned()); } Ok(real) } @@ -549,6 +584,22 @@ mod tests { assert!(read_chunk(&renamed, 0, true).is_err()); } + #[test] + fn lists_every_checkout_of_a_repository() { + let porcelain = "worktree /home/ada/code/rustcode\nHEAD 1a2b\nbranch refs/heads/main\n\n\ + worktree /home/ada/code/worktrees/rustcode-streak\nHEAD 3c4d\n\ + branch refs/heads/feat/streak\n\nworktree /tmp/detached\nHEAD 5e6f\ndetached\n"; + assert_eq!( + checkouts_in_porcelain(porcelain), + [ + PathBuf::from("/home/ada/code/rustcode"), + PathBuf::from("/home/ada/code/worktrees/rustcode-streak"), + PathBuf::from("/tmp/detached"), + ] + ); + assert!(checkouts_in_porcelain("").is_empty()); + } + #[test] fn serves_only_images_kept_in_the_attachment_stores() { let config = tempfile::tempdir().expect("tempdir"); From 5147c692e962eb86b26f0690488a5e6667953d6f Mon Sep 17 00:00:00 2001 From: LHaghfoss Date: Tue, 24 Nov 2026 11:33:00 +0100 Subject: [PATCH 2/2] fix(engine): drop new comments over the baseline --- rustcode/engine/src/controller/attachments.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/rustcode/engine/src/controller/attachments.rs b/rustcode/engine/src/controller/attachments.rs index 6f07f5039..ddf52d0ca 100644 --- a/rustcode/engine/src/controller/attachments.rs +++ b/rustcode/engine/src/controller/attachments.rs @@ -185,9 +185,6 @@ pub fn read_thread_image_chunk( } let scratch = scratch_roots(); let path = match thread_image_in(path_or_uri, &roots, &scratch, home.as_deref()) { - // A worktree the agent added with git itself (`git worktree add`) is a - // checkout of the thread's repository too, so its screenshots show. Git - // is asked only when the cheaper check fails. Err(error) if error == OUTSIDE_THREAD_FOLDERS => { let checkouts = roots .first()